@dsmm/dsmm 0.3.0 → 0.3.1

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 (166) hide show
  1. package/README.md +26 -40
  2. package/cordis.patch.yml +0 -13
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +19 -73
  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 +34 -280
  13. package/docs/roadmap.md +23 -254
  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/ChildrenPanel.d.ts +1 -4
  22. package/lib/client/ChildrenPanel.js +4 -16
  23. package/lib/client/DeploymentFields.d.ts +28 -0
  24. package/lib/client/DeploymentFields.js +68 -0
  25. package/lib/client/DeploymentPage.d.ts +17 -5
  26. package/lib/client/DeploymentPage.js +79 -112
  27. package/lib/client/NativeCommandEntries.d.ts +17 -0
  28. package/lib/client/NativeCommandEntries.js +68 -0
  29. package/lib/client/PermissionsPanel.d.ts +1 -1
  30. package/lib/client/PermissionsPanel.js +8 -8
  31. package/lib/client/ProfilesSection.js +7 -5
  32. package/lib/client/RoleToolView-data.d.ts +35 -0
  33. package/lib/client/RoleToolView-data.js +52 -0
  34. package/lib/client/RoleToolView-locales.d.ts +36 -0
  35. package/lib/client/RoleToolView-locales.js +20 -0
  36. package/lib/client/RoleToolView.d.ts +10 -0
  37. package/lib/client/RoleToolView.js +47 -0
  38. package/lib/client/SessionProfiles.js +39 -15
  39. package/lib/client/children-controller.d.ts +2 -8
  40. package/lib/client/children-controller.js +1 -26
  41. package/lib/client/children-locales.d.ts +27 -52
  42. package/lib/client/children-locales.js +8 -12
  43. package/lib/client/configuration-display.d.ts +5 -0
  44. package/lib/client/configuration-display.js +11 -0
  45. package/lib/client/controller.d.ts +1 -0
  46. package/lib/client/controller.js +20 -13
  47. package/lib/client/deployment-controller.d.ts +13 -1
  48. package/lib/client/deployment-controller.js +84 -24
  49. package/lib/client/deployment-data.d.ts +1 -0
  50. package/lib/client/deployment-data.js +4 -1
  51. package/lib/client/deployment-locales.d.ts +43 -0
  52. package/lib/client/deployment-locales.js +35 -9
  53. package/lib/client/deployment-modules.d.ts +9 -0
  54. package/lib/client/deployment-modules.js +24 -0
  55. package/lib/client/deployment-workspace.d.ts +48 -0
  56. package/lib/client/deployment-workspace.js +123 -0
  57. package/lib/client/index.js +11 -74
  58. package/lib/client/locales.d.ts +7 -0
  59. package/lib/client/locales.js +12 -6
  60. package/lib/client/permission-controller.d.ts +1 -0
  61. package/lib/client/permission-controller.js +3 -2
  62. package/lib/client/permission-locales.d.ts +25 -0
  63. package/lib/client/permission-locales.js +24 -4
  64. package/lib/client/session-labels.js +4 -3
  65. package/lib/client/styles.d.ts +1 -1
  66. package/lib/client/styles.js +9 -8
  67. package/lib/client.js +2713 -2361
  68. package/lib/commands.js +2 -0
  69. package/lib/config-file-store.d.ts +3 -0
  70. package/lib/config-file-store.js +4 -2
  71. package/lib/config-revision.d.ts +5 -0
  72. package/lib/config-revision.js +11 -0
  73. package/lib/core-permission-authority.js +11 -41
  74. package/lib/deployment-config.d.ts +9 -2
  75. package/lib/deployment-config.js +35 -8
  76. package/lib/deployment-permission-rules.js +19 -7
  77. package/lib/dsh-types.d.ts +1 -1
  78. package/lib/host-llm-startup.js +3 -3
  79. package/lib/host-llm.d.ts +9 -3
  80. package/lib/host-llm.js +48 -8
  81. package/lib/index.d.ts +16 -20
  82. package/lib/index.js +130 -416
  83. package/lib/lifetime.d.ts +4 -0
  84. package/lib/lifetime.js +22 -0
  85. package/lib/live-pi-ai-owner.d.ts +1 -0
  86. package/lib/live-pi-ai-owner.js +8 -4
  87. package/lib/mode.d.ts +3 -2
  88. package/lib/mode.js +28 -41
  89. package/lib/model-routing.d.ts +2 -8
  90. package/lib/model-routing.js +59 -175
  91. package/lib/native-admission.d.ts +56 -0
  92. package/lib/native-admission.js +313 -0
  93. package/lib/native-pi-ai-wire.d.ts +3 -1
  94. package/lib/native-pi-ai-wire.js +47 -13
  95. package/lib/permission-control.d.ts +0 -3
  96. package/lib/preset-registry.js +3 -2
  97. package/lib/preset-skills.d.ts +3 -12
  98. package/lib/preset-skills.js +28 -58
  99. package/lib/profile-diagnostics.d.ts +1 -1
  100. package/lib/profile-diagnostics.js +2 -2
  101. package/lib/profile-remote.js +61 -22
  102. package/lib/profile-rpc.d.ts +4 -3
  103. package/lib/profile-rpc.js +33 -37
  104. package/lib/profile-runtime.d.ts +31 -74
  105. package/lib/profile-runtime.js +224 -639
  106. package/lib/profile-store.d.ts +18 -6
  107. package/lib/profile-store.js +104 -62
  108. package/lib/profile-types.d.ts +18 -4
  109. package/lib/profiles.d.ts +3 -1
  110. package/lib/profiles.js +9 -7
  111. package/lib/prompt-content.d.ts +1 -0
  112. package/lib/prompt-content.js +4 -1
  113. package/lib/prompts.d.ts +2 -12
  114. package/lib/prompts.js +11 -66
  115. package/lib/role-control-remote.d.ts +1 -4
  116. package/lib/role-control-remote.js +8 -36
  117. package/lib/role-control-rpc.d.ts +10 -36
  118. package/lib/role-control-rpc.js +112 -269
  119. package/lib/role-control-types.d.ts +3 -26
  120. package/lib/role-control-types.js +3 -4
  121. package/lib/role-identity.d.ts +5 -0
  122. package/lib/role-identity.js +10 -0
  123. package/lib/role-invocation.d.ts +2 -2
  124. package/lib/role-llm-runtime.js +5 -11
  125. package/lib/role-policy.d.ts +19 -50
  126. package/lib/role-policy.js +136 -508
  127. package/lib/role-providers.d.ts +5 -8
  128. package/lib/role-providers.js +20 -86
  129. package/lib/role-routing.d.ts +1 -3
  130. package/lib/role-routing.js +24 -34
  131. package/lib/role-subagents.d.ts +5 -14
  132. package/lib/role-subagents.js +148 -106
  133. package/lib/runtime-integration.d.ts +5 -78
  134. package/lib/runtime-integration.js +11 -697
  135. package/lib/session-metadata.d.ts +13 -12
  136. package/lib/session-metadata.js +6 -31
  137. package/lib/session-scope.js +2 -1
  138. package/lib/settings.d.ts +5 -18
  139. package/lib/settings.js +19 -43
  140. package/lib/state.d.ts +3 -2
  141. package/lib/state.js +26 -10
  142. package/lib/status.d.ts +1 -9
  143. package/lib/status.js +3 -55
  144. package/lib/web-fetch-address-policy.d.ts +24 -0
  145. package/lib/web-fetch-address-policy.js +189 -0
  146. package/lib/web-fetch-fakeip.d.ts +25 -0
  147. package/lib/web-fetch-fakeip.js +107 -0
  148. package/package.json +113 -103
  149. package/docs/research/deepseek-v4-pro.md +0 -74
  150. package/docs/research/oh-dsh.md +0 -96
  151. package/lib/agent-registry.d.ts +0 -36
  152. package/lib/agent-registry.js +0 -75
  153. package/lib/child-admission.d.ts +0 -40
  154. package/lib/child-admission.js +0 -151
  155. package/lib/delivery-authority.d.ts +0 -83
  156. package/lib/delivery-authority.js +0 -397
  157. package/lib/native-child-evidence.d.ts +0 -40
  158. package/lib/native-child-evidence.js +0 -104
  159. package/lib/role-runs.d.ts +0 -138
  160. package/lib/role-runs.js +0 -335
  161. package/lib/session-persistence.d.ts +0 -36
  162. package/lib/session-persistence.js +0 -304
  163. package/lib/subagent-runtime.d.ts +0 -57
  164. package/lib/subagent-runtime.js +0 -257
  165. package/prompts/deepseek-flash.md +0 -11
  166. package/prompts/deepseek-v4-pro.md +0 -14
