@scotthuang/agent-knock-knock 0.12.11 → 0.12.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +43 -30
- package/dist/src/approval-policy.d.ts +11 -2
- package/dist/src/approval-policy.js +33 -7
- package/dist/src/approval-policy.js.map +1 -1
- package/dist/src/callback-cli-adapter.d.ts +47 -0
- package/dist/src/callback-cli-adapter.js +156 -0
- package/dist/src/callback-cli-adapter.js.map +1 -0
- package/dist/src/callback-outbox-policy.d.ts +95 -0
- package/dist/src/callback-outbox-policy.js +149 -0
- package/dist/src/callback-outbox-policy.js.map +1 -0
- package/dist/src/callback-outbox-service.d.ts +247 -0
- package/dist/src/callback-outbox-service.js +1053 -0
- package/dist/src/callback-outbox-service.js.map +1 -0
- package/dist/src/callback-outbox-settlement.d.ts +54 -0
- package/dist/src/callback-outbox-settlement.js +241 -0
- package/dist/src/callback-outbox-settlement.js.map +1 -0
- package/dist/src/canonical-json.d.ts +1 -0
- package/dist/src/canonical-json.js +14 -0
- package/dist/src/canonical-json.js.map +1 -0
- package/dist/src/claude-lifecycle-compatibility.js +15 -0
- package/dist/src/claude-lifecycle-compatibility.js.map +1 -1
- package/dist/src/claude-local-transcript-provider.d.ts +82 -1
- package/dist/src/claude-local-transcript-provider.js +873 -23
- package/dist/src/claude-local-transcript-provider.js.map +1 -1
- package/dist/src/cli-command-runtime.d.ts +14 -0
- package/dist/src/cli-command-runtime.js +164 -0
- package/dist/src/cli-command-runtime.js.map +1 -0
- package/dist/src/cli-core.d.ts +4 -42
- package/dist/src/cli-core.js +958 -28684
- package/dist/src/cli-core.js.map +1 -1
- package/dist/src/cli-runtime-context.d.ts +57 -0
- package/dist/src/cli-runtime-context.js +118 -0
- package/dist/src/cli-runtime-context.js.map +1 -0
- package/dist/src/codex-lifecycle-compatibility.js +2 -1
- package/dist/src/codex-lifecycle-compatibility.js.map +1 -1
- package/dist/src/codex-local-session-provider.d.ts +18 -0
- package/dist/src/codex-local-session-provider.js +67 -0
- package/dist/src/codex-local-session-provider.js.map +1 -1
- package/dist/src/codex-session-provider.js +1 -3
- package/dist/src/codex-session-provider.js.map +1 -1
- package/dist/src/conversation-trace.d.ts +30 -0
- package/dist/src/conversation-trace.js +185 -0
- package/dist/src/conversation-trace.js.map +1 -0
- package/dist/src/deferred-foreground-application-service.d.ts +84 -0
- package/dist/src/deferred-foreground-application-service.js +742 -0
- package/dist/src/deferred-foreground-application-service.js.map +1 -0
- package/dist/src/deferred-foreground-authority-cli-adapter.d.ts +78 -0
- package/dist/src/deferred-foreground-authority-cli-adapter.js +795 -0
- package/dist/src/deferred-foreground-authority-cli-adapter.js.map +1 -0
- package/dist/src/deferred-foreground-boundary.d.ts +61 -0
- package/dist/src/deferred-foreground-boundary.js +2 -0
- package/dist/src/deferred-foreground-boundary.js.map +1 -0
- package/dist/src/deferred-foreground-capability.d.ts +4 -0
- package/dist/src/deferred-foreground-capability.js +184 -0
- package/dist/src/deferred-foreground-capability.js.map +1 -0
- package/dist/src/deferred-foreground-preparation-cli-adapter.d.ts +53 -0
- package/dist/src/deferred-foreground-preparation-cli-adapter.js +210 -0
- package/dist/src/deferred-foreground-preparation-cli-adapter.js.map +1 -0
- package/dist/src/deferred-foreground-preparation-service.d.ts +72 -0
- package/dist/src/deferred-foreground-preparation-service.js +179 -0
- package/dist/src/deferred-foreground-preparation-service.js.map +1 -0
- package/dist/src/deferred-foreground-recovery-cli-adapter.d.ts +139 -0
- package/dist/src/deferred-foreground-recovery-cli-adapter.js +1125 -0
- package/dist/src/deferred-foreground-recovery-cli-adapter.js.map +1 -0
- package/dist/src/deferred-foreground-recovery-service.d.ts +48 -0
- package/dist/src/deferred-foreground-recovery-service.js +91 -0
- package/dist/src/deferred-foreground-recovery-service.js.map +1 -0
- package/dist/src/deferred-foreground-transfer-policy.d.ts +2 -0
- package/dist/src/deferred-foreground-transfer-policy.js +10 -0
- package/dist/src/deferred-foreground-transfer-policy.js.map +1 -0
- package/dist/src/deferred-foreground-transfer.js +46 -105
- package/dist/src/deferred-foreground-transfer.js.map +1 -1
- package/dist/src/doctor-capabilities.d.ts +9 -0
- package/dist/src/doctor-capabilities.js +22 -0
- package/dist/src/doctor-capabilities.js.map +1 -1
- package/dist/src/durable-json-file.d.ts +22 -0
- package/dist/src/durable-json-file.js +127 -0
- package/dist/src/durable-json-file.js.map +1 -0
- package/dist/src/file-lock-cli-adapter.d.ts +43 -0
- package/dist/src/file-lock-cli-adapter.js +150 -0
- package/dist/src/file-lock-cli-adapter.js.map +1 -0
- package/dist/src/herdr-terminal-control-provider.js +1 -3
- package/dist/src/herdr-terminal-control-provider.js.map +1 -1
- package/dist/src/install-doctor-command-adapter.d.ts +17 -0
- package/dist/src/install-doctor-command-adapter.js +225 -0
- package/dist/src/install-doctor-command-adapter.js.map +1 -0
- package/dist/src/live-lifecycle-evidence.js +76 -46
- package/dist/src/live-lifecycle-evidence.js.map +1 -1
- package/dist/src/live-lifecycle-smoke.js +74 -50
- package/dist/src/live-lifecycle-smoke.js.map +1 -1
- package/dist/src/managed-session.d.ts +2 -0
- package/dist/src/managed-session.js +24 -0
- package/dist/src/managed-session.js.map +1 -1
- package/dist/src/managed-turn-recovery-service.d.ts +86 -0
- package/dist/src/managed-turn-recovery-service.js +145 -0
- package/dist/src/managed-turn-recovery-service.js.map +1 -0
- package/dist/src/mutation-transaction.d.ts +48 -0
- package/dist/src/mutation-transaction.js +73 -0
- package/dist/src/mutation-transaction.js.map +1 -0
- package/dist/src/native-thread-lifecycle-cli-adapter.d.ts +154 -0
- package/dist/src/native-thread-lifecycle-cli-adapter.js +786 -0
- package/dist/src/native-thread-lifecycle-cli-adapter.js.map +1 -0
- package/dist/src/native-thread-lifecycle-ledger-cli-adapter.d.ts +25 -0
- package/dist/src/native-thread-lifecycle-ledger-cli-adapter.js +50 -0
- package/dist/src/native-thread-lifecycle-ledger-cli-adapter.js.map +1 -0
- package/dist/src/native-thread-lifecycle-query-service.d.ts +75 -0
- package/dist/src/native-thread-lifecycle-query-service.js +297 -0
- package/dist/src/native-thread-lifecycle-query-service.js.map +1 -0
- package/dist/src/native-thread-lifecycle-recovery-adapter.d.ts +45 -0
- package/dist/src/native-thread-lifecycle-recovery-adapter.js +154 -0
- package/dist/src/native-thread-lifecycle-recovery-adapter.js.map +1 -0
- package/dist/src/native-thread-lifecycle-recovery-service.d.ts +211 -0
- package/dist/src/native-thread-lifecycle-recovery-service.js +1093 -0
- package/dist/src/native-thread-lifecycle-recovery-service.js.map +1 -0
- package/dist/src/native-thread-resume-snapshot-policy.d.ts +73 -0
- package/dist/src/native-thread-resume-snapshot-policy.js +218 -0
- package/dist/src/native-thread-resume-snapshot-policy.js.map +1 -0
- package/dist/src/native-thread-resume-snapshot.d.ts +3 -61
- package/dist/src/native-thread-resume-snapshot.js +2 -143
- package/dist/src/native-thread-resume-snapshot.js.map +1 -1
- package/dist/src/native-thread-transition-application.d.ts +147 -0
- package/dist/src/native-thread-transition-application.js +974 -0
- package/dist/src/native-thread-transition-application.js.map +1 -0
- package/dist/src/native-thread-transition-policy.d.ts +127 -0
- package/dist/src/native-thread-transition-policy.js +154 -0
- package/dist/src/native-thread-transition-policy.js.map +1 -0
- package/dist/src/native-thread-transition-resource-adapter.d.ts +12 -0
- package/dist/src/native-thread-transition-resource-adapter.js +44 -0
- package/dist/src/native-thread-transition-resource-adapter.js.map +1 -0
- package/dist/src/native-thread-transition-settlement-service.d.ts +94 -0
- package/dist/src/native-thread-transition-settlement-service.js +134 -0
- package/dist/src/native-thread-transition-settlement-service.js.map +1 -0
- package/dist/src/native-thread-transition-verification-adapter.d.ts +62 -0
- package/dist/src/native-thread-transition-verification-adapter.js +451 -0
- package/dist/src/native-thread-transition-verification-adapter.js.map +1 -0
- package/dist/src/openclaw-callback-transport.d.ts +69 -0
- package/dist/src/openclaw-callback-transport.js +583 -0
- package/dist/src/openclaw-callback-transport.js.map +1 -0
- package/dist/src/openclaw-plugin-callback-adapter.d.ts +1 -0
- package/dist/src/openclaw-plugin-callback-adapter.js +423 -0
- package/dist/src/openclaw-plugin-callback-adapter.js.map +1 -0
- package/dist/src/openclaw-plugin-command-adapter.d.ts +16 -0
- package/dist/src/openclaw-plugin-command-adapter.js +1868 -0
- package/dist/src/openclaw-plugin-command-adapter.js.map +1 -0
- package/dist/src/openclaw-plugin-helpers.d.ts +27 -4
- package/dist/src/openclaw-plugin-helpers.js +356 -81
- package/dist/src/openclaw-plugin-helpers.js.map +1 -1
- package/dist/src/openclaw-plugin-schemas.d.ts +358 -0
- package/dist/src/openclaw-plugin-schemas.js +366 -0
- package/dist/src/openclaw-plugin-schemas.js.map +1 -0
- package/dist/src/openclaw-plugin-supervisor.d.ts +6 -0
- package/dist/src/openclaw-plugin-supervisor.js +123 -0
- package/dist/src/openclaw-plugin-supervisor.js.map +1 -0
- package/dist/src/openclaw-plugin.js +7 -2212
- package/dist/src/openclaw-plugin.js.map +1 -1
- package/dist/src/openclaw-private-authority-offers.d.ts +22 -0
- package/dist/src/openclaw-private-authority-offers.js +177 -0
- package/dist/src/openclaw-private-authority-offers.js.map +1 -0
- package/dist/src/protocol.d.ts +5 -0
- package/dist/src/protocol.js +59 -3
- package/dist/src/protocol.js.map +1 -1
- package/dist/src/session-store.d.ts +1 -0
- package/dist/src/session-store.js +84 -106
- package/dist/src/session-store.js.map +1 -1
- package/dist/src/store.d.ts +1 -0
- package/dist/src/store.js +5 -2
- package/dist/src/store.js.map +1 -1
- package/dist/src/terminal-acceptance-application-service.d.ts +65 -0
- package/dist/src/terminal-acceptance-application-service.js +63 -0
- package/dist/src/terminal-acceptance-application-service.js.map +1 -0
- package/dist/src/terminal-acceptance-cli-adapter.d.ts +210 -0
- package/dist/src/terminal-acceptance-cli-adapter.js +957 -0
- package/dist/src/terminal-acceptance-cli-adapter.js.map +1 -0
- package/dist/src/terminal-action-projection.d.ts +309 -0
- package/dist/src/terminal-action-projection.js +376 -0
- package/dist/src/terminal-action-projection.js.map +1 -0
- package/dist/src/terminal-agent-bridge.d.ts +3 -0
- package/dist/src/terminal-agent-bridge.js +29 -8
- package/dist/src/terminal-agent-bridge.js.map +1 -1
- package/dist/src/terminal-authority-policy.d.ts +141 -0
- package/dist/src/terminal-authority-policy.js +367 -0
- package/dist/src/terminal-authority-policy.js.map +1 -0
- package/dist/src/terminal-binding-authority.d.ts +118 -0
- package/dist/src/terminal-binding-authority.js +245 -0
- package/dist/src/terminal-binding-authority.js.map +1 -0
- package/dist/src/terminal-binding-reconciliation-service.d.ts +75 -0
- package/dist/src/terminal-binding-reconciliation-service.js +73 -0
- package/dist/src/terminal-binding-reconciliation-service.js.map +1 -0
- package/dist/src/terminal-command-cli-adapter.d.ts +380 -0
- package/dist/src/terminal-command-cli-adapter.js +3288 -0
- package/dist/src/terminal-command-cli-adapter.js.map +1 -0
- package/dist/src/terminal-control-ref.d.ts +4 -0
- package/dist/src/terminal-control-ref.js +11 -8
- package/dist/src/terminal-control-ref.js.map +1 -1
- package/dist/src/terminal-delegate-cli-adapter.d.ts +41 -0
- package/dist/src/terminal-delegate-cli-adapter.js +242 -0
- package/dist/src/terminal-delegate-cli-adapter.js.map +1 -0
- package/dist/src/terminal-dispatch-abort.d.ts +22 -0
- package/dist/src/terminal-dispatch-abort.js +30 -0
- package/dist/src/terminal-dispatch-abort.js.map +1 -0
- package/dist/src/terminal-dispatch-application.d.ts +115 -0
- package/dist/src/terminal-dispatch-application.js +478 -0
- package/dist/src/terminal-dispatch-application.js.map +1 -0
- package/dist/src/terminal-dispatch-capability.d.ts +63 -0
- package/dist/src/terminal-dispatch-capability.js +133 -0
- package/dist/src/terminal-dispatch-capability.js.map +1 -0
- package/dist/src/terminal-dispatch-completion-cli-adapter.d.ts +22 -0
- package/dist/src/terminal-dispatch-completion-cli-adapter.js +96 -0
- package/dist/src/terminal-dispatch-completion-cli-adapter.js.map +1 -0
- package/dist/src/terminal-dispatch-composition.d.ts +79 -0
- package/dist/src/terminal-dispatch-composition.js +2 -0
- package/dist/src/terminal-dispatch-composition.js.map +1 -0
- package/dist/src/terminal-dispatch-execution.d.ts +290 -0
- package/dist/src/terminal-dispatch-execution.js +916 -0
- package/dist/src/terminal-dispatch-execution.js.map +1 -0
- package/dist/src/terminal-dispatch-ledger-codec.d.ts +110 -0
- package/dist/src/terminal-dispatch-ledger-codec.js +399 -0
- package/dist/src/terminal-dispatch-ledger-codec.js.map +1 -0
- package/dist/src/terminal-dispatch-policy.d.ts +93 -0
- package/dist/src/terminal-dispatch-policy.js +122 -0
- package/dist/src/terminal-dispatch-policy.js.map +1 -0
- package/dist/src/terminal-dispatch-presenter.d.ts +65 -0
- package/dist/src/terminal-dispatch-presenter.js +258 -0
- package/dist/src/terminal-dispatch-presenter.js.map +1 -0
- package/dist/src/terminal-dispatch-receipt.d.ts +79 -0
- package/dist/src/terminal-dispatch-receipt.js +314 -0
- package/dist/src/terminal-dispatch-receipt.js.map +1 -0
- package/dist/src/terminal-dispatch-recovery-cli-adapter.d.ts +132 -0
- package/dist/src/terminal-dispatch-recovery-cli-adapter.js +1330 -0
- package/dist/src/terminal-dispatch-recovery-cli-adapter.js.map +1 -0
- package/dist/src/terminal-dispatch-recovery-service.d.ts +271 -0
- package/dist/src/terminal-dispatch-recovery-service.js +374 -0
- package/dist/src/terminal-dispatch-recovery-service.js.map +1 -0
- package/dist/src/terminal-dispatch-repository-cli-adapter.d.ts +35 -0
- package/dist/src/terminal-dispatch-repository-cli-adapter.js +483 -0
- package/dist/src/terminal-dispatch-repository-cli-adapter.js.map +1 -0
- package/dist/src/terminal-handoff-application-service.d.ts +7 -0
- package/dist/src/terminal-handoff-application-service.js +18 -0
- package/dist/src/terminal-handoff-application-service.js.map +1 -0
- package/dist/src/terminal-handoff-cli-adapter.d.ts +229 -0
- package/dist/src/terminal-handoff-cli-adapter.js +1389 -0
- package/dist/src/terminal-handoff-cli-adapter.js.map +1 -0
- package/dist/src/terminal-handoff-facts.d.ts +12 -0
- package/dist/src/terminal-handoff-facts.js +16 -0
- package/dist/src/terminal-handoff-facts.js.map +1 -0
- package/dist/src/terminal-identity-authority-cli-adapter.d.ts +318 -0
- package/dist/src/terminal-identity-authority-cli-adapter.js +1072 -0
- package/dist/src/terminal-identity-authority-cli-adapter.js.map +1 -0
- package/dist/src/terminal-identity-authority-service.d.ts +48 -0
- package/dist/src/terminal-identity-authority-service.js +45 -0
- package/dist/src/terminal-identity-authority-service.js.map +1 -0
- package/dist/src/terminal-list-cli-adapter.d.ts +274 -0
- package/dist/src/terminal-list-cli-adapter.js +2444 -0
- package/dist/src/terminal-list-cli-adapter.js.map +1 -0
- package/dist/src/terminal-list-renderer.d.ts +34 -0
- package/dist/src/terminal-list-renderer.js +643 -0
- package/dist/src/terminal-list-renderer.js.map +1 -0
- package/dist/src/terminal-maintenance-cli-adapter.d.ts +102 -0
- package/dist/src/terminal-maintenance-cli-adapter.js +1059 -0
- package/dist/src/terminal-maintenance-cli-adapter.js.map +1 -0
- package/dist/src/terminal-monitor-application-service.d.ts +275 -0
- package/dist/src/terminal-monitor-application-service.js +982 -0
- package/dist/src/terminal-monitor-application-service.js.map +1 -0
- package/dist/src/terminal-monitor-cli-adapter.d.ts +130 -0
- package/dist/src/terminal-monitor-cli-adapter.js +442 -0
- package/dist/src/terminal-monitor-cli-adapter.js.map +1 -0
- package/dist/src/terminal-monitor-decision-policy.d.ts +98 -0
- package/dist/src/terminal-monitor-decision-policy.js +246 -0
- package/dist/src/terminal-monitor-decision-policy.js.map +1 -0
- package/dist/src/terminal-monitor-launch-plan.d.ts +45 -0
- package/dist/src/terminal-monitor-launch-plan.js +94 -0
- package/dist/src/terminal-monitor-launch-plan.js.map +1 -0
- package/dist/src/terminal-monitor-ownership-policy.d.ts +31 -0
- package/dist/src/terminal-monitor-ownership-policy.js +64 -0
- package/dist/src/terminal-monitor-ownership-policy.js.map +1 -0
- package/dist/src/terminal-monitor-poll-policy.d.ts +48 -0
- package/dist/src/terminal-monitor-poll-policy.js +67 -0
- package/dist/src/terminal-monitor-poll-policy.js.map +1 -0
- package/dist/src/terminal-monitor-reconciliation-eligibility.d.ts +53 -0
- package/dist/src/terminal-monitor-reconciliation-eligibility.js +114 -0
- package/dist/src/terminal-monitor-reconciliation-eligibility.js.map +1 -0
- package/dist/src/terminal-monitor-state-cli-adapter.d.ts +106 -0
- package/dist/src/terminal-monitor-state-cli-adapter.js +1492 -0
- package/dist/src/terminal-monitor-state-cli-adapter.js.map +1 -0
- package/dist/src/terminal-monitor-state-reconciliation-service.d.ts +87 -0
- package/dist/src/terminal-monitor-state-reconciliation-service.js +106 -0
- package/dist/src/terminal-monitor-state-reconciliation-service.js.map +1 -0
- package/dist/src/terminal-monitor-supervision-cli-adapter.d.ts +122 -0
- package/dist/src/terminal-monitor-supervision-cli-adapter.js +685 -0
- package/dist/src/terminal-monitor-supervision-cli-adapter.js.map +1 -0
- package/dist/src/terminal-process-facts.d.ts +2 -0
- package/dist/src/terminal-process-facts.js +19 -0
- package/dist/src/terminal-process-facts.js.map +1 -0
- package/dist/src/terminal-process-source.d.ts +6 -4
- package/dist/src/terminal-process-source.js +25 -20
- package/dist/src/terminal-process-source.js.map +1 -1
- package/dist/src/terminal-runtime-cli-adapter.d.ts +80 -0
- package/dist/src/terminal-runtime-cli-adapter.js +488 -0
- package/dist/src/terminal-runtime-cli-adapter.js.map +1 -0
- package/dist/src/terminal-scoped-approval-authority.d.ts +62 -0
- package/dist/src/terminal-scoped-approval-authority.js +281 -0
- package/dist/src/terminal-scoped-approval-authority.js.map +1 -0
- package/dist/src/terminal-selector-projection-service.d.ts +26 -0
- package/dist/src/terminal-selector-projection-service.js +81 -0
- package/dist/src/terminal-selector-projection-service.js.map +1 -0
- package/dist/src/terminal-status-cli-adapter.d.ts +126 -0
- package/dist/src/terminal-status-cli-adapter.js +577 -0
- package/dist/src/terminal-status-cli-adapter.js.map +1 -0
- package/dist/src/terminal-status-facts.d.ts +56 -0
- package/dist/src/terminal-status-facts.js +199 -0
- package/dist/src/terminal-status-facts.js.map +1 -0
- package/dist/src/terminal-submission-acceptance.d.ts +62 -145
- package/dist/src/terminal-submission-acceptance.js +555 -222
- package/dist/src/terminal-submission-acceptance.js.map +1 -1
- package/dist/src/terminal-submission-facts.d.ts +123 -0
- package/dist/src/terminal-submission-facts.js +205 -0
- package/dist/src/terminal-submission-facts.js.map +1 -0
- package/dist/src/terminal-turn-binding-authority-cli-adapter.d.ts +14 -0
- package/dist/src/terminal-turn-binding-authority-cli-adapter.js +90 -0
- package/dist/src/terminal-turn-binding-authority-cli-adapter.js.map +1 -0
- package/dist/src/terminal-watch-callback-cli-adapter.d.ts +20 -0
- package/dist/src/terminal-watch-callback-cli-adapter.js +55 -0
- package/dist/src/terminal-watch-callback-cli-adapter.js.map +1 -0
- package/dist/src/terminal-watch-cli-adapter.d.ts +64 -0
- package/dist/src/terminal-watch-cli-adapter.js +508 -0
- package/dist/src/terminal-watch-cli-adapter.js.map +1 -0
- package/dist/src/terminal-watch-service.d.ts +97 -0
- package/dist/src/terminal-watch-service.js +714 -0
- package/dist/src/terminal-watch-service.js.map +1 -0
- package/dist/src/terminal-watch-store.d.ts +149 -0
- package/dist/src/terminal-watch-store.js +861 -0
- package/dist/src/terminal-watch-store.js.map +1 -0
- package/dist/src/value-guards.d.ts +4 -0
- package/dist/src/value-guards.js +12 -0
- package/dist/src/value-guards.js.map +1 -0
- package/dist/src/verified-dead-agent-policy.d.ts +192 -0
- package/dist/src/verified-dead-agent-policy.js +262 -0
- package/dist/src/verified-dead-agent-policy.js.map +1 -0
- package/docs/quickstart-herdr.md +8 -0
- package/docs/quickstart-tmux.md +33 -6
- package/openclaw.plugin.json +11 -3
- package/package.json +3 -1
- package/templates/openclaw-skills/agent-knock-knock/SKILL.md +58 -40
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import { isExactNativeThreadId, managedSessionRevision, managedSessionBindingToken, terminalBindingFrom } from "./managed-session.js";
|
|
2
|
+
import { exactRolloutMatches } from "./terminal-binding-authority.js";
|
|
3
|
+
import { isCompleteNativeRollout, terminalControlsShareIncarnation } from "./terminal-authority-policy.js";
|
|
4
|
+
export function deferredForegroundTransferRevision(transfer) {
|
|
5
|
+
const revision = Number(transfer.revision);
|
|
6
|
+
if (!Number.isSafeInteger(revision) || revision < 1) {
|
|
7
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} has no valid revision`);
|
|
8
|
+
}
|
|
9
|
+
return revision;
|
|
10
|
+
}
|
|
11
|
+
export class DeferredForegroundApplicationService {
|
|
12
|
+
#ports;
|
|
13
|
+
constructor(ports) {
|
|
14
|
+
this.#ports = ports;
|
|
15
|
+
}
|
|
16
|
+
assertTransferAuthority(scope, transfer, boundary) {
|
|
17
|
+
scope.assertBoundary(boundary);
|
|
18
|
+
const same = transfer.transfer_id === boundary.transferId &&
|
|
19
|
+
transfer.source_session_id === boundary.sourceSessionId &&
|
|
20
|
+
transfer.target_session_id === boundary.targetSessionId &&
|
|
21
|
+
transfer.source_expected_revision === boundary.sourceBoundRevision &&
|
|
22
|
+
transfer.source_binding_token === boundary.sourceBoundBindingToken &&
|
|
23
|
+
transfer.previous_dispatch_status ===
|
|
24
|
+
boundary.previousDispatchSnapshot.status &&
|
|
25
|
+
transfer.previous_dispatch_fingerprint ===
|
|
26
|
+
boundary.previousDispatchSnapshot.fingerprint &&
|
|
27
|
+
(transfer.version === 1 ? "status_card_only" : transfer.source_kind) ===
|
|
28
|
+
boundary.sourceKind &&
|
|
29
|
+
(transfer.source_rollout_authority ?? "present") ===
|
|
30
|
+
boundary.sourceRolloutAuthority &&
|
|
31
|
+
transfer.source_abandonment_fingerprint ===
|
|
32
|
+
boundary.sourceAbandonmentFingerprint &&
|
|
33
|
+
this.#ports.authority.valuesMatch(transfer.source_turn_history, boundary.sourceTurnHistory) &&
|
|
34
|
+
transfer.source_previous_last_transition_id ===
|
|
35
|
+
boundary.sourcePreviousLastTransitionId &&
|
|
36
|
+
transfer.process_uuid === boundary.processUuid &&
|
|
37
|
+
transfer.process_birth === boundary.processBirth &&
|
|
38
|
+
scope.terminalMatches(transfer, boundary) &&
|
|
39
|
+
scope.transferBelongsToTurn(transfer);
|
|
40
|
+
if (!same) {
|
|
41
|
+
throw new Error(`deferred foreground transfer ${boundary.transferId} authority changed`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
abortBeforeInput(options) {
|
|
45
|
+
let transfer = options.scope.loadTransfer(options.boundary.transferId);
|
|
46
|
+
this.assertTransferAuthority(options.scope, transfer, options.boundary);
|
|
47
|
+
if (transfer.status === "abort_resolved")
|
|
48
|
+
return;
|
|
49
|
+
const zeroInput = provedDispatchDidNotStart(transfer, options.terminalInputNotStartedAt);
|
|
50
|
+
assertCanAbort(transfer, zeroInput);
|
|
51
|
+
if (transfer.status !== "aborted") {
|
|
52
|
+
transfer = options.scope.saveTransfer({
|
|
53
|
+
...transfer,
|
|
54
|
+
status: "aborted",
|
|
55
|
+
aborted_at: this.#ports.clock.now().toISOString(),
|
|
56
|
+
...(zeroInput
|
|
57
|
+
? { terminal_input_not_started_at: options.terminalInputNotStartedAt }
|
|
58
|
+
: {}),
|
|
59
|
+
error: this.#ports.runtime.errorReceipt(options.reason)
|
|
60
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
61
|
+
}
|
|
62
|
+
transfer = this.finalizeAbort(options.scope, transfer);
|
|
63
|
+
this.#ports.runtime.log("info", "deferred_codex_foreground_transfer_aborted", {
|
|
64
|
+
transfer_id: transfer.transfer_id,
|
|
65
|
+
source_session_id: transfer.source_session_id,
|
|
66
|
+
target_session_id: transfer.target_session_id,
|
|
67
|
+
terminal_input_sent: false,
|
|
68
|
+
reason: this.#ports.runtime.summary(options.reason)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
finalizeAbort(scope, transfer) {
|
|
72
|
+
let current = scope.loadTransfer(transfer.transfer_id);
|
|
73
|
+
if (current.status === "abort_resolved")
|
|
74
|
+
return current;
|
|
75
|
+
assertZeroInputAbortIntent(current);
|
|
76
|
+
const target = this.#finalizeAbortedTarget(scope, current);
|
|
77
|
+
const source = this.#finalizeAbortedSource(scope, current);
|
|
78
|
+
const completedAt = this.#ports.clock.now().toISOString();
|
|
79
|
+
current = scope.saveTransfer({
|
|
80
|
+
...current,
|
|
81
|
+
status: "abort_resolved",
|
|
82
|
+
abort_cleanup_completed_at: completedAt,
|
|
83
|
+
abort_source_after_revision: managedSessionRevision(source),
|
|
84
|
+
abort_source_after_status: "bound",
|
|
85
|
+
abort_source_after_binding_token: managedSessionBindingToken(source),
|
|
86
|
+
abort_source_after_binding: source.binding,
|
|
87
|
+
abort_target_after_status: target ? "detached" : "absent",
|
|
88
|
+
...(target ? abortTargetReceipt(target) : {})
|
|
89
|
+
}, deferredForegroundTransferRevision(current));
|
|
90
|
+
return current;
|
|
91
|
+
}
|
|
92
|
+
async reserve(request) {
|
|
93
|
+
let transfer = request.scope.loadTransfer(request.boundary.transferId);
|
|
94
|
+
this.assertTransferAuthority(request.scope, transfer, request.boundary);
|
|
95
|
+
if (transfer.status !== "prepared" || transfer.input_stage !== "none") {
|
|
96
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} is already ` +
|
|
97
|
+
transfer.status);
|
|
98
|
+
}
|
|
99
|
+
const source = await this.#ports.authority.verifyReservedSource(request.scope, request.boundary);
|
|
100
|
+
try {
|
|
101
|
+
return this.#reserveAfterVerification(request, transfer, source);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.#abortFailedReservation(request, error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
begin(options) {
|
|
109
|
+
let transfer = options.scope.loadTransfer(options.boundary.transferId);
|
|
110
|
+
this.assertTransferAuthority(options.scope, transfer, options.boundary);
|
|
111
|
+
this.#assertPreparedTarget(options.scope, transfer);
|
|
112
|
+
if (transfer.status !== "target_prepared" || transfer.input_stage !== "none") {
|
|
113
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} cannot begin ` +
|
|
114
|
+
`dispatch from ${transfer.status}/${transfer.input_stage}`);
|
|
115
|
+
}
|
|
116
|
+
transfer = options.scope.saveTransfer({
|
|
117
|
+
...transfer,
|
|
118
|
+
status: "dispatch_started",
|
|
119
|
+
input_stage: "dispatch_started",
|
|
120
|
+
dispatch_started_at: options.at
|
|
121
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
122
|
+
return transfer;
|
|
123
|
+
}
|
|
124
|
+
advance(options) {
|
|
125
|
+
let transfer = options.scope.loadTransfer(options.boundary.transferId);
|
|
126
|
+
this.assertTransferAuthority(options.scope, transfer, options.boundary);
|
|
127
|
+
this.#assertPreparedTarget(options.scope, transfer);
|
|
128
|
+
this.#assertReservedSource(options.scope, transfer, options.boundary);
|
|
129
|
+
assertStageTransition(transfer, options.stage);
|
|
130
|
+
transfer = options.scope.saveTransfer({
|
|
131
|
+
...transfer,
|
|
132
|
+
status: "dispatch_started",
|
|
133
|
+
input_stage: options.stage,
|
|
134
|
+
dispatch_started_at: transfer.dispatch_started_at ?? options.at,
|
|
135
|
+
...(options.stage === "text_injected"
|
|
136
|
+
? { text_injected_at: options.at }
|
|
137
|
+
: { enter_dispatched_at: options.at })
|
|
138
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
139
|
+
return transfer;
|
|
140
|
+
}
|
|
141
|
+
async commit(request) {
|
|
142
|
+
let transfer = request.scope.loadTransfer(request.boundary.transferId);
|
|
143
|
+
this.assertTransferAuthority(request.scope, transfer, request.boundary);
|
|
144
|
+
this.#ports.authority.assertFrozenPredecessor(request.scope, request.boundary, transfer);
|
|
145
|
+
assertAcceptedIdentityAuthority(transfer, request.identity);
|
|
146
|
+
let source = request.scope.loadSession(transfer.source_session_id);
|
|
147
|
+
const sameNativeThread = request.identity.sessionId.toLowerCase() ===
|
|
148
|
+
transfer.source_before_binding.native_thread_id?.toLowerCase();
|
|
149
|
+
const sourceAlreadyScrubbed = sameNativeThread &&
|
|
150
|
+
this.#isExactScrubbedSource(source, transfer);
|
|
151
|
+
this.#assertCommittableSource(source, transfer, request.boundary, sourceAlreadyScrubbed);
|
|
152
|
+
let target = request.scope.loadSession(transfer.target_session_id);
|
|
153
|
+
const targetAlreadyAccepted = this.#isExactAcceptedTarget(target, transfer, request.identity);
|
|
154
|
+
if (!targetAlreadyAccepted) {
|
|
155
|
+
target = this.#assertPreparedTarget(request.scope, transfer);
|
|
156
|
+
}
|
|
157
|
+
await this.#assertCommitOwnership(request, transfer, sameNativeThread, targetAlreadyAccepted);
|
|
158
|
+
if (sameNativeThread && !sourceAlreadyScrubbed) {
|
|
159
|
+
source = this.#scrubSource(request.scope, transfer, source);
|
|
160
|
+
}
|
|
161
|
+
if (!targetAlreadyAccepted) {
|
|
162
|
+
target = this.#acceptTarget(request, target);
|
|
163
|
+
}
|
|
164
|
+
transfer = this.#persistCommit(request, transfer, source, target, sameNativeThread);
|
|
165
|
+
this.#ports.runtime.crashAt("committed");
|
|
166
|
+
return this.resolve({
|
|
167
|
+
scope: request.scope,
|
|
168
|
+
boundary: request.boundary
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async resolve(options) {
|
|
172
|
+
let transfer = options.scope.loadTransfer(options.boundary.transferId);
|
|
173
|
+
this.assertTransferAuthority(options.scope, transfer, options.boundary);
|
|
174
|
+
if (transfer.status === "resolved") {
|
|
175
|
+
return this.#resolvedTarget(options.scope, transfer);
|
|
176
|
+
}
|
|
177
|
+
assertCommittedReceipt(transfer);
|
|
178
|
+
const source = this.#retireSource(options.scope, transfer);
|
|
179
|
+
const target = this.#bindTarget(options.scope, transfer);
|
|
180
|
+
await this.#ports.authority.assertExclusive(options.scope, options.boundary, {
|
|
181
|
+
processPid: transfer.process_pid,
|
|
182
|
+
nativeThreadId: transfer.target_native_thread_id,
|
|
183
|
+
excludedManagedSessionId: target.session_id,
|
|
184
|
+
allowedManagedSessionIds: abandonedSourceAllowance(transfer)
|
|
185
|
+
});
|
|
186
|
+
transfer = options.scope.saveTransfer({
|
|
187
|
+
...transfer,
|
|
188
|
+
status: "resolved",
|
|
189
|
+
target_after_revision: managedSessionRevision(target),
|
|
190
|
+
target_after_status: "bound",
|
|
191
|
+
target_after_binding_token: managedSessionBindingToken(target),
|
|
192
|
+
source_after_revision: managedSessionRevision(source),
|
|
193
|
+
source_after_status: "detached",
|
|
194
|
+
source_after_binding: source.binding,
|
|
195
|
+
source_after_binding_token: managedSessionBindingToken(source),
|
|
196
|
+
resolved_at: this.#ports.clock.now().toISOString()
|
|
197
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
198
|
+
this.#logResolved(transfer, source, target);
|
|
199
|
+
return target;
|
|
200
|
+
}
|
|
201
|
+
markUncertain(options) {
|
|
202
|
+
let transfer = options.scope.loadTransfer(options.boundary.transferId);
|
|
203
|
+
this.assertTransferAuthority(options.scope, transfer, options.boundary);
|
|
204
|
+
if (["committed", "resolved", "uncertain"].includes(transfer.status)) {
|
|
205
|
+
return transfer;
|
|
206
|
+
}
|
|
207
|
+
if (!["target_prepared", "dispatch_started"].includes(transfer.status)) {
|
|
208
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} has no durable ` +
|
|
209
|
+
"dispatch-start fence");
|
|
210
|
+
}
|
|
211
|
+
const dispatchStartedAt = transfer.dispatch_started_at ??
|
|
212
|
+
this.#ports.clock.now().toISOString();
|
|
213
|
+
const uncertainAt = this.#ports.clock.now().toISOString();
|
|
214
|
+
transfer = options.scope.saveTransfer({
|
|
215
|
+
...transfer,
|
|
216
|
+
status: "uncertain",
|
|
217
|
+
input_stage: transfer.input_stage === "none"
|
|
218
|
+
? "dispatch_started"
|
|
219
|
+
: transfer.input_stage,
|
|
220
|
+
dispatch_started_at: dispatchStartedAt,
|
|
221
|
+
uncertain_at: uncertainAt,
|
|
222
|
+
error: options.reason.slice(0, 2000),
|
|
223
|
+
do_not_retry: true
|
|
224
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
225
|
+
return transfer;
|
|
226
|
+
}
|
|
227
|
+
#finalizeAbortedTarget(scope, transfer) {
|
|
228
|
+
let target = scope.tryLoadSession(transfer.target_session_id);
|
|
229
|
+
if (!target)
|
|
230
|
+
return undefined;
|
|
231
|
+
assertAbortTargetShape(target, transfer, this.#ports.authority.valuesMatch);
|
|
232
|
+
if (target.status === "transitioning") {
|
|
233
|
+
assertAbortTargetRevision(target, transfer);
|
|
234
|
+
const detachedAt = this.#ports.clock.now().toISOString();
|
|
235
|
+
target = scope.saveSession({
|
|
236
|
+
...target,
|
|
237
|
+
status: "detached",
|
|
238
|
+
detached_at: detachedAt,
|
|
239
|
+
updated_at: detachedAt
|
|
240
|
+
}, managedSessionRevision(target));
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
assertResolvedAbortTarget(target, transfer);
|
|
244
|
+
}
|
|
245
|
+
return target;
|
|
246
|
+
}
|
|
247
|
+
#finalizeAbortedSource(scope, transfer) {
|
|
248
|
+
let source = scope.loadSession(transfer.source_session_id);
|
|
249
|
+
if (isRestorableAbortSource(source, transfer, this.#ports.authority.valuesMatch)) {
|
|
250
|
+
const restoredAt = this.#ports.clock.now().toISOString();
|
|
251
|
+
source = scope.saveSession({
|
|
252
|
+
...source,
|
|
253
|
+
status: "bound",
|
|
254
|
+
last_transition_id: transfer.source_previous_last_transition_id,
|
|
255
|
+
updated_at: restoredAt
|
|
256
|
+
}, managedSessionRevision(source));
|
|
257
|
+
}
|
|
258
|
+
assertResolvedAbortSource(source, transfer, this.#ports.authority.valuesMatch);
|
|
259
|
+
return source;
|
|
260
|
+
}
|
|
261
|
+
#reserveAfterVerification(request, transfer, source) {
|
|
262
|
+
const reservedAt = this.#ports.clock.now().toISOString();
|
|
263
|
+
const reserved = request.scope.saveSession({
|
|
264
|
+
...source,
|
|
265
|
+
status: "transitioning",
|
|
266
|
+
last_transition_id: transfer.transfer_id,
|
|
267
|
+
updated_at: reservedAt
|
|
268
|
+
}, managedSessionRevision(source));
|
|
269
|
+
this.#ports.runtime.crashAt("source_session_reserved");
|
|
270
|
+
request.boundary.sourceReservedRevision = managedSessionRevision(reserved);
|
|
271
|
+
request.boundary.sourceReservedBindingToken =
|
|
272
|
+
managedSessionBindingToken(reserved);
|
|
273
|
+
transfer = request.scope.saveTransfer({
|
|
274
|
+
...transfer,
|
|
275
|
+
status: "source_reserved",
|
|
276
|
+
source_reserved_at: reservedAt
|
|
277
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
278
|
+
this.#ports.runtime.crashAt("source_reserved");
|
|
279
|
+
const target = this.#prepareTarget(request, transfer);
|
|
280
|
+
transfer = target.transfer;
|
|
281
|
+
this.#ports.runtime.crashAt("target_prepared");
|
|
282
|
+
const createdSession = request.scope.saveSession(target.provisional, null);
|
|
283
|
+
assertCreatedTarget(createdSession, request.boundary);
|
|
284
|
+
this.#logReserved(request.boundary, transfer, source);
|
|
285
|
+
return {
|
|
286
|
+
createdSession,
|
|
287
|
+
rollback: (scope) => {
|
|
288
|
+
if (!request.scope.sameInvocation(scope)) {
|
|
289
|
+
throw new Error("deferred foreground rollback escaped its exact mutation resources");
|
|
290
|
+
}
|
|
291
|
+
this.abortBeforeInput({
|
|
292
|
+
scope,
|
|
293
|
+
boundary: request.boundary,
|
|
294
|
+
reason: "terminal input was proved not to have started"
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
#prepareTarget(request, transfer) {
|
|
300
|
+
const provisional = {
|
|
301
|
+
...request.targetSession,
|
|
302
|
+
status: "transitioning",
|
|
303
|
+
last_transition_id: transfer.transfer_id
|
|
304
|
+
};
|
|
305
|
+
request.boundary.targetPreparedRevision = 1;
|
|
306
|
+
request.boundary.targetPreparedBindingToken =
|
|
307
|
+
managedSessionBindingToken(provisional);
|
|
308
|
+
const prepared = request.scope.withTurnStatePath({
|
|
309
|
+
...transfer,
|
|
310
|
+
status: "target_prepared",
|
|
311
|
+
target_prepared_at: this.#ports.clock.now().toISOString(),
|
|
312
|
+
target_prepared_revision: 1,
|
|
313
|
+
target_prepared_status: "transitioning",
|
|
314
|
+
target_prepared_last_transition_id: transfer.transfer_id,
|
|
315
|
+
target_prepared_binding_token: managedSessionBindingToken(provisional),
|
|
316
|
+
target_before_binding: provisional.binding,
|
|
317
|
+
message_id: request.messageId,
|
|
318
|
+
turn_id: request.turnId
|
|
319
|
+
});
|
|
320
|
+
return {
|
|
321
|
+
provisional,
|
|
322
|
+
transfer: request.scope.saveTransfer(prepared, deferredForegroundTransferRevision(transfer))
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
#abortFailedReservation(request, error) {
|
|
326
|
+
try {
|
|
327
|
+
this.abortBeforeInput({
|
|
328
|
+
scope: request.scope,
|
|
329
|
+
boundary: request.boundary,
|
|
330
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
catch (abortError) {
|
|
334
|
+
throw new Error(`deferred foreground reservation failed and could not be aborted: ${abortError instanceof Error ? abortError.message : String(abortError)}`, { cause: error });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
#assertPreparedTarget(scope, transfer) {
|
|
338
|
+
const target = scope.loadSession(transfer.target_session_id);
|
|
339
|
+
const matches = target.status === "transitioning" &&
|
|
340
|
+
target.last_transition_id === transfer.transfer_id &&
|
|
341
|
+
managedSessionRevision(target) === transfer.target_prepared_revision &&
|
|
342
|
+
managedSessionBindingToken(target) ===
|
|
343
|
+
transfer.target_prepared_binding_token &&
|
|
344
|
+
this.#ports.authority.valuesMatch(target.binding, transfer.target_before_binding) &&
|
|
345
|
+
target.lineage.transition_id === transfer.transfer_id &&
|
|
346
|
+
target.lineage.previous_session_id === transfer.source_session_id;
|
|
347
|
+
if (!matches) {
|
|
348
|
+
throw new Error(`deferred foreground target ${transfer.target_session_id} changed ` +
|
|
349
|
+
"before terminal dispatch");
|
|
350
|
+
}
|
|
351
|
+
return target;
|
|
352
|
+
}
|
|
353
|
+
#assertReservedSource(scope, transfer, boundary) {
|
|
354
|
+
const source = scope.loadSession(transfer.source_session_id);
|
|
355
|
+
const matches = source.status === "transitioning" &&
|
|
356
|
+
source.last_transition_id === transfer.transfer_id &&
|
|
357
|
+
managedSessionRevision(source) === transfer.source_expected_revision + 1 &&
|
|
358
|
+
managedSessionBindingToken(source) === boundary.sourceReservedBindingToken &&
|
|
359
|
+
this.#ports.authority.valuesMatch(source.binding, transfer.source_before_binding);
|
|
360
|
+
if (!matches) {
|
|
361
|
+
throw new Error(`deferred foreground source ${transfer.source_session_id} changed ` +
|
|
362
|
+
"during terminal dispatch");
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
#isExactScrubbedSource(source, transfer) {
|
|
366
|
+
const before = transfer.source_before_binding;
|
|
367
|
+
const after = source.binding;
|
|
368
|
+
return Boolean(source.status === "transitioning" &&
|
|
369
|
+
source.last_transition_id === transfer.transfer_id &&
|
|
370
|
+
managedSessionRevision(source) === transfer.source_expected_revision + 2 &&
|
|
371
|
+
after &&
|
|
372
|
+
after.binding_id !== before.binding_id &&
|
|
373
|
+
after.generation === before.generation + 1 &&
|
|
374
|
+
after.terminal_id === before.terminal_id &&
|
|
375
|
+
terminalControlsShareIncarnation(after.terminal_control, before.terminal_control) &&
|
|
376
|
+
after.native_thread_id === undefined &&
|
|
377
|
+
after.native_process.rollout === undefined &&
|
|
378
|
+
after.native_process.pid === transfer.process_pid &&
|
|
379
|
+
after.native_process.process_uuid === transfer.process_uuid &&
|
|
380
|
+
after.native_process.process_birth === transfer.process_birth &&
|
|
381
|
+
after.native_process.evidence ===
|
|
382
|
+
"deferred_predecessor_binding_scrubbed");
|
|
383
|
+
}
|
|
384
|
+
#isExactAcceptedTarget(target, transfer, identity) {
|
|
385
|
+
const before = transfer.target_before_binding;
|
|
386
|
+
const after = target.binding;
|
|
387
|
+
return Boolean(before && after && target.status === "transitioning" &&
|
|
388
|
+
target.last_transition_id === transfer.transfer_id &&
|
|
389
|
+
managedSessionRevision(target) ===
|
|
390
|
+
Number(transfer.target_prepared_revision) + 1 &&
|
|
391
|
+
after.binding_id === before.binding_id &&
|
|
392
|
+
after.generation === before.generation &&
|
|
393
|
+
after.native_thread_id === identity.sessionId &&
|
|
394
|
+
after.native_process.pid === transfer.process_pid &&
|
|
395
|
+
after.native_process.process_uuid === identity.processUuid &&
|
|
396
|
+
after.native_process.process_birth === identity.processBirth &&
|
|
397
|
+
exactRolloutMatches(after.native_process.rollout, identity.rollout));
|
|
398
|
+
}
|
|
399
|
+
#assertCommittableSource(source, transfer, boundary, alreadyScrubbed) {
|
|
400
|
+
const reserved = source.status === "transitioning" &&
|
|
401
|
+
source.last_transition_id === transfer.transfer_id &&
|
|
402
|
+
managedSessionRevision(source) === transfer.source_expected_revision + 1 &&
|
|
403
|
+
managedSessionBindingToken(source) === boundary.sourceReservedBindingToken &&
|
|
404
|
+
this.#ports.authority.valuesMatch(source.binding, transfer.source_before_binding);
|
|
405
|
+
if (!reserved && !alreadyScrubbed) {
|
|
406
|
+
throw new Error(`deferred foreground source ${source.session_id} changed before commit`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async #assertCommitOwnership(request, transfer, sameNativeThread, targetAlreadyAccepted) {
|
|
410
|
+
await this.#ports.authority.assertExclusive(request.scope, request.boundary, {
|
|
411
|
+
processPid: transfer.process_pid,
|
|
412
|
+
nativeThreadId: request.identity.sessionId,
|
|
413
|
+
excludedManagedSessionId: targetAlreadyAccepted
|
|
414
|
+
? transfer.target_session_id
|
|
415
|
+
: sameNativeThread
|
|
416
|
+
? transfer.source_session_id
|
|
417
|
+
: transfer.target_session_id,
|
|
418
|
+
allowedManagedSessionIds: abandonedSourceAllowance(transfer)
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
#scrubSource(scope, transfer, source) {
|
|
422
|
+
const scrubbedAt = this.#ports.clock.now();
|
|
423
|
+
const scrubbedBinding = terminalBindingFrom({
|
|
424
|
+
terminalId: transfer.source_before_binding.terminal_id,
|
|
425
|
+
terminalControl: transfer.source_before_binding.terminal_control,
|
|
426
|
+
pid: transfer.process_pid,
|
|
427
|
+
processUuid: transfer.process_uuid,
|
|
428
|
+
processBirth: transfer.process_birth,
|
|
429
|
+
evidence: "deferred_predecessor_binding_scrubbed",
|
|
430
|
+
generation: transfer.source_before_binding.generation + 1,
|
|
431
|
+
now: scrubbedAt
|
|
432
|
+
});
|
|
433
|
+
const saved = scope.saveSession({
|
|
434
|
+
...source,
|
|
435
|
+
binding: scrubbedBinding,
|
|
436
|
+
updated_at: scrubbedAt.toISOString()
|
|
437
|
+
}, managedSessionRevision(source));
|
|
438
|
+
this.#ports.runtime.crashAt("source_scrubbed");
|
|
439
|
+
return saved;
|
|
440
|
+
}
|
|
441
|
+
#acceptTarget(request, target) {
|
|
442
|
+
const acceptedBinding = {
|
|
443
|
+
...target.binding,
|
|
444
|
+
native_thread_id: request.identity.sessionId,
|
|
445
|
+
native_process: {
|
|
446
|
+
...target.binding.native_process,
|
|
447
|
+
process_uuid: request.identity.processUuid,
|
|
448
|
+
process_birth: request.identity.processBirth,
|
|
449
|
+
rollout: request.identity.rollout,
|
|
450
|
+
evidence: request.identity.evidence
|
|
451
|
+
},
|
|
452
|
+
last_verified_at: request.acceptedAt
|
|
453
|
+
};
|
|
454
|
+
const saved = request.scope.saveSession({
|
|
455
|
+
...target,
|
|
456
|
+
binding: acceptedBinding,
|
|
457
|
+
updated_at: request.acceptedAt
|
|
458
|
+
}, managedSessionRevision(target));
|
|
459
|
+
this.#ports.runtime.crashAt("target_accepted");
|
|
460
|
+
return saved;
|
|
461
|
+
}
|
|
462
|
+
#persistCommit(request, transfer, source, target, sameNativeThread) {
|
|
463
|
+
const transportProofAt = transfer.dispatch_started_at ?? request.acceptedAt;
|
|
464
|
+
return request.scope.saveTransfer({
|
|
465
|
+
...transfer,
|
|
466
|
+
status: "committed",
|
|
467
|
+
input_stage: "agent_accepted",
|
|
468
|
+
dispatch_started_at: transfer.dispatch_started_at ?? transportProofAt,
|
|
469
|
+
text_injected_at: transfer.text_injected_at ?? transportProofAt,
|
|
470
|
+
enter_dispatched_at: transfer.enter_dispatched_at ?? transportProofAt,
|
|
471
|
+
agent_accepted_at: request.acceptedAt,
|
|
472
|
+
target_native_thread_id: request.identity.sessionId,
|
|
473
|
+
target_accepted_revision: managedSessionRevision(target),
|
|
474
|
+
target_accepted_status: "transitioning",
|
|
475
|
+
target_accepted_binding_token: managedSessionBindingToken(target),
|
|
476
|
+
target_accepted_binding: target.binding,
|
|
477
|
+
source_pre_retirement_revision: managedSessionRevision(source),
|
|
478
|
+
source_pre_retirement_status: "transitioning",
|
|
479
|
+
source_pre_retirement_binding_token: managedSessionBindingToken(source),
|
|
480
|
+
source_pre_retirement_binding: source.binding,
|
|
481
|
+
source_retirement: sameNativeThread
|
|
482
|
+
? "binding_scrubbed_same_native_thread"
|
|
483
|
+
: "binding_retained",
|
|
484
|
+
committed_at: request.acceptedAt,
|
|
485
|
+
...(transfer.status === "uncertain"
|
|
486
|
+
? { recovered_at: request.acceptedAt }
|
|
487
|
+
: {})
|
|
488
|
+
}, deferredForegroundTransferRevision(transfer));
|
|
489
|
+
}
|
|
490
|
+
#resolvedTarget(scope, transfer) {
|
|
491
|
+
const target = scope.loadSession(transfer.target_session_id);
|
|
492
|
+
if (target.status !== "bound" ||
|
|
493
|
+
managedSessionRevision(target) !== transfer.target_after_revision ||
|
|
494
|
+
managedSessionBindingToken(target) !== transfer.target_after_binding_token) {
|
|
495
|
+
throw new Error(`resolved deferred target ${target.session_id} changed`);
|
|
496
|
+
}
|
|
497
|
+
return target;
|
|
498
|
+
}
|
|
499
|
+
#retireSource(scope, transfer) {
|
|
500
|
+
let source = scope.loadSession(transfer.source_session_id);
|
|
501
|
+
if (source.status === "transitioning") {
|
|
502
|
+
assertSourceCommitReceipt(source, transfer, this.#ports.authority.valuesMatch);
|
|
503
|
+
const detachedAt = this.#ports.clock.now().toISOString();
|
|
504
|
+
source = scope.saveSession({
|
|
505
|
+
...source,
|
|
506
|
+
status: "detached",
|
|
507
|
+
last_transition_id: transfer.source_previous_last_transition_id,
|
|
508
|
+
detached_at: detachedAt,
|
|
509
|
+
updated_at: detachedAt
|
|
510
|
+
}, managedSessionRevision(source));
|
|
511
|
+
this.#ports.runtime.crashAt("source_detached");
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
assertRetiredSource(source, transfer, this.#ports.authority.valuesMatch);
|
|
515
|
+
}
|
|
516
|
+
return source;
|
|
517
|
+
}
|
|
518
|
+
#bindTarget(scope, transfer) {
|
|
519
|
+
let target = scope.loadSession(transfer.target_session_id);
|
|
520
|
+
if (target.status === "transitioning") {
|
|
521
|
+
assertTargetCommitReceipt(target, transfer, this.#ports.authority.valuesMatch);
|
|
522
|
+
const boundAt = this.#ports.clock.now().toISOString();
|
|
523
|
+
target = scope.saveSession({
|
|
524
|
+
...target,
|
|
525
|
+
status: "bound",
|
|
526
|
+
last_transition_id: undefined,
|
|
527
|
+
updated_at: boundAt
|
|
528
|
+
}, managedSessionRevision(target));
|
|
529
|
+
this.#ports.runtime.crashAt("target_bound");
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
assertBoundTarget(target, transfer, this.#ports.authority.valuesMatch);
|
|
533
|
+
}
|
|
534
|
+
return target;
|
|
535
|
+
}
|
|
536
|
+
#logReserved(boundary, transfer, source) {
|
|
537
|
+
this.#ports.runtime.log("info", "deferred_codex_foreground_source_reserved", {
|
|
538
|
+
transfer_id: transfer.transfer_id,
|
|
539
|
+
terminal_id: boundary.terminal.conversationId,
|
|
540
|
+
source_session_id: source.session_id,
|
|
541
|
+
native_thread_id: source.binding?.native_thread_id,
|
|
542
|
+
process_uuid: boundary.processUuid,
|
|
543
|
+
process_birth: boundary.processBirth,
|
|
544
|
+
terminal_input_sent: false
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
#logResolved(transfer, source, target) {
|
|
548
|
+
this.#ports.runtime.log("info", "deferred_codex_foreground_transfer_resolved", {
|
|
549
|
+
transfer_id: transfer.transfer_id,
|
|
550
|
+
source_session_id: source.session_id,
|
|
551
|
+
target_session_id: target.session_id,
|
|
552
|
+
native_thread_id: transfer.target_native_thread_id,
|
|
553
|
+
source_retirement: transfer.source_retirement
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function provedDispatchDidNotStart(transfer, terminalInputNotStartedAt) {
|
|
558
|
+
return transfer.status === "dispatch_started" &&
|
|
559
|
+
transfer.input_stage === "dispatch_started" &&
|
|
560
|
+
terminalInputNotStartedAt !== undefined &&
|
|
561
|
+
Number.isFinite(Date.parse(terminalInputNotStartedAt));
|
|
562
|
+
}
|
|
563
|
+
function assertCanAbort(transfer, provedZeroInput) {
|
|
564
|
+
if (transfer.input_stage !== "none" && !provedZeroInput) {
|
|
565
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} may have started ` +
|
|
566
|
+
"terminal input and cannot restore its source");
|
|
567
|
+
}
|
|
568
|
+
const statusAllowed = [
|
|
569
|
+
"prepared",
|
|
570
|
+
"source_reserved",
|
|
571
|
+
"target_prepared",
|
|
572
|
+
"dispatch_started",
|
|
573
|
+
"aborted"
|
|
574
|
+
].includes(transfer.status);
|
|
575
|
+
if (!statusAllowed) {
|
|
576
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} cannot abort from ` +
|
|
577
|
+
transfer.status);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
function assertZeroInputAbortIntent(transfer) {
|
|
581
|
+
const provedZeroInput = transfer.input_stage === "dispatch_started" &&
|
|
582
|
+
transfer.terminal_input_not_started_at !== undefined &&
|
|
583
|
+
Number.isFinite(Date.parse(transfer.terminal_input_not_started_at));
|
|
584
|
+
if (transfer.status !== "aborted" ||
|
|
585
|
+
(transfer.input_stage !== "none" && !provedZeroInput)) {
|
|
586
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} does not carry a ` +
|
|
587
|
+
"zero-input abort intent");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function assertAbortTargetShape(target, transfer, valuesMatch) {
|
|
591
|
+
if (target.lineage.transition_id !== transfer.transfer_id ||
|
|
592
|
+
target.lineage.previous_session_id !== transfer.source_session_id ||
|
|
593
|
+
target.binding?.native_thread_id ||
|
|
594
|
+
target.binding?.native_process.rollout ||
|
|
595
|
+
target.last_transition_id !== transfer.transfer_id ||
|
|
596
|
+
!transfer.target_before_binding ||
|
|
597
|
+
!valuesMatch(target.binding, transfer.target_before_binding)) {
|
|
598
|
+
throw new Error(`deferred foreground target ${target.session_id} changed before abort cleanup`);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function assertAbortTargetRevision(target, transfer) {
|
|
602
|
+
if (managedSessionRevision(target) !== transfer.target_prepared_revision ||
|
|
603
|
+
managedSessionBindingToken(target) !== transfer.target_prepared_binding_token) {
|
|
604
|
+
throw new Error(`deferred foreground target ${target.session_id} changed before abort cleanup`);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
function assertResolvedAbortTarget(target, transfer) {
|
|
608
|
+
const expectedToken = managedSessionBindingToken({
|
|
609
|
+
session_id: transfer.target_session_id,
|
|
610
|
+
status: "detached",
|
|
611
|
+
binding: transfer.target_before_binding
|
|
612
|
+
});
|
|
613
|
+
if (target.status !== "detached" ||
|
|
614
|
+
managedSessionRevision(target) !== Number(transfer.target_prepared_revision) + 1 ||
|
|
615
|
+
managedSessionBindingToken(target) !== expectedToken) {
|
|
616
|
+
throw new Error(`deferred foreground target ${target.session_id} cannot finish abort ` +
|
|
617
|
+
`cleanup from ${target.status}`);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function isRestorableAbortSource(source, transfer, valuesMatch) {
|
|
621
|
+
return source.status === "transitioning" &&
|
|
622
|
+
source.last_transition_id === transfer.transfer_id &&
|
|
623
|
+
managedSessionRevision(source) === transfer.source_expected_revision + 1 &&
|
|
624
|
+
managedSessionBindingToken(source) === managedSessionBindingToken({
|
|
625
|
+
session_id: transfer.source_session_id,
|
|
626
|
+
status: "transitioning",
|
|
627
|
+
binding: transfer.source_before_binding
|
|
628
|
+
}) &&
|
|
629
|
+
valuesMatch(source.binding, transfer.source_before_binding);
|
|
630
|
+
}
|
|
631
|
+
function assertResolvedAbortSource(source, transfer, valuesMatch) {
|
|
632
|
+
const allowedRevisions = transfer.source_reserved_at
|
|
633
|
+
? [transfer.source_expected_revision + 2]
|
|
634
|
+
: [transfer.source_expected_revision, transfer.source_expected_revision + 2];
|
|
635
|
+
if (source.status !== "bound" ||
|
|
636
|
+
source.last_transition_id !== transfer.source_previous_last_transition_id ||
|
|
637
|
+
!allowedRevisions.includes(managedSessionRevision(source)) ||
|
|
638
|
+
managedSessionBindingToken(source) !== transfer.source_binding_token ||
|
|
639
|
+
!valuesMatch(source.binding, transfer.source_before_binding)) {
|
|
640
|
+
throw new Error(`deferred foreground source ${source.session_id} changed before abort cleanup`);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
function abortTargetReceipt(target) {
|
|
644
|
+
return {
|
|
645
|
+
abort_target_after_revision: managedSessionRevision(target),
|
|
646
|
+
abort_target_after_binding_token: managedSessionBindingToken(target),
|
|
647
|
+
abort_target_after_binding: target.binding
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
function assertCreatedTarget(created, boundary) {
|
|
651
|
+
if (managedSessionRevision(created) !== 1 ||
|
|
652
|
+
managedSessionBindingToken(created) !== boundary.targetPreparedBindingToken) {
|
|
653
|
+
throw new Error(`deferred foreground target ${created.session_id} did not materialize ` +
|
|
654
|
+
"at its prepared CAS authority");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function assertStageTransition(transfer, stage) {
|
|
658
|
+
const expected = stage ===
|
|
659
|
+
"text_injected"
|
|
660
|
+
? "dispatch_started"
|
|
661
|
+
: "text_injected";
|
|
662
|
+
if (transfer.status !== "dispatch_started" || transfer.input_stage !== expected) {
|
|
663
|
+
const action = stage === "text_injected" ? "record text" : "record Enter";
|
|
664
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} cannot ${action} ` +
|
|
665
|
+
`from ${transfer.status}/${transfer.input_stage}`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function assertAcceptedIdentityAuthority(transfer, identity) {
|
|
669
|
+
if (!["dispatch_started", "uncertain"].includes(transfer.status) ||
|
|
670
|
+
transfer.input_stage === "none" ||
|
|
671
|
+
identity.processUuid !== transfer.process_uuid ||
|
|
672
|
+
identity.processBirth !== transfer.process_birth ||
|
|
673
|
+
!isExactNativeThreadId(identity.sessionId) ||
|
|
674
|
+
!isCompleteNativeRollout(identity.rollout)) {
|
|
675
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} lacks exact ` +
|
|
676
|
+
"accepted identity authority");
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function abandonedSourceAllowance(transfer) {
|
|
680
|
+
return transfer.source_rollout_authority ===
|
|
681
|
+
"explicitly_abandoned_predecessor"
|
|
682
|
+
? [transfer.source_session_id]
|
|
683
|
+
: [];
|
|
684
|
+
}
|
|
685
|
+
function assertCommittedReceipt(transfer) {
|
|
686
|
+
if (transfer.status !== "committed" ||
|
|
687
|
+
!transfer.source_pre_retirement_binding ||
|
|
688
|
+
!transfer.source_pre_retirement_revision ||
|
|
689
|
+
!transfer.source_pre_retirement_binding_token ||
|
|
690
|
+
!transfer.target_accepted_binding ||
|
|
691
|
+
!transfer.target_accepted_revision ||
|
|
692
|
+
!transfer.target_accepted_binding_token ||
|
|
693
|
+
!transfer.target_native_thread_id) {
|
|
694
|
+
throw new Error(`deferred foreground transfer ${transfer.transfer_id} is not committed`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function assertSourceCommitReceipt(source, transfer, valuesMatch) {
|
|
698
|
+
if (source.last_transition_id !== transfer.transfer_id ||
|
|
699
|
+
managedSessionRevision(source) !== transfer.source_pre_retirement_revision ||
|
|
700
|
+
managedSessionBindingToken(source) !==
|
|
701
|
+
transfer.source_pre_retirement_binding_token ||
|
|
702
|
+
!valuesMatch(source.binding, transfer.source_pre_retirement_binding)) {
|
|
703
|
+
throw new Error(`deferred foreground source ${source.session_id} changed during commit recovery`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function assertRetiredSource(source, transfer, valuesMatch) {
|
|
707
|
+
const token = managedSessionBindingToken({
|
|
708
|
+
session_id: source.session_id,
|
|
709
|
+
status: "detached",
|
|
710
|
+
binding: transfer.source_pre_retirement_binding
|
|
711
|
+
});
|
|
712
|
+
if (source.status !== "detached" ||
|
|
713
|
+
managedSessionRevision(source) !==
|
|
714
|
+
Number(transfer.source_pre_retirement_revision) + 1 ||
|
|
715
|
+
managedSessionBindingToken(source) !== token ||
|
|
716
|
+
!valuesMatch(source.binding, transfer.source_pre_retirement_binding)) {
|
|
717
|
+
throw new Error(`deferred foreground source ${source.session_id} has no exact retired receipt`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
function assertTargetCommitReceipt(target, transfer, valuesMatch) {
|
|
721
|
+
if (target.last_transition_id !== transfer.transfer_id ||
|
|
722
|
+
managedSessionRevision(target) !== transfer.target_accepted_revision ||
|
|
723
|
+
managedSessionBindingToken(target) !== transfer.target_accepted_binding_token ||
|
|
724
|
+
!valuesMatch(target.binding, transfer.target_accepted_binding)) {
|
|
725
|
+
throw new Error(`deferred foreground target ${target.session_id} changed during commit recovery`);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
function assertBoundTarget(target, transfer, valuesMatch) {
|
|
729
|
+
const token = managedSessionBindingToken({
|
|
730
|
+
session_id: target.session_id,
|
|
731
|
+
status: "bound",
|
|
732
|
+
binding: transfer.target_accepted_binding
|
|
733
|
+
});
|
|
734
|
+
if (target.status !== "bound" ||
|
|
735
|
+
managedSessionRevision(target) !==
|
|
736
|
+
Number(transfer.target_accepted_revision) + 1 ||
|
|
737
|
+
managedSessionBindingToken(target) !== token ||
|
|
738
|
+
!valuesMatch(target.binding, transfer.target_accepted_binding)) {
|
|
739
|
+
throw new Error(`deferred foreground target ${target.session_id} has no exact bound receipt`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
//# sourceMappingURL=deferred-foreground-application-service.js.map
|