@dsmm/dsmm 0.3.0 → 0.3.2

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 (245) hide show
  1. package/README.md +26 -40
  2. package/cordis.patch.yml +9 -13
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +24 -68
  5. package/docs/deferred-native-approval-risk.md +8 -12
  6. package/docs/design.md +25 -254
  7. package/docs/lsp.md +2 -2
  8. package/docs/migration-from-ocmm.md +38 -51
  9. package/docs/model-routing.md +21 -21
  10. package/docs/native-permissions.md +17 -7
  11. package/docs/profiles.md +13 -9
  12. package/docs/releasing.md +25 -311
  13. package/docs/roadmap.md +52 -241
  14. package/docs/runtime-recovery.md +29 -91
  15. package/docs/safety-guards.md +19 -16
  16. package/docs/settings-status.md +23 -11
  17. package/docs/skill-sync.md +17 -17
  18. package/docs/web-fetch-fakeip.md +82 -0
  19. package/lib/child-capture.d.ts +12 -2
  20. package/lib/child-capture.js +22 -5
  21. package/lib/client/ChildPermissions.d.ts +43 -0
  22. package/lib/client/ChildPermissions.js +100 -0
  23. package/lib/client/ChildrenPanel.d.ts +5 -5
  24. package/lib/client/ChildrenPanel.js +6 -18
  25. package/lib/client/DeploymentFields.d.ts +32 -0
  26. package/lib/client/DeploymentFields.js +70 -0
  27. package/lib/client/DeploymentPage.d.ts +21 -6
  28. package/lib/client/DeploymentPage.js +80 -112
  29. package/lib/client/HistoryContinuation.d.ts +7 -0
  30. package/lib/client/HistoryContinuation.js +22 -0
  31. package/lib/client/NativeCommandEntries.d.ts +17 -0
  32. package/lib/client/NativeCommandEntries.js +68 -0
  33. package/lib/client/PermissionPanelEntry.d.ts +8 -0
  34. package/lib/client/PermissionPanelEntry.js +11 -0
  35. package/lib/client/PermissionsPanel.d.ts +3 -1
  36. package/lib/client/PermissionsPanel.js +10 -9
  37. package/lib/client/ProfilesSection.js +8 -6
  38. package/lib/client/RoleAvailability.js +1 -1
  39. package/lib/client/RoleToolView-data.d.ts +35 -0
  40. package/lib/client/RoleToolView-data.js +52 -0
  41. package/lib/client/RoleToolView-locales.d.ts +36 -0
  42. package/lib/client/RoleToolView-locales.js +20 -0
  43. package/lib/client/RoleToolView.d.ts +10 -0
  44. package/lib/client/RoleToolView.js +47 -0
  45. package/lib/client/SessionProfiles.js +51 -24
  46. package/lib/client/TemporaryPermissions.d.ts +21 -0
  47. package/lib/client/TemporaryPermissions.js +94 -0
  48. package/lib/client/children-controller.d.ts +2 -8
  49. package/lib/client/children-controller.js +1 -26
  50. package/lib/client/children-locales.d.ts +27 -52
  51. package/lib/client/children-locales.js +8 -12
  52. package/lib/client/configuration-display.d.ts +5 -0
  53. package/lib/client/configuration-display.js +11 -0
  54. package/lib/client/controller.d.ts +18 -0
  55. package/lib/client/controller.js +118 -28
  56. package/lib/client/deployment-controller.d.ts +13 -1
  57. package/lib/client/deployment-controller.js +84 -24
  58. package/lib/client/deployment-data.d.ts +1 -0
  59. package/lib/client/deployment-data.js +4 -1
  60. package/lib/client/deployment-locales.d.ts +43 -0
  61. package/lib/client/deployment-locales.js +45 -19
  62. package/lib/client/deployment-modules.d.ts +9 -0
  63. package/lib/client/deployment-modules.js +24 -0
  64. package/lib/client/deployment-workspace.d.ts +48 -0
  65. package/lib/client/deployment-workspace.js +123 -0
  66. package/lib/client/history-controller.d.ts +29 -0
  67. package/lib/client/history-controller.js +111 -0
  68. package/lib/client/history-entry.d.ts +11 -0
  69. package/lib/client/history-entry.js +106 -0
  70. package/lib/client/history-locales.d.ts +95 -0
  71. package/lib/client/history-locales.js +41 -0
  72. package/lib/client/index.js +26 -76
  73. package/lib/client/locales.d.ts +13 -0
  74. package/lib/client/locales.js +104 -86
  75. package/lib/client/permission-controller.d.ts +1 -0
  76. package/lib/client/permission-controller.js +3 -2
  77. package/lib/client/permission-locales.d.ts +51 -0
  78. package/lib/client/permission-locales.js +59 -19
  79. package/lib/client/session-labels.js +4 -3
  80. package/lib/client/styles.d.ts +1 -1
  81. package/lib/client/styles.js +9 -8
  82. package/lib/client/temporary-permission-client.d.ts +20 -0
  83. package/lib/client/temporary-permission-client.js +52 -0
  84. package/lib/client/temporary-permission-entry.d.ts +6 -0
  85. package/lib/client/temporary-permission-entry.js +56 -0
  86. package/lib/client.js +5691 -3439
  87. package/lib/commands.js +2 -0
  88. package/lib/config-file-store.d.ts +3 -0
  89. package/lib/config-file-store.js +4 -2
  90. package/lib/config-revision.d.ts +5 -0
  91. package/lib/config-revision.js +11 -0
  92. package/lib/core-permission-authority.js +11 -41
  93. package/lib/deployment-config.d.ts +9 -2
  94. package/lib/deployment-config.js +35 -8
  95. package/lib/deployment-permission-rules.js +19 -7
  96. package/lib/dsh-types.d.ts +1 -1
  97. package/lib/history-candidates.d.ts +30 -0
  98. package/lib/history-candidates.js +176 -0
  99. package/lib/history-codec.d.ts +11 -0
  100. package/lib/history-codec.js +102 -0
  101. package/lib/history-contract.d.ts +44 -0
  102. package/lib/history-contract.js +2 -0
  103. package/lib/history-controller.d.ts +42 -0
  104. package/lib/history-controller.js +329 -0
  105. package/lib/history-policy.d.ts +4 -0
  106. package/lib/history-policy.js +8 -0
  107. package/lib/history-remote.d.ts +28 -0
  108. package/lib/history-remote.js +17 -0
  109. package/lib/history-rpc.d.ts +24 -0
  110. package/lib/history-rpc.js +136 -0
  111. package/lib/history-support.d.ts +15 -0
  112. package/lib/history-support.js +21 -0
  113. package/lib/history-types.d.ts +67 -0
  114. package/lib/history-types.js +2 -0
  115. package/lib/host-llm-startup.js +3 -3
  116. package/lib/host-llm.d.ts +9 -3
  117. package/lib/host-llm.js +48 -8
  118. package/lib/index.d.ts +18 -20
  119. package/lib/index.js +147 -415
  120. package/lib/lifetime.d.ts +4 -0
  121. package/lib/lifetime.js +22 -0
  122. package/lib/live-pi-ai-owner.d.ts +1 -0
  123. package/lib/live-pi-ai-owner.js +8 -4
  124. package/lib/mode.d.ts +3 -2
  125. package/lib/mode.js +28 -41
  126. package/lib/model-routing.d.ts +2 -8
  127. package/lib/model-routing.js +59 -175
  128. package/lib/native-admission.d.ts +77 -0
  129. package/lib/native-admission.js +503 -0
  130. package/lib/native-pi-ai-wire.d.ts +3 -1
  131. package/lib/native-pi-ai-wire.js +47 -13
  132. package/lib/permission-child-control.d.ts +36 -0
  133. package/lib/permission-child-control.js +164 -0
  134. package/lib/permission-control.d.ts +2 -3
  135. package/lib/permission-control.js +7 -0
  136. package/lib/permission-controller.js +2 -2
  137. package/lib/permission-exec-argv.d.ts +32 -0
  138. package/lib/permission-exec-argv.js +171 -0
  139. package/lib/permission-fs-search.js +2 -1
  140. package/lib/permission-fs.js +2 -1
  141. package/lib/permission-native-rules.js +3 -3
  142. package/lib/permission-temporary-files.d.ts +19 -0
  143. package/lib/permission-temporary-files.js +248 -0
  144. package/lib/permission-temporary-grants.d.ts +106 -0
  145. package/lib/permission-temporary-grants.js +198 -0
  146. package/lib/permission-temporary-install.d.ts +25 -0
  147. package/lib/permission-temporary-install.js +86 -0
  148. package/lib/permission-temporary-remote.d.ts +19 -0
  149. package/lib/permission-temporary-remote.js +75 -0
  150. package/lib/permission-temporary-rpc.d.ts +37 -0
  151. package/lib/permission-temporary-rpc.js +154 -0
  152. package/lib/permission-temporary-types.d.ts +47 -0
  153. package/lib/permission-temporary-types.js +2 -0
  154. package/lib/permission-temporary-web.d.ts +11 -0
  155. package/lib/permission-temporary-web.js +154 -0
  156. package/lib/permission-web.js +2 -1
  157. package/lib/preset-registry.js +3 -2
  158. package/lib/preset-skills.d.ts +3 -12
  159. package/lib/preset-skills.js +28 -58
  160. package/lib/profile-diagnostics.d.ts +1 -1
  161. package/lib/profile-diagnostics.js +2 -2
  162. package/lib/profile-remote.js +61 -22
  163. package/lib/profile-rpc.d.ts +4 -3
  164. package/lib/profile-rpc.js +35 -37
  165. package/lib/profile-runtime.d.ts +42 -74
  166. package/lib/profile-runtime.js +314 -617
  167. package/lib/profile-store.d.ts +20 -8
  168. package/lib/profile-store.js +112 -63
  169. package/lib/profile-types.d.ts +19 -4
  170. package/lib/profiles.d.ts +3 -1
  171. package/lib/profiles.js +9 -7
  172. package/lib/prompt-content.d.ts +1 -0
  173. package/lib/prompt-content.js +4 -1
  174. package/lib/prompts.d.ts +2 -12
  175. package/lib/prompts.js +11 -66
  176. package/lib/role-control-remote.d.ts +1 -4
  177. package/lib/role-control-remote.js +8 -36
  178. package/lib/role-control-rpc.d.ts +10 -36
  179. package/lib/role-control-rpc.js +112 -269
  180. package/lib/role-control-types.d.ts +3 -26
  181. package/lib/role-control-types.js +3 -4
  182. package/lib/role-identity.d.ts +5 -0
  183. package/lib/role-identity.js +10 -0
  184. package/lib/role-invocation.d.ts +3 -3
  185. package/lib/role-invocation.js +2 -2
  186. package/lib/role-llm-runtime.js +5 -11
  187. package/lib/role-policy.d.ts +19 -50
  188. package/lib/role-policy.js +136 -508
  189. package/lib/role-providers.d.ts +5 -8
  190. package/lib/role-providers.js +20 -86
  191. package/lib/role-routing.d.ts +1 -3
  192. package/lib/role-routing.js +24 -34
  193. package/lib/role-subagents.d.ts +5 -14
  194. package/lib/role-subagents.js +163 -108
  195. package/lib/runtime-integration.d.ts +5 -78
  196. package/lib/runtime-integration.js +11 -697
  197. package/lib/session-metadata.d.ts +13 -12
  198. package/lib/session-metadata.js +6 -31
  199. package/lib/session-scope.js +2 -1
  200. package/lib/settings.d.ts +5 -18
  201. package/lib/settings.js +19 -43
  202. package/lib/skills.d.ts +1 -0
  203. package/lib/skills.js +5 -1
  204. package/lib/state.d.ts +3 -2
  205. package/lib/state.js +26 -10
  206. package/lib/status.d.ts +1 -9
  207. package/lib/status.js +3 -55
  208. package/lib/web-fetch-address-policy.d.ts +24 -0
  209. package/lib/web-fetch-address-policy.js +189 -0
  210. package/lib/web-fetch-fakeip.d.ts +25 -0
  211. package/lib/web-fetch-fakeip.js +107 -0
  212. package/package.json +124 -106
  213. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
  214. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
  215. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
  216. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
  217. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
  218. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
  219. package/patches/dsh-approval-settlement/README.md +41 -0
  220. package/patches/dsh-approval-settlement/metadata.json +10 -0
  221. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
  222. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
  223. package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
  224. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
  225. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
  226. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
  227. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
  228. package/docs/research/deepseek-v4-pro.md +0 -74
  229. package/docs/research/oh-dsh.md +0 -96
  230. package/lib/agent-registry.d.ts +0 -36
  231. package/lib/agent-registry.js +0 -75
  232. package/lib/child-admission.d.ts +0 -40
  233. package/lib/child-admission.js +0 -151
  234. package/lib/delivery-authority.d.ts +0 -83
  235. package/lib/delivery-authority.js +0 -397
  236. package/lib/native-child-evidence.d.ts +0 -40
  237. package/lib/native-child-evidence.js +0 -104
  238. package/lib/role-runs.d.ts +0 -138
  239. package/lib/role-runs.js +0 -335
  240. package/lib/session-persistence.d.ts +0 -36
  241. package/lib/session-persistence.js +0 -304
  242. package/lib/subagent-runtime.d.ts +0 -57
  243. package/lib/subagent-runtime.js +0 -257
  244. package/prompts/deepseek-flash.md +0 -11
  245. package/prompts/deepseek-v4-pro.md +0 -14
