@sema-agent/core 7.60.0 → 7.62.0
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 +917 -0
- package/README.md +2 -2
- package/dist/agents/agent-transcript-tool.d.ts +2 -2
- package/dist/agents/agent-transcript-tool.js +1 -1
- package/dist/agents/cascade.d.ts +71 -12
- package/dist/agents/cascade.js +61 -21
- package/dist/agents/composition-allowance.d.ts +53 -0
- package/dist/agents/composition-allowance.js +49 -0
- package/dist/agents/composition-placement.d.ts +29 -0
- package/dist/agents/composition-placement.js +24 -0
- package/dist/agents/cumulative-stats.d.ts +4 -0
- package/dist/agents/cumulative-stats.js +3 -0
- package/dist/agents/inherited-tool-pool.d.ts +5 -3
- package/dist/agents/inherited-tool-pool.js +2 -2
- package/dist/agents/list-agents-tool.d.ts +1 -1
- package/dist/agents/peer-held-queue.d.ts +27 -4
- package/dist/agents/peer-held-queue.js +81 -36
- package/dist/agents/peer-notice-route.d.ts +1 -1
- package/dist/agents/peer-notice-route.js +4 -3
- package/dist/agents/peer-notices.d.ts +4 -4
- package/dist/agents/peer-notices.js +8 -4
- package/dist/agents/peer-session-drain.d.ts +8 -1
- package/dist/agents/peer-session-drain.js +49 -10
- package/dist/agents/repair-loop.js +16 -6
- package/dist/agents/retain-ledger.js +3 -1
- package/dist/agents/roster-store.d.ts +1 -1
- package/dist/agents/roster-store.js +7 -4
- package/dist/agents/send-message-tool.d.ts +8 -10
- package/dist/agents/send-message-tool.js +43 -23
- package/dist/agents/subagent-completion-gate.d.ts +35 -0
- package/dist/agents/subagent-completion-gate.js +62 -0
- package/dist/agents/subagent-steps.d.ts +7 -6
- package/dist/agents/subagent.d.ts +36 -41
- package/dist/agents/subagent.js +245 -200
- package/dist/agents/suspend-guard.d.ts +47 -16
- package/dist/agents/suspend-guard.js +13 -4
- package/dist/agents/verify.d.ts +41 -14
- package/dist/agents/verify.js +41 -30
- package/dist/brain/anthropic.js +1 -0
- package/dist/brain/errors.d.ts +7 -1
- package/dist/brain/errors.js +6 -0
- package/dist/brain/failover.js +2 -1
- package/dist/brain/open-responses.js +1 -0
- package/dist/brain/openai.js +1 -0
- package/dist/brain/provider-dialect.d.ts +10 -0
- package/dist/brain/provider-dialect.js +13 -2
- package/dist/brain/stream-engine.d.ts +3 -0
- package/dist/brain/stream-engine.js +4 -0
- package/dist/core/agent-state.d.ts +1 -1
- package/dist/core/allow-entry.d.ts +59 -23
- package/dist/core/allow-entry.js +131 -38
- package/dist/core/ask-origin.d.ts +79 -0
- package/dist/core/ask-origin.js +76 -0
- package/dist/core/ask-question.d.ts +19 -13
- package/dist/core/ask-question.js +8 -2
- package/dist/core/auto-compaction.d.ts +2 -0
- package/dist/core/auto-compaction.js +2 -1
- package/dist/core/auto-mode.js +3 -5
- package/dist/core/background-agent-store.d.ts +7 -5
- package/dist/core/background-agent-store.js +12 -11
- package/dist/core/checkpoint-features.d.ts +722 -0
- package/dist/core/checkpoint-features.js +98 -0
- package/dist/core/checkpoint-requirements.d.ts +33 -5
- package/dist/core/checkpoint-requirements.js +18 -5
- package/dist/core/checkpoint-row-verdict.d.ts +99 -0
- package/dist/core/checkpoint-row-verdict.js +225 -0
- package/dist/core/checkpoint-store.d.ts +107 -738
- package/dist/core/checkpoint-store.js +45 -143
- package/dist/core/child-clamp-seats.d.ts +3 -2
- package/dist/core/child-clamp-seats.js +4 -3
- package/dist/core/closest-name.d.ts +13 -0
- package/dist/core/closest-name.js +35 -0
- package/dist/core/context-settings.js +3 -5
- package/dist/core/cross-boundary-taint.d.ts +1 -1
- package/dist/core/decision-receipt.d.ts +14 -1
- package/dist/core/decision-receipt.js +6 -3
- package/dist/core/delegation-frames.d.ts +13 -9
- package/dist/core/effective-path-target.js +2 -3
- package/dist/core/engine-attestation.d.ts +11 -1
- package/dist/core/engine-attestation.js +2 -0
- package/dist/core/engine-notice.d.ts +68 -21
- package/dist/core/engine-notice.js +9 -2
- package/dist/core/file-history-retention.d.ts +8 -0
- package/dist/core/file-history-retention.js +14 -11
- package/dist/core/file-history-store.d.ts +31 -1
- package/dist/core/file-history-store.js +31 -2
- package/dist/core/frame-settlement.d.ts +10 -0
- package/dist/core/frame-settlement.js +6 -1
- package/dist/core/fs-write-gate-policy.d.ts +3 -3
- package/dist/core/fs-write-gate-policy.js +8 -7
- package/dist/core/gate-fold.js +4 -3
- package/dist/core/gate-lanes.js +7 -4
- package/dist/core/gate-outcome.d.ts +40 -1
- package/dist/core/gate-outcome.js +10 -0
- package/dist/core/git-worktree-env.d.ts +7 -3
- package/dist/core/git-worktree-env.js +16 -13
- package/dist/core/governance-codes.d.ts +14 -4
- package/dist/core/governance-codes.js +19 -4
- package/dist/core/hooks.d.ts +25 -4
- package/dist/core/hooks.js +11 -4
- package/dist/core/host-floor.js +3 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/image-admission.d.ts +47 -7
- package/dist/core/image-admission.js +35 -4
- package/dist/core/input-author.d.ts +36 -0
- package/dist/core/input-author.js +39 -0
- package/dist/core/leg-identity.d.ts +62 -0
- package/dist/core/leg-identity.js +18 -0
- package/dist/core/locked-config.d.ts +4 -3
- package/dist/core/locked-config.js +5 -3
- package/dist/core/lsp.d.ts +5 -3
- package/dist/core/lsp.js +3 -2
- package/dist/core/mailbox-store.d.ts +85 -10
- package/dist/core/mailbox-store.js +31 -10
- package/dist/core/mcp-connection-pool.d.ts +6 -20
- package/dist/core/mcp-connection-pool.js +10 -28
- package/dist/core/mcp-failure.d.ts +76 -15
- package/dist/core/mcp-failure.js +60 -33
- package/dist/core/mcp-host-seat.d.ts +92 -53
- package/dist/core/mcp-host-seat.js +225 -46
- package/dist/core/mcp-probe.js +2 -2
- package/dist/core/mcp-server-link.d.ts +18 -6
- package/dist/core/mcp-server-link.js +19 -4
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/mcp-session-end.d.ts +1 -2
- package/dist/core/mcp-session-end.js +1 -1
- package/dist/core/mcp.d.ts +6 -49
- package/dist/core/mcp.js +115 -111
- package/dist/core/media-byte-cap.d.ts +21 -46
- package/dist/core/media-byte-cap.js +55 -55
- package/dist/core/member-group.d.ts +7 -0
- package/dist/core/member-group.js +35 -0
- package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.d.ts +1 -1
- package/dist/core/memory-engine/consolidation.js +7 -1
- package/dist/core/memory-engine/dual-root.d.ts +31 -0
- package/dist/core/memory-engine/dual-root.js +59 -11
- package/dist/core/memory-engine/engine.js +27 -24
- package/dist/core/memory-engine/file-backend.d.ts +13 -0
- package/dist/core/memory-engine/file-backend.js +35 -15
- package/dist/core/memory-engine/layout.d.ts +3 -0
- package/dist/core/memory-engine/layout.js +13 -3
- package/dist/core/memory-engine/memory-deployment.d.ts +110 -0
- package/dist/core/memory-engine/memory-deployment.js +182 -0
- package/dist/core/memory-engine/sync-client.d.ts +39 -18
- package/dist/core/memory-engine/sync-client.js +72 -14
- package/dist/core/memory-engine/sync-report.d.ts +7 -4
- package/dist/core/memory-engine/sync.d.ts +9 -1
- package/dist/core/memory-vector.d.ts +1 -1
- package/dist/core/memory.d.ts +10 -10
- package/dist/core/mode-policy.d.ts +8 -8
- package/dist/core/mode-policy.js +8 -6
- package/dist/core/mods/agent-stations.d.ts +39 -4
- package/dist/core/mods/agent-stations.js +59 -10
- package/dist/core/mods/classic-events.d.ts +9 -1
- package/dist/core/mods/dollar.d.ts +94 -1
- package/dist/core/mods/dollar.js +13 -1
- package/dist/core/mods/extension-call.d.ts +15 -1
- package/dist/core/mods/extension-call.js +7 -2
- package/dist/core/mods/kernel/dispatch.d.ts +4 -3
- package/dist/core/mods/kernel/dispatch.js +4 -4
- package/dist/core/mods/kernel/events.d.ts +14 -3
- package/dist/core/mods/kernel/events.js +18 -15
- package/dist/core/mods/kernel/registration.d.ts +3 -0
- package/dist/core/mods/kernel/registration.js +5 -0
- package/dist/core/mods/kernel/site-rules.d.ts +6 -3
- package/dist/core/mods/kernel/site-rules.js +10 -2
- package/dist/core/mods/lifecycle-stations.d.ts +36 -4
- package/dist/core/mods/lifecycle-stations.js +44 -9
- package/dist/core/mods/session-append.d.ts +118 -0
- package/dist/core/mods/session-append.js +318 -0
- package/dist/core/mods/session-compact.d.ts +48 -0
- package/dist/core/mods/session-compact.js +194 -0
- package/dist/core/mods/session-receive.d.ts +93 -0
- package/dist/core/mods/session-receive.js +138 -0
- package/dist/core/mods/session-send.d.ts +72 -0
- package/dist/core/mods/session-send.js +88 -0
- package/dist/core/mods/stations.d.ts +88 -21
- package/dist/core/mods/stations.js +149 -11
- package/dist/core/mods/tool-call.d.ts +2 -0
- package/dist/core/mods/tool-call.js +4 -4
- package/dist/core/output-style.js +3 -4
- package/dist/core/own-property-receipt.d.ts +68 -2
- package/dist/core/own-property-receipt.js +45 -2
- package/dist/core/park-selfcheck.js +4 -2
- package/dist/core/path-identity.d.ts +11 -0
- package/dist/core/path-identity.js +4 -0
- package/dist/core/path-rule-binding.d.ts +3 -1
- package/dist/core/path-rule-binding.js +3 -1
- package/dist/core/peer-seat.d.ts +3 -3
- package/dist/core/peer-seat.js +20 -8
- package/dist/core/permission-rule-consent.d.ts +21 -5
- package/dist/core/permission-rule-consent.js +21 -1
- package/dist/core/permission-rule-model.d.ts +34 -11
- package/dist/core/permission-rule-model.js +47 -10
- package/dist/core/permission-rule-org.d.ts +1 -1
- package/dist/core/permission-rule-provider.js +4 -1
- package/dist/core/permission-rules.d.ts +4 -0
- package/dist/core/permission-rules.js +11 -16
- package/dist/core/read-root-candidate.js +1 -1
- package/dist/core/remote-env.d.ts +74 -26
- package/dist/core/remote-env.js +20 -0
- package/dist/core/resume-startup-cause.d.ts +5 -4
- package/dist/core/retention-policy.d.ts +24 -23
- package/dist/core/retention-policy.js +36 -2
- package/dist/core/retention.d.ts +4 -1
- package/dist/core/retired-keys.d.ts +4 -4
- package/dist/core/row-admission.d.ts +10 -0
- package/dist/core/row-admission.js +5 -0
- package/dist/core/runner/advisor-instructions.d.ts +2 -1
- package/dist/core/runner/advisor-instructions.js +2 -1
- package/dist/core/runner/announce-once-ledger.d.ts +4 -4
- package/dist/core/runner/assemble-result.d.ts +13 -3
- package/dist/core/runner/assemble-result.js +12 -7
- package/dist/core/runner/caller-roster.d.ts +12 -9
- package/dist/core/runner/caller-roster.js +5 -2
- package/dist/core/runner/checkpoint-scope.d.ts +16 -1
- package/dist/core/runner/checkpoint-scope.js +21 -0
- package/dist/core/runner/compact-session.js +18 -3
- package/dist/core/runner/compaction-call-options.d.ts +1 -1
- package/dist/core/runner/compaction-restate.d.ts +2 -2
- package/dist/core/runner/compaction-restate.js +4 -3
- package/dist/core/runner/construction-doors.d.ts +2 -2
- package/dist/core/runner/construction-doors.js +2 -2
- package/dist/core/runner/contracts.d.ts +116 -34
- package/dist/core/runner/cross-boundary-lane.d.ts +1 -1
- package/dist/core/runner/decide-continuation.d.ts +4 -2
- package/dist/core/runner/decide-continuation.js +7 -4
- package/dist/core/runner/delegation-owner.d.ts +43 -0
- package/dist/core/runner/delegation-owner.js +59 -0
- package/dist/core/runner/denial-limit-arms.d.ts +15 -21
- package/dist/core/runner/denial-limit-arms.js +17 -10
- package/dist/core/runner/expire-settle.d.ts +44 -0
- package/dist/core/runner/expire-settle.js +55 -0
- package/dist/core/runner/git-status-frame.d.ts +3 -3
- package/dist/core/runner/git-status-frame.js +2 -1
- package/dist/core/runner/halt-attribution.d.ts +2 -1
- package/dist/core/runner/halt-attribution.js +2 -1
- package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
- package/dist/core/runner/lineage-reroot-view.js +108 -0
- package/dist/core/runner/local-claims.d.ts +17 -0
- package/dist/core/runner/local-claims.js +18 -0
- package/dist/core/runner/media-removed-seat.d.ts +46 -0
- package/dist/core/runner/media-removed-seat.js +88 -0
- package/dist/core/runner/park-commit.d.ts +2 -2
- package/dist/core/runner/permission-rule-lanes.d.ts +7 -2
- package/dist/core/runner/permission-rule-lanes.js +28 -9
- package/dist/core/runner/person-path-rows.d.ts +15 -0
- package/dist/core/runner/person-path-rows.js +27 -4
- package/dist/core/runner/placement-fence.d.ts +26 -0
- package/dist/core/runner/placement-fence.js +38 -0
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
- package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
- package/dist/core/runner/prepare-ask-lane.d.ts +6 -12
- package/dist/core/runner/prepare-ask-lane.js +4 -4
- package/dist/core/runner/prepare-boundary-parks.d.ts +4 -1
- package/dist/core/runner/prepare-boundary-parks.js +2 -2
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +2 -1
- package/dist/core/runner/prepare-config-doors.d.ts +6 -6
- package/dist/core/runner/prepare-config-doors.js +19 -21
- package/dist/core/runner/prepare-context-lane.d.ts +6 -2
- package/dist/core/runner/prepare-context-lane.js +13 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +9 -9
- package/dist/core/runner/prepare-delegation-surface.js +4 -5
- package/dist/core/runner/prepare-execution-env.d.ts +5 -2
- package/dist/core/runner/prepare-execution-env.js +7 -4
- package/dist/core/runner/prepare-gate-stations.d.ts +19 -14
- package/dist/core/runner/prepare-gate-stations.js +6 -4
- package/dist/core/runner/prepare-hands-readface.d.ts +6 -6
- package/dist/core/runner/prepare-hands-readface.js +32 -11
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -0
- package/dist/core/runner/prepare-inherited-gate.js +10 -3
- package/dist/core/runner/prepare-lsp.d.ts +3 -0
- package/dist/core/runner/prepare-lsp.js +2 -2
- package/dist/core/runner/prepare-park-ask.d.ts +5 -2
- package/dist/core/runner/prepare-park-ask.js +4 -5
- package/dist/core/runner/prepare-policy-chain.d.ts +10 -21
- package/dist/core/runner/prepare-policy-chain.js +16 -25
- package/dist/core/runner/prepare-project-context.d.ts +2 -2
- package/dist/core/runner/prepare-prompt-inputs.d.ts +5 -4
- package/dist/core/runner/prepare-prompt-inputs.js +3 -2
- package/dist/core/runner/prepare-question-face.d.ts +6 -4
- package/dist/core/runner/prepare-question-face.js +2 -2
- package/dist/core/runner/prepare-run-refs.d.ts +3 -0
- package/dist/core/runner/prepare-run-refs.js +2 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +11 -7
- package/dist/core/runner/prepare-suspend-saga.js +17 -7
- package/dist/core/runner/prepare-task.d.ts +1 -1
- package/dist/core/runner/prepare-task.js +61 -30
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +6 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +3 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -1
- package/dist/core/runner/prepare-workspace-restore.d.ts +5 -0
- package/dist/core/runner/prepare-workspace-restore.js +10 -6
- package/dist/core/runner/read-root-grant.d.ts +1 -1
- package/dist/core/runner/read-root-grant.js +2 -1
- package/dist/core/runner/resume-admission.d.ts +8 -6
- package/dist/core/runner/resume-admission.js +23 -6
- package/dist/core/runner/resume-apply.d.ts +4 -0
- package/dist/core/runner/resume-apply.js +14 -5
- package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
- package/dist/core/runner/resume-checkpoint-screen.js +4 -84
- package/dist/core/runner/resume-claim.d.ts +8 -3
- package/dist/core/runner/resume-claim.js +28 -12
- package/dist/core/runner/resume-internals-and-config.d.ts +2 -2
- package/dist/core/runner/resume-internals-and-config.js +10 -1
- package/dist/core/runner/resume-preflight.d.ts +3 -2
- package/dist/core/runner/resume-preflight.js +13 -26
- package/dist/core/runner/retired-runner-deps.js +2 -0
- package/dist/core/runner/run-git-lane.d.ts +2 -0
- package/dist/core/runner/run-git-lane.js +6 -2
- package/dist/core/runner/run-harness-handlers.d.ts +2 -0
- package/dist/core/runner/run-harness-handlers.js +5 -4
- package/dist/core/runner/run-identity-wiring.d.ts +2 -2
- package/dist/core/runner/run-identity-wiring.js +14 -5
- package/dist/core/runner/run-leg.d.ts +3 -3
- package/dist/core/runner/run-leg.js +64 -36
- package/dist/core/runner/run-notification-lane.js +20 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -2
- package/dist/core/runner/run-settle-and-teardown.js +12 -9
- package/dist/core/runner/run-stop-and-final-verify.js +2 -1
- package/dist/core/runner/run-telemetry-and-budget-seats.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.d.ts +1 -1
- package/dist/core/runner/run-terminal-adoption.js +26 -17
- package/dist/core/runner/run-turn-boundary.js +34 -18
- package/dist/core/runner/runtask.d.ts +18 -3
- package/dist/core/runner/runtask.js +33 -17
- package/dist/core/runner/session-rule-policy.d.ts +1 -1
- package/dist/core/runner/session-rule-policy.js +6 -1
- package/dist/core/runner/shell-env-withheld.d.ts +1 -1
- package/dist/core/runner/steering-preview.d.ts +9 -0
- package/dist/core/runner/steering-preview.js +5 -0
- package/dist/core/runner/stream-halt-verbs.d.ts +1 -14
- package/dist/core/runner/stream-halt-verbs.js +4 -3
- package/dist/core/runner/stream-reap.d.ts +7 -6
- package/dist/core/runner/stream-reap.js +13 -16
- package/dist/core/runner/stream-settle-backstop.d.ts +3 -2
- package/dist/core/runner/stream-settle-backstop.js +5 -3
- package/dist/core/runner/stream-steer-verb.d.ts +5 -2
- package/dist/core/runner/stream-steer-verb.js +16 -7
- package/dist/core/runner/terminal-account.d.ts +11 -1
- package/dist/core/runner/terminal-account.js +20 -0
- package/dist/core/runner/terminal-projection.d.ts +8 -2
- package/dist/core/runner/terminal-projection.js +2 -2
- package/dist/core/runner/tool-disclosure.d.ts +3 -0
- package/dist/core/runner/tool-disclosure.js +5 -2
- package/dist/core/runner/tool-end-body.d.ts +3 -3
- package/dist/core/runner/tool-end-body.js +1 -1
- package/dist/core/runner/tool-face-overlay.js +2 -0
- package/dist/core/runner/tool-output-projection.d.ts +3 -3
- package/dist/core/runner/tool-output-projection.js +7 -6
- package/dist/core/runner/tool-table-view.d.ts +56 -0
- package/dist/core/runner/tool-table-view.js +51 -0
- package/dist/core/runner/turn-attachments.d.ts +8 -2
- package/dist/core/runner/turn-attachments.js +2 -2
- package/dist/core/runner/void-verifier-pause.d.ts +33 -0
- package/dist/core/runner/void-verifier-pause.js +41 -0
- package/dist/core/runner-deps.d.ts +26 -27
- package/dist/core/secret-env.d.ts +19 -16
- package/dist/core/secret-env.js +45 -27
- package/dist/core/session-log-transfer.js +9 -10
- package/dist/core/session-policy-store.d.ts +1 -1
- package/dist/core/session-policy-store.js +5 -2
- package/dist/core/session-reconcile.d.ts +3 -2
- package/dist/core/session-reconcile.js +7 -4
- package/dist/core/session-store.d.ts +3 -1
- package/dist/core/session-store.js +10 -8
- package/dist/core/session.d.ts +16 -5
- package/dist/core/shell-confinement.d.ts +37 -0
- package/dist/core/shell-confinement.js +56 -0
- package/dist/core/skill-grant.js +1 -1
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +8 -2
- package/dist/core/store-contracts/checkpoint-store-contract.js +83 -2
- package/dist/core/store-contracts/file-history-store-contract.d.ts +5 -2
- package/dist/core/store-contracts/file-history-store-contract.js +25 -1
- package/dist/core/store-contracts/mailbox-store-contract.d.ts +12 -5
- package/dist/core/store-contracts/mailbox-store-contract.js +156 -9
- package/dist/core/store-contracts/session-store-contract.js +22 -8
- package/dist/core/store-contracts/tool-result-store-contract.d.ts +1 -1
- package/dist/core/store-contracts/tool-result-store-contract.js +30 -0
- package/dist/core/task-event.d.ts +24 -9
- package/dist/core/task-limits.d.ts +5 -0
- package/dist/core/task-notification.d.ts +89 -12
- package/dist/core/task-notification.js +89 -14
- package/dist/core/task-registry-agent.d.ts +32 -50
- package/dist/core/task-registry-agent.js +36 -56
- package/dist/core/task-registry-monitor.d.ts +1 -1
- package/dist/core/task-registry-monitor.js +15 -60
- package/dist/core/task-registry-shared.d.ts +22 -112
- package/dist/core/task-registry-shared.js +3 -41
- package/dist/core/task-registry-workflow.js +5 -21
- package/dist/core/task-registry.d.ts +32 -62
- package/dist/core/task-registry.js +30 -110
- package/dist/core/task-result.d.ts +29 -12
- package/dist/core/task-spec-members.d.ts +39 -0
- package/dist/core/task-spec-members.js +92 -0
- package/dist/core/task-spec.d.ts +11 -11
- package/dist/core/task-tool-shape.d.ts +7 -57
- package/dist/core/task-tool-shape.js +7 -66
- package/dist/core/terminal-cause.d.ts +36 -6
- package/dist/core/terminal-cause.js +1 -0
- package/dist/core/tool-catalog-entries.js +2 -5
- package/dist/core/tool-check-reading.js +16 -10
- package/dist/core/tool-conformance.js +1 -2
- package/dist/core/tool-errors.d.ts +6 -3
- package/dist/core/tool-errors.js +2 -0
- package/dist/core/tool-face-reader.js +3 -2
- package/dist/core/tool-face.d.ts +8 -5
- package/dist/core/tool-face.js +1 -1
- package/dist/core/tool-name-aliases.d.ts +5 -29
- package/dist/core/tool-name-aliases.js +9 -5
- package/dist/core/tool-name-readings.d.ts +14 -3
- package/dist/core/tool-name-readings.js +2 -0
- package/dist/core/tool-policy.d.ts +109 -18
- package/dist/core/tool-policy.js +84 -14
- package/dist/core/tool-result-store.d.ts +23 -0
- package/dist/core/tool-result-store.js +3 -2
- package/dist/core/tool-roster.d.ts +4 -4
- package/dist/core/tool-spec.d.ts +23 -6
- package/dist/core/trace.d.ts +18 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/types.js +1 -1
- package/dist/core/user-attachment.js +26 -21
- package/dist/core/workflow-journal-store.d.ts +1 -1
- package/dist/core/workflow-run-store.d.ts +2 -0
- package/dist/core/workflow-run-store.js +6 -5
- package/dist/core/workflow-settled-run.d.ts +5 -0
- package/dist/core/workflow-settled-run.js +7 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +37 -9
- package/dist/engine/execution-env/node-execution-env.js +221 -22
- package/dist/engine/harness/agent-harness.d.ts +65 -18
- package/dist/engine/harness/agent-harness.js +90 -23
- package/dist/engine/harness/messages.d.ts +4 -3
- package/dist/engine/harness/messages.js +2 -2
- package/dist/engine/harness/types.d.ts +52 -7
- package/dist/engine/llm/media-removed.d.ts +14 -0
- package/dist/engine/llm/media-removed.js +9 -0
- package/dist/engine/llm/rejected-images.d.ts +35 -25
- package/dist/engine/llm/rejected-images.js +59 -10
- package/dist/engine/llm/types.d.ts +24 -3
- package/dist/engine/llm/types.js +7 -3
- package/dist/engine/loop/agent-loop.d.ts +6 -1
- package/dist/engine/loop/agent-loop.js +20 -11
- package/dist/engine/loop/types.d.ts +12 -3
- package/dist/engine/session/import-validate.js +7 -0
- package/dist/engine/session/parent-chain-guard.d.ts +3 -3
- package/dist/engine/session/parent-chain-guard.js +1 -1
- package/dist/engine/session/path-to-root.d.ts +18 -3
- package/dist/engine/session/path-to-root.js +15 -1
- package/dist/engine/session/repo-utils.d.ts +12 -1
- package/dist/engine/session/repo-utils.js +41 -0
- package/dist/engine/session/session.js +1 -1
- package/dist/engine/session/storage-base.d.ts +20 -0
- package/dist/engine/session/storage-base.js +28 -9
- package/dist/fixtures/index.d.ts +7 -5
- package/dist/fixtures/index.js +5 -3
- package/dist/index.d.ts +29 -18
- package/dist/index.js +19 -11
- package/dist/internal/harness-types.d.ts +2 -0
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/internal/llm.d.ts +2 -1
- package/dist/internal/llm.js +1 -0
- package/dist/orchestration/goal.d.ts +6 -2
- package/dist/orchestration/goal.js +6 -3
- package/dist/orchestration/run-workflow-tool.d.ts +14 -17
- package/dist/orchestration/run-workflow-tool.js +43 -50
- package/dist/orchestration/workflow-types.d.ts +2 -2
- package/dist/orchestration/workflow.d.ts +7 -0
- package/dist/orchestration/workflow.js +10 -12
- package/dist/stores/file/background-agent-store.js +18 -15
- package/dist/stores/file/checkpoint-store.d.ts +2 -0
- package/dist/stores/file/checkpoint-store.js +13 -9
- package/dist/stores/file/file-history-store.js +3 -2
- package/dist/stores/file/fs-atomic.d.ts +0 -22
- package/dist/stores/file/fs-atomic.js +0 -17
- package/dist/stores/file/index.d.ts +7 -12
- package/dist/stores/file/index.js +25 -12
- package/dist/stores/file/ledger-tuning.d.ts +23 -0
- package/dist/stores/file/ledger-tuning.js +21 -0
- package/dist/stores/file/mailbox-store.js +42 -22
- package/dist/stores/file/memory-store.js +3 -2
- package/dist/stores/file/permission-rule-adopt.js +24 -21
- package/dist/stores/file/permission-rule-store.js +6 -3
- package/dist/stores/file/session-policy-store.js +3 -2
- package/dist/stores/file/session-store.d.ts +26 -7
- package/dist/stores/file/session-store.js +59 -35
- package/dist/stores/file/tool-result-store.d.ts +11 -0
- package/dist/stores/file/tool-result-store.js +57 -3
- package/dist/stores/file/usage-window-store.js +3 -2
- package/dist/stores/file/workflow-journal-store.d.ts +0 -2
- package/dist/stores/file/workflow-journal-store.js +3 -18
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/stores/file/workflow-run-store.js +15 -10
- package/dist/tools/fs/bash-program-position.d.ts +3 -2
- package/dist/tools/fs/bash-program-position.js +7 -7
- package/dist/tools/fs/dead-cwd.d.ts +5 -5
- package/dist/tools/fs/dead-cwd.js +4 -11
- package/dist/tools/fs/fs-bash-background-text.d.ts +6 -0
- package/dist/tools/fs/fs-bash-background-text.js +6 -0
- package/dist/tools/fs/fs-bash.d.ts +3 -18
- package/dist/tools/fs/fs-bash.js +37 -124
- package/dist/tools/fs/fs-pdf.js +8 -6
- package/dist/tools/fs/fs-read.js +2 -2
- package/dist/tools/fs/fs-shared.d.ts +28 -3
- package/dist/tools/fs/fs-shared.js +15 -0
- package/dist/tools/fs/index.d.ts +1 -1
- package/dist/tools/fs/index.js +4 -14
- package/dist/tools/fs/pdf.d.ts +4 -4
- package/dist/tools/fs/pdf.js +6 -6
- package/dist/tools/fs/read-deny-home.js +8 -1
- package/dist/tools/fs/read-deny.d.ts +26 -2
- package/dist/tools/fs/read-deny.js +9 -2
- package/dist/tools/fs/read-floor.d.ts +13 -5
- package/dist/tools/fs/read-floor.js +206 -2
- package/dist/tools/fs/removal-targets.js +2 -2
- package/dist/tools/fs/search.d.ts +3 -2
- package/dist/tools/fs/search.js +6 -6
- package/dist/tools/fs/shell-read-argv.d.ts +4 -2
- package/dist/tools/fs/shell-read-argv.js +14 -3
- package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
- package/dist/tools/fs/shell-read-bindings.js +148 -68
- package/dist/tools/fs/shell-read-check.js +20 -4
- package/dist/tools/fs/shell-read-establish.js +25 -9
- package/dist/tools/fs/shell-read-functions.js +2 -2
- package/dist/tools/fs/shell-read-identity.d.ts +3 -1
- package/dist/tools/fs/shell-read-identity.js +4 -2
- package/dist/tools/fs/shell-read-judge.d.ts +7 -1
- package/dist/tools/fs/shell-read-judge.js +1 -1
- package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
- package/dist/tools/fs/shell-read-object-path.js +119 -0
- package/dist/tools/fs/shell-read-plan.d.ts +8 -0
- package/dist/tools/fs/shell-read-plan.js +47 -30
- package/dist/tools/fs/shell-read-start.d.ts +66 -13
- package/dist/tools/fs/shell-read-start.js +89 -17
- package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
- package/dist/tools/fs/shell-read-workdir.js +31 -8
- package/dist/tools/monitor.d.ts +8 -7
- package/dist/tools/monitor.js +12 -10
- package/dist/tools/worktree.d.ts +5 -1
- package/dist/tools/worktree.js +20 -17
- package/package.json +6 -3
- package/test/export-surface.snapshot.json +112 -42
- package/wire-changes/core-stores-sql@7.61.0.json +480 -0
- package/wire-changes/core-stores-sql@7.62.0.json +30 -0
- package/wire-changes/core@7.61.0.json +4405 -0
- package/wire-changes/core@7.62.0.json +2181 -0
- package/wire-changes/mods-kernel@7.61.0.json +65 -0
- package/wire-changes/mods-kernel@7.62.0.json +42 -0
- package/wire-changes/primitives@7.61.0.json +30 -0
- package/wire-changes/primitives@7.62.0.json +30 -0
- package/dist/core/consolidate-scope.d.ts +0 -93
- package/dist/core/consolidate-scope.js +0 -98
- package/dist/core/runner/image-removed-seat.d.ts +0 -12
- package/dist/core/runner/image-removed-seat.js +0 -19
- package/dist/core/runner/memory-consolidation.d.ts +0 -109
- package/dist/core/runner/memory-consolidation.js +0 -251
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one wording of a media block that left the model's view of a request while the transcript keeps it. A block leaves
|
|
3
|
+
* for one of two reasons ({@link MEDIA_REMOVED_REASONS}): the provider refused the request because an image in it could
|
|
4
|
+
* not be processed (`engine/llm/rejected-images.ts`), or the request's media budget had no room left for it (the request
|
|
5
|
+
* trim, `core/media-byte-cap.ts`). Either way the block's slot holds the line {@link mediaRemovedPlaceholder} writes, and
|
|
6
|
+
* the person hears it under the one code `context.media_removed`, whose `detail.reason` is the same word.
|
|
7
|
+
*/
|
|
8
|
+
/** The `errorKind` a provider's image refusal carries (`AssistantMessage.errorKind`). */
|
|
9
|
+
export declare const IMAGE_REFUSAL_KIND = "image_unprocessable";
|
|
10
|
+
/** Why a media block left the request view — `context.media_removed` `detail.reason`, closed. */
|
|
11
|
+
export declare const MEDIA_REMOVED_REASONS: readonly ["rejected_by_provider", "media_budget"];
|
|
12
|
+
export type MediaRemovedReason = (typeof MEDIA_REMOVED_REASONS)[number];
|
|
13
|
+
/** The text that stands in for the `ordinal`-th (1-based) block of its `type` in its message, removed for `reason`. */
|
|
14
|
+
export declare function mediaRemovedPlaceholder(reason: MediaRemovedReason, type: "image" | "document", ordinal: number): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const IMAGE_REFUSAL_KIND = "image_unprocessable";
|
|
2
|
+
export const MEDIA_REMOVED_REASONS = Object.freeze(["rejected_by_provider", "media_budget"]);
|
|
3
|
+
const WHY = Object.freeze({
|
|
4
|
+
rejected_by_provider: `rejected by provider: ${IMAGE_REFUSAL_KIND}`,
|
|
5
|
+
media_budget: "over the request media budget — re-read the file if you still need to see it",
|
|
6
|
+
});
|
|
7
|
+
export function mediaRemovedPlaceholder(reason, type, ordinal) {
|
|
8
|
+
return `[${type} ${ordinal} removed: ${WHY[reason]}]`;
|
|
9
|
+
}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* the same objects, and a view with no marker is the same array — the same transcript yields the same request bytes.
|
|
14
|
-
*
|
|
15
|
-
* The transcript keeps the images: a later reader of the session sees what was read, and every request built from it
|
|
16
|
-
* — the next turn, a resumed session, a compaction summary — reads the same record and removes the same images.
|
|
17
|
-
*/
|
|
18
|
-
/** The `errorKind` a provider's image refusal carries (`AssistantMessage.errorKind`). */
|
|
19
|
-
export declare const IMAGE_REFUSAL_KIND = "image_unprocessable";
|
|
20
|
-
/** The text that stands in for the `ordinal`-th image (1-based) of a carrier the provider refused an image of. */
|
|
21
|
-
export declare function rejectedImagePlaceholder(ordinal: number): string;
|
|
1
|
+
import { IMAGE_REFUSAL_KIND } from "./media-removed.js";
|
|
2
|
+
export { IMAGE_REFUSAL_KIND };
|
|
3
|
+
/** The `errorKind` a provider's refusal of one tool's input schema carries (`AssistantMessage.errorKind`, beside
|
|
4
|
+
* `refusedTool`). */
|
|
5
|
+
export declare const TOOL_SCHEMA_REFUSAL_KIND = "tool_schema_refused";
|
|
6
|
+
/** The schema a tool whose input schema the provider refused travels with: an object that names no parameter (the
|
|
7
|
+
* reference's replacement, `X5t` (cli309.js:264190)). */
|
|
8
|
+
export declare const REFUSED_TOOL_SCHEMA: Readonly<{
|
|
9
|
+
type: "object";
|
|
10
|
+
}>;
|
|
11
|
+
/** How many tools of one transcript the tool view sends without their schema (the reference's bound, the same coordinate). */
|
|
12
|
+
export declare const REFUSED_TOOL_SCHEMAS_MAX = 8;
|
|
22
13
|
/** Is this message a turn the provider failed because an image in the request could not be processed — the live
|
|
23
14
|
* failure or its persisted record? */
|
|
24
15
|
export declare function isImageRefusal(message: unknown): boolean;
|
|
16
|
+
/** The tool a turn the provider failed over that tool's input schema names (the live failure or its persisted record);
|
|
17
|
+
* undefined for any other message. */
|
|
18
|
+
export declare function refusedToolOf(message: unknown): string | undefined;
|
|
19
|
+
/** Is this message a marker of either part — what leaves the message view? */
|
|
20
|
+
export declare function isRequestPartRefusal(message: unknown): boolean;
|
|
25
21
|
/** One carrier whose images a marker removed: the marker, the carrier (both the view's input objects), how many, and
|
|
26
22
|
* the refusal's own time — the one identity a refusal keeps across its live failure, its persisted record and every
|
|
27
23
|
* rebuilt copy of either (the record is minted with the failure's timestamp). */
|
|
@@ -34,13 +30,27 @@ export interface RejectedImageRemoval {
|
|
|
34
30
|
/** A refusal's identity ({@link RejectedImageRemoval.refusalAt}). */
|
|
35
31
|
export declare function imageRefusalAt(message: unknown): number;
|
|
36
32
|
/**
|
|
37
|
-
* The
|
|
38
|
-
* the images of
|
|
39
|
-
* an image to remove.
|
|
33
|
+
* The message view of `messages` under every refusal marker they hold ({@link isRequestPartRefusal}): each marker removed,
|
|
34
|
+
* and the images of an image marker's carrier replaced. `removals` lists, in order, the carriers emptied — empty when no
|
|
35
|
+
* image marker found an image to remove.
|
|
40
36
|
*/
|
|
41
|
-
export declare function
|
|
37
|
+
export declare function removeRefusedRequestParts<T>(messages: readonly T[]): {
|
|
42
38
|
messages: T[];
|
|
43
39
|
removals: RejectedImageRemoval[];
|
|
44
40
|
};
|
|
45
41
|
/** Does `marker`, standing in `messages`, remove images in their request view — was there a carrier left for it? */
|
|
46
42
|
export declare function imageRefusalRemoves(messages: readonly unknown[], marker: object): boolean;
|
|
43
|
+
/** The tools whose schemas `messages` refused and the tool view replaces: in the order the transcript refused them, each
|
|
44
|
+
* once, external-protocol tools only, at most {@link REFUSED_TOOL_SCHEMAS_MAX}. */
|
|
45
|
+
export declare function refusedToolSchemas(messages: readonly unknown[]): string[];
|
|
46
|
+
/** The tool view of `tools` under `messages`' tool-schema refusals: each refused tool ({@link refusedToolSchemas}) with
|
|
47
|
+
* {@link REFUSED_TOOL_SCHEMA} for its parameters, every other tool the same object; with nothing refused, the same array. */
|
|
48
|
+
export declare function withoutRefusedToolSchemas<T extends {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly parameters: unknown;
|
|
51
|
+
}>(tools: readonly T[] | undefined, messages: readonly unknown[]): T[] | undefined;
|
|
52
|
+
/** Does `marker`, standing in `messages`, change the tool view of `tools` — does it name a mounted tool whose schema no
|
|
53
|
+
* earlier marker already replaced, within the transcript's bound? */
|
|
54
|
+
export declare function toolSchemaRefusalReplaces(messages: readonly unknown[], marker: object, tools: readonly {
|
|
55
|
+
readonly name: string;
|
|
56
|
+
}[] | undefined): boolean;
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { protocolOf } from "../../core/protocol-table.js";
|
|
2
|
+
import { IMAGE_REFUSAL_KIND, mediaRemovedPlaceholder } from "./media-removed.js";
|
|
3
|
+
export { IMAGE_REFUSAL_KIND };
|
|
4
|
+
export const TOOL_SCHEMA_REFUSAL_KIND = "tool_schema_refused";
|
|
5
|
+
export const REFUSED_TOOL_SCHEMA = Object.freeze({ type: "object" });
|
|
6
|
+
export const REFUSED_TOOL_SCHEMAS_MAX = 8;
|
|
7
|
+
function refusalKindOf(message) {
|
|
8
|
+
const m = message;
|
|
9
|
+
return m?.role === "assistant" && m.isApiErrorMessage === true ? m.errorKind : undefined;
|
|
4
10
|
}
|
|
5
11
|
export function isImageRefusal(message) {
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
return refusalKindOf(message) === IMAGE_REFUSAL_KIND;
|
|
13
|
+
}
|
|
14
|
+
export function refusedToolOf(message) {
|
|
15
|
+
if (refusalKindOf(message) !== TOOL_SCHEMA_REFUSAL_KIND)
|
|
16
|
+
return undefined;
|
|
17
|
+
const tool = message.refusedTool;
|
|
18
|
+
return typeof tool === "string" && tool.length > 0 ? tool : undefined;
|
|
19
|
+
}
|
|
20
|
+
export function isRequestPartRefusal(message) {
|
|
21
|
+
return isImageRefusal(message) || refusedToolOf(message) !== undefined;
|
|
8
22
|
}
|
|
9
23
|
export function imageRefusalAt(message) {
|
|
10
24
|
const at = message?.timestamp;
|
|
@@ -22,21 +36,23 @@ function imageCount(message) {
|
|
|
22
36
|
}
|
|
23
37
|
function withoutImages(message) {
|
|
24
38
|
let ordinal = 0;
|
|
25
|
-
const content = message.content.map((block) => block?.type === "image" ? { type: "text", text:
|
|
39
|
+
const content = message.content.map((block) => block?.type === "image" ? { type: "text", text: mediaRemovedPlaceholder("rejected_by_provider", "image", ++ordinal) } : block);
|
|
26
40
|
return { ...message, content };
|
|
27
41
|
}
|
|
28
|
-
export function
|
|
29
|
-
if (!messages.some(
|
|
42
|
+
export function removeRefusedRequestParts(messages) {
|
|
43
|
+
if (!messages.some(isRequestPartRefusal))
|
|
30
44
|
return { messages: messages, removals: [] };
|
|
31
45
|
const out = [];
|
|
32
46
|
const carriers = [];
|
|
33
47
|
const removals = [];
|
|
34
48
|
for (const m of messages) {
|
|
35
|
-
if (!
|
|
49
|
+
if (!isRequestPartRefusal(m)) {
|
|
36
50
|
out.push(m);
|
|
37
51
|
carriers.push(undefined);
|
|
38
52
|
continue;
|
|
39
53
|
}
|
|
54
|
+
if (!isImageRefusal(m))
|
|
55
|
+
continue;
|
|
40
56
|
for (let j = out.length - 1; j >= 0; j--) {
|
|
41
57
|
const images = imageCount(out[j]);
|
|
42
58
|
if (images === 0)
|
|
@@ -50,5 +66,38 @@ export function removeRejectedImages(messages) {
|
|
|
50
66
|
return { messages: out, removals };
|
|
51
67
|
}
|
|
52
68
|
export function imageRefusalRemoves(messages, marker) {
|
|
53
|
-
return
|
|
69
|
+
return removeRefusedRequestParts(messages).removals.some((r) => r.marker === marker);
|
|
70
|
+
}
|
|
71
|
+
function schemaReplaceable(tool) {
|
|
72
|
+
return protocolOf(tool) !== undefined;
|
|
73
|
+
}
|
|
74
|
+
export function refusedToolSchemas(messages) {
|
|
75
|
+
const out = [];
|
|
76
|
+
for (const m of messages) {
|
|
77
|
+
const tool = refusedToolOf(m);
|
|
78
|
+
if (tool === undefined || !schemaReplaceable(tool) || out.includes(tool))
|
|
79
|
+
continue;
|
|
80
|
+
if (out.length === REFUSED_TOOL_SCHEMAS_MAX)
|
|
81
|
+
break;
|
|
82
|
+
out.push(tool);
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
export function withoutRefusedToolSchemas(tools, messages) {
|
|
87
|
+
if (tools === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
const refused = refusedToolSchemas(messages);
|
|
90
|
+
if (refused.length === 0 || !tools.some((t) => refused.includes(t.name)))
|
|
91
|
+
return tools;
|
|
92
|
+
return tools.map((t) => (refused.includes(t.name) ? { ...t, parameters: { ...REFUSED_TOOL_SCHEMA } } : t));
|
|
93
|
+
}
|
|
94
|
+
export function toolSchemaRefusalReplaces(messages, marker, tools) {
|
|
95
|
+
const tool = refusedToolOf(marker);
|
|
96
|
+
if (tool === undefined || tools?.some((t) => t.name === tool) !== true)
|
|
97
|
+
return false;
|
|
98
|
+
const at = messages.indexOf(marker);
|
|
99
|
+
if (at < 0)
|
|
100
|
+
return false;
|
|
101
|
+
const before = refusedToolSchemas(messages.slice(0, at));
|
|
102
|
+
return !before.includes(tool) && refusedToolSchemas(messages.slice(0, at + 1)).includes(tool);
|
|
54
103
|
}
|
|
@@ -406,7 +406,15 @@ export interface UserMessage {
|
|
|
406
406
|
* custom Brain); the session import door strips it (an imported frame is an ordinary engine note).
|
|
407
407
|
*/
|
|
408
408
|
attachment?: UserMessageAttachment;
|
|
409
|
+
/** {@link RowRewrittenBy} */
|
|
410
|
+
rewrittenBy?: RowRewrittenBy;
|
|
409
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* The extensions whose rewrite of this row the conversation kept (a `session.append` handler's, at the row's admission),
|
|
414
|
+
* in the order they handed it on — absent ⇒ the row is as its writer made it. Attribution only: never sent to a provider
|
|
415
|
+
* (brains rebuild wire messages field by field; {@link stripEngineMetadata} strips it for a custom Brain).
|
|
416
|
+
*/
|
|
417
|
+
export type RowRewrittenBy = readonly string[];
|
|
410
418
|
/** What the engine found an attachment to be: the four Read lanes, a directory, or bytes the host supplied. */
|
|
411
419
|
export type UserAttachmentKind = "text" | "notebook" | "image" | "pdf" | "directory" | "client_text" | "client_image";
|
|
412
420
|
/** Who held the bytes: the engine read a path in its workspace, or the host supplied text / an image. */
|
|
@@ -608,8 +616,16 @@ export interface AssistantMessage {
|
|
|
608
616
|
* brain boundary off the provider's envelope (`brain/provider-dialect.ts`, `IMAGE_UNPROCESSABLE_RE`). Such a turn —
|
|
609
617
|
* live, or as the transcript's persisted record of it — is the request view's instruction to remove the images of
|
|
610
618
|
* the newest earlier message still carrying any (`engine/llm/rejected-images.ts`, at `convertToLlm`); the loop
|
|
611
|
-
* re-sends the turn without them.
|
|
612
|
-
|
|
619
|
+
* re-sends the turn without them.
|
|
620
|
+
*
|
|
621
|
+
* `"tool_schema_refused"`: the provider refused the request because of one tool's input schema, and located that
|
|
622
|
+
* tool ({@link refusedTool}) — classified at the brain boundary off the provider's envelope (`brain/provider-dialect.ts`,
|
|
623
|
+
* the tool-schema rows). Such a turn, live or as its persisted record, is the request view's instruction to send that
|
|
624
|
+
* tool — when an external protocol (MCP, A2A) provides it — with an empty object schema in every request built from a
|
|
625
|
+
* transcript it stands in (`engine/llm/rejected-images.ts`); the loop re-sends the turn so. */
|
|
626
|
+
errorKind?: "length_empty" | "degenerate" | "input_too_long" | "image_unprocessable" | "tool_schema_refused";
|
|
627
|
+
/** With `errorKind: "tool_schema_refused"`: the engine name of the tool whose input schema the provider refused. */
|
|
628
|
+
refusedTool?: string;
|
|
613
629
|
/** The AUTHORITATIVE-NEGATIVE twin of `errorKind: "input_too_long"`: the brain's provenance-checked
|
|
614
630
|
* classifier RAN and ruled this failure NOT input-too-long (wrong status family, or the provider's
|
|
615
631
|
* own envelope states a different error). The loop's prompt-too-long recovery treats it as a hard
|
|
@@ -670,6 +686,8 @@ export interface AssistantMessage {
|
|
|
670
686
|
* the 2-downgrade stop-loss. Additive — absent everywhere else (incl. the dynamicCut shape).
|
|
671
687
|
*/
|
|
672
688
|
staticReasoningCut?: true;
|
|
689
|
+
/** {@link RowRewrittenBy} */
|
|
690
|
+
rewrittenBy?: RowRewrittenBy;
|
|
673
691
|
timestamp: number;
|
|
674
692
|
}
|
|
675
693
|
export interface ToolResultMessage<TDetails = unknown> {
|
|
@@ -679,6 +697,8 @@ export interface ToolResultMessage<TDetails = unknown> {
|
|
|
679
697
|
content: (TextContent | ImageContent | DocumentContent)[];
|
|
680
698
|
details?: TDetails;
|
|
681
699
|
isError: boolean;
|
|
700
|
+
/** {@link RowRewrittenBy} */
|
|
701
|
+
rewrittenBy?: RowRewrittenBy;
|
|
682
702
|
timestamp: number;
|
|
683
703
|
}
|
|
684
704
|
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
@@ -687,7 +707,8 @@ export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
|
687
707
|
* serializing a Context to an external wire. The eight fields (`enginePrefixChars`/`engineSegments`/
|
|
688
708
|
* `engineMinted`/`provenance`/`actor`/`engineNoteKey`/`attachment`/`runOrigin`) are INTERNAL coordination between the engine's
|
|
689
709
|
* minting side and its consumers (permission classifier, compaction summarizer, prompt suggestions,
|
|
690
|
-
* multiplayer attribution, attachment delivery, run attribution) — they must never reach a provider payload
|
|
710
|
+
* multiplayer attribution, attachment delivery, run attribution) — they must never reach a provider payload; so is
|
|
711
|
+
* {@link RowRewrittenBy}, on every role. The built-in brains construct
|
|
691
712
|
* their own wire shapes and are immune; a CUSTOM Brain that whole-object-serializes messages
|
|
692
713
|
* (`JSON.stringify(context.messages)`) would leak them — run the array through this projection first.
|
|
693
714
|
*/
|
package/dist/engine/llm/types.js
CHANGED
|
@@ -50,9 +50,13 @@ export function renderUserAttachmentView(m, a, cap) {
|
|
|
50
50
|
}
|
|
51
51
|
export function stripEngineMetadata(messages) {
|
|
52
52
|
return messages.map((m) => {
|
|
53
|
-
if (m.role !== "user")
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (m.role !== "user") {
|
|
54
|
+
if (m.rewrittenBy === undefined)
|
|
55
|
+
return m;
|
|
56
|
+
const { rewrittenBy: _r, ...kept } = m;
|
|
57
|
+
return kept;
|
|
58
|
+
}
|
|
59
|
+
const { enginePrefixChars: _a, engineSegments: _b, engineMinted: _c, provenance: _d, actor: _e, engineNoteKey: _f, attachment: _g, runOrigin: _h, rewrittenBy: _i, ...rest } = m;
|
|
56
60
|
return rest;
|
|
57
61
|
});
|
|
58
62
|
}
|
|
@@ -38,6 +38,8 @@ export type LoopContinueReason =
|
|
|
38
38
|
| "reactive_compact_retry"
|
|
39
39
|
/** The provider refused an image; the request view removed it and the turn was re-sent in-turn. */
|
|
40
40
|
| "image_refusal_retry"
|
|
41
|
+
/** The provider refused one tool's input schema; the tool view emptied it and the turn was re-sent in-turn. */
|
|
42
|
+
| "tool_schema_refusal_retry"
|
|
41
43
|
/** ④b recovery: a `length`-stopped answer triggered a synthetic continue nudge for another turn. */
|
|
42
44
|
| "max_output_tokens_recovery"
|
|
43
45
|
/** S2 recovery (design/119): a `toolUse` stop with ZERO parseable tool calls got a retry nudge. */
|
|
@@ -69,7 +71,8 @@ export type LoopTerminalReason =
|
|
|
69
71
|
* budget is used up — the model believes it acted, nothing ran, and there is no more recovery budget
|
|
70
72
|
* left to try again. Before this reason existed, this case fell through to the generic no-more-work
|
|
71
73
|
* path and was reported as a plain `"completed"`, indistinguishable from a turn that genuinely had
|
|
72
|
-
* nothing left to do.
|
|
74
|
+
* nothing left to do. A Runner run reads this exit (and `truncated_output_exhausted`) as a `failed`
|
|
75
|
+
* terminal: `model.malformed_tool_use_exhausted` / `model.truncated_output_exhausted`.
|
|
73
76
|
*
|
|
74
77
|
* `malformedToolUseRetries` 数的是**连续**畸形轮:任何带可解析工具调用的轮(即工具真的跑了)都把它
|
|
75
78
|
* 清零,与上游「重试至多两次、成功即复位」同形——"exhausted" 说的是"刚刚连续 maxRetries + 1 个轮次
|
|
@@ -131,6 +134,8 @@ export interface TrailingToolBatchSettlement {
|
|
|
131
134
|
/** A prompt run's seam beyond its prompts (the trailing-batch settlement); a prompt is delivered at its `message_end`. */
|
|
132
135
|
export interface RunAgentLoopSeams {
|
|
133
136
|
settle?: TrailingToolBatchSettlement;
|
|
137
|
+
/** The prompts RECORD a turn a person's bare refusal ended: they owe no model turn (a drain point's queued input still continues the run). */
|
|
138
|
+
endsAwaitingUser?: true;
|
|
134
139
|
}
|
|
135
140
|
/** The last assistant message of `messages` when at least one of its tool calls has no tool result after it. */
|
|
136
141
|
export declare function findUnansweredToolBatch(messages: readonly AgentMessage[]): AssistantMessage | undefined;
|
|
@@ -9,7 +9,7 @@ import { remoteWords } from "../../core/protocol-http-auth.js";
|
|
|
9
9
|
import { types } from "node:util";
|
|
10
10
|
import { admitToolResultMediaBlocks, firstUnprocessedOverTarget, toolResultMediaBlocks } from "../../core/image-admission.js";
|
|
11
11
|
import { resolveImageProcessor } from "../../core/image-downsample.js";
|
|
12
|
-
import { IMAGE_REFUSAL_KIND, imageRefusalRemoves } from "../llm/rejected-images.js";
|
|
12
|
+
import { IMAGE_REFUSAL_KIND, imageRefusalRemoves, toolSchemaRefusalReplaces, withoutRefusedToolSchemas } from "../llm/rejected-images.js";
|
|
13
13
|
const IMAGE_REFUSAL_RETRIES = 3;
|
|
14
14
|
function appendTextDeltaToAssistantMessage(message, contentIndex, delta) {
|
|
15
15
|
const content = [...message.content];
|
|
@@ -77,7 +77,7 @@ export async function runAgentLoop(prompts, context, config, emit, signal, strea
|
|
|
77
77
|
}
|
|
78
78
|
const delivered = typeof prompts === "function" ? await prompts() : prompts;
|
|
79
79
|
if (delivered.length > 0)
|
|
80
|
-
state.hasMoreToolCalls = true;
|
|
80
|
+
state.hasMoreToolCalls = seams?.endsAwaitingUser !== true;
|
|
81
81
|
state.context.messages.push(...delivered);
|
|
82
82
|
state.newMessages.push(...delivered);
|
|
83
83
|
for (const prompt of delivered) {
|
|
@@ -370,18 +370,27 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
|
|
|
370
370
|
raiseFatalCancellation(executor);
|
|
371
371
|
let interruptedInRecovery = false;
|
|
372
372
|
let imageRetries = 0;
|
|
373
|
-
const
|
|
373
|
+
const refusalChangesRequest = () => message.errorKind === IMAGE_REFUSAL_KIND
|
|
374
|
+
? imageRetries < IMAGE_REFUSAL_RETRIES && imageRefusalRemoves(state.context.messages, message)
|
|
375
|
+
: toolSchemaRefusalReplaces(state.context.messages, message, state.context.tools);
|
|
376
|
+
const resendWithoutRefusedParts = async () => {
|
|
374
377
|
while (message.stopReason === "error" &&
|
|
375
|
-
message.errorKind === IMAGE_REFUSAL_KIND &&
|
|
376
378
|
!signal?.aborted &&
|
|
377
379
|
!turnController.signal.aborted &&
|
|
378
380
|
isBlankFailureContent(message) &&
|
|
379
381
|
executor.admittedCount === 0 &&
|
|
380
|
-
imageRetries < IMAGE_REFUSAL_RETRIES &&
|
|
381
382
|
state.context.messages[state.context.messages.length - 1] === message &&
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
383
|
+
refusalChangesRequest()) {
|
|
384
|
+
if (message.errorKind === IMAGE_REFUSAL_KIND)
|
|
385
|
+
imageRetries++;
|
|
386
|
+
else if (message.refusedTool !== undefined) {
|
|
387
|
+
try {
|
|
388
|
+
state.config.onToolSchemaRefused?.({ tool: message.refusedTool, refusalAt: message.timestamp });
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
trace?.({ kind: "continue", reason: message.errorKind === IMAGE_REFUSAL_KIND ? "image_refusal_retry" : "tool_schema_refusal_retry" });
|
|
385
394
|
executor = new StreamToolExecutor(state.context, state.config, turnController.signal, emit);
|
|
386
395
|
try {
|
|
387
396
|
({ message, cutAtSettle: cutAtFinalSettle } = await streamAssistantResponse(state.context, state.config, turnController.signal, withhold?.sink ?? emit, streamFn, runtime, executor, staticReasoningCutDowngrade));
|
|
@@ -392,7 +401,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
|
|
|
392
401
|
raiseFatalCancellation(executor);
|
|
393
402
|
}
|
|
394
403
|
};
|
|
395
|
-
await
|
|
404
|
+
await resendWithoutRefusedParts();
|
|
396
405
|
{
|
|
397
406
|
if (ptl) {
|
|
398
407
|
const detect = ptlDetect;
|
|
@@ -445,7 +454,7 @@ async function runTurnPhases(state, signal, turnController, publishSeat, retract
|
|
|
445
454
|
}
|
|
446
455
|
}
|
|
447
456
|
}
|
|
448
|
-
await
|
|
457
|
+
await resendWithoutRefusedParts();
|
|
449
458
|
const unrecoveredPtlFailureUnderInterrupt = ptl !== undefined &&
|
|
450
459
|
message.stopReason === "error" &&
|
|
451
460
|
ptlDetect(message) &&
|
|
@@ -719,7 +728,7 @@ async function streamAssistantResponse(context, config, signal, emit, streamFn,
|
|
|
719
728
|
systemPrompt: context.systemPrompt,
|
|
720
729
|
...(context.systemBlocks ? { systemBlocks: context.systemBlocks } : {}),
|
|
721
730
|
messages: llmMessages,
|
|
722
|
-
tools: context.tools,
|
|
731
|
+
tools: withoutRefusedToolSchemas(context.tools, context.messages),
|
|
723
732
|
};
|
|
724
733
|
const streamFunction = resolveAgentCoreStreamFn(runtime, streamFn);
|
|
725
734
|
const resolvedApiKey = (config.getApiKey ? await config.getApiKey(config.model.provider) : undefined) || config.apiKey;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Static, TSchema } from "typebox";
|
|
2
|
-
import type { AssistantMessage, AssistantMessageEvent, DocumentContent, ImageContent, Message, Model, SimpleStreamOptions, StreamFn as LlmStreamFn, TextContent, Tool, ToolResultMessage } from "../llm/index.js";
|
|
2
|
+
import type { AssistantMessage, AssistantMessageEvent, DocumentContent, ImageContent, Message, Model, RowRewrittenBy, SimpleStreamOptions, StreamFn as LlmStreamFn, TextContent, Tool, ToolResultMessage } from "../llm/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Stream function used by the agent loop.
|
|
5
5
|
*
|
|
@@ -232,8 +232,9 @@ export interface LoopPromptTooLongRecovery {
|
|
|
232
232
|
* ends the run — the pre-④b behavior).
|
|
233
233
|
*
|
|
234
234
|
* RB-258: when the budget IS configured and runs out on a still-`length` turn, the loop ends with the
|
|
235
|
-
* dedicated terminal reason `truncated_output_exhausted` (visible on the `LoopTraceSink
|
|
236
|
-
* plain `completed` — the caller can tell "kept
|
|
235
|
+
* dedicated terminal reason `truncated_output_exhausted` (visible on the `LoopTraceSink`; a Runner run reads it as a
|
|
236
|
+
* `failed` terminal, `model.truncated_output_exhausted`) instead of a plain `completed` — the caller can tell "kept
|
|
237
|
+
* hitting the output cap" apart from "actually finished".
|
|
237
238
|
* The OFF case is unchanged (no budget ⇒ nothing to exhaust ⇒ still `completed`).
|
|
238
239
|
*/
|
|
239
240
|
export interface LoopTruncatedOutputRecovery {
|
|
@@ -585,6 +586,12 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
585
586
|
toolCallId: string;
|
|
586
587
|
error: unknown;
|
|
587
588
|
}) => void;
|
|
589
|
+
/** Told once per refusal, when the loop re-sends a turn the provider refused over `tool`'s input schema (the tool view then
|
|
590
|
+
* sends it with an empty object schema); `refusalAt` = the refusal's timestamp. Advisory: a throwing sink changes nothing. */
|
|
591
|
+
onToolSchemaRefused?: (refusal: {
|
|
592
|
+
tool: string;
|
|
593
|
+
refusalAt: number;
|
|
594
|
+
}) => void;
|
|
588
595
|
/**
|
|
589
596
|
* Told, once per executed call, of the media blocks the tool-result seat refused (`admitToolResultMedia`, the last step
|
|
590
597
|
* of the post-execution half): each already stands in the result as a text placeholder naming the tool and the refusal,
|
|
@@ -660,6 +667,8 @@ export interface CustomMessage<T = unknown> {
|
|
|
660
667
|
* derived views (auto-mode window, compaction serializer) present it under a neutral engine label,
|
|
661
668
|
* never `[user]` authority. Set by the INJECTOR at mint time; absent ⇒ verbatim user-lane render. */
|
|
662
669
|
provenance?: "engine-note";
|
|
670
|
+
/** {@link RowRewrittenBy} */
|
|
671
|
+
rewrittenBy?: RowRewrittenBy;
|
|
663
672
|
/** Millisecond timestamp for transcript ordering. */
|
|
664
673
|
timestamp: number;
|
|
665
674
|
}
|
|
@@ -265,6 +265,13 @@ function normalizeEngineProvenanceStamp(message, preserveActorAssertions = false
|
|
|
265
265
|
if (message === null || typeof message !== "object")
|
|
266
266
|
return;
|
|
267
267
|
const m = message;
|
|
268
|
+
if (m.rewrittenBy !== undefined) {
|
|
269
|
+
const r = m.rewrittenBy;
|
|
270
|
+
if (Array.isArray(r) && r.length > 0 && r.every((n) => typeof n === "string" && n.length > 0))
|
|
271
|
+
m.rewrittenBy = [...r];
|
|
272
|
+
else
|
|
273
|
+
delete m.rewrittenBy;
|
|
274
|
+
}
|
|
268
275
|
if (m.role !== "user")
|
|
269
276
|
return;
|
|
270
277
|
if (m.actor !== undefined) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The memory of one walk up a session log's parent chain, shared by `getPathToRoot`, the resume-at ancestry scan and the fork-point judge `settledForkOptions` (the import validator still keeps its own loop — #2253). An entry the
|
|
3
|
-
* walk stands on twice means the parent links loop, which no ancestry can contain: the walk is refused
|
|
4
|
-
* `
|
|
3
|
+
* walk stands on twice means the parent links loop, which no ancestry can contain: the stored log does not hold together, so the walk is refused
|
|
4
|
+
* `corrupt_session` naming that entry instead of being followed again, and saying what a person can do (start a new session, or fork from an entry the
|
|
5
5
|
* loop does not touch). One guard per walk.
|
|
6
6
|
*/
|
|
7
7
|
export declare class ParentChainGuard {
|
|
8
8
|
private readonly stepped;
|
|
9
|
-
/** Records that the walk now stands on `id`; throws `
|
|
9
|
+
/** Records that the walk now stands on `id`; throws `corrupt_session` when it already stood there. */
|
|
10
10
|
stepOnto(id: string): void;
|
|
11
11
|
}
|
|
@@ -3,7 +3,7 @@ export class ParentChainGuard {
|
|
|
3
3
|
stepped = new Set();
|
|
4
4
|
stepOnto(id) {
|
|
5
5
|
if (this.stepped.has(id)) {
|
|
6
|
-
throw new SessionError("
|
|
6
|
+
throw new SessionError("corrupt_session", `Entry ${id} is its own ancestor (parent chain cycles at ${id}) — start a new session, or fork from an entry above the loop`);
|
|
7
7
|
}
|
|
8
8
|
this.stepped.add(id);
|
|
9
9
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SessionError, type ReplayLoss } from "../harness/types.js";
|
|
2
|
+
export type { ReplayLoss };
|
|
1
3
|
/** The fork point a store copies up to: `{}` is the whole log, `{ entryId, position: "at" }` the path from the root down to that entry. It is the answer
|
|
2
4
|
* `settledForkOptions` gives, and the question `selectForkRows` takes. */
|
|
3
5
|
export interface ForkPoint {
|
|
@@ -10,10 +12,23 @@ export interface ParentLinks<T> {
|
|
|
10
12
|
idOf(row: T): string;
|
|
11
13
|
parentOf(row: T): string | null | undefined;
|
|
12
14
|
}
|
|
15
|
+
/** The one sentence of a {@link ReplayLoss}, for every refusal and notice that states it. */
|
|
16
|
+
export declare function replayLossText(loss: ReplayLoss): string;
|
|
17
|
+
/**
|
|
18
|
+
* The refusal of a walk that met a parent the log does not hold: `childId` names `missingParentId` as its parent. The stored log does not hold
|
|
19
|
+
* together, so it is `corrupt_session`; it says where it broke, and `replayLoss` — what the replay that loaded the log dropped, when it dropped
|
|
20
|
+
* any — is the evidence that the missing parent may be one of the records the replay could not read.
|
|
21
|
+
*/
|
|
22
|
+
export declare class LineageBreak extends SessionError {
|
|
23
|
+
readonly missingParentId: string;
|
|
24
|
+
readonly childId: string;
|
|
25
|
+
readonly replayLoss?: ReplayLoss | undefined;
|
|
26
|
+
constructor(missingParentId: string, childId: string, replayLoss?: ReplayLoss | undefined);
|
|
27
|
+
}
|
|
13
28
|
/**
|
|
14
29
|
* The one walk up a log's parent chain: the rows from the root down to `start`, root first. The chain ends at a row with no parent, or at `floorId`
|
|
15
|
-
* (a bounded window's root — its parent is not required to exist). A parent the log does not hold is
|
|
16
|
-
* returns to a row it already stood on is refused by the shared guard
|
|
30
|
+
* (a bounded window's root — its parent is not required to exist). A parent the log does not hold is a {@link LineageBreak} naming it, a chain that
|
|
31
|
+
* returns to a row it already stood on is refused by the shared guard — both `corrupt_session`; neither is followed.
|
|
17
32
|
*/
|
|
18
33
|
export declare function pathToRoot<T>(start: T, links: ParentLinks<T>, floorId?: string | null): T[];
|
|
19
34
|
/** How a log row is read by `selectForkRows`: its entry id and its parent's (`null` = a root). */
|
|
@@ -28,7 +43,7 @@ export interface ForkRowShape<R> {
|
|
|
28
43
|
* branches stay behind) and the leaf is that entry. The rows keep their order.
|
|
29
44
|
*
|
|
30
45
|
* Refusals are the engine's, word for word: a fork point the log does not hold is `invalid_fork_target`, a parent missing part-way up the path (an empty
|
|
31
|
-
* parent id included) or a chain that returns to a row it stood on is `
|
|
46
|
+
* parent id included) or a chain that returns to a row it stood on is `corrupt_session` (the sentence `getPathToRoot` gives), and a fork point that
|
|
32
47
|
* names an entry with a `position` other than `at` is refused `invalid_fork_target` — rows are copied only for the point the judge answers. A point with
|
|
33
48
|
* no entry id is the whole-log form whatever else it carries, as `getEntriesToFork` reads it.
|
|
34
49
|
*/
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { SessionError } from "../harness/types.js";
|
|
2
2
|
import { ParentChainGuard } from "./parent-chain-guard.js";
|
|
3
|
+
export function replayLossText(loss) {
|
|
4
|
+
return `${loss.dropped} of ${loss.total} records skipped as corrupt`;
|
|
5
|
+
}
|
|
6
|
+
export class LineageBreak extends SessionError {
|
|
7
|
+
missingParentId;
|
|
8
|
+
childId;
|
|
9
|
+
replayLoss;
|
|
10
|
+
constructor(missingParentId, childId, replayLoss) {
|
|
11
|
+
super("corrupt_session", `Entry ${missingParentId} not found — ${childId} names it as its parent and the log does not hold it${replayLoss !== undefined ? ` (${replayLossText(replayLoss)})` : ""}`);
|
|
12
|
+
this.missingParentId = missingParentId;
|
|
13
|
+
this.childId = childId;
|
|
14
|
+
this.replayLoss = replayLoss;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
3
17
|
export function pathToRoot(start, links, floorId) {
|
|
4
18
|
const path = [];
|
|
5
19
|
const chain = new ParentChainGuard();
|
|
@@ -15,7 +29,7 @@ export function pathToRoot(start, links, floorId) {
|
|
|
15
29
|
break;
|
|
16
30
|
const parent = parentId === "" ? undefined : links.read(parentId);
|
|
17
31
|
if (parent === undefined) {
|
|
18
|
-
throw new
|
|
32
|
+
throw new LineageBreak(parentId, id);
|
|
19
33
|
}
|
|
20
34
|
current = parent;
|
|
21
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionError, type SessionHead, type SessionLogMark, type SessionMetadata, type SessionRowExpectation, type SessionStorage, type SessionTreeEntry } from "../harness/types.js";
|
|
1
|
+
import { SessionError, type SessionHead, type SessionLogMark, type SessionMetadata, type SessionPlacementRecord, type SessionRowExpectation, type SessionStorage, type SessionTreeEntry } from "../harness/types.js";
|
|
2
2
|
import type { Session } from "../harness/types.js";
|
|
3
3
|
export declare function createSessionId(): string;
|
|
4
4
|
/** The {@link SessionMetadata.incarnation} cell for a write laying a row's metadata down — the bundled repos' ONE mint point.
|
|
@@ -52,6 +52,17 @@ export declare function importRowCells(sessionId: string, owner: unknown, existi
|
|
|
52
52
|
* there but is neither (a blank string included) cannot be read as anyone's, and reading it as anonymous would admit every
|
|
53
53
|
* principal — the row is refused as `corrupt_session` instead (a read fault, never an answer). */
|
|
54
54
|
export declare function readOwnerCell(raw: unknown, sessionId: string): string | null;
|
|
55
|
+
/** The one decoding of a stored {@link SessionMetadata.placement} cell read back by a backend (header line, SQL column): `undefined` is no
|
|
56
|
+
* placement; an object whose `kind` is a placement kind, whose `placedAt` is a finite number and whose `scope`, `handle`, `rootSessionId`
|
|
57
|
+
* and `parentSessionId` are each a string when there is the tuple, answered as stored (a tuple missing a join half is a legal tuple,
|
|
58
|
+
* read by consumers as incomplete; a member this reader does not know is an additive one an older reader tolerates). Anything else —
|
|
59
|
+
* no object, `null` (a backend whose absent cell reads `null` maps it to `undefined` first), a kind outside the set, a member of the
|
|
60
|
+
* wrong form — is neither a placement nor none: the row is refused `corrupt_session`, naming the cell and never the value. */
|
|
61
|
+
export declare function readPlacementCell(raw: unknown, sessionId: string): SessionPlacementRecord | undefined;
|
|
62
|
+
/** The placement cell a write that lays a row down records: `given` (`undefined` is none), its `placedAt` stamped with `now` when it names
|
|
63
|
+
* none, judged by the very judgment {@link readPlacementCell} reads back with — so no row is written that a reader would refuse. A tuple
|
|
64
|
+
* that fails it is refused before anything is written, `config.invalid_argument`, naming the cell and never the value. */
|
|
65
|
+
export declare function placementCellToWrite(given: unknown, sessionId: string, now: number): SessionPlacementRecord | undefined;
|
|
55
66
|
/** A fork lands on a row OTHER than its source: onto its own id it would mint a new occupant over the source's transcript and erase the lineage that carries the source's records. */
|
|
56
67
|
export declare function assertForkTarget(sourceId: string, targetId: string | undefined): void;
|
|
57
68
|
/** A fork row's cells, minted from the SOURCE row as it stands at fork time — the same row the fork copies its history from: the lineage
|
|
@@ -2,6 +2,7 @@ import { SessionError, } from "../harness/types.js";
|
|
|
2
2
|
import { StoredSession } from "./session.js";
|
|
3
3
|
import { uuidv7 } from "./uuid.js";
|
|
4
4
|
import { principalNameFault, principalNameOf } from "../../core/principal-name.js";
|
|
5
|
+
import { receiptRefusal } from "../../core/own-property-receipt.js";
|
|
5
6
|
import { randomUUID } from "node:crypto";
|
|
6
7
|
export function createSessionId() {
|
|
7
8
|
return uuidv7();
|
|
@@ -107,6 +108,46 @@ export function readOwnerCell(raw, sessionId) {
|
|
|
107
108
|
return name;
|
|
108
109
|
throw new SessionError("corrupt_session", `session ${sessionId}'s owner cell holds ${notAnOwnerShape(raw)} — neither an owner nor anonymous; refusing to read the row`);
|
|
109
110
|
}
|
|
111
|
+
const PLACEMENT_KINDS = ["subagent"];
|
|
112
|
+
const PLACEMENT_STRING_MEMBERS = ["scope", "parentSessionId", "rootSessionId", "handle"];
|
|
113
|
+
function isPlacementKind(raw) {
|
|
114
|
+
return PLACEMENT_KINDS.some((kind) => kind === raw);
|
|
115
|
+
}
|
|
116
|
+
function placementFaultSentence(sessionId, fault) {
|
|
117
|
+
const { cell, held, expected } = fault;
|
|
118
|
+
const shape = held === null ? "null" : Array.isArray(held) ? "an array" : held === "" ? "an empty string" : `a ${typeof held}`;
|
|
119
|
+
return `session ${sessionId}'s ${cell} ${held === undefined ? "is not there" : `holds ${shape}`} — ${expected}`;
|
|
120
|
+
}
|
|
121
|
+
function judgePlacementCell(raw) {
|
|
122
|
+
if (raw === undefined)
|
|
123
|
+
return { placement: undefined };
|
|
124
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
125
|
+
return { fault: { cell: "placement cell", held: raw, expected: "a placement is a tuple (an object) or not there at all" } };
|
|
126
|
+
const cell = { ...raw };
|
|
127
|
+
const { kind, placedAt } = cell;
|
|
128
|
+
if (!isPlacementKind(kind))
|
|
129
|
+
return { fault: { cell: "placement.kind", held: kind, expected: `a placement names one of its kinds (${PLACEMENT_KINDS.join(", ")})` } };
|
|
130
|
+
for (const member of PLACEMENT_STRING_MEMBERS) {
|
|
131
|
+
if (cell[member] !== undefined && typeof cell[member] !== "string")
|
|
132
|
+
return { fault: { cell: `placement.${member}`, held: cell[member], expected: "a string when there" } };
|
|
133
|
+
}
|
|
134
|
+
if (typeof placedAt !== "number" || !Number.isFinite(placedAt))
|
|
135
|
+
return { fault: { cell: "placement.placedAt", held: placedAt, expected: "a finite number (epoch ms)" } };
|
|
136
|
+
return { placement: { ...cell, kind, placedAt } };
|
|
137
|
+
}
|
|
138
|
+
export function readPlacementCell(raw, sessionId) {
|
|
139
|
+
const judged = judgePlacementCell(raw);
|
|
140
|
+
if ("fault" in judged)
|
|
141
|
+
throw new SessionError("corrupt_session", `${placementFaultSentence(sessionId, judged.fault)}; refusing to read the row`);
|
|
142
|
+
return judged.placement;
|
|
143
|
+
}
|
|
144
|
+
export function placementCellToWrite(given, sessionId, now) {
|
|
145
|
+
const tuple = typeof given === "object" && given !== null && !Array.isArray(given);
|
|
146
|
+
const judged = judgePlacementCell(tuple ? { ...given, placedAt: given["placedAt"] ?? now } : given);
|
|
147
|
+
if ("fault" in judged)
|
|
148
|
+
throw receiptRefusal(`${placementFaultSentence(sessionId, judged.fault)}; refused before anything was written`);
|
|
149
|
+
return judged.placement;
|
|
150
|
+
}
|
|
110
151
|
export function assertForkTarget(sourceId, targetId) {
|
|
111
152
|
if (targetId === sourceId)
|
|
112
153
|
throw new SessionError("invalid_fork_target", `cannot fork session ${sourceId} onto its own id — fork into a new id`);
|