monomind 1.11.13 → 1.11.14

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 (231) hide show
  1. package/.claude/commands/mastermind/idea.md +1 -1
  2. package/.claude/commands/mastermind/master.md +1 -1
  3. package/.claude/scheduled_tasks.lock +1 -1
  4. package/.claude/skills/mastermind/_protocol.md +4 -4
  5. package/.claude/skills/mastermind/architect.md +4 -7
  6. package/.claude/skills/mastermind/autodev.md +2 -4
  7. package/.claude/skills/mastermind/build.md +3 -3
  8. package/.claude/skills/mastermind/content.md +3 -3
  9. package/.claude/skills/mastermind/createorg.md +2 -2
  10. package/.claude/skills/mastermind/finance.md +3 -3
  11. package/.claude/skills/mastermind/idea.md +0 -8
  12. package/.claude/skills/mastermind/marketing.md +3 -3
  13. package/.claude/skills/mastermind/monitor.md +2 -2
  14. package/.claude/skills/mastermind/ops.md +3 -3
  15. package/.claude/skills/mastermind/release.md +3 -3
  16. package/.claude/skills/mastermind/research.md +3 -3
  17. package/.claude/skills/mastermind/review.md +3 -3
  18. package/.claude/skills/mastermind/sales.md +3 -3
  19. package/README.md +286 -129
  20. package/package.json +2 -2
  21. package/packages/@monomind/cli/README.md +286 -129
  22. package/packages/@monomind/cli/bundled-graph/dist/src/build.js +73 -0
  23. package/packages/@monomind/cli/bundled-graph/dist/src/cluster.js +120 -0
  24. package/packages/@monomind/cli/bundled-graph/package.json +57 -0
  25. package/packages/@monomind/cli/dist/src/agents/halt-signal.d.ts +25 -0
  26. package/packages/@monomind/cli/dist/src/agents/halt-signal.js +76 -0
  27. package/packages/@monomind/cli/dist/src/agents/index.d.ts +18 -0
  28. package/packages/@monomind/cli/dist/src/agents/index.js +13 -0
  29. package/packages/@monomind/cli/dist/src/agents/managed-agent.d.ts +41 -0
  30. package/packages/@monomind/cli/dist/src/agents/managed-agent.js +69 -0
  31. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.d.ts +23 -0
  32. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.js +49 -0
  33. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.d.ts +22 -0
  34. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.js +80 -0
  35. package/packages/@monomind/cli/dist/src/agents/registry-query.d.ts +71 -0
  36. package/packages/@monomind/cli/dist/src/agents/registry-query.js +125 -0
  37. package/packages/@monomind/cli/dist/src/agents/score-decay.d.ts +19 -0
  38. package/packages/@monomind/cli/dist/src/agents/score-decay.js +22 -0
  39. package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.d.ts +13 -0
  40. package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.js +40 -0
  41. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.d.ts +54 -0
  42. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.js +212 -0
  43. package/packages/@monomind/cli/dist/src/agents/termination-watcher.d.ts +30 -0
  44. package/packages/@monomind/cli/dist/src/agents/termination-watcher.js +84 -0
  45. package/packages/@monomind/cli/dist/src/agents/trigger-index.d.ts +20 -0
  46. package/packages/@monomind/cli/dist/src/agents/trigger-index.js +38 -0
  47. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.d.ts +64 -0
  48. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.js +308 -0
  49. package/packages/@monomind/cli/dist/src/agents/version-diff.d.ts +18 -0
  50. package/packages/@monomind/cli/dist/src/agents/version-diff.js +64 -0
  51. package/packages/@monomind/cli/dist/src/agents/version-store.d.ts +60 -0
  52. package/packages/@monomind/cli/dist/src/agents/version-store.js +235 -0
  53. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +45 -0
  54. package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.js +404 -0
  55. package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +14 -0
  56. package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +333 -0
  57. package/packages/@monomind/cli/dist/src/commands/doctor.js +55 -1
  58. package/packages/@monomind/cli/dist/src/commands/ui.js +68 -0
  59. package/packages/@monomind/cli/dist/src/consensus/index.d.ts +7 -0
  60. package/packages/@monomind/cli/dist/src/consensus/index.js +6 -0
  61. package/packages/@monomind/cli/dist/src/context/context-provider.d.ts +44 -0
  62. package/packages/@monomind/cli/dist/src/context/context-provider.js +25 -0
  63. package/packages/@monomind/cli/dist/src/context/git-state-provider.d.ts +12 -0
  64. package/packages/@monomind/cli/dist/src/context/git-state-provider.js +34 -0
  65. package/packages/@monomind/cli/dist/src/context/index.d.ts +12 -0
  66. package/packages/@monomind/cli/dist/src/context/index.js +12 -0
  67. package/packages/@monomind/cli/dist/src/context/project-conventions-provider.d.ts +15 -0
  68. package/packages/@monomind/cli/dist/src/context/project-conventions-provider.js +19 -0
  69. package/packages/@monomind/cli/dist/src/context/prompt-assembler.d.ts +26 -0
  70. package/packages/@monomind/cli/dist/src/context/prompt-assembler.js +93 -0
  71. package/packages/@monomind/cli/dist/src/context/task-history-provider.d.ts +24 -0
  72. package/packages/@monomind/cli/dist/src/context/task-history-provider.js +32 -0
  73. package/packages/@monomind/cli/dist/src/context/user-preferences-provider.d.ts +14 -0
  74. package/packages/@monomind/cli/dist/src/context/user-preferences-provider.js +27 -0
  75. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.d.ts +31 -0
  76. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.js +81 -0
  77. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.d.ts +24 -0
  78. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.js +65 -0
  79. package/packages/@monomind/cli/dist/src/dlq/index.d.ts +10 -0
  80. package/packages/@monomind/cli/dist/src/dlq/index.js +7 -0
  81. package/packages/@monomind/cli/dist/src/eval/dataset-manager.d.ts +33 -0
  82. package/packages/@monomind/cli/dist/src/eval/dataset-manager.js +107 -0
  83. package/packages/@monomind/cli/dist/src/eval/dataset-runner.d.ts +23 -0
  84. package/packages/@monomind/cli/dist/src/eval/dataset-runner.js +59 -0
  85. package/packages/@monomind/cli/dist/src/eval/index.d.ts +10 -0
  86. package/packages/@monomind/cli/dist/src/eval/index.js +7 -0
  87. package/packages/@monomind/cli/dist/src/eval/trace-collector.d.ts +40 -0
  88. package/packages/@monomind/cli/dist/src/eval/trace-collector.js +102 -0
  89. package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
  90. package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.js +264 -0
  91. package/packages/@monomind/cli/dist/src/init/statusline-generator.js +3 -3
  92. package/packages/@monomind/cli/dist/src/interactive/interrupt.d.ts +22 -0
  93. package/packages/@monomind/cli/dist/src/interactive/interrupt.js +71 -0
  94. package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.d.ts +25 -0
  95. package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.js +48 -0
  96. package/packages/@monomind/cli/dist/src/mcp/tool-registry.d.ts +61 -0
  97. package/packages/@monomind/cli/dist/src/mcp/tool-registry.js +246 -0
  98. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +9 -0
  99. package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +230 -0
  100. package/packages/@monomind/cli/dist/src/model/complexity-scorer.d.ts +21 -0
  101. package/packages/@monomind/cli/dist/src/model/complexity-scorer.js +106 -0
  102. package/packages/@monomind/cli/dist/src/model/index.d.ts +4 -0
  103. package/packages/@monomind/cli/dist/src/model/index.js +4 -0
  104. package/packages/@monomind/cli/dist/src/model/model-settings.d.ts +22 -0
  105. package/packages/@monomind/cli/dist/src/model/model-settings.js +33 -0
  106. package/packages/@monomind/cli/dist/src/model/model-tier-resolver.d.ts +24 -0
  107. package/packages/@monomind/cli/dist/src/model/model-tier-resolver.js +65 -0
  108. package/packages/@monomind/cli/dist/src/monovector/capabilities.d.ts +34 -0
  109. package/packages/@monomind/cli/dist/src/monovector/capabilities.js +37 -0
  110. package/packages/@monomind/cli/dist/src/observability/replay-reader.d.ts +1 -1
  111. package/packages/@monomind/cli/dist/src/orchestration/index.d.ts +7 -0
  112. package/packages/@monomind/cli/dist/src/orchestration/index.js +6 -0
  113. package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.d.ts +11 -0
  114. package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.js +31 -0
  115. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.d.ts +68 -0
  116. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.js +180 -0
  117. package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +7 -0
  118. package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.js +126 -0
  119. package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.d.ts +12 -0
  120. package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.js +188 -0
  121. package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.d.ts +7 -0
  122. package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.js +206 -0
  123. package/packages/@monomind/cli/dist/src/runtime/headless.d.ts +60 -0
  124. package/packages/@monomind/cli/dist/src/runtime/headless.js +284 -0
  125. package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.d.ts +50 -0
  126. package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.js +95 -0
  127. package/packages/@monomind/cli/dist/src/services/container-worker-pool.d.ts +197 -0
  128. package/packages/@monomind/cli/dist/src/services/container-worker-pool.js +623 -0
  129. package/packages/@monomind/cli/dist/src/services/index.d.ts +13 -0
  130. package/packages/@monomind/cli/dist/src/services/index.js +11 -0
  131. package/packages/@monomind/cli/dist/src/services/worker-queue.d.ts +201 -0
  132. package/packages/@monomind/cli/dist/src/services/worker-queue.js +594 -0
  133. package/packages/@monomind/cli/dist/src/swarm/communication-graph.d.ts +25 -0
  134. package/packages/@monomind/cli/dist/src/swarm/communication-graph.js +77 -0
  135. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.d.ts +31 -0
  136. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.js +61 -0
  137. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.d.ts +19 -0
  138. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.js +68 -0
  139. package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.d.ts +13 -0
  140. package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.js +205 -0
  141. package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.d.ts +12 -0
  142. package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.js +190 -0
  143. package/packages/@monomind/cli/dist/src/transfer/test-seraphine.d.ts +6 -0
  144. package/packages/@monomind/cli/dist/src/transfer/test-seraphine.js +105 -0
  145. package/packages/@monomind/cli/dist/src/transfer/tests/test-store.d.ts +7 -0
  146. package/packages/@monomind/cli/dist/src/transfer/tests/test-store.js +214 -0
  147. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.d.ts +10 -0
  148. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.js +82 -0
  149. package/packages/@monomind/cli/dist/src/workflow/context-resolver.d.ts +12 -0
  150. package/packages/@monomind/cli/dist/src/workflow/context-resolver.js +23 -0
  151. package/packages/@monomind/cli/dist/src/workflow/dag-builder.d.ts +17 -0
  152. package/packages/@monomind/cli/dist/src/workflow/dag-builder.js +129 -0
  153. package/packages/@monomind/cli/dist/src/workflow/dag-executor.d.ts +9 -0
  154. package/packages/@monomind/cli/dist/src/workflow/dag-executor.js +116 -0
  155. package/packages/@monomind/cli/dist/src/workflow/dag-types.d.ts +41 -0
  156. package/packages/@monomind/cli/dist/src/workflow/dag-types.js +8 -0
  157. package/packages/@monomind/cli/dist/src/workflow/dsl-parser.d.ts +12 -0
  158. package/packages/@monomind/cli/dist/src/workflow/dsl-parser.js +20 -0
  159. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.d.ts +165 -0
  160. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.js +82 -0
  161. package/packages/@monomind/cli/dist/src/workflow/index.d.ts +13 -0
  162. package/packages/@monomind/cli/dist/src/workflow/index.js +11 -0
  163. package/packages/@monomind/cli/dist/src/workflow/template-engine.d.ts +11 -0
  164. package/packages/@monomind/cli/dist/src/workflow/template-engine.js +40 -0
  165. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.d.ts +29 -0
  166. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.js +227 -0
  167. package/packages/@monomind/cli/package.json +9 -9
  168. package/packages/@monomind/guidance/dist/adversarial.d.ts +284 -0
  169. package/packages/@monomind/guidance/dist/adversarial.js +572 -0
  170. package/packages/@monomind/guidance/dist/analyzer.d.ts +530 -0
  171. package/packages/@monomind/guidance/dist/analyzer.js +2518 -0
  172. package/packages/@monomind/guidance/dist/artifacts.d.ts +283 -0
  173. package/packages/@monomind/guidance/dist/artifacts.js +356 -0
  174. package/packages/@monomind/guidance/dist/authority.d.ts +290 -0
  175. package/packages/@monomind/guidance/dist/authority.js +558 -0
  176. package/packages/@monomind/guidance/dist/capabilities.d.ts +209 -0
  177. package/packages/@monomind/guidance/dist/capabilities.js +485 -0
  178. package/packages/@monomind/guidance/dist/coherence.d.ts +233 -0
  179. package/packages/@monomind/guidance/dist/coherence.js +372 -0
  180. package/packages/@monomind/guidance/dist/compiler.d.ts +87 -0
  181. package/packages/@monomind/guidance/dist/compiler.js +419 -0
  182. package/packages/@monomind/guidance/dist/conformance-kit.d.ts +225 -0
  183. package/packages/@monomind/guidance/dist/conformance-kit.js +629 -0
  184. package/packages/@monomind/guidance/dist/continue-gate.d.ts +214 -0
  185. package/packages/@monomind/guidance/dist/continue-gate.js +353 -0
  186. package/packages/@monomind/guidance/dist/crypto-utils.d.ts +17 -0
  187. package/packages/@monomind/guidance/dist/crypto-utils.js +24 -0
  188. package/packages/@monomind/guidance/dist/evolution.d.ts +282 -0
  189. package/packages/@monomind/guidance/dist/evolution.js +500 -0
  190. package/packages/@monomind/guidance/dist/gates.d.ts +79 -0
  191. package/packages/@monomind/guidance/dist/gates.js +302 -0
  192. package/packages/@monomind/guidance/dist/gateway.d.ts +206 -0
  193. package/packages/@monomind/guidance/dist/gateway.js +452 -0
  194. package/packages/@monomind/guidance/dist/generators.d.ts +153 -0
  195. package/packages/@monomind/guidance/dist/generators.js +682 -0
  196. package/packages/@monomind/guidance/dist/headless.d.ts +177 -0
  197. package/packages/@monomind/guidance/dist/headless.js +342 -0
  198. package/packages/@monomind/guidance/dist/hooks.d.ts +109 -0
  199. package/packages/@monomind/guidance/dist/hooks.js +347 -0
  200. package/packages/@monomind/guidance/dist/index.d.ts +205 -0
  201. package/packages/@monomind/guidance/dist/index.js +321 -0
  202. package/packages/@monomind/guidance/dist/ledger.d.ts +162 -0
  203. package/packages/@monomind/guidance/dist/ledger.js +375 -0
  204. package/packages/@monomind/guidance/dist/manifest-validator.d.ts +289 -0
  205. package/packages/@monomind/guidance/dist/manifest-validator.js +838 -0
  206. package/packages/@monomind/guidance/dist/memory-gate.d.ts +222 -0
  207. package/packages/@monomind/guidance/dist/memory-gate.js +382 -0
  208. package/packages/@monomind/guidance/dist/meta-governance.d.ts +265 -0
  209. package/packages/@monomind/guidance/dist/meta-governance.js +348 -0
  210. package/packages/@monomind/guidance/dist/optimizer.d.ts +104 -0
  211. package/packages/@monomind/guidance/dist/optimizer.js +329 -0
  212. package/packages/@monomind/guidance/dist/persistence.d.ts +189 -0
  213. package/packages/@monomind/guidance/dist/persistence.js +464 -0
  214. package/packages/@monomind/guidance/dist/proof.d.ts +185 -0
  215. package/packages/@monomind/guidance/dist/proof.js +238 -0
  216. package/packages/@monomind/guidance/dist/retriever.d.ts +116 -0
  217. package/packages/@monomind/guidance/dist/retriever.js +394 -0
  218. package/packages/@monomind/guidance/dist/ruvbot-integration.d.ts +370 -0
  219. package/packages/@monomind/guidance/dist/ruvbot-integration.js +738 -0
  220. package/packages/@monomind/guidance/dist/temporal.d.ts +426 -0
  221. package/packages/@monomind/guidance/dist/temporal.js +658 -0
  222. package/packages/@monomind/guidance/dist/trust.d.ts +283 -0
  223. package/packages/@monomind/guidance/dist/trust.js +473 -0
  224. package/packages/@monomind/guidance/dist/truth-anchors.d.ts +276 -0
  225. package/packages/@monomind/guidance/dist/truth-anchors.js +488 -0
  226. package/packages/@monomind/guidance/dist/types.d.ts +378 -0
  227. package/packages/@monomind/guidance/dist/types.js +10 -0
  228. package/packages/@monomind/guidance/dist/uncertainty.d.ts +372 -0
  229. package/packages/@monomind/guidance/dist/uncertainty.js +619 -0
  230. package/packages/@monomind/guidance/dist/wasm-kernel.d.ts +48 -0
  231. package/packages/@monomind/guidance/dist/wasm-kernel.js +158 -0
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,308 @@
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 { readFileSync, readdirSync, lstatSync, statSync, realpathSync } from 'fs';
13
+ import { join, extname, resolve, sep } from 'path';
14
+ export class TriggerScanner {
15
+ compiled = [];
16
+ patterns = [];
17
+ totalAgentsScanned = 0;
18
+ buildingIndex = false;
19
+ constructor(patterns = []) {
20
+ for (const p of patterns) {
21
+ this.compileAndAdd(p);
22
+ }
23
+ this.sortByPriority();
24
+ }
25
+ // ---------------------------------------------------------------------------
26
+ // Public API
27
+ // ---------------------------------------------------------------------------
28
+ /**
29
+ * Test all patterns against `taskDescription` and return matches.
30
+ *
31
+ * Patterns are tested in descending priority order.
32
+ * If a `takeover` pattern matches, scanning stops immediately
33
+ * and only that agent is returned.
34
+ */
35
+ scan(taskDescription) {
36
+ const matches = [];
37
+ for (const { source, regex } of this.compiled) {
38
+ // Reset lastIndex in case the regex has the global flag
39
+ regex.lastIndex = 0;
40
+ const m = regex.exec(taskDescription);
41
+ if (!m)
42
+ continue;
43
+ const match = {
44
+ agentSlug: source.agentSlug,
45
+ pattern: source.pattern,
46
+ mode: source.mode,
47
+ matchedText: m[0],
48
+ };
49
+ if (source.mode === 'takeover') {
50
+ // Short-circuit: return only this agent
51
+ return [match];
52
+ }
53
+ matches.push(match);
54
+ }
55
+ return matches;
56
+ }
57
+ /**
58
+ * Build an index by scanning agent markdown files under `agentDir`.
59
+ *
60
+ * Reads each `.md` file, extracts YAML frontmatter, and looks for
61
+ * `triggers:` entries with `pattern`, `mode`, and optional `priority`.
62
+ */
63
+ buildIndex(agentDir, allowedRoot) {
64
+ if (this.buildingIndex) {
65
+ throw new Error('buildIndex is already running; concurrent invocations are not safe');
66
+ }
67
+ this.buildingIndex = true;
68
+ try {
69
+ return this._buildIndex(agentDir, allowedRoot);
70
+ }
71
+ finally {
72
+ this.buildingIndex = false;
73
+ }
74
+ }
75
+ _buildIndex(agentDir, allowedRoot) {
76
+ if (allowedRoot) {
77
+ let resolvedDir;
78
+ let resolvedRoot;
79
+ try {
80
+ resolvedDir = realpathSync(resolve(agentDir));
81
+ }
82
+ catch {
83
+ resolvedDir = resolve(agentDir);
84
+ }
85
+ try {
86
+ resolvedRoot = realpathSync(resolve(allowedRoot));
87
+ }
88
+ catch {
89
+ resolvedRoot = resolve(allowedRoot);
90
+ }
91
+ if (!resolvedDir.startsWith(resolvedRoot + sep) && resolvedDir !== resolvedRoot) {
92
+ throw new Error(`Agent directory escapes workspace: ${resolvedDir}`);
93
+ }
94
+ }
95
+ const mdFiles = this.collectMdFiles(agentDir);
96
+ this.patterns = [];
97
+ this.compiled = [];
98
+ this.totalAgentsScanned = mdFiles.length;
99
+ const MAX_AGENT_FILE_BYTES = 1 * 1024 * 1024;
100
+ for (const filePath of mdFiles) {
101
+ let content;
102
+ try {
103
+ if (statSync(filePath).size > MAX_AGENT_FILE_BYTES)
104
+ continue;
105
+ content = readFileSync(filePath, 'utf-8');
106
+ }
107
+ catch {
108
+ continue;
109
+ }
110
+ const slug = this.slugFromPath(filePath);
111
+ const triggers = this.extractTriggers(content, slug);
112
+ for (const t of triggers) {
113
+ this.compileAndAdd(t);
114
+ }
115
+ }
116
+ this.sortByPriority();
117
+ return {
118
+ patterns: [...this.patterns],
119
+ builtAt: new Date().toISOString(),
120
+ totalAgentsScanned: this.totalAgentsScanned,
121
+ };
122
+ }
123
+ /** Add a pattern to the index at runtime. */
124
+ addPattern(pattern) {
125
+ this.compileAndAdd(pattern);
126
+ this.sortByPriority();
127
+ }
128
+ /**
129
+ * Remove a specific pattern for an agent.
130
+ * Returns `true` if the pattern was found and removed.
131
+ */
132
+ removePattern(agentSlug, pattern) {
133
+ const idx = this.patterns.findIndex((p) => p.agentSlug === agentSlug && p.pattern === pattern);
134
+ if (idx === -1)
135
+ return false;
136
+ this.patterns.splice(idx, 1);
137
+ this.compiled.splice(idx, 1);
138
+ return true;
139
+ }
140
+ /** Return a snapshot of the current index. */
141
+ getIndex() {
142
+ return {
143
+ patterns: [...this.patterns],
144
+ builtAt: new Date().toISOString(),
145
+ totalAgentsScanned: this.totalAgentsScanned,
146
+ };
147
+ }
148
+ /** Number of compiled patterns. */
149
+ get size() {
150
+ return this.compiled.length;
151
+ }
152
+ // ---------------------------------------------------------------------------
153
+ // Internal helpers
154
+ // ---------------------------------------------------------------------------
155
+ compileAndAdd(pattern) {
156
+ if (pattern.pattern.length > 200)
157
+ return;
158
+ // Reject patterns with nested/repeated quantifiers (ReDoS vectors)
159
+ // Covers: (a+)+, (a|b+)+, (a?){n}, ((a)+)+, [a-z]+{n}
160
+ if (/(\(.*[+*?].*\)|[+*?]){2,}|\{[0-9,]+\}.*[+*?]|(\[[^\]]*\]|\.)[+*?][+*?]/.test(pattern.pattern))
161
+ return;
162
+ if (/\([^)]*([+*][^)]*){2,}\)/.test(pattern.pattern))
163
+ return;
164
+ try {
165
+ const regex = new RegExp(pattern.pattern, 'i');
166
+ this.patterns.push(pattern);
167
+ this.compiled.push({ source: pattern, regex });
168
+ }
169
+ catch {
170
+ // Invalid regex — skip silently
171
+ }
172
+ }
173
+ sortByPriority() {
174
+ // Sort both arrays in-sync by descending priority
175
+ const indexed = this.patterns.map((p, i) => ({ p, c: this.compiled[i], priority: p.priority }));
176
+ indexed.sort((a, b) => b.priority - a.priority);
177
+ this.patterns = indexed.map((x) => x.p);
178
+ this.compiled = indexed.map((x) => x.c);
179
+ }
180
+ /** Recursively collect `.md` files (symlinks skipped, visited inodes tracked). */
181
+ collectMdFiles(dir, visited = new Set()) {
182
+ const results = [];
183
+ let entries;
184
+ try {
185
+ entries = readdirSync(dir);
186
+ }
187
+ catch {
188
+ return results;
189
+ }
190
+ for (const entry of entries) {
191
+ const full = join(dir, entry);
192
+ let lstat;
193
+ try {
194
+ lstat = lstatSync(full);
195
+ }
196
+ catch {
197
+ continue;
198
+ }
199
+ if (lstat.isSymbolicLink())
200
+ continue;
201
+ if (lstat.isDirectory()) {
202
+ if (visited.has(lstat.ino))
203
+ continue;
204
+ visited.add(lstat.ino);
205
+ results.push(...this.collectMdFiles(full, visited));
206
+ }
207
+ else if (lstat.isFile() && extname(entry) === '.md') {
208
+ results.push(full);
209
+ }
210
+ }
211
+ return results;
212
+ }
213
+ /** Derive slug from filename. */
214
+ slugFromPath(filePath) {
215
+ const base = filePath.split('/').pop() ?? '';
216
+ return base
217
+ .replace(/\.md$/i, '')
218
+ .toLowerCase()
219
+ .replace(/\s+/g, '-')
220
+ .replace(/[^a-z0-9-]/g, '');
221
+ }
222
+ /**
223
+ * Extract trigger definitions from markdown frontmatter.
224
+ *
225
+ * Looks for a YAML block between `---` markers, then finds lines like:
226
+ * - pattern: "\\b(auth|jwt)\\b"
227
+ * mode: "inject"
228
+ * priority: 10
229
+ */
230
+ extractTriggers(content, agentSlug) {
231
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
232
+ if (!fmMatch)
233
+ return [];
234
+ const block = fmMatch[1];
235
+ const triggers = [];
236
+ // Find trigger blocks: lines starting with "- pattern:" under a triggers: section
237
+ const lines = block.split('\n');
238
+ let inTriggers = false;
239
+ let currentTrigger = null;
240
+ for (const line of lines) {
241
+ const trimmed = line.trim();
242
+ // Measure leading whitespace to distinguish top-level keys from nested props
243
+ const indent = line.length - line.trimStart().length;
244
+ if (trimmed === 'triggers:' || trimmed.startsWith('triggers:')) {
245
+ inTriggers = true;
246
+ continue;
247
+ }
248
+ // Exit triggers section when we hit a non-indented top-level key (indent 0)
249
+ if (inTriggers && indent === 0 && /^[a-zA-Z]/.test(trimmed)) {
250
+ inTriggers = false;
251
+ if (currentTrigger?.pattern) {
252
+ triggers.push(this.finalizeTrigger(currentTrigger, agentSlug));
253
+ }
254
+ currentTrigger = null;
255
+ continue;
256
+ }
257
+ if (!inTriggers)
258
+ continue;
259
+ // New list item
260
+ if (trimmed.startsWith('- pattern:')) {
261
+ if (currentTrigger?.pattern) {
262
+ triggers.push(this.finalizeTrigger(currentTrigger, agentSlug));
263
+ }
264
+ currentTrigger = {
265
+ pattern: this.extractYamlValue(trimmed.replace(/^- pattern:\s*/, '')),
266
+ agentSlug,
267
+ };
268
+ }
269
+ else if (currentTrigger && trimmed.startsWith('mode:')) {
270
+ const val = this.extractYamlValue(trimmed.replace(/^mode:\s*/, ''));
271
+ if (val === 'inject' || val === 'takeover') {
272
+ currentTrigger.mode = val;
273
+ }
274
+ }
275
+ else if (currentTrigger && trimmed.startsWith('priority:')) {
276
+ const val = parseInt(trimmed.replace(/^priority:\s*/, ''), 10);
277
+ if (!isNaN(val)) {
278
+ currentTrigger.priority = val;
279
+ }
280
+ }
281
+ }
282
+ // Flush last trigger
283
+ if (currentTrigger?.pattern) {
284
+ triggers.push(this.finalizeTrigger(currentTrigger, agentSlug));
285
+ }
286
+ return triggers;
287
+ }
288
+ finalizeTrigger(partial, agentSlug) {
289
+ return {
290
+ pattern: partial.pattern,
291
+ mode: partial.mode ?? 'inject',
292
+ priority: partial.priority ?? 0,
293
+ agentSlug,
294
+ };
295
+ }
296
+ extractYamlValue(raw) {
297
+ let v = raw.trim();
298
+ if (v.startsWith('"') && v.endsWith('"')) {
299
+ // YAML double-quoted: unescape \\ → \ so "\\b" becomes \b (word boundary)
300
+ v = v.slice(1, -1).replace(/\\\\/g, '\\');
301
+ }
302
+ else if (v.startsWith("'") && v.endsWith("'")) {
303
+ v = v.slice(1, -1);
304
+ }
305
+ return v;
306
+ }
307
+ }
308
+ //# sourceMappingURL=trigger-scanner.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Agent Version Diff Utility (Task 29)
3
+ *
4
+ * Computes a simple unified-style diff between two content strings.
5
+ */
6
+ export interface LineDiffResult {
7
+ additions: number;
8
+ deletions: number;
9
+ hunks: string;
10
+ }
11
+ /**
12
+ * Compute a unified diff between two content strings.
13
+ *
14
+ * Uses a simple line-by-line LCS-based approach to produce
15
+ * addition/deletion counts and a unified-style hunk string.
16
+ */
17
+ export declare function computeUnifiedDiff(oldContent: string, newContent: string): LineDiffResult;
18
+ //# sourceMappingURL=version-diff.d.ts.map
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Agent Version Diff Utility (Task 29)
3
+ *
4
+ * Computes a simple unified-style diff between two content strings.
5
+ */
6
+ /**
7
+ * Compute a unified diff between two content strings.
8
+ *
9
+ * Uses a simple line-by-line LCS-based approach to produce
10
+ * addition/deletion counts and a unified-style hunk string.
11
+ */
12
+ export function computeUnifiedDiff(oldContent, newContent) {
13
+ const oldLines = oldContent.split('\n');
14
+ const newLines = newContent.split('\n');
15
+ // Simple LCS to find common subsequence
16
+ const m = oldLines.length;
17
+ const n = newLines.length;
18
+ // Build LCS table
19
+ const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
20
+ for (let i = 1; i <= m; i++) {
21
+ for (let j = 1; j <= n; j++) {
22
+ if (oldLines[i - 1] === newLines[j - 1]) {
23
+ dp[i][j] = dp[i - 1][j - 1] + 1;
24
+ }
25
+ else {
26
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
27
+ }
28
+ }
29
+ }
30
+ // Backtrack to produce diff lines
31
+ const diffLines = [];
32
+ let additions = 0;
33
+ let deletions = 0;
34
+ let i = m;
35
+ let j = n;
36
+ const result = [];
37
+ while (i > 0 || j > 0) {
38
+ if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
39
+ result.push({ type: ' ', line: oldLines[i - 1] });
40
+ i--;
41
+ j--;
42
+ }
43
+ else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
44
+ result.push({ type: '+', line: newLines[j - 1] });
45
+ additions++;
46
+ j--;
47
+ }
48
+ else {
49
+ result.push({ type: '-', line: oldLines[i - 1] });
50
+ deletions++;
51
+ i--;
52
+ }
53
+ }
54
+ result.reverse();
55
+ for (const entry of result) {
56
+ diffLines.push(`${entry.type} ${entry.line}`);
57
+ }
58
+ return {
59
+ additions,
60
+ deletions,
61
+ hunks: diffLines.join('\n'),
62
+ };
63
+ }
64
+ //# sourceMappingURL=version-diff.js.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Agent Version Store (Task 29)
3
+ *
4
+ * JSONL-based append-only storage for agent definition versions.
5
+ * Supports save, list, get, rollback, and diff operations.
6
+ */
7
+ import type { AgentVersionRecord, DiffResult } from '../../../shared/src/types/agent-version.js';
8
+ /**
9
+ * JSONL-based agent version store.
10
+ *
11
+ * Each slug's versions are stored in `<dirPath>/versions.jsonl`, one JSON
12
+ * object per line. Rollback rewrites the file to update `isCurrent` flags.
13
+ */
14
+ export declare class AgentVersionStore {
15
+ private readonly dirPath;
16
+ private readonly filePath;
17
+ constructor(dirPath: string);
18
+ private readAll;
19
+ private writeAll;
20
+ /**
21
+ * Save a new version for the given agent slug.
22
+ *
23
+ * Computes a SHA-256 hash of the content, marks all previous versions for
24
+ * the same slug as non-current, and appends the new record.
25
+ */
26
+ saveVersion(slug: string, content: string, version: string, changelog: string, opts?: {
27
+ deprecated?: boolean;
28
+ deprecatedBy?: string;
29
+ capturedBy?: string;
30
+ }): AgentVersionRecord;
31
+ /**
32
+ * List all versions for a slug, sorted by capturedAt DESC (newest first).
33
+ * Uses insertion order (line index) as a stable tiebreaker.
34
+ */
35
+ listVersions(slug: string): AgentVersionRecord[];
36
+ /**
37
+ * Get the current active version for a slug, or null.
38
+ */
39
+ getCurrent(slug: string): AgentVersionRecord | null;
40
+ /**
41
+ * Get a specific version by slug and semver string, or null.
42
+ */
43
+ getVersion(slug: string, version: string): AgentVersionRecord | null;
44
+ /**
45
+ * Roll back to a specific version.
46
+ *
47
+ * Marks the target version as current and all others for that slug as
48
+ * non-current. Rewrites the JSONL file.
49
+ *
50
+ * @throws Error if the target version does not exist.
51
+ */
52
+ rollback(slug: string, toVersion: string): AgentVersionRecord;
53
+ /**
54
+ * Compute a line-level diff between two versions of the same agent.
55
+ *
56
+ * @throws Error if either version does not exist.
57
+ */
58
+ diff(slug: string, fromVersion: string, toVersion: string): DiffResult;
59
+ }
60
+ //# sourceMappingURL=version-store.d.ts.map