refactor(commands): convert start-work template to function

This commit is contained in:
acamq
2026-03-11 18:27:38 -06:00
parent 249818469d
commit 66ac587dfa
3 changed files with 101 additions and 68 deletions
+11 -8
View File
@@ -4,10 +4,17 @@ import { INIT_DEEP_TEMPLATE } from "./templates/init-deep"
import { RALPH_LOOP_TEMPLATE, ULW_LOOP_TEMPLATE, CANCEL_RALPH_TEMPLATE } from "./templates/ralph-loop" import { RALPH_LOOP_TEMPLATE, ULW_LOOP_TEMPLATE, CANCEL_RALPH_TEMPLATE } from "./templates/ralph-loop"
import { STOP_CONTINUATION_TEMPLATE } from "./templates/stop-continuation" import { STOP_CONTINUATION_TEMPLATE } from "./templates/stop-continuation"
import { REFACTOR_TEMPLATE } from "./templates/refactor" import { REFACTOR_TEMPLATE } from "./templates/refactor"
import { START_WORK_TEMPLATE } from "./templates/start-work" import { createStartWorkTemplate } from "./templates/start-work"
import { HANDOFF_TEMPLATE } from "./templates/handoff" import { HANDOFF_TEMPLATE } from "./templates/handoff"
const BUILTIN_COMMAND_DEFINITIONS: Record<BuiltinCommandName, Omit<CommandDefinition, "name">> = { export function loadBuiltinCommands(
disabledCommands?: BuiltinCommandName[],
startWorkConfig?: { worktree?: boolean }
): BuiltinCommands {
const disabled = new Set(disabledCommands ?? [])
const startWorkTemplate = createStartWorkTemplate({ worktreeEnabled: startWorkConfig?.worktree ?? true })
const definitions: Record<BuiltinCommandName, Omit<CommandDefinition, "name">> = {
"init-deep": { "init-deep": {
description: "(builtin) Initialize hierarchical AGENTS.md knowledge base", description: "(builtin) Initialize hierarchical AGENTS.md knowledge base",
template: `<command-instruction> template: `<command-instruction>
@@ -59,7 +66,7 @@ ${REFACTOR_TEMPLATE}
description: "(builtin) Start Sisyphus work session from Prometheus plan", description: "(builtin) Start Sisyphus work session from Prometheus plan",
agent: "atlas", agent: "atlas",
template: `<command-instruction> template: `<command-instruction>
${START_WORK_TEMPLATE} ${startWorkTemplate}
</command-instruction> </command-instruction>
<session-context> <session-context>
@@ -96,13 +103,9 @@ $ARGUMENTS
}, },
} }
export function loadBuiltinCommands(
disabledCommands?: BuiltinCommandName[]
): BuiltinCommands {
const disabled = new Set(disabledCommands ?? [])
const commands: BuiltinCommands = {} const commands: BuiltinCommands = {}
for (const [name, definition] of Object.entries(BUILTIN_COMMAND_DEFINITIONS)) { for (const [name, definition] of Object.entries(definitions)) {
if (!disabled.has(name as BuiltinCommandName)) { if (!disabled.has(name as BuiltinCommandName)) {
const { argumentHint: _argumentHint, ...openCodeCompatible } = definition const { argumentHint: _argumentHint, ...openCodeCompatible } = definition
commands[name] = { ...openCodeCompatible, name } as CommandDefinition commands[name] = { ...openCodeCompatible, name } as CommandDefinition
@@ -1,13 +1,47 @@
export const START_WORK_TEMPLATE = `You are starting a Sisyphus work session. export function createStartWorkTemplate(options?: { worktreeEnabled?: boolean }): string {
const worktreeEnabled = options?.worktreeEnabled ?? true
## ARGUMENTS const argumentsSection = worktreeEnabled
? `- \`/start-work [plan-name] [--worktree <path>]\`
- \`/start-work [plan-name] [--worktree <path>]\`
- \`plan-name\` (optional): name or partial match of the plan to start - \`plan-name\` (optional): name or partial match of the plan to start
- \`--worktree <path>\` (optional): absolute path to an existing git worktree to work in - \`--worktree <path>\` (optional): absolute path to an existing git worktree to work in
- If specified and valid: hook pre-sets worktree_path in boulder.json - If specified and valid: hook pre-sets worktree_path in boulder.json
- If specified but invalid: you must run \`git worktree add <path> <branch>\` first - If specified but invalid: you must run \`git worktree add <path> <branch>\` first
- If omitted: you MUST choose or create a worktree (see Worktree Setup below) - If omitted: you MUST choose or create a worktree (see Worktree Setup below)`
: `- \`/start-work [plan-name]\`
- \`plan-name\` (optional): name or partial match of the plan to start`
const worktreeSetupSection = worktreeEnabled
? `
4. **Worktree Setup** (when \`worktree_path\` not already set in boulder.json):
1. \`git worktree list --porcelain\` — see available worktrees
2. Create: \`git worktree add <absolute-path> <branch-or-HEAD>\`
3. Update boulder.json to add \`"worktree_path": "<absolute-path>"\`
4. All work happens inside that worktree directory
`
: ``
const boulderJsonWorktreeLine = worktreeEnabled
? ` "worktree_path": "/absolute/path/to/git/worktree"\n`
: ``
const resumingWorktreeLine = worktreeEnabled
? `Worktree: {worktree_path}\n`
: ``
const startingWorktreeLine = worktreeEnabled
? `Worktree: {worktree_path}\n`
: ``
const worktreeCritical = worktreeEnabled
? `- Always set worktree_path in boulder.json before executing any tasks\n`
: ``
return `You are starting a Sisyphus work session.
## ARGUMENTS
${argumentsSection}
## WHAT TO DO ## WHAT TO DO
@@ -23,25 +57,18 @@ export const START_WORK_TEMPLATE = `You are starting a Sisyphus work session.
- List available plan files - List available plan files
- If ONE plan: auto-select it - If ONE plan: auto-select it
- If MULTIPLE plans: show list with timestamps, ask user to select - If MULTIPLE plans: show list with timestamps, ask user to select
${worktreeSetupSection}
4. **Worktree Setup** (when \`worktree_path\` not already set in boulder.json): ${worktreeEnabled ? "5" : "4"}. **Create/Update boulder.json**:
1. \`git worktree list --porcelain\` — see available worktrees
2. Create: \`git worktree add <absolute-path> <branch-or-HEAD>\`
3. Update boulder.json to add \`"worktree_path": "<absolute-path>"\`
4. All work happens inside that worktree directory
5. **Create/Update boulder.json**:
\`\`\`json \`\`\`json
{ {
"active_plan": "/absolute/path/to/plan.md", "active_plan": "/absolute/path/to/plan.md",
"started_at": "ISO_TIMESTAMP", "started_at": "ISO_TIMESTAMP",
"session_ids": ["session_id_1", "session_id_2"], "session_ids": ["session_id_1", "session_id_2"],
"plan_name": "plan-name", "plan_name": "plan-name"${worktreeEnabled ? `,\n "worktree_path": "/absolute/path/to/git/worktree"` : ""}
"worktree_path": "/absolute/path/to/git/worktree"
} }
\`\`\` \`\`\`
6. **Read the plan file** and start executing tasks according to atlas workflow ${worktreeEnabled ? "6" : "5"}. **Read the plan file** and start executing tasks according to atlas workflow
## OUTPUT FORMAT ## OUTPUT FORMAT
@@ -65,8 +92,7 @@ Resuming Work Session
Active Plan: {plan-name} Active Plan: {plan-name}
Progress: {completed}/{total} tasks Progress: {completed}/{total} tasks
Sessions: {count} (appending current session) Sessions: {count} (appending current session)
Worktree: {worktree_path} ${resumingWorktreeLine}
Reading plan and continuing from last incomplete task... Reading plan and continuing from last incomplete task...
\`\`\` \`\`\`
@@ -77,8 +103,7 @@ Starting Work Session
Plan: {plan-name} Plan: {plan-name}
Session ID: {session_id} Session ID: {session_id}
Started: {timestamp} Started: {timestamp}
Worktree: {worktree_path} ${startingWorktreeLine}
Reading plan and beginning execution... Reading plan and beginning execution...
\`\`\` \`\`\`
@@ -86,6 +111,8 @@ Reading plan and beginning execution...
- The session_id is injected by the hook - use it directly - The session_id is injected by the hook - use it directly
- Always update boulder.json BEFORE starting work - Always update boulder.json BEFORE starting work
- Always set worktree_path in boulder.json before executing any tasks ${worktreeCritical}- Read the FULL plan file before delegating any tasks
- Read the FULL plan file before delegating any tasks
- Follow atlas delegation protocols (7-section format)` - Follow atlas delegation protocols (7-section format)`
}
export const START_WORK_TEMPLATE = createStartWorkTemplate()
@@ -23,7 +23,10 @@ export async function applyCommandConfig(params: {
ctx: { directory: string }; ctx: { directory: string };
pluginComponents: PluginComponents; pluginComponents: PluginComponents;
}): Promise<void> { }): Promise<void> {
const builtinCommands = loadBuiltinCommands(params.pluginConfig.disabled_commands); const builtinCommands = loadBuiltinCommands(
params.pluginConfig.disabled_commands,
params.pluginConfig.start_work
);
const systemCommands = (params.config.command as Record<string, unknown>) ?? {}; const systemCommands = (params.config.command as Record<string, unknown>) ?? {};
const includeClaudeCommands = params.pluginConfig.claude_code?.commands ?? true; const includeClaudeCommands = params.pluginConfig.claude_code?.commands ?? true;