forked from code-yeongyu/oh-my-openagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.ts
More file actions
205 lines (183 loc) · 6.75 KB
/
Copy pathcommands.ts
File metadata and controls
205 lines (183 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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"
import { STOP_CONTINUATION_TEMPLATE } from "./templates/stop-continuation"
import { REFACTOR_TEMPLATE, REFACTOR_TEAM_MODE_ADDENDUM } from "./templates/refactor"
import { START_WORK_TEMPLATE } from "./templates/start-work"
import { HANDOFF_TEMPLATE } from "./templates/handoff"
import { REMOVE_AI_SLOPS_TEMPLATE, REMOVE_AI_SLOPS_TEAM_MODE_ADDENDUM } from "./templates/remove-ai-slops"
import { HYPERPLAN_TEMPLATE } from "./templates/hyperplan"
interface LoadBuiltinCommandsOptions {
useRegisteredAgents?: boolean
teamModeEnabled?: boolean
}
function resolveStartWorkAgent(options?: LoadBuiltinCommandsOptions): "atlas" | "sisyphus" {
if (options?.useRegisteredAgents) {
return isAgentRegistered("atlas") ? "atlas" : "sisyphus"
}
return "atlas"
}
function withTeamModeAddendum(baseTemplate: string, addendum: string, teamModeEnabled: boolean): string {
return teamModeEnabled ? `${baseTemplate}\n${addendum}` : baseTemplate
}
function createBuiltinCommandDefinitions(
options?: LoadBuiltinCommandsOptions,
): Record<BuiltinCommandName, Omit<CommandDefinition, "name">> {
const teamModeEnabled = options?.teamModeEnabled ?? false
const refactorContent = withTeamModeAddendum(REFACTOR_TEMPLATE, REFACTOR_TEAM_MODE_ADDENDUM, teamModeEnabled)
const removeAiSlopsContent = withTeamModeAddendum(
REMOVE_AI_SLOPS_TEMPLATE,
REMOVE_AI_SLOPS_TEAM_MODE_ADDENDUM,
teamModeEnabled,
)
return {
"init-deep": {
description: "(builtin) Initialize hierarchical AGENTS.md knowledge base",
template: `<command-instruction>
${INIT_DEEP_TEMPLATE}
</command-instruction>
<user-request>
$ARGUMENTS
</user-request>`,
argumentHint: "[--create-new] [--max-depth=N]",
},
"ralph-loop": {
description: "(builtin) Start self-referential development loop until completion",
template: `<command-instruction>
${RALPH_LOOP_TEMPLATE}
</command-instruction>
<user-task>
$ARGUMENTS
</user-task>`,
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: `<command-instruction>
${ULW_LOOP_TEMPLATE}
</command-instruction>
<user-task>
$ARGUMENTS
</user-task>`,
argumentHint: '"task description" [--completion-promise=TEXT] [--strategy=reset|continue]',
},
"cancel-ralph": {
description: "(builtin) Cancel active Ralph Loop",
template: `<command-instruction>
${CANCEL_RALPH_TEMPLATE}
</command-instruction>`,
},
refactor: {
description:
"(builtin) Intelligent refactoring command with LSP, AST-grep, architecture analysis, codemap, and TDD verification.",
template: `<command-instruction>
${refactorContent}
</command-instruction>`,
argumentHint: "<refactoring-target> [--scope=<file|module|project>] [--strategy=<safe|aggressive>]",
},
"start-work": {
description: "(builtin) Start Sisyphus work session from Prometheus plan",
agent: resolveStartWorkAgent(options),
template: `<command-instruction>
${START_WORK_TEMPLATE}
</command-instruction>
<session-context>
Session ID: $SESSION_ID
Timestamp: $TIMESTAMP
</session-context>
<user-request>
$ARGUMENTS
</user-request>`,
argumentHint: "[plan-name]",
},
"stop-continuation": {
description: "(builtin) Stop all continuation mechanisms (ralph loop, todo continuation, boulder) for this session",
template: `<command-instruction>
${STOP_CONTINUATION_TEMPLATE}
</command-instruction>`,
},
"remove-ai-slops": {
description: "(builtin) Remove AI-generated code smells from branch changes and critically review the results",
template: `<command-instruction>
${removeAiSlopsContent}
</command-instruction>
<user-request>
$ARGUMENTS
</user-request>`,
},
handoff: {
description: "(builtin) Create a detailed context summary for continuing work in a new session",
template: `<command-instruction>
${HANDOFF_TEMPLATE}
</command-instruction>
<session-context>
Session ID: $SESSION_ID
Timestamp: $TIMESTAMP
</session-context>
<user-request>
$ARGUMENTS
</user-request>`,
argumentHint: "[goal]",
},
hyperplan: {
description: "(builtin) Adversarial multi-agent planning via team-mode (5 hostile category members cross-critique, lead synthesizes)",
template: `<command-instruction>
${HYPERPLAN_TEMPLATE}
</command-instruction>`,
argumentHint: "[planning-request]",
},
"create-skill": {
description: "(builtin) Create a new AI agent skill following the Agent Skills spec. Usage: /create-skill <name> [description]",
template: `<command-instruction>
Create a new skill at .agents/skills/{name}/SKILL.md with the standard Agent Skills template.
The skill name must use kebab-case and should describe the domain or task.
Steps:
1. Validate the skill name (kebab-case, no spaces)
2. Create .agents/skills/{name}/ directory
3. Generate SKILL.md from the standard template
4. Register in .atl/skill-registry.md
</command-instruction>
<user-request>
$ARGUMENTS
</user-request>`,
argumentHint: "<skill-name> [description]",
},
"update-skill-registry": {
description: "(builtin) Scan all skill directories and rebuild .atl/skill-registry.md with compact rules",
template: `<command-instruction>
Scan all skill directories and rebuild the skill registry at .atl/skill-registry.md.
Scan directories:
- .agents/skills/
- .opencode/skills/
- ~/.config/opencode/skills/
- ~/.claude/skills/
For each skill found:
- Extract name from frontmatter
- Extract trigger words from description
- Generate compact rules (5-15 lines) from Critical Patterns section
- Write to .atl/skill-registry.md
</command-instruction>
<user-request>
$ARGUMENTS
</user-request>`,
argumentHint: "",
},
}
}
export function loadBuiltinCommands(
disabledCommands?: BuiltinCommandName[],
options?: LoadBuiltinCommandsOptions,
): BuiltinCommands {
const builtinCommandDefinitions = createBuiltinCommandDefinitions(options)
const disabled = new Set(disabledCommands ?? [])
const commands: BuiltinCommands = {}
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
}
}
return commands
}