@unbrained/pm-cli 2026.8.6 → 2026.8.8

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 (269) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +65 -0
  3. package/dist/cli/main.js +6 -3
  4. package/dist/cli/register-annotations.d.ts +11 -0
  5. package/dist/cli/register-annotations.js +195 -0
  6. package/dist/cli/register-history-author.js +7 -30
  7. package/dist/cli/register-mutation.js +25 -206
  8. package/dist/cli/register-operations.js +11 -2
  9. package/dist/cli/runtime-compatibility-boundary.d.ts +17 -0
  10. package/dist/cli/runtime-compatibility-boundary.js +43 -0
  11. package/dist/cli/stats-analytics-json.d.ts +9 -0
  12. package/dist/cli/stats-analytics-json.js +69 -0
  13. package/dist/cli-bundle/bundle-manifest.json +156 -692
  14. package/dist/cli-bundle/chunks/chunk-2ZMXX3Q6.js +2068 -0
  15. package/dist/cli-bundle/chunks/chunk-ALDHXLPS.js +3 -0
  16. package/dist/cli-bundle/chunks/chunk-CBLA33YK.js +8 -0
  17. package/dist/cli-bundle/chunks/chunk-GKA54IJM.js +5 -0
  18. package/dist/cli-bundle/chunks/chunk-KRY7SRUO.js +2 -0
  19. package/dist/cli-bundle/chunks/chunk-MNJ4NNSY.js +26 -0
  20. package/dist/cli-bundle/chunks/chunk-NUXRRNAB.js +77 -0
  21. package/dist/cli-bundle/chunks/chunk-OJPCFDDY.js +13 -0
  22. package/dist/cli-bundle/chunks/chunk-PFSD3DAN.js +194 -0
  23. package/dist/cli-bundle/chunks/chunk-QWRRFYK3.js +2 -0
  24. package/dist/cli-bundle/chunks/chunk-SQ7QZFQ6.js +2 -0
  25. package/dist/cli-bundle/chunks/{register-list-query-QH7ONPKU.js → register-list-query-WFZAMJHZ.js} +8 -8
  26. package/dist/cli-bundle/chunks/register-mutation-SOKKOTHQ.js +20 -0
  27. package/dist/cli-bundle/chunks/register-operations-5XQETS6E.js +2 -0
  28. package/dist/cli-bundle/chunks/register-setup-2HL5ZHMK.js +2 -0
  29. package/dist/cli-bundle/focused-chunks/chunk-54EU2UVO.js +2 -0
  30. package/dist/cli-bundle/focused-chunks/{chunk-N7QN3NE6.js → chunk-5FLBTZJQ.js} +2 -2
  31. package/dist/cli-bundle/focused-chunks/chunk-5GJ57YKN.js +2 -0
  32. package/dist/cli-bundle/focused-chunks/{chunk-YLPZHWX7.js → chunk-ANTMGYLI.js} +2 -2
  33. package/dist/cli-bundle/focused-chunks/chunk-CMDS3KYT.js +14 -0
  34. package/dist/cli-bundle/focused-chunks/{chunk-EYO4F74Z.js → chunk-DMKOMTTY.js} +2 -2
  35. package/dist/cli-bundle/focused-chunks/{chunk-GSW2Y7VZ.js → chunk-F5B3HBEZ.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/{chunk-27DK4A5O.js → chunk-FI6DWU2M.js} +2 -2
  37. package/dist/cli-bundle/focused-chunks/{chunk-CL3NB7VW.js → chunk-FNOKJG6N.js} +2 -2
  38. package/dist/cli-bundle/focused-chunks/{chunk-EAXXF2HW.js → chunk-FPDYXZBK.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/{chunk-XNVXIQ4B.js → chunk-GWI6YIKJ.js} +2 -2
  40. package/dist/cli-bundle/focused-chunks/{chunk-6KDHXURF.js → chunk-HCUC62AB.js} +2 -2
  41. package/dist/cli-bundle/focused-chunks/{chunk-GEYU23YS.js → chunk-HGNKPSCB.js} +22 -22
  42. package/dist/cli-bundle/focused-chunks/chunk-IAS7PMLG.js +2 -0
  43. package/dist/cli-bundle/focused-chunks/{chunk-TQMFQYXR.js → chunk-PL2EYDJK.js} +29 -29
  44. package/dist/cli-bundle/focused-chunks/chunk-SM2PJGP3.js +2 -0
  45. package/dist/cli-bundle/focused-chunks/{chunk-4JC3AOGS.js → chunk-TCSAPH33.js} +2 -2
  46. package/dist/cli-bundle/focused-chunks/chunk-U646T7Z6.js +18 -0
  47. package/dist/cli-bundle/focused-chunks/chunk-YKPE4PPY.js +2 -0
  48. package/dist/cli-bundle/focused-chunks/{chunk-GIERI4YU.js → chunk-YSAHYUXX.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/chunk-ZOLDTUU7.js +2 -0
  50. package/dist/cli-bundle/main.js +13 -13
  51. package/dist/cli-bundle/sdk-authoring.js +1 -1
  52. package/dist/cli-bundle/sdk-contracts.js +1 -1
  53. package/dist/cli-bundle/sdk-core.js +38 -37
  54. package/dist/cli-bundle/sdk-governance.js +1 -1
  55. package/dist/cli-bundle/sdk-graph.js +1 -1
  56. package/dist/cli-bundle/sdk-merge.js +1 -1
  57. package/dist/cli-bundle/sdk-query.js +1 -1
  58. package/dist/cli-bundle/sdk-runtime.js +1 -1
  59. package/dist/cli-bundle/sdk-testing.js +1 -1
  60. package/dist/cli-bundle/sdk.js +2 -1
  61. package/dist/cli.js +14 -4
  62. package/dist/core/extensions/reserved-host-flags.js +3 -2
  63. package/dist/core/history/workspace-history.d.ts +22 -2
  64. package/dist/core/history/workspace-history.js +60 -36
  65. package/dist/core/output/output.d.ts +2 -0
  66. package/dist/core/output/output.js +10 -2
  67. package/dist/core/sentry/helpers.d.ts +10 -0
  68. package/dist/core/sentry/helpers.js +59 -4
  69. package/dist/core/shared/command-types.d.ts +2 -0
  70. package/dist/core/shared/command-types.js +2 -2
  71. package/dist/core/shared/constants.d.ts +2 -0
  72. package/dist/core/shared/constants.js +4 -2
  73. package/dist/mcp/tool-definitions.js +6 -2
  74. package/dist/sdk/annotations.d.ts +40 -0
  75. package/dist/sdk/annotations.js +61 -9
  76. package/dist/sdk/author-attribution.d.ts +12 -0
  77. package/dist/sdk/author-attribution.js +87 -9
  78. package/dist/sdk/cli-bootstrap.d.ts +2 -0
  79. package/dist/sdk/cli-bootstrap.js +7 -2
  80. package/dist/sdk/cli-contracts/command-exit-contracts.d.ts +118 -0
  81. package/dist/sdk/cli-contracts/command-exit-contracts.js +152 -0
  82. package/dist/sdk/cli-contracts/completeness.js +54 -5
  83. package/dist/sdk/cli-contracts/flag-contracts.js +6 -2
  84. package/dist/sdk/cli-contracts/registration-helpers.js +3 -2
  85. package/dist/sdk/cli-contracts/runtime-contracts.d.ts +11 -0
  86. package/dist/sdk/cli-contracts/runtime-contracts.js +41 -8
  87. package/dist/sdk/cli-contracts/tool-parameter-tables.js +129 -10
  88. package/dist/sdk/cli-contracts/tool-schema.d.ts +1 -1
  89. package/dist/sdk/cli-contracts/tool-schema.js +22 -3
  90. package/dist/sdk/cli-program.js +3 -2
  91. package/dist/sdk/comments.d.ts +7 -0
  92. package/dist/sdk/comments.js +2 -2
  93. package/dist/sdk/completion.js +12 -5
  94. package/dist/sdk/contracts.d.ts +2 -0
  95. package/dist/sdk/contracts.js +3 -2
  96. package/dist/sdk/core.d.ts +3 -1
  97. package/dist/sdk/core.js +4 -3
  98. package/dist/sdk/environment/host-environment-errors.d.ts +27 -0
  99. package/dist/sdk/environment/host-environment-errors.js +124 -0
  100. package/dist/sdk/environment/project-runtime-compatibility.d.ts +65 -0
  101. package/dist/sdk/environment/project-runtime-compatibility.js +385 -0
  102. package/dist/sdk/environment/source-context.d.ts +23 -0
  103. package/dist/sdk/environment/source-context.js +29 -0
  104. package/dist/sdk/error-code-catalog.d.ts +6 -0
  105. package/dist/sdk/error-code-catalog.js +62 -8
  106. package/dist/sdk/extension.js +9 -11
  107. package/dist/sdk/generated-error-code-catalog.js +739 -3
  108. package/dist/sdk/governance/health.d.ts +11 -3
  109. package/dist/sdk/governance/health.js +5 -5
  110. package/dist/sdk/history-analytics.d.ts +141 -0
  111. package/dist/sdk/history-analytics.js +283 -0
  112. package/dist/sdk/improvement-ledger-validation.d.ts +3 -0
  113. package/dist/sdk/improvement-ledger-validation.js +63 -0
  114. package/dist/sdk/improvement-ledger.d.ts +139 -0
  115. package/dist/sdk/improvement-ledger.js +261 -0
  116. package/dist/sdk/index.d.ts +13 -5
  117. package/dist/sdk/index.js +15 -7
  118. package/dist/sdk/learnings.d.ts +15 -0
  119. package/dist/sdk/learnings.js +2 -2
  120. package/dist/sdk/lifecycle/close-many.d.ts +6 -1
  121. package/dist/sdk/lifecycle/close-many.js +43 -5
  122. package/dist/sdk/lifecycle/plan.js +6 -3
  123. package/dist/sdk/lifecycle/update-many.d.ts +2 -1
  124. package/dist/sdk/lifecycle/update-many.js +29 -5
  125. package/dist/sdk/merge/index.d.ts +1 -1
  126. package/dist/sdk/merge/index.js +3 -3
  127. package/dist/sdk/merge/install.d.ts +21 -0
  128. package/dist/sdk/merge/install.js +58 -20
  129. package/dist/sdk/notes.d.ts +7 -0
  130. package/dist/sdk/notes.js +2 -2
  131. package/dist/sdk/read-output-budget.js +24 -22
  132. package/dist/sdk/read-output-contracts.d.ts +10 -2
  133. package/dist/sdk/read-output-contracts.js +204 -66
  134. package/dist/sdk/read-output-rows.d.ts +29 -0
  135. package/dist/sdk/read-output-rows.js +100 -0
  136. package/dist/sdk/read-output-session.d.ts +69 -0
  137. package/dist/sdk/read-output-session.js +200 -0
  138. package/dist/sdk/runtime-input.d.ts +2 -0
  139. package/dist/sdk/runtime-input.js +14 -2
  140. package/dist/sdk/runtime-primitives.d.ts +1 -1
  141. package/dist/sdk/runtime-primitives.js +3 -3
  142. package/dist/sdk/runtime-stats-options.d.ts +9 -0
  143. package/dist/sdk/runtime-stats-options.js +38 -0
  144. package/dist/sdk/runtime.d.ts +1 -0
  145. package/dist/sdk/runtime.js +13 -50
  146. package/dist/sdk/stats.d.ts +40 -0
  147. package/dist/sdk/stats.js +112 -29
  148. package/dist/sdk/test/execution.js +4 -2
  149. package/dist/sdk/test/parsers.js +5 -2
  150. package/dist/sdk/workspace-snapshot.d.ts +9 -0
  151. package/dist/sdk/workspace-snapshot.js +48 -16
  152. package/docs/AGENT_RUNTIME_PRIMITIVES.md +11 -4
  153. package/docs/IMPROVEMENT_ANALYTICS.md +103 -0
  154. package/docs/OUTPUT_PROJECTION_CONTRACTS.md +5 -5
  155. package/docs/README.md +2 -0
  156. package/docs/READ_OUTPUT_CONTRACTS.md +60 -1
  157. package/docs/RELEASING.md +27 -2
  158. package/docs/SCRIPTING.md +27 -1
  159. package/docs/SDK_CONTEXT_INTEGRITY.md +66 -0
  160. package/docs/SDK_RUNTIME_BOUNDARIES.md +58 -0
  161. package/docs/SELF_DESCRIBING_CONTEXT_CONTRACTS.md +13 -0
  162. package/docs/TESTING.md +17 -0
  163. package/marketplace.json +2 -2
  164. package/package.json +6 -4
  165. package/packages/pm-beads/package.json +1 -1
  166. package/packages/pm-calendar/package.json +1 -1
  167. package/packages/pm-command-kit/package.json +1 -1
  168. package/packages/pm-digital-twin/package.json +1 -1
  169. package/packages/pm-governance-audit/package.json +1 -1
  170. package/packages/pm-guide-shell/package.json +1 -1
  171. package/packages/pm-kanban/package.json +1 -1
  172. package/packages/pm-lifecycle-hooks/package.json +1 -1
  173. package/packages/pm-linked-test-adapters/package.json +1 -1
  174. package/packages/pm-search-advanced/package.json +1 -1
  175. package/packages/pm-templates/package.json +1 -1
  176. package/packages/pm-todos/package.json +1 -1
  177. package/packages/pm-vcs/package.json +1 -1
  178. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  179. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  180. package/sdk/public-surface.json +875 -827
  181. package/dist/cli-bundle/chunks/append-XAJ5Z4XS.js +0 -2
  182. package/dist/cli-bundle/chunks/chunk-343QETLI.js +0 -2
  183. package/dist/cli-bundle/chunks/chunk-3KFVGGRE.js +0 -2
  184. package/dist/cli-bundle/chunks/chunk-3ZJRFYY2.js +0 -23
  185. package/dist/cli-bundle/chunks/chunk-4AVFKHHC.js +0 -2
  186. package/dist/cli-bundle/chunks/chunk-4OVGQW22.js +0 -2
  187. package/dist/cli-bundle/chunks/chunk-5PBP2ZP3.js +0 -2
  188. package/dist/cli-bundle/chunks/chunk-5ZKQPA44.js +0 -2
  189. package/dist/cli-bundle/chunks/chunk-A3XQ7VPU.js +0 -2
  190. package/dist/cli-bundle/chunks/chunk-A6KGKEWT.js +0 -2
  191. package/dist/cli-bundle/chunks/chunk-AJE3AHPD.js +0 -8
  192. package/dist/cli-bundle/chunks/chunk-AOBDLU4T.js +0 -2
  193. package/dist/cli-bundle/chunks/chunk-AYRUGRNS.js +0 -3
  194. package/dist/cli-bundle/chunks/chunk-BP6EMEDP.js +0 -5
  195. package/dist/cli-bundle/chunks/chunk-BXCSXK4J.js +0 -2
  196. package/dist/cli-bundle/chunks/chunk-C3YABSJK.js +0 -2
  197. package/dist/cli-bundle/chunks/chunk-CA3BURYF.js +0 -2
  198. package/dist/cli-bundle/chunks/chunk-CHOQ2VAW.js +0 -2
  199. package/dist/cli-bundle/chunks/chunk-D7I3TUGV.js +0 -2
  200. package/dist/cli-bundle/chunks/chunk-DQGJ2RWT.js +0 -3
  201. package/dist/cli-bundle/chunks/chunk-DWOAOZHZ.js +0 -2
  202. package/dist/cli-bundle/chunks/chunk-E2ZSLTOP.js +0 -2
  203. package/dist/cli-bundle/chunks/chunk-E7BFPLUZ.js +0 -5
  204. package/dist/cli-bundle/chunks/chunk-F4NREH3G.js +0 -2
  205. package/dist/cli-bundle/chunks/chunk-FB7G2HY2.js +0 -2
  206. package/dist/cli-bundle/chunks/chunk-FDBRXV25.js +0 -2
  207. package/dist/cli-bundle/chunks/chunk-GU3TSEHD.js +0 -2
  208. package/dist/cli-bundle/chunks/chunk-HS7OVAUN.js +0 -164
  209. package/dist/cli-bundle/chunks/chunk-JC6FKIFM.js +0 -2
  210. package/dist/cli-bundle/chunks/chunk-JFZIS6JF.js +0 -2
  211. package/dist/cli-bundle/chunks/chunk-JQ4NZ5EB.js +0 -2
  212. package/dist/cli-bundle/chunks/chunk-L6LGKJX3.js +0 -2
  213. package/dist/cli-bundle/chunks/chunk-LEPJJ6QC.js +0 -2
  214. package/dist/cli-bundle/chunks/chunk-M357ZCOR.js +0 -2
  215. package/dist/cli-bundle/chunks/chunk-M4VEE3FK.js +0 -2
  216. package/dist/cli-bundle/chunks/chunk-MCS73BKB.js +0 -3
  217. package/dist/cli-bundle/chunks/chunk-MDTH7SAE.js +0 -19
  218. package/dist/cli-bundle/chunks/chunk-NE5VRDAI.js +0 -2
  219. package/dist/cli-bundle/chunks/chunk-OXY3SJ3N.js +0 -2
  220. package/dist/cli-bundle/chunks/chunk-PECV7L5T.js +0 -2
  221. package/dist/cli-bundle/chunks/chunk-Q3VOP62W.js +0 -2
  222. package/dist/cli-bundle/chunks/chunk-QJ7C3JIW.js +0 -2
  223. package/dist/cli-bundle/chunks/chunk-R6LSRGPS.js +0 -8
  224. package/dist/cli-bundle/chunks/chunk-R6RKEYYW.js +0 -2
  225. package/dist/cli-bundle/chunks/chunk-RAFUN7IX.js +0 -2005
  226. package/dist/cli-bundle/chunks/chunk-RSIC5OPE.js +0 -2
  227. package/dist/cli-bundle/chunks/chunk-RUAU5OSH.js +0 -2
  228. package/dist/cli-bundle/chunks/chunk-SD3YXU2U.js +0 -56
  229. package/dist/cli-bundle/chunks/chunk-SV3YQ4RY.js +0 -2
  230. package/dist/cli-bundle/chunks/chunk-SVV3DQES.js +0 -2
  231. package/dist/cli-bundle/chunks/chunk-SXECIECW.js +0 -5
  232. package/dist/cli-bundle/chunks/chunk-T45OHXDW.js +0 -8
  233. package/dist/cli-bundle/chunks/chunk-TPKDJ5WL.js +0 -2
  234. package/dist/cli-bundle/chunks/chunk-UVVXHGYS.js +0 -3
  235. package/dist/cli-bundle/chunks/chunk-V663653R.js +0 -20
  236. package/dist/cli-bundle/chunks/chunk-WSI5KZQJ.js +0 -55
  237. package/dist/cli-bundle/chunks/chunk-XPOQQJTX.js +0 -13
  238. package/dist/cli-bundle/chunks/chunk-YCCDXBNU.js +0 -2
  239. package/dist/cli-bundle/chunks/chunk-ZFBWCKYF.js +0 -2
  240. package/dist/cli-bundle/chunks/close-DI66JMSB.js +0 -2
  241. package/dist/cli-bundle/chunks/close-many-VFKT6U3O.js +0 -2
  242. package/dist/cli-bundle/chunks/comments-E73HIEZJ.js +0 -2
  243. package/dist/cli-bundle/chunks/copy-WBYVLCPC.js +0 -2
  244. package/dist/cli-bundle/chunks/create-TG67IVFI.js +0 -2
  245. package/dist/cli-bundle/chunks/delete-6XKUVVQN.js +0 -2
  246. package/dist/cli-bundle/chunks/deps-AJUGP2OH.js +0 -2
  247. package/dist/cli-bundle/chunks/docs-QOCLDRKJ.js +0 -2
  248. package/dist/cli-bundle/chunks/files-3ST5TY64.js +0 -2
  249. package/dist/cli-bundle/chunks/focus-R2AWS63Y.js +0 -2
  250. package/dist/cli-bundle/chunks/history-compact-7BJFML4S.js +0 -2
  251. package/dist/cli-bundle/chunks/history-redact-WJN3HYXR.js +0 -2
  252. package/dist/cli-bundle/chunks/history-repair-XDNZUB7F.js +0 -2
  253. package/dist/cli-bundle/chunks/learnings-SZMUPVNA.js +0 -2
  254. package/dist/cli-bundle/chunks/profile-KL53JIAC.js +0 -2
  255. package/dist/cli-bundle/chunks/register-mutation-OCRQNZK4.js +0 -20
  256. package/dist/cli-bundle/chunks/register-operations-HIBJXRGB.js +0 -2
  257. package/dist/cli-bundle/chunks/register-setup-QWBQ6HBS.js +0 -2
  258. package/dist/cli-bundle/chunks/restore-FXA5QPM7.js +0 -2
  259. package/dist/cli-bundle/chunks/schema-QJ27OTRV.js +0 -2
  260. package/dist/cli-bundle/chunks/update-7GBO4SXG.js +0 -2
  261. package/dist/cli-bundle/chunks/update-many-VF6ZKQUO.js +0 -2
  262. package/dist/cli-bundle/focused-chunks/chunk-74CWP3A4.js +0 -2
  263. package/dist/cli-bundle/focused-chunks/chunk-7AZDTGPA.js +0 -2
  264. package/dist/cli-bundle/focused-chunks/chunk-7YTZ7A4E.js +0 -2
  265. package/dist/cli-bundle/focused-chunks/chunk-LKQXXO62.js +0 -2
  266. package/dist/cli-bundle/focused-chunks/chunk-MBBMTDD3.js +0 -12
  267. package/dist/cli-bundle/focused-chunks/chunk-ME4XVOBJ.js +0 -8
  268. package/dist/cli-bundle/focused-chunks/chunk-QL5H3AQH.js +0 -2
  269. package/dist/cli-bundle/focused-chunks/chunk-YHDCGUIW.js +0 -14
@@ -4,8 +4,9 @@
4
4
  * Exposes command and action contract data without loading SDK runtime code.
5
5
  */
6
6
 
7
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2962656f-386f-59a0-8dc1-411ae382dddb")}catch(e){}}();
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="65e53d90-6fff-59df-bdfc-0d2387b5a28d")}catch(e){}}();
8
8
  export * from "./cli-contracts.js";
