@unbrained/pm-cli 2026.10.30 → 2026.11.1

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 (262) hide show
  1. package/.agents/skills/pm-user/references/ECOSYSTEM_PLANNING.md +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/AGENTS.md +3 -3
  4. package/CHANGELOG.md +41 -0
  5. package/README.md +1 -1
  6. package/dist/cli/commander-usage.js +2 -2
  7. package/dist/cli/error-guidance.d.ts +45 -5
  8. package/dist/cli/error-guidance.js +5 -3
  9. package/dist/cli/extension-command-help.d.ts +1 -0
  10. package/dist/cli/extension-command-help.js +2 -2
  11. package/dist/cli/main.d.ts +1 -5
  12. package/dist/cli/main.js +5 -5
  13. package/dist/cli/migration-gates.d.ts +1 -1
  14. package/dist/cli/migration-gates.js +1 -1
  15. package/dist/cli/preflight-warnings.d.ts +11 -0
  16. package/dist/cli/preflight-warnings.js +4 -0
  17. package/dist/cli/register-mutation.js +2 -2
  18. package/dist/cli/register-operations.d.ts +3 -3
  19. package/dist/cli/register-operations.js +1 -1
  20. package/dist/cli-bundle/bundle-manifest.json +1 -1
  21. package/dist/cli-bundle/chunks/chunk-2GK2IVU5.js +8 -0
  22. package/dist/cli-bundle/chunks/chunk-5KW4WUAK.js +6 -0
  23. package/dist/cli-bundle/chunks/chunk-5WVE7XBS.js +114 -0
  24. package/dist/cli-bundle/chunks/chunk-6PKWKVS6.js +8 -0
  25. package/dist/cli-bundle/chunks/chunk-E74BORFX.js +128 -0
  26. package/dist/cli-bundle/chunks/chunk-F3ECOBKA.js +2 -0
  27. package/dist/cli-bundle/chunks/chunk-ICT6E4IW.js +2 -0
  28. package/dist/cli-bundle/chunks/chunk-MP2DQJH2.js +3 -0
  29. package/dist/cli-bundle/chunks/{chunk-LWW4F4G2.js → chunk-MRUA2Z43.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-UUQX3PFD.js → chunk-MTRIGD7M.js} +76 -76
  31. package/dist/cli-bundle/chunks/{chunk-S2U7ECUJ.js → chunk-N45IXPCA.js} +2 -2
  32. package/dist/cli-bundle/chunks/{chunk-MVL27TAH.js → chunk-NILQ2ZMV.js} +2 -2
  33. package/dist/cli-bundle/chunks/{chunk-GRABKNFL.js → chunk-O56O7NIE.js} +2 -2
  34. package/dist/cli-bundle/chunks/chunk-O6TFUV6M.js +31 -0
  35. package/dist/cli-bundle/chunks/{chunk-TH5KPAN4.js → chunk-SBVX5CMV.js} +2 -2
  36. package/dist/cli-bundle/chunks/{chunk-Y6NC3X3E.js → chunk-TMPO4CTZ.js} +3 -3
  37. package/dist/cli-bundle/chunks/chunk-TYERATXH.js +2 -0
  38. package/dist/cli-bundle/chunks/{chunk-EHBGHX55.js → chunk-UEEG47TU.js} +2 -2
  39. package/dist/cli-bundle/chunks/chunk-UUN3WNMQ.js +20 -0
  40. package/dist/cli-bundle/chunks/chunk-WFBYKDB2.js +2 -0
  41. package/dist/cli-bundle/chunks/{chunk-RZQNFHXO.js → chunk-WX25MU4N.js} +3 -3
  42. package/dist/cli-bundle/chunks/{chunk-4BQD5SW2.js → chunk-Y7CKVU56.js} +30 -30
  43. package/dist/cli-bundle/chunks/{indexed-receipt-blobs-LHLE7PSG.js → indexed-receipt-blobs-KGMJVFH2.js} +2 -2
  44. package/dist/cli-bundle/chunks/item-transaction-Q5S5YLEJ.js +2 -0
  45. package/dist/cli-bundle/chunks/{mutation-admission-TRGAVS7N.js → mutation-admission-BOOCJPCU.js} +2 -2
  46. package/dist/cli-bundle/chunks/{register-list-query-BH4F6M7Z.js → register-list-query-23OX36Q3.js} +3 -3
  47. package/dist/cli-bundle/chunks/register-mutation-JPJ5YNDX.js +20 -0
  48. package/dist/cli-bundle/chunks/register-operations-IGR7ERY5.js +2 -0
  49. package/dist/cli-bundle/chunks/{register-setup-QPWSVHFZ.js → register-setup-BMIFKZZP.js} +2 -2
  50. package/dist/cli-bundle/chunks/{settlement-hook-MN3Y7LVX.js → settlement-hook-YWSWFOZY.js} +2 -2
  51. package/dist/cli-bundle/chunks/{stage-RTB6RAAO.js → stage-ON7CYYPM.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/{chunk-POJPJX64.js → chunk-2Y77HWIX.js} +2 -2
  53. package/dist/cli-bundle/focused-chunks/{chunk-SAT7IAEB.js → chunk-3NYWMUX3.js} +3 -3
  54. package/dist/cli-bundle/focused-chunks/chunk-3Z53POXU.js +2 -0
  55. package/dist/cli-bundle/focused-chunks/chunk-5TWS5KOM.js +26 -0
  56. package/dist/cli-bundle/focused-chunks/chunk-5WCQFH6D.js +12 -0
  57. package/dist/cli-bundle/focused-chunks/{chunk-S23ZUASN.js → chunk-6GMYW42K.js} +2 -2
  58. package/dist/cli-bundle/focused-chunks/{chunk-YQUZL2CK.js → chunk-6OKPYCLU.js} +5 -5
  59. package/dist/cli-bundle/focused-chunks/chunk-7WJDRZOR.js +22 -0
  60. package/dist/cli-bundle/focused-chunks/{chunk-3SRX77ES.js → chunk-AL7SOFUL.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/chunk-CIQ6YWCW.js +26 -0
  62. package/dist/cli-bundle/focused-chunks/{chunk-RKPUQDWF.js → chunk-DFUTCKUF.js} +2 -2
  63. package/dist/cli-bundle/focused-chunks/{chunk-RYEZSZJ7.js → chunk-GE755ODZ.js} +2 -2
  64. package/dist/cli-bundle/focused-chunks/chunk-JCR32IAO.js +91 -0
  65. package/dist/cli-bundle/focused-chunks/{chunk-BPE6JTKL.js → chunk-JLXGRDTG.js} +3 -3
  66. package/dist/cli-bundle/focused-chunks/chunk-LVA76N27.js +6 -0
  67. package/dist/cli-bundle/focused-chunks/{chunk-YU7QOYYV.js → chunk-M22TI7LP.js} +3 -3
  68. package/dist/cli-bundle/focused-chunks/chunk-PAT6QF63.js +2 -0
  69. package/dist/cli-bundle/focused-chunks/{chunk-VFWCSQAG.js → chunk-RPUDOJVB.js} +2 -2
  70. package/dist/cli-bundle/focused-chunks/chunk-SXZM4PSS.js +44 -0
  71. package/dist/cli-bundle/focused-chunks/chunk-UQIBGLDR.js +2 -0
  72. package/dist/cli-bundle/focused-chunks/{chunk-RGQEJFXO.js → chunk-VFQAZLKO.js} +2 -2
  73. package/dist/cli-bundle/focused-chunks/{chunk-BCIUAEWX.js → chunk-VS2ZFPXD.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/{chunk-FRFNGMAK.js → chunk-WX2RVS2Y.js} +2 -2
  75. package/dist/cli-bundle/focused-chunks/chunk-Z7GIVH6B.js +3 -0
  76. package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-VK2363JB.js → indexed-receipt-blobs-KHWT44EK.js} +2 -2
  77. package/dist/cli-bundle/focused-chunks/item-transaction-7VLPA2SU.js +2 -0
  78. package/dist/cli-bundle/focused-chunks/{mutation-admission-7VUODEPJ.js → mutation-admission-2DH27R5Y.js} +2 -2
  79. package/dist/cli-bundle/focused-chunks/{settlement-hook-OK6A7PG2.js → settlement-hook-SJV52ZTV.js} +2 -2
  80. package/dist/cli-bundle/focused-chunks/{stage-S5RP5SZH.js → stage-FYOBWQA7.js} +2 -2
  81. package/dist/cli-bundle/main.js +26 -22
  82. package/dist/cli-bundle/sdk-authoring.js +1 -1
  83. package/dist/cli-bundle/sdk-contracts.js +4 -4
  84. package/dist/cli-bundle/sdk-core.js +1 -1
  85. package/dist/cli-bundle/sdk-governance.js +1 -1
  86. package/dist/cli-bundle/sdk-graph.js +1 -1
  87. package/dist/cli-bundle/sdk-merge.js +57 -57
  88. package/dist/cli-bundle/sdk-query.js +1 -1
  89. package/dist/cli-bundle/sdk-runtime.js +1 -1
  90. package/dist/cli-bundle/sdk-testing.js +1 -1
  91. package/dist/cli-bundle/sdk.js +11 -11
  92. package/dist/core/config/nested-settings.js +1 -1
  93. package/dist/core/extensions/extension-hook-runtime.js +1 -1
  94. package/dist/core/extensions/extension-types.d.ts +4 -0
  95. package/dist/core/extensions/extension-types.js +1 -1
  96. package/dist/core/extensions/loader.js +1 -1
  97. package/dist/core/lock/lock.js +4 -4
  98. package/dist/core/output/mutation-projection.js +1 -1
  99. package/dist/core/output/output.js +3 -3
  100. package/dist/core/schema/fields-file.js +1 -1
  101. package/dist/core/sentry/helpers.d.ts +6 -0
  102. package/dist/core/sentry/helpers.js +1 -1
  103. package/dist/core/sentry/instrument.d.ts +1 -1
  104. package/dist/core/sentry/instrument.js +1 -1
  105. package/dist/core/shared/constants.js +1 -1
  106. package/dist/core/shared/errors.d.ts +6 -0
  107. package/dist/core/shared/errors.js +1 -1
  108. package/dist/core/shared/output-unicode.d.ts +10 -0
  109. package/dist/core/shared/output-unicode.js +2 -0
  110. package/dist/core/store/settings-validator.d.ts +1 -0
  111. package/dist/core/store/settings-validator.js +1 -1
  112. package/dist/core/store/settings.js +1 -1
  113. package/dist/core/telemetry/policy.d.ts +8 -0
  114. package/dist/core/telemetry/policy.js +1 -1
  115. package/dist/core/telemetry/runtime.js +3 -3
  116. package/dist/sdk/agent/command-recovery.d.ts +15 -0
  117. package/dist/sdk/agent/command-recovery.js +1 -1
  118. package/dist/sdk/cli-bootstrap.js +1 -1
  119. package/dist/sdk/cli-contracts/agent-output-contracts.d.ts +28 -0
  120. package/dist/sdk/cli-contracts/agent-output-contracts.js +2 -2
  121. package/dist/sdk/cli-contracts/commander-mutation-options.js +1 -1
  122. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  123. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  124. package/dist/sdk/cli-contracts/grammar-contracts.js +1 -1
  125. package/dist/sdk/cli-contracts/tool-parameter-tables.js +1 -1
  126. package/dist/sdk/cli-contracts/tool-schema.js +1 -1
  127. package/dist/sdk/cli-contracts.d.ts +1 -1
  128. package/dist/sdk/cli-contracts.js +1 -1
  129. package/dist/sdk/completion/fish.js +4 -4
  130. package/dist/sdk/completion/zsh.js +3 -3
  131. package/dist/sdk/config.d.ts +1 -0
  132. package/dist/sdk/config.js +1 -1
  133. package/dist/sdk/context-intent-contracts.d.ts +17 -0
  134. package/dist/sdk/context-intent-contracts.js +1 -1
  135. package/dist/sdk/core.d.ts +2 -1
  136. package/dist/sdk/core.js +1 -1
  137. package/dist/sdk/error-runtime.d.ts +9 -0
  138. package/dist/sdk/error-runtime.js +1 -1
  139. package/dist/sdk/errors.js +1 -1
  140. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -1
  141. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +1 -1
  142. package/dist/sdk/index.d.ts +3 -3
  143. package/dist/sdk/index.js +1 -1
  144. package/dist/sdk/init-agent-guidance.js +2 -2
  145. package/dist/sdk/lifecycle/claim.d.ts +27 -0
  146. package/dist/sdk/lifecycle/claim.js +1 -1
  147. package/dist/sdk/lifecycle/close.js +1 -1
  148. package/dist/sdk/lifecycle/create.js +1 -1
  149. package/dist/sdk/lifecycle/mcp-actions.d.ts +1 -1
  150. package/dist/sdk/lifecycle/mcp-actions.js +1 -1
  151. package/dist/sdk/lifecycle/plan.d.ts +2 -3
  152. package/dist/sdk/lifecycle/plan.js +1 -1
  153. package/dist/sdk/lifecycle/repeated-terminal-state.d.ts +45 -0
  154. package/dist/sdk/lifecycle/repeated-terminal-state.js +2 -0
  155. package/dist/sdk/lifecycle/shared-unset-fields.d.ts +9 -0
  156. package/dist/sdk/lifecycle/shared-unset-fields.js +1 -1
  157. package/dist/sdk/lifecycle/task-composition.js +1 -1
  158. package/dist/sdk/lifecycle/update-many.d.ts +0 -1
  159. package/dist/sdk/lifecycle/update-many.js +1 -1
  160. package/dist/sdk/lifecycle/update.d.ts +29 -1
  161. package/dist/sdk/lifecycle/update.js +2 -2
  162. package/dist/sdk/output/list-envelope.d.ts +8 -0
  163. package/dist/sdk/output/list-envelope.js +1 -1
  164. package/dist/sdk/output/table-rows.d.ts +7 -1
  165. package/dist/sdk/output/table-rows.js +1 -1
  166. package/dist/sdk/output.d.ts +2 -1
  167. package/dist/sdk/output.js +2 -2
  168. package/dist/sdk/ownership-source.d.ts +18 -0
  169. package/dist/sdk/ownership-source.js +1 -1
  170. package/dist/sdk/public-surface.json +1 -1
  171. package/dist/sdk/query/context.js +2 -2
  172. package/dist/sdk/query/get.d.ts +1 -1
  173. package/dist/sdk/query/get.js +1 -1
  174. package/dist/sdk/query/next-ranking-policy.d.ts +35 -0
  175. package/dist/sdk/query/next-ranking-policy.js +2 -0
  176. package/dist/sdk/query/next.d.ts +12 -2
  177. package/dist/sdk/query/next.js +2 -2
  178. package/dist/sdk/query/projection-contracts.d.ts +4 -0
  179. package/dist/sdk/query/projection-contracts.js +1 -1
  180. package/dist/sdk/read-output/surfaces.d.ts +27 -0
  181. package/dist/sdk/read-output/surfaces.js +2 -0
  182. package/dist/sdk/read-output-contracts.js +1 -1
  183. package/dist/sdk/runtime/actions.js +1 -1
  184. package/dist/sdk/runtime-input.js +1 -1
  185. package/dist/sdk/runtime-primitives.d.ts +1 -0
  186. package/dist/sdk/runtime-primitives.js +1 -1
  187. package/dist/sdk/runtime-public-contracts.d.ts +2 -0
  188. package/dist/sdk/runtime.d.ts +2 -2
  189. package/dist/sdk/runtime.js +1 -1
  190. package/dist/sdk/start-task-status.d.ts +1 -1
  191. package/dist/sdk/start-task-status.js +1 -1
  192. package/dist/sdk/test/execution-receipts.d.ts +25 -0
  193. package/dist/sdk/test/execution-receipts.js +2 -2
  194. package/dist/sdk/test/execution.d.ts +5 -0
  195. package/dist/sdk/test/execution.js +2 -2
  196. package/dist/types.d.ts +2 -0
  197. package/dist/types.js +1 -1
  198. package/docs/AGENT_GUIDE.md +4 -4
  199. package/docs/AGENT_OUTPUT_ENCODINGS.md +12 -0
  200. package/docs/AGENT_UX_CONTRACTS.md +2 -1
  201. package/docs/COMMANDS.md +59 -5
  202. package/docs/COMMAND_NAMESPACES.md +1 -1
  203. package/docs/CONFIGURATION.md +48 -1
  204. package/docs/DEVELOPMENT_DEPENDENCY_SECURITY.md +26 -0
  205. package/docs/LIFECYCLE_COMMANDS.md +19 -4
  206. package/docs/PACKED_FIRST_RUN.md +2 -1
  207. package/docs/READ_OUTPUT_CONTRACTS.md +24 -6
  208. package/docs/SDK.md +82 -3
  209. package/docs/SDK_ACTION_CONFORMANCE.md +21 -0
  210. package/docs/TESTING.md +38 -2
  211. package/docs/agent-task-token-baseline.json +1 -1
  212. package/docs/agent-task-transcripts.json +1 -1
  213. package/marketplace.json +1 -1
  214. package/package.json +1 -1
  215. package/packages/pm-beads/package.json +1 -1
  216. package/packages/pm-calendar/extensions/calendar/index.ts +1 -0
  217. package/packages/pm-calendar/package.json +1 -1
  218. package/packages/pm-command-kit/package.json +1 -1
  219. package/packages/pm-digital-twin/package.json +1 -1
  220. package/packages/pm-governance-audit/package.json +1 -1
  221. package/packages/pm-guide-shell/package.json +1 -1
  222. package/packages/pm-kanban/package.json +1 -1
  223. package/packages/pm-lifecycle-hooks/package.json +1 -1
  224. package/packages/pm-linked-test-adapters/package.json +1 -1
  225. package/packages/pm-search-advanced/package.json +1 -1
  226. package/packages/pm-templates/package.json +1 -1
  227. package/packages/pm-todos/package.json +1 -1
  228. package/packages/pm-vcs/package.json +1 -1
  229. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  230. package/plugins/pm-claude/package.json +1 -1
  231. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  232. package/plugins/pm-codex/package.json +1 -1
  233. package/plugins/pm-codex/plugin.json +1 -1
  234. package/runtime-dependencies.json +1 -1
  235. package/dist/cli-bundle/chunks/chunk-34MP7WKK.js +0 -6
  236. package/dist/cli-bundle/chunks/chunk-3KMYHYJV.js +0 -2
  237. package/dist/cli-bundle/chunks/chunk-42BHHNTL.js +0 -128
  238. package/dist/cli-bundle/chunks/chunk-I5O3XZOA.js +0 -2
  239. package/dist/cli-bundle/chunks/chunk-LEIVUGDH.js +0 -8
  240. package/dist/cli-bundle/chunks/chunk-OH7WPD42.js +0 -114
  241. package/dist/cli-bundle/chunks/chunk-OOD2A7AF.js +0 -20
  242. package/dist/cli-bundle/chunks/chunk-Q5V7P6NM.js +0 -2
  243. package/dist/cli-bundle/chunks/chunk-QLPFYBXN.js +0 -2
  244. package/dist/cli-bundle/chunks/chunk-SA5NYLPE.js +0 -8
  245. package/dist/cli-bundle/chunks/chunk-VHLAVTJN.js +0 -31
  246. package/dist/cli-bundle/chunks/chunk-XAOVJG52.js +0 -3
  247. package/dist/cli-bundle/chunks/chunk-XPQ4RTSF.js +0 -2
  248. package/dist/cli-bundle/chunks/item-transaction-WIOBZW4E.js +0 -2
  249. package/dist/cli-bundle/chunks/register-mutation-5V2NANIS.js +0 -20
  250. package/dist/cli-bundle/chunks/register-operations-XSFRMUFX.js +0 -2
  251. package/dist/cli-bundle/focused-chunks/chunk-2V6NMNYN.js +0 -26
  252. package/dist/cli-bundle/focused-chunks/chunk-ASHGXMX4.js +0 -3
  253. package/dist/cli-bundle/focused-chunks/chunk-CKBN2D42.js +0 -12
  254. package/dist/cli-bundle/focused-chunks/chunk-I642DXOT.js +0 -22
  255. package/dist/cli-bundle/focused-chunks/chunk-K7DKG5HM.js +0 -91
  256. package/dist/cli-bundle/focused-chunks/chunk-NMQBXU7N.js +0 -44
  257. package/dist/cli-bundle/focused-chunks/chunk-PGM3ENGZ.js +0 -2
  258. package/dist/cli-bundle/focused-chunks/chunk-QFNV4JTA.js +0 -6
  259. package/dist/cli-bundle/focused-chunks/chunk-QVJCQMZY.js +0 -26
  260. package/dist/cli-bundle/focused-chunks/chunk-R2TPPPVU.js +0 -2
  261. package/dist/cli-bundle/focused-chunks/chunk-VJVJ2ZX2.js +0 -2
  262. package/dist/cli-bundle/focused-chunks/item-transaction-ZFDKJIP7.js +0 -2
@@ -0,0 +1,6 @@
1
+ import{c as T}from"./chunk-6GMYW42K.js";import{a,d as I}from"./chunk-VFQAZLKO.js";import{Y as w,j as g,k as v,l as E}from"./chunk-CIQ6YWCW.js";import{A as u,C as m,m as k,z as f}from"./chunk-JLXGRDTG.js";import C from"node:fs/promises";import p from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="74b72dd8-0877-55a4-9c80-d043f19e1f96")}catch{}})();var P=["extensions","docs","examples","assets","prompts"],U=Object.freeze({extensions:Object.freeze([".agents/pm/extensions","extensions",".custom/pm-extensions",".custom/pm-extension"]),docs:Object.freeze(["docs","documentation"]),examples:Object.freeze(["examples","docs/examples"]),assets:Object.freeze(["assets",".agents/pm/assets"]),prompts:Object.freeze(["prompts",".agents/pm/prompts"])});function R(e){return P.includes(e)}function q(e,t){if(t==null)return[];let n=Array.isArray(t)?t:[t],r=[];for(let o of n){if(typeof o!="string"||o.trim().length===0)throw new u(`Package manifest field pm.${e} must contain string paths.`,f.USAGE);r.push(o.trim())}return[...new Set(r)].sort((o,i)=>o.localeCompare(i))}function G(e){if(e==null)return{};if(typeof e!="object"||Array.isArray(e))throw new u("Package manifest field pm must be an object.",f.USAGE);let t={},n=e;for(let[r,o]of Object.entries(n)){if(!R(r))continue;let i=q(r,o);i.length>0&&(t[r]=i)}return t}function c(e,t){let n=e[t];return typeof n=="string"&&n.trim().length>0?n.trim():void 0}function S(e){if(!Array.isArray(e))return;let t=e.map(n=>typeof n=="string"?n.trim():"").filter(n=>n.length>0);return t.length>0?[...new Set(t)].sort((n,r)=>n.localeCompare(r)):void 0}function x(e){if(typeof e=="string"&&e.trim().length>0)return e.trim();if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let t=e.url;return typeof t=="string"&&t.trim().length>0?t.trim():void 0}}function J(e){if(typeof e!="object"||e===null||Array.isArray(e))return;let t=e,n={docs:c(t,"docs"),npm:c(t,"npm"),repository:c(t,"repository"),report:c(t,"report")};return Object.values(n).some(r=>typeof r=="string")?n:void 0}function K(e){if(typeof e!="object"||e===null||Array.isArray(e))return;let t=e,n={image:c(t,"image"),video:c(t,"video")};return Object.values(n).some(r=>typeof r=="string")?n:void 0}function V(e){if(typeof e!="object"||e===null||Array.isArray(e))return;let t=e,n={display_name:c(t,"display_name")??c(t,"displayName"),category:c(t,"category"),summary:c(t,"summary"),links:J(t.links),media:K(t.media),tags:S(t.tags)};return Object.values(n).some(r=>r!==void 0)?n:void 0}async function Y(e){let t=p.join(e,"package.json");if(!await m(t))return{source:"convention",resources:{}};let n;try{n=JSON.parse(await C.readFile(t,"utf8"))}catch(l){throw new u(`Failed to parse package manifest at "${t}": ${String(l)}`,f.USAGE)}if(typeof n!="object"||n===null||Array.isArray(n))throw new u(`Package manifest at "${t}" must be a JSON object.`,f.USAGE);let r=n,o=r.pm,i=o!=null,s=typeof o=="object"&&o!==null&&!Array.isArray(o)?o:{};return{source:i?"pm":"convention",package_json_path:t,package_name:typeof r.name=="string"?r.name:void 0,package_version:typeof r.version=="string"?r.version:void 0,package_private:r.private===!0,package_description:typeof r.description=="string"?r.description:void 0,package_keywords:S(r.keywords),package_homepage:typeof r.homepage=="string"?r.homepage:void 0,package_repository_url:x(r.repository),package_bugs_url:x(r.bugs),aliases:S(s.aliases),resources:G(o),catalog:V(s.catalog)}}async function j(e){if(!await m(e))return[];let t=await C.readdir(e,{withFileTypes:!0}),n=[];for(let r of t){if(!r.isDirectory())continue;let o=p.join(e,r.name);await m(p.join(o,"manifest.json"))&&n.push(o)}return n.sort((r,o)=>r.localeCompare(o))}async function he(e){if(await m(p.join(e,"manifest.json")))return[e];let t=(await Y(e)).resources.extensions??[],n=new Set;for(let r of t){if(r.includes("*")||r.startsWith("!"))throw new u(`Package extension entry "${r}" uses a glob/exclusion pattern. pm package installs currently require concrete extension paths or directories.`,f.USAGE);let o=p.resolve(e,r);if(!w(e,o))throw new u(`Package extension entry "${r}" resolves outside package root.`,f.USAGE);if(await m(p.join(o,"manifest.json"))){n.add(o);continue}for(let i of await j(o))n.add(i)}if(t.length===0)for(let r of U.extensions)for(let o of await j(p.join(e,r)))n.add(o);return[...n].sort((r,o)=>r.localeCompare(o))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="3984f1ef-1703-5a83-a4fa-ec1cdc738572")}catch{}})();var D=[["commands","Commands"],["command_overrides","Command overrides"],["flag_commands","Flag commands"],["item_types","Item types"],["item_fields","Item fields"],["migrations","Migrations"],["profiles","Profiles"],["importers","Importers"],["exporters","Exporters"],["search_providers","Search providers"],["vector_store_adapters","Vector store adapters"],["assurance_providers","Assurance measurement providers"],["hooks","Lifecycle hooks"],["parser_overrides","Parser overrides"],["service_overrides","Service overrides"],["renderer_overrides","Renderer overrides"]];function A(e){return"#".repeat(e)}function $(e){if(!e.includes("`"))return`\`${e}\``;let t=0,n=0;for(let i of e)n=i==="`"?n+1:0,t=Math.max(t,n);let r="`".repeat(t+1),o=e.startsWith("`")||e.endsWith("`")?" ":"";return`${r}${o}${e}${o}${r}`}function B(e){return e.length===0?"Capabilities: _none registered_":`Capabilities: ${e.map($).join(", ")}`}function W(e,t,n){let r=[`${A(t)} ${e}`,""];return n.length===0?(r.push("_None._",""),r):(r.push(...n.map(o=>`- ${$(o)}`),""),r)}function H(e,t,n){return e===0&&!n?[]:[`${A(t)} Preflight overrides`,"",e>0?`- ${e} registered (this surface carries no per-entry identifier)`:"_None._",""]}function be(e,t={}){let n=t.headingLevel??2;if(!Number.isInteger(n)||n<1||n>6)throw new RangeError(`headingLevel must be an integer in [1, 6], received ${String(t.headingLevel)}`);let r=Math.min(n+1,6),o=t.includeEmpty===!0,i=t.title??"Extension surfaces",s=[`${A(n)} ${i}`,""];(o||e.capabilities.length>0)&&s.push(B(e.capabilities),"");for(let[l,d]of D){let y=e[l]??[];y.length===0&&!o||s.push(...W(d,r,y))}return s.push(...H(e.preflight_overrides,r,o)),!(e.preflight_overrides>0||D.some(([l])=>(e[l]?.length??0)>0))&&!o&&s.push("_This extension registers no surfaces._",""),`${s.join(`
2
+ `).trimEnd()}
3
+ `}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="abb182c9-6d6c-5be4-a2ad-c91b00a098d0")}catch{}})();var X=["agile","ops","research"],Q={agile:[{name:"Story",description:"User-facing outcome or capability slice expressed from a stakeholder perspective.",defaultStatus:"open",folder:"stories",aliases:["user-story"]},{name:"Spike",description:"Time-boxed investigation used to reduce uncertainty before implementation.",defaultStatus:"open",folder:"spikes",aliases:["research-spike"]}],ops:[{name:"Incident",description:"Operational disruption, degradation, or support escalation with recovery tracking.",defaultStatus:"open",folder:"incidents",aliases:["outage"]},{name:"Runbook",description:"Repeatable operational procedure, diagnostic path, or response playbook.",defaultStatus:"open",folder:"runbooks",aliases:["playbook"]}],research:[{name:"Experiment",description:"Validated-learning activity with hypothesis, method, and outcome tracking.",defaultStatus:"open",folder:"experiments",aliases:["study"]},{name:"Hypothesis",description:"Testable claim or assumption that should be supported, rejected, or refined.",defaultStatus:"open",folder:"hypotheses",aliases:["assumption"]}]};function Se(e){if(e===void 0)return;let t=e.trim().toLowerCase().replaceAll("-","_");if(t.length===0)throw new Error("Type preset name must not be empty.");if(t==="agile"||t==="ops"||t==="research")return t;throw new Error(`Invalid type preset "${e}". Allowed: ${X.join(", ")}.`)}function Ae(e){return Q[e].map(t=>T(t))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="1abceae0-299e-5fff-aa8c-46c015115571")}catch{}})();var Z=new Set(v),ee=new Set(E),F=new Set([...k.filter(e=>e!=="severity"),"id","title","type","status","priority","tags","assignee","parent","description","body","created_at","updated_at","closed_at","completed_at","author","deadline","estimate","sprint","release","risk","confidence","reviewer","resolution","expected","actual"]),te=["create","update"];function z(e){if(typeof e!="string")return"";let t=e.trim().toLowerCase().replaceAll(/[\s_]+/g,"-");return t.startsWith("--")?t.slice(2):t}function N(e){return e.replaceAll("_","-")}function re(e,t){let n=new Set;for(let r of e){let o=z(r);o.length>0&&o!==t&&n.add(o)}return[...n].sort((r,o)=>r.localeCompare(o))}function ne(e){let t=new Set;for(let n of e??[]){let r=n.trim();r.length>0&&t.add(r)}return[...t].sort((n,r)=>n.localeCompare(r))}function oe(e){let t=new Set,n=[];for(let r of e??[]){let o=r.trim().toLowerCase();if(o.length!==0){if(!ee.has(o))throw new Error(`Invalid field command "${r}". Allowed: ${E.join(", ")}.`);t.has(o)||(t.add(o),n.push(o))}}return e===void 0||n.length===0?[...te]:n}function je(e){let t=a(e.key);if(t.length===0)throw new Error("Field key must not be empty.");if(t.includes(","))throw new Error(`Field key "${t}" must not contain commas: commas separate field names in list flags such as --unset and --fields.`);if(F.has(t))throw new Error(`Cannot define custom field "${t}": custom schema field "${t}" collides with built-in item metadata "${t}". Rename the custom field with a project-specific prefix. Reserved fields: ${[...F].sort((b,M)=>b.localeCompare(M)).join(", ")}.`);let n=typeof e.type=="string"&&e.type.trim().length>0?e.type.trim().toLowerCase():"string";if(!Z.has(n))throw new Error(`Invalid field type "${e.type}". Allowed: ${v.join(", ")}.`);let r=n,o=oe(e.commands),i=z(e.cliFlag),s=i.length>0&&i!==N(t)?i:void 0,l=s??N(t),d=re(e.aliases??[],l),y=[l,...d].find(b=>b.includes(","));if(y!==void 0)throw new Error(`Field flag "${y}" must not contain commas.`);let _=e.description?.trim();return{key:t,type:r,commands:o,description:_&&_.length>0?_:void 0,cliFlag:s,cliAliases:d,required:e.required===!0,requiredOnCreate:e.requiredOnCreate===!0,allowUnset:e.allowUnset!==!1,requiredTypes:ne(e.requiredTypes)}}function ie(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;let t=e;if(Array.isArray(t.fields))return t.fields;if(Array.isArray(t.definitions))return t.definitions}function se(e){let t=ie(e);if(!t)return[];let n=[];for(let r of t){if(typeof r!="object"||r===null||Array.isArray(r))continue;let o=r;typeof o.key!="string"||o.key.trim().length===0||n.push(o)}return n}function Ce(e){if(e==null||e.trim().length===0)return{fields:[]};let t;try{t=JSON.parse(e)}catch{throw new Error("schema/fields.json contains invalid JSON.")}return{fields:se(t)}}function De(e){return`${JSON.stringify({fields:e.fields},null,2)}
4
+ `}function $e(e,t){let n=e.fields.find(s=>a(s.key)===t.key),r=n!==void 0,o=e.fields.filter(s=>a(s.key)!==t.key),i={...n,key:t.key,type:t.type,commands:[...t.commands]};return O(i,"description",t.description),O(i,"cli_flag",t.cliFlag),t.cliAliases.length>0?i.cli_aliases=[...t.cliAliases]:delete i.cli_aliases,L(i,"required",t.required),L(i,"required_on_create",t.requiredOnCreate),t.allowUnset===!1?i.allow_unset=!1:delete i.allow_unset,t.requiredTypes.length>0?i.required_types=[...t.requiredTypes]:delete i.required_types,o.push(i),o.sort((s,l)=>a(s.key).localeCompare(a(l.key))),{file:{fields:o},definition:i,replaced:r}}function Fe(e,t){let n=a(t);if(n.length===0)throw new Error("Field key must not be empty.");let r=[],o=e.fields.filter(i=>a(i.key)===n?(r.push(i),!1):!0);return r.length===0?{file:{fields:o},removed:!1}:{file:{fields:o},removed:!0,definition:r[0]}}function O(e,t,n){let r=e;n!==void 0&&n.length>0?r[t]=n:delete r[t]}function L(e,t,n){let r=e;n?r[t]=!0:delete r[t]}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b1e4c04e-0ade-5d24-95e3-b8dca3832c5a")}catch{}})();var ae=new Set(g),h=new Set(I.map(e=>a(e.id)).filter(e=>e.length>0));function le(e){let t=new Set;for(let n of e){let r=a(n);r.length>0&&t.add(r)}return[...t].sort((n,r)=>n.localeCompare(r))}function Pe(e){let t=a(e.id);if(t.length===0)throw new Error("Status id must not be empty.");if(h.has(t))throw new Error(`Cannot add-status the built-in status "${t}". Built-in statuses are reserved: ${[...h].join(", ")}.`);let n;if(e.roles!==void 0){n=[];let s=new Set;for(let l of e.roles){let d=typeof l=="string"?l.trim().toLowerCase():"";if(d.length!==0){if(!ae.has(d))throw new Error(`Invalid status role "${l}". Allowed roles: ${g.join(", ")}.`);s.has(d)||(s.add(d),n.push(d))}}if(n.length===0)throw new Error(`Status role must include at least one lifecycle role. Allowed roles: ${g.join(", ")}.`)}let r=e.aliases===void 0?void 0:le(e.aliases).filter(s=>s!==t),o=e.description?.trim(),i=typeof e.order=="number"&&Number.isFinite(e.order)?Math.trunc(e.order):void 0;return{id:t,roles:n,aliases:r,description:o&&o.length>0?o:void 0,order:i}}function de(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;let t=e;if(Array.isArray(t.statuses))return t.statuses;if(Array.isArray(t.definitions))return t.definitions}function ce(e){let t=de(e);if(!t)return[];let n=[];for(let r of t){if(typeof r!="object"||r===null||Array.isArray(r))continue;let o=r;typeof o.id!="string"||o.id.trim().length===0||n.push(o)}return n}function Ue(e){if(e==null||e.trim().length===0)return{statuses:[]};let t;try{t=JSON.parse(e)}catch{throw new Error("schema/statuses.json contains invalid JSON.")}return{statuses:ce(t)}}function Re(e){return`${JSON.stringify({statuses:e.statuses},null,2)}
5
+ `}function qe(e,t,n){let r=e.statuses.slice(),o=r.findIndex(l=>a(l.id)===t.id),i=o>=0?r[o]:n,s={...i,id:t.id};return t.roles!==void 0&&(t.roles.length>0?s.roles=[...t.roles]:s.roles!==void 0&&delete s.roles),t.aliases!==void 0&&(t.aliases.length>0?s.aliases=[...t.aliases]:s.aliases!==void 0&&delete s.aliases),t.description!==void 0&&(s.description=t.description),t.order!==void 0&&(s.order=t.order),o>=0?r[o]=s:r.push(s),{file:{statuses:r},definition:s,replaced:i!==void 0}}function Ge(e,t){let n=a(t);if(n.length===0)throw new Error("Status id must not be empty.");if(h.has(n))throw new Error(`Cannot remove built-in status "${n}". Built-in statuses are reserved: ${[...h].join(", ")}.`);let r=e.statuses.slice(),o=r.findIndex(s=>a(s.id)===n);if(o<0)return{file:{statuses:r},removed:!1};let[i]=r.splice(o,1);return{file:{statuses:r},removed:!0,definition:i}}function Je(e,t){let n=[e.id,...e.aliases??[]];for(let r of n){let o=a(r);if(o.length===0)continue;let i=t.get(o);if(i!==void 0&&i!==e.id)throw new Error(`Status token "${o}" already belongs to status "${i}". Choose a different id/alias to avoid shadowing it.`)}}export{P as a,U as b,Y as c,he as d,X as e,Q as f,Se as g,Ae as h,je as i,Ce as j,De as k,$e as l,Fe as m,h as n,Pe as o,Ue as p,Re as q,qe as r,Ge as s,Je as t,be as u};
6
+ //# sourceMappingURL=chunk-LVA76N27.js.map
@@ -1,4 +1,4 @@
1
- import{c as He,e as ze,f as Fe,i as Mn,j as Vn,k as Un,l as Wn,m as qn}from"./chunk-RGQEJFXO.js";import{h as Zn}from"./chunk-4PW5XWVI.js";import{Ad as st,B as Dn,Bd as Ee,Cd as G,Dc as Jn,Ea as $n,Fa as A,Fd as Kn,Ga as $,Gd as Xn,Ha as ot,Ia as g,Id as Yn,Md as M,ea as zn,i as Qe,j as An,ja as Fn,k as xn,l as Cn,m as Nn,mc as Gn,oc as it,q as et,qe as Zt,r as tt,s as Rn,sc as Bn,x as rt,y as nt,yd as $e,z as Xt,za as we,zd as q}from"./chunk-2V6NMNYN.js";import{A as w,C as jn,D as W,E as ie,F as be,G as Ln,H as Yt,I as Le,J as Hn,m as J,u as Pn,x as h,y as je,z as E}from"./chunk-BPE6JTKL.js";import{createHash as hs}from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="ca5b60a5-80a7-5e7d-917f-4c7649bcbab6")}catch{}})();var Kl=["sha256","sha512"],ys="sha256",Qn="sha256";function se(e){if(e===void 0)return ys;if(e==="sha256"||e==="sha512")return e;throw new TypeError(`unsupported_history_hash_algorithm:${String(e)}`)}function K(e,t){return hs(se(t)).update(e,"utf8").digest("hex")}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="4d5692ce-ec33-5eb4-bd9b-7497ffe25b0e")}catch{}})();var gs=16;function Qt(e){let t=e.trim().replaceAll(/[^A-Za-z0-9]+/g," ").split(/\s+/).filter(o=>o.length>0).map(o=>o.toLowerCase());if(t.length===0)return e;let[r,...n]=t;return`${r}${n.map(o=>`${o.slice(0,1).toUpperCase()}${o.slice(1)}`).join("")}`}function vs(e){return[...new Set([qn(e),Qt(e.key),Qt(e.cli_flag),...e.cli_aliases.map(t=>Qt(t))])]}function ro(e,t){for(let r of vs(t)){if(!Object.hasOwn(e,r))continue;let n=e[r];if(n!==void 0)return n}}function no(e){return Array.isArray(e)?e.flatMap(t=>no(t)).map(t=>t.trim()).filter(t=>t.length>0):typeof e=="string"?e.split(/[,\n|]/).map(t=>t.trim()).filter(t=>t.length>0):e==null?[]:[String(e).trim()].filter(t=>t.length>0)}function eo(e,t){if(typeof e=="boolean")return e;if(typeof e=="number"){if(e===1)return!0;if(e===0)return!1}if(typeof e=="string"){let r=e.trim().toLowerCase();if(r==="true"||r==="1"||r==="yes")return!0;if(r==="false"||r==="0"||r==="no")return!1}throw new w(`${t} must be one of true|false|1|0|yes|no`,E.USAGE)}function to(e,t){if(typeof e=="number"&&Number.isFinite(e))return e;let r=typeof e=="string"?e.trim():String(e),n=Number(r);if(!Number.isFinite(n))throw new w(`${t} must be a number`,E.USAGE);return n}function bs(e,t,r){let n=typeof e=="string"?(()=>{try{return JSON.parse(e)}catch{return}})():e;if(r==="array"&&Array.isArray(n)||r==="object"&&typeof n=="object"&&n!==null&&!Array.isArray(n))return n;throw new w(`${t} must be valid JSON ${r}`,E.USAGE)}function ws(e,t){return t===void 0?!0:t==="array"?Array.isArray(e):t==="object"?typeof e=="object"&&e!==null&&!Array.isArray(e):typeof e===t}function Es(e,t,r){if(t.const!==void 0&&A(e)!==A(t.const))return`${r} must equal ${A(t.const)}`;if(t.enum!==void 0&&!t.enum.some(n=>A(n)===A(e)))return`${r} must be one of ${t.enum.map(n=>A(n)).join("|")}`;if(!ws(e,t.type))return`${r} must match configured type ${String(t.type)}`;if(typeof e=="string"){if(t.min_length!==void 0&&e.length<t.min_length)return`${r} must contain at least ${t.min_length} characters`;if(t.format==="date-time"&&!st(e))return`${r} must be an RFC 3339 date-time`}}function ks(e,t,r,n){if(Array.isArray(e)){if(t.min_items!==void 0&&e.length<t.min_items)return`${r} must contain at least ${t.min_items} items`;if(t.items)for(let[o,i]of e.entries()){let s=at(i,t.items,`${r}[${o}]`,n+1);if(s)return s}}}function Ss(e,t,r,n){if(typeof e!="object"||e===null||Array.isArray(e))return;let o=e;for(let i of t.required??[])if(!Object.hasOwn(o,i))return`${r}.${i} is required`;for(let[i,s]of Object.entries(o)){let a=t.properties?.[i];if(!a){if(t.additional_properties===!1)return`${r}.${i} is not allowed`;continue}let d=at(s,a,`${r}.${i}`,n+1);if(d)return d}}function at(e,t,r,n=0){if(n>gs)return`${r} value schema exceeds maximum depth`;let o=Es(e,t,r);if(o)return o;let i=ks(e,t,r,n);if(i)return i;let s=Ss(e,t,r,n);if(s)return s;if(!t.one_of)return;let a=0;for(let d of t.one_of)if(at(e,d,r,n+1)===void 0&&(a+=1,a>1))break;return a===1?void 0:`${r} must match exactly one configured schema variant`}function ae(e,t,r){if(!e.value_schema||t===void 0)return t;let n=at(t,e.value_schema,r);if(n)throw new w(n,E.USAGE);return t}function Is(e,t,r,n){let o=n==="option"&&Array.isArray(t)?t[t.length-1]:t;if(o!==void 0)return ae(e,bs(o,r,e.type),r)}function Me(e,t,r,n="option"){let o=r??`--${e.cli_flag}`;if(e.type==="array"||e.type==="object")return Is(e,t,o,n);if(e.repeatable||e.type==="string_array"){let s=no(t);return e.type==="number"?ae(e,s.map(a=>to(a,o)),o):e.type==="boolean"?ae(e,s.map(a=>eo(a,o)),o):ae(e,s,o)}let i=Array.isArray(t)?t[t.length-1]:t;if(i!==void 0)return e.type==="number"?ae(e,to(i,o),o):e.type==="boolean"?ae(e,eo(i,o),o):ae(e,typeof i=="string"?i:String(i),o)}function Os(e,t){return!e.required&&!e.required_on_create?!1:e.required_types.length===0?!0:t?e.required_types.map(r=>r.toLowerCase()).includes(t.trim().toLowerCase()):!1}function ru(e,t,r){let n={},o=[];for(let i of t.command_to_fields.get("create")??[]){let s=ro(e,i);if(s===void 0){Os(i,r)&&o.push(`--${i.cli_flag}`);continue}n[i.metadata_key]=Me(i,s)}return{values:n,missing_required_flags:[...new Set(o)].sort((i,s)=>i.localeCompare(s))}}function nu(e,t,r=["update"]){let n={},o=(r??["update"]).flatMap(s=>t.command_to_fields.get(s)??[]),i=new Set;for(let s of o){let a=ro(e,s);a!==void 0&&(i.has(s.metadata_key)||(i.add(s.metadata_key),n[s.metadata_key]=Me(s,a)))}return n}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="c35d4830-d7d1-5ee4-99bc-ab52cc3e4e09")}catch{}})();var er=1,tr=2;function iu(e){return Math.max(rr(e),e.tests?.some(t=>t.updated_by!==void 0||t.updated_at!==void 0)?2:1)}function rr(e){let t=e.pm_format_version;return typeof t=="number"&&Number.isInteger(t)&&t>=1?t:1}function oo(e){if(!(typeof e!="number"||!Number.isInteger(e)||e<=1))return e}function Ts(e,t=2,r=t){return e<r?"outdated":e>t?"ahead":"current"}function su(e,t=2,r=t){let n=[],o=[];for(let i of e){let s=Ts(i.version,t,r);s==="outdated"?n.push(i.ref):s==="ahead"&&o.push(i.ref)}return{outdated:n.sort((i,s)=>i.localeCompare(s)),ahead:o.sort((i,s)=>i.localeCompare(s))}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="515840b7-cf86-5d71-8ac1-beac7fd7c8a8")}catch{}})();var As={"in-progress":"in_progress",cancelled:"canceled"};function ct(e,t){if(t){let o=Un(e,t);if(o)return o}if(typeof e!="string")return;let r=e.trim().toLowerCase();if(!r)return;let n=As[r]??r;if(Qe.includes(n))return n}function xs(e,t){return ct(e,t)??e}function lu(e,t){return t.terminal_statuses.has(xs(e,t))}import{encode as Ds}from"@toon-format/toon";import{isDeepStrictEqual as io}from"node:util";import{decode as Cs}from"@toon-format/toon";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="aaa2be03-9478-5fbe-82e6-e4fc86e3735b")}catch{}})();function nr(e){return{value:Cs(e),usedScalarBracketEscape:!1}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="79626299-17a8-573a-9b66-ce37c65e2f5d")}catch{}})();var Ns=/^\s*(<<<<<<<|=======|>>>>>>>)(?:\s.*)?$/;function Rs(e){if(e.length===0)return[];let t=e.split(/\r?\n/),r=[];for(let n=0;n<t.length;n+=1){let o=t[n]??"",i=o.match(Ns);if(!i)continue;let s=i[1];r.push({line:n+1,marker:s,text:o})}return r}function dt(e){return Rs(e)[0]}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="2789e87f-0706-52e8-8f4c-3855c65c618c")}catch{}})();var ar=new Set(["schema","tracker","auto","none"]),uo=new Set(["source","isolated","snapshot"]),Ps=new Set(["legacy","local_mutation","local_source_ref","acknowledged","invalid_provenance","foreign_source_ref"]),js=new Set(["passed","failed","stopped","canceled"]),Ls=new Set(Dn);function Ie(e){return e.replaceAll("\\","/")}function _o(e){for(let t of e)if(t!==0)return t;return 0}function ut(e){for(let[t,r]of Object.entries(e))r===void 0&&delete e[t]}var fo=["id","title","description","created_at","updated_at"],Hs=new Set(J);function mo(e){if(e?.schema)return{statusRegistry:Vn(e.schema),fieldRegistry:Wn(e.schema),unknownFieldPolicy:e.schema.unknown_field_policy??"allow",extensionFieldNames:new Set(e.extensionFieldNames??[]),onWarning:e.onWarning}}function zs(e,t){return e.required?e.required_types.length===0?!0:e.required_types.map(r=>r.toLowerCase()).includes(t.trim().toLowerCase()):!1}function X(e){let t=e.match(/^([a-z_][\w.]*)\s/u)?.[1];throw new w(`Invalid item metadata: ${e}`,E.GENERIC_FAILURE,{code:"item_document_invalid",reason:e.includes("required")?"missing_required_field":"schema_validation_error",...t?{field:t}:{},required:"Provide an item document whose metadata satisfies the active runtime schema.",why:e})}function We(e,t){throw new w(t,E.GENERIC_FAILURE,{code:"item_document_invalid",reason:"syntax_error",format:e,required:`Provide a syntactically valid ${e==="toon"?"TOON":"JSON Markdown"} item document.`,why:"The document could not be decoded far enough to validate item metadata."})}function po(e,t){if(!t||typeof e!="object"||e===null)return;let r=rr(e);if(!(r<=tr))throw new w(`Stored item uses format version ${r}; this runtime supports up to ${tr}. Upgrade pm before reading or changing this item.`,E.CONFLICT,{code:"item_format_version_unsupported",format_version:r,required:"Upgrade to a pm runtime supporting the stored item format.",nextSteps:["Preserve the original item and history; do not lower pm_format_version to bypass compatibility checks."]})}function ho(e){let t=new Set(Hs);for(let r of e.fieldRegistry?.definitions??[])t.add(r.metadata_key);for(let r of e.extensionFieldNames)t.add(r);return t}function y(e,t){e||X(t)}function qe(e,t){return(typeof e!="object"||e===null||Array.isArray(e))&&X(t),e}function or(e,t){let r=e[t];y(typeof r=="string",`${t} must be a string`),y(q(r),`${t} must be a valid ISO timestamp`)}function so(e,t,r){let n=e[t];n!==void 0&&y(typeof n=="number"&&Number.isInteger(n)&&n>=1,`${r} must be an integer >= 1`)}function cr(e,t,r){let n=e[t];n!==void 0&&(y(typeof n=="string",`${r} must be a string`),y(q(n),`${r} must be a valid ISO timestamp`))}function Fs(e){if(e!==void 0){y(Array.isArray(e),"event.recurrence.by_weekday must be an array");for(let t of e){y(typeof t=="string","event.recurrence.by_weekday entries must be strings");let r=t.trim().toLowerCase();y(nt.includes(r),`event.recurrence.by_weekday entries must be one of: ${nt.join(", ")}`)}}}function $s(e){if(e!==void 0){y(Array.isArray(e),"event.recurrence.by_month_day must be an array");for(let t of e)y(typeof t=="number"&&Number.isInteger(t)&&t>=1&&t<=31,"event.recurrence.by_month_day entries must be integers 1..31")}}function Ms(e){if(e!==void 0){y(Array.isArray(e),"event.recurrence.exdates must be an array");for(let t of e)y(typeof t=="string","event.recurrence.exdates entries must be strings"),y(q(t),"event.recurrence.exdates entries must be valid ISO timestamps")}}function Vs(e){let t=qe(e,"event.recurrence must be an object");y(typeof t.freq=="string","event.recurrence.freq must be a string");let r=t.freq.trim().toLowerCase();y(rt.includes(r),`event.recurrence.freq must be one of: ${rt.join(", ")}`),so(t,"interval","event.recurrence.interval"),so(t,"count","event.recurrence.count"),cr(t,"until","event.recurrence.until"),Fs(t.by_weekday),$s(t.by_month_day),Ms(t.exdates)}function Us(e){for(let n of fo)y(typeof e[n]=="string",`${n} is required and must be a string`);let t=e.type;y(typeof t=="string"&&t.trim().length>0,"type must be a non-empty string");let r=e.pm_format_version;return r!==void 0&&y(typeof r=="number"&&Number.isInteger(r)&&r>=er,`pm_format_version must be an integer >= ${er}`),t}function Ws(e,t){let r=e.status;y(typeof r=="string"&&r.trim().length>0,"status must be a non-empty string");let n=t?.statusRegistry,o=ct(r,n),i=n?n.definitions.map(s=>s.id):[...Qe];y(o!==void 0,`status must be one of: ${i.join(", ")}`)}function qs(e){let t=e.priority;y(typeof t=="number"&&Number.isInteger(t)&&[0,1,2,3,4].includes(t),"priority must be an integer 0..4");let r=e.tags;y(Array.isArray(r),"tags must be an array");for(let n of r)y(typeof n=="string","tags entries must be strings")}function Gs(e){let t=e.confidence;if(t!==void 0){if(typeof t=="number"){y(Number.isInteger(t)&&t>=0&&t<=100,"confidence number value must be an integer 0..100");return}if(typeof t=="string"){let r=t.trim().toLowerCase(),n=r==="med"||tt.includes(r);y(n,`confidence string value must be one of: ${[...tt,"med"].join(", ")}`);return}y(!1,"confidence must be a number or string")}}function Bs(e){let t=e.severity;if(t===void 0)return;typeof t!="string"&&X("severity must be a string");let r=t.trim().toLowerCase(),n=r==="med"||et.includes(r);y(n,`severity value must be one of: ${[...et,"med"].join(", ")}`)}function Js(e){e.regression!==void 0&&typeof e.regression!="boolean"&&X("regression must be a boolean")}function Ks(e){let t=e.reminders;if(t!==void 0){y(Array.isArray(t),"reminders must be an array");for(let r of t){let n=qe(r,"reminders entries must be objects");y(typeof n.at=="string","reminder.at must be a string"),y(q(n.at),"reminder.at must be a valid ISO timestamp"),y(typeof n.text=="string","reminder.text must be a string"),y(n.text.trim().length>0,"reminder.text must not be empty")}}}function Xs(e){for(let t of["title","description","location","timezone"])e[t]!==void 0&&(y(typeof e[t]=="string",`event.${t} must be a string`),y(e[t].trim().length>0,`event.${t} must not be empty`))}function Ys(e){e.recurrence!==void 0&&(Vs(e.recurrence),e.recurrence.until!==void 0&&y(G(e.recurrence.until,e.start_at)>=0,"event.recurrence.until must be at or after event.start_at"))}function Zs(e){let t=qe(e,"events entries must be objects");y(typeof t.start_at=="string","event.start_at must be a string"),y(q(t.start_at),"event.start_at must be a valid ISO timestamp"),t.end_at!==void 0&&(y(typeof t.end_at=="string","event.end_at must be a string"),y(q(t.end_at),"event.end_at must be a valid ISO timestamp"),y(G(t.end_at,t.start_at)>0,"event.end_at must be after event.start_at")),Xs(t),t.all_day!==void 0&&y(typeof t.all_day=="boolean","event.all_day must be a boolean"),Ys(t)}function Qs(e){let t=e.events;if(t!==void 0){y(Array.isArray(t),"events must be an array");for(let r of t)Zs(r)}}function ea(e){for(let t of["source_type","source_owner","design","external_ref"]){let r=e[t];r!==void 0&&y(typeof r=="string",`${t} must be a string`)}}function ta(e){let t=e.type_options;if(t===void 0)return;let r=qe(t,"type_options must be an object");for(let[n,o]of Object.entries(r))y(n.trim().length>0,"type_options keys must be non-empty"),y(typeof o=="string","type_options values must be strings"),y(o.trim().length>0,"type_options values must be non-empty strings")}function ra(e,t,r){if(r?.fieldRegistry)for(let n of r.fieldRegistry.definitions){let o=e[n.metadata_key];if(o===void 0){zs(n,t)&&X(`missing required schema field: ${n.metadata_key}`);continue}try{e[n.metadata_key]=Me(n,o,`metadata field "${n.metadata_key}"`,"metadata")}catch(i){X(String(i?.message).replace(/^Invalid\s+/u,""))}}}function na(e,t){if(!t||t.unknownFieldPolicy==="allow")return;let r=ho(t),n=Object.keys(e).filter(o=>!r.has(o)).sort((o,i)=>o.localeCompare(i));n.length!==0&&(t.unknownFieldPolicy==="reject"?X(`unknown schema fields are not allowed: ${n.join(", ")}`):t.onWarning?.(`item_unknown_schema_fields:${n.join(",")}`))}function dr(e,t){let r=qe(e,"item metadata must be an object"),n=Us(r);Ws(r,t),qs(r),Gs(r),Bs(r),Js(r),or(r,"created_at"),or(r,"updated_at"),r.deadline!==void 0&&or(r,"deadline"),Ks(r),Qs(r),cr(r,"closed_at","closed_at"),cr(r,"completed_at","completed_at"),ea(r),ta(r),ra(r,n,t),na(r,t)}function oa(e){if(!(!e||e.length===0))return[...e].map((t,r)=>(y(t.created_at===void 0||typeof t.created_at=="string"&&st(t.created_at),`dependencies.${r}.created_at requires a valid timestamp; restore the dependency timestamp from its source record`),{id:t.id.trim(),kind:t.kind,created_at:t.created_at,author:t.author?.trim()||void 0,source_kind:t.source_kind?.trim()||void 0,author_source:t.author_source})).sort((t,r)=>{let n=G(t.created_at??"",r.created_at??"");if(n!==0)return n;let o=t.id.localeCompare(r.id);if(o!==0)return o;let i=t.kind.localeCompare(r.kind);return i!==0?i:(t.source_kind??"").localeCompare(r.source_kind??"")})}function ir(e){if(!(!e||e.length===0))return[...e].sort((t,r)=>{let n=G(t.created_at,r.created_at);if(n!==0)return n;let o=t.text.localeCompare(r.text);return o!==0?o:t.author.localeCompare(r.author)})}function ia(e){if(!e||e.length===0)return;let t=[...e].map(r=>({at:r.at,text:r.text.trim()})).filter(r=>r.text.length>0).sort((r,n)=>{let o=G(r.at,n.at);return o!==0?o:r.text.localeCompare(n.text)});return t.length===0?void 0:t}function sa(e){if(!e)return;let t=e.freq.trim().toLowerCase();if(!rt.includes(t))return;let r=Array.from(new Set((e.by_weekday??[]).map(s=>s.trim().toLowerCase()).filter(s=>nt.includes(s)))).sort((s,a)=>Xt(s)-Xt(a)),n=Array.from(new Set((e.by_month_day??[]).filter(s=>Number.isInteger(s)&&s>=1&&s<=31).map(s=>s))).sort((s,a)=>s-a),o=Array.from(new Set((e.exdates??[]).map(s=>s.trim()).filter(s=>q(s)))).sort((s,a)=>G(s,a)),i={freq:t,interval:e.interval!==void 0&&e.interval>1?e.interval:void 0,count:e.count,until:e.until?.trim()||void 0,by_weekday:r.length>0?r:void 0,by_month_day:n.length>0?n:void 0,exdates:o.length>0?o:void 0};for(let[s,a]of Object.entries(i))a===void 0&&delete i[s];return i}function aa(e){return!Array.isArray(e)||e.length===0?void 0:[...e].map(ca).sort(da)}function ca(e){let t={start_at:e.start_at,end_at:e.end_at||void 0,title:e.title?.trim()||void 0,description:e.description?.trim()||void 0,location:e.location?.trim()||void 0,all_day:e.all_day,timezone:e.timezone?.trim()||void 0,recurrence:sa(e.recurrence)};return ut(t),t}function da(e,t){return _o([G(e.start_at,t.start_at),(e.end_at??"").localeCompare(t.end_at??""),(e.title??"").localeCompare(t.title??""),+!!e.all_day-+!!t.all_day,(e.timezone??"").localeCompare(t.timezone??""),(e.location??"").localeCompare(t.location??""),(e.description??"").localeCompare(t.description??""),JSON.stringify(e.recurrence??{}).localeCompare(JSON.stringify(t.recurrence??{}))])}function la(e){if(!(!e||e.length===0))return e.map(t=>({path:Ie(t.path),scope:t.scope,note:t.note?.trim()||void 0}))}function ua(e){if(!e||e.length===0)return;let t=e.map(pa).filter(r=>r.run_id.length>0&&r.started_at.length>0&&r.finished_at.length>0&&r.recorded_at.length>0).sort((r,n)=>_o([G(r.recorded_at,n.recorded_at),r.run_id.localeCompare(n.run_id),r.kind.localeCompare(n.kind)]));return t.length>0?t:void 0}function ke(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):void 0}function _a(e){return typeof e=="number"&&Number.isFinite(e)&&e>=1?Math.floor(e):void 0}function sr(e){return typeof e=="string"?e:""}function fa(e){if(!Array.isArray(e))return;let t=e.filter(n=>n!==null&&typeof n=="object"&&typeof n.name=="string"&&n.name.trim().length>0&&typeof n.value=="number"&&Number.isFinite(n.value)&&typeof n.recorded_at=="string"&&n.recorded_at.trim().length>0).map(n=>({name:n.name.trim(),value:n.value,unit:typeof n.unit=="string"&&n.unit.trim()||void 0,threshold:typeof n.threshold=="number"&&Number.isFinite(n.threshold)?n.threshold:void 0,recorded_at:n.recorded_at.trim()})),r=[...new Map(t.map(n=>[n.name,n])).values()].sort((n,o)=>n.name.localeCompare(o.name)).slice(0,32);return r.length>0?r:void 0}function lt(e,t){return typeof e=="string"&&t.has(e)?e:void 0}function ma(e){if(!Array.isArray(e))return;let t=e.filter(r=>r&&typeof r.command=="string"&&r.command.trim().length>0).slice(0,32).map(r=>({command:r.command.trim(),requested_pm_context_mode:lt(r.requested_pm_context_mode,ar),pm_context_mode:lt(r.pm_context_mode,ar),workspace_context_mode:lt(r.workspace_context_mode,uo),trust_reason:lt(r.trust_reason,Ps)}));return t.length>0?t:void 0}function pa(e){let t=typeof e.run_id=="string"?e.run_id.trim():"",r=e.kind==="test"||e.kind==="test-all"?e.kind:"test",n=js.has(e.status)?e.status:"failed",o={run_id:t,kind:r,status:n,started_at:sr(e.started_at),finished_at:sr(e.finished_at),recorded_at:sr(e.recorded_at),attempt:_a(e.attempt),resumed_from:e.resumed_from?.trim()||void 0,passed:ke(e.passed)??0,failed:ke(e.failed)??0,skipped:ke(e.skipped)??0,items:ke(e.items),linked_tests:ke(e.linked_tests),fail_on_skipped_triggered:e.fail_on_skipped_triggered===!0?!0:void 0,measurements:fa(e.measurements),executions:ma(e.executions)};return ut(o),o}function ha(e){if(!(!Array.isArray(e)||e.length===0))return e.map(wa)}function Ve(e){if(!Array.isArray(e))return;let t=[...new Set(e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r.length>0))].sort((r,n)=>r.localeCompare(n));return t.length>0?t:void 0}function fr(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function mr(e){return e==="__proto__"||e==="constructor"||e==="prototype"}function ao(e){if(!fr(e))return;let t=Object.entries(e).map(([r,n])=>[r.trim(),String(n).trim()]).filter(([r,n])=>r.length>0&&!mr(r)&&n.length>0).sort(([r],[n])=>r.localeCompare(n));return t.length>0?Object.fromEntries(t):void 0}function ya(e){if(!fr(e))return;let t=Object.entries(e).map(([r,n])=>[r.trim(),Number(n)]).filter(([r,n])=>r.length>0&&!mr(r)&&Number.isFinite(n)).sort(([r],[n])=>r.localeCompare(n));return t.length>0?Object.fromEntries(t):void 0}function ga(e){let t=e?.trim().toLowerCase();if(!(!t||!ar.has(t)))return t}function va(e){let t=e?.trim().toLowerCase();if(!(!t||!uo.has(t)))return t}function ba(e,t){if(t===!0)return{provenance_invalid:!0};if(e===void 0)return{};if(!fr(e))return{provenance_invalid:!0};let r=m(e.author),n=m(e.created_at),o=e.source_kind;return!r||!n||!q(n)||o!=="local_mutation"&&o!=="merge_union"?{provenance_invalid:!0}:{provenance:{author:r,created_at:n,source_kind:o,source_ref:m(e.source_ref)}}}function wa(e){let t={command:e.command?.trim()||void 0,path:e.path?Ie(e.path):void 0,scope:e.scope,timeout_seconds:typeof e.timeout_seconds=="number"&&Number.isFinite(e.timeout_seconds)&&e.timeout_seconds>0?e.timeout_seconds:void 0,pm_context_mode:ga(e.pm_context_mode),workspace_context_mode:va(e.workspace_context_mode),...ba(e.provenance,e.provenance_invalid),updated_by:m(e.updated_by),updated_at:m(e.updated_at),env_set:ao(e.env_set),env_clear:Ve(e.env_clear),shared_host_safe:e.shared_host_safe===!0?!0:void 0,assert_stdout_contains:Ve(e.assert_stdout_contains),assert_stdout_regex:Ve(e.assert_stdout_regex),assert_stderr_contains:Ve(e.assert_stderr_contains),assert_stderr_regex:Ve(e.assert_stderr_regex),assert_stdout_min_lines:ke(e.assert_stdout_min_lines),assert_json_field_equals:ao(e.assert_json_field_equals),assert_json_field_gte:ya(e.assert_json_field_gte),note:e.note?.trim()||void 0};return ut(t),t}function Ea(e){if(!(!e||e.length===0))return[...e].map(t=>({path:Ie(t.path),scope:t.scope,note:t.note?.trim()||void 0})).sort((t,r)=>{let n=t.scope.localeCompare(r.scope);if(n!==0)return n;let o=t.path.localeCompare(r.path);return o!==0?o:(t.note??"").localeCompare(r.note??"")})}function m(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function ka(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.id),i=m(n.kind);if(!o||!i)continue;let s={id:o,kind:i},a=m(n.note);a&&(s.note=a),n.required_before_step===!0&&(s.required_before_step=!0),t.push(s)}return t.length>0?t:void 0}function Sa(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.path);if(!o)continue;let i={path:Ie(o)};(n.scope==="project"||n.scope==="global")&&(i.scope=n.scope);let s=m(n.note);s&&(i.note=s),t.push(i)}return t.length>0?t:void 0}function Ia(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.command),i=m(n.path);if(!o&&!i)continue;let s={};o&&(s.command=o),i&&(s.path=Ie(i));let a=m(n.note);a&&(s.note=a),t.push(s)}return t.length>0?t:void 0}function Oa(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.path);if(!o)continue;let i={path:Ie(o)};(n.scope==="project"||n.scope==="global")&&(i.scope=n.scope);let s=m(n.note);s&&(i.note=s),t.push(i)}return t.length>0?t:void 0}function Ta(e){if(e===null||typeof e!="object")return;let t=e,r=m(t.id),n=m(t.title),o=m(t.status),i=o&&Ls.has(o)?o:void 0,s=zn(t.order)??Number.NaN,a=typeof t.created_at=="string"?t.created_at:"",d=typeof t.updated_at=="string"?t.updated_at:"";if(!r||!n||!i||!Number.isFinite(s)||!a||!d)return;let l={id:r,order:s,title:n,status:i,created_at:a,updated_at:d};return Aa(l,t),l}function Aa(e,t){let r=[["body","body"],["owner","owner"],["evidence","evidence"],["blocked_reason","blocked_reason"],["superseded_by","superseded_by"]];for(let[i,s]of r){let a=m(t[s]);a&&(e[i]=a)}let n=typeof t.completed_at=="string"?t.completed_at:void 0;n&&n.length>0&&(e.completed_at=n);let o=[["linked_items","linked_items",ka],["files","files",Sa],["tests","tests",Ia],["docs","docs",Oa]];for(let[i,s,a]of o){let d=a(t[s]);d&&(e[i]=d)}}function xa(e){if(!Array.isArray(e))return;let t=e.flatMap(r=>{let n=Ta(r);return n?[n]:[]});return t.sort((r,n)=>r.order-n.order),t.length>0?t:void 0}function Ca(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=typeof n.ts=="string"?n.ts:"",i=typeof n.author=="string"?n.author:"",s=m(n.decision);if(!o||!i||!s)continue;let a={ts:o,author:i,decision:s},d=m(n.rationale);d&&(a.rationale=d);let l=m(n.evidence);l&&(a.evidence=l);let _=m(n.step_id);_&&(a.step_id=_),t.push(a)}return t.length>0?t:void 0}function Na(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=typeof n.ts=="string"?n.ts:"",i=typeof n.author=="string"?n.author:"",s=m(n.text);if(!o||!i||!s)continue;let a={ts:o,author:i,text:s},d=m(n.step_id);d&&(a.step_id=d),t.push(a)}return t.length>0?t:void 0}function Ra(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.text);if(!o)continue;let i={text:o},s=m(n.command);s&&(i.command=s);let a=m(n.expected);a&&(i.expected=a),t.push(i)}return t.length>0?t:void 0}function Da(e){if(!e)return;let t=Object.entries(e).map(([r,n])=>[r.trim(),n.trim()]).filter(([r,n])=>r.length>0&&n.length>0).sort((r,n)=>r[0].localeCompare(n[0]));if(t.length!==0)return Object.fromEntries(t)}function Se(e){let t=0;for(;t<e.length&&e[t]===`
1
+ import{c as He,e as ze,f as Fe,i as Mn,j as Vn,k as Un,l as Wn,m as qn}from"./chunk-VFQAZLKO.js";import{h as Zn}from"./chunk-4PW5XWVI.js";import{B as Dn,Be as Zt,Cc as Bn,Ea as $n,Fa as A,Ga as $,Ha as ot,Ia as g,Nc as Jn,Od as $e,Pd as q,Qd as st,Rd as Ee,Sd as G,Vd as Kn,Wd as Xn,Yd as Yn,ae as M,ea as zn,i as Qe,j as An,ja as Fn,k as xn,l as Cn,m as Nn,q as et,r as tt,s as Rn,wc as Gn,x as rt,y as nt,yc as it,z as Xt,za as we}from"./chunk-CIQ6YWCW.js";import{A as w,C as jn,D as W,E as ie,F as be,G as Ln,H as Yt,I as Le,J as Hn,m as J,u as Pn,x as h,y as je,z as E}from"./chunk-JLXGRDTG.js";import{createHash as hs}from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="ca5b60a5-80a7-5e7d-917f-4c7649bcbab6")}catch{}})();var Kl=["sha256","sha512"],ys="sha256",Qn="sha256";function se(e){if(e===void 0)return ys;if(e==="sha256"||e==="sha512")return e;throw new TypeError(`unsupported_history_hash_algorithm:${String(e)}`)}function K(e,t){return hs(se(t)).update(e,"utf8").digest("hex")}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="4d5692ce-ec33-5eb4-bd9b-7497ffe25b0e")}catch{}})();var gs=16;function Qt(e){let t=e.trim().replaceAll(/[^A-Za-z0-9]+/g," ").split(/\s+/).filter(o=>o.length>0).map(o=>o.toLowerCase());if(t.length===0)return e;let[r,...n]=t;return`${r}${n.map(o=>`${o.slice(0,1).toUpperCase()}${o.slice(1)}`).join("")}`}function vs(e){return[...new Set([qn(e),Qt(e.key),Qt(e.cli_flag),...e.cli_aliases.map(t=>Qt(t))])]}function ro(e,t){for(let r of vs(t)){if(!Object.hasOwn(e,r))continue;let n=e[r];if(n!==void 0)return n}}function no(e){return Array.isArray(e)?e.flatMap(t=>no(t)).map(t=>t.trim()).filter(t=>t.length>0):typeof e=="string"?e.split(/[,\n|]/).map(t=>t.trim()).filter(t=>t.length>0):e==null?[]:[String(e).trim()].filter(t=>t.length>0)}function eo(e,t){if(typeof e=="boolean")return e;if(typeof e=="number"){if(e===1)return!0;if(e===0)return!1}if(typeof e=="string"){let r=e.trim().toLowerCase();if(r==="true"||r==="1"||r==="yes")return!0;if(r==="false"||r==="0"||r==="no")return!1}throw new w(`${t} must be one of true|false|1|0|yes|no`,E.USAGE)}function to(e,t){if(typeof e=="number"&&Number.isFinite(e))return e;let r=typeof e=="string"?e.trim():String(e),n=Number(r);if(!Number.isFinite(n))throw new w(`${t} must be a number`,E.USAGE);return n}function bs(e,t,r){let n=typeof e=="string"?(()=>{try{return JSON.parse(e)}catch{return}})():e;if(r==="array"&&Array.isArray(n)||r==="object"&&typeof n=="object"&&n!==null&&!Array.isArray(n))return n;throw new w(`${t} must be valid JSON ${r}`,E.USAGE)}function ws(e,t){return t===void 0?!0:t==="array"?Array.isArray(e):t==="object"?typeof e=="object"&&e!==null&&!Array.isArray(e):typeof e===t}function Es(e,t,r){if(t.const!==void 0&&A(e)!==A(t.const))return`${r} must equal ${A(t.const)}`;if(t.enum!==void 0&&!t.enum.some(n=>A(n)===A(e)))return`${r} must be one of ${t.enum.map(n=>A(n)).join("|")}`;if(!ws(e,t.type))return`${r} must match configured type ${String(t.type)}`;if(typeof e=="string"){if(t.min_length!==void 0&&e.length<t.min_length)return`${r} must contain at least ${t.min_length} characters`;if(t.format==="date-time"&&!st(e))return`${r} must be an RFC 3339 date-time`}}function ks(e,t,r,n){if(Array.isArray(e)){if(t.min_items!==void 0&&e.length<t.min_items)return`${r} must contain at least ${t.min_items} items`;if(t.items)for(let[o,i]of e.entries()){let s=at(i,t.items,`${r}[${o}]`,n+1);if(s)return s}}}function Ss(e,t,r,n){if(typeof e!="object"||e===null||Array.isArray(e))return;let o=e;for(let i of t.required??[])if(!Object.hasOwn(o,i))return`${r}.${i} is required`;for(let[i,s]of Object.entries(o)){let a=t.properties?.[i];if(!a){if(t.additional_properties===!1)return`${r}.${i} is not allowed`;continue}let d=at(s,a,`${r}.${i}`,n+1);if(d)return d}}function at(e,t,r,n=0){if(n>gs)return`${r} value schema exceeds maximum depth`;let o=Es(e,t,r);if(o)return o;let i=ks(e,t,r,n);if(i)return i;let s=Ss(e,t,r,n);if(s)return s;if(!t.one_of)return;let a=0;for(let d of t.one_of)if(at(e,d,r,n+1)===void 0&&(a+=1,a>1))break;return a===1?void 0:`${r} must match exactly one configured schema variant`}function ae(e,t,r){if(!e.value_schema||t===void 0)return t;let n=at(t,e.value_schema,r);if(n)throw new w(n,E.USAGE);return t}function Is(e,t,r,n){let o=n==="option"&&Array.isArray(t)?t[t.length-1]:t;if(o!==void 0)return ae(e,bs(o,r,e.type),r)}function Me(e,t,r,n="option"){let o=r??`--${e.cli_flag}`;if(e.type==="array"||e.type==="object")return Is(e,t,o,n);if(e.repeatable||e.type==="string_array"){let s=no(t);return e.type==="number"?ae(e,s.map(a=>to(a,o)),o):e.type==="boolean"?ae(e,s.map(a=>eo(a,o)),o):ae(e,s,o)}let i=Array.isArray(t)?t[t.length-1]:t;if(i!==void 0)return e.type==="number"?ae(e,to(i,o),o):e.type==="boolean"?ae(e,eo(i,o),o):ae(e,typeof i=="string"?i:String(i),o)}function Os(e,t){return!e.required&&!e.required_on_create?!1:e.required_types.length===0?!0:t?e.required_types.map(r=>r.toLowerCase()).includes(t.trim().toLowerCase()):!1}function ru(e,t,r){let n={},o=[];for(let i of t.command_to_fields.get("create")??[]){let s=ro(e,i);if(s===void 0){Os(i,r)&&o.push(`--${i.cli_flag}`);continue}n[i.metadata_key]=Me(i,s)}return{values:n,missing_required_flags:[...new Set(o)].sort((i,s)=>i.localeCompare(s))}}function nu(e,t,r=["update"]){let n={},o=(r??["update"]).flatMap(s=>t.command_to_fields.get(s)??[]),i=new Set;for(let s of o){let a=ro(e,s);a!==void 0&&(i.has(s.metadata_key)||(i.add(s.metadata_key),n[s.metadata_key]=Me(s,a)))}return n}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="c35d4830-d7d1-5ee4-99bc-ab52cc3e4e09")}catch{}})();var er=1,tr=2;function iu(e){return Math.max(rr(e),e.tests?.some(t=>t.updated_by!==void 0||t.updated_at!==void 0)?2:1)}function rr(e){let t=e.pm_format_version;return typeof t=="number"&&Number.isInteger(t)&&t>=1?t:1}function oo(e){if(!(typeof e!="number"||!Number.isInteger(e)||e<=1))return e}function Ts(e,t=2,r=t){return e<r?"outdated":e>t?"ahead":"current"}function su(e,t=2,r=t){let n=[],o=[];for(let i of e){let s=Ts(i.version,t,r);s==="outdated"?n.push(i.ref):s==="ahead"&&o.push(i.ref)}return{outdated:n.sort((i,s)=>i.localeCompare(s)),ahead:o.sort((i,s)=>i.localeCompare(s))}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="515840b7-cf86-5d71-8ac1-beac7fd7c8a8")}catch{}})();var As={"in-progress":"in_progress",cancelled:"canceled"};function ct(e,t){if(t){let o=Un(e,t);if(o)return o}if(typeof e!="string")return;let r=e.trim().toLowerCase();if(!r)return;let n=As[r]??r;if(Qe.includes(n))return n}function xs(e,t){return ct(e,t)??e}function lu(e,t){return t.terminal_statuses.has(xs(e,t))}import{encode as Ds}from"@toon-format/toon";import{isDeepStrictEqual as io}from"node:util";import{decode as Cs}from"@toon-format/toon";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="aaa2be03-9478-5fbe-82e6-e4fc86e3735b")}catch{}})();function nr(e){return{value:Cs(e),usedScalarBracketEscape:!1}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="79626299-17a8-573a-9b66-ce37c65e2f5d")}catch{}})();var Ns=/^\s*(<<<<<<<|=======|>>>>>>>)(?:\s.*)?$/;function Rs(e){if(e.length===0)return[];let t=e.split(/\r?\n/),r=[];for(let n=0;n<t.length;n+=1){let o=t[n]??"",i=o.match(Ns);if(!i)continue;let s=i[1];r.push({line:n+1,marker:s,text:o})}return r}function dt(e){return Rs(e)[0]}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="2789e87f-0706-52e8-8f4c-3855c65c618c")}catch{}})();var ar=new Set(["schema","tracker","auto","none"]),uo=new Set(["source","isolated","snapshot"]),Ps=new Set(["legacy","local_mutation","local_source_ref","acknowledged","invalid_provenance","foreign_source_ref"]),js=new Set(["passed","failed","stopped","canceled"]),Ls=new Set(Dn);function Ie(e){return e.replaceAll("\\","/")}function _o(e){for(let t of e)if(t!==0)return t;return 0}function ut(e){for(let[t,r]of Object.entries(e))r===void 0&&delete e[t]}var fo=["id","title","description","created_at","updated_at"],Hs=new Set(J);function mo(e){if(e?.schema)return{statusRegistry:Vn(e.schema),fieldRegistry:Wn(e.schema),unknownFieldPolicy:e.schema.unknown_field_policy??"allow",extensionFieldNames:new Set(e.extensionFieldNames??[]),onWarning:e.onWarning}}function zs(e,t){return e.required?e.required_types.length===0?!0:e.required_types.map(r=>r.toLowerCase()).includes(t.trim().toLowerCase()):!1}function X(e){let t=e.match(/^([a-z_][\w.]*)\s/u)?.[1];throw new w(`Invalid item metadata: ${e}`,E.GENERIC_FAILURE,{code:"item_document_invalid",reason:e.includes("required")?"missing_required_field":"schema_validation_error",...t?{field:t}:{},required:"Provide an item document whose metadata satisfies the active runtime schema.",why:e})}function We(e,t){throw new w(t,E.GENERIC_FAILURE,{code:"item_document_invalid",reason:"syntax_error",format:e,required:`Provide a syntactically valid ${e==="toon"?"TOON":"JSON Markdown"} item document.`,why:"The document could not be decoded far enough to validate item metadata."})}function po(e,t){if(!t||typeof e!="object"||e===null)return;let r=rr(e);if(!(r<=tr))throw new w(`Stored item uses format version ${r}; this runtime supports up to ${tr}. Upgrade pm before reading or changing this item.`,E.CONFLICT,{code:"item_format_version_unsupported",format_version:r,required:"Upgrade to a pm runtime supporting the stored item format.",nextSteps:["Preserve the original item and history; do not lower pm_format_version to bypass compatibility checks."]})}function ho(e){let t=new Set(Hs);for(let r of e.fieldRegistry?.definitions??[])t.add(r.metadata_key);for(let r of e.extensionFieldNames)t.add(r);return t}function y(e,t){e||X(t)}function qe(e,t){return(typeof e!="object"||e===null||Array.isArray(e))&&X(t),e}function or(e,t){let r=e[t];y(typeof r=="string",`${t} must be a string`),y(q(r),`${t} must be a valid ISO timestamp`)}function so(e,t,r){let n=e[t];n!==void 0&&y(typeof n=="number"&&Number.isInteger(n)&&n>=1,`${r} must be an integer >= 1`)}function cr(e,t,r){let n=e[t];n!==void 0&&(y(typeof n=="string",`${r} must be a string`),y(q(n),`${r} must be a valid ISO timestamp`))}function Fs(e){if(e!==void 0){y(Array.isArray(e),"event.recurrence.by_weekday must be an array");for(let t of e){y(typeof t=="string","event.recurrence.by_weekday entries must be strings");let r=t.trim().toLowerCase();y(nt.includes(r),`event.recurrence.by_weekday entries must be one of: ${nt.join(", ")}`)}}}function $s(e){if(e!==void 0){y(Array.isArray(e),"event.recurrence.by_month_day must be an array");for(let t of e)y(typeof t=="number"&&Number.isInteger(t)&&t>=1&&t<=31,"event.recurrence.by_month_day entries must be integers 1..31")}}function Ms(e){if(e!==void 0){y(Array.isArray(e),"event.recurrence.exdates must be an array");for(let t of e)y(typeof t=="string","event.recurrence.exdates entries must be strings"),y(q(t),"event.recurrence.exdates entries must be valid ISO timestamps")}}function Vs(e){let t=qe(e,"event.recurrence must be an object");y(typeof t.freq=="string","event.recurrence.freq must be a string");let r=t.freq.trim().toLowerCase();y(rt.includes(r),`event.recurrence.freq must be one of: ${rt.join(", ")}`),so(t,"interval","event.recurrence.interval"),so(t,"count","event.recurrence.count"),cr(t,"until","event.recurrence.until"),Fs(t.by_weekday),$s(t.by_month_day),Ms(t.exdates)}function Us(e){for(let n of fo)y(typeof e[n]=="string",`${n} is required and must be a string`);let t=e.type;y(typeof t=="string"&&t.trim().length>0,"type must be a non-empty string");let r=e.pm_format_version;return r!==void 0&&y(typeof r=="number"&&Number.isInteger(r)&&r>=er,`pm_format_version must be an integer >= ${er}`),t}function Ws(e,t){let r=e.status;y(typeof r=="string"&&r.trim().length>0,"status must be a non-empty string");let n=t?.statusRegistry,o=ct(r,n),i=n?n.definitions.map(s=>s.id):[...Qe];y(o!==void 0,`status must be one of: ${i.join(", ")}`)}function qs(e){let t=e.priority;y(typeof t=="number"&&Number.isInteger(t)&&[0,1,2,3,4].includes(t),"priority must be an integer 0..4");let r=e.tags;y(Array.isArray(r),"tags must be an array");for(let n of r)y(typeof n=="string","tags entries must be strings")}function Gs(e){let t=e.confidence;if(t!==void 0){if(typeof t=="number"){y(Number.isInteger(t)&&t>=0&&t<=100,"confidence number value must be an integer 0..100");return}if(typeof t=="string"){let r=t.trim().toLowerCase(),n=r==="med"||tt.includes(r);y(n,`confidence string value must be one of: ${[...tt,"med"].join(", ")}`);return}y(!1,"confidence must be a number or string")}}function Bs(e){let t=e.severity;if(t===void 0)return;typeof t!="string"&&X("severity must be a string");let r=t.trim().toLowerCase(),n=r==="med"||et.includes(r);y(n,`severity value must be one of: ${[...et,"med"].join(", ")}`)}function Js(e){e.regression!==void 0&&typeof e.regression!="boolean"&&X("regression must be a boolean")}function Ks(e){let t=e.reminders;if(t!==void 0){y(Array.isArray(t),"reminders must be an array");for(let r of t){let n=qe(r,"reminders entries must be objects");y(typeof n.at=="string","reminder.at must be a string"),y(q(n.at),"reminder.at must be a valid ISO timestamp"),y(typeof n.text=="string","reminder.text must be a string"),y(n.text.trim().length>0,"reminder.text must not be empty")}}}function Xs(e){for(let t of["title","description","location","timezone"])e[t]!==void 0&&(y(typeof e[t]=="string",`event.${t} must be a string`),y(e[t].trim().length>0,`event.${t} must not be empty`))}function Ys(e){e.recurrence!==void 0&&(Vs(e.recurrence),e.recurrence.until!==void 0&&y(G(e.recurrence.until,e.start_at)>=0,"event.recurrence.until must be at or after event.start_at"))}function Zs(e){let t=qe(e,"events entries must be objects");y(typeof t.start_at=="string","event.start_at must be a string"),y(q(t.start_at),"event.start_at must be a valid ISO timestamp"),t.end_at!==void 0&&(y(typeof t.end_at=="string","event.end_at must be a string"),y(q(t.end_at),"event.end_at must be a valid ISO timestamp"),y(G(t.end_at,t.start_at)>0,"event.end_at must be after event.start_at")),Xs(t),t.all_day!==void 0&&y(typeof t.all_day=="boolean","event.all_day must be a boolean"),Ys(t)}function Qs(e){let t=e.events;if(t!==void 0){y(Array.isArray(t),"events must be an array");for(let r of t)Zs(r)}}function ea(e){for(let t of["source_type","source_owner","design","external_ref"]){let r=e[t];r!==void 0&&y(typeof r=="string",`${t} must be a string`)}}function ta(e){let t=e.type_options;if(t===void 0)return;let r=qe(t,"type_options must be an object");for(let[n,o]of Object.entries(r))y(n.trim().length>0,"type_options keys must be non-empty"),y(typeof o=="string","type_options values must be strings"),y(o.trim().length>0,"type_options values must be non-empty strings")}function ra(e,t,r){if(r?.fieldRegistry)for(let n of r.fieldRegistry.definitions){let o=e[n.metadata_key];if(o===void 0){zs(n,t)&&X(`missing required schema field: ${n.metadata_key}`);continue}try{e[n.metadata_key]=Me(n,o,`metadata field "${n.metadata_key}"`,"metadata")}catch(i){X(String(i?.message).replace(/^Invalid\s+/u,""))}}}function na(e,t){if(!t||t.unknownFieldPolicy==="allow")return;let r=ho(t),n=Object.keys(e).filter(o=>!r.has(o)).sort((o,i)=>o.localeCompare(i));n.length!==0&&(t.unknownFieldPolicy==="reject"?X(`unknown schema fields are not allowed: ${n.join(", ")}`):t.onWarning?.(`item_unknown_schema_fields:${n.join(",")}`))}function dr(e,t){let r=qe(e,"item metadata must be an object"),n=Us(r);Ws(r,t),qs(r),Gs(r),Bs(r),Js(r),or(r,"created_at"),or(r,"updated_at"),r.deadline!==void 0&&or(r,"deadline"),Ks(r),Qs(r),cr(r,"closed_at","closed_at"),cr(r,"completed_at","completed_at"),ea(r),ta(r),ra(r,n,t),na(r,t)}function oa(e){if(!(!e||e.length===0))return[...e].map((t,r)=>(y(t.created_at===void 0||typeof t.created_at=="string"&&st(t.created_at),`dependencies.${r}.created_at requires a valid timestamp; restore the dependency timestamp from its source record`),{id:t.id.trim(),kind:t.kind,created_at:t.created_at,author:t.author?.trim()||void 0,source_kind:t.source_kind?.trim()||void 0,author_source:t.author_source})).sort((t,r)=>{let n=G(t.created_at??"",r.created_at??"");if(n!==0)return n;let o=t.id.localeCompare(r.id);if(o!==0)return o;let i=t.kind.localeCompare(r.kind);return i!==0?i:(t.source_kind??"").localeCompare(r.source_kind??"")})}function ir(e){if(!(!e||e.length===0))return[...e].sort((t,r)=>{let n=G(t.created_at,r.created_at);if(n!==0)return n;let o=t.text.localeCompare(r.text);return o!==0?o:t.author.localeCompare(r.author)})}function ia(e){if(!e||e.length===0)return;let t=[...e].map(r=>({at:r.at,text:r.text.trim()})).filter(r=>r.text.length>0).sort((r,n)=>{let o=G(r.at,n.at);return o!==0?o:r.text.localeCompare(n.text)});return t.length===0?void 0:t}function sa(e){if(!e)return;let t=e.freq.trim().toLowerCase();if(!rt.includes(t))return;let r=Array.from(new Set((e.by_weekday??[]).map(s=>s.trim().toLowerCase()).filter(s=>nt.includes(s)))).sort((s,a)=>Xt(s)-Xt(a)),n=Array.from(new Set((e.by_month_day??[]).filter(s=>Number.isInteger(s)&&s>=1&&s<=31).map(s=>s))).sort((s,a)=>s-a),o=Array.from(new Set((e.exdates??[]).map(s=>s.trim()).filter(s=>q(s)))).sort((s,a)=>G(s,a)),i={freq:t,interval:e.interval!==void 0&&e.interval>1?e.interval:void 0,count:e.count,until:e.until?.trim()||void 0,by_weekday:r.length>0?r:void 0,by_month_day:n.length>0?n:void 0,exdates:o.length>0?o:void 0};for(let[s,a]of Object.entries(i))a===void 0&&delete i[s];return i}function aa(e){return!Array.isArray(e)||e.length===0?void 0:[...e].map(ca).sort(da)}function ca(e){let t={start_at:e.start_at,end_at:e.end_at||void 0,title:e.title?.trim()||void 0,description:e.description?.trim()||void 0,location:e.location?.trim()||void 0,all_day:e.all_day,timezone:e.timezone?.trim()||void 0,recurrence:sa(e.recurrence)};return ut(t),t}function da(e,t){return _o([G(e.start_at,t.start_at),(e.end_at??"").localeCompare(t.end_at??""),(e.title??"").localeCompare(t.title??""),+!!e.all_day-+!!t.all_day,(e.timezone??"").localeCompare(t.timezone??""),(e.location??"").localeCompare(t.location??""),(e.description??"").localeCompare(t.description??""),JSON.stringify(e.recurrence??{}).localeCompare(JSON.stringify(t.recurrence??{}))])}function la(e){if(!(!e||e.length===0))return e.map(t=>({path:Ie(t.path),scope:t.scope,note:t.note?.trim()||void 0}))}function ua(e){if(!e||e.length===0)return;let t=e.map(pa).filter(r=>r.run_id.length>0&&r.started_at.length>0&&r.finished_at.length>0&&r.recorded_at.length>0).sort((r,n)=>_o([G(r.recorded_at,n.recorded_at),r.run_id.localeCompare(n.run_id),r.kind.localeCompare(n.kind)]));return t.length>0?t:void 0}function ke(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.floor(e):void 0}function _a(e){return typeof e=="number"&&Number.isFinite(e)&&e>=1?Math.floor(e):void 0}function sr(e){return typeof e=="string"?e:""}function fa(e){if(!Array.isArray(e))return;let t=e.filter(n=>n!==null&&typeof n=="object"&&typeof n.name=="string"&&n.name.trim().length>0&&typeof n.value=="number"&&Number.isFinite(n.value)&&typeof n.recorded_at=="string"&&n.recorded_at.trim().length>0).map(n=>({name:n.name.trim(),value:n.value,unit:typeof n.unit=="string"&&n.unit.trim()||void 0,threshold:typeof n.threshold=="number"&&Number.isFinite(n.threshold)?n.threshold:void 0,recorded_at:n.recorded_at.trim()})),r=[...new Map(t.map(n=>[n.name,n])).values()].sort((n,o)=>n.name.localeCompare(o.name)).slice(0,32);return r.length>0?r:void 0}function lt(e,t){return typeof e=="string"&&t.has(e)?e:void 0}function ma(e){if(!Array.isArray(e))return;let t=e.filter(r=>r&&typeof r.command=="string"&&r.command.trim().length>0).slice(0,32).map(r=>({command:r.command.trim(),requested_pm_context_mode:lt(r.requested_pm_context_mode,ar),pm_context_mode:lt(r.pm_context_mode,ar),workspace_context_mode:lt(r.workspace_context_mode,uo),trust_reason:lt(r.trust_reason,Ps)}));return t.length>0?t:void 0}function pa(e){let t=typeof e.run_id=="string"?e.run_id.trim():"",r=e.kind==="test"||e.kind==="test-all"?e.kind:"test",n=js.has(e.status)?e.status:"failed",o={run_id:t,kind:r,status:n,started_at:sr(e.started_at),finished_at:sr(e.finished_at),recorded_at:sr(e.recorded_at),attempt:_a(e.attempt),resumed_from:e.resumed_from?.trim()||void 0,passed:ke(e.passed)??0,failed:ke(e.failed)??0,skipped:ke(e.skipped)??0,items:ke(e.items),linked_tests:ke(e.linked_tests),fail_on_skipped_triggered:e.fail_on_skipped_triggered===!0?!0:void 0,measurements:fa(e.measurements),executions:ma(e.executions)};return ut(o),o}function ha(e){if(!(!Array.isArray(e)||e.length===0))return e.map(wa)}function Ve(e){if(!Array.isArray(e))return;let t=[...new Set(e.filter(r=>typeof r=="string").map(r=>r.trim()).filter(r=>r.length>0))].sort((r,n)=>r.localeCompare(n));return t.length>0?t:void 0}function fr(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function mr(e){return e==="__proto__"||e==="constructor"||e==="prototype"}function ao(e){if(!fr(e))return;let t=Object.entries(e).map(([r,n])=>[r.trim(),String(n).trim()]).filter(([r,n])=>r.length>0&&!mr(r)&&n.length>0).sort(([r],[n])=>r.localeCompare(n));return t.length>0?Object.fromEntries(t):void 0}function ya(e){if(!fr(e))return;let t=Object.entries(e).map(([r,n])=>[r.trim(),Number(n)]).filter(([r,n])=>r.length>0&&!mr(r)&&Number.isFinite(n)).sort(([r],[n])=>r.localeCompare(n));return t.length>0?Object.fromEntries(t):void 0}function ga(e){let t=e?.trim().toLowerCase();if(!(!t||!ar.has(t)))return t}function va(e){let t=e?.trim().toLowerCase();if(!(!t||!uo.has(t)))return t}function ba(e,t){if(t===!0)return{provenance_invalid:!0};if(e===void 0)return{};if(!fr(e))return{provenance_invalid:!0};let r=m(e.author),n=m(e.created_at),o=e.source_kind;return!r||!n||!q(n)||o!=="local_mutation"&&o!=="merge_union"?{provenance_invalid:!0}:{provenance:{author:r,created_at:n,source_kind:o,source_ref:m(e.source_ref)}}}function wa(e){let t={command:e.command?.trim()||void 0,path:e.path?Ie(e.path):void 0,scope:e.scope,timeout_seconds:typeof e.timeout_seconds=="number"&&Number.isFinite(e.timeout_seconds)&&e.timeout_seconds>0?e.timeout_seconds:void 0,pm_context_mode:ga(e.pm_context_mode),workspace_context_mode:va(e.workspace_context_mode),...ba(e.provenance,e.provenance_invalid),updated_by:m(e.updated_by),updated_at:m(e.updated_at),env_set:ao(e.env_set),env_clear:Ve(e.env_clear),shared_host_safe:e.shared_host_safe===!0?!0:void 0,assert_stdout_contains:Ve(e.assert_stdout_contains),assert_stdout_regex:Ve(e.assert_stdout_regex),assert_stderr_contains:Ve(e.assert_stderr_contains),assert_stderr_regex:Ve(e.assert_stderr_regex),assert_stdout_min_lines:ke(e.assert_stdout_min_lines),assert_json_field_equals:ao(e.assert_json_field_equals),assert_json_field_gte:ya(e.assert_json_field_gte),note:e.note?.trim()||void 0};return ut(t),t}function Ea(e){if(!(!e||e.length===0))return[...e].map(t=>({path:Ie(t.path),scope:t.scope,note:t.note?.trim()||void 0})).sort((t,r)=>{let n=t.scope.localeCompare(r.scope);if(n!==0)return n;let o=t.path.localeCompare(r.path);return o!==0?o:(t.note??"").localeCompare(r.note??"")})}function m(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function ka(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.id),i=m(n.kind);if(!o||!i)continue;let s={id:o,kind:i},a=m(n.note);a&&(s.note=a),n.required_before_step===!0&&(s.required_before_step=!0),t.push(s)}return t.length>0?t:void 0}function Sa(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.path);if(!o)continue;let i={path:Ie(o)};(n.scope==="project"||n.scope==="global")&&(i.scope=n.scope);let s=m(n.note);s&&(i.note=s),t.push(i)}return t.length>0?t:void 0}function Ia(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.command),i=m(n.path);if(!o&&!i)continue;let s={};o&&(s.command=o),i&&(s.path=Ie(i));let a=m(n.note);a&&(s.note=a),t.push(s)}return t.length>0?t:void 0}function Oa(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.path);if(!o)continue;let i={path:Ie(o)};(n.scope==="project"||n.scope==="global")&&(i.scope=n.scope);let s=m(n.note);s&&(i.note=s),t.push(i)}return t.length>0?t:void 0}function Ta(e){if(e===null||typeof e!="object")return;let t=e,r=m(t.id),n=m(t.title),o=m(t.status),i=o&&Ls.has(o)?o:void 0,s=zn(t.order)??Number.NaN,a=typeof t.created_at=="string"?t.created_at:"",d=typeof t.updated_at=="string"?t.updated_at:"";if(!r||!n||!i||!Number.isFinite(s)||!a||!d)return;let l={id:r,order:s,title:n,status:i,created_at:a,updated_at:d};return Aa(l,t),l}function Aa(e,t){let r=[["body","body"],["owner","owner"],["evidence","evidence"],["blocked_reason","blocked_reason"],["superseded_by","superseded_by"]];for(let[i,s]of r){let a=m(t[s]);a&&(e[i]=a)}let n=typeof t.completed_at=="string"?t.completed_at:void 0;n&&n.length>0&&(e.completed_at=n);let o=[["linked_items","linked_items",ka],["files","files",Sa],["tests","tests",Ia],["docs","docs",Oa]];for(let[i,s,a]of o){let d=a(t[s]);d&&(e[i]=d)}}function xa(e){if(!Array.isArray(e))return;let t=e.flatMap(r=>{let n=Ta(r);return n?[n]:[]});return t.sort((r,n)=>r.order-n.order),t.length>0?t:void 0}function Ca(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=typeof n.ts=="string"?n.ts:"",i=typeof n.author=="string"?n.author:"",s=m(n.decision);if(!o||!i||!s)continue;let a={ts:o,author:i,decision:s},d=m(n.rationale);d&&(a.rationale=d);let l=m(n.evidence);l&&(a.evidence=l);let _=m(n.step_id);_&&(a.step_id=_),t.push(a)}return t.length>0?t:void 0}function Na(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=typeof n.ts=="string"?n.ts:"",i=typeof n.author=="string"?n.author:"",s=m(n.text);if(!o||!i||!s)continue;let a={ts:o,author:i,text:s},d=m(n.step_id);d&&(a.step_id=d),t.push(a)}return t.length>0?t:void 0}function Ra(e){if(!Array.isArray(e))return;let t=[];for(let r of e){if(r===null||typeof r!="object")continue;let n=r,o=m(n.text);if(!o)continue;let i={text:o},s=m(n.command);s&&(i.command=s);let a=m(n.expected);a&&(i.expected=a),t.push(i)}return t.length>0?t:void 0}function Da(e){if(!e)return;let t=Object.entries(e).map(([r,n])=>[r.trim(),n.trim()]).filter(([r,n])=>r.length>0&&n.length>0).sort((r,n)=>r[0].localeCompare(n[0]));if(t.length!==0)return Object.fromEntries(t)}function Se(e){let t=0;for(;t<e.length&&e[t]===`
2
2
  `;)t+=1;return e.slice(t).trimEnd()}function Pa(e){if(e===void 0)return;if(typeof e=="number")return e;let t=e.trim().toLowerCase();if(t==="med")return"medium";if(tt.includes(t))return t}function ja(e){if(e===void 0)return;let t=e.trim().toLowerCase();if(t==="med")return"medium";if(et.includes(t))return t}function Ue(e){return e||void 0}function La(e,t){let r=e,n=t;for(let[o,i]of Object.entries(n))mr(o)||Object.prototype.hasOwnProperty.call(r,o)||i===void 0||(r[o]=i)}function Ha(e,t){if(!t?.fieldRegistry)return;let r=e;for(let n of t.fieldRegistry.definitions){let o=r[n.metadata_key];o!==void 0&&(r[n.metadata_key]=Me(n,o,`metadata field "${n.metadata_key}"`,"metadata"))}}function za(e,t){if(!t||t.unknownFieldPolicy==="allow")return;let r=ho(t),n=Object.keys(e).filter(o=>!r.has(o)).sort((o,i)=>o.localeCompare(i));n.length>0&&t.unknownFieldPolicy==="reject"&&X(`unknown schema fields are not allowed: ${n.join(", ")}`),n.length>0&&t.onWarning?.(`item_unknown_schema_fields:${n.join(",")}`)}function _t(e,t={}){let r=mo(t),n=ct(e.status,r?.statusRegistry)??e.status,o=Array.from(new Set((Array.isArray(e.tags)?e.tags:[]).filter(s=>typeof s=="string").map(s=>s.trim().toLowerCase()).filter(Boolean))).sort((s,a)=>s.localeCompare(a)),i={id:e.id,title:e.title,description:e.description,type:e.type,pm_format_version:oo(e.pm_format_version),source_type:m(e.source_type),type_options:Da(e.type_options),status:n,priority:e.priority,tags:o,created_at:e.created_at,updated_at:e.updated_at,dependencies:oa(e.dependencies),comments:ir(e.comments),notes:ir(e.notes),learnings:ir(e.learnings),files:la(e.files),tests:ha(e.tests),test_runs:ua(e.test_runs),docs:Ea(e.docs),deadline:Ue(e.deadline),reminders:ia(e.reminders),events:aa(e.events),closed_at:Ue(e.closed_at),completed_at:Ue(e.completed_at),assignee:m(e.assignee),claim_principal:m(e.claim_principal),source_owner:m(e.source_owner),author:Ue(e.author),estimated_minutes:e.estimated_minutes,acceptance_criteria:e.acceptance_criteria??void 0,design:e.design??void 0,external_ref:e.external_ref??void 0,definition_of_ready:m(e.definition_of_ready),order:e.order,goal:m(e.goal),objective:m(e.objective),value:m(e.value),impact:m(e.impact),outcome:m(e.outcome),why_now:m(e.why_now),parent:m(e.parent),reviewer:m(e.reviewer),risk:e.risk??void 0,confidence:Pa(e.confidence),sprint:m(e.sprint),release:m(e.release),blocked_by:m(e.blocked_by),blocked_reason:m(e.blocked_reason),unblock_note:m(e.unblock_note),reporter:m(e.reporter),severity:ja(e.severity),environment:m(e.environment),repro_steps:m(e.repro_steps),resolution:m(e.resolution),expected_result:m(e.expected_result),actual_result:m(e.actual_result),affected_version:m(e.affected_version),fixed_version:m(e.fixed_version),component:m(e.component),regression:e.regression,customer_impact:m(e.customer_impact),close_reason:Ue(e.close_reason),plan_mode:m(e.plan_mode),plan_scope:m(e.plan_scope),plan_harness:m(e.plan_harness),plan_resume_context:m(e.plan_resume_context),plan_steps:xa(e.plan_steps),plan_decisions:Ca(e.plan_decisions),plan_discoveries:Na(e.plan_discoveries),plan_validation:Ra(e.plan_validation)};return La(i,e),Ha(i,r),za(i,r),ut(i),i}function yo(e){return g(e,J)}function Fa(e){let t=0,r=!1,n=!1;for(let o=0;o<e.length;o+=1){let i=e[o];if(r){if(n){n=!1;continue}if(i==="\\"){n=!0;continue}i==='"'&&(r=!1);continue}if(i==='"'){r=!0;continue}if(i==="{"){t+=1;continue}if(i==="}"&&(t-=1,t===0))return o}return-1}function $a(e){if(!e.startsWith("{"))return{frontMatter:"",body:e};let t=Fa(e);if(t<0)return{frontMatter:"",body:e};let r=e.slice(0,t+1),n=e.slice(t+1).replace(/^\r?\n+/,"");return{frontMatter:r,body:n}}function Ma(e){let t=e.charCodeAt(0)===65279?e.slice(1):e,r=t.match(/^[ \t]*---[ \t]*(?:\r?\n|$)/);if(!r)return{content:t,stripped:!1};let n=r[0].length;for(;n<t.length;){let o=t.indexOf(`
3
3
  `,n),i=o===-1?t.length:o,s=t.slice(n,i).replace(/\r$/,""),a=o===-1?i:i+1;if(s.trim()==="---")return{content:t.slice(a).replace(/^\s+/,""),stripped:!0};n=a}return{content:t,stripped:!1}}function lr(e,t){return _t(e,{...t,onWarning:void 0})}function Va(e,t,r={}){let n=Ma(e);n.stripped&&r.onWarning?.("json_markdown_leading_yaml_frontmatter_ignored");let{frontMatter:o,body:i}=$a(n.content);o||(e.trimStart().startsWith("{")&&We("json_markdown","JSON front matter is not valid JSON"),We("json_markdown","JSON Markdown item document is missing JSON front matter"));let s;try{s=JSON.parse(o)}catch{We("json_markdown","JSON front matter is not valid JSON")}return po(s,r.requireSupportedFormat),dr(s,t),{metadata:lr(s,r),body:Se(i)}}function Ua(e,t,r={}){let n;try{n=nr(e).value}catch{We("toon","TOON item document is not valid TOON")}y(typeof n=="object"&&n!==null&&!Array.isArray(n),"TOON item document must be an object");let o=n;if(po(Object.prototype.hasOwnProperty.call(o,"front_matter")?o.front_matter:o,r.requireSupportedFormat),!fo.some(a=>Object.prototype.hasOwnProperty.call(o,a))&&!Object.prototype.hasOwnProperty.call(o,"front_matter")&&We("toon","TOON input does not have the shape of an item document"),Object.prototype.hasOwnProperty.call(o,"front_matter"))return dr(o.front_matter,t),y(o.body===void 0||typeof o.body=="string","TOON item document body must be a string"),{metadata:lr(o.front_matter,r),body:Se(typeof o.body=="string"?o.body:"")};let{body:i,...s}=o;return y(i===void 0||typeof i=="string","TOON item document body must be a string"),dr(s,t),{metadata:lr(s,r),body:Se(typeof i=="string"?i:"")}}function Wa(e,t={}){let r=_t(e.metadata,t),n=yo(r),o=Se(e.body??"");_r(JSON.parse(JSON.stringify(n))),_r({body:o});let i=JSON.stringify(n,null,2);return o?`${i}
4
4
 
@@ -71,9 +71,9 @@ ${o}
71
71
  WHERE recency_rank = 1`).all(...a).map(_i);if(d.includes(null))return null;i.push(...d)}return hi(i,n)}):null}async function tf(e,t){let r=[...new Set(t.filter(a=>a.trim().length>0&&C.basename(a)===a))];if(r.length===0)return{};let n=new Set(r),o=Nt(),i=await ni(o,e,r,n);if(i!==null&&i!==Q)return i;if(o&&i!==Q&&!await ai(e))try{if(await ad(e,{lockWaitMs:0})){let a=await ni(o,e,r,n);if(a!==null&&a!==Q)return a}}catch{}let s=[];return await Promise.all(r.map(async a=>{let d=C.join(e,"history",`${a}.jsonl`);(await id(d,a).catch(l=>{if(l instanceof w&&l.code==="history_timestamp_invalid")return[];throw l})).forEach((l,_)=>{s.push({stream_id:a,stream_offset:_,entry:l})})})),hi(s,n)}import Xr from"node:fs/promises";import Ce from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="687cbe24-6d5c-5322-962d-455048eb84b5")}catch{}})();var vd=Ce.join("runtime","history-drift-cache.json"),yi={EINVAL:"invalid_cache_path",EISDIR:"cache_path_is_directory",ENOENT:"invalid_cache_path",ENOTDIR:"invalid_cache_path",ERR_FS_EISDIR:"cache_path_is_directory"};function gi(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="string"?e.code:void 0}async function bd(e){let t=Ce.join(e,vd),r=!1,n="invalid_cache_path";try{r=(await Xr.stat(await Xr.realpath(e))).isDirectory()}catch(o){let i=gi(o);n=i===void 0?"unknown":yi[i]??"filesystem_error"}if(!r){Zt(`[pm] warning: history_drift_cache_invalidation_failed:${n}
72
72
  `);return}try{await Xr.rm(t,{force:!0})}catch(o){let i=gi(o);if(ie(o))return;let s=i===void 0?"unknown":yi[i]??"filesystem_error";Zt(`[pm] warning: history_drift_cache_invalidation_failed:${s}
73
73
  `)}}async function Rt(e){let t=Ce.dirname(Ce.resolve(e));Ce.basename(t)==="history"&&await bd(Ce.dirname(t))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="4a3c3c82-0398-549c-8910-fdc69d971cb2")}catch{}})();var Ed={front_matter:{},body:""},_e=3,Be=[1,2,3],kd=1,Sd=[1];function Si(e){return K(A(e),e.hash_algorithm)}function Ne(e){return ot(A(e))}function Of(e){return ot(A(e))}function en(e){let t={...e,record_hash_version:kd},{record_hash:r,...n}=t;return{...t,record_hash:Si(n)}}function vt(e){try{se(e.hash_algorithm)}catch{return{ok:!1,error:"unsupported_history_hash_algorithm"}}if(e.record_hash_version===void 0&&e.record_hash===void 0)return{ok:!0,coverage:"item_state_only"};if(e.record_hash_version===void 0||e.record_hash===void 0)return{ok:!1,error:"incomplete_record_hash_envelope"};if(!Sd.includes(e.record_hash_version))return{ok:!1,error:"unsupported_record_hash_version"};let{record_hash:t,...r}=e;return Si(r)===e.record_hash?{ok:!0,coverage:"record_and_item_state"}:{ok:!1,error:"record_hash_mismatch"}}function Id(e,t){let r={before_hash:e.before_hash,after_hash:e.after_hash,patch_hash:Ne(e.patch)};return e.hash_algorithm!==void 0&&(r.hash_algorithm=e.hash_algorithm),e.item_hash_version!==void 0&&(r.item_hash_version=e.item_hash_version),t.retainOriginalPatch&&(r.patch=structuredClone(e.patch)),t.retainPriorRecordHash!==!1&&e.record_hash_version!==void 0&&e.record_hash!==void 0&&(r.record_hash_version=e.record_hash_version,r.record_hash=e.record_hash,r.record=structuredClone(e)),r}function Vo(e,t,r={}){let n=vt(e);if(!n.ok)throw new TypeError(n.error);let o=Ne(e.patch),i=r.retainPriorRecord===!0||e.before_hash!==t.before_hash||e.after_hash!==t.after_hash||e.item_hash_version!==t.item_hash_version||e.hash_algorithm!==t.hash_algorithm||o!==Ne(t.patch),s=en({...t,...i?{reanchor_evidence:[...t.reanchor_evidence??[],Id(e,r)]}:{}}),a=Hr(s);if(!a.ok)throw new TypeError(a.error);return s}function Ii(e){return!Array.isArray(e)||Object.keys(e).length!==e.length?!1:e.every(t=>!he(t)||typeof t.path!="string"?!1:t.op==="move"||t.op==="copy"?typeof t.from=="string":["add","replace","test"].includes(t.op)?Object.hasOwn(t,"value"):t.op==="remove")}function Od(e){return he(e)&&typeof e.ts=="string"&&typeof e.author=="string"&&typeof e.op=="string"&&typeof e.before_hash=="string"&&typeof e.after_hash=="string"&&Ii(e.patch)}function Td(e){let t=e.record_hash_version!==void 0,r=e.record_hash!==void 0;return t===r}function Ad(e){return!he(e)||!Td(e)||typeof e.before_hash!="string"||typeof e.after_hash!="string"||typeof e.patch_hash!="string"||!/^[a-f0-9]{64}$/u.test(e.patch_hash)||e.patch!==void 0&&!Ii(e.patch)||e.record_hash_version!==void 0&&typeof e.record_hash_version!="number"||e.record_hash!==void 0&&(typeof e.record_hash!="string"||!/^(?:[a-f0-9]{64}|[a-f0-9]{128})$/u.test(e.record_hash))?!1:e.record===void 0||Od(e.record)}function xd(e){try{for(let t of e){if(!Ad(t))return!1;se(t.hash_algorithm)}return!0}catch{return!1}}function Cd(e){let t=e.record;return t!==void 0&&t.before_hash===e.before_hash&&t.after_hash===e.after_hash&&t.item_hash_version===e.item_hash_version&&t.hash_algorithm===e.hash_algorithm&&t.record_hash_version===e.record_hash_version&&t.record_hash===e.record_hash&&Ne(t.patch)===e.patch_hash}function Nd(e,t,r){if(t.patch&&Ne(t.patch)!==t.patch_hash)return{kind:"patch_hash_mismatch"};if(t.record)return Cd(t)?{kind:"record",entry:t.record}:{kind:"record_hash_mismatch"};let n=t.patch??e.patch;if(Ne(n)!==t.patch_hash)return{kind:"digest_only"};let o={...e,before_hash:t.before_hash,after_hash:t.after_hash,patch:n,hash_algorithm:t.hash_algorithm,...t.item_hash_version===void 0?{}:{item_hash_version:t.item_hash_version},...t.record_hash_version===void 0?{}:{record_hash_version:t.record_hash_version},...t.record_hash===void 0?{}:{record_hash:t.record_hash},...r.length===0?{}:{reanchor_evidence:r}};return t.hash_algorithm===void 0&&delete o.hash_algorithm,r.length===0&&delete o.reanchor_evidence,t.item_hash_version===void 0&&delete o.item_hash_version,t.record_hash_version===void 0||t.record_hash===void 0?{kind:"legacy",entry:o}:{kind:"record",entry:o}}function Hr(e){let t=e.reanchor_evidence;if(t===void 0)return{ok:!0,coverage:"none"};if(!Array.isArray(t)||!xd(t))return{ok:!1,error:"rewrite_evidence_invalid"};if(t.length===0)return{ok:!0,coverage:"none"};let r=e;for(let n=t.length-1;n>=0;n-=1){let o=t[n],i=Nd(r,o,t.slice(0,n));if(i.kind==="patch_hash_mismatch")return{ok:!1,error:"rewrite_evidence_patch_hash_mismatch"};if(i.kind==="record_hash_mismatch")return{ok:!1,error:"rewrite_evidence_record_hash_mismatch"};if(i.kind==="digest_only")return{ok:!0,coverage:"digest_only"};if(i.kind==="legacy")return{ok:!0,coverage:"legacy_anchor_only"};if(!vt(i.entry).ok)return{ok:!1,error:"rewrite_evidence_record_hash_mismatch"};r=i.entry}return{ok:!0,coverage:"complete"}}function Dt(e,t){return(e??"").localeCompare(t??"")}function bi(e,t){return(e??0)-(t??0)}function ee(e,t,r){return JSON.stringify(e??r).localeCompare(JSON.stringify(t??r))}function Rd(e,t){return[e.scope.localeCompare(t.scope),Dt(e.path,t.path),Dt(e.command,t.command),bi(e.timeout_seconds,t.timeout_seconds),Dt(e.pm_context_mode,t.pm_context_mode),+!!e.shared_host_safe-+!!t.shared_host_safe,ee(e.env_clear,t.env_clear,[]),ee(e.env_set,t.env_set,{}),ee(e.assert_stdout_contains,t.assert_stdout_contains,[]),ee(e.assert_stdout_regex,t.assert_stdout_regex,[]),ee(e.assert_stderr_contains,t.assert_stderr_contains,[]),ee(e.assert_stderr_regex,t.assert_stderr_regex,[]),bi(e.assert_stdout_min_lines,t.assert_stdout_min_lines),ee(e.assert_json_field_equals,t.assert_json_field_equals,{}),ee(e.assert_json_field_gte,t.assert_json_field_gte,{}),Dt(e.note,t.note)].find(r=>r!==0)??0}function Dd(e){return!e||e==="/"?[]:e.startsWith("/")?e.slice(1).split("/").map(t=>t.replaceAll("~1","/").replaceAll("~0","~")):[]}function Pd(e,t){let r=Dd(t);if(r.length===0)return!0;let n=e;for(let o of r){let i=/^(0|[1-9]\d*)$/.test(o)?Number(o):-1,s=Array.isArray(n)?i>=0&&i<n.length?n[i]:void 0:he(n)&&Object.prototype.hasOwnProperty.call(n,o)?n[o]:void 0;if(s===void 0)return!1;n=s}return!0}function jd(e,t){let r=[],n=structuredClone(e);for(let o of t){let i=o.op==="replace"&&!Pd(n,o.path)?{...o,op:"add"}:o;r.push(i),n=ki.applyPatch(n,[i],!0,!0).newDocument}return r}function Pt(e,t,r=!1){if(!(e.metadata&&Object.keys(e.metadata).length>0))return{front_matter:{},body:e.body??""};let n=Oe(e),o=t===1||t===2&&r?{...n.metadata,...n.metadata.dependencies===void 0?{}:{dependencies:n.metadata.dependencies.map(s=>({...s,id:s.id.toLowerCase()}))},...n.metadata.tests===void 0?{}:{tests:n.metadata.tests.map(({workspace_context_mode:s,provenance:a,provenance_invalid:d,...l})=>l)},...n.metadata.test_runs===void 0?{}:{test_runs:n.metadata.test_runs.map(({executions:s,...a})=>a)}}:n.metadata,i=t===1&&o.tests?{...o,tests:[...o.tests].sort(Rd)}:o;return{front_matter:g(i,J),body:n.body}}function wi(e){if(!(e.metadata&&Object.keys(e.metadata).length>0))return{metadata:{},body:e.body??""};let t=Oe(e);return{metadata:g(t.metadata,J),body:t.body}}function Tf(e){return Oi(e,_e)}function Oi(e,t,r){if(!Be.some(n=>n===t))throw new TypeError(`unsupported_item_hash_version:${String(t)}`);return K(A(Pt(e,t)),r)}function Uo(e,t,r){let n=Oi(e,t,r);return t===2?[n,K(A(Pt(e,t,!0)),r)]:[n]}function Af(){return ot(A(Ed))}function tn(e){let t=Zn(e.op),r=Pt(e.before,_e),n=Pt(e.after,_e),o=wi(e.before),i=wi(e.after),s=ki.compare(o,i),a=jd(o,s),d=Ho(e.author),l=d.harness?Object.fromEntries(Object.entries(jo().provenance_outcomes).filter(([O,S])=>S.resolver!==void 0&&(S.status!=="resolved"||d.provenance?.[O]?.source==="probe"))):void 0,_=l===void 0||Object.keys(l).length===0?e.context:{...e.context,agent_provenance_outcomes:l},f=e.hashAlgorithm??Qn,b={hash_algorithm:f,ts:e.nowIso,author:e.author,author_source:e.authorSource??Lo(e.author),...d.harness?{agent_harness:d.harness}:{},...d.model?{agent_model:d.model}:{},...d.model_source?{agent_model_source:d.model_source}:{},...d.instance?{agent_instance:d.instance}:{},...d.provenance?{agent_provenance:d.provenance}:{},...d.episode?{agent_episode:d.episode}:{},op:t,patch:a,before_hash:K(A(r),f),after_hash:K(A(n),f),item_hash_version:_e,message:e.message===void 0?void 0:e.message,..._===void 0?{}:{context:_}};return en({...b,event_class:xe(b)})}function he(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Yr(e){return new w(e,E.GENERIC_FAILURE,{code:"history_timestamp_invalid"})}function Ti(e){let t=e.ts.trim();if(t.length===0)return $e();if(!Ee(t))throw Yr("History timestamp must be a valid RFC 3339 date-time with millisecond precision");if(t!==e.ts)throw Yr("History timestamp must not contain surrounding whitespace");return e.ts}function Ei(e,t){let r=e.ts;if(typeof r=="string"&&r.trim().length>0){if(!Ee(r))throw Yr("History timestamp must be a valid RFC 3339 date-time with millisecond precision");return e}return{...e,ts:t}}function Zr(e,t){let r=Ti(t);if(typeof e=="string"){let n;try{n=JSON.parse(e)}catch{return e}return he(n)?JSON.stringify(Ei(n,r)):e}return he(e)?JSON.stringify(Ei(e,r)):JSON.stringify(e)}async function Ld(e,t,r){if(r===!1)return!0;if(typeof r=="string"){let s=Zr(r,t);return await Qr(e,s),await Rt(e),await Jr(e),!0}if(typeof r!="object"||r===null)return!1;let n=r;if(n.skip===!0)return!0;let o=typeof n.history_path=="string"?n.history_path:e,i=Zr(typeof n.line=="string"?n.line:n.entry??t,t);return await Qr(o,i),await Rt(o),await Jr(o),!0}async function Qr(e,t){let r;try{r=JSON.parse(t)}catch{r=null}if(!he(r)||r.op!=="create"){await Hn(e,t);return}await vi.mkdir(wd.dirname(e),{recursive:!0});try{await vi.writeFile(e,`${t}
74
- `,{encoding:"utf8",flag:"wx"})}catch(n){throw n.code!=="EEXIST"?n:new w("This item identity is reserved by an existing history stream.",E.CONFLICT,{code:"item_identity_reserved",required:"Choose a new item ID or restore the original item from its history.",nextSteps:["Run pm history <id> --full, then pm restore <id> <version> to recover the original item."]})}}async function rn(e,t){let r=await Bn("history_append",{history_path:e,entry:t});if(r.handled&&await Ld(e,t,r.result))return;let n=t.ts.trim().length>0?t:{...t,ts:Ti(t)},o=en({...n,hash_algorithm:se(n.hash_algorithm),event_class:xe(n)});await mi(e,o,async()=>{await Qr(e,Zr(o,o))}),await Rt(e)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="f4ae942c-f11f-5d24-95bf-a2abf3c226da")}catch{}})();var P={ok:!1},u=e=>typeof e=="string"?{ok:!0,value:e}:P,k=e=>typeof e=="boolean"?{ok:!0,value:e}:P;function x(e={}){return t=>typeof t!="number"||!Number.isFinite(t)||e.int&&(!Number.isInteger(t)||!Number.isSafeInteger(t))||e.positive&&t<=0||typeof e.min=="number"&&t<e.min||typeof e.max=="number"&&t>e.max?P:{ok:!0,value:t}}function I(...e){return t=>typeof t=="string"&&e.includes(t)?{ok:!0,value:t}:P}function p(e,t){return r=>{if(!Array.isArray(r)||t!==void 0&&r.length>t)return P;let n=[];for(let o of r){let i=e(o);if(!i.ok)return P;n.push(i.value)}return{ok:!0,value:n}}}function on(e,t){return r=>typeof r=="string"&&r.length>0&&r.length<=e&&r===r.trim()&&(t===void 0||t.test(r))?{ok:!0,value:r}:P}function c(e){return t=>t===void 0?{ok:!0,value:void 0}:e(t)}function jt(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return P;let r={};for(let[n,o]of Object.entries(t)){let i=e(o);if(!i.ok)return P;r[n]=i.value}return{ok:!0,value:r}}}function v(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return P;let r=t,n={};for(let[o,i]of Object.entries(e)){let s=i(r[o]);if(!s.ok)return P;s.value!==void 0&&(n[o]=s.value)}return{ok:!0,value:n}}}var Hd=v({key:u,values:p(u),required:c(k),aliases:c(p(u)),description:c(u)}),zd=v({command:I("create","update"),option:u,required:c(k),visible:c(k),enabled:c(k)}),Fd=v({name:u,description:c(u),default_status:c(u),execution_role:c(I("agent","human","gate")),folder:c(u),aliases:c(p(u)),required_create_fields:c(p(u)),required_create_repeatables:c(p(u)),options:c(p(Hd)),command_option_policies:c(p(zd))}),$d=v({id:u,aliases:c(p(u)),roles:c(p(I(...An))),description:c(u),order:c(x())}),Md=v({key:u,metadata_key:c(u),front_matter_key:c(u),cli_flag:c(u),cli_aliases:c(p(u)),description:c(u),type:c(I(...xn)),commands:c(p(I(...Cn))),repeatable:c(k),required:c(k),required_on_create:c(k),required_types:c(p(u)),allow_unset:c(k)}),Vd=e=>{if(!Array.isArray(e)||e.length!==2)return P;let[t,r]=e;return typeof t!="string"||typeof r!="string"?P:{ok:!0,value:[t,r]}},Ud=v({type:u,allowed_transitions:p(Vd)}),Wd=c(v({version:c(x({int:!0})),files:c(v({types:c(u),statuses:c(u),fields:c(u),workflows:c(u)})),statuses:c(p($d)),fields:c(p(Md)),workflow:c(v({draft_status:c(u),open_status:c(u),in_progress_status:c(u),blocked_status:c(u),close_status:c(u),canceled_status:c(u)})),type_workflows:c(p(Ud)),unknown_field_policy:c(I(...Nn))})),qd=c(v({preset:c(I(...Rn)),ownership_enforcement:c(I("none","warn","strict")),create_mode_default:c(I("progressive","strict")),close_validation_default:c(I("off","warn","strict")),require_close_reason:c(k),parent_reference:c(I("warn","strict_error")),metadata_profile:c(I("core","strict","custom")),force_required_for_stale_lock:c(k),create_default_type:c(u),workflow_enforcement:c(I("off","warn","strict")),duplicate_detection_mode:c(I("off","advisory","strict")),duplicate_detection_threshold:c(x({min:0,max:1})),duplicate_detection_limit:c(x({int:!0,min:0,max:20}))})),Gd=v({name:u,disabled:c(k),require_trusted:c(k),require_provenance:c(k),sandbox_profile:c(I("none","restricted","strict")),allowed_capabilities:c(p(u)),blocked_capabilities:c(p(u)),allowed_surfaces:c(p(u)),blocked_surfaces:c(p(u)),allowed_commands:c(p(u)),blocked_commands:c(p(u)),allowed_actions:c(p(u)),blocked_actions:c(p(u)),allowed_services:c(p(u)),blocked_services:c(p(u))}),nn=I("block","warn"),Bd=e=>typeof e=="string"?nn(e):v({global:c(nn),project:c(nn)})(e),Jd=c(v({mode:c(I("off","warn","enforce")),trust_mode:c(I("off","warn","enforce")),pm_max_version_exceeded_mode:c(Bd),require_provenance:c(k),trusted_extensions:c(p(u)),default_sandbox_profile:c(I("none","restricted","strict")),allowed_extensions:c(p(u)),blocked_extensions:c(p(u)),allowed_capabilities:c(p(u)),blocked_capabilities:c(p(u)),allowed_surfaces:c(p(u)),blocked_surfaces:c(p(u)),allowed_commands:c(p(u)),blocked_commands:c(p(u)),allowed_actions:c(p(u)),blocked_actions:c(p(u)),allowed_services:c(p(u)),blocked_services:c(p(u)),extension_overrides:c(p(Gd))})),ye=on(128),Kd=v({harness:on(128,/^[a-z0-9]+(?:-[a-z0-9]+)*$/u),environment_keys:c(p(ye,64)),model_environment_keys:c(p(ye,64)),session_environment_keys:c(p(ye,64)),provenance_environment_keys:c(jt(p(ye,64))),provenance_resolvers:c(jt(I("ai_agent_version","claude_session_file"))),provenance_unavailable_dimensions:c(p(ye,64)),argv_markers:c(p(ye,64)),client_names:c(p(ye,64))}),Xd=v({version:x({int:!0}),id_prefix:u,ids:c(v({token_length:c(x({int:!0,min:4,max:12}))})),author_default:u,agent_identity:c(v({probes_enabled:c(k),identity_vocabulary:c(v({version:x({int:!0,positive:!0}),aliases:jt(on(128,/^[a-z0-9]+(?:-[a-z0-9]+)*$/u))})),harness_signals:p(Kd)})),mutation_guard:c(v({require_attributed_author:c(k),secret_guard:c(I("off","advise","block")),stale_in_progress_hours:c(x({int:!0,positive:!0}))})),item_format:c(I("toon","json_markdown")),locks:v({ttl_seconds:x({int:!0}),wait_ms:c(x({int:!0,min:0}))}),checkpoints:c(v({retention_days:c(x({int:!0,positive:!0}))})),output:v({default_format:I("toon","json")}),ux:c(v({deprecation_hints:c(k)})),history:c(v({missing_stream:I("auto_create","strict_error"),compact_policy:c(v({enabled:c(k),max_entries:c(x({int:!0,positive:!0})),trigger:c(I("health_warn","auto"))}))})),validation:c(v({sprint_release_format:I("warn","strict_error"),parent_reference:c(I("warn","strict_error")),metadata_profile:c(I("core","strict","custom")),metadata_required_fields:c(p(u)),lifecycle_stale_blocker_reason_patterns:c(p(u)),lifecycle_closure_like_blocked_reason_patterns:c(p(u)),lifecycle_closure_like_resolution_patterns:c(p(u)),lifecycle_closure_like_actual_result_patterns:c(p(u)),estimate_defaults_by_type:c(jt(x({int:!0,positive:!0})))})),governance:qd,workflow:c(v({definition_of_done:p(u)})),testing:c(v({record_results_to_items:k,allow_untrusted_linked_tests:c(k)})),telemetry:c(v({enabled:k,first_run_prompt_completed:c(k),capture_level:c(I("minimal","redacted","max")),endpoint:c(u),installation_id:c(u),retention_days:c(x({int:!0,positive:!0}))})),agent_guidance:c(v({prompt_completed:c(k),declined:c(k),declined_at:c(u),template_version:c(x({int:!0,positive:!0})),last_checked_files:c(p(u))})),item_types:c(v({definitions:p(Fd)})),schema:Wd,context:c(v({default_depth:c(I("brief","standard","deep")),activity_limit:c(x({int:!0,positive:!0})),stale_threshold_days:c(x({int:!0,positive:!0})),sections:c(v({hierarchy:c(k),activity:c(k),progress:c(k),recently_created:c(k),unparented:c(k),blockers:c(k),files:c(k),workload:c(k),staleness:c(k),tests:c(k)}))})),extensions:v({enabled:p(u),disabled:p(u),policy:Jd}),search:v({score_threshold:x(),hybrid_semantic_weight:c(x()),max_results:x({int:!0}),embedding_model:u,embedding_corpus_max_characters:c(x()),embedding_batch_size:x({int:!0}),embedding_timeout_ms:c(x({int:!0})),scanner_max_batch_retries:x({int:!0}),provider:c(u),default_mode:c(I("auto","keyword","semantic","hybrid")),corpus_fields:c(p(u)),mutation_refresh_policy:c(I("cache_only","semantic_configured","semantic_auto")),query_expansion:c(v({enabled:c(k),provider:c(u)})),rerank:c(v({enabled:c(k),model:c(u),top_k:c(x({int:!0,positive:!0}))})),bm25:c(v({k1:c(x()),b:c(x())}))}),providers:v({openai:v({base_url:u,api_key:u,model:u}),ollama:v({base_url:u,model:u})}),vector_store:v({adapter:c(u),collection_name:c(u),qdrant:v({url:u,api_key:u}),lancedb:v({path:u})})});function sn(e){let t=Xd(e);return t.ok?{success:!0,data:t.value}:{success:!1}}import{AsyncLocalStorage as ol}from"node:async_hooks";import{lstat as il,realpath as Mi}from"node:fs/promises";import Vi from"node:path";import Yd from"node:fs/promises";import Re from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="af606b47-d071-5724-b1e7-de4e1e5d7385")}catch{}})();var De="_workspace";function Lt(e){return Re.join(e,"history",`${De}.jsonl`)}function Zd(e,t){return{metadata:{id:De,title:"Workspace state",description:"Audited singleton workspace document state.",type:"Chore",status:"open",priority:2,tags:["workspace-history"],created_at:t,updated_at:t,documents:e},body:""}}function Ht(e,t=e.length){let r=bt();for(let n of e.slice(0,t))r=Et(r,n.patch).document;return wt(r)}function an(e){return"documents"in e.metadata&&typeof e.metadata.documents=="object"&&e.metadata.documents!==null&&!Array.isArray(e.metadata.documents)?e.metadata.documents:{}}function zt(e){throw new w(`Workspace history verification failed: ${e.join(", ")}`,E.CONFLICT,{code:"workspace_history_chain_invalid",reason:"workspace_history_chain_verification_failed",verification_errors:[...e],required:"Repair the _workspace history chain before reading, reconciling, restoring, or appending audited singleton state.",why:"Continuing against an unverifiable append-only stream could hide or compound workspace state corruption.",examples:["pm history _workspace --verify --json","pm validate --check-history-drift --fix-hints --json"],nextSteps:["Inspect the exact verification_errors and preserve the corrupt stream as evidence.","Use the history-drift remediation returned by validate before retrying the refused operation."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify --json"}})}function Ai(e,t){let r=Re.resolve(t),n=Re.relative(e,r).replaceAll("\\","/");if(n.length===0||n===".."||n.startsWith("../")||Re.isAbsolute(n))throw new TypeError("Workspace history document path must stay inside the tracker root");return{documentPath:n,absolutePath:r}}async function Uf(e){let t=await Ge(Lt(e),De),r=Je(t);r.ok||zt(r.errors);let n=an(t.length===0?je:Ht(t)),o=[],i=[],s=[],a=[];for(let d of Object.keys(n).sort()){let l;try{let _=Ai(e,Re.resolve(e,d));if(l=await be(_.absolutePath),l===null){s.push(d);continue}let f=JSON.parse(l);(A(f)===A(n[d])?o:i).push(d)}catch{a.push(d)}}return{ok:i.length===0&&s.length===0&&a.length===0,document_count:Object.keys(n).length,matching_documents:o,mismatched_documents:i,missing_documents:s,unreadable_documents:a}}async function xi(e){let t=Lt(e.pmRoot),r=await Ge(t,De),n=Je(r);n.ok||zt(n.errors);let o=e.idempotencyKey===void 0?void 0:r.find(f=>f.op===`${e.op}:${e.idempotencyKey}`);if(o)return{entry:o,historyPath:t};let i=$e(),s=r.length===0?je:Ht(r),a=an(s),d=a[e.documentPath];if(d!==void 0&&A(d)!==A(e.before))throw new w(`Workspace history state for "${e.documentPath}" changed outside the audited mutation path.`,E.CONFLICT,{code:"workspace_history_state_conflict",reason:"out_of_band_workspace_state",required:"Reconcile the singleton document with its matching _workspace history state before retrying the mutation.",why:"Accepting the write would make the append-only audit stream describe a state that was not actually observed.",examples:["pm history _workspace --verify","pm validate --check-history-drift --fix-hints"],nextSteps:["Review the version-control change that altered the singleton and preserve the intended document plus its matching workspace history.","Rerun the original mutation only after the on-disk singleton agrees with the latest audited workspace state."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify"}});let l=Zd({...a,[e.documentPath]:e.after},r.length===0?i:s.metadata.created_at),_=tn({nowIso:i,author:e.author,op:e.idempotencyKey===void 0?e.op:`${e.op}:${e.idempotencyKey}`,before:s,after:l,message:e.message});return await rn(t,_),{entry:_,historyPath:t}}async function Wf(e){let t=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await xi(e)}finally{await t()}}async function qf(e){let t=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let r=Lt(e.pmRoot),n=await Ge(r,De),o=Je(n);o.ok||zt(o.errors);let i=n.length===0?je:Ht(n),s=tn({nowIso:$e(),author:e.author,op:e.op,before:i,after:i,message:e.message,context:e.context});return await rn(r,s),{entry:s,historyPath:r}}finally{await t()}}async function Ci(e,t){if(t===e.raw)return!1;let r=t===null?null:JSON.parse(t),n=JSON.parse(e.raw);await Le(e.filePath,e.raw);try{(t!==null||e.recordCreation!==!1)&&await xi({pmRoot:e.pmRoot,documentPath:Re.relative(e.pmRoot,e.filePath).replaceAll("\\","/"),before:r,after:n,op:e.op,idempotencyKey:e.idempotencyKey,author:e.author,lockTtlSeconds:e.lockTtlSeconds,lockWaitMs:e.lockWaitMs,message:e.message})}catch(o){throw t===null?await Yd.rm(e.filePath,{force:!0}):await Le(e.filePath,t),o}return!0}async function Ni(e){let{documentPath:t}=Ai(e.pmRoot,e.filePath),r=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let n=await be(e.filePath);if(e.dryRun===!0||e.idempotencyKey!==void 0){let i=await Ge(Lt(e.pmRoot),De),s=Je(i);s.ok||zt(s.errors);let a=an(i.length===0?je:Ht(i))[t];if(a!==void 0&&A(a)!==A(n===null?null:JSON.parse(n)))throw new w(`Workspace history state for "${t}" changed outside the audited mutation path.`,E.CONFLICT,{code:"workspace_history_state_conflict"});if(e.idempotencyKey!==void 0&&i.some(d=>d.op===`${e.op}:${e.idempotencyKey}`))return{changed:!1,result:void 0,replayed:!0}}let o=await e.mutate(n);return JSON.parse(o.raw),e.dryRun===!0?{changed:n!==o.raw,result:o.result}:{changed:await Ci({...e,raw:o.raw},n),result:o.result}}finally{await r()}}async function Gf(e){let t=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await Ci(e,await be(e.filePath))}finally{await t()}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a0ca9902-540c-50fe-a4e2-9c234c4a01f3")}catch{}})();function Ft(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function cn(e,t,r,n=[]){if($(e,t)&&(n.length>0||Ft(r)))return r;if($(e,r)||$(t,r))return t;if((e===void 0||Ft(e))&&Ft(t)&&Ft(r)){let o=e??{},i=new Set([...Object.keys(o),...Object.keys(t),...Object.keys(r)]);return Object.fromEntries([...i].flatMap(s=>{let a=cn(Object.hasOwn(o,s)?o[s]:void 0,Object.hasOwn(t,s)?t[s]:void 0,Object.hasOwn(r,s)?r[s]:void 0,[...n,s]);return a===void 0?[]:[[s,a]]}))}throw new w(`Settings changed concurrently at ${n.join(".")||"<root>"}; read the latest settings and reapply the intended change.`,E.CONFLICT,{reason:"stale_settings_snapshot",required:"Read a fresh settings snapshot and reapply the intended change.",why:"Another writer changed the same setting after this snapshot was read.",examples:["pm config project export --json"],nextSteps:["Read the current settings, then retry the original config operation."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="de43e8e6-d7ef-53cc-94b0-ccdf1c4f94a3")}catch{}})();var Qd={Epic:2880,Feature:480,Story:480,Milestone:2880,Task:120,Issue:60,Bug:60,Chore:30,Decision:15,Plan:120},Ri=120;function dn(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function Pi(e){let t=new Map;for(let[r,n]of Object.entries(e))t.set(r.toLowerCase(),n);return t}var el=Pi(Qd),Di=new WeakMap;function tl(e){let t=Di.get(e);if(t)return t;let r=Pi(e);return Di.set(e,r),r}function Zf(e,t){let r=(e??"").trim().toLowerCase();if(r.length===0)return Ri;if(t){let o=tl(t).get(r);if(dn(o))return Math.floor(o)}let n=el.get(r);return dn(n)?Math.floor(n):Ri}function ln(e){let t={};if(e===null||typeof e!="object"||Array.isArray(e))return t;for(let[r,n]of Object.entries(e)){let o=r.trim();o.length===0||!dn(n)||(t[o]=Math.floor(n))}return t}import{stat as rl}from"node:fs/promises";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="78c79deb-5cf0-54fe-b98c-a0d5b3671ab2")}catch{}})();var $t=new Map;function ji(e){return[...new Set(e.map(t=>t.trim()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}async function nl(e){try{let t=await rl(e);return{path:e,mtime_ms:t.mtimeMs,size:t.size}}catch{return{path:e,mtime_ms:null,size:null}}}async function te(e){let t=ji(e),r=await Promise.all(t.map(n=>nl(n)));return r.sort((n,o)=>n.path.localeCompare(o.path)),r}function Xe(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1){let n=e[r],o=t[r];if(n.path!==o.path||n.mtime_ms!==o.mtime_ms||n.size!==o.size)return!1}return!0}function Li(e){return $t.get(e)}function Mt(e,t){let r=ji(t.tracked_paths),n=[...t.signatures].map(o=>({path:o.path,mtime_ms:o.mtime_ms,size:o.size})).sort((o,i)=>o.path.localeCompare(i.path));$t.set(e,{tracked_paths:r,signatures:n,value:t.value})}function ge(e){if(e){$t.delete(e);return}$t.clear()}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="f4308e20-251e-52d4-81a4-044e910e87fa")}catch{}})();var mn=new ol;async function vm(e,t,r=()=>!0){let n=new Set([Vi.resolve(e)]);try{n.add(await Mi(e))}catch{}return mn.run([...mn.getStore()??[],[n,r]],t)}function sl(e){let t=Vi.resolve(e);return mn.getStore()?.some(([r,n])=>r.has(t)&&n())??!1}var al="settings:write",Ui=Symbol("pm.settings.persist_source"),cl=128,dl=new Set(["off","advisory","strict"]);function Hi(e){return structuredClone(Pn[e])}function ll(e){return e==="minimal"||e==="default"||e==="strict"||e==="custom"?e:h.governance.preset}function zi(e,t){let r=typeof t.create_default_type=="string"?t.create_default_type.trim():void 0;return r&&r.length>0&&(e.create_default_type=r),(t.workflow_enforcement==="off"||t.workflow_enforcement==="warn"||t.workflow_enforcement==="strict")&&(e.workflow_enforcement=t.workflow_enforcement),t.require_close_reason===!1&&(e.require_close_reason=!1),e.duplicate_detection_mode=t.duplicate_detection_mode,e.duplicate_detection_threshold=t.duplicate_detection_threshold,e.duplicate_detection_limit=t.duplicate_detection_limit,e}function ul(e){return e.preset==="custom"?zi({preset:"custom",ownership_enforcement:e.ownership_enforcement,create_mode_default:e.create_mode_default,close_validation_default:e.close_validation_default,parent_reference:e.parent_reference,metadata_profile:e.metadata_profile,force_required_for_stale_lock:e.force_required_for_stale_lock},e):zi({preset:e.preset},e)}function _l(e){let t=typeof e.create_default_type=="string"?e.create_default_type.trim():void 0,r={};t&&t.length>0&&(r.create_default_type=t),(e.workflow_enforcement==="off"||e.workflow_enforcement==="warn"||e.workflow_enforcement==="strict")&&(r.workflow_enforcement=e.workflow_enforcement),typeof e.require_close_reason=="boolean"&&(r.require_close_reason=e.require_close_reason),dl.has(String(e.duplicate_detection_mode))&&(r.duplicate_detection_mode=e.duplicate_detection_mode);let n=e.duplicate_detection_threshold;[typeof n=="number",Number.isFinite(n),Number(n)>=0,Number(n)<=1].every(Boolean)&&(r.duplicate_detection_threshold=n);let o=e.duplicate_detection_limit;return[typeof o=="number",Number.isSafeInteger(o),Number(o)>=0,Number(o)<=20].every(Boolean)&&(r.duplicate_detection_limit=o),r}function Wi(e){let t=e.governance??{},r=ll(t.preset),n=_l(t);if(r==="custom"){let s=Hi("default"),a=n.require_close_reason??s.require_close_reason;return{preset:r,ownership_enforcement:t.ownership_enforcement??s.ownership_enforcement,create_mode_default:t.create_mode_default??s.create_mode_default,close_validation_default:t.close_validation_default??s.close_validation_default,parent_reference:t.parent_reference??s.parent_reference,metadata_profile:t.metadata_profile??s.metadata_profile,force_required_for_stale_lock:t.force_required_for_stale_lock??s.force_required_for_stale_lock,...n,require_close_reason:a,duplicate_detection_mode:n.duplicate_detection_mode??s.duplicate_detection_mode,duplicate_detection_threshold:n.duplicate_detection_threshold??s.duplicate_detection_threshold,duplicate_detection_limit:n.duplicate_detection_limit??s.duplicate_detection_limit}}let o=Hi(r),i=n.require_close_reason??o.require_close_reason;return{preset:r,...o,...n,require_close_reason:i}}function qi(){return structuredClone(h)}function Gi(e){return e==="cache_only"||e==="semantic_configured"||e==="semantic_auto"?e:h.search.mutation_refresh_policy}function Bi(e){return e==="auto"||e==="keyword"||e==="semantic"||e==="hybrid"?e:"auto"}function Ji(e){return typeof e=="boolean"?e:h.search.query_expansion.enabled}function Ki(e){return typeof e!="string"?h.search.query_expansion.provider:e.trim()}function Xi(e){return typeof e=="boolean"?e:h.search.rerank.enabled}function Yi(e){return typeof e!="string"?h.search.rerank.model:e.trim()}function Zi(e){return typeof e=="number"&&Number.isFinite(e)&&Number.isInteger(e)&&e>0?e:h.search.rerank.top_k}function Qi(e){if(typeof e!="string")return h.vector_store.collection_name;let t=e.trim().replaceAll(/[^a-zA-Z0-9_-]/g,"_").slice(0,cl);return t.length>0?t:h.vector_store.collection_name}function un(e){return{present:Array.isArray(e),values:Array.isArray(e)?structuredClone(e):[]}}function es(e,t){let r=e.schema,n=un(r?.statuses),o=un(r?.fields),i=un(r?.type_workflows);return{persisted_settings:structuredClone(e),source_settings:structuredClone(e),has_source_item_type_definitions:Array.isArray(e.item_types?.definitions),source_item_type_definitions:Pe(e.item_types?.definitions),has_source_schema_statuses:n.present,source_schema_statuses:n.values,has_source_schema_fields:o.present,source_schema_fields:o.values,has_source_schema_type_workflows:i.present,source_schema_type_workflows:i.values,runtime_item_type_definitions:Pe(t.item_types?.definitions),runtime_schema_statuses:structuredClone(t.schema.statuses),runtime_schema_fields:structuredClone(t.schema.fields),runtime_schema_type_workflows:structuredClone(t.schema.type_workflows??[])}}function yn(e,t){Object.defineProperty(e,Ui,{value:t,writable:!0,configurable:!0,enumerable:!1})}function ts(e){let t=e[Ui];if(!(!t||typeof t!="object"))return t}function Vt(e){let t=structuredClone(e.settings),r=ts(e.settings);return r&&yn(t,r),{settings:t,metadata:{has_explicit_item_format:e.metadata.has_explicit_item_format},warnings:[...e.warnings]}}function fl(e,t,r){let n=ze(t);return[r,Fe(e,n.files.types,He.types),Fe(e,n.files.statuses,He.statuses),Fe(e,n.files.fields,He.fields),Fe(e,n.files.workflows,He.workflows)]}async function ml(e,t,r){let n=await te(t);Mt(e,{tracked_paths:t,signatures:n,value:Vt(r)})}async function pl(e,t,r){try{await ml(e,t,r)}catch{ge(e)}}function Fi(e,t){return e.find(r=>r.path===t)}function hl(e,t,r){for(let n of r){let o=Fi(e,n),i=Fi(t,n);if(!o||!i||!Xe([o],[i]))return!1}return!0}async function _n(e,t,r,n,o){try{let i=await te(t);if(!hl(n,i,o)){ge(e);return}Mt(e,{tracked_paths:t,signatures:i,value:Vt(r)})}catch{ge(e)}}function yl(e,t){let r=ze(e.schema),n=Pe(e.item_types?.definitions);if(!t)return{item_type_definitions:n,schema_statuses:r.statuses,schema_fields:r.fields,schema_type_workflows:r.type_workflows};let o=r.type_workflows??[],i=$(n,t.runtime_item_type_definitions),s=$(r.statuses,t.runtime_schema_statuses),a=$(r.fields,t.runtime_schema_fields),d=$(o,t.runtime_schema_type_workflows);return{item_type_definitions:i?t.has_source_item_type_definitions?Pe(t.source_item_type_definitions):[]:n,schema_statuses:s?t.has_source_schema_statuses?structuredClone(t.source_schema_statuses):[]:r.statuses,schema_fields:a?t.has_source_schema_fields?structuredClone(t.source_schema_fields):[]:r.fields,schema_type_workflows:d?t.has_source_schema_type_workflows?structuredClone(t.source_schema_type_workflows):void 0:r.type_workflows}}function U(e){return{settings:qi(),metadata:{has_explicit_item_format:!1},warnings:e?[e]:[]}}function rs(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e.item_format;return t==="toon"||t==="json_markdown"}function pn(e){return[...new Set((e??[]).map(t=>t.trim()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function ns(e){let t=h.agent_guidance,r=e?.template_version;return{prompt_completed:e?.prompt_completed===!0,declined:e?.declined===!0,declined_at:typeof e?.declined_at=="string"?e.declined_at:t.declined_at,template_version:typeof r=="number"&&Number.isInteger(r)&&r>0?r:t.template_version,last_checked_files:pn(e?.last_checked_files??t.last_checked_files)}}function F(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function gl(e){return e==="off"||e==="warn"||e==="enforce"?e:h.extensions.policy.mode}function vl(e){return e==="off"||e==="warn"||e==="enforce"?e:h.extensions.policy.trust_mode}function os(e){return e==="none"||e==="restricted"||e==="strict"?e:h.extensions.policy.default_sandbox_profile}function bl(e){let t=e.name.trim().toLowerCase();if(t.length===0)return null;let r={name:t};e.disabled===!0&&(r.disabled=!0),e.require_trusted===!0&&(r.require_trusted=!0),e.require_provenance===!0&&(r.require_provenance=!0),e.sandbox_profile!==void 0&&(r.sandbox_profile=os(e.sandbox_profile));let n=F(e.allowed_capabilities),o=F(e.blocked_capabilities),i=F(e.allowed_surfaces),s=F(e.blocked_surfaces),a=F(e.allowed_commands),d=F(e.blocked_commands),l=F(e.allowed_actions),_=F(e.blocked_actions),f=F(e.allowed_services),b=F(e.blocked_services);return n.length>0&&(r.allowed_capabilities=n),o.length>0&&(r.blocked_capabilities=o),i.length>0&&(r.allowed_surfaces=i),s.length>0&&(r.blocked_surfaces=s),a.length>0&&(r.allowed_commands=a),d.length>0&&(r.blocked_commands=d),l.length>0&&(r.allowed_actions=l),_.length>0&&(r.blocked_actions=_),f.length>0&&(r.allowed_services=f),b.length>0&&(r.blocked_services=b),r}function wl(e){let t=new Map;for(let r of e??[]){let n=bl(r);n&&t.set(n.name,n)}return[...t.values()].sort((r,n)=>r.name.localeCompare(n.name))}function fn(e){return e==="block"||e==="warn"?e:void 0}function El(e){if(typeof e=="string")return fn(e);if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let t=fn(e.global),r=fn(e.project);return t===void 0&&r===void 0?void 0:{...t!==void 0?{global:t}:{},...r!==void 0?{project:r}:{}}}}function j(e,t){return F(e?.[t]??h.extensions.policy[t])}function is(e){let t=El(e?.pm_max_version_exceeded_mode);return{mode:gl(e?.mode),trust_mode:vl(e?.trust_mode),...t!==void 0?{pm_max_version_exceeded_mode:t}:{},require_provenance:e?.require_provenance===!0,trusted_extensions:j(e,"trusted_extensions"),default_sandbox_profile:os(e?.default_sandbox_profile),allowed_extensions:j(e,"allowed_extensions"),blocked_extensions:j(e,"blocked_extensions"),allowed_capabilities:j(e,"allowed_capabilities"),blocked_capabilities:j(e,"blocked_capabilities"),allowed_surfaces:j(e,"allowed_surfaces"),blocked_surfaces:j(e,"blocked_surfaces"),allowed_commands:j(e,"allowed_commands"),blocked_commands:j(e,"blocked_commands"),allowed_actions:j(e,"allowed_actions"),blocked_actions:j(e,"blocked_actions"),allowed_services:j(e,"allowed_services"),blocked_services:j(e,"blocked_services"),extension_overrides:wl(e?.extension_overrides??h.extensions.policy.extension_overrides)}}function ss(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase().replaceAll("-","_")))].filter(t=>t.length>0).sort((t,r)=>t.localeCompare(r)).filter(t=>["author","acceptance_criteria","estimated_minutes","close_reason","reviewer","risk","confidence","sprint","release"].includes(t))}function re(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function R(e,t){return e===void 0?t:e}function L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function hn(e){return Array.isArray(e)?e:[]}function kl(e,t,r){return{...t.validation,...e.validation,parent_reference:r.parent_reference,metadata_profile:r.metadata_profile,metadata_required_fields:ss(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:re(e.validation?.lifecycle_stale_blocker_reason_patterns??t.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:re(e.validation?.lifecycle_closure_like_blocked_reason_patterns??t.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:re(e.validation?.lifecycle_closure_like_resolution_patterns??t.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:re(e.validation?.lifecycle_closure_like_actual_result_patterns??t.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:ln(e.validation?.estimate_defaults_by_type)}}function Sl(e,t){return{enabled:e.telemetry?.enabled??t.telemetry.enabled,first_run_prompt_completed:e.telemetry?.first_run_prompt_completed??t.telemetry.first_run_prompt_completed,capture_level:e.telemetry?.capture_level??t.telemetry.capture_level,endpoint:e.telemetry?.endpoint??t.telemetry.endpoint,installation_id:e.telemetry?.installation_id??t.telemetry.installation_id,retention_days:e.telemetry?.retention_days??t.telemetry.retention_days}}function Il(e,t){return{...t.search,...e.search,default_mode:Bi(e.search?.default_mode),mutation_refresh_policy:Gi(e.search?.mutation_refresh_policy),query_expansion:{...t.search.query_expansion,...e.search?.query_expansion,enabled:Ji(e.search?.query_expansion?.enabled),provider:Ki(e.search?.query_expansion?.provider)},rerank:{...t.search.rerank,...e.search?.rerank,enabled:Xi(e.search?.rerank?.enabled),model:Yi(e.search?.rerank?.model),top_k:Zi(e.search?.rerank?.top_k)}}}function Ol(e,t){return{adapter:e.vector_store.adapter??t.vector_store.adapter,collection_name:Qi(e.vector_store.collection_name),qdrant:{...t.vector_store.qdrant,...e.vector_store.qdrant},lancedb:{...t.vector_store.lancedb,...e.vector_store.lancedb}}}function Tl(e,t){return e.item_format==="json_markdown"?"toon":e.item_format??t.item_format}function Al(e,t){return{default_depth:e.context?.default_depth??t.context.default_depth,activity_limit:e.context?.activity_limit??t.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??t.context.stale_threshold_days,sections:{...t.context.sections,...e.context?.sections}}}function xl(e,t){return{openai:{...t.providers.openai,...e.providers.openai},ollama:{...t.providers.ollama,...e.providers.ollama}}}function Pe(e){let t=(e??[]).map(n=>Fn(n)).filter(n=>n!==null),r=new Map;for(let n of t)r.set(n.name.toLowerCase(),n);return[...r.values()].sort((n,o)=>n.name.localeCompare(o.name))}function Ut(e){let t=qi(),r=Wi({governance:e.governance??{preset:"default"}});return{...t,...e,item_format:Tl(e,t),locks:{...t.locks,...e.locks},ids:{...t.ids,...e.ids},agent_identity:structuredClone(e.agent_identity??t.agent_identity),mutation_guard:{...t.mutation_guard,...e.mutation_guard},checkpoints:{...t.checkpoints,...e.checkpoints},output:{...t.output,...e.output},ux:{...t.ux,...e.ux},history:{...t.history,...e.history,compact_policy:{...t.history.compact_policy,...e.history?.compact_policy}},validation:kl(e,t,r),governance:r,workflow:{definition_of_done:[...e.workflow?.definition_of_done??t.workflow.definition_of_done]},testing:{record_results_to_items:e.testing?.record_results_to_items??t.testing.record_results_to_items,allow_untrusted_linked_tests:e.testing?.allow_untrusted_linked_tests??t.testing.allow_untrusted_linked_tests},telemetry:Sl(e,t),agent_guidance:ns(e.agent_guidance??t.agent_guidance),item_types:{definitions:Pe(e.item_types?.definitions)},schema:ze(e.schema??t.schema),context:Al(e,t),extensions:{enabled:[...e.extensions.enabled],disabled:[...e.extensions.disabled],policy:is(e.extensions.policy??t.extensions.policy)},search:Il(e,t),providers:xl(e,t),vector_store:Ol(e,t)}}function Cl(e){e.agent_identity=g(e.agent_identity,["probes_enabled","identity_vocabulary","harness_signals"]);let t=e.agent_identity;Object.hasOwn(t,"identity_vocabulary")&&(t.identity_vocabulary=g(L(t.identity_vocabulary),["version","aliases"])),e.agent_identity.harness_signals=hn(e.agent_identity.harness_signals).map(r=>g(L(r),["harness","environment_keys","model_environment_keys","session_environment_keys","provenance_environment_keys","provenance_resolvers","provenance_unavailable_dimensions","argv_markers","client_names"])),e.locks=g(e.locks,["ttl_seconds","wait_ms"]),e.ids=g(e.ids,["token_length"]),e.mutation_guard=g(e.mutation_guard,["require_attributed_author","secret_guard","stale_in_progress_hours"]),e.checkpoints=g(e.checkpoints,["retention_days"]),e.output=g(e.output,["default_format"]),e.ux=g(e.ux,["deprecation_hints"]),e.history=g(e.history,["missing_stream","compact_policy"]),e.validation=g(e.validation,["sprint_release_format","parent_reference","metadata_profile","metadata_required_fields","lifecycle_stale_blocker_reason_patterns","lifecycle_closure_like_blocked_reason_patterns","lifecycle_closure_like_resolution_patterns","lifecycle_closure_like_actual_result_patterns","estimate_defaults_by_type"]),e.governance=g(e.governance,["preset","ownership_enforcement","create_mode_default","close_validation_default","require_close_reason","parent_reference","metadata_profile","force_required_for_stale_lock","create_default_type","workflow_enforcement","duplicate_detection_mode","duplicate_detection_threshold","duplicate_detection_limit"]),e.workflow=g(e.workflow,["definition_of_done"]),e.testing=g(e.testing,["record_results_to_items","allow_untrusted_linked_tests"]),e.telemetry=g(e.telemetry,["enabled","first_run_prompt_completed","capture_level","endpoint","installation_id","retention_days"]),e.agent_guidance=g(e.agent_guidance,["prompt_completed","declined","declined_at","template_version","last_checked_files"]),e.item_types=g(e.item_types,["definitions"]),e.schema=g(e.schema,["version","files","statuses","fields","workflow","type_workflows","unknown_field_policy"]),e.schema.files=g(L(e.schema.files),["types","statuses","fields","workflows"]),e.schema.workflow=g(L(e.schema.workflow),["draft_status","open_status","in_progress_status","blocked_status","close_status","canceled_status"]),e.context=g(e.context,["default_depth","activity_limit","stale_threshold_days","sections"]),e.context.sections=g(L(e.context.sections),["hierarchy","activity","progress","blockers","files","workload","staleness","tests"]),e.extensions=g(e.extensions,["enabled","disabled","policy"]),e.extensions.policy=g(L(e.extensions.policy),["mode","trust_mode","pm_max_version_exceeded_mode","require_provenance","trusted_extensions","default_sandbox_profile","allowed_extensions","blocked_extensions","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services","extension_overrides"]),e.extensions.policy.extension_overrides=hn(e.extensions.policy.extension_overrides).map(r=>g(L(r),["name","disabled","require_trusted","require_provenance","sandbox_profile","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services"])),e.search=g(e.search,["score_threshold","hybrid_semantic_weight","max_results","embedding_model","embedding_corpus_max_characters","embedding_batch_size","embedding_timeout_ms","scanner_max_batch_retries","provider","default_mode","mutation_refresh_policy","query_expansion","rerank"]),e.search.query_expansion=g(L(e.search.query_expansion),["enabled","provider"]),e.search.rerank=g(L(e.search.rerank),["enabled","model","top_k"]),e.providers=g(e.providers,["openai","ollama"]),e.providers.openai=g(L(e.providers.openai),["base_url","api_key","model"]),e.providers.ollama=g(L(e.providers.ollama),["base_url","model"]),e.vector_store=g(e.vector_store,["adapter","collection_name","qdrant","lancedb"]),e.vector_store.qdrant=g(L(e.vector_store.qdrant),["url","api_key"]),e.vector_store.lancedb=g(L(e.vector_store.lancedb),["path"])}function Nl(e){return{...e,locks:R(e.locks,h.locks),ids:R(e.ids,h.ids),agent_identity:R(e.agent_identity,h.agent_identity),mutation_guard:R(e.mutation_guard,h.mutation_guard),checkpoints:R(e.checkpoints,h.checkpoints),output:R(e.output,h.output),ux:R(e.ux,h.ux),history:R(e.history,h.history),validation:R(e.validation,h.validation),workflow:R(e.workflow,h.workflow),testing:R(e.testing,h.testing),telemetry:R(e.telemetry,h.telemetry),agent_guidance:R(e.agent_guidance,h.agent_guidance),item_types:R(e.item_types,h.item_types),schema:R(e.schema,h.schema),context:R(e.context,h.context),extensions:R(e.extensions,h.extensions),search:R(e.search,h.search),providers:R(e.providers,h.providers),vector_store:R(e.vector_store,h.vector_store)}}function Rl(e,t){return{...e.validation,parent_reference:t.parent_reference,metadata_profile:t.metadata_profile,metadata_required_fields:ss(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:re(e.validation?.lifecycle_stale_blocker_reason_patterns??h.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:re(e.validation?.lifecycle_closure_like_blocked_reason_patterns??h.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:re(e.validation?.lifecycle_closure_like_resolution_patterns??h.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:re(e.validation?.lifecycle_closure_like_actual_result_patterns??h.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:ln(e.validation?.estimate_defaults_by_type)}}function Dl(e){return{...h.search,...e.search,default_mode:Bi(e.search?.default_mode),mutation_refresh_policy:Gi(e.search?.mutation_refresh_policy),query_expansion:{...h.search.query_expansion,...e.search?.query_expansion,enabled:Ji(e.search?.query_expansion?.enabled),provider:Ki(e.search?.query_expansion?.provider)},rerank:{...h.search.rerank,...e.search?.rerank,enabled:Xi(e.search?.rerank?.enabled),model:Yi(e.search?.rerank?.model),top_k:Zi(e.search?.rerank?.top_k)}}}function Pl(e){return{default_depth:e.context?.default_depth??h.context.default_depth,activity_limit:e.context?.activity_limit??h.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??h.context.stale_threshold_days,sections:{...h.context.sections,...e.context?.sections}}}function jl(e){return{...e.vector_store,adapter:e.vector_store?.adapter??h.vector_store.adapter,collection_name:Qi(e.vector_store?.collection_name),qdrant:{...e.vector_store?.qdrant},lancedb:{...e.vector_store?.lancedb}}}function Ll(e,t,r,n){return{...e,item_format:"toon",validation:Rl(e,t),governance:t,agent_guidance:ns(e.agent_guidance),item_types:{definitions:n.item_type_definitions},schema:{...r,statuses:n.schema_statuses,fields:n.schema_fields,type_workflows:n.schema_type_workflows},search:Dl(e),context:Pl(e),extensions:{enabled:pn(e.extensions?.enabled),disabled:pn(e.extensions?.disabled),policy:is(e.extensions?.policy)},vector_store:jl(e)}}function as(e,t){for(let r of Object.keys(t)){let n=Reflect.get(t,r),o=e[r];typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof o=="object"&&o!==null&&!Array.isArray(o)?as(o,n):e[r]=structuredClone(n)}}function cs(e,t,r){let n=new Set([...Object.keys(t),...Object.keys(r)]);for(let o of n){let i=t[o],s=r[o];if(!$(i,s)){if(s===void 0){delete e[o];continue}if(typeof i=="object"&&i!==null&&!Array.isArray(i)&&typeof s=="object"&&s!==null&&!Array.isArray(s)){let a=e[o],d=typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{};cs(d,i,s),Object.keys(d).length>0?e[o]=d:delete e[o];continue}e[o]=structuredClone(s)}}}var gn=["version","id_prefix","ids","author_default","agent_identity","mutation_guard","item_format","locks","checkpoints","output","ux","history","validation","governance","workflow","testing","telemetry","agent_guidance","item_types","schema","context","extensions","search","providers","vector_store"];function $i(e,t){let r=Nl(e),n=Wi(r),o=ze(r.schema),i=yl(r,t),s=Ll(r,n,o,i),a=g({...s,governance:ul(n)},gn);return Cl(a),a}function Hl(e,t={}){let r=t.source===void 0?t.persist_source:es(t.source.validated,Ut(t.source.validated)),n=$i(e,r);if(r){let o=Ut(r.source_settings);o.item_types={definitions:structuredClone(r.runtime_item_type_definitions)},o.schema={...o.schema,statuses:structuredClone(r.runtime_schema_statuses),fields:structuredClone(r.runtime_schema_fields),type_workflows:structuredClone(r.runtime_schema_type_workflows)};let i=$i(o,r);t.source!==void 0&&as(i,t.source.validated);let s=structuredClone(t.source===void 0?r.source_settings:t.source.raw);return cs(s,i,n),`${JSON.stringify(g(s,gn),null,2)}
74
+ `,{encoding:"utf8",flag:"wx"})}catch(n){throw n.code!=="EEXIST"?n:new w("This item identity is reserved by an existing history stream.",E.CONFLICT,{code:"item_identity_reserved",required:"Choose a new item ID or restore the original item from its history.",nextSteps:["Run pm history <id> --full, then pm restore <id> <version> to recover the original item."]})}}async function rn(e,t){let r=await Bn("history_append",{history_path:e,entry:t});if(r.handled&&await Ld(e,t,r.result))return;let n=t.ts.trim().length>0?t:{...t,ts:Ti(t)},o=en({...n,hash_algorithm:se(n.hash_algorithm),event_class:xe(n)});await mi(e,o,async()=>{await Qr(e,Zr(o,o))}),await Rt(e)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="405e7bd1-25c0-5e04-b313-d9871efce4f5")}catch{}})();var P={ok:!1},u=e=>typeof e=="string"?{ok:!0,value:e}:P,k=e=>typeof e=="boolean"?{ok:!0,value:e}:P;function x(e={}){return t=>typeof t!="number"||!Number.isFinite(t)||e.int&&(!Number.isInteger(t)||!Number.isSafeInteger(t))||e.positive&&t<=0||typeof e.min=="number"&&t<e.min||typeof e.max=="number"&&t>e.max?P:{ok:!0,value:t}}function I(...e){return t=>typeof t=="string"&&e.includes(t)?{ok:!0,value:t}:P}function p(e,t){return r=>{if(!Array.isArray(r)||t!==void 0&&r.length>t)return P;let n=[];for(let o of r){let i=e(o);if(!i.ok)return P;n.push(i.value)}return{ok:!0,value:n}}}function on(e,t){return r=>typeof r=="string"&&r.length>0&&r.length<=e&&r===r.trim()&&(t===void 0||t.test(r))?{ok:!0,value:r}:P}function c(e){return t=>t===void 0?{ok:!0,value:void 0}:e(t)}function jt(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return P;let r={};for(let[n,o]of Object.entries(t)){let i=e(o);if(!i.ok)return P;r[n]=i.value}return{ok:!0,value:r}}}function v(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return P;let r=t,n={};for(let[o,i]of Object.entries(e)){let s=i(r[o]);if(!s.ok)return P;s.value!==void 0&&(n[o]=s.value)}return{ok:!0,value:n}}}var Hd=v({key:u,values:p(u),required:c(k),aliases:c(p(u)),description:c(u)}),zd=v({command:I("create","update"),option:u,required:c(k),visible:c(k),enabled:c(k)}),Fd=v({name:u,description:c(u),default_status:c(u),execution_role:c(I("agent","human","gate")),folder:c(u),aliases:c(p(u)),required_create_fields:c(p(u)),required_create_repeatables:c(p(u)),options:c(p(Hd)),command_option_policies:c(p(zd))}),$d=v({id:u,aliases:c(p(u)),roles:c(p(I(...An))),description:c(u),order:c(x())}),Md=v({key:u,metadata_key:c(u),front_matter_key:c(u),cli_flag:c(u),cli_aliases:c(p(u)),description:c(u),type:c(I(...xn)),commands:c(p(I(...Cn))),repeatable:c(k),required:c(k),required_on_create:c(k),required_types:c(p(u)),allow_unset:c(k)}),Vd=e=>{if(!Array.isArray(e)||e.length!==2)return P;let[t,r]=e;return typeof t!="string"||typeof r!="string"?P:{ok:!0,value:[t,r]}},Ud=v({type:u,allowed_transitions:p(Vd)}),Wd=c(v({version:c(x({int:!0})),files:c(v({types:c(u),statuses:c(u),fields:c(u),workflows:c(u)})),statuses:c(p($d)),fields:c(p(Md)),workflow:c(v({draft_status:c(u),open_status:c(u),in_progress_status:c(u),blocked_status:c(u),close_status:c(u),canceled_status:c(u)})),type_workflows:c(p(Ud)),unknown_field_policy:c(I(...Nn))})),qd=c(v({preset:c(I(...Rn)),ownership_enforcement:c(I("none","warn","strict")),create_mode_default:c(I("progressive","strict")),close_validation_default:c(I("off","warn","strict")),require_close_reason:c(k),parent_reference:c(I("warn","strict_error")),metadata_profile:c(I("core","strict","custom")),force_required_for_stale_lock:c(k),create_default_type:c(u),workflow_enforcement:c(I("off","warn","strict")),duplicate_detection_mode:c(I("off","advisory","strict")),duplicate_detection_threshold:c(x({min:0,max:1})),duplicate_detection_limit:c(x({int:!0,min:0,max:20}))})),Gd=v({name:u,disabled:c(k),require_trusted:c(k),require_provenance:c(k),sandbox_profile:c(I("none","restricted","strict")),allowed_capabilities:c(p(u)),blocked_capabilities:c(p(u)),allowed_surfaces:c(p(u)),blocked_surfaces:c(p(u)),allowed_commands:c(p(u)),blocked_commands:c(p(u)),allowed_actions:c(p(u)),blocked_actions:c(p(u)),allowed_services:c(p(u)),blocked_services:c(p(u))}),nn=I("block","warn"),Bd=e=>typeof e=="string"?nn(e):v({global:c(nn),project:c(nn)})(e),Jd=c(v({mode:c(I("off","warn","enforce")),trust_mode:c(I("off","warn","enforce")),pm_max_version_exceeded_mode:c(Bd),require_provenance:c(k),trusted_extensions:c(p(u)),default_sandbox_profile:c(I("none","restricted","strict")),allowed_extensions:c(p(u)),blocked_extensions:c(p(u)),allowed_capabilities:c(p(u)),blocked_capabilities:c(p(u)),allowed_surfaces:c(p(u)),blocked_surfaces:c(p(u)),allowed_commands:c(p(u)),blocked_commands:c(p(u)),allowed_actions:c(p(u)),blocked_actions:c(p(u)),allowed_services:c(p(u)),blocked_services:c(p(u)),extension_overrides:c(p(Gd))})),ye=on(128),Kd=v({harness:on(128,/^[a-z0-9]+(?:-[a-z0-9]+)*$/u),environment_keys:c(p(ye,64)),model_environment_keys:c(p(ye,64)),session_environment_keys:c(p(ye,64)),provenance_environment_keys:c(jt(p(ye,64))),provenance_resolvers:c(jt(I("ai_agent_version","claude_session_file"))),provenance_unavailable_dimensions:c(p(ye,64)),argv_markers:c(p(ye,64)),client_names:c(p(ye,64))}),Xd=v({version:x({int:!0}),id_prefix:u,ids:c(v({token_length:c(x({int:!0,min:4,max:12}))})),author_default:u,agent_identity:c(v({probes_enabled:c(k),identity_vocabulary:c(v({version:x({int:!0,positive:!0}),aliases:jt(on(128,/^[a-z0-9]+(?:-[a-z0-9]+)*$/u))})),harness_signals:p(Kd)})),mutation_guard:c(v({require_attributed_author:c(k),secret_guard:c(I("off","advise","block")),stale_in_progress_hours:c(x({int:!0,positive:!0}))})),item_format:c(I("toon","json_markdown")),locks:v({ttl_seconds:x({int:!0}),wait_ms:c(x({int:!0,min:0}))}),checkpoints:c(v({retention_days:c(x({int:!0,positive:!0}))})),output:v({default_format:I("toon","json")}),ux:c(v({deprecation_hints:c(k)})),history:c(v({missing_stream:I("auto_create","strict_error"),compact_policy:c(v({enabled:c(k),max_entries:c(x({int:!0,positive:!0})),trigger:c(I("health_warn","auto"))}))})),validation:c(v({sprint_release_format:I("warn","strict_error"),parent_reference:c(I("warn","strict_error")),metadata_profile:c(I("core","strict","custom")),metadata_required_fields:c(p(u)),lifecycle_stale_blocker_reason_patterns:c(p(u)),lifecycle_closure_like_blocked_reason_patterns:c(p(u)),lifecycle_closure_like_resolution_patterns:c(p(u)),lifecycle_closure_like_actual_result_patterns:c(p(u)),estimate_defaults_by_type:c(jt(x({int:!0,positive:!0})))})),governance:qd,workflow:c(v({definition_of_done:p(u)})),testing:c(v({record_results_to_items:k,allow_untrusted_linked_tests:c(k)})),telemetry:c(v({enabled:k,first_run_prompt_completed:c(k),capture_level:c(I("minimal","redacted","max")),endpoint:c(u),installation_id:c(u),retention_days:c(x({int:!0,positive:!0}))})),agent_guidance:c(v({prompt_completed:c(k),declined:c(k),declined_at:c(u),template_version:c(x({int:!0,positive:!0})),last_checked_files:c(p(u))})),item_types:c(v({definitions:p(Fd)})),schema:Wd,context:c(v({default_depth:c(I("brief","standard","deep")),activity_limit:c(x({int:!0,positive:!0})),stale_threshold_days:c(x({int:!0,positive:!0})),next_ranking_policy:c(I("priority_floor","weighted")),sections:c(v({hierarchy:c(k),activity:c(k),progress:c(k),recently_created:c(k),unparented:c(k),blockers:c(k),files:c(k),workload:c(k),staleness:c(k),tests:c(k)}))})),extensions:v({enabled:p(u),disabled:p(u),policy:Jd}),search:v({score_threshold:x(),hybrid_semantic_weight:c(x()),max_results:x({int:!0}),embedding_model:u,embedding_corpus_max_characters:c(x()),embedding_batch_size:x({int:!0}),embedding_timeout_ms:c(x({int:!0})),scanner_max_batch_retries:x({int:!0}),provider:c(u),default_mode:c(I("auto","keyword","semantic","hybrid")),corpus_fields:c(p(u)),mutation_refresh_policy:c(I("cache_only","semantic_configured","semantic_auto")),query_expansion:c(v({enabled:c(k),provider:c(u)})),rerank:c(v({enabled:c(k),model:c(u),top_k:c(x({int:!0,positive:!0}))})),bm25:c(v({k1:c(x()),b:c(x())}))}),providers:v({openai:v({base_url:u,api_key:u,model:u}),ollama:v({base_url:u,model:u})}),vector_store:v({adapter:c(u),collection_name:c(u),qdrant:v({url:u,api_key:u}),lancedb:v({path:u})})});function sn(e){let t=Xd(e);return t.ok?{success:!0,data:t.value}:{success:!1}}import{AsyncLocalStorage as ol}from"node:async_hooks";import{lstat as il,realpath as Mi}from"node:fs/promises";import Vi from"node:path";import Yd from"node:fs/promises";import Re from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="af606b47-d071-5724-b1e7-de4e1e5d7385")}catch{}})();var De="_workspace";function Lt(e){return Re.join(e,"history",`${De}.jsonl`)}function Zd(e,t){return{metadata:{id:De,title:"Workspace state",description:"Audited singleton workspace document state.",type:"Chore",status:"open",priority:2,tags:["workspace-history"],created_at:t,updated_at:t,documents:e},body:""}}function Ht(e,t=e.length){let r=bt();for(let n of e.slice(0,t))r=Et(r,n.patch).document;return wt(r)}function an(e){return"documents"in e.metadata&&typeof e.metadata.documents=="object"&&e.metadata.documents!==null&&!Array.isArray(e.metadata.documents)?e.metadata.documents:{}}function zt(e){throw new w(`Workspace history verification failed: ${e.join(", ")}`,E.CONFLICT,{code:"workspace_history_chain_invalid",reason:"workspace_history_chain_verification_failed",verification_errors:[...e],required:"Repair the _workspace history chain before reading, reconciling, restoring, or appending audited singleton state.",why:"Continuing against an unverifiable append-only stream could hide or compound workspace state corruption.",examples:["pm history _workspace --verify --json","pm validate --check-history-drift --fix-hints --json"],nextSteps:["Inspect the exact verification_errors and preserve the corrupt stream as evidence.","Use the history-drift remediation returned by validate before retrying the refused operation."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify --json"}})}function Ai(e,t){let r=Re.resolve(t),n=Re.relative(e,r).replaceAll("\\","/");if(n.length===0||n===".."||n.startsWith("../")||Re.isAbsolute(n))throw new TypeError("Workspace history document path must stay inside the tracker root");return{documentPath:n,absolutePath:r}}async function Uf(e){let t=await Ge(Lt(e),De),r=Je(t);r.ok||zt(r.errors);let n=an(t.length===0?je:Ht(t)),o=[],i=[],s=[],a=[];for(let d of Object.keys(n).sort()){let l;try{let _=Ai(e,Re.resolve(e,d));if(l=await be(_.absolutePath),l===null){s.push(d);continue}let f=JSON.parse(l);(A(f)===A(n[d])?o:i).push(d)}catch{a.push(d)}}return{ok:i.length===0&&s.length===0&&a.length===0,document_count:Object.keys(n).length,matching_documents:o,mismatched_documents:i,missing_documents:s,unreadable_documents:a}}async function xi(e){let t=Lt(e.pmRoot),r=await Ge(t,De),n=Je(r);n.ok||zt(n.errors);let o=e.idempotencyKey===void 0?void 0:r.find(f=>f.op===`${e.op}:${e.idempotencyKey}`);if(o)return{entry:o,historyPath:t};let i=$e(),s=r.length===0?je:Ht(r),a=an(s),d=a[e.documentPath];if(d!==void 0&&A(d)!==A(e.before))throw new w(`Workspace history state for "${e.documentPath}" changed outside the audited mutation path.`,E.CONFLICT,{code:"workspace_history_state_conflict",reason:"out_of_band_workspace_state",required:"Reconcile the singleton document with its matching _workspace history state before retrying the mutation.",why:"Accepting the write would make the append-only audit stream describe a state that was not actually observed.",examples:["pm history _workspace --verify","pm validate --check-history-drift --fix-hints"],nextSteps:["Review the version-control change that altered the singleton and preserve the intended document plus its matching workspace history.","Rerun the original mutation only after the on-disk singleton agrees with the latest audited workspace state."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify"}});let l=Zd({...a,[e.documentPath]:e.after},r.length===0?i:s.metadata.created_at),_=tn({nowIso:i,author:e.author,op:e.idempotencyKey===void 0?e.op:`${e.op}:${e.idempotencyKey}`,before:s,after:l,message:e.message});return await rn(t,_),{entry:_,historyPath:t}}async function Wf(e){let t=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await xi(e)}finally{await t()}}async function qf(e){let t=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let r=Lt(e.pmRoot),n=await Ge(r,De),o=Je(n);o.ok||zt(o.errors);let i=n.length===0?je:Ht(n),s=tn({nowIso:$e(),author:e.author,op:e.op,before:i,after:i,message:e.message,context:e.context});return await rn(r,s),{entry:s,historyPath:r}}finally{await t()}}async function Ci(e,t){if(t===e.raw)return!1;let r=t===null?null:JSON.parse(t),n=JSON.parse(e.raw);await Le(e.filePath,e.raw);try{(t!==null||e.recordCreation!==!1)&&await xi({pmRoot:e.pmRoot,documentPath:Re.relative(e.pmRoot,e.filePath).replaceAll("\\","/"),before:r,after:n,op:e.op,idempotencyKey:e.idempotencyKey,author:e.author,lockTtlSeconds:e.lockTtlSeconds,lockWaitMs:e.lockWaitMs,message:e.message})}catch(o){throw t===null?await Yd.rm(e.filePath,{force:!0}):await Le(e.filePath,t),o}return!0}async function Ni(e){let{documentPath:t}=Ai(e.pmRoot,e.filePath),r=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let n=await be(e.filePath);if(e.dryRun===!0||e.idempotencyKey!==void 0){let i=await Ge(Lt(e.pmRoot),De),s=Je(i);s.ok||zt(s.errors);let a=an(i.length===0?je:Ht(i))[t];if(a!==void 0&&A(a)!==A(n===null?null:JSON.parse(n)))throw new w(`Workspace history state for "${t}" changed outside the audited mutation path.`,E.CONFLICT,{code:"workspace_history_state_conflict"});if(e.idempotencyKey!==void 0&&i.some(d=>d.op===`${e.op}:${e.idempotencyKey}`))return{changed:!1,result:void 0,replayed:!0}}let o=await e.mutate(n);return JSON.parse(o.raw),e.dryRun===!0?{changed:n!==o.raw,result:o.result}:{changed:await Ci({...e,raw:o.raw},n),result:o.result}}finally{await r()}}async function Gf(e){let t=await M(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await Ci(e,await be(e.filePath))}finally{await t()}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a0ca9902-540c-50fe-a4e2-9c234c4a01f3")}catch{}})();function Ft(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function cn(e,t,r,n=[]){if($(e,t)&&(n.length>0||Ft(r)))return r;if($(e,r)||$(t,r))return t;if((e===void 0||Ft(e))&&Ft(t)&&Ft(r)){let o=e??{},i=new Set([...Object.keys(o),...Object.keys(t),...Object.keys(r)]);return Object.fromEntries([...i].flatMap(s=>{let a=cn(Object.hasOwn(o,s)?o[s]:void 0,Object.hasOwn(t,s)?t[s]:void 0,Object.hasOwn(r,s)?r[s]:void 0,[...n,s]);return a===void 0?[]:[[s,a]]}))}throw new w(`Settings changed concurrently at ${n.join(".")||"<root>"}; read the latest settings and reapply the intended change.`,E.CONFLICT,{reason:"stale_settings_snapshot",required:"Read a fresh settings snapshot and reapply the intended change.",why:"Another writer changed the same setting after this snapshot was read.",examples:["pm config project export --json"],nextSteps:["Read the current settings, then retry the original config operation."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="de43e8e6-d7ef-53cc-94b0-ccdf1c4f94a3")}catch{}})();var Qd={Epic:2880,Feature:480,Story:480,Milestone:2880,Task:120,Issue:60,Bug:60,Chore:30,Decision:15,Plan:120},Ri=120;function dn(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function Pi(e){let t=new Map;for(let[r,n]of Object.entries(e))t.set(r.toLowerCase(),n);return t}var el=Pi(Qd),Di=new WeakMap;function tl(e){let t=Di.get(e);if(t)return t;let r=Pi(e);return Di.set(e,r),r}function Zf(e,t){let r=(e??"").trim().toLowerCase();if(r.length===0)return Ri;if(t){let o=tl(t).get(r);if(dn(o))return Math.floor(o)}let n=el.get(r);return dn(n)?Math.floor(n):Ri}function ln(e){let t={};if(e===null||typeof e!="object"||Array.isArray(e))return t;for(let[r,n]of Object.entries(e)){let o=r.trim();o.length===0||!dn(n)||(t[o]=Math.floor(n))}return t}import{stat as rl}from"node:fs/promises";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="78c79deb-5cf0-54fe-b98c-a0d5b3671ab2")}catch{}})();var $t=new Map;function ji(e){return[...new Set(e.map(t=>t.trim()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}async function nl(e){try{let t=await rl(e);return{path:e,mtime_ms:t.mtimeMs,size:t.size}}catch{return{path:e,mtime_ms:null,size:null}}}async function te(e){let t=ji(e),r=await Promise.all(t.map(n=>nl(n)));return r.sort((n,o)=>n.path.localeCompare(o.path)),r}function Xe(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r+=1){let n=e[r],o=t[r];if(n.path!==o.path||n.mtime_ms!==o.mtime_ms||n.size!==o.size)return!1}return!0}function Li(e){return $t.get(e)}function Mt(e,t){let r=ji(t.tracked_paths),n=[...t.signatures].map(o=>({path:o.path,mtime_ms:o.mtime_ms,size:o.size})).sort((o,i)=>o.path.localeCompare(i.path));$t.set(e,{tracked_paths:r,signatures:n,value:t.value})}function ge(e){if(e){$t.delete(e);return}$t.clear()}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8d586108-d5b3-5c84-861a-cf532a979cdf")}catch{}})();var mn=new ol;async function vm(e,t,r=()=>!0){let n=new Set([Vi.resolve(e)]);try{n.add(await Mi(e))}catch{}return mn.run([...mn.getStore()??[],[n,r]],t)}function sl(e){let t=Vi.resolve(e);return mn.getStore()?.some(([r,n])=>r.has(t)&&n())??!1}var al="settings:write",Ui=Symbol("pm.settings.persist_source"),cl=128,dl=new Set(["off","advisory","strict"]);function Hi(e){return structuredClone(Pn[e])}function ll(e){return e==="minimal"||e==="default"||e==="strict"||e==="custom"?e:h.governance.preset}function zi(e,t){let r=typeof t.create_default_type=="string"?t.create_default_type.trim():void 0;return r&&r.length>0&&(e.create_default_type=r),(t.workflow_enforcement==="off"||t.workflow_enforcement==="warn"||t.workflow_enforcement==="strict")&&(e.workflow_enforcement=t.workflow_enforcement),t.require_close_reason===!1&&(e.require_close_reason=!1),e.duplicate_detection_mode=t.duplicate_detection_mode,e.duplicate_detection_threshold=t.duplicate_detection_threshold,e.duplicate_detection_limit=t.duplicate_detection_limit,e}function ul(e){return e.preset==="custom"?zi({preset:"custom",ownership_enforcement:e.ownership_enforcement,create_mode_default:e.create_mode_default,close_validation_default:e.close_validation_default,parent_reference:e.parent_reference,metadata_profile:e.metadata_profile,force_required_for_stale_lock:e.force_required_for_stale_lock},e):zi({preset:e.preset},e)}function _l(e){let t=typeof e.create_default_type=="string"?e.create_default_type.trim():void 0,r={};t&&t.length>0&&(r.create_default_type=t),(e.workflow_enforcement==="off"||e.workflow_enforcement==="warn"||e.workflow_enforcement==="strict")&&(r.workflow_enforcement=e.workflow_enforcement),typeof e.require_close_reason=="boolean"&&(r.require_close_reason=e.require_close_reason),dl.has(String(e.duplicate_detection_mode))&&(r.duplicate_detection_mode=e.duplicate_detection_mode);let n=e.duplicate_detection_threshold;[typeof n=="number",Number.isFinite(n),Number(n)>=0,Number(n)<=1].every(Boolean)&&(r.duplicate_detection_threshold=n);let o=e.duplicate_detection_limit;return[typeof o=="number",Number.isSafeInteger(o),Number(o)>=0,Number(o)<=20].every(Boolean)&&(r.duplicate_detection_limit=o),r}function Wi(e){let t=e.governance??{},r=ll(t.preset),n=_l(t);if(r==="custom"){let s=Hi("default"),a=n.require_close_reason??s.require_close_reason;return{preset:r,ownership_enforcement:t.ownership_enforcement??s.ownership_enforcement,create_mode_default:t.create_mode_default??s.create_mode_default,close_validation_default:t.close_validation_default??s.close_validation_default,parent_reference:t.parent_reference??s.parent_reference,metadata_profile:t.metadata_profile??s.metadata_profile,force_required_for_stale_lock:t.force_required_for_stale_lock??s.force_required_for_stale_lock,...n,require_close_reason:a,duplicate_detection_mode:n.duplicate_detection_mode??s.duplicate_detection_mode,duplicate_detection_threshold:n.duplicate_detection_threshold??s.duplicate_detection_threshold,duplicate_detection_limit:n.duplicate_detection_limit??s.duplicate_detection_limit}}let o=Hi(r),i=n.require_close_reason??o.require_close_reason;return{preset:r,...o,...n,require_close_reason:i}}function qi(){return structuredClone(h)}function Gi(e){return e==="cache_only"||e==="semantic_configured"||e==="semantic_auto"?e:h.search.mutation_refresh_policy}function Bi(e){return e==="auto"||e==="keyword"||e==="semantic"||e==="hybrid"?e:"auto"}function Ji(e){return typeof e=="boolean"?e:h.search.query_expansion.enabled}function Ki(e){return typeof e!="string"?h.search.query_expansion.provider:e.trim()}function Xi(e){return typeof e=="boolean"?e:h.search.rerank.enabled}function Yi(e){return typeof e!="string"?h.search.rerank.model:e.trim()}function Zi(e){return typeof e=="number"&&Number.isFinite(e)&&Number.isInteger(e)&&e>0?e:h.search.rerank.top_k}function Qi(e){if(typeof e!="string")return h.vector_store.collection_name;let t=e.trim().replaceAll(/[^a-zA-Z0-9_-]/g,"_").slice(0,cl);return t.length>0?t:h.vector_store.collection_name}function un(e){return{present:Array.isArray(e),values:Array.isArray(e)?structuredClone(e):[]}}function es(e,t){let r=e.schema,n=un(r?.statuses),o=un(r?.fields),i=un(r?.type_workflows);return{persisted_settings:structuredClone(e),source_settings:structuredClone(e),has_source_item_type_definitions:Array.isArray(e.item_types?.definitions),source_item_type_definitions:Pe(e.item_types?.definitions),has_source_schema_statuses:n.present,source_schema_statuses:n.values,has_source_schema_fields:o.present,source_schema_fields:o.values,has_source_schema_type_workflows:i.present,source_schema_type_workflows:i.values,runtime_item_type_definitions:Pe(t.item_types?.definitions),runtime_schema_statuses:structuredClone(t.schema.statuses),runtime_schema_fields:structuredClone(t.schema.fields),runtime_schema_type_workflows:structuredClone(t.schema.type_workflows??[])}}function yn(e,t){Object.defineProperty(e,Ui,{value:t,writable:!0,configurable:!0,enumerable:!1})}function ts(e){let t=e[Ui];if(!(!t||typeof t!="object"))return t}function Vt(e){let t=structuredClone(e.settings),r=ts(e.settings);return r&&yn(t,r),{settings:t,metadata:{has_explicit_item_format:e.metadata.has_explicit_item_format},warnings:[...e.warnings]}}function fl(e,t,r){let n=ze(t);return[r,Fe(e,n.files.types,He.types),Fe(e,n.files.statuses,He.statuses),Fe(e,n.files.fields,He.fields),Fe(e,n.files.workflows,He.workflows)]}async function ml(e,t,r){let n=await te(t);Mt(e,{tracked_paths:t,signatures:n,value:Vt(r)})}async function pl(e,t,r){try{await ml(e,t,r)}catch{ge(e)}}function Fi(e,t){return e.find(r=>r.path===t)}function hl(e,t,r){for(let n of r){let o=Fi(e,n),i=Fi(t,n);if(!o||!i||!Xe([o],[i]))return!1}return!0}async function _n(e,t,r,n,o){try{let i=await te(t);if(!hl(n,i,o)){ge(e);return}Mt(e,{tracked_paths:t,signatures:i,value:Vt(r)})}catch{ge(e)}}function yl(e,t){let r=ze(e.schema),n=Pe(e.item_types?.definitions);if(!t)return{item_type_definitions:n,schema_statuses:r.statuses,schema_fields:r.fields,schema_type_workflows:r.type_workflows};let o=r.type_workflows??[],i=$(n,t.runtime_item_type_definitions),s=$(r.statuses,t.runtime_schema_statuses),a=$(r.fields,t.runtime_schema_fields),d=$(o,t.runtime_schema_type_workflows);return{item_type_definitions:i?t.has_source_item_type_definitions?Pe(t.source_item_type_definitions):[]:n,schema_statuses:s?t.has_source_schema_statuses?structuredClone(t.source_schema_statuses):[]:r.statuses,schema_fields:a?t.has_source_schema_fields?structuredClone(t.source_schema_fields):[]:r.fields,schema_type_workflows:d?t.has_source_schema_type_workflows?structuredClone(t.source_schema_type_workflows):void 0:r.type_workflows}}function U(e){return{settings:qi(),metadata:{has_explicit_item_format:!1},warnings:e?[e]:[]}}function rs(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e.item_format;return t==="toon"||t==="json_markdown"}function pn(e){return[...new Set((e??[]).map(t=>t.trim()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function ns(e){let t=h.agent_guidance,r=e?.template_version;return{prompt_completed:e?.prompt_completed===!0,declined:e?.declined===!0,declined_at:typeof e?.declined_at=="string"?e.declined_at:t.declined_at,template_version:typeof r=="number"&&Number.isInteger(r)&&r>0?r:t.template_version,last_checked_files:pn(e?.last_checked_files??t.last_checked_files)}}function F(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function gl(e){return e==="off"||e==="warn"||e==="enforce"?e:h.extensions.policy.mode}function vl(e){return e==="off"||e==="warn"||e==="enforce"?e:h.extensions.policy.trust_mode}function os(e){return e==="none"||e==="restricted"||e==="strict"?e:h.extensions.policy.default_sandbox_profile}function bl(e){let t=e.name.trim().toLowerCase();if(t.length===0)return null;let r={name:t};e.disabled===!0&&(r.disabled=!0),e.require_trusted===!0&&(r.require_trusted=!0),e.require_provenance===!0&&(r.require_provenance=!0),e.sandbox_profile!==void 0&&(r.sandbox_profile=os(e.sandbox_profile));let n=F(e.allowed_capabilities),o=F(e.blocked_capabilities),i=F(e.allowed_surfaces),s=F(e.blocked_surfaces),a=F(e.allowed_commands),d=F(e.blocked_commands),l=F(e.allowed_actions),_=F(e.blocked_actions),f=F(e.allowed_services),b=F(e.blocked_services);return n.length>0&&(r.allowed_capabilities=n),o.length>0&&(r.blocked_capabilities=o),i.length>0&&(r.allowed_surfaces=i),s.length>0&&(r.blocked_surfaces=s),a.length>0&&(r.allowed_commands=a),d.length>0&&(r.blocked_commands=d),l.length>0&&(r.allowed_actions=l),_.length>0&&(r.blocked_actions=_),f.length>0&&(r.allowed_services=f),b.length>0&&(r.blocked_services=b),r}function wl(e){let t=new Map;for(let r of e??[]){let n=bl(r);n&&t.set(n.name,n)}return[...t.values()].sort((r,n)=>r.name.localeCompare(n.name))}function fn(e){return e==="block"||e==="warn"?e:void 0}function El(e){if(typeof e=="string")return fn(e);if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let t=fn(e.global),r=fn(e.project);return t===void 0&&r===void 0?void 0:{...t!==void 0?{global:t}:{},...r!==void 0?{project:r}:{}}}}function j(e,t){return F(e?.[t]??h.extensions.policy[t])}function is(e){let t=El(e?.pm_max_version_exceeded_mode);return{mode:gl(e?.mode),trust_mode:vl(e?.trust_mode),...t!==void 0?{pm_max_version_exceeded_mode:t}:{},require_provenance:e?.require_provenance===!0,trusted_extensions:j(e,"trusted_extensions"),default_sandbox_profile:os(e?.default_sandbox_profile),allowed_extensions:j(e,"allowed_extensions"),blocked_extensions:j(e,"blocked_extensions"),allowed_capabilities:j(e,"allowed_capabilities"),blocked_capabilities:j(e,"blocked_capabilities"),allowed_surfaces:j(e,"allowed_surfaces"),blocked_surfaces:j(e,"blocked_surfaces"),allowed_commands:j(e,"allowed_commands"),blocked_commands:j(e,"blocked_commands"),allowed_actions:j(e,"allowed_actions"),blocked_actions:j(e,"blocked_actions"),allowed_services:j(e,"allowed_services"),blocked_services:j(e,"blocked_services"),extension_overrides:wl(e?.extension_overrides??h.extensions.policy.extension_overrides)}}function ss(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase().replaceAll("-","_")))].filter(t=>t.length>0).sort((t,r)=>t.localeCompare(r)).filter(t=>["author","acceptance_criteria","estimated_minutes","close_reason","reviewer","risk","confidence","sprint","release"].includes(t))}function re(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function R(e,t){return e===void 0?t:e}function L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function hn(e){return Array.isArray(e)?e:[]}function kl(e,t,r){return{...t.validation,...e.validation,parent_reference:r.parent_reference,metadata_profile:r.metadata_profile,metadata_required_fields:ss(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:re(e.validation?.lifecycle_stale_blocker_reason_patterns??t.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:re(e.validation?.lifecycle_closure_like_blocked_reason_patterns??t.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:re(e.validation?.lifecycle_closure_like_resolution_patterns??t.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:re(e.validation?.lifecycle_closure_like_actual_result_patterns??t.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:ln(e.validation?.estimate_defaults_by_type)}}function Sl(e,t){return{enabled:e.telemetry?.enabled??t.telemetry.enabled,first_run_prompt_completed:e.telemetry?.first_run_prompt_completed??t.telemetry.first_run_prompt_completed,capture_level:e.telemetry?.capture_level??t.telemetry.capture_level,endpoint:e.telemetry?.endpoint??t.telemetry.endpoint,installation_id:e.telemetry?.installation_id??t.telemetry.installation_id,retention_days:e.telemetry?.retention_days??t.telemetry.retention_days}}function Il(e,t){return{...t.search,...e.search,default_mode:Bi(e.search?.default_mode),mutation_refresh_policy:Gi(e.search?.mutation_refresh_policy),query_expansion:{...t.search.query_expansion,...e.search?.query_expansion,enabled:Ji(e.search?.query_expansion?.enabled),provider:Ki(e.search?.query_expansion?.provider)},rerank:{...t.search.rerank,...e.search?.rerank,enabled:Xi(e.search?.rerank?.enabled),model:Yi(e.search?.rerank?.model),top_k:Zi(e.search?.rerank?.top_k)}}}function Ol(e,t){return{adapter:e.vector_store.adapter??t.vector_store.adapter,collection_name:Qi(e.vector_store.collection_name),qdrant:{...t.vector_store.qdrant,...e.vector_store.qdrant},lancedb:{...t.vector_store.lancedb,...e.vector_store.lancedb}}}function Tl(e,t){return e.item_format==="json_markdown"?"toon":e.item_format??t.item_format}function Al(e,t){return{default_depth:e.context?.default_depth??t.context.default_depth,activity_limit:e.context?.activity_limit??t.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??t.context.stale_threshold_days,next_ranking_policy:e.context?.next_ranking_policy??t.context.next_ranking_policy,sections:{...t.context.sections,...e.context?.sections}}}function xl(e,t){return{openai:{...t.providers.openai,...e.providers.openai},ollama:{...t.providers.ollama,...e.providers.ollama}}}function Pe(e){let t=(e??[]).map(n=>Fn(n)).filter(n=>n!==null),r=new Map;for(let n of t)r.set(n.name.toLowerCase(),n);return[...r.values()].sort((n,o)=>n.name.localeCompare(o.name))}function Ut(e){let t=qi(),r=Wi({governance:e.governance??{preset:"default"}});return{...t,...e,item_format:Tl(e,t),locks:{...t.locks,...e.locks},ids:{...t.ids,...e.ids},agent_identity:structuredClone(e.agent_identity??t.agent_identity),mutation_guard:{...t.mutation_guard,...e.mutation_guard},checkpoints:{...t.checkpoints,...e.checkpoints},output:{...t.output,...e.output},ux:{...t.ux,...e.ux},history:{...t.history,...e.history,compact_policy:{...t.history.compact_policy,...e.history?.compact_policy}},validation:kl(e,t,r),governance:r,workflow:{definition_of_done:[...e.workflow?.definition_of_done??t.workflow.definition_of_done]},testing:{record_results_to_items:e.testing?.record_results_to_items??t.testing.record_results_to_items,allow_untrusted_linked_tests:e.testing?.allow_untrusted_linked_tests??t.testing.allow_untrusted_linked_tests},telemetry:Sl(e,t),agent_guidance:ns(e.agent_guidance??t.agent_guidance),item_types:{definitions:Pe(e.item_types?.definitions)},schema:ze(e.schema??t.schema),context:Al(e,t),extensions:{enabled:[...e.extensions.enabled],disabled:[...e.extensions.disabled],policy:is(e.extensions.policy??t.extensions.policy)},search:Il(e,t),providers:xl(e,t),vector_store:Ol(e,t)}}function Cl(e){e.agent_identity=g(e.agent_identity,["probes_enabled","identity_vocabulary","harness_signals"]);let t=e.agent_identity;Object.hasOwn(t,"identity_vocabulary")&&(t.identity_vocabulary=g(L(t.identity_vocabulary),["version","aliases"])),e.agent_identity.harness_signals=hn(e.agent_identity.harness_signals).map(r=>g(L(r),["harness","environment_keys","model_environment_keys","session_environment_keys","provenance_environment_keys","provenance_resolvers","provenance_unavailable_dimensions","argv_markers","client_names"])),e.locks=g(e.locks,["ttl_seconds","wait_ms"]),e.ids=g(e.ids,["token_length"]),e.mutation_guard=g(e.mutation_guard,["require_attributed_author","secret_guard","stale_in_progress_hours"]),e.checkpoints=g(e.checkpoints,["retention_days"]),e.output=g(e.output,["default_format"]),e.ux=g(e.ux,["deprecation_hints"]),e.history=g(e.history,["missing_stream","compact_policy"]),e.validation=g(e.validation,["sprint_release_format","parent_reference","metadata_profile","metadata_required_fields","lifecycle_stale_blocker_reason_patterns","lifecycle_closure_like_blocked_reason_patterns","lifecycle_closure_like_resolution_patterns","lifecycle_closure_like_actual_result_patterns","estimate_defaults_by_type"]),e.governance=g(e.governance,["preset","ownership_enforcement","create_mode_default","close_validation_default","require_close_reason","parent_reference","metadata_profile","force_required_for_stale_lock","create_default_type","workflow_enforcement","duplicate_detection_mode","duplicate_detection_threshold","duplicate_detection_limit"]),e.workflow=g(e.workflow,["definition_of_done"]),e.testing=g(e.testing,["record_results_to_items","allow_untrusted_linked_tests"]),e.telemetry=g(e.telemetry,["enabled","first_run_prompt_completed","capture_level","endpoint","installation_id","retention_days"]),e.agent_guidance=g(e.agent_guidance,["prompt_completed","declined","declined_at","template_version","last_checked_files"]),e.item_types=g(e.item_types,["definitions"]),e.schema=g(e.schema,["version","files","statuses","fields","workflow","type_workflows","unknown_field_policy"]),e.schema.files=g(L(e.schema.files),["types","statuses","fields","workflows"]),e.schema.workflow=g(L(e.schema.workflow),["draft_status","open_status","in_progress_status","blocked_status","close_status","canceled_status"]),e.context=g(e.context,["default_depth","activity_limit","stale_threshold_days","next_ranking_policy","sections"]),e.context.sections=g(L(e.context.sections),["hierarchy","activity","progress","blockers","files","workload","staleness","tests"]),e.extensions=g(e.extensions,["enabled","disabled","policy"]),e.extensions.policy=g(L(e.extensions.policy),["mode","trust_mode","pm_max_version_exceeded_mode","require_provenance","trusted_extensions","default_sandbox_profile","allowed_extensions","blocked_extensions","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services","extension_overrides"]),e.extensions.policy.extension_overrides=hn(e.extensions.policy.extension_overrides).map(r=>g(L(r),["name","disabled","require_trusted","require_provenance","sandbox_profile","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services"])),e.search=g(e.search,["score_threshold","hybrid_semantic_weight","max_results","embedding_model","embedding_corpus_max_characters","embedding_batch_size","embedding_timeout_ms","scanner_max_batch_retries","provider","default_mode","mutation_refresh_policy","query_expansion","rerank"]),e.search.query_expansion=g(L(e.search.query_expansion),["enabled","provider"]),e.search.rerank=g(L(e.search.rerank),["enabled","model","top_k"]),e.providers=g(e.providers,["openai","ollama"]),e.providers.openai=g(L(e.providers.openai),["base_url","api_key","model"]),e.providers.ollama=g(L(e.providers.ollama),["base_url","model"]),e.vector_store=g(e.vector_store,["adapter","collection_name","qdrant","lancedb"]),e.vector_store.qdrant=g(L(e.vector_store.qdrant),["url","api_key"]),e.vector_store.lancedb=g(L(e.vector_store.lancedb),["path"])}function Nl(e){return{...e,locks:R(e.locks,h.locks),ids:R(e.ids,h.ids),agent_identity:R(e.agent_identity,h.agent_identity),mutation_guard:R(e.mutation_guard,h.mutation_guard),checkpoints:R(e.checkpoints,h.checkpoints),output:R(e.output,h.output),ux:R(e.ux,h.ux),history:R(e.history,h.history),validation:R(e.validation,h.validation),workflow:R(e.workflow,h.workflow),testing:R(e.testing,h.testing),telemetry:R(e.telemetry,h.telemetry),agent_guidance:R(e.agent_guidance,h.agent_guidance),item_types:R(e.item_types,h.item_types),schema:R(e.schema,h.schema),context:R(e.context,h.context),extensions:R(e.extensions,h.extensions),search:R(e.search,h.search),providers:R(e.providers,h.providers),vector_store:R(e.vector_store,h.vector_store)}}function Rl(e,t){return{...e.validation,parent_reference:t.parent_reference,metadata_profile:t.metadata_profile,metadata_required_fields:ss(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:re(e.validation?.lifecycle_stale_blocker_reason_patterns??h.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:re(e.validation?.lifecycle_closure_like_blocked_reason_patterns??h.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:re(e.validation?.lifecycle_closure_like_resolution_patterns??h.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:re(e.validation?.lifecycle_closure_like_actual_result_patterns??h.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:ln(e.validation?.estimate_defaults_by_type)}}function Dl(e){return{...h.search,...e.search,default_mode:Bi(e.search?.default_mode),mutation_refresh_policy:Gi(e.search?.mutation_refresh_policy),query_expansion:{...h.search.query_expansion,...e.search?.query_expansion,enabled:Ji(e.search?.query_expansion?.enabled),provider:Ki(e.search?.query_expansion?.provider)},rerank:{...h.search.rerank,...e.search?.rerank,enabled:Xi(e.search?.rerank?.enabled),model:Yi(e.search?.rerank?.model),top_k:Zi(e.search?.rerank?.top_k)}}}function Pl(e){return{default_depth:e.context?.default_depth??h.context.default_depth,activity_limit:e.context?.activity_limit??h.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??h.context.stale_threshold_days,next_ranking_policy:e.context?.next_ranking_policy??h.context.next_ranking_policy,sections:{...h.context.sections,...e.context?.sections}}}function jl(e){return{...e.vector_store,adapter:e.vector_store?.adapter??h.vector_store.adapter,collection_name:Qi(e.vector_store?.collection_name),qdrant:{...e.vector_store?.qdrant},lancedb:{...e.vector_store?.lancedb}}}function Ll(e,t,r,n){return{...e,item_format:"toon",validation:Rl(e,t),governance:t,agent_guidance:ns(e.agent_guidance),item_types:{definitions:n.item_type_definitions},schema:{...r,statuses:n.schema_statuses,fields:n.schema_fields,type_workflows:n.schema_type_workflows},search:Dl(e),context:Pl(e),extensions:{enabled:pn(e.extensions?.enabled),disabled:pn(e.extensions?.disabled),policy:is(e.extensions?.policy)},vector_store:jl(e)}}function as(e,t){for(let r of Object.keys(t)){let n=Reflect.get(t,r),o=e[r];typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof o=="object"&&o!==null&&!Array.isArray(o)?as(o,n):e[r]=structuredClone(n)}}function cs(e,t,r){let n=new Set([...Object.keys(t),...Object.keys(r)]);for(let o of n){let i=t[o],s=r[o];if(!$(i,s)){if(s===void 0){delete e[o];continue}if(typeof i=="object"&&i!==null&&!Array.isArray(i)&&typeof s=="object"&&s!==null&&!Array.isArray(s)){let a=e[o],d=typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{};cs(d,i,s),Object.keys(d).length>0?e[o]=d:delete e[o];continue}e[o]=structuredClone(s)}}}var gn=["version","id_prefix","ids","author_default","agent_identity","mutation_guard","item_format","locks","checkpoints","output","ux","history","validation","governance","workflow","testing","telemetry","agent_guidance","item_types","schema","context","extensions","search","providers","vector_store"];function $i(e,t){let r=Nl(e),n=Wi(r),o=ze(r.schema),i=yl(r,t),s=Ll(r,n,o,i),a=g({...s,governance:ul(n)},gn);return Cl(a),a}function Hl(e,t={}){let r=t.source===void 0?t.persist_source:es(t.source.validated,Ut(t.source.validated)),n=$i(e,r);if(r){let o=Ut(r.source_settings);o.item_types={definitions:structuredClone(r.runtime_item_type_definitions)},o.schema={...o.schema,statuses:structuredClone(r.runtime_schema_statuses),fields:structuredClone(r.runtime_schema_fields),type_workflows:structuredClone(r.runtime_schema_type_workflows)};let i=$i(o,r);t.source!==void 0&&as(i,t.source.validated);let s=structuredClone(t.source===void 0?r.source_settings:t.source.raw);return cs(s,i,n),`${JSON.stringify(g(s,gn),null,2)}
75
75
  `}return`${JSON.stringify(n,null,2)}
