@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
package/lib/profile-runtime.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { ProfileStore, validateSessionProfileId } from "./profile-store.js";
|
|
4
|
-
import { DsmmProfileError, resolveProfileSettings } from "./profiles.js";
|
|
5
|
-
import { DSMM_ROLES,
|
|
6
|
-
import { roleRouteRuntimeState
|
|
4
|
+
import { DsmmProfileError, profileDocumentWarnings, requiredReason, resolveProfileSettings } from "./profiles.js";
|
|
5
|
+
import { DSMM_ROLES, isDsmmRoleId } from "./roles.js";
|
|
6
|
+
import { roleRouteRuntimeState } from "./role-routing.js";
|
|
7
7
|
import { sessionEvents } from "./session-scope.js";
|
|
8
8
|
import { resolveAdmittedDsmmRole as resolveEffectiveDsmmRole } from "./role-policy.js";
|
|
9
9
|
import { DeepworkModeController, hasOpenTurn } from "./state.js";
|
|
10
|
-
import {
|
|
11
|
-
import { freezeSettings } from "./settings.js";
|
|
10
|
+
import { freezeSettings, isRootRoleEnabled } from "./settings.js";
|
|
12
11
|
import { resolveDshHome } from "./dsh-home.js";
|
|
13
12
|
import { lstatSync } from "node:fs";
|
|
14
|
-
import {
|
|
13
|
+
import { projectDsmmModules } from "./modules.js";
|
|
15
14
|
import { Context } from "@deepseek-ai/cordis";
|
|
16
15
|
import { readOnlySettings, readOnlySettingSources } from "./status.js";
|
|
16
|
+
import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
17
|
+
import { admissionFromChildCapture, parseChildAdmissionCapture, parseLegacyChildEvidence } from "./child-capture.js";
|
|
18
|
+
import { normalizeModelRouteJson } from "./route-json.js";
|
|
19
|
+
import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
20
|
+
import { scopeLifetime } from "./delivery-authority.js";
|
|
17
21
|
function deploymentAdmissionView(admission) {
|
|
18
|
-
return { settings: { ...readOnlySettings(admission.settings) }, sources: readOnlySettingSources(admission.sources ?? {}),
|
|
22
|
+
return { modelParameterPolicy: resolvedModelParameterPolicy(admission), settings: { ...readOnlySettings(admission.settings) }, sources: readOnlySettingSources(admission.sources ?? {}),
|
|
19
23
|
captures: readOnlySettingSources(admission.sourceCaptures?.fields ?? {}), restartRequired: [...admission.restartRequired ?? []], named: admission.profile === null ? null : { ...admission.profile } };
|
|
20
24
|
}
|
|
21
25
|
// Exact live native children retain their capture across DSMM runtime replacement.
|
|
@@ -28,6 +32,7 @@ export class DsmmProfileRuntime {
|
|
|
28
32
|
ctx;
|
|
29
33
|
store;
|
|
30
34
|
options;
|
|
35
|
+
childCaptureStore;
|
|
31
36
|
getSettings = (agent) => agent === undefined ? this.current.settings : this.bind(agent).settings;
|
|
32
37
|
current;
|
|
33
38
|
currentDocument = null;
|
|
@@ -36,6 +41,7 @@ export class DsmmProfileRuntime {
|
|
|
36
41
|
admitting = new WeakSet();
|
|
37
42
|
disposedAgents = new WeakSet();
|
|
38
43
|
switching = new WeakSet();
|
|
44
|
+
admissionObservers = new Set();
|
|
39
45
|
disposed = false;
|
|
40
46
|
selectionQueue = Promise.resolve();
|
|
41
47
|
mode;
|
|
@@ -43,29 +49,71 @@ export class DsmmProfileRuntime {
|
|
|
43
49
|
this.ctx = ctx;
|
|
44
50
|
this.store = store;
|
|
45
51
|
this.options = options;
|
|
52
|
+
this.childCaptureStore = options.childCaptureStore ?? store;
|
|
46
53
|
this.baseline = immutableSettings(baseline);
|
|
47
54
|
this.mode = options.modeController ?? new DeepworkModeController({ get: (name) => ctx.get?.(name) }, (agent) => this.getSettings(agent).modules.deepwork.enabled);
|
|
48
55
|
this.current = this.prepare(null, { selectedId: null, appliedRevision: null, selectionRevision: "absent" });
|
|
49
56
|
this.getSettings.admission = (agent) => this.admission(agent);
|
|
50
|
-
this.getSettings.moduleStates = (agent) => { const admission = this.admission(agent); return
|
|
57
|
+
this.getSettings.moduleStates = (agent) => { const admission = this.admission(agent); return projectDsmmModules(this.baseline, admission.deployment, admission, false, this.options.getMountedPermission); };
|
|
58
|
+
this.getSettings.subagentRuntime = () => this.subagentRuntimeView();
|
|
51
59
|
}
|
|
52
60
|
async initialize() {
|
|
61
|
+
const retire = () => { this.disposed = true; this.admissionObservers.clear(); for (const agent of this.agents()?.list() ?? [])
|
|
62
|
+
if (this.bound.has(agent))
|
|
63
|
+
this.options.childAuthority?.revokeParent(agent, "runtime-disposed"); };
|
|
64
|
+
if (this.ctx instanceof Context)
|
|
65
|
+
scopeLifetime(this.ctx, "dsmm.profiles: retire admission lifecycle", retire);
|
|
66
|
+
else
|
|
67
|
+
this.ctx.effect?.(() => retire);
|
|
53
68
|
const selection = await this.store.loadSelection();
|
|
69
|
+
if (this.disposed)
|
|
70
|
+
throw new DsmmProfileError("disposed", "Profile initialization was disposed.");
|
|
54
71
|
this.currentDocument = selection.document === null ? null : freezeSettings(selection.document);
|
|
55
72
|
this.current = this.prepare(selection.document, selection);
|
|
56
73
|
this.ctx.on?.("agent/created", async ({ agent, signal }) => {
|
|
57
74
|
// Factory initialization already owns native maintenance: never whenIdle
|
|
58
75
|
// or reserve maintenance from inside this serial creation listener.
|
|
59
|
-
await this.
|
|
76
|
+
await this.completeAdmission(agent, signal);
|
|
60
77
|
}, { global: true, prepend: true });
|
|
61
|
-
this.ctx.on?.("agent/disposed", ({ agent }) => { this.disposedAgents.add(agent); childAdmissions.delete(agent); }, { global: true });
|
|
62
|
-
|
|
78
|
+
this.ctx.on?.("agent/disposed", ({ agent }) => { this.options.childAuthority?.revokeParent(agent, "agent-disposed"); this.disposedAgents.add(agent); childAdmissions.delete(agent); }, { global: true });
|
|
79
|
+
if (this.options.onAdmissionGuardsInstalled !== undefined)
|
|
80
|
+
await this.options.onAdmissionGuardsInstalled(this);
|
|
63
81
|
// Installation into an already-running host treats those Agents as admitted
|
|
64
82
|
// now, while all later profile switches continue to preserve their snapshot.
|
|
83
|
+
const visited = new Set(), visiting = new Set();
|
|
84
|
+
const admitExisting = async (agent) => {
|
|
85
|
+
if (visited.has(agent))
|
|
86
|
+
return;
|
|
87
|
+
if (visiting.has(agent))
|
|
88
|
+
throw new DsmmProfileError("not-owned", "Existing Agent ownership has a cycle; no child authority was inferred.");
|
|
89
|
+
visiting.add(agent);
|
|
90
|
+
const parent = this.owner(agent);
|
|
91
|
+
if (parent !== undefined && this.options.deferRetainedChildren) {
|
|
92
|
+
visiting.delete(agent);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (parent !== undefined)
|
|
96
|
+
await admitExisting(parent);
|
|
97
|
+
await this.completeAdmission(agent, undefined, this.options.startup);
|
|
98
|
+
visiting.delete(agent);
|
|
99
|
+
visited.add(agent);
|
|
100
|
+
};
|
|
65
101
|
for (const agent of this.agents()?.list() ?? [])
|
|
66
|
-
await
|
|
102
|
+
await admitExisting(agent);
|
|
67
103
|
}
|
|
68
104
|
admission(agent) { return agent === undefined ? this.current : this.bind(agent); }
|
|
105
|
+
/** Host enrollment observes completed exact admissions, never an entered but unpublished policy. */
|
|
106
|
+
hasAdmission(agent) { return !this.disposed && !this.disposedAgents.has(agent) && this.bound.has(agent) && this.agents()?.get?.(agent.id) === agent; }
|
|
107
|
+
observeAdmissions(observer) {
|
|
108
|
+
if (this.disposed)
|
|
109
|
+
throw new DsmmProfileError("disposed", "Profile admission observation was disposed.");
|
|
110
|
+
this.admissionObservers.add(observer);
|
|
111
|
+
return () => { this.admissionObservers.delete(observer); };
|
|
112
|
+
}
|
|
113
|
+
async announceAdmission(agent) {
|
|
114
|
+
for (const observer of this.admissionObservers)
|
|
115
|
+
await observer(agent);
|
|
116
|
+
}
|
|
69
117
|
async getSession(agent) {
|
|
70
118
|
this.assertRoot(agent);
|
|
71
119
|
const admitted = this.bind(agent);
|
|
@@ -81,8 +129,9 @@ export class DsmmProfileRuntime {
|
|
|
81
129
|
const profileModel = this.declaredProfileModel(admitted.settings, role);
|
|
82
130
|
return { sessionId: agent.id, globalDefault: selectionState(this.current), selection: selectionState(disk), admittedSelection: selectionState(admitted), scope: admitted.scope,
|
|
83
131
|
rolePolicy: roleRouteRuntimeState(agent, admitted.settings, role, admitted.epoch), deepwork: this.mode.describe(agent, admitted.settings.defaultActive),
|
|
84
|
-
modules:
|
|
132
|
+
modules: projectDsmmModules(this.baseline, admitted.deployment, admitted, false, this.options.getMountedPermission),
|
|
85
133
|
configuration: deploymentAdmissionView(admitted),
|
|
134
|
+
warnings: structuredClone(admitted.warnings ?? []), roles: structuredClone(admitted.roleAvailability ?? []), subagentRuntime: this.subagentRuntimeView(),
|
|
86
135
|
...(profileModel === undefined ? {} : { profileModel }),
|
|
87
136
|
admissionEpoch: admitted.epoch, switchAllowed: reason === undefined, ...(reason === undefined ? {} : { switchUnavailableReason: reason }) };
|
|
88
137
|
}
|
|
@@ -147,12 +196,27 @@ export class DsmmProfileRuntime {
|
|
|
147
196
|
if (request.sessionId !== agent.id)
|
|
148
197
|
throw new DsmmProfileError("not-owned", "The native session does not match the captured Agent.");
|
|
149
198
|
const admitted = this.bind(agent);
|
|
199
|
+
const modeRevision = this.mode.describe(agent, admitted.settings.defaultActive).revision;
|
|
200
|
+
const coreOnly = () => resolveEffectiveDsmmRole(agent, admitted.settings, this.mode.active(agent, admitted.settings.defaultActive)) === undefined;
|
|
201
|
+
let requiresDelivery = this.options.childAuthority !== undefined && !coreOnly();
|
|
150
202
|
const assertCurrent = (maintenanceSignal) => {
|
|
151
203
|
this.assertRoot(agent);
|
|
152
204
|
if (signal?.aborted || maintenanceSignal?.aborted)
|
|
153
205
|
throw new DsmmProfileError("cancelled", "Session profile selection was cancelled; the previous admission was retained.");
|
|
154
|
-
if (this.bind(agent) !== admitted || admitted.epoch !== request.expectedAdmissionEpoch)
|
|
206
|
+
if (this.bind(agent) !== admitted || admitted.epoch !== request.expectedAdmissionEpoch || this.mode.describe(agent, admitted.settings.defaultActive).revision !== modeRevision)
|
|
155
207
|
throw new DsmmProfileError("conflict", "The session admission changed. Refresh before selecting again.");
|
|
208
|
+
if (this.options.childAuthority !== undefined) {
|
|
209
|
+
if (requiresDelivery)
|
|
210
|
+
this.assertDeliveryFence();
|
|
211
|
+
if (!requiresDelivery && this.options.childAuthority.assertCoreParentAdmission !== undefined) {
|
|
212
|
+
this.options.childAuthority.assertCoreParentAdmission(agent, this.options.childAuthorityOwner ?? this, admitted);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const ticket = this.options.childAuthority.acquireParentTicket(agent);
|
|
216
|
+
if (ticket.admission !== admitted || ticket.owner !== (this.options.childAuthorityOwner ?? this))
|
|
217
|
+
throw new DsmmProfileError("not-owned", "The stable Host authority does not own this exact admission.");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
156
220
|
assertAuthority?.();
|
|
157
221
|
};
|
|
158
222
|
assertCurrent();
|
|
@@ -169,27 +233,56 @@ export class DsmmProfileRuntime {
|
|
|
169
233
|
const epoch = newEpoch();
|
|
170
234
|
let profileModel;
|
|
171
235
|
let committed;
|
|
236
|
+
let next;
|
|
172
237
|
const result = await this.store.selectSession(request, epoch, async (document) => {
|
|
173
238
|
const prepared = immutableSettings(resolveProfileSettings(admitted.baseline, document?.settings ?? {}));
|
|
174
|
-
|
|
239
|
+
const candidate = { settings: prepared, epoch, scope: request.id === null ? "deployment-baseline" : "session-override",
|
|
240
|
+
profile: document === null ? null : { id: document.id, revision: request.expectedRevision } };
|
|
241
|
+
this.assertRootRole(agent, prepared);
|
|
242
|
+
this.validateRootRole(agent, candidate);
|
|
243
|
+
const controlled = !coreOnly() || resolveEffectiveDsmmRole(agent, prepared, this.mode.active(agent, prepared.defaultActive)) !== undefined;
|
|
244
|
+
requiresDelivery ||= controlled && (this.options.childAuthority !== undefined
|
|
245
|
+
|| ["roles", "guards", "subagents"].some(key => JSON.stringify(Reflect.get(prepared, key)) !== JSON.stringify(Reflect.get(admitted.settings, key))));
|
|
246
|
+
if (requiresDelivery)
|
|
247
|
+
this.assertDeliveryFence();
|
|
248
|
+
await this.validate(prepared, requiresDelivery);
|
|
249
|
+
assertCurrent(maintenanceSignal);
|
|
250
|
+
this.assertRootRole(agent, prepared);
|
|
251
|
+
this.validateRootRole(agent, candidate);
|
|
175
252
|
const role = resolveEffectiveDsmmRole(agent, prepared, this.mode.active(agent, prepared.defaultActive));
|
|
176
253
|
profileModel = this.declaredProfileModel(prepared, role);
|
|
177
|
-
assertCurrent(maintenanceSignal);
|
|
178
254
|
return prepared;
|
|
179
255
|
}, {
|
|
180
256
|
assertCurrent: () => assertCurrent(maintenanceSignal),
|
|
257
|
+
prepare: (selection, settings) => {
|
|
258
|
+
next = this.profileAdmission(selection, settings, epoch, request.id === null ? "deployment-baseline" : "session-override", admitted.baseline, admitted.deployment, admitted.restartRequired, selection.document, selection.warnings);
|
|
259
|
+
this.validateRootRole(agent, next);
|
|
260
|
+
if (!requiresDelivery && this.options.childAuthority?.prepareCoreParentAdmission !== undefined) {
|
|
261
|
+
this.options.childAuthority.prepareCoreParentAdmission(agent, this.options.childAuthorityOwner ?? this, admitted, next);
|
|
262
|
+
}
|
|
263
|
+
else
|
|
264
|
+
this.options.childAuthority?.prepareParentAdmission(agent, admitted.epoch, next);
|
|
265
|
+
},
|
|
181
266
|
committed: (selection, settings) => {
|
|
182
|
-
|
|
183
|
-
this.
|
|
184
|
-
|
|
267
|
+
const install = () => { this.bound.set(agent, next); };
|
|
268
|
+
if (this.options.childAuthority !== undefined)
|
|
269
|
+
this.options.childAuthority.publishParentAdmission(agent, admitted.epoch, next, install);
|
|
270
|
+
else
|
|
271
|
+
install();
|
|
272
|
+
committed = next;
|
|
185
273
|
}
|
|
186
274
|
});
|
|
275
|
+
try {
|
|
276
|
+
this.mode.changed(agent);
|
|
277
|
+
}
|
|
278
|
+
catch { /* Observers cannot undo a successful durable admission publication. */ }
|
|
187
279
|
// A committed selection remains a successful transaction even if a
|
|
188
280
|
// queued wake or disposal wins immediately when maintenance releases.
|
|
189
281
|
return { sessionId: request.sessionId, globalDefault: selectionState(this.current), selection: selectionState(result.selection), admittedSelection: selectionState(result.selection),
|
|
190
282
|
deepwork: this.mode.describe(agent, result.prepared.defaultActive),
|
|
191
|
-
modules:
|
|
283
|
+
modules: projectDsmmModules(this.baseline, committed.deployment, committed, false, this.options.getMountedPermission),
|
|
192
284
|
configuration: deploymentAdmissionView(committed),
|
|
285
|
+
warnings: structuredClone(committed.warnings ?? []), roles: structuredClone(committed.roleAvailability ?? []), subagentRuntime: this.subagentRuntimeView(),
|
|
193
286
|
...(profileModel === undefined ? {} : { profileModel }),
|
|
194
287
|
scope: request.id === null ? "deployment-baseline" : "session-override", admissionEpoch: epoch, switchAllowed: true };
|
|
195
288
|
}
|
|
@@ -213,11 +306,12 @@ export class DsmmProfileRuntime {
|
|
|
213
306
|
|| persisted.selectionRevision !== current.selectionRevision;
|
|
214
307
|
return {
|
|
215
308
|
...persisted,
|
|
309
|
+
selectedWarnings: structuredClone(current.warnings ?? []),
|
|
216
310
|
roles: DSMM_ROLES.map((role) => {
|
|
217
311
|
const configured = this.baseline.roleRouting[role.id];
|
|
218
312
|
const runtimePolicy = { ...(configured?.strategy === undefined ? {} : { strategy: configured.strategy }),
|
|
219
313
|
...(configured?.rateLimit === undefined ? {} : { rateLimit: structuredClone(configured.rateLimit) }) };
|
|
220
|
-
return { id: role.id, label: role.name, enabled: this.
|
|
314
|
+
return { id: role.id, label: role.name, enabled: this.current.settings.roles[role.id], availability: this.current.roleAvailability?.find(state => state.id === role.id),
|
|
221
315
|
...(Object.keys(runtimePolicy).length === 0 ? {} : { runtimePolicy }) };
|
|
222
316
|
}),
|
|
223
317
|
editorDefaults: structuredClone(this.baseline.runtimePolicy),
|
|
@@ -256,7 +350,7 @@ export class DsmmProfileRuntime {
|
|
|
256
350
|
});
|
|
257
351
|
// There is no await between successful durable commit and publication of
|
|
258
352
|
// the complete settings value. Draft saves never reach this assignment.
|
|
259
|
-
this.current = this.profileAdmission(result.selection, result.prepared, newEpoch(), "global-default", baseline, this.options.startup, this.current.restartRequired, selectedDocument);
|
|
353
|
+
this.current = this.profileAdmission(result.selection, result.prepared, newEpoch(), "global-default", baseline, this.options.startup, this.current.restartRequired, selectedDocument, result.selection.warnings);
|
|
260
354
|
this.currentDocument = selectedDocument;
|
|
261
355
|
return this.describe();
|
|
262
356
|
});
|
|
@@ -268,6 +362,13 @@ export class DsmmProfileRuntime {
|
|
|
268
362
|
const effective = structuredClone(desired);
|
|
269
363
|
const restartRequired = [];
|
|
270
364
|
effective.modules.deepwork.enabled = desired.modules.deepwork.enabled && this.baseline.modules.deepwork.enabled;
|
|
365
|
+
effective.subagents.allowRouteOverride = desired.subagents.allowRouteOverride && this.baseline.subagents.allowRouteOverride;
|
|
366
|
+
if (desired.subagents.allowRouteOverride && !this.baseline.subagents.allowRouteOverride)
|
|
367
|
+
restartRequired.push("subagents.allowRouteOverride");
|
|
368
|
+
if (this.baseline.subagents.maxDepth !== undefined && (desired.subagents.maxDepth === undefined || desired.subagents.maxDepth > this.baseline.subagents.maxDepth)) {
|
|
369
|
+
effective.subagents.maxDepth = this.baseline.subagents.maxDepth;
|
|
370
|
+
restartRequired.push("subagents.maxDepth");
|
|
371
|
+
}
|
|
271
372
|
if (desired.modules.deepwork.enabled && !this.baseline.modules.deepwork.enabled)
|
|
272
373
|
restartRequired.push("modules.deepwork.enabled");
|
|
273
374
|
for (const role of DSMM_ROLES) {
|
|
@@ -280,6 +381,9 @@ export class DsmmProfileRuntime {
|
|
|
280
381
|
effective.subagents.enableRunInBackground = false;
|
|
281
382
|
restartRequired.push("subagents");
|
|
282
383
|
}
|
|
384
|
+
if (desired.permissionControl.enabled !== this.baseline.permissionControl.enabled)
|
|
385
|
+
restartRequired.push("permissionControl.enabled");
|
|
386
|
+
effective.permissionControl = { ...desired.permissionControl, enabled: this.baseline.permissionControl.enabled };
|
|
283
387
|
for (const key of ["modeName", "promptOrder", "presets", "lsp"]) {
|
|
284
388
|
if (JSON.stringify(desired[key]) !== JSON.stringify(this.baseline[key]))
|
|
285
389
|
restartRequired.push(key);
|
|
@@ -289,9 +393,9 @@ export class DsmmProfileRuntime {
|
|
|
289
393
|
&& (deployment.profile.section ?? deployment.global.section) !== (this.options.startup.profile.section ?? this.options.startup.global.section))
|
|
290
394
|
restartRequired.push("section");
|
|
291
395
|
const baseline = immutableSettings(effective);
|
|
292
|
-
return this.profileAdmission(selection, immutableSettings(resolveProfileSettings(baseline, document?.settings ?? {})), epoch, scope, baseline, deployment, restartRequired, document);
|
|
396
|
+
return this.profileAdmission(selection, immutableSettings(resolveProfileSettings(baseline, document?.settings ?? {})), epoch, scope, baseline, deployment, restartRequired, document, selection.warnings);
|
|
293
397
|
}
|
|
294
|
-
profileAdmission(selection, settings, epoch, scope, baseline = this.baseline, deployment = this.options.startup, restartRequired = [], document = null) {
|
|
398
|
+
profileAdmission(selection, settings, epoch, scope, baseline = this.baseline, deployment = this.options.startup, restartRequired = [], document = null, warnings = profileDocumentWarnings(document)) {
|
|
295
399
|
const sources = { ...deployment?.sources };
|
|
296
400
|
const fields = Object.fromEntries(Object.keys(sources).map((path) => [path, "deployment"]));
|
|
297
401
|
const pinStartup = (prefix) => {
|
|
@@ -305,10 +409,14 @@ export class DsmmProfileRuntime {
|
|
|
305
409
|
fields[path] = "startup";
|
|
306
410
|
}
|
|
307
411
|
};
|
|
308
|
-
for (const key of ["modeName", "promptOrder", "presets", "lsp"])
|
|
412
|
+
for (const key of ["modeName", "promptOrder", "presets", "lsp", "permissionControl.enabled"])
|
|
309
413
|
pinStartup(key);
|
|
310
414
|
if (deployment?.settings.modules.deepwork.enabled && !baseline.modules.deepwork.enabled)
|
|
311
415
|
pinStartup("modules.deepwork.enabled");
|
|
416
|
+
if (deployment?.settings.subagents.allowRouteOverride && !baseline.subagents.allowRouteOverride)
|
|
417
|
+
pinStartup("subagents.allowRouteOverride");
|
|
418
|
+
if (deployment !== undefined && deployment.settings.subagents.maxDepth !== baseline.subagents.maxDepth)
|
|
419
|
+
pinStartup("subagents.maxDepth");
|
|
312
420
|
for (const role of DSMM_ROLES) {
|
|
313
421
|
if (deployment?.settings.roles[role.id] && !baseline.roles[role.id])
|
|
314
422
|
pinStartup(`roles.${role.id}`);
|
|
@@ -324,16 +432,16 @@ export class DsmmProfileRuntime {
|
|
|
324
432
|
}
|
|
325
433
|
};
|
|
326
434
|
for (const [role, policy] of Object.entries(document?.settings.roleRouting ?? {})) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
435
|
+
const prefixes = [...policy?.primary === undefined ? [] : [`roleRouting.${role}.primary.`], ...Object.keys(policy?.levels ?? {}).map(level => `roleRouting.${role}.levels.${level}.`)];
|
|
436
|
+
for (const prefix of prefixes)
|
|
437
|
+
for (const path of Object.keys(sources).filter((path) => path.startsWith(prefix))) {
|
|
438
|
+
delete sources[path];
|
|
439
|
+
delete fields[path];
|
|
440
|
+
}
|
|
334
441
|
}
|
|
335
442
|
mark(document?.settings ?? {}, []);
|
|
336
443
|
return Object.freeze({ ...selectionState(selection), settings, baseline, epoch, scope, ...(deployment === undefined ? {} : { deployment }),
|
|
444
|
+
warnings: freezeSettings(warnings), roleAvailability: freezeSettings(this.roleAvailability(settings, baseline, deployment, document)), subagentRuntime: freezeSettings(this.subagentRuntimeView()),
|
|
337
445
|
...(this.store.origin === undefined ? {} : { store: Object.freeze({ origin: this.store.origin, readOnly: this.store.readOnly === true,
|
|
338
446
|
...(this.store.writeRestriction === undefined ? {} : { writeRestriction: this.store.writeRestriction }) }) }),
|
|
339
447
|
sources: Object.freeze(sources), sourceCaptures: Object.freeze({ fields: Object.freeze(fields), ...(this.options.startup === undefined ? {} : { startup: Object.freeze({
|
|
@@ -342,8 +450,7 @@ export class DsmmProfileRuntime {
|
|
|
342
450
|
}
|
|
343
451
|
declaredProfileModel(settings, role) {
|
|
344
452
|
const primary = role === undefined ? undefined : settings.roleRouting[role]?.primary;
|
|
345
|
-
return primary === undefined ? undefined :
|
|
346
|
-
...(primary.reasoningEffort === undefined ? {} : { reasoningEffort: primary.reasoningEffort }) };
|
|
453
|
+
return primary === undefined ? undefined : normalizeModelRouteJson(primary);
|
|
347
454
|
}
|
|
348
455
|
agents() { return this.ctx.get?.("agents"); }
|
|
349
456
|
bind(agent) {
|
|
@@ -361,24 +468,22 @@ export class DsmmProfileRuntime {
|
|
|
361
468
|
// The native factory enters the exact child/owner pair before announcing
|
|
362
469
|
// creation. Durable lineage and inherited persona never establish ownership.
|
|
363
470
|
const parent = this.owner(agent);
|
|
364
|
-
|
|
471
|
+
if (parent === undefined && agent.session.header?.origin === "subagent")
|
|
472
|
+
throw new DsmmProfileError("not-owned", "A child requires exact direct-parent admission, not current root defaults.");
|
|
473
|
+
if (parent !== undefined)
|
|
474
|
+
throw new DsmmProfileError("activation", "A retained child must complete role validation and authority registration before its settings are published.");
|
|
475
|
+
const admitted = this.current;
|
|
476
|
+
this.assertRootRole(agent, admitted.settings);
|
|
477
|
+
this.validateRootRole(agent, admitted);
|
|
365
478
|
this.bound.set(agent, admitted);
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
bindChild(agent, parent) {
|
|
369
|
-
const retained = childAdmissions.get(agent);
|
|
370
|
-
if (retained !== undefined) {
|
|
371
|
-
const registry = this.agents();
|
|
372
|
-
if (parent !== retained.parent || registry?.get !== undefined && (agent.id === undefined || registry.get(agent.id) !== agent)) {
|
|
373
|
-
throw new DsmmProfileError("not-owned", "The retained child's exact live owner changed; its captured admission was not rebound.");
|
|
374
|
-
}
|
|
479
|
+
try {
|
|
480
|
+
this.options.childAuthority?.registerParent(agent, admitted, this.options.childAuthorityOwner ?? this);
|
|
375
481
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
return admission;
|
|
482
|
+
catch (error) {
|
|
483
|
+
this.bound.delete(agent);
|
|
484
|
+
throw error;
|
|
485
|
+
}
|
|
486
|
+
return admitted;
|
|
382
487
|
}
|
|
383
488
|
owner(agent) {
|
|
384
489
|
const agents = this.agents();
|
|
@@ -395,12 +500,29 @@ export class DsmmProfileRuntime {
|
|
|
395
500
|
throw new DsmmProfileError("not-owned", "Session profile selection requires the exact live ordinary root Agent.");
|
|
396
501
|
}
|
|
397
502
|
}
|
|
503
|
+
/** Host-only awaited completion for fresh, retained and cold exact Agents; no execution occurs here. */
|
|
504
|
+
async completeAdmission(agent, signal, startup) {
|
|
505
|
+
await this.admit(agent, signal, startup);
|
|
506
|
+
return this.bound.get(agent);
|
|
507
|
+
}
|
|
398
508
|
async admit(agent, signal, startup) {
|
|
399
509
|
if (this.bound.has(agent))
|
|
400
510
|
return;
|
|
401
511
|
const parent = this.owner(agent);
|
|
402
|
-
if (
|
|
512
|
+
if (parent !== undefined) {
|
|
513
|
+
this.assertDeliveryFence();
|
|
514
|
+
if (this.options.childAdmission === undefined)
|
|
515
|
+
throw new DsmmProfileError("unavailable", "Child admission completion is not installed; no child policy was inferred from its current parent.");
|
|
516
|
+
const ticket = this.options.childAuthority.acquireParentTicket(parent);
|
|
517
|
+
this.assertOwnedParentTicket(ticket);
|
|
518
|
+
const merged = AbortSignal.any([ticket.signal, ...signal === undefined ? [] : [signal]]);
|
|
519
|
+
const prepared = await this.options.childAdmission.prepare(agent, parent, ticket, merged);
|
|
520
|
+
merged.throwIfAborted();
|
|
521
|
+
await this.completeChildAdmission(agent, parent, prepared, merged);
|
|
403
522
|
return;
|
|
523
|
+
}
|
|
524
|
+
if (agent.session.header?.origin === "subagent")
|
|
525
|
+
throw new DsmmProfileError("not-owned", "A child cannot be admitted as a new root without its exact live direct parent.");
|
|
404
526
|
if (agent.id === undefined) {
|
|
405
527
|
this.bind(agent);
|
|
406
528
|
return;
|
|
@@ -420,29 +542,219 @@ export class DsmmProfileRuntime {
|
|
|
420
542
|
const candidate = selection.admissionEpoch === null
|
|
421
543
|
? this.options.readDesired === undefined ? this.current : this.prepare(this.currentDocument, this.current, newEpoch(), "global-default", deployment)
|
|
422
544
|
: this.prepare(selection.document, selection, selection.admissionEpoch, selection.selectedId === null ? "deployment-baseline" : "session-override", deployment);
|
|
545
|
+
this.assertRootRole(agent, candidate.settings);
|
|
546
|
+
this.validateRootRole(agent, candidate);
|
|
423
547
|
if (this.options.readDesired !== undefined)
|
|
424
|
-
await this.validate(candidate.settings
|
|
548
|
+
await this.validate(candidate.settings);
|
|
425
549
|
signal?.throwIfAborted();
|
|
426
550
|
if (this.disposed || this.disposedAgents.has(agent))
|
|
427
551
|
throw new DsmmProfileError("disposed", "The session was disposed during deployment admission.");
|
|
428
552
|
if (registry?.get !== undefined && registry.get(agent.id) !== agent)
|
|
429
553
|
throw new DsmmProfileError("not-owned", "The live session changed during deployment admission.");
|
|
554
|
+
this.assertRootRole(agent, candidate.settings);
|
|
555
|
+
this.validateRootRole(agent, candidate);
|
|
430
556
|
this.bound.set(agent, candidate);
|
|
557
|
+
try {
|
|
558
|
+
this.options.childAuthority?.registerParent(agent, candidate, this.options.childAuthorityOwner ?? this);
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
this.bound.delete(agent);
|
|
562
|
+
throw error;
|
|
563
|
+
}
|
|
564
|
+
await this.announceAdmission(agent);
|
|
565
|
+
signal?.throwIfAborted();
|
|
566
|
+
if (this.disposed || this.disposedAgents.has(agent))
|
|
567
|
+
throw new DsmmProfileError("disposed", "Root enrollment lost its live admission.");
|
|
568
|
+
if (registry?.get !== undefined && registry.get(agent.id) !== agent)
|
|
569
|
+
throw new DsmmProfileError("not-owned", "Root enrollment lost its exact residency.");
|
|
431
570
|
}
|
|
432
571
|
finally {
|
|
433
572
|
this.admitting.delete(agent);
|
|
434
573
|
}
|
|
435
574
|
}
|
|
436
|
-
|
|
575
|
+
/** Awaited native creation completion: evidence + persistence + role identity + exact-parent authority. */
|
|
576
|
+
async completeChildAdmission(agent, parent, prepared, signal) {
|
|
577
|
+
this.assertDeliveryFence();
|
|
578
|
+
if (this.options.childAdmission === undefined)
|
|
579
|
+
throw new DsmmProfileError("unavailable", "Child role validation is unavailable.");
|
|
580
|
+
const ticket = this.options.childAuthority.acquireParentTicket(parent);
|
|
581
|
+
this.assertOwnedParentTicket(ticket);
|
|
582
|
+
const merged = AbortSignal.any([ticket.signal, ...signal === undefined ? [] : [signal]]);
|
|
583
|
+
const evidence = "mode" in prepared.evidence ? parseLegacyChildEvidence(prepared.evidence) : parseChildAdmissionCapture(prepared.evidence);
|
|
584
|
+
const check = () => {
|
|
585
|
+
merged.throwIfAborted();
|
|
586
|
+
if (this.disposed || this.disposedAgents.has(agent) || this.owner(agent) !== parent || this.agents()?.get?.(agent.id) !== agent || this.agents()?.get?.(parent.id) !== parent || evidence.childSessionId !== agent.id || evidence.parentSessionId !== parent.id)
|
|
587
|
+
throw new DsmmProfileError("not-owned", "The exact child or its direct parent changed during admission.");
|
|
588
|
+
const current = this.options.childAuthority.acquireParentTicket(parent);
|
|
589
|
+
this.assertOwnedParentTicket(current);
|
|
590
|
+
if (current.admission !== ticket.admission || current.owner !== ticket.owner)
|
|
591
|
+
throw new DsmmProfileError("conflict", "The child creation parent ticket changed.");
|
|
592
|
+
};
|
|
593
|
+
check();
|
|
594
|
+
if (prepared.creation && "mode" in evidence)
|
|
595
|
+
throw new DsmmProfileError("validation", "New children require a full original capture, not legacy evidence.");
|
|
596
|
+
const original = "mode" in evidence ? prepared.admission : admissionFromChildCapture(evidence, this.baseline);
|
|
597
|
+
const retained = childAdmissions.get(agent);
|
|
598
|
+
if (retained !== undefined && retained.parent !== parent)
|
|
599
|
+
throw new DsmmProfileError("not-owned", "The retained child's exact direct parent changed.");
|
|
600
|
+
if (retained !== undefined && prepared.creation)
|
|
601
|
+
throw new DsmmProfileError("validation", "A retained child cannot be admitted as a new creation.");
|
|
602
|
+
if (retained !== undefined && JSON.stringify(retained.evidence) !== JSON.stringify(evidence))
|
|
603
|
+
throw new DsmmProfileError("corrupt-selection", "Retained child evidence cannot be replaced by a new parent policy.");
|
|
604
|
+
const admission = retained?.admission ?? freezeSettings({ ...original, baseline: original.settings,
|
|
605
|
+
selectedId: original.profile?.id ?? null, appliedRevision: original.profile?.revision ?? null, selectionRevision: "absent" });
|
|
606
|
+
if (!("mode" in evidence)) {
|
|
607
|
+
if (prepared.creation && evidence.originalAdmissionEpoch !== ticket.parentEpoch)
|
|
608
|
+
throw new DsmmProfileError("conflict", "The child creation invocation epoch changed.");
|
|
609
|
+
if (prepared.admission.epoch !== evidence.originalAdmissionEpoch || JSON.stringify(prepared.admission.profile) !== JSON.stringify(evidence.profilePin))
|
|
610
|
+
throw new DsmmProfileError("validation", "Child admission identity does not match its original capture.");
|
|
611
|
+
if (this.options.childCapturePersistence === "resident") {
|
|
612
|
+
if (!prepared.creation && retained === undefined)
|
|
613
|
+
throw new DsmmProfileError("unavailable", "Resident-only child capture has no cold restart guarantee.");
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
if (this.childCaptureStore.readChildAdmission === undefined || this.childCaptureStore.createChildAdmission === undefined)
|
|
617
|
+
throw new DsmmProfileError("unavailable", "Durable child capture storage is unavailable.");
|
|
618
|
+
if (prepared.creation)
|
|
619
|
+
await this.childCaptureStore.createChildAdmission(evidence, check);
|
|
620
|
+
else {
|
|
621
|
+
const stored = await this.childCaptureStore.readChildAdmission(evidence.childSessionId, evidence.parentSessionId);
|
|
622
|
+
if (JSON.stringify(stored) !== JSON.stringify(evidence))
|
|
623
|
+
throw new DsmmProfileError("corrupt-selection", "The child evidence does not match its immutable stored capture.");
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
if (prepared.admission.profile !== null)
|
|
629
|
+
throw new DsmmProfileError("validation", "Legacy admission cannot synthesize an original profile pin.");
|
|
630
|
+
if (this.childCaptureStore.readChildAdmission === undefined)
|
|
631
|
+
throw new DsmmProfileError("unavailable", "Legacy admission requires a safe capture-absence check.");
|
|
632
|
+
if (await this.childCaptureStore.readChildAdmission(evidence.childSessionId, evidence.parentSessionId) !== null)
|
|
633
|
+
throw new DsmmProfileError("corrupt-selection", "A captured child cannot be downgraded to legacy recovery.");
|
|
634
|
+
}
|
|
635
|
+
check();
|
|
636
|
+
this.options.childAdmission.validateRole(agent, parent, { ...prepared, evidence, admission, retained: retained !== undefined });
|
|
637
|
+
check();
|
|
638
|
+
this.bound.set(agent, admission);
|
|
639
|
+
try {
|
|
640
|
+
this.options.childAuthority.registerParent(agent, admission, this.options.childAuthorityOwner ?? this);
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
this.bound.delete(agent);
|
|
644
|
+
throw error;
|
|
645
|
+
}
|
|
646
|
+
childAdmissions.set(agent, { parent, admission, evidence });
|
|
647
|
+
await this.announceAdmission(agent);
|
|
648
|
+
check();
|
|
649
|
+
}
|
|
650
|
+
/** C's scoped resolver callback: original resident/durable evidence, then explicit trusted legacy folds. */
|
|
651
|
+
async resolveOriginalChildEvidence(ticket, childId, signal, readLegacy) {
|
|
652
|
+
validateSessionProfileId(childId);
|
|
653
|
+
const merged = AbortSignal.any([ticket.signal, signal]);
|
|
654
|
+
const check = () => {
|
|
655
|
+
merged.throwIfAborted();
|
|
656
|
+
this.assertDeliveryFence();
|
|
657
|
+
if (this.disposed || this.disposedAgents.has(ticket.parent) || this.agents()?.get?.(ticket.parent.id) !== ticket.parent)
|
|
658
|
+
throw new DsmmProfileError("not-owned", "Original child evidence requires its exact live direct parent.");
|
|
659
|
+
const current = this.options.childAuthority.acquireParentTicket(ticket.parent);
|
|
660
|
+
this.assertOwnedParentTicket(current);
|
|
661
|
+
if (current.owner !== ticket.owner || current.admission !== ticket.admission || current.parentEpoch !== ticket.parentEpoch)
|
|
662
|
+
throw new DsmmProfileError("conflict", "The original child evidence ticket changed.");
|
|
663
|
+
};
|
|
664
|
+
check();
|
|
665
|
+
const child = this.agents().get(childId);
|
|
666
|
+
if (child !== undefined && this.owner(child) !== ticket.parent)
|
|
667
|
+
throw new DsmmProfileError("not-owned", "Original evidence is scoped to the actual direct child, not an ancestor.");
|
|
668
|
+
const retained = child === undefined ? undefined : childAdmissions.get(child);
|
|
669
|
+
if (retained !== undefined && retained.parent !== ticket.parent)
|
|
670
|
+
throw new DsmmProfileError("not-owned", "The retained evidence has a different exact parent.");
|
|
671
|
+
const checkChild = () => {
|
|
672
|
+
const current = this.agents().get(childId);
|
|
673
|
+
if (current !== undefined && this.owner(current) !== ticket.parent)
|
|
674
|
+
throw new DsmmProfileError("not-owned", "The addressed child's direct owner changed during evidence reading.");
|
|
675
|
+
if (retained !== undefined && (current !== child || childAdmissions.get(child) !== retained))
|
|
676
|
+
throw new DsmmProfileError("conflict", "The retained child residency changed during evidence reading.");
|
|
677
|
+
};
|
|
678
|
+
const stored = await this.childCaptureStore.readChildAdmission?.(childId, ticket.parent.id);
|
|
679
|
+
check();
|
|
680
|
+
checkChild();
|
|
681
|
+
if (stored !== undefined && stored !== null) {
|
|
682
|
+
const capture = parseChildAdmissionCapture(stored);
|
|
683
|
+
if (capture.childSessionId !== childId || capture.parentSessionId !== ticket.parent.id || retained !== undefined && JSON.stringify(retained.evidence) !== JSON.stringify(capture))
|
|
684
|
+
throw new DsmmProfileError("corrupt-selection", "Original child capture identity does not match its scoped residency.");
|
|
685
|
+
return capture;
|
|
686
|
+
}
|
|
687
|
+
if (retained !== undefined) {
|
|
688
|
+
if (!("mode" in retained.evidence)) {
|
|
689
|
+
if (this.options.childCapturePersistence !== "resident")
|
|
690
|
+
throw new DsmmProfileError("corrupt-selection", "The durable original child capture is missing; legacy recovery is not allowed.");
|
|
691
|
+
return retained.evidence;
|
|
692
|
+
}
|
|
693
|
+
if (stored === undefined)
|
|
694
|
+
throw new DsmmProfileError("unavailable", "Legacy evidence requires a safe capture-absence check.");
|
|
695
|
+
return retained.evidence;
|
|
696
|
+
}
|
|
697
|
+
if (stored === undefined || readLegacy === undefined)
|
|
698
|
+
throw new DsmmProfileError("unavailable", "Original capture is unavailable; only an explicit trusted legacy evidence reader can recover a captureless child.");
|
|
699
|
+
const evidence = parseLegacyChildEvidence(await readLegacy(ticket, childId, merged));
|
|
700
|
+
check();
|
|
701
|
+
checkChild();
|
|
702
|
+
if (evidence.childSessionId !== childId || evidence.parentSessionId !== ticket.parent.id)
|
|
703
|
+
throw new DsmmProfileError("not-owned", "Legacy evidence does not identify the addressed direct child.");
|
|
704
|
+
return evidence;
|
|
705
|
+
}
|
|
706
|
+
assertOwnedParentTicket(ticket) {
|
|
707
|
+
if (ticket.owner !== (this.options.childAuthorityOwner ?? this) || this.bound.get(ticket.parent) !== ticket.admission || ticket.parentEpoch !== ticket.admission.epoch)
|
|
708
|
+
throw new DsmmProfileError("not-owned", "Child admission requires this entry's exact completed parent admission and owner.");
|
|
709
|
+
}
|
|
710
|
+
subagentRuntimeView() {
|
|
711
|
+
const view = this.options.childAuthority?.view() ?? { binding: "unavailable", deliveryFenceReady: false, restartRequired: true, reason: "explicit-composition-required" };
|
|
712
|
+
if (view.binding === "dsmm" && view.deliveryFenceReady && (this.options.childAdmission === undefined || this.options.validateRootRole === undefined))
|
|
713
|
+
return { ...view, deliveryFenceReady: false, restartRequired: true, reason: "authority-not-ready" };
|
|
714
|
+
return view;
|
|
715
|
+
}
|
|
716
|
+
assertDeliveryFence() {
|
|
717
|
+
const view = this.subagentRuntimeView();
|
|
718
|
+
if (view.binding !== "dsmm" || !view.deliveryFenceReady || this.options.childAuthority === undefined)
|
|
719
|
+
throw new DsmmProfileError("unavailable", "This operation requires the explicit DSMM SubagentRuntime composition and ready Host admission authority; configure and restart before retrying.");
|
|
720
|
+
}
|
|
721
|
+
assertRootRole(agent, settings) {
|
|
722
|
+
const role = resolveSelectedAgentPreset(agent.session);
|
|
723
|
+
if (isDsmmRoleId(role) && (!settings.modules.deepwork.enabled || !settings.roles[role]))
|
|
724
|
+
throw new DsmmProfileError("activation", "The selected root role is disabled by the candidate admission.", `settings.roles.${role}`, "deployment-ceiling");
|
|
725
|
+
if (role === "dsmm-planner" && !settings.presets.plannerRootEnabled)
|
|
726
|
+
throw new DsmmProfileError("activation", "The Planner root preset is disabled in the startup admission.", "settings.presets.plannerRootEnabled", "deployment-ceiling");
|
|
727
|
+
}
|
|
728
|
+
validateRootRole(agent, admission) {
|
|
729
|
+
if (this.options.childAuthority !== undefined && this.options.validateRootRole === undefined)
|
|
730
|
+
throw new DsmmProfileError("unavailable", "Root role admission completion is unavailable; no direct-parent authority was registered.");
|
|
731
|
+
this.options.validateRootRole?.(agent, admission);
|
|
732
|
+
}
|
|
733
|
+
roleAvailability(settings, baseline, deployment, document) {
|
|
734
|
+
return DSMM_ROLES.map(role => {
|
|
735
|
+
const required = requiredReason(settings, role.id), named = document?.settings.roles?.[role.id];
|
|
736
|
+
const startup = this.baseline.roles[role.id], desired = deployment?.settings.roles[role.id] ?? baseline.roles[role.id];
|
|
737
|
+
const admitted = settings.modules.deepwork.enabled && settings.roles[role.id];
|
|
738
|
+
const reason = !settings.modules.deepwork.enabled ? "module-off" : !desired ? "deployment-disabled" : !startup ? "startup-unavailable" : named === false ? "profile-disabled" : undefined;
|
|
739
|
+
const startupCeiling = !startup && desired;
|
|
740
|
+
const source = named !== undefined ? "named-session" : startupCeiling ? this.options.startup?.sources[`roles.${role.id}`] ?? "defaults" : deployment?.sources[`roles.${role.id}`] ?? "defaults";
|
|
741
|
+
const capture = named !== undefined ? "named-session" : startupCeiling ? "startup" : "deployment";
|
|
742
|
+
return { id: role.id, required: required !== undefined, ...(required === undefined ? {} : { requiredReason: required }), startupAvailable: startup, deploymentEnabled: desired,
|
|
743
|
+
...(named === undefined ? {} : { namedEnabled: named }), admitted, ...(reason === undefined ? {} : { reason }), source, capture };
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
async validate(settings, auditPresets = true) {
|
|
437
747
|
if (!settings.modules.deepwork.enabled)
|
|
438
748
|
return;
|
|
439
749
|
if (this.options.validateCandidate !== undefined) {
|
|
440
750
|
await this.options.validateCandidate(settings);
|
|
441
751
|
return;
|
|
442
752
|
}
|
|
753
|
+
if (!auditPresets)
|
|
754
|
+
return;
|
|
443
755
|
const registry = this.ctx.get?.("agentPresets");
|
|
444
756
|
if (registry !== undefined) {
|
|
445
|
-
for (const role of DSMM_ROLES.filter((role) =>
|
|
757
|
+
for (const role of DSMM_ROLES.filter((role) => isRootRoleEnabled(settings, role.id))) {
|
|
446
758
|
try {
|
|
447
759
|
const preset = await registry.resolve(role.id);
|
|
448
760
|
if (preset.broken !== undefined)
|
|
@@ -453,44 +765,6 @@ export class DsmmProfileRuntime {
|
|
|
453
765
|
}
|
|
454
766
|
}
|
|
455
767
|
}
|
|
456
|
-
// New-root capture validates deployment/schema and standing capability, not
|
|
457
|
-
// dormant role routes. Actual root requests and role/alias preflight own
|
|
458
|
-
// model selection. Named Apply and retained-root startup keep full audits.
|
|
459
|
-
if (!auditCatalog)
|
|
460
|
-
return;
|
|
461
|
-
const nativeAgent = agent ?? (this.agents()?.list() ?? []).find((candidate) => candidate.ctx?.get?.("llm")?.resolveCallConfig !== undefined);
|
|
462
|
-
const inherited = nativeAgent?.options;
|
|
463
|
-
const inheritedRoute = inherited?.provider === undefined || inherited.model === undefined ? undefined
|
|
464
|
-
: { provider: inherited.provider, model: inherited.model, ...(inherited.reasoningEffort === undefined ? {} : { reasoningEffort: inherited.reasoningEffort }) };
|
|
465
|
-
const chains = [];
|
|
466
|
-
for (const role of DSMM_ROLES) {
|
|
467
|
-
if (!settings.roles[role.id])
|
|
468
|
-
continue;
|
|
469
|
-
const policy = resolveRoleRuntimePolicy(settings, role.id);
|
|
470
|
-
// No explicit primary inherits native routing. Dormant fallbacks alone
|
|
471
|
-
// cannot make a usable inherited route fail profile Apply. If that exact
|
|
472
|
-
// route is unavailable here, native request preflight remains authority.
|
|
473
|
-
if (policy.primary === undefined && inheritedRoute === undefined)
|
|
474
|
-
continue;
|
|
475
|
-
const routes = [policy.primary ?? inheritedRoute, ...policy.fallbackRoutes];
|
|
476
|
-
if (routes.length > 0)
|
|
477
|
-
chains.push({ routes, field: `settings.roleRouting.${role.id}.${policy.primary === undefined ? "fallbackRoutes" : "primary"}` });
|
|
478
|
-
}
|
|
479
|
-
if (chains.length === 0)
|
|
480
|
-
return;
|
|
481
|
-
const llm = nativeAgent?.ctx?.get?.("llm")
|
|
482
|
-
?? this.ctx.get?.("llm") ?? (this.ctx.get === undefined ? this.ctx.llm : undefined);
|
|
483
|
-
if (llm?.resolveCallConfig === undefined) {
|
|
484
|
-
throw new DsmmProfileError("activation", "Open a chat so its native model service can validate configured routes before applying this profile.");
|
|
485
|
-
}
|
|
486
|
-
for (const { routes, field } of chains) {
|
|
487
|
-
try {
|
|
488
|
-
await selectInitialModelRoute(llm, routes, signal);
|
|
489
|
-
}
|
|
490
|
-
catch {
|
|
491
|
-
throw new DsmmProfileError("activation", "The configured provider, model or exact reasoning effort is unavailable in the native model catalog.", field);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
768
|
}
|
|
495
769
|
}
|
|
496
770
|
function newEpoch() { return createHash("sha256").update(randomUUID()).digest("hex"); }
|
|
@@ -516,7 +790,8 @@ export async function createProfileRuntime(ctx, baseline, options = {}) {
|
|
|
516
790
|
// constructor path has one compatibility namespace, not a guessed entry.
|
|
517
791
|
const entry = options.startup?.entryId ?? (ctx instanceof Context ? ctx.fiber.entry?.id : undefined) ?? "trusted-direct";
|
|
518
792
|
const store = exists ? ProfileStore.fromLegacy(legacy) : ProfileStore.fromCentral(resolveDshHome(profile.home), profile.dir, entry);
|
|
519
|
-
const
|
|
793
|
+
const childCaptureStore = options.childCaptureStore ?? (exists ? ProfileStore.fromCentral(resolveDshHome(profile.home), profile.dir, entry) : store);
|
|
794
|
+
const runtime = new DsmmProfileRuntime(ctx, baseline, store, { ...options, childCaptureStore });
|
|
520
795
|
await runtime.initialize();
|
|
521
796
|
return runtime;
|
|
522
797
|
}
|