@dsmm/dsmm 0.2.0 → 0.2.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 (291) hide show
  1. package/README.md +38 -66
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
  3. package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
  4. package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
  5. package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
  6. package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
  7. package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
  8. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
  9. package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
  11. package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
  12. package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
  13. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
  14. package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
  15. package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
  16. package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
  19. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
  20. package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
  21. package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
  22. package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
  23. package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
  24. package/docs/agent-presets.md +36 -52
  25. package/docs/compatibility.md +50 -108
  26. package/docs/deferred-native-approval-risk.md +19 -0
  27. package/docs/design.md +2 -2
  28. package/docs/lsp.md +11 -21
  29. package/docs/migration-from-ocmm.md +2 -2
  30. package/docs/model-routing.md +84 -59
  31. package/docs/native-permissions.md +35 -0
  32. package/docs/profiles.md +40 -87
  33. package/docs/releasing.md +83 -2
  34. package/docs/roadmap.md +71 -17
  35. package/docs/settings-status.md +34 -169
  36. package/docs/skill-sync.md +52 -15
  37. package/lib/child-admission-contract.d.ts +37 -0
  38. package/lib/child-admission-contract.js +2 -0
  39. package/lib/child-admission.d.ts +42 -0
  40. package/lib/child-admission.js +162 -0
  41. package/lib/child-capture.d.ts +81 -0
  42. package/lib/child-capture.js +203 -0
  43. package/lib/child-evidence.d.ts +17 -0
  44. package/lib/child-evidence.js +43 -0
  45. package/lib/client/ChildrenPanel.d.ts +43 -0
  46. package/lib/client/ChildrenPanel.js +82 -0
  47. package/lib/client/DeploymentPage.js +15 -8
  48. package/lib/client/EditableChoice.d.ts +17 -0
  49. package/lib/client/EditableChoice.js +49 -0
  50. package/lib/client/PermissionsPanel.d.ts +14 -0
  51. package/lib/client/PermissionsPanel.js +46 -0
  52. package/lib/client/ProfilesSection.js +30 -15
  53. package/lib/client/RoleAvailability.d.ts +7 -0
  54. package/lib/client/RoleAvailability.js +19 -0
  55. package/lib/client/SessionProfiles.js +27 -9
  56. package/lib/client/StructuredEditor.js +15 -7
  57. package/lib/client/children-controller.d.ts +98 -0
  58. package/lib/client/children-controller.js +296 -0
  59. package/lib/client/children-locales.d.ts +367 -0
  60. package/lib/client/children-locales.js +69 -0
  61. package/lib/client/controller.d.ts +6 -1
  62. package/lib/client/controller.js +14 -8
  63. package/lib/client/deployment-data.d.ts +2 -1
  64. package/lib/client/deployment-data.js +34 -5
  65. package/lib/client/deployment-locales.d.ts +4 -0
  66. package/lib/client/deployment-locales.js +11 -2
  67. package/lib/client/diagnostics.d.ts +14 -0
  68. package/lib/client/diagnostics.js +53 -0
  69. package/lib/client/index.d.ts +4 -0
  70. package/lib/client/index.js +96 -2
  71. package/lib/client/locales.d.ts +54 -0
  72. package/lib/client/locales.js +34 -16
  73. package/lib/client/permission-client.d.ts +16 -0
  74. package/lib/client/permission-client.js +38 -0
  75. package/lib/client/permission-controller.d.ts +62 -0
  76. package/lib/client/permission-controller.js +149 -0
  77. package/lib/client/permission-locales.d.ts +114 -0
  78. package/lib/client/permission-locales.js +75 -0
  79. package/lib/client/session-labels.js +4 -4
  80. package/lib/client/structured.js +19 -5
  81. package/lib/client/styles.d.ts +1 -1
  82. package/lib/client/styles.js +20 -0
  83. package/lib/client.js +5780 -1679
  84. package/lib/core-permission-authority.d.ts +18 -0
  85. package/lib/core-permission-authority.js +255 -0
  86. package/lib/core-permissions.d.ts +8 -0
  87. package/lib/core-permissions.js +33 -0
  88. package/lib/delivery-authority.d.ts +68 -0
  89. package/lib/delivery-authority.js +260 -0
  90. package/lib/deployment-config.d.ts +23 -0
  91. package/lib/deployment-config.js +61 -40
  92. package/lib/deployment-permission-rules.d.ts +55 -0
  93. package/lib/deployment-permission-rules.js +306 -0
  94. package/lib/dsh-types.d.ts +10 -4
  95. package/lib/guards.d.ts +1 -1
  96. package/lib/guards.js +29 -8
  97. package/lib/host-llm-startup.d.ts +41 -0
  98. package/lib/host-llm-startup.js +65 -0
  99. package/lib/host-llm.d.ts +92 -0
  100. package/lib/host-llm.js +325 -0
  101. package/lib/index.d.ts +15 -4
  102. package/lib/index.js +300 -47
  103. package/lib/legacy-child-policy.d.ts +51 -0
  104. package/lib/legacy-child-policy.js +123 -0
  105. package/lib/legacy-read-composition.d.ts +20 -0
  106. package/lib/legacy-read-composition.js +144 -0
  107. package/lib/legacy-read-contracts.d.ts +157 -0
  108. package/lib/legacy-read-contracts.js +39 -0
  109. package/lib/legacy-read-host.d.ts +19 -0
  110. package/lib/legacy-read-host.js +67 -0
  111. package/lib/legacy-read-integration.d.ts +121 -0
  112. package/lib/legacy-read-integration.js +522 -0
  113. package/lib/legacy-read-proxy.d.ts +26 -0
  114. package/lib/legacy-read-proxy.js +237 -0
  115. package/lib/live-pi-ai-owner.d.ts +18 -0
  116. package/lib/live-pi-ai-owner.js +144 -0
  117. package/lib/llm-runtime.d.ts +11 -0
  118. package/lib/llm-runtime.js +21 -0
  119. package/lib/managed-settings.d.ts +5 -0
  120. package/lib/managed-settings.js +14 -0
  121. package/lib/model-parameter-policy.d.ts +11 -0
  122. package/lib/model-parameter-policy.js +27 -0
  123. package/lib/model-routing.js +28 -17
  124. package/lib/modules.d.ts +13 -5
  125. package/lib/modules.js +17 -1
  126. package/lib/native-child-evidence.d.ts +42 -0
  127. package/lib/native-child-evidence.js +133 -0
  128. package/lib/native-pi-ai-wire.d.ts +37 -0
  129. package/lib/native-pi-ai-wire.js +261 -0
  130. package/lib/native-scope.js +1 -1
  131. package/lib/permission-bash.d.ts +6 -0
  132. package/lib/permission-bash.js +7 -0
  133. package/lib/permission-control.d.ts +73 -0
  134. package/lib/permission-control.js +205 -0
  135. package/lib/permission-controller.d.ts +68 -0
  136. package/lib/permission-controller.js +317 -0
  137. package/lib/permission-errors.d.ts +7 -0
  138. package/lib/permission-errors.js +21 -0
  139. package/lib/permission-fs-search.d.ts +5 -0
  140. package/lib/permission-fs-search.js +7 -0
  141. package/lib/permission-fs.d.ts +5 -0
  142. package/lib/permission-fs.js +7 -0
  143. package/lib/permission-native-access.d.ts +11 -0
  144. package/lib/permission-native-access.js +6 -0
  145. package/lib/permission-native-command.d.ts +10 -0
  146. package/lib/permission-native-command.js +93 -0
  147. package/lib/permission-native-rules.d.ts +75 -0
  148. package/lib/permission-native-rules.js +278 -0
  149. package/lib/permission-pwsh.d.ts +6 -0
  150. package/lib/permission-pwsh.js +7 -0
  151. package/lib/permission-remote.d.ts +26 -0
  152. package/lib/permission-remote.js +53 -0
  153. package/lib/permission-rpc.d.ts +29 -0
  154. package/lib/permission-rpc.js +152 -0
  155. package/lib/permission-rules.d.ts +115 -0
  156. package/lib/permission-rules.js +256 -0
  157. package/lib/permission-settings.d.ts +45 -0
  158. package/lib/permission-settings.js +48 -0
  159. package/lib/permission-shell.d.ts +38 -0
  160. package/lib/permission-shell.js +150 -0
  161. package/lib/permission-web.d.ts +5 -0
  162. package/lib/permission-web.js +7 -0
  163. package/lib/preset-registry.js +36 -25
  164. package/lib/profile-diagnostics.d.ts +45 -0
  165. package/lib/profile-diagnostics.js +148 -0
  166. package/lib/profile-locale.d.ts +3 -0
  167. package/lib/profile-locale.js +2 -0
  168. package/lib/profile-remote.d.ts +8 -0
  169. package/lib/profile-remote.js +163 -39
  170. package/lib/profile-rpc.d.ts +4 -3
  171. package/lib/profile-rpc.js +14 -12
  172. package/lib/profile-runtime.d.ts +40 -1
  173. package/lib/profile-runtime.js +368 -93
  174. package/lib/profile-store.d.ts +11 -0
  175. package/lib/profile-store.js +143 -11
  176. package/lib/profile-types.d.ts +70 -1
  177. package/lib/profile-types.js +1 -0
  178. package/lib/profiles.d.ts +16 -2
  179. package/lib/profiles.js +156 -79
  180. package/lib/prompt-content.js +1 -1
  181. package/lib/prompts.d.ts +37 -2
  182. package/lib/prompts.js +111 -9
  183. package/lib/recovery-policy.js +20 -7
  184. package/lib/role-control-remote.d.ts +38 -0
  185. package/lib/role-control-remote.js +211 -0
  186. package/lib/role-control-rpc.d.ts +51 -0
  187. package/lib/role-control-rpc.js +377 -0
  188. package/lib/role-control-types.d.ts +92 -0
  189. package/lib/role-control-types.js +8 -0
  190. package/lib/role-invocation.d.ts +47 -0
  191. package/lib/role-invocation.js +135 -0
  192. package/lib/role-llm-runtime.d.ts +17 -0
  193. package/lib/role-llm-runtime.js +62 -0
  194. package/lib/role-llm.d.ts +31 -0
  195. package/lib/role-llm.js +66 -0
  196. package/lib/role-policy.d.ts +49 -8
  197. package/lib/role-policy.js +437 -60
  198. package/lib/role-providers.d.ts +1 -1
  199. package/lib/role-providers.js +30 -35
  200. package/lib/role-routing.d.ts +11 -2
  201. package/lib/role-routing.js +42 -25
  202. package/lib/role-runs.d.ts +135 -0
  203. package/lib/role-runs.js +304 -0
  204. package/lib/role-subagents.d.ts +58 -3
  205. package/lib/role-subagents.js +169 -56
  206. package/lib/roles.d.ts +5 -6
  207. package/lib/roles.js +10 -39
  208. package/lib/route-json.d.ts +19 -0
  209. package/lib/route-json.js +129 -0
  210. package/lib/routing-policy.d.ts +2 -0
  211. package/lib/routing-policy.js +12 -2
  212. package/lib/runtime-integration.d.ts +112 -0
  213. package/lib/runtime-integration.js +784 -0
  214. package/lib/runtime-recovery.js +18 -8
  215. package/lib/settings.d.ts +47 -13
  216. package/lib/settings.js +217 -82
  217. package/lib/skills.js +2 -2
  218. package/lib/status.d.ts +10 -1
  219. package/lib/status.js +11 -8
  220. package/lib/subagent-runtime.d.ts +45 -0
  221. package/lib/subagent-runtime.js +131 -0
  222. package/package.json +106 -56
  223. package/patches/subagent-runtime.yml +15 -0
  224. package/prompts/deepseek-flash.md +1 -1
  225. package/prompts/deepseek-v4-pro.md +2 -2
  226. package/prompts/deepwork.md +27 -18
  227. package/prompts/source/agents/clarifier.md +5 -3
  228. package/prompts/source/agents/orchestrator.md +18 -9
  229. package/prompts/source/agents/plan-critic.md +5 -1
  230. package/prompts/source/agents/planner.md +4 -2
  231. package/prompts/source/agents/reviewer.md +6 -0
  232. package/prompts/source/category/complex.md +4 -4
  233. package/prompts/source/category/creative.md +6 -4
  234. package/prompts/source/category/cross-cutting.md +10 -8
  235. package/prompts/source/category/deep.md +5 -3
  236. package/prompts/source/category/documenting.md +7 -1
  237. package/prompts/source/category/frontend.md +2 -2
  238. package/prompts/source/category/hard-reasoning.md +3 -3
  239. package/prompts/source/category/research.md +4 -2
  240. package/prompts/source/deepwork/claude-opus-5.md +2 -2
  241. package/prompts/source/deepwork/codex.md +1 -1
  242. package/prompts/source/deepwork/default.md +22 -15
  243. package/prompts/source/deepwork/gemini.md +23 -16
  244. package/prompts/source/deepwork/glm.md +21 -14
  245. package/prompts/source/deepwork/gpt.md +12 -6
  246. package/prompts/source/deepwork/planner.md +8 -5
  247. package/prompts/source/manifest.json +178 -63
  248. package/prompts/source/shared/dsh-host-contract.md +5 -3
  249. package/prompts/source/shared/locale.md +2 -2
  250. package/prompts/source/terminal/orchestrator.md +1 -1
  251. package/scripts/cold-profile-composition.mjs +329 -0
  252. package/scripts/cold-profile-sources.mjs +238 -0
  253. package/scripts/migrate-cold-profile.mjs +315 -0
  254. package/skills/ast-grep/SKILL.md +7 -4
  255. package/skills/brainstorming/SKILL.md +43 -22
  256. package/skills/coding-agent-sessions/SKILL.md +7 -4
  257. package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
  258. package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
  259. package/skills/debugging/SKILL.md +14 -9
  260. package/skills/debugging/references/methodology/00-setup.md +14 -62
  261. package/skills/debugging/references/methodology/02-investigate.md +4 -4
  262. package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
  263. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
  264. package/skills/debugging/references/methodology/06-fix.md +6 -6
  265. package/skills/debugging/references/methodology/08-qa.md +5 -5
  266. package/skills/debugging/references/methodology/09-cleanup.md +15 -153
  267. package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
  268. package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
  269. package/skills/debugging/references/runtimes/native-binary.md +9 -54
  270. package/skills/debugging/references/runtimes/node.md +4 -15
  271. package/skills/debugging/references/runtimes/python.md +3 -15
  272. package/skills/debugging/references/runtimes/rust.md +2 -18
  273. package/skills/debugging/references/tools/dap.md +1 -1
  274. package/skills/debugging/references/tools/ghidra.md +4 -15
  275. package/skills/debugging/references/tools/playwright-cli.md +3 -15
  276. package/skills/debugging/references/tools/pwntools.md +4 -16
  277. package/skills/dispatching-parallel-agents/SKILL.md +18 -16
  278. package/skills/frontend/SKILL.md +7 -4
  279. package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
  280. package/skills/git-master/SKILL.md +7 -4
  281. package/skills/init-deep/SKILL.md +7 -4
  282. package/skills/receiving-code-review/SKILL.md +17 -12
  283. package/skills/remove-ai-slops/SKILL.md +39 -38
  284. package/skills/requesting-code-review/SKILL.md +19 -17
  285. package/skills/requesting-code-review/code-reviewer.md +13 -1
  286. package/skills/subagent-driven-development/SKILL.md +29 -26
  287. package/skills/subagent-driven-development/implementer-prompt.md +29 -11
  288. package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
  289. package/skills/using-git-worktrees/SKILL.md +7 -4
  290. package/skills/writing-plans/SKILL.md +29 -24
  291. package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
