@sema-agent/core 7.71.1 → 7.73.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 +500 -0
- package/dist/agents/cross-session-ref.d.ts +2 -2
- package/dist/agents/cross-session-ref.js +7 -2
- package/dist/agents/inherited-tool-pool.d.ts +30 -2
- package/dist/agents/inherited-tool-pool.js +53 -7
- package/dist/agents/parked-resume-drive.d.ts +10 -0
- package/dist/agents/parked-resume-drive.js +9 -0
- package/dist/agents/retain-ledger.d.ts +3 -0
- package/dist/agents/send-message-tool.js +7 -2
- package/dist/agents/send-user-message-tool.d.ts +12 -0
- package/dist/agents/send-user-message-tool.js +67 -0
- package/dist/agents/subagent-steps.d.ts +9 -0
- package/dist/agents/subagent-steps.js +38 -0
- package/dist/agents/subagent.d.ts +2 -0
- package/dist/agents/subagent.js +47 -12
- package/dist/agents/verify.js +23 -7
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.js +14 -9
- package/dist/brain/open-responses.js +4 -5
- package/dist/brain/openai.js +30 -23
- package/dist/brain/stream-engine.js +159 -151
- package/dist/core/a2a.d.ts +24 -3
- package/dist/core/a2a.js +27 -8
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/agent-state.d.ts +28 -7
- package/dist/core/agent-state.js +19 -6
- package/dist/core/allow-entry.js +3 -3
- package/dist/core/approval-object.d.ts +7 -3
- package/dist/core/approval-object.js +30 -9
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/checkpoint-features.d.ts +16 -5
- package/dist/core/checkpoint-features.js +35 -6
- package/dist/core/checkpoint-rekey.d.ts +1 -1
- package/dist/core/checkpoint-rekey.js +6 -1
- package/dist/core/checkpoint-requirements.d.ts +23 -3
- package/dist/core/checkpoint-requirements.js +5 -1
- package/dist/core/checkpoint-row-verdict.d.ts +1 -1
- package/dist/core/checkpoint-row-verdict.js +10 -4
- package/dist/core/checkpoint-store.d.ts +24 -2
- package/dist/core/checkpoint-store.js +1 -0
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/effective-path-target.d.ts +19 -0
- package/dist/core/effective-path-target.js +95 -38
- package/dist/core/engine-capabilities.d.ts +5 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +34 -23
- package/dist/core/engine-version.js +1 -1
- package/dist/core/entries-not-applied.d.ts +19 -7
- package/dist/core/entries-not-applied.js +33 -1
- package/dist/core/file-history-store.d.ts +15 -4
- package/dist/core/file-history-store.js +53 -23
- package/dist/core/gate-fold.js +3 -1
- package/dist/core/governance-codes.d.ts +10 -1
- package/dist/core/governance-codes.js +17 -5
- package/dist/core/hooks.d.ts +3 -0
- package/dist/core/hooks.js +1 -0
- package/dist/core/host-instance.d.ts +23 -0
- package/dist/core/host-instance.js +69 -0
- package/dist/core/instruction-preview.d.ts +63 -0
- package/dist/core/instruction-preview.js +406 -0
- package/dist/core/judged-read.d.ts +57 -0
- package/dist/core/judged-read.js +1 -0
- package/dist/core/leg-budget.d.ts +26 -0
- package/dist/core/leg-budget.js +9 -0
- package/dist/core/leg-identity.d.ts +51 -1
- package/dist/core/leg-identity.js +45 -2
- package/dist/core/manager-launch-check.d.ts +48 -0
- package/dist/core/manager-launch-check.js +64 -0
- package/dist/core/mcp-call-meta.d.ts +2 -2
- package/dist/core/mcp-host-seat.d.ts +5 -0
- package/dist/core/mcp-host-seat.js +7 -1
- package/dist/core/mcp-injection-drop.d.ts +20 -10
- package/dist/core/mcp-injection-drop.js +9 -3
- package/dist/core/mcp-server-spec.d.ts +2 -1
- package/dist/core/mcp.js +3 -1
- package/dist/core/member-outcome.d.ts +3 -2
- package/dist/core/member-outcome.js +1 -1
- package/dist/core/memory-engine/deletion-record.d.ts +46 -0
- package/dist/core/memory-engine/deletion-record.js +96 -0
- package/dist/core/memory-engine/engine.js +24 -16
- package/dist/core/memory-engine/file-backend.js +7 -5
- package/dist/core/memory-engine/index.d.ts +1 -1
- package/dist/core/memory-engine/index.js +1 -1
- package/dist/core/memory-engine/layout.js +6 -4
- package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
- package/dist/core/memory-engine/projection-ledger.js +1 -1
- package/dist/core/memory-engine/scope-contract.d.ts +69 -11
- package/dist/core/memory-engine/scope-contract.js +99 -34
- package/dist/core/memory-engine/sync-client.js +26 -6
- package/dist/core/memory-engine/sync.d.ts +20 -2
- package/dist/core/memory-engine/sync.js +18 -17
- package/dist/core/mode-policy.d.ts +21 -6
- package/dist/core/mode-policy.js +15 -6
- package/dist/core/mounted-mcp.d.ts +7 -2
- package/dist/core/mounted-mcp.js +10 -1
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/param-rule-reach.d.ts +8 -3
- package/dist/core/param-rule-reach.js +9 -1
- package/dist/core/parent-spec-seat.d.ts +13 -1
- package/dist/core/parent-spec-seat.js +18 -0
- package/dist/core/peer-registration.d.ts +52 -0
- package/dist/core/peer-registration.js +37 -0
- package/dist/core/peer-seat.d.ts +3 -1
- package/dist/core/peer-seat.js +3 -3
- package/dist/core/peer-task-store.d.ts +365 -0
- package/dist/core/peer-task-store.js +682 -0
- package/dist/core/permission-rule-consent.js +6 -11
- package/dist/core/permission-rule-model.d.ts +27 -0
- package/dist/core/permission-rule-model.js +34 -6
- package/dist/core/permission-rule-provider.d.ts +35 -33
- package/dist/core/permission-rule-provider.js +38 -295
- package/dist/core/permission-rule-store.d.ts +181 -8
- package/dist/core/permission-rule-store.js +420 -17
- package/dist/core/permission-rule-sync.js +15 -1
- package/dist/core/project-seat.d.ts +55 -0
- package/dist/core/project-seat.js +96 -0
- package/dist/core/protocol-http-auth.d.ts +3 -2
- package/dist/core/protocol-http-auth.js +26 -18
- package/dist/core/remote-env.d.ts +4 -4
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/run-ledger-seat.d.ts +66 -0
- package/dist/core/run-ledger-seat.js +70 -0
- package/dist/core/run-ledger.d.ts +332 -0
- package/dist/core/run-ledger.js +550 -0
- package/dist/core/runner/chain-mismatch.d.ts +32 -0
- package/dist/core/runner/chain-mismatch.js +29 -0
- package/dist/core/runner/changes-history.d.ts +1 -0
- package/dist/core/runner/changes-history.js +2 -2
- package/dist/core/runner/checkpoint-scope.d.ts +13 -3
- package/dist/core/runner/checkpoint-scope.js +12 -4
- package/dist/core/runner/construction-doors.js +6 -0
- package/dist/core/runner/contracts.d.ts +22 -3
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/file-history-restore.d.ts +3 -1
- package/dist/core/runner/file-history-restore.js +9 -6
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/loaded-skills.d.ts +2 -0
- package/dist/core/runner/loaded-skills.js +10 -0
- package/dist/core/runner/nested-memory-lane.d.ts +22 -5
- package/dist/core/runner/nested-memory-lane.js +91 -30
- package/dist/core/runner/person-path-rows.d.ts +23 -20
- package/dist/core/runner/person-path-rows.js +82 -18
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +105 -90
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +5 -3
- package/dist/core/runner/prepare-context-lane.js +1 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +6 -0
- package/dist/core/runner/prepare-execution-env.d.ts +3 -3
- package/dist/core/runner/prepare-file-history.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +10 -2
- package/dist/core/runner/prepare-hands-readface.js +36 -22
- package/dist/core/runner/prepare-inherited-gate.d.ts +8 -5
- package/dist/core/runner/prepare-inherited-gate.js +14 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -2
- package/dist/core/runner/prepare-memory-engine-session.js +2 -2
- package/dist/core/runner/prepare-memory.js +3 -15
- package/dist/core/runner/prepare-project-context.d.ts +1 -1
- package/dist/core/runner/prepare-project-context.js +3 -7
- package/dist/core/runner/prepare-protocol-tools.d.ts +5 -0
- package/dist/core/runner/prepare-protocol-tools.js +2 -2
- package/dist/core/runner/prepare-run-refs.d.ts +1 -1
- package/dist/core/runner/prepare-run-refs.js +3 -2
- package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
- package/dist/core/runner/prepare-suspend-saga.js +4 -2
- package/dist/core/runner/prepare-task.js +50 -37
- package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
- package/dist/core/runner/prepare-turn-wiring.js +2 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +5 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -4
- package/dist/core/runner/read-session-changes.js +1 -1
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-checkpoint-screen.d.ts +8 -7
- package/dist/core/runner/resume-checkpoint-screen.js +7 -6
- package/dist/core/runner/resume-review-outcome.d.ts +3 -0
- package/dist/core/runner/resume-review-outcome.js +24 -1
- package/dist/core/runner/rewind-files.js +3 -2
- package/dist/core/runner/run-harness-handlers.js +3 -0
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +9 -2
- package/dist/core/runner/run-notification-lane.js +20 -1
- package/dist/core/runner/run-settle-and-teardown.js +21 -12
- package/dist/core/runner/run-stop-and-final-verify.js +6 -0
- package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
- package/dist/core/runner/runtask.d.ts +6 -2
- package/dist/core/runner/runtask.js +21 -9
- package/dist/core/runner/shell-env-withheld.d.ts +3 -2
- package/dist/core/runner/shell-env-withheld.js +1 -2
- package/dist/core/runner/stop-tail-notice.d.ts +10 -2
- package/dist/core/runner/stop-tail-notice.js +9 -2
- package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
- package/dist/core/runner/stream-settle-backstop.js +1 -0
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +10 -1
- package/dist/core/runner/terminal-account.js +23 -3
- package/dist/core/runner/tool-face-overlay.d.ts +2 -11
- package/dist/core/runner/tool-face-overlay.js +39 -0
- package/dist/core/runner/trim-stretch.js +7 -2
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner-deps.d.ts +13 -10
- package/dist/core/scheduler.d.ts +47 -7
- package/dist/core/scheduler.js +19 -7
- package/dist/core/secret-env.d.ts +60 -37
- package/dist/core/secret-env.js +45 -48
- package/dist/core/sensitive-path-policy.js +14 -7
- package/dist/core/session-checkout.d.ts +3 -0
- package/dist/core/session-checkout.js +1 -0
- package/dist/core/session-store.d.ts +12 -6
- package/dist/core/session-store.js +26 -6
- package/dist/core/session.d.ts +31 -8
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +17 -0
- package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
- package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
- package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
- package/dist/core/store-contracts/session-store-contract.js +87 -3
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
- package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
- package/dist/core/task-event.d.ts +11 -3
- package/dist/core/task-notification.d.ts +97 -10
- package/dist/core/task-notification.js +129 -5
- package/dist/core/task-registry-shared.d.ts +12 -1
- package/dist/core/task-registry-shared.js +3 -1
- package/dist/core/task-registry-workflow.d.ts +1 -1
- package/dist/core/task-registry-workflow.js +9 -1
- package/dist/core/task-registry.d.ts +39 -2
- package/dist/core/task-registry.js +76 -12
- package/dist/core/task-result.d.ts +13 -0
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +11 -3
- package/dist/core/task-spec.d.ts +57 -23
- package/dist/core/tool-catalog-entries.js +4 -0
- package/dist/core/tool-face-reader.js +1 -1
- package/dist/core/tool-face.d.ts +7 -0
- package/dist/core/tool-face.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +5 -3
- package/dist/core/tool-mount-facts.js +4 -3
- package/dist/core/tool-mount-plan.d.ts +7 -3
- package/dist/core/tool-mount-plan.js +11 -5
- package/dist/core/tool-mount-static.d.ts +2 -2
- package/dist/core/tool-mount-static.js +28 -14
- package/dist/core/tool-registry.d.ts +33 -1
- package/dist/core/tool-registry.js +33 -0
- package/dist/core/tool-result-store.d.ts +19 -2
- package/dist/core/tool-result-store.js +51 -2
- package/dist/core/tool-roster.d.ts +16 -0
- package/dist/core/tool-roster.js +6 -0
- package/dist/core/tool-spec.d.ts +13 -4
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.js +1 -1
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +89 -29
- package/dist/core/wiring-manifest.js +44 -4
- package/dist/core/workflow-journal-store.d.ts +53 -10
- package/dist/core/workflow-journal-store.js +27 -4
- package/dist/core/workflow-run-store-contract.js +16 -0
- package/dist/core/workflow-run-store.d.ts +9 -7
- package/dist/core/workflow-run-store.js +4 -1
- package/dist/engine/execution-env/node-execution-env.js +3 -1
- package/dist/engine/harness/messages.d.ts +1 -1
- package/dist/engine/harness/messages.js +2 -1
- package/dist/engine/harness/types.d.ts +24 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +5 -7
- package/dist/engine/loop/types.d.ts +2 -0
- package/dist/engine/lsp/node-lsp-manager.js +2 -1
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +15 -2
- package/dist/engine/session/session.js +35 -5
- package/dist/index.d.ts +27 -12
- package/dist/index.js +20 -8
- package/dist/orchestration/run-workflow-tool.js +40 -32
- package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
- package/dist/orchestration/workflow-park-adoption.js +47 -12
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +30 -6
- package/dist/orchestration/workflow.js +117 -54
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/stores/file/adoption/marker.d.ts +2 -27
- package/dist/stores/file/adoption/marker.js +12 -0
- package/dist/stores/file/index.d.ts +1 -1
- package/dist/stores/file/index.js +1 -1
- package/dist/stores/file/permission-rule-store.d.ts +3 -1
- package/dist/stores/file/permission-rule-store.js +0 -1
- package/dist/stores/file/workflow-journal-store.d.ts +16 -3
- package/dist/stores/file/workflow-journal-store.js +93 -5
- package/dist/stores/file/workflow-run-store.d.ts +1 -1
- package/dist/tools/artifact/artifact-tool.js +11 -6
- package/dist/tools/fs/file-read-check.d.ts +45 -11
- package/dist/tools/fs/file-read-check.js +200 -57
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- package/dist/tools/fs/judged-reads.d.ts +51 -0
- package/dist/tools/fs/judged-reads.js +68 -0
- package/dist/tools/fs/read-deny-home.d.ts +1 -1
- package/dist/tools/fs/read-deny-home.js +5 -5
- package/dist/tools/fs/read-deny.d.ts +33 -8
- package/dist/tools/fs/read-deny.js +114 -25
- package/dist/tools/fs/safety.d.ts +12 -1
- package/dist/tools/fs/safety.js +16 -3
- package/dist/tools/fs/shell-read-check.d.ts +25 -5
- package/dist/tools/fs/shell-read-check.js +100 -15
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +34 -14
- package/dist/tools/fs/shell-read-judge.d.ts +13 -1
- package/dist/tools/fs/shell-read-judge.js +26 -7
- package/dist/tools/fs/shell-read-plan.d.ts +5 -0
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/scheduler-store-move.d.ts +74 -0
- package/dist/tools/scheduler-store-move.js +103 -0
- package/dist/tools/scheduler-tools.d.ts +43 -29
- package/dist/tools/scheduler-tools.js +161 -118
- package/package.json +2 -2
- package/test/export-surface.snapshot.json +173 -3
- package/wire-changes/answers/core-stores-sql@7.72.0.json +12 -0
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core@7.72.0.json +84 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/mods-kernel@7.72.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/primitives@7.72.0.json +6 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/wiki-gate@7.72.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/core-stores-sql@7.72.0.json +215 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core@7.72.0.json +2426 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/mods-kernel@7.72.0.json +147 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/primitives@7.72.0.json +143 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/wiki-gate@7.72.0.json +145 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { InMemorySessionStorage, SessionError, StoredSession } from "../internal/harness.js";
|
|
2
|
+
import { legBudgetSnapshot, resourceTotalOf } from "./leg-budget.js";
|
|
3
|
+
import { createModelFileReader } from "../tools/fs/fs-read.js";
|
|
4
|
+
import { compileReadDeny, inheritSessionReadFileState, readDenyBuiltinConfigOf, resolveContainmentFace, seedReadFileStateFromTranscript } from "../tools/fs/index.js";
|
|
5
|
+
import { whereItsAnsweredPrefixLeads } from "../tools/fs/read-deny-home.js";
|
|
6
|
+
import { resolveKey } from "../tools/fs/safety.js";
|
|
7
|
+
import { unionAddOnly } from "./child-clamp-seats.js";
|
|
8
|
+
import { enterConfigDoor } from "./config-refusal-input.js";
|
|
9
|
+
import { legCallTargetStamp, validatePath } from "./effective-path-target.js";
|
|
10
|
+
import { SeenFileRegistry } from "./existing-target.js";
|
|
11
|
+
import { legTaskIdOf } from "./leg-identity.js";
|
|
12
|
+
import { bindPathRules, createHeadLeads } from "./path-rule-binding.js";
|
|
13
|
+
import { assertStringArraySeat, screenReadDenySeat } from "./read-face-seats.js";
|
|
14
|
+
import { judgeReadFloorKept, readFloorSeat } from "../tools/fs/read-floor.js";
|
|
15
|
+
import { ENV_PURPOSE_UNSUPPORTED, hasDestroy } from "./remote-env.js";
|
|
16
|
+
import { dataRootSpellings } from "./sensitive-path-policy.js";
|
|
17
|
+
import { sessionRootOf } from "./session-checkout.js";
|
|
18
|
+
import { createSyntheticServedReadJudge } from "./synthetic-read-verdict.js";
|
|
19
|
+
import { readEntrySpec } from "./task-start-judge.js";
|
|
20
|
+
import { readMember, thrownText } from "./thrown-value.js";
|
|
21
|
+
import { TOOL_CATALOG_ENTRIES, toolFace } from "./tool-catalog-entries.js";
|
|
22
|
+
import { toolPolicyPathRules } from "./tool-policy.js";
|
|
23
|
+
import { chainPolicyOnLeg } from "./runner/child-tree.js";
|
|
24
|
+
import { createToolOccurrenceTable } from "./runner/tool-occurrence.js";
|
|
25
|
+
import { delegatedTreeOwner, judgedLegOf, judgedOwnerSeat, judgeRowForTree, legRowRefusal, readRootOccupant, readStandsAsJudged, rowNotTheOneJudged } from "./runner/delegation-owner.js";
|
|
26
|
+
import { legCallerPlaces } from "./runner/leg-caller-places.js";
|
|
27
|
+
import { readLegInternals } from "./runner/leg-frame.js";
|
|
28
|
+
import { receiveLeg } from "./runner/leg-receipt.js";
|
|
29
|
+
import { instructionFamilyOf, primeInstructionReading, } from "./runner/nested-memory-lane.js";
|
|
30
|
+
import { seatInstructionLane } from "./runner/prepare-turn-wiring.js";
|
|
31
|
+
import { createPermissionRuleLanes } from "./runner/permission-rule-lanes.js";
|
|
32
|
+
import { pathTablesCompile, personPathRowsOfTask, readRootsOver } from "./runner/person-path-rows.js";
|
|
33
|
+
import { prepareExecutionEnv } from "./runner/prepare-execution-env.js";
|
|
34
|
+
import { readBlockLeg, readBlockOf } from "./runner/read-block-judge.js";
|
|
35
|
+
import { createRollbackStack } from "./runner/rollback-stack.js";
|
|
36
|
+
import { readStateFromTranscript } from "./runner/session-file-state-replay.js";
|
|
37
|
+
import { legReadCarrier, readSeatLeaf } from "./runner/session-read-file-states.js";
|
|
38
|
+
import { createLiveSessionRules, createSessionRulePolicy } from "./runner/session-rule-policy.js";
|
|
39
|
+
import { taskStartDoors } from "./runner/task-start-doors.js";
|
|
40
|
+
import { resolveTaskRootCanonical } from "./runner/task-root-canonical.js";
|
|
41
|
+
import { settleTeardownLeg } from "./runner/teardown-bounded.js";
|
|
42
|
+
import { thrownFailureOf } from "./runner/terminal-account.js";
|
|
43
|
+
import { valveLeaves } from "../agents/tool-filter.js";
|
|
44
|
+
export const EXTERNAL_INCLUDE_POST_APPROVAL_BLOCKS = Object.freeze(["outside_roots", "rule_denied", "approval_required", "admission_unknown"]);
|
|
45
|
+
const NOOP = () => undefined;
|
|
46
|
+
export async function previewInstructionsOf(seats, spec, internals) {
|
|
47
|
+
try {
|
|
48
|
+
const bag = internals !== undefined ? enterConfigDoor("deps", () => readLegInternals(internals, "runTaskStream")) : undefined;
|
|
49
|
+
const request = readEntrySpec(spec, () => seats.deps.models).spec;
|
|
50
|
+
const silentDeps = { ...seats.deps, onNotice: NOOP, onError: NOOP, tracer: undefined };
|
|
51
|
+
const legInternals = {
|
|
52
|
+
...(enterConfigDoor("deps", () => readRootOccupant(bag, undefined, request.sessionId)) ?? {}),
|
|
53
|
+
receivedPeers: receiveLeg(request, silentDeps),
|
|
54
|
+
};
|
|
55
|
+
const start = taskStartDoors({ request, deps: silentDeps, sessions: seats.sessions, internals: legInternals });
|
|
56
|
+
const projectMemory = instructionFamilyOf(start.spec) === undefined ? "absent" : start.spec.projectMemory === "disabled" ? "disabled" : "on";
|
|
57
|
+
const nestedDecl = start.doors.nestedMemory;
|
|
58
|
+
const rows = rowReader(seats.sessions);
|
|
59
|
+
const existingSession = start.spec.sessionId !== undefined ? await previewSession(seats.sessions, rows, { ...start.spec, sessionId: start.spec.sessionId }, legInternals) : undefined;
|
|
60
|
+
const previewSessionId = start.spec.sessionId ?? "preview-instructions";
|
|
61
|
+
const previewRunId = "preview-instructions";
|
|
62
|
+
const previewTaskId = legTaskIdOf(start.spec, legInternals, previewSessionId);
|
|
63
|
+
const abortController = new AbortController();
|
|
64
|
+
if (start.spec.signal?.aborted)
|
|
65
|
+
abortController.abort();
|
|
66
|
+
const owned = [];
|
|
67
|
+
const rollback = createRollbackStack(NOOP);
|
|
68
|
+
let envPhase;
|
|
69
|
+
try {
|
|
70
|
+
envPhase = await prepareExecutionEnv({
|
|
71
|
+
deps: silentDeps,
|
|
72
|
+
spec: start.spec,
|
|
73
|
+
internals: legInternals,
|
|
74
|
+
resume: undefined,
|
|
75
|
+
placementRootResolved: previewSessionId,
|
|
76
|
+
sessionId: previewSessionId,
|
|
77
|
+
forgetOnThrow: async () => undefined,
|
|
78
|
+
rollback,
|
|
79
|
+
startsEnv: true,
|
|
80
|
+
purpose: "read_changes",
|
|
81
|
+
});
|
|
82
|
+
rollback.commit();
|
|
83
|
+
if (envPhase.ownedEnvSeat.current !== undefined)
|
|
84
|
+
owned.push(envPhase.ownedEnvSeat.current);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
await rollback.unwindAll();
|
|
88
|
+
if (readMember(err, "code") !== ENV_PURPOSE_UNSUPPORTED)
|
|
89
|
+
throw err;
|
|
90
|
+
envPhase = undefined;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const emptyContext = new StoredSession(new InMemorySessionStorage());
|
|
94
|
+
const previewLeg = {
|
|
95
|
+
harness: { getModel: () => start.doors.model },
|
|
96
|
+
session: { buildContext: () => (existingSession ?? emptyContext).buildContext() },
|
|
97
|
+
sessionId: previewSessionId,
|
|
98
|
+
runId: previewRunId,
|
|
99
|
+
announcedListingsRef: {},
|
|
100
|
+
frameReceipts: { listingSnapshotOwed: false },
|
|
101
|
+
hookIdentity: { taskId: previewTaskId, isDelegatedChild: start.delegation.isDelegatedChild },
|
|
102
|
+
};
|
|
103
|
+
const handsEnabled = envPhase !== undefined && envPhase.handsEnabled;
|
|
104
|
+
assertStringArraySeat(silentDeps.readDenyPatterns, "RunnerDeps.readDenyPatterns", "compiler-owned");
|
|
105
|
+
const readBlock = readBlockOf({ spec: start.spec, resume: undefined });
|
|
106
|
+
const liveReadFace = resolveContainmentFace({
|
|
107
|
+
kind: "read",
|
|
108
|
+
specFace: start.spec.readFace,
|
|
109
|
+
depsFace: silentDeps.readFace,
|
|
110
|
+
readOnlyMount: start.spec.handsReadOnly === true,
|
|
111
|
+
readBlock,
|
|
112
|
+
orgGoverned: silentDeps.permissionRuleStore?.partitions.org === true,
|
|
113
|
+
fullShellReachable: false,
|
|
114
|
+
});
|
|
115
|
+
const readDenyAdditions = unionAddOnly("readDenyPatterns", silentDeps.readDenyPatterns, start.spec.readDenyPatterns);
|
|
116
|
+
const readDenyBuiltinCfg = readDenyBuiltinConfigOf({ tiers: silentDeps.readDenyBuiltinTiers, exclude: silentDeps.readDenyBuiltinExclude });
|
|
117
|
+
if (!handsEnabled) {
|
|
118
|
+
if (readDenyAdditions.length > 0)
|
|
119
|
+
compileReadDeny(readDenyAdditions, "readDenyPatterns", { tiers: [] });
|
|
120
|
+
if (projectMemory !== "on" || nestedDecl === undefined)
|
|
121
|
+
return { ok: true, projectMemory };
|
|
122
|
+
const lane = seatInstructionLane({
|
|
123
|
+
declaration: nestedDecl,
|
|
124
|
+
signal: abortController.signal,
|
|
125
|
+
mark: undefined,
|
|
126
|
+
counts: undefined,
|
|
127
|
+
deps: silentDeps,
|
|
128
|
+
leg: () => previewLeg,
|
|
129
|
+
});
|
|
130
|
+
const instructions = await primeInstructionReading(lane, NOOP);
|
|
131
|
+
return { ok: true, projectMemory, ...(instructions !== undefined ? { instructions } : {}) };
|
|
132
|
+
}
|
|
133
|
+
const executionEnv = envPhase.executionEnv;
|
|
134
|
+
const taskRootFinal = existingSession !== undefined && start.spec.sessionId !== undefined
|
|
135
|
+
? await sessionRootOf({ env: executionEnv, session: existingSession, sessionId: start.spec.sessionId, baseRoot: envPhase.taskRootInitial, sessions: rows }, `Runner.previewInstructions: session "${start.spec.sessionId}" checkout cannot be resolved`)
|
|
136
|
+
: envPhase.taskRootInitial;
|
|
137
|
+
const { canonical: taskRootCanonical } = await resolveTaskRootCanonical({
|
|
138
|
+
env: executionEnv,
|
|
139
|
+
given: taskRootFinal,
|
|
140
|
+
onNotice: silentDeps.onNotice,
|
|
141
|
+
sessionId: previewSessionId,
|
|
142
|
+
runId: previewRunId,
|
|
143
|
+
});
|
|
144
|
+
assertStringArraySeat(start.spec.additionalDirectories, "TaskSpec.additionalDirectories", "strings");
|
|
145
|
+
assertStringArraySeat(start.spec.additionalReadDirectories, "TaskSpec.additionalReadDirectories", "strings");
|
|
146
|
+
const additionalRootsCanonical = [];
|
|
147
|
+
const additionalReadRootsCanonical = [];
|
|
148
|
+
const declaredAdditionalRoots = [];
|
|
149
|
+
const canonicalizeDirs = async (dirs, sink, declared) => {
|
|
150
|
+
for (const dir of dirs ?? []) {
|
|
151
|
+
if (!dir || !dir.trim())
|
|
152
|
+
continue;
|
|
153
|
+
const c = await executionEnv.canonicalPath(dir);
|
|
154
|
+
if (c.ok) {
|
|
155
|
+
sink.push(c.value);
|
|
156
|
+
declared?.push(Object.freeze({ directory: dir, canonical: c.value }));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
await canonicalizeDirs(start.spec.additionalDirectories, additionalRootsCanonical, declaredAdditionalRoots);
|
|
161
|
+
await canonicalizeDirs(start.spec.additionalReadDirectories, additionalReadRootsCanonical);
|
|
162
|
+
for (const a of [additionalRootsCanonical, additionalReadRootsCanonical])
|
|
163
|
+
a.splice(0, a.length, ...new Set(a));
|
|
164
|
+
const legHome = validatePath(executionEnv.homeDir, { intent: "validate-coordinate" });
|
|
165
|
+
const legAnchors = { root: taskRootCanonical, ...(legHome !== undefined ? { home: legHome } : {}) };
|
|
166
|
+
const callerPlaces = legCallerPlaces({ deps: silentDeps, spec: start.spec, recorded: undefined });
|
|
167
|
+
const onLeg = enterConfigDoor("deps", () => chainPolicyOnLeg({
|
|
168
|
+
leg: legAnchors,
|
|
169
|
+
chainTop: legAnchors,
|
|
170
|
+
placement: undefined,
|
|
171
|
+
chain: (legInternals.inheritedGate?.parentConstraints ?? []).map((c) => c.policy),
|
|
172
|
+
installations: { live: legInternals.inheritedGate?.pathRuleInstallations, seed: undefined },
|
|
173
|
+
rebase: (p) => p,
|
|
174
|
+
}));
|
|
175
|
+
const installedToolPolicy = onLeg.own(start.doors.lockedPreflight.toolPolicy);
|
|
176
|
+
const inheritedPolicies = (legInternals.inheritedGate?.parentConstraints ?? []).flatMap((c, i) => c.policy !== undefined ? [onLeg.chained(c.policy, i)] : []);
|
|
177
|
+
const headLeads = createHeadLeads((part) => whereItsAnsweredPrefixLeads(executionEnv, part));
|
|
178
|
+
let sessionRulePolicy;
|
|
179
|
+
let ownSessionRow;
|
|
180
|
+
if (silentDeps.sessionPolicyStore !== undefined && start.spec.sessionId !== undefined) {
|
|
181
|
+
const key = { sessionId: start.spec.sessionId, ...(start.spec.principal ? { principal: start.spec.principal } : {}) };
|
|
182
|
+
const seed = (await silentDeps.sessionPolicyStore.getRules(key.sessionId, key.principal)) ?? { rev: 0 };
|
|
183
|
+
ownSessionRow = seed;
|
|
184
|
+
sessionRulePolicy = createSessionRulePolicy({ seed, read: createLiveSessionRules(silentDeps.sessionPolicyStore, { ...key, seed }, { onUnreadable: NOOP, onEnforced: (r) => void (ownSessionRow = r) }) }, { env: executionEnv, rootPath: taskRootFinal, toolEffects: new Map(), anchors: legAnchors, onEarlierGrammar: NOOP });
|
|
185
|
+
}
|
|
186
|
+
const personRows = personPathRowsOfTask({
|
|
187
|
+
deps: silentDeps,
|
|
188
|
+
notices: { onUnread: NOOP, onRowsDropped: NOOP },
|
|
189
|
+
principal: start.spec.principal,
|
|
190
|
+
ids: { sessionId: previewSessionId, runId: previewRunId, taskId: previewTaskId },
|
|
191
|
+
root: taskRootFinal,
|
|
192
|
+
rootCanonical: taskRootCanonical,
|
|
193
|
+
leads: headLeads,
|
|
194
|
+
chainTop: legAnchors,
|
|
195
|
+
occurrences: createToolOccurrenceTable(),
|
|
196
|
+
signals: [abortController.signal, ...(start.spec.signal !== undefined ? [start.spec.signal] : [])],
|
|
197
|
+
seatsBeyond: {
|
|
198
|
+
session_rules: () => (ownSessionRow !== undefined ? { rules: ownSessionRow, unread: false } : undefined),
|
|
199
|
+
ancestor_session_rules: () => [],
|
|
200
|
+
skill_grants: () => [],
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
await personRows.prime();
|
|
204
|
+
const policyPathRows = toolPolicyPathRules([installedToolPolicy, ...inheritedPolicies], legAnchors);
|
|
205
|
+
const effectivePathDenyRules = policyPathRows.filter((r) => r.faces.length > 0 && r.behavior === "deny" && r.unanchored === undefined);
|
|
206
|
+
const canonicalizePersonDirs = async (dirs) => {
|
|
207
|
+
const out = [];
|
|
208
|
+
for (const d of dirs)
|
|
209
|
+
await canonicalizeDirs([d], out).catch(NOOP);
|
|
210
|
+
return out;
|
|
211
|
+
};
|
|
212
|
+
const compileTables = pathTablesCompile({
|
|
213
|
+
env: executionEnv,
|
|
214
|
+
additions: readDenyAdditions,
|
|
215
|
+
builtin: readDenyBuiltinCfg,
|
|
216
|
+
legRows: effectivePathDenyRules,
|
|
217
|
+
legReadAskRows: [],
|
|
218
|
+
leads: headLeads,
|
|
219
|
+
configRoots: callerPlaces.configRoots.dirs,
|
|
220
|
+
callerHomes: callerPlaces.homes.dirs,
|
|
221
|
+
canonicalize: canonicalizePersonDirs,
|
|
222
|
+
});
|
|
223
|
+
const floorRequired = screenReadDenySeat("readDenyFloorRequired", silentDeps.readDenyFloorRequired) === true;
|
|
224
|
+
const tables = await personRows.attachTables(async (person) => {
|
|
225
|
+
const compiled = await compileTables(person);
|
|
226
|
+
judgeReadFloorKept({ env: executionEnv, table: compiled.readDeny, floor: readFloorSeat(compiled.readDeny)?.(undefined), required: floorRequired, onNotice: NOOP });
|
|
227
|
+
return compiled;
|
|
228
|
+
});
|
|
229
|
+
if (projectMemory !== "on" || nestedDecl === undefined)
|
|
230
|
+
return { ok: true, projectMemory };
|
|
231
|
+
const { personDirectories } = readBlockLeg(readBlock);
|
|
232
|
+
const readRoots = readRootsOver({
|
|
233
|
+
own: () => [...additionalRootsCanonical, ...additionalReadRootsCanonical],
|
|
234
|
+
tables,
|
|
235
|
+
ready: personRows.tablesReady,
|
|
236
|
+
store: () => undefined,
|
|
237
|
+
onHeld: NOOP,
|
|
238
|
+
personDirectories,
|
|
239
|
+
});
|
|
240
|
+
const readFileState = new Map();
|
|
241
|
+
const seenFiles = new SeenFileRegistry();
|
|
242
|
+
if (existingSession !== undefined && start.spec.sessionId !== undefined) {
|
|
243
|
+
const judgeKey = async (path) => {
|
|
244
|
+
const rk = await readRoots.ready().then(() => resolveKey(executionEnv, taskRootCanonical, path, undefined, undefined, readRoots(), undefined, undefined, liveReadFace));
|
|
245
|
+
return rk.ok ? rk.key : undefined;
|
|
246
|
+
};
|
|
247
|
+
const carrier = await legReadCarrier({
|
|
248
|
+
resuming: false,
|
|
249
|
+
spec: start.spec,
|
|
250
|
+
sessionId: start.spec.sessionId,
|
|
251
|
+
seats: seats.readStates,
|
|
252
|
+
leaf: () => readSeatLeaf(existingSession),
|
|
253
|
+
getEntry: (id) => existingSession.getEntry(id),
|
|
254
|
+
});
|
|
255
|
+
if (carrier.from === "seat") {
|
|
256
|
+
await inheritSessionReadFileState(readFileState, carrier.state, judgeKey, seenFiles);
|
|
257
|
+
}
|
|
258
|
+
else if (carrier.from === "transcript") {
|
|
259
|
+
const prior = await existingSession.buildContext().catch(() => undefined);
|
|
260
|
+
const rebuilt = readStateFromTranscript(prior?.messages ?? []);
|
|
261
|
+
for (const rec of rebuilt.records) {
|
|
262
|
+
const rk = await judgeKey(rec.path);
|
|
263
|
+
if (rk === undefined)
|
|
264
|
+
continue;
|
|
265
|
+
if ("content" in rec)
|
|
266
|
+
seedReadFileStateFromTranscript(readFileState, rk, rec.content, rec.at, rec.transmittedByToolCallId);
|
|
267
|
+
else
|
|
268
|
+
readFileState.set(rk, { ...rec.observation, lastReadAt: rec.at });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const reader = createModelFileReader({
|
|
273
|
+
env: executionEnv,
|
|
274
|
+
state: readFileState,
|
|
275
|
+
rootCanonical: taskRootCanonical,
|
|
276
|
+
additionalRoots: readRoots,
|
|
277
|
+
readDeny: tables.readDeny,
|
|
278
|
+
readFace: liveReadFace,
|
|
279
|
+
});
|
|
280
|
+
const ruleLanes = createPermissionRuleLanes({
|
|
281
|
+
provider: silentDeps.permissionRuleStore,
|
|
282
|
+
localOwnerDeclared: silentDeps.localOwnerRules === true,
|
|
283
|
+
principal: start.spec.principal,
|
|
284
|
+
sessionId: start.spec.sessionId,
|
|
285
|
+
root: taskRootFinal,
|
|
286
|
+
rootCanonical: taskRootCanonical,
|
|
287
|
+
chainTop: legAnchors,
|
|
288
|
+
leads: headLeads,
|
|
289
|
+
liveCwd: () => taskRootCanonical,
|
|
290
|
+
home: executionEnv.homeDir,
|
|
291
|
+
questionToolMounted: false,
|
|
292
|
+
questionToolName: "AskUserQuestion",
|
|
293
|
+
onRevisionDefect: NOOP,
|
|
294
|
+
onDisclosure: NOOP,
|
|
295
|
+
rows: { pin: (id, judged) => personRows.pin(id, judged), forRequest: () => personRows.forRequest() },
|
|
296
|
+
});
|
|
297
|
+
const stampCallTarget = legCallTargetStamp({
|
|
298
|
+
env: executionEnv,
|
|
299
|
+
root: taskRootCanonical,
|
|
300
|
+
cwd: () => undefined,
|
|
301
|
+
judgesPaths: () => installedToolPolicy?.pathRules !== undefined || ruleLanes.personal !== undefined,
|
|
302
|
+
leads: () => headLeads.resolve([...toolPolicyPathRules([installedToolPolicy, ...inheritedPolicies], legAnchors), ...bindPathRules([], legAnchors)]),
|
|
303
|
+
});
|
|
304
|
+
const exemptRoots = Object.freeze(dataRootSpellings(silentDeps.memoryEngineDir));
|
|
305
|
+
const budget = legBudgetSnapshot(resourceTotalOf(start.spec), undefined);
|
|
306
|
+
const servedReadVerdict = createSyntheticServedReadJudge({
|
|
307
|
+
...(sessionRulePolicy !== undefined ? { denyNarrowingPolicy: sessionRulePolicy } : {}),
|
|
308
|
+
...(installedToolPolicy !== undefined ? { callerPolicy: installedToolPolicy } : {}),
|
|
309
|
+
inheritedPolicies,
|
|
310
|
+
...(ruleLanes.personal !== undefined ? { persistedRuleLane: ruleLanes.personal } : {}),
|
|
311
|
+
...(ruleLanes.org !== undefined ? { orgRuleLane: ruleLanes.org } : {}),
|
|
312
|
+
stampCallTarget,
|
|
313
|
+
signal: abortController.signal,
|
|
314
|
+
}, () => ({ cwd: taskRootCanonical, root: taskRootCanonical, exemptRoots, budget }));
|
|
315
|
+
const readName = TOOL_CATALOG_ENTRIES.find((e) => e.id === "read")?.name;
|
|
316
|
+
const readDecl = readName !== undefined && valveLeaves(start.toolFaceSnapshot.selector)({ name: readName }) ? toolFace("read") : undefined;
|
|
317
|
+
const readContract = readDecl?.contract;
|
|
318
|
+
const readToolFace = readName === undefined || readDecl === undefined || readContract === undefined
|
|
319
|
+
? undefined
|
|
320
|
+
: {
|
|
321
|
+
names: [readName],
|
|
322
|
+
family: readDecl.family,
|
|
323
|
+
...(readDecl.pathTarget !== undefined
|
|
324
|
+
? {
|
|
325
|
+
pathTarget: {
|
|
326
|
+
param: readDecl.pathTarget.param,
|
|
327
|
+
aliases: [...(readDecl.pathTarget.aliases ?? [])],
|
|
328
|
+
access: readDecl.pathTarget.access,
|
|
329
|
+
skillScopeEligible: readDecl.pathTarget.skillScopeEligible === true,
|
|
330
|
+
...(readDecl.pathTarget.base !== undefined ? { base: readDecl.pathTarget.base } : {}),
|
|
331
|
+
...(readDecl.pathTarget.absent !== undefined ? { absent: readDecl.pathTarget.absent } : {}),
|
|
332
|
+
},
|
|
333
|
+
}
|
|
334
|
+
: {}),
|
|
335
|
+
capabilityId: readContract.contractId,
|
|
336
|
+
contractId: readContract.contractId,
|
|
337
|
+
shapeDigest: "",
|
|
338
|
+
implementationRevision: readContract.implementationRevision,
|
|
339
|
+
engineMounted: true,
|
|
340
|
+
};
|
|
341
|
+
const lane = seatInstructionLane({
|
|
342
|
+
declaration: nestedDecl,
|
|
343
|
+
signal: abortController.signal,
|
|
344
|
+
mark: undefined,
|
|
345
|
+
counts: undefined,
|
|
346
|
+
deps: silentDeps,
|
|
347
|
+
leg: () => previewLeg,
|
|
348
|
+
env: executionEnv,
|
|
349
|
+
reader,
|
|
350
|
+
judge: servedReadVerdict,
|
|
351
|
+
readFace: () => readToolFace,
|
|
352
|
+
state: readFileState,
|
|
353
|
+
root: taskRootCanonical,
|
|
354
|
+
additionalRoots: declaredAdditionalRoots,
|
|
355
|
+
});
|
|
356
|
+
const instructions = await primeInstructionReading(lane, NOOP);
|
|
357
|
+
return { ok: true, projectMemory, ...(instructions !== undefined ? { instructions } : {}) };
|
|
358
|
+
}
|
|
359
|
+
finally {
|
|
360
|
+
for (const env of owned)
|
|
361
|
+
if (hasDestroy(env))
|
|
362
|
+
await settleTeardownLeg(() => env.destroy(), "ownedEnv.destroy (previewInstructions)", NOOP);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
const { code, message, detail } = thrownFailureOf(err, thrownText(err));
|
|
367
|
+
return { ok: false, ...(code !== undefined ? { code } : {}), message, ...(detail !== undefined ? { detail } : {}) };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
function rowReader(sessions) {
|
|
371
|
+
const row = async (sessionId) => {
|
|
372
|
+
const readRow = sessions.readRow;
|
|
373
|
+
if (typeof readRow !== "function") {
|
|
374
|
+
throw Object.assign(new Error("Runner.previewInstructions: the session store has no row read (readRow) — a preview reads a named session without running on it, and never opens it through acquire, which sweeps and records activity"), { code: "config.invalid_session_store" });
|
|
375
|
+
}
|
|
376
|
+
return readRow.call(sessions, sessionId);
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
row,
|
|
380
|
+
async acquire(sessionId) {
|
|
381
|
+
const read = sessionId === undefined ? undefined : await row(sessionId);
|
|
382
|
+
if (sessionId === undefined || read === undefined)
|
|
383
|
+
throw new SessionError("not_found", `Session not found: ${sessionId ?? "(none named)"}`);
|
|
384
|
+
return { session: detachedSession(read), sessionId };
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const detachedSession = (row) => new StoredSession(new InMemorySessionStorage({ metadata: structuredClone(row.metadata), entries: structuredClone(row.entries) }));
|
|
389
|
+
async function previewSession(sessions, rows, spec, internals) {
|
|
390
|
+
const ownerSeat = judgedOwnerSeat(internals);
|
|
391
|
+
const leg = judgedLegOf(spec, internals, ownerSeat === undefined ? undefined : await delegatedTreeOwner(ownerSeat, spec.signal));
|
|
392
|
+
let judged;
|
|
393
|
+
if (leg !== undefined) {
|
|
394
|
+
const verdict = await judgeRowForTree(sessions, { sessionId: spec.sessionId, minted: leg.minted, runsOn: true, writes: false }, { bound: true, owner: leg.owner }, leg.signal);
|
|
395
|
+
if (!verdict.open)
|
|
396
|
+
throw legRowRefusal(spec.sessionId, verdict);
|
|
397
|
+
judged = verdict.head;
|
|
398
|
+
}
|
|
399
|
+
const row = await rows.row(spec.sessionId);
|
|
400
|
+
if (judged !== undefined && !(judged === null && row === undefined) && !readStandsAsJudged(judged, row?.head))
|
|
401
|
+
throw legRowRefusal(spec.sessionId, rowNotTheOneJudged());
|
|
402
|
+
if (row === undefined && spec.requireExistingSession === true) {
|
|
403
|
+
throw Object.assign(new Error(`Runner.previewInstructions: session "${spec.sessionId}" does not exist`), { code: "resume.session_not_found" });
|
|
404
|
+
}
|
|
405
|
+
return row === undefined ? undefined : detachedSession(row);
|
|
406
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The judged-read port's vocabulary (`ToolExecuteContext.judgedReads`): what a caller tool that declares a read target
|
|
3
|
+
* (`ToolPathTarget`, `access: "read"`) is handed per call by the file read station — the one way it reads a file the model named.
|
|
4
|
+
*/
|
|
5
|
+
import type { FileError, FileKind, Result } from "../internal/harness.js";
|
|
6
|
+
/**
|
|
7
|
+
* One target of a caller tool's declared read, as the file read station judged it for this call: the element's spelling, the
|
|
8
|
+
* canonical key the station judged it at, and the one way the tool reads it. The port holds targets only once the station's
|
|
9
|
+
* judgment of the WHOLE call has landed and let it through (no element refused; an outside one only when its question was
|
|
10
|
+
* answered yes); a call whose judgment did not land is `not_judged`. `open`
|
|
11
|
+
* judges the key again with the call's tables (the read-deny table, the roots — a target outside them only when the call's
|
|
12
|
+
* question about it was answered yes — the read face), binds the object there (`openBound`) and judges the key once more, then
|
|
13
|
+
* hands over the HELD object. It never resolves the spelling against a working directory that moved since the judgment. Refusals
|
|
14
|
+
* are results, never throws: `permission_denied` (the judgment refuses), `not_supported` (this environment cannot hold the object —
|
|
15
|
+
* the target is not read by name instead), `precondition_failed` (the key no longer names the object it named), any other code
|
|
16
|
+
* the environment's own answer.
|
|
17
|
+
*/
|
|
18
|
+
export interface JudgedRead {
|
|
19
|
+
readonly spelled: string;
|
|
20
|
+
readonly key: string;
|
|
21
|
+
open(signal?: AbortSignal): Promise<Result<JudgedFile, FileError>>;
|
|
22
|
+
}
|
|
23
|
+
/** The object a {@link JudgedRead} holds: every answer is about it or is a refusal. A directory lists only the entries the read-deny
|
|
24
|
+
* table does not withhold (`omitted` counts the withheld ones). The tool closes it. */
|
|
25
|
+
export interface JudgedFile {
|
|
26
|
+
readonly key: string;
|
|
27
|
+
readonly identity: string;
|
|
28
|
+
readonly kind: "file" | "directory";
|
|
29
|
+
size(): Promise<Result<number, FileError>>;
|
|
30
|
+
/** The whole file, never more than `max` bytes (a larger file is refused, `invalid`). */
|
|
31
|
+
readBytes(max: number, signal?: AbortSignal): Promise<Result<Uint8Array, FileError>>;
|
|
32
|
+
list(signal?: AbortSignal): Promise<Result<{
|
|
33
|
+
readonly entries: readonly {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly kind: FileKind;
|
|
36
|
+
}[];
|
|
37
|
+
readonly omitted: number;
|
|
38
|
+
readonly more: number;
|
|
39
|
+
}, FileError>>;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Why a call of a tool that declares a read target has no judged targets (CLOSED set): `no_read_station` — the leg mounts no file read
|
|
44
|
+
* station (a leg with no workspace): nothing on it judges a read the model names; `not_judged` — the leg's station holds no
|
|
45
|
+
* judgment of this whole call that let it through (a call that reached the tool without passing the gate; a judgment that does not answer before
|
|
46
|
+
* the gate's deadline refuses the call, `read_unestablished`, and the tool does not run). Either way the tool reads nothing. The words as a
|
|
47
|
+
* list: `JUDGED_READS_UNAVAILABLE`.
|
|
48
|
+
*/
|
|
49
|
+
export type JudgedReadsUnavailable = "no_read_station" | "not_judged";
|
|
50
|
+
/** `ToolExecuteContext.judgedReads`. */
|
|
51
|
+
export type JudgedReads = {
|
|
52
|
+
readonly kind: "judged";
|
|
53
|
+
readonly targets: readonly JudgedRead[];
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: "unavailable";
|
|
56
|
+
readonly reason: JudgedReadsUnavailable;
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The leg's budget facts a policy judges every request of the leg under (`ToolCallRequest.budget`) — one reading for a run's prepare and
|
|
3
|
+
* for a preview of that leg (`Runner.previewInstructions`), so a policy that judges the budget judges the preview's reads as the run's.
|
|
4
|
+
*/
|
|
5
|
+
import { type ResourceLedger } from "./checkpoint-store.js";
|
|
6
|
+
import type { ToolCallRequest } from "./tool-policy.js";
|
|
7
|
+
/** The resource totals a task configures (`TaskSpec.resourceSuspend`), $ in micro-USD — seeded on the first slice only (later slices
|
|
8
|
+
* read the frozen total off the ledger); `undefined` when the task configures no resource suspend. */
|
|
9
|
+
export declare function resourceTotalOf(spec: {
|
|
10
|
+
readonly resourceSuspend?: {
|
|
11
|
+
readonly totalBudgetUsd?: number;
|
|
12
|
+
readonly totalTokens?: number;
|
|
13
|
+
};
|
|
14
|
+
}): {
|
|
15
|
+
totalBudgetMicroUsd?: number;
|
|
16
|
+
totalTokens?: number;
|
|
17
|
+
} | undefined;
|
|
18
|
+
/** THE leg's budget snapshot, read once per leg from the durable state and frozen onto every request the leg hands a policy. A resumed
|
|
19
|
+
* leg reads its ledger's remaining and spend; a first leg (a preview resumes nothing) its configured total and nothing spent; the count
|
|
20
|
+
* is the durable suspend chain's. Never falsy-test the remaining (`0` = exhausted, not unlimited). */
|
|
21
|
+
export declare function legBudgetSnapshot(resourceTotal: {
|
|
22
|
+
readonly totalBudgetMicroUsd?: number;
|
|
23
|
+
} | undefined, resume: {
|
|
24
|
+
readonly priorLedger?: ResourceLedger;
|
|
25
|
+
readonly priorSuspendCount?: number;
|
|
26
|
+
} | undefined): NonNullable<ToolCallRequest["budget"]>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { remainingBudgetMicroUsd } from "./checkpoint-store.js";
|
|
2
|
+
export function resourceTotalOf(spec) {
|
|
3
|
+
const r = spec.resourceSuspend;
|
|
4
|
+
return r ? { totalBudgetMicroUsd: r.totalBudgetUsd !== undefined ? Math.round(r.totalBudgetUsd * 1e6) : undefined, totalTokens: r.totalTokens } : undefined;
|
|
5
|
+
}
|
|
6
|
+
export function legBudgetSnapshot(resourceTotal, resume) {
|
|
7
|
+
const priorLedger = resume?.priorLedger;
|
|
8
|
+
return { resourceRemainingMicroUsd: priorLedger ? remainingBudgetMicroUsd(priorLedger) : resourceTotal?.totalBudgetMicroUsd, resourceSpentMicroUsd: priorLedger?.spentMicroUsd ?? 0, suspendCount: resume?.priorSuspendCount ?? 0 };
|
|
9
|
+
}
|
|
@@ -39,6 +39,45 @@ export declare function rootAnchorOf(internals: {
|
|
|
39
39
|
sessionId: string;
|
|
40
40
|
occupant?: string;
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* The root session id a leg's {@link HookInvocationIdentity} carries — the session the delegation tree's shared task list
|
|
44
|
+
* belongs to (`task_list.partition_is_root_session`): the tree's root anchor (`internals.rootSessionId`) when present, else
|
|
45
|
+
* the leg's own `sessionId` on a top-level leg (`!isDelegatedChild` and not `observerLeg`), else `undefined` (honestly absent
|
|
46
|
+
* when a delegated or observer leg was handed no root anchor — never fabricating a child's own session as the root).
|
|
47
|
+
*/
|
|
48
|
+
export declare function hookRootSessionIdOf(internals: {
|
|
49
|
+
readonly rootSessionId?: string | undefined;
|
|
50
|
+
readonly observerLeg?: true | undefined;
|
|
51
|
+
} | undefined, sessionId: string, isDelegatedChild: boolean): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The identity facts a parked row records of its leg (`CheckpointState.legIdentity`, reader word `leg_identity`), so a resume
|
|
54
|
+
* reads them back instead of guessing them from the resuming turn: the task id its host declared (`spec.taskId`, after a member
|
|
55
|
+
* ledger's rebind), the task that spawned it (`internals.parentTaskId`), the delegation tree's root and that root's occupant
|
|
56
|
+
* (`internals.rootSessionId` with the scope its box lives in, `rootSessionScope`, written only together, and the root's occupant
|
|
57
|
+
* `rootSessionIncarnation` beside them) and its explicit spawn name (`internals.explicitAgentName` — never the display name a model
|
|
58
|
+
* chose, `sourceAgentName`). Each member is a non-empty string or absent; a leg with none records no section.
|
|
59
|
+
*/
|
|
60
|
+
export interface LegIdentityRecord {
|
|
61
|
+
readonly declaredTaskId?: string;
|
|
62
|
+
readonly parentTaskId?: string;
|
|
63
|
+
readonly rootSessionId?: string;
|
|
64
|
+
readonly rootSessionIncarnation?: string;
|
|
65
|
+
readonly rootSessionScope?: string;
|
|
66
|
+
readonly spawnName?: string;
|
|
67
|
+
}
|
|
68
|
+
/** The leg's {@link LegIdentityRecord} as its park mints it, off the leg's own spec and trusted internals; `undefined` when it has none. */
|
|
69
|
+
export declare function legIdentityRecordOf(declaredTaskId: string | undefined, internals: {
|
|
70
|
+
readonly parentTaskId?: string | undefined;
|
|
71
|
+
readonly rootSessionId?: string | undefined;
|
|
72
|
+
readonly rootSessionIncarnation?: string | undefined;
|
|
73
|
+
readonly rootSessionScope?: string | undefined;
|
|
74
|
+
readonly explicitAgentName?: string | undefined;
|
|
75
|
+
} | undefined): LegIdentityRecord | undefined;
|
|
76
|
+
/** A row's `state.legIdentity` read back: absent ⇒ `undefined` (a row of a leg that had none, or of an earlier release); a record
|
|
77
|
+
* whose every member is a non-empty string, with an occupant and a box scope only beside a root and no other key ⇒ that record (a
|
|
78
|
+
* root recorded without its scope — an earlier mint of this line — is read but restores no root); anything else ⇒
|
|
79
|
+
* `"damaged"` — never read as absent, which would resume the leg under identities its park did not record. */
|
|
80
|
+
export declare function readLegIdentityRecord(raw: unknown): LegIdentityRecord | undefined | "damaged";
|
|
42
81
|
/** The members of the SYNCHRONOUS-CHILD BLOCK a parked row of an earlier release records beside its identity: the spawning run's session
|
|
43
82
|
* and task, and the delegation tree's root session with the occupant of its row. One tuple, so the row's member-shape table, the summary
|
|
44
83
|
* and the row judge (a row holding any of them is a synchronous child's — a leg nobody resumes) name the same four. No release mints
|
|
@@ -132,7 +171,8 @@ export interface NoticeRoute {
|
|
|
132
171
|
/** The keys the notice carries — spread into its detail as-is. */
|
|
133
172
|
readonly address: NoticeAddress;
|
|
134
173
|
/** The session address a notice routed away from the leg's own session is for: on a delegated leg addressed to its tree's
|
|
135
|
-
* root, the root's id
|
|
174
|
+
* root, the root's id, the root occupant the tree was born under (absent = unknown) and the scope the root leg works in (its
|
|
175
|
+
* `rootSessionScope`; absent = not recorded — the scope a notice may name a scope's entries to, `withheldEnvUserNotice`). A delivery to it is judged like any
|
|
136
176
|
* frame addressed there (`PendingSessionNotifications.discardsStaleNotice`). Never spread into a notice: an occupant token
|
|
137
177
|
* is an addressing fact, not a word the wire carries. Absent when the notice goes to the leg's own session. */
|
|
138
178
|
readonly destination?: SessionAddress;
|
|
@@ -150,6 +190,7 @@ export interface NoticeRoute {
|
|
|
150
190
|
export declare function noticeAddressOf(askSource: AskSourceIdentity, root: {
|
|
151
191
|
readonly rootSessionId?: string;
|
|
152
192
|
readonly rootSessionIncarnation?: string;
|
|
193
|
+
readonly rootSessionScope?: string;
|
|
153
194
|
} | undefined): NoticeRoute;
|
|
154
195
|
/** A leg's user-face notice seat: where its notices go ({@link NoticeRoute}) and the admission every one is delivered under. */
|
|
155
196
|
export interface LegNotice {
|
|
@@ -160,6 +201,14 @@ export interface LegNotice {
|
|
|
160
201
|
* announced record. A delegated leg's is its own session's, not its tree root's. */
|
|
161
202
|
readonly told: NoticeTold;
|
|
162
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* The admission every user-face notice of a leg is delivered under: a notice routed to the tree's root is judged against the
|
|
206
|
+
* root's current occupant, named by the leg it came from and its code — one addressed to an occupant the root no longer holds is
|
|
207
|
+
* not admitted (the judge discards it and announces the discard). A top-level leg's notices, and every notice of a leg prepared
|
|
208
|
+
* outside a Runner, are admitted as they are (no predicate). A notice a delegation lane says on a leg's behalf (a spawn's account,
|
|
209
|
+
* `RunnerSelfSeat.emitNotice` with a route) is admitted by this same reading.
|
|
210
|
+
*/
|
|
211
|
+
export declare function legNoticeAdmission(route: NoticeRoute, judge: NoticeDestinationJudge | undefined): ((notice: EngineNotice) => boolean) | undefined;
|
|
163
212
|
/**
|
|
164
213
|
* The leg's one notice seat, minted ONCE at prepare beside the ask source (`Prepared.legNotice`): every seat that tells the
|
|
165
214
|
* person something about this leg — the gate's stations, the shell's withheld-variables line — reads this address and this
|
|
@@ -168,4 +217,5 @@ export interface LegNotice {
|
|
|
168
217
|
export declare function mintLegNotice(askSource: AskSourceIdentity, root: {
|
|
169
218
|
readonly rootSessionId?: string;
|
|
170
219
|
readonly rootSessionIncarnation?: string;
|
|
220
|
+
readonly rootSessionScope?: string;
|
|
171
221
|
} | undefined, judge: NoticeDestinationJudge | undefined, told: NoticeTold): LegNotice;
|