@@ -1,17 +1,14 @@
1
1
  import type { SubagentProvider } from "@deepseek-ai/dsh-subagent";
2
- import type { Agent, AgentOptions } from "@deepseek-ai/dsh-agent";
3
- import type { DshContext } from "./dsh-types.js";
2
+ import type { Context } from "@deepseek-ai/cordis";
4
3
  export { roleProviderName } from "./roles.js";
5
4
  import type { DsmmRoleId } from "./roles.js";
6
- import type { DsmmSettings, DsmmSettingsGetter } from "./settings.js";
7
- import type { DsmmRolePolicy } from "./role-policy.js";
5
+ import type { DsmmSettingsGetter } from "./settings.js";
6
+ import type { NativeAdmission } from "./native-admission.js";
8
7
  export interface DsmmSubagentRegistry {
9
8
  getProvider(name: string): SubagentProvider | undefined;
10
9
  registerProvider(provider: SubagentProvider): () => void;
11
10
  resolveMaxDepth?(configured?: number): number | undefined;
12
11
  }
13
- export declare function roleFromProviderName(provider: string): DsmmRoleId | undefined;
14
- export declare function roleAgentOptions(parent: Agent, role: DsmmRoleId, settings: DsmmSettings, signal: AbortSignal, explicit?: AgentOptions): Promise<AgentOptions | undefined>;
15
- /** The native manager owns descriptors, capability admission and activations. */
16
- export declare function registerRoleProviders(ctx: DshContext, getSettings: DsmmSettingsGetter, getDeploymentSettings?: DsmmSettingsGetter, policy?: DsmmRolePolicy): void;
12
+ export declare function roleFromProviderName(name: string): DsmmRoleId | undefined;
13
+ export declare function registerRoleProviders(ctx: Context, getSettings: DsmmSettingsGetter, admission: NativeAdmission): void;
17
14
  //# sourceMappingURL=role-providers.d.ts.map