76
76
  `}async function zl(e){let t;try{t=await Mi(e)}catch(a){if(W(a))return U();throw a}let r=we(t),n;try{n=await il(r)}catch(a){if(W(a))return U();throw a}if(!n.isFile())throw Yt("settings.json");let o;try{o=await Ln(r,Yt("settings.json"))}catch(a){if(W(a))return U();throw a}let i;try{i=JSON.parse(o)}catch{return U("settings_read_invalid_json")}let s=sn(i);return s.success?{settings:Ut(s.data),metadata:{has_explicit_item_format:rs(i)},warnings:s.data.item_format==="json_markdown"?["settings_item_format_legacy_json_markdown_coerced_to_toon"]:[]}:U("settings_read_invalid_schema")}async function ds(e){if(sl(e))return zl(e);let t=we(e),r=[t];await it({path:t,scope:"project"});let n=Li(e);if(n){let l=await te(n.tracked_paths);if(Xe(l,n.signatures))return Vt(n.value)}let o=await te([t]),i;try{i=await be(t)}catch{return U("settings_read_fs_error")}if(i===null){let l=U();return await _n(e,[t],l,o,[t]),l}let s=await te([t]);if(!Xe(o,s))return ge(e),ds(e);let a;try{a=JSON.parse(i)}catch{let l=U("settings_read_invalid_json");return await _n(e,[t],l,s,[t]),l}let d=sn(a);if(!d.success){let l=U("settings_read_invalid_schema");return await _n(e,[t],l,s,[t]),l}try{let l=Ut(d.data),_=fl(e,l.schema,t);r=_;let f=await te(_),b=await Mn(e,l.schema),O=await te(_),S={...l,item_types:{definitions:Pe([...l.item_types.definitions,...hn(b.type_definitions_from_file)])},schema:b.schema};yn(S,es(d.data,S));let z={settings:S,metadata:{has_explicit_item_format:rs(a)},warnings:[...d.data.item_format==="json_markdown"?["settings_item_format_legacy_json_markdown_coerced_to_toon"]:[],...b.warnings]};return Xe(f,O)?Mt(e,{tracked_paths:_,signatures:O,value:Vt(z)}):ge(e),z}catch{let l=U("settings_read_merge_failed");return await pl(e,r,l),l}}async function bm(e){return(await ds(e)).settings}async function wm(e,t,r=al){let n=we(e),o=ts(t),i=Hl(t,{persist_source:o}),s=JSON.parse(i);try{await Ni({pmRoot:e,filePath:n,mutate:a=>{let d=null;if(a!==null)try{d=JSON.parse(a)}catch{throw new w("Existing settings.json is malformed; the settings write was refused.",E.USAGE,{code:"settings_write_invalid_existing_json",reason:"existing_settings_json_malformed",why:"Writing defaults over malformed settings could destroy intended project configuration.",nextSteps:["Repair the syntax in .agents/pm/settings.json, then retry the original command.","Run pm health to confirm the settings warning has cleared."]})}return{raw:o?`${JSON.stringify(g(cn(o.persisted_settings,s,d),gn),null,2)}
