@dsmm/dsmm 0.3.2 → 0.3.3
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/README.md +2 -2
- package/cordis.patch.yml +0 -9
- package/docs/agent-presets.md +5 -5
- package/docs/compatibility.md +2 -6
- package/docs/migration-from-ocmm.md +1 -1
- package/docs/roadmap.md +5 -12
- package/docs/settings-status.md +1 -1
- package/lib/client/ChildrenPanel.d.ts +1 -4
- package/lib/client/ChildrenPanel.js +3 -3
- package/lib/client/DeploymentPage.d.ts +1 -3
- package/lib/client/DeploymentPage.js +2 -2
- package/lib/client/PermissionsPanel.d.ts +1 -3
- package/lib/client/PermissionsPanel.js +2 -3
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.js +4 -1
- package/lib/client/deployment-locales.js +0 -1
- package/lib/client/deployment-modules.js +1 -1
- package/lib/client/index.js +2 -7
- package/lib/client/locales.js +131 -119
- package/lib/client/permission-locales.d.ts +0 -26
- package/lib/client/permission-locales.js +0 -20
- package/lib/client.js +1837 -3634
- package/lib/index.d.ts +0 -2
- package/lib/index.js +9 -22
- package/lib/native-admission.d.ts +0 -3
- package/lib/native-admission.js +12 -45
- package/lib/permission-fs-search.js +1 -2
- package/lib/permission-fs.js +1 -2
- package/lib/permission-web.js +1 -2
- package/lib/preset-materializer.js +3 -3
- package/lib/preset-registry.d.ts +20 -2
- package/lib/preset-registry.js +46 -17
- package/lib/profile-diagnostics.js +1 -1
- package/lib/profile-remote.js +1 -3
- package/lib/role-policy.js +2 -2
- package/lib/role-subagents.js +2 -1
- package/lib/roles.d.ts +2 -0
- package/lib/roles.js +2 -0
- package/lib/settings.d.ts +1 -3
- package/lib/settings.js +4 -9
- package/package.json +1 -5
- package/lib/client/ChildPermissions.d.ts +0 -43
- package/lib/client/ChildPermissions.js +0 -100
- package/lib/client/HistoryContinuation.d.ts +0 -7
- package/lib/client/HistoryContinuation.js +0 -22
- package/lib/client/PermissionPanelEntry.d.ts +0 -8
- package/lib/client/PermissionPanelEntry.js +0 -11
- package/lib/client/TemporaryPermissions.d.ts +0 -21
- package/lib/client/TemporaryPermissions.js +0 -94
- package/lib/client/history-controller.d.ts +0 -29
- package/lib/client/history-controller.js +0 -111
- package/lib/client/history-entry.d.ts +0 -11
- package/lib/client/history-entry.js +0 -106
- package/lib/client/history-locales.d.ts +0 -95
- package/lib/client/history-locales.js +0 -41
- package/lib/client/temporary-permission-client.d.ts +0 -20
- package/lib/client/temporary-permission-client.js +0 -52
- package/lib/client/temporary-permission-entry.d.ts +0 -6
- package/lib/client/temporary-permission-entry.js +0 -56
- package/lib/history-candidates.d.ts +0 -30
- package/lib/history-candidates.js +0 -176
- package/lib/history-codec.d.ts +0 -11
- package/lib/history-codec.js +0 -102
- package/lib/history-contract.d.ts +0 -44
- package/lib/history-contract.js +0 -2
- package/lib/history-controller.d.ts +0 -42
- package/lib/history-controller.js +0 -329
- package/lib/history-policy.d.ts +0 -4
- package/lib/history-policy.js +0 -8
- package/lib/history-remote.d.ts +0 -28
- package/lib/history-remote.js +0 -17
- package/lib/history-rpc.d.ts +0 -24
- package/lib/history-rpc.js +0 -136
- package/lib/history-support.d.ts +0 -15
- package/lib/history-support.js +0 -21
- package/lib/history-types.d.ts +0 -67
- package/lib/history-types.js +0 -2
- package/lib/permission-child-control.d.ts +0 -36
- package/lib/permission-child-control.js +0 -164
- package/lib/permission-exec-argv.d.ts +0 -32
- package/lib/permission-exec-argv.js +0 -171
- package/lib/permission-temporary-files.d.ts +0 -19
- package/lib/permission-temporary-files.js +0 -248
- package/lib/permission-temporary-grants.d.ts +0 -106
- package/lib/permission-temporary-grants.js +0 -198
- package/lib/permission-temporary-install.d.ts +0 -25
- package/lib/permission-temporary-install.js +0 -86
- package/lib/permission-temporary-remote.d.ts +0 -19
- package/lib/permission-temporary-remote.js +0 -75
- package/lib/permission-temporary-rpc.d.ts +0 -37
- package/lib/permission-temporary-rpc.js +0 -154
- package/lib/permission-temporary-types.d.ts +0 -47
- package/lib/permission-temporary-types.js +0 -2
- package/lib/permission-temporary-web.d.ts +0 -11
- package/lib/permission-temporary-web.js +0 -154
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +0 -13291
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +0 -9133
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +0 -156
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +0 -3546
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +0 -431
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +0 -119
- package/patches/dsh-approval-settlement/README.md +0 -41
- package/patches/dsh-approval-settlement/metadata.json +0 -10
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +0 -383
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +0 -55
- package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +0 -16673
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +0 -29
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +0 -196
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +0 -35
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +0 -40
|
@@ -1,248 +0,0 @@
|
|
|
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
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { TemporaryPermissionDuration, TemporaryPermissionGrantView } from "./permission-temporary-types.js";
|
|
2
|
-
export interface TemporaryApprovalWinner {
|
|
3
|
-
readonly requestId: string;
|
|
4
|
-
readonly deliveryId?: string;
|
|
5
|
-
readonly answerId?: string;
|
|
6
|
-
readonly candidate: string;
|
|
7
|
-
readonly source: "operator" | "temporary" | "unknown";
|
|
8
|
-
readonly automatic: boolean;
|
|
9
|
-
readonly permit?: string;
|
|
10
|
-
readonly retention?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface TemporaryApprovalReceipt {
|
|
13
|
-
readonly requestId: string;
|
|
14
|
-
readonly generation: string;
|
|
15
|
-
readonly outcome: string;
|
|
16
|
-
readonly auditSeq: number;
|
|
17
|
-
readonly source: TemporaryApprovalWinner["source"];
|
|
18
|
-
readonly winner?: TemporaryApprovalWinner;
|
|
19
|
-
}
|
|
20
|
-
export interface TemporaryApprovalDelivery {
|
|
21
|
-
readonly requestId: string;
|
|
22
|
-
readonly deliveryId: string;
|
|
23
|
-
readonly peer: object;
|
|
24
|
-
readonly request: object;
|
|
25
|
-
readonly signal: AbortSignal;
|
|
26
|
-
}
|
|
27
|
-
export interface TemporaryApprovalRuntime {
|
|
28
|
-
request(request: object, options: {
|
|
29
|
-
opened(id: string): void;
|
|
30
|
-
}): Promise<string>;
|
|
31
|
-
settlement(id: string): TemporaryApprovalReceipt | undefined;
|
|
32
|
-
forgetSettlement(id: string): void;
|
|
33
|
-
}
|
|
34
|
-
export interface TemporaryApprovalGateway {
|
|
35
|
-
approvalDelivery(peer: object, requestId: string, deliveryId: string): TemporaryApprovalDelivery | undefined;
|
|
36
|
-
registerApprovalPermits(verify: (delivery: TemporaryApprovalDelivery, permit: string) => boolean): () => void;
|
|
37
|
-
}
|
|
38
|
-
/** Captured by the actual execution adapter. All object identities are Host-only. */
|
|
39
|
-
export interface TemporaryPermissionExecution {
|
|
40
|
-
readonly token: unknown;
|
|
41
|
-
readonly agent: object;
|
|
42
|
-
readonly owner: object;
|
|
43
|
-
readonly generation: string | number;
|
|
44
|
-
readonly registration: object;
|
|
45
|
-
readonly provider: object;
|
|
46
|
-
readonly sessionId: string;
|
|
47
|
-
readonly tool: string;
|
|
48
|
-
readonly project: string;
|
|
49
|
-
readonly target: string;
|
|
50
|
-
readonly summary: string;
|
|
51
|
-
readonly reusable: boolean;
|
|
52
|
-
readonly signal: AbortSignal;
|
|
53
|
-
readonly sessionSignal: AbortSignal;
|
|
54
|
-
/** Host-owned resolved resource and explicit additional scopes; never accepted from RPC. */
|
|
55
|
-
readonly resource?: object;
|
|
56
|
-
readonly scopes?: readonly TemporaryPermissionScope[];
|
|
57
|
-
/** Integrity must not invalidate a manual same-call approval merely for a config revision. */
|
|
58
|
-
assertIntegrity(): void;
|
|
59
|
-
/** Rechecks deny, policy, provider, effective env and owner for automatic use. */
|
|
60
|
-
assertReusable(): void;
|
|
61
|
-
}
|
|
62
|
-
export interface TemporaryPermissionScope {
|
|
63
|
-
readonly id: string;
|
|
64
|
-
readonly summary: string;
|
|
65
|
-
allows(execution: TemporaryPermissionExecution): boolean;
|
|
66
|
-
}
|
|
67
|
-
/** One Host store; it holds grant authority, never pending UI questions or retry work. */
|
|
68
|
-
export declare class TemporaryPermissionGrants {
|
|
69
|
-
private readonly approval;
|
|
70
|
-
private readonly gateway;
|
|
71
|
-
private readonly now;
|
|
72
|
-
private readonly grants;
|
|
73
|
-
private readonly pending;
|
|
74
|
-
private readonly permits;
|
|
75
|
-
private readonly unregister;
|
|
76
|
-
private retired;
|
|
77
|
-
constructor(approval: TemporaryApprovalRuntime, gateway: TemporaryApprovalGateway, now?: () => number);
|
|
78
|
-
private integrity;
|
|
79
|
-
private active;
|
|
80
|
-
private delivery;
|
|
81
|
-
request(peer: object, requestId: string, deliveryId: string): Readonly<{
|
|
82
|
-
scopes?: {
|
|
83
|
-
id: string;
|
|
84
|
-
summary: string;
|
|
85
|
-
}[] | undefined;
|
|
86
|
-
requestId: string;
|
|
87
|
-
deliveryId: string;
|
|
88
|
-
sessionId: string;
|
|
89
|
-
tool: string;
|
|
90
|
-
summary: string;
|
|
91
|
-
reusable: boolean;
|
|
92
|
-
}>;
|
|
93
|
-
retain(peer: object, requestId: string, deliveryId: string, duration: TemporaryPermissionDuration, scopeId?: string): string;
|
|
94
|
-
permit(peer: object, requestId: string, deliveryId: string): string | null;
|
|
95
|
-
private validatePermit;
|
|
96
|
-
approve(request: object, execution: TemporaryPermissionExecution): Promise<{
|
|
97
|
-
check(): void;
|
|
98
|
-
consume(): void;
|
|
99
|
-
finish(): void;
|
|
100
|
-
}>;
|
|
101
|
-
list(agent: object): readonly TemporaryPermissionGrantView[];
|
|
102
|
-
revoke(agent: object, id: string): readonly TemporaryPermissionGrantView[];
|
|
103
|
-
revokeAgent(agent: object): void;
|
|
104
|
-
dispose(): void;
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=permission-temporary-grants.d.ts.map
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
const durations = new Set(["once", "session", "15min", "1h"]);
|
|
3
|
-
/** One Host store; it holds grant authority, never pending UI questions or retry work. */
|
|
4
|
-
export class TemporaryPermissionGrants {
|
|
5
|
-
approval;
|
|
6
|
-
gateway;
|
|
7
|
-
now;
|
|
8
|
-
grants = new Map();
|
|
9
|
-
pending = new Map();
|
|
10
|
-
permits = new Map();
|
|
11
|
-
unregister;
|
|
12
|
-
retired = false;
|
|
13
|
-
constructor(approval, gateway, now = () => performance.now()) {
|
|
14
|
-
this.approval = approval;
|
|
15
|
-
this.gateway = gateway;
|
|
16
|
-
this.now = now;
|
|
17
|
-
this.unregister = gateway.registerApprovalPermits((delivery, permit) => this.validatePermit(delivery, permit));
|
|
18
|
-
}
|
|
19
|
-
integrity(execution) {
|
|
20
|
-
if (this.retired || execution.signal.aborted)
|
|
21
|
-
throw new Error("Temporary permission execution ended.");
|
|
22
|
-
execution.assertIntegrity();
|
|
23
|
-
}
|
|
24
|
-
active(grant, execution) {
|
|
25
|
-
if (!grant.active || grant.deadline <= this.now() || grant.execution.sessionSignal.aborted)
|
|
26
|
-
return false;
|
|
27
|
-
const previous = grant.execution;
|
|
28
|
-
return previous.agent === execution.agent && previous.owner === execution.owner && previous.generation === execution.generation
|
|
29
|
-
&& previous.registration === execution.registration && previous.provider === execution.provider
|
|
30
|
-
&& previous.sessionId === execution.sessionId && previous.tool === execution.tool && previous.project === execution.project
|
|
31
|
-
&& (grant.scope ? grant.scope.allows(execution) : previous.target === execution.target);
|
|
32
|
-
}
|
|
33
|
-
delivery(peer, requestId, deliveryId) {
|
|
34
|
-
const binding = this.pending.get(requestId), delivery = this.gateway.approvalDelivery(peer, requestId, deliveryId);
|
|
35
|
-
if (!binding || binding.closed || binding.receipt !== undefined || !delivery || delivery.request !== binding.request || delivery.signal.aborted)
|
|
36
|
-
throw new Error("Approval delivery is not current.");
|
|
37
|
-
this.integrity(binding.execution);
|
|
38
|
-
return { binding, delivery };
|
|
39
|
-
}
|
|
40
|
-
request(peer, requestId, deliveryId) {
|
|
41
|
-
const { binding } = this.delivery(peer, requestId, deliveryId), exec = binding.execution;
|
|
42
|
-
return Object.freeze({ requestId, deliveryId, sessionId: exec.sessionId, tool: exec.tool, summary: exec.summary, reusable: exec.reusable,
|
|
43
|
-
...(exec.scopes?.length ? { scopes: exec.scopes.map(({ id, summary }) => ({ id, summary })) } : {}) });
|
|
44
|
-
}
|
|
45
|
-
retain(peer, requestId, deliveryId, duration, scopeId = "exact") {
|
|
46
|
-
if (!durations.has(duration))
|
|
47
|
-
throw new TypeError("Invalid permission duration.");
|
|
48
|
-
const { binding, delivery } = this.delivery(peer, requestId, deliveryId);
|
|
49
|
-
const scope = scopeId === "exact" ? undefined : binding.execution.scopes?.find(scope => scope.id === scopeId);
|
|
50
|
-
if (scopeId !== "exact" && !scope)
|
|
51
|
-
throw new Error("Unsupported permission scope.");
|
|
52
|
-
if (duration !== "once" && !binding.execution.reusable)
|
|
53
|
-
throw new Error("This execution supports approval once only.");
|
|
54
|
-
this.list(binding.execution.agent);
|
|
55
|
-
if (duration !== "once" && this.grants.size >= 1024)
|
|
56
|
-
throw new Error("Revoke an existing temporary approval before retaining another.");
|
|
57
|
-
if (binding.intents.size >= 128)
|
|
58
|
-
throw new Error("Too many approval intents for this pending request.");
|
|
59
|
-
const retention = randomUUID();
|
|
60
|
-
binding.intents.set(retention, { delivery, duration, scope });
|
|
61
|
-
return retention;
|
|
62
|
-
}
|
|
63
|
-
permit(peer, requestId, deliveryId) {
|
|
64
|
-
const { binding, delivery } = this.delivery(peer, requestId, deliveryId), execution = binding.execution;
|
|
65
|
-
if (!execution.reusable)
|
|
66
|
-
return null;
|
|
67
|
-
execution.assertReusable();
|
|
68
|
-
for (const grant of this.grants.values()) {
|
|
69
|
-
if (!this.active(grant, execution))
|
|
70
|
-
continue;
|
|
71
|
-
for (const key of binding.permits)
|
|
72
|
-
if (this.permits.get(key)?.delivery === delivery)
|
|
73
|
-
return key;
|
|
74
|
-
const permit = randomUUID();
|
|
75
|
-
this.permits.set(permit, { binding, delivery, grant });
|
|
76
|
-
binding.permits.add(permit);
|
|
77
|
-
return permit;
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
validatePermit(delivery, key) {
|
|
82
|
-
const permit = this.permits.get(key);
|
|
83
|
-
if (!permit || permit.delivery !== delivery || permit.binding.closed || permit.binding.receipt !== undefined || permit.binding.request !== delivery.request)
|
|
84
|
-
return false;
|
|
85
|
-
try {
|
|
86
|
-
this.integrity(permit.binding.execution);
|
|
87
|
-
permit.binding.execution.assertReusable();
|
|
88
|
-
return !delivery.signal.aborted && this.active(permit.grant, permit.binding.execution);
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async approve(request, execution) {
|
|
95
|
-
this.integrity(execution);
|
|
96
|
-
let binding;
|
|
97
|
-
const finish = () => {
|
|
98
|
-
if (!binding || binding.closed)
|
|
99
|
-
return;
|
|
100
|
-
binding.closed = true;
|
|
101
|
-
for (const permit of binding.permits)
|
|
102
|
-
this.permits.delete(permit);
|
|
103
|
-
this.pending.delete(binding.id);
|
|
104
|
-
this.approval.forgetSettlement(binding.id);
|
|
105
|
-
};
|
|
106
|
-
try {
|
|
107
|
-
const outcome = await this.approval.request(request, { opened: id => {
|
|
108
|
-
binding = { id, request, execution, intents: new Map(), permits: new Set(), consumed: false, closed: false };
|
|
109
|
-
this.pending.set(id, binding);
|
|
110
|
-
} });
|
|
111
|
-
if (!binding)
|
|
112
|
-
throw new Error("Compatible approval settlement runtime required.");
|
|
113
|
-
this.integrity(execution);
|
|
114
|
-
const receipt = this.approval.settlement(binding.id);
|
|
115
|
-
binding.receipt = receipt;
|
|
116
|
-
if (outcome !== "allowed-once")
|
|
117
|
-
throw new Error("Native approval did not allow this execution.");
|
|
118
|
-
if (!receipt)
|
|
119
|
-
throw new Error("Native approval audit receipt unavailable.");
|
|
120
|
-
const winner = receipt.winner;
|
|
121
|
-
if (receipt.outcome !== outcome || receipt.requestId !== binding.id)
|
|
122
|
-
throw new Error("Native approval receipt mismatch.");
|
|
123
|
-
if (winner?.automatic) {
|
|
124
|
-
if (receipt.source !== "temporary" || winner.source !== "temporary" || !winner.permit
|
|
125
|
-
|| !this.permits.has(winner.permit))
|
|
126
|
-
throw new Error("Automatic approval source is not continuous.");
|
|
127
|
-
}
|
|
128
|
-
else if (receipt.source === "operator" && winner?.source === "operator" && winner.deliveryId && winner.retention) {
|
|
129
|
-
const intent = binding.intents.get(winner.retention);
|
|
130
|
-
if (intent && intent.delivery.deliveryId === winner.deliveryId && intent.duration !== "once" && execution.reusable && !intent.delivery.signal.aborted) {
|
|
131
|
-
try {
|
|
132
|
-
execution.assertReusable();
|
|
133
|
-
const id = randomUUID();
|
|
134
|
-
this.grants.set(id, { id, execution, duration: intent.duration, scope: intent.scope, active: true,
|
|
135
|
-
deadline: intent.duration === "session" ? Infinity : this.now() + (intent.duration === "15min" ? 900_000 : 3_600_000) });
|
|
136
|
-
}
|
|
137
|
-
catch { /* A failed retention check does not revoke a native manual same-call decision. */ }
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const checked = binding;
|
|
141
|
-
const check = () => {
|
|
142
|
-
this.integrity(execution);
|
|
143
|
-
if (checked.closed)
|
|
144
|
-
throw new Error("Approval execution ended.");
|
|
145
|
-
if (!winner?.automatic)
|
|
146
|
-
return;
|
|
147
|
-
const permit = winner.permit && this.permits.get(winner.permit);
|
|
148
|
-
if (!permit || permit.binding !== checked || permit.delivery.deliveryId !== winner.deliveryId
|
|
149
|
-
|| permit.delivery.signal.aborted || !this.active(permit.grant, execution))
|
|
150
|
-
throw new Error("Temporary permission expired or was revoked.");
|
|
151
|
-
execution.assertReusable();
|
|
152
|
-
if (checked.closed || this.retired || !this.active(permit.grant, execution))
|
|
153
|
-
throw new Error("Temporary permission expired or was revoked.");
|
|
154
|
-
};
|
|
155
|
-
check();
|
|
156
|
-
return Object.freeze({ check, consume() { check(); if (checked.consumed)
|
|
157
|
-
throw new Error("Approval execution already consumed."); checked.consumed = true; }, finish });
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
finish();
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
list(agent) {
|
|
165
|
-
const result = [];
|
|
166
|
-
for (const [id, grant] of this.grants) {
|
|
167
|
-
if (!grant.active || grant.deadline <= this.now() || grant.execution.sessionSignal.aborted) {
|
|
168
|
-
this.grants.delete(id);
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (grant.execution.agent !== agent)
|
|
172
|
-
continue;
|
|
173
|
-
result.push(Object.freeze({ id, sessionId: grant.execution.sessionId, tool: grant.execution.tool, summary: grant.scope?.summary ?? grant.execution.summary,
|
|
174
|
-
duration: grant.duration, ...(grant.deadline === Infinity ? {} : { remainingMs: Math.max(0, grant.deadline - this.now()) }) }));
|
|
175
|
-
}
|
|
176
|
-
return Object.freeze(result);
|
|
177
|
-
}
|
|
178
|
-
revoke(agent, id) {
|
|
179
|
-
const grant = this.grants.get(id);
|
|
180
|
-
if (grant && grant.execution.agent !== agent)
|
|
181
|
-
throw new Error("Grant belongs to another live session.");
|
|
182
|
-
if (grant) {
|
|
183
|
-
grant.active = false;
|
|
184
|
-
this.grants.delete(id);
|
|
185
|
-
}
|
|
186
|
-
return this.list(agent);
|
|
187
|
-
}
|
|
188
|
-
revokeAgent(agent) {
|
|
189
|
-
for (const [id, grant] of this.grants)
|
|
190
|
-
if (grant.execution.agent === agent) {
|
|
191
|
-
grant.active = false;
|
|
192
|
-
this.grants.delete(id);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
dispose() { this.retired = true; for (const grant of this.grants.values())
|
|
196
|
-
grant.active = false; this.grants.clear(); this.permits.clear(); this.pending.clear(); this.unregister(); }
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=permission-temporary-grants.js.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
-
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
3
|
-
import type { CorePermissionAuthority } from "./core-permission-authority.js";
|
|
4
|
-
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
5
|
-
import type { PermissionRulesRuntimeSync } from "./permission-rules.js";
|
|
6
|
-
import { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
|
|
7
|
-
import type { ArgvPermissionOptions, ArgvPermissionAuthority } from "./permission-exec-argv.js";
|
|
8
|
-
import { ChildPermissionControl } from "./permission-child-control.js";
|
|
9
|
-
export interface TemporaryPermissionInstallOptions {
|
|
10
|
-
readonly core: CorePermissionAuthority;
|
|
11
|
-
readonly roles: DsmmRolePolicy;
|
|
12
|
-
readonly rules: PermissionRulesRuntimeSync;
|
|
13
|
-
/** Explicit owned argv composition. Omit only when this capability is not installed. */
|
|
14
|
-
readonly argv?: Pick<ArgvPermissionOptions, "programKind" | "environment" | "maxOutputBytes" | "timeoutMs">;
|
|
15
|
-
}
|
|
16
|
-
/** Composition from the real Core/role owners; no boolean ownership or test-provider authority. */
|
|
17
|
-
export declare function temporaryPermissionCapture(options: TemporaryPermissionInstallOptions, exec: Readonly<ToolExecution>): ArgvPermissionAuthority;
|
|
18
|
-
/** Install in the same Host fiber as the Core authority, after the patched Approval/Gateway and rules owners. */
|
|
19
|
-
export declare function installTemporaryPermissions(ctx: Context, options: TemporaryPermissionInstallOptions): {
|
|
20
|
-
grants: TemporaryPermissionGrants;
|
|
21
|
-
rpc: import("./permission-temporary-rpc.js").DsmmTemporaryPermissionsHost;
|
|
22
|
-
children: ChildPermissionControl;
|
|
23
|
-
dispose(): void;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=permission-temporary-install.d.ts.map
|