@unbrained/pm-cli 2026.5.18 → 2026.5.27

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 (369) hide show
  1. package/CHANGELOG.md +953 -472
  2. package/README.md +4 -11
  3. package/dist/cli/bootstrap-args.d.ts +18 -1
  4. package/dist/cli/bootstrap-args.js +143 -3
  5. package/dist/cli/bootstrap-args.js.map +1 -1
  6. package/dist/cli/commander-usage.js +147 -10
  7. package/dist/cli/commander-usage.js.map +1 -1
  8. package/dist/cli/commands/annotation-command.d.ts +49 -0
  9. package/dist/cli/commands/annotation-command.js +135 -0
  10. package/dist/cli/commands/annotation-command.js.map +1 -0
  11. package/dist/cli/commands/append.js +5 -8
  12. package/dist/cli/commands/append.js.map +1 -1
  13. package/dist/cli/commands/calendar.js +3 -6
  14. package/dist/cli/commands/calendar.js.map +1 -1
  15. package/dist/cli/commands/claim.js +15 -24
  16. package/dist/cli/commands/claim.js.map +1 -1
  17. package/dist/cli/commands/close.js +63 -10
  18. package/dist/cli/commands/close.js.map +1 -1
  19. package/dist/cli/commands/comments.d.ts +5 -0
  20. package/dist/cli/commands/comments.js +27 -117
  21. package/dist/cli/commands/comments.js.map +1 -1
  22. package/dist/cli/commands/completion.d.ts +2 -2
  23. package/dist/cli/commands/completion.js +203 -63
  24. package/dist/cli/commands/completion.js.map +1 -1
  25. package/dist/cli/commands/config.d.ts +1 -1
  26. package/dist/cli/commands/config.js +82 -4
  27. package/dist/cli/commands/config.js.map +1 -1
  28. package/dist/cli/commands/context.js +4 -10
  29. package/dist/cli/commands/context.js.map +1 -1
  30. package/dist/cli/commands/contracts.js +168 -36
  31. package/dist/cli/commands/contracts.js.map +1 -1
  32. package/dist/cli/commands/create.js +53 -313
  33. package/dist/cli/commands/create.js.map +1 -1
  34. package/dist/cli/commands/dedupe-audit.js +7 -4
  35. package/dist/cli/commands/dedupe-audit.js.map +1 -1
  36. package/dist/cli/commands/delete.d.ts +3 -0
  37. package/dist/cli/commands/delete.js +11 -9
  38. package/dist/cli/commands/delete.js.map +1 -1
  39. package/dist/cli/commands/docs.d.ts +2 -12
  40. package/dist/cli/commands/docs.js +8 -316
  41. package/dist/cli/commands/docs.js.map +1 -1
  42. package/dist/cli/commands/event-validation-messages.d.ts +3 -0
  43. package/dist/cli/commands/event-validation-messages.js +44 -0
  44. package/dist/cli/commands/event-validation-messages.js.map +1 -0
  45. package/dist/cli/commands/extension/bundled-catalog.d.ts +14 -0
  46. package/dist/cli/commands/extension/bundled-catalog.js +268 -0
  47. package/dist/cli/commands/extension/bundled-catalog.js.map +1 -0
  48. package/dist/cli/commands/extension/doctor.d.ts +31 -0
  49. package/dist/cli/commands/extension/doctor.js +345 -0
  50. package/dist/cli/commands/extension/doctor.js.map +1 -0
  51. package/dist/cli/commands/extension/install-sources.d.ts +37 -0
  52. package/dist/cli/commands/extension/install-sources.js +384 -0
  53. package/dist/cli/commands/extension/install-sources.js.map +1 -0
  54. package/dist/cli/commands/extension/managed-state.d.ts +48 -0
  55. package/dist/cli/commands/extension/managed-state.js +172 -0
  56. package/dist/cli/commands/extension/managed-state.js.map +1 -0
  57. package/dist/cli/commands/extension/scaffold.d.ts +14 -0
  58. package/dist/cli/commands/extension/scaffold.js +169 -0
  59. package/dist/cli/commands/extension/scaffold.js.map +1 -0
  60. package/dist/cli/commands/extension/shared.d.ts +14 -0
  61. package/dist/cli/commands/extension/shared.js +106 -0
  62. package/dist/cli/commands/extension/shared.js.map +1 -0
  63. package/dist/cli/commands/extension.d.ts +37 -68
  64. package/dist/cli/commands/extension.js +157 -1319
  65. package/dist/cli/commands/extension.js.map +1 -1
  66. package/dist/cli/commands/files.d.ts +1 -12
  67. package/dist/cli/commands/files.js +14 -318
  68. package/dist/cli/commands/files.js.map +1 -1
  69. package/dist/cli/commands/gc.js +17 -4
  70. package/dist/cli/commands/gc.js.map +1 -1
  71. package/dist/cli/commands/get.d.ts +3 -2
  72. package/dist/cli/commands/get.js +52 -9
  73. package/dist/cli/commands/get.js.map +1 -1
  74. package/dist/cli/commands/health.d.ts +10 -0
  75. package/dist/cli/commands/health.js +269 -76
  76. package/dist/cli/commands/health.js.map +1 -1
  77. package/dist/cli/commands/history-redact.d.ts +8 -0
  78. package/dist/cli/commands/history-redact.js +35 -113
  79. package/dist/cli/commands/history-redact.js.map +1 -1
  80. package/dist/cli/commands/history-repair.d.ts +33 -0
  81. package/dist/cli/commands/history-repair.js +172 -0
  82. package/dist/cli/commands/history-repair.js.map +1 -0
  83. package/dist/cli/commands/history.d.ts +4 -4
  84. package/dist/cli/commands/history.js +10 -88
  85. package/dist/cli/commands/history.js.map +1 -1
  86. package/dist/cli/commands/index.d.ts +3 -1
  87. package/dist/cli/commands/index.js +5 -3
  88. package/dist/cli/commands/index.js.map +1 -1
  89. package/dist/cli/commands/init.d.ts +28 -0
  90. package/dist/cli/commands/init.js +23 -2
  91. package/dist/cli/commands/init.js.map +1 -1
  92. package/dist/cli/commands/learnings.js +20 -119
  93. package/dist/cli/commands/learnings.js.map +1 -1
  94. package/dist/cli/commands/legacy-none-tokens.d.ts +3 -0
  95. package/dist/cli/commands/legacy-none-tokens.js +39 -0
  96. package/dist/cli/commands/legacy-none-tokens.js.map +1 -0
  97. package/dist/cli/commands/linked-artifacts.d.ts +96 -0
  98. package/dist/cli/commands/linked-artifacts.js +335 -0
  99. package/dist/cli/commands/linked-artifacts.js.map +1 -0
  100. package/dist/cli/commands/linked-test-entry.d.ts +3 -0
  101. package/dist/cli/commands/linked-test-entry.js +62 -0
  102. package/dist/cli/commands/linked-test-entry.js.map +1 -0
  103. package/dist/cli/commands/linked-test-parsers.d.ts +28 -0
  104. package/dist/cli/commands/linked-test-parsers.js +192 -0
  105. package/dist/cli/commands/linked-test-parsers.js.map +1 -0
  106. package/dist/cli/commands/list.js +49 -24
  107. package/dist/cli/commands/list.js.map +1 -1
  108. package/dist/cli/commands/normalize.js +4 -3
  109. package/dist/cli/commands/normalize.js.map +1 -1
  110. package/dist/cli/commands/notes.js +20 -119
  111. package/dist/cli/commands/notes.js.map +1 -1
  112. package/dist/cli/commands/plan.d.ts +3 -0
  113. package/dist/cli/commands/plan.js +184 -22
  114. package/dist/cli/commands/plan.js.map +1 -1
  115. package/dist/cli/commands/recurrence-parsers.d.ts +26 -0
  116. package/dist/cli/commands/recurrence-parsers.js +98 -0
  117. package/dist/cli/commands/recurrence-parsers.js.map +1 -0
  118. package/dist/cli/commands/restore.js +24 -56
  119. package/dist/cli/commands/restore.js.map +1 -1
  120. package/dist/cli/commands/schema.d.ts +31 -0
  121. package/dist/cli/commands/schema.js +98 -0
  122. package/dist/cli/commands/schema.js.map +1 -0
  123. package/dist/cli/commands/search.js +154 -42
  124. package/dist/cli/commands/search.js.map +1 -1
  125. package/dist/cli/commands/templates.d.ts +4 -0
  126. package/dist/cli/commands/templates.js +89 -17
  127. package/dist/cli/commands/templates.js.map +1 -1
  128. package/dist/cli/commands/test/linked-command-detection.d.ts +37 -0
  129. package/dist/cli/commands/test/linked-command-detection.js +200 -0
  130. package/dist/cli/commands/test/linked-command-detection.js.map +1 -0
  131. package/dist/cli/commands/test-all.js +4 -8
  132. package/dist/cli/commands/test-all.js.map +1 -1
  133. package/dist/cli/commands/test.d.ts +2 -2
  134. package/dist/cli/commands/test.js +12 -357
  135. package/dist/cli/commands/test.js.map +1 -1
  136. package/dist/cli/commands/update-many.js +6 -9
  137. package/dist/cli/commands/update-many.js.map +1 -1
  138. package/dist/cli/commands/update.js +167 -401
  139. package/dist/cli/commands/update.js.map +1 -1
  140. package/dist/cli/commands/validate.d.ts +3 -1
  141. package/dist/cli/commands/validate.js +23 -71
  142. package/dist/cli/commands/validate.js.map +1 -1
  143. package/dist/cli/error-guidance.d.ts +1 -0
  144. package/dist/cli/error-guidance.js +100 -6
  145. package/dist/cli/error-guidance.js.map +1 -1
  146. package/dist/cli/extension-command-help.d.ts +0 -1
  147. package/dist/cli/extension-command-help.js +2 -13
  148. package/dist/cli/extension-command-help.js.map +1 -1
  149. package/dist/cli/extension-command-options.d.ts +1 -0
  150. package/dist/cli/extension-command-options.js +106 -7
  151. package/dist/cli/extension-command-options.js.map +1 -1
  152. package/dist/cli/help-content.d.ts +0 -1
  153. package/dist/cli/help-content.js +13 -9
  154. package/dist/cli/help-content.js.map +1 -1
  155. package/dist/cli/help-json-payload.d.ts +1 -0
  156. package/dist/cli/help-json-payload.js +33 -3
  157. package/dist/cli/help-json-payload.js.map +1 -1
  158. package/dist/cli/main.d.ts +11 -0
  159. package/dist/cli/main.js +109 -55
  160. package/dist/cli/main.js.map +1 -1
  161. package/dist/cli/register-list-query.d.ts +5 -2
  162. package/dist/cli/register-list-query.js +254 -192
  163. package/dist/cli/register-list-query.js.map +1 -1
  164. package/dist/cli/register-mutation.d.ts +1 -1
  165. package/dist/cli/register-mutation.js +247 -64
  166. package/dist/cli/register-mutation.js.map +1 -1
  167. package/dist/cli/register-operations.js +17 -12
  168. package/dist/cli/register-operations.js.map +1 -1
  169. package/dist/cli/register-setup.js +33 -16
  170. package/dist/cli/register-setup.js.map +1 -1
  171. package/dist/cli/registration-helpers.d.ts +0 -2
  172. package/dist/cli/registration-helpers.js +14 -40
  173. package/dist/cli/registration-helpers.js.map +1 -1
  174. package/dist/cli.js +25 -4
  175. package/dist/cli.js.map +1 -1
  176. package/dist/core/config/positional-value.d.ts +44 -0
  177. package/dist/core/config/positional-value.js +109 -0
  178. package/dist/core/config/positional-value.js.map +1 -0
  179. package/dist/core/extensions/extension-capability-aliases.d.ts +14 -0
  180. package/dist/core/extensions/extension-capability-aliases.js +159 -0
  181. package/dist/core/extensions/extension-capability-aliases.js.map +1 -0
  182. package/dist/core/extensions/extension-hook-runtime.d.ts +13 -0
  183. package/dist/core/extensions/extension-hook-runtime.js +414 -0
  184. package/dist/core/extensions/extension-hook-runtime.js.map +1 -0
  185. package/dist/core/extensions/extension-policy.d.ts +69 -0
  186. package/dist/core/extensions/extension-policy.js +481 -0
  187. package/dist/core/extensions/extension-policy.js.map +1 -0
  188. package/dist/core/extensions/extension-registries.d.ts +8 -0
  189. package/dist/core/extensions/extension-registries.js +52 -0
  190. package/dist/core/extensions/extension-registries.js.map +1 -0
  191. package/dist/core/extensions/extension-runtime-helpers.d.ts +6 -0
  192. package/dist/core/extensions/extension-runtime-helpers.js +29 -0
  193. package/dist/core/extensions/extension-runtime-helpers.js.map +1 -0
  194. package/dist/core/extensions/extension-types.d.ts +13 -39
  195. package/dist/core/extensions/extension-types.js +34 -2
  196. package/dist/core/extensions/extension-types.js.map +1 -1
  197. package/dist/core/extensions/index.d.ts +7 -1
  198. package/dist/core/extensions/index.js +11 -14
  199. package/dist/core/extensions/index.js.map +1 -1
  200. package/dist/core/extensions/loader.d.ts +4 -22
  201. package/dist/core/extensions/loader.js +23 -1146
  202. package/dist/core/extensions/loader.js.map +1 -1
  203. package/dist/core/fs/path-utils.d.ts +1 -0
  204. package/dist/core/fs/path-utils.js +12 -0
  205. package/dist/core/fs/path-utils.js.map +1 -0
  206. package/dist/core/history/drift-scan.d.ts +22 -0
  207. package/dist/core/history/drift-scan.js +149 -0
  208. package/dist/core/history/drift-scan.js.map +1 -0
  209. package/dist/core/history/history-rewrite.d.ts +43 -0
  210. package/dist/core/history/history-rewrite.js +48 -0
  211. package/dist/core/history/history-rewrite.js.map +1 -0
  212. package/dist/core/history/history.js +5 -4
  213. package/dist/core/history/history.js.map +1 -1
  214. package/dist/core/history/replay.d.ts +82 -0
  215. package/dist/core/history/replay.js +250 -0
  216. package/dist/core/history/replay.js.map +1 -0
  217. package/dist/core/item/item-format.js +11 -8
  218. package/dist/core/item/item-format.js.map +1 -1
  219. package/dist/core/item/item-record.d.ts +19 -0
  220. package/dist/core/item/item-record.js +24 -0
  221. package/dist/core/item/item-record.js.map +1 -0
  222. package/dist/core/item/item-type-definition.d.ts +52 -0
  223. package/dist/core/item/item-type-definition.js +123 -0
  224. package/dist/core/item/item-type-definition.js.map +1 -0
  225. package/dist/core/item/parse.js +3 -2
  226. package/dist/core/item/parse.js.map +1 -1
  227. package/dist/core/item/priority.d.ts +23 -0
  228. package/dist/core/item/priority.js +55 -0
  229. package/dist/core/item/priority.js.map +1 -0
  230. package/dist/core/item/status.d.ts +14 -1
  231. package/dist/core/item/status.js +22 -2
  232. package/dist/core/item/status.js.map +1 -1
  233. package/dist/core/item/toon-decode.d.ts +19 -0
  234. package/dist/core/item/toon-decode.js +69 -0
  235. package/dist/core/item/toon-decode.js.map +1 -0
  236. package/dist/core/item/type-registry.js +13 -84
  237. package/dist/core/item/type-registry.js.map +1 -1
  238. package/dist/core/output/mutation-projection.d.ts +31 -0
  239. package/dist/core/output/mutation-projection.js +103 -0
  240. package/dist/core/output/mutation-projection.js.map +1 -0
  241. package/dist/core/output/output.d.ts +2 -0
  242. package/dist/core/output/output.js +5 -3
  243. package/dist/core/output/output.js.map +1 -1
  244. package/dist/core/packages/manifest.js +3 -9
  245. package/dist/core/packages/manifest.js.map +1 -1
  246. package/dist/core/schema/item-types-file.d.ts +85 -0
  247. package/dist/core/schema/item-types-file.js +243 -0
  248. package/dist/core/schema/item-types-file.js.map +1 -0
  249. package/dist/core/schema/runtime-schema.d.ts +2 -1
  250. package/dist/core/schema/runtime-schema.js +17 -45
  251. package/dist/core/schema/runtime-schema.js.map +1 -1
  252. package/dist/core/search/semantic-defaults.js +3 -3
  253. package/dist/core/search/semantic-defaults.js.map +1 -1
  254. package/dist/core/search/vector-stores.js +46 -9
  255. package/dist/core/search/vector-stores.js.map +1 -1
  256. package/dist/core/sentry/helpers.d.ts +1 -1
  257. package/dist/core/sentry/helpers.js +20 -3
  258. package/dist/core/sentry/helpers.js.map +1 -1
  259. package/dist/core/shared/author.d.ts +1 -0
  260. package/dist/core/shared/author.js +9 -0
  261. package/dist/core/shared/author.js.map +1 -0
  262. package/dist/core/shared/command-types.d.ts +1 -0
  263. package/dist/core/shared/command-types.js +2 -2
  264. package/dist/core/shared/command-types.js.map +1 -1
  265. package/dist/core/shared/constants.d.ts +10 -1
  266. package/dist/core/shared/constants.js +56 -58
  267. package/dist/core/shared/constants.js.map +1 -1
  268. package/dist/core/shared/lazy-module.d.ts +1 -0
  269. package/dist/core/shared/lazy-module.js +11 -0
  270. package/dist/core/shared/lazy-module.js.map +1 -0
  271. package/dist/core/shared/option-alias-visibility.d.ts +44 -0
  272. package/dist/core/shared/option-alias-visibility.js +76 -0
  273. package/dist/core/shared/option-alias-visibility.js.map +1 -0
  274. package/dist/core/shared/primitives.d.ts +23 -0
  275. package/dist/core/shared/primitives.js +39 -2
  276. package/dist/core/shared/primitives.js.map +1 -1
  277. package/dist/core/shared/text-normalization.d.ts +0 -1
  278. package/dist/core/shared/text-normalization.js +2 -5
  279. package/dist/core/shared/text-normalization.js.map +1 -1
  280. package/dist/core/store/front-matter-cache.d.ts +16 -2
  281. package/dist/core/store/front-matter-cache.js +99 -33
  282. package/dist/core/store/front-matter-cache.js.map +1 -1
  283. package/dist/core/store/item-store.d.ts +2 -0
  284. package/dist/core/store/item-store.js +76 -110
  285. package/dist/core/store/item-store.js.map +1 -1
  286. package/dist/core/store/settings-validator.d.ts +106 -0
  287. package/dist/core/store/settings-validator.js +279 -0
  288. package/dist/core/store/settings-validator.js.map +1 -0
  289. package/dist/core/store/settings.js +6 -343
  290. package/dist/core/store/settings.js.map +1 -1
  291. package/dist/core/telemetry/runtime.js +5 -3
  292. package/dist/core/telemetry/runtime.js.map +1 -1
  293. package/dist/mcp/server.js +138 -39
  294. package/dist/mcp/server.js.map +1 -1
  295. package/dist/sdk/cli-contracts/enum-contracts.d.ts +20 -0
  296. package/dist/sdk/cli-contracts/enum-contracts.js +156 -0
  297. package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -0
  298. package/dist/sdk/cli-contracts/tool-option-contracts.d.ts +14 -0
  299. package/dist/sdk/cli-contracts/tool-option-contracts.js +243 -0
  300. package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -0
  301. package/dist/sdk/cli-contracts/tool-parameter-tables.d.ts +11 -0
  302. package/dist/sdk/cli-contracts/tool-parameter-tables.js +901 -0
  303. package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -0
  304. package/dist/sdk/cli-contracts.d.ts +18 -33
  305. package/dist/sdk/cli-contracts.js +96 -1238
  306. package/dist/sdk/cli-contracts.js.map +1 -1
  307. package/dist/sdk/package-import-adapters.d.ts +74 -0
  308. package/dist/sdk/package-import-adapters.js +186 -0
  309. package/dist/sdk/package-import-adapters.js.map +1 -0
  310. package/dist/sdk/package-runtime-options.d.ts +26 -0
  311. package/dist/sdk/package-runtime-options.js +71 -0
  312. package/dist/sdk/package-runtime-options.js.map +1 -0
  313. package/dist/sdk/runtime.d.ts +27 -1
  314. package/dist/sdk/runtime.js +48 -3
  315. package/dist/sdk/runtime.js.map +1 -1
  316. package/dist/types.d.ts +6 -0
  317. package/dist/types.js +10 -2
  318. package/dist/types.js.map +1 -1
  319. package/docs/AGENT_GUIDE.md +13 -11
  320. package/docs/ARCHITECTURE.md +1 -1
  321. package/docs/CLAUDE_CODE_PLUGIN.md +5 -28
  322. package/docs/CODEX_PLUGIN.md +5 -5
  323. package/docs/COMMANDS.md +58 -9
  324. package/docs/CONFIGURATION.md +16 -1
  325. package/docs/EXTENSIONS.md +4 -63
  326. package/docs/RELEASING.md +12 -8
  327. package/docs/SDK.md +11 -2
  328. package/marketplace.json +7 -3
  329. package/package.json +18 -14
  330. package/packages/pm-beads/extensions/beads/index.js +2 -49
  331. package/packages/pm-beads/extensions/beads/index.ts +2 -54
  332. package/packages/pm-beads/extensions/beads/runtime-loader.js +86 -0
  333. package/packages/pm-beads/extensions/beads/runtime-loader.ts +88 -0
  334. package/packages/pm-beads/extensions/beads/runtime.js +26 -115
  335. package/packages/pm-beads/extensions/beads/runtime.ts +33 -132
  336. package/packages/pm-calendar/README.md +3 -1
  337. package/packages/pm-calendar/extensions/calendar/index.js +66 -2
  338. package/packages/pm-calendar/extensions/calendar/index.ts +71 -2
  339. package/packages/pm-calendar/extensions/calendar/runtime.js +1 -0
  340. package/packages/pm-calendar/extensions/calendar/runtime.ts +1 -0
  341. package/packages/pm-governance-audit/extensions/governance-audit/runtime.js +14 -41
  342. package/packages/pm-governance-audit/extensions/governance-audit/runtime.ts +25 -41
  343. package/packages/pm-guide-shell/extensions/guide-shell/runtime.js +10 -50
  344. package/packages/pm-guide-shell/extensions/guide-shell/runtime.ts +17 -50
  345. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/runtime.js +8 -40
  346. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/runtime.ts +10 -40
  347. package/packages/pm-search-advanced/README.md +8 -0
  348. package/packages/pm-search-advanced/extensions/search-advanced/index.js +75 -1
  349. package/packages/pm-search-advanced/extensions/search-advanced/index.ts +74 -0
  350. package/packages/pm-search-advanced/extensions/search-advanced/runtime.js +58 -33
  351. package/packages/pm-search-advanced/extensions/search-advanced/runtime.ts +60 -33
  352. package/packages/pm-templates/extensions/templates/runtime.js +11 -202
  353. package/packages/pm-templates/extensions/templates/runtime.ts +38 -230
  354. package/packages/pm-todos/extensions/todos/index.js +3 -50
  355. package/packages/pm-todos/extensions/todos/index.ts +3 -55
  356. package/packages/pm-todos/extensions/todos/runtime-loader.js +86 -0
  357. package/packages/pm-todos/extensions/todos/runtime-loader.ts +88 -0
  358. package/packages/pm-todos/extensions/todos/runtime.js +24 -117
  359. package/packages/pm-todos/extensions/todos/runtime.ts +32 -129
  360. package/plugins/pm-claude/README.md +2 -2
  361. package/plugins/pm-claude/commands/pm-planner.md +1 -15
  362. package/plugins/pm-claude/scripts/pm-mcp-server.mjs +5 -2
  363. package/plugins/pm-claude/skills/pm-planner/SKILL.md +3 -21
  364. package/plugins/pm-codex/scripts/pm-mcp-server.mjs +15 -6
  365. package/plugins/pm-codex/skills/pm-native/SKILL.md +1 -13
  366. package/PRD.md +0 -1734
  367. package/dist/core/output/command-aware.d.ts +0 -1
  368. package/dist/core/output/command-aware.js +0 -397
  369. package/dist/core/output/command-aware.js.map +0 -1
