@unbrained/pm-cli 2026.11.23 → 2026.11.25

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 (209) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/error-guidance.js +5 -5
  3. package/dist/cli/main.js +5 -5
  4. package/dist/cli/register-annotations.js +1 -1
  5. package/dist/cli/runtime/invocation-options.js +1 -1
  6. package/dist/cli-bundle/bundle-manifest.json +1 -1
  7. package/dist/cli-bundle/chunks/chunk-4FZH5BTV.js +2 -0
  8. package/dist/cli-bundle/chunks/{chunk-YYT3MIRF.js → chunk-6OIHST4I.js} +1 -1
  9. package/dist/cli-bundle/chunks/chunk-7EPYCU7U.js +9 -0
  10. package/dist/cli-bundle/chunks/{chunk-AEOHUSUI.js → chunk-BVJMVU4Z.js} +68 -68
  11. package/dist/cli-bundle/chunks/{chunk-2UQU7HRR.js → chunk-C4KIZQHW.js} +2 -2
  12. package/dist/cli-bundle/chunks/chunk-CNUFU454.js +113 -0
  13. package/dist/cli-bundle/chunks/chunk-CONBVY2O.js +2 -0
  14. package/dist/cli-bundle/chunks/{chunk-BSRIVYTM.js → chunk-CZEMEPPQ.js} +3 -3
  15. package/dist/cli-bundle/chunks/chunk-DF6A7C32.js +2 -0
  16. package/dist/cli-bundle/chunks/chunk-FHLOGAGA.js +8 -0
  17. package/dist/cli-bundle/chunks/chunk-FVY7U3SU.js +125 -0
  18. package/dist/cli-bundle/chunks/{chunk-F2Z6XLZB.js → chunk-GBVF2ZB3.js} +2 -2
  19. package/dist/cli-bundle/chunks/chunk-GZI7ZAB7.js +2 -0
  20. package/dist/cli-bundle/chunks/chunk-HZZLSBIJ.js +2 -0
  21. package/dist/cli-bundle/chunks/chunk-K34FR5CO.js +3 -0
  22. package/dist/cli-bundle/chunks/{chunk-D6PDUKUG.js → chunk-KHFUHGL3.js} +2 -2
  23. package/dist/cli-bundle/chunks/chunk-L6VS7F3R.js +2 -0
  24. package/dist/cli-bundle/chunks/chunk-LOX3VY4T.js +2 -0
  25. package/dist/cli-bundle/chunks/{chunk-H7JEXRIN.js → chunk-LPW7S5KA.js} +2 -2
  26. package/dist/cli-bundle/chunks/{chunk-5DUP4AZA.js → chunk-MGJMQSN4.js} +2 -2
  27. package/dist/cli-bundle/chunks/chunk-OS5W4ZG2.js +31 -0
  28. package/dist/cli-bundle/chunks/{chunk-O7JHS64G.js → chunk-OWK2JL4I.js} +2 -2
  29. package/dist/cli-bundle/chunks/chunk-SCIPT7WF.js +2 -0
  30. package/dist/cli-bundle/chunks/chunk-SX76UGEY.js +3 -0
  31. package/dist/cli-bundle/chunks/{chunk-CFWLQFJM.js → chunk-VA4T37Q4.js} +50 -51
  32. package/dist/cli-bundle/chunks/chunk-WQOEVGLQ.js +2 -0
  33. package/dist/cli-bundle/chunks/chunk-XHCIOLJP.js +3 -0
  34. package/dist/cli-bundle/chunks/{chunk-J2PDAVBC.js → chunk-XKWJONAO.js} +2 -2
  35. package/dist/cli-bundle/chunks/chunk-YIGBEY7K.js +2 -0
  36. package/dist/cli-bundle/chunks/chunk-ZBOQEZ2H.js +33 -0
  37. package/dist/cli-bundle/chunks/chunk-ZLICQPRG.js +3 -0
  38. package/dist/cli-bundle/chunks/field-option-collisions-QE65APSD.js +2 -0
  39. package/dist/cli-bundle/chunks/{indexed-receipt-blobs-BPYKN5Q7.js → indexed-receipt-blobs-H3MMNXXG.js} +2 -2
  40. package/dist/cli-bundle/{focused-chunks/item-revision-YDACCDVY.js → chunks/item-revision-INDHJV6X.js} +2 -2
  41. package/dist/cli-bundle/chunks/item-transaction-LCKK4XXB.js +2 -0
  42. package/dist/cli-bundle/chunks/mutation-actor-KU7BMLUN.js +2 -0
  43. package/dist/cli-bundle/chunks/mutation-admission-3OMCTQD4.js +2 -0
  44. package/dist/cli-bundle/chunks/{register-list-query-L4IBU64P.js → register-list-query-3GV3LBOT.js} +2 -2
  45. package/dist/cli-bundle/chunks/register-mutation-GZLF47SX.js +21 -0
  46. package/dist/cli-bundle/chunks/register-operations-PBJZGCAL.js +2 -0
  47. package/dist/cli-bundle/chunks/register-setup-ZLJEF6NZ.js +2 -0
  48. package/dist/cli-bundle/chunks/runtime-schema-Y4SHTEXL.js +2 -0
  49. package/dist/cli-bundle/chunks/{settlement-hook-6MR32OOC.js → settlement-hook-ESAAEBRM.js} +2 -2
  50. package/dist/cli-bundle/chunks/stage-3WIZBD4N.js +2 -0
  51. package/dist/cli-bundle/focused-chunks/chunk-3Y5PTQ2F.js +27 -0
  52. package/dist/cli-bundle/focused-chunks/{chunk-Y2ESLKCF.js → chunk-4LQL4EO6.js} +3 -3
  53. package/dist/cli-bundle/focused-chunks/{chunk-RIE3SJSE.js → chunk-4SX2BN4V.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/{chunk-ZHWPCVQL.js → chunk-5RBC4WSE.js} +39 -39
  55. package/dist/cli-bundle/focused-chunks/chunk-7SSGTGZO.js +91 -0
  56. package/dist/cli-bundle/focused-chunks/chunk-A4R57E4K.js +2 -0
  57. package/dist/cli-bundle/focused-chunks/chunk-BOIMP2AR.js +5 -0
  58. package/dist/cli-bundle/focused-chunks/chunk-BYQK5DGH.js +2 -0
  59. package/dist/cli-bundle/focused-chunks/chunk-C3FEDTSD.js +44 -0
  60. package/dist/cli-bundle/focused-chunks/chunk-IAOKVKWW.js +2 -0
  61. package/dist/cli-bundle/focused-chunks/chunk-JOKRDFMQ.js +2 -0
  62. package/dist/cli-bundle/focused-chunks/chunk-MB56Y4M6.js +8 -0
  63. package/dist/cli-bundle/focused-chunks/{chunk-A6VEMCRR.js → chunk-NGFDPEP7.js} +1 -1
  64. package/dist/cli-bundle/focused-chunks/chunk-OCKKIECS.js +3 -0
  65. package/dist/cli-bundle/focused-chunks/chunk-PKX2EHE3.js +26 -0
  66. package/dist/cli-bundle/focused-chunks/chunk-SXC2EO3E.js +3 -0
  67. package/dist/cli-bundle/focused-chunks/chunk-TQIKDFOD.js +2 -0
  68. package/dist/cli-bundle/focused-chunks/chunk-TRL4JDWX.js +8 -0
  69. package/dist/cli-bundle/focused-chunks/{chunk-IROZDIDX.js → chunk-UWWAVXG4.js} +2 -2
  70. package/dist/cli-bundle/focused-chunks/chunk-VMYVN36N.js +13 -0
  71. package/dist/cli-bundle/focused-chunks/chunk-VU2PH4PF.js +2 -0
  72. package/dist/cli-bundle/focused-chunks/chunk-WL2R7T5G.js +2 -0
  73. package/dist/cli-bundle/focused-chunks/chunk-WVA5KOXF.js +3 -0
  74. package/dist/cli-bundle/focused-chunks/{chunk-QQIIMMFU.js → chunk-X4EWD6TL.js} +2 -2
  75. package/dist/cli-bundle/focused-chunks/chunk-XKLBTDJ7.js +100 -0
  76. package/dist/cli-bundle/focused-chunks/chunk-YYEWIKNI.js +2 -0
  77. package/dist/cli-bundle/focused-chunks/chunk-ZLRRII55.js +2 -0
  78. package/dist/cli-bundle/focused-chunks/field-option-collisions-5ROXGUME.js +2 -0
  79. package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-EGEJMG3G.js → indexed-receipt-blobs-PG2VJ3MB.js} +2 -2
  80. package/dist/cli-bundle/focused-chunks/item-revision-KYMSQVZE.js +2 -0
  81. package/dist/cli-bundle/focused-chunks/item-transaction-I4HLVHEJ.js +2 -0
  82. package/dist/cli-bundle/focused-chunks/mutation-actor-GGOQKAE6.js +2 -0
  83. package/dist/cli-bundle/focused-chunks/mutation-admission-OS36ZCMH.js +2 -0
  84. package/dist/cli-bundle/focused-chunks/runtime-schema-YXPYDD2C.js +2 -0
  85. package/dist/cli-bundle/focused-chunks/{settlement-hook-FMLGKG7J.js → settlement-hook-4MGRERCT.js} +2 -2
  86. package/dist/cli-bundle/focused-chunks/stage-4ZFWJUKO.js +2 -0
  87. package/dist/cli-bundle/main.js +26 -26
  88. package/dist/cli-bundle/sdk-authoring.js +1 -1
  89. package/dist/cli-bundle/sdk-contracts.js +4 -4
  90. package/dist/cli-bundle/sdk-core.js +1 -1
  91. package/dist/cli-bundle/sdk-governance.js +1 -1
  92. package/dist/cli-bundle/sdk-graph.js +1 -1
  93. package/dist/cli-bundle/sdk-merge.js +63 -63
  94. package/dist/cli-bundle/sdk-query.js +1 -1
  95. package/dist/cli-bundle/sdk-runtime.js +1 -1
  96. package/dist/cli-bundle/sdk-testing.js +1 -1
  97. package/dist/cli-bundle/sdk.js +12 -12
  98. package/dist/core/profile/profile-lint.d.ts +1 -1
  99. package/dist/core/profile/profile-lint.js +1 -1
  100. package/dist/core/schema/fields-file.js +2 -2
  101. package/dist/core/schema/runtime-field-values.js +1 -1
  102. package/dist/core/schema/runtime-schema.d.ts +2 -0
  103. package/dist/core/schema/runtime-schema.js +1 -1
  104. package/dist/core/shared/command-line.d.ts +54 -4
  105. package/dist/core/shared/command-line.js +1 -1
  106. package/dist/core/shared/errors.d.ts +9 -0
  107. package/dist/core/shared/secret-rules.js +5 -5
  108. package/dist/core/shared/url-credentials.d.ts +16 -3
  109. package/dist/core/shared/url-credentials.js +1 -1
  110. package/dist/core/store/item-store.d.ts +26 -4
  111. package/dist/core/store/item-store.js +1 -1
  112. package/dist/sdk/command-line.d.ts +1 -1
  113. package/dist/sdk/command-line.js +1 -1
  114. package/dist/sdk/context-intent-contracts.js +1 -1
  115. package/dist/sdk/extension/command-options.d.ts +26 -1
  116. package/dist/sdk/extension/command-options.js +1 -1
  117. package/dist/sdk/extension-command-context.js +2 -2
  118. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -1
  119. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +1 -1
  120. package/dist/sdk/governance/tracked-runtime-cache.js +1 -1
  121. package/dist/sdk/index.d.ts +1 -1
  122. package/dist/sdk/lifecycle/claim.d.ts +21 -1
  123. package/dist/sdk/lifecycle/claim.js +1 -1
  124. package/dist/sdk/lifecycle/task-composition.js +1 -1
  125. package/dist/sdk/ownership-source.d.ts +15 -1
  126. package/dist/sdk/ownership-source.js +1 -1
  127. package/dist/sdk/public-surface.json +1 -1
  128. package/dist/sdk/read-output-contracts.d.ts +11 -0
  129. package/dist/sdk/read-output-contracts.js +1 -1
  130. package/dist/sdk/runtime-primitives.d.ts +1 -1
  131. package/dist/sdk/schema/field-flag-spelling.d.ts +22 -0
  132. package/dist/sdk/schema/field-flag-spelling.js +2 -0
  133. package/dist/sdk/schema/field-option-collisions.js +1 -1
  134. package/docs/AGENT_GUIDE.md +2 -2
  135. package/docs/COMMANDS.md +1 -1
  136. package/docs/CONFIGURATION.md +1 -0
  137. package/docs/EXTENSIONS.md +1 -1
  138. package/docs/MUTATION_INTEGRITY.md +97 -8
  139. package/docs/READ_OUTPUT_CONTRACTS.md +2 -0
  140. package/docs/SDK.md +60 -4
  141. package/docs/SDK_AUDITED_MUTATIONS.md +11 -0
  142. package/docs/WORKSPACE_POSITION_AND_LIFECYCLE.md +17 -4
  143. package/marketplace.json +1 -1
  144. package/package.json +1 -1
  145. package/packages/pm-beads/package.json +1 -1
  146. package/packages/pm-calendar/package.json +1 -1
  147. package/packages/pm-command-kit/package.json +1 -1
  148. package/packages/pm-digital-twin/package.json +1 -1
  149. package/packages/pm-governance-audit/package.json +1 -1
  150. package/packages/pm-guide-shell/package.json +1 -1
  151. package/packages/pm-kanban/package.json +1 -1
  152. package/packages/pm-lifecycle-hooks/package.json +1 -1
  153. package/packages/pm-linked-test-adapters/package.json +1 -1
  154. package/packages/pm-search-advanced/package.json +1 -1
  155. package/packages/pm-templates/package.json +1 -1
  156. package/packages/pm-todos/package.json +1 -1
  157. package/packages/pm-vcs/package.json +1 -1
  158. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  159. package/plugins/pm-claude/package.json +1 -1
  160. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  161. package/plugins/pm-codex/package.json +1 -1
  162. package/plugins/pm-codex/plugin.json +1 -1
  163. package/runtime-dependencies.json +1 -1
  164. package/dist/cli-bundle/chunks/chunk-5WZZ5XEN.js +0 -3
  165. package/dist/cli-bundle/chunks/chunk-6MYJLOSG.js +0 -2
  166. package/dist/cli-bundle/chunks/chunk-ENKXRSFZ.js +0 -31
  167. package/dist/cli-bundle/chunks/chunk-FJOEL75F.js +0 -2
  168. package/dist/cli-bundle/chunks/chunk-GDXCAC52.js +0 -2
  169. package/dist/cli-bundle/chunks/chunk-KE7HMBEW.js +0 -2
  170. package/dist/cli-bundle/chunks/chunk-KZHIBEJL.js +0 -33
  171. package/dist/cli-bundle/chunks/chunk-NGJ5ERBF.js +0 -115
  172. package/dist/cli-bundle/chunks/chunk-NQ54T7T2.js +0 -2
  173. package/dist/cli-bundle/chunks/chunk-OKEZF7HU.js +0 -2
  174. package/dist/cli-bundle/chunks/chunk-OKIKF4FD.js +0 -2
  175. package/dist/cli-bundle/chunks/chunk-OPJF254V.js +0 -9
  176. package/dist/cli-bundle/chunks/chunk-RWA5YZ5X.js +0 -2
  177. package/dist/cli-bundle/chunks/chunk-S32NGRQM.js +0 -2
  178. package/dist/cli-bundle/chunks/chunk-TZY5MVJF.js +0 -125
  179. package/dist/cli-bundle/chunks/chunk-ZPS4B6SI.js +0 -8
  180. package/dist/cli-bundle/chunks/item-revision-FMD4KWBB.js +0 -2
  181. package/dist/cli-bundle/chunks/item-transaction-SEHTH7N2.js +0 -2
  182. package/dist/cli-bundle/chunks/mutation-actor-SFGYIRPW.js +0 -2
  183. package/dist/cli-bundle/chunks/mutation-admission-57LBSKQI.js +0 -2
  184. package/dist/cli-bundle/chunks/register-mutation-6NUOPHZ3.js +0 -21
  185. package/dist/cli-bundle/chunks/register-operations-JGYVORNN.js +0 -2
  186. package/dist/cli-bundle/chunks/register-setup-C44SIXEH.js +0 -2
  187. package/dist/cli-bundle/chunks/stage-PQ7AB63N.js +0 -2
  188. package/dist/cli-bundle/focused-chunks/chunk-6LKTEKHS.js +0 -6
  189. package/dist/cli-bundle/focused-chunks/chunk-6LPXMFLM.js +0 -2
  190. package/dist/cli-bundle/focused-chunks/chunk-HMDQDRV2.js +0 -8
  191. package/dist/cli-bundle/focused-chunks/chunk-I66IKYKP.js +0 -2
  192. package/dist/cli-bundle/focused-chunks/chunk-IR2J3NOT.js +0 -2
  193. package/dist/cli-bundle/focused-chunks/chunk-ITKDHSBR.js +0 -2
  194. package/dist/cli-bundle/focused-chunks/chunk-LQYYPXUK.js +0 -26
  195. package/dist/cli-bundle/focused-chunks/chunk-NQTEE66P.js +0 -13
  196. package/dist/cli-bundle/focused-chunks/chunk-O7Z73ALG.js +0 -2
  197. package/dist/cli-bundle/focused-chunks/chunk-OTMMOKPM.js +0 -91
  198. package/dist/cli-bundle/focused-chunks/chunk-OXOCZJC6.js +0 -2
  199. package/dist/cli-bundle/focused-chunks/chunk-QLAHEDT6.js +0 -2
  200. package/dist/cli-bundle/focused-chunks/chunk-TD544C74.js +0 -8
  201. package/dist/cli-bundle/focused-chunks/chunk-UFTUNBMY.js +0 -27
  202. package/dist/cli-bundle/focused-chunks/chunk-XRS3VNC6.js +0 -44
  203. package/dist/cli-bundle/focused-chunks/chunk-XYPEZGTR.js +0 -2
  204. package/dist/cli-bundle/focused-chunks/chunk-YSJKQLFR.js +0 -2
  205. package/dist/cli-bundle/focused-chunks/chunk-Z2X7HH3C.js +0 -102
  206. package/dist/cli-bundle/focused-chunks/item-transaction-UKEQCTKB.js +0 -2
  207. package/dist/cli-bundle/focused-chunks/mutation-actor-AS465LRX.js +0 -2
  208. package/dist/cli-bundle/focused-chunks/mutation-admission-E5UHJZFE.js +0 -2
  209. package/dist/cli-bundle/focused-chunks/stage-36J7YLGI.js +0 -2
