2026-02-22 23:08:39 +01:00
|
|
|
import { tool, type ToolDefinition } from "@opencode-ai/plugin"
|
2026-02-23 11:52:58 +01:00
|
|
|
import { randomUUID } from "node:crypto"
|
2026-02-23 12:46:44 +01:00
|
|
|
import { writeFile, unlink, mkdir } from "node:fs/promises"
|
2026-02-22 23:08:39 +01:00
|
|
|
import { join } from "node:path"
|
|
|
|
|
import { log } from "../../shared/logger"
|
2026-02-24 01:48:18 +01:00
|
|
|
import { COUNCIL_MEMBER_PROMPT, COUNCIL_DELEGATION_ADDENDUM } from "../../agents/athena"
|
2026-02-22 23:08:39 +01:00
|
|
|
|
|
|
|
|
const CLEANUP_DELAY_MS = 30 * 60 * 1000
|
2026-02-23 12:46:44 +01:00
|
|
|
const COUNCIL_TMP_DIR = ".sisyphus/tmp"
|
2026-02-22 23:08:39 +01:00
|
|
|
|
2026-02-23 12:46:44 +01:00
|
|
|
export function createPrepareCouncilPromptTool(directory: string): ToolDefinition {
|
2026-02-22 23:08:39 +01:00
|
|
|
const description = `Save a council analysis prompt to a temp file so council members can read it.
|
|
|
|
|
|
|
|
|
|
Athena-only tool. Saves the prompt once, then each council member task() call uses a short
|
|
|
|
|
"Read <path>" instruction instead of repeating the full question. This keeps task() calls
|
|
|
|
|
fast and small.
|
|
|
|
|
|
2026-02-23 19:42:56 +01:00
|
|
|
The "mode" parameter controls whether council members can delegate exploration to subagents:
|
|
|
|
|
- "solo" (default): Members do all exploration themselves. More thorough but uses more tokens.
|
|
|
|
|
- "delegation": Members can delegate to explore/librarian agents. Faster, lighter context.
|
|
|
|
|
|
2026-02-22 23:08:39 +01:00
|
|
|
Returns the file path to reference in subsequent task() calls.`
|
|
|
|
|
|
|
|
|
|
return tool({
|
|
|
|
|
description,
|
|
|
|
|
args: {
|
|
|
|
|
prompt: tool.schema.string().describe("The full analysis prompt/question for council members"),
|
2026-02-23 19:42:56 +01:00
|
|
|
mode: tool.schema.string().optional().describe('Analysis mode: "solo" (default) or "delegation"'),
|
2026-02-22 23:08:39 +01:00
|
|
|
},
|
2026-02-23 19:42:56 +01:00
|
|
|
async execute(args: { prompt: string; mode?: string }) {
|
2026-02-22 23:08:39 +01:00
|
|
|
if (!args.prompt?.trim()) {
|
|
|
|
|
return "Prompt cannot be empty."
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 19:42:56 +01:00
|
|
|
const mode = args.mode === "delegation" ? "delegation" : "solo"
|
2026-02-23 12:46:44 +01:00
|
|
|
const tmpDir = join(directory, COUNCIL_TMP_DIR)
|
|
|
|
|
await mkdir(tmpDir, { recursive: true })
|
|
|
|
|
|
2026-02-23 11:52:58 +01:00
|
|
|
const filename = `athena-council-${randomUUID().slice(0, 8)}.md`
|
2026-02-23 12:46:44 +01:00
|
|
|
const filePath = join(tmpDir, filename)
|
|
|
|
|
|
2026-02-23 19:42:56 +01:00
|
|
|
const delegationSection = mode === "delegation" ? `\n${COUNCIL_DELEGATION_ADDENDUM}` : ""
|
|
|
|
|
const content = `${COUNCIL_MEMBER_PROMPT}${delegationSection}
|
2026-02-23 12:46:44 +01:00
|
|
|
|
|
|
|
|
## Analysis Question
|
|
|
|
|
|
|
|
|
|
${args.prompt}`
|
2026-02-22 23:08:39 +01:00
|
|
|
|
2026-02-23 12:46:44 +01:00
|
|
|
await writeFile(filePath, content, "utf-8")
|
2026-02-22 23:08:39 +01:00
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2026-02-24 01:48:18 +01:00
|
|
|
unlink(filePath).catch((err) => {
|
|
|
|
|
log("[prepare-council-prompt] Failed to clean up temp file", { filePath, error: String(err) })
|
|
|
|
|
})
|
2026-02-22 23:08:39 +01:00
|
|
|
}, CLEANUP_DELAY_MS)
|
|
|
|
|
|
2026-02-23 19:42:56 +01:00
|
|
|
log("[prepare-council-prompt] Saved prompt", { filePath, length: args.prompt.length, mode })
|
2026-02-22 23:08:39 +01:00
|
|
|
|
2026-02-23 19:42:56 +01:00
|
|
|
return `Council prompt saved to: ${filePath} (mode: ${mode})
|
2026-02-22 23:08:39 +01:00
|
|
|
|
|
|
|
|
Use this path in each council member's task() call:
|
|
|
|
|
- prompt: "Read ${filePath} for your instructions."
|
|
|
|
|
|
|
|
|
|
The file auto-deletes after 30 minutes.`
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|