@unbrained/pm-cli 2026.5.14 → 2026.5.24

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 (436) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/AGENTS.md +78 -457
  3. package/CHANGELOG.md +71 -0
  4. package/CONTRIBUTING.md +1 -0
  5. package/README.md +8 -6
  6. package/dist/cli/argv-utils.js +4 -1
  7. package/dist/cli/argv-utils.js.map +1 -1
  8. package/dist/cli/bootstrap-args.js +4 -1
  9. package/dist/cli/bootstrap-args.js.map +1 -1
  10. package/dist/cli/commander-usage.js +19 -1
  11. package/dist/cli/commander-usage.js.map +1 -1
  12. package/dist/cli/commands/activity.js +4 -1
  13. package/dist/cli/commands/activity.js.map +1 -1
  14. package/dist/cli/commands/aggregate.js +5 -2
  15. package/dist/cli/commands/aggregate.js.map +1 -1
  16. package/dist/cli/commands/annotation-command.d.ts +49 -0
  17. package/dist/cli/commands/annotation-command.js +135 -0
  18. package/dist/cli/commands/annotation-command.js.map +1 -0
  19. package/dist/cli/commands/append.js +5 -6
  20. package/dist/cli/commands/append.js.map +1 -1
  21. package/dist/cli/commands/calendar.js +5 -5
  22. package/dist/cli/commands/calendar.js.map +1 -1
  23. package/dist/cli/commands/claim.d.ts +3 -0
  24. package/dist/cli/commands/claim.js +29 -23
  25. package/dist/cli/commands/claim.js.map +1 -1
  26. package/dist/cli/commands/close.js +63 -8
  27. package/dist/cli/commands/close.js.map +1 -1
  28. package/dist/cli/commands/comments-audit.js +4 -1
  29. package/dist/cli/commands/comments-audit.js.map +1 -1
  30. package/dist/cli/commands/comments.d.ts +5 -0
  31. package/dist/cli/commands/comments.js +29 -116
  32. package/dist/cli/commands/comments.js.map +1 -1
  33. package/dist/cli/commands/completion.js +198 -15
  34. package/dist/cli/commands/completion.js.map +1 -1
  35. package/dist/cli/commands/config.js +4 -1
  36. package/dist/cli/commands/config.js.map +1 -1
  37. package/dist/cli/commands/context.js +21 -13
  38. package/dist/cli/commands/context.js.map +1 -1
  39. package/dist/cli/commands/contracts.d.ts +9 -0
  40. package/dist/cli/commands/contracts.js +314 -64
  41. package/dist/cli/commands/contracts.js.map +1 -1
  42. package/dist/cli/commands/create.js +77 -48
  43. package/dist/cli/commands/create.js.map +1 -1
  44. package/dist/cli/commands/dedupe-audit.js +9 -3
  45. package/dist/cli/commands/dedupe-audit.js.map +1 -1
  46. package/dist/cli/commands/delete.d.ts +3 -0
  47. package/dist/cli/commands/delete.js +11 -7
  48. package/dist/cli/commands/delete.js.map +1 -1
  49. package/dist/cli/commands/deps.js +4 -1
  50. package/dist/cli/commands/deps.js.map +1 -1
  51. package/dist/cli/commands/docs.d.ts +1 -0
  52. package/dist/cli/commands/docs.js +6 -7
  53. package/dist/cli/commands/docs.js.map +1 -1
  54. package/dist/cli/commands/event-validation-messages.d.ts +3 -0
  55. package/dist/cli/commands/event-validation-messages.js +44 -0
  56. package/dist/cli/commands/event-validation-messages.js.map +1 -0
  57. package/dist/cli/commands/extension.d.ts +3 -1
  58. package/dist/cli/commands/extension.js +259 -52
  59. package/dist/cli/commands/extension.js.map +1 -1
  60. package/dist/cli/commands/files.js +8 -12
  61. package/dist/cli/commands/files.js.map +1 -1
  62. package/dist/cli/commands/gc.js +19 -3
  63. package/dist/cli/commands/gc.js.map +1 -1
  64. package/dist/cli/commands/get.d.ts +10 -5
  65. package/dist/cli/commands/get.js +135 -20
  66. package/dist/cli/commands/get.js.map +1 -1
  67. package/dist/cli/commands/guide.js +6 -8
  68. package/dist/cli/commands/guide.js.map +1 -1
  69. package/dist/cli/commands/health.d.ts +14 -0
  70. package/dist/cli/commands/health.js +269 -67
  71. package/dist/cli/commands/health.js.map +1 -1
  72. package/dist/cli/commands/history-redact.d.ts +50 -0
  73. package/dist/cli/commands/history-redact.js +476 -0
  74. package/dist/cli/commands/history-redact.js.map +1 -0
  75. package/dist/cli/commands/history-repair.d.ts +33 -0
  76. package/dist/cli/commands/history-repair.js +166 -0
  77. package/dist/cli/commands/history-repair.js.map +1 -0
  78. package/dist/cli/commands/history.d.ts +4 -0
  79. package/dist/cli/commands/history.js +12 -79
  80. package/dist/cli/commands/history.js.map +1 -1
  81. package/dist/cli/commands/index.d.ts +5 -1
  82. package/dist/cli/commands/index.js +9 -2
  83. package/dist/cli/commands/index.js.map +1 -1
  84. package/dist/cli/commands/init-agent-guidance.d.ts +31 -0
  85. package/dist/cli/commands/init-agent-guidance.js +336 -0
  86. package/dist/cli/commands/init-agent-guidance.js.map +1 -0
  87. package/dist/cli/commands/init.d.ts +42 -0
  88. package/dist/cli/commands/init.js +96 -1
  89. package/dist/cli/commands/init.js.map +1 -1
  90. package/dist/cli/commands/learnings.js +22 -118
  91. package/dist/cli/commands/learnings.js.map +1 -1
  92. package/dist/cli/commands/linked-test-entry.d.ts +3 -0
  93. package/dist/cli/commands/linked-test-entry.js +62 -0
  94. package/dist/cli/commands/linked-test-entry.js.map +1 -0
  95. package/dist/cli/commands/list.d.ts +1 -0
  96. package/dist/cli/commands/list.js +72 -38
  97. package/dist/cli/commands/list.js.map +1 -1
  98. package/dist/cli/commands/metadata-normalizers.js +4 -1
  99. package/dist/cli/commands/metadata-normalizers.js.map +1 -1
  100. package/dist/cli/commands/normalize.js +4 -1
  101. package/dist/cli/commands/normalize.js.map +1 -1
  102. package/dist/cli/commands/notes.js +22 -118
  103. package/dist/cli/commands/notes.js.map +1 -1
  104. package/dist/cli/commands/plan.d.ts +121 -0
  105. package/dist/cli/commands/plan.js +1137 -0
  106. package/dist/cli/commands/plan.js.map +1 -0
  107. package/dist/cli/commands/reindex.js +4 -1
  108. package/dist/cli/commands/reindex.js.map +1 -1
  109. package/dist/cli/commands/restore.js +9 -49
  110. package/dist/cli/commands/restore.js.map +1 -1
  111. package/dist/cli/commands/schema.d.ts +31 -0
  112. package/dist/cli/commands/schema.js +98 -0
  113. package/dist/cli/commands/schema.js.map +1 -0
  114. package/dist/cli/commands/search.js +156 -40
  115. package/dist/cli/commands/search.js.map +1 -1
  116. package/dist/cli/commands/stats.js +4 -1
  117. package/dist/cli/commands/stats.js.map +1 -1
  118. package/dist/cli/commands/templates.d.ts +4 -0
  119. package/dist/cli/commands/templates.js +91 -16
  120. package/dist/cli/commands/templates.js.map +1 -1
  121. package/dist/cli/commands/test-all.js +6 -7
  122. package/dist/cli/commands/test-all.js.map +1 -1
  123. package/dist/cli/commands/test-runs.js +4 -1
  124. package/dist/cli/commands/test-runs.js.map +1 -1
  125. package/dist/cli/commands/test.d.ts +1 -0
  126. package/dist/cli/commands/test.js +9 -9
  127. package/dist/cli/commands/test.js.map +1 -1
  128. package/dist/cli/commands/update-many.js +6 -7
  129. package/dist/cli/commands/update-many.js.map +1 -1
  130. package/dist/cli/commands/update.js +204 -103
  131. package/dist/cli/commands/update.js.map +1 -1
  132. package/dist/cli/commands/upgrade.js +6 -3
  133. package/dist/cli/commands/upgrade.js.map +1 -1
  134. package/dist/cli/commands/validate.d.ts +3 -1
  135. package/dist/cli/commands/validate.js +44 -64
  136. package/dist/cli/commands/validate.js.map +1 -1
  137. package/dist/cli/error-guidance.js +99 -6
  138. package/dist/cli/error-guidance.js.map +1 -1
  139. package/dist/cli/extension-command-help.d.ts +0 -1
  140. package/dist/cli/extension-command-help.js +4 -12
  141. package/dist/cli/extension-command-help.js.map +1 -1
  142. package/dist/cli/extension-command-options.d.ts +1 -0
  143. package/dist/cli/extension-command-options.js +108 -6
  144. package/dist/cli/extension-command-options.js.map +1 -1
  145. package/dist/cli/guide-topics.js +4 -1
  146. package/dist/cli/guide-topics.js.map +1 -1
  147. package/dist/cli/help-content.d.ts +0 -1
  148. package/dist/cli/help-content.js +46 -22
  149. package/dist/cli/help-content.js.map +1 -1
  150. package/dist/cli/help-json-payload.d.ts +1 -0
  151. package/dist/cli/help-json-payload.js +35 -2
  152. package/dist/cli/help-json-payload.js.map +1 -1
  153. package/dist/cli/main.js +214 -30
  154. package/dist/cli/main.js.map +1 -1
  155. package/dist/cli/migration-gates.js +4 -1
  156. package/dist/cli/migration-gates.js.map +1 -1
  157. package/dist/cli/register-list-query.d.ts +1 -1
  158. package/dist/cli/register-list-query.js +75 -29
  159. package/dist/cli/register-list-query.js.map +1 -1
  160. package/dist/cli/register-mutation.d.ts +1 -1
  161. package/dist/cli/register-mutation.js +430 -38
  162. package/dist/cli/register-mutation.js.map +1 -1
  163. package/dist/cli/register-operations.js +47 -10
  164. package/dist/cli/register-operations.js.map +1 -1
  165. package/dist/cli/register-setup.js +47 -25
  166. package/dist/cli/register-setup.js.map +1 -1
  167. package/dist/cli/registration-helpers.d.ts +0 -2
  168. package/dist/cli/registration-helpers.js +21 -40
  169. package/dist/cli/registration-helpers.js.map +1 -1
  170. package/dist/cli/shared-parsers.js +4 -1
  171. package/dist/cli/shared-parsers.js.map +1 -1
  172. package/dist/cli/telemetry-flush.js +4 -1
  173. package/dist/cli/telemetry-flush.js.map +1 -1
  174. package/dist/cli.js +65 -3
  175. package/dist/cli.js.map +1 -1
  176. package/dist/core/extensions/extension-types.js +4 -1
  177. package/dist/core/extensions/extension-types.js.map +1 -1
  178. package/dist/core/extensions/index.d.ts +0 -1
  179. package/dist/core/extensions/index.js +4 -13
  180. package/dist/core/extensions/index.js.map +1 -1
  181. package/dist/core/extensions/item-fields.js +4 -1
  182. package/dist/core/extensions/item-fields.js.map +1 -1
  183. package/dist/core/extensions/loader.js +78 -60
  184. package/dist/core/extensions/loader.js.map +1 -1
  185. package/dist/core/extensions/runtime-registrations.js +4 -1
  186. package/dist/core/extensions/runtime-registrations.js.map +1 -1
  187. package/dist/core/fs/fs-utils.js +4 -1
  188. package/dist/core/fs/fs-utils.js.map +1 -1
  189. package/dist/core/fs/index.js +4 -1
  190. package/dist/core/fs/index.js.map +1 -1
  191. package/dist/core/fs/path-utils.d.ts +1 -0
  192. package/dist/core/fs/path-utils.js +12 -0
  193. package/dist/core/fs/path-utils.js.map +1 -0
  194. package/dist/core/history/drift-scan.d.ts +11 -0
  195. package/dist/core/history/drift-scan.js +67 -0
  196. package/dist/core/history/drift-scan.js.map +1 -0
  197. package/dist/core/history/history-stream-policy.js +4 -1
  198. package/dist/core/history/history-stream-policy.js.map +1 -1
  199. package/dist/core/history/history.js +4 -1
  200. package/dist/core/history/history.js.map +1 -1
  201. package/dist/core/history/index.js +4 -1
  202. package/dist/core/history/index.js.map +1 -1
  203. package/dist/core/history/replay.d.ts +82 -0
  204. package/dist/core/history/replay.js +249 -0
  205. package/dist/core/history/replay.js.map +1 -0
  206. package/dist/core/item/id.js +4 -1
  207. package/dist/core/item/id.js.map +1 -1
  208. package/dist/core/item/index.js +4 -1
  209. package/dist/core/item/index.js.map +1 -1
  210. package/dist/core/item/item-format.js +250 -8
  211. package/dist/core/item/item-format.js.map +1 -1
  212. package/dist/core/item/item-type-definition.d.ts +52 -0
  213. package/dist/core/item/item-type-definition.js +123 -0
  214. package/dist/core/item/item-type-definition.js.map +1 -0
  215. package/dist/core/item/parent-reference-policy.js +4 -1
  216. package/dist/core/item/parent-reference-policy.js.map +1 -1
  217. package/dist/core/item/parse.js +34 -3
  218. package/dist/core/item/parse.js.map +1 -1
  219. package/dist/core/item/priority.d.ts +23 -0
  220. package/dist/core/item/priority.js +55 -0
  221. package/dist/core/item/priority.js.map +1 -0
  222. package/dist/core/item/sprint-release-format.js +4 -1
  223. package/dist/core/item/sprint-release-format.js.map +1 -1
  224. package/dist/core/item/status.d.ts +14 -1
  225. package/dist/core/item/status.js +24 -1
  226. package/dist/core/item/status.js.map +1 -1
  227. package/dist/core/item/toon-decode.d.ts +19 -0
  228. package/dist/core/item/toon-decode.js +69 -0
  229. package/dist/core/item/toon-decode.js.map +1 -0
  230. package/dist/core/item/type-registry.js +15 -83
  231. package/dist/core/item/type-registry.js.map +1 -1
  232. package/dist/core/lock/index.js +4 -1
  233. package/dist/core/lock/index.js.map +1 -1
  234. package/dist/core/lock/lock.js +4 -1
  235. package/dist/core/lock/lock.js.map +1 -1
  236. package/dist/core/output/output.d.ts +4 -0
  237. package/dist/core/output/output.js +47 -6
  238. package/dist/core/output/output.js.map +1 -1
  239. package/dist/core/packages/manifest.d.ts +1 -0
  240. package/dist/core/packages/manifest.js +6 -8
  241. package/dist/core/packages/manifest.js.map +1 -1
  242. package/dist/core/packages/root.d.ts +3 -0
  243. package/dist/core/packages/root.js +51 -0
  244. package/dist/core/packages/root.js.map +1 -0
  245. package/dist/core/schema/item-types-file.d.ts +85 -0
  246. package/dist/core/schema/item-types-file.js +243 -0
  247. package/dist/core/schema/item-types-file.js.map +1 -0
  248. package/dist/core/schema/runtime-field-filters.js +4 -1
  249. package/dist/core/schema/runtime-field-filters.js.map +1 -1
  250. package/dist/core/schema/runtime-field-values.js +4 -1
  251. package/dist/core/schema/runtime-field-values.js.map +1 -1
  252. package/dist/core/schema/runtime-schema.d.ts +2 -1
  253. package/dist/core/schema/runtime-schema.js +13 -8
  254. package/dist/core/schema/runtime-schema.js.map +1 -1
  255. package/dist/core/search/cache.js +7 -2
  256. package/dist/core/search/cache.js.map +1 -1
  257. package/dist/core/search/corpus.d.ts +2 -0
  258. package/dist/core/search/corpus.js +77 -2
  259. package/dist/core/search/corpus.js.map +1 -1
  260. package/dist/core/search/embedding-batches.js +21 -7
  261. package/dist/core/search/embedding-batches.js.map +1 -1
  262. package/dist/core/search/http-client.js +4 -1
  263. package/dist/core/search/http-client.js.map +1 -1
  264. package/dist/core/search/providers.js +4 -1
  265. package/dist/core/search/providers.js.map +1 -1
  266. package/dist/core/search/semantic-defaults.js +12 -3
  267. package/dist/core/search/semantic-defaults.js.map +1 -1
  268. package/dist/core/search/vector-stores.js +4 -1
  269. package/dist/core/search/vector-stores.js.map +1 -1
  270. package/dist/core/sentry/helpers.js +4 -1
  271. package/dist/core/sentry/helpers.js.map +1 -1
  272. package/dist/core/sentry/instrument.js +10 -13
  273. package/dist/core/sentry/instrument.js.map +1 -1
  274. package/dist/core/shared/author.d.ts +1 -0
  275. package/dist/core/shared/author.js +9 -0
  276. package/dist/core/shared/author.js.map +1 -0
  277. package/dist/core/shared/command-types.js +4 -1
  278. package/dist/core/shared/command-types.js.map +1 -1
  279. package/dist/core/shared/conflict-markers.js +4 -1
  280. package/dist/core/shared/conflict-markers.js.map +1 -1
  281. package/dist/core/shared/constants.d.ts +2 -2
  282. package/dist/core/shared/constants.js +24 -1
  283. package/dist/core/shared/constants.js.map +1 -1
  284. package/dist/core/shared/errors.js +4 -1
  285. package/dist/core/shared/errors.js.map +1 -1
  286. package/dist/core/shared/index.js +4 -1
  287. package/dist/core/shared/index.js.map +1 -1
  288. package/dist/core/shared/lazy-module.d.ts +1 -0
  289. package/dist/core/shared/lazy-module.js +11 -0
  290. package/dist/core/shared/lazy-module.js.map +1 -0
  291. package/dist/core/shared/levenshtein.js +4 -1
  292. package/dist/core/shared/levenshtein.js.map +1 -1
  293. package/dist/core/shared/option-alias-visibility.d.ts +44 -0
  294. package/dist/core/shared/option-alias-visibility.js +76 -0
  295. package/dist/core/shared/option-alias-visibility.js.map +1 -0
  296. package/dist/core/shared/primitives.js +4 -1
  297. package/dist/core/shared/primitives.js.map +1 -1
  298. package/dist/core/shared/serialization.js +4 -1
  299. package/dist/core/shared/serialization.js.map +1 -1
  300. package/dist/core/shared/text-normalization.d.ts +0 -1
  301. package/dist/core/shared/text-normalization.js +4 -4
  302. package/dist/core/shared/text-normalization.js.map +1 -1
  303. package/dist/core/shared/time.js +4 -1
  304. package/dist/core/shared/time.js.map +1 -1
  305. package/dist/core/store/front-matter-cache.js +8 -3
  306. package/dist/core/store/front-matter-cache.js.map +1 -1
  307. package/dist/core/store/index.js +4 -1
  308. package/dist/core/store/index.js.map +1 -1
  309. package/dist/core/store/item-format-migration.js +4 -1
  310. package/dist/core/store/item-format-migration.js.map +1 -1
  311. package/dist/core/store/item-store.d.ts +4 -0
  312. package/dist/core/store/item-store.js +133 -39
  313. package/dist/core/store/item-store.js.map +1 -1
  314. package/dist/core/store/paths.js +4 -1
  315. package/dist/core/store/paths.js.map +1 -1
  316. package/dist/core/store/settings-validator.d.ts +106 -0
  317. package/dist/core/store/settings-validator.js +279 -0
  318. package/dist/core/store/settings-validator.js.map +1 -0
  319. package/dist/core/store/settings.js +32 -331
  320. package/dist/core/store/settings.js.map +1 -1
  321. package/dist/core/telemetry/consent.js +4 -1
  322. package/dist/core/telemetry/consent.js.map +1 -1
  323. package/dist/core/telemetry/observability.d.ts +1 -1
  324. package/dist/core/telemetry/observability.js +11 -2
  325. package/dist/core/telemetry/observability.js.map +1 -1
  326. package/dist/core/telemetry/runtime.js +34 -6
  327. package/dist/core/telemetry/runtime.js.map +1 -1
  328. package/dist/core/test/background-runs.js +4 -1
  329. package/dist/core/test/background-runs.js.map +1 -1
  330. package/dist/core/test/item-test-run-tracking.js +4 -1
  331. package/dist/core/test/item-test-run-tracking.js.map +1 -1
  332. package/dist/mcp/server.js +182 -22
  333. package/dist/mcp/server.js.map +1 -1
  334. package/dist/sdk/cli-contracts/commander-mutation-options.js +10 -3
  335. package/dist/sdk/cli-contracts/commander-mutation-options.js.map +1 -1
  336. package/dist/sdk/cli-contracts/commander-types.js +4 -1
  337. package/dist/sdk/cli-contracts/commander-types.js.map +1 -1
  338. package/dist/sdk/cli-contracts.d.ts +13 -2
  339. package/dist/sdk/cli-contracts.js +410 -26
  340. package/dist/sdk/cli-contracts.js.map +1 -1
  341. package/dist/sdk/index.js +4 -1
  342. package/dist/sdk/index.js.map +1 -1
  343. package/dist/sdk/runtime.d.ts +25 -1
  344. package/dist/sdk/runtime.js +48 -2
  345. package/dist/sdk/runtime.js.map +1 -1
  346. package/dist/types/index.js +4 -1
  347. package/dist/types/index.js.map +1 -1
  348. package/dist/types.d.ts +92 -2
  349. package/dist/types.js +42 -1
  350. package/dist/types.js.map +1 -1
  351. package/docs/AGENT_GUIDE.md +23 -7
  352. package/docs/ARCHITECTURE.md +1 -1
  353. package/docs/CLAUDE_CODE_PLUGIN.md +10 -10
  354. package/docs/CODEX_PLUGIN.md +2 -2
  355. package/docs/COMMANDS.md +117 -12
  356. package/docs/CONFIGURATION.md +5 -2
  357. package/docs/EXTENSIONS.md +158 -814
  358. package/docs/QUICKSTART.md +11 -5
  359. package/docs/README.md +7 -6
  360. package/docs/RELEASING.md +13 -9
  361. package/docs/SDK.md +11 -2
  362. package/docs/TESTING.md +2 -2
  363. package/marketplace.json +3 -3
  364. package/package.json +15 -12
  365. package/packages/pm-beads/package.json +1 -1
  366. package/packages/pm-calendar/README.md +4 -2
  367. package/packages/pm-calendar/extensions/calendar/index.js +22 -3
  368. package/packages/pm-calendar/extensions/calendar/index.ts +22 -3
  369. package/packages/pm-calendar/extensions/calendar/runtime.js +26 -7
  370. package/packages/pm-calendar/extensions/calendar/runtime.ts +26 -7
  371. package/packages/pm-calendar/package.json +1 -1
  372. package/packages/pm-governance-audit/package.json +1 -1
  373. package/packages/pm-guide-shell/extensions/guide-shell/index.js +1 -1
  374. package/packages/pm-guide-shell/extensions/guide-shell/index.ts +1 -1
  375. package/packages/pm-guide-shell/package.json +1 -1
  376. package/packages/pm-linked-test-adapters/package.json +1 -1
  377. package/packages/pm-search-advanced/README.md +8 -0
  378. package/packages/pm-search-advanced/extensions/search-advanced/index.js +74 -0
  379. package/packages/pm-search-advanced/extensions/search-advanced/index.ts +75 -1
  380. package/packages/pm-search-advanced/extensions/search-advanced/runtime.js +67 -9
  381. package/packages/pm-search-advanced/extensions/search-advanced/runtime.ts +67 -9
  382. package/packages/pm-search-advanced/package.json +1 -1
  383. package/packages/pm-templates/README.md +1 -1
  384. package/packages/pm-templates/extensions/templates/runtime.js +11 -202
  385. package/packages/pm-templates/extensions/templates/runtime.ts +38 -230
  386. package/packages/pm-templates/package.json +1 -1
  387. package/packages/pm-todos/package.json +1 -1
  388. package/plugins/{pm-cli-claude → pm-claude}/.claude-plugin/plugin.json +2 -2
  389. package/plugins/{pm-cli-claude → pm-claude}/.mcp.json +1 -1
  390. package/plugins/{pm-cli-claude → pm-claude}/README.md +4 -4
  391. package/plugins/{pm-cli-claude → pm-claude}/agents/pm-coordinator.md +1 -1
  392. package/plugins/{pm-cli-claude → pm-claude}/commands/pm-init.md +10 -1
  393. package/plugins/{pm-cli-claude → pm-claude}/commands/pm-planner.md +18 -0
  394. package/plugins/{pm-cli-claude → pm-claude}/skills/pm-planner/SKILL.md +46 -1
  395. package/plugins/{pm-cli-codex → pm-codex}/.codex-plugin/plugin.json +3 -3
  396. package/plugins/{pm-cli-codex → pm-codex}/.mcp.json +1 -1
  397. package/plugins/{pm-cli-codex → pm-codex}/README.md +7 -4
  398. package/plugins/pm-codex/skills/pm-native/SKILL.md +81 -0
  399. package/scripts/finalize-build.mjs +28 -0
  400. package/scripts/prepare-build-cache.mjs +37 -0
  401. package/dist/core/output/command-aware.d.ts +0 -1
  402. package/dist/core/output/command-aware.js +0 -394
  403. package/dist/core/output/command-aware.js.map +0 -1
  404. package/plugins/pm-cli-codex/skills/pm-native/SKILL.md +0 -57
  405. /package/plugins/{pm-cli-claude → pm-claude}/agents/pm-delivery-chain.md +0 -0
  406. /package/plugins/{pm-cli-claude → pm-claude}/agents/pm-triage-agent.md +0 -0
  407. /package/plugins/{pm-cli-claude → pm-claude}/agents/pm-verification-agent.md +0 -0
  408. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-audit.md +0 -0
  409. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-calendar.md +0 -0
  410. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-close-task.md +0 -0
  411. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-developer.md +0 -0
  412. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-list.md +0 -0
  413. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-new.md +0 -0
  414. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-release.md +0 -0
  415. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-search.md +0 -0
  416. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-start-task.md +0 -0
  417. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-status.md +0 -0
  418. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-triage.md +0 -0
  419. /package/plugins/{pm-cli-claude → pm-claude}/commands/pm-workflow.md +0 -0
  420. /package/plugins/{pm-cli-claude → pm-claude}/hooks/hooks.json +0 -0
  421. /package/plugins/{pm-cli-claude → pm-claude}/hooks/session-start.mjs +0 -0
  422. /package/plugins/{pm-cli-claude → pm-claude}/scripts/pm-mcp-server.mjs +0 -0
  423. /package/plugins/{pm-cli-claude → pm-claude}/skills/pm-audit/SKILL.md +0 -0
  424. /package/plugins/{pm-cli-claude → pm-claude}/skills/pm-developer/SKILL.md +0 -0
  425. /package/plugins/{pm-cli-claude → pm-claude}/skills/pm-release/SKILL.md +0 -0
  426. /package/plugins/{pm-cli-claude → pm-claude}/skills/pm-workflow/SKILL.md +0 -0
  427. /package/plugins/{pm-cli-codex → pm-codex}/assets/pm-cli-small.svg +0 -0
  428. /package/plugins/{pm-cli-codex → pm-codex}/commands/pm-audit.md +0 -0
  429. /package/plugins/{pm-cli-codex → pm-codex}/commands/pm-close-task.md +0 -0
  430. /package/plugins/{pm-cli-codex → pm-codex}/commands/pm-start-task.md +0 -0
  431. /package/plugins/{pm-cli-codex → pm-codex}/scripts/pm-mcp-server.mjs +0 -0
  432. /package/plugins/{pm-cli-codex → pm-codex}/skills/pm-auditor/SKILL.md +0 -0
  433. /package/plugins/{pm-cli-codex → pm-codex}/skills/pm-auditor/agents/openai.yaml +0 -0
  434. /package/plugins/{pm-cli-codex → pm-codex}/skills/pm-native/agents/openai.yaml +0 -0
  435. /package/plugins/{pm-cli-codex → pm-codex}/skills/pm-release/SKILL.md +0 -0
  436. /package/plugins/{pm-cli-codex → pm-codex}/skills/pm-release/agents/openai.yaml +0 -0
