@dsmm/dsmm 0.3.1 → 0.3.2
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/cordis.patch.yml +9 -0
- package/docs/compatibility.md +10 -0
- package/docs/releasing.md +25 -65
- package/docs/roadmap.md +44 -2
- package/lib/client/ChildPermissions.d.ts +43 -0
- package/lib/client/ChildPermissions.js +100 -0
- package/lib/client/ChildrenPanel.d.ts +4 -1
- package/lib/client/ChildrenPanel.js +3 -3
- package/lib/client/DeploymentFields.d.ts +6 -2
- package/lib/client/DeploymentFields.js +8 -6
- package/lib/client/DeploymentPage.d.ts +4 -1
- package/lib/client/DeploymentPage.js +5 -4
- package/lib/client/HistoryContinuation.d.ts +7 -0
- package/lib/client/HistoryContinuation.js +22 -0
- package/lib/client/PermissionPanelEntry.d.ts +8 -0
- package/lib/client/PermissionPanelEntry.js +11 -0
- package/lib/client/PermissionsPanel.d.ts +3 -1
- package/lib/client/PermissionsPanel.js +3 -2
- package/lib/client/ProfilesSection.js +3 -3
- package/lib/client/RoleAvailability.js +1 -1
- package/lib/client/SessionProfiles.js +21 -18
- package/lib/client/TemporaryPermissions.d.ts +21 -0
- package/lib/client/TemporaryPermissions.js +94 -0
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.d.ts +17 -0
- package/lib/client/controller.js +101 -18
- package/lib/client/deployment-locales.js +26 -26
- package/lib/client/history-controller.d.ts +29 -0
- package/lib/client/history-controller.js +111 -0
- package/lib/client/history-entry.d.ts +11 -0
- package/lib/client/history-entry.js +106 -0
- package/lib/client/history-locales.d.ts +95 -0
- package/lib/client/history-locales.js +41 -0
- package/lib/client/index.js +16 -3
- package/lib/client/locales.d.ts +6 -0
- package/lib/client/locales.js +104 -92
- package/lib/client/permission-locales.d.ts +26 -0
- package/lib/client/permission-locales.js +55 -35
- package/lib/client/temporary-permission-client.d.ts +20 -0
- package/lib/client/temporary-permission-client.js +52 -0
- package/lib/client/temporary-permission-entry.d.ts +6 -0
- package/lib/client/temporary-permission-entry.js +56 -0
- package/lib/client.js +3881 -1981
- package/lib/history-candidates.d.ts +30 -0
- package/lib/history-candidates.js +176 -0
- package/lib/history-codec.d.ts +11 -0
- package/lib/history-codec.js +102 -0
- package/lib/history-contract.d.ts +44 -0
- package/lib/history-contract.js +2 -0
- package/lib/history-controller.d.ts +42 -0
- package/lib/history-controller.js +329 -0
- package/lib/history-policy.d.ts +4 -0
- package/lib/history-policy.js +8 -0
- package/lib/history-remote.d.ts +28 -0
- package/lib/history-remote.js +17 -0
- package/lib/history-rpc.d.ts +24 -0
- package/lib/history-rpc.js +136 -0
- package/lib/history-support.d.ts +15 -0
- package/lib/history-support.js +21 -0
- package/lib/history-types.d.ts +67 -0
- package/lib/history-types.js +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +24 -6
- package/lib/native-admission.d.ts +21 -0
- package/lib/native-admission.js +206 -16
- package/lib/permission-child-control.d.ts +36 -0
- package/lib/permission-child-control.js +164 -0
- package/lib/permission-control.d.ts +2 -0
- package/lib/permission-control.js +7 -0
- package/lib/permission-controller.js +2 -2
- package/lib/permission-exec-argv.d.ts +32 -0
- package/lib/permission-exec-argv.js +171 -0
- package/lib/permission-fs-search.js +2 -1
- package/lib/permission-fs.js +2 -1
- package/lib/permission-native-rules.js +3 -3
- package/lib/permission-temporary-files.d.ts +19 -0
- package/lib/permission-temporary-files.js +248 -0
- package/lib/permission-temporary-grants.d.ts +106 -0
- package/lib/permission-temporary-grants.js +198 -0
- package/lib/permission-temporary-install.d.ts +25 -0
- package/lib/permission-temporary-install.js +86 -0
- package/lib/permission-temporary-remote.d.ts +19 -0
- package/lib/permission-temporary-remote.js +75 -0
- package/lib/permission-temporary-rpc.d.ts +37 -0
- package/lib/permission-temporary-rpc.js +154 -0
- package/lib/permission-temporary-types.d.ts +47 -0
- package/lib/permission-temporary-types.js +2 -0
- package/lib/permission-temporary-web.d.ts +11 -0
- package/lib/permission-temporary-web.js +154 -0
- package/lib/permission-web.js +2 -1
- package/lib/preset-skills.d.ts +1 -1
- package/lib/preset-skills.js +2 -2
- package/lib/profile-rpc.js +2 -0
- package/lib/profile-runtime.d.ts +12 -1
- package/lib/profile-runtime.js +122 -10
- package/lib/profile-store.d.ts +2 -2
- package/lib/profile-store.js +8 -1
- package/lib/profile-types.d.ts +1 -0
- package/lib/role-invocation.d.ts +1 -1
- package/lib/role-invocation.js +2 -2
- package/lib/role-subagents.js +16 -3
- package/lib/skills.d.ts +1 -0
- package/lib/skills.js +5 -1
- package/package.json +41 -33
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
- package/patches/dsh-approval-settlement/README.md +41 -0
- package/patches/dsh-approval-settlement/metadata.json +10 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
|
@@ -41,6 +41,8 @@ export interface PermissionRegistration {
|
|
|
41
41
|
export declare function permissionOriginal(value: object): object;
|
|
42
42
|
type Request = Parameters<Context["approval"]["request"]>[0];
|
|
43
43
|
type Outcome = Awaited<ReturnType<Context["approval"]["request"]>>;
|
|
44
|
+
/** Explicitly audited DSMM approval adapters retain identity through the patched dispatcher. */
|
|
45
|
+
export declare function permissionApprovalAdapter(ctx: Context, listener: (request: Request, next: () => Promise<Outcome>) => Promise<Outcome>): typeof listener;
|
|
44
46
|
export declare function isSandboxWidening(requested: NativeCommandEntry["sandboxMode"], standing: string | undefined): boolean;
|
|
45
47
|
/** Permission admission precedes native approval; subsequent checks enforce execution integrity only. */
|
|
46
48
|
export declare class PermissionControl {
|
|
@@ -6,6 +6,13 @@ import { PermissionRefusal, permissionOutcome } from "./permission-errors.js";
|
|
|
6
6
|
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
7
7
|
export { PermissionRefusal } from "./permission-errors.js";
|
|
8
8
|
export function permissionOriginal(value) { return Reflect.get(value, symbols.original) ?? value; }
|
|
9
|
+
/** Explicitly audited DSMM approval adapters retain identity through the patched dispatcher. */
|
|
10
|
+
export function permissionApprovalAdapter(ctx, listener) {
|
|
11
|
+
const approval = ctx.get("approval"), factory = approval && Reflect.get(approval, "createForwarder");
|
|
12
|
+
if (typeof factory !== "function")
|
|
13
|
+
return listener;
|
|
14
|
+
return Reflect.apply(factory, approval, [listener]);
|
|
15
|
+
}
|
|
9
16
|
export function isSandboxWidening(requested, standing) {
|
|
10
17
|
return standing === "read-only" || standing === "workspace-write" && requested === "danger-full-access";
|
|
11
18
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Service } from "@deepseek-ai/cordis";
|
|
2
2
|
import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
3
3
|
import { TOOL_ABORTED } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
import { isSandboxWidening, PermissionControl, PermissionRefusal } from "./permission-control.js";
|
|
4
|
+
import { isSandboxWidening, PermissionControl, PermissionRefusal, permissionApprovalAdapter } from "./permission-control.js";
|
|
5
5
|
import { classifyPermissionShell } from "./permission-shell.js";
|
|
6
6
|
import { nativeCommandMatch } from "./permission-native-command.js";
|
|
7
7
|
import { NATIVE_PERMISSION_CAPABILITIES, registerNativePermissionRules } from "./permission-native-rules.js";
|
|
@@ -109,7 +109,7 @@ export class DsmmPermissionController extends Service {
|
|
|
109
109
|
},
|
|
110
110
|
});
|
|
111
111
|
ctx.tools.guard(exec => this.permissions.guard(exec));
|
|
112
|
-
ctx.on("approval/request", (request, next) => this.permissions.answerer(request, next), { prepend: true, global: true });
|
|
112
|
+
ctx.on("approval/request", permissionApprovalAdapter(ctx, (request, next) => this.permissions.answerer(request, next)), { prepend: true, global: true });
|
|
113
113
|
ctx.on("tools/result", exec => { this.permissions.finish(exec); }, { global: true });
|
|
114
114
|
ctx.on("agent/disposed", ({ agent }) => { this.permissions.revokeAgent(agent); }, { global: true });
|
|
115
115
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
|
|
4
|
+
export interface ArgvInput {
|
|
5
|
+
readonly executable: string;
|
|
6
|
+
readonly args: readonly string[];
|
|
7
|
+
readonly cwd: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ArgvPermissionAuthority {
|
|
10
|
+
readonly owner: object;
|
|
11
|
+
readonly generation: string | number;
|
|
12
|
+
readonly sessionSignal: AbortSignal;
|
|
13
|
+
/** Includes live ownership and absolute role/readonly ceilings, not a config-revision veto. */
|
|
14
|
+
assertIntegrity(): void;
|
|
15
|
+
/** Initial admission and reusable permits include every applicable command/path/tool deny. */
|
|
16
|
+
assertProgramAllowed(): void;
|
|
17
|
+
/** A child additionally needs its current explicit operator interaction authority. */
|
|
18
|
+
assertRetentionAllowed?(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface ArgvPermissionOptions {
|
|
21
|
+
readonly grants: TemporaryPermissionGrants;
|
|
22
|
+
capture(execution: Readonly<ToolExecution>, input: ArgvInput): ArgvPermissionAuthority;
|
|
23
|
+
/** Explicit Host classification; unknown programs and interpreters are once-only. */
|
|
24
|
+
programKind(executable: string): "native" | "interpreter" | "unknown";
|
|
25
|
+
readonly environment?: Readonly<Record<string, string | undefined>>;
|
|
26
|
+
readonly maxOutputBytes?: number;
|
|
27
|
+
readonly timeoutMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function effectiveArgvEnvironment(overrides: Readonly<Record<string, string | undefined>>, parent?: Record<string, string>): string;
|
|
30
|
+
/** Explicit argv only. Native shell tools keep their own semantics and approvals. */
|
|
31
|
+
export declare function installPermissionExecArgv(ctx: Context, options: ArgvPermissionOptions): () => void;
|
|
32
|
+
//# sourceMappingURL=permission-exec-argv.d.ts.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { realpath } from "node:fs/promises";
|
|
4
|
+
import { LocalSubprocessRuntime } from "@deepseek-ai/dsh-subprocess-local";
|
|
5
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
6
|
+
import { permissionOriginal } from "./permission-control.js";
|
|
7
|
+
// Resolve the public seam through the installed local provider, not private provider files.
|
|
8
|
+
const subprocessModule = createRequire(createRequire(import.meta.url).resolve("@deepseek-ai/dsh-subprocess-local"))("@deepseek-ai/dsh-subprocess");
|
|
9
|
+
export function effectiveArgvEnvironment(overrides, parent = subprocessModule.scrubbedParentEnv()) {
|
|
10
|
+
const entries = new Map();
|
|
11
|
+
const ambiguous = new Set();
|
|
12
|
+
const keyOf = (key) => process.platform === "win32" ? key.toUpperCase() : key;
|
|
13
|
+
for (const [key, value] of Object.entries(parent)) {
|
|
14
|
+
const normalized = keyOf(key);
|
|
15
|
+
if (entries.has(normalized) && entries.get(normalized) !== value)
|
|
16
|
+
ambiguous.add(normalized);
|
|
17
|
+
entries.set(normalized, value);
|
|
18
|
+
}
|
|
19
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
20
|
+
ambiguous.delete(keyOf(key));
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
entries.delete(keyOf(key));
|
|
23
|
+
else
|
|
24
|
+
entries.set(keyOf(key), value);
|
|
25
|
+
}
|
|
26
|
+
if (ambiguous.size)
|
|
27
|
+
throw new Error("Ambiguous case-insensitive target environment.");
|
|
28
|
+
return JSON.stringify([...entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
29
|
+
}
|
|
30
|
+
function parseInput(value) {
|
|
31
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
32
|
+
throw new TypeError("Expected structured argv.");
|
|
33
|
+
const row = value;
|
|
34
|
+
if (Object.keys(row).some(key => !["executable", "args", "cwd"].includes(key)) || typeof row.executable !== "string"
|
|
35
|
+
|| !isAbsolute(row.executable) || typeof row.cwd !== "string" || !isAbsolute(row.cwd)
|
|
36
|
+
|| !Array.isArray(row.args) || row.args.some(arg => typeof arg !== "string" || arg.includes("\0"))
|
|
37
|
+
|| row.executable.includes("\0") || row.cwd.includes("\0"))
|
|
38
|
+
throw new TypeError("Absolute executable/cwd and a complete string argv are required.");
|
|
39
|
+
return Object.freeze({ executable: row.executable, cwd: row.cwd, args: Object.freeze([...row.args]) });
|
|
40
|
+
}
|
|
41
|
+
async function assertCanonical(input) {
|
|
42
|
+
const [executable, cwd] = await Promise.all([realpath(input.executable), realpath(input.cwd)]);
|
|
43
|
+
if (executable !== input.executable || cwd !== input.cwd)
|
|
44
|
+
throw new Error("Use canonical absolute executable and working-directory paths.");
|
|
45
|
+
}
|
|
46
|
+
/** Explicit argv only. Native shell tools keep their own semantics and approvals. */
|
|
47
|
+
export function installPermissionExecArgv(ctx, options) {
|
|
48
|
+
const subprocess = ctx.get("subprocess"), sandbox = ctx.get("sandbox"), policyService = ctx.get("sandboxPolicy");
|
|
49
|
+
if (!subprocess || !policyService)
|
|
50
|
+
throw new Error("Native subprocess and sandbox policy services required.");
|
|
51
|
+
const original = permissionOriginal(subprocess);
|
|
52
|
+
const policyOwner = permissionOriginal(policyService), sandboxOwner = sandbox && permissionOriginal(sandbox);
|
|
53
|
+
const spawnMethod = Reflect.get(original, "spawn"), resolveMethod = Reflect.get(original, "resolveExecutable");
|
|
54
|
+
const policyMethod = Reflect.get(policyOwner, "resolve"), confineMethod = sandboxOwner && Reflect.get(sandboxOwner, "confine");
|
|
55
|
+
if (Object.getPrototypeOf(original) !== LocalSubprocessRuntime.prototype
|
|
56
|
+
|| Reflect.get(original, "spawn") !== LocalSubprocessRuntime.prototype.spawn
|
|
57
|
+
|| Reflect.get(original, "resolveExecutable") !== LocalSubprocessRuntime.prototype.resolveExecutable)
|
|
58
|
+
throw new Error("Only the verified local subprocess provider is supported.");
|
|
59
|
+
const overrides = Object.freeze({ ...options.environment }), lifetime = new AbortController();
|
|
60
|
+
if (Object.keys(overrides).some(key => overrides[key] !== undefined && (subprocessModule.SENSITIVE_ENV_PATTERN.test(key) || /^DSH_/iu.test(key))))
|
|
61
|
+
throw new Error("Credential and Host identity overrides are not supported by this tool.");
|
|
62
|
+
const prepared = new Map();
|
|
63
|
+
const definition = defineTool({
|
|
64
|
+
name: "dsmm_exec_argv",
|
|
65
|
+
description: "Run an absolute executable with complete literal argv and cwd under the current sandbox. No shell, env input, escalation, stdin or PTY. Approval does not pin binary contents or make subprocesses/hook effects read-only.",
|
|
66
|
+
parameters: {
|
|
67
|
+
executable: { type: "string", required: true },
|
|
68
|
+
args: { type: "array", items: { type: "string" }, required: true },
|
|
69
|
+
cwd: { type: "string", required: true },
|
|
70
|
+
},
|
|
71
|
+
output: { schema: { type: "object", additionalProperties: false, properties: {
|
|
72
|
+
exitCode: { oneOf: [{ type: "number" }, { type: "null" }], required: true }, stdout: { type: "string", required: true }, stderr: { type: "string", required: true },
|
|
73
|
+
truncated: { type: "boolean", required: true }, enforcement: { type: "string", required: true },
|
|
74
|
+
} }, render(_args, value) { return [{ type: "text", text: JSON.stringify(value) }]; } },
|
|
75
|
+
async execute(args, exec) {
|
|
76
|
+
const item = prepared.get(exec.token);
|
|
77
|
+
if (!item)
|
|
78
|
+
throw new Error("Native approval preparation is unavailable.");
|
|
79
|
+
const { input, execution, lease, policy } = item;
|
|
80
|
+
const signal = AbortSignal.any([exec.signal, execution.signal, AbortSignal.timeout(options.timeoutMs ?? 30_000)]);
|
|
81
|
+
try {
|
|
82
|
+
if (JSON.stringify(parseInput(args)) !== JSON.stringify(input))
|
|
83
|
+
throw new Error("Execution arguments changed.");
|
|
84
|
+
let argv = [input.executable, ...input.args], enforcement = "standing-full-access";
|
|
85
|
+
if (policy.mode !== "danger-full-access") {
|
|
86
|
+
if (!sandbox)
|
|
87
|
+
throw new Error("Sandbox backend unavailable; no unconfined fallback.");
|
|
88
|
+
const confined = await sandbox.confine(argv, { ...policy, mode: policy.mode, sessionId: exec.agent?.id }, signal);
|
|
89
|
+
if (confined.enforcement !== "full" && confined.enforcement !== "partial")
|
|
90
|
+
throw new Error("Sandbox enforcement unavailable.");
|
|
91
|
+
argv = confined.argv;
|
|
92
|
+
enforcement = confined.enforcement;
|
|
93
|
+
}
|
|
94
|
+
await assertCanonical(input);
|
|
95
|
+
const spec = { argv, cwd: input.cwd, env: overrides, signal, graceMs: 200,
|
|
96
|
+
stdio: { stdin: "ignore", stdout: { maxBytes: options.maxOutputBytes ?? 16_384 }, stderr: { maxBytes: options.maxOutputBytes ?? 16_384 } } };
|
|
97
|
+
// The complete effective environment is checked after all asynchronous preparation.
|
|
98
|
+
signal.throwIfAborted();
|
|
99
|
+
execution.assertIntegrity();
|
|
100
|
+
lease.consume();
|
|
101
|
+
const handle = subprocess.spawn(spec);
|
|
102
|
+
const outcome = await handle.done;
|
|
103
|
+
const stdout = handle.collected.stdout.readFrom(0), stderr = handle.collected.stderr.readFrom(0);
|
|
104
|
+
return { exitCode: outcome.exitCode, stdout: stdout.text, stderr: stderr.text,
|
|
105
|
+
truncated: stdout.lossy || stderr.lossy, enforcement };
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
lease.finish();
|
|
109
|
+
prepared.delete(exec.token);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
const unregister = ctx.tools.register(definition);
|
|
114
|
+
const registeredBody = definition.execute;
|
|
115
|
+
const pre = ctx.on("tools/pre-execute", async (exec, next) => {
|
|
116
|
+
if (ctx.tools.get(exec.name, exec.agent) !== definition)
|
|
117
|
+
return next();
|
|
118
|
+
const downstream = await next();
|
|
119
|
+
if (downstream.kind === "deny" || downstream.kind === "cancel")
|
|
120
|
+
return downstream;
|
|
121
|
+
if (!exec.agent)
|
|
122
|
+
return { kind: "deny", reason: "A live owned session is required." };
|
|
123
|
+
const input = parseInput(exec.arguments), authority = options.capture(exec, input);
|
|
124
|
+
authority.assertIntegrity();
|
|
125
|
+
authority.assertProgramAllowed();
|
|
126
|
+
const capturedPolicy = policyService.resolve({ session: exec.agent.session });
|
|
127
|
+
const policy = Object.freeze({ ...capturedPolicy }), environment = effectiveArgvEnvironment(overrides);
|
|
128
|
+
const signal = AbortSignal.any([exec.signal, authority.sessionSignal, lifetime.signal]);
|
|
129
|
+
const target = JSON.stringify({ input, environment, policy });
|
|
130
|
+
const check = () => {
|
|
131
|
+
signal.throwIfAborted();
|
|
132
|
+
authority.assertIntegrity();
|
|
133
|
+
if (ctx.tools.get(exec.name, exec.agent) !== definition || definition.execute !== registeredBody || permissionOriginal(ctx.subprocess) !== original
|
|
134
|
+
|| Reflect.get(original, "spawn") !== spawnMethod || Reflect.get(original, "resolveExecutable") !== resolveMethod
|
|
135
|
+
|| Reflect.get(policyOwner, "resolve") !== policyMethod || (sandboxOwner && Reflect.get(sandboxOwner, "confine")) !== confineMethod
|
|
136
|
+
|| (ctx.get("sandbox") && permissionOriginal(ctx.sandbox)) !== sandboxOwner
|
|
137
|
+
|| !ctx.get("sandboxPolicy") || permissionOriginal(ctx.sandboxPolicy) !== policyOwner
|
|
138
|
+
|| JSON.stringify(policyService.resolve({ session: exec.agent.session })) !== JSON.stringify(policy)
|
|
139
|
+
|| effectiveArgvEnvironment(overrides) !== environment)
|
|
140
|
+
throw new Error("Execution provider, policy or environment changed.");
|
|
141
|
+
};
|
|
142
|
+
const resolved = await subprocess.resolveExecutable(input.executable, undefined, signal);
|
|
143
|
+
await assertCanonical(input);
|
|
144
|
+
check();
|
|
145
|
+
if (resolved !== input.executable)
|
|
146
|
+
throw new Error("Executable identity changed; request its canonical absolute path.");
|
|
147
|
+
const execution = { token: exec.token, agent: exec.agent, owner: authority.owner,
|
|
148
|
+
generation: authority.generation, registration: definition, provider: original, sessionId: exec.agent.id,
|
|
149
|
+
tool: exec.name, project: exec.agent.session.header.cwd ?? "", target,
|
|
150
|
+
summary: `${input.executable} ${JSON.stringify(input.args)}\n${input.cwd}\n${policy.mode}; exact effective environment (values hidden). Program/config/hooks may change.`,
|
|
151
|
+
reusable: options.programKind(input.executable) === "native", signal, sessionSignal: authority.sessionSignal,
|
|
152
|
+
assertIntegrity: check, assertReusable() {
|
|
153
|
+
check();
|
|
154
|
+
authority.assertProgramAllowed();
|
|
155
|
+
authority.assertRetentionAllowed?.();
|
|
156
|
+
if (options.programKind(input.executable) !== "native")
|
|
157
|
+
throw new Error("Reusable program classification is no longer current.");
|
|
158
|
+
const approval = ctx.approval;
|
|
159
|
+
if ((approval.overrideOf(exec.agent.session) ?? approval.config.policy ?? "ask") !== "ask")
|
|
160
|
+
throw new Error("Current native policy does not allow automatic approval.");
|
|
161
|
+
} };
|
|
162
|
+
const lease = await options.grants.approve({ agent: exec.agent, toolName: exec.name, callId: exec.callId, signal,
|
|
163
|
+
reason: [downstream.kind === "ask" ? downstream.reason : undefined, execution.summary].filter(Boolean).join("\n") }, execution);
|
|
164
|
+
prepared.set(exec.token, { input, execution, policy, lease });
|
|
165
|
+
return { kind: "allow" };
|
|
166
|
+
}, { prepend: true, global: true });
|
|
167
|
+
const result = ctx.on("tools/result", exec => { const item = prepared.get(exec.token); item?.lease.finish(); prepared.delete(exec.token); }, { global: true });
|
|
168
|
+
return ctx.effect(() => () => { lifetime.abort(); pre(); result(); unregister(); for (const item of prepared.values())
|
|
169
|
+
item.lease.finish(); prepared.clear(); });
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=permission-exec-argv.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as Native from "@deepseek-ai/dsh-tool-fs-search";
|
|
2
2
|
import { DsmmPermissionController } from "./permission-controller.js";
|
|
3
|
+
import { temporaryFileToolScope } from "./permission-temporary-files.js";
|
|
3
4
|
export { Config, inject, name } from "@deepseek-ai/dsh-tool-fs-search";
|
|
4
5
|
export function apply(ctx, config) {
|
|
5
|
-
return Native.apply(DsmmPermissionController.toolScope(ctx, "fs-search"), config);
|
|
6
|
+
return Native.apply(temporaryFileToolScope(DsmmPermissionController.toolScope(ctx, "fs-search"), "fs-search"), config);
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=permission-fs-search.js.map
|
package/lib/permission-fs.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as Native from "@deepseek-ai/dsh-tool-fs";
|
|
2
2
|
import { DsmmPermissionController } from "./permission-controller.js";
|
|
3
|
+
import { temporaryFileToolScope } from "./permission-temporary-files.js";
|
|
3
4
|
export { Config, inject, name } from "@deepseek-ai/dsh-tool-fs";
|
|
4
5
|
export function apply(ctx, config) {
|
|
5
|
-
return Native.apply(DsmmPermissionController.toolScope(ctx, "fs"), config);
|
|
6
|
+
return Native.apply(temporaryFileToolScope(DsmmPermissionController.toolScope(ctx, "fs"), "fs"), config);
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=permission-fs.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, resolve } from "node:path";
|
|
2
|
-
import { PermissionRefusal } from "./permission-control.js";
|
|
2
|
+
import { PermissionRefusal, permissionApprovalAdapter } from "./permission-control.js";
|
|
3
3
|
import { permissionOutcome } from "./permission-errors.js";
|
|
4
4
|
import { classifyPermissionShell, parsePermissionShellReadPaths } from "./permission-shell.js";
|
|
5
5
|
import { intersectPermissionActions } from "./permission-rules.js";
|
|
@@ -249,13 +249,13 @@ export function registerNativePermissionRules(ctx, options) {
|
|
|
249
249
|
}
|
|
250
250
|
return downstream;
|
|
251
251
|
}, { prepend: true, global: true });
|
|
252
|
-
const unapproval = ctx.on("approval/request", async (request, next) => {
|
|
252
|
+
const unapproval = ctx.on("approval/request", permissionApprovalAdapter(ctx, async (request, next) => {
|
|
253
253
|
const ask = request.displayReason === undefined ? undefined : asks.get(request.displayReason);
|
|
254
254
|
if (ask === undefined || request.agent !== ask.exec.agent || request.signal !== ask.exec.signal || request.callId !== ask.exec.callId || request.toolName !== ask.exec.name)
|
|
255
255
|
return next();
|
|
256
256
|
checkIntegrity(ask.exec, ask.binding);
|
|
257
257
|
return permissionOutcome(next, ask.binding.signal, "cancelled");
|
|
258
|
-
}, { prepend: true, global: true });
|
|
258
|
+
}), { prepend: true, global: true });
|
|
259
259
|
const unguard = tools.guard(exec => {
|
|
260
260
|
const binding = bindings.get(exec.token);
|
|
261
261
|
if (binding === undefined)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
3
|
+
import type { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
|
|
4
|
+
import type { ArgvPermissionAuthority } from "./permission-exec-argv.js";
|
|
5
|
+
/** Called only around the actual native module's apply, before its definitions are registered. */
|
|
6
|
+
export declare function temporaryFileToolScope(scope: Context, module: "fs" | "fs-search"): Context;
|
|
7
|
+
export interface TemporaryFileOptions {
|
|
8
|
+
readonly grants: TemporaryPermissionGrants;
|
|
9
|
+
refresh?(): Promise<unknown>;
|
|
10
|
+
capture(execution: Readonly<ToolExecution>): ArgvPermissionAuthority;
|
|
11
|
+
}
|
|
12
|
+
/** Native asks are settled once by the existing ApprovalService; providers remain the original ones. */
|
|
13
|
+
export declare function installTemporaryFilePermissions(ctx: Context, options: TemporaryFileOptions): () => void;
|
|
14
|
+
declare module "@deepseek-ai/cordis" {
|
|
15
|
+
interface Context {
|
|
16
|
+
dsmmTemporaryFilePermissions: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=permission-temporary-files.d.ts.map
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
|
|
6
|
+
import { LocalSubprocessRuntime } from "@deepseek-ai/dsh-subprocess-local";
|
|
7
|
+
import { effectiveArgvEnvironment } from "./permission-exec-argv.js";
|
|
8
|
+
import { permissionOriginal } from "./permission-control.js";
|
|
9
|
+
const registrations = new WeakMap();
|
|
10
|
+
const resources = new WeakMap();
|
|
11
|
+
const running = new AsyncLocalStorage();
|
|
12
|
+
const operations = new Set(["stat", "readText", "streamText", "readBytes", "readByteRange", "listDir", "writeText", "editText"]);
|
|
13
|
+
const requireSearch = createRequire(createRequire(import.meta.url).resolve("@deepseek-ai/dsh-tool-fs-search"));
|
|
14
|
+
/** Called only around the actual native module's apply, before its definitions are registered. */
|
|
15
|
+
export function temporaryFileToolScope(scope, module) {
|
|
16
|
+
const fs = scope.get("fs"), subprocess = scope.get("subprocess"), tools = scope.tools;
|
|
17
|
+
if (!fs || Object.getPrototypeOf(permissionOriginal(fs)) !== LocalFileSystem.prototype)
|
|
18
|
+
return scope;
|
|
19
|
+
if ([...operations, "resolve", "contains", "processPath"].some(key => Reflect.get(permissionOriginal(fs), key) !== Reflect.get(LocalFileSystem.prototype, key)))
|
|
20
|
+
return scope;
|
|
21
|
+
const local = fs;
|
|
22
|
+
const facade = new Proxy(fs, { get(target, key) {
|
|
23
|
+
const value = Reflect.get(target, key, target);
|
|
24
|
+
if (typeof value !== "function")
|
|
25
|
+
return value;
|
|
26
|
+
if (typeof key !== "string" || !operations.has(key))
|
|
27
|
+
return value.bind(target);
|
|
28
|
+
return async (...args) => {
|
|
29
|
+
const active = running.getStore();
|
|
30
|
+
if (active?.registration.fs === local) {
|
|
31
|
+
await active.prepared.checkTarget(args[0], key === "stat");
|
|
32
|
+
active.prepared.check();
|
|
33
|
+
}
|
|
34
|
+
return Reflect.apply(value, target, args);
|
|
35
|
+
};
|
|
36
|
+
} });
|
|
37
|
+
const processFacade = subprocess && new Proxy(subprocess, { get(target, key) {
|
|
38
|
+
const value = Reflect.get(target, key, target);
|
|
39
|
+
if (key === "spawn")
|
|
40
|
+
return (spec) => {
|
|
41
|
+
const active = running.getStore();
|
|
42
|
+
if (active?.registration.subprocess === subprocess)
|
|
43
|
+
active.prepared.spawn(spec);
|
|
44
|
+
return target.spawn(spec);
|
|
45
|
+
};
|
|
46
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
47
|
+
} });
|
|
48
|
+
const toolFacade = new Proxy(tools, { get(target, key) {
|
|
49
|
+
if (key !== "register") {
|
|
50
|
+
const value = Reflect.get(target, key, target);
|
|
51
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
52
|
+
}
|
|
53
|
+
return (native) => {
|
|
54
|
+
const kind = native.name;
|
|
55
|
+
if (!(module === "fs" ? ["read", "write", "edit"] : ["glob", "grep"]).includes(kind))
|
|
56
|
+
return tools.register(native);
|
|
57
|
+
const body = native.execute;
|
|
58
|
+
const definition = { ...native, async execute(args, exec) {
|
|
59
|
+
const prepared = registration.pending.get(exec.token);
|
|
60
|
+
if (!prepared) {
|
|
61
|
+
const controller = scope.get("dsmmTemporaryFilePermissions");
|
|
62
|
+
if (controller && !controller.aborted && !registration.bypass.delete(exec.token))
|
|
63
|
+
throw new Error("Controlled filesystem preparation did not complete.");
|
|
64
|
+
return body(args, exec);
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
await prepared.checkTarget(prepared.target);
|
|
68
|
+
prepared.check();
|
|
69
|
+
prepared.lease?.consume();
|
|
70
|
+
return await running.run({ registration, prepared }, () => body(args, exec));
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
prepared.lease?.finish();
|
|
74
|
+
registration.pending.delete(exec.token);
|
|
75
|
+
}
|
|
76
|
+
} };
|
|
77
|
+
const registration = { scope, kind: kind, definition, fs: local, subprocess,
|
|
78
|
+
lifetime: new AbortController(), pending: new Map(), bypass: new Set() };
|
|
79
|
+
registrations.set(definition, registration);
|
|
80
|
+
const unregister = tools.register(definition);
|
|
81
|
+
return scope.effect(() => () => {
|
|
82
|
+
registration.lifetime.abort();
|
|
83
|
+
registrations.delete(definition);
|
|
84
|
+
for (const prepared of registration.pending.values())
|
|
85
|
+
prepared.lease?.finish();
|
|
86
|
+
registration.pending.clear();
|
|
87
|
+
unregister();
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
} });
|
|
91
|
+
const overrides = { fs: facade, tools: toolFacade, ...processFacade ? { subprocess: processFacade } : {} };
|
|
92
|
+
return scope.extend({ ...overrides, get: ((...args) => Object.hasOwn(overrides, args[0]) ? Reflect.get(overrides, args[0]) : Reflect.apply(scope.get, scope, args)) });
|
|
93
|
+
}
|
|
94
|
+
function inputPath(kind, args) {
|
|
95
|
+
const value = kind === "glob" || kind === "grep" ? args.path ?? "." : args.file_path;
|
|
96
|
+
if (typeof value !== "string" || !value.length || value.includes("\0"))
|
|
97
|
+
throw new TypeError("A concrete native filesystem target is required.");
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function searchArgv(kind, args, executable) {
|
|
101
|
+
if (typeof args.pattern !== "string" || !args.pattern.length)
|
|
102
|
+
throw new TypeError("Invalid search pattern.");
|
|
103
|
+
const parts = kind === "glob" ? ["--files", `--glob=${args.pattern}`, "--sort=modified", "--no-ignore", "--hidden",
|
|
104
|
+
...[".git", ".svn", ".hg", ".bzr", ".jj", ".sl"].flatMap(name => [`--glob=!**/${name}`, `--glob=!**/${name}/**`])]
|
|
105
|
+
: ["--json", `--regexp=${args.pattern}`, ...args.include === undefined ? [] : [`--glob=${args.include}`]];
|
|
106
|
+
return [executable, "--no-config", ...parts, ...args.path === undefined ? [] : ["--", String(args.path)]];
|
|
107
|
+
}
|
|
108
|
+
/** Native asks are settled once by the existing ApprovalService; providers remain the original ones. */
|
|
109
|
+
export function installTemporaryFilePermissions(ctx, options) {
|
|
110
|
+
const lifetime = new AbortController(), active = new Set();
|
|
111
|
+
ctx.provide("dsmmTemporaryFilePermissions", lifetime.signal);
|
|
112
|
+
const pre = ctx.on("tools/pre-execute", async (exec, next) => {
|
|
113
|
+
const definition = ctx.tools.get(exec.name, exec.agent), registration = definition && registrations.get(definition);
|
|
114
|
+
if (!registration || !exec.agent)
|
|
115
|
+
return next();
|
|
116
|
+
const decision = await next();
|
|
117
|
+
if (decision.kind === "deny" || decision.kind === "cancel")
|
|
118
|
+
return decision;
|
|
119
|
+
const { fs, kind, scope } = registration;
|
|
120
|
+
active.add(registration);
|
|
121
|
+
const args = exec.arguments;
|
|
122
|
+
// Native escalation keeps its original once-only request and sandbox controller.
|
|
123
|
+
if (args.sandbox_permissions !== undefined) {
|
|
124
|
+
registration.bypass.add(exec.token);
|
|
125
|
+
return decision;
|
|
126
|
+
}
|
|
127
|
+
const search = kind === "glob" || kind === "grep", mutation = kind === "write" || kind === "edit";
|
|
128
|
+
const subprocess = registration.subprocess, originalFs = permissionOriginal(fs), originalProcess = subprocess && permissionOriginal(subprocess);
|
|
129
|
+
if (search && (!originalProcess || Object.getPrototypeOf(originalProcess) !== LocalSubprocessRuntime.prototype
|
|
130
|
+
|| Reflect.get(originalProcess, "spawn") !== LocalSubprocessRuntime.prototype.spawn
|
|
131
|
+
|| "pkg" in process || process.versions.electron !== undefined)) {
|
|
132
|
+
registration.bypass.add(exec.token);
|
|
133
|
+
return decision;
|
|
134
|
+
}
|
|
135
|
+
await options.refresh?.();
|
|
136
|
+
const authority = options.capture(exec), policyService = scope.get("sandboxPolicy");
|
|
137
|
+
if (!policyService) {
|
|
138
|
+
registration.bypass.add(exec.token);
|
|
139
|
+
return decision;
|
|
140
|
+
}
|
|
141
|
+
const capturedPolicy = policyService.resolve({ session: exec.agent.session }), policy = JSON.stringify(capturedPolicy);
|
|
142
|
+
const policyOwner = permissionOriginal(policyService), policyMethod = Reflect.get(policyOwner, "resolve"), sessionCwd = exec.agent.session.header.cwd;
|
|
143
|
+
const input = inputPath(kind, args), argumentsJson = JSON.stringify(args), body = definition.execute;
|
|
144
|
+
const methods = new Map([...operations, "resolve", "contains", "processPath"].map(key => [key, Reflect.get(originalFs, key)]));
|
|
145
|
+
const spawn = originalProcess && Reflect.get(originalProcess, "spawn"), environment = search ? effectiveArgvEnvironment({}) : "";
|
|
146
|
+
const signal = AbortSignal.any([exec.signal, authority.sessionSignal, registration.lifetime.signal, lifetime.signal]);
|
|
147
|
+
const workingDirectory = scope.get("workingDirectory");
|
|
148
|
+
if (!workingDirectory)
|
|
149
|
+
throw new Error("Native working-directory service unavailable.");
|
|
150
|
+
const cwd = await workingDirectory.ensure(exec.agent, signal);
|
|
151
|
+
if (!isAbsolute(cwd) || !isAbsolute(capturedPolicy.workspaceRoot))
|
|
152
|
+
throw new Error("Absolute native filesystem coordinates required.");
|
|
153
|
+
const root = await fs.resolve(capturedPolicy.workspaceRoot, { signal });
|
|
154
|
+
const directory = await fs.resolve(cwd, { signal });
|
|
155
|
+
const target = await fs.resolve(input, { cwd, signal }), info = await fs.stat(target, signal);
|
|
156
|
+
const type = info?.type ?? "missing", path = fs.processPath(target);
|
|
157
|
+
const parent = await fs.resolve(dirname(path), { signal });
|
|
158
|
+
const executable = search ? requireSearch("@vscode/ripgrep").rgPath : "";
|
|
159
|
+
const expectedArgv = search ? searchArgv(kind, args, executable) : [];
|
|
160
|
+
const check = () => {
|
|
161
|
+
signal.throwIfAborted();
|
|
162
|
+
authority.assertIntegrity();
|
|
163
|
+
const liveFs = scope.get("fs"), livePolicy = scope.get("sandboxPolicy");
|
|
164
|
+
if (ctx.tools.get(exec.name, exec.agent) !== definition || definition.execute !== body || JSON.stringify(exec.arguments) !== argumentsJson
|
|
165
|
+
|| !liveFs || permissionOriginal(liveFs) !== originalFs || [...methods].some(([key, value]) => Reflect.get(originalFs, key) !== value)
|
|
166
|
+
|| !livePolicy || permissionOriginal(livePolicy) !== policyOwner || Reflect.get(policyOwner, "resolve") !== policyMethod
|
|
167
|
+
|| exec.agent.session.header.cwd !== sessionCwd
|
|
168
|
+
|| JSON.stringify(policyService.resolve({ session: exec.agent.session })) !== policy
|
|
169
|
+
|| search && (permissionOriginal(scope.subprocess) !== originalProcess || Reflect.get(originalProcess, "spawn") !== spawn
|
|
170
|
+
|| effectiveArgvEnvironment({}) !== environment))
|
|
171
|
+
throw new Error("Native filesystem execution changed.");
|
|
172
|
+
if (mutation && (capturedPolicy.mode === "read-only" || capturedPolicy.mode === "workspace-write" && !fs.contains(root, target)))
|
|
173
|
+
throw new Error("The standing filesystem policy does not permit this mutation.");
|
|
174
|
+
if (!["read-only", "workspace-write", "danger-full-access"].includes(capturedPolicy.mode))
|
|
175
|
+
throw new Error("Unsupported filesystem policy.");
|
|
176
|
+
};
|
|
177
|
+
check();
|
|
178
|
+
authority.assertProgramAllowed();
|
|
179
|
+
const resource = Object.freeze({ target, type, policy, environment, subprocess: originalProcess });
|
|
180
|
+
resources.set(resource, resource);
|
|
181
|
+
const execution = { token: exec.token, agent: exec.agent, owner: authority.owner, generation: authority.generation,
|
|
182
|
+
registration: definition, provider: originalFs, sessionId: exec.agent.id, tool: kind, project: capturedPolicy.workspaceRoot,
|
|
183
|
+
target: JSON.stringify({ path, type, policy, environment }), resource,
|
|
184
|
+
summary: `${kind}: ${path} (${search && type === "directory" ? "read tree" : mutation ? "write file" : "read file"}); native tool boundary only.`,
|
|
185
|
+
reusable: true, signal, sessionSignal: authority.sessionSignal,
|
|
186
|
+
scopes: [{ id: "tree", summary: `${kind}: ${mutation ? "write" : "read"} tree ${search && type === "directory" ? path : parent.displayPath}; native tool boundary only.`,
|
|
187
|
+
allows(candidate) {
|
|
188
|
+
const other = candidate.resource && resources.get(candidate.resource);
|
|
189
|
+
return !!other && other.policy === policy && other.environment === environment && other.subprocess === originalProcess
|
|
190
|
+
&& fs.contains(search && type === "directory" ? target : parent, other.target);
|
|
191
|
+
} }],
|
|
192
|
+
assertIntegrity: check, assertReusable() {
|
|
193
|
+
check();
|
|
194
|
+
authority.assertProgramAllowed();
|
|
195
|
+
authority.assertRetentionAllowed?.();
|
|
196
|
+
const approval = scope.get("approval");
|
|
197
|
+
if (!approval || (approval.overrideOf(exec.agent.session) ?? approval.config.policy ?? "ask") !== "ask")
|
|
198
|
+
throw new Error("Native approval policy no longer permits reuse.");
|
|
199
|
+
} };
|
|
200
|
+
const lease = decision.kind === "ask" ? await options.grants.approve({ agent: exec.agent, callId: exec.callId, toolName: exec.name, signal,
|
|
201
|
+
reason: `${decision.reason}\n${execution.summary}` }, execution) : undefined;
|
|
202
|
+
const prepared = { execution, target, lease, check() { check(); lease?.check(); },
|
|
203
|
+
async checkTarget(actual, metadata = false) {
|
|
204
|
+
if (metadata && actual.targetKey === directory.targetKey) {
|
|
205
|
+
const fresh = await fs.resolve(cwd, { signal });
|
|
206
|
+
prepared.check();
|
|
207
|
+
if (fresh.targetKey !== directory.targetKey)
|
|
208
|
+
throw new Error("Native working directory changed.");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const fresh = await fs.resolve(input, { cwd, signal }), currentInfo = await fs.stat(fresh, signal);
|
|
212
|
+
prepared.check();
|
|
213
|
+
if (actual.targetKey !== target.targetKey || fresh.targetKey !== target.targetKey || (currentInfo?.type ?? "missing") !== type) {
|
|
214
|
+
throw new Error("Filesystem target changed before native handoff.");
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
spawn(spec) {
|
|
218
|
+
if (!search || JSON.stringify(spec.argv) !== JSON.stringify(expectedArgv) || spec.cwd !== cwd || spec.env !== undefined)
|
|
219
|
+
throw new Error("Native search subprocess does not match the controlled template.");
|
|
220
|
+
// Native rg awaits its helper and working-directory preparation before this synchronous handoff.
|
|
221
|
+
const actual = realpathSync(resolve(spec.cwd, input)), actualType = statSync(actual).isDirectory() ? "directory" : "file";
|
|
222
|
+
if (actual !== path || actualType !== type)
|
|
223
|
+
throw new Error("Search and filesystem targets no longer share the execution world.");
|
|
224
|
+
prepared.check();
|
|
225
|
+
} };
|
|
226
|
+
registration.pending.set(exec.token, prepared);
|
|
227
|
+
return { kind: "allow" };
|
|
228
|
+
}, { prepend: true, global: true });
|
|
229
|
+
const result = ctx.on("tools/result", exec => {
|
|
230
|
+
for (const registration of active) {
|
|
231
|
+
registration.pending.get(exec.token)?.lease?.finish();
|
|
232
|
+
registration.pending.delete(exec.token);
|
|
233
|
+
registration.bypass.delete(exec.token);
|
|
234
|
+
}
|
|
235
|
+
}, { global: true });
|
|
236
|
+
return ctx.effect(() => () => {
|
|
237
|
+
lifetime.abort();
|
|
238
|
+
pre();
|
|
239
|
+
result();
|
|
240
|
+
for (const registration of active) {
|
|
241
|
+
for (const prepared of registration.pending.values())
|
|
242
|
+
prepared.lease?.finish();
|
|
243
|
+
registration.pending.clear();
|
|
244
|
+
}
|
|
245
|
+
active.clear();
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=permission-temporary-files.js.map
|