@sema-agent/core 7.72.0 → 7.74.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 +565 -0
- package/dist/agents/inherited-tool-pool.d.ts +26 -1
- package/dist/agents/inherited-tool-pool.js +46 -2
- package/dist/agents/list-agents-tool.js +1 -1
- 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/retain-ledger.js +3 -3
- package/dist/agents/send-message-tool.js +5 -4
- 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 +43 -12
- package/dist/agents/verify.js +23 -8
- package/dist/agents/yield-adoption.js +3 -1
- package/dist/brain/anthropic.d.ts +42 -1
- package/dist/brain/anthropic.js +68 -13
- package/dist/brain/failover.d.ts +5 -0
- package/dist/brain/failover.js +51 -22
- package/dist/brain/model-lane.d.ts +12 -3
- package/dist/brain/model-lane.js +5 -5
- package/dist/brain/open-responses.js +7 -8
- package/dist/brain/openai.js +31 -24
- package/dist/brain/route-adjudicator.d.ts +33 -4
- package/dist/brain/route-adjudicator.js +49 -12
- package/dist/brain/stream-engine.js +166 -156
- package/dist/brain/stream-shared.d.ts +4 -3
- package/dist/brain/stream-shared.js +2 -2
- package/dist/core/actions-digest.d.ts +43 -0
- package/dist/core/actions-digest.js +22 -0
- package/dist/core/allow-entry.js +4 -4
- package/dist/core/ask-class.d.ts +2 -2
- package/dist/core/ask-headline.d.ts +1 -1
- package/dist/core/ask-origin.d.ts +44 -4
- package/dist/core/ask-origin.js +29 -10
- package/dist/core/auto-mode.d.ts +7 -9
- package/dist/core/auto-mode.js +114 -8
- package/dist/core/background-agent-store.d.ts +1 -0
- package/dist/core/background-agent-store.js +49 -8
- package/dist/core/checkpoint-features.d.ts +3 -2
- package/dist/core/checkpoint-features.js +1 -1
- 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 +9 -3
- package/dist/core/checkpoint-store.d.ts +26 -2
- package/dist/core/checkpoint-store.js +9 -2
- package/dist/core/child-clamp-seats.d.ts +15 -0
- package/dist/core/child-clamp-seats.js +15 -0
- package/dist/core/config-refusal-codes.d.ts +1 -1
- package/dist/core/config-refusal-codes.js +1 -0
- package/dist/core/cron.js +9 -1
- package/dist/core/delegation-frames.d.ts +1 -0
- package/dist/core/delegation-frames.js +1 -1
- package/dist/core/deployment-shape.d.ts +7 -0
- package/dist/core/deployment-shape.js +19 -0
- package/dist/core/engine-capabilities.d.ts +13 -1
- package/dist/core/engine-capabilities.js +1 -1
- package/dist/core/engine-notice.d.ts +41 -28
- 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/gate-fold.js +5 -4
- package/dist/core/gate-lanes.js +8 -12
- package/dist/core/gate-outcome.d.ts +8 -2
- package/dist/core/gate-outcome.js +10 -3
- package/dist/core/governance-codes.d.ts +14 -2
- package/dist/core/governance-codes.js +22 -6
- package/dist/core/hook-condition.d.ts +37 -0
- package/dist/core/hook-condition.js +567 -0
- package/dist/core/hooks.d.ts +5 -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/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-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/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/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 +18 -13
- package/dist/core/memory-engine/scope-contract.js +18 -18
- 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 +25 -6
- package/dist/core/mode-policy.js +33 -8
- package/dist/core/model-seat.d.ts +8 -5
- package/dist/core/model-shell.d.ts +129 -0
- package/dist/core/model-shell.js +249 -0
- package/dist/core/mods/kernel/digest.d.ts +4 -0
- package/dist/core/mods/kernel/digest.js +5 -0
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +15 -6
- package/dist/core/mods/kernel/events.d.ts +21 -5
- package/dist/core/mods/kernel/events.js +19 -10
- package/dist/core/mods/kernel/hash-mirror.d.ts +1 -0
- package/dist/core/mods/kernel/hash-mirror.js +55 -0
- package/dist/core/mods/kernel/index.d.ts +1 -0
- package/dist/core/mods/kernel/index.js +1 -0
- package/dist/core/mods/kernel/package-reader.d.ts +48 -0
- package/dist/core/mods/kernel/package-reader.js +149 -0
- package/dist/core/mods/kernel/site-rules.d.ts +4 -0
- package/dist/core/mods/kernel/site-rules.js +13 -0
- package/dist/core/mods/package.d.ts +7 -3
- package/dist/core/mods/package.js +47 -80
- package/dist/core/own-property-receipt.js +11 -4
- package/dist/core/parent-spec-seat.d.ts +13 -11
- package/dist/core/parent-spec-seat.js +13 -9
- 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 +33 -5
- package/dist/core/permission-rule-org.js +13 -3
- 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/permission-rules.js +4 -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/retain-seat.d.ts +42 -0
- package/dist/core/retain-seat.js +76 -0
- package/dist/core/retired-keys.js +1 -0
- package/dist/core/rewind-refusal-codes.d.ts +8 -0
- package/dist/core/rewind-refusal-codes.js +12 -0
- package/dist/core/roles.d.ts +2 -2
- package/dist/core/roles.js +15 -1
- package/dist/core/rule-offer-read.d.ts +1 -1
- package/dist/core/rule-offer-read.js +32 -4
- package/dist/core/rule-store-fault.d.ts +9 -7
- package/dist/core/rule-store-fault.js +8 -3
- 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/checkpoint-scope.d.ts +14 -3
- package/dist/core/runner/checkpoint-scope.js +16 -6
- package/dist/core/runner/compact-session.js +1 -1
- package/dist/core/runner/construction-doors.js +8 -0
- package/dist/core/runner/contracts.d.ts +21 -5
- package/dist/core/runner/cross-boundary-lane.d.ts +8 -1
- package/dist/core/runner/cross-boundary-lane.js +4 -0
- package/dist/core/runner/delegation-owner.d.ts +30 -0
- package/dist/core/runner/delegation-owner.js +20 -4
- package/dist/core/runner/finish-reason-seat.js +4 -2
- package/dist/core/runner/gate-exit.d.ts +7 -0
- package/dist/core/runner/gate-exit.js +2 -1
- package/dist/core/runner/leg-frame.js +3 -0
- package/dist/core/runner/model-lane-seat.d.ts +3 -0
- package/dist/core/runner/model-lane-seat.js +4 -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 +27 -16
- package/dist/core/runner/person-path-rows.js +93 -15
- package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
- package/dist/core/runner/prepare-config-doors.d.ts +1 -0
- package/dist/core/runner/prepare-config-doors.js +13 -7
- 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-gate-stations.d.ts +6 -0
- package/dist/core/runner/prepare-gate-stations.js +3 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
- package/dist/core/runner/prepare-hands-readface.js +15 -3
- package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
- package/dist/core/runner/prepare-inherited-gate.js +13 -5
- package/dist/core/runner/prepare-offload-wrappers.js +1 -1
- 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 +42 -30
- 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 +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +8 -6
- package/dist/core/runner/resume-apply.js +11 -5
- package/dist/core/runner/resume-policy-outcome.js +5 -2
- 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/role-seat-defaulted.d.ts +3 -3
- package/dist/core/runner/role-seat-defaulted.js +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.d.ts +1 -1
- package/dist/core/runner/rule-store-unreadable-notice.js +3 -3
- package/dist/core/runner/run-harness-handlers.js +4 -1
- package/dist/core/runner/run-identity-wiring.js +3 -2
- package/dist/core/runner/run-leg.js +5 -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 +6 -4
- package/dist/core/runner/shell-env-withheld.js +25 -3
- 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/sub-agent-deny-lists.js +9 -5
- package/dist/core/runner/task-start-doors.js +6 -3
- package/dist/core/runner/terminal-account.d.ts +6 -1
- package/dist/core/runner/terminal-account.js +16 -1
- package/dist/core/runner/tool-end-body.d.ts +1 -1
- package/dist/core/runner/tool-not-executed.d.ts +27 -8
- package/dist/core/runner/tool-not-executed.js +22 -11
- package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
- package/dist/core/runner/write-protection-station.d.ts +1 -1
- package/dist/core/runner/write-protection-station.js +1 -1
- package/dist/core/runner-deps.d.ts +17 -10
- package/dist/core/secret-env.d.ts +61 -37
- package/dist/core/secret-env.js +49 -49
- 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.d.ts +40 -2
- package/dist/core/shell-read-silence.js +23 -4
- package/dist/core/store-contracts/checkpoint-store-contract.js +10 -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 +14 -7
- package/dist/core/task-notification.d.ts +96 -10
- package/dist/core/task-notification.js +135 -6
- package/dist/core/task-registry-agent.d.ts +1 -0
- package/dist/core/task-registry-agent.js +1 -1
- 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 +40 -2
- package/dist/core/task-registry.js +80 -15
- package/dist/core/task-result.d.ts +18 -3
- package/dist/core/task-spec-members.d.ts +3 -1
- package/dist/core/task-spec-members.js +19 -3
- package/dist/core/task-spec.d.ts +48 -22
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-gate-phase.d.ts +6 -3
- package/dist/core/tool-gate-phase.js +1 -0
- package/dist/core/tool-mount-facts.d.ts +8 -4
- package/dist/core/tool-mount-facts.js +7 -2
- package/dist/core/tool-mount-plan.d.ts +3 -1
- package/dist/core/tool-mount-plan.js +10 -3
- package/dist/core/tool-mount-static.d.ts +1 -1
- package/dist/core/tool-mount-static.js +4 -2
- package/dist/core/tool-result-store.d.ts +56 -3
- package/dist/core/tool-result-store.js +219 -25
- package/dist/core/tool-spec.d.ts +9 -2
- package/dist/core/trace.d.ts +3 -3
- package/dist/core/user-attachment.d.ts +5 -1
- package/dist/core/user-attachment.js +14 -7
- package/dist/core/wiring-manifest.d.ts +26 -20
- package/dist/core/wiring-manifest.js +7 -3
- 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.d.ts +75 -1
- package/dist/engine/execution-env/node-execution-env.js +227 -13
- package/dist/engine/harness/types.d.ts +49 -1
- package/dist/engine/harness/types.js +10 -0
- package/dist/engine/llm/types.d.ts +13 -7
- package/dist/engine/llm/validation.d.ts +8 -1
- package/dist/engine/llm/validation.js +31 -2
- 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 +34 -4
- package/dist/host-env.d.ts +10 -0
- package/dist/host-env.js +1 -0
- package/dist/index.d.ts +28 -9
- package/dist/index.js +22 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/goal.js +1 -1
- 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-primitives.js +10 -1
- package/dist/orchestration/workflow-script-runner.d.ts +2 -2
- package/dist/orchestration/workflow-stop.d.ts +128 -0
- package/dist/orchestration/workflow-stop.js +156 -0
- package/dist/orchestration/workflow.d.ts +31 -7
- package/dist/orchestration/workflow.js +119 -57
- package/dist/prompts/manager-recipe.d.ts +18 -0
- package/dist/prompts/manager-recipe.js +24 -0
- package/dist/shell/lex.d.ts +2 -2
- package/dist/shell/lex.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/fs/bash-model-shell.d.ts +23 -0
- package/dist/tools/fs/bash-model-shell.js +25 -0
- package/dist/tools/fs/bash-readonly-classifier.d.ts +6 -0
- package/dist/tools/fs/bash-readonly-classifier.js +3 -0
- package/dist/tools/fs/file-write-check.js +9 -3
- package/dist/tools/fs/fs-bash.js +13 -11
- package/dist/tools/fs/index.d.ts +8 -7
- package/dist/tools/fs/index.js +4 -4
- 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 +4 -1
- package/dist/tools/fs/safety.js +4 -2
- package/dist/tools/fs/shell-read-argv.js +1 -0
- package/dist/tools/fs/shell-read-check.d.ts +9 -2
- package/dist/tools/fs/shell-read-check.js +134 -22
- package/dist/tools/fs/shell-read-establish.d.ts +9 -0
- package/dist/tools/fs/shell-read-establish.js +21 -11
- 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 +7 -3
- package/dist/tools/fs/shell-read-plan.js +8 -5
- package/dist/tools/fs/shell-read-word.d.ts +8 -0
- package/dist/tools/fs/shell-read-word.js +13 -4
- package/dist/tools/fs/shell-read-write-targets.js +17 -9
- package/dist/tools/monitor.js +12 -8
- package/dist/tools/scheduler-tools.d.ts +1 -0
- package/dist/tools/scheduler-tools.js +5 -2
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +192 -3
- package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
- package/wire-changes/answers/core-stores-sql@7.74.0.json +7 -0
- package/wire-changes/answers/core@7.73.0.json +216 -0
- package/wire-changes/answers/core@7.74.0.json +68 -0
- package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
- package/wire-changes/answers/mods-kernel@7.74.0.json +21 -0
- package/wire-changes/answers/primitives@7.73.0.json +12 -0
- package/wire-changes/answers/primitives@7.74.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
- package/wire-changes/answers/wiki-gate@7.74.0.json +8 -0
- package/wire-changes/core-stores-sql@7.73.0.json +326 -0
- package/wire-changes/core-stores-sql@7.74.0.json +143 -0
- package/wire-changes/core@7.73.0.json +6480 -0
- package/wire-changes/core@7.74.0.json +2210 -0
- package/wire-changes/mods-kernel@7.73.0.json +147 -0
- package/wire-changes/mods-kernel@7.74.0.json +421 -0
- package/wire-changes/primitives@7.73.0.json +227 -0
- package/wire-changes/primitives@7.74.0.json +174 -0
- package/wire-changes/wiki-gate@7.73.0.json +145 -0
- package/wire-changes/wiki-gate@7.74.0.json +145 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { strayMembersOf } from "./own-property-receipt.js";
|
|
1
2
|
export function agentIdOf(identity) {
|
|
2
3
|
return identity?.isDelegatedChild === true ? identity.taskId : undefined;
|
|
3
4
|
}
|
|
@@ -9,6 +10,47 @@ export function rootAnchorOf(internals, sessionId, ownOccupant) {
|
|
|
9
10
|
const occupant = root !== undefined ? internals?.rootSessionIncarnation : ownOccupant;
|
|
10
11
|
return { sessionId: root ?? sessionId, ...(occupant !== undefined ? { occupant } : {}) };
|
|
11
12
|
}
|
|
13
|
+
export function hookRootSessionIdOf(internals, sessionId, isDelegatedChild) {
|
|
14
|
+
if (internals?.rootSessionId !== undefined)
|
|
15
|
+
return internals.rootSessionId;
|
|
16
|
+
if (isDelegatedChild || internals?.observerLeg === true)
|
|
17
|
+
return undefined;
|
|
18
|
+
return sessionId;
|
|
19
|
+
}
|
|
20
|
+
const LEG_IDENTITY_MEMBERS = ["declaredTaskId", "parentTaskId", "rootSessionId", "rootSessionIncarnation", "rootSessionScope", "spawnName"];
|
|
21
|
+
const LEG_IDENTITY_WORDS = { subject: "a parked row's leg identity", unit: "member", moment: "when the row is read" };
|
|
22
|
+
const isFilledString = (v) => typeof v === "string" && v !== "";
|
|
23
|
+
export function legIdentityRecordOf(declaredTaskId, internals) {
|
|
24
|
+
const root = internals?.rootSessionId;
|
|
25
|
+
const scope = internals?.rootSessionScope;
|
|
26
|
+
const record = {};
|
|
27
|
+
if (declaredTaskId !== undefined && declaredTaskId !== "")
|
|
28
|
+
record.declaredTaskId = declaredTaskId;
|
|
29
|
+
if (internals?.parentTaskId !== undefined && internals.parentTaskId !== "")
|
|
30
|
+
record.parentTaskId = internals.parentTaskId;
|
|
31
|
+
if (root !== undefined && root !== "" && scope !== undefined && scope !== "") {
|
|
32
|
+
record.rootSessionId = root;
|
|
33
|
+
record.rootSessionScope = scope;
|
|
34
|
+
if (internals?.rootSessionIncarnation !== undefined && internals.rootSessionIncarnation !== "")
|
|
35
|
+
record.rootSessionIncarnation = internals.rootSessionIncarnation;
|
|
36
|
+
}
|
|
37
|
+
if (internals?.explicitAgentName !== undefined && internals.explicitAgentName !== "")
|
|
38
|
+
record.spawnName = internals.explicitAgentName;
|
|
39
|
+
return Object.keys(record).length > 0 ? record : undefined;
|
|
40
|
+
}
|
|
41
|
+
export function readLegIdentityRecord(raw) {
|
|
42
|
+
if (raw === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
45
|
+
return "damaged";
|
|
46
|
+
const keys = Object.keys(raw);
|
|
47
|
+
if (keys.length === 0 || strayMembersOf(raw, LEG_IDENTITY_WORDS, LEG_IDENTITY_MEMBERS) !== undefined)
|
|
48
|
+
return "damaged";
|
|
49
|
+
if (!keys.every((key) => isFilledString(raw[key])))
|
|
50
|
+
return "damaged";
|
|
51
|
+
const record = raw;
|
|
52
|
+
return (record.rootSessionIncarnation !== undefined || record.rootSessionScope !== undefined) && record.rootSessionId === undefined ? "damaged" : record;
|
|
53
|
+
}
|
|
12
54
|
export const SYNC_CHILD_BLOCK_MEMBERS = Object.freeze(["parentSessionId", "parentTaskId", "rootSessionId", "rootSessionIncarnation"]);
|
|
13
55
|
export function mintAskSourceIdentity(leg) {
|
|
14
56
|
const agentId = agentIdOf({ taskId: leg.taskId, isDelegatedChild: leg.isDelegatedChild });
|
|
@@ -44,9 +86,10 @@ export function noticeAddressOf(askSource, root) {
|
|
|
44
86
|
return { address: { sessionId: own } };
|
|
45
87
|
const rootId = root?.rootSessionId;
|
|
46
88
|
const address = { sessionId: rootId ?? own, sourceSessionId: own, ...(askSource.agentId !== undefined ? { agentId: askSource.agentId } : {}) };
|
|
47
|
-
|
|
89
|
+
const scope = root?.rootSessionScope;
|
|
90
|
+
return rootId !== undefined && rootId !== own ? { address, destination: { sessionId: rootId, occupant: root?.rootSessionIncarnation, ...(scope !== undefined ? { scope } : {}) } } : { address };
|
|
48
91
|
}
|
|
49
|
-
function legNoticeAdmission(route, judge) {
|
|
92
|
+
export function legNoticeAdmission(route, judge) {
|
|
50
93
|
const { address, destination } = route;
|
|
51
94
|
if (destination === undefined || judge === undefined)
|
|
52
95
|
return undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE LAUNCH CHECK of a run that directs workers and reports to a person (a run that declares a member ledger,
|
|
3
|
+
* `TaskSpec.runLedger`): before it spends anything, read whether the leg has what such a run needs, item by item, and say so —
|
|
4
|
+
* refuse when it cannot do the job at all, narrow (and say how) when it can do part of it, never start a manager that can only
|
|
5
|
+
* repeat its workers' words without saying that it can.
|
|
6
|
+
*
|
|
7
|
+
* A pure function over facts the leg's prepare reads; each item `ok`, `missing`, or `unknown` (the fact could not be read here —
|
|
8
|
+
* never shown as missing, and never a reason to narrow or refuse).
|
|
9
|
+
*/
|
|
10
|
+
/** The items, in the order they are read. */
|
|
11
|
+
export declare const MANAGER_LAUNCH_ITEMS: readonly ["background_delegation", "report_tool", "read_hands", "worker_transcript", "isolated_checks", "worker_write_approval", "task_list"];
|
|
12
|
+
export type ManagerLaunchItem = (typeof MANAGER_LAUNCH_ITEMS)[number];
|
|
13
|
+
export type ManagerLaunchState = "ok" | "missing" | "unknown";
|
|
14
|
+
/** `task.manager_launch_narrowed`: the run starts without some of what its job needs (the check's sentence). */
|
|
15
|
+
export declare function managerLaunchNarrowedNotice(c: ManagerLaunchCheck, ids: Record<string, string | undefined>): {
|
|
16
|
+
code: "task.manager_launch_narrowed";
|
|
17
|
+
message: string;
|
|
18
|
+
detail: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
export interface ManagerLaunchCheck {
|
|
21
|
+
/** `ready`: nothing missing; `narrowed`: something missing that the run can do without (said in `items`); `refused`. */
|
|
22
|
+
readonly verdict: "ready" | "narrowed" | "refused";
|
|
23
|
+
readonly items: ReadonlyArray<{
|
|
24
|
+
readonly item: ManagerLaunchItem;
|
|
25
|
+
readonly state: ManagerLaunchState;
|
|
26
|
+
readonly means?: string;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
/** The facts the check reads — each `undefined` when the leg cannot read it. */
|
|
30
|
+
export type ManagerLaunchFacts = Readonly<Record<ManagerLaunchItem, boolean | undefined>>;
|
|
31
|
+
/** The check over its facts — see the module head. */
|
|
32
|
+
export declare function managerLaunchCheck(facts: ManagerLaunchFacts): ManagerLaunchCheck;
|
|
33
|
+
/** What a prepared leg reads for the check: the names on its roster, whether its delegation lane launches in the background and
|
|
34
|
+
* its results come back on a lane, whether a person or a park can take its workers' asks, and whether it is one-shot. */
|
|
35
|
+
export interface ManagerLaunchLegReading {
|
|
36
|
+
readonly names: ReadonlySet<string>;
|
|
37
|
+
readonly backgroundAgents: boolean | undefined;
|
|
38
|
+
readonly completionLane: boolean;
|
|
39
|
+
readonly approver: boolean;
|
|
40
|
+
readonly parkStore: boolean;
|
|
41
|
+
readonly oneShot: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** The check's facts off a prepared leg's reading. A worker's writes have an approval route when the leg has an approver to hand
|
|
44
|
+
* down; they have none when there is no approver, no park store and the run is one-shot (nobody can be asked — the measured
|
|
45
|
+
* `delegation.ask_unresolvable`); every other case is not read here (`unknown`). */
|
|
46
|
+
export declare function managerLaunchFactsOf(r: ManagerLaunchLegReading): ManagerLaunchFacts;
|
|
47
|
+
/** The check as one sentence (the notice's message, the refusal's): what is missing and what that means. */
|
|
48
|
+
export declare function managerLaunchCheckSentence(c: ManagerLaunchCheck): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const MANAGER_LAUNCH_ITEMS = Object.freeze([
|
|
2
|
+
"background_delegation",
|
|
3
|
+
"report_tool",
|
|
4
|
+
"read_hands",
|
|
5
|
+
"worker_transcript",
|
|
6
|
+
"isolated_checks",
|
|
7
|
+
"worker_write_approval",
|
|
8
|
+
"task_list",
|
|
9
|
+
]);
|
|
10
|
+
const REFUSING = new Set(["background_delegation", "report_tool"]);
|
|
11
|
+
const NARROWED = {
|
|
12
|
+
background_delegation: "it cannot dispatch workers that report back, so it cannot direct anyone",
|
|
13
|
+
report_tool: "it has no report tool, so nothing it concludes reaches the person with the engine's ledger beside it",
|
|
14
|
+
read_hands: "it cannot read the work itself; it can only send workers to look",
|
|
15
|
+
worker_transcript: "it cannot read a worker's record; it sees only what each worker says",
|
|
16
|
+
isolated_checks: "checks that need running something go to a verification worker (no isolated environment for the manager's own checks)",
|
|
17
|
+
worker_write_approval: "a worker's writes will be refused: nobody on this run can approve them",
|
|
18
|
+
task_list: "the plan cannot be kept as a shared task list",
|
|
19
|
+
};
|
|
20
|
+
const ITEM_WORDS = {
|
|
21
|
+
background_delegation: "dispatching workers that report back",
|
|
22
|
+
report_tool: "the report tool",
|
|
23
|
+
read_hands: "reading the work",
|
|
24
|
+
worker_transcript: "reading a worker's record",
|
|
25
|
+
isolated_checks: "running checks in isolation",
|
|
26
|
+
worker_write_approval: "an approval route for the workers' writes",
|
|
27
|
+
task_list: "a shared task list",
|
|
28
|
+
};
|
|
29
|
+
export function managerLaunchNarrowedNotice(c, ids) {
|
|
30
|
+
return { code: "task.manager_launch_narrowed", message: managerLaunchCheckSentence(c), detail: { ...ids, launch: c } };
|
|
31
|
+
}
|
|
32
|
+
export function managerLaunchCheck(facts) {
|
|
33
|
+
const items = MANAGER_LAUNCH_ITEMS.map((item) => {
|
|
34
|
+
const v = facts[item];
|
|
35
|
+
const state = v === true ? "ok" : v === false ? "missing" : "unknown";
|
|
36
|
+
return Object.freeze({ item, state, ...(state === "missing" ? { means: NARROWED[item] } : {}) });
|
|
37
|
+
});
|
|
38
|
+
const missing = items.filter((i) => i.state === "missing");
|
|
39
|
+
const verdict = missing.some((i) => REFUSING.has(i.item)) ? "refused" : missing.length > 0 ? "narrowed" : "ready";
|
|
40
|
+
return Object.freeze({ verdict, items: Object.freeze(items) });
|
|
41
|
+
}
|
|
42
|
+
export function managerLaunchFactsOf(r) {
|
|
43
|
+
const has = (...names) => names.every((n) => r.names.has(n));
|
|
44
|
+
return {
|
|
45
|
+
background_delegation: r.backgroundAgents === undefined ? undefined : r.backgroundAgents && r.completionLane,
|
|
46
|
+
report_tool: has("SendUserMessage"),
|
|
47
|
+
read_hands: has("Read", "Grep", "Glob"),
|
|
48
|
+
worker_transcript: has("AgentTranscript"),
|
|
49
|
+
isolated_checks: false,
|
|
50
|
+
worker_write_approval: r.approver ? true : !r.parkStore && r.oneShot ? false : undefined,
|
|
51
|
+
task_list: has("TaskCreate", "TaskList"),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function managerLaunchCheckSentence(c) {
|
|
55
|
+
const missing = c.items.filter((i) => i.state === "missing");
|
|
56
|
+
const unknown = c.items.filter((i) => i.state === "unknown").map((i) => ITEM_WORDS[i.item]);
|
|
57
|
+
const said = missing.map((i) => i.means).join("; ");
|
|
58
|
+
const unread = unknown.length > 0 ? ` Not read here: ${unknown.join(", ")}.` : "";
|
|
59
|
+
if (c.verdict === "ready")
|
|
60
|
+
return `The launch check found everything this run needs.${unread}`;
|
|
61
|
+
if (c.verdict === "refused")
|
|
62
|
+
return `This run declares a member ledger but cannot do that job — ${said}.${unread}`;
|
|
63
|
+
return `This run starts narrowed — ${said}.${unread}`;
|
|
64
|
+
}
|
|
@@ -45,14 +45,14 @@ export declare const MCP_CALLER_META_KEY = "sema/caller";
|
|
|
45
45
|
* Who is calling: the identity facts of the leg a request is sent for, every one a value the engine already mints for the leg's own
|
|
46
46
|
* frames (none is minted for this record). Frozen, no prototype.
|
|
47
47
|
* - `taskId` — the leg's task id, minted once at prepare (`legTaskIdOf`): the value `TaskResult.taskId` and `task_progress.taskId` carry,
|
|
48
|
-
* whatever that reading answers on this run (the leg's registry row id,
|
|
48
|
+
* whatever that reading answers on this run (the leg's registry row id; on a ledger run, the host's task id if it gave one other than the session id, the id the parked row recorded on a resume, otherwise the minted `rl-…` id; else the host's task id or the leg's session id).
|
|
49
49
|
* - `runId` — this invocation of the engine (`Prepared.runId`): new on every run, a resume included.
|
|
50
50
|
* - `rootSessionId` — the delegation tree's root session (`rootAnchorOf`): the leg's own session on a top-level leg.
|
|
51
51
|
* - `parentTaskId` — the spawning leg's task id (`RunInternals.parentTaskId`, the value `task_progress.parentTaskId` carries); absent on a
|
|
52
52
|
* leg nobody spawned under a known task.
|
|
53
53
|
* Built once per leg and run, at prepare: every call and fetch of that run carries the same record. No principal, path, model or display
|
|
54
54
|
* name rides it. Session ids do: `taskId` is the leg's own session id wherever that is its task id (a foreground child, a workflow member
|
|
55
|
-
* or a top-level leg handed no task id), and `rootSessionId` is the tree root's session — independent of `sessionMetaKey`.
|
|
55
|
+
* or a non-ledger top-level leg handed no task id; on a ledger run the task id is the host's if it gave one other than the session id, the id the parked row recorded on a resume, otherwise the minted `rl-…` one), and `rootSessionId` is the tree root's session — independent of `sessionMetaKey`.
|
|
56
56
|
*/
|
|
57
57
|
export type McpCaller = Readonly<{
|
|
58
58
|
taskId: string;
|
|
@@ -41,9 +41,12 @@ import type { EngineNotice } from "./engine-notice.js";
|
|
|
41
41
|
* · `credentials_not_carried` — a request does not carry an MCP server's credentials, so the
|
|
42
42
|
* deployment has to mount this server itself: the recovery is the
|
|
43
43
|
* administrator's configuration or the entry without its credentials;
|
|
44
|
-
* `field` names the credentials key when the host knows it
|
|
44
|
+
* `field` names the credentials key when the host knows it;
|
|
45
|
+
* · `name_already_mounted` — an agent definition declared an MCP server whose normalized
|
|
46
|
+
* namespace is already mounted on the run (the run's server stays
|
|
47
|
+
* in use; the agent's duplicate entry was not mounted).
|
|
45
48
|
*/
|
|
46
|
-
export declare const MCP_INJECTION_DROP_REASONS: readonly ["malformed_entry", "name_reserved_by_deployment", "gate_closed", "over_cap", "key_retired", "credentials_not_carried"];
|
|
49
|
+
export declare const MCP_INJECTION_DROP_REASONS: readonly ["malformed_entry", "name_reserved_by_deployment", "gate_closed", "over_cap", "key_retired", "credentials_not_carried", "name_already_mounted"];
|
|
47
50
|
export type McpInjectionDropReason = (typeof MCP_INJECTION_DROP_REASONS)[number];
|
|
48
51
|
/**
|
|
49
52
|
* The user-facing sentence per reason — the disposition table over {@link MCP_INJECTION_DROP_REASONS}
|
|
@@ -57,9 +60,10 @@ export declare const MCP_INJECTION_DROP_TEXT: {
|
|
|
57
60
|
readonly over_cap: "the request named more MCP servers than this deployment mounts per leg — trim the list";
|
|
58
61
|
readonly key_retired: "its declaration carries a configuration key this service no longer accepts — update the application that sent this entry, or remove that key from the entry, then start a new session";
|
|
59
62
|
readonly credentials_not_carried: "requests do not carry credentials for MCP servers, so the deployment has to mount this one — ask an administrator to configure it in the deployment, or remove the credentials from this entry";
|
|
63
|
+
readonly name_already_mounted: "another server of that name is already mounted on this run and stays in use — rename the server in this agent's configuration, or remove the duplicate";
|
|
60
64
|
};
|
|
61
65
|
export type DropTextCoversEveryReason = AssertAllKeysHandled<Exclude<McpInjectionDropReason, keyof typeof MCP_INJECTION_DROP_TEXT>>;
|
|
62
|
-
/** What a host knows at the drop site — facts only, no words of the engine's vocabulary composed. */
|
|
66
|
+
/** What a host (or spawn merge) knows at the drop site — facts only, no words of the engine's vocabulary composed. */
|
|
63
67
|
export interface McpInjectionDropFacts {
|
|
64
68
|
/** The session whose injection carried the entry — the notice's routing key, required (see module note). */
|
|
65
69
|
readonly sessionId: string;
|
|
@@ -72,20 +76,26 @@ export interface McpInjectionDropFacts {
|
|
|
72
76
|
* carried in `detail` only.
|
|
73
77
|
*/
|
|
74
78
|
readonly field?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Optional: the agent definition that declared this server entry (for drops in host intake of
|
|
81
|
+
* agent-level MCP declarations and spawn-time collisions with a server already mounted on the run).
|
|
82
|
+
* Carried in `detail.entries[0].agent` and named in the message when non-empty.
|
|
83
|
+
*/
|
|
84
|
+
readonly agent?: string;
|
|
75
85
|
}
|
|
76
86
|
/**
|
|
77
|
-
* Compose the notice for one
|
|
87
|
+
* Compose the notice for one MCP server declaration that was not mounted, from drop facts: `config.entries_not_applied`,
|
|
78
88
|
* kind `mcp_injection_dropped` (until 7.70.0 its own code, `mcp.injection_dropped`).
|
|
79
89
|
*
|
|
80
|
-
* @contract mcp.injection_dropped.single_mint — the notice for a dropped
|
|
81
|
-
* from
|
|
82
|
-
*
|
|
90
|
+
* @contract mcp.injection_dropped.single_mint — the notice for a dropped MCP server declaration is composed by CORE
|
|
91
|
+
* from drop FACTS (session, server name, one of the closed reasons, optionally the bad field and declaring agent); a
|
|
92
|
+
* caller never spells the code, the audience or the sentence, and a fact outside the vocabulary (an
|
|
83
93
|
* unlisted reason word, an empty session or server name) is refused at the mint with a `TypeError`
|
|
84
94
|
* rather than shaped into a notice that would route nowhere or read as an unknown word downstream.
|
|
85
95
|
*
|
|
86
|
-
* `detail: { kind: "mcp_injection_dropped", entries: [{ entry, reason, field? }], count: 1, identity, sessionId }` — `entry` is the
|
|
87
|
-
* server's name as
|
|
88
|
-
*
|
|
96
|
+
* `detail: { kind: "mcp_injection_dropped", entries: [{ entry, reason, field?, agent? }], count: 1, identity, sessionId }` — `entry` is the
|
|
97
|
+
* server's name as spelled, `reason` one of {@link MCP_INJECTION_DROP_REASONS}, `field` and `agent` present only when supplied as
|
|
98
|
+
* non-empty strings; `sessionId` is lifted onto the typed key by {@link import("./engine-notice.js").deliverEngineNotice},
|
|
89
99
|
* the one throat, so the two spellings cannot disagree.
|
|
90
100
|
*/
|
|
91
101
|
export declare function mcpInjectionDroppedNotice(facts: McpInjectionDropFacts): EngineNotice;
|
|
@@ -6,6 +6,7 @@ export const MCP_INJECTION_DROP_REASONS = Object.freeze([
|
|
|
6
6
|
"over_cap",
|
|
7
7
|
"key_retired",
|
|
8
8
|
"credentials_not_carried",
|
|
9
|
+
"name_already_mounted",
|
|
9
10
|
]);
|
|
10
11
|
export const MCP_INJECTION_DROP_TEXT = {
|
|
11
12
|
malformed_entry: "its declaration could not be read — fix the entry and start a new session",
|
|
@@ -14,6 +15,7 @@ export const MCP_INJECTION_DROP_TEXT = {
|
|
|
14
15
|
over_cap: "the request named more MCP servers than this deployment mounts per leg — trim the list",
|
|
15
16
|
key_retired: "its declaration carries a configuration key this service no longer accepts — update the application that sent this entry, or remove that key from the entry, then start a new session",
|
|
16
17
|
credentials_not_carried: "requests do not carry credentials for MCP servers, so the deployment has to mount this one — ask an administrator to configure it in the deployment, or remove the credentials from this entry",
|
|
18
|
+
name_already_mounted: "another server of that name is already mounted on this run and stays in use — rename the server in this agent's configuration, or remove the duplicate",
|
|
17
19
|
};
|
|
18
20
|
const SENTENCE_NAMES_FIELD = {
|
|
19
21
|
malformed_entry: true,
|
|
@@ -22,10 +24,11 @@ const SENTENCE_NAMES_FIELD = {
|
|
|
22
24
|
over_cap: false,
|
|
23
25
|
key_retired: true,
|
|
24
26
|
credentials_not_carried: true,
|
|
27
|
+
name_already_mounted: false,
|
|
25
28
|
};
|
|
26
29
|
const isReason = (x) => typeof x === "string" && MCP_INJECTION_DROP_REASONS.includes(x);
|
|
27
30
|
export function mcpInjectionDroppedNotice(facts) {
|
|
28
|
-
const { sessionId, server, reason, field } = facts;
|
|
31
|
+
const { sessionId, server, reason, field, agent } = facts;
|
|
29
32
|
if (typeof sessionId !== "string" || sessionId.length === 0) {
|
|
30
33
|
throw new TypeError("mcpInjectionDroppedNotice: sessionId is required — a user-audience notice with no session routes nowhere");
|
|
31
34
|
}
|
|
@@ -36,10 +39,13 @@ export function mcpInjectionDroppedNotice(facts) {
|
|
|
36
39
|
throw new TypeError(`mcpInjectionDroppedNotice: reason ${JSON.stringify(reason)} is not one of ${MCP_INJECTION_DROP_REASONS.join("/")}`);
|
|
37
40
|
}
|
|
38
41
|
const fieldSeat = typeof field === "string" && field.length > 0 ? { field } : {};
|
|
42
|
+
const agentName = typeof agent === "string" && agent.length > 0 ? agent : undefined;
|
|
43
|
+
const agentSeat = agentName !== undefined ? { agent: agentName } : {};
|
|
39
44
|
const where = SENTENCE_NAMES_FIELD[reason] && typeof field === "string" && field.length > 0 ? ` (field \`${field}\`)` : "";
|
|
45
|
+
const source = agentName !== undefined ? `declared by agent "${agentName}"` : "from this request";
|
|
40
46
|
return {
|
|
41
47
|
code: "config.entries_not_applied",
|
|
42
|
-
message: `MCP server "${server}"
|
|
43
|
-
detail: { ...entriesNotAppliedDetail("mcp_injection_dropped", [{ entry: server, reason, ...fieldSeat }]), sessionId },
|
|
48
|
+
message: `MCP server "${server}" ${source} was not mounted: ${MCP_INJECTION_DROP_TEXT[reason]}${where}.`,
|
|
49
|
+
detail: { ...entriesNotAppliedDetail("mcp_injection_dropped", [{ entry: server, reason, ...fieldSeat, ...agentSeat }]), sessionId },
|
|
44
50
|
};
|
|
45
51
|
}
|
|
@@ -216,7 +216,8 @@ export interface McpServerSpec {
|
|
|
216
216
|
* spawned under a known task, the spawner's task id (`task_progress.parentTaskId`). One record per leg and run, built at its prepare, so
|
|
217
217
|
* every call and fetch of the run — every attempt of one call included — carries the same; two legs on one pooled connection each send
|
|
218
218
|
* their own. No principal, path or model rides it. Session ids do, with or without {@link sessionMetaKey}: `taskId` is the leg's own
|
|
219
|
-
* session id wherever that is its task id (a foreground child, a workflow member or a top-level leg handed no `taskId`
|
|
219
|
+
* session id wherever that is its task id (a foreground child, a workflow member or a top-level leg handed no `taskId` that keeps no
|
|
220
|
+
* member ledger — one that keeps one runs as the task id the engine minted for it, `rl-…`), and
|
|
220
221
|
* `rootSessionId` is the tree root's session (a top-level leg's own) — a deployment that must not let a server learn any session id does
|
|
221
222
|
* not declare this for it. Absent or `false` ⇒ nothing is sent.
|
|
222
223
|
*
|
|
@@ -44,7 +44,7 @@ export type MemberOutcomeWord = (typeof MEMBER_OUTCOMES)[number];
|
|
|
44
44
|
/** Membership test for {@link MemberOutcomeWord} — the word crosses process boundaries on the completion frames and the stored rows. */
|
|
45
45
|
export declare function isMemberOutcomeWord(v: unknown): v is MemberOutcomeWord;
|
|
46
46
|
/** What kind of member a row is. Grows by a word when a new holder mints rows (a peer task, a nested workflow). */
|
|
47
|
-
export declare const MEMBER_KINDS: readonly ["workflow_member", "subagent", "background_agent"];
|
|
47
|
+
export declare const MEMBER_KINDS: readonly ["workflow_member", "subagent", "background_agent", "workflow", "peer_task"];
|
|
48
48
|
export type MemberKind = (typeof MEMBER_KINDS)[number];
|
|
49
49
|
/**
|
|
50
50
|
* What ended the run whose end stopped a member (the closed set of {@link MemberOutcome.runEnd}`.cause`). The five stop words are the
|
|
@@ -215,7 +215,8 @@ export type MemberFacts = {
|
|
|
215
215
|
readonly runEnd?: MemberOutcome["runEnd"];
|
|
216
216
|
readonly refused?: MemberRefusals;
|
|
217
217
|
};
|
|
218
|
-
/** The ONE mint of a member's outcome. `kind` / `provenance` are the holder's
|
|
218
|
+
/** The ONE mint of a member's outcome. `kind` / `provenance` are the holder's; `kind` is carried as {@link isMemberOutcome} reads it
|
|
219
|
+
* (a string — a later release's word passes through). The outcome comes back sealed ({@link sealMemberOutcome}). */
|
|
219
220
|
export declare function memberOutcomeOf(kind: MemberKind, provenance: "live" | "replayed", facts: MemberFacts): MemberOutcome;
|
|
220
221
|
/**
|
|
221
222
|
* A background agent row's outcome, as the task registry mints it at the settle that wins the row (first writer wins): the winning
|
|
@@ -6,7 +6,7 @@ const MEMBER_OUTCOME_SET = new Set(MEMBER_OUTCOMES);
|
|
|
6
6
|
export function isMemberOutcomeWord(v) {
|
|
7
7
|
return MEMBER_OUTCOME_SET.has(v);
|
|
8
8
|
}
|
|
9
|
-
export const MEMBER_KINDS = Object.freeze(["workflow_member", "subagent", "background_agent"]);
|
|
9
|
+
export const MEMBER_KINDS = Object.freeze(["workflow_member", "subagent", "background_agent", "workflow", "peer_task"]);
|
|
10
10
|
export const RUN_END_CAUSES = Object.freeze(["turn_end", "one_shot_ceiling", "interrupt", "walltime", "turns", "budget", "signal"]);
|
|
11
11
|
const RUN_END_CAUSE_SET = new Set(RUN_END_CAUSES);
|
|
12
12
|
export function isRunEndCause(v) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { EntryCustodyReport } from "./file-backend.js";
|
|
2
|
+
import type { MemoryBackend } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A store's answer for one id it does not hold:
|
|
5
|
+
* - `never` — its record is whole and names no deletion of the id in this scope: the id is new to it;
|
|
6
|
+
* - `deleted` — its record names a deletion of the id in this scope; `rev` is the version deleted last, when carried;
|
|
7
|
+
* - `undecidable` — its record cannot say (the chain is damaged, an event id is contradicted, a deletion omits scope,
|
|
8
|
+
* the store keeps no custody face, or the read failed); `why` says which. `why` is the engine's sentence: every word in it
|
|
9
|
+
* the store wrote (an event id, a damage reason, a read's thrown text) went through `foreignLine` where it was put in.
|
|
10
|
+
*/
|
|
11
|
+
export type DeletionRecord = {
|
|
12
|
+
readonly kind: "never";
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: "deleted";
|
|
15
|
+
readonly rev?: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: "undecidable";
|
|
18
|
+
readonly why: string;
|
|
19
|
+
};
|
|
20
|
+
/** The precedence every reader of deletion evidence shares: a deletion the record names stands even when the rest of the
|
|
21
|
+
* record is impeached (a sound prefix proves it); otherwise an impeached record answers nothing; otherwise the id was
|
|
22
|
+
* never deleted. `deletedRev`: `undefined` = no deletion named, `null` = one named without its version. */
|
|
23
|
+
export declare function deletionRecordFrom(evidence: {
|
|
24
|
+
readonly deletedRev: string | null | undefined;
|
|
25
|
+
readonly sound: boolean;
|
|
26
|
+
readonly unsoundWhy?: string;
|
|
27
|
+
}): DeletionRecord;
|
|
28
|
+
/** The record one custody report (`custodyOf(id)`, the File store's or any backend's) gives for `id` in `scope`;
|
|
29
|
+
* `undefined` = the store has no custody face. A deletion event is a fact of its own scope (`scope` or legacy
|
|
30
|
+
* `from.scope`) and invisible from any other scope; one carrying no scope, or a contradicted `ev`, fails closed. */
|
|
31
|
+
export declare function deletionRecordOf(id: string, custody: EntryCustodyReport | undefined, scope: string): DeletionRecord;
|
|
32
|
+
/** The store's answer for an id a memory file carries in `scope` that no baseline of the mount names, given where the
|
|
33
|
+
* store holds it (`placement`): `held` when it holds it somewhere (the copy / rename lanes answer), otherwise its
|
|
34
|
+
* deletion record for `scope` — a placement that cannot be read answers `undecidable`, never `never`. */
|
|
35
|
+
export declare function unheldIdRecord(backend: MemoryBackend, id: string, scope: string, placement: {
|
|
36
|
+
readonly state: "absent" | "held" | "unknown";
|
|
37
|
+
}): Promise<DeletionRecord | {
|
|
38
|
+
readonly kind: "held";
|
|
39
|
+
}>;
|
|
40
|
+
/** The harvest's reason for not committing such a file: deleted ⇒ refused (the caller contains it); undecidable ⇒ deferred. */
|
|
41
|
+
export declare function unheldIdRefusal(record: Extract<DeletionRecord, {
|
|
42
|
+
kind: "deleted" | "undecidable";
|
|
43
|
+
}>): string;
|
|
44
|
+
/** Read the store's deletion record in `scope` for each id (its `custodyOf` face, one read per id). A store without the
|
|
45
|
+
* face, a throwing getter, or a read that throws answers `undecidable` for that id — never `never`. */
|
|
46
|
+
export declare function memoryDeletionRecords(backend: MemoryBackend, ids: Iterable<string>, scope: string): Promise<Map<string, DeletionRecord>>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { foreignLine } from "../protocol-http-auth.js";
|
|
2
|
+
import { thrownText } from "../thrown-value.js";
|
|
3
|
+
import { inlineUntrusted } from "../untrusted-text.js";
|
|
4
|
+
function deleteEventScope(ev) {
|
|
5
|
+
if (typeof ev["scope"] === "string" && ev["scope"].length > 0)
|
|
6
|
+
return ev["scope"];
|
|
7
|
+
const from = ev["from"];
|
|
8
|
+
if (from !== null && typeof from === "object") {
|
|
9
|
+
const fromScope = from.scope;
|
|
10
|
+
if (typeof fromScope === "string" && fromScope.length > 0)
|
|
11
|
+
return fromScope;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
export function deletionRecordFrom(evidence) {
|
|
16
|
+
if (evidence.deletedRev !== undefined)
|
|
17
|
+
return evidence.deletedRev === null ? { kind: "deleted" } : { kind: "deleted", rev: evidence.deletedRev };
|
|
18
|
+
if (!evidence.sound)
|
|
19
|
+
return { kind: "undecidable", why: evidence.unsoundWhy ?? "the store's deletion record is damaged" };
|
|
20
|
+
return { kind: "never" };
|
|
21
|
+
}
|
|
22
|
+
export function deletionRecordOf(id, custody, scope) {
|
|
23
|
+
if (typeof scope !== "string" || scope.length === 0)
|
|
24
|
+
throw new TypeError("deletionRecordOf: scope must be a non-empty string");
|
|
25
|
+
if (custody === undefined)
|
|
26
|
+
return { kind: "undecidable", why: "the store keeps no deletion record (it has no custodyOf face)" };
|
|
27
|
+
const seenEvs = new Set();
|
|
28
|
+
let deletedRev;
|
|
29
|
+
let scopelessDelete = false;
|
|
30
|
+
for (const ev of custody.events) {
|
|
31
|
+
if (typeof ev.ev === "string" && ev.ev.length > 0) {
|
|
32
|
+
if (seenEvs.has(ev.ev)) {
|
|
33
|
+
return { kind: "undecidable", why: `the store's deletion record carries event id "${foreignLine(ev.ev, 80)}" twice with conflicting payloads` };
|
|
34
|
+
}
|
|
35
|
+
seenEvs.add(ev.ev);
|
|
36
|
+
}
|
|
37
|
+
if (ev.channel !== "delete" || ev["id"] !== id)
|
|
38
|
+
continue;
|
|
39
|
+
const evScope = deleteEventScope(ev);
|
|
40
|
+
if (evScope === undefined) {
|
|
41
|
+
scopelessDelete = true;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (evScope !== scope)
|
|
45
|
+
continue;
|
|
46
|
+
deletedRev = typeof ev["rev"] === "string" && ev["rev"].length > 0 ? ev["rev"] : null;
|
|
47
|
+
}
|
|
48
|
+
if (scopelessDelete)
|
|
49
|
+
return { kind: "undecidable", why: "a deletion event for this id carries no scope — whether it deleted this scope's entry cannot be read" };
|
|
50
|
+
return deletionRecordFrom({ deletedRev, sound: custody.state === "complete", unsoundWhy: `the store's deletion record for this id is damaged${custody.reason !== undefined ? ` (${foreignLine(custody.reason, 200)})` : ""}` });
|
|
51
|
+
}
|
|
52
|
+
export async function unheldIdRecord(backend, id, scope, placement) {
|
|
53
|
+
if (placement.state === "held")
|
|
54
|
+
return { kind: "held" };
|
|
55
|
+
if (placement.state === "unknown")
|
|
56
|
+
return { kind: "undecidable", why: "where the store holds this id could not be read" };
|
|
57
|
+
return (await memoryDeletionRecords(backend, [id], scope)).get(id);
|
|
58
|
+
}
|
|
59
|
+
export function unheldIdRefusal(record) {
|
|
60
|
+
return record.kind === "deleted"
|
|
61
|
+
? "the memory store deleted the entry this file's id names — a deleted entry's bytes are never taken back; to keep the text, write it as a new note without the id line"
|
|
62
|
+
: `memory write deferred: this file carries an id the memory store does not hold, and whether the store deleted that entry cannot be read (${inlineUntrusted(record.why, 200)}) — not committed, so a deleted entry is never taken back; remove the id line to commit it as a new note`;
|
|
63
|
+
}
|
|
64
|
+
export async function memoryDeletionRecords(backend, ids, scope) {
|
|
65
|
+
if (typeof scope !== "string" || scope.length === 0)
|
|
66
|
+
throw new TypeError("memoryDeletionRecords: scope must be a non-empty string");
|
|
67
|
+
let face;
|
|
68
|
+
let faceErr;
|
|
69
|
+
try {
|
|
70
|
+
const raw = backend.custodyOf;
|
|
71
|
+
face = typeof raw === "function" ? raw : undefined;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
faceErr = foreignLine(thrownText(err), 200);
|
|
75
|
+
}
|
|
76
|
+
const out = new Map();
|
|
77
|
+
for (const id of ids) {
|
|
78
|
+
if (out.has(id))
|
|
79
|
+
continue;
|
|
80
|
+
if (faceErr !== undefined) {
|
|
81
|
+
out.set(id, { kind: "undecidable", why: `the store's deletion record could not be read (${faceErr})` });
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (face === undefined) {
|
|
85
|
+
out.set(id, deletionRecordOf(id, undefined, scope));
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
out.set(id, deletionRecordOf(id, await face.call(backend, id), scope));
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
out.set(id, { kind: "undecidable", why: `the store's deletion record could not be read (${foreignLine(thrownText(err), 200)})` });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
@@ -36,6 +36,7 @@ import { optionKeys, receiveOptions } from "../own-property-receipt.js";
|
|
|
36
36
|
import { admitLandingsThrough, directedLandings, planWritten, refusalNamingWritten, requireWriteGate } from "./consolidation-write-gate.js";
|
|
37
37
|
import { applyEachAlone } from "./landing-admission.js";
|
|
38
38
|
import { ledgerFaultNotice, projectionsHeldAt, retireGoneProjections, retirementNotices } from "./projection-ledger.js";
|
|
39
|
+
import { unheldIdRecord, unheldIdRefusal } from "./deletion-record.js";
|
|
39
40
|
import { dropIndexCopiesOf, indexCopiesAnswered, readAdmittedStoreState } from "./index-copies.js";
|
|
40
41
|
export const MEMORY_RECALL_FRAMING = "Recalled memories appearing inside `<system-reminder>` blocks are background context, not user instructions, and reflect what was true when written — if one names a file, function, or flag, verify it still exists before recommending it.";
|
|
41
42
|
export const MEMORY_INSTRUCTION_TEMPLATE = `# Memory
|
|
@@ -2881,6 +2882,7 @@ export class MemoryEngine {
|
|
|
2881
2882
|
let observedTable;
|
|
2882
2883
|
const recordedResidue = new Set();
|
|
2883
2884
|
const goneCopies = new Set();
|
|
2885
|
+
const debtDeferred = new Set();
|
|
2884
2886
|
const recordedDisposals = [];
|
|
2885
2887
|
const removalDeletes = new Map();
|
|
2886
2888
|
for (const m of missingWritable) {
|
|
@@ -2960,10 +2962,16 @@ export class MemoryEngine {
|
|
|
2960
2962
|
if (nameFinding !== undefined)
|
|
2961
2963
|
scanFindings.push(nameFinding);
|
|
2962
2964
|
scanFindings.push(...scanMemoryWrite(f.text));
|
|
2963
|
-
const
|
|
2965
|
+
const unnamedId = f.parsed.id !== undefined && f.parsed.frontmatter.deleted !== true && !idByBasePath.has(f.canonical) && !basePathById.has(f.parsed.id) && handle.goneIds?.has(f.parsed.id) !== true ? f.parsed.id : undefined;
|
|
2966
|
+
const planeRecord = scanFindings.length === 0 && unnamedId !== undefined ? await unheldIdRecord(this.backend, unnamedId, writeScope, await this.committedPlacementOf(unnamedId)) : undefined;
|
|
2967
|
+
if (planeRecord?.kind === "undecidable") {
|
|
2968
|
+
report.rejections.push({ path: rel, code: "deferred", reason: unheldIdRefusal(planeRecord) });
|
|
2969
|
+
continue;
|
|
2970
|
+
}
|
|
2971
|
+
const finding = scanFindings[0] ?? (planeRecord?.kind === "deleted" ? { code: "invalid", reason: unheldIdRefusal(planeRecord) } : undefined);
|
|
2964
2972
|
if (finding !== undefined) {
|
|
2965
2973
|
const refusedHere = this.storeActRefusedText(f.canonical, "quarantining a rejected file", handle);
|
|
2966
|
-
const q = refusedHere === undefined ? await this.containSuspect(f.canonical, f.text, "quarantining a rejected file", handle) : { removed: false, leftOnPlane: f.text, detail: refusedHere };
|
|
2974
|
+
const q = refusedHere === undefined ? await this.containSuspect(f.canonical, f.text, "quarantining a rejected file", handle, scanFindings.length === 0) : { removed: false, leftOnPlane: f.text, detail: refusedHere };
|
|
2967
2975
|
let contained = q.removed;
|
|
2968
2976
|
const priorId = idByBasePath.get(f.canonical);
|
|
2969
2977
|
if (priorId !== undefined) {
|
|
@@ -3076,11 +3084,8 @@ export class MemoryEngine {
|
|
|
3076
3084
|
if (debt !== undefined) {
|
|
3077
3085
|
const committed = await this.debtCommittedProjection(debt.entryId);
|
|
3078
3086
|
if (committed.state === "unknown") {
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
code: "deferred",
|
|
3082
|
-
reason: "memory write deferred: this file's recorded committed id could not be validated (committed state unreadable) — retried next harvest (fail-closed: a fresh mint here could duplicate the committed entry)",
|
|
3083
|
-
});
|
|
3087
|
+
debtDeferred.add(rel);
|
|
3088
|
+
report.rejections.push({ path: rel, code: "deferred", reason: "memory write deferred: this file's recorded committed id could not be validated (committed state unreadable) — retried next harvest (fail-closed: a fresh mint here could duplicate the committed entry)" });
|
|
3084
3089
|
continue;
|
|
3085
3090
|
}
|
|
3086
3091
|
if (committed.state === "valid" && committed.scope === writeScope && committed.slug === f.slug) {
|
|
@@ -3499,12 +3504,10 @@ export class MemoryEngine {
|
|
|
3499
3504
|
}
|
|
3500
3505
|
}
|
|
3501
3506
|
for (const r of refusedStage) {
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
});
|
|
3507
|
-
report.warnings.push(`${relative(handle.memoryDir, join(writableRoot, r.rel))}: earlier notes about this file committing under a fresh id are superseded — its commit was WITHDRAWN this harvest (deferred to the next)`);
|
|
3507
|
+
const dRel = relative(handle.memoryDir, join(writableRoot, r.rel));
|
|
3508
|
+
debtDeferred.add(dRel);
|
|
3509
|
+
report.rejections.push({ path: dRel, code: "deferred", reason: "memory write deferred: a concurrent writer's projection-debt claim stands at this seat — retried next harvest (committing without a protected id write-back could duplicate the concurrent entry)" });
|
|
3510
|
+
report.warnings.push(`${dRel}: earlier notes about this file committing under a fresh id are superseded — its commit was WITHDRAWN this harvest (deferred to the next)`);
|
|
3508
3511
|
}
|
|
3509
3512
|
if (lineageArmed) {
|
|
3510
3513
|
const remaining = stagedRows();
|
|
@@ -3759,6 +3762,7 @@ export class MemoryEngine {
|
|
|
3759
3762
|
await this.rebaseline(handle, new Set([...(report.degraded?.pending ?? []), ...stoodAsFound, ...records.filter((r) => r.parsed.unclosed === true).map((r) => r.rel)]), new Set([...report.rejections.map((r) => r.path), ...goneCopies]), report.degraded === undefined ? startedAt : (handle.planeBaseline?.at ?? startedAt));
|
|
3760
3763
|
if (carry && lineageSessionId !== undefined && report.degraded === undefined) {
|
|
3761
3764
|
const deferredSeats = [...new Set(report.rejections.filter((r) => r.code === "deferred").map((r) => r.path))];
|
|
3765
|
+
const allDebt = deferredSeats.every((p) => debtDeferred.has(p));
|
|
3762
3766
|
const shown = deferredSeats.slice(0, MAX_DISCLOSED_DEFERRED_SEATS);
|
|
3763
3767
|
const rest = deferredSeats.length - shown.length;
|
|
3764
3768
|
const seatList = `${shown.join(", ")}${rest > 0 ? ` (+${rest} more — see the rejections)` : ""}`;
|
|
@@ -3767,11 +3771,13 @@ export class MemoryEngine {
|
|
|
3767
3771
|
if (closed === "stale" && !report.warnings.includes(STALE_LEG_NOTE))
|
|
3768
3772
|
report.warnings.push(STALE_LEG_NOTE);
|
|
3769
3773
|
if (closed === "written" && deferredSeats.length > 0) {
|
|
3770
|
-
report.warnings.push(
|
|
3774
|
+
report.warnings.push(allDebt
|
|
3775
|
+
? `memory session account closed with ${deferredSeats.length} file(s) still DEFERRED on the model-visible plane — their projection-debt rows STAND and are re-judged by the next harvest's consult, not by this close: ${seatList}`
|
|
3776
|
+
: `memory session account closed with ${deferredSeats.length} file(s) still DEFERRED on the model-visible plane — re-judged by the next harvest, not by this close: ${seatList}`);
|
|
3771
3777
|
}
|
|
3772
3778
|
}
|
|
3773
3779
|
catch (err) {
|
|
3774
|
-
report.warnings.push(`memory session account close FAILED and its outcome is UNKNOWN (a failure after the ledger's journal commit still rolls forward, so the account may read closed at the next strict read; a failure before it leaves the ledger's PRIOR state — open, already closed, valve-closed or absent — unchanged, and an open one keeps future crash residue attributed, the over-holding safe side)${deferredSeats.length > 0 ? `; ${deferredSeats.length} file(s) also stay DEFERRED on the plane under standing projection-debt rows: ${seatList}` : ""}: ${thrownText(err)}`);
|
|
3780
|
+
report.warnings.push(`memory session account close FAILED and its outcome is UNKNOWN (a failure after the ledger's journal commit still rolls forward, so the account may read closed at the next strict read; a failure before it leaves the ledger's PRIOR state — open, already closed, valve-closed or absent — unchanged, and an open one keeps future crash residue attributed, the over-holding safe side)${deferredSeats.length > 0 ? `; ${deferredSeats.length} file(s) also stay DEFERRED on the plane${allDebt ? " under standing projection-debt rows" : ""}: ${seatList}` : ""}: ${thrownText(err)}`);
|
|
3775
3781
|
}
|
|
3776
3782
|
}
|
|
3777
3783
|
if (this.consolidation !== undefined && handle.writeScope !== null && opts?.sessionId !== undefined && report.ok) {
|
|
@@ -5914,8 +5920,10 @@ export class MemoryEngine {
|
|
|
5914
5920
|
return this.writeFailureText(err);
|
|
5915
5921
|
}
|
|
5916
5922
|
}
|
|
5917
|
-
async containSuspect(path, content, act, handle) {
|
|
5923
|
+
async containSuspect(path, content, act, handle, requireCapture = false) {
|
|
5918
5924
|
const capture = await captureIntoQuarantine(this.governanceStore, path, content);
|
|
5925
|
+
if (requireCapture && "failed" in capture)
|
|
5926
|
+
return { removed: false, leftOnPlane: content, detail: `${capture.failed} — file left on plane so its text is not lost` };
|
|
5919
5927
|
const refused = this.storeActRefusedText(path, act, handle);
|
|
5920
5928
|
if (refused !== undefined)
|
|
5921
5929
|
return { ...("name" in capture ? { dest: capture.name } : {}), removed: false, leftOnPlane: content, detail: "failed" in capture ? `${capture.failed}; ${refused}` : refused };
|