@dsmm/dsmm 0.3.10 → 0.3.11

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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +0 -4
  3. package/agent-presets/dsmm-clarifier/agent.cordis.yml +0 -4
  4. package/agent-presets/dsmm-code-search/agent.cordis.yml +0 -4
  5. package/agent-presets/dsmm-coding/agent.cordis.yml +0 -4
  6. package/agent-presets/dsmm-complex/agent.cordis.yml +0 -4
  7. package/agent-presets/dsmm-creative/agent.cordis.yml +0 -4
  8. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +0 -4
  9. package/agent-presets/dsmm-deep/agent.cordis.yml +0 -4
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +0 -4
  11. package/agent-presets/dsmm-documenting/agent.cordis.yml +0 -4
  12. package/agent-presets/dsmm-frontend/agent.cordis.yml +0 -4
  13. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +0 -4
  14. package/agent-presets/dsmm-media-reader/agent.cordis.yml +0 -4
  15. package/agent-presets/dsmm-normal-task/agent.cordis.yml +0 -4
  16. package/agent-presets/dsmm-oracle/agent.cordis.yml +0 -4
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +0 -4
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +0 -4
  19. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +0 -4
  20. package/agent-presets/dsmm-planner/agent.cordis.yml +0 -4
  21. package/agent-presets/dsmm-quick/agent.cordis.yml +0 -4
  22. package/agent-presets/dsmm-research/agent.cordis.yml +0 -4
  23. package/agent-presets/dsmm-reviewer/agent.cordis.yml +0 -4
  24. package/docs/agent-presets.md +2 -2
  25. package/docs/compatibility.md +2 -2
  26. package/docs/deferred-native-approval-risk.md +11 -1
  27. package/docs/design.md +1 -1
  28. package/docs/lsp.md +1 -1
  29. package/docs/model-routing.md +1 -1
  30. package/docs/native-permissions.md +5 -1
  31. package/docs/profiles.md +1 -1
  32. package/docs/roadmap.md +3 -3
  33. package/docs/runtime-recovery.md +1 -1
  34. package/docs/safety-guards.md +23 -5
  35. package/docs/settings-status.md +1 -1
  36. package/lib/child-capture.js +5 -1
  37. package/lib/client/deployment-locales.js +1 -0
  38. package/lib/client/permission-locales.js +8 -8
  39. package/lib/client.js +10 -9
  40. package/lib/command-approval.d.ts +50 -0
  41. package/lib/command-approval.js +148 -0
  42. package/lib/core-permissions.d.ts +2 -1
  43. package/lib/core-permissions.js +6 -3
  44. package/lib/guards.d.ts +2 -1
  45. package/lib/guards.js +45 -8
  46. package/lib/index.d.ts +1 -1
  47. package/lib/index.js +4 -2
  48. package/lib/permission-control.d.ts +5 -2
  49. package/lib/permission-control.js +46 -24
  50. package/lib/permission-controller.d.ts +2 -0
  51. package/lib/permission-controller.js +13 -8
  52. package/lib/permission-native-command.d.ts +2 -0
  53. package/lib/permission-native-command.js +9 -4
  54. package/lib/permission-native-rules.d.ts +2 -2
  55. package/lib/permission-native-rules.js +12 -10
  56. package/lib/profile-diagnostics.js +1 -1
  57. package/lib/profiles.js +2 -1
  58. package/lib/prompt-content.js +2 -2
  59. package/lib/settings.d.ts +2 -0
  60. package/lib/settings.js +10 -0
  61. package/lib/shell-command.d.ts +16 -0
  62. package/lib/shell-command.js +443 -119
  63. package/package.json +1 -1
@@ -4,6 +4,7 @@ import { HarnessError } from "@deepseek-ai/dsh-llm";
4
4
  import { TOOL_ABORTED } from "@deepseek-ai/dsh-tools";
5
5
  import { PermissionRefusal, permissionOutcome } from "./permission-errors.js";
6
6
  import { nativeStandingFullAccess } from "./permission-native-access.js";
7
+ import { CommandApprovals } from "./command-approval.js";
7
8
  export { PermissionRefusal } from "./permission-errors.js";
8
9
  export function permissionOriginal(value) { return Reflect.get(value, symbols.original) ?? value; }
9
10
  /** Explicitly audited DSMM approval adapters retain identity through the patched dispatcher. */
