opencode-enhancer-plugin 1.0.0 ā 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +777 -17
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/sessionStore.d.ts +21 -0
- package/dist/utils/sessionStore.d.ts.map +1 -0
- package/dist/utils/sessionStore.js +70 -0
- package/dist/utils/sessionStore.js.map +1 -0
- package/dist/utils/todoParser.d.ts +9 -0
- package/dist/utils/todoParser.d.ts.map +1 -0
- package/dist/utils/todoParser.js +79 -0
- package/dist/utils/todoParser.js.map +1 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,29 +1,268 @@
|
|
|
1
|
+
import { TodoParser } from "./utils/todoParser.js";
|
|
2
|
+
import { todoStore } from "./utils/sessionStore.js";
|
|
3
|
+
// === TODO ENFORCER CONSTANTS ===
|
|
4
|
+
const TODO_ENFORCER_AGENTS = ['ultraplan', 'strategos'];
|
|
5
|
+
const TODO_MARKER_START = '<!-- TODOS-START -->';
|
|
6
|
+
const TODO_MARKER_END = '<!-- TODOS-END -->';
|
|
7
|
+
// === STRATEGOS MODE CONSTANTS ===
|
|
8
|
+
const STRATEGOS_KEYWORDS = [
|
|
9
|
+
'strategos',
|
|
10
|
+
'strategy',
|
|
11
|
+
'strat',
|
|
12
|
+
'interview mode',
|
|
13
|
+
'strategic plan',
|
|
14
|
+
'complex plan',
|
|
15
|
+
'architecture decision',
|
|
16
|
+
'design review',
|
|
17
|
+
'comprehensive plan',
|
|
18
|
+
'šÆ',
|
|
19
|
+
];
|
|
20
|
+
// Validation Constants
|
|
21
|
+
const VALID_MODEL_PATTERNS = [
|
|
22
|
+
/^opencode\//,
|
|
23
|
+
/^anthropic\//,
|
|
24
|
+
/^openai\//,
|
|
25
|
+
/^google\//,
|
|
26
|
+
/^mistral\//,
|
|
27
|
+
/^cohere\//,
|
|
28
|
+
/^ollama\//
|
|
29
|
+
];
|
|
30
|
+
const DEFAULT_MODEL = "opencode/kimi-k2.5-free";
|
|
31
|
+
// Model Validation Function
|
|
32
|
+
function validateModel(model, agentName, client) {
|
|
33
|
+
if (!model || typeof model !== 'string') {
|
|
34
|
+
client.app.log({
|
|
35
|
+
service: "enhancer",
|
|
36
|
+
level: "warn",
|
|
37
|
+
message: `Invalid model for ${agentName}, using default`
|
|
38
|
+
}).catch(() => { });
|
|
39
|
+
return DEFAULT_MODEL;
|
|
40
|
+
}
|
|
41
|
+
const isValid = VALID_MODEL_PATTERNS.some(pattern => pattern.test(model));
|
|
42
|
+
if (!isValid) {
|
|
43
|
+
client.app.log({
|
|
44
|
+
service: "enhancer",
|
|
45
|
+
level: "warn",
|
|
46
|
+
message: `Unknown model provider for ${agentName}: ${model}, using default`
|
|
47
|
+
}).catch(() => { });
|
|
48
|
+
return DEFAULT_MODEL;
|
|
49
|
+
}
|
|
50
|
+
return model;
|
|
51
|
+
}
|
|
52
|
+
// Model Resolver with Hierarchical Configuration
|
|
53
|
+
function resolveModel(agentName, agentType, existingConfig, client) {
|
|
54
|
+
let model;
|
|
55
|
+
// 1. Check existing OpenCode Config (highest priority)
|
|
56
|
+
if (existingConfig?.model) {
|
|
57
|
+
return validateModel(existingConfig.model, agentName, client);
|
|
58
|
+
}
|
|
59
|
+
// 2. Specific environment variable (e.g., ENHANCER_MODEL_REVIEW_PLAN)
|
|
60
|
+
const specificVar = `ENHANCER_MODEL_${agentName.toUpperCase().replace(/-/g, '_')}`;
|
|
61
|
+
model = process.env[specificVar];
|
|
62
|
+
if (model) {
|
|
63
|
+
client.app.log({
|
|
64
|
+
service: "enhancer",
|
|
65
|
+
level: "info",
|
|
66
|
+
message: `Using specific env var ${specificVar} for ${agentName}`
|
|
67
|
+
}).catch(() => { });
|
|
68
|
+
return validateModel(model, agentName, client);
|
|
69
|
+
}
|
|
70
|
+
// 3. Grouped environment variable (ENHANCER_MODEL_SUBAGENT or ENHANCER_MODEL_PRIMARY)
|
|
71
|
+
const groupVar = `ENHANCER_MODEL_${agentType.toUpperCase()}`;
|
|
72
|
+
model = process.env[groupVar];
|
|
73
|
+
if (model) {
|
|
74
|
+
client.app.log({
|
|
75
|
+
service: "enhancer",
|
|
76
|
+
level: "info",
|
|
77
|
+
message: `Using group env var ${groupVar} for ${agentName}`
|
|
78
|
+
}).catch(() => { });
|
|
79
|
+
return validateModel(model, agentName, client);
|
|
80
|
+
}
|
|
81
|
+
// 4. Default
|
|
82
|
+
return DEFAULT_MODEL;
|
|
83
|
+
}
|
|
1
84
|
export const EnhancerPlugin = async ({ client }) => {
|
|
2
85
|
client.app.log({
|
|
3
86
|
service: "enhancer",
|
|
4
87
|
level: "info",
|
|
5
|
-
message: "Enhancer plugin initialized"
|
|
88
|
+
message: "š„ Enhancer plugin v1.4.0 initialized with Todo Enforcer & Strategos Mode"
|
|
6
89
|
}).catch(() => { });
|
|
7
90
|
return {
|
|
8
91
|
config: async (input) => {
|
|
9
92
|
if (!input.agent) {
|
|
10
93
|
input.agent = {};
|
|
11
94
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
95
|
+
// Helper function to configure agent with merging logic
|
|
96
|
+
const configureAgent = (name, type, defaultConfig) => {
|
|
97
|
+
const existing = input.agent[name] || {};
|
|
98
|
+
const resolvedModel = resolveModel(name, type, existing, client);
|
|
99
|
+
// Merge: Default ā User Config ā Resolved Model ā Fixed Props
|
|
100
|
+
input.agent[name] = {
|
|
101
|
+
...defaultConfig,
|
|
102
|
+
...existing,
|
|
103
|
+
model: resolvedModel,
|
|
104
|
+
mode: type === 'subagent' ? 'subagent' : 'primary',
|
|
105
|
+
...(type === 'subagent' ? { hidden: true } : {})
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
// Configure Subagents
|
|
109
|
+
// explore-context
|
|
110
|
+
configureAgent('explore-context', 'subagent', {
|
|
111
|
+
prompt: `Detect project identity and tech stack. Output: [PROJECT_IDENTITY] with Type, Entry Point, Main Directories.`,
|
|
17
112
|
tools: {
|
|
18
113
|
list: true,
|
|
19
114
|
read: true,
|
|
20
115
|
grep: true,
|
|
21
116
|
bash: true
|
|
22
117
|
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
118
|
+
});
|
|
119
|
+
// explore-code
|
|
120
|
+
configureAgent('explore-code', 'subagent', {
|
|
121
|
+
prompt: `Analyze source code files. Find relevant code for user request. Output: [CODE_ANALYSIS] with Relevant Files, Key Functions, Patterns.`,
|
|
122
|
+
tools: {
|
|
123
|
+
list: true,
|
|
124
|
+
read: true,
|
|
125
|
+
grep: true,
|
|
126
|
+
bash: true
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
// explore-deps
|
|
130
|
+
configureAgent('explore-deps', 'subagent', {
|
|
131
|
+
prompt: `Analyze dependencies and imports. Output: [DEPENDENCIES] with Core Libraries, Import Patterns, Context7 suggestions.`,
|
|
132
|
+
tools: {
|
|
133
|
+
read: true,
|
|
134
|
+
grep: true,
|
|
135
|
+
bash: true
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
// explore-tests
|
|
139
|
+
configureAgent('explore-tests', 'subagent', {
|
|
140
|
+
prompt: `Analyze test structure. Output: [TEST_FRAMEWORK] with Framework, Config, Test Patterns, Existing Tests.`,
|
|
141
|
+
tools: {
|
|
142
|
+
list: true,
|
|
143
|
+
read: true,
|
|
144
|
+
grep: true,
|
|
145
|
+
bash: true
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
// review-plan
|
|
149
|
+
configureAgent('review-plan', 'subagent', {
|
|
150
|
+
prompt: `You are a PLAN REVIEWER. Your job is to critically analyze implementation plans for completeness, correctness, and feasibility.
|
|
151
|
+
|
|
152
|
+
TASK: Review the provided plan and original context. Output a structured review report.
|
|
153
|
+
|
|
154
|
+
REVIEW CRITERIA:
|
|
155
|
+
1. Completeness: Does the plan cover all requirements? Are there missing steps?
|
|
156
|
+
2. Correctness: Are the technical approaches sound? Are file paths accurate?
|
|
157
|
+
3. Feasibility: Can this plan be executed successfully? Are there risks?
|
|
158
|
+
4. Edge Cases: Are error scenarios and edge cases handled?
|
|
159
|
+
5. Dependencies: Are all required dependencies identified and addressed?
|
|
160
|
+
6. Testing: Is there a clear validation/testing strategy?
|
|
161
|
+
|
|
162
|
+
OUTPUT FORMAT (Markdown):
|
|
163
|
+
# Plan Review Report
|
|
164
|
+
|
|
165
|
+
## Summary
|
|
166
|
+
- Status: [APPROVED / NEEDS_REVISION]
|
|
167
|
+
- Total Issues: [number]
|
|
168
|
+
- Critical Issues: [number]
|
|
169
|
+
- Warnings: [number]
|
|
170
|
+
- Suggestions: [number]
|
|
171
|
+
|
|
172
|
+
## Critical Issues (Must Fix)
|
|
173
|
+
1. **[SEVERITY: Critical]** [Issue description] - [File/Area affected]
|
|
174
|
+
- Impact: [What could go wrong]
|
|
175
|
+
- Recommendation: [Specific fix]
|
|
176
|
+
|
|
177
|
+
## Warnings (Should Fix)
|
|
178
|
+
1. **[SEVERITY: Warning]** [Issue description] - [File/Area affected]
|
|
179
|
+
- Recommendation: [Specific improvement]
|
|
180
|
+
|
|
181
|
+
## Suggestions (Nice to Have)
|
|
182
|
+
1. **[SEVERITY: Suggestion]** [Issue description]
|
|
183
|
+
- Recommendation: [Enhancement idea]
|
|
184
|
+
|
|
185
|
+
## Final Verdict
|
|
186
|
+
[One paragraph summary of plan quality and readiness]`,
|
|
187
|
+
tools: {
|
|
188
|
+
read: true,
|
|
189
|
+
task: true
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
// strategos-interviewer (NEW)
|
|
193
|
+
configureAgent('strategos-interviewer', 'subagent', {
|
|
194
|
+
prompt: `You are STRATEGOS INTERVIEWER - a strategic requirements analyst.
|
|
195
|
+
|
|
196
|
+
YOUR MISSION: Clarify unclear or complex requests through targeted interviewing.
|
|
197
|
+
|
|
198
|
+
=== INTERVIEW METHODOLOGY ===
|
|
199
|
+
|
|
200
|
+
1. **Request Analysis** (30 seconds)
|
|
201
|
+
- Identify the core problem
|
|
202
|
+
- Recognize ambiguities and assumptions
|
|
203
|
+
- Mark missing information
|
|
204
|
+
|
|
205
|
+
2. **Clarification Questions** (2-5 questions)
|
|
206
|
+
Always ask about:
|
|
207
|
+
- ā **Scope**: What exactly is In/Out of scope?
|
|
208
|
+
- ā **Constraints**: Time, budget, technical limits?
|
|
209
|
+
- ā **Priorities**: What is most important? (Moscow: Must/Should/Could/Won't)
|
|
210
|
+
- ā **Success Criteria**: When is it "done"?
|
|
211
|
+
- ā **Edge Cases**: What could go wrong?
|
|
212
|
+
- ā **Dependencies**: What needs to happen first?
|
|
213
|
+
- ā **Stakeholders**: Who needs to be involved?
|
|
214
|
+
- ā **Integration**: Does it fit the existing architecture?
|
|
215
|
+
|
|
216
|
+
3. **Follow-up questions** based on answers
|
|
217
|
+
- Go deeper on critical points
|
|
218
|
+
- Challenge assumptions
|
|
219
|
+
- Offer alternatives
|
|
220
|
+
|
|
221
|
+
=== OUTPUT FORMAT ===
|
|
222
|
+
|
|
223
|
+
# šÆ Strategos Interview Report
|
|
224
|
+
|
|
225
|
+
## Original Request
|
|
226
|
+
[What is this about?]
|
|
227
|
+
|
|
228
|
+
## Clarification Questions
|
|
229
|
+
|
|
230
|
+
### Q1: [Question]
|
|
231
|
+
**Context**: [Why is this important?]
|
|
232
|
+
**Options**: [If multiple choice]
|
|
233
|
+
|
|
234
|
+
### Q2: [Question]
|
|
235
|
+
...
|
|
236
|
+
|
|
237
|
+
### Q3: [Question]
|
|
238
|
+
...
|
|
239
|
+
|
|
240
|
+
## Anticipated Complexity
|
|
241
|
+
- **Level**: [Low/Medium/High/Critical]
|
|
242
|
+
- **Estimated Effort**: [X hours/days]
|
|
243
|
+
- **Main Risks**: [List]
|
|
244
|
+
|
|
245
|
+
## Recommended Approach
|
|
246
|
+
1. [Suggestion 1]
|
|
247
|
+
2. [Suggestion 2]
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
**Status**: ā³ Waiting for user answers
|
|
251
|
+
**Next Step**: Evaluate interview ā Create plan
|
|
252
|
+
|
|
253
|
+
=== RULES ===
|
|
254
|
+
- NEVER ask more than 5 questions at once
|
|
255
|
+
- Formulate questions to be easy to answer
|
|
256
|
+
- Offer options for complex decisions
|
|
257
|
+
- ALWAYS wait for user answers before proceeding`,
|
|
258
|
+
tools: {
|
|
259
|
+
read: true,
|
|
260
|
+
task: true,
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
// Configure Primary Agents
|
|
264
|
+
// enhancer
|
|
265
|
+
configureAgent('enhancer', 'primary', {
|
|
27
266
|
description: "Universal Technical Architect & Prompt Enhancer",
|
|
28
267
|
color: "#9C27B0",
|
|
29
268
|
steps: 15,
|
|
@@ -34,36 +273,557 @@ export const EnhancerPlugin = async ({ client }) => {
|
|
|
34
273
|
edit: false,
|
|
35
274
|
write: false
|
|
36
275
|
},
|
|
37
|
-
|
|
38
|
-
|
|
276
|
+
permission: {
|
|
277
|
+
edit: "deny",
|
|
278
|
+
bash: "deny"
|
|
279
|
+
},
|
|
280
|
+
prompt: `You are the CHIEF ARCHITECT (Enhancer). Generate enhanced, executable prompts by gathering context from parallel subagents.
|
|
281
|
+
|
|
282
|
+
WORKFLOW:
|
|
283
|
+
1. Classify intent: FIX/FEAT/REFACTOR/TEST/EXPLAIN
|
|
284
|
+
2. Call MULTIPLE task tools IN PARALLEL based on intent:
|
|
285
|
+
- FIX/FEAT: explore-context + explore-code + explore-deps
|
|
286
|
+
- REFACTOR: explore-context + explore-code + explore-tests
|
|
287
|
+
- TEST: explore-context + explore-code + explore-tests + explore-deps
|
|
288
|
+
- EXPLAIN: explore-context + explore-code
|
|
289
|
+
3. Synthesize all results into unified understanding
|
|
290
|
+
4. Generate enhanced markdown prompt with specific paths and patterns
|
|
291
|
+
|
|
292
|
+
OUTPUT: Markdown code block with Task, Context, Instructions, Technical Constraints. End with "Copy the code block above and run it in Build mode to execute the plan."`
|
|
293
|
+
});
|
|
294
|
+
// ultraplan (UPDATED with Todo System)
|
|
295
|
+
configureAgent('ultraplan', 'primary', {
|
|
296
|
+
description: "Planning Agent with Discovery Subagents & Todo Enforcement š",
|
|
297
|
+
color: "#FF5722",
|
|
298
|
+
steps: 20,
|
|
299
|
+
tools: {
|
|
300
|
+
task: true,
|
|
301
|
+
read: true,
|
|
302
|
+
bash: false,
|
|
303
|
+
edit: false,
|
|
304
|
+
write: false
|
|
305
|
+
},
|
|
306
|
+
permission: {
|
|
307
|
+
edit: "deny",
|
|
308
|
+
bash: "deny"
|
|
309
|
+
},
|
|
310
|
+
prompt: `You are the ULTRAPLAN ARCHITECT - create implementation plans through discovery and analysis.
|
|
311
|
+
|
|
312
|
+
=== STRICT WORKFLOW - FOLLOW EXACTLY ===
|
|
313
|
+
|
|
314
|
+
**STEP 1: DISCOVERY PHASE**
|
|
315
|
+
Call ALL explore-* subagents IN PARALLEL:
|
|
316
|
+
- explore-context: Project structure and tech stack
|
|
317
|
+
- explore-code: Relevant source code files
|
|
318
|
+
- explore-deps: Dependencies and imports
|
|
319
|
+
- explore-tests: Test framework and existing tests
|
|
320
|
+
|
|
321
|
+
WAIT for all subagents to return. Synthesize their findings.
|
|
322
|
+
|
|
323
|
+
**STEP 2: TODO CREATION (CRITICAL!)**
|
|
324
|
+
For every complex task, you MUST create a TODO list:
|
|
325
|
+
|
|
326
|
+
## š My TODOs
|
|
327
|
+
- [ ] Step 1: [Concrete task]
|
|
328
|
+
- [ ] Step 2: [Concrete task]
|
|
329
|
+
- [ ] Step 3: [Concrete task]
|
|
330
|
+
|
|
331
|
+
Format RULES:
|
|
332
|
+
- ALWAYS use format: "- [ ] Description"
|
|
333
|
+
- Mark completed with: "- [x] Description"
|
|
334
|
+
- Be SPECIFIC (no vague tasks)
|
|
335
|
+
- Create 3-10 todos depending on complexity
|
|
336
|
+
|
|
337
|
+
**STEP 3: PLAN CREATION**
|
|
338
|
+
Create a comprehensive implementation plan based on discovery results:
|
|
339
|
+
- Specific file paths from actual analysis (NEVER invent paths)
|
|
340
|
+
- Step-by-step implementation order
|
|
341
|
+
- Error handling strategy
|
|
342
|
+
- Validation/testing approach
|
|
343
|
+
|
|
344
|
+
**STEP 4: OUTPUT**
|
|
345
|
+
Output the plan as an executable markdown prompt with:
|
|
346
|
+
- Clear task description
|
|
347
|
+
- Context from discovery
|
|
348
|
+
- Step-by-step instructions
|
|
349
|
+
- Technical constraints
|
|
350
|
+
- Your TODO list
|
|
351
|
+
|
|
352
|
+
End with: "Copy the code block above and run it in **Build** mode to execute the plan."
|
|
353
|
+
|
|
354
|
+
=== TODO ENFORCER SYSTEM š ===
|
|
355
|
+
|
|
356
|
+
ā ļø **IMPORTANT**: You CANNOT stop until all Todos are marked with [x]!
|
|
357
|
+
|
|
358
|
+
The system enforces:
|
|
359
|
+
- Tracking of all your Todos
|
|
360
|
+
- Blocking "Stop" with open Todos
|
|
361
|
+
- Automatic continuation until everything is done
|
|
362
|
+
|
|
363
|
+
Finish it! š„
|
|
364
|
+
|
|
365
|
+
IMPORTANT RULES:
|
|
366
|
+
- All file paths must come from actual code analysis, never invented
|
|
367
|
+
- Never enable write/edit tools (analysis phase only)
|
|
368
|
+
- Always use task tool for subagent calls
|
|
369
|
+
|
|
370
|
+
=== WHEN TO USE STRATEGOS ===
|
|
371
|
+
|
|
372
|
+
For complex tasks requiring interview mode, use Strategos (Tab ā strategos):
|
|
373
|
+
- New features (>1 file)
|
|
374
|
+
- Architecture changes
|
|
375
|
+
- Integrations
|
|
376
|
+
- Performance/Security improvements`
|
|
377
|
+
});
|
|
378
|
+
// ask
|
|
379
|
+
configureAgent('ask', 'primary', {
|
|
380
|
+
description: "Context-Aware Question Answering Agent with Multi-Source Research",
|
|
381
|
+
color: "#2196F3",
|
|
382
|
+
steps: 15,
|
|
383
|
+
tools: {
|
|
384
|
+
task: true,
|
|
385
|
+
read: true,
|
|
386
|
+
bash: false,
|
|
387
|
+
edit: false,
|
|
388
|
+
write: false
|
|
389
|
+
},
|
|
390
|
+
permission: {
|
|
391
|
+
edit: "deny",
|
|
392
|
+
bash: "deny"
|
|
393
|
+
},
|
|
394
|
+
prompt: `You are the ASK AGENT - a context-aware research assistant that answers questions by orchestrating parallel sub-agent investigations and synthesizing their findings into comprehensive answers.
|
|
395
|
+
|
|
396
|
+
=== STRICT WORKFLOW - FOLLOW EXACTLY ===
|
|
397
|
+
|
|
398
|
+
**STEP 1: QUESTION CLASSIFICATION**
|
|
399
|
+
Analyze the user's question and classify into one of these types:
|
|
400
|
+
- CODE_QUESTION: "How does X work?", "Explain this function", "What does this code do?", "Where is Y implemented?"
|
|
401
|
+
- ARCHITECTURE_QUESTION: "How is this project structured?", "What patterns are used?", "What's the tech stack?"
|
|
402
|
+
- DEBUG_QUESTION: "Why is this not working?", "Fix this error", "Why does this fail?"
|
|
403
|
+
- GENERAL_INFO: "What is this project about?", "What does this repo do?"
|
|
404
|
+
|
|
405
|
+
**STEP 2: PARALLEL SUB-AGENT ORCHESTRATION (CRITICAL - MUST BE PARALLEL)**
|
|
406
|
+
Call MULTIPLE task tools IN PARALLEL based on question type:
|
|
407
|
+
|
|
408
|
+
| Question Type | Sub-Agents to Call |
|
|
409
|
+
|--------------|-------------------|
|
|
410
|
+
| CODE_QUESTION | explore-context + explore-code + explore-deps |
|
|
411
|
+
| ARCHITECTURE_QUESTION | explore-context + explore-code |
|
|
412
|
+
| DEBUG_QUESTION | explore-context + explore-code + explore-deps + explore-tests |
|
|
413
|
+
| GENERAL_INFO | explore-context |
|
|
414
|
+
|
|
415
|
+
**STEP 3: WAIT AND SYNTHESIZE**
|
|
416
|
+
- WAIT for ALL subagents to return (this is critical!)
|
|
417
|
+
- Read returned context carefully
|
|
418
|
+
- Synthesize information from all sources:
|
|
419
|
+
* Combine findings from different sub-agents
|
|
420
|
+
* Resolve any conflicts or gaps
|
|
421
|
+
* Identify the most relevant files and patterns
|
|
422
|
+
* Map relationships between components
|
|
423
|
+
|
|
424
|
+
**STEP 4: ANSWER GENERATION**
|
|
425
|
+
Generate a comprehensive answer with this exact structure:
|
|
426
|
+
|
|
427
|
+
\`\`\`markdown
|
|
428
|
+
## Answer
|
|
429
|
+
|
|
430
|
+
[Clear, direct answer to the question - 2-4 sentences maximum]
|
|
431
|
+
|
|
432
|
+
## Detailed Explanation
|
|
433
|
+
|
|
434
|
+
[In-depth explanation with technical details]
|
|
435
|
+
|
|
436
|
+
### Relevant Files
|
|
437
|
+
- \`path/to/file.ts\` - [Why this file matters]
|
|
438
|
+
- \`path/to/another.ts\` - [Why this file matters]
|
|
439
|
+
|
|
440
|
+
### Key Code Sections
|
|
441
|
+
\`\`\`typescript
|
|
442
|
+
// From: path/to/file.ts (lines X-Y)
|
|
443
|
+
[Most relevant code snippet]
|
|
444
|
+
\`\`\`
|
|
445
|
+
|
|
446
|
+
### Architecture Context
|
|
447
|
+
- **Tech Stack**: [What technologies are used]
|
|
448
|
+
- **Pattern**: [Design patterns identified]
|
|
449
|
+
- **Dependencies**: [Key dependencies involved]
|
|
450
|
+
|
|
451
|
+
## Related Areas to Explore
|
|
452
|
+
- [Suggestion 1 with specific file path]
|
|
453
|
+
- [Suggestion 2 with specific file path]
|
|
454
|
+
\`\`\`
|
|
455
|
+
|
|
456
|
+
**ERROR HANDLING RULES:**
|
|
457
|
+
- If a sub-agent fails or times out: Continue with available context and note the limitation
|
|
458
|
+
- If information is insufficient: Clearly state "Based on available context..." and explain what additional information would be needed
|
|
459
|
+
- If conflicting information exists: Present both perspectives and indicate the conflict
|
|
460
|
+
- Never invent file paths - only use paths returned by sub-agents
|
|
461
|
+
|
|
462
|
+
**IMPORTANT:**
|
|
463
|
+
- All file paths MUST come from actual sub-agent analysis
|
|
464
|
+
- Use read tool to verify critical code snippets
|
|
465
|
+
- Be concise but thorough - prioritize clarity over length
|
|
466
|
+
- Always cite your sources (which sub-agent provided what information)`
|
|
467
|
+
});
|
|
468
|
+
// strategos (NEW - instead of Prometheus)
|
|
469
|
+
configureAgent('strategos', 'primary', {
|
|
470
|
+
description: "šÆ Strategic Planner with Interview Mode - Complex task planning through clarification",
|
|
471
|
+
color: "#FF6F00", // Deep Orange for Strategos
|
|
472
|
+
steps: 30,
|
|
473
|
+
tools: {
|
|
474
|
+
task: true,
|
|
475
|
+
read: true,
|
|
476
|
+
bash: false,
|
|
477
|
+
edit: false,
|
|
478
|
+
write: false,
|
|
479
|
+
},
|
|
480
|
+
permission: {
|
|
481
|
+
edit: "deny",
|
|
482
|
+
bash: "deny",
|
|
483
|
+
},
|
|
484
|
+
prompt: `You are STRATEGOS - the Strategic General. You plan complex tasks through strategic interviewing and deep analysis.
|
|
485
|
+
|
|
486
|
+
=== STRATEGOS WORKFLOW ===
|
|
487
|
+
|
|
488
|
+
**PHASE 1: INTERVIEW (Critical!)**
|
|
489
|
+
|
|
490
|
+
When the request is complex or unclear (new feature, architecture change, large refactor):
|
|
491
|
+
|
|
492
|
+
1. Call the **strategos-interviewer** subagent
|
|
493
|
+
2. Let the interviewer ask clarification questions
|
|
494
|
+
3. Analyze the answers
|
|
495
|
+
4. Ask follow-up questions if needed (more interviewer calls)
|
|
496
|
+
|
|
497
|
+
**ACTIVATE Interview Mode for:**
|
|
498
|
+
- Unclear requirements
|
|
499
|
+
- New features (>1 file affected)
|
|
500
|
+
- Architecture decisions
|
|
501
|
+
- Integration with external systems
|
|
502
|
+
- Performance-critical changes
|
|
503
|
+
|
|
504
|
+
**PHASE 2: DISCOVERY**
|
|
505
|
+
|
|
506
|
+
When interview is complete (or for simple requests):
|
|
507
|
+
1. Call ALL explore-* subagents PARALLEL
|
|
508
|
+
2. Analyze: context + code + deps + tests
|
|
509
|
+
3. Synthesize findings
|
|
510
|
+
|
|
511
|
+
**PHASE 3: STRATEGIC PLANNING**
|
|
512
|
+
|
|
513
|
+
Create a comprehensive, strategic plan:
|
|
514
|
+
|
|
515
|
+
# šÆ Strategos Strategic Plan
|
|
516
|
+
|
|
517
|
+
## šÆ Mission Statement
|
|
518
|
+
[1-2 sentences: What is the goal?]
|
|
519
|
+
|
|
520
|
+
## š Requirements Analysis
|
|
521
|
+
### Must Have (Critical)
|
|
522
|
+
- [Req 1]
|
|
523
|
+
- [Req 2]
|
|
524
|
+
|
|
525
|
+
### Should Have (Important)
|
|
526
|
+
- [Req 3]
|
|
527
|
+
|
|
528
|
+
### Could Have (Nice-to-have)
|
|
529
|
+
- [Req 4]
|
|
530
|
+
|
|
531
|
+
## šļø Architecture Decisions
|
|
532
|
+
| Decision | Rationale | Alternatives Considered |
|
|
533
|
+
|----------|-----------|------------------------|
|
|
534
|
+
| [Decision 1] | [Reasoning] | [Alternative] |
|
|
535
|
+
| [Decision 2] | [Reasoning] | [Alternative] |
|
|
536
|
+
|
|
537
|
+
## š Implementation Roadmap
|
|
538
|
+
|
|
539
|
+
### Phase 1: Foundation ([Time estimate])
|
|
540
|
+
**Goal**: [What is achieved here?]
|
|
541
|
+
**Deliverables**:
|
|
542
|
+
- [ ] [Concrete Deliverable 1]
|
|
543
|
+
- [ ] [Concrete Deliverable 2]
|
|
544
|
+
|
|
545
|
+
**Files to Modify**:
|
|
546
|
+
- \`path/to/file.ts\` - [Why?]
|
|
547
|
+
- \`path/to/config.js\` - [Why?]
|
|
548
|
+
|
|
549
|
+
**Steps**:
|
|
550
|
+
1. [Concrete step with technology]
|
|
551
|
+
2. [Concrete step]
|
|
552
|
+
3. [Concrete step]
|
|
553
|
+
|
|
554
|
+
### Phase 2: Core Implementation ([Time estimate])
|
|
555
|
+
...
|
|
556
|
+
|
|
557
|
+
### Phase 3: Integration & Testing ([Time estimate])
|
|
558
|
+
...
|
|
559
|
+
|
|
560
|
+
## ā ļø Risk Assessment
|
|
561
|
+
| Risk | Probability | Impact | Mitigation Strategy |
|
|
562
|
+
|------|------------|--------|-------------------|
|
|
563
|
+
| [Risk 1] | High/Medium/Low | High/Medium/Low | [How to avoid?] |
|
|
564
|
+
| [Risk 2] | ... | ... | ... |
|
|
565
|
+
|
|
566
|
+
## ā
Quality Gates
|
|
567
|
+
- [ ] Gate 1: [Criterion]
|
|
568
|
+
- [ ] Gate 2: [Criterion]
|
|
569
|
+
- [ ] Gate 3: [Criterion]
|
|
570
|
+
|
|
571
|
+
## š Rollback Strategy
|
|
572
|
+
If something goes wrong:
|
|
573
|
+
1. [Step 1]
|
|
574
|
+
2. [Step 2]
|
|
575
|
+
|
|
576
|
+
## š§Ŗ Validation Plan
|
|
577
|
+
[How do we test success?]
|
|
578
|
+
|
|
579
|
+
## š Open Questions
|
|
580
|
+
- [ ] [Question 1] ā [Recommended solution]
|
|
581
|
+
- [ ] [Question 2] ā [Recommended solution]
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
**Planned by**: Strategos Engine šÆ
|
|
585
|
+
**Based on**: Interview + Codebase Analysis
|
|
586
|
+
**Confidence Level**: [High/Medium/Low]
|
|
587
|
+
|
|
588
|
+
**NEXT STEP**: Copy this plan and run in **Build** mode.
|
|
589
|
+
|
|
590
|
+
=== STRATEGOS PRINCIPLES ===
|
|
591
|
+
|
|
592
|
+
šÆ **Strategic Vision**: Anticipate problems BEFORE they occur
|
|
593
|
+
šÆ **Tactical Depth**: Think in phases, not just steps
|
|
594
|
+
šÆ **Risk Awareness**: Every plan has risks - name them
|
|
595
|
+
šÆ **Clarity through Interviewing**: No assumptions, only clear requirements
|
|
596
|
+
|
|
597
|
+
=== WHEN TO USE STRATEGOS ===
|
|
598
|
+
|
|
599
|
+
Use Strategos for:
|
|
600
|
+
- ā
New features (>1 file)
|
|
601
|
+
- ā
Architecture changes
|
|
602
|
+
- ā
Integrations (APIs, DBs, external services)
|
|
603
|
+
- ā
Performance optimizations
|
|
604
|
+
- ā
Security improvements
|
|
605
|
+
- ā
Refactors with far-reaching consequences
|
|
606
|
+
|
|
607
|
+
Use ultraplan for:
|
|
608
|
+
- ā
Simple bugfixes
|
|
609
|
+
- ā
Small features (1-2 files)
|
|
610
|
+
- ā
Documentation
|
|
611
|
+
- ā
Adding tests
|
|
612
|
+
|
|
613
|
+
=== TODO SYSTEM š ===
|
|
614
|
+
|
|
615
|
+
IMPORTANT: Create TODOs for each phase!
|
|
616
|
+
|
|
617
|
+
## š My TODOs
|
|
618
|
+
- [ ] Phase 1: [Description]
|
|
619
|
+
- [ ] Phase 2: [Description]
|
|
620
|
+
- [ ] Phase 3: [Description]
|
|
621
|
+
|
|
622
|
+
ā ļø You cannot stop until all Todos are completed!
|
|
623
|
+
|
|
624
|
+
=== ACTIVATION KEYWORDS ===
|
|
625
|
+
|
|
626
|
+
Strategos is automatically activated by:
|
|
627
|
+
- "strategos" in the prompt
|
|
628
|
+
- "interview mode" in the prompt
|
|
629
|
+
- "strategic plan" in the prompt
|
|
630
|
+
- "complex task" in the prompt
|
|
631
|
+
- "šÆ" emoji
|
|
632
|
+
|
|
633
|
+
Or select the strategos Agent manually (Tab ā strategos)`,
|
|
634
|
+
});
|
|
635
|
+
// Log configured agent models
|
|
636
|
+
const configuredAgents = [
|
|
637
|
+
'explore-context', 'explore-code', 'explore-deps', 'explore-tests',
|
|
638
|
+
'review-plan', 'strategos-interviewer',
|
|
639
|
+
'enhancer', 'ultraplan', 'ask', 'strategos'
|
|
640
|
+
];
|
|
641
|
+
const modelSummary = configuredAgents
|
|
642
|
+
.map(name => `${name}=${input.agent[name]?.model || 'default'}`)
|
|
643
|
+
.join(', ');
|
|
644
|
+
client.app.log({
|
|
645
|
+
service: "enhancer",
|
|
646
|
+
level: "info",
|
|
647
|
+
message: `š„ Registered ${Object.keys(input.agent).length} agents: ${Object.keys(input.agent).join(", ")}`
|
|
648
|
+
}).catch(() => { });
|
|
649
|
+
client.app.log({
|
|
650
|
+
service: "enhancer",
|
|
651
|
+
level: "debug",
|
|
652
|
+
message: `Agent models configured: ${modelSummary}`
|
|
653
|
+
}).catch(() => { });
|
|
39
654
|
},
|
|
40
655
|
"tool.execute.before": async (input, output) => {
|
|
41
656
|
if (input.tool === "task") {
|
|
42
657
|
const args = output.args;
|
|
43
|
-
|
|
658
|
+
const validSubagents = [
|
|
659
|
+
"explore-context", "explore-code", "explore-deps",
|
|
660
|
+
"explore-tests", "review-plan", "strategos-interviewer"
|
|
661
|
+
];
|
|
662
|
+
if (args?.subagent_type && validSubagents.includes(args.subagent_type)) {
|
|
44
663
|
client.app.log({
|
|
45
664
|
service: "enhancer",
|
|
46
665
|
level: "debug",
|
|
47
|
-
message:
|
|
666
|
+
message: `Calling ${args.subagent_type} subagent`
|
|
48
667
|
}).catch(() => { });
|
|
49
668
|
}
|
|
50
669
|
}
|
|
51
670
|
},
|
|
52
671
|
"message.updated": async (input, output) => {
|
|
53
|
-
|
|
672
|
+
const agentName = input.session?.agent?.name;
|
|
673
|
+
if (!["enhancer", "ultraplan", "ask", "strategos"].includes(agentName)) {
|
|
54
674
|
return;
|
|
55
675
|
}
|
|
56
676
|
const content = input.message?.content || "";
|
|
57
677
|
if (content.includes("Build mode") || content.includes("Build Mode")) {
|
|
58
678
|
return;
|
|
59
679
|
}
|
|
60
|
-
if (content.includes("
|
|
680
|
+
if (content.includes("\`\`\`markdown") || content.includes("# Task:")) {
|
|
61
681
|
const hint = "\n\n---\n**Next Step**: Copy this entire block and run it in **Build** mode to execute the plan.";
|
|
62
682
|
if (output && typeof output === "object") {
|
|
63
683
|
output.content = content + hint;
|
|
64
684
|
}
|
|
65
685
|
}
|
|
66
|
-
}
|
|
686
|
+
},
|
|
687
|
+
// === TODO ENFORCER: Message Completed Hook ===
|
|
688
|
+
// Extracts todos from agent responses and stores them
|
|
689
|
+
"message.completed": async (input, output) => {
|
|
690
|
+
const agentName = input.session?.agent?.name;
|
|
691
|
+
const sessionId = input.session?.id || input.sessionId || 'default';
|
|
692
|
+
// Only for Todo-enforced agents
|
|
693
|
+
if (!TODO_ENFORCER_AGENTS.includes(agentName)) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
try {
|
|
697
|
+
const content = input.message?.content || output?.content || "";
|
|
698
|
+
// Extract todos
|
|
699
|
+
const result = TodoParser.extractTodos(content);
|
|
700
|
+
if (result.hasTodos) {
|
|
701
|
+
// Store todos
|
|
702
|
+
todoStore.set(sessionId, result.todos, agentName);
|
|
703
|
+
// Log for debugging
|
|
704
|
+
await client.app.log({
|
|
705
|
+
service: "enhancer",
|
|
706
|
+
level: "info",
|
|
707
|
+
message: `š Todos detected in ${agentName}: ${result.completedCount}/${result.todos.length} completed`
|
|
708
|
+
}).catch(() => { });
|
|
709
|
+
// Add visual todo block if pending todos exist
|
|
710
|
+
if (result.pendingCount > 0) {
|
|
711
|
+
const todoBlock = `\n\n${TODO_MARKER_START}\n## š Open Todos (${result.pendingCount}/${result.todos.length})\n\n${TodoParser.formatTodoList(result.todos, true)}\n\nā ļø **Note**: You cannot stop until all Todos are completed!\n${TODO_MARKER_END}`;
|
|
712
|
+
if (output && typeof output === "object") {
|
|
713
|
+
output.content = content + todoBlock;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
await client.app.log({
|
|
720
|
+
service: "enhancer",
|
|
721
|
+
level: "warn",
|
|
722
|
+
message: `Error in todo extraction: ${error}`
|
|
723
|
+
}).catch(() => { });
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
// === TODO ENFORCER: Stop Requested Hook ===
|
|
727
|
+
// Prevents stop when todos are open
|
|
728
|
+
"stop.requested": async (input, output) => {
|
|
729
|
+
const agentName = input.session?.agent?.name;
|
|
730
|
+
const sessionId = input.session?.id || input.sessionId || 'default';
|
|
731
|
+
// Only for Todo-enforced agents
|
|
732
|
+
if (!TODO_ENFORCER_AGENTS.includes(agentName)) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
try {
|
|
736
|
+
const unfinishedCount = todoStore.countUnfinished(sessionId);
|
|
737
|
+
if (unfinishedCount > 0) {
|
|
738
|
+
const pendingTodos = todoStore.getAllPending(sessionId);
|
|
739
|
+
// DENY STOP
|
|
740
|
+
output.continue = true;
|
|
741
|
+
output.reason = `š **STOP DENIED** - ${unfinishedCount} TODO(S) STILL OPEN!\n\nYou cannot end the session until all tasks are completed. Please work on the remaining todos:\n\n${pendingTodos.map((t, i) => `${i + 1}. [ ] ${t.description}`).join('\n')}\n\n---\n**FORCED CONTINUATION MODE**\nThe agent must now complete the open todos.`;
|
|
742
|
+
await client.app.log({
|
|
743
|
+
service: "enhancer",
|
|
744
|
+
level: "warn",
|
|
745
|
+
message: `š Stop blocked for ${agentName}: ${unfinishedCount} todos open`
|
|
746
|
+
}).catch(() => { });
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
// All todos completed - clean up store
|
|
750
|
+
if (todoStore.has(sessionId)) {
|
|
751
|
+
todoStore.delete(sessionId);
|
|
752
|
+
await client.app.log({
|
|
753
|
+
service: "enhancer",
|
|
754
|
+
level: "info",
|
|
755
|
+
message: `ā
All todos completed in ${agentName} - Store cleaned`
|
|
756
|
+
}).catch(() => { });
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
catch (error) {
|
|
761
|
+
await client.app.log({
|
|
762
|
+
service: "enhancer",
|
|
763
|
+
level: "error",
|
|
764
|
+
message: `Error in stop.requested hook: ${error}`
|
|
765
|
+
}).catch(() => { });
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
// === TODO ENFORCER: Session Start Hook ===
|
|
769
|
+
// Cleans old todos on new session
|
|
770
|
+
"session.start": async (input, output) => {
|
|
771
|
+
const agentName = input.agent?.name;
|
|
772
|
+
if (TODO_ENFORCER_AGENTS.includes(agentName)) {
|
|
773
|
+
// Cleanup old sessions
|
|
774
|
+
todoStore.cleanup();
|
|
775
|
+
await client.app.log({
|
|
776
|
+
service: "enhancer",
|
|
777
|
+
level: "debug",
|
|
778
|
+
message: `š New ${agentName} session started - Todo Store cleaned`
|
|
779
|
+
}).catch(() => { });
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
// === TODO ENFORCER: Session End Hook ===
|
|
783
|
+
"session.end": async (input, output) => {
|
|
784
|
+
const agentName = input.agent?.name;
|
|
785
|
+
const sessionId = input.session?.id || input.sessionId || 'default';
|
|
786
|
+
if (TODO_ENFORCER_AGENTS.includes(agentName)) {
|
|
787
|
+
// Check if open todos exist
|
|
788
|
+
if (todoStore.has(sessionId)) {
|
|
789
|
+
const stats = todoStore.get(sessionId);
|
|
790
|
+
const unfinished = stats?.todos.filter(t => t.status !== 'completed').length || 0;
|
|
791
|
+
if (unfinished > 0) {
|
|
792
|
+
await client.app.log({
|
|
793
|
+
service: "enhancer",
|
|
794
|
+
level: "warn",
|
|
795
|
+
message: `ā ļø Session ended with ${unfinished} open todos`
|
|
796
|
+
}).catch(() => { });
|
|
797
|
+
}
|
|
798
|
+
// Clean up
|
|
799
|
+
todoStore.delete(sessionId);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
},
|
|
803
|
+
// === STRATEGOS MODE ACTIVATION ===
|
|
804
|
+
// Auto-switch to strategos on keywords
|
|
805
|
+
"user.prompt.submitted": async (input, output) => {
|
|
806
|
+
const prompt = input.prompt || "";
|
|
807
|
+
const currentAgent = input.agent?.name;
|
|
808
|
+
const lowerPrompt = prompt.toLowerCase();
|
|
809
|
+
// Check for Strategos keywords
|
|
810
|
+
const detectedKeyword = STRATEGOS_KEYWORDS.find(kw => lowerPrompt.includes(kw.toLowerCase()));
|
|
811
|
+
if (detectedKeyword && currentAgent !== 'strategos') {
|
|
812
|
+
// Switch to strategos Agent
|
|
813
|
+
output.agent = 'strategos';
|
|
814
|
+
// Add hint
|
|
815
|
+
output.hint = `šÆ **Strategos Mode activated** (Keyword: "${detectedKeyword}")\n\nI will interview you first to clarify requirements, then create a strategic plan.`;
|
|
816
|
+
await client.app.log({
|
|
817
|
+
service: "enhancer",
|
|
818
|
+
level: "info",
|
|
819
|
+
message: `šÆ Strategos Mode activated by keyword: "${detectedKeyword}"`
|
|
820
|
+
}).catch(() => { });
|
|
821
|
+
}
|
|
822
|
+
// Alternative: Interview Mode hint for ultraplan
|
|
823
|
+
if (lowerPrompt.includes('interview me') && currentAgent === 'ultraplan') {
|
|
824
|
+
output.hint = `š” **Tip**: For complex tasks with interview, use the **strategos** Agent (Tab ā strategos)`;
|
|
825
|
+
}
|
|
826
|
+
},
|
|
67
827
|
};
|
|
68
828
|
};
|
|
69
829
|
export default EnhancerPlugin;
|