monomind 1.11.11 → 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 (227) 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/architect.md +7 -4
  5. package/.claude/skills/mastermind/autodev.md +4 -2
  6. package/.claude/skills/mastermind/build.md +3 -3
  7. package/.claude/skills/mastermind/content.md +3 -3
  8. package/.claude/skills/mastermind/createorg.md +2 -2
  9. package/.claude/skills/mastermind/finance.md +3 -3
  10. package/.claude/skills/mastermind/idea.md +8 -0
  11. package/.claude/skills/mastermind/marketing.md +3 -3
  12. package/.claude/skills/mastermind/ops.md +3 -3
  13. package/.claude/skills/mastermind/release.md +3 -3
  14. package/.claude/skills/mastermind/research.md +3 -3
  15. package/.claude/skills/mastermind/review.md +3 -3
  16. package/.claude/skills/mastermind/sales.md +3 -3
  17. package/package.json +1 -1
  18. package/packages/@monomind/cli/dist/src/index.js +19 -14
  19. package/packages/@monomind/cli/dist/src/init/statusline-generator.js +3 -3
  20. package/packages/@monomind/cli/dist/src/observability/replay-reader.d.ts +1 -1
  21. package/packages/@monomind/cli/dist/src/update/checker.js +24 -7
  22. package/packages/@monomind/cli/dist/src/update/index.d.ts +10 -0
  23. package/packages/@monomind/cli/dist/src/update/index.js +29 -2
  24. package/packages/@monomind/cli/package.json +1 -1
  25. package/packages/@monomind/cli/dist/src/agents/halt-signal.d.ts +0 -25
  26. package/packages/@monomind/cli/dist/src/agents/halt-signal.js +0 -76
  27. package/packages/@monomind/cli/dist/src/agents/index.d.ts +0 -18
  28. package/packages/@monomind/cli/dist/src/agents/index.js +0 -13
  29. package/packages/@monomind/cli/dist/src/agents/managed-agent.d.ts +0 -41
  30. package/packages/@monomind/cli/dist/src/agents/managed-agent.js +0 -69
  31. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.d.ts +0 -23
  32. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.js +0 -49
  33. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.d.ts +0 -22
  34. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.js +0 -80
  35. package/packages/@monomind/cli/dist/src/agents/registry-query.d.ts +0 -71
  36. package/packages/@monomind/cli/dist/src/agents/registry-query.js +0 -125
  37. package/packages/@monomind/cli/dist/src/agents/score-decay.d.ts +0 -19
  38. package/packages/@monomind/cli/dist/src/agents/score-decay.js +0 -22
  39. package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.d.ts +0 -13
  40. package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.js +0 -40
  41. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.d.ts +0 -54
  42. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.js +0 -212
  43. package/packages/@monomind/cli/dist/src/agents/termination-watcher.d.ts +0 -30
  44. package/packages/@monomind/cli/dist/src/agents/termination-watcher.js +0 -84
  45. package/packages/@monomind/cli/dist/src/agents/trigger-index.d.ts +0 -20
  46. package/packages/@monomind/cli/dist/src/agents/trigger-index.js +0 -38
  47. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.d.ts +0 -64
  48. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.js +0 -308
  49. package/packages/@monomind/cli/dist/src/agents/version-diff.d.ts +0 -18
  50. package/packages/@monomind/cli/dist/src/agents/version-diff.js +0 -64
  51. package/packages/@monomind/cli/dist/src/agents/version-store.d.ts +0 -60
  52. package/packages/@monomind/cli/dist/src/agents/version-store.js +0 -235
  53. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +0 -45
  54. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.js +0 -404
  55. package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +0 -14
  56. package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +0 -333
  57. package/packages/@monomind/cli/dist/src/commands/ui.js +0 -68
  58. package/packages/@monomind/cli/dist/src/consensus/index.d.ts +0 -7
  59. package/packages/@monomind/cli/dist/src/consensus/index.js +0 -6
  60. package/packages/@monomind/cli/dist/src/context/context-provider.d.ts +0 -44
  61. package/packages/@monomind/cli/dist/src/context/context-provider.js +0 -25
  62. package/packages/@monomind/cli/dist/src/context/git-state-provider.d.ts +0 -12
  63. package/packages/@monomind/cli/dist/src/context/git-state-provider.js +0 -34
  64. package/packages/@monomind/cli/dist/src/context/index.d.ts +0 -12
  65. package/packages/@monomind/cli/dist/src/context/index.js +0 -12
  66. package/packages/@monomind/cli/dist/src/context/project-conventions-provider.d.ts +0 -15
  67. package/packages/@monomind/cli/dist/src/context/project-conventions-provider.js +0 -19
  68. package/packages/@monomind/cli/dist/src/context/prompt-assembler.d.ts +0 -26
  69. package/packages/@monomind/cli/dist/src/context/prompt-assembler.js +0 -93
  70. package/packages/@monomind/cli/dist/src/context/task-history-provider.d.ts +0 -24
  71. package/packages/@monomind/cli/dist/src/context/task-history-provider.js +0 -32
  72. package/packages/@monomind/cli/dist/src/context/user-preferences-provider.d.ts +0 -14
  73. package/packages/@monomind/cli/dist/src/context/user-preferences-provider.js +0 -27
  74. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.d.ts +0 -31
  75. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.js +0 -81
  76. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.d.ts +0 -24
  77. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.js +0 -65
  78. package/packages/@monomind/cli/dist/src/dlq/index.d.ts +0 -10
  79. package/packages/@monomind/cli/dist/src/dlq/index.js +0 -7
  80. package/packages/@monomind/cli/dist/src/eval/dataset-manager.d.ts +0 -33
  81. package/packages/@monomind/cli/dist/src/eval/dataset-manager.js +0 -107
  82. package/packages/@monomind/cli/dist/src/eval/dataset-runner.d.ts +0 -23
  83. package/packages/@monomind/cli/dist/src/eval/dataset-runner.js +0 -59
  84. package/packages/@monomind/cli/dist/src/eval/index.d.ts +0 -10
  85. package/packages/@monomind/cli/dist/src/eval/index.js +0 -7
  86. package/packages/@monomind/cli/dist/src/eval/trace-collector.d.ts +0 -40
  87. package/packages/@monomind/cli/dist/src/eval/trace-collector.js +0 -102
  88. package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.d.ts +0 -68
  89. package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.js +0 -264
  90. package/packages/@monomind/cli/dist/src/interactive/interrupt.d.ts +0 -22
  91. package/packages/@monomind/cli/dist/src/interactive/interrupt.js +0 -71
  92. package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.d.ts +0 -25
  93. package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.js +0 -48
  94. package/packages/@monomind/cli/dist/src/mcp/tool-registry.d.ts +0 -61
  95. package/packages/@monomind/cli/dist/src/mcp/tool-registry.js +0 -246
  96. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +0 -9
  97. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +0 -230
  98. package/packages/@monomind/cli/dist/src/model/complexity-scorer.d.ts +0 -21
  99. package/packages/@monomind/cli/dist/src/model/complexity-scorer.js +0 -106
  100. package/packages/@monomind/cli/dist/src/model/index.d.ts +0 -4
  101. package/packages/@monomind/cli/dist/src/model/index.js +0 -4
  102. package/packages/@monomind/cli/dist/src/model/model-settings.d.ts +0 -22
  103. package/packages/@monomind/cli/dist/src/model/model-settings.js +0 -33
  104. package/packages/@monomind/cli/dist/src/model/model-tier-resolver.d.ts +0 -24
  105. package/packages/@monomind/cli/dist/src/model/model-tier-resolver.js +0 -65
  106. package/packages/@monomind/cli/dist/src/monovector/capabilities.d.ts +0 -34
  107. package/packages/@monomind/cli/dist/src/monovector/capabilities.js +0 -37
  108. package/packages/@monomind/cli/dist/src/orchestration/index.d.ts +0 -7
  109. package/packages/@monomind/cli/dist/src/orchestration/index.js +0 -6
  110. package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.d.ts +0 -11
  111. package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.js +0 -31
  112. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.d.ts +0 -68
  113. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.js +0 -180
  114. package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +0 -7
  115. package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.js +0 -126
  116. package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.d.ts +0 -12
  117. package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.js +0 -188
  118. package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.d.ts +0 -7
  119. package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.js +0 -206
  120. package/packages/@monomind/cli/dist/src/runtime/headless.d.ts +0 -60
  121. package/packages/@monomind/cli/dist/src/runtime/headless.js +0 -284
  122. package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.d.ts +0 -50
  123. package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.js +0 -95
  124. package/packages/@monomind/cli/dist/src/services/container-worker-pool.d.ts +0 -197
  125. package/packages/@monomind/cli/dist/src/services/container-worker-pool.js +0 -623
  126. package/packages/@monomind/cli/dist/src/services/index.d.ts +0 -13
  127. package/packages/@monomind/cli/dist/src/services/index.js +0 -11
  128. package/packages/@monomind/cli/dist/src/services/worker-queue.d.ts +0 -201
  129. package/packages/@monomind/cli/dist/src/services/worker-queue.js +0 -594
  130. package/packages/@monomind/cli/dist/src/swarm/communication-graph.d.ts +0 -25
  131. package/packages/@monomind/cli/dist/src/swarm/communication-graph.js +0 -77
  132. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.d.ts +0 -31
  133. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.js +0 -61
  134. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.d.ts +0 -19
  135. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.js +0 -68
  136. package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.d.ts +0 -13
  137. package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.js +0 -205
  138. package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.d.ts +0 -12
  139. package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.js +0 -190
  140. package/packages/@monomind/cli/dist/src/transfer/test-seraphine.d.ts +0 -6
  141. package/packages/@monomind/cli/dist/src/transfer/test-seraphine.js +0 -105
  142. package/packages/@monomind/cli/dist/src/transfer/tests/test-store.d.ts +0 -7
  143. package/packages/@monomind/cli/dist/src/transfer/tests/test-store.js +0 -214
  144. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.d.ts +0 -10
  145. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.js +0 -82
  146. package/packages/@monomind/cli/dist/src/workflow/context-resolver.d.ts +0 -12
  147. package/packages/@monomind/cli/dist/src/workflow/context-resolver.js +0 -23
  148. package/packages/@monomind/cli/dist/src/workflow/dag-builder.d.ts +0 -17
  149. package/packages/@monomind/cli/dist/src/workflow/dag-builder.js +0 -129
  150. package/packages/@monomind/cli/dist/src/workflow/dag-executor.d.ts +0 -9
  151. package/packages/@monomind/cli/dist/src/workflow/dag-executor.js +0 -116
  152. package/packages/@monomind/cli/dist/src/workflow/dag-types.d.ts +0 -41
  153. package/packages/@monomind/cli/dist/src/workflow/dag-types.js +0 -8
  154. package/packages/@monomind/cli/dist/src/workflow/dsl-parser.d.ts +0 -12
  155. package/packages/@monomind/cli/dist/src/workflow/dsl-parser.js +0 -20
  156. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.d.ts +0 -165
  157. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.js +0 -82
  158. package/packages/@monomind/cli/dist/src/workflow/index.d.ts +0 -13
  159. package/packages/@monomind/cli/dist/src/workflow/index.js +0 -11
  160. package/packages/@monomind/cli/dist/src/workflow/template-engine.d.ts +0 -11
  161. package/packages/@monomind/cli/dist/src/workflow/template-engine.js +0 -40
  162. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.d.ts +0 -29
  163. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.js +0 -227
  164. package/packages/@monomind/guidance/dist/adversarial.d.ts +0 -284
  165. package/packages/@monomind/guidance/dist/adversarial.js +0 -572
  166. package/packages/@monomind/guidance/dist/analyzer.d.ts +0 -530
  167. package/packages/@monomind/guidance/dist/analyzer.js +0 -2518
  168. package/packages/@monomind/guidance/dist/artifacts.d.ts +0 -283
  169. package/packages/@monomind/guidance/dist/artifacts.js +0 -356
  170. package/packages/@monomind/guidance/dist/authority.d.ts +0 -290
  171. package/packages/@monomind/guidance/dist/authority.js +0 -558
  172. package/packages/@monomind/guidance/dist/capabilities.d.ts +0 -209
  173. package/packages/@monomind/guidance/dist/capabilities.js +0 -485
  174. package/packages/@monomind/guidance/dist/coherence.d.ts +0 -233
  175. package/packages/@monomind/guidance/dist/coherence.js +0 -372
  176. package/packages/@monomind/guidance/dist/compiler.d.ts +0 -87
  177. package/packages/@monomind/guidance/dist/compiler.js +0 -419
  178. package/packages/@monomind/guidance/dist/conformance-kit.d.ts +0 -225
  179. package/packages/@monomind/guidance/dist/conformance-kit.js +0 -629
  180. package/packages/@monomind/guidance/dist/continue-gate.d.ts +0 -214
  181. package/packages/@monomind/guidance/dist/continue-gate.js +0 -353
  182. package/packages/@monomind/guidance/dist/crypto-utils.d.ts +0 -17
  183. package/packages/@monomind/guidance/dist/crypto-utils.js +0 -24
  184. package/packages/@monomind/guidance/dist/evolution.d.ts +0 -282
  185. package/packages/@monomind/guidance/dist/evolution.js +0 -500
  186. package/packages/@monomind/guidance/dist/gates.d.ts +0 -79
  187. package/packages/@monomind/guidance/dist/gates.js +0 -302
  188. package/packages/@monomind/guidance/dist/gateway.d.ts +0 -206
  189. package/packages/@monomind/guidance/dist/gateway.js +0 -452
  190. package/packages/@monomind/guidance/dist/generators.d.ts +0 -153
  191. package/packages/@monomind/guidance/dist/generators.js +0 -682
  192. package/packages/@monomind/guidance/dist/headless.d.ts +0 -177
  193. package/packages/@monomind/guidance/dist/headless.js +0 -342
  194. package/packages/@monomind/guidance/dist/hooks.d.ts +0 -109
  195. package/packages/@monomind/guidance/dist/hooks.js +0 -347
  196. package/packages/@monomind/guidance/dist/index.d.ts +0 -205
  197. package/packages/@monomind/guidance/dist/index.js +0 -321
  198. package/packages/@monomind/guidance/dist/ledger.d.ts +0 -162
  199. package/packages/@monomind/guidance/dist/ledger.js +0 -375
  200. package/packages/@monomind/guidance/dist/manifest-validator.d.ts +0 -289
  201. package/packages/@monomind/guidance/dist/manifest-validator.js +0 -838
  202. package/packages/@monomind/guidance/dist/memory-gate.d.ts +0 -222
  203. package/packages/@monomind/guidance/dist/memory-gate.js +0 -382
  204. package/packages/@monomind/guidance/dist/meta-governance.d.ts +0 -265
  205. package/packages/@monomind/guidance/dist/meta-governance.js +0 -348
  206. package/packages/@monomind/guidance/dist/optimizer.d.ts +0 -104
  207. package/packages/@monomind/guidance/dist/optimizer.js +0 -329
  208. package/packages/@monomind/guidance/dist/persistence.d.ts +0 -189
  209. package/packages/@monomind/guidance/dist/persistence.js +0 -464
  210. package/packages/@monomind/guidance/dist/proof.d.ts +0 -185
  211. package/packages/@monomind/guidance/dist/proof.js +0 -238
  212. package/packages/@monomind/guidance/dist/retriever.d.ts +0 -116
  213. package/packages/@monomind/guidance/dist/retriever.js +0 -394
  214. package/packages/@monomind/guidance/dist/ruvbot-integration.d.ts +0 -370
  215. package/packages/@monomind/guidance/dist/ruvbot-integration.js +0 -738
  216. package/packages/@monomind/guidance/dist/temporal.d.ts +0 -426
  217. package/packages/@monomind/guidance/dist/temporal.js +0 -658
  218. package/packages/@monomind/guidance/dist/trust.d.ts +0 -283
  219. package/packages/@monomind/guidance/dist/trust.js +0 -473
  220. package/packages/@monomind/guidance/dist/truth-anchors.d.ts +0 -276
  221. package/packages/@monomind/guidance/dist/truth-anchors.js +0 -488
  222. package/packages/@monomind/guidance/dist/types.d.ts +0 -378
  223. package/packages/@monomind/guidance/dist/types.js +0 -10
  224. package/packages/@monomind/guidance/dist/uncertainty.d.ts +0 -372
  225. package/packages/@monomind/guidance/dist/uncertainty.js +0 -619
  226. package/packages/@monomind/guidance/dist/wasm-kernel.d.ts +0 -48
  227. package/packages/@monomind/guidance/dist/wasm-kernel.js +0 -158
