opencode-swarm-plugin 0.19.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.
@@ -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)