@dsmm/dsmm 0.2.2 → 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 (182) hide show
  1. package/README.md +26 -42
  2. package/cordis.patch.yml +1 -0
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +20 -79
  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 -240
  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 +16 -2
  20. package/lib/child-capture.js +29 -10
  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 +26 -51
  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 +85 -25
  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 +2716 -2364
  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 +17 -21
  82. package/lib/index.js +131 -430
  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/permission-rpc.js +3 -3
  97. package/lib/preset-registry.js +3 -2
  98. package/lib/preset-skills.d.ts +3 -12
  99. package/lib/preset-skills.js +28 -58
  100. package/lib/profile-diagnostics.d.ts +1 -1
  101. package/lib/profile-diagnostics.js +2 -2
  102. package/lib/profile-remote.js +61 -22
  103. package/lib/profile-rpc.d.ts +4 -3
  104. package/lib/profile-rpc.js +39 -41
  105. package/lib/profile-runtime.d.ts +31 -74
  106. package/lib/profile-runtime.js +224 -639
  107. package/lib/profile-store.d.ts +18 -6
  108. package/lib/profile-store.js +106 -64
  109. package/lib/profile-types.d.ts +18 -4
  110. package/lib/profiles.d.ts +3 -1
  111. package/lib/profiles.js +9 -7
  112. package/lib/prompt-content.d.ts +1 -0
  113. package/lib/prompt-content.js +4 -1
  114. package/lib/prompts.d.ts +2 -12
  115. package/lib/prompts.js +11 -66
  116. package/lib/role-control-remote.d.ts +1 -4
  117. package/lib/role-control-remote.js +8 -36
  118. package/lib/role-control-rpc.d.ts +10 -36
  119. package/lib/role-control-rpc.js +112 -265
  120. package/lib/role-control-types.d.ts +3 -26
  121. package/lib/role-control-types.js +3 -4
  122. package/lib/role-identity.d.ts +5 -0
  123. package/lib/role-identity.js +10 -0
  124. package/lib/role-invocation.d.ts +2 -2
  125. package/lib/role-llm-runtime.js +5 -11
  126. package/lib/role-policy.d.ts +19 -53
  127. package/lib/role-policy.js +136 -525
  128. package/lib/role-providers.d.ts +5 -8
  129. package/lib/role-providers.js +20 -126
  130. package/lib/role-routing.d.ts +1 -3
  131. package/lib/role-routing.js +24 -34
  132. package/lib/role-subagents.d.ts +5 -14
  133. package/lib/role-subagents.js +149 -97
  134. package/lib/runtime-integration.d.ts +5 -109
  135. package/lib/runtime-integration.js +11 -779
  136. package/lib/session-metadata.d.ts +13 -12
  137. package/lib/session-metadata.js +6 -31
  138. package/lib/session-scope.js +6 -2
  139. package/lib/settings.d.ts +5 -18
  140. package/lib/settings.js +19 -43
  141. package/lib/state.d.ts +3 -2
  142. package/lib/state.js +26 -10
  143. package/lib/status.d.ts +1 -9
  144. package/lib/status.js +3 -55
  145. package/lib/web-fetch-address-policy.d.ts +24 -0
  146. package/lib/web-fetch-address-policy.js +189 -0
  147. package/lib/web-fetch-fakeip.d.ts +25 -0
  148. package/lib/web-fetch-fakeip.js +107 -0
  149. package/package.json +133 -113
  150. package/docs/research/deepseek-v4-pro.md +0 -74
  151. package/docs/research/oh-dsh.md +0 -96
  152. package/lib/child-admission.d.ts +0 -42
  153. package/lib/child-admission.js +0 -162
  154. package/lib/delivery-authority.d.ts +0 -68
  155. package/lib/delivery-authority.js +0 -260
  156. package/lib/legacy-child-policy.d.ts +0 -51
  157. package/lib/legacy-child-policy.js +0 -123
  158. package/lib/legacy-read-composition.d.ts +0 -20
  159. package/lib/legacy-read-composition.js +0 -144
  160. package/lib/legacy-read-contracts.d.ts +0 -157
  161. package/lib/legacy-read-contracts.js +0 -39
  162. package/lib/legacy-read-host.d.ts +0 -19
  163. package/lib/legacy-read-host.js +0 -67
  164. package/lib/legacy-read-integration.d.ts +0 -121
  165. package/lib/legacy-read-integration.js +0 -522
  166. package/lib/legacy-read-proxy.d.ts +0 -26
  167. package/lib/legacy-read-proxy.js +0 -237
  168. package/lib/native-child-evidence.d.ts +0 -42
  169. package/lib/native-child-evidence.js +0 -133
  170. package/lib/role-runs.d.ts +0 -135
  171. package/lib/role-runs.js +0 -304
  172. package/lib/session-persistence.d.ts +0 -35
  173. package/lib/session-persistence.js +0 -304
  174. package/lib/subagent-runtime.d.ts +0 -45
  175. package/lib/subagent-runtime.js +0 -131
  176. package/prompts/deepseek-flash.md +0 -11
  177. package/prompts/deepseek-v4-pro.md +0 -14
  178. package/scripts/cold-profile-composition.mjs +0 -329
  179. package/scripts/cold-profile-sources.mjs +0 -238
  180. package/scripts/migrate-cold-profile.mjs +0 -315
  181. package/scripts/repair-session-log.mjs +0 -476
  182. package/scripts/session-repair-native-verifier.mjs +0 -367
