opencode-swarm-plugin 0.44.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/swarm.serve.test.ts +6 -4
- package/bin/swarm.ts +16 -10
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.js +7644 -62599
- package/dist/plugin.js +23766 -78721
- 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 -2286
- 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/ADR-010-cass-inhousing.md +0 -1215
- 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/cass-baseline.ts +0 -217
- 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 -2515
- 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/contributor-tools.test.ts +0 -133
- package/src/contributor-tools.ts +0 -201
- 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 -940
- 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/sessions/agent-discovery.test.ts +0 -137
- package/src/sessions/agent-discovery.ts +0 -112
- package/src/sessions/index.ts +0 -15
- 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,838 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for Swarm-Aware Compaction Hook
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it, mock, beforeEach } from "bun:test";
|
|
6
|
-
import {
|
|
7
|
-
SWARM_COMPACTION_CONTEXT,
|
|
8
|
-
SWARM_DETECTION_FALLBACK,
|
|
9
|
-
createCompactionHook,
|
|
10
|
-
scanSessionMessages,
|
|
11
|
-
type ScannedSwarmState,
|
|
12
|
-
} from "./compaction-hook";
|
|
13
|
-
|
|
14
|
-
// Track log calls for verification
|
|
15
|
-
let logCalls: Array<{ level: string; data: any; message?: string }> = [];
|
|
16
|
-
|
|
17
|
-
// Mock logger factory
|
|
18
|
-
const createMockLogger = () => ({
|
|
19
|
-
info: (data: any, message?: string) => {
|
|
20
|
-
logCalls.push({ level: "info", data, message });
|
|
21
|
-
},
|
|
22
|
-
debug: (data: any, message?: string) => {
|
|
23
|
-
logCalls.push({ level: "debug", data, message });
|
|
24
|
-
},
|
|
25
|
-
warn: (data: any, message?: string) => {
|
|
26
|
-
logCalls.push({ level: "warn", data, message });
|
|
27
|
-
},
|
|
28
|
-
error: (data: any, message?: string) => {
|
|
29
|
-
logCalls.push({ level: "error", data, message });
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Mock the dependencies
|
|
34
|
-
mock.module("./hive", () => ({
|
|
35
|
-
getHiveWorkingDirectory: () => "/test/project",
|
|
36
|
-
getHiveAdapter: async () => ({
|
|
37
|
-
queryCells: async () => [],
|
|
38
|
-
}),
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
mock.module("swarm-mail", () => ({
|
|
42
|
-
checkSwarmHealth: async () => ({
|
|
43
|
-
healthy: true,
|
|
44
|
-
database: "connected",
|
|
45
|
-
stats: {
|
|
46
|
-
events: 0,
|
|
47
|
-
agents: 0,
|
|
48
|
-
messages: 0,
|
|
49
|
-
reservations: 0,
|
|
50
|
-
},
|
|
51
|
-
}),
|
|
52
|
-
}));
|
|
53
|
-
|
|
54
|
-
// Mock logger module
|
|
55
|
-
mock.module("./logger", () => ({
|
|
56
|
-
createChildLogger: () => createMockLogger(),
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
describe("Compaction Hook", () => {
|
|
60
|
-
beforeEach(() => {
|
|
61
|
-
// Reset log calls before each test
|
|
62
|
-
logCalls = [];
|
|
63
|
-
});
|
|
64
|
-
describe("SWARM_COMPACTION_CONTEXT", () => {
|
|
65
|
-
it("contains coordinator instructions", () => {
|
|
66
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("COORDINATOR");
|
|
67
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("YOU ARE THE COORDINATOR");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("contains prohibition-first anti-patterns", () => {
|
|
71
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("NEVER");
|
|
72
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("edit");
|
|
73
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("write");
|
|
74
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("SPAWN A WORKER");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("contains resume instructions", () => {
|
|
78
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_status");
|
|
79
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarmmail_inbox");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("contains summary format", () => {
|
|
83
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("Swarm State");
|
|
84
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("Active:");
|
|
85
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("Blocked:");
|
|
86
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("Completed:");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// NEW: Full coordinator workflow must be present post-compaction
|
|
90
|
-
it("contains FULL coordinator workflow phases", () => {
|
|
91
|
-
// Phase 1.5: Research Phase
|
|
92
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_spawn_researcher");
|
|
93
|
-
|
|
94
|
-
// Phase 3: Decompose
|
|
95
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_select_strategy");
|
|
96
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_plan_prompt");
|
|
97
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_validate_decomposition");
|
|
98
|
-
|
|
99
|
-
// Phase 4: Create Cells
|
|
100
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("hive_create_epic");
|
|
101
|
-
|
|
102
|
-
// Phase 6: Spawn Workers
|
|
103
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_spawn_subtask");
|
|
104
|
-
|
|
105
|
-
// Phase 7: Review Loop
|
|
106
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_review");
|
|
107
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_review_feedback");
|
|
108
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_spawn_retry");
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("contains forbidden tools section with ALL forbidden tools", () => {
|
|
112
|
-
// Repository fetching
|
|
113
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("repo-crawl_file");
|
|
114
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("repo-autopsy");
|
|
115
|
-
|
|
116
|
-
// Web/documentation fetching
|
|
117
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("webfetch");
|
|
118
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("fetch_fetch");
|
|
119
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("context7");
|
|
120
|
-
|
|
121
|
-
// Knowledge base
|
|
122
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("pdf-brain");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("contains strategy reference table", () => {
|
|
126
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("file-based");
|
|
127
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("feature-based");
|
|
128
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("risk-based");
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe("SWARM_DETECTION_FALLBACK", () => {
|
|
133
|
-
it("contains detection patterns", () => {
|
|
134
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("swarm_decompose");
|
|
135
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("swarmmail_init");
|
|
136
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("hive_create_epic");
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("contains ID patterns", () => {
|
|
140
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("bd-xxx");
|
|
141
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("Agent names");
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("contains coordination language", () => {
|
|
145
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("spawn");
|
|
146
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("coordinator");
|
|
147
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("reservation");
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe("createCompactionHook", () => {
|
|
152
|
-
it("returns a function", () => {
|
|
153
|
-
const hook = createCompactionHook();
|
|
154
|
-
expect(typeof hook).toBe("function");
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("accepts input and output parameters", async () => {
|
|
158
|
-
const hook = createCompactionHook();
|
|
159
|
-
const input = { sessionID: "test-session" };
|
|
160
|
-
const output = { context: [] as string[] };
|
|
161
|
-
|
|
162
|
-
// Should not throw
|
|
163
|
-
await hook(input, output);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("does not inject context when no swarm detected", async () => {
|
|
167
|
-
const hook = createCompactionHook();
|
|
168
|
-
const output = { context: [] as string[] };
|
|
169
|
-
|
|
170
|
-
await hook({ sessionID: "test" }, output);
|
|
171
|
-
|
|
172
|
-
// With mocked empty data, should not inject
|
|
173
|
-
expect(output.context.length).toBe(0);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe("Detection confidence levels", () => {
|
|
178
|
-
it("HIGH confidence triggers full context", async () => {
|
|
179
|
-
// This would need proper mocking of active reservations
|
|
180
|
-
// For now, just verify the context strings exist
|
|
181
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("YOU ARE THE COORDINATOR");
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("LOW confidence triggers fallback prompt", async () => {
|
|
185
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("Swarm Detection");
|
|
186
|
-
expect(SWARM_DETECTION_FALLBACK).toContain("Check Your Context");
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe("Forbidden tools anti-pattern (TDD red phase)", () => {
|
|
191
|
-
it("SWARM_COMPACTION_CONTEXT includes 'NEVER fetch directly' rule", () => {
|
|
192
|
-
// Should warn against direct fetching
|
|
193
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("NEVER");
|
|
194
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("repo-crawl");
|
|
195
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("webfetch");
|
|
196
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("fetch_fetch");
|
|
197
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("context7");
|
|
198
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("pdf-brain");
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("SWARM_COMPACTION_CONTEXT instructs to spawn researcher instead", () => {
|
|
202
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("SPAWN A RESEARCHER");
|
|
203
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("swarm_spawn_researcher");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("lists all forbidden repo-crawl tools", () => {
|
|
207
|
-
const forbiddenTools = [
|
|
208
|
-
"repo-crawl_file",
|
|
209
|
-
"repo-crawl_readme",
|
|
210
|
-
"repo-crawl_search",
|
|
211
|
-
"repo-crawl_structure",
|
|
212
|
-
"repo-crawl_tree"
|
|
213
|
-
];
|
|
214
|
-
|
|
215
|
-
for (const tool of forbiddenTools) {
|
|
216
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain(tool);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("lists all forbidden repo-autopsy tools", () => {
|
|
221
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("repo-autopsy");
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("lists all forbidden context7 tools", () => {
|
|
225
|
-
const forbiddenTools = [
|
|
226
|
-
"context7_resolve-library-id",
|
|
227
|
-
"context7_get-library-docs"
|
|
228
|
-
];
|
|
229
|
-
|
|
230
|
-
for (const tool of forbiddenTools) {
|
|
231
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain(tool);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("lists all forbidden pdf-brain tools", () => {
|
|
236
|
-
const forbiddenTools = [
|
|
237
|
-
"pdf-brain_search",
|
|
238
|
-
"pdf-brain_read"
|
|
239
|
-
];
|
|
240
|
-
|
|
241
|
-
for (const tool of forbiddenTools) {
|
|
242
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain(tool);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe("Coordinator identity reinforcement (TDD red phase)", () => {
|
|
248
|
-
it("includes ASCII header for coordinator identity", () => {
|
|
249
|
-
// Should have prominent visual indicator
|
|
250
|
-
expect(SWARM_COMPACTION_CONTEXT).toMatch(/[╔═╗║╚╝]|[┌─┐│└┘]|[█▀▄]/);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("repeats 'YOU ARE THE COORDINATOR' multiple times", () => {
|
|
254
|
-
const matches = SWARM_COMPACTION_CONTEXT.match(/YOU ARE THE COORDINATOR/gi);
|
|
255
|
-
expect(matches).toBeDefined();
|
|
256
|
-
expect(matches!.length).toBeGreaterThanOrEqual(2);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it("uses strong imperative language NEVER/ALWAYS/NON-NEGOTIABLE", () => {
|
|
260
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("NEVER");
|
|
261
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("ALWAYS");
|
|
262
|
-
expect(SWARM_COMPACTION_CONTEXT).toContain("NON-NEGOTIABLE");
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("makes role unmistakable with multiple strong statements", () => {
|
|
266
|
-
// Check for strong coordinator identity statements
|
|
267
|
-
const identityPatterns = [
|
|
268
|
-
/YOU ARE THE COORDINATOR/i,
|
|
269
|
-
/NOT A WORKER/i,
|
|
270
|
-
/ORCHESTRATE/i,
|
|
271
|
-
/DO NOT IMPLEMENT/i
|
|
272
|
-
];
|
|
273
|
-
|
|
274
|
-
let matchCount = 0;
|
|
275
|
-
for (const pattern of identityPatterns) {
|
|
276
|
-
if (pattern.test(SWARM_COMPACTION_CONTEXT)) {
|
|
277
|
-
matchCount++;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
expect(matchCount).toBeGreaterThanOrEqual(3);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe("Specific swarm state injection (TDD red phase)", () => {
|
|
286
|
-
it("includes specific epic ID when in_progress epic exists", async () => {
|
|
287
|
-
// Mock hive with an in_progress epic
|
|
288
|
-
mock.module("./hive", () => ({
|
|
289
|
-
getHiveWorkingDirectory: () => "/test/project",
|
|
290
|
-
getHiveAdapter: async () => ({
|
|
291
|
-
queryCells: async () => [
|
|
292
|
-
{
|
|
293
|
-
id: "bd-epic-123",
|
|
294
|
-
title: "Add authentication system",
|
|
295
|
-
type: "epic",
|
|
296
|
-
status: "in_progress",
|
|
297
|
-
parent_id: null,
|
|
298
|
-
updated_at: Date.now(),
|
|
299
|
-
},
|
|
300
|
-
],
|
|
301
|
-
}),
|
|
302
|
-
}));
|
|
303
|
-
|
|
304
|
-
const hook = createCompactionHook();
|
|
305
|
-
const input = { sessionID: "test-session" };
|
|
306
|
-
const output = { context: [] as string[] };
|
|
307
|
-
|
|
308
|
-
await hook(input, output);
|
|
309
|
-
|
|
310
|
-
// Should inject context with the SPECIFIC epic ID, not a placeholder
|
|
311
|
-
expect(output.context.length).toBeGreaterThan(0);
|
|
312
|
-
const injectedContext = output.context[0];
|
|
313
|
-
expect(injectedContext).toContain("bd-epic-123");
|
|
314
|
-
expect(injectedContext).toContain("Add authentication system");
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
it("includes subtask status summary in injected context", async () => {
|
|
318
|
-
// Mock hive with epic + subtasks in various states
|
|
319
|
-
mock.module("./hive", () => ({
|
|
320
|
-
getHiveWorkingDirectory: () => "/test/project",
|
|
321
|
-
getHiveAdapter: async () => ({
|
|
322
|
-
queryCells: async () => [
|
|
323
|
-
{
|
|
324
|
-
id: "bd-epic-456",
|
|
325
|
-
title: "Refactor auth flow",
|
|
326
|
-
type: "epic",
|
|
327
|
-
status: "in_progress",
|
|
328
|
-
parent_id: null,
|
|
329
|
-
updated_at: Date.now(),
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
id: "bd-epic-456.1",
|
|
333
|
-
title: "Update schema",
|
|
334
|
-
type: "task",
|
|
335
|
-
status: "closed",
|
|
336
|
-
parent_id: "bd-epic-456",
|
|
337
|
-
updated_at: Date.now(),
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
id: "bd-epic-456.2",
|
|
341
|
-
title: "Implement service layer",
|
|
342
|
-
type: "task",
|
|
343
|
-
status: "in_progress",
|
|
344
|
-
parent_id: "bd-epic-456",
|
|
345
|
-
updated_at: Date.now(),
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
id: "bd-epic-456.3",
|
|
349
|
-
title: "Add tests",
|
|
350
|
-
type: "task",
|
|
351
|
-
status: "open",
|
|
352
|
-
parent_id: "bd-epic-456",
|
|
353
|
-
updated_at: Date.now(),
|
|
354
|
-
},
|
|
355
|
-
],
|
|
356
|
-
}),
|
|
357
|
-
}));
|
|
358
|
-
|
|
359
|
-
const hook = createCompactionHook();
|
|
360
|
-
const input = { sessionID: "test-session" };
|
|
361
|
-
const output = { context: [] as string[] };
|
|
362
|
-
|
|
363
|
-
await hook(input, output);
|
|
364
|
-
|
|
365
|
-
expect(output.context.length).toBeGreaterThan(0);
|
|
366
|
-
const injectedContext = output.context[0];
|
|
367
|
-
|
|
368
|
-
// Should show subtask counts: 1 closed, 1 in_progress, 1 open
|
|
369
|
-
expect(injectedContext).toMatch(/1.*closed/i);
|
|
370
|
-
expect(injectedContext).toMatch(/1.*in_progress/i);
|
|
371
|
-
expect(injectedContext).toMatch(/1.*open/i);
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it("includes project path in context", async () => {
|
|
375
|
-
mock.module("./hive", () => ({
|
|
376
|
-
getHiveWorkingDirectory: () => "/Users/joel/test-project",
|
|
377
|
-
getHiveAdapter: async () => ({
|
|
378
|
-
queryCells: async () => [
|
|
379
|
-
{
|
|
380
|
-
id: "bd-epic-789",
|
|
381
|
-
title: "Feature work",
|
|
382
|
-
type: "epic",
|
|
383
|
-
status: "in_progress",
|
|
384
|
-
parent_id: null,
|
|
385
|
-
updated_at: Date.now(),
|
|
386
|
-
},
|
|
387
|
-
],
|
|
388
|
-
}),
|
|
389
|
-
}));
|
|
390
|
-
|
|
391
|
-
const hook = createCompactionHook();
|
|
392
|
-
const input = { sessionID: "test-session" };
|
|
393
|
-
const output = { context: [] as string[] };
|
|
394
|
-
|
|
395
|
-
await hook(input, output);
|
|
396
|
-
|
|
397
|
-
expect(output.context.length).toBeGreaterThan(0);
|
|
398
|
-
const injectedContext = output.context[0];
|
|
399
|
-
|
|
400
|
-
// Should include the actual project path, not a placeholder
|
|
401
|
-
expect(injectedContext).toContain("/Users/joel/test-project");
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it("includes actionable swarm_status call with epic ID", async () => {
|
|
405
|
-
mock.module("./hive", () => ({
|
|
406
|
-
getHiveWorkingDirectory: () => "/test/project",
|
|
407
|
-
getHiveAdapter: async () => ({
|
|
408
|
-
queryCells: async () => [
|
|
409
|
-
{
|
|
410
|
-
id: "bd-epic-999",
|
|
411
|
-
title: "Critical fix",
|
|
412
|
-
type: "epic",
|
|
413
|
-
status: "in_progress",
|
|
414
|
-
parent_id: null,
|
|
415
|
-
updated_at: Date.now(),
|
|
416
|
-
},
|
|
417
|
-
],
|
|
418
|
-
}),
|
|
419
|
-
}));
|
|
420
|
-
|
|
421
|
-
const hook = createCompactionHook();
|
|
422
|
-
const input = { sessionID: "test-session" };
|
|
423
|
-
const output = { context: [] as string[] };
|
|
424
|
-
|
|
425
|
-
await hook(input, output);
|
|
426
|
-
|
|
427
|
-
expect(output.context.length).toBeGreaterThan(0);
|
|
428
|
-
const injectedContext = output.context[0];
|
|
429
|
-
|
|
430
|
-
// Should include actionable swarm_status call with the SPECIFIC epic ID
|
|
431
|
-
expect(injectedContext).toContain('swarm_status(epic_id="bd-epic-999"');
|
|
432
|
-
expect(injectedContext).toContain('project_key="/test/project"');
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it("includes coordinator role reminder - NOT worker commands", async () => {
|
|
436
|
-
// Mock an in-progress epic with subtasks
|
|
437
|
-
mock.module("./hive", () => ({
|
|
438
|
-
getHiveWorkingDirectory: () => "/test/project",
|
|
439
|
-
getHiveAdapter: async () => ({
|
|
440
|
-
queryCells: async () => [
|
|
441
|
-
{
|
|
442
|
-
id: "bd-epic-123",
|
|
443
|
-
title: "Test Epic",
|
|
444
|
-
type: "epic",
|
|
445
|
-
status: "in_progress",
|
|
446
|
-
parent_id: null,
|
|
447
|
-
updated_at: Date.now(),
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
id: "bd-task-1",
|
|
451
|
-
type: "task",
|
|
452
|
-
status: "open",
|
|
453
|
-
parent_id: "bd-epic-123",
|
|
454
|
-
updated_at: Date.now(),
|
|
455
|
-
},
|
|
456
|
-
],
|
|
457
|
-
}),
|
|
458
|
-
}));
|
|
459
|
-
|
|
460
|
-
const hook = createCompactionHook();
|
|
461
|
-
const input = { sessionID: "test-session" };
|
|
462
|
-
const output = { context: [] as string[] };
|
|
463
|
-
|
|
464
|
-
await hook(input, output);
|
|
465
|
-
|
|
466
|
-
expect(output.context.length).toBeGreaterThan(0);
|
|
467
|
-
const injectedContext = output.context[0];
|
|
468
|
-
|
|
469
|
-
// Should remind coordinator of their ROLE
|
|
470
|
-
expect(injectedContext).toContain("YOU ARE THE COORDINATOR");
|
|
471
|
-
expect(injectedContext).toContain("Spawn workers");
|
|
472
|
-
|
|
473
|
-
// Should include coordinator commands
|
|
474
|
-
expect(injectedContext).toContain("swarm_spawn_subtask");
|
|
475
|
-
expect(injectedContext).toContain("swarm_review");
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
describe("Logging instrumentation", () => {
|
|
480
|
-
it("logs compaction start with session_id", async () => {
|
|
481
|
-
const hook = createCompactionHook();
|
|
482
|
-
const input = { sessionID: "test-session-123" };
|
|
483
|
-
const output = { context: [] as string[] };
|
|
484
|
-
|
|
485
|
-
await hook(input, output);
|
|
486
|
-
|
|
487
|
-
const startLog = logCalls.find(
|
|
488
|
-
(log) => log.level === "info" && log.message === "compaction started",
|
|
489
|
-
);
|
|
490
|
-
expect(startLog).toBeDefined();
|
|
491
|
-
expect(startLog?.data).toHaveProperty("session_id", "test-session-123");
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it("logs detection phase with confidence and reasons", async () => {
|
|
495
|
-
const hook = createCompactionHook();
|
|
496
|
-
const input = { sessionID: "test-session" };
|
|
497
|
-
const output = { context: [] as string[] };
|
|
498
|
-
|
|
499
|
-
await hook(input, output);
|
|
500
|
-
|
|
501
|
-
const detectionLog = logCalls.find(
|
|
502
|
-
(log) =>
|
|
503
|
-
log.level === "debug" && log.message === "swarm detection complete",
|
|
504
|
-
);
|
|
505
|
-
expect(detectionLog).toBeDefined();
|
|
506
|
-
expect(detectionLog?.data).toHaveProperty("confidence");
|
|
507
|
-
expect(detectionLog?.data).toHaveProperty("detected");
|
|
508
|
-
expect(detectionLog?.data).toHaveProperty("reason_count");
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it("logs context injection when swarm detected", async () => {
|
|
512
|
-
const hook = createCompactionHook();
|
|
513
|
-
const input = { sessionID: "test-session" };
|
|
514
|
-
const output = { context: [] as string[] };
|
|
515
|
-
|
|
516
|
-
// Mock detection to return medium confidence
|
|
517
|
-
mock.module("./hive", () => ({
|
|
518
|
-
getHiveWorkingDirectory: () => "/test/project",
|
|
519
|
-
getHiveAdapter: async () => ({
|
|
520
|
-
queryCells: async () => [
|
|
521
|
-
{
|
|
522
|
-
id: "bd-123",
|
|
523
|
-
type: "epic",
|
|
524
|
-
status: "open",
|
|
525
|
-
parent_id: null,
|
|
526
|
-
updated_at: Date.now(),
|
|
527
|
-
},
|
|
528
|
-
],
|
|
529
|
-
}),
|
|
530
|
-
}));
|
|
531
|
-
|
|
532
|
-
await hook(input, output);
|
|
533
|
-
|
|
534
|
-
const injectionLog = logCalls.find(
|
|
535
|
-
(log) =>
|
|
536
|
-
log.level === "info" && log.message === "injected swarm context",
|
|
537
|
-
);
|
|
538
|
-
expect(injectionLog).toBeDefined();
|
|
539
|
-
expect(injectionLog?.data).toHaveProperty("confidence");
|
|
540
|
-
expect(injectionLog?.data).toHaveProperty("context_length");
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
it("logs completion with duration and success", async () => {
|
|
544
|
-
const hook = createCompactionHook();
|
|
545
|
-
const input = { sessionID: "test-session" };
|
|
546
|
-
const output = { context: [] as string[] };
|
|
547
|
-
|
|
548
|
-
await hook(input, output);
|
|
549
|
-
|
|
550
|
-
const completeLog = logCalls.find(
|
|
551
|
-
(log) => log.level === "info" && log.message === "compaction complete",
|
|
552
|
-
);
|
|
553
|
-
expect(completeLog).toBeDefined();
|
|
554
|
-
expect(completeLog?.data).toHaveProperty("duration_ms");
|
|
555
|
-
expect(completeLog?.data.duration_ms).toBeGreaterThanOrEqual(0);
|
|
556
|
-
expect(completeLog?.data).toHaveProperty("success", true);
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
it("logs detailed detection sources (hive, swarm-mail)", async () => {
|
|
560
|
-
const hook = createCompactionHook();
|
|
561
|
-
const input = { sessionID: "test-session" };
|
|
562
|
-
const output = { context: [] as string[] };
|
|
563
|
-
|
|
564
|
-
await hook(input, output);
|
|
565
|
-
|
|
566
|
-
// Should log details about checking swarm-mail
|
|
567
|
-
const swarmMailLog = logCalls.find(
|
|
568
|
-
(log) => log.level === "debug" && log.message?.includes("swarm-mail"),
|
|
569
|
-
);
|
|
570
|
-
// Should log details about checking hive
|
|
571
|
-
const hiveLog = logCalls.find(
|
|
572
|
-
(log) => log.level === "debug" && log.message?.includes("hive"),
|
|
573
|
-
);
|
|
574
|
-
|
|
575
|
-
// At least one source should be checked
|
|
576
|
-
expect(logCalls.length).toBeGreaterThan(0);
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
it("logs errors without throwing when detection fails", async () => {
|
|
580
|
-
// Mock hive to throw
|
|
581
|
-
mock.module("./hive", () => ({
|
|
582
|
-
getHiveWorkingDirectory: () => {
|
|
583
|
-
throw new Error("Hive not available");
|
|
584
|
-
},
|
|
585
|
-
getHiveAdapter: async () => {
|
|
586
|
-
throw new Error("Hive not available");
|
|
587
|
-
},
|
|
588
|
-
}));
|
|
589
|
-
|
|
590
|
-
const hook = createCompactionHook();
|
|
591
|
-
const input = { sessionID: "test-session" };
|
|
592
|
-
const output = { context: [] as string[] };
|
|
593
|
-
|
|
594
|
-
// Should not throw
|
|
595
|
-
await expect(hook(input, output)).resolves.toBeUndefined();
|
|
596
|
-
|
|
597
|
-
// Should still complete successfully
|
|
598
|
-
const completeLog = logCalls.find(
|
|
599
|
-
(log) => log.level === "info" && log.message === "compaction complete",
|
|
600
|
-
);
|
|
601
|
-
expect(completeLog).toBeDefined();
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
it("includes context size when injecting", async () => {
|
|
605
|
-
const hook = createCompactionHook();
|
|
606
|
-
const input = { sessionID: "test-session" };
|
|
607
|
-
const output = { context: [] as string[] };
|
|
608
|
-
|
|
609
|
-
await hook(input, output);
|
|
610
|
-
|
|
611
|
-
// If context was injected, should log the size
|
|
612
|
-
if (output.context.length > 0) {
|
|
613
|
-
const injectionLog = logCalls.find(
|
|
614
|
-
(log) =>
|
|
615
|
-
log.level === "info" && log.message === "injected swarm context",
|
|
616
|
-
);
|
|
617
|
-
expect(injectionLog?.data.context_length).toBeGreaterThan(0);
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
describe("scanSessionMessages", () => {
|
|
623
|
-
it("returns empty state when client is undefined", async () => {
|
|
624
|
-
const state = await scanSessionMessages(undefined, "test-session");
|
|
625
|
-
expect(state.epicId).toBeUndefined();
|
|
626
|
-
expect(state.agentName).toBeUndefined();
|
|
627
|
-
expect(state.subtasks.size).toBe(0);
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
it("returns empty state when client is null", async () => {
|
|
631
|
-
const state = await scanSessionMessages(null, "test-session");
|
|
632
|
-
expect(state.epicId).toBeUndefined();
|
|
633
|
-
expect(state.subtasks.size).toBe(0);
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
it("extracts epic data from hive_create_epic tool call", async () => {
|
|
637
|
-
const mockClient = {
|
|
638
|
-
session: {
|
|
639
|
-
messages: async () => ({
|
|
640
|
-
data: [
|
|
641
|
-
{
|
|
642
|
-
info: { id: "msg-1", sessionID: "test-session" },
|
|
643
|
-
parts: [
|
|
644
|
-
{
|
|
645
|
-
type: "tool",
|
|
646
|
-
tool: "hive_create_epic",
|
|
647
|
-
state: {
|
|
648
|
-
status: "completed",
|
|
649
|
-
input: { epic_title: "Test Epic" },
|
|
650
|
-
output: JSON.stringify({ epic: { id: "epic-123" } }),
|
|
651
|
-
time: { start: 1000, end: 2000 },
|
|
652
|
-
},
|
|
653
|
-
},
|
|
654
|
-
],
|
|
655
|
-
},
|
|
656
|
-
],
|
|
657
|
-
}),
|
|
658
|
-
},
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
const state = await scanSessionMessages(mockClient, "test-session");
|
|
662
|
-
expect(state.epicId).toBe("epic-123");
|
|
663
|
-
expect(state.epicTitle).toBe("Test Epic");
|
|
664
|
-
});
|
|
665
|
-
|
|
666
|
-
it("extracts agent name from swarmmail_init tool call", async () => {
|
|
667
|
-
const mockClient = {
|
|
668
|
-
session: {
|
|
669
|
-
messages: async () => ({
|
|
670
|
-
data: [
|
|
671
|
-
{
|
|
672
|
-
info: { id: "msg-1", sessionID: "test-session" },
|
|
673
|
-
parts: [
|
|
674
|
-
{
|
|
675
|
-
type: "tool",
|
|
676
|
-
tool: "swarmmail_init",
|
|
677
|
-
state: {
|
|
678
|
-
status: "completed",
|
|
679
|
-
input: {},
|
|
680
|
-
output: JSON.stringify({
|
|
681
|
-
agent_name: "BlueLake",
|
|
682
|
-
project_key: "/test/project",
|
|
683
|
-
}),
|
|
684
|
-
time: { start: 1000, end: 2000 },
|
|
685
|
-
},
|
|
686
|
-
},
|
|
687
|
-
],
|
|
688
|
-
},
|
|
689
|
-
],
|
|
690
|
-
}),
|
|
691
|
-
},
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
const state = await scanSessionMessages(mockClient, "test-session");
|
|
695
|
-
expect(state.agentName).toBe("BlueLake");
|
|
696
|
-
expect(state.projectPath).toBe("/test/project");
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
it("tracks subtasks from swarm_spawn_subtask tool calls", async () => {
|
|
700
|
-
const mockClient = {
|
|
701
|
-
session: {
|
|
702
|
-
messages: async () => ({
|
|
703
|
-
data: [
|
|
704
|
-
{
|
|
705
|
-
info: { id: "msg-1", sessionID: "test-session" },
|
|
706
|
-
parts: [
|
|
707
|
-
{
|
|
708
|
-
type: "tool",
|
|
709
|
-
tool: "swarm_spawn_subtask",
|
|
710
|
-
state: {
|
|
711
|
-
status: "completed",
|
|
712
|
-
input: {
|
|
713
|
-
bead_id: "bd-123.1",
|
|
714
|
-
epic_id: "epic-123",
|
|
715
|
-
subtask_title: "Add auth",
|
|
716
|
-
files: ["src/auth.ts"],
|
|
717
|
-
},
|
|
718
|
-
output: JSON.stringify({ worker: "RedMountain" }),
|
|
719
|
-
time: { start: 1000, end: 2000 },
|
|
720
|
-
},
|
|
721
|
-
},
|
|
722
|
-
],
|
|
723
|
-
},
|
|
724
|
-
],
|
|
725
|
-
}),
|
|
726
|
-
},
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
const state = await scanSessionMessages(mockClient, "test-session");
|
|
730
|
-
expect(state.subtasks.size).toBe(1);
|
|
731
|
-
const subtask = state.subtasks.get("bd-123.1");
|
|
732
|
-
expect(subtask?.title).toBe("Add auth");
|
|
733
|
-
expect(subtask?.status).toBe("spawned");
|
|
734
|
-
expect(subtask?.worker).toBe("RedMountain");
|
|
735
|
-
expect(subtask?.files).toEqual(["src/auth.ts"]);
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
it("marks subtasks as completed from swarm_complete tool calls", async () => {
|
|
739
|
-
const mockClient = {
|
|
740
|
-
session: {
|
|
741
|
-
messages: async () => ({
|
|
742
|
-
data: [
|
|
743
|
-
{
|
|
744
|
-
info: { id: "msg-1", sessionID: "test-session" },
|
|
745
|
-
parts: [
|
|
746
|
-
{
|
|
747
|
-
type: "tool",
|
|
748
|
-
tool: "swarm_spawn_subtask",
|
|
749
|
-
state: {
|
|
750
|
-
status: "completed",
|
|
751
|
-
input: {
|
|
752
|
-
bead_id: "bd-123.1",
|
|
753
|
-
subtask_title: "Add auth",
|
|
754
|
-
},
|
|
755
|
-
output: "{}",
|
|
756
|
-
time: { start: 1000, end: 2000 },
|
|
757
|
-
},
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
type: "tool",
|
|
761
|
-
tool: "swarm_complete",
|
|
762
|
-
state: {
|
|
763
|
-
status: "completed",
|
|
764
|
-
input: { bead_id: "bd-123.1" },
|
|
765
|
-
output: "{}",
|
|
766
|
-
time: { start: 3000, end: 4000 },
|
|
767
|
-
},
|
|
768
|
-
},
|
|
769
|
-
],
|
|
770
|
-
},
|
|
771
|
-
],
|
|
772
|
-
}),
|
|
773
|
-
},
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
const state = await scanSessionMessages(mockClient, "test-session");
|
|
777
|
-
const subtask = state.subtasks.get("bd-123.1");
|
|
778
|
-
expect(subtask?.status).toBe("completed");
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
it("tracks last action", async () => {
|
|
782
|
-
const mockClient = {
|
|
783
|
-
session: {
|
|
784
|
-
messages: async () => ({
|
|
785
|
-
data: [
|
|
786
|
-
{
|
|
787
|
-
info: { id: "msg-1", sessionID: "test-session" },
|
|
788
|
-
parts: [
|
|
789
|
-
{
|
|
790
|
-
type: "tool",
|
|
791
|
-
tool: "swarm_status",
|
|
792
|
-
state: {
|
|
793
|
-
status: "completed",
|
|
794
|
-
input: { epic_id: "epic-123", project_key: "/test" },
|
|
795
|
-
output: "{}",
|
|
796
|
-
time: { start: 5000, end: 6000 },
|
|
797
|
-
},
|
|
798
|
-
},
|
|
799
|
-
],
|
|
800
|
-
},
|
|
801
|
-
],
|
|
802
|
-
}),
|
|
803
|
-
},
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
const state = await scanSessionMessages(mockClient, "test-session");
|
|
807
|
-
expect(state.lastAction?.tool).toBe("swarm_status");
|
|
808
|
-
expect(state.lastAction?.timestamp).toBe(6000);
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
it("handles SDK errors gracefully", async () => {
|
|
812
|
-
const mockClient = {
|
|
813
|
-
session: {
|
|
814
|
-
messages: async () => {
|
|
815
|
-
throw new Error("SDK error");
|
|
816
|
-
},
|
|
817
|
-
},
|
|
818
|
-
};
|
|
819
|
-
|
|
820
|
-
// Should not throw, just return empty state
|
|
821
|
-
const state = await scanSessionMessages(mockClient, "test-session");
|
|
822
|
-
expect(state.subtasks.size).toBe(0);
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
it("respects limit parameter", async () => {
|
|
826
|
-
const mockClient = {
|
|
827
|
-
session: {
|
|
828
|
-
messages: async (opts: { query?: { limit?: number } }) => {
|
|
829
|
-
expect(opts.query?.limit).toBe(50);
|
|
830
|
-
return { data: [] };
|
|
831
|
-
},
|
|
832
|
-
},
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
await scanSessionMessages(mockClient, "test-session", 50);
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
});
|