@@ -24,12 +25,14 @@ export class PermissionControl {
24
25
  bindings = new Map();
25
26
  requests = new WeakMap();
26
27
  execution = new AsyncLocalStorage();
27
- constructor(ctx, collaborators) {
28
+ commandApprovals;
29
+ constructor(ctx, collaborators, approvals) {
28
30
  this.ctx = ctx;
29
31
  this.collaborators = collaborators;
32
+ this.commandApprovals = approvals ?? new CommandApprovals(ctx);
30
33
  }
31
- async compose(exec, registration, entry, action, next, cwd, simple = false) {
32
- const previous = this.bindings.get(exec.token);
34
+ async compose(exec, registration, entry, action, next, cwd, simple = false, contributions = [], source = {}) {
35
+ const previous = this.bindings.get(exec);
33
36
  if (simple && previous?.simple) {
34
37
  this.checkIntegrity(previous);
35
38
  return this.composeDecision(previous, next, false);
@@ -54,22 +57,30 @@ export class PermissionControl {
54
57
  const args = exec.arguments;
55
58
  const officialMode = !nativeOnly && (args.sandbox_permissions === "workspace-write" || args.sandbox_permissions === "danger-full-access") ? args.sandbox_permissions : undefined;
56
59
  const standing = registration.standingMode(exec);
57
- const target = simple ? "danger-full-access" : officialMode ?? (entry === undefined ? undefined : isSandboxWidening(entry.sandboxMode, standing) ? entry.sandboxMode : standing ?? entry.sandboxMode);
58
- const reason = `DSMM command: ${String(args.command)}\nWorking directory: ${cwd}\nSandbox mode: ${target ?? "native standing policy"}. ${target === "danger-full-access" ? "Command execution may write outside the workspace to any OS-permitted location; this is not a cache-only or path-whitelist grant." : "Exact native tool invocation under the stated native sandbox policy."}`;
60
+ const target = simple ? "danger-full-access" : officialMode ?? (entry === undefined ? undefined : isSandboxWidening(entry.sandboxMode, standing) ? entry.sandboxMode : entry.mode === "allow" ? standing ?? entry.sandboxMode : undefined);
61
+ const rules = simple || nativeOnly || contributions.length === 0 ? undefined : this.commandApprovals.capture(exec, contributions, {
62
+ ...source, deferredCommit: true, owner: authority?.owner, ownerGeneration: authority?.ownerGeneration, realm: authority?.realm, assertCurrent: () => integrity.assertCurrent(),
63
+ });
64
+ const ask = !simple && (rules === undefined ? action === "ask" || entry?.mode === "ask" : rules.missing.length > 0);
65
+ const ruleNames = (rules?.missing ?? contributions).map(rule => {
66
+ const semantics = rule.semantics;
67
+ return semantics !== null && typeof semantics === "object" && "id" in semantics ? `${rule.kind}:${String(semantics.id)}` : rule.kind;
68
+ });
69
+ const reason = `DSMM command: ${String(args.command)}\nWorking directory: ${cwd}\n${ruleNames.length === 0 ? "" : `Command rules: ${ruleNames.join(", ")}\n`}Sandbox mode: ${target ?? "native standing policy"}. ${target === "danger-full-access" ? "Command execution may write outside the workspace to any OS-permitted location; this is not a cache-only or path-whitelist grant." : "Exact native tool invocation under the stated native sandbox policy."}`;
59
70
  const lifetime = new AbortController();
60
- const binding = { exec, args: exec.arguments, agent: exec.agent, callId: exec.callId, name: exec.name,
71
+ const binding = { exec, token: exec.token, session: exec.agent?.session, args: exec.arguments, agent: exec.agent, callId: exec.callId, name: exec.name,
61
72
  registration, root: authority?.root, integrity, entry, officialMode, simple,
62
73
  target: target === "workspace-write" || target === "danger-full-access" ? target : undefined,
63
- reason, ask: !simple && (action === "ask" || entry?.mode === "ask"), lifetime,
74
+ reason, ask, rules, lifetime,
64
75
  signal: AbortSignal.any([exec.signal, lifetime.signal, this.lifetime.signal,
65
76
  ...integrity.signal === undefined ? [] : [integrity.signal], ...registration.signal === undefined ? [] : [registration.signal]]),
66
- entered: false, nativeRequest: false };
77
+ entered: false, nativeRequest: false, askSatisfied: !ask };
67
78
  this.checkIntegrity(binding);
68
- this.bindings.set(exec.token, binding);
79
+ this.bindings.set(exec, binding);
69
80
  return this.composeDecision(binding, next, nativeOnly);
70
81
  }
71
82
  async composeDecision(binding, next, nativeOnly) {
72
- const { exec, registration, entry, officialMode, reason } = binding;
83
+ const { exec, registration, reason } = binding;
73
84
  const downstream = await next();
74
85
  if (exec.signal.aborted)
75
86
  return { kind: "cancel" };
@@ -78,13 +89,13 @@ export class PermissionControl {
78
89
  return downstream;
79
90
  if (nativeOnly)
80
91
  return downstream;
81
- const needsAsk = downstream.kind === "ask" || binding.ask && (entry === undefined || officialMode !== undefined);
92
+ const needsAsk = downstream.kind === "ask" || binding.ask && (binding.entry === undefined || binding.officialMode !== undefined);
82
93
  if (!needsAsk)
83
94
  return downstream;
84
95
  const reasons = [downstream.kind === "ask" ? downstream.reason : undefined, reason].filter(Boolean).join("\n");
85
96
  const displayReason = Object.freeze({ en: reasons, zh: reasons,
86
97
  ...downstream.kind === "ask" && downstream.displayReason !== undefined ? Object.fromEntries(Object.entries(downstream.displayReason).map(([locale, text]) => [locale, `${text}\n${reason}`])) : {} });
87
- if (binding.target === undefined)
98
+ if (binding.target === undefined && !binding.ask)
88
99
  return { kind: "ask", reason: reasons, displayReason };
89
100
  const approval = registration.approval();
90
101
  if (approval === undefined || exec.agent === undefined)
@@ -96,6 +107,8 @@ export class PermissionControl {
96
107
  this.checkIntegrity(binding);
97
108
  if (outcome !== "allowed-once")
98
109
  return { kind: "deny", reason: `Native command approval ${outcome}.` };
110
+ binding.rules?.resolved(outcome);
111
+ binding.askSatisfied = true;
99
112
  binding.approvedTarget = binding.target;
100
113
  return { kind: "allow" };
101
114
  }
@@ -103,15 +116,16 @@ export class PermissionControl {
103
116
  if (binding.signal.aborted || binding.exec.signal.aborted)
104
117
  throw new HarnessError("Permission-controlled call cancelled.", TOOL_ABORTED);
105
118
  const { exec, registration } = binding;
106
- if (exec.arguments !== binding.args || exec.agent !== binding.agent || exec.callId !== binding.callId || exec.name !== binding.name
119
+ if (exec.token !== binding.token || exec.agent?.session !== binding.session || exec.arguments !== binding.args || exec.agent !== binding.agent || exec.callId !== binding.callId || exec.name !== binding.name
107
120
  || !registration.active || !registration.unchanged() || registration.definition.execute !== (registration.wrapper ?? registration.body)
108
121
  || this.ctx.tools.get(binding.name, binding.agent) !== registration.registered)
109
122
  throw new PermissionRefusal("stale");
110
123
  binding.integrity.assertCurrent();
111
124
  registration.assertIntegrity?.(exec);
125
+ binding.rules?.assertCurrent();
112
126
  }
113
127
  guard(exec) {
114
- const binding = this.bindings.get(exec.token);
128
+ const binding = this.bindings.get(exec);
115
129
  if (binding === undefined)
116
130
  return undefined;
117
131
  try {
@@ -138,7 +152,7 @@ export class PermissionControl {
138
152
  return owned.allow ? "allowed-once" : permissionOutcome(next, owned.binding.signal, "cancelled");
139
153
  }
140
154
  isSimple(exec) {
141
- const binding = this.bindings.get(exec.token);
155
+ const binding = this.bindings.get(exec);
142
156
  if (binding?.simple !== true)
143
157
  return false;
144
158
  this.checkIntegrity(binding);
@@ -146,7 +160,7 @@ export class PermissionControl {
146
160
  }
147
161
  pending(registration) { return [...this.bindings.values()].some(binding => binding.registration === registration); }
148
162
  async run(exec, args, registration, body) {
149
- const binding = this.bindings.get(exec.token);
163
+ const binding = this.bindings.get(exec);
150
164
  if (binding === undefined && registration.simpleOnly)
151
165
  return body(exec.signal, args);
152
166
  if (binding === undefined || binding.registration !== registration || binding.entered || args !== binding.args)
@@ -155,7 +169,7 @@ export class PermissionControl {
155
169
  this.checkIntegrity(binding);
156
170
  binding.entered = true;
157
171
  try {
158
- if (binding.entry !== undefined && binding.officialMode === undefined && !nativeStandingFullAccess(this.ctx, exec.agent)) {
172
+ if (binding.entry !== undefined && (binding.target !== undefined || !binding.askSatisfied) && binding.officialMode === undefined && !nativeStandingFullAccess(this.ctx, exec.agent)) {
159
173
  if (binding.approvedTarget === undefined) {
160
174
  const approval = registration.approval();
161
175
  if (approval === undefined || exec.agent === undefined)
@@ -166,10 +180,13 @@ export class PermissionControl {
166
180
  throw new HarnessError("Native permission request cancelled.", TOOL_ABORTED);
167
181
  if (outcome !== "allowed-once")
168
182
  throw new PermissionRefusal(outcome === "unavailable" ? "unavailable" : "denied");
183
+ binding.rules?.resolved(outcome);
184
+ binding.askSatisfied = true;
169
185
  binding.approvedTarget = binding.target;
170
186
  }
171
187
  binding.mode = binding.approvedTarget;
172
188
  }
189
+ this.commandApprovals.commit(binding.exec);
173
190
  return await this.execution.run(binding, () => body(binding.signal, binding.simple ? Object.freeze({ ...args,
174
191
  sandbox_permissions: "danger-full-access", justification: binding.reason }) : args));
175
192
  }
@@ -204,10 +221,14 @@ export class PermissionControl {
204
221
  }
205
222
  const actual = { ...request, reason: [request.reason, binding.reason].filter(Boolean).join("\n") };
206
223
  const covers = binding.entry !== undefined && (binding.entry.sandboxMode === "danger-full-access" || binding.officialMode === "workspace-write");
207
- return this.request(binding, actual, service, covers && binding.entry.mode === "allow" && !binding.ask);
224
+ const outcome = await this.request(binding, actual, service, covers && binding.entry.mode === "allow" && !binding.ask);
225
+ binding.rules?.resolved(outcome);
226
+ if (outcome === "allowed-once")
227
+ this.commandApprovals.commit(binding.exec);
228
+ return outcome;
208
229
  }
209
230
  approvedTarget(exec) {
210
- const binding = this.bindings.get(exec.token);
231
+ const binding = this.bindings.get(exec);
211
232
  if (binding === undefined)
212
233
  return undefined;
213
234
  this.checkIntegrity(binding);
@@ -224,20 +245,21 @@ export class PermissionControl {
224
245
  return mode;
225
246
  }
226
247
  finish(exec) {
227
- const binding = this.bindings.get(exec.token);
248
+ const binding = this.bindings.get(exec);
228
249
  if (binding !== undefined) {
229
250
  binding.mode = undefined;
230
251
  binding.approvedTarget = undefined;
231
252
  binding.lifetime.abort();
232
253
  }
233
- this.bindings.delete(exec.token);
254
+ this.bindings.delete(exec);
255
+ this.commandApprovals.finish(exec);
234
256
  }
235
- revokePolicy() { }
257
+ revokePolicy() { this.commandApprovals.invalidate(); }
236
258
  revokeRegistration(registration) { registration.active = false; }
237
- revokeAgent(agent) { for (const binding of this.bindings.values())
259
+ revokeAgent(agent) { this.commandApprovals.revokeAgent(agent); for (const binding of this.bindings.values())
238
260
  if (binding.agent === agent || binding.root === agent)
239
261
  this.finish(binding.exec); }
240
- retire() { this.lifetime.abort(); for (const binding of this.bindings.values()) {
262
+ retire() { this.lifetime.abort(); this.commandApprovals.invalidate(); for (const binding of this.bindings.values()) {
241
263
  binding.lifetime.abort();
242
264
  binding.mode = undefined;
243
265
  binding.approvedTarget = undefined;
@@ -4,6 +4,7 @@ import type { ToolExecution } from "@deepseek-ai/dsh-tools";
4
4
  import type { Agent } from "@deepseek-ai/dsh-agent";
5
5
  import { PermissionControl } from "./permission-control.js";
6
6
  import type { PermissionControlCollaborators } from "./permission-control.js";
7
+ import type { CommandApprovals } from "./command-approval.js";
7
8
  import type { PermissionShellIdentity } from "./permission-shell.js";
8
9
  import type { NativePermissionCapabilityView, NativePermissionFileSystem, NativePermissionToolIdentity } from "./permission-native-rules.js";
9
10
  import type { PermissionRulesRuntimeSync } from "./permission-rules.js";
@@ -13,6 +14,7 @@ export type ManagedPermissionTool = "fs" | "fs-search" | "web";
13
14
  type NativeToolKind = Exclude<NativePermissionToolIdentity["kind"], "shell">;
14
15
  export declare const PERMISSION_CONTROLLER_INJECT: readonly ["tools", "agents"];
15
16
  export interface PermissionControllerOptions {
17
+ readonly commandApprovals?: CommandApprovals;
16
18
  /** The existing live Core owner/admission/Root/realm/run facts, not serialized settings or a ready boolean. */
17
19
  readonly authority: PermissionControlCollaborators;
18
20
  readonly rules: PermissionRulesRuntimeSync;
@@ -3,7 +3,7 @@ import { HarnessError } from "@deepseek-ai/dsh-llm";
3
3
  import { TOOL_ABORTED } from "@deepseek-ai/dsh-tools";
4
4
  import { isSandboxWidening, PermissionControl, PermissionRefusal, permissionApprovalAdapter, permissionOriginal } from "./permission-control.js";
5
5
  import { classifyPermissionShell } from "./permission-shell.js";
6
- import { nativeCommandMatch, simpleCommandMatch, simpleShellCommand, simpleShellDialect } from "./permission-native-command.js";
6
+ import { nativeCommandMatches, simpleCommandMatch, simpleShellCommand, simpleShellDialect } from "./permission-native-command.js";
7
7
  import { NATIVE_PERMISSION_CAPABILITIES, registerNativePermissionRules } from "./permission-native-rules.js";
8
8
  import { nativeStandingFullAccess } from "./permission-native-access.js";
9
9
  export const PERMISSION_CONTROLLER_INJECT = ["tools", "agents"];
@@ -62,7 +62,7 @@ export class DsmmPermissionController extends Service {
62
62
  throw new PermissionRefusal("stale");
63
63
  },
64
64
  };
65
- this.permissions = new PermissionControl(ctx, authority);
65
+ this.permissions = new PermissionControl(ctx, authority, options.commandApprovals);
66
66
  if (this.rules.status().mounted) {
67
67
  registerNativePermissionRules(ctx, {
68
68
  runtime: this.rules,
@@ -92,7 +92,7 @@ export class DsmmPermissionController extends Service {
92
92
  return { signal: current.signal, assertCurrent: () => options.authority.assertCurrent(current, exec) };
93
93
  },
94
94
  assertCurrent: exec => authority.assertCurrent(authority.current(exec), exec),
95
- managedShellDecision: async (exec, action, downstream, snapshot) => {
95
+ managedShellDecision: async (exec, action, downstream, snapshot, asks) => {
96
96
  const definition = ctx.tools.get(exec.name, exec.agent), managed = definition === undefined ? undefined : this.registrations.get(definition);
97
97
  if (managed === undefined)
98
98
  throw new PermissionRefusal("stale");
@@ -100,14 +100,19 @@ export class DsmmPermissionController extends Service {
100
100
  const full = nativeStandingFullAccess(ctx, exec.agent);
101
101
  if (full)
102
102
  return this.permissions.compose(exec, managed.registration, undefined, "inherit", downstream, workspace);
103
- const policy = (snapshot ?? this.rules.getPolicy()).policy;
104
- const entry = nativeCommandMatch(policy.nativeCommands, managed.kind, managed.shell, exec.arguments, workspace);
105
- if (entry === "ambiguous")
103
+ const source = snapshot ?? this.rules.getPolicy(), policy = source.policy;
104
+ const entries = nativeCommandMatches(policy.nativeCommands, managed.kind, managed.shell, exec.arguments, workspace);
105
+ if (entries === "ambiguous")
106
106
  managed.scope.logger.warn("Ambiguous native command sandbox modes; retaining native execution policy.");
107
- if (entry !== undefined && entry !== "ambiguous" && managed.scope.get("shell")?.sandboxMode === undefined)
107
+ const entry = entries === "ambiguous" ? undefined : entries.find(entry => entry.mode === "ask") ?? entries[0];
108
+ if (entry !== undefined && managed.scope.get("shell")?.sandboxMode === undefined)
108
109
  return { kind: "deny", reason: "Native command sandbox enhancement is unavailable in this executor." };
109
110
  const operation = classifyPermissionShell(managed.shell, exec.arguments, workspace, exec);
110
- return this.permissions.compose(exec, managed.registration, entry === "ambiguous" ? undefined : entry, action, downstream, operation.workingDirectory);
111
+ const contributions = [
112
+ ...asks.map(rule => ({ kind: "shell", semantics: rule })),
113
+ ...entries === "ambiguous" ? [] : entries.filter(entry => entry.mode === "ask").map(entry => ({ kind: "native-command", semantics: entry })),
114
+ ];
115
+ return this.permissions.compose(exec, managed.registration, entry, action, downstream, operation.workingDirectory, false, contributions, { source, sourceCurrent: () => this.rules.getPolicy() });
111
116
  },
112
117
  });
113
118
  ctx.on("tools/pre-execute", async (exec, next) => {
@@ -7,6 +7,8 @@ export declare function parseHostNativeCommands(input?: unknown): NativeCommands
7
7
  * Unsupported syntax retains the ordinary native path. */
8
8
  export declare function literalCommand(command: string, dialect: PermissionShellIdentity["dialect"], mode?: "legacy" | "simple"): readonly string[] | undefined;
9
9
  export declare function nativeCommandMatch(settings: NativeCommandsSettings, tool: "bash" | "pwsh", identity: PermissionShellIdentity, args: unknown, workspace: string): NativeCommandEntry | "ambiguous" | undefined;
10
+ /** All matching entries retain provenance; mode ambiguity is resolved before any memory lookup. */
11
+ export declare function nativeCommandMatches(settings: NativeCommandsSettings, tool: "bash" | "pwsh", identity: PermissionShellIdentity, args: unknown, workspace: string): readonly NativeCommandEntry[] | "ambiguous";
10
12
  export declare function simpleShellDialect(name: string): PermissionShellIdentity["dialect"] | undefined;
11
13
  export declare function simpleShellCommand(args: unknown): string | undefined;
12
14
  /** A simple hit carries no legacy entry, cwd grant, read trust or sandbox target. */
@@ -76,15 +76,20 @@ export function literalCommand(command, dialect, mode = "legacy") {
76
76
  return Object.freeze(words);
77
77
  }
78
78
  export function nativeCommandMatch(settings, tool, identity, args, workspace) {
79
+ const matches = nativeCommandMatches(settings, tool, identity, args, workspace);
80
+ return matches === "ambiguous" ? matches : matches.find(entry => entry.mode === "ask") ?? matches[0];
81
+ }
82
+ /** All matching entries retain provenance; mode ambiguity is resolved before any memory lookup. */
83
+ export function nativeCommandMatches(settings, tool, identity, args, workspace) {
79
84
  if (!settings.enabled || args === null || typeof args !== "object")
80
- return undefined;
85
+ return [];
81
86
  const command = Reflect.get(args, identity.commandField), modelCwd = identity.cwdField === undefined ? undefined : Reflect.get(args, identity.cwdField);
82
87
  if (typeof command !== "string" || !isAbsolute(workspace) || modelCwd !== undefined && typeof modelCwd !== "string")
83
- return undefined;
88
+ return [];
84
89
  const cwd = normalize(modelCwd === undefined ? workspace : resolve(workspace, modelCwd));
85
90
  const words = literalCommand(command, identity.dialect);
86
91
  if (words === undefined)
87
- return undefined;
92
+ return [];
88
93
  const matches = parseHostNativeCommands(settings).entries.filter((entry) => {
89
94
  if (typeof entry === "string")
90
95
  return false;
@@ -96,7 +101,7 @@ export function nativeCommandMatch(settings, tool, identity, args, workspace) {
96
101
  });
97
102
  if (new Set(matches.map(entry => entry.sandboxMode)).size > 1)
98
103
  return "ambiguous";
99
- return matches.find(entry => entry.mode === "ask") ?? matches[0];
104
+ return matches;
100
105
  }
101
106
  export function simpleShellDialect(name) {
102
107
  const lower = name.toLowerCase();
@@ -2,7 +2,7 @@ import type { Context } from "@deepseek-ai/cordis";
2
2
  import type { PreToolDecision, ToolDefinition, ToolExecution } from "@deepseek-ai/dsh-tools";
3
3
  import type { PermissionExecutionIntegrity } from "./permission-control.js";
4
4
  import type { PermissionShellIdentity } from "./permission-shell.js";
5
- import type { PermissionRuleSnapshot, PermissionRulesRuntimeSync } from "./permission-rules.js";
5
+ import type { PermissionRule, PermissionRuleSnapshot, PermissionRulesRuntimeSync } from "./permission-rules.js";
6
6
  import type { PermissionRulesStatus } from "./permission-rules.js";
7
7
  import type { PermissionRuleAction } from "./permission-settings.js";
8
8
  export interface NativePermissionFsTarget {
@@ -44,7 +44,7 @@ export interface NativePermissionRulesOptions {
44
44
  /** Pure restriction fallback for standalone consumers without an authority capture. */
45
45
  assertCurrent(execution: Readonly<ToolExecution>): void;
46
46
  /** Compose this exact registration's native request; never creates an independent approval UI. */
47
- managedShellDecision?(execution: Readonly<ToolExecution>, action: Exclude<PermissionRuleAction, "deny">, downstream: () => Promise<PreToolDecision>, snapshot: PermissionRuleSnapshot | undefined): Promise<PreToolDecision>;
47
+ managedShellDecision?(execution: Readonly<ToolExecution>, action: Exclude<PermissionRuleAction, "deny">, downstream: () => Promise<PreToolDecision>, snapshot: PermissionRuleSnapshot | undefined, asks: readonly PermissionRule[]): Promise<PreToolDecision>;
48
48
  }
49
49
  /** The public native search tools accept pattern/path/include only; no model-controlled rg flags. */
50
50
  export declare function parseNativePermissionReadPaths(kind: "read" | "glob" | "grep", input: unknown): readonly string[];
@@ -53,14 +53,14 @@ export function parseNativePermissionReadPaths(kind, input) {
53
53
  export function registerNativePermissionRules(ctx, options) {
54
54
  if (!options.runtime.status().mounted)
55
55
  return () => { };
56
- const bindings = new Map();
56
+ const bindings = new WeakMap();
57
57
  const asks = new WeakMap();
58
58
  const lifetime = new AbortController();
59
59
  const tools = ctx.tools;
60
60
  const checkIntegrity = (exec, binding) => {
61
61
  if (exec.signal.aborted || binding.signal.aborted)
62
62
  throw new PermissionRefusal("cancelled");
63
- if (exec.arguments !== binding.args || exec.agent !== binding.agent || exec.callId !== binding.callId || exec.name !== binding.name
63
+ if (exec !== binding.exec || exec.token !== binding.token || exec.arguments !== binding.args || exec.agent !== binding.agent || exec.callId !== binding.callId || exec.name !== binding.name
64
64
  || tools.get(binding.name, binding.agent) !== binding.definition || binding.definition.execute !== binding.body)
65
65
  throw new PermissionRefusal("stale");
66
66
  if (exec.agent !== undefined && ctx.agents.get(exec.agent.id) !== exec.agent)
@@ -178,8 +178,10 @@ export function registerNativePermissionRules(ctx, options) {
178
178
  return policy.rules.some(rule => !rule.revoked && rule.match.kind === "shell" && rule.action === "deny") ? "deny" : "inherit";
179
179
  const operation = classifyPermissionShell(shell, exec.arguments, cwd, exec);
180
180
  shell.readCapability?.assertCurrent(exec);
181
- const rules = policy.rules.filter(rule => !rule.revoked && rule.match.kind === "shell" && rule.match.executable === operation.executable
182
- && rule.match.command === operation.command && rule.match.workingDirectory === operation.workingDirectory).map(rule => rule.action);
181
+ const matched = policy.rules.filter(rule => !rule.revoked && rule.match.kind === "shell" && rule.match.executable === operation.executable
182
+ && rule.match.command === operation.command && rule.match.workingDirectory === operation.workingDirectory);
183
+ binding.asks.push(...matched.filter(rule => rule.action === "ask"));
184
+ const rules = matched.map(rule => rule.action);
183
185
  if (operation.effect !== "read") {
184
186
  // Unknown reads cannot bypass a configured hard outside-read boundary.
185
187
  const hardRead = operation.effect === "unknown" && (policy.outsideReads === "deny" || policy.rules.some(rule => !rule.revoked && rule.match.kind === "outside-read" && rule.action === "deny"));
@@ -210,11 +212,11 @@ export function registerNativePermissionRules(ctx, options) {
210
212
  }
211
213
  const authority = nativeOnly ? undefined : options.captureAuthority?.(exec);
212
214
  const integrity = options.captureIntegrity?.(exec);
213
- const binding = { definition, body: definition.execute, identity, snapshot, nativeOnly, authority, integrity,
215
+ const binding = { exec, token: exec.token, asks: [], definition, body: definition.execute, identity, snapshot, nativeOnly, authority, integrity,
214
216
  args: exec.arguments, agent: exec.agent, name: exec.name, callId: exec.callId,
215
217
  signal: AbortSignal.any([exec.signal, lifetime.signal, ...identity.signal === undefined ? [] : [identity.signal], ...integrity?.signal === undefined ? [] : [integrity.signal]]), approval: ctx.get("approval"), fs: identity.context.get("fs"),
216
218
  workspaceRoot: exec.agent?.session.header.cwd ?? "" };
217
- bindings.set(exec.token, binding);
219
+ bindings.set(exec, binding);
218
220
  check(exec, binding);
219
221
  let action = "inherit";
220
222
  if (snapshot !== undefined) {
@@ -231,7 +233,7 @@ export function registerNativePermissionRules(ctx, options) {
231
233
  if (action === "deny")
232
234
  return { kind: "deny", reason: "DSMM native permission rule denied this tool call." };
233
235
  if (identity.kind === "shell" && options.managedShellDecision !== undefined)
234
- return options.managedShellDecision(exec, action, next, snapshot);
236
+ return options.managedShellDecision(exec, action, next, snapshot, binding.asks);
235
237
  const downstream = await next();
236
238
  if (exec.signal.aborted)
237
239
  return { kind: "cancel" };
@@ -262,7 +264,7 @@ export function registerNativePermissionRules(ctx, options) {
262
264
  return permissionOutcome(next, ask.binding.signal, "cancelled");
263
265
  }), { prepend: true, global: true });
264
266
  const unguard = tools.guard(exec => {
265
- const binding = bindings.get(exec.token);
267
+ const binding = bindings.get(exec);
266
268
  if (binding === undefined)
267
269
  return undefined;
268
270
  try {
@@ -273,8 +275,8 @@ export function registerNativePermissionRules(ctx, options) {
273
275
  return "Native tool execution identity is no longer current.";
274
276
  }
275
277
  });
276
- const unresult = ctx.on("tools/result", exec => { bindings.delete(exec.token); }, { global: true });
277
- const dispose = () => { lifetime.abort(); unhook(); unguard(); unresult(); unapproval(); bindings.clear(); };
278
+ const unresult = ctx.on("tools/result", exec => { bindings.delete(exec); }, { global: true });
279
+ const dispose = () => { lifetime.abort(); unhook(); unguard(); unresult(); unapproval(); };
278
280
  return ctx.effect(() => dispose);
279
281
  }
280
282
  export const NATIVE_PERMISSION_CAPABILITIES = Object.freeze({ outsideReads: "tool-call-boundary", finalInode: false,
@@ -40,7 +40,7 @@ const configFields = {
40
40
  skills: "skills", roles: "roles", roleRouting: "role-routing", runtimePolicy: { strategy: null, rateLimit },
41
41
  presets: { materialize: null, root: null }, subagents: { toolTopology: null, allowRouteOverride: null, enableRunInBackground: null, backgroundMode: null, maxDepth: null },
42
42
  workflow: { policy: null, strictGates: null, reviewCap: null, finalReviewPolicy: null },
43
- guards: { scope: null, shellCommandSafety: null, gitWriteGuard: null, toolOutputTruncation: { enabled: null, maxInlineBytes: null }, planFormatValidation: null, questionLabelHelper: { enabled: null, maxLabelChars: null }, todoDisciplineHelper: null },
43
+ guards: { scope: null, shellCommandSafety: null, gitWriteGuard: null, gitWriteScope: null, toolOutputTruncation: { enabled: null, maxInlineBytes: null }, planFormatValidation: null, questionLabelHelper: { enabled: null, maxLabelChars: null }, todoDisciplineHelper: null },
44
44
  runtimeRecovery: { enabled: null, retryOnStatusCodes: [null], retryOnCodes: [null], fallbackRoutes: [route], maxFallbackAttempts: null, idleContinuation: { enabled: null, maxContinuations: null, prompt: null } },
45
45
  lsp: { enabled: null, serverName: null, command: null, args: [null], cwd: null, env: {}, toolCallTimeoutMs: null, failOnStartupError: null }
46
46
  };
package/lib/profiles.js CHANGED
@@ -308,9 +308,10 @@ function workflow(value, field) {
308
308
  }
309
309
  function guards(value, field) {
310
310
  const item = record(value, field);
311
- keys(item, ["scope", "shellCommandSafety", "gitWriteGuard", "toolOutputTruncation", "planFormatValidation", "questionLabelHelper", "todoDisciplineHelper"], field);
311
+ keys(item, ["scope", "shellCommandSafety", "gitWriteGuard", "gitWriteScope", "toolOutputTruncation", "planFormatValidation", "questionLabelHelper", "todoDisciplineHelper"], field);
312
312
  optional(item, "scope", (scope, path) => enumeration(scope, ["deepwork-or-dsmm-agent", "always", "off"], path), field);
313
313
  optional(item, "gitWriteGuard", (policy, path) => enumeration(policy, ["ask", "deny", "off"], path), field);
314
+ optional(item, "gitWriteScope", (scope, path) => enumeration(scope, ["all-writes", "high-risk"], path), field);
314
315
  for (const key of ["shellCommandSafety", "planFormatValidation", "todoDisciplineHelper"])
315
316
  optional(item, key, bool, field);
316
317
  optional(item, "toolOutputTruncation", (raw, path) => {
@@ -15,7 +15,7 @@ export function readPromptAsset(path) {
15
15
  }
16
16
  export const SOURCE_ROLE_CATALOG = JSON.parse(readPromptAsset("catalog.json"));
17
17
  export function buildRoleIdentity(role) {
18
- return `You are ${role.name} (role ID: ${role.id}).`;
18
+ return `You are ${role.name}.`;
19
19
  }
20
20
  export function splitCategory(text) {
21
21
  const calibrations = new Map();
@@ -25,6 +25,6 @@ export function splitCategory(text) {
25
25
  export function buildRolePersona(role) {
26
26
  const source = role.promptArtifact === null ? role.description : readPromptAsset(role.promptArtifact.replace("prompts/source/", ""));
27
27
  const body = role.kind === "category" ? splitCategory(source).base : source;
28
- return [buildRoleIdentity(role), readPromptAsset("shared/locale.md"), body, readPromptAsset("shared/dsh-host-contract.md"), readPromptAsset(role.terminalArtifact.replace("prompts/source/", ""))].filter(Boolean).join("\n\n---\n\n");
28
+ return [readPromptAsset("shared/locale.md"), body, readPromptAsset("shared/dsh-host-contract.md"), readPromptAsset(role.terminalArtifact.replace("prompts/source/", ""))].filter(Boolean).join("\n\n---\n\n");
29
29
  }
30
30
  //# sourceMappingURL=prompt-content.js.map
package/lib/settings.d.ts CHANGED
@@ -17,6 +17,7 @@ export type { DsmmSkillName, MvpSkillName } from "./skills.js";
17
17
  export type DsmmFinalReviewPolicy = "simple-oracle-complex-reviewer" | "reviewer-only" | "off";
18
18
  export type DsmmGuardScope = "deepwork-or-dsmm-agent" | "always" | "off";
19
19
  export type DsmmGitWritePolicy = "ask" | "deny" | "off";
20
+ export type DsmmGitWriteScope = "all-writes" | "high-risk";
20
21
  export type DsmmInvocationLevel = "normal" | "low" | "high" | "max";
21
22
  export type DsmmLevelOverride = {
22
23
  reasoningEffort: string;
@@ -50,6 +51,7 @@ export interface DsmmGuardSettings {
50
51
  scope: DsmmGuardScope;
51
52
  shellCommandSafety: boolean;
52
53
  gitWriteGuard: DsmmGitWritePolicy;
54
+ gitWriteScope: DsmmGitWriteScope;
53
55
  toolOutputTruncation: {
54
56
  enabled: boolean;
55
57
  maxInlineBytes: number;
package/lib/settings.js CHANGED
@@ -36,6 +36,7 @@ export const DEFAULT_DSMM_SETTINGS = {
36
36
  scope: "deepwork-or-dsmm-agent",
37
37
  shellCommandSafety: true,
38
38
  gitWriteGuard: "ask",
39
+ gitWriteScope: "all-writes",
39
40
  toolOutputTruncation: {
40
41
  enabled: true,
41
42
  maxInlineBytes: 12000
@@ -105,6 +106,8 @@ const ROLE_ROUTING_VALIDATION_SCHEMA = Schema.transform(Schema.any(), (input) =>
105
106
  rejectDeprecatedFields(input);
106
107
  if (Object.hasOwn(input, "locale"))
107
108
  validateLocale(input.locale);
109
+ if (isRoutingRecord(input.guards) && Object.hasOwn(input.guards, "gitWriteScope"))
110
+ validateShape(input.guards.gitWriteScope, GIT_WRITE_SCOPE_SCHEMA, ["guards", "gitWriteScope"]);
108
111
  if (isRoutingRecord(input.runtimeRecovery) && Array.isArray(input.runtimeRecovery.fallbackRoutes)) {
109
112
  for (const route of input.runtimeRecovery.fallbackRoutes) {
110
113
  normalizeExplicitRoute(route);
@@ -154,6 +157,10 @@ const GIT_WRITE_POLICY_SCHEMA = Schema.union([
154
157
  Schema.const("deny"),
155
158
  Schema.const("off")
156
159
  ]).default(DEFAULT_DSMM_SETTINGS.guards.gitWriteGuard);
160
+ const GIT_WRITE_SCOPE_SCHEMA = Schema.union([
161
+ Schema.const("all-writes"),
162
+ Schema.const("high-risk")
163
+ ]).default(DEFAULT_DSMM_SETTINGS.guards.gitWriteScope);
157
164
  const TOOL_OUTPUT_TRUNCATION_SCHEMA = Schema.object({
158
165
  enabled: Schema.boolean().default(DEFAULT_DSMM_SETTINGS.guards.toolOutputTruncation.enabled),
159
166
  maxInlineBytes: Schema.number().default(DEFAULT_DSMM_SETTINGS.guards.toolOutputTruncation.maxInlineBytes)
@@ -166,6 +173,7 @@ const GUARDS_SCHEMA = Schema.object({
166
173
  scope: GUARD_SCOPE_SCHEMA,
167
174
  shellCommandSafety: Schema.boolean().default(DEFAULT_DSMM_SETTINGS.guards.shellCommandSafety),
168
175
  gitWriteGuard: GIT_WRITE_POLICY_SCHEMA,
176
+ gitWriteScope: GIT_WRITE_SCOPE_SCHEMA,
169
177
  toolOutputTruncation: TOOL_OUTPUT_TRUNCATION_SCHEMA,
170
178
  planFormatValidation: Schema.boolean().default(DEFAULT_DSMM_SETTINGS.guards.planFormatValidation),
171
179
  questionLabelHelper: QUESTION_LABEL_HELPER_SCHEMA,
@@ -672,6 +680,8 @@ function resolveWorkflowSettings(config) {
672
680
  }
673
681
  export function resolveGuardSettings(config) {
674
682
  const defaults = DEFAULT_DSMM_SETTINGS.guards;
683
+ if (config !== undefined && Object.hasOwn(config, "gitWriteScope"))
684
+ validateShape(config.gitWriteScope, GIT_WRITE_SCOPE_SCHEMA, ["guards", "gitWriteScope"]);
675
685
  return {
676
686
  ...defaults,
677
687
  ...config,
@@ -12,6 +12,22 @@ export interface ParsedShellSegment {
12
12
  words: readonly string[];
13
13
  }
14
14
  export declare function parseShellCommand(input: string, dialect: ShellDialect): readonly ParsedShellSegment[];
15
+ export interface GitStaticContext {
16
+ /** Literal spelling, not a claim about executable identity or repository confinement. */
17
+ readonly executable: string;
18
+ readonly globalOptions: readonly string[];
19
+ readonly environment: readonly string[];
20
+ }
21
+ export interface GitCommandAction {
22
+ readonly ruleId: `git.${string}`;
23
+ readonly action: string;
24
+ readonly risk: "write" | "high-risk";
25
+ /** Callers must also bind actual cwd, dialect, Agent and tool registration. */
26
+ readonly reusable: boolean;
27
+ readonly context: GitStaticContext;
28
+ }
29
+ /** Pure, finite Git classification; this is not a shell AST or an authorization grant. */
30
+ export declare function evaluateGitCommand(input: string, dialect: ShellDialect): readonly GitCommandAction[];
15
31
  export declare function classifyKnownGitWrite(input: string, dialect: ShellDialect): string | undefined;
16
32
  export type ShellDialectViolation = "powershell-export" | "powershell-source" | "powershell-dev-null" | "posix-powershell-env";
17
33
  export declare function classifyShellDialectViolation(input: string, dialect: ShellDialect): ShellDialectViolation | undefined;