opencodekit 0.15.10 → 0.15.12
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/dist/index.js +1 -1
- package/dist/template/.opencode/agent/build.md +390 -0
- package/dist/template/.opencode/command/implement.md +136 -10
- package/dist/template/.opencode/memory/observations/2026-01-25-decision-agent-roles-build-orchestrates-general-e.md +14 -0
- package/dist/template/.opencode/memory/observations/2026-01-25-decision-simplified-swarm-helper-tool-to-fix-type.md +20 -0
- package/dist/template/.opencode/memory/observations/2026-01-25-decision-use-beads-as-swarm-board-source-of-truth.md +14 -0
- package/dist/template/.opencode/memory/observations/2026-01-25-learning-user-wants-real-swarm-coordination-guida.md +15 -0
- package/dist/template/.opencode/memory/research/opencode-mcp-bug-report.md +126 -0
- package/dist/template/.opencode/opencode.json +151 -46
- package/dist/template/.opencode/package.json +1 -1
- package/dist/template/.opencode/plans/swarm-protocol.md +123 -0
- package/dist/template/.opencode/plugin/README.md +10 -0
- package/dist/template/.opencode/plugin/copilot-auth.ts +104 -77
- package/dist/template/.opencode/plugin/swarm-enforcer.ts +297 -0
- package/dist/template/.opencode/skill/swarm-coordination/SKILL.md +405 -0
- package/dist/template/.opencode/tool/swarm-delegate.ts +175 -0
- package/dist/template/.opencode/tool/swarm-helper.ts +164 -0
- package/package.json +1 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: swarm-coordination
|
|
3
|
+
description: >
|
|
4
|
+
Use when implementing plans with multiple independent tasks that can run in parallel.
|
|
5
|
+
Enables leader agents to spawn, coordinate, and monitor worker swarms. Covers delegation
|
|
6
|
+
packets, mailbox communication, task assignment, and graceful shutdown patterns.
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
license: MIT
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Swarm Coordination - Multi-Agent Parallel Execution
|
|
12
|
+
|
|
13
|
+
Coordinate multiple agents working on independent tasks in parallel. Leader orchestrates, workers execute, mailbox communicates.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
**Swarm = Leader + Workers + Mailbox**
|
|
18
|
+
|
|
19
|
+
- **Leader (build agent)**: Orchestrates the swarm - spawns workers, monitors progress, synthesizes results
|
|
20
|
+
- **Workers (general agents)**: Execute independent tasks - read delegation, make changes, report back
|
|
21
|
+
- **Mailbox (swarm-mail.jsonl)**: Append-only log for coordination messages
|
|
22
|
+
|
|
23
|
+
**Key Distinction**:
|
|
24
|
+
|
|
25
|
+
- **Swarm**: Parallel execution of independent tasks from a plan
|
|
26
|
+
- **Beads**: Task tracking and dependency management across sessions
|
|
27
|
+
- **Task tool**: Spawning individual subagents for research/execution
|
|
28
|
+
|
|
29
|
+
**When to Use Swarm Coordination**:
|
|
30
|
+
|
|
31
|
+
- "Does this plan have 3+ independent tasks?" → **YES** = Swarm
|
|
32
|
+
- "Can multiple tasks run in parallel without conflicts?" → **YES** = Swarm
|
|
33
|
+
- "Do I need to coordinate multiple agents?" → **YES** = Swarm
|
|
34
|
+
- "Is this a single task or sequential dependency chain?" → **NO** = Single agent
|
|
35
|
+
|
|
36
|
+
## Architecture
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
40
|
+
│ BUILD AGENT (Leader) │
|
|
41
|
+
│ - Parses plan into tasks │
|
|
42
|
+
│ - Creates delegation packets │
|
|
43
|
+
│ - Spawns worker agents via Task tool │
|
|
44
|
+
│ - Monitors mailbox for progress │
|
|
45
|
+
│ - Synthesizes final results │
|
|
46
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
47
|
+
│ │ │
|
|
48
|
+
▼ ▼ ▼
|
|
49
|
+
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
|
|
50
|
+
│ WORKER-1 │ │ WORKER-2 │ │ WORKER-3 │
|
|
51
|
+
│ (general) │ │ (general) │ │ (general) │
|
|
52
|
+
│ │ │ │ │ │
|
|
53
|
+
│ - Read │ │ - Read │ │ - Read │
|
|
54
|
+
│ delegation│ │ delegation│ │ delegation│
|
|
55
|
+
│ - Execute │ │ - Execute │ │ - Execute │
|
|
56
|
+
│ - Report │ │ - Report │ │ - Report │
|
|
57
|
+
└─────────────┘ └─────────────┘ └─────────────┘
|
|
58
|
+
│ │ │
|
|
59
|
+
└────────────────────┼────────────────────┘
|
|
60
|
+
▼
|
|
61
|
+
┌─────────────────┐
|
|
62
|
+
│ SWARM MAILBOX │
|
|
63
|
+
│ (swarm-mail │
|
|
64
|
+
│ .jsonl) │
|
|
65
|
+
└─────────────────┘
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Swarm Launch Flow (5 Steps)
|
|
69
|
+
|
|
70
|
+
### Step 1: Parse Plan into Tasks
|
|
71
|
+
|
|
72
|
+
Extract independent tasks from the approved plan:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Read the plan
|
|
76
|
+
const plan = read({ filePath: ".beads/artifacts/<bead-id>/plan.md" });
|
|
77
|
+
|
|
78
|
+
// Identify parallelizable tasks
|
|
79
|
+
// Tasks are parallel if they:
|
|
80
|
+
// - Don't modify the same files
|
|
81
|
+
// - Don't have sequential dependencies
|
|
82
|
+
// - Can verify independently
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Step 2: Create Delegation Packets
|
|
86
|
+
|
|
87
|
+
For each task, create a delegation packet:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
swarm_delegate({
|
|
91
|
+
bead_id: "task-1",
|
|
92
|
+
title: "Implement auth service",
|
|
93
|
+
expected_outcome: "Auth service with JWT tokens, tests pass",
|
|
94
|
+
required_tools: "read, grep, lsp, edit, bash",
|
|
95
|
+
must_do: "LSP before edits, run npm test after changes",
|
|
96
|
+
must_not_do: "No new dependencies, don't edit config files",
|
|
97
|
+
acceptance_checks: "typecheck: npm run typecheck, lint: npm run lint, test: npm test",
|
|
98
|
+
context: "See .beads/artifacts/task-1/spec.md for requirements",
|
|
99
|
+
write: true,
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Step 3: Spawn Worker Agents
|
|
104
|
+
|
|
105
|
+
Use Task tool to spawn workers in parallel:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Multiple Task calls in one message run simultaneously
|
|
109
|
+
Task({
|
|
110
|
+
subagent_type: "general",
|
|
111
|
+
description: "Execute task-1",
|
|
112
|
+
prompt: `Execute bead task-1: Implement auth service
|
|
113
|
+
|
|
114
|
+
Read delegation packet at: .beads/artifacts/task-1/delegation.md
|
|
115
|
+
|
|
116
|
+
Requirements:
|
|
117
|
+
1. Follow all MUST DO constraints
|
|
118
|
+
2. Avoid all MUST NOT DO items
|
|
119
|
+
3. Run acceptance checks before claiming done
|
|
120
|
+
4. Report completion via swarm-helper sendTeamMessage
|
|
121
|
+
|
|
122
|
+
Team: plan-implementation
|
|
123
|
+
Worker: worker-1`,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
Task({
|
|
127
|
+
subagent_type: "general",
|
|
128
|
+
description: "Execute task-2",
|
|
129
|
+
prompt: `Execute bead task-2: Add user routes
|
|
130
|
+
...same pattern...`,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
Task({
|
|
134
|
+
subagent_type: "general",
|
|
135
|
+
description: "Execute task-3",
|
|
136
|
+
prompt: `Execute bead task-3: Create frontend forms
|
|
137
|
+
...same pattern...`,
|
|
138
|
+
});
|
|
139
|
+
// All three run in parallel
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Step 4: Monitor Progress
|
|
143
|
+
|
|
144
|
+
Check mailbox for worker reports:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
swarm_helper({
|
|
148
|
+
operation: "getTeamStatus",
|
|
149
|
+
team_name: "plan-implementation",
|
|
150
|
+
limit: 20,
|
|
151
|
+
});
|
|
152
|
+
// Returns messages from workers about progress
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Step 5: Synthesize Results
|
|
156
|
+
|
|
157
|
+
When all workers complete:
|
|
158
|
+
|
|
159
|
+
1. Read their completion messages from mailbox
|
|
160
|
+
2. Verify all acceptance checks passed
|
|
161
|
+
3. Run full test suite
|
|
162
|
+
4. Summarize what was accomplished
|
|
163
|
+
5. Close the parent bead
|
|
164
|
+
|
|
165
|
+
## Delegation Packet Structure
|
|
166
|
+
|
|
167
|
+
```markdown
|
|
168
|
+
# Delegation Packet
|
|
169
|
+
|
|
170
|
+
- TASK: task-1 - Implement auth service
|
|
171
|
+
- EXPECTED OUTCOME: Auth service with JWT tokens, tests pass
|
|
172
|
+
- REQUIRED TOOLS:
|
|
173
|
+
- read
|
|
174
|
+
- grep
|
|
175
|
+
- lsp
|
|
176
|
+
- edit
|
|
177
|
+
- bash
|
|
178
|
+
- MUST DO:
|
|
179
|
+
- LSP before edits
|
|
180
|
+
- Run npm test after changes
|
|
181
|
+
- Follow existing code patterns
|
|
182
|
+
- MUST NOT DO:
|
|
183
|
+
- No new dependencies
|
|
184
|
+
- Don't edit config files
|
|
185
|
+
- Don't modify shared utilities
|
|
186
|
+
- ACCEPTANCE CHECKS:
|
|
187
|
+
- typecheck: npm run typecheck
|
|
188
|
+
- lint: npm run lint
|
|
189
|
+
- test: npm test
|
|
190
|
+
- CONTEXT:
|
|
191
|
+
See .beads/artifacts/task-1/spec.md for requirements
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Worker Protocol
|
|
195
|
+
|
|
196
|
+
Workers follow this execution pattern:
|
|
197
|
+
|
|
198
|
+
### 1. Read Delegation
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// First action: read the delegation packet
|
|
202
|
+
read({ filePath: ".beads/artifacts/<task-id>/delegation.md" });
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 2. Announce Start
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
swarm_helper({
|
|
209
|
+
operation: "sendTeamMessage",
|
|
210
|
+
team_name: "plan-implementation",
|
|
211
|
+
from_worker: "worker-1",
|
|
212
|
+
to_worker: "leader",
|
|
213
|
+
message: "Starting: <task-title>",
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 3. Execute Task
|
|
218
|
+
|
|
219
|
+
Follow the MUST DO constraints. Avoid MUST NOT DO items. Use required tools only.
|
|
220
|
+
|
|
221
|
+
### 4. Run Acceptance Checks
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Run each check from the delegation packet
|
|
225
|
+
npm run typecheck
|
|
226
|
+
npm run lint
|
|
227
|
+
npm test
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 5. Report Completion
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
swarm_helper({
|
|
234
|
+
operation: "sendTeamMessage",
|
|
235
|
+
team_name: "plan-implementation",
|
|
236
|
+
from_worker: "worker-1",
|
|
237
|
+
to_worker: "leader",
|
|
238
|
+
message: "DONE: <task-title>. All checks passed. Changes: <summary>",
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Mailbox Message Format
|
|
243
|
+
|
|
244
|
+
Messages in `.beads/swarm-mail.jsonl`:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"timestamp": "2025-01-27T10:30:00.000Z",
|
|
249
|
+
"team_name": "plan-implementation",
|
|
250
|
+
"from_worker": "worker-1",
|
|
251
|
+
"to_worker": "leader",
|
|
252
|
+
"message": "DONE: Implement auth service. All checks passed.",
|
|
253
|
+
"status": "unread"
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Message Types
|
|
258
|
+
|
|
259
|
+
| Type | From | To | Purpose |
|
|
260
|
+
| -------- | ------ | -------- | --------------------------- |
|
|
261
|
+
| START | worker | leader | Worker beginning task |
|
|
262
|
+
| PROGRESS | worker | leader | Intermediate update |
|
|
263
|
+
| BLOCKED | worker | leader | Worker needs help |
|
|
264
|
+
| DONE | worker | leader | Task completed successfully |
|
|
265
|
+
| ERROR | worker | leader | Task failed |
|
|
266
|
+
| HELP | worker | worker-N | Request assistance |
|
|
267
|
+
| ASSIGN | leader | worker | New task assignment |
|
|
268
|
+
| SHUTDOWN | leader | all | Graceful shutdown signal |
|
|
269
|
+
|
|
270
|
+
## Conflict Prevention
|
|
271
|
+
|
|
272
|
+
### File Reservation
|
|
273
|
+
|
|
274
|
+
Before workers start, leader reserves files:
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
// Reserve files for each worker
|
|
278
|
+
bd_reserve({
|
|
279
|
+
paths: ["src/auth/service.ts", "src/auth/types.ts"],
|
|
280
|
+
reason: "worker-1: auth service implementation",
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Non-Overlapping Assignments
|
|
285
|
+
|
|
286
|
+
Ensure workers don't edit same files:
|
|
287
|
+
|
|
288
|
+
| Worker | Assigned Files |
|
|
289
|
+
| -------- | ----------------------- |
|
|
290
|
+
| worker-1 | src/auth/\* |
|
|
291
|
+
| worker-2 | src/routes/user/\* |
|
|
292
|
+
| worker-3 | src/components/forms/\* |
|
|
293
|
+
|
|
294
|
+
## Error Handling
|
|
295
|
+
|
|
296
|
+
### Worker Fails Acceptance Checks
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// Worker sends error message
|
|
300
|
+
swarm_helper({
|
|
301
|
+
operation: "sendTeamMessage",
|
|
302
|
+
team_name: "plan-implementation",
|
|
303
|
+
from_worker: "worker-1",
|
|
304
|
+
to_worker: "leader",
|
|
305
|
+
message: "ERROR: typecheck failed. Issue: missing type for AuthToken",
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Leader Response
|
|
310
|
+
|
|
311
|
+
1. Read error from mailbox
|
|
312
|
+
2. Decide: fix locally or reassign
|
|
313
|
+
3. Either spawn fix-agent or adjust task
|
|
314
|
+
|
|
315
|
+
### Worker Gets Blocked
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
// Worker asks for help
|
|
319
|
+
swarm_helper({
|
|
320
|
+
operation: "sendTeamMessage",
|
|
321
|
+
team_name: "plan-implementation",
|
|
322
|
+
from_worker: "worker-2",
|
|
323
|
+
to_worker: "leader",
|
|
324
|
+
message: "BLOCKED: Need auth service types. Waiting on worker-1.",
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Graceful Shutdown
|
|
329
|
+
|
|
330
|
+
Leader signals completion:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
// After all workers done
|
|
334
|
+
swarm_helper({
|
|
335
|
+
operation: "sendTeamMessage",
|
|
336
|
+
team_name: "plan-implementation",
|
|
337
|
+
from_worker: "leader",
|
|
338
|
+
to_worker: "all",
|
|
339
|
+
message: "SHUTDOWN: All tasks complete. Final verification passed.",
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## When to Use Swarm vs Single Agent
|
|
344
|
+
|
|
345
|
+
| Scenario | Approach |
|
|
346
|
+
| ----------------------------- | ------------ |
|
|
347
|
+
| 1-2 file changes | Single agent |
|
|
348
|
+
| Sequential dependencies | Single agent |
|
|
349
|
+
| 3+ independent parallel tasks | Swarm |
|
|
350
|
+
| Cross-domain work (FE/BE/DB) | Swarm |
|
|
351
|
+
| Time-sensitive parallel work | Swarm |
|
|
352
|
+
|
|
353
|
+
## Integration with Beads
|
|
354
|
+
|
|
355
|
+
Swarm works on top of Beads:
|
|
356
|
+
|
|
357
|
+
1. **Plan creates beads** for each task
|
|
358
|
+
2. **Leader claims parent** bead
|
|
359
|
+
3. **Workers claim child** beads
|
|
360
|
+
4. **Completion closes** beads via `bd_done()`
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
// Leader workflow
|
|
364
|
+
bd_claim(); // Gets parent task
|
|
365
|
+
// ... spawn swarm ...
|
|
366
|
+
// ... monitor completion ...
|
|
367
|
+
bd_done({ id: "parent-task", msg: "Swarm completed all subtasks" });
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Quick Reference
|
|
371
|
+
|
|
372
|
+
```
|
|
373
|
+
SWARM LAUNCH:
|
|
374
|
+
1. Parse plan → identify parallel tasks
|
|
375
|
+
2. Create delegation packets (swarm-delegate)
|
|
376
|
+
3. Spawn workers (Task tool, multiple in one message)
|
|
377
|
+
4. Monitor mailbox (swarm-helper getTeamStatus)
|
|
378
|
+
5. Synthesize results
|
|
379
|
+
|
|
380
|
+
WORKER EXECUTION:
|
|
381
|
+
1. Read delegation packet
|
|
382
|
+
2. Announce start via mailbox
|
|
383
|
+
3. Execute with constraints
|
|
384
|
+
4. Run acceptance checks
|
|
385
|
+
5. Report completion via mailbox
|
|
386
|
+
|
|
387
|
+
COORDINATION:
|
|
388
|
+
- Mailbox: .beads/swarm-mail.jsonl
|
|
389
|
+
- Delegation: .beads/artifacts/<id>/delegation.md
|
|
390
|
+
- File locks: bd_reserve() before spawning
|
|
391
|
+
|
|
392
|
+
SHUTDOWN:
|
|
393
|
+
- All workers done → leader sends SHUTDOWN
|
|
394
|
+
- Run full test suite
|
|
395
|
+
- Close parent bead
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Rules
|
|
399
|
+
|
|
400
|
+
1. **Leader spawns, workers execute** - Clear role separation
|
|
401
|
+
2. **Delegation packets are contracts** - Workers follow them strictly
|
|
402
|
+
3. **Mailbox for coordination** - All communication through swarm-mail
|
|
403
|
+
4. **No file conflicts** - Reserve before spawning workers
|
|
404
|
+
5. **Acceptance checks required** - Workers verify before reporting done
|
|
405
|
+
6. **Graceful shutdown** - Leader waits for all workers, then shuts down
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { tool } from "@opencode-ai/plugin";
|
|
4
|
+
|
|
5
|
+
function isSafePathSegment(value: string): boolean {
|
|
6
|
+
if (!value) return false;
|
|
7
|
+
if (value.includes("..")) return false;
|
|
8
|
+
if (value.includes("/")) return false;
|
|
9
|
+
if (value.includes("\\")) return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function sanitizeFilename(value: string): string {
|
|
14
|
+
const trimmed = value.trim();
|
|
15
|
+
if (!trimmed) return "delegation.md";
|
|
16
|
+
if (!isSafePathSegment(trimmed)) return "delegation.md";
|
|
17
|
+
return trimmed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function splitList(input?: string): string[] {
|
|
21
|
+
if (!input) return [];
|
|
22
|
+
const parts = input
|
|
23
|
+
.split(/\r?\n|,/g)
|
|
24
|
+
.map((s) => s.trim())
|
|
25
|
+
.filter(Boolean);
|
|
26
|
+
return [...new Set(parts)];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function formatBullets(items: string[]): string {
|
|
30
|
+
if (items.length === 0) return "- (none)";
|
|
31
|
+
return items.map((i) => `- ${i}`).join("\n");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function fileExists(filePath: string): Promise<boolean> {
|
|
35
|
+
try {
|
|
36
|
+
await fs.access(filePath);
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default tool({
|
|
44
|
+
description: `Generate a Swarm delegation packet (Beads-as-board).
|
|
45
|
+
|
|
46
|
+
Purpose:
|
|
47
|
+
- Creates a consistent delegation envelope for a specific Beads task
|
|
48
|
+
- Optionally appends it to .beads/artifacts/<id>/delegation.md
|
|
49
|
+
|
|
50
|
+
Example:
|
|
51
|
+
swarm-delegate({
|
|
52
|
+
bead_id: "opencodekit-template-xyz",
|
|
53
|
+
title: "Add feature X",
|
|
54
|
+
expected_outcome: "Feature X works and tests pass",
|
|
55
|
+
required_tools: "read, grep, lsp, bash",
|
|
56
|
+
must_do: "LSP before edits, run project verification commands",
|
|
57
|
+
must_not_do: "no new deps, don't edit dist/",
|
|
58
|
+
acceptance_checks: "typecheck: <command>, lint: <command>, test: <command>",
|
|
59
|
+
context: "See .beads/artifacts/<id>/spec.md",
|
|
60
|
+
write: true
|
|
61
|
+
})`,
|
|
62
|
+
args: {
|
|
63
|
+
bead_id: tool.schema
|
|
64
|
+
.string()
|
|
65
|
+
.describe("Beads issue id (e.g., opencodekit-template-abc)"),
|
|
66
|
+
title: tool.schema
|
|
67
|
+
.string()
|
|
68
|
+
.optional()
|
|
69
|
+
.describe("Optional title (defaults to Beads id only)"),
|
|
70
|
+
expected_outcome: tool.schema
|
|
71
|
+
.string()
|
|
72
|
+
.describe("Measurable end state for this task"),
|
|
73
|
+
required_tools: tool.schema
|
|
74
|
+
.string()
|
|
75
|
+
.optional()
|
|
76
|
+
.describe("Comma/newline-separated list of tools"),
|
|
77
|
+
must_do: tool.schema
|
|
78
|
+
.string()
|
|
79
|
+
.optional()
|
|
80
|
+
.describe("Comma/newline-separated MUST DO list"),
|
|
81
|
+
must_not_do: tool.schema
|
|
82
|
+
.string()
|
|
83
|
+
.optional()
|
|
84
|
+
.describe("Comma/newline-separated MUST NOT DO list"),
|
|
85
|
+
acceptance_checks: tool.schema
|
|
86
|
+
.string()
|
|
87
|
+
.optional()
|
|
88
|
+
.describe(
|
|
89
|
+
"Comma/newline-separated checks (prefer 'typecheck: <command>', 'lint: <command>', 'test: <command>')",
|
|
90
|
+
),
|
|
91
|
+
context: tool.schema
|
|
92
|
+
.string()
|
|
93
|
+
.optional()
|
|
94
|
+
.describe("Extra context pointers (files/links/notes)"),
|
|
95
|
+
write: tool.schema
|
|
96
|
+
.boolean()
|
|
97
|
+
.optional()
|
|
98
|
+
.describe("When true, append packet to task artifact file"),
|
|
99
|
+
output_file: tool.schema
|
|
100
|
+
.string()
|
|
101
|
+
.optional()
|
|
102
|
+
.describe(
|
|
103
|
+
"Artifact filename under .beads/artifacts/<id>/ (default: delegation.md)",
|
|
104
|
+
),
|
|
105
|
+
},
|
|
106
|
+
execute: async (args: {
|
|
107
|
+
bead_id: string;
|
|
108
|
+
title?: string;
|
|
109
|
+
expected_outcome: string;
|
|
110
|
+
required_tools?: string;
|
|
111
|
+
must_do?: string;
|
|
112
|
+
must_not_do?: string;
|
|
113
|
+
acceptance_checks?: string;
|
|
114
|
+
context?: string;
|
|
115
|
+
write?: boolean;
|
|
116
|
+
output_file?: string;
|
|
117
|
+
}) => {
|
|
118
|
+
const beadId = args.bead_id.trim();
|
|
119
|
+
if (!beadId) return "Error: bead_id is required.";
|
|
120
|
+
if (!isSafePathSegment(beadId)) {
|
|
121
|
+
return "Error: bead_id must be a single path segment (no slashes or '..').";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const title = args.title?.trim();
|
|
125
|
+
const taskLine = title ? `${beadId} - ${title}` : beadId;
|
|
126
|
+
|
|
127
|
+
const requiredTools = splitList(args.required_tools);
|
|
128
|
+
const mustDo = splitList(args.must_do);
|
|
129
|
+
const mustNotDo = splitList(args.must_not_do);
|
|
130
|
+
const acceptanceChecks = splitList(args.acceptance_checks);
|
|
131
|
+
const context = args.context?.trim();
|
|
132
|
+
|
|
133
|
+
const now = new Date();
|
|
134
|
+
const stamp = now.toISOString();
|
|
135
|
+
|
|
136
|
+
const packet = [
|
|
137
|
+
"# Delegation Packet",
|
|
138
|
+
"",
|
|
139
|
+
`- TASK: ${taskLine}`,
|
|
140
|
+
`- EXPECTED OUTCOME: ${args.expected_outcome.trim()}`,
|
|
141
|
+
"- REQUIRED TOOLS:",
|
|
142
|
+
formatBullets(requiredTools),
|
|
143
|
+
"- MUST DO:",
|
|
144
|
+
formatBullets(mustDo),
|
|
145
|
+
"- MUST NOT DO:",
|
|
146
|
+
formatBullets(mustNotDo),
|
|
147
|
+
"- ACCEPTANCE CHECKS:",
|
|
148
|
+
formatBullets(acceptanceChecks),
|
|
149
|
+
"- CONTEXT:",
|
|
150
|
+
context ? context : "(none)",
|
|
151
|
+
].join("\n");
|
|
152
|
+
|
|
153
|
+
if (!args.write) {
|
|
154
|
+
return `${packet}\n`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const artifactDir = path.join(process.cwd(), ".beads", "artifacts", beadId);
|
|
158
|
+
const outName = sanitizeFilename(args.output_file || "delegation.md");
|
|
159
|
+
const outPath = path.join(artifactDir, outName);
|
|
160
|
+
|
|
161
|
+
const specPath = path.join(artifactDir, "spec.md");
|
|
162
|
+
const hasSpec = await fileExists(specPath);
|
|
163
|
+
|
|
164
|
+
await fs.mkdir(artifactDir, { recursive: true });
|
|
165
|
+
|
|
166
|
+
const header = `\n\n---\nGenerated: ${stamp}\n---\n\n`;
|
|
167
|
+
await fs.appendFile(outPath, `${header}${packet}\n`, "utf-8");
|
|
168
|
+
|
|
169
|
+
const specNote = hasSpec
|
|
170
|
+
? ""
|
|
171
|
+
: `\nWarning: spec.md not found at ${specPath}`;
|
|
172
|
+
|
|
173
|
+
return `✓ Delegation packet appended to ${outPath}${specNote}\n\n${packet}\n`;
|
|
174
|
+
},
|
|
175
|
+
});
|