@@ -1,40 +0,0 @@
1
- import { readFileSync, existsSync } from 'node:fs';
2
- import { resolve } from 'node:path';
3
- const DEFAULT_PATH = '.agents/shared_instructions.md';
4
- export class SharedInstructionsLoader {
5
- cache = null;
6
- filePath;
7
- constructor(filePath) {
8
- this.filePath = filePath ?? DEFAULT_PATH;
9
- }
10
- load(basePath) {
11
- const fullPath = basePath ? resolve(basePath, this.filePath) : this.filePath;
12
- if (!existsSync(fullPath)) {
13
- this.cache = '';
14
- return '';
15
- }
16
- this.cache = readFileSync(fullPath, 'utf-8');
17
- return this.cache;
18
- }
19
- getSharedInstructions(basePath) {
20
- if (this.cache !== null)
21
- return this.cache;
22
- return this.load(basePath);
23
- }
24
- reload(basePath) {
25
- this.cache = null;
26
- return this.load(basePath);
27
- }
28
- isLoaded() {
29
- return this.cache !== null;
30
- }
31
- /** Prepend shared instructions to an agent prompt with separator */
32
- prependToPrompt(agentPrompt, basePath) {
33
- const shared = this.getSharedInstructions(basePath);
34
- if (!shared)
35
- return agentPrompt;
36
- return `${shared}\n\n---\n\n${agentPrompt}`;
37
- }
38
- }
39
- export const sharedInstructionsLoader = new SharedInstructionsLoader();
40
- //# sourceMappingURL=shared-instructions-loader.js.map
@@ -1,54 +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 type { SpecializationScore, ScoreUpdate } from '../../../shared/src/types/specialization.js';
8
- /**
9
- * JSONL-based specialization scorer.
10
- *
11
- * Stores one JSON object per line in the configured file path.
12
- * Each line represents a SpecializationScore for a unique agent+taskType pair.
13
- * On update, the entire file is rewritten to maintain a single record per pair.
14
- */
15
- export declare class SpecializationScorer {
16
- private readonly filePath;
17
- constructor(filePath: string);
18
- private readAll;
19
- private writeAll;
20
- /**
21
- * Record an outcome for a given agent+taskType pair.
22
- *
23
- * Updates running averages for latency and quality, recalculates
24
- * successRate, applies time-decay, and persists the result.
25
- */
26
- recordOutcome(update: ScoreUpdate): SpecializationScore;
27
- /**
28
- * Get the score for a specific agent+taskType pair, or null if not found.
29
- * Recalculates decay on read.
30
- */
31
- getScore(agentSlug: string, taskType: string): SpecializationScore | null;
32
- /**
33
- * Get top N candidates for a task type from the given list of slugs,
34
- * sorted by effectiveScore descending.
35
- */
36
- getTopCandidates(taskType: string, slugs: string[], topN?: number): SpecializationScore[];
37
- /**
38
- * Return the best candidate slug for a task type.
39
- * Falls back to the first candidate if no scores exist.
40
- */
41
- topCandidate(taskType: string, candidates: string[]): string;
42
- /**
43
- * Get all scores for a given agent across all task types.
44
- */
45
- getAllScores(agentSlug: string): SpecializationScore[];
46
- /**
47
- * Reset scores for an agent. If taskType is provided, only that
48
- * pair is removed; otherwise all scores for the agent are removed.
49
- *
50
- * @returns The number of records deleted.
51
- */
52
- resetScores(agentSlug: string, taskType?: string): number;
53
- }
54
- //# sourceMappingURL=specialization-scorer.d.ts.map
@@ -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