@@ -1,679 +1,33 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6e8bb06d-d0ca-5e37-9e3a-cf76b1b21ace")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="4fba8687-0797-5479-afc8-12f1a2e5a954")}catch(e){}}();
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
6
  import { pathExists } from "../fs/fs-utils.js";
7
+ import { isPathWithinDirectory } from "../fs/path-utils.js";
7
8
  import { resolveGlobalPmRoot } from "../store/paths.js";
8
- import { KNOWN_EXTENSION_CAPABILITIES, KNOWN_EXTENSION_POLICY_MODES, KNOWN_EXTENSION_POLICY_SURFACES, KNOWN_EXTENSION_SANDBOX_PROFILES, KNOWN_EXTENSION_TRUST_MODES, EXTENSION_CAPABILITY_CONTRACT_VERSION, EXTENSION_CAPABILITY_LEGACY_ALIASES, } from "./extension-types.js";
9
+ import { asRecordLoose } from "../shared/primitives.js";
10
+ // Cohesive helper groups now live in sibling modules. They are imported for the
11
+ // discovery/activation code that stays here and re-exported below so existing
12
+ // import sites (sdk/index.ts, commands/extension.ts, health.ts, tests, …) keep
13
+ // importing everything from "./loader.js" unchanged.
14
+ import { normalizeNames, isKnownExtensionCapability, collectUnknownExtensionCapabilities, normalizeManifestCapabilities, formatUnknownExtensionCapabilityWarning, formatLegacyExtensionCapabilityAliasWarning, } from "./extension-capability-aliases.js";
15
+ import { normalizeExtensionPolicy, serializeExtensionPolicy, hydrateExtensionPolicy, normalizePolicySandboxProfile, evaluateExtensionPolicyForExtension, evaluateExtensionPolicyForCapability, evaluateExtensionPolicyForRegistration, } from "./extension-policy.js";
16
+ import { createEmptyExtensionHookRegistry, createEmptyExtensionCommandRegistry, createEmptyExtensionParserRegistry, createEmptyExtensionPreflightRegistry, createEmptyExtensionServiceRegistry, createEmptyExtensionRendererRegistry, createEmptyExtensionRegistrationRegistry, } from "./extension-registries.js";
17
+ import { normalizeCommandName, cloneContextSnapshot, } from "./extension-runtime-helpers.js";
18
+ export { parseUnknownExtensionCapabilityWarning, parseLegacyExtensionCapabilityAliasWarning, } from "./extension-capability-aliases.js";
19
+ export { createEmptyExtensionHookRegistry, createEmptyExtensionCommandRegistry, createEmptyExtensionParserRegistry, createEmptyExtensionPreflightRegistry, createEmptyExtensionServiceRegistry, createEmptyExtensionRendererRegistry, createEmptyExtensionRegistrationRegistry, } from "./extension-registries.js";
20
+ export { runBeforeCommandHooks, runAfterCommandHooks, runOnWriteHooks, runOnReadHooks, runOnIndexHooks, runCommandHandler, runParserOverride, runPreflightOverride, runServiceOverrideSync, runServiceOverride, runCommandOverride, runRendererOverride, } from "./extension-hook-runtime.js";
21
+ import { KNOWN_EXTENSION_SERVICE_NAMES, createDefaultExtensionGovernancePolicy, } from "./extension-types.js";
9
22
  export * from "./extension-types.js";
