@dsmm/dsmm 0.3.1 → 0.3.3

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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/docs/agent-presets.md +5 -5
  3. package/docs/compatibility.md +7 -1
  4. package/docs/migration-from-ocmm.md +1 -1
  5. package/docs/releasing.md +25 -65
  6. package/docs/roadmap.md +37 -2
  7. package/docs/settings-status.md +1 -1
  8. package/lib/client/DeploymentFields.d.ts +6 -2
  9. package/lib/client/DeploymentFields.js +8 -6
  10. package/lib/client/DeploymentPage.d.ts +1 -0
  11. package/lib/client/DeploymentPage.js +4 -3
  12. package/lib/client/ProfilesSection.js +3 -3
  13. package/lib/client/RoleAvailability.js +1 -1
  14. package/lib/client/SessionProfiles.js +21 -18
  15. package/lib/client/controller.d.ts +17 -0
  16. package/lib/client/controller.js +104 -18
  17. package/lib/client/deployment-locales.js +26 -27
  18. package/lib/client/deployment-modules.js +1 -1
  19. package/lib/client/index.js +10 -2
  20. package/lib/client/locales.d.ts +6 -0
  21. package/lib/client/locales.js +148 -124
  22. package/lib/client/permission-locales.js +35 -35
  23. package/lib/client.js +645 -542
  24. package/lib/index.js +10 -5
  25. package/lib/native-admission.d.ts +18 -0
  26. package/lib/native-admission.js +174 -17
  27. package/lib/permission-control.d.ts +2 -0
  28. package/lib/permission-control.js +7 -0
  29. package/lib/permission-controller.js +2 -2
  30. package/lib/permission-native-rules.js +3 -3
  31. package/lib/preset-materializer.js +3 -3
  32. package/lib/preset-registry.d.ts +20 -2
  33. package/lib/preset-registry.js +46 -17
  34. package/lib/preset-skills.d.ts +1 -1
  35. package/lib/preset-skills.js +2 -2
  36. package/lib/profile-diagnostics.js +1 -1
  37. package/lib/profile-remote.js +1 -3
  38. package/lib/profile-rpc.js +2 -0
  39. package/lib/profile-runtime.d.ts +12 -1
  40. package/lib/profile-runtime.js +122 -10
  41. package/lib/profile-store.d.ts +2 -2
  42. package/lib/profile-store.js +8 -1
  43. package/lib/profile-types.d.ts +1 -0
  44. package/lib/role-invocation.d.ts +1 -1
  45. package/lib/role-invocation.js +2 -2
  46. package/lib/role-policy.js +2 -2
  47. package/lib/role-subagents.js +18 -4
  48. package/lib/roles.d.ts +2 -0
  49. package/lib/roles.js +2 -0
  50. package/lib/settings.d.ts +1 -3
  51. package/lib/settings.js +4 -9
  52. package/lib/skills.d.ts +1 -0
  53. package/lib/skills.js +5 -1
  54. package/package.json +37 -33