@@ -1,2 +1,2 @@
1
- import I from"node:fs/promises";import{buildDeletedItemError as bt}from"../history/tombstone.js";import{normalizeHistoryOperationForWrite as Pt}from"../history/operation-contract.js";import{enforceWorkflowMutation as B}from"../policy/workflow-policy-store.js";import{recordItemMetadataEnumeration as L}from"./item-metadata-read-work.js";import{advanceItemMutationPreconditions as G,assertItemMutationPreconditions as V,itemMutationPreconditionHistoryContext as kt,transactionCompensationHistoryContext as Y}from"./item-mutation-precondition.js";import{checkpointMutationHistoryContext as Ct}from"../checkpoint/mutation-context.js";import M from"node:path";import{getActiveExtensionRegistrations as K,projectAfterCommandItemSnapshot as E,recordAfterCommandAffectedItem as X,runActiveOnReadHooks as Nt,runActiveBeforeMutationHooks as J,runActiveOnWriteHooks as D,runActiveServiceOverride as Q}from"../extensions/index.js";import{collectRegisteredItemFieldNames as Tt}from"../extensions/item-fields.js";import{EMPTY_CANONICAL_DOCUMENT as Z,EXIT_CODE as C,TYPE_TO_FOLDER as O}from"../shared/constants.js";import{PmCliError as y}from"../shared/errors.js";import{levenshteinDistanceWithinLimit as Dt}from"../shared/levenshtein.js";import{appendHistoryEntry as tt,createHistoryEntry as et}from"../history/history.js";import{enforceHistoryStreamPolicyForItem as ot}from"../history/history-stream-policy.js";import{canonicalDocument as W,parseItemDocument as it,serializeItemDocument as Ot}from"../item/item-format.js";import{resolveItemTypeRegistry as Wt}from"../item/type-registry.js";import{effectiveItemFormatVersion as At,requiredItemFormatVersion as nt}from"../item/item-format-version.js";import{assertProjectRuntimeFormatGuard as St}from"../../sdk/environment/project-runtime-compatibility.js";import{acquireLockLease as Lt}from"../lock/lock.js";import{isFileMissingError as Mt,writeFileAtomic as A}from"../fs/fs-utils.js";import{isUtf8 as Et}from"node:buffer";import{normalizeItemId as rt,normalizeRawItemId as jt}from"../item/id.js";import{acquireItemMetadataDerivedIndexLock as at,listAllDocumentCandidatesCached as $t,listAllDocumentsCached as Ht,listAllDocumentsCachedLight as zt,refreshItemMetadataDerivedIndex as st}from"./item-metadata-cache.js";import{getHistoryPath as dt,getItemPath as ct,ITEM_FILE_EXTENSIONS as qt,resolveWorkspaceRoot as Ut}from"./paths.js";import{resolveGovernanceKnobs as Bt}from"./settings.js";import{assertReadableTrackerRoot as j}from"./tracker-preflight.js";import{resolveClaimPrincipal as Gt}from"../shared/author.js";import{pruneResolvedDeferredFields as Vt}from"../item/deferred-fields.js";import{nowIso as mt}from"../shared/time.js";import{redactOptionalIdentityCredentials as Yt}from"../shared/url-credentials.js";async function Kt(t){try{return await I.access(t),!0}catch{return!1}}function Xt(t,o){return typeof t=="object"&&t!==null&&"code"in t&&t.code===o}function lt(t,o){t&&(t.includes(o)||t.push(o))}function $(t){return t??Tt(K())}function Jt(t){return t==="toon"?["toon","json_markdown"]:t==="json_markdown"?["json_markdown","toon"]:["toon","json_markdown"]}async function H(t,o,e="pm-",i,a=O){const n=o.trim(),d=n.startsWith("#")?n.slice(1):n;if(d.length===0)return null;const l=rt(o,e),m=jt(o),r=[...new Set([d,l,m])].filter(h=>h.length>0),f=Object.entries(a),c=Jt(i);for(const h of r){const u=new Map;for(const[s]of f)for(const g of c){const p=ct(t,s,h,g,a);await Kt(p)&&u.set(p,u.get(p)??{id:h,type:s,itemPath:p,item_format:g})}if(u.size>1){const s=[...u.keys()].map(g=>M.relative(t,g).split(M.sep).join("/")).sort();throw new y(`Item ${h} has ambiguous identity across ${s.join(", ")}. Preserve both documents and inspect pm ops validate --check-storage-integrity before resolving the collision.`,C.CONFLICT,{code:"item_identity_ambiguous",item_id:h,paths:s})}for(const s of u.values())return s}return null}async function ft(t,o={}){const e=await Qt(t,o);if(e.error!==null)throw e.error;return{raw:e.raw,document:e.document}}async function Qt(t,o={}){const e=await I.readFile(t.itemPath);if(!Et(e))throw new y("Item contains invalid UTF-8; preserve a binary backup before recovering it.",C.CONFLICT,{code:"item_document_encoding_invalid",item_id:t.id,item_path:t.itemPath,byte_length:e.length,empty:!1});const i=e.toString("utf8");await Nt({path:t.itemPath,scope:"project"});let a;try{a=it(i,{format:t.item_format,requireSupportedFormat:!0,schema:o.schema,extensionFieldNames:$(o.extensionFieldNames),onWarning:n=>lt(o.warnings,n)})}catch(n){if(n instanceof y&&n.code==="item_format_version_unsupported")throw new y(`Item ${t.id}: ${n.message}`,n.exitCode,{...n.context,item_id:t.id,item_path:t.itemPath});if(n instanceof y&&n.code==="item_document_invalid")return{raw:i,document:null,error:new y(`Cannot read ${t.id} at ${t.itemPath}${e.length===0?" (zero-length file)":""}: ${n.message}`,n.exitCode,{...n.context,item_id:t.id,item_path:t.itemPath,byte_length:e.length,empty:e.length===0,nextSteps:[`Run pm history ${t.id} --full, then pm restore ${t.id} <version> to recover a recorded state.`]})};throw n}return{raw:i,document:a,error:null}}async function Zt(t,o,e=O,i,a){await j(t);const n=await Ht(t,o,e,i,a);return L(n.length),n.map(d=>d.metadata)}async function Me(t,o,e=O,i,a){await j(t);const n=await zt(t,o,e,i,a);return L(n.length),n.map(d=>d.metadata)}async function Ee(t,o,e=O,i,a,n={}){await j(t);const d=await $t(t,o,e,i,a,{includeBody:!0,forceSourceScan:n.forceSourceScan});return L(d.length),d.map(l=>({...l.metadata,body:l.body}))}function ut(t){return{async get(o){const e=await H(t.pmRoot,o,t.settings.id_prefix,t.settings.item_format,t.typeToFolder);if(!e)return null;const{document:i}=await ft(e,{schema:t.settings.schema});return{item:i.metadata,body:i.body}},list:()=>Zt(t.pmRoot,t.settings.item_format,t.typeToFolder,void 0,t.settings.schema)}}async function te(t,o){const e=new Set(Object.values(o)),i=[];return await Promise.all([...e].map(async a=>{try{const n=await I.readdir(M.join(t,a));for(const d of n)for(const l of qt)if(d.toLowerCase().endsWith(l)){i.push(d.slice(0,-l.length));break}}catch{}})),i}async function ht(t,o,e,i){const a=rt(o,e),n=await te(t,i);if(n.length===0)return[];const d=Math.max(3,Math.floor(a.length/2));return n.map(m=>({id:m,distance:Dt(m,a,d)})).filter(m=>m.distance!==null).sort((m,r)=>m.distance-r.distance).slice(0,3).map(m=>m.id)}async function ee(t,o,e,i){const a=await bt(t,o,e);if(a)return a;const n=await ht(t,o,e,i),d=["Confirm the active --path/PM_PATH scope, then retry with a valid id."];return n.length>0&&d.unshift(`Did you mean one of: ${n.join(", ")}?`),new y(`Item ${o} not found`,C.NOT_FOUND,{code:"item_not_found",id:o,nextSteps:d})}function gt(t,o){return t==="claim"||o===!0&&(t==="comment_add"||t==="comment_edit"||t==="comment_delete"||t==="note_add"||t==="learning_add"||t==="release"||t==="update"||t==="update_ownership_bypass"||t==="update_audit")}async function wt(t){const o=t.typeToFolder??Wt(t.settings,K()).type_to_folder,e=await H(t.pmRoot,t.id,t.settings.id_prefix,t.settings.item_format,o);if(!e)throw await ee(t.pmRoot,t.id,t.settings.id_prefix,o);const i=await Lt(t.pmRoot,e.id,t.settings.locks.ttl_seconds,t.author,!!t.force,t.settings.governance.force_required_for_stale_lock,t.settings.locks.wait_ms,{waitPolicy:"progress"}),a=i.release;try{const n=[],{raw:d,document:l}=await ft(e,{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames,warnings:n}),m=l.metadata.assignee?.trim(),r=Yt(m),f=l.metadata.claim_principal?.trim()||m,c=Gt(t.author),h=Bt(t.settings);if(r&&f!==c&&!t.force&&!gt(t.op,t.bypassAssigneeConflict)){if(h.ownership_enforcement==="strict")throw new y(`Item ${e.id} is assigned to ${r}. Use --force to override.`,C.CONFLICT);h.ownership_enforcement==="warn"&&n.push(`ownership_warning:assignee_conflict:${e.id}:${r}`)}return{typeToFolder:o,located:e,originalRaw:d,document:l,warnings:n,releaseLock:a,lease:i}}catch(n){throw await a(),n}}function pt(t){return Object.keys(t).length===0?void 0:t}async function yt(t,o,e,i){return t.fence(async()=>{let a;try{a=await I.readFile(o.itemPath,"utf8")}catch(n){if(!Mt(n))throw n;a=null}if(a!==e)throw new y(`Item ${o.id} changed after this mutation read it; refusing to overwrite the newer revision. Nothing was written.`,C.CONFLICT,{code:"stale_revision",item_id:o.id,reason:a===null?"item_removed":"item_revision_changed",required:"Re-read the item and apply the mutation again; the newer stored revision was kept."});return i()})}function oe(t,o,e){if(!t.handled||typeof t.result!="object"||t.result===null)return{effectiveTargetItemPath:o,effectiveSerializedAfter:e,skipItemWrite:!1};const i=t.result;return{effectiveTargetItemPath:typeof i.target_item_path=="string"&&i.target_item_path.trim().length>0?i.target_item_path:o,effectiveSerializedAfter:typeof i.contents=="string"?i.contents:e,skipItemWrite:i.skip_write===!0}}async function _t(t){try{const o=await H(t.pmRoot,t.id,t.settings.id_prefix,t.settings.item_format,t.typeToFolder);if(!o)return{document:Z};const e=it(await I.readFile(o.itemPath,"utf8"),{format:o.item_format,requireSupportedFormat:!0,schema:t.settings.schema,extensionFieldNames:$(t.extensionFieldNames)});return e.metadata.id===t.embeddedId?{document:e}:{document:t.fallback,revision:It}}catch{return{document:t.fallback,revision:It}}}const It="unreadable-after-storage-override";async function ie(t){const o=await Q("item_store_delete",t),e=o.handled&&typeof o.result=="object"&&o.result!==null?o.result:{};return{effectiveItemPath:typeof e.item_path=="string"&&e.item_path.trim().length>0?e.item_path:t.item_path,skipDelete:e.skip_delete===!0,warnings:o.warnings}}async function ne(t){if(!t.skipItemWrite){if(t.effectiveTargetItemPath!==t.originalItemPath){await A(t.originalItemPath,t.originalRaw),await I.rm(t.effectiveTargetItemPath,{force:!0});return}await A(t.originalItemPath,t.originalRaw)}}function re(t,o){Vt(t.metadata)&&o.push("deferred_fields")}async function z(t){Pt(t.op);const o=await wt({pmRoot:t.pmRoot,settings:t.settings,id:t.id,op:t.op,author:t.author,force:t.force,bypassAssigneeConflict:t.bypassAssigneeConflict,extensionFieldNames:t.extensionFieldNames,typeToFolder:t.typeToFolder}),{typeToFolder:e,located:i,originalRaw:a,document:n,warnings:d,releaseLock:l,lease:m}=o;try{V(t.pmRoot,n,i.id);const r=W(n,{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),f=W(structuredClone(n),{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),c=await t.mutate(f,{storageId:i.id});if(re(f,c.changedFields),t.skipNoop===!0&&c.changedFields.length===0)return{item:r.metadata,body:r.body,changedFields:[],warnings:[...d,...c.warnings??[]]};const h={...t.resolveHistoryContext?.(),...Ct(t.pmRoot,i.id),...kt(t.pmRoot,[i.id,n.metadata.id])},u=Math.max(nt(r.metadata),nt(f.metadata));St(Ut(t.pmRoot),u),u>At(f.metadata)&&(f.metadata.pm_format_version=u,c.changedFields.push("pm_format_version")),f.metadata.updated_at=mt();const s=W(f,{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),g=await B({pmRoot:t.pmRoot,settings:t.settings,operation:t.op,author:t.author,before:r,after:s});await J({pm_root:t.pmRoot,operation:t.op,before:r,after:s,changed_fields:c.changedFields,author:t.author,sdk:ut({pmRoot:t.pmRoot,settings:t.settings,typeToFolder:e})});const p=await ot({pmRoot:t.pmRoot,settings:t.settings,itemId:i.id,commandLabel:t.op}),v="toon",x=Ot(s,{format:v,schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),b=ct(t.pmRoot,s.metadata.type,i.id,v,e),F=dt(t.pmRoot,i.id),N=await yt(m,i,a,async()=>{const P=await Q("item_store_write",{op:t.op,pm_root:t.pmRoot,item_id:i.id,source_item_path:i.itemPath,target_item_path:b,history_path:F,item_format:v,before:r,after:s,contents:x}),{effectiveTargetItemPath:_,effectiveSerializedAfter:q,skipItemWrite:k}=oe(P,b,x),vt=await at(t.pmRoot,t.author);let U=[];try{k||await A(_,q),!k&&_!==i.itemPath&&await I.rm(i.itemPath);const Rt=et({nowIso:s.metadata.updated_at,author:t.author,op:t.op,before:r,after:s,message:t.message,context:pt({...h,...g.decisions.length===0?{}:{workflow_policies:g.decisions},...Y(t.pmRoot,[i.id,n.metadata.id],t.op)})});try{await tt(F,Rt)}catch(xt){throw await ne({skipItemWrite:k,effectiveTargetItemPath:_,originalItemPath:i.itemPath,originalRaw:a}),xt}k||(U=await st({pmRoot:t.pmRoot,preferredFormat:t.settings.item_format,typeToFolder:e,schema:t.settings.schema,itemPath:_,previousItemPath:i.itemPath,document:s}))}finally{await vt()}const Ft=k||_!==b||q!==x;return{derivedIndexWarnings:U,effectiveTargetItemPath:_,overrideWarnings:P.warnings,stored:Ft?await _t({pmRoot:t.pmRoot,settings:t.settings,id:i.id,typeToFolder:e,extensionFieldNames:t.extensionFieldNames,fallback:s,embeddedId:s.metadata.id}):{document:s}}}),{derivedIndexWarnings:w,effectiveTargetItemPath:R,stored:T}=N;G(t.pmRoot,T.document,i.id,[s.metadata.id],T.revision);const S=[...await D({path:R,scope:"project",op:t.op,item_id:s.metadata.id,item_type:s.metadata.type,before:r,after:s,changed_fields:c.changedFields}),...await D({path:F,scope:"project",op:`${t.op}:history`,item_id:s.metadata.id,item_type:s.metadata.type,before:r,after:s,changed_fields:c.changedFields})];return X({id:s.metadata.id,op:t.op,item_type:s.metadata.type,previous_status:r.metadata.status,status:s.metadata.status,previous:E(r.metadata,c.changedFields),current:E(s.metadata,c.changedFields),changed_fields:c.changedFields}),{item:s.metadata,body:s.body,changedFields:c.changedFields,warnings:[...d,...c.warnings??[],...g.warnings,...p.warnings,...N.overrideWarnings,...w,...S]}}finally{await l()}}async function je(t){const{historyContext:o,...e}=t;return z({...e,resolveHistoryContext:()=>o})}async function $e(t){return z(t)}async function He(t){return z(t)}const ze={appendWarning:lt,bypassesAssigneeConflict:gt,buildDidYouMeanSuggestions:ht,isErrno:Xt};async function qe(t){const o=await wt({pmRoot:t.pmRoot,settings:t.settings,id:t.id,op:"delete",author:t.author,force:t.force}),{located:e,originalRaw:i,document:a,warnings:n,releaseLock:d,lease:l}=o;try{V(t.pmRoot,a,e.id);const m=$(void 0),r=W(a,{schema:t.settings.schema,extensionFieldNames:m}),f=await B({pmRoot:t.pmRoot,settings:t.settings,operation:"delete",author:t.author,before:r,after:null,dryRun:t.dryRun});await J({pm_root:t.pmRoot,operation:"delete",before:r,after:null,changed_fields:["deleted"],author:t.author,dry_run:t.dryRun===!0,sdk:ut({pmRoot:t.pmRoot,settings:t.settings,typeToFolder:o.typeToFolder})});const c=await ot({pmRoot:t.pmRoot,settings:t.settings,itemId:e.id,commandLabel:"delete"}),h=mt(),u=Z,s=et({nowIso:h,author:t.author,op:"delete",before:r,after:u,message:t.message,context:pt({...f.decisions.length===0?{}:{workflow_policies:f.decisions},...Y(t.pmRoot,[e.id,a.metadata.id],"delete")})}),g=dt(t.pmRoot,e.id),p=()=>ie({op:"delete",pm_root:t.pmRoot,item_id:e.id,item_path:e.itemPath,history_path:g,before:r});if(t.dryRun===!0){const w=await p();return{item:r.metadata,changedFields:["deleted"],targetPath:w.effectiveItemPath,warnings:[...n,...f.warnings,...c.warnings,...w.warnings]}}const v=await yt(l,e,i,async()=>{const{effectiveItemPath:w,skipDelete:R,warnings:T}=await p(),S=await at(t.pmRoot,t.author);let P=[];try{R||await I.rm(w);try{await tt(g,s)}catch(_){throw R||await A(w,i),_}R||(P=await st({pmRoot:t.pmRoot,preferredFormat:t.settings.item_format,typeToFolder:o.typeToFolder,schema:t.settings.schema,itemPath:w,document:null}))}finally{await S()}return{derivedIndexWarnings:P,effectiveItemPath:w,overrideWarnings:T,stored:R||w!==e.itemPath?await _t({pmRoot:t.pmRoot,settings:t.settings,id:e.id,typeToFolder:o.typeToFolder,fallback:u,embeddedId:a.metadata.id}):{document:u}}}),{derivedIndexWarnings:x,effectiveItemPath:b,stored:F}=v;G(t.pmRoot,F.document,e.id,[a.metadata.id],F.revision);const N=[...await D({path:b,scope:"project",op:"delete",item_id:r.metadata.id,item_type:r.metadata.type,before:r,after:u,changed_fields:["deleted"]}),...await D({path:g,scope:"project",op:"delete:history",item_id:r.metadata.id,item_type:r.metadata.type,before:r,after:u,changed_fields:["deleted"]})];return X({id:r.metadata.id,op:"delete",item_type:r.metadata.type,previous_status:r.metadata.status,previous:E(r.metadata,Object.keys(r.metadata)),changed_fields:["deleted"]}),{item:r.metadata,changedFields:["deleted"],warnings:[...n,...f.warnings,...c.warnings,...v.overrideWarnings,...x,...N]}}finally{await d()}}export{ee as buildItemNotFoundError,ut as createMutationGuardSdk,qe as deleteItem,ze as itemStoreTestOnly,Zt as listAllItemMetadata,Me as listAllItemMetadataLight,Ee as listAllItemMetadataWithBody,H as locateItem,He as mutateItem,je as mutateItemWithHistoryContext,$e as mutateItemWithHistoryContextResolver,ft as readLocatedItem,Qt as readLocatedItemSnapshot};
1
+ import _ from"node:fs/promises";import{buildDeletedItemError as Pt}from"../history/tombstone.js";import{normalizeHistoryOperationForWrite as kt}from"../history/operation-contract.js";import{enforceWorkflowMutation as G}from"../policy/workflow-policy-store.js";import{recordItemMetadataEnumeration as M}from"./item-metadata-read-work.js";import{advanceItemMutationPreconditions as V,assertItemMutationPreconditions as Y,itemMutationPreconditionHistoryContext as Ct,transactionCompensationHistoryContext as K}from"./item-mutation-precondition.js";import{checkpointMutationHistoryContext as Nt}from"../checkpoint/mutation-context.js";import E from"node:path";import{getActiveExtensionRegistrations as X,projectAfterCommandItemSnapshot as j,recordAfterCommandAffectedItem as J,runActiveOnReadHooks as Tt,runActiveBeforeMutationHooks as Q,runActiveOnWriteHooks as D,runActiveServiceOverride as Z}from"../extensions/index.js";import{collectRegisteredItemFieldNames as St}from"../extensions/item-fields.js";import{EMPTY_CANONICAL_DOCUMENT as tt,EXIT_CODE as k,TYPE_TO_FOLDER as O}from"../shared/constants.js";import{PmCliError as y}from"../shared/errors.js";import{levenshteinDistanceWithinLimit as Dt}from"../shared/levenshtein.js";import{appendHistoryEntry as et,createHistoryEntry as ot}from"../history/history.js";import{enforceHistoryStreamPolicyForItem as it}from"../history/history-stream-policy.js";import{canonicalDocument as W,parseItemDocument as nt,serializeItemDocument as Ot}from"../item/item-format.js";import{resolveItemTypeRegistry as Wt}from"../item/type-registry.js";import{effectiveItemFormatVersion as At,requiredItemFormatVersion as rt}from"../item/item-format-version.js";import{assertProjectRuntimeFormatGuard as Lt}from"../../sdk/environment/project-runtime-compatibility.js";import{acquireLockLease as Mt}from"../lock/lock.js";import{isFileMissingError as Et,writeFileAtomic as A}from"../fs/fs-utils.js";import{isUtf8 as jt}from"node:buffer";import{normalizeItemId as at,normalizeRawItemId as $t}from"../item/id.js";import{acquireItemMetadataDerivedIndexLock as st,listAllDocumentCandidatesCached as Ht,listAllDocumentsCached as zt,listAllDocumentsCachedLight as Ut,refreshItemMetadataDerivedIndex as dt}from"./item-metadata-cache.js";import{getHistoryPath as ct,getItemPath as mt,ITEM_FILE_EXTENSIONS as qt,resolveWorkspaceRoot as Bt}from"./paths.js";import{resolveGovernanceKnobs as Gt}from"./settings.js";import{assertReadableTrackerRoot as $}from"./tracker-preflight.js";import{resolveClaimPrincipal as Vt}from"../shared/author.js";import{pruneResolvedDeferredFields as Yt}from"../item/deferred-fields.js";import{nowIso as lt}from"../shared/time.js";import{redactOptionalIdentityCredentials as Kt}from"../shared/url-credentials.js";async function Xt(t){try{return await _.access(t),!0}catch{return!1}}function Jt(t,e){return typeof t=="object"&&t!==null&&"code"in t&&t.code===e}function ft(t,e){t&&(t.includes(e)||t.push(e))}function H(t){return t??St(X())}function Qt(t){return t==="toon"?["toon","json_markdown"]:t==="json_markdown"?["json_markdown","toon"]:["toon","json_markdown"]}async function z(t,e,o="pm-",i,r=O){const n=e.trim(),d=n.startsWith("#")?n.slice(1):n;if(d.length===0)return null;const l=at(e,o),f=$t(e),s=[...new Set([d,l,f])].filter(c=>c.length>0),m=Object.entries(r),g=Qt(i);for(const c of s){const u=new Map;for(const[h]of m)for(const a of g){const p=mt(t,h,c,a,r);await Xt(p)&&u.set(p,u.get(p)??{id:c,type:h,itemPath:p,item_format:a})}if(u.size>1){const h=[...u.keys()].map(a=>E.relative(t,a).split(E.sep).join("/")).sort();throw new y(`Item ${c} has ambiguous identity across ${h.join(", ")}. Preserve both documents and inspect pm ops validate --check-storage-integrity before resolving the collision.`,k.CONFLICT,{code:"item_identity_ambiguous",item_id:c,paths:h})}for(const h of u.values())return h}return null}async function ut(t,e={}){const o=await Zt(t,e);if(o.error!==null)throw o.error;return{raw:o.raw,document:o.document}}async function Zt(t,e={}){const o=await _.readFile(t.itemPath);if(!jt(o))throw new y("Item contains invalid UTF-8; preserve a binary backup before recovering it.",k.CONFLICT,{code:"item_document_encoding_invalid",item_id:t.id,item_path:t.itemPath,byte_length:o.length,empty:!1});const i=o.toString("utf8");await Tt({path:t.itemPath,scope:"project"});let r;try{r=nt(i,{format:t.item_format,requireSupportedFormat:!0,schema:e.schema,extensionFieldNames:H(e.extensionFieldNames),onWarning:n=>ft(e.warnings,n)})}catch(n){if(n instanceof y&&n.code==="item_format_version_unsupported")throw new y(`Item ${t.id}: ${n.message}`,n.exitCode,{...n.context,item_id:t.id,item_path:t.itemPath});if(n instanceof y&&n.code==="item_document_invalid")return{raw:i,document:null,error:new y(`Cannot read ${t.id} at ${t.itemPath}${o.length===0?" (zero-length file)":""}: ${n.message}`,n.exitCode,{...n.context,item_id:t.id,item_path:t.itemPath,byte_length:o.length,empty:o.length===0,nextSteps:[`Run pm history ${t.id} --full, then pm restore ${t.id} <version> to recover a recorded state.`]})};throw n}return{raw:i,document:r,error:null}}async function te(t,e,o=O,i,r){await $(t);const n=await zt(t,e,o,i,r);return M(n.length),n.map(d=>d.metadata)}async function He(t,e,o=O,i,r){await $(t);const n=await Ut(t,e,o,i,r);return M(n.length),n.map(d=>d.metadata)}async function ze(t,e,o=O,i,r,n={}){await $(t);const d=await Ht(t,e,o,i,r,{includeBody:!0,forceSourceScan:n.forceSourceScan});return M(d.length),d.map(l=>({...l.metadata,body:l.body}))}function ht(t){return{async get(e){const o=await z(t.pmRoot,e,t.settings.id_prefix,t.settings.item_format,t.typeToFolder);if(!o)return null;const{document:i}=await ut(o,{schema:t.settings.schema});return{item:i.metadata,body:i.body}},list:()=>te(t.pmRoot,t.settings.item_format,t.typeToFolder,void 0,t.settings.schema)}}async function ee(t,e){const o=new Set(Object.values(e)),i=[];return await Promise.all([...o].map(async r=>{try{const n=await _.readdir(E.join(t,r));for(const d of n)for(const l of qt)if(d.toLowerCase().endsWith(l)){i.push(d.slice(0,-l.length));break}}catch{}})),i}async function gt(t,e,o,i){const r=at(e,o),n=await ee(t,i);if(n.length===0)return[];const d=Math.max(3,Math.floor(r.length/2));return n.map(f=>({id:f,distance:Dt(f,r,d)})).filter(f=>f.distance!==null).sort((f,s)=>f.distance-s.distance).slice(0,3).map(f=>f.id)}async function oe(t,e,o,i){const r=await Pt(t,e,o);if(r)return r;const n=await gt(t,e,o,i),d=["Confirm the active --path/PM_PATH scope, then retry with a valid id."];return n.length>0&&d.unshift(`Did you mean one of: ${n.join(", ")}?`),new y(`Item ${e} not found`,k.NOT_FOUND,{code:"item_not_found",id:e,nextSteps:d})}function pt(t,e){return t==="claim"||e===!0&&(t==="comment_add"||t==="comment_edit"||t==="comment_delete"||t==="note_add"||t==="learning_add"||t==="release"||t==="update"||t==="update_ownership_bypass"||t==="update_audit")}async function wt(t){const e=t.typeToFolder??Wt(t.settings,X()).type_to_folder,o=await z(t.pmRoot,t.id,t.settings.id_prefix,t.settings.item_format,e);if(!o)throw await oe(t.pmRoot,t.id,t.settings.id_prefix,e);const i=await Mt(t.pmRoot,o.id,t.settings.locks.ttl_seconds,t.author,!!t.force,t.settings.governance.force_required_for_stale_lock,t.settings.locks.wait_ms,{waitPolicy:"progress"}),r=i.release;try{const n=[],{raw:d,document:l}=await ut(o,{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames,warnings:n}),f=l.metadata.assignee?.trim(),s=Kt(f),m=l.metadata.claim_principal?.trim()||f,g=Vt(t.author),c=Gt(t.settings),u=!!s&&m!==g,h=u&&t.callerClaimScope!==void 0&&await t.callerClaimScope({document:l,storageId:o.id,callerPrincipal:g});if(u&&!h&&!t.force&&!pt(t.op,t.bypassAssigneeConflict)){if(c.ownership_enforcement==="strict")throw new y(`Item ${o.id} is assigned to ${s}. Use --force to override.`,k.CONFLICT);c.ownership_enforcement==="warn"&&n.push(`ownership_warning:assignee_conflict:${o.id}:${s}`)}return{typeToFolder:e,located:o,originalRaw:d,document:l,warnings:n,releaseLock:r,lease:i,callerClaimScoped:h}}catch(n){throw await r(),n}}function yt(t){return Object.keys(t).length===0?void 0:t}async function _t(t,e,o,i){return t.fence(async()=>{let r;try{r=await _.readFile(e.itemPath,"utf8")}catch(n){if(!Et(n))throw n;r=null}if(r!==o)throw new y(`Item ${e.id} changed after this mutation read it; refusing to overwrite the newer revision. Nothing was written.`,k.CONFLICT,{code:"stale_revision",item_id:e.id,reason:r===null?"item_removed":"item_revision_changed",required:"Re-read the item and apply the mutation again; the newer stored revision was kept."});return i()})}function ie(t,e,o){if(!t.handled||typeof t.result!="object"||t.result===null)return{effectiveTargetItemPath:e,effectiveSerializedAfter:o,skipItemWrite:!1};const i=t.result;return{effectiveTargetItemPath:typeof i.target_item_path=="string"&&i.target_item_path.trim().length>0?i.target_item_path:e,effectiveSerializedAfter:typeof i.contents=="string"?i.contents:o,skipItemWrite:i.skip_write===!0}}async function It(t){try{const e=await z(t.pmRoot,t.id,t.settings.id_prefix,t.settings.item_format,t.typeToFolder);if(!e)return{document:tt};const o=nt(await _.readFile(e.itemPath,"utf8"),{format:e.item_format,requireSupportedFormat:!0,schema:t.settings.schema,extensionFieldNames:H(t.extensionFieldNames)});return o.metadata.id===t.embeddedId?{document:o}:{document:t.fallback,revision:vt}}catch{return{document:t.fallback,revision:vt}}}const vt="unreadable-after-storage-override";async function ne(t){const e=await Z("item_store_delete",t),o=e.handled&&typeof e.result=="object"&&e.result!==null?e.result:{};return{effectiveItemPath:typeof o.item_path=="string"&&o.item_path.trim().length>0?o.item_path:t.item_path,skipDelete:o.skip_delete===!0,warnings:e.warnings}}async function re(t){if(!t.skipItemWrite){if(t.effectiveTargetItemPath!==t.originalItemPath){await A(t.originalItemPath,t.originalRaw),await _.rm(t.effectiveTargetItemPath,{force:!0});return}await A(t.originalItemPath,t.originalRaw)}}function ae(t,e){Yt(t.metadata)&&e.push("deferred_fields")}function se(t,e){return e?{storageId:t,callerClaimScoped:!0}:{storageId:t}}function de(t,e,o){o&&e.length===0||ae(t,e)}function ce(t,e){return t===!0||e}async function U(t){kt(t.op);const e=await wt({pmRoot:t.pmRoot,settings:t.settings,id:t.id,op:t.op,author:t.author,force:t.force,bypassAssigneeConflict:t.bypassAssigneeConflict,callerClaimScope:t.callerClaimScope,extensionFieldNames:t.extensionFieldNames,typeToFolder:t.typeToFolder}),{typeToFolder:o,located:i,originalRaw:r,document:n,warnings:d,releaseLock:l,lease:f,callerClaimScoped:s}=e;try{Y(t.pmRoot,n,i.id);const m=W(n,{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),g=W(structuredClone(n),{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),c=await t.mutate(g,se(i.id,s));if(de(g,c.changedFields,s),ce(t.skipNoop,s)&&c.changedFields.length===0)return{item:m.metadata,body:m.body,changedFields:[],warnings:[...d,...c.warnings??[]]};const u={...t.resolveHistoryContext?.(),...Nt(t.pmRoot,i.id),...Ct(t.pmRoot,[i.id,n.metadata.id])},h=Math.max(rt(m.metadata),rt(g.metadata));Lt(Bt(t.pmRoot),h),h>At(g.metadata)&&(g.metadata.pm_format_version=h,c.changedFields.push("pm_format_version")),g.metadata.updated_at=lt();const a=W(g,{schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),p=await G({pmRoot:t.pmRoot,settings:t.settings,operation:t.op,author:t.author,before:m,after:a});await Q({pm_root:t.pmRoot,operation:t.op,before:m,after:a,changed_fields:c.changedFields,author:t.author,sdk:ht({pmRoot:t.pmRoot,settings:t.settings,typeToFolder:o})});const C=await it({pmRoot:t.pmRoot,settings:t.settings,itemId:i.id,commandLabel:t.op}),R="toon",x=Ot(a,{format:R,schema:t.settings.schema,extensionFieldNames:t.extensionFieldNames}),I=mt(t.pmRoot,a.metadata.type,i.id,R,o),b=ct(t.pmRoot,i.id),w=await _t(f,i,r,async()=>{const S=await Z("item_store_write",{op:t.op,pm_root:t.pmRoot,item_id:i.id,source_item_path:i.itemPath,target_item_path:I,history_path:b,item_format:R,before:m,after:a,contents:x}),{effectiveTargetItemPath:F,effectiveSerializedAfter:q,skipItemWrite:P}=ie(S,I,x),Ft=await st(t.pmRoot,t.author);let B=[];try{P||await A(F,q),!P&&F!==i.itemPath&&await _.rm(i.itemPath);const xt=ot({nowIso:a.metadata.updated_at,author:t.author,op:t.op,before:m,after:a,message:t.message,context:yt({...u,...p.decisions.length===0?{}:{workflow_policies:p.decisions},...K(t.pmRoot,[i.id,n.metadata.id],t.op)})});try{await et(b,xt)}catch(bt){throw await re({skipItemWrite:P,effectiveTargetItemPath:F,originalItemPath:i.itemPath,originalRaw:r}),bt}P||(B=await dt({pmRoot:t.pmRoot,preferredFormat:t.settings.item_format,typeToFolder:o,schema:t.settings.schema,itemPath:F,previousItemPath:i.itemPath,document:a}))}finally{await Ft()}const Rt=P||F!==I||q!==x;return{derivedIndexWarnings:B,effectiveTargetItemPath:F,overrideWarnings:S.warnings,stored:Rt?await It({pmRoot:t.pmRoot,settings:t.settings,id:i.id,typeToFolder:o,extensionFieldNames:t.extensionFieldNames,fallback:a,embeddedId:a.metadata.id}):{document:a}}}),{derivedIndexWarnings:v,effectiveTargetItemPath:L,stored:N}=w;V(t.pmRoot,N.document,i.id,[a.metadata.id],N.revision);const T=[...await D({path:L,scope:"project",op:t.op,item_id:a.metadata.id,item_type:a.metadata.type,before:m,after:a,changed_fields:c.changedFields}),...await D({path:b,scope:"project",op:`${t.op}:history`,item_id:a.metadata.id,item_type:a.metadata.type,before:m,after:a,changed_fields:c.changedFields})];return J({id:a.metadata.id,op:t.op,item_type:a.metadata.type,previous_status:m.metadata.status,status:a.metadata.status,previous:j(m.metadata,c.changedFields),current:j(a.metadata,c.changedFields),changed_fields:c.changedFields}),{item:a.metadata,body:a.body,changedFields:c.changedFields,warnings:[...d,...c.warnings??[],...p.warnings,...C.warnings,...w.overrideWarnings,...v,...T]}}finally{await l()}}async function Ue(t){const{historyContext:e,...o}=t;return U({...o,resolveHistoryContext:()=>e})}async function qe(t){return U(t)}async function Be(t){return U(t)}const Ge={appendWarning:ft,bypassesAssigneeConflict:pt,buildDidYouMeanSuggestions:gt,isErrno:Jt};async function Ve(t){const e=await wt({pmRoot:t.pmRoot,settings:t.settings,id:t.id,op:"delete",author:t.author,force:t.force}),{located:o,originalRaw:i,document:r,warnings:n,releaseLock:d,lease:l}=e;try{Y(t.pmRoot,r,o.id);const f=H(void 0),s=W(r,{schema:t.settings.schema,extensionFieldNames:f}),m=await G({pmRoot:t.pmRoot,settings:t.settings,operation:"delete",author:t.author,before:s,after:null,dryRun:t.dryRun});await Q({pm_root:t.pmRoot,operation:"delete",before:s,after:null,changed_fields:["deleted"],author:t.author,dry_run:t.dryRun===!0,sdk:ht({pmRoot:t.pmRoot,settings:t.settings,typeToFolder:e.typeToFolder})});const g=await it({pmRoot:t.pmRoot,settings:t.settings,itemId:o.id,commandLabel:"delete"}),c=lt(),u=tt,h=ot({nowIso:c,author:t.author,op:"delete",before:s,after:u,message:t.message,context:yt({...m.decisions.length===0?{}:{workflow_policies:m.decisions},...K(t.pmRoot,[o.id,r.metadata.id],"delete")})}),a=ct(t.pmRoot,o.id),p=()=>ne({op:"delete",pm_root:t.pmRoot,item_id:o.id,item_path:o.itemPath,history_path:a,before:s});if(t.dryRun===!0){const w=await p();return{item:s.metadata,changedFields:["deleted"],targetPath:w.effectiveItemPath,warnings:[...n,...m.warnings,...g.warnings,...w.warnings]}}const C=await _t(l,o,i,async()=>{const{effectiveItemPath:w,skipDelete:v,warnings:L}=await p(),N=await st(t.pmRoot,t.author);let T=[];try{v||await _.rm(w);try{await et(a,h)}catch(S){throw v||await A(w,i),S}v||(T=await dt({pmRoot:t.pmRoot,preferredFormat:t.settings.item_format,typeToFolder:e.typeToFolder,schema:t.settings.schema,itemPath:w,document:null}))}finally{await N()}return{derivedIndexWarnings:T,effectiveItemPath:w,overrideWarnings:L,stored:v||w!==o.itemPath?await It({pmRoot:t.pmRoot,settings:t.settings,id:o.id,typeToFolder:e.typeToFolder,fallback:u,embeddedId:r.metadata.id}):{document:u}}}),{derivedIndexWarnings:R,effectiveItemPath:x,stored:I}=C;V(t.pmRoot,I.document,o.id,[r.metadata.id],I.revision);const b=[...await D({path:x,scope:"project",op:"delete",item_id:s.metadata.id,item_type:s.metadata.type,before:s,after:u,changed_fields:["deleted"]}),...await D({path:a,scope:"project",op:"delete:history",item_id:s.metadata.id,item_type:s.metadata.type,before:s,after:u,changed_fields:["deleted"]})];return J({id:s.metadata.id,op:"delete",item_type:s.metadata.type,previous_status:s.metadata.status,previous:j(s.metadata,Object.keys(s.metadata)),changed_fields:["deleted"]}),{item:s.metadata,changedFields:["deleted"],warnings:[...n,...m.warnings,...g.warnings,...C.overrideWarnings,...R,...b]}}finally{await d()}}export{oe as buildItemNotFoundError,ht as createMutationGuardSdk,Ve as deleteItem,Ge as itemStoreTestOnly,te as listAllItemMetadata,He as listAllItemMetadataLight,ze as listAllItemMetadataWithBody,z as locateItem,Be as mutateItem,Ue as mutateItemWithHistoryContext,qe as mutateItemWithHistoryContextResolver,ut as readLocatedItem,Zt as readLocatedItemSnapshot};
2
2
  //# sourceMappingURL=item-store.js.map
@@ -1,4 +1,4 @@
1
- import type{GlobalOptions}from "../core/shared/command-types.js";export{quoteWindowsCommandArg,quoteCommandArg,renderPmCommand}from "../core/shared/command-line.js";export{URL_CREDENTIAL_PLACEHOLDER,invocationCarriesUrlCredentials,redactUrlCredentialsInText,redactUrlCredentialsInToken,runWithUrlCredentialInvocation,}from "../core/shared/url-credentials.js";
1
+ import type{GlobalOptions}from "../core/shared/command-types.js";export{COMMAND_SHELL_ENV,quoteCmdCommandArg,quoteCommandArg,quotePosixCommandArg,quotePowerShellCommandArg,quoteWindowsCommandArg,renderPmCommand,resolveCommandShellDialect,type CommandShellDialect,}from "../core/shared/command-line.js";export{URL_CREDENTIAL_PLACEHOLDER,invocationCarriesUrlCredentials,redactUrlCredentialsInText,redactUrlCredentialsInToken,runWithUrlCredentialInvocation,}from "../core/shared/url-credentials.js";
2
2
  /** Tracker selection a rendered recovery command must preserve: the requested path and extension isolation. */
3
3
  export type CommandScope=Pick<GlobalOptions,"path"|"noExtensions">;
4
4
  /** Retain caller scope before runtime dispatch resolves its working storage path. */
@@ -1,2 +1,2 @@
1
- import{findBootstrapCommandTokenIndex as a}from"./cli-contracts/bootstrap-command-scanner.js";import c from"node:path";import{resolveImplicitPmRoot as d,resolvePmRoot as m,resolveWorkspaceRoot as u}from"../core/store/paths.js";import{isPathWithinDirectory as f}from"../core/fs/path-utils.js";import{quoteWindowsCommandArg as v,quoteCommandArg as _,renderPmCommand as k}from"../core/shared/command-line.js";import{URL_CREDENTIAL_PLACEHOLDER as L,invocationCarriesUrlCredentials as U,redactUrlCredentialsInText as W,redactUrlCredentialsInToken as g,runWithUrlCredentialInvocation as y}from"../core/shared/url-credentials.js";const i=new WeakMap;function P(e){i.set(e,e.path)}function l(e){if(!process.env.PM_PATH?.trim())return;const t=m(e);return f(u(t),e)&&t===d(e)?void 0:c.relative(e,t)||"."}function R(e,t=process.cwd()){const n=i.has(e)?i.get(e):e.path,r=n?.trim()?n:l(t),o=r?["--pm-path",r]:[];return e.noExtensions&&o.push("--no-extensions"),o}const p=new Set(["--literal","--regex","--replacement"]);function h(e){const t=a(e);if(t===void 0)return!1;if(e[t]==="history-redact")return!0;if(e[t]!=="history")return!1;const n=e.slice(t+1),r=a(n);return r!==void 0&&n[r]==="redact"}function S(e){if(!h(e))return[...e];const t=[];let n=!1;for(const r of e){if(n){t.push("[redacted]"),n=!1;continue}n=!1;const o=r.indexOf("="),s=o>=0?r.slice(0,o):r;if(!p.has(s)){t.push(r);continue}if(o>=0){t.push(`${s}=[redacted]`);continue}t.push(s),n=!0}return t}export{L as URL_CREDENTIAL_PLACEHOLDER,P as capturePmCommandScope,U as invocationCarriesUrlCredentials,h as isHistoryRedactInvocation,_ as quoteCommandArg,v as quoteWindowsCommandArg,S as redactSensitiveCommandArgs,W as redactUrlCredentialsInText,g as redactUrlCredentialsInToken,k as renderPmCommand,R as resolvePmCommandScopeArgs,y as runWithUrlCredentialInvocation};
1
+ import{findBootstrapCommandTokenIndex as a}from"./cli-contracts/bootstrap-command-scanner.js";import d from"node:path";import{resolveImplicitPmRoot as c,resolvePmRoot as m,resolveWorkspaceRoot as u}from"../core/store/paths.js";import{isPathWithinDirectory as l}from"../core/fs/path-utils.js";import{COMMAND_SHELL_ENV as v,quoteCmdCommandArg as T,quoteCommandArg as _,quotePosixCommandArg as g,quotePowerShellCommandArg as L,quoteWindowsCommandArg as D,renderPmCommand as k,resolveCommandShellDialect as H}from"../core/shared/command-line.js";import{URL_CREDENTIAL_PLACEHOLDER as U,invocationCarriesUrlCredentials as W,redactUrlCredentialsInText as y,redactUrlCredentialsInToken as M,runWithUrlCredentialInvocation as O}from"../core/shared/url-credentials.js";const i=new WeakMap;function P(e){i.set(e,e.path)}function f(e){if(!process.env.PM_PATH?.trim())return;const t=m(e);return l(u(t),e)&&t===c(e)?void 0:d.relative(e,t)||"."}function S(e,t=process.cwd()){const n=i.has(e)?i.get(e):e.path,o=n?.trim()?n:f(t),r=o?["--pm-path",o]:[];return e.noExtensions&&r.push("--no-extensions"),r}const p=new Set(["--literal","--regex","--replacement"]);function C(e){const t=a(e);if(t===void 0)return!1;if(e[t]==="history-redact")return!0;if(e[t]!=="history")return!1;const n=e.slice(t+1),o=a(n);return o!==void 0&&n[o]==="redact"}function E(e){if(!C(e))return[...e];const t=[];let n=!1;for(const o of e){if(n){t.push("[redacted]"),n=!1;continue}n=!1;const r=o.indexOf("="),s=r>=0?o.slice(0,r):o;if(!p.has(s)){t.push(o);continue}if(r>=0){t.push(`${s}=[redacted]`);continue}t.push(s),n=!0}return t}export{v as COMMAND_SHELL_ENV,U as URL_CREDENTIAL_PLACEHOLDER,P as capturePmCommandScope,W as invocationCarriesUrlCredentials,C as isHistoryRedactInvocation,T as quoteCmdCommandArg,_ as quoteCommandArg,g as quotePosixCommandArg,L as quotePowerShellCommandArg,D as quoteWindowsCommandArg,E as redactSensitiveCommandArgs,y as redactUrlCredentialsInText,M as redactUrlCredentialsInToken,k as renderPmCommand,H as resolveCommandShellDialect,S as resolvePmCommandScopeArgs,O as runWithUrlCredentialInvocation};
2
2
  //# sourceMappingURL=command-line.js.map
@@ -1,2 +1,2 @@
1
- import{AsyncLocalStorage as tt}from"node:async_hooks";import{attachExtensionReadOutputRows as et}from"./read-output/extension.js";import{renderPmCommand as P}from"./command-line.js";import{attachOutputOmissionReceipt as nt}from"./output-projection.js";import{encodeQueryCursor as rt}from"./pagination.js";import{applyReadOutputDimensions as ot,decodeReadOutputContinuationCursor as it,isReadResultOmittedForBudget as q,resolveReadOutputSurface as dt,stabilizeReadOutputReceiptEstimates as ut}from"./read-output-contracts.js";import{estimateReadOutputTokens as I,MAX_ESTIMATE_ITERATIONS as st,readOutputMeasurementFormat as T,registerReadOutputPassHooks as at,resolveReadOutputRecoveryBudget as ct}from"./read-output-budget.js";import{propagateContextUsageServingReceipt as E}from"./context-usage.js";import{readOutputContinuationRowCollections as ft}from"./read-output-rows.js";import{EXIT_CODE as R}from"../core/shared/constants.js";import{PmCliError as B}from"../core/shared/errors.js";import{compactExplanatoryString as lt,isContinuationTokenKey as _t,isTrackerItemDocumentKey as gt}from"../core/shared/text-normalization.js";const mt="limit_overridden_by_intent",z=Object.freeze([{command:"context",intent:"orient",description:"Bounded active hierarchy, ownership, blockers, and recent progress.",included_field_groups:["summary","focus","hierarchy","blockers","activity"],token_budget:3e3,source:"core"},{command:"context",intent:"handoff",description:"Active ownership, evidence, decisions, and immediate continuation context.",included_field_groups:["summary","focus","in_progress","decisions","activity"],token_budget:2200,source:"core"},{command:"get",intent:"inspect",description:"Standard-depth item metadata, relationships, evidence, and lifecycle state.",included_field_groups:["item","children","claim_state","linked"],token_budget:3200,source:"core"},{command:"list",intent:"triage",description:"A budget-derived page of compact governance, ownership, priority, and blocker rows for triage.",included_field_groups:["identity","governance","ownership","dependencies"],token_budget:3200,source:"core"},{command:"next",intent:"execute",description:"The highest-ranked actionable work with concise ranking evidence.",included_field_groups:["recommended"],token_budget:1200,source:"core"},{command:"search",intent:"discover",description:"A budget-derived page of ranked canonical lineage candidates with compact match evidence.",included_field_groups:["identity","status","lineage","match"],token_budget:1800,source:"core"}]),U=new tt;function bt(){return U.getStore()??z}function Yt(t,e){return U.run(kt(t.workspaceContracts,t.packageContracts),e)}function ht(t,e){const n=t.command.trim().toLowerCase(),r=t.intent.trim().toLowerCase(),i=`${n}:${r}`;if(!/^[a-z0-9][a-z0-9-]*$/.test(n)||!/^[a-z0-9][a-z0-9-]*$/.test(r))throw new TypeError(`Invalid context intent command or name: ${i}`);if(t.description.trim().length===0)throw new TypeError(`Context intent ${i} requires a non-empty description`);if(!Number.isSafeInteger(t.token_budget)||t.token_budget<=0)throw new TypeError(`Context intent ${i} requires a positive integer token_budget`);const o=[...new Set(t.included_field_groups.map(d=>d.trim()).filter(Boolean))];if(o.length===0)throw new TypeError(`Context intent ${i} requires included_field_groups`);return{command:n,intent:r,description:t.description.trim(),included_field_groups:o,token_budget:t.token_budget,source:e}}function kt(t=[],e=[]){const n=[{source:"core",contracts:z,allowOverride:!1},{source:"package",contracts:e,allowOverride:!1},{source:"workspace",contracts:t,allowOverride:!0}],r=new Map,i=new Set;for(const o of n){i.clear();for(const d of o.contracts){const s=ht(d,o.source),u=`${s.command}:${s.intent}`;if(i.has(u))throw new TypeError(`Duplicate context intent declaration: ${u}`);if(i.add(u),!o.allowOverride&&r.has(u))throw new TypeError(`Duplicate context intent declaration: ${u}`);r.set(u,s)}}return[...r.values()].sort((o,d)=>o.command.localeCompare(d.command)||o.intent.localeCompare(d.intent))}function G(t,e,n=bt(),r=[]){const i=t.trim().toLowerCase(),o=e.trim().toLowerCase(),d=n.find(a=>a.command===i&&a.intent===o);if(d)return{...d,source:d.source??"core"};const s=n.filter(a=>a.command===i).map(a=>a.intent);if(s.length===0)return;const u=s.map(a=>{const f=Array.from({length:o.length+1},(b,g)=>g);for(let b=1;b<=a.length;b+=1){let g=f[0];f[0]=b;for(let h=1;h<=o.length;h+=1){const j=f[h];f[h]=Math.min(f[h]+1,f[h-1]+1,g+(a[b-1]===o[h-1]?0:1)),g=j}}return{candidate:a,distance:f[o.length]}}).sort((a,f)=>a.distance-f.distance||a.candidate.localeCompare(f.candidate))[0].candidate,c=[i,...r,"--for",o],l=[i,...r,"--for",u],_=P(l);throw new B(`Unknown context intent "${o}" for ${i}. Did you mean "${u}"?`,R.USAGE,{code:"unknown_context_intent",reason:"unknown_intent",field:"for",flag:"--for",value:o,required:`Use a declared ${i} intent.`,why:"Intent names are command-local contracts and cannot be inferred from output section names.",nextSteps:[_],recovery:{recovery_mode:"compact",attempted_command:P(c),allowed_values:[...s].sort(),suggested_retry:_,suggested_retry_args:l}})}function A(t,e){const n=k(t.limit),r=String(n===void 0?e:Math.min(n,e));return(t.limit===void 0||n!==void 0)&&(t.limit=r),r}const X={context:(t,e,n,r)=>{t.section===void 0&&t.depth===void 0&&(t.section=e.intent==="handoff"?["activity","progress","blockers"]:["hierarchy","blockers","activity"]),t.depth===void 0&&(t.depth=e.intent==="handoff"?"deep":"standard");const i=v(r,t.tokenBudget,e.token_budget),o=C("context",e.intent,i,n),d=A(t,o);t.activityLimit===void 0&&(t.activityLimit=d)},get:t=>{t.depth===void 0&&t.fields===void 0&&(t.depth="standard")},list:(t,e,n,r)=>{t.brief===void 0&&t.compact===void 0&&t.full===void 0&&t.fields===void 0&&(t.fields="id,title,status,type,priority,parent,assignee,risk,blocked_by");const i=v(r,t.tokenBudget,e.token_budget),o=C("list",e.intent,i,n);A(t,o)},next:t=>{t.readyOnly===void 0&&(t.readyOnly=!0)},search:(t,e,n,r)=>{t.compact===void 0&&t.full===void 0&&t.fields===void 0&&(t.compact=!0);const i=v(r,t.tokenBudget,e.token_budget),o=C("search",e.intent,i,n);A(t,o)}};function Ht(t,e,n=[]){const r=e.tokenBudget??e.token_budget;if(typeof e.for!="string"){if(r!==void 0&&(t==="get"||t==="list"||t==="search"))throw new B("--token-budget requires a declared context intent selected with --for",R.USAGE,{code:"missing_required_option",field:"for",required:"Select a context intent with --for when setting --token-budget.",why:"A token-budget override has no projection contract to constrain without a selected intent.",nextSteps:["Retry with --for <intent> --token-budget <n>, or omit --token-budget."]});if(e.tokenBudget!==void 0||e.token_budget===void 0)return e;const u={...e,tokenBudget:r};return delete u.token_budget,u}const i=G(t,e.for,void 0,n),o=w(e),d=k(r)!==void 0||typeof o=="number",s={...e};return s.tokenBudget===void 0&&r!==void 0&&(s.tokenBudget=r),delete s.token_budget,typeof o=="number"?s.tokenBudget=String(o):s.tokenBudget===void 0&&(s.tokenBudget=String(i.token_budget)),X[t](s,i,d,o),s}const pt={context:"bounded_sections",get:"standard_item",list:"bounded_fields_and_rows",next:"bounded_ranked_rows",search:"bounded_ranked_rows"},x=256;function N(t,e,n=!0,r=!0){return Array.isArray(t)?t.map(i=>N(i,e,n,!1)):t!==null&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([i,o])=>[i,n&&typeof o=="string"&&_t(i)?o:N(o,e,n&&!(r&&gt(e,i)),!1)])):typeof t=="string"?lt(t):t}function k(t){const e=typeof t=="number"?t:typeof t=="string"&&/^\d+$/u.test(t.trim())?Number(t):Number.NaN;return Number.isSafeInteger(e)&&e>0?e:void 0}function w(t){const e=t.outputBudget??t.output_budget;return e==="unbounded"?e:k(e)}function yt(t){return w(t)===void 0?"--token-budget":"--output-budget"}function v(t,e,n){return typeof t=="number"?t:wt(e,n)}function wt(t,e){const n=k(t);if(n===void 0)return e;if(n<x)throw new B(`Context intent token budget must be at least ${x}`,R.USAGE,{code:"invalid_argument_value",reason:"below_minimum",field:"tokenBudget",value:String(t),required:`Use an integer token budget of at least ${x}.`,why:"Smaller ceilings cannot contain the minimum machine-readable intent receipt.",nextSteps:[`Retry with --token-budget ${x} or omit the override.`]});return n}function W(t,e){const n=t==="context"&&e==="orient";return t==="context"?n?{overhead:1200,rowCost:600}:{overhead:800,rowCost:500}:{overhead:t==="list"?520:480,rowCost:16}}function C(t,e,n,r){if(t==="get"||t==="next")return;const{overhead:i,rowCost:o}=W(t,e),d=Math.max(t==="context"?1:2,Math.floor((n-i)/o));return r?d:Math.min(t==="context"?20:100,d)}function p(t,e,n){const r=T(n),i=n.outputRowContract===!0||n.output_row_contract===!0;let o=e.estimated_tokens,d=o;for(let s=0;s<st;s+=1){e.estimated_tokens=o;const u=I(i||!Object.hasOwn(t,"row_contract")?t:Object.fromEntries(Object.entries(t).filter(([c])=>c!=="row_contract")),r);if(u===o)return;o=u,d=Math.max(d,o)}e.estimated_tokens=d}const F={context:["high_level","low_level","blocked_fallback","recently_created","unparented","hierarchy","activity","blockers"],get:["children"],list:["items"],next:["ready","decision_needed","gate_needed","containers","blocked","held_by_others"],search:["items"]};function K(t){try{const e=JSON.parse(Buffer.from(t,"base64url").toString("utf8"));return typeof e.fingerprint!="string"||!Number.isSafeInteger(e.after_index)?void 0:{fingerprint:e.fingerprint,after_index:e.after_index,...typeof e.snapshot=="string"?{snapshot:e.snapshot}:{}}}catch{return}}function xt(t){if(t===null||typeof t!="object")return;if(typeof t.id=="string")return t.id;const e=t.item?.id;return typeof e=="string"?e:void 0}function vt(t,e,n,r){let i=!1;for(;;){if(p(t,e,r),e.estimated_tokens<=e.token_budget||n.length<=1)return i;const o=Buffer.byteLength(JSON.stringify(n),"utf8"),d=(e.estimated_tokens-e.token_budget)*4;n.splice(-Math.min(n.length-1,Math.max(1,Math.ceil(d/Math.max(1,Math.ceil(o/n.length)))))),i=!0}}function Ct(t,e,n){const r=t.items,i=typeof t.next_cursor=="string",o=i?t.next_cursor:n.after;if(!Array.isArray(r)||typeof o!="string")return!1;const d=K(o);if(d===void 0)return!1;const s=r.length,u=[...r];let c=!1;for(;;){if(c=vt(t,e,r,n)||c,!c)return!1;const l=xt(r.at(-1));if(l===void 0)return r.splice(0,r.length,...u),p(t,e,n),!1;if(t.next_cursor=rt(d.fingerprint,l,i?d.after_index-(s-r.length):d.after_index+r.length,d.snapshot),p(t,e,n),e.estimated_tokens<=e.token_budget||r.length<=1)break}return typeof t.count=="number"&&(t.count=r.length),typeof t.applied_limit=="number"&&(t.applied_limit=r.length),!0}function Ot(t,e,n,r){if(t==="list"||t==="search")return Ct(e,n,r);if(t!=="next"||typeof e.next_cursor=="string")return!1;let i=!1;for(;;){if(p(e,n,r),n.estimated_tokens<=n.token_budget)return i;const o=F[t].map(a=>({key:a,rows:Array.isArray(e[a])?e[a]:[]})).filter(({rows:a})=>a.length>0).sort((a,f)=>f.rows.length-a.rows.length||a.key.localeCompare(f.key))[0];if(o===void 0)return i;const d=F[t].reduce((a,f)=>a+(Array.isArray(e[f])?e[f].length:0),0);if(d<=1)return i;const s=Math.min(o.rows.length,d-1),u=Buffer.byteLength(JSON.stringify(o.rows),"utf8"),c=Math.max(1,Math.ceil(u/o.rows.length)),l=(n.estimated_tokens-n.token_budget)*4,_=Math.min(s,Math.max(1,Math.ceil(l/c)));o.rows.splice(-_,_),i=!0}}function S(t,e,n){if(typeof e.for!="string")return n;const r=t.startsWith("list-")?"list":t;if(!(r in X))return n;const i=r,o=G(i,e.for),d=w(e),s=v(d,e.tokenBudget??e.token_budget,o.token_budget),u={command:i,intent:o.intent,source:o.source,included_field_groups:[...o.included_field_groups],token_budget:s,declared_token_budget:o.token_budget,token_budget_override:s-o.token_budget,estimated_tokens:0,within_budget:!0,degradation:pt[i],declaration_feasible:!0,result_omitted:!1},c={...n},l=C(i,o.intent,u.token_budget,k(e.tokenBudget??e.token_budget)!==void 0||typeof d=="number");if(l!==void 0){const g=k(e.limit),h=g!==void 0&&g<l;u.budget_derived_limit=l,u.binding_constraint=h?"explicit_limit":"token_budget",u.limit_reason=h?"The caller supplied a smaller row limit than the budget-derived ceiling.":"The selected intent token budget constrains the effective row ceiling.",c.budget_derived_limit=l,Bt({builtInCommand:i,intent:o.intent},u,c,e)}const _=M.get(e)??0,a=u.token_budget;u.token_budget=a-_;const f=d==="unbounded"?$(c,u,e):It(i,c,u,e,dt(t,e));u.declaration_feasible=u.estimated_tokens<=u.declared_token_budget;const b=J(d,u,f,()=>Y(t,i,o.intent,{...u,token_budget:a,estimated_tokens:u.estimated_tokens+_},c,e));return u.result_omitted&&(u.estimated_tokens+=_,u.declaration_feasible=u.estimated_tokens<=u.declared_token_budget),u.token_budget=a,b}function $(t,e,n){const r={...t,context_intent:e};return p(r,e,n),r}function It(t,e,n,r,i){let o=$(e,n,r);return n.estimated_tokens>n.token_budget&&(n.degradation="recursive_budget_compaction",o=$(N(e,i),n,r)),n.estimated_tokens>n.token_budget&&Ot(t,o,n,r)&&(n.degradation="budget_row_compaction",p(o,n,r)),o}const M=new WeakMap;function J(t,e,n,r){return e.estimated_tokens<=e.token_budget||(e.within_budget=!1,t==="unbounded")?n:(e.degradation="budget_receipt_only",e.result_omitted=!0,typeof t=="number"?{output_budget_exceeded:{omitted_result:!0,reason:"requested_budget_infeasible",restore_with:"Unbounded",recovery:{outputBudget:"unbounded"}},context_intent:e}:{budget_exceeded:{omitted_result:!0,reason:e.token_budget_override===0?"declared_budget_infeasible":"effective_budget_infeasible",restore_with:r()},context_intent:e})}const Tt=["applied_limit","completeness","context_intent","count","filters","has_more","now","omission_receipt","projection","row_contract","sorting","total","truncated"];function V(t,e){if(typeof t.after!="string"||t.after.length===0||q(e))return e;const n=K(t.after)?.fingerprint??"opaque_cursor",r={...e};for(const i of Tt)delete r[i];return r.continuation_contract={fingerprint:n,metadata:"reference",restore_with:"omit --after"},r}function m(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Et(t,e){const n=t==="get"&&m(e.item)&&typeof e.item.id=="string"?e.item.id:t==="search"&&typeof e.query=="string"?e.query:void 0;return n===void 0?"":` ${Q(n)}`}function Q(t){return`'${t.replaceAll("'",`'"'"'`)}'`}function Rt(t){return typeof t.fields=="string"&&t.fields.trim()!==""?` --fields ${Q(t.fields)}`:""}function Bt(t,e,n,r){const i=k(r.limit),o=e.budget_derived_limit;if(i===void 0||i<=o)return;const{overhead:d,rowCost:s}=W(t.builtInCommand,t.intent),u=Math.max(e.token_budget,d+s*i);e.limit_reason=`The ${e.token_budget}-token ${t.intent} budget carries ${o} rows, so it reduced the caller's --limit ${i}.`,e.limit_override={flag:"--limit",requested:i,effective:o,...Number.isSafeInteger(u)?{token_budget_for_requested:u,restore_with:`${yt(r)} ${u}`}:{}};const c=`${mt}:--limit ${i}->${o}`;n.warnings=Array.isArray(n.warnings)?[...n.warnings,c]:[c],m(n.filters)&&(n.filters={...n.filters,requested_limit:String(i)})}function Y(t,e,n,r,i,o){const d=Et(e,i),s=e==="get"?"":` --limit ${r.budget_derived_limit??1}`,{output_budget:u}=ct({effective_budget_tokens:r.token_budget,measured_result_tokens:r.estimated_tokens});return`pm ${t}${d}${Rt(o)} --for ${n} --token-budget ${u}${s}`}function y(t,e){if(m(t))return typeof t[e]=="number"?t[e]:void 0}function H(t,e){let n=t;for(let r=0;r<8;r+=1){At(n);const i=y(n.context_intent,"estimated_tokens"),o=y(n.read_output,"estimated_tokens"),d=y(n.read_session,"spent_this_call_tokens");if(m(n.context_intent)&&n.context_intent.result_omitted!==!0&&p(n,n.context_intent,e),n=ut(n,e),y(n.context_intent,"estimated_tokens")===i&&y(n.read_output,"estimated_tokens")===o&&y(n.read_session,"spent_this_call_tokens")===d)break}return n}function At(t){const e=t.context_intent;m(e)&&Number(e.estimated_tokens)>Number(e.token_budget)&&(e.within_budget=!1)}function Nt(t,e){const n=e.context_intent;if(!m(n)||n.result_omitted===!0)return;const r=n.degradation==="recursive_budget_compaction"||n.degradation==="budget_row_compaction",i={...e};for(const o of ft(t)){const d=e[o.path];if(Array.isArray(d)&&Array.isArray(o.value)&&d.length<=o.value.length){const s=o.value.slice(0,d.length);i[o.path]=r?s.map(L):s}}return i}function L(t){return Array.isArray(t)?t.map(L):t!==null&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,L(n)])):t}function Zt(t,e,n){const r=nt(t,et(t??"",n));if(typeof r!="object"||r===null||Array.isArray(r))return E(n,r),r;const i=t??"",o=r,d=S(i,e,o),s=y(d.context_intent,"estimated_tokens"),u=Nt(o,d),c=O(i,e,n,d,u),l=D(e,c,d.context_intent);if(l===void 0)return St(e,c,d)?Mt(i,e,n,o,d,Number(s),u,c):c;const _={...e};M.set(_,l.estimated-Number(s));const a=S(i,_,o),f=Z(i,e,_,n,a,u),b=f===void 0?l:D(e,f,a.context_intent);if(b===void 0)return f;const g={...b.receipt,estimated_tokens:b.estimated};return O(i,{...e,outputCursor:void 0,output_cursor:void 0},n,J(w(e),g,f??c,()=>Y(i,g.command,g.intent,g,o,e)))}function St(t,e,n){const r=n.context_intent;return Object.hasOwn(e,"output_budget_exceeded")&&m(r)&&r.result_omitted!==!0&&$t.has(String(r.command))&&(t.outputInclude??t.output_include)===void 0&&(t.outputSession??t.output_session)===void 0}const $t=new Set(["list","search"]);function Mt(t,e,n,r,i,o,d,s){const u=O(t,{...e,outputBudget:"unbounded"},n,{...i,context_intent:{...i.context_intent}},d),c={...e};M.set(c,I(u,T(e))-o);const l=S(t,c,r),_=Z(t,e,c,n,l,d);return _===void 0||Object.hasOwn(_,"output_budget_exceeded")||D(e,_,l.context_intent)!==void 0?s:_}function Z(t,e,n,r,i,o){return q(i)||Lt(e,i)?void 0:O(t,n,r,i,o)}function Lt(t,e){const n=t.outputCursor??t.output_cursor;if(typeof n!="string")return!1;const r=it(n),i=e[r.path];return Array.isArray(i)&&i.length<=r.offset}function D(t,e,n){const r=m(e.context_intent),i=r?e.context_intent:n;if(!m(i)||i.result_omitted===!0||Object.hasOwn(e,"output_budget_exceeded"))return;const o=i,d=r?o.estimated_tokens:I(e,T(t));return w(t)==="unbounded"||d<=o.token_budget?void 0:{receipt:o,estimated:d}}function Dt(t){return!m(t)||t.result_omitted===!0?{}:{mirrorEstimate:(e,n)=>{m(e.context_intent)&&(e.context_intent.estimated_tokens=n)}}}function O(t,e,n,r,i){const o={...e,outputRowContract:e.outputRowContract===!0||e.output_row_contract===!0};at(o,{...i===void 0?{}:{continuationBinding:V(e,i)},...Dt(r.context_intent)});const d=ot(t,o,V(e,r));if(E(n,d),e.outputRowContract===!0||e.output_row_contract===!0||!Object.hasOwn(d,"row_contract"))return m(d.context_intent)?H(d,e):d;const s=Object.fromEntries(Object.entries(d).filter(([c])=>c!=="row_contract"));Object.defineProperty(s,"row_contract",{value:d.row_contract,enumerable:!1,configurable:!0});const u=H(s,e);return delete u.row_contract,E(d,u),u}export{mt as CONTEXT_INTENT_LIMIT_OVERRIDE_WARNING,z as PM_CONTEXT_INTENT_CONTRACTS,Ht as applyContextIntentProjection,S as attachContextIntentReceipt,Zt as attachReadOutputContracts,kt as composeContextIntentContracts,xt as contextIntentRowId,K as decodeContextIntentCursor,bt as getActiveContextIntentContracts,G as resolveContextIntentContract,Yt as runWithContextIntentContracts};
1
+ import{AsyncLocalStorage as tt}from"node:async_hooks";import{attachExtensionReadOutputRows as et}from"./read-output/extension.js";import{quoteCommandArg as I,renderPmCommand as q}from"./command-line.js";import{attachOutputOmissionReceipt as nt}from"./output-projection.js";import{encodeQueryCursor as rt}from"./pagination.js";import{applyReadOutputDimensions as ot,decodeReadOutputContinuationCursor as it,isReadResultOmittedForBudget as z,resolveReadOutputSurface as dt,stabilizeReadOutputReceiptEstimates as ut}from"./read-output-contracts.js";import{estimateReadOutputTokens as T,MAX_ESTIMATE_ITERATIONS as st,readOutputMeasurementFormat as E,registerReadOutputPassHooks as at,resolveReadOutputRecoveryBudget as ct}from"./read-output-budget.js";import{propagateContextUsageServingReceipt as R}from"./context-usage.js";import{readOutputContinuationRowCollections as ft}from"./read-output-rows.js";import{EXIT_CODE as B}from"../core/shared/constants.js";import{PmCliError as A}from"../core/shared/errors.js";import{compactExplanatoryString as lt,isContinuationTokenKey as _t,isTrackerItemDocumentKey as gt}from"../core/shared/text-normalization.js";const mt="limit_overridden_by_intent",U=Object.freeze([{command:"context",intent:"orient",description:"Bounded active hierarchy, ownership, blockers, and recent progress.",included_field_groups:["summary","focus","hierarchy","blockers","activity"],token_budget:3e3,source:"core"},{command:"context",intent:"handoff",description:"Active ownership, evidence, decisions, and immediate continuation context.",included_field_groups:["summary","focus","in_progress","decisions","activity"],token_budget:2200,source:"core"},{command:"get",intent:"inspect",description:"Standard-depth item metadata, relationships, evidence, and lifecycle state.",included_field_groups:["item","children","claim_state","linked"],token_budget:3200,source:"core"},{command:"list",intent:"triage",description:"A budget-derived page of compact governance, ownership, priority, and blocker rows for triage.",included_field_groups:["identity","governance","ownership","dependencies"],token_budget:3200,source:"core"},{command:"next",intent:"execute",description:"The highest-ranked actionable work with concise ranking evidence.",included_field_groups:["recommended"],token_budget:1200,source:"core"},{command:"search",intent:"discover",description:"A budget-derived page of ranked canonical lineage candidates with compact match evidence.",included_field_groups:["identity","status","lineage","match"],token_budget:1800,source:"core"}]),G=new tt;function bt(){return G.getStore()??U}function Ht(t,e){return G.run(kt(t.workspaceContracts,t.packageContracts),e)}function ht(t,e){const n=t.command.trim().toLowerCase(),r=t.intent.trim().toLowerCase(),i=`${n}:${r}`;if(!/^[a-z0-9][a-z0-9-]*$/.test(n)||!/^[a-z0-9][a-z0-9-]*$/.test(r))throw new TypeError(`Invalid context intent command or name: ${i}`);if(t.description.trim().length===0)throw new TypeError(`Context intent ${i} requires a non-empty description`);if(!Number.isSafeInteger(t.token_budget)||t.token_budget<=0)throw new TypeError(`Context intent ${i} requires a positive integer token_budget`);const o=[...new Set(t.included_field_groups.map(d=>d.trim()).filter(Boolean))];if(o.length===0)throw new TypeError(`Context intent ${i} requires included_field_groups`);return{command:n,intent:r,description:t.description.trim(),included_field_groups:o,token_budget:t.token_budget,source:e}}function kt(t=[],e=[]){const n=[{source:"core",contracts:U,allowOverride:!1},{source:"package",contracts:e,allowOverride:!1},{source:"workspace",contracts:t,allowOverride:!0}],r=new Map,i=new Set;for(const o of n){i.clear();for(const d of o.contracts){const s=ht(d,o.source),u=`${s.command}:${s.intent}`;if(i.has(u))throw new TypeError(`Duplicate context intent declaration: ${u}`);if(i.add(u),!o.allowOverride&&r.has(u))throw new TypeError(`Duplicate context intent declaration: ${u}`);r.set(u,s)}}return[...r.values()].sort((o,d)=>o.command.localeCompare(d.command)||o.intent.localeCompare(d.intent))}function X(t,e,n=bt(),r=[]){const i=t.trim().toLowerCase(),o=e.trim().toLowerCase(),d=n.find(a=>a.command===i&&a.intent===o);if(d)return{...d,source:d.source??"core"};const s=n.filter(a=>a.command===i).map(a=>a.intent);if(s.length===0)return;const u=s.map(a=>{const f=Array.from({length:o.length+1},(b,g)=>g);for(let b=1;b<=a.length;b+=1){let g=f[0];f[0]=b;for(let h=1;h<=o.length;h+=1){const j=f[h];f[h]=Math.min(f[h]+1,f[h-1]+1,g+(a[b-1]===o[h-1]?0:1)),g=j}}return{candidate:a,distance:f[o.length]}}).sort((a,f)=>a.distance-f.distance||a.candidate.localeCompare(f.candidate))[0].candidate,c=[i,...r,"--for",o],l=[i,...r,"--for",u],_=q(l);throw new A(`Unknown context intent "${o}" for ${i}. Did you mean "${u}"?`,B.USAGE,{code:"unknown_context_intent",reason:"unknown_intent",field:"for",flag:"--for",value:o,required:`Use a declared ${i} intent.`,why:"Intent names are command-local contracts and cannot be inferred from output section names.",nextSteps:[_],recovery:{recovery_mode:"compact",attempted_command:q(c),allowed_values:[...s].sort(),suggested_retry:_,suggested_retry_args:l}})}function N(t,e){const n=k(t.limit),r=String(n===void 0?e:Math.min(n,e));return(t.limit===void 0||n!==void 0)&&(t.limit=r),r}const W={context:(t,e,n,r)=>{t.section===void 0&&t.depth===void 0&&(t.section=e.intent==="handoff"?["activity","progress","blockers"]:["hierarchy","blockers","activity"]),t.depth===void 0&&(t.depth=e.intent==="handoff"?"deep":"standard");const i=C(r,t.tokenBudget,e.token_budget),o=v("context",e.intent,i,n),d=N(t,o);t.activityLimit===void 0&&(t.activityLimit=d)},get:t=>{t.depth===void 0&&t.fields===void 0&&(t.depth="standard")},list:(t,e,n,r)=>{t.brief===void 0&&t.compact===void 0&&t.full===void 0&&t.fields===void 0&&(t.fields="id,title,status,type,priority,parent,assignee,risk,blocked_by");const i=C(r,t.tokenBudget,e.token_budget),o=v("list",e.intent,i,n);N(t,o)},next:t=>{t.readyOnly===void 0&&(t.readyOnly=!0)},search:(t,e,n,r)=>{t.compact===void 0&&t.full===void 0&&t.fields===void 0&&(t.compact=!0);const i=C(r,t.tokenBudget,e.token_budget),o=v("search",e.intent,i,n);N(t,o)}};function Qt(t,e,n=[]){const r=e.tokenBudget??e.token_budget;if(typeof e.for!="string"){if(r!==void 0&&(t==="get"||t==="list"||t==="search"))throw new A("--token-budget requires a declared context intent selected with --for",B.USAGE,{code:"missing_required_option",field:"for",required:"Select a context intent with --for when setting --token-budget.",why:"A token-budget override has no projection contract to constrain without a selected intent.",nextSteps:["Retry with --for <intent> --token-budget <n>, or omit --token-budget."]});if(e.tokenBudget!==void 0||e.token_budget===void 0)return e;const u={...e,tokenBudget:r};return delete u.token_budget,u}const i=X(t,e.for,void 0,n),o=w(e),d=k(r)!==void 0||typeof o=="number",s={...e};return s.tokenBudget===void 0&&r!==void 0&&(s.tokenBudget=r),delete s.token_budget,typeof o=="number"?s.tokenBudget=String(o):s.tokenBudget===void 0&&(s.tokenBudget=String(i.token_budget)),W[t](s,i,d,o),s}const pt={context:"bounded_sections",get:"standard_item",list:"bounded_fields_and_rows",next:"bounded_ranked_rows",search:"bounded_ranked_rows"},x=256;function S(t,e,n=!0,r=!0){return Array.isArray(t)?t.map(i=>S(i,e,n,!1)):t!==null&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([i,o])=>[i,n&&typeof o=="string"&&_t(i)?o:S(o,e,n&&!(r&&gt(e,i)),!1)])):typeof t=="string"?lt(t):t}function k(t){const e=typeof t=="number"?t:typeof t=="string"&&/^\d+$/u.test(t.trim())?Number(t):Number.NaN;return Number.isSafeInteger(e)&&e>0?e:void 0}function w(t){const e=t.outputBudget??t.output_budget;return e==="unbounded"?e:k(e)}function yt(t){return w(t)===void 0?"--token-budget":"--output-budget"}function C(t,e,n){return typeof t=="number"?t:wt(e,n)}function wt(t,e){const n=k(t);if(n===void 0)return e;if(n<x)throw new A(`Context intent token budget must be at least ${x}`,B.USAGE,{code:"invalid_argument_value",reason:"below_minimum",field:"tokenBudget",value:String(t),required:`Use an integer token budget of at least ${x}.`,why:"Smaller ceilings cannot contain the minimum machine-readable intent receipt.",nextSteps:[`Retry with --token-budget ${x} or omit the override.`]});return n}function F(t,e){const n=t==="context"&&e==="orient";return t==="context"?n?{overhead:1200,rowCost:600}:{overhead:800,rowCost:500}:{overhead:t==="list"?520:480,rowCost:16}}function v(t,e,n,r){if(t==="get"||t==="next")return;const{overhead:i,rowCost:o}=F(t,e),d=Math.max(t==="context"?1:2,Math.floor((n-i)/o));return r?d:Math.min(t==="context"?20:100,d)}function p(t,e,n){const r=E(n),i=n.outputRowContract===!0||n.output_row_contract===!0;let o=e.estimated_tokens,d=o;for(let s=0;s<st;s+=1){e.estimated_tokens=o;const u=T(i||!Object.hasOwn(t,"row_contract")?t:Object.fromEntries(Object.entries(t).filter(([c])=>c!=="row_contract")),r);if(u===o)return;o=u,d=Math.max(d,o)}e.estimated_tokens=d}const K={context:["high_level","low_level","blocked_fallback","recently_created","unparented","hierarchy","activity","blockers"],get:["children"],list:["items"],next:["ready","decision_needed","gate_needed","containers","blocked","held_by_others"],search:["items"]};function J(t){try{const e=JSON.parse(Buffer.from(t,"base64url").toString("utf8"));return typeof e.fingerprint!="string"||!Number.isSafeInteger(e.after_index)?void 0:{fingerprint:e.fingerprint,after_index:e.after_index,...typeof e.snapshot=="string"?{snapshot:e.snapshot}:{}}}catch{return}}function xt(t){if(t===null||typeof t!="object")return;if(typeof t.id=="string")return t.id;const e=t.item?.id;return typeof e=="string"?e:void 0}function Ct(t,e,n,r){let i=!1;for(;;){if(p(t,e,r),e.estimated_tokens<=e.token_budget||n.length<=1)return i;const o=Buffer.byteLength(JSON.stringify(n),"utf8"),d=(e.estimated_tokens-e.token_budget)*4;n.splice(-Math.min(n.length-1,Math.max(1,Math.ceil(d/Math.max(1,Math.ceil(o/n.length)))))),i=!0}}function vt(t,e,n){const r=t.items,i=typeof t.next_cursor=="string",o=i?t.next_cursor:n.after;if(!Array.isArray(r)||typeof o!="string")return!1;const d=J(o);if(d===void 0)return!1;const s=r.length,u=[...r];let c=!1;for(;;){if(c=Ct(t,e,r,n)||c,!c)return!1;const l=xt(r.at(-1));if(l===void 0)return r.splice(0,r.length,...u),p(t,e,n),!1;if(t.next_cursor=rt(d.fingerprint,l,i?d.after_index-(s-r.length):d.after_index+r.length,d.snapshot),p(t,e,n),e.estimated_tokens<=e.token_budget||r.length<=1)break}return typeof t.count=="number"&&(t.count=r.length),typeof t.applied_limit=="number"&&(t.applied_limit=r.length),!0}function Ot(t,e,n,r){if(t==="list"||t==="search")return vt(e,n,r);if(t!=="next"||typeof e.next_cursor=="string")return!1;let i=!1;for(;;){if(p(e,n,r),n.estimated_tokens<=n.token_budget)return i;const o=K[t].map(a=>({key:a,rows:Array.isArray(e[a])?e[a]:[]})).filter(({rows:a})=>a.length>0).sort((a,f)=>f.rows.length-a.rows.length||a.key.localeCompare(f.key))[0];if(o===void 0)return i;const d=K[t].reduce((a,f)=>a+(Array.isArray(e[f])?e[f].length:0),0);if(d<=1)return i;const s=Math.min(o.rows.length,d-1),u=Buffer.byteLength(JSON.stringify(o.rows),"utf8"),c=Math.max(1,Math.ceil(u/o.rows.length)),l=(n.estimated_tokens-n.token_budget)*4,_=Math.min(s,Math.max(1,Math.ceil(l/c)));o.rows.splice(-_,_),i=!0}}function $(t,e,n){if(typeof e.for!="string")return n;const r=t.startsWith("list-")?"list":t;if(!(r in W))return n;const i=r,o=X(i,e.for),d=w(e),s=C(d,e.tokenBudget??e.token_budget,o.token_budget),u={command:i,intent:o.intent,source:o.source,included_field_groups:[...o.included_field_groups],token_budget:s,declared_token_budget:o.token_budget,token_budget_override:s-o.token_budget,estimated_tokens:0,within_budget:!0,degradation:pt[i],declaration_feasible:!0,result_omitted:!1},c={...n},l=v(i,o.intent,u.token_budget,k(e.tokenBudget??e.token_budget)!==void 0||typeof d=="number");if(l!==void 0){const g=k(e.limit),h=g!==void 0&&g<l;u.budget_derived_limit=l,u.binding_constraint=h?"explicit_limit":"token_budget",u.limit_reason=h?"The caller supplied a smaller row limit than the budget-derived ceiling.":"The selected intent token budget constrains the effective row ceiling.",c.budget_derived_limit=l,Bt({builtInCommand:i,intent:o.intent},u,c,e)}const _=L.get(e)??0,a=u.token_budget;u.token_budget=a-_;const f=d==="unbounded"?M(c,u,e):It(i,c,u,e,dt(t,e));u.declaration_feasible=u.estimated_tokens<=u.declared_token_budget;const b=V(d,u,f,()=>H(t,i,o.intent,{...u,token_budget:a,estimated_tokens:u.estimated_tokens+_},c,e));return u.result_omitted&&(u.estimated_tokens+=_,u.declaration_feasible=u.estimated_tokens<=u.declared_token_budget),u.token_budget=a,b}function M(t,e,n){const r={...t,context_intent:e};return p(r,e,n),r}function It(t,e,n,r,i){let o=M(e,n,r);return n.estimated_tokens>n.token_budget&&(n.degradation="recursive_budget_compaction",o=M(S(e,i),n,r)),n.estimated_tokens>n.token_budget&&Ot(t,o,n,r)&&(n.degradation="budget_row_compaction",p(o,n,r)),o}const L=new WeakMap;function V(t,e,n,r){return e.estimated_tokens<=e.token_budget||(e.within_budget=!1,t==="unbounded")?n:(e.degradation="budget_receipt_only",e.result_omitted=!0,typeof t=="number"?{output_budget_exceeded:{omitted_result:!0,reason:"requested_budget_infeasible",restore_with:"Unbounded",recovery:{outputBudget:"unbounded"}},context_intent:e}:{budget_exceeded:{omitted_result:!0,reason:e.token_budget_override===0?"declared_budget_infeasible":"effective_budget_infeasible",restore_with:r()},context_intent:e})}const Tt=["applied_limit","completeness","context_intent","count","filters","has_more","now","omission_receipt","projection","row_contract","sorting","total","truncated"];function Y(t,e){if(typeof t.after!="string"||t.after.length===0||z(e))return e;const n=J(t.after)?.fingerprint??"opaque_cursor",r={...e};for(const i of Tt)delete r[i];return r.continuation_contract={fingerprint:n,metadata:"reference",restore_with:"omit --after"},r}function m(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Et(t,e){const n=t==="get"&&m(e.item)&&typeof e.item.id=="string"?e.item.id:t==="search"&&typeof e.query=="string"?e.query:void 0;return n===void 0?"":` ${I(n)}`}function Rt(t){return typeof t.fields=="string"&&t.fields.trim()!==""?` --fields ${I(t.fields)}`:""}function Bt(t,e,n,r){const i=k(r.limit),o=e.budget_derived_limit;if(i===void 0||i<=o)return;const{overhead:d,rowCost:s}=F(t.builtInCommand,t.intent),u=Math.max(e.token_budget,d+s*i);e.limit_reason=`The ${e.token_budget}-token ${t.intent} budget carries ${o} rows, so it reduced the caller's --limit ${i}.`,e.limit_override={flag:"--limit",requested:i,effective:o,...Number.isSafeInteger(u)?{token_budget_for_requested:u,restore_with:`${yt(r)} ${u}`}:{}};const c=`${mt}:--limit ${i}->${o}`;n.warnings=Array.isArray(n.warnings)?[...n.warnings,c]:[c],m(n.filters)&&(n.filters={...n.filters,requested_limit:String(i)})}function H(t,e,n,r,i,o){const d=Et(e,i),s=e==="get"?"":` --limit ${r.budget_derived_limit??1}`,{output_budget:u}=ct({effective_budget_tokens:r.token_budget,measured_result_tokens:r.estimated_tokens});return`pm ${t}${d}${Rt(o)} --for ${I(n)} --token-budget ${u}${s}`}function y(t,e){if(m(t))return typeof t[e]=="number"?t[e]:void 0}function Q(t,e){let n=t;for(let r=0;r<8;r+=1){At(n);const i=y(n.context_intent,"estimated_tokens"),o=y(n.read_output,"estimated_tokens"),d=y(n.read_session,"spent_this_call_tokens");if(m(n.context_intent)&&n.context_intent.result_omitted!==!0&&p(n,n.context_intent,e),n=ut(n,e),y(n.context_intent,"estimated_tokens")===i&&y(n.read_output,"estimated_tokens")===o&&y(n.read_session,"spent_this_call_tokens")===d)break}return n}function At(t){const e=t.context_intent;m(e)&&Number(e.estimated_tokens)>Number(e.token_budget)&&(e.within_budget=!1)}function Nt(t,e){const n=e.context_intent;if(!m(n)||n.result_omitted===!0)return;const r=n.degradation==="recursive_budget_compaction"||n.degradation==="budget_row_compaction",i={...e};for(const o of ft(t)){const d=e[o.path];if(Array.isArray(d)&&Array.isArray(o.value)&&d.length<=o.value.length){const s=o.value.slice(0,d.length);i[o.path]=r?s.map(D):s}}return i}function D(t){return Array.isArray(t)?t.map(D):t!==null&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,D(n)])):t}function Zt(t,e,n){const r=nt(t,et(t??"",n));if(typeof r!="object"||r===null||Array.isArray(r))return R(n,r),r;const i=t??"",o=r,d=$(i,e,o),s=y(d.context_intent,"estimated_tokens"),u=Nt(o,d),c=O(i,e,n,d,u),l=P(e,c,d.context_intent);if(l===void 0)return St(e,c,d)?Mt(i,e,n,o,d,Number(s),u,c):c;const _={...e};L.set(_,l.estimated-Number(s));const a=$(i,_,o),f=Z(i,e,_,n,a,u),b=f===void 0?l:P(e,f,a.context_intent);if(b===void 0)return f;const g={...b.receipt,estimated_tokens:b.estimated};return O(i,{...e,outputCursor:void 0,output_cursor:void 0},n,V(w(e),g,f??c,()=>H(i,g.command,g.intent,g,o,e)))}function St(t,e,n){const r=n.context_intent;return Object.hasOwn(e,"output_budget_exceeded")&&m(r)&&r.result_omitted!==!0&&$t.has(String(r.command))&&(t.outputInclude??t.output_include)===void 0&&(t.outputSession??t.output_session)===void 0}const $t=new Set(["list","search"]);function Mt(t,e,n,r,i,o,d,s){const u=O(t,{...e,outputBudget:"unbounded"},n,{...i,context_intent:{...i.context_intent}},d),c={...e};L.set(c,T(u,E(e))-o);const l=$(t,c,r),_=Z(t,e,c,n,l,d);return _===void 0||Object.hasOwn(_,"output_budget_exceeded")||P(e,_,l.context_intent)!==void 0?s:_}function Z(t,e,n,r,i,o){return z(i)||Lt(e,i)?void 0:O(t,n,r,i,o)}function Lt(t,e){const n=t.outputCursor??t.output_cursor;if(typeof n!="string")return!1;const r=it(n),i=e[r.path];return Array.isArray(i)&&i.length<=r.offset}function P(t,e,n){const r=m(e.context_intent),i=r?e.context_intent:n;if(!m(i)||i.result_omitted===!0||Object.hasOwn(e,"output_budget_exceeded"))return;const o=i,d=r?o.estimated_tokens:T(e,E(t));return w(t)==="unbounded"||d<=o.token_budget?void 0:{receipt:o,estimated:d}}function Dt(t){return!m(t)||t.result_omitted===!0?{}:{mirrorEstimate:(e,n)=>{m(e.context_intent)&&(e.context_intent.estimated_tokens=n)}}}function O(t,e,n,r,i){const o={...e,outputRowContract:e.outputRowContract===!0||e.output_row_contract===!0};at(o,{...i===void 0?{}:{continuationBinding:Y(e,i)},...Dt(r.context_intent)});const d=ot(t,o,Y(e,r));if(R(n,d),e.outputRowContract===!0||e.output_row_contract===!0||!Object.hasOwn(d,"row_contract"))return m(d.context_intent)?Q(d,e):d;const s=Object.fromEntries(Object.entries(d).filter(([c])=>c!=="row_contract"));Object.defineProperty(s,"row_contract",{value:d.row_contract,enumerable:!1,configurable:!0});const u=Q(s,e);return delete u.row_contract,R(d,u),u}export{mt as CONTEXT_INTENT_LIMIT_OVERRIDE_WARNING,U as PM_CONTEXT_INTENT_CONTRACTS,Qt as applyContextIntentProjection,$ as attachContextIntentReceipt,Zt as attachReadOutputContracts,kt as composeContextIntentContracts,xt as contextIntentRowId,J as decodeContextIntentCursor,bt as getActiveContextIntentContracts,X as resolveContextIntentContract,Ht as runWithContextIntentContracts};
2
2
  //# sourceMappingURL=context-intent-contracts.js.map
@@ -23,6 +23,9 @@ repeatable?:boolean;
23
23
  default?:unknown;
24
24
  /** `strict` refuses malformed number/boolean tokens before dispatch; `coerce` (default) forwards them. */
25
25
  value_validation?:string;}
26
+ type LooseOptionCoercionKind="string"|"number"|"boolean";
27
+ /** The value kind a declared flag coerces to (`bool` and other supported spellings included), or null when untyped. */
28
+ export declare function resolveLooseOptionCoercionKind(definition:LooseCommandFlagDefinition):LooseOptionCoercionKind|null;
26
29
  /** Collect every option key the declared flags answer to: each long flag's camel-case key and each short letter. */
27
30
  export declare function collectLooseCommandOptionKeysForDefinitions(definitions:ReadonlyArray<LooseCommandFlagDefinition>):Set<string>;
28
31
  /**
@@ -127,4 +130,26 @@ stop?:{atSubcommand:(token:string)=> boolean;atFirstUnrecognized:boolean;};}
127
130
  * Values compare after the declared coercion, so `--count 1 -c 1` is
128
131
  * accepted; repeats of one spelling and list flags are not checked.
129
132
  */
130
- export declare function refuseConflictingArgvOptionSpellings(scopes:readonly ArgvOptionScope[],definitions:ReadonlyArray<LooseCommandFlagDefinition>,commandPath:string):void;
133
+ export declare function refuseConflictingArgvOptionSpellings(scopes:readonly ArgvOptionScope[],definitions:ReadonlyArray<LooseCommandFlagDefinition>,commandPath:string):void;
134
+ /**
135
+ * Reorder the recorded occurrences of every declared repeatable boolean switch
136
+ * into argv order (pm-g2zzus). Commander registers such a switch without a
137
+ * value, so it accumulates each bare `--many` while `--many=false` and
138
+ * `--no-many` reach only the loose parser; the coercer used to keep the loose
139
+ * occurrences alone whenever any existed, dropping the bare ones. The scan
140
+ * that resolves spelling conflicts walks each scope's tokens with Commander's
141
+ * grammar and reports, in argv order, which occurrences Commander consumed and
142
+ * where a loose occurrence sits; a token another option consumed is never
143
+ * counted. Values stay with their reader: Commander's bare occurrences come
144
+ * from the scan, and every loose occurrence keeps the loose parser's own
145
+ * value, which reads the leftover tokens after Commander removed its own (so
146
+ * `--Many --source x false` keeps `false`) and folds spellings Commander did
147
+ * not register (`--Many=false` is `many`). Only the keys the coercer reads for
148
+ * a switch move, so another declaration's key (`--s` beside a switch aliased
149
+ * `-S`) keeps its occurrences. When the scan and the loose parser disagree on
150
+ * how many loose occurrences there are, every value is kept, loose ones first.
151
+ * A switch with no loose occurrence keeps Commander's accumulated value, which
152
+ * a preflight override may have rewritten. Returns `occurrenceSource`
153
+ * unchanged when Commander consumed no repeatable switch occurrence.
154
+ */
155
+ export declare function orderArgvRepeatableSwitchOccurrences(occurrenceSource:Record<string,unknown>,scopes:readonly ArgvOptionScope[],definitions:ReadonlyArray<LooseCommandFlagDefinition>):Record<string,unknown>;export{};
@@ -1,2 +1,2 @@
1
- import{isDeepStrictEqual as V}from"node:util";import{resolvePmCommandOperation as F}from"../cli-contracts/command-aliases.js";import{describeFlagScalarValueFailure as $,resolveExtensionFlagValueContract as x,resolveExtensionLongFlagName as b,EXIT_CODE as p,PmCliError as g,flattenFlagListValue as D,resolveFlagValueKind as ee}from"../runtime-primitives.js";import{RESERVED_EXTENSION_HOST_FLAG_NAMES as ne}from"../../core/extensions/reserved-host-flags.js";const te=new Set(["__proto__","prototype","constructor"]),A=Symbol("looseOptionOccurrences");function d(e){return e.trim().toLowerCase().replaceAll(/-([a-z0-9])/g,(t,o)=>o.toUpperCase())}function re(e,n,t){const o=e[n];if(o===void 0){e[n]=t;return}if(Array.isArray(o)){o.push(t),e[n]=o;return}e[n]=[o,t]}function _(e,n){const t=e[n];if(!t.startsWith("-")||t==="-"||t==="--")return null;if(!t.startsWith("--")){const i=t.indexOf("=");if(i>=0)return{consumed:1,key:t.slice(1,i).trim(),value:t.slice(i+1),attached:!0};const a=t.slice(1).trim(),u=e[n+1];return typeof u=="string"&&!u.startsWith("-")?{consumed:2,key:a,value:u}:{consumed:1,key:a,value:!0}}const o=t.indexOf("=");if(o>=0)return{consumed:1,key:t.slice(2,o).trim(),value:t.slice(o+1),attached:!0};if(t.startsWith("--no-"))return{consumed:1,key:t.slice(5).trim(),value:!1};const r=t.slice(2).trim(),s=e[n+1];return typeof s=="string"&&!s.startsWith("-")?{consumed:2,key:r,value:s}:{consumed:1,key:r,value:!0}}function S(e){return te.has(e)}function w(e){const n=(typeof e.value_type=="string"?e.value_type:void 0)??(typeof e.type=="string"?e.type:void 0);return ee(n)}function O(e){const n=[],t=b(e.long)??"",o=typeof e.short=="string"?e.short.trim():"";if(t.startsWith("--")){const r=d(t.slice(2));r.length>0&&!S(r)&&n.push(r)}if(o.startsWith("-")&&!o.startsWith("--")){const r=d(o.slice(1));r.length>0&&!S(r)&&n.push(r)}return[...new Set(n)]}function We(e){const n=new Set;for(const t of e)for(const o of O(t))n.add(o);return n}function m(e){const n=b(e.long)??"";if(n.startsWith("--")){const t=d(n.slice(2));if(t.length>0&&!S(t))return t}return O(e)[0]??null}function y(e){const n=b(e.long)??"";if(n.startsWith("--")&&n.length>2)return n;const t=typeof e.short=="string"?e.short.trim():"";return t.startsWith("-")&&!t.startsWith("--")&&t.length>1?t:null}function W(e,n){return[...(n.definitions??e).map(o=>y(o)).filter(o=>o!==null),...n.inheritedFlags??[]]}function Te(e,n,t,o={}){if(n.length===0)return;const r=new Set,s=new Map,i=[],a=W(n,o);for(const u of n){const l=O(u),c=y(u);for(const f of l)r.add(f),u.enabled===!1&&s.set(f,c);u.required===!0&&u.enabled!==!1&&l.length>0&&i.push({keys:l,label:c,definition:u})}for(const u of Object.keys(e)){r.has(u)||T(`--${u}`,`--${u}`,t,a);const l=s.get(u);l&&q(l,t)}for(const u of i){const l=c=>Object.hasOwn(e,c)&&(u.definition.list!==!0||z(u.definition,e[c]));u.keys.some(l)||R(u.definition,u.keys[0],u.label,t)}}function T(e,n,t,o){const r=o.length>0?` Expected one of: ${[...new Set(o)].join(", ")}.`:"";throw new g(`Unknown option '${e}' for extension command '${t}'.${r}`,p.USAGE,{code:"unknown_option",flag:n,required:`Use a flag the command accepts; run pm contracts --command ${t} --flags-only --json to list them.`})}function q(e,n){throw new g(`Option '${e}' is disabled for extension command '${n}'.`,p.USAGE,{code:"extension_option_disabled",flag:e,required:`Remove ${e}; the command declares it with enabled: false.`,why:"A disabled declaration keeps the flag in the contract while refusing every value for it.",examples:[`pm ${n} --help`],nextSteps:[`Run pm contracts --command ${n} --flags-only --json to list the flags this command accepts.`]})}function R(e,n,t,o){const r=x(e),s=r.value_arity==="none"?t:r.value_arity==="optional"?`${t} [${r.value_name}]`:`${t} <${r.value_name}>`;throw new g(`Missing required option '${t}' for extension command '${o}'.`,p.USAGE,{code:"missing_required_option",flag:t,field:n,required:`Pass ${s}.`,why:"The command declares this flag as required, so pm refuses the invocation before the extension handler runs.",examples:[`pm ${o} ${s}`],nextSteps:[`Run pm contracts --command ${o} --flags-only --json to read each flag's sdk_option key.`],recovery:{missing:[t]}})}function oe(e){return typeof e=="string"||e==null?e:String(e)}function se(e){if(typeof e=="number")return e;if(typeof e=="string"&&e.trim().length>0){const n=Number(e);return Number.isFinite(n)?n:e}return e}function M(e){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.trim().toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="0")return!1}return e}const ie={string:oe,number:se,boolean:M};function h(e,n){return Array.isArray(e)?e.map(t=>h(t,n)):ie[n](e)}function E(e,n,t){const o=t?(Array.isArray(e)?e.flat(1/0):[e]).filter(r=>r!=null&&r!==""):D(e);return n?o.map(r=>h(r,n)):o}function z(e,n){return E(n,null,e.repeatable===!0).length>0}function ae(e,n,t,o){return t?E(e,n,o):n?h(e,n):e}function ue(e,n,t){const o=U(e,n);return o.length===0?t:o.map(r=>r.value)}function k(e){return x(e).value_arity==="none"}function L(e,n,t,o,r){const s=y(e),i=r?` for extension command '${r}'`:"",a=t===!0?"no value":JSON.stringify(t);throw new g(`Option '${s}'${i} expects ${o}; received ${a}.`,p.USAGE,{code:"extension_flag_value_invalid",flag:s,required:`Pass ${s} ${n==="number"?"<number>":"<true|false|1|0>"}.`,why:`The flag declares value_type ${n} with value_validation strict, so a malformed token is refused before the extension handler runs.`,nextSteps:[`Re-run with a valid ${n} value for ${s}.`,`Run pm ${r??"<command>"} --help to review the declared flag contract.`]})}function C(e,n){return e.value_validation==="strict"&&n!=="string"}function U(e,n){const t=e[A];if(!t)return[];const o=new Set(n);return t.filter(r=>o.has(r.key))}function le(e,n,t,o){if(k(e))for(const r of U(t,n)){if(r.attached!==!0)continue;const s=e.list===!0&&e.repeatable!==!0?D(r.value):[r.value];for(const i of s){const a=$(h(i,"boolean"),"boolean");a!==null&&L(e,"boolean",i,a.expected,o)}}}function ce(e,n,t,o,r){const s=Array.isArray(t)?t.flat(1/0):[t],i=o?s:s.flatMap(a=>typeof a=="string"?a.split(","):[a]);for(const a of i)if(typeof a=="string"&&a.trim().length===0){const u=$(a,n);L(e,n,a,u.expected,r)}}function K(e,n,t,o){if(!C(e,t))return n;const r=t==="boolean"&&k(e),s=i=>{const a=$(i,t);return a===null?i:r&&typeof i=="string"?!0:L(e,t,i,a.expected,o)};return Array.isArray(n)?n.map(s):s(n)}function fe(e,n,t,o){for(const r of t)if(!(r===n||!Object.hasOwn(e,r))){if(Object.hasOwn(e,n)){if(o){const s=e[n],i=e[r];e[n]=[...Array.isArray(s)?s:[s],...Array.isArray(i)?i:[i]].filter(a=>a!=null)}delete e[r];continue}e[n]=e[r],delete e[r]}}function B(e,n,t=e,o){if(n.length===0)return e;const r=Object.create(null);for(const[i,a]of Object.entries(e))r[i]=a;const s=new Set(n.map(i=>m(i)).filter(i=>i!==null));for(const i of n){const a=m(i);if(a){const u=O(i).filter(l=>l===a||!s.has(l));de(r,i,a,u,t,o)}}return r}function de(e,n,t,o,r,s){const i=n.list===!0,a=w(n);a&&!i&&pe(e,n,t,o,a,s),fe(e,t,o,i);const u=n.repeatable===!0;if(!Object.hasOwn(e,t)){n.default!==void 0&&(e[t]=ae(n.default,a,i,u));return}if(a==="boolean"&&C(n,a)&&le(n,o,r,s),i){e[t]=ge(n,o,r,e[t],a,u,s);return}a&&(e[t]=K(n,h(e[t],a),a,s))}function pe(e,n,t,o,r,s){for(const i of o)i!==t&&Object.hasOwn(e,i)&&K(n,h(e[i],r),r,s)}function ge(e,n,t,o,r,s,i){const a=ue(t,n,o);r&&C(e,r)&&ce(e,r,a,s,i);const u=E(a,r,s);return r?K(e,u,r,i):u}function qe(e){const n=Object.create(null),t=[];Object.defineProperty(n,A,{value:t});let o=0;for(;o<e.length;){const r=_(e,o);if(!r){o+=1;continue}const s=d(r.key);if(s.length===0||S(s)){o+=r.consumed;continue}re(n,s,r.value),t.push({...r,key:s}),o+=r.consumed}return n}function Re(e){const n=[];let t=0;for(;t<e.length;){if(e[t]==="--"){n.push(...e.slice(t+1));break}const o=_(e,t);if(o){t+=Math.max(1,o.consumed);continue}n.push(e[t]),t+=1}return n}function Me(e,n){if(n.length===0)return[...e];const t=new Set,o=new Set;for(const i of n){const a=w(i);for(const u of O(i))t.add(u),a==="boolean"&&o.add(u)}if(t.size===0)return[...e];const r=[];let s=0;for(;s<e.length;){if(e[s]==="--"){r.push(...e.slice(s+1));break}const i=_(e,s);if(i){const a=d(i.key);if(t.has(a)){const u=e[s],l=o.has(a)&&!u.includes("=")?1:i.consumed;s+=l;continue}}r.push(e[s]),s+=1}return r}function ze(e){return m(e)}function I(e){return e.trim().toLowerCase().split(/\s+/u).filter(n=>n.length>0).join(" ")}function ke(e,n){const t=I(n);if(t.length===0)return[];const o=F(t);return e.flags.filter(r=>F(I(r.target_command))===o).flatMap(r=>[...r.flags])}function G(e,n,t,o){const r=y(e),[s,i]=t;throw new g(`Options '${s}' and '${i}' both set ${r} for extension command '${o}' with different values.`,p.USAGE,{code:"extension_option_spelling_conflict",required:`Pass ${r} once, under the handler key '${n}'.`,why:`'${s}' and '${i}' are spellings of the same declared flag, and pm refuses to choose between two different values.`,nextSteps:[`Remove '${s}' or '${i}' and pass one value as '${n}'.`,`Run pm contracts --command ${o} --flags-only --json to read each flag's sdk_option key.`]})}function Ue(e,n,t,o={}){if(n.length===0)return e;const r=n.map(c=>c.repeatable===!0&&c.list!==!0?{...c,list:!0}:c),s=Oe(r),i=we(e,s,t),a=new Set([...s.long.values()].map(({handlerKey:c})=>c)),u=Object.create(null),l=Object.create(null);for(const[c,f]of Object.entries(i))a.has(c)?u[c]=f:f===void 0||o.undeclaredKeys==="pass"||me(c)?l[c]=f:T(c,ye(c),t,W(r,{}));return J(u,r,t),Object.assign(l,B(u,r,H(u,s),t))}function H(e,n){const t=new Set([...n.long.values()].map(({handlerKey:s})=>s)),o=Object.entries(e).filter(([s])=>t.has(s)).flatMap(([s,i])=>(Array.isArray(i)?i.flat(1/0):[i]).map(a=>({consumed:1,key:s,value:a,attached:!0}))),r=Object.create(null);return Object.defineProperty(r,A,{value:o}),r}function J(e,n,t){for(const o of n){const r=m(o);if(r===null)continue;const s=y(o),i=e[r],a=Object.hasOwn(e,r);o.enabled===!1&&a&&q(s,t);const u=a&&(o.list!==!0||z(o,i));o.required===!0&&o.enabled!==!1&&!u&&R(o,r,s,t),o.list!==!0&&Array.isArray(i)&&he(s,t)}}function he(e,n){throw new g(`Option '${e}' for extension command '${n}' takes one value; received an array.`,p.USAGE,{code:"extension_flag_value_invalid",flag:e,required:`Pass one value for ${e}, or ask the package to declare it with list: true or repeatable: true.`,why:"The flag is not declared list or repeatable, so pm refuses an array before the extension handler runs instead of handing it a value of the wrong shape.",nextSteps:[`Run pm contracts --command ${n} --flags-only --json to read each flag's value contract.`]})}const X=new Set([...[...ne].flatMap(e=>{const n=e.replace(/^--/u,"");return[n,...n.startsWith("no-")?[n.slice(3)]:[]].flatMap(o=>[d(o),o.replaceAll("-","_")])}),"force","subcommand","inputResponses","requestState"]);function me(e){return X.has(e)||X.has(d(e.replace(/^-{1,2}/u,"")))}function ye(e){return`--${e.replace(/^-+/u,"").replace(/([a-z0-9])([A-Z])/gu,"$1-$2").replaceAll("_","-").toLowerCase()}`}function Oe(e){const n={long:new Map,short:new Map},t=(o,r,s)=>{r.length>0&&!o.has(r)&&o.set(r,s)};for(const o of e){const r=m(o);if(r===null)continue;const s={handlerKey:r,definition:o};t(n.long,r,s);const i=typeof o.short=="string"?o.short.trim():"";i.startsWith("-")&&!i.startsWith("--")&&t(n.short,i.slice(1),s)}return n}function j(e,n){return e.long.get(n)??e.short.get(n.replace(/^-(?!-)/u,""))??e.long.get(d(n.replace(/^-{1,2}/u,"")))}function be(e,n,t,o){const r=/^(?:--)?no-(.+)$/u.exec(n)?.[1];if(r===void 0||j(e,n)!==void 0)return{spelling:n,value:t};const s=j(e,r);return s===void 0||w(s.definition)!=="boolean"?{spelling:n,value:t}:(s.definition.list===!0||s.definition.repeatable===!0)&&Array.isArray(t)?{spelling:r,value:t.flat(1/0).map(i=>Y(n,s.definition,i,o))}:s.definition.list===!0&&t!==void 0?{spelling:r,value:Y(n,s.definition,t,o)}:{spelling:r,value:t===void 0?t:v(n,s.definition,t,o)}}function Y(e,n,t,o){const r=s=>s.trim().length===0?s:String(v(e,n,s.trim(),o));return t==null?t:typeof t!="string"?v(e,n,t,o):t.trim().length===0?t:n.repeatable===!0||!t.includes(",")?v(e,n,t,o):t.split(",").map(r).join(",")}function v(e,n,t,o){const r=M(t);return typeof r=="boolean"?!r:Se(e,n,t,o)}function Se(e,n,t,o){const r=y(n);throw new g(`Option '${e}' for extension command '${o}' negates ${r} and expects true, false, 1, or 0; received ${JSON.stringify(t)}.`,p.USAGE,{code:"extension_flag_value_invalid",flag:r,required:`Pass ${r} as true or false, or '${e}' as true.`,why:`'${e}' is the negated spelling of the boolean ${r}, so only a boolean value can be inverted before the extension handler runs.`,nextSteps:[`Run pm contracts --command ${o} --flags-only --json to read each flag's value contract.`]})}function we(e,n,t){const o=Object.create(null),r=new Map;for(const[s,i]of Object.entries(e)){const{spelling:a,value:u}=be(n,s,i,t),l=j(n,a);if(l===void 0)o[a]=u;else if(u!==void 0){const c=r.get(l.handlerKey);c===void 0?(r.set(l.handlerKey,a),o[l.handlerKey]=u):V(Z(l.definition,l.handlerKey,o[l.handlerKey],n,t),Z(l.definition,l.handlerKey,u,n,t))||G(l.definition,l.handlerKey,[c,a],t)}}return o}function Z(e,n,t,o,r){const s={[n]:t};return J(s,[e],r),B(s,[e],H(s,o),r)[n]}function ve(e){const n=new Map;for(const t of e){const o=m(t);if(o===null)continue;const r={definition:t,handlerKey:o,kind:w(t),arity:x(t).value_arity,scalar:t.list!==!0},s=[b(t.long),typeof t.short=="string"?t.short.trim():""];for(const i of s.filter(a=>a?.startsWith("-")===!0))n.has(i)||n.set(i,r)}return n}function $e(e,n,t){const o=e.optionOf(t),r=n.get(t),s=r?.scalar===!0?r:void 0;if(o!==void 0){const i={arity:o.arity,...o.variadic===!0?{variadic:!0}:{}};if(s?.handlerKey===o.key)return{...i,declared:s};const a=r===void 0&&t.startsWith("--no-")?n.get(`--${t.slice(5)}`):void 0;return a?.scalar===!0&&a.kind==="boolean"&&a.handlerKey===o.key?{...i,declared:a,negates:!0}:i}if(!(!e.includesLooseFlags||r===void 0))return s===void 0?{arity:r.arity,loose:!0}:{arity:r.arity,declared:s,loose:!0}}function N(e){return e.length>1&&e.startsWith("-")}const Q=/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/u;function xe(e,n,t){const{tokens:o}=e;let r=0,s,i=!1,a=!1;for(;r<o.length||s!==void 0;){const u=s??o[r++];if(u==="--")return;if(a&&s===void 0&&Ae(e,u))continue;const l=N(u)?Ee(e,u,o[r],n,t):{consumedByCommander:!1,consumed:0};if(r+=l.consumed,s=l.group,a=l.variadic===!0,!l.consumedByCommander){if(_e(e.stop,u,i))return;i=!0}}}function Ae(e,n){return!N(n)||e.negativeNumbersAreValues&&Q.test(n)}function _e(e,n,t){return e!==void 0&&(e.atFirstUnrecognized||!t&&e.atSubcommand(n))}function Ee(e,n,t,o,r){const s=Le(n,t,o);if(s!==void 0)return r(s.spelling,s.entry,s.value),{consumedByCommander:!1,consumed:s.consumed};const i=o(n);if(i!==void 0){const a=i.arity==="required"||i.arity==="optional"&&t!==void 0&&(!N(t)||e.negativeNumbersAreValues&&Q.test(t));return r(n,i,i.negates===!0?!1:a?t:!0),{consumedByCommander:!0,consumed:a?1:0,variadic:i.variadic===!0}}return n[1]!=="-"?{consumed:0,...Ce(n,o,r)}:{consumedByCommander:Ke(n,o,r,e.includesLooseFlags?r:()=>{}),consumed:0}}function Le(e,n,t){const o=e.indexOf("="),r=o>1?e.slice(0,o):e,s=t(r);if(s?.loose===!0)return o>1?{spelling:r,entry:s,value:e.slice(o+1),consumed:0}:n!==void 0&&!n.startsWith("-")?{spelling:r,entry:s,value:n,consumed:1}:{spelling:r,entry:s,value:!0,consumed:0};const i=o<0&&e.startsWith("--no-")?t(`--${e.slice(5)}`):void 0;return i?.loose===!0&&i.declared?.kind==="boolean"?{spelling:e,entry:i,value:!1,consumed:0}:void 0}function Ce(e,n,t){const o=e.slice(0,2),r=e.length>2?n(o):void 0;return r===void 0||r.loose===!0?{consumedByCommander:!1}:r.arity!=="none"?(t(o,r,e.slice(2)),{consumedByCommander:!0}):(t(o,r,!0),{consumedByCommander:!0,group:`-${e.slice(2)}`})}function Ke(e,n,t,o){const r=e.indexOf("=");if(r>2){const i=e.slice(0,r),a=n(i);return a!==void 0&&a.arity!=="none"?(t(i,a,e.slice(r+1)),!0):(a?.declared?.kind==="boolean"&&o(i,a,e.slice(r+1)),!1)}const s=e.startsWith("--no-")?n(`--${e.slice(5)}`):void 0;return s?.declared?.kind==="boolean"&&o(e,s,!1),!1}function Be(e,n,t){const o=ve(n),r=new Map;for(const s of e)xe(s,i=>$e(s,o,i),(i,a,u)=>{a.declared!==void 0&&je(r,a.declared,i,u,t)})}function je(e,n,t,o,r){const{definition:s,handlerKey:i,kind:a}=n,u=a?h(o,a):o,l=e.get(i)??new Map,c=[...l].find(([f,P])=>f!==t&&!V(P,u));c!==void 0&&G(s,i,[c[0],t],r),l.set(t,u),e.set(i,l)}export{B as coerceLooseCommandOptionsWithFlagDefinitions,ke as collectExtensionFlagDefinitionsForCommand,We as collectLooseCommandOptionKeysForDefinitions,Re as collectLoosePositionalArgs,Ue as normalizeDirectExtensionCommandOptions,qe as parseLooseCommandOptions,Be as refuseConflictingArgvOptionSpellings,ze as resolveExtensionFlagOptionKey,Me as stripLooseCommandOptionTokens,Te as validateLooseCommandOptionsWithFlagDefinitions};
1
+ import{isDeepStrictEqual as T}from"node:util";import{resolvePmCommandOperation as k}from"../cli-contracts/command-aliases.js";import{describeFlagScalarValueFailure as j,resolveExtensionFlagValueContract as F,resolveExtensionLongFlagName as L,EXIT_CODE as m,PmCliError as y,flattenFlagListValue as z,resolveFlagValueKind as fe}from"../runtime-primitives.js";import{RESERVED_EXTENSION_HOST_FLAG_NAMES as de}from"../../core/extensions/reserved-host-flags.js";const pe=new Set(["__proto__","prototype","constructor"]),x=Symbol("looseOptionOccurrences");function h(e){return e.trim().toLowerCase().replaceAll(/-([a-z0-9])/g,(t,o)=>o.toUpperCase())}function ge(e,n,t){const o=e[n];if(o===void 0){e[n]=t;return}if(Array.isArray(o)){o.push(t),e[n]=o;return}e[n]=[o,t]}function N(e,n){const t=e[n];if(!t.startsWith("-")||t==="-"||t==="--")return null;if(!t.startsWith("--")){const i=t.indexOf("=");if(i>=0)return{consumed:1,key:t.slice(1,i).trim(),value:t.slice(i+1),attached:!0};const a=t.slice(1).trim(),l=e[n+1];return typeof l=="string"&&!l.startsWith("-")?{consumed:2,key:a,value:l}:{consumed:1,key:a,value:!0}}const o=t.indexOf("=");if(o>=0)return{consumed:1,key:t.slice(2,o).trim(),value:t.slice(o+1),attached:!0};if(t.startsWith("--no-"))return{consumed:1,key:t.slice(5).trim(),value:!1};const r=t.slice(2).trim(),s=e[n+1];return typeof s=="string"&&!s.startsWith("-")?{consumed:2,key:r,value:s}:{consumed:1,key:r,value:!0}}function E(e){return pe.has(e)}function C(e){const n=(typeof e.value_type=="string"?e.value_type:void 0)??(typeof e.type=="string"?e.type:void 0);return fe(n)}function v(e){const n=[],t=L(e.long)??"",o=typeof e.short=="string"?e.short.trim():"";if(t.startsWith("--")){const r=h(t.slice(2));r.length>0&&!E(r)&&n.push(r)}if(o.startsWith("-")&&!o.startsWith("--")){const r=h(o.slice(1));r.length>0&&!E(r)&&n.push(r)}return[...new Set(n)]}function He(e){const n=new Set;for(const t of e)for(const o of v(t))n.add(o);return n}function O(e){const n=L(e.long)??"";if(n.startsWith("--")){const t=h(n.slice(2));if(t.length>0&&!E(t))return t}return v(e)[0]??null}function $(e){const n=L(e.long)??"";if(n.startsWith("--")&&n.length>2)return n;const t=typeof e.short=="string"?e.short.trim():"";return t.startsWith("-")&&!t.startsWith("--")&&t.length>1?t:null}function U(e,n){return[...(n.definitions??e).map(o=>$(o)).filter(o=>o!==null),...n.inheritedFlags??[]]}function Je(e,n,t,o={}){if(n.length===0)return;const r=new Set,s=new Map,i=[],a=U(n,o);for(const l of n){const u=v(l),c=$(l);for(const g of u)r.add(g),l.enabled===!1&&s.set(g,c);l.required===!0&&l.enabled!==!1&&u.length>0&&i.push({keys:u,label:c,definition:l})}for(const l of Object.keys(e)){r.has(l)||B(`--${l}`,`--${l}`,t,a);const u=s.get(l);u&&I(u,t)}for(const l of i){const u=c=>Object.hasOwn(e,c)&&(l.definition.list!==!0||J(l.definition,e[c]));l.keys.some(u)||G(l.definition,l.keys[0],l.label,t)}}function B(e,n,t,o){const r=o.length>0?` Expected one of: ${[...new Set(o)].join(", ")}.`:"";throw new y(`Unknown option '${e}' for extension command '${t}'.${r}`,m.USAGE,{code:"unknown_option",flag:n,required:`Use a flag the command accepts; run pm contracts --command ${t} --flags-only --json to list them.`})}function I(e,n){throw new y(`Option '${e}' is disabled for extension command '${n}'.`,m.USAGE,{code:"extension_option_disabled",flag:e,required:`Remove ${e}; the command declares it with enabled: false.`,why:"A disabled declaration keeps the flag in the contract while refusing every value for it.",examples:[`pm ${n} --help`],nextSteps:[`Run pm contracts --command ${n} --flags-only --json to list the flags this command accepts.`]})}function G(e,n,t,o){const r=F(e),s=r.value_arity==="none"?t:r.value_arity==="optional"?`${t} [${r.value_name}]`:`${t} <${r.value_name}>`;throw new y(`Missing required option '${t}' for extension command '${o}'.`,m.USAGE,{code:"missing_required_option",flag:t,field:n,required:`Pass ${s}.`,why:"The command declares this flag as required, so pm refuses the invocation before the extension handler runs.",examples:[`pm ${o} ${s}`],nextSteps:[`Run pm contracts --command ${o} --flags-only --json to read each flag's sdk_option key.`],recovery:{missing:[t]}})}function he(e){return typeof e=="string"||e==null?e:String(e)}function me(e){if(typeof e=="number")return e;if(typeof e=="string"&&e.trim().length>0){const n=Number(e);return Number.isFinite(n)?n:e}return e}function H(e){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.trim().toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="0")return!1}return e}const ye={string:he,number:me,boolean:H};function b(e,n){return Array.isArray(e)?e.map(t=>b(t,n)):ye[n](e)}function V(e,n,t){const o=t?(Array.isArray(e)?e.flat(1/0):[e]).filter(r=>r!=null&&r!==""):z(e);return n?o.map(r=>b(r,n)):o}function J(e,n){return V(n,null,e.repeatable===!0).length>0}function Oe(e,n,t,o){return t?V(e,n,o):n?b(e,n):e}function be(e,n,t){const o=Y(e,n);return o.length===0?t:o.map(r=>r.value)}function X(e){return F(e).value_arity==="none"}function q(e,n,t,o,r){const s=$(e),i=r?` for extension command '${r}'`:"",a=t===!0?"no value":JSON.stringify(t);throw new y(`Option '${s}'${i} expects ${o}; received ${a}.`,m.USAGE,{code:"extension_flag_value_invalid",flag:s,required:`Pass ${s} ${n==="number"?"<number>":"<true|false|1|0>"}.`,why:`The flag declares value_type ${n} with value_validation strict, so a malformed token is refused before the extension handler runs.`,nextSteps:[`Re-run with a valid ${n} value for ${s}.`,`Run pm ${r??"<command>"} --help to review the declared flag contract.`]})}function D(e,n){return e.value_validation==="strict"&&n!=="string"}function Y(e,n){const t=e[x];if(!t)return[];const o=new Set(n);return t.filter(r=>o.has(r.key))}function we(e,n,t,o){if(X(e))for(const r of Y(t,n)){if(r.attached!==!0)continue;const s=e.list===!0&&e.repeatable!==!0?z(r.value):[r.value];for(const i of s){const a=j(b(i,"boolean"),"boolean");a!==null&&q(e,"boolean",i,a.expected,o)}}}function Se(e,n,t,o,r){const s=Array.isArray(t)?t.flat(1/0):[t],i=o?s:s.flatMap(a=>typeof a=="string"?a.split(","):[a]);for(const a of i)if(typeof a=="string"&&a.trim().length===0){const l=j(a,n);q(e,n,a,l.expected,r)}}function R(e,n,t,o){if(!D(e,t))return n;const r=t==="boolean"&&X(e),s=i=>{const a=j(i,t);return a===null?i:r&&typeof i=="string"?!0:q(e,t,i,a.expected,o)};return Array.isArray(n)?n.map(s):s(n)}function ve(e,n,t,o){for(const r of t)if(!(r===n||!Object.hasOwn(e,r))){if(Object.hasOwn(e,n)){if(o){const s=e[n],i=e[r];e[n]=[...Array.isArray(s)?s:[s],...Array.isArray(i)?i:[i]].filter(a=>a!=null)}delete e[r];continue}e[n]=e[r],delete e[r]}}function Z(e,n,t=e,o){if(n.length===0)return e;const r=Object.create(null);for(const[i,a]of Object.entries(e))r[i]=a;const s=new Set(n.map(i=>O(i)).filter(i=>i!==null));for(const i of n){const a=O(i);if(a){const l=v(i).filter(u=>u===a||!s.has(u));$e(r,i,a,l,t,o)}}return r}function $e(e,n,t,o,r,s){const i=n.list===!0,a=C(n);a&&!i&&xe(e,n,t,o,a,s),ve(e,t,o,i);const l=n.repeatable===!0;if(!Object.hasOwn(e,t)){n.default!==void 0&&(e[t]=Oe(n.default,a,i,l));return}if(a==="boolean"&&D(n,a)&&we(n,o,r,s),i){e[t]=Ae(n,o,r,e[t],a,l,s);return}a&&(e[t]=R(n,b(e[t],a),a,s))}function xe(e,n,t,o,r,s){for(const i of o)i!==t&&Object.hasOwn(e,i)&&R(n,b(e[i],r),r,s)}function Ae(e,n,t,o,r,s,i){const a=be(t,n,o);r&&D(e,r)&&Se(e,r,a,s,i);const l=V(a,r,s);return r?R(e,l,r,i):l}function Xe(e){const n=Object.create(null),t=[];Object.defineProperty(n,x,{value:t});let o=0;for(;o<e.length;){const r=N(e,o);if(!r){o+=1;continue}const s=h(r.key);if(s.length===0||E(s)){o+=r.consumed;continue}ge(n,s,r.value),t.push({...r,key:s}),o+=r.consumed}return n}function Ye(e){const n=[];let t=0;for(;t<e.length;){if(e[t]==="--"){n.push(...e.slice(t+1));break}const o=N(e,t);if(o){t+=Math.max(1,o.consumed);continue}n.push(e[t]),t+=1}return n}function Ze(e,n){if(n.length===0)return[...e];const t=new Set,o=new Set;for(const i of n){const a=C(i);for(const l of v(i))t.add(l),a==="boolean"&&o.add(l)}if(t.size===0)return[...e];const r=[];let s=0;for(;s<e.length;){if(e[s]==="--"){r.push(...e.slice(s+1));break}const i=N(e,s);if(i){const a=h(i.key);if(t.has(a)){const l=e[s],u=o.has(a)&&!l.includes("=")?1:i.consumed;s+=u;continue}}r.push(e[s]),s+=1}return r}function Qe(e){return O(e)}function Q(e){return e.trim().toLowerCase().split(/\s+/u).filter(n=>n.length>0).join(" ")}function Pe(e,n){const t=Q(n);if(t.length===0)return[];const o=k(t);return e.flags.filter(r=>k(Q(r.target_command))===o).flatMap(r=>[...r.flags])}function P(e,n,t,o){const r=$(e),[s,i]=t;throw new y(`Options '${s}' and '${i}' both set ${r} for extension command '${o}' with different values.`,m.USAGE,{code:"extension_option_spelling_conflict",required:`Pass ${r} once, under the handler key '${n}'.`,why:`'${s}' and '${i}' are spellings of the same declared flag, and pm refuses to choose between two different values.`,nextSteps:[`Remove '${s}' or '${i}' and pass one value as '${n}'.`,`Run pm contracts --command ${o} --flags-only --json to read each flag's sdk_option key.`]})}function en(e,n,t,o={}){if(n.length===0)return e;const r=n.map(c=>c.repeatable===!0&&c.list!==!0?{...c,list:!0}:c),s=Ce(r),i=Fe(e,s,t),a=new Set([...s.long.values()].map(({handlerKey:c})=>c)),l=Object.create(null),u=Object.create(null);for(const[c,g]of Object.entries(i))a.has(c)?l[c]=g:g===void 0||o.undeclaredKeys==="pass"||Le(c)?u[c]=g:B(c,Ee(c),t,U(r,{}));return ne(l,r,t),Object.assign(u,Z(l,r,ee(l,s),t))}function ee(e,n){const t=new Set([...n.long.values()].map(({handlerKey:s})=>s)),o=Object.entries(e).filter(([s])=>t.has(s)).flatMap(([s,i])=>(Array.isArray(i)?i.flat(1/0):[i]).map(a=>({consumed:1,key:s,value:a,attached:!0}))),r=Object.create(null);return Object.defineProperty(r,x,{value:o}),r}function ne(e,n,t){for(const o of n){const r=O(o);if(r===null)continue;const s=$(o),i=e[r],a=Object.hasOwn(e,r);o.enabled===!1&&a&&I(s,t);const l=a&&(o.list!==!0||J(o,i));o.required===!0&&o.enabled!==!1&&!l&&G(o,r,s,t),o.list!==!0&&Array.isArray(i)&&_e(s,t)}}function _e(e,n){throw new y(`Option '${e}' for extension command '${n}' takes one value; received an array.`,m.USAGE,{code:"extension_flag_value_invalid",flag:e,required:`Pass one value for ${e}, or ask the package to declare it with list: true or repeatable: true.`,why:"The flag is not declared list or repeatable, so pm refuses an array before the extension handler runs instead of handing it a value of the wrong shape.",nextSteps:[`Run pm contracts --command ${n} --flags-only --json to read each flag's value contract.`]})}const te=new Set([...[...de].flatMap(e=>{const n=e.replace(/^--/u,"");return[n,...n.startsWith("no-")?[n.slice(3)]:[]].flatMap(o=>[h(o),o.replaceAll("-","_")])}),"force","subcommand","inputResponses","requestState"]);function Le(e){return te.has(e)||te.has(h(e.replace(/^-{1,2}/u,"")))}function Ee(e){return`--${e.replace(/^-+/u,"").replace(/([a-z0-9])([A-Z])/gu,"$1-$2").replaceAll("_","-").toLowerCase()}`}function Ce(e){const n={long:new Map,short:new Map},t=(o,r,s)=>{r.length>0&&!o.has(r)&&o.set(r,s)};for(const o of e){const r=O(o);if(r===null)continue;const s={handlerKey:r,definition:o};t(n.long,r,s);const i=typeof o.short=="string"?o.short.trim():"";i.startsWith("-")&&!i.startsWith("--")&&t(n.short,i.slice(1),s)}return n}function W(e,n){return e.long.get(n)??e.short.get(n.replace(/^-(?!-)/u,""))??e.long.get(h(n.replace(/^-{1,2}/u,"")))}function Ke(e,n,t,o){const r=/^(?:--)?no-(.+)$/u.exec(n)?.[1];if(r===void 0||W(e,n)!==void 0)return{spelling:n,value:t};const s=W(e,r);return s===void 0||C(s.definition)!=="boolean"?{spelling:n,value:t}:(s.definition.list===!0||s.definition.repeatable===!0)&&Array.isArray(t)?{spelling:r,value:t.flat(1/0).map(i=>re(n,s.definition,i,o))}:s.definition.list===!0&&t!==void 0?{spelling:r,value:re(n,s.definition,t,o)}:{spelling:r,value:t===void 0?t:K(n,s.definition,t,o)}}function re(e,n,t,o){const r=s=>s.trim().length===0?s:String(K(e,n,s.trim(),o));return t==null?t:typeof t!="string"?K(e,n,t,o):t.trim().length===0?t:n.repeatable===!0||!t.includes(",")?K(e,n,t,o):t.split(",").map(r).join(",")}function K(e,n,t,o){const r=H(t);return typeof r=="boolean"?!r:je(e,n,t,o)}function je(e,n,t,o){const r=$(n);throw new y(`Option '${e}' for extension command '${o}' negates ${r} and expects true, false, 1, or 0; received ${JSON.stringify(t)}.`,m.USAGE,{code:"extension_flag_value_invalid",flag:r,required:`Pass ${r} as true or false, or '${e}' as true.`,why:`'${e}' is the negated spelling of the boolean ${r}, so only a boolean value can be inverted before the extension handler runs.`,nextSteps:[`Run pm contracts --command ${o} --flags-only --json to read each flag's value contract.`]})}function Fe(e,n,t){const o=Object.create(null),r=new Map;for(const[s,i]of Object.entries(e)){const{spelling:a,value:l}=Ke(n,s,i,t),u=W(n,a);if(u===void 0)o[a]=l;else if(l!==void 0){const c=r.get(u.handlerKey);c===void 0?(r.set(u.handlerKey,a),o[u.handlerKey]=l):T(oe(u.definition,u.handlerKey,o[u.handlerKey],n,t),oe(u.definition,u.handlerKey,l,n,t))||P(u.definition,u.handlerKey,[c,a],t)}}return o}function oe(e,n,t,o,r){const s={[n]:t};return ne(s,[e],r),Z(s,[e],ee(s,o),r)[n]}function se(e){const n=new Map;for(const t of e){const o=O(t);if(o===null)continue;const r={definition:t,handlerKey:o,kind:C(t),arity:F(t).value_arity,scalar:t.list!==!0},s=[L(t.long),typeof t.short=="string"?t.short.trim():""];for(const i of s.filter(a=>a?.startsWith("-")===!0))n.has(i)||n.set(i,r)}return n}function ie(e,n,t,o=ke){const r=e.optionOf(t),s=n.get(t),i=s!==void 0&&o(s)?s:void 0;if(r!==void 0){const a={arity:r.arity,...r.variadic===!0?{variadic:!0}:{}};if(i?.handlerKey===r.key)return{...a,declared:i};if(s!==void 0)return a;const l=Te(n,t,r,o);return l===void 0?a:{...a,declared:l,negates:!0}}if(!(!e.includesLooseFlags||s===void 0))return i===void 0?{arity:s.arity,loose:!0}:{arity:s.arity,declared:i,loose:!0}}function M(e){return e.length>1&&e.startsWith("-")}const ae=/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/u;function le(e,n,t){const{tokens:o}=e;let r=0,s,i=!1,a=!1;for(;r<o.length||s!==void 0;){const l=s??o[r++];if(l==="--")return;if(a&&s===void 0&&Ne(e,l))continue;const u=M(l)?qe(e,l,o[r],n,t):{consumedByCommander:!1,consumed:0};if(r+=u.consumed,s=u.group,a=u.variadic===!0,!u.consumedByCommander){if(Ve(e.stop,l,i))return;i=!0}}}function Ne(e,n){return!M(n)||e.negativeNumbersAreValues&&ae.test(n)}function Ve(e,n,t){return e!==void 0&&(e.atFirstUnrecognized||!t&&e.atSubcommand(n))}function qe(e,n,t,o,r){const s=De(n,t,o);if(s!==void 0)return r(s.spelling,s.entry,s.value,"loose"),{consumedByCommander:!1,consumed:s.consumed};const i=o(n);if(i!==void 0){const a=i.arity==="required"||i.arity==="optional"&&t!==void 0&&(!M(t)||e.negativeNumbersAreValues&&ae.test(t));return r(n,i,i.negates===!0?!1:a?t:!0,"commander"),{consumedByCommander:!0,consumed:a?1:0,variadic:i.variadic===!0}}return n[1]!=="-"?{consumed:0,...Re(n,o,r)}:{consumedByCommander:We(n,o,r,e.includesLooseFlags?r:()=>{}),consumed:0}}function De(e,n,t){const o=e.indexOf("="),r=o>1?e.slice(0,o):e,s=t(r);if(s?.loose===!0)return o>1?{spelling:r,entry:s,value:e.slice(o+1),consumed:0}:n!==void 0&&!n.startsWith("-")?{spelling:r,entry:s,value:n,consumed:1}:{spelling:r,entry:s,value:!0,consumed:0};const i=o<0&&e.startsWith("--no-")?t(`--${e.slice(5)}`):void 0;return i?.loose===!0&&i.declared?.kind==="boolean"?{spelling:e,entry:i,value:!1,consumed:0}:void 0}function Re(e,n,t){const o=e.slice(0,2),r=e.length>2?n(o):void 0;return r===void 0||r.loose===!0?{consumedByCommander:!1}:r.arity!=="none"?(t(o,r,e.slice(2),"commander"),{consumedByCommander:!0}):(t(o,r,!0,"commander"),{consumedByCommander:!0,group:`-${e.slice(2)}`})}function We(e,n,t,o){const r=e.indexOf("=");if(r>2){const i=e.slice(0,r),a=n(i);return a!==void 0&&a.arity!=="none"?(t(i,a,e.slice(r+1),"commander"),!0):(a?.declared?.kind==="boolean"&&o(i,a,e.slice(r+1),"loose"),!1)}const s=e.startsWith("--no-")?n(`--${e.slice(5)}`):void 0;return s?.declared?.kind==="boolean"&&o(e,s,!1,"loose"),!1}function nn(e,n,t){const o=se(n),r=new Map;for(const s of e)le(s,i=>ie(s,o,i),(i,a,l)=>{a.declared!==void 0&&Me(r,a.declared,i,l,t)})}function Me(e,n,t,o,r){const{definition:s,handlerKey:i,kind:a}=n,l=a?b(o,a):o,u=e.get(i)??new Map,c=[...u].find(([g,f])=>g!==t&&!T(f,l));c!==void 0&&P(s,i,[c[0],t],r),u.set(t,l),e.set(i,u)}function Te(e,n,t,o){const r=n.startsWith("--no-")?e.get(`--${n.slice(5)}`):void 0;return r!==void 0&&o(r)&&r.kind==="boolean"&&r.handlerKey===t.key?r:void 0}function ke(e){return e.scalar}function ue(e){return!e.scalar&&e.kind==="boolean"&&e.arity==="none"}function tn(e,n,t){const o=se(t),r=[...new Set(o.values())].filter(ue);if(r.length===0)return e;const s=new Set(t.map(f=>O(f)).filter(f=>f!==null)),i=f=>v(f.definition).filter(d=>d===f.handlerKey||!s.has(d)),a=new Map([...r].reverse().flatMap(f=>i(f).map(d=>[d,f]))),l=new Map;for(const f of n)le(f,d=>ie(f,o,d,ue)??ze(f,a,d),(d,w,S,A)=>{if(w.declared===void 0)return;const _=l.get(w.declared)??[];_.push(A==="commander"?{value:S}:null),l.set(w.declared,_)});const u=[...l].filter(([,f])=>f.some(d=>d!==null));if(u.length===0)return e;let c=e[x]??[];for(const[f,d]of u){const w=new Set(i(f)),S=c.filter(({key:p})=>w.has(p));if(S.length===0)continue;const A=p=>({consumed:0,key:f.handlerKey,value:p.value});let _=0;const ce=d.filter(p=>p===null).length===S.length?d.map(p=>p===null?S[_++]:A(p)):[...S,...d.filter(p=>p!==null).map(A)];c=[...c.filter(({key:p})=>!w.has(p)),...ce]}const g=Object.assign(Object.create(null),e);return Object.defineProperty(g,x,{value:c}),g}function ze(e,n,t){const o=!t.startsWith("--")&&e.optionOf(t.slice(0,2))!==void 0;if(!e.includesLooseFlags||o)return;const r=n.get(h(t.replace(/^-+/u,"")));return r===void 0?void 0:{arity:r.arity,declared:r,loose:!0}}export{Z as coerceLooseCommandOptionsWithFlagDefinitions,Pe as collectExtensionFlagDefinitionsForCommand,He as collectLooseCommandOptionKeysForDefinitions,Ye as collectLoosePositionalArgs,en as normalizeDirectExtensionCommandOptions,tn as orderArgvRepeatableSwitchOccurrences,Xe as parseLooseCommandOptions,nn as refuseConflictingArgvOptionSpellings,Qe as resolveExtensionFlagOptionKey,C as resolveLooseOptionCoercionKind,Ze as stripLooseCommandOptionTokens,Je as validateLooseCommandOptionsWithFlagDefinitions};
2
2
  //# sourceMappingURL=command-options.js.map
