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,111 @@
|
|
|
1
|
+
export const MAX_SUBSTITUTION_DEPTH = 8;
|
|
2
|
+
|
|
3
|
+
function backtickEnd(command, start) {
|
|
4
|
+
let escaped = false;
|
|
5
|
+
for (let index = start + 1; index < command.length; index += 1) {
|
|
6
|
+
const character = command[index];
|
|
7
|
+
if (escaped) { escaped = false; continue; }
|
|
8
|
+
if (character === "\\") { escaped = true; continue; }
|
|
9
|
+
if (character === "`") return index;
|
|
10
|
+
}
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function substitutionEnd(command, start, depth) {
|
|
15
|
+
if (depth >= MAX_SUBSTITUTION_DEPTH) return -1;
|
|
16
|
+
let quote = null;
|
|
17
|
+
let escaped = false;
|
|
18
|
+
let lineComment = false;
|
|
19
|
+
let parentheses = 0;
|
|
20
|
+
for (let index = start + 2; index < command.length; index += 1) {
|
|
21
|
+
const character = command[index];
|
|
22
|
+
const next = command[index + 1];
|
|
23
|
+
if (lineComment) {
|
|
24
|
+
if (character === "\n") lineComment = false;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (escaped) { escaped = false; continue; }
|
|
28
|
+
if (character === "\\" && quote !== "'") { escaped = true; continue; }
|
|
29
|
+
if (quote === "'") {
|
|
30
|
+
if (character === quote) quote = null;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (quote === '"') {
|
|
34
|
+
if (character === quote) { quote = null; continue; }
|
|
35
|
+
if (character === "$" && next === "(" && command[index + 2] !== "(") {
|
|
36
|
+
const end = substitutionEnd(command, index, depth + 1);
|
|
37
|
+
if (end < 0) return -1;
|
|
38
|
+
index = end;
|
|
39
|
+
} else if (character === "`") {
|
|
40
|
+
const end = backtickEnd(command, index);
|
|
41
|
+
if (end < 0) return -1;
|
|
42
|
+
index = end;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (character === "'" || character === '"') { quote = character; continue; }
|
|
47
|
+
if (character === "#" && (index === 0 || /[\s;&|()]/.test(command[index - 1]))) {
|
|
48
|
+
lineComment = true;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (character === "$" && next === "(" && command[index + 2] !== "(") {
|
|
52
|
+
const end = substitutionEnd(command, index, depth + 1);
|
|
53
|
+
if (end < 0) return -1;
|
|
54
|
+
index = end;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (character === "`") {
|
|
58
|
+
const end = backtickEnd(command, index);
|
|
59
|
+
if (end < 0) return -1;
|
|
60
|
+
index = end;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (character === "(") { parentheses += 1; continue; }
|
|
64
|
+
if (character === ")") {
|
|
65
|
+
if (parentheses === 0) return index;
|
|
66
|
+
parentheses -= 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function shellSubstitutions(command, depth) {
|
|
73
|
+
const substitutions = [];
|
|
74
|
+
let quote = null;
|
|
75
|
+
let escaped = false;
|
|
76
|
+
let lineComment = false;
|
|
77
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
78
|
+
const character = command[index];
|
|
79
|
+
const next = command[index + 1];
|
|
80
|
+
if (lineComment) {
|
|
81
|
+
if (character === "\n") lineComment = false;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (escaped) { escaped = false; continue; }
|
|
85
|
+
if (character === "\\" && quote !== "'") { escaped = true; continue; }
|
|
86
|
+
if (quote === "'") {
|
|
87
|
+
if (character === quote) quote = null;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (character === '"') { quote = quote === '"' ? null : '"'; continue; }
|
|
91
|
+
if (!quote && character === "'") { quote = character; continue; }
|
|
92
|
+
if (!quote && character === "#" && (index === 0 || /[\s;&|()]/.test(command[index - 1]))) {
|
|
93
|
+
lineComment = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (character === "$" && next === "(" && command[index + 2] !== "(") {
|
|
97
|
+
const end = substitutionEnd(command, index, depth);
|
|
98
|
+
if (end < 0) continue;
|
|
99
|
+
substitutions.push({ text: command.slice(index + 2, end), index: index + 2 });
|
|
100
|
+
index = end;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (character === "`") {
|
|
104
|
+
const end = backtickEnd(command, index);
|
|
105
|
+
if (end < 0) continue;
|
|
106
|
+
substitutions.push({ text: command.slice(index + 1, end), index: index + 1 });
|
|
107
|
+
index = end;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return substitutions;
|
|
111
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const WRAPPER_NAMES = new Set(["sudo", "env", "command", "builtin", "exec", "timeout", "nice"]);
|
|
2
|
+
const VALUE_OPTIONS = {
|
|
3
|
+
sudo: new Set([
|
|
4
|
+
"-C", "--close-from", "-D", "--chdir", "-g", "--group", "-h", "--host",
|
|
5
|
+
"-p", "--prompt", "-r", "--role", "-t", "--type", "-u", "--user"
|
|
6
|
+
]),
|
|
7
|
+
env: new Set(["-C", "--chdir", "-u", "--unset", "-S", "--split-string"]),
|
|
8
|
+
exec: new Set(["-a"]),
|
|
9
|
+
timeout: new Set(["-k", "--kill-after", "-s", "--signal"]),
|
|
10
|
+
nice: new Set(["-n", "--adjustment"])
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function shellExecutableName(value) {
|
|
14
|
+
if (typeof value !== "string") return "";
|
|
15
|
+
return value.replace(/^.*[\\/]/, "").replace(/\.exe$/i, "").toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function wrapperName(value) {
|
|
19
|
+
const base = shellExecutableName(value);
|
|
20
|
+
return WRAPPER_NAMES.has(base) ? base : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function optionDetails(value, valueOptions) {
|
|
24
|
+
if (value.includes("=")) return { option: value.slice(0, value.indexOf("=")), attached: true, payload: value.slice(value.indexOf("=") + 1) };
|
|
25
|
+
const short = value.slice(0, 2);
|
|
26
|
+
if (value.length > 2 && !value.startsWith("--") && valueOptions.has(short)) {
|
|
27
|
+
return { option: short, attached: true, payload: value.slice(2) };
|
|
28
|
+
}
|
|
29
|
+
return { option: value, attached: false, payload: null };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function replaceSplitString(tokens, payload, tokenize) {
|
|
33
|
+
if (!payload || typeof tokenize !== "function") return;
|
|
34
|
+
tokens.unshift(...tokenize(payload));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function discardOptions(tokens, kind, tokenize) {
|
|
38
|
+
const valueOptions = VALUE_OPTIONS[kind] ?? new Set();
|
|
39
|
+
while (tokens[0]) {
|
|
40
|
+
const value = tokens[0].value;
|
|
41
|
+
if (value === "--") { tokens.shift(); return; }
|
|
42
|
+
if (kind === "env" && /^[A-Za-z_][A-Za-z0-9_]*=/.test(value)) { tokens.shift(); continue; }
|
|
43
|
+
if (!value.startsWith("-") || value === "-") return;
|
|
44
|
+
tokens.shift();
|
|
45
|
+
const { option, attached, payload } = optionDetails(value, valueOptions);
|
|
46
|
+
if (!valueOptions.has(option)) continue;
|
|
47
|
+
const splitString = kind === "env" && ["-S", "--split-string"].includes(option);
|
|
48
|
+
if (attached) {
|
|
49
|
+
if (splitString) replaceSplitString(tokens, payload, tokenize);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const argument = tokens.shift();
|
|
53
|
+
if (splitString) replaceSplitString(tokens, argument?.value, tokenize);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function unwrapLeadingShellWrapper(tokens, tokenize) {
|
|
58
|
+
const kind = wrapperName(tokens[0]?.value);
|
|
59
|
+
if (!kind) return false;
|
|
60
|
+
tokens.shift();
|
|
61
|
+
discardOptions(tokens, kind, tokenize);
|
|
62
|
+
if (kind === "timeout" && tokens[0]) tokens.shift();
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { isInside } from "./paths.js";
|
|
5
|
+
|
|
6
|
+
const MAX_TARGET_BYTES = 2 * 1024 * 1024;
|
|
7
|
+
const AUTHORITY = "context-only";
|
|
8
|
+
|
|
9
|
+
function sameFile(left, right) {
|
|
10
|
+
return left.dev === right.dev && left.ino === right.ino && left.size === right.size
|
|
11
|
+
&& left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function optionalStat(path) {
|
|
15
|
+
try { return await lstat(path); }
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code === "ENOENT") return null;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function verifyParents(parents, root) {
|
|
23
|
+
for (const [path, before] of parents) {
|
|
24
|
+
const after = await lstat(path);
|
|
25
|
+
if (after.isSymbolicLink() || !after.isDirectory() || !sameFile(before, after)
|
|
26
|
+
|| !isInside(root, await realpath(path))) {
|
|
27
|
+
throw new Error("delivery target parent changed during the knowledge query");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Inspect only the target's components, never enumerate its parent or any tree.
|
|
33
|
+
// ENOENT is a baseline, not permission to create; other errors still abort the query.
|
|
34
|
+
export async function targetSnapshot(root, relativePath) {
|
|
35
|
+
if (isAbsolute(relativePath)) throw new Error("delivery target path must be relative");
|
|
36
|
+
const absolute = resolve(root, relativePath);
|
|
37
|
+
if (!isInside(root, absolute) || absolute === root) throw new Error("delivery target escapes the project root");
|
|
38
|
+
const parts = relative(root, absolute).split(sep);
|
|
39
|
+
const parents = [[root, await lstat(root)]];
|
|
40
|
+
let cursor = root;
|
|
41
|
+
for (let index = 0; index < parts.length; index++) {
|
|
42
|
+
cursor = join(cursor, parts[index]);
|
|
43
|
+
const before = await optionalStat(cursor);
|
|
44
|
+
if (!before) {
|
|
45
|
+
await verifyParents(parents, root);
|
|
46
|
+
if (await optionalStat(cursor)) throw new Error("delivery target appeared during the knowledge query");
|
|
47
|
+
return { path: relativePath, state: "absent", bytes: 0, sha256: null,
|
|
48
|
+
existingParent: relative(root, parents.at(-1)[0]) || ".", authority: AUTHORITY };
|
|
49
|
+
}
|
|
50
|
+
if (before.isSymbolicLink()) throw new Error("delivery target and parents must be non-symbolic paths");
|
|
51
|
+
const canonical = await realpath(cursor);
|
|
52
|
+
if (!isInside(root, canonical)) throw new Error("delivery target resolves outside the project root");
|
|
53
|
+
if (index < parts.length - 1) {
|
|
54
|
+
if (!before.isDirectory()) throw new Error("delivery target parent must be a directory");
|
|
55
|
+
parents.push([cursor, before]);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (!before.isFile()) throw new Error("delivery target must be a regular non-symbolic file");
|
|
59
|
+
if (before.size > MAX_TARGET_BYTES) {
|
|
60
|
+
await verifyParents(parents, root);
|
|
61
|
+
return { path: relativePath, bytes: before.size,
|
|
62
|
+
omitted: "target-exceeds-2-mib", authority: AUTHORITY };
|
|
63
|
+
}
|
|
64
|
+
const bytes = await readFile(canonical);
|
|
65
|
+
const after = await lstat(absolute);
|
|
66
|
+
if (!sameFile(before, after) || after.isSymbolicLink()) {
|
|
67
|
+
throw new Error("delivery target changed during the knowledge query");
|
|
68
|
+
}
|
|
69
|
+
await verifyParents(parents, root);
|
|
70
|
+
return { path: relativePath, bytes: bytes.length,
|
|
71
|
+
sha256: createHash("sha256").update(bytes).digest("hex"), authority: AUTHORITY };
|
|
72
|
+
}
|
|
73
|
+
}
|