9
+ export * from "./cli-contracts/command-exit-contracts.js";
9
10
  export * from "./context-intent-contracts.js";
10
11
  export * from "./error-code-catalog.js";
11
12
  export * from "./generated-error-code-catalog.js";
@@ -14,4 +15,4 @@ export * from "./output-token-accounting.js";
14
15
  export * from "./output-contracts.js";
15
16
  export * from "./read-output-contracts.js";
16
17
  //# sourceMappingURL=contracts.js.map
17
- //# debugId=2962656f-386f-59a0-8dc1-411ae382dddb
18
+ //# debugId=65e53d90-6fff-59df-bdfc-0d2387b5a28d
@@ -6,6 +6,8 @@
6
6
  export { BASELINE_ITEM_FORMAT_VERSION, BUILTIN_ITEM_TYPE_VALUES, CONFIDENCE_TEXT_VALUES, CURRENT_ITEM_FORMAT_VERSION, DEPENDENCY_KIND_VALUES, EXIT_CODE, ISSUE_SEVERITY_VALUES, ITEM_TYPE_VALUES, PM_CLI_EXPECTED_ERROR_NAME, PmCliError, PmClient, RISK_VALUES, STATUS_VALUES, canonicalDocument, classifyItemFormatVersion, createPmCliExpectedError, effectiveItemFormatVersion, emptyImportedDocument, isPmCliExpectedError, normalizeItemFormatVersion, normalizeItemId, normalizeStatusInput, nowIso, runAction, serializeItemDocument, aggregate, append, claim, claimNext, close, comments, context, copy, create, deleteItem, deps, docs, files, filesDiscover, focus, get, graph, learnings, list, next, notes, release, restore, search, update, type AggregateOptions, type AggregateResult, type AggregateRow, type AppendCommandOptions, type AppendResult, type ClaimNextOptions, type ClaimResult, type CloseResult, type CommentsCommandOptions, type CommentsResult, type ContextOptions, type ContextResult, type CopyResult, type CreateResult, type Dependency, type DeleteResult, type DepsCommandOptions, type DepsResult, type DocsCommandOptions, type DocsResult, type FilesCommandOptions, type FilesDiscoverOptions, type FilesDiscoverResult, type FilesResult, type FocusResult, type GetOptions, type GetResult, type ItemFormatVersionScanEntry, type ItemFormatVersionScanResult, type ItemFormatVersionStatus, type LearningsCommandOptions, type LearningsResult, type ListOptions, type ListResult, type NextOptions, type NextResult, type NotesCommandOptions, type NotesResult, type PmActionInput, type PmActionName, type PmActionOptions, type PmClientOptions, type ReleaseResult, type RestoreResult, type SearchOptions, type SearchResult, type UpdateResult, } from "./runtime.js";
