@dsmm/dsmm 0.2.0 → 0.3.0
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 +37 -67
- package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
- package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
- package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
- package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
- package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
- package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
- package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
- package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
- package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
- package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
- package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
- package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
- package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
- package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
- package/cordis.patch.yml +14 -0
- package/docs/agent-presets.md +36 -52
- package/docs/compatibility.md +47 -110
- package/docs/deferred-native-approval-risk.md +19 -0
- package/docs/design.md +2 -2
- package/docs/lsp.md +11 -21
- package/docs/migration-from-ocmm.md +2 -2
- package/docs/model-routing.md +84 -59
- package/docs/native-permissions.md +35 -0
- package/docs/profiles.md +40 -87
- package/docs/releasing.md +123 -2
- package/docs/roadmap.md +71 -17
- package/docs/settings-status.md +34 -169
- package/docs/skill-sync.md +52 -15
- package/lib/agent-registry.d.ts +36 -0
- package/lib/agent-registry.js +75 -0
- package/lib/child-admission-contract.d.ts +37 -0
- package/lib/child-admission-contract.js +2 -0
- package/lib/child-admission.d.ts +40 -0
- package/lib/child-admission.js +151 -0
- package/lib/child-capture.d.ts +85 -0
- package/lib/child-capture.js +205 -0
- package/lib/child-evidence.d.ts +17 -0
- package/lib/child-evidence.js +43 -0
- package/lib/client/ChildrenPanel.d.ts +43 -0
- package/lib/client/ChildrenPanel.js +82 -0
- package/lib/client/DeploymentPage.js +15 -8
- package/lib/client/EditableChoice.d.ts +17 -0
- package/lib/client/EditableChoice.js +49 -0
- package/lib/client/PermissionsPanel.d.ts +14 -0
- package/lib/client/PermissionsPanel.js +46 -0
- package/lib/client/ProfilesSection.js +30 -15
- package/lib/client/RoleAvailability.d.ts +7 -0
- package/lib/client/RoleAvailability.js +19 -0
- package/lib/client/SessionProfiles.js +27 -9
- package/lib/client/StructuredEditor.js +15 -7
- package/lib/client/children-controller.d.ts +98 -0
- package/lib/client/children-controller.js +296 -0
- package/lib/client/children-locales.d.ts +367 -0
- package/lib/client/children-locales.js +69 -0
- package/lib/client/controller.d.ts +6 -1
- package/lib/client/controller.js +14 -8
- package/lib/client/deployment-controller.js +1 -1
- package/lib/client/deployment-data.d.ts +2 -1
- package/lib/client/deployment-data.js +34 -5
- package/lib/client/deployment-locales.d.ts +4 -0
- package/lib/client/deployment-locales.js +11 -2
- package/lib/client/diagnostics.d.ts +14 -0
- package/lib/client/diagnostics.js +53 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +96 -2
- package/lib/client/locales.d.ts +54 -0
- package/lib/client/locales.js +34 -16
- package/lib/client/permission-client.d.ts +16 -0
- package/lib/client/permission-client.js +38 -0
- package/lib/client/permission-controller.d.ts +62 -0
- package/lib/client/permission-controller.js +149 -0
- package/lib/client/permission-locales.d.ts +114 -0
- package/lib/client/permission-locales.js +75 -0
- package/lib/client/session-labels.js +4 -4
- package/lib/client/structured.js +19 -5
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +20 -0
- package/lib/client.js +5780 -1679
- package/lib/core-permission-authority.d.ts +18 -0
- package/lib/core-permission-authority.js +255 -0
- package/lib/core-permissions.d.ts +8 -0
- package/lib/core-permissions.js +33 -0
- package/lib/delivery-authority.d.ts +83 -0
- package/lib/delivery-authority.js +397 -0
- package/lib/deployment-config.d.ts +23 -0
- package/lib/deployment-config.js +61 -40
- package/lib/deployment-permission-rules.d.ts +55 -0
- package/lib/deployment-permission-rules.js +306 -0
- package/lib/dsh-types.d.ts +10 -4
- package/lib/guards.d.ts +1 -1
- package/lib/guards.js +29 -8
- package/lib/host-llm-startup.d.ts +41 -0
- package/lib/host-llm-startup.js +65 -0
- package/lib/host-llm.d.ts +92 -0
- package/lib/host-llm.js +325 -0
- package/lib/index.d.ts +15 -4
- package/lib/index.js +288 -48
- package/lib/live-pi-ai-owner.d.ts +18 -0
- package/lib/live-pi-ai-owner.js +144 -0
- package/lib/llm-runtime.d.ts +11 -0
- package/lib/llm-runtime.js +21 -0
- package/lib/managed-settings.d.ts +5 -0
- package/lib/managed-settings.js +14 -0
- package/lib/model-parameter-policy.d.ts +11 -0
- package/lib/model-parameter-policy.js +27 -0
- package/lib/model-routing.js +28 -17
- package/lib/modules.d.ts +13 -5
- package/lib/modules.js +17 -1
- package/lib/native-child-evidence.d.ts +40 -0
- package/lib/native-child-evidence.js +104 -0
- package/lib/native-pi-ai-wire.d.ts +37 -0
- package/lib/native-pi-ai-wire.js +261 -0
- package/lib/native-scope.js +1 -1
- package/lib/permission-bash.d.ts +6 -0
- package/lib/permission-bash.js +7 -0
- package/lib/permission-control.d.ts +73 -0
- package/lib/permission-control.js +205 -0
- package/lib/permission-controller.d.ts +68 -0
- package/lib/permission-controller.js +317 -0
- package/lib/permission-errors.d.ts +7 -0
- package/lib/permission-errors.js +21 -0
- package/lib/permission-fs-search.d.ts +5 -0
- package/lib/permission-fs-search.js +7 -0
- package/lib/permission-fs.d.ts +5 -0
- package/lib/permission-fs.js +7 -0
- package/lib/permission-native-access.d.ts +11 -0
- package/lib/permission-native-access.js +6 -0
- package/lib/permission-native-command.d.ts +10 -0
- package/lib/permission-native-command.js +93 -0
- package/lib/permission-native-rules.d.ts +75 -0
- package/lib/permission-native-rules.js +278 -0
- package/lib/permission-pwsh.d.ts +6 -0
- package/lib/permission-pwsh.js +7 -0
- package/lib/permission-remote.d.ts +26 -0
- package/lib/permission-remote.js +53 -0
- package/lib/permission-rpc.d.ts +29 -0
- package/lib/permission-rpc.js +152 -0
- package/lib/permission-rules.d.ts +115 -0
- package/lib/permission-rules.js +256 -0
- package/lib/permission-settings.d.ts +45 -0
- package/lib/permission-settings.js +48 -0
- package/lib/permission-shell.d.ts +38 -0
- package/lib/permission-shell.js +150 -0
- package/lib/permission-web.d.ts +5 -0
- package/lib/permission-web.js +7 -0
- package/lib/preset-registry.js +36 -25
- package/lib/profile-diagnostics.d.ts +45 -0
- package/lib/profile-diagnostics.js +148 -0
- package/lib/profile-locale.d.ts +3 -0
- package/lib/profile-locale.js +2 -0
- package/lib/profile-remote.d.ts +8 -0
- package/lib/profile-remote.js +163 -39
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +20 -16
- package/lib/profile-runtime.d.ts +40 -1
- package/lib/profile-runtime.js +368 -93
- package/lib/profile-store.d.ts +11 -0
- package/lib/profile-store.js +143 -11
- package/lib/profile-types.d.ts +70 -1
- package/lib/profile-types.js +1 -0
- package/lib/profiles.d.ts +16 -2
- package/lib/profiles.js +156 -79
- package/lib/prompt-content.js +1 -1
- package/lib/prompts.d.ts +37 -2
- package/lib/prompts.js +111 -9
- package/lib/recovery-policy.js +20 -7
- package/lib/role-control-remote.d.ts +38 -0
- package/lib/role-control-remote.js +211 -0
- package/lib/role-control-rpc.d.ts +51 -0
- package/lib/role-control-rpc.js +381 -0
- package/lib/role-control-types.d.ts +92 -0
- package/lib/role-control-types.js +8 -0
- package/lib/role-invocation.d.ts +47 -0
- package/lib/role-invocation.js +135 -0
- package/lib/role-llm-runtime.d.ts +17 -0
- package/lib/role-llm-runtime.js +62 -0
- package/lib/role-llm.d.ts +31 -0
- package/lib/role-llm.js +66 -0
- package/lib/role-policy.d.ts +46 -8
- package/lib/role-policy.js +421 -61
- package/lib/role-providers.d.ts +2 -2
- package/lib/role-providers.js +27 -72
- package/lib/role-routing.d.ts +11 -2
- package/lib/role-routing.js +42 -25
- package/lib/role-runs.d.ts +138 -0
- package/lib/role-runs.js +335 -0
- package/lib/role-subagents.d.ts +58 -3
- package/lib/role-subagents.js +179 -56
- package/lib/roles.d.ts +5 -6
- package/lib/roles.js +10 -39
- package/lib/route-json.d.ts +19 -0
- package/lib/route-json.js +129 -0
- package/lib/routing-policy.d.ts +2 -0
- package/lib/routing-policy.js +12 -2
- package/lib/runtime-integration.d.ts +81 -0
- package/lib/runtime-integration.js +702 -0
- package/lib/runtime-recovery.js +18 -8
- package/lib/session-persistence.d.ts +2 -1
- package/lib/session-persistence.js +1 -1
- package/lib/session-scope.js +4 -1
- package/lib/settings.d.ts +47 -13
- package/lib/settings.js +217 -82
- package/lib/skills.js +2 -2
- package/lib/status.d.ts +10 -1
- package/lib/status.js +11 -8
- package/lib/subagent-runtime.d.ts +57 -0
- package/lib/subagent-runtime.js +257 -0
- package/package.json +149 -89
- package/patches/subagent-runtime.yml +15 -0
- package/prompts/deepseek-flash.md +1 -1
- package/prompts/deepseek-v4-pro.md +2 -2
- package/prompts/deepwork.md +27 -18
- package/prompts/source/agents/clarifier.md +5 -3
- package/prompts/source/agents/orchestrator.md +18 -9
- package/prompts/source/agents/plan-critic.md +5 -1
- package/prompts/source/agents/planner.md +4 -2
- package/prompts/source/agents/reviewer.md +6 -0
- package/prompts/source/category/complex.md +4 -4
- package/prompts/source/category/creative.md +6 -4
- package/prompts/source/category/cross-cutting.md +10 -8
- package/prompts/source/category/deep.md +5 -3
- package/prompts/source/category/documenting.md +7 -1
- package/prompts/source/category/frontend.md +2 -2
- package/prompts/source/category/hard-reasoning.md +3 -3
- package/prompts/source/category/research.md +4 -2
- package/prompts/source/deepwork/claude-opus-5.md +2 -2
- package/prompts/source/deepwork/codex.md +1 -1
- package/prompts/source/deepwork/default.md +22 -15
- package/prompts/source/deepwork/gemini.md +23 -16
- package/prompts/source/deepwork/glm.md +21 -14
- package/prompts/source/deepwork/gpt.md +12 -6
- package/prompts/source/deepwork/planner.md +8 -5
- package/prompts/source/manifest.json +178 -63
- package/prompts/source/shared/dsh-host-contract.md +5 -3
- package/prompts/source/shared/locale.md +2 -2
- package/prompts/source/terminal/orchestrator.md +1 -1
- package/skills/ast-grep/SKILL.md +7 -4
- package/skills/brainstorming/SKILL.md +43 -22
- package/skills/coding-agent-sessions/SKILL.md +7 -4
- package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
- package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
- package/skills/debugging/SKILL.md +14 -9
- package/skills/debugging/references/methodology/00-setup.md +14 -62
- package/skills/debugging/references/methodology/02-investigate.md +4 -4
- package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
- package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
- package/skills/debugging/references/methodology/06-fix.md +6 -6
- package/skills/debugging/references/methodology/08-qa.md +5 -5
- package/skills/debugging/references/methodology/09-cleanup.md +15 -153
- package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
- package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
- package/skills/debugging/references/runtimes/native-binary.md +9 -54
- package/skills/debugging/references/runtimes/node.md +4 -15
- package/skills/debugging/references/runtimes/python.md +3 -15
- package/skills/debugging/references/runtimes/rust.md +2 -18
- package/skills/debugging/references/tools/dap.md +1 -1
- package/skills/debugging/references/tools/ghidra.md +4 -15
- package/skills/debugging/references/tools/playwright-cli.md +3 -15
- package/skills/debugging/references/tools/pwntools.md +4 -16
- package/skills/dispatching-parallel-agents/SKILL.md +18 -16
- package/skills/frontend/SKILL.md +7 -4
- package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
- package/skills/git-master/SKILL.md +7 -4
- package/skills/init-deep/SKILL.md +7 -4
- package/skills/receiving-code-review/SKILL.md +17 -12
- package/skills/remove-ai-slops/SKILL.md +39 -38
- package/skills/requesting-code-review/SKILL.md +19 -17
- package/skills/requesting-code-review/code-reviewer.md +13 -1
- package/skills/subagent-driven-development/SKILL.md +29 -26
- package/skills/subagent-driven-development/implementer-prompt.md +29 -11
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
- package/skills/using-git-worktrees/SKILL.md +7 -4
- package/skills/writing-plans/SKILL.md +29 -24
- package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { TOOL_ABORTED } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
import { isSandboxWidening, PermissionControl, PermissionRefusal } from "./permission-control.js";
|
|
5
|
+
import { classifyPermissionShell } from "./permission-shell.js";
|
|
6
|
+
import { nativeCommandMatch } from "./permission-native-command.js";
|
|
7
|
+
import { NATIVE_PERMISSION_CAPABILITIES, registerNativePermissionRules } from "./permission-native-rules.js";
|
|
8
|
+
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
9
|
+
export const PERMISSION_CONTROLLER_INJECT = ["tools", "agents"];
|
|
10
|
+
/** Bind methods to the original scoped receiver, preserving filters and registry layers. */
|
|
11
|
+
function toolsFacade(tools, register) {
|
|
12
|
+
const methods = new Map();
|
|
13
|
+
return new Proxy(tools, { get: (_target, key) => {
|
|
14
|
+
if (key === "register")
|
|
15
|
+
return register;
|
|
16
|
+
const value = Reflect.get(tools, key, tools);
|
|
17
|
+
if (typeof value !== "function")
|
|
18
|
+
return value;
|
|
19
|
+
const previous = methods.get(key);
|
|
20
|
+
if (previous?.original === value)
|
|
21
|
+
return previous.bound;
|
|
22
|
+
const bound = value.bind(tools);
|
|
23
|
+
methods.set(key, { original: value, bound });
|
|
24
|
+
return bound;
|
|
25
|
+
} });
|
|
26
|
+
}
|
|
27
|
+
function nativeToolKind(module, name) {
|
|
28
|
+
if (module === "fs")
|
|
29
|
+
return name === "read" ? "read" : undefined;
|
|
30
|
+
if (module === "fs-search")
|
|
31
|
+
return name === "glob" || name === "grep" ? name : undefined;
|
|
32
|
+
return name === "web_search" ? "webSearch" : name === "web_fetch" ? "webFetch" : undefined;
|
|
33
|
+
}
|
|
34
|
+
function unchangedFields(value, previous) {
|
|
35
|
+
const current = Object.getOwnPropertyDescriptors(value), keys = Reflect.ownKeys(value);
|
|
36
|
+
return keys.length === Reflect.ownKeys(previous).length && keys.every(key => {
|
|
37
|
+
const a = Reflect.get(current, key), b = Reflect.get(previous, key);
|
|
38
|
+
return a !== undefined && b !== undefined && a.value === b.value && a.get === b.get && a.set === b.set
|
|
39
|
+
&& a.enumerable === b.enumerable && a.configurable === b.configurable && a.writable === b.writable;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Ordinary module owner. Only registrations captured by native module façades are managed. */
|
|
43
|
+
export class DsmmPermissionController extends Service {
|
|
44
|
+
options;
|
|
45
|
+
permissions;
|
|
46
|
+
rules;
|
|
47
|
+
registrations = new Map();
|
|
48
|
+
toolRegistrations = new Map();
|
|
49
|
+
lifetime = new AbortController();
|
|
50
|
+
constructor(ctx, options) {
|
|
51
|
+
super(ctx, "dsmmPermissionController");
|
|
52
|
+
this.options = options;
|
|
53
|
+
this.rules = options.rules;
|
|
54
|
+
const authority = {
|
|
55
|
+
rootCurrent: options.authority.rootCurrent === undefined ? undefined : (root, exec) => options.authority.rootCurrent(root, exec),
|
|
56
|
+
captureIntegrity: options.authority.captureIntegrity === undefined ? undefined : exec => options.authority.captureIntegrity(exec),
|
|
57
|
+
current: exec => options.authority.current(exec),
|
|
58
|
+
assertCurrent: (current, exec) => {
|
|
59
|
+
options.authority.assertCurrent(options.authority.current(exec), exec);
|
|
60
|
+
if (current.agent !== exec.agent || this.lifetime.signal.aborted)
|
|
61
|
+
throw new PermissionRefusal("stale");
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
this.permissions = new PermissionControl(ctx, authority);
|
|
65
|
+
if (this.rules.status().mounted) {
|
|
66
|
+
registerNativePermissionRules(ctx, {
|
|
67
|
+
runtime: this.rules,
|
|
68
|
+
captureIntegrity: options.authority.captureIntegrity === undefined ? undefined : exec => options.authority.captureIntegrity(exec),
|
|
69
|
+
identify: definition => {
|
|
70
|
+
const managed = this.registrations.get(definition);
|
|
71
|
+
if (managed === undefined) {
|
|
72
|
+
const tool = this.toolRegistrations.get(definition);
|
|
73
|
+
if (tool === undefined)
|
|
74
|
+
return undefined;
|
|
75
|
+
return { kind: tool.kind, context: tool.scope, signal: tool.signal,
|
|
76
|
+
assertCurrent: () => { if (tool.signal.aborted || !tool.unchanged())
|
|
77
|
+
throw new PermissionRefusal("stale"); },
|
|
78
|
+
assertIntegrity: () => { if (tool.signal.aborted || !tool.unchanged())
|
|
79
|
+
throw new PermissionRefusal("stale"); },
|
|
80
|
+
coLocated: (exec, fs) => options.coLocated?.(tool.scope, exec, fs) === true };
|
|
81
|
+
}
|
|
82
|
+
return { kind: "shell", context: managed.scope, shell: managed.shell, signal: managed.registration.signal,
|
|
83
|
+
assertIntegrity: () => { if (!managed.registration.active || !managed.registration.unchanged())
|
|
84
|
+
throw new PermissionRefusal("stale"); },
|
|
85
|
+
assertCurrent: exec => managed.registration.assertCurrent?.(exec),
|
|
86
|
+
coLocated: (exec, fs) => options.coLocated?.(managed.scope, exec, fs) === true };
|
|
87
|
+
},
|
|
88
|
+
captureAuthority: exec => {
|
|
89
|
+
const current = options.authority.current(exec);
|
|
90
|
+
return { signal: current.signal, assertCurrent: () => options.authority.assertCurrent(current, exec) };
|
|
91
|
+
},
|
|
92
|
+
assertCurrent: exec => authority.assertCurrent(authority.current(exec), exec),
|
|
93
|
+
managedShellDecision: async (exec, action, downstream) => {
|
|
94
|
+
const definition = ctx.tools.get(exec.name, exec.agent), managed = definition === undefined ? undefined : this.registrations.get(definition);
|
|
95
|
+
if (managed === undefined)
|
|
96
|
+
throw new PermissionRefusal("stale");
|
|
97
|
+
const workspace = exec.agent?.session.header.cwd ?? "";
|
|
98
|
+
const full = nativeStandingFullAccess(ctx, exec.agent);
|
|
99
|
+
if (full)
|
|
100
|
+
return this.permissions.compose(exec, managed.registration, undefined, "inherit", downstream, workspace);
|
|
101
|
+
const policy = this.rules.getPolicy().policy;
|
|
102
|
+
const entry = nativeCommandMatch(policy.nativeCommands, managed.kind, managed.shell, exec.arguments, workspace);
|
|
103
|
+
if (entry === "ambiguous")
|
|
104
|
+
managed.scope.logger.warn("Ambiguous native command sandbox modes; retaining native execution policy.");
|
|
105
|
+
if (entry !== undefined && entry !== "ambiguous" && managed.scope.get("shell")?.sandboxMode === undefined)
|
|
106
|
+
return { kind: "deny", reason: "Native command sandbox enhancement is unavailable in this executor." };
|
|
107
|
+
const operation = classifyPermissionShell(managed.shell, exec.arguments, workspace, exec);
|
|
108
|
+
return this.permissions.compose(exec, managed.registration, entry === "ambiguous" ? undefined : entry, action, downstream, operation.workingDirectory);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
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 });
|
|
113
|
+
ctx.on("tools/result", exec => { this.permissions.finish(exec); }, { global: true });
|
|
114
|
+
ctx.on("agent/disposed", ({ agent }) => { this.permissions.revokeAgent(agent); }, { global: true });
|
|
115
|
+
}
|
|
116
|
+
ctx.effect(() => () => this.retire());
|
|
117
|
+
}
|
|
118
|
+
/** Public in-process facts for DSMM consumers; requested/configured modes never grant access. */
|
|
119
|
+
nativeAccess(exec) {
|
|
120
|
+
const mode = this.permissions.approvedTarget(exec);
|
|
121
|
+
return Object.freeze({ standingFullAccess: nativeStandingFullAccess(this.ctx, exec.agent),
|
|
122
|
+
...mode === undefined ? {} : { approvedSandboxMode: mode } });
|
|
123
|
+
}
|
|
124
|
+
/** Optional public injection also captures definitions registered before Core publishes this service. */
|
|
125
|
+
static toolScope(scope, kind) {
|
|
126
|
+
const originalTools = scope.tools;
|
|
127
|
+
return scope.extend({ tools: toolsFacade(originalTools, definition => {
|
|
128
|
+
const mapped = nativeToolKind(kind, definition.name);
|
|
129
|
+
if (mapped === undefined)
|
|
130
|
+
return originalTools.register(definition);
|
|
131
|
+
const unregister = originalTools.register(definition);
|
|
132
|
+
const binding = scope.inject(["dsmmPermissionController"], injected => {
|
|
133
|
+
injected.dsmmPermissionController.captureTool(injected, definition, mapped);
|
|
134
|
+
});
|
|
135
|
+
return scope.effect(() => () => { const disposing = binding.dispose(); unregister(); return disposing; });
|
|
136
|
+
}) });
|
|
137
|
+
}
|
|
138
|
+
toolScope(scope, kind) {
|
|
139
|
+
return DsmmPermissionController.toolScope(scope, kind);
|
|
140
|
+
}
|
|
141
|
+
captureTool(scope, definition, kind) {
|
|
142
|
+
if (!this.rules.status().mounted)
|
|
143
|
+
return;
|
|
144
|
+
if (this.lifetime.signal.aborted)
|
|
145
|
+
throw new PermissionRefusal("unavailable");
|
|
146
|
+
const fields = Object.getOwnPropertyDescriptors(definition), outputFields = Object.getOwnPropertyDescriptors(definition.output);
|
|
147
|
+
const parameters = JSON.stringify(definition.parameters), outputSchema = JSON.stringify(definition.output.schema);
|
|
148
|
+
const lifetime = new AbortController();
|
|
149
|
+
const managed = { scope, definition, kind,
|
|
150
|
+
signal: AbortSignal.any([lifetime.signal, this.lifetime.signal]),
|
|
151
|
+
unchanged: () => unchangedFields(definition, fields) && unchangedFields(definition.output, outputFields)
|
|
152
|
+
&& JSON.stringify(definition.parameters) === parameters && JSON.stringify(definition.output.schema) === outputSchema,
|
|
153
|
+
dispose: () => { lifetime.abort(); if (this.toolRegistrations.get(definition) === managed)
|
|
154
|
+
this.toolRegistrations.delete(definition); },
|
|
155
|
+
};
|
|
156
|
+
this.toolRegistrations.set(definition, managed);
|
|
157
|
+
scope.effect(() => managed.dispose);
|
|
158
|
+
}
|
|
159
|
+
/** The receiver is captured before extend: do not register into an Agent's own layer. */
|
|
160
|
+
shellScope(scope, kind) {
|
|
161
|
+
if (!this.rules.status().mounted)
|
|
162
|
+
return scope;
|
|
163
|
+
if (this.lifetime.signal.aborted)
|
|
164
|
+
throw new PermissionRefusal("unavailable");
|
|
165
|
+
const originalTools = scope.tools, originalShell = scope.get("shell"), methods = new Map();
|
|
166
|
+
if (originalShell === undefined)
|
|
167
|
+
throw new PermissionRefusal("unavailable");
|
|
168
|
+
const register = (definition) => this.registerShell(scope, originalTools, kind, definition);
|
|
169
|
+
const facade = new Proxy(originalTools, { get: (_target, key) => {
|
|
170
|
+
if (key === "register")
|
|
171
|
+
return register;
|
|
172
|
+
const value = Reflect.get(originalTools, key, originalTools);
|
|
173
|
+
if (typeof value !== "function")
|
|
174
|
+
return value;
|
|
175
|
+
const previous = methods.get(key);
|
|
176
|
+
if (previous?.original === value)
|
|
177
|
+
return previous.bound;
|
|
178
|
+
const bound = value.bind(originalTools);
|
|
179
|
+
methods.set(key, { original: value, bound });
|
|
180
|
+
return bound;
|
|
181
|
+
} });
|
|
182
|
+
const shell = new Proxy(originalShell, { get: (_target, key) => {
|
|
183
|
+
if (key === "resolve")
|
|
184
|
+
return (request) => Reflect.apply(originalShell.resolve, originalShell, [request]);
|
|
185
|
+
if (key === "execute")
|
|
186
|
+
return (spec) => {
|
|
187
|
+
const mode = this.permissions.sandboxMode();
|
|
188
|
+
if (mode !== undefined && spec.sandboxPolicy === undefined)
|
|
189
|
+
throw new PermissionRefusal("unavailable");
|
|
190
|
+
return Reflect.apply(originalShell.execute, originalShell, [mode === undefined || !isSandboxWidening(mode, spec.sandboxPolicy?.mode) ? spec : { ...spec, sandboxPolicy: { ...spec.sandboxPolicy, mode } }]);
|
|
191
|
+
};
|
|
192
|
+
const value = Reflect.get(originalShell, key, originalShell);
|
|
193
|
+
return typeof value === "function" ? value.bind(originalShell) : value;
|
|
194
|
+
} });
|
|
195
|
+
// This façade only binds request provenance. The original service still applies never, audit and cancellation.
|
|
196
|
+
const approval = () => {
|
|
197
|
+
const original = scope.get("approval");
|
|
198
|
+
if (original === undefined)
|
|
199
|
+
return undefined;
|
|
200
|
+
return new Proxy(original, { get: (_target, key) => {
|
|
201
|
+
if (key === "request")
|
|
202
|
+
return (request) => this.permissions.nativeApproval(request, original);
|
|
203
|
+
const value = Reflect.get(original, key, original);
|
|
204
|
+
return typeof value === "function" ? value.bind(original) : value;
|
|
205
|
+
} });
|
|
206
|
+
};
|
|
207
|
+
// Native.apply resolves its optional approver with public Context.get, not the property getter.
|
|
208
|
+
return scope.extend({ tools: facade, shell,
|
|
209
|
+
get: ((...args) => args[0] === "approval" ? approval() : Reflect.apply(scope.get, scope, args)),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
registerShell(scope, originalTools, kind, definition) {
|
|
213
|
+
if (this.lifetime.signal.aborted)
|
|
214
|
+
throw new PermissionRefusal("unavailable");
|
|
215
|
+
const identity = this.options.shellIdentity(scope, kind);
|
|
216
|
+
if (identity.dialect !== (kind === "bash" ? "posix" : "powershell") || identity.commandField !== "command" || identity.cwdField !== "workdir" || identity.executable.length === 0)
|
|
217
|
+
throw new PermissionRefusal("validation");
|
|
218
|
+
const capability = identity.readCapability;
|
|
219
|
+
const shell = Object.freeze({ ...identity, readCapability: capability === undefined ? undefined : Object.freeze({
|
|
220
|
+
signal: capability.signal, resolveExecutable: capability.resolveExecutable.bind(capability), assertCurrent: capability.assertCurrent.bind(capability),
|
|
221
|
+
}) });
|
|
222
|
+
const fields = Object.getOwnPropertyDescriptors(definition), body = definition.execute, lifetime = new AbortController();
|
|
223
|
+
const parameters = JSON.stringify(definition.parameters), outputSchema = JSON.stringify(definition.output.schema);
|
|
224
|
+
const outputFields = Object.getOwnPropertyDescriptors(definition.output), shellOwner = scope.get("shell"), sandboxPolicy = scope.get("sandboxPolicy");
|
|
225
|
+
if (shellOwner === undefined)
|
|
226
|
+
throw new PermissionRefusal("unavailable");
|
|
227
|
+
let registration;
|
|
228
|
+
const wrapper = async (args, exec) => {
|
|
229
|
+
return this.permissions.run(exec, args, registration, async (signal) => {
|
|
230
|
+
const value = await body.call(definition, args, Object.freeze({ ...exec, signal,
|
|
231
|
+
deferContext: exec.deferContext.bind(exec), concludeTurn: exec.concludeTurn.bind(exec) }));
|
|
232
|
+
if (signal.aborted)
|
|
233
|
+
throw new HarnessError("Permission-controlled tool execution was cancelled.", TOOL_ABORTED);
|
|
234
|
+
return value;
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const registered = Object.create(Object.getPrototypeOf(definition), { ...fields, execute: { ...fields.execute, value: wrapper } });
|
|
238
|
+
const registeredFields = Object.getOwnPropertyDescriptors(registered);
|
|
239
|
+
registration = { definition, registered, body, identity: Object.freeze({}), active: true,
|
|
240
|
+
approval: () => scope.get("approval"),
|
|
241
|
+
standingMode: exec => sandboxPolicy?.resolve(exec.agent === undefined ? {} : { session: exec.agent.session }).mode,
|
|
242
|
+
signal: AbortSignal.any([lifetime.signal, this.lifetime.signal]),
|
|
243
|
+
assertCurrent: exec => {
|
|
244
|
+
shell.readCapability?.assertCurrent(exec);
|
|
245
|
+
},
|
|
246
|
+
unchanged: () => unchangedFields(definition, fields) && unchangedFields(registered, registeredFields)
|
|
247
|
+
&& unchangedFields(definition.output, outputFields) && JSON.stringify(definition.parameters) === parameters && JSON.stringify(definition.output.schema) === outputSchema,
|
|
248
|
+
};
|
|
249
|
+
let unregister, disposed = false;
|
|
250
|
+
const managed = { kind, scope, registration, shell, dispose: () => {
|
|
251
|
+
if (disposed)
|
|
252
|
+
return;
|
|
253
|
+
disposed = true;
|
|
254
|
+
this.permissions.revokeRegistration(registration);
|
|
255
|
+
lifetime.abort();
|
|
256
|
+
this.registrations.delete(registered);
|
|
257
|
+
unregister?.();
|
|
258
|
+
} };
|
|
259
|
+
this.registrations.set(registered, managed);
|
|
260
|
+
try {
|
|
261
|
+
unregister = originalTools.register(registered);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
this.permissions.revokeRegistration(registration);
|
|
265
|
+
lifetime.abort();
|
|
266
|
+
this.registrations.delete(registered);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
if (disposed) {
|
|
270
|
+
unregister();
|
|
271
|
+
return () => { };
|
|
272
|
+
}
|
|
273
|
+
return scope.effect(() => managed.dispose);
|
|
274
|
+
}
|
|
275
|
+
coverage(agent) {
|
|
276
|
+
return Object.freeze([...this.registrations.values()].filter(managed => managed.registration.active
|
|
277
|
+
&& !managed.registration.signal?.aborted && managed.registration.unchanged()
|
|
278
|
+
&& this.ctx.tools.get(managed.registration.registered.name, agent) === managed.registration.registered).map(managed => Object.freeze({
|
|
279
|
+
name: managed.registration.registered.name, kind: managed.kind, boundary: "cooperative-body", approval: "native-once",
|
|
280
|
+
})));
|
|
281
|
+
}
|
|
282
|
+
/** Actual visible non-Shell registrations, not executor readiness or co-location proof. */
|
|
283
|
+
toolCoverage(agent) {
|
|
284
|
+
if (!this.rules.status().mounted || this.lifetime.signal.aborted)
|
|
285
|
+
return Object.freeze([]);
|
|
286
|
+
return Object.freeze([...this.toolRegistrations.values()].filter(managed => !managed.signal.aborted && managed.unchanged()
|
|
287
|
+
&& this.ctx.tools.get(managed.definition.name, agent) === managed.definition).map(managed => Object.freeze({
|
|
288
|
+
name: managed.definition.name, kind: managed.kind, boundary: "tool-call-boundary", approval: "native-once",
|
|
289
|
+
pathEvidence: managed.kind === "read" ? "native-fs" : managed.kind === "glob" || managed.kind === "grep" ? "requires-colocation" : "not-applicable",
|
|
290
|
+
})));
|
|
291
|
+
}
|
|
292
|
+
capabilities(agent) {
|
|
293
|
+
if (this.lifetime.signal.aborted)
|
|
294
|
+
throw new PermissionRefusal("unavailable");
|
|
295
|
+
return Object.freeze({ limits: NATIVE_PERMISSION_CAPABILITIES, runtime: this.rules.status(), tools: Object.freeze([
|
|
296
|
+
...this.coverage(agent).map(tool => Object.freeze({ name: tool.name, kind: "shell", approval: tool.approval, scopedMemory: false })),
|
|
297
|
+
...this.toolCoverage(agent).map(tool => Object.freeze({ name: tool.name, kind: tool.kind, approval: tool.approval, scopedMemory: false })),
|
|
298
|
+
]) });
|
|
299
|
+
}
|
|
300
|
+
retire() {
|
|
301
|
+
if (this.lifetime.signal.aborted)
|
|
302
|
+
return;
|
|
303
|
+
this.lifetime.abort();
|
|
304
|
+
this.permissions.retire();
|
|
305
|
+
for (const managed of [...this.registrations.values()])
|
|
306
|
+
managed.dispose();
|
|
307
|
+
for (const managed of [...this.toolRegistrations.values()])
|
|
308
|
+
managed.dispose();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/** Parent supplies the real existing Core collaborators and A's sole runtime-sync owner. */
|
|
312
|
+
export function installPermissionController(ctx, options) {
|
|
313
|
+
if (ctx.get("dsmmPermissionController") !== undefined)
|
|
314
|
+
throw new PermissionRefusal("unavailable");
|
|
315
|
+
return new DsmmPermissionController(ctx, options);
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=permission-controller.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class PermissionRefusal extends Error {
|
|
2
|
+
readonly code: "not-owned" | "stale" | "cancelled" | "unavailable" | "validation" | "not-found" | "scope-unavailable" | "replayed" | "denied";
|
|
3
|
+
constructor(code: "not-owned" | "stale" | "cancelled" | "unavailable" | "validation" | "not-found" | "scope-unavailable" | "replayed" | "denied");
|
|
4
|
+
}
|
|
5
|
+
/** A policy lifetime may end while the native answerer is still waiting. */
|
|
6
|
+
export declare function permissionOutcome<T>(answer: () => Promise<T>, signal: AbortSignal, cancelled: T): Promise<T>;
|
|
7
|
+
//# sourceMappingURL=permission-errors.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class PermissionRefusal extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code) {
|
|
4
|
+
super("The Host refused the permission operation.");
|
|
5
|
+
this.code = code;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** A policy lifetime may end while the native answerer is still waiting. */
|
|
9
|
+
export async function permissionOutcome(answer, signal, cancelled) {
|
|
10
|
+
if (signal.aborted)
|
|
11
|
+
return cancelled;
|
|
12
|
+
let abort;
|
|
13
|
+
const ended = new Promise(resolve => { abort = () => resolve(cancelled); signal.addEventListener("abort", abort, { once: true }); });
|
|
14
|
+
try {
|
|
15
|
+
return await Promise.race([Promise.resolve().then(answer), ended]);
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
signal.removeEventListener("abort", abort);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=permission-errors.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import * as Native from "@deepseek-ai/dsh-tool-fs-search";
|
|
3
|
+
export { Config, inject, name } from "@deepseek-ai/dsh-tool-fs-search";
|
|
4
|
+
export declare function apply(ctx: Context, config: Native.Config): ReturnType<typeof Native.apply>;
|
|
5
|
+
//# sourceMappingURL=permission-fs-search.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Native from "@deepseek-ai/dsh-tool-fs-search";
|
|
2
|
+
import { DsmmPermissionController } from "./permission-controller.js";
|
|
3
|
+
export { Config, inject, name } from "@deepseek-ai/dsh-tool-fs-search";
|
|
4
|
+
export function apply(ctx, config) {
|
|
5
|
+
return Native.apply(DsmmPermissionController.toolScope(ctx, "fs-search"), config);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=permission-fs-search.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import * as Native from "@deepseek-ai/dsh-tool-fs";
|
|
3
|
+
export { Config, inject, name } from "@deepseek-ai/dsh-tool-fs";
|
|
4
|
+
export declare function apply(ctx: Context, config: Native.Config): ReturnType<typeof Native.apply>;
|
|
5
|
+
//# sourceMappingURL=permission-fs.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Native from "@deepseek-ai/dsh-tool-fs";
|
|
2
|
+
import { DsmmPermissionController } from "./permission-controller.js";
|
|
3
|
+
export { Config, inject, name } from "@deepseek-ai/dsh-tool-fs";
|
|
4
|
+
export function apply(ctx, config) {
|
|
5
|
+
return Native.apply(DsmmPermissionController.toolScope(ctx, "fs"), config);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=permission-fs.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
export type NativePermissionMode = "workspace-write" | "danger-full-access";
|
|
4
|
+
export interface NativePermissionAccess {
|
|
5
|
+
readonly standingFullAccess: boolean;
|
|
6
|
+
/** An execution-local target authorized by a fulfilled original native request. */
|
|
7
|
+
readonly approvedSandboxMode?: NativePermissionMode;
|
|
8
|
+
}
|
|
9
|
+
/** Public effective native policy only; requested tool arguments are never authority. */
|
|
10
|
+
export declare function nativeStandingFullAccess(ctx: Context, agent?: Agent): boolean;
|
|
11
|
+
//# sourceMappingURL=permission-native-access.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Public effective native policy only; requested tool arguments are never authority. */
|
|
2
|
+
export function nativeStandingFullAccess(ctx, agent) {
|
|
3
|
+
const sandbox = (agent?.ctx ?? ctx).get("sandboxPolicy");
|
|
4
|
+
return sandbox?.resolve(agent === undefined ? {} : { session: agent.session }).mode === "danger-full-access";
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=permission-native-access.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NativeCommandEntry, NativeCommandsSettings } from "./permission-settings.js";
|
|
2
|
+
import type { PermissionShellIdentity } from "./permission-shell.js";
|
|
3
|
+
/** Host-only validation: Windows drive-relative roots never authorize an enhancement. */
|
|
4
|
+
export declare function parseHostNativeCommands(input?: unknown): NativeCommandsSettings;
|
|
5
|
+
/** Finite literal grammar: ASCII blanks, bare literal tokens, and static quotes.
|
|
6
|
+
* POSIX quote fragments concatenate; PowerShell quotes must enclose a whole operand.
|
|
7
|
+
* Unsupported syntax retains the ordinary native path. */
|
|
8
|
+
export declare function literalCommand(command: string, dialect: PermissionShellIdentity["dialect"]): readonly string[] | undefined;
|
|
9
|
+
export declare function nativeCommandMatch(settings: NativeCommandsSettings, tool: "bash" | "pwsh", identity: PermissionShellIdentity, args: unknown, workspace: string): NativeCommandEntry | "ambiguous" | undefined;
|
|
10
|
+
//# sourceMappingURL=permission-native-command.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isAbsolute, normalize, parse, resolve } from "node:path";
|
|
2
|
+
import { parseNativeCommands } from "./permission-settings.js";
|
|
3
|
+
import { PermissionRefusal } from "./permission-errors.js";
|
|
4
|
+
/** Host-only validation: Windows drive-relative roots never authorize an enhancement. */
|
|
5
|
+
export function parseHostNativeCommands(input = {}) {
|
|
6
|
+
const settings = parseNativeCommands(input);
|
|
7
|
+
return Object.freeze({ enabled: settings.enabled, entries: Object.freeze(settings.entries.map(entry => {
|
|
8
|
+
const cwd = entry.match.workingDirectory;
|
|
9
|
+
if (!isAbsolute(cwd) || process.platform === "win32" && parse(normalize(cwd)).root.length === 1)
|
|
10
|
+
throw new PermissionRefusal("validation");
|
|
11
|
+
return Object.freeze({ ...entry, match: Object.freeze({ ...entry.match, workingDirectory: normalize(cwd) }) });
|
|
12
|
+
})) });
|
|
13
|
+
}
|
|
14
|
+
/** Finite literal grammar: ASCII blanks, bare literal tokens, and static quotes.
|
|
15
|
+
* POSIX quote fragments concatenate; PowerShell quotes must enclose a whole operand.
|
|
16
|
+
* Unsupported syntax retains the ordinary native path. */
|
|
17
|
+
export function literalCommand(command, dialect) {
|
|
18
|
+
if (/[\u0000-\u0008\u000a-\u001f\u007f-\u009f\u2018-\u201f]/u.test(command) || command.includes("--%"))
|
|
19
|
+
return undefined;
|
|
20
|
+
const words = [];
|
|
21
|
+
let word = "", quote = "", started = false;
|
|
22
|
+
for (let index = 0; index < command.length; index++) {
|
|
23
|
+
const char = command[index];
|
|
24
|
+
if (quote !== "") {
|
|
25
|
+
if (char === quote) {
|
|
26
|
+
if (dialect === "powershell" && quote === "'" && command[index + 1] === "'") {
|
|
27
|
+
word += "'";
|
|
28
|
+
index++;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// Adjacent PowerShell double quotes encode an embedded quote, not concatenation.
|
|
32
|
+
if (dialect === "powershell" && index + 1 < command.length && command[index + 1] !== " " && command[index + 1] !== "\t")
|
|
33
|
+
return undefined;
|
|
34
|
+
quote = "";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if ((dialect === "powershell" && char === '"') || (quote === '"' && (char === "$" || char === "`")))
|
|
38
|
+
return undefined;
|
|
39
|
+
else if (char === "\\" && dialect === "posix" && quote === '"' && /[\\$`"]/u.test(command[index + 1] ?? ""))
|
|
40
|
+
return undefined;
|
|
41
|
+
else
|
|
42
|
+
word += char;
|
|
43
|
+
}
|
|
44
|
+
else if (char === "'" || char === '"') {
|
|
45
|
+
// A quoted PowerShell command name is an expression without a call operator.
|
|
46
|
+
if (dialect === "powershell" && (started || words.length === 0))
|
|
47
|
+
return undefined;
|
|
48
|
+
quote = char;
|
|
49
|
+
started = true;
|
|
50
|
+
}
|
|
51
|
+
else if (char === " " || char === "\t") {
|
|
52
|
+
if (started) {
|
|
53
|
+
words.push(word);
|
|
54
|
+
word = "";
|
|
55
|
+
started = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (!/[\p{L}\p{M}\p{N}_./:=+%\-]/u.test(char) && !(char === "\\" && dialect === "powershell"))
|
|
59
|
+
return undefined;
|
|
60
|
+
else {
|
|
61
|
+
word += char;
|
|
62
|
+
started = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (quote !== "")
|
|
66
|
+
return undefined;
|
|
67
|
+
if (started)
|
|
68
|
+
words.push(word);
|
|
69
|
+
if (!words.length || words[0] === "" || words[0].includes("=") || dialect === "powershell" && /^(?:[\d+\-]|\.\d)/u.test(words[0])
|
|
70
|
+
|| /^(?:\.|eval|exec|invoke-expression|iex|cmd(?:\.exe)?|pwsh(?:\.exe)?|powershell(?:\.exe)?|bash|sh|zsh|env|sudo|node(?:\.exe)?|python[\d.]*(?:\.exe)?|command|builtin|time|if|then|elif|elseif|else|fi|for|foreach|while|until|do|done|case|esac|in|function|select|coproc|return|throw|exit|break|continue|trap|switch|try|catch|finally|class|enum|using|param|dynamicparam|filter|data|begin|process|end|configuration|workflow|parallel|sequence|default|define|from|var)$/iu.test(words[0].replace(/^.*[\\/]/u, "")))
|
|
71
|
+
return undefined;
|
|
72
|
+
return Object.freeze(words);
|
|
73
|
+
}
|
|
74
|
+
export function nativeCommandMatch(settings, tool, identity, args, workspace) {
|
|
75
|
+
if (!settings.enabled || args === null || typeof args !== "object")
|
|
76
|
+
return undefined;
|
|
77
|
+
const command = Reflect.get(args, identity.commandField), modelCwd = identity.cwdField === undefined ? undefined : Reflect.get(args, identity.cwdField);
|
|
78
|
+
if (typeof command !== "string" || !isAbsolute(workspace) || modelCwd !== undefined && typeof modelCwd !== "string")
|
|
79
|
+
return undefined;
|
|
80
|
+
const cwd = normalize(modelCwd === undefined ? workspace : resolve(workspace, modelCwd));
|
|
81
|
+
const words = literalCommand(command, identity.dialect);
|
|
82
|
+
if (words === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
const matches = parseHostNativeCommands(settings).entries.filter(entry => {
|
|
85
|
+
const match = entry.match, argv = match.subcommand === undefined ? words.slice(1) : words.slice(2);
|
|
86
|
+
return match.tool === tool && match.executable === words[0] && normalize(match.workingDirectory) === cwd
|
|
87
|
+
&& (match.subcommand === undefined || match.subcommand === words[1]) && argv.length === match.args.length && argv.every((value, index) => value === match.args[index]);
|
|
88
|
+
});
|
|
89
|
+
if (new Set(matches.map(entry => entry.sandboxMode)).size > 1)
|
|
90
|
+
return "ambiguous";
|
|
91
|
+
return matches.find(entry => entry.mode === "ask") ?? matches[0];
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=permission-native-command.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { PreToolDecision, ToolDefinition, ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
3
|
+
import type { PermissionExecutionIntegrity } from "./permission-control.js";
|
|
4
|
+
import type { PermissionShellIdentity } from "./permission-shell.js";
|
|
5
|
+
import type { PermissionRulesRuntimeSync } from "./permission-rules.js";
|
|
6
|
+
import type { PermissionRulesStatus } from "./permission-rules.js";
|
|
7
|
+
import type { PermissionRuleAction } from "./permission-settings.js";
|
|
8
|
+
export interface NativePermissionFsTarget {
|
|
9
|
+
readonly targetKey: unknown;
|
|
10
|
+
readonly displayPath: string;
|
|
11
|
+
}
|
|
12
|
+
/** Structural public FS capability; keys are never parsed as paths. */
|
|
13
|
+
export interface NativePermissionFileSystem {
|
|
14
|
+
resolve(path: string, options?: {
|
|
15
|
+
cwd?: string;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<NativePermissionFsTarget>;
|
|
18
|
+
contains(parent: NativePermissionFsTarget, child: NativePermissionFsTarget): boolean;
|
|
19
|
+
}
|
|
20
|
+
type FileSystem = NativePermissionFileSystem;
|
|
21
|
+
/** Supplied only by the owner of the actual registered definition/native execution context. */
|
|
22
|
+
export interface NativePermissionToolIdentity {
|
|
23
|
+
readonly kind: "read" | "glob" | "grep" | "shell" | "webSearch" | "webFetch";
|
|
24
|
+
readonly context: Context;
|
|
25
|
+
readonly signal?: AbortSignal;
|
|
26
|
+
readonly shell?: PermissionShellIdentity;
|
|
27
|
+
/** Live proof FS and direct rg/Shell executor share path and workspace semantics. No name/cwd inference. */
|
|
28
|
+
coLocated?(execution: Readonly<ToolExecution>, fs: FileSystem): boolean;
|
|
29
|
+
assertCurrent(execution: Readonly<ToolExecution>): void;
|
|
30
|
+
assertIntegrity?(execution: Readonly<ToolExecution>): void;
|
|
31
|
+
}
|
|
32
|
+
interface NativePermissionAuthority {
|
|
33
|
+
readonly signal: AbortSignal;
|
|
34
|
+
assertCurrent(): void;
|
|
35
|
+
}
|
|
36
|
+
export interface NativePermissionRulesOptions {
|
|
37
|
+
readonly runtime: PermissionRulesRuntimeSync;
|
|
38
|
+
captureIntegrity?(execution: Readonly<ToolExecution>): PermissionExecutionIntegrity;
|
|
39
|
+
/** Exact registration identity, never trust a matching tool name alone. */
|
|
40
|
+
identify(definition: ToolDefinition, execution: Readonly<ToolExecution>): NativePermissionToolIdentity | undefined;
|
|
41
|
+
/** Capture the invocation's original Core epoch after rule refresh. */
|
|
42
|
+
captureAuthority?(execution: Readonly<ToolExecution>): NativePermissionAuthority;
|
|
43
|
+
/** Pure restriction fallback for standalone consumers without an authority capture. */
|
|
44
|
+
assertCurrent(execution: Readonly<ToolExecution>): void;
|
|
45
|
+
/** Compose this exact registration's native request; never creates an independent approval UI. */
|
|
46
|
+
managedShellDecision?(execution: Readonly<ToolExecution>, action: Exclude<PermissionRuleAction, "deny">, downstream: () => Promise<PreToolDecision>): Promise<PreToolDecision>;
|
|
47
|
+
}
|
|
48
|
+
/** The public native search tools accept pattern/path/include only; no model-controlled rg flags. */
|
|
49
|
+
export declare function parseNativePermissionReadPaths(kind: "read" | "glob" | "grep", input: unknown): readonly string[];
|
|
50
|
+
/** Tool-call-boundary rules only. No body fence, scoped memory, socket isolation or final-inode guarantee. */
|
|
51
|
+
export declare function registerNativePermissionRules(ctx: Context, options: NativePermissionRulesOptions): () => void;
|
|
52
|
+
export interface NativePermissionCapabilities {
|
|
53
|
+
readonly outsideReads: "tool-call-boundary";
|
|
54
|
+
readonly finalInode: false;
|
|
55
|
+
readonly scopedMemory: "not-provided-by-native-rules";
|
|
56
|
+
readonly webFetch: "native-public-only";
|
|
57
|
+
readonly webSearchDestinations: "unsupported";
|
|
58
|
+
readonly proxyAddressBinding: "native-proxy-dependent";
|
|
59
|
+
readonly shellSockets: "native-executor-dependent";
|
|
60
|
+
readonly providerAuthMcp: "not-covered";
|
|
61
|
+
}
|
|
62
|
+
export declare const NATIVE_PERMISSION_CAPABILITIES: NativePermissionCapabilities;
|
|
63
|
+
export interface NativePermissionCapabilityView {
|
|
64
|
+
readonly limits: NativePermissionCapabilities;
|
|
65
|
+
readonly runtime: PermissionRulesStatus;
|
|
66
|
+
/** Registry presence, not executor readiness, network reachability or final-body ownership. */
|
|
67
|
+
readonly tools: readonly {
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly kind: NativePermissionToolIdentity["kind"];
|
|
70
|
+
readonly approval: "native-once";
|
|
71
|
+
readonly scopedMemory: false;
|
|
72
|
+
}[];
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=permission-native-rules.d.ts.map
|