blun-king-cli 9.1.642 → 9.1.644
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/LIESMICH.txt +18 -0
- package/README.md +20 -6
- package/bin/blun.js +3 -3
- package/bin/king.js +3 -3
- package/bin/launcher-mode.js +125 -126
- package/bin/launcher-runtime.js +603 -616
- package/bin/plugin-bootstrap.js +339 -405
- package/bin/rename-private-staging.cjs +2 -2
- package/bin/retired-bundled-plugins.cjs +84 -0
- package/bin/startup-security-host.cjs +105 -0
- package/bin/startup-security.cjs +9 -105
- package/bin/startup-warning-policy.cjs +22 -0
- package/bin/update-lease-installer.cjs +125 -0
- package/bin/update-lease-sockets.cjs +228 -0
- package/bin/update-lease.js +22 -327
- package/bin/verify-bundled-agent-sources.cjs +2 -4
- package/blun.mjs +78 -193
- package/bundled-agent-sources.json +1 -552
- package/package.json +4 -6
- package/tool-liveness642/index.cjs +7 -0
- package/tool-liveness642/queue-delivery.cjs +109 -0
- package/tool-liveness642/receipt.json +40 -0
- package/tool-liveness642/shell-yield.cjs +43 -0
- package/tool-liveness642/task-wait.cjs +45 -0
- package/versionierung/BELEG.json +43 -0
- package/versionierung/LIESMICH.md +5 -0
- package/versionierung/urspruenglicher-overlay-beleg.json +39 -0
- package/worker-host.mjs +48 -128
- package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
- package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
- package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
- package/agent-spine-plugin/.mcp.json +0 -8
- package/agent-spine-plugin/CHANGELOG.md +0 -1614
- package/agent-spine-plugin/LICENSE +0 -186
- package/agent-spine-plugin/README.md +0 -432
- package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
- package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
- package/agent-spine-plugin/bin/agentspine.js +0 -7
- package/agent-spine-plugin/blun.plugin.json +0 -68
- package/agent-spine-plugin/docs/acceptance.md +0 -61
- package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
- package/agent-spine-plugin/docs/host-integration.md +0 -193
- package/agent-spine-plugin/docs/preflight-recall.md +0 -71
- package/agent-spine-plugin/docs/preservation-contract.md +0 -53
- package/agent-spine-plugin/docs/quality-gates.md +0 -50
- package/agent-spine-plugin/docs/session-timeline.md +0 -112
- package/agent-spine-plugin/docs/source-roots.md +0 -113
- package/agent-spine-plugin/docs/world-model.md +0 -119
- package/agent-spine-plugin/hooks/codex.json +0 -47
- package/agent-spine-plugin/hooks/hooks.json +0 -106
- package/agent-spine-plugin/hooks/version.json +0 -5
- package/agent-spine-plugin/package.json +0 -77
- package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
- package/agent-spine-plugin/scripts/check-hosts.js +0 -208
- package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
- package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
- package/agent-spine-plugin/scripts/check-install.js +0 -478
- package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
- package/agent-spine-plugin/scripts/check-syntax.js +0 -29
- package/agent-spine-plugin/scripts/github-actions.js +0 -11
- package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
- package/agent-spine-plugin/scripts/release-check.js +0 -150
- package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
- package/agent-spine-plugin/scripts/run-checks.js +0 -50
- package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
- package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
- package/agent-spine-plugin/spine-example/1-identity.md +0 -12
- package/agent-spine-plugin/spine-example/2-voice.md +0 -6
- package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
- package/agent-spine-plugin/spine-example/4-history.md +0 -4
- package/agent-spine-plugin/src/cli-agent.js +0 -315
- package/agent-spine-plugin/src/cli-attention.js +0 -95
- package/agent-spine-plugin/src/cli-autonomy.js +0 -36
- package/agent-spine-plugin/src/cli-common.js +0 -71
- package/agent-spine-plugin/src/cli-continuity.js +0 -116
- package/agent-spine-plugin/src/cli-core.js +0 -128
- package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
- package/agent-spine-plugin/src/cli-host.js +0 -21
- package/agent-spine-plugin/src/cli-learning.js +0 -320
- package/agent-spine-plugin/src/cli-premortem.js +0 -16
- package/agent-spine-plugin/src/cli-sharing.js +0 -230
- package/agent-spine-plugin/src/cli.js +0 -181
- package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
- package/agent-spine-plugin/src/hook.js +0 -500
- package/agent-spine-plugin/src/index.js +0 -108
- package/agent-spine-plugin/src/lib/acceptance.js +0 -435
- package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
- package/agent-spine-plugin/src/lib/attention-context.js +0 -167
- package/agent-spine-plugin/src/lib/attention-events.js +0 -113
- package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
- package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
- package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
- package/agent-spine-plugin/src/lib/attention.js +0 -164
- package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
- package/agent-spine-plugin/src/lib/audit.js +0 -401
- package/agent-spine-plugin/src/lib/authentication.js +0 -515
- package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
- package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
- package/agent-spine-plugin/src/lib/autonomy.js +0 -8
- package/agent-spine-plugin/src/lib/briefing.js +0 -493
- package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
- package/agent-spine-plugin/src/lib/catalog.js +0 -167
- package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
- package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
- package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
- package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
- package/agent-spine-plugin/src/lib/context.js +0 -156
- package/agent-spine-plugin/src/lib/continuity.js +0 -338
- package/agent-spine-plugin/src/lib/coordination.js +0 -577
- package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
- package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
- package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
- package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
- package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
- package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
- package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
- package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
- package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
- package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
- package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
- package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
- package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
- package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
- package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
- package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
- package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
- package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
- package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
- package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
- package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
- package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
- package/agent-spine-plugin/src/lib/documents.js +0 -239
- package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
- package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
- package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
- package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
- package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
- package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
- package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
- package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
- package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
- package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
- package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
- package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
- package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
- package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
- package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
- package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
- package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
- package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
- package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
- package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
- package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
- package/agent-spine-plugin/src/lib/graph.js +0 -337
- package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
- package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
- package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
- package/agent-spine-plugin/src/lib/hook-context.js +0 -441
- package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
- package/agent-spine-plugin/src/lib/hook-input.js +0 -27
- package/agent-spine-plugin/src/lib/hook-output.js +0 -284
- package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
- package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
- package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
- package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
- package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
- package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
- package/agent-spine-plugin/src/lib/https-transport.js +0 -392
- package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
- package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
- package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
- package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
- package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
- package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
- package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
- package/agent-spine-plugin/src/lib/learning-context.js +0 -137
- package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
- package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
- package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
- package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
- package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
- package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
- package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
- package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
- package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
- package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
- package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
- package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
- package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
- package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
- package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
- package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
- package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
- package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
- package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
- package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
- package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
- package/agent-spine-plugin/src/lib/learning.js +0 -36
- package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
- package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
- package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
- package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
- package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
- package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
- package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
- package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
- package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
- package/agent-spine-plugin/src/lib/object-transport.js +0 -206
- package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
- package/agent-spine-plugin/src/lib/paths.js +0 -109
- package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
- package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
- package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
- package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
- package/agent-spine-plugin/src/lib/preflight.js +0 -688
- package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
- package/agent-spine-plugin/src/lib/runtime.js +0 -13
- package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
- package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
- package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
- package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
- package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
- package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
- package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
- package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
- package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
- package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
- package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
- package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
- package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
- package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
- package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
- package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
- package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
- package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
- package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
- package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
- package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
- package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
- package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
- package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
- package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
- package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
- package/agent-spine-plugin/src/lib/sharing.js +0 -969
- package/agent-spine-plugin/src/lib/source-roots.js +0 -475
- package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
- package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
- package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
- package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
- package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
- package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
- package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
- package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
- package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
- package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
- package/agent-spine-plugin/src/lib/world-model.js +0 -333
- package/agent-spine-plugin/src/mcp.js +0 -456
- package/agent-spine-plugin/src/version.js +0 -1
- package/agent-spine-plugin/src/worker.js +0 -257
- package/bin/agentspine-king-goal-inbox.mjs +0 -127
- package/bin/agentspine-king-goal-intake.mjs +0 -106
- package/bin/agentspine-king-host-runner.mjs +0 -109
- package/bin/agentspine-king-snapshot-policy.cjs +0 -80
- package/bin/agentspine-king-status-policy.mjs +0 -226
- package/bin/agentspine-king-worker-host.mjs +0 -160
- package/bin/managed-plugin-selection.cjs +0 -141
- package/bin/verify-agent-behavior.cjs +0 -122
- package/bin/verify-agent-components.cjs +0 -104
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
const MAX_BYTES=1200;
|
|
2
|
-
const BOUND="\n[optional runtime detail omitted: 1200-byte bound]";
|
|
3
|
-
const bytes=value=>Buffer.byteLength(JSON.stringify(value));
|
|
4
|
-
|
|
5
|
-
function addRecallField(packet,key,value,maximum=1020){
|
|
6
|
-
if(value===undefined||value===null)return;
|
|
7
|
-
packet[key]=value;
|
|
8
|
-
if(bytes(packet)<=maximum)return true;
|
|
9
|
-
delete packet[key];
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function sharedPrefix(values){
|
|
14
|
-
let prefix=values[0]||"";
|
|
15
|
-
for(const value of values.slice(1)){
|
|
16
|
-
while(prefix&&!value.startsWith(prefix))prefix=prefix.slice(0,-1);
|
|
17
|
-
}
|
|
18
|
-
return prefix.length>=4?prefix:"";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function compactRows(packet,candidates){
|
|
22
|
-
if(candidates.rows.length<2)return;
|
|
23
|
-
if(!candidates.prefixes){
|
|
24
|
-
const digest=candidates.fields.indexOf("digest");
|
|
25
|
-
if(digest>=0&&candidates.rows.every(row=>row[digest]===candidates.rows[0][digest])){
|
|
26
|
-
candidates.common={...(candidates.common||{}),digest:candidates.rows[0][digest]};
|
|
27
|
-
candidates.fields.splice(digest,1);
|
|
28
|
-
for(const row of candidates.rows)row.splice(digest,1);
|
|
29
|
-
}
|
|
30
|
-
candidates.prefixes=candidates.fields.map((field,index)=>{
|
|
31
|
-
const values=candidates.rows.map(row=>row[index]);
|
|
32
|
-
const prefix=["id","message","session"].includes(field)?sharedPrefix(values)
|
|
33
|
-
:field==="at"&&values.every(value=>/^\d{4}-\d{2}-\d{2}T\d{2}:/.test(value))
|
|
34
|
-
?values[0].slice(0,14):"";
|
|
35
|
-
if(!prefix||!values.every(value=>value.startsWith(prefix)))return"";
|
|
36
|
-
for(const row of candidates.rows)row[index]=row[index].slice(prefix.length);
|
|
37
|
-
return prefix;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if(packet.task){
|
|
41
|
-
delete packet.task.status;
|
|
42
|
-
if(packet.task.lastVerifiedStep)delete packet.task.lastVerifiedStep.result;
|
|
43
|
-
}
|
|
44
|
-
const review=packet.feedbackReview;
|
|
45
|
-
if(review?.modelClarification)packet.feedbackReview={
|
|
46
|
-
status:review.status,completionVerified:false,target:review.targetAssertionId,
|
|
47
|
-
question:review.modelClarification.question,model:true
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function compactFeedback(packet){
|
|
52
|
-
const candidates=packet.feedbackCandidates;
|
|
53
|
-
const proposal=packet.feedbackReview?.modelClarification;
|
|
54
|
-
if(proposal)for(const key of ["completionVerified","provider","replaces"])delete proposal[key];
|
|
55
|
-
if(candidates&&!Array.isArray(candidates)
|
|
56
|
-
&&Array.isArray(candidates.fields)&&Array.isArray(candidates.rows)){
|
|
57
|
-
compactRows(packet,candidates);
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
if(!Array.isArray(candidates)||candidates.length<2)return false;
|
|
61
|
-
const origins=["provider","session"];
|
|
62
|
-
const sharedKeys=origins.filter(key=>candidates.every(item=>item?.[key]===candidates[0]?.[key]));
|
|
63
|
-
const fields=["id","text","digest","message","at",
|
|
64
|
-
...origins.filter(key=>!sharedKeys.includes(key))];
|
|
65
|
-
packet.feedbackCandidates={
|
|
66
|
-
fields,
|
|
67
|
-
...(sharedKeys.length?{common:Object.fromEntries(sharedKeys.map(key=>
|
|
68
|
-
[key,candidates[0][key]]))}:{}),
|
|
69
|
-
rows:candidates.map(item=>fields.map(key=>item[key]))
|
|
70
|
-
};
|
|
71
|
-
compactRows(packet,packet.feedbackCandidates);
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function timelineRecall(t){
|
|
76
|
-
if(!t.events?.length)return{status:t.status,reason:t.reason,awaited:t.awaited,
|
|
77
|
-
reads:t.sourceReads,completionVerified:false,omitted:t.omittedEvents||0};
|
|
78
|
-
return{status:t.status,awaited:t.awaited,reads:t.sourceReads,completionVerified:false,
|
|
79
|
-
naturalMessages:"unresolved",trust:"untrusted-session-history",
|
|
80
|
-
...(t.source?{source:t.source}:{sources:t.sources}),prefixes:t.prefixes,
|
|
81
|
-
fields:t.fields,rows:t.events.map(row=>[...row]),omitted:t.omittedEvents||0}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function preAnswerRecallCapsule(detailed){
|
|
85
|
-
if(detailed?.event!=="UserPromptSubmit"||!detailed.loaded)return null;
|
|
86
|
-
const briefing=detailed.briefing;
|
|
87
|
-
const preflight=detailed.preflight?.briefing;
|
|
88
|
-
if(!briefing||!preflight)return null;
|
|
89
|
-
if(briefing.scope?.groupId!==null&&briefing.scope?.groupId!==undefined)return null;
|
|
90
|
-
const omitted=[];
|
|
91
|
-
const packet=briefing.preAnswerRecall?structuredClone(briefing.preAnswerRecall):{
|
|
92
|
-
schema:"agentspine.pre-answer-recall/v1",
|
|
93
|
-
order:"review-before-claims-and-actions",
|
|
94
|
-
authority:"context-only"
|
|
95
|
-
};
|
|
96
|
-
const timeline=detailed.sourceResolution?.timeline?.preAnswerRecall;
|
|
97
|
-
if(timeline?.awaited){
|
|
98
|
-
let candidate=timelineRecall(timeline);
|
|
99
|
-
while(!addRecallField(packet,"timeline",candidate)&&candidate.rows?.length){
|
|
100
|
-
candidate.rows.pop();
|
|
101
|
-
candidate.omitted += 1;
|
|
102
|
-
if(!candidate.rows.length)candidate={status:"unavailable",reason:"host-context-budget",
|
|
103
|
-
awaited:candidate.awaited,reads:candidate.reads,completionVerified:false,omitted:candidate.omitted};
|
|
104
|
-
}
|
|
105
|
-
if(!packet.timeline&&bytes(packet)>MAX_BYTES){
|
|
106
|
-
const keys=Object.keys(packet).filter(key=>!/^schema$|^order$|^authority$/.test(key));
|
|
107
|
-
for(const key of keys)delete packet[key];
|
|
108
|
-
packet.timeline=candidate;packet.omitted=keys;
|
|
109
|
-
}else if(!packet.timeline)packet.timelineOmitted=true;
|
|
110
|
-
}
|
|
111
|
-
const mustRemember = (preflight.mustRemember || []).map((item) => ({
|
|
112
|
-
id: item.id, claim: item.claim, checksum: item.checksum
|
|
113
|
-
}));
|
|
114
|
-
if (mustRemember.length && !addRecallField(packet, "mustRemember", mustRemember)) {
|
|
115
|
-
if (!compactFeedback(packet)
|
|
116
|
-
|| !addRecallField(packet, "mustRemember", mustRemember, MAX_BYTES)) {
|
|
117
|
-
omitted.push("mustRemember");
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const retrieval = (preflight.retrieval || []).flatMap((provider) =>
|
|
121
|
-
(provider.items || []).map((item) => ({ providerId: provider.providerId,
|
|
122
|
-
id: item.id, revision: item.revision, claim: item.claim, source: item.source }))).slice(0, 3);
|
|
123
|
-
if (retrieval.length && !addRecallField(packet, "retrieval", retrieval)) {
|
|
124
|
-
if (!compactFeedback(packet)
|
|
125
|
-
|| !addRecallField(packet, "retrieval", retrieval, MAX_BYTES)) {
|
|
126
|
-
omitted.push("retrieval");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
compactFeedback(packet);
|
|
130
|
-
if(omitted.length&&bytes({...packet,omitted})<=MAX_BYTES)packet.omitted=omitted;
|
|
131
|
-
return Object.keys(packet).length > 3 ? packet : null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function compactPremortemRegistration(premortem, includeRoot = true) {
|
|
135
|
-
const root = premortem?.registration?.root;
|
|
136
|
-
const requirementId = premortem?.requirementId || premortem?.registration?.requirementId;
|
|
137
|
-
const target = includeRoot && typeof root === "string"
|
|
138
|
-
? ` with root ${JSON.stringify(root)}` : " for the current project";
|
|
139
|
-
return [
|
|
140
|
-
"Recommended delivery preparation (advisory; does not block coding or replies):",
|
|
141
|
-
`session_briefing, delivery_knowledge_query, then record_delivery_premortem${target}.`,
|
|
142
|
-
`Requirement: ${requirementId || "<unavailable; continue the authorized task>"}.`,
|
|
143
|
-
"Only stored call receipts from this session and goal step count; the calls grant no authority.",
|
|
144
|
-
"Completion: Premortem closure sha256 <64hex>, latest write digest, and all three check IDs with results."
|
|
145
|
-
].join("\n");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function blunRuntimeContext(context) {
|
|
149
|
-
const detailed = JSON.parse(context);
|
|
150
|
-
const sourceResolution = detailed.sourceResolution ? {
|
|
151
|
-
status: detailed.sourceResolution.status || null,
|
|
152
|
-
reason: detailed.sourceResolution.reason || null,
|
|
153
|
-
...(detailed.sourceResolution.incomplete ? {
|
|
154
|
-
incomplete: true,
|
|
155
|
-
warning: detailed.sourceResolution.warning || "Host-native source context is incomplete."
|
|
156
|
-
} : {})
|
|
157
|
-
} : null;
|
|
158
|
-
const runtime = {
|
|
159
|
-
schema: "agentspine.blun-runtime-context/v1",
|
|
160
|
-
event: detailed.event,
|
|
161
|
-
loaded: Boolean(detailed.loaded),
|
|
162
|
-
failedClosed: detailed.failedClosed ? true : undefined,
|
|
163
|
-
indexedSources: detailed.indexedSources || 0,
|
|
164
|
-
sourceResolution,
|
|
165
|
-
instruction: detailed.loaded
|
|
166
|
-
? "Detailed AgentSpine context is available on demand through session_briefing. Load it only when the current request needs continuity."
|
|
167
|
-
: detailed.instruction,
|
|
168
|
-
authority: "context-only"
|
|
169
|
-
};
|
|
170
|
-
const recall = preAnswerRecallCapsule(detailed);
|
|
171
|
-
if (recall) runtime.preAnswerRecall = recall;
|
|
172
|
-
if (detailed.signal && (detailed.signal.captured || detailed.signal.accepted || detailed.signal.reason)) {
|
|
173
|
-
runtime.signal = detailed.signal;
|
|
174
|
-
}
|
|
175
|
-
if (detailed.attentionEvent
|
|
176
|
-
&& (detailed.attentionEvent.captured || detailed.attentionEvent.duplicate || detailed.attentionEvent.reason)) {
|
|
177
|
-
runtime.attentionEvent = detailed.attentionEvent;
|
|
178
|
-
}
|
|
179
|
-
if (detailed.selfstarter && (detailed.selfstarter.active || detailed.selfstarter.blocked)) {
|
|
180
|
-
runtime.selfstarter = detailed.selfstarter;
|
|
181
|
-
}
|
|
182
|
-
if (detailed.channelEvent?.active) runtime.channelEvent = detailed.channelEvent;
|
|
183
|
-
if (detailed.preflight?.premortem) runtime.premortem = detailed.preflight.premortem;
|
|
184
|
-
return JSON.stringify(runtime);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function blunRuntimeMessage(context) {
|
|
188
|
-
const runtime = JSON.parse(blunRuntimeContext(context));
|
|
189
|
-
const base = runtime.loaded
|
|
190
|
-
? runtime.preAnswerRecall
|
|
191
|
-
? `AgentSpine ready: ${runtime.indexedSources} sources indexed.`
|
|
192
|
-
: `AgentSpine ready: ${runtime.indexedSources} sources indexed. Load detailed continuity only on demand through session_briefing.`
|
|
193
|
-
: `AgentSpine unavailable${runtime.sourceResolution?.reason ? `: ${runtime.sourceResolution.reason}` : ""}. ${runtime.instruction}`;
|
|
194
|
-
const active = {};
|
|
195
|
-
if (runtime.signal && (runtime.signal.captured || runtime.signal.accepted
|
|
196
|
-
|| String(runtime.signal.reason || "").startsWith("rejected:"))) {
|
|
197
|
-
active.signal = runtime.signal;
|
|
198
|
-
}
|
|
199
|
-
if (runtime.attentionEvent && (runtime.attentionEvent.captured || runtime.attentionEvent.duplicate
|
|
200
|
-
|| String(runtime.attentionEvent.reason || "").startsWith("rejected:"))) {
|
|
201
|
-
active.attentionEvent = runtime.attentionEvent;
|
|
202
|
-
}
|
|
203
|
-
if (runtime.selfstarter) active.selfstarter = runtime.selfstarter;
|
|
204
|
-
if (runtime.channelEvent) active.channelEvent = runtime.channelEvent;
|
|
205
|
-
const details = Object.keys(active).length === 0
|
|
206
|
-
? ""
|
|
207
|
-
: `\nActive AgentSpine runtime data: ${JSON.stringify(active)}`;
|
|
208
|
-
const recall = runtime.preAnswerRecall
|
|
209
|
-
? `\n${JSON.stringify(runtime.preAnswerRecall)}`
|
|
210
|
-
: "";
|
|
211
|
-
const root = runtime.premortem?.registration?.root;
|
|
212
|
-
const instruction = typeof root === "string"
|
|
213
|
-
? runtime.premortem?.instruction?.replace("registration.root", () => `root ${JSON.stringify(root)}`)
|
|
214
|
-
: runtime.premortem?.instruction;
|
|
215
|
-
const premortem = instruction ? `\n${instruction}` : "";
|
|
216
|
-
const message = `${base}${recall}${details}${premortem}`;
|
|
217
|
-
if (Buffer.byteLength(message) <= MAX_BYTES) return message;
|
|
218
|
-
const compact = `${base}${recall}${BOUND}\n${compactPremortemRegistration(runtime.premortem)}`;
|
|
219
|
-
if (Buffer.byteLength(compact) <= MAX_BYTES) return compact;
|
|
220
|
-
if (!runtime.preAnswerRecall) {
|
|
221
|
-
return `${base}${BOUND}\n${compactPremortemRegistration(runtime.premortem, false)}`;
|
|
222
|
-
}
|
|
223
|
-
const recallOnly = `${base}${recall}${BOUND}`;
|
|
224
|
-
if (Buffer.byteLength(recallOnly) <= MAX_BYTES) return recallOnly;
|
|
225
|
-
return Buffer.byteLength(recall)<=MAX_BYTES+1?recall.slice(1):`${base}\nRecall unavailable.`;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export function hookOutput(event, context, env = process.env, sourceWarning = null) {
|
|
229
|
-
if (env.BLUN_PLUGIN_ROOT) {
|
|
230
|
-
const source=JSON.parse(context).sourceResolution,w=sourceWarning||(source?.incomplete&&source.warning);
|
|
231
|
-
return {hookSpecificOutput:{hookEventName:event,additionalContext:blunRuntimeMessage(context),
|
|
232
|
-
...(w?{message:`AgentSpine source warning: ${w}`}:{})}};
|
|
233
|
-
}
|
|
234
|
-
return { hookSpecificOutput: { hookEventName: event, additionalContext: context,
|
|
235
|
-
...(sourceWarning ? { message: sourceWarning } : {}) } };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export function blockedHookOutput(event, reason, env = process.env) {
|
|
239
|
-
const output = { decision: "block", reason };
|
|
240
|
-
if (!env.CLAUDE_PLUGIN_ROOT || env.PLUGIN_ROOT) return output;
|
|
241
|
-
if (event === "PreToolUse") return { hookSpecificOutput: {
|
|
242
|
-
hookEventName: event, permissionDecision: "deny", permissionDecisionReason: reason
|
|
243
|
-
} };
|
|
244
|
-
return output;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export function denyTool(reason) {
|
|
248
|
-
process.stdout.write(`${JSON.stringify(blockedHookOutput("PreToolUse", reason))}\n`);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function blockPrompt(reason) {
|
|
252
|
-
process.stdout.write(`${JSON.stringify(blockedHookOutput("UserPromptSubmit", reason))}\n`);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
export function blockStop(event, reason) {
|
|
256
|
-
process.stdout.write(`${JSON.stringify(blockedHookOutput(event, reason))}\n`);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export function lifecycleOutput(event, artifactGuard, premortem, delivery = null, env = process.env,
|
|
260
|
-
sourceWarning = null, lessonRecall = null) {
|
|
261
|
-
const w=[sourceWarning&&`AgentSpine source warning: ${sourceWarning}`,artifactGuard?.reason,
|
|
262
|
-
delivery?.status==="test-failed"&&delivery.reason].filter(Boolean),c=[];
|
|
263
|
-
if (/^[a-f0-9]{64}$/.test(premortem?.writeDigest || "")) {
|
|
264
|
-
c.push([
|
|
265
|
-
premortem.writeIntent
|
|
266
|
-
? "AgentSpine recorded the allowed mutation intent for the delivery premortem."
|
|
267
|
-
: "AgentSpine recorded the direct write for the delivery premortem.",
|
|
268
|
-
`Premortem latest write sha256 ${premortem.writeDigest}`
|
|
269
|
-
].join("\n"));
|
|
270
|
-
}
|
|
271
|
-
if (lessonRecall?.status === "recalled") {
|
|
272
|
-
c.push(JSON.stringify({
|
|
273
|
-
schema: lessonRecall.schema, receiptDigest: lessonRecall.receiptDigest,
|
|
274
|
-
instruction: lessonRecall.instruction, items: lessonRecall.items,
|
|
275
|
-
learning: lessonRecall.learning || [], learningDiagnostics: lessonRecall.learningDiagnostics || null,
|
|
276
|
-
omitted: lessonRecall.omitted,
|
|
277
|
-
authority: "context-only"
|
|
278
|
-
}));
|
|
279
|
-
}
|
|
280
|
-
const o={hookEventName:event},f=env.BLUN_PLUGIN_ROOT?"message":"additionalContext";
|
|
281
|
-
if(w.length)o[f]=w.join("\n");
|
|
282
|
-
if(c.length)o.additionalContext=[o.additionalContext,...c].filter(Boolean).join("\n");
|
|
283
|
-
return Object.keys(o).length>1?{hookSpecificOutput:o}:{};
|
|
284
|
-
}
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
inspectPremortemState,
|
|
3
|
-
preparePremortemRequirement,
|
|
4
|
-
recordPremortemWriteIntent,
|
|
5
|
-
recordPremortemWrite,
|
|
6
|
-
verifyPremortemBeforeWrite,
|
|
7
|
-
verifyPremortemStop
|
|
8
|
-
} from "./delivery-premortem.js";
|
|
9
|
-
import { consumeDeliveryAgentUse, deliveryAgentUseGuidance,
|
|
10
|
-
removeDeliveryAgentUse, verifyDeliveryAgentUse } from "./delivery-agent-usage.js";
|
|
11
|
-
import { deliveryToolActions, verifyDeliveryStop } from "./delivery-verification.js";
|
|
12
|
-
import { boundedId } from "./hook-context.js";
|
|
13
|
-
import { auditGuard } from "./hook-protection.js";
|
|
14
|
-
import { comparablePath, projectId as localProjectId } from "./paths.js";
|
|
15
|
-
import { resolveFinalAssistantMessage } from "./hook-final-message.js";
|
|
16
|
-
import { assignmentPremortemBinding, beginDeliveryAssignment, continueDeliveryAssignment,
|
|
17
|
-
resolveDeliveryAssignment } from "./delivery-assignment.js";
|
|
18
|
-
import { deliveryWriteIdDigest } from "./delivery-premortem-binding.js";
|
|
19
|
-
|
|
20
|
-
export function premortemBinding(input, scope, root = null) {
|
|
21
|
-
return {
|
|
22
|
-
host: scope?.host || null,
|
|
23
|
-
sessionId: boundedId(input?.session_id ?? input?.sessionId, "sessionId"),
|
|
24
|
-
entityId: scope?.entityId || null,
|
|
25
|
-
groupId: scope?.groupId || null,
|
|
26
|
-
projectId: scope?.projectId || (root ? `project:${localProjectId(comparablePath(root))}` : null),
|
|
27
|
-
taskId: scope?.goalId || scope?.queueId ? null : scope?.currentTaskId || null,
|
|
28
|
-
assignmentId: input?.assignment_id || input?.assignmentId || null,
|
|
29
|
-
goalId: scope?.goalId || null,
|
|
30
|
-
goalStepId: scope?.goalStepId || null,
|
|
31
|
-
queueId: scope?.queueId || null,
|
|
32
|
-
planDefinitionsDigest: scope?.planDefinitionsDigest || null,
|
|
33
|
-
gatewayAttempt: scope?.gatewayAttempt || null
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function exactBinding(input, scope, root, begin = false) {
|
|
38
|
-
if (input?.assignment_id && input?.assignmentId && input.assignment_id !== input.assignmentId) {
|
|
39
|
-
return { status: "foreign-assignment", blocked: true,
|
|
40
|
-
reason: "Conflicting assignment_id and assignmentId cannot select a delivery." };
|
|
41
|
-
}
|
|
42
|
-
const binding = premortemBinding(input, scope, root);
|
|
43
|
-
if (begin && binding.assignmentId) {
|
|
44
|
-
return continueDeliveryAssignment({ root, binding, assignmentId: binding.assignmentId });
|
|
45
|
-
}
|
|
46
|
-
const suppliedEventId = input?.event_id ?? input?.hook_event_id ?? input?.turn_id;
|
|
47
|
-
const promptEventId = suppliedEventId
|
|
48
|
-
? boundedId(suppliedEventId, "eventId")
|
|
49
|
-
: `prompt:${deliveryWriteIdDigest({ tool_input: input?.prompt ?? input?.user_prompt
|
|
50
|
-
?? input?.message ?? input?.input ?? null })}`;
|
|
51
|
-
const assignment = begin
|
|
52
|
-
? await beginDeliveryAssignment({ root, binding,
|
|
53
|
-
eventId: promptEventId,
|
|
54
|
-
now: input.timestamp || new Date() })
|
|
55
|
-
: await resolveDeliveryAssignment({ root, binding, assignmentId: binding.assignmentId });
|
|
56
|
-
return assignment.blocked ? assignment : {
|
|
57
|
-
...assignment, binding: assignmentPremortemBinding(binding, assignment)
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function isPremortemWrite(input) {
|
|
62
|
-
return deliveryToolActions(input).some((item) => item.kind === "write");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function diagnostic(input, phase, result) {
|
|
66
|
-
if (result?.status === "degraded") await auditGuard(input, phase, result);
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function degraded(error, path) {
|
|
71
|
-
return {
|
|
72
|
-
status: "degraded", blocked: false, path,
|
|
73
|
-
reason: String(error?.message || error || "premortem state unavailable").slice(0, 2048)
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function invalidWriteSession(error, path) {
|
|
78
|
-
return {
|
|
79
|
-
status: "invalid-session", blocked: true, path,
|
|
80
|
-
reason: "AgentSpine denied this write before mutation because a valid host session_id is required: "
|
|
81
|
-
+ String(error?.message || error || "sessionId is missing").slice(0, 400)
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function withRegistrationGuidance(result, root, assignmentId = null) {
|
|
86
|
-
const requirementId = result.requirementId || result.requirement?.requirementId || null;
|
|
87
|
-
const registration = { tool: "record_delivery_premortem", root, requirementId };
|
|
88
|
-
const agentSpineUse = deliveryAgentUseGuidance(root, requirementId);
|
|
89
|
-
return {
|
|
90
|
-
...result, assignmentId, registration, agentSpineUse,
|
|
91
|
-
instruction: [
|
|
92
|
-
"Advisory preparation; never blocks authorized coding or replies. Bind calls to session, assignment and step:",
|
|
93
|
-
"Reuse the host-verified briefing; delivery_knowledge_query and record_delivery_premortem need no second briefing fetch.",
|
|
94
|
-
`Use registration.root; Requirement: ${requirementId || "<unavailable; continue the authorized task>"}.`,
|
|
95
|
-
"Premortem: exactly baseline-environment, contract-tests, delivery-path; each `this delivery fails because ` statement needs a concrete check.",
|
|
96
|
-
"Context only; no authority. Never reset receipts or repeat tests merely to dismiss a warning.",
|
|
97
|
-
"Host continuation: UserPromptSubmit assignmentId; omit for new work. Chat cannot select continuation.",
|
|
98
|
-
"After observed tests: ordinary assignments use complete_delivery; goals retain checkpoints/outcomes. Legacy closure:",
|
|
99
|
-
"`Premortem closure sha256 <64hex>`, `Premortem latest write sha256 <64hex>`, and:",
|
|
100
|
-
"- <category> <checkId>: PASS — <nonempty result>"
|
|
101
|
-
].join("\n")
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function prepareHookPremortem({ input, root, scope }) {
|
|
106
|
-
try {
|
|
107
|
-
const exact = await exactBinding(input, scope, root, true);
|
|
108
|
-
if (exact.blocked) return withRegistrationGuidance(exact, root, exact.assignmentId);
|
|
109
|
-
if (exact.status === "degraded") {
|
|
110
|
-
await diagnostic(input, "premortem-prepare", exact);
|
|
111
|
-
return withRegistrationGuidance(exact, root);
|
|
112
|
-
}
|
|
113
|
-
if (exact.status === "continued") return withRegistrationGuidance({
|
|
114
|
-
status: "required", blocked: false, requirementId: exact.requirementId,
|
|
115
|
-
requirement: exact.requirement, continuation: true
|
|
116
|
-
}, root, exact.assignmentId);
|
|
117
|
-
const result = await preparePremortemRequirement({
|
|
118
|
-
root, binding: exact.binding, now: input.timestamp || new Date()
|
|
119
|
-
});
|
|
120
|
-
await diagnostic(input, "premortem-prepare", result);
|
|
121
|
-
return withRegistrationGuidance(result, root, exact.assignmentId);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
const result = degraded(error, root);
|
|
124
|
-
await diagnostic(input, "premortem-prepare", result);
|
|
125
|
-
return withRegistrationGuidance(result, root);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function verifyHookPremortemWrite({ input, root, scope }) {
|
|
130
|
-
if (!isPremortemWrite(input)) return { status: "not-applicable", blocked: false };
|
|
131
|
-
try {
|
|
132
|
-
if (!boundedId(input?.session_id ?? input?.sessionId, "sessionId")) {
|
|
133
|
-
throw new Error("sessionId is missing");
|
|
134
|
-
}
|
|
135
|
-
} catch (error) {
|
|
136
|
-
return invalidWriteSession(error, root);
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
const exact = await exactBinding(input, scope, root);
|
|
140
|
-
if (exact.blocked) return exact;
|
|
141
|
-
const binding = exact.binding;
|
|
142
|
-
const result = await diagnostic(input, "premortem-before-write", await verifyPremortemBeforeWrite({
|
|
143
|
-
root, binding, now: input.timestamp || new Date()
|
|
144
|
-
}));
|
|
145
|
-
let requirement = null;
|
|
146
|
-
if (result.status === "missing") {
|
|
147
|
-
requirement = await diagnostic(input, "premortem-prepare-on-write", await preparePremortemRequirement({
|
|
148
|
-
root, binding, now: input.timestamp || new Date()
|
|
149
|
-
}));
|
|
150
|
-
if (requirement.status === "degraded") return withRegistrationGuidance(requirement, root);
|
|
151
|
-
if (requirement.blocked) return requirement;
|
|
152
|
-
}
|
|
153
|
-
if (result.blocked && new Set(["conflict", "late", "finalized", "mismatch"]).has(result.status)) {
|
|
154
|
-
const recovery = result.status === "conflict" ? {
|
|
155
|
-
tool: "recover_delivery_premortem", root,
|
|
156
|
-
predecessorRequirementId: result.requirementId,
|
|
157
|
-
instruction: "Recover into a fresh assignment-bound requirement, then run all three preflight calls again. History is preserved; recovery grants no authority."
|
|
158
|
-
} : null;
|
|
159
|
-
return { ...result, recovery,
|
|
160
|
-
reason: `${result.reason}\nPremortem status: ${result.status}.${recovery ? `\n${recovery.instruction}` : ""}` };
|
|
161
|
-
}
|
|
162
|
-
const requirementId = requirement?.requirementId || result.requirementId;
|
|
163
|
-
if (requirementId?.split(":").length === 3) {
|
|
164
|
-
const usage = await diagnostic(input, "delivery-agent-use-before-write",
|
|
165
|
-
await verifyDeliveryAgentUse({ root, requirementId }));
|
|
166
|
-
if (usage.blocked) {
|
|
167
|
-
const guidance = withRegistrationGuidance(requirement || result, root);
|
|
168
|
-
return { ...usage, reason: `${usage.reason}\n${guidance.instruction}` };
|
|
169
|
-
}
|
|
170
|
-
if (!result.blocked) return { ...result, agentSpineUse: usage };
|
|
171
|
-
} else if (!result.blocked) return result;
|
|
172
|
-
const named = `${result.reason}\nPremortem status: ${result.status}.`;
|
|
173
|
-
const guided = requirement ? withRegistrationGuidance(requirement, root) : null;
|
|
174
|
-
return result.status === "missing"
|
|
175
|
-
? { ...result, requirementId: guided.requirementId, registration: guided.registration,
|
|
176
|
-
reason: `${named}\n${guided.instruction}` }
|
|
177
|
-
: { ...result, reason: named };
|
|
178
|
-
} catch (error) {
|
|
179
|
-
return diagnostic(input, "premortem-before-write", degraded(error, root));
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export async function recordHookPremortemWrite({ input, root, scope, success }) {
|
|
184
|
-
if (!isPremortemWrite(input)) return { status: "not-applicable", blocked: false };
|
|
185
|
-
if (success !== true) return { status: "write-failed", blocked: false };
|
|
186
|
-
try {
|
|
187
|
-
const exact = await exactBinding(input, scope, root);
|
|
188
|
-
if (exact.blocked) return exact;
|
|
189
|
-
const result = await diagnostic(input, "premortem-write", await recordPremortemWrite({
|
|
190
|
-
root, binding: exact.binding, input,
|
|
191
|
-
now: input.timestamp || new Date()
|
|
192
|
-
}));
|
|
193
|
-
return result.status === "duplicate" ? { ...result, status: "write-recorded" } : result;
|
|
194
|
-
} catch (error) {
|
|
195
|
-
return diagnostic(input, "premortem-write", degraded(error, root));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export async function recordHookPremortemWriteIntent({ input, root, scope }) {
|
|
200
|
-
if (!isPremortemWrite(input)) return { status: "not-applicable", blocked: false };
|
|
201
|
-
try {
|
|
202
|
-
const exact = await exactBinding(input, scope, root);
|
|
203
|
-
if (exact.blocked) return exact;
|
|
204
|
-
return await diagnostic(input, "premortem-write-intent", await recordPremortemWriteIntent({
|
|
205
|
-
root, binding: exact.binding, input, now: input.timestamp || new Date()
|
|
206
|
-
}));
|
|
207
|
-
} catch (error) {
|
|
208
|
-
return diagnostic(input, "premortem-write-intent", degraded(error, root));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export async function verifyHookPremortemStop({ input, root, scope, paused = false,
|
|
213
|
-
consume = false }) {
|
|
214
|
-
if (paused) return { status: "paused-job", blocked: false };
|
|
215
|
-
try {
|
|
216
|
-
const message = resolveFinalAssistantMessage(input);
|
|
217
|
-
if (!message.known) {
|
|
218
|
-
return diagnostic(input, "premortem-stop", degraded(new Error(`premortem ${message.reason}`), root));
|
|
219
|
-
}
|
|
220
|
-
const exact = await exactBinding(input, scope, root);
|
|
221
|
-
if (exact.blocked) return exact;
|
|
222
|
-
const binding = exact.binding;
|
|
223
|
-
const inspection = await diagnostic(input, "premortem-stop-inspect",
|
|
224
|
-
await inspectPremortemState({ root, binding }));
|
|
225
|
-
let usage = null;
|
|
226
|
-
if (inspection.hasWrite && inspection.requirementId) {
|
|
227
|
-
usage = await diagnostic(input, "delivery-agent-use-stop",
|
|
228
|
-
await verifyDeliveryAgentUse({ root, requirementId: inspection.requirementId }));
|
|
229
|
-
if (usage.blocked) return usage;
|
|
230
|
-
}
|
|
231
|
-
let allowStoredCompletion = false;
|
|
232
|
-
if (inspection.completionSource === "mcp") {
|
|
233
|
-
const tested = await verifyDeliveryStop({ root, host: binding.host,
|
|
234
|
-
sessionId: binding.sessionId, scope });
|
|
235
|
-
if (tested.blocked) return diagnostic(input, "completion-test-check", tested);
|
|
236
|
-
allowStoredCompletion = tested.status === "verified";
|
|
237
|
-
}
|
|
238
|
-
const result = await diagnostic(input, "premortem-stop", await verifyPremortemStop({
|
|
239
|
-
root, binding, message: message.text,
|
|
240
|
-
allowStoredCompletion,
|
|
241
|
-
now: input.timestamp || new Date()
|
|
242
|
-
}));
|
|
243
|
-
if (!inspection.hasWrite && inspection.requirementId) {
|
|
244
|
-
await diagnostic(input, "delivery-agent-use-read-only-cleanup",
|
|
245
|
-
await removeDeliveryAgentUse({ root, requirementId: inspection.requirementId }));
|
|
246
|
-
}
|
|
247
|
-
if (consume && result.status === "closed" && usage && inspection.requirementId) {
|
|
248
|
-
const consumed = await diagnostic(input, "delivery-agent-use-consume",
|
|
249
|
-
await consumeDeliveryAgentUse({ root, requirementId: inspection.requirementId,
|
|
250
|
-
now: input.timestamp || new Date() }));
|
|
251
|
-
return { ...result, agentSpineUse: { ...usage, consumption: consumed } };
|
|
252
|
-
}
|
|
253
|
-
return result;
|
|
254
|
-
} catch (error) {
|
|
255
|
-
return diagnostic(input, "premortem-stop", degraded(error, root));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { recordHookScanAudit } from "./hook-audit.js";
|
|
2
|
-
|
|
3
|
-
// This is deliberately called only for process evidence and code-quality
|
|
4
|
-
// findings, after effect authorization. It must never wrap access denials.
|
|
5
|
-
export async function processAdvisory(input, payload, root, scope, details) {
|
|
6
|
-
const event = input.hook_event_name || input.event_name;
|
|
7
|
-
const status = details.premortem?.status || details.deliveryVerification?.status || details.artifactGuard?.status;
|
|
8
|
-
const diagnostic = {
|
|
9
|
-
schema: "agentspine.process-advisory/v1", presentation: "internal-only",
|
|
10
|
-
status: /^[a-z-]{1,64}$/.test(status || "") ? status : "unavailable",
|
|
11
|
-
completionVerified: false, action: "continue-authorized-task", automaticRetry: false,
|
|
12
|
-
authority: "context-only",
|
|
13
|
-
instruction: "Do not quote this diagnostic. Continue working or answer normally. "
|
|
14
|
-
+ "Mention only relevant evidence-backed limitations in the user's language; never invent a risk or a passed test. "
|
|
15
|
-
+ "Ask only for a consequential user decision. Do not reset receipts or repeat work to satisfy process bookkeeping."
|
|
16
|
-
};
|
|
17
|
-
const fresh = await recordHookScanAudit({
|
|
18
|
-
event,
|
|
19
|
-
phase: "process-advisory",
|
|
20
|
-
error: { code: "UNVERIFIED_DELIVERY", message: JSON.stringify(diagnostic) },
|
|
21
|
-
onceKey: JSON.stringify(["process-advisory", root, scope,
|
|
22
|
-
input.session_id || input.sessionId, input.assignment_id || input.assignmentId || null]),
|
|
23
|
-
});
|
|
24
|
-
const result = {
|
|
25
|
-
...details,
|
|
26
|
-
blocked: false,
|
|
27
|
-
advisory: true,
|
|
28
|
-
completionVerified: false,
|
|
29
|
-
diagnostic: fresh ? diagnostic : null
|
|
30
|
-
};
|
|
31
|
-
if (payload) return result;
|
|
32
|
-
const output = fresh ? { hookSpecificOutput: {
|
|
33
|
-
hookEventName: event, additionalContext: JSON.stringify(diagnostic)
|
|
34
|
-
} } : {};
|
|
35
|
-
process.stdout.write(`${JSON.stringify(output)}\n`);
|
|
36
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, relative } from "node:path";
|
|
2
|
-
import { deliveryToolActions } from "./delivery-command-actions.js";
|
|
3
|
-
import { recordHookScanAudit } from "./hook-audit.js";
|
|
4
|
-
|
|
5
|
-
export function candidatePaths(value, output = []) {
|
|
6
|
-
if (!value) return output;
|
|
7
|
-
if (typeof value === "string") {
|
|
8
|
-
for (const match of value.matchAll(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/gm)) output.push(match[1].trim());
|
|
9
|
-
return output;
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(value)) {
|
|
12
|
-
for (const item of value) candidatePaths(item, output);
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
for (const [key, item] of Object.entries(value)) {
|
|
16
|
-
if (["path", "file_path", "target_file", "filename"].includes(key) && typeof item === "string") output.push(item);
|
|
17
|
-
else candidatePaths(item, output);
|
|
18
|
-
}
|
|
19
|
-
return output;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function isMutationTool(name = "") {
|
|
23
|
-
return /(^|__)(apply_patch|edit|write|delete|move|rename|bash|exec_command|shell|powershell|pwsh)(_|$)/i.test(name);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isScanFailOpenTool(name = "") {
|
|
27
|
-
return /(^|__)(apply_patch|edit|write|bash|exec_command|shell|powershell|pwsh)(_|$)/i.test(name);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function filesystemScanError(error) {
|
|
31
|
-
return Boolean(error && (error.code === "AGENTSPINE_SCAN_INCOMPLETE" || error.agentSpineScan === true));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function hookScanFailureFailsOpen(error) {
|
|
35
|
-
return filesystemScanError(error) || (["EPERM", "EACCES"].includes(error?.code)
|
|
36
|
-
&& ["opendir", "readdir", "scandir"].includes(error?.syscall));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function auditSkippedScans(input, phase, skipped = []) {
|
|
40
|
-
const item = skipped.find((entry) => entry.code === "AGENTSPINE_SCAN_INCOMPLETE") || skipped[0];
|
|
41
|
-
if (!item) return;
|
|
42
|
-
await recordHookScanAudit({
|
|
43
|
-
event: "PreToolUse", toolName: input.tool_name || null, phase,
|
|
44
|
-
error: { code: item.code, message: item.message || `${item.code}: ${item.operation} skipped ${item.path}` },
|
|
45
|
-
path: item.path, operation: item.operation, now: input.timestamp || new Date()
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function auditGuard(input, phase, result, once = false) {
|
|
50
|
-
await recordHookScanAudit({
|
|
51
|
-
event: input.hook_event_name || input.event_name || "unknown", toolName: input.tool_name || null,
|
|
52
|
-
phase, error: { code: result.status || "GUARD_ERROR", message: result.reason || result.status },
|
|
53
|
-
path: result.path || input.cwd || process.cwd(), operation: "verify",
|
|
54
|
-
onceKey: once ? `${phase}\0${result.status}\0${result.path || input.cwd || ""}` : null,
|
|
55
|
-
now: input.timestamp || new Date()
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function allowScanFailure(input, phase, error) {
|
|
60
|
-
const event = input.hook_event_name || input.event_name || "unknown";
|
|
61
|
-
await recordHookScanAudit({
|
|
62
|
-
event, toolName: input.tool_name || null, phase, error,
|
|
63
|
-
path: error?.path || input.cwd || process.cwd(), now: input.timestamp || new Date()
|
|
64
|
-
});
|
|
65
|
-
return { blocked: false, scanFailedOpen: true, event, phase, error: error.message };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function finishScanFailure(input, payload, phase, error) {
|
|
69
|
-
const allowed = await allowScanFailure(input, phase, error);
|
|
70
|
-
if (payload) return allowed;
|
|
71
|
-
process.stdout.write("{}\n");
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function stringValues(value, output = []) {
|
|
76
|
-
if (typeof value === "string") output.push(value);
|
|
77
|
-
else if (Array.isArray(value)) value.forEach((item) => stringValues(item, output));
|
|
78
|
-
else if (value && typeof value === "object") Object.values(value).forEach((item) => stringValues(item, output));
|
|
79
|
-
return output;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function shellTargetsProtected(input, documents, cwd, root) {
|
|
83
|
-
if (!/(bash|exec_command|shell|powershell|pwsh)/i.test(input.tool_name || "")) return null;
|
|
84
|
-
const command = stringValues(input.tool_input || input.tool_args).join("\n").replaceAll("\\", "/");
|
|
85
|
-
if (!deliveryToolActions(input).some((item) => item.kind === "write")) return null;
|
|
86
|
-
for (const document of documents) {
|
|
87
|
-
const forms = new Set([document.path.replaceAll("\\", "/"), document.relativePath]);
|
|
88
|
-
for (const base of [cwd, root]) {
|
|
89
|
-
const candidate = relative(base, document.path);
|
|
90
|
-
if (candidate && !candidate.startsWith("..") && !isAbsolute(candidate)) forms.add(candidate.replaceAll("\\", "/"));
|
|
91
|
-
}
|
|
92
|
-
if ([...forms].some((form) => form && command.includes(form))) return document;
|
|
93
|
-
}
|
|
94
|
-
return null;
|
|
95
|
-
}
|