@@ -0,0 +1,166 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e227bfe2-45fa-5ebf-a43d-cb679ecbe106")}catch(e){}}();
3
+ import fs from "node:fs/promises";
4
+ import jsonPatch from "fast-json-patch";
5
+ import { pathExists, readFileIfExists, writeFileAtomic } from "../../core/fs/fs-utils.js";
6
+ import { historyEntriesToRaw, reanchorHistoryEntries, replayHash, toReplayDocument, verifyHistoryChain, } from "../../core/history/replay.js";
7
+ import { resolveItemTypeRegistry } from "../../core/item/type-registry.js";
8
+ import { acquireLock } from "../../core/lock/lock.js";
9
+ import { EXIT_CODE } from "../../core/shared/constants.js";
10
+ import { PmCliError } from "../../core/shared/errors.js";
11
+ import { nowIso } from "../../core/shared/time.js";
12
+ import { getActiveExtensionRegistrations, runActiveOnWriteHooks } from "../../core/extensions/index.js";
13
+ import { readLocatedItem } from "../../core/store/item-store.js";
14
+ import { getSettingsPath, resolvePmRoot } from "../../core/store/paths.js";
15
+ import { readSettings, resolveGovernanceKnobs } from "../../core/store/settings.js";
16
+ import { readHistoryEntries } from "./history.js";
17
+ import { resolveHistorySubject } from "./history-redact.js";
18
+ function toAuthor(candidate, defaultAuthor) {
19
+ const resolved = candidate ?? process.env.PM_AUTHOR ?? defaultAuthor;
20
+ const trimmed = resolved.trim();
21
+ return trimmed.length > 0 ? trimmed : "unknown";
22
+ }
23
+ export async function runHistoryRepair(id, options, global) {
24
+ const pmRoot = resolvePmRoot(process.cwd(), global.path);
25
+ if (!(await pathExists(getSettingsPath(pmRoot)))) {
26
+ throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);
27
+ }
28
+ const settings = await readSettings(pmRoot);
29
+ const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());
30
+ const subject = await resolveHistorySubject(pmRoot, id, settings, typeRegistry.type_to_folder);
31
+ if (!(await pathExists(subject.historyPath))) {
32
+ throw new PmCliError(`No history stream exists for ${subject.id}.`, EXIT_CODE.NOT_FOUND);
33
+ }
34
+ const historyEntries = await readHistoryEntries(subject.historyPath, subject.id);
35
+ if (historyEntries.length === 0) {
36
+ throw new PmCliError(`No history entries exist for ${subject.id}; nothing to repair.`, EXIT_CODE.USAGE);
37
+ }
38
+ const chainBefore = verifyHistoryChain(historyEntries);
39
+ const reanchor = reanchorHistoryEntries(historyEntries);
40
+ // Reconcile the replayed chain with the current on-disk item document so the
41
+ // latest after_hash matches what pm validate/health compute for the item.
42
+ let currentItemReplay = null;
43
+ const currentItemPath = subject.located?.itemPath ?? null;
44
+ let matchedChainBefore = null;
45
+ const loadedItem = subject.located
46
+ ? await readLocatedItem(subject.located, { schema: settings.schema })
47
+ : null;
48
+ if (loadedItem) {
49
+ // Use the shared canonical replay form so reconciliation hashing matches the
50
+ // semantics pm validate/health use for the on-disk item (avoids hash divergence).
51
+ currentItemReplay = toReplayDocument(loadedItem.document);
52
+ const lastOriginalAfterHash = historyEntries[historyEntries.length - 1]?.after_hash;
53
+ matchedChainBefore = replayHash(currentItemReplay) === lastOriginalAfterHash;
54
+ }
55
+ const finalReplay = reanchor.finalDocument;
56
+ const reconcileNeeded = currentItemReplay !== null && replayHash(finalReplay) !== replayHash(currentItemReplay);
57
+ const changed = reanchor.entriesRehashed > 0 || reanchor.entriesPatchRepaired > 0 || reconcileNeeded;
58
+ const author = toAuthor(options.author, settings.author_default);
59
+ const dryRun = Boolean(options.dryRun);
60
+ const repairMessage = typeof options.message === "string" && options.message.trim().length > 0
61
+ ? options.message
62
+ : `history-repair re-anchored ${reanchor.entriesRehashed} entr${reanchor.entriesRehashed === 1 ? "y" : "ies"}${reanchor.entriesPatchRepaired > 0 ? `, repaired ${reanchor.entriesPatchRepaired} patch(es)` : ""}${reconcileNeeded ? ", reconciled chain with on-disk item" : ""}.`;
63
+ const rewrittenEntries = [...reanchor.entries];
64
+ let auditEntryAdded = false;
65
+ if (changed) {
66
+ if (reconcileNeeded && currentItemReplay) {
67
+ rewrittenEntries.push({
68
+ ts: nowIso(),
69
+ author,
70
+ op: "history_repair",
71
+ patch: jsonPatch.compare(finalReplay, currentItemReplay),
72
+ before_hash: replayHash(finalReplay),
73
+ after_hash: replayHash(currentItemReplay),
74
+ message: repairMessage,
75
+ });
76
+ }
77
+ else {
78
+ rewrittenEntries.push({
79
+ ts: nowIso(),
80
+ author,
81
+ op: "history_repair",
82
+ patch: [],
83
+ before_hash: replayHash(finalReplay),
84
+ after_hash: replayHash(finalReplay),
85
+ message: repairMessage,
86
+ });
87
+ }
88
+ auditEntryAdded = true;
89
+ }
90
+ const historyVerify = verifyHistoryChain(rewrittenEntries);
91
+ if (!historyVerify.ok) {
92
+ throw new PmCliError(`history-repair produced an invalid rewritten chain (${historyVerify.errors.join(", ")}).`, EXIT_CODE.GENERIC_FAILURE);
93
+ }
94
+ const warnings = [];
95
+ if (!changed) {
96
+ warnings.push("history_repair_no_changes");
97
+ }
98
+ if (reanchor.skippedOps > 0) {
99
+ warnings.push(`history_repair_skipped_unresolvable_ops:${reanchor.skippedOps}`);
100
+ }
101
+ if (changed && !dryRun) {
102
+ if (loadedItem) {
103
+ const governance = resolveGovernanceKnobs(settings);
104
+ const assigned = loadedItem.document.metadata.assignee?.trim();
105
+ if (assigned && assigned !== author && !options.force) {
106
+ if (governance.ownership_enforcement === "strict") {
107
+ throw new PmCliError(`Item ${subject.id} is assigned to ${assigned}. Use --force to override.`, EXIT_CODE.CONFLICT);
108
+ }
109
+ if (governance.ownership_enforcement === "warn") {
110
+ warnings.push(`ownership_warning:assignee_conflict:${subject.id}:${assigned}`);
111
+ }
112
+ }
113
+ }
114
+ const releaseLock = await acquireLock(pmRoot, subject.id, settings.locks.ttl_seconds, author, Boolean(options.force), settings.governance.force_required_for_stale_lock);
115
+ try {
116
+ const previousHistoryRaw = await readFileIfExists(subject.historyPath);
117
+ try {
118
+ await writeFileAtomic(subject.historyPath, historyEntriesToRaw(rewrittenEntries));
119
+ }
120
+ catch (error) {
121
+ if (previousHistoryRaw === null) {
122
+ await fs.rm(subject.historyPath, { force: true });
123
+ }
124
+ else {
125
+ await writeFileAtomic(subject.historyPath, previousHistoryRaw);
126
+ }
127
+ throw error;
128
+ }
129
+ warnings.push(...(await runActiveOnWriteHooks({
130
+ path: subject.historyPath,
131
+ scope: "project",
132
+ op: "history_repair:history",
133
+ })));
134
+ }
135
+ finally {
136
+ await releaseLock();
137
+ }
138
+ }
139
+ return {
140
+ id: subject.id,
141
+ dry_run: dryRun,
142
+ changed,
143
+ history: {
144
+ path: subject.historyPath,
145
+ entries_scanned: historyEntries.length,
146
+ chain_drift_before: !chainBefore.ok,
147
+ entries_rehashed: reanchor.entriesRehashed,
148
+ entries_patch_repaired: reanchor.entriesPatchRepaired,
149
+ converted_replace_to_add: reanchor.convertedReplaceToAdd,
150
+ skipped_ops: reanchor.skippedOps,
151
+ reconciled_with_item: reconcileNeeded,
152
+ audit_entry_added: auditEntryAdded,
153
+ verify_ok: historyVerify.ok,
154
+ verify_errors: historyVerify.errors,
155
+ },
156
+ item: {
157
+ exists: currentItemPath !== null,
158
+ path: currentItemPath,
159
+ matched_chain_before: matchedChainBefore,
160
+ },
161
+ warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),
162
+ generated_at: nowIso(),
163
+ };
164
+ }
165
+ //# sourceMappingURL=history-repair.js.map
166
+ //# debugId=e227bfe2-45fa-5ebf-a43d-cb679ecbe106
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history-repair.js","sources":["cli/commands/history-repair.ts"],"sourceRoot":"/","sourcesContent":["import fs from \"node:fs/promises\";\nimport jsonPatch from \"fast-json-patch\";\nimport { pathExists, readFileIfExists, writeFileAtomic } from \"../../core/fs/fs-utils.js\";\nimport {\n historyEntriesToRaw,\n reanchorHistoryEntries,\n replayHash,\n toReplayDocument,\n verifyHistoryChain,\n type ReplayDocument,\n} from \"../../core/history/replay.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { acquireLock } from \"../../core/lock/lock.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { nowIso } from \"../../core/shared/time.js\";\nimport { getActiveExtensionRegistrations, runActiveOnWriteHooks } from \"../../core/extensions/index.js\";\nimport { readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings, resolveGovernanceKnobs } from \"../../core/store/settings.js\";\nimport type { HistoryEntry, HistoryPatchOp } from \"../../types/index.js\";\nimport { readHistoryEntries } from \"./history.js\";\nimport { resolveHistorySubject } from \"./history-redact.js\";\n\nexport interface HistoryRepairCommandOptions {\n dryRun?: boolean;\n author?: string;\n message?: string;\n force?: boolean;\n}\n\nexport interface HistoryRepairResult {\n id: string;\n dry_run: boolean;\n changed: boolean;\n history: {\n path: string;\n entries_scanned: number;\n chain_drift_before: boolean;\n entries_rehashed: number;\n entries_patch_repaired: number;\n converted_replace_to_add: number;\n skipped_ops: number;\n reconciled_with_item: boolean;\n audit_entry_added: boolean;\n verify_ok: boolean;\n verify_errors: string[];\n };\n item: {\n exists: boolean;\n path: string | null;\n matched_chain_before: boolean | null;\n };\n warnings: string[];\n generated_at: string;\n}\n\nfunction toAuthor(candidate: string | undefined, defaultAuthor: string): string {\n const resolved = candidate ?? process.env.PM_AUTHOR ?? defaultAuthor;\n const trimmed = resolved.trim();\n return trimmed.length > 0 ? trimmed : \"unknown\";\n}\n\nexport async function runHistoryRepair(\n id: string,\n options: HistoryRepairCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRepairResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const subject = await resolveHistorySubject(pmRoot, id, settings, typeRegistry.type_to_folder);\n\n if (!(await pathExists(subject.historyPath))) {\n throw new PmCliError(`No history stream exists for ${subject.id}.`, EXIT_CODE.NOT_FOUND);\n }\n const historyEntries = await readHistoryEntries(subject.historyPath, subject.id);\n if (historyEntries.length === 0) {\n throw new PmCliError(`No history entries exist for ${subject.id}; nothing to repair.`, EXIT_CODE.USAGE);\n }\n\n const chainBefore = verifyHistoryChain(historyEntries);\n const reanchor = reanchorHistoryEntries(historyEntries);\n\n // Reconcile the replayed chain with the current on-disk item document so the\n // latest after_hash matches what pm validate/health compute for the item.\n let currentItemReplay: ReplayDocument | null = null;\n const currentItemPath: string | null = subject.located?.itemPath ?? null;\n let matchedChainBefore: boolean | null = null;\n const loadedItem = subject.located\n ? await readLocatedItem(subject.located, { schema: settings.schema })\n : null;\n if (loadedItem) {\n // Use the shared canonical replay form so reconciliation hashing matches the\n // semantics pm validate/health use for the on-disk item (avoids hash divergence).\n currentItemReplay = toReplayDocument(loadedItem.document);\n const lastOriginalAfterHash = historyEntries[historyEntries.length - 1]?.after_hash;\n matchedChainBefore = replayHash(currentItemReplay) === lastOriginalAfterHash;\n }\n\n const finalReplay = reanchor.finalDocument;\n const reconcileNeeded =\n currentItemReplay !== null && replayHash(finalReplay) !== replayHash(currentItemReplay);\n\n const changed = reanchor.entriesRehashed > 0 || reanchor.entriesPatchRepaired > 0 || reconcileNeeded;\n const author = toAuthor(options.author, settings.author_default);\n const dryRun = Boolean(options.dryRun);\n\n const repairMessage =\n typeof options.message === \"string\" && options.message.trim().length > 0\n ? options.message\n : `history-repair re-anchored ${reanchor.entriesRehashed} entr${\n reanchor.entriesRehashed === 1 ? \"y\" : \"ies\"\n }${reanchor.entriesPatchRepaired > 0 ? `, repaired ${reanchor.entriesPatchRepaired} patch(es)` : \"\"}${\n reconcileNeeded ? \", reconciled chain with on-disk item\" : \"\"\n }.`;\n\n const rewrittenEntries: HistoryEntry[] = [...reanchor.entries];\n let auditEntryAdded = false;\n if (changed) {\n if (reconcileNeeded && currentItemReplay) {\n rewrittenEntries.push({\n ts: nowIso(),\n author,\n op: \"history_repair\",\n patch: jsonPatch.compare(finalReplay, currentItemReplay) as HistoryPatchOp[],\n before_hash: replayHash(finalReplay),\n after_hash: replayHash(currentItemReplay),\n message: repairMessage,\n });\n } else {\n rewrittenEntries.push({\n ts: nowIso(),\n author,\n op: \"history_repair\",\n patch: [],\n before_hash: replayHash(finalReplay),\n after_hash: replayHash(finalReplay),\n message: repairMessage,\n });\n }\n auditEntryAdded = true;\n }\n\n const historyVerify = verifyHistoryChain(rewrittenEntries);\n if (!historyVerify.ok) {\n throw new PmCliError(\n `history-repair produced an invalid rewritten chain (${historyVerify.errors.join(\", \")}).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n\n const warnings: string[] = [];\n if (!changed) {\n warnings.push(\"history_repair_no_changes\");\n }\n if (reanchor.skippedOps > 0) {\n warnings.push(`history_repair_skipped_unresolvable_ops:${reanchor.skippedOps}`);\n }\n\n if (changed && !dryRun) {\n if (loadedItem) {\n const governance = resolveGovernanceKnobs(settings);\n const assigned = loadedItem.document.metadata.assignee?.trim();\n if (assigned && assigned !== author && !options.force) {\n if (governance.ownership_enforcement === \"strict\") {\n throw new PmCliError(\n `Item ${subject.id} is assigned to ${assigned}. Use --force to override.`,\n EXIT_CODE.CONFLICT,\n );\n }\n if (governance.ownership_enforcement === \"warn\") {\n warnings.push(`ownership_warning:assignee_conflict:${subject.id}:${assigned}`);\n }\n }\n }\n\n const releaseLock = await acquireLock(\n pmRoot,\n subject.id,\n settings.locks.ttl_seconds,\n author,\n Boolean(options.force),\n settings.governance.force_required_for_stale_lock,\n );\n try {\n const previousHistoryRaw = await readFileIfExists(subject.historyPath);\n try {\n await writeFileAtomic(subject.historyPath, historyEntriesToRaw(rewrittenEntries));\n } catch (error) {\n if (previousHistoryRaw === null) {\n await fs.rm(subject.historyPath, { force: true });\n } else {\n await writeFileAtomic(subject.historyPath, previousHistoryRaw);\n }\n throw error;\n }\n warnings.push(\n ...(await runActiveOnWriteHooks({\n path: subject.historyPath,\n scope: \"project\",\n op: \"history_repair:history\",\n })),\n );\n } finally {\n await releaseLock();\n }\n }\n\n return {\n id: subject.id,\n dry_run: dryRun,\n changed,\n history: {\n path: subject.historyPath,\n entries_scanned: historyEntries.length,\n chain_drift_before: !chainBefore.ok,\n entries_rehashed: reanchor.entriesRehashed,\n entries_patch_repaired: reanchor.entriesPatchRepaired,\n converted_replace_to_add: reanchor.convertedReplaceToAdd,\n skipped_ops: reanchor.skippedOps,\n reconciled_with_item: reconcileNeeded,\n audit_entry_added: auditEntryAdded,\n verify_ok: historyVerify.ok,\n verify_errors: historyVerify.errors,\n },\n item: {\n exists: currentItemPath !== null,\n path: currentItemPath,\n matched_chain_before: matchedChainBefore,\n },\n warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),\n generated_at: nowIso(),\n };\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,kBAAkB,GAEnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2B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AK,EAAE,SAAS;gBAChB,EAAE,EAAE,wBAAwB;aAC7B,CAAC,CAAC,CACJ,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,MAAM,WAAW,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,OAAO,EAAE,MAAM;QACf,OAAO;QACP,OAAO,EAAE;YACP,IAAI,EAAE,OAAO,CAAC,WAAW;YACzB,eAAe,EAAE,cAAc,CAAC,MAAM;YACtC,kBAAkB,EAAE,CAAC,WAAW,CAAC,EAAE;YACnC,gBAAgB,EAAE,QAAQ,CAAC,eAAe;YAC1C,sBAAsB,EAAE,QAAQ,CAAC,oBAAoB;YACrD,wBAAwB,EAAE,QAAQ,CAAC,qBAAqB;YACxD,WAAW,EAAE,QAAQ,CAAC,UAAU;YAChC,oBAAoB,EAAE,eAAe;YACrC,iBAAiB,EAAE,eAAe;YAClC,SAAS,EAAE,aAAa,CAAC,EAAE;YAC3B,aAAa,EAAE,aAAa,CAAC,MAAM;SACpC;QACD,IAAI,EAAE;YACJ,MAAM,EAAE,eAAe,KAAK,IAAI;YAChC,IAAI,EAAE,eAAe;YACrB,oBAAoB,EAAE,kBAAkB;SACzC;QACD,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACjF,YAAY,EAAE,MAAM,EAAE;KACvB,CAAC;AACJ,CAAC","debugId":"e227bfe2-45fa-5ebf-a43d-cb679ecbe106"}
@@ -1,9 +1,11 @@
1
1
  import type { GlobalOptions } from "../../core/shared/command-types.js";
