@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
|
@@ -89,6 +89,7 @@ async function gateToolWrite(hook, tool, path, key, content) {
|
|
|
89
89
|
return `Error (${tool}): write rejected by the write gate (${res.code}): ${clipHookText(res.reason)}`;
|
|
90
90
|
return undefined;
|
|
91
91
|
}
|
|
92
|
+
const rootOf = (seat) => (typeof seat === "function" ? seat() : seat);
|
|
92
93
|
export function createEditFileTool(env, state, rootCanonical, cwdRef, additionalRoots, beforeWrite, trackEdit, onEdited, writeFace, writeDeny) {
|
|
93
94
|
return defineTool({
|
|
94
95
|
name: "Edit",
|
|
@@ -114,7 +115,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
|
|
|
114
115
|
const path = fileArgPath(args);
|
|
115
116
|
if (path === undefined)
|
|
116
117
|
return { ok: true };
|
|
117
|
-
const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
118
|
+
const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
118
119
|
if (!r.ok)
|
|
119
120
|
return { ok: true };
|
|
120
121
|
if (a.old_string === a.new_string)
|
|
@@ -152,7 +153,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
|
|
|
152
153
|
const path = fileArgPath(args);
|
|
153
154
|
if (path === undefined)
|
|
154
155
|
return errorResult(`Error (Edit): file_path is required.`);
|
|
155
|
-
const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
156
|
+
const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
156
157
|
if (!r.ok)
|
|
157
158
|
return errorResult(violationText("Edit", r.violation), violationDetails(r.violation));
|
|
158
159
|
if (!batch && a.old_string === a.new_string) {
|
|
@@ -190,7 +191,7 @@ export function createEditFileTool(env, state, rootCanonical, cwdRef, additional
|
|
|
190
191
|
details: { type: "create", filePath: path, content: created },
|
|
191
192
|
};
|
|
192
193
|
}
|
|
193
|
-
return errorResult(`Error (Edit): ${await enoentMessage(env, r.key, cwdRef?.current ?? rootCanonical, ctx.signal)}`);
|
|
194
|
+
return errorResult(`Error (Edit): ${await enoentMessage(env, r.key, cwdRef?.current ?? rootOf(rootCanonical), ctx.signal)}`);
|
|
194
195
|
}
|
|
195
196
|
const editInfo = await env.fileInfo(r.key, ctx.signal);
|
|
196
197
|
if (editInfo.ok && editInfo.value.size > MAX_EDIT_BYTES) {
|
|
@@ -346,7 +347,7 @@ export function createWriteFileTool(env, state, rootCanonical, cwdRef, additiona
|
|
|
346
347
|
return { ok: true };
|
|
347
348
|
if (ipynbRedirect("Write", path))
|
|
348
349
|
return { ok: true };
|
|
349
|
-
const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
350
|
+
const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
350
351
|
if (!r.ok)
|
|
351
352
|
return { ok: true };
|
|
352
353
|
const exists = await env.exists(r.key, ctx.signal);
|
|
@@ -365,7 +366,7 @@ export function createWriteFileTool(env, state, rootCanonical, cwdRef, additiona
|
|
|
365
366
|
const ipynb = ipynbRedirect("Write", path);
|
|
366
367
|
if (ipynb)
|
|
367
368
|
return errorResult(ipynb);
|
|
368
|
-
const r = await resolveKey(env, rootCanonical, path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
369
|
+
const r = await resolveKey(env, rootOf(rootCanonical), path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
369
370
|
if (!r.ok)
|
|
370
371
|
return errorResult(violationText("Write", r.violation), violationDetails(r.violation));
|
|
371
372
|
const exists = await env.exists(r.key, ctx.signal);
|
|
@@ -462,7 +463,7 @@ export function createNotebookEditTool(env, state, rootCanonical, cwdRef, additi
|
|
|
462
463
|
return { ok: false, code: "invalid", message: NOTEBOOK_CELL_TYPE_REQUIRED_MESSAGE };
|
|
463
464
|
if (mode !== "insert" && !a.cell_id)
|
|
464
465
|
return { ok: false, code: "invalid", message: NOTEBOOK_CELL_ID_REQUIRED_MESSAGE };
|
|
465
|
-
const r = await resolveKey(env, rootCanonical, a.notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
466
|
+
const r = await resolveKey(env, rootOf(rootCanonical), a.notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
466
467
|
if (!r.ok)
|
|
467
468
|
return { ok: true };
|
|
468
469
|
const notRead = requireRead(state, r.key);
|
|
@@ -482,7 +483,7 @@ export function createNotebookEditTool(env, state, rootCanonical, cwdRef, additi
|
|
|
482
483
|
return errorResult(NOTEBOOK_CELL_TYPE_REQUIRED_MESSAGE);
|
|
483
484
|
if (mode !== "insert" && !cell_id)
|
|
484
485
|
return errorResult(NOTEBOOK_CELL_ID_REQUIRED_MESSAGE);
|
|
485
|
-
const r = await resolveKey(env, rootCanonical, notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
486
|
+
const r = await resolveKey(env, rootOf(rootCanonical), notebook_path, ctx.signal, cwdRef?.current, additionalRoots, undefined, seatForCall(writeDeny, ctx.toolCallId), writeFace?.());
|
|
486
487
|
if (!r.ok)
|
|
487
488
|
return errorResult(violationText("NotebookEdit", r.violation), violationDetails(r.violation));
|
|
488
489
|
const notRead = requireRead(state, r.key);
|
package/dist/tools/fs/index.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ export interface HandsToolkitOptions {
|
|
|
26
26
|
* `bash_readonly` IS constrained by them (that face refuses a read outside the roots), so widening
|
|
27
27
|
* here widens what the read-only band may read. */
|
|
28
28
|
additionalRoots?: readonly string[];
|
|
29
|
+
/** The WRITE tools' primary root (edit_file / write_file / notebook_edit), read per call: the leg's write location, which
|
|
30
|
+
* moves with an EnterWorktree switch while the read tools keep `rootCanonical`. Absent ⇒ `rootCanonical` (one root). */
|
|
31
|
+
writeRoot?: () => string;
|
|
29
32
|
/** The read-boundary whitelist: extra allowed containment roots for the READ faces only —
|
|
30
33
|
* read_file/grep/glob/repo_map and `bash_readonly` admit them; edit_file/write_file/notebook_edit
|
|
31
34
|
* and the full `bash`'s disclosure roots deliberately do NOT (widening reads must never silently
|
package/dist/tools/fs/index.js
CHANGED
|
@@ -81,7 +81,7 @@ export function createHandsToolkit(env, readFileState, rootCanonical, opts = {})
|
|
|
81
81
|
afterPlacement(createReadFileTool(env, readFileState, rootCanonical, readCwd, readFaceRoots, opts.readImageDownsampler, opts.pdfModelCapabilities, bgOutputReadExemption, readDeny, readFace, opts.reminderMark, opts.reminderDisclosureCounts, reader)),
|
|
82
82
|
];
|
|
83
83
|
if (handsWriteHalfMounts({ readOnly })) {
|
|
84
|
-
tools.push(createEditFileTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createWriteFileTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createNotebookEditTool(env, readFileState, rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
|
|
84
|
+
tools.push(createEditFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createWriteFileTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny), createNotebookEditTool(env, readFileState, opts.writeRoot ?? rootCanonical, cwdRef, additionalRoots, opts.beforeWrite, opts.trackFileEdit, opts.onFileEdited, writeFaceOf, writeDeny));
|
|
85
85
|
}
|
|
86
86
|
tools.push(afterPlacement(createGrepTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)), afterPlacement(createGlobTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)), afterPlacement(createRepoMapTool(env, rootCanonical, readFaceRoots, readDeny, readFace, cwdRef, readAdmission)));
|
|
87
87
|
if (includeShell) {
|
|
@@ -12,8 +12,9 @@ export interface PatternKillReading {
|
|
|
12
12
|
export declare function patternKillReadings(command: string, cwd: string): PatternKillReading[];
|
|
13
13
|
/**
|
|
14
14
|
* The refusal for a command whose pattern-kill would select this agent's own process or one above it — or undefined (run it).
|
|
15
|
-
* `cwd`: where the command stands, for the plan's read of its words (nothing is read from disk).
|
|
16
|
-
*
|
|
15
|
+
* `cwd`: where the command stands, for the plan's read of its words (nothing is read from disk). Where the question is put is
|
|
16
|
+
* the env's own declaration ({@link processTableOf}): this process's table is asked, another table is not, and an env that does
|
|
17
|
+
* not say is refused. Windows is not asked: this process's table is not read there.
|
|
17
18
|
*/
|
|
18
19
|
export declare function patternKillRefusal(command: string, env: ExecutionEnv, cwd: string, signal?: AbortSignal): Promise<{
|
|
19
20
|
content: string;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { errorResult } from "../../core/tools.js";
|
|
4
|
-
import {
|
|
4
|
+
import { processTableOf } from "../../core/remote-env.js";
|
|
5
5
|
import { inheritedHostEnv } from "../../core/secret-env.js";
|
|
6
6
|
import { inlineUntrusted } from "../../core/untrusted-text.js";
|
|
7
7
|
import { planShellReads } from "./shell-read-plan.js";
|
|
8
8
|
import { programArgs } from "./shell-read-write-targets.js";
|
|
9
9
|
const PROBE_TIMEOUT_MS = 5_000;
|
|
10
10
|
const ANCESTOR_HOPS_MAX = 128;
|
|
11
|
-
const
|
|
11
|
+
const SHELL_PID_SPELLING = String.raw `\$(?:\$|\{\$\})`;
|
|
12
|
+
const SHELL_PID_WORD = new RegExp(`^${SHELL_PID_SPELLING}$`);
|
|
13
|
+
const SHELL_PID_EXPANSION = new RegExp(SHELL_PID_SPELLING, "g");
|
|
12
14
|
const NAME_SELECTION_KEEPS_ANCESTORS = process.platform === "linux" ? [] : ["-a"];
|
|
15
|
+
const OPTIONS_END_AT_FIRST_OPERAND = process.platform !== "linux";
|
|
13
16
|
const SIGNAL_ONLY_FIRST_ARGUMENT = process.platform !== "linux";
|
|
14
17
|
const HANDLER_SELECTS_BY_SIGNAL = process.platform === "linux";
|
|
15
18
|
const LONG_OPTIONS = new Map([
|
|
@@ -54,21 +57,28 @@ const isSignalWord = (w) => {
|
|
|
54
57
|
const m = SIGNAL_WORD.exec(w);
|
|
55
58
|
return m !== null && (m[1] === undefined || SIGNAL_NAMES.has(m[1].toUpperCase()));
|
|
56
59
|
};
|
|
57
|
-
function
|
|
60
|
+
function readSelection(allWords, killer) {
|
|
58
61
|
const signalAt = killer !== "pkill" ? -1 : SIGNAL_ONLY_FIRST_ARGUMENT ? (isSignalWord(allWords[0] ?? "") ? 0 : -1) : allWords.findIndex(isSignalWord);
|
|
59
62
|
const signalWord = signalAt < 0 ? undefined : allWords[signalAt].slice(1);
|
|
60
63
|
const words = signalAt < 0 ? allWords : allWords.filter((_, i) => i !== signalAt);
|
|
61
64
|
const out = [];
|
|
65
|
+
const parentLists = [];
|
|
62
66
|
let ended = false;
|
|
63
67
|
let requireHandler = false;
|
|
68
|
+
let negated = false;
|
|
64
69
|
let signalOption;
|
|
65
70
|
let valueOf;
|
|
71
|
+
const valueGiven = (key, value) => {
|
|
72
|
+
if (key === "P")
|
|
73
|
+
parentLists.push(value.split(","));
|
|
74
|
+
};
|
|
66
75
|
for (const w of words) {
|
|
67
76
|
if (valueOf !== undefined) {
|
|
68
|
-
if (valueOf === "ask")
|
|
77
|
+
if (valueOf.fate === "ask")
|
|
69
78
|
out.push(w);
|
|
70
|
-
else if (valueOf === "signal")
|
|
79
|
+
else if (valueOf.fate === "signal")
|
|
71
80
|
signalOption = w;
|
|
81
|
+
valueGiven(valueOf.key, w);
|
|
72
82
|
valueOf = undefined;
|
|
73
83
|
continue;
|
|
74
84
|
}
|
|
@@ -82,60 +92,75 @@ function selectorWords(allWords, killer) {
|
|
|
82
92
|
if (key !== undefined && (takesValueKey(key) || longValue === undefined)) {
|
|
83
93
|
if (key === "H")
|
|
84
94
|
requireHandler = true;
|
|
95
|
+
if (key === "v")
|
|
96
|
+
negated = true;
|
|
85
97
|
const fate = fateOfKey(key);
|
|
86
98
|
if (fate === "ask")
|
|
87
99
|
out.push(w);
|
|
88
100
|
if (takesValueKey(key) && longValue === undefined)
|
|
89
|
-
valueOf = fate;
|
|
90
|
-
else if (
|
|
91
|
-
|
|
101
|
+
valueOf = { fate, key };
|
|
102
|
+
else if (longValue !== undefined) {
|
|
103
|
+
if (fate === "signal")
|
|
104
|
+
signalOption = longValue;
|
|
105
|
+
valueGiven(key, longValue);
|
|
106
|
+
}
|
|
92
107
|
continue;
|
|
93
108
|
}
|
|
94
109
|
const letters = bundledLetters(w);
|
|
95
110
|
if (letters === undefined) {
|
|
96
111
|
out.push(w);
|
|
112
|
+
if (OPTIONS_END_AT_FIRST_OPERAND && (w === "-" || !w.startsWith("-")))
|
|
113
|
+
ended = true;
|
|
97
114
|
continue;
|
|
98
115
|
}
|
|
99
116
|
if (letters.includes("H"))
|
|
100
117
|
requireHandler = true;
|
|
118
|
+
if (letters.includes("v"))
|
|
119
|
+
negated = true;
|
|
101
120
|
const last = letters[letters.length - 1];
|
|
102
121
|
const fate = fateOfKey(last);
|
|
103
122
|
const kept = letters.filter((ch) => fateOfKey(ch) === "ask").join("");
|
|
104
123
|
const attached = VALUED_LETTERS.has(last) ? w.slice(1 + letters.length) : "";
|
|
105
124
|
if (kept !== "")
|
|
106
125
|
out.push(`-${kept}${fate === "ask" ? attached : ""}`);
|
|
107
|
-
if (VALUED_LETTERS.has(last)
|
|
108
|
-
|
|
126
|
+
if (VALUED_LETTERS.has(last)) {
|
|
127
|
+
if (attached === "")
|
|
128
|
+
valueOf = { fate, key: last };
|
|
129
|
+
else
|
|
130
|
+
valueGiven(last, attached);
|
|
131
|
+
}
|
|
109
132
|
}
|
|
110
133
|
const signal = signalOption ?? signalWord;
|
|
111
|
-
return HANDLER_SELECTS_BY_SIGNAL && requireHandler && signal !== undefined ? ["--signal", signal, ...out] : out;
|
|
134
|
+
return { words: HANDLER_SELECTS_BY_SIGNAL && requireHandler && signal !== undefined ? ["--signal", signal, ...out] : out, parentLists, negated };
|
|
112
135
|
}
|
|
113
|
-
const
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return attached !== null && SHELL_PID_WORD.test(attached[1]);
|
|
120
|
-
});
|
|
136
|
+
const LAST_PARENT_LIST_WINS = process.platform === "linux";
|
|
137
|
+
function boundedToShellChildren(read, unread) {
|
|
138
|
+
if (unread !== undefined)
|
|
139
|
+
return false;
|
|
140
|
+
const standing = LAST_PARENT_LIST_WINS ? read.parentLists.slice(-1) : read.parentLists;
|
|
141
|
+
return standing.length > 0 && standing.every((list) => list.every((pid) => SHELL_PID_WORD.test(pid)));
|
|
121
142
|
}
|
|
122
143
|
const literalName = (name) => name.replace(/[\\.[\]{}()*+?^$|]/g, "\\$&");
|
|
123
144
|
function wordsOf(segment) {
|
|
124
145
|
const args = programArgs(segment);
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
|
|
146
|
+
const expands = (a) => `\`${inlineUntrusted(a.raw, 60)}\` is expanded by the shell when the command runs`;
|
|
147
|
+
const stream = segment.reentry === "argv" ? "its arguments arrive on a stream" : undefined;
|
|
148
|
+
const opaque = args.find((a) => a.rewritten === true && /[$`*?[~{\\]/.test(a.raw.replace(SHELL_PID_EXPANSION, "0")));
|
|
149
|
+
const first = args.find((a) => a.rewritten === true);
|
|
150
|
+
const unread = stream ?? (opaque === undefined ? undefined : expands(opaque));
|
|
151
|
+
const computed = unread ?? (first === undefined ? undefined : expands(first));
|
|
152
|
+
return { words: args.map((a) => a.spelled), ...(computed !== undefined ? { computed } : {}), ...(unread !== undefined ? { unread } : {}) };
|
|
128
153
|
}
|
|
129
154
|
const shown = (segment) => inlineUntrusted(segment.text, 200);
|
|
130
155
|
function readPkill(segment) {
|
|
131
|
-
const { words, computed } = wordsOf(segment);
|
|
132
|
-
|
|
133
|
-
|
|
156
|
+
const { words, computed, unread } = wordsOf(segment);
|
|
157
|
+
const read = readSelection(words, "pkill");
|
|
158
|
+
if (boundedToShellChildren(read, unread)) {
|
|
159
|
+
return read.negated ? { text: shown(segment), probes: [], computed: "the selection is negated (`-v` / `--inverse`), so `-P` of the shell's pid no longer limits it to the shell's children" } : undefined;
|
|
134
160
|
}
|
|
135
161
|
if (computed !== undefined)
|
|
136
162
|
return { text: shown(segment), probes: [], computed };
|
|
137
|
-
|
|
138
|
-
return selectors.length === 0 ? undefined : { text: shown(segment), probes: [selectors] };
|
|
163
|
+
return read.words.length === 0 ? undefined : { text: shown(segment), probes: [read.words] };
|
|
139
164
|
}
|
|
140
165
|
const OPT_FLAG = { does: "flag" };
|
|
141
166
|
const OPT_FILTER = { does: "filter" };
|
|
@@ -157,7 +182,6 @@ const KILLALL_OPTIONS = new Map([
|
|
|
157
182
|
["-v", OPT_FLAG], ["--verbose", OPT_FLAG], ["-V", OPT_FLAG], ["--version", OPT_FLAG], ["-w", OPT_FLAG], ["--wait", OPT_FLAG], ["-d", OPT_FLAG], ["-z", OPT_FLAG], ["--help", OPT_FLAG],
|
|
158
183
|
]);
|
|
159
184
|
const takesValue = (opt) => opt !== undefined && (opt.does === "select" || opt.does === "context" || opt.does === "filter" || opt.does === "valued");
|
|
160
|
-
const OPTIONS_END_AT_FIRST_NAME = process.platform !== "linux";
|
|
161
185
|
const KILLALL_VALUED_LETTERS = new Set([...KILLALL_OPTIONS].filter(([spelling, opt]) => !spelling.startsWith("--") && takesValue(opt)).map(([spelling]) => spelling.slice(1)));
|
|
162
186
|
function optionsOf(w) {
|
|
163
187
|
if (w.startsWith("--")) {
|
|
@@ -185,7 +209,7 @@ function readKillallWords(words) {
|
|
|
185
209
|
}
|
|
186
210
|
if (!w.startsWith("-") || w === "-") {
|
|
187
211
|
names.push(w);
|
|
188
|
-
if (
|
|
212
|
+
if (OPTIONS_END_AT_FIRST_OPERAND) {
|
|
189
213
|
names.push(...words.slice(i + 1));
|
|
190
214
|
break;
|
|
191
215
|
}
|
|
@@ -238,7 +262,7 @@ function readSelector(segment) {
|
|
|
238
262
|
const names = read.words.filter((w, i) => !w.startsWith("-") && read.words[i - 1] !== "-o");
|
|
239
263
|
return { text: shown(segment), probes: names.map((n) => [...NAME_SELECTION_KEEPS_ANCESTORS, "-x", literalName(n)]) };
|
|
240
264
|
}
|
|
241
|
-
return { text: shown(segment), probes: [
|
|
265
|
+
return { text: shown(segment), probes: [readSelection(read.words, "pgrep").words] };
|
|
242
266
|
}
|
|
243
267
|
const SELECTORS = new Set(["pgrep", "pidof"]);
|
|
244
268
|
const EVERY_PROCESS_PID = /^-0*1$/;
|
|
@@ -358,12 +382,8 @@ const SENTENCE = {
|
|
|
358
382
|
computed: (f) => `Error (Bash): refusing to run \`${f.text}\` — which processes it selects is decided when the command runs (${f.why}), so it cannot first be checked against this agent's own process and the processes above it. Write the pattern into the command as a literal, ${WAY_OUT}.`,
|
|
359
383
|
unavailable: (f) => `Error (Bash): refusing to run \`${f.text}\` — the check that its selection holds neither this agent's own process nor a process above it could not run (${f.why}). Stop the process by its PID, or target your own children with \`pkill -P $$ ...\`.`,
|
|
360
384
|
};
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return undefined;
|
|
364
|
-
const readings = patternKillReadings(command, cwd);
|
|
365
|
-
if (readings.length === 0)
|
|
366
|
-
return undefined;
|
|
385
|
+
const UNDECLARED_TABLE = "the execution environment does not declare whether its commands run on this agent's process table — `capabilities.sharesProcessTable` is missing or not a boolean";
|
|
386
|
+
async function findingsOnThisTable(readings, signal) {
|
|
367
387
|
const found = [];
|
|
368
388
|
const asked = await Promise.all(readings.map(async (r) => ({ r, answers: await Promise.all(r.probes.map((p) => selected(p, signal))) })));
|
|
369
389
|
let ancestry;
|
|
@@ -389,6 +409,18 @@ export async function patternKillRefusal(command, env, cwd, signal) {
|
|
|
389
409
|
found.push({ kind: "hit", text: r.text, pid, own: pid === process.pid });
|
|
390
410
|
}
|
|
391
411
|
}
|
|
412
|
+
return found;
|
|
413
|
+
}
|
|
414
|
+
export async function patternKillRefusal(command, env, cwd, signal) {
|
|
415
|
+
if (process.platform === "win32")
|
|
416
|
+
return undefined;
|
|
417
|
+
const readings = patternKillReadings(command, cwd).filter((r) => r.probes.length > 0 || r.computed !== undefined || r.everyProcess === true);
|
|
418
|
+
if (readings.length === 0)
|
|
419
|
+
return undefined;
|
|
420
|
+
const table = processTableOf(env);
|
|
421
|
+
if (table === "other")
|
|
422
|
+
return undefined;
|
|
423
|
+
const found = table === "this" ? await findingsOnThisTable(readings, signal) : [{ kind: "unavailable", text: readings[0].text, why: UNDECLARED_TABLE }];
|
|
392
424
|
const f = found.find((x) => x.kind === "hit") ?? found.find((x) => x.kind === "computed") ?? found[0];
|
|
393
425
|
if (f === undefined || signal?.aborted === true)
|
|
394
426
|
return undefined;
|
package/dist/tools/fs/safety.js
CHANGED
|
@@ -444,7 +444,7 @@ function within(rootCanonical, p) {
|
|
|
444
444
|
}
|
|
445
445
|
export async function resolveKey(env, rootCanonical, path, signal, baseCwd, additionalRoots, exactFileReadExemption, readDeny, containmentFace) {
|
|
446
446
|
const views = await readPath(env, path, baseCwd ?? rootCanonical, { root: rootCanonical, ...(baseCwd !== undefined ? { cwd: baseCwd } : {}) }, { intent: "resolve", views: readDeny !== undefined ? "chain" : "canonical" }, signal);
|
|
447
|
-
const canon = views.canonical ??
|
|
447
|
+
const canon = views.canonical ?? { ok: false, message: `cannot resolve path "${clipSpelling(path)}": ${views.lexical?.kind === "unreadable" ? views.lexical.reason : "the environment was not asked where it lands"}; refused.` };
|
|
448
448
|
if (!canon.ok)
|
|
449
449
|
return { ok: false, violation: { code: "invalid", message: canon.message } };
|
|
450
450
|
const key = canon.key;
|
|
@@ -545,6 +545,10 @@ async function probeRealTarget(env, path, target, family, signal) {
|
|
|
545
545
|
if (!newPath.ok) {
|
|
546
546
|
return { ok: false, message: newPath.message, unresolvedSymlink: true };
|
|
547
547
|
}
|
|
548
|
+
if ("reprobe" in newPath) {
|
|
549
|
+
abs = newPath.reprobe;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
548
552
|
return { ok: true, key: newPath.key };
|
|
549
553
|
}
|
|
550
554
|
const canon = await env.canonicalPath(abs, signal);
|
|
@@ -559,6 +563,10 @@ async function probeRealTarget(env, path, target, family, signal) {
|
|
|
559
563
|
if (!viaAncestors.ok) {
|
|
560
564
|
return { ok: false, message: viaAncestors.message, unresolvedSymlink: true };
|
|
561
565
|
}
|
|
566
|
+
if ("reprobe" in viaAncestors) {
|
|
567
|
+
abs = viaAncestors.reprobe;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
562
570
|
return { ok: true, key: viaAncestors.key };
|
|
563
571
|
}
|
|
564
572
|
if (!env.readLink) {
|
|
@@ -584,7 +592,7 @@ async function probeRealTarget(env, path, target, family, signal) {
|
|
|
584
592
|
}
|
|
585
593
|
abs = reabs.value;
|
|
586
594
|
}
|
|
587
|
-
return { ok: false, message: `
|
|
595
|
+
return { ok: false, message: `resolving "${path}" exceeded the hop cap (links followed, or a \`..\` back into an existing directory re-probed); target unresolved`, unresolvedSymlink: true };
|
|
588
596
|
}
|
|
589
597
|
function parentDir(abs) {
|
|
590
598
|
const i = lastSepIndex(abs);
|
|
@@ -623,15 +631,39 @@ async function canonicalizeNewPath(env, abs, family, signal, opts) {
|
|
|
623
631
|
if (!canon.ok) {
|
|
624
632
|
return { ok: false, message: `cannot canonicalize existing ancestor "${candidate}": ${canon.error.message}` };
|
|
625
633
|
}
|
|
626
|
-
|
|
627
|
-
const canonSep = nativeSepOf(canon.value);
|
|
628
|
-
if (tailSegments.length === 0)
|
|
629
|
-
return { ok: true, key: canon.value };
|
|
630
|
-
return { ok: true, key: [canon.value.replace(family === "win" ? /[\\/]+$/ : /\/+$/, ""), ...tailSegments].join(canonSep) };
|
|
634
|
+
return { ok: true, ...rejoinMissingTail(canon.value, tail.reverse(), family) };
|
|
631
635
|
}
|
|
632
636
|
tail.push(parts.pop());
|
|
633
637
|
}
|
|
634
|
-
|
|
638
|
+
const share = family === "win" && isUncSpelling(abs) ? tail.pop() : undefined;
|
|
639
|
+
return { ok: true, ...rejoinMissingTail(`${[...parts, ...(share !== undefined ? [share] : [])].join(sep)}${sep}`, tail.reverse(), family) };
|
|
640
|
+
}
|
|
641
|
+
function rejoinMissingTail(canonical, tail, family) {
|
|
642
|
+
const trimmed = (at) => at.replace(family === "win" ? /[\\/]+$/ : /\/+$/, "");
|
|
643
|
+
let at = canonical;
|
|
644
|
+
const names = [];
|
|
645
|
+
for (let i = 0; i < tail.length; i++) {
|
|
646
|
+
const seg = tail[i];
|
|
647
|
+
if (seg === "" || seg === ".")
|
|
648
|
+
continue;
|
|
649
|
+
if (seg !== "..")
|
|
650
|
+
names.push(seg);
|
|
651
|
+
else if (names.length > 1)
|
|
652
|
+
names.pop();
|
|
653
|
+
else {
|
|
654
|
+
if (names.length === 1)
|
|
655
|
+
names.pop();
|
|
656
|
+
else {
|
|
657
|
+
const up = normalizeAbsPathLexically(`${at}/..`);
|
|
658
|
+
if (up !== normalizeAbsPathLexically(at))
|
|
659
|
+
at = up;
|
|
660
|
+
}
|
|
661
|
+
const rest = tail.slice(i + 1);
|
|
662
|
+
if (rest.some((s) => s !== "" && s !== "."))
|
|
663
|
+
return { reprobe: [trimmed(at), ...rest].join(nativeSepOf(at)) };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return { key: names.length === 0 ? at : [trimmed(at), ...names].join(nativeSepOf(at)) };
|
|
635
667
|
}
|
|
636
668
|
export function violationText(toolName, v) {
|
|
637
669
|
return `Error (${toolName}): ${v.message}`;
|
package/dist/tools/fs/search.js
CHANGED
|
@@ -40,25 +40,6 @@ const TYPE_GLOBS = {
|
|
|
40
40
|
css: "*.{css,scss,less}",
|
|
41
41
|
};
|
|
42
42
|
const basename = (p) => p.slice(Math.max(p.lastIndexOf("/"), p.lastIndexOf("\\")) + 1);
|
|
43
|
-
function collapseDotSegments(p) {
|
|
44
|
-
const win = isWinFormPath(p);
|
|
45
|
-
const lead = (win ? /^[\\/]*/ : /^\/*/).exec(p)?.[0] ?? "";
|
|
46
|
-
const sep = win ? "\\" : "/";
|
|
47
|
-
const parts = p.slice(lead.length).split(win ? /[\\/]+/ : /\/+/);
|
|
48
|
-
const floor = !win ? 0 : lead.length >= 2 ? 2 : /^[A-Za-z]:$/.test(parts[0] ?? "") ? 1 : 0;
|
|
49
|
-
const kept = [];
|
|
50
|
-
for (const part of parts) {
|
|
51
|
-
if (part === "" || part === ".")
|
|
52
|
-
continue;
|
|
53
|
-
if (part === "..") {
|
|
54
|
-
if (kept.length > floor)
|
|
55
|
-
kept.pop();
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
kept.push(part);
|
|
59
|
-
}
|
|
60
|
-
return kept.length === 0 ? "" : lead + kept.join(sep);
|
|
61
|
-
}
|
|
62
43
|
const NO_MATCHES = "No matches.";
|
|
63
44
|
const GREP_LINE_CLIP = 500;
|
|
64
45
|
function clipLine(line) {
|
|
@@ -813,18 +794,19 @@ export async function jsGrepDetailed(env, root, p, signal, guards, deny, denyOut
|
|
|
813
794
|
const mode = p.output_mode ?? "files_with_matches";
|
|
814
795
|
const rel = (abs) => (abs.startsWith(rootPrefix) ? abs.slice(rootPrefix.length) : abs);
|
|
815
796
|
const startWin = isWinFormPath(start);
|
|
816
|
-
const
|
|
817
|
-
const
|
|
797
|
+
const trailingSeparators = startWin ? /[\\/]+$/ : /\/+$/;
|
|
798
|
+
const anchor = start.replace(trailingSeparators, "");
|
|
799
|
+
const targetSpell = p.path ? p.path.replace(trailingSeparators, "") : "";
|
|
818
800
|
const isBoundary = (c) => c === "/" || (startWin && c === "\\");
|
|
819
801
|
const relOut = (abs) => {
|
|
820
802
|
if (!p.path) {
|
|
821
803
|
const r = rel(abs);
|
|
822
804
|
return r === abs ? r : `./${r}`;
|
|
823
805
|
}
|
|
824
|
-
if (abs ===
|
|
806
|
+
if (abs === start || abs === anchor)
|
|
825
807
|
return targetSpell;
|
|
826
|
-
if (abs.startsWith(
|
|
827
|
-
return targetSpell + abs.slice(
|
|
808
|
+
if (abs.startsWith(anchor) && isBoundary(abs[anchor.length]))
|
|
809
|
+
return targetSpell + abs.slice(anchor.length);
|
|
828
810
|
return rel(abs);
|
|
829
811
|
};
|
|
830
812
|
if (p.glob) {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import type { ExecutionEnv } from "../../internal/harness-types.js";
|
|
21
21
|
import { violationDetails } from "./safety.js";
|
|
22
22
|
import { type ShellReadPlan } from "./shell-read-plan.js";
|
|
23
|
+
import { type ReadLanding } from "./shell-read-identity.js";
|
|
23
24
|
import { type HomeViewSource } from "./read-deny-home.js";
|
|
24
25
|
import { type EstablishedRead, type ShellReadBoundary, type ShellReadDisposition, type ShellReadFinding, type ShellReadSeat } from "./shell-read-judge.js";
|
|
25
26
|
import type { ReadRootGrantCandidate } from "../../core/tool-spec.js";
|
|
@@ -104,8 +105,15 @@ export interface ShellReadVerdictFacts {
|
|
|
104
105
|
readonly writesPlaced?: true;
|
|
105
106
|
/** A FACT beside the disposition: a write target this command names lands on the write-protection table — judged by
|
|
106
107
|
* the table's own judge, as a write tool's target is — so the command's ask carries that table's class, whichever
|
|
107
|
-
* mode reads it. Absent ⇒ no target the station established is covered (or no judge is mounted).
|
|
108
|
+
* mode reads it. Absent ⇒ no target the station established is covered (or no judge is mounted). Said of a target whose
|
|
109
|
+
* TEXT names the row (the table's spelling view of one of its spellings); a covered target whose text names none is the
|
|
110
|
+
* member below — one target, one of the two. */
|
|
108
111
|
readonly writeProtected?: true;
|
|
112
|
+
/** A FACT beside the disposition: a write target this command names meets the write-protection table only where it resolves
|
|
113
|
+
* on disk (its real target, a link on the way) — none of the target's spellings names a row — so the command's ask carries
|
|
114
|
+
* that reading's class, which the auto-mode classifier does not answer. Beside `writeProtected` when another target's text
|
|
115
|
+
* names a row. Absent ⇒ no such target (or no judge is mounted). */
|
|
116
|
+
readonly writeProtectedOnDisk?: true;
|
|
109
117
|
/** A FACT beside the disposition: a target this command's program WRITES was placed and the environment could not say
|
|
110
118
|
* where it leads ({@link EstablishedRead.unresolved}) — the reading's `target_unresolved` fact, the same one a write
|
|
111
119
|
* tool's unresolved target states, so the command's ask carries that class (no automatic lane answers it; the shell face
|
|
@@ -169,9 +177,18 @@ export type ShellReadAdmission = (toolName: string, toolCallId: string | undefin
|
|
|
169
177
|
isError: true;
|
|
170
178
|
details?: unknown;
|
|
171
179
|
} | undefined>;
|
|
180
|
+
/** Where the station's last non-refused judgment of a call found its reads land (`readLandingsOf`): the judgment its
|
|
181
|
+
* admission holds for the call id — the one the spawn re-establishes — read without consuming it. `undefined` ⇒ the
|
|
182
|
+
* station holds none (a refused judgment records nothing). Its readers take it right where the latest judgment is a
|
|
183
|
+
* non-refused one of the bytes they hold: the park when the filed bytes are the judged ones, the resumed leg's execution
|
|
184
|
+
* station after its belt. A judgment that settles after a newer one replaced it is what the spawn would re-establish too:
|
|
185
|
+
* the spawn then refuses bytes the entry does not describe, and a row bound to it vetoes the resume wherever the two
|
|
186
|
+
* commands' reads differ (fail-closed either way). */
|
|
187
|
+
export type ShellReadLandings = (toolCallId: string) => readonly ReadLanding[] | undefined;
|
|
172
188
|
export interface ShellReadStation {
|
|
173
189
|
readonly check: ShellReadCheck;
|
|
174
190
|
readonly admit: ShellReadAdmission;
|
|
191
|
+
readonly landings: ShellReadLandings;
|
|
175
192
|
}
|
|
176
193
|
export interface ShellReadStationOptions {
|
|
177
194
|
readonly env: ExecutionEnv;
|