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,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swarm DurableDeferred Integration Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests cross-agent task completion signaling using DurableDeferred.
|
|
5
|
-
* Workers resolve a deferred when completing, coordinators await it.
|
|
6
|
-
*/
|
|
7
|
-
import { beforeAll, describe, expect, it } from "bun:test";
|
|
8
|
-
import { Effect, pipe } from "effect";
|
|
9
|
-
import type { DatabaseAdapter } from "../../swarm-mail/src/types/database";
|
|
10
|
-
import type { SwarmMailAdapter } from "../../swarm-mail/src/adapter";
|
|
11
|
-
import { createInMemorySwarmMailLibSQL } from "../../swarm-mail/src/libsql.convenience";
|
|
12
|
-
import { DurableDeferredLive } from "../../swarm-mail/src/streams/effect/deferred";
|
|
13
|
-
import { swarm_complete } from "./swarm-orchestrate";
|
|
14
|
-
|
|
15
|
-
describe("swarm_complete DurableDeferred integration", () => {
|
|
16
|
-
let swarmMail: SwarmMailAdapter;
|
|
17
|
-
let db: DatabaseAdapter;
|
|
18
|
-
let projectKey: string;
|
|
19
|
-
|
|
20
|
-
beforeAll(async () => {
|
|
21
|
-
// Use in-memory libSQL database
|
|
22
|
-
swarmMail = await createInMemorySwarmMailLibSQL("test-deferred-integration");
|
|
23
|
-
db = await swarmMail.getDatabase();
|
|
24
|
-
projectKey = "/tmp/test-deferred-integration";
|
|
25
|
-
|
|
26
|
-
// Register test agent using swarm-mail adapter
|
|
27
|
-
await swarmMail.registerAgent(projectKey, "TestWorker");
|
|
28
|
-
|
|
29
|
-
// Create test bead using swarm-mail Hive adapter
|
|
30
|
-
await swarmMail.createCell(projectKey, {
|
|
31
|
-
title: "Test Task",
|
|
32
|
-
type: "task",
|
|
33
|
-
priority: 2,
|
|
34
|
-
status: "in_progress",
|
|
35
|
-
id: "test-bead-123",
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should resolve deferred when swarm_complete is called", async () => {
|
|
40
|
-
const beadId = "test-bead-123";
|
|
41
|
-
|
|
42
|
-
// First create deferred (coordinator side)
|
|
43
|
-
const createProgram = Effect.gen(function* () {
|
|
44
|
-
const DurableDeferred = yield* Effect.serviceOption(DurableDeferredLive);
|
|
45
|
-
expect(DurableDeferred._tag).toBe("Some");
|
|
46
|
-
|
|
47
|
-
if (DurableDeferred._tag !== "Some") {
|
|
48
|
-
throw new Error("DurableDeferred service not available");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const service = DurableDeferred.value;
|
|
52
|
-
|
|
53
|
-
// Create deferred keyed by bead_id
|
|
54
|
-
const handle = yield* service.create({
|
|
55
|
-
ttlSeconds: 60,
|
|
56
|
-
db,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
expect(handle.url).toMatch(/^deferred:/);
|
|
60
|
-
|
|
61
|
-
return handle.url;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const deferredUrl = await Effect.runPromise(
|
|
65
|
-
pipe(createProgram, Effect.provide(DurableDeferredLive))
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// Worker completes the task (this should resolve the deferred)
|
|
69
|
-
const mockContext = {
|
|
70
|
-
sessionID: "test-session",
|
|
71
|
-
messageID: "test-message",
|
|
72
|
-
agent: "test-agent",
|
|
73
|
-
abort: new AbortController().signal,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const completeResult = await swarm_complete.execute(
|
|
77
|
-
{
|
|
78
|
-
project_key: projectKey,
|
|
79
|
-
agent_name: "TestWorker",
|
|
80
|
-
bead_id: beadId,
|
|
81
|
-
summary: "Task completed successfully",
|
|
82
|
-
skip_verification: true, // Skip UBS/typecheck for test
|
|
83
|
-
},
|
|
84
|
-
mockContext
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const parsed = JSON.parse(completeResult);
|
|
88
|
-
expect(parsed.success).toBe(true);
|
|
89
|
-
|
|
90
|
-
// TODO: Resolve the deferred in swarm_complete implementation
|
|
91
|
-
// For now, manually resolve to verify await works
|
|
92
|
-
const resolveProgram = Effect.gen(function* () {
|
|
93
|
-
const DurableDeferred = yield* Effect.serviceOption(DurableDeferredLive);
|
|
94
|
-
if (DurableDeferred._tag !== "Some") {
|
|
95
|
-
throw new Error("DurableDeferred service not available");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const service = DurableDeferred.value;
|
|
99
|
-
yield* service.resolve(deferredUrl, { completed: true }, db);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
await Effect.runPromise(
|
|
103
|
-
pipe(resolveProgram, Effect.provide(DurableDeferredLive))
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Coordinator awaits completion
|
|
107
|
-
const awaitProgram = Effect.gen(function* () {
|
|
108
|
-
const DurableDeferred = yield* Effect.serviceOption(DurableDeferredLive);
|
|
109
|
-
if (DurableDeferred._tag !== "Some") {
|
|
110
|
-
throw new Error("DurableDeferred service not available");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const service = DurableDeferred.value;
|
|
114
|
-
const result = yield* service.await(deferredUrl, 60, db);
|
|
115
|
-
|
|
116
|
-
expect(result).toEqual({ completed: true });
|
|
117
|
-
return result;
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const result = await Effect.runPromise(
|
|
121
|
-
pipe(awaitProgram, Effect.provide(DurableDeferredLive))
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expect(result).toEqual({ completed: true });
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should timeout if deferred is never resolved", async () => {
|
|
128
|
-
const program = Effect.gen(function* () {
|
|
129
|
-
const DurableDeferred = yield* Effect.serviceOption(DurableDeferredLive);
|
|
130
|
-
expect(DurableDeferred._tag).toBe("Some");
|
|
131
|
-
|
|
132
|
-
if (DurableDeferred._tag !== "Some") {
|
|
133
|
-
throw new Error("DurableDeferred service not available");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const service = DurableDeferred.value;
|
|
137
|
-
|
|
138
|
-
// Create deferred with short timeout
|
|
139
|
-
const handle = yield* service.create({
|
|
140
|
-
ttlSeconds: 1,
|
|
141
|
-
db,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Don't resolve it - just await
|
|
145
|
-
const result = yield* handle.value;
|
|
146
|
-
|
|
147
|
-
return result;
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// Should timeout and throw TimeoutError
|
|
151
|
-
await expect(
|
|
152
|
-
Effect.runPromise(
|
|
153
|
-
pipe(program, Effect.provide(DurableDeferredLive))
|
|
154
|
-
)
|
|
155
|
-
).rejects.toThrow(/timed out/);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swarm DurableDeferred Unit Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests that swarm_complete resolves a deferred for cross-agent signaling.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, expect, it } from "bun:test";
|
|
7
|
-
|
|
8
|
-
describe("swarm_complete DurableDeferred integration", () => {
|
|
9
|
-
it("should add deferred_resolved to response when deferred exists", () => {
|
|
10
|
-
// This is a regression test - ensures the new fields are in the response
|
|
11
|
-
// The actual database integration is tested in swarm-deferred.integration.test.ts
|
|
12
|
-
|
|
13
|
-
const mockResponse = {
|
|
14
|
-
success: true,
|
|
15
|
-
bead_id: "test-bead-123",
|
|
16
|
-
closed: true,
|
|
17
|
-
reservations_released: true,
|
|
18
|
-
deferred_resolved: true, // NEW FIELD
|
|
19
|
-
deferred_error: undefined, // NEW FIELD
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
expect(mockResponse.deferred_resolved).toBe(true);
|
|
23
|
-
expect(mockResponse).toHaveProperty("deferred_error");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should handle deferred_error when resolution fails", () => {
|
|
27
|
-
const mockResponse = {
|
|
28
|
-
success: true,
|
|
29
|
-
bead_id: "test-bead-123",
|
|
30
|
-
closed: true,
|
|
31
|
-
deferred_resolved: false,
|
|
32
|
-
deferred_error: "Database not available",
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
expect(mockResponse.deferred_resolved).toBe(false);
|
|
36
|
-
expect(mockResponse.deferred_error).toBe("Database not available");
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swarm Insights Data Layer Tests
|
|
3
|
-
*
|
|
4
|
-
* TDD: Red → Green → Refactor
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
8
|
-
import {
|
|
9
|
-
getStrategyInsights,
|
|
10
|
-
getFileInsights,
|
|
11
|
-
getPatternInsights,
|
|
12
|
-
formatInsightsForPrompt,
|
|
13
|
-
type StrategyInsight,
|
|
14
|
-
type FileInsight,
|
|
15
|
-
type PatternInsight,
|
|
16
|
-
} from "./swarm-insights";
|
|
17
|
-
import { createInMemorySwarmMail, type SwarmMailAdapter } from "swarm-mail";
|
|
18
|
-
|
|
19
|
-
describe("swarm-insights data layer", () => {
|
|
20
|
-
let swarmMail: SwarmMailAdapter;
|
|
21
|
-
|
|
22
|
-
beforeAll(async () => {
|
|
23
|
-
swarmMail = await createInMemorySwarmMail("test-insights");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterAll(async () => {
|
|
27
|
-
await swarmMail.close();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("getStrategyInsights", () => {
|
|
31
|
-
test("returns empty array when no data", async () => {
|
|
32
|
-
const insights = await getStrategyInsights(swarmMail, "test-task");
|
|
33
|
-
expect(insights).toEqual([]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test("returns strategy success rates from outcomes", async () => {
|
|
37
|
-
// Seed some outcome events (id is auto-increment, timestamp is integer)
|
|
38
|
-
const db = await swarmMail.getDatabase();
|
|
39
|
-
const now = Date.now();
|
|
40
|
-
await db.query(
|
|
41
|
-
`INSERT INTO events (type, project_key, timestamp, data) VALUES
|
|
42
|
-
('subtask_outcome', 'test', ?, ?),
|
|
43
|
-
('subtask_outcome', 'test', ?, ?),
|
|
44
|
-
('subtask_outcome', 'test', ?, ?)`,
|
|
45
|
-
[
|
|
46
|
-
now,
|
|
47
|
-
JSON.stringify({ strategy: "file-based", success: "true" }),
|
|
48
|
-
now,
|
|
49
|
-
JSON.stringify({ strategy: "file-based", success: "true" }),
|
|
50
|
-
now,
|
|
51
|
-
JSON.stringify({ strategy: "file-based", success: "false" }),
|
|
52
|
-
],
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const insights = await getStrategyInsights(swarmMail, "test-task");
|
|
56
|
-
|
|
57
|
-
expect(insights.length).toBeGreaterThan(0);
|
|
58
|
-
const fileBased = insights.find((i) => i.strategy === "file-based");
|
|
59
|
-
expect(fileBased).toBeDefined();
|
|
60
|
-
expect(fileBased?.successRate).toBeCloseTo(66.67, 0);
|
|
61
|
-
expect(fileBased?.totalAttempts).toBe(3);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("includes recommendation based on success rate", async () => {
|
|
65
|
-
const insights = await getStrategyInsights(swarmMail, "test-task");
|
|
66
|
-
const fileBased = insights.find((i) => i.strategy === "file-based");
|
|
67
|
-
|
|
68
|
-
expect(fileBased?.recommendation).toBeDefined();
|
|
69
|
-
expect(typeof fileBased?.recommendation).toBe("string");
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("getFileInsights", () => {
|
|
74
|
-
test("returns empty array for unknown files", async () => {
|
|
75
|
-
const insights = await getFileInsights(swarmMail, [
|
|
76
|
-
"src/unknown-file.ts",
|
|
77
|
-
]);
|
|
78
|
-
expect(insights).toEqual([]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("returns past issues for known files", async () => {
|
|
82
|
-
// Seed some file-related events (id is auto-increment, timestamp is integer)
|
|
83
|
-
const db = await swarmMail.getDatabase();
|
|
84
|
-
const now = Date.now();
|
|
85
|
-
await db.query(
|
|
86
|
-
`INSERT INTO events (type, project_key, timestamp, data) VALUES
|
|
87
|
-
('subtask_outcome', 'test', ?, ?)`,
|
|
88
|
-
[
|
|
89
|
-
now,
|
|
90
|
-
JSON.stringify({
|
|
91
|
-
files_touched: ["src/auth.ts"],
|
|
92
|
-
success: "false",
|
|
93
|
-
error_count: 2,
|
|
94
|
-
}),
|
|
95
|
-
],
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const insights = await getFileInsights(swarmMail, ["src/auth.ts"]);
|
|
99
|
-
|
|
100
|
-
expect(insights.length).toBeGreaterThan(0);
|
|
101
|
-
const authInsight = insights.find((i) => i.file === "src/auth.ts");
|
|
102
|
-
expect(authInsight).toBeDefined();
|
|
103
|
-
expect(authInsight?.failureCount).toBeGreaterThan(0);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test("includes gotchas from semantic memory", async () => {
|
|
107
|
-
// This would query semantic memory for file-specific learnings
|
|
108
|
-
const insights = await getFileInsights(swarmMail, ["src/auth.ts"]);
|
|
109
|
-
|
|
110
|
-
// Even if no gotchas, the structure should be correct
|
|
111
|
-
const authInsight = insights.find((i) => i.file === "src/auth.ts");
|
|
112
|
-
expect(authInsight?.gotchas).toBeDefined();
|
|
113
|
-
expect(Array.isArray(authInsight?.gotchas)).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe("getPatternInsights", () => {
|
|
118
|
-
test("returns common failure patterns", async () => {
|
|
119
|
-
const insights = await getPatternInsights(swarmMail);
|
|
120
|
-
|
|
121
|
-
expect(Array.isArray(insights)).toBe(true);
|
|
122
|
-
// Structure check
|
|
123
|
-
if (insights.length > 0) {
|
|
124
|
-
expect(insights[0]).toHaveProperty("pattern");
|
|
125
|
-
expect(insights[0]).toHaveProperty("frequency");
|
|
126
|
-
expect(insights[0]).toHaveProperty("recommendation");
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("includes anti-patterns from learning system", async () => {
|
|
131
|
-
const insights = await getPatternInsights(swarmMail);
|
|
132
|
-
|
|
133
|
-
// Should include anti-patterns if any exist
|
|
134
|
-
expect(Array.isArray(insights)).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe("formatInsightsForPrompt", () => {
|
|
139
|
-
test("formats strategy insights concisely", () => {
|
|
140
|
-
const strategies: StrategyInsight[] = [
|
|
141
|
-
{
|
|
142
|
-
strategy: "file-based",
|
|
143
|
-
successRate: 85,
|
|
144
|
-
totalAttempts: 20,
|
|
145
|
-
recommendation: "Preferred for this project",
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
strategy: "feature-based",
|
|
149
|
-
successRate: 60,
|
|
150
|
-
totalAttempts: 10,
|
|
151
|
-
recommendation: "Use with caution",
|
|
152
|
-
},
|
|
153
|
-
];
|
|
154
|
-
|
|
155
|
-
const formatted = formatInsightsForPrompt({ strategies });
|
|
156
|
-
|
|
157
|
-
expect(formatted).toContain("file-based");
|
|
158
|
-
expect(formatted).toContain("85%");
|
|
159
|
-
expect(formatted.length).toBeLessThan(500); // Context-efficient
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test("formats file insights concisely", () => {
|
|
163
|
-
const files: FileInsight[] = [
|
|
164
|
-
{
|
|
165
|
-
file: "src/auth.ts",
|
|
166
|
-
failureCount: 3,
|
|
167
|
-
lastFailure: "2025-12-25",
|
|
168
|
-
gotchas: ["Watch for race conditions in token refresh"],
|
|
169
|
-
},
|
|
170
|
-
];
|
|
171
|
-
|
|
172
|
-
const formatted = formatInsightsForPrompt({ files });
|
|
173
|
-
|
|
174
|
-
expect(formatted).toContain("src/auth.ts");
|
|
175
|
-
expect(formatted).toContain("race conditions");
|
|
176
|
-
expect(formatted.length).toBeLessThan(300); // Per-file budget
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("formats pattern insights concisely", () => {
|
|
180
|
-
const patterns: PatternInsight[] = [
|
|
181
|
-
{
|
|
182
|
-
pattern: "Missing error handling",
|
|
183
|
-
frequency: 5,
|
|
184
|
-
recommendation: "Add try/catch around async operations",
|
|
185
|
-
},
|
|
186
|
-
];
|
|
187
|
-
|
|
188
|
-
const formatted = formatInsightsForPrompt({ patterns });
|
|
189
|
-
|
|
190
|
-
expect(formatted).toContain("Missing error handling");
|
|
191
|
-
expect(formatted).toContain("try/catch");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test("respects token budget", () => {
|
|
195
|
-
// Create many insights
|
|
196
|
-
const strategies: StrategyInsight[] = Array.from({ length: 10 }, (_, i) => ({
|
|
197
|
-
strategy: `strategy-${i}`,
|
|
198
|
-
successRate: 50 + i * 5,
|
|
199
|
-
totalAttempts: 10,
|
|
200
|
-
recommendation: `Recommendation for strategy ${i}`,
|
|
201
|
-
}));
|
|
202
|
-
|
|
203
|
-
const formatted = formatInsightsForPrompt({ strategies }, { maxTokens: 200 });
|
|
204
|
-
|
|
205
|
-
// Should truncate to fit budget
|
|
206
|
-
expect(formatted.length).toBeLessThan(1000); // ~200 tokens ≈ 800 chars
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
test("returns empty string when no insights", () => {
|
|
210
|
-
const formatted = formatInsightsForPrompt({});
|
|
211
|
-
expect(formatted).toBe("");
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
});
|