blun-king-cli 9.1.567 → 9.1.569
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/agent-spine-plugin/.claude-plugin/marketplace.json +1 -1
- package/agent-spine-plugin/.claude-plugin/plugin.json +1 -1
- package/agent-spine-plugin/.codex-plugin/plugin.json +2 -1
- package/agent-spine-plugin/CHANGELOG.md +1581 -0
- package/agent-spine-plugin/README.md +30 -4
- package/agent-spine-plugin/blun.plugin.json +3 -3
- package/agent-spine-plugin/docs/acceptance.md +61 -0
- package/agent-spine-plugin/docs/assignment-continuation.md +48 -0
- package/agent-spine-plugin/docs/host-integration.md +178 -0
- package/agent-spine-plugin/docs/preflight-recall.md +69 -0
- package/agent-spine-plugin/docs/preservation-contract.md +53 -0
- package/agent-spine-plugin/docs/quality-gates.md +50 -0
- package/agent-spine-plugin/docs/releasing.md +85 -0
- package/agent-spine-plugin/docs/session-timeline.md +251 -0
- package/agent-spine-plugin/docs/source-roots.md +113 -0
- package/agent-spine-plugin/docs/structured-completion.md +67 -0
- package/agent-spine-plugin/docs/world-model.md +94 -0
- package/agent-spine-plugin/hooks/codex.json +2 -2
- package/agent-spine-plugin/hooks/hooks.json +1 -1
- package/agent-spine-plugin/hooks/version.json +1 -1
- package/agent-spine-plugin/package.json +13 -3
- package/agent-spine-plugin/scripts/check-codex-install.js +226 -0
- package/agent-spine-plugin/scripts/check-hosts.js +14 -5
- package/agent-spine-plugin/scripts/check-install-hook.js +226 -0
- package/agent-spine-plugin/scripts/check-install-selfstarter.js +154 -0
- package/agent-spine-plugin/scripts/check-install.js +478 -0
- package/agent-spine-plugin/scripts/check-line-budget.js +58 -0
- package/agent-spine-plugin/scripts/check-syntax.js +29 -0
- package/agent-spine-plugin/scripts/github-actions.js +11 -0
- package/agent-spine-plugin/scripts/hermetic-process.js +183 -0
- package/agent-spine-plugin/scripts/release-check.js +145 -0
- package/agent-spine-plugin/scripts/run-acceptance.js +19 -0
- package/agent-spine-plugin/scripts/run-checks.js +47 -0
- package/agent-spine-plugin/scripts/run-tests-hermetic.js +89 -0
- package/agent-spine-plugin/skills/agent-spine/SKILL.md +16 -2
- package/agent-spine-plugin/spine-example/1-identity.md +12 -0
- package/agent-spine-plugin/spine-example/2-voice.md +6 -0
- package/agent-spine-plugin/spine-example/3-conduct.md +8 -0
- package/agent-spine-plugin/spine-example/4-history.md +4 -0
- package/agent-spine-plugin/src/cli-agent.js +296 -0
- package/agent-spine-plugin/src/cli-attention.js +95 -0
- package/agent-spine-plugin/src/cli-autonomy.js +36 -0
- package/agent-spine-plugin/src/cli-common.js +71 -0
- package/agent-spine-plugin/src/cli-continuity.js +116 -0
- package/agent-spine-plugin/src/cli-core.js +128 -0
- package/agent-spine-plugin/src/cli-diagnostics.js +291 -0
- package/agent-spine-plugin/src/cli-host.js +21 -0
- package/agent-spine-plugin/src/cli-learning.js +305 -0
- package/agent-spine-plugin/src/cli-premortem.js +16 -0
- package/agent-spine-plugin/src/cli-sharing.js +230 -0
- package/agent-spine-plugin/src/cli.js +40 -1350
- package/agent-spine-plugin/src/codex-reader-launcher.js +182 -0
- package/agent-spine-plugin/src/hook.js +185 -567
- package/agent-spine-plugin/src/index.js +16 -2
- package/agent-spine-plugin/src/lib/acceptance.js +113 -11
- package/agent-spine-plugin/src/lib/action-lesson-recall.js +53 -0
- package/agent-spine-plugin/src/lib/attention-context.js +167 -0
- package/agent-spine-plugin/src/lib/attention-events.js +113 -0
- package/agent-spine-plugin/src/lib/attention-privacy.js +72 -0
- package/agent-spine-plugin/src/lib/attention-schema.js +164 -0
- package/agent-spine-plugin/src/lib/attention-storage.js +93 -0
- package/agent-spine-plugin/src/lib/attention.js +9 -600
- package/agent-spine-plugin/src/lib/audit-premortem.js +223 -0
- package/agent-spine-plugin/src/lib/audit.js +56 -6
- package/agent-spine-plugin/src/lib/autonomy-policy.js +110 -0
- package/agent-spine-plugin/src/lib/autonomy-store.js +202 -0
- package/agent-spine-plugin/src/lib/autonomy.js +8 -0
- package/agent-spine-plugin/src/lib/briefing.js +67 -4
- package/agent-spine-plugin/src/lib/catalog-document-read.js +51 -0
- package/agent-spine-plugin/src/lib/catalog.js +1 -1
- package/agent-spine-plugin/src/lib/codex-installation.js +231 -0
- package/agent-spine-plugin/src/lib/codex-skill-installation.js +211 -0
- package/agent-spine-plugin/src/lib/context.js +3 -1
- package/agent-spine-plugin/src/lib/delivery-agent-usage.js +224 -0
- package/agent-spine-plugin/src/lib/delivery-assignment.js +220 -0
- package/agent-spine-plugin/src/lib/delivery-command-actions.js +453 -0
- package/agent-spine-plugin/src/lib/delivery-knowledge.js +78 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +107 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +171 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +45 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +101 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-file.js +21 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-index.js +493 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +37 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +120 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +65 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-results.js +28 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +46 -0
- package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +285 -0
- package/agent-spine-plugin/src/lib/delivery-premortem.js +499 -0
- package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +115 -0
- package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +111 -0
- package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +64 -0
- package/agent-spine-plugin/src/lib/delivery-target.js +73 -0
- package/agent-spine-plugin/src/lib/delivery-verification.js +445 -0
- package/agent-spine-plugin/src/lib/documents.js +27 -5
- package/agent-spine-plugin/src/lib/filesystem-retry.js +2 -0
- package/agent-spine-plugin/src/lib/gateway-common.js +68 -0
- package/agent-spine-plugin/src/lib/gateway-control.js +302 -0
- package/agent-spine-plugin/src/lib/gateway-delivery.js +103 -0
- package/agent-spine-plugin/src/lib/gateway-execution.js +350 -0
- package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +185 -0
- package/agent-spine-plugin/src/lib/gateway-inspection.js +85 -0
- package/agent-spine-plugin/src/lib/gateway-knowledge.js +129 -0
- package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +197 -0
- package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +82 -0
- package/agent-spine-plugin/src/lib/gateway-premortem.js +363 -0
- package/agent-spine-plugin/src/lib/gateway-runs.js +300 -0
- package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +31 -0
- package/agent-spine-plugin/src/lib/gateway-runtime-records.js +21 -0
- package/agent-spine-plugin/src/lib/gateway-runtime.js +18 -1623
- package/agent-spine-plugin/src/lib/gateway-state-transaction.js +356 -0
- package/agent-spine-plugin/src/lib/gateway-state.js +342 -0
- package/agent-spine-plugin/src/lib/hook-artifact-guards.js +356 -0
- package/agent-spine-plugin/src/lib/hook-audit.js +16 -2
- package/agent-spine-plugin/src/lib/hook-briefing-use.js +68 -0
- package/agent-spine-plugin/src/lib/hook-context.js +424 -0
- package/agent-spine-plugin/src/lib/hook-final-message.js +26 -0
- package/agent-spine-plugin/src/lib/hook-input.js +27 -0
- package/agent-spine-plugin/src/lib/hook-output.js +140 -0
- package/agent-spine-plugin/src/lib/hook-premortem.js +257 -0
- package/agent-spine-plugin/src/lib/hook-process-advisory.js +37 -0
- package/agent-spine-plugin/src/lib/hook-protection.js +95 -0
- package/agent-spine-plugin/src/lib/hook-stop-verification.js +84 -0
- package/agent-spine-plugin/src/lib/hook-timeline.js +91 -0
- package/agent-spine-plugin/src/lib/identifier-analysis.js +446 -0
- package/agent-spine-plugin/src/lib/indexed-memory.js +23 -6
- package/agent-spine-plugin/src/lib/knowledge-evidence.js +431 -0
- package/agent-spine-plugin/src/lib/learning-applications.js +441 -0
- package/agent-spine-plugin/src/lib/learning-candidates.js +274 -0
- package/agent-spine-plugin/src/lib/learning-context.js +130 -0
- package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +310 -0
- package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +350 -0
- package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +372 -0
- package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +292 -0
- package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +321 -0
- package/agent-spine-plugin/src/lib/learning-findings.js +458 -0
- package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +285 -0
- package/agent-spine-plugin/src/lib/learning-measurements.js +265 -0
- package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +165 -0
- package/agent-spine-plugin/src/lib/learning-outcomes.js +343 -0
- package/agent-spine-plugin/src/lib/learning-reconciliation.js +290 -0
- package/agent-spine-plugin/src/lib/learning-retry-contracts.js +188 -0
- package/agent-spine-plugin/src/lib/learning-schema.js +229 -0
- package/agent-spine-plugin/src/lib/learning-scope-targets.js +424 -0
- package/agent-spine-plugin/src/lib/learning-state-upgrade.js +477 -0
- package/agent-spine-plugin/src/lib/learning-status-configuration.js +476 -0
- package/agent-spine-plugin/src/lib/learning-storage.js +203 -0
- package/agent-spine-plugin/src/lib/learning-trial-recovery.js +218 -0
- package/agent-spine-plugin/src/lib/learning-validation-contracts.js +375 -0
- package/agent-spine-plugin/src/lib/learning-validation-renewal.js +298 -0
- package/agent-spine-plugin/src/lib/learning-validation-runtime.js +234 -0
- package/agent-spine-plugin/src/lib/learning.js +36 -6923
- package/agent-spine-plugin/src/lib/lesson-recall-session.js +172 -0
- package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +37 -0
- package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +124 -0
- package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +45 -0
- package/agent-spine-plugin/src/lib/mcp-premortem.js +68 -0
- package/agent-spine-plugin/src/lib/mcp-runtime.js +269 -0
- package/agent-spine-plugin/src/lib/mcp-source-context.js +51 -0
- package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +164 -0
- package/agent-spine-plugin/src/lib/mcp-world-tools.js +52 -0
- package/agent-spine-plugin/src/lib/owned-file-lock.js +30 -10
- package/agent-spine-plugin/src/lib/project-portfolio.js +176 -0
- package/agent-spine-plugin/src/lib/selfstarter-core.js +382 -0
- package/agent-spine-plugin/src/lib/selfstarter-jobs.js +149 -0
- package/agent-spine-plugin/src/lib/selfstarter-lease.js +204 -0
- package/agent-spine-plugin/src/lib/selfstarter-policy.js +90 -0
- package/agent-spine-plugin/src/lib/selfstarter-workspace.js +111 -0
- package/agent-spine-plugin/src/lib/selfstarter.js +11 -911
- package/agent-spine-plugin/src/lib/session-timeline-auth.js +316 -0
- package/agent-spine-plugin/src/lib/session-timeline-codex.js +58 -0
- package/agent-spine-plugin/src/lib/session-timeline-contract.js +48 -0
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +41 -0
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +132 -0
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +17 -0
- package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +500 -0
- package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +157 -0
- package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +74 -0
- package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +117 -0
- package/agent-spine-plugin/src/lib/session-timeline-invocation.js +201 -0
- package/agent-spine-plugin/src/lib/session-timeline-king.js +79 -0
- package/agent-spine-plugin/src/lib/session-timeline-prior.js +59 -0
- package/agent-spine-plugin/src/lib/session-timeline-provider.js +34 -0
- package/agent-spine-plugin/src/lib/session-timeline-query.js +55 -0
- package/agent-spine-plugin/src/lib/session-timeline-results.js +31 -0
- package/agent-spine-plugin/src/lib/session-timeline-root.js +11 -0
- package/agent-spine-plugin/src/lib/session-timeline-search.js +82 -0
- package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +217 -0
- package/agent-spine-plugin/src/lib/session-timeline-source.js +83 -0
- package/agent-spine-plugin/src/lib/session-timeline-state.js +45 -0
- package/agent-spine-plugin/src/lib/session-timeline-transport.js +50 -0
- package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +148 -0
- package/agent-spine-plugin/src/lib/session-timeline.js +453 -0
- package/agent-spine-plugin/src/lib/source-roots.js +69 -136
- package/agent-spine-plugin/src/lib/source-tree-scan.js +178 -0
- package/agent-spine-plugin/src/lib/task-knowledge-context.js +78 -0
- package/agent-spine-plugin/src/lib/timeline-tool-guard.js +202 -0
- package/agent-spine-plugin/src/lib/world-knowledge.js +249 -0
- package/agent-spine-plugin/src/lib/world-model.js +278 -0
- package/agent-spine-plugin/src/mcp.js +20 -161
- package/agent-spine-plugin/src/version.js +1 -1
- package/agent-spine-plugin/src/worker.js +22 -5
- package/bin/agent-resume-snapshot.cjs +2 -2
- package/bin/agentspine-king-goal-inbox.mjs +111 -0
- package/bin/agentspine-king-goal-intake.mjs +106 -0
- package/bin/baseline-skill-performance-policy.cjs +1 -16
- package/bin/core-bootstrap.js +2 -0
- package/bin/curiosity-scout-policy.cjs +5 -1
- package/bin/input-draft-persistence.cjs +2 -2
- package/bin/king-tui-function-contract.json +33 -0
- package/bin/launcher-restart-policy.cjs +150 -0
- package/bin/launcher-runtime.js +56 -44
- package/bin/managed-context-startup-policy.cjs +27 -0
- package/bin/managed-plugin-selection.cjs +116 -0
- package/bin/mistake-relevance-policy.cjs +1 -1
- package/bin/observer-hooks.cjs +14 -0
- package/bin/oversized-context-offload-policy.cjs +86 -0
- package/bin/plugin-bootstrap.js +7 -40
- package/bin/proactive-compaction-policy.cjs +1 -1
- package/bin/provider-model-refresh-deadline.cjs +53 -0
- package/bin/provider-model-refresh-policy.cjs +107 -0
- package/bin/release-artifact-freeze-policy.cjs +30 -0
- package/bin/repeated-user-message-projection.cjs +3 -126
- package/bin/research-page-result.cjs +74 -0
- package/bin/runtime-exit-ledger.cjs +1 -0
- package/bin/session-compaction-policy.cjs +84 -0
- package/bin/skill-listing-performance-policy.cjs +2 -2
- package/bin/standard-tools-bootstrap.js +0 -37
- package/bin/subagent-skill-policy.cjs +3 -1
- package/bin/telegram-approval-relay.cjs +12 -7
- package/bin/telegram-private-conversation-policy.cjs +3 -2
- package/bin/telegram-queue-handoff-policy.cjs +24 -0
- package/bin/thinking-activity-status-policy.cjs +1 -1
- package/bin/thinking-only-guard.cjs +16 -12
- package/bin/tool-call-loop-policy.cjs +0 -2
- package/bin/tool-result-offload-policy.cjs +11 -2
- package/bin/tui-functional-contract.cjs +55 -0
- package/bin/update-notice.js +18 -14
- package/bin/user-message-offload-policy.cjs +1 -1
- package/bin/user-prompt-hook-origin-policy.cjs +34 -0
- package/bin/windows-node-crash-dump.cjs +110 -0
- package/blun.mjs +2517 -1048
- package/codebase-index/codebase_index.py +4 -3
- package/package.json +3 -17
- package/standard-skills/research-evidence/SKILL.md +39 -0
- package/standard-skills/research-evidence/references/evidence-format.md +82 -0
- package/standard-skills/research-evidence/scripts/evidence-collection.cjs +254 -0
- package/standard-skills/research-evidence/scripts/score-report.cjs +112 -0
- package/standard-skills/web-lesen/SKILL.md +37 -22
- package/standard-skills/web-lesen/scripts/crawl_public.py +376 -0
- package/telegram-plugin/DELIVERY.md +36 -0
- package/telegram-plugin/bin/telegram-approval-relay.cjs +13 -7
- package/telegram-plugin/bin/telegram-launcher-status-queue.cjs +122 -0
- package/telegram-plugin/bin/telegram-private-conversation-policy.cjs +3 -2
- package/telegram-plugin/bin/telegram-reply-parts.cjs +149 -0
- package/telegram-plugin/dist/bridge.mjs +7 -56
- package/telegram-plugin/dist/mcp-server.mjs +33 -4
- package/agent-spine-plugin/skill/SKILL.md +0 -76
- package/bin/mnemo-connect-heartbeat.cjs +0 -204
- package/bin/mnemo-tool-agent-policy.cjs +0 -22
- package/telegram-plugin/bin/telegram-mnemo-capture.cjs +0 -297
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
const STATIC_GLOBALS = new Set([
|
|
2
|
+
"AbortController", "AbortSignal", "Array", "ArrayBuffer", "Atomics", "BigInt", "BigInt64Array",
|
|
3
|
+
"BigUint64Array", "Blob", "Boolean", "Buffer", "console", "crypto", "CustomEvent", "DataView", "Date",
|
|
4
|
+
"decodeURI", "decodeURIComponent", "document", "DOMException", "encodeURI", "encodeURIComponent",
|
|
5
|
+
"Error", "escape", "eval", "EvalError", "Event", "EventTarget", "exports", "fetch", "File",
|
|
6
|
+
"FinalizationRegistry", "Float32Array", "Float64Array", "FormData", "Function", "global", "globalThis",
|
|
7
|
+
"Headers", "history", "Infinity", "Int16Array", "Int32Array", "Int8Array", "Intl", "isFinite", "isNaN",
|
|
8
|
+
"JSON", "location", "Map", "Math", "MessageChannel", "MessageEvent", "MessagePort", "module", "NaN",
|
|
9
|
+
"navigator", "Number", "Object", "parseFloat", "parseInt", "performance", "process", "Promise", "Proxy",
|
|
10
|
+
"queueMicrotask", "RangeError", "ReadableStream", "ReferenceError", "Reflect", "RegExp", "Request",
|
|
11
|
+
"require", "Response", "self", "Set", "setImmediate", "setInterval", "setTimeout", "SharedArrayBuffer",
|
|
12
|
+
"String", "structuredClone", "Symbol", "SyntaxError", "TextDecoder", "TextEncoder", "TransformStream",
|
|
13
|
+
"TypeError", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray", "undefined", "unescape",
|
|
14
|
+
"URIError", "URL", "URLSearchParams", "WeakMap", "WeakRef", "WeakSet", "WebAssembly", "window",
|
|
15
|
+
"WritableStream", "clearImmediate", "clearInterval", "clearTimeout", "__dirname", "__filename"
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const KEYWORDS = new Set([
|
|
19
|
+
"await", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do",
|
|
20
|
+
"else", "enum", "export", "extends", "false", "finally", "for", "function", "if", "import", "in",
|
|
21
|
+
"instanceof", "let", "new", "null", "return", "super", "switch", "this", "throw", "true", "try",
|
|
22
|
+
"typeof", "var", "void", "while", "with", "yield"
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const REGEX_PREFIXES = new Set([
|
|
26
|
+
"(", "[", "{", "}", ",", ";", ":", "=", "=>", "!", "?", "&&", "||", "??", "return", "throw",
|
|
27
|
+
"case", "delete", "typeof", "void", "in", "of", "await", "yield", "else", "do"
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const CONTROL_HEADS = new Set(["catch", "for", "if", "switch", "while", "with"]);
|
|
31
|
+
const IDENTIFIER_START = /^[$_\p{ID_Start}]$/u;
|
|
32
|
+
const IDENTIFIER_PART = /^[$_\u200C\u200D\p{ID_Continue}]$/u;
|
|
33
|
+
|
|
34
|
+
function codePoint(source, index) {
|
|
35
|
+
return String.fromCodePoint(source.codePointAt(index));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function templateExpressionEnd(source, start) {
|
|
39
|
+
let depth = 1;
|
|
40
|
+
let index = start;
|
|
41
|
+
const skipString = (quote) => {
|
|
42
|
+
index += 1;
|
|
43
|
+
while (index < source.length) {
|
|
44
|
+
if (source[index] === "\\") index += 2;
|
|
45
|
+
else if (source[index] === quote) { index += 1; return; }
|
|
46
|
+
else index += 1;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const skipTemplate = () => {
|
|
50
|
+
index += 1;
|
|
51
|
+
while (index < source.length) {
|
|
52
|
+
if (source[index] === "\\") { index += 2; continue; }
|
|
53
|
+
if (source[index] === "`") { index += 1; return; }
|
|
54
|
+
if (source.startsWith("${", index)) {
|
|
55
|
+
const end = templateExpressionEnd(source, index + 2);
|
|
56
|
+
index = end < 0 ? source.length : end + 1;
|
|
57
|
+
} else index += 1;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
while (index < source.length) {
|
|
61
|
+
if (["'", "\""].includes(source[index])) { skipString(source[index]); continue; }
|
|
62
|
+
if (source[index] === "`") { skipTemplate(); continue; }
|
|
63
|
+
if (source.startsWith("//", index)) {
|
|
64
|
+
const newline = source.indexOf("\n", index + 2);
|
|
65
|
+
index = newline < 0 ? source.length : newline + 1;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (source.startsWith("/*", index)) {
|
|
69
|
+
const end = source.indexOf("*/", index + 2);
|
|
70
|
+
index = end < 0 ? source.length : end + 2;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (source[index] === "{") depth += 1;
|
|
74
|
+
else if (source[index] === "}" && --depth === 0) return index;
|
|
75
|
+
index += 1;
|
|
76
|
+
}
|
|
77
|
+
return -1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function tokenize(source) {
|
|
81
|
+
const tokens = [];
|
|
82
|
+
let index = 0;
|
|
83
|
+
let line = 1;
|
|
84
|
+
const push = (value, kind = "punctuator", atLine = line) => tokens.push({ value, line: atLine, kind });
|
|
85
|
+
const skipQuoted = (quote) => {
|
|
86
|
+
push("<literal>", "literal");
|
|
87
|
+
index += 1;
|
|
88
|
+
while (index < source.length) {
|
|
89
|
+
if (source[index] === "\n") line += 1;
|
|
90
|
+
if (source[index] === "\\") index += 2;
|
|
91
|
+
else if (source[index] === quote) { index += 1; break; }
|
|
92
|
+
else index += 1;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const skipTemplate = () => {
|
|
96
|
+
index += 1;
|
|
97
|
+
while (index < source.length) {
|
|
98
|
+
if (source[index] === "\n") { line += 1; index += 1; continue; }
|
|
99
|
+
if (source[index] === "\\") { index += 2; continue; }
|
|
100
|
+
if (source[index] === "`") { index += 1; return; }
|
|
101
|
+
if (source.startsWith("${", index)) {
|
|
102
|
+
const startLine = line;
|
|
103
|
+
const start = index + 2;
|
|
104
|
+
const end = templateExpressionEnd(source, start);
|
|
105
|
+
if (end < 0) { index = source.length; return; }
|
|
106
|
+
for (const token of tokenize(source.slice(start, end))) {
|
|
107
|
+
push(token.value, token.kind, startLine + token.line - 1);
|
|
108
|
+
}
|
|
109
|
+
line += (source.slice(start, end).match(/\n/g) || []).length;
|
|
110
|
+
index = end + 1;
|
|
111
|
+
} else index += 1;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const skipRegex = () => {
|
|
115
|
+
const previous = tokens.at(-1)?.value;
|
|
116
|
+
let allowed = !previous || REGEX_PREFIXES.has(previous);
|
|
117
|
+
if (!allowed && previous === ")") {
|
|
118
|
+
const open = matchingOpen(tokens, tokens.length - 1);
|
|
119
|
+
allowed = open > 0 && CONTROL_HEADS.has(tokens[open - 1].value);
|
|
120
|
+
}
|
|
121
|
+
if (!allowed) return false;
|
|
122
|
+
let cursor = index + 1;
|
|
123
|
+
let characterClass = false;
|
|
124
|
+
while (cursor < source.length) {
|
|
125
|
+
const current = source[cursor];
|
|
126
|
+
if (current === "\n" || current === "\r") return false;
|
|
127
|
+
if (current === "\\") { cursor += 2; continue; }
|
|
128
|
+
if (current === "[") characterClass = true;
|
|
129
|
+
else if (current === "]") characterClass = false;
|
|
130
|
+
else if (current === "/" && !characterClass) {
|
|
131
|
+
cursor += 1;
|
|
132
|
+
while (/[A-Za-z]/.test(source[cursor] || "")) cursor += 1;
|
|
133
|
+
index = cursor;
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
cursor += 1;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
};
|
|
140
|
+
while (index < source.length) {
|
|
141
|
+
const character = source[index];
|
|
142
|
+
if (character === "\n") { line += 1; index += 1; continue; }
|
|
143
|
+
if (/\s/.test(character)) { index += 1; continue; }
|
|
144
|
+
if (source.startsWith("//", index)) {
|
|
145
|
+
index = source.indexOf("\n", index);
|
|
146
|
+
if (index < 0) break;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (source.startsWith("/*", index)) {
|
|
150
|
+
const end = source.indexOf("*/", index + 2);
|
|
151
|
+
const stop = end < 0 ? source.length : end + 2;
|
|
152
|
+
line += (source.slice(index, stop).match(/\n/g) || []).length;
|
|
153
|
+
index = stop;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (character === "/" && skipRegex()) continue;
|
|
157
|
+
if (["'", "\""].includes(character)) { skipQuoted(character); continue; }
|
|
158
|
+
if (character === "`") { skipTemplate(); continue; }
|
|
159
|
+
const first = codePoint(source, index);
|
|
160
|
+
if (IDENTIFIER_START.test(first)) {
|
|
161
|
+
const start = index;
|
|
162
|
+
index += first.length;
|
|
163
|
+
while (index < source.length) {
|
|
164
|
+
const next = codePoint(source, index);
|
|
165
|
+
if (!IDENTIFIER_PART.test(next)) break;
|
|
166
|
+
index += next.length;
|
|
167
|
+
}
|
|
168
|
+
push(source.slice(start, index), "word");
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (/\d/.test(character)) {
|
|
172
|
+
const match = source.slice(index).match(/^(?:0[xob])?[\da-f._]+/i)[0];
|
|
173
|
+
push(match, "number");
|
|
174
|
+
index += match.length;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const operator = ["=>", "?.", "...", "===", "!==", "==", "!=", "<=", ">=", "&&", "||", "??"]
|
|
178
|
+
.find((value) => source.startsWith(value, index));
|
|
179
|
+
push(operator || character);
|
|
180
|
+
index += (operator || character).length;
|
|
181
|
+
}
|
|
182
|
+
return tokens;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function identifier(token) {
|
|
186
|
+
return Boolean(token?.kind === "word" && !KEYWORDS.has(token.value));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function matchingOpen(tokens, closeIndex) {
|
|
190
|
+
let depth = 0;
|
|
191
|
+
for (let index = closeIndex; index >= 0; index -= 1) {
|
|
192
|
+
if (tokens[index].value === ")") depth += 1;
|
|
193
|
+
else if (tokens[index].value === "(" && --depth === 0) return index;
|
|
194
|
+
}
|
|
195
|
+
return -1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function matchingClose(tokens, openIndex) {
|
|
199
|
+
const pairs = { "(": ")", "[": "]", "{": "}" };
|
|
200
|
+
const open = tokens[openIndex]?.value;
|
|
201
|
+
const close = pairs[open];
|
|
202
|
+
if (!close) return -1;
|
|
203
|
+
let depth = 0;
|
|
204
|
+
for (let index = openIndex; index < tokens.length; index += 1) {
|
|
205
|
+
if (tokens[index].value === open) depth += 1;
|
|
206
|
+
else if (tokens[index].value === close && --depth === 0) return index;
|
|
207
|
+
}
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function skipExpression(tokens, start, end, stops = new Set([","])) {
|
|
212
|
+
let depth = 0;
|
|
213
|
+
for (let index = start; index < tokens.length; index += 1) {
|
|
214
|
+
if (index >= end) return end;
|
|
215
|
+
const value = tokens[index].value;
|
|
216
|
+
if (depth === 0 && stops.has(value)) return index;
|
|
217
|
+
if (["(", "[", "{"].includes(value)) depth += 1;
|
|
218
|
+
else if ([")", "]", "}"].includes(value)) depth -= 1;
|
|
219
|
+
}
|
|
220
|
+
return end;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function collectBindingPattern(tokens, start, end, declared) {
|
|
224
|
+
let index = start;
|
|
225
|
+
if (tokens[index]?.value === "...") index += 1;
|
|
226
|
+
if (index >= end) return index;
|
|
227
|
+
if (identifier(tokens[index])) {
|
|
228
|
+
declared.add(tokens[index].value);
|
|
229
|
+
return index + 1;
|
|
230
|
+
}
|
|
231
|
+
const open = tokens[index]?.value;
|
|
232
|
+
if (!["[", "{"].includes(open)) return index + 1;
|
|
233
|
+
const close = matchingClose(tokens, index);
|
|
234
|
+
if (close < 0 || close > end) return end;
|
|
235
|
+
let cursor = index + 1;
|
|
236
|
+
while (cursor < close) {
|
|
237
|
+
if (tokens[cursor].value === ",") { cursor += 1; continue; }
|
|
238
|
+
let bindingHandled = false;
|
|
239
|
+
if (open === "{" && tokens[cursor].value !== "...") {
|
|
240
|
+
if (tokens[cursor].value === "[") {
|
|
241
|
+
const computedClose = matchingClose(tokens, cursor);
|
|
242
|
+
cursor = computedClose < 0 || computedClose >= close ? close : computedClose + 1;
|
|
243
|
+
if (tokens[cursor]?.value === ":") cursor += 1;
|
|
244
|
+
} else {
|
|
245
|
+
const key = tokens[cursor];
|
|
246
|
+
cursor += 1;
|
|
247
|
+
if (tokens[cursor]?.value === ":") cursor += 1;
|
|
248
|
+
else if (identifier(key)) {
|
|
249
|
+
declared.add(key.value);
|
|
250
|
+
bindingHandled = true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (!bindingHandled) {
|
|
255
|
+
const next = collectBindingPattern(tokens, cursor, close, declared);
|
|
256
|
+
if (next > cursor) cursor = next;
|
|
257
|
+
}
|
|
258
|
+
if (tokens[cursor]?.value === "=") cursor = skipExpression(tokens, cursor + 1, close);
|
|
259
|
+
else cursor = skipExpression(tokens, cursor, close);
|
|
260
|
+
if (tokens[cursor]?.value === ",") cursor += 1;
|
|
261
|
+
}
|
|
262
|
+
return close + 1;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function collectBindingList(tokens, start, end, declared) {
|
|
266
|
+
let cursor = start;
|
|
267
|
+
while (cursor < end) {
|
|
268
|
+
if (tokens[cursor].value === ",") { cursor += 1; continue; }
|
|
269
|
+
const next = collectBindingPattern(tokens, cursor, end, declared);
|
|
270
|
+
cursor = next > cursor ? next : cursor + 1;
|
|
271
|
+
if (tokens[cursor]?.value === "=") cursor = skipExpression(tokens, cursor + 1, end);
|
|
272
|
+
else cursor = skipExpression(tokens, cursor, end);
|
|
273
|
+
if (tokens[cursor]?.value === ",") cursor += 1;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function collectVariableBindings(tokens, start, declared) {
|
|
278
|
+
let end = start;
|
|
279
|
+
let depth = 0;
|
|
280
|
+
let initializerSeen = false;
|
|
281
|
+
const declaration = start - 1;
|
|
282
|
+
const inForHeader = tokens[declaration - 1]?.value === "("
|
|
283
|
+
&& (tokens[declaration - 2]?.value === "for"
|
|
284
|
+
|| (tokens[declaration - 2]?.value === "await" && tokens[declaration - 3]?.value === "for"));
|
|
285
|
+
while (end < tokens.length) {
|
|
286
|
+
const value = tokens[end].value;
|
|
287
|
+
if (depth === 0 && (value === ";"
|
|
288
|
+
|| (inForHeader && !initializerSeen && ["of", "in"].includes(value)))) break;
|
|
289
|
+
if (depth === 0 && value === "=") initializerSeen = true;
|
|
290
|
+
if (["(", "[", "{"].includes(value)) depth += 1;
|
|
291
|
+
else if ([")", "]", "}"].includes(value)) {
|
|
292
|
+
if (depth === 0) break;
|
|
293
|
+
depth -= 1;
|
|
294
|
+
}
|
|
295
|
+
end += 1;
|
|
296
|
+
}
|
|
297
|
+
collectBindingList(tokens, start, end, declared);
|
|
298
|
+
return end;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function collectImportBindings(tokens, start, declared) {
|
|
302
|
+
if (tokens[start]?.value === "(") return;
|
|
303
|
+
if (tokens[start]?.kind === "literal") return;
|
|
304
|
+
let end = start;
|
|
305
|
+
while (end < tokens.length && !["from", ";"].includes(tokens[end].value)) end += 1;
|
|
306
|
+
let cursor = start;
|
|
307
|
+
if (identifier(tokens[cursor])) {
|
|
308
|
+
declared.add(tokens[cursor].value);
|
|
309
|
+
cursor += 1;
|
|
310
|
+
if (tokens[cursor]?.value === ",") cursor += 1;
|
|
311
|
+
}
|
|
312
|
+
if (tokens[cursor]?.value === "*" && tokens[cursor + 1]?.value === "as"
|
|
313
|
+
&& identifier(tokens[cursor + 2])) declared.add(tokens[cursor + 2].value);
|
|
314
|
+
if (tokens[cursor]?.value !== "{") return;
|
|
315
|
+
const close = Math.min(matchingClose(tokens, cursor), end);
|
|
316
|
+
let itemStart = cursor + 1;
|
|
317
|
+
for (let index = itemStart; index <= close; index += 1) {
|
|
318
|
+
if (index < close && tokens[index].value !== ",") continue;
|
|
319
|
+
const item = tokens.slice(itemStart, index);
|
|
320
|
+
const alias = item.findIndex((token) => token.value === "as");
|
|
321
|
+
const local = alias >= 0
|
|
322
|
+
? item.slice(alias + 1).find(identifier)
|
|
323
|
+
: [...item].reverse().find(identifier);
|
|
324
|
+
if (local) declared.add(local.value);
|
|
325
|
+
itemStart = index + 1;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function classBodyOpens(tokens) {
|
|
330
|
+
const openings = new Set();
|
|
331
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
332
|
+
if (tokens[index].value !== "class" || tokens[index + 1]?.value === "("
|
|
333
|
+
|| [".", "?."].includes(tokens[index - 1]?.value)) continue;
|
|
334
|
+
let parentheses = 0;
|
|
335
|
+
let brackets = 0;
|
|
336
|
+
for (let cursor = index + 1; cursor < tokens.length; cursor += 1) {
|
|
337
|
+
const value = tokens[cursor].value;
|
|
338
|
+
if (value === "(") parentheses += 1;
|
|
339
|
+
else if (value === ")") parentheses -= 1;
|
|
340
|
+
else if (value === "[") brackets += 1;
|
|
341
|
+
else if (value === "]") brackets -= 1;
|
|
342
|
+
else if (value === "{" && parentheses === 0 && brackets === 0) {
|
|
343
|
+
openings.add(cursor);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return openings;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function enclosingBrace(tokens, index) {
|
|
352
|
+
let depth = 0;
|
|
353
|
+
for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
|
|
354
|
+
if (tokens[cursor].value === "}") depth += 1;
|
|
355
|
+
else if (tokens[cursor].value === "{") {
|
|
356
|
+
if (depth === 0) return cursor;
|
|
357
|
+
depth -= 1;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return -1;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function methodContainer(tokens, index, classBodies) {
|
|
364
|
+
const open = enclosingBrace(tokens, index);
|
|
365
|
+
if (classBodies.has(open)) return true;
|
|
366
|
+
if (open < 0) return false;
|
|
367
|
+
const previous = tokens[open - 1]?.value;
|
|
368
|
+
return ![undefined, "{", "}", ";", ")", "else", "try", "finally", "do", "=>", "static"]
|
|
369
|
+
.includes(previous);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function collectMethod(tokens, index, declared, nonCalls, classBodies) {
|
|
373
|
+
const name = tokens[index];
|
|
374
|
+
const propertyName = name?.kind === "word" || name?.kind === "literal" || name?.kind === "number";
|
|
375
|
+
if (!propertyName || tokens[index + 1]?.value !== "(" || tokens[index - 1]?.value === "extends"
|
|
376
|
+
|| !methodContainer(tokens, index, classBodies)) return;
|
|
377
|
+
const close = matchingClose(tokens, index + 1);
|
|
378
|
+
if (close < 0 || tokens[close + 1]?.value !== "{") return;
|
|
379
|
+
nonCalls.add(index);
|
|
380
|
+
collectBindingList(tokens, index + 2, close, declared);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function collectComputedMethod(tokens, index, declared, classBodies) {
|
|
384
|
+
if (tokens[index]?.value !== "[") return;
|
|
385
|
+
const propertyClose = matchingClose(tokens, index);
|
|
386
|
+
if (propertyClose < 0 || tokens[propertyClose + 1]?.value !== "(") return;
|
|
387
|
+
const parametersClose = matchingClose(tokens, propertyClose + 1);
|
|
388
|
+
if (parametersClose < 0 || tokens[parametersClose + 1]?.value !== "{"
|
|
389
|
+
|| !methodContainer(tokens, index, classBodies)) return;
|
|
390
|
+
collectBindingList(tokens, propertyClose + 2, parametersClose, declared);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function collectDeclarations(tokens, declared, nonCalls) {
|
|
394
|
+
const classBodies = classBodyOpens(tokens);
|
|
395
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
396
|
+
const value = tokens[index].value;
|
|
397
|
+
if (["const", "let", "var"].includes(value)) {
|
|
398
|
+
collectVariableBindings(tokens, index + 1, declared);
|
|
399
|
+
} else if (["function", "class"].includes(value)) {
|
|
400
|
+
let cursor = index + 1;
|
|
401
|
+
if (tokens[cursor]?.value === "*") cursor += 1;
|
|
402
|
+
if (identifier(tokens[cursor])) declared.add(tokens[cursor++].value);
|
|
403
|
+
if (value === "function" && tokens[cursor]?.value === "(") {
|
|
404
|
+
const end = matchingClose(tokens, cursor);
|
|
405
|
+
if (end >= 0) collectBindingList(tokens, cursor + 1, end, declared);
|
|
406
|
+
}
|
|
407
|
+
} else if (value === "catch" && tokens[index + 1]?.value === "(") {
|
|
408
|
+
const end = matchingClose(tokens, index + 1);
|
|
409
|
+
if (end > index) collectBindingList(tokens, index + 2, end, declared);
|
|
410
|
+
} else if (value === "import") {
|
|
411
|
+
collectImportBindings(tokens, index + 1, declared);
|
|
412
|
+
} else if (value === "=>") {
|
|
413
|
+
if (tokens[index - 1]?.value === ")") {
|
|
414
|
+
const open = matchingOpen(tokens, index - 1);
|
|
415
|
+
if (open >= 0) collectBindingList(tokens, open + 1, index - 1, declared);
|
|
416
|
+
} else if (identifier(tokens[index - 1])) declared.add(tokens[index - 1].value);
|
|
417
|
+
}
|
|
418
|
+
if (value === "async" && tokens[index + 1]?.value === "(") {
|
|
419
|
+
const close = matchingClose(tokens, index + 1);
|
|
420
|
+
if (close >= 0 && tokens[close + 1]?.value === "=>") nonCalls.add(index);
|
|
421
|
+
}
|
|
422
|
+
collectMethod(tokens, index, declared, nonCalls, classBodies);
|
|
423
|
+
collectComputedMethod(tokens, index, declared, classBodies);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function undeclaredCalls(source, { allowlist = [] } = {}) {
|
|
428
|
+
const tokens = tokenize(source);
|
|
429
|
+
const declared = new Set([...STATIC_GLOBALS, ...Object.getOwnPropertyNames(globalThis), ...allowlist]);
|
|
430
|
+
const nonCalls = new Set();
|
|
431
|
+
collectDeclarations(tokens, declared, nonCalls);
|
|
432
|
+
const findings = [];
|
|
433
|
+
const seen = new Set();
|
|
434
|
+
for (let index = 0; index < tokens.length - 1; index += 1) {
|
|
435
|
+
const token = tokens[index];
|
|
436
|
+
const call = tokens[index + 1].value === "("
|
|
437
|
+
|| (tokens[index + 1].value === "?." && tokens[index + 2]?.value === "(");
|
|
438
|
+
if (!identifier(token) || nonCalls.has(index) || !call
|
|
439
|
+
|| [".", "?."].includes(tokens[index - 1]?.value)) continue;
|
|
440
|
+
const key = `${token.line}\0${token.value}`;
|
|
441
|
+
if (declared.has(token.value) || seen.has(key)) continue;
|
|
442
|
+
seen.add(key);
|
|
443
|
+
findings.push({ name: token.value, line: token.line });
|
|
444
|
+
}
|
|
445
|
+
return findings;
|
|
446
|
+
}
|
|
@@ -11,7 +11,8 @@ export const INDEXED_MEMORY_CACHE_SCHEMA = "agentspine.indexed-memory-cache/v1";
|
|
|
11
11
|
const CACHE_LIMIT = 16 * 1024 * 1024;
|
|
12
12
|
const FILE_LIMIT = 4 * 1024 * 1024;
|
|
13
13
|
const MAX_ATTEMPTS = 3;
|
|
14
|
-
const MAX_INDEXED_LINKS =
|
|
14
|
+
const MAX_INDEXED_LINKS = 4096;
|
|
15
|
+
const MAX_LIVE_SELECTIONS = 8;
|
|
15
16
|
|
|
16
17
|
function sha256(value) { return createHash("sha256").update(value).digest("hex"); }
|
|
17
18
|
function cachePath(env) { return join(stateRoot(env), "indexed-memory-cache.json"); }
|
|
@@ -205,17 +206,22 @@ export function parseMemoryIndex(text, indexPath, root) {
|
|
|
205
206
|
}
|
|
206
207
|
|
|
207
208
|
export function relevantMemoryEntry(entry, scope = {}) {
|
|
208
|
-
|
|
209
|
+
const pinned = new Set(Array.isArray(scope.pinnedPaths) ? scope.pinnedPaths : []);
|
|
210
|
+
if (pinned.has(entry.relativePath)) return { relevant: true, reason: "pinned", score: 1000 };
|
|
209
211
|
const exact = [
|
|
210
212
|
["entity", scope.entityId], ["person", scope.entityId], ["project", scope.projectId],
|
|
211
213
|
["group", scope.groupId], ["task", scope.currentTaskId]
|
|
212
214
|
];
|
|
213
215
|
for (const [key, value] of exact) {
|
|
214
|
-
if (entry.directives[key] && value && entry.directives[key] === value)
|
|
216
|
+
if (entry.directives[key] && value && entry.directives[key] === value) {
|
|
217
|
+
return { relevant: true, reason: key, score: 500 };
|
|
218
|
+
}
|
|
215
219
|
}
|
|
216
220
|
const prompt = tokens(scope.prompt);
|
|
217
|
-
|
|
218
|
-
return { relevant:
|
|
221
|
+
const matches = entry.promptTokens.filter((value) => prompt.has(value)).length;
|
|
222
|
+
if (matches) return { relevant: true, reason: "prompt", score: 700 + Math.min(matches, 99) };
|
|
223
|
+
if (entry.always) return { relevant: true, reason: "always", score: 100 };
|
|
224
|
+
return { relevant: false, reason: "scope", score: 0 };
|
|
219
225
|
}
|
|
220
226
|
|
|
221
227
|
export async function resolveIndexedMemory({ root, scope = {}, env = process.env, hooks = {}, deadline = Infinity }) {
|
|
@@ -228,7 +234,7 @@ export async function resolveIndexedMemory({ root, scope = {}, env = process.env
|
|
|
228
234
|
const key = rootKey(canonicalRoot);
|
|
229
235
|
const cached = cache.roots[key] || {};
|
|
230
236
|
const diagnostics = {
|
|
231
|
-
indexed: 0, relevant: 0, loaded: 0, cacheHits: 0, cacheMisses: 0, missing: 0,
|
|
237
|
+
indexed: 0, relevant: 0, selected: 0, omittedRelevant: 0, loaded: 0, cacheHits: 0, cacheMisses: 0, missing: 0,
|
|
232
238
|
rejected: { scope: 0, path: 0, symlink: 0, race: 0, size: 0 }, directoryEnumeration: 0
|
|
233
239
|
};
|
|
234
240
|
const index = await safeIndexedSnapshot(canonicalRoot, "MEMORY.md", cached["MEMORY.md"], hooks);
|
|
@@ -244,11 +250,22 @@ export async function resolveIndexedMemory({ root, scope = {}, env = process.env
|
|
|
244
250
|
if (entries.length > MAX_INDEXED_LINKS) throw new Error(`Claude MEMORY.md indexes more than ${MAX_INDEXED_LINKS} direct files`);
|
|
245
251
|
diagnostics.indexed = entries.length;
|
|
246
252
|
const sources = [{ path: index.path, relativePath: "MEMORY.md", snapshot: index, relevance: "index" }];
|
|
253
|
+
const selected = [];
|
|
247
254
|
for (const entry of entries) {
|
|
248
255
|
checkDeadline();
|
|
249
256
|
const relevance = relevantMemoryEntry(entry, scope);
|
|
250
257
|
if (!relevance.relevant) { diagnostics.rejected.scope += 1; continue; }
|
|
251
258
|
diagnostics.relevant += 1;
|
|
259
|
+
selected.push({ entry, relevance });
|
|
260
|
+
}
|
|
261
|
+
const chosen = new Set([...selected].sort((left, right) => right.relevance.score - left.relevance.score
|
|
262
|
+
|| left.entry.relativePath.localeCompare(right.entry.relativePath)).slice(0, MAX_LIVE_SELECTIONS)
|
|
263
|
+
.map(({ entry }) => entry.relativePath));
|
|
264
|
+
diagnostics.selected = chosen.size;
|
|
265
|
+
diagnostics.omittedRelevant = Math.max(0, selected.length - MAX_LIVE_SELECTIONS);
|
|
266
|
+
for (const { entry, relevance } of selected) {
|
|
267
|
+
if (!chosen.has(entry.relativePath)) continue;
|
|
268
|
+
checkDeadline();
|
|
252
269
|
const snapshot = await safeIndexedSnapshot(canonicalRoot, entry.relativePath, cached[entry.relativePath], hooks);
|
|
253
270
|
if (snapshot.rejected) {
|
|
254
271
|
if (snapshot.rejected === "missing") diagnostics.missing += 1;
|