2
2
  import type { HistoryEntry } from "../../types/index.js";
3
+ export { verifyHistoryChain } from "../../core/history/replay.js";
3
4
  export interface HistoryCommandOptions {
4
5
  limit?: string;
5
6
  diff?: boolean;
6
7
  verify?: boolean;
8
+ compact?: boolean;
7
9
  }
8
10
  export interface HistoryDiffEntry {
9
11
  index: number;
@@ -24,6 +26,8 @@ export interface HistoryVerificationResult {
24
26
  export interface HistoryResult {
25
27
  id: string;
26
28
  history: HistoryEntry[];
29
+ compact_history?: HistoryDiffEntry[];
30
+ compact: boolean;
27
31
  count: number;
28
32
  limit: number | null;
29
33
  diff?: HistoryDiffEntry[];
@@ -1,6 +1,8 @@
1
- import jsonPatch from "fast-json-patch";
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7dab57b7-674a-5649-ac20-6307a59ce87d")}catch(e){}}();
2
3
  import { pathExists, readFileIfExists } from "../../core/fs/fs-utils.js";
3
4
  import { hashDocument, hashEmptyDocument } from "../../core/history/history.js";
5
+ import { verifyHistoryChain } from "../../core/history/replay.js";
4
6
  import { enforceHistoryStreamPolicyForItem } from "../../core/history/history-stream-policy.js";
5
7
  import { EXIT_CODE } from "../../core/shared/constants.js";
6
8
  import { findFirstMergeConflictMarker } from "../../core/shared/conflict-markers.js";
@@ -12,10 +14,7 @@ import { locateItem, readLocatedItem } from "../../core/store/item-store.js";
12
14
  import { getHistoryPath, getSettingsPath, resolvePmRoot } from "../../core/store/paths.js";
13
15
  import { readSettings } from "../../core/store/settings.js";
14
16
  import { parseLimit } from "../shared-parsers.js";
15
- const EMPTY_REPLAY_DOCUMENT = {
16
- metadata: {},
17
- body: "",
18
- };
17
+ export { verifyHistoryChain } from "../../core/history/replay.js";
19
18
  function limitEntries(values, limit) {
20
19
  if (limit === undefined)
21
20
  return values;
@@ -60,77 +59,6 @@ function buildDiffEntries(entries, startIndex) {
60
59
  };
61
60
  });
62
61
  }
63
- function replayHash(document) {
64
- const itemDocument = {
65
- metadata: document.metadata,
66
- body: document.body,
67
- };
68
- return hashDocument(itemDocument);
69
- }
70
- function normalizeReplayPatchPath(path) {
71
- if (path === "/front_matter") {
72
- return "/metadata";
73
- }
74
- if (path.startsWith("/front_matter/")) {
75
- return `/metadata/${path.slice("/front_matter/".length)}`;
76
- }
77
- return path;
78
- }
79
- function normalizeReplayPatchOps(patch) {
80
- return patch.map((operation) => ({
81
- ...operation,
82
- path: normalizeReplayPatchPath(operation.path),
83
- from: operation.from ? normalizeReplayPatchPath(operation.from) : undefined,
84
- }));
85
- }
86
- function applyHistoryPatch(current, patch, entryNumber) {
87
- try {
88
- const normalizedPatch = normalizeReplayPatchOps(patch);
89
- const applied = jsonPatch.applyPatch(structuredClone(current), normalizedPatch, true, false).newDocument;
90
- if (typeof applied !== "object" ||
91
- applied === null ||
92
- !("metadata" in applied) ||
93
- !("body" in applied) ||
94
- typeof applied.body !== "string" ||
95
- typeof applied.metadata !== "object" ||
96
- applied.metadata === null) {
97
- throw new PmCliError(`History replay produced an invalid document shape at entry ${entryNumber}.`, EXIT_CODE.GENERIC_FAILURE);
98
- }
99
- const replay = applied;
100
- return {
101
- metadata: replay.metadata,
102
- body: replay.body,
103
- };
104
- }
105
- catch {
106
- throw new PmCliError(`Failed to apply history patch at entry ${entryNumber}.`, EXIT_CODE.GENERIC_FAILURE);
107
- }
108
- }
109
- function verifyHistoryChain(entries) {
110
- let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);
111
- for (let index = 0; index < entries.length; index += 1) {
112
- const entry = entries[index];
113
- const beforeHash = replayHash(replay);
114
- if (beforeHash !== entry.before_hash) {
115
- return {
116
- ok: false,
117
- errors: [`verify_failed:before_hash_mismatch:entry_${index + 1}`],
118
- };
119
- }
120
- replay = applyHistoryPatch(replay, entry.patch, index + 1);
121
- const afterHash = replayHash(replay);
122
- if (afterHash !== entry.after_hash) {
123
- return {
124
- ok: false,
125
- errors: [`verify_failed:after_hash_mismatch:entry_${index + 1}`],
126
- };
127
- }
128
- }
129
- return {
130
- ok: true,
131
- errors: [],
132
- };
133
- }
134
62
  export async function readHistoryEntries(historyPath, itemId) {
135
63
  const raw = await readFileIfExists(historyPath);
136
64
  if (raw === null) {
@@ -193,14 +121,18 @@ export async function runHistory(id, options, global) {
193
121
  }
194
122
  const fullHistory = await readHistoryEntries(historyPath, resolvedId);
195
123
  const history = limitEntries(fullHistory, limit);
124
+ const compact = options.compact === true;
125
+ const compactHistory = compact ? buildDiffEntries(history, Math.max(0, fullHistory.length - history.length)) : undefined;
196
126
  const result = {
197
127
  id: resolvedId,
198
- history,
128
+ history: compact ? [] : history,
129
+ compact_history: compactHistory,
130
+ compact,
199
131
  count: history.length,
200
132
  limit: limit ?? null,
201
133
  };
202
134
  if (options.diff) {
203
- result.diff = buildDiffEntries(history, Math.max(0, fullHistory.length - history.length));
135
+ result.diff = compact ? [] : buildDiffEntries(history, Math.max(0, fullHistory.length - history.length));
204
136
  }
205
137
  if (options.verify) {
206
138
  const verification = verifyHistoryChain(fullHistory);
@@ -227,4 +159,5 @@ export async function runHistory(id, options, global) {
227
159
  }
228
160
  return result;
229
161
  }
230
- //# sourceMappingURL=history.js.map
162
+ //# sourceMappingURL=history.js.map
163
+ //# debugId=7dab57b7-674a-5649-ac20-6307a59ce87d
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","sourceRoot":"/","sources":["cli/commands/history.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AAErF,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,oBAAoB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,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;QACtH,IAAI,eAAmC,CAAC;QACxC,IAAI,oBAAyC,CAAC;QAC9C,MAAM,MAAM,GAAG,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QAExC,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YAC3E,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChD,oBAAoB,GAAG,eAAe,KAAK,eAAe,CAAC;YAC3D,IAAI,CAAC,oBAAoB,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;QAED,MAAM,CAAC,YAAY,GAAG;YACpB,EAAE,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YACvB,OAAO,EAAE,WAAW,CAAC,MAAM;YAC3B,MAAM;YACN,iBAAiB,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;YACtG,iBAAiB,EAAE,eAAe;YAClC,sBAAsB,EAAE,oBAAoB;SAC7C,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import jsonPatch from \"fast-json-patch\";\nimport { pathExists, readFileIfExists } from \"../../core/fs/fs-utils.js\";\nimport { hashDocument, hashEmptyDocument } from \"../../core/history/history.js\";\nimport { enforceHistoryStreamPolicyForItem } from \"../../core/history/history-stream-policy.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport { findFirstMergeConflictMarker } from \"../../core/shared/conflict-markers.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { getActiveExtensionRegistrations, runActiveOnReadHooks } from \"../../core/extensions/index.js\";\nimport { normalizeItemId } from \"../../core/item/id.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { parseLimit } from \"../shared-parsers.js\";\nimport type { HistoryEntry, HistoryPatchOp, ItemDocument } from \"../../types/index.js\";\n\nexport interface HistoryCommandOptions {\n limit?: string;\n diff?: boolean;\n verify?: boolean;\n}\n\nexport interface HistoryDiffEntry {\n index: number;\n ts: string;\n op: string;\n author: string;\n patch_ops: number;\n changed_fields: string[];\n}\n\nexport interface HistoryVerificationResult {\n ok: boolean;\n entries: number;\n errors: string[];\n latest_after_hash?: string;\n current_item_hash?: string;\n current_matches_latest?: boolean;\n}\n\nexport interface HistoryResult {\n id: string;\n history: HistoryEntry[];\n count: number;\n limit: number | null;\n diff?: HistoryDiffEntry[];\n verification?: HistoryVerificationResult;\n}\n\ninterface ReplayDocument {\n metadata: Record<string, unknown>;\n body: string;\n}\n\nconst EMPTY_REPLAY_DOCUMENT: ReplayDocument = {\n metadata: {},\n body: \"\",\n};\n\nfunction limitEntries<T>(values: T[], limit: number | undefined): T[] {\n if (limit === undefined) return values;\n return values.slice(Math.max(0, values.length - limit));\n}\n\nfunction decodeJsonPointerSegment(segment: string): string {\n return segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n}\n\nfunction patchPathToChangedField(path: string): string {\n if (path === \"/body\" || path.startsWith(\"/body/\")) {\n return \"body\";\n }\n if (\n path === \"/metadata\" ||\n path.startsWith(\"/metadata/\") ||\n path === \"/front_matter\" ||\n path.startsWith(\"/front_matter/\")\n ) {\n const segment = path.replace(/^\\/(?:metadata|front_matter)\\/?/, \"\").split(\"/\")[0];\n if (!segment) {\n return \"metadata\";\n }\n return decodeJsonPointerSegment(segment);\n }\n const segment = path.replace(/^\\//, \"\").split(\"/\")[0];\n return segment ? decodeJsonPointerSegment(segment) : \"root\";\n}\n\nfunction buildDiffEntries(entries: HistoryEntry[], startIndex: number): HistoryDiffEntry[] {\n return entries.map((entry, index) => {\n const changedFields = new Set<string>();\n for (const op of entry.patch) {\n changedFields.add(patchPathToChangedField(op.path));\n if (op.from) {\n changedFields.add(patchPathToChangedField(op.from));\n }\n }\n return {\n index: startIndex + index + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: entry.patch.length,\n changed_fields: [...changedFields].sort((left, right) => left.localeCompare(right)),\n };\n });\n}\n\nfunction replayHash(document: ReplayDocument): string {\n const itemDocument: ItemDocument = {\n metadata: document.metadata as unknown as ItemDocument[\"metadata\"],\n body: document.body,\n };\n return hashDocument(itemDocument);\n}\n\nfunction normalizeReplayPatchPath(path: string): string {\n if (path === \"/front_matter\") {\n return \"/metadata\";\n }\n if (path.startsWith(\"/front_matter/\")) {\n return `/metadata/${path.slice(\"/front_matter/\".length)}`;\n }\n return path;\n}\n\nfunction normalizeReplayPatchOps(patch: HistoryPatchOp[]): HistoryPatchOp[] {\n return patch.map((operation) => ({\n ...operation,\n path: normalizeReplayPatchPath(operation.path),\n from: operation.from ? normalizeReplayPatchPath(operation.from) : undefined,\n }));\n}\n\nfunction applyHistoryPatch(current: ReplayDocument, patch: HistoryPatchOp[], entryNumber: number): ReplayDocument {\n try {\n const normalizedPatch = normalizeReplayPatchOps(patch);\n const applied = jsonPatch.applyPatch(\n structuredClone(current),\n normalizedPatch as jsonPatch.Operation[],\n true,\n false,\n ).newDocument as unknown;\n if (\n typeof applied !== \"object\" ||\n applied === null ||\n !(\"metadata\" in applied) ||\n !(\"body\" in applied) ||\n typeof (applied as { body: unknown }).body !== \"string\" ||\n typeof (applied as { metadata: unknown }).metadata !== \"object\" ||\n (applied as { metadata: unknown }).metadata === null\n ) {\n throw new PmCliError(\n `History replay produced an invalid document shape at entry ${entryNumber}.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n const replay = applied as { metadata: Record<string, unknown>; body: string };\n return {\n metadata: replay.metadata,\n body: replay.body,\n };\n } catch {\n throw new PmCliError(`Failed to apply history patch at entry ${entryNumber}.`, EXIT_CODE.GENERIC_FAILURE);\n }\n}\n\nfunction verifyHistoryChain(entries: HistoryEntry[]): { ok: boolean; errors: string[] } {\n let replay: ReplayDocument = structuredClone(EMPTY_REPLAY_DOCUMENT);\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n const beforeHash = replayHash(replay);\n if (beforeHash !== entry.before_hash) {\n return {\n ok: false,\n errors: [`verify_failed:before_hash_mismatch:entry_${index + 1}`],\n };\n }\n replay = applyHistoryPatch(replay, entry.patch, index + 1);\n const afterHash = replayHash(replay);\n if (afterHash !== entry.after_hash) {\n return {\n ok: false,\n errors: [`verify_failed:after_hash_mismatch:entry_${index + 1}`],\n };\n }\n }\n return {\n ok: true,\n errors: [],\n };\n}\n\nexport async function readHistoryEntries(historyPath: string, itemId: string): Promise<HistoryEntry[]> {\n const raw = await readFileIfExists(historyPath);\n if (raw === null) {\n return [];\n }\n await runActiveOnReadHooks({\n path: historyPath,\n scope: \"project\",\n });\n if (raw.trim() === \"\") {\n return [];\n }\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `History for ${itemId} contains merge conflict markers at line ${conflictMarker.line} (${conflictMarker.marker}). Resolve <<<<<<< ======= >>>>>>> markers and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n {\n code: \"history_merge_conflict_markers_detected\",\n required: \"Repair the history stream by resolving merge-conflict markers.\",\n why: \"Conflict markers break JSONL parsing and invalidate deterministic audit history.\",\n examples: [`pm history ${itemId}`, `pm restore ${itemId} <timestamp-or-version>`],\n nextSteps: [\"Resolve or restore the history file, then rerun the command.\"],\n },\n );\n }\n\n const entries: HistoryEntry[] = [];\n const lines = raw.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index]?.trim();\n if (!line) continue;\n try {\n entries.push(JSON.parse(line) as HistoryEntry);\n } catch {\n throw new PmCliError(\n `History for ${itemId} contains invalid JSON at line ${index + 1}. Repair or restore the history stream and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n }\n return entries;\n}\n\nexport async function runHistory(id: string, options: HistoryCommandOptions, global: GlobalOptions): Promise<HistoryResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const limit = parseLimit(options.limit);\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const located = await locateItem(\n pmRoot,\n normalizedId,\n settings.id_prefix,\n settings.item_format,\n typeRegistry.type_to_folder,\n );\n const resolvedId = located?.id ?? normalizedId;\n const historyPath = getHistoryPath(pmRoot, resolvedId);\n if (!located && !(await pathExists(historyPath))) {\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n }\n if (located) {\n await enforceHistoryStreamPolicyForItem({\n pmRoot,\n settings,\n itemId: located.id,\n commandLabel: \"history\",\n });\n }\n\n const fullHistory = await readHistoryEntries(historyPath, resolvedId);\n const history = limitEntries(fullHistory, limit);\n const result: HistoryResult = {\n id: resolvedId,\n history,\n count: history.length,\n limit: limit ?? null,\n };\n\n if (options.diff) {\n result.diff = buildDiffEntries(history, Math.max(0, fullHistory.length - history.length));\n }\n\n if (options.verify) {\n const verification = verifyHistoryChain(fullHistory);\n const latestAfterHash = fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : hashEmptyDocument();\n let currentItemHash: string | undefined;\n let currentMatchesLatest: boolean | undefined;\n const errors = [...verification.errors];\n\n if (located) {\n const loaded = await readLocatedItem(located, { schema: settings.schema });\n currentItemHash = hashDocument(loaded.document);\n currentMatchesLatest = currentItemHash === latestAfterHash;\n if (!currentMatchesLatest) {\n errors.push(\"verify_failed:current_item_hash_mismatch\");\n }\n }\n\n result.verification = {\n ok: errors.length === 0,\n entries: fullHistory.length,\n errors,\n latest_after_hash: fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : undefined,\n current_item_hash: currentItemHash,\n current_matches_latest: currentMatchesLatest,\n };\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"history.js","sources":["cli/commands/history.ts"],"sourceRoot":"/","sourcesContent":["import { pathExists, readFileIfExists } from \"../../core/fs/fs-utils.js\";\nimport { hashDocument, hashEmptyDocument } from \"../../core/history/history.js\";\nimport { verifyHistoryChain } from \"../../core/history/replay.js\";\nimport { enforceHistoryStreamPolicyForItem } from \"../../core/history/history-stream-policy.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport { findFirstMergeConflictMarker } from \"../../core/shared/conflict-markers.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { getActiveExtensionRegistrations, runActiveOnReadHooks } from \"../../core/extensions/index.js\";\nimport { normalizeItemId } from \"../../core/item/id.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { parseLimit } from \"../shared-parsers.js\";\nimport type { HistoryEntry } from \"../../types/index.js\";\n\nexport { verifyHistoryChain } from \"../../core/history/replay.js\";\n\nexport interface HistoryCommandOptions {\n limit?: string;\n diff?: boolean;\n verify?: boolean;\n compact?: boolean;\n}\n\nexport interface HistoryDiffEntry {\n index: number;\n ts: string;\n op: string;\n author: string;\n patch_ops: number;\n changed_fields: string[];\n}\n\nexport interface HistoryVerificationResult {\n ok: boolean;\n entries: number;\n errors: string[];\n latest_after_hash?: string;\n current_item_hash?: string;\n current_matches_latest?: boolean;\n}\n\nexport interface HistoryResult {\n id: string;\n history: HistoryEntry[];\n compact_history?: HistoryDiffEntry[];\n compact: boolean;\n count: number;\n limit: number | null;\n diff?: HistoryDiffEntry[];\n verification?: HistoryVerificationResult;\n}\n\nfunction limitEntries<T>(values: T[], limit: number | undefined): T[] {\n if (limit === undefined) return values;\n return values.slice(Math.max(0, values.length - limit));\n}\n\nfunction decodeJsonPointerSegment(segment: string): string {\n return segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n}\n\nfunction patchPathToChangedField(path: string): string {\n if (path === \"/body\" || path.startsWith(\"/body/\")) {\n return \"body\";\n }\n if (\n path === \"/metadata\" ||\n path.startsWith(\"/metadata/\") ||\n path === \"/front_matter\" ||\n path.startsWith(\"/front_matter/\")\n ) {\n const segment = path.replace(/^\\/(?:metadata|front_matter)\\/?/, \"\").split(\"/\")[0];\n if (!segment) {\n return \"metadata\";\n }\n return decodeJsonPointerSegment(segment);\n }\n const segment = path.replace(/^\\//, \"\").split(\"/\")[0];\n return segment ? decodeJsonPointerSegment(segment) : \"root\";\n}\n\nfunction buildDiffEntries(entries: HistoryEntry[], startIndex: number): HistoryDiffEntry[] {\n return entries.map((entry, index) => {\n const changedFields = new Set<string>();\n for (const op of entry.patch) {\n changedFields.add(patchPathToChangedField(op.path));\n if (op.from) {\n changedFields.add(patchPathToChangedField(op.from));\n }\n }\n return {\n index: startIndex + index + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: entry.patch.length,\n changed_fields: [...changedFields].sort((left, right) => left.localeCompare(right)),\n };\n });\n}\n\nexport async function readHistoryEntries(historyPath: string, itemId: string): Promise<HistoryEntry[]> {\n const raw = await readFileIfExists(historyPath);\n if (raw === null) {\n return [];\n }\n await runActiveOnReadHooks({\n path: historyPath,\n scope: \"project\",\n });\n if (raw.trim() === \"\") {\n return [];\n }\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `History for ${itemId} contains merge conflict markers at line ${conflictMarker.line} (${conflictMarker.marker}). Resolve <<<<<<< ======= >>>>>>> markers and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n {\n code: \"history_merge_conflict_markers_detected\",\n required: \"Repair the history stream by resolving merge-conflict markers.\",\n why: \"Conflict markers break JSONL parsing and invalidate deterministic audit history.\",\n examples: [`pm history ${itemId}`, `pm restore ${itemId} <timestamp-or-version>`],\n nextSteps: [\"Resolve or restore the history file, then rerun the command.\"],\n },\n );\n }\n\n const entries: HistoryEntry[] = [];\n const lines = raw.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index]?.trim();\n if (!line) continue;\n try {\n entries.push(JSON.parse(line) as HistoryEntry);\n } catch {\n throw new PmCliError(\n `History for ${itemId} contains invalid JSON at line ${index + 1}. Repair or restore the history stream and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n }\n return entries;\n}\n\nexport async function runHistory(id: string, options: HistoryCommandOptions, global: GlobalOptions): Promise<HistoryResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const limit = parseLimit(options.limit);\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const located = await locateItem(\n pmRoot,\n normalizedId,\n settings.id_prefix,\n settings.item_format,\n typeRegistry.type_to_folder,\n );\n const resolvedId = located?.id ?? normalizedId;\n const historyPath = getHistoryPath(pmRoot, resolvedId);\n if (!located && !(await pathExists(historyPath))) {\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n }\n if (located) {\n await enforceHistoryStreamPolicyForItem({\n pmRoot,\n settings,\n itemId: located.id,\n commandLabel: \"history\",\n });\n }\n\n const fullHistory = await readHistoryEntries(historyPath, resolvedId);\n const history = limitEntries(fullHistory, limit);\n const compact = options.compact === true;\n const compactHistory = compact ? buildDiffEntries(history, Math.max(0, fullHistory.length - history.length)) : undefined;\n const result: HistoryResult = {\n id: resolvedId,\n history: compact ? [] : history,\n compact_history: compactHistory,\n compact,\n count: history.length,\n limit: limit ?? null,\n };\n\n if (options.diff) {\n result.diff = compact ? [] : buildDiffEntries(history, Math.max(0, fullHistory.length - history.length));\n }\n\n if (options.verify) {\n const verification = verifyHistoryChain(fullHistory);\n const latestAfterHash = fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : hashEmptyDocument();\n let currentItemHash: string | undefined;\n let currentMatchesLatest: boolean | undefined;\n const errors = [...verification.errors];\n\n if (located) {\n const loaded = await readLocatedItem(located, { schema: settings.schema });\n currentItemHash = hashDocument(loaded.document);\n currentMatchesLatest = currentItemHash === latestAfterHash;\n if (!currentMatchesLatest) {\n errors.push(\"verify_failed:current_item_hash_mismatch\");\n }\n }\n\n result.verification = {\n ok: errors.length === 0,\n entries: fullHistory.length,\n errors,\n latest_after_hash: fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : undefined,\n current_item_hash: currentItemHash,\n current_matches_latest: currentMatchesLatest,\n };\n }\n\n return result;\n}\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AAErF,OAAO,EAAE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  export { runGet } from "./get.js";
18
18
  export { runHealth } from "./health.js";
19
19
  export { runHistory } from "./history.js";
20
- export { runInit } from "./init.js";
20
+ export { runHistoryRedact, type HistoryRedactCommandOptions, type HistoryRedactResult } from "./history-redact.js";
21
+ export { runHistoryRepair, type HistoryRepairCommandOptions, type HistoryRepairResult } from "./history-repair.js";
22
+ export { runInit, summarizeInitResult, type InitConciseResult } from "./init.js";
21
23
  export { runLearnings } from "./learnings.js";
22
24
  export { runList, type ListOptions } from "./list.js";
23
25
  export { runNotes } from "./notes.js";
26
+ export { runPlan, PLAN_SUBCOMMANDS, PLAN_SHOW_DEPTH_VALUES, type PlanCommandOptions, type PlanCommandResult, type PlanDispatchInput, type PlanResultPlan, type PlanStepSummary, type PlanShowDepth, type PlanSubcommand, } from "./plan.js";
27
+ export { runSchemaAddType, formatSchemaAddTypeHuman, SCHEMA_SUBCOMMANDS, type SchemaSubcommand, type SchemaAddTypeCommandOptions, type SchemaAddTypeResult, } from "./schema.js";
24
28
  export { runSearch } from "./search.js";
25
29
  export { runRestore } from "./restore.js";
26
30
  export { runStats } from "./stats.js";
@@ -1,3 +1,5 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="976d2cdf-7f8e-5cd9-9146-7fdb15fa1512")}catch(e){}}();
1
3
  export { runAppend } from "./append.js";
