opencode-swarm-plugin 0.56.0 → 0.57.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/README.md +21 -0
- package/claude-plugin/.claude-plugin/plugin.json +1 -4
- package/claude-plugin/agents/background-worker.md +1 -0
- package/claude-plugin/agents/coordinator.md +1 -0
- package/claude-plugin/agents/worker.md +1 -0
- package/claude-plugin/bin/swarm-mcp-server.ts +47 -8
- package/claude-plugin/commands/hive.md +1 -1
- package/claude-plugin/commands/swarm.md +5 -1
- package/claude-plugin/dist/agent-mail.d.ts +480 -0
- package/claude-plugin/dist/agent-mail.d.ts.map +1 -0
- package/claude-plugin/dist/anti-patterns.d.ts +257 -0
- package/claude-plugin/dist/anti-patterns.d.ts.map +1 -0
- package/claude-plugin/dist/bin/swarm.js +373128 -0
- package/claude-plugin/dist/cass-tools.d.ts +74 -0
- package/claude-plugin/dist/cass-tools.d.ts.map +1 -0
- package/claude-plugin/dist/claude-plugin/claude-plugin-assets.d.ts +10 -0
- package/claude-plugin/dist/claude-plugin/claude-plugin-assets.d.ts.map +1 -0
- package/claude-plugin/dist/compaction-hook.d.ts +178 -0
- package/claude-plugin/dist/compaction-hook.d.ts.map +1 -0
- package/claude-plugin/dist/compaction-observability.d.ts +173 -0
- package/claude-plugin/dist/compaction-observability.d.ts.map +1 -0
- package/claude-plugin/dist/compaction-prompt-scoring.d.ts +125 -0
- package/claude-plugin/dist/compaction-prompt-scoring.d.ts.map +1 -0
- package/claude-plugin/dist/compaction-prompt-scoring.js +139 -0
- package/claude-plugin/dist/contributor-tools.d.ts +42 -0
- package/claude-plugin/dist/contributor-tools.d.ts.map +1 -0
- package/claude-plugin/dist/coordinator-guard.d.ts +79 -0
- package/claude-plugin/dist/coordinator-guard.d.ts.map +1 -0
- package/claude-plugin/dist/dashboard.d.ts +82 -0
- package/claude-plugin/dist/dashboard.d.ts.map +1 -0
- package/claude-plugin/dist/decision-trace-integration.d.ts +204 -0
- package/claude-plugin/dist/decision-trace-integration.d.ts.map +1 -0
- package/claude-plugin/dist/error-enrichment.d.ts +49 -0
- package/claude-plugin/dist/error-enrichment.d.ts.map +1 -0
- package/claude-plugin/dist/eval-capture.d.ts +494 -0
- package/claude-plugin/dist/eval-capture.d.ts.map +1 -0
- package/claude-plugin/dist/eval-capture.js +12844 -0
- package/claude-plugin/dist/eval-gates.d.ts +84 -0
- package/claude-plugin/dist/eval-gates.d.ts.map +1 -0
- package/claude-plugin/dist/eval-history.d.ts +117 -0
- package/claude-plugin/dist/eval-history.d.ts.map +1 -0
- package/claude-plugin/dist/eval-learning.d.ts +216 -0
- package/claude-plugin/dist/eval-learning.d.ts.map +1 -0
- package/claude-plugin/dist/eval-runner.d.ts +134 -0
- package/claude-plugin/dist/eval-runner.d.ts.map +1 -0
- package/claude-plugin/dist/examples/plugin-wrapper-template.ts +3341 -0
- package/claude-plugin/dist/export-tools.d.ts +76 -0
- package/claude-plugin/dist/export-tools.d.ts.map +1 -0
- package/claude-plugin/dist/hive.d.ts +949 -0
- package/claude-plugin/dist/hive.d.ts.map +1 -0
- package/claude-plugin/dist/hive.js +15009 -0
- package/claude-plugin/dist/hivemind-tools.d.ts +479 -0
- package/claude-plugin/dist/hivemind-tools.d.ts.map +1 -0
- package/claude-plugin/dist/hooks/atomic-write.d.ts +21 -0
- package/claude-plugin/dist/hooks/atomic-write.d.ts.map +1 -0
- package/claude-plugin/dist/hooks/constants.d.ts +28 -0
- package/claude-plugin/dist/hooks/constants.d.ts.map +1 -0
- package/claude-plugin/dist/hooks/index.d.ts +16 -0
- package/claude-plugin/dist/hooks/index.d.ts.map +1 -0
- package/claude-plugin/dist/hooks/session-start.d.ts +30 -0
- package/claude-plugin/dist/hooks/session-start.d.ts.map +1 -0
- package/claude-plugin/dist/hooks/tool-complete.d.ts +54 -0
- package/claude-plugin/dist/hooks/tool-complete.d.ts.map +1 -0
- package/claude-plugin/dist/index.d.ts +2017 -0
- package/claude-plugin/dist/index.d.ts.map +1 -0
- package/claude-plugin/dist/index.js +73453 -0
- package/claude-plugin/dist/learning.d.ts +700 -0
- package/claude-plugin/dist/learning.d.ts.map +1 -0
- package/claude-plugin/dist/logger.d.ts +38 -0
- package/claude-plugin/dist/logger.d.ts.map +1 -0
- package/claude-plugin/dist/mandate-promotion.d.ts +93 -0
- package/claude-plugin/dist/mandate-promotion.d.ts.map +1 -0
- package/claude-plugin/dist/mandate-storage.d.ts +209 -0
- package/claude-plugin/dist/mandate-storage.d.ts.map +1 -0
- package/claude-plugin/dist/mandates.d.ts +230 -0
- package/claude-plugin/dist/mandates.d.ts.map +1 -0
- package/claude-plugin/dist/memory-tools.d.ts +281 -0
- package/claude-plugin/dist/memory-tools.d.ts.map +1 -0
- package/claude-plugin/dist/memory.d.ts +164 -0
- package/claude-plugin/dist/memory.d.ts.map +1 -0
- package/claude-plugin/dist/model-selection.d.ts +37 -0
- package/claude-plugin/dist/model-selection.d.ts.map +1 -0
- package/claude-plugin/dist/observability-health.d.ts +87 -0
- package/claude-plugin/dist/observability-health.d.ts.map +1 -0
- package/claude-plugin/dist/observability-tools.d.ts +184 -0
- package/claude-plugin/dist/observability-tools.d.ts.map +1 -0
- package/claude-plugin/dist/output-guardrails.d.ts +125 -0
- package/claude-plugin/dist/output-guardrails.d.ts.map +1 -0
- package/claude-plugin/dist/pattern-maturity.d.ts +246 -0
- package/claude-plugin/dist/pattern-maturity.d.ts.map +1 -0
- package/claude-plugin/dist/planning-guardrails.d.ts +183 -0
- package/claude-plugin/dist/planning-guardrails.d.ts.map +1 -0
- package/claude-plugin/dist/plugin.d.ts +22 -0
- package/claude-plugin/dist/plugin.d.ts.map +1 -0
- package/claude-plugin/dist/plugin.js +72295 -0
- package/claude-plugin/dist/post-compaction-tracker.d.ts +133 -0
- package/claude-plugin/dist/post-compaction-tracker.d.ts.map +1 -0
- package/claude-plugin/dist/query-tools.d.ts +90 -0
- package/claude-plugin/dist/query-tools.d.ts.map +1 -0
- package/claude-plugin/dist/rate-limiter.d.ts +218 -0
- package/claude-plugin/dist/rate-limiter.d.ts.map +1 -0
- package/claude-plugin/dist/regression-detection.d.ts +58 -0
- package/claude-plugin/dist/regression-detection.d.ts.map +1 -0
- package/claude-plugin/dist/replay-tools.d.ts +28 -0
- package/claude-plugin/dist/replay-tools.d.ts.map +1 -0
- package/claude-plugin/dist/repo-crawl.d.ts +146 -0
- package/claude-plugin/dist/repo-crawl.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/cell-events.d.ts +1352 -0
- package/claude-plugin/dist/schemas/cell-events.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/cell.d.ts +413 -0
- package/claude-plugin/dist/schemas/cell.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/evaluation.d.ts +161 -0
- package/claude-plugin/dist/schemas/evaluation.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/index.d.ts +46 -0
- package/claude-plugin/dist/schemas/index.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/mandate.d.ts +336 -0
- package/claude-plugin/dist/schemas/mandate.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/swarm-context.d.ts +131 -0
- package/claude-plugin/dist/schemas/swarm-context.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/task.d.ts +189 -0
- package/claude-plugin/dist/schemas/task.d.ts.map +1 -0
- package/claude-plugin/dist/schemas/worker-handoff.d.ts +78 -0
- package/claude-plugin/dist/schemas/worker-handoff.d.ts.map +1 -0
- package/claude-plugin/dist/sessions/agent-discovery.d.ts +59 -0
- package/claude-plugin/dist/sessions/agent-discovery.d.ts.map +1 -0
- package/claude-plugin/dist/sessions/index.d.ts +10 -0
- package/claude-plugin/dist/sessions/index.d.ts.map +1 -0
- package/claude-plugin/dist/skills.d.ts +490 -0
- package/claude-plugin/dist/skills.d.ts.map +1 -0
- package/claude-plugin/dist/storage.d.ts +260 -0
- package/claude-plugin/dist/storage.d.ts.map +1 -0
- package/claude-plugin/dist/structured.d.ts +206 -0
- package/claude-plugin/dist/structured.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-adversarial-review.d.ts +104 -0
- package/claude-plugin/dist/swarm-adversarial-review.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-decompose.d.ts +297 -0
- package/claude-plugin/dist/swarm-decompose.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-insights.d.ts +390 -0
- package/claude-plugin/dist/swarm-insights.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-mail.d.ts +274 -0
- package/claude-plugin/dist/swarm-mail.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-orchestrate.d.ts +924 -0
- package/claude-plugin/dist/swarm-orchestrate.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-prompts.d.ts +467 -0
- package/claude-plugin/dist/swarm-prompts.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-prompts.js +45283 -0
- package/claude-plugin/dist/swarm-research.d.ts +125 -0
- package/claude-plugin/dist/swarm-research.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-review.d.ts +214 -0
- package/claude-plugin/dist/swarm-review.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-signature.d.ts +106 -0
- package/claude-plugin/dist/swarm-signature.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-strategies.d.ts +113 -0
- package/claude-plugin/dist/swarm-strategies.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-validation.d.ts +127 -0
- package/claude-plugin/dist/swarm-validation.d.ts.map +1 -0
- package/claude-plugin/dist/swarm-worktree.d.ts +185 -0
- package/claude-plugin/dist/swarm-worktree.d.ts.map +1 -0
- package/claude-plugin/dist/swarm.d.ts +590 -0
- package/claude-plugin/dist/swarm.d.ts.map +1 -0
- package/claude-plugin/dist/tool-availability.d.ts +91 -0
- package/claude-plugin/dist/tool-availability.d.ts.map +1 -0
- package/claude-plugin/dist/utils/tree-renderer.d.ts +61 -0
- package/claude-plugin/dist/utils/tree-renderer.d.ts.map +1 -0
- package/claude-plugin/dist/validators/index.d.ts +7 -0
- package/claude-plugin/dist/validators/index.d.ts.map +1 -0
- package/claude-plugin/dist/validators/schema-validator.d.ts +58 -0
- package/claude-plugin/dist/validators/schema-validator.d.ts.map +1 -0
- package/claude-plugin/skills/always-on-guidance/SKILL.md +44 -0
- package/dist/agent-mail.d.ts +4 -4
- package/dist/agent-mail.d.ts.map +1 -1
- package/dist/bin/swarm.js +477 -22
- package/dist/claude-plugin/claude-plugin-assets.d.ts +10 -0
- package/dist/claude-plugin/claude-plugin-assets.d.ts.map +1 -0
- package/dist/compaction-hook.d.ts +1 -1
- package/dist/compaction-hook.d.ts.map +1 -1
- package/dist/index.js +375 -265
- package/dist/plugin.js +374 -264
- package/dist/skills.d.ts +15 -0
- package/dist/skills.d.ts.map +1 -1
- package/dist/swarm-mail.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts +4 -2
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-prompts.js +84 -7
- package/global-skills/swarm-coordination/SKILL.md +21 -20
- package/package.json +2 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CASS Tools - Cross-Agent Session Search
|
|
3
|
+
*
|
|
4
|
+
* Provides tools for searching across AI coding agent histories.
|
|
5
|
+
* Uses inhouse SessionIndexer from swarm-mail package.
|
|
6
|
+
*
|
|
7
|
+
* Events emitted:
|
|
8
|
+
* - cass_searched: When a search is performed
|
|
9
|
+
* - cass_viewed: When a session is viewed
|
|
10
|
+
* - cass_indexed: When the index is built/rebuilt
|
|
11
|
+
*/
|
|
12
|
+
export declare const cassTools: {
|
|
13
|
+
cass_search: {
|
|
14
|
+
description: string;
|
|
15
|
+
args: {
|
|
16
|
+
query: import("zod").ZodString;
|
|
17
|
+
agent: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
|
+
days: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
19
|
+
limit: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
20
|
+
fields: import("zod").ZodOptional<import("zod").ZodString>;
|
|
21
|
+
};
|
|
22
|
+
execute(args: {
|
|
23
|
+
query: string;
|
|
24
|
+
agent?: string | undefined;
|
|
25
|
+
days?: number | undefined;
|
|
26
|
+
limit?: number | undefined;
|
|
27
|
+
fields?: string | undefined;
|
|
28
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
29
|
+
};
|
|
30
|
+
cass_view: {
|
|
31
|
+
description: string;
|
|
32
|
+
args: {
|
|
33
|
+
path: import("zod").ZodString;
|
|
34
|
+
line: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
35
|
+
};
|
|
36
|
+
execute(args: {
|
|
37
|
+
path: string;
|
|
38
|
+
line?: number | undefined;
|
|
39
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
40
|
+
};
|
|
41
|
+
cass_expand: {
|
|
42
|
+
description: string;
|
|
43
|
+
args: {
|
|
44
|
+
path: import("zod").ZodString;
|
|
45
|
+
line: import("zod").ZodNumber;
|
|
46
|
+
context: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
47
|
+
};
|
|
48
|
+
execute(args: {
|
|
49
|
+
path: string;
|
|
50
|
+
line: number;
|
|
51
|
+
context?: number | undefined;
|
|
52
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
53
|
+
};
|
|
54
|
+
cass_health: {
|
|
55
|
+
description: string;
|
|
56
|
+
args: {};
|
|
57
|
+
execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
58
|
+
};
|
|
59
|
+
cass_index: {
|
|
60
|
+
description: string;
|
|
61
|
+
args: {
|
|
62
|
+
full: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
63
|
+
};
|
|
64
|
+
execute(args: {
|
|
65
|
+
full?: boolean | undefined;
|
|
66
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
67
|
+
};
|
|
68
|
+
cass_stats: {
|
|
69
|
+
description: string;
|
|
70
|
+
args: {};
|
|
71
|
+
execute(args: Record<string, never>, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=cass-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cass-tools.d.ts","sourceRoot":"","sources":["../src/cass-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgaH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAOrB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ClaudePluginAssetCopyOptions = {
|
|
2
|
+
packageRoot: string;
|
|
3
|
+
distRoot?: string;
|
|
4
|
+
pluginRoot?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Copy compiled runtime assets into the Claude plugin root.
|
|
8
|
+
*/
|
|
9
|
+
export declare function copyClaudePluginRuntimeAssets({ packageRoot, distRoot, pluginRoot, }: ClaudePluginAssetCopyOptions): void;
|
|
10
|
+
//# sourceMappingURL=claude-plugin-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-plugin-assets.d.ts","sourceRoot":"","sources":["../../src/claude-plugin/claude-plugin-assets.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,QAAoC,EACpC,UAA+C,GAChD,EAAE,4BAA4B,GAAG,IAAI,CAgBrC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm-Aware Compaction Hook
|
|
3
|
+
*
|
|
4
|
+
* Provides context preservation during OpenCode session compaction.
|
|
5
|
+
* When context is compacted, this hook injects instructions for the summarizer
|
|
6
|
+
* to preserve swarm coordination state and enable seamless resumption.
|
|
7
|
+
*
|
|
8
|
+
* ## Philosophy: Err on the Side of Continuation
|
|
9
|
+
*
|
|
10
|
+
* It's better to inject swarm context unnecessarily than to lose an active swarm.
|
|
11
|
+
* The cost of a false positive (extra context) is low.
|
|
12
|
+
* The cost of a false negative (lost swarm) is high - wasted work, confused agents.
|
|
13
|
+
*
|
|
14
|
+
* Hook signature (from @opencode-ai/plugin):
|
|
15
|
+
* ```typescript
|
|
16
|
+
* "experimental.session.compacting"?: (
|
|
17
|
+
* input: { sessionID: string },
|
|
18
|
+
* output: { context: string[] }
|
|
19
|
+
* ) => Promise<void>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { SWARM_COMPACTION_CONTEXT, createCompactionHook } from "opencode-swarm-plugin";
|
|
25
|
+
*
|
|
26
|
+
* const hooks: Hooks = {
|
|
27
|
+
* "experimental.session.compacting": createCompactionHook(),
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Swarm-aware compaction context
|
|
33
|
+
*
|
|
34
|
+
* Injected during compaction to keep the swarm cooking. The coordinator should
|
|
35
|
+
* wake up from compaction and immediately resume orchestration - spawning agents,
|
|
36
|
+
* monitoring progress, unblocking work.
|
|
37
|
+
*
|
|
38
|
+
* This is NOT about preserving state for a human - it's about the swarm continuing
|
|
39
|
+
* autonomously after context compression.
|
|
40
|
+
*
|
|
41
|
+
* Structure optimized for eval scores:
|
|
42
|
+
* 1. ASCII header (visual anchor, coordinatorIdentity scorer)
|
|
43
|
+
* 2. What Good Looks Like (behavioral examples, outcome-focused)
|
|
44
|
+
* 3. Immediate actions (actionable tool calls, postCompactionDiscipline scorer)
|
|
45
|
+
* 4. Forbidden tools (explicit list, forbiddenToolsPresent scorer)
|
|
46
|
+
* 5. Mandatory behaviors (inbox, skills, review)
|
|
47
|
+
* 6. Role & mandates (strong language, coordinatorIdentity scorer)
|
|
48
|
+
* 7. Reference sections (supporting material)
|
|
49
|
+
*/
|
|
50
|
+
export declare const SWARM_COMPACTION_CONTEXT: string;
|
|
51
|
+
/**
|
|
52
|
+
* Fallback detection prompt - tells the compactor what to look for
|
|
53
|
+
*
|
|
54
|
+
* Used when we can't definitively detect a swarm but want to be safe.
|
|
55
|
+
* The compactor can check the conversation context for these patterns.
|
|
56
|
+
*/
|
|
57
|
+
export declare const SWARM_DETECTION_FALLBACK = "## \uD83D\uDC1D Swarm Detection - Check Your Context\n\n**IMPORTANT:** Before summarizing, check if this session involves an active swarm.\n\nLook for ANY of these patterns in the conversation:\n\n### Tool Calls (definite swarm sign)\n- `swarm_decompose`, `swarm_spawn_subtask`, `swarm_status`, `swarm_complete`\n- `swarmmail_init`, `swarmmail_reserve`, `swarmmail_send`\n- `hive_create_epic`, `hive_start`, `hive_close`\n\n### IDs and Names\n- Cell IDs: `bd-xxx`, `bd-xxx.N` (subtask format)\n- Agent names: BlueLake, RedMountain, GreenValley, etc.\n- Epic references: \"epic\", \"subtask\", \"parent\"\n\n### Coordination Language\n- \"spawn\", \"worker\", \"coordinator\"\n- \"reserve\", \"reservation\", \"files\"\n- \"blocked\", \"unblock\", \"dependency\"\n- \"progress\", \"complete\", \"in_progress\"\n\n### If You Find Swarm Evidence\n\nInclude this in your summary:\n1. Epic ID and title\n2. Project path\n3. Subtask status (running/blocked/done/pending)\n4. Any blockers or issues\n5. What should happen next\n\n**Then tell the resumed session:**\n\"This is an active swarm. Check swarm_status and swarmmail_inbox immediately.\"\n";
|
|
58
|
+
/**
|
|
59
|
+
* SDK Client type (minimal interface for scanSessionMessages)
|
|
60
|
+
*
|
|
61
|
+
* The actual SDK client uses a more complex Options-based API:
|
|
62
|
+
* client.session.messages({ path: { id: sessionID }, query: { limit } })
|
|
63
|
+
*
|
|
64
|
+
* We accept `unknown` and handle the type internally to avoid
|
|
65
|
+
* tight coupling to SDK internals.
|
|
66
|
+
*/
|
|
67
|
+
export type OpencodeClient = unknown;
|
|
68
|
+
/**
|
|
69
|
+
* Scanned swarm state extracted from session messages
|
|
70
|
+
*/
|
|
71
|
+
export interface ScannedSwarmState {
|
|
72
|
+
epicId?: string;
|
|
73
|
+
epicTitle?: string;
|
|
74
|
+
projectPath?: string;
|
|
75
|
+
agentName?: string;
|
|
76
|
+
subtasks: Map<string, {
|
|
77
|
+
title: string;
|
|
78
|
+
status: string;
|
|
79
|
+
worker?: string;
|
|
80
|
+
files?: string[];
|
|
81
|
+
}>;
|
|
82
|
+
lastAction?: {
|
|
83
|
+
tool: string;
|
|
84
|
+
args: unknown;
|
|
85
|
+
timestamp: number;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Scan session messages for swarm state using SDK client
|
|
90
|
+
*
|
|
91
|
+
* Extracts swarm coordination state from actual tool calls:
|
|
92
|
+
* - swarm_spawn_subtask → subtask tracking
|
|
93
|
+
* - swarmmail_init → agent name, project path
|
|
94
|
+
* - hive_create_epic → epic ID and title
|
|
95
|
+
* - swarm_status → epic reference
|
|
96
|
+
* - swarm_complete → subtask completion
|
|
97
|
+
*
|
|
98
|
+
* @param client - OpenCode SDK client (undefined if not available)
|
|
99
|
+
* @param sessionID - Session to scan
|
|
100
|
+
* @param limit - Max messages to fetch (default 100)
|
|
101
|
+
* @returns Extracted swarm state
|
|
102
|
+
*/
|
|
103
|
+
export declare function scanSessionMessages(client: OpencodeClient, sessionID: string, limit?: number): Promise<ScannedSwarmState>;
|
|
104
|
+
/**
|
|
105
|
+
* Options for creating a compaction hook with dependency injection
|
|
106
|
+
*/
|
|
107
|
+
export interface CompactionHookOptions {
|
|
108
|
+
/** Optional OpenCode SDK client for scanning session messages */
|
|
109
|
+
client?: OpencodeClient;
|
|
110
|
+
/** Custom getHiveAdapter function (for testing) */
|
|
111
|
+
getHiveAdapter?: (projectKey: string) => Promise<{
|
|
112
|
+
queryCells: (projectKey: string, filters: Record<string, unknown>) => Promise<Array<{
|
|
113
|
+
id: string;
|
|
114
|
+
title?: string;
|
|
115
|
+
type: string;
|
|
116
|
+
status: string;
|
|
117
|
+
parent_id: string | null;
|
|
118
|
+
updated_at: number;
|
|
119
|
+
}>>;
|
|
120
|
+
}>;
|
|
121
|
+
/** Custom checkSwarmHealth function (for testing) */
|
|
122
|
+
checkSwarmHealth?: (projectKey?: string) => Promise<{
|
|
123
|
+
healthy: boolean;
|
|
124
|
+
database: "connected" | "disconnected";
|
|
125
|
+
stats?: {
|
|
126
|
+
events: number;
|
|
127
|
+
agents: number;
|
|
128
|
+
messages: number;
|
|
129
|
+
reservations: number;
|
|
130
|
+
};
|
|
131
|
+
}>;
|
|
132
|
+
/** Custom getHiveWorkingDirectory function (for testing) */
|
|
133
|
+
getHiveWorkingDirectory?: () => string;
|
|
134
|
+
/** Custom logger instance (for testing) */
|
|
135
|
+
logger?: {
|
|
136
|
+
info: (data: unknown, message?: string) => void;
|
|
137
|
+
debug: (data: unknown, message?: string) => void;
|
|
138
|
+
warn: (data: unknown, message?: string) => void;
|
|
139
|
+
error: (data: unknown, message?: string) => void;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create the compaction hook for use in plugin registration
|
|
144
|
+
*
|
|
145
|
+
* Injects swarm context based on detection confidence:
|
|
146
|
+
* - HIGH/MEDIUM: Full swarm context (definitely/probably a swarm)
|
|
147
|
+
* - LOW: Fallback detection prompt (let compactor check context)
|
|
148
|
+
* - NONE: No injection (probably not a swarm)
|
|
149
|
+
*
|
|
150
|
+
* Philosophy: Err on the side of continuation. A false positive costs
|
|
151
|
+
* a bit of context space. A false negative loses the swarm.
|
|
152
|
+
*
|
|
153
|
+
* @param options - Configuration options including SDK client and dependency injection hooks
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* import { createCompactionHook } from "opencode-swarm-plugin";
|
|
158
|
+
*
|
|
159
|
+
* export const SwarmPlugin: Plugin = async (input) => ({
|
|
160
|
+
* tool: { ... },
|
|
161
|
+
* "experimental.session.compacting": createCompactionHook({ client: input.client }),
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example Testing with custom dependencies
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const hook = createCompactionHook({
|
|
168
|
+
* getHiveAdapter: async () => mockAdapter,
|
|
169
|
+
* checkSwarmHealth: async () => mockHealth,
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare function createCompactionHook(options?: OpencodeClient | CompactionHookOptions): (input: {
|
|
174
|
+
sessionID: string;
|
|
175
|
+
}, output: {
|
|
176
|
+
context: string[];
|
|
177
|
+
}) => Promise<void>;
|
|
178
|
+
//# sourceMappingURL=compaction-hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction-hook.d.ts","sourceRoot":"","sources":["../src/compaction-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA0CH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,wBAAwB,QAoPpC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,0nCAiCpC,CAAC;AA2FF;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,GAAG,CACX,MAAM,EACN;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CA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;IAC5D,uBAAuB,CAAC,EAAE,MAAM,MAAM,CAAC;IACvC,2CAA2C;IAC3C,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QAChD,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QACjD,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QAChD,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;KAClD,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,CAAC,EAAE,cAAc,GAAG,qBAAqB,IAwB9C,OAAO;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,EAC5B,QAAQ;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,KAC5B,OAAO,CAAC,IAAI,CAAC,CAgSjB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction Hook Observability
|
|
3
|
+
*
|
|
4
|
+
* Structured logging, metrics, and queryable history for the pre-compaction hook.
|
|
5
|
+
*
|
|
6
|
+
* **Philosophy:** Make the invisible visible. When patterns aren't extracted,
|
|
7
|
+
* when detection fails, when timing explodes - we need to know WHY.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const metrics = createMetricsCollector({ session_id: "abc123" });
|
|
12
|
+
*
|
|
13
|
+
* recordPhaseStart(metrics, CompactionPhase.DETECT);
|
|
14
|
+
* // ... detection logic ...
|
|
15
|
+
* recordPhaseComplete(metrics, CompactionPhase.DETECT, { confidence: "high" });
|
|
16
|
+
*
|
|
17
|
+
* recordPatternExtracted(metrics, "epic_state", "Found epic bd-123");
|
|
18
|
+
*
|
|
19
|
+
* const summary = getMetricsSummary(metrics);
|
|
20
|
+
* console.log(`Detected: ${summary.detected}, Confidence: ${summary.confidence}`);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Compaction phases - aligned with existing log structure
|
|
25
|
+
*
|
|
26
|
+
* From compaction-hook.ts:
|
|
27
|
+
* - START: session_id, trigger
|
|
28
|
+
* - GATHER: source (swarm-mail|hive), duration_ms, stats/counts
|
|
29
|
+
* - DETECT: confidence, detected, reason_count, reasons
|
|
30
|
+
* - INJECT: confidence, context_length, context_type (full|fallback|none)
|
|
31
|
+
* - COMPLETE: duration_ms, success, detected, confidence, context_injected
|
|
32
|
+
*/
|
|
33
|
+
export declare enum CompactionPhase {
|
|
34
|
+
START = "START",
|
|
35
|
+
GATHER_SWARM_MAIL = "GATHER_SWARM_MAIL",
|
|
36
|
+
GATHER_HIVE = "GATHER_HIVE",
|
|
37
|
+
DETECT = "DETECT",
|
|
38
|
+
INJECT = "INJECT",
|
|
39
|
+
COMPLETE = "COMPLETE"
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Phase timing and outcome
|
|
43
|
+
*/
|
|
44
|
+
interface PhaseMetrics {
|
|
45
|
+
duration_ms: number;
|
|
46
|
+
success: boolean;
|
|
47
|
+
error?: string;
|
|
48
|
+
/** Additional phase-specific data */
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Pattern extraction record
|
|
53
|
+
*/
|
|
54
|
+
interface PatternRecord {
|
|
55
|
+
pattern_type: string;
|
|
56
|
+
reason: string;
|
|
57
|
+
/** Debug details (only captured if debug mode enabled) */
|
|
58
|
+
details?: Record<string, unknown>;
|
|
59
|
+
timestamp: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Compaction metrics collector
|
|
63
|
+
*
|
|
64
|
+
* Mutable state object that accumulates metrics during a compaction run.
|
|
65
|
+
*/
|
|
66
|
+
export interface CompactionMetrics {
|
|
67
|
+
/** Session metadata */
|
|
68
|
+
session_id?: string;
|
|
69
|
+
has_sdk_client?: boolean;
|
|
70
|
+
debug?: boolean;
|
|
71
|
+
/** Phase timings */
|
|
72
|
+
phases: Map<CompactionPhase, {
|
|
73
|
+
start_time: number;
|
|
74
|
+
end_time?: number;
|
|
75
|
+
metadata?: Record<string, unknown>;
|
|
76
|
+
error?: string;
|
|
77
|
+
}>;
|
|
78
|
+
/** Pattern extraction tracking */
|
|
79
|
+
extracted: PatternRecord[];
|
|
80
|
+
skipped: PatternRecord[];
|
|
81
|
+
/** Final detection result */
|
|
82
|
+
confidence?: "high" | "medium" | "low" | "none";
|
|
83
|
+
detected?: boolean;
|
|
84
|
+
/** Overall timing */
|
|
85
|
+
start_time: number;
|
|
86
|
+
end_time?: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Metrics summary (read-only snapshot)
|
|
90
|
+
*/
|
|
91
|
+
export interface CompactionMetricsSummary {
|
|
92
|
+
session_id?: string;
|
|
93
|
+
has_sdk_client?: boolean;
|
|
94
|
+
/** Phase breakdown */
|
|
95
|
+
phases: Record<string, PhaseMetrics>;
|
|
96
|
+
/** Pattern extraction stats */
|
|
97
|
+
patterns_extracted: number;
|
|
98
|
+
patterns_skipped: number;
|
|
99
|
+
extraction_success_rate: number;
|
|
100
|
+
extracted_patterns: string[];
|
|
101
|
+
skipped_patterns: string[];
|
|
102
|
+
/** Detection outcome */
|
|
103
|
+
confidence?: "high" | "medium" | "low" | "none";
|
|
104
|
+
detected?: boolean;
|
|
105
|
+
/** Timing */
|
|
106
|
+
total_duration_ms: number;
|
|
107
|
+
/** Debug info (only if debug mode enabled) */
|
|
108
|
+
debug_info?: Array<{
|
|
109
|
+
phase: string;
|
|
110
|
+
pattern: string;
|
|
111
|
+
details: Record<string, unknown>;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a metrics collector
|
|
116
|
+
*
|
|
117
|
+
* @param metadata - Session metadata to capture
|
|
118
|
+
* @returns Mutable metrics collector
|
|
119
|
+
*/
|
|
120
|
+
export declare function createMetricsCollector(metadata?: {
|
|
121
|
+
session_id?: string;
|
|
122
|
+
has_sdk_client?: boolean;
|
|
123
|
+
debug?: boolean;
|
|
124
|
+
}): CompactionMetrics;
|
|
125
|
+
/**
|
|
126
|
+
* Record phase start
|
|
127
|
+
*
|
|
128
|
+
* @param metrics - Metrics collector
|
|
129
|
+
* @param phase - Phase being started
|
|
130
|
+
*/
|
|
131
|
+
export declare function recordPhaseStart(metrics: CompactionMetrics, phase: CompactionPhase): void;
|
|
132
|
+
/**
|
|
133
|
+
* Record phase completion
|
|
134
|
+
*
|
|
135
|
+
* @param metrics - Metrics collector
|
|
136
|
+
* @param phase - Phase being completed
|
|
137
|
+
* @param result - Phase outcome
|
|
138
|
+
*/
|
|
139
|
+
export declare function recordPhaseComplete(metrics: CompactionMetrics, phase: CompactionPhase, result?: {
|
|
140
|
+
success?: boolean;
|
|
141
|
+
error?: string;
|
|
142
|
+
confidence?: "high" | "medium" | "low" | "none";
|
|
143
|
+
detected?: boolean;
|
|
144
|
+
[key: string]: unknown;
|
|
145
|
+
}): void;
|
|
146
|
+
/**
|
|
147
|
+
* Record an extracted pattern
|
|
148
|
+
*
|
|
149
|
+
* @param metrics - Metrics collector
|
|
150
|
+
* @param pattern_type - Type of pattern extracted (e.g., "epic_state", "agent_name")
|
|
151
|
+
* @param reason - Human-readable reason for extraction
|
|
152
|
+
* @param details - Debug details (only captured if debug mode enabled)
|
|
153
|
+
*/
|
|
154
|
+
export declare function recordPatternExtracted(metrics: CompactionMetrics, pattern_type: string, reason: string, details?: Record<string, unknown>): void;
|
|
155
|
+
/**
|
|
156
|
+
* Record a skipped pattern
|
|
157
|
+
*
|
|
158
|
+
* @param metrics - Metrics collector
|
|
159
|
+
* @param pattern_type - Type of pattern that was skipped
|
|
160
|
+
* @param reason - Human-readable reason for skipping
|
|
161
|
+
*/
|
|
162
|
+
export declare function recordPatternSkipped(metrics: CompactionMetrics, pattern_type: string, reason: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* Get metrics summary (read-only snapshot)
|
|
165
|
+
*
|
|
166
|
+
* Computes derived metrics like success rates and total duration.
|
|
167
|
+
*
|
|
168
|
+
* @param metrics - Metrics collector
|
|
169
|
+
* @returns Immutable summary
|
|
170
|
+
*/
|
|
171
|
+
export declare function getMetricsSummary(metrics: CompactionMetrics): CompactionMetricsSummary;
|
|
172
|
+
export {};
|
|
173
|
+
//# sourceMappingURL=compaction-observability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction-observability.d.ts","sourceRoot":"","sources":["../src/compaction-observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;;;;;GASG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,iBAAiB,sBAAsB;IACvC,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,UAAU,YAAY;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,UAAU,aAAa;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACp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0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compaction Prompt Quality Scoring - Pure Functions
|
|
3
|
+
*
|
|
4
|
+
* Evaluates the quality of continuation prompts generated after context compaction.
|
|
5
|
+
* **Problem**: Post-compaction coordinators often "wake up" confused, forget their role,
|
|
6
|
+
* and start editing files instead of checking worker status.
|
|
7
|
+
*
|
|
8
|
+
* **Solution**: Score prompts on 5 dimensions that predict coordinator success:
|
|
9
|
+
*
|
|
10
|
+
* 1. **Epic ID Specificity (0.20)**: Real IDs (`mjkw...`) not placeholders (`<epic-id>`, `bd-xxx`)
|
|
11
|
+
* - Placeholders = coordinator can't check actual swarm status
|
|
12
|
+
*
|
|
13
|
+
* 2. **Actionability (0.20)**: Tool calls with real values (e.g., `swarm_status(epic_id='mjkw81rkq4c')`)
|
|
14
|
+
* - Generic instructions like "check status" don't work
|
|
15
|
+
*
|
|
16
|
+
* 3. **Coordinator Identity (0.25)**: ASCII header + strong mandates (NEVER/ALWAYS)
|
|
17
|
+
* - Visual + semantic cues reinforce role post-compaction
|
|
18
|
+
*
|
|
19
|
+
* 4. **Forbidden Tools Listed (0.15)**: Explicitly lists Edit, Write, swarmmail_reserve, git commit
|
|
20
|
+
* - Naming forbidden tools reduces violations
|
|
21
|
+
*
|
|
22
|
+
* 5. **Post-Compaction Discipline (0.20)**: First suggested tool is swarm_status or inbox (not Edit)
|
|
23
|
+
* - First tool sets the pattern - "check status" vs "dive into code"
|
|
24
|
+
*
|
|
25
|
+
* **Pure functions**: These can be tested without evalite. The evalite wrappers are in
|
|
26
|
+
* `evals/scorers/compaction-prompt-scorers.ts`.
|
|
27
|
+
*
|
|
28
|
+
* **Data source**: Captured from `captureCompactionEvent()` with `compaction_type: "prompt_generated"`.
|
|
29
|
+
* The payload includes the FULL prompt content (not truncated) for scoring.
|
|
30
|
+
*
|
|
31
|
+
* **Integration**: `compaction-prompt.eval.ts` uses these scorers to track prompt quality over time.
|
|
32
|
+
* Progressive gates enforce quality: bootstrap → stabilization → production.
|
|
33
|
+
*
|
|
34
|
+
* @module compaction-prompt-scoring
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Compaction prompt structure (from LLM generation)
|
|
38
|
+
*/
|
|
39
|
+
export interface CompactionPrompt {
|
|
40
|
+
content: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Scorer result type
|
|
44
|
+
*/
|
|
45
|
+
export interface ScorerResult {
|
|
46
|
+
score: number;
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
/** Matches real epic/cell IDs (mjkw prefix + 7+ base36 chars) */
|
|
50
|
+
export declare const REAL_EPIC_ID: RegExp;
|
|
51
|
+
/** Matches common placeholder patterns */
|
|
52
|
+
export declare const PLACEHOLDERS: RegExp[];
|
|
53
|
+
/** Matches ASCII box-drawing characters (for headers) */
|
|
54
|
+
export declare const ASCII_BOX: RegExp;
|
|
55
|
+
/** Matches strong mandate language */
|
|
56
|
+
export declare const STRONG_LANGUAGE: RegExp[];
|
|
57
|
+
/**
|
|
58
|
+
* Score epic ID specificity
|
|
59
|
+
*
|
|
60
|
+
* Validates that epic IDs are REAL, not placeholders.
|
|
61
|
+
* Placeholders like <epic-id>, bd-xxx, <path> indicate
|
|
62
|
+
* the prompt generator failed to inject actual values.
|
|
63
|
+
*
|
|
64
|
+
* @returns 1.0 if real IDs, 0.0 if placeholders found
|
|
65
|
+
*/
|
|
66
|
+
export declare function scoreEpicIdSpecificity(prompt: CompactionPrompt): ScorerResult;
|
|
67
|
+
/**
|
|
68
|
+
* Score actionability of tool calls
|
|
69
|
+
*
|
|
70
|
+
* Validates that the prompt includes SPECIFIC actionable tool calls.
|
|
71
|
+
* Generic instructions like "check status" are useless.
|
|
72
|
+
* Good: swarm_status(epic_id='mjkw81rkq4c', project_key='/path')
|
|
73
|
+
* Bad: "Check the status of workers"
|
|
74
|
+
*
|
|
75
|
+
* @returns 1.0 if actionable tool calls with real values, 0.0 otherwise
|
|
76
|
+
*/
|
|
77
|
+
export declare function scoreActionability(prompt: CompactionPrompt): ScorerResult;
|
|
78
|
+
/**
|
|
79
|
+
* Score coordinator identity reinforcement
|
|
80
|
+
*
|
|
81
|
+
* Validates that the prompt has STRONG coordinator identity reinforcement.
|
|
82
|
+
* Post-compaction coordinators lose their identity without visual+semantic cues.
|
|
83
|
+
*
|
|
84
|
+
* Checks:
|
|
85
|
+
* 1. ASCII box header (visual anchor)
|
|
86
|
+
* 2. Strong language (NEVER/ALWAYS, not "should"/"consider")
|
|
87
|
+
*
|
|
88
|
+
* @returns 1.0 for ASCII header + strong mandates, 0.5 for header only, 0.0 otherwise
|
|
89
|
+
*/
|
|
90
|
+
export declare function scoreCoordinatorIdentity(prompt: CompactionPrompt): ScorerResult;
|
|
91
|
+
/**
|
|
92
|
+
* Score forbidden tools listing
|
|
93
|
+
*
|
|
94
|
+
* Validates that the prompt LISTS forbidden tools by name.
|
|
95
|
+
* Coordinators must know exactly which tools to avoid.
|
|
96
|
+
*
|
|
97
|
+
* Required forbidden tools:
|
|
98
|
+
* 1. Edit
|
|
99
|
+
* 2. Write
|
|
100
|
+
* 3. swarmmail_reserve (only workers reserve)
|
|
101
|
+
* 4. git commit (workers commit)
|
|
102
|
+
* 5. bash (for file modifications)
|
|
103
|
+
*
|
|
104
|
+
* @returns ratio of forbidden tools mentioned (0.0 to 1.0)
|
|
105
|
+
*/
|
|
106
|
+
export declare function scoreForbiddenToolsPresent(prompt: CompactionPrompt): ScorerResult;
|
|
107
|
+
/**
|
|
108
|
+
* Score post-compaction discipline (first tool correctness)
|
|
109
|
+
*
|
|
110
|
+
* Validates that the FIRST suggested tool is correct.
|
|
111
|
+
* Coordinators should check status FIRST, not edit files.
|
|
112
|
+
*
|
|
113
|
+
* Good first tools:
|
|
114
|
+
* - swarm_status
|
|
115
|
+
* - swarmmail_inbox
|
|
116
|
+
*
|
|
117
|
+
* Bad first tools:
|
|
118
|
+
* - Edit
|
|
119
|
+
* - Write
|
|
120
|
+
* - Read (should check status first)
|
|
121
|
+
*
|
|
122
|
+
* @returns 1.0 if first tool is swarm_status or inbox, 0.0 otherwise
|
|
123
|
+
*/
|
|
124
|
+
export declare function scorePostCompactionDiscipline(prompt: CompactionPrompt): ScorerResult;
|
|
125
|
+
//# sourceMappingURL=compaction-prompt-scoring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction-prompt-scoring.d.ts","sourceRoot":"","sources":["../src/compaction-prompt-scoring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB;AAID,iEAAiE;AACjE,eAAO,MAAM,YAAY,QAAqB,CAAC;AAE/C,0CAA0C;AAC1C,eAAO,MAAM,YAAY,UAKxB,CAAC;AAEF,yDAAyD;AACzD,eAAO,MAAM,SAAS,QAAiB,CAAC;AAExC,sCAAsC;AACtC,eAAO,MAAM,eAAe,UAAoD,CAAC;AAIjF;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,CAuB7E;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,CA+BzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,gBAAgB,GACtB,YAAY,CA6Bd;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,gBAAgB,GACtB,YAAY,CAkCd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,gBAAgB,GACtB,YAAY,CAiCd"}
|