blun-king-cli 9.1.643 → 9.1.645
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/CHANGELOG.md +19 -123
- package/LIESMICH.txt +17 -45
- package/README.md +15 -76
- package/RELEASE-9.1.645.md +29 -0
- 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 +77 -180
- package/bundled-agent-sources.json +1 -552
- package/package.json +3 -6
- package/tool-liveness642/receipt.json +1 -1
- package/worker-host.mjs +62 -120
- 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,500 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
import { catalogForStateRoot, saveCatalog } from "./lib/catalog.js";
|
|
5
|
-
import { loadGraph } from "./lib/graph.js";
|
|
6
|
-
import { canonicalPath } from "./lib/paths.js";
|
|
7
|
-
import { resolveHostSourceCatalog } from "./lib/source-roots.js";
|
|
8
|
-
import { sessionBriefing } from "./lib/briefing.js";
|
|
9
|
-
import { captureContinuityPrompt } from "./lib/continuity.js";
|
|
10
|
-
import { recordLearningApplications, recordLearningDeliveries } from "./lib/learning.js";
|
|
11
|
-
import { authorizeJobEffect, checkpointJobEffect, closeJobLease } from "./lib/selfstarter.js";
|
|
12
|
-
import { syncPersonaRosterFromEnvironment } from "./lib/persona-runtime.js";
|
|
13
|
-
import { captureMustRememberPrompt, recordPreflightFailure, runPreflight, verifyPreflightReceipt } from "./lib/preflight.js";
|
|
14
|
-
import { actionLessonRecall } from "./lib/action-lesson-recall.js";
|
|
15
|
-
import { captureSessionTimelineLifecycle, finalizeUserPromptSessionTimeline } from "./lib/hook-timeline.js";
|
|
16
|
-
import { fitTimelineRecallToHostContext } from "./lib/pre-answer-timeline-recall.js";
|
|
17
|
-
import { timelineToolKind } from "./lib/mcp-timeline-tools.js";
|
|
18
|
-
import { emitTimelineToolGuard, runTimelineToolGuard } from "./lib/timeline-tool-guard.js";
|
|
19
|
-
import { readHookInput, SILENT_OVERSIZE_POST_TOOL_USE, SILENT_OVERSIZE_POST_TOOL_USE_ARG } from "./lib/hook-input.js";
|
|
20
|
-
import { isMainModule } from "./lib/runtime.js";
|
|
21
|
-
import { deliveryActorSession, deliverySuccessEvidence, recordDeliveryToolUse, recordDeliveryWriteIntent } from "./lib/delivery-verification.js";
|
|
22
|
-
import { blockPrompt, blockStop, blunRuntimeContext, blunRuntimeMessage, denyTool, hookOutput, lifecycleOutput } from "./lib/hook-output.js";
|
|
23
|
-
import { ATTENTION_WRITE_EVENTS, boundedId, captureAttentionLifecycle, hookDeliveryId, hostContextLimit, hostFromInput,
|
|
24
|
-
promptFromInput, renderContext, runtimeScope, selfstarterInput, selfstarterRootSkipped, selfstarterScope, sessionId,
|
|
25
|
-
startChannelEvent, startSelfstarter, toolResult, toolSucceeded } from "./lib/hook-context.js";
|
|
26
|
-
import { auditGuard, auditSkippedScans, candidatePaths, finishScanFailure, hookScanFailureFailsOpen, isMutationTool, isScanFailOpenTool, shellTargetsProtected } from "./lib/hook-protection.js";
|
|
27
|
-
import { captureJavaScriptBeforeWrite, inspectWrittenJavaScript, verifyBaselineBeforeWrite, verifyDeliveredArtifacts } from "./lib/hook-artifact-guards.js";
|
|
28
|
-
import { isPremortemWrite, prepareHookPremortem, recordHookPremortemWrite,
|
|
29
|
-
recordHookPremortemWriteIntent, verifyHookPremortemWrite } from "./lib/hook-premortem.js";
|
|
30
|
-
import { verifyHookStopContracts } from "./lib/hook-stop-verification.js";
|
|
31
|
-
import { processAdvisory } from "./lib/hook-process-advisory.js";
|
|
32
|
-
import { recordHookBriefingUse } from "./lib/hook-briefing-use.js";
|
|
33
|
-
export { blunRuntimeContext, blunRuntimeMessage } from "./lib/hook-output.js";
|
|
34
|
-
const CONTEXT_EVENTS = new Set(["SessionStart", "UserPromptSubmit", "PreCompact", "PostCompact"]);
|
|
35
|
-
const KNOWN_EVENTS = new Set([...CONTEXT_EVENTS, "InstructionsLoaded", "PreToolUse", "PostToolUse", "Stop", "SubagentStop"]);
|
|
36
|
-
async function writeContextOutput(output, host) {
|
|
37
|
-
const field = Object.hasOwn(output.hookSpecificOutput, "additionalContext") ? "additionalContext" : "message", content = output.hookSpecificOutput[field];
|
|
38
|
-
await new Promise((resolveWrite, rejectWrite) => process.stdout.write(`${JSON.stringify(output)}\n`, (error) => error ? rejectWrite(error) : resolveWrite()));
|
|
39
|
-
return { schema: "agentspine.host-context-handoff/v1", host, field, bytes: Buffer.byteLength(content), digest: createHash("sha256").update(content).digest("hex") };
|
|
40
|
-
}
|
|
41
|
-
async function runHookCore(input, payload, options) {
|
|
42
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("hook input must be one JSON object");
|
|
43
|
-
const event = input.hook_event_name || input.event_name || "";
|
|
44
|
-
if (!KNOWN_EVENTS.has(event)) throw new Error(`unsupported hook event: ${event || "missing"}`);
|
|
45
|
-
if (event === "InstructionsLoaded") {
|
|
46
|
-
const file = input.file_path;
|
|
47
|
-
if (typeof file !== "string" || !file || !["User", "Project", "Local", "Managed"].includes(input.memory_type)
|
|
48
|
-
|| !["session_start", "nested_traversal", "path_glob_match", "include", "compact"].includes(input.load_reason)) {
|
|
49
|
-
throw new Error("InstructionsLoaded payload is invalid");
|
|
50
|
-
}
|
|
51
|
-
if (payload) return { blocked: false, observed: true };
|
|
52
|
-
process.stdout.write("{}\n");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const cwd = await canonicalPath(input.cwd || process.cwd());
|
|
56
|
-
const host = hostFromInput(input);
|
|
57
|
-
const instructionHost = host === "generic" ? input.instruction_host : host;
|
|
58
|
-
if (host === "generic" && !["claude", "codex"].includes(instructionHost)) {
|
|
59
|
-
const reason = "AgentSpine generic hosts must bind instruction_host to claude or codex";
|
|
60
|
-
if (event === "UserPromptSubmit") {
|
|
61
|
-
if (payload) return { blocked: true, failedClosed: true, reason };
|
|
62
|
-
blockPrompt(reason);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
throw new Error(reason);
|
|
66
|
-
}
|
|
67
|
-
let resolvedSources;
|
|
68
|
-
try {
|
|
69
|
-
resolvedSources = await resolveHostSourceCatalog({ host: instructionHost, cwd, input });
|
|
70
|
-
} catch (error) {
|
|
71
|
-
if (hookScanFailureFailsOpen(error)) {
|
|
72
|
-
return finishScanFailure(input, payload, "source-resolution", error);
|
|
73
|
-
}
|
|
74
|
-
const reason = `AgentSpine source resolution failed closed: ${error.message}`;
|
|
75
|
-
if (event === "PreToolUse" && isMutationTool(input.tool_name)) {
|
|
76
|
-
if (payload) return { blocked: true, failedClosed: true, reason };
|
|
77
|
-
denyTool(reason);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (event === "UserPromptSubmit") {
|
|
81
|
-
if (payload) return { blocked: true, failedClosed: true, reason };
|
|
82
|
-
blockPrompt(reason);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const context = JSON.stringify({
|
|
86
|
-
schema: "agentspine.hook-context/v1", event, loaded: false, failedClosed: true,
|
|
87
|
-
indexedSources: 0, sourceResolution: { status: "failed-closed", reason: error.message },
|
|
88
|
-
instruction: "Do not claim AgentSpine recall succeeded. Continue under current native host rules; no remembered context or automatic effect was applied.",
|
|
89
|
-
authority: "context-only"
|
|
90
|
-
});
|
|
91
|
-
if (payload) return { blocked: false, failedClosed: true, context, error: error.message };
|
|
92
|
-
if (CONTEXT_EVENTS.has(event)) process.stdout.write(`${JSON.stringify(hookOutput(event, context))}\n`);
|
|
93
|
-
else process.stdout.write("{}\n");
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const root = resolvedSources.projectRoot;
|
|
97
|
-
const catalog = resolvedSources.catalog;
|
|
98
|
-
const diagnostics=resolvedSources.diagnostics,catalogPath=await saveCatalog(catalog),sourceWarning=[...new Set([diagnostics.warning,...resolvedSources.unverified.map((item)=>item.message),...(diagnostics.warnings||[]).map((item)=>item.message)].filter(Boolean))].join("\nAgentSpine source warning: ")||null;
|
|
99
|
-
if (CONTEXT_EVENTS.has(event) && resolvedSources.unverified.length && !catalog.summary.total) {
|
|
100
|
-
if (payload) return { blocked: false, sourceUnverified: true, sourceWarning };
|
|
101
|
-
process.stdout.write(`${JSON.stringify({ hookSpecificOutput: { hookEventName: event, message: sourceWarning } })}\n`); return;
|
|
102
|
-
}
|
|
103
|
-
let scope = null, selfstarter = null, channelEvent = null, learningDelivery = null;
|
|
104
|
-
let deliveryVerification = null, artifactGuard = null, premortem = null, lessonRecall = null;
|
|
105
|
-
if (event === "PreToolUse" && isScanFailOpenTool(input.tool_name) && diagnostics.skipped?.length) {
|
|
106
|
-
await auditSkippedScans(input, "source-resolution", diagnostics.skipped);
|
|
107
|
-
}
|
|
108
|
-
if (event === "PreToolUse" && isMutationTool(input.tool_name)) {
|
|
109
|
-
const { graph } = await loadGraph(root, catalog);
|
|
110
|
-
const inferredProtected = new Set(graph.annotations
|
|
111
|
-
.filter((annotation) => ["constitution", "soul", "memory-index", "memory-fact"].includes(annotation.layer))
|
|
112
|
-
.map((annotation) => annotation.path));
|
|
113
|
-
const protectedRelative = new Set(catalog.documents
|
|
114
|
-
.filter((doc) => doc.protected || inferredProtected.has(doc.relativePath))
|
|
115
|
-
.map((doc) => doc.relativePath));
|
|
116
|
-
let expanded = true;
|
|
117
|
-
while (expanded) {
|
|
118
|
-
expanded = false;
|
|
119
|
-
for (const edge of graph.edges) {
|
|
120
|
-
if (protectedRelative.has(edge.from) && !protectedRelative.has(edge.to)) {
|
|
121
|
-
protectedRelative.add(edge.to);
|
|
122
|
-
expanded = true;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const protectedDocuments = [...catalog.documents.filter((doc) => protectedRelative.has(doc.relativePath)),
|
|
127
|
-
...resolvedSources.unverified.map((item) => ({ path: item.path, relativePath: item.id }))];
|
|
128
|
-
const protectedPaths = new Set(protectedDocuments.map((doc) => resolve(doc.path)));
|
|
129
|
-
const targets = await Promise.all(candidatePaths(input.tool_input || input.tool_args).map(async (path) => {
|
|
130
|
-
const target = resolve(cwd, path);
|
|
131
|
-
try { return await canonicalPath(target); } catch (error) {
|
|
132
|
-
if (error.code !== "ENOENT") throw error;
|
|
133
|
-
return target;
|
|
134
|
-
}
|
|
135
|
-
}));
|
|
136
|
-
const hit = targets.find((path) => protectedPaths.has(path));
|
|
137
|
-
const shellHit = shellTargetsProtected(input, protectedDocuments, cwd, root);
|
|
138
|
-
if (hit || shellHit) {
|
|
139
|
-
const relativePath = shellHit?.relativePath
|
|
140
|
-
|| protectedDocuments.find((doc) => resolve(doc.path) === hit)?.relativePath || hit;
|
|
141
|
-
const reason = `AgentSpine protected source: ${relativePath}. Existing identity, rule, soul, and memory documents are read-only to agents.`;
|
|
142
|
-
if (payload) return { blocked: true, reason };
|
|
143
|
-
denyTool(reason);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (event === "PreToolUse") {
|
|
148
|
-
try {
|
|
149
|
-
artifactGuard = await verifyBaselineBeforeWrite({ input, cwd });
|
|
150
|
-
if (["no-stand", "no-baseline", "invalid-stand", "ambiguous-baseline"].includes(artifactGuard.status)) {
|
|
151
|
-
await auditGuard(input, "baseline-guard", artifactGuard, true);
|
|
152
|
-
}
|
|
153
|
-
if (artifactGuard.blocked) {
|
|
154
|
-
if (payload) return { blocked: true, reason: artifactGuard.reason, artifactGuard };
|
|
155
|
-
denyTool(artifactGuard.reason);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
} catch (error) {
|
|
159
|
-
artifactGuard = { status: "scan-failed-open", blocked: false, path: error.path || cwd, reason: error.message };
|
|
160
|
-
await auditGuard(input, "baseline-guard", artifactGuard);
|
|
161
|
-
}
|
|
162
|
-
try { await captureJavaScriptBeforeWrite({ input, cwd, root }); }
|
|
163
|
-
catch (error) {
|
|
164
|
-
await auditGuard(input, "identifier-before-state", {
|
|
165
|
-
status: "scan-failed-open", blocked: false, path: error.path || cwd, reason: error.message
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (event === "PreToolUse" && !selfstarterRootSkipped(diagnostics)) {
|
|
170
|
-
try {
|
|
171
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
172
|
-
const exact = await selfstarterScope(input, scope, root, "effect");
|
|
173
|
-
if (exact) {
|
|
174
|
-
selfstarter = await authorizeJobEffect({
|
|
175
|
-
root, ...exact, toolName: input.tool_name, toolUseId: hookDeliveryId(input),
|
|
176
|
-
now: input.timestamp || new Date()
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
} catch (error) {
|
|
180
|
-
if (isScanFailOpenTool(input.tool_name) && hookScanFailureFailsOpen(error)) {
|
|
181
|
-
return finishScanFailure(input, payload, "self-starter", error);
|
|
182
|
-
}
|
|
183
|
-
const reason = `AgentSpine self-starter denied this effect: ${error.message}`;
|
|
184
|
-
if (payload) return { blocked: true, reason, selfstarter: { allowed: false, reason: error.message } };
|
|
185
|
-
denyTool(reason);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (event === "PreToolUse" && isPremortemWrite(input)) {
|
|
190
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
191
|
-
premortem = await verifyHookPremortemWrite({ input, root, scope });
|
|
192
|
-
if (premortem.blocked) {
|
|
193
|
-
if (premortem.status === "invalid-session") {
|
|
194
|
-
if (payload) return { blocked: true, reason: premortem.reason, premortem };
|
|
195
|
-
return denyTool(premortem.reason);
|
|
196
|
-
}
|
|
197
|
-
deliveryVerification = await recordDeliveryWriteIntent({
|
|
198
|
-
root, host: scope.host, sessionId: deliveryActorSession(input), scope, input
|
|
199
|
-
});
|
|
200
|
-
return processAdvisory(input, payload, root, scope, { premortem, deliveryVerification });
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (event === "PreToolUse") {
|
|
204
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
205
|
-
deliveryVerification = await recordDeliveryWriteIntent({
|
|
206
|
-
root, host: scope.host, sessionId: deliveryActorSession(input), scope, input
|
|
207
|
-
});
|
|
208
|
-
if (deliveryVerification.blocked) {
|
|
209
|
-
return processAdvisory(input, payload, root, scope, { deliveryVerification });
|
|
210
|
-
}
|
|
211
|
-
if (typeof options.afterDeliveryWriteIntent === "function") await options.afterDeliveryWriteIntent();
|
|
212
|
-
const premortemIntent = await recordHookPremortemWriteIntent({ input, root, scope });
|
|
213
|
-
if (premortemIntent.blocked) {
|
|
214
|
-
return processAdvisory(input, payload, root, scope, { deliveryVerification, premortem: premortemIntent });
|
|
215
|
-
}
|
|
216
|
-
premortem = { ...premortem, writeIntent: premortemIntent.status,
|
|
217
|
-
writeDigest: premortemIntent.writeDigest || null };
|
|
218
|
-
try { lessonRecall = await actionLessonRecall({ catalog, event, input, scope }); }
|
|
219
|
-
catch (error) { lessonRecall = { status: "degraded", items: [], reason: error.message, authority: "context-only" }; }
|
|
220
|
-
}
|
|
221
|
-
if (["PostToolUse", "Stop", "SubagentStop"].includes(event)) {
|
|
222
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
223
|
-
if (event === "PostToolUse") {
|
|
224
|
-
premortem = await recordHookPremortemWrite({
|
|
225
|
-
input, root, scope, success: toolSucceeded(input)
|
|
226
|
-
});
|
|
227
|
-
deliveryVerification = await recordDeliveryToolUse({
|
|
228
|
-
root, host: scope.host, sessionId: deliveryActorSession(input), scope,
|
|
229
|
-
input, success: deliverySuccessEvidence(input)
|
|
230
|
-
});
|
|
231
|
-
if (toolSucceeded(input)) {
|
|
232
|
-
try {
|
|
233
|
-
artifactGuard = await inspectWrittenJavaScript({ input, cwd, root });
|
|
234
|
-
} catch (error) {
|
|
235
|
-
artifactGuard = { status: "scan-failed-open", blocked: false, path: error.path || cwd, reason: error.message };
|
|
236
|
-
await auditGuard(input, "identifier-guard", artifactGuard);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
const activeJob = selfstarterRootSkipped(diagnostics)
|
|
241
|
-
? null : await selfstarterScope(input, scope, root, "resume");
|
|
242
|
-
const pauseRequested = Boolean(activeJob && selfstarterInput(input)?.status !== "completed");
|
|
243
|
-
let contracts = await verifyHookStopContracts({
|
|
244
|
-
input,
|
|
245
|
-
root,
|
|
246
|
-
scope,
|
|
247
|
-
recordPause: pauseRequested
|
|
248
|
-
});
|
|
249
|
-
({ deliveryVerification, premortem } = contracts);
|
|
250
|
-
if (contracts.blocked) {
|
|
251
|
-
return processAdvisory(input, payload, root, scope, { deliveryVerification, premortem });
|
|
252
|
-
}
|
|
253
|
-
try {
|
|
254
|
-
artifactGuard = await verifyDeliveredArtifacts({ input, cwd });
|
|
255
|
-
if (artifactGuard.blocked) {
|
|
256
|
-
return processAdvisory(input, payload, root, scope, { deliveryVerification, artifactGuard });
|
|
257
|
-
}
|
|
258
|
-
} catch (error) {
|
|
259
|
-
artifactGuard = { status: "scan-failed-open", blocked: false, path: error.path || cwd, reason: error.message };
|
|
260
|
-
await auditGuard(input, "delivery-artifact-guard", artifactGuard);
|
|
261
|
-
}
|
|
262
|
-
if (typeof options.afterArtifactVerification === "function") await options.afterArtifactVerification();
|
|
263
|
-
contracts = await verifyHookStopContracts({
|
|
264
|
-
input,
|
|
265
|
-
root,
|
|
266
|
-
scope,
|
|
267
|
-
recordPause: pauseRequested,
|
|
268
|
-
completionFence: !pauseRequested,
|
|
269
|
-
afterDeliveryVerification: options.afterFinalDeliveryVerification,
|
|
270
|
-
afterPremortemVerification: options.afterFinalPremortemVerification
|
|
271
|
-
});
|
|
272
|
-
({ deliveryVerification, premortem } = contracts);
|
|
273
|
-
if (contracts.blocked) {
|
|
274
|
-
return processAdvisory(input, payload, root, scope,
|
|
275
|
-
{ deliveryVerification, premortem, artifactGuard });
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
let attentionEvent = null;
|
|
280
|
-
if (ATTENTION_WRITE_EVENTS.has(event) && !CONTEXT_EVENTS.has(event)) {
|
|
281
|
-
scope = await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
282
|
-
attentionEvent = await captureAttentionLifecycle(input, event, root, scope, catalog);
|
|
283
|
-
}
|
|
284
|
-
if (event === "PostToolUse" && !selfstarterRootSkipped(diagnostics)) {
|
|
285
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
286
|
-
const exact = await selfstarterScope(input, scope, root, "effect");
|
|
287
|
-
if (exact) {
|
|
288
|
-
selfstarter = await checkpointJobEffect({
|
|
289
|
-
root, ...exact, toolName: input.tool_name, toolUseId: hookDeliveryId(input),
|
|
290
|
-
success: toolSucceeded(input), result: toolResult(input), now: input.timestamp || new Date()
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (["Stop", "SubagentStop"].includes(event)) {
|
|
295
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
296
|
-
const exact = selfstarterRootSkipped(diagnostics)
|
|
297
|
-
? null : await selfstarterScope(input, scope, root, "resume");
|
|
298
|
-
if (exact && !scope.currentTaskId) scope.currentTaskId = exact.taskId;
|
|
299
|
-
try {
|
|
300
|
-
learningDelivery = await recordLearningDeliveries({
|
|
301
|
-
root, sessionId: sessionId(input), hookEvent: event,
|
|
302
|
-
scope: {
|
|
303
|
-
personaId: scope.entityId, userId: scope.userId, tenantId: scope.tenantId,
|
|
304
|
-
projectId: scope.projectId, groupId: scope.groupId, taskId: scope.currentTaskId
|
|
305
|
-
},
|
|
306
|
-
completedAt: input.timestamp || new Date()
|
|
307
|
-
});
|
|
308
|
-
} catch (error) {
|
|
309
|
-
learningDelivery = { status: "degraded", receipts: [], reason: error.message, authority: "context-only" };
|
|
310
|
-
}
|
|
311
|
-
const requested = selfstarterInput(input);
|
|
312
|
-
if (exact) {
|
|
313
|
-
selfstarter = await closeJobLease({
|
|
314
|
-
root, ...exact, status: requested?.status || "waiting", now: input.timestamp || new Date()
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
if (CONTEXT_EVENTS.has(event)) {
|
|
319
|
-
let signal = null;
|
|
320
|
-
let preflight = null;
|
|
321
|
-
let briefingOrigin = null;
|
|
322
|
-
try {
|
|
323
|
-
await syncPersonaRosterFromEnvironment({ root, env: process.env, now: input.timestamp || new Date(), catalog });
|
|
324
|
-
scope ||= await runtimeScope(input, root, resolvedSources.userStateRoot, catalog);
|
|
325
|
-
if (event !== "UserPromptSubmit") {
|
|
326
|
-
try { diagnostics.timeline = await captureSessionTimelineLifecycle({ root, event, input, scope,
|
|
327
|
-
hostHome: resolvedSources.hostHome, catalog }); }
|
|
328
|
-
catch (error) { diagnostics.timeline = { status: "degraded", reason: error.message, authority: "context-only" }; }
|
|
329
|
-
}
|
|
330
|
-
channelEvent = await startChannelEvent(input, event, root, scope, catalog);
|
|
331
|
-
selfstarter = await startSelfstarter(input, event, root, scope, diagnostics);
|
|
332
|
-
if (selfstarter?.job && !scope.currentTaskId) scope.currentTaskId = selfstarter.job.taskId;
|
|
333
|
-
if (event === "UserPromptSubmit") {
|
|
334
|
-
const prompt = promptFromInput(input);
|
|
335
|
-
if (prompt === null) throw new Error("mandatory preflight requires the exact current prompt");
|
|
336
|
-
preflight = await runPreflight({
|
|
337
|
-
input, scope, resolvedSources, prompt, now: input.timestamp || new Date(), env: process.env
|
|
338
|
-
});
|
|
339
|
-
if (!await verifyPreflightReceipt({
|
|
340
|
-
receipt: preflight.receipt, input, scope, resolvedSources, prompt,
|
|
341
|
-
now: input.timestamp || new Date(), env: process.env
|
|
342
|
-
})) throw new Error("newly created preflight receipt failed exact turn verification");
|
|
343
|
-
preflight.premortem = await prepareHookPremortem({ input, root, scope });
|
|
344
|
-
preflight.pendingMustRemember = await captureMustRememberPrompt({ prompt, receipt: preflight.receipt, env: process.env });
|
|
345
|
-
try {
|
|
346
|
-
attentionEvent = await captureAttentionLifecycle(input, event, root, scope, catalog);
|
|
347
|
-
} catch (error) {
|
|
348
|
-
attentionEvent = { event: null, duplicate: false, reason: `rejected:${error.message}` };
|
|
349
|
-
}
|
|
350
|
-
if (prompt !== null) {
|
|
351
|
-
try {
|
|
352
|
-
signal = await captureContinuityPrompt({
|
|
353
|
-
root, prompt, entityId: scope.entityId, groupId: scope.groupId,
|
|
354
|
-
projectId: scope.projectId, userStateRoot: resolvedSources.userStateRoot,
|
|
355
|
-
eventId: boundedId(input.event_id ?? input.hook_event_id, "eventId"), catalog,
|
|
356
|
-
userCatalog: resolvedSources.userStateRoot && resolvedSources.userStateRoot !== root
|
|
357
|
-
? catalogForStateRoot(catalog, resolvedSources.userStateRoot) : catalog
|
|
358
|
-
});
|
|
359
|
-
} catch (error) {
|
|
360
|
-
signal = { captured: false, accepted: false, reason: `rejected:${error.message}` };
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
const briefing = await sessionBriefing({
|
|
365
|
-
root, cwd, host: scope.host, entityId: scope.entityId, groupId: scope.groupId,
|
|
366
|
-
userId: scope.userId, tenantId: scope.tenantId, projectId: scope.projectId, currentTaskId: scope.currentTaskId, portalRef: scope.portalRef, threadRef: scope.threadRef,
|
|
367
|
-
includePrivate: Boolean(scope.entityId && !scope.groupId),
|
|
368
|
-
focusActive: true, includeSourceContent: event === "UserPromptSubmit" ? false : !scope.groupId,
|
|
369
|
-
maxBytes: event === "UserPromptSubmit" ? 4096 : scope.config.maxBriefingBytes,
|
|
370
|
-
now: input.timestamp || new Date(),
|
|
371
|
-
catalog, userStateRoot: resolvedSources.userStateRoot, sourceDiagnostics: event === "UserPromptSubmit" ? null : diagnostics,
|
|
372
|
-
prompt: event === "UserPromptSubmit" ? promptFromInput(input) : null, preAnswer: event === "UserPromptSubmit"
|
|
373
|
-
});
|
|
374
|
-
if (event === "PostCompact") {
|
|
375
|
-
try { lessonRecall = await actionLessonRecall({ catalog, event, input, scope }); }
|
|
376
|
-
catch (error) { lessonRecall = { status: "degraded", items: [], reason: error.message, authority: "context-only" }; }
|
|
377
|
-
}
|
|
378
|
-
let context = renderContext(event, catalog, briefing, signal, attentionEvent, selfstarter, channelEvent, diagnostics, preflight, lessonRecall);
|
|
379
|
-
if (event === "UserPromptSubmit" && Buffer.byteLength(context) > hostContextLimit(preflight)) {
|
|
380
|
-
throw new Error("mandatory preflight context exceeds the host hook injection limit");
|
|
381
|
-
}
|
|
382
|
-
if (event === "UserPromptSubmit") {
|
|
383
|
-
const finalized = await finalizeUserPromptSessionTimeline({ root, input, scope, resolvedSources, preflight,
|
|
384
|
-
prompt: promptFromInput(input), now: input.timestamp || new Date() });
|
|
385
|
-
if (!finalized.preflightConsumed) throw new Error("preflight receipt could not be consumed atomically for this exact turn");
|
|
386
|
-
briefingOrigin = finalized.briefingOrigin;
|
|
387
|
-
diagnostics.timeline = finalized.timeline;
|
|
388
|
-
}
|
|
389
|
-
if (event === "UserPromptSubmit") {
|
|
390
|
-
const activeCanaries = briefing.learning.filter((item) => ["active", "revalidating"].includes(item.outcomeStatus));
|
|
391
|
-
if (!activeCanaries.length) {
|
|
392
|
-
preflight.learningApplications = {
|
|
393
|
-
status: "not-applicable", receipts: [], authority: "context-only"
|
|
394
|
-
};
|
|
395
|
-
} else try {
|
|
396
|
-
const application = await recordLearningApplications({
|
|
397
|
-
root, items: briefing.learning,
|
|
398
|
-
scope: {
|
|
399
|
-
personaId: scope.entityId, userId: scope.userId, tenantId: scope.tenantId,
|
|
400
|
-
projectId: scope.projectId, groupId: scope.groupId, taskId: scope.currentTaskId
|
|
401
|
-
},
|
|
402
|
-
preflightReceipt: preflight.receipt,
|
|
403
|
-
sessionBriefingDigest: createHash("sha256").update(JSON.stringify(briefing)).digest("hex"),
|
|
404
|
-
projectedAt: input.timestamp || new Date()
|
|
405
|
-
});
|
|
406
|
-
preflight.learningApplications = {
|
|
407
|
-
status: application.receipts.length ? "recorded" : "not-applicable",
|
|
408
|
-
receipts: application.receipts.map((item) => ({
|
|
409
|
-
id: item.id, learningId: item.learningId, projectedAt: item.projectedAt, expiresAt: item.expiresAt
|
|
410
|
-
})),
|
|
411
|
-
authority: "context-only"
|
|
412
|
-
};
|
|
413
|
-
} catch (error) {
|
|
414
|
-
briefing.learning = briefing.learning.filter((item) => !["active", "revalidating"].includes(item.outcomeStatus));
|
|
415
|
-
preflight.learningApplications = {
|
|
416
|
-
status: "degraded", receipts: [], reason: error.message, authority: "context-only"
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
const fitted = fitTimelineRecallToHostContext({ timeline: diagnostics.timeline,
|
|
420
|
-
maximumBytes: hostContextLimit(preflight), render: (timeline) => renderContext(event, catalog, briefing,
|
|
421
|
-
signal, attentionEvent, selfstarter, channelEvent, { ...diagnostics, timeline },
|
|
422
|
-
preflight, lessonRecall) });
|
|
423
|
-
diagnostics.timeline = fitted.timeline;
|
|
424
|
-
const enriched = fitted.context;
|
|
425
|
-
if (Buffer.byteLength(enriched) <= hostContextLimit(preflight)) context = enriched;
|
|
426
|
-
else if (preflight.learningApplications.status === "degraded") {
|
|
427
|
-
preflight.learningApplications = null;
|
|
428
|
-
context = renderContext(event, catalog, briefing, signal, attentionEvent, selfstarter, channelEvent,
|
|
429
|
-
diagnostics, preflight, lessonRecall);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
if (payload) return { blocked: false, context, briefing, preflight, signal, attentionEvent, channelEvent, lessonRecall, catalogPath };
|
|
433
|
-
const output = hookOutput(event, context, process.env, sourceWarning);
|
|
434
|
-
const handoff = await writeContextOutput(output, process.env.BLUN_PLUGIN_ROOT ? "king"
|
|
435
|
-
: process.env.PLUGIN_ROOT ? "codex" : process.env.CLAUDE_PLUGIN_ROOT ? "claude" : scope.host);
|
|
436
|
-
if (event === "UserPromptSubmit" && briefingOrigin) {
|
|
437
|
-
await recordHookBriefingUse({ origin: briefingOrigin, root, handoff, now: input.timestamp || new Date() });
|
|
438
|
-
}
|
|
439
|
-
return;
|
|
440
|
-
} catch (error) {
|
|
441
|
-
if (hookScanFailureFailsOpen(error)) {
|
|
442
|
-
return finishScanFailure(input, payload, "context-lifecycle", error);
|
|
443
|
-
}
|
|
444
|
-
if (event === "UserPromptSubmit") {
|
|
445
|
-
await recordPreflightFailure({ receiptId: preflight?.receipt?.id || null, input, host,
|
|
446
|
-
error, now: input.timestamp || new Date(), env: process.env }).catch(() => {});
|
|
447
|
-
const reason = `AgentSpine pre-answer preflight blocked this turn: ${error.message}`;
|
|
448
|
-
if (payload) return { blocked: true, failedClosed: true, reason, error: error.message, catalogPath };
|
|
449
|
-
blockPrompt(reason);
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
const context = JSON.stringify({
|
|
453
|
-
schema: "agentspine.hook-context/v1", event, loaded: false, failedClosed: true,
|
|
454
|
-
indexedSources: catalog.summary.total,
|
|
455
|
-
sourceResolution: diagnostics,
|
|
456
|
-
error: error.message,
|
|
457
|
-
instruction: "Do not claim AgentSpine recall succeeded. Continue with the current request under native host rules and run agentspine audit before using remembered context.",
|
|
458
|
-
authority: "context-only"
|
|
459
|
-
});
|
|
460
|
-
if (payload) return { blocked: false, failedClosed: true, context, error: error.message, catalogPath };
|
|
461
|
-
process.stdout.write(`${JSON.stringify(hookOutput(event, context))}\n`);
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (artifactGuard?.blocked) {
|
|
466
|
-
return processAdvisory(input, payload, root, scope, { artifactGuard,
|
|
467
|
-
attentionEvent, selfstarter, learningDelivery, deliveryVerification, premortem });
|
|
468
|
-
}
|
|
469
|
-
if (payload) return { blocked: false, sourceWarning, artifactGuard, attentionEvent, selfstarter,
|
|
470
|
-
learningDelivery, deliveryVerification, premortem, lessonRecall };
|
|
471
|
-
process.stdout.write(`${JSON.stringify(lifecycleOutput(event, artifactGuard, premortem, deliveryVerification, process.env, sourceWarning, lessonRecall))}\n`);
|
|
472
|
-
}
|
|
473
|
-
export async function runHook(payload = null, options = {}) {
|
|
474
|
-
let input = payload;
|
|
475
|
-
try {
|
|
476
|
-
input ||= await readHookInput(options);
|
|
477
|
-
if (input === SILENT_OVERSIZE_POST_TOOL_USE) return;
|
|
478
|
-
if (input.hook_event_name === "PreToolUse" && timelineToolKind(input.tool_name)) {
|
|
479
|
-
const result = await runTimelineToolGuard(input);
|
|
480
|
-
if (!payload) emitTimelineToolGuard(result);
|
|
481
|
-
return result;
|
|
482
|
-
}
|
|
483
|
-
return await runHookCore(input, payload, options);
|
|
484
|
-
} catch (error) {
|
|
485
|
-
if (!hookScanFailureFailsOpen(error) || input === SILENT_OVERSIZE_POST_TOOL_USE) throw error;
|
|
486
|
-
return finishScanFailure(input, payload, "lifecycle", error);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (isMainModule(import.meta.url)) {
|
|
490
|
-
const args = process.argv.slice(2);
|
|
491
|
-
const silentOversizePostToolUse = args.length === 1 && args[0] === SILENT_OVERSIZE_POST_TOOL_USE_ARG;
|
|
492
|
-
const argumentError = args.length && !silentOversizePostToolUse
|
|
493
|
-
? new Error(`unsupported hook argument: ${args[0]}`) : null;
|
|
494
|
-
(argumentError ? Promise.reject(argumentError) : runHook(null, { silentOversizePostToolUse })).catch((error) => {
|
|
495
|
-
process.stderr.write(`AgentSpine hook: ${String(error.message).slice(0, 2048)}\n`);
|
|
496
|
-
// Claude command hooks treat exit 2 as a blocking failure. Exit 1 is
|
|
497
|
-
// fail-open, which is unsafe for malformed pre-answer payloads.
|
|
498
|
-
process.exitCode = 2;
|
|
499
|
-
});
|
|
500
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
export { buildCatalog, loadCatalog, saveCatalog, scanAndSave, verifyCatalog } from "./lib/catalog.js";
|
|
2
|
-
export { resolveContext, readDocument } from "./lib/context.js";
|
|
3
|
-
export { sessionBriefing } from "./lib/briefing.js";
|
|
4
|
-
export { recordWorldAssertion, worldContext, worldModelStatePath } from "./lib/world-model.js";
|
|
5
|
-
export { discoverDocuments } from "./lib/documents.js";
|
|
6
|
-
export {
|
|
7
|
-
bindSourceRoot, inspectSourceRegistry, purgeSourceBinding, resolveHostSourceCatalog,
|
|
8
|
-
rollbackSourceBinding, SOURCE_REGISTRY_SCHEMA
|
|
9
|
-
} from "./lib/source-roots.js";
|
|
10
|
-
export { runAudit } from "./lib/audit.js";
|
|
11
|
-
export {
|
|
12
|
-
attentionContext, attentionFindings, configureAttention, deleteAttention, inspectAttention, loadAttention,
|
|
13
|
-
recordActivity, recordAttentionEvent, resolveAttention, upsertAttention
|
|
14
|
-
} from "./lib/attention.js";
|
|
15
|
-
export {
|
|
16
|
-
acceptContinuityLearning, addLearningEvidence, beginLearningRevalidation, configureLearning, deleteLearning, evaluateLearning,
|
|
17
|
-
learningContext, learningOutcomeStatus, loadLearning, proposeLearning, purgeLearningBySubject,
|
|
18
|
-
purgeStaleLearningApplications, recordLearningOutcome, registerLearningEvaluation, renewLearningValidation,
|
|
19
|
-
reviewLearning, revokeLearningApplication, revokeLearningDelivery, revokeLearningEvaluation, revokeLearningEvidence, revokeLearningMeasurement, revokeLearningOutcome, revokeLearningTrialFailure, revokeLearningValidation,
|
|
20
|
-
rollbackLearning
|
|
21
|
-
} from "./lib/learning.js";
|
|
22
|
-
export {
|
|
23
|
-
captureContinuityPrompt, configureContinuity, continuityFindings,
|
|
24
|
-
inspectContinuity, loadContinuity, purgeContinuity
|
|
25
|
-
} from "./lib/continuity.js";
|
|
26
|
-
export {
|
|
27
|
-
checkDelegation, createTask, deleteTask, grantDelegation, loadCoordination,
|
|
28
|
-
loadDelegationPolicy, revokeDelegation, taskContext, updateTask
|
|
29
|
-
} from "./lib/coordination.js";
|
|
30
|
-
export {
|
|
31
|
-
authorizeJobEffect, cancelJob, checkpointJobEffect, closeJobLease, deleteJob,
|
|
32
|
-
executionPolicyFindings, grantExecution, inspectSelfstarter, loadExecutionPolicy,
|
|
33
|
-
loadSelfstarter, registerJob, resolveSessionJob, revokeExecution, selfstarterContext,
|
|
34
|
-
selfstarterFindings, startOrResumeJob, workspaceFingerprint
|
|
35
|
-
} from "./lib/selfstarter.js";
|
|
36
|
-
export {
|
|
37
|
-
CHANNEL_EVENT_SCHEMA, CHANNEL_POLICY_SCHEMA, CHANNEL_RUNTIME_SCHEMA,
|
|
38
|
-
channelEventSigningPayload, channelPolicyFindings, channelRuntimeContext,
|
|
39
|
-
channelRuntimeFindings, claimChannelEvent, completeChannelEvent,
|
|
40
|
-
grantChannelBinding, ingestChannelEvent, inspectChannelRuntime,
|
|
41
|
-
loadChannelPolicy, loadChannelRuntime, revokeChannelBinding
|
|
42
|
-
} from "./lib/channel-runtime.js";
|
|
43
|
-
export {
|
|
44
|
-
PERSONA_EVENT_SCHEMA, PERSONA_POLICY_SCHEMA, PERSONA_ROSTER_SCHEMA, PERSONA_RUNTIME_SCHEMA,
|
|
45
|
-
applyPersonaRoster, inspectPersonaRuntime, loadPersonaRuntime, personaContext,
|
|
46
|
-
personaRuntimeFindings, syncPersonaRosterFromEnvironment
|
|
47
|
-
} from "./lib/persona-runtime.js";
|
|
48
|
-
export {
|
|
49
|
-
EXECUTION_ATTEMPT_SCHEMA, GATEWAY_EVENT_SCHEMA, GATEWAY_POLICY_SCHEMA, GATEWAY_RUNTIME_SCHEMA,
|
|
50
|
-
GOAL_PLAN_SCHEMA,
|
|
51
|
-
assignGoal, claimGatewayWork, completeGatewayRun, deliverPrepared, failGatewayRun, markGatewayHostStarted, reviewLegacyGatewayHold,
|
|
52
|
-
enqueueGatewayWake, executionAttemptForStep, gatewayContext, gatewayRuntimeFindings,
|
|
53
|
-
inspectGatewayRuntime, loadGatewayRuntime, reconcileGateway, resolveGoalKnowledgeGap, setGatewayControl
|
|
54
|
-
} from "./lib/gateway-runtime.js";
|
|
55
|
-
export { createTelegramAdapter } from "./lib/telegram-adapter.js";
|
|
56
|
-
export { evaluateVoiceOutput, voiceCue } from "./lib/voice-runtime.js";
|
|
57
|
-
export {
|
|
58
|
-
MUST_REMEMBER_SCHEMA, PREFLIGHT_POLICY_SCHEMA, PREFLIGHT_SCHEMA, RETRIEVAL_QUERY_SCHEMA,
|
|
59
|
-
RETRIEVAL_RESULT_SCHEMA, captureMustRememberPrompt, configurePreflightPolicy, confirmMustRemember, preflightStatus,
|
|
60
|
-
recordPreflightFailure,
|
|
61
|
-
proposeMustRemember, purgeMustRemember, rollbackMustRemember, runPreflight, verifyPreflightReceipt
|
|
62
|
-
} from "./lib/preflight.js";
|
|
63
|
-
export { runWorker, runWorkerTick } from "./worker.js";
|
|
64
|
-
export {
|
|
65
|
-
AUTONOMY_ACTIONS, AUTONOMY_CONFIRMATION, AUTONOMY_MODES, AUTONOMY_SCHEMA, EVIDENCE_CLASSES,
|
|
66
|
-
PUBLISH_CONFIRMATION, autonomyFindings, autonomyStatus, configureAutonomyProject,
|
|
67
|
-
evaluateAutonomyAction, loadAutonomy, modeAllows, projectPortfolioContext,
|
|
68
|
-
recordProjectObservation, revokeAutonomyProject, scanProjectPortfolio
|
|
69
|
-
} from "./lib/autonomy.js";
|
|
70
|
-
export {
|
|
71
|
-
createKnowledgeGap, createSelfHelpReport, createSelfHelpRequirement, createSelfHelpResolution,
|
|
72
|
-
KNOWLEDGE_GAP_SCHEMA, pendingSelfHelpRequirement, resolveKnowledgeGapCandidate,
|
|
73
|
-
sameKnowledgeGapResolution, SELF_HELP_REPORT_SCHEMA, SELF_HELP_REQUIREMENT_SCHEMA,
|
|
74
|
-
selfHelpPolicyForWorkItem, validKnowledgeGap, validSelfHelpReport, validSelfHelpRequirement,
|
|
75
|
-
validStepKnowledgeState
|
|
76
|
-
} from "./lib/knowledge-evidence.js";
|
|
77
|
-
export {
|
|
78
|
-
configureSharing, deleteShared, initDirectoryAdapter, inspectSharing, loadSharing,
|
|
79
|
-
publishLearning, pullShared, readDirectoryExchange, reviewShared, rollbackShared, sharedContext, sharedInbox,
|
|
80
|
-
sharingAuthenticationFindings, sharingFindings, validateSharedEvent
|
|
81
|
-
} from "./lib/sharing.js";
|
|
82
|
-
export {
|
|
83
|
-
buildHttpsSnapshot, exportHttpsSnapshot, fetchHttpsSnapshot, importHttpsSnapshot, pullHttpsSnapshot,
|
|
84
|
-
resolveHttpsEndpoint, validateHttpsEndpoint, validateHttpsSnapshot
|
|
85
|
-
} from "./lib/https-transport.js";
|
|
86
|
-
export {
|
|
87
|
-
httpsObjectUrl, publishHttpsSnapshot, putHttpsSnapshot, validateHttpsObjectBase
|
|
88
|
-
} from "./lib/object-transport.js";
|
|
89
|
-
export {
|
|
90
|
-
fetchHttpsFeed, httpsFeedUrl, inspectHttpsFeedState, loadHttpsFeedState, publishHttpsFeed,
|
|
91
|
-
pullHttpsFeed, validateHttpsFeed
|
|
92
|
-
} from "./lib/feed-transport.js";
|
|
93
|
-
export {
|
|
94
|
-
buildPeerResponse, createPeerRequest, importPeerResponse, pullPeerCommand,
|
|
95
|
-
servePeerOnce, validatePeerRequest, validatePeerResponse
|
|
96
|
-
} from "./lib/peer-transport.js";
|
|
97
|
-
export {
|
|
98
|
-
initSqliteAdapter, inspectSqliteAdapter, publishSqliteSnapshot, pullSqliteSnapshot
|
|
99
|
-
} from "./lib/sqlite-transport.js";
|
|
100
|
-
export {
|
|
101
|
-
assertTrustedIdentity, generateSigningIdentity, inspectSignerRegistry, inspectTrust, listSigningIdentities,
|
|
102
|
-
loadTrust, revokeTrustedSigner, signEnvelope, trustedSignerContext, trustFindings,
|
|
103
|
-
trustSigner, validatePublicIdentity, verifyEnvelope
|
|
104
|
-
} from "./lib/authentication.js";
|
|
105
|
-
export {
|
|
106
|
-
annotateDocument, linkDocuments, linkEntities, loadGraph, unlinkEntities,
|
|
107
|
-
relationshipContext, upsertEntity
|
|
108
|
-
} from "./lib/graph.js";
|