77
77
  `:i,result:void 0}},op:r,author:zo(void 0,t.author_default),lockTtlSeconds:t.locks.ttl_seconds,lockWaitMs:t.locks.wait_ms,recordCreation:!1}),o&&yn(t,{...o,persisted_settings:structuredClone(s)}),await Gn({path:n,scope:"project",op:r})}finally{ge(e)}}import ls from"node:fs";import Ye from"node:path";import{createRequire as Fl}from"node:module";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="19d9b802-1efa-5716-8176-ecbf5b153ff0")}catch{}})();var us="@unbrained/pm-cli";var bn=/\b(\d{4})\.(\d{1,2})\.(\d{1,2})(?:-(\d+))?\b/u,wn="2026.8.31";function Wt(e){let t=e.match(bn);return t?[Number(t[1]),Number(t[2]),Number(t[3]),Number(t[4]??0)]:null}function Gt(e,t){let r=Wt(e),n=Wt(t);if(!r||!n)return null;for(let o=0;o<r.length;o+=1){let i=r[o]-n[o];if(i!==0)return Math.sign(i)}return 0}function vn(e){return Gt(e,wn)!==-1?3:2}function qt(e){try{let t=JSON.parse(ls.readFileSync(e,"utf8"));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function $l(e){let t=[...e.matchAll(/(<=|<)\s*v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/gu)].map(n=>({inclusive:n[1]==="<=",version:n[2]})),r=e.match(/\b\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?\s+-\s+v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/u);return r?[...t,{inclusive:!0,version:r[1]}]:t}function Ml(e){let t=e.split("||").map(r=>$l(r));return{bounded:t.some(r=>r.length>0),compatible:t.some(r=>r.every(n=>{let o=Gt(wn,n.version);return o!==null&&(n.inclusive?o!==1:o===-1)}))}}function _s(e){return["dependencies","devDependencies","optionalDependencies","peerDependencies"].flatMap(t=>{let r=e[t];if(typeof r!="object"||r===null)return[];let n=r[us];return typeof n=="string"?[n.trim()]:[]})}function Vl(e){return _s(e).flatMap(t=>{let r=/^[<!]/u.test(t)?void 0:t.match(bn)?.[0];if(!r)return[];let n=/^(?:=|v)?\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?$/u.test(t),o=Ml(t);return[{version:r,constraint:n?"exact":o.bounded?"range":"minimum",...n?{}:{declaration:t},history_epoch_compatible:n?Gt(r,wn)!==-1:o.compatible}]})}function Ul(e){let t=qt(Ye.join(e,"package-lock.json"))?.packages;if(typeof t!="object"||t===null)return;let r=t["node_modules/@unbrained/pm-cli"];if(typeof r!="object"||r===null)return;let n=r.version;return typeof n=="string"?n:void 0}function Wl(e,t){try{let r=ls.readFileSync(Ye.join(e,t),"utf8").split(/\r?\n/u),n=r.findIndex(s=>s.includes(us));if(n<0)return;let o=r[n].match(/^\s*/u)[0].length,i=[r[n]];for(let s=n+1;s<r.length;s+=1){let a=r[s],d=a.trim(),l=a.match(/^\s*/u)[0].length;if(d.length>0&&l<=o)break;i.push(a)}return i.join(`
