Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion packages/opencode/src/cli/cmd/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,58 @@ import { EOL } from "os"
const AgentCreateCommand = cmd({
command: "create",
describe: "create a new agent",
async handler() {
builder: (yargs) =>
yargs
.option("path", {
type: "string",
describe: "directory path to generate the agent file",
})
.option("description", {
type: "string",
describe: "what the agent should do",
})
.option("mode", {
type: "string",
describe: "agent mode",
choices: ["all", "primary", "subagent"] as const,
}),
async handler(args) {
const cliPath = args.path as string | undefined
const cliDescription = args.description as string | undefined
const cliMode = args.mode as "all" | "primary" | "subagent" | undefined

const isNonInteractive = cliPath && cliDescription && cliMode

if (isNonInteractive) {
await Instance.provide({
directory: process.cwd(),
async fn() {
const generated = await Agent.generate({ description: cliDescription }).catch((error) => {
console.error(`Error: LLM failed to generate agent: ${error.message}`)
process.exit(1)
})

const frontmatter: any = {
description: generated.whenToUse,
mode: cliMode,
}

const content = matter.stringify(generated.systemPrompt, frontmatter)
const agentDir = path.join(cliPath, "agent")
const filePath = path.join(agentDir, `${generated.identifier}.md`)

const file = Bun.file(filePath)
if (await file.exists()) {
console.error(`Error: Agent file already exists: ${filePath}`)
process.exit(1)
}

await Bun.write(filePath, content)
console.log(filePath)
},
})
return
}
await Instance.provide({
directory: process.cwd(),
async fn() {
Expand Down