@@ -1,92 +1,26 @@
1
1
  import { SubagentError } from "@deepseek-ai/dsh-subagent";
2
2
  import { DSMM_ROLE_IDS, roleProviderName } from "./roles.js";
3
3
  export { roleProviderName } from "./roles.js";
4
- import { currentRoleInvocation, invocationAgentOptions, resolveRoleInvocation } from "./role-invocation.js";
5
- import { currentManagedCreation } from "./agent-registry.js";
6
- export function roleFromProviderName(provider) {
7
- return DSMM_ROLE_IDS.find((role) => role !== "dsmm-orchestrator" && roleProviderName(role) === provider);
8
- }
9
- const NO_CAPABILITIES = Object.freeze({ agentOptions: false, outputSchema: false, depthLimit: false, agentPreset: false });
10
- function supportedSpawn(provider) {
11
- return provider !== undefined && provider.name === "spawn" && typeof provider.prepareContinuable === "function"
12
- && provider.inheritsParentContext === false && provider.agentRouteDefaults === undefined;
13
- }
14
- export async function roleAgentOptions(parent, role, settings, signal, explicit) {
15
- const invocation = currentRoleInvocation(parent, role) ?? await resolveRoleInvocation(parent, role, settings, signal, {}, explicit);
16
- return invocationAgentOptions(invocation, explicit);
17
- }
18
- /** The native manager owns descriptors, capability admission and activations. */
19
- export function registerRoleProviders(ctx, getSettings, getDeploymentSettings = getSettings, policy) {
20
- const installed = new WeakSet();
21
- const install = (readyCtx) => {
22
- const registry = readyCtx.get?.("subagents")
23
- ?? (readyCtx.get === undefined ? readyCtx.subagents : undefined);
24
- if (registry === undefined || installed.has(registry))
25
- return;
26
- const disposers = [];
27
- installed.add(registry);
28
- try {
29
- const settings = getDeploymentSettings();
30
- if (!settings.modules.deepwork.enabled)
31
- return;
32
- for (const role of DSMM_ROLE_IDS) {
33
- if (role === "dsmm-orchestrator" || !settings.roles[role])
34
- continue;
35
- let active = true;
36
- const dispose = registry.registerProvider({
37
- name: roleProviderName(role),
38
- get capabilities() { const spawn = registry.getProvider("spawn"); return supportedSpawn(spawn) ? spawn.capabilities : NO_CAPABILITIES; },
39
- inheritsParentContext: false,
40
- get prepareContinuable() {
41
- const spawn = registry.getProvider("spawn");
42
- return async (request) => {
43
- if (!supportedSpawn(spawn) || spawn.prepareContinuable === undefined)
44
- throw new SubagentError("DSMM requires a local spawn provider", "UNSUPPORTED_CAPABILITY");
45
- if (!active || registry.getProvider("spawn") !== spawn)
46
- throw new SubagentError("DSMM native continuable provider changed", "NO_PROVIDER");
47
- const admitted = getSettings(request.parent);
48
- if (!admitted.modules.deepwork.enabled || !admitted.roles[role])
49
- throw new SubagentError("DSMM module or role is disabled", "UNAUTHORIZED");
50
- const operation = currentManagedCreation();
51
- if (operation?.kind !== "fresh" || operation.parent !== request.parent || operation.childId !== request.sessionId)
52
- throw new SubagentError("DSMM role requires its managed creation operation", "UNAUTHORIZED");
53
- if (operation.delegationMode === "continuable" && (!admitted.subagents.enableRunInBackground || admitted.subagents.backgroundMode !== "continuable"))
54
- throw new SubagentError("DSMM continuable delegation requires explicit admitted opt-in", "UNAUTHORIZED");
55
- const preparing = policy?.prepareContinuable(request.parent, role, request.signal);
56
- const invocation = currentRoleInvocation(request.parent, role);
57
- request.signal.throwIfAborted();
58
- if (!active || registry.getProvider("spawn") !== spawn)
59
- throw new SubagentError("DSMM continuable provider changed during preflight", "NO_PROVIDER");
60
- if (preparing !== undefined)
61
- policy.recordContinuableCreation(request.sessionId, request.parent, role, invocation, preparing.epoch, request.signal);
62
- const prepared = await spawn.prepareContinuable(request);
63
- if (prepared.seed !== undefined)
64
- throw new SubagentError("DSMM spawn cannot inherit parent history", "UNSUPPORTED_CAPABILITY");
65
- return prepared;
66
- };
67
- }
68
- });
69
- const provider = registry.getProvider(roleProviderName(role));
70
- if (provider !== undefined)
71
- policy?.captureProvider(provider);
72
- disposers.push(() => { active = false; dispose(); });
4
+ export function roleFromProviderName(name) { return DSMM_ROLE_IDS.find(role => role !== "dsmm-orchestrator" && roleProviderName(role) === name); }
5
+ export function registerRoleProviders(ctx, getSettings, admission) {
6
+ const registry = ctx.subagents;
7
+ for (const role of DSMM_ROLE_IDS.filter(role => role !== "dsmm-orchestrator" && getSettings().roles[role])) {
8
+ const provider = {
9
+ name: roleProviderName(role), inheritsParentContext: false,
10
+ get capabilities() { return registry.getProvider("spawn")?.capabilities ?? { agentOptions: false, agentPreset: false, outputSchema: false, depthLimit: false }; },
11
+ async prepareContinuable(request) {
12
+ admission.prepare(request, provider);
13
+ const spawn = registry.getProvider("spawn");
14
+ if (!spawn?.prepareContinuable || spawn.inheritsParentContext !== false || spawn.agentRouteDefaults !== undefined)
15
+ throw new SubagentError("Independent native spawn provider required", "UNSUPPORTED_CAPABILITY");
16
+ const prepared = await spawn.prepareContinuable(request);
17
+ admission.prepare(request, provider);
18
+ if (registry.getProvider("spawn") !== spawn || prepared.seed !== undefined)
19
+ throw new SubagentError("Independent spawn seed changed", "UNAUTHORIZED");
20
+ return prepared;
73
21
  }
74
- readyCtx.effect?.(() => () => {
75
- for (const dispose of disposers.reverse())
76
- dispose();
77
- installed.delete(registry);
78
- });
79
- }
80
- catch (error) {
81
- for (const dispose of disposers.reverse())
82
- dispose();
83
- installed.delete(registry);
84
- throw error;
85
- }
86
- };
87
- if (ctx.inject !== undefined)
88
- ctx.inject(["subagents"], install);
89
- else
90
- install(ctx);
22
+ };
23
+ registry.registerProvider(provider);
24
+ }
91
25
  }
92
26
  //# sourceMappingURL=role-providers.js.map
@@ -43,11 +43,9 @@ export declare function pinRoleRoute(agent: DshAgent, identity: string, route: D
43
43
  }): RoleRouteLock;
44
44
  export declare function clearRoleRouteLock(agent: DshAgent): void;
45
45
  export declare function roleRouteRuntimeState(agent: DshAgent, settings: DsmmSettings, role: DsmmRoleId | undefined, epoch?: string): DsmmRoleRuntimeState;
46
- export declare function rolePolicyIdentity(settings: DsmmSettings, role: DsmmRoleId | undefined, epoch?: string): string | undefined;
47
- /** Durable profile choice is not permission to retain a former process's route lock. */
48
46
  export declare function liveRolePolicyIdentity(agent: DshAgent, settings: DsmmSettings, role: DsmmRoleId | undefined, epoch?: string): string | undefined;
49
47
  /** Native custom events are model-hidden log facts, retained across surface compaction. */
50
- export declare function establishRolePolicy(frame: AgentRequestFrame, settings: DsmmSettings, role: DsmmRoleId | undefined, ctx?: DshContext, epoch?: string): Promise<string | undefined>;
48
+ export declare function establishRolePolicy(frame: AgentRequestFrame, settings: DsmmSettings, role: DsmmRoleId | undefined, _ctx?: DshContext, epoch?: string): Promise<string | undefined>;
51
49
  export declare function recordAdmittedRecoveryRoute(frame: AgentRequestFrame, route: DsmmModelRoute): void;
52
50
  export declare function takeAdmittedRecoveryRoute(frame: AgentRequestFrame): DsmmModelRoute | undefined;
53
51
  export declare function effectiveRoleFallbackRoutes(settings: DsmmSettings, role: DsmmRoleId | undefined): readonly DsmmModelRoute[];
@@ -1,6 +1,7 @@
1
- import { createHash, randomUUID } from "node:crypto";
1
+ import { randomBytes } from "node:crypto";
2
+ import { isDeepStrictEqual } from "node:util";
2
3
  import { LlmError } from "@deepseek-ai/dsh-llm";
3
- import { assertDsmmMetadataPersistence } from "./session-metadata.js";
4
+ import { appendRolePolicyRecord } from "./session-metadata.js";
4
5
  import { isDsmmRoleId } from "./roles.js";
5
6
  import { isCurrentRecoveryStep } from "./recovery-policy.js";
6
7
  import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
@@ -9,7 +10,7 @@ import { canonicalModelRouteJson, normalizeModelRouteJson, sameModelRouteJson }
9
10
  import { DsmmMissingProviderError, modelRouteFromHeader, modelRouteToCall } from "./role-llm.js";
10
11
  const admittedRecoveryRoutes = new WeakMap();
11
12
  const routeLocks = new WeakMap();
12
- const agentEntries = new WeakMap();
13
+ const agentPolicies = new WeakMap();
13
14
  export const DSMM_ROLE_POLICY_EVENT = "dsmm/role-policy";
14
15
  /** Native user selection is authority; inherited headers/default configs are not. */
15
16
  export function latestNativeModelSelection(agent) {
@@ -99,35 +100,24 @@ export function roleRouteRuntimeState(agent, settings, role, epoch) {
99
100
  ...(lock === undefined ? {} : { route: { ...lock.route } }), retries: lock?.retries ?? 0,
100
101
  rateLimitFailures: lock?.rateLimits ?? 0, switches: lock?.switches ?? 0, totalDelayMs: lock?.totalDelayMs ?? 0 };
101
102
  }
102
- export function rolePolicyIdentity(settings, role, epoch) {
103
- if (role === undefined)
103
+ export function liveRolePolicyIdentity(agent, settings, role, epoch) {
104
+ if (role === undefined) {
105
+ agentPolicies.delete(agent);
104
106
  return undefined;
107
+ }
105
108
  const policy = settings.roleRouting[role];
106
109
  const resolved = resolveRoleRuntimePolicy(settings, role);
107
- const legacy = [policy?.primary, ...resolved.fallbackRoutes].every(route => route === undefined
108
- || Object.keys(route).every(key => ["provider", "model", "reasoningEffort"].includes(key)));
109
- const seen = new Set(policy?.primary === undefined ? [] : [JSON.stringify([policy.primary.provider, policy.primary.model])]);
110
- const identityFallbacks = legacy ? resolved.fallbackRoutes.filter(route => {
111
- const key = JSON.stringify([route.provider, route.model]);
112
- if (seen.has(key))
113
- return false;
114
- seen.add(key);
115
- return true;
116
- }) : resolved.fallbackRoutes;
117
- return createHash("sha256").update(JSON.stringify({
118
- version: 2, role, epoch: epoch ?? null, primary: policy?.primary === undefined ? null : canonicalRoute(policy.primary),
119
- fallbackSource: resolved.fallbackSource, fallbackRoutes: identityFallbacks.map(canonicalRoute),
120
- strategy: resolved.strategy, rateLimit: resolved.rateLimit
121
- })).digest("hex");
122
- }
123
- /** Durable profile choice is not permission to retain a former process's route lock. */
124
- export function liveRolePolicyIdentity(agent, settings, role, epoch) {
125
- let entry = agentEntries.get(agent);
126
- if (entry === undefined) {
127
- entry = randomUUID();
128
- agentEntries.set(agent, entry);
110
+ const fields = { role, epoch, primary: policy?.primary, levels: policy?.levels,
111
+ fallbackSource: resolved.fallbackSource, fallbackRoutes: resolved.fallbackRoutes,
112
+ strategy: resolved.strategy, rateLimit: resolved.rateLimit, modelParameters: settings.modelParameters,
113
+ recovery: { enabled: settings.runtimeRecovery.enabled, retryOnStatusCodes: settings.runtimeRecovery.retryOnStatusCodes,
114
+ retryOnCodes: settings.runtimeRecovery.retryOnCodes, maxFallbackAttempts: settings.runtimeRecovery.maxFallbackAttempts } };
115
+ let observed = agentPolicies.get(agent);
116
+ if (observed === undefined || !isDeepStrictEqual(observed.fields, fields)) {
117
+ observed = { fields: structuredClone(fields), identity: randomBytes(32).toString("hex") };
118
+ agentPolicies.set(agent, observed);
129
119
  }
130
- return rolePolicyIdentity(settings, role, `${epoch ?? "unscoped"}:${entry}`);
120
+ return observed.identity;
131
121
  }
132
122
  function canonicalRoute(route) {
133
123
  if (Object.keys(route).every(key => ["provider", "model", "reasoningEffort"].includes(key))) {
@@ -156,7 +146,7 @@ function readPolicyMarker(event) {
156
146
  return { role: data.role, policy: data.policy };
157
147
  }
158
148
  /** Native custom events are model-hidden log facts, retained across surface compaction. */
159
- export async function establishRolePolicy(frame, settings, role, ctx, epoch) {
149
+ export async function establishRolePolicy(frame, settings, role, _ctx, epoch) {
160
150
  const identity = liveRolePolicyIdentity(frame.agent, settings, role, epoch);
161
151
  const declared = role !== undefined && (Object.keys(settings.roleRouting[role] ?? {}).length > 0 || settings.runtimeRecovery.fallbackRoutes.length > 0);
162
152
  if (frame.signal.aborted)
@@ -173,14 +163,12 @@ export async function establishRolePolicy(frame, settings, role, ctx, epoch) {
173
163
  return identity;
174
164
  if (identity === undefined || role === undefined || !declared) {
175
165
  if (latest !== undefined && latest.policy !== null) {
176
- assertDsmmMetadataPersistence(ctx ?? frame.agent.ctx);
177
- await frame.agent.session.append(DSMM_ROLE_POLICY_EVENT, { version: 1, role: latest.role, policy: null });
166
+ appendRolePolicyRecord(frame.agent.session, { version: 1, role: latest.role, policy: null });
178
167
  }
179
168
  return identity;
180
169
  }
181
170
  if (latest?.role !== role || latest.policy !== identity) {
182
- assertDsmmMetadataPersistence(ctx ?? frame.agent.ctx);
183
- await frame.agent.session.append(DSMM_ROLE_POLICY_EVENT, { version: 1, role, policy: identity });
171
+ appendRolePolicyRecord(frame.agent.session, { version: 1, role, policy: identity });
184
172
  }
185
173
  return identity;
186
174
  }
@@ -203,12 +191,14 @@ export function sameModelRoute(left, right) {
203
191
  }
204
192
  /** Accepted post-policy route changes are durable host/recovery ownership, not a new primary request. */
205
193
  export function persistedRoleRoute(frame, primary, fallbacks = [], identity) {
194
+ const currentIdentity = agentPolicies.get(frame.agent)?.identity;
206
195
  const events = policyEvents(frame);
207
196
  let matchingPolicy = false;
208
197
  let selected;
209
198
  for (const event of events) {
210
199
  if (isPresetBoundary(frame, event) || event.type === DSMM_ROLE_POLICY_EVENT) {
211
- matchingPolicy = event.type === DSMM_ROLE_POLICY_EVENT && identity !== undefined && readPolicyMarker(event)?.policy === identity;
200
+ const marker = event.type === DSMM_ROLE_POLICY_EVENT ? readPolicyMarker(event) : undefined;
201
+ matchingPolicy = identity !== undefined && identity === currentIdentity && marker?.policy === identity;
212
202
  selected = undefined;
213
203
  continue;
214
204
  }
@@ -4,16 +4,16 @@ import type { ToolRuntime } from "@deepseek-ai/dsh-tools";
4
4
  import type { DshAgent, DshContext } from "./dsh-types.js";
5
5
  import type { DsmmRoleId } from "./roles.js";
6
6
  import { DsmmRolePolicy } from "./role-policy.js";
7
- import type { DsmmSettings, DsmmSettingsGetter, DsmmProfileAdmission, DsmmModelRoute } from "./settings.js";
7
+ import type { DsmmSettings, DsmmSettingsGetter, DsmmModelRoute } from "./settings.js";
8
8
  import type { DeepworkModeController } from "./state.js";
9
9
  import type { DsmmInvocationView } from "./profile-types.js";
10
10
  import type { ResolvedRoleInvocation } from "./role-invocation.js";
11
- import type { RoleRunRegistry } from "./role-runs.js";
11
+ import type { NativeAdmission } from "./native-admission.js";
12
12
  /** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
13
13
  export declare function registerNativeSubagentControls(ctx: Context): Promise<void>;
14
- /** C's same-run holder/live projection can read the actual lock without reapplying defaults. */
14
+ /** Project the captured invocation without reapplying deployment defaults. */
15
15
  export declare function roleInvocationView(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], getSettings: DsmmSettingsGetter, child?: DshAgent, ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): DsmmInvocationView;
16
- /** Initial preflight/lock is not an observed SDK request; keep E's distinction truthful. */
16
+ /** Distinguish the captured route from an observed native request. */
17
17
  export declare function roleInvocationObservation(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], getSettings: DsmmSettingsGetter, child?: DshAgent, ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): {
18
18
  view: DsmmInvocationView;
19
19
  routeKind: "initial" | "actual";
@@ -41,15 +41,6 @@ export interface DsmmRoleRouteComparison {
41
41
  }
42
42
  /** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
43
43
  export declare function roleRouteComparison(child: Agent): DsmmRoleRouteComparison;
44
- export interface DsmmRoleRunCapture {
45
- readonly invocation: ResolvedRoleInvocation;
46
- readonly admission: DsmmProfileAdmission;
47
- }
48
- /** Created on the parent's stable Host scope, never per profile entry or tool call. */
49
- export interface DsmmRoleRunsBinding {
50
- readonly registry: RoleRunRegistry<DsmmRoleRunCapture, DsmmInvocationView>;
51
- readonly owner: object;
52
- }
53
44
  export interface DsmmCallableEntry {
54
45
  name: string;
55
46
  kind: "role" | "category";
@@ -61,5 +52,5 @@ export declare function callableRoleInventory(settings: DsmmSettings, targets: r
61
52
  /** Exact currently exposed definitions, suitable for E's runtime guidance and safe capability views. */
62
53
  export declare function admittedCallableRoleInventory(agent: DshAgent, settings: DsmmSettings, policy: DsmmRolePolicy, tools: ToolRuntime): readonly DsmmCallableEntry[];
63
54
  /** Published name retained; all native/headless Agents consume one admitted policy. */
64
- export declare function registerHeadlessRoleTools(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy?: DsmmRolePolicy, roleRuns?: DsmmRoleRunsBinding): Promise<void>;
55
+ export declare function registerHeadlessRoleTools(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy: DsmmRolePolicy, admission: NativeAdmission, onlyAgent: DshAgent): Promise<void>;
65
56
  //# sourceMappingURL=role-subagents.d.ts.map