@unbrained/pm-cli 2026.11.29 → 2026.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/commander-usage.js +10 -10
  3. package/dist/cli/error-guidance.js +5 -5
  4. package/dist/cli/extension-command-help.js +6 -6
  5. package/dist/cli/help-json-payload.js +7 -7
  6. package/dist/cli/main.js +5 -5
  7. package/dist/cli/register-list-query.js +10 -10
  8. package/dist/cli/register-mutation.js +3 -3
  9. package/dist/cli/runtime/invocation-command-path.js +2 -0
  10. package/dist/cli/runtime/read-output-mutation-retry.js +1 -1
  11. package/dist/cli-bundle/bundle-manifest.json +1 -1
  12. package/dist/cli-bundle/chunks/{chunk-JQHLOSSS.js → chunk-3HKPVOAN.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-ZSBPE36C.js → chunk-3KEMIPKG.js} +2 -2
  14. package/dist/cli-bundle/chunks/{chunk-JFPCL45G.js → chunk-4YQMQOUO.js} +2 -2
  15. package/dist/cli-bundle/chunks/{chunk-EYEQC3L2.js → chunk-4YYFY33T.js} +2 -2
  16. package/dist/cli-bundle/chunks/chunk-A5ZEMOVR.js +2 -0
  17. package/dist/cli-bundle/chunks/{chunk-WLZ5KVM2.js → chunk-AHV3CSQG.js} +2 -2
  18. package/dist/cli-bundle/chunks/chunk-AJLU6KLW.js +2 -0
  19. package/dist/cli-bundle/chunks/{chunk-R6M5OGJH.js → chunk-C6WM6ZN4.js} +3 -3
  20. package/dist/cli-bundle/chunks/chunk-CBUC4X7Q.js +127 -0
  21. package/dist/cli-bundle/chunks/{chunk-K3MVVDLN.js → chunk-CWPR234D.js} +2 -2
  22. package/dist/cli-bundle/chunks/chunk-I4SPJQQI.js +3 -0
  23. package/dist/cli-bundle/chunks/{chunk-VI3A7UZ2.js → chunk-L2ZSSMYY.js} +2 -2
  24. package/dist/cli-bundle/chunks/{chunk-DBASKWBO.js → chunk-MZZ4ZJ5Z.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-CV2B4JUB.js → chunk-NA6D75V5.js} +2 -2
  26. package/dist/cli-bundle/chunks/chunk-NRQCBUYD.js +113 -0
  27. package/dist/cli-bundle/chunks/{chunk-ZK4CY24V.js → chunk-OBPO6V7H.js} +2 -2
  28. package/dist/cli-bundle/chunks/{chunk-3US5T6B2.js → chunk-OKEJ4U2I.js} +7 -7
  29. package/dist/cli-bundle/chunks/{chunk-3E53F7QY.js → chunk-OXC5KBIQ.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-NLHNB2L3.js → chunk-PCDTWL6V.js} +2 -2
  31. package/dist/cli-bundle/chunks/{chunk-LQEB6GSY.js → chunk-Q6GLSAJY.js} +2 -2
  32. package/dist/cli-bundle/chunks/{chunk-3TK2YOVB.js → chunk-Q6K7HWZ7.js} +2 -2
  33. package/dist/cli-bundle/chunks/chunk-QDV7S2QS.js +2 -0
  34. package/dist/cli-bundle/chunks/{chunk-Q6GIFUCW.js → chunk-SY5C3U32.js} +3 -3
  35. package/dist/cli-bundle/chunks/{chunk-L7HON3BE.js → chunk-U7RBJGLF.js} +23 -23
  36. package/dist/cli-bundle/chunks/chunk-WSEIEDEK.js +2 -0
  37. package/dist/cli-bundle/chunks/{chunk-FRYNDVLN.js → chunk-XME6GIFQ.js} +2 -2
  38. package/dist/cli-bundle/chunks/{chunk-WNB62BGK.js → chunk-YSVOXCYH.js} +2 -2
  39. package/dist/cli-bundle/chunks/{chunk-KCR4NF2A.js → chunk-ZL6J6JYT.js} +6 -6
  40. package/dist/cli-bundle/chunks/{field-option-collisions-OZE43TOH.js → field-option-collisions-BBGTV7AD.js} +2 -2
  41. package/dist/cli-bundle/chunks/item-revision-3LENTXYF.js +2 -0
  42. package/dist/cli-bundle/chunks/item-transaction-66RDV7PH.js +2 -0
  43. package/dist/cli-bundle/chunks/{linked-resource-value-list-2655COY2.js → linked-resource-value-list-E2DX52LY.js} +2 -2
  44. package/dist/cli-bundle/chunks/{mutation-actor-QOKPDYM4.js → mutation-actor-NHN33ITJ.js} +2 -2
  45. package/dist/cli-bundle/chunks/{mutation-admission-JNJHB3E6.js → mutation-admission-PGKJTCG6.js} +2 -2
  46. package/dist/cli-bundle/chunks/{register-list-query-YGVUE4YZ.js → register-list-query-7S5QWDTI.js} +11 -11
  47. package/dist/cli-bundle/chunks/{register-mutation-3JVZQDHH.js → register-mutation-2F6JUBST.js} +5 -5
  48. package/dist/cli-bundle/chunks/{register-operations-LCHUHKRA.js → register-operations-ET3UKPYK.js} +2 -2
  49. package/dist/cli-bundle/chunks/{register-setup-IJ7M3VUK.js → register-setup-I63QTFCU.js} +2 -2
  50. package/dist/cli-bundle/chunks/{stage-7BD7U2BX.js → stage-4ZCF74G4.js} +2 -2
  51. package/dist/cli-bundle/focused-chunks/{chunk-NO5MUY4I.js → chunk-2DGKVXFT.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/chunk-2UWKU2BQ.js +3 -0
  53. package/dist/cli-bundle/focused-chunks/{chunk-42SU4LK3.js → chunk-4SCFAWAW.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/{chunk-LSVRZ4KQ.js → chunk-6BKT6XQN.js} +2 -2
  55. package/dist/cli-bundle/focused-chunks/chunk-6IY5CVGJ.js +2 -0
  56. package/dist/cli-bundle/focused-chunks/chunk-7A6SEZEY.js +4 -0
  57. package/dist/cli-bundle/focused-chunks/{chunk-LKTRICZR.js → chunk-BHNBPCHP.js} +2 -2
  58. package/dist/cli-bundle/focused-chunks/{chunk-PPCBCPIZ.js → chunk-EQCQTYKO.js} +2 -2
  59. package/dist/cli-bundle/focused-chunks/{chunk-NNLENKU7.js → chunk-HTDYNY4L.js} +2 -2
  60. package/dist/cli-bundle/focused-chunks/{chunk-S5VG7RFY.js → chunk-JPZGC3W4.js} +5 -5
  61. package/dist/cli-bundle/focused-chunks/{chunk-ACTBMSCH.js → chunk-KNBGHCIP.js} +3 -3
  62. package/dist/cli-bundle/focused-chunks/chunk-N64AC5G6.js +100 -0
  63. package/dist/cli-bundle/focused-chunks/{chunk-EUDAUT6T.js → chunk-OG57ESZK.js} +2 -2
  64. package/dist/cli-bundle/focused-chunks/{chunk-2CQFGJQ6.js → chunk-P2H3GTJK.js} +2 -2
  65. package/dist/cli-bundle/focused-chunks/{chunk-QTV6UE2Q.js → chunk-PT7RT3T6.js} +26 -26
  66. package/dist/cli-bundle/focused-chunks/chunk-QZRYGYTI.js +2 -0
  67. package/dist/cli-bundle/focused-chunks/{chunk-BPOU2S44.js → chunk-SQ72CVUH.js} +2 -2
  68. package/dist/cli-bundle/focused-chunks/chunk-SQMOF65W.js +2 -0
  69. package/dist/cli-bundle/focused-chunks/chunk-T3ILWAEV.js +2 -0
  70. package/dist/cli-bundle/focused-chunks/{chunk-KWKPX36T.js → chunk-TR22GU7M.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/{chunk-TSZVCALS.js → chunk-TXTPAFHJ.js} +2 -2
  72. package/dist/cli-bundle/focused-chunks/chunk-VK3IE3TS.js +29 -0
  73. package/dist/cli-bundle/focused-chunks/{chunk-GTUPHXKR.js → chunk-VQIC3UZB.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/{chunk-S4AC7OMI.js → chunk-W4JMV7GF.js} +2 -2
  75. package/dist/cli-bundle/focused-chunks/{field-option-collisions-HABQYZMQ.js → field-option-collisions-2C6DLUC4.js} +2 -2
  76. package/dist/cli-bundle/focused-chunks/item-revision-723XCQPS.js +2 -0
  77. package/dist/cli-bundle/focused-chunks/{item-transaction-YZ2PUPGM.js → item-transaction-2K4SFLJ7.js} +2 -2
  78. package/dist/cli-bundle/focused-chunks/{mutation-actor-DJ2VRLKG.js → mutation-actor-DJMZUIZI.js} +2 -2
  79. package/dist/cli-bundle/focused-chunks/mutation-admission-SDWQVVHN.js +2 -0
  80. package/dist/cli-bundle/focused-chunks/{stage-FEJT2UCG.js → stage-QBZIK3T5.js} +2 -2
  81. package/dist/cli-bundle/main.js +27 -27
  82. package/dist/cli-bundle/sdk-authoring.js +1 -1
  83. package/dist/cli-bundle/sdk-contracts.js +1 -1
  84. package/dist/cli-bundle/sdk-core.js +1 -1
  85. package/dist/cli-bundle/sdk-governance.js +1 -1
  86. package/dist/cli-bundle/sdk-graph.js +1 -1
  87. package/dist/cli-bundle/sdk-merge.js +63 -63
  88. package/dist/cli-bundle/sdk-query.js +1 -1
  89. package/dist/cli-bundle/sdk-runtime.js +1 -1
  90. package/dist/cli-bundle/sdk-testing.js +1 -1
  91. package/dist/cli-bundle/sdk.js +2 -2
  92. package/dist/core/extensions/reserved-host-flags.js +1 -1
  93. package/dist/core/shared/secret-rules.d.ts +86 -12
  94. package/dist/core/shared/secret-rules.js +7 -5
  95. package/dist/core/shared/url-credentials.d.ts +4 -2
  96. package/dist/core/shared/url-credentials.js +1 -1
  97. package/dist/sdk/cli-bootstrap.js +1 -1
  98. package/dist/sdk/cli-contracts/flag-contracts.d.ts +50 -0
  99. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  100. package/dist/sdk/cli-contracts/runtime-contracts.d.ts +3 -1
  101. package/dist/sdk/cli-contracts/runtime-contracts.js +1 -1
  102. package/dist/sdk/context-intent-contracts.js +1 -1
  103. package/dist/sdk/extension/command-options.js +1 -1
  104. package/dist/sdk/lifecycle/expect-hash-admission.d.ts +15 -0
  105. package/dist/sdk/lifecycle/expect-hash-admission.js +2 -0
  106. package/dist/sdk/lifecycle/item-revision.d.ts +4 -1
  107. package/dist/sdk/lifecycle/item-revision.js +1 -1
  108. package/dist/sdk/mutation-guard.js +1 -1
  109. package/dist/sdk/output-contracts.js +1 -1
  110. package/dist/sdk/output-projection.d.ts +1 -1
  111. package/dist/sdk/output-projection.js +1 -1
  112. package/dist/sdk/public-surface.json +1 -1
  113. package/dist/sdk/query/aggregate.js +1 -1
  114. package/dist/sdk/query/context.js +1 -1
  115. package/dist/sdk/query/list.js +1 -1
  116. package/dist/sdk/query/next.js +1 -1
  117. package/dist/sdk/query/search-contracts.js +1 -1
  118. package/dist/sdk/read-output/surfaces.js +1 -1
  119. package/dist/sdk/read-output-budget.d.ts +1 -1
  120. package/dist/sdk/read-output-budget.js +1 -1
  121. package/dist/sdk/read-output-contracts.js +1 -1
  122. package/dist/sdk/read-output-rows.js +1 -1
  123. package/docs/COMMANDS.md +37 -0
  124. package/docs/CONFIGURATION.md +22 -3
  125. package/docs/MUTATION_INTEGRITY.md +226 -10
  126. package/docs/READ_OUTPUT_CONTRACTS.md +5 -0
  127. package/docs/SDK.md +35 -9
  128. package/docs/agent-task-token-baseline.json +1 -1
  129. package/marketplace.json +1 -1
  130. package/package.json +1 -1
  131. package/packages/pm-beads/package.json +1 -1
  132. package/packages/pm-calendar/package.json +1 -1
  133. package/packages/pm-command-kit/package.json +1 -1
  134. package/packages/pm-digital-twin/package.json +1 -1
  135. package/packages/pm-governance-audit/package.json +1 -1
  136. package/packages/pm-guide-shell/package.json +1 -1
  137. package/packages/pm-kanban/package.json +1 -1
  138. package/packages/pm-lifecycle-hooks/package.json +1 -1
  139. package/packages/pm-linked-test-adapters/package.json +1 -1
  140. package/packages/pm-search-advanced/package.json +1 -1
  141. package/packages/pm-templates/package.json +1 -1
  142. package/packages/pm-todos/package.json +1 -1
  143. package/packages/pm-vcs/package.json +1 -1
  144. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  145. package/plugins/pm-claude/package.json +1 -1
  146. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  147. package/plugins/pm-codex/package.json +1 -1
  148. package/plugins/pm-codex/plugin.json +1 -1
  149. package/runtime-dependencies.json +1 -1
  150. package/dist/cli-bundle/chunks/chunk-4EBHZBM2.js +0 -2
  151. package/dist/cli-bundle/chunks/chunk-CNZOC6JD.js +0 -2
  152. package/dist/cli-bundle/chunks/chunk-JV7LREUF.js +0 -3
  153. package/dist/cli-bundle/chunks/chunk-NRCGGNOE.js +0 -2
  154. package/dist/cli-bundle/chunks/chunk-PY6A7ULK.js +0 -125
  155. package/dist/cli-bundle/chunks/chunk-RWHS77ME.js +0 -113
  156. package/dist/cli-bundle/chunks/chunk-SV27NNXQ.js +0 -2
  157. package/dist/cli-bundle/chunks/item-revision-3WXNNFLP.js +0 -2
  158. package/dist/cli-bundle/chunks/item-transaction-DJ5GAITL.js +0 -2
  159. package/dist/cli-bundle/focused-chunks/chunk-5NSWNLFE.js +0 -2
  160. package/dist/cli-bundle/focused-chunks/chunk-BPBKHY6H.js +0 -100
  161. package/dist/cli-bundle/focused-chunks/chunk-BZ3PUUPG.js +0 -2
  162. package/dist/cli-bundle/focused-chunks/chunk-KLOHZNJ4.js +0 -2
  163. package/dist/cli-bundle/focused-chunks/chunk-MYWUMVCZ.js +0 -4
  164. package/dist/cli-bundle/focused-chunks/chunk-NZA2LP4Y.js +0 -27
  165. package/dist/cli-bundle/focused-chunks/chunk-TX24L7RQ.js +0 -3
  166. package/dist/cli-bundle/focused-chunks/chunk-WJAUHPXD.js +0 -2
  167. package/dist/cli-bundle/focused-chunks/item-revision-YH5R7YPW.js +0 -2
  168. package/dist/cli-bundle/focused-chunks/mutation-admission-3SECKVKY.js +0 -2
@@ -1,2 +1,2 @@
1
- import{READ_OUTPUT_DIMENSION_FLAGS as wt,READ_OUTPUT_COMPOSITION_FLAGS as Rt,PM_READ_OUTPUT_SURFACES as bt}from"./read-output/options.js";import{resolvePmHistoryOperation as L}from"./cli-contracts/command-aliases.js";import{resolveExtensionOutputCommand as At}from"./read-output/extension.js";import{BEHAVIOR_PRESERVING_MIGRATION_HINTS as G,LEGACY_FLAGS_BY_COMMAND as Ct,VALUE_BEARING_INCLUDE_ALIASES as Et,flagSelector as $,optionKey as kt,readOutputIncludeModeOptionsForSurface as q,resolveNativeReadOutputSurface as Tt}from"./read-output/surfaces.js";import{EXIT_CODE as w}from"../core/shared/constants.js";import{PmCliError as R}from"../core/shared/errors.js";import{compactReadOutputToBudget as St,estimateReadOutputTokens as xt,readOutputMeasurementFormat as V,projectReadOutputItemToBrief as It,preserveReadOutputRowContract as k,mirrorReadOutputReceiptEstimate as jt,resolveReadOutputPassHooks as z,resolveReadOutputRecoveryBudget as vt,updateReadOutputReceiptEstimate as T}from"./read-output-budget.js";import{resolveReadOutputRecoveryBudget as en}from"./read-output-budget.js";import{resolvePmCommandOutputBudget as Ut}from"./cli-contracts/agent-output-contracts.js";import{boundReadOutputRows as Pt,countReadOutputRows as K,mapReadOutputRows as H,readOutputBudgetCollections as Y,readOutputContinuationRowCollections as v,readOutputRowPaths as Nt,readOutputRowCollections as Mt,refreshReadOutputDeliveredCounts as U}from"./read-output-rows.js";import{applyReadOutputContinuation as Dt,decodeReadOutputContinuationCursor as Ft,encodeReadOutputContinuationCursor as Bt,prioritizeAssuranceAssertions as Lt,readOutputCollectionFingerprint as Gt,refreshReadOutputDeliveredRowCounters as $t}from"./read-output/continuation.js";import{PM_READ_OUTPUT_TAIL_RETENTION_POLICIES as S,readOutputRetainsTail as x}from"./read-output/tail-retention.js";import{decodeReadOutputContinuationCursor as on,encodeReadOutputContinuationCursor as un,PM_READ_OUTPUT_CONTINUATION_FINGERPRINT_POLICIES as rn,readOutputCollectionFingerprint as sn}from"./read-output/continuation.js";import{PM_READ_OUTPUT_TAIL_RETENTION_POLICIES as cn,readOutputRetainsTail as dn}from"./read-output/tail-retention.js";import{applyReadOutputSessionReferences as qt,attachReadOutputSessionReceipt as W,parseReadOutputSession as P,readOutputSessionRemainingTokens as Vt}from"./read-output-session.js";import{decodeQueryCursorEnvelope as zt,encodeQueryCursor as Kt}from"./pagination.js";import{READ_OUTPUT_INVOCATION_PROVENANCE as N}from"./read-output/provenance.js";const b=["include","amount","cost","encoding"];import{PM_READ_OUTPUT_SURFACES as fn}from"./read-output/options.js";const J=["canonical","legacy","intent","default"],C=wt,qe=Object.freeze(b.map(t=>C[t])),Ve=Rt;function Ht(t,e){const n=G[t];if(n!==void 0)return n;const o=e==="include"?Et.has(t)?"<csv>":$(t):e==="amount"?"<n>":e==="cost"?"<tokens>":"<toon|json>";return`${t} is a compatibility alias; prefer ${C[e]} ${o}.`}function X(t){const e=Ct[t]??{},n=Object.freeze(Object.fromEntries(b.map(o=>[o,Object.freeze({dimension:o,canonical_option:C[o],applicable:!0,inapplicable_reason:null,legacy_aliases:Object.freeze((e[o]??[]).map(u=>Object.freeze({flag:u,semantics:G[u]===void 0?"replacement":"behavior_preserving",migration_hint:Ht(u,o),visibility:"hidden_alias"})))})])));return Object.freeze({command:t,dimensions:n,precedence:J,budget_retention_policy:t==="assurance"?"verdict_priority":Object.hasOwn(S,t)?"ordered_suffix":"ordered_prefix",projection_modes:Object.freeze([...q(t).keys()])})}const Yt=Object.freeze(bt.map(X)),Wt=new Map(Yt.map(t=>[t.command,t]));function I(t,e={}){const n=L(t.trim().toLowerCase()),o=At(n);return o!==void 0?o.read_output===void 0?void 0:`extension:${o.command}`:Tt(n,e)}const Q=["outputInclude","output_include","outputLimit","output_limit","outputBudget","output_budget","outputFormat","output_format","outputSession","output_session","outputCursor","output_cursor","outputRowContract","output_row_contract"],Z={comments:["add","body","comment","text","stdin","file","edit","delete"],notes:["add","note","text","addJson","stdin","file","edit","delete"],learnings:["add","learning","text","stdin","file","edit","delete"],files:["add","addGlob","remove","migrate","apply","note"],docs:["add","addGlob","remove","migrate","note"],"package-catalog":["activate","adopt","adoptAll","deactivate","doctor","init","install","manage","migrate","reload","scaffold","uninstall"]};function Jt(t){return Q.some(e=>e!=="outputFormat"&&e!=="output_format"&&t[e]!==void 0)}const Xt=[{keys:["outputInclude","output_include"],valid:t=>E(t)!==void 0,message:"--output-include requires at least one comma-separated field or section."},{keys:["outputLimit","output_limit"],valid:t=>t==="unbounded"||A(t)!==void 0,message:"--output-limit must be a positive integer or unbounded."},{keys:["outputBudget","output_budget"],valid:t=>t==="unbounded"||A(t)!==void 0,message:"--output-budget must be a positive integer or unbounded."},{keys:["outputSession","output_session"],valid:t=>(P(t),!0),message:"--output-session must be a valid session-state object."},{keys:["outputCursor","output_cursor"],valid:t=>typeof t=="string"&&t.trim().length>0,message:"--output-cursor requires a non-empty continuation cursor."}],ze="read_output_surface_unsupported",Ke="read_output_mutation_conflict",tt=[{flag:"--output-include",keys:["outputInclude","output_include"]},{flag:"--output-limit",keys:["outputLimit","output_limit"]},{flag:"--output-budget",keys:["outputBudget","output_budget"]},{flag:"--output-session",keys:["outputSession","output_session"]},{flag:"--output-cursor",keys:["outputCursor","output_cursor"]},{flag:"--output-row-contract",keys:["outputRowContract","output_row_contract"]}],He=tt.map(({flag:t})=>t);function Qt(t,e,n){const o=tt.filter(({keys:s})=>s.some(d=>e[d]!==void 0)),u=o.map(({flag:s})=>s),i=o.flatMap(({keys:s})=>s.filter(d=>e[d]!==void 0)),r=u.join(", ");return new R(`Universal output controls (${r}) cannot be combined with a ${t} mutation; nothing was written.`,w.USAGE,{code:"read_output_mutation_conflict",field:u[0],details:{surface:t,output_controls:u,output_option_keys:i,mutation_options:[...n]},required:`Retry the ${t} mutation without ${r}. To bound or page the result, read it with those controls in a separate call after the write.`,why:"Universal output controls shape a read. A mutation returns its own bounded receipt, so the controls have nothing to shape and the write is refused before it runs.",examples:[...Zt[t]]})}const Zt={comments:['pm comments <id> --add "<text>"',"pm comments <id> --output-limit 5"],notes:['pm notes <id> --add "<text>"',"pm notes <id> --output-limit 5"],learnings:['pm learnings <id> --add "<text>"',"pm learnings <id> --output-limit 5"],files:["pm files <id> --add path=<path>","pm files <id> --output-limit 5"],docs:["pm docs <id> --add path=<path>","pm docs <id> --output-limit 5"],"package-catalog":["pm package install <source> --project","pm package catalog --output-limit 5"]},te=new Set(["comments","notes","learnings"]);function Ye(t,e){const n=e[1];return te.has(L(t.trim().toLowerCase()))&&typeof n=="string"?{add:n}:{}}function We(t,e){const n=e.outputFormat??e.output_format;if(n!==void 0&&n!=="json"&&n!=="toon")throw new R("--output-format must be toon or json.",w.USAGE);if(!Jt(e))return;const o=I(t,e);if(!o){const u=Q.filter(i=>e[i]!==void 0);throw new R(`Universal output controls apply only to read commands; ${t||"this command"} is not a read surface.`,w.USAGE,{code:"read_output_surface_unsupported",details:{command:t||null,output_option_keys:u},required:"Drop the universal output controls, or run a read command. An extension command accepts them only when it declares read_output.",why:"Universal output controls shape a read's rows; a command that is not a read surface has no rows for them to bound, page or project."})}if(Object.hasOwn(Z,o)){const u=o,i=Z[u].filter(r=>e[r]!==void 0&&e[r]!==!1);if(i.length>0)throw Qt(u,e,i)}for(const u of Xt){const i=u.keys.map(r=>e[r]).find(r=>r!==void 0);if(i!==void 0&&!u.valid(i))throw new R(u.message,w.USAGE)}}function et(t){const e=I(t);return e?q(e):new Map}function ee(t,e,n){const o=E(e)??[],u=et(t),i=[],r=[],s=n,d=s[N],f=new Set(d?.canonical_include_modes??[]),l=new Set(d?.explicit_legacy_aliases??[]);for(const c of o){const _=u.get(c);if(_===void 0){i.push(c);continue}const O=`--${c.replaceAll("_","-")}`;D(M(n,O))&&l.add(O),n[_]=!0,r.push(c),f.add(c)}const a=I(t)==="get"?i.filter(c=>c!=="item"):[],p=a.length>0;return p&&(n.fields=[...new Set([...E(n.fields)??[],...a])].join(","),f.add("fields")),(r.length>0||p)&&(s[N]={canonical_include_modes:[...f],explicit_legacy_aliases:[...l],...d?.cli_invocation_observed===!0?{cli_invocation_observed:!0}:{}}),{selectors:i,modes:r}}function Je(t,e){const n=e.outputInclude??e.output_include;if(n===void 0)return;const{selectors:o,modes:u}=ee(t,n,e);if(u.length===0)return;const i=o.length>0?o.join(","):void 0;e.outputInclude=i,Object.hasOwn(e,"output_include")&&(e.output_include=i)}function M(t,e){const n=kt(e);if(Object.hasOwn(t,n))return t[n];const o=e.slice(2).replaceAll("-","_");if(Object.hasOwn(t,o))return t[o];if(e==="--no-truncate"&&t.truncate===!1)return!0}function D(t){return t!==void 0&&t!==!1&&t!==null}function E(t){const n=(Array.isArray(t)?t:[t]).flatMap(o=>typeof o=="string"?o.split(","):[]).map(o=>o.trim()).filter(Boolean);return n.length>0?[...new Set(n)]:void 0}function A(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 ne(t,e,n,o){for(const u of t.legacy_aliases){if(o(u.flag))continue;const i=M(e,u.flag),r={value:i,flag:u.flag};if(D(i)&&n(r))return r}}function nt(t,e){const n=E(t);if(n)return{source:"canonical",value:n};if(e)return{source:"legacy",value:E(e.value)??[$(e.flag)]}}function ot(t,e){if(t==="unbounded")return{source:"canonical",value:"unbounded"};const n=A(t);if(n!==void 0)return{source:"canonical",value:n};if(!e)return;if(e.flag==="--no-truncate"||e.flag==="--unbounded")return{source:"legacy",value:"unbounded"};const o=A(e.value);return o===void 0?void 0:{source:"legacy",value:o}}function ut(t,e){if(t==="unbounded")return{source:"canonical",value:"unbounded"};const n=A(t);if(n!==void 0)return{source:"canonical",value:n};if(!e)return;const o=A(e.value);return o===void 0?void 0:{source:"legacy",value:o}}function it(t,e){if(t==="json"||t==="toon")return{source:"canonical",value:t};if(e)return e.flag==="--stream"||e.flag==="--follow"?{source:"legacy",value:"stream"}:e.value==="json"||e.value==="toon"?{source:"legacy",value:e.value}:void 0}function rt(t,e,n){if(!t)return!1;const o=new Set(t.explicit_legacy_aliases);if(t.cli_invocation_observed===!0||t.sdk_invocation_observed===!0)return!o.has(n);const u=new Set(t.canonical_include_modes.map(i=>`--${i.replaceAll("_","-")}`));return e==="include"&&u.has(n)&&!o.has(n)}function oe(t,e,n,o){return t.trim().toLowerCase().replaceAll(/\s+/gu," ").split(" ")[0]==="list-all"||D(M(o,"--no-truncate"))&&!rt(n,"amount","--no-truncate")||e.amount?.flag==="--no-truncate"||e.include?.flag==="--full"||n?.canonical_include_modes.includes("full")===!0}function ue(t,e){return b.flatMap(n=>t[n]?.source==="canonical"||n==="include"&&(e?.canonical_include_modes.length??0)>0?[C[n]]:[])}function st(t,e){const n=I(t,e);if(!n)return;const o=Wt.get(n)??X(n),u=e[N],i={include:g=>nt(void 0,g),amount:g=>ot(void 0,g),cost:g=>ut(void 0,g),encoding:g=>it(void 0,g)},r=Object.fromEntries(b.map(g=>[g,ne(o.dimensions[g],e,y=>i[g](y)!==void 0,y=>rt(u,g,y))])),s=b.flatMap(g=>{const y=r[g];return y?[y.flag]:[]}),d=b.flatMap(g=>{const y=r[g];return y?[o.dimensions[g].legacy_aliases.find(yt=>yt.flag===y.flag).migration_hint]:[]}),f=it(e.outputFormat??e.output_format,r.encoding),l=nt(e.outputInclude??e.output_include,r.include),a=ot(e.outputLimit??e.output_limit,r.amount),p=ut(e.outputBudget??e.output_budget,r.cost),c=oe(t,r,u,e),_=Ut(t,{generateFallback:!0}),O=f?.value==="json"||e.resolvedOutputFormat==="json"?"json":"toon",h=p??(c?{source:"intent",value:"unbounded"}:{source:"default",value:_.default_max_estimated_tokens_by_format[O]});return{command:n,include:l,amount:a,cost:h,encoding:f,canonical_options_used:ue({include:l,amount:a,cost:h,encoding:f},u),legacy_aliases_used:s,migration_hints:d,precedence:J}}function m(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}const F=new Set(["applied_bound","applied_limit","completeness","continuation_kind","continuation_path","continuation_contract","count","filters","has_more","next_cursor","now","omission_receipt","projection","budget_retention_policy","row_contract","sorting","total","truncated"]),ie=["collection_counts","notes_count","tests_count"];function at(t,e){const n=new Set(e.map(o=>o.split(".")[0]));return Object.fromEntries(Object.entries(t).filter(([o])=>n.has(o)))}function re(t){const e=m(t.item)?t.item:{},n=[...new Set([...Object.keys(e),...ie.filter(u=>Object.hasOwn(e,u))])].sort((u,i)=>u.localeCompare(i)),o=Object.keys(t).filter(u=>u!=="item"&&u!=="read_output"&&!F.has(u)).sort((u,i)=>u.localeCompare(i));return{item:e,itemFields:n,sections:o,valid:[...n,"item",...n.map(u=>`item.${u}`),...o]}}function se(t,e){const n=re(t),o=e.filter(a=>!n.valid.includes(a));if(o.length>0)throw new R(`Unknown --output-include selector(s) for get: ${o.join(", ")}. Valid selectors: ${n.valid.join(", ")}.`,w.USAGE);const u=e.includes("item"),i=e.flatMap(a=>a.startsWith("item.")?[a.slice(5)]:n.itemFields.includes(a)?[a]:[]).filter((a,p,c)=>c.indexOf(a)===p);if(u&&i.length>0)throw new R("--output-include cannot mix a full item with projected item fields; use item or item.<field>, not both.",w.USAGE);const r=new Set(e.filter(a=>n.sections.includes(a))),s=Object.fromEntries(Object.entries(t).filter(([a])=>F.has(a)||r.has(a)));u?s.item=n.item:i.length>0&&(s.item=at(n.item,i));const d=[...u?[]:i.length>0?n.itemFields.filter(a=>!i.includes(a)).map(a=>({name:`item.${a}`,restore_with:`--output-include item.${a}`})):[{name:"item",restore_with:"--output-include item"}],...n.sections.filter(a=>!r.has(a)).map(a=>({name:a,restore_with:`--output-include ${a}`}))],l=[...m(s.omission_receipt)&&Array.isArray(s.omission_receipt.omitted_field_groups)?s.omission_receipt.omitted_field_groups:[],...d];return s.omission_receipt={has_omissions:l.length>0,omitted_field_group_count:l.length,omitted_field_groups:l},s}function ct(t){let e=0;return H({...t},n=>(m(n)&&Object.keys(n).length>0&&(e+=1),n)),e}function ae(t,e,n,o){if(ct(e)===0||ct(n)>0)return;const u=[...et(t).keys()],i=u.length>0?` Declared ${t} projection modes: ${u.join(", ")}.`:` The ${t} surface declares no projection modes; name row fields instead.`;throw new R(`Unknown --output-include selector(s) for ${t}: ${o.join(", ")}. No selector matched any returned row field.${i}`,w.USAGE)}function ce(t,e,n){if(t==="get")return se(e,n);const o=Nt(e),u=n.flatMap(r=>o.flatMap(s=>r.startsWith(`${s}.`)?[r.slice(s.length+1)]:[])),i=n.some(r=>Object.hasOwn(e,r.split(".")[0])&&!o.some(s=>r.startsWith(`${s}.`)));if(o.length>0&&(!i||u.length>0)){const r={...e},s=u.length>0?u:n,d=H(r,f=>m(f)?at(f,s):f);return ae(t,e,d,s),d}return Object.fromEntries(Object.entries(e).filter(([r])=>n.some(s=>s.split(".")[0]===r)||F.has(r)))}function de(t,e,n,o){if(e==="unbounded")return t;const{result:u,truncated:i}=Pt(t,e,r=>x(n,r));if(!i)return u;if(u.has_more=!0,u.truncated=!0,mt(u,n,[...o.entries()].flatMap(([r,s])=>s.rows>e?[{path:r,total_rows:s.totalRows}]:[])),typeof u.count=="number"){const r=m(u.projection)?u.projection.row_key:void 0;u.count=typeof r=="string"&&Array.isArray(u[r])?u[r].length:K(u)}return typeof u.returned_count=="number"&&(u.returned_count=K(u)),u.applied_bound={kind:"output_limit",source:"explicit",value:e},u}function le(t){return b.filter(e=>t[e]!==void 0&&t[e]?.source!=="default"||t.canonical_options_used.includes(C[e]))}function j(t,e,n,o){let u=W(t,e,o);k(t,u);for(let i=0;i<8;i+=1){const r=n.estimated_tokens,s=u.read_session.spent_this_call_tokens;T(u,n,o);const d=u;u=W(u,e,o),k(d,u);const f=u.read_session.spent_this_call_tokens;if(n.estimated_tokens===r&&f===s)return u}return u}function fe(t,e){if(!m(t.read_output))return t;const n=V(e),o=t.read_output,u=P(e.outputSession??e.output_session);return u===void 0?(T(t,o,n),t):j(t,u,o,n)}function dt(t,e){if(t!=="validate")return e;const n=m(e.projection)?e.projection:void 0;if(!(Array.isArray(n?.declared_field_groups)?n.declared_field_groups:[]).some(a=>m(a)&&a.name==="diagnostic_rows"))return e;const u=[...new Set(Y(e).map(({path:a})=>a).filter(a=>/^checks\.\d+\.details\./u.test(a)))],i=u.filter(a=>!u.some(p=>p!==a&&a.startsWith(`${p}.`)));if(i.length===0)return e;const r=m(e.row_contract)?e.row_contract:{},s=Array.isArray(r.row_keys)?r.row_keys.filter(a=>typeof a=="string"):[],d=Array.isArray(r.continuation_row_keys)?r.continuation_row_keys.filter(a=>typeof a=="string"):[],f=s.length>0?s:i,l=[...new Set(i)];return JSON.stringify(f)===JSON.stringify(s)&&JSON.stringify(l)===JSON.stringify(d)?e:{...e,row_contract:{...r,row_keys:f,continuation_row_keys:l,jq_selector:typeof r.jq_selector=="string"?r.jq_selector:".checks[].details"}}}function pe(t,e){return t.include?.source==="canonical"&&!B(e)}function lt(t,e){let n={...t};return pe(e,t)&&(n=ce(e.command,n,e.include.value)),e.command==="assurance"?Lt(n):n}function _e(t,e){const n=z(e)?.continuationBinding;if(n===void 0)return;const o=lt(dt(t.command,n),t);return new Map(v(o).filter(u=>!x(t.command,u.path)).map(u=>[u.path,u]))}function me(t,e,n,o,u){let i=lt(t,e);U(i,t);const r=_e(e,u);if(i=Dt(i,e.command,o,r),e.command==="history"&&o){const f=["compact_history","provenance_history","history","diff"];if(i=Object.fromEntries(Object.entries(i).filter(([l])=>!f.includes(l)||l===o.path)),m(i.projection)&&(i.projection={...i.projection,row_key:o.path}),m(i.row_contract)){const l=i.row_contract;i.row_contract={...l,row_keys:[o.path],...Array.isArray(l.continuation_row_keys)?{continuation_row_keys:[o.path]}:{}}}i.count=Object.keys(i[o.path]).length}const s=t.count_only===!0?{...i,count_only:!0,count:t.count}:i,d=Ae(i,t,e.command,o,u,r);return e.amount?.source==="canonical"&&(i=de(i,e.amount.value,e.command,d.collectionsBeforeBudget),d.cursorContinuesExistingPage&&Ot(i,d.originalItems,d.cursorSource,!0,d.originalItemOffset)),U(i,s),gt(i,e.command,d),{projected:n===void 0?i:qt(i,n),continuationState:d}}function ge(t,e){return[...t.cost!==void 0&&t.cost.value!=="unbounded"&&(t.cost.source==="canonical"||t.cost.source==="default"||t.command==="context"&&t.cost.source==="legacy")?[{source:t.cost.source,tokens:t.cost.value}]:[],...e===void 0?[]:[{source:"session",tokens:Vt(e)}]].sort((o,u)=>o.tokens-u.tokens)[0]}function ft(t){const e=t.canonical_options_used;return e&&e.length>0?{canonical_options_used:e}:{}}function pt(t,e){return m(t.context_intent)&&t.context_intent.command==="context"&&t.context_intent.token_budget===e&&t.context_intent.within_budget===!0}function Oe(t,e,n){return t.command!=="next"||(e.tokenBudget??e.token_budget)===void 0?!1:!(m(n.context_intent)&&n.context_intent.command==="next"&&n.context_intent.within_budget===!0)}function _t(t,e={}){return t?.source==="default"||t?.source==="legacy"&&!pt(e,t.tokens)?{budget_source:t.source,budget_tokens:t.tokens}:{}}function he(t,e,n,o,u,i){const r={contract_version:1,command:t.command,requested_dimensions:e,..._t(o),precedence:t.precedence,...ft(t),legacy_aliases_used:[],migration_hints:[],estimated_tokens:0,within_budget:!1,strings_compacted:!1,rows_compacted:!1,result_omitted:!0,...n===void 0?{omitted_result_estimated_tokens:u}:{}},s={output_budget_exceeded:{omitted_result:!0,reason:"requested_budget_infeasible",restore_with:"Unbounded",recovery:{outputBudget:"unbounded"}},read_output:r},d=n===void 0?s:j(s,n,r,i);if(n===void 0&&T(d,r,i),n!==void 0&&r.estimated_tokens>o.tokens)throw new R("The remaining output-session budget cannot fit its mandatory receipts; start a new session with a larger token_budget.",w.USAGE);return d}function ye(t,e,n){return t.command==="context"&&t.cost?.source==="legacy"&&!pt(n,t.cost.value)||Oe(t,e,n)||e.outputRowContract===!0||e.output_row_contract===!0||t.canonical_options_used.includes("--output-include")||t.command==="list"&&t.canonical_options_used.length>0&&t.include?.value.includes("full")===!0}function we(t,e,n,o,u){if(e!==void 0||B(n)||ye(t,u,n))return!1;if(t.amount?.source==="canonical"&&t.amount.value!=="unbounded"){const i=t.amount.value;if(Mt(n).some(({value:r})=>(Array.isArray(r)?r.length:Object.keys(r).length)>i))return!1}return t.cost===void 0||t.cost.value==="unbounded"||t.cost.source==="legacy"&&t.command!=="context"||xt(u.outputRowContract===!1?Object.fromEntries(Object.entries(n).filter(([i])=>i!=="row_contract")):n,o)<=t.cost.value}function mt(t,e,n){const o=Object.hasOwn(S,e)?S[e]:void 0,u=n.find(i=>o?.paths.includes(i.path));o!==void 0&&u!==void 0&&typeof t[o.total_key]!="number"&&(t[o.total_key]=u.total_rows)}function gt(t,e,n){const o=S[e]?.paths[0];o!==void 0&&$t(t,e,n.producer,n.collectionsBeforeBudget.get(o)?.rows)}function Re(t,e,n,o){const u=n.backward?n.rows-o:n.baseOffset+o;return{path:e,cursor:Bt({command:t,path:e,offset:u,total_rows:n.totalRows,fingerprint:n.fingerprint,...n.backward?{direction:"backward"}:{}}),retained_rows:o,remaining_rows:n.backward?u:n.totalRows-u,total_rows:n.totalRows}}function be(t,e,n,o,u,i,r){if(!n.rows_compacted)return;const s=e.amount?.value==="unbounded"?["amount"]:[],d=new Map(v(t).map(_=>[_.path,Array.isArray(_.value)?_.value.length:Object.keys(_.value).length])),f=[...r.entries()].flatMap(([_,O])=>{const h=d.get(_);return h>=O.rows?[]:[Re(e.command,_,O,h)]}),l=f[0];mt(t,e.command,f);const a=l?"; page --output-cursor":"",p=o.source==="session"?`Truncated by the remaining ${o.tokens}-token session budget; start a new output session with a larger token_budget${a}.`:`${o.tokens}-token: raise --output-budget${a}`;n.migration_hints=[p,...e.migration_hints];const c=vt({effective_budget_tokens:o.tokens,measured_result_tokens:i});l&&!u&&(typeof t.next_cursor!="string"||t.continuation_kind==="output_cursor")&&(t.next_cursor=l.cursor),t.continuation_kind=u?"producer_cursor":l?"output_cursor":"none",t.output_budget_truncation={reason:"output_budget_reached",budget_source:o.source,budget_tokens:o.tokens,overridden_dimensions:s,compacted_row_paths:n.compacted_row_paths,continuation_cursor_rebased:u,continuation_available:f.length>0,recovery_budget_multiplier:l?1:c.recovery_budget_multiplier,continuations:f,restore_with:l?"recovery":`Retry with --output-budget ${c.output_budget} because no declared row collection can be continued.`,recovery:l?{cursor:l.cursor,cli:"--output-cursor",sdk:"outputCursor",mcp:"outputCursor"}:{cli:`--output-budget ${c.output_budget}`,sdk:{outputBudget:c.output_budget},mcp:{outputBudget:c.output_budget}}}}function Ot(t,e,n,o,u){if(typeof n!="string"||!Array.isArray(t.items))return!1;const i=t.items.length,r=e.length;if(i===0||i>=r)return!1;let s;try{s=zt(n)}catch{return!1}const d=s.after_index;if(d===void 0)return!1;const f=e[i-1];if(Object.prototype.toString.call(f)!=="[object Object]")return!1;const l=Reflect.get(f,"id");if(typeof l!="string"||l.length===0)return!1;const a=o?d-(r-i):d+u+i;return a<0?!1:(t.next_cursor=Kt(s.fingerprint,l,a,s.snapshot),!0)}function ht(t){return Array.isArray(t)?t.length:Object.keys(t).length}function Ae(t,e,n,o,u,i){const r=new Map(v(t).map(f=>{const l=ht(f.value),a=o?.path===f.path,p=x(n,f.path),c=i?.get(f.path)??f;let _;return[f.path,{rows:l,totalRows:a?o.total_rows:ht(c.value),baseOffset:a&&!p?o.offset:0,backward:p,get fingerprint(){return _??=a?o.fingerprint:Gt(f.path,c.value,n),_}}]})),s=typeof t.next_cursor=="string",d=o?.path==="items"?o.offset:0;return{collectionsBeforeBudget:r,originalItems:Array.isArray(e.items)?d>0?e.items.slice(d):e.items:[],originalItemOffset:d,cursorContinuesExistingPage:s,cursorSource:s?t.next_cursor:u.after,producer:e}}function Ce(t,e,n,o,u,i,r,s,d,f){const l={...e,count_only:n},a=o.command==="assurance"&&Array.isArray(t.assertions)?t.assertions.filter(c=>m(c)&&c.verdict!=="pass").length:0,p=new Map;if(a>0&&p.set("assertions",a),o.command==="history"&&Array.isArray(t.diff))for(const c of Y(t))c.path.startsWith("diff.")&&p.set(c.path,Object.keys(c.value).length);return St(t,u,i.tokens,p,f,c=>{U(c,l),gt(c,o.command,s);const _=Ot(c,s.originalItems,s.cursorSource,s.cursorContinuesExistingPage,s.originalItemOffset);if(be(c,o,u,i,_,d,s.collectionsBeforeBudget),o.command==="history"&&m(c.projection)){c.has_more=typeof c.next_cursor=="string"||c.applied_bound?.kind==="output_limit";const O=c.projection.row_key;typeof O=="string"&&Array.isArray(c[O])&&(c.count=c[O].length)}r!==void 0&&Object.assign(c,j(c,r,u,f))},o.command==="history"&&Array.isArray(t.diff),c=>x(o.command,c),o.command)}function Xe(t,e,n){const o=st(t,e);if(!o)return n;const u=V(e),i=P(e.outputSession??e.output_session),r=e.outputCursor??e.output_cursor,s=typeof r=="string"?Ft(r):void 0,d=le(o),f=dt(o.command,n);if(s===void 0&&we(o,i,f,u,e))return f;const l=ge(o,i),a=me(f,o,i,s,e);let p=a.projected;k(p,p,e.outputRowContract===!1);const c=B(p),_={contract_version:1,command:o.command,requested_dimensions:d,..._t(l,p),precedence:o.precedence,...ft(o),legacy_aliases_used:o.legacy_aliases_used,migration_hints:o.migration_hints,estimated_tokens:0,within_budget:!c,strings_compacted:!1,rows_compacted:!1,result_omitted:c};p.read_output=_;const O=z(e)?.mirrorEstimate;if(O!==void 0&&jt(_,O),p=i===void 0?p:j(p,i,_,u),T(p,_,u),l!==void 0&&_.estimated_tokens>l.tokens){const h=It(o.command,e,p);h!==void 0&&(_.applied_depth="brief",_.degradation_reason="output_budget_reached",k(p,h),p=fe(h,e)),_.estimated_tokens>l.tokens&&(p=Ce(p,p,f.count_only===!0,o,_,l,i,a.continuationState,_.estimated_tokens,u))}return l!==void 0&&_.estimated_tokens>l.tokens?he(o,d,i,l,_.estimated_tokens,u):p}function Ee(t){return m(t)&&m(t.context_intent)&&t.context_intent.result_omitted===!0}function B(t){return ke(t)||Ee(t)}function ke(t){return m(t)&&m(t.output_budget_exceeded)&&t.output_budget_exceeded.omitted_result===!0&&t.output_budget_exceeded.reason==="requested_budget_infeasible"}function Qe(t,e){const n=e.outputFormat??e.output_format;if(n==="json"||n==="toon")return n;const o=st(t,e)?.encoding;return o?.value==="json"||o?.value==="toon"?o.value:void 0}export{Ve as PM_READ_OUTPUT_COMPOSITION_OPTION_FLAGS,rn as PM_READ_OUTPUT_CONTINUATION_FINGERPRINT_POLICIES,b as PM_READ_OUTPUT_DIMENSIONS,qe as PM_READ_OUTPUT_OPTION_FLAGS,fn as PM_READ_OUTPUT_SURFACES,Yt as PM_READ_OUTPUT_SURFACE_CONTRACTS,cn as PM_READ_OUTPUT_TAIL_RETENTION_POLICIES,Ke as READ_OUTPUT_MUTATION_CONFLICT_CODE,He as READ_OUTPUT_SHAPING_CONTROL_FLAGS,ze as READ_OUTPUT_SURFACE_UNSUPPORTED_CODE,Ye as annotationPositionalMutationOptions,Xe as applyReadOutputDimensions,ee as applyReadOutputIncludeModes,on as decodeReadOutputContinuationCursor,un as encodeReadOutputContinuationCursor,ke as isReadOutputBudgetExceeded,B as isReadResultOmittedForBudget,Je as normalizeReadOutputIncludeModeOptions,sn as readOutputCollectionFingerprint,et as readOutputIncludeModeOptions,dn as readOutputRetainsTail,st as resolveReadOutputDimensions,Qe as resolveReadOutputEncoding,en as resolveReadOutputRecoveryBudget,I as resolveReadOutputSurface,fe as stabilizeReadOutputReceiptEstimates,We as validateReadOutputOptions};
1
+ import{READ_OUTPUT_DIMENSION_FLAGS as wt,READ_OUTPUT_COMPOSITION_FLAGS as Rt,PM_READ_OUTPUT_SURFACES as bt}from"./read-output/options.js";import{resolvePmHistoryOperation as B}from"./cli-contracts/command-aliases.js";import{resolveExtensionOutputCommand as At}from"./read-output/extension.js";import{BEHAVIOR_PRESERVING_MIGRATION_HINTS as G,LEGACY_FLAGS_BY_COMMAND as Ct,VALUE_BEARING_INCLUDE_ALIASES as Et,flagSelector as $,optionKey as kt,readOutputIncludeModeOptionsForSurface as q,resolveNativeReadOutputSurface as Tt}from"./read-output/surfaces.js";import{EXIT_CODE as w}from"../core/shared/constants.js";import{PmCliError as R}from"../core/shared/errors.js";import{compactReadOutputToBudget as St,estimateReadOutputTokens as xt,readOutputMeasurementFormat as V,projectReadOutputItemToBrief as It,preserveReadOutputRowContract as k,mirrorReadOutputReceiptEstimate as jt,resolveReadOutputPassHooks as z,resolveReadOutputRecoveryBudget as vt,updateReadOutputReceiptEstimate as T}from"./read-output-budget.js";import{resolveReadOutputRecoveryBudget as on}from"./read-output-budget.js";import{resolvePmCommandOutputBudget as Pt}from"./cli-contracts/agent-output-contracts.js";import{boundReadOutputRows as Ut,countReadOutputRows as K,mapReadOutputRows as H,readOutputBudgetCollections as Y,readOutputContinuationRowCollections as v,readOutputRowPaths as Nt,readOutputRowCollections as Dt,refreshReadOutputDeliveredCounts as P}from"./read-output-rows.js";import{applyReadOutputContinuation as Mt,decodeReadOutputContinuationCursor as Ft,encodeReadOutputContinuationCursor as Lt,prioritizeAssuranceAssertions as Bt,readOutputCollectionFingerprint as Gt,refreshReadOutputDeliveredRowCounters as $t}from"./read-output/continuation.js";import{PM_READ_OUTPUT_TAIL_RETENTION_POLICIES as S,readOutputRetainsTail as x}from"./read-output/tail-retention.js";import{decodeReadOutputContinuationCursor as rn,encodeReadOutputContinuationCursor as sn,PM_READ_OUTPUT_CONTINUATION_FINGERPRINT_POLICIES as an,readOutputCollectionFingerprint as cn}from"./read-output/continuation.js";import{PM_READ_OUTPUT_TAIL_RETENTION_POLICIES as ln,readOutputRetainsTail as fn}from"./read-output/tail-retention.js";import{applyReadOutputSessionReferences as qt,attachReadOutputSessionReceipt as W,parseReadOutputSession as U,readOutputSessionRemainingTokens as Vt}from"./read-output-session.js";import{decodeQueryCursorEnvelope as zt,encodeQueryCursor as Kt}from"./pagination.js";import{READ_OUTPUT_INVOCATION_PROVENANCE as N}from"./read-output/provenance.js";const b=["include","amount","cost","encoding"];import{PM_READ_OUTPUT_SURFACES as _n}from"./read-output/options.js";const J=["canonical","legacy","intent","default"],C=wt,ze=Object.freeze(b.map(t=>C[t])),Ke=Rt;function Ht(t,e){const n=G[t];if(n!==void 0)return n;const o=e==="include"?Et.has(t)?"<csv>":$(t):e==="amount"?"<n>":e==="cost"?"<tokens>":"<toon|json>";return`${t} is a compatibility alias; prefer ${C[e]} ${o}.`}function X(t){const e=Ct[t]??{},n=Object.freeze(Object.fromEntries(b.map(o=>[o,Object.freeze({dimension:o,canonical_option:C[o],applicable:!0,inapplicable_reason:null,legacy_aliases:Object.freeze((e[o]??[]).map(u=>Object.freeze({flag:u,semantics:G[u]===void 0?"replacement":"behavior_preserving",migration_hint:Ht(u,o),visibility:"hidden_alias"})))})])));return Object.freeze({command:t,dimensions:n,precedence:J,budget_retention_policy:t==="assurance"?"verdict_priority":Object.hasOwn(S,t)?"ordered_suffix":"ordered_prefix",projection_modes:Object.freeze([...q(t).keys()])})}const Yt=Object.freeze(bt.map(X)),Wt=new Map(Yt.map(t=>[t.command,t]));function I(t,e={}){const n=B(t.trim().toLowerCase()),o=At(n);return o!==void 0?o.read_output===void 0?void 0:`extension:${o.command}`:Tt(n,e)}const Q=["outputInclude","output_include","outputLimit","output_limit","outputBudget","output_budget","outputFormat","output_format","outputSession","output_session","outputCursor","output_cursor","outputRowContract","output_row_contract"],Z={comments:["add","body","comment","text","stdin","file","edit","delete"],notes:["add","note","text","addJson","stdin","file","edit","delete"],learnings:["add","learning","text","stdin","file","edit","delete"],files:["add","addGlob","remove","migrate","apply","note"],docs:["add","addGlob","remove","migrate","note"],"package-catalog":["activate","adopt","adoptAll","deactivate","doctor","init","install","manage","migrate","reload","scaffold","uninstall"]};function Jt(t){return Q.some(e=>e!=="outputFormat"&&e!=="output_format"&&t[e]!==void 0)}const Xt=[{keys:["outputInclude","output_include"],valid:t=>E(t)!==void 0,message:"--output-include requires at least one comma-separated field or section."},{keys:["outputLimit","output_limit"],valid:t=>t==="unbounded"||A(t)!==void 0,message:"--output-limit must be a positive integer or unbounded."},{keys:["outputBudget","output_budget"],valid:t=>t==="unbounded"||A(t)!==void 0,message:"--output-budget must be a positive integer or unbounded."},{keys:["outputSession","output_session"],valid:t=>(U(t),!0),message:"--output-session must be a valid session-state object."},{keys:["outputCursor","output_cursor"],valid:t=>typeof t=="string"&&t.trim().length>0,message:"--output-cursor requires a non-empty continuation cursor."}],He="read_output_surface_unsupported",Ye="read_output_mutation_conflict",tt=[{flag:"--output-include",keys:["outputInclude","output_include"]},{flag:"--output-limit",keys:["outputLimit","output_limit"]},{flag:"--output-budget",keys:["outputBudget","output_budget"]},{flag:"--output-session",keys:["outputSession","output_session"]},{flag:"--output-cursor",keys:["outputCursor","output_cursor"]},{flag:"--output-row-contract",keys:["outputRowContract","output_row_contract"]}],We=tt.map(({flag:t})=>t);function Qt(t,e,n){const o=tt.filter(({keys:s})=>s.some(d=>e[d]!==void 0)),u=o.map(({flag:s})=>s),i=o.flatMap(({keys:s})=>s.filter(d=>e[d]!==void 0)),r=u.join(", ");return new R(`Universal output controls (${r}) cannot be combined with a ${t} mutation; nothing was written.`,w.USAGE,{code:"read_output_mutation_conflict",field:u[0],details:{surface:t,output_controls:u,output_option_keys:i,mutation_options:[...n]},required:`Retry the ${t} mutation without ${r}. To bound or page the result, read it with those controls in a separate call after the write.`,why:"Universal output controls shape a read. A mutation returns its own bounded receipt, so the controls have nothing to shape and the write is refused before it runs.",examples:[...Zt[t]]})}const Zt={comments:['pm comments <id> --add "<text>"',"pm comments <id> --output-limit 5"],notes:['pm notes <id> --add "<text>"',"pm notes <id> --output-limit 5"],learnings:['pm learnings <id> --add "<text>"',"pm learnings <id> --output-limit 5"],files:["pm files <id> --add path=<path>","pm files <id> --output-limit 5"],docs:["pm docs <id> --add path=<path>","pm docs <id> --output-limit 5"],"package-catalog":["pm package install <source> --project","pm package catalog --output-limit 5"]},te=new Set(["comments","notes","learnings"]);function Je(t,e){const n=e[1];return te.has(B(t.trim().toLowerCase()))&&typeof n=="string"?{add:n}:{}}function Xe(t,e){const n=e.outputFormat??e.output_format;if(n!==void 0&&n!=="json"&&n!=="toon")throw new R("--output-format must be toon or json.",w.USAGE);if(!Jt(e))return;const o=I(t,e);if(!o){const u=Q.filter(i=>e[i]!==void 0);throw new R(`Universal output controls apply only to read commands; ${t||"this command"} is not a read surface.`,w.USAGE,{code:"read_output_surface_unsupported",details:{command:t||null,output_option_keys:u},required:"Drop the universal output controls, or run a read command. An extension command accepts them only when it declares read_output.",why:"Universal output controls shape a read's rows; a command that is not a read surface has no rows for them to bound, page or project."})}if(Object.hasOwn(Z,o)){const u=o,i=Z[u].filter(r=>e[r]!==void 0&&e[r]!==!1);if(i.length>0)throw Qt(u,e,i)}for(const u of Xt){const i=u.keys.map(r=>e[r]).find(r=>r!==void 0);if(i!==void 0&&!u.valid(i))throw new R(u.message,w.USAGE)}}function et(t){const e=I(t);return e?q(e):new Map}function ee(t,e,n){const o=E(e)??[],u=et(t),i=[],r=[],s=n,d=s[N],l=new Set(d?.canonical_include_modes??[]),f=new Set(d?.explicit_legacy_aliases??[]);for(const _ of o){const c=u.get(_);if(c===void 0){i.push(_);continue}const h=`--${_.replaceAll("_","-")}`;M(D(n,h))&&f.add(h),n[c]=!0,r.push(_),l.add(_)}const a=I(t)==="get"?i.filter(_=>_!=="item"):[],p=a.length>0;return p&&(n.fields=[...new Set([...E(n.fields)??[],...a])].join(","),l.add("fields")),(r.length>0||p)&&(s[N]={canonical_include_modes:[...l],explicit_legacy_aliases:[...f],...d?.cli_invocation_observed===!0?{cli_invocation_observed:!0}:{}}),{selectors:i,modes:r}}function Qe(t,e){const n=e.outputInclude??e.output_include;if(n===void 0)return;const{selectors:o,modes:u}=ee(t,n,e);if(u.length===0)return;const i=o.length>0?o.join(","):void 0;e.outputInclude=i,Object.hasOwn(e,"output_include")&&(e.output_include=i)}function D(t,e){const n=kt(e);if(Object.hasOwn(t,n))return t[n];const o=e.slice(2).replaceAll("-","_");if(Object.hasOwn(t,o))return t[o];if(e==="--no-truncate"&&t.truncate===!1)return!0}function M(t){return t!==void 0&&t!==!1&&t!==null}function E(t){const n=(Array.isArray(t)?t:[t]).flatMap(o=>typeof o=="string"?o.split(","):[]).map(o=>o.trim()).filter(Boolean);return n.length>0?[...new Set(n)]:void 0}function A(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 ne(t,e,n,o){for(const u of t.legacy_aliases){if(o(u.flag))continue;const i=D(e,u.flag),r={value:i,flag:u.flag};if(M(i)&&n(r))return r}}function nt(t,e){const n=E(t);if(n)return{source:"canonical",value:n};if(e)return{source:"legacy",value:E(e.value)??[$(e.flag)]}}function ot(t,e){if(t==="unbounded")return{source:"canonical",value:"unbounded"};const n=A(t);if(n!==void 0)return{source:"canonical",value:n};if(!e)return;if(e.flag==="--no-truncate"||e.flag==="--unbounded")return{source:"legacy",value:"unbounded"};const o=A(e.value);return o===void 0?void 0:{source:"legacy",value:o}}function ut(t,e){if(t==="unbounded")return{source:"canonical",value:"unbounded"};const n=A(t);if(n!==void 0)return{source:"canonical",value:n};if(!e)return;const o=A(e.value);return o===void 0?void 0:{source:"legacy",value:o}}function it(t,e){if(t==="json"||t==="toon")return{source:"canonical",value:t};if(e)return e.flag==="--stream"||e.flag==="--follow"?{source:"legacy",value:"stream"}:e.value==="json"||e.value==="toon"?{source:"legacy",value:e.value}:void 0}function rt(t,e,n){if(!t)return!1;const o=new Set(t.explicit_legacy_aliases);if(t.cli_invocation_observed===!0||t.sdk_invocation_observed===!0)return!o.has(n);const u=new Set(t.canonical_include_modes.map(i=>`--${i.replaceAll("_","-")}`));return e==="include"&&u.has(n)&&!o.has(n)}function oe(t,e,n,o){return t.trim().toLowerCase().replaceAll(/\s+/gu," ").split(" ")[0]==="list-all"||M(D(o,"--no-truncate"))&&!rt(n,"amount","--no-truncate")||e.amount?.flag==="--no-truncate"||e.include?.flag==="--full"||n?.canonical_include_modes.includes("full")===!0}function ue(t,e){return b.flatMap(n=>t[n]?.source==="canonical"||n==="include"&&(e?.canonical_include_modes.length??0)>0?[C[n]]:[])}function st(t,e){const n=I(t,e);if(!n)return;const o=Wt.get(n)??X(n),u=e[N],i={include:g=>nt(void 0,g),amount:g=>ot(void 0,g),cost:g=>ut(void 0,g),encoding:g=>it(void 0,g)},r=Object.fromEntries(b.map(g=>[g,ne(o.dimensions[g],e,y=>i[g](y)!==void 0,y=>rt(u,g,y))])),s=b.flatMap(g=>{const y=r[g];return y?[y.flag]:[]}),d=b.flatMap(g=>{const y=r[g];return y?[o.dimensions[g].legacy_aliases.find(yt=>yt.flag===y.flag).migration_hint]:[]}),l=it(e.outputFormat??e.output_format,r.encoding),f=nt(e.outputInclude??e.output_include,r.include),a=ot(e.outputLimit??e.output_limit,r.amount),p=ut(e.outputBudget??e.output_budget,r.cost),_=oe(t,r,u,e),c=Pt(t,{generateFallback:!0}),h=l?.value==="json"||e.resolvedOutputFormat==="json"?"json":"toon",O=p??(_?{source:"intent",value:"unbounded"}:{source:"default",value:c.default_max_estimated_tokens_by_format[h]});return{command:n,include:f,amount:a,cost:O,encoding:l,canonical_options_used:ue({include:f,amount:a,cost:O,encoding:l},u),legacy_aliases_used:s,migration_hints:d,precedence:J}}function m(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}const F=new Set(["applied_bound","applied_limit","completeness","continuation_kind","continuation_path","continuation_contract","count","filters","has_more","next_cursor","now","omission_receipt","projection","budget_retention_policy","row_contract","sorting","total","truncated"]),ie=["collection_counts","notes_count","tests_count"];function at(t,e){const n=new Set(e.map(o=>o.split(".")[0]));return Object.fromEntries(Object.entries(t).filter(([o])=>n.has(o)))}function re(t){const e=m(t.item)?t.item:{},n=[...new Set([...Object.keys(e),...ie.filter(u=>Object.hasOwn(e,u))])].sort((u,i)=>u.localeCompare(i)),o=Object.keys(t).filter(u=>u!=="item"&&u!=="read_output"&&!F.has(u)).sort((u,i)=>u.localeCompare(i));return{item:e,itemFields:n,sections:o,valid:[...n,"item",...n.map(u=>`item.${u}`),...o]}}function se(t,e){const n=re(t),o=e.filter(a=>!n.valid.includes(a));if(o.length>0)throw new R(`Unknown --output-include selector(s) for get: ${o.join(", ")}. Valid selectors: ${n.valid.join(", ")}.`,w.USAGE);const u=e.includes("item"),i=e.flatMap(a=>a.startsWith("item.")?[a.slice(5)]:n.itemFields.includes(a)?[a]:[]).filter((a,p,_)=>_.indexOf(a)===p);if(u&&i.length>0)throw new R("--output-include cannot mix a full item with projected item fields; use item or item.<field>, not both.",w.USAGE);const r=new Set(e.filter(a=>n.sections.includes(a))),s=Object.fromEntries(Object.entries(t).filter(([a])=>F.has(a)||r.has(a)));u?s.item=n.item:i.length>0&&(s.item=at(n.item,i));const d=[...u?[]:i.length>0?n.itemFields.filter(a=>!i.includes(a)).map(a=>({name:`item.${a}`,restore_with:`--output-include item.${a}`})):[{name:"item",restore_with:"--output-include item"}],...n.sections.filter(a=>!r.has(a)).map(a=>({name:a,restore_with:`--output-include ${a}`}))],f=[...m(s.omission_receipt)&&Array.isArray(s.omission_receipt.omitted_field_groups)?s.omission_receipt.omitted_field_groups:[],...d];return s.omission_receipt={has_omissions:f.length>0,omitted_field_group_count:f.length,omitted_field_groups:f},s}function ct(t){let e=0;return H({...t},n=>(m(n)&&Object.keys(n).length>0&&(e+=1),n)),e}function ae(t,e,n,o){if(ct(e)===0||ct(n)>0)return;const u=[...et(t).keys()],i=u.length>0?` Declared ${t} projection modes: ${u.join(", ")}.`:` The ${t} surface declares no projection modes; name row fields instead.`;throw new R(`Unknown --output-include selector(s) for ${t}: ${o.join(", ")}. No selector matched any returned row field.${i}`,w.USAGE)}function ce(t,e,n){if(t==="get")return se(e,n);const o=Nt(e),u=n.flatMap(r=>o.flatMap(s=>r.startsWith(`${s}.`)?[r.slice(s.length+1)]:[])),i=n.some(r=>Object.hasOwn(e,r.split(".")[0])&&!o.some(s=>r.startsWith(`${s}.`)));if(o.length>0&&(!i||u.length>0)){const r={...e},s=u.length>0?u:n,d=H(r,l=>m(l)?at(l,s):l);return ae(t,e,d,s),d}return Object.fromEntries(Object.entries(e).filter(([r])=>n.some(s=>s.split(".")[0]===r)||F.has(r)))}function de(t,e,n,o){if(e==="unbounded")return t;const{result:u,truncated:i}=Ut(t,e,r=>x(n,r));if(!i)return u;if(u.has_more=!0,u.truncated=!0,mt(u,n,[...o.entries()].flatMap(([r,s])=>s.rows>e?[{path:r,total_rows:s.totalRows}]:[])),typeof u.count=="number"){const r=m(u.projection)?u.projection.row_key:void 0;u.count=typeof r=="string"&&Array.isArray(u[r])?u[r].length:K(u)}return typeof u.returned_count=="number"&&(u.returned_count=K(u)),u.applied_bound={kind:"output_limit",source:"explicit",value:e},u}function le(t){return b.filter(e=>t[e]!==void 0&&t[e]?.source!=="default"||t.canonical_options_used.includes(C[e]))}function j(t,e,n,o){let u=W(t,e,o);k(t,u);for(let i=0;i<8;i+=1){const r=n.estimated_tokens,s=u.read_session.spent_this_call_tokens;T(u,n,o);const d=u;u=W(u,e,o),k(d,u);const l=u.read_session.spent_this_call_tokens;if(n.estimated_tokens===r&&l===s)return u}return u}function fe(t,e){if(!m(t.read_output))return t;const n=V(e),o=t.read_output,u=U(e.outputSession??e.output_session);return u===void 0?(T(t,o,n),t):j(t,u,o,n)}function dt(t,e){if(t!=="validate")return e;const n=m(e.projection)?e.projection:void 0;if(!(Array.isArray(n?.declared_field_groups)?n.declared_field_groups:[]).some(a=>m(a)&&a.name==="diagnostic_rows"))return e;const u=[...new Set(Y(e).map(({path:a})=>a).filter(a=>/^checks\.\d+\.details\./u.test(a)))],i=u.filter(a=>!u.some(p=>p!==a&&a.startsWith(`${p}.`)));if(i.length===0)return e;const r=m(e.row_contract)?e.row_contract:{},s=Array.isArray(r.row_keys)?r.row_keys.filter(a=>typeof a=="string"):[],d=Array.isArray(r.continuation_row_keys)?r.continuation_row_keys.filter(a=>typeof a=="string"):[],l=s.length>0?s:i,f=[...new Set(i)];return JSON.stringify(l)===JSON.stringify(s)&&JSON.stringify(f)===JSON.stringify(d)?e:{...e,row_contract:{...r,row_keys:l,continuation_row_keys:f,jq_selector:typeof r.jq_selector=="string"?r.jq_selector:".checks[].details"}}}function pe(t,e){return t.include?.source==="canonical"&&!L(e)}function lt(t,e){let n={...t};return pe(e,t)&&(n=ce(e.command,n,e.include.value)),e.command==="assurance"?Bt(n):n}function _e(t,e){const n=z(e)?.continuationBinding;if(n===void 0)return;const o=lt(dt(t.command,n),t);return new Map(v(o).filter(u=>!x(t.command,u.path)).map(u=>[u.path,u]))}function me(t,e,n,o,u){let i=lt(t,e);P(i,t);const r=_e(e,u);if(i=Mt(i,e.command,o,r),e.command==="history"&&o){const l=["compact_history","provenance_history","history","diff"];if(i=Object.fromEntries(Object.entries(i).filter(([f])=>!l.includes(f)||f===o.path)),m(i.projection)&&(i.projection={...i.projection,row_key:o.path}),m(i.row_contract)){const f=i.row_contract;i.row_contract={...f,row_keys:[o.path],...Array.isArray(f.continuation_row_keys)?{continuation_row_keys:[o.path]}:{}}}i.count=Object.keys(i[o.path]).length}const s=t.count_only===!0?{...i,count_only:!0,count:t.count}:i,d=Ae(i,t,e.command,o,u,r);return e.amount?.source==="canonical"&&(i=de(i,e.amount.value,e.command,d.collectionsBeforeBudget),d.cursorContinuesExistingPage&&Ot(i,d.originalItems,d.cursorSource,!0,d.originalItemOffset)),P(i,s),gt(i,e.command,d),{projected:n===void 0?i:qt(i,n),continuationState:d}}function ge(t,e){return[...t.cost!==void 0&&t.cost.value!=="unbounded"&&(t.cost.source==="canonical"||t.cost.source==="default"||t.command==="context"&&t.cost.source==="legacy")?[{source:t.cost.source,tokens:t.cost.value}]:[],...e===void 0?[]:[{source:"session",tokens:Vt(e)}]].sort((o,u)=>o.tokens-u.tokens)[0]}function ft(t){const e=t.canonical_options_used;return e&&e.length>0?{canonical_options_used:e}:{}}function pt(t,e){return m(t.context_intent)&&t.context_intent.command==="context"&&t.context_intent.token_budget===e&&t.context_intent.within_budget===!0}function Oe(t,e,n){return t.command!=="next"||(e.tokenBudget??e.token_budget)===void 0?!1:!(m(n.context_intent)&&n.context_intent.command==="next"&&n.context_intent.within_budget===!0)}function _t(t,e={}){return t?.source==="default"||t?.source==="legacy"&&!pt(e,t.tokens)?{budget_source:t.source,budget_tokens:t.tokens}:{}}function he(t,e,n,o,u,i){const r={contract_version:1,command:t.command,requested_dimensions:e,..._t(o),precedence:t.precedence,...ft(t),legacy_aliases_used:[],migration_hints:[],estimated_tokens:0,within_budget:!1,strings_compacted:!1,rows_compacted:!1,result_omitted:!0,...n===void 0?{omitted_result_estimated_tokens:u}:{}},s={output_budget_exceeded:{omitted_result:!0,reason:"requested_budget_infeasible",restore_with:"Unbounded",recovery:{outputBudget:"unbounded"}},read_output:r},d=n===void 0?s:j(s,n,r,i);if(n===void 0&&T(d,r,i),n!==void 0&&r.estimated_tokens>o.tokens)throw new R("The remaining output-session budget cannot fit its mandatory receipts; start a new session with a larger token_budget.",w.USAGE);return d}function ye(t,e,n){return t.command==="context"&&t.cost?.source==="legacy"&&!pt(n,t.cost.value)||Oe(t,e,n)||e.outputRowContract===!0||e.output_row_contract===!0||t.canonical_options_used.includes("--output-include")||t.command==="list"&&t.canonical_options_used.length>0&&t.include?.value.includes("full")===!0}function we(t,e,n,o,u){if(e!==void 0||L(n)||ye(t,u,n))return!1;if(t.amount?.source==="canonical"&&t.amount.value!=="unbounded"){const i=t.amount.value;if(Dt(n).some(({value:r})=>(Array.isArray(r)?r.length:Object.keys(r).length)>i))return!1}return t.cost===void 0||t.cost.value==="unbounded"||t.cost.source==="legacy"&&t.command!=="context"||xt(u.outputRowContract===!1?Object.fromEntries(Object.entries(n).filter(([i])=>i!=="row_contract")):n,o)<=t.cost.value}function mt(t,e,n){const o=Object.hasOwn(S,e)?S[e]:void 0,u=n.find(i=>o?.paths.includes(i.path));o!==void 0&&u!==void 0&&typeof t[o.total_key]!="number"&&(t[o.total_key]=u.total_rows)}function gt(t,e,n){const o=S[e]?.paths[0];o!==void 0&&$t(t,e,n.producer,n.collectionsBeforeBudget.get(o)?.rows)}function Re(t,e,n,o){const u=n.backward?n.rows-o:n.baseOffset+o;return{path:e,cursor:Lt({command:t,path:e,offset:u,total_rows:n.totalRows,fingerprint:n.fingerprint,...n.backward?{direction:"backward"}:{}}),retained_rows:o,remaining_rows:n.backward?u:n.totalRows-u,total_rows:n.totalRows}}function be(t,e,n,o,u,i,r){if(!n.rows_compacted)return;const s=e.amount?.value==="unbounded"?["amount"]:[],d=new Map(v(t).map(c=>[c.path,Array.isArray(c.value)?c.value.length:Object.keys(c.value).length])),l=[...r.entries()].flatMap(([c,h])=>{const O=d.get(c);return O>=h.rows?[]:[Re(e.command,c,h,O)]}),f=l[0];mt(t,e.command,l);const a=f?"; page --output-cursor":"",p=o.source==="session"?`Truncated by the remaining ${o.tokens}-token session budget; start a new output session with a larger token_budget${a}.`:`${o.tokens}-token: raise --output-budget${a}`;n.migration_hints=[p,...e.migration_hints];const _=vt({effective_budget_tokens:o.tokens,measured_result_tokens:i});f&&!u&&(typeof t.next_cursor!="string"||t.continuation_kind==="output_cursor")&&(t.next_cursor=f.cursor),t.continuation_kind=u?"producer_cursor":f?"output_cursor":"none",t.output_budget_truncation={reason:"output_budget_reached",budget_source:o.source,budget_tokens:o.tokens,overridden_dimensions:s,compacted_row_paths:n.compacted_row_paths,continuation_cursor_rebased:u,continuation_available:l.length>0,recovery_budget_multiplier:f?1:_.recovery_budget_multiplier,continuations:l,restore_with:f?"recovery":`Retry with --output-budget ${_.output_budget} because no declared row collection can be continued.`,recovery:f?{cursor:f.cursor,cli:"--output-cursor",sdk:"outputCursor",mcp:"outputCursor"}:{cli:`--output-budget ${_.output_budget}`,sdk:{outputBudget:_.output_budget},mcp:{outputBudget:_.output_budget}}}}function Ot(t,e,n,o,u){if(typeof n!="string"||!Array.isArray(t.items))return!1;const i=t.items.length,r=e.length;if(i===0||i>=r)return!1;let s;try{s=zt(n)}catch{return!1}const d=s.after_index;if(d===void 0)return!1;const l=e[i-1];if(Object.prototype.toString.call(l)!=="[object Object]")return!1;const f=Reflect.get(l,"id");if(typeof f!="string"||f.length===0)return!1;const a=o?d-(r-i):d+u+i;return a<0?!1:(t.next_cursor=Kt(s.fingerprint,f,a,s.snapshot),!0)}function ht(t){return Array.isArray(t)?t.length:Object.keys(t).length}function Ae(t,e,n,o,u,i){const r=new Map(v(t).map(l=>{const f=ht(l.value),a=o?.path===l.path,p=x(n,l.path),_=i?.get(l.path)??l;let c;return[l.path,{rows:f,totalRows:a?o.total_rows:ht(_.value),baseOffset:a&&!p?o.offset:0,backward:p,get fingerprint(){return c??=a?o.fingerprint:Gt(l.path,_.value,n),c}}]})),s=typeof t.next_cursor=="string",d=o?.path==="items"?o.offset:0;return{collectionsBeforeBudget:r,originalItems:Array.isArray(e.items)?d>0?e.items.slice(d):e.items:[],originalItemOffset:d,cursorContinuesExistingPage:s,cursorSource:s?t.next_cursor:u.after,producer:e}}function Ce(t,e,n,o,u,i,r,s,d,l,f){const a={...e,count_only:n},p=o.command==="assurance"&&Array.isArray(t.assertions)?t.assertions.filter(c=>m(c)&&c.verdict!=="pass").length:0,_=new Map;if(p>0&&_.set("assertions",p),o.command==="history"&&Array.isArray(t.diff))for(const c of Y(t))c.path.startsWith("diff.")&&_.set(c.path,Object.keys(c.value).length);return St(t,u,i.tokens,_,l,c=>{P(c,a),gt(c,o.command,s);const h=Ot(c,s.originalItems,s.cursorSource,s.cursorContinuesExistingPage,s.originalItemOffset);if(be(c,o,u,i,h,d,s.collectionsBeforeBudget),o.command==="history"&&m(c.projection)){c.has_more=typeof c.next_cursor=="string"||c.applied_bound?.kind==="output_limit";const O=c.projection.row_key;typeof O=="string"&&Array.isArray(c[O])&&(c.count=c[O].length)}r!==void 0&&Object.assign(c,j(c,r,u,l))},o.command==="history"&&Array.isArray(t.diff),c=>x(o.command,c),o.command,f)}const Ee=/^command_flags\.\d+\.flags$/u;function ke(t,e){const n=t==="contracts"&&m(e.selected)&&e.selected.command_scoped===!0;return o=>n&&Ee.test(o)}function Ze(t,e,n){const o=st(t,e);if(!o)return n;const u=V(e),i=U(e.outputSession??e.output_session),r=e.outputCursor??e.output_cursor,s=typeof r=="string"?Ft(r):void 0,d=le(o),l=dt(o.command,n);if(s===void 0&&we(o,i,l,u,e))return l;const f=ge(o,i),a=me(l,o,i,s,e);let p=a.projected;k(p,p,e.outputRowContract===!1);const _=L(p),c={contract_version:1,command:o.command,requested_dimensions:d,..._t(f,p),precedence:o.precedence,...ft(o),legacy_aliases_used:o.legacy_aliases_used,migration_hints:o.migration_hints,estimated_tokens:0,within_budget:!_,strings_compacted:!1,rows_compacted:!1,result_omitted:_};p.read_output=c;const h=z(e)?.mirrorEstimate;if(h!==void 0&&jt(c,h),p=i===void 0?p:j(p,i,c,u),T(p,c,u),f!==void 0&&c.estimated_tokens>f.tokens){const O=It(o.command,e,p);O!==void 0&&(c.applied_depth="brief",c.degradation_reason="output_budget_reached",k(p,O),p=fe(O,e)),c.estimated_tokens>f.tokens&&(p=Ce(p,p,l.count_only===!0,o,c,f,i,a.continuationState,c.estimated_tokens,u,ke(o.command,l)))}return f!==void 0&&c.estimated_tokens>f.tokens?he(o,d,i,f,c.estimated_tokens,u):p}function Te(t){return m(t)&&m(t.context_intent)&&t.context_intent.result_omitted===!0}function L(t){return Se(t)||Te(t)}function Se(t){return m(t)&&m(t.output_budget_exceeded)&&t.output_budget_exceeded.omitted_result===!0&&t.output_budget_exceeded.reason==="requested_budget_infeasible"}function tn(t,e){const n=e.outputFormat??e.output_format;if(n==="json"||n==="toon")return n;const o=st(t,e)?.encoding;return o?.value==="json"||o?.value==="toon"?o.value:void 0}export{Ke as PM_READ_OUTPUT_COMPOSITION_OPTION_FLAGS,an as PM_READ_OUTPUT_CONTINUATION_FINGERPRINT_POLICIES,b as PM_READ_OUTPUT_DIMENSIONS,ze as PM_READ_OUTPUT_OPTION_FLAGS,_n as PM_READ_OUTPUT_SURFACES,Yt as PM_READ_OUTPUT_SURFACE_CONTRACTS,ln as PM_READ_OUTPUT_TAIL_RETENTION_POLICIES,Ye as READ_OUTPUT_MUTATION_CONFLICT_CODE,We as READ_OUTPUT_SHAPING_CONTROL_FLAGS,He as READ_OUTPUT_SURFACE_UNSUPPORTED_CODE,Je as annotationPositionalMutationOptions,Ze as applyReadOutputDimensions,ee as applyReadOutputIncludeModes,rn as decodeReadOutputContinuationCursor,sn as encodeReadOutputContinuationCursor,Se as isReadOutputBudgetExceeded,L as isReadResultOmittedForBudget,Qe as normalizeReadOutputIncludeModeOptions,cn as readOutputCollectionFingerprint,et as readOutputIncludeModeOptions,fn as readOutputRetainsTail,st as resolveReadOutputDimensions,tn as resolveReadOutputEncoding,on as resolveReadOutputRecoveryBudget,I as resolveReadOutputSurface,fe as stabilizeReadOutputReceiptEstimates,Xe as validateReadOutputOptions};
2
2
  //# sourceMappingURL=read-output-contracts.js.map
@@ -1,2 +1,2 @@
1
- const b=new Set(["applied_bound","completeness","budget_retention_policy","continuation_contract","continuation_kind","continuation_path","filters","omission_receipt","output_budget_truncation","projection","read_output","read_session","row_contract","sorting"]);function u(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function A(t,r){let e=t;for(const n of r.split("."))if(Array.isArray(e)){if(!/^\d+$/u.test(n))return;e=e[Number(n)]}else{if(!u(e))return;e=e[n]}return e}function y(t,r,e){const n=r.split("."),i=(s,o)=>{if(o===n.length)return e;const c=n[o];if(Array.isArray(s)){const l=Number(c),f=[...s];return f[l]=i(s[l],o+1),f}const a=s;return{...a,[c]:i(a[c],o+1)}};return i(t,0)}function C(t,r,e,n){const i=w(t).find(c=>c.path===r);if(!i)return t;const s=Array.isArray(i.value)?i.value.slice(e,n):Object.fromEntries(Object.entries(i.value).slice(e,n)),o=y(t,r,s);return u(o.summary)&&u(o.summary.focus_row_states)&&typeof o.summary.focus_row_states[r]=="string"&&(o.summary={...o.summary,focus_row_states:{...o.summary.focus_row_states,[r]:o.summary.focus_row_states[r].slice(e,n)}}),S(o),o}function g(t){const r=t.row_contract;return u(r)&&Array.isArray(r.row_keys)?r.row_keys.filter(e=>typeof e=="string"&&e.trim().length>0):Object.entries(t).filter(([,e])=>Array.isArray(e)).map(([e])=>e)}function O(t){const r=t.row_contract;return u(r)&&Array.isArray(r.continuation_row_keys)?r.continuation_row_keys.filter(e=>typeof e=="string"&&e.trim().length>0):g(t)}function p(t){return g(t).flatMap(r=>{const e=A(t,r);return Array.isArray(e)||u(e)?[{path:r,value:e}]:[]})}function w(t){return O(t).flatMap(r=>{const e=A(t,r);return Array.isArray(e)||u(e)?[{path:r,value:e}]:[]})}function x(t){const r=p(t),e=new Set(r.map(i=>i.path)),n=(i,s)=>{if(Array.isArray(i)){e.has(s)||r.push({path:s,value:i}),i.forEach((o,c)=>n(o,`${s}.${c}`));return}if(u(i))for(const[o,c]of Object.entries(i))s.length===0&&b.has(o)||n(c,s.length===0?o:`${s}.${o}`)};return n(t,""),r}function E(t){return p(t).reduce((r,e)=>r+(Array.isArray(e.value)?e.value.length:Object.keys(e.value).length),0)}function M(t,r){let e=t;for(const n of p(e)){const i=Array.isArray(n.value)?n.value.map((s,o)=>r(s,n.path,o)):Object.fromEntries(Object.entries(n.value).map(([s,o],c)=>[s,r(o,n.path,c)]));e=y(e,n.path,i)}return e}function $(t,r,e=()=>!1){let n=t,i=!1;for(const s of p(n)){const o=Array.isArray(s.value)?s.value:Object.entries(s.value);if(o.length<=r)continue;i=!0;const c=e(s.path)?o.length-r:0,a=o.slice(c,c+r),l=Array.isArray(s.value)?a:Object.fromEntries(a);n=y(n,s.path,l)}return{result:n,truncated:i}}const h=["high_level","low_level","blocked_fallback"];function d(t){const r=t.status==="in_progress"?"i":"o";return t.blocked===!0?r.toUpperCase():r}function k(t,r){if(!u(t.summary)||!u(t.summary.returned_focus))return;const e=new Map(r.map(n=>[n.id,n]));t.summary={...t.summary,focus_row_states:Object.fromEntries(h.map(n=>[n,Array.isArray(t[n])?t[n].filter(u).map(i=>d(e.get(i.id)??i)).join(""):""]))}}function v(t,r){if(t!==void 0){if(typeof t!="string"||t.length!==r||!/^[iIoO]*$/u.test(t))throw new TypeError("Context focus classification receipt must contain one i/I/o/O code per delivered record");return t}}function j(t,r,e,n){const i=Array.isArray(r[e])?r[e].filter(u):[],s=v(n[e],i.length)??i.map(d).join(""),o=new Map(i.flatMap((f,m)=>f.id===void 0?[]:[[f.id,s[m]]])),c=Array.isArray(t[e])?t[e].filter(u):[];let a=!1;return{states:c.map((f,m)=>{const _=o.get(f.id)??(f.id===void 0?s[m]:void 0)??d(f);return _!==d(f)&&(a=!0),_}).join(""),needsStates:a}}function R(t,r){typeof t.count=="number"&&(t.count_only===!0||r.count_only===!0?typeof r.count=="number"&&(t.count=r.count):Array.isArray(t.items)&&(t.count=t.items.length))}function S(t,r=t){if(R(t,r),!u(t.summary)||!u(t.summary.returned_focus))return;const e={...t.summary},n=u(r.summary)&&u(r.summary.focus_row_states)?r.summary.focus_row_states:{},i=h.map(a=>({key:a,...j(t,r,a,n)})),s=Object.fromEntries(i.map(({key:a,states:l})=>[a,l])),o=i.some(a=>a.needsStates),c=Object.values(s).join("");typeof e.high_level=="number"&&(e.high_level=Array.isArray(t.high_level)?t.high_level.length:0),typeof e.low_level=="number"&&(e.low_level=Array.isArray(t.low_level)?t.low_level.length:0),e.returned_focus={active_items:c.length,in_progress:[...c].filter(a=>a.toLowerCase()==="i").length,open:[...c].filter(a=>a.toLowerCase()==="o").length,blocked:[...c].filter(a=>a===a.toUpperCase()).length},o?e.focus_row_states=s:delete e.focus_row_states,t.summary=e}export{$ as boundReadOutputRows,E as countReadOutputRows,M as mapReadOutputRows,x as readOutputBudgetCollections,w as readOutputContinuationRowCollections,O as readOutputContinuationRowPaths,p as readOutputRowCollections,g as readOutputRowPaths,S as refreshReadOutputDeliveredCounts,k as rememberReadOutputFocusRows,C as sliceReadOutputRowCollection};
1
+ const b=new Set(["applied_bound","completeness","budget_retention_policy","continuation_contract","continuation_kind","continuation_path","filters","omission_receipt","output_budget_truncation","projection","read_output","read_session","row_contract","sorting"]);function u(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function A(t,r){let e=t;for(const n of r.split("."))if(Array.isArray(e)){if(!/^\d+$/u.test(n))return;e=e[Number(n)]}else{if(!u(e))return;e=e[n]}return e}function y(t,r,e){const n=r.split("."),s=(i,o)=>{if(o===n.length)return e;const c=n[o];if(Array.isArray(i)){const l=Number(c),f=[...i];return f[l]=s(i[l],o+1),f}const a=i;return{...a,[c]:s(a[c],o+1)}};return s(t,0)}function C(t,r,e,n){const s=w(t).find(c=>c.path===r);if(!s)return t;const i=Array.isArray(s.value)?s.value.slice(e,n):Object.fromEntries(Object.entries(s.value).slice(e,n)),o=y(t,r,i);return r==="matches"&&typeof o.count=="number"&&Array.isArray(i)&&(o.count=i.length),u(o.summary)&&u(o.summary.focus_row_states)&&typeof o.summary.focus_row_states[r]=="string"&&(o.summary={...o.summary,focus_row_states:{...o.summary.focus_row_states,[r]:o.summary.focus_row_states[r].slice(e,n)}}),S(o),o}function g(t){const r=t.row_contract;return u(r)&&Array.isArray(r.row_keys)?r.row_keys.filter(e=>typeof e=="string"&&e.trim().length>0):Object.entries(t).filter(([,e])=>Array.isArray(e)).map(([e])=>e)}function O(t){const r=t.row_contract;return u(r)&&Array.isArray(r.continuation_row_keys)?r.continuation_row_keys.filter(e=>typeof e=="string"&&e.trim().length>0):g(t)}function p(t){return g(t).flatMap(r=>{const e=A(t,r);return Array.isArray(e)||u(e)?[{path:r,value:e}]:[]})}function w(t){return O(t).flatMap(r=>{const e=A(t,r);return Array.isArray(e)||u(e)?[{path:r,value:e}]:[]})}function x(t){const r=p(t),e=new Set(r.map(s=>s.path)),n=(s,i)=>{if(Array.isArray(s)){e.has(i)||r.push({path:i,value:s}),s.forEach((o,c)=>n(o,`${i}.${c}`));return}if(u(s))for(const[o,c]of Object.entries(s))i.length===0&&b.has(o)||n(c,i.length===0?o:`${i}.${o}`)};return n(t,""),r}function E(t){return p(t).reduce((r,e)=>r+(Array.isArray(e.value)?e.value.length:Object.keys(e.value).length),0)}function M(t,r){let e=t;for(const n of p(e)){const s=Array.isArray(n.value)?n.value.map((i,o)=>r(i,n.path,o)):Object.fromEntries(Object.entries(n.value).map(([i,o],c)=>[i,r(o,n.path,c)]));e=y(e,n.path,s)}return e}function $(t,r,e=()=>!1){let n=t,s=!1;for(const i of p(n)){const o=Array.isArray(i.value)?i.value:Object.entries(i.value);if(o.length<=r)continue;s=!0;const c=e(i.path)?o.length-r:0,a=o.slice(c,c+r),l=Array.isArray(i.value)?a:Object.fromEntries(a);n=y(n,i.path,l)}return{result:n,truncated:s}}const h=["high_level","low_level","blocked_fallback"];function m(t){const r=t.status==="in_progress"?"i":"o";return t.blocked===!0?r.toUpperCase():r}function k(t,r){if(!u(t.summary)||!u(t.summary.returned_focus))return;const e=new Map(r.map(n=>[n.id,n]));t.summary={...t.summary,focus_row_states:Object.fromEntries(h.map(n=>[n,Array.isArray(t[n])?t[n].filter(u).map(s=>m(e.get(s.id)??s)).join(""):""]))}}function v(t,r){if(t!==void 0){if(typeof t!="string"||t.length!==r||!/^[iIoO]*$/u.test(t))throw new TypeError("Context focus classification receipt must contain one i/I/o/O code per delivered record");return t}}function j(t,r,e,n){const s=Array.isArray(r[e])?r[e].filter(u):[],i=v(n[e],s.length)??s.map(m).join(""),o=new Map(s.flatMap((f,d)=>f.id===void 0?[]:[[f.id,i[d]]])),c=Array.isArray(t[e])?t[e].filter(u):[];let a=!1;return{states:c.map((f,d)=>{const _=o.get(f.id)??(f.id===void 0?i[d]:void 0)??m(f);return _!==m(f)&&(a=!0),_}).join(""),needsStates:a}}function R(t,r){typeof t.count=="number"&&(t.count_only===!0||r.count_only===!0?typeof r.count=="number"&&(t.count=r.count):Array.isArray(t.items)&&(t.count=t.items.length))}function S(t,r=t){if(R(t,r),!u(t.summary)||!u(t.summary.returned_focus))return;const e={...t.summary},n=u(r.summary)&&u(r.summary.focus_row_states)?r.summary.focus_row_states:{},s=h.map(a=>({key:a,...j(t,r,a,n)})),i=Object.fromEntries(s.map(({key:a,states:l})=>[a,l])),o=s.some(a=>a.needsStates),c=Object.values(i).join("");typeof e.high_level=="number"&&(e.high_level=Array.isArray(t.high_level)?t.high_level.length:0),typeof e.low_level=="number"&&(e.low_level=Array.isArray(t.low_level)?t.low_level.length:0),e.returned_focus={active_items:c.length,in_progress:[...c].filter(a=>a.toLowerCase()==="i").length,open:[...c].filter(a=>a.toLowerCase()==="o").length,blocked:[...c].filter(a=>a===a.toUpperCase()).length},o?e.focus_row_states=i:delete e.focus_row_states,t.summary=e}export{$ as boundReadOutputRows,E as countReadOutputRows,M as mapReadOutputRows,x as readOutputBudgetCollections,w as readOutputContinuationRowCollections,O as readOutputContinuationRowPaths,p as readOutputRowCollections,g as readOutputRowPaths,S as refreshReadOutputDeliveredCounts,k as rememberReadOutputFocusRows,C as sliceReadOutputRowCollection};
2
2
  //# sourceMappingURL=read-output-rows.js.map
package/docs/COMMANDS.md CHANGED
@@ -1846,6 +1846,43 @@ back to the registered description), so agents never need a generic
1846
1846
  `Inspect flags.` placeholder. Request heavier command-specific flags or schemas
1847
1847
  only after selecting the exact path.
1848
1848
 
1849
+ A command-scoped contract lists two row sets: `flags`, the options the command
1850
+ declares, and `inherited_flags`, the host flags it accepts from the root program,
1851
+ each marked `owner: "host"`
1852
+ ([pm-6vk110](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-6vk110.toon),
1853
+ tracker record excluded from npm). A core command inherits `--json`, `--quiet`,
1854
+ `--pm-path`, `--no-extensions` and the other reserved host flags; the read-output
1855
+ controls (`--output-include`, `--output-limit`, `--output-budget`,
1856
+ `--output-session`, `--output-cursor`, `--output-row-contract`) appear only on
1857
+ read surfaces, because every other core command refuses them with
1858
+ `read_output_surface_unsupported`. `--expect-hash` follows the runtime's
1859
+ admission rule: it is omitted and refused with `expect_hash_requires_mutation`
1860
+ on reads, the static package inventory and read-only subcommands such as
1861
+ `files lookup`; native mutations that write no existing item (`config`, `gc`,
1862
+ `profile`) still admit it for now, and refusing them there is pending
1863
+ ([pm-oehf5s](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-oehf5s.toon),
1864
+ tracker record excluded from npm). A host
1865
+ flag the command publishes itself, such as `close --author` or an
1866
+ `--output-format` encoding row, stays in `flags` and is not repeated. Under the
1867
+ default output budget a command-scoped contract keeps every declared flag and
1868
+ sheds inherited rows and per-flag invocation detail first. `pm help <command> --json` lists the same
1869
+ rows as `inherited_options`. An unscoped catalog omits the core rows instead of
1870
+ repeating them on every command and says so in
1871
+ `core_inherited_flags_omitted_reason`.
1872
+
1873
+ Executable subcommands have their own entries, so `pm contracts --command "files
1874
+ discover"` and `pm contracts --command "files lookup"` publish exactly the flags
1875
+ those parsers accept, and the `files` entry lists only what `pm files <id>`
1876
+ accepts. A census over the command tree fails when an executable command has no
1877
+ entry, or when a contract row and the parser disagree
1878
+ ([pm-9ke7h9](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-9ke7h9.toon),
1879
+ tracker record excluded from npm). An invalid-value refusal offers an executable
1880
+ retry only when it can bind the refused flag, from the producer's field or the one
1881
+ supplied flag its message names, and rewrites only that flag's value; a missing or
1882
+ ambiguous binding withholds the retry and keeps the help and contract guidance
1883
+ ([pm-s1fw0x](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-s1fw0x.toon),
1884
+ tracker record excluded from npm).
1885
+
1849
1886
  ## Completion
1850
1887
 
1851
1888
  `pm completion` is provided by the optional `guide-shell` package (`pm package install guide-shell --project`).
@@ -448,15 +448,34 @@ URL credentials never reach telemetry or Sentry, whatever the host looks like
448
448
  tracker record excluded from npm). Before any other sanitizer runs, each
449
449
  command argument is treated as one token and each other string as
450
450
  whitespace-delimited words. In every such token, the span between the first
451
- `:` and the last `@` is replaced with `[redacted]`, and any scheme slashes
452
- are kept. The rule is conservative so that it is complete: a single-label
451
+ `:` and the last `@` is replaced with `[redacted]`, and any scheme slashes are
452
+ kept. An argument with blanks keeps that one span, but it starts after the
453
+ longest provably public prefix that ends before a word that starts a URL. A
454
+ word starts a URL with a scheme of two or more characters, then a colon and a
455
+ slash or backslash. A slashless URL such as `https:u:p@h` keeps the one span. A
456
+ provably public prefix holds only words without a `:` or special-scheme URLs
457
+ whose host (with at most a numeric port) a `/` ends inside the word. It holds no
458
+ tab or line break, and the token rule finds no possible userinfo in it. So a
459
+ public URL before a separate credential URL survives, while
460
+ `https://user:secret value://tail@host` or `https://u:pa/ss value://tail@host`
461
+ loses its whole userinfo
462
+ ([pm-gh1799](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-gh1799.toon);
463
+ tracker record excluded from npm). The rule is conservative so that it is complete: a single-label
453
464
  host, `host:port`, a backslash authority or a password with any characters is
454
465
  covered. A scoped package name after a colon is hidden too. The CLI also
455
466
  registers each secret of the running invocation, including its shell and
456
467
  JSON escaping. Any echoed run that shares a six-character fragment with one
457
468
  of them is removed, so a split, truncated or re-cased echo exposes at most
458
469
  five consecutive characters (more only for a secret beyond the 65,536-fragment
459
- budget). The command taxonomy of an unknown
470
+ budget). Every secret of one invocation shares that budget, so secrets that
471
+ together exceed it widen the bound for all of them. Below it, the five-character
472
+ bound holds for each URL. One exception is case folding: a capital sigma
473
+ lower-cases to a final sigma at the end of a word, so a truncated or re-cased
474
+ echo that moves a sigma to a word end can keep more. When a public prefix is
475
+ split off an argument, the
476
+ later URL's secret is registered exactly as when that URL is given alone.
477
+ The public prefix is never registered, so text that only the prefix shares is
478
+ not removed. The command taxonomy of an unknown
460
479
  command is derived from the already-redacted token.
461
480
 
462
481
  The separate local event and OTLP queues retain their existing formats. Turning
@@ -238,7 +238,12 @@ keys (including temporary keys), Google, Anthropic, OpenAI, GitLab, Sentry,
238
238
  private keys, JWT-shaped tokens, npm authentication assignments, password
239
239
  assignments, inline sshpass passwords, private IPv4 addresses, private SSH
240
240
  hosts, and absolute home-directory paths. Every repository rule also runs
241
- against mutation string leaves in `advise` and `block` modes.
241
+ against mutation string leaves in `advise` and `block` modes. JWT-shaped tokens
242
+ are found by a scan with exactly the pattern's matches that examines each
243
+ segment run a bounded number of times, so text made of repeated `-eyJ` runs
244
+ stays linear
245
+ ([pm-8oetjo](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-8oetjo.toon);
246
+ tracker record excluded from npm).
242
247
 
243
248
  Two repository fixture exemptions apply only to `tests/` and `examples/`:
244
249
  absolute home paths and user-at-private-host matches. They never exempt
@@ -475,8 +480,9 @@ decodes to `$`, as JSON and JavaScript readers decode it.
475
480
 
476
481
  Each candidate key/value is judged by the rule's own value grammar. The
477
482
  password rule's literal minimum, the credential-key placeholder exclusions
478
- and the high-entropy predicate therefore carry over. Bare tokens inside a
479
- container are never judged, so `password=[scrubbed]` stays clean. A
483
+ and the high-entropy predicate therefore carry over. The string walk never
484
+ judges a bare token inside a container, so `password=[scrubbed]` stays clean;
485
+ numbers in a container are judged by the separate number walk described below. A
480
486
  structured string literal that spans a raw line break is a host-language
481
487
  artifact, not a credential. The pass is linear. Nested keys inside a
482
488
  walked container still get their own scalar check. Each container is walked
@@ -542,15 +548,186 @@ compactly (whitespace-free) under a prefixed key or as an object member's
542
548
  value under any credential key above it. The finding reports the leaf's path,
543
549
  never its value. `{ api_key: "…" }`, `{ clientSecret: "…" }` and
544
550
  `{ password: ["…"] }` are therefore judged like `{"api_key":"…"}`, and pm's
545
- own fields such as `token_budget`, `max_tokens` and numeric counts stay clean.
551
+ own fields such as `token_budget`, `max_tokens` and `estimated_minutes` stay
552
+ clean, because no credential key names them.
546
553
  A payload string is complete data, so it is judged as a decoded literal
547
554
  whether or not its JSON spelling needs escapes: its quote characters are
548
555
  data, and an unclosed reference in it is literal text (the source-text rule
549
- for a reference cut by the grammar never applies). Only strings are judged: a
550
- number, boolean, null or boxed value under a credential key is not a
551
- credential, and the pass never serializes a value or
552
- calls `toJSON`. Each leaf is judged once per rule, so the pass is linear in
553
- the payload. Both passes walk the payload with their own stack, so payload
556
+ for a reference cut by the grammar never applies). A finite number or a
557
+ bigint under a credential key is judged as its JSON spelling: the unquoted
558
+ `JSON.stringify` spelling of a finite number (with its sign, decimal point or
559
+ exponent, such as `1e+21`), or the base-10 digits of a bigint
560
+ (GH-1802,
561
+ [pm-gh1802](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-gh1802.toon);
562
+ tracker record excluded from npm): `{ password: { pin: <nine digits> } }` is
563
+ reported like `{"password":{"pin":<nine digits>}}`, while a number shorter
564
+ than the rule's literal minimum stays clean. In text, a number inside an array
565
+ or a nested object under a credential key is judged exactly as the same number
566
+ directly after the key. Strings keep their container walk unchanged; numbers
567
+ get a walk of their own, which reads JSON, JSON-like text and the
568
+ JSON-compatible subset of YAML flow. There a number (a JSON number, or a YAML
569
+ decimal such as `+5`, `.5` or `5.`) must start where a value starts and a
570
+ delimiter, a closer or the end must end it, so `abc123` and other bare tokens
571
+ stay unjudged. A value starts after an array opener, a separator, or a colon
572
+ that YAML flow reads as a separator: one after a quoted key (`"pin":1`), or one
573
+ before a blank, a flow indicator or the end (`pin: 1`, `items:[1]`, also as an
574
+ implicit mapping inside an array), so the
575
+ digits after a colon inside a plain scalar (`{ref:2026…}`, `[ref:2026…]`) are
576
+ not a value. A container that
577
+ holds one of these constructs only YAML has is not judged for numbers at all: a
578
+ blank-separated comment, an anchor, alias or tag, an explicit key (`?` before
579
+ a blank, a delimiter, an opener or the end), a bare YAML 1.1 merge key (`<<`), a collection used as a key, a doubled quote
580
+ inside a single-quoted string, a quoted string folded over a line break, a
581
+ double-quoted string with an escape JSON does not define, a backslash outside
582
+ a string, or a quote inside a bare token (`pin's`, `item-"x`): JSON has neither,
583
+ so escaped text read raw, or a quote the text lexer may pair differently, is
584
+ never read as structure. Two values with no separator between them (a
585
+ collection or a token, quoted or bare, right after a collection, a number or a
586
+ quoted string: `[[] {}]`, `[1 []]`, `[[] "a"]`, `["a" b]`) and a second
587
+ separator colon in one member or array element (`{a: b: 1}`, `["a": "b": 1]`)
588
+ also stop the walk, since neither JSON nor YAML flow allows them; separated by
589
+ commas the values are ordinary, as is one colon per member or implicit array
590
+ mapping. A YAML-only scalar spelling that is not
591
+ one of them (a hexadecimal `0x2a`, `.inf`) is a bare token the walk skips: it is
592
+ not judged, and a decimal beside it still is. A single-quoted string that holds a backslash also stops the walk,
593
+ because YAML reads the backslash literally and Python reads it as an escape,
594
+ so the two dialects disagree on where the string ends. A number is reported
595
+ only once the container it sits in closes with its matching closer: a
596
+ mismatched closer, or text or an enclosing string that ends first, means no
597
+ finding. The closed container must also be a value, not a key (no separator
598
+ colon follows it, as in `{"pin":[1]: 0}`), and, read on its own, a real
599
+ parser must accept it: `JSON.parse`, or a strict YAML 1.2 parse (the `yaml`
600
+ dependency, loaded on first use) that reports no error and reads one of the
601
+ judged numbers as a numeric scalar at the same offset (a bare carriage return
602
+ after digits belongs to a YAML plain scalar, so there the value is a string,
603
+ while JSON reads the carriage return as whitespace). A container too deep
604
+ for the YAML parser (it records the stack overflow as `RESOURCE_EXHAUSTION`;
605
+ how deep that is depends on the runtime's stack, so the spec simulates the
606
+ error) was never read, so when that is the only parse error a pending number there
607
+ is reported with `normalization_incomplete` for review instead of being
608
+ dropped, unless every judged number lies inside a scalar the parser did
609
+ compose and none qualifies (a number under a metadata key stays exempt; a
610
+ number qualifies only as a numeric scalar starting at its offset). It takes
611
+ precedence over a string finding in the same container, so the review flag
612
+ reaches the caller. After a string finding the number walk runs only as a
613
+ probe for such a number. Every number walk, probe or not, is skipped inside
614
+ a range a recorded walk already covered; a probe is also skipped inside a
615
+ range an earlier probe covered, whatever that probe's verdict, and records
616
+ only probe ranges, so recorded walks never see probes. Ranges are kept per
617
+ key class, as for the other walks (a walk or probe of an exact key covers
618
+ later ones of both classes in its range, one of a prefixed key only later
619
+ prefixed ones), so within one rule reading and lexical scope at most two
620
+ recorded ranges and two probe ranges cover any offset, and nested string
621
+ findings keep the scan linear. A match therefore carries
622
+ `normalization_incomplete` only from its own walk's or probe's verdict, which
623
+ flags that container's match rather than a particular number. A nested key
624
+ whose walk or probe was skipped contributes no number verdict or review flag
625
+ of its own; only the earlier walks and probes covering it report, each for
626
+ its own container, so a number reachable only through the skipped scan is a
627
+ recorded miss of the same kind as a discarded walk's, owned by pm-o1ntjo. Any other parse error, or a repeated key in the part the
628
+ parser did read, settles the container as invalid. JSON of any depth is read by `JSON.parse`. The numeric metadata
629
+ exemption follows the same split: JSON reads a member name exactly as the
630
+ walk does, while on the YAML route it is judged by the key the parser
631
+ resolves (a bare carriage return before the colon stays in a YAML plain
632
+ key, so `exp` followed by one is another key than `exp`). A container that
633
+ reads as JSON on its own is judged as JSON even when the text around it is
634
+ YAML, where a bare carriage return after digits would make the value a
635
+ string: the walk cannot know the surrounding language, and valid JSON keeps
636
+ its findings (a recorded limit; a bare carriage return outside a string is
637
+ rare, and `JSON.stringify` never writes one). The hand-written walk
638
+ stops early at constructs outside JSON-compatible flow; the parse makes the
639
+ boundary exact, so YAML's own rules apply too: no empty entries, one colon per
640
+ entry, the implicit key of a single-pair entry in a flow sequence on one line
641
+ and at most 1,024 UTF-16 code units from its start to its colon, blanks
642
+ included (the parser's count; the YAML spec counts characters, and sets no
643
+ such limit for keys inside a flow mapping), no scalar starting with a
644
+ reserved indicator such as `@` or `- `, no
645
+ document markers, and unique keys, while a JSON text with duplicate names
646
+ still counts. Key uniqueness is checked in one pass with a set per mapping,
647
+ judging keys as the parser does (a scalar by its resolved value, a collection
648
+ or tagged object by identity, mappings used as keys and `!!pairs` entries
649
+ included), since the
650
+ parser's own check compares each key with every earlier one; a `.nan` key
651
+ counts as a repeat, which only withholds a finding, and a key of 1,024 or more
652
+ characters is remembered by the SHA-256 digest of its UTF-16 code units,
653
+ because V8 hashes a long string by its length alone. For the same reason
654
+ `JSON.parse`, which interns the keys it builds, is quadratic over many long
655
+ keys of one length: each double-quoted run of 1,024 or more code units is
656
+ parsed alone, as a value, and shrunk to `""` before the text around it is
657
+ parsed. One string token in place of another leaves JSON validity unchanged,
658
+ so JSON verdicts hold exactly (repeated names, any JSON whitespace, nesting
659
+ deeper than the YAML parser reads). The whole confirmation path (walk, parse,
660
+ key check) is linear in the container's length. YAML's indentation rules relative to
661
+ an enclosing block are not applied, since the container is read alone. A seeded property in the spec checks that, in nested
662
+ flow text neither parser reads, a number never adds a finding, and that, for
663
+ its generated texts, readable YAML-only text reports a number finding only
664
+ where the scan of its parsed payload reports the same rule. That compares rule
665
+ names, not members: the YAML route confirms a numeric scalar at the judged
666
+ offset, while a payload built from the same YAML can differ (YAML keys `0` and
667
+ `"0"` are distinct, but a JavaScript object merges them), so it is not a
668
+ member-for-member parity claim. The number walk stops at that construct
669
+ without a finding, so inside a walked container YAML-only syntax may hide a
670
+ number but never creates or names one, and the walks stay linear. A walk that
671
+ ends without a finding, at such a construct, at a mismatched closer or at the
672
+ end of its text, also covers the complete containers it read before it: within
673
+ the same lexical scope, a discarded walk of an exact key
674
+ suppresses the walk of any key inside that range, and one of a prefixed key
675
+ suppresses only prefixed keys, so
676
+ such a key's numbers are not judged (a recorded miss, owned with the key scan
677
+ by pm-o1ntjo). Strings in
678
+ such a container are judged exactly as before. The key scan that starts each
679
+ walk is lexical, as it is for strings and flat assignments: a `password` key
680
+ written inside a comment, an anchor name, a tag URI or the continuation line of
681
+ a quoted string folded over a line break is read as text and starts its own
682
+ walk, so such a span can yield a number finding that YAML would not read
683
+ ([pm-o1ntjo](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-o1ntjo.toon)
684
+ owns a YAML-aware key scan; tracker record excluded from npm). A walk that starts
685
+ inside a quoted string value reads that string's text as standalone text with
686
+ its own quotes (a note string holding single-quoted fragments is read as those
687
+ fragments), descending into each enclosing string in turn, and none starts where a
688
+ quote earlier on the line leaves the text lexer unsure whether it is inside a
689
+ string: a container that closes inside the string's text is judged, one that
690
+ does not is not a container, and an outer container that skipped the string
691
+ never suppresses the walk inside it. No raw number walk starts inside a string
692
+ that holds a backslash where the text lexer reads backslashes as escapes, even
693
+ a trailing one with nothing after it to escape (the string walk there is
694
+ unchanged). A valid double-quoted JSON
695
+ string with an escape is judged through the text it decodes to (the decoded
696
+ reading below); any other such string, such as an escaping single-quoted Python
697
+ string, is not decoded, so the raw number walk does not read a container in it
698
+ (a recorded miss). A number directly after its key there is still judged as a
699
+ raw scalar (by the flat reading for a bare key, by the structured reading for a
700
+ quoted key), a valid JSON literal inside it is still decoded on its own, and a
701
+ single-quoted form the lexer reads as shell text keeps its container walk.
702
+ For the numeric metadata exemption, the number walk reads a double-quoted
703
+ member name as JSON decodes it (`"\u0065xp"` is `exp`); the key scan that
704
+ recognizes credential keys reads key names as written. Text is judged as written and a payload number as
705
+ `JSON.stringify` spells it, so `1e10` in text is the four characters written
706
+ there. The key scan reads key names as written; escaped and camelCase key
707
+ spellings, which a payload reads too, are
708
+ [pm-f89x9c](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-f89x9c.toon)
709
+ (tracker record excluded from npm). A number whose member name, decoded, is
710
+ numeric metadata is not judged in either reading: a JSON Schema
711
+ bound (`maximum`, `minimum`, `exclusiveMaximum`, `exclusiveMinimum`,
712
+ `multipleOf`, and the `max`/`min` `Length`, `Items`, `Properties` and
713
+ `Contains` keywords) or a time field of a token or session record (`exp`,
714
+ `iat`, `nbf`, `expires_at`, `expires_in`, `issued_at`, `not_before`,
715
+ `created_at`, `updated_at` and their camelCase spellings). A bigint of
716
+ more than 4096 digits is not converted: it is reported for review with
717
+ `normalization_incomplete: true`, like a value too large for a rule's pattern.
718
+ A boolean, null, non-finite number or boxed value is not judged. The pass
719
+ spells only a judged string or finite number with `JSON.stringify` (a bigint
720
+ as its digits); it never serializes the payload or any object in it, and never
721
+ calls a `toJSON` method. Each leaf is judged once per rule,
722
+ so the pass is linear in the payload. Findings are deduplicated by their
723
+ structural location (each entry's position under its parent, interned once per
724
+ scan), so a flagged name's `[key <n>]` placeholder and a literal property
725
+ spelled the same way never merge, however long the names above them are. When
726
+ the text pass and the member pass both report the same rule for a value at the
727
+ same location, the finding kept carries `normalization_incomplete` if either
728
+ did, so a member the member pass could not judge still needs review after the
729
+ text pass found an ordinary match there; a finding on the property name keeps
730
+ its own key and never merges with one on the value. Both passes walk the payload with their own stack, so payload
554
731
  depth is not limited by the call stack, and a deeply nested credential is
555
732
  blocked like a shallow one
556
733
  ([pm-wq9njf](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-wq9njf.toon);
@@ -558,6 +735,42 @@ tracker record excluded from npm). A value that is clean only as unquoted code,
558
735
  statement constant, is a string literal in a payload, as it already is in its
559
736
  JSON spelling.
560
737
 
738
+ A mutation string is also judged as the text each escaped JSON string in it
739
+ encodes
740
+ ([pm-rzojed](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-rzojed.toon);
741
+ tracker record excluded from npm). An escape can hide an assignment from the
742
+ text reading: in `"pm comments pm-x --add 'note\npassword=\"…\"'"` the `\n`
743
+ joins the letter `n` to the key and `\"` hides the quoted value. Every span
744
+ between consecutive unescaped double quotes on one line that holds a backslash
745
+ is decoded when it is a valid JSON string literal, and the decoded text is
746
+ judged again by every reading of every rule (the home-path views included), up
747
+ to three string levels deep, so a rendered recovery command keeps its findings inside a JSON
748
+ envelope. A span with a backslash JSON
749
+ does not define as an escape (a regular expression's `\.`, a Windows path, a
750
+ YAML-only or Python-only escape) is not a JSON string and keeps its text as
751
+ written. The inventory rules skip a decoded text shorter than seven UTF-16 code
752
+ units only under a conservative test: the text is ASCII without `%` or a
753
+ backslash. Seven units is the shortest concrete finding any inventory rule
754
+ reports in text as it stands; it does not bound warnings, because a home-path
755
+ view can rewrite text before judging it (NFKC folds a circled 25 to two
756
+ digits, so a five-unit literal can stay encoded after the last pass and raise
757
+ an incomplete-inspection warning). Every view leaves ASCII without `%` or a
758
+ backslash unchanged, so such text holds no finding and raises no warning; any
759
+ other short text is judged, including some that no view would change (`é`).
760
+ A rule outside the inventory carries no such minimum and judges every decoded
761
+ literal. A finding from
762
+ this reading records the `json_unescape` normalization and never returns the
763
+ decoded text. Because spans between consecutive quotes partition a line, a
764
+ stray prose quote cannot misalign a literal, and each level reads each
765
+ character once. The reading only adds findings, and each judged string's
766
+ literals are decoded once for the inventory rules, on a decode node they
767
+ share (a scan that also runs rules outside the inventory decodes them once more
768
+ for those). The
769
+ repository gate reads files as written: it still reports whatever a file's
770
+ text matches as written, but not a finding that only this decoded reading
771
+ makes, such as a synthetic detector fixture that tracker history records
772
+ inside an escaped JSON string.
773
+
561
774
  Property names are text too
562
775
  ([pm-x07qz2](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-x07qz2.toon);
563
776
  tracker record excluded from npm). Every property name in a payload is judged
@@ -576,7 +789,10 @@ characters that exhausts the regex stack) fails closed for itself: the guard
576
789
  reports it under that rule with `normalization_incomplete: true` for explicit
577
790
  review, and keeps scanning every other leaf, instead of letting the error make
578
791
  the whole scan fail open. Any other detector error still yields the
579
- `secret_guard_scan_failed_open` advisory.
792
+ `secret_guard_scan_failed_open` advisory. A rule that reports an ordinary
793
+ match in a leaf keeps scanning that leaf for an incomplete one, so the flag
794
+ survives for every rule (it once did only for the home-path rule): a policy
795
+ that allows the ordinary finding still sees that the leaf needs review.
580
796
 
581
797
  A private address or host path can be legitimate project context. The default
582
798
  remains advisory; a workspace selecting `block` must replace those literals
@@ -163,6 +163,11 @@ certificate. Subsequent pages carry `continuation_contract` with
163
163
  `metadata: "reference"` and `restore_with: "omit --after"`; repeated metadata
164
164
  is optional in `PmReadOutputProducerContinuation<Result>`. Follow `next_cursor`
165
165
  until it is empty, rather than relying on the optional `has_more` field.
166
+ An extension command's `--after` continues a page only when its value carries
167
+ the SDK query-cursor envelope. A package operand that happens to be named
168
+ `--after` keeps its first-page metadata
169
+ ([pm-gh1798](https://github.com/unbraind/pm-cli/blob/main/.agents/pm/issues/pm-gh1798.toon);
170
+ tracker record excluded from npm).
166
171
 
167
172
  Calls whose options contain no producer cursor retain their first-page types.
168
173
  Omitting the options argument has the same precise type as passing `{}` for