2
4
  export { runAggregate } from "./aggregate.js";
3
5
  export { runActivity } from "./activity.js";
@@ -17,10 +19,14 @@ export { runGc } from "./gc.js";
17
19
  export { runGet } from "./get.js";
18
20
  export { runHealth } from "./health.js";
19
21
  export { runHistory } from "./history.js";
20
- export { runInit } from "./init.js";
22
+ export { runHistoryRedact } from "./history-redact.js";
23
+ export { runHistoryRepair } from "./history-repair.js";
24
+ export { runInit, summarizeInitResult } from "./init.js";
21
25
  export { runLearnings } from "./learnings.js";
22
26
  export { runList } from "./list.js";
23
27
  export { runNotes } from "./notes.js";
28
+ export { runPlan, PLAN_SUBCOMMANDS, PLAN_SHOW_DEPTH_VALUES, } from "./plan.js";
29
+ export { runSchemaAddType, formatSchemaAddTypeHuman, SCHEMA_SUBCOMMANDS, } from "./schema.js";
24
30
  export { runSearch } from "./search.js";
25
31
  export { runRestore } from "./restore.js";
26
32
  export { runStats } from "./stats.js";
@@ -31,4 +37,5 @@ export { runUpdate } from "./update.js";
31
37
  export { runUpdateMany } from "./update-many.js";
