opencode-swarm-plugin 0.43.0 → 0.44.1
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/bin/cass.characterization.test.ts +422 -0
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.test.ts +68 -0
- package/bin/swarm.ts +81 -8
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/contributor-tools.d.ts +42 -0
- package/dist/contributor-tools.d.ts.map +1 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7728 -62590
- package/dist/plugin.js +23833 -78695
- package/dist/sessions/agent-discovery.d.ts +59 -0
- package/dist/sessions/agent-discovery.d.ts.map +1 -0
- package/dist/sessions/index.d.ts +10 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-review.d.ts.map +1 -1
- package/package.json +17 -5
- package/.changeset/swarm-insights-data-layer.md +0 -63
- package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
- package/.hive/analysis/session-data-quality-audit.md +0 -320
- package/.hive/eval-results.json +0 -483
- package/.hive/issues.jsonl +0 -138
- package/.hive/memories.jsonl +0 -729
- package/.opencode/eval-history.jsonl +0 -327
- package/.turbo/turbo-build.log +0 -9
- package/CHANGELOG.md +0 -2255
- package/SCORER-ANALYSIS.md +0 -598
- package/docs/analysis/subagent-coordination-patterns.md +0 -902
- package/docs/analysis-socratic-planner-pattern.md +0 -504
- package/docs/planning/ADR-001-monorepo-structure.md +0 -171
- package/docs/planning/ADR-002-package-extraction.md +0 -393
- package/docs/planning/ADR-003-performance-improvements.md +0 -451
- package/docs/planning/ADR-004-message-queue-features.md +0 -187
- package/docs/planning/ADR-005-devtools-observability.md +0 -202
- package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
- package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
- package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
- package/docs/planning/ROADMAP.md +0 -368
- package/docs/semantic-memory-cli-syntax.md +0 -123
- package/docs/swarm-mail-architecture.md +0 -1147
- package/docs/testing/context-recovery-test.md +0 -470
- package/evals/ARCHITECTURE.md +0 -1189
- package/evals/README.md +0 -768
- package/evals/compaction-prompt.eval.ts +0 -149
- package/evals/compaction-resumption.eval.ts +0 -289
- package/evals/coordinator-behavior.eval.ts +0 -307
- package/evals/coordinator-session.eval.ts +0 -154
- package/evals/evalite.config.ts.bak +0 -15
- package/evals/example.eval.ts +0 -31
- package/evals/fixtures/compaction-cases.ts +0 -350
- package/evals/fixtures/compaction-prompt-cases.ts +0 -311
- package/evals/fixtures/coordinator-sessions.ts +0 -328
- package/evals/fixtures/decomposition-cases.ts +0 -105
- package/evals/lib/compaction-loader.test.ts +0 -248
- package/evals/lib/compaction-loader.ts +0 -320
- package/evals/lib/data-loader.evalite-test.ts +0 -289
- package/evals/lib/data-loader.test.ts +0 -345
- package/evals/lib/data-loader.ts +0 -281
- package/evals/lib/llm.ts +0 -115
- package/evals/scorers/compaction-prompt-scorers.ts +0 -145
- package/evals/scorers/compaction-scorers.ts +0 -305
- package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
- package/evals/scorers/coordinator-discipline.ts +0 -325
- package/evals/scorers/index.test.ts +0 -146
- package/evals/scorers/index.ts +0 -328
- package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
- package/evals/scorers/outcome-scorers.ts +0 -349
- package/evals/swarm-decomposition.eval.ts +0 -121
- package/examples/commands/swarm.md +0 -745
- package/examples/plugin-wrapper-template.ts +0 -2426
- package/examples/skills/hive-workflow/SKILL.md +0 -212
- package/examples/skills/skill-creator/SKILL.md +0 -223
- package/examples/skills/swarm-coordination/SKILL.md +0 -292
- package/global-skills/cli-builder/SKILL.md +0 -344
- package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
- package/global-skills/learning-systems/SKILL.md +0 -644
- package/global-skills/skill-creator/LICENSE.txt +0 -202
- package/global-skills/skill-creator/SKILL.md +0 -352
- package/global-skills/skill-creator/references/output-patterns.md +0 -82
- package/global-skills/skill-creator/references/workflows.md +0 -28
- package/global-skills/swarm-coordination/SKILL.md +0 -995
- package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
- package/global-skills/swarm-coordination/references/strategies.md +0 -138
- package/global-skills/system-design/SKILL.md +0 -213
- package/global-skills/testing-patterns/SKILL.md +0 -430
- package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
- package/opencode-swarm-plugin-0.30.7.tgz +0 -0
- package/opencode-swarm-plugin-0.31.0.tgz +0 -0
- package/scripts/cleanup-test-memories.ts +0 -346
- package/scripts/init-skill.ts +0 -222
- package/scripts/migrate-unknown-sessions.ts +0 -349
- package/scripts/validate-skill.ts +0 -204
- package/src/agent-mail.ts +0 -1724
- package/src/anti-patterns.test.ts +0 -1167
- package/src/anti-patterns.ts +0 -448
- package/src/compaction-capture.integration.test.ts +0 -257
- package/src/compaction-hook.test.ts +0 -838
- package/src/compaction-hook.ts +0 -1204
- package/src/compaction-observability.integration.test.ts +0 -139
- package/src/compaction-observability.test.ts +0 -187
- package/src/compaction-observability.ts +0 -324
- package/src/compaction-prompt-scorers.test.ts +0 -475
- package/src/compaction-prompt-scoring.ts +0 -300
- package/src/dashboard.test.ts +0 -611
- package/src/dashboard.ts +0 -462
- package/src/error-enrichment.test.ts +0 -403
- package/src/error-enrichment.ts +0 -219
- package/src/eval-capture.test.ts +0 -1015
- package/src/eval-capture.ts +0 -929
- package/src/eval-gates.test.ts +0 -306
- package/src/eval-gates.ts +0 -218
- package/src/eval-history.test.ts +0 -508
- package/src/eval-history.ts +0 -214
- package/src/eval-learning.test.ts +0 -378
- package/src/eval-learning.ts +0 -360
- package/src/eval-runner.test.ts +0 -223
- package/src/eval-runner.ts +0 -402
- package/src/export-tools.test.ts +0 -476
- package/src/export-tools.ts +0 -257
- package/src/hive.integration.test.ts +0 -2241
- package/src/hive.ts +0 -1628
- package/src/index.ts +0 -935
- package/src/learning.integration.test.ts +0 -1815
- package/src/learning.ts +0 -1079
- package/src/logger.test.ts +0 -189
- package/src/logger.ts +0 -135
- package/src/mandate-promotion.test.ts +0 -473
- package/src/mandate-promotion.ts +0 -239
- package/src/mandate-storage.integration.test.ts +0 -601
- package/src/mandate-storage.test.ts +0 -578
- package/src/mandate-storage.ts +0 -794
- package/src/mandates.ts +0 -540
- package/src/memory-tools.test.ts +0 -195
- package/src/memory-tools.ts +0 -344
- package/src/memory.integration.test.ts +0 -334
- package/src/memory.test.ts +0 -158
- package/src/memory.ts +0 -527
- package/src/model-selection.test.ts +0 -188
- package/src/model-selection.ts +0 -68
- package/src/observability-tools.test.ts +0 -359
- package/src/observability-tools.ts +0 -871
- package/src/output-guardrails.test.ts +0 -438
- package/src/output-guardrails.ts +0 -381
- package/src/pattern-maturity.test.ts +0 -1160
- package/src/pattern-maturity.ts +0 -525
- package/src/planning-guardrails.test.ts +0 -491
- package/src/planning-guardrails.ts +0 -438
- package/src/plugin.ts +0 -23
- package/src/post-compaction-tracker.test.ts +0 -251
- package/src/post-compaction-tracker.ts +0 -237
- package/src/query-tools.test.ts +0 -636
- package/src/query-tools.ts +0 -324
- package/src/rate-limiter.integration.test.ts +0 -466
- package/src/rate-limiter.ts +0 -774
- package/src/replay-tools.test.ts +0 -496
- package/src/replay-tools.ts +0 -240
- package/src/repo-crawl.integration.test.ts +0 -441
- package/src/repo-crawl.ts +0 -610
- package/src/schemas/cell-events.test.ts +0 -347
- package/src/schemas/cell-events.ts +0 -807
- package/src/schemas/cell.ts +0 -257
- package/src/schemas/evaluation.ts +0 -166
- package/src/schemas/index.test.ts +0 -199
- package/src/schemas/index.ts +0 -286
- package/src/schemas/mandate.ts +0 -232
- package/src/schemas/swarm-context.ts +0 -115
- package/src/schemas/task.ts +0 -161
- package/src/schemas/worker-handoff.test.ts +0 -302
- package/src/schemas/worker-handoff.ts +0 -131
- package/src/skills.integration.test.ts +0 -1192
- package/src/skills.test.ts +0 -643
- package/src/skills.ts +0 -1549
- package/src/storage.integration.test.ts +0 -341
- package/src/storage.ts +0 -884
- package/src/structured.integration.test.ts +0 -817
- package/src/structured.test.ts +0 -1046
- package/src/structured.ts +0 -762
- package/src/swarm-decompose.test.ts +0 -188
- package/src/swarm-decompose.ts +0 -1302
- package/src/swarm-deferred.integration.test.ts +0 -157
- package/src/swarm-deferred.test.ts +0 -38
- package/src/swarm-insights.test.ts +0 -214
- package/src/swarm-insights.ts +0 -459
- package/src/swarm-mail.integration.test.ts +0 -970
- package/src/swarm-mail.ts +0 -739
- package/src/swarm-orchestrate.integration.test.ts +0 -282
- package/src/swarm-orchestrate.test.ts +0 -548
- package/src/swarm-orchestrate.ts +0 -3084
- package/src/swarm-prompts.test.ts +0 -1270
- package/src/swarm-prompts.ts +0 -2077
- package/src/swarm-research.integration.test.ts +0 -701
- package/src/swarm-research.test.ts +0 -698
- package/src/swarm-research.ts +0 -472
- package/src/swarm-review.integration.test.ts +0 -285
- package/src/swarm-review.test.ts +0 -879
- package/src/swarm-review.ts +0 -709
- package/src/swarm-strategies.ts +0 -407
- package/src/swarm-worktree.test.ts +0 -501
- package/src/swarm-worktree.ts +0 -575
- package/src/swarm.integration.test.ts +0 -2377
- package/src/swarm.ts +0 -38
- package/src/tool-adapter.integration.test.ts +0 -1221
- package/src/tool-availability.ts +0 -461
- package/tsconfig.json +0 -28
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Planning Guardrails
|
|
3
|
-
*
|
|
4
|
-
* Detects when agents are about to make planning mistakes and warns them.
|
|
5
|
-
* Non-blocking - just emits warnings to help agents self-correct.
|
|
6
|
-
*
|
|
7
|
-
* @module planning-guardrails
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { captureCoordinatorEvent } from "./eval-capture.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Patterns that suggest file modification work
|
|
14
|
-
* These indicate the todo is about implementation, not tracking
|
|
15
|
-
*/
|
|
16
|
-
const FILE_MODIFICATION_PATTERNS = [
|
|
17
|
-
/\bimplement\b/i,
|
|
18
|
-
/\bcreate\b.*\.(ts|js|tsx|jsx|py|rs|go|java|rb|swift|kt)/i,
|
|
19
|
-
/\badd\b.*\.(ts|js|tsx|jsx|py|rs|go|java|rb|swift|kt)/i,
|
|
20
|
-
/\bupdate\b.*\.(ts|js|tsx|jsx|py|rs|go|java|rb|swift|kt)/i,
|
|
21
|
-
/\bmodify\b/i,
|
|
22
|
-
/\brefactor\b/i,
|
|
23
|
-
/\bextract\b/i,
|
|
24
|
-
/\bmigrate\b/i,
|
|
25
|
-
/\bconvert\b/i,
|
|
26
|
-
/\brewrite\b/i,
|
|
27
|
-
/\bfix\b.*\.(ts|js|tsx|jsx|py|rs|go|java|rb|swift|kt)/i,
|
|
28
|
-
/\bwrite\b.*\.(ts|js|tsx|jsx|py|rs|go|java|rb|swift|kt)/i,
|
|
29
|
-
/src\//i,
|
|
30
|
-
/lib\//i,
|
|
31
|
-
/packages?\//i,
|
|
32
|
-
/components?\//i,
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Patterns that suggest this is tracking/coordination work (OK for todowrite)
|
|
37
|
-
*/
|
|
38
|
-
const TRACKING_PATTERNS = [
|
|
39
|
-
/\breview\b/i,
|
|
40
|
-
/\bcheck\b/i,
|
|
41
|
-
/\bverify\b/i,
|
|
42
|
-
/\btest\b.*pass/i,
|
|
43
|
-
/\brun\b.*test/i,
|
|
44
|
-
/\bdeploy\b/i,
|
|
45
|
-
/\bmerge\b/i,
|
|
46
|
-
/\bpr\b/i,
|
|
47
|
-
/\bpush\b/i,
|
|
48
|
-
/\bcommit\b/i,
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Result of analyzing todowrite args
|
|
53
|
-
*/
|
|
54
|
-
export interface TodoWriteAnalysis {
|
|
55
|
-
/** Whether this looks like parallel work that should use swarm */
|
|
56
|
-
looksLikeParallelWork: boolean;
|
|
57
|
-
|
|
58
|
-
/** Number of todos that look like file modifications */
|
|
59
|
-
fileModificationCount: number;
|
|
60
|
-
|
|
61
|
-
/** Total number of todos */
|
|
62
|
-
totalCount: number;
|
|
63
|
-
|
|
64
|
-
/** Warning message if applicable */
|
|
65
|
-
warning?: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Analyze todowrite args to detect potential planning mistakes
|
|
70
|
-
*
|
|
71
|
-
* Triggers warning when:
|
|
72
|
-
* - 6+ todos created in one call
|
|
73
|
-
* - Most todos match file modification patterns
|
|
74
|
-
* - Few todos match tracking patterns
|
|
75
|
-
*
|
|
76
|
-
* @param args - The todowrite tool arguments
|
|
77
|
-
* @returns Analysis result with optional warning
|
|
78
|
-
*/
|
|
79
|
-
export function analyzeTodoWrite(args: { todos?: unknown[] }): TodoWriteAnalysis {
|
|
80
|
-
const todos = args.todos;
|
|
81
|
-
|
|
82
|
-
// Not enough todos to analyze
|
|
83
|
-
if (!todos || !Array.isArray(todos) || todos.length < 6) {
|
|
84
|
-
return {
|
|
85
|
-
looksLikeParallelWork: false,
|
|
86
|
-
fileModificationCount: 0,
|
|
87
|
-
totalCount: todos?.length ?? 0,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Count todos that look like file modifications
|
|
92
|
-
let fileModificationCount = 0;
|
|
93
|
-
|
|
94
|
-
for (const todo of todos) {
|
|
95
|
-
if (typeof todo !== "object" || todo === null) continue;
|
|
96
|
-
|
|
97
|
-
const content = (todo as { content?: string }).content ?? "";
|
|
98
|
-
|
|
99
|
-
// Check if it matches file modification patterns
|
|
100
|
-
const isFileModification = FILE_MODIFICATION_PATTERNS.some((pattern) =>
|
|
101
|
-
pattern.test(content)
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Check if it matches tracking patterns
|
|
105
|
-
const isTracking = TRACKING_PATTERNS.some((pattern) =>
|
|
106
|
-
pattern.test(content)
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
if (isFileModification && !isTracking) {
|
|
110
|
-
fileModificationCount++;
|
|
111
|
-
}
|
|
112
|
-
// trackingCount not currently used but kept for future ratio analysis
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Trigger warning if most todos look like file modifications
|
|
116
|
-
const ratio = fileModificationCount / todos.length;
|
|
117
|
-
const looksLikeParallelWork = ratio >= 0.5 && fileModificationCount >= 4;
|
|
118
|
-
|
|
119
|
-
if (looksLikeParallelWork) {
|
|
120
|
-
return {
|
|
121
|
-
looksLikeParallelWork: true,
|
|
122
|
-
fileModificationCount,
|
|
123
|
-
totalCount: todos.length,
|
|
124
|
-
warning: `⚠️ This looks like a multi-file implementation plan (${fileModificationCount}/${todos.length} items are file modifications).
|
|
125
|
-
|
|
126
|
-
Consider using swarm instead:
|
|
127
|
-
swarm_decompose → hive_create_epic → parallel task spawns
|
|
128
|
-
|
|
129
|
-
TodoWrite is for tracking progress, not parallelizable implementation work.
|
|
130
|
-
Swarm workers can complete these ${fileModificationCount} tasks in parallel.
|
|
131
|
-
|
|
132
|
-
(Continuing with todowrite - this is just a suggestion)`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
looksLikeParallelWork: false,
|
|
138
|
-
fileModificationCount,
|
|
139
|
-
totalCount: todos.length,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Check if a tool call should trigger planning guardrails
|
|
145
|
-
*
|
|
146
|
-
* @param toolName - Name of the tool being called
|
|
147
|
-
* @returns Whether this tool should be analyzed
|
|
148
|
-
*/
|
|
149
|
-
export function shouldAnalyzeTool(toolName: string): boolean {
|
|
150
|
-
return toolName === "todowrite" || toolName === "TodoWrite";
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Violation patterns for coordinator behavior detection
|
|
155
|
-
*
|
|
156
|
-
* These patterns identify when a coordinator is performing work
|
|
157
|
-
* that should be delegated to worker agents.
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```ts
|
|
161
|
-
* // Bad: Coordinator editing files
|
|
162
|
-
* if (VIOLATION_PATTERNS.FILE_MODIFICATION_TOOLS.includes("edit")) { ... }
|
|
163
|
-
*
|
|
164
|
-
* // Good: Worker editing files
|
|
165
|
-
* // (no violation when agentContext === "worker")
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
export const VIOLATION_PATTERNS = {
|
|
169
|
-
/**
|
|
170
|
-
* Tool names that modify files
|
|
171
|
-
*
|
|
172
|
-
* Coordinators should NEVER call these tools directly.
|
|
173
|
-
* Workers reserve files and make modifications.
|
|
174
|
-
*/
|
|
175
|
-
FILE_MODIFICATION_TOOLS: ["edit", "write"],
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Tool names for file reservations
|
|
179
|
-
*
|
|
180
|
-
* Coordinators don't reserve files - workers do this
|
|
181
|
-
* before editing to prevent conflicts.
|
|
182
|
-
*/
|
|
183
|
-
RESERVATION_TOOLS: ["swarmmail_reserve", "agentmail_reserve"],
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Regex patterns that indicate test execution in bash commands
|
|
187
|
-
*
|
|
188
|
-
* Coordinators review test results, workers run tests.
|
|
189
|
-
* Matches common test runners and test file patterns.
|
|
190
|
-
*/
|
|
191
|
-
TEST_EXECUTION_PATTERNS: [
|
|
192
|
-
/\bbun\s+test\b/i,
|
|
193
|
-
/\bnpm\s+(run\s+)?test/i,
|
|
194
|
-
/\byarn\s+(run\s+)?test/i,
|
|
195
|
-
/\bpnpm\s+(run\s+)?test/i,
|
|
196
|
-
/\bjest\b/i,
|
|
197
|
-
/\bvitest\b/i,
|
|
198
|
-
/\bmocha\b/i,
|
|
199
|
-
/\bava\b/i,
|
|
200
|
-
/\btape\b/i,
|
|
201
|
-
/\.test\.(ts|js|tsx|jsx)\b/i,
|
|
202
|
-
/\.spec\.(ts|js|tsx|jsx)\b/i,
|
|
203
|
-
],
|
|
204
|
-
} as const;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Result of violation detection
|
|
208
|
-
*/
|
|
209
|
-
export interface ViolationDetectionResult {
|
|
210
|
-
/** Whether a violation was detected */
|
|
211
|
-
isViolation: boolean;
|
|
212
|
-
|
|
213
|
-
/** Type of violation if detected */
|
|
214
|
-
violationType?:
|
|
215
|
-
| "coordinator_edited_file"
|
|
216
|
-
| "coordinator_ran_tests"
|
|
217
|
-
| "coordinator_reserved_files"
|
|
218
|
-
| "no_worker_spawned";
|
|
219
|
-
|
|
220
|
-
/** Human-readable message */
|
|
221
|
-
message?: string;
|
|
222
|
-
|
|
223
|
-
/** Payload data for the violation */
|
|
224
|
-
payload?: Record<string, unknown>;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Detect coordinator violations in real-time
|
|
229
|
-
*
|
|
230
|
-
* Checks for patterns that indicate a coordinator is doing work
|
|
231
|
-
* that should be delegated to workers:
|
|
232
|
-
* 1. Edit/Write tool calls (coordinators plan, workers implement)
|
|
233
|
-
* 2. Test execution (workers verify, coordinators review)
|
|
234
|
-
* 3. File reservations (workers reserve before editing)
|
|
235
|
-
* 4. No worker spawned after decomposition (coordinators must delegate)
|
|
236
|
-
*
|
|
237
|
-
* When a violation is detected, captures it via captureCoordinatorEvent().
|
|
238
|
-
*
|
|
239
|
-
* @param params - Detection parameters
|
|
240
|
-
* @returns Violation detection result
|
|
241
|
-
*/
|
|
242
|
-
export function detectCoordinatorViolation(params: {
|
|
243
|
-
sessionId: string;
|
|
244
|
-
epicId: string;
|
|
245
|
-
toolName: string;
|
|
246
|
-
toolArgs: Record<string, unknown>;
|
|
247
|
-
agentContext: "coordinator" | "worker";
|
|
248
|
-
checkNoSpawn?: boolean;
|
|
249
|
-
}): ViolationDetectionResult {
|
|
250
|
-
const { sessionId, epicId, toolName, toolArgs, agentContext, checkNoSpawn = false } = params;
|
|
251
|
-
|
|
252
|
-
// Only check coordinator violations
|
|
253
|
-
if (agentContext !== "coordinator") {
|
|
254
|
-
return { isViolation: false };
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Check for file modification violation
|
|
258
|
-
if (VIOLATION_PATTERNS.FILE_MODIFICATION_TOOLS.includes(toolName as any)) {
|
|
259
|
-
const file = (toolArgs.filePath as string) || "";
|
|
260
|
-
const payload = { tool: toolName, file };
|
|
261
|
-
|
|
262
|
-
captureCoordinatorEvent({
|
|
263
|
-
session_id: sessionId,
|
|
264
|
-
epic_id: epicId,
|
|
265
|
-
timestamp: new Date().toISOString(),
|
|
266
|
-
event_type: "VIOLATION",
|
|
267
|
-
violation_type: "coordinator_edited_file",
|
|
268
|
-
payload,
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
isViolation: true,
|
|
273
|
-
violationType: "coordinator_edited_file",
|
|
274
|
-
message: `⚠️ Coordinator should not edit files directly. Coordinators should spawn workers to implement changes.`,
|
|
275
|
-
payload,
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Check for test execution violation
|
|
280
|
-
if (toolName === "bash") {
|
|
281
|
-
const command = (toolArgs.command as string) || "";
|
|
282
|
-
const isTestCommand = VIOLATION_PATTERNS.TEST_EXECUTION_PATTERNS.some((pattern) =>
|
|
283
|
-
pattern.test(command),
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
if (isTestCommand) {
|
|
287
|
-
const payload = { tool: toolName, command };
|
|
288
|
-
|
|
289
|
-
captureCoordinatorEvent({
|
|
290
|
-
session_id: sessionId,
|
|
291
|
-
epic_id: epicId,
|
|
292
|
-
timestamp: new Date().toISOString(),
|
|
293
|
-
event_type: "VIOLATION",
|
|
294
|
-
violation_type: "coordinator_ran_tests",
|
|
295
|
-
payload,
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
isViolation: true,
|
|
300
|
-
violationType: "coordinator_ran_tests",
|
|
301
|
-
message: `⚠️ Coordinator should not run tests directly. Workers run tests as part of their implementation verification.`,
|
|
302
|
-
payload,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Check for file reservation violation
|
|
308
|
-
if (VIOLATION_PATTERNS.RESERVATION_TOOLS.includes(toolName as any)) {
|
|
309
|
-
const paths = (toolArgs.paths as string[]) || [];
|
|
310
|
-
const payload = { tool: toolName, paths };
|
|
311
|
-
|
|
312
|
-
captureCoordinatorEvent({
|
|
313
|
-
session_id: sessionId,
|
|
314
|
-
epic_id: epicId,
|
|
315
|
-
timestamp: new Date().toISOString(),
|
|
316
|
-
event_type: "VIOLATION",
|
|
317
|
-
violation_type: "coordinator_reserved_files",
|
|
318
|
-
payload,
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
return {
|
|
322
|
-
isViolation: true,
|
|
323
|
-
violationType: "coordinator_reserved_files",
|
|
324
|
-
message: `⚠️ Coordinator should not reserve files. Workers reserve files before editing to prevent conflicts.`,
|
|
325
|
-
payload,
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// Check for no worker spawned after decomposition
|
|
330
|
-
if (toolName === "hive_create_epic" && checkNoSpawn) {
|
|
331
|
-
const epicTitle = (toolArgs.epic_title as string) || "";
|
|
332
|
-
const subtasks = (toolArgs.subtasks as unknown[]) || [];
|
|
333
|
-
const payload = { epic_title: epicTitle, subtask_count: subtasks.length };
|
|
334
|
-
|
|
335
|
-
captureCoordinatorEvent({
|
|
336
|
-
session_id: sessionId,
|
|
337
|
-
epic_id: epicId,
|
|
338
|
-
timestamp: new Date().toISOString(),
|
|
339
|
-
event_type: "VIOLATION",
|
|
340
|
-
violation_type: "no_worker_spawned",
|
|
341
|
-
payload,
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
return {
|
|
345
|
-
isViolation: true,
|
|
346
|
-
violationType: "no_worker_spawned",
|
|
347
|
-
message: `⚠️ Coordinator created decomposition without spawning workers. After hive_create_epic, use swarm_spawn_subtask for each task.`,
|
|
348
|
-
payload,
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return { isViolation: false };
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Coordinator context state
|
|
357
|
-
*
|
|
358
|
-
* Tracks whether the current session is acting as a swarm coordinator.
|
|
359
|
-
* Set when an epic is created or when swarm tools are used.
|
|
360
|
-
*/
|
|
361
|
-
interface CoordinatorContext {
|
|
362
|
-
/** Whether we're in coordinator mode */
|
|
363
|
-
isCoordinator: boolean;
|
|
364
|
-
/** Active epic ID if any */
|
|
365
|
-
epicId?: string;
|
|
366
|
-
/** Session ID for event capture */
|
|
367
|
-
sessionId?: string;
|
|
368
|
-
/** When coordinator mode was activated */
|
|
369
|
-
activatedAt?: number;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/** Global coordinator context state */
|
|
373
|
-
let coordinatorContext: CoordinatorContext = {
|
|
374
|
-
isCoordinator: false,
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Set coordinator context
|
|
379
|
-
*
|
|
380
|
-
* Called when swarm coordination begins (e.g., after hive_create_epic or swarm_decompose).
|
|
381
|
-
*
|
|
382
|
-
* @param ctx - Coordinator context to set
|
|
383
|
-
*/
|
|
384
|
-
export function setCoordinatorContext(ctx: Partial<CoordinatorContext>): void {
|
|
385
|
-
coordinatorContext = {
|
|
386
|
-
...coordinatorContext,
|
|
387
|
-
...ctx,
|
|
388
|
-
activatedAt: ctx.isCoordinator ? Date.now() : coordinatorContext.activatedAt,
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Get current coordinator context
|
|
394
|
-
*
|
|
395
|
-
* @returns Current coordinator context state
|
|
396
|
-
*/
|
|
397
|
-
export function getCoordinatorContext(): CoordinatorContext {
|
|
398
|
-
return { ...coordinatorContext };
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Clear coordinator context
|
|
403
|
-
*
|
|
404
|
-
* Called when swarm coordination ends (e.g., epic closed or session ends).
|
|
405
|
-
*/
|
|
406
|
-
export function clearCoordinatorContext(): void {
|
|
407
|
-
coordinatorContext = {
|
|
408
|
-
isCoordinator: false,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Check if we're in coordinator context
|
|
414
|
-
*
|
|
415
|
-
* Returns true if:
|
|
416
|
-
* 1. Coordinator context was explicitly set
|
|
417
|
-
* 2. Context was set within the last 4 hours (session timeout)
|
|
418
|
-
*
|
|
419
|
-
* @returns Whether we're currently in coordinator mode
|
|
420
|
-
*/
|
|
421
|
-
export function isInCoordinatorContext(): boolean {
|
|
422
|
-
if (!coordinatorContext.isCoordinator) {
|
|
423
|
-
return false;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// Check for session timeout (4 hours)
|
|
427
|
-
const COORDINATOR_TIMEOUT_MS = 4 * 60 * 60 * 1000;
|
|
428
|
-
if (coordinatorContext.activatedAt) {
|
|
429
|
-
const elapsed = Date.now() - coordinatorContext.activatedAt;
|
|
430
|
-
if (elapsed > COORDINATOR_TIMEOUT_MS) {
|
|
431
|
-
// Session timed out, clear context
|
|
432
|
-
clearCoordinatorContext();
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return true;
|
|
438
|
-
}
|
package/src/plugin.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenCode Plugin Entry Point
|
|
3
|
-
*
|
|
4
|
-
* CRITICAL: Only export the plugin function as DEFAULT from this file.
|
|
5
|
-
*
|
|
6
|
-
* OpenCode's plugin loader calls ALL exports as functions during initialization.
|
|
7
|
-
* If you export both named AND default pointing to the same function, the plugin
|
|
8
|
-
* gets registered TWICE, causing hooks to fire multiple times.
|
|
9
|
-
*
|
|
10
|
-
* If you need to export utilities for external use, add them to src/index.ts instead.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* // ✅ CORRECT - only default export
|
|
14
|
-
* export default SwarmPlugin;
|
|
15
|
-
*
|
|
16
|
-
* // ❌ WRONG - causes double registration
|
|
17
|
-
* export { SwarmPlugin };
|
|
18
|
-
* export default SwarmPlugin;
|
|
19
|
-
*/
|
|
20
|
-
import SwarmPlugin from "./index";
|
|
21
|
-
|
|
22
|
-
// Only default export - no named exports!
|
|
23
|
-
export default SwarmPlugin;
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Post-Compaction Tool Call Tracker Tests
|
|
3
|
-
*
|
|
4
|
-
* TDD: RED → GREEN → REFACTOR
|
|
5
|
-
*
|
|
6
|
-
* Tests tracking of tool calls after compaction resumption.
|
|
7
|
-
* Emits resumption_started on first tool call, then tool_call_tracked for each call (max 20).
|
|
8
|
-
* Detects coordinator violations: Edit, Write, swarmmail_reserve are forbidden.
|
|
9
|
-
*/
|
|
10
|
-
import { describe, test, expect, beforeEach, mock } from "bun:test";
|
|
11
|
-
import {
|
|
12
|
-
createPostCompactionTracker,
|
|
13
|
-
type PostCompactionTracker,
|
|
14
|
-
type ToolCallEvent,
|
|
15
|
-
} from "./post-compaction-tracker";
|
|
16
|
-
|
|
17
|
-
describe("PostCompactionTracker - TDD", () => {
|
|
18
|
-
let tracker: PostCompactionTracker;
|
|
19
|
-
let mockCapture: ReturnType<typeof mock>;
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
mockCapture = mock((event: any) => {});
|
|
23
|
-
tracker = createPostCompactionTracker({
|
|
24
|
-
sessionId: "test-session",
|
|
25
|
-
epicId: "mjkwehsqnbm",
|
|
26
|
-
onEvent: mockCapture,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// ============================================================================
|
|
31
|
-
// RED: Test resumption_started event
|
|
32
|
-
// ============================================================================
|
|
33
|
-
|
|
34
|
-
test("emits resumption_started on first tool call", () => {
|
|
35
|
-
const toolCall: ToolCallEvent = {
|
|
36
|
-
tool: "read",
|
|
37
|
-
args: { filePath: "/test/file.ts" },
|
|
38
|
-
timestamp: Date.now(),
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
tracker.trackToolCall(toolCall);
|
|
42
|
-
|
|
43
|
-
expect(mockCapture).toHaveBeenCalledTimes(2); // resumption_started + tool_call_tracked
|
|
44
|
-
const firstCall = mockCapture.mock.calls[0][0];
|
|
45
|
-
expect(firstCall.compaction_type).toBe("resumption_started");
|
|
46
|
-
expect(firstCall.payload.session_id).toBe("test-session");
|
|
47
|
-
expect(firstCall.payload.epic_id).toBe("mjkwehsqnbm");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("resumption_started only emitted once", () => {
|
|
51
|
-
tracker.trackToolCall({
|
|
52
|
-
tool: "read",
|
|
53
|
-
args: {},
|
|
54
|
-
timestamp: Date.now(),
|
|
55
|
-
});
|
|
56
|
-
tracker.trackToolCall({
|
|
57
|
-
tool: "glob",
|
|
58
|
-
args: {},
|
|
59
|
-
timestamp: Date.now(),
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// First call: resumption_started + tool_call_tracked
|
|
63
|
-
// Second call: tool_call_tracked only
|
|
64
|
-
expect(mockCapture).toHaveBeenCalledTimes(3);
|
|
65
|
-
|
|
66
|
-
const calls = mockCapture.mock.calls;
|
|
67
|
-
expect(calls[0][0].compaction_type).toBe("resumption_started");
|
|
68
|
-
expect(calls[1][0].compaction_type).toBe("tool_call_tracked");
|
|
69
|
-
expect(calls[2][0].compaction_type).toBe("tool_call_tracked");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// ============================================================================
|
|
73
|
-
// RED: Test tool_call_tracked event
|
|
74
|
-
// ============================================================================
|
|
75
|
-
|
|
76
|
-
test("emits tool_call_tracked for each of first 20 calls", () => {
|
|
77
|
-
for (let i = 0; i < 20; i++) {
|
|
78
|
-
tracker.trackToolCall({
|
|
79
|
-
tool: `tool-${i}`,
|
|
80
|
-
args: {},
|
|
81
|
-
timestamp: Date.now(),
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// First call: resumption_started + tool_call_tracked = 2
|
|
86
|
-
// Next 19 calls: tool_call_tracked only = 19
|
|
87
|
-
// Total: 21 events (1 resumption_started + 20 tool_call_tracked)
|
|
88
|
-
expect(mockCapture).toHaveBeenCalledTimes(21);
|
|
89
|
-
|
|
90
|
-
const trackedEvents = mockCapture.mock.calls.filter(
|
|
91
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
92
|
-
);
|
|
93
|
-
expect(trackedEvents).toHaveLength(20);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("tool_call_tracked includes tool name and args", () => {
|
|
97
|
-
tracker.trackToolCall({
|
|
98
|
-
tool: "edit",
|
|
99
|
-
args: { filePath: "/test.ts", oldString: "foo", newString: "bar" },
|
|
100
|
-
timestamp: Date.now(),
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const trackedEvent = mockCapture.mock.calls.find(
|
|
104
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
105
|
-
)?.[0];
|
|
106
|
-
|
|
107
|
-
expect(trackedEvent).toBeDefined();
|
|
108
|
-
expect(trackedEvent.payload.tool).toBe("edit");
|
|
109
|
-
expect(trackedEvent.payload.args.filePath).toBe("/test.ts");
|
|
110
|
-
expect(trackedEvent.payload.call_number).toBe(1);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// ============================================================================
|
|
114
|
-
// RED: Test coordinator violation detection
|
|
115
|
-
// ============================================================================
|
|
116
|
-
|
|
117
|
-
test("detects Edit as coordinator violation", () => {
|
|
118
|
-
tracker.trackToolCall({
|
|
119
|
-
tool: "edit",
|
|
120
|
-
args: { filePath: "/test.ts", oldString: "a", newString: "b" },
|
|
121
|
-
timestamp: Date.now(),
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const trackedEvent = mockCapture.mock.calls.find(
|
|
125
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
126
|
-
)?.[0];
|
|
127
|
-
|
|
128
|
-
expect(trackedEvent.payload.is_coordinator_violation).toBe(true);
|
|
129
|
-
expect(trackedEvent.payload.violation_reason).toBe(
|
|
130
|
-
"Coordinators NEVER edit files - spawn worker instead",
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("detects Write as coordinator violation", () => {
|
|
135
|
-
tracker.trackToolCall({
|
|
136
|
-
tool: "write",
|
|
137
|
-
args: { filePath: "/new.ts", content: "export {}" },
|
|
138
|
-
timestamp: Date.now(),
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const trackedEvent = mockCapture.mock.calls.find(
|
|
142
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
143
|
-
)?.[0];
|
|
144
|
-
|
|
145
|
-
expect(trackedEvent.payload.is_coordinator_violation).toBe(true);
|
|
146
|
-
expect(trackedEvent.payload.violation_reason).toBe(
|
|
147
|
-
"Coordinators NEVER write files - spawn worker instead",
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("detects swarmmail_reserve as coordinator violation", () => {
|
|
152
|
-
tracker.trackToolCall({
|
|
153
|
-
tool: "swarmmail_reserve",
|
|
154
|
-
args: { paths: ["/src/**"], reason: "test" },
|
|
155
|
-
timestamp: Date.now(),
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
const trackedEvent = mockCapture.mock.calls.find(
|
|
159
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
160
|
-
)?.[0];
|
|
161
|
-
|
|
162
|
-
expect(trackedEvent.payload.is_coordinator_violation).toBe(true);
|
|
163
|
-
expect(trackedEvent.payload.violation_reason).toBe(
|
|
164
|
-
"Coordinators NEVER reserve files - workers reserve files",
|
|
165
|
-
);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test("does not flag Read as violation", () => {
|
|
169
|
-
tracker.trackToolCall({
|
|
170
|
-
tool: "read",
|
|
171
|
-
args: { filePath: "/test.ts" },
|
|
172
|
-
timestamp: Date.now(),
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const trackedEvent = mockCapture.mock.calls.find(
|
|
176
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
177
|
-
)?.[0];
|
|
178
|
-
|
|
179
|
-
expect(trackedEvent.payload.is_coordinator_violation).toBe(false);
|
|
180
|
-
expect(trackedEvent.payload.violation_reason).toBeUndefined();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
test("does not flag swarm_spawn_subtask as violation", () => {
|
|
184
|
-
tracker.trackToolCall({
|
|
185
|
-
tool: "swarm_spawn_subtask",
|
|
186
|
-
args: { bead_id: "bd-123", subtask_title: "Test" },
|
|
187
|
-
timestamp: Date.now(),
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
const trackedEvent = mockCapture.mock.calls.find(
|
|
191
|
-
(call: any) => call[0].compaction_type === "tool_call_tracked",
|
|
192
|
-
)?.[0];
|
|
193
|
-
|
|
194
|
-
expect(trackedEvent.payload.is_coordinator_violation).toBe(false);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// ============================================================================
|
|
198
|
-
// RED: Test tracking stops after 20 calls
|
|
199
|
-
// ============================================================================
|
|
200
|
-
|
|
201
|
-
test("stops tracking after 20 calls", () => {
|
|
202
|
-
for (let i = 0; i < 25; i++) {
|
|
203
|
-
tracker.trackToolCall({
|
|
204
|
-
tool: `tool-${i}`,
|
|
205
|
-
args: {},
|
|
206
|
-
timestamp: Date.now(),
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Should only track first 20: 1 resumption_started + 20 tool_call_tracked
|
|
211
|
-
expect(mockCapture).toHaveBeenCalledTimes(21);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test("returns tracking status", () => {
|
|
215
|
-
expect(tracker.isTracking()).toBe(true);
|
|
216
|
-
|
|
217
|
-
for (let i = 0; i < 20; i++) {
|
|
218
|
-
tracker.trackToolCall({
|
|
219
|
-
tool: `tool-${i}`,
|
|
220
|
-
args: {},
|
|
221
|
-
timestamp: Date.now(),
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
expect(tracker.isTracking()).toBe(false);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// ============================================================================
|
|
229
|
-
// RED: Test configurable limit
|
|
230
|
-
// ============================================================================
|
|
231
|
-
|
|
232
|
-
test("respects custom call limit", () => {
|
|
233
|
-
const customTracker = createPostCompactionTracker({
|
|
234
|
-
sessionId: "test",
|
|
235
|
-
epicId: "test",
|
|
236
|
-
onEvent: mockCapture,
|
|
237
|
-
maxCalls: 5,
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
for (let i = 0; i < 10; i++) {
|
|
241
|
-
customTracker.trackToolCall({
|
|
242
|
-
tool: `tool-${i}`,
|
|
243
|
-
args: {},
|
|
244
|
-
timestamp: Date.now(),
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// 1 resumption_started + 5 tool_call_tracked
|
|
249
|
-
expect(mockCapture).toHaveBeenCalledTimes(6);
|
|
250
|
-
});
|
|
251
|
-
});
|