refactor(commands): convert start-work template to function
This commit is contained in:
@@ -4,33 +4,40 @@ 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(
|
||||||
"init-deep": {
|
disabledCommands?: BuiltinCommandName[],
|
||||||
description: "(builtin) Initialize hierarchical AGENTS.md knowledge base",
|
startWorkConfig?: { worktree?: boolean }
|
||||||
template: `<command-instruction>
|
): BuiltinCommands {
|
||||||
|
const disabled = new Set(disabledCommands ?? [])
|
||||||
|
const startWorkTemplate = createStartWorkTemplate({ worktreeEnabled: startWorkConfig?.worktree ?? true })
|
||||||
|
|
||||||
|
const definitions: Record<BuiltinCommandName, Omit<CommandDefinition, "name">> = {
|
||||||
|
"init-deep": {
|
||||||
|
description: "(builtin) Initialize hierarchical AGENTS.md knowledge base",
|
||||||
|
template: `<command-instruction>
|
||||||
${INIT_DEEP_TEMPLATE}
|
${INIT_DEEP_TEMPLATE}
|
||||||
</command-instruction>
|
</command-instruction>
|
||||||
|
|
||||||
<user-request>
|
<user-request>
|
||||||
$ARGUMENTS
|
$ARGUMENTS
|
||||||
</user-request>`,
|
</user-request>`,
|
||||||
argumentHint: "[--create-new] [--max-depth=N]",
|
argumentHint: "[--create-new] [--max-depth=N]",
|
||||||
},
|
},
|
||||||
"ralph-loop": {
|
"ralph-loop": {
|
||||||
description: "(builtin) Start self-referential development loop until completion",
|
description: "(builtin) Start self-referential development loop until completion",
|
||||||
template: `<command-instruction>
|
template: `<command-instruction>
|
||||||
${RALPH_LOOP_TEMPLATE}
|
${RALPH_LOOP_TEMPLATE}
|
||||||
</command-instruction>
|
</command-instruction>
|
||||||
|
|
||||||
<user-task>
|
<user-task>
|
||||||
$ARGUMENTS
|
$ARGUMENTS
|
||||||
</user-task>`,
|
</user-task>`,
|
||||||
argumentHint: '"task description" [--completion-promise=TEXT] [--max-iterations=N] [--strategy=reset|continue]',
|
argumentHint: '"task description" [--completion-promise=TEXT] [--max-iterations=N] [--strategy=reset|continue]',
|
||||||
},
|
},
|
||||||
"ulw-loop": {
|
"ulw-loop": {
|
||||||
description: "(builtin) Start ultrawork loop - continues until completion with ultrawork mode",
|
description: "(builtin) Start ultrawork loop - continues until completion with ultrawork mode",
|
||||||
template: `<command-instruction>
|
template: `<command-instruction>
|
||||||
${ULW_LOOP_TEMPLATE}
|
${ULW_LOOP_TEMPLATE}
|
||||||
@@ -41,25 +48,25 @@ $ARGUMENTS
|
|||||||
</user-task>`,
|
</user-task>`,
|
||||||
argumentHint: '"task description" [--completion-promise=TEXT] [--strategy=reset|continue]',
|
argumentHint: '"task description" [--completion-promise=TEXT] [--strategy=reset|continue]',
|
||||||
},
|
},
|
||||||
"cancel-ralph": {
|
"cancel-ralph": {
|
||||||
description: "(builtin) Cancel active Ralph Loop",
|
description: "(builtin) Cancel active Ralph Loop",
|
||||||
template: `<command-instruction>
|
template: `<command-instruction>
|
||||||
${CANCEL_RALPH_TEMPLATE}
|
${CANCEL_RALPH_TEMPLATE}
|
||||||
</command-instruction>`,
|
</command-instruction>`,
|
||||||
},
|
},
|
||||||
refactor: {
|
refactor: {
|
||||||
description:
|
description:
|
||||||
"(builtin) Intelligent refactoring command with LSP, AST-grep, architecture analysis, codemap, and TDD verification.",
|
"(builtin) Intelligent refactoring command with LSP, AST-grep, architecture analysis, codemap, and TDD verification.",
|
||||||
template: `<command-instruction>
|
template: `<command-instruction>
|
||||||
${REFACTOR_TEMPLATE}
|
${REFACTOR_TEMPLATE}
|
||||||
</command-instruction>`,
|
</command-instruction>`,
|
||||||
argumentHint: "<refactoring-target> [--scope=<file|module|project>] [--strategy=<safe|aggressive>]",
|
argumentHint: "<refactoring-target> [--scope=<file|module|project>] [--strategy=<safe|aggressive>]",
|
||||||
},
|
},
|
||||||
"start-work": {
|
"start-work": {
|
||||||
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>
|
||||||
@@ -70,17 +77,17 @@ Timestamp: $TIMESTAMP
|
|||||||
<user-request>
|
<user-request>
|
||||||
$ARGUMENTS
|
$ARGUMENTS
|
||||||
</user-request>`,
|
</user-request>`,
|
||||||
argumentHint: "[plan-name]",
|
argumentHint: "[plan-name]",
|
||||||
},
|
},
|
||||||
"stop-continuation": {
|
"stop-continuation": {
|
||||||
description: "(builtin) Stop all continuation mechanisms (ralph loop, todo continuation, boulder) for this session",
|
description: "(builtin) Stop all continuation mechanisms (ralph loop, todo continuation, boulder) for this session",
|
||||||
template: `<command-instruction>
|
template: `<command-instruction>
|
||||||
${STOP_CONTINUATION_TEMPLATE}
|
${STOP_CONTINUATION_TEMPLATE}
|
||||||
</command-instruction>`,
|
</command-instruction>`,
|
||||||
},
|
},
|
||||||
handoff: {
|
handoff: {
|
||||||
description: "(builtin) Create a detailed context summary for continuing work in a new session",
|
description: "(builtin) Create a detailed context summary for continuing work in a new session",
|
||||||
template: `<command-instruction>
|
template: `<command-instruction>
|
||||||
${HANDOFF_TEMPLATE}
|
${HANDOFF_TEMPLATE}
|
||||||
</command-instruction>
|
</command-instruction>
|
||||||
|
|
||||||
@@ -92,17 +99,13 @@ Timestamp: $TIMESTAMP
|
|||||||
<user-request>
|
<user-request>
|
||||||
$ARGUMENTS
|
$ARGUMENTS
|
||||||
</user-request>`,
|
</user-request>`,
|
||||||
argumentHint: "[goal]",
|
argumentHint: "[goal]",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user