opencode-swarm-plugin 0.21.0 → 0.23.0
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/.turbo/turbo-build.log +9 -0
- package/CHANGELOG.md +12 -0
- package/README.md +111 -166
- package/dist/agent-mail.d.ts +480 -0
- package/dist/agent-mail.d.ts.map +1 -0
- package/dist/anti-patterns.d.ts +257 -0
- package/dist/anti-patterns.d.ts.map +1 -0
- package/dist/beads.d.ts +377 -0
- package/dist/beads.d.ts.map +1 -0
- package/dist/eval-capture.d.ts +206 -0
- package/dist/eval-capture.d.ts.map +1 -0
- package/dist/index.d.ts +1299 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +776 -4387
- package/dist/learning.d.ts +670 -0
- package/dist/learning.d.ts.map +1 -0
- package/dist/mandate-promotion.d.ts +93 -0
- package/dist/mandate-promotion.d.ts.map +1 -0
- package/dist/mandate-storage.d.ts +209 -0
- package/dist/mandate-storage.d.ts.map +1 -0
- package/dist/mandates.d.ts +230 -0
- package/dist/mandates.d.ts.map +1 -0
- package/dist/output-guardrails.d.ts +125 -0
- package/dist/output-guardrails.d.ts.map +1 -0
- package/dist/pattern-maturity.d.ts +246 -0
- package/dist/pattern-maturity.d.ts.map +1 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +755 -4375
- package/dist/rate-limiter.d.ts +218 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/repo-crawl.d.ts +146 -0
- package/dist/repo-crawl.d.ts.map +1 -0
- package/dist/schemas/bead.d.ts +255 -0
- package/dist/schemas/bead.d.ts.map +1 -0
- package/dist/schemas/evaluation.d.ts +161 -0
- package/dist/schemas/evaluation.d.ts.map +1 -0
- package/dist/schemas/index.d.ts +34 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/mandate.d.ts +336 -0
- package/dist/schemas/mandate.d.ts.map +1 -0
- package/dist/schemas/swarm-context.d.ts +131 -0
- package/dist/schemas/swarm-context.d.ts.map +1 -0
- package/dist/schemas/task.d.ts +188 -0
- package/dist/schemas/task.d.ts.map +1 -0
- package/dist/skills.d.ts +471 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/storage.d.ts +260 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/structured.d.ts +196 -0
- package/dist/structured.d.ts.map +1 -0
- package/dist/swarm-decompose.d.ts +201 -0
- package/dist/swarm-decompose.d.ts.map +1 -0
- package/dist/swarm-mail.d.ts +240 -0
- package/dist/swarm-mail.d.ts.map +1 -0
- package/dist/swarm-orchestrate.d.ts +708 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -0
- package/dist/swarm-prompts.d.ts +292 -0
- package/dist/swarm-prompts.d.ts.map +1 -0
- package/dist/swarm-strategies.d.ts +100 -0
- package/dist/swarm-strategies.d.ts.map +1 -0
- package/dist/swarm.d.ts +455 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/tool-availability.d.ts +91 -0
- package/dist/tool-availability.d.ts.map +1 -0
- package/docs/planning/ADR-001-monorepo-structure.md +171 -0
- package/docs/planning/ADR-002-package-extraction.md +393 -0
- package/docs/planning/ADR-003-performance-improvements.md +451 -0
- package/docs/planning/ADR-004-message-queue-features.md +187 -0
- package/docs/planning/ADR-005-devtools-observability.md +202 -0
- package/docs/planning/ROADMAP.md +368 -0
- package/docs/semantic-memory-cli-syntax.md +123 -0
- package/docs/swarm-mail-architecture.md +1147 -0
- package/package.json +13 -24
- package/scripts/cleanup-test-memories.ts +346 -0
- package/src/agent-mail.ts +1 -1
- package/src/beads.ts +1 -2
- package/src/index.ts +2 -2
- package/src/learning.integration.test.ts +80 -10
- package/src/mandate-storage.test.ts +3 -3
- package/src/storage.ts +189 -9
- package/src/swarm-mail.ts +3 -3
- package/src/swarm-orchestrate.ts +399 -246
- package/src/swarm.integration.test.ts +124 -0
- package/src/tool-availability.ts +1 -1
- package/tsconfig.json +1 -1
- package/.beads/.local_version +0 -1
- package/.beads/README.md +0 -81
- package/.beads/analysis/skill-architecture-meta-skills.md +0 -1562
- package/.beads/config.yaml +0 -62
- package/.beads/issues.jsonl +0 -2186
- package/.beads/metadata.json +0 -4
- package/.gitattributes +0 -3
- package/.github/workflows/ci.yml +0 -30
- package/.github/workflows/opencode.yml +0 -31
- package/.opencode/skills/tdd/SKILL.md +0 -182
- package/INTEGRATION_EXAMPLE.md +0 -66
- package/VERIFICATION_QUALITY_PATTERNS.md +0 -565
- package/bun.lock +0 -286
- package/dist/pglite.data +0 -0
- package/dist/pglite.wasm +0 -0
- package/src/streams/agent-mail.test.ts +0 -777
- package/src/streams/agent-mail.ts +0 -535
- package/src/streams/debug.test.ts +0 -500
- package/src/streams/debug.ts +0 -727
- package/src/streams/effect/ask.integration.test.ts +0 -314
- package/src/streams/effect/ask.ts +0 -202
- package/src/streams/effect/cursor.integration.test.ts +0 -418
- package/src/streams/effect/cursor.ts +0 -288
- package/src/streams/effect/deferred.test.ts +0 -357
- package/src/streams/effect/deferred.ts +0 -445
- package/src/streams/effect/index.ts +0 -17
- package/src/streams/effect/layers.ts +0 -73
- package/src/streams/effect/lock.test.ts +0 -385
- package/src/streams/effect/lock.ts +0 -399
- package/src/streams/effect/mailbox.test.ts +0 -260
- package/src/streams/effect/mailbox.ts +0 -318
- package/src/streams/events.test.ts +0 -924
- package/src/streams/events.ts +0 -329
- package/src/streams/index.test.ts +0 -229
- package/src/streams/index.ts +0 -578
- package/src/streams/migrations.test.ts +0 -359
- package/src/streams/migrations.ts +0 -362
- package/src/streams/projections.test.ts +0 -611
- package/src/streams/projections.ts +0 -504
- package/src/streams/store.integration.test.ts +0 -658
- package/src/streams/store.ts +0 -1075
- package/src/streams/swarm-mail.ts +0 -552
- package/test-bug-fixes.ts +0 -86
- package/vitest.integration.config.ts +0 -13
- package/workflow-integration-analysis.md +0 -876
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-swarm-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Multi-agent swarm coordination for OpenCode with learning capabilities, beads integration, and Agent Mail",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
9
|
"swarm": "./bin/swarm.ts"
|
|
10
10
|
},
|
|
@@ -14,37 +14,25 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts"
|
|
15
15
|
},
|
|
16
16
|
"./plugin": {
|
|
17
|
-
"import": "./dist/plugin.js"
|
|
17
|
+
"import": "./dist/plugin.js",
|
|
18
|
+
"types": "./dist/plugin.d.ts"
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
|
-
"build": "bun build ./src/index.ts --outdir ./dist --target node --external @electric-sql/pglite && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target node --external @electric-sql/pglite",
|
|
22
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --external @electric-sql/pglite --external swarm-mail && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target node --external @electric-sql/pglite --external swarm-mail && tsc",
|
|
22
23
|
"dev": "bun --watch src/index.ts",
|
|
23
|
-
"test": "bun test
|
|
24
|
-
"test:
|
|
25
|
-
"test:
|
|
26
|
-
"test:
|
|
27
|
-
"test:all": "bun run test && bun run test:swarm",
|
|
24
|
+
"test": "bun test --timeout 10000 src/anti-patterns.test.ts src/mandate-promotion.test.ts src/mandate-storage.test.ts src/output-guardrails.test.ts src/pattern-maturity.test.ts src/skills.test.ts src/structured.test.ts src/schemas/",
|
|
25
|
+
"test:integration": "bun test --timeout 60000 src/*.integration.test.ts",
|
|
26
|
+
"test:all": "bun test --timeout 60000 src/",
|
|
27
|
+
"test:watch": "bun test --watch src/",
|
|
28
28
|
"typecheck": "tsc --noEmit",
|
|
29
|
-
"
|
|
30
|
-
"eval:dev": "evalite watch evals/",
|
|
31
|
-
"eval:run": "evalite run evals/",
|
|
32
|
-
"eval:ci": "evalite run evals/ --threshold 80",
|
|
33
|
-
"release": "npm run build && npm version patch && git push && npm run publish:otp",
|
|
34
|
-
"release:minor": "npm run build && npm version minor && git push && npm run publish:otp",
|
|
35
|
-
"release:major": "npm run build && npm version major && git push && npm run publish:otp",
|
|
36
|
-
"publish:otp": "bash -c 'source .env && npm publish --otp=$(op item get $NPM_1P_ITEM --otp)'"
|
|
29
|
+
"publish:pkg": "npm publish --access public --provenance"
|
|
37
30
|
},
|
|
38
31
|
"dependencies": {
|
|
39
|
-
"@clack/prompts": "^0.11.0",
|
|
40
|
-
"@effect/schema": "^0.75.5",
|
|
41
|
-
"@electric-sql/pglite": "0.3.14",
|
|
42
32
|
"@opencode-ai/plugin": "^1.0.134",
|
|
43
|
-
"effect": "^3.19.12",
|
|
44
33
|
"gray-matter": "^4.0.3",
|
|
45
34
|
"ioredis": "^5.4.1",
|
|
46
|
-
"
|
|
47
|
-
"nanoid": "^5.1.6",
|
|
35
|
+
"swarm-mail": "workspace:*",
|
|
48
36
|
"zod": "4.1.8"
|
|
49
37
|
},
|
|
50
38
|
"devDependencies": {
|
|
@@ -53,6 +41,7 @@
|
|
|
53
41
|
"ai": "6.0.0-beta.150",
|
|
54
42
|
"bun-types": "^1.3.4",
|
|
55
43
|
"evalite": "^1.0.0-beta.10",
|
|
44
|
+
"turbo": "^2.6.3",
|
|
56
45
|
"typescript": "^5.7.0",
|
|
57
46
|
"vitest": "^4.0.15"
|
|
58
47
|
},
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Semantic Memory Test Pollution Cleanup
|
|
4
|
+
*
|
|
5
|
+
* This script audits and documents test pollution in semantic-memory storage.
|
|
6
|
+
* Test artifacts from integration tests pollute the production knowledge base,
|
|
7
|
+
* making semantic search unreliable and wasting storage.
|
|
8
|
+
*
|
|
9
|
+
* ROOT CAUSE:
|
|
10
|
+
* - Integration tests write to shared semantic-memory MCP server
|
|
11
|
+
* - No isolation between test and production collections
|
|
12
|
+
* - Tests don't clean up after themselves
|
|
13
|
+
* - No in-memory test mode available
|
|
14
|
+
*
|
|
15
|
+
* PREVENTION STRATEGY:
|
|
16
|
+
* 1. Test isolation via collection prefixes (test-*, temp-*)
|
|
17
|
+
* 2. Cleanup hooks in test teardown
|
|
18
|
+
* 3. Mock semantic-memory in unit tests
|
|
19
|
+
* 4. Document production collection names
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* bun scripts/cleanup-test-memories.ts [--dry-run] [--collections <prefix>]
|
|
23
|
+
*
|
|
24
|
+
* Examples:
|
|
25
|
+
* bun scripts/cleanup-test-memories.ts --dry-run
|
|
26
|
+
* bun scripts/cleanup-test-memories.ts --collections test-patterns,test-feedback
|
|
27
|
+
* bun scripts/cleanup-test-memories.ts
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { parseArgs } from "node:util";
|
|
31
|
+
|
|
32
|
+
/** Test collection patterns to identify pollution */
|
|
33
|
+
const TEST_COLLECTION_PATTERNS = [
|
|
34
|
+
"test-patterns",
|
|
35
|
+
"test-feedback",
|
|
36
|
+
/^test-.*/,
|
|
37
|
+
/^temp-.*/,
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
40
|
+
interface Memory {
|
|
41
|
+
id: string;
|
|
42
|
+
collection: string;
|
|
43
|
+
content: string;
|
|
44
|
+
metadata?: string;
|
|
45
|
+
created_at?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface AuditReport {
|
|
49
|
+
total_memories: number;
|
|
50
|
+
test_artifacts: Memory[];
|
|
51
|
+
production_memories: Memory[];
|
|
52
|
+
collections: {
|
|
53
|
+
name: string;
|
|
54
|
+
count: number;
|
|
55
|
+
is_test: boolean;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Check if a collection name matches test patterns
|
|
61
|
+
*/
|
|
62
|
+
function isTestCollection(collection: string): boolean {
|
|
63
|
+
return TEST_COLLECTION_PATTERNS.some((pattern) => {
|
|
64
|
+
if (typeof pattern === "string") {
|
|
65
|
+
return collection === pattern;
|
|
66
|
+
}
|
|
67
|
+
return pattern.test(collection);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Parse semantic-memory_list output into structured data
|
|
73
|
+
*
|
|
74
|
+
* Output format is like:
|
|
75
|
+
* ```
|
|
76
|
+
* • 32577e43... (test-patterns)
|
|
77
|
+
* {"id":"pattern-1765749526038-65vu4n","content":"Test pattern...
|
|
78
|
+
* • 825ccc37... (test-feedback)
|
|
79
|
+
* {"id":"test-1765749524072-fs3i37vpoik","criterion":"type_safe"...
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
function parseMemoryList(output: string): Memory[] {
|
|
83
|
+
const memories: Memory[] = [];
|
|
84
|
+
const lines = output.split("\n");
|
|
85
|
+
|
|
86
|
+
let currentMemory: Partial<Memory> | null = null;
|
|
87
|
+
|
|
88
|
+
for (const line of lines) {
|
|
89
|
+
// Match memory header: • 32577e43... (collection-name)
|
|
90
|
+
const headerMatch = line.match(/^•\s+([a-f0-9]+)\.\.\.\s+\(([^)]+)\)/);
|
|
91
|
+
if (headerMatch) {
|
|
92
|
+
if (currentMemory) {
|
|
93
|
+
memories.push(currentMemory as Memory);
|
|
94
|
+
}
|
|
95
|
+
currentMemory = {
|
|
96
|
+
id: headerMatch[1],
|
|
97
|
+
collection: headerMatch[2],
|
|
98
|
+
content: "",
|
|
99
|
+
};
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Match content line (indented JSON or text)
|
|
104
|
+
if (currentMemory && line.trim()) {
|
|
105
|
+
currentMemory.content = (
|
|
106
|
+
currentMemory.content +
|
|
107
|
+
" " +
|
|
108
|
+
line.trim()
|
|
109
|
+
).trim();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (currentMemory) {
|
|
114
|
+
memories.push(currentMemory as Memory);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return memories;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Audit semantic-memory for test pollution
|
|
122
|
+
*
|
|
123
|
+
* NOTE: This is a documentation-only script since semantic-memory MCP
|
|
124
|
+
* does not expose delete/remove APIs. The actual cleanup must be done
|
|
125
|
+
* manually via PostgreSQL.
|
|
126
|
+
*/
|
|
127
|
+
async function auditMemories(): Promise<AuditReport> {
|
|
128
|
+
console.log("🔍 Auditing semantic-memory for test pollution...\n");
|
|
129
|
+
console.log(
|
|
130
|
+
"⚠️ NOTE: semantic-memory_list is an MCP tool that must be called",
|
|
131
|
+
);
|
|
132
|
+
console.log(" by the AI agent, not from this script.\n");
|
|
133
|
+
console.log("Based on manual inspection, here's the pollution summary:\n");
|
|
134
|
+
|
|
135
|
+
// Simulated data based on actual semantic-memory_list output
|
|
136
|
+
const knownTestCollections = {
|
|
137
|
+
"test-patterns": 16,
|
|
138
|
+
"test-feedback": 16,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const knownProductionCollections = {
|
|
142
|
+
default: 5, // egghead-rails, POC migration, Docker, Durable Streams, one test
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const totalTest = Object.values(knownTestCollections).reduce(
|
|
146
|
+
(a, b) => a + b,
|
|
147
|
+
0,
|
|
148
|
+
);
|
|
149
|
+
const totalProd = Object.values(knownProductionCollections).reduce(
|
|
150
|
+
(a, b) => a + b,
|
|
151
|
+
0,
|
|
152
|
+
);
|
|
153
|
+
const totalMemories = totalTest + totalProd;
|
|
154
|
+
|
|
155
|
+
// Build collections array
|
|
156
|
+
const collections = [
|
|
157
|
+
...Object.entries(knownTestCollections).map(([name, count]) => ({
|
|
158
|
+
name,
|
|
159
|
+
count,
|
|
160
|
+
is_test: true,
|
|
161
|
+
})),
|
|
162
|
+
...Object.entries(knownProductionCollections).map(([name, count]) => ({
|
|
163
|
+
name,
|
|
164
|
+
count,
|
|
165
|
+
is_test: false,
|
|
166
|
+
})),
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
// Simulate test artifacts for reporting
|
|
170
|
+
const testArtifacts = Array.from({ length: totalTest }, (_, i) => ({
|
|
171
|
+
id: `test-${i}`,
|
|
172
|
+
collection: i < 16 ? "test-patterns" : "test-feedback",
|
|
173
|
+
content: "Test artifact",
|
|
174
|
+
}));
|
|
175
|
+
|
|
176
|
+
const productionMemories = Array.from({ length: totalProd }, (_, i) => ({
|
|
177
|
+
id: `prod-${i}`,
|
|
178
|
+
collection: "default",
|
|
179
|
+
content: "Production memory",
|
|
180
|
+
}));
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
total_memories: totalMemories,
|
|
184
|
+
test_artifacts: testArtifacts,
|
|
185
|
+
production_memories: productionMemories,
|
|
186
|
+
collections,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Generate cleanup report
|
|
192
|
+
*/
|
|
193
|
+
function generateReport(report: AuditReport, dryRun: boolean): void {
|
|
194
|
+
console.log("📊 SEMANTIC MEMORY AUDIT REPORT");
|
|
195
|
+
console.log("================================\n");
|
|
196
|
+
|
|
197
|
+
console.log(`Total memories: ${report.total_memories}`);
|
|
198
|
+
console.log(
|
|
199
|
+
`Test artifacts: ${report.test_artifacts.length} (${Math.round((report.test_artifacts.length / report.total_memories) * 100)}%)`,
|
|
200
|
+
);
|
|
201
|
+
console.log(`Production memories: ${report.production_memories.length}\n`);
|
|
202
|
+
|
|
203
|
+
console.log("Collections breakdown:");
|
|
204
|
+
console.log("----------------------");
|
|
205
|
+
for (const col of report.collections) {
|
|
206
|
+
const marker = col.is_test ? "🚨 TEST" : "✅ PROD";
|
|
207
|
+
console.log(` ${marker} ${col.name.padEnd(20)} ${col.count} memories`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
console.log("\n⚠️ CLEANUP REQUIRED\n");
|
|
211
|
+
|
|
212
|
+
if (report.test_artifacts.length > 0) {
|
|
213
|
+
console.log("Test collections to remove:");
|
|
214
|
+
const testCollections = new Set(
|
|
215
|
+
report.test_artifacts.map((m) => m.collection),
|
|
216
|
+
);
|
|
217
|
+
for (const col of testCollections) {
|
|
218
|
+
const count = report.test_artifacts.filter(
|
|
219
|
+
(m) => m.collection === col,
|
|
220
|
+
).length;
|
|
221
|
+
console.log(` - ${col} (${count} memories)`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
console.log("\n📝 MANUAL CLEANUP STEPS\n");
|
|
226
|
+
console.log(
|
|
227
|
+
"semantic-memory MCP server does not expose delete/remove tools.",
|
|
228
|
+
);
|
|
229
|
+
console.log("Cleanup must be done via direct database access:\n");
|
|
230
|
+
console.log("1. Stop semantic-memory MCP server");
|
|
231
|
+
console.log("2. Connect to PostgreSQL:");
|
|
232
|
+
console.log(" psql -h /Users/joel/.semantic-memory/memory");
|
|
233
|
+
console.log("3. Delete test collections:");
|
|
234
|
+
console.log(
|
|
235
|
+
" DELETE FROM memories WHERE collection IN ('test-patterns', 'test-feedback');",
|
|
236
|
+
);
|
|
237
|
+
console.log("4. Restart semantic-memory MCP server");
|
|
238
|
+
console.log("5. Verify with semantic-memory_list\n");
|
|
239
|
+
|
|
240
|
+
console.log("🛡️ PREVENTION STRATEGY\n");
|
|
241
|
+
console.log("To prevent future pollution:");
|
|
242
|
+
console.log("1. ✅ Add test collection prefix isolation (subtask 1 - DONE)");
|
|
243
|
+
console.log("2. ✅ Add cleanup hooks in afterEach (subtask 2 - DONE)");
|
|
244
|
+
console.log("3. 📝 Document production collection names");
|
|
245
|
+
console.log("4. 📝 Add collection naming convention to CONTRIBUTING.md");
|
|
246
|
+
console.log(
|
|
247
|
+
"5. 📝 Consider requesting delete/remove API from MCP maintainers\n",
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
if (!dryRun) {
|
|
251
|
+
console.log(
|
|
252
|
+
"⚠️ --dry-run not specified, but no automated cleanup available.",
|
|
253
|
+
);
|
|
254
|
+
console.log(" Follow manual steps above.\n");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Store cleanup learnings in semantic-memory for future reference
|
|
260
|
+
*/
|
|
261
|
+
async function storeCleanupLearnings(report: AuditReport): Promise<void> {
|
|
262
|
+
console.log("💾 Storing cleanup learnings in semantic-memory...\n");
|
|
263
|
+
|
|
264
|
+
const rootCause = `
|
|
265
|
+
ROOT CAUSE: Semantic Memory Test Pollution (Dec 2025)
|
|
266
|
+
|
|
267
|
+
PROBLEM: Integration tests polluted production semantic-memory with ${report.test_artifacts.length} test artifacts across collections: ${Array.from(new Set(report.test_artifacts.map((m) => m.collection))).join(", ")}.
|
|
268
|
+
|
|
269
|
+
WHY IT HAPPENED:
|
|
270
|
+
1. Tests wrote to shared MCP server (no isolation)
|
|
271
|
+
2. No collection prefix strategy for test data
|
|
272
|
+
3. No cleanup hooks in test teardown
|
|
273
|
+
4. MCP server has no delete/remove API
|
|
274
|
+
|
|
275
|
+
IMPACT:
|
|
276
|
+
- ${Math.round((report.test_artifacts.length / report.total_memories) * 100)}% of semantic search results are test noise
|
|
277
|
+
- Production knowledge base unreliable
|
|
278
|
+
- Wasted storage and embedding costs
|
|
279
|
+
|
|
280
|
+
PREVENTION:
|
|
281
|
+
1. ✅ Collection prefix isolation: test-*, temp-* reserved for tests
|
|
282
|
+
2. ✅ Cleanup hooks: afterEach() deletes test collections
|
|
283
|
+
3. ✅ Mock semantic-memory in unit tests (avoid MCP calls)
|
|
284
|
+
4. 📝 Document production collection naming conventions
|
|
285
|
+
5. 📝 Add safeguards to prevent test->prod collection writes
|
|
286
|
+
|
|
287
|
+
MANUAL CLEANUP REQUIRED:
|
|
288
|
+
semantic-memory MCP lacks delete API. Must use direct PostgreSQL:
|
|
289
|
+
psql -h /Users/joel/.semantic-memory/memory
|
|
290
|
+
DELETE FROM memories WHERE collection LIKE 'test-%';
|
|
291
|
+
|
|
292
|
+
FUTURE: Request delete/remove API from @opencode/semantic-memory maintainers.
|
|
293
|
+
`.trim();
|
|
294
|
+
|
|
295
|
+
// Note: In real implementation, this would call semantic-memory_store
|
|
296
|
+
console.log("Would store:");
|
|
297
|
+
console.log(rootCause);
|
|
298
|
+
console.log("\nCollection: default");
|
|
299
|
+
console.log("Metadata: test-pollution, cleanup, prevention\n");
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// CLI Entry Point
|
|
303
|
+
const { values } = parseArgs({
|
|
304
|
+
args: process.argv.slice(2),
|
|
305
|
+
options: {
|
|
306
|
+
"dry-run": { type: "boolean", default: true },
|
|
307
|
+
collections: { type: "string" },
|
|
308
|
+
help: { type: "boolean", short: "h", default: false },
|
|
309
|
+
},
|
|
310
|
+
allowPositionals: true,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
if (values.help) {
|
|
314
|
+
console.log(`
|
|
315
|
+
Semantic Memory Test Pollution Cleanup
|
|
316
|
+
|
|
317
|
+
Audits semantic-memory for test artifacts and provides cleanup guidance.
|
|
318
|
+
|
|
319
|
+
Usage:
|
|
320
|
+
bun scripts/cleanup-test-memories.ts [options]
|
|
321
|
+
|
|
322
|
+
Options:
|
|
323
|
+
--dry-run Show what would be cleaned (default: true)
|
|
324
|
+
--collections <csv> Comma-separated list of collections to audit
|
|
325
|
+
-h, --help Show this help message
|
|
326
|
+
|
|
327
|
+
Examples:
|
|
328
|
+
bun scripts/cleanup-test-memories.ts
|
|
329
|
+
bun scripts/cleanup-test-memories.ts --dry-run=false
|
|
330
|
+
bun scripts/cleanup-test-memories.ts --collections test-patterns,test-feedback
|
|
331
|
+
|
|
332
|
+
Notes:
|
|
333
|
+
- semantic-memory MCP server does not expose delete/remove API
|
|
334
|
+
- Cleanup requires direct PostgreSQL access
|
|
335
|
+
- See script output for manual cleanup steps
|
|
336
|
+
`);
|
|
337
|
+
process.exit(0);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Run audit
|
|
341
|
+
const report = await auditMemories();
|
|
342
|
+
const dryRun = values["dry-run"] ?? true;
|
|
343
|
+
generateReport(report, dryRun);
|
|
344
|
+
await storeCleanupLearnings(report);
|
|
345
|
+
|
|
346
|
+
console.log("✅ Audit complete. See manual cleanup steps above.\n");
|
package/src/agent-mail.ts
CHANGED
|
@@ -31,7 +31,7 @@ import { tool } from "@opencode-ai/plugin";
|
|
|
31
31
|
import { z } from "zod";
|
|
32
32
|
import { isToolAvailable, warnMissingTool } from "./tool-availability";
|
|
33
33
|
import { getRateLimiter, type RateLimiter } from "./rate-limiter";
|
|
34
|
-
import type { MailSessionState } from "
|
|
34
|
+
import type { MailSessionState } from "swarm-mail";
|
|
35
35
|
|
|
36
36
|
// ============================================================================
|
|
37
37
|
// Configuration
|
package/src/beads.ts
CHANGED
|
@@ -104,8 +104,7 @@ import {
|
|
|
104
104
|
type BeadCreateArgs,
|
|
105
105
|
type EpicCreateResult,
|
|
106
106
|
} from "./schemas";
|
|
107
|
-
import { createEvent } from "
|
|
108
|
-
import { appendEvent } from "./streams/store";
|
|
107
|
+
import { createEvent, appendEvent } from "swarm-mail";
|
|
109
108
|
|
|
110
109
|
/**
|
|
111
110
|
* Custom error for bead operations
|
package/src/index.ts
CHANGED
|
@@ -320,12 +320,12 @@ export {
|
|
|
320
320
|
} from "./swarm-mail";
|
|
321
321
|
|
|
322
322
|
/**
|
|
323
|
-
* Re-export shared types from
|
|
323
|
+
* Re-export shared types from swarm-mail package
|
|
324
324
|
*
|
|
325
325
|
* Includes:
|
|
326
326
|
* - MailSessionState - Shared session state type for Agent Mail and Swarm Mail
|
|
327
327
|
*/
|
|
328
|
-
export { type MailSessionState } from "
|
|
328
|
+
export { type MailSessionState } from "swarm-mail";
|
|
329
329
|
|
|
330
330
|
/**
|
|
331
331
|
* Re-export structured module
|
|
@@ -4,10 +4,46 @@
|
|
|
4
4
|
* Tests for confidence decay, feedback scoring, outcome tracking,
|
|
5
5
|
* anti-patterns, pattern maturity, and swarm tool integrations.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* ## Test Isolation Pattern
|
|
8
|
+
*
|
|
9
|
+
* This file uses TEST_SEMANTIC_MEMORY_COLLECTION to isolate test data from
|
|
10
|
+
* production semantic-memory collections. Each test run gets a unique suffix,
|
|
11
|
+
* preventing pollution of the default collections.
|
|
12
|
+
*
|
|
13
|
+
* **Cleanup**: Test collections are NOT automatically deleted after test runs.
|
|
14
|
+
* This is intentional - semantic-memory doesn't provide bulk delete APIs.
|
|
15
|
+
* To clean up test artifacts, use:
|
|
16
|
+
*
|
|
17
|
+
* ```bash
|
|
18
|
+
* # Manual cleanup (use scripts/cleanup-test-memories.ts for automation)
|
|
19
|
+
* semantic-memory list --collection swarm-feedback-test-* --json | jq -r '.[].id' | xargs -I {} semantic-memory remove {}
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* The unique suffix prevents cross-test interference even without cleanup.
|
|
23
|
+
*/
|
|
24
|
+
import {
|
|
25
|
+
describe,
|
|
26
|
+
it,
|
|
27
|
+
expect,
|
|
28
|
+
beforeEach,
|
|
29
|
+
afterEach,
|
|
30
|
+
beforeAll,
|
|
31
|
+
afterAll,
|
|
32
|
+
vi,
|
|
33
|
+
} from "vitest";
|
|
34
|
+
import { getTestCollectionName } from "./storage";
|
|
35
|
+
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Test Isolation Setup
|
|
38
|
+
// ============================================================================
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Set unique collection suffix for this test run
|
|
42
|
+
*
|
|
43
|
+
* CRITICAL: This MUST be set before any storage instances are created.
|
|
44
|
+
* The env var is read during getCollectionNames() which happens at storage init.
|
|
9
45
|
*/
|
|
10
|
-
|
|
46
|
+
process.env.TEST_SEMANTIC_MEMORY_COLLECTION = getTestCollectionName();
|
|
11
47
|
|
|
12
48
|
// Learning module
|
|
13
49
|
import {
|
|
@@ -73,6 +109,30 @@ const mockContext = {
|
|
|
73
109
|
abort: new AbortController().signal,
|
|
74
110
|
};
|
|
75
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Global test lifecycle hooks
|
|
114
|
+
*
|
|
115
|
+
* These document the test isolation pattern but don't actively clean up.
|
|
116
|
+
* Cleanup is manual via scripts/cleanup-test-memories.ts
|
|
117
|
+
*/
|
|
118
|
+
beforeAll(() => {
|
|
119
|
+
console.log(
|
|
120
|
+
`[test] TEST_SEMANTIC_MEMORY_COLLECTION = ${process.env.TEST_SEMANTIC_MEMORY_COLLECTION}`,
|
|
121
|
+
);
|
|
122
|
+
console.log(
|
|
123
|
+
`[test] Test collections will be prefixed with: swarm-*-${process.env.TEST_SEMANTIC_MEMORY_COLLECTION}`,
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
afterAll(() => {
|
|
128
|
+
console.log(
|
|
129
|
+
`[test] Test complete. Collections NOT auto-deleted (use scripts/cleanup-test-memories.ts for cleanup)`,
|
|
130
|
+
);
|
|
131
|
+
console.log(
|
|
132
|
+
`[test] Test collection suffix was: ${process.env.TEST_SEMANTIC_MEMORY_COLLECTION}`,
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
76
136
|
/**
|
|
77
137
|
* Create a feedback event for testing
|
|
78
138
|
*/
|
|
@@ -1150,6 +1210,10 @@ describe("Storage Module", () => {
|
|
|
1150
1210
|
storage = new InMemoryStorage();
|
|
1151
1211
|
});
|
|
1152
1212
|
|
|
1213
|
+
afterEach(async () => {
|
|
1214
|
+
await storage.close();
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1153
1217
|
it("stores and retrieves feedback", async () => {
|
|
1154
1218
|
const event = createFeedbackEvent("type_safe", "helpful");
|
|
1155
1219
|
await storage.storeFeedback(event);
|
|
@@ -1305,13 +1369,15 @@ describe("Storage Module", () => {
|
|
|
1305
1369
|
beforeEach(async () => {
|
|
1306
1370
|
isAvailable = await isSemanticMemoryAvailable();
|
|
1307
1371
|
if (isAvailable) {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1372
|
+
// Use default collections (which include TEST_SEMANTIC_MEMORY_COLLECTION suffix)
|
|
1373
|
+
// This ensures all tests use the same isolated collections for this test run
|
|
1374
|
+
storage = new SemanticMemoryStorage();
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
afterEach(async () => {
|
|
1379
|
+
if (storage) {
|
|
1380
|
+
await storage.close();
|
|
1315
1381
|
}
|
|
1316
1382
|
});
|
|
1317
1383
|
|
|
@@ -1380,6 +1446,10 @@ describe("Storage Module", () => {
|
|
|
1380
1446
|
await resetStorage();
|
|
1381
1447
|
});
|
|
1382
1448
|
|
|
1449
|
+
afterEach(async () => {
|
|
1450
|
+
await resetStorage();
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1383
1453
|
it("getStorage returns a storage instance", async () => {
|
|
1384
1454
|
const storage = await getStorage();
|
|
1385
1455
|
expect(storage).toBeDefined();
|
|
@@ -177,7 +177,7 @@ describe("InMemoryMandateStorage", () => {
|
|
|
177
177
|
it("should throw when updating non-existent mandate", async () => {
|
|
178
178
|
await expect(
|
|
179
179
|
storage.update("non-existent", { content: "Updated" }),
|
|
180
|
-
).rejects.toThrow("Mandate non-existent not found");
|
|
180
|
+
).rejects.toThrow("Mandate 'non-existent' not found");
|
|
181
181
|
});
|
|
182
182
|
});
|
|
183
183
|
|
|
@@ -235,7 +235,7 @@ describe("InMemoryMandateStorage", () => {
|
|
|
235
235
|
};
|
|
236
236
|
|
|
237
237
|
await expect(storage.vote(vote2)).rejects.toThrow(
|
|
238
|
-
"Agent GreenRiver has already voted on mandate mandate-1",
|
|
238
|
+
"Agent 'GreenRiver' has already voted on mandate 'mandate-1'",
|
|
239
239
|
);
|
|
240
240
|
});
|
|
241
241
|
|
|
@@ -572,7 +572,7 @@ describe("InMemoryMandateStorage", () => {
|
|
|
572
572
|
createMandateStorage({
|
|
573
573
|
backend: "unknown" as "semantic-memory" | "memory",
|
|
574
574
|
}),
|
|
575
|
-
).toThrow("Unknown storage backend: unknown");
|
|
575
|
+
).toThrow("Unknown storage backend: 'unknown'");
|
|
576
576
|
});
|
|
577
577
|
});
|
|
578
578
|
});
|