diff --git a/src/features/builtin-commands/commands.test.ts b/src/features/builtin-commands/commands.test.ts index 15231bb44..8db604198 100644 --- a/src/features/builtin-commands/commands.test.ts +++ b/src/features/builtin-commands/commands.test.ts @@ -1,8 +1,17 @@ -import { describe, test, expect } from "bun:test" +import { afterEach, beforeEach, describe, test, expect } from "bun:test" import { loadBuiltinCommands } from "./commands" import { HANDOFF_TEMPLATE } from "./templates/handoff" import { REMOVE_AI_SLOPS_TEMPLATE } from "./templates/remove-ai-slops" import type { BuiltinCommandName } from "./types" +import { _resetForTesting, registerAgentName } from "../claude-code-session-state" + +beforeEach(() => { + _resetForTesting() +}) + +afterEach(() => { + _resetForTesting() +}) describe("loadBuiltinCommands", () => { test("should include handoff command in loaded commands", () => { @@ -69,6 +78,17 @@ describe("loadBuiltinCommands", () => { //#then expect(commands["start-work"].agent).toBe("sisyphus") }) + + test("should preassign Atlas as the native agent for start-work when Atlas is registered", () => { + //#given + registerAgentName("atlas") + + //#when + const commands = loadBuiltinCommands() + + //#then + expect(commands["start-work"].agent).toBe("atlas") + }) }) describe("loadBuiltinCommands — remove-ai-slops", () => { diff --git a/src/features/builtin-commands/commands.ts b/src/features/builtin-commands/commands.ts index 3c0f1e432..8b82bd3a1 100644 --- a/src/features/builtin-commands/commands.ts +++ b/src/features/builtin-commands/commands.ts @@ -1,4 +1,5 @@ import type { CommandDefinition } from "../claude-code-command-loader" +import { isAgentRegistered } from "../claude-code-session-state" import type { BuiltinCommandName, BuiltinCommands } from "./types" import { INIT_DEEP_TEMPLATE } from "./templates/init-deep" import { RALPH_LOOP_TEMPLATE, ULW_LOOP_TEMPLATE, CANCEL_RALPH_TEMPLATE } from "./templates/ralph-loop" @@ -8,58 +9,59 @@ import { START_WORK_TEMPLATE } from "./templates/start-work" import { HANDOFF_TEMPLATE } from "./templates/handoff" import { REMOVE_AI_SLOPS_TEMPLATE } from "./templates/remove-ai-slops" -const BUILTIN_COMMAND_DEFINITIONS: Record> = { - "init-deep": { - description: "(builtin) Initialize hierarchical AGENTS.md knowledge base", - template: ` +function createBuiltinCommandDefinitions(): Record> { + return { + "init-deep": { + description: "(builtin) Initialize hierarchical AGENTS.md knowledge base", + template: ` ${INIT_DEEP_TEMPLATE} $ARGUMENTS `, - argumentHint: "[--create-new] [--max-depth=N]", - }, - "ralph-loop": { - description: "(builtin) Start self-referential development loop until completion", - template: ` + argumentHint: "[--create-new] [--max-depth=N]", + }, + "ralph-loop": { + description: "(builtin) Start self-referential development loop until completion", + template: ` ${RALPH_LOOP_TEMPLATE} $ARGUMENTS `, - argumentHint: '"task description" [--completion-promise=TEXT] [--max-iterations=N] [--strategy=reset|continue]', - }, - "ulw-loop": { - description: "(builtin) Start ultrawork loop - continues until completion with ultrawork mode", - template: ` + argumentHint: '"task description" [--completion-promise=TEXT] [--max-iterations=N] [--strategy=reset|continue]', + }, + "ulw-loop": { + description: "(builtin) Start ultrawork loop - continues until completion with ultrawork mode", + template: ` ${ULW_LOOP_TEMPLATE} $ARGUMENTS `, - argumentHint: '"task description" [--completion-promise=TEXT] [--strategy=reset|continue]', - }, - "cancel-ralph": { - description: "(builtin) Cancel active Ralph Loop", - template: ` + argumentHint: '"task description" [--completion-promise=TEXT] [--strategy=reset|continue]', + }, + "cancel-ralph": { + description: "(builtin) Cancel active Ralph Loop", + template: ` ${CANCEL_RALPH_TEMPLATE} `, - }, - refactor: { - description: - "(builtin) Intelligent refactoring command with LSP, AST-grep, architecture analysis, codemap, and TDD verification.", - template: ` + }, + refactor: { + description: + "(builtin) Intelligent refactoring command with LSP, AST-grep, architecture analysis, codemap, and TDD verification.", + template: ` ${REFACTOR_TEMPLATE} `, - argumentHint: " [--scope=] [--strategy=]", - }, - "start-work": { - description: "(builtin) Start Sisyphus work session from Prometheus plan", - agent: "sisyphus", - template: ` + argumentHint: " [--scope=] [--strategy=]", + }, + "start-work": { + description: "(builtin) Start Sisyphus work session from Prometheus plan", + agent: isAgentRegistered("atlas") ? "atlas" : "sisyphus", + template: ` ${START_WORK_TEMPLATE} @@ -71,27 +73,27 @@ Timestamp: $TIMESTAMP $ARGUMENTS `, - argumentHint: "[plan-name]", - }, - "stop-continuation": { - description: "(builtin) Stop all continuation mechanisms (ralph loop, todo continuation, boulder) for this session", - template: ` + argumentHint: "[plan-name]", + }, + "stop-continuation": { + description: "(builtin) Stop all continuation mechanisms (ralph loop, todo continuation, boulder) for this session", + template: ` ${STOP_CONTINUATION_TEMPLATE} `, - }, - "remove-ai-slops": { - description: "(builtin) Remove AI-generated code smells from branch changes and critically review the results", - template: ` + }, + "remove-ai-slops": { + description: "(builtin) Remove AI-generated code smells from branch changes and critically review the results", + template: ` ${REMOVE_AI_SLOPS_TEMPLATE} $ARGUMENTS `, - }, - handoff: { - description: "(builtin) Create a detailed context summary for continuing work in a new session", - template: ` + }, + handoff: { + description: "(builtin) Create a detailed context summary for continuing work in a new session", + template: ` ${HANDOFF_TEMPLATE} @@ -103,17 +105,19 @@ Timestamp: $TIMESTAMP $ARGUMENTS `, - argumentHint: "[goal]", - }, + argumentHint: "[goal]", + }, + } } export function loadBuiltinCommands( disabledCommands?: BuiltinCommandName[] ): BuiltinCommands { + const builtinCommandDefinitions = createBuiltinCommandDefinitions() const disabled = new Set(disabledCommands ?? []) const commands: BuiltinCommands = {} - for (const [name, definition] of Object.entries(BUILTIN_COMMAND_DEFINITIONS)) { + for (const [name, definition] of Object.entries(builtinCommandDefinitions)) { if (!disabled.has(name as BuiltinCommandName)) { const { argumentHint: _argumentHint, ...openCodeCompatible } = definition commands[name] = { ...openCodeCompatible, name } as CommandDefinition