@@ -38,7 +38,7 @@ const configFields = {
38
38
  deepseekV4ProMaxReasoningPresets: null, deepseekFlashMaxReasoningPresets: null,
39
39
  modules: { deepwork: { enabled: null } },
40
40
  skills: "skills", roles: "roles", roleRouting: "role-routing", runtimePolicy: { strategy: null, rateLimit },
41
- presets: { materialize: null, plannerRootEnabled: null, root: null }, subagents: { toolTopology: null, allowRouteOverride: null, enableRunInBackground: null, backgroundMode: null, maxDepth: null },
41
+ presets: { materialize: null, root: null }, subagents: { toolTopology: null, allowRouteOverride: null, enableRunInBackground: null, backgroundMode: null, maxDepth: null },
42
42
  workflow: { policy: null, strictGates: null, reviewCap: null, finalReviewPolicy: null },
43
43
  guards: { scope: null, shellCommandSafety: null, gitWriteGuard: null, toolOutputTruncation: { enabled: null, maxInlineBytes: null }, planFormatValidation: null, questionLabelHelper: { enabled: null, maxLabelChars: null }, todoDisciplineHelper: null },
44
44
  runtimeRecovery: { enabled: null, retryOnStatusCodes: [null], retryOnCodes: [null], fallbackRoutes: [route], maxFallbackAttempts: null, idleContinuation: { enabled: null, maxContinuations: null, prompt: null } },
@@ -413,9 +413,7 @@ function readOnlySettingsData(value) {
413
413
  fail("private environment");
414
414
  }
415
415
  if (settings.presets !== undefined) {
416
- const presets = object(settings.presets, ["materialize"], ["root", "plannerRootEnabled"]);
417
- if (Object.hasOwn(presets, "plannerRootEnabled"))
418
- boolean(presets.plannerRootEnabled, "presets.plannerRootEnabled");
416
+ const presets = object(settings.presets, ["materialize"], ["root"]);
419
417
  if (presets.root !== undefined && presets.root !== "<configured>")
420
418
  fail("private directory");
421
419
  }
@@ -132,6 +132,8 @@ let DsmmProfilesHost = (() => {
132
132
  const checkAuthority = () => {
133
133
  if (signal.aborted)
134
134
  throw new DsmmProfileError("cancelled", "The session profile operation was cancelled; no late selection is allowed.");
135
+ if (!readOnly)
136
+ assertLocalSettingsOperator(this.ctx);
135
137
  const currentConnection = this.ctx.get("connection");
136
138
  const currentOwner = currentConnection === undefined ? undefined : Reflect.get(currentConnection, symbols.original) ?? currentConnection;
137
139
  if (currentOwner !== connectionOwner || currentConnection?.browserPeer !== invocation.peer) {
@@ -6,6 +6,7 @@ import type { DsmmProfileAdmission, DsmmSettings, DsmmSettingsGetter, DsmmDeploy
6
6
  import { DeepworkModeController } from "./state.js";
7
7
  import type { DsmmMountedPermissionGetter } from "./modules.js";
8
8
  export interface DsmmProfileRuntimeStore {
9
+ readonly profileDir?: string;
9
10
  readonly readOnly?: boolean;
10
11
  readonly origin?: "central" | "legacy" | "explicit";
11
12
  readonly writeRestriction?: string;
@@ -36,6 +37,12 @@ export type DsmmSessionProfileSnapshot = SessionProfileSnapshot;
36
37
  interface AdmittedProfile extends ProfileSelectionState, DsmmProfileAdmission {
37
38
  baseline: DsmmSettings;
38
39
  }
40
+ export interface PreparedHistoryProfile {
41
+ readonly admission: DsmmProfileAdmission;
42
+ readonly label?: string;
43
+ assertCurrent(): undefined;
44
+ revalidate(signal: AbortSignal): Promise<void>;
45
+ }
39
46
  /** Configuration transactions and immutable snapshots; native admission owns Agent binding. */
40
47
  export declare class DsmmProfileRuntime {
41
48
  private readonly ctx;
@@ -47,6 +54,7 @@ export declare class DsmmProfileRuntime {
47
54
  private document;
48
55
  private readonly bound;
49
56
  private readonly observations;
57
+ private readonly historyAdmissions;
50
58
  private disposed;
51
59
  private queue;
52
60
  private readonly mode;
@@ -58,10 +66,13 @@ export declare class DsmmProfileRuntime {
58
66
  /** Called only by the awaited native creation owner after all Agent-scoped installation. */
59
67
  publish(agent: DshAgent, admission: DsmmProfileAdmission): void;
60
68
  release(agent: DshAgent): void;
69
+ /** Prepare an explicit current choice; historical selection files and epochs are not read. */
70
+ prepareHistory(profileId: string | null, signal: AbortSignal): Promise<PreparedHistoryProfile>;
61
71
  prepareRoot(agent: DshAgent, signal: AbortSignal): Promise<AdmittedProfile>;
62
72
  getSession(agent: DshAgent): Promise<DsmmSessionProfileSnapshot>;
73
+ private sessionSnapshot;
63
74
  selectMode(request: SessionModeSelectRequest, agent: DshAgent, signal?: AbortSignal, authority?: () => void): Promise<DsmmSessionProfileSnapshot>;
64
- selectSession(_request: SessionProfileSelectRequest, agent: DshAgent, _signal?: AbortSignal, _authority?: () => void): Promise<SessionProfileSnapshot>;
75
+ selectSession(request: SessionProfileSelectRequest, agent: DshAgent, signal?: AbortSignal, authority?: () => void): Promise<SessionProfileSnapshot>;
65
76
  private assertRoot;
66
77
  describe(): Promise<ProfileSnapshot>;
67
78
  read(id: string): Promise<ProfileReadResult>;
@@ -1,9 +1,10 @@
1
1
  import { join } from "node:path";
2
2
  import { randomBytes } from "node:crypto";
3
- import { lstatSync } from "node:fs";
3
+ import { lstatSync, realpathSync } from "node:fs";
4
+ import { isDeepStrictEqual } from "node:util";
4
5
  import { Context } from "@deepseek-ai/cordis";
5
6
  import { ProfileStore, validateSessionProfileId } from "./profile-store.js";
6
- import { DsmmProfileError, profileDocumentWarnings, requiredReason, resolveProfileSettings } from "./profiles.js";
7
+ import { DsmmProfileError, parseProfileDocument, profileDocumentWarnings, requiredReason, resolveProfileSettings, validateProfileId } from "./profiles.js";
7
8
  import { DSMM_ROLES, isDsmmRoleId } from "./roles.js";
8
9
  import { freezeSettings, isRootRoleEnabled } from "./settings.js";
9
10
  import { roleRouteRuntimeState } from "./role-routing.js";
@@ -36,6 +37,7 @@ export class DsmmProfileRuntime {
36
37
  document = null;
37
38
  bound = new WeakMap();
38
39
  observations = new WeakMap();
40
+ historyAdmissions = new WeakSet();
39
41
  disposed = false;
40
42
  queue = Promise.resolve();
41
43
  mode;
@@ -88,6 +90,51 @@ export class DsmmProfileRuntime {
88
90
  this.bound.set(agent, admission);
89
91
  }
90
92
  release(agent) { this.bound.delete(agent); }
93
+ /** Prepare an explicit current choice; historical selection files and epochs are not read. */
94
+ async prepareHistory(profileId, signal) {
95
+ this.assertCurrent();
96
+ signal.throwIfAborted();
97
+ if (profileId !== null)
98
+ validateProfileId(profileId);
99
+ const directory = profileId === null ? undefined : this.store.profileDir;
100
+ if (profileId !== null && directory === undefined)
101
+ throw new DsmmProfileError("unavailable", "History continuation requires an observable saved-profile store.");
102
+ const path = directory === undefined ? undefined : join(directory, `${profileId}.jsonc`);
103
+ const observe = () => {
104
+ if (path === undefined)
105
+ return undefined;
106
+ const stat = lstatSync(path, { bigint: true }), parent = lstatSync(directory, { bigint: true });
107
+ if (!stat.isFile() || stat.isSymbolicLink() || !parent.isDirectory() || parent.isSymbolicLink())
108
+ throw new DsmmProfileError("unsafe-path", "The saved profile source is not a regular file.");
109
+ return [realpathSync(directory), parent.dev, parent.ino, stat.dev, stat.ino, stat.size, stat.mtimeNs, stat.ctimeNs];
110
+ };
111
+ const source = observe();
112
+ const saved = profileId === null ? null : await this.store.read(profileId);
113
+ const deployment = await this.options.readDesired?.();
114
+ const document = saved === null ? null : parseProfileDocument(saved.content, saved.id);
115
+ const candidate = this.prepare(document, { selectedId: profileId, appliedRevision: saved?.revision ?? null,
116
+ selectionRevision: "unavailable", ...(saved === null ? {} : { sourceRevision: saved.revision }) }, newEpoch(), profileId === null ? "deployment-baseline" : "session-override", deployment);
117
+ const assertCurrent = () => {
118
+ this.assertCurrent();
119
+ signal.throwIfAborted();
120
+ if (!isDeepStrictEqual(source, observe()))
121
+ throw new DsmmProfileError("conflict", "The saved profile changed during history continuation.");
122
+ };
123
+ await this.validate(candidate.settings);
124
+ assertCurrent();
125
+ this.historyAdmissions.add(candidate);
126
+ return { admission: candidate, ...(saved?.label === undefined ? {} : { label: saved.label }), assertCurrent,
127
+ revalidate: async (currentSignal) => {
128
+ currentSignal.throwIfAborted();
129
+ assertCurrent();
130
+ const desired = await this.options.readDesired?.();
131
+ if (!isDeepStrictEqual(desired, deployment))
132
+ throw new DsmmProfileError("conflict", "Deployment changed during history continuation.");
133
+ await this.validate(candidate.settings);
134
+ currentSignal.throwIfAborted();
135
+ assertCurrent();
136
+ } };
137
+ }
91
138
  async prepareRoot(agent, signal) {
92
139
  this.assertRoot(agent);
93
140
  signal.throwIfAborted();
@@ -112,19 +159,24 @@ export class DsmmProfileRuntime {
112
159
  const disk = await this.store.loadSessionSelection(agent.id);
113
160
  await this.ctx.get?.("dsmmNativeAdmission")?.ensure?.(agent);
114
161
  this.assertRoot(agent);
115
- if (this.admission(agent) !== admitted || (disk.admissionEpoch === null && admitted.scope !== "global-default")
116
- || (disk.admissionEpoch !== null && (disk.admissionEpoch !== admitted.epoch || disk.selectedId !== admitted.selectedId || disk.appliedRevision !== admitted.appliedRevision))) {
162
+ if (this.admission(agent) !== admitted || !this.historyAdmissions.has(admitted) && ((disk.admissionEpoch === null && admitted.scope !== "global-default")
163
+ || (disk.admissionEpoch !== null && (disk.admissionEpoch !== admitted.epoch || disk.selectedId !== admitted.selectedId || disk.appliedRevision !== admitted.appliedRevision)))) {
117
164
  throw new DsmmProfileError("conflict", "The session choice changed outside this owner; its admitted configuration was retained.");
118
165
  }
166
+ if (disk.admissionEpoch === admitted.epoch)
167
+ this.observations.set(admitted, selectionState(disk));
168
+ return this.sessionSnapshot(agent, admitted, disk);
169
+ }
170
+ sessionSnapshot(agent, admitted, disk, inMaintenance = false) {
119
171
  const role = resolveAdmittedDsmmRole(agent, admitted.settings, this.mode.active(agent, admitted.settings.defaultActive));
120
172
  const profileModel = role === undefined ? undefined : admitted.settings.roleRouting[role]?.primary;
121
173
  const deepwork = this.mode.describe(agent, admitted.settings.defaultActive);
122
- return { sessionId: agent.id, globalDefault: this.observedSelection(this.current), selection: selectionState(disk), admittedSelection: selectionState(admitted), scope: admitted.scope,
174
+ return { sessionId: agent.id, globalDefault: this.observedSelection(this.current), selection: selectionState(disk), admittedSelection: this.observedSelection(admitted), scope: admitted.scope,
123
175
  rolePolicy: structuredClone(roleRouteRuntimeState(agent, admitted.settings, role, admitted.epoch)), deepwork,
124
176
  modules: projectDsmmModules(this.baseline, admitted.deployment, admitted, false, this.options.getMountedPermission), configuration: deploymentAdmissionView(admitted),
125
177
  warnings: structuredClone(admitted.warnings ?? []), roles: structuredClone(admitted.roleAvailability ?? []), subagentRuntime: this.runtimeView(),
126
178
  ...(profileModel === undefined ? {} : { profileModel: structuredClone(profileModel) }), admissionEpoch: admitted.epoch,
127
- ...this.sessionActions(agent, admitted, deepwork, profileModel !== undefined), switchAllowed: false, switchUnavailableReason: "unavailable" };
179
+ ...this.sessionActions(agent, admitted, deepwork, profileModel !== undefined, inMaintenance), switchAllowed: false, switchUnavailableReason: "unavailable" };
128
180
  }
129
181
  async selectMode(request, agent, signal, authority) {
130
182
  this.assertRoot(agent);
@@ -168,9 +220,68 @@ export class DsmmProfileRuntime {
168
220
  throw new DsmmProfileError("maintenance", "The native session refused the Deepwork change.");
169
221
  }
170
222
  }
171
- async selectSession(_request, agent, _signal, _authority) {
223
+ async selectSession(request, agent, signal, authority) {
172
224
  this.assertRoot(agent);
173
- throw new DsmmProfileError("unavailable", "Live Apply is unavailable; save and select a default for new sessions.");
225
+ if (this.historyAdmissions.has(this.admission(agent)))
226
+ throw new DsmmProfileError("unavailable", "A continued historical Agent is not a blank configuration target.");
227
+ if (request.sessionId !== agent.id)
228
+ throw new DsmmProfileError("not-owned", "The native session does not match the captured Agent.");
229
+ const previous = this.admission(agent);
230
+ const owner = this.ctx.get?.("dsmmNativeAdmission");
231
+ const check = (maintenanceSignal) => {
232
+ this.assertRoot(agent);
233
+ if (signal?.aborted || maintenanceSignal?.aborted)
234
+ throw new DsmmProfileError("cancelled", "The session configuration change was cancelled.");
235
+ if (this.admission(agent) !== previous || previous.epoch !== request.expectedAdmissionEpoch || this.ctx.get?.("dsmmNativeAdmission") !== owner) {
236
+ throw new DsmmProfileError("conflict", "The admitted session configuration changed; refresh before selecting again.");
237
+ }
238
+ authority?.();
239
+ };
240
+ check();
241
+ if (owner?.beginBlank === undefined || agent.runMaintenance === undefined)
242
+ throw new DsmmProfileError("unavailable", "Native blank-session configuration maintenance is unavailable.");
243
+ if (agent.status === "running")
244
+ throw new DsmmProfileError("busy", "Wait for the session to become idle.");
245
+ try {
246
+ return await agent.runMaintenance(async (maintenanceSignal) => {
247
+ check(maintenanceSignal);
248
+ const transaction = owner.beginBlank(agent, signal === undefined ? maintenanceSignal : AbortSignal.any([maintenanceSignal, signal]), () => check(maintenanceSignal));
249
+ const assertCurrent = () => transaction.assertCurrent();
250
+ let next, response;
251
+ try {
252
+ const epoch = newEpoch();
253
+ const result = await this.store.selectSession(request, epoch, async (document) => {
254
+ const deployment = await this.options.readDesired?.();
255
+ assertCurrent();
256
+ const candidate = this.prepare(document, { selectedId: request.id, appliedRevision: null, selectionRevision: "unavailable" }, epoch, request.id === null ? "deployment-baseline" : "session-override", deployment ?? previous.deployment);
257
+ await this.validate(candidate.settings);
258
+ assertCurrent();
259
+ return { candidate, document };
260
+ }, {
261
+ assertCurrent,
262
+ prepare: async (selection, prepared) => {
263
+ assertCurrent();
264
+ const candidate = prepared.candidate;
265
+ next = this.profileAdmission(selection, candidate.settings, selection.admissionEpoch, candidate.scope, candidate.baseline, candidate.deployment, candidate.restartRequired, prepared.document, selection.warnings);
266
+ await transaction.prepare(next, () => { response = this.sessionSnapshot(agent, next, selection, true); });
267
+ assertCurrent();
268
+ },
269
+ committed: () => { this.bound.set(agent, next); transaction.committed(); },
270
+ });
271
+ this.observations.set(next, selectionState(result.selection));
272
+ return { ...response, selection: selectionState(result.selection), admittedSelection: selectionState(result.selection),
273
+ ...(result.selection.refreshRequired ? { refreshRequired: true } : {}) };
274
+ }
275
+ finally {
276
+ await transaction.close();
277
+ }
278
+ });
279
+ }
280
+ catch (error) {
281
+ if (error instanceof DsmmProfileError)
282
+ throw error;
283
+ throw new DsmmProfileError("maintenance", "The native session refused the configuration change.");
284
+ }
174
285
  }
175
286
  assertRoot(agent) {
176
287
  this.assertCurrent();
@@ -324,7 +435,7 @@ export class DsmmProfileRuntime {
324
435
  return { id: role.id, label: role.name, enabled: admission.settings.roles[role.id], availability: admission.roleAvailability?.find(row => row.id === role.id), ...(Object.keys(runtimePolicy).length === 0 ? {} : { runtimePolicy }) };
325
436
  });
326
437
  }
327
- sessionActions(agent, admission, mode, hasProfileModel) {
438
+ sessionActions(agent, admission, mode, hasProfileModel, inMaintenance = false) {
328
439
  const llm = agent.ctx?.get?.("llm") ?? this.ctx.get?.("llm");
329
440
  const selectModelUnavailableReason = !hasProfileModel ? "model-unconfigured" : llm?.resolveCallConfig === undefined ? "model-service-unavailable" : undefined;
330
441
  const owner = this.ctx.get?.("dsmmNativeAdmission");
@@ -332,9 +443,10 @@ export class DsmmProfileRuntime {
332
443
  const toggleModeUnavailableReason = agent.status === "running" || hasOpenTurn(sessionEvents(agent.session)) ? "busy"
333
444
  : agent.runMaintenance === undefined ? "maintenance" : !mode.active && (!this.baseline.modules.deepwork.enabled || !admission.settings.modules.deepwork.enabled) ? "module-off"
334
445
  : mode.locked || !mode.active && !ready ? "runtime-unavailable" : undefined;
446
+ const applyOverlayUnavailableReason = this.historyAdmissions.has(admission) ? "new-session-required" : this.store.readOnly ? "runtime-unavailable" : owner?.blankReason?.(agent, inMaintenance) ?? (owner?.blankReason === undefined ? "runtime-unavailable" : undefined);
335
447
  return { canSelectModel: selectModelUnavailableReason === undefined, ...(selectModelUnavailableReason === undefined ? {} : { selectModelUnavailableReason }),
336
448
  canToggleMode: toggleModeUnavailableReason === undefined, ...(toggleModeUnavailableReason === undefined ? {} : { toggleModeUnavailableReason }),
337
- canApplyOverlay: false, applyOverlayUnavailableReason: "new-session-required" };
449
+ canApplyOverlay: applyOverlayUnavailableReason === undefined, ...(applyOverlayUnavailableReason === undefined ? {} : { applyOverlayUnavailableReason }) };
338
450
  }
339
451
  async validate(settings) {
340
452
  if (!settings.modules.deepwork.enabled)
@@ -16,8 +16,8 @@ export interface LoadedSessionProfileSelection extends LoadedProfileSelection {
16
16
  }
17
17
  export declare const MAX_SESSION_PROFILE_CHOICES = 1024;
18
18
  export interface SessionProfileCommit<T> {
19
- /** Fallible synchronous preparation before the final fence/rename; never publication. */
20
- prepare?(selection: LoadedSessionProfileSelection, prepared: T): void;
19
+ /** Fallible installation preparation before the final fence/rename; never publication. */
20
+ prepare?(selection: LoadedSessionProfileSelection, prepared: T): void | Promise<void>;
21
21
  /** Trusted native liveness/cancellation fence; invoked immediately before rename. */
22
22
  assertCurrent(): void;
23
23
  /** Synchronous publication after durable commit. Must not throw or await. */
@@ -179,7 +179,14 @@ export class ProfileStore {
179
179
  const bytes = Buffer.from(`${JSON.stringify(pointer)}\n`, "utf8");
180
180
  const selection = { sessionId: request.sessionId, admissionEpoch: epoch,
181
181
  selectedId: request.id, appliedRevision: revision, selectionRevision: "unavailable", document: draft?.document ?? null, content: draft?.content ?? null, ...source, ...warningFields(draft) };
182
- commit.prepare?.(selection, prepared);
182
+ try {
183
+ await commit.prepare?.(selection, prepared);
184
+ }
185
+ catch (error) {
186
+ if (error instanceof DsmmProfileError)
187
+ throw error;
188
+ throw new DsmmProfileError("activation", "The candidate installation could not be prepared; the previous session selection was retained.");
189
+ }
183
190
  const owned = this.atomicReplace(target, bytes, fence, assertLock);
184
191
  commit.committed(selection, prepared);
185
192
  const observed = observeCommitted(target, owned, this.observe);
@@ -203,6 +203,7 @@ export interface SessionProfileSnapshot {
203
203
  selectModelUnavailableReason?: SessionActionUnavailableReason;
204
204
  canToggleMode: boolean;
205
205
  toggleModeUnavailableReason?: SessionActionUnavailableReason;
206
+ /** Host-authoritative blank-session choice; never started-session hot Apply. */
206
207
  canApplyOverlay: boolean;
207
208
  applyOverlayUnavailableReason?: SessionActionUnavailableReason;
208
209
  rolePolicy?: DsmmRoleRuntimeState;
@@ -26,7 +26,7 @@ export declare function bindRoleInvocation(agent: DshAgent, invocation: Resolved
26
26
  export declare function capturedRoleInvocation(agent: DshAgent): ResolvedRoleInvocation | undefined;
27
27
  export declare function capturedOriginalRoleInvocation(agent: DshAgent): ChildAdmissionCapture["invocation"] | undefined;
28
28
  /** Complete selections replace model and effort together; effort-only selections narrow candidates. */
29
- export declare function resolveRoleInvocation(parent: Agent, target: DsmmRoleId, settings: DsmmSettings, signal: AbortSignal, options?: DsmmInvocationOptions, nativeOptions?: AgentOptions): Promise<ResolvedRoleInvocation>;
29
+ export declare function resolveRoleInvocation(parent: Agent, target: DsmmRoleId, settings: DsmmSettings, signal: AbortSignal, options?: DsmmInvocationOptions, nativeOptions?: AgentOptions, parameterPolicy?: ResolvedModelParameterPolicy): Promise<ResolvedRoleInvocation>;
30
30
  export declare function invocationAgentOptions(invocation: ResolvedRoleInvocation, options?: AgentOptions): AgentOptions;
31
31
  export declare function invocationView(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): {
32
32
  runId?: string | undefined;
@@ -27,7 +27,7 @@ export function bindRoleInvocation(agent, invocation, original) {
27
27
  export function capturedRoleInvocation(agent) { return captured.get(agent); }
28
28
  export function capturedOriginalRoleInvocation(agent) { return originalCaptures.get(agent)?.invocation; }
29
29
  /** Complete selections replace model and effort together; effort-only selections narrow candidates. */
30
- export async function resolveRoleInvocation(parent, target, settings, signal, options = {}, nativeOptions) {
30
+ export async function resolveRoleInvocation(parent, target, settings, signal, options = {}, nativeOptions, parameterPolicy) {
31
31
  if (!isDsmmRoleId(target) || target === "dsmm-orchestrator")
32
32
  throw new SubagentError("Unknown DSMM delegation target", "UNAUTHORIZED");
33
33
  if (Object.keys(options).some(key => key !== "level" && key !== "route"))
@@ -93,7 +93,7 @@ export async function resolveRoleInvocation(parent, target, settings, signal, op
93
93
  if (llm === undefined)
94
94
  throw new Error("DSMM invocation requires the parent's native LLM service");
95
95
  const admission = parent.ctx.get("dsmmProfileRuntime")?.admission(parent);
96
- const modelParameterPolicy = capturedRoleInvocation(parent)?.modelParameterPolicy
96
+ const modelParameterPolicy = parameterPolicy ?? capturedRoleInvocation(parent)?.modelParameterPolicy
97
97
  ?? (admission === undefined ? configuredModelParameterPolicy(settings) : resolvedModelParameterPolicy(admission));
98
98
  const project = (candidate, source) => modelRouteFromCall(projectModelRouteParameters(candidate, source, modelParameterPolicy.mode !== "native-defaults"));
99
99
  const projected = initialCandidates.map((candidate, index) => project(candidate, index === 0 || candidateEffort !== undefined ? effortSource : "dsmm-config"));
@@ -53,7 +53,7 @@ export class DsmmRolePolicy {
53
53
  this.assertLive(agent);
54
54
  this.assertLive(parent);
55
55
  this.assertDelegation(parent, invocation.target);
56
- if (!this.agents().isOwnedBy(agent.id, parent) || agent.session.header?.parentSession !== parent.id || this.selected(agent) !== invocation.target)
56
+ if (!this.agents().isOwnedBy(agent.id, parent) || agent.session.header?.parentSession !== parent.id || this.selected(agent) !== this.selected(parent))
57
57
  throw new SubagentError("Child lineage or composition mismatch", "UNAUTHORIZED");
58
58
  if (maximum !== undefined && delegationDepthOf(agent) > maximum)
59
59
  throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
@@ -70,7 +70,7 @@ export class DsmmRolePolicy {
70
70
  const settings = this.getSettings(agent), identity = liveIdentities.get(agent), selected = this.selected(agent);
71
71
  if (identity?.child) {
72
72
  this.assertLive(identity.parent);
73
- if (!this.agents().isOwnedBy(agent.id, identity.parent) || selected !== identity.role)
73
+ if (!this.agents().isOwnedBy(agent.id, identity.parent) || selected !== this.selected(identity.parent))
74
74
  throw new SubagentError("Child admission no longer matches composition", "UNAUTHORIZED");
75
75
  }
76
76
  else if (agent.session.header?.origin !== "subagent")
@@ -188,7 +188,8 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
188
188
  return admission.duringCall(parent, exec.signal, async (signal) => {
189
189
  const invocation = await resolveRoleInvocation(parent, role.id, current, signal, { ...(args.level === undefined ? {} : { level: args.level }), ...(args.route === undefined ? {} : { route: args.route }) });
190
190
  const capturedProvider = provider;
191
- const request = { parent, agentPreset: role.id, prompt: [{ type: "text", text: args.prompt }],
191
+ const parentComposition = parent.ctx.get?.("agentPresets")?.composedPreset(parent.ctx);
192
+ const request = { parent, ...(parentComposition === undefined ? {} : { agentPreset: parentComposition }), prompt: [{ type: "text", text: args.prompt }],
192
193
  agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
193
194
  const assertCurrent = () => {
194
195
  if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
@@ -293,12 +294,18 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
293
294
  const host = ctx.get?.("tools");
294
295
  const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];
295
296
  const definitions = names.map((name) => host?.get(name));
297
+ const providers = targets.map(role => {
298
+ const provider = subagents?.getProvider(roleProviderName(role));
299
+ return provider === undefined ? undefined : Reflect.get(provider, symbols.original) ?? provider;
300
+ });
301
+ const sameProviders = providers.length === state.providers.length && providers.every((provider, index) => provider === state.providers[index]);
296
302
  const signature = JSON.stringify([identity.role, targets, settings.subagents, targets.map((role) => [settings.roleRouting[role], subagents?.getProvider(roleProviderName(role))?.capabilities])]);
297
303
  const sameRealm = state.tools !== undefined && (Reflect.get(state.tools, symbols.original) ?? state.tools) === (Reflect.get(tools, symbols.original) ?? tools);
298
304
  const parentScope = scopeParentOf(agent);
299
305
  const sameParent = state.parentScope === parentScope;
300
- if (sameRealm && sameParent && signature === state.signature && definitions.length === state.hostDefinitions.length && definitions.every((definition, i) => definition === state.hostDefinitions[i]))
306
+ if (sameRealm && sameParent && sameProviders && signature === state.signature && definitions.length === state.hostDefinitions.length && definitions.every((definition, i) => definition === state.hostDefinitions[i]))
301
307
  return;
308
+ state.signature = undefined;
302
309
  for (const dispose of state.owned.splice(0))
303
310
  dispose();
304
311
  state.restriction?.();
@@ -322,6 +329,7 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
322
329
  state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, admission));
323
330
  policy.captureTools(agent, tools, [...inventory.map(entry => entry.name), ...names], !sameRealm || !sameParent);
324
331
  state.signature = signature;
332
+ state.providers = providers;
325
333
  state.hostDefinitions = definitions;
326
334
  state.parentScope = parentScope;
327
335
  };
@@ -332,7 +340,7 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
332
340
  return;
333
341
  const agentCtx = nativeAgentContext(agent);
334
342
  policy.admit(agent);
335
- states.set(agent, { owned: [], hostDefinitions: [] });
343
+ states.set(agent, { owned: [], hostDefinitions: [], providers: [] });
336
344
  const retire = () => {
337
345
  stopIdentity();
338
346
  const state = states.get(agent);
@@ -348,7 +356,13 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
348
356
  };
349
357
  admission.lifetime.signal.addEventListener("abort", retire, { once: true });
350
358
  agentCtx.effect(() => retire);
351
- reconcile(agent);
359
+ try {
360
+ reconcile(agent);
361
+ }
362
+ catch (error) {
363
+ retire();
364
+ throw error;
365
+ }
352
366
  admittedRealms.set(agent, () => reconcile(agent));
353
367
  };
354
368
  // Native assembly collects sections before its waterfall. Admission/mode/preset
package/lib/roles.d.ts CHANGED
@@ -2,6 +2,8 @@ import type { DsmmSkillName } from "./skills.js";
2
2
  import type { DsmmRoleRouting } from "./settings.js";
3
3
  export declare const DSMM_ROLE_IDS: readonly ["dsmm-orchestrator", "dsmm-planner", "dsmm-plan-critic", "dsmm-builder", "dsmm-reviewer", "dsmm-oracle", "dsmm-oracle-2nd", "dsmm-creative", "dsmm-code-search", "dsmm-doc-search", "dsmm-clarifier", "dsmm-media-reader", "dsmm-frontend", "dsmm-hard-reasoning", "dsmm-research", "dsmm-quick", "dsmm-coding", "dsmm-normal-task", "dsmm-complex", "dsmm-deep", "dsmm-documenting", "dsmm-cross-cutting"];
4
4
  export type DsmmRoleId = (typeof DSMM_ROLE_IDS)[number];
5
+ /** The one user-selectable composition; every other role is an internal delegation target. */
6
+ export declare const DSMM_DISPATCHER_ROLE: DsmmRoleId;
5
7
  export type DsmmRoleMode = "primary" | "all" | "subagent";
6
8
  export type DsmmDelegationGroup = "primary-coordinator" | "utility-leaf" | "read-only-workflow" | "standard-workflow" | "local-coordinator";
7
9
  export interface DsmmRoleDefinition {
package/lib/roles.js CHANGED
@@ -8,6 +8,8 @@ export const DSMM_ROLE_IDS = [
8
8
  "dsmm-coding", "dsmm-normal-task", "dsmm-complex", "dsmm-deep",
9
9
  "dsmm-documenting", "dsmm-cross-cutting"
10
10
  ];
11
+ /** The one user-selectable composition; every other role is an internal delegation target. */
12
+ export const DSMM_DISPATCHER_ROLE = "dsmm-orchestrator";
11
13
  // Generated source catalog is checked against the exact literal ID inventory.
12
14
  // It carries no OCMM provider/model default and requires only package assets.
13
15
  export const DSMM_ROLES = SOURCE_ROLE_CATALOG.map((row) => ({
package/lib/settings.d.ts CHANGED
@@ -36,8 +36,6 @@ export interface DsmmWorkflowSettings {
36
36
  }
37
37
  export interface DsmmPresetSettings {
38
38
  materialize: boolean;
39
- /** Startup-pinned root exposure only; workflow Planner delegation stays enabled. */
40
- plannerRootEnabled: boolean;
41
39
  root?: string;
42
40
  }
43
41
  export interface DsmmSubagentSettings {
@@ -238,7 +236,7 @@ export declare function validateLocale(value: unknown, field?: string): asserts
238
236
  export declare function normalizeLevelOverride(value: unknown, field?: string): DsmmLevelOverride;
239
237
  export declare function resolveRoleRouting(input: DsmmRoleRouting | undefined): DsmmRoleRouting;
240
238
  export declare function isRoleEnabled(settings: DsmmSettings, role: DsmmRoleId): boolean;
241
- /** Native standing-root availability is independent of child role enablement. */
239
+ /** Only the dispatcher is a selectable standing root; every other role stays an internal delegation target. */
242
240
  export declare function isRootRoleEnabled(settings: DsmmSettings, id: DsmmRoleId): boolean;
243
241
  export declare function resolveGuardSettings(config: DsmmPluginConfig["guards"]): DsmmGuardSettings;
244
242
  export declare function registerSettings(ctx: DshContext, config?: DsmmPluginConfig, options?: RegisterSettingsOptions): () => DsmmSettings;
package/lib/settings.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import Schema from "@deepseek-ai/schemastery";
2
2
  import { DEFAULT_DSMM_LSP_SETTINGS, resolveLspSettings } from "./lsp.js";
3
- import { DSMM_ROLES, DSMM_ROLE_IDS, isRootRole } from "./roles.js";
3
+ import { DSMM_DISPATCHER_ROLE, DSMM_ROLES, DSMM_ROLE_IDS } from "./roles.js";
4
4
  import { DSMM_SKILL_NAMES } from "./skills.js";
5
5
  import { DEFAULT_DSMM_RUNTIME_POLICY, DSMM_RATE_LIMIT_BOUNDS, normalizeRateLimitOverrides, normalizeRoutingStrategy, normalizeRuntimePolicy, resolveRoleRuntimePolicy } from "./routing-policy.js";
6
6
  import { DEPRECATED_DSMM_FIELDS, DsmmConfigValidationError, safeDiagnosticField } from "./profile-diagnostics.js";
@@ -23,8 +23,7 @@ export const DEFAULT_DSMM_SETTINGS = {
23
23
  roleRouting: {},
24
24
  runtimePolicy: DEFAULT_DSMM_RUNTIME_POLICY,
25
25
  presets: {
26
- materialize: false,
27
- plannerRootEnabled: false
26
+ materialize: false
28
27
  },
29
28
  subagents: { enableRunInBackground: false, backgroundMode: "one-shot", toolTopology: "per-role", allowRouteOverride: false },
30
29
  workflow: {
@@ -117,7 +116,6 @@ const ROLE_ROUTING_VALIDATION_SCHEMA = Schema.transform(Schema.any(), (input) =>
117
116
  });
118
117
  const PRESETS_SCHEMA = Schema.object({
119
118
  materialize: Schema.boolean().default(DEFAULT_DSMM_SETTINGS.presets.materialize),
120
- plannerRootEnabled: Schema.boolean().default(DEFAULT_DSMM_SETTINGS.presets.plannerRootEnabled),
121
119
  root: Schema.string()
122
120
  });
123
121
  const SUBAGENTS_SCHEMA = Schema.object({
@@ -649,18 +647,15 @@ function normalizeExplicitRoute(value) {
649
647
  export function isRoleEnabled(settings, role) {
650
648
  return settings.roles[role];
651
649
  }
652
- /** Native standing-root availability is independent of child role enablement. */
650
+ /** Only the dispatcher is a selectable standing root; every other role stays an internal delegation target. */
653
651
  export function isRootRoleEnabled(settings, id) {
654
- const role = DSMM_ROLES.find(role => role.id === id);
655
- return settings.modules.deepwork.enabled && settings.roles[id] && isRootRole(role)
656
- && (id !== "dsmm-planner" || settings.presets.plannerRootEnabled);
652
+ return id === DSMM_DISPATCHER_ROLE && settings.modules.deepwork.enabled && settings.roles[id];
657
653
  }
658
654
  function resolvePresetSettings(config) {
659
655
  if (config !== undefined)
660
656
  validateShape(config, PRESETS_SCHEMA, ["presets"]);
661
657
  return {
662
658
  materialize: config?.materialize ?? DEFAULT_DSMM_SETTINGS.presets.materialize,
663
- plannerRootEnabled: config?.plannerRootEnabled ?? DEFAULT_DSMM_SETTINGS.presets.plannerRootEnabled,
664
659
  ...(config?.root === undefined ? {} : { root: config.root })
665
660
  };
666
661
  }
package/lib/skills.d.ts CHANGED
@@ -22,6 +22,7 @@ export interface BundledSkillProviderOptions {
22
22
  agent: DshAgent;
23
23
  controller: DeepworkModeController;
24
24
  getSettings: DsmmSettingsGetter;
25
+ catalogReady?: () => boolean;
25
26
  /** Body I/O seam for deterministic cancellation/race contract tests. */
26
27
  load?: typeof readBundledSkill;
27
28
  }
package/lib/skills.js CHANGED
@@ -96,12 +96,14 @@ export function registerBundledSkills(ctx, skills, options) {
96
96
  async list(lookup) {
97
97
  const signal = signalFor(lookup), current = generation, parent = scopeParentOf(agentScope);
98
98
  signal.throwIfAborted();
99
+ if (options.catalogReady?.() === false)
100
+ return { candidates: [], complete: false };
99
101
  const enabled = names();
100
102
  if (enabled.length === 0)
101
103
  return [];
102
104
  const snapshot = await ancestor(lookup, signal);
103
105
  signal.throwIfAborted();
104
- if (!snapshot.complete || generation !== current || scopeParentOf(agentScope) !== parent)
106
+ if (!snapshot.complete || generation !== current || scopeParentOf(agentScope) !== parent || options.catalogReady?.() === false)
105
107
  return { candidates: [], complete: false };
106
108
  return enabled.filter((name) => !occupied(snapshot, name)).map((name) => ({
107
109
  ...bundledSkillMetadata(name), rank: BUNDLED_SKILL_RANK, locator: { name, parent }
@@ -110,6 +112,8 @@ export function registerBundledSkills(ctx, skills, options) {
110
112
  async get(candidate, lookup) {
111
113
  const signal = signalFor(lookup), current = generation;
112
114
  signal.throwIfAborted();
115
+ if (options.catalogReady?.() === false)
116
+ return undefined;
113
117
  const name = names().find((name) => name === candidate.name);
114
118
  const locator = candidate.locator;
115
119
  if (name === undefined || typeof locator !== "object" || locator === null