@@ -0,0 +1,329 @@
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
+ }
@@ -0,0 +1,238 @@
1
+ import { createHash } from "node:crypto";
2
+ import { spawnSync } from "node:child_process";
3
+ import { lstatSync, readFileSync, realpathSync } from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import { dirname, isAbsolute, join, parse, resolve } from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { findNodeAtLocation, parseTree } from "jsonc-parser";
8
+
9
+ export class ColdProfileMigrationError extends Error {
10
+ constructor(code) {
11
+ super(`Cold-profile migration refused: ${code}`);
12
+ this.name = "ColdProfileMigrationError";
13
+ this.code = code;
14
+ }
15
+ }
16
+
17
+ export const refuse = code => { throw new ColdProfileMigrationError(code); };
18
+ export const digest = bytes => createHash("sha256").update(bytes).digest("hex");
19
+
20
+ /** Writes never follow a profile, Home, or output directory symlink/junction. */
21
+ export function plainPath(filename, { missing = false } = {}) {
22
+ if (!isAbsolute(filename)) refuse("ABSOLUTE_PATH_REQUIRED");
23
+ let cursor = resolve(filename);
24
+ while (cursor !== parse(cursor).root) {
25
+ try {
26
+ if (lstatSync(cursor).isSymbolicLink()) refuse("LINKED_SOURCE_OR_TARGET");
27
+ } catch (error) {
28
+ if (error.code !== "ENOENT" || !missing) throw error;
29
+ }
30
+ cursor = dirname(cursor);
31
+ }
32
+ return resolve(filename);
33
+ }
34
+
35
+ /** One necessary source readset, held in memory; source contents are never receipts. */
36
+ export class SourceReadset {
37
+ files = new Map();
38
+ capabilities = new Map();
39
+ record(entry) {
40
+ const previous = this.files.get(entry.filename);
41
+ if (previous && JSON.stringify(previous) !== JSON.stringify(entry)) refuse("SOURCE_CONFLICT");
42
+ this.files.set(entry.filename, entry);
43
+ }
44
+ read(filename, { optional = false, packageSource = false } = {}) {
45
+ filename = resolve(filename);
46
+ if (!packageSource) plainPath(filename, { missing: optional });
47
+ let bytes = null;
48
+ let canonical = null;
49
+ try {
50
+ canonical = realpathSync(filename);
51
+ if (!lstatSync(canonical).isFile()) refuse("SOURCE_NOT_FILE");
52
+ bytes = readFileSync(filename);
53
+ } catch (error) {
54
+ if (error.code !== "ENOENT" || !optional) throw error;
55
+ }
56
+ this.record({ kind: "source", filename, canonical, hash: bytes === null ? null : digest(bytes) });
57
+ return bytes?.toString("utf8") ?? null;
58
+ }
59
+ package(filename, { packageSource = true } = {}) {
60
+ filename = resolve(filename);
61
+ if (!packageSource) plainPath(filename);
62
+ const canonical = realpathSync(filename);
63
+ const manifest = jsonDocument(readFileSync(filename, "utf8")).value;
64
+ this.record({ kind: "package", filename, canonical, hash: packageIdentity(manifest) });
65
+ return manifest;
66
+ }
67
+ module(filename, { packageSource = false } = {}) {
68
+ filename = resolve(filename);
69
+ if (!packageSource) plainPath(filename);
70
+ const canonical = realpathSync(filename);
71
+ if (!lstatSync(canonical).isFile()) refuse("UNRESOLVED_ENTRY_MODULE");
72
+ this.record({ kind: "module", filename, canonical });
73
+ }
74
+ dormantCapability(options, baseURL, specifier) {
75
+ const request = { installAnchor: options.installAnchor, profileDir: options.profileDir, home: options.home, baseURL, specifier };
76
+ const selected = freshCapability(request);
77
+ if (!selected.resolved) return false;
78
+ const key = JSON.stringify(request);
79
+ const previous = this.capabilities.get(key);
80
+ if (previous && JSON.stringify(previous.selected) !== JSON.stringify(selected)) refuse("SOURCE_CONFLICT");
81
+ this.capabilities.set(key, { request, selected });
82
+ return true;
83
+ }
84
+ assertCurrent() {
85
+ for (const entry of this.files.values()) {
86
+ let canonical = null;
87
+ let hash = null;
88
+ try {
89
+ canonical = realpathSync(entry.filename);
90
+ if (!lstatSync(canonical).isFile()) refuse("SOURCE_CONFLICT");
91
+ if (entry.kind === "source") hash = digest(readFileSync(entry.filename));
92
+ else if (entry.kind === "package") hash = packageIdentity(jsonDocument(readFileSync(entry.filename, "utf8")).value);
93
+ } catch (error) {
94
+ if (error.code !== "ENOENT") throw error;
95
+ }
96
+ if (canonical !== entry.canonical || (entry.kind !== "module" && hash !== entry.hash)) refuse("SOURCE_CONFLICT");
97
+ }
98
+ for (const { request, selected } of this.capabilities.values()) {
99
+ if (JSON.stringify(freshCapability(request)) !== JSON.stringify(selected)) refuse("SOURCE_CONFLICT");
100
+ }
101
+ }
102
+ revision(context) {
103
+ const files = [...this.files.values()].sort((a, b) => a.filename.localeCompare(b.filename));
104
+ const capabilities = [...this.capabilities.values()].sort((a, b) => JSON.stringify(a.request).localeCompare(JSON.stringify(b.request)));
105
+ return digest(JSON.stringify({ context, files, ...(capabilities.length ? { capabilities } : {}) }));
106
+ }
107
+ }
108
+
109
+ const capabilitySpecifiers = new Set([
110
+ "@deepseek-ai/dsh-ptc-runtime-node/package.json",
111
+ "@deepseek-ai/dsh-agent-preset-registry/package.json",
112
+ ]);
113
+
114
+ /** A new process discards Node's manifest/path caches and the SDK's ResolutionRouter caches. */
115
+ function freshCapability(request) {
116
+ if (!capabilitySpecifiers.has(request.specifier)) refuse("DORMANT_RESOLUTION_UNAVAILABLE");
117
+ // Preloaded hooks can change native routing or execute user code in the probe.
118
+ if (process.env.NODE_OPTIONS?.trim() || process.execArgv.some(arg => /^(?:--(?:import|require|loader|experimental-loader)(?:=|$)|-r)/.test(arg))) refuse("DORMANT_RESOLUTION_UNAVAILABLE");
119
+ const flags = [];
120
+ for (let i = 0; i < process.execArgv.length; i++) {
121
+ const arg = process.execArgv[i];
122
+ if (/^(?:--conditions=|--preserve-symlinks$|--preserve-symlinks-main$|--no-addons$|--no-experimental-require-module$)/.test(arg)) flags.push(arg);
123
+ else if (arg === "--conditions" || arg === "-C") flags.push(arg, process.execArgv[++i]);
124
+ }
125
+ const child = spawnSync(process.execPath, [...flags, fileURLToPath(import.meta.url), "--dsmm-dormant-resolution"], {
126
+ input: JSON.stringify(request), encoding: "utf8", timeout: 30_000, maxBuffer: 1024 * 1024,
127
+ env: { ...process.env, NODE_OPTIONS: "" }, windowsHide: true,
128
+ });
129
+ if (child.error || child.status !== 0) refuse("DORMANT_RESOLUTION_UNAVAILABLE");
130
+ let selected;
131
+ try { selected = JSON.parse(child.stdout); } catch { refuse("DORMANT_RESOLUTION_UNAVAILABLE"); }
132
+ if (typeof selected?.resolved !== "boolean") refuse("DORMANT_RESOLUTION_UNAVAILABLE");
133
+ return selected;
134
+ }
135
+
136
+ /** Uses the SDK's actual CJS interception, without mounting entries or importing capability code. */
137
+ async function resolveCapability(request) {
138
+ if (!capabilitySpecifiers.has(request.specifier)) refuse("DORMANT_RESOLUTION_UNAVAILABLE");
139
+ const native = createRequire(request.installAnchor);
140
+ const bootPath = native.resolve("@deepseek-ai/dsh-app-boot");
141
+ const boot = await import(pathToFileURL(bootPath).href);
142
+ if (boot.getDshRuntimeVersion() !== "0.2.0-rc.2") refuse("UNSUPPORTED_SDK");
143
+ const { Context } = await import(pathToFileURL(createRequire(bootPath).resolve("@deepseek-ai/cordis")).href);
144
+ const profile = boot.loadProfileDirectory("dsmm-cold-profile", request.profileDir, request.installAnchor);
145
+ if (profile.skippedBundles.length) refuse("SKIPPED_BUNDLE");
146
+ const resolution = await boot.createRuntimeResolution({ installAnchor: request.installAnchor, profile, home: request.home });
147
+ const ctx = new Context();
148
+ try {
149
+ await ctx.plugin(boot.PluginPackages, { resolution });
150
+ if (!ctx.get("pluginPackages")?.interception) refuse("DORMANT_RESOLUTION_UNAVAILABLE");
151
+ const require = createRequire(request.baseURL);
152
+ let target;
153
+ try { target = require.resolve(request.specifier); } catch { return { resolved: false }; }
154
+ const name = request.specifier.slice(0, -"/package.json".length);
155
+ const manifests = new Set([
156
+ target,
157
+ ...(require.resolve.paths(name) ?? []).map(searchPath => join(searchPath, name, "package.json")),
158
+ ...resolution.entries.filter(entry => entry.name === name).map(entry => join(entry.packageDir, "package.json")),
159
+ ]);
160
+ const packages = [...manifests].sort().map(filename => {
161
+ try {
162
+ const canonical = realpathSync(filename);
163
+ const hash = packageIdentity(jsonDocument(readFileSync(filename, "utf8")).value);
164
+ return { filename, canonical, hash };
165
+ } catch (error) {
166
+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;
167
+ return { filename, canonical: null, hash: null };
168
+ }
169
+ });
170
+ const canonical = realpathSync(target);
171
+ if (!lstatSync(canonical).isFile()) refuse("DORMANT_RESOLUTION_UNAVAILABLE");
172
+ return { resolved: true, target, canonical, packages };
173
+ } finally {
174
+ await ctx.fiber.dispose();
175
+ }
176
+ }
177
+
178
+ function packageIdentity(manifest) {
179
+ const fields = ["name", "version", "type", "main", "exports", "imports", "dependencies", "peerDependencies", "optionalDependencies"];
180
+ const identity = Object.fromEntries(fields.filter(field => Object.hasOwn(manifest, field)).map(field => [field, manifest[field]]));
181
+ if (manifest.dsh?.bundle !== undefined) identity.bundle = manifest.dsh.bundle;
182
+ return digest(JSON.stringify(identity));
183
+ }
184
+
185
+ /** SDK manifests are strict JSON; duplicate properties are refused rather than erased. */
186
+ export function jsonDocument(text) {
187
+ const errors = [];
188
+ const tree = parseTree(text, errors, { disallowComments: true, allowTrailingComma: false });
189
+ if (!tree || errors.length) refuse("INVALID_MANIFEST");
190
+ const visit = node => {
191
+ if (node.type === "object") {
192
+ const names = new Set();
193
+ for (const property of node.children ?? []) {
194
+ const key = property.children[0].value;
195
+ if (names.has(key)) refuse("DUPLICATE_MANIFEST_KEY");
196
+ names.add(key);
197
+ }
198
+ }
199
+ for (const child of node.children ?? []) visit(child);
200
+ };
201
+ visit(tree);
202
+ return { tree, value: JSON.parse(text) };
203
+ }
204
+
205
+ export function bundleToken(text, slot) {
206
+ const { tree } = jsonDocument(text);
207
+ const node = findNodeAtLocation(tree, ["dsh", "profile", "bundles", slot]);
208
+ if (node?.type !== "string") refuse("INVALID_BUNDLE_SLOT");
209
+ return { offset: node.offset, length: node.length, literal: text.slice(node.offset, node.offset + node.length) };
210
+ }
211
+
212
+ export function replaceBundleToken(text, slot, name) {
213
+ const token = bundleToken(text, slot);
214
+ return text.slice(0, token.offset) + JSON.stringify(name) + text.slice(token.offset + token.length);
215
+ }
216
+
217
+ export async function loadColdProfileSdk(installAnchor) {
218
+ if (!isAbsolute(installAnchor)) refuse("ABSOLUTE_PATH_REQUIRED");
219
+ const require = createRequire(installAnchor);
220
+ const bootPath = require.resolve("@deepseek-ai/dsh-app-boot");
221
+ const includePath = require.resolve("@deepseek-ai/cordis-plugin-include");
222
+ const yamlPath = require.resolve("js-yaml");
223
+ const atomicPath = require.resolve("@deepseek-ai/dsh-atomic-write");
224
+ const exportsPath = createRequire(bootPath).resolve("resolve.exports");
225
+ const [boot, include, yaml, atomic, packageExports] = await Promise.all(
226
+ [bootPath, includePath, yamlPath, atomicPath, exportsPath].map(filename => import(pathToFileURL(filename).href)),
227
+ );
228
+ if (boot.getDshRuntimeVersion() !== "0.2.0-rc.2") refuse("UNSUPPORTED_SDK");
229
+ return { boot, include, yaml, atomic, packageExports, modulePaths: [bootPath, includePath, yamlPath, atomicPath, exportsPath] };
230
+ }
231
+
232
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url) && process.argv[2] === "--dsmm-dormant-resolution") {
233
+ try {
234
+ process.stdout.write(JSON.stringify(await resolveCapability(JSON.parse(readFileSync(0, "utf8")))));
235
+ } catch {
236
+ process.exitCode = 1;
237
+ }
238
+ }