blun-king-cli 9.1.643 → 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 +18 -179
- package/bundled-agent-sources.json +1 -552
- package/package.json +1 -5
- package/tool-liveness642/receipt.json +1 -1
- package/worker-host.mjs +3 -119
- 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,350 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EXECUTION_ATTEMPT_SCHEMA, EXECUTION_OUTCOME_SCHEMA, ID_RE, METRIC_OPERATORS,
|
|
3
|
-
STRATEGY_TRANSFER_PROOF_SCHEMA, exactId, sha256, timestamp
|
|
4
|
-
} from "./gateway-common.js";
|
|
5
|
-
|
|
6
|
-
function executionDecisionMaterial(execution) {
|
|
7
|
-
return {
|
|
8
|
-
requiredCapabilities: execution.requiredCapabilities, strategies: execution.strategies,
|
|
9
|
-
verification: execution.verification, selectedStrategyId: execution.selectedStrategyId,
|
|
10
|
-
...(execution.explorationMaxAttempts === undefined ? {} : {
|
|
11
|
-
explorationMaxAttempts: execution.explorationMaxAttempts,
|
|
12
|
-
explorationOrder: execution.explorationOrder
|
|
13
|
-
}),
|
|
14
|
-
...(execution.transferKey === undefined ? {} : {
|
|
15
|
-
transferKey: execution.transferKey, transferMaxAgeDays: execution.transferMaxAgeDays,
|
|
16
|
-
transferProof: execution.transferProof
|
|
17
|
-
}),
|
|
18
|
-
authority: "context-only-decision"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function sufficientExecutionStrategies(execution) {
|
|
23
|
-
const required = new Set(execution.requiredCapabilities);
|
|
24
|
-
return execution.strategies.filter((strategy) => strategy.capabilities.every((capability) => ID_RE.test(capability))
|
|
25
|
-
&& [...required].every((capability) => strategy.capabilities.includes(capability)))
|
|
26
|
-
.sort((left, right) => left.risk - right.risk || left.cost - right.cost
|
|
27
|
-
|| left.strategyId.localeCompare(right.strategyId));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function selectedExecutionStrategy(execution) {
|
|
31
|
-
const sufficient = sufficientExecutionStrategies(execution);
|
|
32
|
-
const minimumRisk = sufficient[0]?.risk;
|
|
33
|
-
const transferred = execution.transferProof && sufficient.find((strategy) =>
|
|
34
|
-
strategy.strategyId === execution.transferProof.strategyId && strategy.risk === minimumRisk);
|
|
35
|
-
return transferred || sufficient[0] || null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function expectedExplorationOrder(execution) {
|
|
39
|
-
const sufficient = sufficientExecutionStrategies(execution);
|
|
40
|
-
const selected = selectedExecutionStrategy(execution);
|
|
41
|
-
if (!selected) return [];
|
|
42
|
-
return [selected, ...sufficient.filter((strategy) => strategy.risk === selected.risk
|
|
43
|
-
&& strategy.strategyId !== selected.strategyId)].map((strategy) => strategy.strategyId);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function strategyTransferProofMaterial(proof) {
|
|
47
|
-
return {
|
|
48
|
-
transferKey: proof.transferKey, strategyId: proof.strategyId, maxAgeDays: proof.maxAgeDays,
|
|
49
|
-
evidence: proof.evidence, authority: "context-only-transfer"
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function validStrategyTransferProof(proof) {
|
|
54
|
-
if (!(proof && proof.schema === STRATEGY_TRANSFER_PROOF_SCHEMA
|
|
55
|
-
&& ID_RE.test(proof.proofId || "") && ID_RE.test(proof.transferKey || "")
|
|
56
|
-
&& ID_RE.test(proof.strategyId || "") && Number.isInteger(proof.maxAgeDays)
|
|
57
|
-
&& proof.maxAgeDays >= 1 && proof.maxAgeDays <= 90 && Array.isArray(proof.evidence)
|
|
58
|
-
&& proof.evidence.length >= 2 && proof.evidence.length <= 8
|
|
59
|
-
&& new Set(proof.evidence.map((item) => item.sourceGoalId)).size === proof.evidence.length
|
|
60
|
-
&& new Set(proof.evidence.map((item) => item.sourceDigest)).size === proof.evidence.length
|
|
61
|
-
&& proof.evidence.every((item) => item && ID_RE.test(item.sourceGoalId || "")
|
|
62
|
-
&& ID_RE.test(item.sourceStepId || "") && ID_RE.test(item.outcomeId || "")
|
|
63
|
-
&& /^[a-f0-9]{64}$/.test(item.outcomeDigest || "")
|
|
64
|
-
&& /^[a-f0-9]{64}$/.test(item.sourceDigest || "")
|
|
65
|
-
&& Number.isFinite(new Date(item.completedAt).getTime()))
|
|
66
|
-
&& /^[a-f0-9]{64}$/.test(proof.proofDigest || "")
|
|
67
|
-
&& proof.authority === "context-only-transfer")) return false;
|
|
68
|
-
const digest = sha256(JSON.stringify(strategyTransferProofMaterial(proof)));
|
|
69
|
-
return proof.proofDigest === digest && proof.proofId === "strategy-transfer:" + digest.slice(0, 32);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function sameStrategy(left, right) {
|
|
73
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function sameVerification(left, right) {
|
|
77
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function collectStrategyTransferEvidence(goals, execution, strategy, scope) {
|
|
81
|
-
if (!execution.transferKey) return { evidence: [], regressed: false };
|
|
82
|
-
const before = new Date(scope.before);
|
|
83
|
-
const cutoff = new Date(before.getTime() - execution.transferMaxAgeDays * 86400000);
|
|
84
|
-
const evidence = []; let regressed = false;
|
|
85
|
-
for (const goal of goals) {
|
|
86
|
-
if (goal.goalId === scope.goalId || goal.projectId !== scope.projectId || goal.groupId !== scope.groupId || !goal.plan) continue;
|
|
87
|
-
for (const step of goal.plan.steps) {
|
|
88
|
-
const prior = step.execution;
|
|
89
|
-
const completedAt = step.completedAt && new Date(step.completedAt);
|
|
90
|
-
const updatedAt = new Date(step.updatedAt);
|
|
91
|
-
if (!prior || prior.transferKey !== execution.transferKey
|
|
92
|
-
|| !sameVerification(prior.verification, execution.verification)
|
|
93
|
-
|| !sameStrategy(prior.strategies.find((item) => item.strategyId === strategy.strategyId), strategy)
|
|
94
|
-
|| updatedAt > before) continue;
|
|
95
|
-
for (const outcome of step.executionOutcomes || []) {
|
|
96
|
-
if (outcome.strategyId !== strategy.strategyId) continue;
|
|
97
|
-
const observedAt = new Date(outcome.observedAt);
|
|
98
|
-
if (observedAt < cutoff || observedAt > before || observedAt < new Date(goal.createdAt)) continue;
|
|
99
|
-
if (!outcome.passed || outcome.blockingDefect) { regressed = true; continue; }
|
|
100
|
-
if (step.status !== "completed" || !completedAt || completedAt < cutoff || completedAt > before
|
|
101
|
-
|| observedAt > completedAt) continue;
|
|
102
|
-
evidence.push({ sourceGoalId: goal.goalId, sourceStepId: step.stepId, outcomeId: outcome.outcomeId,
|
|
103
|
-
outcomeDigest: outcome.digest, sourceDigest: outcome.sourceDigest, completedAt: step.completedAt });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const unique = [];
|
|
108
|
-
for (const item of evidence.sort((left, right) => left.completedAt.localeCompare(right.completedAt)
|
|
109
|
-
|| left.outcomeId.localeCompare(right.outcomeId))) {
|
|
110
|
-
if (!unique.some((entry) => entry.sourceGoalId === item.sourceGoalId || entry.sourceDigest === item.sourceDigest)) unique.push(item);
|
|
111
|
-
}
|
|
112
|
-
return { evidence: unique.slice(-8), regressed };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function createStrategyTransferProof(goals, execution, scope) {
|
|
116
|
-
if (!execution.transferKey) return null;
|
|
117
|
-
const required = new Set(execution.requiredCapabilities);
|
|
118
|
-
const sufficient = execution.strategies.filter((strategy) =>
|
|
119
|
-
[...required].every((capability) => strategy.capabilities.includes(capability)));
|
|
120
|
-
const minimumRisk = Math.min(...sufficient.map((strategy) => strategy.risk));
|
|
121
|
-
const proven = sufficient.filter((strategy) => strategy.risk === minimumRisk).map((strategy) => ({
|
|
122
|
-
strategy, ...collectStrategyTransferEvidence(goals, execution, strategy, scope)
|
|
123
|
-
})).filter((item) => !item.regressed && item.evidence.length >= 2)
|
|
124
|
-
.sort((left, right) => right.evidence.length - left.evidence.length
|
|
125
|
-
|| left.strategy.cost - right.strategy.cost || left.strategy.strategyId.localeCompare(right.strategy.strategyId));
|
|
126
|
-
if (!proven.length) return null;
|
|
127
|
-
const proof = { schema: STRATEGY_TRANSFER_PROOF_SCHEMA, proofId: null,
|
|
128
|
-
transferKey: execution.transferKey, strategyId: proven[0].strategy.strategyId,
|
|
129
|
-
maxAgeDays: execution.transferMaxAgeDays, evidence: proven[0].evidence,
|
|
130
|
-
proofDigest: null, authority: "context-only-transfer" };
|
|
131
|
-
proof.proofDigest = sha256(JSON.stringify(strategyTransferProofMaterial(proof)));
|
|
132
|
-
proof.proofId = "strategy-transfer:" + proof.proofDigest.slice(0, 32);
|
|
133
|
-
return proof;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function validGoalTransferProofs(goal, goals) {
|
|
137
|
-
if (!goal.plan) return true;
|
|
138
|
-
return goal.plan.steps.every((step) => {
|
|
139
|
-
if (!step.execution?.transferProof) return true;
|
|
140
|
-
const expected = createStrategyTransferProof(goals, step.execution, {
|
|
141
|
-
goalId: goal.goalId, projectId: goal.projectId, groupId: goal.groupId, before: goal.createdAt
|
|
142
|
-
});
|
|
143
|
-
return JSON.stringify(expected) === JSON.stringify(step.execution.transferProof);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function validExecutionDecision(execution) {
|
|
148
|
-
if (!(execution && execution.authority === "context-only-decision"
|
|
149
|
-
&& Array.isArray(execution.requiredCapabilities) && execution.requiredCapabilities.length > 0
|
|
150
|
-
&& execution.requiredCapabilities.length <= 16
|
|
151
|
-
&& new Set(execution.requiredCapabilities).size === execution.requiredCapabilities.length
|
|
152
|
-
&& execution.requiredCapabilities.every((capability) => ID_RE.test(capability || ""))
|
|
153
|
-
&& Array.isArray(execution.strategies) && execution.strategies.length >= 2 && execution.strategies.length <= 8
|
|
154
|
-
&& new Set(execution.strategies.map((strategy) => strategy?.strategyId)).size === execution.strategies.length
|
|
155
|
-
&& execution.strategies.every((strategy) => strategy && ID_RE.test(strategy.strategyId || "")
|
|
156
|
-
&& Array.isArray(strategy.capabilities) && strategy.capabilities.length > 0 && strategy.capabilities.length <= 16
|
|
157
|
-
&& new Set(strategy.capabilities).size === strategy.capabilities.length
|
|
158
|
-
&& strategy.capabilities.every((capability) => ID_RE.test(capability || ""))
|
|
159
|
-
&& Number.isInteger(strategy.risk) && strategy.risk >= 0 && strategy.risk <= 100
|
|
160
|
-
&& Number.isInteger(strategy.cost) && strategy.cost >= 0 && strategy.cost <= 100)
|
|
161
|
-
&& execution.verification && ID_RE.test(execution.verification.evaluatorId || "")
|
|
162
|
-
&& ID_RE.test(execution.verification.metric || "") && METRIC_OPERATORS.has(execution.verification.operator)
|
|
163
|
-
&& Number.isFinite(execution.verification.threshold)
|
|
164
|
-
&& Number.isInteger(execution.verification.minCases) && execution.verification.minCases >= 1
|
|
165
|
-
&& execution.verification.minCases <= 100000 && ID_RE.test(execution.selectedStrategyId || "")
|
|
166
|
-
&& (execution.explorationMaxAttempts === undefined || (Number.isInteger(execution.explorationMaxAttempts)
|
|
167
|
-
&& execution.explorationMaxAttempts >= 2 && execution.explorationMaxAttempts <= 4
|
|
168
|
-
&& Array.isArray(execution.explorationOrder)
|
|
169
|
-
&& execution.explorationOrder.length === execution.explorationMaxAttempts
|
|
170
|
-
&& new Set(execution.explorationOrder).size === execution.explorationOrder.length
|
|
171
|
-
&& execution.explorationOrder.every((strategyId) => ID_RE.test(strategyId || ""))))
|
|
172
|
-
&& (execution.transferKey === undefined || (ID_RE.test(execution.transferKey || "")
|
|
173
|
-
&& Number.isInteger(execution.transferMaxAgeDays) && execution.transferMaxAgeDays >= 1
|
|
174
|
-
&& execution.transferMaxAgeDays <= 90
|
|
175
|
-
&& (execution.transferProof === null || (validStrategyTransferProof(execution.transferProof)
|
|
176
|
-
&& execution.transferProof.transferKey === execution.transferKey
|
|
177
|
-
&& execution.transferProof.maxAgeDays === execution.transferMaxAgeDays))))
|
|
178
|
-
&& /^[a-f0-9]{64}$/.test(execution.decisionDigest || ""))) return false;
|
|
179
|
-
const selected = selectedExecutionStrategy(execution);
|
|
180
|
-
return selected?.strategyId === execution.selectedStrategyId
|
|
181
|
-
&& (execution.explorationMaxAttempts === undefined
|
|
182
|
-
|| JSON.stringify(execution.explorationOrder)
|
|
183
|
-
=== JSON.stringify(expectedExplorationOrder(execution).slice(0, execution.explorationMaxAttempts)))
|
|
184
|
-
&& execution.decisionDigest === sha256(JSON.stringify(executionDecisionMaterial(execution)));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function createExecutionDecision(value, field, transferContext) {
|
|
188
|
-
if (value === null || value === undefined) return null;
|
|
189
|
-
const execution = {
|
|
190
|
-
requiredCapabilities: Array.isArray(value.requiredCapabilities)
|
|
191
|
-
? value.requiredCapabilities.map((capability) => exactId(capability, `${field}.requiredCapabilities`)) : [],
|
|
192
|
-
strategies: Array.isArray(value.strategies) ? value.strategies.map((strategy, index) => ({
|
|
193
|
-
strategyId: exactId(strategy?.strategyId, `${field}.strategies[${index}].strategyId`),
|
|
194
|
-
capabilities: Array.isArray(strategy?.capabilities)
|
|
195
|
-
? strategy.capabilities.map((capability) => exactId(capability, `${field}.strategies[${index}].capabilities`)) : [],
|
|
196
|
-
risk: Number(strategy?.risk), cost: Number(strategy?.cost)
|
|
197
|
-
})) : [],
|
|
198
|
-
verification: {
|
|
199
|
-
evaluatorId: exactId(value.verification?.evaluatorId, `${field}.verification.evaluatorId`),
|
|
200
|
-
metric: exactId(value.verification?.metric, `${field}.verification.metric`),
|
|
201
|
-
operator: value.verification?.operator,
|
|
202
|
-
threshold: Number(value.verification?.threshold), minCases: Number(value.verification?.minCases)
|
|
203
|
-
},
|
|
204
|
-
selectedStrategyId: null, decisionDigest: null, authority: "context-only-decision"
|
|
205
|
-
};
|
|
206
|
-
if (value.transfer !== undefined && value.transfer !== null) {
|
|
207
|
-
execution.transferKey = exactId(value.transfer?.transferKey, `${field}.transfer.transferKey`);
|
|
208
|
-
execution.transferMaxAgeDays = Number(value.transfer?.maxAgeDays);
|
|
209
|
-
execution.transferProof = null;
|
|
210
|
-
execution.transferProof = createStrategyTransferProof(transferContext.goals, execution, transferContext.scope);
|
|
211
|
-
}
|
|
212
|
-
execution.selectedStrategyId = selectedExecutionStrategy(execution)?.strategyId || null;
|
|
213
|
-
if (value.exploration !== undefined && value.exploration !== null) {
|
|
214
|
-
execution.explorationMaxAttempts = Number(value.exploration?.maxAttempts);
|
|
215
|
-
execution.explorationOrder = expectedExplorationOrder(execution).slice(0, execution.explorationMaxAttempts);
|
|
216
|
-
}
|
|
217
|
-
execution.decisionDigest = sha256(JSON.stringify(executionDecisionMaterial(execution)));
|
|
218
|
-
if (!validExecutionDecision(execution)) {
|
|
219
|
-
throw new Error(`${field} requires 2-8 bounded strategies and one objective verification gate`);
|
|
220
|
-
}
|
|
221
|
-
return execution;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function executionOutcomeMaterial(outcome) {
|
|
225
|
-
return {
|
|
226
|
-
queueId: outcome.queueId, decisionDigest: outcome.decisionDigest, strategyId: outcome.strategyId,
|
|
227
|
-
...(outcome.attempt === undefined ? {} : {
|
|
228
|
-
attempt: outcome.attempt, previousOutcomeDigest: outcome.previousOutcomeDigest
|
|
229
|
-
}),
|
|
230
|
-
capabilitiesUsed: outcome.capabilitiesUsed, evaluatorId: outcome.evaluatorId, metric: outcome.metric,
|
|
231
|
-
value: outcome.value, cases: outcome.cases, blockingDefect: outcome.blockingDefect,
|
|
232
|
-
sourceDigest: outcome.sourceDigest, observedAt: outcome.observedAt, passed: outcome.passed,
|
|
233
|
-
authority: "objective-evidence-only"
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export function currentExecutionAttempt(execution, outcomes = []) {
|
|
238
|
-
if (execution.explorationMaxAttempts === undefined) return null;
|
|
239
|
-
if (outcomes.length >= execution.explorationMaxAttempts || outcomes.some((outcome) => outcome.passed || outcome.blockingDefect)) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
schema: EXECUTION_ATTEMPT_SCHEMA,
|
|
244
|
-
attempt: outcomes.length + 1, maxAttempts: execution.explorationMaxAttempts,
|
|
245
|
-
strategyId: execution.explorationOrder[outcomes.length],
|
|
246
|
-
previousOutcomeDigest: outcomes.at(-1)?.digest || null,
|
|
247
|
-
decisionDigest: execution.decisionDigest, authority: "context-only-attempt"
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function executionAttemptForStep(step) {
|
|
252
|
-
if (!step?.execution || !Array.isArray(step.executionOutcomes)) return null;
|
|
253
|
-
return currentExecutionAttempt(step.execution, step.executionOutcomes);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function metricPassed(operator, value, threshold) {
|
|
257
|
-
if (operator === "gte") return value >= threshold;
|
|
258
|
-
if (operator === "lte") return value <= threshold;
|
|
259
|
-
return value === threshold;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function validExecutionOutcome(outcome, execution, expectedStrategyId = execution.selectedStrategyId,
|
|
263
|
-
expectedAttempt = null, previousOutcomeDigest = null) {
|
|
264
|
-
if (!(outcome && outcome.schema === EXECUTION_OUTCOME_SCHEMA && ID_RE.test(outcome.outcomeId || "")
|
|
265
|
-
&& ID_RE.test(outcome.queueId || "") && outcome.decisionDigest === execution.decisionDigest
|
|
266
|
-
&& outcome.strategyId === expectedStrategyId
|
|
267
|
-
&& (execution.explorationMaxAttempts === undefined
|
|
268
|
-
? outcome.attempt === undefined && outcome.previousOutcomeDigest === undefined
|
|
269
|
-
: outcome.attempt === expectedAttempt && outcome.previousOutcomeDigest === previousOutcomeDigest)
|
|
270
|
-
&& Array.isArray(outcome.capabilitiesUsed)
|
|
271
|
-
&& outcome.capabilitiesUsed.length <= 16 && new Set(outcome.capabilitiesUsed).size === outcome.capabilitiesUsed.length
|
|
272
|
-
&& outcome.capabilitiesUsed.every((capability) => ID_RE.test(capability || ""))
|
|
273
|
-
&& outcome.evaluatorId === execution.verification.evaluatorId && outcome.metric === execution.verification.metric
|
|
274
|
-
&& Number.isFinite(outcome.value) && Number.isInteger(outcome.cases) && outcome.cases >= 0
|
|
275
|
-
&& typeof outcome.blockingDefect === "boolean" && /^[a-f0-9]{64}$/.test(outcome.sourceDigest || "")
|
|
276
|
-
&& Number.isFinite(new Date(outcome.observedAt).getTime()) && typeof outcome.passed === "boolean"
|
|
277
|
-
&& /^[a-f0-9]{64}$/.test(outcome.digest || "") && outcome.authority === "objective-evidence-only")) return false;
|
|
278
|
-
const strategy = execution.strategies.find((item) => item.strategyId === expectedStrategyId);
|
|
279
|
-
const used = new Set(outcome.capabilitiesUsed);
|
|
280
|
-
const expectedPass = execution.requiredCapabilities.every((capability) => used.has(capability))
|
|
281
|
-
&& outcome.capabilitiesUsed.every((capability) => strategy.capabilities.includes(capability))
|
|
282
|
-
&& outcome.cases >= execution.verification.minCases && !outcome.blockingDefect
|
|
283
|
-
&& metricPassed(execution.verification.operator, outcome.value, execution.verification.threshold);
|
|
284
|
-
const digest = sha256(JSON.stringify(executionOutcomeMaterial(outcome)));
|
|
285
|
-
return outcome.passed === expectedPass && outcome.digest === digest
|
|
286
|
-
&& outcome.outcomeId === "execution-outcome:" + digest.slice(0, 32);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export function validExecutionOutcomeSequence(execution, outcomes) {
|
|
290
|
-
if (execution.explorationMaxAttempts === undefined) {
|
|
291
|
-
return outcomes.every((outcome) => validExecutionOutcome(outcome, execution));
|
|
292
|
-
}
|
|
293
|
-
if (outcomes.length > execution.explorationMaxAttempts
|
|
294
|
-
|| new Set(outcomes.map((outcome) => outcome.sourceDigest)).size !== outcomes.length) return false;
|
|
295
|
-
let previous = null;
|
|
296
|
-
for (let index = 0; index < outcomes.length; index += 1) {
|
|
297
|
-
const outcome = outcomes[index];
|
|
298
|
-
if (!validExecutionOutcome(outcome, execution, execution.explorationOrder[index], index + 1, previous)) return false;
|
|
299
|
-
if (index < outcomes.length - 1 && (outcome.passed || outcome.blockingDefect)) return false;
|
|
300
|
-
previous = outcome.digest;
|
|
301
|
-
}
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export function reviewExecutionResult(execution, priorOutcomes, queueId, report, now) {
|
|
306
|
-
const attempt = currentExecutionAttempt(execution, priorOutcomes);
|
|
307
|
-
const expectedStrategyId = attempt?.strategyId || execution.selectedStrategyId;
|
|
308
|
-
if (!report || report.strategyId !== expectedStrategyId || !Array.isArray(report.capabilitiesUsed)
|
|
309
|
-
|| !report.outcome || report.outcome.evaluatorId !== execution.verification.evaluatorId
|
|
310
|
-
|| report.outcome.metric !== execution.verification.metric) {
|
|
311
|
-
return { passed: false, outcome: null, reason: "Objective execution evidence is missing or invalid." };
|
|
312
|
-
}
|
|
313
|
-
let outcome;
|
|
314
|
-
try {
|
|
315
|
-
outcome = {
|
|
316
|
-
schema: EXECUTION_OUTCOME_SCHEMA, outcomeId: null, queueId,
|
|
317
|
-
decisionDigest: execution.decisionDigest, strategyId: report.strategyId,
|
|
318
|
-
...(attempt === null ? {} : { attempt: attempt.attempt, previousOutcomeDigest: attempt.previousOutcomeDigest }),
|
|
319
|
-
capabilitiesUsed: report.capabilitiesUsed.map((capability) => exactId(capability, "execution.capabilitiesUsed")),
|
|
320
|
-
evaluatorId: report.outcome.evaluatorId, metric: report.outcome.metric,
|
|
321
|
-
value: Number(report.outcome.value), cases: Number(report.outcome.cases),
|
|
322
|
-
blockingDefect: report.outcome.blockingDefect === true, sourceDigest: String(report.outcome.sourceDigest || ""),
|
|
323
|
-
observedAt: timestamp(report.outcome.observedAt || now), passed: false, digest: null,
|
|
324
|
-
authority: "objective-evidence-only"
|
|
325
|
-
};
|
|
326
|
-
if (new Date(outcome.observedAt) > new Date(now)
|
|
327
|
-
|| (attempt && priorOutcomes.some((prior) => prior.sourceDigest === outcome.sourceDigest))) {
|
|
328
|
-
return { passed: false, outcome: null, reason: "Objective execution evidence is missing or invalid." };
|
|
329
|
-
}
|
|
330
|
-
const strategy = execution.strategies.find((item) => item.strategyId === expectedStrategyId);
|
|
331
|
-
const used = new Set(outcome.capabilitiesUsed);
|
|
332
|
-
outcome.passed = execution.requiredCapabilities.every((capability) => used.has(capability))
|
|
333
|
-
&& outcome.capabilitiesUsed.every((capability) => strategy.capabilities.includes(capability))
|
|
334
|
-
&& outcome.cases >= execution.verification.minCases && !outcome.blockingDefect
|
|
335
|
-
&& metricPassed(execution.verification.operator, outcome.value, execution.verification.threshold);
|
|
336
|
-
outcome.digest = sha256(JSON.stringify(executionOutcomeMaterial(outcome)));
|
|
337
|
-
outcome.outcomeId = "execution-outcome:" + outcome.digest.slice(0, 32);
|
|
338
|
-
} catch {
|
|
339
|
-
return { passed: false, outcome: null, reason: "Objective execution evidence is missing or invalid." };
|
|
340
|
-
}
|
|
341
|
-
if (!validExecutionOutcome(outcome, execution, expectedStrategyId, attempt?.attempt ?? null,
|
|
342
|
-
attempt?.previousOutcomeDigest ?? null)
|
|
343
|
-
|| !validExecutionOutcomeSequence(execution, [...priorOutcomes, outcome])) {
|
|
344
|
-
return { passed: false, outcome: null, reason: "Objective execution evidence is missing or invalid." };
|
|
345
|
-
}
|
|
346
|
-
const nextAttempt = !outcome.passed && !outcome.blockingDefect
|
|
347
|
-
? currentExecutionAttempt(execution, [...priorOutcomes, outcome]) : null;
|
|
348
|
-
return { passed: outcome.passed, outcome, nextAttempt,
|
|
349
|
-
reason: outcome.passed ? null : "The objective execution gate did not pass." };
|
|
350
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { channelRuntimeFindings, claimChannelEvent, completeChannelEvent, loadChannelPolicy, loadChannelRuntime } from "./channel-runtime.js";
|
|
2
|
-
import { loadGraph } from "./graph.js";
|
|
3
|
-
import { emptyPolicy, emptyRuntime, exactId, sha256, timestamp } from "./gateway-common.js";
|
|
4
|
-
import { assertActivePersona, exactReplyBinding } from "./gateway-runtime-identity.js";
|
|
5
|
-
import { appendReceipt } from "./gateway-runtime-records.js";
|
|
6
|
-
import { normalizePolicy, normalizeRuntime, pathsFor, readJson, withLock } from "./gateway-state.js";
|
|
7
|
-
import { loadPersonaRuntime } from "./persona-runtime.js";
|
|
8
|
-
|
|
9
|
-
const SCHEMA = "agentspine.group-response/v1";
|
|
10
|
-
const CONTRIBUTIONS = new Set(["idea", "error", "improvement"]);
|
|
11
|
-
|
|
12
|
-
// This is a host result contract, not a permission or an objective evaluation.
|
|
13
|
-
export function groupResponseContract(event) {
|
|
14
|
-
if (!event?.groupId) return null;
|
|
15
|
-
return { schema: SCHEMA, defaultKind: "silence", kinds: ["silence", "answer", ...CONTRIBUTIONS],
|
|
16
|
-
eventId: event.eventId, sessionKey: event.sessionKey, groupId: event.groupId,
|
|
17
|
-
authority: "context-only", directAddressVerified: false,
|
|
18
|
-
instruction: "Without a direct request, stay silent unless contributing a relevant idea, concrete error, or improvement. Return groupResponse with this schema and kind; silence has no text. Contributions need a stable subjectId. Answer direct requests normally. Suggestions are not verified facts. Do not echo bot status messages." };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function reviewGroupResponse({ result, text, event, item, runtime, current }) {
|
|
22
|
-
if (result?.groupResponse === undefined) return null; // Preserve the legacy reply contract.
|
|
23
|
-
const response = result.groupResponse;
|
|
24
|
-
if (!event?.groupId || event.privacy !== "group" || event.groupId !== item.groupId
|
|
25
|
-
|| event.projectId !== item.projectId || event.agentId !== item.agentId) {
|
|
26
|
-
throw new Error("group response requires the exact group channel work item");
|
|
27
|
-
}
|
|
28
|
-
if (!response || Array.isArray(response) || response.schema !== SCHEMA
|
|
29
|
-
|| !["silence", "answer", ...CONTRIBUTIONS].includes(response.kind)) {
|
|
30
|
-
throw new Error("unknown group response contract or kind");
|
|
31
|
-
}
|
|
32
|
-
const contribution = CONTRIBUTIONS.has(response.kind);
|
|
33
|
-
const keys = contribution ? ["schema", "kind", "subjectId"] : ["schema", "kind"];
|
|
34
|
-
if (Object.keys(response).length !== keys.length || Object.keys(response).some((key) => !keys.includes(key))) {
|
|
35
|
-
throw new Error("group response fields do not match its kind");
|
|
36
|
-
}
|
|
37
|
-
if (response.kind === "silence" && result.text !== undefined && result.text !== null && result.text !== "") {
|
|
38
|
-
throw new Error("silent group response must not contain text or a visible placeholder");
|
|
39
|
-
}
|
|
40
|
-
if (response.kind !== "silence" && !text) throw new Error("group contribution or answer requires text");
|
|
41
|
-
let contributionDigest = null;
|
|
42
|
-
let duplicate = false;
|
|
43
|
-
if (contribution) {
|
|
44
|
-
const subjectId = exactId(response.subjectId, "groupResponse.subjectId");
|
|
45
|
-
// The gateway derives the digest. Changing an event ID cannot repeat the same
|
|
46
|
-
// contribution; different private routes and sessions never share dedupe state.
|
|
47
|
-
contributionDigest = sha256(JSON.stringify([event.provider, event.tenantId, event.accountId,
|
|
48
|
-
event.bindingId, event.agentId, event.projectId, event.groupId, event.chatId, event.threadId,
|
|
49
|
-
event.sessionKey, subjectId, text]));
|
|
50
|
-
duplicate = runtime.receipts.some((receipt) => receipt.kind === "group-contribution-prepared"
|
|
51
|
-
&& receipt.details.schema === SCHEMA && receipt.details.contributionDigest === contributionDigest);
|
|
52
|
-
}
|
|
53
|
-
const suppressed = response.kind === "silence" || duplicate;
|
|
54
|
-
if (suppressed || contribution) appendReceipt(runtime,
|
|
55
|
-
suppressed ? "group-response-suppressed" : "group-contribution-prepared", item.queueId, current,
|
|
56
|
-
{ schema: SCHEMA, eventId: event.eventId, bindingId: event.bindingId,
|
|
57
|
-
kind: response.kind, reason: duplicate ? "duplicate" : response.kind,
|
|
58
|
-
contributionDigest, deliveryConfirmed: false, completionVerified: false });
|
|
59
|
-
return { schema: SCHEMA, kind: response.kind, suppressed, duplicate,
|
|
60
|
-
deliveryConfirmed: false, completionVerified: false };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Recover the local acknowledgement after the gateway transaction commits.
|
|
64
|
-
// No adapter, outbox or delivery receipt is involved. A crash between claim and
|
|
65
|
-
// completion resumes the same lease, or reacquires it after its original expiry.
|
|
66
|
-
export async function settleSuppressedGroupEvents({ root = process.cwd(), now = new Date() } = {}) {
|
|
67
|
-
const paths = await pathsFor(root);
|
|
68
|
-
return withLock(paths, async () => {
|
|
69
|
-
const [policy, runtime, channelPolicy, channel, personas] = await Promise.all([
|
|
70
|
-
readJson(paths.gatewayPolicyPath, paths.catalog.root, normalizePolicy, emptyPolicy),
|
|
71
|
-
readJson(paths.gatewayRuntimePath, paths.catalog.root, normalizeRuntime, emptyRuntime),
|
|
72
|
-
loadChannelPolicy(paths.catalog.root, paths.catalog), loadChannelRuntime(paths.catalog.root, paths.catalog),
|
|
73
|
-
loadPersonaRuntime(paths.catalog.root, paths.catalog)
|
|
74
|
-
]);
|
|
75
|
-
if (!policy.enabled || policy.killSwitch) return { settled: 0 };
|
|
76
|
-
const current = timestamp(now);
|
|
77
|
-
let settled = 0; let deferred = 0;
|
|
78
|
-
const pending = runtime.receipts.filter((receipt) => receipt.kind === "group-response-suppressed"
|
|
79
|
-
&& channel.runtime.events.some((event) => event.eventId === receipt.details.eventId
|
|
80
|
-
&& !["completed", "cancelled"].includes(event.status)));
|
|
81
|
-
if (pending.length) {
|
|
82
|
-
const { graph } = await loadGraph(paths.catalog.root, paths.catalog);
|
|
83
|
-
if (channelRuntimeFindings(channel.runtime, channelPolicy.policy, graph).length) {
|
|
84
|
-
throw new Error("suppressed channel event integrity mismatch");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
for (const receipt of pending) {
|
|
88
|
-
if (settled >= 20) break;
|
|
89
|
-
if (receipt.details.schema !== SCHEMA) throw new Error("unknown group response receipt version");
|
|
90
|
-
const item = runtime.queue.find((entry) => entry.queueId === receipt.objectId);
|
|
91
|
-
const event = channel.runtime.events.find((entry) => entry.eventId === receipt.details.eventId);
|
|
92
|
-
if (!item || item.status !== "completed" || item.channelEventId !== event.eventId
|
|
93
|
-
|| item.groupId !== event.groupId || item.agentId !== event.agentId || item.projectId !== event.projectId
|
|
94
|
-
|| !event.groupId || receipt.details.bindingId !== event.bindingId
|
|
95
|
-
|| runtime.outbox.some((entry) => entry.queueId === item.queueId)) {
|
|
96
|
-
throw new Error("suppressed group response lost its exact no-delivery binding");
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
assertActivePersona(personas.policy, personas.runtime, item.agentId, item.projectId, item.groupId);
|
|
100
|
-
exactReplyBinding(channelPolicy.policy, event);
|
|
101
|
-
} catch {
|
|
102
|
-
// Revocation keeps this event untouched, without stopping other work.
|
|
103
|
-
deferred += 1;
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
const workerId = "group-silence:" + sha256(item.queueId).slice(0, 32);
|
|
107
|
-
try {
|
|
108
|
-
if (event.status === "leased" && new Date(event.lease.expiresAt) > new Date(current)) {
|
|
109
|
-
if (event.lease.workerId !== workerId) { deferred += 1; continue; }
|
|
110
|
-
} else {
|
|
111
|
-
const claim = await claimChannelEvent({ root: paths.catalog.root, agentId: event.agentId,
|
|
112
|
-
projectId: event.projectId, groupId: event.groupId, provider: event.provider,
|
|
113
|
-
eventId: event.eventId, workerId, now: current, catalog: paths.catalog });
|
|
114
|
-
if (!claim.event) { deferred += 1; continue; }
|
|
115
|
-
}
|
|
116
|
-
await completeChannelEvent({ root: paths.catalog.root, eventId: event.eventId,
|
|
117
|
-
workerId, status: "completed", now: current });
|
|
118
|
-
settled += 1;
|
|
119
|
-
} catch {
|
|
120
|
-
// Local acknowledgement is recoverable bookkeeping, not a new work gate.
|
|
121
|
-
// Keep the durable suppression and do not claim acknowledgement succeeded.
|
|
122
|
-
deferred += 1;
|
|
123
|
-
break; // Do not repeat the same unavailable channel service in this tick.
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return { settled, deferred };
|
|
127
|
-
});
|
|
128
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ID_RE, safeCheckpoint, sha256 } from "./gateway-common.js";
|
|
2
|
-
|
|
3
|
-
const SCHEMA = "agentspine.host-execution-hold/v1";
|
|
4
|
-
const validTime = (value) => typeof value === "string" && Number.isFinite(new Date(value).getTime());
|
|
5
|
-
|
|
6
|
-
export function heldExecution(item) {
|
|
7
|
-
return item?.executionHold?.status === "held" ? item.executionHold : null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function newExecutionHold(item, resources = null) {
|
|
11
|
-
return { schema: SCHEMA, status: "held", workerId: item.lease.workerId,
|
|
12
|
-
claimedAt: item.lease.claimedAt, attempt: item.attempts,
|
|
13
|
-
hostSessionId: null, hostStartedAt: item.lease.hostStartedAt ?? null,
|
|
14
|
-
resources, settledAt: null, checkpointDigest: null, authority: "execution-state-only" };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function validExecutionHold(item) {
|
|
18
|
-
const hold = item.executionHold;
|
|
19
|
-
if (hold === undefined) return true;
|
|
20
|
-
return hold && hold.schema === SCHEMA && ["held", "settled"].includes(hold.status)
|
|
21
|
-
&& ID_RE.test(hold.workerId || "") && validTime(hold.claimedAt)
|
|
22
|
-
&& Number.isInteger(hold.attempt) && hold.attempt > 0 && hold.attempt === item.attempts
|
|
23
|
-
&& (hold.hostSessionId === null || ID_RE.test(hold.hostSessionId || ""))
|
|
24
|
-
&& (hold.hostStartedAt === null || validTime(hold.hostStartedAt))
|
|
25
|
-
&& (hold.resources === null || (Array.isArray(hold.resources) && hold.resources.length <= 16
|
|
26
|
-
&& new Set(hold.resources).size === hold.resources.length && hold.resources.every((resource) => ID_RE.test(resource || ""))))
|
|
27
|
-
&& (hold.status === "held" ? hold.settledAt === null && hold.checkpointDigest === null
|
|
28
|
-
: validTime(hold.settledAt) && (hold.checkpointDigest === null || /^[a-f0-9]{64}$/.test(hold.checkpointDigest)))
|
|
29
|
-
&& (!item.lease || (hold.status === "held" && hold.workerId === item.lease.workerId
|
|
30
|
-
&& hold.claimedAt === item.lease.claimedAt))
|
|
31
|
-
&& hold.authority === "execution-state-only";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Old ambiguous records have no resource snapshot. Conservatively retain the whole scope.
|
|
35
|
-
export function retainLegacyExecutionHolds(runtime) {
|
|
36
|
-
for (const item of runtime.queue) {
|
|
37
|
-
if (item.executionHold !== undefined) continue;
|
|
38
|
-
let original = item.lease ? item : null;
|
|
39
|
-
if (!original && ["blocked", "cancelled"].includes(item.status)) {
|
|
40
|
-
original = runtime.history.findLast((entry) => entry.kind === "queue"
|
|
41
|
-
&& entry.objectId === item.queueId && entry.value.attempts === item.attempts
|
|
42
|
-
&& entry.value.lease && entry.value.lease.executionMode !== "read-only")?.value;
|
|
43
|
-
}
|
|
44
|
-
if (original?.lease && original.lease.executionMode !== "read-only") {
|
|
45
|
-
item.executionHold = newExecutionHold(original);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function executionBlocks(heldItem, candidate, resources) {
|
|
51
|
-
const hold = heldExecution(heldItem);
|
|
52
|
-
if (!hold || heldItem.queueId === candidate.queueId) return false;
|
|
53
|
-
if (heldItem.agentId === candidate.agentId) return true;
|
|
54
|
-
return heldItem.projectId === candidate.projectId && heldItem.groupId === candidate.groupId
|
|
55
|
-
&& (hold.resources === null || resources.some((resource) => hold.resources.includes(resource)));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function exactHeldGeneration(item, { workerId, claimedAt, attempt }) {
|
|
59
|
-
const hold = heldExecution(item);
|
|
60
|
-
return Boolean(hold && hold.workerId === workerId && hold.claimedAt === claimedAt && hold.attempt === attempt);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function requireHostQuiescence(item, receipt, result, current) {
|
|
64
|
-
const hold = heldExecution(item);
|
|
65
|
-
if (!hold?.hostSessionId) return null;
|
|
66
|
-
const checkedAt = receipt?.checkedAt;
|
|
67
|
-
const age = new Date(current).getTime() - checkedAt;
|
|
68
|
-
if (!receipt || receipt.sessionId !== hold.hostSessionId || receipt.admissionClosed !== true
|
|
69
|
-
|| receipt.status !== "quiescent" || !Array.isArray(receipt.remaining) || receipt.remaining.length !== 0
|
|
70
|
-
|| !Number.isFinite(checkedAt) || age < 0 || age > 30000
|
|
71
|
-
|| checkedAt < new Date(hold.hostStartedAt).getTime()) {
|
|
72
|
-
throw new Error("host settlement requires fresh exact-session quiescence with no remaining work");
|
|
73
|
-
}
|
|
74
|
-
if (item.goalId && (result?.checkpoint === undefined || result.checkpoint === null)) {
|
|
75
|
-
throw new Error("host settlement requires a non-null goal checkpoint");
|
|
76
|
-
}
|
|
77
|
-
return { sessionId: hold.hostSessionId, checkedAt,
|
|
78
|
-
checkpointDigest: item.goalId ? sha256(JSON.stringify(safeCheckpoint(result.checkpoint))) : null };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function settleHostExecution(runtime, item, proof, current, appendReceipt) {
|
|
82
|
-
const hold = heldExecution(item);
|
|
83
|
-
if (!hold) return null;
|
|
84
|
-
hold.status = "settled";
|
|
85
|
-
hold.settledAt = current;
|
|
86
|
-
hold.checkpointDigest = proof?.checkpointDigest ?? null;
|
|
87
|
-
return appendReceipt(runtime, "host-execution-settled", item.queueId, current, {
|
|
88
|
-
workerId: hold.workerId, claimedAt: hold.claimedAt, attempt: hold.attempt,
|
|
89
|
-
sessionId: hold.hostSessionId, checkedAt: proof?.checkedAt ?? null,
|
|
90
|
-
checkpointDigest: hold.checkpointDigest, legacy: hold.hostSessionId === null
|
|
91
|
-
});
|
|
92
|
-
}
|