@dsmm/dsmm 0.1.9 → 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 (553) hide show
  1. package/README.md +46 -58
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +91 -186
  3. package/agent-presets/dsmm-builder/preset.yml +1 -1
  4. package/agent-presets/dsmm-clarifier/agent.cordis.yml +120 -17
  5. package/agent-presets/dsmm-clarifier/preset.yml +1 -1
  6. package/agent-presets/dsmm-code-search/agent.cordis.yml +72 -17
  7. package/agent-presets/dsmm-code-search/preset.yml +1 -1
  8. package/agent-presets/dsmm-coding/agent.cordis.yml +169 -0
  9. package/agent-presets/dsmm-coding/preset.yml +3 -0
  10. package/agent-presets/dsmm-complex/agent.cordis.yml +154 -0
  11. package/agent-presets/dsmm-complex/preset.yml +3 -0
  12. package/agent-presets/dsmm-creative/agent.cordis.yml +122 -15
  13. package/agent-presets/dsmm-creative/preset.yml +1 -1
  14. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +179 -0
  15. package/agent-presets/dsmm-cross-cutting/preset.yml +3 -0
  16. package/agent-presets/dsmm-deep/agent.cordis.yml +189 -0
  17. package/agent-presets/dsmm-deep/preset.yml +3 -0
  18. package/agent-presets/dsmm-doc-search/agent.cordis.yml +72 -17
  19. package/agent-presets/dsmm-doc-search/preset.yml +1 -1
  20. package/agent-presets/dsmm-documenting/agent.cordis.yml +168 -0
  21. package/agent-presets/dsmm-documenting/preset.yml +3 -0
  22. package/agent-presets/dsmm-frontend/agent.cordis.yml +161 -0
  23. package/agent-presets/dsmm-frontend/preset.yml +3 -0
  24. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +153 -0
  25. package/agent-presets/dsmm-hard-reasoning/preset.yml +3 -0
  26. package/agent-presets/dsmm-media-reader/agent.cordis.yml +72 -17
  27. package/agent-presets/dsmm-media-reader/preset.yml +1 -1
  28. package/agent-presets/dsmm-normal-task/agent.cordis.yml +127 -0
  29. package/agent-presets/dsmm-normal-task/preset.yml +3 -0
  30. package/agent-presets/dsmm-oracle/agent.cordis.yml +109 -15
  31. package/agent-presets/dsmm-oracle/preset.yml +1 -1
  32. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +109 -15
  33. package/agent-presets/dsmm-oracle-2nd/preset.yml +1 -1
  34. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +174 -190
  35. package/agent-presets/dsmm-orchestrator/preset.yml +1 -1
  36. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +102 -16
  37. package/agent-presets/dsmm-plan-critic/preset.yml +1 -1
  38. package/agent-presets/dsmm-planner/agent.cordis.yml +134 -15
  39. package/agent-presets/dsmm-planner/preset.yml +1 -1
  40. package/agent-presets/dsmm-quick/agent.cordis.yml +132 -0
  41. package/agent-presets/dsmm-quick/preset.yml +3 -0
  42. package/agent-presets/dsmm-research/agent.cordis.yml +156 -0
  43. package/agent-presets/dsmm-research/preset.yml +3 -0
  44. package/agent-presets/dsmm-reviewer/agent.cordis.yml +108 -16
  45. package/agent-presets/dsmm-reviewer/preset.yml +1 -1
  46. package/cordis.patch.yml +1 -5
  47. package/docs/agent-presets.md +48 -15
  48. package/docs/compatibility.md +58 -68
  49. package/docs/deferred-native-approval-risk.md +19 -0
  50. package/docs/design.md +43 -2
  51. package/docs/lsp.md +12 -12
  52. package/docs/migration-from-ocmm.md +10 -2
  53. package/docs/model-routing.md +84 -59
  54. package/docs/native-permissions.md +35 -0
  55. package/docs/profiles.md +43 -64
  56. package/docs/releasing.md +159 -8
  57. package/docs/roadmap.md +77 -17
  58. package/docs/runtime-recovery.md +12 -0
  59. package/docs/safety-guards.md +7 -3
  60. package/docs/settings-status.md +46 -40
  61. package/docs/skill-sync.md +89 -14
  62. package/lib/child-admission-contract.d.ts +37 -0
  63. package/lib/child-admission-contract.js +2 -0
  64. package/lib/child-admission.d.ts +42 -0
  65. package/lib/child-admission.js +162 -0
  66. package/lib/child-capture.d.ts +81 -0
  67. package/lib/child-capture.js +203 -0
  68. package/lib/child-evidence.d.ts +17 -0
  69. package/lib/child-evidence.js +43 -0
  70. package/lib/client/ChildrenPanel.d.ts +43 -0
  71. package/lib/client/ChildrenPanel.js +82 -0
  72. package/lib/client/DeploymentPage.d.ts +18 -0
  73. package/lib/client/DeploymentPage.js +127 -0
  74. package/lib/client/EditableChoice.d.ts +17 -0
  75. package/lib/client/EditableChoice.js +49 -0
  76. package/lib/client/PermissionsPanel.d.ts +14 -0
  77. package/lib/client/PermissionsPanel.js +46 -0
  78. package/lib/client/ProfilesSection.js +32 -15
  79. package/lib/client/RoleAvailability.d.ts +7 -0
  80. package/lib/client/RoleAvailability.js +19 -0
  81. package/lib/client/SessionProfiles.js +27 -9
  82. package/lib/client/StructuredEditor.js +15 -7
  83. package/lib/client/children-controller.d.ts +98 -0
  84. package/lib/client/children-controller.js +296 -0
  85. package/lib/client/children-locales.d.ts +367 -0
  86. package/lib/client/children-locales.js +69 -0
  87. package/lib/client/controller.d.ts +6 -1
  88. package/lib/client/controller.js +14 -8
  89. package/lib/client/deployment-controller.d.ts +50 -0
  90. package/lib/client/deployment-controller.js +193 -0
  91. package/lib/client/deployment-data.d.ts +17 -0
  92. package/lib/client/deployment-data.js +138 -0
  93. package/lib/client/deployment-locales.d.ts +70 -0
  94. package/lib/client/deployment-locales.js +81 -0
  95. package/lib/client/diagnostics.d.ts +14 -0
  96. package/lib/client/diagnostics.js +53 -0
  97. package/lib/client/index.d.ts +4 -0
  98. package/lib/client/index.js +145 -1
  99. package/lib/client/locales.d.ts +58 -0
  100. package/lib/client/locales.js +38 -18
  101. package/lib/client/permission-client.d.ts +16 -0
  102. package/lib/client/permission-client.js +38 -0
  103. package/lib/client/permission-controller.d.ts +62 -0
  104. package/lib/client/permission-controller.js +149 -0
  105. package/lib/client/permission-locales.d.ts +114 -0
  106. package/lib/client/permission-locales.js +75 -0
  107. package/lib/client/plugins-contract.d.ts +27 -0
  108. package/lib/client/plugins-contract.js +2 -0
  109. package/lib/client/session-labels.js +4 -4
  110. package/lib/client/structured.js +19 -5
  111. package/lib/client/styles.d.ts +1 -1
  112. package/lib/client/styles.js +36 -0
  113. package/lib/client.js +6724 -1604
  114. package/lib/commands.js +3 -0
  115. package/lib/config-file-store.d.ts +23 -0
  116. package/lib/config-file-store.js +67 -0
  117. package/lib/core-permission-authority.d.ts +18 -0
  118. package/lib/core-permission-authority.js +255 -0
  119. package/lib/core-permissions.d.ts +8 -0
  120. package/lib/core-permissions.js +33 -0
  121. package/lib/delivery-authority.d.ts +68 -0
  122. package/lib/delivery-authority.js +260 -0
  123. package/lib/deployment-config.d.ts +60 -0
  124. package/lib/deployment-config.js +205 -0
  125. package/lib/deployment-permission-rules.d.ts +55 -0
  126. package/lib/deployment-permission-rules.js +306 -0
  127. package/lib/dsh-home.d.ts +3 -0
  128. package/lib/dsh-home.js +10 -0
  129. package/lib/dsh-types.d.ts +22 -69
  130. package/lib/guards.d.ts +3 -2
  131. package/lib/guards.js +44 -6
  132. package/lib/host-llm-startup.d.ts +41 -0
  133. package/lib/host-llm-startup.js +65 -0
  134. package/lib/host-llm.d.ts +92 -0
  135. package/lib/host-llm.js +325 -0
  136. package/lib/index.d.ts +23 -5
  137. package/lib/index.js +383 -40
  138. package/lib/legacy-child-policy.d.ts +51 -0
  139. package/lib/legacy-child-policy.js +123 -0
  140. package/lib/legacy-read-composition.d.ts +20 -0
  141. package/lib/legacy-read-composition.js +144 -0
  142. package/lib/legacy-read-contracts.d.ts +157 -0
  143. package/lib/legacy-read-contracts.js +39 -0
  144. package/lib/legacy-read-host.d.ts +19 -0
  145. package/lib/legacy-read-host.js +67 -0
  146. package/lib/legacy-read-integration.d.ts +121 -0
  147. package/lib/legacy-read-integration.js +522 -0
  148. package/lib/legacy-read-proxy.d.ts +26 -0
  149. package/lib/legacy-read-proxy.js +237 -0
  150. package/lib/live-pi-ai-owner.d.ts +18 -0
  151. package/lib/live-pi-ai-owner.js +144 -0
  152. package/lib/llm-runtime.d.ts +11 -0
  153. package/lib/llm-runtime.js +21 -0
  154. package/lib/lsp.d.ts +13 -0
  155. package/lib/lsp.js +60 -0
  156. package/lib/managed-settings.d.ts +5 -0
  157. package/lib/managed-settings.js +14 -0
  158. package/lib/mode.js +42 -47
  159. package/lib/model-parameter-policy.d.ts +11 -0
  160. package/lib/model-parameter-policy.js +27 -0
  161. package/lib/model-routing.js +33 -19
  162. package/lib/modules.d.ts +35 -0
  163. package/lib/modules.js +37 -0
  164. package/lib/native-child-evidence.d.ts +42 -0
  165. package/lib/native-child-evidence.js +133 -0
  166. package/lib/native-pi-ai-wire.d.ts +37 -0
  167. package/lib/native-pi-ai-wire.js +261 -0
  168. package/lib/native-scope.d.ts +9 -0
  169. package/lib/native-scope.js +20 -0
  170. package/lib/permission-bash.d.ts +6 -0
  171. package/lib/permission-bash.js +7 -0
  172. package/lib/permission-control.d.ts +73 -0
  173. package/lib/permission-control.js +205 -0
  174. package/lib/permission-controller.d.ts +68 -0
  175. package/lib/permission-controller.js +317 -0
  176. package/lib/permission-errors.d.ts +7 -0
  177. package/lib/permission-errors.js +21 -0
  178. package/lib/permission-fs-search.d.ts +5 -0
  179. package/lib/permission-fs-search.js +7 -0
  180. package/lib/permission-fs.d.ts +5 -0
  181. package/lib/permission-fs.js +7 -0
  182. package/lib/permission-native-access.d.ts +11 -0
  183. package/lib/permission-native-access.js +6 -0
  184. package/lib/permission-native-command.d.ts +10 -0
  185. package/lib/permission-native-command.js +93 -0
  186. package/lib/permission-native-rules.d.ts +75 -0
  187. package/lib/permission-native-rules.js +278 -0
  188. package/lib/permission-pwsh.d.ts +6 -0
  189. package/lib/permission-pwsh.js +7 -0
  190. package/lib/permission-remote.d.ts +26 -0
  191. package/lib/permission-remote.js +53 -0
  192. package/lib/permission-rpc.d.ts +29 -0
  193. package/lib/permission-rpc.js +152 -0
  194. package/lib/permission-rules.d.ts +115 -0
  195. package/lib/permission-rules.js +256 -0
  196. package/lib/permission-settings.d.ts +45 -0
  197. package/lib/permission-settings.js +48 -0
  198. package/lib/permission-shell.d.ts +38 -0
  199. package/lib/permission-shell.js +150 -0
  200. package/lib/permission-web.d.ts +5 -0
  201. package/lib/permission-web.js +7 -0
  202. package/lib/plan-validation.js +6 -44
  203. package/lib/preset-materializer.js +2 -0
  204. package/lib/preset-registry.d.ts +1 -1
  205. package/lib/preset-registry.js +38 -24
  206. package/lib/preset-skills.d.ts +4 -1
  207. package/lib/preset-skills.js +60 -19
  208. package/lib/profile-diagnostics.d.ts +45 -0
  209. package/lib/profile-diagnostics.js +148 -0
  210. package/lib/profile-locale.d.ts +3 -0
  211. package/lib/profile-locale.js +2 -0
  212. package/lib/profile-remote.d.ts +22 -0
  213. package/lib/profile-remote.js +344 -27
  214. package/lib/profile-rpc.d.ts +25 -1
  215. package/lib/profile-rpc.js +143 -3
  216. package/lib/profile-runtime.d.ts +63 -0
  217. package/lib/profile-runtime.js +496 -77
  218. package/lib/profile-store.d.ts +56 -1
  219. package/lib/profile-store.js +377 -111
  220. package/lib/profile-types.d.ts +125 -1
  221. package/lib/profile-types.js +1 -0
  222. package/lib/profiles.d.ts +16 -2
  223. package/lib/profiles.js +156 -79
  224. package/lib/prompt-content.d.ts +25 -0
  225. package/lib/prompt-content.js +27 -0
  226. package/lib/prompts.d.ts +45 -4
  227. package/lib/prompts.js +157 -43
  228. package/lib/recovery-policy.js +20 -7
  229. package/lib/role-control-remote.d.ts +38 -0
  230. package/lib/role-control-remote.js +211 -0
  231. package/lib/role-control-rpc.d.ts +51 -0
  232. package/lib/role-control-rpc.js +377 -0
  233. package/lib/role-control-types.d.ts +92 -0
  234. package/lib/role-control-types.js +8 -0
  235. package/lib/role-invocation.d.ts +47 -0
  236. package/lib/role-invocation.js +135 -0
  237. package/lib/role-llm-runtime.d.ts +17 -0
  238. package/lib/role-llm-runtime.js +62 -0
  239. package/lib/role-llm.d.ts +31 -0
  240. package/lib/role-llm.js +66 -0
  241. package/lib/role-policy.d.ts +92 -0
  242. package/lib/role-policy.js +601 -0
  243. package/lib/role-providers.d.ts +7 -3
  244. package/lib/role-providers.js +74 -46
  245. package/lib/role-routing.d.ts +11 -2
  246. package/lib/role-routing.js +42 -25
  247. package/lib/role-runs.d.ts +135 -0
  248. package/lib/role-runs.js +304 -0
  249. package/lib/role-subagents.d.ts +63 -4
  250. package/lib/role-subagents.js +299 -47
  251. package/lib/roles.d.ts +20 -9
  252. package/lib/roles.js +87 -216
  253. package/lib/route-json.d.ts +19 -0
  254. package/lib/route-json.js +129 -0
  255. package/lib/routing-policy.d.ts +2 -0
  256. package/lib/routing-policy.js +12 -2
  257. package/lib/runtime-integration.d.ts +112 -0
  258. package/lib/runtime-integration.js +784 -0
  259. package/lib/runtime-recovery.js +34 -13
  260. package/lib/session-scope.js +2 -0
  261. package/lib/settings.d.ts +116 -14
  262. package/lib/settings.js +455 -149
  263. package/lib/skills.d.ts +24 -9
  264. package/lib/skills.js +114 -35
  265. package/lib/state.d.ts +10 -6
  266. package/lib/state.js +48 -49
  267. package/lib/status.d.ts +35 -1
  268. package/lib/status.js +58 -17
  269. package/lib/subagent-runtime.d.ts +45 -0
  270. package/lib/subagent-runtime.js +131 -0
  271. package/locale/en.json +2 -2
  272. package/locale/zh.json +2 -2
  273. package/package.json +112 -45
  274. package/patches/subagent-runtime.yml +15 -0
  275. package/prompts/deepseek-flash.md +1 -1
  276. package/prompts/deepseek-v4-pro.md +2 -2
  277. package/prompts/deepwork.md +153 -20
  278. package/prompts/source/agents/clarifier.md +47 -0
  279. package/prompts/source/agents/orchestrator.md +72 -0
  280. package/prompts/source/agents/plan-critic.md +29 -0
  281. package/prompts/source/agents/planner.md +21 -0
  282. package/prompts/source/agents/reviewer.md +23 -0
  283. package/prompts/source/catalog.json +548 -0
  284. package/prompts/source/category/coding.md +46 -0
  285. package/prompts/source/category/complex.md +29 -0
  286. package/prompts/source/category/creative.md +40 -0
  287. package/prompts/source/category/cross-cutting.md +54 -0
  288. package/prompts/source/category/deep.md +64 -0
  289. package/prompts/source/category/documenting.md +68 -0
  290. package/prompts/source/category/frontend.md +38 -0
  291. package/prompts/source/category/hard-reasoning.md +53 -0
  292. package/prompts/source/category/normal-task.md +27 -0
  293. package/prompts/source/category/quick.md +34 -0
  294. package/prompts/source/category/research.md +58 -0
  295. package/prompts/source/deepwork/claude-opus-5.md +28 -0
  296. package/prompts/source/deepwork/codex.md +9 -0
  297. package/prompts/source/deepwork/default.md +136 -0
  298. package/prompts/source/deepwork/gemini.md +191 -0
  299. package/prompts/source/deepwork/glm.md +263 -0
  300. package/prompts/source/deepwork/gpt.md +49 -0
  301. package/prompts/source/deepwork/kimi-k27.md +13 -0
  302. package/prompts/source/deepwork/planner.md +44 -0
  303. package/prompts/source/deepwork/swe-2.md +13 -0
  304. package/prompts/source/manifest.json +3233 -0
  305. package/prompts/source/shared/dsh-host-contract.md +8 -0
  306. package/prompts/source/shared/locale.md +8 -0
  307. package/prompts/source/shared/shell-safety.md +7 -0
  308. package/prompts/source/terminal/builder.md +13 -0
  309. package/prompts/source/terminal/clarifier.md +41 -0
  310. package/prompts/source/terminal/code-search.md +39 -0
  311. package/prompts/source/terminal/coding.md +41 -0
  312. package/prompts/source/terminal/complex.md +43 -0
  313. package/prompts/source/terminal/creative.md +41 -0
  314. package/prompts/source/terminal/cross-cutting.md +43 -0
  315. package/prompts/source/terminal/deep.md +43 -0
  316. package/prompts/source/terminal/doc-search.md +39 -0
  317. package/prompts/source/terminal/documenting.md +41 -0
  318. package/prompts/source/terminal/frontend.md +41 -0
  319. package/prompts/source/terminal/hard-reasoning.md +41 -0
  320. package/prompts/source/terminal/media-reader.md +39 -0
  321. package/prompts/source/terminal/normal-task.md +41 -0
  322. package/prompts/source/terminal/oracle-2nd.md +53 -0
  323. package/prompts/source/terminal/oracle.md +53 -0
  324. package/prompts/source/terminal/orchestrator.md +26 -0
  325. package/prompts/source/terminal/plan-critic.md +41 -0
  326. package/prompts/source/terminal/planner.md +42 -0
  327. package/prompts/source/terminal/quick.md +39 -0
  328. package/prompts/source/terminal/research.md +39 -0
  329. package/prompts/source/terminal/reviewer.md +53 -0
  330. package/scripts/cold-profile-composition.mjs +329 -0
  331. package/scripts/cold-profile-sources.mjs +238 -0
  332. package/scripts/migrate-cold-profile.mjs +315 -0
  333. package/skills/ast-grep/LICENSE +21 -0
  334. package/skills/ast-grep/README.md +138 -0
  335. package/skills/ast-grep/SKILL.md +287 -0
  336. package/skills/ast-grep/SOURCE +1 -0
  337. package/skills/ast-grep/install.ps1 +235 -0
  338. package/skills/ast-grep/install.sh +286 -0
  339. package/skills/ast-grep/references/cli.md +233 -0
  340. package/skills/ast-grep/references/install.md +168 -0
  341. package/skills/ast-grep/references/patterns.md +149 -0
  342. package/skills/ast-grep/references/pitfalls.md +305 -0
  343. package/skills/ast-grep/references/recipes.md +404 -0
  344. package/skills/ast-grep/references/sgconfig.md +250 -0
  345. package/skills/ast-grep/references/yaml-rules.md +511 -0
  346. package/skills/ast-grep/scripts/ast_grep_helper.py +760 -0
  347. package/skills/ast-grep/tests/smoke.ps1 +129 -0
  348. package/skills/ast-grep/tests/smoke.sh +212 -0
  349. package/skills/ast-grep/tests/test_resolver.py +154 -0
  350. package/skills/brainstorming/SKILL.md +123 -9
  351. package/skills/coding-agent-sessions/LICENSE-UPSTREAM.md +82 -0
  352. package/skills/coding-agent-sessions/NOTICE.md +24 -0
  353. package/skills/coding-agent-sessions/SKILL.md +147 -0
  354. package/skills/coding-agent-sessions/agents/openai.yaml +4 -0
  355. package/skills/coding-agent-sessions/pyrightconfig.json +5 -0
  356. package/skills/coding-agent-sessions/references/all-platforms.md +77 -0
  357. package/skills/coding-agent-sessions/references/claude.md +34 -0
  358. package/skills/coding-agent-sessions/references/codex.md +32 -0
  359. package/skills/coding-agent-sessions/references/opencode.md +45 -0
  360. package/skills/coding-agent-sessions/references/senpi.md +29 -0
  361. package/skills/coding-agent-sessions/scripts/agent_sessions/__init__.py +1 -0
  362. package/skills/coding-agent-sessions/scripts/agent_sessions/aside_scanner.py +140 -0
  363. package/skills/coding-agent-sessions/scripts/agent_sessions/claude.py +66 -0
  364. package/skills/coding-agent-sessions/scripts/agent_sessions/cli.py +283 -0
  365. package/skills/coding-agent-sessions/scripts/agent_sessions/codex.py +105 -0
  366. package/skills/coding-agent-sessions/scripts/agent_sessions/file_scanners.py +275 -0
  367. package/skills/coding-agent-sessions/scripts/agent_sessions/jsonio.py +55 -0
  368. package/skills/coding-agent-sessions/scripts/agent_sessions/kiro_scanner.py +91 -0
  369. package/skills/coding-agent-sessions/scripts/agent_sessions/opencode.py +289 -0
  370. package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -0
  371. package/skills/coding-agent-sessions/scripts/agent_sessions/scanners.py +104 -0
  372. package/skills/coding-agent-sessions/scripts/agent_sessions/sqlite_optional_scanners.py +203 -0
  373. package/skills/coding-agent-sessions/scripts/agent_sessions/sqlite_scanners.py +177 -0
  374. package/skills/coding-agent-sessions/scripts/agent_sessions/timeparse.py +51 -0
  375. package/skills/coding-agent-sessions/scripts/agent_sessions/transcript.py +149 -0
  376. package/skills/coding-agent-sessions/scripts/agent_sessions/types.py +57 -0
  377. package/skills/coding-agent-sessions/scripts/find-agent-sessions.py +19 -0
  378. package/skills/coding-agent-sessions/scripts/tests/test_agent_sessions.py +322 -0
  379. package/skills/coding-agent-sessions/scripts/tests/test_aside_scanner.py +131 -0
  380. package/skills/coding-agent-sessions/scripts/tests/test_cli_contract.py +126 -0
  381. package/skills/coding-agent-sessions/scripts/tests/test_extended_scanners.py +262 -0
  382. package/skills/coding-agent-sessions/scripts/tests/test_optional_sqlite_scanners.py +79 -0
  383. package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -0
  384. package/skills/debugging/SKILL.md +130 -4
  385. package/skills/debugging/references/logging.md +2 -0
  386. package/skills/debugging/references/methodology/00-setup.md +16 -62
  387. package/skills/debugging/references/methodology/02-investigate.md +11 -5
  388. package/skills/debugging/references/methodology/03-flaky-triage.md +6 -4
  389. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +6 -16
  390. package/skills/debugging/references/methodology/05-escalate.md +2 -0
  391. package/skills/debugging/references/methodology/06-fix.md +8 -6
  392. package/skills/debugging/references/methodology/08-qa.md +7 -5
  393. package/skills/debugging/references/methodology/09-cleanup.md +16 -152
  394. package/skills/debugging/references/methodology/partial-runtime-evidence.md +7 -18
  395. package/skills/debugging/references/runtimes/bundled-js-binary.md +3 -16
  396. package/skills/debugging/references/runtimes/go.md +2 -0
  397. package/skills/debugging/references/runtimes/native-binary.md +11 -54
  398. package/skills/debugging/references/runtimes/node.md +6 -15
  399. package/skills/debugging/references/runtimes/python.md +5 -15
  400. package/skills/debugging/references/runtimes/rust.md +4 -18
  401. package/skills/debugging/references/scripts/dap.test.mjs +539 -0
  402. package/skills/debugging/references/scripts/fixture-adapter.mjs +164 -0
  403. package/skills/debugging/references/tools/dap.md +4 -2
  404. package/skills/debugging/references/tools/ghidra.md +6 -15
  405. package/skills/debugging/references/tools/playwright-cli.md +5 -15
  406. package/skills/debugging/references/tools/pwndbg.md +2 -0
  407. package/skills/debugging/references/tools/pwntools.md +6 -16
  408. package/skills/dispatching-parallel-agents/SKILL.md +96 -7
  409. package/skills/frontend/.frontend-materialized.json +856 -0
  410. package/skills/frontend/ATTRIBUTION.md +37 -0
  411. package/skills/frontend/LICENSE-Apache-2.0.txt +201 -0
  412. package/skills/frontend/LICENSE-taste-skill.txt +21 -0
  413. package/skills/frontend/LICENSE-ui-ux-pro-max.txt +21 -0
  414. package/skills/frontend/SKILL.md +145 -0
  415. package/skills/frontend/references/design/README.md +256 -0
  416. package/skills/frontend/references/design/_INDEX.md +206 -0
  417. package/skills/frontend/references/design/airbnb.md +393 -0
  418. package/skills/frontend/references/design/airtable.md +92 -0
  419. package/skills/frontend/references/design/apple.md +250 -0
  420. package/skills/frontend/references/design/aside.md +211 -0
  421. package/skills/frontend/references/design/binance.md +348 -0
  422. package/skills/frontend/references/design/bmw.md +183 -0
  423. package/skills/frontend/references/design/brutalist-skill.md +92 -0
  424. package/skills/frontend/references/design/bugatti.md +271 -0
  425. package/skills/frontend/references/design/cal.md +262 -0
  426. package/skills/frontend/references/design/claude.md +315 -0
  427. package/skills/frontend/references/design/clay.md +307 -0
  428. package/skills/frontend/references/design/clickhouse.md +284 -0
  429. package/skills/frontend/references/design/clone-from-url.md +69 -0
  430. package/skills/frontend/references/design/cohere.md +269 -0
  431. package/skills/frontend/references/design/coinbase.md +132 -0
  432. package/skills/frontend/references/design/composio.md +310 -0
  433. package/skills/frontend/references/design/cursor.md +312 -0
  434. package/skills/frontend/references/design/design-system-architecture.md +250 -0
  435. package/skills/frontend/references/design/elevenlabs.md +268 -0
  436. package/skills/frontend/references/design/expo.md +284 -0
  437. package/skills/frontend/references/design/ferrari.md +317 -0
  438. package/skills/frontend/references/design/figma.md +223 -0
  439. package/skills/frontend/references/design/framer.md +249 -0
  440. package/skills/frontend/references/design/gpt-tasteskill.md +74 -0
  441. package/skills/frontend/references/design/hashicorp.md +281 -0
  442. package/skills/frontend/references/design/ibm.md +335 -0
  443. package/skills/frontend/references/design/image-to-code-skill.md +1228 -0
  444. package/skills/frontend/references/design/imagegen-brandkit.md +798 -0
  445. package/skills/frontend/references/design/imagegen-frontend-mobile.md +1465 -0
  446. package/skills/frontend/references/design/imagegen-frontend-web.md +987 -0
  447. package/skills/frontend/references/design/interaction-skill.md +52 -0
  448. package/skills/frontend/references/design/intercom.md +149 -0
  449. package/skills/frontend/references/design/kraken.md +128 -0
  450. package/skills/frontend/references/design/lamborghini.md +291 -0
  451. package/skills/frontend/references/design/linear.app.md +370 -0
  452. package/skills/frontend/references/design/lovable.md +301 -0
  453. package/skills/frontend/references/design/mastercard.md +368 -0
  454. package/skills/frontend/references/design/meta.md +369 -0
  455. package/skills/frontend/references/design/minimalist-skill.md +85 -0
  456. package/skills/frontend/references/design/minimax.md +260 -0
  457. package/skills/frontend/references/design/mintlify.md +329 -0
  458. package/skills/frontend/references/design/miro.md +111 -0
  459. package/skills/frontend/references/design/mistral.ai.md +264 -0
  460. package/skills/frontend/references/design/mongodb.md +269 -0
  461. package/skills/frontend/references/design/nike.md +366 -0
  462. package/skills/frontend/references/design/notion.md +312 -0
  463. package/skills/frontend/references/design/nvidia.md +296 -0
  464. package/skills/frontend/references/design/ollama.md +270 -0
  465. package/skills/frontend/references/design/opencode.ai.md +284 -0
  466. package/skills/frontend/references/design/output-skill.md +49 -0
  467. package/skills/frontend/references/design/pinterest.md +233 -0
  468. package/skills/frontend/references/design/playstation.md +367 -0
  469. package/skills/frontend/references/design/posthog.md +259 -0
  470. package/skills/frontend/references/design/raycast.md +271 -0
  471. package/skills/frontend/references/design/react-dev-tooling-skill.md +232 -0
  472. package/skills/frontend/references/design/redesign-skill.md +178 -0
  473. package/skills/frontend/references/design/renault.md +314 -0
  474. package/skills/frontend/references/design/replicate.md +264 -0
  475. package/skills/frontend/references/design/resend.md +306 -0
  476. package/skills/frontend/references/design/revolut.md +188 -0
  477. package/skills/frontend/references/design/runwayml.md +247 -0
  478. package/skills/frontend/references/design/sanity.md +360 -0
  479. package/skills/frontend/references/design/sentry.md +265 -0
  480. package/skills/frontend/references/design/shopify.md +353 -0
  481. package/skills/frontend/references/design/soft-skill.md +98 -0
  482. package/skills/frontend/references/design/spacex.md +197 -0
  483. package/skills/frontend/references/design/spotify.md +249 -0
  484. package/skills/frontend/references/design/starbucks.md +583 -0
  485. package/skills/frontend/references/design/stitch-design-example.md +121 -0
  486. package/skills/frontend/references/design/stitch-skill.md +184 -0
  487. package/skills/frontend/references/design/stripe.md +325 -0
  488. package/skills/frontend/references/design/supabase.md +258 -0
  489. package/skills/frontend/references/design/superhuman.md +255 -0
  490. package/skills/frontend/references/design/taste-skill.md +1206 -0
  491. package/skills/frontend/references/design/tesla.md +289 -0
  492. package/skills/frontend/references/design/theverge.md +342 -0
  493. package/skills/frontend/references/design/together.ai.md +266 -0
  494. package/skills/frontend/references/design/uber.md +298 -0
  495. package/skills/frontend/references/design/vercel.md +313 -0
  496. package/skills/frontend/references/design/vodafone.md +426 -0
  497. package/skills/frontend/references/design/voltagent.md +326 -0
  498. package/skills/frontend/references/design/warp.md +256 -0
  499. package/skills/frontend/references/design/webflow.md +95 -0
  500. package/skills/frontend/references/design/wired.md +281 -0
  501. package/skills/frontend/references/design/wise.md +176 -0
  502. package/skills/frontend/references/design/x.ai.md +260 -0
  503. package/skills/frontend/references/design/zapier.md +331 -0
  504. package/skills/frontend/references/perfection/README.md +264 -0
  505. package/skills/frontend/references/perfection/react-perf-tooling.md +234 -0
  506. package/skills/frontend/references/ui-ux-db/README.md +659 -0
  507. package/skills/frontend/references/ui-ux-db/data/app-interface.csv +31 -0
  508. package/skills/frontend/references/ui-ux-db/data/charts.csv +26 -0
  509. package/skills/frontend/references/ui-ux-db/data/colors.csv +162 -0
  510. package/skills/frontend/references/ui-ux-db/data/google-fonts.csv +1924 -0
  511. package/skills/frontend/references/ui-ux-db/data/icons.csv +106 -0
  512. package/skills/frontend/references/ui-ux-db/data/landing.csv +35 -0
  513. package/skills/frontend/references/ui-ux-db/data/products.csv +162 -0
  514. package/skills/frontend/references/ui-ux-db/data/react-performance.csv +45 -0
  515. package/skills/frontend/references/ui-ux-db/data/stacks/angular.csv +51 -0
  516. package/skills/frontend/references/ui-ux-db/data/stacks/astro.csv +54 -0
  517. package/skills/frontend/references/ui-ux-db/data/stacks/flutter.csv +53 -0
  518. package/skills/frontend/references/ui-ux-db/data/stacks/html-tailwind.csv +56 -0
  519. package/skills/frontend/references/ui-ux-db/data/stacks/jetpack-compose.csv +53 -0
  520. package/skills/frontend/references/ui-ux-db/data/stacks/laravel.csv +51 -0
  521. package/skills/frontend/references/ui-ux-db/data/stacks/nextjs.csv +53 -0
  522. package/skills/frontend/references/ui-ux-db/data/stacks/nuxt-ui.csv +51 -0
  523. package/skills/frontend/references/ui-ux-db/data/stacks/nuxtjs.csv +59 -0
  524. package/skills/frontend/references/ui-ux-db/data/stacks/react-native.csv +52 -0
  525. package/skills/frontend/references/ui-ux-db/data/stacks/react.csv +54 -0
  526. package/skills/frontend/references/ui-ux-db/data/stacks/shadcn.csv +61 -0
  527. package/skills/frontend/references/ui-ux-db/data/stacks/svelte.csv +54 -0
  528. package/skills/frontend/references/ui-ux-db/data/stacks/swiftui.csv +51 -0
  529. package/skills/frontend/references/ui-ux-db/data/stacks/threejs.csv +54 -0
  530. package/skills/frontend/references/ui-ux-db/data/stacks/vue.csv +50 -0
  531. package/skills/frontend/references/ui-ux-db/data/styles.csv +85 -0
  532. package/skills/frontend/references/ui-ux-db/data/typography.csv +74 -0
  533. package/skills/frontend/references/ui-ux-db/data/ui-reasoning.csv +162 -0
  534. package/skills/frontend/references/ui-ux-db/data/ux-guidelines.csv +100 -0
  535. package/skills/frontend/references/ui-ux-db/data/web-interface.csv +31 -0
  536. package/skills/frontend/references/ui-ux-db/scripts/core.py +262 -0
  537. package/skills/frontend/references/ui-ux-db/scripts/design_system.py +1148 -0
  538. package/skills/frontend/references/ui-ux-db/scripts/search.py +114 -0
  539. package/skills/frontend/scripts/perfection/lighthouse-audit.py +201 -0
  540. package/skills/git-master/SKILL.md +115 -0
  541. package/skills/git-master/agents/openai.yaml +13 -0
  542. package/skills/init-deep/SKILL.md +282 -0
  543. package/skills/receiving-code-review/SKILL.md +117 -7
  544. package/skills/remove-ai-slops/SKILL.md +160 -8
  545. package/skills/requesting-code-review/SKILL.md +98 -3
  546. package/skills/requesting-code-review/code-reviewer.md +59 -0
  547. package/skills/subagent-driven-development/SKILL.md +179 -6
  548. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +23 -0
  549. package/skills/subagent-driven-development/implementer-prompt.md +87 -0
  550. package/skills/subagent-driven-development/spec-reviewer-prompt.md +37 -0
  551. package/skills/using-git-worktrees/SKILL.md +144 -0
  552. package/skills/writing-plans/SKILL.md +126 -7
  553. package/skills/writing-plans/plan-document-reviewer-prompt.md +47 -0