10
23
  const DEFAULT_EXTENSION_PRIORITY = 100;
11
24
  /* Types now in extension-types.ts - re-exported via `export * from "./extension-types.js"` above */
12
- function normalizeNames(values) {
13
- return [...new Set(values.map((value) => value.trim()).filter((value) => value.length > 0))].sort((a, b) => a.localeCompare(b));
14
- }
15
- function isKnownExtensionCapability(value) {
16
- return KNOWN_EXTENSION_CAPABILITIES.includes(value);
17
- }
18
- function collectUnknownExtensionCapabilities(capabilities) {
19
- return capabilities.filter((capability) => !isKnownExtensionCapability(capability));
20
- }
21
- const DEFAULT_EXTENSION_POLICY = Object.freeze({
22
- mode: "off",
23
- trust_mode: "off",
24
- require_provenance: false,
25
- trusted_extensions: [],
26
- default_sandbox_profile: "none",
27
- allowed_extensions: [],
28
- blocked_extensions: [],
29
- allowed_capabilities: [],
30
- blocked_capabilities: [],
31
- allowed_surfaces: [],
32
- blocked_surfaces: [],
33
- allowed_commands: [],
34
- blocked_commands: [],
35
- allowed_actions: [],
36
- blocked_actions: [],
37
- allowed_services: [],
38
- blocked_services: [],
39
- extension_overrides: [],
40
- });
25
+ const DEFAULT_EXTENSION_POLICY = Object.freeze(createDefaultExtensionGovernancePolicy());
41
26
  let extensionReloadEpoch = 0;
42
27
  export function nextExtensionReloadToken(seed = Date.now()) {
43
28
  extensionReloadEpoch += 1;
44
29
  return `${extensionReloadEpoch}-${seed}`;
45
30
  }