@@ -1,3 +1,3 @@
1
- import{createHash as k}from"node:crypto";import{runActiveOnWriteHooks as A}from"../core/extensions/index.js";import{mutateWorkspaceJsonWithHistory as I}from"../core/history/workspace-history.js";import{resolveAuthor as P}from"../core/shared/author.js";import{EXIT_CODE as u}from"../core/shared/constants.js";import{PmCliError as f}from"../core/shared/errors.js";import{asRecordOrNull as w}from"../core/shared/primitives.js";import{stableValueEquals as y}from"../core/shared/serialization.js";import{getSettingsPath as v}from"../core/store/paths.js";import{mergeSettings as E,readSettings as O,runWithConfigurationOnlySettings as W,serializeSettings as b}from"../core/store/settings.js";import{clearSettingsReadCache as _}from"../core/store/settings-read-cache.js";import{readSettingsSection as j,writeSettingsSection as C}from"../core/store/settings-sections.js";import{validateSettings as g}from"../core/store/settings-validator.js";import{isPmCliExpectedError as N}from"./errors.js";import{getItemAt as x}from"./history-read.js";import{fitOutputEnvelope as G}from"./output/fit-envelope.js";import{RelationshipEventLog as z,RelationshipEventStore as J}from"./relationship-history.js";import{analyzeGraphImpact as U}from"./relationship-analytics.js";import{RelationshipGraph as $,createRelationshipKindRegistry as R}from"./relationships.js";import{commitWorkspaceTransaction as T}from"./workspace-transaction.js";function h(t){const d=R();for(const c of t)d.register(c);return d}function H(t,d,c=[]){if(c.length===0)return t;const m=JSON.parse(t),e=JSON.parse(b(d));for(const r of c){const n=r.split(".");let a=e;for(const i of n){const s=w(a);if(!/^[a-zA-Z][a-zA-Z0-9_]*$/u.test(i)||["constructor","prototype","__proto__"].includes(i)||s===null||!Object.hasOwn(s,i))throw new f(`Invalid owned settings subtree: ${r}. Select a declared inline object path.`,u.USAGE);a=s[i]}if(w(a)===null)throw new f(`Invalid owned settings subtree: ${r}. Select a declared inline object path.`,u.USAGE);let o=m,l=e;for(const i of n.slice(0,-1)){const s=o[i];l=l[i],s===void 0&&Object.defineProperty(o,i,{value:structuredClone(l),enumerable:!0,writable:!0,configurable:!0}),o=o[i]}Object.defineProperty(o,n.at(-1),{value:a,enumerable:!0,writable:!0,configurable:!0})}return y(m,JSON.parse(t))?t:`${JSON.stringify(m,null,2)}
2
- `}function ce(t,d,c,m){return{fitOutputEnvelope:G,client:d,isItemNotFoundError:e=>N(e)&&e.exitCode===u.NOT_FOUND,getItemAt:(e,r)=>x(e,r,{pmRoot:t}),readSettingsSection:(e,r)=>j(t,e,r),writeSettingsSection:(e,r,n)=>C(t,e,r,{author:c,...n}),openRelationshipEventStore:e=>J.open({pmRoot:t,nodes:e.nodes,registry:h(e.definitions),...e.relativePath===void 0?{}:{relativePath:e.relativePath}}),createRelationshipGraph:e=>new $(e.nodes,e.edges,h(e.definitions)),analyzeRelationshipImpact:(e,r,n)=>U(e,r,n),validateRelationshipEvents:e=>{const r=new z(e.nodes,{registry:h(e.definitions)});return e.events.map(n=>r.append({...n,expectedVersion:r.version}))},commitWorkspaceTransaction:e=>T({...e,pmRoot:t}),mutateWorkspaceSettings:async e=>{if(!/^[a-zA-Z0-9._-]{1,128}$/u.test(e.operationId))throw new f("Workspace settings operationId must be 1-128 letters, digits, dots, underscores, or hyphens.",u.USAGE);const r=e.dryRun===!0?await W(t,()=>O(t)):await O(t);try{const n=await I({pmRoot:t,filePath:v(t),op:"extension:pm:settings",idempotencyKey:m===void 0?e.operationId:`${k("sha256").update(m).digest("hex").slice(0,16)}:${e.operationId}`,author:P(c,r.author_default),lockTtlSeconds:r.locks.ttl_seconds,lockWaitMs:r.locks.wait_ms,recordCreation:!1,dryRun:e.dryRun===!0,mutate:async a=>{const o=a===null?null:JSON.parse(a),l=g(o);if(!l.success)throw new f("Workspace settings mutation requires a valid initialized settings.json.",u.USAGE);const i=E(l.data),s=await e.mutate(structuredClone(i));if(!g(s).success)throw new f("Workspace settings mutation returned invalid settings.json.",u.USAGE);let p=y(i,s)?a:b(s,{source:{raw:o,validated:l.data}});p=H(p,s,e.replaceSubtrees);const S=g(JSON.parse(p));if(!S.success)throw new f("Workspace settings mutation serialized invalid settings.json.",u.USAGE);return{raw:p,result:e.includePreview===!0?E(S.data):void 0}}});return n.changed&&e.dryRun!==!0&&await A({path:v(t),scope:"project",op:"extension:pm:settings"}),{changed:n.changed,dry_run:e.dryRun===!0,replayed:n.replayed===!0,...n.result===void 0?{}:{preview:n.result}}}finally{_(t)}}}}export{ce as createExtensionCommandSdk};
1
+ import{createHash as k}from"node:crypto";import{runActiveOnWriteHooks as C}from"../core/extensions/index.js";import{mutateWorkspaceJsonWithHistory as I}from"../core/history/workspace-history.js";import{resolveAuthor as N}from"../core/shared/author.js";import{EXIT_CODE as p}from"../core/shared/constants.js";import{PmCliError as g}from"../core/shared/errors.js";import{asRecordOrNull as w}from"../core/shared/primitives.js";import{stableValueEquals as h}from"../core/shared/serialization.js";import{getSettingsPath as O}from"../core/store/paths.js";import{mergeSettings as E,readSettings as b,runWithConfigurationOnlySettings as P,serializeSettings as A}from"../core/store/settings.js";import{clearSettingsReadCache as W}from"../core/store/settings-read-cache.js";import{readSettingsSection as j,writeSettingsSection as x}from"../core/store/settings-sections.js";import{validateSettings as y}from"../core/store/settings-validator.js";import{isPmCliExpectedError as z}from"./errors.js";import{getItemAt as G}from"./history-read.js";import{fitOutputEnvelope as J}from"./output/fit-envelope.js";import{RelationshipEventLog as R,RelationshipEventStore as U}from"./relationship-history.js";import{analyzeGraphImpact as $}from"./relationship-analytics.js";import{RelationshipGraph as T,createRelationshipKindRegistry as F}from"./relationships.js";import{commitWorkspaceTransaction as D}from"./workspace-transaction.js";function v(t){const m=F();for(const c of t)m.register(c);return m}function H(t,m,c=[]){if(c.length===0)return t;const d=JSON.parse(t),e=JSON.parse(A(m));for(const n of c){const i=n.split(".");let l=e;for(const s of i){const a=w(l);if(!/^[a-zA-Z][a-zA-Z0-9_]*$/u.test(s)||["constructor","prototype","__proto__"].includes(s)||a===null||!Object.hasOwn(a,s))throw new g(`Invalid owned settings subtree: ${n}. Select a declared inline object path.`,p.USAGE);l=a[s]}if(w(l)===null)throw new g(`Invalid owned settings subtree: ${n}. Select a declared inline object path.`,p.USAGE);let o=d,u=e;for(const s of i.slice(0,-1)){const a=o[s];u=u[s],a===void 0&&Object.defineProperty(o,s,{value:structuredClone(u),enumerable:!0,writable:!0,configurable:!0}),o=o[s]}Object.defineProperty(o,i.at(-1),{value:l,enumerable:!0,writable:!0,configurable:!0})}return h(d,JSON.parse(t))?t:`${JSON.stringify(d,null,2)}
2
+ `}async function K(t,m,c){const d=m.schema?.fields??[];if(d.length===0)return;const{normalizeCliToken:e,resolveRuntimeFieldRegistry:n}=await import("../core/schema/runtime-schema.js"),i=r=>n({fields:[r]}).definitions[0],l=r=>JSON.parse(JSON.stringify(r)),o=[...t.schema.fields,...Array.isArray(c)?c:[]].map(r=>({resolved:i(r),persisted:l(r)})),u=r=>[r.cli_flag,...Array.isArray(r.cli_aliases)?r.cli_aliases:[]].some(f=>typeof f=="string"&&e(f).length===0),s=d.filter(r=>{const f=i(r),_=o.some(S=>h(S.persisted,l(r)));return f===void 0||u(r)?!_:!o.some(S=>h(S.resolved,f))});if(s.length===0)return;const{assertFieldDefinitionOptionsAvailable:a}=await import("./schema/field-option-collisions.js");for(const r of s)a(r)}function ue(t,m,c,d){return{fitOutputEnvelope:J,client:m,isItemNotFoundError:e=>z(e)&&e.exitCode===p.NOT_FOUND,getItemAt:(e,n)=>G(e,n,{pmRoot:t}),readSettingsSection:(e,n)=>j(t,e,n),writeSettingsSection:(e,n,i)=>x(t,e,n,{author:c,...i}),openRelationshipEventStore:e=>U.open({pmRoot:t,nodes:e.nodes,registry:v(e.definitions),...e.relativePath===void 0?{}:{relativePath:e.relativePath}}),createRelationshipGraph:e=>new T(e.nodes,e.edges,v(e.definitions)),analyzeRelationshipImpact:(e,n,i)=>$(e,n,i),validateRelationshipEvents:e=>{const n=new R(e.nodes,{registry:v(e.definitions)});return e.events.map(i=>n.append({...i,expectedVersion:n.version}))},commitWorkspaceTransaction:e=>D({...e,pmRoot:t}),mutateWorkspaceSettings:async e=>{if(!/^[a-zA-Z0-9._-]{1,128}$/u.test(e.operationId))throw new g("Workspace settings operationId must be 1-128 letters, digits, dots, underscores, or hyphens.",p.USAGE);const n=e.dryRun===!0?await P(t,()=>b(t)):await b(t);try{const i=await I({pmRoot:t,filePath:O(t),op:"extension:pm:settings",idempotencyKey:d===void 0?e.operationId:`${k("sha256").update(d).digest("hex").slice(0,16)}:${e.operationId}`,author:N(c,n.author_default),lockTtlSeconds:n.locks.ttl_seconds,lockWaitMs:n.locks.wait_ms,recordCreation:!1,dryRun:e.dryRun===!0,mutate:async l=>{const o=l===null?null:JSON.parse(l),u=y(o);if(!u.success)throw new g("Workspace settings mutation requires a valid initialized settings.json.",p.USAGE);const s=E(u.data),a=await e.mutate(structuredClone(s));if(!y(a).success)throw new g("Workspace settings mutation returned invalid settings.json.",p.USAGE);await K(s,a,o.schema?.fields);let r=h(s,a)?l:A(a,{source:{raw:o,validated:u.data}});r=H(r,a,e.replaceSubtrees);const f=y(JSON.parse(r));if(!f.success)throw new g("Workspace settings mutation serialized invalid settings.json.",p.USAGE);return{raw:r,result:e.includePreview===!0?E(f.data):void 0}}});return i.changed&&e.dryRun!==!0&&await C({path:O(t),scope:"project",op:"extension:pm:settings"}),{changed:i.changed,dry_run:e.dryRun===!0,replayed:i.replayed===!0,...i.result===void 0?{}:{preview:i.result}}}finally{W(t)}}}}export{ue as createExtensionCommandSdk};
3
3
  //# sourceMappingURL=extension-command-context.js.map
