opencode-swarm-plugin 0.20.0 → 0.21.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/.beads/issues.jsonl +202 -0
- package/INTEGRATION_EXAMPLE.md +66 -0
- package/README.md +127 -562
- package/dist/index.js +3842 -2917
- package/dist/plugin.js +3824 -2918
- package/docs/analysis/subagent-coordination-patterns.md +2 -0
- package/evals/README.md +116 -0
- package/evals/evalite.config.ts +15 -0
- package/evals/example.eval.ts +32 -0
- package/evals/fixtures/decomposition-cases.ts +105 -0
- package/evals/lib/data-loader.test.ts +288 -0
- package/evals/lib/data-loader.ts +111 -0
- package/evals/lib/llm.ts +115 -0
- package/evals/scorers/index.ts +200 -0
- package/evals/scorers/outcome-scorers.test.ts +27 -0
- package/evals/scorers/outcome-scorers.ts +349 -0
- package/evals/swarm-decomposition.eval.ts +112 -0
- package/package.json +8 -1
- package/src/beads.ts +49 -0
- package/src/eval-capture.ts +487 -0
- package/src/index.ts +45 -3
- package/src/output-guardrails.test.ts +438 -0
- package/src/output-guardrails.ts +381 -0
- package/src/schemas/index.ts +18 -0
- package/src/schemas/swarm-context.ts +115 -0
- package/src/streams/events.test.ts +296 -0
- package/src/streams/events.ts +93 -0
- package/src/streams/migrations.test.ts +24 -20
- package/src/streams/migrations.ts +51 -0
- package/src/streams/projections.ts +187 -0
- package/src/streams/store.ts +275 -0
- package/src/swarm-orchestrate.ts +430 -1
- package/src/swarm-prompts.ts +84 -12
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Output Guardrails Integration Example
|
|
2
|
+
|
|
3
|
+
## How to Integrate into src/index.ts
|
|
4
|
+
|
|
5
|
+
Add to the `tool.execute.after` hook:
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { guardrailOutput, createMetrics } from "./output-guardrails";
|
|
9
|
+
|
|
10
|
+
// In the SwarmPlugin function:
|
|
11
|
+
"tool.execute.after": async (input, output) => {
|
|
12
|
+
const toolName = input.tool;
|
|
13
|
+
|
|
14
|
+
// Apply guardrails to prevent context blowout
|
|
15
|
+
const guardrailed = guardrailOutput(toolName, output.output || "");
|
|
16
|
+
|
|
17
|
+
if (guardrailed.truncated) {
|
|
18
|
+
// Log metrics for learning
|
|
19
|
+
const metrics = createMetrics(guardrailed, toolName);
|
|
20
|
+
console.log(
|
|
21
|
+
`[swarm-plugin] Truncated ${toolName}: ${metrics.originalLength} → ${metrics.truncatedLength} chars`
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Update output
|
|
25
|
+
output.output = guardrailed.output;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// ... existing code (Agent Mail tracking, auto-release, etc.)
|
|
29
|
+
},
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## What It Does
|
|
33
|
+
|
|
34
|
+
1. **Prevents Context Exhaustion**: Tools like `context7_get-library-docs` and `repo-autopsy_search` can return 100k+ chars, blowing out context
|
|
35
|
+
2. **Smart Truncation**: Preserves JSON structure, code blocks (```), and markdown headers
|
|
36
|
+
3. **Per-Tool Limits**: Higher limits for code tools (64k), lower for stats (8k)
|
|
37
|
+
4. **Skip Internal Tools**: Never truncates beads_*, swarmmail_*, structured_*, swarm_* tools
|
|
38
|
+
5. **Metrics**: Track truncation patterns for future optimization
|
|
39
|
+
|
|
40
|
+
## Default Limits
|
|
41
|
+
|
|
42
|
+
- **Default**: 32,000 chars (~8k tokens)
|
|
43
|
+
- **Code/Doc Tools**: 64,000 chars (repo-autopsy_file, context7_get-library-docs, cass_view)
|
|
44
|
+
- **Search Tools**: 48,000 chars (cass_search, skills_read)
|
|
45
|
+
- **Stats Tools**: 8,000-24,000 chars (cass_stats, repo-autopsy_stats, repo-autopsy_structure)
|
|
46
|
+
- **Skip Tools**: All beads_*, agentmail_*, swarmmail_*, structured_*, swarm_*, mandate_* tools
|
|
47
|
+
|
|
48
|
+
## Testing
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Run tests
|
|
52
|
+
bun test src/output-guardrails.test.ts
|
|
53
|
+
|
|
54
|
+
# Typecheck
|
|
55
|
+
bun run typecheck
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Coverage
|
|
59
|
+
|
|
60
|
+
- ✅ 29 tests passing
|
|
61
|
+
- ✅ JSON structure preservation
|
|
62
|
+
- ✅ Code block boundary detection
|
|
63
|
+
- ✅ Markdown header preservation
|
|
64
|
+
- ✅ Per-tool limits
|
|
65
|
+
- ✅ Skip tool configuration
|
|
66
|
+
- ✅ Edge cases (empty string, exact limit, unicode, CRLF)
|