@@ -3,26 +3,67 @@ import { createHash, randomUUID } from "node:crypto";
3
3
  import { basename, dirname, isAbsolute, join, parse, resolve } from "node:path";
4
4
  import { parseTree } from "jsonc-parser";
5
5
  import { ABSENT_PROFILE_SELECTION_REVISION } from "./profile-types.js";
6
- import { DsmmProfileError, MAX_PROFILE_BYTES, MAX_PROFILE_COUNT, MAX_PROFILE_DIRECTORY_ENTRIES, MAX_PROFILE_REVISIONS, parseProfileDocument, profileErrorInfo, validateProfileId, validateProfileRevision } from "./profiles.js";
6
+ import { DsmmProfileError, MAX_PROFILE_BYTES, MAX_PROFILE_COUNT, MAX_PROFILE_DIRECTORY_ENTRIES, MAX_PROFILE_REVISIONS, parseProfileDocument, validateProfileDocument, profileErrorInfo, validateProfileId, validateProfileRevision } from "./profiles.js";
7
+ import { inspectJsonDocument } from "./profile-diagnostics.js";
8
+ import { parseChildAdmissionCapture } from "./child-capture.js";
7
9
  export const MAX_SESSION_PROFILE_CHOICES = 1024;
10
+ const trustedLayout = Symbol("trusted profile storage layout");
11
+ const LEGACY_WRITE_RESTRICTION = "Legacy profiles are read-only. Explicitly import them before saving or changing selections.";
8
12
  /** This directory is supplied by the Host, never by a remote method parameter. */