7
7
  export * from "./core-governance.js";
8
8
  export * from "./agent-session-context.js";
9
- export { PM_READ_OUTPUT_DIMENSIONS, PM_READ_OUTPUT_OPTION_FLAGS, PM_READ_OUTPUT_SURFACE_CONTRACTS, applyReadOutputDimensions, isReadOutputBudgetExceeded, resolveReadOutputDimensions, resolveReadOutputEncoding, resolveReadOutputSurface, validateReadOutputOptions, } from "./read-output-contracts.js";
9
+ export { PM_READ_OUTPUT_DIMENSIONS, PM_READ_OUTPUT_OPTION_FLAGS, PM_READ_OUTPUT_COMPOSITION_OPTION_FLAGS, PM_READ_OUTPUT_SURFACE_CONTRACTS, applyReadOutputDimensions, isReadOutputBudgetExceeded, resolveReadOutputDimensions, resolveReadOutputEncoding, resolveReadOutputSurface, validateReadOutputOptions, } from "./read-output-contracts.js";
10
+ export { applyReadOutputSessionReferences, attachReadOutputSessionReceipt, parseReadOutputSession, readOutputSessionRemainingTokens, } from "./read-output-session.js";
10
11
  export type { PmReadOutputBudgetExceeded, PmReadOutputDimension, PmReadOutputLegacyAlias, PmReadOutputOptions, PmReadOutputReceipt, PmReadOutputResult, PmReadOutputResultFor, PmReadOutputSurface, PmReadOutputSurfaceContract, } from "./read-output-contracts.js";