@@ -1,45 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import type { ContentBlock, MessageId } from "@deepseek-ai/dsh-llm";
4
- import type { SessionId } from "@deepseek-ai/dsh-session";
5
- import { SubagentRuntime } from "@deepseek-ai/dsh-subagent";
6
- import type { SubagentPromptReceipt, SubagentPromptRequest, SubagentProvider, SubagentSendMessageOptions } from "@deepseek-ai/dsh-subagent";
7
- import { DsmmDeliveryAuthority } from "./delivery-authority.js";
8
- import type { DeliveryAdmission, DeliveryParentClassifier } from "./delivery-authority.js";
9
- export { DsmmDeliveryAuthority } from "./delivery-authority.js";
10
- export type { DeliveryAdmission, DeliveryFenceView, DeliveryParentClassifier, DeliveryPolicyBinding, ParentAdmissionTicket } from "./delivery-authority.js";
11
- declare module "@deepseek-ai/dsh-typert-protocol/types" {
12
- interface RemoteErrorDetailsMap {
13
- "subagent/unauthorized": {
14
- readonly childSessionId: SessionId;
15
- };
16
- }
17
- }
18
- type ContinuableStart = SubagentRuntime["startContinuable"];
19
- type ContinuablePreflight = (spec: Parameters<ContinuableStart>[0], start: ContinuableStart) => ReturnType<ContinuableStart>;
20
- /** Explicit startup replacement for the stock row, in the SAME Host service scope. */
21
- export declare class DsmmSubagentRuntime<A extends DeliveryAdmission = DeliveryAdmission, E = unknown> extends SubagentRuntime {
22
- readonly authority: DsmmDeliveryAuthority<A, E>;
23
- private readonly waiters;
24
- private readonly lifetime;
25
- private requiredProviders;
26
- private continuablePreflight?;
27
- constructor(ctx: Context, config: ConstructorParameters<typeof SubagentRuntime>[1], hostClassifier?: DeliveryParentClassifier);
28
- /** Host composition may select spawn/fork names before enabling the policy. */
29
- requireProviders(names: readonly string[]): void;
30
- registerProvider(provider: SubagentProvider): () => void;
31
- /** Host entry route preparation before native normalization loses caller option provenance. */
32
- configureContinuablePreflight(preflight: ContinuablePreflight, signal: AbortSignal): void;
33
- startContinuable(spec: Parameters<ContinuableStart>[0]): ReturnType<ContinuableStart>;
34
- /** Fulfillment proves this exact registry contains the provider, not just a mounted plugin. */
35
- waitForProvider(name: string, signal?: AbortSignal): Promise<SubagentProvider>;
36
- /** Policy explicitly enabled AND every required provider actually registered. */
37
- waitUntilReady(signal?: AbortSignal): Promise<void>;
38
- sendMessage(sender: Agent, targetId: SessionId, content: ContentBlock[], options: SubagentSendMessageOptions): Promise<MessageId>;
39
- prompt(request: SubagentPromptRequest, callerSignal: AbortSignal): Promise<SubagentPromptReceipt>;
40
- private wakeWaiters;
41
- private substrateReady;
42
- private waitFor;
43
- }
44
- export default DsmmSubagentRuntime;
45
- //# sourceMappingURL=subagent-runtime.d.ts.map
@@ -1,131 +0,0 @@
1
- import { SubagentError, SubagentRuntime } from "@deepseek-ai/dsh-subagent";
2
- import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
3
- import { TYPERT as NATIVE_SUBAGENT_HOST } from "@deepseek-ai/dsh-subagent/typert";
4
- import { DsmmDeliveryAuthority, scopeLifetime } from "./delivery-authority.js";
5
- export { DsmmDeliveryAuthority } from "./delivery-authority.js";
6
- /** Explicit startup replacement for the stock row, in the SAME Host service scope. */
7
- export class DsmmSubagentRuntime extends SubagentRuntime {
8
- authority;
9
- waiters = new Set();
10
- lifetime = new AbortController();
11
- requiredProviders = ["spawn"];
12
- continuablePreflight;
13
- constructor(ctx, config, hostClassifier) {
14
- if (ctx.get("subagents") !== undefined) {
15
- throw new SubagentError("Explicit DSMM startup composition must exclude the stock subagents row; restart with one provider.", "DUPLICATE_PROVIDER");
16
- }
17
- super(ctx, config);
18
- this.authority = new DsmmDeliveryAuthority(ctx, () => this.substrateReady(), () => this.wakeWaiters(), hostClassifier);
19
- ctx.inject(["typert"], (remoteCtx) => {
20
- if (remoteCtx.typert.getPackage("@deepseek-ai/dsh-subagent", "host") === undefined) {
21
- remoteCtx.typert.register(NATIVE_SUBAGENT_HOST);
22
- }
23
- this.wakeWaiters();
24
- });
25
- ctx.on("subagent/provider-added", () => this.wakeWaiters());
26
- ctx.on("subagent/provider-removed", () => this.wakeWaiters());
27
- scopeLifetime(ctx, "dsmm.subagents: close registration barriers", () => { this.lifetime.abort(); this.wakeWaiters(); });
28
- }
29
- /** Host composition may select spawn/fork names before enabling the policy. */
30
- requireProviders(names) {
31
- if (this.authority.view().deliveryFenceReady || names.length === 0 || names.some((name) => name.length === 0)) {
32
- throw new SubagentError("Provider readiness must be configured before DSMM admission becomes ready.", "UNAUTHORIZED");
33
- }
34
- this.requiredProviders = [...new Set(names)];
35
- this.wakeWaiters();
36
- }
37
- registerProvider(provider) {
38
- const dispose = super.registerProvider(provider);
39
- this.wakeWaiters();
40
- return dispose;
41
- }
42
- /** Host entry route preparation before native normalization loses caller option provenance. */
43
- configureContinuablePreflight(preflight, signal) {
44
- signal.throwIfAborted();
45
- if (this.continuablePreflight !== undefined)
46
- throw new SubagentError("Continuable routing already has a Host owner", "UNAUTHORIZED");
47
- this.continuablePreflight = preflight;
48
- signal.addEventListener("abort", () => { if (this.continuablePreflight === preflight)
49
- this.continuablePreflight = undefined; }, { once: true });
50
- }
51
- startContinuable(spec) {
52
- const start = request => super.startContinuable(request);
53
- return this.continuablePreflight === undefined ? start(spec) : this.continuablePreflight(spec, start);
54
- }
55
- /** Fulfillment proves this exact registry contains the provider, not just a mounted plugin. */
56
- waitForProvider(name, signal) {
57
- return this.waitFor(() => this.getProvider(name), signal);
58
- }
59
- /** Policy explicitly enabled AND every required provider actually registered. */
60
- waitUntilReady(signal) {
61
- return this.waitFor(() => this.authority.view().deliveryFenceReady ? true : undefined, signal).then(() => { });
62
- }
63
- async sendMessage(sender, targetId, content, options) {
64
- // The SDK alone validates exact residency and adjacency on child -> parent.
65
- if (sender.session.header.parentSession === targetId || !this.authority.isManaged(sender)) {
66
- return super.sendMessage(sender, targetId, content, options);
67
- }
68
- const ticket = this.authority.acquireParentTicket(sender);
69
- const signal = AbortSignal.any([options.signal, ticket.signal]);
70
- const evidence = await this.authority.resolveChildEvidence(ticket, targetId, signal);
71
- this.authority.assertDelivery(ticket, targetId, evidence);
72
- signal.throwIfAborted();
73
- return super.sendMessage(sender, targetId, content, { ...options, signal });
74
- }
75
- async prompt(request, callerSignal) {
76
- const parent = this.ctx.get("agents")?.get(request.parentSessionId);
77
- if (parent === undefined || !this.authority.isManaged(parent))
78
- return super.prompt(request, callerSignal);
79
- let signal = callerSignal;
80
- try {
81
- const ticket = this.authority.acquireParentTicket(parent);
82
- signal = AbortSignal.any([callerSignal, ticket.signal, this.authority.acquireBrowserSignal(this.ctx)]);
83
- const evidence = await this.authority.resolveChildEvidence(ticket, request.childSessionId, signal);
84
- this.authority.assertDelivery(ticket, request.childSessionId, evidence);
85
- signal.throwIfAborted();
86
- }
87
- catch (error) {
88
- // Match the native public prompt error boundary, without relabeling success.
89
- if (signal.aborted)
90
- throw new RemoteError("gateway/cancelled", "Subagent prompt was cancelled.", {}, { cause: error });
91
- if (error instanceof SubagentError && error.code === "UNAUTHORIZED") {
92
- throw new RemoteError("subagent/unauthorized", "Subagent delivery was not authorized.", { childSessionId: request.childSessionId }, { cause: error });
93
- }
94
- throw new RemoteError("gateway/internal", "Subagent prompt failed.", {}, { cause: error });
95
- }
96
- return super.prompt(request, signal);
97
- }
98
- wakeWaiters() {
99
- for (const waiter of this.waiters)
100
- waiter.check();
101
- }
102
- substrateReady() {
103
- const typert = this.ctx.get("typert");
104
- return this.requiredProviders.every((name) => this.getProvider(name) !== undefined)
105
- && (typert === undefined || typert.local.get("subagents/prompt") !== undefined);
106
- }
107
- waitFor(read, callerSignal) {
108
- const signal = callerSignal === undefined ? this.lifetime.signal : AbortSignal.any([callerSignal, this.lifetime.signal]);
109
- return new Promise((resolve, reject) => {
110
- const cleanup = () => { this.waiters.delete(waiter); signal.removeEventListener("abort", check); };
111
- const check = () => {
112
- if (signal.aborted) {
113
- cleanup();
114
- reject(signal.reason);
115
- return;
116
- }
117
- const value = read();
118
- if (value !== undefined) {
119
- cleanup();
120
- resolve(value);
121
- }
122
- };
123
- const waiter = { check };
124
- this.waiters.add(waiter);
125
- signal.addEventListener("abort", check, { once: true });
126
- check();
127
- });
128
- }
129
- }
130
- export default DsmmSubagentRuntime;
131
- //# sourceMappingURL=subagent-runtime.js.map
@@ -1,11 +0,0 @@
1
- <dsmm-deepseek-flash-calibration>
2
-
3
- DeepSeek-V41-Flash applies only to the verified deepseek-official/deepseek-flash or deepseek-account/deepseek-flash routes. The host catalog and explicit user model choice are authoritative.
4
-
5
- - Keep work outcome-first and avoid procedural review or approval loops.
6
- - Runtime reasoning effort is chosen by the adapter only from the resolved model's advertised efforts. If the catalog advertises no reasoning efforts, leave the request unchanged.
7
- - Ordinary root model and effort stay native-owned; explicit preflighted invocation effort takes precedence. For other eligible child requests, auto preserves explicit upstream effort; strict uses only an advertised effort.
8
- - Do not assume max, high, temperature, or another model's capabilities. Do not claim model heterogeneity when all child roles use the same route.
9
- - Maintain tool-call continuity required by the provider and never reveal private reasoning.
10
-
11
- </dsmm-deepseek-flash-calibration>
@@ -1,14 +0,0 @@
1
- <dsmm-deepseek-v4-pro-calibration>
2
-
3
- DeepSeek V4 Pro calibration is active.
4
-
5
- - Treat complex coding, architecture, migration, debugging, and review tasks as deliberate reasoning tasks.
6
- - First classify the task and identify the evidence needed.
7
- - Use tools before making repository-specific or API-specific claims.
8
- - Runtime reasoning effort is enforced by `agent/request`, not this prompt.
9
- - Ordinary root model and effort stay under the native model picker. Explicit preflighted invocation effort takes precedence over calibration.
10
- - For other eligible child requests, `auto` preserves explicit upstream effort; `strict` uses the configured default only when the adapter advertises a supported effort. If none is advertised, leave the request unchanged.
11
- - Keep final answers concise and do not expose private chain-of-thought.
12
- - When tool calls are enabled through the provider, preserve the provider-required reasoning/tool-call continuity.
13
-
14
- </dsmm-deepseek-v4-pro-calibration>
@@ -1,329 +0,0 @@
1
- import { dirname, extname, isAbsolute, join, relative, sep } from "node:path";
2
- import { createRequire } from "node:module";
3
- import { existsSync } from "node:fs";
4
- import { fileURLToPath, pathToFileURL } from "node:url";
5
- import { isDeepStrictEqual } from "node:util";
6
- import { SourceReadset, jsonDocument, refuse } from "./cold-profile-sources.mjs";
7
-
8
- export const BASE_BUNDLE = "@deepseek-ai/dsh-base";
9
- export const MODULE_REPLACEMENTS = Object.freeze({
10
- "@deepseek-ai/dsh-settings": "@dsmm/dsmm/managed-settings",
11
- "@deepseek-ai/dsh-llm": "@dsmm/dsmm/llm-runtime",
12
- "@deepseek-ai/dsh-subagent": "@dsmm/dsmm/subagent-runtime",
13
- "@deepseek-ai/dsh-session-persistence-jsonl": "@dsmm/dsmm/session-persistence",
14
- "@deepseek-ai/dsh-tool-bash": "@dsmm/dsmm/permission-bash",
15
- "@deepseek-ai/dsh-tool-pwsh": "@dsmm/dsmm/permission-pwsh",
16
- "@deepseek-ai/dsh-tool-fs": "@dsmm/dsmm/permission-fs",
17
- "@deepseek-ai/dsh-tool-fs-search": "@dsmm/dsmm/permission-fs-search",
18
- "@deepseek-ai/dsh-tool-web": "@dsmm/dsmm/permission-web",
19
- });
20
- const nativeToolIds = new Map([
21
- ["@deepseek-ai/dsh-tool-fs", "tool-fs"],
22
- ["@deepseek-ai/dsh-tool-fs-search", "tool-fs-search"],
23
- ["@deepseek-ai/dsh-tool-web", "tool-web"],
24
- ]);
25
- const projectedNativeTools = new Set([...nativeToolIds.keys()].map(name => MODULE_REPLACEMENTS[name]));
26
- const nativeGroups = new Set(["cordis:group", "@deepseek-ai/cordis-plugin-group"]);
27
- const nativeIncludes = new Set(["cordis:include", "@deepseek-ai/cordis-plugin-include"]);
28
- const officialLoop = "@deepseek-ai/dsh-agent-loop";
29
- const officialPiAi = "@deepseek-ai/dsh-llm-pi-ai";
30
- const object = value => value !== null && typeof value === "object" && !Array.isArray(value);
31
- const under = (root, filename) => {
32
- const path = relative(root, filename);
33
- return path === "" || (!path.startsWith(`..${sep}`) && path !== ".." && !isAbsolute(path));
34
- };
35
-
36
- function entryWalk(rows, visit) {
37
- if (!Array.isArray(rows)) refuse("UNSUPPORTED_ENTRY_TREE");
38
- for (const row of rows) {
39
- if (!object(row) || typeof row.name !== "string") refuse("UNSUPPORTED_ENTRY_TREE");
40
- visit(row);
41
- if (nativeGroups.has(row.name)) entryWalk(row.config, visit);
42
- else if (row.group) refuse("UNSUPPORTED_GROUP_CARRIER");
43
- }
44
- }
45
-
46
- /** Mutates only approved, original base insertion declarations, never selector names. */
47
- function projectBase(patches, { migrateShell, migrateSubagent, migrateSessionPersistence }) {
48
- patches = structuredClone(patches);
49
- const changed = new Map();
50
- for (const patch of patches) {
51
- if (!patch.insert) continue;
52
- entryWalk(patch.insert, row => {
53
- if (row.name === "@deepseek-ai/dsh-llm") {
54
- if (row.id !== "llm" || changed.has(row.id)) refuse("AMBIGUOUS_BASE_LLM");
55
- } else if (row.name === "@deepseek-ai/dsh-settings") {
56
- if (row.id !== "settings" || changed.has(row.id)) refuse("AMBIGUOUS_BASE_SETTINGS");
57
- } else if (row.name === "@deepseek-ai/dsh-subagent") {
58
- if (!migrateSubagent) return;
59
- if (row.id !== "subagent" || changed.has(row.id)) refuse("AMBIGUOUS_BASE_SUBAGENT");
60
- } else if (row.name === "@deepseek-ai/dsh-session-persistence-jsonl") {
61
- if (!migrateSessionPersistence) return;
62
- if (row.id !== "session-persistence-jsonl" || changed.has(row.id)) refuse("AMBIGUOUS_BASE_SESSION_PERSISTENCE");
63
- } else if (nativeToolIds.has(row.name)) {
64
- if (row.id !== nativeToolIds.get(row.name)) refuse("AMBIGUOUS_BASE_NATIVE_TOOL");
65
- } else if (!migrateShell || !["@deepseek-ai/dsh-tool-bash", "@deepseek-ai/dsh-tool-pwsh"].includes(row.name)) return;
66
- if (typeof row.id !== "string" || changed.has(row.id)) refuse("AMBIGUOUS_BASE_ENTRY");
67
- const name = MODULE_REPLACEMENTS[row.name];
68
- changed.set(row.id, { original: row.name, replacement: name });
69
- row.name = name;
70
- });
71
- }
72
- if (!changed.has("llm")) refuse("ORIGINAL_BASE_LLM_REQUIRED");
73
- if (!changed.has("settings")) refuse("ORIGINAL_BASE_SETTINGS_REQUIRED");
74
- if (migrateSubagent && !changed.has("subagent")) refuse("ORIGINAL_BASE_SUBAGENT_REQUIRED");
75
- if (migrateSessionPersistence && !changed.has("session-persistence-jsonl")) refuse("ORIGINAL_BASE_SESSION_PERSISTENCE_REQUIRED");
76
- return { patches, changed };
77
- }
78
-
79
- function compose(boot, lists) {
80
- const warnings = [];
81
- const rows = boot.composeEntries(lists, warning => warnings.push(warning));
82
- return { rows, warnings };
83
- }
84
-
85
- function expectedRows(rows, changed) {
86
- const expected = structuredClone(rows);
87
- const seen = new Set();
88
- entryWalk(expected, row => {
89
- const change = changed.get(row.id);
90
- if (!change) return;
91
- if (seen.has(row.id) || row.name !== change.original) refuse("ALTERNATE_ENTRY_OWNER");
92
- seen.add(row.id);
93
- row.name = change.replacement;
94
- });
95
- if (seen.size !== changed.size) refuse("MIGRATED_ENTRY_MISSING");
96
- return expected;
97
- }
98
-
99
- function assertSelectorSemantics(composeAll, original, projected) {
100
- const originalPatches = original.flat();
101
- const projectedPatches = projected.flat();
102
- // Prefix composition retains the SDK's single-pass patch index and detects
103
- // changed match/skip decisions even when later patches mask their final values.
104
- for (let count = 1; count <= originalPatches.length; count++) {
105
- if (composeAll([originalPatches.slice(0, count)]).warnings.length !== composeAll([projectedPatches.slice(0, count)]).warnings.length) refuse("SELECTOR_SEMANTICS_CHANGED");
106
- }
107
- }
108
-
109
- function llmRealm(row, inherited, position) {
110
- if (row.intercept?.llm != null) refuse("UNSUPPORTED_LLM_TOPOLOGY");
111
- if (!Object.hasOwn(row.isolate ?? {}, "llm")) return inherited;
112
- const label = row.isolate.llm;
113
- if (label == null || label === "") return "root";
114
- if (label === true) return `local:${position}`;
115
- if (typeof label === "string") return `named:${label}`;
116
- refuse("UNSUPPORTED_LLM_TOPOLOGY");
117
- }
118
-
119
- /** All declarations participate, including disabled/expression-gated rows; this is not activation proof. */
120
- function assertLlmTopology(topology) {
121
- if (topology.owners.length !== 1) refuse("ALTERNATE_LLM_OWNER");
122
- if (topology.loops.length !== 1) refuse("OFFICIAL_AGENT_LOOP_REQUIRED");
123
- const ownerRealm = topology.owners[0];
124
- if ([...topology.loops, ...topology.providers, ...topology.consumers].some(realm => realm !== ownerRealm)) refuse("LLM_REALM_MISMATCH");
125
- }
126
-
127
- function dormantModule(row, options, readset, disabledBaseURL) {
128
- if (!disabledBaseURL || row.group || !object(row.disabled) || typeof row.disabled.__jsExpr !== "string") return false;
129
- const declarations = [
130
- ["dsh-tui-code-runtime", "@deepseek-ai/dsh-code-runtime-worker-thread", "@deepseek-ai/dsh-ptc-runtime-node", "code-runtime"],
131
- ["dsh-tui-agent-presets", "@deepseek-ai/dsh-agent-presets", "@deepseek-ai/dsh-agent-preset-registry", "agent-presets"],
132
- ];
133
- for (const [id, name, capability, official] of declarations) {
134
- if (row.id !== id || row.name !== name) continue;
135
- const expression = `(() => {
136
- const require = process.getBuiltinModule('node:module').createRequire(ctx.baseUrl)
137
- try { require.resolve('${capability}/package.json'); return true } catch {}
138
- return [...ctx.loader.entries()].some(entry => entry.options.id === '${official}' && entry.options.name === '${name}' && !entry.disabled)
139
- })()`;
140
- if (row.disabled.__jsExpr.trim() !== expression) return false;
141
- return readset.dormantCapability(options, disabledBaseURL, `${capability}/package.json`);
142
- }
143
- return false;
144
- }
145
-
146
- /** Native groups inherit context; native includes keep their own patch index and source base. */
147
- function inspectTrees(rows, options, sdk, readset, baseURL, {
148
- ancestors = new Set(), root = true, ids = new Set(), inheritedRealm = "root", prefix = "root",
149
- topology = { owners: [], loops: [], providers: [], consumers: [] },
150
- nativeToolSelection = { projected: [], unprojected: [] },
151
- disabledBaseURL,
152
- } = {}) {
153
- if (!Array.isArray(rows)) refuse("UNSUPPORTED_ENTRY_TREE");
154
- for (const [index, row] of rows.entries()) {
155
- if (!object(row) || typeof row.name !== "string") refuse("UNSUPPORTED_ENTRY_TREE");
156
- const position = `${prefix}/${index}`;
157
- const slot = { path: position, ...(row.id ? { id: row.id } : {}), name: row.name };
158
- if (nativeToolIds.has(row.name)) nativeToolSelection.unprojected.push(slot);
159
- else if (projectedNativeTools.has(row.name)) nativeToolSelection.projected.push(slot);
160
- if (row.id) {
161
- if (ids.has(row.id)) refuse("DUPLICATE_ENTRY_ID");
162
- ids.add(row.id);
163
- }
164
- if ((row.name === "@deepseek-ai/dsh-llm" || row.name === MODULE_REPLACEMENTS["@deepseek-ai/dsh-llm"]) && (!root || row.id !== "llm")) refuse("ALTERNATE_LLM_OWNER");
165
- if ((row.id === "llm" || row.name.endsWith("/llm-runtime")) && row.name !== "@deepseek-ai/dsh-llm" && row.name !== MODULE_REPLACEMENTS["@deepseek-ai/dsh-llm"]) refuse("ALTERNATE_LLM_OWNER");
166
- if (typeof row.inject !== "undefined" && row.inject !== null && !Array.isArray(row.inject) && !object(row.inject)) refuse("UNSUPPORTED_SCOPE_METADATA");
167
- for (const key of ["isolate", "intercept"]) {
168
- if (row[key] !== undefined && row[key] !== null && (!object(row[key]) || row[key].__jsExpr)) refuse("UNSUPPORTED_SCOPE_METADATA");
169
- }
170
- const realm = llmRealm(row, inheritedRealm, position);
171
- if (row.name === "@deepseek-ai/dsh-llm" || row.name === MODULE_REPLACEMENTS["@deepseek-ai/dsh-llm"]) topology.owners.push(realm);
172
- if (row.id === "agent-loop" || row.name === officialLoop || /(?:^|\/)agent-loop(?:$|\/)/.test(row.name)) {
173
- if (row.name !== officialLoop || row.id !== "agent-loop") refuse("ALTERNATE_AGENT_LOOP");
174
- topology.loops.push(realm);
175
- }
176
- if (row.id === "llm-pi-ai" && row.name !== officialPiAi) refuse("ALTERNATE_PROVIDER_OWNER");
177
- if (row.name === officialPiAi || row.name.startsWith("@deepseek-ai/dsh-llm-deepseek-")) topology.providers.push(realm);
178
- if ((Array.isArray(row.inject) && row.inject.includes("llm")) || (object(row.inject) && Object.hasOwn(row.inject, "llm"))) topology.consumers.push(realm);
179
- if (!row.name.startsWith("cordis:") && !dormantModule(row, options, readset, disabledBaseURL)) {
180
- let filename;
181
- const local = row.name.startsWith("file:") || row.name.startsWith(".") || isAbsolute(row.name);
182
- if (local) {
183
- try { filename = isAbsolute(row.name) ? row.name : fileURLToPath(new URL(row.name, baseURL)); } catch { refuse("UNSUPPORTED_MODULE_SOURCE"); }
184
- if (!options.sourceRoots.some(sourceRoot => under(sourceRoot, filename))) refuse("MODULE_OUTSIDE_SOURCE_SCOPE");
185
- readset.module(filename);
186
- } else {
187
- const packageName = row.name.startsWith("@") ? row.name.split("/").slice(0, 2).join("/") : row.name.split("/")[0];
188
- const entry = sdk.resolution.entries.find(entry => entry.name === packageName);
189
- const require = createRequire(baseURL);
190
- const localDir = (require.resolve.paths(packageName) ?? [])
191
- .filter(searchPath => under(options.profileDir, searchPath))
192
- .map(searchPath => join(searchPath, packageName))
193
- .find(candidate => existsSync(join(candidate, "package.json")));
194
- const packageDir = localDir ?? entry?.packageDir;
195
- if (!packageDir) refuse("UNRESOLVED_ENTRY_MODULE");
196
- const manifest = readset.package(join(packageDir, "package.json"));
197
- try {
198
- if (Object.hasOwn(manifest, "exports")) {
199
- const targets = sdk.packageExports.exports(manifest, row.name, { conditions: ["node"] });
200
- if (!targets || targets.length !== 1 || !targets[0].startsWith("./")) refuse("UNSUPPORTED_MODULE_EXPORT");
201
- filename = join(packageDir, targets[0]);
202
- } else {
203
- const subpath = row.name.slice(packageName.length + 1);
204
- filename = createRequire(join(packageDir, "package.json")).resolve(join(packageDir, subpath || manifest.main || "index.js"));
205
- }
206
- } catch {
207
- refuse("UNRESOLVED_ENTRY_MODULE");
208
- }
209
- readset.module(filename, { packageSource: true });
210
- }
211
- }
212
- if (nativeGroups.has(row.name)) {
213
- inspectTrees(row.config, options, sdk, readset, baseURL, { ancestors, root, ids, inheritedRealm: realm, prefix: position, topology, nativeToolSelection });
214
- continue;
215
- }
216
- if (row.group) refuse("UNSUPPORTED_GROUP_CARRIER");
217
- if (row.name === "@deepseek-ai/dsh-agent-preset") {
218
- if (!object(row.config) || !Array.isArray(row.config.plugins)) refuse("UNSUPPORTED_PRESET_PLUGINS");
219
- inspectTrees(row.config.plugins, options, sdk, readset, baseURL, {
220
- ancestors, root: false, inheritedRealm: realm, prefix: `${position}/plugins`, nativeToolSelection,
221
- });
222
- }
223
- if (!nativeIncludes.has(row.name)) continue;
224
- const config = row.config;
225
- if (!object(config) || typeof config.path !== "string" || config.__jsExpr) refuse("UNSUPPORTED_INCLUDE");
226
- let filename;
227
- try { filename = fileURLToPath(new URL(config.path, baseURL)); } catch { refuse("UNSUPPORTED_INCLUDE"); }
228
- if (!options.sourceRoots.some(sourceRoot => under(sourceRoot, filename))) refuse("INCLUDE_OUTSIDE_SOURCE_SCOPE");
229
- if (!new Set([".json", ".yml", ".yaml"]).has(extname(filename)) || /(?:credentials|secrets|\.env)/i.test(filename)) refuse("UNSUPPORTED_INCLUDE");
230
- if (ancestors.has(filename)) refuse("INCLUDE_CYCLE");
231
- const content = readset.read(filename, { optional: true });
232
- const source = content === null ? config.initial : extname(filename) === ".json"
233
- ? jsonDocument(content).value : sdk.yaml.load(content, { schema: sdk.include.entryListSchema });
234
- if (!Array.isArray(source)) refuse("UNSUPPORTED_INCLUDE");
235
- const warnings = [];
236
- const children = sdk.include.applyEntryPatches(source, config.patches, (...args) => warnings.push(args));
237
- if (warnings.length) refuse("INCLUDE_PATCH_DIAGNOSTIC");
238
- const next = new Set(ancestors).add(filename);
239
- inspectTrees(children, options, sdk, readset, new URL(".", pathToFileURL(filename)).href, {
240
- ancestors: next, root: false, inheritedRealm: realm, prefix: `${position}/include`, topology,
241
- nativeToolSelection,
242
- });
243
- }
244
- return topology;
245
- }
246
-
247
- /** Full ordered bundle/profile/Home/explicit-launcher source validation and necessary CAS revision. */
248
- export async function inspectColdComposition(options, sdk, { projectionName, receipt } = {}) {
249
- const readset = new SourceReadset();
250
- const manifestPath = join(options.profileDir, "package.json");
251
- const manifestText = readset.read(manifestPath);
252
- const manifest = jsonDocument(manifestText).value;
253
- const bundles = manifest.dsh?.profile?.bundles;
254
- if (!Array.isArray(bundles) || !bundles.every(name => typeof name === "string")) refuse("INVALID_BUNDLES");
255
- const originalName = receipt?.projectionName ?? BASE_BUNDLE;
256
- const slot = bundles.indexOf(originalName);
257
- if (slot < 0 || bundles.lastIndexOf(originalName) !== slot) refuse("EXACT_BASE_SLOT_REQUIRED");
258
- readset.package(options.installAnchor);
259
- for (const filename of sdk.modulePaths) readset.module(filename, { packageSource: true });
260
- readset.read(join(options.profileDir, "compatibility.json"), { optional: true });
261
- readset.read(join(options.profileDir, "cordis.patch.yml"), { optional: true });
262
- const homePatch = join(options.home, "cordis.patch.yml");
263
- readset.read(homePatch, { optional: true });
264
- for (const filename of options.overlays) readset.read(filename);
265
- if (options.rootConfig) readset.read(options.rootConfig);
266
- if (receipt) readset.read(join(options.profileDir, "node_modules", receipt.projectionName, ".dsmm-cold-profile.json"));
267
- const discover = sdk.boot.loadProfileDirectory("dsmm-cold-profile", options.profileDir, options.installAnchor);
268
- if (discover.skippedBundles.length || discover.layers.length !== bundles.length) refuse("SKIPPED_BUNDLE");
269
- for (const layer of discover.layers) {
270
- readset.package(join(layer.packageDir, "package.json"), { packageSource: layer.packageName !== originalName || !receipt });
271
- for (const filename of layer.patchPaths) readset.read(filename, { packageSource: layer.packageName !== originalName || !receipt });
272
- }
273
- const profile = sdk.boot.loadProfileDirectory("dsmm-cold-profile", options.profileDir, options.installAnchor);
274
- if (profile.skippedBundles.length || profile.layers.length !== bundles.length) refuse("SOURCE_CONFLICT");
275
- const lists = profile.layers.map(layer => layer.patches);
276
- lists.push(profile.patches, sdk.boot.loadOptionalPatches("dsmm-cold-profile", homePatch) ?? []);
277
- lists.push(...options.overlays.map(filename => sdk.boot.loadOverlayPatches("dsmm-cold-profile", filename)));
278
- // Normal profile launchers mount an empty root file. Explicit roots retain their original base.
279
- const rootRows = options.rootConfig
280
- ? sdk.yaml.load(readset.read(options.rootConfig), { schema: sdk.include.entryListSchema }) : [];
281
- if (!Array.isArray(rootRows)) refuse("UNSUPPORTED_ROOT_CONFIG");
282
- const composeAll = layers => {
283
- if (rootRows.length === 0) return compose(sdk.boot, layers);
284
- const warnings = [];
285
- const rows = sdk.include.applyEntryPatches(rootRows, layers.flat(), (...args) => warnings.push(args));
286
- return { rows, warnings };
287
- };
288
- const before = composeAll(lists);
289
- let projected = lists[slot];
290
- let changed;
291
- let after;
292
- if (receipt) {
293
- changed = new Map(receipt.changes.map(change => [change.id, change]));
294
- after = before;
295
- const originalLists = structuredClone(lists);
296
- for (const patch of originalLists[slot]) if (patch.insert) entryWalk(patch.insert, row => {
297
- const change = changed.get(row.id);
298
- if (change && row.name === change.replacement) row.name = change.original;
299
- });
300
- const original = composeAll(originalLists);
301
- assertSelectorSemantics(composeAll, originalLists, lists);
302
- if (!isDeepStrictEqual(expectedRows(original.rows, changed), after.rows) || original.warnings.length !== after.warnings.length) refuse("SELECTOR_SEMANTICS_CHANGED");
303
- } else {
304
- ({ patches: projected, changed } = projectBase(lists[slot], options));
305
- const projectedLists = [...lists];
306
- projectedLists[slot] = projected;
307
- after = composeAll(projectedLists);
308
- assertSelectorSemantics(composeAll, lists, projectedLists);
309
- if (!isDeepStrictEqual(expectedRows(before.rows, changed), after.rows) || before.warnings.length !== after.warnings.length) refuse("SELECTOR_SEMANTICS_CHANGED");
310
- }
311
- const rootURL = pathToFileURL(options.rootConfig ?? join(options.profileDir, "cordis.yml")).href;
312
- const resolution = await sdk.boot.createRuntimeResolution({ installAnchor: options.installAnchor, profile, home: options.home });
313
- const nativeToolSelection = { projected: [], unprojected: [] };
314
- // First disabled evaluation inherits loader.ctx before Entry._patchContext.
315
- // Nested groups/includes/presets receive no proof from their traversal base.
316
- assertLlmTopology(inspectTrees(after.rows, options, { ...sdk, resolution }, readset, rootURL, {
317
- nativeToolSelection, disabledBaseURL: pathToFileURL(dirname(fileURLToPath(rootURL))).href + "/",
318
- }));
319
- readset.assertCurrent();
320
- const context = { ...options, projectionName: receipt?.projectionName ?? projectionName ?? null };
321
- // Generated transaction identity is not part of a caller's expected source revision.
322
- delete context.projectionName;
323
- return {
324
- readset, revision: readset.revision(context), manifestText, manifestPath, slot,
325
- baseLayer: profile.layers[slot], projected, changes: [...changed].map(([id, change]) => ({ id, ...change })),
326
- rows: after.rows,
327
- nativeToolSelection: { status: nativeToolSelection.unprojected.length ? "partial" : "projected", ...nativeToolSelection },
328
- };
329
- }