monomind 1.11.12 → 1.11.13

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.
Files changed (222) hide show
  1. package/.claude/commands/mastermind/idea.md +1 -1
  2. package/.claude/commands/mastermind/master.md +1 -1
  3. package/.claude/skills/mastermind/_protocol.md +4 -4
  4. package/.claude/skills/mastermind/build.md +3 -3
  5. package/.claude/skills/mastermind/content.md +3 -3
  6. package/.claude/skills/mastermind/createorg.md +2 -2
  7. package/.claude/skills/mastermind/finance.md +3 -3
  8. package/.claude/skills/mastermind/marketing.md +3 -3
  9. package/.claude/skills/mastermind/ops.md +3 -3
  10. package/.claude/skills/mastermind/release.md +3 -3
  11. package/.claude/skills/mastermind/research.md +3 -3
  12. package/.claude/skills/mastermind/review.md +3 -3
  13. package/.claude/skills/mastermind/sales.md +3 -3
  14. package/package.json +1 -1
  15. package/packages/@monomind/cli/dist/src/init/statusline-generator.js +3 -3
  16. package/packages/@monomind/cli/dist/src/observability/replay-reader.d.ts +1 -1
  17. package/packages/@monomind/cli/dist/src/update/checker.js +24 -7
  18. package/packages/@monomind/cli/dist/src/update/index.js +3 -6
  19. package/packages/@monomind/cli/package.json +1 -1
  20. package/packages/@monomind/cli/dist/src/agents/halt-signal.d.ts +0 -25
  21. package/packages/@monomind/cli/dist/src/agents/halt-signal.js +0 -76
  22. package/packages/@monomind/cli/dist/src/agents/index.d.ts +0 -18
  23. package/packages/@monomind/cli/dist/src/agents/index.js +0 -13
  24. package/packages/@monomind/cli/dist/src/agents/managed-agent.d.ts +0 -41
  25. package/packages/@monomind/cli/dist/src/agents/managed-agent.js +0 -69
  26. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.d.ts +0 -23
  27. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.js +0 -49
  28. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.d.ts +0 -22
  29. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.js +0 -80
  30. package/packages/@monomind/cli/dist/src/agents/registry-query.d.ts +0 -71
  31. package/packages/@monomind/cli/dist/src/agents/registry-query.js +0 -125
  32. package/packages/@monomind/cli/dist/src/agents/score-decay.d.ts +0 -19
  33. package/packages/@monomind/cli/dist/src/agents/score-decay.js +0 -22
  34. package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.d.ts +0 -13
  35. package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.js +0 -40
  36. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.d.ts +0 -54
  37. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.js +0 -212
  38. package/packages/@monomind/cli/dist/src/agents/termination-watcher.d.ts +0 -30
  39. package/packages/@monomind/cli/dist/src/agents/termination-watcher.js +0 -84
  40. package/packages/@monomind/cli/dist/src/agents/trigger-index.d.ts +0 -20
  41. package/packages/@monomind/cli/dist/src/agents/trigger-index.js +0 -38
  42. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.d.ts +0 -64
  43. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.js +0 -308
  44. package/packages/@monomind/cli/dist/src/agents/version-diff.d.ts +0 -18
  45. package/packages/@monomind/cli/dist/src/agents/version-diff.js +0 -64
  46. package/packages/@monomind/cli/dist/src/agents/version-store.d.ts +0 -60
  47. package/packages/@monomind/cli/dist/src/agents/version-store.js +0 -235
  48. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +0 -45
  49. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.js +0 -404
  50. package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +0 -14
  51. package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +0 -333
  52. package/packages/@monomind/cli/dist/src/commands/ui.js +0 -68
  53. package/packages/@monomind/cli/dist/src/consensus/index.d.ts +0 -7
  54. package/packages/@monomind/cli/dist/src/consensus/index.js +0 -6
  55. package/packages/@monomind/cli/dist/src/context/context-provider.d.ts +0 -44
  56. package/packages/@monomind/cli/dist/src/context/context-provider.js +0 -25
  57. package/packages/@monomind/cli/dist/src/context/git-state-provider.d.ts +0 -12
  58. package/packages/@monomind/cli/dist/src/context/git-state-provider.js +0 -34
  59. package/packages/@monomind/cli/dist/src/context/index.d.ts +0 -12
  60. package/packages/@monomind/cli/dist/src/context/index.js +0 -12
  61. package/packages/@monomind/cli/dist/src/context/project-conventions-provider.d.ts +0 -15
  62. package/packages/@monomind/cli/dist/src/context/project-conventions-provider.js +0 -19
  63. package/packages/@monomind/cli/dist/src/context/prompt-assembler.d.ts +0 -26
  64. package/packages/@monomind/cli/dist/src/context/prompt-assembler.js +0 -93
  65. package/packages/@monomind/cli/dist/src/context/task-history-provider.d.ts +0 -24
  66. package/packages/@monomind/cli/dist/src/context/task-history-provider.js +0 -32
  67. package/packages/@monomind/cli/dist/src/context/user-preferences-provider.d.ts +0 -14
  68. package/packages/@monomind/cli/dist/src/context/user-preferences-provider.js +0 -27
  69. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.d.ts +0 -31
  70. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.js +0 -81
  71. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.d.ts +0 -24
  72. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.js +0 -65
  73. package/packages/@monomind/cli/dist/src/dlq/index.d.ts +0 -10
  74. package/packages/@monomind/cli/dist/src/dlq/index.js +0 -7
  75. package/packages/@monomind/cli/dist/src/eval/dataset-manager.d.ts +0 -33
  76. package/packages/@monomind/cli/dist/src/eval/dataset-manager.js +0 -107
  77. package/packages/@monomind/cli/dist/src/eval/dataset-runner.d.ts +0 -23
  78. package/packages/@monomind/cli/dist/src/eval/dataset-runner.js +0 -59
  79. package/packages/@monomind/cli/dist/src/eval/index.d.ts +0 -10
  80. package/packages/@monomind/cli/dist/src/eval/index.js +0 -7
  81. package/packages/@monomind/cli/dist/src/eval/trace-collector.d.ts +0 -40
  82. package/packages/@monomind/cli/dist/src/eval/trace-collector.js +0 -102
  83. package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.d.ts +0 -68
  84. package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.js +0 -264
  85. package/packages/@monomind/cli/dist/src/interactive/interrupt.d.ts +0 -22
  86. package/packages/@monomind/cli/dist/src/interactive/interrupt.js +0 -71
  87. package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.d.ts +0 -25
  88. package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.js +0 -48
  89. package/packages/@monomind/cli/dist/src/mcp/tool-registry.d.ts +0 -61
  90. package/packages/@monomind/cli/dist/src/mcp/tool-registry.js +0 -246
  91. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +0 -9
  92. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +0 -230
  93. package/packages/@monomind/cli/dist/src/model/complexity-scorer.d.ts +0 -21
  94. package/packages/@monomind/cli/dist/src/model/complexity-scorer.js +0 -106
  95. package/packages/@monomind/cli/dist/src/model/index.d.ts +0 -4
  96. package/packages/@monomind/cli/dist/src/model/index.js +0 -4
  97. package/packages/@monomind/cli/dist/src/model/model-settings.d.ts +0 -22
  98. package/packages/@monomind/cli/dist/src/model/model-settings.js +0 -33
  99. package/packages/@monomind/cli/dist/src/model/model-tier-resolver.d.ts +0 -24
  100. package/packages/@monomind/cli/dist/src/model/model-tier-resolver.js +0 -65
  101. package/packages/@monomind/cli/dist/src/monovector/capabilities.d.ts +0 -34
  102. package/packages/@monomind/cli/dist/src/monovector/capabilities.js +0 -37
  103. package/packages/@monomind/cli/dist/src/orchestration/index.d.ts +0 -7
  104. package/packages/@monomind/cli/dist/src/orchestration/index.js +0 -6
  105. package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.d.ts +0 -11
  106. package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.js +0 -31
  107. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.d.ts +0 -68
  108. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.js +0 -180
  109. package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +0 -7
  110. package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.js +0 -126
  111. package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.d.ts +0 -12
  112. package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.js +0 -188
  113. package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.d.ts +0 -7
  114. package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.js +0 -206
  115. package/packages/@monomind/cli/dist/src/runtime/headless.d.ts +0 -60
  116. package/packages/@monomind/cli/dist/src/runtime/headless.js +0 -284
  117. package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.d.ts +0 -50
  118. package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.js +0 -95
  119. package/packages/@monomind/cli/dist/src/services/container-worker-pool.d.ts +0 -197
  120. package/packages/@monomind/cli/dist/src/services/container-worker-pool.js +0 -623
  121. package/packages/@monomind/cli/dist/src/services/index.d.ts +0 -13
  122. package/packages/@monomind/cli/dist/src/services/index.js +0 -11
  123. package/packages/@monomind/cli/dist/src/services/worker-queue.d.ts +0 -201
  124. package/packages/@monomind/cli/dist/src/services/worker-queue.js +0 -594
  125. package/packages/@monomind/cli/dist/src/swarm/communication-graph.d.ts +0 -25
  126. package/packages/@monomind/cli/dist/src/swarm/communication-graph.js +0 -77
  127. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.d.ts +0 -31
  128. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.js +0 -61
  129. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.d.ts +0 -19
  130. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.js +0 -68
  131. package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.d.ts +0 -13
  132. package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.js +0 -205
  133. package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.d.ts +0 -12
  134. package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.js +0 -190
  135. package/packages/@monomind/cli/dist/src/transfer/test-seraphine.d.ts +0 -6
  136. package/packages/@monomind/cli/dist/src/transfer/test-seraphine.js +0 -105
  137. package/packages/@monomind/cli/dist/src/transfer/tests/test-store.d.ts +0 -7
  138. package/packages/@monomind/cli/dist/src/transfer/tests/test-store.js +0 -214
  139. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.d.ts +0 -10
  140. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.js +0 -82
  141. package/packages/@monomind/cli/dist/src/workflow/context-resolver.d.ts +0 -12
  142. package/packages/@monomind/cli/dist/src/workflow/context-resolver.js +0 -23
  143. package/packages/@monomind/cli/dist/src/workflow/dag-builder.d.ts +0 -17
  144. package/packages/@monomind/cli/dist/src/workflow/dag-builder.js +0 -129
  145. package/packages/@monomind/cli/dist/src/workflow/dag-executor.d.ts +0 -9
  146. package/packages/@monomind/cli/dist/src/workflow/dag-executor.js +0 -116
  147. package/packages/@monomind/cli/dist/src/workflow/dag-types.d.ts +0 -41
  148. package/packages/@monomind/cli/dist/src/workflow/dag-types.js +0 -8
  149. package/packages/@monomind/cli/dist/src/workflow/dsl-parser.d.ts +0 -12
  150. package/packages/@monomind/cli/dist/src/workflow/dsl-parser.js +0 -20
  151. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.d.ts +0 -165
  152. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.js +0 -82
  153. package/packages/@monomind/cli/dist/src/workflow/index.d.ts +0 -13
  154. package/packages/@monomind/cli/dist/src/workflow/index.js +0 -11
  155. package/packages/@monomind/cli/dist/src/workflow/template-engine.d.ts +0 -11
  156. package/packages/@monomind/cli/dist/src/workflow/template-engine.js +0 -40
  157. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.d.ts +0 -29
  158. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.js +0 -227
  159. package/packages/@monomind/guidance/dist/adversarial.d.ts +0 -284
  160. package/packages/@monomind/guidance/dist/adversarial.js +0 -572
  161. package/packages/@monomind/guidance/dist/analyzer.d.ts +0 -530
  162. package/packages/@monomind/guidance/dist/analyzer.js +0 -2518
  163. package/packages/@monomind/guidance/dist/artifacts.d.ts +0 -283
  164. package/packages/@monomind/guidance/dist/artifacts.js +0 -356
  165. package/packages/@monomind/guidance/dist/authority.d.ts +0 -290
  166. package/packages/@monomind/guidance/dist/authority.js +0 -558
  167. package/packages/@monomind/guidance/dist/capabilities.d.ts +0 -209
  168. package/packages/@monomind/guidance/dist/capabilities.js +0 -485
  169. package/packages/@monomind/guidance/dist/coherence.d.ts +0 -233
  170. package/packages/@monomind/guidance/dist/coherence.js +0 -372
  171. package/packages/@monomind/guidance/dist/compiler.d.ts +0 -87
  172. package/packages/@monomind/guidance/dist/compiler.js +0 -419
  173. package/packages/@monomind/guidance/dist/conformance-kit.d.ts +0 -225
  174. package/packages/@monomind/guidance/dist/conformance-kit.js +0 -629
  175. package/packages/@monomind/guidance/dist/continue-gate.d.ts +0 -214
  176. package/packages/@monomind/guidance/dist/continue-gate.js +0 -353
  177. package/packages/@monomind/guidance/dist/crypto-utils.d.ts +0 -17
  178. package/packages/@monomind/guidance/dist/crypto-utils.js +0 -24
  179. package/packages/@monomind/guidance/dist/evolution.d.ts +0 -282
  180. package/packages/@monomind/guidance/dist/evolution.js +0 -500
  181. package/packages/@monomind/guidance/dist/gates.d.ts +0 -79
  182. package/packages/@monomind/guidance/dist/gates.js +0 -302
  183. package/packages/@monomind/guidance/dist/gateway.d.ts +0 -206
  184. package/packages/@monomind/guidance/dist/gateway.js +0 -452
  185. package/packages/@monomind/guidance/dist/generators.d.ts +0 -153
  186. package/packages/@monomind/guidance/dist/generators.js +0 -682
  187. package/packages/@monomind/guidance/dist/headless.d.ts +0 -177
  188. package/packages/@monomind/guidance/dist/headless.js +0 -342
  189. package/packages/@monomind/guidance/dist/hooks.d.ts +0 -109
  190. package/packages/@monomind/guidance/dist/hooks.js +0 -347
  191. package/packages/@monomind/guidance/dist/index.d.ts +0 -205
  192. package/packages/@monomind/guidance/dist/index.js +0 -321
  193. package/packages/@monomind/guidance/dist/ledger.d.ts +0 -162
  194. package/packages/@monomind/guidance/dist/ledger.js +0 -375
  195. package/packages/@monomind/guidance/dist/manifest-validator.d.ts +0 -289
  196. package/packages/@monomind/guidance/dist/manifest-validator.js +0 -838
  197. package/packages/@monomind/guidance/dist/memory-gate.d.ts +0 -222
  198. package/packages/@monomind/guidance/dist/memory-gate.js +0 -382
  199. package/packages/@monomind/guidance/dist/meta-governance.d.ts +0 -265
  200. package/packages/@monomind/guidance/dist/meta-governance.js +0 -348
  201. package/packages/@monomind/guidance/dist/optimizer.d.ts +0 -104
  202. package/packages/@monomind/guidance/dist/optimizer.js +0 -329
  203. package/packages/@monomind/guidance/dist/persistence.d.ts +0 -189
  204. package/packages/@monomind/guidance/dist/persistence.js +0 -464
  205. package/packages/@monomind/guidance/dist/proof.d.ts +0 -185
  206. package/packages/@monomind/guidance/dist/proof.js +0 -238
  207. package/packages/@monomind/guidance/dist/retriever.d.ts +0 -116
  208. package/packages/@monomind/guidance/dist/retriever.js +0 -394
  209. package/packages/@monomind/guidance/dist/ruvbot-integration.d.ts +0 -370
  210. package/packages/@monomind/guidance/dist/ruvbot-integration.js +0 -738
  211. package/packages/@monomind/guidance/dist/temporal.d.ts +0 -426
  212. package/packages/@monomind/guidance/dist/temporal.js +0 -658
  213. package/packages/@monomind/guidance/dist/trust.d.ts +0 -283
  214. package/packages/@monomind/guidance/dist/trust.js +0 -473
  215. package/packages/@monomind/guidance/dist/truth-anchors.d.ts +0 -276
  216. package/packages/@monomind/guidance/dist/truth-anchors.js +0 -488
  217. package/packages/@monomind/guidance/dist/types.d.ts +0 -378
  218. package/packages/@monomind/guidance/dist/types.js +0 -10
  219. package/packages/@monomind/guidance/dist/uncertainty.d.ts +0 -372
  220. package/packages/@monomind/guidance/dist/uncertainty.js +0 -619
  221. package/packages/@monomind/guidance/dist/wasm-kernel.d.ts +0 -48
  222. package/packages/@monomind/guidance/dist/wasm-kernel.js +0 -158