12
+ export type { PmReadOutputSessionReceipt, PmReadOutputSessionReference, PmReadOutputSessionState, } from "./read-output-session.js";
11
13
  export type { ItemDocument, ItemMetadata, ItemStatus, ItemType, PmSettings, } from "../types/index.js";
package/dist/sdk/core.js CHANGED
@@ -4,10 +4,11 @@
4
4
  * Provides the stable item lifecycle client and universal project data types.
5
5
  */
6
6
 
7
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d70db3d9-b094-52fd-8f0f-47eed9f6e7f0")}catch(e){}}();
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="54d31df7-e708-585d-9fb2-3c5ddfcc6138")}catch(e){}}();
8
8
  export { BASELINE_ITEM_FORMAT_VERSION, BUILTIN_ITEM_TYPE_VALUES, CONFIDENCE_TEXT_VALUES, CURRENT_ITEM_FORMAT_VERSION, DEPENDENCY_KIND_VALUES, EXIT_CODE, ISSUE_SEVERITY_VALUES, ITEM_TYPE_VALUES, PM_CLI_EXPECTED_ERROR_NAME, PmCliError, PmClient, RISK_VALUES, STATUS_VALUES, canonicalDocument, classifyItemFormatVersion, createPmCliExpectedError, effectiveItemFormatVersion, emptyImportedDocument, isPmCliExpectedError, normalizeItemFormatVersion, normalizeItemId, normalizeStatusInput, nowIso, runAction, serializeItemDocument, aggregate, append, claim, claimNext, close, comments, context, copy, create, deleteItem, deps, docs, files, filesDiscover, focus, get, graph, learnings, list, next, notes, release, restore, search, update, } from "./runtime.js";