9
13
  export class ProfileStore {
10
14
  profileDir;
15
+ stateDir;
11
16
  timeoutMs;
12
17
  pollMs;
13
18
  rename;
14
19
  rootIdentity;
20
+ origin;
21
+ hostProfile;
22
+ identities = new Map();
15
23
  constructor(profileDir, options = {}) {
16
- if (!isAbsolute(profileDir) || dirname(resolve(profileDir)) === resolve(profileDir) || basename(resolve(profileDir)) !== "dsmm-profiles") {
24
+ const layout = options[trustedLayout];
25
+ if (!isAbsolute(profileDir) || dirname(resolve(profileDir)) === resolve(profileDir) || (layout === undefined && basename(resolve(profileDir)) !== "dsmm-profiles")) {
17
26
  throw new DsmmProfileError("unsafe-path", "The Host must supply its native profile's dsmm-profiles directory.");
18
27
  }
19
28
  this.profileDir = resolve(profileDir);
29
+ this.stateDir = layout?.stateDir ?? this.profileDir;
30
+ this.origin = layout?.origin ?? "explicit";
31
+ this.hostProfile = layout?.hostProfile;
20
32
  this.timeoutMs = boundedOption(options.lockTimeoutMs, 2000, 0, 30000);
21
33
  this.pollMs = boundedOption(options.lockPollMs, 25, 1, 1000);
22
34
  this.rename = options.rename ?? renameSync;
23
35
  }
36
+ static fromCentral(home, canonicalHostProfile, actualEntryId, options = {}) {
37
+ const root = trustedHome(home);
38
+ validateTrustedDirectoryPath(canonicalHostProfile);
39
+ if (resolve(canonicalHostProfile) !== canonicalHostProfile)
40
+ throw new DsmmProfileError("unsafe-path", "A canonical Host profile identity is required.");
41
+ validateDirectories(canonicalHostProfile, false);
42
+ if (typeof actualEntryId !== "string" || actualEntryId.length < 1 || actualEntryId.length > 256 || actualEntryId.trim().length === 0
43
+ || /[\u0000-\u001f\u007f]/u.test(actualEntryId) || Buffer.from(actualEntryId, "utf8").toString("utf8") !== actualEntryId) {
44
+ throw new DsmmProfileError("validation", "A bounded native entry identity is required.", "actualEntryId");
45
+ }
46
+ const identity = process.platform === "win32" ? canonicalHostProfile.toLowerCase() : canonicalHostProfile;
47
+ const profileDir = join(root, "plugins", "dsmm", "profiles");
48
+ const stateDir = join(profileDir, ".state", digest(Buffer.from(JSON.stringify([identity, actualEntryId]), "utf8")));
49
+ const trusted = { ...options, [trustedLayout]: { origin: "central", stateDir, hostProfile: canonicalHostProfile } };
50
+ const store = new ProfileStore(profileDir, trusted);
51
+ store.validateRoot(false);
52
+ store.validateState(false);
53
+ return store;
54
+ }
55
+ static fromLegacy(legacyDir, options = {}) {
56
+ validateTrustedDirectoryPath(legacyDir);
57
+ if (basename(resolve(legacyDir)) !== "dsmm-profiles")
58
+ throw new DsmmProfileError("unsafe-path", "The legacy store must be the Host's exact dsmm-profiles directory.");
59
+ const root = resolve(legacyDir);
60
+ const trusted = { ...options, [trustedLayout]: { origin: "legacy", stateDir: root } };
61
+ const store = new ProfileStore(root, trusted);
62
+ store.validateRoot(false);
63
+ return store;
64
+ }
24
65
  async describe() {
25
- return this.locked(() => {
66
+ return this.readOperation(() => {
26
67
  const entries = this.inventory();
27
68
  const profiles = entries.map((name) => {
28
69
  const id = name.slice(0, -6);
@@ -31,7 +72,7 @@ export class ProfileStore {
31
72
  if (name !== `${id}.jsonc`)
32
73
  throw new DsmmProfileError("unsafe-path", "Profile filename must use lowercase .jsonc and match its ID.");
33
74
  const draft = this.draft(id, entries);
34
- return { id, ...(draft.document.label === undefined ? {} : { label: draft.document.label }), revision: draft.revision };
75
+ return { id, ...(draft.document.label === undefined ? {} : { label: draft.document.label.trim() === "" ? id : draft.document.label }), revision: draft.revision, ...warningFields(draft) };
35
76
  }
36
77
  catch (error) {
37
78
  return { id: safeInventoryId(id), revision: null, error: profileErrorInfo(error) };
@@ -39,21 +80,23 @@ export class ProfileStore {
39
80
  });
40
81
  try {
41
82
  const selected = this.selection();
42
- return { profiles, selectedId: selected.selectedId, appliedRevision: selected.appliedRevision, selectionRevision: selected.selectionRevision };
83
+ return { ...this.metadata(), profiles, selectedId: selected.selectedId, appliedRevision: selected.appliedRevision, selectionRevision: selected.selectionRevision, ...(selected.warnings === undefined ? {} : { selectedWarnings: selected.warnings }) };
43
84
  }
44
85
  catch (error) {
45
86
  // An error is not a successful fallback to the baseline.
46
- return { profiles, selectedId: null, appliedRevision: null, selectionRevision: "unavailable", selectionError: profileErrorInfo(error, "corrupt-selection") };
87
+ return { ...this.metadata(), profiles, selectedId: null, appliedRevision: null, selectionRevision: "unavailable", selectionError: profileErrorInfo(error, "corrupt-selection") };
47
88
  }
48
89
  });
49
90
  }
50
91
  async read(id) {
51
92
  validateProfileId(id);
52
- return this.locked(() => this.readResult(this.draft(id, this.inventory())));
93
+ return this.readOperation(() => this.readResult(this.draft(id, this.inventory())));
53
94
  }
54
95
  async save(request) {
96
+ this.assertWritable();
55
97
  validateProfileId(request.id);
56
98
  const document = parseProfileDocument(request.content, request.id);
99
+ const warnings = validateProfileDocument(request.content, request.id).diagnostics;
57
100
  if (request.expectedRevision !== null)
58
101
  validateProfileRevision(request.expectedRevision);
59
102
  return this.locked((assertLock) => {
@@ -72,17 +115,18 @@ export class ProfileStore {
72
115
  if (latest !== request.expectedRevision)
73
116
  conflict("The profile was edited externally during save. Reload it before saving.");
74
117
  }, assertLock);
75
- return this.readResult({ bytes, content: request.content, revision: digest(bytes), document });
118
+ return this.readResult({ bytes, content: request.content, revision: digest(bytes), document, ...(warnings.length ? { warnings } : {}) });
76
119
  });
77
120
  }
78
121
  async loadSelection() {
79
- return this.locked(() => this.selection());
122
+ return this.readOperation(() => this.selection());
80
123
  }
81
124
  async loadSessionSelection(sessionId) {
82
125
  validateSessionProfileId(sessionId);
83
- return this.locked(() => this.sessionSelection(sessionId));
126
+ return this.readOperation(() => this.sessionSelection(sessionId));
84
127
  }
85
128
  async selectSession(request, epoch, validateCandidate, commit) {
129
+ this.assertWritable();
86
130
  validateSessionProfileId(request.sessionId);
87
131
  validateSelectionRequest(request);
88
132
  validateProfileRevision(epoch, "admissionEpoch");
@@ -102,7 +146,7 @@ export class ProfileStore {
102
146
  throw error;
103
147
  throw new DsmmProfileError("activation", "The candidate profile could not be activated; the previous session selection was retained.");
104
148
  }
105
- const directory = join(this.profileDir, ".sessions");
149
+ const directory = join(this.stateDir, ".sessions");
106
150
  const target = join(directory, `${sessionChoiceKey(request.sessionId)}.json`);
107
151
  const fence = (temporary) => {
108
152
  commit.assertCurrent();
@@ -110,7 +154,7 @@ export class ProfileStore {
110
154
  conflict("The session selection was edited externally. Refresh before selecting again.");
111
155
  if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
112
156
  conflict("The draft changed during activation. Reload and select again.");
113
- validateDirectories(directory, false);
157
+ validateDirectories(directory, false, false, this.identities);
114
158
  // The one exclusive atomic staging file is not a session choice.
115
159
  const entries = boundedEntries(directory, MAX_SESSION_PROFILE_CHOICES + (temporary === undefined ? 0 : 1))
116
160
  .filter((name) => temporary === undefined || name !== basename(temporary));
@@ -119,20 +163,22 @@ export class ProfileStore {
119
163
  };
120
164
  assertLock();
121
165
  commit.assertCurrent();
122
- validateDirectories(directory, true);
166
+ validateDirectories(directory, true, false, this.identities);
123
167
  fence();
124
168
  if (draft !== undefined)
125
169
  this.publishRevision(draft, assertLock);
126
170
  const pointer = { version: 1, sessionId: request.sessionId, id: request.id, revision: draft?.revision ?? null, epoch };
127
171
  const bytes = Buffer.from(`${JSON.stringify(pointer)}\n`, "utf8");
128
172
  const selection = { sessionId: request.sessionId, admissionEpoch: epoch,
129
- selectedId: request.id, appliedRevision: draft?.revision ?? null, selectionRevision: digest(bytes), document: draft?.document ?? null, content: draft?.content ?? null };
173
+ selectedId: request.id, appliedRevision: draft?.revision ?? null, selectionRevision: digest(bytes), document: draft?.document ?? null, content: draft?.content ?? null, ...warningFields(draft) };
174
+ commit.prepare?.(selection, prepared);
130
175
  this.atomicReplace(target, bytes, fence, assertLock);
131
176
  commit.committed(selection, prepared);
132
177
  return { selection, prepared };
133
178
  });
134
179
  }
135
180
  async select(request, validateCandidate) {
181
+ this.assertWritable();
136
182
  validateSelectionRequest(request);
137
183
  return this.locked(async (assertLock) => {
138
184
  const current = this.selection();
@@ -159,22 +205,24 @@ export class ProfileStore {
159
205
  this.publishRevision(draft, assertLock);
160
206
  const pointer = { version: 1, id: request.id, revision: draft?.revision ?? null };
161
207
  const bytes = Buffer.from(`${JSON.stringify(pointer)}\n`, "utf8");
162
- this.atomicReplace(join(this.profileDir, ".selection.json"), bytes, () => {
208
+ this.validateState(true);
209
+ this.atomicReplace(join(this.stateDir, ".selection.json"), bytes, () => {
163
210
  this.assertSelectionRevision(request.expectedSelectionRevision);
164
211
  if (draft !== undefined && this.draft(request.id, this.inventory()).revision !== draft.revision)
165
212
  conflict("The draft changed during selection. Reload and select again.");
166
213
  }, assertLock);
167
214
  return {
168
- selection: { selectedId: request.id, appliedRevision: draft?.revision ?? null, selectionRevision: digest(bytes), document: draft?.document ?? null, content: draft?.content ?? null },
215
+ selection: { selectedId: request.id, appliedRevision: draft?.revision ?? null, selectionRevision: digest(bytes), document: draft?.document ?? null, content: draft?.content ?? null, ...warningFields(draft) },
169
216
  prepared
170
217
  };
171
218
  });
172
219
  }
173
220
  readResult(draft) {
174
- return { id: draft.document.id, ...(draft.document.label === undefined ? {} : { label: draft.document.label }), revision: draft.revision, content: draft.content };
221
+ return { id: draft.document.id, ...(draft.document.label === undefined ? {} : { label: draft.document.label }), revision: draft.revision, content: draft.content, ...warningFields(draft) };
175
222
  }
176
223
  inventory() {
177
- this.validateRoot(false);
224
+ if (!this.validateRoot(false))
225
+ return [];
178
226
  const names = boundedEntries(this.profileDir, MAX_PROFILE_DIRECTORY_ENTRIES).filter((name) => !name.startsWith(".") && /\.jsonc$/iu.test(name)).sort();
179
227
  if (names.length > MAX_PROFILE_COUNT)
180
228
  throw new DsmmProfileError("limit", "Profile inventory exceeds the 128-profile limit.");
@@ -200,13 +248,17 @@ export class ProfileStore {
200
248
  if (name === undefined)
201
249
  throw new DsmmProfileError("not-found", "The requested Deepwork profile does not exist.");
202
250
  const file = regularFile(join(this.profileDir, name), MAX_PROFILE_BYTES);
203
- return { ...file, document: parseProfileDocument(file.content, id) };
251
+ return { ...file, ...validatedProfile(file.content, id) };
204
252
  }
205
253
  selection() {
206
254
  this.validateRoot(false);
207
- const path = join(this.profileDir, ".selection.json");
208
- if (status(path) === undefined)
255
+ this.validateState(false);
256
+ const path = join(this.stateDir, ".selection.json");
257
+ if (status(path) === undefined) {
258
+ if (this.origin === "legacy")
259
+ throw new DsmmProfileError("corrupt-selection", "The legacy selection is missing. Restore its original pointer and immutable revision explicitly.");
209
260
  return { selectedId: null, appliedRevision: null, selectionRevision: ABSENT_PROFILE_SELECTION_REVISION, document: null, content: null };
261
+ }
210
262
  try {
211
263
  const file = regularFile(path, 1024);
212
264
  const pointer = parseSelectionPointer(file.content);
@@ -216,20 +268,22 @@ export class ProfileStore {
216
268
  const immutable = regularFile(join(this.profileDir, ".revisions", `${pointer.revision}.jsonc`), MAX_PROFILE_BYTES);
217
269
  if (immutable.revision !== pointer.revision)
218
270
  throw new DsmmProfileError("corrupt-selection", "The selected immutable profile revision failed its SHA256 verification.");
219
- const document = parseProfileDocument(immutable.content, pointer.id);
220
- return { selectedId: pointer.id, appliedRevision: pointer.revision, selectionRevision: file.revision, document, content: immutable.content };
271
+ return { selectedId: pointer.id, appliedRevision: pointer.revision, selectionRevision: file.revision, ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
221
272
  }
222
273
  catch (error) {
223
274
  if (error instanceof DsmmProfileError && error.code === "unsafe-path")
224
275
  throw error;
276
+ if (error instanceof DsmmProfileError && error.reason !== undefined)
277
+ throw new DsmmProfileError("corrupt-selection", error.message, error.field, error.reason, error.location);
225
278
  throw new DsmmProfileError("corrupt-selection", "The selected profile pointer or immutable revision is missing or invalid. Repair it explicitly; the baseline was not silently selected.");
226
279
  }
227
280
  }
228
281
  sessionSelection(sessionId, temporary) {
229
282
  this.validateRoot(false);
283
+ this.validateState(false);
230
284
  const absent = { sessionId, admissionEpoch: null, selectedId: null, appliedRevision: null,
231
285
  selectionRevision: ABSENT_PROFILE_SELECTION_REVISION, document: null, content: null };
232
- const directory = join(this.profileDir, ".sessions");
286
+ const directory = join(this.stateDir, ".sessions");
233
287
  if (status(directory) === undefined)
234
288
  return absent;
235
289
  validateDirectories(directory, false);
@@ -250,11 +304,13 @@ export class ProfileStore {
250
304
  if (immutable.revision !== pointer.revision)
251
305
  throw new DsmmProfileError("corrupt-selection", "The session's immutable profile revision failed SHA256 verification.");
252
306
  return { sessionId, admissionEpoch: pointer.epoch, selectedId: pointer.id, appliedRevision: pointer.revision,
253
- selectionRevision: file.revision, document: parseProfileDocument(immutable.content, pointer.id), content: immutable.content };
307
+ selectionRevision: file.revision, ...validatedProfile(immutable.content, pointer.id), content: immutable.content };
254
308
  }
255
309
  catch (error) {
256
310
  if (error instanceof DsmmProfileError && error.code === "unsafe-path")
257
311
  throw error;
312
+ if (error instanceof DsmmProfileError && error.reason !== undefined)
313
+ throw new DsmmProfileError("corrupt-selection", error.message, error.field, error.reason, error.location);
258
314
  throw new DsmmProfileError("corrupt-selection", "The session profile choice or immutable revision is missing or invalid. Repair it explicitly; no global or baseline fallback was admitted.");
259
315
  }
260
316
  }
@@ -295,112 +351,297 @@ export class ProfileStore {
295
351
  }
296
352
  }
297
353
  atomicReplace(target, bytes, beforeRename, assertLock) {
298
- assertLock();
299
- if (status(target) !== undefined)
300
- assertRegular(status(target));
301
- const temporary = join(dirname(target), `.dsmm-tmp-${randomUUID()}`);
302
- let fd;
303
- let created = false;
304
- try {
305
- fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
306
- created = true;
307
- writeAll(fd, bytes);
308
- fsyncSync(fd);
309
- closeSync(fd);
310
- fd = undefined;
311
- this.validateRoot(false);
312
- if (status(target) !== undefined)
313
- assertRegular(status(target));
314
- beforeRename(temporary);
354
+ atomicReplace(target, bytes, beforeRename, () => {
315
355
  assertLock();
316
- this.rename(temporary, target);
317
- created = false;
318
- // rename is the transaction commit. No fallible work follows it.
319
- }
320
- finally {
321
- if (fd !== undefined)
322
- closeSync(fd);
323
- if (created) {
324
- try {
325
- unlinkSync(temporary);
326
- }
327
- catch { /* Never remove another or previous file to recover a failed commit. */ }
328
- }
329
- }
356
+ validateDirectories(dirname(target), false, false, this.identities);
357
+ }, this.rename);
330
358
  }
331
359
  validateRoot(create) {
332
- validateDirectories(this.profileDir, create);
360
+ if (this.hostProfile !== undefined)
361
+ validateDirectories(this.hostProfile, false, false, this.identities);
362
+ if (!validateDirectories(this.profileDir, create, this.origin === "central", this.identities))
363
+ return false;
333
364
  const current = lstatSync(this.profileDir);
334
365
  if (this.rootIdentity !== undefined && !sameFile(this.rootIdentity, current)) {
335
366
  throw new DsmmProfileError("unsafe-path", "The profile storage directory was replaced during this Host's lifetime; no operation was committed.");
336
367
  }
337
368
  this.rootIdentity ??= current;
338
- }
339
- async locked(operation) {
340
- let fd;
341
- let ownedStatus;
342
- let ownedBytes;
343
- const lockPath = join(this.profileDir, ".lock");
344
- const assertLock = () => {
345
- this.validateRoot(false);
346
- const current = status(lockPath);
347
- if (fd === undefined || ownedStatus === undefined || ownedBytes === undefined || current === undefined || !sameFile(ownedStatus, current) || !sameFile(ownedStatus, fstatSync(fd))) {
348
- conflict("Profile lock ownership changed during this operation. No selection was committed; retry after the current owner finishes.");
369
+ return true;
370
+ }
371
+ validateState(create) {
372
+ return validateDirectories(this.stateDir, create, this.origin === "central", this.identities);
373
+ }
374
+ metadata() {
375
+ return { origin: this.origin, readOnly: this.origin === "legacy", ...(this.origin === "legacy" ? { writeRestriction: LEGACY_WRITE_RESTRICTION } : {}) };
376
+ }
377
+ get readOnly() { return this.origin === "legacy"; }
378
+ get writeRestriction() { return this.readOnly ? LEGACY_WRITE_RESTRICTION : undefined; }
379
+ assertWritable() {
380
+ if (this.origin === "legacy")
381
+ throw new DsmmProfileError("unavailable", LEGACY_WRITE_RESTRICTION);
382
+ }
383
+ /** Host-only immutable state. No RPC exposes this writer or a filesystem path. */
384
+ async createChildAdmission(input, assertCurrent) {
385
+ this.assertWritable();
386
+ const capture = parseChildAdmissionCapture(input);
387
+ if (capture.version !== 2)
388
+ throw new DsmmProfileError("validation", "New child admissions require capture v2.");
389
+ const revision = digest(Buffer.from(JSON.stringify(capture), "utf8"));
390
+ const bytes = Buffer.from(`${JSON.stringify({ version: 1, revision, capture })}\n`, "utf8");
391
+ if (bytes.length > MAX_PROFILE_BYTES)
392
+ throw new DsmmProfileError("limit", "Child admission exceeds the supported size.");
393
+ return this.locked(assertLock => {
394
+ // The Host's synchronous admission fence runs after lock acquisition and
395
+ // before any child namespace or record write; this operation never awaits.
396
+ assertLock();
397
+ assertCurrent?.();
398
+ const directory = join(this.stateDir, ".children", "v1");
399
+ this.validateState(true);
400
+ validateDirectories(directory, true, false, this.identities);
401
+ const path = join(directory, `${sessionChoiceKey(capture.childSessionId)}.json`);
402
+ const existing = this.childAdmission(capture.childSessionId, capture.parentSessionId);
403
+ if (existing !== null) {
404
+ if (JSON.stringify(existing) !== JSON.stringify(capture))
405
+ conflict("An immutable child admission already exists; it cannot be overwritten.");
406
+ return existing;
349
407
  }
350
- assertRegular(current);
351
- assertRegular(fstatSync(fd));
352
- if (!regularFile(lockPath, 256).bytes.equals(ownedBytes))
353
- conflict("The profile lock was altered during this operation. No selection was committed; retry after the current owner finishes.");
354
- };
355
- try {
356
- this.validateRoot(true);
357
- const deadline = performance.now() + this.timeoutMs;
358
- for (;;) {
359
- this.validateRoot(false);
360
- try {
361
- fd = openSync(lockPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
362
- ownedStatus = fstatSync(fd);
363
- ownedBytes = Buffer.from(`${process.pid} ${randomUUID()}\n`, "utf8");
364
- writeAll(fd, ownedBytes);
365
- fsyncSync(fd);
366
- break;
367
- }
368
- catch (error) {
369
- if (fd !== undefined || errorCode(error) !== "EEXIST")
370
- throw error;
371
- const existing = status(lockPath);
372
- if (existing !== undefined)
373
- assertRegular(existing);
374
- if (performance.now() >= deadline)
375
- throw new DsmmProfileError("lock-timeout", "Another process owns the profile lock. Retry after it finishes; locks are never stolen.");
376
- await new Promise((done) => setTimeout(done, Math.min(this.pollMs, Math.max(1, deadline - performance.now()))));
408
+ if (boundedEntries(directory, MAX_SESSION_PROFILE_CHOICES).length >= MAX_SESSION_PROFILE_CHOICES)
409
+ throw new DsmmProfileError("limit", "The child admission inventory is full.");
410
+ assertLock();
411
+ let fd, owned;
412
+ try {
413
+ fd = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
414
+ owned = fstatSync(fd);
415
+ assertRegular(owned);
416
+ writeAll(fd, bytes);
417
+ fsyncSync(fd);
418
+ assertLock();
419
+ validateDirectories(directory, false, false, this.identities);
420
+ const named = status(path);
421
+ if (named === undefined || !sameFile(owned, named))
422
+ conflict("Child admission identity changed during creation.");
423
+ return capture;
424
+ }
425
+ catch (error) {
426
+ if (owned !== undefined) {
427
+ try {
428
+ assertLock();
429
+ const named = status(path);
430
+ if (named !== undefined && sameFile(owned, named))
431
+ unlinkSync(path);
432
+ }
433
+ catch { /* Preserve a replacement or an invalidated root. */ }
377
434
  }
435
+ throw error;
378
436
  }
437
+ finally {
438
+ if (fd !== undefined)
439
+ closeSync(fd);
440
+ }
441
+ });
442
+ }
443
+ async readChildAdmission(childId, parentId) {
444
+ validateSessionProfileId(childId);
445
+ validateSessionProfileId(parentId);
446
+ return this.readOperation(() => this.childAdmission(childId, parentId));
447
+ }
448
+ /** Only a trusted native session-deleted handler may call this; drain never does. */
449
+ async deleteChildAdmission(childId, parentId) {
450
+ this.assertWritable();
451
+ validateSessionProfileId(childId);
452
+ validateSessionProfileId(parentId);
453
+ await this.locked(assertLock => {
454
+ const capture = this.childAdmission(childId, parentId);
455
+ if (capture === null)
456
+ return;
457
+ const path = join(this.stateDir, ".children", "v1", `${sessionChoiceKey(childId)}.json`);
458
+ const file = regularFile(path, MAX_PROFILE_BYTES), owned = lstatSync(path);
379
459
  assertLock();
380
- return await operation(assertLock);
460
+ if (!sameFile(owned, lstatSync(path)) || !regularFile(path, MAX_PROFILE_BYTES).bytes.equals(file.bytes))
461
+ conflict("Child capture changed before native deletion cleanup.");
462
+ unlinkSync(path);
463
+ });
464
+ }
465
+ childAdmission(childId, parentId) {
466
+ this.validateRoot(false);
467
+ this.validateState(false);
468
+ const directory = join(this.stateDir, ".children", "v1");
469
+ // Validate an existing parent sidecar directory even if the version path is absent.
470
+ if (!validateDirectories(join(this.stateDir, ".children"), false, true, this.identities))
471
+ return null;
472
+ if (boundedEntries(join(this.stateDir, ".children"), 16).some(name => name !== "v1"))
473
+ throw new DsmmProfileError("corrupt-selection", "The child capture namespace has an unsupported version; legacy recovery is not allowed.");
474
+ if (!validateDirectories(directory, false, true, this.identities))
475
+ return null;
476
+ const path = join(directory, `${sessionChoiceKey(childId)}.json`);
477
+ if (status(path) === undefined)
478
+ return null;
479
+ const file = regularFile(path, MAX_PROFILE_BYTES);
480
+ try {
481
+ const inspected = inspectJsonDocument(file.content, false);
482
+ if (inspected.diagnostics.length)
483
+ throw new Error("Invalid child JSON");
484
+ const envelope = JSON.parse(file.content);
485
+ if (envelope === null || typeof envelope !== "object" || Array.isArray(envelope) || Object.keys(envelope).length !== 3 || envelope.version !== 1 || !Object.hasOwn(envelope, "revision") || !Object.hasOwn(envelope, "capture"))
486
+ throw new Error("Invalid capture envelope");
487
+ validateProfileRevision(envelope.revision, "revision");
488
+ if (digest(Buffer.from(JSON.stringify(envelope.capture), "utf8")) !== envelope.revision)
489
+ throw new Error("Capture integrity mismatch");
490
+ const capture = parseChildAdmissionCapture(envelope.capture);
491
+ if (capture.childSessionId !== childId || capture.parentSessionId !== parentId)
492
+ throw new Error("Child capture identity mismatch");
493
+ return capture;
494
+ }
495
+ catch {
496
+ throw new DsmmProfileError("corrupt-selection", "The existing child admission is invalid; legacy recovery is not allowed.");
497
+ }
498
+ }
499
+ async readOperation(operation) {
500
+ if (this.origin === "explicit")
501
+ return this.locked(operation);
502
+ try {
503
+ const first = operation();
504
+ const second = operation();
505
+ this.validateRoot(false);
506
+ this.validateState(false);
507
+ if (JSON.stringify(first) !== JSON.stringify(second)) {
508
+ throw new DsmmProfileError(this.origin === "legacy" ? "corrupt-selection" : "conflict", "Profile storage changed during the read. No selection was admitted; retry after it is stable.");
509
+ }
510
+ return second;
381
511
  }
382
512
  catch (error) {
383
513
  if (error instanceof DsmmProfileError)
384
514
  throw error;
385
- throw new DsmmProfileError("io", "Deepwork profile storage failed. Existing files and the previous selection were retained.");
515
+ throw new DsmmProfileError("io", "Deepwork profile storage could not be read safely.");
386
516
  }
387
- finally {
388
- if (fd !== undefined) {
389
- try {
390
- closeSync(fd);
391
- }
392
- catch { /* A committed pointer must remain a successful transaction. */ }
393
- try {
394
- this.validateRoot(false);
395
- const current = status(lockPath);
396
- if (ownedStatus !== undefined && ownedBytes !== undefined && current !== undefined && sameFile(ownedStatus, current) && current.isFile() && !current.isSymbolicLink() && regularFile(lockPath, 256).bytes.equals(ownedBytes))
397
- unlinkSync(lockPath);
398
- }
399
- catch { /* Do not delete a replacement lock or traverse an altered root. */ }
517
+ }
518
+ async locked(operation) {
519
+ this.assertWritable();
520
+ return locked(this.profileDir, ".lock", (create) => { this.validateRoot(create); }, this.timeoutMs, this.pollMs, operation);
521
+ }
522
+ }
523
+ async function locked(directory, lockName, validateRoot, timeoutMs, pollMs, operation) {
524
+ let fd;
525
+ let ownedStatus;
526
+ let ownedBytes;
527
+ const lockPath = join(directory, lockName);
528
+ const assertLock = () => {
529
+ validateRoot(false);
530
+ const current = status(lockPath);
531
+ if (fd === undefined || ownedStatus === undefined || ownedBytes === undefined || current === undefined || !sameFile(ownedStatus, current) || !sameFile(ownedStatus, fstatSync(fd))) {
532
+ conflict("Profile lock ownership changed during this operation. No selection was committed; retry after the current owner finishes.");
533
+ }
534
+ assertRegular(current);
535
+ assertRegular(fstatSync(fd));
536
+ if (!regularFile(lockPath, 256).bytes.equals(ownedBytes))
537
+ conflict("The profile lock was altered during this operation. No selection was committed; retry after the current owner finishes.");
538
+ };
539
+ try {
540
+ validateRoot(true);
541
+ const deadline = performance.now() + timeoutMs;
542
+ for (;;) {
543
+ validateRoot(false);
544
+ try {
545
+ fd = openSync(lockPath, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
546
+ ownedStatus = fstatSync(fd);
547
+ ownedBytes = Buffer.from(`${process.pid} ${randomUUID()}\n`, "utf8");
548
+ writeAll(fd, ownedBytes);
549
+ fsyncSync(fd);
550
+ break;
551
+ }
552
+ catch (error) {
553
+ if (fd !== undefined || errorCode(error) !== "EEXIST")
554
+ throw error;
555
+ const existing = status(lockPath);
556
+ if (existing !== undefined)
557
+ assertRegular(existing);
558
+ if (performance.now() >= deadline)
559
+ throw new DsmmProfileError("lock-timeout", "Another process owns the profile lock. Retry after it finishes; locks are never stolen.");
560
+ await new Promise((done) => setTimeout(done, Math.min(pollMs, Math.max(1, deadline - performance.now()))));
400
561
  }
401
562
  }
563
+ assertLock();
564
+ return await operation(assertLock);
565
+ }
566
+ catch (error) {
567
+ if (error instanceof DsmmProfileError)
568
+ throw error;
569
+ throw new DsmmProfileError("io", "Deepwork profile storage failed. Existing files and the previous selection were retained.");
570
+ }
571
+ finally {
572
+ if (fd !== undefined) {
573
+ try {
574
+ closeSync(fd);
575
+ }
576
+ catch { /* A committed pointer must remain a successful transaction. */ }
577
+ try {
578
+ validateRoot(false);
579
+ const current = status(lockPath);
580
+ if (ownedStatus !== undefined && ownedBytes !== undefined && current !== undefined && sameFile(ownedStatus, current) && current.isFile() && !current.isSymbolicLink() && regularFile(lockPath, 256).bytes.equals(ownedBytes))
581
+ unlinkSync(lockPath);
582
+ }
583
+ catch { /* Do not delete a replacement lock or traverse an altered root. */ }
584
+ }
402
585
  }
403
586
  }
587
+ function atomicReplace(target, bytes, beforeRename, assertAuthority, rename, assertCurrent) {
588
+ assertAuthority();
589
+ if (status(target) !== undefined)
590
+ assertRegular(status(target));
591
+ const temporary = join(dirname(target), `.dsmm-tmp-${randomUUID()}`);
592
+ let fd;
593
+ let created = false;
594
+ let owned;
595
+ try {
596
+ fd = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
597
+ created = true;
598
+ owned = fstatSync(fd);
599
+ assertRegular(owned);
600
+ writeAll(fd, bytes);
601
+ fsyncSync(fd);
602
+ closeSync(fd);
603
+ fd = undefined;
604
+ assertAuthority();
605
+ if (status(target) !== undefined)
606
+ assertRegular(status(target));
607
+ beforeRename(temporary);
608
+ assertAuthority();
609
+ const staged = regularFile(temporary, bytes.length);
610
+ if (!sameFile(owned, lstatSync(temporary)) || !staged.bytes.equals(bytes))
611
+ conflict("The staged file changed before commit. No file was replaced.");
612
+ assertCurrent?.();
613
+ rename(temporary, target);
614
+ created = false;
615
+ // rename is the transaction commit. No fallible work follows it.
616
+ }
617
+ finally {
618
+ if (fd !== undefined)
619
+ closeSync(fd);
620
+ if (created) {
621
+ try {
622
+ assertAuthority();
623
+ const current = status(temporary);
624
+ if (owned !== undefined && current !== undefined && sameFile(owned, current))
625
+ unlinkSync(temporary);
626
+ }
627
+ catch { /* Never traverse an altered root or remove another owner's staging file. */ }
628
+ }
629
+ }
630
+ }
631
+ function validateTrustedDirectoryPath(path) {
632
+ if (typeof path !== "string" || path.length > 4096 || !isAbsolute(path) || /[\u0000-\u001f\u007f]/u.test(path)
633
+ || Buffer.from(path, "utf8").toString("utf8") !== path || dirname(resolve(path)) === resolve(path)) {
634
+ throw new DsmmProfileError("unsafe-path", "A bounded absolute trusted Host directory is required.");
635
+ }
636
+ }
637
+ function trustedHome(home) {
638
+ validateTrustedDirectoryPath(home);
639
+ const root = resolve(home);
640
+ validateDirectories(root, false, true);
641
+ return root;
642
+ }
643
+ /** @internal Shared only by the fixed config file adapter; not a wire-path storage API. */
644
+ export const profileStoreFilePrimitives = { trustedHome, validateDirectories, status, regularFile, digest, boundedOption, locked, atomicReplace };
404
645
  function boundedOption(value, fallback, minimum, maximum) {
405
646
  if (value === undefined)
406
647
  return fallback;
@@ -424,7 +665,7 @@ function status(path) {
424
665
  throw error;
425
666
  }
426
667
  }
427
- function validateDirectories(directory, create) {
668
+ function validateDirectories(directory, create, allowMissing = false, identities) {
428
669
  const absolute = resolve(directory);
429
670
  const root = parse(absolute).root;
430
671
  const parts = [];
@@ -433,6 +674,8 @@ function validateDirectories(directory, create) {
433
674
  parts.unshift(root);
434
675
  for (const path of parts) {
435
676
  let found = status(path);
677
+ if (found === undefined && identities?.has(path))
678
+ throw new DsmmProfileError("unsafe-path", "A pinned storage directory disappeared; storage authority was invalidated.");
436
679
  if (found === undefined && create) {
437
680
  try {
438
681
  mkdirSync(path, { mode: 0o700 });
@@ -443,13 +686,21 @@ function validateDirectories(directory, create) {
443
686
  }
444
687
  found = status(path);
445
688
  }
689
+ if (found === undefined && allowMissing) {
690
+ return false;
691
+ }
446
692
  if (found === undefined || found.isSymbolicLink() || !found.isDirectory())
447
693
  throw new DsmmProfileError("unsafe-path", "Profile directories and every ancestor must be real directories, not links or junctions.");
448
694
  const canonical = resolve(realpathSync(path));
449
695
  if ((process.platform === "win32" ? canonical.toLowerCase() : canonical) !== (process.platform === "win32" ? path.toLowerCase() : path)) {
450
696
  throw new DsmmProfileError("unsafe-path", "Profile storage must not traverse redirected directories or reparse points.");
451
697
  }
698
+ const pinned = identities?.get(path);
699
+ if (pinned !== undefined && !sameFile(pinned, found))
700
+ throw new DsmmProfileError("unsafe-path", "A storage directory was replaced; storage authority was invalidated.");
701
+ identities?.set(path, found);
452
702
  }
703
+ return true;
453
704
  }
454
705
  function assertRegular(found) {
455
706
  if (found.isSymbolicLink() || !found.isFile() || found.nlink !== 1)
@@ -459,6 +710,7 @@ function sameFile(first, second) {
459
710
  return first.dev === second.dev && first.ino === second.ino;
460
711
  }
461
712
  function regularFile(path, maximum) {
713
+ validateDirectories(dirname(path), false);
462
714
  const before = status(path);
463
715
  if (before === undefined)
464
716
  throw new DsmmProfileError("not-found", "The required profile file does not exist.");
@@ -467,6 +719,7 @@ function regularFile(path, maximum) {
467
719
  throw new DsmmProfileError("limit", "Profile storage contains an oversized file.");
468
720
  const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
469
721
  try {
722
+ validateDirectories(dirname(path), false);
470
723
  const opened = fstatSync(fd);
471
724
  assertRegular(opened);
472
725
  if (!sameFile(before, opened))
@@ -483,6 +736,10 @@ function regularFile(path, maximum) {
483
736
  throw new DsmmProfileError("limit", "Profile storage contains an oversized file.");
484
737
  const after = fstatSync(fd);
485
738
  const named = status(path);
739
+ validateDirectories(dirname(path), false);
740
+ assertRegular(after);
741
+ if (named !== undefined)
742
+ assertRegular(named);
486
743
  if (named === undefined || !sameFile(opened, named) || opened.size !== after.size || opened.mtimeMs !== after.mtimeMs || opened.ctimeMs !== after.ctimeMs)
487
744
  conflict("The profile file was edited while being read. Retry the operation.");
488
745
  const bytes = buffer.subarray(0, size);
@@ -585,4 +842,13 @@ function conflict(message) {
585
842
  function safeInventoryId(id) {
586
843
  return /^[a-zA-Z0-9_-]{1,64}$/u.test(id) ? id : "invalid-profile";
587
844
  }
845
+ function warningFields(value) {
846
+ return value?.warnings === undefined ? {} : { warnings: value.warnings };
847
+ }
848
+ function validatedProfile(content, id) {
849
+ const result = validateProfileDocument(content, id);
850
+ if (result.document === undefined)
851
+ parseProfileDocument(content, id);
852
+ return { document: result.document, ...(result.diagnostics.length ? { warnings: result.diagnostics } : {}) };
853
+ }
588
854
  //# sourceMappingURL=profile-store.js.map