78
78
  `).match(/^\s*version(?::\s*|\s+)["']?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/mu)?.[1]??i[0].match(bn)?.[0]}catch{return}}function ql(e){let t=[],r=qt(Ye.join(e,"package.json"));r&&t.push(...Vl(r).map(i=>({...i,source:"package.json"})));let n=qt(Ye.join(e,"node_modules","@unbrained","pm-cli","package.json"))?.version;typeof n=="string"&&Wt(n)&&t.push({version:n,source:"installed-package",constraint:"exact",history_epoch_compatible:vn(n)===3});let o=Ul(e);o&&Wt(o)&&t.push({version:o,source:"package-lock.json",constraint:"exact",history_epoch_compatible:vn(o)===3});for(let i of["pnpm-lock.yaml","yarn.lock"]){let s=Wl(e,i);s&&t.push({version:s,source:i,constraint:"exact",history_epoch_compatible:vn(s)===3})}return t}function Am(e,t){if(t<=1)return;let{minVersion:r,lt:n}=Fl(import.meta.url)("semver"),o=_s(qt(Ye.join(e,"package.json"))??{}).find(s=>{try{let a=r(s);return a!==null&&n(a,"2026.10.10")}catch{return!1}}),i=o===void 0?ql(e).find(s=>Gt(s.version,"2026.10.10")===-1):{version:o,source:"package.json"};if(i)throw new w(`The project selects pm ${i.version}, which cannot safely refuse item format ${t}.`,E.CONFLICT,{code:"project_runtime_item_format_incompatible",reason:i.source,required:"Upgrade project pins, installed SDKs, CI hosts and Git merge drivers before writing guarded item formats.",nextSteps:["Use a pm runtime supporting the required item format throughout the project; preserve original item and history bytes, and never re-anchor history to satisfy an older host."]})}import kn from"node:fs/promises";import Bt from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="658ab1c3-da92-5af6-a170-85ed7befaad6")}catch{}})();function ne(e,t){return typeof e=="object"&&e!==null&&"code"in e&&e.code===t}function fs(e){let t=["--pm-path",e,"init","--defaults","--agent-guidance","skip"];return{suggested_retry:Jn(t),suggested_retry_args:t}}function Jt(e){return new w(`Tracker root is not a directory at ${e}.`,E.USAGE,{code:"tracker_root_not_directory",reason:"not_a_directory",resolved_path:e,nextSteps:["Pass a tracker directory, usually <workspace>/.agents/pm, rather than a file path."]})}function En(e){return new w(`Tracker root is not readable at ${e}.`,E.GENERIC_FAILURE,{code:"tracker_root_unreadable",reason:"unreadable",resolved_path:e,nextSteps:["Grant read and directory-search permission to the tracker root, then retry."]})}async function Gl(e){let t=Bt.resolve(e),r=Bt.parse(t).root,n=Bt.dirname(t);for(;n!==r;){let o;try{o=await kn.stat(n)}catch(i){if(ne(i,"ENOTDIR"))throw Jt(e);if(!ne(i,"ENOENT"))throw i;n=Bt.dirname(n);continue}if(!o.isDirectory())throw Jt(e);return}}async function Bl(e){let t;try{t=await kn.stat(e)}catch(r){throw ne(r,"ENOENT")?(await Gl(e),new w(`Tracker is not initialized at ${e}. Tracker root does not exist. Run pm init first.`,E.NOT_FOUND,{code:"tracker_root_missing",reason:"missing",resolved_path:e,nextSteps:["Confirm the tracker root path or initialize it with the emitted retry."],recovery:fs(e)})):ne(r,"ENOTDIR")?Jt(e):ne(r,"EACCES")||ne(r,"EPERM")?En(e):r}if(!t.isDirectory())throw Jt(e);if(process.platform!=="win32"&&((t.mode&292)===0||(t.mode&73)===0))throw En(e);try{await(await kn.opendir(e)).close()}catch(r){throw ne(r,"EACCES")||ne(r,"EPERM")?En(e):r}}async function Hm(e){if(await Bl(e),!await jn(we(e)))throw new w(`Tracker is not initialized at ${e}. Run pm init first.`,E.NOT_FOUND,{code:"tracker_not_initialized",reason:"settings_missing",resolved_path:e,nextSteps:["Initialize the selected tracker root with the emitted retry."],recovery:fs(e)})}export{Kl as a,ys as b,Qn as c,se as d,K as e,Fo as f,ro as g,Me as h,ru as i,nu as j,er as k,tr as l,iu as m,rr as n,oo as o,Ts as p,su as q,ct as r,xs as s,lu as t,dt as u,wa as v,_t as w,xu as x,Cu as y,Oe as z,ce as A,hr as B,Du as C,Pu as D,vr as E,Eo as F,wr as G,Uu as H,Wu as I,qu as J,Gu as K,Bu as L,Ju as M,Cr as N,Nr as O,Co as P,o_ as Q,i_ as R,s_ as S,a_ as T,c_ as U,d_ as V,jr as W,jo as X,l_ as Y,u_ as Z,__ as _,Ic as $,f_ as aa,zo as ba,gt as ca,Ge as da,xe as ea,Ko as fa,ad as ga,_d as ha,ef as ia,tf as ja,bd as ka,Rt as la,_e as ma,Be as na,Of as oa,en as pa,vt as qa,Vo as ra,Tf as sa,Uo as ta,Af as ua,tn as va,rn as wa,Ac as xa,bt as ya,R_ as za,Lr as Aa,wt as Ba,D_ as Ca,P_ as Da,qo as Ea,Et as Fa,kt as Ga,Je as Ha,Hc as Ia,j_ as Ja,L_ as Ka,De as La,Lt as Ma,Uf as Na,Wf as Oa,qf as Pa,Ni as Qa,Gf as Ra,sn as Sa,Zf as Ta,ge as Ua,vm as Va,sl as Wa,Wi as Xa,Ut as Ya,Hl as Za,ds as _a,bm as $a,wm as ab,ql as bb,Am as cb,Bl as db,Hm as eb};
79
- //# sourceMappingURL=chunk-YU7QOYYV.js.map
79
+ //# sourceMappingURL=chunk-M22TI7LP.js.map