@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,96 @@
|
|
|
1
|
+
import { isAbsoluteHostPath } from "@sema-agent/primitives";
|
|
2
|
+
export const PROJECT_ID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
export const PROJECT_SEAT_NAME_MAX = 256;
|
|
4
|
+
export const PROJECT_SEAT_FILES_MAX = 100;
|
|
5
|
+
const SEAT_MEMBERS = ["id", "name", "description", "instructions", "files"];
|
|
6
|
+
const TEXT_MEMBERS = ["name", "description", "instructions"];
|
|
7
|
+
const shown = (v) => {
|
|
8
|
+
if (typeof v === "string")
|
|
9
|
+
return JSON.stringify(v.length > 48 ? `${v.slice(0, 48)}…` : v);
|
|
10
|
+
if (v === null)
|
|
11
|
+
return "null";
|
|
12
|
+
if (Array.isArray(v))
|
|
13
|
+
return "an array";
|
|
14
|
+
return typeof v === "object" ? "an object" : typeof v === "function" ? "a function" : String(v);
|
|
15
|
+
};
|
|
16
|
+
export function screenProjectSeat(value, at = "TaskSpec.project") {
|
|
17
|
+
try {
|
|
18
|
+
return screenRead(value, at);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return refusal(at, "could not be read: its read threw — a seat whose read throws is refused rather than read as absent");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function refusal(field, why, code = "config.invalid_argument") {
|
|
25
|
+
return { ok: false, code, field, message: `${field}: ${why} — the leg is refused rather than run under a project it was not given.` };
|
|
26
|
+
}
|
|
27
|
+
function screenRead(value, at) {
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
return { ok: true };
|
|
30
|
+
const refuse = refusal;
|
|
31
|
+
const proto = value === null || typeof value !== "object" || Array.isArray(value) ? undefined : Object.getPrototypeOf(value);
|
|
32
|
+
if (proto === undefined || (proto !== null && Object.getPrototypeOf(proto) !== null)) {
|
|
33
|
+
return refuse(at, `must be a plain object { id, name?, description?, instructions?, files? } (got ${shown(value)})`);
|
|
34
|
+
}
|
|
35
|
+
const own = Reflect.ownKeys(value);
|
|
36
|
+
const stray = own.find((k) => typeof k !== "string" || !SEAT_MEMBERS.includes(k));
|
|
37
|
+
if (stray !== undefined)
|
|
38
|
+
return refuse(`${at}.${String(stray)}`, `is no member of a project seat (its members are ${SEAT_MEMBERS.join(", ")})`);
|
|
39
|
+
const read = {};
|
|
40
|
+
for (const k of own) {
|
|
41
|
+
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
42
|
+
if (d === undefined || !("value" in d))
|
|
43
|
+
return refuse(`${at}.${k}`, "must be a plain data member, not an accessor");
|
|
44
|
+
if (d.value !== undefined)
|
|
45
|
+
read[k] = d.value;
|
|
46
|
+
}
|
|
47
|
+
const id = read["id"];
|
|
48
|
+
if (id === undefined)
|
|
49
|
+
return refuse(`${at}.id`, "is required — a seat names its project");
|
|
50
|
+
if (typeof id !== "string" || !PROJECT_ID_REGEX.test(id)) {
|
|
51
|
+
return refuse(`${at}.id`, `must be a project UUID (the id a \`.sema/project\` marker carries), got ${shown(id)}`, "config.project_id_invalid");
|
|
52
|
+
}
|
|
53
|
+
for (const k of TEXT_MEMBERS) {
|
|
54
|
+
const v = read[k];
|
|
55
|
+
if (v === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
if (typeof v !== "string")
|
|
58
|
+
return refuse(`${at}.${k}`, `must be a string (got ${shown(v)}); leave it out to say none`);
|
|
59
|
+
if (v.trim() === "")
|
|
60
|
+
return refuse(`${at}.${k}`, "is empty or only whitespace; leave it out to say none");
|
|
61
|
+
}
|
|
62
|
+
const name = read["name"];
|
|
63
|
+
if (name !== undefined && /[\r\n]/.test(name))
|
|
64
|
+
return refuse(`${at}.name`, "is one line — it carries a line break");
|
|
65
|
+
if (name !== undefined && name.length > PROJECT_SEAT_NAME_MAX)
|
|
66
|
+
return refuse(`${at}.name`, `is at most ${PROJECT_SEAT_NAME_MAX} characters (got ${name.length})`);
|
|
67
|
+
const given = read["files"];
|
|
68
|
+
let files;
|
|
69
|
+
if (given !== undefined) {
|
|
70
|
+
if (!Array.isArray(given))
|
|
71
|
+
return refuse(`${at}.files`, `must be a list of absolute host paths (got ${shown(given)})`);
|
|
72
|
+
const length = given.length;
|
|
73
|
+
if (length > PROJECT_SEAT_FILES_MAX)
|
|
74
|
+
return refuse(`${at}.files`, `holds at most ${PROJECT_SEAT_FILES_MAX} entries (got ${length})`);
|
|
75
|
+
const entries = Array.from({ length }, (_, i) => given[i]);
|
|
76
|
+
const bad = entries.findIndex((p) => !isAbsoluteHostPath(p));
|
|
77
|
+
if (bad >= 0)
|
|
78
|
+
return refuse(`${at}.files[${bad}]`, `must be an absolute host path (got ${shown(entries[bad])})`);
|
|
79
|
+
files = entries;
|
|
80
|
+
}
|
|
81
|
+
const seat = Object.freeze({
|
|
82
|
+
id,
|
|
83
|
+
...Object.fromEntries(TEXT_MEMBERS.filter((k) => read[k] !== undefined).map((k) => [k, read[k]])),
|
|
84
|
+
...(files !== undefined ? { files: Object.freeze(files) } : {}),
|
|
85
|
+
});
|
|
86
|
+
return { ok: true, seat };
|
|
87
|
+
}
|
|
88
|
+
const REFUSED = Symbol("refused project seat");
|
|
89
|
+
export function captureProjectSeat(value, at) {
|
|
90
|
+
const screened = screenProjectSeat(value, at);
|
|
91
|
+
return screened.ok ? screened.seat : Object.freeze({ [REFUSED]: screened });
|
|
92
|
+
}
|
|
93
|
+
export function handedProjectSeat(captured) {
|
|
94
|
+
const refused = captured?.[REFUSED];
|
|
95
|
+
return refused ?? { ok: true, ...(captured !== undefined ? { seat: captured } : {}) };
|
|
96
|
+
}
|
|
@@ -244,8 +244,9 @@ export declare function foreignLine(text: string, maxLen?: number, reading?: For
|
|
|
244
244
|
* these words does their remote-words reading not carry", for a reader that carries the same words in another spelling and must carry
|
|
245
245
|
* no less: the regions its echo pass withholds and the spans its vocabulary pass then withholds in those marked words
|
|
246
246
|
* ({@link egressCredentialReading}: the label a rendering keeps is not in the span), read back through the marks (a span that touches a
|
|
247
|
-
* mark reaches the whole region the mark stands for)
|
|
248
|
-
*
|
|
247
|
+
* mark reaches the whole region the mark stands for); the regions are the merge's own account of what it wrote ({@link mergeWithheldSpans}),
|
|
248
|
+
* and where a mark the text already held meets what is taken (see {@link writtenRegions}), the answer is the whole text; and checked against
|
|
249
|
+
* the reading's own output: where the text outside the spans does not stand in it as written
|
|
249
250
|
* ({@link carriesTheRest}), the spans missed a removal, and the answer is the whole text.
|
|
250
251
|
*/
|
|
251
252
|
export declare function remoteWordsSpans(text: string, declared: readonly string[], found?: FoundElsewhere): Array<readonly [number, number]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { boundedForeignReading, egressCredentialFinds, egressCredentialReading, egressText, oneLineFinds, wholeForeignReading } from "./untrusted-egress.js";
|
|
2
|
-
import { CREDENTIAL_MIN_CHARS, crossesNetworkInClear, isRedactionMark, isSensitiveRecordKey, REDACTION_MARKS, renderWithheld } from "@sema-agent/primitives";
|
|
2
|
+
import { CREDENTIAL_MIN_CHARS, crossesNetworkInClear, isRedactionMark, isSensitiveRecordKey, mergeWithheldSpans, REDACTION_MARKS, renderWithheld } from "@sema-agent/primitives";
|
|
3
3
|
import { foldPlaces, foldToOneLine, INLINE_TRUNCATION_MARK, inlineUntrusted, LABEL_MAX, withoutUnrenderable } from "./untrusted-text.js";
|
|
4
4
|
import { callerText } from "./caller-text.js";
|
|
5
5
|
import { PRINCIPAL_NAME_SPELLING, readPrincipal } from "./principal-name.js";
|
|
@@ -481,8 +481,8 @@ function echoTaken(text, declared, found) {
|
|
|
481
481
|
}
|
|
482
482
|
export function remoteWordsSpans(text, declared, found = NOTHING_FOUND) {
|
|
483
483
|
const taken = echoTaken(text, declared, found);
|
|
484
|
-
const marked =
|
|
485
|
-
const regions = writtenRegions(
|
|
484
|
+
const { text: marked, regions: merged, dropped } = mergeWithheldSpans(text, taken);
|
|
485
|
+
const regions = writtenRegions(taken, merged, dropped);
|
|
486
486
|
if (regions === undefined)
|
|
487
487
|
return [[0, text.length]];
|
|
488
488
|
const reading = egressCredentialReading(marked);
|
|
@@ -539,22 +539,30 @@ function mergedRanges(ranges) {
|
|
|
539
539
|
}
|
|
540
540
|
return merged;
|
|
541
541
|
}
|
|
542
|
-
function writtenRegions(
|
|
543
|
-
const
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
kept = end;
|
|
542
|
+
function writtenRegions(spans, merged, dropped) {
|
|
543
|
+
const marks = dropped.map((i) => spans[i]).sort((a, b) => a.start - b.start || a.end - b.end);
|
|
544
|
+
const inside = merged.map(() => []);
|
|
545
|
+
const standing = new Map();
|
|
546
|
+
let r = 0;
|
|
547
|
+
for (const s of marks) {
|
|
548
|
+
while (r < merged.length && merged[r].end < s.end)
|
|
549
|
+
r++;
|
|
550
|
+
const region = merged[r];
|
|
551
|
+
if (region !== undefined && region.start <= s.start && s.end <= region.end)
|
|
552
|
+
inside[r].push(s);
|
|
553
|
+
else
|
|
554
|
+
standing.set(`${s.start}:${s.end}`, s);
|
|
556
555
|
}
|
|
557
|
-
|
|
556
|
+
if (merged.some((region, k) => coveredLength([...region.spans.map((i) => spans[i]), ...inside[k]]) < region.end - region.start))
|
|
557
|
+
return undefined;
|
|
558
|
+
const regions = [...merged.map(({ start, end, mark }) => ({ start, end, length: mark.length })), ...[...standing.values()].map(({ start, end }) => ({ start, end, length: end - start }))].sort((a, b) => a.start - b.start || a.end - b.end);
|
|
559
|
+
for (let i = 1; i < regions.length; i++)
|
|
560
|
+
if (regions[i].start <= regions[i - 1].end)
|
|
561
|
+
return undefined;
|
|
562
|
+
return regions;
|
|
563
|
+
}
|
|
564
|
+
function coveredLength(spans) {
|
|
565
|
+
return mergedRanges(spans.map(({ start, end }) => [start, end])).reduce((n, [start, end]) => n + end - start, 0);
|
|
558
566
|
}
|
|
559
567
|
function cookieMembers(text) {
|
|
560
568
|
const members = [];
|
|
@@ -589,7 +589,7 @@ export interface RemoteExecutionEnv extends ExecutionEnv {
|
|
|
589
589
|
* Why the engine asks an {@link ExecutionEnvFactory} for an env ({@link ExecutionEnvFactoryContext.purpose}):
|
|
590
590
|
* · `"run"` — a leg's own env (one per leg, destroyed when the leg ends); every leg, a delegated child's included;
|
|
591
591
|
* · `"rewind_files"` — `Runner.rewindFiles`, out of any run; writes only the session's tracked files;
|
|
592
|
-
* · `"read_changes"` —
|
|
592
|
+
* · `"read_changes"` — read-only readings outside any run (`Runner.readSessionChanges`, `Runner.previewInstructions`); writes nothing.
|
|
593
593
|
*/
|
|
594
594
|
export type ExecutionEnvPurpose = "run" | "rewind_files" | "read_changes";
|
|
595
595
|
/** The closed set of {@link ExecutionEnvPurpose} words, frozen. */
|
|
@@ -608,9 +608,9 @@ export interface ExecutionEnvFactoryContext {
|
|
|
608
608
|
/**
|
|
609
609
|
* Why the engine asks for this env — always present. `"run"`: a leg's own env (one per leg, destroyed when the leg ends) —
|
|
610
610
|
* the meaning every factory call had before this member; every leg, a delegated child's included. `"rewind_files"`:
|
|
611
|
-
* `Runner.rewindFiles`, out of any run; writes only the session's tracked files. `"read_changes"`:
|
|
612
|
-
*
|
|
613
|
-
* (`RunnerDeps.executionEnvFactoryHonorsReadChanges`).
|
|
611
|
+
* `Runner.rewindFiles`, out of any run; writes only the session's tracked files. `"read_changes"`: read-only readings
|
|
612
|
+
* outside any run (`Runner.readSessionChanges`, `Runner.previewInstructions`); writes nothing — asked only of a factory the
|
|
613
|
+
* deployment declares answers it (`RunnerDeps.executionEnvFactoryHonorsReadChanges`).
|
|
614
614
|
*
|
|
615
615
|
* For a purpose other than `"run"` a factory ATTACHES to the workspace the session's runs use (the same directory / host /
|
|
616
616
|
* device) and never mints one — or refuses: a refusal coded {@link ENV_PURPOSE_UNSUPPORTED} when it does not serve the
|
|
@@ -36,6 +36,7 @@ export const RETIRED_TASK_SPEC_KEYS = Object.freeze({
|
|
|
36
36
|
promptProfile: 'the prompt\'s shape is the `lean_prompt` trait now — write `promptLean: false` for the long (classic) shape, `promptLean: true` (or nothing, on a model that declares `lean_prompt`) for the lean one',
|
|
37
37
|
rewindFiles: "capture needs no request (first-touch tracking is on whenever `RunnerDeps.fileHistoryStore` is wired and neither `RunnerDeps.fileHistoryCapture` nor `TaskSpec.fileHistory` turns it off); to restore files with the conversation write `resumeAt` + `restoreFiles: true`, for a code-only restore `rewindFilesTo` — drop the key",
|
|
38
38
|
compactionModel: SUMMARY_ON_MAIN_MODEL,
|
|
39
|
+
projectId: "a leg's project is one seat now — write `project: { id }` (the same UUID, as `TaskSpec.project.id`); the project's texts (`name`, `description`, `instructions`, `files`) ride that seat beside it",
|
|
39
40
|
});
|
|
40
41
|
export const RETIRED_SKILLS_SEAT_KEYS = Object.freeze({
|
|
41
42
|
"skills[].manifest": "a skill's tools are its `allowedTools` / `disallowedTools` now — an allow-rule and a deny-rule source for the run the skill is activated in, never a fence; move `manifest.allowTools` to `allowedTools`. To fence tools write deny rules (or a delegated agent definition's `allowTools`); to fence write paths use session `allowDirs`",
|
|
@@ -9,7 +9,7 @@ import { type RuleOffer } from "./permission-rule-model.js";
|
|
|
9
9
|
* Why a stored rule-offer value, or one element of it, is not read:
|
|
10
10
|
* · `not_an_array` — the value itself (present, and not a list): no element is read;
|
|
11
11
|
* · `unknown_word` — a closed-set member holds a word this engine does not know: the offer `kind`, a batch member's
|
|
12
|
-
* `kind`, a `match` (a newer minter, or another writer);
|
|
12
|
+
* `kind`, a `match`, a `cautions` word (a newer minter, or another writer);
|
|
13
13
|
* · `malformed` — not an object, a member missing or of the wrong type, a batch with no members, an uncovered count
|
|
14
14
|
* that is not a non-negative safe integer.
|
|
15
15
|
* The first defect in reading order names the element's problem.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PERSISTED_RULE_MATCHES, RULE_OFFER_BATCH_MEMBER_KINDS, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, isAddStamp, } from "./permission-rule-model.js";
|
|
1
|
+
import { PERSISTED_RULE_MATCHES, RULE_OFFER_BATCH_MEMBER_KINDS, RULE_OFFER_CAUTIONS, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, isAddStamp, } from "./permission-rule-model.js";
|
|
2
2
|
import { isPlainRecord } from "./checkpoint-store.js";
|
|
3
3
|
const OFFER_MATCHES = PERSISTED_RULE_MATCHES.filter((m) => m !== "call");
|
|
4
4
|
export const RULE_OFFER_SHAPE_PROBLEMS = Object.freeze(["not_an_array", "unknown_word", "malformed"]);
|
|
@@ -46,7 +46,10 @@ function readOfferElement(value) {
|
|
|
46
46
|
const peerFingerprint = Object.hasOwn(value, "peerFingerprint") ? value.peerFingerprint : undefined;
|
|
47
47
|
if (peerFingerprint !== undefined && !isAddStamp(peerFingerprint))
|
|
48
48
|
return MALFORMED;
|
|
49
|
-
|
|
49
|
+
const cautions = cautionsOf(value);
|
|
50
|
+
if ("problem" in cautions)
|
|
51
|
+
return cautions;
|
|
52
|
+
return { offer: { kind: "single", rule, match, command, ...(peerFingerprint !== undefined ? { peerFingerprint } : {}), ...cautions.seat } };
|
|
50
53
|
}
|
|
51
54
|
case "batch":
|
|
52
55
|
return readBatch(value);
|
|
@@ -87,8 +90,13 @@ function readBatchMember(value) {
|
|
|
87
90
|
if (typeof kind !== "string")
|
|
88
91
|
return kind;
|
|
89
92
|
switch (kind) {
|
|
90
|
-
case "command":
|
|
91
|
-
|
|
93
|
+
case "command": {
|
|
94
|
+
const read = commandMember(value.rule, value.match, value.command, value.segment);
|
|
95
|
+
if ("problem" in read)
|
|
96
|
+
return read;
|
|
97
|
+
const cautions = cautionsOf(value);
|
|
98
|
+
return "problem" in cautions ? cautions : { member: { ...read.member, ...cautions.seat } };
|
|
99
|
+
}
|
|
92
100
|
case "directoryRead": {
|
|
93
101
|
const rule = value.rule;
|
|
94
102
|
const directory = value.directory;
|
|
@@ -113,6 +121,26 @@ function commandMember(rule, rawMatch, command, segment) {
|
|
|
113
121
|
return MALFORMED;
|
|
114
122
|
return { member: { kind: "command", rule, match, command, segment } };
|
|
115
123
|
}
|
|
124
|
+
function cautionsOf(value) {
|
|
125
|
+
const raw = Object.hasOwn(value, "cautions") ? value.cautions : undefined;
|
|
126
|
+
if (raw === undefined)
|
|
127
|
+
return { seat: {} };
|
|
128
|
+
if (!Array.isArray(raw))
|
|
129
|
+
return MALFORMED;
|
|
130
|
+
const words = [];
|
|
131
|
+
let unknown = false;
|
|
132
|
+
const length = raw.length;
|
|
133
|
+
for (let i = 0; i < length; i++) {
|
|
134
|
+
const word = wordOf(raw[i], RULE_OFFER_CAUTIONS);
|
|
135
|
+
if (typeof word === "string")
|
|
136
|
+
words.push(word);
|
|
137
|
+
else if (word === MALFORMED)
|
|
138
|
+
return MALFORMED;
|
|
139
|
+
else
|
|
140
|
+
unknown = true;
|
|
141
|
+
}
|
|
142
|
+
return unknown ? UNKNOWN_WORD : { seat: { cautions: words } };
|
|
143
|
+
}
|
|
116
144
|
function detailRowsOf(detail, count) {
|
|
117
145
|
if (!Array.isArray(detail))
|
|
118
146
|
return undefined;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bindings of a run's member ledger book (`TaskSpec.runLedger`) that need the prepared leg: the holder's rows of the members the
|
|
3
|
+
* task dispatched (read at each snapshot), and the run's own tool calls (the evidence a check may cite, heard as each one starts and
|
|
4
|
+
* finishes). Bound once, right after prepare, by the lane that minted the book.
|
|
5
|
+
*
|
|
6
|
+
* A MEMBER is a background agent or workflow run whose registry row names this task as the one that dispatched it (`parentTaskId`,
|
|
7
|
+
* written at registration by the agent tool and the workflow tool alike) — one key for both kinds, whatever owner the row registered
|
|
8
|
+
* under (a session-scoped spawn registers under the session) and whatever else the session's reach holds (another task's spawns).
|
|
9
|
+
* How it stands is that row's: whether it runs, how it ended (the ending its holder minted, else the one its status word names —
|
|
10
|
+
* `outcomeOfLegacyRow`, the one table), a workflow run's own members (the run's member ledger, as the registry keeps it).
|
|
11
|
+
*
|
|
12
|
+
* The holder read is this process's task registry. A durable background-agent or workflow-run store is not read: a member whose row
|
|
13
|
+
* only such a store holds (a resume in another process) is one the holder no longer hands back — the book counts it unreadable and
|
|
14
|
+
* the coverage is incomplete (`docs/KNOWN-LIMITS.md`, KL-4459-b).
|
|
15
|
+
*/
|
|
16
|
+
import { type TaskListRow } from "./task-registry.js";
|
|
17
|
+
import { type RunEndCause } from "./member-outcome.js";
|
|
18
|
+
import type { RunLedgerBook, RunLedgerRegistryRow } from "./run-ledger.js";
|
|
19
|
+
/** What the binding reads off the prepared leg: its task id (the book's), its run id, its registry access, its session, and its
|
|
20
|
+
* harness's event stream. */
|
|
21
|
+
export interface RunLedgerLeg {
|
|
22
|
+
readonly taskId: string;
|
|
23
|
+
readonly runId: string;
|
|
24
|
+
readonly registryAccess: {
|
|
25
|
+
readonly owner: string;
|
|
26
|
+
readonly scope: string;
|
|
27
|
+
};
|
|
28
|
+
readonly sessionId: string;
|
|
29
|
+
readonly harness: {
|
|
30
|
+
subscribe(listener: (event: {
|
|
31
|
+
readonly type: string;
|
|
32
|
+
readonly toolCallId?: string;
|
|
33
|
+
}) => void): () => void;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** The task's member rows as its holder hands them (see the module head): every row of the reach that names the task as its
|
|
37
|
+
* parent, read as one set (no display cap — other tasks' rows in the reach never push a member out). The reach is the leg's own,
|
|
38
|
+
* its tree root's occupant included (`occupant`, the one its registry-facing tools act for): a worker an earlier occupant of a recycled
|
|
39
|
+
* session id started is no member, as it is no task of that leg. */
|
|
40
|
+
export declare function ledgerRegistryRows(access: {
|
|
41
|
+
readonly owner: string;
|
|
42
|
+
readonly scope: string;
|
|
43
|
+
}, sessionId: string, taskId: string, occupant?: string): RunLedgerRegistryRow[];
|
|
44
|
+
/** One member by its id — the same rule, read with no listing at all (a frame's row, however many rows the reach holds). */
|
|
45
|
+
export declare function ledgerMemberRow(access: {
|
|
46
|
+
readonly owner: string;
|
|
47
|
+
readonly scope: string;
|
|
48
|
+
}, sessionId: string, taskId: string, memberId: string, occupant?: string): RunLedgerRegistryRow | undefined;
|
|
49
|
+
/** One registry row as a snapshot reads it: running while its status says so; else the ending its holder minted (a background
|
|
50
|
+
* agent's), else the one its status word names ({@link outcomeOfLegacyRow}) — a parked row's is `parked`. A workflow row carries
|
|
51
|
+
* its run's own member ledger once the run settled. */
|
|
52
|
+
export declare function ledgerRegistryRowOf(r: TaskListRow, name?: string): RunLedgerRegistryRow;
|
|
53
|
+
/** The run-end reap of the run's task-scoped background agents (the teardown's own selection: `skipSessionScoped`), run ahead of a
|
|
54
|
+
* member ledger's last word (r3.1 R1.3: the last word is read after the reap, nothing simulated): the person's-stop mark first when
|
|
55
|
+
* a person stopped the run's work, then the reap with what ended the run, then — when it stopped any — a bounded wait until none
|
|
56
|
+
* of the agents this sweep selects remain running (ignoring monitors, background shells and session-scoped rows). The wait counts
|
|
57
|
+
* the task-scoped agents currently running under this owner, so an agent started by the same owner after the stop pass can hold the
|
|
58
|
+
* last snapshot up to the two-second bound. The teardown's own reap after it finds nothing left to take. */
|
|
59
|
+
export declare function reapTaskAgentsBeforeLastWord(access: {
|
|
60
|
+
readonly owner: string;
|
|
61
|
+
readonly scope: string;
|
|
62
|
+
}, source: "user" | "parent", runEnd: RunEndCause | undefined): Promise<void>;
|
|
63
|
+
/** Bind the book to the prepared leg — see the module head. The book's task is the leg's: a book minted for another task id is an
|
|
64
|
+
* engine fault, refused here rather than read as a ledger of nobody's members. `occupant`: the occupant of the leg's tree root the
|
|
65
|
+
* leg acts for (absent = none read: every row admits it, as on every registry face). */
|
|
66
|
+
export declare function bindRunLedgerBook(book: RunLedgerBook, prepared: RunLedgerLeg, occupant?: string): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { abortBackgroundAgentsAtRunEnd, defaultTaskRegistry, onRunEndAgentsSettled } from "./task-registry.js";
|
|
2
|
+
import { occupantStamp } from "./task-registry-shared.js";
|
|
3
|
+
import { outcomeOfLegacyRow } from "./member-outcome.js";
|
|
4
|
+
export function ledgerRegistryRows(access, sessionId, taskId, occupant) {
|
|
5
|
+
const reach = { ...access, sessionId, ...occupantStamp({ rootSessionIncarnation: occupant }) };
|
|
6
|
+
return defaultTaskRegistry.membersOfTask(reach, taskId).flatMap((r) => memberRowOf(r, reach, taskId) ?? []);
|
|
7
|
+
}
|
|
8
|
+
export function ledgerMemberRow(access, sessionId, taskId, memberId, occupant) {
|
|
9
|
+
const reach = { ...access, sessionId, ...occupantStamp({ rootSessionIncarnation: occupant }) };
|
|
10
|
+
const row = defaultTaskRegistry.runEndReading([memberId], reach, access)[0]?.row;
|
|
11
|
+
return row !== undefined ? memberRowOf(row, reach, taskId) : undefined;
|
|
12
|
+
}
|
|
13
|
+
function memberRowOf(r, reach, taskId) {
|
|
14
|
+
if (r.type !== "background_agent" && r.type !== "workflow")
|
|
15
|
+
return undefined;
|
|
16
|
+
const facts = defaultTaskRegistry.getAccessibleTask(r.task_id, reach);
|
|
17
|
+
return facts?.parentTaskId === taskId ? ledgerRegistryRowOf(r, facts.name) : undefined;
|
|
18
|
+
}
|
|
19
|
+
export function ledgerRegistryRowOf(r, name) {
|
|
20
|
+
const running = r.status === "running" || r.status === "pending";
|
|
21
|
+
const kind = r.type === "workflow" ? "workflow" : "background_agent";
|
|
22
|
+
const minted = r.type === "background_agent" ? defaultTaskRegistry.getAgentOutcome(r.task_id) : undefined;
|
|
23
|
+
const outcome = running ? undefined : (minted ?? outcomeOfLegacyRow(r, kind));
|
|
24
|
+
const ledger = r.type === "workflow" && !running ? defaultTaskRegistry.getWorkflowMembers(r.task_id) : undefined;
|
|
25
|
+
const cycle = r.type === "background_agent" ? (defaultTaskRegistry.backgroundAgentCycleSeq(r.task_id) ?? 1) : 1;
|
|
26
|
+
return {
|
|
27
|
+
taskId: r.task_id,
|
|
28
|
+
kind: r.type,
|
|
29
|
+
...(r.description !== undefined ? { label: r.description } : {}),
|
|
30
|
+
...(name !== undefined ? { name } : {}),
|
|
31
|
+
running,
|
|
32
|
+
cycle,
|
|
33
|
+
...(outcome !== undefined ? { outcome } : {}),
|
|
34
|
+
...(ledger !== undefined ? { members: { coverage: ledger.coverage, counts: ledger.counts } } : {}),
|
|
35
|
+
...(r.toolUseId !== undefined ? { toolUseId: r.toolUseId } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const LAST_WORD_REAP_WAIT_MS = 2_000;
|
|
39
|
+
export async function reapTaskAgentsBeforeLastWord(access, source, runEnd) {
|
|
40
|
+
if (source === "user")
|
|
41
|
+
defaultTaskRegistry.markRunEndAgentsStoppedByUser(access, { skipSessionScoped: true });
|
|
42
|
+
if (abortBackgroundAgentsAtRunEnd(defaultTaskRegistry, access, { skipSessionScoped: true }, runEnd) === 0)
|
|
43
|
+
return;
|
|
44
|
+
let off;
|
|
45
|
+
let timer;
|
|
46
|
+
await new Promise((resolve) => {
|
|
47
|
+
off = onRunEndAgentsSettled(defaultTaskRegistry, access, { skipSessionScoped: true }, resolve);
|
|
48
|
+
if (off === undefined)
|
|
49
|
+
return resolve();
|
|
50
|
+
timer = setTimeout(resolve, LAST_WORD_REAP_WAIT_MS);
|
|
51
|
+
});
|
|
52
|
+
off?.();
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
}
|
|
55
|
+
export function bindRunLedgerBook(book, prepared, occupant) {
|
|
56
|
+
if (book.taskId !== undefined && book.taskId !== prepared.taskId)
|
|
57
|
+
throw Object.assign(new Error(`the member ledger book is task "${book.taskId}"'s, but the leg runs as task "${prepared.taskId}"`), { code: "internal.run_ledger_unbound" });
|
|
58
|
+
const taskId = prepared.taskId;
|
|
59
|
+
book.bind(prepared.runId, () => ledgerRegistryRows(prepared.registryAccess, prepared.sessionId, taskId, occupant), (memberId) => ledgerMemberRow(prepared.registryAccess, prepared.sessionId, taskId, memberId, occupant));
|
|
60
|
+
prepared.harness.subscribe((e) => {
|
|
61
|
+
if (e.type === "turn_start")
|
|
62
|
+
return book.turnStarted();
|
|
63
|
+
if (typeof e.toolCallId !== "string")
|
|
64
|
+
return;
|
|
65
|
+
if (e.type === "tool_execution_start")
|
|
66
|
+
book.callStarted(e.toolCallId);
|
|
67
|
+
else if (e.type === "tool_execution_end")
|
|
68
|
+
book.callEnded(e.toolCallId);
|
|
69
|
+
});
|
|
70
|
+
}
|