@@ -1,2 +1,2 @@
1
- const e=[{code:"acceptance_criteria_mutation_conflict",exit_code:2,sources:["sdk/lifecycle/update.ts"],emitting_commands:["update","update-many"]},{code:"acceptance_criteria_remove_unmatched",exit_code:3,sources:["sdk/lifecycle/update-many.ts","sdk/lifecycle/update.ts"],emitting_commands:["update","update-many"]},{code:"acceptance_criteria_semicolon_forbidden",exit_code:2,stable:!0,sources:["core/item/parse.ts"]},{code:"accepted_rejected_value",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"alias_collision",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"alias_target_missing",exit_code:1,sources:["sdk/cli-contracts/grammar-contracts.ts"]},{code:"already_claimed_by",exit_code:4,stable:!0,sources:["sdk/lifecycle/claim.ts"],emitting_commands:["claim"]},{code:"ambiguous_option_combination",exit_code:2,stable:!0,sources:["sdk/lifecycle/claim.ts","sdk/lifecycle/plan.ts"],emitting_commands:["claim","plan"]},{code:"annotation_alias_conflict",exit_code:2,sources:["cli/register-annotations.ts"]},{code:"annotation_entry_mismatch",exit_code:4,sources:["sdk/annotations.ts"]},{code:"annotation_expectation_invalid",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_expectation_without_target",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_flag_like_value",exit_code:2,stable:!0,sources:["sdk/annotations.ts"]},{code:"annotation_if_absent_without_append",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_message_without_text",exit_code:2,stable:!0,sources:["sdk/annotations.ts"]},{code:"annotation_text_compacted",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_text_source_conflict",exit_code:2,sources:["sdk/runtime-input.ts"]},{code:"annotation_transposed_subcommand",exit_code:2,sources:["cli/register-annotations.ts"]},{code:"append_empty_body",exit_code:2,stable:!0,sources:["sdk/lifecycle/append.ts"],emitting_commands:["append"]},{code:"assurance_registry_invalid",exit_code:1,sources:["sdk/governance/assurance.ts"]},{code:"bare_comma_entry_ambiguous",exit_code:2,sources:["core/item/parse.ts"]},{code:"blocker_identity_read_failed",exit_code:1,sources:["sdk/query/declared-blockers.ts"]},{code:"body_file_conflicts_with_body",exit_code:2,stable:!0,sources:["core/io/body-file.ts"]},{code:"body_file_missing_path",exit_code:2,stable:!0,sources:["core/io/body-file.ts"]},{code:"body_file_unreadable",exit_code:3,stable:!0,sources:["core/io/body-file.ts"]},{code:"budget_exceeded",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"bulk_create_route",exit_code:2,sources:["cli/register-mutation.ts"]},{code:"bulk_ids_input_empty",exit_code:2,sources:["core/io/bulk-ids-input.ts","sdk/history-compact.ts","sdk/history-mcp.ts"],owned_states:[{state:"bulk_ids_stdin_contains_no_nonempty_ids",probe_id:"bulk-ids-stdin-empty",entrypoints:["update-many"],expected_exit_class:"usage"}]},{code:"bulk_ids_input_missing_path",exit_code:2,sources:["core/io/bulk-ids-input.ts"],owned_states:[{state:"bulk_ids_file_token_omits_its_path",probe_id:"bulk-ids-file-path-missing",entrypoints:["update-many"],expected_exit_class:"usage"}]},{code:"bulk_ids_input_unreadable",exit_code:3,sources:["core/io/bulk-ids-input.ts"],owned_states:[{state:"bulk_ids_file_path_cannot_be_read",probe_id:"bulk-ids-file-unreadable",entrypoints:["update-many"],expected_exit_class:"not_found"}]},{code:"bundle_integrity_torn_install",exit_code:1,stable:!0,sources:["cli/bundle-integrity.ts"]},{code:"capability_undeclared",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"capability_unused",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"child_projection_item_bound_exceeded",exit_code:1,stable:!0,sources:["sdk/item-children.ts"]},{code:"close_reason_required",exit_code:2,stable:!0,sources:["sdk/lifecycle-policy.ts","sdk/lifecycle/close-many.ts"],emitting_commands:["*","close-many"]},{code:"close_through_update",exit_code:1,stable:!0,sources:["core/telemetry/observability.ts"]},{code:"close_validation_deferred_fields",exit_code:2,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"close_validation_missing_fields",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"collected_zero_items",exit_code:1,stable:!0,sources:["sdk/test/execution-receipts.ts"]},{code:"collection_transposed_subcommand",exit_code:2,sources:["cli/error-guidance.ts"]},{code:"command_failed",exit_code:1,stable:!0,sources:["cli/error-guidance.ts"]},{code:"command_namespace",exit_code:2,stable:!0,sources:["sdk/cli-contracts/runtime-contracts.ts"]},{code:"command_override_conflict",exit_code:4,stable:!0,sources:["sdk/compose.ts"]},{code:"config_duplicate",exit_code:1,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"config_key_unknown",exit_code:2,stable:!0,sources:["core/profile/profile-lint.ts","sdk/config.ts"]},{code:"config_value_invalid",exit_code:2,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"conflicting_lifecycle_owner",exit_code:2,stable:!0,sources:["cli/register-operations.ts"]},{code:"context_evaluation_read_incomplete",exit_code:2,sources:["sdk/context-relevance.ts"]},{code:"context_signal_store_invalid",exit_code:2,sources:["sdk/context-signal-store.ts"]},{code:"context_signal_store_stale",exit_code:1,sources:["sdk/context-signal-store.ts"]},{code:"context_signal_store_write_failed",exit_code:1,sources:["sdk/context-signal-store.ts"]},{code:"context_takes_no_item_argument",exit_code:1,stable:!0,sources:["cli/error-guidance.ts"]},{code:"core_item_field_requires_dedicated_flag",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"create_deferral_conflict",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_deferral_field_unsupported",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_deferral_fields_required",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_deferral_reason_required",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_positional_type_without_title",exit_code:2,stable:!0,sources:["cli/register-mutation.ts"]},{code:"dependency_cardinality_created",exit_code:2,sources:["sdk/graph/cardinality-integrity.ts"]},{code:"dependency_edge_not_allowed",exit_code:2,stable:!0,sources:["sdk/dependency-flag-validation.ts"]},{code:"dependency_flag_value_invalid",exit_code:2,sources:["sdk/dependency-flag-validation.ts"]},{code:"dependency_remove_no_match",exit_code:3,sources:["sdk/lifecycle/dependency-removal.ts"],emitting_commands:["update"]},{code:"dependency_target_not_found",exit_code:3,sources:["sdk/dependency-flag-validation.ts"]},{code:"dependency_temporal_order_invalid",exit_code:2,sources:["sdk/dependency-flag-validation.ts"]},{code:"duplicate_canonical_flag",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"duplicate_command",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"duplicate_destination",exit_code:1,sources:["sdk/cli-contracts/grammar-contracts.ts"]},{code:"duplicate_edge",exit_code:1,stable:!0,sources:["sdk/graph/remediation.ts"]},{code:"duplicate_observation",exit_code:1,sources:["sdk/flag-invocation-contracts.ts"]},{code:"duplicate_probe",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"duplicate_sweep_cost_limit",exit_code:4,stable:!0,sources:["sdk/query/duplicate-candidates.ts"],emitting_commands:["duplicate-candidates"]},{code:"duplicate_target_circular",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"duplicate_target_is_duplicate",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"duplicate_target_missing",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"duplicate_target_self",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"empty_corpus",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"empty_surface",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"error_code_mismatch",exit_code:1,sources:["sdk/agent/refusal-closure.ts","sdk/agent/tracker-preflight-contracts.ts"]},{code:"event_cursor_query_mismatch",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"event_history_integrity_failed",exit_code:1,sources:["core/history/event-index.ts"]},{code:"event_index_unavailable",exit_code:1,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"exit_code_mismatch",exit_code:1,sources:["sdk/agent/tracker-preflight-contracts.ts"]},{code:"expect_hash_background_unsupported",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_invalid",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_invocation_rewritten",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_requires_mutation",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_target_required",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expected_revision_duplicate",exit_code:2,sources:["core/store/item-mutation-precondition.ts"]},{code:"expected_revision_scope_conflict",exit_code:2,sources:["core/store/item-mutation-precondition.ts"]},{code:"extension_command_activation_failed",exit_code:1,stable:!0,sources:["cli/commander-usage.ts"]},{code:"extension_dependency_name_unsafe",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"extension_dependency_spec_invalid",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"extension_dependency_version_unsafe",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"extension_flag_value_invalid",exit_code:2,sources:["sdk/extension/command-options.ts"]},{code:"extension_install_incomplete_source_scan",exit_code:2,sources:["sdk/extension/install-plan.ts"]},{code:"extension_install_rollback_failed",exit_code:1,sources:["sdk/extension/install-snapshot.ts"]},{code:"extension_install_soft_failed",exit_code:1,stable:!0,sources:["cli/register-setup.ts"]},{code:"extension_install_source_contains_destination",exit_code:2,stable:!0,sources:["sdk/extension/install-runtime.ts"]},{code:"extension_item_field_reserved",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"extension_item_field_type_conflict",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"extension_item_field_unknown",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"extension_mutation_guard_failed",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_mutation_guard_invalid_decision",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_mutation_guard_invalid_denial",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_mutation_guard_timed_out",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_option_disabled",exit_code:2,sources:["sdk/extension/command-options.ts"]},{code:"extension_option_spelling_conflict",exit_code:2,sources:["sdk/extension/command-options.ts"]},{code:"extension_read_output_invalid",exit_code:2,sources:["sdk/read-output/extension.ts"]},{code:"extension_update_health_partial_coverage",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"extensions_unreadable",exit_code:1,sources:["sdk/extension/static-inventory.ts"]},{code:"field_duplicate",exit_code:1,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"field_invalid",exit_code:2,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"field_mcp_input_collision",exit_code:1,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"field_option_collision",exit_code:1,sources:["core/profile/profile-lint.ts"]},{code:"finalization_invalid_document",exit_code:2,sources:["sdk/transactions/item-finalization.ts"]},{code:"github_source_entry_unbuilt",exit_code:2,stable:!0,sources:["sdk/extension/shared.ts"]},{code:"hierarchy_cardinality_created",exit_code:4,sources:["sdk/graph/hierarchy-integrity.ts"]},{code:"hierarchy_cycle_created",exit_code:4,sources:["sdk/graph/hierarchy-integrity.ts"]},{code:"hierarchy_parent_divergence_created",exit_code:4,sources:["sdk/graph/hierarchy-integrity.ts"]},{code:"history_append_only_repair_unavailable",exit_code:4,sources:["sdk/history/append-only-repair.ts"]},{code:"history_author_acknowledge_plan_conflict",exit_code:4,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_plan_fingerprint_required",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_preview_limit_invalid",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_required_values_missing",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_selector_conflict",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_selector_required",exit_code:2,stable:!0,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_target_not_actionable",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_target_unreadable",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_baseline_unavailable",exit_code:1,sources:["core/history/projection.ts"]},{code:"history_compact_boundary_bridged",exit_code:2,sources:["sdk/history-compact.ts"]},{code:"history_drift_chain_mismatch",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_chain_mismatches"]},{code:"history_drift_chain_unbridgeable",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"history_drift_hash_mismatch",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_hash_mismatches"]},{code:"history_drift_merge_receipt",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"history_drift_missing_stream",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_missing_streams"]},{code:"history_drift_unreadable_stream",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_unreadable_streams"]},{code:"history_drift_unrepairable_stream",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"history_drift_version_skew",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_version_skews"]},{code:"history_json_invalid",exit_code:1,sources:["core/history/read.ts"]},{code:"history_merge_conflict_markers_detected",exit_code:1,stable:!0,sources:["core/history/read.ts"],canonical_code:"merge_conflict_markers_detected"},{code:"history_record_integrity_invalid",exit_code:4,sources:["sdk/history/reanchor-refusal.ts"]},{code:"history_record_invalid",exit_code:1,sources:["core/history/read.ts"]},{code:"history_record_version_unsupported",exit_code:4,sources:["sdk/history/reanchor-refusal.ts"]},{code:"history_redact_bridge_unlocated",exit_code:1,sources:["sdk/history-redact.ts"]},{code:"history_replay_invalid",exit_code:1,sources:["core/history/projection.ts","core/history/tombstone.ts"]},{code:"history_salvage_refused",exit_code:4,sources:["sdk/history/salvage.ts"]},{code:"history_stream_over_compact_threshold",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"history_target_out_of_range",exit_code:1,stable:!0,sources:["core/history/projection.ts"]},{code:"history_timestamp_invalid",exit_code:1,sources:["core/history/event-index.ts","core/history/history.ts"]},{code:"history_union_rebase_conflict",exit_code:4,sources:["sdk/merge/history-scalar-rebase.ts"]},{code:"history_unknown_author_events",exit_code:2,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_unknown_author_events"]},{code:"history_version_mapping_unavailable",exit_code:2,sources:["core/history/version-address.ts"]},{code:"history_version_pruned",exit_code:2,sources:["core/history/projection.ts"]},{code:"history_version_unreconstructable",exit_code:2,sources:["core/history/projection.ts"]},{code:"host_environment_capacity_fault",exit_code:1,sources:["core/fs/host-environment-errors.ts"]},{code:"host_environment_operation_invalid",exit_code:2,sources:["core/fs/host-environment-errors.ts"]},{code:"host_environment_permission_fault",exit_code:1,sources:["core/fs/host-environment-errors.ts"]},{code:"host_environment_resource_fault",exit_code:1,sources:["core/fs/host-environment-errors.ts"]},{code:"improvement_metric_contract_conflict",exit_code:4,sources:["sdk/improvement-ledger.ts"]},{code:"improvement_observation_conflict",exit_code:4,sources:["sdk/improvement-ledger.ts"]},{code:"in_progress_idle",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"in_progress_unowned",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"incomplete_allowed_values",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"inconsistent_concept_kind",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"init_existing_settings_requires_force",exit_code:2,stable:!0,sources:["sdk/init.ts"]},{code:"init_gitignore_unwritable",exit_code:1,stable:!0,sources:["sdk/workspace.ts"]},{code:"init_id_prefix_conflict",exit_code:2,stable:!0,sources:["sdk/init.ts"]},{code:"init_id_prefix_path_like",exit_code:2,stable:!0,sources:["sdk/init.ts"]},{code:"integrity_history_conflict_marker",exit_code:4,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_storage_history_conflict_markers"]},{code:"integrity_history_invalid_json",exit_code:2,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_history_unreadable",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_item_ahead_format_version",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_format_version_ahead_items"]},{code:"integrity_item_conflict_marker",exit_code:4,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_item_outdated_format_version",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_format_version_outdated_items"]},{code:"integrity_item_parse_failed",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_item_unreadable",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"invalid_argument_value",exit_code:2,stable:!0,sources:["cli/error-guidance.ts","core/item/priority.ts","core/shared/url-credentials.ts","core/telemetry/observability.ts","sdk/config.ts","sdk/context-intent-contracts.ts","sdk/dependencies.ts","sdk/governance/assurance-mutation-error.ts","sdk/history-redact.ts","sdk/lifecycle/create.ts","sdk/lifecycle/task-composition.ts","sdk/lifecycle/update-many.ts","sdk/lifecycle/update.ts","sdk/linked-artifacts.ts","sdk/query/next.ts","sdk/runtime-input.ts","sdk/runtime.ts","sdk/runtime/mutation-admission.ts","sdk/runtime/mutation-value-validation.ts","sdk/runtime/schema-preview.ts","sdk/test/run-phases.ts","sdk/workspace.ts"],emitting_commands:["*","create","next","task-composition","update","update-many"]},{code:"invalid_command_usage",exit_code:2,stable:!0,sources:["cli/error-guidance.ts","core/telemetry/observability.ts"]},{code:"invalid_event_cursor",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_event_cursor_mode",exit_code:2,sources:["cli/register-list-query.ts","sdk/mutation-events.ts","sdk/runtime-extended-actions.ts"]},{code:"invalid_event_follow_interval",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_event_limit",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_event_since",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_history_analytics_limit",exit_code:2,sources:["sdk/history-analytics.ts"]},{code:"invalid_history_analytics_minimum_sample",exit_code:2,sources:["sdk/history-analytics.ts"]},{code:"invalid_history_analytics_since",exit_code:2,sources:["sdk/history-analytics.ts"]},{code:"invalid_improvement_ledger",exit_code:1,sources:["sdk/improvement-ledger-validation.ts"]},{code:"invalid_improvement_metric",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_improvement_observation",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_improvement_observation_limit",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_improvement_observation_timestamp",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_provenance_predicate",exit_code:2,stable:!0,sources:["sdk/history-provenance.ts"]},{code:"invalid_query_cursor",exit_code:2,stable:!0,sources:["sdk/pagination.ts","sdk/query/window-pagination.ts"]},{code:"invalid_read_output_session",exit_code:2,sources:["sdk/read-output-session.ts"]},{code:"invalid_reproducible_process_environment",exit_code:2,sources:["sdk/reproducibility/process.ts"]},{code:"invalid_workspace_snapshot_target",exit_code:2,sources:["sdk/workspace-snapshot.ts"]},{code:"item_already_active",exit_code:4,sources:["sdk/lifecycle/update.ts"],emitting_commands:["update"]},{code:"item_already_exists",exit_code:4,stable:!0,sources:["sdk/lifecycle/create.ts"],emitting_commands:["create"]},{code:"item_deleted",exit_code:3,sources:["core/history/tombstone.ts"]},{code:"item_document_encoding_invalid",exit_code:4,sources:["core/store/item-store.ts"]},{code:"item_document_invalid",exit_code:1,stable:!0,sources:["core/item/item-format.ts"]},{code:"item_document_roundtrip_failed",exit_code:1,stable:!0,sources:["core/item/item-format.ts"]},{code:"item_format_version_unsupported",exit_code:4,sources:["core/item/item-format.ts"]},{code:"item_id_collision",exit_code:4,stable:!0,sources:["sdk/lifecycle/copy.ts"],emitting_commands:["copy"]},{code:"item_identity_ambiguous",exit_code:4,sources:["core/store/item-store.ts"]},{code:"item_identity_conflict",exit_code:4,sources:["sdk/governance/validate-history-drift.ts","sdk/lifecycle/item-revision.ts","sdk/merge/three-way.ts","sdk/query/declared-blockers.ts"]},{code:"item_identity_reserved",exit_code:4,sources:["core/history/history.ts"]},{code:"item_not_found",exit_code:3,stable:!0,sources:["cli/error-guidance.ts","core/store/item-store.ts","core/telemetry/observability.ts","sdk/governance/validate-history-drift.ts"]},{code:"item_revision_conflict",exit_code:4,sources:["core/store/item-mutation-precondition.ts"]},{code:"likely_duplicate",exit_code:4,stable:!0,sources:["sdk/similarity.ts"]},{code:"linked_artifact_mutation_conflict",exit_code:2,sources:["sdk/linked-artifacts.ts"]},{code:"linked_artifact_note_conflict",exit_code:4,sources:["sdk/linked-artifacts.ts"]},{code:"linked_artifact_note_key_misread",exit_code:2,sources:["sdk/linked-artifacts.ts"]},{code:"linked_resource_positional_value",exit_code:2,sources:["cli/error-guidance.ts"]},{code:"linked_test_command_immutable",exit_code:2,sources:["sdk/test/update.ts"]},{code:"linked_test_command_not_executable",exit_code:2,sources:["sdk/test/entry.ts"]},{code:"linked_test_context_invalid",exit_code:2,sources:["sdk/test/entry.ts"]},{code:"linked_test_patch_fields_unsupported",exit_code:2,sources:["sdk/test/update.ts"]},{code:"linked_test_remove_no_match",exit_code:3,sources:["sdk/test/execution.ts"]},{code:"linked_test_update_ambiguous",exit_code:2,sources:["sdk/test/update.ts"]},{code:"linked_test_update_no_match",exit_code:3,sources:["sdk/test/update.ts"]},{code:"linked_test_value_not_quoted",exit_code:1,stable:!0,sources:["cli/error-guidance.ts"]},{code:"list_source_incomplete",exit_code:1,stable:!0,sources:["sdk/query/list.ts"],emitting_commands:["list"]},{code:"local_package_archive_unsafe",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"local_source_not_found_bare_name",exit_code:3,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"lock_conflict",exit_code:4,stable:!0,sources:["cli/error-guidance.ts","core/lock/lock.ts","core/telemetry/observability.ts"]},{code:"lock_lost",exit_code:4,sources:["core/lock/lock.ts"]},{code:"lock_path_unsafe",exit_code:4,sources:["core/lock/lock-confinement.ts"]},{code:"locks_stale_count",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"locks_unreadable",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"malformed_plan_step_evidence",exit_code:2,stable:!0,sources:["sdk/lifecycle/plan.ts"],emitting_commands:["plan"]},{code:"managed_state_invalid",exit_code:2,sources:["sdk/extension/static-inventory.ts"]},{code:"managed_state_unreadable",exit_code:1,sources:["sdk/extension/static-inventory.ts"]},{code:"manifest_capabilities_absent",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"manifest_invalid",exit_code:2,sources:["sdk/extension/static-inventory.ts"]},{code:"manifest_unknown_key",exit_code:1,sources:["core/extensions/manifest-schema.ts"],owned_states:[{state:"author_workspace_manifest_declares_an_unknown_top_level_key",probe_id:"author-manifest-unknown-key",entrypoints:["health"],expected_exit_class:"generic_failure"}]},{code:"manifest_unreadable",exit_code:1,sources:["sdk/extension/static-inventory.ts"]},{code:"mcp_annotation_file_unavailable",exit_code:2,sources:["sdk/runtime-input.ts"]},{code:"mcp_stdin_unavailable",exit_code:2,sources:["sdk/annotations.ts"]},{code:"mcp_task_not_found_or_not_authorized",exit_code:3,sources:["sdk/mcp/tasks.ts"]},{code:"merge_artifacts_ignored",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"merge_bun_launcher_unavailable",exit_code:5,sources:["sdk/merge/install.ts"]},{code:"merge_conflict_markers_detected",exit_code:1,stable:!0,sources:["core/item/item-format.ts"],aliases:["history_merge_conflict_markers_detected"]},{code:"merge_decisions_unreviewed",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"merge_driver_configuration_drift",exit_code:1,sources:["core/diagnostics/remediation.ts"]}];export{e as PM_ERROR_CODE_CATALOG_PART_1};
1
+ const e=[{code:"acceptance_criteria_mutation_conflict",exit_code:2,sources:["sdk/lifecycle/update.ts"],emitting_commands:["update","update-many"]},{code:"acceptance_criteria_remove_unmatched",exit_code:3,sources:["sdk/lifecycle/update-many.ts","sdk/lifecycle/update.ts"],emitting_commands:["update","update-many"]},{code:"acceptance_criteria_semicolon_forbidden",exit_code:2,stable:!0,sources:["core/item/parse.ts"]},{code:"accepted_rejected_value",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"alias_collision",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"alias_target_missing",exit_code:1,sources:["sdk/cli-contracts/grammar-contracts.ts"]},{code:"already_claimed_by",exit_code:4,stable:!0,sources:["sdk/lifecycle/claim.ts"],emitting_commands:["claim"]},{code:"ambiguous_option_combination",exit_code:2,stable:!0,sources:["sdk/lifecycle/claim.ts","sdk/lifecycle/plan.ts"],emitting_commands:["claim","plan"]},{code:"annotation_alias_conflict",exit_code:2,sources:["cli/register-annotations.ts"]},{code:"annotation_entry_mismatch",exit_code:4,sources:["sdk/annotations.ts"]},{code:"annotation_expectation_invalid",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_expectation_without_target",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_flag_like_value",exit_code:2,stable:!0,sources:["sdk/annotations.ts"]},{code:"annotation_if_absent_without_append",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_message_without_text",exit_code:2,stable:!0,sources:["sdk/annotations.ts"]},{code:"annotation_text_compacted",exit_code:2,sources:["sdk/annotations.ts"]},{code:"annotation_text_source_conflict",exit_code:2,sources:["sdk/runtime-input.ts"]},{code:"annotation_transposed_subcommand",exit_code:2,sources:["cli/register-annotations.ts"]},{code:"append_empty_body",exit_code:2,stable:!0,sources:["sdk/lifecycle/append.ts"],emitting_commands:["append"]},{code:"assurance_registry_invalid",exit_code:1,sources:["sdk/governance/assurance.ts"]},{code:"bare_comma_entry_ambiguous",exit_code:2,sources:["core/item/parse.ts"]},{code:"blocker_identity_read_failed",exit_code:1,sources:["sdk/query/declared-blockers.ts"]},{code:"body_file_conflicts_with_body",exit_code:2,stable:!0,sources:["core/io/body-file.ts"]},{code:"body_file_missing_path",exit_code:2,stable:!0,sources:["core/io/body-file.ts"]},{code:"body_file_unreadable",exit_code:3,stable:!0,sources:["core/io/body-file.ts"]},{code:"budget_exceeded",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"bulk_create_route",exit_code:2,sources:["cli/register-mutation.ts"]},{code:"bulk_ids_input_empty",exit_code:2,sources:["core/io/bulk-ids-input.ts","sdk/history-compact.ts","sdk/history-mcp.ts"],owned_states:[{state:"bulk_ids_stdin_contains_no_nonempty_ids",probe_id:"bulk-ids-stdin-empty",entrypoints:["update-many"],expected_exit_class:"usage"}]},{code:"bulk_ids_input_missing_path",exit_code:2,sources:["core/io/bulk-ids-input.ts"],owned_states:[{state:"bulk_ids_file_token_omits_its_path",probe_id:"bulk-ids-file-path-missing",entrypoints:["update-many"],expected_exit_class:"usage"}]},{code:"bulk_ids_input_unreadable",exit_code:3,sources:["core/io/bulk-ids-input.ts"],owned_states:[{state:"bulk_ids_file_path_cannot_be_read",probe_id:"bulk-ids-file-unreadable",entrypoints:["update-many"],expected_exit_class:"not_found"}]},{code:"bundle_integrity_torn_install",exit_code:1,stable:!0,sources:["cli/bundle-integrity.ts"]},{code:"capability_undeclared",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"capability_unused",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"child_projection_item_bound_exceeded",exit_code:1,stable:!0,sources:["sdk/item-children.ts"]},{code:"close_reason_required",exit_code:2,stable:!0,sources:["sdk/lifecycle-policy.ts","sdk/lifecycle/close-many.ts"],emitting_commands:["*","close-many"]},{code:"close_through_update",exit_code:1,stable:!0,sources:["core/telemetry/observability.ts"]},{code:"close_validation_deferred_fields",exit_code:2,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"close_validation_missing_fields",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"collected_zero_items",exit_code:1,stable:!0,sources:["sdk/test/execution-receipts.ts"]},{code:"collection_transposed_subcommand",exit_code:2,sources:["cli/error-guidance.ts"]},{code:"command_failed",exit_code:1,stable:!0,sources:["cli/error-guidance.ts"]},{code:"command_namespace",exit_code:2,stable:!0,sources:["sdk/cli-contracts/runtime-contracts.ts"]},{code:"command_override_conflict",exit_code:4,stable:!0,sources:["sdk/compose.ts"]},{code:"config_duplicate",exit_code:1,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"config_key_unknown",exit_code:2,stable:!0,sources:["core/profile/profile-lint.ts","sdk/config.ts"]},{code:"config_value_invalid",exit_code:2,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"conflicting_lifecycle_owner",exit_code:2,stable:!0,sources:["cli/register-operations.ts"]},{code:"context_evaluation_read_incomplete",exit_code:2,sources:["sdk/context-relevance.ts"]},{code:"context_signal_store_invalid",exit_code:2,sources:["sdk/context-signal-store.ts"]},{code:"context_signal_store_stale",exit_code:1,sources:["sdk/context-signal-store.ts"]},{code:"context_signal_store_write_failed",exit_code:1,sources:["sdk/context-signal-store.ts"]},{code:"context_takes_no_item_argument",exit_code:1,stable:!0,sources:["cli/error-guidance.ts"]},{code:"core_item_field_requires_dedicated_flag",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"create_deferral_conflict",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_deferral_field_unsupported",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_deferral_fields_required",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_deferral_reason_required",exit_code:2,sources:["sdk/lifecycle/create-deferrals.ts"],emitting_commands:["create"]},{code:"create_positional_type_without_title",exit_code:2,stable:!0,sources:["cli/register-mutation.ts"]},{code:"dependency_cardinality_created",exit_code:2,sources:["sdk/graph/cardinality-integrity.ts"]},{code:"dependency_edge_not_allowed",exit_code:2,stable:!0,sources:["sdk/dependency-flag-validation.ts"]},{code:"dependency_flag_value_invalid",exit_code:2,sources:["sdk/dependency-flag-validation.ts"]},{code:"dependency_remove_no_match",exit_code:3,sources:["sdk/lifecycle/dependency-removal.ts"],emitting_commands:["update"]},{code:"dependency_target_not_found",exit_code:3,sources:["sdk/dependency-flag-validation.ts"]},{code:"dependency_temporal_order_invalid",exit_code:2,sources:["sdk/dependency-flag-validation.ts"]},{code:"duplicate_canonical_flag",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"duplicate_command",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"duplicate_destination",exit_code:1,sources:["sdk/cli-contracts/grammar-contracts.ts"]},{code:"duplicate_edge",exit_code:1,stable:!0,sources:["sdk/graph/remediation.ts"]},{code:"duplicate_observation",exit_code:1,sources:["sdk/flag-invocation-contracts.ts"]},{code:"duplicate_probe",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"duplicate_sweep_cost_limit",exit_code:4,stable:!0,sources:["sdk/query/duplicate-candidates.ts"],emitting_commands:["duplicate-candidates"]},{code:"duplicate_target_circular",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"duplicate_target_is_duplicate",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"duplicate_target_missing",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"duplicate_target_self",exit_code:2,stable:!0,sources:["sdk/lifecycle/close.ts"],emitting_commands:["close"]},{code:"empty_corpus",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"empty_surface",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"error_code_mismatch",exit_code:1,sources:["sdk/agent/refusal-closure.ts","sdk/agent/tracker-preflight-contracts.ts"]},{code:"event_cursor_query_mismatch",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"event_history_integrity_failed",exit_code:1,sources:["core/history/event-index.ts"]},{code:"event_index_unavailable",exit_code:1,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"exit_code_mismatch",exit_code:1,sources:["sdk/agent/tracker-preflight-contracts.ts"]},{code:"expect_hash_background_unsupported",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_invalid",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_invocation_rewritten",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_requires_mutation",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expect_hash_target_required",exit_code:2,sources:["sdk/lifecycle/item-revision.ts"]},{code:"expected_revision_duplicate",exit_code:2,sources:["core/store/item-mutation-precondition.ts"]},{code:"expected_revision_scope_conflict",exit_code:2,sources:["core/store/item-mutation-precondition.ts"]},{code:"extension_command_activation_failed",exit_code:1,stable:!0,sources:["cli/commander-usage.ts"]},{code:"extension_dependency_name_unsafe",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"extension_dependency_spec_invalid",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"extension_dependency_version_unsafe",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"extension_flag_value_invalid",exit_code:2,sources:["sdk/extension/command-options.ts"]},{code:"extension_install_incomplete_source_scan",exit_code:2,sources:["sdk/extension/install-plan.ts"]},{code:"extension_install_rollback_failed",exit_code:1,sources:["sdk/extension/install-snapshot.ts"]},{code:"extension_install_soft_failed",exit_code:1,stable:!0,sources:["cli/register-setup.ts"]},{code:"extension_install_source_contains_destination",exit_code:2,stable:!0,sources:["sdk/extension/install-runtime.ts"]},{code:"extension_item_field_reserved",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"extension_item_field_type_conflict",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"extension_item_field_unknown",exit_code:2,stable:!0,sources:["core/extensions/item-fields.ts"]},{code:"extension_mutation_guard_failed",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_mutation_guard_invalid_decision",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_mutation_guard_invalid_denial",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_mutation_guard_timed_out",exit_code:4,stable:!0,sources:["core/extensions/extension-hook-runtime.ts"]},{code:"extension_option_disabled",exit_code:2,sources:["sdk/extension/command-options.ts"]},{code:"extension_option_spelling_conflict",exit_code:2,sources:["sdk/extension/command-options.ts"]},{code:"extension_read_output_invalid",exit_code:2,sources:["sdk/read-output/extension.ts"]},{code:"extension_update_health_partial_coverage",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"extensions_unreadable",exit_code:1,sources:["sdk/extension/static-inventory.ts"]},{code:"field_duplicate",exit_code:1,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"field_flag_invalid",exit_code:2,sources:["core/profile/profile-lint.ts"]},{code:"field_invalid",exit_code:2,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"field_mcp_input_collision",exit_code:1,stable:!0,sources:["core/profile/profile-lint.ts"]},{code:"field_option_collision",exit_code:1,sources:["core/profile/profile-lint.ts"]},{code:"finalization_invalid_document",exit_code:2,sources:["sdk/transactions/item-finalization.ts"]},{code:"github_source_entry_unbuilt",exit_code:2,stable:!0,sources:["sdk/extension/shared.ts"]},{code:"hierarchy_cardinality_created",exit_code:4,sources:["sdk/graph/hierarchy-integrity.ts"]},{code:"hierarchy_cycle_created",exit_code:4,sources:["sdk/graph/hierarchy-integrity.ts"]},{code:"hierarchy_parent_divergence_created",exit_code:4,sources:["sdk/graph/hierarchy-integrity.ts"]},{code:"history_append_only_repair_unavailable",exit_code:4,sources:["sdk/history/append-only-repair.ts"]},{code:"history_author_acknowledge_plan_conflict",exit_code:4,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_plan_fingerprint_required",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_preview_limit_invalid",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_required_values_missing",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_selector_conflict",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_selector_required",exit_code:2,stable:!0,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_target_not_actionable",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_author_acknowledge_target_unreadable",exit_code:2,sources:["sdk/author-attribution.ts"]},{code:"history_baseline_unavailable",exit_code:1,sources:["core/history/projection.ts"]},{code:"history_compact_boundary_bridged",exit_code:2,sources:["sdk/history-compact.ts"]},{code:"history_drift_chain_mismatch",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_chain_mismatches"]},{code:"history_drift_chain_unbridgeable",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"history_drift_hash_mismatch",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_hash_mismatches"]},{code:"history_drift_merge_receipt",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"history_drift_missing_stream",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_missing_streams"]},{code:"history_drift_unreadable_stream",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_unreadable_streams"]},{code:"history_drift_unrepairable_stream",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"history_drift_version_skew",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_drift_version_skews"]},{code:"history_json_invalid",exit_code:1,sources:["core/history/read.ts"]},{code:"history_merge_conflict_markers_detected",exit_code:1,stable:!0,sources:["core/history/read.ts"],canonical_code:"merge_conflict_markers_detected"},{code:"history_record_integrity_invalid",exit_code:4,sources:["sdk/history/reanchor-refusal.ts"]},{code:"history_record_invalid",exit_code:1,sources:["core/history/read.ts"]},{code:"history_record_version_unsupported",exit_code:4,sources:["sdk/history/reanchor-refusal.ts"]},{code:"history_redact_bridge_unlocated",exit_code:1,sources:["sdk/history-redact.ts"]},{code:"history_replay_invalid",exit_code:1,sources:["core/history/projection.ts","core/history/tombstone.ts"]},{code:"history_salvage_refused",exit_code:4,sources:["sdk/history/salvage.ts"]},{code:"history_stream_over_compact_threshold",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"history_target_out_of_range",exit_code:1,stable:!0,sources:["core/history/projection.ts"]},{code:"history_timestamp_invalid",exit_code:1,sources:["core/history/event-index.ts","core/history/history.ts"]},{code:"history_union_rebase_conflict",exit_code:4,sources:["sdk/merge/history-scalar-rebase.ts"]},{code:"history_unknown_author_events",exit_code:2,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_history_unknown_author_events"]},{code:"history_version_mapping_unavailable",exit_code:2,sources:["core/history/version-address.ts"]},{code:"history_version_pruned",exit_code:2,sources:["core/history/projection.ts"]},{code:"history_version_unreconstructable",exit_code:2,sources:["core/history/projection.ts"]},{code:"host_environment_capacity_fault",exit_code:1,sources:["core/fs/host-environment-errors.ts"]},{code:"host_environment_operation_invalid",exit_code:2,sources:["core/fs/host-environment-errors.ts"]},{code:"host_environment_permission_fault",exit_code:1,sources:["core/fs/host-environment-errors.ts"]},{code:"host_environment_resource_fault",exit_code:1,sources:["core/fs/host-environment-errors.ts"]},{code:"improvement_metric_contract_conflict",exit_code:4,sources:["sdk/improvement-ledger.ts"]},{code:"improvement_observation_conflict",exit_code:4,sources:["sdk/improvement-ledger.ts"]},{code:"in_progress_idle",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"in_progress_unowned",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"incomplete_allowed_values",exit_code:1,sources:["sdk/agent/refusal-closure.ts"]},{code:"inconsistent_concept_kind",exit_code:1,sources:["sdk/cli-contracts/flag-lexicon-contracts.ts"]},{code:"init_existing_settings_requires_force",exit_code:2,stable:!0,sources:["sdk/init.ts"]},{code:"init_gitignore_unwritable",exit_code:1,stable:!0,sources:["sdk/workspace.ts"]},{code:"init_id_prefix_conflict",exit_code:2,stable:!0,sources:["sdk/init.ts"]},{code:"init_id_prefix_path_like",exit_code:2,stable:!0,sources:["sdk/init.ts"]},{code:"integrity_history_conflict_marker",exit_code:4,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_storage_history_conflict_markers"]},{code:"integrity_history_invalid_json",exit_code:2,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_history_unreadable",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_item_ahead_format_version",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_format_version_ahead_items"]},{code:"integrity_item_conflict_marker",exit_code:4,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_item_outdated_format_version",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"],aliases:["validate_format_version_outdated_items"]},{code:"integrity_item_parse_failed",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"integrity_item_unreadable",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"invalid_argument_value",exit_code:2,stable:!0,sources:["cli/error-guidance.ts","core/item/priority.ts","core/shared/url-credentials.ts","core/telemetry/observability.ts","sdk/config.ts","sdk/context-intent-contracts.ts","sdk/dependencies.ts","sdk/governance/assurance-mutation-error.ts","sdk/history-redact.ts","sdk/lifecycle/create.ts","sdk/lifecycle/task-composition.ts","sdk/lifecycle/update-many.ts","sdk/lifecycle/update.ts","sdk/linked-artifacts.ts","sdk/query/next.ts","sdk/runtime-input.ts","sdk/runtime.ts","sdk/runtime/mutation-admission.ts","sdk/runtime/mutation-value-validation.ts","sdk/runtime/schema-preview.ts","sdk/test/run-phases.ts","sdk/workspace.ts"],emitting_commands:["*","create","next","task-composition","update","update-many"]},{code:"invalid_command_usage",exit_code:2,stable:!0,sources:["cli/error-guidance.ts","core/telemetry/observability.ts"]},{code:"invalid_event_cursor",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_event_cursor_mode",exit_code:2,sources:["cli/register-list-query.ts","sdk/mutation-events.ts","sdk/runtime-extended-actions.ts"]},{code:"invalid_event_follow_interval",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_event_limit",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_event_since",exit_code:2,stable:!0,sources:["sdk/mutation-events.ts"]},{code:"invalid_history_analytics_limit",exit_code:2,sources:["sdk/history-analytics.ts"]},{code:"invalid_history_analytics_minimum_sample",exit_code:2,sources:["sdk/history-analytics.ts"]},{code:"invalid_history_analytics_since",exit_code:2,sources:["sdk/history-analytics.ts"]},{code:"invalid_improvement_ledger",exit_code:1,sources:["sdk/improvement-ledger-validation.ts"]},{code:"invalid_improvement_metric",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_improvement_observation",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_improvement_observation_limit",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_improvement_observation_timestamp",exit_code:2,sources:["sdk/improvement-ledger.ts"]},{code:"invalid_provenance_predicate",exit_code:2,stable:!0,sources:["sdk/history-provenance.ts"]},{code:"invalid_query_cursor",exit_code:2,stable:!0,sources:["sdk/pagination.ts","sdk/query/window-pagination.ts"]},{code:"invalid_read_output_session",exit_code:2,sources:["sdk/read-output-session.ts"]},{code:"invalid_reproducible_process_environment",exit_code:2,sources:["sdk/reproducibility/process.ts"]},{code:"invalid_workspace_snapshot_target",exit_code:2,sources:["sdk/workspace-snapshot.ts"]},{code:"item_already_active",exit_code:4,sources:["sdk/lifecycle/update.ts"],emitting_commands:["update"]},{code:"item_already_exists",exit_code:4,stable:!0,sources:["sdk/lifecycle/create.ts"],emitting_commands:["create"]},{code:"item_deleted",exit_code:3,sources:["core/history/tombstone.ts"]},{code:"item_document_encoding_invalid",exit_code:4,sources:["core/store/item-store.ts"]},{code:"item_document_invalid",exit_code:1,stable:!0,sources:["core/item/item-format.ts"]},{code:"item_document_roundtrip_failed",exit_code:1,stable:!0,sources:["core/item/item-format.ts"]},{code:"item_format_version_unsupported",exit_code:4,sources:["core/item/item-format.ts"]},{code:"item_id_collision",exit_code:4,stable:!0,sources:["sdk/lifecycle/copy.ts"],emitting_commands:["copy"]},{code:"item_identity_ambiguous",exit_code:4,sources:["core/store/item-store.ts"]},{code:"item_identity_conflict",exit_code:4,sources:["sdk/governance/validate-history-drift.ts","sdk/lifecycle/item-revision.ts","sdk/merge/three-way.ts","sdk/query/declared-blockers.ts"]},{code:"item_identity_reserved",exit_code:4,sources:["core/history/history.ts"]},{code:"item_not_found",exit_code:3,stable:!0,sources:["cli/error-guidance.ts","core/store/item-store.ts","core/telemetry/observability.ts","sdk/governance/validate-history-drift.ts"]},{code:"item_revision_conflict",exit_code:4,sources:["core/store/item-mutation-precondition.ts"]},{code:"likely_duplicate",exit_code:4,stable:!0,sources:["sdk/similarity.ts"]},{code:"linked_artifact_mutation_conflict",exit_code:2,sources:["sdk/linked-artifacts.ts"]},{code:"linked_artifact_note_conflict",exit_code:4,sources:["sdk/linked-artifacts.ts"]},{code:"linked_artifact_note_key_misread",exit_code:2,sources:["sdk/linked-artifacts.ts"]},{code:"linked_resource_positional_value",exit_code:2,sources:["cli/error-guidance.ts"]},{code:"linked_test_command_immutable",exit_code:2,sources:["sdk/test/update.ts"]},{code:"linked_test_command_not_executable",exit_code:2,sources:["sdk/test/entry.ts"]},{code:"linked_test_context_invalid",exit_code:2,sources:["sdk/test/entry.ts"]},{code:"linked_test_patch_fields_unsupported",exit_code:2,sources:["sdk/test/update.ts"]},{code:"linked_test_remove_no_match",exit_code:3,sources:["sdk/test/execution.ts"]},{code:"linked_test_update_ambiguous",exit_code:2,sources:["sdk/test/update.ts"]},{code:"linked_test_update_no_match",exit_code:3,sources:["sdk/test/update.ts"]},{code:"linked_test_value_not_quoted",exit_code:1,stable:!0,sources:["cli/error-guidance.ts"]},{code:"list_source_incomplete",exit_code:1,stable:!0,sources:["sdk/query/list.ts"],emitting_commands:["list"]},{code:"local_package_archive_unsafe",exit_code:2,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"local_source_not_found_bare_name",exit_code:3,stable:!0,sources:["sdk/extension/install-sources.ts"]},{code:"lock_conflict",exit_code:4,stable:!0,sources:["cli/error-guidance.ts","core/lock/lock.ts","core/telemetry/observability.ts"]},{code:"lock_lost",exit_code:4,sources:["core/lock/lock.ts"]},{code:"lock_path_unsafe",exit_code:4,sources:["core/lock/lock-confinement.ts"]},{code:"locks_stale_count",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"locks_unreadable",exit_code:1,stable:!0,sources:["core/diagnostics/remediation.ts"]},{code:"malformed_plan_step_evidence",exit_code:2,stable:!0,sources:["sdk/lifecycle/plan.ts"],emitting_commands:["plan"]},{code:"managed_state_invalid",exit_code:2,sources:["sdk/extension/static-inventory.ts"]},{code:"managed_state_unreadable",exit_code:1,sources:["sdk/extension/static-inventory.ts"]},{code:"manifest_capabilities_absent",exit_code:1,stable:!0,sources:["sdk/compose.ts"]},{code:"manifest_invalid",exit_code:2,sources:["sdk/extension/static-inventory.ts"]},{code:"manifest_unknown_key",exit_code:1,sources:["core/extensions/manifest-schema.ts"],owned_states:[{state:"author_workspace_manifest_declares_an_unknown_top_level_key",probe_id:"author-manifest-unknown-key",entrypoints:["health"],expected_exit_class:"generic_failure"}]},{code:"manifest_unreadable",exit_code:1,sources:["sdk/extension/static-inventory.ts"]},{code:"mcp_annotation_file_unavailable",exit_code:2,sources:["sdk/runtime-input.ts"]},{code:"mcp_stdin_unavailable",exit_code:2,sources:["sdk/annotations.ts"]},{code:"mcp_task_not_found_or_not_authorized",exit_code:3,sources:["sdk/mcp/tasks.ts"]},{code:"merge_artifacts_ignored",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"merge_bun_launcher_unavailable",exit_code:5,sources:["sdk/merge/install.ts"]},{code:"merge_conflict_markers_detected",exit_code:1,stable:!0,sources:["core/item/item-format.ts"],aliases:["history_merge_conflict_markers_detected"]},{code:"merge_decisions_unreviewed",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"merge_driver_configuration_drift",exit_code:1,sources:["core/diagnostics/remediation.ts"]},{code:"merge_driver_configuration_missing",exit_code:1,sources:["core/diagnostics/remediation.ts"]}];export{e as PM_ERROR_CODE_CATALOG_PART_1};
2
2
  //# sourceMappingURL=generated-error-code-catalog-part-1.js.map