@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,397 @@
|
|
|
1
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
3
|
+
import { currentManagedCreation, exactRegistry } from "./agent-registry.js";
|
|
4
|
+
function original(value) {
|
|
5
|
+
return Reflect.get(value, symbols.original) ?? value;
|
|
6
|
+
}
|
|
7
|
+
function unauthorized() {
|
|
8
|
+
throw new SubagentError("DSMM delivery requires current exact direct-parent authority.", "UNAUTHORIZED");
|
|
9
|
+
}
|
|
10
|
+
/** Public plugin/status dispatch precedes async cleanup, including ancestor Host teardown. */
|
|
11
|
+
export function scopeLifetime(scope, label, revoke, install = () => { }) {
|
|
12
|
+
// Cordis's public ambient const enum has no JavaScript export for source-only Node loading.
|
|
13
|
+
const unloading = 5, disposed = 4;
|
|
14
|
+
return scope.effect(() => {
|
|
15
|
+
// Context.fiber can be a facade; its public readonly ctx identifies the exact owner.
|
|
16
|
+
const owners = new Map();
|
|
17
|
+
for (let fiber = scope.fiber; !owners.has(fiber.ctx); fiber = fiber.parent.fiber)
|
|
18
|
+
owners.set(fiber.ctx, fiber);
|
|
19
|
+
let retired = false;
|
|
20
|
+
let detachPlugin = () => { }, detachStatus = () => { };
|
|
21
|
+
const retire = () => { retired = true; revoke(); };
|
|
22
|
+
const cleanup = () => { detachPlugin(); detachStatus(); retire(); };
|
|
23
|
+
try {
|
|
24
|
+
detachPlugin = scope.on("internal/plugin", (fiber) => {
|
|
25
|
+
if (owners.has(fiber.ctx) && fiber.uid === null)
|
|
26
|
+
retire();
|
|
27
|
+
}, { global: true, prepend: true });
|
|
28
|
+
detachStatus = scope.on("internal/status", (fiber) => {
|
|
29
|
+
if (owners.has(fiber.ctx) && (fiber.state === unloading || fiber.state === disposed))
|
|
30
|
+
retire();
|
|
31
|
+
}, { global: true, prepend: true });
|
|
32
|
+
if ([...owners.values()].some((fiber) => fiber.uid === null || fiber.state === unloading || fiber.state === disposed))
|
|
33
|
+
unauthorized();
|
|
34
|
+
install();
|
|
35
|
+
if (retired)
|
|
36
|
+
unauthorized();
|
|
37
|
+
return cleanup;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
cleanup();
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}, label);
|
|
44
|
+
}
|
|
45
|
+
/** Stable Host lifetime; profile entry disposal must not replace this object. */
|
|
46
|
+
export class DsmmDeliveryAuthority {
|
|
47
|
+
ctx;
|
|
48
|
+
lifetime = new AbortController();
|
|
49
|
+
parents = new Map();
|
|
50
|
+
tickets = new WeakMap();
|
|
51
|
+
managedIds = new Set();
|
|
52
|
+
managed = new WeakMap();
|
|
53
|
+
liveManaged = new Set();
|
|
54
|
+
retiredAgents = new WeakSet();
|
|
55
|
+
binding;
|
|
56
|
+
connection;
|
|
57
|
+
providersReady;
|
|
58
|
+
changed;
|
|
59
|
+
hostClassifier;
|
|
60
|
+
constructor(ctx, providersReady = () => true, changed = () => { }, hostClassifier) {
|
|
61
|
+
this.ctx = ctx;
|
|
62
|
+
this.providersReady = providersReady;
|
|
63
|
+
this.changed = changed;
|
|
64
|
+
this.hostClassifier = hostClassifier;
|
|
65
|
+
scopeLifetime(ctx, "dsmm.deliveryAuthority: revoke Host tickets", () => {
|
|
66
|
+
this.lifetime.abort();
|
|
67
|
+
for (const parent of this.liveManaged)
|
|
68
|
+
this.revokeParent(parent, "host-disposed");
|
|
69
|
+
for (const parent of this.parents.keys())
|
|
70
|
+
this.revokeParent(parent, "host-disposed");
|
|
71
|
+
this.changed();
|
|
72
|
+
});
|
|
73
|
+
ctx.on("agent/disposed", ({ agent }) => this.revokeParent(agent, "registry-residency-disposed"), { global: true });
|
|
74
|
+
ctx.on("agent/created", ({ agent, signal }) => {
|
|
75
|
+
const retire = () => this.revokeParent(agent, "agent-lifecycle-ended");
|
|
76
|
+
signal?.addEventListener("abort", retire, { once: true });
|
|
77
|
+
if (signal?.aborted)
|
|
78
|
+
retire();
|
|
79
|
+
const operation = currentManagedCreation();
|
|
80
|
+
if (operation === undefined || !operation.claimed || operation.childId !== agent.id
|
|
81
|
+
|| operation.registry !== exactRegistry(ctx.agents) || !ctx.agents.isOwnedBy(agent.id, operation.parent))
|
|
82
|
+
return;
|
|
83
|
+
if (operation.child !== agent || operation.retired)
|
|
84
|
+
unauthorized();
|
|
85
|
+
if (signal?.aborted || operation.ownerSignal?.aborted)
|
|
86
|
+
retire();
|
|
87
|
+
}, { global: true, prepend: true });
|
|
88
|
+
ctx.inject(["connection"], (connectionCtx) => {
|
|
89
|
+
const connection = connectionCtx.get("connection");
|
|
90
|
+
const state = { owner: original(connection), browserPeer: connection.browserPeer, controller: new AbortController() };
|
|
91
|
+
const revoke = () => {
|
|
92
|
+
state.controller.abort();
|
|
93
|
+
if (this.connection === state)
|
|
94
|
+
this.connection = undefined;
|
|
95
|
+
};
|
|
96
|
+
connection.browserPeer.signal.addEventListener("abort", revoke, { once: true });
|
|
97
|
+
// Browser peer scope ancestry includes the exact providing Connection fiber.
|
|
98
|
+
const detachPeer = scopeLifetime(connection.browserPeer.ctx, "dsmm.deliveryAuthority: revoke browser and Connection lifetime", revoke);
|
|
99
|
+
scopeLifetime(connectionCtx, "dsmm.deliveryAuthority: release Connection observer", () => { revoke(); connection.browserPeer.signal.removeEventListener("abort", revoke); detachPeer(); }, () => {
|
|
100
|
+
if (state.controller.signal.aborted || connection.browserPeer.signal.aborted)
|
|
101
|
+
unauthorized();
|
|
102
|
+
this.connection = state;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
view() {
|
|
107
|
+
const ready = !this.lifetime.signal.aborted && this.binding?.enabled === true && this.providersReady();
|
|
108
|
+
return { binding: "dsmm", deliveryFenceReady: ready, restartRequired: false,
|
|
109
|
+
...(ready ? {} : { reason: "authority-not-ready" }) };
|
|
110
|
+
}
|
|
111
|
+
/** Bind once per entry scope; teardown revokes its pending tickets synchronously. */
|
|
112
|
+
bindPolicy(scope, owner, policy) {
|
|
113
|
+
if (this.lifetime.signal.aborted || this.binding !== undefined)
|
|
114
|
+
unauthorized();
|
|
115
|
+
const binding = { owner, policy, enabled: false };
|
|
116
|
+
return scopeLifetime(scope, "dsmm.deliveryAuthority: release policy owner", () => {
|
|
117
|
+
if (this.binding !== binding)
|
|
118
|
+
return;
|
|
119
|
+
this.binding = undefined;
|
|
120
|
+
this.revokeOwner(owner, "policy-owner-disposed");
|
|
121
|
+
this.changed();
|
|
122
|
+
}, () => {
|
|
123
|
+
this.binding = binding;
|
|
124
|
+
this.changed();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Called after A/B admission/capture guards are installed, not at service mount. */
|
|
128
|
+
enablePolicy(owner) {
|
|
129
|
+
if (this.binding?.owner !== owner || this.lifetime.signal.aborted)
|
|
130
|
+
unauthorized();
|
|
131
|
+
this.binding.enabled = true;
|
|
132
|
+
this.changed();
|
|
133
|
+
}
|
|
134
|
+
isManaged(parent, intent = "delivery") {
|
|
135
|
+
if (this.managed.has(parent))
|
|
136
|
+
return true;
|
|
137
|
+
// An admitted native parent still needs current proof of its delivery target's identity.
|
|
138
|
+
if (intent === "delivery" && this.parents.has(parent))
|
|
139
|
+
return true;
|
|
140
|
+
if (intent === "creation" && parent.session.header.origin !== "subagent" && this.binding?.policy.classifyParent(parent) === "native")
|
|
141
|
+
return false;
|
|
142
|
+
if (this.managedIds.has(parent.id))
|
|
143
|
+
return true;
|
|
144
|
+
// An absent binding is unknown authority, never proof of a native caller.
|
|
145
|
+
const hostKind = this.hostClassifier?.(parent);
|
|
146
|
+
if (hostKind === "dsmm")
|
|
147
|
+
return true;
|
|
148
|
+
const kind = this.binding?.policy.classifyParent(parent) ?? hostKind;
|
|
149
|
+
return kind !== "native";
|
|
150
|
+
}
|
|
151
|
+
registerParent(parent, admission, owner) {
|
|
152
|
+
if (this.retiredAgents.has(parent) || this.binding?.owner !== owner || this.lifetime.signal.aborted
|
|
153
|
+
|| this.ctx.get("agents")?.get(parent.id) !== parent || admission.epoch.length === 0)
|
|
154
|
+
unauthorized();
|
|
155
|
+
const managed = this.managed.get(parent);
|
|
156
|
+
if (managed === undefined && parent.session.header.origin === "subagent")
|
|
157
|
+
unauthorized();
|
|
158
|
+
if (managed?.status === "retired")
|
|
159
|
+
unauthorized();
|
|
160
|
+
if (managed?.status === "pending") {
|
|
161
|
+
if (managed.admission !== undefined && (managed.admission !== admission || managed.owner !== owner))
|
|
162
|
+
unauthorized();
|
|
163
|
+
managed.admission = admission;
|
|
164
|
+
managed.owner = owner;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const existing = this.parents.get(parent);
|
|
168
|
+
if (existing !== undefined) {
|
|
169
|
+
if (existing.owner !== owner || existing.admission !== admission || existing.publishing)
|
|
170
|
+
unauthorized();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// Durable IDs may be reused on cold resume; the former exact Agent cannot retain authority.
|
|
174
|
+
for (const [previous, state] of this.parents) {
|
|
175
|
+
if (previous.id === parent.id)
|
|
176
|
+
this.revokeParent(state.parent, "residency-replaced");
|
|
177
|
+
}
|
|
178
|
+
const state = { parent, owner, admission, epoch: new AbortController(), lifetime: new AbortController(),
|
|
179
|
+
publishing: false, usedEpochs: new Set([admission.epoch]) };
|
|
180
|
+
state.detachResidency = scopeLifetime(parent.ctx, "dsmm.deliveryAuthority: revoke exact Agent residency", () => {
|
|
181
|
+
if (this.parents.get(parent) === state)
|
|
182
|
+
this.revokeParent(parent, "residency-disposed");
|
|
183
|
+
}, () => {
|
|
184
|
+
this.parents.set(parent, state);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
beginPending(operation, agent) {
|
|
188
|
+
if (operation.child !== undefined || operation.retired || this.managed.has(agent) || this.retiredAgents.has(agent))
|
|
189
|
+
unauthorized();
|
|
190
|
+
operation.child = agent;
|
|
191
|
+
let release;
|
|
192
|
+
const ready = new Promise(done => { release = done; });
|
|
193
|
+
this.managed.set(agent, { operation, status: "pending", ready, release });
|
|
194
|
+
this.liveManaged.add(agent);
|
|
195
|
+
this.managedIds.add(operation.parent.id);
|
|
196
|
+
this.managedIds.add(agent.id);
|
|
197
|
+
const retire = () => this.revokeParent(agent, "managed-owner-ended");
|
|
198
|
+
operation.ownerSignal?.addEventListener("abort", retire, { once: true });
|
|
199
|
+
scopeLifetime(agent.ctx, "dsmm.deliveryAuthority: pending residency", retire);
|
|
200
|
+
if (operation.ownerSignal?.aborted || this.lifetime.signal.aborted)
|
|
201
|
+
retire();
|
|
202
|
+
}
|
|
203
|
+
/** Receipt acceptance, not the caller's old operation signal, opens execution. */
|
|
204
|
+
promote(operation) {
|
|
205
|
+
const child = operation.child, managed = child === undefined ? undefined : this.managed.get(child);
|
|
206
|
+
if (child === undefined || managed?.operation !== operation)
|
|
207
|
+
throw new SubagentError("Managed receipt has no exact prepared child", "UNAUTHORIZED");
|
|
208
|
+
if (managed.status !== "pending" || operation.retired || operation.ownerSignal?.aborted)
|
|
209
|
+
throw new SubagentError("Managed receipt residency ended before promotion", "UNAUTHORIZED");
|
|
210
|
+
if (this.ctx.agents.get(child.id) !== child || !this.ctx.agents.isOwnedBy(child.id, operation.parent)
|
|
211
|
+
|| exactRegistry(this.ctx.agents) !== operation.registry)
|
|
212
|
+
throw new SubagentError("Managed receipt registry or ownership changed", "UNAUTHORIZED");
|
|
213
|
+
if (managed.admission === undefined || managed.owner !== operation.owner)
|
|
214
|
+
throw new SubagentError("Managed receipt has no completed capture admission", "UNAUTHORIZED");
|
|
215
|
+
managed.status = "active";
|
|
216
|
+
try {
|
|
217
|
+
this.registerParent(child, managed.admission, managed.owner);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
this.revokeParent(child, "promotion-failed");
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
managed.release();
|
|
224
|
+
}
|
|
225
|
+
assertSender(parent) {
|
|
226
|
+
if (this.retiredAgents.has(parent))
|
|
227
|
+
unauthorized();
|
|
228
|
+
const state = this.managed.get(parent);
|
|
229
|
+
if (state !== undefined && state.status !== "active")
|
|
230
|
+
unauthorized();
|
|
231
|
+
}
|
|
232
|
+
async waitForPromotion(parent, signal) {
|
|
233
|
+
if (this.retiredAgents.has(parent))
|
|
234
|
+
unauthorized();
|
|
235
|
+
const state = this.managed.get(parent);
|
|
236
|
+
if (state === undefined || state.status === "active")
|
|
237
|
+
return;
|
|
238
|
+
if (state.status === "retired" || signal === undefined)
|
|
239
|
+
unauthorized();
|
|
240
|
+
signal.throwIfAborted();
|
|
241
|
+
await new Promise((resolve, reject) => {
|
|
242
|
+
const abort = () => { signal.removeEventListener("abort", abort); reject(signal.reason); };
|
|
243
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
244
|
+
void state.ready.then(() => { signal.removeEventListener("abort", abort); resolve(); });
|
|
245
|
+
});
|
|
246
|
+
signal.throwIfAborted();
|
|
247
|
+
this.assertSender(parent);
|
|
248
|
+
}
|
|
249
|
+
retireOperation(operation, reason) {
|
|
250
|
+
operation.retired = true;
|
|
251
|
+
if (operation.child !== undefined)
|
|
252
|
+
this.revokeParent(operation.child, reason);
|
|
253
|
+
}
|
|
254
|
+
acquireParentTicket(parent) {
|
|
255
|
+
if (!this.view().deliveryFenceReady)
|
|
256
|
+
unauthorized();
|
|
257
|
+
const state = this.current(parent);
|
|
258
|
+
const ticket = Object.freeze({ parent, owner: state.owner, admission: state.admission, parentEpoch: state.admission.epoch,
|
|
259
|
+
signal: AbortSignal.any([state.epoch.signal, state.lifetime.signal, this.lifetime.signal]) });
|
|
260
|
+
this.tickets.set(ticket, state);
|
|
261
|
+
return ticket;
|
|
262
|
+
}
|
|
263
|
+
assertTicket(ticket) {
|
|
264
|
+
ticket.signal.throwIfAborted();
|
|
265
|
+
if (!this.view().deliveryFenceReady)
|
|
266
|
+
unauthorized();
|
|
267
|
+
const state = this.current(ticket.parent);
|
|
268
|
+
if (this.tickets.get(ticket) !== state || state.owner !== ticket.owner || state.admission !== ticket.admission
|
|
269
|
+
|| state.admission.epoch !== ticket.parentEpoch)
|
|
270
|
+
unauthorized();
|
|
271
|
+
}
|
|
272
|
+
async resolveChildEvidence(ticket, childId, signal) {
|
|
273
|
+
signal.throwIfAborted();
|
|
274
|
+
this.assertTicket(ticket);
|
|
275
|
+
const policy = this.binding.policy;
|
|
276
|
+
const evidence = await policy.resolveChildEvidence(ticket, childId, signal);
|
|
277
|
+
signal.throwIfAborted();
|
|
278
|
+
this.assertTicket(ticket);
|
|
279
|
+
return evidence;
|
|
280
|
+
}
|
|
281
|
+
/** Validate the target and return whether its materialization requires DSMM capture. */
|
|
282
|
+
assertDelivery(ticket, childId, evidence) {
|
|
283
|
+
this.assertTicket(ticket);
|
|
284
|
+
this.binding.policy.assertDelivery(ticket, childId, evidence);
|
|
285
|
+
const managed = this.binding.policy.isNativeEvidence?.(evidence) !== true;
|
|
286
|
+
if (!managed && this.managedIds.has(childId))
|
|
287
|
+
unauthorized();
|
|
288
|
+
this.assertTicket(ticket);
|
|
289
|
+
return managed;
|
|
290
|
+
}
|
|
291
|
+
prepareParentAdmission(parent, expectedEpoch, nextAdmission) {
|
|
292
|
+
if (!this.view().deliveryFenceReady)
|
|
293
|
+
unauthorized();
|
|
294
|
+
const state = this.current(parent);
|
|
295
|
+
if (state.admission.epoch !== expectedEpoch || nextAdmission.epoch.length === 0 || state.usedEpochs.has(nextAdmission.epoch))
|
|
296
|
+
unauthorized();
|
|
297
|
+
state.prepared = { expectedEpoch, expected: state.admission, admission: nextAdmission, controller: new AbortController() };
|
|
298
|
+
}
|
|
299
|
+
/** Core configuration uses the same exact parent state without acquiring delivery capability. */
|
|
300
|
+
assertCoreParentAdmission(parent, owner, expected) {
|
|
301
|
+
const state = this.current(parent);
|
|
302
|
+
if (state.owner !== owner || state.admission !== expected || state.admission.epoch !== expected.epoch
|
|
303
|
+
|| parent.session.header.origin === "subagent" || !this.ctx.agents.roots().includes(parent))
|
|
304
|
+
unauthorized();
|
|
305
|
+
}
|
|
306
|
+
prepareCoreParentAdmission(parent, owner, expected, nextAdmission) {
|
|
307
|
+
this.assertCoreParentAdmission(parent, owner, expected);
|
|
308
|
+
const state = this.current(parent);
|
|
309
|
+
if (nextAdmission.epoch.length === 0 || state.usedEpochs.has(nextAdmission.epoch))
|
|
310
|
+
unauthorized();
|
|
311
|
+
state.prepared = { expectedEpoch: expected.epoch, expected, admission: nextAdmission, controller: new AbortController() };
|
|
312
|
+
}
|
|
313
|
+
/** Trusted successful-commit callback: install MUST be synchronous and nonthrowing. */
|
|
314
|
+
publishParentAdmission(parent, expectedEpoch, nextAdmission, install) {
|
|
315
|
+
const state = this.current(parent);
|
|
316
|
+
const prepared = state.prepared;
|
|
317
|
+
if (state.admission.epoch !== expectedEpoch || prepared?.expectedEpoch !== expectedEpoch || prepared.expected !== state.admission || prepared.admission !== nextAdmission)
|
|
318
|
+
unauthorized();
|
|
319
|
+
const previous = state.epoch;
|
|
320
|
+
state.publishing = true;
|
|
321
|
+
try {
|
|
322
|
+
install();
|
|
323
|
+
state.admission = nextAdmission;
|
|
324
|
+
state.epoch = prepared.controller;
|
|
325
|
+
state.usedEpochs.add(nextAdmission.epoch);
|
|
326
|
+
state.prepared = undefined;
|
|
327
|
+
previous.abort();
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
this.withdrawParent(parent, "publication-failed");
|
|
331
|
+
throw error;
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
state.publishing = false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
revokeParent(parent, _reason) {
|
|
338
|
+
this.retiredAgents.add(parent);
|
|
339
|
+
const managed = this.managed.get(parent);
|
|
340
|
+
if (managed !== undefined) {
|
|
341
|
+
managed.status = "retired";
|
|
342
|
+
managed.operation.retired = true;
|
|
343
|
+
managed.release();
|
|
344
|
+
}
|
|
345
|
+
this.liveManaged.delete(parent);
|
|
346
|
+
for (const child of this.liveManaged)
|
|
347
|
+
if (this.managed.get(child).operation.parent === parent)
|
|
348
|
+
this.revokeParent(child, _reason);
|
|
349
|
+
this.withdrawParent(parent, _reason);
|
|
350
|
+
}
|
|
351
|
+
/** Admission withdrawal invalidates tickets without terminating a living Agent. */
|
|
352
|
+
withdrawParent(parent, reason) {
|
|
353
|
+
const managed = this.managed.get(parent);
|
|
354
|
+
if (managed?.status === "pending") {
|
|
355
|
+
this.revokeParent(parent, reason);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const state = this.parents.get(parent);
|
|
359
|
+
if (state === undefined)
|
|
360
|
+
return;
|
|
361
|
+
this.parents.delete(parent);
|
|
362
|
+
state.lifetime.abort();
|
|
363
|
+
state.epoch.abort();
|
|
364
|
+
state.prepared?.controller.abort();
|
|
365
|
+
state.detachResidency?.();
|
|
366
|
+
}
|
|
367
|
+
revokeOwner(owner, reason) {
|
|
368
|
+
for (const parent of this.liveManaged) {
|
|
369
|
+
const state = this.managed.get(parent);
|
|
370
|
+
if (state.status === "pending" && state.operation.owner === owner)
|
|
371
|
+
this.revokeParent(parent, reason);
|
|
372
|
+
}
|
|
373
|
+
for (const [parent, state] of this.parents)
|
|
374
|
+
if (state.owner === owner)
|
|
375
|
+
this.withdrawParent(parent, reason);
|
|
376
|
+
}
|
|
377
|
+
/** Only the native exact browser peer/Connection can authorize browser delivery. */
|
|
378
|
+
acquireBrowserSignal(callerCtx) {
|
|
379
|
+
const invocation = callerCtx.invocation;
|
|
380
|
+
const connection = callerCtx.get("connection");
|
|
381
|
+
const state = this.connection;
|
|
382
|
+
if (invocation?.peer === undefined || connection === undefined || state === undefined
|
|
383
|
+
|| original(connection) !== state.owner || connection.browserPeer !== invocation.peer || state.browserPeer !== invocation.peer)
|
|
384
|
+
unauthorized();
|
|
385
|
+
state.controller.signal.throwIfAborted();
|
|
386
|
+
return state.controller.signal;
|
|
387
|
+
}
|
|
388
|
+
current(parent) {
|
|
389
|
+
this.assertSender(parent);
|
|
390
|
+
const state = this.parents.get(parent);
|
|
391
|
+
if (state === undefined || state.publishing || state.lifetime.signal.aborted || this.lifetime.signal.aborted
|
|
392
|
+
|| this.binding?.owner !== state.owner || this.ctx.get("agents")?.get(parent.id) !== parent)
|
|
393
|
+
unauthorized();
|
|
394
|
+
return state;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
//# sourceMappingURL=delivery-authority.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
1
2
|
import type { DshContext } from "./dsh-types.js";
|
|
2
3
|
import { FixedConfigFileStore } from "./config-file-store.js";
|
|
3
4
|
import type { DsmmDeploymentSnapshot, DsmmPluginConfig } from "./settings.js";
|
|
@@ -17,6 +18,9 @@ export interface GlobalConfigSnapshot {
|
|
|
17
18
|
config: DsmmPluginConfig;
|
|
18
19
|
revision: string;
|
|
19
20
|
}
|
|
21
|
+
export interface DeploymentWriteCoordinator {
|
|
22
|
+
global(request: GlobalConfigSaveRequest, config: DsmmPluginConfig, assertAuthority: () => void, write: (config: DsmmPluginConfig) => Promise<GlobalConfigSnapshot>): Promise<GlobalConfigSnapshot>;
|
|
23
|
+
}
|
|
20
24
|
export declare function parseGlobalConfig(content: string | null): DsmmPluginConfig;
|
|
21
25
|
/** Only schema fields, never filesystem paths or array indexes. Full candidate is revalidated. */
|
|
22
26
|
export declare function editGlobalConfig(config: DsmmPluginConfig, edits: DeploymentPathEdit[]): DsmmPluginConfig;
|
|
@@ -24,10 +28,29 @@ export declare function editGlobalConfig(config: DsmmPluginConfig, edits: Deploy
|
|
|
24
28
|
export declare class DsmmDeploymentConfig {
|
|
25
29
|
private readonly ctx;
|
|
26
30
|
private readonly config;
|
|
31
|
+
private writeCoordinator?;
|
|
27
32
|
readonly home: string;
|
|
28
33
|
readonly store: FixedConfigFileStore;
|
|
29
34
|
readonly entryId: string;
|
|
30
35
|
readonly hostProfileKey: string;
|
|
36
|
+
get nativeEntry(): Context["fiber"]["entry"] | undefined;
|
|
37
|
+
coordinateWrites(coordinator: DeploymentWriteCoordinator): () => void;
|
|
38
|
+
/** Synchronous source identity for permission dispatch fences; no form revision or process identity. */
|
|
39
|
+
permissionSource(): {
|
|
40
|
+
revision: string;
|
|
41
|
+
globalRevision: string;
|
|
42
|
+
nativeRevision: string;
|
|
43
|
+
global: DsmmPluginConfig;
|
|
44
|
+
profile: DsmmPluginConfig;
|
|
45
|
+
policy: {
|
|
46
|
+
nativeCommands: import("./permission-settings.js").NativeCommandsSettings;
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
outsideReads: import("./permission-settings.js").PermissionRuleAction;
|
|
49
|
+
webSearch: import("./permission-settings.js").PermissionWebPolicy;
|
|
50
|
+
webFetch: import("./permission-settings.js").PermissionWebPolicy;
|
|
51
|
+
rules: readonly import("./permission-rules.js").PermissionRule[];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
31
54
|
constructor(ctx: DshContext, config: DsmmPluginConfig);
|
|
32
55
|
private profile;
|
|
33
56
|
readGlobal(): Promise<GlobalConfigSnapshot>;
|
package/lib/deployment-config.js
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { Context } from "@deepseek-ai/cordis";
|
|
3
|
-
import { parseTree } from "jsonc-parser";
|
|
4
3
|
import { resolveDshHome } from "./dsh-home.js";
|
|
5
4
|
import { FixedConfigFileStore } from "./config-file-store.js";
|
|
6
5
|
import { copyJson, freezeSettings, resolveDeployment, validateDeploymentPath, validateSparseConfig } from "./settings.js";
|
|
7
6
|
import { DsmmProfileError } from "./profiles.js";
|
|
8
7
|
import { resolve } from "node:path";
|
|
8
|
+
import { diagnosticSourcePath, DsmmConfigValidationError, fieldLocation, inspectJsonDocument } from "./profile-diagnostics.js";
|
|
9
|
+
import { parseHostNativeCommands } from "./permission-native-command.js";
|
|
9
10
|
function configurationError() { throw new DsmmProfileError("validation", "Deepwork deployment configuration is invalid; restore valid plain JSON before saving or admitting a new session."); }
|
|
10
|
-
function validateJsonTree(node, depth = 0) {
|
|
11
|
-
if (depth > 64)
|
|
12
|
-
configurationError();
|
|
13
|
-
if (node.type === "object") {
|
|
14
|
-
const names = (node.children ?? []).map((property) => property.children?.[0]?.value);
|
|
15
|
-
if (new Set(names).size !== names.length)
|
|
16
|
-
configurationError();
|
|
17
|
-
}
|
|
18
|
-
for (const child of node.children ?? [])
|
|
19
|
-
validateJsonTree(child, depth + 1);
|
|
20
|
-
}
|
|
21
11
|
export function parseGlobalConfig(content) {
|
|
22
12
|
if (content === null)
|
|
23
13
|
return {};
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
14
|
+
const inspected = inspectJsonDocument(content, false);
|
|
15
|
+
const issue = inspected.diagnostics[0];
|
|
16
|
+
if (issue !== undefined)
|
|
17
|
+
throw new DsmmProfileError("validation", `${issue.field}: ${issue.reason}`, issue.field, issue.code, issue.location);
|
|
18
|
+
if (inspected.tree?.type !== "object")
|
|
27
19
|
configurationError();
|
|
28
|
-
validateJsonTree(tree);
|
|
29
20
|
try {
|
|
30
|
-
|
|
21
|
+
const config = validateSparseConfig(JSON.parse(content), true);
|
|
22
|
+
if (config.permissionControl?.nativeCommands !== undefined)
|
|
23
|
+
parseHostNativeCommands(config.permissionControl.nativeCommands);
|
|
24
|
+
return config;
|
|
31
25
|
}
|
|
32
|
-
catch {
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof DsmmConfigValidationError)
|
|
28
|
+
throw new DsmmProfileError("validation", error.message, error.diagnostic.field, error.diagnostic.code, fieldLocation(content, inspected.tree, error.diagnostic.field, diagnosticSourcePath(error)));
|
|
33
29
|
return configurationError();
|
|
34
30
|
}
|
|
35
31
|
}
|
|
@@ -46,12 +42,7 @@ export function editGlobalConfig(config, edits) {
|
|
|
46
42
|
|| !Array.isArray(edit.path) || edit.path.length === 0 || edit.path.length > 8
|
|
47
43
|
|| edit.path.some((key) => typeof key !== "string" || !/^[a-zA-Z][a-zA-Z0-9_-]*$/u.test(key) || ["constructor", "prototype", "__proto__"].includes(key)))
|
|
48
44
|
configurationError();
|
|
49
|
-
|
|
50
|
-
validateDeploymentPath(edit.path);
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
configurationError();
|
|
54
|
-
}
|
|
45
|
+
validateDeploymentPath(edit.path);
|
|
55
46
|
let node = result;
|
|
56
47
|
for (const key of edit.path.slice(0, -1)) {
|
|
57
48
|
const child = node[key];
|
|
@@ -64,14 +55,12 @@ export function editGlobalConfig(config, edits) {
|
|
|
64
55
|
node[key] = copyJson(edit.value);
|
|
65
56
|
else
|
|
66
57
|
Reflect.deleteProperty(node, key);
|
|
67
|
-
|
|
68
|
-
result = validateSparseConfig(result, true);
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
configurationError();
|
|
72
|
-
}
|
|
58
|
+
result = validateSparseConfig(result, true);
|
|
73
59
|
}
|
|
74
|
-
|
|
60
|
+
const configResult = result;
|
|
61
|
+
if (configResult.permissionControl?.nativeCommands !== undefined)
|
|
62
|
+
parseHostNativeCommands(configResult.permissionControl.nativeCommands);
|
|
63
|
+
return configResult;
|
|
75
64
|
}
|
|
76
65
|
function hash(input) { return createHash("sha256").update(JSON.stringify(input)).digest("hex"); }
|
|
77
66
|
function presentValue(parsed, raw) {
|
|
@@ -106,23 +95,40 @@ function sources(global, profile, settings) {
|
|
|
106
95
|
export class DsmmDeploymentConfig {
|
|
107
96
|
ctx;
|
|
108
97
|
config;
|
|
98
|
+
writeCoordinator;
|
|
109
99
|
home;
|
|
110
100
|
store;
|
|
111
101
|
entryId;
|
|
112
102
|
hostProfileKey;
|
|
103
|
+
get nativeEntry() { return Context.is(this.ctx) ? this.ctx.fiber.entry : undefined; }
|
|
104
|
+
coordinateWrites(coordinator) {
|
|
105
|
+
if (this.writeCoordinator !== undefined)
|
|
106
|
+
throw new DsmmProfileError("conflict", "Deployment writes already have an owner.");
|
|
107
|
+
this.writeCoordinator = coordinator;
|
|
108
|
+
return () => { if (this.writeCoordinator === coordinator)
|
|
109
|
+
this.writeCoordinator = undefined; };
|
|
110
|
+
}
|
|
111
|
+
/** Synchronous source identity for permission dispatch fences; no form revision or process identity. */
|
|
112
|
+
permissionSource() {
|
|
113
|
+
const profile = this.profile(), file = this.store.read(), global = parseGlobalConfig(file.content);
|
|
114
|
+
const settings = resolveDeployment(global, profile.config);
|
|
115
|
+
return freezeSettings({ revision: hash([this.hostProfileKey, file.revision, profile.revision, profile.config]),
|
|
116
|
+
globalRevision: file.revision, nativeRevision: profile.revision, global, profile: profile.config,
|
|
117
|
+
policy: { ...settings.permissionControl, nativeCommands: parseHostNativeCommands(settings.permissionControl.nativeCommands) } });
|
|
118
|
+
}
|
|
113
119
|
constructor(ctx, config) {
|
|
114
120
|
this.ctx = ctx;
|
|
115
121
|
this.config = config;
|
|
116
122
|
const profile = ctx.get?.("profileContext");
|
|
117
123
|
this.home = resolveDshHome(profile?.home);
|
|
118
124
|
this.store = new FixedConfigFileStore(this.home);
|
|
119
|
-
const entry = ctx
|
|
125
|
+
const entry = Context.is(ctx) ? ctx.fiber.entry : undefined;
|
|
120
126
|
this.entryId = entry?.id ?? "trusted-direct";
|
|
121
127
|
const identity = profile?.dir === undefined ? "trusted-direct" : resolve(profile.dir);
|
|
122
128
|
this.hostProfileKey = hash([process.platform === "win32" ? identity.toLowerCase() : identity, this.entryId]);
|
|
123
129
|
}
|
|
124
130
|
profile() {
|
|
125
|
-
const entry = this.ctx
|
|
131
|
+
const entry = Context.is(this.ctx) ? this.ctx.fiber.entry : undefined;
|
|
126
132
|
const raw = entry === undefined ? Object.fromEntries(Object.entries(this.config).flatMap(([key, parsed]) => {
|
|
127
133
|
const value = parsed !== null && typeof parsed === "object" && "get" in parsed && typeof parsed.get === "function" ? parsed.get() : parsed;
|
|
128
134
|
return value === undefined ? [] : [[key, value]];
|
|
@@ -135,9 +141,14 @@ export class DsmmDeploymentConfig {
|
|
|
135
141
|
const value = parsed !== null && typeof parsed === "object" && "get" in parsed && typeof parsed.get === "function" ? parsed.get() : parsed;
|
|
136
142
|
snapshot[key] = presentValue(value, Reflect.get(presence, key));
|
|
137
143
|
}
|
|
138
|
-
|
|
144
|
+
const config = validateSparseConfig(snapshot);
|
|
145
|
+
if (config.permissionControl?.nativeCommands !== undefined)
|
|
146
|
+
parseHostNativeCommands(config.permissionControl.nativeCommands);
|
|
147
|
+
return { config, revision: hash(presence) };
|
|
139
148
|
}
|
|
140
|
-
catch {
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error instanceof DsmmConfigValidationError)
|
|
151
|
+
throw error;
|
|
141
152
|
return configurationError();
|
|
142
153
|
}
|
|
143
154
|
}
|
|
@@ -152,10 +163,12 @@ export class DsmmDeploymentConfig {
|
|
|
152
163
|
try {
|
|
153
164
|
settings = resolveDeployment(global.config, profile.config);
|
|
154
165
|
}
|
|
155
|
-
catch {
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error instanceof DsmmConfigValidationError)
|
|
168
|
+
throw error;
|
|
156
169
|
return configurationError();
|
|
157
170
|
}
|
|
158
|
-
const entry = this.ctx
|
|
171
|
+
const entry = Context.is(this.ctx) ? this.ctx.fiber.entry : undefined;
|
|
159
172
|
const descriptor = entry === undefined ? undefined : this.ctx.get?.("settings")?.describe({ redactSecrets: true }).find((row) => row.ns === entry.options.id);
|
|
160
173
|
if (this.profile().revision !== profile.revision || this.store.read().revision !== global.revision)
|
|
161
174
|
throw new DsmmProfileError("conflict", "Deployment sources changed while projecting native state; refresh before retrying.");
|
|
@@ -174,11 +187,19 @@ export class DsmmDeploymentConfig {
|
|
|
174
187
|
try {
|
|
175
188
|
resolveDeployment(config, this.profile().config);
|
|
176
189
|
}
|
|
177
|
-
catch {
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error instanceof DsmmConfigValidationError)
|
|
192
|
+
throw error;
|
|
178
193
|
configurationError();
|
|
179
194
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
195
|
+
const write = async (candidate) => {
|
|
196
|
+
const validated = validateSparseConfig(candidate, true);
|
|
197
|
+
resolveDeployment(validated, this.profile().config);
|
|
198
|
+
assertAuthority();
|
|
199
|
+
const saved = await this.store.save(`${JSON.stringify(validated, null, 2)}\n`, request.expectedRevision, assertAuthority);
|
|
200
|
+
return { config: validated, revision: saved.revision };
|
|
201
|
+
};
|
|
202
|
+
return this.writeCoordinator === undefined ? write(config) : this.writeCoordinator.global(request, config, assertAuthority, write);
|
|
182
203
|
}
|
|
183
204
|
}
|
|
184
205
|
//# sourceMappingURL=deployment-config.js.map
|