@dsmm/dsmm 0.3.10 → 0.3.12
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 +1 -1
- package/agent-presets/dsmm-builder/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-clarifier/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-code-search/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-coding/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-complex/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-creative/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-deep/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-doc-search/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-documenting/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-frontend/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-media-reader/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-normal-task/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-oracle/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-orchestrator/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-plan-critic/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-planner/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-quick/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-research/agent.cordis.yml +0 -4
- package/agent-presets/dsmm-reviewer/agent.cordis.yml +0 -4
- package/docs/agent-presets.md +5 -5
- package/docs/compatibility.md +10 -4
- package/docs/deferred-native-approval-risk.md +11 -1
- package/docs/design.md +15 -5
- package/docs/lsp.md +1 -1
- package/docs/model-routing.md +6 -6
- package/docs/native-permissions.md +5 -1
- package/docs/profiles.md +36 -5
- package/docs/roadmap.md +3 -3
- package/docs/runtime-recovery.md +5 -5
- package/docs/safety-guards.md +23 -5
- package/docs/settings-status.md +3 -3
- package/lib/child-capture.d.ts +9 -0
- package/lib/child-capture.js +29 -2
- package/lib/client/ProfilesSection.js +65 -13
- package/lib/client/RoleToolView-data.d.ts +4 -4
- package/lib/client/RoleToolView-data.js +3 -1
- package/lib/client/RoleToolView-locales.d.ts +7 -4
- package/lib/client/RoleToolView-locales.js +10 -6
- package/lib/client/RoleToolView.js +20 -5
- package/lib/client/SessionProfiles.d.ts +5 -1
- package/lib/client/SessionProfiles.js +13 -9
- package/lib/client/StructuredEditor.d.ts +32 -0
- package/lib/client/StructuredEditor.js +75 -23
- package/lib/client/controller.d.ts +10 -0
- package/lib/client/controller.js +44 -14
- package/lib/client/deployment-locales.js +1 -0
- package/lib/client/locales.d.ts +36 -0
- package/lib/client/locales.js +47 -17
- package/lib/client/permission-locales.js +8 -8
- package/lib/client/session-labels.js +4 -1
- package/lib/client/structured.d.ts +4 -0
- package/lib/client/structured.js +16 -1
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +19 -1
- package/lib/client.js +772 -312
- package/lib/command-approval.d.ts +50 -0
- package/lib/command-approval.js +148 -0
- package/lib/core-permissions.d.ts +2 -1
- package/lib/core-permissions.js +6 -3
- package/lib/guards.d.ts +2 -1
- package/lib/guards.js +45 -8
- package/lib/host-llm.js +3 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.js +5 -3
- package/lib/model-routing.d.ts +3 -2
- package/lib/model-routing.js +28 -7
- package/lib/native-admission.d.ts +2 -0
- package/lib/native-admission.js +106 -34
- package/lib/permission-control.d.ts +5 -2
- package/lib/permission-control.js +46 -24
- package/lib/permission-controller.d.ts +2 -0
- package/lib/permission-controller.js +13 -8
- package/lib/permission-native-command.d.ts +2 -0
- package/lib/permission-native-command.js +9 -4
- package/lib/permission-native-rules.d.ts +2 -2
- package/lib/permission-native-rules.js +12 -10
- package/lib/profile-diagnostics.js +1 -1
- package/lib/profile-runtime.d.ts +11 -0
- package/lib/profile-runtime.js +48 -13
- package/lib/profile-store.d.ts +4 -1
- package/lib/profile-store.js +37 -14
- package/lib/profiles.js +2 -1
- package/lib/prompt-content.js +2 -2
- package/lib/role-control-rpc.js +18 -5
- package/lib/role-llm-runtime.js +10 -1
- package/lib/role-policy.d.ts +4 -3
- package/lib/role-policy.js +6 -6
- package/lib/role-providers.js +1 -0
- package/lib/runtime-recovery.d.ts +2 -2
- package/lib/runtime-recovery.js +7 -4
- package/lib/settings.d.ts +2 -0
- package/lib/settings.js +10 -0
- package/lib/shell-command.d.ts +16 -0
- package/lib/shell-command.js +443 -119
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { PreToolDecision, ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
type Approval = Context["approval"];
|
|
5
|
+
type Outcome = Awaited<ReturnType<Approval["request"]>>;
|
|
6
|
+
/** A matcher supplies the whole rule semantics, not a command/reason-derived permission. */
|
|
7
|
+
export interface CommandRuleContribution {
|
|
8
|
+
readonly kind: "git" | "shell" | "native-command";
|
|
9
|
+
readonly semantics: unknown;
|
|
10
|
+
readonly reusable?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface CommandApprovalScope {
|
|
13
|
+
/** Managed entry points commit only after their stronger final integrity check. */
|
|
14
|
+
readonly deferredCommit?: boolean;
|
|
15
|
+
readonly source?: object;
|
|
16
|
+
sourceCurrent?(): object;
|
|
17
|
+
readonly owner?: object;
|
|
18
|
+
readonly ownerGeneration?: string | number;
|
|
19
|
+
readonly realm?: object;
|
|
20
|
+
assertCurrent?(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface CommandApprovalBinding {
|
|
23
|
+
readonly missing: readonly CommandRuleContribution[];
|
|
24
|
+
readonly signal: AbortSignal;
|
|
25
|
+
assertCurrent(): void;
|
|
26
|
+
/** Only the caller awaiting its own complete service request may supply this outcome. */
|
|
27
|
+
resolved(outcome: Outcome): void;
|
|
28
|
+
}
|
|
29
|
+
/** Core-owned memory. Invocation records never serve as reusable native target grants. */
|
|
30
|
+
export declare class CommandApprovals {
|
|
31
|
+
private readonly ctx;
|
|
32
|
+
private memory;
|
|
33
|
+
private invocations;
|
|
34
|
+
private readonly retiredAgents;
|
|
35
|
+
private generation;
|
|
36
|
+
private readonly lifetime;
|
|
37
|
+
constructor(ctx: Context);
|
|
38
|
+
capture(exec: Readonly<ToolExecution>, contributions: readonly CommandRuleContribution[], scope?: CommandApprovalScope): CommandApprovalBinding | undefined;
|
|
39
|
+
/** Generic guard-owned request, including no-target calls and independent downstream asks. */
|
|
40
|
+
decide(exec: Readonly<ToolExecution>, binding: CommandApprovalBinding | undefined, next: () => Promise<PreToolDecision>, reason: string): Promise<PreToolDecision>;
|
|
41
|
+
check(exec: Readonly<ToolExecution>): void;
|
|
42
|
+
commit(exec: Readonly<ToolExecution>, includeDeferred?: boolean): void;
|
|
43
|
+
guard(exec: Readonly<ToolExecution>): string | undefined;
|
|
44
|
+
finish(exec: Readonly<ToolExecution>): void;
|
|
45
|
+
invalidate(): void;
|
|
46
|
+
revokeAgent(agent: Agent): void;
|
|
47
|
+
retire(): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=command-approval.d.ts.map
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
3
|
+
import { PermissionRefusal } from "./permission-errors.js";
|
|
4
|
+
const original = (value) => Reflect.get(value, symbols.original) ?? value;
|
|
5
|
+
/** Core-owned memory. Invocation records never serve as reusable native target grants. */
|
|
6
|
+
export class CommandApprovals {
|
|
7
|
+
ctx;
|
|
8
|
+
memory = new WeakMap();
|
|
9
|
+
invocations = new WeakMap();
|
|
10
|
+
retiredAgents = new WeakSet();
|
|
11
|
+
generation = {};
|
|
12
|
+
lifetime = new AbortController();
|
|
13
|
+
constructor(ctx) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
ctx.inject(["tools"], scope => { scope.tools.guard(exec => this.guard(exec)); });
|
|
16
|
+
ctx.on("tools/execute", async (exec, next) => { this.commit(exec, false); return next(); }, { global: true, prepend: true });
|
|
17
|
+
ctx.on("tools/result", exec => { this.finish(exec); }, { global: true });
|
|
18
|
+
ctx.on("agent/disposed", ({ agent }) => { this.revokeAgent(agent); }, { global: true });
|
|
19
|
+
ctx.effect(() => () => this.retire());
|
|
20
|
+
}
|
|
21
|
+
capture(exec, contributions, scope = {}) {
|
|
22
|
+
const agent = exec.agent;
|
|
23
|
+
if (agent === undefined || this.retiredAgents.has(agent))
|
|
24
|
+
return undefined;
|
|
25
|
+
const resolveTools = () => agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools");
|
|
26
|
+
const tools = resolveTools(), definition = tools?.get(exec.name, agent), registry = agent.ctx.get("agents");
|
|
27
|
+
if (tools === undefined || definition === undefined || registry === undefined || registry.get(agent.id) !== agent)
|
|
28
|
+
return undefined;
|
|
29
|
+
const session = agent.session, workspace = session.header.cwd, context = agent.ctx, token = exec.token, args = exec.arguments;
|
|
30
|
+
const values = structuredClone(args), name = exec.name, callId = exec.callId;
|
|
31
|
+
const owner = scope.owner ?? this, realm = scope.realm ?? context, generation = this.generation;
|
|
32
|
+
const signal = AbortSignal.any([exec.signal, this.lifetime.signal]);
|
|
33
|
+
const rules = contributions.map(rule => ({ ...rule, semantics: structuredClone(rule.semantics) }));
|
|
34
|
+
let approved = false;
|
|
35
|
+
const assertCurrent = () => {
|
|
36
|
+
const currentTools = resolveTools(), currentRegistry = agent.ctx.get("agents");
|
|
37
|
+
if (signal.aborted || exec.signal.aborted || this.retiredAgents.has(agent))
|
|
38
|
+
throw new PermissionRefusal("cancelled");
|
|
39
|
+
if (agent.session !== session || agent.ctx !== context
|
|
40
|
+
|| currentTools === undefined || original(currentTools) !== original(tools) || currentTools.get(name, agent) !== definition
|
|
41
|
+
|| currentRegistry === undefined || original(currentRegistry) !== original(registry) || currentRegistry.get(agent.id) !== agent) {
|
|
42
|
+
this.memory.delete(agent);
|
|
43
|
+
throw new PermissionRefusal("stale");
|
|
44
|
+
}
|
|
45
|
+
if (exec.token !== token || exec.arguments !== args || !isDeepStrictEqual(exec.arguments, values)
|
|
46
|
+
|| exec.agent !== agent || exec.name !== name || exec.callId !== callId || session.header.cwd !== workspace)
|
|
47
|
+
throw new PermissionRefusal("stale");
|
|
48
|
+
try {
|
|
49
|
+
scope.assertCurrent?.();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.memory.delete(agent);
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const sourceCurrent = () => {
|
|
57
|
+
try {
|
|
58
|
+
return generation === this.generation && (scope.sourceCurrent === undefined || scope.sourceCurrent() === scope.source);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const policyAllows = () => {
|
|
65
|
+
const approval = this.ctx.get("approval");
|
|
66
|
+
return approval !== undefined && (approval.overrideOf(session) ?? approval.config.policy ?? "ask") !== "never";
|
|
67
|
+
};
|
|
68
|
+
const previous = this.memory.get(agent);
|
|
69
|
+
if (previous !== undefined && previous.session !== session)
|
|
70
|
+
this.memory.delete(agent);
|
|
71
|
+
const remembered = previous?.session === session ? previous.rules : [];
|
|
72
|
+
const missing = rules.filter(rule => rule.reusable === false || !sourceCurrent() || !policyAllows() || !remembered.some(item => item.tools === original(tools) && item.definition === definition && item.source === scope.source && item.owner === owner
|
|
73
|
+
&& item.ownerGeneration === scope.ownerGeneration && item.realm === realm && isDeepStrictEqual(item.rule, rule)));
|
|
74
|
+
const binding = {
|
|
75
|
+
missing, signal, assertCurrent, deferredCommit: scope.deferredCommit === true,
|
|
76
|
+
resolved: outcome => { assertCurrent(); approved = outcome === "allowed-once"; },
|
|
77
|
+
commit: () => {
|
|
78
|
+
assertCurrent();
|
|
79
|
+
if (!approved || !sourceCurrent() || !policyAllows())
|
|
80
|
+
return;
|
|
81
|
+
approved = false;
|
|
82
|
+
let state = this.memory.get(agent);
|
|
83
|
+
if (state?.session !== session) {
|
|
84
|
+
state = { session, rules: [] };
|
|
85
|
+
this.memory.set(agent, state);
|
|
86
|
+
}
|
|
87
|
+
for (const rule of missing) {
|
|
88
|
+
if (rule.reusable === false)
|
|
89
|
+
continue;
|
|
90
|
+
const item = { rule, tools: original(tools), definition, source: scope.source, owner, ownerGeneration: scope.ownerGeneration, realm };
|
|
91
|
+
if (!state.rules.some(previous => previous.tools === item.tools && previous.definition === definition && previous.source === item.source
|
|
92
|
+
&& previous.owner === owner && previous.ownerGeneration === item.ownerGeneration && previous.realm === realm && isDeepStrictEqual(previous.rule, rule)))
|
|
93
|
+
state.rules.push(item);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
assertCurrent();
|
|
98
|
+
const bindings = this.invocations.get(exec) ?? [];
|
|
99
|
+
bindings.push(binding);
|
|
100
|
+
this.invocations.set(exec, bindings);
|
|
101
|
+
return binding;
|
|
102
|
+
}
|
|
103
|
+
/** Generic guard-owned request, including no-target calls and independent downstream asks. */
|
|
104
|
+
async decide(exec, binding, next, reason) {
|
|
105
|
+
const downstream = await next();
|
|
106
|
+
if (exec.signal.aborted || binding?.signal.aborted)
|
|
107
|
+
return { kind: "cancel" };
|
|
108
|
+
binding?.assertCurrent();
|
|
109
|
+
if (downstream.kind === "deny" || downstream.kind === "cancel" || binding?.missing.length === 0)
|
|
110
|
+
return downstream;
|
|
111
|
+
const combined = [downstream.kind === "ask" ? downstream.reason : undefined, reason].filter(Boolean).join("\n");
|
|
112
|
+
if (binding === undefined)
|
|
113
|
+
return downstream.kind === "allow" ? { kind: "ask", reason: combined } : downstream;
|
|
114
|
+
const approval = this.ctx.get("approval");
|
|
115
|
+
if (approval === undefined || exec.agent === undefined)
|
|
116
|
+
return { kind: "deny", reason: "Command approval is unavailable." };
|
|
117
|
+
const displayReason = Object.freeze({ en: combined, zh: combined,
|
|
118
|
+
...downstream.kind === "ask" && downstream.displayReason !== undefined
|
|
119
|
+
? Object.fromEntries(Object.entries(downstream.displayReason).map(([locale, text]) => [locale, `${text}\n${reason}`])) : {} });
|
|
120
|
+
const outcome = await approval.request({ agent: exec.agent, callId: exec.callId, toolName: exec.name, signal: binding.signal, reason: combined, displayReason });
|
|
121
|
+
if (exec.signal.aborted || binding.signal.aborted)
|
|
122
|
+
return { kind: "cancel" };
|
|
123
|
+
binding.resolved(outcome);
|
|
124
|
+
return outcome === "allowed-once" ? { kind: "allow" } : { kind: outcome === "cancelled" ? "cancel" : "deny", reason: "Command approval was not granted." };
|
|
125
|
+
}
|
|
126
|
+
check(exec) { for (const binding of this.invocations.get(exec) ?? [])
|
|
127
|
+
binding.assertCurrent(); }
|
|
128
|
+
commit(exec, includeDeferred = true) {
|
|
129
|
+
this.check(exec);
|
|
130
|
+
for (const binding of this.invocations.get(exec) ?? [])
|
|
131
|
+
if (includeDeferred || !binding.deferredCommit)
|
|
132
|
+
binding.commit();
|
|
133
|
+
}
|
|
134
|
+
guard(exec) {
|
|
135
|
+
try {
|
|
136
|
+
this.check(exec);
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return "Command execution identity is no longer current.";
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
finish(exec) { this.invocations.delete(exec); }
|
|
144
|
+
invalidate() { this.generation = {}; this.memory = new WeakMap(); }
|
|
145
|
+
revokeAgent(agent) { this.retiredAgents.add(agent); this.memory.delete(agent); }
|
|
146
|
+
retire() { this.lifetime.abort(); this.invalidate(); }
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=command-approval.js.map
|
|
@@ -3,6 +3,7 @@ import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
|
3
3
|
import type { DsmmDeploymentConfig } from "./deployment-config.js";
|
|
4
4
|
import type { PermissionControlCollaborators } from "./permission-control.js";
|
|
5
5
|
import type { DsmmPermissionController } from "./permission-controller.js";
|
|
6
|
+
import type { CommandApprovals } from "./command-approval.js";
|
|
6
7
|
/** The native Core fiber owns one source backend, execution controller and RPC service. */
|
|
7
|
-
export declare function installCorePermissions(ctx: Context, deployment: DsmmDeploymentConfig, authority: PermissionControlCollaborators, assertWritable: (root: Agent) => void): DsmmPermissionController;
|
|
8
|
+
export declare function installCorePermissions(ctx: Context, deployment: DsmmDeploymentConfig, authority: PermissionControlCollaborators, assertWritable: (root: Agent) => void, commandApprovals?: CommandApprovals): DsmmPermissionController;
|
|
8
9
|
//# sourceMappingURL=core-permissions.d.ts.map
|
package/lib/core-permissions.js
CHANGED
|
@@ -3,11 +3,14 @@ import { PermissionRefusal, permissionOriginal } from "./permission-control.js";
|
|
|
3
3
|
import { installPermissionController } from "./permission-controller.js";
|
|
4
4
|
import { registerPermissionControlRpc } from "./permission-rpc.js";
|
|
5
5
|
/** The native Core fiber owns one source backend, execution controller and RPC service. */
|
|
6
|
-
export function installCorePermissions(ctx, deployment, authority, assertWritable) {
|
|
6
|
+
export function installCorePermissions(ctx, deployment, authority, assertWritable, commandApprovals) {
|
|
7
7
|
let controller;
|
|
8
8
|
const backend = installDeploymentPermissionRules(ctx, {
|
|
9
9
|
deployment, assertWritable,
|
|
10
|
-
revoke: () => {
|
|
10
|
+
revoke: () => { if (controller === undefined)
|
|
11
|
+
commandApprovals?.invalidate();
|
|
12
|
+
else
|
|
13
|
+
controller.permissions.revokePolicy(); },
|
|
11
14
|
notify: async () => {
|
|
12
15
|
const current = ctx.get("dsmmPermissionController");
|
|
13
16
|
if (controller === undefined || current === undefined || permissionOriginal(current) !== permissionOriginal(controller)
|
|
@@ -16,7 +19,7 @@ export function installCorePermissions(ctx, deployment, authority, assertWritabl
|
|
|
16
19
|
},
|
|
17
20
|
});
|
|
18
21
|
controller = installPermissionController(ctx, {
|
|
19
|
-
authority, rules: backend.runtime,
|
|
22
|
+
authority, rules: backend.runtime, commandApprovals,
|
|
20
23
|
// The public ShellExecutor has no executable/environment resolution proof.
|
|
21
24
|
// This identity never grants read trust or filesystem colocation.
|
|
22
25
|
shellIdentity: (_scope, kind) => Object.freeze({ executable: `unresolved-native-${kind}`,
|
package/lib/guards.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import type { DshContext, DshPostToolDecision, DshPreToolDecision, DshToolExecut
|
|
|
2
2
|
import type { DsmmSettings, DsmmSettingsGetter } from "./settings.js";
|
|
3
3
|
import type { DeepworkModeController } from "./state.js";
|
|
4
4
|
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
5
|
+
import type { CommandApprovals } from "./command-approval.js";
|
|
5
6
|
export declare const DSMM_GUARD_PREFIX = "[dsmm safety]";
|
|
6
7
|
export declare function truncateTextMiddle(text: string, maxBytes: number, toolName: string): string;
|
|
7
8
|
export declare function isSafetyScopeActive(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): boolean;
|
|
8
9
|
export declare function decidePreToolExecution(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController, nativeFullAccess?: boolean, simple?: boolean): DshPreToolDecision | undefined;
|
|
9
10
|
export declare function decidePostToolExecution(exec: DshToolExecution, result: Readonly<DshToolExecutionResult>, decision: DshPostToolDecision, settings: DsmmSettings, controller: DeepworkModeController): DshPostToolDecision;
|
|
10
|
-
export declare function registerSafetyGuards(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, rolePolicy?: DsmmRolePolicy): void;
|
|
11
|
+
export declare function registerSafetyGuards(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, rolePolicy?: DsmmRolePolicy, commandApprovals?: CommandApprovals): void;
|
|
11
12
|
//# sourceMappingURL=guards.d.ts.map
|
package/lib/guards.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isDsmmRoleId } from "./roles.js";
|
|
2
2
|
import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
3
3
|
import { validatePlanMutation } from "./plan-validation.js";
|
|
4
|
-
import {
|
|
4
|
+
import { evaluateGitCommand, classifyShellDialectViolation } from "./shell-command.js";
|
|
5
|
+
import { isAbsolute, resolve } from "node:path";
|
|
6
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
7
|
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
6
8
|
import { Context } from "@deepseek-ai/cordis";
|
|
7
9
|
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
@@ -118,25 +120,43 @@ function shellDialectViolationDecision(violation) {
|
|
|
118
120
|
reason: `${DSMM_GUARD_PREFIX} bash command appears to use PowerShell syntax (\`$env:\`). Use POSIX environment syntax for bash.`
|
|
119
121
|
};
|
|
120
122
|
}
|
|
121
|
-
function
|
|
123
|
+
function gitActions(exec, settings) {
|
|
122
124
|
if (settings.guards.gitWriteGuard === "off")
|
|
123
|
-
return
|
|
125
|
+
return [];
|
|
124
126
|
const command = commandText(exec);
|
|
125
127
|
const dialect = shellDialect(exec);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
return command === undefined || dialect === undefined ? [] : evaluateGitCommand(command, dialect)
|
|
129
|
+
.filter(action => settings.guards.gitWriteScope !== "high-risk" || action.risk === "high-risk");
|
|
130
|
+
}
|
|
131
|
+
function gitRuleReason(actions) {
|
|
132
|
+
return actions.map(({ action, ruleId }) => `git ${action === "reset.hard" ? "reset --hard" : action.replaceAll(".", " ")} [${ruleId}]`).join(", ");
|
|
133
|
+
}
|
|
134
|
+
function commandWorkingDirectory(exec) {
|
|
135
|
+
const workspace = exec.agent?.session.header?.cwd, workdir = asRecord(exec.arguments)?.workdir;
|
|
136
|
+
return typeof workspace === "string" && isAbsolute(workspace) && (workdir === undefined || typeof workdir === "string")
|
|
137
|
+
? resolve(workspace, workdir ?? ".") : undefined;
|
|
138
|
+
}
|
|
139
|
+
function gitContributions(exec, actions) {
|
|
140
|
+
const cwd = commandWorkingDirectory(exec);
|
|
141
|
+
const dialect = shellDialect(exec);
|
|
142
|
+
return actions.map(action => ({ kind: "git", reusable: action.reusable && cwd !== undefined,
|
|
143
|
+
semantics: { ruleId: action.ruleId, risk: action.risk, context: action.context, cwd, dialect } }));
|
|
144
|
+
}
|
|
145
|
+
function gitWriteDecision(exec, settings, simple = false) {
|
|
146
|
+
const actions = gitActions(exec, settings);
|
|
147
|
+
if (actions.length === 0)
|
|
128
148
|
return undefined;
|
|
129
149
|
if (settings.guards.gitWriteGuard === "deny") {
|
|
130
150
|
return {
|
|
131
151
|
kind: "deny",
|
|
132
|
-
reason: `${DSMM_GUARD_PREFIX} git write command is disabled by dsmm settings:
|
|
152
|
+
reason: `${DSMM_GUARD_PREFIX} git write command is disabled by dsmm settings: ${gitRuleReason(actions)}`
|
|
133
153
|
};
|
|
134
154
|
}
|
|
135
155
|
if (simple)
|
|
136
156
|
return undefined;
|
|
137
157
|
return {
|
|
138
158
|
kind: "ask",
|
|
139
|
-
reason: `${DSMM_GUARD_PREFIX} git write command requires explicit user approval before running:
|
|
159
|
+
reason: `${DSMM_GUARD_PREFIX} git write command requires explicit user approval before running: ${gitRuleReason(actions)}`
|
|
140
160
|
};
|
|
141
161
|
}
|
|
142
162
|
function questionLabelDecision(exec, settings) {
|
|
@@ -236,8 +256,18 @@ export function decidePostToolExecution(exec, result, decision, settings, contro
|
|
|
236
256
|
content: [{ type: "text", text: truncateTextMiddle(text, truncation.maxInlineBytes, exec.name) }]
|
|
237
257
|
};
|
|
238
258
|
}
|
|
239
|
-
export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
259
|
+
export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy, commandApprovals) {
|
|
240
260
|
const truncationLimits = new WeakMap();
|
|
261
|
+
const sources = new WeakMap();
|
|
262
|
+
const sourceFor = (agent, settings = getSettings(agent)) => {
|
|
263
|
+
const value = getSettings.admission?.(agent) ?? settings;
|
|
264
|
+
let source = sources.get(agent);
|
|
265
|
+
if (source?.value !== value) {
|
|
266
|
+
source = { value, generation: {} };
|
|
267
|
+
sources.set(agent, source);
|
|
268
|
+
}
|
|
269
|
+
return source.generation;
|
|
270
|
+
};
|
|
241
271
|
const tools = ctx.get?.("tools");
|
|
242
272
|
if (rolePolicy !== undefined && tools !== undefined) {
|
|
243
273
|
const guard = tools.guard((execution) => execution.agent === undefined ? undefined : rolePolicy.toolDenial(execution.agent, execution.name, tools, execution));
|
|
@@ -260,6 +290,7 @@ export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
|
260
290
|
throw error;
|
|
261
291
|
}
|
|
262
292
|
const simple = Context.is(ctx) && await ctx.get("dsmmPermissionController")?.simpleCommandAllowed(execution) === true;
|
|
293
|
+
const source = commandApprovals === undefined || full || simple || exec.agent === undefined ? undefined : sourceFor(exec.agent, settings);
|
|
263
294
|
const decision = decidePreToolExecution(exec, settings, controller, full, simple);
|
|
264
295
|
if (!full && settings.modules.deepwork.enabled && settings.guards.toolOutputTruncation.enabled && isSafetyScopeActive(exec, settings, controller))
|
|
265
296
|
truncationLimits.set(exec, settings.guards.toolOutputTruncation.maxInlineBytes);
|
|
@@ -267,6 +298,12 @@ export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
|
267
298
|
return next();
|
|
268
299
|
if (decision.kind === "deny")
|
|
269
300
|
return decision;
|
|
301
|
+
if (commandApprovals !== undefined && decision.kind === "ask") {
|
|
302
|
+
const actions = gitActions(exec, settings), contributions = gitContributions(exec, actions);
|
|
303
|
+
const binding = commandApprovals.capture(execution, contributions, { source, sourceCurrent: exec.agent === undefined ? undefined : () => sourceFor(exec.agent) });
|
|
304
|
+
const missing = binding === undefined ? actions : actions.filter((_action, index) => binding.missing.some(rule => isDeepStrictEqual(rule, contributions[index])));
|
|
305
|
+
return commandApprovals.decide(execution, binding, next, `${DSMM_GUARD_PREFIX} git write command requires explicit user approval before running: ${gitRuleReason(missing)}\nCommand: ${commandText(exec)}\nWorking directory: ${commandWorkingDirectory(exec) ?? "unresolved"}`);
|
|
306
|
+
}
|
|
270
307
|
const downstream = await next();
|
|
271
308
|
return downstream.kind === "allow" ? decision : downstream;
|
|
272
309
|
}, { prepend: true });
|
package/lib/host-llm.js
CHANGED
|
@@ -6,13 +6,13 @@ import { copyRouteJson } from "./route-json.js";
|
|
|
6
6
|
import { modelRouteFromCall } from "./role-llm.js";
|
|
7
7
|
import { classifyDsmmAgent } from "./runtime-integration.js";
|
|
8
8
|
import { latestNativeModelSelection } from "./role-routing.js";
|
|
9
|
-
import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
10
9
|
import { capturedRoleInvocation } from "./role-invocation.js";
|
|
11
10
|
export function captureDsmmEffortSource(agent) {
|
|
12
11
|
const current = agent;
|
|
13
12
|
const invocation = capturedRoleInvocation(current);
|
|
14
|
-
if (latestNativeModelSelection(current) !== undefined
|
|
15
|
-
|
|
13
|
+
if (latestNativeModelSelection(current) !== undefined)
|
|
14
|
+
return "native";
|
|
15
|
+
if (agent.session.header.origin !== "subagent")
|
|
16
16
|
return "native";
|
|
17
17
|
return invocation?.effortSource ?? (invocation?.routeSource === "inherited" ? "native" : "dsmm-config");
|
|
18
18
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from
|
|
|
23
23
|
export type { DsmmStatusSnapshot } from "./status.js";
|
|
24
24
|
export type * from "./dsh-types.js";
|
|
25
25
|
export { DSMM_SKILL_NAMES, DSMM_SETTINGS_SCHEMA, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, deploymentEditorSchema, isRoleEnabled, resolveConfig, resolveDeployment, resolveRoleRouting, registerSettings, validateNativeConfig } from "./settings.js";
|
|
26
|
-
export type { DsmmFinalReviewPolicy, DsmmGitWritePolicy, DsmmGuardScope, DsmmGuardSettings, DsmmPluginConfig, DsmmNativeConfig, DsmmModelRoute, DsmmRoleRoutingConfig, DsmmRoleRouting, DsmmRecoveryRoute, DsmmRuntimeRecoverySettings, DsmmSettings, DsmmSettingsGetter, DsmmSkillName, DsmmWorkflowSettings, MvpSkillName, DsmmSubagentSettings, DsmmDeploymentSnapshot } from "./settings.js";
|
|
26
|
+
export type { DsmmFinalReviewPolicy, DsmmGitWritePolicy, DsmmGitWriteScope, DsmmGuardScope, DsmmGuardSettings, DsmmPluginConfig, DsmmNativeConfig, DsmmModelRoute, DsmmRoleRoutingConfig, DsmmRoleRouting, DsmmRecoveryRoute, DsmmRuntimeRecoverySettings, DsmmSettings, DsmmSettingsGetter, DsmmSkillName, DsmmWorkflowSettings, MvpSkillName, DsmmSubagentSettings, DsmmDeploymentSnapshot } from "./settings.js";
|
|
27
27
|
export { createProfileRuntime, DsmmProfileRuntime } from "./profile-runtime.js";
|
|
28
28
|
export type { DsmmProfileRuntimeStore, DsmmProfileRuntimeOptions } from "./profile-runtime.js";
|
|
29
29
|
export { resolveDshHome } from "./dsh-home.js";
|
package/lib/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { scopeLifetime } from "./lifetime.js";
|
|
|
18
18
|
import { runtimeAdmissionView, assertSupportedHostStartup } from "./runtime-integration.js";
|
|
19
19
|
import { createCorePermissionAuthority } from "./core-permission-authority.js";
|
|
20
20
|
import { installCorePermissions } from "./core-permissions.js";
|
|
21
|
+
import { CommandApprovals } from "./command-approval.js";
|
|
21
22
|
import { registerRoleControlRpc } from "./role-control-rpc.js";
|
|
22
23
|
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
23
24
|
import { DsmmProfileError } from "./profiles.js";
|
|
@@ -56,6 +57,7 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
56
57
|
const ctx = input;
|
|
57
58
|
const deployment = new DsmmDeploymentConfig(ctx, config);
|
|
58
59
|
const lifetime = new AbortController();
|
|
60
|
+
const commandApprovals = new CommandApprovals(ctx);
|
|
59
61
|
scopeLifetime(ctx, "dsmm: retire Core", () => lifetime.abort());
|
|
60
62
|
let admission;
|
|
61
63
|
const assert = (agent) => { lifetime.signal.throwIfAborted(); if (!admission)
|
|
@@ -144,8 +146,8 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
144
146
|
await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
|
|
145
147
|
return;
|
|
146
148
|
}
|
|
147
|
-
registerModelRouting(scope, controller, candidate);
|
|
148
|
-
registerSafetyGuards(scope, controller, candidate, policy);
|
|
149
|
+
registerModelRouting(scope, controller, candidate, agent);
|
|
150
|
+
registerSafetyGuards(scope, controller, candidate, policy, commandApprovals);
|
|
149
151
|
if (startup.settings.modules.deepwork.enabled) {
|
|
150
152
|
if (ctx.get("subagents") !== undefined)
|
|
151
153
|
await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
|
|
@@ -160,7 +162,7 @@ export async function apply(input, config = {}, startupOptions = {}) {
|
|
|
160
162
|
ctx.inject(["typert"], scope => { registerConfigRpc(scope, deployment, startup.settings, () => profiles, startup.sources, mountedPermission); new DsmmProfilesHost(scope, profiles); registerRoleControlRpc(scope, nativeAdmission); });
|
|
161
163
|
const permissions = createCorePermissionAuthority(ctx, { getSettings, rolePolicy: policy, signal: lifetime.signal });
|
|
162
164
|
const installPermissions = () => ctx.inject(["tools", ...(ctx.fiber.entry === undefined ? [] : ["settings"])], scope => {
|
|
163
|
-
const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable);
|
|
165
|
+
const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable, commandApprovals);
|
|
164
166
|
const identity = Reflect.get(installed, symbols.original) ?? installed;
|
|
165
167
|
scopeLifetime(scope, "dsmm: release permission projection", () => { if (permissionOwner === identity)
|
|
166
168
|
permissionOwner = undefined; }, () => { permissionOwner = identity; });
|
package/lib/model-routing.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { DshContext } from "./dsh-types.js";
|
|
1
|
+
import type { AgentRequestFrame, DshLlmCallConfig, DshAgent, DshContext } from "./dsh-types.js";
|
|
2
2
|
import type { DsmmSettingsGetter } from "./settings.js";
|
|
3
3
|
import type { DeepworkModeController } from "./state.js";
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function prepareDsmmRequest(frame: AgentRequestFrame, proposal: DshLlmCallConfig, assertCurrent: () => void): Promise<DshLlmCallConfig>;
|
|
5
|
+
export declare function registerModelRouting(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, agent?: DshAgent): void;
|
|
5
6
|
//# sourceMappingURL=model-routing.d.ts.map
|
package/lib/model-routing.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
1
2
|
import { applyModelRoute, clearRoleRouteLock, effectiveRoleFallbackRoutes, establishRolePolicy, latestNativeModelSelection, nativeModelSelectionWasAccepted, orderedModelRoutes, persistedRoleRoute, pinRoleRoute, roleRouteLock, selectInitialModelRoute, sameExactModelRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
|
|
2
3
|
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
3
4
|
import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
|
|
@@ -6,7 +7,14 @@ import { capturedRoleInvocation } from "./role-invocation.js";
|
|
|
6
7
|
import { modelRouteFromCall } from "./role-llm.js";
|
|
7
8
|
import { configuredModelParameterPolicy, resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
8
9
|
import { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
9
|
-
|
|
10
|
+
const preparations = new WeakMap();
|
|
11
|
+
export async function prepareDsmmRequest(frame, proposal, assertCurrent) {
|
|
12
|
+
const prepare = preparations.get(frame.agent);
|
|
13
|
+
if (!prepare)
|
|
14
|
+
throw new Error("Admitted Agent has no request preparation binding");
|
|
15
|
+
return prepare(frame, proposal, assertCurrent);
|
|
16
|
+
}
|
|
17
|
+
export function registerModelRouting(ctx, controller, getSettings, agent) {
|
|
10
18
|
const installedContexts = new WeakSet();
|
|
11
19
|
const install = (readyCtx) => {
|
|
12
20
|
if (installedContexts.has(readyCtx) || readyCtx.on === undefined)
|
|
@@ -16,16 +24,19 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
16
24
|
const assembledSelections = new WeakMap();
|
|
17
25
|
let dispose, disposeAgent, disposeAssembly;
|
|
18
26
|
try {
|
|
19
|
-
|
|
27
|
+
const owned = agent !== undefined && readyCtx.get?.("llm") instanceof DsmmAwareLlmRuntime;
|
|
28
|
+
let recovery;
|
|
29
|
+
registerRuntimeRecovery(readyCtx, controller, getSettings, owned ? prepare => { recovery = prepare; } : undefined);
|
|
20
30
|
disposeAssembly = readyCtx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
|
21
31
|
if (context.agent !== undefined && context.signal !== undefined)
|
|
22
32
|
assembledSelections.set(context.agent, { signal: context.signal, intent: latestNativeModelSelection(context.agent) });
|
|
23
33
|
return next();
|
|
24
34
|
}, { prepend: true });
|
|
25
|
-
|
|
26
|
-
const downstream = await
|
|
35
|
+
const prepare = async (frame, proposal, assertCurrent = () => frame.signal.throwIfAborted()) => {
|
|
36
|
+
const downstream = recovery === undefined ? proposal : await recovery(frame, proposal);
|
|
27
37
|
if (frame.signal.aborted)
|
|
28
38
|
return downstream;
|
|
39
|
+
assertCurrent();
|
|
29
40
|
const settings = getSettings(frame.agent), admission = getSettings.admission?.(frame.agent);
|
|
30
41
|
const parameterPolicy = admission === undefined ? configuredModelParameterPolicy(settings) : resolvedModelParameterPolicy(admission);
|
|
31
42
|
if (!settings.modules.deepwork.enabled)
|
|
@@ -37,6 +48,7 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
37
48
|
const invocation = capturedRoleInvocation(frame.agent);
|
|
38
49
|
const primary = invocation?.initialRoute ?? policy?.primary;
|
|
39
50
|
const identity = await establishRolePolicy(frame, settings, role, readyCtx, admission?.epoch);
|
|
51
|
+
assertCurrent();
|
|
40
52
|
frame.signal.throwIfAborted();
|
|
41
53
|
const fallbacks = effectiveRoleFallbackRoutes(settings, role);
|
|
42
54
|
const currentStep = isCurrentRecoveryStep(ordinaryRoot ? sessionEvents(frame.agent.session) : childOwnedSessionEvents(frame.agent.session), frame.turn, frame.step);
|
|
@@ -59,9 +71,10 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
59
71
|
return downstream;
|
|
60
72
|
}
|
|
61
73
|
const llm = frame.agent.ctx?.get?.("llm") ?? readyCtx.get?.("llm") ?? readyCtx.llm;
|
|
74
|
+
const assembledManual = manual !== undefined && sameModelRoute(downstream, manual.route) && downstream.reasoningEffort === manual.route.reasoningEffort;
|
|
62
75
|
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
63
|
-
&& (
|
|
64
|
-
const selected = modelRouteFromCall(downstream);
|
|
76
|
+
&& (assembledManual || nativeModelSelectionWasAccepted(frame.agent, manual))) {
|
|
77
|
+
const selected = assembledManual ? modelRouteFromCall(downstream) : manual.route;
|
|
65
78
|
const generation = (lock?.generation ?? -1) + 1;
|
|
66
79
|
lock = pinRoleRoute(frame.agent, identity, selected, [selected, ...fallbacks], { preserveCandidates: parameterPolicy.mode === "native-defaults" });
|
|
67
80
|
lock.manualSelectionSeq = manual.seq;
|
|
@@ -86,6 +99,7 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
86
99
|
const inherited = modelRouteFromCall(downstream);
|
|
87
100
|
const candidates = invocation?.candidates ?? orderedModelRoutes([primary ?? inherited, ...fallbacks]);
|
|
88
101
|
const selected = accepted ?? invocation?.initialRoute ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal, parameterPolicy.mode === "passthrough" ? readyCtx.get?.("dsmmLlmRoutes") : undefined) : inherited);
|
|
102
|
+
assertCurrent();
|
|
89
103
|
frame.signal.throwIfAborted();
|
|
90
104
|
lock = pinRoleRoute(frame.agent, identity, selected, candidates, { preserveCandidates: parameterPolicy.mode === "native-defaults", initialCandidate: accepted ?? invocation?.selectedCandidate });
|
|
91
105
|
if (accepted !== undefined)
|
|
@@ -93,7 +107,14 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
93
107
|
lockedAgents.add(frame.agent);
|
|
94
108
|
}
|
|
95
109
|
return applyModelRoute(downstream, lock.route);
|
|
96
|
-
}
|
|
110
|
+
};
|
|
111
|
+
if (owned) {
|
|
112
|
+
preparations.set(agent, prepare);
|
|
113
|
+
dispose = () => { if (preparations.get(agent) === prepare)
|
|
114
|
+
preparations.delete(agent); };
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
dispose = readyCtx.on("agent/request", async (frame, next) => prepare(frame, await next()), { prepend: true });
|
|
97
118
|
disposeAgent = readyCtx.on("agent/disposed", ({ agent }) => { lockedAgents.delete(agent); clearRoleRouteLock(agent); }, { global: true });
|
|
98
119
|
}
|
|
99
120
|
catch (error) {
|
|
@@ -20,6 +20,8 @@ export declare class NativeAdmission {
|
|
|
20
20
|
readonly policy: DsmmRolePolicy;
|
|
21
21
|
readonly lifetime: AbortController;
|
|
22
22
|
private readonly pending;
|
|
23
|
+
private readonly providers;
|
|
24
|
+
registerProvider(provider: SubagentProvider): void;
|
|
23
25
|
private readonly live;
|
|
24
26
|
private readonly candidates;
|
|
25
27
|
private readonly agents;
|