Skip to content

Instantly share code, notes, and snippets.

@willswire
Created June 29, 2025 00:34
Show Gist options
  • Save willswire/b316e66522d53a0ee2fb1ae4ec11e636 to your computer and use it in GitHub Desktop.
Save willswire/b316e66522d53a0ee2fb1ae4ec11e636 to your computer and use it in GitHub Desktop.
jazz.swift
import ArgumentParser
import Foundation
import FoundationModels
@main
struct JazzCommand: AsyncParsableCommand {
static var configuration = CommandConfiguration(
commandName: "jazz",
abstract: "A CLI tool to interpret shell tasks as natural language instructions."
)
@Argument(help: "A description of your shell task.")
var prompt: String
mutating func run() async throws {
let session = LanguageModelSession(
tools: [DocumentationTool()],
instructions: """
You are an AI-powered CLI assistant. You receive a description \
of a desired shell action and must output exactly one valid Unix command \
(including any flags, quoting or escaping). \
- Output only the command—no explanations, no commentary. \
- Choose the simplest, safest invocation that accomplishes the task. \
You have access to a documentation tool for concrete usage examples of popular tools.
Examples:
Input: list all files in this directory sorted by size, largest first
Output: ls -lSh
Input: search for “TODO” in all .js files under src/
Output: grep -R --include="*.js" "TODO" src/
"""
)
let response = try await session.respond(to: prompt)
print(response.content)
}
}
struct DocumentationTool: Tool {
let name = "docs"
let description = "Fetches a short, community-driven example for a shell command from tldr-pages."
@Generable
struct Arguments {
@Guide(description: "The shell command to look up (for example: 'curl' or 'ls')")
let command: String
}
func call(arguments: Arguments) async throws -> ToolOutput {
let url = URL(string: "https://raw.githubusercontent.com/tldr-pages/tldr/main/pages/common/\(arguments.command).md")!
let content = try String(contentsOf: url, encoding: .utf8)
return ToolOutput(GeneratedContent(properties: ["docs": content]))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment