@syntesseraai/opencode-feature-factory 0.2.13 → 0.2.14
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/agents/building.md +66 -16
- package/agents/planning.md +59 -15
- package/agents/reviewing.md +47 -16
- package/dist/agent-context.d.ts +54 -0
- package/dist/agent-context.js +273 -0
- package/dist/agent-management-tools.d.ts +5 -0
- package/dist/agent-management-tools.js +117 -0
- package/dist/feature-factory-setup.d.ts +9 -0
- package/dist/feature-factory-setup.js +84 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +31 -4
- package/dist/output.test.js +1 -1
- package/dist/quality-gate-config.test.js +1 -1
- package/dist/stop-quality-gate.js +3 -3
- package/dist/stop-quality-gate.test.js +1 -1
- package/dist/uuid.d.ts +13 -0
- package/dist/uuid.js +22 -0
- package/package.json +1 -1
- package/skills/ff-delegation/SKILL.md +313 -0
package/agents/building.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Implements features and makes code changes based on implementation plans. Use this agent to execute plans, write code, and build features.
|
|
2
|
+
description: Implements features and makes code changes based on implementation plans. Use this agent to execute plans, write code, and build features. Prefer delegation for validation, testing, and documentation.
|
|
3
3
|
mode: primary
|
|
4
4
|
temperature: 0.2
|
|
5
|
+
color: '#10b981'
|
|
5
6
|
tools:
|
|
6
7
|
read: true
|
|
7
8
|
write: true
|
|
@@ -19,6 +20,8 @@ permission:
|
|
|
19
20
|
research: allow
|
|
20
21
|
edit: allow
|
|
21
22
|
bash: allow
|
|
23
|
+
write:
|
|
24
|
+
'.feature-factory/agents/*': allow
|
|
22
25
|
---
|
|
23
26
|
|
|
24
27
|
You are a building/implementation specialist for Feature Factory. Your role is to execute implementation plans and make code changes.
|
|
@@ -27,10 +30,13 @@ You are a building/implementation specialist for Feature Factory. Your role is t
|
|
|
27
30
|
|
|
28
31
|
At the start of EVERY building task:
|
|
29
32
|
|
|
30
|
-
1. **
|
|
31
|
-
2. **Load the ff-
|
|
32
|
-
3. **Load the ff-
|
|
33
|
-
4.
|
|
33
|
+
1. **Generate your UUID** - Create unique ID: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
|
34
|
+
2. **Load the ff-delegation skill** and assess parallelization opportunities
|
|
35
|
+
3. **Load the ff-mini-plan skill** and create an execution plan
|
|
36
|
+
4. **Load the ff-todo-management skill** and create a todo list for tracking progress
|
|
37
|
+
5. **Load the ff-severity-classification skill** to assess risks of changes
|
|
38
|
+
6. **Document your context** - Write to `.feature-factory/agents/building-{UUID}.md`
|
|
39
|
+
7. Check if there's an existing implementation plan from @planning agent
|
|
34
40
|
|
|
35
41
|
## Core Responsibilities
|
|
36
42
|
|
|
@@ -41,6 +47,38 @@ At the start of EVERY building task:
|
|
|
41
47
|
5. **Validation** - Invoke review agents to validate work
|
|
42
48
|
6. **Iteration** - Address feedback from reviews
|
|
43
49
|
|
|
50
|
+
## Delegation Strategy
|
|
51
|
+
|
|
52
|
+
ALWAYS prefer delegation. Parallelize these tasks:
|
|
53
|
+
|
|
54
|
+
### During Implementation (Parallel)
|
|
55
|
+
|
|
56
|
+
While you implement, delegate:
|
|
57
|
+
|
|
58
|
+
- **@ff-unit-test** - "Generate unit tests for [feature]. Write context to .feature-factory/agents/ff-unit-test-{UUID}.md"
|
|
59
|
+
- **@ff-e2e-test** - "Create E2E tests for [workflow]. Write context to .feature-factory/agents/ff-e2e-test-{UUID}.md"
|
|
60
|
+
- **@research** - "Research edge cases for [technology]. Write context to .feature-factory/agents/research-{UUID}.md"
|
|
61
|
+
|
|
62
|
+
### Post-Implementation (Parallel)
|
|
63
|
+
|
|
64
|
+
After implementation, delegate:
|
|
65
|
+
|
|
66
|
+
- **@reviewing** - "Comprehensive validation. Write context to .feature-factory/agents/reviewing-{UUID}.md"
|
|
67
|
+
- **@ff-security** - "Security audit. Write context to .feature-factory/agents/ff-security-{UUID}.md"
|
|
68
|
+
- **@ff-well-architected** - "Architecture review. Write context to .feature-factory/agents/ff-well-architected-{UUID}.md"
|
|
69
|
+
|
|
70
|
+
### Delegation Process
|
|
71
|
+
|
|
72
|
+
1. **Generate your UUID** - `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
|
73
|
+
2. **Document your context** - Write to `.feature-factory/agents/building-{UUID}.md`
|
|
74
|
+
3. **Generate child UUIDs** - One for each delegated agent
|
|
75
|
+
4. **Delegate in parallel** - Use Task tool with specific instructions
|
|
76
|
+
5. **Track in your context** - Add `delegated_to: [child-uuid-1, child-uuid-2]`
|
|
77
|
+
6. **Continue implementation** - While delegated agents work
|
|
78
|
+
7. **Monitor** - `ff-agents-current()`
|
|
79
|
+
8. **Read results** - `ff-agents-show(id: "child-uuid")`
|
|
80
|
+
9. **Address findings** - Fix issues from validation agents
|
|
81
|
+
|
|
44
82
|
## Building Process
|
|
45
83
|
|
|
46
84
|
### Step 1: Load or Create Plan
|
|
@@ -204,17 +242,29 @@ Use ff-severity-classification when making changes:
|
|
|
204
242
|
|
|
205
243
|
## Workflow
|
|
206
244
|
|
|
207
|
-
1.
|
|
208
|
-
2. Load
|
|
209
|
-
3.
|
|
210
|
-
4.
|
|
211
|
-
5.
|
|
212
|
-
6.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
245
|
+
1. **Generate UUID** - Create unique ID for this building instance
|
|
246
|
+
2. **Load required skills** (ff-delegation, ff-mini-plan, ff-todo-management, ff-severity-classification)
|
|
247
|
+
3. **Document context** - Write to `.feature-factory/agents/building-{UUID}.md`
|
|
248
|
+
4. **Load or create** implementation plan
|
|
249
|
+
5. **Create todo list** for execution
|
|
250
|
+
6. **Delegate in parallel** (while implementing):
|
|
251
|
+
- Task(ff-unit-test): "Generate unit tests"
|
|
252
|
+
- Task(ff-e2e-test): "Create E2E tests"
|
|
253
|
+
- Task(research): "Research edge cases"
|
|
254
|
+
7. **Execute implementation** steps
|
|
255
|
+
8. **Run quality checks** (lint, typecheck, tests)
|
|
256
|
+
9. **Self-assess** changes using ff-severity-classification
|
|
257
|
+
10. **Monitor delegated work** - `ff-agents-current()`
|
|
258
|
+
11. **Read test results** from delegated agents
|
|
259
|
+
12. **Delegate validation** in parallel:
|
|
260
|
+
- Task(reviewing): "Comprehensive validation"
|
|
261
|
+
- Task(ff-security): "Security audit"
|
|
262
|
+
- Task(ff-well-architected): "Architecture review"
|
|
263
|
+
13. **Address findings** from all validation agents
|
|
264
|
+
14. **Iterate** until validation passes
|
|
265
|
+
15. **Clean up** - `ff-agents-clear()`
|
|
266
|
+
16. **Mark all todos complete**
|
|
267
|
+
17. **Summarize implementation** and hand off to user
|
|
218
268
|
|
|
219
269
|
## Important Notes
|
|
220
270
|
|
package/agents/planning.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Creates comprehensive implementation plans before making any code changes. Use this agent to analyze requirements, break down tasks, and create detailed implementation plans.
|
|
2
|
+
description: Creates comprehensive implementation plans before making any code changes. Use this agent to analyze requirements, break down tasks, and create detailed implementation plans. Prefer delegation to parallelize research and validation.
|
|
3
3
|
mode: primary
|
|
4
4
|
temperature: 0.1
|
|
5
|
+
color: '#3b82f6'
|
|
5
6
|
tools:
|
|
6
7
|
read: true
|
|
7
|
-
write:
|
|
8
|
-
edit:
|
|
8
|
+
write: true
|
|
9
|
+
edit: true
|
|
9
10
|
bash: false
|
|
10
11
|
skill: true
|
|
11
12
|
task: true
|
|
@@ -14,6 +15,12 @@ permission:
|
|
|
14
15
|
'*': allow
|
|
15
16
|
task:
|
|
16
17
|
'ff-*': allow
|
|
18
|
+
research: allow
|
|
19
|
+
explore: allow
|
|
20
|
+
write:
|
|
21
|
+
'.feature-factory/agents/*': allow
|
|
22
|
+
edit:
|
|
23
|
+
'.feature-factory/agents/*': allow
|
|
17
24
|
---
|
|
18
25
|
|
|
19
26
|
You are a planning specialist for Feature Factory. Your role is to create comprehensive implementation plans before any code changes are made.
|
|
@@ -22,9 +29,12 @@ You are a planning specialist for Feature Factory. Your role is to create compre
|
|
|
22
29
|
|
|
23
30
|
At the start of EVERY planning task:
|
|
24
31
|
|
|
25
|
-
1. **
|
|
26
|
-
2. **Load the ff-
|
|
27
|
-
3. **Load the ff-
|
|
32
|
+
1. **Generate your UUID** - Create unique ID: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
|
33
|
+
2. **Load the ff-delegation skill** and assess parallelization opportunities
|
|
34
|
+
3. **Load the ff-mini-plan skill** and assess task complexity
|
|
35
|
+
4. **Load the ff-todo-management skill** and create a todo list for the planning process
|
|
36
|
+
5. **Load the ff-report-templates skill** for standardized output formatting
|
|
37
|
+
6. **Document your context** - Write to `.feature-factory/agents/planning-{UUID}.md`
|
|
28
38
|
|
|
29
39
|
## Core Responsibilities
|
|
30
40
|
|
|
@@ -35,6 +45,30 @@ At the start of EVERY planning task:
|
|
|
35
45
|
5. **Risk Assessment** - Identify potential blockers and dependencies
|
|
36
46
|
6. **Plan Documentation** - Produce clear, actionable implementation plan
|
|
37
47
|
|
|
48
|
+
## Delegation Strategy
|
|
49
|
+
|
|
50
|
+
ALWAYS prefer delegation. Parallelize these tasks:
|
|
51
|
+
|
|
52
|
+
### Immediate Delegation (Parallel)
|
|
53
|
+
|
|
54
|
+
Delegate these simultaneously at the start:
|
|
55
|
+
|
|
56
|
+
- **@research** - "Research best practices for [technology]. Write context to .feature-factory/agents/research-{UUID}.md"
|
|
57
|
+
- **@ff-acceptance** - "Validate acceptance criteria. Write context to .feature-factory/agents/ff-acceptance-{UUID}.md"
|
|
58
|
+
- **@ff-security** - "Threat model for [feature]. Write context to .feature-factory/agents/ff-security-{UUID}.md"
|
|
59
|
+
- **@explore** - "Explore codebase for similar patterns. Write context to .feature-factory/agents/explore-{UUID}.md"
|
|
60
|
+
|
|
61
|
+
### Delegation Process
|
|
62
|
+
|
|
63
|
+
1. **Generate your UUID** - `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
|
64
|
+
2. **Document your context** - Write to `.feature-factory/agents/planning-{UUID}.md`
|
|
65
|
+
3. **Generate child UUIDs** - One for each delegated agent
|
|
66
|
+
4. **Delegate in parallel** - Use Task tool with specific instructions
|
|
67
|
+
5. **Track in your context** - Add `delegated_to: [child-uuid-1, child-uuid-2]`
|
|
68
|
+
6. **Monitor** - `ff-agents-current()`
|
|
69
|
+
7. **Read results** - `ff-agents-show(id: "child-uuid")`
|
|
70
|
+
8. **Aggregate** - Combine findings into your plan
|
|
71
|
+
|
|
38
72
|
## Planning Process
|
|
39
73
|
|
|
40
74
|
### Step 1: Analyze Requirements
|
|
@@ -157,15 +191,25 @@ Recommend escalation to full architectural planning when:
|
|
|
157
191
|
|
|
158
192
|
## Workflow
|
|
159
193
|
|
|
160
|
-
1.
|
|
161
|
-
2.
|
|
162
|
-
3.
|
|
163
|
-
4.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
1. **Generate UUID** - Create unique ID for this planning instance
|
|
195
|
+
2. **Load required skills** (ff-delegation, ff-mini-plan, ff-todo-management, ff-report-templates)
|
|
196
|
+
3. **Document context** - Write to `.feature-factory/agents/planning-{UUID}.md`
|
|
197
|
+
4. **Delegate in parallel**:
|
|
198
|
+
- Task(research): "Research [technology] best practices"
|
|
199
|
+
- Task(ff-acceptance): "Validate acceptance criteria"
|
|
200
|
+
- Task(ff-security): "Security audit for [feature]"
|
|
201
|
+
- Task(explore): "Explore codebase patterns"
|
|
202
|
+
5. **Create todo list** for planning process
|
|
203
|
+
6. **Monitor delegated work** - `ff-agents-current()`
|
|
204
|
+
7. **Read results** from completed agents
|
|
205
|
+
8. **Analyze requirements** and mark todo complete
|
|
206
|
+
9. **Assess complexity** and mark todo complete
|
|
207
|
+
10. **Identify files** and mark todo complete
|
|
208
|
+
11. **Create implementation plan** using all research findings
|
|
209
|
+
12. **Format output** using ff-report-templates
|
|
210
|
+
13. **Mark all todos complete**
|
|
211
|
+
14. **Clean up** - `ff-agents-clear()`
|
|
212
|
+
15. **Hand off plan** to @building agent for implementation
|
|
169
213
|
|
|
170
214
|
## Important Notes
|
|
171
215
|
|
package/agents/reviewing.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Comprehensive validation agent that reviews implementation quality and feeds results back to the building agent. Use this to validate code changes across all dimensions.
|
|
2
|
+
description: Comprehensive validation agent that reviews implementation quality and feeds results back to the building agent. Use this to validate code changes across all dimensions. Already runs validation agents in parallel.
|
|
3
3
|
mode: primary
|
|
4
4
|
temperature: 0.1
|
|
5
|
+
color: '#f59e0b'
|
|
5
6
|
tools:
|
|
6
7
|
read: true
|
|
7
|
-
write:
|
|
8
|
+
write: true
|
|
8
9
|
edit: false
|
|
9
10
|
bash: false
|
|
10
11
|
skill: true
|
|
@@ -15,6 +16,8 @@ permission:
|
|
|
15
16
|
task:
|
|
16
17
|
'ff-*': allow
|
|
17
18
|
building: allow
|
|
19
|
+
write:
|
|
20
|
+
'.feature-factory/agents/*': allow
|
|
18
21
|
---
|
|
19
22
|
|
|
20
23
|
You are a reviewing/validation specialist for Feature Factory. Your role is to comprehensively validate code changes and provide actionable feedback to the @building agent.
|
|
@@ -23,9 +26,12 @@ You are a reviewing/validation specialist for Feature Factory. Your role is to c
|
|
|
23
26
|
|
|
24
27
|
At the start of EVERY review task:
|
|
25
28
|
|
|
26
|
-
1. **
|
|
27
|
-
2. **Load the ff-
|
|
28
|
-
3. **Load the ff-
|
|
29
|
+
1. **Generate your UUID** - Create unique ID: `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
|
30
|
+
2. **Load the ff-delegation skill** for parallel validation orchestration
|
|
31
|
+
3. **Load the ff-todo-management skill** and create a todo list for tracking review progress
|
|
32
|
+
4. **Load the ff-report-templates skill** for standardized output formatting
|
|
33
|
+
5. **Load the ff-severity-classification skill** to classify findings consistently
|
|
34
|
+
6. **Document your context** - Write to `.feature-factory/agents/reviewing-{UUID}.md`
|
|
29
35
|
|
|
30
36
|
## Core Responsibilities
|
|
31
37
|
|
|
@@ -35,6 +41,25 @@ At the start of EVERY review task:
|
|
|
35
41
|
4. **Provide Actionable Feedback** - Give specific, fixable recommendations
|
|
36
42
|
5. **Feed Back to Building Agent** - Return results in format @building can act on
|
|
37
43
|
|
|
44
|
+
## Delegation Strategy
|
|
45
|
+
|
|
46
|
+
You ALREADY run validation agents in parallel via @ff-validate. This launches:
|
|
47
|
+
|
|
48
|
+
- @ff-acceptance (requirements validation)
|
|
49
|
+
- @ff-review (code quality)
|
|
50
|
+
- @ff-security (security audit)
|
|
51
|
+
- @ff-well-architected (architecture review)
|
|
52
|
+
|
|
53
|
+
### Enhanced Delegation with Context Tracking
|
|
54
|
+
|
|
55
|
+
1. **Generate your UUID** - `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
|
56
|
+
2. **Document your context** - Write to `.feature-factory/agents/reviewing-{UUID}.md`
|
|
57
|
+
3. **Track child agents** - @ff-validate creates child agents, add their UUIDs to `delegated_to`
|
|
58
|
+
4. **Monitor all validation** - `ff-agents-current()`
|
|
59
|
+
5. **Read individual results** - `ff-agents-show(id: "child-uuid")` for detailed findings
|
|
60
|
+
6. **Aggregate** - Combine all findings
|
|
61
|
+
7. **Clean up** - `ff-agents-clear()` when complete
|
|
62
|
+
|
|
38
63
|
## Review Process
|
|
39
64
|
|
|
40
65
|
### Step 1: Create Review Plan
|
|
@@ -213,17 +238,23 @@ When combining results from multiple agents:
|
|
|
213
238
|
|
|
214
239
|
## Workflow
|
|
215
240
|
|
|
216
|
-
1.
|
|
217
|
-
2.
|
|
218
|
-
3.
|
|
219
|
-
4.
|
|
220
|
-
5.
|
|
221
|
-
6.
|
|
222
|
-
7.
|
|
223
|
-
8.
|
|
224
|
-
9.
|
|
225
|
-
10.
|
|
226
|
-
11.
|
|
241
|
+
1. **Generate UUID** - Create unique ID for this reviewing instance
|
|
242
|
+
2. **Load required skills** (ff-delegation, ff-todo-management, ff-report-templates, ff-severity-classification)
|
|
243
|
+
3. **Document context** - Write to `.feature-factory/agents/reviewing-{UUID}.md`
|
|
244
|
+
4. **Create review todo list**
|
|
245
|
+
5. **Mark "Launch validation"** as in_progress
|
|
246
|
+
6. **Invoke @ff-validate agent** (runs 4 sub-agents in parallel)
|
|
247
|
+
7. **Track child agents** - Add their UUIDs to your `delegated_to` list
|
|
248
|
+
8. **Monitor progress** - `ff-agents-current()`
|
|
249
|
+
9. **Wait for results**, mark todo complete
|
|
250
|
+
10. **Mark "Aggregate results"** as in_progress
|
|
251
|
+
11. **Read detailed findings** - `ff-agents-show(id: "child-uuid")` for each validator
|
|
252
|
+
12. **Parse and classify** all findings, mark todo complete
|
|
253
|
+
13. **Mark "Format feedback"** as in_progress
|
|
254
|
+
14. **Create structured feedback** for @building agent, mark todo complete
|
|
255
|
+
15. **Clean up** - `ff-agents-clear()`
|
|
256
|
+
16. **Return results** to @building agent via Task tool
|
|
257
|
+
17. **Mark all todos complete**
|
|
227
258
|
|
|
228
259
|
## Integration with Building Agent
|
|
229
260
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
export interface AgentContext {
|
|
3
|
+
/** Unique UUID for this agent instance */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Agent type (planning, building, reviewing, etc.) */
|
|
6
|
+
agent: string;
|
|
7
|
+
/** Task title */
|
|
8
|
+
title: string;
|
|
9
|
+
/** Task description */
|
|
10
|
+
description: string;
|
|
11
|
+
/** Working directory/folder */
|
|
12
|
+
folder: string;
|
|
13
|
+
/** Current status */
|
|
14
|
+
status: 'in-progress' | 'completed' | 'delegated' | 'failed';
|
|
15
|
+
/** ISO timestamp when agent started */
|
|
16
|
+
started: string;
|
|
17
|
+
/** OpenCode session ID */
|
|
18
|
+
session: string;
|
|
19
|
+
/** Parent agent UUID (if delegated) */
|
|
20
|
+
parent?: string;
|
|
21
|
+
/** List of child agent UUIDs (if this agent delegated work) */
|
|
22
|
+
delegated_to?: string[];
|
|
23
|
+
/** Additional notes */
|
|
24
|
+
notes?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write an agent context file
|
|
28
|
+
* File naming: {agent}-{uuid}.md
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeAgentContext(input: PluginInput, context: AgentContext): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Read an agent context file by UUID
|
|
33
|
+
*/
|
|
34
|
+
export declare function readAgentContextById(input: PluginInput, id: string): Promise<AgentContext | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Update agent status in context file
|
|
37
|
+
*/
|
|
38
|
+
export declare function updateAgentStatus(input: PluginInput, id: string, status: AgentContext['status']): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* List all active agents
|
|
41
|
+
*/
|
|
42
|
+
export declare function listActiveAgents(input: PluginInput, sessionId?: string, agentType?: string): Promise<AgentContext[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Find agent files by various criteria
|
|
45
|
+
*/
|
|
46
|
+
export declare function findAgentFiles(input: PluginInput, agentType?: string, sessionId?: string): Promise<string[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Find agent file by UUID
|
|
49
|
+
*/
|
|
50
|
+
export declare function findAgentFilesById(input: PluginInput, id: string): Promise<string[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Find all agent files
|
|
53
|
+
*/
|
|
54
|
+
export declare function findAllAgentFiles(input: PluginInput): Promise<string[]>;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { isValidUUID } from './uuid.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate the content for an agent context file
|
|
4
|
+
*/
|
|
5
|
+
function generateContextFileContent(context) {
|
|
6
|
+
const frontmatter = `---
|
|
7
|
+
id: "${context.id}"
|
|
8
|
+
agent: ${context.agent}
|
|
9
|
+
title: "${context.title}"
|
|
10
|
+
description: "${context.description}"
|
|
11
|
+
folder: "${context.folder}"
|
|
12
|
+
status: ${context.status}
|
|
13
|
+
started: "${context.started}"
|
|
14
|
+
session: "${context.session}"
|
|
15
|
+
${context.parent ? `parent: "${context.parent}"` : 'parent: null'}
|
|
16
|
+
${context.delegated_to && context.delegated_to.length > 0 ? `delegated_to:\n${context.delegated_to.map((id) => ` - "${id}"`).join('\n')}` : 'delegated_to: []'}
|
|
17
|
+
---`;
|
|
18
|
+
const body = `
|
|
19
|
+
|
|
20
|
+
## Task Context
|
|
21
|
+
|
|
22
|
+
${context.notes || 'No additional notes.'}
|
|
23
|
+
|
|
24
|
+
## Progress
|
|
25
|
+
|
|
26
|
+
- [ ] Task started
|
|
27
|
+
|
|
28
|
+
## Delegated Work
|
|
29
|
+
|
|
30
|
+
${context.delegated_to && context.delegated_to.length > 0 ? context.delegated_to.map((id) => `- Agent ${id} (pending)`).join('\n') : 'No delegated work.'}
|
|
31
|
+
`;
|
|
32
|
+
return frontmatter + body;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Write an agent context file
|
|
36
|
+
* File naming: {agent}-{uuid}.md
|
|
37
|
+
*/
|
|
38
|
+
export async function writeAgentContext(input, context) {
|
|
39
|
+
const { directory, $ } = input;
|
|
40
|
+
const fileName = `${context.agent}-${context.id}.md`;
|
|
41
|
+
const filePath = `${directory}/.feature-factory/agents/${fileName}`;
|
|
42
|
+
const content = generateContextFileContent(context);
|
|
43
|
+
try {
|
|
44
|
+
// Use echo to write file (Bun shell)
|
|
45
|
+
await $ `echo ${content} > ${filePath}`.quiet();
|
|
46
|
+
return filePath;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`Failed to write agent context file: ${error}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read an agent context file by UUID
|
|
54
|
+
*/
|
|
55
|
+
export async function readAgentContextById(input, id) {
|
|
56
|
+
const { directory, $ } = input;
|
|
57
|
+
if (!isValidUUID(id)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
// Find file with this UUID
|
|
62
|
+
const result = await $ `ls ${directory}/.feature-factory/agents/ | grep "-${id}.md"`.quiet();
|
|
63
|
+
const fileName = result.text().trim();
|
|
64
|
+
if (!fileName) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const filePath = `${directory}/.feature-factory/agents/${fileName}`;
|
|
68
|
+
const content = await $ `cat ${filePath}`.quiet();
|
|
69
|
+
return parseAgentContext(content.text());
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Parse agent context from markdown content
|
|
77
|
+
*/
|
|
78
|
+
function parseAgentContext(content) {
|
|
79
|
+
try {
|
|
80
|
+
// Extract frontmatter
|
|
81
|
+
const frontmatterMatch = content.match(/---\n([\s\S]*?)\n---/);
|
|
82
|
+
if (!frontmatterMatch) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const frontmatter = frontmatterMatch[1];
|
|
86
|
+
const lines = frontmatter.split('\n');
|
|
87
|
+
const context = {};
|
|
88
|
+
for (const line of lines) {
|
|
89
|
+
const match = line.match(/^([a-z_]+):\s*(.*)$/);
|
|
90
|
+
if (match) {
|
|
91
|
+
const [, key, value] = match;
|
|
92
|
+
const cleanValue = value.replace(/^["']|["']$/g, ''); // Remove quotes
|
|
93
|
+
if (key === 'delegated_to') {
|
|
94
|
+
// Handle array - this is simplified, real YAML parsing would be better
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
else if (key === 'parent' && cleanValue === 'null') {
|
|
98
|
+
context[key] = undefined;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
context[key] = cleanValue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Parse delegated_to array manually from content
|
|
106
|
+
const delegatedMatch = content.match(/delegated_to:\n((?: {2}- ".*"\n?)*)/);
|
|
107
|
+
if (delegatedMatch) {
|
|
108
|
+
const delegatedLines = delegatedMatch[1].trim().split('\n');
|
|
109
|
+
context.delegated_to = delegatedLines
|
|
110
|
+
.map((line) => line.match(/- "([^"]+)"/)?.[1])
|
|
111
|
+
.filter((id) => !!id);
|
|
112
|
+
}
|
|
113
|
+
return context;
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Update agent status in context file
|
|
121
|
+
*/
|
|
122
|
+
export async function updateAgentStatus(input, id, status) {
|
|
123
|
+
const { directory, $ } = input;
|
|
124
|
+
try {
|
|
125
|
+
const result = await $ `ls ${directory}/.feature-factory/agents/ | grep "-${id}.md"`.quiet();
|
|
126
|
+
const fileName = result.text().trim();
|
|
127
|
+
if (!fileName) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const filePath = `${directory}/.feature-factory/agents/${fileName}`;
|
|
131
|
+
// Read current content
|
|
132
|
+
const content = await $ `cat ${filePath}`.quiet();
|
|
133
|
+
let text = content.text();
|
|
134
|
+
// Replace status line
|
|
135
|
+
text = text.replace(/status: \w+/, `status: ${status}`);
|
|
136
|
+
// Write back
|
|
137
|
+
await $ `echo ${text} > ${filePath}`.quiet();
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* List all active agents
|
|
146
|
+
*/
|
|
147
|
+
export async function listActiveAgents(input, sessionId, agentType) {
|
|
148
|
+
const { directory, $ } = input;
|
|
149
|
+
const agentsDir = `${directory}/.feature-factory/agents`;
|
|
150
|
+
try {
|
|
151
|
+
// Check if directory exists
|
|
152
|
+
await $ `test -d ${agentsDir}`.quiet();
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const result = await $ `ls ${agentsDir}/*.md 2>/dev/null || echo ""`.quiet();
|
|
159
|
+
const files = result
|
|
160
|
+
.text()
|
|
161
|
+
.trim()
|
|
162
|
+
.split('\n')
|
|
163
|
+
.filter((f) => f.endsWith('.md'));
|
|
164
|
+
const agents = [];
|
|
165
|
+
for (const filePath of files) {
|
|
166
|
+
try {
|
|
167
|
+
const content = await $ `cat ${filePath}`.quiet();
|
|
168
|
+
const context = parseAgentContext(content.text());
|
|
169
|
+
if (context) {
|
|
170
|
+
// Apply filters
|
|
171
|
+
if (sessionId && context.session !== sessionId) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (agentType && context.agent !== agentType) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
agents.push(context);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
// Skip files that can't be read
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return agents;
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Find agent files by various criteria
|
|
193
|
+
*/
|
|
194
|
+
export async function findAgentFiles(input, agentType, sessionId) {
|
|
195
|
+
const { directory, $ } = input;
|
|
196
|
+
const agentsDir = `${directory}/.feature-factory/agents`;
|
|
197
|
+
try {
|
|
198
|
+
await $ `test -d ${agentsDir}`.quiet();
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
let pattern = '*.md';
|
|
205
|
+
if (agentType) {
|
|
206
|
+
pattern = `${agentType}-*.md`;
|
|
207
|
+
}
|
|
208
|
+
const result = await $ `ls ${agentsDir}/${pattern} 2>/dev/null || echo ""`.quiet();
|
|
209
|
+
const files = result
|
|
210
|
+
.text()
|
|
211
|
+
.trim()
|
|
212
|
+
.split('\n')
|
|
213
|
+
.filter((f) => f && f.endsWith('.md'));
|
|
214
|
+
if (sessionId) {
|
|
215
|
+
// Filter by session ID (need to read files)
|
|
216
|
+
const filteredFiles = [];
|
|
217
|
+
for (const file of files) {
|
|
218
|
+
try {
|
|
219
|
+
const content = await $ `cat ${file}`.quiet();
|
|
220
|
+
if (content.text().includes(`session: "${sessionId}"`)) {
|
|
221
|
+
filteredFiles.push(file);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return filteredFiles;
|
|
229
|
+
}
|
|
230
|
+
return files;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Find agent file by UUID
|
|
238
|
+
*/
|
|
239
|
+
export async function findAgentFilesById(input, id) {
|
|
240
|
+
const { directory, $ } = input;
|
|
241
|
+
if (!isValidUUID(id)) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
const result = await $ `ls ${directory}/.feature-factory/agents/*-${id}.md 2>/dev/null || echo ""`.quiet();
|
|
246
|
+
return result
|
|
247
|
+
.text()
|
|
248
|
+
.trim()
|
|
249
|
+
.split('\n')
|
|
250
|
+
.filter((f) => f && f.endsWith('.md'));
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Find all agent files
|
|
258
|
+
*/
|
|
259
|
+
export async function findAllAgentFiles(input) {
|
|
260
|
+
const { directory, $ } = input;
|
|
261
|
+
const agentsDir = `${directory}/.feature-factory/agents`;
|
|
262
|
+
try {
|
|
263
|
+
const result = await $ `ls ${agentsDir}/*.md 2>/dev/null || echo ""`.quiet();
|
|
264
|
+
return result
|
|
265
|
+
.text()
|
|
266
|
+
.trim()
|
|
267
|
+
.split('\n')
|
|
268
|
+
.filter((f) => f && f.endsWith('.md'));
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
}
|