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.
- package/.claude/commands/mastermind/idea.md +1 -1
- package/.claude/commands/mastermind/master.md +1 -1
- package/.claude/scheduled_tasks.lock +1 -1
- package/.claude/skills/mastermind/_protocol.md +4 -4
- package/.claude/skills/mastermind/architect.md +4 -7
- package/.claude/skills/mastermind/autodev.md +2 -4
- package/.claude/skills/mastermind/build.md +3 -3
- package/.claude/skills/mastermind/content.md +3 -3
- package/.claude/skills/mastermind/createorg.md +2 -2
- package/.claude/skills/mastermind/finance.md +3 -3
- package/.claude/skills/mastermind/idea.md +0 -8
- package/.claude/skills/mastermind/marketing.md +3 -3
- package/.claude/skills/mastermind/monitor.md +2 -2
- package/.claude/skills/mastermind/ops.md +3 -3
- package/.claude/skills/mastermind/release.md +3 -3
- package/.claude/skills/mastermind/research.md +3 -3
- package/.claude/skills/mastermind/review.md +3 -3
- package/.claude/skills/mastermind/sales.md +3 -3
- package/README.md +286 -129
- package/package.json +2 -2
- package/packages/@monomind/cli/README.md +286 -129
- package/packages/@monomind/cli/bundled-graph/dist/src/build.js +73 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cluster.js +120 -0
- package/packages/@monomind/cli/bundled-graph/package.json +57 -0
- package/packages/@monomind/cli/dist/src/agents/halt-signal.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/agents/halt-signal.js +76 -0
- package/packages/@monomind/cli/dist/src/agents/index.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/agents/index.js +13 -0
- package/packages/@monomind/cli/dist/src/agents/managed-agent.d.ts +41 -0
- package/packages/@monomind/cli/dist/src/agents/managed-agent.js +69 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-experiment.d.ts +23 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-experiment.js +49 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.d.ts +22 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.js +80 -0
- package/packages/@monomind/cli/dist/src/agents/registry-query.d.ts +71 -0
- package/packages/@monomind/cli/dist/src/agents/registry-query.js +125 -0
- package/packages/@monomind/cli/dist/src/agents/score-decay.d.ts +19 -0
- package/packages/@monomind/cli/dist/src/agents/score-decay.js +22 -0
- package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.js +40 -0
- package/packages/@monomind/cli/dist/src/agents/specialization-scorer.d.ts +54 -0
- package/packages/@monomind/cli/dist/src/agents/specialization-scorer.js +212 -0
- package/packages/@monomind/cli/dist/src/agents/termination-watcher.d.ts +30 -0
- package/packages/@monomind/cli/dist/src/agents/termination-watcher.js +84 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-index.d.ts +20 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-index.js +38 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-scanner.d.ts +64 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-scanner.js +308 -0
- package/packages/@monomind/cli/dist/src/agents/version-diff.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/agents/version-diff.js +64 -0
- package/packages/@monomind/cli/dist/src/agents/version-store.d.ts +60 -0
- package/packages/@monomind/cli/dist/src/agents/version-store.js +235 -0
- package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +45 -0
- package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.js +404 -0
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +333 -0
- package/packages/@monomind/cli/dist/src/commands/doctor.js +55 -1
- package/packages/@monomind/cli/dist/src/commands/ui.js +68 -0
- package/packages/@monomind/cli/dist/src/consensus/index.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/consensus/index.js +6 -0
- package/packages/@monomind/cli/dist/src/context/context-provider.d.ts +44 -0
- package/packages/@monomind/cli/dist/src/context/context-provider.js +25 -0
- package/packages/@monomind/cli/dist/src/context/git-state-provider.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/context/git-state-provider.js +34 -0
- package/packages/@monomind/cli/dist/src/context/index.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/context/index.js +12 -0
- package/packages/@monomind/cli/dist/src/context/project-conventions-provider.d.ts +15 -0
- package/packages/@monomind/cli/dist/src/context/project-conventions-provider.js +19 -0
- package/packages/@monomind/cli/dist/src/context/prompt-assembler.d.ts +26 -0
- package/packages/@monomind/cli/dist/src/context/prompt-assembler.js +93 -0
- package/packages/@monomind/cli/dist/src/context/task-history-provider.d.ts +24 -0
- package/packages/@monomind/cli/dist/src/context/task-history-provider.js +32 -0
- package/packages/@monomind/cli/dist/src/context/user-preferences-provider.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/context/user-preferences-provider.js +27 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-reader.d.ts +31 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-reader.js +81 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-writer.d.ts +24 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-writer.js +65 -0
- package/packages/@monomind/cli/dist/src/dlq/index.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/dlq/index.js +7 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-manager.d.ts +33 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-manager.js +107 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-runner.d.ts +23 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-runner.js +59 -0
- package/packages/@monomind/cli/dist/src/eval/index.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/eval/index.js +7 -0
- package/packages/@monomind/cli/dist/src/eval/trace-collector.d.ts +40 -0
- package/packages/@monomind/cli/dist/src/eval/trace-collector.js +102 -0
- package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.js +264 -0
- package/packages/@monomind/cli/dist/src/init/statusline-generator.js +3 -3
- package/packages/@monomind/cli/dist/src/interactive/interrupt.d.ts +22 -0
- package/packages/@monomind/cli/dist/src/interactive/interrupt.js +71 -0
- package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.js +48 -0
- package/packages/@monomind/cli/dist/src/mcp/tool-registry.d.ts +61 -0
- package/packages/@monomind/cli/dist/src/mcp/tool-registry.js +246 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +230 -0
- package/packages/@monomind/cli/dist/src/model/complexity-scorer.d.ts +21 -0
- package/packages/@monomind/cli/dist/src/model/complexity-scorer.js +106 -0
- package/packages/@monomind/cli/dist/src/model/index.d.ts +4 -0
- package/packages/@monomind/cli/dist/src/model/index.js +4 -0
- package/packages/@monomind/cli/dist/src/model/model-settings.d.ts +22 -0
- package/packages/@monomind/cli/dist/src/model/model-settings.js +33 -0
- package/packages/@monomind/cli/dist/src/model/model-tier-resolver.d.ts +24 -0
- package/packages/@monomind/cli/dist/src/model/model-tier-resolver.js +65 -0
- package/packages/@monomind/cli/dist/src/monovector/capabilities.d.ts +34 -0
- package/packages/@monomind/cli/dist/src/monovector/capabilities.js +37 -0
- package/packages/@monomind/cli/dist/src/observability/replay-reader.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/orchestration/index.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/orchestration/index.js +6 -0
- package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.js +31 -0
- package/packages/@monomind/cli/dist/src/orchestration/routing-modes.d.ts +68 -0
- package/packages/@monomind/cli/dist/src/orchestration/routing-modes.js +180 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.js +126 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.js +188 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.js +206 -0
- package/packages/@monomind/cli/dist/src/runtime/headless.d.ts +60 -0
- package/packages/@monomind/cli/dist/src/runtime/headless.js +284 -0
- package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.js +95 -0
- package/packages/@monomind/cli/dist/src/services/container-worker-pool.d.ts +197 -0
- package/packages/@monomind/cli/dist/src/services/container-worker-pool.js +623 -0
- package/packages/@monomind/cli/dist/src/services/index.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/services/index.js +11 -0
- package/packages/@monomind/cli/dist/src/services/worker-queue.d.ts +201 -0
- package/packages/@monomind/cli/dist/src/services/worker-queue.js +594 -0
- package/packages/@monomind/cli/dist/src/swarm/communication-graph.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/swarm/communication-graph.js +77 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.d.ts +31 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.js +61 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.d.ts +19 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.js +68 -0
- package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.js +205 -0
- package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.js +190 -0
- package/packages/@monomind/cli/dist/src/transfer/test-seraphine.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/transfer/test-seraphine.js +105 -0
- package/packages/@monomind/cli/dist/src/transfer/tests/test-store.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/transfer/tests/test-store.js +214 -0
- package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.js +82 -0
- package/packages/@monomind/cli/dist/src/workflow/context-resolver.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/workflow/context-resolver.js +23 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-builder.d.ts +17 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-builder.js +129 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-executor.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-executor.js +116 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-types.d.ts +41 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-types.js +8 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-parser.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-parser.js +20 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-schema.d.ts +165 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-schema.js +82 -0
- package/packages/@monomind/cli/dist/src/workflow/index.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/workflow/index.js +11 -0
- package/packages/@monomind/cli/dist/src/workflow/template-engine.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/workflow/template-engine.js +40 -0
- package/packages/@monomind/cli/dist/src/workflow/workflow-executor.d.ts +29 -0
- package/packages/@monomind/cli/dist/src/workflow/workflow-executor.js +227 -0
- package/packages/@monomind/cli/package.json +9 -9
- package/packages/@monomind/guidance/dist/adversarial.d.ts +284 -0
- package/packages/@monomind/guidance/dist/adversarial.js +572 -0
- package/packages/@monomind/guidance/dist/analyzer.d.ts +530 -0
- package/packages/@monomind/guidance/dist/analyzer.js +2518 -0
- package/packages/@monomind/guidance/dist/artifacts.d.ts +283 -0
- package/packages/@monomind/guidance/dist/artifacts.js +356 -0
- package/packages/@monomind/guidance/dist/authority.d.ts +290 -0
- package/packages/@monomind/guidance/dist/authority.js +558 -0
- package/packages/@monomind/guidance/dist/capabilities.d.ts +209 -0
- package/packages/@monomind/guidance/dist/capabilities.js +485 -0
- package/packages/@monomind/guidance/dist/coherence.d.ts +233 -0
- package/packages/@monomind/guidance/dist/coherence.js +372 -0
- package/packages/@monomind/guidance/dist/compiler.d.ts +87 -0
- package/packages/@monomind/guidance/dist/compiler.js +419 -0
- package/packages/@monomind/guidance/dist/conformance-kit.d.ts +225 -0
- package/packages/@monomind/guidance/dist/conformance-kit.js +629 -0
- package/packages/@monomind/guidance/dist/continue-gate.d.ts +214 -0
- package/packages/@monomind/guidance/dist/continue-gate.js +353 -0
- package/packages/@monomind/guidance/dist/crypto-utils.d.ts +17 -0
- package/packages/@monomind/guidance/dist/crypto-utils.js +24 -0
- package/packages/@monomind/guidance/dist/evolution.d.ts +282 -0
- package/packages/@monomind/guidance/dist/evolution.js +500 -0
- package/packages/@monomind/guidance/dist/gates.d.ts +79 -0
- package/packages/@monomind/guidance/dist/gates.js +302 -0
- package/packages/@monomind/guidance/dist/gateway.d.ts +206 -0
- package/packages/@monomind/guidance/dist/gateway.js +452 -0
- package/packages/@monomind/guidance/dist/generators.d.ts +153 -0
- package/packages/@monomind/guidance/dist/generators.js +682 -0
- package/packages/@monomind/guidance/dist/headless.d.ts +177 -0
- package/packages/@monomind/guidance/dist/headless.js +342 -0
- package/packages/@monomind/guidance/dist/hooks.d.ts +109 -0
- package/packages/@monomind/guidance/dist/hooks.js +347 -0
- package/packages/@monomind/guidance/dist/index.d.ts +205 -0
- package/packages/@monomind/guidance/dist/index.js +321 -0
- package/packages/@monomind/guidance/dist/ledger.d.ts +162 -0
- package/packages/@monomind/guidance/dist/ledger.js +375 -0
- package/packages/@monomind/guidance/dist/manifest-validator.d.ts +289 -0
- package/packages/@monomind/guidance/dist/manifest-validator.js +838 -0
- package/packages/@monomind/guidance/dist/memory-gate.d.ts +222 -0
- package/packages/@monomind/guidance/dist/memory-gate.js +382 -0
- package/packages/@monomind/guidance/dist/meta-governance.d.ts +265 -0
- package/packages/@monomind/guidance/dist/meta-governance.js +348 -0
- package/packages/@monomind/guidance/dist/optimizer.d.ts +104 -0
- package/packages/@monomind/guidance/dist/optimizer.js +329 -0
- package/packages/@monomind/guidance/dist/persistence.d.ts +189 -0
- package/packages/@monomind/guidance/dist/persistence.js +464 -0
- package/packages/@monomind/guidance/dist/proof.d.ts +185 -0
- package/packages/@monomind/guidance/dist/proof.js +238 -0
- package/packages/@monomind/guidance/dist/retriever.d.ts +116 -0
- package/packages/@monomind/guidance/dist/retriever.js +394 -0
- package/packages/@monomind/guidance/dist/ruvbot-integration.d.ts +370 -0
- package/packages/@monomind/guidance/dist/ruvbot-integration.js +738 -0
- package/packages/@monomind/guidance/dist/temporal.d.ts +426 -0
- package/packages/@monomind/guidance/dist/temporal.js +658 -0
- package/packages/@monomind/guidance/dist/trust.d.ts +283 -0
- package/packages/@monomind/guidance/dist/trust.js +473 -0
- package/packages/@monomind/guidance/dist/truth-anchors.d.ts +276 -0
- package/packages/@monomind/guidance/dist/truth-anchors.js +488 -0
- package/packages/@monomind/guidance/dist/types.d.ts +378 -0
- package/packages/@monomind/guidance/dist/types.js +10 -0
- package/packages/@monomind/guidance/dist/uncertainty.d.ts +372 -0
- package/packages/@monomind/guidance/dist/uncertainty.js +619 -0
- package/packages/@monomind/guidance/dist/wasm-kernel.d.ts +48 -0
- 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
|