blun-king-cli 9.1.642 → 9.1.644
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LIESMICH.txt +18 -0
- package/README.md +20 -6
- package/bin/blun.js +3 -3
- package/bin/king.js +3 -3
- package/bin/launcher-mode.js +125 -126
- package/bin/launcher-runtime.js +603 -616
- package/bin/plugin-bootstrap.js +339 -405
- package/bin/rename-private-staging.cjs +2 -2
- package/bin/retired-bundled-plugins.cjs +84 -0
- package/bin/startup-security-host.cjs +105 -0
- package/bin/startup-security.cjs +9 -105
- package/bin/startup-warning-policy.cjs +22 -0
- package/bin/update-lease-installer.cjs +125 -0
- package/bin/update-lease-sockets.cjs +228 -0
- package/bin/update-lease.js +22 -327
- package/bin/verify-bundled-agent-sources.cjs +2 -4
- package/blun.mjs +78 -193
- package/bundled-agent-sources.json +1 -552
- package/package.json +4 -6
- package/tool-liveness642/index.cjs +7 -0
- package/tool-liveness642/queue-delivery.cjs +109 -0
- package/tool-liveness642/receipt.json +40 -0
- package/tool-liveness642/shell-yield.cjs +43 -0
- package/tool-liveness642/task-wait.cjs +45 -0
- package/versionierung/BELEG.json +43 -0
- package/versionierung/LIESMICH.md +5 -0
- package/versionierung/urspruenglicher-overlay-beleg.json +39 -0
- package/worker-host.mjs +48 -128
- package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
- package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
- package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
- package/agent-spine-plugin/.mcp.json +0 -8
- package/agent-spine-plugin/CHANGELOG.md +0 -1614
- package/agent-spine-plugin/LICENSE +0 -186
- package/agent-spine-plugin/README.md +0 -432
- package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
- package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
- package/agent-spine-plugin/bin/agentspine.js +0 -7
- package/agent-spine-plugin/blun.plugin.json +0 -68
- package/agent-spine-plugin/docs/acceptance.md +0 -61
- package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
- package/agent-spine-plugin/docs/host-integration.md +0 -193
- package/agent-spine-plugin/docs/preflight-recall.md +0 -71
- package/agent-spine-plugin/docs/preservation-contract.md +0 -53
- package/agent-spine-plugin/docs/quality-gates.md +0 -50
- package/agent-spine-plugin/docs/session-timeline.md +0 -112
- package/agent-spine-plugin/docs/source-roots.md +0 -113
- package/agent-spine-plugin/docs/world-model.md +0 -119
- package/agent-spine-plugin/hooks/codex.json +0 -47
- package/agent-spine-plugin/hooks/hooks.json +0 -106
- package/agent-spine-plugin/hooks/version.json +0 -5
- package/agent-spine-plugin/package.json +0 -77
- package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
- package/agent-spine-plugin/scripts/check-hosts.js +0 -208
- package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
- package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
- package/agent-spine-plugin/scripts/check-install.js +0 -478
- package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
- package/agent-spine-plugin/scripts/check-syntax.js +0 -29
- package/agent-spine-plugin/scripts/github-actions.js +0 -11
- package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
- package/agent-spine-plugin/scripts/release-check.js +0 -150
- package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
- package/agent-spine-plugin/scripts/run-checks.js +0 -50
- package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
- package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
- package/agent-spine-plugin/spine-example/1-identity.md +0 -12
- package/agent-spine-plugin/spine-example/2-voice.md +0 -6
- package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
- package/agent-spine-plugin/spine-example/4-history.md +0 -4
- package/agent-spine-plugin/src/cli-agent.js +0 -315
- package/agent-spine-plugin/src/cli-attention.js +0 -95
- package/agent-spine-plugin/src/cli-autonomy.js +0 -36
- package/agent-spine-plugin/src/cli-common.js +0 -71
- package/agent-spine-plugin/src/cli-continuity.js +0 -116
- package/agent-spine-plugin/src/cli-core.js +0 -128
- package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
- package/agent-spine-plugin/src/cli-host.js +0 -21
- package/agent-spine-plugin/src/cli-learning.js +0 -320
- package/agent-spine-plugin/src/cli-premortem.js +0 -16
- package/agent-spine-plugin/src/cli-sharing.js +0 -230
- package/agent-spine-plugin/src/cli.js +0 -181
- package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
- package/agent-spine-plugin/src/hook.js +0 -500
- package/agent-spine-plugin/src/index.js +0 -108
- package/agent-spine-plugin/src/lib/acceptance.js +0 -435
- package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
- package/agent-spine-plugin/src/lib/attention-context.js +0 -167
- package/agent-spine-plugin/src/lib/attention-events.js +0 -113
- package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
- package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
- package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
- package/agent-spine-plugin/src/lib/attention.js +0 -164
- package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
- package/agent-spine-plugin/src/lib/audit.js +0 -401
- package/agent-spine-plugin/src/lib/authentication.js +0 -515
- package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
- package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
- package/agent-spine-plugin/src/lib/autonomy.js +0 -8
- package/agent-spine-plugin/src/lib/briefing.js +0 -493
- package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
- package/agent-spine-plugin/src/lib/catalog.js +0 -167
- package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
- package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
- package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
- package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
- package/agent-spine-plugin/src/lib/context.js +0 -156
- package/agent-spine-plugin/src/lib/continuity.js +0 -338
- package/agent-spine-plugin/src/lib/coordination.js +0 -577
- package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
- package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
- package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
- package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
- package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
- package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
- package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
- package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
- package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
- package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
- package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
- package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
- package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
- package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
- package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
- package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
- package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
- package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
- package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
- package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
- package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
- package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
- package/agent-spine-plugin/src/lib/documents.js +0 -239
- package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
- package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
- package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
- package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
- package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
- package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
- package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
- package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
- package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
- package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
- package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
- package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
- package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
- package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
- package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
- package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
- package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
- package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
- package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
- package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
- package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
- package/agent-spine-plugin/src/lib/graph.js +0 -337
- package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
- package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
- package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
- package/agent-spine-plugin/src/lib/hook-context.js +0 -441
- package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
- package/agent-spine-plugin/src/lib/hook-input.js +0 -27
- package/agent-spine-plugin/src/lib/hook-output.js +0 -284
- package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
- package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
- package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
- package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
- package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
- package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
- package/agent-spine-plugin/src/lib/https-transport.js +0 -392
- package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
- package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
- package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
- package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
- package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
- package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
- package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
- package/agent-spine-plugin/src/lib/learning-context.js +0 -137
- package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
- package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
- package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
- package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
- package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
- package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
- package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
- package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
- package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
- package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
- package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
- package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
- package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
- package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
- package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
- package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
- package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
- package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
- package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
- package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
- package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
- package/agent-spine-plugin/src/lib/learning.js +0 -36
- package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
- package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
- package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
- package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
- package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
- package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
- package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
- package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
- package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
- package/agent-spine-plugin/src/lib/object-transport.js +0 -206
- package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
- package/agent-spine-plugin/src/lib/paths.js +0 -109
- package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
- package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
- package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
- package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
- package/agent-spine-plugin/src/lib/preflight.js +0 -688
- package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
- package/agent-spine-plugin/src/lib/runtime.js +0 -13
- package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
- package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
- package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
- package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
- package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
- package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
- package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
- package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
- package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
- package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
- package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
- package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
- package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
- package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
- package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
- package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
- package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
- package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
- package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
- package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
- package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
- package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
- package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
- package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
- package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
- package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
- package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
- package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
- package/agent-spine-plugin/src/lib/sharing.js +0 -969
- package/agent-spine-plugin/src/lib/source-roots.js +0 -475
- package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
- package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
- package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
- package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
- package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
- package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
- package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
- package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
- package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
- package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
- package/agent-spine-plugin/src/lib/world-model.js +0 -333
- package/agent-spine-plugin/src/mcp.js +0 -456
- package/agent-spine-plugin/src/version.js +0 -1
- package/agent-spine-plugin/src/worker.js +0 -257
- package/bin/agentspine-king-goal-inbox.mjs +0 -127
- package/bin/agentspine-king-goal-intake.mjs +0 -106
- package/bin/agentspine-king-host-runner.mjs +0 -109
- package/bin/agentspine-king-snapshot-policy.cjs +0 -80
- package/bin/agentspine-king-status-policy.mjs +0 -226
- package/bin/agentspine-king-worker-host.mjs +0 -160
- package/bin/managed-plugin-selection.cjs +0 -141
- package/bin/verify-agent-behavior.cjs +0 -122
- package/bin/verify-agent-components.cjs +0 -104
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
import { loadChannelPolicy, loadChannelRuntime } from "./channel-runtime.js";
|
|
2
|
-
import { executionBlocks, heldExecution, newExecutionHold, requireHostQuiescence,
|
|
3
|
-
settleHostExecution } from "./gateway-host-fencing.js";
|
|
4
|
-
import { reviewGroupResponse } from "./gateway-group-response.js";
|
|
5
|
-
import {
|
|
6
|
-
AMBIGUOUS_HOST_OUTCOME, assertGatewayCompletionMode, exactGatewayLeaseGeneration, failGatewayLane,
|
|
7
|
-
markHostStarted, newGatewayLease, normalizeGatewayExecutionMode,
|
|
8
|
-
requireExactGatewayLease, requireExactHostLease
|
|
9
|
-
} from "./gateway-host-lifecycle.js";
|
|
10
|
-
import { handlePlanKnowledge } from "./gateway-knowledge.js";
|
|
11
|
-
import { assertActivePersona, currentLane, exactReplyBinding } from "./gateway-runtime-identity.js";
|
|
12
|
-
import { appendReceipt, preserve } from "./gateway-runtime-records.js";
|
|
13
|
-
import * as goalPremortem from "./gateway-premortem.js";
|
|
14
|
-
import { writeGatewayStatePair } from "./gateway-state-transaction.js";
|
|
15
|
-
import { loadPersonaRuntime } from "./persona-runtime.js";
|
|
16
|
-
import { evaluateVoiceOutput } from "./voice-runtime.js";
|
|
17
|
-
import {
|
|
18
|
-
PRIORITY, emptyPolicy, emptyRuntime, exactId, safeCheckpoint, safeText,
|
|
19
|
-
sha256, timestamp
|
|
20
|
-
} from "./gateway-common.js";
|
|
21
|
-
import { reviewExecutionResult } from "./gateway-execution.js";
|
|
22
|
-
import {
|
|
23
|
-
activateNextPlanStep, conflictingResources, currentPlanStep, effectiveQueuePriority,
|
|
24
|
-
newGoalQueue, normalizePolicy, normalizeRuntime, pathsFor, planQueueKey,
|
|
25
|
-
planStepAgentId, planStepResources, queuePlanStep, readJson, withLock, writeJson
|
|
26
|
-
} from "./gateway-state.js";
|
|
27
|
-
|
|
28
|
-
export function gatewayWorkMatcher({ agentId = null, projectId = null, groupId, goalOnly = false } = {}) {
|
|
29
|
-
agentId = exactId(agentId, "agentId", true);
|
|
30
|
-
projectId = exactId(projectId, "projectId", true);
|
|
31
|
-
groupId = groupId === undefined ? undefined : exactId(groupId, "groupId", true);
|
|
32
|
-
return (item) => Boolean(item && (agentId === null || item.agentId === agentId)
|
|
33
|
-
&& (projectId === null || item.projectId === projectId)
|
|
34
|
-
&& (groupId === undefined || item.groupId === groupId)
|
|
35
|
-
&& (!goalOnly || (item.goalId && !item.channelEventId)));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export async function claimGatewayWork({ root = process.cwd(), workerId, leaseSeconds = 120,
|
|
39
|
-
executionMode = "host-effect", agentId = null, projectId = null, groupId, goalOnly = false, now = new Date() }) {
|
|
40
|
-
const matchesWork = gatewayWorkMatcher({ agentId, projectId, groupId, goalOnly });
|
|
41
|
-
const paths = await pathsFor(root);
|
|
42
|
-
return withLock(paths, async () => {
|
|
43
|
-
const [policy, runtime, personas] = await Promise.all([
|
|
44
|
-
readJson(paths.gatewayPolicyPath, paths.catalog.root, normalizePolicy, emptyPolicy),
|
|
45
|
-
readJson(paths.gatewayRuntimePath, paths.catalog.root, normalizeRuntime, emptyRuntime),
|
|
46
|
-
loadPersonaRuntime(paths.catalog.root, paths.catalog)
|
|
47
|
-
]);
|
|
48
|
-
if (!policy.enabled || policy.killSwitch) return { item: null, reason: "disabled" };
|
|
49
|
-
const current = timestamp(now); workerId = exactId(workerId, "workerId");
|
|
50
|
-
executionMode = normalizeGatewayExecutionMode(executionMode);
|
|
51
|
-
const seconds = Number(leaseSeconds);
|
|
52
|
-
if (!Number.isInteger(seconds) || seconds < 15 || seconds > 900) throw new Error("leaseSeconds must be 15-900");
|
|
53
|
-
const items = runtime.queue.filter((item) => item.status === "pending" && new Date(item.availableAt) <= new Date(current)
|
|
54
|
-
&& matchesWork(item)
|
|
55
|
-
&& !currentLane(runtime, item.agentId));
|
|
56
|
-
items.sort((a, b) => effectiveQueuePriority(policy, b) - effectiveQueuePriority(policy, a)
|
|
57
|
-
|| a.createdAt.localeCompare(b.createdAt) || a.queueId.localeCompare(b.queueId));
|
|
58
|
-
let item = null; let revoked = false;
|
|
59
|
-
for (const candidate of items) {
|
|
60
|
-
try {
|
|
61
|
-
assertActivePersona(personas.policy, personas.runtime, candidate.agentId, candidate.projectId, candidate.groupId);
|
|
62
|
-
} catch {
|
|
63
|
-
preserve(runtime, "queue", candidate, "identity-revoked", current);
|
|
64
|
-
candidate.status = "cancelled"; candidate.completedAt = current; candidate.updatedAt = current;
|
|
65
|
-
appendReceipt(runtime, "identity-revoked", candidate.queueId, current, {});
|
|
66
|
-
runtime.revision += 1; revoked = true;
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (candidate.goalStepId) {
|
|
70
|
-
const goal = policy.goals.find((entry) => entry.goalId === candidate.goalId);
|
|
71
|
-
const step = goal && currentPlanStep(goal);
|
|
72
|
-
if (!goal?.plan || goal.status !== "active" || step?.stepId !== candidate.goalStepId || step.status !== "active"
|
|
73
|
-
|| candidate.agentId !== planStepAgentId(goal, step)) {
|
|
74
|
-
preserve(runtime, "queue", candidate, "plan-step-stale", current);
|
|
75
|
-
candidate.status = "cancelled"; candidate.completedAt = current; candidate.updatedAt = current;
|
|
76
|
-
appendReceipt(runtime, "plan-step-stale", candidate.queueId, current, { goalStepId: candidate.goalStepId });
|
|
77
|
-
runtime.revision += 1; revoked = true;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const resourceConflict = runtime.queue.some((leased) => leased.status === "leased"
|
|
82
|
-
&& leased.queueId !== candidate.queueId && conflictingResources(policy, candidate, leased).length > 0);
|
|
83
|
-
if (resourceConflict) continue;
|
|
84
|
-
if (runtime.queue.some((held) => executionBlocks(held, candidate,
|
|
85
|
-
planStepResources(queuePlanStep(policy, candidate))))) continue;
|
|
86
|
-
item = candidate;
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
if (!item && revoked) await writeJson(paths.gatewayRuntimePath, runtime);
|
|
90
|
-
if (!item) return { item: null, reason: runtime.queue.some((entry) => entry.status === "pending") ? "waiting" : "idle/needs-goal" };
|
|
91
|
-
preserve(runtime, "queue", item, "leased", current);
|
|
92
|
-
item.status = "leased"; item.attempts += 1; item.updatedAt = current;
|
|
93
|
-
item.lease = newGatewayLease(workerId, current, seconds, executionMode);
|
|
94
|
-
if (executionMode === "host-effect") item.executionHold = newExecutionHold(item,
|
|
95
|
-
[...planStepResources(queuePlanStep(policy, item))]);
|
|
96
|
-
runtime.lanes = runtime.lanes.filter((lane) => lane.agentId !== item.agentId || lane.status !== "leased");
|
|
97
|
-
runtime.lanes.push({ agentId: item.agentId, queueId: item.queueId, workerId, status: "leased", claimedAt: current,
|
|
98
|
-
expiresAt: item.lease.expiresAt, updatedAt: current, authority: "execution-state-only" });
|
|
99
|
-
runtime.health.worker = "healthy"; runtime.health.lastTickAt = current; runtime.revision += 1;
|
|
100
|
-
const receipt = appendReceipt(runtime, "leased", item.queueId, current,
|
|
101
|
-
{ workerId, attempt: item.attempts, executionMode });
|
|
102
|
-
await writeJson(paths.gatewayRuntimePath, runtime);
|
|
103
|
-
return { item: structuredClone(item), receipt };
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export async function markGatewayHostStarted({ root = process.cwd(), queueId, workerId, claimedAt, attempt, hostSessionId,
|
|
108
|
-
now = new Date() }) {
|
|
109
|
-
const paths = await pathsFor(root);
|
|
110
|
-
return withLock(paths, async () => {
|
|
111
|
-
const [policy, runtime] = await Promise.all([
|
|
112
|
-
readJson(paths.gatewayPolicyPath, paths.catalog.root, normalizePolicy, emptyPolicy),
|
|
113
|
-
readJson(paths.gatewayRuntimePath, paths.catalog.root, normalizeRuntime, emptyRuntime)
|
|
114
|
-
]);
|
|
115
|
-
if (!policy.enabled || policy.killSwitch) throw new Error("gateway was disabled before host execution");
|
|
116
|
-
const item = runtime.queue.find((entry) => entry.queueId === exactId(queueId, "queueId"));
|
|
117
|
-
workerId = exactId(workerId, "workerId"); claimedAt = exactGatewayLeaseGeneration(claimedAt, attempt, "host start");
|
|
118
|
-
const current = timestamp(now);
|
|
119
|
-
const lane = requireExactHostLease(runtime, item, { workerId, claimedAt, attempt, current });
|
|
120
|
-
const sessionId = hostSessionId === undefined ? null : exactId(hostSessionId, "hostSessionId");
|
|
121
|
-
const receipt = markHostStarted(runtime, item, lane, workerId, current, { preserve, appendReceipt });
|
|
122
|
-
item.executionHold.hostSessionId = sessionId;
|
|
123
|
-
item.executionHold.hostStartedAt = current;
|
|
124
|
-
await writeJson(paths.gatewayRuntimePath, runtime);
|
|
125
|
-
return { item: structuredClone(item), receipt };
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function completeGatewayRun({ root = process.cwd(), queueId, workerId, claimedAt, attempt,
|
|
130
|
-
result, quiescence, now = new Date() }) {
|
|
131
|
-
const paths = await pathsFor(root);
|
|
132
|
-
return withLock(paths, async () => {
|
|
133
|
-
const [policy, runtime, channelPolicy, channelRuntime, personas] = await Promise.all([
|
|
134
|
-
readJson(paths.gatewayPolicyPath, paths.catalog.root, normalizePolicy, emptyPolicy),
|
|
135
|
-
readJson(paths.gatewayRuntimePath, paths.catalog.root, normalizeRuntime, emptyRuntime),
|
|
136
|
-
loadChannelPolicy(paths.catalog.root, paths.catalog), loadChannelRuntime(paths.catalog.root, paths.catalog),
|
|
137
|
-
loadPersonaRuntime(paths.catalog.root, paths.catalog)
|
|
138
|
-
]);
|
|
139
|
-
if (!policy.enabled || policy.killSwitch) throw new Error("gateway was disabled before run completion");
|
|
140
|
-
const item = runtime.queue.find((entry) => entry.queueId === exactId(queueId, "queueId"));
|
|
141
|
-
workerId = exactId(workerId, "workerId");
|
|
142
|
-
claimedAt = exactGatewayLeaseGeneration(claimedAt, attempt, "run completion"); const current = timestamp(now);
|
|
143
|
-
const lane = requireExactGatewayLease(runtime, item,
|
|
144
|
-
{ workerId, claimedAt, attempt, current, action: "run completion", allowHeld: true });
|
|
145
|
-
const hold = heldExecution(item);
|
|
146
|
-
const hostProof = requireHostQuiescence(item, quiescence, result, current);
|
|
147
|
-
const markedHostRun = assertGatewayCompletionMode(item.lease ??
|
|
148
|
-
{ executionMode: "host-effect", hostStartedAt: hold?.hostStartedAt }, result);
|
|
149
|
-
const runIdentity = assertActivePersona(personas.policy, personas.runtime, item.agentId, item.projectId, item.groupId);
|
|
150
|
-
const boundGoal = item.goalId ? policy.goals.find((entry) => entry.goalId === item.goalId) : null;
|
|
151
|
-
const previousGoal = boundGoal ? structuredClone(boundGoal) : null;
|
|
152
|
-
const boundStep = item.goalStepId ? boundGoal && currentPlanStep(boundGoal) : null;
|
|
153
|
-
if (hostProof && boundGoal && policy.goals.some((goal) => goal.goalId !== boundGoal.goalId
|
|
154
|
-
&& goal.agentId === boundGoal.agentId && goal.status === "active")) {
|
|
155
|
-
result = { ...result, completed: false, blocked: true, knowledgeGap: null, selfHelp: null,
|
|
156
|
-
blocker: "Checkpoint saved; another focused goal was assigned while this host was unresolved." };
|
|
157
|
-
}
|
|
158
|
-
if (hostProof && boundGoal?.status === "blocked" && boundGoal.blocker === AMBIGUOUS_HOST_OUTCOME
|
|
159
|
-
&& (!boundStep || boundStep.blocker === AMBIGUOUS_HOST_OUTCOME)) {
|
|
160
|
-
boundGoal.status = "active"; boundGoal.blocker = null;
|
|
161
|
-
if (boundStep) { boundStep.status = "active"; boundStep.blocker = null; }
|
|
162
|
-
}
|
|
163
|
-
if (item.goalStepId) {
|
|
164
|
-
if (!boundGoal?.plan || boundGoal.status !== "active" || boundStep?.stepId !== item.goalStepId
|
|
165
|
-
|| boundStep.status !== "active" || item.agentId !== planStepAgentId(boundGoal, boundStep)) {
|
|
166
|
-
throw new Error("run completion is not bound to the current active goal step");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const knowledgeGapRequest = result?.knowledgeGap === undefined || result?.knowledgeGap === null
|
|
170
|
-
? null : result.knowledgeGap;
|
|
171
|
-
const selfHelpRequest = result?.selfHelp === undefined || result?.selfHelp === null ? null : result.selfHelp;
|
|
172
|
-
if (knowledgeGapRequest && (item.channelEventId || !item.goalStepId || !boundGoal?.plan)) {
|
|
173
|
-
throw new Error("knowledge gaps require an exact goal-plan step without a channel obligation");
|
|
174
|
-
}
|
|
175
|
-
if (selfHelpRequest && (item.channelEventId || !item.goalStepId || !boundGoal?.plan)) {
|
|
176
|
-
throw new Error("self-help research requires an exact goal-plan step without a channel obligation");
|
|
177
|
-
}
|
|
178
|
-
if (knowledgeGapRequest && (result?.blocked || result?.completed)) {
|
|
179
|
-
throw new Error("knowledge gap result cannot also complete or generically block a step");
|
|
180
|
-
}
|
|
181
|
-
if (selfHelpRequest && (knowledgeGapRequest || result?.blocked || result?.completed)) {
|
|
182
|
-
throw new Error("self-help research cannot also complete, block, or open a knowledge gap");
|
|
183
|
-
}
|
|
184
|
-
const resultCheckpoint = boundGoal && result?.checkpoint !== undefined ? safeCheckpoint(result.checkpoint) : boundGoal?.checkpoint ?? null;
|
|
185
|
-
const premortemReview = boundStep?.premortemContractVersion === 1 && result?.completed
|
|
186
|
-
? await goalPremortem.reviewGoalPremortem({ root: paths.catalog.root, goal: boundGoal, step: boundStep,
|
|
187
|
-
item, checkpoint: resultCheckpoint, completedAt: current, host: runIdentity.binding.host, readOnly: result?.readOnly === true }) : null;
|
|
188
|
-
let executionReview = boundStep?.execution && result?.completed
|
|
189
|
-
? reviewExecutionResult(boundStep.execution, boundStep.executionOutcomes || [],
|
|
190
|
-
item.queueId, result.execution, current) : null;
|
|
191
|
-
if (executionReview && (boundStep.executionOutcomes || []).length >= 8) {
|
|
192
|
-
executionReview = { passed: false, outcome: null, reason: "Execution outcome history is full." };
|
|
193
|
-
}
|
|
194
|
-
const text = result?.text ? safeText(result.text, "result.text", 16000) : null;
|
|
195
|
-
if (result?.groupResponse !== undefined && !item.channelEventId) {
|
|
196
|
-
throw new Error("group response requires channel work");
|
|
197
|
-
}
|
|
198
|
-
let communication = null;
|
|
199
|
-
let clarification = null; let exploration = null; let selfHelp = null; let selfHelpRequired = null;
|
|
200
|
-
preserve(runtime, "queue", item, "run-completed", current);
|
|
201
|
-
if (item.channelEventId) {
|
|
202
|
-
const event = channelRuntime.runtime.events.find((entry) => entry.eventId === item.channelEventId);
|
|
203
|
-
if (!event) throw new Error("channel event disappeared before delivery preparation");
|
|
204
|
-
const binding = exactReplyBinding(channelPolicy.policy, event);
|
|
205
|
-
communication = reviewGroupResponse({ result, text, event, item, runtime, current });
|
|
206
|
-
if (communication?.suppressed) {
|
|
207
|
-
item.status = "completed"; item.completedAt = current;
|
|
208
|
-
} else {
|
|
209
|
-
if (!text) throw new Error("a channel obligation requires a non-empty response");
|
|
210
|
-
const voice = evaluateVoiceOutput(text);
|
|
211
|
-
if (!voice.ok) throw new Error("channel response contains a prohibited attachment or consciousness claim");
|
|
212
|
-
const idempotencyKey = "delivery:" + sha256([event.eventId, binding.id, event.chatId, event.threadId || "", event.replyTo || ""].join("\0")).slice(0, 32);
|
|
213
|
-
let outbox = runtime.outbox.find((entry) => entry.idempotencyKey === idempotencyKey);
|
|
214
|
-
if (!outbox) {
|
|
215
|
-
outbox = { outboxId: "gateway-outbox:" + sha256(idempotencyKey).slice(0, 32), queueId: item.queueId,
|
|
216
|
-
idempotencyKey, bindingId: binding.id, eventId: event.eventId, provider: event.provider, tenantId: event.tenantId,
|
|
217
|
-
accountId: event.accountId, chatId: event.chatId, threadId: event.threadId, replyTo: event.replyTo,
|
|
218
|
-
text, status: "prepared", attempts: 0, nextAttemptAt: current, createdAt: current, updatedAt: current,
|
|
219
|
-
deliveredAt: null, adapterReceipt: null, lastError: null, authority: "delivery-state-only" };
|
|
220
|
-
runtime.outbox.push(outbox);
|
|
221
|
-
}
|
|
222
|
-
item.status = "awaiting-delivery";
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
item.status = result?.blocked || knowledgeGapRequest || premortemReview?.blocked || (executionReview && !executionReview.passed)
|
|
226
|
-
? "blocked" : "completed"; item.completedAt = current;
|
|
227
|
-
const goal = boundGoal;
|
|
228
|
-
if (goal) {
|
|
229
|
-
policy.history.push({ kind: "goal", at: current, value: previousGoal, authority: "authenticated-goal-policy" });
|
|
230
|
-
const checkpoint = resultCheckpoint;
|
|
231
|
-
goal.checkpoint = checkpoint; goal.heartbeatAt = current;
|
|
232
|
-
goal.blocker = result?.blocked ? safeText(result.blocker || "Run blocked.", "blocker", 500)
|
|
233
|
-
: premortemReview?.blocked ? premortemReview.reason : executionReview && !executionReview.passed ? executionReview.reason : null;
|
|
234
|
-
if (goal.plan && item.goalStepId) {
|
|
235
|
-
const step = currentPlanStep(goal);
|
|
236
|
-
step.checkpoint = checkpoint; step.updatedAt = current;
|
|
237
|
-
const knowledge = handlePlanKnowledge({ goal, step, item, runtime, current,
|
|
238
|
-
selfHelpRequest, knowledgeGapRequest, appendReceipt, newGoalQueue, planQueueKey });
|
|
239
|
-
if (knowledge) ({ clarification = null, selfHelp = null, selfHelpRequired = null } = knowledge);
|
|
240
|
-
else if (result?.blocked || premortemReview?.blocked) {
|
|
241
|
-
step.status = "blocked"; step.blocker = goal.blocker; goal.status = "blocked";
|
|
242
|
-
} else if (executionReview && !executionReview.passed) {
|
|
243
|
-
if (executionReview.outcome) step.executionOutcomes.push(executionReview.outcome);
|
|
244
|
-
if (executionReview.outcome && executionReview.nextAttempt) {
|
|
245
|
-
item.status = "completed"; step.status = "active"; step.blocker = null;
|
|
246
|
-
goal.status = "active"; goal.blocker = null; goal.nextSafeStep = step.title;
|
|
247
|
-
goal.plan.revision += 1;
|
|
248
|
-
const key = planQueueKey(goal.goalId, step.stepId, "explore",
|
|
249
|
-
executionReview.outcome.digest.slice(0, 20));
|
|
250
|
-
let queued = runtime.queue.find((entry) => entry.dedupeKey === key);
|
|
251
|
-
if (!queued) {
|
|
252
|
-
queued = newGoalQueue(goal, step, "follow-up", key, current);
|
|
253
|
-
runtime.queue.push(queued);
|
|
254
|
-
}
|
|
255
|
-
exploration = { queueId: queued.queueId, ...executionReview.nextAttempt };
|
|
256
|
-
appendReceipt(runtime, "execution-exploration-continued", queued.queueId, current, {
|
|
257
|
-
goalStepId: step.stepId, failedOutcomeId: executionReview.outcome.outcomeId,
|
|
258
|
-
attempt: executionReview.nextAttempt.attempt,
|
|
259
|
-
strategyId: executionReview.nextAttempt.strategyId
|
|
260
|
-
});
|
|
261
|
-
} else {
|
|
262
|
-
step.status = "blocked"; step.blocker = goal.blocker; goal.status = "blocked";
|
|
263
|
-
appendReceipt(runtime, executionReview.outcome ? "execution-gate-failed" : "execution-proof-invalid",
|
|
264
|
-
item.queueId, current, { goalStepId: step.stepId,
|
|
265
|
-
outcomeId: executionReview.outcome?.outcomeId || null });
|
|
266
|
-
}
|
|
267
|
-
} else if (result?.completed) {
|
|
268
|
-
if (premortemReview?.attachments) Object.assign(step, premortemReview.attachments);
|
|
269
|
-
if (executionReview?.outcome) {
|
|
270
|
-
step.executionOutcomes.push(executionReview.outcome);
|
|
271
|
-
appendReceipt(runtime, "execution-gate-passed", item.queueId, current, {
|
|
272
|
-
goalStepId: step.stepId, outcomeId: executionReview.outcome.outcomeId
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
step.status = "completed"; step.completedAt = current; step.completedByQueueId = item.queueId; step.blocker = null;
|
|
276
|
-
goal.plan.currentStepId = null; goal.plan.revision += 1;
|
|
277
|
-
const next = activateNextPlanStep(goal.plan, current);
|
|
278
|
-
if (next) {
|
|
279
|
-
goal.status = "active"; goal.nextSafeStep = next.title; goal.blocker = null;
|
|
280
|
-
const key = planQueueKey(goal.goalId, next.stepId, "ready", String(goal.plan.revision));
|
|
281
|
-
if (!runtime.queue.some((entry) => entry.dedupeKey === key)) {
|
|
282
|
-
const queued = newGoalQueue(goal, next, "follow-up", key, current);
|
|
283
|
-
runtime.queue.push(queued);
|
|
284
|
-
appendReceipt(runtime, "goal-step-ready", queued.queueId, current, { goalStepId: next.stepId });
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
goal.status = "completed";
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
goal.status = "active"; step.blocker = null;
|
|
291
|
-
}
|
|
292
|
-
} else if (!goal.plan) {
|
|
293
|
-
goal.status = result?.completed ? "completed" : result?.blocked ? "blocked" : "active";
|
|
294
|
-
}
|
|
295
|
-
goal.updatedAt = current;
|
|
296
|
-
policy.revision += 1;
|
|
297
|
-
if (goal.status === "active" && (!goal.plan || !result?.completed) && !selfHelp && !selfHelpRequired) {
|
|
298
|
-
const checkpointDigest = sha256(JSON.stringify(goal.checkpoint || { heartbeatAt: current })).slice(0, 20);
|
|
299
|
-
const step = currentPlanStep(goal);
|
|
300
|
-
const key = step ? planQueueKey(goal.goalId, step.stepId, "follow-up", checkpointDigest)
|
|
301
|
-
: "goal:" + goal.goalId + ":follow-up:" + checkpointDigest;
|
|
302
|
-
if (!runtime.queue.some((entry) => entry.dedupeKey === key)) runtime.queue.push({
|
|
303
|
-
queueId: "gateway-queue:" + sha256(key).slice(0, 32), dedupeKey: key, kind: "follow-up",
|
|
304
|
-
agentId: planStepAgentId(goal, step), projectId: goal.projectId, groupId: goal.groupId, goalId: goal.goalId,
|
|
305
|
-
goalStepId: step?.stepId || null, channelEventId: null, priority: goal.priority, status: "pending", attempts: 0, lease: null,
|
|
306
|
-
availableAt: new Date(new Date(current).getTime() + 60000).toISOString(), createdAt: current, updatedAt: current,
|
|
307
|
-
completedAt: null, lastError: null, authority: "execution-state-only"
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
item.lease = null; item.updatedAt = current; lane.status = "completed"; lane.updatedAt = current;
|
|
313
|
-
const hostSettlement = settleHostExecution(runtime, item, hostProof, current, appendReceipt);
|
|
314
|
-
if (markedHostRun) runtime.health.host = "healthy";
|
|
315
|
-
runtime.health.worker = "healthy"; runtime.health.lastTickAt = current;
|
|
316
|
-
appendReceipt(runtime, "run-terminal", item.queueId, current, { status: item.status, goalStepId: item.goalStepId || null }); runtime.revision += 1;
|
|
317
|
-
await writeGatewayStatePair(policy, runtime);
|
|
318
|
-
return { item, outbox: runtime.outbox.find((entry) => entry.queueId === item.queueId) || null,
|
|
319
|
-
clarification, exploration, selfHelp, selfHelpRequired, executionReview, premortemReview, communication, hostSettlement };
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export async function failGatewayRun({ root = process.cwd(), queueId, workerId, claimedAt, attempt, error, retryAfterMs = 5000,
|
|
324
|
-
now = new Date() }) {
|
|
325
|
-
const paths = await pathsFor(root);
|
|
326
|
-
return withLock(paths, async () => {
|
|
327
|
-
const [policy, runtime] = await Promise.all([
|
|
328
|
-
readJson(paths.gatewayPolicyPath, paths.catalog.root, normalizePolicy, emptyPolicy),
|
|
329
|
-
readJson(paths.gatewayRuntimePath, paths.catalog.root, normalizeRuntime, emptyRuntime)
|
|
330
|
-
]);
|
|
331
|
-
const item = runtime.queue.find((entry) => entry.queueId === exactId(queueId, "queueId"));
|
|
332
|
-
workerId = exactId(workerId, "workerId"); claimedAt = exactGatewayLeaseGeneration(claimedAt, attempt, "run failure");
|
|
333
|
-
const current = timestamp(now);
|
|
334
|
-
const lane = requireExactGatewayLease(runtime, item,
|
|
335
|
-
{ workerId, claimedAt, attempt, current, action: "run failure", allowHeld: true });
|
|
336
|
-
const message = safeText(String(error || "host runtime unavailable"), "runError", 500);
|
|
337
|
-
const delay = Number(retryAfterMs);
|
|
338
|
-
if (!Number.isFinite(delay) || delay < 250 || delay > 300000) throw new Error("retryAfterMs must be 250-300000");
|
|
339
|
-
const failure = failGatewayLane(policy, runtime, item, lane, current,
|
|
340
|
-
{ error: message, retryAfterMs: delay, preserve, appendReceipt });
|
|
341
|
-
if (failure.ambiguous) await writeGatewayStatePair(policy, runtime);
|
|
342
|
-
else await writeJson(paths.gatewayRuntimePath, runtime);
|
|
343
|
-
return { item, receipt: failure.receipt, policyEnabled: policy.enabled && !policy.killSwitch };
|
|
344
|
-
});
|
|
345
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { personaRuntimeFindings } from "./persona-runtime.js";
|
|
2
|
-
|
|
3
|
-
export function currentLane(runtime, agentId) {
|
|
4
|
-
return runtime.lanes.find((item) => item.agentId === agentId && item.status === "leased") || null;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function assertActivePersona(personaPolicy, personaRuntime, agentId, projectId, groupId) {
|
|
8
|
-
const findings = personaRuntimeFindings(personaPolicy, personaRuntime);
|
|
9
|
-
if (findings.length) throw new Error("persona runtime is unhealthy: " + findings.join(", "));
|
|
10
|
-
const persona = personaRuntime.personas.find((item) => item.personaId === agentId && item.status === "active");
|
|
11
|
-
if (!persona || !["agent", "bot"].includes(persona.kind)) {
|
|
12
|
-
throw new Error("gateway work requires an active authenticated agent or bot");
|
|
13
|
-
}
|
|
14
|
-
if (groupId !== null && persona.groupId !== groupId) {
|
|
15
|
-
throw new Error("gateway work group does not match authenticated persona membership");
|
|
16
|
-
}
|
|
17
|
-
const binding = personaPolicy.bindings.find((item) => item.id === persona.bindingId && item.active);
|
|
18
|
-
if (!binding || !binding.tenantId || !binding.profileId || !projectId) {
|
|
19
|
-
throw new Error("gateway work lacks an active authenticated identity binding");
|
|
20
|
-
}
|
|
21
|
-
return { persona, binding };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function exactReplyBinding(channelPolicy, event) {
|
|
25
|
-
const binding = channelPolicy.bindings.find((item) => item.id === event.bindingId && item.status === "active"
|
|
26
|
-
&& item.agentId === event.agentId && item.projectId === event.projectId && item.groupId === event.groupId
|
|
27
|
-
&& item.provider === event.provider && item.tenantId === event.tenantId && item.accountId === event.accountId
|
|
28
|
-
&& item.chatId === event.chatId && item.threadId === event.threadId && item.capabilities.includes("reply"));
|
|
29
|
-
if (!binding) throw new Error("current exact channel reply capability is unavailable");
|
|
30
|
-
return binding;
|
|
31
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
function sha256(value) {
|
|
4
|
-
return createHash("sha256").update(value).digest("hex");
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function appendReceipt(runtime, kind, objectId, now, details = {}) {
|
|
8
|
-
const material = { kind, objectId, at: now, details, authority: "execution-state-only" };
|
|
9
|
-
const digest = sha256(JSON.stringify(material));
|
|
10
|
-
const id = "gateway-receipt:" + digest.slice(0, 24);
|
|
11
|
-
const previous = runtime.receipts.find((item) => item.id === id);
|
|
12
|
-
if (previous) return previous;
|
|
13
|
-
const receipt = { id, ...material, digest };
|
|
14
|
-
runtime.receipts.push(receipt);
|
|
15
|
-
return receipt;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function preserve(runtime, kind, value, transition, now) {
|
|
19
|
-
runtime.history.push({ kind, objectId: kind === "outbox" ? value.outboxId : value.queueId, transition, at: now,
|
|
20
|
-
value: structuredClone(value), authority: "execution-state-only" });
|
|
21
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
EXECUTION_ATTEMPT_SCHEMA, EXECUTION_OUTCOME_SCHEMA, GATEWAY_EVENT_SCHEMA,
|
|
3
|
-
GATEWAY_POLICY_SCHEMA, GATEWAY_RUNTIME_SCHEMA, GOAL_PLAN_SCHEMA,
|
|
4
|
-
KNOWLEDGE_GAP_SCHEMA, STRATEGY_TRANSFER_PROOF_SCHEMA
|
|
5
|
-
} from "./gateway-common.js";
|
|
6
|
-
export { executionAttemptForStep } from "./gateway-execution.js";
|
|
7
|
-
export {
|
|
8
|
-
assignGoal, enqueueGatewayWake, reconcileGateway, resolveGoalKnowledgeGap,
|
|
9
|
-
reviewLegacyGatewayHold, setGatewayControl
|
|
10
|
-
} from "./gateway-control.js";
|
|
11
|
-
export {
|
|
12
|
-
claimGatewayWork, completeGatewayRun, failGatewayRun, markGatewayHostStarted
|
|
13
|
-
} from "./gateway-runs.js";
|
|
14
|
-
export { deliverPrepared, updateGatewayHealth } from "./gateway-delivery.js";
|
|
15
|
-
export {
|
|
16
|
-
gatewayContext, gatewayHealthFindings, gatewayRuntimeFindings,
|
|
17
|
-
inspectGatewayRuntime, loadGatewayRuntime
|
|
18
|
-
} from "./gateway-inspection.js";
|