opencode-swarm-plugin 0.43.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/cass.characterization.test.ts +422 -0
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.test.ts +68 -0
- package/bin/swarm.ts +81 -8
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/contributor-tools.d.ts +42 -0
- package/dist/contributor-tools.d.ts.map +1 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7728 -62590
- package/dist/plugin.js +23833 -78695
- package/dist/sessions/agent-discovery.d.ts +59 -0
- package/dist/sessions/agent-discovery.d.ts.map +1 -0
- package/dist/sessions/index.d.ts +10 -0
- package/dist/sessions/index.d.ts.map +1 -0
- 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 -2255
- 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/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/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 -2426
- 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/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 -935
- 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/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
package/src/index.ts
DELETED
|
@@ -1,935 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenCode Swarm Plugin
|
|
3
|
-
*
|
|
4
|
-
* A type-safe plugin for multi-agent coordination with hive issue tracking
|
|
5
|
-
* and Agent Mail integration. Provides structured tools for swarm operations.
|
|
6
|
-
*
|
|
7
|
-
* @module opencode-swarm-plugin
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* // In opencode.jsonc
|
|
12
|
-
* {
|
|
13
|
-
* "plugins": ["opencode-swarm-plugin"]
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* // Programmatic usage (hive is the new name, beads is deprecated)
|
|
20
|
-
* import { hiveTools, beadsTools, agentMailTools, swarmMailTools } from "opencode-swarm-plugin"
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
import type { Plugin, PluginInput, Hooks } from "@opencode-ai/plugin";
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
hiveTools,
|
|
27
|
-
beadsTools,
|
|
28
|
-
setHiveWorkingDirectory,
|
|
29
|
-
setBeadsWorkingDirectory,
|
|
30
|
-
} from "./hive";
|
|
31
|
-
import {
|
|
32
|
-
agentMailTools,
|
|
33
|
-
setAgentMailProjectDirectory,
|
|
34
|
-
type AgentMailState,
|
|
35
|
-
AGENT_MAIL_URL,
|
|
36
|
-
} from "./agent-mail";
|
|
37
|
-
import {
|
|
38
|
-
swarmMailTools,
|
|
39
|
-
setSwarmMailProjectDirectory,
|
|
40
|
-
type SwarmMailState,
|
|
41
|
-
} from "./swarm-mail";
|
|
42
|
-
import { structuredTools } from "./structured";
|
|
43
|
-
import { swarmTools } from "./swarm";
|
|
44
|
-
import { worktreeTools } from "./swarm-worktree";
|
|
45
|
-
import { reviewTools } from "./swarm-review";
|
|
46
|
-
import { repoCrawlTools } from "./repo-crawl";
|
|
47
|
-
import { skillsTools, setSkillsProjectDirectory } from "./skills";
|
|
48
|
-
import { mandateTools } from "./mandates";
|
|
49
|
-
import { memoryTools } from "./memory-tools";
|
|
50
|
-
import { observabilityTools } from "./observability-tools";
|
|
51
|
-
import { researchTools } from "./swarm-research";
|
|
52
|
-
import { evalTools } from "./eval-runner";
|
|
53
|
-
import {
|
|
54
|
-
guardrailOutput,
|
|
55
|
-
DEFAULT_GUARDRAIL_CONFIG,
|
|
56
|
-
type GuardrailResult,
|
|
57
|
-
} from "./output-guardrails";
|
|
58
|
-
import {
|
|
59
|
-
analyzeTodoWrite,
|
|
60
|
-
shouldAnalyzeTool,
|
|
61
|
-
detectCoordinatorViolation,
|
|
62
|
-
isInCoordinatorContext,
|
|
63
|
-
getCoordinatorContext,
|
|
64
|
-
setCoordinatorContext,
|
|
65
|
-
clearCoordinatorContext,
|
|
66
|
-
} from "./planning-guardrails";
|
|
67
|
-
import { createCompactionHook } from "./compaction-hook";
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* OpenCode Swarm Plugin
|
|
71
|
-
*
|
|
72
|
-
* Registers all swarm coordination tools:
|
|
73
|
-
* - hive:* - Type-safe hive issue tracker wrappers (primary)
|
|
74
|
-
* - beads:* - Legacy aliases for hive tools (deprecated, use hive:* instead)
|
|
75
|
-
* - agent-mail:* - Multi-agent coordination via Agent Mail MCP (legacy)
|
|
76
|
-
* - swarm-mail:* - Multi-agent coordination with embedded event sourcing (recommended)
|
|
77
|
-
* - structured:* - Structured output parsing and validation
|
|
78
|
-
* - swarm:* - Swarm orchestration and task decomposition
|
|
79
|
-
* - repo-crawl:* - GitHub API tools for repository research
|
|
80
|
-
* - skills:* - Agent skills discovery, activation, and execution
|
|
81
|
-
* - mandate:* - Agent voting system for collaborative knowledge curation
|
|
82
|
-
* - semantic-memory:* - Semantic memory with vector embeddings (Ollama + PGLite)
|
|
83
|
-
*
|
|
84
|
-
* @param input - Plugin context from OpenCode
|
|
85
|
-
* @returns Plugin hooks including tools, events, and tool execution hooks
|
|
86
|
-
*/
|
|
87
|
-
const SwarmPlugin: Plugin = async (
|
|
88
|
-
input: PluginInput,
|
|
89
|
-
): Promise<Hooks> => {
|
|
90
|
-
const { $, directory, client } = input;
|
|
91
|
-
|
|
92
|
-
// Set the working directory for hive commands
|
|
93
|
-
// This ensures hive operations run in the project directory, not ~/.config/opencode
|
|
94
|
-
setHiveWorkingDirectory(directory);
|
|
95
|
-
|
|
96
|
-
// Set the project directory for skills discovery
|
|
97
|
-
// Skills are discovered from .opencode/skills/, .claude/skills/, or skills/
|
|
98
|
-
setSkillsProjectDirectory(directory);
|
|
99
|
-
|
|
100
|
-
// Set the project directory for Agent Mail (legacy MCP-based)
|
|
101
|
-
// This ensures agentmail_init uses the correct project path by default
|
|
102
|
-
// (prevents using plugin directory when working in a different project)
|
|
103
|
-
setAgentMailProjectDirectory(directory);
|
|
104
|
-
|
|
105
|
-
// Set the project directory for Swarm Mail (embedded event-sourced)
|
|
106
|
-
// This ensures swarmmail_init uses the correct project path by default
|
|
107
|
-
setSwarmMailProjectDirectory(directory);
|
|
108
|
-
|
|
109
|
-
/** Track active sessions for cleanup */
|
|
110
|
-
let activeAgentMailState: AgentMailState | null = null;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Release all file reservations for the active agent
|
|
114
|
-
* Best-effort cleanup - errors are logged but not thrown
|
|
115
|
-
*/
|
|
116
|
-
async function releaseReservations(): Promise<void> {
|
|
117
|
-
if (
|
|
118
|
-
!activeAgentMailState ||
|
|
119
|
-
activeAgentMailState.reservations.length === 0
|
|
120
|
-
) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
const response = await fetch(`${AGENT_MAIL_URL}/mcp/`, {
|
|
126
|
-
method: "POST",
|
|
127
|
-
headers: { "Content-Type": "application/json" },
|
|
128
|
-
body: JSON.stringify({
|
|
129
|
-
jsonrpc: "2.0",
|
|
130
|
-
id: crypto.randomUUID(),
|
|
131
|
-
method: "tools/call",
|
|
132
|
-
params: {
|
|
133
|
-
name: "release_file_reservations",
|
|
134
|
-
arguments: {
|
|
135
|
-
project_key: activeAgentMailState.projectKey,
|
|
136
|
-
agent_name: activeAgentMailState.agentName,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
}),
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
if (response.ok) {
|
|
143
|
-
activeAgentMailState.reservations = [];
|
|
144
|
-
}
|
|
145
|
-
} catch (error) {
|
|
146
|
-
// Agent Mail might not be running - that's ok
|
|
147
|
-
console.warn(
|
|
148
|
-
`[swarm-plugin] Could not auto-release reservations: ${error instanceof Error ? error.message : String(error)}`,
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
/**
|
|
155
|
-
* Register all tools from modules
|
|
156
|
-
*
|
|
157
|
-
* Tools are namespaced by module:
|
|
158
|
-
* - hive:create, hive:query, hive:update, etc. (primary)
|
|
159
|
-
* - beads:* - Legacy aliases (deprecated, use hive:* instead)
|
|
160
|
-
* - agent-mail:init, agent-mail:send, agent-mail:reserve, etc. (legacy MCP)
|
|
161
|
-
* - swarm-mail:init, swarm-mail:send, swarm-mail:reserve, etc. (embedded)
|
|
162
|
-
* - repo-crawl:readme, repo-crawl:structure, etc.
|
|
163
|
-
* - mandate:file, mandate:vote, mandate:query, etc.
|
|
164
|
-
* - semantic-memory:store, semantic-memory:find, semantic-memory:get, etc.
|
|
165
|
-
*/
|
|
166
|
-
tool: {
|
|
167
|
-
...hiveTools,
|
|
168
|
-
...swarmMailTools,
|
|
169
|
-
...structuredTools,
|
|
170
|
-
...swarmTools,
|
|
171
|
-
...worktreeTools,
|
|
172
|
-
...reviewTools,
|
|
173
|
-
...repoCrawlTools,
|
|
174
|
-
...skillsTools,
|
|
175
|
-
...mandateTools,
|
|
176
|
-
...memoryTools,
|
|
177
|
-
...observabilityTools,
|
|
178
|
-
...researchTools,
|
|
179
|
-
...evalTools,
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Event hook for session lifecycle
|
|
184
|
-
*
|
|
185
|
-
* Handles cleanup when session becomes idle:
|
|
186
|
-
* - Releases any held file reservations
|
|
187
|
-
*/
|
|
188
|
-
event: async ({ event }) => {
|
|
189
|
-
// Auto-release reservations on session idle
|
|
190
|
-
if (event.type === "session.idle") {
|
|
191
|
-
await releaseReservations();
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Hook before tool execution for planning guardrails
|
|
197
|
-
*
|
|
198
|
-
* Warns when agents are about to make planning mistakes:
|
|
199
|
-
* - Using todowrite for multi-file implementation (should use swarm)
|
|
200
|
-
* - Coordinator editing files directly (should spawn workers)
|
|
201
|
-
* - Coordinator running tests (workers should run tests)
|
|
202
|
-
*/
|
|
203
|
-
"tool.execute.before": async (input, output) => {
|
|
204
|
-
const toolName = input.tool;
|
|
205
|
-
|
|
206
|
-
// Check for planning anti-patterns
|
|
207
|
-
if (shouldAnalyzeTool(toolName)) {
|
|
208
|
-
const analysis = analyzeTodoWrite(output.args);
|
|
209
|
-
if (analysis.warning) {
|
|
210
|
-
console.warn(`[swarm-plugin] ${analysis.warning}`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Check for coordinator violations when in coordinator context
|
|
215
|
-
if (isInCoordinatorContext()) {
|
|
216
|
-
const ctx = getCoordinatorContext();
|
|
217
|
-
const violation = detectCoordinatorViolation({
|
|
218
|
-
sessionId: input.sessionID || "unknown",
|
|
219
|
-
epicId: ctx.epicId || "unknown",
|
|
220
|
-
toolName,
|
|
221
|
-
toolArgs: output.args as Record<string, unknown>,
|
|
222
|
-
agentContext: "coordinator",
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
if (violation.isViolation) {
|
|
226
|
-
console.warn(`[swarm-plugin] ${violation.message}`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Activate coordinator context when swarm tools are used
|
|
231
|
-
if (toolName === "hive_create_epic" || toolName === "swarm_decompose") {
|
|
232
|
-
setCoordinatorContext({
|
|
233
|
-
isCoordinator: true,
|
|
234
|
-
sessionId: input.sessionID,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Capture epic ID when epic is created
|
|
239
|
-
if (toolName === "hive_create_epic" && output.args) {
|
|
240
|
-
const args = output.args as { epic_title?: string };
|
|
241
|
-
// Epic ID will be set after execution in tool.execute.after
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Hook after tool execution for automatic cleanup and guardrails
|
|
247
|
-
*
|
|
248
|
-
* - Applies output guardrails to prevent context blowout from MCP tools
|
|
249
|
-
* - Auto-releases file reservations after swarm:complete or hive:close
|
|
250
|
-
* - Auto-syncs cells after closing
|
|
251
|
-
*/
|
|
252
|
-
"tool.execute.after": async (input, output) => {
|
|
253
|
-
const toolName = input.tool;
|
|
254
|
-
|
|
255
|
-
// Apply output guardrails to prevent context blowout
|
|
256
|
-
// Skip if output is empty or tool is in skip list
|
|
257
|
-
if (output.output && typeof output.output === "string") {
|
|
258
|
-
const guardrailResult = guardrailOutput(toolName, output.output);
|
|
259
|
-
if (guardrailResult.truncated) {
|
|
260
|
-
output.output = guardrailResult.output;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Track Agent Mail state for cleanup
|
|
265
|
-
if (toolName === "agentmail_init" && output.output) {
|
|
266
|
-
try {
|
|
267
|
-
const result = JSON.parse(output.output);
|
|
268
|
-
if (result.agent) {
|
|
269
|
-
activeAgentMailState = {
|
|
270
|
-
projectKey: result.project?.human_key || "",
|
|
271
|
-
agentName: result.agent.name,
|
|
272
|
-
reservations: [],
|
|
273
|
-
startedAt: new Date().toISOString(),
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
} catch {
|
|
277
|
-
// Parsing failed - ignore
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Track reservations from output
|
|
282
|
-
if (
|
|
283
|
-
toolName === "agentmail_reserve" &&
|
|
284
|
-
output.output &&
|
|
285
|
-
activeAgentMailState
|
|
286
|
-
) {
|
|
287
|
-
// Extract reservation count from output if present
|
|
288
|
-
const match = output.output.match(/Reserved (\d+) path/);
|
|
289
|
-
if (match) {
|
|
290
|
-
// Track reservation for cleanup
|
|
291
|
-
activeAgentMailState.reservations.push(Date.now());
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Auto-release after swarm:complete
|
|
296
|
-
if (toolName === "swarm_complete" && activeAgentMailState) {
|
|
297
|
-
await releaseReservations();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Capture epic ID when epic is created (for coordinator context)
|
|
301
|
-
if (toolName === "hive_create_epic" && output.output) {
|
|
302
|
-
try {
|
|
303
|
-
const result = JSON.parse(output.output);
|
|
304
|
-
if (result.epic?.id) {
|
|
305
|
-
setCoordinatorContext({
|
|
306
|
-
isCoordinator: true,
|
|
307
|
-
epicId: result.epic.id,
|
|
308
|
-
sessionId: input.sessionID,
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
} catch {
|
|
312
|
-
// Parsing failed - ignore
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Clear coordinator context when epic is closed
|
|
317
|
-
if (toolName === "hive_close" && output.output && isInCoordinatorContext()) {
|
|
318
|
-
const ctx = getCoordinatorContext();
|
|
319
|
-
try {
|
|
320
|
-
// Check if the closed cell is the active epic
|
|
321
|
-
const result = JSON.parse(output.output);
|
|
322
|
-
if (result.id === ctx.epicId) {
|
|
323
|
-
clearCoordinatorContext();
|
|
324
|
-
}
|
|
325
|
-
} catch {
|
|
326
|
-
// Parsing failed - ignore
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Note: hive_sync should be called explicitly at session end
|
|
331
|
-
// Auto-sync was removed because bd CLI is deprecated
|
|
332
|
-
// The hive_sync tool handles flushing to JSONL and git commit/push
|
|
333
|
-
},
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Compaction hook for swarm context preservation
|
|
337
|
-
*
|
|
338
|
-
* When OpenCode compacts session context, this hook injects swarm state
|
|
339
|
-
* to ensure coordinators can resume orchestration seamlessly.
|
|
340
|
-
*
|
|
341
|
-
* Uses SDK client to scan actual session messages for precise swarm state
|
|
342
|
-
* (epic IDs, subtask status, agent names) rather than relying solely on
|
|
343
|
-
* heuristic detection from hive/swarm-mail.
|
|
344
|
-
*
|
|
345
|
-
* Note: This hook is experimental and may not be in the published Hooks type yet.
|
|
346
|
-
*/
|
|
347
|
-
"experimental.session.compacting": createCompactionHook(client),
|
|
348
|
-
} as Hooks & {
|
|
349
|
-
"experimental.session.compacting"?: (
|
|
350
|
-
input: { sessionID: string },
|
|
351
|
-
output: { context: string[] },
|
|
352
|
-
) => Promise<void>;
|
|
353
|
-
};
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Default export for OpenCode plugin loading
|
|
358
|
-
*
|
|
359
|
-
* OpenCode loads plugins by their default export, so this allows:
|
|
360
|
-
* ```json
|
|
361
|
-
* { "plugins": ["opencode-swarm-plugin"] }
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
export default SwarmPlugin;
|
|
365
|
-
|
|
366
|
-
// =============================================================================
|
|
367
|
-
// Re-exports for programmatic use
|
|
368
|
-
// =============================================================================
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Re-export all schemas for type-safe usage
|
|
372
|
-
*/
|
|
373
|
-
export * from "./schemas";
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Re-export hive module (primary) and beads module (deprecated aliases)
|
|
377
|
-
*
|
|
378
|
-
* Includes:
|
|
379
|
-
* - hiveTools - All hive tool definitions (primary)
|
|
380
|
-
* - beadsTools - Legacy aliases for backward compatibility (deprecated)
|
|
381
|
-
* - Individual tool exports (hive_create, hive_query, etc.)
|
|
382
|
-
* - Legacy aliases (hive_create, hive_query, etc.)
|
|
383
|
-
* - HiveError, HiveValidationError (and BeadError, BeadValidationError aliases)
|
|
384
|
-
*
|
|
385
|
-
* DEPRECATED: Use hive_* tools instead of beads_* tools
|
|
386
|
-
*/
|
|
387
|
-
export * from "./hive";
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Re-export agent-mail module (legacy MCP-based)
|
|
391
|
-
*
|
|
392
|
-
* Includes:
|
|
393
|
-
* - agentMailTools - All agent mail tool definitions
|
|
394
|
-
* - AgentMailError, FileReservationConflictError - Error classes
|
|
395
|
-
* - AgentMailState - Session state type
|
|
396
|
-
*
|
|
397
|
-
* NOTE: For OpenCode plugin usage, import from "opencode-swarm-plugin/plugin" instead
|
|
398
|
-
* to avoid the plugin loader trying to call these classes as functions.
|
|
399
|
-
*
|
|
400
|
-
* DEPRECATED: Use swarm-mail module instead for embedded event-sourced implementation.
|
|
401
|
-
*/
|
|
402
|
-
export {
|
|
403
|
-
agentMailTools,
|
|
404
|
-
AgentMailError,
|
|
405
|
-
AgentMailNotInitializedError,
|
|
406
|
-
FileReservationConflictError,
|
|
407
|
-
createAgentMailError,
|
|
408
|
-
setAgentMailProjectDirectory,
|
|
409
|
-
getAgentMailProjectDirectory,
|
|
410
|
-
mcpCallWithAutoInit,
|
|
411
|
-
isProjectNotFoundError,
|
|
412
|
-
isAgentNotFoundError,
|
|
413
|
-
type AgentMailState,
|
|
414
|
-
} from "./agent-mail";
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Re-export swarm-mail module (embedded event-sourced)
|
|
418
|
-
*
|
|
419
|
-
* Includes:
|
|
420
|
-
* - swarmMailTools - All swarm mail tool definitions
|
|
421
|
-
* - setSwarmMailProjectDirectory, getSwarmMailProjectDirectory - Directory management
|
|
422
|
-
* - clearSessionState - Session cleanup
|
|
423
|
-
* - SwarmMailState - Session state type
|
|
424
|
-
*
|
|
425
|
-
* Features:
|
|
426
|
-
* - Embedded PGLite storage (no external server dependency)
|
|
427
|
-
* - Event sourcing for full audit trail
|
|
428
|
-
* - Offset-based resumability
|
|
429
|
-
* - Materialized views for fast queries
|
|
430
|
-
* - File reservation with conflict detection
|
|
431
|
-
*/
|
|
432
|
-
export {
|
|
433
|
-
swarmMailTools,
|
|
434
|
-
setSwarmMailProjectDirectory,
|
|
435
|
-
getSwarmMailProjectDirectory,
|
|
436
|
-
clearSessionState,
|
|
437
|
-
type SwarmMailState,
|
|
438
|
-
} from "./swarm-mail";
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Re-export shared types from swarm-mail package
|
|
442
|
-
*
|
|
443
|
-
* Includes:
|
|
444
|
-
* - MailSessionState - Shared session state type for Agent Mail and Swarm Mail
|
|
445
|
-
*/
|
|
446
|
-
export { type MailSessionState } from "swarm-mail";
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Re-export structured module
|
|
450
|
-
*
|
|
451
|
-
* Includes:
|
|
452
|
-
* - structuredTools - Structured output parsing tools
|
|
453
|
-
* - Utility functions for JSON extraction
|
|
454
|
-
*/
|
|
455
|
-
export {
|
|
456
|
-
structuredTools,
|
|
457
|
-
extractJsonFromText,
|
|
458
|
-
formatZodErrors,
|
|
459
|
-
getSchemaByName,
|
|
460
|
-
} from "./structured";
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Re-export swarm module
|
|
464
|
-
*
|
|
465
|
-
* Includes:
|
|
466
|
-
* - swarmTools - Swarm orchestration tools
|
|
467
|
-
* - SwarmError, DecompositionError - Error classes
|
|
468
|
-
* - formatSubtaskPrompt, formatEvaluationPrompt - Prompt helpers
|
|
469
|
-
* - selectStrategy, formatStrategyGuidelines - Strategy selection helpers
|
|
470
|
-
* - STRATEGIES - Strategy definitions
|
|
471
|
-
*
|
|
472
|
-
* Types:
|
|
473
|
-
* - DecompositionStrategy - Strategy type union
|
|
474
|
-
* - StrategyDefinition - Strategy definition interface
|
|
475
|
-
*
|
|
476
|
-
* NOTE: Prompt template strings (DECOMPOSITION_PROMPT, etc.) are NOT exported
|
|
477
|
-
* to avoid confusing the plugin loader which tries to call all exports as functions
|
|
478
|
-
*/
|
|
479
|
-
export {
|
|
480
|
-
swarmTools,
|
|
481
|
-
SwarmError,
|
|
482
|
-
DecompositionError,
|
|
483
|
-
formatSubtaskPrompt,
|
|
484
|
-
formatSubtaskPromptV2,
|
|
485
|
-
formatEvaluationPrompt,
|
|
486
|
-
SUBTASK_PROMPT_V2,
|
|
487
|
-
// Strategy exports
|
|
488
|
-
STRATEGIES,
|
|
489
|
-
selectStrategy,
|
|
490
|
-
formatStrategyGuidelines,
|
|
491
|
-
type DecompositionStrategy,
|
|
492
|
-
type StrategyDefinition,
|
|
493
|
-
} from "./swarm";
|
|
494
|
-
|
|
495
|
-
// =============================================================================
|
|
496
|
-
// Unified Tool Registry for CLI
|
|
497
|
-
// =============================================================================
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* All tools in a single registry for CLI tool execution
|
|
501
|
-
*
|
|
502
|
-
* This is used by `swarm tool <name>` command to dynamically execute tools.
|
|
503
|
-
* Each tool has an `execute` function that takes (args, ctx) and returns a string.
|
|
504
|
-
*
|
|
505
|
-
* Note: hiveTools includes both hive_* and beads_* (legacy aliases)
|
|
506
|
-
*/
|
|
507
|
-
export const allTools = {
|
|
508
|
-
...hiveTools,
|
|
509
|
-
...swarmMailTools,
|
|
510
|
-
...structuredTools,
|
|
511
|
-
...swarmTools,
|
|
512
|
-
...worktreeTools,
|
|
513
|
-
...reviewTools,
|
|
514
|
-
...repoCrawlTools,
|
|
515
|
-
...skillsTools,
|
|
516
|
-
...mandateTools,
|
|
517
|
-
...memoryTools,
|
|
518
|
-
...observabilityTools,
|
|
519
|
-
} as const;
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
* Type for CLI tool names (all available tools)
|
|
523
|
-
*/
|
|
524
|
-
export type CLIToolName = keyof typeof allTools;
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Re-export storage module
|
|
528
|
-
*
|
|
529
|
-
* Includes:
|
|
530
|
-
* - createStorage, createStorageWithFallback - Factory functions
|
|
531
|
-
* - getStorage, setStorage, resetStorage - Global instance management
|
|
532
|
-
* - InMemoryStorage, SemanticMemoryStorage - Storage implementations
|
|
533
|
-
* - isSemanticMemoryAvailable - Availability check
|
|
534
|
-
* - DEFAULT_STORAGE_CONFIG - Default configuration
|
|
535
|
-
*
|
|
536
|
-
* Types:
|
|
537
|
-
* - LearningStorage - Unified storage interface
|
|
538
|
-
* - StorageConfig, StorageBackend, StorageCollections - Configuration types
|
|
539
|
-
*/
|
|
540
|
-
export {
|
|
541
|
-
createStorage,
|
|
542
|
-
createStorageWithFallback,
|
|
543
|
-
getStorage,
|
|
544
|
-
setStorage,
|
|
545
|
-
resetStorage,
|
|
546
|
-
InMemoryStorage,
|
|
547
|
-
SemanticMemoryStorage,
|
|
548
|
-
isSemanticMemoryAvailable,
|
|
549
|
-
DEFAULT_STORAGE_CONFIG,
|
|
550
|
-
type LearningStorage,
|
|
551
|
-
type StorageConfig,
|
|
552
|
-
type StorageBackend,
|
|
553
|
-
type StorageCollections,
|
|
554
|
-
} from "./storage";
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* Re-export tool-availability module
|
|
558
|
-
*
|
|
559
|
-
* Includes:
|
|
560
|
-
* - checkTool, isToolAvailable - Check individual tool availability
|
|
561
|
-
* - checkAllTools - Check all tools at once
|
|
562
|
-
* - withToolFallback, ifToolAvailable - Execute with graceful fallback
|
|
563
|
-
* - formatToolAvailability - Format availability for display
|
|
564
|
-
* - resetToolCache - Reset cached availability (for testing)
|
|
565
|
-
*
|
|
566
|
-
* Types:
|
|
567
|
-
* - ToolName - Supported tool names
|
|
568
|
-
* - ToolStatus, ToolAvailability - Status types
|
|
569
|
-
*/
|
|
570
|
-
export {
|
|
571
|
-
checkTool,
|
|
572
|
-
isToolAvailable,
|
|
573
|
-
checkAllTools,
|
|
574
|
-
getToolAvailability,
|
|
575
|
-
withToolFallback,
|
|
576
|
-
ifToolAvailable,
|
|
577
|
-
warnMissingTool,
|
|
578
|
-
requireTool,
|
|
579
|
-
formatToolAvailability,
|
|
580
|
-
resetToolCache,
|
|
581
|
-
type ToolName,
|
|
582
|
-
type ToolStatus,
|
|
583
|
-
type ToolAvailability,
|
|
584
|
-
} from "./tool-availability";
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* Re-export repo-crawl module
|
|
588
|
-
*
|
|
589
|
-
* Includes:
|
|
590
|
-
* - repoCrawlTools - All GitHub API repository research tools
|
|
591
|
-
* - repo_readme, repo_structure, repo_tree, repo_file, repo_search - Individual tools
|
|
592
|
-
* - RepoCrawlError - Error class
|
|
593
|
-
*
|
|
594
|
-
* Features:
|
|
595
|
-
* - Parse repos from various formats (owner/repo, URLs)
|
|
596
|
-
* - Optional GITHUB_TOKEN auth for higher rate limits (5000 vs 60 req/hour)
|
|
597
|
-
* - Tech stack detection from file patterns
|
|
598
|
-
* - Graceful rate limit handling
|
|
599
|
-
*/
|
|
600
|
-
export { repoCrawlTools, RepoCrawlError } from "./repo-crawl";
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Re-export skills module
|
|
604
|
-
*
|
|
605
|
-
* Implements Anthropic's Agent Skills specification for OpenCode.
|
|
606
|
-
*
|
|
607
|
-
* Includes:
|
|
608
|
-
* - skillsTools - All skills tools (list, use, execute, read)
|
|
609
|
-
* - discoverSkills, getSkill, listSkills - Discovery functions
|
|
610
|
-
* - parseFrontmatter - YAML frontmatter parser
|
|
611
|
-
* - getSkillsContextForSwarm - Swarm integration helper
|
|
612
|
-
* - findRelevantSkills - Task-based skill matching
|
|
613
|
-
*
|
|
614
|
-
* Types:
|
|
615
|
-
* - Skill, SkillMetadata, SkillRef - Skill data types
|
|
616
|
-
*/
|
|
617
|
-
export {
|
|
618
|
-
skillsTools,
|
|
619
|
-
discoverSkills,
|
|
620
|
-
getSkill,
|
|
621
|
-
listSkills,
|
|
622
|
-
parseFrontmatter,
|
|
623
|
-
setSkillsProjectDirectory,
|
|
624
|
-
invalidateSkillsCache,
|
|
625
|
-
getSkillsContextForSwarm,
|
|
626
|
-
findRelevantSkills,
|
|
627
|
-
type Skill,
|
|
628
|
-
type SkillMetadata,
|
|
629
|
-
type SkillRef,
|
|
630
|
-
} from "./skills";
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* Re-export mandates module
|
|
634
|
-
*
|
|
635
|
-
* Agent voting system for collaborative knowledge curation.
|
|
636
|
-
*
|
|
637
|
-
* Includes:
|
|
638
|
-
* - mandateTools - All mandate tools (file, vote, query, list, stats)
|
|
639
|
-
* - MandateError - Error class
|
|
640
|
-
*
|
|
641
|
-
* Features:
|
|
642
|
-
* - Submit ideas, tips, lore, snippets, and feature requests
|
|
643
|
-
* - Vote on entries (upvote/downvote) with 90-day decay
|
|
644
|
-
* - Semantic search for relevant mandates
|
|
645
|
-
* - Status transitions based on consensus (candidate → established → mandate)
|
|
646
|
-
* - Persistent storage with semantic-memory
|
|
647
|
-
*
|
|
648
|
-
* Types:
|
|
649
|
-
* - MandateEntry, Vote, MandateScore - Core data types
|
|
650
|
-
* - MandateStatus, MandateContentType - Enum types
|
|
651
|
-
*/
|
|
652
|
-
export { mandateTools, MandateError } from "./mandates";
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Re-export mandate-storage module
|
|
656
|
-
*
|
|
657
|
-
* Includes:
|
|
658
|
-
* - createMandateStorage - Factory function
|
|
659
|
-
* - getMandateStorage, setMandateStorage, resetMandateStorage - Global instance management
|
|
660
|
-
* - updateMandateStatus, updateAllMandateStatuses - Status update helpers
|
|
661
|
-
* - InMemoryMandateStorage, SemanticMemoryMandateStorage - Storage implementations
|
|
662
|
-
*
|
|
663
|
-
* Types:
|
|
664
|
-
* - MandateStorage - Unified storage interface
|
|
665
|
-
* - MandateStorageConfig, MandateStorageBackend, MandateStorageCollections - Configuration types
|
|
666
|
-
*/
|
|
667
|
-
export {
|
|
668
|
-
createMandateStorage,
|
|
669
|
-
getMandateStorage,
|
|
670
|
-
setMandateStorage,
|
|
671
|
-
resetMandateStorage,
|
|
672
|
-
updateMandateStatus,
|
|
673
|
-
updateAllMandateStatuses,
|
|
674
|
-
InMemoryMandateStorage,
|
|
675
|
-
SemanticMemoryMandateStorage,
|
|
676
|
-
DEFAULT_MANDATE_STORAGE_CONFIG,
|
|
677
|
-
type MandateStorage,
|
|
678
|
-
type MandateStorageConfig,
|
|
679
|
-
type MandateStorageBackend,
|
|
680
|
-
type MandateStorageCollections,
|
|
681
|
-
} from "./mandate-storage";
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Re-export mandate-promotion module
|
|
685
|
-
*
|
|
686
|
-
* Includes:
|
|
687
|
-
* - evaluatePromotion - Evaluate status transitions
|
|
688
|
-
* - shouldPromote - Determine new status based on score
|
|
689
|
-
* - formatPromotionResult - Format promotion result for display
|
|
690
|
-
* - evaluateBatchPromotions, getStatusChanges, groupByTransition - Batch helpers
|
|
691
|
-
*
|
|
692
|
-
* Types:
|
|
693
|
-
* - PromotionResult - Promotion evaluation result
|
|
694
|
-
*/
|
|
695
|
-
export {
|
|
696
|
-
evaluatePromotion,
|
|
697
|
-
shouldPromote,
|
|
698
|
-
formatPromotionResult,
|
|
699
|
-
evaluateBatchPromotions,
|
|
700
|
-
getStatusChanges,
|
|
701
|
-
groupByTransition,
|
|
702
|
-
type PromotionResult,
|
|
703
|
-
} from "./mandate-promotion";
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Re-export output-guardrails module
|
|
707
|
-
*
|
|
708
|
-
* Includes:
|
|
709
|
-
* - guardrailOutput - Main entry point for truncating tool output
|
|
710
|
-
* - truncateWithBoundaries - Smart truncation preserving structure
|
|
711
|
-
* - getToolLimit - Get character limit for a tool
|
|
712
|
-
* - DEFAULT_GUARDRAIL_CONFIG - Default configuration
|
|
713
|
-
*
|
|
714
|
-
* Types:
|
|
715
|
-
* - GuardrailConfig - Configuration interface
|
|
716
|
-
* - GuardrailResult - Result of guardrail processing
|
|
717
|
-
* - GuardrailMetrics - Analytics data
|
|
718
|
-
*/
|
|
719
|
-
export {
|
|
720
|
-
guardrailOutput,
|
|
721
|
-
truncateWithBoundaries,
|
|
722
|
-
createMetrics,
|
|
723
|
-
DEFAULT_GUARDRAIL_CONFIG,
|
|
724
|
-
type GuardrailConfig,
|
|
725
|
-
type GuardrailResult,
|
|
726
|
-
type GuardrailMetrics,
|
|
727
|
-
} from "./output-guardrails";
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Re-export compaction-hook module
|
|
731
|
-
*
|
|
732
|
-
* Includes:
|
|
733
|
-
* - SWARM_COMPACTION_CONTEXT - Prompt text for swarm state preservation
|
|
734
|
-
* - createCompactionHook - Factory function for the compaction hook
|
|
735
|
-
* - scanSessionMessages - Scan session for swarm state
|
|
736
|
-
* - ScannedSwarmState - Scanned state interface
|
|
737
|
-
*
|
|
738
|
-
* Usage:
|
|
739
|
-
* ```typescript
|
|
740
|
-
* import { createCompactionHook } from "opencode-swarm-plugin";
|
|
741
|
-
*
|
|
742
|
-
* const hooks = {
|
|
743
|
-
* "experimental.session.compacting": createCompactionHook(),
|
|
744
|
-
* };
|
|
745
|
-
* ```
|
|
746
|
-
*/
|
|
747
|
-
export {
|
|
748
|
-
SWARM_COMPACTION_CONTEXT,
|
|
749
|
-
createCompactionHook,
|
|
750
|
-
scanSessionMessages,
|
|
751
|
-
type ScannedSwarmState,
|
|
752
|
-
} from "./compaction-hook";
|
|
753
|
-
|
|
754
|
-
/**
|
|
755
|
-
* Re-export compaction-observability module
|
|
756
|
-
*
|
|
757
|
-
* Includes:
|
|
758
|
-
* - CompactionPhase - Enum of compaction phases
|
|
759
|
-
* - createMetricsCollector - Create a metrics collector
|
|
760
|
-
* - recordPhaseStart, recordPhaseComplete - Phase timing
|
|
761
|
-
* - recordPatternExtracted, recordPatternSkipped - Pattern tracking
|
|
762
|
-
* - getMetricsSummary - Get metrics summary
|
|
763
|
-
*
|
|
764
|
-
* Types:
|
|
765
|
-
* - CompactionMetrics - Mutable metrics collector
|
|
766
|
-
* - CompactionMetricsSummary - Read-only summary snapshot
|
|
767
|
-
*
|
|
768
|
-
* Features:
|
|
769
|
-
* - Phase timing breakdown (START, GATHER, DETECT, INJECT, COMPLETE)
|
|
770
|
-
* - Pattern extraction tracking with reasons
|
|
771
|
-
* - Success rate calculation
|
|
772
|
-
* - Debug mode for verbose details
|
|
773
|
-
* - JSON serializable for persistence
|
|
774
|
-
*
|
|
775
|
-
* Usage:
|
|
776
|
-
* ```typescript
|
|
777
|
-
* import { createMetricsCollector, CompactionPhase, recordPhaseStart } from "opencode-swarm-plugin";
|
|
778
|
-
*
|
|
779
|
-
* const metrics = createMetricsCollector({ session_id: "abc123" });
|
|
780
|
-
* recordPhaseStart(metrics, CompactionPhase.DETECT);
|
|
781
|
-
* // ... work ...
|
|
782
|
-
* recordPhaseComplete(metrics, CompactionPhase.DETECT);
|
|
783
|
-
* const summary = getMetricsSummary(metrics);
|
|
784
|
-
* ```
|
|
785
|
-
*/
|
|
786
|
-
export {
|
|
787
|
-
CompactionPhase,
|
|
788
|
-
createMetricsCollector,
|
|
789
|
-
recordPhaseStart,
|
|
790
|
-
recordPhaseComplete,
|
|
791
|
-
recordPatternExtracted,
|
|
792
|
-
recordPatternSkipped,
|
|
793
|
-
getMetricsSummary,
|
|
794
|
-
type CompactionMetrics,
|
|
795
|
-
type CompactionMetricsSummary,
|
|
796
|
-
} from "./compaction-observability";
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* Re-export memory module
|
|
800
|
-
*
|
|
801
|
-
* Includes:
|
|
802
|
-
* - memoryTools - All semantic-memory tools (store, find, get, remove, validate, list, stats, check)
|
|
803
|
-
* - createMemoryAdapter - Factory function for memory adapter
|
|
804
|
-
* - resetMemoryCache - Cache management for testing
|
|
805
|
-
*
|
|
806
|
-
* Types:
|
|
807
|
-
* - MemoryAdapter - Memory adapter interface
|
|
808
|
-
* - StoreArgs, FindArgs, IdArgs, ListArgs - Tool argument types
|
|
809
|
-
* - StoreResult, FindResult, StatsResult, HealthResult, OperationResult - Result types
|
|
810
|
-
*/
|
|
811
|
-
export {
|
|
812
|
-
memoryTools,
|
|
813
|
-
createMemoryAdapter,
|
|
814
|
-
resetMemoryCache,
|
|
815
|
-
type MemoryAdapter,
|
|
816
|
-
type StoreArgs,
|
|
817
|
-
type FindArgs,
|
|
818
|
-
type IdArgs,
|
|
819
|
-
type ListArgs,
|
|
820
|
-
type StoreResult,
|
|
821
|
-
type FindResult,
|
|
822
|
-
type StatsResult,
|
|
823
|
-
type HealthResult,
|
|
824
|
-
type OperationResult,
|
|
825
|
-
} from "./memory-tools";
|
|
826
|
-
export type { Memory, SearchResult, SearchOptions } from "swarm-mail";
|
|
827
|
-
|
|
828
|
-
/**
|
|
829
|
-
* Re-export eval-history module
|
|
830
|
-
*
|
|
831
|
-
* Includes:
|
|
832
|
-
* - recordEvalRun - Record eval run to JSONL history
|
|
833
|
-
* - getScoreHistory - Get score history for a specific eval
|
|
834
|
-
* - getPhase - Get current phase based on run count and variance
|
|
835
|
-
* - calculateVariance - Calculate statistical variance of scores
|
|
836
|
-
* - ensureEvalHistoryDir - Ensure history directory exists
|
|
837
|
-
* - getEvalHistoryPath - Get path to eval history file
|
|
838
|
-
*
|
|
839
|
-
* Constants:
|
|
840
|
-
* - DEFAULT_EVAL_HISTORY_PATH - Default path (.opencode/eval-history.jsonl)
|
|
841
|
-
* - VARIANCE_THRESHOLD - Variance threshold for production phase (0.1)
|
|
842
|
-
* - BOOTSTRAP_THRESHOLD - Run count for bootstrap phase (10)
|
|
843
|
-
* - STABILIZATION_THRESHOLD - Run count for stabilization phase (50)
|
|
844
|
-
*
|
|
845
|
-
* Types:
|
|
846
|
-
* - Phase - Progressive phases (bootstrap | stabilization | production)
|
|
847
|
-
* - EvalRunRecord - Single eval run record
|
|
848
|
-
*/
|
|
849
|
-
export {
|
|
850
|
-
recordEvalRun,
|
|
851
|
-
getScoreHistory,
|
|
852
|
-
getPhase,
|
|
853
|
-
calculateVariance,
|
|
854
|
-
ensureEvalHistoryDir,
|
|
855
|
-
getEvalHistoryPath,
|
|
856
|
-
DEFAULT_EVAL_HISTORY_PATH,
|
|
857
|
-
VARIANCE_THRESHOLD,
|
|
858
|
-
BOOTSTRAP_THRESHOLD,
|
|
859
|
-
STABILIZATION_THRESHOLD,
|
|
860
|
-
type Phase,
|
|
861
|
-
type EvalRunRecord,
|
|
862
|
-
} from "./eval-history";
|
|
863
|
-
|
|
864
|
-
/**
|
|
865
|
-
* Re-export eval-gates module
|
|
866
|
-
*
|
|
867
|
-
* Includes:
|
|
868
|
-
* - checkGate - Check if current score passes quality gate
|
|
869
|
-
* - DEFAULT_THRESHOLDS - Default regression thresholds by phase
|
|
870
|
-
*
|
|
871
|
-
* Types:
|
|
872
|
-
* - GateResult - Result from gate check
|
|
873
|
-
* - GateConfig - Configuration for gate thresholds
|
|
874
|
-
*
|
|
875
|
-
* Features:
|
|
876
|
-
* - Phase-based regression thresholds (Bootstrap: none, Stabilization: 10%, Production: 5%)
|
|
877
|
-
* - Configurable thresholds via GateConfig
|
|
878
|
-
* - Clear pass/fail messages with baseline comparison
|
|
879
|
-
* - Handles edge cases (division by zero, no history)
|
|
880
|
-
*/
|
|
881
|
-
export {
|
|
882
|
-
checkGate,
|
|
883
|
-
DEFAULT_THRESHOLDS,
|
|
884
|
-
type GateResult,
|
|
885
|
-
type GateConfig,
|
|
886
|
-
} from "./eval-gates";
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Re-export logger infrastructure
|
|
890
|
-
*
|
|
891
|
-
* Includes:
|
|
892
|
-
* - getLogger - Gets or creates the main logger instance
|
|
893
|
-
* - createChildLogger - Creates a module-specific child logger with separate log file
|
|
894
|
-
* - logger - Default logger instance for immediate use
|
|
895
|
-
*
|
|
896
|
-
* Features:
|
|
897
|
-
* - Daily log rotation via pino-roll (numeric format: swarm.1log, swarm.2log, etc.)
|
|
898
|
-
* - 14-day retention
|
|
899
|
-
* - Module-specific child loggers
|
|
900
|
-
* - Pretty mode for development (SWARM_LOG_PRETTY=1)
|
|
901
|
-
* - Logs to ~/.config/swarm-tools/logs/
|
|
902
|
-
*
|
|
903
|
-
* @example
|
|
904
|
-
* ```typescript
|
|
905
|
-
* import { logger, createChildLogger } from "opencode-swarm-plugin";
|
|
906
|
-
*
|
|
907
|
-
* // Use default logger
|
|
908
|
-
* logger.info("Application started");
|
|
909
|
-
*
|
|
910
|
-
* // Create module-specific logger
|
|
911
|
-
* const compactionLog = createChildLogger("compaction");
|
|
912
|
-
* compactionLog.info("Compaction started");
|
|
913
|
-
* ```
|
|
914
|
-
*/
|
|
915
|
-
export { getLogger, createChildLogger, logger } from "./logger";
|
|
916
|
-
|
|
917
|
-
/**
|
|
918
|
-
* Re-export swarm-research module
|
|
919
|
-
*
|
|
920
|
-
* Includes:
|
|
921
|
-
* - discoverDocTools - Discover available documentation tools
|
|
922
|
-
* - getInstalledVersions - Get installed package versions from lockfile
|
|
923
|
-
* - researchTools - Plugin tools for tool discovery and version detection
|
|
924
|
-
*
|
|
925
|
-
* Types:
|
|
926
|
-
* - DiscoveredTool - Tool discovery result interface
|
|
927
|
-
* - VersionInfo - Package version information
|
|
928
|
-
*/
|
|
929
|
-
export {
|
|
930
|
-
discoverDocTools,
|
|
931
|
-
getInstalledVersions,
|
|
932
|
-
researchTools,
|
|
933
|
-
type DiscoveredTool,
|
|
934
|
-
type VersionInfo,
|
|
935
|
-
} from "./swarm-research";
|