@sema-agent/core 7.56.0 → 7.58.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 +926 -0
- package/LICENSE +1 -1
- package/dist/agents/org-delivery-gate.js +3 -4
- package/dist/agents/peer-held-queue.d.ts +69 -49
- package/dist/agents/peer-held-queue.js +255 -106
- package/dist/agents/peer-session-drain.js +63 -43
- package/dist/agents/send-message-tool.js +3 -2
- package/dist/agents/subagent-steps.js +2 -4
- package/dist/agents/subagent.js +8 -8
- package/dist/brain/anthropic.js +16 -8
- package/dist/brain/open-responses.js +10 -8
- package/dist/brain/openai.js +11 -9
- package/dist/brain/provider-dialect.d.ts +3 -2
- package/dist/brain/provider-dialect.js +2 -2
- package/dist/brain/request-params.d.ts +6 -0
- package/dist/brain/request-params.js +14 -1
- package/dist/brain/route-adjudicator.js +2 -1
- package/dist/brain/stream-engine.d.ts +9 -0
- package/dist/brain/stream-engine.js +24 -10
- package/dist/brain/stream-shared.d.ts +5 -4
- package/dist/brain/stream-shared.js +4 -4
- package/dist/core/a2a.d.ts +2 -1
- package/dist/core/a2a.js +23 -10
- package/dist/core/allow-entry.d.ts +5 -11
- package/dist/core/allow-entry.js +19 -26
- package/dist/core/approval-object.d.ts +21 -5
- package/dist/core/approval-object.js +44 -17
- package/dist/core/ask-origin.d.ts +23 -4
- package/dist/core/ask-origin.js +5 -1
- package/dist/core/auto-compaction.d.ts +75 -6
- package/dist/core/auto-compaction.js +43 -27
- package/dist/core/auto-mode-directive.d.ts +29 -5
- package/dist/core/auto-mode-directive.js +38 -8
- package/dist/core/background-agent-store.d.ts +6 -2
- package/dist/core/background-agent-store.js +1 -1
- package/dist/core/checkpoint-requirements.d.ts +13 -1
- package/dist/core/checkpoint-requirements.js +4 -0
- package/dist/core/checkpoint-store.d.ts +44 -40
- package/dist/core/checkpoint-store.js +32 -14
- package/dist/core/cross-boundary-taint.js +4 -2
- package/dist/core/engine-notice.d.ts +4 -3
- package/dist/core/engine-notice.js +6 -0
- package/dist/core/file-history-store.d.ts +14 -8
- package/dist/core/file-history-store.js +14 -4
- package/dist/core/fs-write-gate-policy.d.ts +4 -2
- package/dist/core/fs-write-gate-policy.js +7 -3
- package/dist/core/gate-fold.js +6 -3
- package/dist/core/gate-lanes.js +13 -5
- package/dist/core/git-worktree-env.d.ts +53 -11
- package/dist/core/git-worktree-env.js +96 -12
- package/dist/core/hooks.d.ts +6 -3
- package/dist/core/hooks.js +12 -5
- package/dist/core/human-input-projection.d.ts +1 -0
- package/dist/core/human-input-projection.js +3 -0
- package/dist/core/locked-config.d.ts +15 -1
- package/dist/core/locked-config.js +38 -2
- package/dist/core/mailbox-store.d.ts +62 -1
- package/dist/core/mailbox-store.js +59 -0
- package/dist/core/mcp-call-meta.d.ts +66 -0
- package/dist/core/mcp-call-meta.js +103 -0
- package/dist/core/mcp-connection-pool.d.ts +3 -1
- package/dist/core/mcp-connection-pool.js +3 -1
- package/dist/core/mcp-failure.d.ts +7 -1
- package/dist/core/mcp-failure.js +10 -0
- package/dist/core/mcp-name-judge.d.ts +46 -0
- package/dist/core/mcp-name-judge.js +61 -0
- package/dist/core/mcp-probe.d.ts +5 -1
- package/dist/core/mcp-probe.js +3 -6
- package/dist/core/mcp-server-link.d.ts +5 -2
- package/dist/core/mcp-server-spec.d.ts +46 -18
- package/dist/core/mcp-server-spec.js +1 -18
- package/dist/core/mcp.d.ts +6 -14
- package/dist/core/mcp.js +85 -65
- package/dist/core/memory-engine/consolidation-driver.js +4 -3
- package/dist/core/memory-engine/distiller.js +26 -17
- package/dist/core/memory-engine/layout.js +5 -2
- package/dist/core/memory-engine/scope-contract.d.ts +45 -4
- package/dist/core/memory-engine/scope-contract.js +80 -11
- package/dist/core/mode-policy.d.ts +8 -5
- package/dist/core/mode-policy.js +5 -4
- package/dist/core/mods/host.js +1 -1
- package/dist/core/mods/kernel/dispatch.d.ts +3 -0
- package/dist/core/mods/kernel/dispatch.js +10 -8
- package/dist/core/mods/kernel/events.d.ts +5 -1
- package/dist/core/mods/kernel/events.js +1 -1
- package/dist/core/mods/kernel/registration.d.ts +5 -1
- package/dist/core/mods/kernel/site-rules.d.ts +3 -0
- package/dist/core/mods/kernel/site-rules.js +10 -0
- package/dist/core/mods/package.d.ts +23 -0
- package/dist/core/mods/package.js +118 -0
- package/dist/core/mods/stations.d.ts +2 -2
- package/dist/core/mods/stations.js +1 -1
- package/dist/core/mods/tool-call.d.ts +5 -1
- package/dist/core/mods/tool-call.js +12 -3
- package/dist/core/park-selfcheck.js +2 -0
- package/dist/core/path-guard-rows.d.ts +20 -0
- package/dist/core/path-guard-rows.js +11 -0
- package/dist/core/peer-seat.d.ts +186 -0
- package/dist/core/peer-seat.js +307 -0
- package/dist/core/permission-rule-consent.d.ts +5 -3
- package/dist/core/permission-rule-consent.js +20 -15
- package/dist/core/permission-rule-model.d.ts +43 -2
- package/dist/core/permission-rule-model.js +52 -8
- package/dist/core/permission-rule-org.js +1 -1
- package/dist/core/present-plan-tool.d.ts +10 -1
- package/dist/core/present-plan-tool.js +46 -2
- package/dist/core/protocol-http-auth.d.ts +56 -31
- package/dist/core/protocol-http-auth.js +71 -42
- package/dist/core/protocol-naming.d.ts +20 -0
- package/dist/core/protocol-naming.js +20 -3
- package/dist/core/read-only-shell.d.ts +20 -5
- package/dist/core/read-only-shell.js +29 -14
- package/dist/core/redaction-marks.d.ts +16 -0
- package/dist/core/redaction-marks.js +16 -0
- package/dist/core/redaction-passes.js +8 -9
- package/dist/core/remote-env.d.ts +37 -1
- package/dist/core/remote-env.js +11 -0
- package/dist/core/resume-startup-cause.d.ts +24 -2
- package/dist/core/resume-startup-cause.js +20 -1
- package/dist/core/retention.d.ts +41 -15
- package/dist/core/retention.js +59 -12
- package/dist/core/rewrite-rejudge.d.ts +37 -0
- package/dist/core/rewrite-rejudge.js +40 -0
- package/dist/core/roles.js +50 -7
- package/dist/core/run-origin.d.ts +40 -0
- package/dist/core/run-origin.js +37 -0
- package/dist/core/runner/advertised-writable-dirs.d.ts +57 -38
- package/dist/core/runner/advertised-writable-dirs.js +126 -0
- package/dist/core/runner/compact-session.d.ts +10 -0
- package/dist/core/runner/compact-session.js +202 -0
- package/dist/core/runner/compaction-call-options.d.ts +2 -2
- package/dist/core/runner/compaction-restate.d.ts +15 -6
- package/dist/core/runner/compaction-restate.js +28 -2
- package/dist/core/runner/compaction-seams.d.ts +21 -1
- package/dist/core/runner/compaction-seams.js +11 -8
- package/dist/core/runner/contracts.d.ts +36 -21
- package/dist/core/runner/derived-route-fallback.d.ts +13 -0
- package/dist/core/runner/derived-route-fallback.js +6 -0
- package/dist/core/runner/env-capability-census.d.ts +3 -2
- package/dist/core/runner/env-capability-census.js +9 -3
- package/dist/core/runner/gate-exit.d.ts +18 -4
- package/dist/core/runner/gate-exit.js +5 -1
- package/dist/core/runner/permission-rule-lanes.d.ts +7 -7
- package/dist/core/runner/permission-rule-lanes.js +17 -11
- package/dist/core/runner/prepare-acquire-reconcile.d.ts +3 -0
- package/dist/core/runner/prepare-acquire-reconcile.js +2 -1
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +2 -0
- package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
- package/dist/core/runner/prepare-config-doors.d.ts +14 -5
- package/dist/core/runner/prepare-config-doors.js +16 -13
- package/dist/core/runner/prepare-delegation-surface.d.ts +4 -0
- package/dist/core/runner/prepare-delegation-surface.js +15 -18
- package/dist/core/runner/prepare-gate-stations.js +1 -1
- package/dist/core/runner/prepare-hands-readface.d.ts +10 -4
- package/dist/core/runner/prepare-hands-readface.js +6 -1
- package/dist/core/runner/prepare-memory.d.ts +3 -0
- package/dist/core/runner/prepare-memory.js +19 -23
- package/dist/core/runner/prepare-park-ask.d.ts +2 -0
- package/dist/core/runner/prepare-park-ask.js +2 -2
- package/dist/core/runner/prepare-policy-chain.d.ts +4 -4
- package/dist/core/runner/prepare-policy-chain.js +4 -6
- package/dist/core/runner/prepare-protocol-tools.d.ts +4 -2
- package/dist/core/runner/prepare-protocol-tools.js +3 -3
- package/dist/core/runner/prepare-suspend-saga.d.ts +2 -0
- package/dist/core/runner/prepare-suspend-saga.js +2 -1
- package/dist/core/runner/prepare-task.d.ts +4 -1
- package/dist/core/runner/prepare-task.js +46 -37
- package/dist/core/runner/prepare-tool-disclosure-mount.d.ts +13 -0
- package/dist/core/runner/prepare-tool-disclosure-mount.js +13 -7
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -0
- package/dist/core/runner/prepare-wiring-manifest.js +2 -2
- package/dist/core/runner/prepare-workspace-restore.d.ts +3 -0
- package/dist/core/runner/prepare-workspace-restore.js +4 -4
- package/dist/core/runner/resume-admission.js +1 -1
- package/dist/core/runner/resume-checkpoint-screen.js +2 -0
- package/dist/core/runner/rewind-files.d.ts +2 -5
- package/dist/core/runner/rewind-files.js +9 -51
- package/dist/core/runner/run-harness-handlers.d.ts +3 -4
- package/dist/core/runner/run-harness-handlers.js +1 -8
- package/dist/core/runner/run-identity-wiring.js +1 -0
- package/dist/core/runner/run-leg.js +15 -22
- package/dist/core/runner/run-notification-lane.d.ts +2 -0
- package/dist/core/runner/run-notification-lane.js +5 -2
- package/dist/core/runner/run-recovery-lanes.js +3 -4
- package/dist/core/runner/run-settle-and-teardown.js +5 -11
- package/dist/core/runner/run-terminal-adoption.js +3 -4
- package/dist/core/runner/run-turn-boundary.js +3 -5
- package/dist/core/runner/runtask.d.ts +8 -1
- package/dist/core/runner/runtask.js +28 -34
- package/dist/core/runner/send-message-continuation.js +1 -1
- package/dist/core/runner/session-verb-doors.d.ts +28 -0
- package/dist/core/runner/session-verb-doors.js +48 -0
- package/dist/core/runner/session-write-ledger.d.ts +30 -0
- package/dist/core/runner/session-write-ledger.js +101 -0
- package/dist/core/runner/stream-settle-backstop.js +11 -14
- package/dist/core/runner/sub-agent-deny-lists.d.ts +25 -3
- package/dist/core/runner/sub-agent-deny-lists.js +21 -10
- package/dist/core/runner/teardown-bounded.d.ts +1 -0
- package/dist/core/runner/teardown-bounded.js +1 -0
- package/dist/core/runner/terminal-account.js +3 -3
- package/dist/core/runner/tool-end-body.js +1 -0
- package/dist/core/runner/tool-occurrence.d.ts +4 -1
- package/dist/core/runner/tool-occurrence.js +2 -1
- package/dist/core/runner/write-protection-station.d.ts +8 -2
- package/dist/core/runner/write-protection-station.js +2 -0
- package/dist/core/runner-deps.d.ts +4 -4
- package/dist/core/secret-env.d.ts +4 -0
- package/dist/core/secret-env.js +3 -0
- package/dist/core/sensitive-path-policy.js +6 -7
- package/dist/core/session-log-transfer.d.ts +24 -0
- package/dist/core/session-log-transfer.js +166 -0
- package/dist/core/session-policy-store.d.ts +7 -2
- package/dist/core/session-policy-store.js +1 -1
- package/dist/core/session-store.d.ts +84 -19
- package/dist/core/session-store.js +162 -24
- package/dist/core/session.d.ts +92 -1
- package/dist/core/shell-read-silence.js +1 -0
- package/dist/core/shell-wrapper-projection.d.ts +1 -1
- package/dist/core/steer-replay.d.ts +4 -2
- package/dist/core/steer-replay.js +2 -1
- package/dist/core/store-contracts/background-agent-store-contract.js +1 -0
- package/dist/core/store-contracts/checkpoint-store-contract.js +19 -1
- package/dist/core/store-contracts/file-history-store-contract.js +9 -0
- package/dist/core/store-contracts/mailbox-store-contract.js +49 -1
- package/dist/core/store-contracts/session-repo-contract.js +112 -5
- package/dist/core/store-contracts/session-store-contract.d.ts +4 -1
- package/dist/core/store-contracts/session-store-contract.js +236 -2
- package/dist/core/task-event.d.ts +68 -8
- package/dist/core/task-registry-agent.d.ts +8 -4
- package/dist/core/task-registry-agent.js +14 -8
- package/dist/core/task-registry-shared.d.ts +36 -6
- package/dist/core/task-registry-shared.js +11 -0
- package/dist/core/task-registry.d.ts +1 -1
- package/dist/core/task-registry.js +1 -1
- package/dist/core/task-spec.d.ts +37 -0
- package/dist/core/task-stream.d.ts +2 -1
- package/dist/core/terminal-cause.d.ts +1 -1
- package/dist/core/tool-catalog-entries.d.ts +6 -0
- package/dist/core/tool-catalog-entries.js +2 -0
- package/dist/core/tool-name-aliases.d.ts +32 -2
- package/dist/core/tool-name-aliases.js +23 -0
- package/dist/core/tool-name-readings.d.ts +4 -0
- package/dist/core/tool-name-readings.js +1 -0
- package/dist/core/tool-policy.d.ts +10 -6
- package/dist/core/tool-policy.js +4 -7
- package/dist/core/tool-result-store.d.ts +17 -10
- package/dist/core/tool-result-store.js +3 -1
- package/dist/core/trace.d.ts +4 -1
- package/dist/core/trace.js +2 -1
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +18 -0
- package/dist/core/untrusted-egress.js +82 -12
- package/dist/core/wiring-manifest.d.ts +12 -3
- package/dist/core/wiring-manifest.js +4 -3
- package/dist/core/workspace-snapshot.d.ts +44 -0
- package/dist/core/workspace-snapshot.js +34 -0
- package/dist/core/write-protect.d.ts +43 -3
- package/dist/core/write-protect.js +43 -16
- package/dist/engine/execution-env/node-execution-env.js +15 -11
- package/dist/engine/execution-env/symlink-chain.d.ts +7 -5
- package/dist/engine/harness/agent-harness.d.ts +12 -5
- package/dist/engine/harness/agent-harness.js +13 -2
- package/dist/engine/harness/types.d.ts +48 -7
- package/dist/engine/harness/types.js +5 -1
- package/dist/engine/llm/types.d.ts +12 -3
- package/dist/engine/llm/types.js +1 -1
- package/dist/engine/loop/agent-loop.d.ts +1 -4
- package/dist/engine/loop/agent-loop.js +26 -4
- package/dist/engine/session/import-validate.js +3 -0
- package/dist/engine/session/memory-repo.d.ts +17 -9
- package/dist/engine/session/memory-repo.js +44 -34
- package/dist/engine/session/repo-utils.d.ts +22 -4
- package/dist/engine/session/repo-utils.js +49 -1
- package/dist/engine/session/storage-base.d.ts +10 -1
- package/dist/engine/session/storage-base.js +7 -1
- package/dist/index.d.ts +23 -11
- package/dist/index.js +15 -6
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/internal/harness.d.ts +4 -3
- package/dist/internal/harness.js +3 -2
- package/dist/stores/file/checkpoint-store.d.ts +0 -4
- package/dist/stores/file/checkpoint-store.js +0 -1
- package/dist/stores/file/file-history-store.js +12 -4
- package/dist/stores/file/index.d.ts +4 -1
- package/dist/stores/file/index.js +4 -1
- package/dist/stores/file/mailbox-store.d.ts +2 -1
- package/dist/stores/file/mailbox-store.js +26 -1
- package/dist/stores/file/session-store.d.ts +15 -8
- package/dist/stores/file/session-store.js +28 -13
- package/dist/tools/fs/bash-readonly-classifier.d.ts +15 -19
- package/dist/tools/fs/bash-readonly-classifier.js +5 -10
- package/dist/tools/fs/fs-bash.js +10 -3
- package/dist/tools/fs/fs-write.d.ts +6 -3
- package/dist/tools/fs/fs-write.js +8 -7
- package/dist/tools/fs/index.d.ts +3 -0
- package/dist/tools/fs/index.js +1 -1
- package/dist/tools/fs/pattern-kill-guard.d.ts +3 -2
- package/dist/tools/fs/pattern-kill-guard.js +68 -36
- package/dist/tools/fs/safety.js +40 -8
- package/dist/tools/fs/search.js +6 -24
- package/dist/tools/fs/shell-read-check.d.ts +18 -1
- package/dist/tools/fs/shell-read-check.js +66 -16
- package/dist/tools/fs/shell-read-establish.js +2 -1
- package/dist/tools/fs/shell-read-identity.d.ts +12 -9
- package/dist/tools/fs/shell-read-identity.js +10 -5
- package/dist/tools/fs/shell-read-judge.d.ts +10 -1
- package/dist/tools/web.js +9 -7
- package/dist/tools/worktree.d.ts +42 -15
- package/dist/tools/worktree.js +60 -32
- package/package.json +4 -2
- package/test/export-surface.snapshot.json +141 -3
- package/wire-changes/core-stores-sql@7.57.0.json +29 -0
- package/wire-changes/core-stores-sql@7.58.0.json +29 -0
- package/wire-changes/core@7.57.0.json +1487 -0
- package/wire-changes/core@7.58.0.json +2188 -0
- package/wire-changes/mods-kernel@7.57.0.json +29 -0
- package/wire-changes/mods-kernel@7.58.0.json +81 -0
- package/wire-changes/primitives@7.57.0.json +245 -0
- package/wire-changes/primitives@7.58.0.json +29 -0
package/dist/core/gate-lanes.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { argsAsTheToolReads, withArgsReading } from "./effective-path-target.js";
|
|
2
2
|
import { attest, attestationOf, bindableArgsOf, decisionText, foldHookAsk, refusalOf, refuseOutOfContractDecision } from "./tool-policy.js";
|
|
3
|
-
import { outletAsk, readRejudge, rewriteChasedSentence, screenRewrite } from "./rewrite-rejudge.js";
|
|
3
|
+
import { APPROVER_AUTHOR, extensionAuthors, noteRewrite, outletAsk, POLICY_AUTHOR, readRejudge, rewriteChasedSentence, screenRewrite } from "./rewrite-rejudge.js";
|
|
4
4
|
import { arbitrateByMode, classifyAsk, decisionAskClassesOf, dontAskRefusalMessage, fileCommandOptionsSentence, persistedRuleMandateOf, safetyAxisOf, stampAskOrigin } from "./ask-origin.js";
|
|
5
5
|
import { classifierParseFailureDenyMessage, denialLimitFallbackMessage, rungDidNotRule, unarmedWindow } from "./auto-mode.js";
|
|
6
6
|
import { classifierNoRulingArm, settleNoRulingAsk } from "./classifier-unavailable-arm.js";
|
|
7
7
|
import { SETTLEMENT_NOBODY_JUDGED } from "./gate-outcome.js";
|
|
8
8
|
import { inlineUntrusted } from "./untrusted-text.js";
|
|
9
9
|
import { ASK_USER_QUESTION_TOOL_NAME, isEngineQuestionFace } from "./ask-question.js";
|
|
10
|
-
import {
|
|
10
|
+
import { routesContent } from "./tool-catalog-entries.js";
|
|
11
11
|
import { applyPersistedTightening, disclosedRuleSet } from "./persisted-rule-arms.js";
|
|
12
12
|
import { skillAllowDecision, skillRowRefusal } from "./skill-grant.js";
|
|
13
13
|
import { allowRuleShadowOf, withAllowRuleShadow } from "./allow-entry.js";
|
|
@@ -27,7 +27,6 @@ import { readStationAnswer } from "./shell-read-silence.js";
|
|
|
27
27
|
import { agentIdOf, judgedInputOf, raiseToolCheck } from "./mods/stations.js";
|
|
28
28
|
import { extensionAllowOf, readToolChecks } from "./tool-check-reading.js";
|
|
29
29
|
import { policyThrowLine, reportPolicyThrow } from "./runner/policy-throw.js";
|
|
30
|
-
const routesContent = engineMountedAs(["ask-user-question", "structured-output", "report-blocked"]);
|
|
31
30
|
function parkWith(suspendAsk, parkArgs, carry) {
|
|
32
31
|
return suspendAsk(...parkArgs, carry);
|
|
33
32
|
}
|
|
@@ -78,6 +77,7 @@ export async function runGateLanes(pass) {
|
|
|
78
77
|
requiresUserInteraction: input.requiresUserInteraction,
|
|
79
78
|
probeUnanswered: pass.probeUnanswered === true,
|
|
80
79
|
writeProtected: pass.writeProtected === true,
|
|
80
|
+
writeProtectedOnDisk: pass.writeProtectedOnDisk === true,
|
|
81
81
|
targetUnresolved: pass.targetUnresolved === true,
|
|
82
82
|
});
|
|
83
83
|
const readFaceNow = input.readFace?.();
|
|
@@ -336,7 +336,7 @@ export async function runGateLanes(pass) {
|
|
|
336
336
|
const command = typeof args === "object" && args !== null && !Array.isArray(args) ? args[commandParam] : undefined;
|
|
337
337
|
const backgrounded = typeof args === "object" && args !== null && args.run_in_background === true;
|
|
338
338
|
const shape = typeof command === "string" ? readShellCommand(command) : undefined;
|
|
339
|
-
if (typeof command === "string" && shape !== undefined && !backgrounded && readOnlyShellVerdict(command, shape, input.trackedCwd?.()).readOnly) {
|
|
339
|
+
if (typeof command === "string" && shape !== undefined && !backgrounded && readOnlyShellVerdict(command, { shape, cwd: input.trackedCwd?.() }).readOnly) {
|
|
340
340
|
pass.decision = {
|
|
341
341
|
action: "allow",
|
|
342
342
|
message: "the command is read-only (upstream's read-only command tables) — allowed without asking",
|
|
@@ -554,6 +554,7 @@ export async function runGateLanes(pass) {
|
|
|
554
554
|
}
|
|
555
555
|
if (approvedWithArgs && pass.decision.action === "allow" && pass.decision.updatedInput !== undefined) {
|
|
556
556
|
let editArgs = pass.decision.updatedInput;
|
|
557
|
+
let shownToApprover = { bytes: pass.policyRewrite ?? pass.currentInput };
|
|
557
558
|
let editDenied;
|
|
558
559
|
let editAnswer = pass.decision;
|
|
559
560
|
let unanswered;
|
|
@@ -568,6 +569,9 @@ export async function runGateLanes(pass) {
|
|
|
568
569
|
return await untakenValueExit(pass, { value: editArgs, message: taken.refusal, deniedBy: "ask_resolution" });
|
|
569
570
|
}
|
|
570
571
|
editArgs = argsAsTheToolReads(pass.req, taken.value);
|
|
572
|
+
if (shownToApprover !== undefined)
|
|
573
|
+
noteRewrite(pass.rewrites, pass.req, shownToApprover.bytes, editArgs, APPROVER_AUTHOR);
|
|
574
|
+
shownToApprover = undefined;
|
|
571
575
|
if (round >= 3) {
|
|
572
576
|
editDenied = {
|
|
573
577
|
action: "deny",
|
|
@@ -579,7 +583,7 @@ export async function runGateLanes(pass) {
|
|
|
579
583
|
let editHookAsk;
|
|
580
584
|
let rewrittenEdit = false;
|
|
581
585
|
if (screening !== undefined) {
|
|
582
|
-
const screened = await screening.screen(editArgs, `the approved edit for "${toolName}"
|
|
586
|
+
const screened = await screening.screen(editArgs, `the approved edit for "${toolName}"`, pass.req);
|
|
583
587
|
if (screened.kind === "refused") {
|
|
584
588
|
editDenied = { action: "deny", message: screened.reason };
|
|
585
589
|
pass.deniedBy = "hook";
|
|
@@ -600,6 +604,7 @@ export async function runGateLanes(pass) {
|
|
|
600
604
|
}
|
|
601
605
|
const hookRead = readRejudge(pass.req, editArgs, hr);
|
|
602
606
|
if (hookRead.kind === "rewritten") {
|
|
607
|
+
noteRewrite(pass.rewrites, pass.req, editArgs, hookRead.form, extensionAuthors(screened.rewrittenBy ?? []));
|
|
603
608
|
editArgs = hookRead.form;
|
|
604
609
|
rewrittenEdit = true;
|
|
605
610
|
}
|
|
@@ -643,6 +648,7 @@ export async function runGateLanes(pass) {
|
|
|
643
648
|
pass.deniedBy = "policy";
|
|
644
649
|
break;
|
|
645
650
|
}
|
|
651
|
+
noteRewrite(pass.rewrites, pass.req, editArgs, policyRead.form, POLICY_AUTHOR);
|
|
646
652
|
editArgs = policyRead.form;
|
|
647
653
|
rewrittenEdit = true;
|
|
648
654
|
const second = screening !== undefined ? await screenRewrite(screening, pass.req, editArgs, `the rewritten edit for "${toolName}"`) : undefined;
|
|
@@ -721,6 +727,7 @@ export async function runGateLanes(pass) {
|
|
|
721
727
|
}
|
|
722
728
|
if (editRead?.kind === "approved") {
|
|
723
729
|
carriedOwnAsk = editRead.outstanding ?? (editDecision.action === "ask" ? editDecision : undefined);
|
|
730
|
+
shownToApprover = { bytes: editArgs };
|
|
724
731
|
editArgs = editRead.allow.updatedInput;
|
|
725
732
|
editAnswer = editRead.allow;
|
|
726
733
|
continue;
|
|
@@ -767,6 +774,7 @@ export async function runGateLanes(pass) {
|
|
|
767
774
|
if (rr.updatedInput === undefined) {
|
|
768
775
|
break;
|
|
769
776
|
}
|
|
777
|
+
shownToApprover = { bytes: editArgs };
|
|
770
778
|
editArgs = rr.updatedInput;
|
|
771
779
|
editAnswer = rr;
|
|
772
780
|
if (editAskDecision.action === "ask")
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import type { ExecutionEnv } from "../internal/harness-types.js";
|
|
2
|
-
/**
|
|
3
|
-
* userland reaper
|
|
4
|
-
|
|
2
|
+
/** The managed parent (under the repository root) that holds every managed worktree — the reference implementation's
|
|
3
|
+
* `.claude/worktrees/` under this project's brand — so {@link pruneWorktrees} and a userland reaper find orphans by one known
|
|
4
|
+
* location. Every tree the engine mints lives at `<repoRoot>/.sema/worktrees/<slug>` (see {@link managedWorktreeDir}). */
|
|
5
|
+
export declare const WORKTREE_PARENT = ".sema/worktrees";
|
|
6
|
+
/** Why `name` is not a managed worktree name, or `undefined` when it is one. */
|
|
7
|
+
export declare function worktreeNameProblem(name: string): string | undefined;
|
|
8
|
+
/** THE managed location of the tree named `name` under `repoRoot`. */
|
|
9
|
+
export declare function managedWorktreeDir(repoRoot: string, name: string): string;
|
|
10
|
+
/** The checkout a managed worktree directory was minted under — `dir` minus its `/.sema/worktrees/<slug>` tail — or `undefined`
|
|
11
|
+
* when `dir` is not shaped as a managed tree. Literal, byte-exact segments (no case fold): this answer EXEMPTS, and a fold
|
|
12
|
+
* would widen an exemption. */
|
|
13
|
+
export declare function managedWorktreeBaseOf(dir: string): string | undefined;
|
|
14
|
+
/** The branch the path law gives the managed tree at `dir` (`sema/<slug>`), or `undefined` when `dir` is not a managed tree —
|
|
15
|
+
* what a recorded branch must equal before anything deletes it (a record cannot name some other branch for removal). */
|
|
16
|
+
export declare function managedWorktreeBranchOf(dir: string): string | undefined;
|
|
5
17
|
export interface AddWorktreeOptions {
|
|
6
18
|
/** The base repository root — where `git worktree add` runs (the base env's cwd is typically this). */
|
|
7
19
|
repoRoot: string;
|
|
8
|
-
/** Stable per-task identity
|
|
20
|
+
/** Stable per-task identity: with no {@link name}, the tree's name is this (sanitized) plus a random suffix — a fresh name
|
|
21
|
+
* per mint, for the lanes that mint one tree per child. */
|
|
9
22
|
sessionId: string;
|
|
23
|
+
/** The managed name ({@link worktreeNameProblem} grammar), used as given: the tree lands at `.sema/worktrees/<slug>` on the
|
|
24
|
+
* new branch `sema/<slug>`. A name whose directory or branch already exists is refused, never reused or reset. */
|
|
25
|
+
name?: string;
|
|
10
26
|
/**
|
|
11
27
|
* How to build a worktree-ROOTED {@link ExecutionEnv} for THIS env type — the only env-specific bit. Local:
|
|
12
28
|
* `(dir) => new NodeExecutionEnv({ cwd: dir })`. A single-E2B deployment: an E2B env whose cwd is `dir`. The
|
|
@@ -17,16 +33,39 @@ export interface AddWorktreeOptions {
|
|
|
17
33
|
commit?: string;
|
|
18
34
|
}
|
|
19
35
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
36
|
+
* Remove a managed worktree and — by the ONE branch rule — its branch: the branch is deleted only when its tip is still the
|
|
37
|
+
* commit the tree was minted at (it carries nothing the tree made); otherwise it is kept, so commits made in the tree stay
|
|
38
|
+
* reachable after the directory is gone. The branch half is best-effort (a branch left behind is a name, not an orphaned
|
|
39
|
+
* directory) and reported as `branchKept`.
|
|
40
|
+
*
|
|
41
|
+
* server [1796]②: the worktree removal itself used to be fire-and-forget — a transient failure (spawn EAGAIN/EMFILE under
|
|
42
|
+
* load) then left the directory AND its registration behind, which `git worktree prune` can never reclaim (prune only
|
|
43
|
+
* deregisters worktrees whose directory is gone). Check the result, retry once (the observed failures are transient),
|
|
44
|
+
* and report the outcome.
|
|
45
|
+
*/
|
|
46
|
+
export declare function removeManagedWorktree(baseEnv: ExecutionEnv, repoRoot: string, worktreeDir: string, branch?: {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly baseSha: string;
|
|
49
|
+
}): Promise<{
|
|
50
|
+
ok: true;
|
|
51
|
+
branchDeleted?: string;
|
|
52
|
+
branchKept?: string;
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
detail: string;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* design/97 CORE-6 — the env-agnostic git-WORKTREE isolation primitive, and the engine's ONE worktree mint. Creates a managed
|
|
59
|
+
* worktree at `<repoRoot>/.sema/worktrees/<slug>` on the new branch `sema/<slug>` (via the BASE env's shell, refusing when
|
|
60
|
+
* any level of that path is a symlink) and returns a worktree-ROOTED ExecutionEnv (built by `rootEnvAt`) whose `destroy()`
|
|
61
|
+
* removes the worktree (and its branch, by the branch rule of {@link removeManagedWorktree}). A control-plane
|
|
62
|
+
* `executionEnvFactory` calls this when its `ctx.isolation === "worktree"` and returns the result (with `destroy`); for a
|
|
63
|
+
* non-isolated task it returns the SHARED base env (no `destroy`) so the Runner never tears the base down.
|
|
25
64
|
*
|
|
26
65
|
* ISOLATE-ONLY: the runtime never merges — the orchestrator script reads each worktree's result and
|
|
27
66
|
* decides verify/merge in userland. Caveats: `git worktree` isolates the git WORKING COPY, not
|
|
28
67
|
* arbitrary shell access (bash can still reach the host — sandbox separately); UNCOMMITTED changes in the base
|
|
29
|
-
* repo are absent in the child (
|
|
68
|
+
* repo are absent in the child (the tree starts at the base commit); a worktree orphaned by a process crash is reaped by
|
|
30
69
|
* {@link pruneWorktrees} (userland — there is no Runner hook for post-kill cleanup).
|
|
31
70
|
*/
|
|
32
71
|
export declare function addWorktree(baseEnv: ExecutionEnv, opts: AddWorktreeOptions): Promise<{
|
|
@@ -34,13 +73,16 @@ export declare function addWorktree(baseEnv: ExecutionEnv, opts: AddWorktreeOpti
|
|
|
34
73
|
destroy(): Promise<void>;
|
|
35
74
|
};
|
|
36
75
|
worktreeDir: string;
|
|
76
|
+
name: string;
|
|
77
|
+
branch: string;
|
|
78
|
+
baseSha?: string;
|
|
37
79
|
}>;
|
|
38
80
|
/** Reap orphaned worktrees (after a crash removed their dirs) — `git worktree prune` deregisters them. A userland
|
|
39
81
|
* reaper calls this periodically against the base repo; core ships no post-kill Runner hook.
|
|
40
82
|
*
|
|
41
83
|
* HRD-PTL-11: the exec Result used to be discarded, so every caller had to ASSUME the prune landed — and
|
|
42
84
|
* ExitWorktree's "already gone externally" leg told the model "stale git worktree metadata was pruned"
|
|
43
|
-
* on a claim it could not have checked. Same fail-loud treatment {@link
|
|
85
|
+
* on a claim it could not have checked. Same fail-loud treatment {@link removeManagedWorktree} already got
|
|
44
86
|
* Report the outcome, let the caller decide what to say. Never throws (a throwing env
|
|
45
87
|
* lands on the same `{ok:false}`), so a caller that ignores the value behaves exactly as before. */
|
|
46
88
|
export declare function pruneWorktrees(baseEnv: ExecutionEnv, repoRoot: string): Promise<{
|
|
@@ -1,28 +1,107 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { thrownLabel, thrownText } from "./thrown-value.js";
|
|
3
|
-
export const WORKTREE_PARENT = ".sema
|
|
3
|
+
export const WORKTREE_PARENT = ".sema/worktrees";
|
|
4
|
+
const WORKTREE_BRANCH_PREFIX = "sema";
|
|
5
|
+
const NAME_SEGMENT = /^[a-zA-Z0-9._-]+$/;
|
|
6
|
+
const NAME_MAX = 64;
|
|
7
|
+
export function worktreeNameProblem(name) {
|
|
8
|
+
if (name.length > NAME_MAX)
|
|
9
|
+
return `Invalid worktree name: must be ${NAME_MAX} characters or fewer (got ${name.length})`;
|
|
10
|
+
for (const segment of name.split("/")) {
|
|
11
|
+
if (segment === "." || segment === "..")
|
|
12
|
+
return `Invalid worktree name "${name}": must not contain "." or ".." path segments`;
|
|
13
|
+
if (segment.toLowerCase().replace(/\.+$/, "") === ".git")
|
|
14
|
+
return `Invalid worktree name "${name}": "${segment}" is a reserved git directory name`;
|
|
15
|
+
if (!NAME_SEGMENT.test(segment))
|
|
16
|
+
return `Invalid worktree name "${name}": each "/"-separated segment must be non-empty and contain only letters, digits, dots, underscores, and dashes`;
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
function slugOf(name) {
|
|
21
|
+
return name.replaceAll("/", "+");
|
|
22
|
+
}
|
|
23
|
+
export function managedWorktreeDir(repoRoot, name) {
|
|
24
|
+
return `${repoRoot}/${WORKTREE_PARENT}/${slugOf(name)}`;
|
|
25
|
+
}
|
|
26
|
+
export function managedWorktreeBaseOf(dir) {
|
|
27
|
+
const parts = dir.split("/");
|
|
28
|
+
if (parts.length < 4)
|
|
29
|
+
return undefined;
|
|
30
|
+
const [dot, parent, slug] = parts.slice(-3);
|
|
31
|
+
if (dot !== ".sema" || parent !== "worktrees" || slug === undefined || slug === "" || slug === "." || slug === "..")
|
|
32
|
+
return undefined;
|
|
33
|
+
const base = parts.slice(0, -3).join("/");
|
|
34
|
+
return base === "" ? "/" : base;
|
|
35
|
+
}
|
|
36
|
+
export function managedWorktreeBranchOf(dir) {
|
|
37
|
+
if (managedWorktreeBaseOf(dir) === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
return `${WORKTREE_BRANCH_PREFIX}/${dir.slice(dir.lastIndexOf("/") + 1)}`;
|
|
40
|
+
}
|
|
4
41
|
function shq(s) {
|
|
5
42
|
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
6
43
|
}
|
|
7
|
-
async function
|
|
44
|
+
async function symlinkedLevel(env, repoRoot, worktreeDir) {
|
|
45
|
+
for (const level of [`${repoRoot}/.sema`, `${repoRoot}/${WORKTREE_PARENT}`, worktreeDir]) {
|
|
46
|
+
const info = await env.fileInfo(level);
|
|
47
|
+
if (!info.ok) {
|
|
48
|
+
if (info.error.code === "not_found")
|
|
49
|
+
continue;
|
|
50
|
+
return `Cannot create worktree: failed to read ${level} (${thrownText(info.error)}); a level of the managed path whose kind is unknown could be a symlink. Nothing was created.`;
|
|
51
|
+
}
|
|
52
|
+
if (info.value.kind === "symlink") {
|
|
53
|
+
return `Cannot create worktree: ${level} is a symlink. A symlink at .sema, .sema/worktrees or .sema/worktrees/<name> could redirect worktree creation outside the repository. Remove the symlink and retry.`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
export async function removeManagedWorktree(baseEnv, repoRoot, worktreeDir, branch) {
|
|
8
59
|
let detail = "";
|
|
9
|
-
|
|
60
|
+
let removed = false;
|
|
61
|
+
for (let attempt = 0; attempt < 2 && !removed; attempt++) {
|
|
10
62
|
try {
|
|
11
63
|
const r = await baseEnv.exec(`git worktree remove --force ${shq(worktreeDir)}`, { cwd: repoRoot });
|
|
12
64
|
if (r.ok && r.value.exitCode === 0)
|
|
13
|
-
|
|
14
|
-
|
|
65
|
+
removed = true;
|
|
66
|
+
else
|
|
67
|
+
detail = r.ok ? r.value.stderr || r.value.stdout || `exit ${r.value.exitCode}` : thrownText(r.error);
|
|
15
68
|
}
|
|
16
69
|
catch (err) {
|
|
17
70
|
detail = thrownLabel(err);
|
|
18
71
|
}
|
|
19
72
|
}
|
|
20
|
-
|
|
73
|
+
if (!removed)
|
|
74
|
+
return { ok: false, detail };
|
|
75
|
+
if (branch === undefined || branch.name !== managedWorktreeBranchOf(worktreeDir))
|
|
76
|
+
return { ok: true };
|
|
77
|
+
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(branch.baseSha) || /^0+$/.test(branch.baseSha))
|
|
78
|
+
return { ok: true, branchKept: `${branch.name} (its base commit is not a usable witness)` };
|
|
79
|
+
try {
|
|
80
|
+
const del = await baseEnv.exec(`git update-ref --no-deref -d ${shq(`refs/heads/${branch.name}`)} ${shq(branch.baseSha)}`, { cwd: repoRoot });
|
|
81
|
+
if (del.ok && del.value.exitCode === 0)
|
|
82
|
+
return { ok: true, branchDeleted: branch.name };
|
|
83
|
+
const tip = await baseEnv.exec(`git rev-parse --verify --quiet ${shq(`refs/heads/${branch.name}`)}`, { cwd: repoRoot });
|
|
84
|
+
if (tip.ok && tip.value.exitCode !== 0)
|
|
85
|
+
return { ok: true };
|
|
86
|
+
if (tip.ok && tip.value.stdout.trim() !== branch.baseSha)
|
|
87
|
+
return { ok: true, branchKept: `${branch.name} (it carries commits made in the worktree)` };
|
|
88
|
+
return { ok: true, branchKept: `${branch.name} (it could not be deleted: ${del.ok ? (del.value.stderr || del.value.stdout).trim() : thrownText(del.error)})` };
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
return { ok: true, branchKept: `${branch.name} (it could not be deleted: ${thrownLabel(err)})` };
|
|
92
|
+
}
|
|
21
93
|
}
|
|
22
94
|
export async function addWorktree(baseEnv, opts) {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
95
|
+
const name = opts.name ?? `${(opts.sessionId || "task").replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 50)}-${randomUUID().slice(0, 8)}`;
|
|
96
|
+
const nameProblem = worktreeNameProblem(name);
|
|
97
|
+
if (nameProblem !== undefined)
|
|
98
|
+
throw new Error(nameProblem);
|
|
99
|
+
const worktreeDir = managedWorktreeDir(opts.repoRoot, name);
|
|
100
|
+
const branch = `${WORKTREE_BRANCH_PREFIX}/${slugOf(name)}`;
|
|
101
|
+
const symlinked = await symlinkedLevel(baseEnv, opts.repoRoot, worktreeDir);
|
|
102
|
+
if (symlinked !== undefined)
|
|
103
|
+
throw new Error(symlinked);
|
|
104
|
+
const add = await baseEnv.exec(`git worktree add --no-track -b ${shq(branch)} ${shq(worktreeDir)} ${shq(opts.commit ?? "HEAD")}`, {
|
|
26
105
|
cwd: opts.repoRoot,
|
|
27
106
|
});
|
|
28
107
|
if (!add.ok || add.value.exitCode !== 0) {
|
|
@@ -34,12 +113,17 @@ export async function addWorktree(baseEnv, opts) {
|
|
|
34
113
|
.exec(`ex="$(git rev-parse --git-path info/exclude)" && mkdir -p "$(dirname "$ex")" && ` +
|
|
35
114
|
`{ grep -qxF ${excludeLine} "$ex" 2>/dev/null || printf '%s\\n' ${excludeLine} >> "$ex"; }`, { cwd: opts.repoRoot })
|
|
36
115
|
.catch(() => undefined);
|
|
116
|
+
const baseSha = await baseEnv
|
|
117
|
+
.exec("git rev-parse HEAD", { cwd: worktreeDir })
|
|
118
|
+
.then((r) => (r.ok && r.value.exitCode === 0 && r.value.stdout.trim() !== "" ? r.value.stdout.trim() : undefined))
|
|
119
|
+
.catch(() => undefined);
|
|
120
|
+
const branchRule = baseSha !== undefined ? { name: branch, baseSha } : undefined;
|
|
37
121
|
let inner;
|
|
38
122
|
try {
|
|
39
123
|
inner = await opts.rootEnvAt(worktreeDir);
|
|
40
124
|
}
|
|
41
125
|
catch (err) {
|
|
42
|
-
await
|
|
126
|
+
await removeManagedWorktree(baseEnv, opts.repoRoot, worktreeDir, branchRule);
|
|
43
127
|
throw err;
|
|
44
128
|
}
|
|
45
129
|
const innerDestroy = inner.destroy;
|
|
@@ -50,14 +134,14 @@ export async function addWorktree(baseEnv, opts) {
|
|
|
50
134
|
await innerDestroy.call(inner);
|
|
51
135
|
}
|
|
52
136
|
finally {
|
|
53
|
-
const removed = await
|
|
137
|
+
const removed = await removeManagedWorktree(baseEnv, opts.repoRoot, worktreeDir, branchRule);
|
|
54
138
|
if (!removed.ok) {
|
|
55
139
|
throw new Error(`git worktree remove failed twice — ${worktreeDir} is now an orphan (dir + registration remain; ` +
|
|
56
140
|
`\`git worktree prune\` cannot reclaim it while the dir exists — remove it manually): ${removed.detail}`);
|
|
57
141
|
}
|
|
58
142
|
}
|
|
59
143
|
};
|
|
60
|
-
return { env, worktreeDir };
|
|
144
|
+
return { env, worktreeDir, name, branch, ...(baseSha !== undefined ? { baseSha } : {}) };
|
|
61
145
|
}
|
|
62
146
|
export async function pruneWorktrees(baseEnv, repoRoot) {
|
|
63
147
|
try {
|
package/dist/core/hooks.d.ts
CHANGED
|
@@ -553,13 +553,16 @@ export interface ToolGateResult {
|
|
|
553
553
|
gate?: GateOutcome;
|
|
554
554
|
/** The args to execute with — the pass's own immutable copy, the value every judge of the call read (the model's args
|
|
555
555
|
* as taken at the gate's entry, or what a hook, a policy or a person rewrote them to); re-validated by the loop. Present
|
|
556
|
-
* on every allow exit, whether or not anything rewrote (
|
|
556
|
+
* on every allow exit, whether or not anything rewrote ({@link rewrite} says whether, and who); absent on a block and a suspend. */
|
|
557
557
|
updatedInput?: unknown;
|
|
558
558
|
/** The input this pass decided on (what a refusal refused, what an allowed call runs with) as a deep, FROZEN plain-data projection
|
|
559
559
|
* taken at the exit — never the live args: on a refusal every member that is not data (a bigint, a Map, a Date, a class instance, a
|
|
560
560
|
* function, an accessor, a symbol-keyed member) is a `[not recorded: …]` marker; an allow exit meets only the gate's own copy, so there
|
|
561
561
|
* just a bigint, a cycle's closing member and containers past 256 levels are. Beside {@link gate} on both terminal exits; absent on the suspend exit. */
|
|
562
562
|
finalInput?: unknown;
|
|
563
|
+
/** The allow exit's record of a rewrite: `finalInput` and who replaced the args, when they are not the ones the entry took
|
|
564
|
+
* (`tool_end.rewrite`, the one home of its contract). Absent on every other exit and on an allow that runs the entry's bytes. */
|
|
565
|
+
rewrite?: import("./task-event.js").ToolInputRewrite;
|
|
563
566
|
/** A blocking refusal's structured details, when the refusing station minted any (the shell read station's
|
|
564
567
|
* `read_path_denied` / `readonly_out_of_root` cards): the loop attaches them to the error result it mints
|
|
565
568
|
* from `reason`, so the refusal reaches `tool_end.structured` / `errorCode` exactly as the tool's own
|
|
@@ -1252,8 +1255,8 @@ export interface ToolGateInput extends PermissionSeatInputs, SkillGateSeats, All
|
|
|
1252
1255
|
/**
|
|
1253
1256
|
* F-012 L2 — the SANDBOX ADMISSION leg. Present ONLY when the runner armed the mode: the execution
|
|
1254
1257
|
* env DECLARES isolation (`RemoteExecutionEnv.capabilities.isolation === true` — a Runner-resolved
|
|
1255
|
-
* fact, never caller self-report) AND the park prerequisites hold (durable park configured + a
|
|
1256
|
-
* checkpoint store
|
|
1258
|
+
* fact, never caller self-report) AND the park prerequisites hold (durable park configured + a wired
|
|
1259
|
+
* checkpoint store — every store carries the required `reopen`, read at its seat). Absent ⇒ the whole step does not
|
|
1257
1260
|
* exist and the decision path is byte-identical to a build without it.
|
|
1258
1261
|
*
|
|
1259
1262
|
* Semantics (the ruling): inside a declared sandbox, an engine-authored "confirm a potentially
|
package/dist/core/hooks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { argsAsTheToolReads, stampArgsReading } from "./effective-path-target.js";
|
|
2
|
+
import { extensionAuthors, noteRewrite, screeningAuthorship } from "./rewrite-rejudge.js";
|
|
2
3
|
import { abortedSeatDeny, decisionText, describeThrown, isEngineRefusal, ownArgs, ownedReading, refuseOutOfContractDecision, unaskedSeatAnswer } from "./tool-policy.js";
|
|
3
4
|
import { createSettlementLedger, engineFailClosedExit, hookDenyExit, unownedArgsExit } from "./runner/gate-exit.js";
|
|
4
5
|
import { classicEventBase, dispatchClassic, ENGINE_CORE_ANSWER, engineCore, failedHandlerClause, judgedInputOf, observePermissionDenied, recordScreeningChain } from "./mods/stations.js";
|
|
@@ -128,10 +129,11 @@ export function createPreToolUseScreening(input) {
|
|
|
128
129
|
};
|
|
129
130
|
};
|
|
130
131
|
return {
|
|
131
|
-
screen: async (args, subject) => {
|
|
132
|
+
screen: async (args, subject, readAs) => {
|
|
132
133
|
let outcome;
|
|
134
|
+
const authorship = screeningAuthorship(readAs ?? {});
|
|
133
135
|
try {
|
|
134
|
-
outcome = await dispatchClassic(bus, "classic.PreToolUse", eventOf(args), { ...(input.abortSignal !== undefined ? { signal: input.abortSignal } : {}), checkAnswer: preToolUseAnswerViolation, ranks: PRE_TOOL_USE_RANKS });
|
|
136
|
+
outcome = await dispatchClassic(bus, "classic.PreToolUse", eventOf(args), { ...(input.abortSignal !== undefined ? { signal: input.abortSignal } : {}), checkAnswer: (a, e, by, below) => preToolUseAnswerViolation(a) ?? authorship.record(a, e, by, below), ranks: PRE_TOOL_USE_RANKS });
|
|
135
137
|
}
|
|
136
138
|
catch (err) {
|
|
137
139
|
return { kind: "refused", reason: preToolUseRefusedReason(subject, { kind: "failed", registration: "engine", cause: "threw", reason: `could not raise the screening: ${describeThrown(err)}`, skipped: [] }) };
|
|
@@ -141,7 +143,9 @@ export function createPreToolUseScreening(input) {
|
|
|
141
143
|
if (outcome.kind === "failed")
|
|
142
144
|
return { kind: "refused", reason: preToolUseRefusedReason(subject, outcome) };
|
|
143
145
|
const r = screenPreToolUseResult(outcome.answer);
|
|
144
|
-
|
|
146
|
+
const answer = r === null || r === false ? undefined : r;
|
|
147
|
+
const rewrittenBy = authorship.of(outcome.answer);
|
|
148
|
+
return { kind: "answered", answer, ...(outcome.answeredBy !== undefined ? { answeredBy: outcome.answeredBy } : {}), ...(answer?.updatedInput !== undefined ? { rewrittenBy: rewrittenBy.length > 0 || outcome.answeredBy === undefined ? rewrittenBy : [outcome.answeredBy] } : {}) };
|
|
145
149
|
},
|
|
146
150
|
deniedReason: (answer) => decisionText(answer) ?? `tool "${toolName}" blocked by a PreToolUse hook`,
|
|
147
151
|
};
|
|
@@ -237,6 +241,7 @@ export async function runToolGate(input) {
|
|
|
237
241
|
screening,
|
|
238
242
|
afterFold: runGateLanes,
|
|
239
243
|
currentInput: args,
|
|
244
|
+
rewrites: { entry: args, by: [] },
|
|
240
245
|
req: Object.freeze({ toolName, args, toolCallId, ...(() => { const f = input.toolFaceOf?.(toolName); const read = event.readArguments; if (f !== undefined && read !== undefined)
|
|
241
246
|
stampArgsReading(f, ownedReading(read)); return f !== undefined ? { face: f } : {}; })() }),
|
|
242
247
|
preToolContext: [],
|
|
@@ -251,7 +256,7 @@ export async function runToolGate(input) {
|
|
|
251
256
|
if (!owned.ok)
|
|
252
257
|
return await unownedArgsExit(pass, owned.reason);
|
|
253
258
|
if (screening !== undefined) {
|
|
254
|
-
const screened = await screening.screen(pass.currentInput, `this call to "${toolName}"
|
|
259
|
+
const screened = await screening.screen(pass.currentInput, `this call to "${toolName}"`, pass.req);
|
|
255
260
|
if (screened.kind === "refused") {
|
|
256
261
|
return await engineFailClosedExit(pass, screened.reason);
|
|
257
262
|
}
|
|
@@ -264,7 +269,9 @@ export async function runToolGate(input) {
|
|
|
264
269
|
return hookDenyExit(pass, screening.deniedReason(r));
|
|
265
270
|
}
|
|
266
271
|
if (r.updatedInput !== undefined) {
|
|
267
|
-
|
|
272
|
+
const rewritten = argsAsTheToolReads(pass.req, r.updatedInput);
|
|
273
|
+
noteRewrite(pass.rewrites, pass.req, pass.currentInput, rewritten, extensionAuthors(screened.rewrittenBy ?? []));
|
|
274
|
+
pass.currentInput = rewritten;
|
|
268
275
|
}
|
|
269
276
|
if (r.action === "ask") {
|
|
270
277
|
pass.hookAsk = r;
|
|
@@ -32,6 +32,7 @@ const HANDLED_HUMAN_INPUT_KEYS = {
|
|
|
32
32
|
principal: "forwarded",
|
|
33
33
|
entryId: "forwarded",
|
|
34
34
|
attachments: "forwarded",
|
|
35
|
+
runOrigin: "forwarded",
|
|
35
36
|
};
|
|
36
37
|
export function buildHumanInputEvent(input) {
|
|
37
38
|
void HANDLED_HUMAN_INPUT_KEYS;
|
|
@@ -47,6 +48,7 @@ export function buildHumanInputEvent(input) {
|
|
|
47
48
|
...(input.principal !== undefined ? { principal: input.principal } : {}),
|
|
48
49
|
...(input.entryId !== undefined ? { entryId: input.entryId } : {}),
|
|
49
50
|
...(input.attachments !== undefined && input.attachments.length > 0 ? { attachments: input.attachments.map((a) => ({ ...a })) } : {}),
|
|
51
|
+
...(input.runOrigin !== undefined ? { runOrigin: input.runOrigin } : {}),
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
export function buildAppliedHumanInputEvent(input) {
|
|
@@ -59,5 +61,6 @@ export function buildAppliedHumanInputEvent(input) {
|
|
|
59
61
|
...(input.actor !== undefined ? { actor: input.actor } : {}),
|
|
60
62
|
...(input.actor?.issuer !== undefined ? { issuer: input.actor.issuer } : {}),
|
|
61
63
|
...(input.principal !== undefined ? { principal: input.principal } : {}),
|
|
64
|
+
...(input.runOrigin !== undefined ? { runOrigin: input.runOrigin } : {}),
|
|
62
65
|
});
|
|
63
66
|
}
|
|
@@ -184,7 +184,21 @@ export declare function judgeEntryToolFaces(copy: McpServerSpec): {
|
|
|
184
184
|
code: string;
|
|
185
185
|
};
|
|
186
186
|
};
|
|
187
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* The `sessionMetaKey` question for ONE snapshot MCP entry — asked by the door and the materialization entrance like its siblings, through
|
|
189
|
+
* the one judge ({@link judgeSessionMetaKey}); a key that cannot ride refuses under `config.invalid_argument`, naming the server and the key.
|
|
190
|
+
* The entry is unchanged (a string is already the engine's own copy).
|
|
191
|
+
*/
|
|
192
|
+
export declare function judgeEntrySessionMetaKey(copy: McpServerSpec): {
|
|
193
|
+
ok: true;
|
|
194
|
+
entry: McpServerSpec;
|
|
195
|
+
} | {
|
|
196
|
+
ok: false;
|
|
197
|
+
error: Error & {
|
|
198
|
+
code: string;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
/** Everything a snapshot MCP entry declares beyond its plain data, judged: its `toolAxes` ({@link judgeEntryToolAxes}), its `toolFaces` ({@link judgeEntryToolFaces}), its `sessionMetaKey` ({@link judgeEntrySessionMetaKey}). */
|
|
188
202
|
export declare function judgeMcpEntryDeclarations(copy: McpServerSpec): {
|
|
189
203
|
ok: true;
|
|
190
204
|
entry: McpServerSpec;
|
|
@@ -2,10 +2,12 @@ import { types } from "node:util";
|
|
|
2
2
|
import { DECLARATION_PATH_RULES, NO_DECLARATION_PATH_RULES, declarationFaultOf, declarerWord, readToolAxes, receiveDeclaration, toolAxesRefusal } from "./mcp-server-spec.js";
|
|
3
3
|
import { isPlainRecord, receive } from "./mods/kernel/receive.js";
|
|
4
4
|
import { readToolFaces } from "./tool-face-reader.js";
|
|
5
|
+
import { judgeSessionMetaKey } from "./mcp-call-meta.js";
|
|
5
6
|
import { CONFIG_RECEIPT_MODE } from "./own-property-receipt.js";
|
|
6
7
|
import { isToolContentOrigin, TOOL_CONTENT_ORIGINS } from "./memory-engine/content-origin.js";
|
|
7
8
|
import { inlineUntrusted } from "./untrusted-text.js";
|
|
8
9
|
import { assertNoRetiredToolPolicyKeys } from "./retired-keys.js";
|
|
10
|
+
import { CREDENTIALS_MEMBER, declaredCredentials, peerSeatMissing, retiredValueMember } from "./peer-seat.js";
|
|
9
11
|
export const LOCKED_KEY_REGISTRY = {
|
|
10
12
|
mcp: { specFields: ["mcp"] },
|
|
11
13
|
toolPolicy: { specFields: ["toolPolicy", "basePolicyForResumeEdit"] },
|
|
@@ -89,8 +91,30 @@ export function snapshotDeclaredEntry(entry, at) {
|
|
|
89
91
|
throw entryFaultRefusal(at, declarer, received.fault.path, received.fault.problem);
|
|
90
92
|
if (!isPlainRecord(received.value))
|
|
91
93
|
throw unreadableDeclaration(at, declarer, "an entry", `it is ${inlineUntrusted(describeDeclared(received.value), 80)}, not an object`);
|
|
94
|
+
const retired = retiredValueMember(received.value, at);
|
|
95
|
+
if (retired !== undefined) {
|
|
96
|
+
throw declarationRefusal("config.credential_in_declaration", at, declarer, `declares ${retired.join(".")}, a member that carried values and is retired: a declaration names the peer and at most one opaque reference (${CREDENTIALS_MEMBER[at].join(".")}); the pieces a request carries are answered per send by the deployment's peer seat (RunnerDeps.peerSeat). The value is not repeated here.`);
|
|
97
|
+
}
|
|
98
|
+
const credentials = declaredCredentials(received.value, at);
|
|
99
|
+
if ("problem" in credentials) {
|
|
100
|
+
throw declarationRefusal("config.credential_ref_invalid", at, declarer, `declares ${CREDENTIALS_MEMBER[at].join(".")} that is not a credential reference (${inlineUntrusted(credentials.problem, 160)}).`);
|
|
101
|
+
}
|
|
92
102
|
return received.value;
|
|
93
103
|
}
|
|
104
|
+
function declarationRefusal(code, at, declarer, sentence) {
|
|
105
|
+
const refusal = codedError(code, `${declarerWord(at)}${declarer === undefined ? "" : ` ${declarerNameOf(declarer)}`} ${sentence}`);
|
|
106
|
+
if (declarer !== undefined)
|
|
107
|
+
Object.defineProperty(refusal, "declarer", { value: declarer, enumerable: true, writable: false, configurable: false });
|
|
108
|
+
return refusal;
|
|
109
|
+
}
|
|
110
|
+
function assertPeerSeatFor(entries, at, seat) {
|
|
111
|
+
for (const entry of entries ?? []) {
|
|
112
|
+
const read = declaredCredentials(entry, at);
|
|
113
|
+
const missing = "ref" in read ? peerSeatMissing(`${declarerWord(at)} ${declarerNameOf(entry.name)}`, read.ref, seat) : undefined;
|
|
114
|
+
if (missing !== undefined)
|
|
115
|
+
throw missing;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
94
118
|
function describeDeclared(value) {
|
|
95
119
|
try {
|
|
96
120
|
return JSON.stringify(value) ?? String(value);
|
|
@@ -139,9 +163,16 @@ export function judgeEntryToolFaces(copy) {
|
|
|
139
163
|
return { ok: false, error: toolFacesRefusal(declarerNameOf(copy.name), faces.problem) };
|
|
140
164
|
return { ok: true, entry: Object.freeze((faces.faces === undefined ? rest : { ...rest, toolFaces: deepFrozen(faces.faces) })) };
|
|
141
165
|
}
|
|
166
|
+
export function judgeEntrySessionMetaKey(copy) {
|
|
167
|
+
const read = judgeSessionMetaKey(copy.sessionMetaKey);
|
|
168
|
+
if (!("problem" in read))
|
|
169
|
+
return { ok: true, entry: copy };
|
|
170
|
+
return { ok: false, error: codedError("config.invalid_argument", `${declarerWord("mcp")} ${declarerNameOf(copy.name)} declares ${inlineUntrusted(read.problem, 200)}. The key decides where the leg's session id rides on this server's requests, so it is refused rather than dropped or defaulted — a connector keyed on a session it never receives would share one state across every session.`) };
|
|
171
|
+
}
|
|
142
172
|
export function judgeMcpEntryDeclarations(copy) {
|
|
143
173
|
const axes = judgeEntryToolAxes(copy, "mcp");
|
|
144
|
-
|
|
174
|
+
const faces = axes.ok ? judgeEntryToolFaces(axes.entry) : axes;
|
|
175
|
+
return faces.ok ? judgeEntrySessionMetaKey(faces.entry) : faces;
|
|
145
176
|
}
|
|
146
177
|
function declaredEntriesOf(declared, at) {
|
|
147
178
|
const field = at;
|
|
@@ -211,10 +242,15 @@ export function preflightLockedConfig(spec, deps, enter = ENTER_AS_IS) {
|
|
|
211
242
|
const declaredServers = lockedKeys.has("mcp") ? undefined : spec.mcp;
|
|
212
243
|
const mcp = declaredServers === undefined ? undefined : enter("taskConfig", () => snapshotAndValidateMcpEntries(declaredServers));
|
|
213
244
|
const declaredPeers = spec.a2a;
|
|
245
|
+
const a2a = declaredPeers === undefined ? undefined : enter("taskConfig", () => snapshotAndValidateA2aEntries(declaredPeers));
|
|
246
|
+
enter("taskConfig", () => {
|
|
247
|
+
assertPeerSeatFor(mcp, "mcp", deps.peerSeat);
|
|
248
|
+
assertPeerSeatFor(a2a, "a2a", deps.peerSeat);
|
|
249
|
+
});
|
|
214
250
|
return {
|
|
215
251
|
lockedKeys,
|
|
216
252
|
mcp,
|
|
217
|
-
a2a
|
|
253
|
+
a2a,
|
|
218
254
|
...policies,
|
|
219
255
|
};
|
|
220
256
|
}
|