@unbrained/pm-cli 2026.5.30 → 2026.5.31

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 (228) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli/commands/calendar.js +81 -9
  3. package/dist/cli/commands/calendar.js.map +1 -1
  4. package/dist/cli/commands/create.js +34 -4
  5. package/dist/cli/commands/create.js.map +1 -1
  6. package/dist/cli/commands/extension/install-sources.d.ts +2 -0
  7. package/dist/cli/commands/extension/install-sources.js +11 -4
  8. package/dist/cli/commands/extension/install-sources.js.map +1 -1
  9. package/dist/cli/commands/reindex.js +3 -3
  10. package/dist/cli/commands/reindex.js.map +1 -1
  11. package/dist/cli/commands/search.d.ts +17 -0
  12. package/dist/cli/commands/search.js +40 -10
  13. package/dist/cli/commands/search.js.map +1 -1
  14. package/dist/cli/register-list-query.js +9 -11
  15. package/dist/cli/register-list-query.js.map +1 -1
  16. package/dist/cli/register-mutation.js +20 -22
  17. package/dist/cli/register-mutation.js.map +1 -1
  18. package/dist/cli/register-operations.js +32 -25
  19. package/dist/cli/register-operations.js.map +1 -1
  20. package/dist/cli/register-setup.js +6 -8
  21. package/dist/cli/register-setup.js.map +1 -1
  22. package/dist/cli/registration-helpers.js +6 -3
  23. package/dist/cli/registration-helpers.js.map +1 -1
  24. package/dist/cli/search-refresh.d.ts +2 -0
  25. package/dist/cli/search-refresh.js +13 -0
  26. package/dist/cli/search-refresh.js.map +1 -0
  27. package/dist/cli-bundle/chunks/activity-OWYSUZOY.js +17 -0
  28. package/dist/cli-bundle/chunks/activity-OWYSUZOY.js.map +7 -0
  29. package/dist/cli-bundle/chunks/aggregate-ADUOSFRO.js +209 -0
  30. package/dist/cli-bundle/chunks/aggregate-ADUOSFRO.js.map +7 -0
  31. package/dist/cli-bundle/chunks/append-JD2DETU7.js +73 -0
  32. package/dist/cli-bundle/chunks/append-JD2DETU7.js.map +7 -0
  33. package/dist/cli-bundle/chunks/chunk-3HUE7XOF.js +27 -0
  34. package/dist/cli-bundle/chunks/chunk-3HUE7XOF.js.map +7 -0
  35. package/dist/cli-bundle/chunks/chunk-3M73P3G6.js +1636 -0
  36. package/dist/cli-bundle/chunks/chunk-3M73P3G6.js.map +7 -0
  37. package/dist/cli-bundle/chunks/chunk-4AEZR5EJ.js +189 -0
  38. package/dist/cli-bundle/chunks/chunk-4AEZR5EJ.js.map +7 -0
  39. package/dist/cli-bundle/chunks/chunk-5HSEP75M.js +330 -0
  40. package/dist/cli-bundle/chunks/chunk-5HSEP75M.js.map +7 -0
  41. package/dist/cli-bundle/chunks/chunk-6HT2F4TK.js +1770 -0
  42. package/dist/cli-bundle/chunks/chunk-6HT2F4TK.js.map +7 -0
  43. package/dist/cli-bundle/chunks/chunk-6YCV7WSL.js +552 -0
  44. package/dist/cli-bundle/chunks/chunk-6YCV7WSL.js.map +7 -0
  45. package/dist/cli-bundle/chunks/chunk-7Y53ZJIQ.js +202 -0
  46. package/dist/cli-bundle/chunks/chunk-7Y53ZJIQ.js.map +7 -0
  47. package/dist/cli-bundle/chunks/chunk-A7E7PUVX.js +157 -0
  48. package/dist/cli-bundle/chunks/chunk-A7E7PUVX.js.map +7 -0
  49. package/dist/cli-bundle/chunks/chunk-AKOOMO3T.js +90 -0
  50. package/dist/cli-bundle/chunks/chunk-AKOOMO3T.js.map +7 -0
  51. package/dist/cli-bundle/chunks/chunk-BUPWJ3IJ.js +950 -0
  52. package/dist/cli-bundle/chunks/chunk-BUPWJ3IJ.js.map +7 -0
  53. package/dist/cli-bundle/chunks/chunk-CEFIVZPG.js +79 -0
  54. package/dist/cli-bundle/chunks/chunk-CEFIVZPG.js.map +7 -0
  55. package/dist/cli-bundle/chunks/chunk-D7AOMPRH.js +349 -0
  56. package/dist/cli-bundle/chunks/chunk-D7AOMPRH.js.map +7 -0
  57. package/dist/cli-bundle/chunks/chunk-EAOG77HM.js +56 -0
  58. package/dist/cli-bundle/chunks/chunk-EAOG77HM.js.map +7 -0
  59. package/dist/cli-bundle/chunks/chunk-EGUGFSNX.js +47 -0
  60. package/dist/cli-bundle/chunks/chunk-EGUGFSNX.js.map +7 -0
  61. package/dist/cli-bundle/chunks/chunk-FM26RGSU.js +56 -0
  62. package/dist/cli-bundle/chunks/chunk-FM26RGSU.js.map +7 -0
  63. package/dist/cli-bundle/chunks/chunk-FQE6XZDB.js +435 -0
  64. package/dist/cli-bundle/chunks/chunk-FQE6XZDB.js.map +7 -0
  65. package/dist/cli-bundle/chunks/chunk-G57E5D7T.js +185 -0
  66. package/dist/cli-bundle/chunks/chunk-G57E5D7T.js.map +7 -0
  67. package/dist/cli-bundle/chunks/chunk-GN7IJPCD.js +3621 -0
  68. package/dist/cli-bundle/chunks/chunk-GN7IJPCD.js.map +7 -0
  69. package/dist/cli-bundle/chunks/chunk-JFWUHHS2.js +233 -0
  70. package/dist/cli-bundle/chunks/chunk-JFWUHHS2.js.map +7 -0
  71. package/dist/cli-bundle/chunks/chunk-JTWRXG4B.js +1861 -0
  72. package/dist/cli-bundle/chunks/chunk-JTWRXG4B.js.map +7 -0
  73. package/dist/cli-bundle/chunks/chunk-JULRTHJQ.js +648 -0
  74. package/dist/cli-bundle/chunks/chunk-JULRTHJQ.js.map +7 -0
  75. package/dist/cli-bundle/chunks/{chunk-PB2YU2E3.js → chunk-KBQY3YG5.js} +28 -70
  76. package/dist/cli-bundle/chunks/chunk-KBQY3YG5.js.map +7 -0
  77. package/dist/cli-bundle/chunks/chunk-L2FXEKDB.js +185 -0
  78. package/dist/cli-bundle/chunks/chunk-L2FXEKDB.js.map +7 -0
  79. package/dist/cli-bundle/chunks/chunk-LRBOHPUE.js +189 -0
  80. package/dist/cli-bundle/chunks/chunk-LRBOHPUE.js.map +7 -0
  81. package/dist/cli-bundle/chunks/chunk-LSXGH6NE.js +5153 -0
  82. package/dist/cli-bundle/chunks/chunk-LSXGH6NE.js.map +7 -0
  83. package/dist/cli-bundle/chunks/chunk-MD7K4JYF.js +1345 -0
  84. package/dist/cli-bundle/chunks/chunk-MD7K4JYF.js.map +7 -0
  85. package/dist/cli-bundle/chunks/chunk-NGN7UV5K.js +341 -0
  86. package/dist/cli-bundle/chunks/chunk-NGN7UV5K.js.map +7 -0
  87. package/dist/cli-bundle/chunks/chunk-O7IWB35H.js +18 -0
  88. package/dist/cli-bundle/chunks/chunk-O7IWB35H.js.map +7 -0
  89. package/dist/cli-bundle/chunks/chunk-OGZEG5TT.js +2929 -0
  90. package/dist/cli-bundle/chunks/chunk-OGZEG5TT.js.map +7 -0
  91. package/dist/cli-bundle/chunks/{chunk-RJONRNXN.js → chunk-P53TN6IA.js} +22 -30
  92. package/dist/cli-bundle/chunks/chunk-P53TN6IA.js.map +7 -0
  93. package/dist/cli-bundle/chunks/chunk-PVNQLCIS.js +176 -0
  94. package/dist/cli-bundle/chunks/chunk-PVNQLCIS.js.map +7 -0
  95. package/dist/cli-bundle/chunks/chunk-PXUAZUUY.js +1680 -0
  96. package/dist/cli-bundle/chunks/chunk-PXUAZUUY.js.map +7 -0
  97. package/dist/cli-bundle/chunks/chunk-QAJBIGRA.js +20 -0
  98. package/dist/cli-bundle/chunks/chunk-QAJBIGRA.js.map +7 -0
  99. package/dist/cli-bundle/chunks/chunk-SEXQN4KL.js +60 -0
  100. package/dist/cli-bundle/chunks/chunk-SEXQN4KL.js.map +7 -0
  101. package/dist/cli-bundle/chunks/chunk-U7FMKRXH.js +362 -0
  102. package/dist/cli-bundle/chunks/chunk-U7FMKRXH.js.map +7 -0
  103. package/dist/cli-bundle/chunks/chunk-VGICHR7D.js +141 -0
  104. package/dist/cli-bundle/chunks/chunk-VGICHR7D.js.map +7 -0
  105. package/dist/cli-bundle/chunks/chunk-WDPXDQFG.js +632 -0
  106. package/dist/cli-bundle/chunks/chunk-WDPXDQFG.js.map +7 -0
  107. package/dist/cli-bundle/chunks/chunk-WJ2NAC37.js +252 -0
  108. package/dist/cli-bundle/chunks/chunk-WJ2NAC37.js.map +7 -0
  109. package/dist/cli-bundle/chunks/claim-EE4TKKCV.js +133 -0
  110. package/dist/cli-bundle/chunks/claim-EE4TKKCV.js.map +7 -0
  111. package/dist/cli-bundle/chunks/close-XY4CSAYF.js +14 -0
  112. package/dist/cli-bundle/chunks/close-XY4CSAYF.js.map +7 -0
  113. package/dist/cli-bundle/chunks/comments-AAKJQ6LW.js +104 -0
  114. package/dist/cli-bundle/chunks/comments-AAKJQ6LW.js.map +7 -0
  115. package/dist/cli-bundle/chunks/config-V3FZOKLI.js +1577 -0
  116. package/dist/cli-bundle/chunks/config-V3FZOKLI.js.map +7 -0
  117. package/dist/cli-bundle/chunks/context-RZ5QPNJB.js +1458 -0
  118. package/dist/cli-bundle/chunks/context-RZ5QPNJB.js.map +7 -0
  119. package/dist/cli-bundle/chunks/contracts-YLMH33VU.js +1245 -0
  120. package/dist/cli-bundle/chunks/contracts-YLMH33VU.js.map +7 -0
  121. package/dist/cli-bundle/chunks/create-PZVHRIZQ.js +28 -0
  122. package/dist/cli-bundle/chunks/create-PZVHRIZQ.js.map +7 -0
  123. package/dist/cli-bundle/chunks/delete-RHCTEORS.js +59 -0
  124. package/dist/cli-bundle/chunks/delete-RHCTEORS.js.map +7 -0
  125. package/dist/cli-bundle/chunks/deps-MZYCMLAO.js +229 -0
  126. package/dist/cli-bundle/chunks/deps-MZYCMLAO.js.map +7 -0
  127. package/dist/cli-bundle/chunks/docs-FXXUCZYU.js +35 -0
  128. package/dist/cli-bundle/chunks/docs-FXXUCZYU.js.map +7 -0
  129. package/dist/cli-bundle/chunks/extension-B4WL7BQU.js +25 -0
  130. package/dist/cli-bundle/chunks/extension-B4WL7BQU.js.map +7 -0
  131. package/dist/cli-bundle/chunks/files-WVOX67PE.js +286 -0
  132. package/dist/cli-bundle/chunks/files-WVOX67PE.js.map +7 -0
  133. package/dist/cli-bundle/chunks/gc-JWNF66EC.js +181 -0
  134. package/dist/cli-bundle/chunks/gc-JWNF66EC.js.map +7 -0
  135. package/dist/cli-bundle/chunks/get-LTK3HOCQ.js +198 -0
  136. package/dist/cli-bundle/chunks/get-LTK3HOCQ.js.map +7 -0
  137. package/dist/cli-bundle/chunks/health-TCWL55KM.js +1233 -0
  138. package/dist/cli-bundle/chunks/health-TCWL55KM.js.map +7 -0
  139. package/dist/cli-bundle/chunks/history-A2JUDXUE.js +21 -0
  140. package/dist/cli-bundle/chunks/history-A2JUDXUE.js.map +7 -0
  141. package/dist/cli-bundle/chunks/history-redact-ED6RFCPL.js +20 -0
  142. package/dist/cli-bundle/chunks/history-redact-ED6RFCPL.js.map +7 -0
  143. package/dist/cli-bundle/chunks/history-repair-ZWSTDRH2.js +198 -0
  144. package/dist/cli-bundle/chunks/history-repair-ZWSTDRH2.js.map +7 -0
  145. package/dist/cli-bundle/chunks/init-M2WUB4YH.js +16 -0
  146. package/dist/cli-bundle/chunks/init-M2WUB4YH.js.map +7 -0
  147. package/dist/cli-bundle/chunks/learnings-NXTWE3FR.js +48 -0
  148. package/dist/cli-bundle/chunks/learnings-NXTWE3FR.js.map +7 -0
  149. package/dist/cli-bundle/chunks/list-OGWQPC26.js +20 -0
  150. package/dist/cli-bundle/chunks/list-OGWQPC26.js.map +7 -0
  151. package/dist/cli-bundle/chunks/notes-DFS5ZGOO.js +48 -0
  152. package/dist/cli-bundle/chunks/notes-DFS5ZGOO.js.map +7 -0
  153. package/dist/cli-bundle/chunks/plan-67AB2PLM.js +1175 -0
  154. package/dist/cli-bundle/chunks/plan-67AB2PLM.js.map +7 -0
  155. package/dist/cli-bundle/chunks/{register-list-query-EIVQ5FMR.js → register-list-query-UP3VRUFS.js} +24 -15
  156. package/dist/cli-bundle/chunks/register-list-query-UP3VRUFS.js.map +7 -0
  157. package/dist/cli-bundle/chunks/{register-mutation-RSZNPSGI.js → register-mutation-YWSBF545.js} +38 -28
  158. package/dist/cli-bundle/chunks/register-mutation-YWSBF545.js.map +7 -0
  159. package/dist/cli-bundle/chunks/{register-operations-APUSYDMR.js → register-operations-3BDTGSDH.js} +49 -30
  160. package/dist/cli-bundle/chunks/register-operations-3BDTGSDH.js.map +7 -0
  161. package/dist/cli-bundle/chunks/{register-setup-OZOKSMPJ.js → register-setup-V56GDRUS.js} +21 -12
  162. package/dist/cli-bundle/chunks/register-setup-V56GDRUS.js.map +7 -0
  163. package/dist/cli-bundle/chunks/restore-MB2ISME7.js +18 -0
  164. package/dist/cli-bundle/chunks/restore-MB2ISME7.js.map +7 -0
  165. package/dist/cli-bundle/chunks/schema-Q622KC46.js +119 -0
  166. package/dist/cli-bundle/chunks/schema-Q622KC46.js.map +7 -0
  167. package/dist/cli-bundle/chunks/search-HENBL456.js +1135 -0
  168. package/dist/cli-bundle/chunks/search-HENBL456.js.map +7 -0
  169. package/dist/cli-bundle/chunks/stats-N6H3YP2F.js +124 -0
  170. package/dist/cli-bundle/chunks/stats-N6H3YP2F.js.map +7 -0
  171. package/dist/cli-bundle/chunks/test-VNBDRJ4Z.js +32 -0
  172. package/dist/cli-bundle/chunks/test-VNBDRJ4Z.js.map +7 -0
  173. package/dist/cli-bundle/chunks/test-all-G2AZOHXI.js +332 -0
  174. package/dist/cli-bundle/chunks/test-all-G2AZOHXI.js.map +7 -0
  175. package/dist/cli-bundle/chunks/test-runs-GX5HTPSF.js +939 -0
  176. package/dist/cli-bundle/chunks/test-runs-GX5HTPSF.js.map +7 -0
  177. package/dist/cli-bundle/chunks/update-H6SCWNMA.js +22 -0
  178. package/dist/cli-bundle/chunks/update-H6SCWNMA.js.map +7 -0
  179. package/dist/cli-bundle/chunks/update-many-46HRSP2Q.js +676 -0
  180. package/dist/cli-bundle/chunks/update-many-46HRSP2Q.js.map +7 -0
  181. package/dist/cli-bundle/chunks/upgrade-H5HHM5UV.js +271 -0
  182. package/dist/cli-bundle/chunks/upgrade-H5HHM5UV.js.map +7 -0
  183. package/dist/cli-bundle/chunks/validate-TMCVKIGZ.js +1110 -0
  184. package/dist/cli-bundle/chunks/validate-TMCVKIGZ.js.map +7 -0
  185. package/dist/cli-bundle/main.js +146 -90
  186. package/dist/cli-bundle/main.js.map +4 -4
  187. package/dist/core/item/item-type-definition.js +6 -2
  188. package/dist/core/item/item-type-definition.js.map +1 -1
  189. package/dist/core/item/type-registry.d.ts +4 -0
  190. package/dist/core/item/type-registry.js +10 -2
  191. package/dist/core/item/type-registry.js.map +1 -1
  192. package/dist/core/search/background-refresh.d.ts +53 -0
  193. package/dist/core/search/background-refresh.js +286 -0
  194. package/dist/core/search/background-refresh.js.map +1 -0
  195. package/dist/core/search/cache.d.ts +20 -1
  196. package/dist/core/search/cache.js +33 -4
  197. package/dist/core/search/cache.js.map +1 -1
  198. package/dist/core/search/vector-stores.js +7 -3
  199. package/dist/core/search/vector-stores.js.map +1 -1
  200. package/dist/core/shared/constants.d.ts +2 -2
  201. package/dist/core/shared/constants.js +2 -3
  202. package/dist/core/shared/constants.js.map +1 -1
  203. package/dist/core/store/item-format-migration.js +25 -15
  204. package/dist/core/store/item-format-migration.js.map +1 -1
  205. package/dist/core/store/settings-validator.js +6 -2
  206. package/dist/core/store/settings-validator.js.map +1 -1
  207. package/dist/core/telemetry/runtime.d.ts +10 -0
  208. package/dist/core/telemetry/runtime.js +86 -2
  209. package/dist/core/telemetry/runtime.js.map +1 -1
  210. package/dist/sdk/cli-contracts/tool-parameter-tables.js +4 -4
  211. package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
  212. package/dist/sdk/cli-contracts.js +26 -5
  213. package/dist/sdk/cli-contracts.js.map +1 -1
  214. package/dist/types.d.ts +7 -1
  215. package/dist/types.js +2 -2
  216. package/dist/types.js.map +1 -1
  217. package/docs/RELEASING.md +1 -1
  218. package/package.json +1 -2
  219. package/dist/cli-bundle/chunks/chunk-PB2YU2E3.js.map +0 -7
  220. package/dist/cli-bundle/chunks/chunk-RJONRNXN.js.map +0 -7
  221. package/dist/cli-bundle/chunks/chunk-SW5BMMCU.js +0 -13864
  222. package/dist/cli-bundle/chunks/chunk-SW5BMMCU.js.map +0 -7
  223. package/dist/cli-bundle/chunks/commands-XJ4TJ5UN.js +0 -24225
  224. package/dist/cli-bundle/chunks/commands-XJ4TJ5UN.js.map +0 -7
  225. package/dist/cli-bundle/chunks/register-list-query-EIVQ5FMR.js.map +0 -7
  226. package/dist/cli-bundle/chunks/register-mutation-RSZNPSGI.js.map +0 -7
  227. package/dist/cli-bundle/chunks/register-operations-APUSYDMR.js.map +0 -7
  228. package/dist/cli-bundle/chunks/register-setup-OZOKSMPJ.js.map +0 -7