9
9
  export * from "./core-governance.js";
10
10
  export * from "./agent-session-context.js";
11
- export { PM_READ_OUTPUT_DIMENSIONS, PM_READ_OUTPUT_OPTION_FLAGS, PM_READ_OUTPUT_SURFACE_CONTRACTS, applyReadOutputDimensions, isReadOutputBudgetExceeded, resolveReadOutputDimensions, resolveReadOutputEncoding, resolveReadOutputSurface, validateReadOutputOptions, } from "./read-output-contracts.js";
11
+ export { PM_READ_OUTPUT_DIMENSIONS, PM_READ_OUTPUT_OPTION_FLAGS, PM_READ_OUTPUT_COMPOSITION_OPTION_FLAGS, PM_READ_OUTPUT_SURFACE_CONTRACTS, applyReadOutputDimensions, isReadOutputBudgetExceeded, resolveReadOutputDimensions, resolveReadOutputEncoding, resolveReadOutputSurface, validateReadOutputOptions, } from "./read-output-contracts.js";
12
+ export { applyReadOutputSessionReferences, attachReadOutputSessionReceipt, parseReadOutputSession, readOutputSessionRemainingTokens, } from "./read-output-session.js";
12
13
  //# sourceMappingURL=core.js.map
13
- //# debugId=d70db3d9-b094-52fd-8f0f-47eed9f6e7f0
14
+ //# debugId=54d31df7-e708-585d-9fb2-3c5ddfcc6138
@@ -0,0 +1,27 @@
1
+ import { PmCliError } from "../../core/shared/errors.js";
2
+ /** Optional stable codes used by an existing SDK surface for each fault class. */
3
+ export interface HostEnvironmentFaultCodeOverrides {
4
+ /** Code used for quota and storage exhaustion. */
5
+ capacity?: string;
6
+ /** Code used for access policy and read-only filesystems. */
7
+ permission?: string;
8
+ /** Code used for file-descriptor and memory exhaustion. */
9
+ resource?: string;
10
+ }
11
+ /** Context and compatibility controls for a host-environment boundary. */
12
+ export interface HostEnvironmentBoundaryOptions {
13
+ /** Existing surface-specific codes that must remain compatible. */
14
+ codes?: HostEnvironmentFaultCodeOverrides;
15
+ /** Human explanation of why the operation needs host resources. */
16
+ why?: string;
17
+ /** Additional ordered recovery guidance. */
18
+ nextSteps?: readonly string[];
19
+ /** Copyable retry command when one is safe. */
20
+ suggestedRetry?: string;
21
+ }
22
+ /** Return a declared host errno only when it represents recoverable environment state. */
23
+ export declare function classifyHostEnvironmentFault(error: unknown): string | null;
24
+ /** Translate one known host fault into a stable path-redacted SDK refusal. */
25
+ export declare function translateHostEnvironmentFault(error: unknown, operation: string, options?: HostEnvironmentBoundaryOptions): PmCliError | null;
26
+ /** Run one SDK filesystem stage and translate only declared host faults. */
27
+ export declare function withHostEnvironmentBoundary<T>(operation: string, run: () => Promise<T>, options?: HostEnvironmentBoundaryOptions): Promise<T>;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @module sdk/host-environment-errors
3
+ *
4
+ * Classifies host filesystem/resource failures at SDK boundaries without
5
+ * leaking local paths or swallowing genuine implementation defects.
6
+ */
7
+
8
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="41fec0f3-5cc8-5007-a896-f8d8b83ae4f5")}catch(e){}}();
9
+ import { EXIT_CODE } from "../../core/shared/constants.js";
10
+ import { PmCliError } from "../../core/shared/errors.js";
11
+ const HOST_ENVIRONMENT_FAULTS = new Map([
12
+ [
13
+ "EACCES",
14
+ {
15
+ summary: "was denied filesystem permission",
16
+ recovery: "Grant the required filesystem access, then retry.",
17
+ category: "permission",
18
+ },
19
+ ],
20
+ [
21
+ "EDQUOT",
22
+ {
23
+ summary: "exceeded the filesystem quota",
24
+ recovery: "Raise or reclaim the filesystem quota, then retry.",
25
+ category: "capacity",
26
+ },
27
+ ],
28
+ [
29
+ "EMFILE",
30
+ {
31
+ summary: "exhausted the process file-descriptor limit",
32
+ recovery: "Close unused file handles or raise the process limit, then retry.",
33
+ category: "resource",
34
+ },
35
+ ],
36
+ [
37
+ "ENFILE",
38
+ {
39
+ summary: "exhausted the host file-descriptor limit",
40
+ recovery: "Free host file descriptors or raise the host limit, then retry.",
41
+ category: "resource",
42
+ },
43
+ ],
44
+ [
45
+ "ENOMEM",
46
+ {
47
+ summary: "ran out of available memory",
48
+ recovery: "Free memory or reduce concurrent work, then retry.",
49
+ category: "resource",
50
+ },
51
+ ],
52
+ [
53
+ "ENOSPC",
54
+ {
55
+ summary: "ran out of storage space",
56
+ recovery: "Free storage on the filesystem holding the project, then retry.",
57
+ category: "capacity",
58
+ },
59
+ ],
60
+ [
61
+ "EPERM",
62
+ {
63
+ summary: "was denied by the host permission policy",
64
+ recovery: "Grant the required filesystem permission, then retry.",
65
+ category: "permission",
66
+ },
67
+ ],
68
+ [
69
+ "EROFS",
70
+ {
71
+ summary: "targeted a read-only filesystem",
72
+ recovery: "Use a writable project filesystem or remount it read-write, then retry.",
73
+ category: "permission",
74
+ },
75
+ ],
76
+ ]);
77
+ const OPERATION_PATTERN = /^[a-z][a-z0-9_]{0,63}$/u;
78
+ const HOST_ENVIRONMENT_FAULT_CODES = {
79
+ capacity: { code: "host_environment_capacity_fault" },
80
+ permission: { code: "host_environment_permission_fault" },
81
+ resource: { code: "host_environment_resource_fault" },
82
+ };
83
+ /** Return a declared host errno only when it represents recoverable environment state. */
84
+ export function classifyHostEnvironmentFault(error) {
85
+ if (typeof error !== "object" || error === null || !("code" in error))
86
+ return null;
87
+ const code = error.code;
88
+ return typeof code === "string" && HOST_ENVIRONMENT_FAULTS.has(code)
89
+ ? code
90
+ : null;
91
+ }
92
+ /** Translate one known host fault into a stable path-redacted SDK refusal. */
93
+ export function translateHostEnvironmentFault(error, operation, options = {}) {
94
+ const errno = classifyHostEnvironmentFault(error);
95
+ if (errno === null)
96
+ return null;
97
+ if (!OPERATION_PATTERN.test(operation)) {
98
+ throw new PmCliError("Host environment operation labels must be bounded identifiers.", EXIT_CODE.USAGE, { code: "host_environment_operation_invalid", field: "operation" });
99
+ }
100
+ const fault = HOST_ENVIRONMENT_FAULTS.get(errno);
101
+ return new PmCliError(`Host filesystem operation ${operation} ${fault.summary}.`, EXIT_CODE.GENERIC_FAILURE, {
102
+ code: options.codes?.[fault.category] ??
103
+ HOST_ENVIRONMENT_FAULT_CODES[fault.category].code,
104
+ reason: errno,
105
+ required: fault.recovery,
106
+ why: options.why ??
107
+ "The operating system refused a required project filesystem operation.",
108
+ nextSteps: [fault.recovery, ...(options.nextSteps ?? [])],
109
+ ...(options.suggestedRetry
110
+ ? { recovery: { suggested_retry: options.suggestedRetry } }
111
+ : {}),
112
+ });
113
+ }
114
+ /** Run one SDK filesystem stage and translate only declared host faults. */
115
+ export async function withHostEnvironmentBoundary(operation, run, options = {}) {
116
+ try {
117
+ return await run();
118
+ }
119
+ catch (error) {
120
+ throw translateHostEnvironmentFault(error, operation, options) ?? error;
121
+ }
122
+ }
123
+ //# sourceMappingURL=host-environment-errors.js.map
124
+ //# debugId=41fec0f3-5cc8-5007-a896-f8d8b83ae4f5
@@ -0,0 +1,65 @@
1
+ import { PmCliError } from "../../core/shared/errors.js";
2
+ export { PmCliError };
3
+ /** One discovered project pin that can prove the active executable is stale. */
4
+ export interface ProjectRuntimeVersionPin {
5
+ /** Exact or minimum date-version extracted from the project declaration. */
6
+ version: string;
7
+ /** Redaction-safe origin of the pin. */
8
+ source: "package.json" | "installed-package" | "package-lock.json" | "pnpm-lock.yaml" | "yarn.lock";
9
+ }
10
+ /** Structured result returned by the read-only compatibility probe. */
11
+ export interface ProjectRuntimeCompatibilityResult {
12
+ /** Whether the invocation can write with the active runtime. */
13
+ compatible: boolean;
14
+ /** Active executable package version. */
15
+ executing_version: string;
16
+ /** Highest project pin discovered without exposing local paths. */
17
+ project_version?: string;
18
+ /** Origin of the highest project pin. */
19
+ source?: ProjectRuntimeVersionPin["source"];
20
+ /** Canonical command selected from the invocation. */
21
+ command?: string;
22
+ /** Whether the selected invocation can mutate project state. */
23
+ mutating: boolean;
24
+ /** Whether the active executable is older than the strongest project pin. */
25
+ stale?: boolean;
26
+ /** Non-blocking diagnostic attached to stale read-only invocations. */
27
+ warning?: ProjectRuntimeCompatibilityWarning;
28
+ /** Whether the explicit one-invocation recovery override was accepted. */
29
+ override_applied: boolean;
30
+ }
31
+ /** Structured, package-manager-neutral warning returned for a stale read. */
32
+ export interface ProjectRuntimeCompatibilityWarning {
33
+ /** Stable warning code for filtering and automation. */
34
+ code: "project_runtime_stale_read";
35
+ /** Active executable package version. */
36
+ executing_version: string;
37
+ /** Strongest newer project version pin. */
38
+ project_version: string;
39
+ /** Redaction-safe origin of the project pin. */
40
+ source: ProjectRuntimeVersionPin["source"];
41
+ /** Concise explanation of the mismatch. */
42
+ message: string;
43
+ /** Package-manager-neutral recovery actions. */
44
+ next_steps: string[];
45
+ }
46
+ /** Compare pm date versions without accepting arbitrary semver-like prose. */
47
+ export declare function comparePmDateVersions(left: string, right: string): number | null;
48
+ /** Discover declared, installed, and lock-resolved versions without network I/O. */
49
+ export declare function discoverProjectRuntimeVersionPins(projectRoot: string): ProjectRuntimeVersionPin[];
50
+ /** Classify mutation-capable invocations while preserving explicit read modes. */
51
+ export declare function isProjectMutatingInvocation(argv: readonly string[]): boolean;
52
+ /** Inspect whether one invocation is compatible with the project's newest pin. */
53
+ export declare function inspectProjectRuntimeCompatibility(options: {
54
+ executingVersion: string;
55
+ projectRoot: string;
56
+ argv: readonly string[];
57
+ allowStale?: boolean;
58
+ }): ProjectRuntimeCompatibilityResult;
59
+ /** Refuse stale mutations with a stable SDK error and package-neutral recovery. */
60
+ export declare function assertProjectRuntimeCompatibility(options: {
61
+ executingVersion: string;
62
+ projectRoot: string;
63
+ argv: readonly string[];
64
+ allowStale?: boolean;
65
+ }): ProjectRuntimeCompatibilityResult;
@@ -0,0 +1,385 @@
1
+ /**
2
+ * @module sdk/project-runtime-compatibility
3
+ *
4
+ * Protects project mutations from an older PATH-resolved pm executable while
5
+ * leaving diagnosis reads available.
6
+ */
7
+
8
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="962636b0-ed3b-5ad0-ae0c-904435025986")}catch(e){}}();
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import { EXIT_CODE } from "../../core/shared/constants.js";
12
+ import { PmCliError } from "../../core/shared/errors.js";
13
+ export { PmCliError };
14
+ const PACKAGE_NAME = "@unbrained/pm-cli";
15
+ const MUTATING_COMMANDS = new Set([
16
+ "append",
17
+ "claim",
18
+ "changelog",
19
+ "close",
20
+ "close-many",
21
+ "close-task",
22
+ "comments",
23
+ "config",
24
+ "copy",
25
+ "create",
26
+ "dedupe-merge",
27
+ "delete",
28
+ "deps",
29
+ "docs",
30
+ "extension",
31
+ "event",
32
+ "events",
33
+ "files",
34
+ "focus",
35
+ "gc",
36
+ "history-author-acknowledge",
37
+ "history-compact",
38
+ "history-redact",
39
+ "history-repair",
40
+ "init",
41
+ "install",
42
+ "item",
43
+ "learnings",
44
+ "meet",
45
+ "merge",
46
+ "normalize",
47
+ "notes",
48
+ "package",
49
+ "packages",
50
+ "pause-task",
51
+ "plan",
52
+ "profile",
53
+ "reindex",
54
+ "release",
55
+ "remind",
56
+ "restore",
57
+ "schema",
58
+ "start-task",
59
+ "test",
60
+ "test-all",
61
+ "test-runs",
62
+ "test-runs-worker",
63
+ "telemetry",
64
+ "templates",
65
+ "twin",
66
+ "update",
67
+ "update-many",
68
+ "upgrade",
69
+ "vcs",
70
+ "workspace",
71
+ ]);
72
+ const GLOBAL_VALUE_FLAGS = new Set([
73
+ "--author",
74
+ "--output-budget",
75
+ "--output-format",
76
+ "--output-include",
77
+ "--output-limit",
78
+ "--output-session",
79
+ "--path",
80
+ "--pm-path",
81
+ ]);
82
+ const VERSION_PATTERN = /\b(\d{4})\.(\d{1,2})\.(\d{1,2})(?:-(\d+))?\b/u;
83
+ /** Return whether an invocation includes one of the exact mutation switches. */
84
+ function hasAnyToken(argv, tokens) {
85
+ return argv.some((token) => tokens.includes(token.split("=", 1)[0]));
86
+ }
87
+ /** Classify package/extension compatibility aliases from subcommands and legacy flags. */
88
+ function isPackageMutation(argv, positionals) {
89
+ return ([
90
+ "activate",
91
+ "adopt",
92
+ "adopt-all",
93
+ "deactivate",
94
+ "init",
95
+ "install",
96
+ "migrate",
97
+ "reload",
98
+ "uninstall",
99
+ ].includes(positionals[0] ?? "") ||
100
+ hasAnyToken(argv, [
101
+ "--activate",
102
+ "--adopt",
103
+ "--adopt-all",
104
+ "--deactivate",
105
+ "--fix-managed-state",
106
+ "--init",
107
+ "--install",
108
+ "--output",
109
+ "--reload",
110
+ "--scaffold",
111
+ "--uninstall",
112
+ ]));
113
+ }
114
+ const MIXED_COMMAND_CLASSIFIERS = {
115
+ changelog: (argv, positionals) => {
116
+ if (positionals[0] === "generate")
117
+ return !hasAnyToken(argv, ["--check"]);
118
+ const exportIndex = argv.indexOf("export");
119
+ return (positionals[0] === "export" &&
120
+ (hasAnyToken(argv, ["--output"]) ||
121
+ (exportIndex >= 0 &&
122
+ argv[exportIndex + 1] !== undefined &&
123
+ !argv[exportIndex + 1].startsWith("-"))));
124
+ },
125
+ comments: (argv) => hasAnyToken(argv, ["--add", "--delete", "--edit", "--file", "--stdin"]),
126
+ config: (_argv, positionals) => (positionals[0] === "project" || positionals[0] === "global"
127
+ ? positionals[1]
128
+ : positionals[0]) === "set",
129
+ deps: () => false,
130
+ docs: (argv) => hasAnyToken(argv, ["--add", "--add-glob", "--migrate", "--remove"]),
131
+ duplicates: () => false,
132
+ events: () => false,
133
+ extension: isPackageMutation,
134
+ files: (argv, positionals) => hasAnyToken(argv, ["--add", "--add-glob", "--migrate", "--remove"]) ||
135
+ (positionals[0] === "discover" && hasAnyToken(argv, ["--apply"])),
136
+ health: (argv) => !hasAnyToken(argv, ["--check-only", "--no-refresh", "--skip-vectors"]),
137
+ learnings: (argv) => hasAnyToken(argv, ["--add", "--delete", "--edit", "--file", "--stdin"]),
138
+ merge: (_argv, positionals) => positionals[0] !== "report",
139
+ notes: (argv) => hasAnyToken(argv, ["--add", "--delete", "--edit", "--file", "--stdin"]),
140
+ package: isPackageMutation,
141
+ packages: isPackageMutation,
142
+ profile: (_argv, positionals) => positionals[0] === "apply",
143
+ schema: (argv, positionals) => [
144
+ "add-field",
145
+ "add-status",
146
+ "add-type",
147
+ "remove-field",
148
+ "remove-status",
149
+ "remove-type",
150
+ "remap-status",
151
+ "rename-field",
152
+ "rename-type",
153
+ ].includes(positionals[0] ?? "") &&
154
+ !(hasAnyToken(argv, ["--infer"]) && !hasAnyToken(argv, ["--apply"])),
155
+ telemetry: (_argv, positionals) => positionals.slice(0, 2).some((token) => ["clear", "flush"].includes(token)),
156
+ templates: (_argv, positionals) => positionals[0] === "save",
157
+ test: (argv) => hasAnyToken(argv, [
158
+ "--add",
159
+ "--add-json",
160
+ "--background",
161
+ "--measure",
162
+ "--remove",
163
+ "--resume",
164
+ "--run",
165
+ "--stop",
166
+ ]),
167
+ validate: (argv) => hasAnyToken(argv, ["--auto-fix", "--prune-missing"]),
168
+ vcs: (_argv, positionals) => ["abandon", "create", "merge", "propose", "ref-create"].includes(positionals[0] ?? ""),
169
+ workspace: (_argv, positionals) => positionals[0] === "snapshot" &&
170
+ ["create", "delete", "restore"].includes(positionals[1] ?? ""),
171
+ };
172
+ /** Parse the supported date-version coordinates used by pm releases. */
173
+ function parseDateVersion(value) {
174
+ const match = value.match(VERSION_PATTERN);
175
+ return match
176
+ ? [
177
+ Number(match[1]),
178
+ Number(match[2]),
179
+ Number(match[3]),
180
+ Number(match[4] ?? 0),
181
+ ]
182
+ : null;
183
+ }
184
+ /** Compare pm date versions without accepting arbitrary semver-like prose. */
185
+ export function comparePmDateVersions(left, right) {
186
+ const leftParts = parseDateVersion(left);
187
+ const rightParts = parseDateVersion(right);
188
+ if (!leftParts || !rightParts)
189
+ return null;
190
+ for (let index = 0; index < leftParts.length; index += 1) {
191
+ const delta = leftParts[index] - rightParts[index];
192
+ if (delta !== 0)
193
+ return Math.sign(delta);
194
+ }
195
+ return 0;
196
+ }
197
+ /** Read one optional JSON object without turning absence or corruption into startup failure. */
198
+ function readJsonRecord(filePath) {
199
+ try {
200
+ const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
201
+ return typeof parsed === "object" &&
202
+ parsed !== null &&
203
+ !Array.isArray(parsed)
204
+ ? parsed
205
+ : null;
206
+ }
207
+ catch {
208
+ return null;
209
+ }
210
+ }
211
+ /** Extract the highest explicit lower-bound pm date version from dependency declarations. */
212
+ function dependencyPin(packageJson) {
213
+ const versions = [];
214
+ for (const field of [
215
+ "dependencies",
216
+ "devDependencies",
217
+ "optionalDependencies",
218
+ "peerDependencies",
219
+ ]) {
220
+ const dependencies = packageJson[field];
221
+ if (typeof dependencies !== "object" || dependencies === null)
222
+ continue;
223
+ const value = dependencies[PACKAGE_NAME];
224
+ const specification = typeof value === "string" ? value.trim() : "";
225
+ const version = /^[<!]/u.test(specification)
226
+ ? undefined
227
+ : specification.match(VERSION_PATTERN)?.[0];
228
+ if (version)
229
+ versions.push(version);
230
+ }
231
+ return versions.sort((left, right) => comparePmDateVersions(right, left))[0];
232
+ }
233
+ /** Read npm's exact installed package coordinate from package-lock.json. */
234
+ function packageLockPin(projectRoot) {
235
+ const lock = readJsonRecord(path.join(projectRoot, "package-lock.json"));
236
+ const packages = lock?.packages;
237
+ if (typeof packages !== "object" || packages === null)
238
+ return undefined;
239
+ const installed = packages["node_modules/@unbrained/pm-cli"];
240
+ if (typeof installed !== "object" || installed === null)
241
+ return undefined;
242
+ const version = installed.version;
243
+ return typeof version === "string" ? version : undefined;
244
+ }
245
+ /** Read the exact coordinate from the matching text lockfile package block. */
246
+ function textLockPin(projectRoot, file) {
247
+ try {
248
+ const lines = fs
249
+ .readFileSync(path.join(projectRoot, file), "utf8")
250
+ .split(/\r?\n/u);
251
+ const packageLineIndex = lines.findIndex((line) => line.includes(PACKAGE_NAME));
252
+ if (packageLineIndex < 0)
253
+ return undefined;
254
+ const packageIndent = lines[packageLineIndex].match(/^\s*/u)[0].length;
255
+ const entry = [lines[packageLineIndex]];
256
+ for (let index = packageLineIndex + 1; index < lines.length; index += 1) {
257
+ const line = lines[index];
258
+ const trimmed = line.trim();
259
+ const indent = line.match(/^\s*/u)[0].length;
260
+ if (trimmed.length > 0 && indent <= packageIndent)
261
+ break;
262
+ entry.push(line);
263
+ }
264
+ const entrySource = entry.join("\n");
265
+ const explicitVersion = entrySource.match(/^\s*version(?::\s*|\s+)["']?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/mu)?.[1];
266
+ return explicitVersion ?? entry[0].match(VERSION_PATTERN)?.[0];
267
+ }
268
+ catch {
269
+ return undefined;
270
+ }
271
+ }
272
+ /** Discover declared, installed, and lock-resolved versions without network I/O. */
273
+ export function discoverProjectRuntimeVersionPins(projectRoot) {
274
+ const pins = [];
275
+ const projectPackage = readJsonRecord(path.join(projectRoot, "package.json"));
276
+ const declared = projectPackage ? dependencyPin(projectPackage) : undefined;
277
+ if (declared)
278
+ pins.push({ version: declared, source: "package.json" });
279
+ const installedPackage = readJsonRecord(path.join(projectRoot, "node_modules", "@unbrained", "pm-cli", "package.json"));
280
+ const installedVersion = installedPackage?.version;
281
+ if (typeof installedVersion === "string" &&
282
+ parseDateVersion(installedVersion)) {
283
+ pins.push({ version: installedVersion, source: "installed-package" });
284
+ }
285
+ const packageLockVersion = packageLockPin(projectRoot);
286
+ if (packageLockVersion && parseDateVersion(packageLockVersion)) {
287
+ pins.push({ version: packageLockVersion, source: "package-lock.json" });
288
+ }
289
+ for (const file of ["pnpm-lock.yaml", "yarn.lock"]) {
290
+ const version = textLockPin(projectRoot, file);
291
+ if (version)
292
+ pins.push({ version, source: file });
293
+ }
294
+ return pins;
295
+ }
296
+ /** Resolve the first command token and index while preserving global option values. */
297
+ function commandTokenFromArgv(argv) {
298
+ for (let index = 0; index < argv.length; index += 1) {
299
+ const token = argv[index];
300
+ if (GLOBAL_VALUE_FLAGS.has(token)) {
301
+ index += 1;
302
+ continue;
303
+ }
304
+ if (!token.startsWith("-"))
305
+ return { command: token.toLowerCase(), index };
306
+ }
307
+ return undefined;
308
+ }
309
+ /** Classify mutation-capable invocations while preserving explicit read modes. */
310
+ export function isProjectMutatingInvocation(argv) {
311
+ const commandToken = commandTokenFromArgv(argv);
312
+ if (!commandToken)
313
+ return false;
314
+ if (hasAnyToken(argv, ["--help", "-h", "--dry-run"]))
315
+ return false;
316
+ const { command, index: commandIndex } = commandToken;
317
+ const positionals = [];
318
+ for (let index = commandIndex + 1; index < argv.length; index += 1) {
319
+ const token = argv[index];
320
+ if (GLOBAL_VALUE_FLAGS.has(token)) {
321
+ index += 1;
322
+ continue;
323
+ }
324
+ if (!token.startsWith("-"))
325
+ positionals.push(token.toLowerCase());
326
+ }
327
+ const mixedClassifier = MIXED_COMMAND_CLASSIFIERS[command];
328
+ return mixedClassifier
329
+ ? mixedClassifier(argv, positionals)
330
+ : MUTATING_COMMANDS.has(command);
331
+ }
332
+ /** Inspect whether one invocation is compatible with the project's newest pin. */
333
+ export function inspectProjectRuntimeCompatibility(options) {
334
+ const command = commandTokenFromArgv(options.argv)?.command;
335
+ const mutating = isProjectMutatingInvocation(options.argv);
336
+ const pins = discoverProjectRuntimeVersionPins(options.projectRoot)
337
+ .filter((pin) => comparePmDateVersions(pin.version, options.executingVersion) !== null)
338
+ .sort((left, right) => comparePmDateVersions(right.version, left.version));
339
+ const newest = pins[0];
340
+ const stale = newest !== undefined &&
341
+ comparePmDateVersions(options.executingVersion, newest.version) === -1;
342
+ const warning = stale && !mutating
343
+ ? {
344
+ code: "project_runtime_stale_read",
345
+ executing_version: options.executingVersion,
346
+ project_version: newest.version,
347
+ source: newest.source,
348
+ message: "This read is using an older pm runtime than the project requires.",
349
+ next_steps: [
350
+ `Run the command through the project's installed ${PACKAGE_NAME} ${newest.version}.`,
351
+ "Install the project dependencies with its declared package manager if the local executable is missing.",
352
+ ],
353
+ }
354
+ : undefined;
355
+ return {
356
+ compatible: !mutating || !stale || options.allowStale === true,
357
+ executing_version: options.executingVersion,
358
+ ...(newest
359
+ ? { project_version: newest.version, source: newest.source }
360
+ : {}),
361
+ ...(command ? { command } : {}),
362
+ mutating,
363
+ stale,
364
+ ...(warning ? { warning } : {}),
365
+ override_applied: stale && mutating && options.allowStale === true,
366
+ };
367
+ }
368
+ /** Refuse stale mutations with a stable SDK error and package-neutral recovery. */
369
+ export function assertProjectRuntimeCompatibility(options) {
370
+ const result = inspectProjectRuntimeCompatibility(options);
371
+ if (result.compatible)
372
+ return result;
373
+ throw new PmCliError(`pm ${result.executing_version} cannot mutate a project pinned to newer pm ${result.project_version}.`, EXIT_CODE.CONFLICT, {
374
+ code: "project_runtime_stale_mutation",
375
+ reason: result.source,
376
+ why: "An older runtime can write storage, history, and merge contracts it does not understand.",
377
+ nextSteps: [
378
+ `Run this command through the project's installed ${PACKAGE_NAME} ${result.project_version}.`,
379
+ "For an intentional recovery only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.",
380
+ "Read-only commands remain available without an override.",
381
+ ],
382
+ });
383
+ }
384
+ //# sourceMappingURL=project-runtime-compatibility.js.map
385
+ //# debugId=962636b0-ed3b-5ad0-ae0c-904435025986