@unbrained/pm-cli 2026.11.30 → 2026.12.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 (382) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/commander-usage.js +10 -10
  3. package/dist/cli/error-guidance.js +5 -5
  4. package/dist/cli/extension-command-help.js +6 -6
  5. package/dist/cli/help-json-payload.js +7 -7
  6. package/dist/cli/main.js +5 -5
  7. package/dist/cli/register-list-query.js +10 -10
  8. package/dist/cli/register-mutation.js +3 -3
  9. package/dist/cli/runtime/invocation-command-path.js +2 -0
  10. package/dist/cli/runtime/read-output-mutation-retry.js +1 -1
  11. package/dist/cli-bundle/bundle-manifest.json +1 -1
  12. package/dist/cli-bundle/chunks/{chunk-DCWGM7CY.js → chunk-3HKPVOAN.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-Z7YL2SUM.js → chunk-3KEMIPKG.js} +2 -2
  14. package/dist/cli-bundle/chunks/{chunk-TX74QJ4W.js → chunk-4YYFY33T.js} +2 -2
  15. package/dist/cli-bundle/chunks/{chunk-47ZS6RPL.js → chunk-7NAO7I75.js} +2 -2
  16. package/dist/cli-bundle/chunks/{chunk-IGEFPHV7.js → chunk-7V65VACG.js} +52 -52
  17. package/dist/cli-bundle/chunks/chunk-A5ZEMOVR.js +2 -0
  18. package/dist/cli-bundle/chunks/{chunk-5PNOVDVO.js → chunk-AHV3CSQG.js} +2 -2
  19. package/dist/cli-bundle/chunks/{chunk-KCVSSONY.js → chunk-C6WM6ZN4.js} +3 -3
  20. package/dist/cli-bundle/chunks/chunk-CBUC4X7Q.js +127 -0
  21. package/dist/cli-bundle/chunks/{chunk-CCKM5YQM.js → chunk-G6TARHFK.js} +2 -2
  22. package/dist/cli-bundle/chunks/{chunk-TY55UX6M.js → chunk-GOEQXVOI.js} +2 -2
  23. package/dist/cli-bundle/chunks/chunk-I4SPJQQI.js +3 -0
  24. package/dist/cli-bundle/chunks/{chunk-Q4VZSMUL.js → chunk-L2ZSSMYY.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-NHBG5ET3.js → chunk-MZZ4ZJ5Z.js} +2 -2
  26. package/dist/cli-bundle/chunks/chunk-NRQCBUYD.js +113 -0
  27. package/dist/cli-bundle/chunks/{chunk-YVTALIN3.js → chunk-OBPO6V7H.js} +2 -2
  28. package/dist/cli-bundle/chunks/{chunk-KXTKLDKD.js → chunk-OXC5KBIQ.js} +2 -2
  29. package/dist/cli-bundle/chunks/{chunk-HXQ3OHQR.js → chunk-PCDTWL6V.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-AOTI76Q6.js → chunk-Q6K7HWZ7.js} +2 -2
  31. package/dist/cli-bundle/chunks/chunk-QDV7S2QS.js +2 -0
  32. package/dist/cli-bundle/chunks/{chunk-NZSXWIX7.js → chunk-ROTEELDL.js} +7 -7
  33. package/dist/cli-bundle/chunks/{chunk-WFYE34TO.js → chunk-SDXCJZKB.js} +23 -23
  34. package/dist/cli-bundle/chunks/{chunk-2SBTXR6C.js → chunk-SY5C3U32.js} +3 -3
  35. package/dist/cli-bundle/chunks/{chunk-FR7ULTM4.js → chunk-TKUG2X24.js} +2 -2
  36. package/dist/cli-bundle/chunks/{chunk-FECZV72T.js → chunk-UNBW2LF3.js} +2 -2
  37. package/dist/cli-bundle/chunks/chunk-V2S4XAX3.js +2 -0
  38. package/dist/cli-bundle/chunks/chunk-WSEIEDEK.js +2 -0
  39. package/dist/cli-bundle/chunks/{chunk-ZA5NS3PL.js → chunk-ZL6J6JYT.js} +6 -6
  40. package/dist/cli-bundle/chunks/{field-option-collisions-2F2Z7R7B.js → field-option-collisions-BBGTV7AD.js} +2 -2
  41. package/dist/cli-bundle/chunks/item-revision-3LENTXYF.js +2 -0
  42. package/dist/cli-bundle/chunks/item-transaction-56J5OCHA.js +2 -0
  43. package/dist/cli-bundle/chunks/{linked-resource-value-list-WXPPYUVQ.js → linked-resource-value-list-ZBIY4H23.js} +2 -2
  44. package/dist/cli-bundle/chunks/{mutation-actor-UK3QNEEB.js → mutation-actor-NHN33ITJ.js} +2 -2
  45. package/dist/cli-bundle/chunks/{mutation-admission-UTDYPFWP.js → mutation-admission-PGKJTCG6.js} +2 -2
  46. package/dist/cli-bundle/chunks/{register-list-query-DRA3CWHI.js → register-list-query-7S5QWDTI.js} +11 -11
  47. package/dist/cli-bundle/chunks/{register-mutation-WO74VLEQ.js → register-mutation-EK6DVIQK.js} +5 -5
  48. package/dist/cli-bundle/chunks/{register-operations-CRBKH7WN.js → register-operations-6MURXE4V.js} +2 -2
  49. package/dist/cli-bundle/chunks/{register-setup-6V6NQB5C.js → register-setup-RW26X3GJ.js} +2 -2
  50. package/dist/cli-bundle/chunks/{stage-DYEHGASU.js → stage-4ZCF74G4.js} +2 -2
  51. package/dist/cli-bundle/focused-chunks/{chunk-RQYVX2T6.js → chunk-2DGKVXFT.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/chunk-2UWKU2BQ.js +3 -0
  53. package/dist/cli-bundle/focused-chunks/{chunk-A3DORTXS.js → chunk-3COWDIPX.js} +54 -54
  54. package/dist/cli-bundle/focused-chunks/{chunk-UQJ4PY2Y.js → chunk-4SCFAWAW.js} +2 -2
  55. package/dist/cli-bundle/focused-chunks/{chunk-7G7JIXLL.js → chunk-6BKT6XQN.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/chunk-6IY5CVGJ.js +2 -0
  57. package/dist/cli-bundle/focused-chunks/chunk-7A6SEZEY.js +4 -0
  58. package/dist/cli-bundle/focused-chunks/{chunk-IJ3T3W4U.js → chunk-BHNBPCHP.js} +2 -2
  59. package/dist/cli-bundle/focused-chunks/{chunk-LWBZ7UGG.js → chunk-EQCQTYKO.js} +2 -2
  60. package/dist/cli-bundle/focused-chunks/{chunk-FM5WQ6ZU.js → chunk-HTDYNY4L.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/{chunk-TQQO42C2.js → chunk-J72TRWR5.js} +26 -26
  62. package/dist/cli-bundle/focused-chunks/{chunk-L357ZAES.js → chunk-JPZGC3W4.js} +5 -5
  63. package/dist/cli-bundle/focused-chunks/{chunk-62AMZMR4.js → chunk-KNBGHCIP.js} +3 -3
  64. package/dist/cli-bundle/focused-chunks/chunk-N64AC5G6.js +100 -0
  65. package/dist/cli-bundle/focused-chunks/{chunk-IIVDBAJM.js → chunk-OG57ESZK.js} +2 -2
  66. package/dist/cli-bundle/focused-chunks/{chunk-MZNV26XE.js → chunk-P2H3GTJK.js} +2 -2
  67. package/dist/cli-bundle/focused-chunks/chunk-QZRYGYTI.js +2 -0
  68. package/dist/cli-bundle/focused-chunks/chunk-SQMOF65W.js +2 -0
  69. package/dist/cli-bundle/focused-chunks/chunk-T3ILWAEV.js +2 -0
  70. package/dist/cli-bundle/focused-chunks/{chunk-SXC3NVZI.js → chunk-TR22GU7M.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/{chunk-M57KDG7I.js → chunk-TXTPAFHJ.js} +2 -2
  72. package/dist/cli-bundle/focused-chunks/chunk-VK3IE3TS.js +29 -0
  73. package/dist/cli-bundle/focused-chunks/{chunk-NJTKGBSK.js → chunk-VQIC3UZB.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/{chunk-U35K7FSE.js → chunk-W4JMV7GF.js} +2 -2
  75. package/dist/cli-bundle/focused-chunks/{field-option-collisions-7TG7STO7.js → field-option-collisions-2C6DLUC4.js} +2 -2
  76. package/dist/cli-bundle/focused-chunks/item-revision-723XCQPS.js +2 -0
  77. package/dist/cli-bundle/focused-chunks/{item-transaction-2IC2MLML.js → item-transaction-LQLQLZE7.js} +2 -2
  78. package/dist/cli-bundle/focused-chunks/{mutation-actor-LJVF2HVD.js → mutation-actor-DJMZUIZI.js} +2 -2
  79. package/dist/cli-bundle/focused-chunks/mutation-admission-SDWQVVHN.js +2 -0
  80. package/dist/cli-bundle/focused-chunks/{stage-MWR73LTZ.js → stage-QBZIK3T5.js} +2 -2
  81. package/dist/cli-bundle/main.js +27 -27
  82. package/dist/cli-bundle/sdk-authoring.js +1 -1
  83. package/dist/cli-bundle/sdk-contracts.js +1 -1
  84. package/dist/cli-bundle/sdk-core.js +1 -1
  85. package/dist/cli-bundle/sdk-governance.js +1 -1
  86. package/dist/cli-bundle/sdk-graph.js +1 -1
  87. package/dist/cli-bundle/sdk-merge.js +61 -61
  88. package/dist/cli-bundle/sdk-query.js +1 -1
  89. package/dist/cli-bundle/sdk-runtime.js +1 -1
  90. package/dist/cli-bundle/sdk-testing.js +1 -1
  91. package/dist/cli-bundle/sdk.js +2 -2
  92. package/dist/core/extensions/reserved-host-flags.js +1 -1
  93. package/dist/core/shared/secret-rules.d.ts +86 -12
  94. package/dist/core/shared/secret-rules.js +7 -5
  95. package/dist/sdk/cli-bootstrap.js +1 -1
  96. package/dist/sdk/cli-contracts/flag-contracts.d.ts +50 -0
  97. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  98. package/dist/sdk/cli-contracts/runtime-contracts.d.ts +3 -1
  99. package/dist/sdk/cli-contracts/runtime-contracts.js +1 -1
  100. package/dist/sdk/extension/command-options.js +1 -1
  101. package/dist/sdk/extension/install-sources.d.ts +2 -2
  102. package/dist/sdk/extension/install-sources.js +5 -5
  103. package/dist/sdk/lifecycle/expect-hash-admission.d.ts +15 -0
  104. package/dist/sdk/lifecycle/expect-hash-admission.js +2 -0
  105. package/dist/sdk/lifecycle/item-revision.d.ts +4 -1
  106. package/dist/sdk/lifecycle/item-revision.js +1 -1
  107. package/dist/sdk/mutation-guard.js +1 -1
  108. package/dist/sdk/output-contracts.js +1 -1
  109. package/dist/sdk/output-projection.d.ts +1 -1
  110. package/dist/sdk/output-projection.js +1 -1
  111. package/dist/sdk/public-surface.json +1 -1
  112. package/dist/sdk/query/aggregate.js +1 -1
  113. package/dist/sdk/query/context.js +1 -1
  114. package/dist/sdk/query/list.js +1 -1
  115. package/dist/sdk/query/next.js +1 -1
  116. package/dist/sdk/query/search-contracts.js +1 -1
  117. package/dist/sdk/read-output/surfaces.js +1 -1
  118. package/dist/sdk/read-output-budget.d.ts +1 -1
  119. package/dist/sdk/read-output-budget.js +1 -1
  120. package/dist/sdk/read-output-contracts.js +1 -1
  121. package/dist/sdk/read-output-rows.js +1 -1
  122. package/docs/COMMANDS.md +37 -0
  123. package/docs/MUTATION_INTEGRITY.md +226 -10
  124. package/docs/SDK.md +16 -6
  125. package/docs/agent-task-token-baseline.json +1 -1
  126. package/marketplace.json +1 -1
  127. package/node_modules/tar/README.md +1792 -1147
  128. package/node_modules/tar/dist/commonjs/bytes.d.ts +21 -0
  129. package/node_modules/tar/dist/commonjs/bytes.js +83 -0
  130. package/node_modules/tar/dist/commonjs/codec.d.ts +53 -0
  131. package/node_modules/tar/dist/commonjs/codec.js +35 -0
  132. package/node_modules/tar/dist/commonjs/concat.d.ts +3 -0
  133. package/node_modules/tar/dist/commonjs/concat.js +20 -0
  134. package/node_modules/tar/dist/commonjs/create.d.ts +39 -2
  135. package/node_modules/tar/dist/commonjs/create.js +150 -64
  136. package/node_modules/tar/dist/commonjs/dealias.d.ts +79 -0
  137. package/node_modules/tar/dist/commonjs/dealias.js +50 -0
  138. package/node_modules/tar/dist/commonjs/delete.d.ts +19 -0
  139. package/node_modules/tar/dist/commonjs/delete.js +121 -0
  140. package/node_modules/tar/dist/commonjs/entries.d.ts +82 -0
  141. package/node_modules/tar/dist/commonjs/entries.js +398 -0
  142. package/node_modules/tar/dist/commonjs/extract.d.ts +14 -2
  143. package/node_modules/tar/dist/commonjs/extract.js +40 -81
  144. package/node_modules/tar/dist/commonjs/fs.d.ts +201 -0
  145. package/node_modules/tar/dist/commonjs/fs.js +5 -0
  146. package/node_modules/tar/dist/commonjs/header.d.ts +4 -4
  147. package/node_modules/tar/dist/commonjs/header.js +71 -53
  148. package/node_modules/tar/dist/commonjs/index.d.ts +25 -18
  149. package/node_modules/tar/dist/commonjs/index.js +46 -18
  150. package/node_modules/tar/dist/commonjs/index.min.js +2 -3
  151. package/node_modules/tar/dist/commonjs/large-numbers.d.ts +2 -2
  152. package/node_modules/tar/dist/commonjs/large-numbers.js +4 -4
  153. package/node_modules/tar/dist/commonjs/list.d.ts +23 -6
  154. package/node_modules/tar/dist/commonjs/list.js +99 -138
  155. package/node_modules/tar/dist/commonjs/mkdir.d.ts +16 -11
  156. package/node_modules/tar/dist/commonjs/mkdir.js +121 -159
  157. package/node_modules/tar/dist/commonjs/normalize-unicode.js +9 -0
  158. package/node_modules/tar/dist/commonjs/options.d.ts +284 -513
  159. package/node_modules/tar/dist/commonjs/options.js +20 -61
  160. package/node_modules/tar/dist/commonjs/pack.d.ts +150 -96
  161. package/node_modules/tar/dist/commonjs/pack.js +752 -445
  162. package/node_modules/tar/dist/commonjs/parser.d.ts +98 -0
  163. package/node_modules/tar/dist/commonjs/parser.js +452 -0
  164. package/node_modules/tar/dist/commonjs/path-reservations.d.ts +17 -7
  165. package/node_modules/tar/dist/commonjs/path-reservations.js +110 -140
  166. package/node_modules/tar/dist/commonjs/path.d.ts +19 -0
  167. package/node_modules/tar/dist/commonjs/path.js +90 -0
  168. package/node_modules/tar/dist/commonjs/pax.d.ts +3 -1
  169. package/node_modules/tar/dist/commonjs/pax.js +67 -36
  170. package/node_modules/tar/dist/commonjs/read-entry.d.ts +97 -11
  171. package/node_modules/tar/dist/commonjs/read-entry.js +251 -97
  172. package/node_modules/tar/dist/commonjs/read-file.d.ts +22 -0
  173. package/node_modules/tar/dist/commonjs/read-file.js +104 -0
  174. package/node_modules/tar/dist/commonjs/replace.d.ts +45 -1
  175. package/node_modules/tar/dist/commonjs/replace.js +164 -211
  176. package/node_modules/tar/dist/commonjs/server/codecs.d.ts +38 -0
  177. package/node_modules/tar/dist/commonjs/server/codecs.js +252 -0
  178. package/node_modules/tar/dist/commonjs/server/index.d.ts +115 -0
  179. package/node_modules/tar/dist/commonjs/server/index.js +166 -0
  180. package/node_modules/tar/dist/commonjs/server/index.min.js +3 -0
  181. package/node_modules/tar/dist/commonjs/strip-absolute-path.d.ts +8 -0
  182. package/node_modules/tar/dist/commonjs/strip-absolute-path.js +17 -20
  183. package/node_modules/tar/dist/commonjs/to-stream.d.ts +7 -0
  184. package/node_modules/tar/dist/commonjs/to-stream.js +22 -0
  185. package/node_modules/tar/dist/commonjs/types.d.ts +4 -3
  186. package/node_modules/tar/dist/commonjs/types.js +4 -3
  187. package/node_modules/tar/dist/commonjs/unpack.d.ts +143 -89
  188. package/node_modules/tar/dist/commonjs/unpack.js +780 -725
  189. package/node_modules/tar/dist/commonjs/update.d.ts +11 -1
  190. package/node_modules/tar/dist/commonjs/update.js +37 -28
  191. package/node_modules/tar/dist/commonjs/warn.d.ts +27 -0
  192. package/node_modules/tar/dist/commonjs/warn.js +36 -0
  193. package/node_modules/tar/dist/commonjs/win32-path.d.ts +16 -0
  194. package/node_modules/tar/dist/commonjs/win32-path.js +67 -0
  195. package/node_modules/tar/dist/commonjs/write-entry.d.ts +64 -111
  196. package/node_modules/tar/dist/commonjs/write-entry.js +108 -672
  197. package/node_modules/tar/dist/commonjs/write-flag.d.ts +18 -0
  198. package/node_modules/tar/dist/commonjs/write-flag.js +29 -0
  199. package/node_modules/tar/dist/esm/bytes.d.ts +21 -0
  200. package/node_modules/tar/dist/esm/bytes.js +72 -0
  201. package/node_modules/tar/dist/esm/codec.d.ts +53 -0
  202. package/node_modules/tar/dist/esm/codec.js +32 -0
  203. package/node_modules/tar/dist/esm/concat.d.ts +3 -0
  204. package/node_modules/tar/dist/esm/concat.js +16 -0
  205. package/node_modules/tar/dist/esm/create.d.ts +39 -2
  206. package/node_modules/tar/dist/esm/create.js +144 -61
  207. package/node_modules/tar/dist/esm/dealias.d.ts +79 -0
  208. package/node_modules/tar/dist/esm/dealias.js +46 -0
  209. package/node_modules/tar/dist/esm/delete.d.ts +19 -0
  210. package/node_modules/tar/dist/esm/delete.js +117 -0
  211. package/node_modules/tar/dist/esm/entries.d.ts +82 -0
  212. package/node_modules/tar/dist/esm/entries.js +388 -0
  213. package/node_modules/tar/dist/esm/extract.d.ts +14 -2
  214. package/node_modules/tar/dist/esm/extract.js +37 -44
  215. package/node_modules/tar/dist/esm/fs.d.ts +201 -0
  216. package/node_modules/tar/dist/esm/fs.js +4 -0
  217. package/node_modules/tar/dist/esm/header.d.ts +4 -4
  218. package/node_modules/tar/dist/esm/header.js +71 -53
  219. package/node_modules/tar/dist/esm/index.d.ts +25 -18
  220. package/node_modules/tar/dist/esm/index.js +23 -18
  221. package/node_modules/tar/dist/esm/index.min.js +2 -3
  222. package/node_modules/tar/dist/esm/large-numbers.d.ts +2 -2
  223. package/node_modules/tar/dist/esm/large-numbers.js +4 -4
  224. package/node_modules/tar/dist/esm/list.d.ts +23 -6
  225. package/node_modules/tar/dist/esm/list.js +96 -101
  226. package/node_modules/tar/dist/esm/mkdir.d.ts +16 -11
  227. package/node_modules/tar/dist/esm/mkdir.js +119 -154
  228. package/node_modules/tar/dist/esm/normalize-unicode.js +9 -0
  229. package/node_modules/tar/dist/esm/options.d.ts +284 -513
  230. package/node_modules/tar/dist/esm/options.js +17 -51
  231. package/node_modules/tar/dist/esm/pack.d.ts +150 -96
  232. package/node_modules/tar/dist/esm/pack.js +750 -441
  233. package/node_modules/tar/dist/esm/parser.d.ts +98 -0
  234. package/node_modules/tar/dist/esm/parser.js +448 -0
  235. package/node_modules/tar/dist/esm/path-reservations.d.ts +17 -7
  236. package/node_modules/tar/dist/esm/path-reservations.js +110 -140
  237. package/node_modules/tar/dist/esm/path.d.ts +19 -0
  238. package/node_modules/tar/dist/esm/path.js +80 -0
  239. package/node_modules/tar/dist/esm/pax.d.ts +3 -1
  240. package/node_modules/tar/dist/esm/pax.js +66 -35
  241. package/node_modules/tar/dist/esm/read-entry.d.ts +97 -11
  242. package/node_modules/tar/dist/esm/read-entry.js +248 -96
  243. package/node_modules/tar/dist/esm/read-file.d.ts +22 -0
  244. package/node_modules/tar/dist/esm/read-file.js +99 -0
  245. package/node_modules/tar/dist/esm/replace.d.ts +45 -1
  246. package/node_modules/tar/dist/esm/replace.js +160 -207
  247. package/node_modules/tar/dist/esm/server/codecs.d.ts +38 -0
  248. package/node_modules/tar/dist/esm/server/codecs.js +214 -0
  249. package/node_modules/tar/dist/esm/server/index.d.ts +115 -0
  250. package/node_modules/tar/dist/esm/server/index.js +102 -0
  251. package/node_modules/tar/dist/esm/server/index.min.js +3 -0
  252. package/node_modules/tar/dist/esm/strip-absolute-path.d.ts +8 -0
  253. package/node_modules/tar/dist/esm/strip-absolute-path.js +17 -20
  254. package/node_modules/tar/dist/esm/to-stream.d.ts +7 -0
  255. package/node_modules/tar/dist/esm/to-stream.js +18 -0
  256. package/node_modules/tar/dist/esm/types.d.ts +4 -3
  257. package/node_modules/tar/dist/esm/types.js +4 -3
  258. package/node_modules/tar/dist/esm/unpack.d.ts +143 -89
  259. package/node_modules/tar/dist/esm/unpack.js +776 -719
  260. package/node_modules/tar/dist/esm/update.d.ts +11 -1
  261. package/node_modules/tar/dist/esm/update.js +35 -28
  262. package/node_modules/tar/dist/esm/warn.d.ts +27 -0
  263. package/node_modules/tar/dist/esm/warn.js +31 -0
  264. package/node_modules/tar/dist/esm/win32-path.d.ts +16 -0
  265. package/node_modules/tar/dist/esm/win32-path.js +60 -0
  266. package/node_modules/tar/dist/esm/write-entry.d.ts +64 -111
  267. package/node_modules/tar/dist/esm/write-entry.js +107 -633
  268. package/node_modules/tar/dist/esm/write-flag.d.ts +18 -0
  269. package/node_modules/tar/dist/esm/write-flag.js +25 -0
  270. package/node_modules/tar/package.json +68 -224
  271. package/package.json +2 -2
  272. package/packages/pm-beads/package.json +1 -1
  273. package/packages/pm-calendar/package.json +1 -1
  274. package/packages/pm-command-kit/package.json +1 -1
  275. package/packages/pm-digital-twin/package.json +1 -1
  276. package/packages/pm-governance-audit/package.json +1 -1
  277. package/packages/pm-guide-shell/package.json +1 -1
  278. package/packages/pm-kanban/package.json +1 -1
  279. package/packages/pm-lifecycle-hooks/package.json +1 -1
  280. package/packages/pm-linked-test-adapters/package.json +1 -1
  281. package/packages/pm-search-advanced/package.json +1 -1
  282. package/packages/pm-templates/package.json +1 -1
  283. package/packages/pm-todos/package.json +1 -1
  284. package/packages/pm-vcs/package.json +1 -1
  285. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  286. package/plugins/pm-claude/package.json +1 -1
  287. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  288. package/plugins/pm-codex/package.json +1 -1
  289. package/plugins/pm-codex/plugin.json +1 -1
  290. package/runtime-dependencies.json +1 -1
  291. package/dist/cli-bundle/chunks/chunk-3TXEWHQX.js +0 -125
  292. package/dist/cli-bundle/chunks/chunk-JPJNJHQW.js +0 -2
  293. package/dist/cli-bundle/chunks/chunk-NVYDPNQP.js +0 -2
  294. package/dist/cli-bundle/chunks/chunk-SJWIPGZW.js +0 -113
  295. package/dist/cli-bundle/chunks/chunk-USBTXMKS.js +0 -2
  296. package/dist/cli-bundle/chunks/chunk-VCXQ6A35.js +0 -3
  297. package/dist/cli-bundle/chunks/chunk-YPMNXG2C.js +0 -2
  298. package/dist/cli-bundle/chunks/item-revision-UAF6L47R.js +0 -2
  299. package/dist/cli-bundle/chunks/item-transaction-RJECL53Y.js +0 -2
  300. package/dist/cli-bundle/focused-chunks/chunk-2UUBS4BG.js +0 -2
  301. package/dist/cli-bundle/focused-chunks/chunk-4ER3VMST.js +0 -2
  302. package/dist/cli-bundle/focused-chunks/chunk-4YBMHMBJ.js +0 -2
  303. package/dist/cli-bundle/focused-chunks/chunk-HXM7K6VH.js +0 -100
  304. package/dist/cli-bundle/focused-chunks/chunk-NGHT2LNG.js +0 -3
  305. package/dist/cli-bundle/focused-chunks/chunk-P55AZPFN.js +0 -2
  306. package/dist/cli-bundle/focused-chunks/chunk-WAP3DF4B.js +0 -27
  307. package/dist/cli-bundle/focused-chunks/chunk-XR745UGE.js +0 -4
  308. package/dist/cli-bundle/focused-chunks/item-revision-J7EUGCHR.js +0 -2
  309. package/dist/cli-bundle/focused-chunks/mutation-admission-SLFAUONA.js +0 -2
  310. package/node_modules/@isaacs/fs-minipass/LICENSE +0 -15
  311. package/node_modules/@isaacs/fs-minipass/README.md +0 -71
  312. package/node_modules/@isaacs/fs-minipass/dist/commonjs/index.d.ts +0 -118
  313. package/node_modules/@isaacs/fs-minipass/dist/commonjs/index.js +0 -430
  314. package/node_modules/@isaacs/fs-minipass/dist/commonjs/package.json +0 -3
  315. package/node_modules/@isaacs/fs-minipass/dist/esm/index.d.ts +0 -118
  316. package/node_modules/@isaacs/fs-minipass/dist/esm/index.js +0 -420
  317. package/node_modules/@isaacs/fs-minipass/dist/esm/package.json +0 -3
  318. package/node_modules/@isaacs/fs-minipass/package.json +0 -72
  319. package/node_modules/chownr/LICENSE.md +0 -63
  320. package/node_modules/chownr/README.md +0 -3
  321. package/node_modules/chownr/dist/commonjs/index.d.ts +0 -3
  322. package/node_modules/chownr/dist/commonjs/index.js +0 -93
  323. package/node_modules/chownr/dist/commonjs/package.json +0 -3
  324. package/node_modules/chownr/dist/esm/index.d.ts +0 -3
  325. package/node_modules/chownr/dist/esm/index.js +0 -85
  326. package/node_modules/chownr/dist/esm/package.json +0 -3
  327. package/node_modules/chownr/package.json +0 -69
  328. package/node_modules/minipass/LICENSE.md +0 -55
  329. package/node_modules/minipass/README.md +0 -825
  330. package/node_modules/minipass/dist/commonjs/index.d.ts +0 -545
  331. package/node_modules/minipass/dist/commonjs/index.js +0 -1038
  332. package/node_modules/minipass/dist/commonjs/package.json +0 -3
  333. package/node_modules/minipass/dist/esm/index.d.ts +0 -545
  334. package/node_modules/minipass/dist/esm/index.js +0 -1020
  335. package/node_modules/minipass/dist/esm/package.json +0 -3
  336. package/node_modules/minipass/package.json +0 -77
  337. package/node_modules/minizlib/LICENSE +0 -26
  338. package/node_modules/minizlib/README.md +0 -64
  339. package/node_modules/minizlib/dist/commonjs/constants.d.ts +0 -2
  340. package/node_modules/minizlib/dist/commonjs/constants.js +0 -123
  341. package/node_modules/minizlib/dist/commonjs/index.d.ts +0 -99
  342. package/node_modules/minizlib/dist/commonjs/index.js +0 -416
  343. package/node_modules/minizlib/dist/commonjs/package.json +0 -3
  344. package/node_modules/minizlib/dist/esm/constants.d.ts +0 -2
  345. package/node_modules/minizlib/dist/esm/constants.js +0 -117
  346. package/node_modules/minizlib/dist/esm/index.d.ts +0 -99
  347. package/node_modules/minizlib/dist/esm/index.js +0 -363
  348. package/node_modules/minizlib/dist/esm/package.json +0 -3
  349. package/node_modules/minizlib/package.json +0 -80
  350. package/node_modules/tar/dist/commonjs/get-write-flag.d.ts +0 -2
  351. package/node_modules/tar/dist/commonjs/get-write-flag.js +0 -32
  352. package/node_modules/tar/dist/commonjs/make-command.d.ts +0 -49
  353. package/node_modules/tar/dist/commonjs/make-command.js +0 -52
  354. package/node_modules/tar/dist/commonjs/normalize-windows-path.d.ts +0 -2
  355. package/node_modules/tar/dist/commonjs/normalize-windows-path.js +0 -12
  356. package/node_modules/tar/dist/commonjs/parse.d.ts +0 -92
  357. package/node_modules/tar/dist/commonjs/parse.js +0 -655
  358. package/node_modules/tar/dist/commonjs/process-umask.d.ts +0 -2
  359. package/node_modules/tar/dist/commonjs/process-umask.js +0 -7
  360. package/node_modules/tar/dist/commonjs/warn-method.d.ts +0 -24
  361. package/node_modules/tar/dist/commonjs/warn-method.js +0 -31
  362. package/node_modules/tar/dist/esm/get-write-flag.d.ts +0 -2
  363. package/node_modules/tar/dist/esm/get-write-flag.js +0 -26
  364. package/node_modules/tar/dist/esm/make-command.d.ts +0 -49
  365. package/node_modules/tar/dist/esm/make-command.js +0 -48
  366. package/node_modules/tar/dist/esm/normalize-windows-path.d.ts +0 -2
  367. package/node_modules/tar/dist/esm/normalize-windows-path.js +0 -9
  368. package/node_modules/tar/dist/esm/parse.d.ts +0 -92
  369. package/node_modules/tar/dist/esm/parse.js +0 -651
  370. package/node_modules/tar/dist/esm/process-umask.d.ts +0 -2
  371. package/node_modules/tar/dist/esm/process-umask.js +0 -3
  372. package/node_modules/tar/dist/esm/warn-method.d.ts +0 -24
  373. package/node_modules/tar/dist/esm/warn-method.js +0 -27
  374. package/node_modules/yallist/LICENSE.md +0 -63
  375. package/node_modules/yallist/README.md +0 -205
  376. package/node_modules/yallist/dist/commonjs/index.d.ts +0 -39
  377. package/node_modules/yallist/dist/commonjs/index.js +0 -384
  378. package/node_modules/yallist/dist/commonjs/package.json +0 -3
  379. package/node_modules/yallist/dist/esm/index.d.ts +0 -39
  380. package/node_modules/yallist/dist/esm/index.js +0 -379
  381. package/node_modules/yallist/dist/esm/package.json +0 -3
  382. package/node_modules/yallist/package.json +0 -68
@@ -1 +1 @@
1
- {"name":"pm","owner":{"name":"unbrained","url":"https://github.com/unbraind/pm-cli"},"description":"Official marketplace for pm CLI — native git-based project management for Claude Code and AI coding agents.","version":"2026.11.30","plugins":[{"name":"pm-claude","source":"./plugins/pm-claude","description":"Native pm CLI integration for Claude Code — 32 MCP tools, 14 workflow skills with slash invocations, 4 subagents, hybrid TUI task tracking, session context injection, and coordination subagents for git-based project management without leaving Claude Code.","version":"2026.11.30","author":{"name":"unbrained","url":"https://github.com/unbraind/pm-cli"},"homepage":"https://github.com/unbraind/pm-cli","repository":"https://github.com/unbraind/pm-cli","license":"MIT","keywords":["pm-cli","project-management","mcp","tasks","agents","workflows","git-native","task-tracker","ai"],"category":"productivity"}]}
1
+ {"name":"pm","owner":{"name":"unbrained","url":"https://github.com/unbraind/pm-cli"},"description":"Official marketplace for pm CLI — native git-based project management for Claude Code and AI coding agents.","version":"2026.12.2","plugins":[{"name":"pm-claude","source":"./plugins/pm-claude","description":"Native pm CLI integration for Claude Code — 32 MCP tools, 14 workflow skills with slash invocations, 4 subagents, hybrid TUI task tracking, session context injection, and coordination subagents for git-based project management without leaving Claude Code.","version":"2026.12.2","author":{"name":"unbrained","url":"https://github.com/unbraind/pm-cli"},"homepage":"https://github.com/unbraind/pm-cli","repository":"https://github.com/unbraind/pm-cli","license":"MIT","keywords":["pm-cli","project-management","mcp","tasks","agents","workflows","git-native","task-tracker","ai"],"category":"productivity"}]}
@@ -1,16 +1,16 @@
1
- import{pathExists as K,resolveItemTypeRegistry as X,EXIT_CODE as Q,getSettingsPath as Z,resolvePmRoot as ee,readSettings as ne,getActiveExtensionRegistrations as te,locateItem as oe,runActiveServiceOverride as se,levenshteinDistanceWithinLimit as E}from"../sdk/runtime-primitives.js";import{BUILTIN_ITEM_TYPE_VALUES as ae}from"../types/index.js";import{PM_CORE_COMMAND_NAMES as R,resolveSubcommandFlagContractsForCommand as re}from"../sdk/cli-contracts.js";import{formatCommanderErrorForDisplay as ie,formatCommanderErrorForJson as ce,projectLeanErrorEnvelope as de}from"./error-guidance.js";import{normalizeHelpCommandPath as v}from"./help-content.js";import{getCommandPath as le}from"./registration-helpers.js";import{EXECUTABLE_COMMAND_ALIASES as L,findBootstrapCommandTokenIndex as h,normalizeBootstrapInvocation as me,parseBootstrapHelpRequest as ue,parseBootstrapGlobalOptions as _,parseBootstrapCommandName as O,resolveLifecycleVerb as fe}from"./bootstrap-args.js";import{extractProvidedOptionFlags as pe,normalizeLongFlag as p,renderPmCommand as y}from"./argv-utils.js";import{normalizeExtensionNameForMatch as ge}from"./commands/extension/shared.js";import{canonicalizeCommandSuggestions as F,rankCommandPaths as he,resolveMisnestedCommandPath as Ce}from"../sdk/agent/command-suggestions.js";import{isCompatibleRecoveryFlag as we,renderMissingOptionRetry as ke,resolveLifecycleVerbRecovery as ye}from"../sdk/agent/command-recovery.js";import{resolvePmCommandScopeArgs as xe}from"../sdk/command-line.js";import{attachOutputTokenAccounting as U}from"../sdk/output-token-accounting.js";import{findPmNamespacedCommand as $,resolvePmCommandAlias as C}from"../sdk/cli-contracts/command-aliases.js";import{redactRefusalArgv as Se}from"./runtime/refusal-credential-redaction.js";import{redactUrlCredentialsInText as b}from"../sdk/command-line.js";const P=ae.join("|"),Ie={calendar:"calendar",cal:"calendar",reindex:"search-advanced","search-advanced":"search-advanced",guide:"guide-shell",completion:"guide-shell",templates:"templates","test-runs":"linked-test-adapters",beads:"beads",todos:"todos"},_e={comments:{"--body":["--add"],"--text":["--add"],"--comment":["--add"]},notes:{"--body":["--add"],"--text":["--add"],"--note":["--add"]},learnings:{"--body":["--add"],"--text":["--add"],"--learning":["--add"]},update:{"--add-tag":["--add-tags"],"--remove-tag":["--remove-tags"],"--tag":["--tags"]},create:{"--add-tag":["--add-tags"],"--tag":["--tags"]}},A=["add-field","add-status","add-type","apply-preset","list","list-fields","remap-status","remove-field","remove-status","remove-type","rename-field","rename-type","show","show-field","show-status"];function Te(t,s){const e=_e[t];if(!e)return[];const o=p(s);for(const[a,n]of Object.entries(e))if(p(a)===o)return n;return[]}function fn(t,s,e){if(e.length===0)return t;const o=e.map(i=>({...i,name:b(i.name),error:b(i.error),...i.recovery_commands?{recovery_commands:i.recovery_commands.map(b)}:{}}));if(s){const i=o.find(m=>m.declared_command_match===!0),{token_accounting:c,...d}=JSON.parse(t),l={...d,...i?{extension_command_failure:{code:"extension_command_activation_failed",extension:i.name,layer:i.layer,error:i.error,recovery_commands:i.recovery_commands??[]}}:{},failed_extensions:o};return JSON.stringify(c===void 0?l:U(l,m=>`${JSON.stringify(m,null,2)}
2
- `),null,2)}const a=o.map(i=>`- ${i.layer}:${i.name}: ${i.error}`).join(`
3
- `),n=o.find(i=>i.declared_command_match===!0);if(!n)return`${t}
1
+ import{pathExists as X,resolveItemTypeRegistry as Q,EXIT_CODE as Z,getSettingsPath as ee,resolvePmRoot as ne,readSettings as te,getActiveExtensionRegistrations as oe,locateItem as se,runActiveServiceOverride as ae,levenshteinDistanceWithinLimit as E}from"../sdk/runtime-primitives.js";import{BUILTIN_ITEM_TYPE_VALUES as re}from"../types/index.js";import{PM_CORE_COMMAND_NAMES as F,resolveSubcommandFlagContractsForCommand as ie}from"../sdk/cli-contracts.js";import{listNestedSubcommandFlagContractPaths as R}from"../sdk/cli-contracts/flag-contracts.js";import{formatCommanderErrorForDisplay as ce,formatCommanderErrorForJson as de,projectLeanErrorEnvelope as le}from"./error-guidance.js";import{normalizeHelpCommandPath as v}from"./help-content.js";import{getCommandPath as me}from"./registration-helpers.js";import{EXECUTABLE_COMMAND_ALIASES as L,findBootstrapCommandTokenIndex as C,normalizeBootstrapInvocation as ue,parseBootstrapHelpRequest as fe,parseBootstrapGlobalOptions as _,parseBootstrapCommandName as O,resolveLifecycleVerb as pe}from"./bootstrap-args.js";import{extractProvidedOptionFlags as ge,normalizeLongFlag as p,renderPmCommand as x}from"./argv-utils.js";import{normalizeExtensionNameForMatch as he}from"./commands/extension/shared.js";import{canonicalizeCommandSuggestions as U,rankCommandPaths as Ce,resolveMisnestedCommandPath as we}from"../sdk/agent/command-suggestions.js";import{isCompatibleRecoveryFlag as ke,renderMissingOptionRetry as ye,resolveLifecycleVerbRecovery as xe}from"../sdk/agent/command-recovery.js";import{resolvePmCommandScopeArgs as Se}from"../sdk/command-line.js";import{attachOutputTokenAccounting as $}from"../sdk/output-token-accounting.js";import{findPmNamespacedCommand as A,resolvePmCommandAlias as w,resolvePmCommandOperation as Ie}from"../sdk/cli-contracts/command-aliases.js";import{redactRefusalArgv as _e}from"./runtime/refusal-credential-redaction.js";import{redactUrlCredentialsInText as b}from"../sdk/command-line.js";const P=re.join("|"),Te={calendar:"calendar",cal:"calendar",reindex:"search-advanced","search-advanced":"search-advanced",guide:"guide-shell",completion:"guide-shell",templates:"templates","test-runs":"linked-test-adapters",beads:"beads",todos:"todos"},ve={comments:{"--body":["--add"],"--text":["--add"],"--comment":["--add"]},notes:{"--body":["--add"],"--text":["--add"],"--note":["--add"]},learnings:{"--body":["--add"],"--text":["--add"],"--learning":["--add"]},update:{"--add-tag":["--add-tags"],"--remove-tag":["--remove-tags"],"--tag":["--tags"]},create:{"--add-tag":["--add-tags"],"--tag":["--tags"]}},M=["add-field","add-status","add-type","apply-preset","list","list-fields","remap-status","remove-field","remove-status","remove-type","rename-field","rename-type","show","show-field","show-status"];function Oe(n,s){const e=ve[n];if(!e)return[];const t=p(s);for(const[a,o]of Object.entries(e))if(p(a)===t)return o;return[]}function Cn(n,s,e){if(e.length===0)return n;const t=e.map(i=>({...i,name:b(i.name),error:b(i.error),...i.recovery_commands?{recovery_commands:i.recovery_commands.map(b)}:{}}));if(s){const i=t.find(m=>m.declared_command_match===!0),{token_accounting:c,...d}=JSON.parse(n),l={...d,...i?{extension_command_failure:{code:"extension_command_activation_failed",extension:i.name,layer:i.layer,error:i.error,recovery_commands:i.recovery_commands??[]}}:{},failed_extensions:t};return JSON.stringify(c===void 0?l:$(l,m=>`${JSON.stringify(m,null,2)}
2
+ `),null,2)}const a=t.map(i=>`- ${i.layer}:${i.name}: ${i.error}`).join(`
3
+ `),o=t.find(i=>i.declared_command_match===!0);if(!o)return`${n}
4
4
  Extension activation failures:
5
- ${a}`;const r=(n.recovery_commands??[]).map(i=>`- ${i}`).join(`
6
- `);return`Extension command unavailable: ${n.layer}:${n.name}
7
- ${n.error}${r.length>0?`
5
+ ${a}`;const r=(o.recovery_commands??[]).map(i=>`- ${i}`).join(`
6
+ `);return`Extension command unavailable: ${o.layer}:${o.name}
7
+ ${o.error}${r.length>0?`
8
8
  Recovery:
9
9
  ${r}`:""}
10
10
 
11
- ${t}
11
+ ${n}
12
12
  Extension activation failures:
13
- ${a}`}function pn(t){return ue(t).commandPathTokens[0]??O(t)??"<command>"}function z(t,s){const e=new Set,o=[...t.commands];for(;o.length>0;){const a=o.shift();if(!a)continue;const n=v(le(a)),r=n.split(" ").some(i=>i.startsWith("_"));n.length>0&&!r&&e.add(n),o.push(...a.commands)}for(const a of s.keys()){const n=v(a),r=n.split(" ").some(i=>i.startsWith("_"));n.length>0&&!r&&e.add(n)}return[...e].sort((a,n)=>a.localeCompare(n))}function M(t,s){const e=t.trim().toLowerCase(),o=s.trim().toLowerCase();if(o.length===0)return Number.POSITIVE_INFINITY;const a=e.split(" ");if(e===o)return 0;if(a.includes(o))return 1;if(a.some(i=>i.startsWith(o)))return 2;if(e.includes(o))return 3;const n=o.length>=5?2:1;let r=Number.POSITIVE_INFINITY;for(const i of a){const c=E(i,o,n);c!==null&&(r=Math.min(r,c))}return Number.isFinite(r)?4+r:Number.POSITIVE_INFINITY}function W(t){return p(t).slice(2).replace(/-/g,"")}function N(t){return y(t)}function j(t){const s=C(t)?.canonical??L[t]??t,e=s.split(" ")[0]?.trim().toLowerCase();if(!e)return null;const o=Ie[e];return o?{packageAlias:o,canonicalPath:s,installCommand:`pm package install ${o} --project`}:null}function V(t){let s=ge(t);for(const e of["@unbrained/","builtin-","pm-"])s.startsWith(e)&&(s=s.slice(e.length));return s}function B(t,s){const e=V(t);if(e.length===0)return[];const o=[];for(const a of s.values()){const n=new Set,r=a.source;if(r)for(const c of[r.name,r.package]){const d=V(c??"");d.length>0&&n.add(d)}if(n.size===0)continue;[...n].some(c=>c===e||c.includes(e)||e.includes(c))&&o.push(a.command)}return[...new Set(o)].sort((a,n)=>a.localeCompare(n))}function x(t,s){const e=new Set,o=s??re(t);for(const a of o){a.flag.startsWith("--")&&e.add(p(a.flag));for(const n of a.aliases??[])n.startsWith("--")&&e.add(p(n))}return[...e].sort((a,n)=>a.localeCompare(n))}function q(t,s){if(!t.startsWith("--"))return[];const e=W(t);if(e.length===0)return[];const o=e.length>=8?2:1,a=[];for(const n of s){const r=W(n);if(r===e)continue;if(e.length>=3&&r.startsWith(e)){a.push({flag:n,rank:0,distance:r.length-e.length});continue}const i=E(e,r,o);i===null||i<=0||a.push({flag:n,rank:1,distance:i})}return a.sort((n,r)=>n.rank!==r.rank?n.rank-r.rank:n.distance!==r.distance?n.distance-r.distance:n.flag.localeCompare(r.flag)).map(n=>n.flag).slice(0,3)}let T;const ve=new Set(["ctx","packages","list-draft","list-open","list-in-progress","list-blocked","list-closed","list-canceled","start-task","pause-task","close-task","help"]);function Oe(){if(T)return T;const t=new Map;for(const s of R)if(!ve.has(s))for(const e of x(s)){const o=t.get(e)??[];o.push(s),t.set(e,o)}return T=t,T}function be(t,s){if(!t.startsWith("--"))return[];const e=Oe().get(p(t));if(!e)return[];const o=s?.trim().toLowerCase(),a=new Set(x(o));return[...new Set(e.filter(n=>n!==o).map(n=>({command:n,sharedFlagCount:x(n).filter(r=>a.has(r)).length})).sort((n,r)=>n.sharedFlagCount!==r.sharedFlagCount?r.sharedFlagCount-n.sharedFlagCount:n.command.localeCompare(r.command)).map(({command:n})=>C(n)?.canonical??n))]}function Pe(t,s,e){for(let o=0;o<t.length;o+=1){const a=t[o];if(!a.startsWith("--"))continue;const n=a.indexOf("="),r=n>=0?a.slice(0,n):a;if(p(r)!==p(s))continue;const i=[...t];return i[o]=n>=0?`${e}${a.slice(n)}`:e,i}}function Ne(t){const s=new Set(t.commandPaths),e=n=>Math.min(M(n,t.normalizedUnknown),t.primaryToken!==t.normalizedUnknown?M(n,t.primaryToken):Number.POSITIVE_INFINITY),o=new Map,a=(n,r)=>{if(!Number.isFinite(r)||!s.has(n))return;const i=o.get(n);(i===void 0||r<i)&&o.set(n,r)};for(const n of t.commandPaths)a(n,e(n));for(const[n,r]of Object.entries(L))n!=="read"&&a(r,e(n));return[...o.entries()].sort(([n,r],[i,c])=>r!==c?r-c:n.localeCompare(i)).map(([n])=>n)}function Ee(t){const s=C(t.normalizedUnknown),e=he(t.commandPaths,t.primaryToken),o=Ne(t),a=B(t.primaryToken,t.extensionDescriptors).filter(n=>t.commandPaths.includes(n));return F([...s&&t.commandPaths.includes(s.canonical)?[s.canonical_argv.join(" ")]:[],...e,...o,...a],t.commandPaths,t.primaryToken).filter(n=>!t.normalizedUnknown.includes(" ")||n!==t.normalizedUnknown)}function Re(t,s,e){const[o,...a]=t.split(" ");if(e.includes(o)||C(o)!==void 0)return;const n=o.endsWith("s")?o.slice(0,-1):`${o}s`,r=C(n),i=r&&e.includes(r.canonical)?r.canonical:e.includes(n)?n:void 0;if(i===void 0)return;let c=i;const d=["package","packages","extension"].includes(i)?[fe(Fe(s))??""].filter(l=>l.length>0):Ue(s,a.length);for(const l of[...a,...d]){const m=`${c} ${l}`,f=C(m);if(!e.includes(m)&&!(f!==void 0&&!f.hidden&&e.includes(f.canonical)))break;c=m}return c}function Le(t,s,e,o){const a=Re(t,s,e),n=Ce(t,e)??a,r=o.length>0||a!==void 0,i=r?[]:F($e(e),e),c=[...new Set([...n?[n]:[],...o.length>0?o:i])].slice(0,3);return{misnestedPath:n,hasConcreteCandidates:r,suggestedPaths:c}}function Fe(t){const s=h([...t]);return s===void 0?[]:t.slice(s+1)}function Ue(t,s){const e=[];let o=h([...t]);for(;o!==void 0;){const a=h(t.slice(o+1));o=a===void 0?void 0:o+1+a,o!==void 0&&e.push(t[o])}return e.slice(s)}function $e(t){return[...new Set(t.map(e=>e.split(" ")[0]).filter(e=>e.length>0))].sort((e,o)=>e.localeCompare(o))}function Ae(t,s){const e=t.map(o=>`pm ${o} --help`);return s?[...new Set([...e,"pm --help --all"])]:[...new Set(["pm --help --all",...e])]}function ze(t,s,e){let o=h([...s]);const a=[];for(;o!==void 0;){if(a.push(s[o]),s[o]===t)return a.join(" ");if(!e.includes(a.join(" ")))return t;const n=h(s.slice(o+1));o=n===void 0?void 0:o+1+n}return t}function D(t,s){if(!t)return;const e=_([...s]);return[...xe(e),...t.split(" "),"--help"]}function Me(t,s,e,o=[]){const a=t.match(/unknown command '([^']+)'/i);if(!a||typeof a[1]!="string")return;const n=z(s,e),r=ze(a[1],o,n),i=v(r);if(i.length===0||n.length===0)return;const c=ye(i,n);if(c){const k=D("update",o),J=k.slice(0,-2);return{suggestedRetryCommand:y(k),suggestedRetryArgs:k,unknownCommandExamples:[y(k),...c.examples.map(Y=>y([...J,...Y]))],unknownCommandNextSteps:c.nextSteps}}const d=j(i);if(d&&!n.includes(d.canonicalPath.split(" ")[0]))return{unknownCommandExamples:[d.installCommand,`pm ${d.canonicalPath} --help`,"pm --help --all"],unknownCommandNextSteps:[`"${i}" is provided by the "${d.packageAlias}" package. Install it with: ${d.installCommand}. Command after installation: pm ${d.canonicalPath}.`],suggestedRetryCommand:d.installCommand};const l=i.split(" ")[0],m=Ee({commandPaths:n,normalizedUnknown:i,primaryToken:l,extensionDescriptors:e}),{misnestedPath:f,hasConcreteCandidates:S,suggestedPaths:I}=Le(i,o,n,m),g=D(f,o),u=Ae(I,S),w=S?`Did you mean: ${I.join(", ")}?`:null;return{...g?{suggestedRetryCommand:y(g),suggestedRetryArgs:g}:{},unknownCommandExamples:g?[y(g),...u.slice(1)]:u,unknownCommandNextSteps:[...w?[w]:[],'Run "pm --help --all" to list every command available in this runtime, including active extensions.',...w?["Use one of the suggested command paths above with --help to inspect valid flags and usage."]:[]]}}function We(t){return Array.from(new Set(t))}function je(t){let s="";for(const e of t){if(e===" "||e===" "||e===`
14
- `||e==="\r"||e==="\f"||e==="\v")break;s+=e}return s}function Ve(t){let s=t.length;for(;s>0;){const e=t[s-1];if(e!==","&&e!==":"&&e!==";")break;s-=1}return t.slice(0,s)}function Be(t,s){const e=s.trim().toLowerCase();return t.commands.find(o=>o.name().trim().toLowerCase()===e?!0:(typeof o.aliases=="function"?o.aliases():[]).some(n=>n.trim().toLowerCase()===e))}function gn(t,s){if(s.length===0)return!0;let e=t;for(const[o,a]of s.entries()){const n=Be(e,a);if(!n){const r=e.registeredArguments;return r.length>0&&(e.commands.length===0||r[0]?.required===!0)&&(r.at(-1)?.variadic===!0||s.length-o<=r.length)}e=n}return!0}async function qe(t,s,e,o){try{const a=ee(process.cwd(),t.path);if(!await K(Z(a)))return{allowedTypes:P};const n=await ne(a),r=t.noExtensions?void 0:te(),i=X(n,r);let c;if(/too many arguments/i.test(s)&&["comments","docs","files","learnings","notes","test"].includes(o??"")){const d=e.findIndex(m=>m===o),l=e[d+2];if(e[d+1]?.toLowerCase()==="add"&&l!==void 0&&!l.startsWith("-"))try{c=(await oe(a,l,n.id_prefix,n.item_format,i.type_to_folder))?.id}catch{}}return{allowedTypes:i.types.length>0?i.types.join("|"):P,pmRoot:a,settings:n,typeToFolder:i.type_to_folder,verifiedCollectionItemId:c}}catch{return{allowedTypes:P}}}function De(t,s){const e=t.match(/unknown option '([^']+)'/i),o=e&&s?We([...Te(s,e[1]),...q(e[1],x(s))]).filter(r=>we(e[1],r)):void 0,a=e?be(e[1],s):[],n=e!==null&&x(s).includes(p(e[1]));return{match:e,suggestions:o,otherCommands:a,scope:n?"declared_on_path":a.length>0?"declared_elsewhere":"declared_nowhere"}}function He(t,s,e){if(!s||!e||e.length===0)return;const o=Pe(t,s[1],e[0]);return o?N(o):void 0}function H(t,s){const e=t.match(/required option '([^']+)' not specified/i),o=e?.[1]?Ve(je(e[1].trim())):void 0;if(!o?.startsWith("--"))return;const a=O(s);if(a)return ke(s,a,[o])}function Ge(t,s){if(!/too many arguments/i.test(t))return;const e=h(s),o=$(s.slice(e));if(o?.alias!=="schema")return;const a=e+o.canonical_argv.length-1,n=s[a+1]?.trim().toLowerCase(),r=s[a+2]?.trim().toLowerCase();if(!n||!r)return;const i=`${n}-${r}`;if(!A.includes(i))return;const c=[...s.slice(0,a+1),i,...s.slice(a+3)];return{unknownSubcommandPath:"schema",unknownSubcommandToken:`${n} ${r}`,unknownSubcommandAllowedValues:[...A],suggestedRetryCommand:N(c)}}function Je(t,s,e,o){const a=h(s),n=$(s.slice(a))?.alias??O(s);if(!/unknown option /i.test(t)||n===void 0)return n;const r=C(n)?.canonical??n;return R.some(i=>i===n)||z(e,o).includes(r)?n:void 0}async function G(t,s,e,o={},a=process.argv.slice(2)){const r=(typeof t=="object"&&t!==null?t.message:void 0)??"Invalid command usage",i=me([...a]).argv,c=Se(i),d=_(i),l=Je(r,c,s,e),m=N(c),f=pe(c),S=await qe(d,r,c,l),I=S.allowedTypes,g=Me(r,s,e,c),u=De(r,l),w=Ge(r,c),k=w?.suggestedRetryCommand??He(c,u.match,u.suggestions)??H(r,c);return{message:r,commandName:l,allowedTypes:I,attemptedCommand:m,normalizedInvocationArgs:[...c],providedOptionFlags:f,unknownOptionSuggestions:u.suggestions,unknownOptionOtherCommands:u.otherCommands.length>0?u.otherCommands.slice(0,12):void 0,unknownOptionOtherCommandsTotal:u.otherCommands.length>0?u.otherCommands.length:void 0,unknownOptionOtherCommandsTruncated:u.otherCommands.length>12||void 0,unknownOptionScope:u.scope,suggestedRetryCommand:k,verifiedCollectionItemId:S.verifiedCollectionItemId,linkedResourceValueList:await Ye(r,l,s,c),...w,...g,...o}}async function Ye(t,s,e,o){if(!/too many arguments/i.test(t))return;const{resolveUsageValueListRecovery:a}=await import("./linked-resource-value-list.js");return a(s,e,o)}async function hn(t,s,e,o={},a=process.argv.slice(2)){const n=await G(t,s,e,o,a),{message:r,commandName:i,allowedTypes:c,...d}=n,l=_(n.normalizedInvocationArgs).lean,m=ie(r,i,c,d,{lean:l}),f=await se("help_format",{message:m,command:i,allowed_types:c});return f.handled&&typeof f.result=="string"?f.result:m}async function Cn(t,s,e,o=!1,a={},n=process.argv.slice(2)){const r=await G(t,s,e,a,n),i=ce(r.message,r.commandName,r.allowedTypes,Q.USAGE,r),c=o?de(i):i,d=_(r.normalizedInvocationArgs).tokenAccounting===!0;return JSON.stringify(d?U(c,l=>`${JSON.stringify(l,null,2)}
15
- `):c,null,2)}const wn={collectKnownLongFlags:x,collectInstalledPackageCommandPathHints:B,resolveOptionalPackageInstallHint:j,resolveSuggestedRetryForMissingOption:H,suggestNearestLongFlags:q};export{P as BUILTIN_TYPE_HELP_VALUES,wn as _testOnly,fn as appendCommanderExtensionFailures,Me as buildUnknownCommandGuidanceFromRuntime,z as collectRuntimeCommandPaths,Cn as formatCommanderUsageJson,hn as formatCommanderUsageMessage,gn as isKnownHelpCommandPath,Be as resolveChildCommandByToken,G as resolveCommanderUsageContext,pn as resolveUnknownCommanderToken,M as scoreCommandPathMatch};
13
+ ${a}`}function wn(n){return fe(n).commandPathTokens[0]??O(n)??"<command>"}function z(n,s){const e=new Set,t=[...n.commands];for(;t.length>0;){const a=t.shift();if(!a)continue;const o=v(me(a)),r=o.split(" ").some(i=>i.startsWith("_"));o.length>0&&!r&&e.add(o),t.push(...a.commands)}for(const a of s.keys()){const o=v(a),r=o.split(" ").some(i=>i.startsWith("_"));o.length>0&&!r&&e.add(o)}return[...e].sort((a,o)=>a.localeCompare(o))}function W(n,s){const e=n.trim().toLowerCase(),t=s.trim().toLowerCase();if(t.length===0)return Number.POSITIVE_INFINITY;const a=e.split(" ");if(e===t)return 0;if(a.includes(t))return 1;if(a.some(i=>i.startsWith(t)))return 2;if(e.includes(t))return 3;const o=t.length>=5?2:1;let r=Number.POSITIVE_INFINITY;for(const i of a){const c=E(i,t,o);c!==null&&(r=Math.min(r,c))}return Number.isFinite(r)?4+r:Number.POSITIVE_INFINITY}function j(n){return p(n).slice(2).replace(/-/g,"")}function N(n){return x(n)}function V(n){const s=w(n)?.canonical??L[n]??n,e=s.split(" ")[0]?.trim().toLowerCase();if(!e)return null;const t=Te[e];return t?{packageAlias:t,canonicalPath:s,installCommand:`pm package install ${t} --project`}:null}function B(n){let s=he(n);for(const e of["@unbrained/","builtin-","pm-"])s.startsWith(e)&&(s=s.slice(e.length));return s}function q(n,s){const e=B(n);if(e.length===0)return[];const t=[];for(const a of s.values()){const o=new Set,r=a.source;if(r)for(const c of[r.name,r.package]){const d=B(c??"");d.length>0&&o.add(d)}if(o.size===0)continue;[...o].some(c=>c===e||c.includes(e)||e.includes(c))&&t.push(a.command)}return[...new Set(t)].sort((a,o)=>a.localeCompare(o))}function g(n,s){const e=new Set,t=s??ie(n);for(const a of t){a.flag.startsWith("--")&&e.add(p(a.flag));for(const o of a.aliases??[])o.startsWith("--")&&e.add(p(o))}return[...e].sort((a,o)=>a.localeCompare(o))}function D(n,s){if(!n.startsWith("--"))return[];const e=j(n);if(e.length===0)return[];const t=e.length>=8?2:1,a=[];for(const o of s){const r=j(o);if(r===e)continue;if(e.length>=3&&r.startsWith(e)){a.push({flag:o,rank:0,distance:r.length-e.length});continue}const i=E(e,r,t);i===null||i<=0||a.push({flag:o,rank:1,distance:i})}return a.sort((o,r)=>o.rank!==r.rank?o.rank-r.rank:o.distance!==r.distance?o.distance-r.distance:o.flag.localeCompare(r.flag)).map(o=>o.flag).slice(0,3)}let T;const be=new Set(["ctx","packages","list-draft","list-open","list-in-progress","list-blocked","list-closed","list-canceled","start-task","pause-task","close-task","help"]);function Pe(){if(T)return T;const n=new Map;for(const e of F)if(!be.has(e))for(const t of g(e)){const a=n.get(t)??[];a.push(e),n.set(t,a)}const s=new Map;for(const e of R())for(const t of g(e))n.has(t)||s.set(t,[...s.get(t)??[],e]);for(const[e,t]of s)n.set(e,t);return T=n,T}function Ne(n,s){if(!n.startsWith("--"))return[];const e=Pe().get(p(n));if(!e)return[];const t=s?.trim().toLowerCase(),a=new Set(g(t)),o=e.filter(r=>r!==t).map(r=>({command:r,sharedFlagCount:g(r).filter(i=>a.has(i)).length})).sort((r,i)=>r.sharedFlagCount!==i.sharedFlagCount?i.sharedFlagCount-r.sharedFlagCount:r.command.localeCompare(i.command)).map(({command:r})=>r);return[...new Set([...Ee(n,t),...o].map(r=>w(r)?.canonical??r))]}function Ee(n,s){if(s===void 0)return[];const e=Ie(s).split(" ",1)[0].replace(/^packages$/u,"package"),t=p(n);return R().filter(a=>a.split(" ",1)[0]===e&&g(a).includes(t))}function Fe(n,s,e){for(let t=0;t<n.length;t+=1){const a=n[t];if(!a.startsWith("--"))continue;const o=a.indexOf("="),r=o>=0?a.slice(0,o):a;if(p(r)!==p(s))continue;const i=[...n];return i[t]=o>=0?`${e}${a.slice(o)}`:e,i}}function Re(n){const s=new Set(n.commandPaths),e=o=>Math.min(W(o,n.normalizedUnknown),n.primaryToken!==n.normalizedUnknown?W(o,n.primaryToken):Number.POSITIVE_INFINITY),t=new Map,a=(o,r)=>{if(!Number.isFinite(r)||!s.has(o))return;const i=t.get(o);(i===void 0||r<i)&&t.set(o,r)};for(const o of n.commandPaths)a(o,e(o));for(const[o,r]of Object.entries(L))o!=="read"&&a(r,e(o));return[...t.entries()].sort(([o,r],[i,c])=>r!==c?r-c:o.localeCompare(i)).map(([o])=>o)}function Le(n){const s=w(n.normalizedUnknown),e=Ce(n.commandPaths,n.primaryToken),t=Re(n),a=q(n.primaryToken,n.extensionDescriptors).filter(o=>n.commandPaths.includes(o));return U([...s&&n.commandPaths.includes(s.canonical)?[s.canonical_argv.join(" ")]:[],...e,...t,...a],n.commandPaths,n.primaryToken).filter(o=>!n.normalizedUnknown.includes(" ")||o!==n.normalizedUnknown)}function Ue(n,s,e){const[t,...a]=n.split(" ");if(e.includes(t)||w(t)!==void 0)return;const o=t.endsWith("s")?t.slice(0,-1):`${t}s`,r=w(o),i=r&&e.includes(r.canonical)?r.canonical:e.includes(o)?o:void 0;if(i===void 0)return;let c=i;const d=["package","packages","extension"].includes(i)?[pe(Ae(s))??""].filter(l=>l.length>0):Me(s,a.length);for(const l of[...a,...d]){const m=`${c} ${l}`,f=w(m);if(!e.includes(m)&&!(f!==void 0&&!f.hidden&&e.includes(f.canonical)))break;c=m}return c}function $e(n,s,e,t){const a=Ue(n,s,e),o=we(n,e)??a,r=t.length>0||a!==void 0,i=r?[]:U(ze(e),e),c=[...new Set([...o?[o]:[],...t.length>0?t:i])].slice(0,3);return{misnestedPath:o,hasConcreteCandidates:r,suggestedPaths:c}}function Ae(n){const s=C([...n]);return s===void 0?[]:n.slice(s+1)}function Me(n,s){const e=[];let t=C([...n]);for(;t!==void 0;){const a=C(n.slice(t+1));t=a===void 0?void 0:t+1+a,t!==void 0&&e.push(n[t])}return e.slice(s)}function ze(n){return[...new Set(n.map(e=>e.split(" ")[0]).filter(e=>e.length>0))].sort((e,t)=>e.localeCompare(t))}function We(n,s){const e=n.map(t=>`pm ${t} --help`);return s?[...new Set([...e,"pm --help --all"])]:[...new Set(["pm --help --all",...e])]}function je(n,s,e){let t=C([...s]);const a=[];for(;t!==void 0;){if(a.push(s[t]),s[t]===n)return a.join(" ");if(!e.includes(a.join(" ")))return n;const o=C(s.slice(t+1));t=o===void 0?void 0:t+1+o}return n}function H(n,s){if(!n)return;const e=_([...s]);return[...Se(e),...n.split(" "),"--help"]}function Ve(n,s,e,t=[]){const a=n.match(/unknown command '([^']+)'/i);if(!a||typeof a[1]!="string")return;const o=z(s,e),r=je(a[1],t,o),i=v(r);if(i.length===0||o.length===0)return;const c=xe(i,o);if(c){const y=H("update",t),Y=y.slice(0,-2);return{suggestedRetryCommand:x(y),suggestedRetryArgs:y,unknownCommandExamples:[x(y),...c.examples.map(K=>x([...Y,...K]))],unknownCommandNextSteps:c.nextSteps}}const d=V(i);if(d&&!o.includes(d.canonicalPath.split(" ")[0]))return{unknownCommandExamples:[d.installCommand,`pm ${d.canonicalPath} --help`,"pm --help --all"],unknownCommandNextSteps:[`"${i}" is provided by the "${d.packageAlias}" package. Install it with: ${d.installCommand}. Command after installation: pm ${d.canonicalPath}.`],suggestedRetryCommand:d.installCommand};const l=i.split(" ")[0],m=Le({commandPaths:o,normalizedUnknown:i,primaryToken:l,extensionDescriptors:e}),{misnestedPath:f,hasConcreteCandidates:S,suggestedPaths:I}=$e(i,t,o,m),h=H(f,t),u=We(I,S),k=S?`Did you mean: ${I.join(", ")}?`:null;return{...h?{suggestedRetryCommand:x(h),suggestedRetryArgs:h}:{},unknownCommandExamples:h?[x(h),...u.slice(1)]:u,unknownCommandNextSteps:[...k?[k]:[],'Run "pm --help --all" to list every command available in this runtime, including active extensions.',...k?["Use one of the suggested command paths above with --help to inspect valid flags and usage."]:[]]}}function Be(n){return Array.from(new Set(n))}function qe(n){let s="";for(const e of n){if(e===" "||e===" "||e===`
14
+ `||e==="\r"||e==="\f"||e==="\v")break;s+=e}return s}function De(n){let s=n.length;for(;s>0;){const e=n[s-1];if(e!==","&&e!==":"&&e!==";")break;s-=1}return n.slice(0,s)}function He(n,s){const e=s.trim().toLowerCase();return n.commands.find(t=>t.name().trim().toLowerCase()===e?!0:(typeof t.aliases=="function"?t.aliases():[]).some(o=>o.trim().toLowerCase()===e))}function kn(n,s){if(s.length===0)return!0;let e=n;for(const[t,a]of s.entries()){const o=He(e,a);if(!o){const r=e.registeredArguments;return r.length>0&&(e.commands.length===0||r[0]?.required===!0)&&(r.at(-1)?.variadic===!0||s.length-t<=r.length)}e=o}return!0}async function Ge(n,s,e,t){try{const a=ne(process.cwd(),n.path);if(!await X(ee(a)))return{allowedTypes:P};const o=await te(a),r=n.noExtensions?void 0:oe(),i=Q(o,r);let c;if(/too many arguments/i.test(s)&&["comments","docs","files","learnings","notes","test"].includes(t??"")){const d=e.findIndex(m=>m===t),l=e[d+2];if(e[d+1]?.toLowerCase()==="add"&&l!==void 0&&!l.startsWith("-"))try{c=(await se(a,l,o.id_prefix,o.item_format,i.type_to_folder))?.id}catch{}}return{allowedTypes:i.types.length>0?i.types.join("|"):P,pmRoot:a,settings:o,typeToFolder:i.type_to_folder,verifiedCollectionItemId:c}}catch{return{allowedTypes:P}}}function Je(n,s){const e=n.match(/unknown option '([^']+)'/i),t=e&&s?Be([...Oe(s,e[1]),...D(e[1],g(s))]).filter(r=>ke(e[1],r)):void 0,a=e?Ne(e[1],s):[],o=e!==null&&g(s).includes(p(e[1]));return{match:e,suggestions:t,otherCommands:a,scope:o?"declared_on_path":a.length>0?"declared_elsewhere":"declared_nowhere"}}function Ye(n,s,e){if(!s||!e||e.length===0)return;const t=Fe(n,s[1],e[0]);return t?N(t):void 0}function G(n,s){const e=n.match(/required option '([^']+)' not specified/i),t=e?.[1]?De(qe(e[1].trim())):void 0;if(!t?.startsWith("--"))return;const a=O(s);if(a)return ye(s,a,[t])}function Ke(n,s){if(!/too many arguments/i.test(n))return;const e=C(s),t=A(s.slice(e));if(t?.alias!=="schema")return;const a=e+t.canonical_argv.length-1,o=s[a+1]?.trim().toLowerCase(),r=s[a+2]?.trim().toLowerCase();if(!o||!r)return;const i=`${o}-${r}`;if(!M.includes(i))return;const c=[...s.slice(0,a+1),i,...s.slice(a+3)];return{unknownSubcommandPath:"schema",unknownSubcommandToken:`${o} ${r}`,unknownSubcommandAllowedValues:[...M],suggestedRetryCommand:N(c)}}function Xe(n,s,e,t){const a=C(s),o=A(s.slice(a))?.alias??O(s);if(!/unknown option /i.test(n)||o===void 0)return o;const r=w(o)?.canonical??o;return F.some(i=>i===o)||z(e,t).includes(r)?o:void 0}async function J(n,s,e,t={},a=process.argv.slice(2)){const r=(typeof n=="object"&&n!==null?n.message:void 0)??"Invalid command usage",i=ue([...a]).argv,c=_e(i),d=_(i),l=Xe(r,c,s,e),m=N(c),f=ge(c),S=await Ge(d,r,c,l),I=S.allowedTypes,h=Ve(r,s,e,c),u=Je(r,l),k=Ke(r,c),y=k?.suggestedRetryCommand??Ye(c,u.match,u.suggestions)??G(r,c);return{message:r,commandName:l,allowedTypes:I,attemptedCommand:m,normalizedInvocationArgs:[...c],providedOptionFlags:f,unknownOptionSuggestions:u.suggestions,unknownOptionOtherCommands:u.otherCommands.length>0?u.otherCommands.slice(0,12):void 0,unknownOptionOtherCommandsTotal:u.otherCommands.length>0?u.otherCommands.length:void 0,unknownOptionOtherCommandsTruncated:u.otherCommands.length>12||void 0,unknownOptionScope:u.scope,suggestedRetryCommand:y,verifiedCollectionItemId:S.verifiedCollectionItemId,linkedResourceValueList:await Qe(r,l,s,c),...k,...h,...t}}async function Qe(n,s,e,t){if(!/too many arguments/i.test(n))return;const{resolveUsageValueListRecovery:a}=await import("./linked-resource-value-list.js");return a(s,e,t)}async function yn(n,s,e,t={},a=process.argv.slice(2)){const o=await J(n,s,e,t,a),{message:r,commandName:i,allowedTypes:c,...d}=o,l=_(o.normalizedInvocationArgs).lean,m=ce(r,i,c,d,{lean:l}),f=await ae("help_format",{message:m,command:i,allowed_types:c});return f.handled&&typeof f.result=="string"?f.result:m}async function xn(n,s,e,t=!1,a={},o=process.argv.slice(2)){const r=await J(n,s,e,a,o),i=de(r.message,r.commandName,r.allowedTypes,Z.USAGE,r),c=t?le(i):i,d=_(r.normalizedInvocationArgs).tokenAccounting===!0;return JSON.stringify(d?$(c,l=>`${JSON.stringify(l,null,2)}
15
+ `):c,null,2)}const Sn={collectKnownLongFlags:g,collectInstalledPackageCommandPathHints:q,resolveOptionalPackageInstallHint:V,resolveSuggestedRetryForMissingOption:G,suggestNearestLongFlags:D};export{P as BUILTIN_TYPE_HELP_VALUES,Sn as _testOnly,Cn as appendCommanderExtensionFailures,Ve as buildUnknownCommandGuidanceFromRuntime,z as collectRuntimeCommandPaths,xn as formatCommanderUsageJson,yn as formatCommanderUsageMessage,kn as isKnownHelpCommandPath,He as resolveChildCommandByToken,J as resolveCommanderUsageContext,wn as resolveUnknownCommanderToken,W as scoreCommandPathMatch};
16
16
  //# sourceMappingURL=commander-usage.js.map
@@ -1,7 +1,7 @@
1
- import{describeReadCompletenessControls as fe,isReadProjectionRecoveryFlag as he,resolveReadCompletenessControls as _e,resolveReadOptionRetryArgs as ge,resolveLinkedResourcePositionalRecovery as ye}from"../sdk/agent/command-recovery.js";import{PM_CLI_ERROR_DETAILS_LIMITS as ve,isPmTokenBudgetRecovery as we,projectPmCliErrorContextDetailsSlot as be}from"../sdk/errors.js";import{resolveRecoveryCommandName as G}from"../sdk/agent/command-recovery.js";import{estimatePmOutputTokens as M,isGenericRefusalRequired as N,isGenericRefusalWhy as W,projectLeanRecoveryPayload as V,projectPmDiagnosticOutput as ke,projectPmDiagnosticText as $e,resolvePmDiagnosticOutputBudget as F,withoutGenericRefusalExamples as B}from"../sdk/cli-contracts/agent-output-contracts.js";import{renderPmCommand as f}from"./argv-utils.js";import{invocationCarriesUrlCredentials as Ce,quoteCommandArg as Ae,resolveCommandShellDialect as Re}from"../sdk/command-line.js";import{discoverNearbyPmRoot as Se}from"../sdk/tracker-root-discovery.js";import{stripGlobalBootstrapTokens as R}from"../sdk/cli-bootstrap.js";import{findPmNamespacedCommand as xe,resolvePmCommandAlias as H}from"../sdk/cli-contracts/command-aliases.js";import{redactGuidanceCredentials as T}from"./runtime/refusal-credential-redaction.js";function dn(e){const{title:t,...n}=e;W(n.why)&&delete n.why,N(n.required)&&delete n.required;const i=B(n.examples);i.length>0?n.examples=i:delete n.examples;const r=V(n.recovery);return r===void 0?delete n.recovery:n.recovery=r,n}const Ee=new Set(["unknown_command","unknown_option","missing_required_option","missing_required_argument","invalid_argument_value","invalid_command_usage","command_failed"]);function Ie(e){return!e.why||e.recovery?.recovery_mode==="compact"?!1:!Ee.has(e.code)}function Y(e){return`urn:pm-cli:error:${e}`}function u(e){return{...e,type:Y(e.code)}}const k={packageName:"@unbrained/pm-guide-shell",installCommand:"pm install guide-shell"},K={packageName:"@unbrained/pm-calendar",installCommand:"pm install calendar"},X={packageName:"@unbrained/pm-search-advanced",installCommand:"pm install search-advanced"},S={packageName:"@unbrained/pm-governance-audit",installCommand:"pm install audit"},Te={guide:k,shell:k,completion:k,"completion-statuses":k,"completion-tags":k,"completion-types":k,templates:{packageName:"@unbrained/pm-templates",installCommand:"pm install templates"},calendar:K,cal:K,reindex:X,"search-advanced":X,"test-runs":{packageName:"@unbrained/pm-linked-test-adapters",installCommand:"pm install linked-test-adapters"},"comments-audit":S,"dedupe-audit":S,"dedupe-merge":S,normalize:S};function J(e){const t=e.trim().split(/\s+/)[0]?.toLowerCase();if(t)return Te[t]}function x(e,t){return t.length===0?[]:[e,...t.map(n=>` - ${n}`)]}function Oe(e){if(!Array.isArray(e))return;const t=e.filter(n=>typeof n=="string").map(n=>n.trim()).filter(n=>n.length>0);return t.length>0?t:void 0}function qe(e){if(!Array.isArray(e))return;const t=e.map(n=>({source:typeof n?.source=="string"?n.source.trim():"",command:typeof n?.command=="string"?n.command.trim():"",reason:typeof n?.reason=="string"?n.reason.trim():""})).filter(n=>n.source.length>0&&n.command.length>0&&n.reason.length>0);return t.length>0?t:void 0}function O(e,t,n){typeof n=="string"&&n.trim().length>0&&(e[t]=n.trim())}function Z(e){return Array.isArray(e)&&e.length>0&&e.every(t=>typeof t=="string")?[...e]:void 0}function _(e,t,n){if(t==="normalized_args"||t==="suggested_retry_args"||t==="allowed_values"){const r=Z(n);r&&(e[t]=r);return}if(t==="parsed_positionals"){if(!Array.isArray(n))return;const r=n.map(o=>({role:typeof o?.role=="string"?o.role.trim():"",value:typeof o?.value=="string"?o.value.trim():""})).filter(o=>o.role.length>0&&o.value.length>0);r.length>0&&(e.parsed_positionals=r);return}const i=Oe(n);i&&(e[t]=i)}function Le(e,t){if(!we(t))return;const{requested_tokens:n,feasible_tokens:i,minimum_feasible_tokens:r,minimum_status:o,basis:a,reason:s}=t;e.token_budget={requested_tokens:n,feasible_tokens:i,minimum_feasible_tokens:r,minimum_status:o,basis:a,reason:s}}const Q=["retry_after_ms","waited_ms","owner_handoffs"];function De(e,t){for(const n of Q)typeof t[n]=="number"&&e.push(` ${n}: ${t[n]}`)}function Pe(e,t){for(const n of Q){const i=t[n];typeof i=="number"&&Number.isSafeInteger(i)&&i>=0&&(e[n]=i)}}function y(e){if(!e||typeof e!="object")return;const t={};Le(t,e.token_budget),e.recovery_mode==="compact"&&(t.recovery_mode="compact"),O(t,"attempted_command",e.attempted_command),_(t,"normalized_args",e.normalized_args),_(t,"parsed_positionals",e.parsed_positionals),_(t,"provided_fields",e.provided_fields),_(t,"missing",e.missing),_(t,"missing_required_fields",e.missing_required_fields),_(t,"suggested_flags",e.suggested_flags),_(t,"allowed_values",e.allowed_values),_(t,"candidate_commands",e.candidate_commands),typeof e.candidate_commands_total=="number"&&Number.isSafeInteger(e.candidate_commands_total)&&e.candidate_commands_total>=0&&(t.candidate_commands_total=e.candidate_commands_total),e.candidate_commands_truncated===!0&&(t.candidate_commands_truncated=!0),(e.option_scope==="declared_on_path"||e.option_scope==="declared_elsewhere"||e.option_scope==="declared_nowhere")&&(t.option_scope=e.option_scope),O(t,"suggested_retry",e.suggested_retry),_(t,"suggested_retry_args",e.suggested_retry_args),Pe(t,e);const n=qe(e.fallback_candidates);return n&&(t.fallback_candidates=n),O(t,"next_best_command",e.next_best_command),Object.keys(t).length>0?t:void 0}function q(e,t,n){n&&e.push(` ${t}: ${n}`)}function v(e,t,n,i){n&&n.length>0&&e.push(` ${t}: ${n.join(i)}`)}const L=8,ze=12,ee=Number.POSITIVE_INFINITY;function je(e,t,n){const i=t!==void 0&&n===ee&&t.length<=ze?t.length:Math.min(n,L),r=t?.slice(0,i).map(o=>/^[\p{L}\p{N}._:/@=-]+$/u.test(o)?o:JSON.stringify(o));v(e,"allowed_values",r,", "),t&&t.length>i&&e.push(` allowed_values_omitted: ${t.length-i} (complete domain via SDK error.context.recovery.allowed_values; JSON diagnostics may be budgeted)`)}function Ue(e,t){const n=y(e);if(!n)return[];const i=["Recovery bundle:"];if(n.token_budget){const r=n.token_budget;i.push(` requested_token_budget: ${r.requested_tokens}`,` feasible_token_budget: ${r.feasible_tokens??"unavailable"}`,` minimum_token_budget: ${r.minimum_feasible_tokens??"not established"}`)}if(q(i,"suggested_retry",n.suggested_retry),q(i,"attempted_command",n.attempted_command),v(i,"normalized_args",n.attempted_command?void 0:n.normalized_args," "),n.parsed_positionals&&n.parsed_positionals.length>0){i.push(" parsed_positionals:");for(const r of n.parsed_positionals)i.push(` - ${r.role}: ${r.value}`)}if(v(i,"provided_fields",n.provided_fields,", "),v(i,"missing",n.missing,", "),v(i,"missing_required_fields",n.missing_required_fields,", "),v(i,"suggested_flags",n.suggested_flags,", "),je(i,n.allowed_values,t),v(i,"candidate_commands",n.candidate_commands,", "),typeof n.candidate_commands_total=="number"&&i.push(` candidate_commands_total: ${String(n.candidate_commands_total)}`),n.candidate_commands_truncated===!0&&i.push(" candidate_commands_truncated: true"),n.option_scope!==void 0&&i.push(` option_scope: ${n.option_scope}`),De(i,n),q(i,"next_best_command",n.next_best_command),n.fallback_candidates&&n.fallback_candidates.length>0){i.push(" fallback_candidates:");for(const r of n.fallback_candidates)i.push(` - ${r.source}: ${r.command} (${r.reason})`)}return i}const te=120;function Ge(e){if(e.claimedBy===void 0)return;const t=e.claimedAt?` since ${e.claimedAt}`:"",n=Array.from(e.claimedBy);return`Held by: ${n.length>te?`${n.slice(0,te).join("")}...`:e.claimedBy} (${e.claimSource??"unknown"}${t})${We(e.claimActivity)}`}function Me(e){return e.history_unreadable===!0?"history unreadable":e.unproven_activity!==void 0?`idleness unproven: ${e.unproven_activity}`:e.last_activity_at===null?"no valid activity time":"idle time not measurable"}function Ne(e){return e.state!==void 0?e.state:e.history_unreadable===!0||e.unproven_activity!==void 0||!Number.isFinite(e.idle_hours)?"unknown":e.stale_policy.stale?"stale":"active"}function We(e){if(e===void 0)return"";const t=`${e.stale_policy.setting}=${e.stale_policy.threshold_hours}`,n=Ne(e);if(n==="unknown"){const i=Number.isFinite(e.idle_hours)?`, last recorded activity ${e.idle_hours}h ago`:"";return`; activity unknown under ${t} (${Me(e)}${i})`}return`; idle ${e.idle_hours}h, ${n} under ${t}`}function Ve(e,t){const n=[`Error: ${e.title}`];e.code==="close_validation_missing_fields"&&e.recovery?.suggested_retry&&n.push(`Run: ${e.recovery.suggested_retry}`,"Template: replace every placeholder with real evidence before running."),(!t||!N(e.required))&&n.push("","What is required:",` ${e.required}`),e.nextSteps&&e.nextSteps.length>0&&(n.push(""),n.push(...x("Next steps:",e.nextSteps))),e.happened!==e.title&&n.push("","What happened:",` ${e.happened}`);const i=Ge(e);return i!==void 0&&n.push("",i),n}function Fe(e,t){const n=[];e.why&&!(t&&W(e.why))&&n.push("","Why:",` ${e.why}`);const i=t?B(e.examples):e.examples??[];i.length>0&&n.push("",...x("Examples:",i));const r=e.verificationErrors??[];return r.length>0&&n.push("",...x("Verification errors:",r)),n.push(...Be(e)),n}function Be(e){if(e.details!==void 0&&Object.keys(e.details).length>0)return["","Details:",...JSON.stringify(e.details,null,2).split(`
2
- `).map(r=>` ${r}`)];const t=e.detailsOmitted;if(t===void 0)return[];const n=t.path===void 0?` (over ${t.byte_limit} bytes)`:` at ${t.path}`;return["",`Details omitted: ${t.reason}${n}`]}function He(e,t={}){return ne(e,t,ee)}function ne(e,t,n){const i=t.lean===!0,r=[...Ve(e,i),...Fe(e,i||e.code==="close_validation_missing_fields")],o=e.code==="close_validation_missing_fields"&&e.recovery?{...e.recovery,suggested_retry:void 0}:e.recovery,a=Ue(i?V(o):o,n);return a.length>0&&(r.push(""),r.push(...a)),r.join(`
3
- `)}const Ye="Some guidance was omitted to fit the diagnostic token ceiling; rerun with --json for structured recovery within its own budget.",Ke=400,ie=320;function Xe(e){const t=y(e);if(!t)return;const n={};t.suggested_retry&&Buffer.byteLength(t.suggested_retry,"utf8")<=Ke&&(n.suggested_retry=t.suggested_retry);for(const i of["missing","missing_required_fields"]){const r=t[i];r&&r.length>0&&(n[i]=r.slice(0,3))}return t.allowed_values&&(n.allowed_values=t.allowed_values),t.next_best_command&&(n.next_best_command=t.next_best_command),Object.keys(n).length>0?n:void 0}function re(e,t){if(e.code!=="close_validation_missing_fields"||!e.recovery?.suggested_retry||t.recovery?.suggested_retry)return t.nextSteps;const n=t.recovery?.next_best_command?["Run recovery.next_best_command with real evidence, then repeat the original close."]:[...t.nextSteps,"Retrieve the complete retry from SDK error.context.recovery.suggested_retry; replace placeholders with real evidence before executing it."];return b(n,e.partialLegalDomainNotice)}function Je(e,t={}){const n=He(e,t),i=F("error").default_max_estimated_tokens_by_format.text,r=g=>M(Buffer.byteLength(g,"utf8"))<=i;if(r(n))return n;const o={...e,why:void 0},a=b(e.nextSteps?.slice(0,1)??[],e.partialLegalDomainNotice),s={...o,details:void 0,examples:e.examples?.slice(0,1),nextSteps:a,verificationErrors:e.verificationErrors?.slice(0,3)},d={...s,recovery:Xe(e.recovery)};d.nextSteps=re(e,d);const c=Array.from(e.happened),l={...d,examples:void 0,happened:c.length>ie?`${c.slice(0,ie).join("")}...`:e.happened},m={code:e.code,type:e.type,title:e.title,happened:l.happened,required:e.required,nextSteps:b([],e.partialLegalDomainNotice)};m.nextSteps=re(e,m);for(const[g,C]of[[o,L],[s,L],[d,3],[l,3],...e.partialLegalDomainNotice?[[m,3],[{...m,happened:e.title},3],[{...m,required:"Correct the producer metadata before relying on a complete legal domain."},3]]:[]]){const A=`${ne(g,t,C)}
1
+ import{describeReadCompletenessControls as ge,isReadProjectionRecoveryFlag as ye,resolveReadCompletenessControls as ve,resolveReadOptionRetryArgs as we,resolveLinkedResourcePositionalRecovery as be}from"../sdk/agent/command-recovery.js";import{PM_CLI_ERROR_DETAILS_LIMITS as ke,isPmTokenBudgetRecovery as $e,projectPmCliErrorContextDetailsSlot as Ce}from"../sdk/errors.js";import{resolveRecoveryCommandName as M}from"../sdk/agent/command-recovery.js";import{estimatePmOutputTokens as G,isGenericRefusalRequired as N,isGenericRefusalWhy as F,projectLeanRecoveryPayload as W,projectPmDiagnosticOutput as Ae,projectPmDiagnosticText as Re,resolvePmDiagnosticOutputBudget as V,withoutGenericRefusalExamples as B}from"../sdk/cli-contracts/agent-output-contracts.js";import{renderPmCommand as h}from"./argv-utils.js";import{invocationCarriesUrlCredentials as Se,quoteCommandArg as xe,resolveCommandShellDialect as Ee}from"../sdk/command-line.js";import{discoverNearbyPmRoot as Ie}from"../sdk/tracker-root-discovery.js";import{stripGlobalBootstrapTokens as R}from"../sdk/cli-bootstrap.js";import{PM_NAMESPACED_COMMAND_ALIASES as Oe,findPmNamespacedCommand as Te,resolvePmCommandAlias as H,resolvePmCommandOperation as qe}from"../sdk/cli-contracts/command-aliases.js";import{redactGuidanceCredentials as O}from"./runtime/refusal-credential-redaction.js";import{resolveInvocationCommandPath as Le}from"./runtime/invocation-command-path.js";import{scanOptionTokens as Y}from"./runtime/projection-retry.js";import{resolveSubcommandFlagContractsForCommand as K}from"../sdk/cli-contracts/flag-contracts.js";import{enrichCliFlagInvocationContracts as De}from"../sdk/flag-invocation-contracts.js";function Ct(e){const{title:n,...t}=e;F(t.why)&&delete t.why,N(t.required)&&delete t.required;const i=B(t.examples);i.length>0?t.examples=i:delete t.examples;const r=W(t.recovery);return r===void 0?delete t.recovery:t.recovery=r,t}const Pe=new Set(["unknown_command","unknown_option","missing_required_option","missing_required_argument","invalid_argument_value","invalid_command_usage","command_failed"]);function je(e){return!e.why||e.recovery?.recovery_mode==="compact"?!1:!Pe.has(e.code)}function X(e){return`urn:pm-cli:error:${e}`}function m(e){return{...e,type:X(e.code)}}const k={packageName:"@unbrained/pm-guide-shell",installCommand:"pm install guide-shell"},Z={packageName:"@unbrained/pm-calendar",installCommand:"pm install calendar"},J={packageName:"@unbrained/pm-search-advanced",installCommand:"pm install search-advanced"},S={packageName:"@unbrained/pm-governance-audit",installCommand:"pm install audit"},ze={guide:k,shell:k,completion:k,"completion-statuses":k,"completion-tags":k,"completion-types":k,templates:{packageName:"@unbrained/pm-templates",installCommand:"pm install templates"},calendar:Z,cal:Z,reindex:J,"search-advanced":J,"test-runs":{packageName:"@unbrained/pm-linked-test-adapters",installCommand:"pm install linked-test-adapters"},"comments-audit":S,"dedupe-audit":S,"dedupe-merge":S,normalize:S};function Q(e){const n=e.trim().split(/\s+/)[0]?.toLowerCase();if(n)return ze[n]}function x(e,n){return n.length===0?[]:[e,...n.map(t=>` - ${t}`)]}function Ue(e){if(!Array.isArray(e))return;const n=e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(t=>t.length>0);return n.length>0?n:void 0}function Me(e){if(!Array.isArray(e))return;const n=e.map(t=>({source:typeof t?.source=="string"?t.source.trim():"",command:typeof t?.command=="string"?t.command.trim():"",reason:typeof t?.reason=="string"?t.reason.trim():""})).filter(t=>t.source.length>0&&t.command.length>0&&t.reason.length>0);return n.length>0?n:void 0}function T(e,n,t){typeof t=="string"&&t.trim().length>0&&(e[n]=t.trim())}function ee(e){return Array.isArray(e)&&e.length>0&&e.every(n=>typeof n=="string")?[...e]:void 0}function g(e,n,t){if(n==="normalized_args"||n==="suggested_retry_args"||n==="allowed_values"){const r=ee(t);r&&(e[n]=r);return}if(n==="parsed_positionals"){if(!Array.isArray(t))return;const r=t.map(o=>({role:typeof o?.role=="string"?o.role.trim():"",value:typeof o?.value=="string"?o.value.trim():""})).filter(o=>o.role.length>0&&o.value.length>0);r.length>0&&(e.parsed_positionals=r);return}const i=Ue(t);i&&(e[n]=i)}function Ge(e,n){if(!$e(n))return;const{requested_tokens:t,feasible_tokens:i,minimum_feasible_tokens:r,minimum_status:o,basis:a,reason:s}=n;e.token_budget={requested_tokens:t,feasible_tokens:i,minimum_feasible_tokens:r,minimum_status:o,basis:a,reason:s}}const ne=["retry_after_ms","waited_ms","owner_handoffs"];function Ne(e,n){for(const t of ne)typeof n[t]=="number"&&e.push(` ${t}: ${n[t]}`)}function Fe(e,n){for(const t of ne){const i=n[t];typeof i=="number"&&Number.isSafeInteger(i)&&i>=0&&(e[t]=i)}}function y(e){if(!e||typeof e!="object")return;const n={};Ge(n,e.token_budget),e.recovery_mode==="compact"&&(n.recovery_mode="compact"),T(n,"attempted_command",e.attempted_command),g(n,"normalized_args",e.normalized_args),g(n,"parsed_positionals",e.parsed_positionals),g(n,"provided_fields",e.provided_fields),g(n,"missing",e.missing),g(n,"missing_required_fields",e.missing_required_fields),g(n,"suggested_flags",e.suggested_flags),g(n,"allowed_values",e.allowed_values),g(n,"candidate_commands",e.candidate_commands),typeof e.candidate_commands_total=="number"&&Number.isSafeInteger(e.candidate_commands_total)&&e.candidate_commands_total>=0&&(n.candidate_commands_total=e.candidate_commands_total),e.candidate_commands_truncated===!0&&(n.candidate_commands_truncated=!0),(e.option_scope==="declared_on_path"||e.option_scope==="declared_elsewhere"||e.option_scope==="declared_nowhere")&&(n.option_scope=e.option_scope),T(n,"suggested_retry",e.suggested_retry),g(n,"suggested_retry_args",e.suggested_retry_args),Fe(n,e);const t=Me(e.fallback_candidates);return t&&(n.fallback_candidates=t),T(n,"next_best_command",e.next_best_command),Object.keys(n).length>0?n:void 0}function q(e,n,t){t&&e.push(` ${n}: ${t}`)}function v(e,n,t,i){t&&t.length>0&&e.push(` ${n}: ${t.join(i)}`)}const L=8,We=12,te=Number.POSITIVE_INFINITY;function Ve(e,n,t){const i=n!==void 0&&t===te&&n.length<=We?n.length:Math.min(t,L),r=n?.slice(0,i).map(o=>/^[\p{L}\p{N}._:/@=-]+$/u.test(o)?o:JSON.stringify(o));v(e,"allowed_values",r,", "),n&&n.length>i&&e.push(` allowed_values_omitted: ${n.length-i} (complete domain via SDK error.context.recovery.allowed_values; JSON diagnostics may be budgeted)`)}function Be(e,n){const t=y(e);if(!t)return[];const i=["Recovery bundle:"];if(t.token_budget){const r=t.token_budget;i.push(` requested_token_budget: ${r.requested_tokens}`,` feasible_token_budget: ${r.feasible_tokens??"unavailable"}`,` minimum_token_budget: ${r.minimum_feasible_tokens??"not established"}`)}if(q(i,"suggested_retry",t.suggested_retry),q(i,"attempted_command",t.attempted_command),v(i,"normalized_args",t.attempted_command?void 0:t.normalized_args," "),t.parsed_positionals&&t.parsed_positionals.length>0){i.push(" parsed_positionals:");for(const r of t.parsed_positionals)i.push(` - ${r.role}: ${r.value}`)}if(v(i,"provided_fields",t.provided_fields,", "),v(i,"missing",t.missing,", "),v(i,"missing_required_fields",t.missing_required_fields,", "),v(i,"suggested_flags",t.suggested_flags,", "),Ve(i,t.allowed_values,n),v(i,"candidate_commands",t.candidate_commands,", "),typeof t.candidate_commands_total=="number"&&i.push(` candidate_commands_total: ${String(t.candidate_commands_total)}`),t.candidate_commands_truncated===!0&&i.push(" candidate_commands_truncated: true"),t.option_scope!==void 0&&i.push(` option_scope: ${t.option_scope}`),Ne(i,t),q(i,"next_best_command",t.next_best_command),t.fallback_candidates&&t.fallback_candidates.length>0){i.push(" fallback_candidates:");for(const r of t.fallback_candidates)i.push(` - ${r.source}: ${r.command} (${r.reason})`)}return i}const ie=120;function He(e){if(e.claimedBy===void 0)return;const n=e.claimedAt?` since ${e.claimedAt}`:"",t=Array.from(e.claimedBy);return`Held by: ${t.length>ie?`${t.slice(0,ie).join("")}...`:e.claimedBy} (${e.claimSource??"unknown"}${n})${Xe(e.claimActivity)}`}function Ye(e){return e.history_unreadable===!0?"history unreadable":e.unproven_activity!==void 0?`idleness unproven: ${e.unproven_activity}`:e.last_activity_at===null?"no valid activity time":"idle time not measurable"}function Ke(e){return e.state!==void 0?e.state:e.history_unreadable===!0||e.unproven_activity!==void 0||!Number.isFinite(e.idle_hours)?"unknown":e.stale_policy.stale?"stale":"active"}function Xe(e){if(e===void 0)return"";const n=`${e.stale_policy.setting}=${e.stale_policy.threshold_hours}`,t=Ke(e);if(t==="unknown"){const i=Number.isFinite(e.idle_hours)?`, last recorded activity ${e.idle_hours}h ago`:"";return`; activity unknown under ${n} (${Ye(e)}${i})`}return`; idle ${e.idle_hours}h, ${t} under ${n}`}function Ze(e,n){const t=[`Error: ${e.title}`];e.code==="close_validation_missing_fields"&&e.recovery?.suggested_retry&&t.push(`Run: ${e.recovery.suggested_retry}`,"Template: replace every placeholder with real evidence before running."),(!n||!N(e.required))&&t.push("","What is required:",` ${e.required}`),e.nextSteps&&e.nextSteps.length>0&&(t.push(""),t.push(...x("Next steps:",e.nextSteps))),e.happened!==e.title&&t.push("","What happened:",` ${e.happened}`);const i=He(e);return i!==void 0&&t.push("",i),t}function Je(e,n){const t=[];e.why&&!(n&&F(e.why))&&t.push("","Why:",` ${e.why}`);const i=n?B(e.examples):e.examples??[];i.length>0&&t.push("",...x("Examples:",i));const r=e.verificationErrors??[];return r.length>0&&t.push("",...x("Verification errors:",r)),t.push(...Qe(e)),t}function Qe(e){if(e.details!==void 0&&Object.keys(e.details).length>0)return["","Details:",...JSON.stringify(e.details,null,2).split(`
2
+ `).map(r=>` ${r}`)];const n=e.detailsOmitted;if(n===void 0)return[];const t=n.path===void 0?` (over ${n.byte_limit} bytes)`:` at ${n.path}`;return["",`Details omitted: ${n.reason}${t}`]}function en(e,n={}){return re(e,n,te)}function re(e,n,t){const i=n.lean===!0,r=[...Ze(e,i),...Je(e,i||e.code==="close_validation_missing_fields")],o=e.code==="close_validation_missing_fields"&&e.recovery?{...e.recovery,suggested_retry:void 0}:e.recovery,a=Be(i?W(o):o,t);return a.length>0&&(r.push(""),r.push(...a)),r.join(`
3
+ `)}const nn="Some guidance was omitted to fit the diagnostic token ceiling; rerun with --json for structured recovery within its own budget.",tn=400,oe=320;function rn(e){const n=y(e);if(!n)return;const t={};n.suggested_retry&&Buffer.byteLength(n.suggested_retry,"utf8")<=tn&&(t.suggested_retry=n.suggested_retry);for(const i of["missing","missing_required_fields"]){const r=n[i];r&&r.length>0&&(t[i]=r.slice(0,3))}return n.allowed_values&&(t.allowed_values=n.allowed_values),n.next_best_command&&(t.next_best_command=n.next_best_command),Object.keys(t).length>0?t:void 0}function ae(e,n){if(e.code!=="close_validation_missing_fields"||!e.recovery?.suggested_retry||n.recovery?.suggested_retry)return n.nextSteps;const t=n.recovery?.next_best_command?["Run recovery.next_best_command with real evidence, then repeat the original close."]:[...n.nextSteps,"Retrieve the complete retry from SDK error.context.recovery.suggested_retry; replace placeholders with real evidence before executing it."];return b(t,e.partialLegalDomainNotice)}function on(e,n={}){const t=en(e,n),i=V("error").default_max_estimated_tokens_by_format.text,r=f=>G(Buffer.byteLength(f,"utf8"))<=i;if(r(t))return t;const o={...e,why:void 0},a=b(e.nextSteps?.slice(0,1)??[],e.partialLegalDomainNotice),s={...o,details:void 0,examples:e.examples?.slice(0,1),nextSteps:a,verificationErrors:e.verificationErrors?.slice(0,3)},d={...s,recovery:rn(e.recovery)};d.nextSteps=ae(e,d);const l=Array.from(e.happened),c={...d,examples:void 0,happened:l.length>oe?`${l.slice(0,oe).join("")}...`:e.happened},u={code:e.code,type:e.type,title:e.title,happened:c.happened,required:e.required,nextSteps:b([],e.partialLegalDomainNotice)};u.nextSteps=ae(e,u);for(const[f,C]of[[o,L],[s,L],[d,3],[c,3],...e.partialLegalDomainNotice?[[u,3],[{...u,happened:e.title},3],[{...u,required:"Correct the producer metadata before relying on a complete legal domain."},3]]:[]]){const A=`${re(f,n,C)}
4
4
 
5
- ${Ye}`;if(r(A))return A}return n}function Ze(e,t){t.tombstone!==void 0&&(e.tombstone=t.tombstone,e.item_id=t.itemId),t.lease!==void 0&&(e.lease=t.lease,e.current_owner=t.currentOwner??null,e.item_id=t.itemId),t.claimedBy!==void 0&&(e.claimed_by=t.claimedBy,e.claimed_at=t.claimedAt??null,e.claim_source=t.claimSource??"unknown",t.claimActivity!==void 0&&(e.claim_activity=t.claimActivity),e.item_id=t.itemId),t.currentRevision!==void 0&&(e.expected_revision=t.expectedRevision??null,e.current_revision=t.currentRevision,t.itemId!==void 0&&(e.item_id=t.itemId))}function oe(e,t){return t.sideEffects!==void 0&&(e.side_effects=t.sideEffects),t.previewStorage!==void 0&&(e.preview_storage=t.previewStorage),t.transactionOperation!==void 0&&(e.transaction_operation=t.transactionOperation),Ze(e,t),Ie(t)&&(e.why=t.why),t.examples&&t.examples.length>0&&(e.examples=t.examples),t.nextSteps&&t.nextSteps.length>0&&(e.next_steps=t.nextSteps),t.verificationErrors&&t.verificationErrors.length>0&&(e.verification_errors=t.verificationErrors),t.flag!==void 0&&(e.flag=t.flag),t.value!==void 0&&(e.value=t.value),t.unmatchedSelectors!==void 0&&(e.unmatched_selectors=t.unmatchedSelectors),t.availableDependencies!==void 0&&(e.available_dependencies=t.availableDependencies),t.recovery&&(e.recovery=t.recovery),e}function Qe(e,t){if(e.flag)return e.flag;const n=r=>{const o=r.split("=",1)[0];return R([o]).length>0&&!["--help","--no-changed-fields","--version"].includes(o)&&t.some(a=>a===o||a.startsWith(`${o}=`))};return[...`${e.title} ${e.happened}`.matchAll(/--[A-Za-z0-9][A-Za-z0-9_-]*/gu)].map(r=>r[0]).find(r=>n(r))}function et(e,t,n){if(e.value!==void 0)return e.value;if(e.flag===void 0&&n){const i=t.find(o=>o===n||o.startsWith(`${n}=`));if(i?.startsWith(`${n}=`))return i.slice(n.length+1);const r=t.indexOf(n);return t[r+1]}}function tt(e,t){if(e.policyViolations?.length)return{surface:`policy:${e.policyViolations.map(s=>s.policy_id).join(",")}`,policies:e.policyViolations,policy_violation_count:e.policyViolationCount,missing_fields:[...new Set(e.policyViolations.flatMap(s=>s.missing_fields))],exit_code:t};const n=R(e.recovery?.normalized_args??[]),i=xe(n),r=i?[i.alias,...n.slice(i.canonical_argv.length)]:n,o=Qe(e,r),a=et(e,r,o);return{surface:o??e.recovery?.missing?.[0]??G(r)??"command",...a!==void 0?{rejected_value:a}:{},...e.recovery?.allowed_values?.length?{legal_domain:e.recovery.allowed_values}:{},exit_code:t}}function ae(e,t){const n=oe({type:e.type,code:e.code,title:e.title,detail:e.happened,required:e.required,exit_code:t,refusal:tt(e,t),...e.changed===!1?{changed:!1}:{}},e);return e.details!==void 0&&(n.details=e.details),e.detailsOmitted!==void 0&&(n.details_omitted=e.detailsOmitted),n}function D(e,t){const n=T(e),i=n.recovery,o=!!i?.suggested_retry||!!i?.suggested_retry_args?.length||!!i?.allowed_values?.length||!!i?.candidate_commands?.length||!!n.nextSteps?.length?"recovery_bundle":"error";return ke(nt(ae(n,t),o),{diagnosticClass:o})}function nt(e,t){if(e.details===void 0)return e;const n=F(t).default_max_estimated_tokens_by_format.json;if(M(Buffer.byteLength(JSON.stringify(e,null,2),"utf8"))<=n)return e;const{details:i,...r}=e;return{...r,details_omitted:{reason:"diagnostic_budget",byte_limit:ve.max_bytes}}}function E(e){return oe({type:e.type,code:e.code,title:e.title,detail:e.happened,required:e.required,...e.changed===!1?{changed:!1}:{}},e)}function I(e){return e.replace(/\(outputHelp\)/g,"").trim()}function it(e){const t=e.toLowerCase();return t.includes("cannot find module")||t.includes("cannot find package")||t.includes("err_module_not_found")||t.includes("module_not_found")}function w(e){if(!Array.isArray(e))return;const t=e.map(n=>n.trim()).filter(n=>n.length>0);return t.length>0?t:void 0}function P(e){const t=new Set,n=[];for(const i of e)t.has(i)||(t.add(i),n.push(i));return n}function rt(e){return G(e?.normalized_args)}function ot(e){const t=e.match(/\bmust be one of:?\s+([A-Za-z0-9_.|,\- ]+)/i);return t?t[1].split(/[|,]/).map(n=>n.trim()).filter(n=>/^[A-Za-z0-9_.-]+$/.test(n)):[]}function at(e,t){const n=e?.normalized_args,i=e?.provided_fields,r=t[0];if(!(!Array.isArray(n)||!Array.isArray(i)||!r))for(const o of i){const a=n.findIndex(s=>s===o);if(a>=0&&a<n.length-1&&!n[a+1]?.startsWith("-")){const s=[...n];return s[a+1]=r,f(s)}}}function se(e){const t=e.split(/\r?\n/)[0].trim();if(t.length===0)return;const n=Array.from(t);return n.length<=120?t:`${n.slice(0,117).join("")}...`}function $(e,t){return typeof e=="string"&&e.trim().length>0?e.trim():t}function st(e,t){if(e.flag!==void 0)return e.flag;if(e.field===void 0)return;const n=e.field.startsWith("--")?e.field:`--${e.field.replaceAll(/([A-Z])([A-Z][a-z])/gu,"$1-$2").replaceAll(/([a-z0-9])([A-Z])/gu,"$1-$2").replaceAll("_","-").toLowerCase()}`;return t?.normalized_args?.some(i=>i===n||i.startsWith(`${n}=`))?n:void 0}function dt(e,t,n,i){if(t==="close_validation_missing_fields")return"Close is missing required evidence";const r=e.code==="command_failed"||e.code==="invalid_argument_value"&&t!==e.code;return(n.code&&r?se(i):void 0)??e.title}function ct(e){const t=be(e);return t===void 0?{}:"details"in t?{details:t.details}:{detailsOmitted:t.details_omitted}}const lt=400;function ut(e){const t=[];for(const n of e.slice(0,8)){const i=JSON.stringify(n);Buffer.byteLength([...t,i].join(", "),"utf8")<=lt&&t.push(i)}return t}function mt(e){const t=e?.allowed_values;if(t===void 0||Array.isArray(t)&&t.every(a=>typeof a=="string"))return;const n=Array.isArray(t)?t.filter(a=>typeof a=="string"):[],i=ut(n),r=i.join(", ")||"none shown",o=n.length>i.length?` (${n.length-i.length} additional valid choices omitted)`:"";return`Incomplete legal domain from malformed producer metadata. Usable choices shown: ${r}${o}. Correct the producer metadata before relying on a complete domain.`}function pt(e,t,n){const i=y(t),r=i&&e?y({...e,...i}):i??e;if(!n)return r;const{allowed_values:o,...a}=r??{};return Object.keys(a).length>0?a:void 0}function h(e,t,n){if(!n)return e;const i=I(t),r=$(n.code,e.code),o=$(n.type,Y(r)),a=w(n.examples)??e.examples,s=w(n.nextSteps)??e.nextSteps,d=mt(n.recovery),c=d?[...s?.slice(0,1)??[],d,...s?.slice(1)??[]]:s,l=w(n.verification_errors)??e.verificationErrors,m=pt(e.recovery,n.recovery,d!==void 0);return{...e,code:r,changed:n.changed,sideEffects:n.side_effects,type:o,title:dt(e,r,n,i),happened:i.length>0?i:e.happened,required:$(n.required,e.required),why:$(n.why,e.why),examples:a,nextSteps:c,urlCredentialsRejected:n.url_credentials_rejected??e.urlCredentialsRejected,partialLegalDomainNotice:d,verificationErrors:l,policyViolations:n.policy_violations,policyViolationCount:n.policy_violation_count,flag:st(n,m)??e.flag,value:n.value??e.value,unmatchedSelectors:n.unmatched_selectors,itemId:n.item_id,transactionOperation:n.transaction_operation,previewStorage:n.preview_storage,tombstone:n.tombstone,lease:n.lease,currentOwner:n.current_owner,claimedBy:n.claimed_by,claimedAt:n.claimed_at,claimSource:n.claim_source,claimActivity:n.claim_activity,expectedRevision:n.expected_revision,currentRevision:n.current_revision,availableDependencies:n.available_dependencies,recovery:m,...ct(n)}}function ft(e,t,n){const i=t.match(/^Tracker is not initialized at (.+)\. (?:Run pm init first|Tracker root does not exist\. Run pm init first)\.$/);if(!i)return null;const r=i[1],o=Se(process.cwd(),r);return h(u(o?{code:"tracker_not_initialized",title:"Tracker exists at a custom path",happened:`pm did not find initialized metadata at ${r}, but found a tracker at ${o}.`,required:"Select the existing tracker root explicitly.",why:"Implicit discovery checks the default .agents/pm layout and ancestor root-layout trackers, while custom nested roots require an explicit path.",examples:[`pm --pm-path ${o} <command>`,`PM_PATH=${o} pm <command>`],nextSteps:[`Re-run with "--pm-path ${o}" or export PM_PATH=${o}.`]}:{code:"tracker_not_initialized",title:"Tracker is not initialized",happened:`pm data path does not contain initialized tracker metadata (${i[1]}).`,required:"Select an existing tracker with --pm-path/PM_PATH, or initialize the default .agents/pm storage.",why:"Most commands require settings in an explicitly selected root, an ancestor root-layout tracker, or the default .agents/pm directory.",examples:["pm init","pm init acme"],nextSteps:['Run "pm init", then rerun your original command.']}),e,n)}function ht(e,t,n){const i=t.match(/^Item ([^ ]+) not found$/);if(!i)return null;const r=i[1],o=/^(undefined|null|<.*>|\[.*\]|{.*}|)$/.test(r),a=o?`The item ID "${r}" looks like a placeholder or unresolved variable. Ensure the ID argument is resolved before calling pm.`:`No item with id "${r}" exists in the active tracker scope.`;return h(u({code:"item_not_found",title:"Item ID not found",flag:"id",value:r,happened:a,required:"Use an existing item ID from current tracker data.",why:"Mutation and read commands operate only on known IDs.",examples:["pm list --status open --limit 20",'pm search "<keyword>" --limit 10'],nextSteps:o?["Check that the variable holding the item ID is defined before passing it to pm.",'Use "pm list --status open --limit 20" to find valid IDs.']:["Confirm the active --path/PM_PATH scope, then retry with a valid id."]}),e,n)}function _t(e,t,n){return!t.includes("is assigned to")||!t.includes("Use --force to override")?null:h(u({code:"ownership_conflict",title:"Ownership conflict",happened:t,required:"Run as the assigned owner, claim the item when appropriate, or use --force only for an approved override.",why:"Ownership checks prevent accidental concurrent mutations on claimed items and protect against conflicting writes.",examples:["pm claim pm-a1b2","pm update pm-a1b2 --status in_progress --force"],nextSteps:["Use --force for approved systematic metadata updates performed by leads or maintainers.","Use --force when correcting known stale metadata after coordinating ownership changes.",'For non-terminal reassignment, prefer "pm claim <ID>" before running other mutations.']}),e,n)}function gt(e,t,n){if(!t.includes("is locked"))return null;const i=Z(n?.recovery?.normalized_args),r=i?f(i):void 0,o=h(u({code:"lock_conflict",title:"Lock conflict",happened:t,required:"Wait for lock release, then retry the same operation. Set PM_LOCK_WAIT_MS to a larger bounded millisecond budget for expected contention.",why:"Locking protects item files from concurrent write races.",examples:r?[r]:["pm gc --scope locks --dry-run"]}),e,n);return i&&(o.recovery={...o.recovery,suggested_retry:r,suggested_retry_args:[...i]}),o}function yt(e,t,n){const i=t.match(/^Missing required option /),r=t.match(/^Missing required options /);if(!i&&!r)return null;const o=!!r,a=o?null:t.replace(/^Missing required option\s+/,"").trim(),s=a??"",d=a?`Pass ${a} with a valid value before running the command.`:"Provide the required option for this command invocation.";return h(u({code:"missing_required_option",title:o?"Missing required options":`Missing required option ${s}`,happened:t,required:o?"Provide every required option for this command invocation.":d,why:"Required options define command intent and enforce deterministic write contracts.",examples:['pm create --title "Task title" --description "Task details" --type Task --create-mode progressive','pm create --title "Task title" --description "Task details" --type Task --status open --priority 1 --message "Create task" --dep "id=pm-epic01,kind=parent,created_at=now" --comment "created_at=now,text=Why this task exists." --note "created_at=now,text=Initial implementation note." --learning "created_at=now,text=Durable lesson placeholder." --file "path=src/example.ts,scope=project" --test "command=node scripts/run-tests.mjs test,scope=project,timeout_seconds=240" --doc "path=README.md,scope=project"'],nextSteps:['Run "pm <command> --help" to view required and recommended flags.',"For staged triage without placeholder linkage values, use --create-mode progressive."]}),e,n)}function vt(e,t,n){return t.startsWith("No update flags provided")?h(u({code:"no_update_fields",title:"No update fields supplied",happened:"The update command was called without any field-changing flags.",required:"Provide at least one field-changing flag such as --status, --priority, --title, --tags, --description, or --body. Use --message only to label a real mutation.",why:"pm update mutates existing item fields; no-op invocations are rejected to avoid ambiguous history.",examples:['pm update pm-a1b2 --status in_progress --message "Start implementation"','pm update pm-a1b2 --description "Clarified implementation scope" --message "Clarify task intent"','pm append pm-a1b2 --body "Detailed progress notes" --message "Append progress notes"'],nextSteps:["Choose the item field you intend to change, then pair that change with --message for history context.","Use pm comments, pm notes, pm learnings, or pm append when you only need to add narrative context."]}),e,n):null}function wt(e,t){if(e.startsWith("Invalid "))return!0;if(!e.includes(" must be ")&&!e.includes(" requires "))return!1;const n=$(t?.code,void 0);return n===void 0||n==="invalid_argument_value"||t?.allowed!==void 0}function bt(e,t,n){if(!wt(t,n))return null;const i=y(n?.recovery),r=rt(i),o=r?`pm ${r} --help`:"pm <command> --help",a=n?.recovery?.allowed_values!==void 0?[]:n?.allowed??ot(t),s=y({...i,allowed_values:i?.allowed_values??a}),d=at(i,a),c=d?[d,o]:[o,"pm contracts --command <command> --flags-only --json"],l=a.length>0?[`Allowed values: ${a.join("|")}`,`Run "${o}" to confirm command-specific constraints.`]:["Check allowed values in command help, then rerun with corrected input."];return h(u({code:"invalid_argument_value",title:"Invalid argument value",happened:t,required:"Use values that match documented command constraints.",why:"Validation protects data consistency and deterministic behavior across commands.",examples:c,nextSteps:l,recovery:s}),e,n)}function z(e,t){const n=I(e),i=ft(e,n,t)??ht(e,n,t)??_t(e,n,t)??gt(e,n,t)??yt(e,n,t)??vt(e,n,t)??bt(e,n,t);return i||h(u({code:"command_failed",title:"Command failed",happened:n,required:"Adjust command input or tracker state and retry.",why:"pm enforces explicit, deterministic contracts for data and command semantics.",examples:["pm --help","pm <command> --help"]}),e,t)}function de(e,t,n){return e==="create"&&t.startsWith("--type")?[`pm create --title "Example title" --description "Example description" --type ${n.split("|")[0]||"Task"} --status open --priority 1 --message "Create item" --create-mode progressive`]:e==="update"?['pm update pm-a1b2 --status in_progress --message "Start implementation"']:[`pm ${e??"<command>"} --help`]}function kt(e){const t=e.trim();return t.match(/--[A-Za-z0-9][A-Za-z0-9_-]*/)?.[0]??t}function $t(e){if(!(!Array.isArray(e)||e.length===0))return f(e)}function j(e){if(!Array.isArray(e))return;const t=e.map(n=>n.trim()).filter(n=>n.length>0);return t.length>0?t:void 0}function p(e,t={}){const n=j(e?.providedOptionFlags),i=Array.isArray(e?.normalizedInvocationArgs)&&e?.normalizedInvocationArgs.length>0?e.normalizedInvocationArgs:void 0,r=typeof e?.attemptedCommand=="string"?e.attemptedCommand:$t(i),o=typeof e?.suggestedRetryCommand=="string"?e.suggestedRetryCommand:void 0;return y({attempted_command:r,normalized_args:i,provided_fields:n,suggested_retry:o,suggested_retry_args:e?.suggestedRetryArgs,...t})}function b(e,t){return!t||e.includes(t)?e:[...e,t]}const Ct=new Set(["--add","--add-json","--remove"]),At=new Set(["command","cmd","path"]);function Rt(e){if(Array.isArray(e))for(const t of e){if(!t.startsWith("--"))continue;const n=t.indexOf("="),i=n>=0?t.slice(0,n):t;if(Ct.has(i))return i}}function St(e){if(!Array.isArray(e))return;const t=e.indexOf("test");if(t<0)return;const n=e[t+1];if(!(typeof n!="string"||n.startsWith("-")))for(let i=t+2;i<e.length;i+=1){const r=e[i];if(r!=="--add"&&r!=="--remove")continue;const o=e[i+1];if(typeof o!="string"||!At.has(o))return;const a=[];for(let c=i+2;c<e.length;c+=1){const l=e[c];if(l.startsWith("--")&&l.length>2)break;a.push(l)}if(a.length<2)return;const s=`${o}=${a.join(" ")}`,d=[...e.slice(0,i+1),s,...e.slice(i+2+a.length)];return f(d)}}function xt(e,t,n,i){const r=e.match(/required option '([^']+)' not specified/);if(!r)return null;const o=kt(r[1]),a=o.startsWith("--type"),s=i?.suggestedRetryCommand,d=j(i?.providedOptionFlags),c=[o],l=de(t,o,n),m=s?b(l,s):l,g=a?[`Allowed type values: ${n}`,`Run "pm ${t??"create"} --help --type <value>" for type-aware policy details.`]:[`Run "pm ${t??"<command>"} --help" for required option guidance.`],C=s?b(g,`Replay with preserved arguments: ${s}`):g,A=d&&d.length>0?b(C,`Already provided options: ${d.join(", ")}`):C;return u({code:"missing_required_option",title:`Missing required option ${o}`,happened:`Commander rejected the command because ${o} was not provided.`,required:`Pass ${o} with a valid value before running the command.`,why:a?"--type selects item contract and policy routing, including required/disabled option rules.":"Required flags define mandatory command intent and prevent ambiguous execution.",examples:m,nextSteps:A,recovery:p(i,{missing:c})})}function Et(e,t,n){const i=e.match(/missing required argument '([^']+)'/);if(!i)return null;const r=i[1];return u({code:"missing_required_argument",title:`Missing required argument ${r}`,happened:`Command invocation omitted positional argument ${r}.`,required:`Provide ${r} in the expected command position.`,why:"Positional arguments identify the target entity or action context for the command.",examples:[`pm ${t??"<command>"} --help`],recovery:p(n,{missing:[r]})})}function It(e,t,n){return u({code:"unsupported_update_option",title:`Unsupported option ${e} for update`,happened:`pm update does not accept ${e} for linked artifact mutations.`,required:"Use dedicated linked-artifact commands instead of pm update for files/docs changes.",why:"pm update manages scalar item metadata, while linked files/docs are managed by pm files and pm docs.",examples:['pm files pm-a1b2 --add "path=src/cli/main.ts,scope=project,note=implementation surface"','pm docs pm-a1b2 --add "path=README.md,scope=project,note=user-facing contract"'],nextSteps:['Run "pm files --help" and "pm docs --help" for add/remove payload formats.'],recovery:p(t,{suggested_flags:n})})}const Tt={declared_elsewhere:"Use an option declared on this path, or move the declared option to one of its accepting command paths.",declared_on_path:"Use the option with the value and syntax declared by this command path.",declared_nowhere:"Use a declared option on this command path; this spelling exists nowhere in the command lexicon."};function Ot(e){const t=w(e.unknownOptionOtherCommands)??[];return{otherCommands:t,optionScope:e.unknownOptionScope??(t.length>0?"declared_elsewhere":"declared_nowhere"),candidateTotal:e.unknownOptionOtherCommandsTotal??t.length}}function qt(e,t,n,i,r){const o=i.otherCommands.slice(0,3),a=i.candidateTotal-o.length,s=a>0?` and ${String(a)} more command path(s)`:"";return["Run command help to confirm the exact option contracts for this command path.",n.length?`Nearest supported options: ${n.join(", ")}`:void 0,r?void 0:Lt(e,t),o.length?`${e} is accepted by ${o.join(", ")}${s}. Inspect those command contracts only if you intended a different operation.`:void 0,le(e)?`"${e}" contains spaces, so it is a value that starts with --, not an option. Pass it after a -- separator at the end of the command, or through the command's named value flag.`:i.optionScope==="declared_nowhere"?`${e} is not declared on any command path. Use a nearest supported option on ${t??"the attempted command"}, or inspect that command's help.`:void 0,r?`Replay with suggested correction: ${r}`:void 0].filter(d=>typeof d=="string")}const ce=["--brief","--compact","--standard","--deep","--full","--summary","--depth"];function Lt(e,t){if(t===void 0||!ce.includes(e.split("=",1)[0]))return;const n=_e(t);return n===void 0?void 0:`Completeness controls accepted by pm ${n.command}: ${fe(n)}.`}function Dt(e,t,n){const i=ge(n??"",e.normalizedInvocationArgs??[],t);return i?{retryCommand:f(i),suggestedRetryArgs:i}:[...ce,"--toon",...n==="activity"?["--since"]:[]].includes(t.split("=",1)[0])?{}:void 0}function le(e){return/\s/u.test(e)}function Pt(e,t){const n=e?.indexOf(t)??-1;if(e===void 0||n<0||e.includes("--")||e.lastIndexOf(t)!==n)return{};if(e.slice(n+1).some(r=>!r.startsWith("-")))return{};const i=[...R(e.filter((r,o)=>o!==n)),"--",t];return{retryCommand:f(i),suggestedRetryArgs:i}}function zt(e,t,n){if(le(t))return Pt(e.normalizedInvocationArgs,t);if(["--dry-run","--check","--check-only","--plan","--preview"].includes(t.split("=",1)[0]))return{};const i=Dt(e,t,n);if(i)return i;if(e.suggestedRetryCommand!==void 0)return{retryCommand:e.suggestedRetryCommand};if(he(t))return{};const r=e.normalizedInvocationArgs;if(r===void 0)return{};if(r.filter(s=>s===t||s.startsWith(`${t}=`)).length!==1)return{};const o=r.findIndex(s=>s===t||s.startsWith(`${t}=`));if(o<0||r.includes("--")||!r[o]?.includes("=")&&o!==r.length-1&&r[o+1]?.startsWith("-")!==!0)return{};const a=R(r.filter((s,d)=>d!==o));return{retryCommand:f(a),suggestedRetryArgs:a}}function jt(e,t,n){const i=e.match(/unknown option '([^']+)'/);if(!i)return null;const r=n??{},o=i[1],a=j(r.unknownOptionSuggestions)??[],{retryCommand:s,suggestedRetryArgs:d}=zt(r,o,t);if(t==="update"&&(o==="--file"||o==="--doc"))return It(o,n,a);const c=Ot(r),l=qt(o,t,a,c,s);["--dry-run","--check","--check-only","--plan","--preview"].includes(o.split("=",1)[0])&&l.push("The requested preview is unavailable on this path. Inspect the item with a read-only command or use a command that declares this option; do not replay this mutation without preview intent.");const m=[s,t?`pm ${H(t)?.canonical??t} --help`:"pm --help --all"].filter(g=>typeof g=="string");return u({code:"unknown_option",title:`Unknown option ${o}`,happened:`Commander does not recognize option ${o} for this command path.`,required:Tt[c.optionScope],why:"Option contracts are command-specific and intentionally validated.",flag:o,value:o,examples:m,nextSteps:l,recovery:p(n,{suggested_flags:a.length>0?a:void 0,suggested_retry:s,suggested_retry_args:d,candidate_commands:c.otherCommands,candidate_commands_total:c.candidateTotal||void 0,candidate_commands_truncated:r.unknownOptionOtherCommandsTruncated,option_scope:c.optionScope})})}function Ut(e,t,n,i,r){const o=`"${e}" is provided by the ${t.packageName} package. Install it with: ${t.installCommand}`,a=i.filter(s=>!s.endsWith(`: ${t.installCommand}`));return u({code:"unknown_command",title:`Unknown command ${e}`,happened:`pm does not expose command path "${e}" in current runtime configuration. It is shipped by the optional ${t.packageName} package.`,required:`Install the ${t.packageName} package, or use a valid command name or subcommand path.`,why:"Command registry includes core commands plus active extension command handlers; package-provided commands appear only after the package is installed.",examples:P([t.installCommand,...n]),nextSteps:P([o,...a]),recovery:p(r)})}function Gt(e,t){const n=e.match(/unknown command '([^']+)'/);if(!n)return null;const i=n[1],r=w(t?.unknownCommandExamples),o=w(t?.unknownCommandNextSteps),a=J(i),s=r??["pm --help"],d=o??["Verify spelling and active extensions, then rerun."],c=new Set(t?.failedExtensions?.map(m=>m.name.trim().toLowerCase())),l=a?.packageName.replace(/^@unbrained\/pm-/,"").toLowerCase();return a&&(!l||!c.has(l))?Ut(i,a,s,d,t):u({code:"unknown_command",title:`Unknown command ${i}`,happened:`pm does not expose command path "${i}" in current runtime configuration.`,required:"Use a valid command name or subcommand path.",why:"Command registry includes core commands plus active extension command handlers.",examples:s,nextSteps:d,recovery:p(t)})}function Mt(e){const t=e?.unknownSubcommandPath?.trim(),n=e?.unknownSubcommandToken?.trim(),i=w(e?.unknownSubcommandAllowedValues);if(!t||!n||!i)return null;const r=e?.suggestedRetryCommand;return u({code:"unknown_subcommand",title:`Unknown ${t} subcommand ${n}`,value:n,happened:`The positional token sequence "${n}" is not a declared ${t} subcommand.`,required:`Use one of: ${i.join(", ")}.`,why:"Subcommands are single positional tokens; multi-word action names use hyphens.",examples:[...r?[r]:[],`pm ${H(t)?.canonical??t} --help`],nextSteps:r?[`Retry with the declared hyphenated action: ${r}`]:["Choose one value from recovery.allowed_values."],recovery:p(e,{allowed_values:i,suggested_retry:r})})}function Nt(e,t,n){if(!/too many arguments/i.test(e)||t!=="test")return null;const i=n?.normalizedInvocationArgs,r=Rt(i);if(!r)return null;const o=St(i);return u({code:"linked_test_value_not_quoted",title:`Linked-test ${r} value must be one argument`,happened:`Commander saw extra positional tokens after the item id \u2014 usually a ${r} value containing spaces (for example a command with " -- ") that the shell split into multiple tokens.`,required:`Quote the whole ${r} value as a single argument. Accepted forms: --add "command=npm test -- parser", --add command "npm test -- parser" (two-token form with the value quoted), or --add-json for complex commands.`,why:"The shell splits unquoted values before pm can see them, so pm cannot reassemble the intended command unambiguously.",examples:[...o?[o]:[],'pm test pm-a1b2 --add "command=npm test -- parser"','pm test pm-a1b2 --add command "npm test -- parser"',`pm test pm-a1b2 --add-json '{"command":"npm test -- parser"}'`],nextSteps:[...o?[`Replay with the value re-joined into one argument: ${o}`]:[],"Prefer --add-json for commands containing commas, equals signs, or quotes.",'Run "pm test --help" for linked-test entry contracts.'],recovery:p(n,o?{suggested_retry:o}:{})})}const Wt=new Set(["comments","docs","files","learnings","notes","test"]);function Vt(e,t,n){if(!/too many arguments/i.test(e))return null;const i=ye(t,n?.normalizedInvocationArgs??[]);if(!i)return null;const r=i.retryArgs?f(i.retryArgs):void 0,o=f(i.templateArgs??["test",i.itemId,"--add",`command=<actual command>,${i.value}`]);return u({code:"linked_resource_positional_value",title:"Linked-resource values require an explicit --add option",happened:`The value after the item id is not a positional argument of ${t}.`,required:r?`Retry the explicit collection mutation: ${r}`:`Supply the actual command and its metadata together, for example ${o}.`,examples:[r??o],recovery:p(n,{suggested_retry:r,suggested_retry_args:i.retryArgs})})}function Ft(e){return[...e].some(t=>t.charCodeAt(0)<32||t.charCodeAt(0)===127)}function Bt(e){const t=Ce()?void 0:e.retryArgs,n=process.platform==="win32"||Re(process.platform)==="cmd",i=t?.some(r=>Ft(r)||n&&Ae(r,process.platform,"cmd")!==r)===!0;return{retryArgs:t,argvOnly:i,retry:t&&!i?f(t):void 0}}function Ht(e,t,n){const i=n?.linkedResourceValueList;if(!/too many arguments/i.test(e)||i===void 0)return null;const r=i.flags[0],o=i.flags.join(", "),{retryArgs:a,argvOnly:s,retry:d}=Bt(i),c=t!=="test"&&i.flags.includes("--add"),l=`pm ${t} ${i.itemId} ${r} <value> ${r} <value>`,m=i.extraValues.length;return u({code:"linked_resource_value_list",title:`Repeat ${r} once per value${c?" (or use --add-glob)":""}`,happened:`${m} more value${m===1?"":"s"} followed the value of ${o}. pm ${t} takes one value per occurrence, so they were read as extra positional arguments and nothing was changed.`,required:d?`Retry with one ${r} per value: ${d}`:s?`Retry with one ${r} per value by replaying recovery.suggested_retry_args (shown with --json): a value holds a control character, or needs cmd.exe quoting that a copied command cannot carry exactly.`:i.readsStdin?`Write one ${r} per value and pipe the same input again, because the command reads stdin: ${l}`:`Write one ${r} per value, and quote a value that contains spaces or commas so the shell passes it as one argument: ${l}`,why:`Each occurrence of a repeatable flag takes exactly one value, so an item id written after the flag (pm ${t} ${r} <value> <id>) stays unambiguous.`,examples:[d??l,...c?[`pm ${t} ${i.itemId} --add-glob "<pattern>"`]:[],`pm ${t} --help`],recovery:p(n,{suggested_retry:d,suggested_retry_args:a})})}function Yt(e,t,n){if(!/too many arguments/i.test(e)||!Wt.has(t??""))return null;const i=n?.normalizedInvocationArgs??[],r=i.findIndex(c=>c===t),o=i[r+1],a=i[r+2],s=n?.verifiedCollectionItemId?.trim();if(o?.toLowerCase()!=="add"||!a||a.startsWith("-")||!s||s.toLowerCase()!==a.toLowerCase())return null;const d=`pm ${t} ${s} --add <value>`;return u({code:"collection_transposed_subcommand",title:`Transposed ${t} add syntax`,happened:`The positional token "add" occupied the item-id role and "${s}" occupied the next positional role. pm ${t} does not use an add subcommand.`,required:`Place the item id immediately after ${t}, then use --add for the value.`,why:"Collection mutations use object-first grammar: pm <collection> <item-id> --add <value>.",examples:[d,`pm ${t} --help`],recovery:p(n,{parsed_positionals:[{role:"transposed_subcommand",value:o},{role:"item_id",value:s}],suggested_retry:d})})}const Kt=new Set(["--activity-limit","--assignee","--assignee-filter","--date","--depth","--fields","--format","--from","--limit","--parent","--path","--pm-path","--priority","--release","--section","--sprint","--stale-threshold","--tag","--to","--type"]),ue=new Set(["context","ctx"]);function Xt(e,t,n){if(!/too many arguments/i.test(e)||!ue.has(t??""))return null;const i=n?.normalizedInvocationArgs??[],r=i.findIndex(c=>ue.has(c)),o=r===-1?1:r+1,a=e.match(/got \d+:\s*(\S+)/i);let s=a?a[1].replace(/\.$/,""):void 0;if(s===void 0){let c=!1;for(const l of i.slice(o)){if(c){c=!1;continue}const m=l.split("=")[0];if(Kt.has(m)){c=!l.includes("=");continue}if(!l.startsWith("-")){s=l;break}}}if(!s)return null;const d=`pm get ${s}`;return u({code:"context_takes_no_item_argument",title:"pm context takes no item argument",happened:`pm context renders a workspace-level snapshot and received the positional argument "${s}".`,required:`Use ${d} for one item's full details, or pm context --parent ${s} to scope the snapshot to that item's subtree.`,why:"Item-level detail (pm get) and workspace-level context (pm context) are separate projections.",examples:[d,`pm context --parent ${s}`],recovery:p(n,{suggested_retry:d})})}function U(e,t,n,i){const r=I(e),o=xt(r,t,n,i)??Et(r,t,i)??jt(r,t,i)??Gt(r,i)??Mt(i)??Yt(r,t,i)??Ht(r,t,i)??Nt(r,t,i)??Vt(r,t,i)??Xt(r,t,i);return o||u({code:"invalid_command_usage",title:"Invalid command usage",happened:r,required:"Use the command with valid arguments and options.",why:"Commander validates CLI contracts before execution.",examples:["pm --help",`pm ${t??"<command>"} --help`],recovery:p(i)})}function cn(e,t,n={}){const i=T(z(e,t));return(t?.code==="tracker_root_missing"||t?.code==="tracker_not_initialized")&&i.title==="Tracker is not initialized"&&i.recovery?.suggested_retry_args?[`Error: ${i.title}`,`Run: ${f(i.recovery.suggested_retry_args)}`,"Use --json for full recovery details."].join(`
6
- `):me(i,n)}function me(e,t){const n=T(e),i=a=>$e(Je(n,a),n.required).output,r=i(t);if(t.lean!==!0)return r;const o=i({});return Buffer.byteLength(o,"utf8")<Buffer.byteLength(r,"utf8")?o:r}function ln(e,t){return E(z(e,t))}function un(e,t,n){return D(z(e,n),t)}function mn(e,t,n,i,r={}){const o=U(e,t,n,i);return me(o,r)}function pn(e,t,n,i){return E(U(e,t,n,i))}function fn(e,t,n,i,r){return D(U(e,t,n,r),i)}function hn(e,t){const n=pe(e);return D(n,t)}function pe(e){const t=I(e);return it(t)?u({code:"module_import_failed",title:"Module import failed",happened:t,required:"Ensure the active checkout is built and any package or extension entry file exists before retrying.",why:"Node could not resolve an imported module. In pm this usually means an extension/package entrypoint, build artifact, or dependency is missing from the active runtime.",examples:["pnpm build","pm package manage --doctor --project","pm health --check-only --json"],nextSteps:["Rebuild the checkout or package that provides the missing module.","Run package doctor for installed extensions when the failure follows package installation or activation.","Rerun the original pm command after the runtime files are present."]}):u({code:"unknown_error",title:"Unhandled error",happened:t,required:"Inspect command input and runtime state, then retry.",why:"Unexpected runtime failures can occur from environment or extension-level issues.",examples:["pm --help","pm health --json"]})}function _n(e){return E(pe(e))}const gn={applyPmCliErrorContext:h,appendIfMissing:b,buildCommanderRecoveryPayload:p,buildFallbackTitleFromMessage:se,commandExampleForRequiredOption:de,dedupeStrings:P,guidanceToClassification:E,guidanceToJsonEnvelope:ae,normalizeRecoveryPayload:y,renderList:x,resolveKnownPackageCommandHint:J};export{gn as _testOnly,St as buildLinkedTestQuotedRetryCommand,pn as classifyCommanderError,ln as classifyPmCliError,_n as classifyUnknownError,mn as formatCommanderErrorForDisplay,fn as formatCommanderErrorForJson,cn as formatPmCliErrorForDisplay,un as formatPmCliErrorForJson,hn as formatUnknownErrorForJson,dn as projectLeanErrorEnvelope,He as renderGuidanceMessage};
5
+ ${nn}`;if(r(A))return A}return t}function an(e,n){n.tombstone!==void 0&&(e.tombstone=n.tombstone,e.item_id=n.itemId),n.lease!==void 0&&(e.lease=n.lease,e.current_owner=n.currentOwner??null,e.item_id=n.itemId),n.claimedBy!==void 0&&(e.claimed_by=n.claimedBy,e.claimed_at=n.claimedAt??null,e.claim_source=n.claimSource??"unknown",n.claimActivity!==void 0&&(e.claim_activity=n.claimActivity),e.item_id=n.itemId),n.currentRevision!==void 0&&(e.expected_revision=n.expectedRevision??null,e.current_revision=n.currentRevision,n.itemId!==void 0&&(e.item_id=n.itemId))}function se(e,n){return n.sideEffects!==void 0&&(e.side_effects=n.sideEffects),n.previewStorage!==void 0&&(e.preview_storage=n.previewStorage),n.transactionOperation!==void 0&&(e.transaction_operation=n.transactionOperation),an(e,n),je(n)&&(e.why=n.why),n.examples&&n.examples.length>0&&(e.examples=n.examples),n.nextSteps&&n.nextSteps.length>0&&(e.next_steps=n.nextSteps),n.verificationErrors&&n.verificationErrors.length>0&&(e.verification_errors=n.verificationErrors),n.flag!==void 0&&(e.flag=n.flag),n.value!==void 0&&(e.value=n.value),n.unmatchedSelectors!==void 0&&(e.unmatched_selectors=n.unmatchedSelectors),n.availableDependencies!==void 0&&(e.available_dependencies=n.availableDependencies),n.recovery&&(e.recovery=n.recovery),e}function sn(e,n){if(e.flag)return e.flag;const t=r=>{const o=r.split("=",1)[0];return R([o]).length>0&&!["--help","--no-changed-fields","--version"].includes(o)&&n.some(a=>a===o||a.startsWith(`${o}=`))};return[...`${e.title} ${e.happened}`.matchAll(/--[A-Za-z0-9][A-Za-z0-9_-]*/gu)].map(r=>r[0]).find(r=>t(r))}function dn(e,n,t){if(e.value!==void 0)return e.value;if(e.flag===void 0&&t){const i=n.find(o=>o===t||o.startsWith(`${t}=`));if(i?.startsWith(`${t}=`))return i.slice(t.length+1);const r=n.indexOf(t);return n[r+1]}}function cn(e){const n=R([...e]),t=Te(n);return t?[t.alias,...n.slice(t.canonical_argv.length)]:n}function ln(e,n){if(e.policyViolations?.length)return{surface:`policy:${e.policyViolations.map(o=>o.policy_id).join(",")}`,policies:e.policyViolations,policy_violation_count:e.policyViolationCount,missing_fields:[...new Set(e.policyViolations.flatMap(o=>o.missing_fields))],exit_code:n};const t=cn(e.recovery?.normalized_args??[]),i=sn(e,t),r=dn(e,t,i);return{surface:i??e.recovery?.missing?.[0]??M(t)??"command",...r!==void 0?{rejected_value:r}:{},...e.recovery?.allowed_values?.length?{legal_domain:e.recovery.allowed_values}:{},exit_code:n}}function de(e,n){const t=se({type:e.type,code:e.code,title:e.title,detail:e.happened,required:e.required,exit_code:n,refusal:ln(e,n),...e.changed===!1?{changed:!1}:{}},e);return e.details!==void 0&&(t.details=e.details),e.detailsOmitted!==void 0&&(t.details_omitted=e.detailsOmitted),t}function D(e,n){const t=O(e),i=t.recovery,o=!!i?.suggested_retry||!!i?.suggested_retry_args?.length||!!i?.allowed_values?.length||!!i?.candidate_commands?.length||!!t.nextSteps?.length?"recovery_bundle":"error";return Ae(un(de(t,n),o),{diagnosticClass:o})}function un(e,n){if(e.details===void 0)return e;const t=V(n).default_max_estimated_tokens_by_format.json;if(G(Buffer.byteLength(JSON.stringify(e,null,2),"utf8"))<=t)return e;const{details:i,...r}=e;return{...r,details_omitted:{reason:"diagnostic_budget",byte_limit:ke.max_bytes}}}function E(e){return se({type:e.type,code:e.code,title:e.title,detail:e.happened,required:e.required,...e.changed===!1?{changed:!1}:{}},e)}function I(e){return e.replace(/\(outputHelp\)/g,"").trim()}function mn(e){const n=e.toLowerCase();return n.includes("cannot find module")||n.includes("cannot find package")||n.includes("err_module_not_found")||n.includes("module_not_found")}function w(e){if(!Array.isArray(e))return;const n=e.map(t=>t.trim()).filter(t=>t.length>0);return n.length>0?n:void 0}function P(e){const n=new Set,t=[];for(const i of e)n.has(i)||(n.add(i),t.push(i));return t}function pn(e){return M(e?.normalized_args)}function fn(e){const n=e.match(/\bmust be one of:?\s+([A-Za-z0-9_.|,\- ]+)/i);return n?n[1].split(/[|,]/).map(t=>t.trim()).filter(t=>/^[A-Za-z0-9_.-]+$/.test(t)):[]}function hn(e){if(e===void 0)return;const n=e.trim().replace(/\s+/gu," ").replace(/^ctx(?= |$)/u,"context").replace(/^(package|packages|extension) scaffold$/u,"$1 init"),t=qe(n);return Oe.find(i=>i.alias===t)?.canonical??n}function _n(e,n,t){const i=t?.normalized_args;if(n===void 0||!Array.isArray(i))return{commandPath:void 0,refusedFlag:void 0};const r=Le(i),o=le(n,t);if(o!==void 0)return{commandPath:r,refusedFlag:o};const a=new Set(K(r).filter(c=>c.reservation_scope!=="inherited").flatMap(c=>[c.flag,...c.aliases??[]])),s=new Set([...Y(i,r)?.keys()??[]].map(c=>i[c].split("=",1)[0])),d=e.replace(/"[^"]*"|'[^']*'/gu," "),l=new Set([...d.matchAll(/--[A-Za-z0-9][A-Za-z0-9_-]*/gu)].map(c=>c[0]).filter(c=>a.has(c)&&s.has(c)));return{commandPath:r,refusedFlag:l.size===1?[...l][0]:void 0}}function gn(e,n,t,i){const r=De(e??"",K(e)).some(s=>(s.flag===n||s.aliases?.includes(n)===!0)&&s.takes_value),o=t[i+1],a=t[i+2];return r&&o!==void 0&&!o.startsWith("-")&&(a===void 0||a.startsWith("-"))}function yn(e,n,t){const i=Y(e,n.commandPath);if(i===void 0)return;const r=[...i].filter(([u,f])=>e[u].split("=",1)[0]===t||f.flag===t);if(r.length!==1)return;const[o,a]=r[0],s=e[o].includes("=");if(!s&&!a.consumesValue&&!gn(n.commandPath,t,e,o))return;const d=e[o].split("=",1)[0],l=s?e[o].slice(d.length+1):e[o+1],c=[...i.values()].some(u=>u.flag==="--json");return l===void 0?void 0:{index:o,attached:s,spelling:d,value:l,jsonRequested:c}}function vn(e,n){return!(e.value.startsWith("-")&&!e.attached)&&!/[=,:\n]/u.test(e.value)&&!n.includes(e.value)}function wn(e,n,t){const i=e?.normalized_args,r=t.refusedFlag;if(!Array.isArray(i)||r===void 0||n.length===0)return;const o=yn(i,t,r);if(o===void 0||!vn(o,n))return;const a=o.jsonRequested&&n.includes("json")?"json":n[0],s=[...i];return o.attached?s[o.index]=`${o.spelling}=${a}`:s[o.index+1]=a,h(s)}function ce(e){const n=e.split(/\r?\n/)[0].trim();if(n.length===0)return;const t=Array.from(n);return t.length<=120?n:`${t.slice(0,117).join("")}...`}function $(e,n){return typeof e=="string"&&e.trim().length>0?e.trim():n}function le(e,n){if(e.flag!==void 0)return e.flag;if(e.field===void 0)return;const t=e.field.startsWith("--")?e.field:`--${e.field.replaceAll(/([A-Z])([A-Z][a-z])/gu,"$1-$2").replaceAll(/([a-z0-9])([A-Z])/gu,"$1-$2").replaceAll("_","-").toLowerCase()}`;return n?.normalized_args?.some(i=>i===t||i.startsWith(`${t}=`))?t:void 0}function bn(e,n,t,i){if(n==="close_validation_missing_fields")return"Close is missing required evidence";const r=e.code==="command_failed"||e.code==="invalid_argument_value"&&n!==e.code;return(t.code&&r?ce(i):void 0)??e.title}function kn(e){const n=Ce(e);return n===void 0?{}:"details"in n?{details:n.details}:{detailsOmitted:n.details_omitted}}const $n=400;function Cn(e){const n=[];for(const t of e.slice(0,8)){const i=JSON.stringify(t);Buffer.byteLength([...n,i].join(", "),"utf8")<=$n&&n.push(i)}return n}function An(e){const n=e?.allowed_values;if(n===void 0||Array.isArray(n)&&n.every(a=>typeof a=="string"))return;const t=Array.isArray(n)?n.filter(a=>typeof a=="string"):[],i=Cn(t),r=i.join(", ")||"none shown",o=t.length>i.length?` (${t.length-i.length} additional valid choices omitted)`:"";return`Incomplete legal domain from malformed producer metadata. Usable choices shown: ${r}${o}. Correct the producer metadata before relying on a complete domain.`}function Rn(e,n,t){const i=y(n),r=i&&e?y({...e,...i}):i??e;if(!t)return r;const{allowed_values:o,...a}=r??{};return Object.keys(a).length>0?a:void 0}function _(e,n,t){if(!t)return e;const i=I(n),r=$(t.code,e.code),o=$(t.type,X(r)),a=w(t.examples)??e.examples,s=w(t.nextSteps)??e.nextSteps,d=An(t.recovery),l=d?[...s?.slice(0,1)??[],d,...s?.slice(1)??[]]:s,c=w(t.verification_errors)??e.verificationErrors,u=Rn(e.recovery,t.recovery,d!==void 0);return{...e,code:r,changed:t.changed,sideEffects:t.side_effects,type:o,title:bn(e,r,t,i),happened:i.length>0?i:e.happened,required:$(t.required,e.required),why:$(t.why,e.why),examples:a,nextSteps:l,urlCredentialsRejected:t.url_credentials_rejected??e.urlCredentialsRejected,partialLegalDomainNotice:d,verificationErrors:c,policyViolations:t.policy_violations,policyViolationCount:t.policy_violation_count,flag:le(t,u)??e.flag,value:t.value??e.value,unmatchedSelectors:t.unmatched_selectors,itemId:t.item_id,transactionOperation:t.transaction_operation,previewStorage:t.preview_storage,tombstone:t.tombstone,lease:t.lease,currentOwner:t.current_owner,claimedBy:t.claimed_by,claimedAt:t.claimed_at,claimSource:t.claim_source,claimActivity:t.claim_activity,expectedRevision:t.expected_revision,currentRevision:t.current_revision,availableDependencies:t.available_dependencies,recovery:u,...kn(t)}}function Sn(e,n,t){const i=n.match(/^Tracker is not initialized at (.+)\. (?:Run pm init first|Tracker root does not exist\. Run pm init first)\.$/);if(!i)return null;const r=i[1],o=Ie(process.cwd(),r);return _(m(o?{code:"tracker_not_initialized",title:"Tracker exists at a custom path",happened:`pm did not find initialized metadata at ${r}, but found a tracker at ${o}.`,required:"Select the existing tracker root explicitly.",why:"Implicit discovery checks the default .agents/pm layout and ancestor root-layout trackers, while custom nested roots require an explicit path.",examples:[`pm --pm-path ${o} <command>`,`PM_PATH=${o} pm <command>`],nextSteps:[`Re-run with "--pm-path ${o}" or export PM_PATH=${o}.`]}:{code:"tracker_not_initialized",title:"Tracker is not initialized",happened:`pm data path does not contain initialized tracker metadata (${i[1]}).`,required:"Select an existing tracker with --pm-path/PM_PATH, or initialize the default .agents/pm storage.",why:"Most commands require settings in an explicitly selected root, an ancestor root-layout tracker, or the default .agents/pm directory.",examples:["pm init","pm init acme"],nextSteps:['Run "pm init", then rerun your original command.']}),e,t)}function xn(e,n,t){const i=n.match(/^Item ([^ ]+) not found$/);if(!i)return null;const r=i[1],o=/^(undefined|null|<.*>|\[.*\]|{.*}|)$/.test(r),a=o?`The item ID "${r}" looks like a placeholder or unresolved variable. Ensure the ID argument is resolved before calling pm.`:`No item with id "${r}" exists in the active tracker scope.`;return _(m({code:"item_not_found",title:"Item ID not found",flag:"id",value:r,happened:a,required:"Use an existing item ID from current tracker data.",why:"Mutation and read commands operate only on known IDs.",examples:["pm list --status open --limit 20",'pm search "<keyword>" --limit 10'],nextSteps:o?["Check that the variable holding the item ID is defined before passing it to pm.",'Use "pm list --status open --limit 20" to find valid IDs.']:["Confirm the active --path/PM_PATH scope, then retry with a valid id."]}),e,t)}function En(e,n,t){return!n.includes("is assigned to")||!n.includes("Use --force to override")?null:_(m({code:"ownership_conflict",title:"Ownership conflict",happened:n,required:"Run as the assigned owner, claim the item when appropriate, or use --force only for an approved override.",why:"Ownership checks prevent accidental concurrent mutations on claimed items and protect against conflicting writes.",examples:["pm claim pm-a1b2","pm update pm-a1b2 --status in_progress --force"],nextSteps:["Use --force for approved systematic metadata updates performed by leads or maintainers.","Use --force when correcting known stale metadata after coordinating ownership changes.",'For non-terminal reassignment, prefer "pm claim <ID>" before running other mutations.']}),e,t)}function In(e,n,t){if(!n.includes("is locked"))return null;const i=ee(t?.recovery?.normalized_args),r=i?h(i):void 0,o=_(m({code:"lock_conflict",title:"Lock conflict",happened:n,required:"Wait for lock release, then retry the same operation. Set PM_LOCK_WAIT_MS to a larger bounded millisecond budget for expected contention.",why:"Locking protects item files from concurrent write races.",examples:r?[r]:["pm gc --scope locks --dry-run"]}),e,t);return i&&(o.recovery={...o.recovery,suggested_retry:r,suggested_retry_args:[...i]}),o}function On(e,n,t){const i=n.match(/^Missing required option /),r=n.match(/^Missing required options /);if(!i&&!r)return null;const o=!!r,a=o?null:n.replace(/^Missing required option\s+/,"").trim(),s=a??"",d=a?`Pass ${a} with a valid value before running the command.`:"Provide the required option for this command invocation.";return _(m({code:"missing_required_option",title:o?"Missing required options":`Missing required option ${s}`,happened:n,required:o?"Provide every required option for this command invocation.":d,why:"Required options define command intent and enforce deterministic write contracts.",examples:['pm create --title "Task title" --description "Task details" --type Task --create-mode progressive','pm create --title "Task title" --description "Task details" --type Task --status open --priority 1 --message "Create task" --dep "id=pm-epic01,kind=parent,created_at=now" --comment "created_at=now,text=Why this task exists." --note "created_at=now,text=Initial implementation note." --learning "created_at=now,text=Durable lesson placeholder." --file "path=src/example.ts,scope=project" --test "command=node scripts/run-tests.mjs test,scope=project,timeout_seconds=240" --doc "path=README.md,scope=project"'],nextSteps:['Run "pm <command> --help" to view required and recommended flags.',"For staged triage without placeholder linkage values, use --create-mode progressive."]}),e,t)}function Tn(e,n,t){return n.startsWith("No update flags provided")?_(m({code:"no_update_fields",title:"No update fields supplied",happened:"The update command was called without any field-changing flags.",required:"Provide at least one field-changing flag such as --status, --priority, --title, --tags, --description, or --body. Use --message only to label a real mutation.",why:"pm update mutates existing item fields; no-op invocations are rejected to avoid ambiguous history.",examples:['pm update pm-a1b2 --status in_progress --message "Start implementation"','pm update pm-a1b2 --description "Clarified implementation scope" --message "Clarify task intent"','pm append pm-a1b2 --body "Detailed progress notes" --message "Append progress notes"'],nextSteps:["Choose the item field you intend to change, then pair that change with --message for history context.","Use pm comments, pm notes, pm learnings, or pm append when you only need to add narrative context."]}),e,t):null}function qn(e,n){if(e.startsWith("Invalid "))return!0;if(!e.includes(" must be ")&&!e.includes(" requires "))return!1;const t=$(n?.code,void 0);return t===void 0||t==="invalid_argument_value"||n?.allowed!==void 0}function Ln(e,n,t){if(!qn(n,t))return null;const i=y(t?.recovery),r=pn(i),o=r?`pm ${r} --help`:"pm <command> --help",a=t?.recovery?.allowed_values!==void 0?[]:t?.allowed??fn(n),s=y({...i,allowed_values:i?.allowed_values??a}),d=_n(n,t,i),l=wn(i,a,d),c=hn(d.commandPath??r),u=l?[l,o]:[o,c===void 0?"pm contracts --command <command> --flags-only --json":h(["contracts","--command",c,"--flags-only","--json"])],f=a.length>0?[`Allowed values: ${a.join("|")}`,`Run "${o}" to confirm command-specific constraints.`]:["Check allowed values in command help, then rerun with corrected input."];return _(m({code:"invalid_argument_value",title:"Invalid argument value",happened:n,required:"Use values that match documented command constraints.",why:"Validation protects data consistency and deterministic behavior across commands.",examples:u,nextSteps:f,recovery:s}),e,t)}function j(e,n){const t=I(e),i=Sn(e,t,n)??xn(e,t,n)??En(e,t,n)??In(e,t,n)??On(e,t,n)??Tn(e,t,n)??Ln(e,t,n);return i||_(m({code:"command_failed",title:"Command failed",happened:t,required:"Adjust command input or tracker state and retry.",why:"pm enforces explicit, deterministic contracts for data and command semantics.",examples:["pm --help","pm <command> --help"]}),e,n)}function ue(e,n,t){return e==="create"&&n.startsWith("--type")?[`pm create --title "Example title" --description "Example description" --type ${t.split("|")[0]||"Task"} --status open --priority 1 --message "Create item" --create-mode progressive`]:e==="update"?['pm update pm-a1b2 --status in_progress --message "Start implementation"']:[`pm ${e??"<command>"} --help`]}function Dn(e){const n=e.trim();return n.match(/--[A-Za-z0-9][A-Za-z0-9_-]*/)?.[0]??n}function Pn(e){if(!(!Array.isArray(e)||e.length===0))return h(e)}function z(e){if(!Array.isArray(e))return;const n=e.map(t=>t.trim()).filter(t=>t.length>0);return n.length>0?n:void 0}function p(e,n={}){const t=z(e?.providedOptionFlags),i=Array.isArray(e?.normalizedInvocationArgs)&&e?.normalizedInvocationArgs.length>0?e.normalizedInvocationArgs:void 0,r=typeof e?.attemptedCommand=="string"?e.attemptedCommand:Pn(i),o=typeof e?.suggestedRetryCommand=="string"?e.suggestedRetryCommand:void 0;return y({attempted_command:r,normalized_args:i,provided_fields:t,suggested_retry:o,suggested_retry_args:e?.suggestedRetryArgs,...n})}function b(e,n){return!n||e.includes(n)?e:[...e,n]}const jn=new Set(["--add","--add-json","--remove"]),zn=new Set(["command","cmd","path"]);function Un(e){if(Array.isArray(e))for(const n of e){if(!n.startsWith("--"))continue;const t=n.indexOf("="),i=t>=0?n.slice(0,t):n;if(jn.has(i))return i}}function Mn(e){if(!Array.isArray(e))return;const n=e.indexOf("test");if(n<0)return;const t=e[n+1];if(!(typeof t!="string"||t.startsWith("-")))for(let i=n+2;i<e.length;i+=1){const r=e[i];if(r!=="--add"&&r!=="--remove")continue;const o=e[i+1];if(typeof o!="string"||!zn.has(o))return;const a=[];for(let l=i+2;l<e.length;l+=1){const c=e[l];if(c.startsWith("--")&&c.length>2)break;a.push(c)}if(a.length<2)return;const s=`${o}=${a.join(" ")}`,d=[...e.slice(0,i+1),s,...e.slice(i+2+a.length)];return h(d)}}function Gn(e,n,t,i){const r=e.match(/required option '([^']+)' not specified/);if(!r)return null;const o=Dn(r[1]),a=o.startsWith("--type"),s=i?.suggestedRetryCommand,d=z(i?.providedOptionFlags),l=[o],c=ue(n,o,t),u=s?b(c,s):c,f=a?[`Allowed type values: ${t}`,`Run "pm ${n??"create"} --help --type <value>" for type-aware policy details.`]:[`Run "pm ${n??"<command>"} --help" for required option guidance.`],C=s?b(f,`Replay with preserved arguments: ${s}`):f,A=d&&d.length>0?b(C,`Already provided options: ${d.join(", ")}`):C;return m({code:"missing_required_option",title:`Missing required option ${o}`,happened:`Commander rejected the command because ${o} was not provided.`,required:`Pass ${o} with a valid value before running the command.`,why:a?"--type selects item contract and policy routing, including required/disabled option rules.":"Required flags define mandatory command intent and prevent ambiguous execution.",examples:u,nextSteps:A,recovery:p(i,{missing:l})})}function Nn(e,n,t){const i=e.match(/missing required argument '([^']+)'/);if(!i)return null;const r=i[1];return m({code:"missing_required_argument",title:`Missing required argument ${r}`,happened:`Command invocation omitted positional argument ${r}.`,required:`Provide ${r} in the expected command position.`,why:"Positional arguments identify the target entity or action context for the command.",examples:[`pm ${n??"<command>"} --help`],recovery:p(t,{missing:[r]})})}function Fn(e,n,t){return m({code:"unsupported_update_option",title:`Unsupported option ${e} for update`,happened:`pm update does not accept ${e} for linked artifact mutations.`,required:"Use dedicated linked-artifact commands instead of pm update for files/docs changes.",why:"pm update manages scalar item metadata, while linked files/docs are managed by pm files and pm docs.",examples:['pm files pm-a1b2 --add "path=src/cli/main.ts,scope=project,note=implementation surface"','pm docs pm-a1b2 --add "path=README.md,scope=project,note=user-facing contract"'],nextSteps:['Run "pm files --help" and "pm docs --help" for add/remove payload formats.'],recovery:p(n,{suggested_flags:t})})}const Wn={declared_elsewhere:"Use an option declared on this path, or move the declared option to one of its accepting command paths.",declared_on_path:"Use the option with the value and syntax declared by this command path.",declared_nowhere:"Use a declared option on this command path; this spelling exists nowhere in the command lexicon."};function Vn(e){const n=w(e.unknownOptionOtherCommands)??[];return{otherCommands:n,optionScope:e.unknownOptionScope??(n.length>0?"declared_elsewhere":"declared_nowhere"),candidateTotal:e.unknownOptionOtherCommandsTotal??n.length}}function Bn(e,n,t,i,r){const o=i.otherCommands.slice(0,3),a=i.candidateTotal-o.length,s=a>0?` and ${String(a)} more command path(s)`:"";return["Run command help to confirm the exact option contracts for this command path.",t.length?`Nearest supported options: ${t.join(", ")}`:void 0,r?void 0:Hn(e,n),o.length?`${e} is accepted by ${o.join(", ")}${s}. Inspect those command contracts only if you intended a different operation.`:void 0,pe(e)?`"${e}" contains spaces, so it is a value that starts with --, not an option. Pass it after a -- separator at the end of the command, or through the command's named value flag.`:i.optionScope==="declared_nowhere"?`${e} is not declared on any command path. Use a nearest supported option on ${n??"the attempted command"}, or inspect that command's help.`:void 0,r?`Replay with suggested correction: ${r}`:void 0].filter(d=>typeof d=="string")}const me=["--brief","--compact","--standard","--deep","--full","--summary","--depth"];function Hn(e,n){if(n===void 0||!me.includes(e.split("=",1)[0]))return;const t=ve(n);return t===void 0?void 0:`Completeness controls accepted by pm ${t.command}: ${ge(t)}.`}function Yn(e,n,t){const i=we(t??"",e.normalizedInvocationArgs??[],n);return i?{retryCommand:h(i),suggestedRetryArgs:i}:[...me,"--toon",...t==="activity"?["--since"]:[]].includes(n.split("=",1)[0])?{}:void 0}function pe(e){return/\s/u.test(e)}function Kn(e,n){const t=e?.indexOf(n)??-1;if(e===void 0||t<0||e.includes("--")||e.lastIndexOf(n)!==t)return{};if(e.slice(t+1).some(r=>!r.startsWith("-")))return{};const i=[...R(e.filter((r,o)=>o!==t)),"--",n];return{retryCommand:h(i),suggestedRetryArgs:i}}function Xn(e,n,t){if(pe(n))return Kn(e.normalizedInvocationArgs,n);if(["--dry-run","--check","--check-only","--plan","--preview"].includes(n.split("=",1)[0]))return{};const i=Yn(e,n,t);if(i)return i;if(e.suggestedRetryCommand!==void 0)return{retryCommand:e.suggestedRetryCommand};if(ye(n))return{};const r=e.normalizedInvocationArgs;if(r===void 0)return{};if(r.filter(s=>s===n||s.startsWith(`${n}=`)).length!==1)return{};const o=r.findIndex(s=>s===n||s.startsWith(`${n}=`));if(o<0||r.includes("--")||!r[o]?.includes("=")&&o!==r.length-1&&r[o+1]?.startsWith("-")!==!0)return{};const a=R(r.filter((s,d)=>d!==o));return{retryCommand:h(a),suggestedRetryArgs:a}}function Zn(e,n,t){const i=e.match(/unknown option '([^']+)'/);if(!i)return null;const r=t??{},o=i[1],a=z(r.unknownOptionSuggestions)??[],{retryCommand:s,suggestedRetryArgs:d}=Xn(r,o,n);if(n==="update"&&(o==="--file"||o==="--doc"))return Fn(o,t,a);const l=Vn(r),c=Bn(o,n,a,l,s);["--dry-run","--check","--check-only","--plan","--preview"].includes(o.split("=",1)[0])&&c.push("The requested preview is unavailable on this path. Inspect the item with a read-only command or use a command that declares this option; do not replay this mutation without preview intent.");const u=[s,n?`pm ${H(n)?.canonical??n} --help`:"pm --help --all"].filter(f=>typeof f=="string");return m({code:"unknown_option",title:`Unknown option ${o}`,happened:`Commander does not recognize option ${o} for this command path.`,required:Wn[l.optionScope],why:"Option contracts are command-specific and intentionally validated.",flag:o,value:o,examples:u,nextSteps:c,recovery:p(t,{suggested_flags:a.length>0?a:void 0,suggested_retry:s,suggested_retry_args:d,candidate_commands:l.otherCommands,candidate_commands_total:l.candidateTotal||void 0,candidate_commands_truncated:r.unknownOptionOtherCommandsTruncated,option_scope:l.optionScope})})}function Jn(e,n,t,i,r){const o=`"${e}" is provided by the ${n.packageName} package. Install it with: ${n.installCommand}`,a=i.filter(s=>!s.endsWith(`: ${n.installCommand}`));return m({code:"unknown_command",title:`Unknown command ${e}`,happened:`pm does not expose command path "${e}" in current runtime configuration. It is shipped by the optional ${n.packageName} package.`,required:`Install the ${n.packageName} package, or use a valid command name or subcommand path.`,why:"Command registry includes core commands plus active extension command handlers; package-provided commands appear only after the package is installed.",examples:P([n.installCommand,...t]),nextSteps:P([o,...a]),recovery:p(r)})}function Qn(e,n){const t=e.match(/unknown command '([^']+)'/);if(!t)return null;const i=t[1],r=w(n?.unknownCommandExamples),o=w(n?.unknownCommandNextSteps),a=Q(i),s=r??["pm --help"],d=o??["Verify spelling and active extensions, then rerun."],l=new Set(n?.failedExtensions?.map(u=>u.name.trim().toLowerCase())),c=a?.packageName.replace(/^@unbrained\/pm-/,"").toLowerCase();return a&&(!c||!l.has(c))?Jn(i,a,s,d,n):m({code:"unknown_command",title:`Unknown command ${i}`,happened:`pm does not expose command path "${i}" in current runtime configuration.`,required:"Use a valid command name or subcommand path.",why:"Command registry includes core commands plus active extension command handlers.",examples:s,nextSteps:d,recovery:p(n)})}function et(e){const n=e?.unknownSubcommandPath?.trim(),t=e?.unknownSubcommandToken?.trim(),i=w(e?.unknownSubcommandAllowedValues);if(!n||!t||!i)return null;const r=e?.suggestedRetryCommand;return m({code:"unknown_subcommand",title:`Unknown ${n} subcommand ${t}`,value:t,happened:`The positional token sequence "${t}" is not a declared ${n} subcommand.`,required:`Use one of: ${i.join(", ")}.`,why:"Subcommands are single positional tokens; multi-word action names use hyphens.",examples:[...r?[r]:[],`pm ${H(n)?.canonical??n} --help`],nextSteps:r?[`Retry with the declared hyphenated action: ${r}`]:["Choose one value from recovery.allowed_values."],recovery:p(e,{allowed_values:i,suggested_retry:r})})}function nt(e,n,t){if(!/too many arguments/i.test(e)||n!=="test")return null;const i=t?.normalizedInvocationArgs,r=Un(i);if(!r)return null;const o=Mn(i);return m({code:"linked_test_value_not_quoted",title:`Linked-test ${r} value must be one argument`,happened:`Commander saw extra positional tokens after the item id \u2014 usually a ${r} value containing spaces (for example a command with " -- ") that the shell split into multiple tokens.`,required:`Quote the whole ${r} value as a single argument. Accepted forms: --add "command=npm test -- parser", --add command "npm test -- parser" (two-token form with the value quoted), or --add-json for complex commands.`,why:"The shell splits unquoted values before pm can see them, so pm cannot reassemble the intended command unambiguously.",examples:[...o?[o]:[],'pm test pm-a1b2 --add "command=npm test -- parser"','pm test pm-a1b2 --add command "npm test -- parser"',`pm test pm-a1b2 --add-json '{"command":"npm test -- parser"}'`],nextSteps:[...o?[`Replay with the value re-joined into one argument: ${o}`]:[],"Prefer --add-json for commands containing commas, equals signs, or quotes.",'Run "pm test --help" for linked-test entry contracts.'],recovery:p(t,o?{suggested_retry:o}:{})})}const tt=new Set(["comments","docs","files","learnings","notes","test"]);function it(e,n,t){if(!/too many arguments/i.test(e))return null;const i=be(n,t?.normalizedInvocationArgs??[]);if(!i)return null;const r=i.retryArgs?h(i.retryArgs):void 0,o=h(i.templateArgs??["test",i.itemId,"--add",`command=<actual command>,${i.value}`]);return m({code:"linked_resource_positional_value",title:"Linked-resource values require an explicit --add option",happened:`The value after the item id is not a positional argument of ${n}.`,required:r?`Retry the explicit collection mutation: ${r}`:`Supply the actual command and its metadata together, for example ${o}.`,examples:[r??o],recovery:p(t,{suggested_retry:r,suggested_retry_args:i.retryArgs})})}function rt(e){return[...e].some(n=>n.charCodeAt(0)<32||n.charCodeAt(0)===127)}function ot(e){const n=Se()?void 0:e.retryArgs,t=process.platform==="win32"||Ee(process.platform)==="cmd",i=n?.some(r=>rt(r)||t&&xe(r,process.platform,"cmd")!==r)===!0;return{retryArgs:n,argvOnly:i,retry:n&&!i?h(n):void 0}}function at(e,n,t){const i=t?.linkedResourceValueList;if(!/too many arguments/i.test(e)||i===void 0)return null;const r=i.flags[0],o=i.flags.join(", "),{retryArgs:a,argvOnly:s,retry:d}=ot(i),l=n!=="test"&&i.flags.includes("--add"),c=`pm ${n} ${i.itemId} ${r} <value> ${r} <value>`,u=i.extraValues.length;return m({code:"linked_resource_value_list",title:`Repeat ${r} once per value${l?" (or use --add-glob)":""}`,happened:`${u} more value${u===1?"":"s"} followed the value of ${o}. pm ${n} takes one value per occurrence, so they were read as extra positional arguments and nothing was changed.`,required:d?`Retry with one ${r} per value: ${d}`:s?`Retry with one ${r} per value by replaying recovery.suggested_retry_args (shown with --json): a value holds a control character, or needs cmd.exe quoting that a copied command cannot carry exactly.`:i.readsStdin?`Write one ${r} per value and pipe the same input again, because the command reads stdin: ${c}`:`Write one ${r} per value, and quote a value that contains spaces or commas so the shell passes it as one argument: ${c}`,why:`Each occurrence of a repeatable flag takes exactly one value, so an item id written after the flag (pm ${n} ${r} <value> <id>) stays unambiguous.`,examples:[d??c,...l?[`pm ${n} ${i.itemId} --add-glob "<pattern>"`]:[],`pm ${n} --help`],recovery:p(t,{suggested_retry:d,suggested_retry_args:a})})}function st(e,n,t){if(!/too many arguments/i.test(e)||!tt.has(n??""))return null;const i=t?.normalizedInvocationArgs??[],r=i.findIndex(l=>l===n),o=i[r+1],a=i[r+2],s=t?.verifiedCollectionItemId?.trim();if(o?.toLowerCase()!=="add"||!a||a.startsWith("-")||!s||s.toLowerCase()!==a.toLowerCase())return null;const d=`pm ${n} ${s} --add <value>`;return m({code:"collection_transposed_subcommand",title:`Transposed ${n} add syntax`,happened:`The positional token "add" occupied the item-id role and "${s}" occupied the next positional role. pm ${n} does not use an add subcommand.`,required:`Place the item id immediately after ${n}, then use --add for the value.`,why:"Collection mutations use object-first grammar: pm <collection> <item-id> --add <value>.",examples:[d,`pm ${n} --help`],recovery:p(t,{parsed_positionals:[{role:"transposed_subcommand",value:o},{role:"item_id",value:s}],suggested_retry:d})})}const dt=new Set(["--activity-limit","--assignee","--assignee-filter","--date","--depth","--fields","--format","--from","--limit","--parent","--path","--pm-path","--priority","--release","--section","--sprint","--stale-threshold","--tag","--to","--type"]),fe=new Set(["context","ctx"]);function ct(e,n,t){if(!/too many arguments/i.test(e)||!fe.has(n??""))return null;const i=t?.normalizedInvocationArgs??[],r=i.findIndex(l=>fe.has(l)),o=r===-1?1:r+1,a=e.match(/got \d+:\s*(\S+)/i);let s=a?a[1].replace(/\.$/,""):void 0;if(s===void 0){let l=!1;for(const c of i.slice(o)){if(l){l=!1;continue}const u=c.split("=")[0];if(dt.has(u)){l=!c.includes("=");continue}if(!c.startsWith("-")){s=c;break}}}if(!s)return null;const d=`pm get ${s}`;return m({code:"context_takes_no_item_argument",title:"pm context takes no item argument",happened:`pm context renders a workspace-level snapshot and received the positional argument "${s}".`,required:`Use ${d} for one item's full details, or pm context --parent ${s} to scope the snapshot to that item's subtree.`,why:"Item-level detail (pm get) and workspace-level context (pm context) are separate projections.",examples:[d,`pm context --parent ${s}`],recovery:p(t,{suggested_retry:d})})}function U(e,n,t,i){const r=I(e),o=Gn(r,n,t,i)??Nn(r,n,i)??Zn(r,n,i)??Qn(r,i)??et(i)??st(r,n,i)??at(r,n,i)??nt(r,n,i)??it(r,n,i)??ct(r,n,i);return o||m({code:"invalid_command_usage",title:"Invalid command usage",happened:r,required:"Use the command with valid arguments and options.",why:"Commander validates CLI contracts before execution.",examples:["pm --help",`pm ${n??"<command>"} --help`],recovery:p(i)})}function At(e,n,t={}){const i=O(j(e,n));return(n?.code==="tracker_root_missing"||n?.code==="tracker_not_initialized")&&i.title==="Tracker is not initialized"&&i.recovery?.suggested_retry_args?[`Error: ${i.title}`,`Run: ${h(i.recovery.suggested_retry_args)}`,"Use --json for full recovery details."].join(`
6
+ `):he(i,t)}function he(e,n){const t=O(e),i=a=>Re(on(t,a),t.required).output,r=i(n);if(n.lean!==!0)return r;const o=i({});return Buffer.byteLength(o,"utf8")<Buffer.byteLength(r,"utf8")?o:r}function Rt(e,n){return E(j(e,n))}function St(e,n,t){return D(j(e,t),n)}function xt(e,n,t,i,r={}){const o=U(e,n,t,i);return he(o,r)}function Et(e,n,t,i){return E(U(e,n,t,i))}function It(e,n,t,i,r){return D(U(e,n,t,r),i)}function Ot(e,n){const t=_e(e);return D(t,n)}function _e(e){const n=I(e);return mn(n)?m({code:"module_import_failed",title:"Module import failed",happened:n,required:"Ensure the active checkout is built and any package or extension entry file exists before retrying.",why:"Node could not resolve an imported module. In pm this usually means an extension/package entrypoint, build artifact, or dependency is missing from the active runtime.",examples:["pnpm build","pm package manage --doctor --project","pm health --check-only --json"],nextSteps:["Rebuild the checkout or package that provides the missing module.","Run package doctor for installed extensions when the failure follows package installation or activation.","Rerun the original pm command after the runtime files are present."]}):m({code:"unknown_error",title:"Unhandled error",happened:n,required:"Inspect command input and runtime state, then retry.",why:"Unexpected runtime failures can occur from environment or extension-level issues.",examples:["pm --help","pm health --json"]})}function Tt(e){return E(_e(e))}const qt={applyPmCliErrorContext:_,appendIfMissing:b,buildCommanderRecoveryPayload:p,buildFallbackTitleFromMessage:ce,commandExampleForRequiredOption:ue,dedupeStrings:P,guidanceToClassification:E,guidanceToJsonEnvelope:de,normalizeRecoveryPayload:y,renderList:x,resolveKnownPackageCommandHint:Q};export{qt as _testOnly,Mn as buildLinkedTestQuotedRetryCommand,Et as classifyCommanderError,Rt as classifyPmCliError,Tt as classifyUnknownError,xt as formatCommanderErrorForDisplay,It as formatCommanderErrorForJson,At as formatPmCliErrorForDisplay,St as formatPmCliErrorForJson,Ot as formatUnknownErrorForJson,Ct as projectLeanErrorEnvelope,en as renderGuidanceMessage};
7
7
  //# sourceMappingURL=error-guidance.js.map
@@ -1,9 +1,9 @@
1
- import{Option as F}from"commander";import{PM_RELOCATED_COMMAND_ALIASES as d}from"../sdk/cli-contracts/command-aliases.js";import{resolveExtensionCommandInheritedFlagContracts as b}from"../sdk/cli-contracts/flag-contracts.js";import{resolveExtensionFlagOptionKey as N}from"../sdk/extension/command-options.js";import{enrichCliFlagInvocationContracts as L}from"../sdk/flag-invocation-contracts.js";import{resolveExtensionFlagValueContract as _,resolveExtensionLongFlagName as p}from"../sdk/runtime-primitives.js";function f(t){return t.trim().toLowerCase().split(/\s+/).filter(n=>n.length>0).join(" ")}function tn(t,n){const e=new Map;for(const o of t){const i=f(o.command);for(const r of n){if(r.layer!==o.layer||r.name!==o.name)continue;const a=f(r.command),s=a.split(" "),u=s.at(-1),l=s.slice(1).join(" "),c=l?`${s[0]}-${u} ${l}`:`${s[0]}-${u}`;if(u&&i===c){e.set(i,a);break}}}return e}function on(t,n,e,o){if(!n||!e)return;let i,r=0;for(const[s,u]of t.entries()){if(u!==n)continue;const l=t.slice(s);for(const[c,m]of o.entries()){const y=c.split(" ");y.length>r&&y.every((O,D)=>l[D]===O)&&(i=m,r=y.length)}}const a=i?.flags.find(s=>s.long===e||s.short===e);if(a)return j(a).takesValue}function g(t){if(typeof t!="string")return null;const n=t.trim();return n.length>0?n:null}function h(t){return typeof t=="boolean"?t:void 0}function j(t){const n=_(t);return{takesValue:n.value_arity!=="none",valueName:n.value_name}}function q(t){const n=p(t.long);if(!n||!n.startsWith("--")||n.length<3)return null;const e=C(t);return e?`${e} ${E(t)}`:null}function $(t){const n=[...new Set(t.map(q).filter(e=>e!==null))].sort((e,o)=>e.localeCompare(o));return n.length===0?null:`
1
+ import{Option as D}from"commander";import{PM_RELOCATED_COMMAND_ALIASES as d,resolvePmCommandOperation as H}from"../sdk/cli-contracts/command-aliases.js";import{isExpectHashAdmissibleAction as N}from"../sdk/lifecycle/item-revision.js";import{resolveCoreCommandInheritedFlagContracts as L,resolveExtensionCommandInheritedFlagContracts as j}from"../sdk/cli-contracts/flag-contracts.js";import{resolveExtensionFlagOptionKey as q}from"../sdk/extension/command-options.js";import{enrichCliFlagInvocationContracts as W}from"../sdk/flag-invocation-contracts.js";import{resolveExtensionFlagValueContract as _,resolveExtensionLongFlagName as p}from"../sdk/runtime-primitives.js";function f(e){return e.trim().toLowerCase().split(/\s+/).filter(t=>t.length>0).join(" ")}function ln(e,t){const n=new Map;for(const o of e){const i=f(o.command);for(const r of t){if(r.layer!==o.layer||r.name!==o.name)continue;const s=f(r.command),a=s.split(" "),u=a.at(-1),l=a.slice(1).join(" "),c=l?`${a[0]}-${u} ${l}`:`${a[0]}-${u}`;if(u&&i===c){n.set(i,s);break}}}return n}function cn(e,t,n,o){if(!t||!n)return;let i,r=0;for(const[a,u]of e.entries()){if(u!==t)continue;const l=e.slice(a);for(const[c,m]of o.entries()){const y=c.split(" ");y.length>r&&y.every((w,F)=>l[F]===w)&&(i=m,r=y.length)}}const s=i?.flags.find(a=>a.long===n||a.short===n);if(s)return z(s).takesValue}function g(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function h(e){return typeof e=="boolean"?e:void 0}function z(e){const t=_(e);return{takesValue:t.value_arity!=="none",valueName:t.value_name}}function I(e){const t=p(e.long);if(!t||!t.startsWith("--")||t.length<3)return null;const n=C(e);return n?`${n} ${E(e)}`:null}function $(e){const t=[...new Set(e.map(I).filter(n=>n!==null))].sort((n,o)=>n.localeCompare(o));return t.length===0?null:`
2
2
  Extension-provided flags:
3
- ${n.join(`
4
- `)}`}function rn(t){const n=new Map;for(const i of t){const r=f(i.target_command);if(r.length===0)continue;const a=n.get(r)??[];a.push(...i.flags),n.set(r,a)}const e=[...n.entries()].sort(([i],[r])=>i.localeCompare(r)),o=new Map;for(const[i,r]of e){const a=$(r);a&&o.set(i,a)}return o}function k(t,n){return typeof n!="string"||n.trim().length===0?t.replace(/\s+/g,"-"):n.trim().toLowerCase()}function S(t){if(!Array.isArray(t))return[];const n=[],e=new Set;for(const o of t){if(typeof o!="string")continue;const i=o.trim();i.length===0||e.has(i)||(e.add(i),n.push(i))}return n}function H(t){return Array.isArray(t)?t.map(n=>{const e=typeof n.name=="string"?n.name.trim():"";if(e.length===0)return null;const o={name:e,required:n.required===!0,variadic:n.variadic===!0};return typeof n.description=="string"&&n.description.trim().length>0&&(o.description=n.description.trim()),o}).filter(n=>n!==null):[]}function W(t){const n=new Map;for(const e of t){const o=f(e.command);if(o.length===0)continue;const i=typeof e.description=="string"&&e.description.trim().length>0?e.description.trim():void 0,r=typeof e.intent=="string"&&e.intent.trim().length>0?e.intent.trim():void 0;n.set(o,{command:o,action:k(o,e.action),description:i,intent:r,examples:S(e.examples),failure_hints:S(e.failure_hints),arguments:H(e.arguments),flags:[],tier:e.tier??"standard",family:e.family??"extensions",...e.read_output===void 0?{}:{read_output_declared:!0},source:{layer:e.layer,name:e.name,package:e.source_package,version:e.source_version}})}return n}function z(t){const n=new Map;for(const e of t){const o=f(e.target_command);if(o.length===0)continue;const i=n.get(o)??[];i.push(...e.flags),n.set(o,i)}return n}function B(t,n,e){const o=new Set;for(const i of t){const r=f(i);r.length>0&&o.add(r)}for(const i of n.keys())o.add(i);for(const i of e.keys())o.add(i);return o}function M(t,n,e){const o=e.get(t);return o?n.get(o):void 0}function an(t,n,e,o=new Map){const i=W(n),r=z(e),a=B(t,i,r),s=new Map,u=[...a].sort((l,c)=>l.localeCompare(c));for(const l of u){const c=M(l,i,o)??i.get(l),m=r.get(l)??(c?r.get(c.command):void 0)??[];if(c){s.set(l,{...c,command:l,flags:m});continue}s.set(l,{command:l,action:k(l,void 0),examples:[],failure_hints:[],arguments:[],flags:m,tier:"standard",family:"extensions"})}return s}function I(t){const n=t.variadic?"...":"";return t.required?`<${t.name}${n}>`:`[${t.name}${n}]`}function sn(t,n){for(const e of n.arguments)t.argument(I(e),e.description??"Extension argument.")}function T(t){if(h(t.visible)===!1)return null;const e=p(t.long),o=g(t.short),i=o&&o.startsWith("-")&&!o.startsWith("--")?o:null,r=e&&e.startsWith("--")&&e.length>2?e:null,a=[i,r].filter(s=>s!==null);return a.length>0?a:null}function C(t){const n=T(t);if(!n)return null;const{value_name:e,value_arity:o}=_(t),r=e?o==="optional"?` [${e}]`:` <${e}>`:"";return`${n.join(", ")}${r}`}function R(t){return C(t)}function E(t){const n=g(t.description)??"Extension-provided option.",e=[];h(t.required)===!0&&e.push("required"),h(t.enabled)===!1&&e.push("disabled");const o=e.length>0?` [${e.join(", ")}]`:"",i=t.default!==void 0?` (default: ${JSON.stringify(t.default)})`:"";return`${n}${o}${i}`}function w(t,n){const e=p(n.long),o=g(n.short);return t.options.some(i=>{const r=i;return e!==null&&r.long===e||o!==null&&r.short===o})}function ln(t,n){for(const e of n){if(w(t,e))continue;const o=R(e);if(!o)continue;const i=E(e),r=new F(o,i);if(r.negate=!1,e.list!==!0){t.addOption(r);continue}t.addOption(r.argParser((a,s=[])=>[...Array.isArray(s)?s:[s],a??!0]))}}function cn(t,n){return $(n.filter(e=>!w(t,e)))}function V(t){const n=C(t);if(!n)return null;const e=p(t.long),o=g(t.short),i=e&&e.startsWith("--")&&e.length>2?e:null,r=o&&o.startsWith("-")&&!o.startsWith("--")?o:null,a=_(t),s=h(t.required)===!0;return{flags:n,long:i,short:r,description:E(t),takes_value:a.value_arity!=="none",value_required:a.value_arity==="required",value_name:a.value_name,variadic:!1,required:s,aliases:[],alias_for:null,...t.default!==void 0?{default_value:t.default}:{},owner:"extension",...P(N(t))}}function P(t){return t===null?{}:{sdk_option:t}}function G(t){return L(t.command,b({readOutput:t.read_output_declared===!0})).map(n=>({flags:n.takes_value?`${n.flag} <${n.value_name}>`:n.flag,long:n.flag,short:null,description:n.description,takes_value:n.takes_value,value_required:n.value_required,value_name:n.takes_value?n.value_name:null,variadic:!1,required:!1,aliases:[...n.aliases??[]],alias_for:null,owner:"host"}))}function un(t){return["","Inherited host flags (delivered through context.global):",` ${G(t).map(e=>e.flags).join(", ")}`,` Run pm contracts --command ${t.command} --flags-only --json for each flag's owner and sdk_option key.`].join(`
5
- `)}function mn(t){if(!t)return[];const n=[],e=new Set;for(const o of t.flags){const i=V(o);!i||e.has(i.flags)||(e.add(i.flags),n.push(i))}return n}function fn(t,n){if(n.length===0)return t;const e=new Map(t.map(o=>[o.flags,o]));for(const o of n){const i=e.get(o.flags);e.set(o.flags,i?{...i,...o.default_value!==void 0?{default_value:o.default_value}:{},...o.owner===void 0?{}:{owner:o.owner},...o.sdk_option===void 0?{}:{sdk_option:o.sdk_option}}:o)}return[...e.values()]}function dn(t){const n=[];if(t.intent&&n.push(`Intent: ${t.intent}`),t.action&&n.push(`Action contract: ${t.action}`),t.examples.length>0){n.push("Examples:");for(const e of t.examples)n.push(` - ${e}`)}if(t.failure_hints.length>0){n.push("Common failure hints:");for(const e of t.failure_hints)n.push(` - ${e}`)}return n.length===0?null:`
3
+ ${t.join(`
4
+ `)}`}function un(e){const t=new Map;for(const i of e){const r=f(i.target_command);if(r.length===0)continue;const s=t.get(r)??[];s.push(...i.flags),t.set(r,s)}const n=[...t.entries()].sort(([i],[r])=>i.localeCompare(r)),o=new Map;for(const[i,r]of n){const s=$(r);s&&o.set(i,s)}return o}function k(e,t){return typeof t!="string"||t.trim().length===0?e.replace(/\s+/g,"-"):t.trim().toLowerCase()}function S(e){if(!Array.isArray(e))return[];const t=[],n=new Set;for(const o of e){if(typeof o!="string")continue;const i=o.trim();i.length===0||n.has(i)||(n.add(i),t.push(i))}return t}function M(e){return Array.isArray(e)?e.map(t=>{const n=typeof t.name=="string"?t.name.trim():"";if(n.length===0)return null;const o={name:n,required:t.required===!0,variadic:t.variadic===!0};return typeof t.description=="string"&&t.description.trim().length>0&&(o.description=t.description.trim()),o}).filter(t=>t!==null):[]}function B(e){const t=new Map;for(const n of e){const o=f(n.command);if(o.length===0)continue;const i=typeof n.description=="string"&&n.description.trim().length>0?n.description.trim():void 0,r=typeof n.intent=="string"&&n.intent.trim().length>0?n.intent.trim():void 0;t.set(o,{command:o,action:k(o,n.action),description:i,intent:r,examples:S(n.examples),failure_hints:S(n.failure_hints),arguments:M(n.arguments),flags:[],tier:n.tier??"standard",family:n.family??"extensions",...n.read_output===void 0?{}:{read_output_declared:!0},source:{layer:n.layer,name:n.name,package:n.source_package,version:n.source_version}})}return t}function T(e){const t=new Map;for(const n of e){const o=f(n.target_command);if(o.length===0)continue;const i=t.get(o)??[];i.push(...n.flags),t.set(o,i)}return t}function P(e,t,n){const o=new Set;for(const i of e){const r=f(i);r.length>0&&o.add(r)}for(const i of t.keys())o.add(i);for(const i of n.keys())o.add(i);return o}function R(e,t,n){const o=n.get(e);return o?t.get(o):void 0}function mn(e,t,n,o=new Map){const i=B(t),r=T(n),s=P(e,i,r),a=new Map,u=[...s].sort((l,c)=>l.localeCompare(c));for(const l of u){const c=R(l,i,o)??i.get(l),m=r.get(l)??(c?r.get(c.command):void 0)??[];if(c){a.set(l,{...c,command:l,flags:m});continue}a.set(l,{command:l,action:k(l,void 0),examples:[],failure_hints:[],arguments:[],flags:m,tier:"standard",family:"extensions"})}return a}function V(e){const t=e.variadic?"...":"";return e.required?`<${e.name}${t}>`:`[${e.name}${t}]`}function fn(e,t){for(const n of t.arguments)e.argument(V(n),n.description??"Extension argument.")}function G(e){if(h(e.visible)===!1)return null;const n=p(e.long),o=g(e.short),i=o&&o.startsWith("-")&&!o.startsWith("--")?o:null,r=n&&n.startsWith("--")&&n.length>2?n:null,s=[i,r].filter(a=>a!==null);return s.length>0?s:null}function C(e){const t=G(e);if(!t)return null;const{value_name:n,value_arity:o}=_(e),r=n?o==="optional"?` [${n}]`:` <${n}>`:"";return`${t.join(", ")}${r}`}function J(e){return C(e)}function E(e){const t=g(e.description)??"Extension-provided option.",n=[];h(e.required)===!0&&n.push("required"),h(e.enabled)===!1&&n.push("disabled");const o=n.length>0?` [${n.join(", ")}]`:"",i=e.default!==void 0?` (default: ${JSON.stringify(e.default)})`:"";return`${t}${o}${i}`}function A(e,t){const n=p(t.long),o=g(t.short);return e.options.some(i=>{const r=i;return n!==null&&r.long===n||o!==null&&r.short===o})}function dn(e,t){for(const n of t){if(A(e,n))continue;const o=J(n);if(!o)continue;const i=E(n),r=new D(o,i);if(r.negate=!1,n.list!==!0){e.addOption(r);continue}e.addOption(r.argParser((s,a=[])=>[...Array.isArray(a)?a:[a],s??!0]))}}function pn(e,t){return $(t.filter(n=>!A(e,n)))}function K(e){const t=C(e);if(!t)return null;const n=p(e.long),o=g(e.short),i=n&&n.startsWith("--")&&n.length>2?n:null,r=o&&o.startsWith("-")&&!o.startsWith("--")?o:null,s=_(e),a=h(e.required)===!0;return{flags:t,long:i,short:r,description:E(e),takes_value:s.value_arity!=="none",value_required:s.value_arity==="required",value_name:s.value_name,variadic:!1,required:a,aliases:[],alias_for:null,...e.default!==void 0?{default_value:e.default}:{},owner:"extension",...Q(q(e))}}function Q(e){return e===null?{}:{sdk_option:e}}function O(e,t){return W(e,t).map(n=>({flags:`${n.short===void 0?"":`${n.short}, `}${n.takes_value?`${n.flag} <${n.value_name}>`:n.flag}`,long:n.flag,short:n.short??null,description:n.description,takes_value:n.takes_value,value_required:n.value_required,value_name:n.takes_value?n.value_name:null,variadic:!1,required:!1,aliases:[...n.aliases??[]],alias_for:null,owner:"host"}))}function U(e){return O(e.command,j({readOutput:e.read_output_declared===!0}))}function gn(e,t){const n=t.flatMap(o=>[o.long,o.short,...o.aliases].filter(i=>typeof i=="string"));return O(e,L(e,n,{expectHashAdmissible:N(H(e))}))}function hn(e){return["","Inherited host flags (delivered through context.global):",` ${U(e).map(n=>n.flags).join(" | ")}`,` Run pm contracts --command ${e.command} --flags-only --json for each flag's owner and sdk_option key.`].join(`
5
+ `)}function xn(e){if(!e)return[];const t=[],n=new Set;for(const o of e.flags){const i=K(o);!i||n.has(i.flags)||(n.add(i.flags),t.push(i))}return t}function yn(e,t){if(t.length===0)return e;const n=new Map(e.map(o=>[o.flags,o]));for(const o of t){const i=n.get(o.flags);n.set(o.flags,i?{...i,...o.default_value!==void 0?{default_value:o.default_value}:{},...o.owner===void 0?{}:{owner:o.owner},...o.sdk_option===void 0?{}:{sdk_option:o.sdk_option}}:o)}return[...n.values()]}function _n(e){const t=[];if(e.intent&&t.push(`Intent: ${e.intent}`),e.action&&t.push(`Action contract: ${e.action}`),e.examples.length>0){t.push("Examples:");for(const n of e.examples)t.push(` - ${n}`)}if(e.failure_hints.length>0){t.push("Common failure hints:");for(const n of e.failure_hints)t.push(` - ${n}`)}return t.length===0?null:`
6
6
  Extension command metadata:
7
- ${n.join(`
8
- `)}`}function J(t){const n=t;if(typeof n.aliases=="function")return n.aliases().map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);if(typeof n.alias=="function"){const e=n.alias();if(typeof e=="string"&&e.trim().length>0)return[e.trim().toLowerCase()]}return Array.isArray(n._aliases)?n._aliases.map(e=>e.trim().toLowerCase()).filter(e=>e.length>0):[]}function v(t,n){const e=n.trim().toLowerCase();return t.commands.find(o=>o.name().trim().toLowerCase()===e?!0:J(o).includes(e))??null}function A(t,n){let e=t;for(const o of n){const i=v(e,o);if(!i)return null;e=i}return e}const x=new WeakSet;function pn(t){return x.has(t)}function gn(t,n){if(n.length===0)return null;let e=t;for(let o=0;o<n.length;o+=1){const i=n[o];o>0&&d.some(s=>s.canonical===n.join(" "))&&e.enablePositionalOptions();const r=v(e,i);if(r){e=r;continue}const a=e.command(i);x.add(a),o<n.length-1?(a.description("Extension-provided command group."),a.action(()=>{a.help()})):a.description("Extension-provided command path."),e=a}return e}function K(t,n){const e=n.join(" "),o=d.find(a=>e===a.canonical||e.startsWith(`${a.canonical} `));if(o)return{core_path:o.canonical,extension_path:e};let i=t;const r=[];for(const a of n){const s=v(i,a);if(!s)return null;r.push(a);const u=s.commands.length>0||d.some(l=>l.canonical.startsWith(`${r.join(" ")} `));if(!x.has(s)&&(r.length===n.length||!u))return{core_path:r.join(" "),extension_path:n.join(" ")};i=s}return null}function Q(t,n,e,o,i=!1){const r=n.split(" ").filter(c=>c.length>0),a=K(t,r),s=A(t,r),u=d.some(c=>c.canonical===n&&c.alias===o?.action&&!t.commands.some(m=>m.name()===c.alias)&&(s===null||x.has(s)));if(!a||a.core_path===n&&s!==null&&!e.has(n)&&!i||u&&!e.has(n))return null;const l=o?.source?.package??o?.source?.name??"unknown-extension";return`extension_command_collision:${a.extension_path}:core_owner=pm-cli:${a.core_path}:extension_owner=${l}`}function hn(t,n,e,o,i){return[...new Set([...n,...e.keys()])].filter(r=>r.trim().length>0).sort((r,a)=>r.localeCompare(a)).filter(r=>{const a=Q(t,r,o,e.get(r),n.includes(r));return a?(i(a),!o.has(r)&&A(t,r.split(" "))!==null):!0})}function xn(t,n,e){t.push(e),n(`[pm] warning: ${e}; core command preserved. Rename or namespace the extension command alias.`)}export{sn as applyDynamicExtensionArguments,ln as applyDynamicExtensionFlagOptions,tn as buildCanonicalExtensionAliases,dn as buildDynamicExtensionCommandMetadataHelp,mn as buildDynamicExtensionHelpOptionSummaries,Q as buildExtensionCommandCollisionWarning,un as buildExtensionInheritedFlagHelp,G as buildExtensionInheritedHelpOptionSummaries,cn as buildResidualDynamicExtensionFlagHelp,rn as collectDynamicExtensionFlagHelpByCommand,an as collectExtensionCommandHelpDescriptors,hn as collectSafeExtensionCommandPaths,J as commandAliases,gn as ensureCommandPath,on as extensionFlagTakesValueForInvocation,A as findCommandByPath,v as findDirectChildCommand,K as findExtensionCommandPathCollision,pn as isExtensionCreatedCommand,fn as mergeHelpOptionSummaries,f as normalizeExtensionCommandPath,xn as reportExtensionCommandCollision,j as resolveExtensionFlagArity};
7
+ ${t.join(`
8
+ `)}`}function X(e){const t=e;if(typeof t.aliases=="function")return t.aliases().map(n=>n.trim().toLowerCase()).filter(n=>n.length>0);if(typeof t.alias=="function"){const n=t.alias();if(typeof n=="string"&&n.trim().length>0)return[n.trim().toLowerCase()]}return Array.isArray(t._aliases)?t._aliases.map(n=>n.trim().toLowerCase()).filter(n=>n.length>0):[]}function v(e,t){const n=t.trim().toLowerCase();return e.commands.find(o=>o.name().trim().toLowerCase()===n?!0:X(o).includes(n))??null}function b(e,t){let n=e;for(const o of t){const i=v(n,o);if(!i)return null;n=i}return n}const x=new WeakSet;function Cn(e){return x.has(e)}function En(e,t){if(t.length===0)return null;let n=e;for(let o=0;o<t.length;o+=1){const i=t[o];o>0&&d.some(a=>a.canonical===t.join(" "))&&n.enablePositionalOptions();const r=v(n,i);if(r){n=r;continue}const s=n.command(i);x.add(s),o<t.length-1?(s.description("Extension-provided command group."),s.action(()=>{s.help()})):s.description("Extension-provided command path."),n=s}return n}function Y(e,t){const n=t.join(" "),o=d.find(s=>n===s.canonical||n.startsWith(`${s.canonical} `));if(o)return{core_path:o.canonical,extension_path:n};let i=e;const r=[];for(const s of t){const a=v(i,s);if(!a)return null;r.push(s);const u=a.commands.length>0||d.some(l=>l.canonical.startsWith(`${r.join(" ")} `));if(!x.has(a)&&(r.length===t.length||!u))return{core_path:r.join(" "),extension_path:t.join(" ")};i=a}return null}function Z(e,t,n,o,i=!1){const r=t.split(" ").filter(c=>c.length>0),s=Y(e,r),a=b(e,r),u=d.some(c=>c.canonical===t&&c.alias===o?.action&&!e.commands.some(m=>m.name()===c.alias)&&(a===null||x.has(a)));if(!s||s.core_path===t&&a!==null&&!n.has(t)&&!i||u&&!n.has(t))return null;const l=o?.source?.package??o?.source?.name??"unknown-extension";return`extension_command_collision:${s.extension_path}:core_owner=pm-cli:${s.core_path}:extension_owner=${l}`}function vn(e,t,n,o,i){return[...new Set([...t,...n.keys()])].filter(r=>r.trim().length>0).sort((r,s)=>r.localeCompare(s)).filter(r=>{const s=Z(e,r,o,n.get(r),t.includes(r));return s?(i(s),!o.has(r)&&b(e,r.split(" "))!==null):!0})}function $n(e,t,n){e.push(n),t(`[pm] warning: ${n}; core command preserved. Rename or namespace the extension command alias.`)}export{fn as applyDynamicExtensionArguments,dn as applyDynamicExtensionFlagOptions,ln as buildCanonicalExtensionAliases,gn as buildCoreInheritedHelpOptionSummaries,_n as buildDynamicExtensionCommandMetadataHelp,xn as buildDynamicExtensionHelpOptionSummaries,Z as buildExtensionCommandCollisionWarning,hn as buildExtensionInheritedFlagHelp,U as buildExtensionInheritedHelpOptionSummaries,pn as buildResidualDynamicExtensionFlagHelp,un as collectDynamicExtensionFlagHelpByCommand,mn as collectExtensionCommandHelpDescriptors,vn as collectSafeExtensionCommandPaths,X as commandAliases,En as ensureCommandPath,cn as extensionFlagTakesValueForInvocation,b as findCommandByPath,v as findDirectChildCommand,Y as findExtensionCommandPathCollision,Cn as isExtensionCreatedCommand,yn as mergeHelpOptionSummaries,f as normalizeExtensionCommandPath,$n as reportExtensionCommandCollision,z as resolveExtensionFlagArity};
9
9
  //# sourceMappingURL=extension-command-help.js.map