monomind 1.10.57 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/core/coordinator.md +71 -0
- package/.claude/agents/generated/case-analyst.md +50 -0
- package/.claude/agents/generated/copy-editor.md +45 -0
- package/.claude/agents/generated/court-reporter.md +50 -0
- package/.claude/agents/generated/defender.md +51 -0
- package/.claude/agents/generated/editor-in-chief.md +45 -0
- package/.claude/agents/generated/fact-checker.md +45 -0
- package/.claude/agents/generated/judge.md +51 -0
- package/.claude/agents/generated/prosecutor.md +51 -0
- package/.claude/agents/generated/reporter.md +45 -0
- package/.claude/commands/hooks/README.md +1 -1
- package/.claude/commands/hooks/overview.md +1 -1
- package/.claude/commands/mastermind/_repeat.md +1 -1
- package/.claude/commands/mastermind/do.md +3 -1
- package/.claude/commands/mastermind/help.md +2 -2
- package/.claude/commands/mastermind/master.md +39 -6
- package/.claude/commands/mastermind/memory.md +1 -1
- package/.claude/commands/memory/memory-search.md +2 -2
- package/.claude/commands/monitoring/status.md +1 -1
- package/.claude/commands/{browse.md → monobrowse.md} +2 -2
- package/.claude/commands/sparc.md +1 -1
- package/.claude/helpers/handlers/graph-status-handler.cjs +1 -1
- package/.claude/helpers/loop-tracker.cjs +1 -1
- package/.claude/scheduled_tasks.lock +1 -1
- package/.claude/skills/agent-browser-testing/SKILL.md +1 -1
- package/.claude/skills/hooks-automation/SKILL.md +0 -3
- package/.claude/skills/mastermind/build.md +1 -1
- package/.claude/skills/mastermind/code-quality-reviewer-prompt.md +60 -0
- package/.claude/skills/mastermind/content.md +1 -1
- package/.claude/skills/mastermind/createorg.md +79 -2
- package/.claude/skills/mastermind/design.md +3 -1
- package/.claude/skills/mastermind/finance.md +1 -1
- package/.claude/skills/mastermind/implementer-prompt.md +109 -0
- package/.claude/skills/mastermind/marketing.md +1 -1
- package/.claude/skills/mastermind/ops.md +1 -1
- package/.claude/skills/mastermind/plan.md +20 -2
- package/.claude/skills/mastermind/release.md +1 -1
- package/.claude/skills/mastermind/research.md +1 -1
- package/.claude/skills/mastermind/review.md +1 -1
- package/.claude/skills/mastermind/sales.md +1 -1
- package/.claude/skills/mastermind/spec-reviewer-prompt.md +63 -0
- package/.claude/skills/sparc-methodology/SKILL.md +3 -3
- package/.claude/skills/swarm-advanced/SKILL.md +1 -4
- package/.claude-plugin/README.md +1 -2
- package/.claude-plugin/docs/PLUGIN_SUMMARY.md +0 -1
- package/README.md +18 -32
- package/package.json +1 -1
- package/packages/@monomind/cli/README.md +18 -32
- package/packages/@monomind/cli/dist/src/agents/registry-builder.d.ts +1 -7
- package/packages/@monomind/cli/dist/src/agents/registry-builder.js +10 -6
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.d.ts +59 -12
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +67 -13
- package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +0 -13
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +5 -5
- package/packages/@monomind/cli/dist/src/commands/agent.js +1 -6
- package/packages/@monomind/cli/dist/src/commands/analyze.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/commands/analyze.js +8 -18
- package/packages/@monomind/cli/dist/src/commands/doctor.js +53 -3
- package/packages/@monomind/cli/dist/src/commands/embeddings.js +9 -33
- package/packages/@monomind/cli/dist/src/commands/hooks.js +24 -76
- package/packages/@monomind/cli/dist/src/commands/index.d.ts +4 -6
- package/packages/@monomind/cli/dist/src/commands/index.js +8 -15
- package/packages/@monomind/cli/dist/src/commands/init.js +2 -2
- package/packages/@monomind/cli/dist/src/commands/issues.js +16 -11
- package/packages/@monomind/cli/dist/src/commands/memory.js +6 -6
- package/packages/@monomind/cli/dist/src/commands/migrate.js +1 -2
- package/packages/@monomind/cli/dist/src/commands/monograph.js +18 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/backup.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/backup.js +25 -25
- package/packages/@monomind/cli/dist/src/commands/monovector/benchmark.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/benchmark.js +14 -14
- package/packages/@monomind/cli/dist/src/commands/monovector/import.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/import.js +21 -21
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/index.d.ts +6 -6
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/index.js +22 -22
- package/packages/@monomind/cli/dist/src/commands/monovector/init.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/init.js +36 -36
- package/packages/@monomind/cli/dist/src/commands/monovector/migrate.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/migrate.js +16 -16
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/optimize.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/optimize.js +10 -10
- package/packages/@monomind/cli/dist/src/commands/monovector/setup.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/setup.js +77 -77
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/status.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/{ruvector → monovector}/status.js +34 -34
- package/packages/@monomind/cli/dist/src/commands/neural.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/commands/neural.js +31 -608
- package/packages/@monomind/cli/dist/src/commands/performance.js +7 -10
- package/packages/@monomind/cli/dist/src/commands/plugins.js +3 -4
- package/packages/@monomind/cli/dist/src/commands/process.js +5 -12
- package/packages/@monomind/cli/dist/src/commands/progress.js +16 -16
- package/packages/@monomind/cli/dist/src/commands/route.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/commands/route.js +23 -23
- package/packages/@monomind/cli/dist/src/commands/status.js +0 -3
- package/packages/@monomind/cli/dist/src/commands/swarm.js +2 -3
- package/packages/@monomind/cli/dist/src/config-adapter.js +27 -0
- package/packages/@monomind/cli/dist/src/consensus/audit-writer.d.ts +44 -17
- package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/index.js +5 -5
- package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +10 -14
- package/packages/@monomind/cli/dist/src/init/executor.js +17 -27
- package/packages/@monomind/cli/dist/src/init/helpers-generator.js +2 -2
- package/packages/@monomind/cli/dist/src/init/types.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-client.js +1 -7
- package/packages/@monomind/cli/dist/src/mcp-server.js +9 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +1 -52
- package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.js +5 -5
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +6 -5
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.js +51 -54
- package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.js +10 -10
- package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +0 -24
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +189 -480
- package/packages/@monomind/cli/dist/src/mcp-tools/index.d.ts +0 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/index.js +0 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.d.ts +334 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.js +1108 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +76 -34
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +2 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.js +3 -3
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.js +29 -19
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +1 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +2 -2
- package/packages/@monomind/cli/dist/src/memory/intelligence.js +14 -8
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +17 -2
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +76 -23
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +37 -39
- 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/monovector/command-outcomes.d.ts +37 -0
- package/packages/@monomind/cli/dist/src/monovector/command-outcomes.js +87 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-router.d.ts +103 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-router.js +337 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-tools.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/monovector/coverage-tools.js +112 -0
- package/packages/@monomind/cli/dist/src/{ruvector → monovector}/diff-classifier.d.ts +2 -2
- package/packages/@monomind/cli/dist/src/monovector/index.d.ts +61 -0
- package/packages/@monomind/cli/dist/src/monovector/index.js +67 -0
- package/packages/@monomind/cli/dist/src/monovector/init-state.d.ts +35 -0
- package/packages/@monomind/cli/dist/src/monovector/init-state.js +36 -0
- package/packages/@monomind/cli/dist/src/monovector/route-outcomes.d.ts +55 -0
- package/packages/@monomind/cli/dist/src/monovector/route-outcomes.js +137 -0
- package/packages/@monomind/cli/dist/src/parser.js +3 -3
- package/packages/@monomind/cli/dist/src/plugins/store/discovery.js +0 -31
- package/packages/@monomind/cli/dist/src/production/circuit-breaker.d.ts +26 -6
- package/packages/@monomind/cli/dist/src/production/error-handler.d.ts +55 -30
- package/packages/@monomind/cli/dist/src/production/index.d.ts +3 -20
- package/packages/@monomind/cli/dist/src/production/index.js +3 -15
- package/packages/@monomind/cli/dist/src/production/monitoring.d.ts +54 -34
- package/packages/@monomind/cli/dist/src/production/monitoring.js +12 -14
- package/packages/@monomind/cli/dist/src/production/rate-limiter.d.ts +64 -19
- package/packages/@monomind/cli/dist/src/production/rate-limiter.js +5 -5
- package/packages/@monomind/cli/dist/src/production/retry.js +4 -2
- package/packages/@monomind/cli/dist/src/services/claim-service.d.ts +50 -59
- package/packages/@monomind/cli/dist/src/services/claim-service.js +83 -50
- package/packages/@monomind/cli/dist/src/services/config-file-manager.js +8 -1
- package/packages/@monomind/cli/dist/src/services/worker-daemon.js +4 -0
- package/packages/@monomind/cli/dist/src/types.d.ts +13 -0
- package/packages/@monomind/cli/package.json +13 -13
- package/packages/@monomind/guidance/dist/index.d.ts +1 -1
- package/packages/@monomind/guidance/dist/index.js +1 -1
- package/packages/@monomind/guidance/package.json +1 -2
- package/scripts/build-monovector.sh +10 -0
- package/scripts/publish-monovector.sh +20 -0
- package/.claude/commands/monomind/adr.md +0 -11
- package/.claude/commands/monomind/budget.md +0 -7
- package/.claude/commands/monomind/createtask.md +0 -277
- package/.claude/commands/monomind/do.md +0 -498
- package/.claude/commands/monomind/graph-status.md +0 -7
- package/.claude/commands/monomind/help.md +0 -118
- package/.claude/commands/monomind/idea.md +0 -273
- package/.claude/commands/monomind/improve.md +0 -352
- package/.claude/commands/monomind/loops.md +0 -7
- package/.claude/commands/monomind/memory.md +0 -230
- package/.claude/commands/monomind/repeat.md +0 -257
- package/.claude/commands/monomind/review.md +0 -317
- package/.claude/commands/monomind/specialagents.md +0 -125
- package/.claude/commands/monomind/swarm.md +0 -161
- package/.claude/commands/monomind/understand.md +0 -139
- package/.claude/commands/training/README.md +0 -39
- package/.claude/commands/training/neural-patterns.md +0 -73
- package/.claude/commands/training/neural-train.md +0 -79
- package/packages/@monomind/cli/dist/src/commands/appliance-advanced.d.ts +0 -9
- package/packages/@monomind/cli/dist/src/commands/appliance-advanced.js +0 -238
- package/packages/@monomind/cli/dist/src/commands/appliance.d.ts +0 -8
- package/packages/@monomind/cli/dist/src/commands/appliance.js +0 -406
- package/packages/@monomind/cli/dist/src/commands/ruvector/backup.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/benchmark.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/import.d.ts +0 -18
- package/packages/@monomind/cli/dist/src/commands/ruvector/init.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/migrate.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/ruvector/setup.d.ts +0 -18
- package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.d.ts +0 -182
- package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.js +0 -316
- package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.d.ts +0 -67
- package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.js +0 -277
- package/packages/@monomind/cli/dist/src/ruvector/coverage-router.d.ts +0 -160
- package/packages/@monomind/cli/dist/src/ruvector/coverage-router.js +0 -539
- package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.d.ts +0 -33
- package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.js +0 -157
- package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.d.ts +0 -146
- package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.js +0 -551
- package/packages/@monomind/cli/dist/src/ruvector/flash-attention.d.ts +0 -195
- package/packages/@monomind/cli/dist/src/ruvector/flash-attention.js +0 -643
- package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.d.ts +0 -187
- package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.js +0 -929
- package/packages/@monomind/cli/dist/src/ruvector/index.d.ts +0 -67
- package/packages/@monomind/cli/dist/src/ruvector/index.js +0 -88
- package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.d.ts +0 -218
- package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.js +0 -455
- package/packages/@monomind/cli/dist/src/ruvector/model-router.d.ts +0 -222
- package/packages/@monomind/cli/dist/src/ruvector/model-router.js +0 -512
- package/packages/@monomind/cli/dist/src/ruvector/moe-router.d.ts +0 -213
- package/packages/@monomind/cli/dist/src/ruvector/moe-router.js +0 -649
- package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.d.ts +0 -217
- package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.js +0 -712
- package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.d.ts +0 -179
- package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.js +0 -363
- package/packages/@monomind/cli/dist/src/ruvector/semantic-router.d.ts +0 -77
- package/packages/@monomind/cli/dist/src/ruvector/semantic-router.js +0 -178
- package/packages/@monomind/cli/dist/src/ruvector/vector-db.d.ts +0 -69
- package/packages/@monomind/cli/dist/src/ruvector/vector-db.js +0 -243
- package/packages/@monomind/cli/dist/src/services/ruvector-training.d.ts +0 -222
- package/packages/@monomind/cli/dist/src/services/ruvector-training.js +0 -696
- /package/packages/@monomind/cli/dist/src/{ruvector → monovector}/diff-classifier.js +0 -0
|
@@ -56,6 +56,11 @@ export function safeParseEmbedding(raw) {
|
|
|
56
56
|
}
|
|
57
57
|
return parsed;
|
|
58
58
|
}
|
|
59
|
+
// ===== Embedding model constants — single source of truth =====
|
|
60
|
+
// Changing these requires rebuilding stored embeddings (dimension mismatch silently
|
|
61
|
+
// degrades search to BM25-only; see bridgeSearchEntries dimension-mismatch handling).
|
|
62
|
+
const BRIDGE_EMBEDDING_MODEL = 'Xenova/all-MiniLM-L6-v2';
|
|
63
|
+
const BRIDGE_EMBEDDING_DIMS = 384;
|
|
59
64
|
// ===== Lazy singleton =====
|
|
60
65
|
// registryInstance is typed as `any` because ControllerRegistry lives in @monomind/memory
|
|
61
66
|
// and cross-package type resolution is currently broken. When that is fixed, replace with
|
|
@@ -63,8 +68,15 @@ export function safeParseEmbedding(raw) {
|
|
|
63
68
|
let registryPromise = null;
|
|
64
69
|
let registryInstance = null;
|
|
65
70
|
let bridgeAvailable = null;
|
|
71
|
+
// Allow up to 3 init attempts before permanently latching unavailable.
|
|
72
|
+
// Transient failures (e.g. model not yet downloaded, sqlite cold-start) should
|
|
73
|
+
// not permanently degrade the process. After MAX_INIT_ATTEMPTS the latch is set.
|
|
74
|
+
const MAX_INIT_ATTEMPTS = 3;
|
|
75
|
+
let initAttempts = 0;
|
|
66
76
|
/** Backpressure flag for A-MEM Zettelkasten linking — see bridgeStoreEntry. */
|
|
67
77
|
let _amemInFlight = false;
|
|
78
|
+
/** OR-3: Count SONA learning failures so callers can detect degraded state. */
|
|
79
|
+
let _sonaErrorCount = 0;
|
|
68
80
|
/**
|
|
69
81
|
* Resolve database path with path traversal protection.
|
|
70
82
|
* Only allows paths within or below the project's .swarm directory,
|
|
@@ -83,6 +95,11 @@ function getDbPath(customPath) {
|
|
|
83
95
|
if (rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
84
96
|
return path.join(swarmDir, 'memory.db'); // fallback to safe default
|
|
85
97
|
}
|
|
98
|
+
// Reject non-.db paths — prevents plugins from passing e.g. 'package.json'
|
|
99
|
+
// and having SQLite truncate/corrupt it on first open.
|
|
100
|
+
if (!resolved.endsWith('.db')) {
|
|
101
|
+
return path.join(swarmDir, 'memory.db');
|
|
102
|
+
}
|
|
86
103
|
return resolved;
|
|
87
104
|
}
|
|
88
105
|
/**
|
|
@@ -98,12 +115,16 @@ function generateId(prefix) {
|
|
|
98
115
|
async function getRegistry(dbPath) {
|
|
99
116
|
if (bridgeAvailable === false)
|
|
100
117
|
return null;
|
|
118
|
+
if (initAttempts >= MAX_INIT_ATTEMPTS) {
|
|
119
|
+
bridgeAvailable = false;
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
101
122
|
if (registryInstance)
|
|
102
123
|
return registryInstance;
|
|
103
124
|
if (!registryPromise) {
|
|
104
125
|
registryPromise = (async () => {
|
|
105
126
|
try {
|
|
106
|
-
const { ControllerRegistry } = await import('@
|
|
127
|
+
const { ControllerRegistry } = await import('@monoes/memory');
|
|
107
128
|
const registry = new ControllerRegistry();
|
|
108
129
|
// Suppress noisy console.log during init
|
|
109
130
|
const origLog = console.log;
|
|
@@ -113,17 +134,20 @@ async function getRegistry(dbPath) {
|
|
|
113
134
|
msg.includes('better-sqlite3') ||
|
|
114
135
|
msg.includes('[AgentDB]') ||
|
|
115
136
|
msg.includes('[HNSWLibBackend]') ||
|
|
116
|
-
msg.includes('
|
|
137
|
+
msg.includes('MonoVector graph'))
|
|
117
138
|
return;
|
|
118
139
|
origLog.apply(console, args);
|
|
119
140
|
};
|
|
120
141
|
try {
|
|
121
142
|
await registry.initialize({
|
|
122
143
|
dbPath: dbPath || getDbPath(),
|
|
123
|
-
embeddingModel:
|
|
124
|
-
dimension:
|
|
144
|
+
embeddingModel: BRIDGE_EMBEDDING_MODEL,
|
|
145
|
+
dimension: BRIDGE_EMBEDDING_DIMS,
|
|
125
146
|
controllers: {
|
|
126
147
|
reasoningBank: true,
|
|
148
|
+
// learningBridge enables SONA/LoRA pattern learning — re-enabled after
|
|
149
|
+
// confirming LearningBridge init errors are isolated per-controller in
|
|
150
|
+
// ControllerRegistry and do not propagate to bridgeAvailable = false.
|
|
127
151
|
learningBridge: true,
|
|
128
152
|
tieredCache: true,
|
|
129
153
|
hierarchicalMemory: true,
|
|
@@ -140,8 +164,11 @@ async function getRegistry(dbPath) {
|
|
|
140
164
|
return registry;
|
|
141
165
|
}
|
|
142
166
|
catch {
|
|
143
|
-
|
|
167
|
+
initAttempts++;
|
|
144
168
|
registryPromise = null;
|
|
169
|
+
if (initAttempts >= MAX_INIT_ATTEMPTS) {
|
|
170
|
+
bridgeAvailable = false;
|
|
171
|
+
}
|
|
145
172
|
return null;
|
|
146
173
|
}
|
|
147
174
|
})();
|
|
@@ -379,7 +406,7 @@ export async function bridgeStoreEntry(options) {
|
|
|
379
406
|
if (emb) {
|
|
380
407
|
embeddingJson = JSON.stringify(Array.from(emb));
|
|
381
408
|
dimensions = emb.length;
|
|
382
|
-
model =
|
|
409
|
+
model = BRIDGE_EMBEDDING_MODEL;
|
|
383
410
|
}
|
|
384
411
|
}
|
|
385
412
|
}
|
|
@@ -425,7 +452,12 @@ export async function bridgeStoreEntry(options) {
|
|
|
425
452
|
void (async () => {
|
|
426
453
|
try {
|
|
427
454
|
const neighbors = await bridgeSearchEntries({
|
|
428
|
-
query:
|
|
455
|
+
query: (() => {
|
|
456
|
+
// Snap to last sentence boundary within 512 chars to avoid cutting mid-phrase.
|
|
457
|
+
const raw = options.value.slice(0, 512);
|
|
458
|
+
const snapped = raw.replace(/[^.!?\n]*$/, '');
|
|
459
|
+
return snapped.trim() || raw;
|
|
460
|
+
})(),
|
|
429
461
|
namespace: options.namespace,
|
|
430
462
|
limit: 3,
|
|
431
463
|
threshold: 0.7,
|
|
@@ -682,17 +714,33 @@ export async function bridgeGetEntry(options) {
|
|
|
682
714
|
}
|
|
683
715
|
// Collaborative memory promotion: track agent reads for auto-promotion to 'team'
|
|
684
716
|
// Source: https://arxiv.org/abs/2505.18279
|
|
717
|
+
//
|
|
718
|
+
// Security: agentId is caller-supplied. Two guards prevent a single process
|
|
719
|
+
// from fabricating 3 different IDs to force-promote a private entry:
|
|
720
|
+
// 1. Format validation — rejects non-standard IDs before they touch the DB
|
|
721
|
+
// 2. Time-spread check — the 3 reads must span ≥5 minutes, making rapid
|
|
722
|
+
// batch escalation observable and impractical within a single session
|
|
685
723
|
if (options.agentId) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
724
|
+
const AGENT_ID_RE = /^[a-zA-Z0-9_\-.]{1,128}$/;
|
|
725
|
+
if (AGENT_ID_RE.test(options.agentId)) {
|
|
726
|
+
try {
|
|
727
|
+
const now = Date.now();
|
|
728
|
+
ctx.db.prepare('INSERT OR IGNORE INTO agent_reads (entry_id, agent_id, read_at) VALUES (?, ?, ?)').run(row.id, options.agentId, now);
|
|
729
|
+
const cutoff = now - 24 * 60 * 60 * 1000;
|
|
730
|
+
const SPREAD_MS = 5 * 60 * 1000; // reads must span ≥5 min to count
|
|
731
|
+
const stats = ctx.db.prepare(`SELECT COUNT(DISTINCT agent_id) as cnt,
|
|
732
|
+
MIN(read_at) as earliest,
|
|
733
|
+
MAX(read_at) as latest
|
|
734
|
+
FROM agent_reads WHERE entry_id = ? AND read_at > ?`).get(row.id, cutoff);
|
|
735
|
+
// Require 3+ distinct-agent reads AND earliest+latest span ≥5 min
|
|
736
|
+
const distinctAgents = stats?.cnt ?? 0;
|
|
737
|
+
const spread = stats ? (stats.latest - stats.earliest) : 0;
|
|
738
|
+
if (distinctAgents >= 3 && spread >= SPREAD_MS) {
|
|
739
|
+
ctx.db.prepare("UPDATE memory_entries SET access_level = 'team' WHERE id = ? AND access_level = 'private'").run(row.id);
|
|
740
|
+
}
|
|
693
741
|
}
|
|
742
|
+
catch { /* non-critical */ }
|
|
694
743
|
}
|
|
695
|
-
catch { /* non-critical */ }
|
|
696
744
|
}
|
|
697
745
|
// Bounded tags read — refuse to JSON.parse a multi-MB tags blob that an
|
|
698
746
|
// older write may have persisted before the write-side cap was added.
|
|
@@ -806,7 +854,7 @@ export async function bridgeGenerateEmbedding(text, dbPath) {
|
|
|
806
854
|
return {
|
|
807
855
|
embedding: Array.from(emb),
|
|
808
856
|
dimensions: emb.length,
|
|
809
|
-
model:
|
|
857
|
+
model: BRIDGE_EMBEDDING_MODEL,
|
|
810
858
|
};
|
|
811
859
|
}
|
|
812
860
|
catch {
|
|
@@ -834,7 +882,7 @@ export async function bridgeLoadEmbeddingModel(dbPath) {
|
|
|
834
882
|
return {
|
|
835
883
|
success: true,
|
|
836
884
|
dimensions: test.length,
|
|
837
|
-
modelName:
|
|
885
|
+
modelName: BRIDGE_EMBEDDING_MODEL,
|
|
838
886
|
loadTime: Date.now() - startTime,
|
|
839
887
|
};
|
|
840
888
|
}
|
|
@@ -868,7 +916,7 @@ export async function bridgeGetHNSWStatus(dbPath) {
|
|
|
868
916
|
available: true,
|
|
869
917
|
initialized: true,
|
|
870
918
|
entryCount,
|
|
871
|
-
dimensions:
|
|
919
|
+
dimensions: BRIDGE_EMBEDDING_DIMS,
|
|
872
920
|
};
|
|
873
921
|
}
|
|
874
922
|
catch {
|
|
@@ -965,8 +1013,8 @@ export async function bridgeAddToHNSW(id, embedding, entry, dbPath) {
|
|
|
965
1013
|
id, key, namespace, content, type,
|
|
966
1014
|
embedding, embedding_dimensions, embedding_model,
|
|
967
1015
|
created_at, updated_at, status
|
|
968
|
-
) VALUES (?, ?, ?, ?, 'semantic', ?, ?,
|
|
969
|
-
`).run(id, entry.key, entry.namespace, entry.content, embeddingJson, embedding.length, now, now);
|
|
1016
|
+
) VALUES (?, ?, ?, ?, 'semantic', ?, ?, ?, ?, ?, 'active')
|
|
1017
|
+
`).run(id, entry.key, entry.namespace, entry.content, embeddingJson, embedding.length, BRIDGE_EMBEDDING_MODEL, now, now);
|
|
970
1018
|
return true;
|
|
971
1019
|
}
|
|
972
1020
|
catch {
|
|
@@ -1047,6 +1095,7 @@ export async function shutdownBridge() {
|
|
|
1047
1095
|
registryInstance = null;
|
|
1048
1096
|
registryPromise = null;
|
|
1049
1097
|
bridgeAvailable = null;
|
|
1098
|
+
initAttempts = 0;
|
|
1050
1099
|
}
|
|
1051
1100
|
}
|
|
1052
1101
|
// ===== Phase 3: ReasoningBank pattern operations =====
|
|
@@ -1197,6 +1246,10 @@ export async function bridgeRecordFeedback(options) {
|
|
|
1197
1246
|
controller += '+skills';
|
|
1198
1247
|
}
|
|
1199
1248
|
}
|
|
1249
|
+
// SONA learning feed removed (lean teardown): the per-task ONNX/embedding
|
|
1250
|
+
// write-path via LearningBridge.onInsightRecorded/consolidate is gone. Routing
|
|
1251
|
+
// learning is preserved through the file-based route-outcomes records and the
|
|
1252
|
+
// keyword router; the heavyweight neural trajectory feed was pure overhead.
|
|
1200
1253
|
// Always store feedback as a memory entry for retrieval (ensures it persists)
|
|
1201
1254
|
const storeResult = await bridgeStoreEntry({
|
|
1202
1255
|
key: `feedback-${options.taskId}`,
|
|
@@ -1348,7 +1401,7 @@ export async function bridgeSessionEnd(options) {
|
|
|
1348
1401
|
// ===== Phase 5: SemanticRouter bridge =====
|
|
1349
1402
|
/**
|
|
1350
1403
|
* Route a task via AgentDB's SemanticRouter.
|
|
1351
|
-
* Returns null to fall back to local
|
|
1404
|
+
* Returns null to fall back to local monovector router.
|
|
1352
1405
|
*/
|
|
1353
1406
|
export async function bridgeRouteTask(options) {
|
|
1354
1407
|
const registry = await getRegistry(options.dbPath);
|
|
@@ -1410,7 +1463,7 @@ export async function bridgeHealthCheck(dbPath) {
|
|
|
1410
1463
|
const s = cache.stats();
|
|
1411
1464
|
cacheStats = { size: s.size ?? 0, hits: s.hits ?? 0, misses: s.misses ?? 0 };
|
|
1412
1465
|
}
|
|
1413
|
-
return { available: true, controllers, attestationCount, cacheStats };
|
|
1466
|
+
return { available: true, controllers, attestationCount, cacheStats, sonaErrorCount: _sonaErrorCount };
|
|
1414
1467
|
}
|
|
1415
1468
|
catch {
|
|
1416
1469
|
return null;
|
|
@@ -1618,7 +1671,7 @@ export async function bridgeContextSynthesize(params) {
|
|
|
1618
1671
|
}
|
|
1619
1672
|
/**
|
|
1620
1673
|
* Route via SemanticRouter.
|
|
1621
|
-
* Available since agentdb 3.0.0-alpha.10 — uses @
|
|
1674
|
+
* Available since agentdb 3.0.0-alpha.10 — uses @monoes/router for
|
|
1622
1675
|
* semantic matching with keyword fallback.
|
|
1623
1676
|
*/
|
|
1624
1677
|
export async function bridgeSemanticRoute(params) {
|
|
@@ -123,8 +123,8 @@ export declare function softmaxAttention(scores: Float32Array, temperature?: num
|
|
|
123
123
|
export declare function topKIndices(scores: Float32Array, k: number): number[];
|
|
124
124
|
/**
|
|
125
125
|
* Flash Attention-style search
|
|
126
|
-
* Combines batch similarity, softmax, and top-k in one pass
|
|
127
|
-
* Returns indices and attention weights
|
|
126
|
+
* Combines batch similarity, softmax, and top-k in one pass.
|
|
127
|
+
* Returns indices and attention weights.
|
|
128
128
|
*/
|
|
129
129
|
export declare function flashAttentionSearch(query: Float32Array | number[], vectors: (Float32Array | number[])[], options?: {
|
|
130
130
|
k?: number;
|
|
@@ -373,24 +373,26 @@ export async function getHNSWIndex(options) {
|
|
|
373
373
|
if (hnswInitializing) {
|
|
374
374
|
throw new Error('HNSW initialization timed out after 5s');
|
|
375
375
|
}
|
|
376
|
-
return
|
|
376
|
+
// Init may have failed — return null rather than a non-initialized index object
|
|
377
|
+
return hnswIndex?.initialized ? hnswIndex : null;
|
|
377
378
|
}
|
|
378
379
|
hnswInitializing = true;
|
|
379
380
|
try {
|
|
380
|
-
//
|
|
381
|
-
//
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
// Lean teardown: the native @monoes/core HNSW backend (WASM VectorDb) has been
|
|
382
|
+
// removed. Callers of getHNSWIndex() already treat a null return as "no native
|
|
383
|
+
// index — use the pure-JS / brute-force fallback", so we short-circuit here.
|
|
384
|
+
const monovectorModule = await import('@monoes/core').catch(() => null);
|
|
385
|
+
if (!monovectorModule) {
|
|
384
386
|
hnswInitializing = false;
|
|
385
|
-
return null; // HNSW not available
|
|
387
|
+
return null; // HNSW not available — pure-JS fallback path
|
|
386
388
|
}
|
|
387
389
|
// ESM returns { default: { VectorDb, ... } }, CJS returns { VectorDb, ... }
|
|
388
|
-
const
|
|
389
|
-
if (!
|
|
390
|
+
const monovectorCore = monovectorModule.default || monovectorModule;
|
|
391
|
+
if (!monovectorCore?.VectorDb) {
|
|
390
392
|
hnswInitializing = false;
|
|
391
393
|
return null; // VectorDb not found
|
|
392
394
|
}
|
|
393
|
-
const { VectorDb } =
|
|
395
|
+
const { VectorDb } = monovectorCore;
|
|
394
396
|
// Persistent storage paths — resolve to absolute to survive CWD changes
|
|
395
397
|
const swarmDir = path.resolve(process.cwd(), '.swarm');
|
|
396
398
|
if (!fs.existsSync(swarmDir)) {
|
|
@@ -400,7 +402,7 @@ export async function getHNSWIndex(options) {
|
|
|
400
402
|
const metadataPath = path.join(swarmDir, 'hnsw.metadata.json');
|
|
401
403
|
const dbPath = options?.dbPath ? path.resolve(options.dbPath) : path.join(swarmDir, 'memory.db');
|
|
402
404
|
// Create HNSW index with persistent storage
|
|
403
|
-
// @
|
|
405
|
+
// @monoes/core uses string enum for distanceMetric: 'Cosine', 'Euclidean', 'DotProduct', 'Manhattan'
|
|
404
406
|
const db = new VectorDb({
|
|
405
407
|
dimensions,
|
|
406
408
|
distanceMetric: 'Cosine',
|
|
@@ -486,6 +488,8 @@ export async function getHNSWIndex(options) {
|
|
|
486
488
|
// SQLite load failed, start with empty index
|
|
487
489
|
}
|
|
488
490
|
}
|
|
491
|
+
// initialized = true even on empty DB — absence of vectors is a valid ready state,
|
|
492
|
+
// not a failure. The concurrent-waiter null-check at line ~395 relies on this.
|
|
489
493
|
hnswIndex.initialized = true;
|
|
490
494
|
hnswInitializing = false;
|
|
491
495
|
return hnswIndex;
|
|
@@ -572,7 +576,7 @@ export async function searchHNSWIndex(queryEmbedding, options) {
|
|
|
572
576
|
continue;
|
|
573
577
|
}
|
|
574
578
|
// Convert cosine distance to similarity score (1 - distance)
|
|
575
|
-
// Cosine distance from @
|
|
579
|
+
// Cosine distance from @monoes/core: 0 = identical, 2 = opposite
|
|
576
580
|
const score = 1 - (result.score / 2);
|
|
577
581
|
filtered.push({
|
|
578
582
|
id: entry.id.substring(0, 12),
|
|
@@ -818,25 +822,16 @@ export function topKIndices(scores, k) {
|
|
|
818
822
|
}
|
|
819
823
|
/**
|
|
820
824
|
* Flash Attention-style search
|
|
821
|
-
* Combines batch similarity, softmax, and top-k in one pass
|
|
822
|
-
* Returns indices and attention weights
|
|
825
|
+
* Combines batch similarity, softmax, and top-k in one pass.
|
|
826
|
+
* Returns indices and attention weights.
|
|
823
827
|
*/
|
|
824
828
|
export function flashAttentionSearch(query, vectors, options = {}) {
|
|
825
829
|
const { k = 10, temperature = 1.0, threshold = 0 } = options;
|
|
826
|
-
// Compute batch similarity
|
|
827
830
|
const scores = batchCosineSim(query, vectors);
|
|
828
|
-
|
|
829
|
-
const
|
|
830
|
-
// Filter by threshold
|
|
831
|
-
const filtered = indices.filter(i => scores[i] >= threshold);
|
|
832
|
-
// Extract scores for filtered results
|
|
833
|
-
const topScores = new Float32Array(filtered.length);
|
|
834
|
-
for (let i = 0; i < filtered.length; i++) {
|
|
835
|
-
topScores[i] = scores[filtered[i]];
|
|
836
|
-
}
|
|
837
|
-
// Compute attention weights (softmax over top-k)
|
|
831
|
+
const indices = topKIndices(scores, k).filter(i => scores[i] >= threshold);
|
|
832
|
+
const topScores = new Float32Array(indices.map(i => scores[i]));
|
|
838
833
|
const weights = softmaxAttention(topScores, temperature);
|
|
839
|
-
return { indices
|
|
834
|
+
return { indices, scores: topScores, weights };
|
|
840
835
|
}
|
|
841
836
|
// ============================================================================
|
|
842
837
|
// METADATA AND INITIALIZATION
|
|
@@ -1375,22 +1370,22 @@ export async function loadEmbeddingModel(options) {
|
|
|
1375
1370
|
loadTime: Date.now() - startTime
|
|
1376
1371
|
};
|
|
1377
1372
|
}
|
|
1378
|
-
// Fallback: Check for
|
|
1373
|
+
// Fallback: Check for monovector ONNX embedder (bundled MiniLM-L6-v2 since v0.2.15)
|
|
1379
1374
|
// v0.2.16: LoRA B=0 fix makes AdaptiveEmbedder safe (identity when untrained)
|
|
1380
1375
|
// Note: isReady() returns false until first embed() call (lazy init), so we
|
|
1381
1376
|
// skip the isReady() gate and verify with a probe embed instead.
|
|
1382
|
-
const
|
|
1383
|
-
if (
|
|
1377
|
+
const monovector = await import('monovector').catch(() => null);
|
|
1378
|
+
if (monovector?.initOnnxEmbedder) {
|
|
1384
1379
|
try {
|
|
1385
|
-
await
|
|
1380
|
+
await monovector.initOnnxEmbedder();
|
|
1386
1381
|
// Fallback: OptimizedOnnxEmbedder (raw ONNX, lazy-inits on first embed)
|
|
1387
|
-
const onnxEmb =
|
|
1382
|
+
const onnxEmb = monovector.getOptimizedOnnxEmbedder?.();
|
|
1388
1383
|
if (onnxEmb?.embed) {
|
|
1389
1384
|
// Probe embed to trigger lazy ONNX init and verify it works
|
|
1390
1385
|
const probe = await onnxEmb.embed('test');
|
|
1391
1386
|
if (probe && probe.length > 0 && (Array.isArray(probe) ? probe.some((v) => v !== 0) : true)) {
|
|
1392
1387
|
if (verbose) {
|
|
1393
|
-
console.log(`Loading
|
|
1388
|
+
console.log(`Loading monovector ONNX embedder (all-MiniLM-L6-v2, ${probe.length}d)...`);
|
|
1394
1389
|
}
|
|
1395
1390
|
embeddingModelState = {
|
|
1396
1391
|
loaded: true,
|
|
@@ -1401,14 +1396,14 @@ export async function loadEmbeddingModel(options) {
|
|
|
1401
1396
|
return {
|
|
1402
1397
|
success: true,
|
|
1403
1398
|
dimensions: probe.length || 384,
|
|
1404
|
-
modelName: '
|
|
1399
|
+
modelName: 'monovector/onnx',
|
|
1405
1400
|
loadTime: Date.now() - startTime
|
|
1406
1401
|
};
|
|
1407
1402
|
}
|
|
1408
1403
|
}
|
|
1409
1404
|
}
|
|
1410
1405
|
catch {
|
|
1411
|
-
//
|
|
1406
|
+
// monovector ONNX init failed, continue to next fallback
|
|
1412
1407
|
}
|
|
1413
1408
|
}
|
|
1414
1409
|
// Legacy fallback: Check for agentic-flow core embeddings
|
|
@@ -1481,7 +1476,7 @@ export async function generateEmbedding(text) {
|
|
|
1481
1476
|
if (state.model && typeof state.model === 'function') {
|
|
1482
1477
|
try {
|
|
1483
1478
|
const output = await state.model(text, { pooling: 'mean', normalize: true });
|
|
1484
|
-
// Handle both @xenova/transformers (output.data) and
|
|
1479
|
+
// Handle both @xenova/transformers (output.data) and monovector (plain array) formats
|
|
1485
1480
|
const embedding = output?.data
|
|
1486
1481
|
? Array.from(output.data)
|
|
1487
1482
|
: Array.isArray(output) ? output : null;
|
|
@@ -1822,13 +1817,14 @@ export async function storeEntry(options) {
|
|
|
1822
1817
|
// Add to HNSW index for faster future searches (validated to reject malformed embeddings)
|
|
1823
1818
|
if (embeddingJson) {
|
|
1824
1819
|
const embResult = safeParseEmbeddingLocal(embeddingJson);
|
|
1825
|
-
if (embResult)
|
|
1820
|
+
if (embResult) {
|
|
1826
1821
|
await addToHNSWIndex(id, embResult, {
|
|
1827
1822
|
id,
|
|
1828
1823
|
key,
|
|
1829
1824
|
namespace,
|
|
1830
1825
|
content: value
|
|
1831
1826
|
});
|
|
1827
|
+
}
|
|
1832
1828
|
}
|
|
1833
1829
|
return {
|
|
1834
1830
|
success: true,
|
|
@@ -1915,10 +1911,12 @@ export async function searchEntries(options) {
|
|
|
1915
1911
|
if (score < threshold) {
|
|
1916
1912
|
const lowerContent = (content || '').toLowerCase();
|
|
1917
1913
|
const lowerQuery = query.toLowerCase();
|
|
1918
|
-
const words = lowerQuery.split(/\s+/);
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1914
|
+
const words = lowerQuery.split(/\s+/).filter(w => w.length > 0);
|
|
1915
|
+
if (words.length > 0) {
|
|
1916
|
+
const matchCount = words.filter(w => lowerContent.includes(w)).length;
|
|
1917
|
+
const keywordScore = matchCount / words.length * 0.5;
|
|
1918
|
+
score = Math.max(score, keywordScore);
|
|
1919
|
+
}
|
|
1922
1920
|
}
|
|
1923
1921
|
if (score >= threshold) {
|
|
1924
1922
|
results.push({
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability surface for the (removed) @monoes/* native learning packages.
|
|
3
|
+
*
|
|
4
|
+
* Lean teardown: the SONA / native / WASM learning layer (@monoes/sona, router,
|
|
5
|
+
* attention, learning-wasm, core, and @monomind/monovector-upstream) has been
|
|
6
|
+
* removed. This module is now a stub that always reports "nothing native is
|
|
7
|
+
* available", so every caller takes the pure-JS / keyword-routing path. The
|
|
8
|
+
* function and type surface is preserved so importers (index.ts, hooks-tools.ts,
|
|
9
|
+
* doctor.ts, neural.ts) keep compiling without change.
|
|
10
|
+
*/
|
|
11
|
+
export interface MonoesCapabilities {
|
|
12
|
+
/** @monoes/sona SonaEngine available — always false after teardown */
|
|
13
|
+
sona: boolean;
|
|
14
|
+
/** @monoes/router backend — always 'none' after teardown */
|
|
15
|
+
router: 'native' | 'js' | 'none';
|
|
16
|
+
/** @monoes/attention FlashAttention available — always false after teardown */
|
|
17
|
+
attention: boolean;
|
|
18
|
+
/** @monoes/learning-wasm WasmMicroLoRA available — always false after teardown */
|
|
19
|
+
learningWasm: boolean;
|
|
20
|
+
/** @monomind/monovector-upstream plugin loaded — always false after teardown */
|
|
21
|
+
upstreamPlugin: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns the stubbed capability surface — all native backends report absent.
|
|
25
|
+
* Async to preserve the original signature; callers `await` this everywhere.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCapabilities(): Promise<MonoesCapabilities>;
|
|
28
|
+
/** Synchronous read of the (constant) capability surface. */
|
|
29
|
+
export declare function getCachedCapabilities(): MonoesCapabilities | null;
|
|
30
|
+
/** No-op after teardown — there is nothing to re-probe. */
|
|
31
|
+
export declare function resetCapabilitiesCache(): void;
|
|
32
|
+
/** Returns the stubbed capability surface — kept for API compatibility. */
|
|
33
|
+
export declare function refreshCapabilities(): Promise<MonoesCapabilities>;
|
|
34
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability surface for the (removed) @monoes/* native learning packages.
|
|
3
|
+
*
|
|
4
|
+
* Lean teardown: the SONA / native / WASM learning layer (@monoes/sona, router,
|
|
5
|
+
* attention, learning-wasm, core, and @monomind/monovector-upstream) has been
|
|
6
|
+
* removed. This module is now a stub that always reports "nothing native is
|
|
7
|
+
* available", so every caller takes the pure-JS / keyword-routing path. The
|
|
8
|
+
* function and type surface is preserved so importers (index.ts, hooks-tools.ts,
|
|
9
|
+
* doctor.ts, neural.ts) keep compiling without change.
|
|
10
|
+
*/
|
|
11
|
+
const STUB_CAPABILITIES = {
|
|
12
|
+
sona: false,
|
|
13
|
+
router: 'none',
|
|
14
|
+
attention: false,
|
|
15
|
+
learningWasm: false,
|
|
16
|
+
upstreamPlugin: false,
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Returns the stubbed capability surface — all native backends report absent.
|
|
20
|
+
* Async to preserve the original signature; callers `await` this everywhere.
|
|
21
|
+
*/
|
|
22
|
+
export async function getCapabilities() {
|
|
23
|
+
return STUB_CAPABILITIES;
|
|
24
|
+
}
|
|
25
|
+
/** Synchronous read of the (constant) capability surface. */
|
|
26
|
+
export function getCachedCapabilities() {
|
|
27
|
+
return STUB_CAPABILITIES;
|
|
28
|
+
}
|
|
29
|
+
/** No-op after teardown — there is nothing to re-probe. */
|
|
30
|
+
export function resetCapabilitiesCache() {
|
|
31
|
+
/* no-op */
|
|
32
|
+
}
|
|
33
|
+
/** Returns the stubbed capability surface — kept for API compatibility. */
|
|
34
|
+
export async function refreshCapabilities() {
|
|
35
|
+
return STUB_CAPABILITIES;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface CommandOutcome {
|
|
2
|
+
ts: number;
|
|
3
|
+
command: string;
|
|
4
|
+
exitCode: number;
|
|
5
|
+
success: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Append a command outcome. Non-fatal on error. */
|
|
8
|
+
export declare function recordCommand(baseDir: string, cmd: {
|
|
9
|
+
command: string;
|
|
10
|
+
exitCode: number;
|
|
11
|
+
ts: number;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Derive a measured success signal from recent command outcomes.
|
|
15
|
+
* Returns:
|
|
16
|
+
* - true if the most recent command(s) in-window ended in a good (final) state
|
|
17
|
+
* - false if the task ended on a failing command
|
|
18
|
+
* - null if there are no recent commands (no signal — caller should treat as unknown)
|
|
19
|
+
*
|
|
20
|
+
* Heuristic: FINAL-STATE — the exit code of the LAST command in the window.
|
|
21
|
+
* Within a task the dominant workflow is iterate-until-green (run tests → fail → fix →
|
|
22
|
+
* run tests → pass), so the task is judged by the state it ENDED in, not by whether any
|
|
23
|
+
* intermediate command failed. "All must pass" would produce pervasive false failures
|
|
24
|
+
* because benign commands routinely exit non-zero (`grep` no-match → 1, `test -f`, `diff`)
|
|
25
|
+
* and the fail-then-pass shape is the norm. Using the last command correctly scores
|
|
26
|
+
* fail→fix→pass as success and ends-on-failure as failure.
|
|
27
|
+
*
|
|
28
|
+
* Known limitation: the store is global (not task-scoped — no taskId exists at command
|
|
29
|
+
* time), so a trailing benign command after a real failure (e.g. `git status` after a
|
|
30
|
+
* failed test) could mask it, and the final command of a prior task could bleed in if a
|
|
31
|
+
* new task records no commands of its own. The time window bounds the latter; per-task
|
|
32
|
+
* scoping would require threading a taskId into post-command.
|
|
33
|
+
*/
|
|
34
|
+
export declare function deriveRecentSuccess(baseDir: string, windowMs?: number): Promise<boolean | null>;
|
|
35
|
+
/** Read recent command outcomes (for diagnostics). */
|
|
36
|
+
export declare function readCommandOutcomes(baseDir: string, windowMs?: number): Promise<CommandOutcome[]>;
|
|
37
|
+
//# sourceMappingURL=command-outcomes.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-windowed command outcome store. Lets post-task derive a MEASURED task
|
|
3
|
+
* success signal from real command exit codes, instead of trusting a
|
|
4
|
+
* caller-supplied --success flag.
|
|
5
|
+
*/
|
|
6
|
+
import { promises as fs } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
function storePath(baseDir) {
|
|
9
|
+
return join(baseDir, 'command-outcomes.jsonl');
|
|
10
|
+
}
|
|
11
|
+
/** Append a command outcome. Non-fatal on error. */
|
|
12
|
+
export async function recordCommand(baseDir, cmd) {
|
|
13
|
+
try {
|
|
14
|
+
await fs.mkdir(baseDir, { recursive: true });
|
|
15
|
+
const rec = { ts: cmd.ts, command: cmd.command, exitCode: cmd.exitCode, success: cmd.exitCode === 0 };
|
|
16
|
+
await fs.appendFile(storePath(baseDir), JSON.stringify(rec) + '\n', 'utf8');
|
|
17
|
+
// Opportunistic trim: keep file bounded (last 500 lines) to avoid unbounded growth
|
|
18
|
+
// (cheap: only rewrite when it gets large)
|
|
19
|
+
}
|
|
20
|
+
catch { /* non-fatal */ }
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Derive a measured success signal from recent command outcomes.
|
|
24
|
+
* Returns:
|
|
25
|
+
* - true if the most recent command(s) in-window ended in a good (final) state
|
|
26
|
+
* - false if the task ended on a failing command
|
|
27
|
+
* - null if there are no recent commands (no signal — caller should treat as unknown)
|
|
28
|
+
*
|
|
29
|
+
* Heuristic: FINAL-STATE — the exit code of the LAST command in the window.
|
|
30
|
+
* Within a task the dominant workflow is iterate-until-green (run tests → fail → fix →
|
|
31
|
+
* run tests → pass), so the task is judged by the state it ENDED in, not by whether any
|
|
32
|
+
* intermediate command failed. "All must pass" would produce pervasive false failures
|
|
33
|
+
* because benign commands routinely exit non-zero (`grep` no-match → 1, `test -f`, `diff`)
|
|
34
|
+
* and the fail-then-pass shape is the norm. Using the last command correctly scores
|
|
35
|
+
* fail→fix→pass as success and ends-on-failure as failure.
|
|
36
|
+
*
|
|
37
|
+
* Known limitation: the store is global (not task-scoped — no taskId exists at command
|
|
38
|
+
* time), so a trailing benign command after a real failure (e.g. `git status` after a
|
|
39
|
+
* failed test) could mask it, and the final command of a prior task could bleed in if a
|
|
40
|
+
* new task records no commands of its own. The time window bounds the latter; per-task
|
|
41
|
+
* scoping would require threading a taskId into post-command.
|
|
42
|
+
*/
|
|
43
|
+
export async function deriveRecentSuccess(baseDir, windowMs = 300_000) {
|
|
44
|
+
try {
|
|
45
|
+
const content = await fs.readFile(storePath(baseDir), 'utf8').catch(() => '');
|
|
46
|
+
if (!content)
|
|
47
|
+
return null;
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
const recent = [];
|
|
50
|
+
for (const line of content.trim().split('\n')) {
|
|
51
|
+
try {
|
|
52
|
+
const rec = JSON.parse(line);
|
|
53
|
+
if (now - rec.ts <= windowMs)
|
|
54
|
+
recent.push(rec);
|
|
55
|
+
}
|
|
56
|
+
catch { /* skip malformed */ }
|
|
57
|
+
}
|
|
58
|
+
if (recent.length === 0)
|
|
59
|
+
return null;
|
|
60
|
+
// Final-state: the last command in the window decides the outcome.
|
|
61
|
+
return recent[recent.length - 1].success;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Read recent command outcomes (for diagnostics). */
|
|
68
|
+
export async function readCommandOutcomes(baseDir, windowMs = 300_000) {
|
|
69
|
+
try {
|
|
70
|
+
const content = await fs.readFile(storePath(baseDir), 'utf8').catch(() => '');
|
|
71
|
+
if (!content)
|
|
72
|
+
return [];
|
|
73
|
+
const now = Date.now();
|
|
74
|
+
return content.trim().split('\n').map(l => {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(l);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}).filter((r) => r !== null && now - r.ts <= windowMs);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=command-outcomes.js.map
|