@dsmm/dsmm 0.3.0 → 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/README.md +26 -40
- package/cordis.patch.yml +9 -13
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +24 -68
- package/docs/deferred-native-approval-risk.md +8 -12
- package/docs/design.md +25 -254
- package/docs/lsp.md +2 -2
- package/docs/migration-from-ocmm.md +38 -51
- package/docs/model-routing.md +21 -21
- package/docs/native-permissions.md +17 -7
- package/docs/profiles.md +13 -9
- package/docs/releasing.md +25 -311
- package/docs/roadmap.md +52 -241
- package/docs/runtime-recovery.md +29 -91
- package/docs/safety-guards.md +19 -16
- package/docs/settings-status.md +23 -11
- package/docs/skill-sync.md +17 -17
- package/docs/web-fetch-fakeip.md +82 -0
- package/lib/child-capture.d.ts +12 -2
- package/lib/child-capture.js +22 -5
- package/lib/client/ChildPermissions.d.ts +43 -0
- package/lib/client/ChildPermissions.js +100 -0
- package/lib/client/ChildrenPanel.d.ts +5 -5
- package/lib/client/ChildrenPanel.js +6 -18
- package/lib/client/DeploymentFields.d.ts +32 -0
- package/lib/client/DeploymentFields.js +70 -0
- package/lib/client/DeploymentPage.d.ts +21 -6
- package/lib/client/DeploymentPage.js +80 -112
- package/lib/client/HistoryContinuation.d.ts +7 -0
- package/lib/client/HistoryContinuation.js +22 -0
- package/lib/client/NativeCommandEntries.d.ts +17 -0
- package/lib/client/NativeCommandEntries.js +68 -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 +10 -9
- package/lib/client/ProfilesSection.js +8 -6
- package/lib/client/RoleAvailability.js +1 -1
- package/lib/client/RoleToolView-data.d.ts +35 -0
- package/lib/client/RoleToolView-data.js +52 -0
- package/lib/client/RoleToolView-locales.d.ts +36 -0
- package/lib/client/RoleToolView-locales.js +20 -0
- package/lib/client/RoleToolView.d.ts +10 -0
- package/lib/client/RoleToolView.js +47 -0
- package/lib/client/SessionProfiles.js +51 -24
- package/lib/client/TemporaryPermissions.d.ts +21 -0
- package/lib/client/TemporaryPermissions.js +94 -0
- package/lib/client/children-controller.d.ts +2 -8
- package/lib/client/children-controller.js +1 -26
- package/lib/client/children-locales.d.ts +27 -52
- package/lib/client/children-locales.js +8 -12
- package/lib/client/configuration-display.d.ts +5 -0
- package/lib/client/configuration-display.js +11 -0
- package/lib/client/controller.d.ts +18 -0
- package/lib/client/controller.js +118 -28
- package/lib/client/deployment-controller.d.ts +13 -1
- package/lib/client/deployment-controller.js +84 -24
- package/lib/client/deployment-data.d.ts +1 -0
- package/lib/client/deployment-data.js +4 -1
- package/lib/client/deployment-locales.d.ts +43 -0
- package/lib/client/deployment-locales.js +45 -19
- package/lib/client/deployment-modules.d.ts +9 -0
- package/lib/client/deployment-modules.js +24 -0
- package/lib/client/deployment-workspace.d.ts +48 -0
- package/lib/client/deployment-workspace.js +123 -0
- 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 +26 -76
- package/lib/client/locales.d.ts +13 -0
- package/lib/client/locales.js +104 -86
- package/lib/client/permission-controller.d.ts +1 -0
- package/lib/client/permission-controller.js +3 -2
- package/lib/client/permission-locales.d.ts +51 -0
- package/lib/client/permission-locales.js +59 -19
- package/lib/client/session-labels.js +4 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +9 -8
- 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 +5691 -3439
- package/lib/commands.js +2 -0
- package/lib/config-file-store.d.ts +3 -0
- package/lib/config-file-store.js +4 -2
- package/lib/config-revision.d.ts +5 -0
- package/lib/config-revision.js +11 -0
- package/lib/core-permission-authority.js +11 -41
- package/lib/deployment-config.d.ts +9 -2
- package/lib/deployment-config.js +35 -8
- package/lib/deployment-permission-rules.js +19 -7
- package/lib/dsh-types.d.ts +1 -1
- 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/host-llm-startup.js +3 -3
- package/lib/host-llm.d.ts +9 -3
- package/lib/host-llm.js +48 -8
- package/lib/index.d.ts +18 -20
- package/lib/index.js +147 -415
- package/lib/lifetime.d.ts +4 -0
- package/lib/lifetime.js +22 -0
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +8 -4
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +28 -41
- package/lib/model-routing.d.ts +2 -8
- package/lib/model-routing.js +59 -175
- package/lib/native-admission.d.ts +77 -0
- package/lib/native-admission.js +503 -0
- package/lib/native-pi-ai-wire.d.ts +3 -1
- package/lib/native-pi-ai-wire.js +47 -13
- package/lib/permission-child-control.d.ts +36 -0
- package/lib/permission-child-control.js +164 -0
- package/lib/permission-control.d.ts +2 -3
- 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-registry.js +3 -2
- package/lib/preset-skills.d.ts +3 -12
- package/lib/preset-skills.js +28 -58
- package/lib/profile-diagnostics.d.ts +1 -1
- package/lib/profile-diagnostics.js +2 -2
- package/lib/profile-remote.js +61 -22
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +35 -37
- package/lib/profile-runtime.d.ts +42 -74
- package/lib/profile-runtime.js +314 -617
- package/lib/profile-store.d.ts +20 -8
- package/lib/profile-store.js +112 -63
- package/lib/profile-types.d.ts +19 -4
- package/lib/profiles.d.ts +3 -1
- package/lib/profiles.js +9 -7
- package/lib/prompt-content.d.ts +1 -0
- package/lib/prompt-content.js +4 -1
- package/lib/prompts.d.ts +2 -12
- package/lib/prompts.js +11 -66
- package/lib/role-control-remote.d.ts +1 -4
- package/lib/role-control-remote.js +8 -36
- package/lib/role-control-rpc.d.ts +10 -36
- package/lib/role-control-rpc.js +112 -269
- package/lib/role-control-types.d.ts +3 -26
- package/lib/role-control-types.js +3 -4
- package/lib/role-identity.d.ts +5 -0
- package/lib/role-identity.js +10 -0
- package/lib/role-invocation.d.ts +3 -3
- package/lib/role-invocation.js +2 -2
- package/lib/role-llm-runtime.js +5 -11
- package/lib/role-policy.d.ts +19 -50
- package/lib/role-policy.js +136 -508
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -86
- package/lib/role-routing.d.ts +1 -3
- package/lib/role-routing.js +24 -34
- package/lib/role-subagents.d.ts +5 -14
- package/lib/role-subagents.js +163 -108
- package/lib/runtime-integration.d.ts +5 -78
- package/lib/runtime-integration.js +11 -697
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +2 -1
- package/lib/settings.d.ts +5 -18
- package/lib/settings.js +19 -43
- package/lib/skills.d.ts +1 -0
- package/lib/skills.js +5 -1
- package/lib/state.d.ts +3 -2
- package/lib/state.js +26 -10
- package/lib/status.d.ts +1 -9
- package/lib/status.js +3 -55
- package/lib/web-fetch-address-policy.d.ts +24 -0
- package/lib/web-fetch-address-policy.js +189 -0
- package/lib/web-fetch-fakeip.d.ts +25 -0
- package/lib/web-fetch-fakeip.js +107 -0
- package/package.json +124 -106
- 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
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/agent-registry.d.ts +0 -36
- package/lib/agent-registry.js +0 -75
- package/lib/child-admission.d.ts +0 -40
- package/lib/child-admission.js +0 -151
- package/lib/delivery-authority.d.ts +0 -83
- package/lib/delivery-authority.js +0 -397
- package/lib/native-child-evidence.d.ts +0 -40
- package/lib/native-child-evidence.js +0 -104
- package/lib/role-runs.d.ts +0 -138
- package/lib/role-runs.js +0 -335
- package/lib/session-persistence.d.ts +0 -36
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -57
- package/lib/subagent-runtime.js +0 -257
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
package/lib/native-pi-ai-wire.js
CHANGED
|
@@ -3,14 +3,16 @@ import { brandString } from "@deepseek-ai/dsh-brand";
|
|
|
3
3
|
import { PiAiAdapter, Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
4
|
import { createModels, createProvider, envApiKeyAuth, hasApi } from "@earendil-works/pi-ai";
|
|
5
5
|
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
6
|
+
import { getBuiltinModels, getBuiltinProviders } from "@earendil-works/pi-ai/providers/all";
|
|
6
7
|
import { buildBaseOptions } from "@earendil-works/pi-ai/api/simple-options";
|
|
7
8
|
import { LlmError, ReasoningEffortId, assertUsableApiKey, attributionHeaders, freezeMessage, resolveImageAttachmentAccess, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
8
|
-
import { snapshotDsmmCall } from "./host-llm.js";
|
|
9
|
+
import { singleUsePreparedStream, snapshotDsmmCall } from "./host-llm.js";
|
|
9
10
|
import { DsmmMissingProviderError, modelRouteToCall } from "./role-llm.js";
|
|
10
11
|
import { normalizeModelRouteJson } from "./route-json.js";
|
|
11
12
|
function normalizeDeclaredProfiles(config) {
|
|
12
13
|
const profiles = new Map();
|
|
13
|
-
|
|
14
|
+
const normalized = Config(config);
|
|
15
|
+
for (const [provider, profile] of Object.entries(normalized.providers.get())) {
|
|
14
16
|
if (profile.api !== "openai-completions" || !profile.baseURL || !profile.apiKeyEnv || !profile.models?.length
|
|
15
17
|
|| profile.modelOverrides !== undefined && Object.keys(profile.modelOverrides).length > 0) {
|
|
16
18
|
throw new LlmError("Raw execution requires an explicit completions endpoint, credential reference and finite model list without catalog overrides", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
@@ -30,8 +32,15 @@ function normalizeDeclaredProfiles(config) {
|
|
|
30
32
|
throw new LlmError("Declared models must have input modalities", "INVALID_CONFIG");
|
|
31
33
|
if (!Number.isSafeInteger(contextWindow) || contextWindow <= 0 || !Number.isSafeInteger(maxTokens) || maxTokens <= 0)
|
|
32
34
|
throw new LlmError("Model capacities must be positive integers", "INVALID_CONFIG");
|
|
35
|
+
const efforts = entry.reasoningEfforts;
|
|
36
|
+
const thinkingLevelMap = {
|
|
37
|
+
off: null, minimal: null, low: null, medium: null, high: null, xhigh: null, max: null,
|
|
38
|
+
...(efforts || {}),
|
|
39
|
+
};
|
|
40
|
+
if (efforts && efforts.off === null)
|
|
41
|
+
delete thinkingLevelMap.off;
|
|
33
42
|
return { id: entry.id, name: entry.name ?? entry.id, provider, api: "openai-completions", baseUrl: profile.baseURL,
|
|
34
|
-
reasoning:
|
|
43
|
+
reasoning: !!efforts, ...(efforts ? { thinkingLevelMap } : {}), input, contextWindow: contextWindow, maxTokens: maxTokens,
|
|
35
44
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
36
45
|
compat: { ...profile.compat, ...entry.compat } };
|
|
37
46
|
});
|
|
@@ -68,7 +77,7 @@ function protectedHeaders(headers) {
|
|
|
68
77
|
return Object.fromEntries(result);
|
|
69
78
|
}
|
|
70
79
|
/** Public provider composition preserves the SDK's native content/replay/stream translator. */
|
|
71
|
-
function rawProvider(provider, generation, request, assertCurrent) {
|
|
80
|
+
function rawProvider(provider, generation, request, assertCurrent, effortSource) {
|
|
72
81
|
return {
|
|
73
82
|
...provider,
|
|
74
83
|
streamSimple(model, context, options) {
|
|
@@ -92,14 +101,22 @@ function rawProvider(provider, generation, request, assertCurrent) {
|
|
|
92
101
|
if (tokenField !== undefined && !Object.hasOwn(payload, tokenField))
|
|
93
102
|
throw new LlmError("Raw token field does not match the declared model protocol", "INVALID_REQUEST");
|
|
94
103
|
const body = { ...payload, ...request.customParameters };
|
|
95
|
-
if (request.reasoningEffort !== undefined)
|
|
104
|
+
if (effortSource === "dsmm-config" && request.reasoningEffort !== undefined)
|
|
96
105
|
Reflect.set(body, "reasoning_effort", request.reasoningEffort);
|
|
97
106
|
if (request.stop !== undefined)
|
|
98
107
|
Reflect.set(body, "stop", [...request.stop]);
|
|
99
108
|
return body;
|
|
100
109
|
},
|
|
101
110
|
};
|
|
102
|
-
|
|
111
|
+
const transformHeaders = (headers) => {
|
|
112
|
+
assertCurrent();
|
|
113
|
+
request.signal?.throwIfAborted();
|
|
114
|
+
return protectedHeaders(headers);
|
|
115
|
+
};
|
|
116
|
+
if (effortSource === "native")
|
|
117
|
+
return generation.streamSimple(exact, context, { ...options,
|
|
118
|
+
...(typeof rawBudget === "number" ? { maxTokens: rawBudget } : {}), onPayload: wireOptions.onPayload, transformHeaders });
|
|
119
|
+
return generation.stream({ ...exact, reasoning: false, thinkingLevelMap: undefined }, context, { ...wireOptions, transformHeaders });
|
|
103
120
|
},
|
|
104
121
|
};
|
|
105
122
|
}
|
|
@@ -186,6 +203,8 @@ export function createDsmmPiAiProviderOwner(ctx, options, borrowed) {
|
|
|
186
203
|
for (const profile of profiles.values())
|
|
187
204
|
models.setProvider(profile.piProvider);
|
|
188
205
|
const owner = Object.freeze({ stockAdapter, providers,
|
|
206
|
+
requiresRaw: (config) => config.customParameters !== undefined || config.stop !== undefined && profiles.has(config.provider),
|
|
207
|
+
supportsNativeStop: (provider) => !profiles.has(provider),
|
|
189
208
|
async resolveRoute(input, signal) {
|
|
190
209
|
const route = normalizeModelRouteJson(input);
|
|
191
210
|
signal?.throwIfAborted();
|
|
@@ -213,16 +232,22 @@ export function createDsmmPiAiProviderOwner(ctx, options, borrowed) {
|
|
|
213
232
|
throw new LlmError("Provider is not owned by this Host", "NO_ADAPTER");
|
|
214
233
|
return Object.freeze({ identity, signal: borrowed === undefined ? life.signal : AbortSignal.any([life.signal, borrowed.signal]), retryPolicy: profile.retryPolicy, assertCurrent,
|
|
215
234
|
...(profile.reasoning === undefined ? {} : { defaultReasoningEffort: ReasoningEffortId(profile.reasoning) }),
|
|
216
|
-
async prepareCall(selectedProvider, model, signal, assertAdmission) {
|
|
235
|
+
async prepareCall(selectedProvider, model, signal, assertAdmission, effortSource) {
|
|
217
236
|
const assertCall = () => { signal.throwIfAborted(); assertCurrent(); assertAdmission?.(); };
|
|
218
237
|
assertCall();
|
|
219
238
|
if (selectedProvider !== provider || models.getModel(provider, model) === undefined)
|
|
220
239
|
throw new LlmError("Provider has no exact declared model", "UNKNOWN_MODEL");
|
|
221
|
-
const
|
|
240
|
+
const prepared = await (borrowed?.adapter ?? stockAdapter).prepareCall(provider, model, signal);
|
|
222
241
|
assertCall();
|
|
223
|
-
|
|
242
|
+
if (prepared.model.provider !== provider || prepared.model.id !== model)
|
|
243
|
+
throw new LlmError("Provider resolved another model", "INVALID_ADAPTER");
|
|
244
|
+
const catalogProvider = getBuiltinProviders().find(id => id === provider);
|
|
245
|
+
const catalogModel = catalogProvider !== undefined && getBuiltinModels(catalogProvider).some(entry => entry.id === model);
|
|
246
|
+
return { model: prepared.model, stream: singleUsePreparedStream(request => {
|
|
224
247
|
assertCall();
|
|
225
248
|
request.signal?.throwIfAborted();
|
|
249
|
+
if (request.provider !== provider || request.model !== model)
|
|
250
|
+
throw new LlmError("Raw request changed its prepared route", "INVALID_PREPARED_CALL");
|
|
226
251
|
const extended = request;
|
|
227
252
|
const checked = snapshotDsmmCall({ provider: request.provider, model: request.model,
|
|
228
253
|
...(request.reasoningEffort === undefined ? {} : { reasoningEffort: request.reasoningEffort }),
|
|
@@ -231,8 +256,17 @@ export function createDsmmPiAiProviderOwner(ctx, options, borrowed) {
|
|
|
231
256
|
...(request.stop === undefined ? {} : { stop: request.stop }),
|
|
232
257
|
...(extended.customParameters === undefined ? {} : { customParameters: extended.customParameters }),
|
|
233
258
|
});
|
|
234
|
-
|
|
235
|
-
|
|
259
|
+
if (catalogModel)
|
|
260
|
+
throw new LlmError("Raw execution cannot reproduce implicit catalog model semantics", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
261
|
+
const source = effortSource?.() ?? "dsmm-config";
|
|
262
|
+
if (source === "native") {
|
|
263
|
+
if (prepared.model.reasoning !== undefined && models.getModel(provider, model)?.thinkingLevelMap === undefined
|
|
264
|
+
|| Object.hasOwn(checked.customParameters ?? {}, "reasoning_effort")) {
|
|
265
|
+
throw new LlmError("Native raw execution requires its declared wire mapping and cannot replace native effort with raw effort", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const projectedProfiles = new Map([...profiles].map(([id, item]) => [id, { ...item, reasoning: source === "native" ? item.reasoning : undefined,
|
|
269
|
+
piProvider: rawProvider(item.piProvider, models, { ...request, ...checked }, assertCall, source) }]));
|
|
236
270
|
const credentialSignal = request.signal === undefined ? life.signal : AbortSignal.any([life.signal, request.signal]);
|
|
237
271
|
const rawAdapter = new PiAiAdapter({ ...adapterOptions, profiles: () => projectedProfiles,
|
|
238
272
|
resolveApiKey: async (selectedProvider, selectedProfile) => {
|
|
@@ -248,8 +282,8 @@ export function createDsmmPiAiProviderOwner(ctx, options, borrowed) {
|
|
|
248
282
|
const { replayState: _replay, ...source } = message.source;
|
|
249
283
|
return freezeMessage({ ...message, source });
|
|
250
284
|
});
|
|
251
|
-
return rawAdapter.stream({ ...native, messages });
|
|
252
|
-
} };
|
|
285
|
+
return rawAdapter.stream({ ...native, ...(source === "native" && request.reasoningEffort !== undefined ? { reasoningEffort: request.reasoningEffort } : {}), messages });
|
|
286
|
+
}) };
|
|
253
287
|
},
|
|
254
288
|
});
|
|
255
289
|
},
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
|
|
4
|
+
import type { ChildPermissionView } from "./permission-temporary-types.js";
|
|
5
|
+
interface ChildScope {
|
|
6
|
+
readonly role?: string;
|
|
7
|
+
readonly readOnly: boolean;
|
|
8
|
+
check(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface ChildPermissionOptions {
|
|
11
|
+
capture(parent: Agent, child: Agent): ChildScope;
|
|
12
|
+
refresh(): Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
/** A live operator policy transition, separate from the immutable native creation fact. */
|
|
15
|
+
export declare class ChildPermissionControl {
|
|
16
|
+
private readonly ctx;
|
|
17
|
+
private readonly grants;
|
|
18
|
+
private readonly options;
|
|
19
|
+
private readonly operators;
|
|
20
|
+
private readonly transitions;
|
|
21
|
+
private readonly lifetime;
|
|
22
|
+
constructor(ctx: Context, grants: TemporaryPermissionGrants, options: ChildPermissionOptions);
|
|
23
|
+
private live;
|
|
24
|
+
private operator;
|
|
25
|
+
assertEnabled(child: Agent): void;
|
|
26
|
+
authorizeChild(_peer: object, child: Agent): {
|
|
27
|
+
assertCurrent(): void;
|
|
28
|
+
};
|
|
29
|
+
describe(parent: Agent, child: Agent): ChildPermissionView;
|
|
30
|
+
private change;
|
|
31
|
+
enable(parent: Agent, child: Agent, checkOperator: () => void): Promise<ChildPermissionView>;
|
|
32
|
+
revoke(parent: Agent, child: Agent, checkOperator: () => void): Promise<ChildPermissionView>;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=permission-child-control.d.ts.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { SubagentRuntime } from "@deepseek-ai/dsh-subagent";
|
|
2
|
+
import { ApprovalService } from "@deepseek-ai/dsh-user-approval";
|
|
3
|
+
import { SessionSeq } from "@deepseek-ai/dsh-session";
|
|
4
|
+
import { PermissionRefusal, permissionApprovalAdapter, permissionOriginal } from "./permission-control.js";
|
|
5
|
+
function latestPolicy(agent) {
|
|
6
|
+
for (let seq = agent.session.seq - 1; seq >= 0; seq--) {
|
|
7
|
+
const event = agent.session.eventAt(SessionSeq(seq));
|
|
8
|
+
if (event?.type === "approval/policy")
|
|
9
|
+
return event;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
/** A live operator policy transition, separate from the immutable native creation fact. */
|
|
14
|
+
export class ChildPermissionControl {
|
|
15
|
+
ctx;
|
|
16
|
+
grants;
|
|
17
|
+
options;
|
|
18
|
+
operators = new Map();
|
|
19
|
+
transitions = new WeakMap();
|
|
20
|
+
lifetime = new AbortController();
|
|
21
|
+
constructor(ctx, grants, options) {
|
|
22
|
+
this.ctx = ctx;
|
|
23
|
+
this.grants = grants;
|
|
24
|
+
this.options = options;
|
|
25
|
+
const guard = ctx.on("approval/request", permissionApprovalAdapter(ctx, (request, next) => {
|
|
26
|
+
const agent = request.agent, agents = ctx.get("agents");
|
|
27
|
+
if (agents?.roots().includes(agent) && agent.session.header.origin !== "subagent")
|
|
28
|
+
return next();
|
|
29
|
+
try {
|
|
30
|
+
this.assertEnabled(agent);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return Promise.resolve("unavailable");
|
|
34
|
+
}
|
|
35
|
+
return next();
|
|
36
|
+
}), { prepend: true, global: true });
|
|
37
|
+
const disposed = ctx.on("agent/disposed", ({ agent }) => {
|
|
38
|
+
for (const [child, authority] of this.operators)
|
|
39
|
+
if (child === agent || authority.parent === agent) {
|
|
40
|
+
this.grants.revokeAgent(child);
|
|
41
|
+
this.transitions.set(child, {});
|
|
42
|
+
this.operators.delete(child);
|
|
43
|
+
}
|
|
44
|
+
}, { global: true });
|
|
45
|
+
ctx.effect(() => () => { this.lifetime.abort(); guard(); disposed(); for (const child of this.operators.keys())
|
|
46
|
+
this.grants.revokeAgent(child); this.operators.clear(); });
|
|
47
|
+
}
|
|
48
|
+
live(parent, child) {
|
|
49
|
+
this.lifetime.signal.throwIfAborted();
|
|
50
|
+
const agents = this.ctx.get("agents"), runtime = this.ctx.get("subagents"), approval = child.ctx.get("approval");
|
|
51
|
+
if (!agents || !runtime || !approval || agents.get(parent.id) !== parent || agents.get(child.id) !== child || !agents.roots().includes(parent)
|
|
52
|
+
|| !agents.isOwnedBy(child.id, parent) || child.session.header.parentSession !== parent.id || child.session.id !== child.id
|
|
53
|
+
|| Object.getPrototypeOf(permissionOriginal(runtime)) !== SubagentRuntime.prototype || Reflect.get(permissionOriginal(runtime), "creationApprovalOf") !== SubagentRuntime.prototype.creationApprovalOf
|
|
54
|
+
|| Object.getPrototypeOf(permissionOriginal(approval)) !== ApprovalService.prototype || Reflect.get(permissionOriginal(approval), "setPolicy") !== ApprovalService.prototype.setPolicy)
|
|
55
|
+
throw new PermissionRefusal("not-owned");
|
|
56
|
+
const origin = runtime.creationApprovalOf(child);
|
|
57
|
+
if (!origin || origin.parent !== parent || origin.child !== child)
|
|
58
|
+
throw new PermissionRefusal("unavailable");
|
|
59
|
+
return { origin, approval };
|
|
60
|
+
}
|
|
61
|
+
operator(child, authority) {
|
|
62
|
+
const live = this.live(authority.parent, child);
|
|
63
|
+
if (live.origin !== authority.origin || permissionOriginal(live.approval) !== permissionOriginal(authority.approval)
|
|
64
|
+
|| child.session !== authority.session || latestPolicy(child) !== authority.record
|
|
65
|
+
|| authority.approval.overrideOf(child.session) !== (authority.enabled ? "ask" : "never"))
|
|
66
|
+
throw new PermissionRefusal("stale");
|
|
67
|
+
}
|
|
68
|
+
assertEnabled(child) {
|
|
69
|
+
const authority = this.operators.get(child);
|
|
70
|
+
if (!authority?.enabled)
|
|
71
|
+
throw new PermissionRefusal("denied");
|
|
72
|
+
this.operator(child, authority);
|
|
73
|
+
authority.scope.check();
|
|
74
|
+
}
|
|
75
|
+
authorizeChild(_peer, child) {
|
|
76
|
+
this.assertEnabled(child);
|
|
77
|
+
const authority = this.operators.get(child);
|
|
78
|
+
return { assertCurrent: () => { if (this.operators.get(child) !== authority)
|
|
79
|
+
throw new PermissionRefusal("stale"); this.assertEnabled(child); } };
|
|
80
|
+
}
|
|
81
|
+
describe(parent, child) {
|
|
82
|
+
const value = { parentSessionId: parent.id, childSessionId: child.id, project: child.session.header.cwd ?? "",
|
|
83
|
+
state: "unavailable", canEnable: false, canRevoke: this.operators.has(child) || this.grants.list(child).length > 0 };
|
|
84
|
+
try {
|
|
85
|
+
const { origin } = this.live(parent, child), authority = this.operators.get(child), scope = this.options.capture(parent, child);
|
|
86
|
+
scope.check();
|
|
87
|
+
if (authority) {
|
|
88
|
+
this.operator(child, authority);
|
|
89
|
+
if (authority.enabled)
|
|
90
|
+
authority.scope.check();
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
origin.assertCurrent(parent, child);
|
|
94
|
+
return { ...value, state: authority?.enabled ? "enabled" : "disabled", canEnable: true, readOnly: scope.readOnly, ...(scope.role ? { role: scope.role } : {}) };
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
change(child, operation) {
|
|
101
|
+
if (child.status === "running") {
|
|
102
|
+
operation();
|
|
103
|
+
return Promise.resolve();
|
|
104
|
+
}
|
|
105
|
+
if (child.status !== "idle")
|
|
106
|
+
throw new PermissionRefusal("unavailable");
|
|
107
|
+
return child.runMaintenance(async (signal) => { signal.throwIfAborted(); operation(); });
|
|
108
|
+
}
|
|
109
|
+
async enable(parent, child, checkOperator) {
|
|
110
|
+
checkOperator();
|
|
111
|
+
const initial = this.live(parent, child), previous = this.operators.get(child), transition = {};
|
|
112
|
+
if (previous)
|
|
113
|
+
this.operator(child, previous);
|
|
114
|
+
else
|
|
115
|
+
initial.origin.assertCurrent(parent, child);
|
|
116
|
+
this.transitions.set(child, transition);
|
|
117
|
+
await this.options.refresh();
|
|
118
|
+
const scope = this.options.capture(parent, child);
|
|
119
|
+
await this.change(child, () => {
|
|
120
|
+
checkOperator();
|
|
121
|
+
scope.check();
|
|
122
|
+
const current = this.live(parent, child);
|
|
123
|
+
if (this.transitions.get(child) !== transition || current.origin !== initial.origin || permissionOriginal(current.approval) !== permissionOriginal(initial.approval)
|
|
124
|
+
|| !this.ctx.get("typertGateway")?.hasLiveClient())
|
|
125
|
+
throw new PermissionRefusal("unavailable");
|
|
126
|
+
if (previous)
|
|
127
|
+
this.operator(child, previous);
|
|
128
|
+
else
|
|
129
|
+
current.origin.assertCurrent(parent, child);
|
|
130
|
+
current.approval.setPolicy(child, "ask");
|
|
131
|
+
this.operators.set(child, { parent, origin: current.origin, scope, approval: current.approval, session: child.session, record: latestPolicy(child), enabled: true });
|
|
132
|
+
});
|
|
133
|
+
return this.describe(parent, child);
|
|
134
|
+
}
|
|
135
|
+
async revoke(parent, child, checkOperator) {
|
|
136
|
+
checkOperator();
|
|
137
|
+
this.grants.revokeAgent(child);
|
|
138
|
+
this.transitions.set(child, {});
|
|
139
|
+
const previous = this.operators.get(child);
|
|
140
|
+
if (!previous)
|
|
141
|
+
return this.describe(parent, child);
|
|
142
|
+
const enabled = previous.enabled;
|
|
143
|
+
previous.enabled = false;
|
|
144
|
+
try {
|
|
145
|
+
await this.change(child, () => {
|
|
146
|
+
checkOperator();
|
|
147
|
+
const live = this.live(parent, child);
|
|
148
|
+
if (previous.parent !== parent || live.origin !== previous.origin || child.session !== previous.session || latestPolicy(child) !== previous.record
|
|
149
|
+
|| permissionOriginal(live.approval) !== permissionOriginal(previous.approval)
|
|
150
|
+
|| live.approval.overrideOf(child.session) !== (enabled ? "ask" : "never"))
|
|
151
|
+
throw new PermissionRefusal("stale");
|
|
152
|
+
live.approval.setPolicy(child, "never");
|
|
153
|
+
previous.record = latestPolicy(child);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return { ...this.describe(parent, child), state: "unavailable", canEnable: false };
|
|
158
|
+
}
|
|
159
|
+
return this.describe(parent, child);
|
|
160
|
+
}
|
|
161
|
+
dispose() { this.lifetime.abort(); for (const child of this.operators.keys())
|
|
162
|
+
this.grants.revokeAgent(child); this.operators.clear(); }
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=permission-child-control.js.map
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
3
|
import type { PreToolDecision, ToolDefinition, ToolExecution, ToolRunContext } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
import type { RoleRunHolder } from "./role-runs.js";
|
|
5
4
|
import type { NativeCommandEntry } from "./permission-settings.js";
|
|
6
5
|
import type { NativePermissionMode } from "./permission-native-access.js";
|
|
7
6
|
export { PermissionRefusal } from "./permission-errors.js";
|
|
8
|
-
export type PermissionRunHolder = Pick<RoleRunHolder, "state" | "owner" | "invocation" | "holderSignal" | "drained">;
|
|
9
7
|
export interface PermissionExecutionAuthority {
|
|
10
8
|
readonly agent: Agent;
|
|
11
9
|
readonly root: Agent;
|
|
@@ -15,7 +13,6 @@ export interface PermissionExecutionAuthority {
|
|
|
15
13
|
readonly owner: object;
|
|
16
14
|
readonly ownerGeneration: string | number;
|
|
17
15
|
readonly signal: AbortSignal;
|
|
18
|
-
readonly run?: PermissionRunHolder;
|
|
19
16
|
}
|
|
20
17
|
export type PermissionRootApprovalAuthority = Pick<PermissionExecutionAuthority, "root" | "realm" | "admissionRevision" | "permissionRevision" | "owner" | "ownerGeneration" | "signal">;
|
|
21
18
|
export interface PermissionExecutionIntegrity {
|
|
@@ -44,6 +41,8 @@ export interface PermissionRegistration {
|
|
|
44
41
|
export declare function permissionOriginal(value: object): object;
|
|
45
42
|
type Request = Parameters<Context["approval"]["request"]>[0];
|
|
46
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;
|
|
47
46
|
export declare function isSandboxWidening(requested: NativeCommandEntry["sandboxMode"], standing: string | undefined): boolean;
|
|
48
47
|
/** Permission admission precedes native approval; subsequent checks enforce execution integrity only. */
|
|
49
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
|