@dsmm/dsmm 0.1.1 → 0.1.5

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 (108) hide show
  1. package/README.md +26 -15
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +14 -12
  3. package/agent-presets/dsmm-builder/preset.yml +1 -1
  4. package/agent-presets/dsmm-clarifier/agent.cordis.yml +4 -2
  5. package/agent-presets/dsmm-clarifier/preset.yml +1 -1
  6. package/agent-presets/dsmm-code-search/agent.cordis.yml +4 -2
  7. package/agent-presets/dsmm-code-search/preset.yml +1 -1
  8. package/agent-presets/dsmm-creative/agent.cordis.yml +3 -1
  9. package/agent-presets/dsmm-creative/preset.yml +1 -1
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +4 -2
  11. package/agent-presets/dsmm-doc-search/preset.yml +1 -1
  12. package/agent-presets/dsmm-media-reader/agent.cordis.yml +4 -2
  13. package/agent-presets/dsmm-media-reader/preset.yml +1 -1
  14. package/agent-presets/dsmm-oracle/agent.cordis.yml +3 -1
  15. package/agent-presets/dsmm-oracle/preset.yml +1 -1
  16. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +3 -1
  17. package/agent-presets/dsmm-oracle-2nd/preset.yml +1 -1
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +15 -13
  19. package/agent-presets/dsmm-orchestrator/preset.yml +2 -2
  20. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +4 -2
  21. package/agent-presets/dsmm-plan-critic/preset.yml +1 -1
  22. package/agent-presets/dsmm-planner/agent.cordis.yml +4 -2
  23. package/agent-presets/dsmm-planner/preset.yml +1 -1
  24. package/agent-presets/dsmm-reviewer/agent.cordis.yml +4 -2
  25. package/agent-presets/dsmm-reviewer/preset.yml +1 -1
  26. package/docs/agent-presets.md +15 -5
  27. package/docs/compatibility.md +66 -11
  28. package/docs/migration-from-ocmm.md +8 -0
  29. package/docs/model-routing.md +25 -7
  30. package/docs/profiles.md +95 -0
  31. package/docs/releasing.md +66 -19
  32. package/docs/runtime-recovery.md +39 -14
  33. package/docs/settings-status.md +13 -5
  34. package/lib/client/ProfilesSection.d.ts +11 -0
  35. package/lib/client/ProfilesSection.js +66 -0
  36. package/lib/client/SessionProfiles.d.ts +19 -0
  37. package/lib/client/SessionProfiles.js +24 -0
  38. package/lib/client/StructuredEditor.d.ts +11 -0
  39. package/lib/client/StructuredEditor.js +74 -0
  40. package/lib/client/controller.d.ts +115 -0
  41. package/lib/client/controller.js +340 -0
  42. package/lib/client/index.d.ts +13 -0
  43. package/lib/client/index.js +54 -0
  44. package/lib/client/locales.d.ts +145 -0
  45. package/lib/client/locales.js +91 -0
  46. package/lib/client/session-labels.d.ts +8 -0
  47. package/lib/client/session-labels.js +13 -0
  48. package/lib/client/structured.d.ts +18 -0
  49. package/lib/client/structured.js +98 -0
  50. package/lib/client/styles.d.ts +3 -0
  51. package/lib/client/styles.js +36 -0
  52. package/lib/client.js +2825 -0
  53. package/lib/commands.d.ts +3 -3
  54. package/lib/commands.js +5 -4
  55. package/lib/dsh-types.d.ts +20 -0
  56. package/lib/guards.d.ts +2 -2
  57. package/lib/guards.js +3 -2
  58. package/lib/index.d.ts +12 -4
  59. package/lib/index.js +98 -20
  60. package/lib/mode.d.ts +2 -2
  61. package/lib/mode.js +1 -1
  62. package/lib/model-routing.d.ts +2 -2
  63. package/lib/model-routing.js +100 -15
  64. package/lib/preset-registry.js +5 -3
  65. package/lib/profile-remote.d.ts +37 -0
  66. package/lib/profile-remote.js +219 -0
  67. package/lib/profile-rpc.d.ts +35 -0
  68. package/lib/profile-rpc.js +187 -0
  69. package/lib/profile-runtime.d.ts +63 -0
  70. package/lib/profile-runtime.js +310 -0
  71. package/lib/profile-store.d.ts +60 -0
  72. package/lib/profile-store.js +588 -0
  73. package/lib/profile-types.d.ts +80 -0
  74. package/lib/profile-types.js +2 -0
  75. package/lib/profiles.d.ts +26 -0
  76. package/lib/profiles.js +269 -0
  77. package/lib/prompts.d.ts +2 -2
  78. package/lib/prompts.js +4 -4
  79. package/lib/role-providers.d.ts +2 -2
  80. package/lib/role-providers.js +49 -6
  81. package/lib/role-routing.d.ts +37 -3
  82. package/lib/role-routing.js +110 -35
  83. package/lib/role-subagents.d.ts +2 -2
  84. package/lib/role-subagents.js +6 -4
  85. package/lib/roles.d.ts +4 -0
  86. package/lib/roles.js +43 -27
  87. package/lib/routing-policy.d.ts +32 -0
  88. package/lib/routing-policy.js +92 -0
  89. package/lib/runtime-recovery.d.ts +2 -2
  90. package/lib/runtime-recovery.js +215 -54
  91. package/lib/session-metadata.d.ts +13 -0
  92. package/lib/session-metadata.js +34 -0
  93. package/lib/session-persistence.d.ts +35 -0
  94. package/lib/session-persistence.js +304 -0
  95. package/lib/settings.d.ts +34 -1
  96. package/lib/settings.js +33 -7
  97. package/lib/state.d.ts +1 -0
  98. package/lib/state.js +4 -0
  99. package/lib/status.d.ts +9 -1
  100. package/lib/status.js +34 -12
  101. package/locale/en.json +6 -0
  102. package/locale/zh.json +6 -0
  103. package/package.json +66 -15
  104. package/patches/agent-presets-root.example.cordis.patch.yml +6 -10
  105. package/prompts/deepseek-v4-pro.md +1 -1
  106. package/prompts/deepwork.md +3 -3
  107. package/scripts/repair-session-log.mjs +476 -0
  108. package/scripts/session-repair-native-verifier.mjs +367 -0