@@ -0,0 +1,552 @@
1
+ import {
2
+ resolveAuthor
3
+ } from "./chunk-O7IWB35H.js";
4
+ import {
5
+ readHistoryEntries
6
+ } from "./chunk-LRBOHPUE.js";
7
+ import {
8
+ EMPTY_REPLAY_DOCUMENT,
9
+ historyEntriesToRaw,
10
+ replayHash,
11
+ replayToItemDocument,
12
+ tryApplyReplayPatch,
13
+ verifyHistoryChain
14
+ } from "./chunk-JFWUHHS2.js";
15
+ import {
16
+ createHistoryEntry,
17
+ locateItem,
18
+ readLocatedItem
19
+ } from "./chunk-BUPWJ3IJ.js";
20
+ import {
21
+ acquireLock
22
+ } from "./chunk-4AEZR5EJ.js";
23
+ import {
24
+ normalizeItemId,
25
+ normalizeRawItemId
26
+ } from "./chunk-CEFIVZPG.js";
27
+ import {
28
+ canonicalDocument,
29
+ serializeItemDocument
30
+ } from "./chunk-MD7K4JYF.js";
31
+ import {
32
+ resolveItemTypeRegistry
33
+ } from "./chunk-WDPXDQFG.js";
34
+ import {
35
+ nowIso
36
+ } from "./chunk-PVNQLCIS.js";
37
+ import {
38
+ EXIT_CODE,
39
+ PmCliError,
40
+ getActiveExtensionRegistrations,
41
+ getHistoryPath,
42
+ getItemPath,
43
+ getSettingsPath,
44
+ pathExists,
45
+ readFileIfExists,
46
+ readSettings,
47
+ resolveGovernanceKnobs,
48
+ resolvePmRoot,
49
+ runActiveOnWriteHooks,
50
+ writeFileAtomic
51
+ } from "./chunk-LSXGH6NE.js";
52
+
53
+ // dist/cli/commands/history-redact.js
54
+ import fs from "node:fs/promises";
55
+
56
+ // dist/core/history/history-rewrite.js
57
+ !(function() {
58
+ try {
59
+ var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
60
+ n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "6929fbcd-89b7-580d-93fc-f647b086b95f");
61
+ } catch (e2) {
62
+ }
63
+ })();
64
+ function checkHistoryRewriteOwnership(params) {
65
+ if (!params.itemDocument)
66
+ return [];
67
+ const assigned = params.itemDocument.metadata?.assignee?.trim();
68
+ if (!assigned || assigned === params.author || params.force)
69
+ return [];
70
+ const governance = resolveGovernanceKnobs(params.settings);
71
+ if (governance.ownership_enforcement === "strict") {
72
+ throw new PmCliError(`Item ${params.subjectId} is assigned to ${assigned}. Use --force to override.`, EXIT_CODE.CONFLICT);
73
+ }
74
+ if (governance.ownership_enforcement === "warn") {
75
+ return [`ownership_warning:assignee_conflict:${params.subjectId}:${assigned}`];
76
+ }
77
+ return [];
78
+ }
79
+ async function verifyHistoryRewriteNoDrift(params) {
80
+ const historyRawUnderLock = await readFileIfExists(params.subject.historyPath);
81
+ if (historyRawUnderLock !== params.historyRawBeforeLock) {
82
+ throw new PmCliError(`History for ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`, EXIT_CODE.CONFLICT);
83
+ }
84
+ const locatedUnderLock = await locateItem(params.pmRoot, params.subject.id, params.settings.id_prefix, params.settings.item_format, params.typeRegistry.type_to_folder);
85
+ const loadedItemUnderLock = locatedUnderLock ? await readLocatedItem(locatedUnderLock, { schema: params.settings.schema }) : null;
86
+ if ((loadedItemUnderLock?.raw ?? null) !== (params.currentItemRawBeforeLock ?? null)) {
87
+ throw new PmCliError(`Item ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`, EXIT_CODE.CONFLICT);
88
+ }
89
+ return { historyRawUnderLock, locatedUnderLock, loadedItemUnderLock };
90
+ }
91
+
92
+ // dist/cli/commands/history-redact.js
93
+ !(function() {
94
+ try {
95
+ var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
96
+ n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "f92d5c88-f7f6-522f-a15b-fb109875fdac");
97
+ } catch (e2) {
98
+ }
99
+ })();
100
+ function normalizeStringArrayInput(value) {
101
+ if (Array.isArray(value)) {
102
+ return value;
103
+ }
104
+ if (typeof value === "string") {
105
+ return [value];
106
+ }
107
+ return [];
108
+ }
109
+ function normalizeRegexFlags(flags) {
110
+ const unique = [];
111
+ for (const token of flags) {
112
+ if (!unique.includes(token)) {
113
+ unique.push(token);
114
+ }
115
+ }
116
+ if (!unique.includes("g")) {
117
+ unique.push("g");
118
+ }
119
+ return unique.join("");
120
+ }
121
+ function parseRegexRule(spec) {
122
+ const trimmed = spec.trim();
123
+ if (trimmed.length === 0) {
124
+ throw new PmCliError("history-redact --regex requires a non-empty pattern.", EXIT_CODE.USAGE);
125
+ }
126
+ let source = trimmed;
127
+ let flags = "g";
128
+ if (trimmed.startsWith("/") && trimmed.length > 1) {
129
+ const slashIndex = trimmed.lastIndexOf("/");
130
+ if (slashIndex > 0) {
131
+ source = trimmed.slice(1, slashIndex);
132
+ flags = normalizeRegexFlags(trimmed.slice(slashIndex + 1));
133
+ }
134
+ }
135
+ if (source.length === 0) {
136
+ throw new PmCliError("history-redact --regex cannot use an empty pattern.", EXIT_CODE.USAGE);
137
+ }
138
+ try {
139
+ new RegExp(source, flags);
140
+ } catch (error) {
141
+ throw new PmCliError(`Invalid --regex value "${spec}": ${error instanceof Error ? error.message : String(error)}`, EXIT_CODE.USAGE);
142
+ }
143
+ return {
144
+ kind: "regex",
145
+ source,
146
+ flags,
147
+ label: `/${source}/${flags}`
148
+ };
149
+ }
150
+ function buildRedactionRules(literalInput, regexInput) {
151
+ const literalRules = [...new Set(normalizeStringArrayInput(literalInput).map((entry) => entry.trim()))].filter((entry) => entry.length > 0).map((entry) => ({
152
+ kind: "literal",
153
+ value: entry,
154
+ label: entry
155
+ }));
156
+ const regexRules = [...new Set(normalizeStringArrayInput(regexInput).map((entry) => entry.trim()))].filter((entry) => entry.length > 0).map(parseRegexRule);
157
+ const rules = [...literalRules, ...regexRules];
158
+ if (rules.length === 0) {
159
+ throw new PmCliError("history-redact requires at least one matcher via --literal or --regex.", EXIT_CODE.USAGE, {
160
+ code: "missing_required_argument",
161
+ required: "Provide --literal <value> and/or --regex <pattern>.",
162
+ examples: [
163
+ 'pm history-redact pm-a1b2 --literal "[redacted_path_prefix]/private"',
164
+ 'pm history-redact pm-a1b2 --regex "/192\\\\.168\\\\.[0-9.]+/g" --replacement "[scrubbed_ip]"'
165
+ ]
166
+ });
167
+ }
168
+ return rules;
169
+ }
170
+ function applyLiteralRule(value, literal, replacement) {
171
+ if (literal.length === 0) {
172
+ return { value, replacements: 0 };
173
+ }
174
+ let cursor = 0;
175
+ let replacements = 0;
176
+ while (cursor <= value.length) {
177
+ const index = value.indexOf(literal, cursor);
178
+ if (index === -1) {
179
+ break;
180
+ }
181
+ replacements += 1;
182
+ cursor = index + Math.max(1, literal.length);
183
+ }
184
+ if (replacements === 0) {
185
+ return { value, replacements: 0 };
186
+ }
187
+ return {
188
+ value: value.split(literal).join(replacement),
189
+ replacements
190
+ };
191
+ }
192
+ function applyRegexRule(value, rule, replacement) {
193
+ const regex = new RegExp(rule.source, rule.flags);
194
+ const matches = [...value.matchAll(regex)];
195
+ if (matches.length === 0) {
196
+ return { value, replacements: 0 };
197
+ }
198
+ return {
199
+ value: value.replace(regex, replacement),
200
+ replacements: matches.length
201
+ };
202
+ }
203
+ function redactStringValue(value, rules, replacement) {
204
+ let next = value;
205
+ let replacements = 0;
206
+ for (const rule of rules) {
207
+ const result = rule.kind === "literal" ? applyLiteralRule(next, rule.value, replacement) : applyRegexRule(next, rule, replacement);
208
+ next = result.value;
209
+ replacements += result.replacements;
210
+ }
211
+ return {
212
+ value: next,
213
+ replacements
214
+ };
215
+ }
216
+ function redactUnknownValue(value, rules, replacement) {
217
+ if (typeof value === "string") {
218
+ return redactStringValue(value, rules, replacement);
219
+ }
220
+ if (Array.isArray(value)) {
221
+ let replacements = 0;
222
+ const nextValues = value.map((entry) => {
223
+ const redacted = redactUnknownValue(entry, rules, replacement);
224
+ replacements += redacted.replacements;
225
+ return redacted.value;
226
+ });
227
+ return {
228
+ value: nextValues,
229
+ replacements
230
+ };
231
+ }
232
+ if (typeof value === "object" && value !== null) {
233
+ let replacements = 0;
234
+ const nextRecord = {};
235
+ for (const [key, entry] of Object.entries(value)) {
236
+ const redacted = redactUnknownValue(entry, rules, replacement);
237
+ replacements += redacted.replacements;
238
+ nextRecord[key] = redacted.value;
239
+ }
240
+ return {
241
+ value: nextRecord,
242
+ replacements
243
+ };
244
+ }
245
+ return {
246
+ value,
247
+ replacements: 0
248
+ };
249
+ }
250
+ function applyHistoryPatch(current, patch, entryNumber, op) {
251
+ const result = tryApplyReplayPatch(current, patch);
252
+ if (!result.ok) {
253
+ throw new PmCliError(`history-redact failed to apply patch at entry ${entryNumber} (op=${op}): ${result.error instanceof Error ? result.error.message : String(result.error)}`, EXIT_CODE.GENERIC_FAILURE);
254
+ }
255
+ return result.document;
256
+ }
257
+ function inspectHistoryIntegrity(entries) {
258
+ let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);
259
+ let hashMismatchesBefore = 0;
260
+ let hashMismatchesAfter = 0;
261
+ for (let index = 0; index < entries.length; index += 1) {
262
+ const entry = entries[index];
263
+ if (replayHash(replay) !== entry.before_hash) {
264
+ hashMismatchesBefore += 1;
265
+ }
266
+ replay = applyHistoryPatch(replay, entry.patch, index + 1, entry.op);
267
+ if (replayHash(replay) !== entry.after_hash) {
268
+ hashMismatchesAfter += 1;
269
+ }
270
+ }
271
+ return {
272
+ hashMismatchesBefore,
273
+ hashMismatchesAfter,
274
+ finalDocument: replay
275
+ };
276
+ }
277
+ function redactHistoryEntry(entry, rules, replacement) {
278
+ let replacements = 0;
279
+ let changed = false;
280
+ let nextMessage = entry.message;
281
+ if (typeof entry.message === "string") {
282
+ const redactedMessage = redactStringValue(entry.message, rules, replacement);
283
+ nextMessage = redactedMessage.value;
284
+ replacements += redactedMessage.replacements;
285
+ if (redactedMessage.replacements > 0) {
286
+ changed = true;
287
+ }
288
+ }
289
+ const nextPatch = entry.patch.map((operation) => {
290
+ if (!Object.prototype.hasOwnProperty.call(operation, "value")) {
291
+ return operation;
292
+ }
293
+ const redactedValue = redactUnknownValue(operation.value, rules, replacement);
294
+ replacements += redactedValue.replacements;
295
+ if (redactedValue.replacements > 0) {
296
+ changed = true;
297
+ return {
298
+ ...operation,
299
+ value: redactedValue.value
300
+ };
301
+ }
302
+ return operation;
303
+ });
304
+ return {
305
+ entry: {
306
+ ...entry,
307
+ message: nextMessage,
308
+ patch: nextPatch
309
+ },
310
+ replacements,
311
+ changed
312
+ };
313
+ }
314
+ function rewriteHistoryEntries(entries, rules, replacement) {
315
+ let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);
316
+ let entriesChanged = 0;
317
+ let replacements = 0;
318
+ const rewrittenEntries = [];
319
+ for (let index = 0; index < entries.length; index += 1) {
320
+ const redacted = redactHistoryEntry(entries[index], rules, replacement);
321
+ replacements += redacted.replacements;
322
+ if (redacted.changed) {
323
+ entriesChanged += 1;
324
+ }
325
+ const beforeHash = replayHash(replay);
326
+ replay = applyHistoryPatch(replay, redacted.entry.patch, index + 1, redacted.entry.op);
327
+ const afterHash = replayHash(replay);
328
+ rewrittenEntries.push({
329
+ ...redacted.entry,
330
+ before_hash: beforeHash,
331
+ after_hash: afterHash
332
+ });
333
+ }
334
+ return {
335
+ entries: rewrittenEntries,
336
+ finalDocument: replay,
337
+ entriesChanged,
338
+ replacements
339
+ };
340
+ }
341
+ function hasItemMetadata(replay) {
342
+ return Object.keys(replay.metadata).length > 0;
343
+ }
344
+ async function resolveHistorySubject(pmRoot, id, settings, typeToFolder) {
345
+ const located = await locateItem(pmRoot, id, settings.id_prefix, settings.item_format, typeToFolder);
346
+ if (located) {
347
+ return {
348
+ id: located.id,
349
+ historyPath: getHistoryPath(pmRoot, located.id),
350
+ located
351
+ };
352
+ }
353
+ const normalizedId = normalizeItemId(id, settings.id_prefix);
354
+ const rawNormalizedId = normalizeRawItemId(id);
355
+ const candidateIds = normalizedId === rawNormalizedId ? [normalizedId] : [normalizedId, rawNormalizedId];
356
+ for (const candidateId of candidateIds) {
357
+ const historyPath = getHistoryPath(pmRoot, candidateId);
358
+ if (await pathExists(historyPath)) {
359
+ return {
360
+ id: candidateId,
361
+ historyPath,
362
+ located: null
363
+ };
364
+ }
365
+ }
366
+ throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);
367
+ }
368
+ async function runHistoryRedact(id, options, global2) {
369
+ const pmRoot = resolvePmRoot(process.cwd(), global2.path);
370
+ if (!await pathExists(getSettingsPath(pmRoot))) {
371
+ throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);
372
+ }
373
+ const settings = await readSettings(pmRoot);
374
+ const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());
375
+ const replacement = typeof options.replacement === "string" && options.replacement.length > 0 ? options.replacement : "[redacted]";
376
+ const rules = buildRedactionRules(options.literal, options.regex);
377
+ const subject = await resolveHistorySubject(pmRoot, id, settings, typeRegistry.type_to_folder);
378
+ if (!await pathExists(subject.historyPath)) {
379
+ throw new PmCliError(`No history stream exists for ${subject.id}.`, EXIT_CODE.NOT_FOUND);
380
+ }
381
+ const historyRawBeforeLock = await readFileIfExists(subject.historyPath);
382
+ const historyEntries = await readHistoryEntries(subject.historyPath, subject.id);
383
+ if (historyEntries.length === 0) {
384
+ throw new PmCliError(`No history entries exist for ${subject.id}; nothing to redact.`, EXIT_CODE.USAGE);
385
+ }
386
+ const integritySnapshot = inspectHistoryIntegrity(historyEntries);
387
+ const rewritten = rewriteHistoryEntries(historyEntries, rules, replacement);
388
+ const preexistingHashMismatches = integritySnapshot.hashMismatchesBefore + integritySnapshot.hashMismatchesAfter;
389
+ const dryRun = Boolean(options.dryRun);
390
+ const changed = rewritten.replacements > 0;
391
+ const warnings = [];
392
+ if (preexistingHashMismatches > 0) {
393
+ warnings.push(`history_redact_preexisting_hash_mismatches:${preexistingHashMismatches}`);
394
+ }
395
+ if (!changed) {
396
+ warnings.push("history_redact_no_matches");
397
+ }
398
+ let currentItemRaw = null;
399
+ let currentItemPath = subject.located?.itemPath ?? null;
400
+ let currentItemDocument = null;
401
+ if (subject.located) {
402
+ const loaded = await readLocatedItem(subject.located, { schema: settings.schema });
403
+ currentItemRaw = loaded.raw;
404
+ currentItemDocument = loaded.document;
405
+ }
406
+ let nextItemPath = null;
407
+ let nextItemRaw = null;
408
+ let nextItemDocument = null;
409
+ if (hasItemMetadata(rewritten.finalDocument)) {
410
+ const canonical = canonicalDocument(replayToItemDocument(rewritten.finalDocument), { schema: settings.schema });
411
+ if (canonical.metadata.id !== subject.id) {
412
+ throw new PmCliError(`history-redact would change item id from ${subject.id} to ${canonical.metadata.id}; narrow your patterns.`, EXIT_CODE.USAGE);
413
+ }
414
+ nextItemDocument = canonical;
415
+ nextItemPath = getItemPath(pmRoot, canonical.metadata.type, subject.id, "toon", typeRegistry.type_to_folder);
416
+ nextItemRaw = serializeItemDocument(canonical, {
417
+ format: "toon",
418
+ schema: settings.schema
419
+ });
420
+ }
421
+ const itemChanged = (currentItemPath ?? null) !== (nextItemPath ?? null) || (currentItemRaw ?? null) !== (nextItemRaw ?? null);
422
+ const author = resolveAuthor(options.author, settings.author_default);
423
+ const redactionMessage = typeof options.message === "string" && options.message.trim().length > 0 ? options.message : `history-redact replaced ${rewritten.replacements} match(es) across ${rewritten.entriesChanged} entr${rewritten.entriesChanged === 1 ? "y" : "ies"}.`;
424
+ const rewrittenEntries = [...rewritten.entries];
425
+ let auditEntryAdded = false;
426
+ if (!dryRun && changed) {
427
+ const finalDocument = nextItemDocument ?? replayToItemDocument(rewritten.finalDocument);
428
+ rewrittenEntries.push(createHistoryEntry({
429
+ nowIso: nowIso(),
430
+ author,
431
+ op: "history_redact",
432
+ before: finalDocument,
433
+ after: finalDocument,
434
+ message: redactionMessage
435
+ }));
436
+ auditEntryAdded = true;
437
+ }
438
+ const historyVerify = verifyHistoryChain(rewrittenEntries);
439
+ if (!historyVerify.ok) {
440
+ throw new PmCliError(`history-redact produced an invalid rewritten chain (${historyVerify.errors.join(", ")}).`, EXIT_CODE.GENERIC_FAILURE);
441
+ }
442
+ if (!dryRun && changed) {
443
+ warnings.push(...checkHistoryRewriteOwnership({
444
+ itemDocument: currentItemDocument,
445
+ subjectId: subject.id,
446
+ author,
447
+ force: options.force,
448
+ settings
449
+ }));
450
+ const releaseLock = await acquireLock(pmRoot, subject.id, settings.locks.ttl_seconds, author, Boolean(options.force), settings.governance.force_required_for_stale_lock);
451
+ try {
452
+ const { historyRawUnderLock } = await verifyHistoryRewriteNoDrift({
453
+ pmRoot,
454
+ subject,
455
+ settings,
456
+ typeRegistry,
457
+ historyRawBeforeLock,
458
+ currentItemRawBeforeLock: currentItemRaw,
459
+ operation: "history-redact"
460
+ });
461
+ const affectedItemPaths = /* @__PURE__ */ new Set();
462
+ if (currentItemPath) {
463
+ affectedItemPaths.add(currentItemPath);
464
+ }
465
+ if (nextItemPath) {
466
+ affectedItemPaths.add(nextItemPath);
467
+ }
468
+ const itemSnapshots = /* @__PURE__ */ new Map();
469
+ if (currentItemPath && currentItemRaw !== null) {
470
+ itemSnapshots.set(currentItemPath, currentItemRaw);
471
+ }
472
+ try {
473
+ if (nextItemPath && nextItemRaw !== null && nextItemRaw !== currentItemRaw) {
474
+ await writeFileAtomic(nextItemPath, nextItemRaw);
475
+ }
476
+ if (currentItemPath && (!nextItemPath || nextItemPath !== currentItemPath)) {
477
+ await fs.rm(currentItemPath, { force: true });
478
+ }
479
+ await writeFileAtomic(subject.historyPath, historyEntriesToRaw(rewrittenEntries));
480
+ } catch (error) {
481
+ if (historyRawUnderLock === null) {
482
+ await fs.rm(subject.historyPath, { force: true });
483
+ } else {
484
+ await writeFileAtomic(subject.historyPath, historyRawUnderLock);
485
+ }
486
+ for (const itemPath of affectedItemPaths) {
487
+ const snapshot = itemSnapshots.get(itemPath);
488
+ if (snapshot === void 0) {
489
+ await fs.rm(itemPath, { force: true });
490
+ } else {
491
+ await writeFileAtomic(itemPath, snapshot);
492
+ }
493
+ }
494
+ throw error;
495
+ }
496
+ const itemHookPath = nextItemPath ?? currentItemPath;
497
+ if (itemHookPath) {
498
+ warnings.push(...await runActiveOnWriteHooks({
499
+ path: itemHookPath,
500
+ scope: "project",
501
+ op: "history_redact"
502
+ }));
503
+ }
504
+ warnings.push(...await runActiveOnWriteHooks({
505
+ path: subject.historyPath,
506
+ scope: "project",
507
+ op: "history_redact:history"
508
+ }));
509
+ } finally {
510
+ await releaseLock();
511
+ }
512
+ }
513
+ return {
514
+ id: subject.id,
515
+ dry_run: dryRun,
516
+ changed,
517
+ patterns: {
518
+ literals: rules.filter((rule) => rule.kind === "literal").map((rule) => rule.value),
519
+ regex: rules.filter((rule) => rule.kind === "regex").map((rule) => `/${rule.source}/${rule.flags}`),
520
+ replacement
521
+ },
522
+ history: {
523
+ path: subject.historyPath,
524
+ entries_scanned: historyEntries.length,
525
+ entries_changed: rewritten.entriesChanged,
526
+ replacements: rewritten.replacements,
527
+ hash_mismatches_before: integritySnapshot.hashMismatchesBefore,
528
+ hash_mismatches_after: integritySnapshot.hashMismatchesAfter,
529
+ preexisting_hash_mismatches: preexistingHashMismatches,
530
+ audit_entry_added: auditEntryAdded,
531
+ verify_ok: historyVerify.ok,
532
+ verify_errors: historyVerify.errors
533
+ },
534
+ item: {
535
+ existed_before: currentItemPath !== null,
536
+ exists_after: nextItemPath !== null,
537
+ path_before: currentItemPath,
538
+ path_after: nextItemPath,
539
+ changed: itemChanged
540
+ },
541
+ warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),
542
+ generated_at: nowIso()
543
+ };
544
+ }
545
+
546
+ export {
547
+ checkHistoryRewriteOwnership,
548
+ verifyHistoryRewriteNoDrift,
549
+ resolveHistorySubject,
550
+ runHistoryRedact
551
+ };
552
+ //# sourceMappingURL=chunk-6YCV7WSL.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../cli/commands/history-redact.ts", "../../../../../../../../core/history/history-rewrite.ts"],
4
+ "sourcesContent": ["import fs from \"node:fs/promises\";\nimport { pathExists, readFileIfExists, writeFileAtomic } from \"../../core/fs/fs-utils.js\";\nimport { createHistoryEntry } from \"../../core/history/history.js\";\nimport {\n checkHistoryRewriteOwnership,\n verifyHistoryRewriteNoDrift,\n} from \"../../core/history/history-rewrite.js\";\nimport {\n EMPTY_REPLAY_DOCUMENT,\n historyEntriesToRaw,\n replayHash,\n replayToItemDocument,\n tryApplyReplayPatch,\n verifyHistoryChain,\n type ReplayDocument,\n} from \"../../core/history/replay.js\";\nimport { normalizeItemId, normalizeRawItemId } from \"../../core/item/id.js\";\nimport { canonicalDocument, serializeItemDocument } from \"../../core/item/item-format.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 { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getItemPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { resolveAuthor } from \"../../core/shared/author.js\";\nimport type { HistoryEntry, HistoryPatchOp, ItemDocument } from \"../../types/index.js\";\nimport { readHistoryEntries } from \"./history.js\";\n\nexport interface HistoryRedactCommandOptions {\n literal?: string[] | string;\n regex?: string[] | string;\n replacement?: string;\n dryRun?: boolean;\n author?: string;\n message?: string;\n force?: boolean;\n}\n\ninterface RegexRule {\n kind: \"regex\";\n source: string;\n flags: string;\n label: string;\n}\n\ninterface LiteralRule {\n kind: \"literal\";\n value: string;\n label: string;\n}\n\ntype RedactionRule = RegexRule | LiteralRule;\n\ninterface RedactionRewriteResult {\n entries: HistoryEntry[];\n finalDocument: ReplayDocument;\n entriesChanged: number;\n replacements: number;\n}\n\ninterface HistoryIntegritySnapshot {\n hashMismatchesBefore: number;\n hashMismatchesAfter: number;\n finalDocument: ReplayDocument;\n}\n\nexport interface HistorySubject {\n id: string;\n historyPath: string;\n located: Awaited<ReturnType<typeof locateItem>>;\n}\n\nexport interface HistoryRedactResult {\n id: string;\n dry_run: boolean;\n changed: boolean;\n patterns: {\n literals: string[];\n regex: string[];\n replacement: string;\n };\n history: {\n path: string;\n entries_scanned: number;\n entries_changed: number;\n replacements: number;\n hash_mismatches_before: number;\n hash_mismatches_after: number;\n preexisting_hash_mismatches: number;\n audit_entry_added: boolean;\n verify_ok: boolean;\n verify_errors: string[];\n };\n item: {\n existed_before: boolean;\n exists_after: boolean;\n path_before: string | null;\n path_after: string | null;\n changed: boolean;\n };\n warnings: string[];\n generated_at: string;\n}\n\nfunction normalizeStringArrayInput(value: string[] | string | undefined): string[] {\n if (Array.isArray(value)) {\n return value;\n }\n if (typeof value === \"string\") {\n return [value];\n }\n return [];\n}\n\nfunction normalizeRegexFlags(flags: string): string {\n const unique: string[] = [];\n for (const token of flags) {\n if (!unique.includes(token)) {\n unique.push(token);\n }\n }\n if (!unique.includes(\"g\")) {\n unique.push(\"g\");\n }\n return unique.join(\"\");\n}\n\nfunction parseRegexRule(spec: string): RegexRule {\n const trimmed = spec.trim();\n if (trimmed.length === 0) {\n throw new PmCliError(\"history-redact --regex requires a non-empty pattern.\", EXIT_CODE.USAGE);\n }\n\n let source = trimmed;\n let flags = \"g\";\n if (trimmed.startsWith(\"/\") && trimmed.length > 1) {\n const slashIndex = trimmed.lastIndexOf(\"/\");\n if (slashIndex > 0) {\n source = trimmed.slice(1, slashIndex);\n flags = normalizeRegexFlags(trimmed.slice(slashIndex + 1));\n }\n }\n if (source.length === 0) {\n throw new PmCliError(\"history-redact --regex cannot use an empty pattern.\", EXIT_CODE.USAGE);\n }\n try {\n new RegExp(source, flags);\n } catch (error) {\n throw new PmCliError(\n `Invalid --regex value \"${spec}\": ${error instanceof Error ? error.message : String(error)}`,\n EXIT_CODE.USAGE,\n );\n }\n\n return {\n kind: \"regex\",\n source,\n flags,\n label: `/${source}/${flags}`,\n };\n}\n\nfunction buildRedactionRules(\n literalInput: string[] | string | undefined,\n regexInput: string[] | string | undefined,\n): RedactionRule[] {\n const literalRules = [...new Set(normalizeStringArrayInput(literalInput).map((entry) => entry.trim()))]\n .filter((entry) => entry.length > 0)\n .map<LiteralRule>((entry) => ({\n kind: \"literal\",\n value: entry,\n label: entry,\n }));\n const regexRules = [...new Set(normalizeStringArrayInput(regexInput).map((entry) => entry.trim()))]\n .filter((entry) => entry.length > 0)\n .map(parseRegexRule);\n\n const rules = [...literalRules, ...regexRules];\n if (rules.length === 0) {\n throw new PmCliError(\n \"history-redact requires at least one matcher via --literal or --regex.\",\n EXIT_CODE.USAGE,\n {\n code: \"missing_required_argument\",\n required: \"Provide --literal <value> and/or --regex <pattern>.\",\n examples: [\n 'pm history-redact pm-a1b2 --literal \"[redacted_path_prefix]/private\"',\n 'pm history-redact pm-a1b2 --regex \"/192\\\\\\\\.168\\\\\\\\.[0-9.]+/g\" --replacement \"[scrubbed_ip]\"',\n ],\n },\n );\n }\n return rules;\n}\n\nfunction applyLiteralRule(value: string, literal: string, replacement: string): { value: string; replacements: number } {\n if (literal.length === 0) {\n return { value, replacements: 0 };\n }\n let cursor = 0;\n let replacements = 0;\n while (cursor <= value.length) {\n const index = value.indexOf(literal, cursor);\n if (index === -1) {\n break;\n }\n replacements += 1;\n cursor = index + Math.max(1, literal.length);\n }\n if (replacements === 0) {\n return { value, replacements: 0 };\n }\n return {\n value: value.split(literal).join(replacement),\n replacements,\n };\n}\n\nfunction applyRegexRule(value: string, rule: RegexRule, replacement: string): { value: string; replacements: number } {\n const regex = new RegExp(rule.source, rule.flags);\n const matches = [...value.matchAll(regex)];\n if (matches.length === 0) {\n return { value, replacements: 0 };\n }\n return {\n value: value.replace(regex, replacement),\n replacements: matches.length,\n };\n}\n\nfunction redactStringValue(value: string, rules: RedactionRule[], replacement: string): { value: string; replacements: number } {\n let next = value;\n let replacements = 0;\n for (const rule of rules) {\n const result =\n rule.kind === \"literal\"\n ? applyLiteralRule(next, rule.value, replacement)\n : applyRegexRule(next, rule, replacement);\n next = result.value;\n replacements += result.replacements;\n }\n return {\n value: next,\n replacements,\n };\n}\n\nfunction redactUnknownValue(value: unknown, rules: RedactionRule[], replacement: string): { value: unknown; replacements: number } {\n if (typeof value === \"string\") {\n return redactStringValue(value, rules, replacement);\n }\n if (Array.isArray(value)) {\n let replacements = 0;\n const nextValues = value.map((entry) => {\n const redacted = redactUnknownValue(entry, rules, replacement);\n replacements += redacted.replacements;\n return redacted.value;\n });\n return {\n value: nextValues,\n replacements,\n };\n }\n if (typeof value === \"object\" && value !== null) {\n let replacements = 0;\n const nextRecord: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n const redacted = redactUnknownValue(entry, rules, replacement);\n replacements += redacted.replacements;\n nextRecord[key] = redacted.value;\n }\n return {\n value: nextRecord,\n replacements,\n };\n }\n return {\n value,\n replacements: 0,\n };\n}\n\nfunction applyHistoryPatch(current: ReplayDocument, patch: HistoryPatchOp[], entryNumber: number, op: string): ReplayDocument {\n const result = tryApplyReplayPatch(current, patch);\n if (!result.ok) {\n throw new PmCliError(\n `history-redact failed to apply patch at entry ${entryNumber} (op=${op}): ${\n result.error instanceof Error ? result.error.message : String(result.error)\n }`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n return result.document;\n}\n\nfunction inspectHistoryIntegrity(entries: HistoryEntry[]): HistoryIntegritySnapshot {\n let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);\n let hashMismatchesBefore = 0;\n let hashMismatchesAfter = 0;\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n if (replayHash(replay) !== entry.before_hash) {\n hashMismatchesBefore += 1;\n }\n replay = applyHistoryPatch(replay, entry.patch, index + 1, entry.op);\n if (replayHash(replay) !== entry.after_hash) {\n hashMismatchesAfter += 1;\n }\n }\n return {\n hashMismatchesBefore,\n hashMismatchesAfter,\n finalDocument: replay,\n };\n}\n\nfunction redactHistoryEntry(entry: HistoryEntry, rules: RedactionRule[], replacement: string): {\n entry: HistoryEntry;\n replacements: number;\n changed: boolean;\n} {\n let replacements = 0;\n let changed = false;\n let nextMessage = entry.message;\n\n if (typeof entry.message === \"string\") {\n const redactedMessage = redactStringValue(entry.message, rules, replacement);\n nextMessage = redactedMessage.value;\n replacements += redactedMessage.replacements;\n if (redactedMessage.replacements > 0) {\n changed = true;\n }\n }\n\n const nextPatch = entry.patch.map((operation) => {\n if (!Object.prototype.hasOwnProperty.call(operation, \"value\")) {\n return operation;\n }\n const redactedValue = redactUnknownValue(operation.value, rules, replacement);\n replacements += redactedValue.replacements;\n if (redactedValue.replacements > 0) {\n changed = true;\n return {\n ...operation,\n value: redactedValue.value,\n };\n }\n return operation;\n });\n\n return {\n entry: {\n ...entry,\n message: nextMessage,\n patch: nextPatch,\n },\n replacements,\n changed,\n };\n}\n\nfunction rewriteHistoryEntries(entries: HistoryEntry[], rules: RedactionRule[], replacement: string): RedactionRewriteResult {\n let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);\n let entriesChanged = 0;\n let replacements = 0;\n const rewrittenEntries: HistoryEntry[] = [];\n\n for (let index = 0; index < entries.length; index += 1) {\n const redacted = redactHistoryEntry(entries[index], rules, replacement);\n replacements += redacted.replacements;\n if (redacted.changed) {\n entriesChanged += 1;\n }\n const beforeHash = replayHash(replay);\n replay = applyHistoryPatch(replay, redacted.entry.patch, index + 1, redacted.entry.op);\n const afterHash = replayHash(replay);\n rewrittenEntries.push({\n ...redacted.entry,\n before_hash: beforeHash,\n after_hash: afterHash,\n });\n }\n\n return {\n entries: rewrittenEntries,\n finalDocument: replay,\n entriesChanged,\n replacements,\n };\n}\n\nfunction hasItemMetadata(replay: ReplayDocument): boolean {\n return Object.keys(replay.metadata).length > 0;\n}\n\nexport async function resolveHistorySubject(\n pmRoot: string,\n id: string,\n settings: Awaited<ReturnType<typeof readSettings>>,\n typeToFolder: Record<string, string>,\n): Promise<HistorySubject> {\n const located = await locateItem(pmRoot, id, settings.id_prefix, settings.item_format, typeToFolder);\n if (located) {\n return {\n id: located.id,\n historyPath: getHistoryPath(pmRoot, located.id),\n located,\n };\n }\n\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const rawNormalizedId = normalizeRawItemId(id);\n const candidateIds = normalizedId === rawNormalizedId ? [normalizedId] : [normalizedId, rawNormalizedId];\n for (const candidateId of candidateIds) {\n const historyPath = getHistoryPath(pmRoot, candidateId);\n if (await pathExists(historyPath)) {\n return {\n id: candidateId,\n historyPath,\n located: null,\n };\n }\n }\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n}\n\nexport async function runHistoryRedact(\n id: string,\n options: HistoryRedactCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRedactResult> {\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 replacement = typeof options.replacement === \"string\" && options.replacement.length > 0 ? options.replacement : \"[redacted]\";\n const rules = buildRedactionRules(options.literal, options.regex);\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 historyRawBeforeLock = await readFileIfExists(subject.historyPath);\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 redact.`, EXIT_CODE.USAGE);\n }\n\n const integritySnapshot = inspectHistoryIntegrity(historyEntries);\n const rewritten = rewriteHistoryEntries(historyEntries, rules, replacement);\n const preexistingHashMismatches = integritySnapshot.hashMismatchesBefore + integritySnapshot.hashMismatchesAfter;\n const dryRun = Boolean(options.dryRun);\n const changed = rewritten.replacements > 0;\n const warnings: string[] = [];\n if (preexistingHashMismatches > 0) {\n warnings.push(`history_redact_preexisting_hash_mismatches:${preexistingHashMismatches}`);\n }\n if (!changed) {\n warnings.push(\"history_redact_no_matches\");\n }\n\n let currentItemRaw: string | null = null;\n let currentItemPath: string | null = subject.located?.itemPath ?? null;\n let currentItemDocument: ItemDocument | null = null;\n if (subject.located) {\n const loaded = await readLocatedItem(subject.located, { schema: settings.schema });\n currentItemRaw = loaded.raw;\n currentItemDocument = loaded.document;\n }\n\n let nextItemPath: string | null = null;\n let nextItemRaw: string | null = null;\n let nextItemDocument: ItemDocument | null = null;\n if (hasItemMetadata(rewritten.finalDocument)) {\n const canonical = canonicalDocument(replayToItemDocument(rewritten.finalDocument), { schema: settings.schema });\n if (canonical.metadata.id !== subject.id) {\n throw new PmCliError(\n `history-redact would change item id from ${subject.id} to ${canonical.metadata.id}; narrow your patterns.`,\n EXIT_CODE.USAGE,\n );\n }\n nextItemDocument = canonical;\n nextItemPath = getItemPath(pmRoot, canonical.metadata.type, subject.id, \"toon\", typeRegistry.type_to_folder);\n nextItemRaw = serializeItemDocument(canonical, {\n format: \"toon\",\n schema: settings.schema,\n });\n }\n\n const itemChanged =\n (currentItemPath ?? null) !== (nextItemPath ?? null) ||\n (currentItemRaw ?? null) !== (nextItemRaw ?? null);\n\n const author = resolveAuthor(options.author, settings.author_default);\n const redactionMessage =\n typeof options.message === \"string\" && options.message.trim().length > 0\n ? options.message\n : `history-redact replaced ${rewritten.replacements} match(es) across ${rewritten.entriesChanged} entr${\n rewritten.entriesChanged === 1 ? \"y\" : \"ies\"\n }.`;\n\n const rewrittenEntries = [...rewritten.entries];\n let auditEntryAdded = false;\n if (!dryRun && changed) {\n const finalDocument = nextItemDocument ?? replayToItemDocument(rewritten.finalDocument);\n rewrittenEntries.push(\n createHistoryEntry({\n nowIso: nowIso(),\n author,\n op: \"history_redact\",\n before: finalDocument,\n after: finalDocument,\n message: redactionMessage,\n }),\n );\n auditEntryAdded = true;\n }\n const historyVerify = verifyHistoryChain(rewrittenEntries);\n if (!historyVerify.ok) {\n throw new PmCliError(\n `history-redact produced an invalid rewritten chain (${historyVerify.errors.join(\", \")}).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n\n if (!dryRun && changed) {\n warnings.push(\n ...checkHistoryRewriteOwnership({\n itemDocument: currentItemDocument,\n subjectId: subject.id,\n author,\n force: options.force,\n settings,\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 { historyRawUnderLock } = await verifyHistoryRewriteNoDrift({\n pmRoot,\n subject,\n settings,\n typeRegistry,\n historyRawBeforeLock,\n currentItemRawBeforeLock: currentItemRaw,\n operation: \"history-redact\",\n });\n const affectedItemPaths = new Set<string>();\n if (currentItemPath) {\n affectedItemPaths.add(currentItemPath);\n }\n if (nextItemPath) {\n affectedItemPaths.add(nextItemPath);\n }\n const itemSnapshots = new Map<string, string>();\n if (currentItemPath && currentItemRaw !== null) {\n itemSnapshots.set(currentItemPath, currentItemRaw);\n }\n\n try {\n if (nextItemPath && nextItemRaw !== null && nextItemRaw !== currentItemRaw) {\n await writeFileAtomic(nextItemPath, nextItemRaw);\n }\n if (currentItemPath && (!nextItemPath || nextItemPath !== currentItemPath)) {\n await fs.rm(currentItemPath, { force: true });\n }\n await writeFileAtomic(subject.historyPath, historyEntriesToRaw(rewrittenEntries));\n } catch (error) {\n if (historyRawUnderLock === null) {\n await fs.rm(subject.historyPath, { force: true });\n } else {\n await writeFileAtomic(subject.historyPath, historyRawUnderLock);\n }\n for (const itemPath of affectedItemPaths) {\n const snapshot = itemSnapshots.get(itemPath);\n if (snapshot === undefined) {\n await fs.rm(itemPath, { force: true });\n } else {\n await writeFileAtomic(itemPath, snapshot);\n }\n }\n throw error;\n }\n\n const itemHookPath = nextItemPath ?? currentItemPath;\n if (itemHookPath) {\n warnings.push(\n ...(await runActiveOnWriteHooks({\n path: itemHookPath,\n scope: \"project\",\n op: \"history_redact\",\n })),\n );\n }\n warnings.push(\n ...(await runActiveOnWriteHooks({\n path: subject.historyPath,\n scope: \"project\",\n op: \"history_redact:history\",\n })),\n );\n } finally {\n await releaseLock();\n }\n }\n\n return {\n id: subject.id,\n dry_run: dryRun,\n changed,\n patterns: {\n literals: rules.filter((rule): rule is LiteralRule => rule.kind === \"literal\").map((rule) => rule.value),\n regex: rules.filter((rule): rule is RegexRule => rule.kind === \"regex\").map((rule) => `/${rule.source}/${rule.flags}`),\n replacement,\n },\n history: {\n path: subject.historyPath,\n entries_scanned: historyEntries.length,\n entries_changed: rewritten.entriesChanged,\n replacements: rewritten.replacements,\n hash_mismatches_before: integritySnapshot.hashMismatchesBefore,\n hash_mismatches_after: integritySnapshot.hashMismatchesAfter,\n preexisting_hash_mismatches: preexistingHashMismatches,\n audit_entry_added: auditEntryAdded,\n verify_ok: historyVerify.ok,\n verify_errors: historyVerify.errors,\n },\n item: {\n existed_before: currentItemPath !== null,\n exists_after: nextItemPath !== null,\n path_before: currentItemPath,\n path_after: nextItemPath,\n changed: itemChanged,\n },\n warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),\n generated_at: nowIso(),\n };\n}\n", "import { readFileIfExists } from \"../fs/fs-utils.js\";\nimport type { ItemTypeRegistry } from \"../item/type-registry.js\";\nimport { EXIT_CODE } from \"../shared/constants.js\";\nimport { PmCliError } from \"../shared/errors.js\";\nimport { locateItem, readLocatedItem } from \"../store/item-store.js\";\nimport { resolveGovernanceKnobs } from \"../store/settings.js\";\nimport type { ItemDocument, PmSettings } from \"../../types/index.js\";\n\ntype LoadedItem = Awaited<ReturnType<typeof readLocatedItem>>;\n\nexport interface HistoryRewriteSubject {\n id: string;\n historyPath: string;\n}\n\nexport interface HistoryRewriteOwnershipParams {\n itemDocument: ItemDocument | null;\n subjectId: string;\n author: string;\n force: boolean | undefined;\n settings: PmSettings;\n}\n\n/**\n * Apply ownership_enforcement governance to a history-rewriting operation.\n * Returns the warning(s) the caller should append (empty when no conflict or strict-throws).\n * Throws PmCliError(CONFLICT) in strict mode when the assignee conflicts and --force is not set.\n */\nexport function checkHistoryRewriteOwnership(params: HistoryRewriteOwnershipParams): string[] {\n if (!params.itemDocument) return [];\n const assigned = params.itemDocument.metadata?.assignee?.trim();\n if (!assigned || assigned === params.author || params.force) return [];\n\n const governance = resolveGovernanceKnobs(params.settings);\n if (governance.ownership_enforcement === \"strict\") {\n throw new PmCliError(\n `Item ${params.subjectId} is assigned to ${assigned}. Use --force to override.`,\n EXIT_CODE.CONFLICT,\n );\n }\n if (governance.ownership_enforcement === \"warn\") {\n return [`ownership_warning:assignee_conflict:${params.subjectId}:${assigned}`];\n }\n return [];\n}\n\nexport interface VerifyHistoryRewriteDriftParams {\n pmRoot: string;\n subject: HistoryRewriteSubject;\n settings: PmSettings;\n typeRegistry: ItemTypeRegistry;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n /** Short operation name used in the conflict message (e.g. \"history-redact\"). */\n operation: string;\n}\n\nexport interface VerifiedHistoryRewriteState {\n historyRawUnderLock: string | null;\n locatedUnderLock: Awaited<ReturnType<typeof locateItem>>;\n loadedItemUnderLock: LoadedItem | null;\n}\n\n/**\n * Re-read the history stream and the located item document under the acquired lock and\n * compare both with the pre-lock raw snapshots. Throws PmCliError(CONFLICT) if either\n * diverged while waiting for the lock so the caller surfaces an actionable retry.\n */\nexport async function verifyHistoryRewriteNoDrift(\n params: VerifyHistoryRewriteDriftParams,\n): Promise<VerifiedHistoryRewriteState> {\n const historyRawUnderLock = await readFileIfExists(params.subject.historyPath);\n if (historyRawUnderLock !== params.historyRawBeforeLock) {\n throw new PmCliError(\n `History for ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`,\n EXIT_CODE.CONFLICT,\n );\n }\n const locatedUnderLock = await locateItem(\n params.pmRoot,\n params.subject.id,\n params.settings.id_prefix,\n params.settings.item_format,\n params.typeRegistry.type_to_folder,\n );\n const loadedItemUnderLock = locatedUnderLock\n ? await readLocatedItem(locatedUnderLock, { schema: params.settings.schema })\n : null;\n if ((loadedItemUnderLock?.raw ?? null) !== (params.currentItemRawBeforeLock ?? null)) {\n throw new PmCliError(\n `Item ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`,\n EXIT_CODE.CONFLICT,\n );\n }\n return { historyRawUnderLock, locatedUnderLock, loadedItemUnderLock };\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;;;;;;;;;;AC4BT,SAAU,6BAA6B,QAAqC;AAChF,MAAI,CAAC,OAAO;AAAc,WAAO,CAAA;AACjC,QAAM,WAAW,OAAO,aAAa,UAAU,UAAU,KAAI;AAC7D,MAAI,CAAC,YAAY,aAAa,OAAO,UAAU,OAAO;AAAO,WAAO,CAAA;AAEpE,QAAM,aAAa,uBAAuB,OAAO,QAAQ;AACzD,MAAI,WAAW,0BAA0B,UAAU;AACjD,UAAM,IAAI,WACR,QAAQ,OAAO,SAAS,mBAAmB,QAAQ,8BACnD,UAAU,QAAQ;EAEtB;AACA,MAAI,WAAW,0BAA0B,QAAQ;AAC/C,WAAO,CAAC,uCAAuC,OAAO,SAAS,IAAI,QAAQ,EAAE;EAC/E;AACA,SAAO,C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