package/lib/index.js CHANGED
@@ -4,463 +4,177 @@ import { registerSafetyGuards } from "./guards.js";
4
4
  import { registerDeepworkPrompt } from "./mode.js";
5
5
  import { registerAgentSkills } from "./preset-skills.js";
6
6
  import { registerModelRouting } from "./model-routing.js";
7
- import { registerRuntimeRecovery } from "./runtime-recovery.js";
8
- import { reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
9
7
  import { registerHeadlessRoleTools, registerNativeSubagentControls } from "./role-subagents.js";
10
8
  import { registerRolePresets } from "./preset-registry.js";
11
9
  import { registerRoleProviders } from "./role-providers.js";
12
10
  import { DsmmRolePolicy } from "./role-policy.js";
13
- import { registerLspRuntime } from "./lsp.js";
14
11
  import { createProfileRuntime } from "./profile-runtime.js";
15
12
  import { DsmmProfilesHost, registerConfigRpc } from "./profile-rpc.js";
16
- import { DSMM_CONFIG_SCHEMA, DSMM_NATIVE_CONFIG_SCHEMA, registerSettings } from "./settings.js";
17
- import { DeepworkModeController, isDeepworkActive } from "./state.js";
18
- import DsmmSessionPersistence from "./session-persistence.js";
19
- import { isAbsolute } from "node:path";
20
- import { createHash, randomUUID } from "node:crypto";
21
- import { DsmmProfileError } from "./profiles.js";
13
+ import { DSMM_CONFIG_SCHEMA, DSMM_NATIVE_CONFIG_SCHEMA } from "./settings.js";
14
+ import { DeepworkModeController } from "./state.js";
22
15
  import { DsmmDeploymentConfig } from "./deployment-config.js";
23
- import { agentForScope } from "./native-scope.js";
24
- import { resolveSelectedAgentPreset, sessionEvents } from "./session-scope.js";
25
- import { projectDsmmModules } from "./modules.js";
26
- import { scopeLifetime } from "./delivery-authority.js";
27
- import { admittedAgentContext, assertSupportedHostStartup, classifyDsmmAgent, integrateSubagentRuntime, managedAgentContext, publicProfileRuntime, registerRoleControlContribution, registerRuntimeGuidance, runtimeAdmissionView } from "./runtime-integration.js";
16
+ import { NativeAdmission } from "./native-admission.js";
17
+ import { scopeLifetime } from "./lifetime.js";
18
+ import { runtimeAdmissionView, assertSupportedHostStartup } from "./runtime-integration.js";
28
19
  import { createCorePermissionAuthority } from "./core-permission-authority.js";
29
- import { nativeStandingFullAccess } from "./permission-native-access.js";
30
20
  import { installCorePermissions } from "./core-permissions.js";
21
+ import { registerRoleControlRpc } from "./role-control-rpc.js";
22
+ import { nativeStandingFullAccess } from "./permission-native-access.js";
23
+ import { DsmmProfileError } from "./profiles.js";
24
+ import { registerLspRuntime } from "./lsp.js";
31
25
  export const name = "dsmm";
32
26
  export const inject = ["profileContext", "agents"];
33
- // Direct public Config calls keep the complete plain flat ABI. Native Cordis
34
- // consumes the same object's Standard Schema protocol for sparse volatile refs.
35
- export const Config = new Proxy(DSMM_NATIVE_CONFIG_SCHEMA, {
36
- apply(_target, _receiver, args) { return DSMM_CONFIG_SCHEMA(args[0] ?? {}); }
37
- });
27
+ export const Config = new Proxy(DSMM_NATIVE_CONFIG_SCHEMA, { apply(_target, _receiver, args) { return DSMM_CONFIG_SCHEMA(args[0] ?? {}); } });
38
28
  export { DSMM_ROLE_IDS, DSMM_ROLES, isDsmmRoleId, renderAgentCordis, renderPresetMetadata } from "./roles.js";
39
29
  export { DSMM_MANAGED_PRESET_MARKER, materializeRolePresets, reconcileRolePresets, resolveManagedPresetRoot } from "./preset-materializer.js";
40
30
  export { DSMM_GUARD_PREFIX, decidePostToolExecution, decidePreToolExecution, isSafetyScopeActive, registerSafetyGuards, truncateTextMiddle } from "./guards.js";
41
31
  export { DEFAULT_DSMM_LSP_SETTINGS, DSMM_LSP_SERVER_NAME, DSMM_LSP_TOOL_NAMES, parseLspSmokeCommand, publicLspToolName, renderLspMcpPatch, resolveLspSettings, toDshMcpClientConfig } from "./lsp.js";
42
32
  export { classifyModelFamily } from "./model-family.js";
43
- export { desiredDeepseekEffort, isDeepseekV4ProRoute, registerModelRouting, selectAdvertisedEffort } from "./model-routing.js";
44
- export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
45
- export { registerRuntimeRecovery } from "./runtime-recovery.js";
33
+ export { registerModelRouting } from "./model-routing.js";
46
34
  export { childOwnedSessionEvents, resolveEffectiveDsmmRole, resolveSelectedAgentPreset } from "./session-scope.js";
47
35
  export { roleFromProviderName, roleProviderName, registerRoleProviders } from "./role-providers.js";
48
36
  export { effectiveRoleFallbackRoutes } from "./role-routing.js";
49
37
  export { DSMM_STATUS_COMMAND, registerDsmmStatusCommand } from "./commands.js";
50
38
  export { DSMM_STATUS_VERSION, createDsmmStatusSnapshot, formatDsmmStatus } from "./status.js";
51
- export { DSMM_SKILL_NAMES, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, isRoleEnabled, resolveConfig, resolveRoleRouting, registerSettings } from "./settings.js";
39
+ export { DSMM_SKILL_NAMES, DSMM_SETTINGS_SCHEMA, DEFAULT_DSMM_SETTINGS, MVP_SKILL_NAMES, deploymentEditorSchema, isRoleEnabled, resolveConfig, resolveDeployment, resolveRoleRouting, registerSettings, validateNativeConfig } from "./settings.js";
52
40
  export { createProfileRuntime, DsmmProfileRuntime } from "./profile-runtime.js";
53
41
  export { resolveDshHome } from "./dsh-home.js";
54
42
  export { DsmmDeploymentConfig, parseGlobalConfig, editGlobalConfig } from "./deployment-config.js";
55
43
  export { DSMM_MODULE_DESCRIPTORS, deepworkEnabled, projectDeepworkModule } from "./modules.js";
56
44
  export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
57
45
  export { DsmmNativeLlmRuntime } from "./llm-runtime.js";
58
- /** The current Host composition does not accept compatibility adapters. */
46
+ export { registerRuntimeRecovery } from "./runtime-recovery.js";
47
+ export { classifyRecoveryFailure, foldAttemptedRecoveryRoutes, foldDurableRecoveryWork, selectFallbackRoute } from "./recovery-policy.js";
59
48
  export function createDsmmHostPlugin(startup) {
60
49
  assertSupportedHostStartup(startup);
61
- return { name, Config, inject,
62
- apply(ctx, config = {}) { return apply(ctx, config, startup); } };
50
+ return { name, Config, inject, apply(ctx, config = {}) { return apply(ctx, config, startup); } };
63
51
  }
64
- export function apply(ctx, config = {}, hostStartup = {}) {
65
- assertSupportedHostStartup(hostStartup);
66
- if (!Context.is(ctx)) {
67
- return applyConfigured(ctx, config, undefined, undefined, hostStartup);
68
- }
52
+ export async function apply(input, config = {}, startupOptions = {}) {
53
+ assertSupportedHostStartup(startupOptions);
54
+ if (!Context.is(input))
55
+ throw new Error("DSMM requires the native Cordis Host");
56
+ const ctx = input;
69
57
  const deployment = new DsmmDeploymentConfig(ctx, config);
70
- return deployment.readDesired().then((startup) => applyConfigured(ctx, config, deployment, startup, hostStartup));
71
- }
72
- function applyConfigured(ctx, config, deployment, startup, hostStartup = {}) {
73
- // Volatile desired saves retain live realms. An ordinary Loader remount must
74
- // not replace already-admitted Agent policy/skill realms, including busy Agents.
75
- if (Context.is(ctx) && ctx.fiber.entry !== undefined) {
76
- const native = ctx;
77
- const owner = ctx.fiber.entry;
78
- native.on("loader/patch-context", (entry, next) => {
79
- if (entry === owner && (native.get("agents")?.list().length ?? 0) > 0) {
80
- throw new Error("dsmm deployment Config requires restart while Agents are admitted; runtime mode/profile changes use idle maintenance instead");
81
- }
82
- next();
83
- }, { global: true });
84
- }
85
- const storage = config.sessionPersistence;
86
- if (storage !== undefined) {
87
- if (storage === null || typeof storage !== "object" || typeof storage.root !== "string" || !isAbsolute(storage.root)
88
- || Object.keys(storage).some((key) => !["root", "compression"].includes(key))
89
- || storage.compression !== undefined && !["zstd", "none"].includes(storage.compression)) {
90
- throw new Error("Deepwork sessionPersistence must preserve an explicit absolute native root and compression");
91
- }
92
- if (!Context.is(ctx))
93
- throw new Error("Deepwork sessionPersistence requires a native Cordis Context");
94
- const native = ctx;
95
- if (native.get("sessionPersistence") !== undefined)
96
- throw new Error("Disable the exact existing JSONL entry at startup before enabling Deepwork sessionPersistence; live replacement is refused");
97
- const fiber = native.plugin(DsmmSessionPersistence, storage);
98
- return fiber.await().then(() => applyRuntime(ctx, config, deployment, startup, hostStartup));
99
- }
100
- return applyRuntime(ctx, config, deployment, startup, hostStartup);
101
- }
102
- function applyRuntime(ctx, config, deployment, startup, hostStartup = {}) {
103
- const native = Context.is(ctx) ? ctx : undefined;
104
58
  const lifetime = new AbortController();
105
- if (native !== undefined)
106
- scopeLifetime(native, "dsmm: revoke Core startup and admission", () => lifetime.abort());
59
+ scopeLifetime(ctx, "dsmm: retire Core", () => lifetime.abort());
60
+ // Install a startup execution fence before asynchronous configuration reads.
61
+ let admission;
62
+ const assert = (agent) => { lifetime.signal.throwIfAborted(); if (!admission)
63
+ throw new Error("DSMM initialization is incomplete"); return admission.assert(agent); };
64
+ ctx.on("agent/created", () => { lifetime.signal.throwIfAborted(); if (!admission?.isReady)
65
+ throw new Error("DSMM initialization is incomplete"); }, { global: true, prepend: true });
66
+ ctx.on("agent/pre-step", async (frame, next) => { await admission?.ensure(frame.agent); assert(frame.agent); return next(); }, { global: true, prepend: true });
67
+ ctx.on("agent/request", async (frame, next) => { await admission?.ensure(frame.agent); assert(frame.agent); return next(); }, { global: true, prepend: true });
68
+ ctx.on("tools/pre-execute", async (exec, next) => { if (exec.agent) {
69
+ await admission?.ensure(exec.agent);
70
+ assert(exec.agent);
71
+ } return next(); }, { global: true, prepend: true });
72
+ const startup = await deployment.readDesired();
73
+ lifetime.signal.throwIfAborted();
74
+ const getSettings = agent => agent === undefined ? startup.settings : admission.configuration(agent).settings;
75
+ getSettings.admission = agent => agent === undefined ? profiles.admission() : admission.configuration(agent);
76
+ getSettings.subagentRuntime = () => runtimeAdmissionView(ctx);
77
+ const controller = new DeepworkModeController(ctx, agent => getSettings(agent).modules.deepwork.enabled, () => admission?.isReady === true && ctx.get("subagents") !== undefined && ctx.get("agentPresets") !== undefined);
78
+ const policy = new DsmmRolePolicy(ctx, getSettings, controller);
107
79
  let permissionOwner;
108
- const getMountedPermission = () => {
109
- if (native === undefined || lifetime.signal.aborted)
110
- return null;
111
- const current = native.get("dsmmPermissionController");
112
- if (current === undefined || (Reflect.get(current, symbols.original) ?? current) !== permissionOwner)
80
+ const mountedPermission = () => {
81
+ if (lifetime.signal.aborted)
113
82
  return null;
114
- return current?.rules.status().mounted ?? null;
115
- };
116
- let rootAdmissionsInitialized = false;
117
- const completedRootAdmissions = new WeakSet();
118
- let rolePolicy;
119
- const controlledParent = (agent) => {
120
- if (classifyDsmmAgent(agent) === "dsmm")
121
- return true;
122
- if (agent.session.header?.origin === "subagent")
123
- return false;
124
- // A pending parent admission cannot establish native-child eligibility.
125
- if (!rootAdmissionsInitialized && !completedRootAdmissions.has(agent))
126
- return true;
127
- const settings = getBoundSettings(agent);
128
- return settings.modules.deepwork.enabled && isDeepworkActive(sessionEvents(agent.session), settings.defaultActive, resolveSelectedAgentPreset(agent.session));
129
- };
130
- if (native !== undefined) {
131
- ctx = managedAgentContext(native, controlledParent);
132
- }
133
- const validatingRootModule = new WeakMap();
134
- const controller = new DeepworkModeController(ctx, (agent) => validatingRootModule.get(agent) ?? getBoundSettings(agent).modules.deepwork.enabled);
135
- let runtime;
136
- let profileInitialization;
137
- let requiresNativeProfiles = ctx.get !== undefined;
138
- const requireProfileAdmission = (agent) => {
139
- if (agent !== undefined && requiresNativeProfiles && runtime === undefined) {
140
- throw new DsmmProfileError("unavailable", "Native Deepwork profile admission is not ready. No provider request or tool work is allowed.");
141
- }
142
- };
143
- const getBoundSettings = (agent) => {
144
- requireProfileAdmission(agent);
145
- return runtime?.getSettings(agent) ?? getSettings();
83
+ const current = ctx.get("dsmmPermissionController");
84
+ return current && (Reflect.get(current, symbols.original) ?? current) === permissionOwner ? current.rules.status().mounted : null;
146
85
  };
147
- const deploymentAdmissions = new WeakMap();
148
- getBoundSettings.admission = (agent) => {
149
- requireProfileAdmission(agent);
150
- const nativeAdmission = runtime?.getSettings.admission?.(agent);
151
- if (nativeAdmission !== undefined)
152
- return nativeAdmission;
153
- const settings = getSettings();
154
- let admission = deploymentAdmissions.get(settings);
155
- if (admission === undefined) {
156
- admission = Object.freeze({ settings, profile: null, scope: "deployment-baseline", epoch: createHash("sha256").update(randomUUID()).digest("hex") });
157
- deploymentAdmissions.set(settings, admission);
158
- }
159
- return admission;
160
- };
161
- getBoundSettings.moduleStates = (agent) => {
162
- requireProfileAdmission(agent);
163
- return runtime?.getSettings.moduleStates?.(agent) ?? projectDsmmModules(getSettings(), startup, getBoundSettings.admission(agent), false, getMountedPermission);
164
- };
165
- getBoundSettings.subagentRuntime = () => native === undefined
166
- ? { binding: "unavailable", deliveryFenceReady: false, restartRequired: true, reason: "explicit-composition-required" }
167
- : runtimeAdmissionView(native);
168
- rolePolicy = new DsmmRolePolicy(ctx, getBoundSettings, controller);
169
- const assertDwDelivery = (agent) => {
170
- if (rolePolicy.identity(agent).role === undefined)
171
- return;
172
- const integration = native?.get("dsmmRuntimeIntegration");
173
- if (integration === undefined || !integration.runtime.authority.view().deliveryFenceReady)
174
- throw new DsmmProfileError("unavailable", "Deepwork execution requires its live delivery fence.");
175
- return integration.bridge.authority.acquireParentTicket(agent);
176
- };
177
- const getSettings = registerSettings(ctx, config, {
178
- ...(startup === undefined ? {} : { resolved: startup.settings }),
179
- install(readyCtx, getReadySettings) {
180
- const startupMounted = getReadySettings().modules.deepwork.enabled;
181
- // The global editor belongs to core, not profile/DW installation success.
182
- if (deployment !== undefined) {
183
- readyCtx.provide?.("dsmmDeploymentConfig", deployment);
184
- readyCtx.inject?.(["typert"], (rpcCtx) => {
185
- registerConfigRpc(rpcCtx, deployment, getReadySettings(), () => runtime, startup?.sources, getMountedPermission);
186
- });
187
- }
188
- const install = (installCtx, settingsGetter) => {
189
- if (startupMounted) {
190
- registerDeepworkPrompt(installCtx, controller, settingsGetter, { section: startup === undefined ? config.section : startup.profile.section ?? startup.global.section });
191
- registerAgentSkills(installCtx, controller, settingsGetter);
192
- }
193
- const installCommands = (commandCtx) => {
194
- if (startupMounted)
195
- registerDeepworkCommand(commandCtx, controller, settingsGetter);
196
- // Status projects live substrate readiness without replacing the exact
197
- // immutable admission reference used by authority and providers.
198
- const statusSettings = Object.assign(((agent) => settingsGetter(agent)), settingsGetter);
199
- statusSettings.admission = agent => ({ ...getBoundSettings.admission(agent), subagentRuntime: getBoundSettings.subagentRuntime() });
200
- registerDsmmStatusCommand(commandCtx, controller, statusSettings);
201
- };
202
- if (installCtx.get !== undefined && installCtx.inject !== undefined)
203
- installCtx.inject(["commands"], installCommands);
204
- else
205
- installCommands(installCtx);
206
- if (!startupMounted)
86
+ const profiles = await createProfileRuntime(ctx, startup.settings, { startup, readDesired: () => deployment.readDesired(), modeController: controller,
87
+ runtimeView: () => runtimeAdmissionView(ctx), getMountedPermission: mountedPermission });
88
+ lifetime.signal.throwIfAborted();
89
+ admission = new NativeAdmission(ctx, profiles, policy);
90
+ ctx.provide("dsmmNativeAdmission", admission);
91
+ ctx.provide("dsmmProfileRuntime", profiles);
92
+ ctx.provide("dsmmDeploymentConfig", deployment);
93
+ ctx.provide("dsmmCoreLlmOwner", { async admit(frame) {
94
+ const captured = assert(frame.agent), full = nativeStandingFullAccess(ctx, frame.agent);
95
+ const permissions = ctx.get("dsmmPermissionController");
96
+ if (!full && captured.settings.permissionControl.enabled && permissions === undefined)
97
+ throw new DsmmProfileError("unavailable", "Core permission authority is not ready.");
98
+ if (!full)
99
+ await permissions?.rules.refresh();
100
+ const permissionIdentity = permissions === undefined ? undefined : Reflect.get(permissions, symbols.original) ?? permissions;
101
+ const permissionRevision = full ? undefined : permissions?.rules.getPolicy().revision;
102
+ const permissionSignal = full ? undefined : permissions?.rules.signal;
103
+ const signal = AbortSignal.any([frame.signal, lifetime.signal, ...permissionSignal === undefined ? [] : [permissionSignal]]);
104
+ const assertCurrent = () => {
105
+ signal.throwIfAborted();
106
+ if (assert(frame.agent) !== captured)
107
+ throw new DsmmProfileError("not-owned", "Native admission changed.");
108
+ if (full)
207
109
  return;
208
- // Standing compositions are deployment-only and never replaced on a
209
- // runtime profile selection. All routes are read from Agent bindings.
210
- const settings = getReadySettings();
211
- const root = resolveManagedPresetRoot(settings, deployment === undefined ? process.env : { ...process.env, DSH_HOME: deployment.home });
212
- if (root !== undefined)
213
- reconcileRolePresets({ root, settings });
214
- };
215
- if (readyCtx.get === undefined) {
216
- registerRolePresets(readyCtx, getReadySettings);
217
- install(readyCtx, getReadySettings);
218
- if (startupMounted)
219
- registerRoleProviders(readyCtx, getReadySettings, getReadySettings, rolePolicy);
220
- return;
221
- }
222
- requiresNativeProfiles = true;
223
- const installProfiles = async (profileCtx) => {
224
- if (native === undefined)
225
- throw new Error("dsmm native profiles require the actual Cordis Host scope");
226
- const hostCtx = profileCtx;
227
- profileCtx = managedAgentContext(hostCtx, controlledParent);
228
- if (startupMounted) {
229
- await registerLspRuntime(profileCtx, { ...getReadySettings().lsp, enabled: false }, getBoundSettings);
230
- }
231
- // Standing definitions must exist before initialize audits retained
232
- // Agents. A missing optional registry still installs later from this
233
- // same frozen startup getter, without blocking unrelated Hosts.
234
- const presets = registerRolePresets(profileCtx, getReadySettings);
235
- if (profileCtx.get?.("agentPresets") !== undefined)
236
- await presets;
237
- const integration = await integrateSubagentRuntime(hostCtx, getReadySettings(), rolePolicy, () => runtime, hostStartup);
238
- lifetime.signal.throwIfAborted();
239
- if (startupMounted && hostCtx.get("subagents") !== undefined) {
240
- // The actual registry exists now. Alias registration is synchronous and
241
- // does not wait on a policy-ready provider, avoiding a startup cycle.
242
- registerRoleProviders({ get: hostCtx.get.bind(hostCtx), effect: callback => hostCtx.effect(() => callback() ?? (() => { })) }, getBoundSettings, getReadySettings, rolePolicy);
243
- }
244
- const retainedChildren = profileCtx.get("agents").list().filter(agent => agent.session.header?.origin === "subagent");
245
- const manager = await createProfileRuntime(profileCtx, getReadySettings(), { modeController: controller,
246
- getMountedPermission, deferRetainedChildren: integration !== undefined,
247
- ...(startup === undefined ? {} : { startup }), ...(deployment === undefined ? {} : { readDesired: () => deployment.readDesired() }),
248
- ...(integration === undefined ? {} : { childAuthority: integration.bridge.authority, childAuthorityOwner: integration.owner,
249
- childAdmission: integration.bridge.childAdmission, childCapturePersistence: "durable" }),
250
- validateRootRole: (agent, admission) => {
251
- // Candidate identity validation precedes publication. Its mode check
252
- // must not recursively demand the not-yet-bound live admission.
253
- validatingRootModule.set(agent, admission.settings.modules.deepwork.enabled);
254
- try {
255
- rolePolicy.validateRootRole(agent, admission);
256
- }
257
- finally {
258
- validatingRootModule.delete(agent);
259
- }
260
- },
261
- onAdmissionGuardsInstalled: async (initializing) => {
262
- runtime = initializing;
263
- integration?.onAdmissionGuardsInstalled();
264
- // Native descendants are filtered from their direct parent's actual
265
- // admission, including a preselected named profile, not startup mode.
266
- for (const root of hostCtx.agents.roots()) {
267
- const agent = root;
268
- await initializing.completeAdmission(agent, undefined, startup);
269
- completedRootAdmissions.add(agent);
270
- }
271
- rootAdmissionsInitialized = true;
272
- },
273
- subagentCapabilities: {
274
- backgroundJobs: profileCtx.get?.("jobs") !== undefined,
275
- continuable: profileCtx.get?.("sessionPersistence") !== undefined && profileCtx.get?.("sessionQuery") !== undefined
276
- && profileCtx.get?.("subagents")?.getProvider("spawn")?.prepareContinuable !== undefined
277
- } });
278
- runtime = manager;
279
- lifetime.signal.throwIfAborted();
280
- // Retained controlled children enroll only after their awaited admission
281
- // in the Core-dependent continuation; ordinary Core startup stays independent.
282
- const admittedCtx = admittedAgentContext(profileCtx, manager);
283
- install(admittedCtx, getBoundSettings);
284
- registerRuntimeGuidance(admittedCtx, getBoundSettings, rolePolicy);
285
- const published = publicProfileRuntime(manager, hostCtx);
286
- profileCtx.provide?.("dsmmProfileRuntime", published);
287
- if (integration !== undefined) {
288
- hostCtx.provide("dsmmRuntimeIntegration", integration);
289
- hostCtx.inject(["dsmmCoreLlmOwner"], async (continuationCtx) => {
290
- const continuation = new AbortController();
291
- scopeLifetime(continuationCtx, "dsmm: cancel DW startup continuation", () => continuation.abort());
292
- return integration.continueStartup(async (signal) => {
293
- const visited = new Set();
294
- const admit = async (agent) => {
295
- signal.throwIfAborted();
296
- lifetime.signal.throwIfAborted();
297
- if (visited.has(agent))
298
- return;
299
- visited.add(agent);
300
- const parent = hostCtx.agents.list().find(parent => parent !== agent && hostCtx.agents.isOwnedBy(agent.id, parent));
301
- if (parent !== undefined)
302
- await admit(parent);
303
- if (parent !== undefined && classifyDsmmAgent(agent) === "native" && !controlledParent(parent))
304
- return;
305
- await manager.completeAdmission(agent, signal, startup);
306
- };
307
- for (const agent of retainedChildren)
308
- if (hostCtx.agents.get(agent.id) === agent)
309
- await admit(agent);
310
- signal.throwIfAborted();
311
- lifetime.signal.throwIfAborted();
312
- await registerNativeSubagentControls(profileCtx);
313
- signal.throwIfAborted();
314
- lifetime.signal.throwIfAborted();
315
- await registerHeadlessRoleTools(admittedAgentContext(profileCtx, manager), controller, getBoundSettings, rolePolicy, integration);
316
- signal.throwIfAborted();
317
- lifetime.signal.throwIfAborted();
318
- hostCtx.inject(["typert", "subagents"], scope => integration.registerControls(scope));
319
- }, AbortSignal.any([lifetime.signal, continuation.signal]));
320
- });
110
+ const current = ctx.get("dsmmPermissionController");
111
+ if ((current === undefined ? undefined : Reflect.get(current, symbols.original) ?? current) !== permissionIdentity
112
+ || current?.rules.getPolicy().revision !== permissionRevision || current?.rules.signal !== permissionSignal) {
113
+ throw new DsmmProfileError("not-owned", "Core permission authority changed.");
321
114
  }
322
- else
323
- registerRoleControlContribution(hostCtx);
324
- profileCtx.inject?.(["typert"], (rpcCtx) => {
325
- new DsmmProfilesHost(rpcCtx, published);
326
- });
327
115
  };
328
- if (readyCtx.inject !== undefined) {
329
- profileInitialization = new Promise((resolve, reject) => {
330
- const fiber = readyCtx.inject(["profileContext"], async (profileCtx) => {
331
- try {
332
- await installProfiles(profileCtx);
333
- resolve();
334
- }
335
- catch (error) {
336
- reject(error);
337
- }
338
- });
339
- scopeLifetime(fiber.ctx, "dsmm: cancel Core profile initialization", () => reject(new DsmmProfileError("unavailable", "Core profile initialization was disposed.")));
340
- });
341
- }
342
- else
343
- throw new Error("dsmm native profiles require asynchronous profileContext injection");
116
+ assertCurrent();
117
+ return Object.freeze({ agent: frame.agent, admission: captured, capture: captured, epoch: captured.epoch, signal, assertCurrent });
118
+ } });
119
+ const nativeAdmission = admission;
120
+ if (startup.settings.modules.deepwork.enabled) {
121
+ const presets = ctx.inject(["agentPresets"], async (scope) => {
122
+ await registerRolePresets(scope, () => startup.settings);
123
+ const providers = scope.inject(["subagents"], async (runtimeScope) => {
124
+ registerRoleProviders(runtimeScope, () => startup.settings, nativeAdmission);
125
+ await registerNativeSubagentControls(runtimeScope);
126
+ });
127
+ if (scope.get("subagents") !== undefined)
128
+ await providers.await();
129
+ });
130
+ if (ctx.get("agentPresets") !== undefined)
131
+ await presets.await();
132
+ }
133
+ if (startup.settings.modules.deepwork.enabled)
134
+ await registerLspRuntime(ctx, startup.settings.lsp, getSettings);
135
+ lifetime.signal.throwIfAborted();
136
+ const installed = new WeakSet();
137
+ admission.activate(async (agent, candidate) => {
138
+ candidate.subagentRuntime = () => runtimeAdmissionView(ctx);
139
+ const scope = agent.ctx;
140
+ if (candidate().modules.deepwork.enabled) {
141
+ registerAgentSkills(scope, controller, candidate, agent, admission.lifetime.signal);
142
+ registerDeepworkPrompt(scope, controller, candidate, { section: startup.profile.section ?? startup.global.section }, agent, admission.lifetime.signal);
344
143
  }
144
+ if (installed.has(agent)) {
145
+ if (candidate().modules.deepwork.enabled && ctx.get("subagents") !== undefined)
146
+ await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
147
+ return;
148
+ }
149
+ registerModelRouting(scope, controller, candidate);
150
+ registerSafetyGuards(scope, controller, candidate, policy);
151
+ if (candidate().modules.deepwork.enabled) {
152
+ if (ctx.get("subagents") !== undefined)
153
+ await registerHeadlessRoleTools(scope, controller, candidate, policy, nativeAdmission, agent);
154
+ }
155
+ installed.add(agent);
345
156
  });
346
- if (getSettings().modules.deepwork.enabled) {
347
- registerRuntimeRecovery(ctx, controller, getBoundSettings);
348
- registerModelRouting(ctx, controller, getBoundSettings);
349
- }
350
- if (ctx.get !== undefined) {
351
- ctx.on?.("system-prompt/assemble", async (_assembly, options, next) => {
352
- const agent = agentForScope(ctx, options.scope);
353
- if (agent !== undefined) {
354
- await native?.get("dsmmRuntimeIntegration")?.runtime.authority.waitForPromotion(agent, options.signal);
355
- rolePolicy.assertModuleAdmission(agent);
356
- assertDwDelivery(agent);
357
- }
358
- return next();
359
- }, { prepend: true, global: true });
360
- ctx.on?.("agent/request", async (frame, next) => {
361
- await native?.get("dsmmRuntimeIntegration")?.runtime.authority.waitForPromotion(frame.agent, frame.signal);
362
- rolePolicy.assertModuleAdmission(frame.agent);
363
- assertDwDelivery(frame.agent);
364
- return next();
365
- }, { prepend: true, global: true });
366
- ctx.on?.("tools/execute", async (exec, next) => {
367
- if (exec.agent === undefined)
368
- return next();
369
- return rolePolicy.duringToolExecution(exec, next);
370
- }, { global: true });
371
- }
372
- registerSafetyGuards(ctx, controller, getBoundSettings, ctx.get === undefined ? undefined : rolePolicy);
373
- if (native === undefined)
374
- return profileInitialization;
375
- native.inject(["tools"], scope => {
376
- managedAgentContext(scope, controlledParent).on("tools/pre-execute", (exec, next) => rolePolicy.beforeToolDecision(async () => {
377
- if (exec.agent !== undefined && !nativeStandingFullAccess(scope, exec.agent)) {
378
- rolePolicy.assertModuleAdmission(exec.agent);
379
- assertDwDelivery(exec.agent);
380
- }
381
- return next();
382
- }), { prepend: true, global: true });
383
- managedAgentContext(scope, controlledParent).get("tools").guard(exec => {
384
- rolePolicy.assertToolExecution(exec);
385
- });
157
+ ctx.inject(["commands"], scope => {
158
+ registerDsmmStatusCommand(scope, controller, getSettings);
159
+ if (startup.settings.modules.deepwork.enabled)
160
+ registerDeepworkCommand(scope, controller, getSettings);
386
161
  });
387
- if (deployment !== undefined) {
388
- const permissions = createCorePermissionAuthority(native, { getSettings: getBoundSettings, rolePolicy, signal: lifetime.signal });
389
- native.inject(["tools"], scope => {
390
- const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable);
391
- const identity = Reflect.get(installed, symbols.original) ?? installed;
392
- scopeLifetime(scope, "dsmm: release mounted permission projection", () => { if (permissionOwner === identity)
393
- permissionOwner = undefined; }, () => { permissionOwner = identity; });
394
- });
395
- }
396
- return Promise.resolve(profileInitialization).then(() => {
397
- lifetime.signal.throwIfAborted();
398
- const owner = { async admit(frame) {
399
- const agent = frame.agent;
400
- frame.signal.throwIfAborted();
401
- lifetime.signal.throwIfAborted();
402
- if (frame.agent.session.header.origin === "subagent" && classifyDsmmAgent(frame.agent) === "native") {
403
- const registry = native.agents;
404
- const parents = registry.list().filter(parent => parent !== frame.agent && registry.isOwnedBy(frame.agent.id, parent));
405
- if (registry.get(frame.agent.id) !== frame.agent || parents.length !== 1
406
- || frame.agent.session.header.parentSession !== parents[0].id)
407
- throw new DsmmProfileError("not-owned", "The native child lost its physical owner.");
408
- if (!controlledParent(parents[0]))
409
- return undefined;
410
- }
411
- rolePolicy.assertModuleAdmission(agent);
412
- const admission = getBoundSettings.admission(agent);
413
- const permissions = native.get("dsmmPermissionController");
414
- const full = nativeStandingFullAccess(native, frame.agent);
415
- if (!full && admission.settings.permissionControl.enabled && permissions === undefined)
416
- throw new DsmmProfileError("unavailable", "Core permission authority is not ready.");
417
- if (!full)
418
- await permissions?.rules.refresh();
419
- frame.signal.throwIfAborted();
420
- lifetime.signal.throwIfAborted();
421
- const permissionIdentity = permissions === undefined ? undefined : Reflect.get(permissions, symbols.original) ?? permissions;
422
- const permissionRevision = full ? undefined : permissions?.rules.getPolicy().revision;
423
- const permissionSignal = full ? undefined : permissions?.rules.signal;
424
- const bindPermission = (captured) => {
425
- if (full)
426
- return captured;
427
- const signal = AbortSignal.any([captured.signal, ...permissionSignal === undefined ? [] : [permissionSignal]]);
428
- const assertCurrent = () => {
429
- signal.throwIfAborted();
430
- captured.assertCurrent();
431
- const current = native.get("dsmmPermissionController");
432
- if ((current === undefined ? undefined : Reflect.get(current, symbols.original) ?? current) !== permissionIdentity
433
- || current?.rules.getPolicy().revision !== permissionRevision
434
- || current?.rules.signal !== permissionSignal)
435
- throw new DsmmProfileError("not-owned", "LLM permission revision changed.");
436
- };
437
- assertCurrent();
438
- return Object.freeze({ ...captured, signal, assertCurrent });
439
- };
440
- if (rolePolicy.identity(agent).role !== undefined) {
441
- const integration = native.get("dsmmRuntimeIntegration");
442
- if (integration?.runtime.authority.view().deliveryFenceReady !== true)
443
- throw new DsmmProfileError("unavailable", "Deepwork requests require the live delivery fence.");
444
- const admitted = await integration.admitLlmRequest(frame.agent, frame.signal);
445
- if (admitted === undefined)
446
- throw new DsmmProfileError("not-owned", "Deepwork request lost its role admission.");
447
- return bindPermission(admitted);
448
- }
449
- const signal = AbortSignal.any([frame.signal, lifetime.signal]);
450
- const assertCurrent = () => {
451
- signal.throwIfAborted();
452
- rolePolicy.assertModuleAdmission(agent);
453
- if (native.get("dsmmCoreLlmOwner") !== owner || getBoundSettings.admission(agent) !== admission)
454
- throw new DsmmProfileError("not-owned", "Core LLM admission changed.");
455
- };
456
- assertCurrent();
457
- return bindPermission(Object.freeze({ agent: frame.agent, admission, capture: admission, epoch: admission.epoch, signal, assertCurrent }));
458
- } };
459
- native.provide("dsmmCoreLlmOwner", owner);
162
+ ctx.inject(["typert"], scope => { registerConfigRpc(scope, deployment, startup.settings, () => profiles, startup.sources, mountedPermission); new DsmmProfilesHost(scope, profiles); registerRoleControlRpc(scope, nativeAdmission); });
163
+ const permissions = createCorePermissionAuthority(ctx, { getSettings, rolePolicy: policy, signal: lifetime.signal });
164
+ const installPermissions = () => ctx.inject(["tools", ...(ctx.fiber.entry === undefined ? [] : ["settings"])], scope => {
165
+ const installed = installCorePermissions(scope, deployment, permissions.authority, permissions.assertWritable);
166
+ const identity = Reflect.get(installed, symbols.original) ?? installed;
167
+ scopeLifetime(scope, "dsmm: release permission projection", () => { if (permissionOwner === identity)
168
+ permissionOwner = undefined; }, () => { permissionOwner = identity; });
460
169
  });
170
+ if (ctx.fiber.entry === undefined || ctx.fiber.state === 2)
171
+ installPermissions();
172
+ else {
173
+ const owner = ctx.fiber.ctx;
174
+ const detach = ctx.on("internal/status", fiber => { if (fiber.ctx !== owner || fiber.state !== 2)
175
+ return; detach(); if (!lifetime.signal.aborted)
176
+ installPermissions(); }, { global: true });
177
+ }
461
178
  }
462
- // Cordis Loader introspects this object's Config/inject; a bare function loses
463
- // the exported schema and may pass null where required DSMM defaults belong.
464
- // Method-form apply keeps Cordis on its awaited callback, not constructor, path.
465
- export default { name, inject, Config, apply(ctx, config = {}) { return apply(ctx, config); } };
179
+ export default { name, inject, Config, apply };
466
180
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ /** Revoke synchronously when an owning scope begins unloading, before async cleanup. */
3
+ export declare function scopeLifetime(scope: Context, label: string, revoke: () => void, install?: () => void): () => void;
4
+ //# sourceMappingURL=lifetime.d.ts.map
@@ -0,0 +1,22 @@
1
+ /** Revoke synchronously when an owning scope begins unloading, before async cleanup. */
2
+ export function scopeLifetime(scope, label, revoke, install = () => { }) {
3
+ return scope.effect(() => {
4
+ const owners = new Map();
5
+ for (let fiber = scope.fiber; !owners.has(fiber.ctx); fiber = fiber.parent.fiber)
6
+ owners.set(fiber.ctx, fiber);
7
+ const retired = () => [...owners.values()].some(fiber => fiber.uid === null || fiber.state === 4 || fiber.state === 5);
8
+ const plugin = scope.on("internal/plugin", fiber => { if (owners.has(fiber.ctx) && retired())
9
+ revoke(); }, { global: true, prepend: true });
10
+ const status = scope.on("internal/status", fiber => { if (owners.has(fiber.ctx) && retired())
11
+ revoke(); }, { global: true, prepend: true });
12
+ if (retired()) {
13
+ plugin();
14
+ status();
15
+ revoke();
16
+ throw new Error("DSMM owner is retired");
17
+ }
18
+ install();
19
+ return () => { plugin(); status(); revoke(); };
20
+ }, label);
21
+ }
22
+ //# sourceMappingURL=lifetime.js.map