package/lib/commands.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { DshContext } from "./dsh-types.js";
2
2
  import { DSMM_STATUS_COMMAND } from "./settings.js";
3
- import type { DsmmSettings } from "./settings.js";
3
+ import type { DsmmSettingsGetter } from "./settings.js";
4
4
  import type { DeepworkModeController } from "./state.js";
5
5
  export { DSMM_STATUS_COMMAND };
6
6
  export interface DeepworkCommandInput {
@@ -8,6 +8,6 @@ export interface DeepworkCommandInput {
8
8
  message: string;
9
9
  }
10
10
  export declare function parseDeepworkCommandInput(rawInput: string): DeepworkCommandInput;
11
- export declare function registerDeepworkCommand(readyCtx: DshContext, controller: DeepworkModeController, getSettings: () => DsmmSettings): void;
12
- export declare function registerDsmmStatusCommand(readyCtx: DshContext, controller: DeepworkModeController, getSettings: () => DsmmSettings): void;
11
+ export declare function registerDeepworkCommand(readyCtx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter): void;
12
+ export declare function registerDsmmStatusCommand(readyCtx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter): void;
13
13
  //# sourceMappingURL=commands.d.ts.map
package/lib/commands.js CHANGED
@@ -8,7 +8,7 @@ export function parseDeepworkCommandInput(rawInput) {
8
8
  }
9
9
  async function handleDeepworkCommand(controller, getSettings, invocation) {
10
10
  const parsed = parseDeepworkCommandInput(invocation.rawInput);
11
- await controller.select(invocation.agent, parsed.action === "on", getSettings().defaultActive);
11
+ await controller.select(invocation.agent, parsed.action === "on", getSettings(invocation.agent).defaultActive);
12
12
  if (parsed.action === "on" && parsed.message !== "") {
13
13
  await invocation.agent.steer?.(createUserMessage({
14
14
  content: [{ type: "text", text: parsed.message }],
@@ -23,10 +23,11 @@ function handleDsmmStatusCommand(controller, getSettings, invocation) {
23
23
  const input = invocation.rawInput.trim();
24
24
  if (input !== "" && input !== "json")
25
25
  return { kind: "error", text: "Usage: /dsmm-status [json]" };
26
- const settings = getSettings();
26
+ const settings = getSettings(invocation.agent);
27
27
  const snapshot = createDsmmStatusSnapshot({
28
28
  agent: invocation.agent,
29
29
  settings,
30
+ admission: getSettings.admission?.(invocation.agent),
30
31
  modeActive: controller.active(invocation.agent, settings.defaultActive)
31
32
  });
32
33
  return {
@@ -38,7 +39,7 @@ export function registerDeepworkCommand(readyCtx, controller, getSettings) {
38
39
  const commands = readyCtx.get?.("commands") ?? readyCtx.commands;
39
40
  commands?.register({
40
41
  name: getSettings().modeName,
41
- description: "Enter or leave dsmm deepwork mode",
42
+ description: "Enter or leave Deepwork mode",
42
43
  input: { hint: "[off|message]" },
43
44
  handler: (invocation) => handleDeepworkCommand(controller, getSettings, invocation)
44
45
  });
@@ -47,7 +48,7 @@ export function registerDsmmStatusCommand(readyCtx, controller, getSettings) {
47
48
  const commands = readyCtx.get?.("commands") ?? readyCtx.commands;
48
49
  commands?.register({
49
50
  name: DSMM_STATUS_COMMAND,
50
- description: "Show DSMM status",
51
+ description: "Show Deepwork status",
51
52
  input: { hint: "[json]" },
52
53
  handler: (invocation) => handleDsmmStatusCommand(controller, getSettings, invocation)
53
54
  });
@@ -18,6 +18,7 @@ export interface DshSessionHeader {
18
18
  origin?: string;
19
19
  }
20
20
  export interface DshSession {
21
+ readonly id?: string;
21
22
  inheritedEventCount?: number;
22
23
  events?: readonly DshSessionEvent[];
23
24
  snapshotEvents?(): readonly DshSessionEvent[];
@@ -29,7 +30,12 @@ export interface DshSession {
29
30
  append(type: "dsmm/role-policy", payload: import("./dsh-events.js").DsmmRolePolicyEventData): unknown | Promise<unknown>;
30
31
  }
31
32
  export interface DshAgent {
33
+ id?: string;
34
+ ctx?: DshContext;
32
35
  session: DshSession;
36
+ readonly status?: "idle" | "running";
37
+ /** Public native reservation: throws synchronously unless truly idle. */
38
+ runMaintenance?<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>;
33
39
  options?: {
34
40
  provider?: string;
35
41
  model?: string;
@@ -38,6 +44,17 @@ export interface DshAgent {
38
44
  steer?(message: unknown): unknown | Promise<unknown>;
39
45
  inject?(message: unknown): unknown | Promise<unknown>;
40
46
  }
47
+ export interface DshAgentsRegistry {
48
+ get(id: string): DshAgent | undefined;
49
+ list(): DshAgent[];
50
+ roots(): DshAgent[];
51
+ isOwnedBy(id: string, owner: DshAgent): boolean;
52
+ }
53
+ export interface DshAgentCreatedFrame {
54
+ agent: DshAgent;
55
+ source: "startup" | "resume" | "clear" | "compact";
56
+ signal?: AbortSignal;
57
+ }
41
58
  export interface DshLlmCallConfig {
42
59
  provider: string;
43
60
  model: string;
@@ -77,6 +94,7 @@ export interface DshResolvedModelInfo {
77
94
  }
78
95
  export interface DshLlmRuntime {
79
96
  resolveModelInfo(provider: string, model: string, signal?: AbortSignal): Promise<DshResolvedModelInfo>;
97
+ resolveCallConfig?(config: DshLlmCallConfig, signal?: AbortSignal): Promise<DshLlmCallConfig>;
80
98
  }
81
99
  export interface AgentRequestFrame {
82
100
  agent: DshAgent;
@@ -280,6 +298,7 @@ export interface PreStepDecision {
280
298
  [key: string]: unknown;
281
299
  }
282
300
  export interface DshContext {
301
+ agents?: DshAgentsRegistry;
283
302
  subagents?: import("./role-providers.js").DsmmSubagentRegistry;
284
303
  settings?: DshSettingsRegistry;
285
304
  systemPrompt?: DshSystemPromptRegistry;
@@ -288,6 +307,7 @@ export interface DshContext {
288
307
  tools?: DshToolRuntime;
289
308
  llm?: DshLlmRuntime;
290
309
  get?<T = unknown>(name: string): T | undefined;
310
+ provide?(name: string, service: unknown): unknown;
291
311
  plugin?(plugin: unknown, config?: unknown): PromiseLike<unknown>;
292
312
  inject?(dependencies: string[], installer: (readyCtx: DshContext) => unknown): unknown;
293
313
  effect?(callback: () => void | (() => void)): unknown;
package/lib/guards.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import type { DshContext, DshPostToolDecision, DshPreToolDecision, DshToolExecution, DshToolExecutionResult } from "./dsh-types.js";
2
- import type { DsmmSettings } from "./settings.js";
2
+ import type { DsmmSettings, DsmmSettingsGetter } from "./settings.js";
3
3
  import type { DeepworkModeController } from "./state.js";
4
4
  export declare const DSMM_GUARD_PREFIX = "[dsmm safety]";
5
5
  export declare function truncateTextMiddle(text: string, maxBytes: number, toolName: string): string;
6
6
  export declare function isSafetyScopeActive(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): boolean;
7
7
  export declare function decidePreToolExecution(exec: DshToolExecution, settings: DsmmSettings, controller: DeepworkModeController): DshPreToolDecision | undefined;
8
8
  export declare function decidePostToolExecution(exec: DshToolExecution, result: Readonly<DshToolExecutionResult>, decision: DshPostToolDecision, settings: DsmmSettings, controller: DeepworkModeController): DshPostToolDecision;
9
- export declare function registerSafetyGuards(ctx: DshContext, controller: DeepworkModeController, getSettings: () => DsmmSettings): void;
9
+ export declare function registerSafetyGuards(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter): void;
10
10
  //# sourceMappingURL=guards.d.ts.map
package/lib/guards.js CHANGED
@@ -236,7 +236,7 @@ export function decidePostToolExecution(exec, result, decision, settings, contro
236
236
  }
237
237
  export function registerSafetyGuards(ctx, controller, getSettings) {
238
238
  ctx.on?.("tools/pre-execute", async (exec, next) => {
239
- const decision = decidePreToolExecution(exec, getSettings(), controller);
239
+ const decision = decidePreToolExecution(exec, getSettings(exec.agent), controller);
240
240
  if (decision === undefined)
241
241
  return next();
242
242
  if (decision.kind === "deny")
@@ -245,8 +245,9 @@ export function registerSafetyGuards(ctx, controller, getSettings) {
245
245
  return downstream.kind === "allow" ? decision : downstream;
246
246
  }, { prepend: true });
247
247
  ctx.on?.("tools/post-execute", async (exec, result, next) => {
248
+ const settings = getSettings(exec.agent);
248
249
  const decision = await next();
249
- return decidePostToolExecution(exec, result, decision, getSettings(), controller);
250
+ return decidePostToolExecution(exec, result, decision, settings, controller);
250
251
  }, { prepend: true });
251
252
  }
252
253
  //# sourceMappingURL=guards.js.map
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { DshContext } from "./dsh-types.js";
2
2
  import type { DsmmPluginConfig } from "./settings.js";
3
3
  export declare const name = "dsmm";
4
- export declare const inject: readonly [];
4
+ export declare const inject: readonly ["profileContext"];
5
5
  export type Config = DsmmPluginConfig;
6
6
  export declare const Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
7
7
  export type { DeepworkSessionEventMap } from "./dsh-events.js";
@@ -26,8 +26,16 @@ export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from
26
26
  export type { DsmmStatusSnapshot } from "./status.js";
27
27
  export type { AgentRequestErrorFrame, AgentRequestFrame, AgentTurnStoppingFrame, DshEpochHeader, DshGoalChangeEventData, DshGoalSnapshot, DshLlmCallConfig, DshLlmFailure, DshModelReasoningInfo, DshReasoningEffortInfo, DshRequestErrorAction, DshRequestHeaderEventData, DshResolvedModelInfo, DshStepBoundaryEventData, DshTodoItem, DshTodoWriteEventData } from "./dsh-types.js";
28
28
  export { DSMM_SKILL_NAMES, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, isRoleEnabled, resolveConfig, resolveRoleRouting, registerSettings } from "./settings.js";
29
- export type { DeepseekCalibration, DeepseekDefaultReasoningEffort, DsmmFinalReviewPolicy, DsmmGitWritePolicy, DsmmGuardScope, DsmmGuardSettings, DsmmPluginConfig, DsmmModelRoute, DsmmRoleRoutingConfig, DsmmRoleRouting, DsmmRecoveryRoute, DsmmRuntimeRecoverySettings, DsmmSettings, DsmmSkillName, DsmmWorkflowSettings, MvpSkillName } from "./settings.js";
29
+ export type { DeepseekCalibration, DeepseekDefaultReasoningEffort, DsmmFinalReviewPolicy, DsmmGitWritePolicy, DsmmGuardScope, DsmmGuardSettings, DsmmPluginConfig, DsmmModelRoute, DsmmRoleRoutingConfig, DsmmRoleRouting, DsmmRecoveryRoute, DsmmRuntimeRecoverySettings, DsmmSettings, DsmmSettingsGetter, DsmmSkillName, DsmmWorkflowSettings, MvpSkillName } from "./settings.js";
30
+ export { createProfileRuntime, DsmmProfileRuntime } from "./profile-runtime.js";
31
+ export type { DsmmProfileRuntimeStore, DsmmProfileRuntimeOptions } from "./profile-runtime.js";
30
32
  export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
31
- export declare function apply(ctx: DshContext, config?: Config): void;
32
- export default apply;
33
+ export declare function apply(ctx: DshContext, config?: Config): void | Promise<void>;
34
+ declare const _default: {
35
+ name: string;
36
+ inject: readonly ["profileContext"];
37
+ Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
38
+ apply: typeof apply;
39
+ };
40
+ export default _default;
33
41
  //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -7,10 +7,16 @@ import { reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materia
7
7
  import { registerHeadlessRoleTools } from "./role-subagents.js";
8
8
  import { registerRolePresets } from "./preset-registry.js";
9
9
  import { registerRoleProviders } from "./role-providers.js";
10
+ import { createProfileRuntime } from "./profile-runtime.js";
11
+ import { registerProfilesRpc } from "./profile-rpc.js";
10
12
  import { DSMM_CONFIG_SCHEMA, registerSettings } from "./settings.js";
11
13
  import { DeepworkModeController } from "./state.js";
14
+ import DsmmSessionPersistence from "./session-persistence.js";
15
+ import { isAbsolute } from "node:path";
16
+ import { createHash, randomUUID } from "node:crypto";
17
+ import { DsmmProfileError } from "./profiles.js";
12
18
  export const name = "dsmm";
13
- export const inject = [];
19
+ export const inject = ["profileContext"];
14
20
  export const Config = DSMM_CONFIG_SCHEMA;
15
21
  export { DSMM_ROLE_IDS, DSMM_ROLES, isDsmmRoleId, renderAgentCordis, renderPresetMetadata } from "./roles.js";
16
22
  export { DSMM_MANAGED_PRESET_MARKER, materializeRolePresets, reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
@@ -26,33 +32,105 @@ export { effectiveRoleFallbackRoutes } from "./role-routing.js";
26
32
  export { DSMM_STATUS_COMMAND, registerDsmmStatusCommand } from "./commands.js";
27
33
  export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from "./status.js";
28
34
  export { DSMM_SKILL_NAMES, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, isRoleEnabled, resolveConfig, resolveRoleRouting, registerSettings } from "./settings.js";
35
+ export { createProfileRuntime, DsmmProfileRuntime } from "./profile-runtime.js";
29
36
  export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
30
37
  export function apply(ctx, config = {}) {
38
+ const storage = config.sessionPersistence;
39
+ if (storage !== undefined) {
40
+ if (storage === null || typeof storage !== "object" || typeof storage.root !== "string" || !isAbsolute(storage.root)
41
+ || Object.keys(storage).some((key) => !["root", "compression"].includes(key))
42
+ || storage.compression !== undefined && !["zstd", "none"].includes(storage.compression)) {
43
+ throw new Error("Deepwork sessionPersistence must preserve an explicit absolute native root and compression");
44
+ }
45
+ if (ctx.get === undefined || ctx.plugin === undefined)
46
+ throw new Error("Deepwork sessionPersistence requires native startup composition");
47
+ if (ctx.get("sessionPersistence") !== undefined)
48
+ throw new Error("Disable the exact existing JSONL entry at startup before enabling Deepwork sessionPersistence; live replacement is refused");
49
+ const fiber = ctx.plugin(DsmmSessionPersistence, storage);
50
+ if (fiber === undefined)
51
+ throw new Error("Deepwork sessionPersistence startup registration failed");
52
+ return fiber.await().then(() => applyRuntime(ctx, config));
53
+ }
54
+ return applyRuntime(ctx, config);
55
+ }
56
+ function applyRuntime(ctx, config) {
31
57
  const controller = new DeepworkModeController(ctx);
58
+ let runtime;
59
+ let profileInitialization;
60
+ let requiresNativeProfiles = ctx.get !== undefined;
61
+ const requireProfileAdmission = () => {
62
+ if (requiresNativeProfiles && runtime === undefined) {
63
+ throw new DsmmProfileError("unavailable", "Native Deepwork profile admission is not ready. No provider request or tool work is allowed.");
64
+ }
65
+ };
66
+ const getBoundSettings = (agent) => {
67
+ requireProfileAdmission();
68
+ return runtime?.getSettings(agent) ?? getSettings();
69
+ };
70
+ const deploymentAdmissions = new WeakMap();
71
+ getBoundSettings.admission = (agent) => {
72
+ requireProfileAdmission();
73
+ const nativeAdmission = runtime?.getSettings.admission?.(agent);
74
+ if (nativeAdmission !== undefined)
75
+ return nativeAdmission;
76
+ const settings = getSettings();
77
+ let admission = deploymentAdmissions.get(settings);
78
+ if (admission === undefined) {
79
+ admission = Object.freeze({ settings, profile: null, scope: "deployment-baseline", epoch: createHash("sha256").update(randomUUID()).digest("hex") });
80
+ deploymentAdmissions.set(settings, admission);
81
+ }
82
+ return admission;
83
+ };
32
84
  const getSettings = registerSettings(ctx, config, {
33
85
  install(readyCtx, getReadySettings) {
34
- registerDeepworkPrompt(readyCtx, controller, getReadySettings, config);
35
- const installCommands = (commandCtx) => {
36
- registerDeepworkCommand(commandCtx, controller, getReadySettings);
37
- registerDsmmStatusCommand(commandCtx, controller, getReadySettings);
86
+ const install = (installCtx, settingsGetter) => {
87
+ registerDeepworkPrompt(installCtx, controller, settingsGetter, config);
88
+ const installCommands = (commandCtx) => {
89
+ registerDeepworkCommand(commandCtx, controller, settingsGetter);
90
+ registerDsmmStatusCommand(commandCtx, controller, settingsGetter);
91
+ };
92
+ if (installCtx.get !== undefined && installCtx.inject !== undefined)
93
+ installCtx.inject(["commands"], installCommands);
94
+ else
95
+ installCommands(installCtx);
96
+ registerRoleProviders(installCtx, settingsGetter, getReadySettings);
97
+ // Standing compositions are deployment-only and never replaced on a
98
+ // runtime profile selection. All routes are read from Agent bindings.
99
+ registerRolePresets(installCtx, getReadySettings);
100
+ const settings = getReadySettings();
101
+ const root = resolveManagedPresetRoot(settings);
102
+ if (root !== undefined)
103
+ reconcileRolePresets({ root, settings });
38
104
  };
39
- if (readyCtx.get !== undefined && readyCtx.inject !== undefined)
40
- readyCtx.inject(["commands"], installCommands);
41
- else
42
- installCommands(readyCtx);
43
- registerRoleProviders(readyCtx, getReadySettings);
44
- registerRolePresets(readyCtx, getReadySettings);
45
- const settings = getReadySettings();
46
- const root = resolveManagedPresetRoot(settings);
47
- if (root === undefined)
105
+ if (readyCtx.get === undefined) {
106
+ install(readyCtx, getReadySettings);
48
107
  return;
49
- reconcileRolePresets({ root, settings });
108
+ }
109
+ requiresNativeProfiles = true;
110
+ const installProfiles = async (profileCtx) => {
111
+ runtime = await createProfileRuntime(profileCtx, getReadySettings());
112
+ profileCtx.provide?.("dsmmProfileRuntime", runtime);
113
+ const manager = runtime;
114
+ profileCtx.inject?.(["typert"], (rpcCtx) => {
115
+ registerProfilesRpc(rpcCtx, manager);
116
+ });
117
+ install(profileCtx, runtime.getSettings);
118
+ };
119
+ if (readyCtx.inject !== undefined) {
120
+ const initialization = readyCtx.inject(["profileContext"], installProfiles);
121
+ profileInitialization = Promise.resolve(initialization).then(() => undefined);
122
+ }
123
+ else
124
+ throw new Error("dsmm native profiles require asynchronous profileContext injection");
50
125
  }
51
126
  });
52
- registerRuntimeRecovery(ctx, controller, getSettings);
53
- registerModelRouting(ctx, controller, getSettings);
54
- registerHeadlessRoleTools(ctx, controller, getSettings);
55
- registerSafetyGuards(ctx, controller, getSettings);
127
+ registerRuntimeRecovery(ctx, controller, getBoundSettings);
128
+ registerModelRouting(ctx, controller, getBoundSettings);
129
+ registerHeadlessRoleTools(ctx, controller, getBoundSettings);
130
+ registerSafetyGuards(ctx, controller, getBoundSettings);
131
+ return profileInitialization;
56
132
  }
57
- export default apply;
133
+ // Cordis Loader introspects this object's Config/inject; a bare function loses
134
+ // the exported schema and may pass null where required DSMM defaults belong.
135
+ export default { name, inject, Config, apply };
58
136
  //# sourceMappingURL=index.js.map
package/lib/mode.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { DshContext } from "./dsh-types.js";
2
2
  import type { Config } from "./index.js";
3
- import type { DsmmSettings } from "./settings.js";
3
+ import type { DsmmSettingsGetter } from "./settings.js";
4
4
  import type { DeepworkModeController } from "./state.js";
5
- export declare function registerDeepworkPrompt(readyCtx: DshContext, controller: DeepworkModeController, getSettings: () => DsmmSettings, config?: Config): void;
5
+ export declare function registerDeepworkPrompt(readyCtx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, config?: Config): void;
6
6
  //# sourceMappingURL=mode.d.ts.map
package/lib/mode.js CHANGED
@@ -14,7 +14,7 @@ export function registerDeepworkPrompt(readyCtx, controller, getSettings, config
14
14
  order: getSettings().promptOrder,
15
15
  interpolate: false,
16
16
  text(context) {
17
- const settings = getSettings();
17
+ const settings = getSettings(context.agent);
18
18
  const preset = resolveSelectedAgentPreset(context.agent?.session);
19
19
  const active = controller.active(context.agent, settings.defaultActive);
20
20
  if (!active && !isDsmmRoleId(preset))
@@ -1,5 +1,5 @@
1
1
  import type { DshContext, DshLlmCallConfig, DshModelReasoningInfo } from "./dsh-types.js";
2
- import type { DeepseekDefaultReasoningEffort, DsmmSettings } from "./settings.js";
2
+ import type { DeepseekDefaultReasoningEffort, DsmmSettings, DsmmSettingsGetter } from "./settings.js";
3
3
  import type { DeepworkModeController } from "./state.js";
4
4
  export type DeepseekReasoningEffort = DeepseekDefaultReasoningEffort | "max";
5
5
  export type DeepseekModelRoute = "v4-pro" | "flash";
@@ -7,5 +7,5 @@ export declare function isDeepseekV4ProRoute(config: Pick<DshLlmCallConfig, "pro
7
7
  export declare function isDeepseekFlashRoute(config: Pick<DshLlmCallConfig, "provider" | "model">): boolean;
8
8
  export declare function desiredDeepseekEffort(settings: DsmmSettings, preset?: string, route?: DeepseekModelRoute): DeepseekReasoningEffort;
9
9
  export declare function selectAdvertisedEffort(desired: DeepseekReasoningEffort, reasoning: DshModelReasoningInfo | undefined): string | undefined;
10
- export declare function registerModelRouting(ctx: DshContext, controller: DeepworkModeController, getSettings: () => DsmmSettings): void;
10
+ export declare function registerModelRouting(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter): void;
11
11
  //# sourceMappingURL=model-routing.d.ts.map
@@ -1,6 +1,8 @@
1
1
  import { isDsmmRoleId } from "./roles.js";
2
- import { applyModelRoute, effectiveRoleFallbackRoutes, establishRolePolicy, persistedRoleRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
2
+ import { applyModelRoute, clearRoleRouteLock, effectiveRoleFallbackRoutes, establishRolePolicy, latestNativeModelSelection, nativeModelSelectionWasAccepted, orderedModelRoutes, persistedRoleRoute, pinRoleRoute, roleRouteLock, selectInitialModelRoute, sameExactModelRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
3
3
  import { resolveEffectiveDsmmRole, resolveSelectedAgentPreset } from "./session-scope.js";
4
+ import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
5
+ import { isCurrentRecoveryStep } from "./recovery-policy.js";
4
6
  export function isDeepseekV4ProRoute(config) {
5
7
  return config.provider.toLowerCase() === "deepseek-official" && config.model.toLowerCase() === "deepseek-v4-pro";
6
8
  }
@@ -28,36 +30,99 @@ export function selectAdvertisedEffort(desired, reasoning) {
28
30
  }
29
31
  return advertised.has(desired) ? desired : fallback;
30
32
  }
33
+ function hasLiveRuntimeOwner(ctx, agent) {
34
+ const agents = ctx.get?.("agents");
35
+ return agent.id !== undefined && agents !== undefined
36
+ && agents.list().some((parent) => parent !== agent && agents.isOwnedBy(agent.id, parent));
37
+ }
31
38
  export function registerModelRouting(ctx, controller, getSettings) {
32
39
  const installedContexts = new WeakSet();
33
40
  const install = (readyCtx) => {
34
41
  if (installedContexts.has(readyCtx) || readyCtx.on === undefined)
35
42
  return;
36
43
  installedContexts.add(readyCtx);
44
+ const lockedAgents = new Set();
45
+ const assembledSelections = new WeakMap();
37
46
  let dispose;
47
+ let disposeAgent;
48
+ let disposeAssembly;
38
49
  try {
50
+ disposeAssembly = readyCtx.on("system-prompt/assemble", async (_assembly, context, next) => {
51
+ if (context.agent !== undefined && context.signal !== undefined) {
52
+ assembledSelections.set(context.agent, { signal: context.signal, intent: latestNativeModelSelection(context.agent) });
53
+ }
54
+ return next();
55
+ }, { prepend: true });
39
56
  dispose = readyCtx.on("agent/request", async (frame, next) => {
40
57
  let downstream = await next();
41
- const settings = getSettings();
58
+ if (frame.signal.aborted)
59
+ return downstream;
60
+ const settings = getSettings(frame.agent);
42
61
  const admitted = takeAdmittedRecoveryRoute(frame);
43
62
  const active = controller.active(frame.agent, settings.defaultActive);
44
63
  const role = resolveEffectiveDsmmRole(frame.agent, settings, active);
45
64
  const policy = role === undefined ? undefined : settings.roleRouting[role];
46
65
  const primary = policy?.primary;
47
- const identity = await establishRolePolicy(frame, settings, role);
48
- if (admitted !== undefined) {
49
- downstream = applyModelRoute(downstream, admitted);
50
- if (admitted.reasoningEffort !== undefined || primary !== undefined
51
- || (role !== undefined && settings.roleRouting[role]?.fallbackRoutes !== undefined))
52
- return downstream;
53
- }
66
+ const epoch = getSettings.admission?.(frame.agent).epoch;
67
+ const identity = await establishRolePolicy(frame, settings, role, readyCtx, epoch);
54
68
  const fallbacks = effectiveRoleFallbackRoutes(settings, role);
55
- if (primary !== undefined)
56
- return applyModelRoute(downstream, persistedRoleRoute(frame, primary, fallbacks, identity) ?? primary);
57
- if (settings.runtimeRecovery.enabled && policy?.fallbackRoutes !== undefined) {
58
- const accepted = persistedRoleRoute(frame, undefined, fallbacks, identity);
59
- if (accepted !== undefined)
60
- return applyModelRoute(downstream, accepted);
69
+ const liveAlias = primary !== undefined && role !== undefined && frame.agent.session.header?.origin === "subagent"
70
+ && (frame.agent.session.inheritedEventCount ?? 0) === 0
71
+ && hasLiveRuntimeOwner(readyCtx, frame.agent);
72
+ const currentStep = isCurrentRecoveryStep(frame.agent.session.header?.origin === "subagent" ? childOwnedSessionEvents(frame.agent.session) : sessionEvents(frame.agent.session), frame.turn, frame.step);
73
+ if (role !== undefined && identity !== undefined && currentStep) {
74
+ let lock = roleRouteLock(frame.agent, identity);
75
+ const exactPolicy = primary !== undefined || policy?.fallbackRoutes !== undefined || fallbacks.length > 0;
76
+ const captured = assembledSelections.get(frame.agent);
77
+ const manual = captured?.signal === frame.signal ? captured.intent : undefined;
78
+ if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
79
+ && (sameExactModelRoute(downstream, manual.route) || nativeModelSelectionWasAccepted(frame.agent, manual))) {
80
+ const llm = frame.agent.ctx?.get?.("llm")
81
+ ?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
82
+ if (llm?.resolveCallConfig === undefined)
83
+ throw new Error("dsmm explicit model selection requires the native LLM service");
84
+ await llm.resolveCallConfig(applyModelRoute(downstream, manual.route), frame.signal);
85
+ frame.signal.throwIfAborted();
86
+ const generation = (lock?.generation ?? -1) + 1;
87
+ lock = pinRoleRoute(frame.agent, identity, manual.route, [manual.route, ...fallbacks]);
88
+ lock.manualSelectionSeq = manual.seq;
89
+ lock.generation = generation;
90
+ lockedAgents.add(frame.agent);
91
+ }
92
+ if (lock?.manualSelectionSeq !== undefined) {
93
+ // An unchanged explicit intent must not undo a policy-authorized
94
+ // fallback; a fresh native selection event re-admits above.
95
+ return applyModelRoute(downstream, lock.route);
96
+ }
97
+ if (admitted !== undefined)
98
+ return applyModelRoute(downstream, admitted);
99
+ const accepted = persistedRoleRoute(frame, liveAlias ? undefined : primary, fallbacks, identity);
100
+ if (lock !== undefined && accepted !== undefined && !sameModelRoute(accepted, lock.route)) {
101
+ // An explicit already-committed native route change remains host-owned;
102
+ // DSMM's pending current-frame route still has precedence above.
103
+ lock.route = { ...accepted };
104
+ lock.generation += 1;
105
+ lock.startupSettled = true;
106
+ lock.retries = 0;
107
+ lock.rateLimits = 0;
108
+ }
109
+ if (lock === undefined) {
110
+ const inherited = { provider: downstream.provider, model: downstream.model,
111
+ ...(downstream.reasoningEffort === undefined ? {} : { reasoningEffort: downstream.reasoningEffort }) };
112
+ const candidates = orderedModelRoutes([liveAlias ? inherited : primary ?? inherited, ...fallbacks]);
113
+ const persisted = accepted;
114
+ const llm = frame.agent.ctx?.get?.("llm")
115
+ ?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
116
+ const selected = persisted ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal) : inherited);
117
+ frame.signal.throwIfAborted();
118
+ lock = pinRoleRoute(frame.agent, identity, selected, candidates);
119
+ if (persisted !== undefined)
120
+ lock.startupSettled = true;
121
+ lockedAgents.add(frame.agent);
122
+ }
123
+ downstream = applyModelRoute(downstream, lock.route);
124
+ if (exactPolicy || lock.attempts > 0)
125
+ return downstream;
61
126
  }
62
127
  // Named fallback efforts are native policy IDs, never legacy calibration inputs.
63
128
  if (fallbacks.some((fallback) => fallback.reasoningEffort !== undefined
@@ -92,15 +157,35 @@ export function registerModelRouting(ctx, controller, getSettings) {
92
157
  warnUnavailable(readyCtx, ctx, desired, `${downstream.provider}/${downstream.model}`);
93
158
  return downstream;
94
159
  }
160
+ if (identity !== undefined) {
161
+ const lock = roleRouteLock(frame.agent, identity);
162
+ if (lock !== undefined)
163
+ lock.route = { ...lock.route, reasoningEffort: selected };
164
+ }
95
165
  return { ...downstream, reasoningEffort: selected };
96
166
  }, { prepend: true });
167
+ disposeAgent = readyCtx.on("agent/disposed", ({ agent }) => {
168
+ lockedAgents.delete(agent);
169
+ clearRoleRouteLock(agent);
170
+ }, { global: true });
97
171
  }
98
172
  catch (error) {
99
173
  installedContexts.delete(readyCtx);
174
+ if (typeof dispose === "function")
175
+ dispose();
176
+ if (typeof disposeAssembly === "function")
177
+ disposeAssembly();
100
178
  throw error;
101
179
  }
102
180
  readyCtx.effect?.(() => () => {
181
+ for (const agent of lockedAgents)
182
+ clearRoleRouteLock(agent);
183
+ lockedAgents.clear();
103
184
  installedContexts.delete(readyCtx);
185
+ if (typeof disposeAgent === "function")
186
+ disposeAgent();
187
+ if (typeof disposeAssembly === "function")
188
+ disposeAssembly();
104
189
  if (typeof dispose === "function")
105
190
  dispose();
106
191
  });
@@ -1,5 +1,5 @@
1
1
  import { getTraceable } from "@deepseek-ai/cordis";
2
- import { DSMM_ROLES, DSMM_ROLE_IDS, rolePluginRows } from "./roles.js";
2
+ import { DSMM_ROLES, DSMM_ROLE_IDS, isRootRole, rolePluginRows } from "./roles.js";
3
3
  import { enabledSkillNames } from "./skills.js";
4
4
  /** Declare roles to DSH 0.2's native registry; directories are not discovery inputs. */
5
5
  export function registerRolePresets(ctx, getSettings) {
@@ -10,7 +10,7 @@ export function registerRolePresets(ctx, getSettings) {
10
10
  throw new Error("dsmm requires the native DSH agentPresets registry");
11
11
  const settings = getSettings();
12
12
  const enabled = DSMM_ROLE_IDS.filter((id) => settings.roles[id]);
13
- const active = DSMM_ROLES.filter((role) => enabled.includes(role.id));
13
+ const active = DSMM_ROLES.filter((role) => isRootRole(role) && enabled.includes(role.id));
14
14
  const disposers = [];
15
15
  try {
16
16
  for (const role of active) {
@@ -19,7 +19,9 @@ export function registerRolePresets(ctx, getSettings) {
19
19
  name: role.name,
20
20
  description: role.description,
21
21
  order: role.order,
22
- plugins: rolePluginRows(role, enabledSkillNames(settings), enabled, settings.roleRouting)
22
+ // Profiles do not replace standing native compositions. Child routes
23
+ // are admitted by the role provider from the parent's fixed snapshot.
24
+ plugins: rolePluginRows(role, enabledSkillNames(settings), enabled)
23
25
  }));
24
26
  }
25
27
  // A direct selection of a read-only preset must be restricted at the Agent
@@ -0,0 +1,37 @@
1
+ import type { RemoteResult, TypertRemoteContribution } from "@deepseek-ai/dsh-typert-protocol";
2
+ import type { TypertContribution } from "@deepseek-ai/dsh-typert-registry";
3
+ import type { ProfileErrorInfo, ProfileReadResult, ProfileSaveRequest, ProfileSelectRequest, ProfileSnapshot, SessionProfileSelectRequest, SessionProfileSnapshot } from "./profile-types.js";
4
+ export interface DsmmProfilesRemote {
5
+ describe(): Promise<RemoteResult<ProfileSnapshot>>;
6
+ read(id: string): Promise<RemoteResult<ProfileReadResult>>;
7
+ save(request: ProfileSaveRequest): Promise<RemoteResult<ProfileReadResult>>;
8
+ select(request: ProfileSelectRequest): Promise<RemoteResult<ProfileSnapshot>>;
9
+ describeSession(sessionId: string): Promise<RemoteResult<SessionProfileSnapshot>>;
10
+ selectSession(sessionId: string, request: SessionProfileSelectRequest): Promise<RemoteResult<SessionProfileSnapshot>>;
11
+ }
12
+ declare module "@deepseek-ai/dsh-typert-protocol/types" {
13
+ interface TypertRemoteMap {
14
+ "dsmmProfiles/describe": DsmmProfilesRemote["describe"];
15
+ "dsmmProfiles/read": DsmmProfilesRemote["read"];
16
+ "dsmmProfiles/save": DsmmProfilesRemote["save"];
17
+ "dsmmProfiles/select": DsmmProfilesRemote["select"];
18
+ "dsmmProfiles/describeSession": DsmmProfilesRemote["describeSession"];
19
+ "dsmmProfiles/selectSession": DsmmProfilesRemote["selectSession"];
20
+ }
21
+ interface TypertRemoteNamespaceMap {
22
+ dsmmProfiles: DsmmProfilesRemote;
23
+ }
24
+ interface RemoteErrorDetailsMap {
25
+ "dsmm-profiles/refused": ProfileErrorInfo;
26
+ "dsmm-profiles/peer-required": {};
27
+ }
28
+ }
29
+ /** Shared wire grammar for native codec validation and local form feedback. */
30
+ export declare function isProfileId(value: unknown): value is string;
31
+ /** Opaque native identities are never interpreted as paths. */
32
+ export declare function isNativeSessionId(value: unknown): value is string;
33
+ /** Explicit strict Host contract; no SRC fallback or browser-supplied authority. */
34
+ export declare const TYPERT_REMOTE: TypertRemoteContribution;
35
+ export declare const TYPERT_HOST: TypertContribution;
36
+ export default TYPERT_REMOTE;
37
+ //# sourceMappingURL=profile-remote.d.ts.map