46
- function normalizePolicyName(value) {
47
- if (typeof value !== "string") {
48
- return "";
49
- }
50
- return value.trim().toLowerCase();
51
- }
52
- function normalizePolicyStringSet(values) {
53
- return new Set((values ?? [])
54
- .map((value) => value.trim().toLowerCase())
55
- .filter((value) => value.length > 0));
56
- }
57
- function normalizePolicySurfaceToken(value) {
58
- const normalized = value.trim().toLowerCase();
59
- if (normalized.length === 0) {
60
- return "";
61
- }
62
- const segments = normalized
63
- .split(/[.:/]/)
64
- .map((segment) => segment.replace(/[\s_-]+/g, ""))
65
- .filter((segment) => segment.length > 0);
66
- if (segments.length === 0) {
67
- return "";
68
- }
69
- if (segments.length === 1) {
70
- return segments[0];
71
- }
72
- return `${segments[0]}.${segments.slice(1).join("")}`;
73
- }
74
- function normalizePolicySurfaceSet(values) {
75
- return new Set((values ?? [])
76
- .map((value) => normalizePolicySurfaceToken(value))
77
- .filter((value) => value.length > 0));
78
- }
79
- function normalizePolicyMode(value) {
80
- const normalized = normalizePolicyName(value);
81
- if (KNOWN_EXTENSION_POLICY_MODES.includes(normalized)) {
82
- return normalized;
83
- }
84
- return "off";
85
- }
86
- function normalizePolicyTrustMode(value) {
87
- const normalized = normalizePolicyName(value);
88
- if (KNOWN_EXTENSION_TRUST_MODES.includes(normalized)) {
89
- return normalized;
90
- }
91
- return "off";
92
- }
93
- function normalizePolicySandboxProfile(value) {
94
- const normalized = normalizePolicyName(value);
95
- if (KNOWN_EXTENSION_SANDBOX_PROFILES.includes(normalized)) {
96
- return normalized;
97
- }
98
- return "none";
99
- }
100
- function toSortedList(values) {
101
- return [...new Set(values)].sort((left, right) => left.localeCompare(right));
102
- }
103
- function normalizeExtensionPolicy(settings) {
104
- const policy = settings.extensions.policy;
105
- const mode = normalizePolicyMode(policy?.mode);
106
- const trustMode = normalizePolicyTrustMode(policy?.trust_mode);
107
- const requireProvenance = policy?.require_provenance === true;
108
- const trustedExtensions = normalizePolicyStringSet(policy?.trusted_extensions);
109
- const defaultSandboxProfile = normalizePolicySandboxProfile(policy?.default_sandbox_profile);
110
- const allowedExtensions = normalizePolicyStringSet(policy?.allowed_extensions);
111
- const blockedExtensions = normalizePolicyStringSet(policy?.blocked_extensions);
112
- const allowedCapabilities = normalizePolicyStringSet(policy?.allowed_capabilities);
113
- const blockedCapabilities = normalizePolicyStringSet(policy?.blocked_capabilities);
114
- const allowedSurfaces = normalizePolicySurfaceSet(policy?.allowed_surfaces);
115
- const blockedSurfaces = normalizePolicySurfaceSet(policy?.blocked_surfaces);
116
- const allowedCommands = normalizePolicyStringSet(policy?.allowed_commands);
117
- const blockedCommands = normalizePolicyStringSet(policy?.blocked_commands);
118
- const allowedActions = normalizePolicyStringSet(policy?.allowed_actions);
119
- const blockedActions = normalizePolicyStringSet(policy?.blocked_actions);
120
- const allowedServices = normalizePolicyStringSet(policy?.allowed_services);
121
- const blockedServices = normalizePolicyStringSet(policy?.blocked_services);
122
- const overridesByName = new Map();
123
- for (const rawOverride of policy?.extension_overrides ?? []) {
124
- const name = normalizePolicyName(rawOverride.name);
125
- if (name.length === 0) {
126
- continue;
127
- }
128
- overridesByName.set(name, {
129
- name,
130
- disabled: rawOverride.disabled === true,
131
- requireTrusted: rawOverride.require_trusted === true,
132
- requireProvenance: rawOverride.require_provenance === true,
133
- sandboxProfile: rawOverride.sandbox_profile !== undefined
134
- ? normalizePolicySandboxProfile(rawOverride.sandbox_profile)
135
- : undefined,
136
- allowedCapabilities: normalizePolicyStringSet(rawOverride.allowed_capabilities),
137
- blockedCapabilities: normalizePolicyStringSet(rawOverride.blocked_capabilities),
138
- allowedSurfaces: normalizePolicySurfaceSet(rawOverride.allowed_surfaces),
139
- blockedSurfaces: normalizePolicySurfaceSet(rawOverride.blocked_surfaces),
140
- allowedCommands: normalizePolicyStringSet(rawOverride.allowed_commands),
141
- blockedCommands: normalizePolicyStringSet(rawOverride.blocked_commands),
142
- allowedActions: normalizePolicyStringSet(rawOverride.allowed_actions),
143
- blockedActions: normalizePolicyStringSet(rawOverride.blocked_actions),
144
- allowedServices: normalizePolicyStringSet(rawOverride.allowed_services),
145
- blockedServices: normalizePolicyStringSet(rawOverride.blocked_services),
146
- });
147
- }
148
- const warnings = [];
149
- for (const capability of toSortedList([...allowedCapabilities, ...blockedCapabilities])) {
150
- if (!isKnownExtensionCapability(capability)) {
151
- warnings.push(`extension_policy_unknown_capability:${capability}`);
152
- }
153
- }
154
- for (const override of [...overridesByName.values()].sort((left, right) => left.name.localeCompare(right.name))) {
155
- for (const capability of toSortedList([...override.allowedCapabilities, ...override.blockedCapabilities])) {
156
- if (!isKnownExtensionCapability(capability)) {
157
- warnings.push(`extension_policy_unknown_capability:${override.name}:${capability}`);
158
- }
159
- }
160
- }
161
- const knownSurfaces = new Set(KNOWN_EXTENSION_POLICY_SURFACES);
162
- for (const surface of toSortedList([...allowedSurfaces, ...blockedSurfaces])) {
163
- if (!knownSurfaces.has(surface)) {
164
- warnings.push(`extension_policy_unknown_surface:${surface}`);
165
- }
166
- }
167
- for (const override of [...overridesByName.values()].sort((left, right) => left.name.localeCompare(right.name))) {
168
- for (const surface of toSortedList([...override.allowedSurfaces, ...override.blockedSurfaces])) {
169
- if (!knownSurfaces.has(surface)) {
170
- warnings.push(`extension_policy_unknown_surface:${override.name}:${surface}`);
171
- }
172
- }
173
- }
174
- return {
175
- mode,
176
- trustMode,
177
- requireProvenance,
178
- trustedExtensions,
179
- defaultSandboxProfile,
180
- allowedExtensions,
181
- blockedExtensions,
182
- allowedCapabilities,
183
- blockedCapabilities,
184
- allowedSurfaces,
185
- blockedSurfaces,
186
- allowedCommands,
187
- blockedCommands,
188
- allowedActions,
189
- blockedActions,
190
- allowedServices,
191
- blockedServices,
192
- overridesByName,
193
- warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),
194
- };
195
- }
196
- function serializeExtensionPolicy(policy) {
197
- const overrides = [...policy.overridesByName.values()]
198
- .sort((left, right) => left.name.localeCompare(right.name))
199
- .map((override) => ({
200
- name: override.name,
201
- ...(override.disabled ? { disabled: true } : {}),
202
- ...(override.requireTrusted ? { require_trusted: true } : {}),
203
- ...(override.requireProvenance ? { require_provenance: true } : {}),
204
- ...(override.sandboxProfile ? { sandbox_profile: override.sandboxProfile } : {}),
205
- ...(override.allowedCapabilities.size > 0 ? { allowed_capabilities: toSortedList(override.allowedCapabilities) } : {}),
206
- ...(override.blockedCapabilities.size > 0 ? { blocked_capabilities: toSortedList(override.blockedCapabilities) } : {}),
207
- ...(override.allowedSurfaces.size > 0 ? { allowed_surfaces: toSortedList(override.allowedSurfaces) } : {}),
208
- ...(override.blockedSurfaces.size > 0 ? { blocked_surfaces: toSortedList(override.blockedSurfaces) } : {}),
209
- ...(override.allowedCommands.size > 0 ? { allowed_commands: toSortedList(override.allowedCommands) } : {}),
210
- ...(override.blockedCommands.size > 0 ? { blocked_commands: toSortedList(override.blockedCommands) } : {}),
211
- ...(override.allowedActions.size > 0 ? { allowed_actions: toSortedList(override.allowedActions) } : {}),
212
- ...(override.blockedActions.size > 0 ? { blocked_actions: toSortedList(override.blockedActions) } : {}),
213
- ...(override.allowedServices.size > 0 ? { allowed_services: toSortedList(override.allowedServices) } : {}),
214
- ...(override.blockedServices.size > 0 ? { blocked_services: toSortedList(override.blockedServices) } : {}),
215
- }));
216
- return {
217
- mode: policy.mode,
218
- trust_mode: policy.trustMode,
219
- require_provenance: policy.requireProvenance,
220
- trusted_extensions: toSortedList(policy.trustedExtensions),
221
- default_sandbox_profile: policy.defaultSandboxProfile,
222
- allowed_extensions: toSortedList(policy.allowedExtensions),
223
- blocked_extensions: toSortedList(policy.blockedExtensions),
224
- allowed_capabilities: toSortedList(policy.allowedCapabilities),
225
- blocked_capabilities: toSortedList(policy.blockedCapabilities),
226
- allowed_surfaces: toSortedList(policy.allowedSurfaces),
227
- blocked_surfaces: toSortedList(policy.blockedSurfaces),
228
- allowed_commands: toSortedList(policy.allowedCommands),
229
- blocked_commands: toSortedList(policy.blockedCommands),
230
- allowed_actions: toSortedList(policy.allowedActions),
231
- blocked_actions: toSortedList(policy.blockedActions),
232
- allowed_services: toSortedList(policy.allowedServices),
233
- blocked_services: toSortedList(policy.blockedServices),
234
- extension_overrides: overrides,
235
- };
236
- }
237
- function hydrateExtensionPolicy(policy) {
238
- const overridesByName = new Map();
239
- for (const rawOverride of policy.extension_overrides ?? []) {
240
- const name = normalizePolicyName(rawOverride.name);
241
- if (name.length === 0) {
242
- continue;
243
- }
244
- overridesByName.set(name, {
245
- name,
246
- disabled: rawOverride.disabled === true,
247
- requireTrusted: rawOverride.require_trusted === true,
248
- requireProvenance: rawOverride.require_provenance === true,
249
- sandboxProfile: rawOverride.sandbox_profile !== undefined
250
- ? normalizePolicySandboxProfile(rawOverride.sandbox_profile)
251
- : undefined,
252
- allowedCapabilities: normalizePolicyStringSet(rawOverride.allowed_capabilities),
253
- blockedCapabilities: normalizePolicyStringSet(rawOverride.blocked_capabilities),
254
- allowedSurfaces: normalizePolicySurfaceSet(rawOverride.allowed_surfaces),
255
- blockedSurfaces: normalizePolicySurfaceSet(rawOverride.blocked_surfaces),
256
- allowedCommands: normalizePolicyStringSet(rawOverride.allowed_commands),
257
- blockedCommands: normalizePolicyStringSet(rawOverride.blocked_commands),
258
- allowedActions: normalizePolicyStringSet(rawOverride.allowed_actions),
259
- blockedActions: normalizePolicyStringSet(rawOverride.blocked_actions),
260
- allowedServices: normalizePolicyStringSet(rawOverride.allowed_services),
261
- blockedServices: normalizePolicyStringSet(rawOverride.blocked_services),
262
- });
263
- }
264
- return {
265
- mode: normalizePolicyMode(policy.mode),
266
- trustMode: normalizePolicyTrustMode(policy.trust_mode),
267
- requireProvenance: policy.require_provenance === true,
268
- trustedExtensions: normalizePolicyStringSet(policy.trusted_extensions),
269
- defaultSandboxProfile: normalizePolicySandboxProfile(policy.default_sandbox_profile),
270
- allowedExtensions: normalizePolicyStringSet(policy.allowed_extensions),
271
- blockedExtensions: normalizePolicyStringSet(policy.blocked_extensions),
272
- allowedCapabilities: normalizePolicyStringSet(policy.allowed_capabilities),
273
- blockedCapabilities: normalizePolicyStringSet(policy.blocked_capabilities),
274
- allowedSurfaces: normalizePolicySurfaceSet(policy.allowed_surfaces),
275
- blockedSurfaces: normalizePolicySurfaceSet(policy.blocked_surfaces),
276
- allowedCommands: normalizePolicyStringSet(policy.allowed_commands),
277
- blockedCommands: normalizePolicyStringSet(policy.blocked_commands),
278
- allowedActions: normalizePolicyStringSet(policy.allowed_actions),
279
- blockedActions: normalizePolicyStringSet(policy.blocked_actions),
280
- allowedServices: normalizePolicyStringSet(policy.allowed_services),
281
- blockedServices: normalizePolicyStringSet(policy.blocked_services),
282
- overridesByName,
283
- warnings: [],
284
- };
285
- }
286
- function resolvePolicyOverride(policy, extensionName) {
287
- return policy.overridesByName.get(normalizePolicyName(extensionName)) ?? null;
288
- }
289
- function evaluatePolicySet(allowed, blocked, value, notAllowlistedReason, blockedReason) {
290
- if (blocked.has(value)) {
291
- return blockedReason;
292
- }
293
- if (allowed.size > 0 && !allowed.has(value)) {
294
- return notAllowlistedReason;
295
- }
296
- return null;
297
- }
298
- function resolvePolicyCapabilityReason(policy, extension, capability) {
299
- const normalizedCapability = capability.trim().toLowerCase();
300
- const override = resolvePolicyOverride(policy, extension.name);
301
- const allowed = override && override.allowedCapabilities.size > 0 ? override.allowedCapabilities : policy.allowedCapabilities;
302
- const blocked = new Set([
303
- ...policy.blockedCapabilities,
304
- ...(override ? override.blockedCapabilities : []),
305
- ]);
306
- return evaluatePolicySet(allowed, blocked, normalizedCapability, "capability_not_allowlisted", "capability_blocked");
307
- }
308
- function resolvePolicySurfaceReason(policy, extension, surface) {
309
- const override = resolvePolicyOverride(policy, extension.name);
310
- const allowed = override && override.allowedSurfaces.size > 0 ? override.allowedSurfaces : policy.allowedSurfaces;
311
- const blocked = new Set([
312
- ...policy.blockedSurfaces,
313
- ...(override ? override.blockedSurfaces : []),
314
- ]);
315
- return evaluatePolicySet(allowed, blocked, surface, "surface_not_allowlisted", "surface_blocked");
316
- }
317
- function resolvePolicyCommandReason(policy, extension, command) {
318
- const normalizedCommand = normalizeCommandName(command);
319
- if (normalizedCommand.length === 0) {
320
- return null;
321
- }
322
- const override = resolvePolicyOverride(policy, extension.name);
323
- const allowed = override && override.allowedCommands.size > 0 ? override.allowedCommands : policy.allowedCommands;
324
- const blocked = new Set([
325
- ...policy.blockedCommands,
326
- ...(override ? override.blockedCommands : []),
327
- ]);
328
- return evaluatePolicySet(allowed, blocked, normalizedCommand, "command_not_allowlisted", "command_blocked");
329
- }
330
- function resolvePolicyActionReason(policy, extension, action) {
331
- const normalizedAction = normalizePolicyName(action).replace(/\s+/g, "-");
332
- if (normalizedAction.length === 0) {
333
- return null;
334
- }
335
- const override = resolvePolicyOverride(policy, extension.name);
336
- const allowed = override && override.allowedActions.size > 0 ? override.allowedActions : policy.allowedActions;
337
- const blocked = new Set([
338
- ...policy.blockedActions,
339
- ...(override ? override.blockedActions : []),
340
- ]);
341
- return evaluatePolicySet(allowed, blocked, normalizedAction, "action_not_allowlisted", "action_blocked");
342
- }
343
- function resolvePolicyServiceReason(policy, extension, service) {
344
- const normalizedService = normalizePolicyName(service);
345
- if (normalizedService.length === 0) {
346
- return null;
347
- }
348
- const override = resolvePolicyOverride(policy, extension.name);
349
- const allowed = override && override.allowedServices.size > 0 ? override.allowedServices : policy.allowedServices;
350
- const blocked = new Set([
351
- ...policy.blockedServices,
352
- ...(override ? override.blockedServices : []),
353
- ]);
354
- return evaluatePolicySet(allowed, blocked, normalizedService, "service_not_allowlisted", "service_blocked");
355
- }
356
- function resolvePolicyExtensionReason(policy, extension) {
357
- const name = normalizePolicyName(extension.name);
358
- const override = resolvePolicyOverride(policy, extension.name);
359
- if (override?.disabled === true) {
360
- return "extension_override_disabled";
361
- }
362
- return evaluatePolicySet(policy.allowedExtensions, policy.blockedExtensions, name, "extension_not_allowlisted", "extension_blocked");
363
- }
364
- function resolvePolicyTrustReason(policy, extension) {
365
- if (policy.trustMode === "off") {
366
- return null;
367
- }
368
- const override = resolvePolicyOverride(policy, extension.name);
369
- const name = normalizePolicyName(extension.name);
370
- const trusted = extension.trusted === true;
371
- const provenanceVerified = extension.provenanceVerified === true;
372
- if (policy.trustedExtensions.size > 0 && !policy.trustedExtensions.has(name)) {
373
- return "extension_not_trusted";
374
- }
375
- if ((override?.requireTrusted === true || policy.trustMode === "warn" || policy.trustMode === "enforce") && !trusted) {
376
- return "extension_untrusted";
377
- }
378
- if ((policy.requireProvenance || override?.requireProvenance === true) && !provenanceVerified) {
379
- return "provenance_missing_or_unverified";
380
- }
381
- return null;
382
- }
383
- function resolvePolicySandboxReason(policy, extension) {
384
- if (policy.mode === "off") {
385
- return null;
386
- }
387
- const override = resolvePolicyOverride(policy, extension.name);
388
- const profile = override?.sandboxProfile ?? extension.sandboxProfile ?? policy.defaultSandboxProfile;
389
- if (profile === "none") {
390
- return null;
391
- }
392
- const permissions = extension.permissions;
393
- if (!permissions) {
394
- return "sandbox_permissions_missing";
395
- }
396
- const hasPermission = (name) => permissions[name] === true;
397
- if (profile === "restricted") {
398
- if (hasPermission("process_spawn")) {
399
- return "sandbox_restricted_disallows_process_spawn";
400
- }
401
- if (hasPermission("env_write")) {
402
- return "sandbox_restricted_disallows_env_write";
403
- }
404
- return null;
405
- }
406
- if (profile === "strict") {
407
- if (hasPermission("process_spawn")) {
408
- return "sandbox_strict_disallows_process_spawn";
409
- }
410
- if (hasPermission("network")) {
411
- return "sandbox_strict_disallows_network";
412
- }
413
- if (hasPermission("fs_write")) {
414
- return "sandbox_strict_disallows_fs_write";
415
- }
416
- if (hasPermission("env_write")) {
417
- return "sandbox_strict_disallows_env_write";
418
- }
419
- }
420
- return null;
421
- }
422
- function buildPolicyWarning(mode, scope, extension, reason, details = {}) {
423
- const tokens = Object.entries(details)
424
- .sort((left, right) => left[0].localeCompare(right[0]))
425
- .map(([key, value]) => `${key}=${value}`)
426
- .join(":");
427
- const suffix = tokens.length > 0 ? `:${tokens}` : "";
428
- return `extension_policy_${mode}_${scope}:${extension.layer}:${extension.name}:reason=${reason}${suffix}`;
429
- }
430
- function evaluateExtensionPolicyForExtension(policy, extension) {
431
- if (policy.mode === "off" && policy.trustMode === "off") {
432
- return { allowed: true, warning: null };
433
- }
434
- const reason = resolvePolicyExtensionReason(policy, extension);
435
- const trustReason = resolvePolicyTrustReason(policy, extension);
436
- const sandboxReason = resolvePolicySandboxReason(policy, extension);
437
- const extensionEnforced = reason && policy.mode === "enforce";
438
- const trustEnforced = trustReason && policy.trustMode === "enforce";
439
- const sandboxEnforced = sandboxReason && policy.mode === "enforce";
440
- if (!reason && !trustReason && !sandboxReason) {
441
- return { allowed: true, warning: null };
442
- }
443
- if (extensionEnforced) {
444
- return {
445
- allowed: false,
446
- warning: buildPolicyWarning("blocked", "extension", extension, reason),
447
- };
448
- }
449
- if (trustEnforced) {
450
- return {
451
- allowed: false,
452
- warning: buildPolicyWarning("blocked", "trust", extension, trustReason),
453
- };
454
- }
455
- if (sandboxEnforced) {
456
- return {
457
- allowed: false,
458
- warning: buildPolicyWarning("blocked", "extension", extension, sandboxReason),
459
- };
460
- }
461
- if (reason && policy.mode === "warn") {
462
- return {
463
- allowed: true,
464
- warning: buildPolicyWarning("violation", "extension", extension, reason),
465
- };
466
- }
467
- if (trustReason && policy.trustMode === "warn") {
468
- return {
469
- allowed: true,
470
- warning: buildPolicyWarning("violation", "trust", extension, trustReason),
471
- };
472
- }
473
- if (sandboxReason && policy.mode === "warn") {
474
- return {
475
- allowed: true,
476
- warning: buildPolicyWarning("violation", "extension", extension, sandboxReason),
477
- };
478
- }
479
- return {
480
- allowed: true,
481
- warning: null,
482
- };
483
- }
484
- function evaluateExtensionPolicyForCapability(policy, extension, capability) {
485
- if (policy.mode === "off") {
486
- return { allowed: true, warning: null };
487
- }
488
- const reason = resolvePolicyCapabilityReason(policy, extension, capability);
489
- if (!reason) {
490
- return { allowed: true, warning: null };
491
- }
492
- return {
493
- allowed: policy.mode === "warn",
494
- warning: buildPolicyWarning(policy.mode === "warn" ? "violation" : "blocked", "capability", extension, reason, { capability: capability.trim().toLowerCase() }),
495
- };
496
- }
497
- function evaluateExtensionPolicyForRegistration(policy, extension, surface, method, capability, details) {
498
- if (policy.mode === "off") {
499
- return { allowed: true, warning: null };
500
- }
501
- const capabilityReason = typeof capability === "string" ? resolvePolicyCapabilityReason(policy, extension, capability) : null;
502
- const surfaceReason = resolvePolicySurfaceReason(policy, extension, surface);
503
- const commandReason = details?.command ? resolvePolicyCommandReason(policy, extension, details.command) : null;
504
- const actionReason = details?.action ? resolvePolicyActionReason(policy, extension, details.action) : null;
505
- const serviceReason = details?.service ? resolvePolicyServiceReason(policy, extension, details.service) : null;
506
- const reason = capabilityReason ?? surfaceReason ?? commandReason ?? actionReason ?? serviceReason;
507
- if (!reason) {
508
- return { allowed: true, warning: null };
509
- }
510
- const warningDetails = {
511
- method: normalizePolicyName(method).replace(/\s+/g, "_"),
512
- surface,
513
- };
514
- if (capability) {
515
- warningDetails.capability = capability;
516
- }
517
- if (details?.command) {
518
- warningDetails.command = normalizeCommandName(details.command);
519
- }
520
- if (details?.action) {
521
- warningDetails.action = normalizePolicyName(details.action).replace(/\s+/g, "-");
522
- }
523
- if (details?.service) {
524
- warningDetails.service = normalizePolicyName(details.service);
525
- }
526
- const warning = buildPolicyWarning(policy.mode === "warn" ? "violation" : "blocked", "registration", extension, reason, warningDetails);
527
- return {
528
- allowed: policy.mode === "warn",
529
- warning,
530
- };
531
- }
532
- function resolveLegacyExtensionCapabilityAlias(capability) {
533
- const normalized = capability.trim().toLowerCase();
534
- if (normalized.length === 0) {
535
- return null;
536
- }
537
- return EXTENSION_CAPABILITY_LEGACY_ALIASES[normalized] ?? null;
538
- }
539
- function normalizeManifestCapabilities(rawCapabilities) {
540
- const normalizedCapabilities = normalizeNames([...rawCapabilities].map((value) => value.toLowerCase()));
541
- const remappedCapabilities = [];
542
- const legacyAliases = [];
543
- for (const capability of normalizedCapabilities) {
544
- const legacyAliasTarget = resolveLegacyExtensionCapabilityAlias(capability);
545
- if (legacyAliasTarget) {
546
- remappedCapabilities.push(legacyAliasTarget);
547
- legacyAliases.push({
548
- alias: capability,
549
- target: legacyAliasTarget,
550
- });
551
- continue;
552
- }
553
- remappedCapabilities.push(capability);
554
- }
555
- const dedupedLegacyAliases = [...new Map(legacyAliases.map((entry) => [`${entry.alias}>${entry.target}`, entry])).values()].sort((left, right) => left.alias.localeCompare(right.alias));
556
- return {
557
- capabilities: normalizeNames(remappedCapabilities),
558
- legacy_aliases: dedupedLegacyAliases,
559
- };
560
- }
561
- function levenshteinDistance(left, right) {
562
- if (left === right) {
563
- return 0;
564
- }
565
- if (left.length === 0) {
566
- return right.length;
567
- }
568
- if (right.length === 0) {
569
- return left.length;
570
- }
571
- const previous = new Array(right.length + 1);
572
- const current = new Array(right.length + 1);
573
- for (let j = 0; j <= right.length; j += 1) {
574
- previous[j] = j;
575
- }
576
- for (let i = 1; i <= left.length; i += 1) {
577
- current[0] = i;
578
- for (let j = 1; j <= right.length; j += 1) {
579
- const substitutionCost = left[i - 1] === right[j - 1] ? 0 : 1;
580
- current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + substitutionCost);
581
- }
582
- for (let j = 0; j <= right.length; j += 1) {
583
- previous[j] = current[j];
584
- }
585
- }
586
- return previous[right.length] ?? left.length;
587
- }
588
- function suggestKnownExtensionCapability(capability) {
589
- const normalized = capability.trim().toLowerCase();
590
- if (normalized.length === 0) {
591
- return null;
592
- }
593
- const legacyAlias = resolveLegacyExtensionCapabilityAlias(normalized);
594
- if (legacyAlias) {
595
- return legacyAlias;
596
- }
597
- let bestMatch = null;
598
- let bestDistance = Number.POSITIVE_INFINITY;
599
- for (const candidate of KNOWN_EXTENSION_CAPABILITIES) {
600
- const distance = levenshteinDistance(normalized, candidate);
601
- if (distance < bestDistance) {
602
- bestDistance = distance;
603
- bestMatch = candidate;
604
- }
605
- }
606
- const maxDistance = Math.max(1, Math.floor(normalized.length * 0.34));
607
- return bestMatch !== null && bestDistance <= maxDistance ? bestMatch : null;
608
- }
609
- function formatUnknownExtensionCapabilityWarning(layer, name, capability) {
610
- const allowed = KNOWN_EXTENSION_CAPABILITIES.join(",");
611
- const suggested = suggestKnownExtensionCapability(capability) ?? "none";
612
- return `extension_capability_unknown:${layer}:${name}:${capability}:allowed=${allowed}:suggested=${suggested}`;
613
- }
614
- function formatLegacyExtensionCapabilityAliasWarning(layer, name, aliases) {
615
- const aliasesToken = aliases.map((entry) => `${entry.alias}>${entry.target}`).join(",");
616
- return `extension_capability_legacy_alias:${layer}:${name}:aliases=${aliasesToken}`;
617
- }
618
- export function parseUnknownExtensionCapabilityWarning(warning) {
619
- const match = /^extension_capability_unknown:(global|project):([^:]+):([^:]+):allowed=([^:]+):suggested=([^:]+)$/.exec(warning.trim());
620
- if (!match) {
621
- return null;
622
- }
623
- const [, layerRaw, name, capability, allowedRaw, suggestedRaw] = match;
624
- const layer = layerRaw;
625
- const allowed_capabilities = allowedRaw
626
- .split(",")
627
- .map((value) => value.trim())
628
- .filter((value) => value.length > 0);
629
- const legacyAlias = resolveLegacyExtensionCapabilityAlias(capability);
630
- const suggestedFromWarning = suggestedRaw === "none" ? undefined : suggestedRaw;
631
- const suggested_capability = suggestedFromWarning ?? legacyAlias ?? undefined;
632
- const suggestion_source = suggested_capability
633
- ? legacyAlias === suggested_capability
634
- ? "legacy_alias"
635
- : "nearest_match"
636
- : undefined;
637
- return {
638
- layer,
639
- name,
640
- capability,
641
- allowed_capabilities,
642
- capability_contract_version: EXTENSION_CAPABILITY_CONTRACT_VERSION,
643
- suggested_capability,
644
- suggestion_source,
645
- legacy_alias_target: legacyAlias ?? undefined,
646
- };
647
- }
648
- export function parseLegacyExtensionCapabilityAliasWarning(warning) {
649
- const match = /^extension_capability_legacy_alias:(global|project):([^:]+):aliases=(.+)$/.exec(warning.trim());
650
- if (!match) {
651
- return [];
652
- }
653
- const [, layerRaw, name, aliasesRaw] = match;
654
- const layer = layerRaw;
655
- const allowedCapabilities = [...KNOWN_EXTENSION_CAPABILITIES];
656
- const parsed = [];
657
- for (const token of aliasesRaw.split(",")) {
658
- const [rawAlias, rawTarget] = token.split(">");
659
- const alias = rawAlias?.trim();
660
- const target = rawTarget?.trim().toLowerCase();
661
- if (!alias || !target || !isKnownExtensionCapability(target)) {
662
- continue;
663
- }
664
- parsed.push({
665
- layer,
666
- name,
667
- capability: alias,
668
- allowed_capabilities: allowedCapabilities,
669
- capability_contract_version: EXTENSION_CAPABILITY_CONTRACT_VERSION,
670
- suggested_capability: target,
671
- suggestion_source: "legacy_alias",
672
- legacy_alias_target: target,
673
- });
674
- }
675
- return parsed;
676
- }
677
31
  function parseManifest(raw) {
678
32
  if (typeof raw !== "object" || raw === null) {
679
33
  return null;
@@ -722,7 +76,7 @@ function parseManifest(raw) {
722
76
  }
723
77
  let provenance;
724
78
  if ("provenance" in candidate && candidate.provenance !== undefined && candidate.provenance !== null) {
725
- const provenanceRecord = asRecord(candidate.provenance);
79
+ const provenanceRecord = asRecordLoose(candidate.provenance);
726
80
  if (!provenanceRecord) {
727
81
  return null;
728
82
  }
@@ -752,7 +106,7 @@ function parseManifest(raw) {
752
106
  }
753
107
  let permissions;
754
108
  if ("permissions" in candidate && candidate.permissions !== undefined && candidate.permissions !== null) {
755
- const permissionsRecord = asRecord(candidate.permissions);
109
+ const permissionsRecord = asRecordLoose(candidate.permissions);
756
110
  if (!permissionsRecord) {
757
111
  return null;
758
112
  }
@@ -807,12 +161,6 @@ function parseManifest(raw) {
807
161
  legacy_capability_aliases: legacyCapabilityAliases.length > 0 ? legacyCapabilityAliases : undefined,
808
162
  };
809
163
  }
810
- function asRecord(value) {
811
- if (typeof value !== "object" || value === null) {
812
- return null;
813
- }
814
- return value;
815
- }
816
164
  function shouldEnable(name, enabled, disabled) {
817
165
  if (disabled.has(name)) {
818
166
  return false;
@@ -822,13 +170,6 @@ function shouldEnable(name, enabled, disabled) {
822
170
  }
823
171
  return enabled.has(name);
824
172
  }
825
- function isPathWithinDirectory(directory, targetPath) {
826
- const relative = path.relative(directory, targetPath);
827
- if (relative.length === 0) {
828
- return true;
829
- }
830
- return !relative.startsWith("..") && !path.isAbsolute(relative);
831
- }
832
173
  async function isCanonicalPathWithinDirectory(directory, targetPath) {
833
174
  const [resolvedDirectory, resolvedTargetPath] = await Promise.all([fs.realpath(directory), fs.realpath(targetPath)]);
834
175
  return isPathWithinDirectory(resolvedDirectory, resolvedTargetPath);
@@ -839,54 +180,6 @@ export function resolveExtensionRoots(pmRoot, cwd = process.cwd()) {
839
180
  project: path.join(pmRoot, "extensions"),
840
181
  };
841
182
  }
842
- export function createEmptyExtensionHookRegistry() {
843
- return {
844
- beforeCommand: [],
845
- afterCommand: [],
846
- onWrite: [],
847
- onRead: [],
848
- onIndex: [],
849
- };
850
- }
851
- export function createEmptyExtensionCommandRegistry() {
852
- return {
853
- overrides: [],
854
- handlers: [],
855
- };
856
- }
857
- export function createEmptyExtensionParserRegistry() {
858
- return {
859
- overrides: [],
860
- };
861
- }
862
- export function createEmptyExtensionPreflightRegistry() {
863
- return {
864
- overrides: [],
865
- };
866
- }
867
- export function createEmptyExtensionServiceRegistry() {
868
- return {
869
- overrides: [],
870
- };
871
- }
872
- export function createEmptyExtensionRendererRegistry() {
873
- return {
874
- overrides: [],
875
- };
876
- }
877
- export function createEmptyExtensionRegistrationRegistry() {
878
- return {
879
- commands: [],
880
- flags: [],
881
- item_fields: [],
882
- item_types: [],
883
- migrations: [],
884
- importers: [],
885
- exporters: [],
886
- search_providers: [],
887
- vector_store_adapters: [],
888
- };
889
- }
890
183
  async function listExtensionDirectories(extensionsRoot) {
891
184
  try {
892
185
  const entries = await fs.readdir(extensionsRoot, { withFileTypes: true });
@@ -1188,7 +481,7 @@ export async function loadExtensions(options) {
1188
481
  };
1189
482
  }
1190
483
  function resolveActivatableExtension(module) {
1191
- const moduleRecord = asRecord(module);
484
+ const moduleRecord = asRecordLoose(module);
1192
485
  if (!moduleRecord) {
1193
486
  return null;
1194
487
  }
@@ -1197,7 +490,7 @@ function resolveActivatableExtension(module) {
1197
490
  activate: moduleRecord.activate,
1198
491
  };
1199
492
  }
1200
- const defaultExport = asRecord(moduleRecord.default);
493
+ const defaultExport = asRecordLoose(moduleRecord.default);
1201
494
  if (defaultExport && typeof defaultExport.activate === "function") {
1202
495
  return {
1203
496
  activate: defaultExport.activate,
@@ -1205,46 +498,11 @@ function resolveActivatableExtension(module) {
1205
498
  }
1206
499
  return null;
1207
500
  }
1208
- function normalizeCommandName(command) {
1209
- return command
1210
- .trim()
1211
- .toLowerCase()
1212
- .split(/\s+/)
1213
- .filter((part) => part.length > 0)
1214
- .join(" ");
1215
- }
1216
- function defaultGlobalOptions() {
1217
- return {
1218
- json: false,
1219
- quiet: false,
1220
- noExtensions: false,
1221
- profile: false,
1222
- };
1223
- }
1224
- function cloneCommandOptionsSnapshot(options) {
1225
- return options ? cloneContextSnapshot(options) : {};
1226
- }
1227
- function cloneGlobalOptionsSnapshot(options) {
1228
- return options ? cloneContextSnapshot(options) : defaultGlobalOptions();
1229
- }
1230
- function cloneContextSnapshot(value) {
1231
- return structuredClone(value);
1232
- }
1233
501
  function isOutputRendererFormat(value) {
1234
502
  return value === "toon" || value === "json";
1235
503
  }
1236
- const EXTENSION_SERVICE_NAMES = [
1237
- "output_format",
1238
- "error_format",
1239
- "help_format",
1240
- "lock_acquire",
1241
- "lock_release",
1242
- "history_append",
1243
- "item_store_write",
1244
- "item_store_delete",
1245
- ];
1246
504
  function isExtensionServiceName(value) {
1247
- return EXTENSION_SERVICE_NAMES.includes(value);
505
+ return KNOWN_EXTENSION_SERVICE_NAMES.includes(value);
1248
506
  }
1249
507
  function assertHookHandler(hookName, hook) {
1250
508
  if (typeof hook !== "function") {
@@ -1748,7 +1006,7 @@ function createExtensionApi(extension, hooks, commands, parsers, preflight, serv
1748
1006
  assertExtensionCapability(extension, "services", "registerService");
1749
1007
  const normalizedService = String(service).trim().toLowerCase();
1750
1008
  if (!isExtensionServiceName(normalizedService)) {
1751
- throw new TypeError(`registerService service must be one of: ${EXTENSION_SERVICE_NAMES.join(", ")}`);
1009
+ throw new TypeError(`registerService service must be one of: ${KNOWN_EXTENSION_SERVICE_NAMES.join(", ")}`);
1752
1010
  }
1753
1011
  if (!allowRegistration("services.override", "registerService", "services", { service: normalizedService })) {
1754
1012
  return;
@@ -2006,18 +1264,6 @@ function createExtensionApi(extension, hooks, commands, parsers, preflight, serv
2006
1264
  },
2007
1265
  };
2008
1266
  }
2009
- async function executeRegisteredHooks(entries, hookName, context) {
2010
- const warnings = [];
2011
- for (const entry of entries) {
2012
- try {
2013
- await entry.run(cloneContextSnapshot(context));
2014
- }
2015
- catch {
2016
- warnings.push(`extension_hook_failed:${entry.layer}:${entry.name}:${hookName}`);
2017
- }
2018
- }
2019
- return warnings;
2020
- }
2021
1267
  function getRegistrationCounts(registrations) {
2022
1268
  const commandCount = registrations.commands.length;
2023
1269
  const flagCount = registrations.flags.reduce((total, entry) => total + entry.flags.length, 0);
@@ -2206,374 +1452,5 @@ export async function activateExtensions(loadResult) {
2206
1452
  registration_counts: getRegistrationCounts(registrations),
2207
1453
  };
2208
1454
  }
2209
- export async function runBeforeCommandHooks(hooks, context) {
2210
- return executeRegisteredHooks(hooks.beforeCommand, "beforeCommand", context);
2211
- }
2212
- export async function runAfterCommandHooks(hooks, context) {
2213
- return executeRegisteredHooks(hooks.afterCommand, "afterCommand", context);
2214
- }
2215
- export async function runOnWriteHooks(hooks, context) {
2216
- return executeRegisteredHooks(hooks.onWrite, "onWrite", context);
2217
- }
2218
- export async function runOnReadHooks(hooks, context) {
2219
- return executeRegisteredHooks(hooks.onRead, "onRead", context);
2220
- }
2221
- export async function runOnIndexHooks(hooks, context) {
2222
- return executeRegisteredHooks(hooks.onIndex, "onIndex", context);
2223
- }
2224
- export async function runCommandHandler(commands, context) {
2225
- const command = normalizeCommandName(context.command);
2226
- if (command.length === 0) {
2227
- return {
2228
- handled: false,
2229
- result: null,
2230
- warnings: [],
2231
- };
2232
- }
2233
- const matched = [...commands.handlers].reverse().find((entry) => entry.command === command);
2234
- if (!matched) {
2235
- return {
2236
- handled: false,
2237
- result: null,
2238
- warnings: [],
2239
- };
2240
- }
2241
- try {
2242
- const result = await matched.run({
2243
- command,
2244
- args: cloneContextSnapshot(context.args),
2245
- options: cloneContextSnapshot(context.options),
2246
- global: cloneContextSnapshot(context.global),
2247
- pm_root: context.pm_root,
2248
- });
2249
- return {
2250
- handled: true,
2251
- result,
2252
- warnings: [],
2253
- };
2254
- }
2255
- catch (error) {
2256
- const exitCode = typeof error === "object" && error !== null && "exitCode" in error
2257
- ? error.exitCode
2258
- : undefined;
2259
- if (typeof exitCode === "number" && Number.isFinite(exitCode)) {
2260
- throw error;
2261
- }
2262
- return {
2263
- handled: false,
2264
- result: null,
2265
- warnings: [`extension_command_handler_failed:${matched.layer}:${matched.name}:${matched.command}`],
2266
- };
2267
- }
2268
- }
2269
- export async function runParserOverride(parsers, context) {
2270
- const command = normalizeCommandName(context.command);
2271
- if (command.length === 0) {
2272
- return {
2273
- overridden: false,
2274
- context: {
2275
- command,
2276
- args: cloneContextSnapshot(context.args),
2277
- options: cloneCommandOptionsSnapshot(context.options),
2278
- global: cloneGlobalOptionsSnapshot(context.global),
2279
- pm_root: context.pm_root,
2280
- },
2281
- warnings: [],
2282
- };
2283
- }
2284
- const matched = [...parsers.overrides].reverse().find((entry) => entry.command === command);
2285
- if (!matched) {
2286
- return {
2287
- overridden: false,
2288
- context: {
2289
- command,
2290
- args: cloneContextSnapshot(context.args),
2291
- options: cloneCommandOptionsSnapshot(context.options),
2292
- global: cloneGlobalOptionsSnapshot(context.global),
2293
- pm_root: context.pm_root,
2294
- },
2295
- warnings: [],
2296
- };
2297
- }
2298
- try {
2299
- const delta = (await Promise.resolve(matched.run({
2300
- command,
2301
- args: cloneContextSnapshot(context.args),
2302
- options: cloneCommandOptionsSnapshot(context.options),
2303
- global: cloneGlobalOptionsSnapshot(context.global),
2304
- pm_root: context.pm_root,
2305
- }))) ?? {};
2306
- const nextArgs = Array.isArray(delta.args) ? cloneContextSnapshot(delta.args) : cloneContextSnapshot(context.args);
2307
- const nextOptions = delta.options ? cloneCommandOptionsSnapshot(delta.options) : cloneCommandOptionsSnapshot(context.options);
2308
- const nextGlobal = delta.global ? cloneGlobalOptionsSnapshot(delta.global) : cloneGlobalOptionsSnapshot(context.global);
2309
- return {
2310
- overridden: true,
2311
- context: {
2312
- command,
2313
- args: nextArgs,
2314
- options: nextOptions,
2315
- global: nextGlobal,
2316
- pm_root: context.pm_root,
2317
- },
2318
- warnings: [],
2319
- };
2320
- }
2321
- catch {
2322
- return {
2323
- overridden: false,
2324
- context: {
2325
- command,
2326
- args: cloneContextSnapshot(context.args),
2327
- options: cloneCommandOptionsSnapshot(context.options),
2328
- global: cloneGlobalOptionsSnapshot(context.global),
2329
- pm_root: context.pm_root,
2330
- },
2331
- warnings: [`extension_parser_override_failed:${matched.layer}:${matched.name}:${matched.command}`],
2332
- };
2333
- }
2334
- }
2335
- export async function runPreflightOverride(preflight, context) {
2336
- const matched = [...preflight.overrides].reverse()[0];
2337
- const baseContext = {
2338
- command: normalizeCommandName(context.command),
2339
- args: cloneContextSnapshot(context.args),
2340
- options: cloneCommandOptionsSnapshot(context.options),
2341
- global: cloneGlobalOptionsSnapshot(context.global),
2342
- pm_root: context.pm_root,
2343
- };
2344
- const baseDecision = cloneContextSnapshot(context.decision);
2345
- if (!matched) {
2346
- return {
2347
- overridden: false,
2348
- context: baseContext,
2349
- decision: baseDecision,
2350
- warnings: [],
2351
- };
2352
- }
2353
- try {
2354
- const delta = (await Promise.resolve(matched.run({
2355
- command: baseContext.command,
2356
- args: cloneContextSnapshot(baseContext.args),
2357
- options: cloneCommandOptionsSnapshot(baseContext.options),
2358
- global: cloneGlobalOptionsSnapshot(baseContext.global),
2359
- pm_root: baseContext.pm_root,
2360
- decision: cloneContextSnapshot(baseDecision),
2361
- }))) ?? {};
2362
- const nextContext = {
2363
- command: baseContext.command,
2364
- args: Array.isArray(delta.args) ? cloneContextSnapshot(delta.args) : baseContext.args,
2365
- options: delta.options ? cloneCommandOptionsSnapshot(delta.options) : baseContext.options,
2366
- global: delta.global ? cloneGlobalOptionsSnapshot(delta.global) : baseContext.global,
2367
- pm_root: baseContext.pm_root,
2368
- };
2369
- const nextDecision = {
2370
- enforce_item_format_gate: typeof delta.enforce_item_format_gate === "boolean"
2371
- ? delta.enforce_item_format_gate
2372
- : baseDecision.enforce_item_format_gate,
2373
- run_preflight_item_format_sync: typeof delta.run_preflight_item_format_sync === "boolean"
2374
- ? delta.run_preflight_item_format_sync
2375
- : baseDecision.run_preflight_item_format_sync,
2376
- run_extension_migrations: typeof delta.run_extension_migrations === "boolean"
2377
- ? delta.run_extension_migrations
2378
- : baseDecision.run_extension_migrations,
2379
- enforce_mandatory_migration_gate: typeof delta.enforce_mandatory_migration_gate === "boolean"
2380
- ? delta.enforce_mandatory_migration_gate
2381
- : baseDecision.enforce_mandatory_migration_gate,
2382
- };
2383
- return {
2384
- overridden: true,
2385
- context: nextContext,
2386
- decision: nextDecision,
2387
- warnings: [],
2388
- };
2389
- }
2390
- catch {
2391
- return {
2392
- overridden: false,
2393
- context: baseContext,
2394
- decision: baseDecision,
2395
- warnings: [`extension_preflight_override_failed:${matched.layer}:${matched.name}`],
2396
- };
2397
- }
2398
- }
2399
- function resolveDefaultServiceResult(context) {
2400
- return {
2401
- handled: false,
2402
- result: context.payload,
2403
- warnings: [],
2404
- };
2405
- }
2406
- export function runServiceOverrideSync(services, context) {
2407
- const matches = [...services.overrides].reverse().filter((entry) => entry.service === context.service);
2408
- if (matches.length === 0) {
2409
- return resolveDefaultServiceResult(context);
2410
- }
2411
- const warnings = [];
2412
- for (const matched of matches) {
2413
- try {
2414
- const serviceContext = {
2415
- service: context.service,
2416
- command: context.command ? normalizeCommandName(context.command) : undefined,
2417
- args: context.args ? cloneContextSnapshot(context.args) : undefined,
2418
- options: context.options ? cloneCommandOptionsSnapshot(context.options) : undefined,
2419
- global: context.global ? cloneGlobalOptionsSnapshot(context.global) : undefined,
2420
- pm_root: context.pm_root,
2421
- payload: cloneContextSnapshot(context.payload),
2422
- };
2423
- const result = matched.run(serviceContext);
2424
- if (result instanceof Promise) {
2425
- warnings.push(`extension_service_override_async_unsupported:${matched.layer}:${matched.name}:${matched.service}`);
2426
- continue;
2427
- }
2428
- if (context.service === "output_format" && (result === null || result === undefined || result === serviceContext.payload)) {
2429
- continue;
2430
- }
2431
- return {
2432
- handled: true,
2433
- result,
2434
- warnings,
2435
- };
2436
- }
2437
- catch {
2438
- warnings.push(`extension_service_override_failed:${matched.layer}:${matched.name}:${matched.service}`);
2439
- }
2440
- }
2441
- return {
2442
- handled: false,
2443
- result: context.payload,
2444
- warnings,
2445
- };
2446
- }
2447
- export async function runServiceOverride(services, context) {
2448
- const matches = [...services.overrides].reverse().filter((entry) => entry.service === context.service);
2449
- if (matches.length === 0) {
2450
- return resolveDefaultServiceResult(context);
2451
- }
2452
- const warnings = [];
2453
- for (const matched of matches) {
2454
- try {
2455
- const serviceContext = {
2456
- service: context.service,
2457
- command: context.command ? normalizeCommandName(context.command) : undefined,
2458
- args: context.args ? cloneContextSnapshot(context.args) : undefined,
2459
- options: context.options ? cloneCommandOptionsSnapshot(context.options) : undefined,
2460
- global: context.global ? cloneGlobalOptionsSnapshot(context.global) : undefined,
2461
- pm_root: context.pm_root,
2462
- payload: cloneContextSnapshot(context.payload),
2463
- };
2464
- const result = await Promise.resolve(matched.run(serviceContext));
2465
- if (context.service === "output_format" && (result === null || result === undefined || result === serviceContext.payload)) {
2466
- continue;
2467
- }
2468
- return {
2469
- handled: true,
2470
- result,
2471
- warnings,
2472
- };
2473
- }
2474
- catch {
2475
- warnings.push(`extension_service_override_failed:${matched.layer}:${matched.name}:${matched.service}`);
2476
- }
2477
- }
2478
- return {
2479
- handled: false,
2480
- result: context.payload,
2481
- warnings,
2482
- };
2483
- }
2484
- export function runCommandOverride(commands, context) {
2485
- const command = normalizeCommandName(context.command);
2486
- if (command.length === 0) {
2487
- return {
2488
- overridden: false,
2489
- result: context.result,
2490
- warnings: [],
2491
- };
2492
- }
2493
- const matched = [...commands.overrides].reverse().find((entry) => entry.command === command);
2494
- if (!matched) {
2495
- return {
2496
- overridden: false,
2497
- result: context.result,
2498
- warnings: [],
2499
- };
2500
- }
2501
- try {
2502
- const overrideOptions = cloneCommandOptionsSnapshot(context.options);
2503
- const overrideGlobal = cloneGlobalOptionsSnapshot(context.global);
2504
- const overrideResult = matched.run({
2505
- command,
2506
- args: cloneContextSnapshot(context.args),
2507
- options: overrideOptions,
2508
- global: overrideGlobal,
2509
- pm_root: context.pm_root,
2510
- result: cloneContextSnapshot(context.result),
2511
- });
2512
- if (overrideResult instanceof Promise) {
2513
- return {
2514
- overridden: false,
2515
- result: context.result,
2516
- warnings: [`extension_command_override_async_unsupported:${matched.layer}:${matched.name}:${matched.command}`],
2517
- };
2518
- }
2519
- return {
2520
- overridden: true,
2521
- result: overrideResult,
2522
- warnings: [],
2523
- };
2524
- }
2525
- catch {
2526
- return {
2527
- overridden: false,
2528
- result: context.result,
2529
- warnings: [`extension_command_override_failed:${matched.layer}:${matched.name}:${matched.command}`],
2530
- };
2531
- }
2532
- }
2533
- export function runRendererOverride(renderers, context) {
2534
- const matched = [...renderers.overrides].reverse().find((entry) => entry.format === context.format);
2535
- if (!matched) {
2536
- return {
2537
- overridden: false,
2538
- rendered: null,
2539
- warnings: [],
2540
- };
2541
- }
2542
- try {
2543
- const rendererCommand = typeof context.command === "string" ? normalizeCommandName(context.command) : "";
2544
- const rendererArgs = Array.isArray(context.args) ? cloneContextSnapshot(context.args) : [];
2545
- const rendererOptions = cloneCommandOptionsSnapshot(context.options);
2546
- const rendererGlobal = cloneGlobalOptionsSnapshot(context.global);
2547
- const rendererPmRoot = typeof context.pm_root === "string" ? context.pm_root : "";
2548
- const rendered = matched.run({
2549
- format: context.format,
2550
- command: rendererCommand,
2551
- args: rendererArgs,
2552
- options: rendererOptions,
2553
- global: rendererGlobal,
2554
- pm_root: rendererPmRoot,
2555
- result: cloneContextSnapshot(context.result),
2556
- });
2557
- if (typeof rendered !== "string") {
2558
- return {
2559
- overridden: false,
2560
- rendered: null,
2561
- warnings: [`extension_renderer_invalid_result:${matched.layer}:${matched.name}:${matched.format}`],
2562
- };
2563
- }
2564
- return {
2565
- overridden: true,
2566
- rendered,
2567
- warnings: [],
2568
- };
2569
- }
2570
- catch {
2571
- return {
2572
- overridden: false,
2573
- rendered: null,
2574
- warnings: [`extension_renderer_failed:${matched.layer}:${matched.name}:${matched.format}`],
2575
- };
2576
- }
2577
- }
2578
1455
  //# sourceMappingURL=loader.js.map
2579
- //# debugId=6e8bb06d-d0ca-5e37-9e3a-cf76b1b21ace
1456
+ //# debugId=4fba8687-0797-5479-afc8-12f1a2e5a954