@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,261 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
3
|
+
import { PiAiAdapter, Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
|
+
import { createModels, createProvider, envApiKeyAuth, hasApi } from "@earendil-works/pi-ai";
|
|
5
|
+
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
6
|
+
import { buildBaseOptions } from "@earendil-works/pi-ai/api/simple-options";
|
|
7
|
+
import { LlmError, ReasoningEffortId, assertUsableApiKey, attributionHeaders, freezeMessage, resolveImageAttachmentAccess, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
8
|
+
import { snapshotDsmmCall } from "./host-llm.js";
|
|
9
|
+
import { DsmmMissingProviderError, modelRouteToCall } from "./role-llm.js";
|
|
10
|
+
import { normalizeModelRouteJson } from "./route-json.js";
|
|
11
|
+
function normalizeDeclaredProfiles(config) {
|
|
12
|
+
const profiles = new Map();
|
|
13
|
+
for (const [provider, profile] of Object.entries(Config(config).providers.get())) {
|
|
14
|
+
if (profile.api !== "openai-completions" || !profile.baseURL || !profile.apiKeyEnv || !profile.models?.length
|
|
15
|
+
|| profile.modelOverrides !== undefined && Object.keys(profile.modelOverrides).length > 0) {
|
|
16
|
+
throw new LlmError("Raw execution requires an explicit completions endpoint, credential reference and finite model list without catalog overrides", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
17
|
+
}
|
|
18
|
+
const endpoint = new URL(profile.baseURL);
|
|
19
|
+
if (!["http:", "https:"].includes(endpoint.protocol) || endpoint.username || endpoint.password)
|
|
20
|
+
throw new LlmError("Invalid provider endpoint", "INVALID_CONFIG");
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
const models = profile.models.map(entry => {
|
|
23
|
+
if (!entry.id || seen.has(entry.id))
|
|
24
|
+
throw new LlmError("Model identities must be nonempty and unique", "INVALID_CONFIG");
|
|
25
|
+
seen.add(entry.id);
|
|
26
|
+
const contextWindow = entry.contextWindow ?? profile.defaultContextWindow;
|
|
27
|
+
const maxTokens = entry.maxTokens ?? profile.defaultMaxTokens;
|
|
28
|
+
const input = [...(entry.input?.length ? entry.input : profile.defaultInput)];
|
|
29
|
+
if (input.length === 0)
|
|
30
|
+
throw new LlmError("Declared models must have input modalities", "INVALID_CONFIG");
|
|
31
|
+
if (!Number.isSafeInteger(contextWindow) || contextWindow <= 0 || !Number.isSafeInteger(maxTokens) || maxTokens <= 0)
|
|
32
|
+
throw new LlmError("Model capacities must be positive integers", "INVALID_CONFIG");
|
|
33
|
+
return { id: entry.id, name: entry.name ?? entry.id, provider, api: "openai-completions", baseUrl: profile.baseURL,
|
|
34
|
+
reasoning: false, input, contextWindow: contextWindow, maxTokens: maxTokens,
|
|
35
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
36
|
+
compat: { ...profile.compat, ...entry.compat } };
|
|
37
|
+
});
|
|
38
|
+
const piProvider = createProvider({ id: provider, name: profile.displayName ?? provider, baseUrl: profile.baseURL,
|
|
39
|
+
auth: { apiKey: envApiKeyAuth(provider, []) }, models, api: openAICompletionsApi() });
|
|
40
|
+
profiles.set(provider, {
|
|
41
|
+
provider, displayName: profile.displayName ?? provider, api: profile.api, baseURL: profile.baseURL,
|
|
42
|
+
...(profile.headers === undefined ? {} : { headers: { ...profile.headers } }),
|
|
43
|
+
...(profile.reasoning === undefined ? {} : { reasoning: profile.reasoning }),
|
|
44
|
+
...(profile.thinkingBudgets === undefined ? {} : { thinkingBudgets: { ...profile.thinkingBudgets } }),
|
|
45
|
+
...(profile.cacheRetention === undefined ? {} : { cacheRetention: profile.cacheRetention }),
|
|
46
|
+
...(profile.transport === undefined ? {} : { transport: profile.transport }),
|
|
47
|
+
...(profile.timeoutMs === undefined ? {} : { timeoutMs: profile.timeoutMs }),
|
|
48
|
+
...(profile.websocketConnectTimeoutMs === undefined ? {} : { websocketConnectTimeoutMs: profile.websocketConnectTimeoutMs }),
|
|
49
|
+
apiKeyEnv: brandString(profile.apiKeyEnv),
|
|
50
|
+
streamIdleTimeoutMs: profile.streamIdleTimeoutMs, maxRequestImageBytes: profile.maxRequestImageBytes,
|
|
51
|
+
requestImagePixelBudget: profile.requestImagePixelBudget, requestImageMaxBytes: profile.requestImageMaxBytes,
|
|
52
|
+
retryPolicy: resolveRetryPolicy(profile.retryPolicy?.mode === "normal" ? { ...profile.retryPolicy,
|
|
53
|
+
retryableCodes: profile.retryPolicy.retryableCodes === undefined ? undefined : [...profile.retryPolicy.retryableCodes] } : profile.retryPolicy, `dsmm.providers.${provider}.retryPolicy`), piProvider, modelErrors: new Map(),
|
|
54
|
+
configuredMaxTokens: new Map(profile.models.flatMap(model => model.maxTokens === undefined ? [] : [[model.id, model.maxTokens]])),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (profiles.size === 0)
|
|
58
|
+
throw new LlmError("DSMM provider owner must own at least one declared route", "INVALID_CONFIG");
|
|
59
|
+
return profiles;
|
|
60
|
+
}
|
|
61
|
+
function protectedHeaders(headers) {
|
|
62
|
+
const result = new Headers();
|
|
63
|
+
for (const [key, value] of Object.entries(headers))
|
|
64
|
+
if (value !== null)
|
|
65
|
+
result.set(key, value);
|
|
66
|
+
for (const [key, value] of Object.entries(attributionHeaders()))
|
|
67
|
+
result.set(key, value);
|
|
68
|
+
return Object.fromEntries(result);
|
|
69
|
+
}
|
|
70
|
+
/** Public provider composition preserves the SDK's native content/replay/stream translator. */
|
|
71
|
+
function rawProvider(provider, generation, request, assertCurrent) {
|
|
72
|
+
return {
|
|
73
|
+
...provider,
|
|
74
|
+
streamSimple(model, context, options) {
|
|
75
|
+
const exact = generation.getModel(model.provider, model.id);
|
|
76
|
+
if (exact === undefined || !hasApi(exact, "openai-completions"))
|
|
77
|
+
throw new LlmError("Raw generation has no exact completions model", "UNKNOWN_MODEL");
|
|
78
|
+
const tokenField = ["max_tokens", "max_completion_tokens", "max_output_tokens"].find(key => Object.hasOwn(request.customParameters ?? {}, key));
|
|
79
|
+
const rawBudget = tokenField === undefined ? undefined : request.customParameters?.[tokenField];
|
|
80
|
+
if (rawBudget !== undefined && (typeof rawBudget !== "number" || options?.maxTokens !== undefined && rawBudget > options.maxTokens))
|
|
81
|
+
throw new LlmError("Raw token budget conflicts with the Host request budget", "INVALID_REQUEST");
|
|
82
|
+
const baseOptions = buildBaseOptions(exact, context, { ...options, ...(typeof rawBudget === "number" ? { maxTokens: rawBudget } : {}) });
|
|
83
|
+
if (rawBudget !== undefined && baseOptions.maxTokens !== rawBudget)
|
|
84
|
+
throw new LlmError("Raw token budget exceeds the native context budget", "INVALID_REQUEST");
|
|
85
|
+
const wireOptions = {
|
|
86
|
+
...baseOptions,
|
|
87
|
+
onPayload(payload) {
|
|
88
|
+
assertCurrent();
|
|
89
|
+
request.signal?.throwIfAborted();
|
|
90
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload))
|
|
91
|
+
throw new LlmError("Provider did not build an object payload", "INVALID_REQUEST");
|
|
92
|
+
if (tokenField !== undefined && !Object.hasOwn(payload, tokenField))
|
|
93
|
+
throw new LlmError("Raw token field does not match the declared model protocol", "INVALID_REQUEST");
|
|
94
|
+
const body = { ...payload, ...request.customParameters };
|
|
95
|
+
if (request.reasoningEffort !== undefined)
|
|
96
|
+
Reflect.set(body, "reasoning_effort", request.reasoningEffort);
|
|
97
|
+
if (request.stop !== undefined)
|
|
98
|
+
Reflect.set(body, "stop", [...request.stop]);
|
|
99
|
+
return body;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
return generation.stream(exact, context, { ...wireOptions, transformHeaders: protectedHeaders });
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function createDsmmPiAiProviderPlugin(options, ready) {
|
|
107
|
+
return { name: "dsmm-llm-provider-owner", inject: ["llm", "settings"], Config,
|
|
108
|
+
apply(ctx, config) {
|
|
109
|
+
const expected = Config(options.config).providers.get();
|
|
110
|
+
if (!isDeepStrictEqual(config.providers.get(), expected))
|
|
111
|
+
throw new LlmError("Cold provider entry differs from the Host-owned declaration", "INVALID_CONFIG");
|
|
112
|
+
ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber));
|
|
113
|
+
ctx.on("internal/config", function (_raw, next) {
|
|
114
|
+
const candidate = next();
|
|
115
|
+
if (this === ctx.fiber && !isDeepStrictEqual(Config(candidate).providers.get(), expected))
|
|
116
|
+
throw new LlmError("Provider ownership changes require a cold Host restart", "INVALID_CONFIG");
|
|
117
|
+
return candidate;
|
|
118
|
+
});
|
|
119
|
+
const owner = createDsmmPiAiProviderOwner(ctx, options);
|
|
120
|
+
ctx.provide("dsmmLlmRoutes", owner);
|
|
121
|
+
ready(owner);
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Build the raw executor from declared profiles; borrowed registrations remain native-owned. */
|
|
126
|
+
export function createDsmmPiAiProviderOwner(ctx, options, borrowed) {
|
|
127
|
+
const profiles = normalizeDeclaredProfiles(options.config);
|
|
128
|
+
const identity = Object.freeze({});
|
|
129
|
+
const life = new AbortController();
|
|
130
|
+
const assertCurrent = () => {
|
|
131
|
+
life.signal.throwIfAborted();
|
|
132
|
+
if (borrowed !== undefined) {
|
|
133
|
+
borrowed.signal.throwIfAborted();
|
|
134
|
+
borrowed.assertCurrent();
|
|
135
|
+
}
|
|
136
|
+
else if (ctx.get("dsmmLlmProviderOwner") !== owner)
|
|
137
|
+
throw new LlmError("Provider generation no longer owns its Host service", "INVALID_PREPARED_CALL");
|
|
138
|
+
};
|
|
139
|
+
if (borrowed === undefined)
|
|
140
|
+
ctx.effect(() => () => life.abort(new LlmError("Provider owner retired", "INVALID_PREPARED_CALL")));
|
|
141
|
+
const resolveNamedKey = async (provider, profile, signal) => {
|
|
142
|
+
signal.throwIfAborted();
|
|
143
|
+
assertCurrent();
|
|
144
|
+
if (profile.apiKeyEnv === undefined)
|
|
145
|
+
throw new LlmError("Provider credential reference is required", "MISSING_CREDENTIAL");
|
|
146
|
+
const key = await options.resolveApiKey(provider, profile.apiKeyEnv, signal);
|
|
147
|
+
signal.throwIfAborted();
|
|
148
|
+
assertCurrent();
|
|
149
|
+
if (key === undefined)
|
|
150
|
+
throw new LlmError("Provider credential is unavailable", "MISSING_CREDENTIAL");
|
|
151
|
+
return assertUsableApiKey(key, "dsmm", profile.apiKeyEnv);
|
|
152
|
+
};
|
|
153
|
+
const resolveApiKey = (provider, profile) => resolveNamedKey(provider, profile, life.signal);
|
|
154
|
+
const adapterOptions = { profiles: () => profiles, resolveApiKey, auth: options.auth,
|
|
155
|
+
resolveAttachments: () => ctx.get("attachments"),
|
|
156
|
+
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, path => ctx.get("fs")?.processPathFromHostPath(path), ref),
|
|
157
|
+
onReplayDegrade: () => ctx.logger.warn("DSMM provider replay degraded to native content"),
|
|
158
|
+
};
|
|
159
|
+
const stockStream = (request, preparationSignal) => {
|
|
160
|
+
assertCurrent();
|
|
161
|
+
const signal = AbortSignal.any([life.signal, ...request.signal === undefined ? [] : [request.signal], ...preparationSignal === undefined ? [] : [preparationSignal]]);
|
|
162
|
+
return new PiAiAdapter({ ...adapterOptions, resolveApiKey: (provider, profile) => resolveNamedKey(provider, profile, signal) }).stream(request);
|
|
163
|
+
};
|
|
164
|
+
const stockAdapter = new class extends PiAiAdapter {
|
|
165
|
+
stream(request) { return stockStream(request); }
|
|
166
|
+
async prepareCall(provider, model, signal) {
|
|
167
|
+
const prepared = await super.prepareCall(provider, model, signal);
|
|
168
|
+
signal?.throwIfAborted();
|
|
169
|
+
assertCurrent();
|
|
170
|
+
return { ...prepared, stream: request => stockStream(request, signal) };
|
|
171
|
+
}
|
|
172
|
+
}(adapterOptions);
|
|
173
|
+
const providers = Object.freeze([...profiles.keys()]);
|
|
174
|
+
if (borrowed === undefined) {
|
|
175
|
+
ctx.llm.registerAdapter([...providers], stockAdapter);
|
|
176
|
+
ctx.llm.registerConfigurableProviders([...profiles.values()].map(profile => ({ provider: profile.provider, displayName: profile.displayName,
|
|
177
|
+
settingsNs: options.settingsNamespace, settingsPath: ["providers", profile.provider], declared: true })));
|
|
178
|
+
ctx.llm.registerModelDiscovery(options.settingsNamespace, async (request, signal) => {
|
|
179
|
+
signal?.throwIfAborted();
|
|
180
|
+
if (request.provider === undefined || !profiles.has(request.provider))
|
|
181
|
+
throw new LlmError("Discovery requires a route owned by this Host", "NO_ADAPTER");
|
|
182
|
+
return (await stockAdapter.listModels(request.provider)).map(model => ({ id: model.id, name: model.name, inputModalities: model.inputModalities }));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const models = createModels(options.auth);
|
|
186
|
+
for (const profile of profiles.values())
|
|
187
|
+
models.setProvider(profile.piProvider);
|
|
188
|
+
const owner = Object.freeze({ stockAdapter, providers,
|
|
189
|
+
async resolveRoute(input, signal) {
|
|
190
|
+
const route = normalizeModelRouteJson(input);
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
assertCurrent();
|
|
193
|
+
const call = snapshotDsmmCall(modelRouteToCall(route));
|
|
194
|
+
if (profiles.has(route.provider)) {
|
|
195
|
+
if (models.getModel(route.provider, route.model) === undefined)
|
|
196
|
+
throw new LlmError("Provider has no exact declared model", "UNKNOWN_MODEL");
|
|
197
|
+
await stockAdapter.resolveModel(route.provider, route.model, signal);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
if (!ctx.llm.listProviders().some(provider => provider.id === route.provider))
|
|
201
|
+
throw new DsmmMissingProviderError();
|
|
202
|
+
await ctx.llm.resolveCallConfig(call, signal);
|
|
203
|
+
if (call.customParameters !== undefined)
|
|
204
|
+
throw new LlmError("Raw route parameters require their declared Host provider owner", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
205
|
+
}
|
|
206
|
+
signal?.throwIfAborted();
|
|
207
|
+
assertCurrent();
|
|
208
|
+
return route;
|
|
209
|
+
},
|
|
210
|
+
generation(provider) {
|
|
211
|
+
const profile = profiles.get(provider);
|
|
212
|
+
if (profile === undefined)
|
|
213
|
+
throw new LlmError("Provider is not owned by this Host", "NO_ADAPTER");
|
|
214
|
+
return Object.freeze({ identity, signal: borrowed === undefined ? life.signal : AbortSignal.any([life.signal, borrowed.signal]), retryPolicy: profile.retryPolicy, assertCurrent,
|
|
215
|
+
...(profile.reasoning === undefined ? {} : { defaultReasoningEffort: ReasoningEffortId(profile.reasoning) }),
|
|
216
|
+
async prepareCall(selectedProvider, model, signal, assertAdmission) {
|
|
217
|
+
const assertCall = () => { signal.throwIfAborted(); assertCurrent(); assertAdmission?.(); };
|
|
218
|
+
assertCall();
|
|
219
|
+
if (selectedProvider !== provider || models.getModel(provider, model) === undefined)
|
|
220
|
+
throw new LlmError("Provider has no exact declared model", "UNKNOWN_MODEL");
|
|
221
|
+
const metadata = await (borrowed?.adapter ?? stockAdapter).resolveModel(provider, model, signal);
|
|
222
|
+
assertCall();
|
|
223
|
+
return { model: metadata, stream(request) {
|
|
224
|
+
assertCall();
|
|
225
|
+
request.signal?.throwIfAborted();
|
|
226
|
+
const extended = request;
|
|
227
|
+
const checked = snapshotDsmmCall({ provider: request.provider, model: request.model,
|
|
228
|
+
...(request.reasoningEffort === undefined ? {} : { reasoningEffort: request.reasoningEffort }),
|
|
229
|
+
...(request.temperature === undefined ? {} : { temperature: request.temperature }),
|
|
230
|
+
...(request.maxTokens === undefined ? {} : { maxTokens: request.maxTokens }),
|
|
231
|
+
...(request.stop === undefined ? {} : { stop: request.stop }),
|
|
232
|
+
...(extended.customParameters === undefined ? {} : { customParameters: extended.customParameters }),
|
|
233
|
+
});
|
|
234
|
+
const projectedProfiles = new Map([...profiles].map(([id, item]) => [id, { ...item, reasoning: undefined,
|
|
235
|
+
piProvider: rawProvider(item.piProvider, models, { ...request, ...checked }, assertCall) }]));
|
|
236
|
+
const credentialSignal = request.signal === undefined ? life.signal : AbortSignal.any([life.signal, request.signal]);
|
|
237
|
+
const rawAdapter = new PiAiAdapter({ ...adapterOptions, profiles: () => projectedProfiles,
|
|
238
|
+
resolveApiKey: async (selectedProvider, selectedProfile) => {
|
|
239
|
+
assertCall();
|
|
240
|
+
const key = await resolveNamedKey(selectedProvider, selectedProfile, credentialSignal);
|
|
241
|
+
assertCall();
|
|
242
|
+
return key;
|
|
243
|
+
} });
|
|
244
|
+
const { reasoningEffort: _effort, stop: _stop, ...native } = request;
|
|
245
|
+
const messages = native.messages.map(message => {
|
|
246
|
+
if (message.role !== "assistant" || message.source.replayState === undefined || profiles.has(message.source.provider))
|
|
247
|
+
return message;
|
|
248
|
+
const { replayState: _replay, ...source } = message.source;
|
|
249
|
+
return freezeMessage({ ...message, source });
|
|
250
|
+
});
|
|
251
|
+
return rawAdapter.stream({ ...native, messages });
|
|
252
|
+
} };
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
if (borrowed === undefined)
|
|
258
|
+
ctx.provide("dsmmLlmProviderOwner", owner);
|
|
259
|
+
return owner;
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=native-pi-ai-wire.js.map
|
package/lib/native-scope.js
CHANGED
|
@@ -6,7 +6,7 @@ const sdk = createRequire(require.resolve("@deepseek-ai/dsh-agent-preset-registr
|
|
|
6
6
|
const scope = sdk("@deepseek-ai/dsh-scope");
|
|
7
7
|
export const { scopeOf, scopeParentOf } = scope;
|
|
8
8
|
export function nativeAgentContext(agent) {
|
|
9
|
-
if (!(agent.ctx
|
|
9
|
+
if (!Context.is(agent.ctx) || scopeOf(agent.ctx) !== agent) {
|
|
10
10
|
throw new Error("dsmm skills require the exact native Agent scope, never a shared preset/global scope");
|
|
11
11
|
}
|
|
12
12
|
return agent.ctx;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import * as Native from "@deepseek-ai/dsh-tool-bash";
|
|
3
|
+
export { Config, name } from "@deepseek-ai/dsh-tool-bash";
|
|
4
|
+
export declare const inject: string[];
|
|
5
|
+
export declare function apply(ctx: Context, config: Native.Config): void;
|
|
6
|
+
//# sourceMappingURL=permission-bash.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Native from "@deepseek-ai/dsh-tool-bash";
|
|
2
|
+
export { Config, name } from "@deepseek-ai/dsh-tool-bash";
|
|
3
|
+
export const inject = [...Native.inject, "dsmmPermissionController"];
|
|
4
|
+
export function apply(ctx, config) {
|
|
5
|
+
Native.apply(ctx.dsmmPermissionController.shellScope(ctx, "bash"), config);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=permission-bash.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { PreToolDecision, ToolDefinition, ToolExecution, ToolRunContext } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
import type { RoleRunHolder } from "./role-runs.js";
|
|
5
|
+
import type { NativeCommandEntry } from "./permission-settings.js";
|
|
6
|
+
import type { NativePermissionMode } from "./permission-native-access.js";
|
|
7
|
+
export { PermissionRefusal } from "./permission-errors.js";
|
|
8
|
+
export type PermissionRunHolder = Pick<RoleRunHolder, "state" | "owner" | "invocation" | "holderSignal" | "drained">;
|
|
9
|
+
export interface PermissionExecutionAuthority {
|
|
10
|
+
readonly agent: Agent;
|
|
11
|
+
readonly root: Agent;
|
|
12
|
+
readonly realm: object;
|
|
13
|
+
readonly admissionRevision: string;
|
|
14
|
+
readonly permissionRevision: string;
|
|
15
|
+
readonly owner: object;
|
|
16
|
+
readonly ownerGeneration: string | number;
|
|
17
|
+
readonly signal: AbortSignal;
|
|
18
|
+
readonly run?: PermissionRunHolder;
|
|
19
|
+
}
|
|
20
|
+
export type PermissionRootApprovalAuthority = Pick<PermissionExecutionAuthority, "root" | "realm" | "admissionRevision" | "permissionRevision" | "owner" | "ownerGeneration" | "signal">;
|
|
21
|
+
export interface PermissionExecutionIntegrity {
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
assertCurrent(): void;
|
|
24
|
+
}
|
|
25
|
+
export interface PermissionControlCollaborators {
|
|
26
|
+
current(exec: Readonly<ToolExecution>): PermissionExecutionAuthority;
|
|
27
|
+
rootCurrent?(root: Agent, exec: Readonly<ToolExecution>): PermissionRootApprovalAuthority;
|
|
28
|
+
assertCurrent(authority: PermissionExecutionAuthority, exec: Readonly<ToolExecution>): void;
|
|
29
|
+
/** Physical ownership and real scope lifetime only; never permission/admission epochs. */
|
|
30
|
+
captureIntegrity?(exec: Readonly<ToolExecution>): PermissionExecutionIntegrity;
|
|
31
|
+
}
|
|
32
|
+
export interface PermissionRegistration {
|
|
33
|
+
readonly definition: ToolDefinition;
|
|
34
|
+
readonly registered: ToolDefinition;
|
|
35
|
+
readonly body: ToolDefinition["execute"];
|
|
36
|
+
readonly identity: object;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
assertCurrent?(execution: Readonly<ToolExecution>): void;
|
|
39
|
+
approval(): Context["approval"] | undefined;
|
|
40
|
+
standingMode(execution: Readonly<ToolExecution>): string | undefined;
|
|
41
|
+
unchanged(): boolean;
|
|
42
|
+
active: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function permissionOriginal(value: object): object;
|
|
45
|
+
type Request = Parameters<Context["approval"]["request"]>[0];
|
|
46
|
+
type Outcome = Awaited<ReturnType<Context["approval"]["request"]>>;
|
|
47
|
+
export declare function isSandboxWidening(requested: NativeCommandEntry["sandboxMode"], standing: string | undefined): boolean;
|
|
48
|
+
/** Permission admission precedes native approval; subsequent checks enforce execution integrity only. */
|
|
49
|
+
export declare class PermissionControl {
|
|
50
|
+
private readonly ctx;
|
|
51
|
+
private readonly collaborators;
|
|
52
|
+
private readonly lifetime;
|
|
53
|
+
private readonly bindings;
|
|
54
|
+
private readonly requests;
|
|
55
|
+
private readonly execution;
|
|
56
|
+
constructor(ctx: Context, collaborators: PermissionControlCollaborators);
|
|
57
|
+
compose(exec: Readonly<ToolExecution>, registration: PermissionRegistration, entry: NativeCommandEntry | undefined, action: "inherit" | "allow" | "ask", next: () => Promise<PreToolDecision>, cwd: string): Promise<PreToolDecision>;
|
|
58
|
+
private checkIntegrity;
|
|
59
|
+
guard(exec: Readonly<ToolExecution>): string | undefined;
|
|
60
|
+
answerer(request: Request, next: () => Promise<Outcome>): Promise<Outcome>;
|
|
61
|
+
run<T>(exec: ToolRunContext, args: unknown, registration: PermissionRegistration, body: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
62
|
+
private request;
|
|
63
|
+
/** Scoped original native body; a target fact is consumed only for its exact official request. */
|
|
64
|
+
nativeApproval(request: Request, service: Context["approval"]): Promise<Outcome>;
|
|
65
|
+
approvedTarget(exec: Readonly<ToolExecution>): NativePermissionMode | undefined;
|
|
66
|
+
sandboxMode(): NativePermissionMode | undefined;
|
|
67
|
+
finish(exec: Readonly<ToolExecution>): void;
|
|
68
|
+
revokePolicy(): void;
|
|
69
|
+
revokeRegistration(registration: PermissionRegistration): void;
|
|
70
|
+
revokeAgent(agent: Agent): void;
|
|
71
|
+
retire(): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=permission-control.d.ts.map
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
3
|
+
import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
4
|
+
import { TOOL_ABORTED } from "@deepseek-ai/dsh-tools";
|
|
5
|
+
import { PermissionRefusal, permissionOutcome } from "./permission-errors.js";
|
|
6
|
+
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
7
|
+
export { PermissionRefusal } from "./permission-errors.js";
|
|
8
|
+
export function permissionOriginal(value) { return Reflect.get(value, symbols.original) ?? value; }
|
|
9
|
+
export function isSandboxWidening(requested, standing) {
|
|
10
|
+
return standing === "read-only" || standing === "workspace-write" && requested === "danger-full-access";
|
|
11
|
+
}
|
|
12
|
+
/** Permission admission precedes native approval; subsequent checks enforce execution integrity only. */
|
|
13
|
+
export class PermissionControl {
|
|
14
|
+
ctx;
|
|
15
|
+
collaborators;
|
|
16
|
+
lifetime = new AbortController();
|
|
17
|
+
bindings = new Map();
|
|
18
|
+
requests = new WeakMap();
|
|
19
|
+
execution = new AsyncLocalStorage();
|
|
20
|
+
constructor(ctx, collaborators) {
|
|
21
|
+
this.ctx = ctx;
|
|
22
|
+
this.collaborators = collaborators;
|
|
23
|
+
}
|
|
24
|
+
async compose(exec, registration, entry, action, next, cwd) {
|
|
25
|
+
const nativeOnly = nativeStandingFullAccess(this.ctx, exec.agent);
|
|
26
|
+
const authority = nativeOnly ? undefined : this.collaborators.current(exec);
|
|
27
|
+
if (authority !== undefined) {
|
|
28
|
+
registration.assertCurrent?.(exec);
|
|
29
|
+
this.collaborators.assertCurrent(authority, exec);
|
|
30
|
+
}
|
|
31
|
+
const agent = exec.agent, realm = agent?.ctx;
|
|
32
|
+
const integrity = this.collaborators.captureIntegrity?.(exec) ?? { assertCurrent: () => {
|
|
33
|
+
if (agent !== undefined && (this.ctx.agents.get(agent.id) !== agent || agent.ctx !== realm))
|
|
34
|
+
throw new PermissionRefusal("not-owned");
|
|
35
|
+
if (authority === undefined)
|
|
36
|
+
return;
|
|
37
|
+
const current = this.collaborators.current(exec);
|
|
38
|
+
if (current.agent !== authority.agent || current.root !== authority.root || current.realm !== authority.realm
|
|
39
|
+
|| current.owner !== authority.owner || current.ownerGeneration !== authority.ownerGeneration)
|
|
40
|
+
throw new PermissionRefusal("not-owned");
|
|
41
|
+
} };
|
|
42
|
+
const args = exec.arguments;
|
|
43
|
+
const officialMode = !nativeOnly && (args.sandbox_permissions === "workspace-write" || args.sandbox_permissions === "danger-full-access") ? args.sandbox_permissions : undefined;
|
|
44
|
+
const standing = registration.standingMode(exec);
|
|
45
|
+
const target = officialMode ?? (entry === undefined ? undefined : isSandboxWidening(entry.sandboxMode, standing) ? entry.sandboxMode : standing ?? entry.sandboxMode);
|
|
46
|
+
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."}`;
|
|
47
|
+
const lifetime = new AbortController();
|
|
48
|
+
const binding = { exec, args: exec.arguments, agent: exec.agent, callId: exec.callId, name: exec.name,
|
|
49
|
+
registration, root: authority?.root, integrity, entry, officialMode,
|
|
50
|
+
target: target === "workspace-write" || target === "danger-full-access" ? target : undefined,
|
|
51
|
+
reason, ask: action === "ask" || entry?.mode === "ask", lifetime,
|
|
52
|
+
signal: AbortSignal.any([exec.signal, lifetime.signal, this.lifetime.signal,
|
|
53
|
+
...integrity.signal === undefined ? [] : [integrity.signal], ...registration.signal === undefined ? [] : [registration.signal]]),
|
|
54
|
+
entered: false, nativeRequest: false };
|
|
55
|
+
this.checkIntegrity(binding);
|
|
56
|
+
this.bindings.set(exec.token, binding);
|
|
57
|
+
const downstream = await next();
|
|
58
|
+
if (exec.signal.aborted)
|
|
59
|
+
return { kind: "cancel" };
|
|
60
|
+
this.checkIntegrity(binding);
|
|
61
|
+
if (downstream.kind === "deny" || downstream.kind === "cancel")
|
|
62
|
+
return downstream;
|
|
63
|
+
if (nativeOnly)
|
|
64
|
+
return downstream;
|
|
65
|
+
const needsAsk = downstream.kind === "ask" || binding.ask && (entry === undefined || officialMode !== undefined);
|
|
66
|
+
if (!needsAsk)
|
|
67
|
+
return downstream;
|
|
68
|
+
const reasons = [downstream.kind === "ask" ? downstream.reason : undefined, reason].filter(Boolean).join("\n");
|
|
69
|
+
const displayReason = Object.freeze({ en: reasons, zh: reasons,
|
|
70
|
+
...downstream.kind === "ask" && downstream.displayReason !== undefined ? Object.fromEntries(Object.entries(downstream.displayReason).map(([locale, text]) => [locale, `${text}\n${reason}`])) : {} });
|
|
71
|
+
if (binding.target === undefined)
|
|
72
|
+
return { kind: "ask", reason: reasons, displayReason };
|
|
73
|
+
const approval = registration.approval();
|
|
74
|
+
if (approval === undefined || exec.agent === undefined)
|
|
75
|
+
return { kind: "deny", reason: "Native approval is unavailable for this command." };
|
|
76
|
+
const outcome = await approval.request({ agent: exec.agent, callId: exec.callId, toolName: exec.name,
|
|
77
|
+
reason: reasons, displayReason, signal: binding.signal });
|
|
78
|
+
if (exec.signal.aborted)
|
|
79
|
+
return { kind: "cancel" };
|
|
80
|
+
this.checkIntegrity(binding);
|
|
81
|
+
if (outcome !== "allowed-once")
|
|
82
|
+
return { kind: "deny", reason: `Native command approval ${outcome}.` };
|
|
83
|
+
binding.approvedTarget = binding.target;
|
|
84
|
+
return { kind: "allow" };
|
|
85
|
+
}
|
|
86
|
+
checkIntegrity(binding) {
|
|
87
|
+
if (binding.signal.aborted || binding.exec.signal.aborted)
|
|
88
|
+
throw new HarnessError("Permission-controlled call cancelled.", TOOL_ABORTED);
|
|
89
|
+
const { exec, registration } = binding;
|
|
90
|
+
if (exec.arguments !== binding.args || exec.agent !== binding.agent || exec.callId !== binding.callId || exec.name !== binding.name
|
|
91
|
+
|| !registration.active || !registration.unchanged() || registration.definition.execute !== registration.body
|
|
92
|
+
|| this.ctx.tools.get(binding.name, binding.agent) !== registration.registered)
|
|
93
|
+
throw new PermissionRefusal("stale");
|
|
94
|
+
binding.integrity.assertCurrent();
|
|
95
|
+
}
|
|
96
|
+
guard(exec) {
|
|
97
|
+
const binding = this.bindings.get(exec.token);
|
|
98
|
+
if (binding === undefined)
|
|
99
|
+
return undefined;
|
|
100
|
+
try {
|
|
101
|
+
this.checkIntegrity(binding);
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return "Native command execution identity is no longer current.";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async answerer(request, next) {
|
|
109
|
+
const owned = this.requests.get(request);
|
|
110
|
+
if (owned === undefined)
|
|
111
|
+
return next();
|
|
112
|
+
this.checkIntegrity(owned.binding);
|
|
113
|
+
return owned.allow ? "allowed-once" : permissionOutcome(next, owned.binding.signal, "cancelled");
|
|
114
|
+
}
|
|
115
|
+
async run(exec, args, registration, body) {
|
|
116
|
+
const binding = this.bindings.get(exec.token);
|
|
117
|
+
if (binding === undefined || binding.registration !== registration || binding.entered || args !== binding.args)
|
|
118
|
+
throw new PermissionRefusal("stale");
|
|
119
|
+
binding.signal = AbortSignal.any([binding.signal, exec.signal]);
|
|
120
|
+
this.checkIntegrity(binding);
|
|
121
|
+
binding.entered = true;
|
|
122
|
+
try {
|
|
123
|
+
if (binding.entry !== undefined && binding.officialMode === undefined && !nativeStandingFullAccess(this.ctx, exec.agent)) {
|
|
124
|
+
if (binding.approvedTarget === undefined) {
|
|
125
|
+
const approval = registration.approval();
|
|
126
|
+
if (approval === undefined || exec.agent === undefined)
|
|
127
|
+
throw new PermissionRefusal("unavailable");
|
|
128
|
+
const request = { agent: exec.agent, toolName: exec.name, callId: exec.callId, signal: binding.signal, reason: binding.reason };
|
|
129
|
+
const outcome = await this.request(binding, request, approval, binding.entry.mode === "allow" && !binding.ask);
|
|
130
|
+
if (outcome === "cancelled")
|
|
131
|
+
throw new HarnessError("Native permission request cancelled.", TOOL_ABORTED);
|
|
132
|
+
if (outcome !== "allowed-once")
|
|
133
|
+
throw new PermissionRefusal(outcome === "unavailable" ? "unavailable" : "denied");
|
|
134
|
+
binding.approvedTarget = binding.target;
|
|
135
|
+
}
|
|
136
|
+
binding.mode = binding.approvedTarget;
|
|
137
|
+
}
|
|
138
|
+
return await this.execution.run(binding, () => body(binding.signal));
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
this.finish(binding.exec);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async request(binding, request, service, allow) {
|
|
145
|
+
this.requests.set(request, { binding, allow });
|
|
146
|
+
try {
|
|
147
|
+
const result = await service.request(request);
|
|
148
|
+
this.checkIntegrity(binding);
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
this.requests.delete(request);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Scoped original native body; a target fact is consumed only for its exact official request. */
|
|
156
|
+
async nativeApproval(request, service) {
|
|
157
|
+
const binding = this.execution.getStore();
|
|
158
|
+
if (binding === undefined || binding.officialMode === undefined || binding.nativeRequest || request.agent !== binding.agent
|
|
159
|
+
|| request.callId !== binding.callId || request.toolName !== binding.registration.definition.name || request.signal !== binding.signal)
|
|
160
|
+
return service.request(request);
|
|
161
|
+
this.checkIntegrity(binding);
|
|
162
|
+
binding.nativeRequest = true;
|
|
163
|
+
if (binding.approvedTarget === binding.officialMode) {
|
|
164
|
+
binding.approvedTarget = undefined;
|
|
165
|
+
return "allowed-once";
|
|
166
|
+
}
|
|
167
|
+
const actual = { ...request, reason: [request.reason, binding.reason].filter(Boolean).join("\n") };
|
|
168
|
+
const covers = binding.entry !== undefined && (binding.entry.sandboxMode === "danger-full-access" || binding.officialMode === "workspace-write");
|
|
169
|
+
return this.request(binding, actual, service, covers && binding.entry.mode === "allow" && !binding.ask);
|
|
170
|
+
}
|
|
171
|
+
approvedTarget(exec) {
|
|
172
|
+
const binding = this.bindings.get(exec.token);
|
|
173
|
+
if (binding === undefined)
|
|
174
|
+
return undefined;
|
|
175
|
+
this.checkIntegrity(binding);
|
|
176
|
+
return binding.approvedTarget;
|
|
177
|
+
}
|
|
178
|
+
sandboxMode() {
|
|
179
|
+
const binding = this.execution.getStore();
|
|
180
|
+
if (binding === undefined || binding.mode === undefined)
|
|
181
|
+
return undefined;
|
|
182
|
+
this.checkIntegrity(binding);
|
|
183
|
+
const mode = binding.mode;
|
|
184
|
+
binding.mode = undefined;
|
|
185
|
+
binding.approvedTarget = undefined;
|
|
186
|
+
return mode;
|
|
187
|
+
}
|
|
188
|
+
finish(exec) {
|
|
189
|
+
const binding = this.bindings.get(exec.token);
|
|
190
|
+
if (binding !== undefined) {
|
|
191
|
+
binding.mode = undefined;
|
|
192
|
+
binding.approvedTarget = undefined;
|
|
193
|
+
binding.lifetime.abort();
|
|
194
|
+
}
|
|
195
|
+
this.bindings.delete(exec.token);
|
|
196
|
+
}
|
|
197
|
+
revokePolicy() { }
|
|
198
|
+
revokeRegistration(registration) { registration.active = false; }
|
|
199
|
+
revokeAgent(agent) { for (const binding of this.bindings.values())
|
|
200
|
+
if (binding.agent === agent || binding.root === agent)
|
|
201
|
+
this.finish(binding.exec); }
|
|
202
|
+
retire() { this.lifetime.abort(); for (const binding of this.bindings.values())
|
|
203
|
+
this.finish(binding.exec); }
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=permission-control.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
5
|
+
import { PermissionControl } from "./permission-control.js";
|
|
6
|
+
import type { PermissionControlCollaborators } from "./permission-control.js";
|
|
7
|
+
import type { PermissionShellIdentity } from "./permission-shell.js";
|
|
8
|
+
import type { NativePermissionCapabilityView, NativePermissionFileSystem, NativePermissionToolIdentity } from "./permission-native-rules.js";
|
|
9
|
+
import type { PermissionRulesRuntimeSync } from "./permission-rules.js";
|
|
10
|
+
import type { NativePermissionAccess } from "./permission-native-access.js";
|
|
11
|
+
export type ManagedPermissionShell = "bash" | "pwsh";
|
|
12
|
+
export type ManagedPermissionTool = "fs" | "fs-search" | "web";
|
|
13
|
+
type NativeToolKind = Exclude<NativePermissionToolIdentity["kind"], "shell">;
|
|
14
|
+
export declare const PERMISSION_CONTROLLER_INJECT: readonly ["tools", "agents"];
|
|
15
|
+
export interface PermissionControllerOptions {
|
|
16
|
+
/** The existing live Core owner/admission/Root/realm/run facts, not serialized settings or a ready boolean. */
|
|
17
|
+
readonly authority: PermissionControlCollaborators;
|
|
18
|
+
readonly rules: PermissionRulesRuntimeSync;
|
|
19
|
+
/** Native registration identity; only an explicit capability proves Shell read semantics. */
|
|
20
|
+
shellIdentity(scope: Context, kind: ManagedPermissionShell): PermissionShellIdentity;
|
|
21
|
+
coLocated?(scope: Context, execution: Readonly<ToolExecution>, fs: NativePermissionFileSystem): boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ManagedPermissionShellCoverage {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly kind: ManagedPermissionShell;
|
|
26
|
+
readonly boundary: "cooperative-body";
|
|
27
|
+
readonly approval: "native-once";
|
|
28
|
+
}
|
|
29
|
+
export interface ManagedPermissionToolCoverage {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly kind: NativeToolKind;
|
|
32
|
+
readonly boundary: "tool-call-boundary";
|
|
33
|
+
readonly approval: "native-once";
|
|
34
|
+
readonly pathEvidence: "native-fs" | "requires-colocation" | "not-applicable";
|
|
35
|
+
}
|
|
36
|
+
/** Ordinary module owner. Only registrations captured by native module façades are managed. */
|
|
37
|
+
export declare class DsmmPermissionController extends Service {
|
|
38
|
+
private readonly options;
|
|
39
|
+
readonly permissions: PermissionControl;
|
|
40
|
+
readonly rules: PermissionRulesRuntimeSync;
|
|
41
|
+
private readonly registrations;
|
|
42
|
+
private readonly toolRegistrations;
|
|
43
|
+
private readonly lifetime;
|
|
44
|
+
constructor(ctx: Context, options: PermissionControllerOptions);
|
|
45
|
+
/** Public in-process facts for DSMM consumers; requested/configured modes never grant access. */
|
|
46
|
+
nativeAccess(exec: Readonly<ToolExecution>): NativePermissionAccess;
|
|
47
|
+
/** Optional public injection also captures definitions registered before Core publishes this service. */
|
|
48
|
+
static toolScope(scope: Context, kind: ManagedPermissionTool): Context;
|
|
49
|
+
toolScope(scope: Context, kind: ManagedPermissionTool): Context;
|
|
50
|
+
private captureTool;
|
|
51
|
+
/** The receiver is captured before extend: do not register into an Agent's own layer. */
|
|
52
|
+
shellScope(scope: Context, kind: ManagedPermissionShell): Context;
|
|
53
|
+
private registerShell;
|
|
54
|
+
coverage(agent?: Agent): readonly ManagedPermissionShellCoverage[];
|
|
55
|
+
/** Actual visible non-Shell registrations, not executor readiness or co-location proof. */
|
|
56
|
+
toolCoverage(agent?: Agent): readonly ManagedPermissionToolCoverage[];
|
|
57
|
+
capabilities(agent?: Agent): NativePermissionCapabilityView;
|
|
58
|
+
retire(): void;
|
|
59
|
+
}
|
|
60
|
+
declare module "@deepseek-ai/cordis" {
|
|
61
|
+
interface Context {
|
|
62
|
+
dsmmPermissionController: DsmmPermissionController;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Parent supplies the real existing Core collaborators and A's sole runtime-sync owner. */
|
|
66
|
+
export declare function installPermissionController(ctx: Context, options: PermissionControllerOptions): DsmmPermissionController;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=permission-controller.d.ts.map
|