32
38
  export { runUpgrade } from "./upgrade.js";
33
39
  export { runValidate } from "./validate.js";
34
- //# sourceMappingURL=index.js.map
40
+ //# sourceMappingURL=index.js.map
41
+ //# debugId=976d2cdf-7f8e-5cd9-9146-7fdb15fa1512
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["cli/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAA+C,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,QAAQ,EAA8C,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAgD,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,YAAY,EAAsD,MAAM,gBAAgB,CAAC;AAClG,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,UAAU,GAIX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAA6B,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAgD,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAA6D,MAAM,WAAW,CAAC;AACnH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAA6D,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAwD,MAAM,kBAAkB,CAAC;AACvG,OAAO,EAAE,UAAU,EAAkD,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAwE,MAAM,eAAe,CAAC","sourcesContent":["export { runAppend } from \"./append.js\";\nexport { runAggregate, type AggregateOptions, type AggregateResult } from \"./aggregate.js\";\nexport { runActivity } from \"./activity.js\";\nexport { runClaim, runRelease } from \"./claim.js\";\nexport { runClose, type CloseCommandOptions, type CloseResult } from \"./close.js\";\nexport { runComments } from \"./comments.js\";\nexport { runConfig, type ConfigCommandOptions, type ConfigResult } from \"./config.js\";\nexport { runContracts, type ContractsCommandOptions, type ContractsResult } from \"./contracts.js\";\nexport {\n CONTEXT_OUTPUT_VALUES,\n renderContextMarkdown,\n resolveContextOutputFormat,\n runContext,\n type ContextOptions,\n type ContextOutputFormat,\n type ContextResult,\n} from \"./context.js\";\nexport { runCreate, type CreateCommandOptions } from \"./create.js\";\nexport { runDelete, type DeleteCommandOptions, type DeleteResult } from \"./delete.js\";\nexport { runDeps, DEPS_FORMAT_VALUES, type DepsCommandOptions, type DepsFormat, type DepsResult } from \"./deps.js\";\nexport { runDocs } from \"./docs.js\";\nexport { runExtension, type ExtensionCommandOptions, type ExtensionCommandResult } from \"./extension.js\";\nexport { runFiles, runFilesDiscover } from \"./files.js\";\nexport { runGc } from \"./gc.js\";\nexport { runGet } from \"./get.js\";\nexport { runHealth } from \"./health.js\";\nexport { runHistory } from \"./history.js\";\nexport { runInit } from \"./init.js\";\nexport { runLearnings } from \"./learnings.js\";\nexport { runList, type ListOptions } from \"./list.js\";\nexport { runNotes } from \"./notes.js\";\nexport { runSearch } from \"./search.js\";\nexport { runRestore } from \"./restore.js\";\nexport { runStats } from \"./stats.js\";\nexport { runTest } from \"./test.js\";\nexport { runTestAll } from \"./test-all.js\";\nexport {\n runStartBackgroundRun,\n runTestRunsList,\n runTestRunsLogs,\n runTestRunsResume,\n runTestRunsStatus,\n runTestRunsStop,\n runTestRunsWorker,\n} from \"./test-runs.js\";\nexport { runUpdate } from \"./update.js\";\nexport { runUpdateMany, type UpdateManyCommandOptions, type UpdateManyResult } from \"./update-many.js\";\nexport { runUpgrade, type UpgradeCommandOptions, type UpgradeResult } from \"./upgrade.js\";\nexport { runValidate, type ValidateCheck, type ValidateCommandOptions, type ValidateResult } from \"./validate.js\";\n"]}
1
+ {"version":3,"file":"index.js","sources":["cli/commands/index.ts"],"sourceRoot":"/","sourcesContent":["export { runAppend } from \"./append.js\";\nexport { runAggregate, type AggregateOptions, type AggregateResult } from \"./aggregate.js\";\nexport { runActivity } from \"./activity.js\";\nexport { runClaim, runRelease } from \"./claim.js\";\nexport { runClose, type CloseCommandOptions, type CloseResult } from \"./close.js\";\nexport { runComments } from \"./comments.js\";\nexport { runConfig, type ConfigCommandOptions, type ConfigResult } from \"./config.js\";\nexport { runContracts, type ContractsCommandOptions, type ContractsResult } from \"./contracts.js\";\nexport {\n CONTEXT_OUTPUT_VALUES,\n renderContextMarkdown,\n resolveContextOutputFormat,\n runContext,\n type ContextOptions,\n type ContextOutputFormat,\n type ContextResult,\n} from \"./context.js\";\nexport { runCreate, type CreateCommandOptions } from \"./create.js\";\nexport { runDelete, type DeleteCommandOptions, type DeleteResult } from \"./delete.js\";\nexport { runDeps, DEPS_FORMAT_VALUES, type DepsCommandOptions, type DepsFormat, type DepsResult } from \"./deps.js\";\nexport { runDocs } from \"./docs.js\";\nexport { runExtension, type ExtensionCommandOptions, type ExtensionCommandResult } from \"./extension.js\";\nexport { runFiles, runFilesDiscover } from \"./files.js\";\nexport { runGc } from \"./gc.js\";\nexport { runGet } from \"./get.js\";\nexport { runHealth } from \"./health.js\";\nexport { runHistory } from \"./history.js\";\nexport { runHistoryRedact, type HistoryRedactCommandOptions, type HistoryRedactResult } from \"./history-redact.js\";\nexport { runHistoryRepair, type HistoryRepairCommandOptions, type HistoryRepairResult } from \"./history-repair.js\";\nexport { runInit, summarizeInitResult, type InitConciseResult } from \"./init.js\";\nexport { runLearnings } from \"./learnings.js\";\nexport { runList, type ListOptions } from \"./list.js\";\nexport { runNotes } from \"./notes.js\";\nexport {\n runPlan,\n PLAN_SUBCOMMANDS,\n PLAN_SHOW_DEPTH_VALUES,\n type PlanCommandOptions,\n type PlanCommandResult,\n type PlanDispatchInput,\n type PlanResultPlan,\n type PlanStepSummary,\n type PlanShowDepth,\n type PlanSubcommand,\n} from \"./plan.js\";\nexport {\n runSchemaAddType,\n formatSchemaAddTypeHuman,\n SCHEMA_SUBCOMMANDS,\n type SchemaSubcommand,\n type SchemaAddTypeCommandOptions,\n type SchemaAddTypeResult,\n} from \"./schema.js\";\nexport { runSearch } from \"./search.js\";\nexport { runRestore } from \"./restore.js\";\nexport { runStats } from \"./stats.js\";\nexport { runTest } from \"./test.js\";\nexport { runTestAll } from \"./test-all.js\";\nexport {\n runStartBackgroundRun,\n runTestRunsList,\n runTestRunsLogs,\n runTestRunsResume,\n runTestRunsStatus,\n runTestRunsStop,\n runTestRunsWorker,\n} from \"./test-runs.js\";\nexport { runUpdate } from \"./update.js\";\nexport { runUpdateMany, type UpdateManyCommandOptions, type UpdateManyResult } from \"./update-many.js\";\nexport { runUpgrade, type UpgradeCommandOptions, type UpgradeResult } from \"./upgrade.js\";\nexport { runValidate, type ValidateCheck, type ValidateCommandOptions, type ValidateResult } from \"./validate.js\";\n"],"names":[],"mappings":";;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAA+C,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,QAAQ,EAA8C,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAgD,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,YAAY,EAAsD,MAAM,gBAAgB,CAAC;AAClG,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,UAAU,GAIX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAA6B,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,SAAS,EAAgD,MAAM,aAAa,CAAC;AACtF,OAAO,EAA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,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAwD,MAAM,kBAAkB,CAAC;AACvG,OAAO,EAAE,UAAU,EAAkD,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAwE,MAAM,eAAe,CAAC","debugId":"976d2cdf-7f8e-5cd9-9146-7fdb15fa1512"}
@@ -0,0 +1,31 @@
1
+ import type { PmSettings } from "../../types/index.js";
2
+ export type InitAgentGuidanceMode = "ask" | "add" | "skip" | "status";
3
+ export declare const INIT_AGENT_GUIDANCE_MODE_VALUES: InitAgentGuidanceMode[];
4
+ export interface InitAgentGuidanceSummary {
5
+ mode: InitAgentGuidanceMode;
6
+ present: boolean;
7
+ prompted: boolean;
8
+ applied: boolean;
9
+ skipped: boolean;
10
+ declined: boolean;
11
+ prompt_completed: boolean;
12
+ template_version: number;
13
+ target_file: string;
14
+ checked_files: string[];
15
+ files_with_guidance: string[];
16
+ missing_files: string[];
17
+ }
18
+ export interface RunInitAgentGuidanceOptions {
19
+ pm_root: string;
20
+ cwd: string;
21
+ mode: InitAgentGuidanceMode;
22
+ interactive: boolean;
23
+ settings: PmSettings;
24
+ }
25
+ export interface RunInitAgentGuidanceResult {
26
+ summary: InitAgentGuidanceSummary;
27
+ warnings: string[];
28
+ next_steps: string[];
29
+ settings_changed: boolean;
30
+ }
31
+ export declare function runInitAgentGuidance(options: RunInitAgentGuidanceOptions): Promise<RunInitAgentGuidanceResult>;