@unbrained/pm-cli 2026.11.26 → 2026.11.28

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 (185) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli-bundle/bundle-manifest.json +1 -1
  3. package/dist/cli-bundle/chunks/{chunk-BITDGTAX.js → chunk-2YD2AERA.js} +2 -2
  4. package/dist/cli-bundle/chunks/chunk-54AQJTUH.js +3 -0
  5. package/dist/cli-bundle/chunks/chunk-56DKWGHE.js +2 -0
  6. package/dist/cli-bundle/chunks/chunk-56GUDMXN.js +113 -0
  7. package/dist/cli-bundle/chunks/chunk-5ECCMDSU.js +2 -0
  8. package/dist/cli-bundle/chunks/chunk-6RBD2AKU.js +2 -0
  9. package/dist/cli-bundle/chunks/{chunk-PQSEEVOA.js → chunk-C4O5TZY3.js} +46 -46
  10. package/dist/cli-bundle/chunks/chunk-CATRDGAB.js +125 -0
  11. package/dist/cli-bundle/chunks/{chunk-5FY2VHRF.js → chunk-CDUV7DFD.js} +2 -2
  12. package/dist/cli-bundle/chunks/chunk-CTM26LUE.js +4 -0
  13. package/dist/cli-bundle/chunks/chunk-D3I5AHNN.js +2 -0
  14. package/dist/cli-bundle/chunks/chunk-E2LQ6LCJ.js +2 -0
  15. package/dist/cli-bundle/chunks/{chunk-B2GM6KOM.js → chunk-FG4TNQQM.js} +2 -2
  16. package/dist/cli-bundle/chunks/chunk-JQYPSABI.js +2 -0
  17. package/dist/cli-bundle/chunks/chunk-LMDIKSDZ.js +9 -0
  18. package/dist/cli-bundle/chunks/chunk-LRGYV6QQ.js +2 -0
  19. package/dist/cli-bundle/chunks/chunk-MO6PPUI6.js +2 -0
  20. package/dist/cli-bundle/chunks/chunk-O2SWNEBW.js +8 -0
  21. package/dist/cli-bundle/chunks/{chunk-5AAIRHNE.js → chunk-O2WNNIKK.js} +2 -2
  22. package/dist/cli-bundle/chunks/{chunk-LNZKNVMT.js → chunk-OFIYA3PI.js} +3 -3
  23. package/dist/cli-bundle/chunks/{chunk-DYL2N3OC.js → chunk-Q6BGQRCB.js} +2 -2
  24. package/dist/cli-bundle/chunks/chunk-RGE3XW3A.js +2 -0
  25. package/dist/cli-bundle/chunks/chunk-SP6CDM6B.js +31 -0
  26. package/dist/cli-bundle/chunks/{chunk-T3GJPXIZ.js → chunk-T7RZPIOB.js} +14 -14
  27. package/dist/cli-bundle/chunks/{chunk-MNFCJNQA.js → chunk-T7UTG56V.js} +4 -4
  28. package/dist/cli-bundle/chunks/chunk-TWRUA2NH.js +3 -0
  29. package/dist/cli-bundle/chunks/chunk-WKDKBS4P.js +4 -0
  30. package/dist/cli-bundle/chunks/chunk-YEMFOKFG.js +2 -0
  31. package/dist/cli-bundle/chunks/{chunk-ZDL45VTB.js → chunk-YLS2N4SN.js} +2 -2
  32. package/dist/cli-bundle/chunks/{chunk-FWBR3OW7.js → chunk-ZXERHBMA.js} +2 -2
  33. package/dist/cli-bundle/chunks/field-definition-losses-JFMMMVTV.js +2 -0
  34. package/dist/cli-bundle/chunks/field-option-collisions-G4LQ2646.js +2 -0
  35. package/dist/cli-bundle/{focused-chunks/item-revision-RPTXN7WW.js → chunks/item-revision-O7L3AA2W.js} +2 -2
  36. package/dist/cli-bundle/chunks/item-transaction-4XC74ULD.js +2 -0
  37. package/dist/cli-bundle/chunks/mutation-actor-A45DFDEO.js +2 -0
  38. package/dist/cli-bundle/chunks/mutation-admission-SIUIMAEO.js +2 -0
  39. package/dist/cli-bundle/chunks/{register-list-query-EKSCZWEZ.js → register-list-query-FCPGG2UT.js} +2 -2
  40. package/dist/cli-bundle/chunks/{register-mutation-ZIAOKKUJ.js → register-mutation-VD3JX23I.js} +2 -2
  41. package/dist/cli-bundle/chunks/register-operations-KHJD4GFZ.js +2 -0
  42. package/dist/cli-bundle/chunks/register-setup-EWAZZWPL.js +2 -0
  43. package/dist/cli-bundle/chunks/runtime-schema-3RAXYNG5.js +2 -0
  44. package/dist/cli-bundle/chunks/{settlement-hook-ESAAEBRM.js → settlement-hook-KWBOSRDZ.js} +2 -2
  45. package/dist/cli-bundle/chunks/stage-UIDZMTE5.js +2 -0
  46. package/dist/cli-bundle/focused-chunks/chunk-5MZXU6HB.js +2 -0
  47. package/dist/cli-bundle/focused-chunks/chunk-64DSKZJN.js +100 -0
  48. package/dist/cli-bundle/focused-chunks/{chunk-YSZZSV6M.js → chunk-7EKKUYN5.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/chunk-7P6OGPEG.js +2 -0
  50. package/dist/cli-bundle/focused-chunks/chunk-A5B43EWU.js +2 -0
  51. package/dist/cli-bundle/focused-chunks/chunk-AHCOSTL7.js +2 -0
  52. package/dist/cli-bundle/focused-chunks/chunk-CQLOYNJY.js +2 -0
  53. package/dist/cli-bundle/focused-chunks/chunk-E4C6T3NL.js +2 -0
  54. package/dist/cli-bundle/focused-chunks/{chunk-3GQRWIT5.js → chunk-HCWDMFWA.js} +2 -2
  55. package/dist/cli-bundle/focused-chunks/{chunk-GQBWI4KA.js → chunk-J4V3J5MC.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/chunk-JD45Y2BR.js +91 -0
  57. package/dist/cli-bundle/focused-chunks/chunk-KMGI5GZP.js +2 -0
  58. package/dist/cli-bundle/focused-chunks/chunk-MSLRDKWL.js +4 -0
  59. package/dist/cli-bundle/focused-chunks/chunk-O33WUEAF.js +3 -0
  60. package/dist/cli-bundle/focused-chunks/{chunk-QNWNUQSJ.js → chunk-OEMI52ZS.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/{chunk-AAB3ZR7Z.js → chunk-Q6JCMFGU.js} +2 -2
  62. package/dist/cli-bundle/focused-chunks/chunk-RBOWKXFV.js +8 -0
  63. package/dist/cli-bundle/focused-chunks/chunk-TF57RHS2.js +2 -0
  64. package/dist/cli-bundle/focused-chunks/{chunk-TNVLDU7Z.js → chunk-VNU3IFBL.js} +2 -2
  65. package/dist/cli-bundle/focused-chunks/chunk-X5ZVPFK7.js +4 -0
  66. package/dist/cli-bundle/focused-chunks/chunk-XVCMYFQU.js +27 -0
  67. package/dist/cli-bundle/focused-chunks/{chunk-RDELKGLS.js → chunk-Y7EC2L2G.js} +3 -3
  68. package/dist/cli-bundle/focused-chunks/{chunk-FQWKESMI.js → chunk-YC3PFFDE.js} +56 -56
  69. package/dist/cli-bundle/focused-chunks/{chunk-QSRXF6XS.js → chunk-YX75PQFO.js} +2 -2
  70. package/dist/cli-bundle/focused-chunks/{chunk-KEZ4VXYD.js → chunk-Z4FWJGQG.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/chunk-ZHHFOQSL.js +44 -0
  72. package/dist/cli-bundle/focused-chunks/chunk-ZUAPUBJK.js +2 -0
  73. package/dist/cli-bundle/focused-chunks/{chunk-NXUFVQ33.js → chunk-ZYHGQIQ7.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/field-definition-losses-NUZO3JCP.js +2 -0
  75. package/dist/cli-bundle/focused-chunks/field-option-collisions-63YQ2J3N.js +2 -0
  76. package/dist/cli-bundle/focused-chunks/item-revision-PV5O6F5Y.js +2 -0
  77. package/dist/cli-bundle/focused-chunks/item-transaction-S5QXBGAT.js +2 -0
  78. package/dist/cli-bundle/{chunks/mutation-actor-HGG47KXV.js → focused-chunks/mutation-actor-2AAUJG2Z.js} +2 -2
  79. package/dist/cli-bundle/focused-chunks/mutation-admission-X7HHNERR.js +2 -0
  80. package/dist/cli-bundle/focused-chunks/runtime-schema-5J2ONRNV.js +2 -0
  81. package/dist/cli-bundle/focused-chunks/stage-56RYPMBK.js +2 -0
  82. package/dist/cli-bundle/main.js +2 -2
  83. package/dist/cli-bundle/sdk-authoring.js +1 -1
  84. package/dist/cli-bundle/sdk-contracts.js +1 -1
  85. package/dist/cli-bundle/sdk-core.js +1 -1
  86. package/dist/cli-bundle/sdk-governance.js +1 -1
  87. package/dist/cli-bundle/sdk-graph.js +1 -1
  88. package/dist/cli-bundle/sdk-merge.js +63 -63
  89. package/dist/cli-bundle/sdk-query.js +1 -1
  90. package/dist/cli-bundle/sdk-runtime.js +1 -1
  91. package/dist/cli-bundle/sdk-testing.js +1 -1
  92. package/dist/cli-bundle/sdk.js +2 -2
  93. package/dist/core/extensions/index.js +1 -1
  94. package/dist/core/extensions/item-fields.d.ts +15 -1
  95. package/dist/core/extensions/item-fields.js +1 -1
  96. package/dist/core/extensions/loader.js +1 -1
  97. package/dist/core/profile/profile-lint.js +1 -1
  98. package/dist/core/schema/runtime-schema.d.ts +20 -1
  99. package/dist/core/schema/runtime-schema.js +2 -2
  100. package/dist/core/shared/command-line.d.ts +2 -2
  101. package/dist/core/shared/command-line.js +1 -1
  102. package/dist/core/shared/secret-rules.js +5 -5
  103. package/dist/sdk/agent/refusal-reachability.d.ts +1 -1
  104. package/dist/sdk/extension/command-options.d.ts +8 -0
  105. package/dist/sdk/extension/command-options.js +1 -1
  106. package/dist/sdk/extension-command-context.js +2 -2
  107. package/dist/sdk/governance/validate.js +1 -1
  108. package/dist/sdk/lifecycle/create.js +1 -1
  109. package/dist/sdk/lifecycle/update.js +2 -2
  110. package/dist/sdk/profile.js +1 -1
  111. package/dist/sdk/read-output-contracts.js +1 -1
  112. package/dist/sdk/schema/field-definition-losses.js +2 -0
  113. package/dist/sdk/schema/field-option-collisions.js +1 -1
  114. package/dist/sdk/schema.js +2 -2
  115. package/docs/COMMANDS.md +1 -1
  116. package/docs/CONFIGURATION.md +3 -1
  117. package/docs/EXTENSIONS.md +1 -1
  118. package/docs/MUTATION_INTEGRITY.md +47 -0
  119. package/docs/SDK.md +3 -1
  120. package/docs/SDK_AUDITED_MUTATIONS.md +12 -3
  121. package/marketplace.json +1 -1
  122. package/package.json +1 -1
  123. package/packages/pm-beads/package.json +1 -1
  124. package/packages/pm-calendar/package.json +1 -1
  125. package/packages/pm-command-kit/package.json +1 -1
  126. package/packages/pm-digital-twin/package.json +1 -1
  127. package/packages/pm-governance-audit/package.json +1 -1
  128. package/packages/pm-guide-shell/package.json +1 -1
  129. package/packages/pm-kanban/package.json +1 -1
  130. package/packages/pm-lifecycle-hooks/package.json +1 -1
  131. package/packages/pm-linked-test-adapters/package.json +1 -1
  132. package/packages/pm-search-advanced/package.json +1 -1
  133. package/packages/pm-templates/package.json +1 -1
  134. package/packages/pm-todos/package.json +1 -1
  135. package/packages/pm-vcs/package.json +1 -1
  136. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  137. package/plugins/pm-claude/package.json +1 -1
  138. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  139. package/plugins/pm-codex/package.json +1 -1
  140. package/plugins/pm-codex/plugin.json +1 -1
  141. package/runtime-dependencies.json +1 -1
  142. package/dist/cli-bundle/chunks/chunk-5BPDT7G2.js +0 -2
  143. package/dist/cli-bundle/chunks/chunk-7F3UFYZA.js +0 -2
  144. package/dist/cli-bundle/chunks/chunk-CBBKXTJG.js +0 -2
  145. package/dist/cli-bundle/chunks/chunk-DUJSME77.js +0 -3
  146. package/dist/cli-bundle/chunks/chunk-GQXK4KKH.js +0 -31
  147. package/dist/cli-bundle/chunks/chunk-HOLQZ56F.js +0 -8
  148. package/dist/cli-bundle/chunks/chunk-HTGN24XM.js +0 -3
  149. package/dist/cli-bundle/chunks/chunk-IGW3RVJC.js +0 -3
  150. package/dist/cli-bundle/chunks/chunk-KCRRTJ4X.js +0 -125
  151. package/dist/cli-bundle/chunks/chunk-KES4VHU4.js +0 -2
  152. package/dist/cli-bundle/chunks/chunk-NDS4MXZX.js +0 -2
  153. package/dist/cli-bundle/chunks/chunk-QMM46SJM.js +0 -4
  154. package/dist/cli-bundle/chunks/chunk-RFK3ERYX.js +0 -2
  155. package/dist/cli-bundle/chunks/chunk-SX76UGEY.js +0 -3
  156. package/dist/cli-bundle/chunks/chunk-WZOJSHJT.js +0 -113
  157. package/dist/cli-bundle/chunks/chunk-XRCE4QNL.js +0 -9
  158. package/dist/cli-bundle/chunks/field-option-collisions-CGRJEAPQ.js +0 -2
  159. package/dist/cli-bundle/chunks/item-revision-FGDR5NSF.js +0 -2
  160. package/dist/cli-bundle/chunks/item-transaction-C3KAMEYO.js +0 -2
  161. package/dist/cli-bundle/chunks/mutation-admission-LLHIRY6O.js +0 -2
  162. package/dist/cli-bundle/chunks/register-operations-ECVBZ5FM.js +0 -2
  163. package/dist/cli-bundle/chunks/register-setup-3QYD5H4H.js +0 -2
  164. package/dist/cli-bundle/chunks/runtime-schema-Y4SHTEXL.js +0 -2
  165. package/dist/cli-bundle/chunks/stage-RSCSUYEJ.js +0 -2
  166. package/dist/cli-bundle/focused-chunks/chunk-3BR5NWQI.js +0 -2
  167. package/dist/cli-bundle/focused-chunks/chunk-AVLB4L7M.js +0 -44
  168. package/dist/cli-bundle/focused-chunks/chunk-FW5Q26HA.js +0 -2
  169. package/dist/cli-bundle/focused-chunks/chunk-IWEGGRRD.js +0 -2
  170. package/dist/cli-bundle/focused-chunks/chunk-JUG3BAZZ.js +0 -2
  171. package/dist/cli-bundle/focused-chunks/chunk-NSFS3VWP.js +0 -100
  172. package/dist/cli-bundle/focused-chunks/chunk-OCKKIECS.js +0 -3
  173. package/dist/cli-bundle/focused-chunks/chunk-R6QFPHWW.js +0 -3
  174. package/dist/cli-bundle/focused-chunks/chunk-RFJ3MEFP.js +0 -27
  175. package/dist/cli-bundle/focused-chunks/chunk-RMJKVQYE.js +0 -3
  176. package/dist/cli-bundle/focused-chunks/chunk-UA2JNKMY.js +0 -4
  177. package/dist/cli-bundle/focused-chunks/chunk-VV2QF5IE.js +0 -91
  178. package/dist/cli-bundle/focused-chunks/chunk-WHHFPATO.js +0 -8
  179. package/dist/cli-bundle/focused-chunks/chunk-YNRW2FWB.js +0 -2
  180. package/dist/cli-bundle/focused-chunks/field-option-collisions-WV6GPYYP.js +0 -2
  181. package/dist/cli-bundle/focused-chunks/item-transaction-A6MVNPT7.js +0 -2
  182. package/dist/cli-bundle/focused-chunks/mutation-actor-6ZVW6OME.js +0 -2
  183. package/dist/cli-bundle/focused-chunks/mutation-admission-2DA4CINP.js +0 -2
  184. package/dist/cli-bundle/focused-chunks/runtime-schema-YXPYDD2C.js +0 -2
  185. package/dist/cli-bundle/focused-chunks/stage-RG3PKST7.js +0 -2
@@ -1,2 +1,2 @@
1
- import{existsSync as E}from"node:fs";import{AsyncLocalStorage as A}from"node:async_hooks";import a from"node:path";import{ownedTransactionCompensation as S}from"../store/item-mutation-precondition.js";import{runCommandHandler as w,runBeforeMutationHooks as I,runCommandOverride as y,runOnIndexHooks as H,runParserOverride as P,runPreflightOverride as W,runOnReadHooks as M,runRendererOverride as T,runServiceOverride as j,runServiceOverrideSync as N,runOnWriteHooks as U}from"./loader.js";let c=null,l=null,m=null,f=null,d=null,p=null,v=null,u=null,_,g=[];const C=new A;function s(){return C.getStore()}function X(e){return C.run({hooks:null,commands:null,parsers:null,preflight:null,services:null,renderers:null,registrations:null,commandContext:null,commandResult:void 0,affectedItems:[]},e)}const D=new Set(["body","comments","dependencies","docs","events","files","learnings","notes","reminders","test_runs","tests"]);function k(e){let t=a.resolve(e);for(;;){if(E(a.join(t,".git")))return t;const o=a.dirname(t);if(o===t)return;t=o}}function x(e){const t=process.env.PM_SOURCE_WORKSPACE_ROOT?.trim()||process.cwd(),o=k(t)??a.resolve(t),n=k(o);if(!e)return{source_workspace_root:o,...n?{repo_root:n}:{}};const r=a.relative(o,a.resolve(e)),i=r.length>0&&!r.startsWith(`..${a.sep}`)&&r!==".."&&!a.isAbsolute(r);return{source_workspace_root:o,...n?{repo_root:n}:{},...i?{pm_root_rel:r.split(a.sep).join("/")}:{}}}function Y(e){const t=s();if(t){t.hooks=e;return}c=e}function $(e){const t=s();if(t){t.commands=e;return}l=e}function q(e){const t=s();if(t){t.parsers=e;return}m=e}function z(e){const t=s();if(t){t.preflight=e;return}f=e}function J(e){const t=s();if(t){t.services=e;return}d=e}function V(e){const t=s();if(t){t.renderers=e;return}p=e}function Z(e){const t=s();if(t){t.registrations=e;return}v=e}function ee(){const e=s();return e?e.registrations:v}function te(){const e=s();if(e){e.hooks=null,e.commands=null,e.parsers=null,e.preflight=null,e.services=null,e.renderers=null,e.registrations=null,e.commandContext=null,e.commandResult=null,e.affectedItems=[];return}c=null,l=null,m=null,f=null,d=null,p=null,v=null,u=null,_=null}function oe(e){const t=e?{...e,...x(e.pm_root)}:null,o=s();if(o){o.commandContext=t;return}u=t}function ne(){const e=s(),t=e?e.commandContext:u;return t?{...t,args:[...t.args],options:t.options?{...t.options}:{},global:t.global?{...t.global}:void 0}:null}function re(e){const t=s()??{commandContext:u,hooks:c,commands:l,parsers:m,preflight:f,services:d,renderers:p,registrations:v};return t.commandContext?.command!==e||[t.hooks,t.preflight,t.services,t.renderers].some(r=>Object.values(r??{}).some(i=>i.length>0))||[t.commands,t.parsers].some(r=>Object.values(r??{}).some(i=>i.some(h=>h.command===e)))?!1:!Object.entries(t.registrations??{}).some(([r,i])=>["migrations","search_providers","vector_store_adapters","assurance_providers"].includes(r)&&i.length>0)}function se(e){const t=s();if(t){t.commandResult=e;return}_=e}function ie(){const e=s();return e?e.commandResult:_}function ce(e){if(!e)return;const t=s();t?t.affectedItems.push(e):g.push(e)}function ae(e,t){if(!e||!e.id)return{};const o={id:e.id,type:e.type,status:e.status};if(!Array.isArray(t))return o;const n=e;for(const r of t){if(typeof r!="string")continue;const i=r.startsWith("unset:")?r.slice(6):r;i==="id"||i==="type"||i==="status"||D.has(i)||Object.hasOwn(n,i)&&n[i]!==void 0&&(o[i]=n[i])}return o}function ue(){const e=s(),t=e?.affectedItems??g;if(t.length===0)return;const o=t;return e?e.affectedItems=[]:g=[],o}function le(){const e=s();if(e){e.hooks=null,e.commands=null,e.parsers=null,e.preflight=null,e.services=null,e.renderers=null,e.registrations=null,e.commandContext=null,e.commandResult=void 0,e.affectedItems=[];return}c=null,l=null,m=null,f=null,d=null,p=null,v=null,u=null,_=void 0,g=[]}async function de(e){const t=s(),o=t?t.hooks:c;return o?U(o,e):[]}const O=new A;function me(e,t){return!e||(e.beforeMutation?.length??0)===0?t():O.run(e,t)}function B(){const e=s();return e?e.hooks:c}async function fe(e){const t=O.getStore(),o=t??B();if(!o)return;const{resolveMutationActor:n}=await import("./mutation-actor.js"),r=t!==void 0||e.dry_run===!0,i=r?void 0:S(e.pm_root,[e.before?.metadata.id,e.after?.metadata.id],e.operation),h=await I(o,{pm_root:e.pm_root,operation:e.operation,before:e.before,after:e.after,changed_fields:e.changed_fields,sdk:e.sdk,actor:n(e.author),dry_run:r,...i===void 0?{}:{compensation:{transaction_id:i.transaction_id,step_id:i.step_id}}});i?.overrides.push(...h.map(b=>({source:"mutation_guard",...b})))}async function pe(e){const t=s(),o=t?t.hooks:c;return o?M(o,e):[]}function ve(){const e=s();return((e?e.hooks:c)?.onWrite?.length??0)>0}function _e(){const e=s();return((e?e.hooks:c)?.onRead?.length??0)>0}async function ge(e){const t=s(),o=t?t.hooks:c;return o?H(o,e):[]}function xe(e){const t=s(),o=t?t.commands:l,n=t?t.commandContext:u;return!o||!n?{overridden:!1,result:e,warnings:[]}:y(o,{command:n.command,args:[...n.args],options:n.options?{...n.options}:{},global:n.global?{...n.global}:void 0,pm_root:n.pm_root,source_workspace_root:n.source_workspace_root,repo_root:n.repo_root,pm_root_rel:n.pm_root_rel,result:e})}async function he(e){const t=s(),o=t?t.commands:l;return o?w(o,{...e,...x(e.pm_root)}):{handled:!1,result:null,warnings:[]}}async function Ae(e){const t=s(),o=t?t.parsers:m;return o?P(o,{...e,...x(e.pm_root)}):{overridden:!1,context:{command:e.command,args:[...e.args],options:{...e.options},global:{...e.global},pm_root:e.pm_root},warnings:[]}}async function Ce(e){const t=s(),o=t?t.preflight:f;return o?W(o,{...e,...x(e.pm_root)}):{overridden:!1,context:{command:e.command,args:[...e.args],options:{...e.options},global:{...e.global},pm_root:e.pm_root},decision:{...e.decision},warnings:[]}}function ke(e,t){const o=s(),n=o?o.renderers:p,r=o?o.commandContext:u;return n?T(n,{format:e,command:r?.command,args:r?[...r.args]:[],options:r?.options?{...r.options}:{},global:r?.global?{...r.global}:void 0,pm_root:r?.pm_root,source_workspace_root:r?.source_workspace_root,repo_root:r?.repo_root,pm_root_rel:r?.pm_root_rel,result:t}):{overridden:!1,rendered:null,warnings:[]}}function R(e,t){const o=s(),n=o?o.commandContext:u;return{service:e,command:n?.command,args:n?[...n.args]:[],options:n?.options?{...n.options}:{},global:n?.global?{...n.global}:void 0,pm_root:n?.pm_root,source_workspace_root:n?.source_workspace_root,repo_root:n?.repo_root,pm_root_rel:n?.pm_root_rel,payload:t}}async function Oe(e,t){const o=s(),n=o?o.services:d;return n?j(n,R(e,t)):{handled:!1,result:t,warnings:[]}}function Re(e,t){const o=s(),n=o?o.services:d;return n?N(n,R(e,t)):{handled:!1,result:t,warnings:[]}}export*from"./loader.js";export*from"./command-hook-context.js";import{createSerialQueue as Ie}from"../shared/serial-queue.js";import{EXTENSION_CAPABILITY_REGISTRATION_SURFACES as He,collectUsedExtensionCapabilities as Pe,reconcileExtensionCapabilityUsage as We}from"./capability-usage.js";export{He as EXTENSION_CAPABILITY_REGISTRATION_SURFACES,le as clearActiveExtensionHooks,Pe as collectUsedExtensionCapabilities,ue as consumeAfterCommandAffectedItems,Ie as createSerialQueue,ne as getActiveCommandContext,ie as getActiveCommandResult,B as getActiveExtensionHooks,ee as getActiveExtensionRegistrations,_e as hasActiveOnReadHooks,ve as hasActiveOnWriteHooks,re as isActiveCommandUnextended,ae as projectAfterCommandItemSnapshot,We as reconcileExtensionCapabilityUsage,ce as recordAfterCommandAffectedItem,te as resetActiveExtensionRuntimeState,x as resolvePortableWorkspaceContext,fe as runActiveBeforeMutationHooks,he as runActiveCommandHandler,xe as runActiveCommandOverride,ge as runActiveOnIndexHooks,pe as runActiveOnReadHooks,de as runActiveOnWriteHooks,Ae as runActiveParserOverride,Ce as runActivePreflightOverride,ke as runActiveRendererOverride,Oe as runActiveServiceOverride,Re as runActiveServiceOverrideSync,X as runWithIsolatedExtensionRuntime,me as runWithPreviewMutationGuards,oe as setActiveCommandContext,se as setActiveCommandResult,$ as setActiveExtensionCommands,Y as setActiveExtensionHooks,q as setActiveExtensionParsers,z as setActiveExtensionPreflight,Z as setActiveExtensionRegistrations,V as setActiveExtensionRenderers,J as setActiveExtensionServices};
1
+ import{existsSync as S,realpathSync as w}from"node:fs";import{AsyncLocalStorage as k}from"node:async_hooks";import c from"node:path";import{ownedTransactionCompensation as R}from"../store/item-mutation-precondition.js";import{runCommandHandler as I,runBeforeMutationHooks as y,runCommandOverride as H,runOnIndexHooks as P,runParserOverride as T,runPreflightOverride as W,runOnReadHooks as M,runRendererOverride as j,runServiceOverride as D,runServiceOverrideSync as G,runOnWriteHooks as N}from"./loader.js";let a=null,d=null,p=null,v=null,f=null,g=null,_=null,l=null,h,A=[];const O=new k;function s(){return O.getStore()}function Z(e){return O.run({hooks:null,commands:null,parsers:null,preflight:null,services:null,renderers:null,registrations:null,commandContext:null,commandResult:void 0,affectedItems:[]},e)}const L=new Set(["body","comments","dependencies","docs","events","files","learnings","notes","reminders","test_runs","tests"]);function m(e){try{return w.native(e)}catch{return}}function U(e){const t=e.split(c.sep).join("/");return t.endsWith("/")?t.slice(0,-1):t}function $(e){const t={resolved:new Set,spelled:new Set};let n=!0;for(const o of(e.GIT_CEILING_DIRECTORIES??"").split(c.delimiter))if(o.length===0)n=!1;else if(c.isAbsolute(o))if(!n)t.spelled.add(o.endsWith("/")?o.slice(0,-1):o);else{const r=m(o);r!==void 0&&t.resolved.add(r)}else continue;return t}function B(e,t){return e.resolved.has(t)||e.spelled.has(U(t))}function F(e,t){for(let n=e;;n=c.dirname(n)){if(m(n)===t)return n;if(c.dirname(n)===n)return t}}function K(e,t){const n=c.resolve(e),o=c.isAbsolute(e)?e:`${process.cwd()}${c.sep}${e}`,r=m(o);let i=r??n;for(;;){if(S(c.join(i,".git"))){const x=F(n,i);return{source:x,repo:x}}const u=c.dirname(i);if(u===i||B(t,u))return{source:r===void 0||m(n)===r?n:r};i=u}}function Q(e,t){const n=m(e),o=m(t);return n!==void 0&&o!==void 0?c.relative(n,o):c.relative(e,c.resolve(t))}function C(e){const t=process.env.PM_SOURCE_WORKSPACE_ROOT?.trim()||process.cwd(),{source:n,repo:o}=K(t,$(process.env));if(!e)return{source_workspace_root:n,...o?{repo_root:o}:{}};const r=Q(n,e),i=r.length>0&&!r.startsWith(`..${c.sep}`)&&r!==".."&&!c.isAbsolute(r);return{source_workspace_root:n,...o?{repo_root:o}:{},...i?{pm_root_rel:r.split(c.sep).join("/")}:{}}}function ee(e){const t=s();if(t){t.hooks=e;return}a=e}function te(e){const t=s();if(t){t.commands=e;return}d=e}function ne(e){const t=s();if(t){t.parsers=e;return}p=e}function oe(e){const t=s();if(t){t.preflight=e;return}v=e}function re(e){const t=s();if(t){t.services=e;return}f=e}function se(e){const t=s();if(t){t.renderers=e;return}g=e}function ie(e){const t=s();if(t){t.registrations=e;return}_=e}function ce(){const e=s();return e?e.registrations:_}function ae(){const e=s();if(e){e.hooks=null,e.commands=null,e.parsers=null,e.preflight=null,e.services=null,e.renderers=null,e.registrations=null,e.commandContext=null,e.commandResult=null,e.affectedItems=[];return}a=null,d=null,p=null,v=null,f=null,g=null,_=null,l=null,h=null}function le(e){const t=e?{...e,...C(e.pm_root)}:null,n=s();if(n){n.commandContext=t;return}l=t}function ue(){const e=s(),t=e?e.commandContext:l;return t?{...t,args:[...t.args],options:t.options?{...t.options}:{},global:t.global?{...t.global}:void 0}:null}function de(e){const t=s()??{commandContext:l,hooks:a,commands:d,parsers:p,preflight:v,services:f,renderers:g,registrations:_};return t.commandContext?.command!==e||[t.hooks,t.preflight,t.services,t.renderers].some(r=>Object.values(r??{}).some(i=>i.length>0))||[t.commands,t.parsers].some(r=>Object.values(r??{}).some(i=>i.some(u=>u.command===e)))?!1:!Object.entries(t.registrations??{}).some(([r,i])=>["migrations","search_providers","vector_store_adapters","assurance_providers"].includes(r)&&i.length>0)}function fe(e){const t=s();if(t){t.commandResult=e;return}h=e}function me(){const e=s();return e?e.commandResult:h}function pe(e){if(!e)return;const t=s();t?t.affectedItems.push(e):A.push(e)}function ve(e,t){if(!e||!e.id)return{};const n={id:e.id,type:e.type,status:e.status};if(!Array.isArray(t))return n;const o=e;for(const r of t){if(typeof r!="string")continue;const i=r.startsWith("unset:")?r.slice(6):r;i==="id"||i==="type"||i==="status"||L.has(i)||Object.hasOwn(o,i)&&o[i]!==void 0&&(n[i]=o[i])}return n}function ge(){const e=s(),t=e?.affectedItems??A;if(t.length===0)return;const n=t;return e?e.affectedItems=[]:A=[],n}function _e(){const e=s();if(e){e.hooks=null,e.commands=null,e.parsers=null,e.preflight=null,e.services=null,e.renderers=null,e.registrations=null,e.commandContext=null,e.commandResult=void 0,e.affectedItems=[];return}a=null,d=null,p=null,v=null,f=null,g=null,_=null,l=null,h=void 0,A=[]}async function xe(e){const t=s(),n=t?t.hooks:a;return n?N(n,e):[]}const b=new k;function he(e,t){return!e||(e.beforeMutation?.length??0)===0?t():b.run(e,t)}function X(){const e=s();return e?e.hooks:a}async function Ae(e){const t=b.getStore(),n=t??X();if(!n)return;const{resolveMutationActor:o}=await import("./mutation-actor.js"),r=t!==void 0||e.dry_run===!0,i=r?void 0:R(e.pm_root,[e.before?.metadata.id,e.after?.metadata.id],e.operation),u=await y(n,{pm_root:e.pm_root,operation:e.operation,before:e.before,after:e.after,changed_fields:e.changed_fields,sdk:e.sdk,actor:o(e.author),dry_run:r,...i===void 0?{}:{compensation:{transaction_id:i.transaction_id,step_id:i.step_id}}});i?.overrides.push(...u.map(x=>({source:"mutation_guard",...x})))}async function Ce(e){const t=s(),n=t?t.hooks:a;return n?M(n,e):[]}function ke(){const e=s();return((e?e.hooks:a)?.onWrite?.length??0)>0}function Oe(){const e=s();return((e?e.hooks:a)?.onRead?.length??0)>0}async function be(e){const t=s(),n=t?t.hooks:a;return n?P(n,e):[]}function Ee(e){const t=s(),n=t?t.commands:d,o=t?t.commandContext:l;return!n||!o?{overridden:!1,result:e,warnings:[]}:H(n,{command:o.command,args:[...o.args],options:o.options?{...o.options}:{},global:o.global?{...o.global}:void 0,pm_root:o.pm_root,source_workspace_root:o.source_workspace_root,repo_root:o.repo_root,pm_root_rel:o.pm_root_rel,result:e})}async function Se(e){const t=s(),n=t?t.commands:d;return n?I(n,{...e,...C(e.pm_root)}):{handled:!1,result:null,warnings:[]}}async function we(e){const t=s(),n=t?t.parsers:p;return n?T(n,{...e,...C(e.pm_root)}):{overridden:!1,context:{command:e.command,args:[...e.args],options:{...e.options},global:{...e.global},pm_root:e.pm_root},warnings:[]}}async function Re(e){const t=s(),n=t?t.preflight:v;return n?W(n,{...e,...C(e.pm_root)}):{overridden:!1,context:{command:e.command,args:[...e.args],options:{...e.options},global:{...e.global},pm_root:e.pm_root},decision:{...e.decision},warnings:[]}}function Ie(e,t){const n=s(),o=n?n.renderers:g,r=n?n.commandContext:l;return o?j(o,{format:e,command:r?.command,args:r?[...r.args]:[],options:r?.options?{...r.options}:{},global:r?.global?{...r.global}:void 0,pm_root:r?.pm_root,source_workspace_root:r?.source_workspace_root,repo_root:r?.repo_root,pm_root_rel:r?.pm_root_rel,result:t}):{overridden:!1,rendered:null,warnings:[]}}function E(e,t){const n=s(),o=n?n.commandContext:l;return{service:e,command:o?.command,args:o?[...o.args]:[],options:o?.options?{...o.options}:{},global:o?.global?{...o.global}:void 0,pm_root:o?.pm_root,source_workspace_root:o?.source_workspace_root,repo_root:o?.repo_root,pm_root_rel:o?.pm_root_rel,payload:t}}async function ye(e,t){const n=s(),o=n?n.services:f;return o?D(o,E(e,t)):{handled:!1,result:t,warnings:[]}}function He(e,t){const n=s(),o=n?n.services:f;return o?G(o,E(e,t)):{handled:!1,result:t,warnings:[]}}export*from"./loader.js";export*from"./command-hook-context.js";import{createSerialQueue as je}from"../shared/serial-queue.js";import{EXTENSION_CAPABILITY_REGISTRATION_SURFACES as Ge,collectUsedExtensionCapabilities as Ne,reconcileExtensionCapabilityUsage as Le}from"./capability-usage.js";export{Ge as EXTENSION_CAPABILITY_REGISTRATION_SURFACES,_e as clearActiveExtensionHooks,Ne as collectUsedExtensionCapabilities,ge as consumeAfterCommandAffectedItems,je as createSerialQueue,ue as getActiveCommandContext,me as getActiveCommandResult,X as getActiveExtensionHooks,ce as getActiveExtensionRegistrations,Oe as hasActiveOnReadHooks,ke as hasActiveOnWriteHooks,de as isActiveCommandUnextended,ve as projectAfterCommandItemSnapshot,Le as reconcileExtensionCapabilityUsage,pe as recordAfterCommandAffectedItem,ae as resetActiveExtensionRuntimeState,C as resolvePortableWorkspaceContext,Ae as runActiveBeforeMutationHooks,Se as runActiveCommandHandler,Ee as runActiveCommandOverride,be as runActiveOnIndexHooks,Ce as runActiveOnReadHooks,xe as runActiveOnWriteHooks,we as runActiveParserOverride,Re as runActivePreflightOverride,Ie as runActiveRendererOverride,ye as runActiveServiceOverride,He as runActiveServiceOverrideSync,Z as runWithIsolatedExtensionRuntime,he as runWithPreviewMutationGuards,le as setActiveCommandContext,fe as setActiveCommandResult,te as setActiveExtensionCommands,ee as setActiveExtensionHooks,ne as setActiveExtensionParsers,oe as setActiveExtensionPreflight,ie as setActiveExtensionRegistrations,se as setActiveExtensionRenderers,re as setActiveExtensionServices};
2
2
  //# sourceMappingURL=index.js.map
@@ -6,6 +6,13 @@
6
6
  import type{ExtensionRegistrationRegistry}from "./loader.js";import{type PmCliErrorContext}from "../shared/errors.js";
7
7
  /** Item metadata keys extension-provided fields may never shadow, exposed without mutation methods. */
8
8
  export declare const RESERVED_ITEM_FIELD_NAMES:ReadonlySet<string>;
9
+ /**
10
+ * Activation warning for an extension item field named after built-in item
11
+ * metadata (pm-dhlij3). Activation drops only that field, so the package's
12
+ * other fields and every create and update keep working; package doctor and
13
+ * health carry this warning, which names the package, the field and a rename.
14
+ */
15
+ export declare function formatReservedItemFieldWarning(layer:string,extension:string,field:string):string;
9
16
  /** Implements collect registered item field names for the public runtime surface of this module. */
10
17
  export declare function collectRegisteredItemFieldNames(registrations:ExtensionRegistrationRegistry|null):string[];
11
18
  /**
@@ -16,4 +23,11 @@ export declare function collectRegisteredItemFieldNames(registrations:ExtensionR
16
23
  */
17
24
  export declare function parseRegisteredItemFieldAssignments(rawFields:string[]|undefined,registrations:ExtensionRegistrationRegistry|null,resolveCoreFieldRecovery?:(field:string)=> Pick<PmCliErrorContext,"recovery"|"nextSteps">,resolveSchemaFieldRecovery?:(field:string)=> Pick<PmCliErrorContext,"recovery"|"nextSteps">|undefined):Record<string,unknown>;
18
25
  /** Implements apply registered item field defaults and validation for the public runtime surface of this module. */
19
- export declare function applyRegisteredItemFieldDefaultsAndValidation(itemMetadata:Record<string,unknown>,registrations:ExtensionRegistrationRegistry|null,options?:{skipDefaultFields?:ReadonlySet<string>;}):void;
26
+ export declare function applyRegisteredItemFieldDefaultsAndValidation(itemMetadata:Record<string,unknown>,registrations:ExtensionRegistrationRegistry|null,options?:{skipDefaultFields?:ReadonlySet<string>;}):void;
27
+ /**
28
+ * Apply extension field defaults and validation for a create or update write.
29
+ * A typed refusal, such as conflicting field types across packages, keeps its
30
+ * code (pm-dhlij3); a value that fails its declared type or allowed values
31
+ * becomes a usage refusal.
32
+ */
33
+ export declare function applyRegisteredItemFieldDefaultsForWrite(itemMetadata:Record<string,unknown>,registrations:ExtensionRegistrationRegistry|null,options?:{skipDefaultFields?:ReadonlySet<string>;}):void;
@@ -1,2 +1,2 @@
1
- import{normalizeItemFieldType as _}from"./item-field-types.js";import{EXIT_CODE as f,ITEM_METADATA_KEY_ORDER as A}from"../shared/constants.js";import{PmCliError as l}from"../shared/errors.js";const c=new Set(A),u=Object.freeze({get size(){return c.size},has(e){return c.has(e)},entries(){return c.entries()},keys(){return c.keys()},values(){return c.values()},forEach(e,t){c.forEach(n=>e.call(t,n,n,u))},[Symbol.iterator](){return c.values()}});function h(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function y(e){return typeof e!="string"?null:_(e)}function w(e){try{return structuredClone(e)}catch{return e}}function E(e){const t=e.trim(),n=t.indexOf("=");if(n<=0)throw new l(`--field entries must use name=value syntax, received: ${e}`,f.USAGE);const i=t.slice(0,n).trim(),r=t.slice(n+1);return{key:i,value:r}}function b(e,t,n){try{const i=JSON.parse(e);if(n==="array"&&Array.isArray(i)||n==="object"&&typeof i=="object"&&i!==null&&!Array.isArray(i))return i}catch{}throw new l(`--field ${t}=... must be valid JSON ${n}`,f.USAGE)}function x(e,t,n){if(t==="string")return n;if(t==="number"){const i=n.trim();if(i.length===0)throw new l(`--field ${e}=... must be a number`,f.USAGE);const r=Number(i);if(!Number.isFinite(r))throw new l(`--field ${e}=... must be a number`,f.USAGE);return r}if(t==="boolean"){const i=n.trim().toLowerCase();if(i==="true"||i==="1"||i==="yes")return!0;if(i==="false"||i==="0"||i==="no")return!1;throw new l(`--field ${e}=... must be one of true|false|1|0|yes|no`,f.USAGE)}return t==="string_array"?n.split(/[\n,|]/u).map(i=>i.trim()).filter(i=>i.length>0):b(n,e,t)}function p(e){const t=new Map;if(!e)return t;for(const n of e.item_fields)for(const i of n.fields){const r=h(i.name),o=y(i.type);if(!r||!o)continue;const s=t.get(r);if(s&&s.type!==o)throw new l(`Extension item field "${r}" is declared with conflicting types: ${s.type}, ${o}`,f.USAGE,{code:"extension_item_field_type_conflict",nextSteps:["Make every active extension declaration for this field use the same type."]});t.set(r,{name:r,type:o})}return t}function g(e){if(u.has(e))throw new l(`Extension item field "${e}" collides with built-in item metadata "${e}"; rename the extension field with an extension-specific prefix. Reserved fields: ${[...u].sort((t,n)=>t.localeCompare(n)).join(", ")}.`,f.USAGE,{code:"extension_item_field_reserved",nextSteps:["Rename the extension item field, preferably with an extension-specific prefix."]})}function U(e){return[...p(e).keys()].sort((t,n)=>t.localeCompare(n))}function j(e,t,n,i){if(!e||e.length===0)return{};const r=p(t),o={};for(const s of e){const{key:a,value:m}=E(s),d=r.get(a);if(!d)throw $(a,r,n,i);g(d.name),o[d.name]=x(d.name,d.type,m)}return o}function $(e,t,n,i){if(u.has(e)){const s=n?.(e)??{recovery:{provided_fields:[e]},nextSteps:["Core metadata has no generic --field mutation path. Use the owning lifecycle, evidence, or importer API; inspect pm update <id> --help for declared mutation flags."]};return new l(`--field ${e} is a core item field, not an extension field`,f.USAGE,{code:"core_item_field_requires_dedicated_flag",field:e,...s})}const r=i?.(e);if(r!==void 0){const s=r.recovery?.suggested_flags?.[0];return new l(s===void 0?`--field ${e} is a project-schema field, not an extension field`:`--field ${e} is a project-schema field; set it with its declared flag ${s}`,f.USAGE,{code:"project_schema_field_requires_declared_flag",field:e,changed:!1,...r})}const o=[...t.keys()].sort((s,a)=>s.localeCompare(a));return new l(`--field ${e} is not declared by an active extension item-field registration`,f.USAGE,{code:"extension_item_field_unknown",field:e,recovery:{provided_fields:[e]},nextSteps:o.length>0?[`Use one of the declared fields: ${o.join(", ")}`]:["Activate an extension that calls registerItemFields before setting extension fields."]})}function S(e,t){return t==="string"?typeof e=="string":t==="number"?typeof e=="number"&&Number.isFinite(e):t==="boolean"?typeof e=="boolean":t==="array"?Array.isArray(e):t==="string_array"?Array.isArray(e)&&e.every(n=>typeof n=="string"):typeof e=="object"&&e!==null&&!Array.isArray(e)}function F(e,t){return!t||t.length===0?!0:t.some(n=>Object.is(n,e))}function G(e,t,n={}){if(t){p(t);for(const i of t.item_fields)for(const r of i.fields){const o=h(r.name);if(!o)continue;g(o),!(o in e)&&!n.skipDefaultFields?.has(o)&&Object.prototype.hasOwnProperty.call(r,"default")&&(e[o]=w(r.default));const s=e[o];if(s===void 0)continue;const a=y(r.type);if(a&&!S(s,a))throw new TypeError(`Item field "${o}" must be of type ${a}`);const m=Array.isArray(r.values)?r.values:void 0;if(!F(s,m))throw new TypeError(`Item field "${o}" must match one of the configured allowed values`)}}}export{u as RESERVED_ITEM_FIELD_NAMES,G as applyRegisteredItemFieldDefaultsAndValidation,U as collectRegisteredItemFieldNames,j as parseRegisteredItemFieldAssignments};
1
+ import{normalizeItemFieldType as _}from"./item-field-types.js";import{EXIT_CODE as l,ITEM_METADATA_KEY_ORDER as A}from"../shared/constants.js";import{PmCliError as f}from"../shared/errors.js";const c=new Set(A),u=Object.freeze({get size(){return c.size},has(e){return c.has(e)},entries(){return c.entries()},keys(){return c.keys()},values(){return c.values()},forEach(e,t){c.forEach(n=>e.call(t,n,n,u))},[Symbol.iterator](){return c.values()}});function h(e){if(typeof e!="string")return null;const t=e.trim();return t.length>0?t:null}function g(e){return typeof e!="string"?null:_(e)}function w(e){try{return structuredClone(e)}catch{return e}}function E(e){const t=e.trim(),n=t.indexOf("=");if(n<=0)throw new f(`--field entries must use name=value syntax, received: ${e}`,l.USAGE);const r=t.slice(0,n).trim(),i=t.slice(n+1);return{key:r,value:i}}function b(e,t,n){try{const r=JSON.parse(e);if(n==="array"&&Array.isArray(r)||n==="object"&&typeof r=="object"&&r!==null&&!Array.isArray(r))return r}catch{}throw new f(`--field ${t}=... must be valid JSON ${n}`,l.USAGE)}function x(e,t,n){if(t==="string")return n;if(t==="number"){const r=n.trim();if(r.length===0)throw new f(`--field ${e}=... must be a number`,l.USAGE);const i=Number(r);if(!Number.isFinite(i))throw new f(`--field ${e}=... must be a number`,l.USAGE);return i}if(t==="boolean"){const r=n.trim().toLowerCase();if(r==="true"||r==="1"||r==="yes")return!0;if(r==="false"||r==="0"||r==="no")return!1;throw new f(`--field ${e}=... must be one of true|false|1|0|yes|no`,l.USAGE)}return t==="string_array"?n.split(/[\n,|]/u).map(r=>r.trim()).filter(r=>r.length>0):b(n,e,t)}function p(e){const t=new Map;if(!e)return t;for(const n of e.item_fields)for(const r of n.fields){const i=h(r.name),o=g(r.type);if(!i||!o)continue;const s=t.get(i);if(s&&s.type!==o)throw new f(`Extension item field "${i}" is declared with conflicting types: ${s.type}, ${o}`,l.USAGE,{code:"extension_item_field_type_conflict",nextSteps:["Make every active extension declaration for this field use the same type."]});t.set(i,{name:i,type:o})}return t}function y(e){if(u.has(e))throw new f(`Extension item field "${e}" collides with built-in item metadata "${e}"; rename the extension field with an extension-specific prefix. Reserved fields: ${[...u].sort((t,n)=>t.localeCompare(n)).join(", ")}.`,l.USAGE,{code:"extension_item_field_reserved",nextSteps:["Rename the extension item field, preferably with an extension-specific prefix."]})}function G(e,t,n){const r=t.replace(/^@[^/]+\//u,"").replaceAll(/[^A-Za-z0-9]+/gu,"_").toLowerCase();return`extension_item_field_reserved:${e}:${t}:${n}:rename=${r}_${n}`}function j(e){return[...p(e).keys()].sort((t,n)=>t.localeCompare(n))}function z(e,t,n,r){if(!e||e.length===0)return{};const i=p(t),o={};for(const s of e){const{key:a,value:m}=E(s),d=i.get(a);if(!d)throw $(a,i,n,r);y(d.name),o[d.name]=x(d.name,d.type,m)}return o}function $(e,t,n,r){if(u.has(e)){const s=n?.(e)??{recovery:{provided_fields:[e]},nextSteps:["Core metadata has no generic --field mutation path. Use the owning lifecycle, evidence, or importer API; inspect pm update <id> --help for declared mutation flags."]};return new f(`--field ${e} is a core item field, not an extension field`,l.USAGE,{code:"core_item_field_requires_dedicated_flag",field:e,...s})}const i=r?.(e);if(i!==void 0){const s=i.recovery?.suggested_flags?.[0];return new f(s===void 0?`--field ${e} is a project-schema field, not an extension field`:`--field ${e} is a project-schema field; set it with its declared flag ${s}`,l.USAGE,{code:"project_schema_field_requires_declared_flag",field:e,changed:!1,...i})}const o=[...t.keys()].sort((s,a)=>s.localeCompare(a));return new f(`--field ${e} is not declared by an active extension item-field registration`,l.USAGE,{code:"extension_item_field_unknown",field:e,recovery:{provided_fields:[e]},nextSteps:o.length>0?[`Use one of the declared fields: ${o.join(", ")}`]:["Activate an extension that calls registerItemFields before setting extension fields."]})}function F(e,t){return t==="string"?typeof e=="string":t==="number"?typeof e=="number"&&Number.isFinite(e):t==="boolean"?typeof e=="boolean":t==="array"?Array.isArray(e):t==="string_array"?Array.isArray(e)&&e.every(n=>typeof n=="string"):typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e,t){return!t||t.length===0?!0:t.some(n=>Object.is(n,e))}function I(e,t,n={}){if(t){p(t);for(const r of t.item_fields)for(const i of r.fields){const o=h(i.name);if(!o)continue;y(o),!(o in e)&&!n.skipDefaultFields?.has(o)&&Object.prototype.hasOwnProperty.call(i,"default")&&(e[o]=w(i.default));const s=e[o];if(s===void 0)continue;const a=g(i.type);if(a&&!F(s,a))throw new TypeError(`Item field "${o}" must be of type ${a}`);const m=Array.isArray(i.values)?i.values:void 0;if(!S(s,m))throw new TypeError(`Item field "${o}" must match one of the configured allowed values`)}}}function C(e,t,n={}){try{I(e,t,n)}catch(r){throw r instanceof f?r:new f(r.message,l.USAGE)}}export{u as RESERVED_ITEM_FIELD_NAMES,I as applyRegisteredItemFieldDefaultsAndValidation,C as applyRegisteredItemFieldDefaultsForWrite,j as collectRegisteredItemFieldNames,G as formatReservedItemFieldWarning,z as parseRegisteredItemFieldAssignments};
2
2
  //# sourceMappingURL=item-fields.js.map
@@ -1,2 +1,2 @@
1
- import w from"node:fs/promises";import x from"node:path";import{pathToFileURL as xe}from"node:url";import{createRelationshipKindRegistry as Ee}from"../../sdk/relationships.js";import{pathExists as H}from"../fs/fs-utils.js";import{isPathWithinDirectory as L}from"../fs/path-utils.js";import{isHostOutputSuppressed as be,suppressHostOutput as Ce}from"../output/output-control.js";import{resolvePmPackageRootFromModule as Re}from"../packages/root.js";import{asRecordLoose as B,resolveActivatablePropertyRecord as ke}from"../shared/primitives.js";import{resolveGlobalPmRoot as $e}from"../store/paths.js";import{captureExtensionActivationRollback as Pe}from"./activation-transaction.js";import{assertCommandDefinitionMetadataStrings as Se}from"./command-visibility-tier.js";import{normalizeExtensionReadOutput as Ie}from"./read-output-contract.js";import{normalizeExtensionContributionInventory as Me}from"./contribution-inventory.js";import{buildImportExportContext as U,resolveImportExportArtifactOutput as Ae}from"./exporter-output-contract.js";import{buildReadyExtensionCandidate as Te}from"./extension-candidate.js";import{collectUnknownExtensionCapabilities as De,formatLegacyExtensionCapabilityAliasWarning as Fe,formatUnknownExtensionCapabilityWarning as Oe,isKnownExtensionCapability as ze,normalizeNames as K}from"./extension-capability-aliases.js";import{evaluateExtensionPolicyForCapability as We,evaluateExtensionPolicyForExtension as je,evaluateExtensionPolicyForRegistration as Ne,hydrateExtensionPolicy as Ve,normalizeExtensionPolicy as qe,serializeExtensionPolicy as He}from"./extension-policy.js";import{createEmptyExtensionCommandRegistry as Le,createEmptyExtensionHookRegistry as Be,createEmptyExtensionParserRegistry as Ue,createEmptyExtensionPreflightRegistry as Ke,createEmptyExtensionRegistrationRegistry as Xe,createEmptyExtensionRendererRegistry as Ge,createEmptyExtensionServiceRegistry as Je}from"./extension-registries.js";import{normalizeCommandName as b}from"./extension-runtime-helpers.js";import{KNOWN_EXTENSION_CAPABILITIES as Ye,KNOWN_EXTENSION_SERVICE_NAMES as Qe,createDefaultExtensionGovernancePolicy as Ze}from"./extension-types.js";import{parseExtensionManifestDocument as X}from"./manifest-parser.js";import{formatExtensionManifestSchemaWarnings as er}from"./manifest-schema.js";import{snapshotExtensionModuleGraph as rr}from"./module-graph-snapshot.js";import{collectPreflightCollisionWarnings as tr,normalizePreflightOverride as nr}from"./preflight-ownership.js";import{applyProjectProfileDefaults as ir,assertFlagValueTypeAndDefault as sr,normalizeCommandDefinitionArguments as T,normalizeFlagDefinitions as D,resolveCommandDefinitionAction as F,validateFlagDefinitions as O,validateItemFieldDefinitions as G,validateItemTypeDefinitions as or,validateMigrationDefinition as ar,validateProjectProfileDefinition as mr}from"./registration-contracts.js";import{assertOptionalStringField as $,normalizeOptionalStringArrayField as C}from"./registration-validation.js";import{assertHookHandler as E,assertNonEmptyRegistrationString as P,assertRegistrationFunction as S,attachRuntimeDefinition as I,cloneRuntimeRegistrationValue as cr,createRegistrationValidationError as y,extractRegistrationValidationTrace as J,isExtensionServiceName as lr,isOutputRendererFormat as dr,normalizeRegistrationName as Y,normalizeRegistrationRecord as R,normalizeRegistrationRecordList as z,normalizeRuntimeRegistrationRecord as k,sanitizeRegistrationValue as Q,toRegistrationCommandPath as Z,validateAssuranceMeasurementProviderDefinition as ur}from"./registration-values.js";import{normalizeServiceOverrideOwnership as hr}from"./service-ownership.js";import{compareComparableVersions as pr,evaluatePmMaxVersionBound as fr,evaluatePmMinVersionBound as gr,parseComparableVersion as yr}from"./version-compat.js";import{parseLegacyExtensionCapabilityAliasWarning as wt,parseUnknownExtensionCapabilityWarning as xt}from"./extension-capability-aliases.js";import{createEmptyExtensionCommandRegistry as bt,createEmptyExtensionHookRegistry as Ct,createEmptyExtensionParserRegistry as Rt,createEmptyExtensionPreflightRegistry as kt,createEmptyExtensionRegistrationRegistry as $t,createEmptyExtensionRendererRegistry as Pt,createEmptyExtensionServiceRegistry as St}from"./extension-registries.js";import{runAfterCommandHooks as Mt,runBeforeCommandHooks as At,runBeforeMutationHooks as Tt,runCommandHandler as Dt,runCommandOverride as Ft,runOnIndexHooks as Ot,runOnReadHooks as zt,runOnWriteHooks as Wt,runParserOverride as jt,runPreflightOverride as Nt,runRendererOverride as Vt,runServiceOverride as qt,runServiceOverrideSync as Ht}from"./extension-hook-runtime.js";export*from"./extension-types.js";import{DEFAULT_EXTENSION_PRIORITY as Ut,parseExtensionManifestDocument as Kt}from"./manifest-parser.js";let W=null;const _r=Object.freeze(Ze());let ee=0;function vr(r=Date.now()){return ee+=1,`${ee}-${r}`}function wr(r,e,t){return t.has(r)?!1:e.size===0?!0:e.has(r)}async function xr(r,e){const[t,n]=await Promise.all([w.realpath(r),w.realpath(e)]);return L(t,n)}function Er(r,e=process.cwd()){return{global:x.join($e(e),"extensions"),project:x.join(r,"extensions")}}async function br(r){try{return(await w.readdir(r,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,n)=>t.localeCompare(n))}catch{return[]}}function Cr(r){const e={layer:r.layer,directory:r.directory,manifest_path:r.manifest_path,name:r.manifest.name,version:r.manifest.version,entry:r.manifest.entry,priority:r.manifest.priority,entry_path:r.entry_path,manifest_version:r.manifest.manifest_version,pm_min_version:r.manifest.pm_min_version,pm_max_version:r.manifest.pm_max_version,engines:r.manifest.engines,trusted:r.manifest.trusted,provenance:r.manifest.provenance,sandbox_profile:r.manifest.sandbox_profile,permissions:r.manifest.permissions,capabilities:[...r.manifest.capabilities],activation:r.manifest.activation?{commands:[...r.manifest.activation.commands]}:void 0,contributions:r.manifest.contributions??r.contributions};return r.source_package&&(e.source_package=r.source_package),r.source_aliases&&(e.source_aliases=[...r.source_aliases]),e}function re(r){return typeof r=="string"&&r.trim().length>0?r.trim():void 0}async function te(r){const e=new Map;try{const t=JSON.parse(await w.readFile(x.join(r,".managed-extensions.json"),"utf8")),i=B(t)?.entries;if(!Array.isArray(i))return e;for(const o of i){if(typeof o!="object"||o===null)continue;const s=o,a=re(s.source?.package),m=[s.source?.input,s.source?.name,a].map(d=>re(d)).filter(d=>d!==void 0),c=Me(s.contributions),l={aliases:[...new Set(m)],...a?{package_name:a}:{},...c?{contributions:c}:{}};typeof s.directory=="string"&&s.directory.trim().length>0&&e.set(`directory:${s.directory.trim()}`,l),typeof s.name=="string"&&s.name.trim().length>0&&e.set(`name:${s.name.trim()}`,l)}}catch{return e}return e}function ne(r){return[...r].sort((e,t)=>{if(e.manifest.priority!==t.manifest.priority)return e.manifest.priority-t.manifest.priority;const n=e.manifest.name.localeCompare(t.manifest.name);return n!==0?n:e.directory.localeCompare(t.directory)})}function Rr(r,e){const t=[...ne(r),...ne(e)],n=[];for(const i of t){const o=n.findIndex(s=>s.manifest.name===i.manifest.name);o>=0&&n.splice(o,1),n.push(i)}return n}async function ie(r,e,t,n,i){const o=[],s=[],a=[],m=await br(e),c=await te(e);for(const l of m){const d=await Pr(r,e,l,t,n,c,i);o.push(d.diagnostic),s.push(...d.warnings),d.candidate&&a.push(d.candidate)}return{diagnostics:o,warnings:s,candidates:a}}function kr(){return{diagnostics:[],warnings:[],candidates:[]}}function se(r,e,t,n){return{diagnostic:{layer:r,directory:e,manifest_path:t,name:null,version:null,entry:null,priority:null,entry_path:null,enabled:null,status:"warn"},warnings:[n],candidate:null}}function $r(r,e,t,n,i,o,s,a){const m=er(r,e,t);Array.isArray(e.legacy_capability_aliases)&&e.legacy_capability_aliases.length>0&&m.push(Fe(r,e.name,e.legacy_capability_aliases));for(const c of De(e.capabilities))m.push(Oe(r,e.name,c));return n?i||m.push(`extension_entry_missing:${r}:${e.name}`):m.push(`extension_entry_outside_extension:${r}:${e.name}`),o.warning&&m.push(a?o.warning:o.warning.replace("extension_pm_","extension_disabled_pm_")),s.warning&&m.push(a?s.warning:s.warning.replace("extension_pm_","extension_disabled_pm_")),m}async function Pr(r,e,t,n,i,o,s){const a=x.join(e,t),m=x.join(a,"manifest.json");if(!await H(m))return se(r,t,m,`extension_manifest_missing:${r}:${t}`);let c,l;try{const q=JSON.parse(await w.readFile(m,"utf8"));l=B(q),c=X(q)}catch{l=null,c=null}if(!c||!l)return se(r,t,m,`extension_manifest_invalid:${r}:${t}`);const d=x.resolve(a,c.entry),h=L(a,d),u=h?await H(d):!1,f=h&&u?await xr(a,d):h,g=wr(c.name,n,i),v=await me(r,c),_=await ce(r,c,s),A=$r(r,c,l,f,u,v,_,g),V=f&&u&&v.allowed&&_.allowed,we=o.get(`directory:${t}`)??o.get(`name:${c.name}`);return{diagnostic:{layer:r,directory:t,manifest_path:m,name:c.name,version:c.version,entry:c.entry,priority:c.priority,entry_path:d,enabled:g,status:V?"ok":"warn"},warnings:A,candidate:Te({layer:r,directory:t,manifestPath:m,entryPath:d,manifest:c,sourceIdentity:we,extensionReady:V,enabledForLoad:g})}}async function Sr(r){const e=Er(r.pmRoot,r.cwd??process.cwd()),t=K(r.settings.extensions.enabled),n=K(r.settings.extensions.disabled),i=qe(r.settings),o=He(i);if(r.noExtensions)return{disabled_by_flag:!0,roots:e,configured_enabled:t,configured_disabled:n,discovered:[],effective:[],warnings:[...i.warnings],policy:o};const s=new Set(t),a=new Set(n),m=r.ignoreGlobalExtensions===!0?kr():await ie("global",e.global,s,a,i.pmMaxVersionExceededMode.global),c=await ie("project",e.project,s,a,i.pmMaxVersionExceededMode.project),l=[...i.warnings],d=Rr(m.candidates,c.candidates),h=[];for(const u of d){const f={layer:u.layer,name:u.manifest.name,trusted:u.manifest.trusted===!0,provenanceVerified:u.manifest.provenance?.verified===!0,sandboxProfile:u.manifest.sandbox_profile,permissions:u.manifest.permissions&&typeof u.manifest.permissions=="object"?{fs_read:u.manifest.permissions.fs_read,fs_write:u.manifest.permissions.fs_write,network:u.manifest.permissions.network,env_read:u.manifest.permissions.env_read,env_write:u.manifest.permissions.env_write,process_spawn:u.manifest.permissions.process_spawn}:void 0},g=je(i,f);if(g.warning&&l.push(g.warning),!!g.allowed){for(const v of u.manifest.capabilities){const _=We(i,f,v);_.warning&&l.push(_.warning)}h.push(Cr(u))}}return{disabled_by_flag:!1,roots:e,configured_enabled:t,configured_disabled:n,discovered:[...m.diagnostics,...c.diagnostics],effective:h,warnings:[...new Set([...m.warnings,...c.warnings,...l])],policy:o}}function M(r){return r instanceof Error&&r.message.trim().length>0?r.message:String(r)}async function oe(){try{const r=Re(import.meta.url,["../../.."]),e=await w.readFile(x.join(r,"package.json"),"utf8"),t=JSON.parse(e);return typeof t.version=="string"&&t.version.trim().length>0?t.version.trim():null}catch{return null}}function j(){return W??=oe(),W}function ae(r,e,t){const n=t.current??"unknown";if(t.kind==="pm_min_version")switch(t.status){case"invalid":return`extension_pm_min_version_invalid:${r}:${e.name}:required=${t.required}`;case"unchecked":return`extension_pm_min_version_unchecked:${r}:${e.name}:required=${t.required}:current=${n}`;case"unmet":return`extension_pm_min_version_unmet:${r}:${e.name}:required=${t.required}:current=${n}`;default:return}switch(t.status){case"invalid":return`extension_pm_max_version_invalid:${r}:${e.name}:allowed=${t.required}`;case"unchecked":return`extension_pm_max_version_unchecked:${r}:${e.name}:allowed=${t.required}:current=${n}`;case"exceeded_warn":return`extension_pm_max_version_exceeded_warn:${r}:${e.name}:allowed=${t.required}:current=${n}`;case"exceeded":return`extension_pm_max_version_exceeded:${r}:${e.name}:allowed=${t.required}:current=${n}`;default:return}}async function me(r,e){if(e.pm_min_version===void 0)return{allowed:!0};const t=gr(e.pm_min_version,await j()),n=ae(r,e,t);return n?{allowed:t.allowed,warning:n}:{allowed:t.allowed}}async function ce(r,e,t){if(e.pm_max_version===void 0)return{allowed:!0};const n=fr(e.pm_max_version,await j(),t),i=ae(r,e,n);return i?{allowed:n.allowed,warning:i}:{allowed:n.allowed}}async function N(r){try{const e=await w.stat(r);return`${Math.trunc(e.mtimeMs)}-${e.size}`}catch{return"missing"}}async function le(r,e){let t=r.entry_path;e.module_graph_snapshot_root&&(t=await rr(e.module_graph_snapshot_root,r));const n=new URL(xe(t).href);if(!(e.cache_bust===!0||typeof e.reload_token=="string"))return n.href;const[o,s]=await Promise.all([N(r.entry_path),N(r.manifest_path)]),a=e.reload_token??vr();return n.searchParams.set("pm_ext_reload",a),n.searchParams.set("pm_ext_entry",o),n.searchParams.set("pm_ext_manifest",s),n.href}async function pt(r){const e=await Sr(r),t=[],n=[],i=[...e.warnings];if(e.disabled_by_flag)return{...e,warnings:i,loaded:t,failed:n};const o=typeof r.extensionFilter=="function"?e.effective.filter(r.extensionFilter):e.effective;for(const s of o)try{const m=await import(await le(s,r));t.push({...s,module:m})}catch(a){i.push(`extension_load_failed:${s.layer}:${s.name}`),n.push({layer:s.layer,name:s.name,entry_path:s.entry_path,error:M(a)})}return{...e,warnings:i,loaded:t,failed:n}}const de=5e3,Ir=2147483647;function Mr(r){const t={activate:r.activate.bind(r)};if(typeof r.deactivate=="function"){const n=r.deactivate;t.deactivate=n.bind(r)}return t}function ue(r){const e=ke(r);return e?Mr(e):null}async function ft(r,e,t={}){const n=he(t?.deactivate_timeout_ms),i=new Set((e?.failed??[]).map(l=>`${l.layer}:${l.name}`)),o=[];for(const l of r.loaded){if(i.has(`${l.layer}:${l.name}`))continue;const d=ue(l.module);!d||typeof d.deactivate!="function"||o.push({extension:l,deactivate:d.deactivate})}const s=await Promise.all(o.map(async({extension:l,deactivate:d})=>{try{return await Ar(d,n),{ok:!0}}catch(h){return{ok:!1,layer:l.layer,name:l.name,error:M(h)}}})),a=[],m=[];let c=0;for(const l of s){if(l.ok){c+=1;continue}a.push(`extension_deactivate_failed:${l.layer}:${l.name}`),m.push({layer:l.layer,name:l.name,error:l.error})}return{deactivated:c,warnings:a,failed:m}}function he(r){return typeof r!="number"||r<0?de:r===0||r===1/0?0:Number.isFinite(r)?Math.min(Ir,Math.max(1,Math.floor(r))):de}async function Ar(r,e){if(e===0){await r();return}let t;try{const n=Promise.resolve().then(()=>r());n.catch(()=>{}),await Promise.race([n,new Promise((i,o)=>{t=setTimeout(()=>{o(new Error(`extension deactivate timed out after ${e}ms`))},e),t.unref?.()})])}finally{clearTimeout(t)}}function Tr(r){if(!Array.isArray(r.capabilities))return null;const e=new Set;for(const t of r.capabilities){const n=t.trim().toLowerCase();ze(n)&&e.add(n)}return e}function p(r,e,t){const n=Tr(r);if(n!==null&&!n.has(e))throw y(`${t} requires capability '${e}' in extension manifest capabilities`,{method:t,registration_index:-1,capability:e,missing_capability:e,expected_schema:`"capabilities": [..., "${e}"]`,received:r.capabilities,hint:`Add "${e}" to ${r.name} manifest capabilities, or remove the ${t} registration call.`})}function Dr(r){return Object.freeze({name:r.name,layer:r.layer,version:r.version,capabilities:Object.freeze((r.capabilities??[]).filter(e=>Ye.includes(e))),pm_min_version:r.pm_min_version,pm_max_version:r.pm_max_version,source_package:r.source_package})}function Fr(r){return{layer:r.layer,name:r.name,trusted:r.trusted===!0,provenanceVerified:r.provenance?.verified===!0,sandboxProfile:r.sandbox_profile,permissions:r.permissions&&typeof r.permissions=="object"?{fs_read:r.permissions.fs_read,fs_write:r.permissions.fs_write,network:r.permissions.network,env_read:r.permissions.env_read,env_write:r.permissions.env_write,process_spawn:r.permissions.process_spawn}:void 0}}class Or{extension;hooks;#e;#s;#t;#n;#o;#a;#m;#c;#r;#i;#l;#d;constructor(e,t,n,i,o,s,a,m,c,l,d){this.#e=e,this.extension=Dr(e),this.#s=Fr(e),this.#t=t,this.#n=n,this.#o=i,this.#a=o,this.#m=s,this.#c=a,this.#r=m,this.#i=c,this.#l=l,this.#d=d,this.registerCommand=this.registerCommand.bind(this),this.registerParser=this.registerParser.bind(this),this.registerPreflight=this.registerPreflight.bind(this),this.registerService=this.registerService.bind(this),this.registerFlags=this.registerFlags.bind(this),this.registerItemFields=this.registerItemFields.bind(this),this.registerItemTypes=this.registerItemTypes.bind(this),this.registerRelationshipKinds=this.registerRelationshipKinds.bind(this),this.registerMigration=this.registerMigration.bind(this),this.registerProfile=this.registerProfile.bind(this),this.registerRenderer=this.registerRenderer.bind(this),this.registerImporter=this.registerImporter.bind(this),this.registerExporter=this.registerExporter.bind(this),this.registerSearchProvider=this.registerSearchProvider.bind(this),this.registerVectorStoreAdapter=this.registerVectorStoreAdapter.bind(this),this.registerAssuranceMeasurementProvider=this.registerAssuranceMeasurementProvider.bind(this),this.hooks={beforeCommand:h=>this.registerBeforeCommand(h),beforeMutation:h=>this.registerBeforeMutation(h),afterCommand:h=>this.registerAfterCommand(h),onWrite:h=>this.registerOnWrite(h),onRead:h=>this.registerOnRead(h),onIndex:h=>this.registerOnIndex(h)}}allowRegistration(e,t,n,i){const o=Ne(this.#d,this.#s,e,t,n,i);return o.warning&&this.#i.push(o.warning),o.allowed}registerCommandTrace(e,t,n,i,o){return{method:"registerCommand",registration_index:e==="override"?this.#n.overrides.length:this.#n.handlers.length,command:t,expected_schema:n,received:Q(i),hint:o}}registerCommandOverride(e,t){const n=b(e);if(n.length===0)throw y("registerCommand requires a non-empty command name",this.registerCommandTrace("override",e,'registerCommand("<command>", (context) => unknown)',e,"Provide a non-empty command path as the first argument."));if(typeof t!="function"){const i=this.registerCommandTrace("override",n,'registerCommand("<command>", (context) => unknown)',t,"Provide a function as the second registerCommand argument.");throw y(`registerCommand requires an override function when command name is provided (command="${n}", registration_index=${i.registration_index})`,i)}this.allowRegistration("commands.override","registerCommand","commands",{command:n})&&this.#n.overrides.push({layer:this.#e.layer,name:this.#e.name,command:n,run:t})}resolveCommandDefinitionRunHandler(e,t){const n=typeof e.run=="function"?e.run:void 0,i=typeof e.handler=="function"?e.handler:void 0;return!n&&i&&this.#i.push(`extension_command_definition_legacy_handler_alias:${this.#e.layer}:${this.#e.name}:${t}`),n??i}registerCommandDefinition(e){if(typeof e!="object"||e===null)throw y("registerCommand requires a command definition object",this.registerCommandTrace("definition",void 0,"{ name: string; run: (context) => unknown; }",e,'Use registerCommand({ name: "command path", run: (context) => ... }).'));if(typeof e.name!="string")throw y("registerCommand requires a command definition name",this.registerCommandTrace("definition",void 0,"{ name: string; run: (context) => unknown; }",e,"Set command definition.name to a non-empty string command path."));const t=b(e.name);if(t.length===0)throw y("registerCommand requires a non-empty command definition name",this.registerCommandTrace("definition",e.name,"{ name: string; run: (context) => unknown; }",e,"Ensure command definition.name contains a non-empty command path."));const n=this.resolveCommandDefinitionRunHandler(e,t);if(typeof n!="function"){const i=this.registerCommandTrace("definition",t,"{ name: string; run: (context) => unknown; }",n,"Define command definition.run as a function.");throw y(`registerCommand requires a command definition run handler (command="${t}", registration_index=${i.registration_index})`,i)}try{Se(e);const i=F(t,e.action),o=Ie(e.read_output,t,i);if(!this.allowRegistration("commands.handler","registerCommand","commands",{command:t,action:i}))return;const s=e.description?.trim(),a=e.intent?.trim(),m=C("registerCommand definition.examples",e.examples),c=C("registerCommand definition.failure_hints",e.failure_hints),l=T(e.arguments);e.flags!==void 0&&(p(this.#e,"schema","registerCommand flags"),this.allowRegistration("schema.flags","registerCommand flags","schema")&&(O(e.flags),this.#r.flags.push({layer:this.#e.layer,name:this.#e.name,target_command:t,flags:D("registerCommand definition.flags",e.flags)})));const d={source_version:this.#e.version,read_output:o,layer:this.#e.layer,name:this.#e.name,source_package:this.#e.source_package,command:t,action:i,examples:m,failure_hints:c,arguments:l,tier:e.tier??"standard",family:e.family??"extensions"};s&&(d.description=s),a&&(d.intent=a),this.#r.commands.push(d)}catch(i){const o=M(i),s=this.registerCommandTrace("definition",t,"{ name: string; run: (context) => unknown; action?: string; arguments?: object[]; flags?: object[]; }",e,o),a=y(`registerCommand definition metadata invalid (command="${t}", registration_index=${s.registration_index}): ${o}`,s);this.#i.push(`extension_command_quarantined:${this.#e.layer}:${this.#e.name}:${t}`),this.#l.push({layer:this.#e.layer,name:this.#e.name,entry_path:this.#e.entry_path,error:a.message,trace:s});return}this.#n.handlers.push({layer:this.#e.layer,name:this.#e.name,command:t,run:n})}registerCommand(e,t){if(p(this.#e,"commands","registerCommand"),typeof e=="string"){this.registerCommandOverride(e,t);return}this.registerCommandDefinition(e)}registerParser(e,t){if(p(this.#e,"parser","registerParser"),!this.allowRegistration("parser.override","registerParser","parser"))return;const n=b(P("registerParser command",e));S("registerParser override",t),this.#o.overrides.push({layer:this.#e.layer,name:this.#e.name,command:n,run:t})}registerPreflight(e){if(p(this.#e,"preflight","registerPreflight"),!this.allowRegistration("preflight.override","registerPreflight","preflight"))return;const t=nr(e);this.#a.overrides.push({layer:this.#e.layer,name:this.#e.name,...t})}registerService(e,t,n={}){p(this.#e,"services","registerService");const i=String(e).trim().toLowerCase();if(!lr(i))throw new TypeError(`registerService service must be one of: ${Qe.join(", ")}`);this.allowRegistration("services.override","registerService","services",{service:i})&&(S("registerService override",t),this.#m.overrides.push({layer:this.#e.layer,name:this.#e.name,service:i,run:t,...hr(n)?{passThrough:!0}:{}}))}registerRenderer(e,t,n={}){if(p(this.#e,"renderers","registerRenderer"),!this.allowRegistration("renderers.override","registerRenderer","renderers"))return;if(typeof t!="function")throw new TypeError("registerRenderer requires a renderer function");const i=String(e).trim().toLowerCase();if(!dr(i))throw new Error(`registerRenderer format must be toon|json, received: ${String(e)}`);if(n.resultDiscriminator!==void 0&&typeof n.resultDiscriminator!="function")throw new TypeError("registerRenderer ownership.resultDiscriminator must be a function when provided");const o=[...new Set((n.commands??[]).map(s=>{if(typeof s!="string"||s.trim().length===0)throw new TypeError("registerRenderer ownership.commands must contain non-empty command paths");return b(s)}))];this.#c.overrides.push({layer:this.#e.layer,name:this.#e.name,format:i,run:t,commands:o,...n.resultDiscriminator?{resultDiscriminator:n.resultDiscriminator}:{}})}registerFlags(e,t){if(p(this.#e,"schema","registerFlags"),!this.allowRegistration("schema.flags","registerFlags","schema"))return;const n=b(P("registerFlags targetCommand",e));O(t);const i=D("registerFlags flags",t);if(i.length===0)throw new TypeError("registerFlags requires at least one flag definition");this.#r.flags.push({layer:this.#e.layer,name:this.#e.name,target_command:n,flags:i})}registerItemFields(e){if(p(this.#e,"schema","registerItemFields"),!this.allowRegistration("schema.itemfields","registerItemFields","schema"))return;G(e);const t=z("registerItemFields fields",e);if(t.length===0)throw new TypeError("registerItemFields requires at least one field definition");this.#r.item_fields.push({layer:this.#e.layer,name:this.#e.name,fields:t})}registerItemTypes(e){if(p(this.#e,"schema","registerItemTypes"),!this.allowRegistration("schema.itemtypes","registerItemTypes","schema"))return;or(e);const t=z("registerItemTypes types",e);if(t.length===0)throw new TypeError("registerItemTypes requires at least one type definition");this.#r.item_types.push({layer:this.#e.layer,name:this.#e.name,types:t})}registerRelationshipKinds(e){if(p(this.#e,"schema","registerRelationshipKinds"),!this.allowRegistration("schema.relationshipkinds","registerRelationshipKinds","schema"))return;if(!Array.isArray(e))throw new TypeError("registerRelationshipKinds definitions requires an array of object definitions");if(e.length===0)throw new TypeError("registerRelationshipKinds requires at least one definition");const t=Ee();for(const i of this.#r.relationship_kinds)for(const o of i.definitions)t.register(o);const n=e.map(i=>(t.register(i),t.require(i.kind)));this.#r.relationship_kinds.push({layer:this.#e.layer,name:this.#e.name,definitions:n})}registerMigration(e){if(p(this.#e,"schema","registerMigration"),!this.allowRegistration("schema.migrations","registerMigration","schema"))return;ar(e);const t=k("registerMigration definition",e);this.#r.migrations.push(I({layer:this.#e.layer,name:this.#e.name,definition:R("registerMigration definition",e)},t))}registerProfile(e){if(p(this.#e,"schema","registerProfile"),!this.allowRegistration("schema.profiles","registerProfile","schema"))return;const t=cr(e);mr(t),this.#r.profiles.push({layer:this.#e.layer,name:this.#e.name,profile:ir(t)})}registerImportExportCommandFlags(e,t,n){n.flags!==void 0&&(p(this.#e,"schema",`${e} options.flags`),this.allowRegistration("schema.flags",`${e} options.flags`,"schema")&&(O(n.flags),this.#r.flags.push({layer:this.#e.layer,name:this.#e.name,target_command:t,flags:D(`${e} options.flags`,n.flags)})))}applyImportExportCommandMetadata(e,t,n){if(n!==void 0&&(typeof n!="object"||n===null||Array.isArray(n)))throw new TypeError(`${e} options must be an object when provided`);const i=`${e==="registerImporter"?"Import":"Export"} items with the registered extension adapter.`,o=[{name:"file",required:!1,description:"Optional input or output file path."}],s={...n,description:n?.description??i,arguments:n?.arguments??o},a=Ae(e,s,n?.description!==void 0);$(`${e} options.action`,s.action),$(`${e} options.description`,s.description),$(`${e} options.intent`,s.intent);const m=F(t,s.action),c=C(`${e} options.examples`,s.examples),l=C(`${e} options.failure_hints`,s.failure_hints),d=T(s.arguments);this.registerImportExportCommandFlags(e,t,s);const h={source_version:this.#e.version,layer:this.#e.layer,name:this.#e.name,source_package:this.#e.source_package,command:t,action:m,examples:c,failure_hints:l,arguments:d},u=s.description?.trim();u&&(h.description=u);const f=s.intent?.trim();return f&&(h.intent=f),this.#r.commands.push(h),a}registerImporter(e,t,n){if(p(this.#e,"importers","registerImporter"),!this.allowRegistration("importers.importer","registerImporter","importers"))return;const i=Y(P("registerImporter name",e));S("registerImporter importer",t);const o=Z(i,"import");this.applyImportExportCommandMetadata("registerImporter",o,n),this.#r.importers.push({layer:this.#e.layer,name:this.#e.name,importer:i}),this.#n.handlers.push({layer:this.#e.layer,name:this.#e.name,command:o,run:async s=>t(U(s,i,"import"))})}registerExporter(e,t,n){if(p(this.#e,"importers","registerExporter"),!this.allowRegistration("importers.exporter","registerExporter","importers"))return;const i=Y(P("registerExporter name",e));S("registerExporter exporter",t);const o=Z(i,"export"),s=this.applyImportExportCommandMetadata("registerExporter",o,n);this.#r.exporters.push({layer:this.#e.layer,name:this.#e.name,exporter:i,...s===void 0?{}:{output:s}}),this.#n.handlers.push({layer:this.#e.layer,name:this.#e.name,command:o,run:async a=>{const m=await t(U(a,i,"export"));return s?.receipt==="suppress"&&!be(m)?Ce(m):m}})}registerSearchProvider(e){if(p(this.#e,"search","registerSearchProvider"),!this.allowRegistration("search.provider","registerSearchProvider","search"))return;const t=k("registerSearchProvider provider",e);this.#r.search_providers.push(I({layer:this.#e.layer,name:this.#e.name,definition:R("registerSearchProvider provider",e)},t))}registerVectorStoreAdapter(e){if(p(this.#e,"search","registerVectorStoreAdapter"),!this.allowRegistration("search.vectorstore","registerVectorStoreAdapter","search"))return;const t=k("registerVectorStoreAdapter adapter",e);this.#r.vector_store_adapters.push(I({layer:this.#e.layer,name:this.#e.name,definition:R("registerVectorStoreAdapter adapter",e)},t))}registerAssuranceMeasurementProvider(e){if(p(this.#e,"services","registerAssuranceMeasurementProvider"),!this.allowRegistration("services.assuranceprovider","registerAssuranceMeasurementProvider","services"))return;if(ur(e),e.network&&this.#e.permissions?.network!==!0)throw new TypeError("registerAssuranceMeasurementProvider network provider requires permissions.network=true");const t=k("registerAssuranceMeasurementProvider provider",e);this.#r.assurance_providers.push(I({layer:this.#e.layer,name:this.#e.name,network_permission:this.#e.permissions?.network===!0,definition:R("registerAssuranceMeasurementProvider provider",e)},t))}registerBeforeCommand(e){p(this.#e,"hooks","api.hooks.beforeCommand"),this.allowRegistration("hooks.beforecommand","api.hooks.beforeCommand","hooks")&&(E("beforeCommand",e),this.#t.beforeCommand.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerBeforeMutation(e){p(this.#e,"hooks","api.hooks.beforeMutation"),this.allowRegistration("hooks.beforemutation","api.hooks.beforeMutation","hooks")&&(E("beforeMutation",e),this.#t.beforeMutation.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerAfterCommand(e){p(this.#e,"hooks","api.hooks.afterCommand"),this.allowRegistration("hooks.aftercommand","api.hooks.afterCommand","hooks")&&(E("afterCommand",e),this.#t.afterCommand.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerOnWrite(e){p(this.#e,"hooks","api.hooks.onWrite"),this.allowRegistration("hooks.onwrite","api.hooks.onWrite","hooks")&&(E("onWrite",e),this.#t.onWrite.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerOnRead(e){p(this.#e,"hooks","api.hooks.onRead"),this.allowRegistration("hooks.onread","api.hooks.onRead","hooks")&&(E("onRead",e),this.#t.onRead.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerOnIndex(e){p(this.#e,"hooks","api.hooks.onIndex"),this.allowRegistration("hooks.onindex","api.hooks.onIndex","hooks")&&(E("onIndex",e),this.#t.onIndex.push({layer:this.#e.layer,name:this.#e.name,run:e}))}}function pe(r,e,t,n,i,o,s,a,m,c,l){return new Or(r,e,t,n,i,o,s,a,m,c,l)}function fe(r){const e=r.commands.length,t=r.flags.reduce((s,a)=>s+a.flags.length,0),n=r.item_fields.reduce((s,a)=>s+a.fields.length,0),i=r.item_types.reduce((s,a)=>s+a.types.length,0),o=(r.relationship_kinds??[]).reduce((s,a)=>s+a.definitions.length,0);return{commands:e,flags:t,item_fields:n,item_types:i,...o>0?{relationship_kinds:o}:{},migrations:r.migrations.length,profiles:r.profiles.length,importers:r.importers.length,exporters:r.exporters.length,search_providers:r.search_providers.length,vector_store_adapters:r.vector_store_adapters.length,...(r.assurance_providers?.length??0)>0?{assurance_providers:r.assurance_providers.length}:{}}}function ge(r){const e=[],t=(o,s)=>{const a=new Map;for(const m of o){const c=a.get(m.command)??[];c.push(m),a.set(m.command,c)}for(const m of[...a.keys()].sort((c,l)=>c.localeCompare(l))){const c=a.get(m);if(c.length<=1)continue;const l=c[c.length-1];for(const d of c.slice(0,-1))e.push(`${s}:${m}:${l.layer}:${l.name}:${d.layer}:${d.name}`)}};t(r.handlers,"extension_command_handler_collision"),t(r.overrides,"extension_command_override_collision");const n=new Set(r.handlers.map(o=>o.command)),i=[...new Set(r.overrides.map(o=>o.command))].filter(o=>n.has(o));i.sort((o,s)=>o.localeCompare(s));for(const o of i){const s=r.handlers.filter(m=>m.command===o),a=r.overrides.filter(m=>m.command===o);for(const m of a)for(const c of s)e.push(`extension_command_override_handler_overlap:${o}:${m.layer}:${m.name}:${c.layer}:${c.name}`)}return e}function ye(r){const e=new Map;for(const n of r.overrides){const i=e.get(n.format)??[];i.push(n),e.set(n.format,i)}const t=[];for(const n of[...e.keys()].sort((i,o)=>i.localeCompare(o))){const i=e.get(n);if(i.length<=1)continue;const o=i[i.length-1];for(const s of i.slice(0,-1))o.commands?.length&&s.commands?.length&&!s.commands.some(a=>o.commands?.includes(a))||t.push(`extension_renderer_collision:${n}:${o.layer}:${o.name}:${s.layer}:${s.name}`)}return t}function _e(r){const e=[],t=new Map;for(const n of r.overrides){const i=t.get(n.command)??[];i.push(n),t.set(n.command,i)}for(const n of[...t.keys()].sort((i,o)=>i.localeCompare(o))){const i=t.get(n);if(i.length<=1)continue;const o=i[i.length-1];for(const s of i.slice(0,-1))e.push(`extension_parser_override_collision:${n}:${o.layer}:${o.name}:${s.layer}:${s.name}`)}return e}const zr=new Set(["output_format"]);function ve(r){const e=[],t=new Map;for(const n of r.overrides){const i=t.get(n.service)??[];i.push(n),t.set(n.service,i)}for(const n of[...t.keys()].sort((i,o)=>i.localeCompare(o))){const i=t.get(n);if(i.length<=1||zr.has(n))continue;const o=i[i.length-1];for(const s of i.slice(0,-1))e.push(`extension_service_override_collision:${n}:${o.layer}:${o.name}:${s.layer}:${s.name}`)}return e}async function gt(r){const e=Ve(r.policy??_r),t=Be(),n=Le(),i=Ue(),o=Ke(),s=Je(),a=Ge(),m=Xe(),c=[],l=[];for(const u of r.loaded){const f=ue(u.module);if(!f)continue;const g=c.length,v=Pe({hooks:t,commands:n,parsers:i,preflight:o,services:s,renderers:a,registrations:m});try{await f.activate(pe(u,t,n,i,o,s,a,m,l,c,e)),c.length>g&&(v(),l.push(`extension_activation_rolled_back:${u.layer}:${u.name}`))}catch(_){v(),l.push(`extension_activate_failed:${u.layer}:${u.name}`);const A=J(_);c.push({layer:u.layer,name:u.name,entry_path:u.entry_path,error:M(_),trace:A})}}const d=[...ge(n),..._e(i),...tr(o),...ve(s),...ye(a)],h=[...new Set([...l,...d])];return{hooks:t,commands:n,parsers:i,preflight:o,services:s,renderers:a,registrations:m,failed:c,warnings:h,hook_counts:{before_command:t.beforeCommand.length,before_mutation:t.beforeMutation.length,after_command:t.afterCommand.length,on_write:t.onWrite.length,on_read:t.onRead.length,on_index:t.onIndex.length},command_override_count:n.overrides.length,command_handler_count:n.handlers.length,parser_override_count:i.overrides.length,preflight_override_count:o.overrides.length,service_override_count:s.overrides.length,renderer_override_count:a.overrides.length,registration_counts:fe(m)}}const yt={assertFlagValueTypeAndDefault:sr,assertOptionalStringField:$,compareComparableVersions:pr,collectCommandCollisionWarnings:ge,collectParserCollisionWarnings:_e,collectRendererCollisionWarnings:ye,collectServiceCollisionWarnings:ve,createExtensionApi:pe,createRegistrationValidationError:y,evaluatePmMaxVersionCompatibility:ce,evaluatePmMinVersionCompatibility:me,extractRegistrationValidationTrace:J,fingerprintPath:N,getRegistrationCounts:fe,normalizeCommandDefinitionArguments:T,normalizeExtensionDeactivateTimeout:he,normalizeOptionalStringArrayField:C,normalizeRegistrationRecord:R,normalizeRegistrationRecordList:z,normalizeRuntimeRegistrationRecord:k,parseComparableVersion:yr,parseManifest:X,readCurrentPmCliVersion:oe,readManagedExtensionSourcePackages:async r=>new Map([...await te(r)].filter(e=>typeof e[1].package_name=="string").map(([e,t])=>[e,t.package_name])),resolveExtensionImportHref:le,resolveCurrentPmCliVersion:j,resolveCommandDefinitionAction:F,sanitizeRegistrationValue:Q,validateItemFieldDefinitions:G,resetCurrentPmCliVersionCacheForTest:()=>{W=null}};export{Ut as DEFAULT_EXTENSION_PRIORITY,yt as _testOnlyLoader,gt as activateExtensions,bt as createEmptyExtensionCommandRegistry,Ct as createEmptyExtensionHookRegistry,Rt as createEmptyExtensionParserRegistry,kt as createEmptyExtensionPreflightRegistry,$t as createEmptyExtensionRegistrationRegistry,Pt as createEmptyExtensionRendererRegistry,St as createEmptyExtensionServiceRegistry,ft as deactivateExtensions,Sr as discoverExtensions,xr as isCanonicalPathWithinDirectory,pt as loadExtensions,vr as nextExtensionReloadToken,Kt as parseExtensionManifestDocument,wt as parseLegacyExtensionCapabilityAliasWarning,xt as parseUnknownExtensionCapabilityWarning,Er as resolveExtensionRoots,Mt as runAfterCommandHooks,At as runBeforeCommandHooks,Tt as runBeforeMutationHooks,Dt as runCommandHandler,Ft as runCommandOverride,Ot as runOnIndexHooks,zt as runOnReadHooks,Wt as runOnWriteHooks,jt as runParserOverride,Nt as runPreflightOverride,Vt as runRendererOverride,qt as runServiceOverride,Ht as runServiceOverrideSync};
1
+ import w from"node:fs/promises";import x from"node:path";import{pathToFileURL as xe}from"node:url";import{createRelationshipKindRegistry as Ee}from"../../sdk/relationships.js";import{pathExists as H}from"../fs/fs-utils.js";import{isPathWithinDirectory as L}from"../fs/path-utils.js";import{isHostOutputSuppressed as be,suppressHostOutput as Ce}from"../output/output-control.js";import{resolvePmPackageRootFromModule as Re}from"../packages/root.js";import{asRecordLoose as B,resolveActivatablePropertyRecord as ke}from"../shared/primitives.js";import{resolveGlobalPmRoot as $e}from"../store/paths.js";import{captureExtensionActivationRollback as Pe}from"./activation-transaction.js";import{assertCommandDefinitionMetadataStrings as Se}from"./command-visibility-tier.js";import{normalizeExtensionReadOutput as Ie}from"./read-output-contract.js";import{normalizeExtensionContributionInventory as Me}from"./contribution-inventory.js";import{buildImportExportContext as U,resolveImportExportArtifactOutput as Ae}from"./exporter-output-contract.js";import{buildReadyExtensionCandidate as Te}from"./extension-candidate.js";import{collectUnknownExtensionCapabilities as De,formatLegacyExtensionCapabilityAliasWarning as Fe,formatUnknownExtensionCapabilityWarning as Oe,isKnownExtensionCapability as ze,normalizeNames as K}from"./extension-capability-aliases.js";import{evaluateExtensionPolicyForCapability as We,evaluateExtensionPolicyForExtension as Ne,evaluateExtensionPolicyForRegistration as je,hydrateExtensionPolicy as Ve,normalizeExtensionPolicy as qe,serializeExtensionPolicy as He}from"./extension-policy.js";import{createEmptyExtensionCommandRegistry as Le,createEmptyExtensionHookRegistry as Be,createEmptyExtensionParserRegistry as Ue,createEmptyExtensionPreflightRegistry as Ke,createEmptyExtensionRegistrationRegistry as Xe,createEmptyExtensionRendererRegistry as Ge,createEmptyExtensionServiceRegistry as Je}from"./extension-registries.js";import{normalizeCommandName as b}from"./extension-runtime-helpers.js";import{KNOWN_EXTENSION_CAPABILITIES as Ye,KNOWN_EXTENSION_SERVICE_NAMES as Qe,createDefaultExtensionGovernancePolicy as Ze}from"./extension-types.js";import{formatReservedItemFieldWarning as er,RESERVED_ITEM_FIELD_NAMES as rr}from"./item-fields.js";import{parseExtensionManifestDocument as X}from"./manifest-parser.js";import{formatExtensionManifestSchemaWarnings as tr}from"./manifest-schema.js";import{snapshotExtensionModuleGraph as nr}from"./module-graph-snapshot.js";import{collectPreflightCollisionWarnings as ir,normalizePreflightOverride as sr}from"./preflight-ownership.js";import{applyProjectProfileDefaults as or,assertFlagValueTypeAndDefault as ar,normalizeCommandDefinitionArguments as T,normalizeFlagDefinitions as D,resolveCommandDefinitionAction as F,validateFlagDefinitions as O,validateItemFieldDefinitions as G,validateItemTypeDefinitions as mr,validateMigrationDefinition as cr,validateProjectProfileDefinition as lr}from"./registration-contracts.js";import{assertOptionalStringField as $,normalizeOptionalStringArrayField as C}from"./registration-validation.js";import{assertHookHandler as E,assertNonEmptyRegistrationString as P,assertRegistrationFunction as S,attachRuntimeDefinition as I,cloneRuntimeRegistrationValue as dr,createRegistrationValidationError as y,extractRegistrationValidationTrace as J,isExtensionServiceName as ur,isOutputRendererFormat as hr,normalizeRegistrationName as Y,normalizeRegistrationRecord as R,normalizeRegistrationRecordList as z,normalizeRuntimeRegistrationRecord as k,sanitizeRegistrationValue as Q,toRegistrationCommandPath as Z,validateAssuranceMeasurementProviderDefinition as pr}from"./registration-values.js";import{normalizeServiceOverrideOwnership as fr}from"./service-ownership.js";import{compareComparableVersions as gr,evaluatePmMaxVersionBound as yr,evaluatePmMinVersionBound as _r,parseComparableVersion as vr}from"./version-compat.js";import{parseLegacyExtensionCapabilityAliasWarning as bt,parseUnknownExtensionCapabilityWarning as Ct}from"./extension-capability-aliases.js";import{createEmptyExtensionCommandRegistry as kt,createEmptyExtensionHookRegistry as $t,createEmptyExtensionParserRegistry as Pt,createEmptyExtensionPreflightRegistry as St,createEmptyExtensionRegistrationRegistry as It,createEmptyExtensionRendererRegistry as Mt,createEmptyExtensionServiceRegistry as At}from"./extension-registries.js";import{runAfterCommandHooks as Dt,runBeforeCommandHooks as Ft,runBeforeMutationHooks as Ot,runCommandHandler as zt,runCommandOverride as Wt,runOnIndexHooks as Nt,runOnReadHooks as jt,runOnWriteHooks as Vt,runParserOverride as qt,runPreflightOverride as Ht,runRendererOverride as Lt,runServiceOverride as Bt,runServiceOverrideSync as Ut}from"./extension-hook-runtime.js";export*from"./extension-types.js";import{DEFAULT_EXTENSION_PRIORITY as Gt,parseExtensionManifestDocument as Jt}from"./manifest-parser.js";let W=null;const wr=Object.freeze(Ze());let ee=0;function xr(r=Date.now()){return ee+=1,`${ee}-${r}`}function Er(r,e,t){return t.has(r)?!1:e.size===0?!0:e.has(r)}async function br(r,e){const[t,n]=await Promise.all([w.realpath(r),w.realpath(e)]);return L(t,n)}function Cr(r,e=process.cwd()){return{global:x.join($e(e),"extensions"),project:x.join(r,"extensions")}}async function Rr(r){try{return(await w.readdir(r,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,n)=>t.localeCompare(n))}catch{return[]}}function kr(r){const e={layer:r.layer,directory:r.directory,manifest_path:r.manifest_path,name:r.manifest.name,version:r.manifest.version,entry:r.manifest.entry,priority:r.manifest.priority,entry_path:r.entry_path,manifest_version:r.manifest.manifest_version,pm_min_version:r.manifest.pm_min_version,pm_max_version:r.manifest.pm_max_version,engines:r.manifest.engines,trusted:r.manifest.trusted,provenance:r.manifest.provenance,sandbox_profile:r.manifest.sandbox_profile,permissions:r.manifest.permissions,capabilities:[...r.manifest.capabilities],activation:r.manifest.activation?{commands:[...r.manifest.activation.commands]}:void 0,contributions:r.manifest.contributions??r.contributions};return r.source_package&&(e.source_package=r.source_package),r.source_aliases&&(e.source_aliases=[...r.source_aliases]),e}function re(r){return typeof r=="string"&&r.trim().length>0?r.trim():void 0}async function te(r){const e=new Map;try{const t=JSON.parse(await w.readFile(x.join(r,".managed-extensions.json"),"utf8")),i=B(t)?.entries;if(!Array.isArray(i))return e;for(const o of i){if(typeof o!="object"||o===null)continue;const s=o,a=re(s.source?.package),m=[s.source?.input,s.source?.name,a].map(d=>re(d)).filter(d=>d!==void 0),c=Me(s.contributions),l={aliases:[...new Set(m)],...a?{package_name:a}:{},...c?{contributions:c}:{}};typeof s.directory=="string"&&s.directory.trim().length>0&&e.set(`directory:${s.directory.trim()}`,l),typeof s.name=="string"&&s.name.trim().length>0&&e.set(`name:${s.name.trim()}`,l)}}catch{return e}return e}function ne(r){return[...r].sort((e,t)=>{if(e.manifest.priority!==t.manifest.priority)return e.manifest.priority-t.manifest.priority;const n=e.manifest.name.localeCompare(t.manifest.name);return n!==0?n:e.directory.localeCompare(t.directory)})}function $r(r,e){const t=[...ne(r),...ne(e)],n=[];for(const i of t){const o=n.findIndex(s=>s.manifest.name===i.manifest.name);o>=0&&n.splice(o,1),n.push(i)}return n}async function ie(r,e,t,n,i){const o=[],s=[],a=[],m=await Rr(e),c=await te(e);for(const l of m){const d=await Ir(r,e,l,t,n,c,i);o.push(d.diagnostic),s.push(...d.warnings),d.candidate&&a.push(d.candidate)}return{diagnostics:o,warnings:s,candidates:a}}function Pr(){return{diagnostics:[],warnings:[],candidates:[]}}function se(r,e,t,n){return{diagnostic:{layer:r,directory:e,manifest_path:t,name:null,version:null,entry:null,priority:null,entry_path:null,enabled:null,status:"warn"},warnings:[n],candidate:null}}function Sr(r,e,t,n,i,o,s,a){const m=tr(r,e,t);Array.isArray(e.legacy_capability_aliases)&&e.legacy_capability_aliases.length>0&&m.push(Fe(r,e.name,e.legacy_capability_aliases));for(const c of De(e.capabilities))m.push(Oe(r,e.name,c));return n?i||m.push(`extension_entry_missing:${r}:${e.name}`):m.push(`extension_entry_outside_extension:${r}:${e.name}`),o.warning&&m.push(a?o.warning:o.warning.replace("extension_pm_","extension_disabled_pm_")),s.warning&&m.push(a?s.warning:s.warning.replace("extension_pm_","extension_disabled_pm_")),m}async function Ir(r,e,t,n,i,o,s){const a=x.join(e,t),m=x.join(a,"manifest.json");if(!await H(m))return se(r,t,m,`extension_manifest_missing:${r}:${t}`);let c,l;try{const q=JSON.parse(await w.readFile(m,"utf8"));l=B(q),c=X(q)}catch{l=null,c=null}if(!c||!l)return se(r,t,m,`extension_manifest_invalid:${r}:${t}`);const d=x.resolve(a,c.entry),h=L(a,d),u=h?await H(d):!1,f=h&&u?await br(a,d):h,g=Er(c.name,n,i),v=await me(r,c),_=await ce(r,c,s),A=Sr(r,c,l,f,u,v,_,g),V=f&&u&&v.allowed&&_.allowed,we=o.get(`directory:${t}`)??o.get(`name:${c.name}`);return{diagnostic:{layer:r,directory:t,manifest_path:m,name:c.name,version:c.version,entry:c.entry,priority:c.priority,entry_path:d,enabled:g,status:V?"ok":"warn"},warnings:A,candidate:Te({layer:r,directory:t,manifestPath:m,entryPath:d,manifest:c,sourceIdentity:we,extensionReady:V,enabledForLoad:g})}}async function Mr(r){const e=Cr(r.pmRoot,r.cwd??process.cwd()),t=K(r.settings.extensions.enabled),n=K(r.settings.extensions.disabled),i=qe(r.settings),o=He(i);if(r.noExtensions)return{disabled_by_flag:!0,roots:e,configured_enabled:t,configured_disabled:n,discovered:[],effective:[],warnings:[...i.warnings],policy:o};const s=new Set(t),a=new Set(n),m=r.ignoreGlobalExtensions===!0?Pr():await ie("global",e.global,s,a,i.pmMaxVersionExceededMode.global),c=await ie("project",e.project,s,a,i.pmMaxVersionExceededMode.project),l=[...i.warnings],d=$r(m.candidates,c.candidates),h=[];for(const u of d){const f={layer:u.layer,name:u.manifest.name,trusted:u.manifest.trusted===!0,provenanceVerified:u.manifest.provenance?.verified===!0,sandboxProfile:u.manifest.sandbox_profile,permissions:u.manifest.permissions&&typeof u.manifest.permissions=="object"?{fs_read:u.manifest.permissions.fs_read,fs_write:u.manifest.permissions.fs_write,network:u.manifest.permissions.network,env_read:u.manifest.permissions.env_read,env_write:u.manifest.permissions.env_write,process_spawn:u.manifest.permissions.process_spawn}:void 0},g=Ne(i,f);if(g.warning&&l.push(g.warning),!!g.allowed){for(const v of u.manifest.capabilities){const _=We(i,f,v);_.warning&&l.push(_.warning)}h.push(kr(u))}}return{disabled_by_flag:!1,roots:e,configured_enabled:t,configured_disabled:n,discovered:[...m.diagnostics,...c.diagnostics],effective:h,warnings:[...new Set([...m.warnings,...c.warnings,...l])],policy:o}}function M(r){return r instanceof Error&&r.message.trim().length>0?r.message:String(r)}async function oe(){try{const r=Re(import.meta.url,["../../.."]),e=await w.readFile(x.join(r,"package.json"),"utf8"),t=JSON.parse(e);return typeof t.version=="string"&&t.version.trim().length>0?t.version.trim():null}catch{return null}}function N(){return W??=oe(),W}function ae(r,e,t){const n=t.current??"unknown";if(t.kind==="pm_min_version")switch(t.status){case"invalid":return`extension_pm_min_version_invalid:${r}:${e.name}:required=${t.required}`;case"unchecked":return`extension_pm_min_version_unchecked:${r}:${e.name}:required=${t.required}:current=${n}`;case"unmet":return`extension_pm_min_version_unmet:${r}:${e.name}:required=${t.required}:current=${n}`;default:return}switch(t.status){case"invalid":return`extension_pm_max_version_invalid:${r}:${e.name}:allowed=${t.required}`;case"unchecked":return`extension_pm_max_version_unchecked:${r}:${e.name}:allowed=${t.required}:current=${n}`;case"exceeded_warn":return`extension_pm_max_version_exceeded_warn:${r}:${e.name}:allowed=${t.required}:current=${n}`;case"exceeded":return`extension_pm_max_version_exceeded:${r}:${e.name}:allowed=${t.required}:current=${n}`;default:return}}async function me(r,e){if(e.pm_min_version===void 0)return{allowed:!0};const t=_r(e.pm_min_version,await N()),n=ae(r,e,t);return n?{allowed:t.allowed,warning:n}:{allowed:t.allowed}}async function ce(r,e,t){if(e.pm_max_version===void 0)return{allowed:!0};const n=yr(e.pm_max_version,await N(),t),i=ae(r,e,n);return i?{allowed:n.allowed,warning:i}:{allowed:n.allowed}}async function j(r){try{const e=await w.stat(r);return`${Math.trunc(e.mtimeMs)}-${e.size}`}catch{return"missing"}}async function le(r,e){let t=r.entry_path;e.module_graph_snapshot_root&&(t=await nr(e.module_graph_snapshot_root,r));const n=new URL(xe(t).href);if(!(e.cache_bust===!0||typeof e.reload_token=="string"))return n.href;const[o,s]=await Promise.all([j(r.entry_path),j(r.manifest_path)]),a=e.reload_token??xr();return n.searchParams.set("pm_ext_reload",a),n.searchParams.set("pm_ext_entry",o),n.searchParams.set("pm_ext_manifest",s),n.href}async function yt(r){const e=await Mr(r),t=[],n=[],i=[...e.warnings];if(e.disabled_by_flag)return{...e,warnings:i,loaded:t,failed:n};const o=typeof r.extensionFilter=="function"?e.effective.filter(r.extensionFilter):e.effective;for(const s of o)try{const m=await import(await le(s,r));t.push({...s,module:m})}catch(a){i.push(`extension_load_failed:${s.layer}:${s.name}`),n.push({layer:s.layer,name:s.name,entry_path:s.entry_path,error:M(a)})}return{...e,warnings:i,loaded:t,failed:n}}const de=5e3,Ar=2147483647;function Tr(r){const t={activate:r.activate.bind(r)};if(typeof r.deactivate=="function"){const n=r.deactivate;t.deactivate=n.bind(r)}return t}function ue(r){const e=ke(r);return e?Tr(e):null}async function _t(r,e,t={}){const n=he(t?.deactivate_timeout_ms),i=new Set((e?.failed??[]).map(l=>`${l.layer}:${l.name}`)),o=[];for(const l of r.loaded){if(i.has(`${l.layer}:${l.name}`))continue;const d=ue(l.module);!d||typeof d.deactivate!="function"||o.push({extension:l,deactivate:d.deactivate})}const s=await Promise.all(o.map(async({extension:l,deactivate:d})=>{try{return await Dr(d,n),{ok:!0}}catch(h){return{ok:!1,layer:l.layer,name:l.name,error:M(h)}}})),a=[],m=[];let c=0;for(const l of s){if(l.ok){c+=1;continue}a.push(`extension_deactivate_failed:${l.layer}:${l.name}`),m.push({layer:l.layer,name:l.name,error:l.error})}return{deactivated:c,warnings:a,failed:m}}function he(r){return typeof r!="number"||r<0?de:r===0||r===1/0?0:Number.isFinite(r)?Math.min(Ar,Math.max(1,Math.floor(r))):de}async function Dr(r,e){if(e===0){await r();return}let t;try{const n=Promise.resolve().then(()=>r());n.catch(()=>{}),await Promise.race([n,new Promise((i,o)=>{t=setTimeout(()=>{o(new Error(`extension deactivate timed out after ${e}ms`))},e),t.unref?.()})])}finally{clearTimeout(t)}}function Fr(r){if(!Array.isArray(r.capabilities))return null;const e=new Set;for(const t of r.capabilities){const n=t.trim().toLowerCase();ze(n)&&e.add(n)}return e}function p(r,e,t){const n=Fr(r);if(n!==null&&!n.has(e))throw y(`${t} requires capability '${e}' in extension manifest capabilities`,{method:t,registration_index:-1,capability:e,missing_capability:e,expected_schema:`"capabilities": [..., "${e}"]`,received:r.capabilities,hint:`Add "${e}" to ${r.name} manifest capabilities, or remove the ${t} registration call.`})}function Or(r){return Object.freeze({name:r.name,layer:r.layer,version:r.version,capabilities:Object.freeze((r.capabilities??[]).filter(e=>Ye.includes(e))),pm_min_version:r.pm_min_version,pm_max_version:r.pm_max_version,source_package:r.source_package})}function zr(r){return{layer:r.layer,name:r.name,trusted:r.trusted===!0,provenanceVerified:r.provenance?.verified===!0,sandboxProfile:r.sandbox_profile,permissions:r.permissions&&typeof r.permissions=="object"?{fs_read:r.permissions.fs_read,fs_write:r.permissions.fs_write,network:r.permissions.network,env_read:r.permissions.env_read,env_write:r.permissions.env_write,process_spawn:r.permissions.process_spawn}:void 0}}class Wr{extension;hooks;#e;#s;#t;#n;#o;#a;#m;#c;#r;#i;#l;#d;constructor(e,t,n,i,o,s,a,m,c,l,d){this.#e=e,this.extension=Or(e),this.#s=zr(e),this.#t=t,this.#n=n,this.#o=i,this.#a=o,this.#m=s,this.#c=a,this.#r=m,this.#i=c,this.#l=l,this.#d=d,this.registerCommand=this.registerCommand.bind(this),this.registerParser=this.registerParser.bind(this),this.registerPreflight=this.registerPreflight.bind(this),this.registerService=this.registerService.bind(this),this.registerFlags=this.registerFlags.bind(this),this.registerItemFields=this.registerItemFields.bind(this),this.registerItemTypes=this.registerItemTypes.bind(this),this.registerRelationshipKinds=this.registerRelationshipKinds.bind(this),this.registerMigration=this.registerMigration.bind(this),this.registerProfile=this.registerProfile.bind(this),this.registerRenderer=this.registerRenderer.bind(this),this.registerImporter=this.registerImporter.bind(this),this.registerExporter=this.registerExporter.bind(this),this.registerSearchProvider=this.registerSearchProvider.bind(this),this.registerVectorStoreAdapter=this.registerVectorStoreAdapter.bind(this),this.registerAssuranceMeasurementProvider=this.registerAssuranceMeasurementProvider.bind(this),this.hooks={beforeCommand:h=>this.registerBeforeCommand(h),beforeMutation:h=>this.registerBeforeMutation(h),afterCommand:h=>this.registerAfterCommand(h),onWrite:h=>this.registerOnWrite(h),onRead:h=>this.registerOnRead(h),onIndex:h=>this.registerOnIndex(h)}}allowRegistration(e,t,n,i){const o=je(this.#d,this.#s,e,t,n,i);return o.warning&&this.#i.push(o.warning),o.allowed}registerCommandTrace(e,t,n,i,o){return{method:"registerCommand",registration_index:e==="override"?this.#n.overrides.length:this.#n.handlers.length,command:t,expected_schema:n,received:Q(i),hint:o}}registerCommandOverride(e,t){const n=b(e);if(n.length===0)throw y("registerCommand requires a non-empty command name",this.registerCommandTrace("override",e,'registerCommand("<command>", (context) => unknown)',e,"Provide a non-empty command path as the first argument."));if(typeof t!="function"){const i=this.registerCommandTrace("override",n,'registerCommand("<command>", (context) => unknown)',t,"Provide a function as the second registerCommand argument.");throw y(`registerCommand requires an override function when command name is provided (command="${n}", registration_index=${i.registration_index})`,i)}this.allowRegistration("commands.override","registerCommand","commands",{command:n})&&this.#n.overrides.push({layer:this.#e.layer,name:this.#e.name,command:n,run:t})}resolveCommandDefinitionRunHandler(e,t){const n=typeof e.run=="function"?e.run:void 0,i=typeof e.handler=="function"?e.handler:void 0;return!n&&i&&this.#i.push(`extension_command_definition_legacy_handler_alias:${this.#e.layer}:${this.#e.name}:${t}`),n??i}registerCommandDefinition(e){if(typeof e!="object"||e===null)throw y("registerCommand requires a command definition object",this.registerCommandTrace("definition",void 0,"{ name: string; run: (context) => unknown; }",e,'Use registerCommand({ name: "command path", run: (context) => ... }).'));if(typeof e.name!="string")throw y("registerCommand requires a command definition name",this.registerCommandTrace("definition",void 0,"{ name: string; run: (context) => unknown; }",e,"Set command definition.name to a non-empty string command path."));const t=b(e.name);if(t.length===0)throw y("registerCommand requires a non-empty command definition name",this.registerCommandTrace("definition",e.name,"{ name: string; run: (context) => unknown; }",e,"Ensure command definition.name contains a non-empty command path."));const n=this.resolveCommandDefinitionRunHandler(e,t);if(typeof n!="function"){const i=this.registerCommandTrace("definition",t,"{ name: string; run: (context) => unknown; }",n,"Define command definition.run as a function.");throw y(`registerCommand requires a command definition run handler (command="${t}", registration_index=${i.registration_index})`,i)}try{Se(e);const i=F(t,e.action),o=Ie(e.read_output,t,i);if(!this.allowRegistration("commands.handler","registerCommand","commands",{command:t,action:i}))return;const s=e.description?.trim(),a=e.intent?.trim(),m=C("registerCommand definition.examples",e.examples),c=C("registerCommand definition.failure_hints",e.failure_hints),l=T(e.arguments);e.flags!==void 0&&(p(this.#e,"schema","registerCommand flags"),this.allowRegistration("schema.flags","registerCommand flags","schema")&&(O(e.flags),this.#r.flags.push({layer:this.#e.layer,name:this.#e.name,target_command:t,flags:D("registerCommand definition.flags",e.flags)})));const d={source_version:this.#e.version,read_output:o,layer:this.#e.layer,name:this.#e.name,source_package:this.#e.source_package,command:t,action:i,examples:m,failure_hints:c,arguments:l,tier:e.tier??"standard",family:e.family??"extensions"};s&&(d.description=s),a&&(d.intent=a),this.#r.commands.push(d)}catch(i){const o=M(i),s=this.registerCommandTrace("definition",t,"{ name: string; run: (context) => unknown; action?: string; arguments?: object[]; flags?: object[]; }",e,o),a=y(`registerCommand definition metadata invalid (command="${t}", registration_index=${s.registration_index}): ${o}`,s);this.#i.push(`extension_command_quarantined:${this.#e.layer}:${this.#e.name}:${t}`),this.#l.push({layer:this.#e.layer,name:this.#e.name,entry_path:this.#e.entry_path,error:a.message,trace:s});return}this.#n.handlers.push({layer:this.#e.layer,name:this.#e.name,command:t,run:n})}registerCommand(e,t){if(p(this.#e,"commands","registerCommand"),typeof e=="string"){this.registerCommandOverride(e,t);return}this.registerCommandDefinition(e)}registerParser(e,t){if(p(this.#e,"parser","registerParser"),!this.allowRegistration("parser.override","registerParser","parser"))return;const n=b(P("registerParser command",e));S("registerParser override",t),this.#o.overrides.push({layer:this.#e.layer,name:this.#e.name,command:n,run:t})}registerPreflight(e){if(p(this.#e,"preflight","registerPreflight"),!this.allowRegistration("preflight.override","registerPreflight","preflight"))return;const t=sr(e);this.#a.overrides.push({layer:this.#e.layer,name:this.#e.name,...t})}registerService(e,t,n={}){p(this.#e,"services","registerService");const i=String(e).trim().toLowerCase();if(!ur(i))throw new TypeError(`registerService service must be one of: ${Qe.join(", ")}`);this.allowRegistration("services.override","registerService","services",{service:i})&&(S("registerService override",t),this.#m.overrides.push({layer:this.#e.layer,name:this.#e.name,service:i,run:t,...fr(n)?{passThrough:!0}:{}}))}registerRenderer(e,t,n={}){if(p(this.#e,"renderers","registerRenderer"),!this.allowRegistration("renderers.override","registerRenderer","renderers"))return;if(typeof t!="function")throw new TypeError("registerRenderer requires a renderer function");const i=String(e).trim().toLowerCase();if(!hr(i))throw new Error(`registerRenderer format must be toon|json, received: ${String(e)}`);if(n.resultDiscriminator!==void 0&&typeof n.resultDiscriminator!="function")throw new TypeError("registerRenderer ownership.resultDiscriminator must be a function when provided");const o=[...new Set((n.commands??[]).map(s=>{if(typeof s!="string"||s.trim().length===0)throw new TypeError("registerRenderer ownership.commands must contain non-empty command paths");return b(s)}))];this.#c.overrides.push({layer:this.#e.layer,name:this.#e.name,format:i,run:t,commands:o,...n.resultDiscriminator?{resultDiscriminator:n.resultDiscriminator}:{}})}registerFlags(e,t){if(p(this.#e,"schema","registerFlags"),!this.allowRegistration("schema.flags","registerFlags","schema"))return;const n=b(P("registerFlags targetCommand",e));O(t);const i=D("registerFlags flags",t);if(i.length===0)throw new TypeError("registerFlags requires at least one flag definition");this.#r.flags.push({layer:this.#e.layer,name:this.#e.name,target_command:n,flags:i})}registerItemFields(e){if(p(this.#e,"schema","registerItemFields"),!this.allowRegistration("schema.itemfields","registerItemFields","schema"))return;G(e);const t=z("registerItemFields fields",e);if(t.length===0)throw new TypeError("registerItemFields requires at least one field definition");const{layer:n,name:i}=this.#e,o=t.filter(s=>{const a=typeof s.name=="string"?s.name.trim():"";return rr.has(a)?(this.#i.push(er(n,i,a)),!1):!0});this.#r.item_fields.push({layer:n,name:i,fields:o})}registerItemTypes(e){if(p(this.#e,"schema","registerItemTypes"),!this.allowRegistration("schema.itemtypes","registerItemTypes","schema"))return;mr(e);const t=z("registerItemTypes types",e);if(t.length===0)throw new TypeError("registerItemTypes requires at least one type definition");this.#r.item_types.push({layer:this.#e.layer,name:this.#e.name,types:t})}registerRelationshipKinds(e){if(p(this.#e,"schema","registerRelationshipKinds"),!this.allowRegistration("schema.relationshipkinds","registerRelationshipKinds","schema"))return;if(!Array.isArray(e))throw new TypeError("registerRelationshipKinds definitions requires an array of object definitions");if(e.length===0)throw new TypeError("registerRelationshipKinds requires at least one definition");const t=Ee();for(const i of this.#r.relationship_kinds)for(const o of i.definitions)t.register(o);const n=e.map(i=>(t.register(i),t.require(i.kind)));this.#r.relationship_kinds.push({layer:this.#e.layer,name:this.#e.name,definitions:n})}registerMigration(e){if(p(this.#e,"schema","registerMigration"),!this.allowRegistration("schema.migrations","registerMigration","schema"))return;cr(e);const t=k("registerMigration definition",e);this.#r.migrations.push(I({layer:this.#e.layer,name:this.#e.name,definition:R("registerMigration definition",e)},t))}registerProfile(e){if(p(this.#e,"schema","registerProfile"),!this.allowRegistration("schema.profiles","registerProfile","schema"))return;const t=dr(e);lr(t),this.#r.profiles.push({layer:this.#e.layer,name:this.#e.name,profile:or(t)})}registerImportExportCommandFlags(e,t,n){n.flags!==void 0&&(p(this.#e,"schema",`${e} options.flags`),this.allowRegistration("schema.flags",`${e} options.flags`,"schema")&&(O(n.flags),this.#r.flags.push({layer:this.#e.layer,name:this.#e.name,target_command:t,flags:D(`${e} options.flags`,n.flags)})))}applyImportExportCommandMetadata(e,t,n){if(n!==void 0&&(typeof n!="object"||n===null||Array.isArray(n)))throw new TypeError(`${e} options must be an object when provided`);const i=`${e==="registerImporter"?"Import":"Export"} items with the registered extension adapter.`,o=[{name:"file",required:!1,description:"Optional input or output file path."}],s={...n,description:n?.description??i,arguments:n?.arguments??o},a=Ae(e,s,n?.description!==void 0);$(`${e} options.action`,s.action),$(`${e} options.description`,s.description),$(`${e} options.intent`,s.intent);const m=F(t,s.action),c=C(`${e} options.examples`,s.examples),l=C(`${e} options.failure_hints`,s.failure_hints),d=T(s.arguments);this.registerImportExportCommandFlags(e,t,s);const h={source_version:this.#e.version,layer:this.#e.layer,name:this.#e.name,source_package:this.#e.source_package,command:t,action:m,examples:c,failure_hints:l,arguments:d},u=s.description?.trim();u&&(h.description=u);const f=s.intent?.trim();return f&&(h.intent=f),this.#r.commands.push(h),a}registerImporter(e,t,n){if(p(this.#e,"importers","registerImporter"),!this.allowRegistration("importers.importer","registerImporter","importers"))return;const i=Y(P("registerImporter name",e));S("registerImporter importer",t);const o=Z(i,"import");this.applyImportExportCommandMetadata("registerImporter",o,n),this.#r.importers.push({layer:this.#e.layer,name:this.#e.name,importer:i}),this.#n.handlers.push({layer:this.#e.layer,name:this.#e.name,command:o,run:async s=>t(U(s,i,"import"))})}registerExporter(e,t,n){if(p(this.#e,"importers","registerExporter"),!this.allowRegistration("importers.exporter","registerExporter","importers"))return;const i=Y(P("registerExporter name",e));S("registerExporter exporter",t);const o=Z(i,"export"),s=this.applyImportExportCommandMetadata("registerExporter",o,n);this.#r.exporters.push({layer:this.#e.layer,name:this.#e.name,exporter:i,...s===void 0?{}:{output:s}}),this.#n.handlers.push({layer:this.#e.layer,name:this.#e.name,command:o,run:async a=>{const m=await t(U(a,i,"export"));return s?.receipt==="suppress"&&!be(m)?Ce(m):m}})}registerSearchProvider(e){if(p(this.#e,"search","registerSearchProvider"),!this.allowRegistration("search.provider","registerSearchProvider","search"))return;const t=k("registerSearchProvider provider",e);this.#r.search_providers.push(I({layer:this.#e.layer,name:this.#e.name,definition:R("registerSearchProvider provider",e)},t))}registerVectorStoreAdapter(e){if(p(this.#e,"search","registerVectorStoreAdapter"),!this.allowRegistration("search.vectorstore","registerVectorStoreAdapter","search"))return;const t=k("registerVectorStoreAdapter adapter",e);this.#r.vector_store_adapters.push(I({layer:this.#e.layer,name:this.#e.name,definition:R("registerVectorStoreAdapter adapter",e)},t))}registerAssuranceMeasurementProvider(e){if(p(this.#e,"services","registerAssuranceMeasurementProvider"),!this.allowRegistration("services.assuranceprovider","registerAssuranceMeasurementProvider","services"))return;if(pr(e),e.network&&this.#e.permissions?.network!==!0)throw new TypeError("registerAssuranceMeasurementProvider network provider requires permissions.network=true");const t=k("registerAssuranceMeasurementProvider provider",e);this.#r.assurance_providers.push(I({layer:this.#e.layer,name:this.#e.name,network_permission:this.#e.permissions?.network===!0,definition:R("registerAssuranceMeasurementProvider provider",e)},t))}registerBeforeCommand(e){p(this.#e,"hooks","api.hooks.beforeCommand"),this.allowRegistration("hooks.beforecommand","api.hooks.beforeCommand","hooks")&&(E("beforeCommand",e),this.#t.beforeCommand.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerBeforeMutation(e){p(this.#e,"hooks","api.hooks.beforeMutation"),this.allowRegistration("hooks.beforemutation","api.hooks.beforeMutation","hooks")&&(E("beforeMutation",e),this.#t.beforeMutation.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerAfterCommand(e){p(this.#e,"hooks","api.hooks.afterCommand"),this.allowRegistration("hooks.aftercommand","api.hooks.afterCommand","hooks")&&(E("afterCommand",e),this.#t.afterCommand.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerOnWrite(e){p(this.#e,"hooks","api.hooks.onWrite"),this.allowRegistration("hooks.onwrite","api.hooks.onWrite","hooks")&&(E("onWrite",e),this.#t.onWrite.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerOnRead(e){p(this.#e,"hooks","api.hooks.onRead"),this.allowRegistration("hooks.onread","api.hooks.onRead","hooks")&&(E("onRead",e),this.#t.onRead.push({layer:this.#e.layer,name:this.#e.name,run:e}))}registerOnIndex(e){p(this.#e,"hooks","api.hooks.onIndex"),this.allowRegistration("hooks.onindex","api.hooks.onIndex","hooks")&&(E("onIndex",e),this.#t.onIndex.push({layer:this.#e.layer,name:this.#e.name,run:e}))}}function pe(r,e,t,n,i,o,s,a,m,c,l){return new Wr(r,e,t,n,i,o,s,a,m,c,l)}function fe(r){const e=r.commands.length,t=r.flags.reduce((s,a)=>s+a.flags.length,0),n=r.item_fields.reduce((s,a)=>s+a.fields.length,0),i=r.item_types.reduce((s,a)=>s+a.types.length,0),o=(r.relationship_kinds??[]).reduce((s,a)=>s+a.definitions.length,0);return{commands:e,flags:t,item_fields:n,item_types:i,...o>0?{relationship_kinds:o}:{},migrations:r.migrations.length,profiles:r.profiles.length,importers:r.importers.length,exporters:r.exporters.length,search_providers:r.search_providers.length,vector_store_adapters:r.vector_store_adapters.length,...(r.assurance_providers?.length??0)>0?{assurance_providers:r.assurance_providers.length}:{}}}function ge(r){const e=[],t=(o,s)=>{const a=new Map;for(const m of o){const c=a.get(m.command)??[];c.push(m),a.set(m.command,c)}for(const m of[...a.keys()].sort((c,l)=>c.localeCompare(l))){const c=a.get(m);if(c.length<=1)continue;const l=c[c.length-1];for(const d of c.slice(0,-1))e.push(`${s}:${m}:${l.layer}:${l.name}:${d.layer}:${d.name}`)}};t(r.handlers,"extension_command_handler_collision"),t(r.overrides,"extension_command_override_collision");const n=new Set(r.handlers.map(o=>o.command)),i=[...new Set(r.overrides.map(o=>o.command))].filter(o=>n.has(o));i.sort((o,s)=>o.localeCompare(s));for(const o of i){const s=r.handlers.filter(m=>m.command===o),a=r.overrides.filter(m=>m.command===o);for(const m of a)for(const c of s)e.push(`extension_command_override_handler_overlap:${o}:${m.layer}:${m.name}:${c.layer}:${c.name}`)}return e}function ye(r){const e=new Map;for(const n of r.overrides){const i=e.get(n.format)??[];i.push(n),e.set(n.format,i)}const t=[];for(const n of[...e.keys()].sort((i,o)=>i.localeCompare(o))){const i=e.get(n);if(i.length<=1)continue;const o=i[i.length-1];for(const s of i.slice(0,-1))o.commands?.length&&s.commands?.length&&!s.commands.some(a=>o.commands?.includes(a))||t.push(`extension_renderer_collision:${n}:${o.layer}:${o.name}:${s.layer}:${s.name}`)}return t}function _e(r){const e=[],t=new Map;for(const n of r.overrides){const i=t.get(n.command)??[];i.push(n),t.set(n.command,i)}for(const n of[...t.keys()].sort((i,o)=>i.localeCompare(o))){const i=t.get(n);if(i.length<=1)continue;const o=i[i.length-1];for(const s of i.slice(0,-1))e.push(`extension_parser_override_collision:${n}:${o.layer}:${o.name}:${s.layer}:${s.name}`)}return e}const Nr=new Set(["output_format"]);function ve(r){const e=[],t=new Map;for(const n of r.overrides){const i=t.get(n.service)??[];i.push(n),t.set(n.service,i)}for(const n of[...t.keys()].sort((i,o)=>i.localeCompare(o))){const i=t.get(n);if(i.length<=1||Nr.has(n))continue;const o=i[i.length-1];for(const s of i.slice(0,-1))e.push(`extension_service_override_collision:${n}:${o.layer}:${o.name}:${s.layer}:${s.name}`)}return e}async function vt(r){const e=Ve(r.policy??wr),t=Be(),n=Le(),i=Ue(),o=Ke(),s=Je(),a=Ge(),m=Xe(),c=[],l=[];for(const u of r.loaded){const f=ue(u.module);if(!f)continue;const g=c.length,v=Pe({hooks:t,commands:n,parsers:i,preflight:o,services:s,renderers:a,registrations:m});try{await f.activate(pe(u,t,n,i,o,s,a,m,l,c,e)),c.length>g&&(v(),l.push(`extension_activation_rolled_back:${u.layer}:${u.name}`))}catch(_){v(),l.push(`extension_activate_failed:${u.layer}:${u.name}`);const A=J(_);c.push({layer:u.layer,name:u.name,entry_path:u.entry_path,error:M(_),trace:A})}}const d=[...ge(n),..._e(i),...ir(o),...ve(s),...ye(a)],h=[...new Set([...l,...d])];return{hooks:t,commands:n,parsers:i,preflight:o,services:s,renderers:a,registrations:m,failed:c,warnings:h,hook_counts:{before_command:t.beforeCommand.length,before_mutation:t.beforeMutation.length,after_command:t.afterCommand.length,on_write:t.onWrite.length,on_read:t.onRead.length,on_index:t.onIndex.length},command_override_count:n.overrides.length,command_handler_count:n.handlers.length,parser_override_count:i.overrides.length,preflight_override_count:o.overrides.length,service_override_count:s.overrides.length,renderer_override_count:a.overrides.length,registration_counts:fe(m)}}const wt={assertFlagValueTypeAndDefault:ar,assertOptionalStringField:$,compareComparableVersions:gr,collectCommandCollisionWarnings:ge,collectParserCollisionWarnings:_e,collectRendererCollisionWarnings:ye,collectServiceCollisionWarnings:ve,createExtensionApi:pe,createRegistrationValidationError:y,evaluatePmMaxVersionCompatibility:ce,evaluatePmMinVersionCompatibility:me,extractRegistrationValidationTrace:J,fingerprintPath:j,getRegistrationCounts:fe,normalizeCommandDefinitionArguments:T,normalizeExtensionDeactivateTimeout:he,normalizeOptionalStringArrayField:C,normalizeRegistrationRecord:R,normalizeRegistrationRecordList:z,normalizeRuntimeRegistrationRecord:k,parseComparableVersion:vr,parseManifest:X,readCurrentPmCliVersion:oe,readManagedExtensionSourcePackages:async r=>new Map([...await te(r)].filter(e=>typeof e[1].package_name=="string").map(([e,t])=>[e,t.package_name])),resolveExtensionImportHref:le,resolveCurrentPmCliVersion:N,resolveCommandDefinitionAction:F,sanitizeRegistrationValue:Q,validateItemFieldDefinitions:G,resetCurrentPmCliVersionCacheForTest:()=>{W=null}};export{Gt as DEFAULT_EXTENSION_PRIORITY,wt as _testOnlyLoader,vt as activateExtensions,kt as createEmptyExtensionCommandRegistry,$t as createEmptyExtensionHookRegistry,Pt as createEmptyExtensionParserRegistry,St as createEmptyExtensionPreflightRegistry,It as createEmptyExtensionRegistrationRegistry,Mt as createEmptyExtensionRendererRegistry,At as createEmptyExtensionServiceRegistry,_t as deactivateExtensions,Mr as discoverExtensions,br as isCanonicalPathWithinDirectory,yt as loadExtensions,xr as nextExtensionReloadToken,Jt as parseExtensionManifestDocument,bt as parseLegacyExtensionCapabilityAliasWarning,Ct as parseUnknownExtensionCapabilityWarning,Cr as resolveExtensionRoots,Dt as runAfterCommandHooks,Ft as runBeforeCommandHooks,Ot as runBeforeMutationHooks,zt as runCommandHandler,Wt as runCommandOverride,Nt as runOnIndexHooks,jt as runOnReadHooks,Vt as runOnWriteHooks,qt as runParserOverride,Ht as runPreflightOverride,Lt as runRendererOverride,Bt as runServiceOverride,Ut as runServiceOverrideSync};
2
2
  //# sourceMappingURL=loader.js.map
@@ -1,2 +1,2 @@
1
- import{BUILTIN_ITEM_TYPE_VALUES as _}from"../../types/index.js";import{parseNestedSettingValue as g,resolveNestedSettingDescriptor as k}from"../config/nested-settings.js";import{normalizeAddFieldInput as v}from"../schema/fields-file.js";import{normalizeAddStatusInput as S}from"../schema/status-defs-file.js";import{normalizeAddTypeInput as $}from"../schema/item-types-file.js";import{normalizeStatusToken as p}from"../schema/type-workflows.js";import{DEFAULT_RUNTIME_STATUS_DEFINITIONS as T}from"../schema/runtime-schema.js";import{toErrorMessage as f}from"../shared/primitives.js";import{resolvePmToolCustomFieldCollision as I}from"../../sdk/cli-contracts/tool-schema.js";import{describeFieldFlagSpellingDefectLine as b,describeFieldOptionCollision as F,resolveAddFieldFlagSpellingDefects as P,resolveAddFieldOptionCollisions as C}from"../../sdk/schema/field-option-collisions.js";import{normalizeProfileLookupKey as h}from"./profile-presets.js";const J=["profile","types","statuses","fields","workflows","config","templates","packages"],Q=["profile_name_empty","profile_name_not_normalized","profile_title_empty","profile_summary_empty","type_invalid","type_duplicate","status_invalid","status_duplicate","field_invalid","field_duplicate","field_mcp_input_collision","field_option_collision","field_flag_invalid","workflow_type_empty","workflow_type_unknown","workflow_duplicate_type","workflow_transition_malformed","workflow_status_unknown","config_key_unknown","config_value_invalid","config_duplicate","template_type_unknown","package_spec_empty"],L=new Set(T.flatMap(t=>[p(t.id),...(t.aliases??[]).map(e=>p(e))]).filter(t=>t.length>0)),w=new Set(_.map(t=>t.toLowerCase()));function E(t,e){t.name.trim().length===0?e.push({severity:"error",code:"profile_name_empty",dimension:"profile",message:"Profile name must not be empty; profile resolution requires a non-blank name."}):t.name!==h(t.name)&&e.push({severity:"warning",code:"profile_name_not_normalized",dimension:"profile",target:t.name,message:`Profile name "${t.name}" is not in canonical form; resolution folds it to "${h(t.name)}" (lowercase, hyphens as underscores).`}),t.title.trim().length===0&&e.push({severity:"warning",code:"profile_title_empty",dimension:"profile",message:"Profile title is empty; list and show surfaces will render a blank title."}),t.summary.trim().length===0&&e.push({severity:"warning",code:"profile_summary_empty",dimension:"profile",message:"Profile summary is empty; list and show surfaces will render a blank archetype description."})}function N(t,e){const r=new Set,i=new Set;for(const[s,o]of t.types.entries()){let n;try{n=$(o).name}catch(d){e.push({severity:"error",code:"type_invalid",dimension:"types",target:typeof o.name=="string"?o.name:`#${s}`,message:f(d)});continue}const a=n.toLowerCase();if(i.has(a)){e.push({severity:"error",code:"type_duplicate",dimension:"types",target:n,message:`Item type "${n}" is declared more than once; the later definition silently overwrites the earlier upsert.`});continue}i.add(a),r.add(a)}return r}function z(t,e){const r=new Set,i=new Set;for(const[s,o]of t.statuses.entries()){let n;try{n=S(o)}catch(a){e.push({severity:"error",code:"status_invalid",dimension:"statuses",target:typeof o.id=="string"?o.id:`#${s}`,message:f(a)});continue}if(i.has(n.id)){e.push({severity:"error",code:"status_duplicate",dimension:"statuses",target:n.id,message:`Status "${n.id}" is declared more than once; the later definition silently overwrites the earlier upsert.`});continue}i.add(n.id),r.add(n.id);for(const a of n.aliases??[])r.add(p(a))}return r}function x(t,e){const r=new Set;for(const[i,s]of t.fields.entries()){let o,n;try{n=v(s),o=n.key}catch(m){e.push({severity:"error",code:"field_invalid",dimension:"fields",target:typeof s.key=="string"?s.key:`#${i}`,message:f(m)});continue}if(r.has(o)){e.push({severity:"error",code:"field_duplicate",dimension:"fields",target:o,message:`Field "${o}" is declared more than once; the later definition silently overwrites the earlier upsert.`});continue}r.add(o);const a=P(n);a.length>0&&e.push({severity:"error",code:"field_flag_invalid",dimension:"fields",target:o,message:`Field "${o}" declares a flag that is not one option spelling: ${a.map(b).join("; ")}. Pass one spelling per alias.`});const d=C(n);d.length>0&&e.push({severity:"error",code:"field_option_collision",dimension:"fields",target:o,message:`Field "${o}" would disable a built-in option: ${d.map(F).join("; ")}. Rename the field or narrow its commands.`});const l=I(o);l&&e.push({severity:"warning",code:"field_mcp_input_collision",dimension:"fields",target:o,message:`Field "${o}" collides with canonical MCP property "${l.property}" owned by ${l.owner}; callers must pass the custom value through ${l.nested_path}.`})}}function A(t,e,r,i){const s=new Set;for(const[o,n]of t.workflows.entries()){const a=n.type.trim().toLowerCase();if(a.length===0){i.push({severity:"error",code:"workflow_type_empty",dimension:"workflows",target:`#${o}`,message:"Workflow has an empty type; the workflow resolver drops entries without a type."});continue}const d=s.has(a);s.add(a),d?i.push({severity:"warning",code:"workflow_duplicate_type",dimension:"workflows",target:n.type,message:`Workflow type "${n.type}" is declared more than once; the later transition set wins.`}):!w.has(a)&&!e.has(a)&&i.push({severity:"warning",code:"workflow_type_unknown",dimension:"workflows",target:n.type,message:`Workflow governs type "${n.type}" which is neither a built-in type nor declared by this profile; it has no effect unless that type already exists.`});const l=new Set;for(const m of n.allowed_transitions){const u=p(m[0]),y=p(m[1]);if(u.length===0||y.length===0){i.push({severity:"error",code:"workflow_transition_malformed",dimension:"workflows",target:n.type,message:`Workflow "${n.type}" has a transition with an empty status; the workflow resolver silently drops it.`});continue}for(const c of[u,y])L.has(c)||r.has(c)||l.has(c)||(l.add(c),i.push({severity:"warning",code:"workflow_status_unknown",dimension:"workflows",target:c,message:`Workflow "${n.type}" references status "${c}" which is neither a built-in status nor declared by this profile; transitions to or from it are unreachable.`}))}}}function O(t,e){const r=new Set;for(const i of t.config){const s=k(i.key);if(s===void 0){e.push({severity:"error",code:"config_key_unknown",dimension:"config",target:i.key,message:`Config knob "${i.key}" is not a recognized setting; apply rejects it with a usage error.`});continue}r.has(s.key)?e.push({severity:"error",code:"config_duplicate",dimension:"config",target:s.key,message:`Config knob "${s.key}" is set more than once; the later value silently overwrites the earlier one.`}):r.add(s.key);const o=g(s,i.value);o.ok||e.push({severity:"error",code:"config_value_invalid",dimension:"config",target:i.key,message:o.error.message})}}function U(t,e,r){for(const i of t.templates){const s=i.options.type;if(typeof s!="string"||s.trim().length===0)continue;const o=s.trim().toLowerCase();!w.has(o)&&!e.has(o)&&r.push({severity:"warning",code:"template_type_unknown",dimension:"templates",target:i.name,message:`Template "${i.name}" creates type "${s}" which is neither a built-in type nor declared by this profile.`})}}function D(t,e){for(const[r,i]of t.packages.entries())i.spec.trim().length===0&&e.push({severity:"warning",code:"package_spec_empty",dimension:"packages",target:`#${r}`,message:"Package recommendation has an empty spec; it cannot be surfaced as an install hint."})}function X(t){const e=[];E(t,e);const r=N(t,e),i=z(t,e);x(t,e),A(t,r,i,e),O(t,e),U(t,r,e),D(t,e);const s=e.filter(n=>n.severity==="error").length,o=e.length-s;return{profile:t.name,ok:s===0,findings:e,errorCount:s,warningCount:o}}export{Q as PROFILE_LINT_CODES,J as PROFILE_LINT_DIMENSIONS,X as lintProjectProfile};
1
+ import{BUILTIN_ITEM_TYPE_VALUES as _}from"../../types/index.js";import{parseNestedSettingValue as g,resolveNestedSettingDescriptor as k}from"../config/nested-settings.js";import{normalizeAddFieldInput as v}from"../schema/fields-file.js";import{normalizeAddStatusInput as S}from"../schema/status-defs-file.js";import{normalizeAddTypeInput as $}from"../schema/item-types-file.js";import{normalizeStatusToken as p}from"../schema/type-workflows.js";import{DEFAULT_RUNTIME_STATUS_DEFINITIONS as T}from"../schema/runtime-schema.js";import{toErrorMessage as f}from"../shared/primitives.js";import{resolvePmToolCustomFieldCollision as I}from"../../sdk/cli-contracts/tool-schema.js";import{describeFieldFlagSpellingDefectLine as b,describeFieldOptionCollision as F,resolveAddFieldFlagSpellingDefects as P,resolveAddFieldOptionCollisions as C}from"../../sdk/schema/field-option-collisions.js";import{normalizeProfileLookupKey as h}from"./profile-presets.js";const J=["profile","types","statuses","fields","workflows","config","templates","packages"],Q=["profile_name_empty","profile_name_not_normalized","profile_title_empty","profile_summary_empty","type_invalid","type_duplicate","status_invalid","status_duplicate","field_invalid","field_duplicate","field_mcp_input_collision","field_option_collision","field_flag_invalid","workflow_type_empty","workflow_type_unknown","workflow_duplicate_type","workflow_transition_malformed","workflow_status_unknown","config_key_unknown","config_value_invalid","config_duplicate","template_type_unknown","package_spec_empty"],L=new Set(T.flatMap(t=>[p(t.id),...(t.aliases??[]).map(e=>p(e))]).filter(t=>t.length>0)),w=new Set(_.map(t=>t.toLowerCase()));function E(t,e){t.name.trim().length===0?e.push({severity:"error",code:"profile_name_empty",dimension:"profile",message:"Profile name must not be empty; profile resolution requires a non-blank name."}):t.name!==h(t.name)&&e.push({severity:"warning",code:"profile_name_not_normalized",dimension:"profile",target:t.name,message:`Profile name "${t.name}" is not in canonical form; resolution folds it to "${h(t.name)}" (lowercase, hyphens as underscores).`}),t.title.trim().length===0&&e.push({severity:"warning",code:"profile_title_empty",dimension:"profile",message:"Profile title is empty; list and show surfaces will render a blank title."}),t.summary.trim().length===0&&e.push({severity:"warning",code:"profile_summary_empty",dimension:"profile",message:"Profile summary is empty; list and show surfaces will render a blank archetype description."})}function N(t,e){const r=new Set,i=new Set;for(const[s,o]of t.types.entries()){let n;try{n=$(o).name}catch(d){e.push({severity:"error",code:"type_invalid",dimension:"types",target:typeof o.name=="string"?o.name:`#${s}`,message:f(d)});continue}const a=n.toLowerCase();if(i.has(a)){e.push({severity:"error",code:"type_duplicate",dimension:"types",target:n,message:`Item type "${n}" is declared more than once; the later definition silently overwrites the earlier upsert.`});continue}i.add(a),r.add(a)}return r}function z(t,e){const r=new Set,i=new Set;for(const[s,o]of t.statuses.entries()){let n;try{n=S(o)}catch(a){e.push({severity:"error",code:"status_invalid",dimension:"statuses",target:typeof o.id=="string"?o.id:`#${s}`,message:f(a)});continue}if(i.has(n.id)){e.push({severity:"error",code:"status_duplicate",dimension:"statuses",target:n.id,message:`Status "${n.id}" is declared more than once; the later definition silently overwrites the earlier upsert.`});continue}i.add(n.id),r.add(n.id);for(const a of n.aliases??[])r.add(p(a))}return r}function x(t,e){const r=new Set;for(const[i,s]of t.fields.entries()){let o,n;try{n=v(s),o=n.key}catch(m){e.push({severity:"error",code:"field_invalid",dimension:"fields",target:typeof s.key=="string"?s.key:`#${i}`,message:f(m)});continue}if(r.has(o)){e.push({severity:"error",code:"field_duplicate",dimension:"fields",target:o,message:`Field "${o}" is declared more than once; the later definition silently overwrites the earlier upsert.`});continue}r.add(o);const a=P(n,s);a.length>0&&e.push({severity:"error",code:"field_flag_invalid",dimension:"fields",target:o,message:`Field "${o}" declares a flag that is not one option spelling: ${a.map(b).join("; ")}. Pass one spelling per alias.`});const d=C(n);d.length>0&&e.push({severity:"error",code:"field_option_collision",dimension:"fields",target:o,message:`Field "${o}" would disable a built-in option: ${d.map(F).join("; ")}. Rename the field or narrow its commands.`});const l=I(o);l&&e.push({severity:"warning",code:"field_mcp_input_collision",dimension:"fields",target:o,message:`Field "${o}" collides with canonical MCP property "${l.property}" owned by ${l.owner}; callers must pass the custom value through ${l.nested_path}.`})}}function A(t,e,r,i){const s=new Set;for(const[o,n]of t.workflows.entries()){const a=n.type.trim().toLowerCase();if(a.length===0){i.push({severity:"error",code:"workflow_type_empty",dimension:"workflows",target:`#${o}`,message:"Workflow has an empty type; the workflow resolver drops entries without a type."});continue}const d=s.has(a);s.add(a),d?i.push({severity:"warning",code:"workflow_duplicate_type",dimension:"workflows",target:n.type,message:`Workflow type "${n.type}" is declared more than once; the later transition set wins.`}):!w.has(a)&&!e.has(a)&&i.push({severity:"warning",code:"workflow_type_unknown",dimension:"workflows",target:n.type,message:`Workflow governs type "${n.type}" which is neither a built-in type nor declared by this profile; it has no effect unless that type already exists.`});const l=new Set;for(const m of n.allowed_transitions){const u=p(m[0]),y=p(m[1]);if(u.length===0||y.length===0){i.push({severity:"error",code:"workflow_transition_malformed",dimension:"workflows",target:n.type,message:`Workflow "${n.type}" has a transition with an empty status; the workflow resolver silently drops it.`});continue}for(const c of[u,y])L.has(c)||r.has(c)||l.has(c)||(l.add(c),i.push({severity:"warning",code:"workflow_status_unknown",dimension:"workflows",target:c,message:`Workflow "${n.type}" references status "${c}" which is neither a built-in status nor declared by this profile; transitions to or from it are unreachable.`}))}}}function O(t,e){const r=new Set;for(const i of t.config){const s=k(i.key);if(s===void 0){e.push({severity:"error",code:"config_key_unknown",dimension:"config",target:i.key,message:`Config knob "${i.key}" is not a recognized setting; apply rejects it with a usage error.`});continue}r.has(s.key)?e.push({severity:"error",code:"config_duplicate",dimension:"config",target:s.key,message:`Config knob "${s.key}" is set more than once; the later value silently overwrites the earlier one.`}):r.add(s.key);const o=g(s,i.value);o.ok||e.push({severity:"error",code:"config_value_invalid",dimension:"config",target:i.key,message:o.error.message})}}function U(t,e,r){for(const i of t.templates){const s=i.options.type;if(typeof s!="string"||s.trim().length===0)continue;const o=s.trim().toLowerCase();!w.has(o)&&!e.has(o)&&r.push({severity:"warning",code:"template_type_unknown",dimension:"templates",target:i.name,message:`Template "${i.name}" creates type "${s}" which is neither a built-in type nor declared by this profile.`})}}function D(t,e){for(const[r,i]of t.packages.entries())i.spec.trim().length===0&&e.push({severity:"warning",code:"package_spec_empty",dimension:"packages",target:`#${r}`,message:"Package recommendation has an empty spec; it cannot be surfaced as an install hint."})}function X(t){const e=[];E(t,e);const r=N(t,e),i=z(t,e);x(t,e),A(t,r,i,e),O(t,e),U(t,r,e),D(t,e);const s=e.filter(n=>n.severity==="error").length,o=e.length-s;return{profile:t.name,ok:s===0,findings:e,errorCount:s,warningCount:o}}export{Q as PROFILE_LINT_CODES,J as PROFILE_LINT_DIMENSIONS,X as lintProjectProfile};
2
2
  //# sourceMappingURL=profile-lint.js.map
@@ -1,4 +1,4 @@
1
- import type{ItemTypeDefinition,RuntimeFieldCommand,RuntimeFieldValueSchema,RuntimeFieldType,RuntimeSchemaSettings,RuntimeStatusDefinition,RuntimeStatusRole,RuntimeWorkflowDefinition}from "../../types/index.js";export type{RuntimeFieldCommand}from "../../types/index.js";
1
+ import type{ItemTypeDefinition,RuntimeFieldCommand,RuntimeFieldDefinition,RuntimeFieldValueSchema,RuntimeFieldType,RuntimeSchemaSettings,RuntimeStatusDefinition,RuntimeStatusRole,RuntimeWorkflowDefinition}from "../../types/index.js";export type{RuntimeFieldCommand}from "../../types/index.js";
2
2
  /** Fallback runtime schema file paths used when callers do not provide an override. */
3
3
  export declare const DEFAULT_RUNTIME_SCHEMA_FILE_PATHS:Readonly<{types:"schema/types.json";statuses:"schema/statuses.json";fields:"schema/fields.json";workflows:"schema/workflows.json";}>;
4
4
  /** Fallback runtime workflow used when callers do not provide an override. */
@@ -101,8 +101,27 @@ warnings:string[];
101
101
  created_paths:string[];}
102
102
  /** Normalize a stored field flag token as the registry reads it: trimmed, lower-cased, separators as hyphens, leading dashes removed. */
103
103
  export declare function normalizeCliToken(value:unknown):string;
104
+ /** Why the field registry drops a whole stored definition (pm-x9r2h3). */
105
+ export type RuntimeFieldDefinitionDropReason="not_an_object"|"key_empty"|"metadata_key_empty"|"cli_flag_empty"|"value_schema_invalid";
106
+ /**
107
+ * What the field registry discards from one stored definition (pm-x9r2h3):
108
+ * the whole definition, or members it ignores or replaces while keeping it.
109
+ */
110
+ export interface RuntimeFieldDefinitionLoss{
111
+ /** Set when the registry drops the whole definition. */
112
+ dropped?:RuntimeFieldDefinitionDropReason;
113
+ /** One line per member the registry ignores or replaces, such as a blank alias. */
114
+ ignored:string[];}
115
+ /**
116
+ * Resolve one stored definition and record what the registry discards from
117
+ * it. The registry and `pm validate` both read this one function, so a
118
+ * diagnostic can never disagree with what the registry keeps.
119
+ */
120
+ export declare function inspectRuntimeFieldDefinition(definition:unknown):{resolved:RuntimeFieldDefinitionResolved|null;loss:RuntimeFieldDefinitionLoss;};
104
121
  /** Implements normalize runtime schema settings for the public runtime surface of this module. */
105
122
  export declare function normalizeRuntimeSchemaSettings(schema:Partial<RuntimeSchemaSettings>|undefined):RuntimeSchemaSettings;
123
+ /** The definitions list of a parsed fields file, in any of its accepted shapes; undefined for any other shape. */
124
+ export declare function readFieldsFromSchemaFile(parsed:unknown):RuntimeFieldDefinition[]|undefined;
106
125
  /** Implements file path for schema section for the public runtime surface of this module. */
107
126
  export declare function filePathForSchemaSection(pmRoot:string,configuredPath:string|undefined,fallbackPath:string):string;
108
127
  /** Resolves the active tracker's `schema/types.json` path so user-facing hints (e.g. the invalid-type error) point at the real `--pm-path` location instead of the hardcoded `.agents/pm` default. Mirrors how `pm schema add/remove-type` report their target path. */
@@ -1,3 +1,3 @@
1
- import U from"node:path";import{pathExists as W,readFileIfExists as v}from"../fs/fs-utils.js";import{createFileAtomic as K}from"../fs/atomic-create.js";import{DEFAULT_STATUS_DEFINITIONS as V,DEFAULT_WORKFLOW_DEFINITION as H}from"../shared/constants.js";import{RUNTIME_FIELD_COMMAND_VALUES as Y,RUNTIME_FIELD_TYPE_VALUES as $,RUNTIME_STATUS_ROLE_VALUES as J,RUNTIME_UNKNOWN_FIELD_POLICY_VALUES as B,STATUS_VALUES as X}from"../../types/index.js";import{normalizeStatusToken as k}from"./status-token.js";const m=Object.freeze({types:"schema/types.json",statuses:"schema/statuses.json",fields:"schema/fields.json",workflows:"schema/workflows.json"}),O=H,D=V,Z=["create","update"],G=new Set(J),Q=new Set($),ee=new Set(Y),te=new Set(B),ne=new Set(["string","number","boolean","array","object"]),re=16;function R(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const se=[e=>e.type===void 0||typeof e.type=="string"&&ne.has(e.type),e=>!Object.hasOwn(e,"const")||E(e.const),e=>e.enum===void 0||Array.isArray(e.enum)&&e.enum.every(t=>E(t)),e=>e.min_length===void 0||Number.isInteger(e.min_length)&&e.min_length>=0,e=>e.min_items===void 0||Number.isInteger(e.min_items)&&e.min_items>=0,e=>e.format===void 0||e.format==="date-time",e=>e.required===void 0||Array.isArray(e.required)&&e.required.every(t=>typeof t=="string"&&t.length>0),e=>e.additional_properties===void 0||typeof e.additional_properties=="boolean",e=>e.properties===void 0||R(e.properties),e=>e.one_of===void 0||Array.isArray(e.one_of)&&e.one_of.length>0];function E(e,t=new Set){if(e===null||typeof e=="string"||typeof e=="boolean")return!0;if(typeof e=="number")return Number.isFinite(e);if(typeof e!="object"||t.has(e))return!1;t.add(e);const n=Array.isArray(e)?e.every(r=>E(r,t)):Object.values(e).every(r=>E(r,t));return t.delete(e),n}function I(e,t=0,n=new Set){if(!R(e)||t>re||n.has(e))return;n.add(e);const r=e,s=r.type,o=r.enum,u=r.one_of,a=r.properties,i=r.items,d=r.required,c=r.min_length,l=r.min_items,p=r.format,w=r.additional_properties;if(!se.every(_=>_(r))){n.delete(e);return}const h=a===void 0?void 0:Object.fromEntries(Object.entries(a).map(([_,z])=>[_,I(z,t+1,n)])),A=i===void 0?void 0:I(i,t+1,n),g=u===void 0?void 0:u.map(_=>I(_,t+1,n));if([...Object.values(h??{}),...i===void 0?[]:[A],...g??[]].some(_=>_===void 0)){n.delete(e);return}return n.delete(e),Object.fromEntries(Object.entries({type:s,const:Object.hasOwn(r,"const")?r.const:void 0,enum:o,min_length:c,min_items:l,format:p,properties:h,required:d===void 0?void 0:[...new Set(d)],additional_properties:w,items:A,one_of:g}).filter(([,_])=>_!==void 0))}function T(e){const t=Array.isArray(e)?e:[];return[...new Set(t.map(n=>typeof n=="string"?n.trim():"").filter(n=>n.length>0))].sort((n,r)=>n.localeCompare(r))}function f(e){if(typeof e!="string"||e.length===0)return;const t=k(e);return t.length>0?t:void 0}function ie(e){return e.startsWith("--")?e.slice(2):e}function M(e){return typeof e=="string"?ie(e.trim().toLowerCase().replaceAll(/[\s_]+/g,"-")):""}function j(e){return e.replaceAll("_","-")}function oe(e){const t=e.replaceAll(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(s=>s.length>0).map(s=>s.toLowerCase());if(t.length===0)return e;const[n,...r]=t;return`${n}${r.map(s=>`${s.slice(0,1).toUpperCase()}${s.slice(1)}`).join("")}`}function L(e,t){const n=f(e.id);if(!n)return null;const r=[...new Set(T(e.aliases).map(k).filter(a=>a.length>0))].sort((a,i)=>a.localeCompare(i)),s=T(e.roles).filter(a=>G.has(a)),o=e.description?.trim(),u=typeof e.order=="number"&&Number.isFinite(e.order)?e.order:t;return{id:n,aliases:r,roles:s,description:o&&o.length>0?o:void 0,order:u}}function ae(e){return{draft_status:f(e?.draft_status),open_status:f(e?.open_status),in_progress_status:f(e?.in_progress_status),blocked_status:f(e?.blocked_status),close_status:f(e?.close_status),canceled_status:f(e?.canceled_status)}}function C(e,t){if(!Array.isArray(t)||t.length!==2)return;const n=k(t[0]),r=k(t[1]);n.length===0||r.length===0||e.pairs.some(s=>s[0]===n&&s[1]===r)||e.pairs.push([n,r])}function le(e){const t=typeof e?.type=="string"?e.type.trim():"";if(t.length===0||!Array.isArray(e?.allowed_transitions))return null;const n={type:t,pairs:[],denyAll:e.allowed_transitions.length===0};for(const r of e.allowed_transitions)C(n,r);return{typeKey:t.toLowerCase(),record:n}}function ue(e){if(!Array.isArray(e)||e.length===0)return;const t=new Map;for(const r of e){const s=le(r);if(s===null)continue;const o=t.get(s.typeKey)??s.record;o.denyAll||=s.record.denyAll;for(const u of s.record.pairs)C(o,u);t.set(s.typeKey,o)}const n=[];for(const r of t.values())(r.pairs.length>0||r.denyAll)&&n.push({type:r.type,allowed_transitions:r.pairs});return n.sort((r,s)=>r.type.localeCompare(s.type)),n.length>0?n:void 0}function P(e){const t=k(e.key??"");if(!t)return null;const n=k(e.metadata_key??e.front_matter_key??t),r=M(e.cli_flag??j(t));if(!r)return null;const s=T(e.cli_aliases).map(l=>M(l)).filter(l=>l.length>0&&l!==r),o=typeof e.type=="string"?e.type.trim().toLowerCase():"string",u=Q.has(o)?o:"string",a=(()=>{const l=T(e.commands).filter(p=>ee.has(p));return l.length>0?l:[...Z]})(),i=e.description?.trim(),d=T(e.required_types),c=e.value_schema===void 0?void 0:I(e.value_schema);return e.value_schema!==void 0&&c===void 0?null:{key:t,metadata_key:n,cli_flag:r,cli_aliases:s,description:i&&i.length>0?i:void 0,type:u,commands:a,repeatable:[e.repeatable===!0,u==="string_array"].includes(!0),required:e.required===!0,required_on_create:e.required_on_create===!0,required_types:d,allow_unset:e.allow_unset!==!1,value_schema:c}}function de(e){const t=new Map;for(const[r,s]of e.entries()){const o=L(s,r);o&&t.set(o.id,o)}const n=q([...t.values()]);return n.length>0?n:q(D.map((r,s)=>L(r,s)).filter(r=>r!==null))}function q(e){return e.sort((t,n)=>t.order===n.order?t.id.localeCompare(n.id):t.order-n.order)}function ce(e){const t=new Map;for(const n of e??[]){const r=P(n);r&&t.set(r.key,r)}return[...t.values()].sort((n,r)=>n.key.localeCompare(r.key))}function fe(e){return{id:e.id,aliases:e.aliases.length>0?[...e.aliases]:void 0,roles:e.roles.length>0?[...e.roles]:void 0,description:e.description,order:e.order}}function _e(e){return{key:e.key,metadata_key:e.metadata_key!==e.key?e.metadata_key:void 0,cli_flag:e.cli_flag!==j(e.key)?e.cli_flag:void 0,cli_aliases:e.cli_aliases.length>0?[...e.cli_aliases]:void 0,description:e.description,type:e.type,commands:[...e.commands],repeatable:e.repeatable===!0?!0:void 0,required:e.required===!0?!0:void 0,required_on_create:e.required_on_create===!0?!0:void 0,required_types:e.required_types.length>0?[...e.required_types]:void 0,allow_unset:e.allow_unset===!1?!1:void 0,value_schema:e.value_schema}}function me(e){const t=typeof e=="string"?e.trim().toLowerCase():"allow";return te.has(t)?t:"allow"}function F(e){const t={...m,...e?.files},n=e?.statuses&&e.statuses.length>0?e.statuses:D,r=de(n),s=ce(e?.fields);return{version:typeof e?.version=="number"&&Number.isFinite(e.version)?Math.floor(e.version):1,files:t,statuses:r.map(fe),fields:s.map(_e),workflow:{...O,...ae(e?.workflow)},type_workflows:ue(e?.type_workflows),unknown_field_policy:me(e?.unknown_field_policy)}}function pe(e,t,n){try{return JSON.parse(e)}catch{n.push(t);return}}function ye(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;const t=e;if(Array.isArray(t.definitions))return t.definitions;if(typeof t.item_types=="object"&&t.item_types!==null){const n=t.item_types;if(Array.isArray(n.definitions))return n.definitions}}function we(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;const t=e;if(Array.isArray(t.statuses))return t.statuses;if(Array.isArray(t.definitions))return t.definitions}function Se(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;const t=e;if(Array.isArray(t.fields))return t.fields;if(Array.isArray(t.definitions))return t.definitions}function he(e){if(typeof e!="object"||e===null||Array.isArray(e))return;const t=e;return typeof t.workflow=="object"&&t.workflow!==null&&!Array.isArray(t.workflow)?t.workflow:typeof t.workflows=="object"&&t.workflows!==null&&!Array.isArray(t.workflows)?t.workflows:t}function Ae(e){if(typeof e!="object"||e===null||Array.isArray(e))return;const t=e;if(Array.isArray(t.type_workflows))return t.type_workflows}function y(e,t,n){const r=t?.trim()||n;return U.isAbsolute(r)?r:U.join(e,r)}function Le(e,t){return y(e,t.files.types,m.types)}async function Ne(e,t){const n=F(t),r=[{path:y(e,n.files.types,m.types),seed:{definitions:[]}},{path:y(e,n.files.statuses,m.statuses),seed:{statuses:D}},{path:y(e,n.files.fields,m.fields),seed:{fields:[]}},{path:y(e,n.files.workflows,m.workflows),seed:{workflow:O}}],s=[];for(const o of r)await W(o.path)||await K(o.path,`${JSON.stringify(o.seed,null,2)}
2
- `)&&s.push(o.path);return{created_paths:s}}async function Ue(e,t){const n=F(t),r=[],s=y(e,n.files.types,m.types),o=y(e,n.files.statuses,m.statuses),u=y(e,n.files.fields,m.fields),a=y(e,n.files.workflows,m.workflows);let i,d,c,l,p;const w=async(z,x)=>{const N=await v(z);if(N!==null)return pe(N,x,r)},h=await w(s,"runtime_schema_types_invalid_json");h!==void 0&&(i=ye(h),i===void 0&&r.push("runtime_schema_types_invalid_shape"));const A=await w(o,"runtime_schema_statuses_invalid_json");A!==void 0&&(d=we(A),d===void 0&&r.push("runtime_schema_statuses_invalid_shape"));const g=await w(u,"runtime_schema_fields_invalid_json");g!==void 0&&(c=Se(g),c===void 0&&r.push("runtime_schema_fields_invalid_shape"));const S=await w(a,"runtime_schema_workflows_invalid_json");return S!==void 0&&(l=he(S),l===void 0&&r.push("runtime_schema_workflows_invalid_shape"),p=Ae(S)),{schema:F({...n,statuses:[...n.statuses,...d??[]],fields:[...n.fields,...c??[]],workflow:{...n.workflow,...l},type_workflows:[...n.type_workflows??[],...p??[]]}),type_definitions_from_file:i,warnings:r,created_paths:[]}}function b(e,t,n,r=!1){const o=n.map(a=>f(a)).filter(a=>typeof a=="string").find(a=>e.some(i=>i.id===a));if(r&&o!==void 0)return o;const u=e.find(a=>a.roles.includes(t));return u!==void 0?u.id:o??e[0]?.id}function ge(e){const t=new Map,n=new Map;for(const r of e){n.set(r.id,r),t.set(r.id,r.id),t.set(r.id.replaceAll("_","-"),r.id),t.set(r.id.replaceAll("_"," "),r.id);for(const s of r.aliases)t.set(s,r.id),t.set(s.replaceAll("_","-"),r.id),t.set(s.replaceAll("_"," "),r.id)}return{aliasToId:t,byId:n}}function ke(e){const t={activeStatuses:new Set,blockedStatuses:new Set,draftStatuses:new Set,terminalCanceledStatuses:new Set,terminalDoneStatuses:new Set,terminalStatuses:new Set};for(const n of e){const r=new Set(n.roles);(r.has("terminal")||r.has("terminal_done")||r.has("terminal_canceled"))&&t.terminalStatuses.add(n.id),r.has("terminal_done")&&t.terminalDoneStatuses.add(n.id),r.has("terminal_canceled")&&t.terminalCanceledStatuses.add(n.id),r.has("active")&&t.activeStatuses.add(n.id),r.has("blocked")&&t.blockedStatuses.add(n.id),r.has("draft")&&t.draftStatuses.add(n.id)}return t}function Oe(e){const t=F(e),n=t.statuses.map((S,_)=>L(S,_)).filter(S=>S!==null),{aliasToId:r,byId:s}=ge(n),{activeStatuses:o,blockedStatuses:u,draftStatuses:a,terminalCanceledStatuses:i,terminalDoneStatuses:d,terminalStatuses:c}=ke(n),l=t.workflow,p=f(l.open_status)??b(n,"default_open",["open","in_progress",X[0]]),w=f(l.in_progress_status)??b(n,"active",["in_progress","in-progress",p],!0),h=f(l.blocked_status)??b(n,"blocked",["blocked"]),A=f(l.close_status)??b(n,"default_close",["closed","done","complete"]),g=f(l.canceled_status)??b(n,"default_cancel",["canceled","cancelled"]);return{definitions:n,by_id:s,alias_to_id:r,terminal_statuses:c,terminal_done_statuses:d,terminal_canceled_statuses:i,active_statuses:o,blocked_statuses:u,draft_statuses:a,open_status:p,in_progress_status:w,blocked_status:h,close_status:A,canceled_status:g}}function Te(e,t){const n=k(e);if(n)return t.alias_to_id.get(n)}function Re(e){const t=F(e),n=new Map,r=t.fields.map(i=>P(i)).filter(i=>i!==null);for(const i of r)n.set(i.key,i);const s=[...n.values()].sort((i,d)=>i.key.localeCompare(d.key)),o=new Map,u=new Map,a=new Map;for(const i of s){o.set(i.key,i),u.set(i.cli_flag,i);for(const d of i.cli_aliases)u.set(d,i);for(const d of i.commands){const c=a.get(d)??[];c.push(i),a.set(d,c)}}for(const[i,d]of a.entries())d.sort((c,l)=>c.key.localeCompare(l.key)),a.set(i,d);return{definitions:s,by_key:o,by_cli_token:u,command_to_fields:a}}function Me(e){return oe(e.key)}function je(e,t){const n=Te(e,t);return n?t.terminal_statuses.has(n):!1}export{m as DEFAULT_RUNTIME_SCHEMA_FILE_PATHS,D as DEFAULT_RUNTIME_STATUS_DEFINITIONS,O as DEFAULT_RUNTIME_WORKFLOW,Ne as ensureRuntimeSchemaFileScaffold,y as filePathForSchemaSection,Ue as loadRuntimeSchemaFromOptionalFiles,M as normalizeCliToken,F as normalizeRuntimeSchemaSettings,Te as normalizeStatusInputWithRegistry,Le as resolveItemTypesFilePath,Re as resolveRuntimeFieldRegistry,Oe as resolveRuntimeStatusRegistry,Me as runtimeFieldOptionTarget,je as statusIsTerminal};
1
+ import K from"node:path";import{pathExists as H,readFileIfExists as J}from"../fs/fs-utils.js";import{createFileAtomic as X}from"../fs/atomic-create.js";import{DEFAULT_STATUS_DEFINITIONS as Z,DEFAULT_WORKFLOW_DEFINITION as G,ITEM_METADATA_KEY_ORDER as Q}from"../shared/constants.js";import{RUNTIME_FIELD_COMMAND_VALUES as ee,RUNTIME_FIELD_TYPE_VALUES as te,RUNTIME_STATUS_ROLE_VALUES as ne,RUNTIME_UNKNOWN_FIELD_POLICY_VALUES as re,STATUS_VALUES as se}from"../../types/index.js";import{BUILTIN_FIELD_KEYS as ie}from"./fields-file.js";import{normalizeStatusToken as p}from"./status-token.js";const m=Object.freeze({types:"schema/types.json",statuses:"schema/statuses.json",fields:"schema/fields.json",workflows:"schema/workflows.json"}),q=G,z=Z,oe=["create","update"],ae=new Set(ne),le=new Set(te),x=new Set(ee),ue=new Set(re),de=new Set(["string","number","boolean","array","object"]),ce=16;function T(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const fe=[e=>e.type===void 0||typeof e.type=="string"&&de.has(e.type),e=>!Object.hasOwn(e,"const")||I(e.const),e=>e.enum===void 0||Array.isArray(e.enum)&&e.enum.every(t=>I(t)),e=>e.min_length===void 0||Number.isInteger(e.min_length)&&e.min_length>=0,e=>e.min_items===void 0||Number.isInteger(e.min_items)&&e.min_items>=0,e=>e.format===void 0||e.format==="date-time",e=>e.required===void 0||Array.isArray(e.required)&&e.required.every(t=>typeof t=="string"&&t.length>0),e=>e.additional_properties===void 0||typeof e.additional_properties=="boolean",e=>e.properties===void 0||T(e.properties),e=>e.one_of===void 0||Array.isArray(e.one_of)&&e.one_of.length>0];function I(e,t=new Set){if(e===null||typeof e=="string"||typeof e=="boolean")return!0;if(typeof e=="number")return Number.isFinite(e);if(typeof e!="object"||t.has(e))return!1;t.add(e);const n=Array.isArray(e)?e.every(r=>I(r,t)):Object.values(e).every(r=>I(r,t));return t.delete(e),n}function L(e,t=0,n=new Set){if(!T(e)||t>ce||n.has(e))return;n.add(e);const r=e,s=r.type,o=r.enum,l=r.one_of,a=r.properties,i=r.items,u=r.required,f=r.min_length,d=r.min_items,h=r.format,S=r.additional_properties;if(!fe.every(_=>_(r))){n.delete(e);return}const g=a===void 0?void 0:Object.fromEntries(Object.entries(a).map(([_,O])=>[_,L(O,t+1,n)])),A=i===void 0?void 0:L(i,t+1,n),k=l===void 0?void 0:l.map(_=>L(_,t+1,n));if([...Object.values(g??{}),...i===void 0?[]:[A],...k??[]].some(_=>_===void 0)){n.delete(e);return}return n.delete(e),Object.fromEntries(Object.entries({type:s,const:Object.hasOwn(r,"const")?r.const:void 0,enum:o,min_length:f,min_items:d,format:h,properties:g,required:u===void 0?void 0:[...new Set(u)],additional_properties:S,items:A,one_of:k}).filter(([,_])=>_!==void 0))}function E(e){const t=Array.isArray(e)?e:[];return[...new Set(t.map(n=>typeof n=="string"?n.trim():"").filter(n=>n.length>0))].sort((n,r)=>n.localeCompare(r))}function c(e){if(typeof e!="string"||e.length===0)return;const t=p(e);return t.length>0?t:void 0}function _e(e){return e.replace(/^(?:--)+/u,"")}function N(e){return typeof e=="string"?_e(e.trim().toLowerCase().replaceAll(/[\s_]+/g,"-")):""}function $(e){return e.replaceAll("_","-")}function me(e){const t=e.replaceAll(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(s=>s.length>0).map(s=>s.toLowerCase());if(t.length===0)return e;const[n,...r]=t;return`${n}${r.map(s=>`${s.slice(0,1).toUpperCase()}${s.slice(1)}`).join("")}`}function U(e,t){const n=c(e.id);if(!n)return null;const r=[...new Set(E(e.aliases).map(p).filter(a=>a.length>0))].sort((a,i)=>a.localeCompare(i)),s=E(e.roles).filter(a=>ae.has(a)),o=e.description?.trim(),l=typeof e.order=="number"&&Number.isFinite(e.order)?e.order:t;return{id:n,aliases:r,roles:s,description:o&&o.length>0?o:void 0,order:l}}function pe(e){return{draft_status:c(e?.draft_status),open_status:c(e?.open_status),in_progress_status:c(e?.in_progress_status),blocked_status:c(e?.blocked_status),close_status:c(e?.close_status),canceled_status:c(e?.canceled_status)}}function W(e,t){if(!Array.isArray(t)||t.length!==2)return;const n=p(t[0]),r=p(t[1]);n.length===0||r.length===0||e.pairs.some(s=>s[0]===n&&s[1]===r)||e.pairs.push([n,r])}function ye(e){const t=typeof e?.type=="string"?e.type.trim():"";if(t.length===0||!Array.isArray(e?.allowed_transitions))return null;const n={type:t,pairs:[],denyAll:e.allowed_transitions.length===0};for(const r of e.allowed_transitions)W(n,r);return{typeKey:t.toLowerCase(),record:n}}function Se(e){if(!Array.isArray(e)||e.length===0)return;const t=new Map;for(const r of e){const s=ye(r);if(s===null)continue;const o=t.get(s.typeKey)??s.record;o.denyAll||=s.record.denyAll;for(const l of s.record.pairs)W(o,l);t.set(s.typeKey,o)}const n=[];for(const r of t.values())(r.pairs.length>0||r.denyAll)&&n.push({type:r.type,allowed_transitions:r.pairs});return n.sort((r,s)=>r.type.localeCompare(s.type)),n.length>0?n:void 0}function M(e){try{return JSON.stringify(e)??String(e)}catch{try{return String(e)}catch{return"a value that cannot be shown"}}}function j(e,t,n,r){return t===void 0?[]:Array.isArray(t)?t.filter(s=>typeof s!="string"||!n(s.trim())).map(s=>`${e}: ${M(s)} is not ${r}`):[`${e}: is not a list`]}const we=["repeatable","required","required_on_create","allow_unset"];function he(e,t){return we.flatMap(n=>{const r=e[n];return r===void 0||typeof r=="boolean"?[]:[`${n}: ${M(r)} is not a boolean, so it reads as ${String(t[n])}`]})}const ge=new Set(["type","const","enum","min_length","min_items","format","properties","required","additional_properties","items","one_of"]);function D(e,t){if(!T(e))return[];const n=e;return[...Object.keys(n).filter(r=>!ge.has(r)).map(r=>`${t}.${r}: is not a value schema keyword, so it is not enforced`),...T(n.properties)?Object.entries(n.properties).flatMap(([r,s])=>D(s,`${t}.properties.${r}`)):[],...D(n.items,`${t}.items`),...Array.isArray(n.one_of)?n.one_of.flatMap((r,s)=>D(r,`${t}.one_of[${s}]`)):[]]}function R(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function C(e,t,n){if(e===void 0)return;const r=e.filter(s=>!t(s)).length;return r===0?e:(n.warnings.push(`${n.warningKey}:${r}`),n.keepPositions?e.map(s=>t(s)?s:{}):e.filter(s=>t(s)))}function Ae(e){return R(e)&&typeof e.name=="string"}function ke(e){const t=typeof e.type=="string"?e.type.trim().toLowerCase():"string";return le.has(t)?t:"string"}function Ee(e){const t=E(e.commands).filter(n=>x.has(n));return t.length>0?t:[...oe]}function v(e){return e.metadata_key!=null?{member:"metadata_key",value:e.metadata_key}:e.front_matter_key==null?void 0:{member:"front_matter_key",value:e.front_matter_key}}const be=new Set([...ie,...Q]);function Fe(e,t){const n=v(e);return n!==void 0&&p(n.value).length===0&&be.has(t)}function Te(e,t){const n=p(v(e)?.value);return n.length>0?n:t}function Ie(e,t){const n=typeof e.type=="string"&&e.type.trim().toLowerCase()===t.type,r=v(e);return[...r===void 0||p(r.value).length>0?[]:[`${r.member}: ${M(r.value)} names no item key, so values are stored under the field key`],...j("cli_aliases",e.cli_aliases,s=>N(s).length>0,"a flag spelling"),...e.type===void 0||n?[]:[`type: ${M(e.type)} is not a field type, so the field reads as string`],...j("commands",e.commands,s=>x.has(s),"a field command"),...j("required_types",e.required_types,s=>s.length>0,"a type name"),...e.description===void 0||typeof e.description=="string"?[]:["description: is not a string"],...he(e,t),...D(e.value_schema,"value_schema")]}function Le(e){const t=i=>({resolved:null,loss:{dropped:i,ignored:[]}});if(!R(e))return t("not_an_object");const n=p(e.key??"");if(!n)return t("key_empty");if(Fe(e,n))return t("metadata_key_empty");const r=N(e.cli_flag??$(n));if(!r)return t("cli_flag_empty");const s=e.value_schema===void 0?void 0:L(e.value_schema);if(e.value_schema!==void 0&&s===void 0)return t("value_schema_invalid");const o=ke(e),l=typeof e.description=="string"?e.description.trim():void 0,a={key:n,metadata_key:Te(e,n),cli_flag:r,cli_aliases:E(e.cli_aliases).map(i=>N(i)).filter(i=>i.length>0&&i!==r),description:l&&l.length>0?l:void 0,type:o,commands:Ee(e),repeatable:[e.repeatable===!0,o==="string_array"].includes(!0),required:e.required===!0,required_on_create:e.required_on_create===!0,required_types:E(e.required_types),allow_unset:e.allow_unset!==!1,value_schema:s};return{resolved:a,loss:{ignored:Ie(e,a)}}}function V(e){return Le(e).resolved}function Me(e){const t=new Map;for(const[r,s]of e.entries()){const o=U(s,r);o&&t.set(o.id,o)}const n=B([...t.values()]);return n.length>0?n:B(z.map((r,s)=>U(r,s)).filter(r=>r!==null))}function B(e){return e.sort((t,n)=>t.order===n.order?t.id.localeCompare(n.id):t.order-n.order)}function De(e){const t=new Map;for(const n of e??[]){const r=V(n);r&&t.set(r.key,r)}return[...t.values()].sort((n,r)=>n.key.localeCompare(r.key))}function Re(e){return{id:e.id,aliases:e.aliases.length>0?[...e.aliases]:void 0,roles:e.roles.length>0?[...e.roles]:void 0,description:e.description,order:e.order}}function Oe(e){return{key:e.key,metadata_key:e.metadata_key!==e.key?e.metadata_key:void 0,cli_flag:e.cli_flag!==$(e.key)?e.cli_flag:void 0,cli_aliases:e.cli_aliases.length>0?[...e.cli_aliases]:void 0,description:e.description,type:e.type,commands:[...e.commands],repeatable:e.repeatable===!0?!0:void 0,required:e.required===!0?!0:void 0,required_on_create:e.required_on_create===!0?!0:void 0,required_types:e.required_types.length>0?[...e.required_types]:void 0,allow_unset:e.allow_unset===!1?!1:void 0,value_schema:e.value_schema}}function ze(e){const t=typeof e=="string"?e.trim().toLowerCase():"allow";return ue.has(t)?t:"allow"}function b(e){const t={...m,...e?.files},n=e?.statuses&&e.statuses.length>0?e.statuses:z,r=Me(n),s=De(e?.fields);return{version:typeof e?.version=="number"&&Number.isFinite(e.version)?Math.floor(e.version):1,files:t,statuses:r.map(Re),fields:s.map(Oe),workflow:{...q,...pe(e?.workflow)},type_workflows:Se(e?.type_workflows),unknown_field_policy:ze(e?.unknown_field_policy)}}function Ne(e,t,n){try{return JSON.parse(e)}catch{n.push(t);return}}function Ue(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;const t=e;if(Array.isArray(t.definitions))return t.definitions;if(typeof t.item_types=="object"&&t.item_types!==null){const n=t.item_types;if(Array.isArray(n.definitions))return n.definitions}}function je(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;const t=e;if(Array.isArray(t.statuses))return t.statuses;if(Array.isArray(t.definitions))return t.definitions}function Ce(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;const t=e;if(Array.isArray(t.fields))return t.fields;if(Array.isArray(t.definitions))return t.definitions}function ve(e){if(typeof e!="object"||e===null||Array.isArray(e))return;const t=e;return typeof t.workflow=="object"&&t.workflow!==null&&!Array.isArray(t.workflow)?t.workflow:typeof t.workflows=="object"&&t.workflows!==null&&!Array.isArray(t.workflows)?t.workflows:t}function Pe(e){if(typeof e!="object"||e===null||Array.isArray(e))return;const t=e;if(Array.isArray(t.type_workflows))return t.type_workflows}function y(e,t,n){const r=t?.trim()||n;return K.isAbsolute(r)?r:K.join(e,r)}function Xe(e,t){return y(e,t.files.types,m.types)}async function Ze(e,t){const n=b(t),r=[{path:y(e,n.files.types,m.types),seed:{definitions:[]}},{path:y(e,n.files.statuses,m.statuses),seed:{statuses:z}},{path:y(e,n.files.fields,m.fields),seed:{fields:[]}},{path:y(e,n.files.workflows,m.workflows),seed:{workflow:q}}],s=[];for(const o of r)await H(o.path)||await X(o.path,`${JSON.stringify(o.seed,null,2)}
2
+ `)&&s.push(o.path);return{created_paths:s}}async function Ge(e,t){const n=b(t),r=[],s=y(e,n.files.types,m.types),o=y(e,n.files.statuses,m.statuses),l=y(e,n.files.fields,m.fields),a=y(e,n.files.workflows,m.workflows);let i,u,f,d,h;const S=async(O,Y)=>{const P=await J(O);if(P!==null)return Ne(P,Y,r)},g=await S(s,"runtime_schema_types_invalid_json");g!==void 0&&(i=C(Ue(g),Ae,{warningKey:"runtime_schema_types_entry_invalid",warnings:r,keepPositions:!1}),i===void 0&&r.push("runtime_schema_types_invalid_shape"));const A=await S(o,"runtime_schema_statuses_invalid_json");A!==void 0&&(u=C(je(A),R,{warningKey:"runtime_schema_statuses_entry_invalid",warnings:r,keepPositions:!0}),u===void 0&&r.push("runtime_schema_statuses_invalid_shape"));const k=await S(l,"runtime_schema_fields_invalid_json");k!==void 0&&(f=C(Ce(k),R,{warningKey:"runtime_schema_fields_entry_invalid",warnings:r,keepPositions:!1}),f===void 0&&r.push("runtime_schema_fields_invalid_shape"));const w=await S(a,"runtime_schema_workflows_invalid_json");return w!==void 0&&(d=ve(w),d===void 0&&r.push("runtime_schema_workflows_invalid_shape"),h=Pe(w)),{schema:b({...n,statuses:[...n.statuses,...u??[]],fields:[...n.fields,...f??[]],workflow:{...n.workflow,...d},type_workflows:[...n.type_workflows??[],...h??[]]}),type_definitions_from_file:i,warnings:r,created_paths:[]}}function F(e,t,n,r=!1){const o=n.map(a=>c(a)).filter(a=>typeof a=="string").find(a=>e.some(i=>i.id===a));if(r&&o!==void 0)return o;const l=e.find(a=>a.roles.includes(t));return l!==void 0?l.id:o??e[0]?.id}function Ke(e){const t=new Map,n=new Map;for(const r of e){n.set(r.id,r),t.set(r.id,r.id),t.set(r.id.replaceAll("_","-"),r.id),t.set(r.id.replaceAll("_"," "),r.id);for(const s of r.aliases)t.set(s,r.id),t.set(s.replaceAll("_","-"),r.id),t.set(s.replaceAll("_"," "),r.id)}return{aliasToId:t,byId:n}}function qe(e){const t={activeStatuses:new Set,blockedStatuses:new Set,draftStatuses:new Set,terminalCanceledStatuses:new Set,terminalDoneStatuses:new Set,terminalStatuses:new Set};for(const n of e){const r=new Set(n.roles);(r.has("terminal")||r.has("terminal_done")||r.has("terminal_canceled"))&&t.terminalStatuses.add(n.id),r.has("terminal_done")&&t.terminalDoneStatuses.add(n.id),r.has("terminal_canceled")&&t.terminalCanceledStatuses.add(n.id),r.has("active")&&t.activeStatuses.add(n.id),r.has("blocked")&&t.blockedStatuses.add(n.id),r.has("draft")&&t.draftStatuses.add(n.id)}return t}function Qe(e){const t=b(e),n=t.statuses.map((w,_)=>U(w,_)).filter(w=>w!==null),{aliasToId:r,byId:s}=Ke(n),{activeStatuses:o,blockedStatuses:l,draftStatuses:a,terminalCanceledStatuses:i,terminalDoneStatuses:u,terminalStatuses:f}=qe(n),d=t.workflow,h=c(d.open_status)??F(n,"default_open",["open","in_progress",se[0]]),S=c(d.in_progress_status)??F(n,"active",["in_progress","in-progress",h],!0),g=c(d.blocked_status)??F(n,"blocked",["blocked"]),A=c(d.close_status)??F(n,"default_close",["closed","done","complete"]),k=c(d.canceled_status)??F(n,"default_cancel",["canceled","cancelled"]);return{definitions:n,by_id:s,alias_to_id:r,terminal_statuses:f,terminal_done_statuses:u,terminal_canceled_statuses:i,active_statuses:o,blocked_statuses:l,draft_statuses:a,open_status:h,in_progress_status:S,blocked_status:g,close_status:A,canceled_status:k}}function xe(e,t){const n=p(e);if(n)return t.alias_to_id.get(n)}function et(e){const t=b(e),n=new Map,r=t.fields.map(i=>V(i)).filter(i=>i!==null);for(const i of r)n.set(i.key,i);const s=[...n.values()].sort((i,u)=>i.key.localeCompare(u.key)),o=new Map,l=new Map,a=new Map;for(const i of s){o.set(i.key,i),l.set(i.cli_flag,i);for(const u of i.cli_aliases)l.set(u,i);for(const u of i.commands){const f=a.get(u)??[];f.push(i),a.set(u,f)}}for(const[i,u]of a.entries())u.sort((f,d)=>f.key.localeCompare(d.key)),a.set(i,u);return{definitions:s,by_key:o,by_cli_token:l,command_to_fields:a}}function tt(e){return me(e.key)}function nt(e,t){const n=xe(e,t);return n?t.terminal_statuses.has(n):!1}export{m as DEFAULT_RUNTIME_SCHEMA_FILE_PATHS,z as DEFAULT_RUNTIME_STATUS_DEFINITIONS,q as DEFAULT_RUNTIME_WORKFLOW,Ze as ensureRuntimeSchemaFileScaffold,y as filePathForSchemaSection,Le as inspectRuntimeFieldDefinition,Ge as loadRuntimeSchemaFromOptionalFiles,N as normalizeCliToken,b as normalizeRuntimeSchemaSettings,xe as normalizeStatusInputWithRegistry,Ce as readFieldsFromSchemaFile,Xe as resolveItemTypesFilePath,et as resolveRuntimeFieldRegistry,Qe as resolveRuntimeStatusRegistry,tt as runtimeFieldOptionTarget,nt as statusIsTerminal};
3
3
  //# sourceMappingURL=runtime-schema.js.map
@@ -52,8 +52,8 @@ export declare const quoteCommandArg:(arg:string,platform?:NodeJS.Platform,diale
52
52
  /**
53
53
  * Quote one argument for a POSIX shell. Double quotes with `"`, `\`, `$` and
54
54
  * backticks escaped are exact for `sh -c` and scripts; an argument holding
55
- * `!` is single-quoted instead, because interactive bash and zsh
56
- * history-expand `!` inside double quotes (pm-oq893h).
55
+ * `!` or a line break, or ending in a backslash, is single-quoted instead,
56
+ * the one spelling every interactive history scanner reads as the shell does.
57
57
  */
58
58
  export declare const quotePosixCommandArg:(arg:string)=> string;
59
59
  /** Render a complete pm command from already-tokenized arguments. */
@@ -1,2 +1,2 @@
1
- const l="PM_COMMAND_SHELL",a=new Map([["posix","posix"],["sh","posix"],["bash","posix"],["zsh","posix"],["cmd","cmd"],["cmd.exe","cmd"],["powershell","powershell"],["pwsh","powershell"]]),r=(e=process.platform,t=process.env)=>{const o=t[l]?.trim().toLowerCase(),n=o===void 0?void 0:a.get(o);return n!==void 0?n:e==="win32"?"cmd":"posix"},d=e=>{let t='"',o=0;for(const n of e){if(n==="\\"){o+=1;continue}t+="\\".repeat(n==='"'?o*2+1:o),t+=n,o=0}return`${t}${"\\".repeat(o*2)}"`},c=new Set(["(",")","!","^",'"',"<",">","&","|"]),i=e=>{let t="";for(let o=0;o<e.length;o+=1){const n=e[o];if(c.has(n)){t+=`^${n}`;continue}t+=n,n==="%"&&!c.has(e.charAt(o+1))&&(t+="^")}return t},u=/["%]/u,m=/\r\n|[\r\n]/gu,h=e=>{const t=e.replace(m," "),o=d(t);return u.test(t)?i(o):o},A=/['\u2018\u2019\u201A\u201B]/gu,_=e=>e.replace(A,"$&$&"),x=e=>`'${_(e)}'`,E={posix:/^(?!=)[A-Za-z0-9._:/@=-]+$/u,cmd:/^[A-Za-z0-9._:/\\@=-]+$/u,powershell:/^(?!--$)[A-Za-z0-9._:/\\=-][A-Za-z0-9._:/\\@=-]*$/u},C=(e,t=process.platform,o)=>{const n=o??r(t);return E[n].test(e)?e:n==="cmd"?h(e):n==="powershell"?x(e):f(e)},f=e=>e.includes("!")?`'${e.replaceAll("'","'\\''")}'`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`,S=(e,t=process.platform,o)=>{const n=o??r(t),s=e.map(p=>C(p,t,n)).join(" ");return s.length>0?`pm ${s}`:"pm"};export{l as COMMAND_SHELL_ENV,i as escapeCmdMetacharacters,_ as escapePowerShellSingleQuotes,h as quoteCmdCommandArg,C as quoteCommandArg,f as quotePosixCommandArg,x as quotePowerShellCommandArg,d as quoteWindowsCommandArg,S as renderPmCommand,r as resolveCommandShellDialect};
1
+ const l="PM_COMMAND_SHELL",a=new Map([["posix","posix"],["sh","posix"],["bash","posix"],["zsh","posix"],["cmd","cmd"],["cmd.exe","cmd"],["powershell","powershell"],["pwsh","powershell"]]),r=(e=process.platform,o=process.env)=>{const t=o[l]?.trim().toLowerCase(),n=t===void 0?void 0:a.get(t);return n!==void 0?n:e==="win32"?"cmd":"posix"},d=e=>{let o='"',t=0;for(const n of e){if(n==="\\"){t+=1;continue}o+="\\".repeat(n==='"'?t*2+1:t),o+=n,t=0}return`${o}${"\\".repeat(t*2)}"`},c=new Set(["(",")","!","^",'"',"<",">","&","|"]),i=e=>{let o="";for(let t=0;t<e.length;t+=1){const n=e[t];if(c.has(n)){o+=`^${n}`;continue}o+=n,n==="%"&&!c.has(e.charAt(t+1))&&(o+="^")}return o},u=/["%]/u,m=/\r\n|[\r\n]/gu,h=e=>{const o=e.replace(m," "),t=d(o);return u.test(o)?i(t):t},_=/['\u2018\u2019\u201A\u201B]/gu,A=e=>e.replace(_,"$&$&"),E=e=>`'${A(e)}'`,x={posix:/^(?!=)[A-Za-z0-9._:/@=-]+$/u,cmd:/^[A-Za-z0-9._:/\\@=-]+$/u,powershell:/^(?!--$)[A-Za-z0-9._:/\\=-][A-Za-z0-9._:/\\@=-]*$/u},C=(e,o=process.platform,t)=>{const n=t??r(o);return x[n].test(e)?e:n==="cmd"?h(e):n==="powershell"?E(e):$(e)},S=/!|[\r\n]|\\$/u,$=e=>S.test(e)?`'${e.replaceAll("'","'\\''")}'`:`"${e.replace(/(["\\$`])/g,"\\$1")}"`,f=(e,o=process.platform,t)=>{const n=t??r(o),s=e.map(p=>C(p,o,n)).join(" ");return s.length>0?`pm ${s}`:"pm"};export{l as COMMAND_SHELL_ENV,i as escapeCmdMetacharacters,A as escapePowerShellSingleQuotes,h as quoteCmdCommandArg,C as quoteCommandArg,$ as quotePosixCommandArg,E as quotePowerShellCommandArg,d as quoteWindowsCommandArg,f as renderPmCommand,r as resolveCommandShellDialect};
2
2
  //# sourceMappingURL=command-line.js.map