@@ -1,212 +0,0 @@
1
- /**
2
- * Agent Specialization Scorer (Task 39)
3
- *
4
- * JSONL-based per-agent-per-task-type scoring with time-decay.
5
- * Enables monomind to prefer historically successful agents for specific task types.
6
- */
7
- import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, statSync } from 'fs';
8
- import { randomBytes } from 'crypto';
9
- import { dirname } from 'path';
10
- import { calculateDecayFactor } from './score-decay.js';
11
- import { parseJsonl } from '../utils/parse-jsonl.js';
12
- /** Key used to identify a unique agent+taskType pair in the JSONL store. */
13
- function scoreKey(agentSlug, taskType) {
14
- return `${agentSlug}::${taskType}`;
15
- }
16
- /**
17
- * JSONL-based specialization scorer.
18
- *
19
- * Stores one JSON object per line in the configured file path.
20
- * Each line represents a SpecializationScore for a unique agent+taskType pair.
21
- * On update, the entire file is rewritten to maintain a single record per pair.
22
- */
23
- export class SpecializationScorer {
24
- filePath;
25
- constructor(filePath) {
26
- this.filePath = filePath;
27
- const dir = dirname(filePath);
28
- if (!existsSync(dir)) {
29
- mkdirSync(dir, { recursive: true });
30
- }
31
- }
32
- // ---------------------------------------------------------------------------
33
- // Persistence helpers
34
- // ---------------------------------------------------------------------------
35
- readAll() {
36
- if (!existsSync(this.filePath)) {
37
- return [];
38
- }
39
- // 10MB cap. readAll is on the routing hot path; without this cap a
40
- // bloated scorer file (planted or grown via repeated recordOutcome calls
41
- // with diverse agentSlug::taskType keys) crashes the CLI on every route.
42
- const stat = statSync(this.filePath);
43
- if (stat.size > 10 * 1024 * 1024) {
44
- throw new Error('Scorer store exceeds 10MB; run compaction');
45
- }
46
- const raw = readFileSync(this.filePath, 'utf-8');
47
- return parseJsonl(raw).filter((r) => r !== null && typeof r === 'object' && !Array.isArray(r) &&
48
- Object.getPrototypeOf(r) === Object.prototype);
49
- }
50
- writeAll(records) {
51
- const lines = records.map((r) => JSON.stringify(r));
52
- // Unique tmp filename so concurrent recordOutcome calls don't collide.
53
- const tmp = `${this.filePath}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`;
54
- writeFileSync(tmp, lines.join('\n') + '\n', 'utf-8');
55
- renameSync(tmp, this.filePath);
56
- }
57
- // ---------------------------------------------------------------------------
58
- // Public API
59
- // ---------------------------------------------------------------------------
60
- /**
61
- * Record an outcome for a given agent+taskType pair.
62
- *
63
- * Updates running averages for latency and quality, recalculates
64
- * successRate, applies time-decay, and persists the result.
65
- */
66
- recordOutcome(update) {
67
- const records = this.readAll();
68
- const key = scoreKey(update.agentSlug, update.taskType);
69
- let idx = records.findIndex((r) => scoreKey(r.agentSlug, r.taskType) === key);
70
- const now = new Date().toISOString();
71
- if (idx === -1) {
72
- // Create new record
73
- const score = {
74
- agentSlug: update.agentSlug,
75
- taskType: update.taskType,
76
- successCount: update.success ? 1 : 0,
77
- failureCount: update.success ? 0 : 1,
78
- totalCount: 1,
79
- successRate: update.success ? 1.0 : 0.0,
80
- avgLatencyMs: update.latencyMs,
81
- avgQualityScore: update.qualityScore ?? (update.success ? 1.0 : 0.0),
82
- lastUpdated: now,
83
- decayFactor: 1.0,
84
- effectiveScore: update.success ? 1.0 : 0.0,
85
- };
86
- records.push(score);
87
- this.writeAll(records);
88
- return score;
89
- }
90
- // Update existing record
91
- const existing = records[idx];
92
- const newTotal = existing.totalCount + 1;
93
- const newSuccess = existing.successCount + (update.success ? 1 : 0);
94
- const newFailure = existing.failureCount + (update.success ? 0 : 1);
95
- const newRate = newSuccess / newTotal;
96
- // Running average for latency
97
- const newAvgLatency = (existing.avgLatencyMs * existing.totalCount + update.latencyMs) /
98
- newTotal;
99
- // Running average for quality
100
- const quality = update.qualityScore ?? (update.success ? 1.0 : 0.0);
101
- const newAvgQuality = (existing.avgQualityScore * existing.totalCount + quality) / newTotal;
102
- const decay = calculateDecayFactor(now);
103
- const updated = {
104
- agentSlug: update.agentSlug,
105
- taskType: update.taskType,
106
- successCount: newSuccess,
107
- failureCount: newFailure,
108
- totalCount: newTotal,
109
- successRate: newRate,
110
- avgLatencyMs: newAvgLatency,
111
- avgQualityScore: newAvgQuality,
112
- lastUpdated: now,
113
- decayFactor: decay,
114
- effectiveScore: newRate * decay,
115
- };
116
- records[idx] = updated;
117
- this.writeAll(records);
118
- return updated;
119
- }
120
- /**
121
- * Get the score for a specific agent+taskType pair, or null if not found.
122
- * Recalculates decay on read.
123
- */
124
- getScore(agentSlug, taskType) {
125
- const records = this.readAll();
126
- const key = scoreKey(agentSlug, taskType);
127
- const record = records.find((r) => scoreKey(r.agentSlug, r.taskType) === key);
128
- if (!record)
129
- return null;
130
- // Recalculate decay on read
131
- const decay = calculateDecayFactor(record.lastUpdated);
132
- return {
133
- ...record,
134
- decayFactor: decay,
135
- effectiveScore: record.successRate * decay,
136
- };
137
- }
138
- /**
139
- * Get top N candidates for a task type from the given list of slugs,
140
- * sorted by effectiveScore descending.
141
- */
142
- getTopCandidates(taskType, slugs, topN = 3) {
143
- const scored = [];
144
- for (const slug of slugs) {
145
- const score = this.getScore(slug, taskType);
146
- if (score) {
147
- scored.push(score);
148
- }
149
- }
150
- return scored
151
- .sort((a, b) => b.effectiveScore - a.effectiveScore)
152
- .slice(0, topN);
153
- }
154
- /**
155
- * Return the best candidate slug for a task type.
156
- * Falls back to the first candidate if no scores exist.
157
- */
158
- topCandidate(taskType, candidates) {
159
- if (candidates.length === 0) {
160
- throw new Error('candidates array must not be empty');
161
- }
162
- const top = this.getTopCandidates(taskType, candidates, 1);
163
- if (top.length === 0) {
164
- return candidates[0];
165
- }
166
- return top[0].agentSlug;
167
- }
168
- /**
169
- * Get all scores for a given agent across all task types.
170
- */
171
- getAllScores(agentSlug) {
172
- const records = this.readAll();
173
- return records
174
- .filter((r) => r.agentSlug === agentSlug)
175
- .map((r) => {
176
- const decay = calculateDecayFactor(r.lastUpdated);
177
- return {
178
- ...r,
179
- decayFactor: decay,
180
- effectiveScore: r.successRate * decay,
181
- };
182
- });
183
- }
184
- /**
185
- * Reset scores for an agent. If taskType is provided, only that
186
- * pair is removed; otherwise all scores for the agent are removed.
187
- *
188
- * @returns The number of records deleted.
189
- */
190
- resetScores(agentSlug, taskType) {
191
- const records = this.readAll();
192
- const before = records.length;
193
- const remaining = records.filter((r) => {
194
- if (r.agentSlug !== agentSlug)
195
- return true;
196
- if (taskType !== undefined && r.taskType !== taskType)
197
- return true;
198
- return false;
199
- });
200
- const deleted = before - remaining.length;
201
- if (deleted > 0) {
202
- if (remaining.length === 0) {
203
- writeFileSync(this.filePath, '', 'utf-8');
204
- }
205
- else {
206
- this.writeAll(remaining);
207
- }
208
- }
209
- return deleted;
210
- }
211
- }
212
- //# sourceMappingURL=specialization-scorer.js.map
@@ -1,30 +0,0 @@
1
- /**
2
- * Termination Watcher (Task 35)
3
- *
4
- * Monitors agent run state and checks termination conditions.
5
- * Persists termination events to JSONL.
6
- */
7
- import type { TerminationPolicy, TerminationEvent } from '../../../shared/src/types/termination.js';
8
- /** Live state of a running agent. */
9
- export interface AgentRunState {
10
- agentId: string;
11
- agentSlug: string;
12
- swarmId?: string;
13
- turnCount: number;
14
- cumulativeCostUsd: number;
15
- startedAt: Date;
16
- consecutiveFailures: number;
17
- }
18
- /**
19
- * Check whether an agent should be terminated based on its current state,
20
- * last output, and the effective termination policy.
21
- *
22
- * Returns a `TerminationEvent` if a condition is met, or `null` if the
23
- * agent is still within bounds.
24
- */
25
- export declare function check(state: AgentRunState, lastOutput: string, policy?: Partial<TerminationPolicy>): TerminationEvent | null;
26
- /**
27
- * Persist a termination event to the JSONL log.
28
- */
29
- export declare function persistEvent(event: TerminationEvent, filePath?: string): void;
30
- //# sourceMappingURL=termination-watcher.d.ts.map
@@ -1,84 +0,0 @@
1
- /**
2
- * Termination Watcher (Task 35)
3
- *
4
- * Monitors agent run state and checks termination conditions.
5
- * Persists termination events to JSONL.
6
- */
7
- import { randomUUID } from 'crypto';
8
- import { existsSync, mkdirSync, appendFileSync } from 'fs';
9
- import { join, dirname } from 'path';
10
- import { DEFAULT_TERMINATION_POLICY } from '../../../shared/src/types/termination.js';
11
- /** Reasons that trigger cascade halt (hard failures). */
12
- const CASCADE_REASONS = new Set([
13
- 'max_turns_exceeded',
14
- 'max_cost_exceeded',
15
- 'timeout',
16
- 'max_retries_exceeded',
17
- ]);
18
- /**
19
- * Check whether an agent should be terminated based on its current state,
20
- * last output, and the effective termination policy.
21
- *
22
- * Returns a `TerminationEvent` if a condition is met, or `null` if the
23
- * agent is still within bounds.
24
- */
25
- export function check(state, lastOutput, policy) {
26
- const effective = {
27
- ...DEFAULT_TERMINATION_POLICY,
28
- ...policy,
29
- };
30
- // 1. Max turns
31
- if (state.turnCount >= effective.maxTurns) {
32
- return buildEvent(state, 'max_turns_exceeded', state.turnCount);
33
- }
34
- // 2. Max cost
35
- if (state.cumulativeCostUsd >= effective.maxCostUsd) {
36
- return buildEvent(state, 'max_cost_exceeded', state.cumulativeCostUsd);
37
- }
38
- // 3. Timeout
39
- const elapsed = Date.now() - state.startedAt.getTime();
40
- if (elapsed >= effective.timeoutMs) {
41
- return buildEvent(state, 'timeout', elapsed);
42
- }
43
- // 4. Stop phrases
44
- for (const phrase of effective.stopOnPhrases) {
45
- if (lastOutput.includes(phrase)) {
46
- return buildEvent(state, 'stop_phrase_matched', phrase);
47
- }
48
- }
49
- // 5. Max retries (consecutive failures)
50
- if (state.consecutiveFailures >= effective.maxRetries) {
51
- return buildEvent(state, 'max_retries_exceeded', state.consecutiveFailures);
52
- }
53
- return null;
54
- }
55
- function buildEvent(state, reason, triggeredValue) {
56
- return {
57
- eventId: randomUUID(),
58
- agentId: state.agentId,
59
- agentSlug: state.agentSlug,
60
- reason,
61
- triggeredValue,
62
- swarmId: state.swarmId,
63
- terminatedAt: new Date(),
64
- cascadeHalt: CASCADE_REASONS.has(reason),
65
- };
66
- }
67
- /**
68
- * Persist a termination event to the JSONL log.
69
- */
70
- export function persistEvent(event, filePath) {
71
- const target = filePath ?? join(process.cwd(), 'data', 'termination-events.jsonl');
72
- const dir = dirname(target);
73
- if (!existsSync(dir)) {
74
- mkdirSync(dir, { recursive: true });
75
- }
76
- const serialized = {
77
- ...event,
78
- terminatedAt: event.terminatedAt instanceof Date
79
- ? event.terminatedAt.toISOString()
80
- : String(event.terminatedAt),
81
- };
82
- appendFileSync(target, JSON.stringify(serialized) + '\n', 'utf-8');
83
- }
84
- //# sourceMappingURL=termination-watcher.js.map
@@ -1,20 +0,0 @@
1
- /**
2
- * Trigger Index Persistence (Task 32)
3
- *
4
- * Handles saving and loading the TriggerIndex JSON file
5
- * at `.monomind/trigger-index.json` (or a custom path).
6
- */
7
- import type { TriggerIndex } from '../../../../@monoes/shared/src/types/trigger.js';
8
- /** Default path for the persisted trigger index. */
9
- export declare const DEFAULT_TRIGGER_INDEX_PATH = ".monomind/trigger-index.json";
10
- /**
11
- * Save a TriggerIndex to a JSON file.
12
- * Creates parent directories if they don't exist.
13
- */
14
- export declare function save(index: TriggerIndex, path?: string): void;
15
- /**
16
- * Load a TriggerIndex from a JSON file.
17
- * Throws if the file does not exist or contains invalid JSON.
18
- */
19
- export declare function load(path?: string): TriggerIndex;
20
- //# sourceMappingURL=trigger-index.d.ts.map
@@ -1,38 +0,0 @@
1
- /**
2
- * Trigger Index Persistence (Task 32)
3
- *
4
- * Handles saving and loading the TriggerIndex JSON file
5
- * at `.monomind/trigger-index.json` (or a custom path).
6
- */
7
- import { readFileSync, writeFileSync, mkdirSync } from 'fs';
8
- import { dirname } from 'path';
9
- /** Default path for the persisted trigger index. */
10
- export const DEFAULT_TRIGGER_INDEX_PATH = '.monomind/trigger-index.json';
11
- /**
12
- * Save a TriggerIndex to a JSON file.
13
- * Creates parent directories if they don't exist.
14
- */
15
- export function save(index, path = DEFAULT_TRIGGER_INDEX_PATH) {
16
- mkdirSync(dirname(path), { recursive: true });
17
- writeFileSync(path, JSON.stringify(index, null, 2), 'utf-8');
18
- }
19
- /**
20
- * Load a TriggerIndex from a JSON file.
21
- * Throws if the file does not exist or contains invalid JSON.
22
- */
23
- export function load(path = DEFAULT_TRIGGER_INDEX_PATH) {
24
- const raw = readFileSync(path, 'utf-8');
25
- const parsed = JSON.parse(raw);
26
- // Basic structural validation
27
- if (!Array.isArray(parsed.patterns)) {
28
- throw new Error(`Invalid trigger index: "patterns" must be an array`);
29
- }
30
- if (typeof parsed.builtAt !== 'string') {
31
- throw new Error(`Invalid trigger index: "builtAt" must be a string`);
32
- }
33
- if (typeof parsed.totalAgentsScanned !== 'number') {
34
- throw new Error(`Invalid trigger index: "totalAgentsScanned" must be a number`);
35
- }
36
- return parsed;
37
- }
38
- //# sourceMappingURL=trigger-index.js.map
@@ -1,64 +0,0 @@
1
- /**
2
- * Trigger Scanner (Task 32)
3
- *
4
- * Scans task descriptions against compiled trigger patterns
5
- * from agent frontmatter and returns matches.
6
- *
7
- * - Patterns are tested in descending priority order.
8
- * - A `takeover` match short-circuits: only that agent is returned.
9
- * - `inject` matches accumulate as additional candidates.
10
- * - Invalid regex patterns are silently skipped.
11
- */
12
- import type { TriggerPattern, TriggerMatch, TriggerIndex } from '../../../../@monomind/shared/src/types/trigger.js';
13
- export declare class TriggerScanner {
14
- private compiled;
15
- private patterns;
16
- private totalAgentsScanned;
17
- private buildingIndex;
18
- constructor(patterns?: TriggerPattern[]);
19
- /**
20
- * Test all patterns against `taskDescription` and return matches.
21
- *
22
- * Patterns are tested in descending priority order.
23
- * If a `takeover` pattern matches, scanning stops immediately
24
- * and only that agent is returned.
25
- */
26
- scan(taskDescription: string): TriggerMatch[];
27
- /**
28
- * Build an index by scanning agent markdown files under `agentDir`.
29
- *
30
- * Reads each `.md` file, extracts YAML frontmatter, and looks for
31
- * `triggers:` entries with `pattern`, `mode`, and optional `priority`.
32
- */
33
- buildIndex(agentDir: string, allowedRoot?: string): TriggerIndex;
34
- private _buildIndex;
35
- /** Add a pattern to the index at runtime. */
36
- addPattern(pattern: TriggerPattern): void;
37
- /**
38
- * Remove a specific pattern for an agent.
39
- * Returns `true` if the pattern was found and removed.
40
- */
41
- removePattern(agentSlug: string, pattern: string): boolean;
42
- /** Return a snapshot of the current index. */
43
- getIndex(): TriggerIndex;
44
- /** Number of compiled patterns. */
45
- get size(): number;
46
- private compileAndAdd;
47
- private sortByPriority;
48
- /** Recursively collect `.md` files (symlinks skipped, visited inodes tracked). */
49
- private collectMdFiles;
50
- /** Derive slug from filename. */
51
- private slugFromPath;
52
- /**
53
- * Extract trigger definitions from markdown frontmatter.
54
- *
55
- * Looks for a YAML block between `---` markers, then finds lines like:
56
- * - pattern: "\\b(auth|jwt)\\b"
57
- * mode: "inject"
58
- * priority: 10
59
- */
60
- private extractTriggers;
61
- private finalizeTrigger;
62
- private extractYamlValue;
63
- }
64
- //# sourceMappingURL=trigger-scanner.d.ts.map