@unbrained/pm-cli 2026.11.12 → 2026.11.13
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +11 -0
- package/dist/cli-bundle/bundle-manifest.json +1 -1
- package/dist/cli-bundle/chunks/{chunk-3DWEBVIK.js → chunk-36E4L2R4.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-FJNHTBJ2.js → chunk-4WD4CHVH.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-OBTU2BHJ.js → chunk-5LG5YZYF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UY7Z3ZHQ.js → chunk-6UXBWMEM.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-OFIXSWJS.js → chunk-CO7RWLCM.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-COTC2QOR.js +6 -0
- package/dist/cli-bundle/chunks/{chunk-6ESY4Y2B.js → chunk-FAYX6C7H.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-PS2YAPXC.js → chunk-GIAJX2QJ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-GLPUIQDB.js → chunk-GWVP23RZ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-GDS4DC5A.js → chunk-GXGMMIZN.js} +4 -4
- package/dist/cli-bundle/chunks/{chunk-PZI6CR24.js → chunk-HQINCDF6.js} +47 -47
- package/dist/cli-bundle/chunks/{chunk-U7MZIX3D.js → chunk-IYDIPXBO.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-KJL42AN5.js → chunk-L4F4ZHGR.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-T4UC3ZKL.js → chunk-LKVFPQNY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-MR3CRLA7.js → chunk-O6PBQMD7.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-5NY6EQSX.js → chunk-O6T24Z3M.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-L3SA3354.js → chunk-OQCVU2SG.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-2DUUL53Z.js → chunk-PUU5DXSV.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-QSSENTXG.js +20 -0
- package/dist/cli-bundle/chunks/{chunk-UTNPDAID.js → chunk-TCYIGAQG.js} +31 -31
- package/dist/cli-bundle/chunks/chunk-UFZQPKQS.js +124 -0
- package/dist/cli-bundle/chunks/{chunk-EALO2FPM.js → chunk-URWNUZQZ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-2K6GJUW7.js → chunk-UYARS5XF.js} +2 -2
- package/dist/cli-bundle/chunks/{item-revision-SYJT6TVZ.js → item-revision-G5OVYGZ5.js} +2 -2
- package/dist/cli-bundle/chunks/item-transaction-I2X2P4TW.js +2 -0
- package/dist/cli-bundle/chunks/{mutation-admission-T57TAVWI.js → mutation-admission-SET4KY73.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-5XZXTPNG.js → register-list-query-JNJY2D3N.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-V6WJFL77.js → register-mutation-WTHZHPOP.js} +2 -2
- package/dist/cli-bundle/chunks/{register-operations-5RAWXY2F.js → register-operations-EZP3EG6A.js} +2 -2
- package/dist/cli-bundle/chunks/{register-setup-HCKCSQWQ.js → register-setup-THFZP23A.js} +2 -2
- package/dist/cli-bundle/chunks/{stage-VIDXGF3T.js → stage-JXJILTYE.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-2ZPGEGTB.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-NSOXVVQX.js → chunk-3MB47JLT.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-5OCUNAQN.js → chunk-4LFE3FQL.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-5KTOMFLR.js +44 -0
- package/dist/cli-bundle/focused-chunks/{chunk-MK7UQEE5.js → chunk-5NTLNE54.js} +18 -18
- package/dist/cli-bundle/focused-chunks/{chunk-P6KYUJD4.js → chunk-ADBFVDTG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-AXPRCCYM.js → chunk-CSKDIMQP.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-IPIFI4NT.js → chunk-FNIX62V6.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-VUNX6NBR.js → chunk-IYV3IPRF.js} +51 -51
- package/dist/cli-bundle/focused-chunks/{chunk-KN7RBRRH.js → chunk-J3LQQP3N.js} +22 -22
- package/dist/cli-bundle/focused-chunks/{chunk-BHYGUVAU.js → chunk-JR75B6HU.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-NP5C2TQM.js → chunk-Q3OA5OAK.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-TZO6L523.js → chunk-QGQJBQCH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-GB2N4OM7.js → chunk-RIMNSVFA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-GBW2EAAG.js → chunk-TVJ2PHAK.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-LAIN47EJ.js → chunk-VGFKTSGY.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-RXY6BFRW.js → chunk-VGJDKDKA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-VGUQ4V47.js +82 -0
- package/dist/cli-bundle/focused-chunks/chunk-VTOTZ5UC.js +91 -0
- package/dist/cli-bundle/focused-chunks/{chunk-SPAEZKVA.js → chunk-WFVZ7GGR.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-3FN4ON2Z.js → chunk-ZJF6ZA7B.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-GAXO2UQX.js → chunk-ZOGEQFGH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{item-revision-PWJNBW3F.js → item-revision-IF7E7BVY.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{item-transaction-T6HXC3NS.js → item-transaction-5TFWIOXI.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{mutation-admission-CLPOLSXZ.js → mutation-admission-KELM46JF.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{stage-EKYWEU2Y.js → stage-UAKMQTCI.js} +2 -2
- package/dist/cli-bundle/main.js +2 -2
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +1 -1
- package/dist/cli-bundle/sdk-core.js +1 -1
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +57 -57
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +1 -1
- package/dist/core/history/history-rewrite.js +1 -1
- package/dist/core/schema/runtime-field-values.js +1 -1
- package/dist/core/shared/author.js +2 -2
- package/dist/core/shared/secret-rules.d.ts +8 -2
- package/dist/core/shared/secret-rules.js +3 -3
- package/dist/core/shared/url-credentials.d.ts +33 -5
- package/dist/core/shared/url-credentials.js +1 -1
- package/dist/core/store/item-store.js +1 -1
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -1
- package/dist/sdk/lifecycle/claim.js +1 -1
- package/dist/sdk/lifecycle/create.js +1 -1
- package/dist/sdk/lifecycle/restore.js +1 -1
- package/dist/sdk/lifecycle/update.js +2 -2
- package/dist/sdk/ownership-source.js +1 -1
- package/docs/MUTATION_INTEGRITY.md +56 -6
- package/marketplace.json +1 -1
- package/package.json +1 -1
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-digital-twin/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-claude/package.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/pm-codex/package.json +1 -1
- package/plugins/pm-codex/plugin.json +1 -1
- package/runtime-dependencies.json +1 -1
- package/dist/cli-bundle/chunks/chunk-5NGGI7JC.js +0 -6
- package/dist/cli-bundle/chunks/chunk-A7L5IEYV.js +0 -20
- package/dist/cli-bundle/chunks/chunk-FOT5K5OM.js +0 -124
- package/dist/cli-bundle/chunks/item-transaction-YXZ27UC6.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-AIYJHVKV.js +0 -44
- package/dist/cli-bundle/focused-chunks/chunk-BB2GMKRB.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-HIKZYZ26.js +0 -82
- package/dist/cli-bundle/focused-chunks/chunk-NY65XTX7.js +0 -91
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as R}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{b as R}from"./chunk-CO7RWLCM.js";import{Va as E,Xa as D,Za as T,_a as H}from"./chunk-UFZQPKQS.js";import{Ad as p,Bi as b,Fa as c,Ff as u,Fi as w,Na as y,Xd as g,dj as x,pj as M,qi as _,si as I,ti as v}from"./chunk-HQINCDF6.js";import{A as f,C as l}from"./chunk-O4ZLEN4T.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="eb2e6046-156c-56ee-a03a-ecaa1cccfb45")}catch{}})();function K(e,t){let i=w(e),s=e.length>0?e[e.length-1].after_hash:v(),a=t===void 0||i.item_hash_version===void 0?void 0:I(t,i.item_hash_version,g(e.at(-1)?.hash_algorithm)),n=t===void 0?void 0:a===void 0?_(t):a[Math.max(0,a.indexOf(s))],o=n===void 0?void 0:n===s,r=[...i.errors];return o===!1&&r.push("verify_failed:current_item_hash_mismatch"),{ok:r.length===0,entries:e.length,errors:r,latest_after_hash:e.length>0?e[e.length-1].after_hash:void 0,current_item_hash:n,current_matches_latest:o}}async function Q(e,t,i={}){let s=y(i.cwd??process.cwd(),i.pmRoot);await M(s);let a=await x(s),n=c(a,p()),o=await R(s,e,a,n.type_to_folder),r=await u(o.historyPath,o.id);if(r.length===0)throw new l(`No history exists for ${o.id}; point-in-time reads are unavailable.`,f.NOT_FOUND);let d=D(t,r),C=H(T(r,d.historyIndex),d),m=b(C,{schema:a.schema});if(m.metadata.id!==o.id)throw new l(`History target resolved to item ${m.metadata.id}, expected ${o.id}.`,f.GENERIC_FAILURE);let k=r[d.historyIndex],h=E(r,!0);return{document:m,reconstructed:!0,as_of_version:h===null?null:h+d.historyIndex+1,as_of_timestamp:k.ts,target:d,history_length:r.length}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e524f0ad-faad-5d89-b8f5-1283979919ad")}catch{}})();export{K as a,Q as b};
|
|
2
|
+
//# sourceMappingURL=chunk-IYDIPXBO.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{kb as h}from"./chunk-PS2YAPXC.js";import{$ as g,Hb as $,Ib as R,Nb as V,Uh as U,Vf as L,Wb as v,Wf as W,X as w,Y as k,Z as F,_ as A,aa as C,gb as D,kc as B,lc as z,sf as G,t as N,tf as S,u as p,w as E,x as M,y as I}from"./chunk-PZI6CR24.js";import{A as y,C as _}from"./chunk-O4ZLEN4T.js";import{Command as ae}from"commander";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a851f5ac-99a5-5061-a0c3-a08d898ea20b")}catch{}})();function nt(e){return new ae().name("pm").description("Universal, flexible, extensible, agent-optimized project management CLI for any project or programming language.").version(e).showHelpAfterError(!1).allowExcessArguments(!1).allowUnknownOption(!1).configureOutput({writeOut:t=>{U(t)},writeErr:()=>{}}).option("--json","Output JSON instead of TOON; mutations emit a flat receipt with top-level id/status/changed_field_count while reads use documented entity or collection envelopes").option("--lean","Omit null and empty containers from JSON output").option("--token-accounting","Attach a bounded per-section token-cost receipt to command output").option("--output-include <fields>","Retain comma-separated fields or sections in read output").option("--output-limit <count>","Bound rows in read output").option("--output-budget <tokens|unbounded>","Bound estimated tokens in read output or explicitly disable the default ceiling").option("--output-format <toon|json>","Select the result encoding for reads and mutations").option("--output-session <state>","Carry a JSON session budget and served-item ledger across read calls").option("--output-cursor <cursor>","Resume continuation_kind=output_cursor").option("--output-row-contract","Include row selectors, encoding metadata, and read-output receipts").option("--quiet","Suppress stdout output").option("--no-changed-fields","Omit the changed_fields array from mutation output (keeps changed_field_count)").option("--full-changed-fields","Restore the legacy full mutation envelope and changed_fields array").option("--id-only","Print only id and status for single-item mutation output").option("--pm-path <dir>","Explicit tracker storage path for this command (preferred over --path)").option("--path <dir>","Backward-compatible alias for --pm-path; this is the tracker storage path, not a workspace cwd").option("--no-extensions","Disable extension loading").option("--no-pager","Disable pager integration for help and long output").option("--explain","Render extended rationale and examples in help output").option("--all","Reveal every public command and compatibility alias").option("--profile","Print deterministic timing diagnostics").option("--author <id>","Override mutation author for this invocation").option("--expect-hash <revision>","Refuse writes to the named item unless it is still at this item_hash from pm get (a bare hash names the command's <id>; guard each other item with <id>=<item_hash>, repeatable)",(t,n)=>[...n??[],t]).exitOverride()}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8efedca0-725e-520f-ad06-825a0cccddaa")}catch{}})();var j=new Set(["append","claim","close","close-task","comments","copy","delete","deps","docs","files","focus","get","history","history-compact","history-redact","history-repair","learnings","notes","pause-task","release","restore","start-task","test","update"]),q=new Map([["files","discover"],["item","complete"]]),le=new Map([["append",1],["close",1],["close-task",1],["comments",1],["item complete",1],["learnings",1],["notes",1],["restore",1]]);function K(e){let t=p(e?.trim().toLowerCase()??"");return j.has(t)||q.has(t)}function ce(e,t,n){let o=j.has(n)?t+1:void 0,s=g(e.slice(t+1));if(s===void 0)return o;let r=t+1+s,a=`${n} ${e[r]}`,i=p(a);return i===a?n==="item"&&e[r]==="complete"?r+1:o:K(i)?P(e,r,i):void 0}function P(e,t,n){if(["history","context","ctx","update","close","item"].includes(n))return ce(e,t,n);let o=q.get(n);if(o===void 0)return t+1;let s=e[t+1]?.toLowerCase()===o;return t+(s?2:1)}function ue(e){let t=new Map;for(let n of h(e))for(let o of[n.flag,n.short,...n.aliases??[]])o&&t.set(o,n);return t}function de(e){let t=[];for(let n=0;n<e.length;n+=1){let o=e[n];if(o==="--")break;o==="--id"?(t.push({index:n,consumed:2,value:e[n+1]}),n+=1):o.startsWith("--id=")&&t.push({index:n,consumed:1,value:o.slice(5)})}return t}function fe(e,t,n){if(e.indexOf("=")>=0||t===void 0||t.startsWith("-"))return!1;let o=n.get(e);return o!==void 0&&o.value_type!=="boolean"}function pe(e,t,n,o,s){let r=0;for(let a=t;a<e.length;a+=1){let i=e[a];if(i==="--")break;if(i==="--id"){a+=1;continue}if(!i.startsWith("--id=")){if(!i.startsWith("-")){if(a<o)return!0;r+=1;continue}fe(i,e[a+1],s)&&(a+=1)}}return r>(le.get(p(n))??0)}function Y(e){let t=g(e),n=t===void 0?void 0:e[t]?.toLowerCase();if(n!=="context"&&n!=="ctx"&&!K(n))return{argv:[...e],changed:!1,conflict:!1};let o=P(e,t,n);if(o===void 0)return{argv:[...e],changed:!1,conflict:!1};let s=o>t+1?`${p(e.slice(t,o-1).join(" "))} ${e[o-1]}`:n,r=ue(s),a=de(e),i=a[0];if(!i||!i.value?.trim())return{argv:[...e],changed:!1,conflict:!1};if(a.length>1||pe(e,o,s,i.index,r))return{argv:[...e],changed:!1,conflict:!0,itemId:i.value};let l=[...e.slice(0,i.index),...e.slice(i.index+i.consumed)],c=g(l),u=P(l,c,n);return l.splice(u,0,i.value),{argv:l,changed:!0,conflict:!1,itemId:i.value}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7b271a35-800c-52bf-9368-0410e76b8d4e")}catch{}})();var me=new Set(["--output-include","--output-limit","--output-budget","--output-format","--output-session","--output-cursor"]),he=new Set(["toon","json"]);function ge(e,t,n){let o=e[t];if(k.has(o))return n.booleanFlags.add(o),1;let s=o.indexOf("="),r=s>0?o.slice(0,s):o;if(!w.has(r))return 1;let a=s>0?o.slice(s+1):void 0,i=a===void 0&&A(r,e[t+1]),l=a??(i?e[t+1]:void 0);return r==="--author"?n.author=l??"":typeof l=="string"&&l.length>0&&(me.has(r)?n.outputValues:n.pathValues).set(r,l),i?2:1}function be(e){return e.outputValues.get("--output-format")!=="toon"&&(e.booleanFlags.has("--json")||e.outputValues.get("--output-format")==="json"||e.pathValues.get("--format")?.trim().toLowerCase()==="json")}function ye(e){let t={booleanFlags:new Set,outputValues:new Map,pathValues:new Map},n=0;for(;n<e.length&&e[n]!=="--";)n+=ge(e,n,t);return{path:t.pathValues.get("--pm-path")??t.pathValues.get("--path"),noExtensions:t.booleanFlags.has("--no-extensions")||["history attest","history-attest"].includes(ee(e)??""),noPager:t.booleanFlags.has("--no-pager"),json:be(t),quiet:t.booleanFlags.has("--quiet"),lean:t.booleanFlags.has("--lean"),tokenAccounting:t.booleanFlags.has("--token-accounting"),...t.booleanFlags.has("--output-row-contract")?{outputRowContract:!0}:{},...t.outputValues.get("--output-include")===void 0?{}:{outputInclude:t.outputValues.get("--output-include")},...t.outputValues.get("--output-limit")===void 0?{}:{outputLimit:t.outputValues.get("--output-limit")},...t.outputValues.get("--output-budget")===void 0?{}:{outputBudget:t.outputValues.get("--output-budget")},...he.has(t.outputValues.get("--output-format"))?{outputFormat:t.outputValues.get("--output-format")}:{},...t.outputValues.get("--output-session")===void 0?{}:{outputSession:t.outputValues.get("--output-session")},...t.outputValues.get("--output-cursor")===void 0?{}:{outputCursor:t.outputValues.get("--output-cursor")},...t.author===""?{authorMissingValue:!0}:t.author!==void 0?{author:t.author}:{}}}function Z(e){let t=[],n=0;for(;n<e.length;){let o=e[n];if(o==="--")break;if(k.has(o)||o==="--profile"||o==="--id-only"||o==="--full-changed-fields"||o==="--explain"){n+=1;continue}if(w.has(o)){n+=A(o,e[n+1])?2:1;continue}if(F(o)){n+=1;continue}t.push(o),n+=1}return t}function _e(e){let t=Z(e);if(t[0]?.trim().toLowerCase()==="help"){let o=[];for(let s=1;s<t.length;s+=1){let r=t[s];if(r.startsWith("-"))break;o.push(r.trim().toLowerCase())}return{requested:!0,commandPathTokens:o}}if(t.findIndex(o=>o==="--help"||o==="-h")<0)return{requested:!1,commandPathTokens:[]};let n=[];for(let o of t){if(o.startsWith("-"))break;n.push(o.trim().toLowerCase())}return{requested:!0,commandPathTokens:n}}function T(e){return g(e)}function we(e){return C(e)}function Ie(e,t){return t.noPager?!0:process.stdout.isTTY===!0?!1:_e(e).requested}function bt(e){let t=["PAGER","MANPAGER","GIT_PAGER","LESS"],n=t.map(r=>process.env[r]),o=()=>{for(let[r,a]of t.entries()){let i=n[r];i===void 0?delete process.env[a]:process.env[a]=i}},s=ye(e);return Ie(e,s)&&(process.env.PAGER="cat",process.env.MANPAGER="cat",process.env.GIT_PAGER="cat",(typeof process.env.LESS!="string"||process.env.LESS.trim().length===0)&&(process.env.LESS="FRX")),o}var ke=new Set(["install","uninstall","explore","manage","doctor","adopt","adopt-all","activate","deactivate"]);function Ce(e){let t=T(e);if(t===void 0||e[t]!=="extension")return[...e];let n=e[t+1];if(!n||n.startsWith("-"))return[...e];if(!ke.has(n))return[...e];if(e.includes("--help")||e.includes("-h"))return[...e];let o=`--${n}`;return e.includes(o)?[...e]:[...e.slice(0,t+1),o,...e.slice(t+2)]}var ve=new Set(["pm","pm-cli"]);function Se(e,t){let n=T(e);if(n===void 0)return e;let o=e[n];return ve.has(o.trim().toLowerCase())?(t.push({from:o,to:[],reason:"executable_alias",confidence:"high"}),[...e.slice(0,n),...e.slice(n+1)]):e}function Te(e,t){let n=T(e);if(n!==void 0&&e[n]==="help"){let i=T(e.slice(n+1));n=i===void 0?void 0:n+1+i}if(n===void 0)return e;let o=e[n],s=M[o.trim().toLowerCase()];if(!s)return e;let r=s.split(" "),a=[...e.slice(0,n),...r,...e.slice(n+1)];return t.push({from:o,to:r,reason:"command_alias",confidence:"high"}),a}function x(e){return e.replace(/^--?/,"").replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function X(e){return x(e).replace(/-/g,"")}function J(e,t,n){let o=e.get(t);if(o===void 0){e.set(t,n);return}o!==n&&e.set(t,null)}function xe(e){let t=[],n=o=>{typeof o=="string"&&o.startsWith("--")&&t.push(o)};n(e.flag);for(let o of e.aliases??[])n(o);return t}function Oe(e,t){let n=t??h(e),o=new Map,s=new Map,r=new Map,a=new Set;for(let i of n){let l=xe(i);if(l.length===0)continue;let c=`--${x(l[0])}`;for(let d of l)J(o,x(d),c),J(s,X(d),c);let u=X(c);r.has(c)||r.set(c,u),i.list===!0&&a.add(c)}return{canonicalByNormalized:o,canonicalByCompact:s,canonicalComparables:[...r.entries()].map(([i,l])=>({canonicalFlag:i,comparable:l})),listCanonicalFlags:a}}function H(e,t){let n=x(e),o=t.canonicalByNormalized.get(n);if(typeof o=="string")return{flag:o,reason:"flag_alias",confidence:"high"};let s=n.replace(/-/g,""),r=t.canonicalByCompact.get(s);if(typeof r=="string")return{flag:r,reason:"flag_alias",confidence:"high"};let a=s.length>=8?2:1,i=Number.POSITIVE_INFINITY,l,c=!1;for(let u of t.canonicalComparables){let d=v(s,u.comparable,a);if(d!==null){if(d<i){i=d,l=u.canonicalFlag,c=!1;continue}d===i&&l!==u.canonicalFlag&&(c=!0)}}return!l||c||!Number.isFinite(i)||i<=0?null:{flag:l,reason:"flag_typo",confidence:i>=2?"medium":"high"}}function yt(e){let t=[`${e}s`];return e.endsWith("y")&&e.length>1&&t.push(`${e.slice(0,-1)}ies`),t}function Ee(e,t=!1){if(t||e.includes("://"))return null;let n=e.match(/^([A-Za-z][A-Za-z0-9_-]{1,63})([:=])(.*)$/);if(!n)return null;let o=n[1],s=n[3];return s.length===0?null:{key:o,value:s}}function Ae(e,t,n=!1){if(n||!e.startsWith("--"))return{tokens:[e]};let o=e.indexOf("="),s=o>=0?e.slice(0,o):e,r=o>=0?e.slice(o+1):void 0,a=H(s,t);if(!a)return{tokens:[e]};let i=r===void 0?a.flag:`${a.flag}=${r}`;return i===e?{tokens:[e]}:{tokens:[i],event:{from:e,to:[i],reason:a.reason,confidence:a.confidence}}}function Le(e){let t=new Set,n=!1;for(let o=0;o<e.length;o+=1){if(n){t.add(o),n=!1;continue}let s=e[o];n=s==="--path"||s==="--pm-path"}return t}function Pe(e){if(!e.startsWith("--"))return null;let t=e.indexOf("=");return t<0?{flag:e}:{flag:e.slice(0,t),inlineValue:e.slice(t+1)}}function Ne(e,t,n){n.push(e[t]);let o=e[t+1];return typeof o=="string"&&o!=="--"?(n.push(o),t+2):t+1}function Me(e,t,n,o){if(n.inlineValue!==void 0)return{originalTokens:[e[t]],value:n.inlineValue,consumed:1};let s=[],r=t+1;for(;r<e.length&&e[r]!=="--"&&!e[r].startsWith("-")&&(s.length===0||o.has(n.flag));)s.push(e[r]),r+=1;let a=s.length===0?1:1+s.length;return{originalTokens:e.slice(t,t+a),value:s.length===0?void 0:s.join(","),consumed:a}}function Fe(e,t,n,o){let s=e.get(n);if(s){s.values.push(o.value),s.occurrences+=1;return}e.set(n,{outputIndex:t.length,originalTokens:o.originalTokens,values:[o.value],occurrences:1}),t.push(null)}function De(e,t){let n=[],o=[];for(let[s,r]of e){if(!(r.occurrences>=2||t.has(s)&&r.originalTokens.length>2)){o.push({outputIndex:r.outputIndex,tokens:r.originalTokens});continue}let a=`${s}=${r.values.join(",")}`;o.push({outputIndex:r.outputIndex,tokens:[a]}),n.push({from:`${s} (x${r.occurrences})`,to:[a],reason:"list_merge",confidence:"high"})}return{events:n,splices:o}}function $e(e,t){t.sort((n,o)=>o.outputIndex-n.outputIndex);for(let n of t)e.splice(n.outputIndex,1,...n.tokens)}function Re(e,t,n=new Set,o=new Set){if(t.size===0)return{argv:[...e],events:[]};let s=[],r=new Map,a=0;for(;a<e.length;){let c=e[a];if(c==="--"){s.push(...e.slice(a));break}if(n.has(c)){a=Ne(e,a,s);continue}let u=Pe(c);if(!u||!t.has(u.flag)){s.push(c),a+=1;continue}let d=Me(e,a,u,o);if(d.value===void 0){s.push(c),a+=d.consumed;continue}Fe(r,s,u.flag,{originalTokens:d.originalTokens,value:d.value}),a+=d.consumed}let{events:i,splices:l}=De(r,o);return $e(s,l),{argv:s,events:i}}var Q=new Map([["--add",new Set(["command","cmd","path"])],["--remove",new Set(["command","path"])]]);function Ve(e,t){if(e!=="test"||t.length<2)return!1;let n=t[t.length-1],o=t[t.length-2],s=Q.get(o);return s!==void 0&&s.has(n)}function Be(e,t,n){if(t!=="test")return e;let o=[],s=0;for(;s<e.length;){let r=e[s];if(r==="--")return o.push(...e.slice(s)),o;let a=Q.get(r),i=a?e[s+1]:void 0;if(!a||typeof i!="string"||!a.has(i)){o.push(r),s+=1;continue}let l=s+2;for(;l<e.length&&!e[l].startsWith("-");)l+=1;if(l-(s+2)!==1){o.push(r),s+=1;continue}let c=e[s+2],u=`${i}=${c}`;o.push(r,u),n.push({from:`${r} ${i} ${c}`,to:[r,u],reason:"bare_key_value",confidence:"high"}),s+=3}return o}function ze(e,t,n,o){let s=[],r=Le(e);for(let a=0;a<e.length;a+=1){let i=e[a];if(i==="--"){s.push(...e.slice(a));break}let l=r.has(a),c=s[s.length-1];if(i.startsWith("--")){let b=Ae(i,t,l);s.push(...b.tokens),b.event&&o.push(b.event);continue}let u=Ee(i,l);if(!u||typeof c=="string"&&c.startsWith("-")&&!c.includes("=")||["search","comments","notes","learnings"].includes(n)||Ve(n,s)){s.push(i);continue}let d=H(u.key,t);if(!d){s.push(i);continue}let m=u.value.startsWith("-")?[`${d.flag}=${u.value}`]:[d.flag,u.value];s.push(...m),o.push({from:i,to:m,reason:"bare_key_value",confidence:d.confidence})}return s}function Ge(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--verify"){let o=e[t+1];if(o===void 0||o==="--")throw new _("history attest --verify requires a bundle file.",y.USAGE);e.splice(t,2,`--verify=${o}`)}else(w.has(n)||n==="--output"||n==="--hash-algorithm")&&(t+=1)}}function We(e,t){if(!e.some(o=>o==="--help"||o==="-h"))return;let n=new Set(h(t).flatMap(o=>[o.flag,...o.aliases??[],...o.short===void 0?[]:[o.short]]));for(let o=0;o<e.length;o+=1){let s=e[o];if(s==="--")break;s!=="--help"&&s!=="-h"||n.has(e[o-1])&&!k.has(e[o-1])&&(e[o-1]=s)}}function _t(e){let t=[],n=Se(e,t),o=Ce(n);(o.length!==n.length||o.some((b,re)=>b!==n[re]))&&t.push({from:n.join(" "),to:[...o],reason:"legacy_extension_action",confidence:"high"});let s=Te(o,t),r=Y(s);if(r.conflict)throw new _("Provide the item id either positionally or with --id, not both.",y.USAGE);r.changed&&t.push({from:`--id ${r.itemId}`,to:[r.itemId],reason:"item_id_alias",confidence:"high"});let a=we(r.argv),i=ee(r.argv),l=p(i??a??""),c=Oe(i??a),u=ze(r.argv,c,l,t),d=Be(u,l,t),m=Re(d,c.listCanonicalFlags,w,a==="create"?new Set(["--tags"]):new Set);for(let b of m.events)t.push(b);return We(m.argv,i??a),i==="history attest"&&Ge(m.argv),{argv:m.argv,commandName:a,trace:t}}function ee(e){let t=Z(e),n=t[0]?.trim().toLowerCase(),o=t[1]?.trim().toLowerCase(),s=N(t);return s?s.canonical:(n==="extension"||n==="package"||n==="packages")&&typeof o=="string"&&o.length>0&&!o.startsWith("-")?`${n} ${o}`:n}function wt(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--type"){let o=e[t+1];if(typeof o=="string"&&o.trim().length>0)return o.trim();continue}if(n.startsWith("--type=")){let o=n.slice(7).trim();if(o.length>0)return o}}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="fb625cd9-f8a8-56cf-88ab-abef64051497")}catch{}})();function St(e){if(e===void 0)return()=>{};let t=e.trim();if(t.length===0)throw new _("--author requires a non-empty value.",y.USAGE,{code:"missing_required_argument",nextSteps:["Pass an explicit author identifier with --author <id>."]});let n=G();S(t);let o=!1;return()=>{o||(o=!0,n===void 0?S(void 0):S(n))}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d0e60f7e-e0a8-5ef4-9af7-4a1f102ccb7d")}catch{}})();var f=Object.freeze({clock:"PM_CLOCK",tickMs:"PM_CLOCK_TICK_MS",seed:"PM_SEED"});function O(e,t,n,o){return new _(e,y.USAGE,{code:"invalid_reproducible_process_environment",reason:t,field:n,required:`${f.clock} and ${f.seed}; ${f.tickMs} is optional`,nextSteps:[`Set ${f.clock} to an ISO-8601 instant with Z or a numeric UTC offset and ${f.seed} to a non-empty reproducibility seed.`,`Optionally set ${f.tickMs} to a non-negative integer; it defaults to 1.`,"Unset all three variables to retain normal wall-clock and cryptographic-random behavior."],recovery:{recovery_mode:"compact",provided_fields:o,missing_required_fields:t==="incomplete"?[f.clock,f.seed].filter(s=>!o.includes(s)):void 0}})}function Ue(e){let t=e[f.clock],n=e[f.tickMs],o=e[f.seed],s=[[f.clock,t],[f.tickMs,n],[f.seed,o]].filter(a=>a[1]!==void 0).map(([a])=>a);if(s.length===0)return;if(t===void 0||o===void 0)throw O("Reproducible process execution requires PM_CLOCK and PM_SEED together.","incomplete",t===void 0?f.clock:f.seed,s);if(o.trim().length===0)throw O(`${f.seed} must not be empty.`,"invalid_value",f.seed,s);if(!V(t))throw O(`${f.clock} must be a valid ISO-8601 instant with Z or a numeric UTC offset.`,"invalid_value",f.clock,s);let r=n===void 0?1:Number(n);if(n?.trim().length===0||!Number.isSafeInteger(r)||r<0)throw O(`${f.tickMs} must be a non-negative integer.`,"invalid_value",f.tickMs,s);return $({clock:t,seed:o,tickMs:r})}function je(e){let t=Ue(e);return t===void 0?n=>n():R(t)}async function Lt(e,t){return je(e)(t)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="94bdb20f-d193-5767-91f2-8207169b82d1")}catch{}})();var te=new Set([...Object.values(B),...z,"--full","--brief","--compact","--summary","--fields","--section","--token-budget"]),ne=new Set(["--full-changed-fields","--no-changed-fields","--id-only"]);function zt(e,t){if(!["block","unblock"].includes(e)||t.includes(e)||!t.includes("update"))return;let n=new Set(h("update").map(o=>o.flag));if((e==="block"?["--blocked-by","--blocked-reason"]:["--unset","--unblock-note"]).every(o=>n.has(o)))return e==="block"?{examples:[["update","<item-id>","--blocked-by","<blocker-id>","--blocked-reason","<reason>"]],nextSteps:["Choose the actual item and blocker identifiers before running update. --blocked-by records the blocker field and its blocked_by relationship."]}:{examples:[["update","<item-id>","--unset","blocked-by","--unset","blocked-reason","--unblock-note","<note>"]],nextSteps:[`Inspect the item's blockers before running update. --unset blocked-by removes the blocker field and the blocked_by rows naming it; other blocked_by relationships stay, so remove one with --dep-remove "id=<id>,kind=blocked_by" or all with --dep-remove kind=blocked_by. --unset blocked-reason clears the stale reason. --unblock-note alone records a note and does not unblock the item.`,"If your project also uses a blocked lifecycle status, choose its appropriate next status separately with update --status."]}}function qe(e,t){let n=e.includes("="),o=n?e.slice(e.indexOf("=")+1):t;if(!(!o||o.startsWith("--")))return{consumed:n?1:2,replacement:["--from",o],conflicts:["--from"]}}var Ke=["--depth","--output-include","--fields","--section","--for"];function Ye(e){let t=L(p(e.trim().toLowerCase()));if(t===void 0)return;let n=h(t),o=n.flatMap(a=>[a.flag,...a.aliases??[]]),s=[...W(t).keys()].filter(a=>o.includes(`--${a}`)),r=[...n.find(a=>a.flag==="--depth")?.values??[]];if(!(s.length===0&&r.length===0))return{command:t,modes:s,depth_values:r,declared_flags:o}}function Gt(e){return[...e.depth_values.length>0?[`--depth ${e.depth_values.join("|")}`]:[],...e.modes.map(t=>`--${t}`)].join(", ")}function Xe(e,t,n,o){let s=Ye(e);if(s===void 0||s.declared_flags.includes(t))return;let r=[...Ke,...s.modes.map(i=>`--${i}`)].filter(i=>i!==t);if(t==="--depth"){let i=n.includes("="),l=(i?n.slice(n.indexOf("=")+1):o)?.trim().toLowerCase();if(!l)return;let c=i?1:2;return s.modes.includes(l)?{consumed:c,replacement:[`--${l}`],conflicts:r}:l==="standard"?{consumed:c,replacement:[],conflicts:r}:void 0}let a=t.slice(2);return n===t&&s.depth_values.includes(a)?{consumed:1,replacement:["--depth",a],conflicts:r}:void 0}function Je(e,t,n,o){return t==="--since"&&e==="activity"?qe(n,o):t==="--toon"&&n===t?{consumed:1,replacement:["--output-format","toon"],conflicts:["--json","--format","--output-format","--stream"]}:Xe(e,t,n,o)}function Ze(e){let t=g(e);if(t===void 0)return;let n=e[t].trim().toLowerCase(),o=`${n} ${e[t+1]?.trim().toLowerCase()??""}`,s=p(o);return s!==o.trim()?s:n==="ctx"?"context":p(n)}function Wt(e,t,n){let o=e==="ctx"?"context":p(e);if(L(o)===void 0||t.includes("--")||Ze(t)!==o)return;let s=n.split("=",1)[0],r=t.flatMap((d,m)=>d===s||d.startsWith(`${s}=`)?[m]:[]);if(r.length!==1)return;let a=r[0],i=Je(o,s,t[a],t[a+1]);if(!i)return;let{replacement:l,consumed:c,conflicts:u}=i;if(!t.some(d=>u.includes(d.split("=",1)[0])))return[...t.slice(0,a),...l,...t.slice(a+c)]}function oe(e){let t=e.split("=",1)[0].replaceAll("_","-");return te.has(t)||t.length>=5&&[...te].some(n=>n.startsWith(t))}function Ut(e,t){let n=e.split("=",1)[0].replaceAll("_","-");return oe(n)?!ne.has(t):ne.has(n)?!oe(t):!0}function se(e){return e.trim().match(/--[a-z0-9][a-z0-9_-]*/i)?.[0]?.replaceAll("_","-").toLowerCase()}function jt(e){if(!(!Array.isArray(e)||e.length===0))return C(e)}function He(e,t){let n=se(t);if(!n)return;let o=h(e).find(s=>s.flag===n||s.aliases?.includes(n));return o?o.value_type==="boolean"?null:`<${o.value_name??"value"}>`:"<value>"}function qt(e,t,n){let o=[...e],s=o.indexOf("--"),r=s<0?o.length:s;for(let a of n){let i=se(a);if(!i||o.slice(0,r).some(u=>u===i||u.startsWith(`${i}=`)))continue;let l=He(t,i),c=l?[i,l]:[i];o.splice(r,0,...c),r+=c.length}return o.length===e.length?void 0:D(o)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="bd9a8d3b-bc6f-5309-a3fb-7e5f41ef9dab")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="12066389-daef-5fce-b7a6-0ecffa926d66")}catch{}})();function Qt(e,t){let n=e.trim().split(/\s+/u);if(!(n.length<2||t.includes(n.join(" "))))for(let o=1;o<n.length;o+=1){if(!t.includes(n.slice(0,o).join(" ")))return;let s=n.slice(o).join(" "),r=I(s),a=new Set(t.filter(i=>i===s||i.endsWith(` ${s}`)||i===r?.canonical).map(i=>I(i)?.canonical??i).filter(i=>t.includes(i)));if(a.size>0)return a.size===1?[...a][0]:void 0}}var Qe={add:["create","append"],fetch:["get"],inspect:["get","health"],log:["history","comments","notes"],ls:["list"],pause:["release"],read:["get"],remove:["delete"],rm:["delete"],show:["get"],start:["start-task"]};function ie(e,t){let n=e.trim().toLowerCase(),o=t.trim().toLowerCase();if(o.length===0)return Number.POSITIVE_INFINITY;let s=n.split(" "),r=Qe[o]?.indexOf(p(n));if(r!==void 0&&r>=0)return r;if(n===o)return 10;if(s.includes(o))return 11;if(s.some(l=>l.startsWith(o)))return 12;let a=o.length>=5?2:1,i=Number.POSITIVE_INFINITY;for(let l of s){let c=v(l,o,a);c!==null&&(i=Math.min(i,c))}return Number.isFinite(i)?20+i:n.includes(o)?30:Number.POSITIVE_INFINITY}function en(e,t){return e.map(n=>({path:n,score:ie(n,t)})).filter(n=>Number.isFinite(n.score)).sort((n,o)=>n.score!==o.score?n.score-o.score:n.path===o.path?0:n.path<o.path?-1:1).map(n=>n.path)}function tn(e,t,n){let o=new Set(t),s=E.filter(i=>i.lifecycle==="deprecated").slice().sort((i,l)=>l.alias.length-i.alias.length),r=[],a=e.flatMap(i=>{let l=s.find(u=>i===u.alias||i.startsWith(`${u.alias} `)),c=i;if(l){let u=i.slice(l.alias.length);if(!o.has(`${l.canonical}${u}`))return[];c=`${l.canonical_argv.join(" ")}${u}`}return n!==void 0&&ie(i,n)<10&&r.push(c),[c]});return[...new Set(r.length>0?r:a)]}export{nt as a,K as b,Y as c,ye as d,Z as e,_e as f,T as g,we as h,bt as i,Ce as j,yt as k,Re as l,Be as m,_t as n,wt as o,St as p,f as q,Ue as r,je as s,Lt as t,zt as u,Ye as v,Gt as w,Wt as x,oe as y,Ut as z,jt as A,He as B,qt as C,Qt as D,ie as E,en as F,tn as G};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{kb as h}from"./chunk-GIAJX2QJ.js";import{$ as g,$f as L,Nb as $,Ob as R,Tb as V,X as w,Y as k,Z as F,_ as A,_h as U,aa as C,ac as v,ag as W,gb as D,qc as B,rc as z,t as N,u as p,w as E,x as M,y as I,yf as G,zf as S}from"./chunk-HQINCDF6.js";import{A as y,C as _}from"./chunk-O4ZLEN4T.js";import{Command as ae}from"commander";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a851f5ac-99a5-5061-a0c3-a08d898ea20b")}catch{}})();function nt(e){return new ae().name("pm").description("Universal, flexible, extensible, agent-optimized project management CLI for any project or programming language.").version(e).showHelpAfterError(!1).allowExcessArguments(!1).allowUnknownOption(!1).configureOutput({writeOut:t=>{U(t)},writeErr:()=>{}}).option("--json","Output JSON instead of TOON; mutations emit a flat receipt with top-level id/status/changed_field_count while reads use documented entity or collection envelopes").option("--lean","Omit null and empty containers from JSON output").option("--token-accounting","Attach a bounded per-section token-cost receipt to command output").option("--output-include <fields>","Retain comma-separated fields or sections in read output").option("--output-limit <count>","Bound rows in read output").option("--output-budget <tokens|unbounded>","Bound estimated tokens in read output or explicitly disable the default ceiling").option("--output-format <toon|json>","Select the result encoding for reads and mutations").option("--output-session <state>","Carry a JSON session budget and served-item ledger across read calls").option("--output-cursor <cursor>","Resume continuation_kind=output_cursor").option("--output-row-contract","Include row selectors, encoding metadata, and read-output receipts").option("--quiet","Suppress stdout output").option("--no-changed-fields","Omit the changed_fields array from mutation output (keeps changed_field_count)").option("--full-changed-fields","Restore the legacy full mutation envelope and changed_fields array").option("--id-only","Print only id and status for single-item mutation output").option("--pm-path <dir>","Explicit tracker storage path for this command (preferred over --path)").option("--path <dir>","Backward-compatible alias for --pm-path; this is the tracker storage path, not a workspace cwd").option("--no-extensions","Disable extension loading").option("--no-pager","Disable pager integration for help and long output").option("--explain","Render extended rationale and examples in help output").option("--all","Reveal every public command and compatibility alias").option("--profile","Print deterministic timing diagnostics").option("--author <id>","Override mutation author for this invocation").option("--expect-hash <revision>","Refuse writes to the named item unless it is still at this item_hash from pm get (a bare hash names the command's <id>; guard each other item with <id>=<item_hash>, repeatable)",(t,n)=>[...n??[],t]).exitOverride()}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8efedca0-725e-520f-ad06-825a0cccddaa")}catch{}})();var j=new Set(["append","claim","close","close-task","comments","copy","delete","deps","docs","files","focus","get","history","history-compact","history-redact","history-repair","learnings","notes","pause-task","release","restore","start-task","test","update"]),q=new Map([["files","discover"],["item","complete"]]),le=new Map([["append",1],["close",1],["close-task",1],["comments",1],["item complete",1],["learnings",1],["notes",1],["restore",1]]);function K(e){let t=p(e?.trim().toLowerCase()??"");return j.has(t)||q.has(t)}function ce(e,t,n){let o=j.has(n)?t+1:void 0,s=g(e.slice(t+1));if(s===void 0)return o;let r=t+1+s,a=`${n} ${e[r]}`,i=p(a);return i===a?n==="item"&&e[r]==="complete"?r+1:o:K(i)?P(e,r,i):void 0}function P(e,t,n){if(["history","context","ctx","update","close","item"].includes(n))return ce(e,t,n);let o=q.get(n);if(o===void 0)return t+1;let s=e[t+1]?.toLowerCase()===o;return t+(s?2:1)}function ue(e){let t=new Map;for(let n of h(e))for(let o of[n.flag,n.short,...n.aliases??[]])o&&t.set(o,n);return t}function de(e){let t=[];for(let n=0;n<e.length;n+=1){let o=e[n];if(o==="--")break;o==="--id"?(t.push({index:n,consumed:2,value:e[n+1]}),n+=1):o.startsWith("--id=")&&t.push({index:n,consumed:1,value:o.slice(5)})}return t}function fe(e,t,n){if(e.indexOf("=")>=0||t===void 0||t.startsWith("-"))return!1;let o=n.get(e);return o!==void 0&&o.value_type!=="boolean"}function pe(e,t,n,o,s){let r=0;for(let a=t;a<e.length;a+=1){let i=e[a];if(i==="--")break;if(i==="--id"){a+=1;continue}if(!i.startsWith("--id=")){if(!i.startsWith("-")){if(a<o)return!0;r+=1;continue}fe(i,e[a+1],s)&&(a+=1)}}return r>(le.get(p(n))??0)}function Y(e){let t=g(e),n=t===void 0?void 0:e[t]?.toLowerCase();if(n!=="context"&&n!=="ctx"&&!K(n))return{argv:[...e],changed:!1,conflict:!1};let o=P(e,t,n);if(o===void 0)return{argv:[...e],changed:!1,conflict:!1};let s=o>t+1?`${p(e.slice(t,o-1).join(" "))} ${e[o-1]}`:n,r=ue(s),a=de(e),i=a[0];if(!i||!i.value?.trim())return{argv:[...e],changed:!1,conflict:!1};if(a.length>1||pe(e,o,s,i.index,r))return{argv:[...e],changed:!1,conflict:!0,itemId:i.value};let l=[...e.slice(0,i.index),...e.slice(i.index+i.consumed)],c=g(l),u=P(l,c,n);return l.splice(u,0,i.value),{argv:l,changed:!0,conflict:!1,itemId:i.value}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7b271a35-800c-52bf-9368-0410e76b8d4e")}catch{}})();var me=new Set(["--output-include","--output-limit","--output-budget","--output-format","--output-session","--output-cursor"]),he=new Set(["toon","json"]);function ge(e,t,n){let o=e[t];if(k.has(o))return n.booleanFlags.add(o),1;let s=o.indexOf("="),r=s>0?o.slice(0,s):o;if(!w.has(r))return 1;let a=s>0?o.slice(s+1):void 0,i=a===void 0&&A(r,e[t+1]),l=a??(i?e[t+1]:void 0);return r==="--author"?n.author=l??"":typeof l=="string"&&l.length>0&&(me.has(r)?n.outputValues:n.pathValues).set(r,l),i?2:1}function be(e){return e.outputValues.get("--output-format")!=="toon"&&(e.booleanFlags.has("--json")||e.outputValues.get("--output-format")==="json"||e.pathValues.get("--format")?.trim().toLowerCase()==="json")}function ye(e){let t={booleanFlags:new Set,outputValues:new Map,pathValues:new Map},n=0;for(;n<e.length&&e[n]!=="--";)n+=ge(e,n,t);return{path:t.pathValues.get("--pm-path")??t.pathValues.get("--path"),noExtensions:t.booleanFlags.has("--no-extensions")||["history attest","history-attest"].includes(ee(e)??""),noPager:t.booleanFlags.has("--no-pager"),json:be(t),quiet:t.booleanFlags.has("--quiet"),lean:t.booleanFlags.has("--lean"),tokenAccounting:t.booleanFlags.has("--token-accounting"),...t.booleanFlags.has("--output-row-contract")?{outputRowContract:!0}:{},...t.outputValues.get("--output-include")===void 0?{}:{outputInclude:t.outputValues.get("--output-include")},...t.outputValues.get("--output-limit")===void 0?{}:{outputLimit:t.outputValues.get("--output-limit")},...t.outputValues.get("--output-budget")===void 0?{}:{outputBudget:t.outputValues.get("--output-budget")},...he.has(t.outputValues.get("--output-format"))?{outputFormat:t.outputValues.get("--output-format")}:{},...t.outputValues.get("--output-session")===void 0?{}:{outputSession:t.outputValues.get("--output-session")},...t.outputValues.get("--output-cursor")===void 0?{}:{outputCursor:t.outputValues.get("--output-cursor")},...t.author===""?{authorMissingValue:!0}:t.author!==void 0?{author:t.author}:{}}}function Z(e){let t=[],n=0;for(;n<e.length;){let o=e[n];if(o==="--")break;if(k.has(o)||o==="--profile"||o==="--id-only"||o==="--full-changed-fields"||o==="--explain"){n+=1;continue}if(w.has(o)){n+=A(o,e[n+1])?2:1;continue}if(F(o)){n+=1;continue}t.push(o),n+=1}return t}function _e(e){let t=Z(e);if(t[0]?.trim().toLowerCase()==="help"){let o=[];for(let s=1;s<t.length;s+=1){let r=t[s];if(r.startsWith("-"))break;o.push(r.trim().toLowerCase())}return{requested:!0,commandPathTokens:o}}if(t.findIndex(o=>o==="--help"||o==="-h")<0)return{requested:!1,commandPathTokens:[]};let n=[];for(let o of t){if(o.startsWith("-"))break;n.push(o.trim().toLowerCase())}return{requested:!0,commandPathTokens:n}}function T(e){return g(e)}function we(e){return C(e)}function Ie(e,t){return t.noPager?!0:process.stdout.isTTY===!0?!1:_e(e).requested}function bt(e){let t=["PAGER","MANPAGER","GIT_PAGER","LESS"],n=t.map(r=>process.env[r]),o=()=>{for(let[r,a]of t.entries()){let i=n[r];i===void 0?delete process.env[a]:process.env[a]=i}},s=ye(e);return Ie(e,s)&&(process.env.PAGER="cat",process.env.MANPAGER="cat",process.env.GIT_PAGER="cat",(typeof process.env.LESS!="string"||process.env.LESS.trim().length===0)&&(process.env.LESS="FRX")),o}var ke=new Set(["install","uninstall","explore","manage","doctor","adopt","adopt-all","activate","deactivate"]);function Ce(e){let t=T(e);if(t===void 0||e[t]!=="extension")return[...e];let n=e[t+1];if(!n||n.startsWith("-"))return[...e];if(!ke.has(n))return[...e];if(e.includes("--help")||e.includes("-h"))return[...e];let o=`--${n}`;return e.includes(o)?[...e]:[...e.slice(0,t+1),o,...e.slice(t+2)]}var ve=new Set(["pm","pm-cli"]);function Se(e,t){let n=T(e);if(n===void 0)return e;let o=e[n];return ve.has(o.trim().toLowerCase())?(t.push({from:o,to:[],reason:"executable_alias",confidence:"high"}),[...e.slice(0,n),...e.slice(n+1)]):e}function Te(e,t){let n=T(e);if(n!==void 0&&e[n]==="help"){let i=T(e.slice(n+1));n=i===void 0?void 0:n+1+i}if(n===void 0)return e;let o=e[n],s=M[o.trim().toLowerCase()];if(!s)return e;let r=s.split(" "),a=[...e.slice(0,n),...r,...e.slice(n+1)];return t.push({from:o,to:r,reason:"command_alias",confidence:"high"}),a}function x(e){return e.replace(/^--?/,"").replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function X(e){return x(e).replace(/-/g,"")}function J(e,t,n){let o=e.get(t);if(o===void 0){e.set(t,n);return}o!==n&&e.set(t,null)}function xe(e){let t=[],n=o=>{typeof o=="string"&&o.startsWith("--")&&t.push(o)};n(e.flag);for(let o of e.aliases??[])n(o);return t}function Oe(e,t){let n=t??h(e),o=new Map,s=new Map,r=new Map,a=new Set;for(let i of n){let l=xe(i);if(l.length===0)continue;let c=`--${x(l[0])}`;for(let d of l)J(o,x(d),c),J(s,X(d),c);let u=X(c);r.has(c)||r.set(c,u),i.list===!0&&a.add(c)}return{canonicalByNormalized:o,canonicalByCompact:s,canonicalComparables:[...r.entries()].map(([i,l])=>({canonicalFlag:i,comparable:l})),listCanonicalFlags:a}}function H(e,t){let n=x(e),o=t.canonicalByNormalized.get(n);if(typeof o=="string")return{flag:o,reason:"flag_alias",confidence:"high"};let s=n.replace(/-/g,""),r=t.canonicalByCompact.get(s);if(typeof r=="string")return{flag:r,reason:"flag_alias",confidence:"high"};let a=s.length>=8?2:1,i=Number.POSITIVE_INFINITY,l,c=!1;for(let u of t.canonicalComparables){let d=v(s,u.comparable,a);if(d!==null){if(d<i){i=d,l=u.canonicalFlag,c=!1;continue}d===i&&l!==u.canonicalFlag&&(c=!0)}}return!l||c||!Number.isFinite(i)||i<=0?null:{flag:l,reason:"flag_typo",confidence:i>=2?"medium":"high"}}function yt(e){let t=[`${e}s`];return e.endsWith("y")&&e.length>1&&t.push(`${e.slice(0,-1)}ies`),t}function Ee(e,t=!1){if(t||e.includes("://"))return null;let n=e.match(/^([A-Za-z][A-Za-z0-9_-]{1,63})([:=])(.*)$/);if(!n)return null;let o=n[1],s=n[3];return s.length===0?null:{key:o,value:s}}function Ae(e,t,n=!1){if(n||!e.startsWith("--"))return{tokens:[e]};let o=e.indexOf("="),s=o>=0?e.slice(0,o):e,r=o>=0?e.slice(o+1):void 0,a=H(s,t);if(!a)return{tokens:[e]};let i=r===void 0?a.flag:`${a.flag}=${r}`;return i===e?{tokens:[e]}:{tokens:[i],event:{from:e,to:[i],reason:a.reason,confidence:a.confidence}}}function Le(e){let t=new Set,n=!1;for(let o=0;o<e.length;o+=1){if(n){t.add(o),n=!1;continue}let s=e[o];n=s==="--path"||s==="--pm-path"}return t}function Pe(e){if(!e.startsWith("--"))return null;let t=e.indexOf("=");return t<0?{flag:e}:{flag:e.slice(0,t),inlineValue:e.slice(t+1)}}function Ne(e,t,n){n.push(e[t]);let o=e[t+1];return typeof o=="string"&&o!=="--"?(n.push(o),t+2):t+1}function Me(e,t,n,o){if(n.inlineValue!==void 0)return{originalTokens:[e[t]],value:n.inlineValue,consumed:1};let s=[],r=t+1;for(;r<e.length&&e[r]!=="--"&&!e[r].startsWith("-")&&(s.length===0||o.has(n.flag));)s.push(e[r]),r+=1;let a=s.length===0?1:1+s.length;return{originalTokens:e.slice(t,t+a),value:s.length===0?void 0:s.join(","),consumed:a}}function Fe(e,t,n,o){let s=e.get(n);if(s){s.values.push(o.value),s.occurrences+=1;return}e.set(n,{outputIndex:t.length,originalTokens:o.originalTokens,values:[o.value],occurrences:1}),t.push(null)}function De(e,t){let n=[],o=[];for(let[s,r]of e){if(!(r.occurrences>=2||t.has(s)&&r.originalTokens.length>2)){o.push({outputIndex:r.outputIndex,tokens:r.originalTokens});continue}let a=`${s}=${r.values.join(",")}`;o.push({outputIndex:r.outputIndex,tokens:[a]}),n.push({from:`${s} (x${r.occurrences})`,to:[a],reason:"list_merge",confidence:"high"})}return{events:n,splices:o}}function $e(e,t){t.sort((n,o)=>o.outputIndex-n.outputIndex);for(let n of t)e.splice(n.outputIndex,1,...n.tokens)}function Re(e,t,n=new Set,o=new Set){if(t.size===0)return{argv:[...e],events:[]};let s=[],r=new Map,a=0;for(;a<e.length;){let c=e[a];if(c==="--"){s.push(...e.slice(a));break}if(n.has(c)){a=Ne(e,a,s);continue}let u=Pe(c);if(!u||!t.has(u.flag)){s.push(c),a+=1;continue}let d=Me(e,a,u,o);if(d.value===void 0){s.push(c),a+=d.consumed;continue}Fe(r,s,u.flag,{originalTokens:d.originalTokens,value:d.value}),a+=d.consumed}let{events:i,splices:l}=De(r,o);return $e(s,l),{argv:s,events:i}}var Q=new Map([["--add",new Set(["command","cmd","path"])],["--remove",new Set(["command","path"])]]);function Ve(e,t){if(e!=="test"||t.length<2)return!1;let n=t[t.length-1],o=t[t.length-2],s=Q.get(o);return s!==void 0&&s.has(n)}function Be(e,t,n){if(t!=="test")return e;let o=[],s=0;for(;s<e.length;){let r=e[s];if(r==="--")return o.push(...e.slice(s)),o;let a=Q.get(r),i=a?e[s+1]:void 0;if(!a||typeof i!="string"||!a.has(i)){o.push(r),s+=1;continue}let l=s+2;for(;l<e.length&&!e[l].startsWith("-");)l+=1;if(l-(s+2)!==1){o.push(r),s+=1;continue}let c=e[s+2],u=`${i}=${c}`;o.push(r,u),n.push({from:`${r} ${i} ${c}`,to:[r,u],reason:"bare_key_value",confidence:"high"}),s+=3}return o}function ze(e,t,n,o){let s=[],r=Le(e);for(let a=0;a<e.length;a+=1){let i=e[a];if(i==="--"){s.push(...e.slice(a));break}let l=r.has(a),c=s[s.length-1];if(i.startsWith("--")){let b=Ae(i,t,l);s.push(...b.tokens),b.event&&o.push(b.event);continue}let u=Ee(i,l);if(!u||typeof c=="string"&&c.startsWith("-")&&!c.includes("=")||["search","comments","notes","learnings"].includes(n)||Ve(n,s)){s.push(i);continue}let d=H(u.key,t);if(!d){s.push(i);continue}let m=u.value.startsWith("-")?[`${d.flag}=${u.value}`]:[d.flag,u.value];s.push(...m),o.push({from:i,to:m,reason:"bare_key_value",confidence:d.confidence})}return s}function Ge(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--verify"){let o=e[t+1];if(o===void 0||o==="--")throw new _("history attest --verify requires a bundle file.",y.USAGE);e.splice(t,2,`--verify=${o}`)}else(w.has(n)||n==="--output"||n==="--hash-algorithm")&&(t+=1)}}function We(e,t){if(!e.some(o=>o==="--help"||o==="-h"))return;let n=new Set(h(t).flatMap(o=>[o.flag,...o.aliases??[],...o.short===void 0?[]:[o.short]]));for(let o=0;o<e.length;o+=1){let s=e[o];if(s==="--")break;s!=="--help"&&s!=="-h"||n.has(e[o-1])&&!k.has(e[o-1])&&(e[o-1]=s)}}function _t(e){let t=[],n=Se(e,t),o=Ce(n);(o.length!==n.length||o.some((b,re)=>b!==n[re]))&&t.push({from:n.join(" "),to:[...o],reason:"legacy_extension_action",confidence:"high"});let s=Te(o,t),r=Y(s);if(r.conflict)throw new _("Provide the item id either positionally or with --id, not both.",y.USAGE);r.changed&&t.push({from:`--id ${r.itemId}`,to:[r.itemId],reason:"item_id_alias",confidence:"high"});let a=we(r.argv),i=ee(r.argv),l=p(i??a??""),c=Oe(i??a),u=ze(r.argv,c,l,t),d=Be(u,l,t),m=Re(d,c.listCanonicalFlags,w,a==="create"?new Set(["--tags"]):new Set);for(let b of m.events)t.push(b);return We(m.argv,i??a),i==="history attest"&&Ge(m.argv),{argv:m.argv,commandName:a,trace:t}}function ee(e){let t=Z(e),n=t[0]?.trim().toLowerCase(),o=t[1]?.trim().toLowerCase(),s=N(t);return s?s.canonical:(n==="extension"||n==="package"||n==="packages")&&typeof o=="string"&&o.length>0&&!o.startsWith("-")?`${n} ${o}`:n}function wt(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--type"){let o=e[t+1];if(typeof o=="string"&&o.trim().length>0)return o.trim();continue}if(n.startsWith("--type=")){let o=n.slice(7).trim();if(o.length>0)return o}}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="fb625cd9-f8a8-56cf-88ab-abef64051497")}catch{}})();function St(e){if(e===void 0)return()=>{};let t=e.trim();if(t.length===0)throw new _("--author requires a non-empty value.",y.USAGE,{code:"missing_required_argument",nextSteps:["Pass an explicit author identifier with --author <id>."]});let n=G();S(t);let o=!1;return()=>{o||(o=!0,n===void 0?S(void 0):S(n))}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d0e60f7e-e0a8-5ef4-9af7-4a1f102ccb7d")}catch{}})();var f=Object.freeze({clock:"PM_CLOCK",tickMs:"PM_CLOCK_TICK_MS",seed:"PM_SEED"});function O(e,t,n,o){return new _(e,y.USAGE,{code:"invalid_reproducible_process_environment",reason:t,field:n,required:`${f.clock} and ${f.seed}; ${f.tickMs} is optional`,nextSteps:[`Set ${f.clock} to an ISO-8601 instant with Z or a numeric UTC offset and ${f.seed} to a non-empty reproducibility seed.`,`Optionally set ${f.tickMs} to a non-negative integer; it defaults to 1.`,"Unset all three variables to retain normal wall-clock and cryptographic-random behavior."],recovery:{recovery_mode:"compact",provided_fields:o,missing_required_fields:t==="incomplete"?[f.clock,f.seed].filter(s=>!o.includes(s)):void 0}})}function Ue(e){let t=e[f.clock],n=e[f.tickMs],o=e[f.seed],s=[[f.clock,t],[f.tickMs,n],[f.seed,o]].filter(a=>a[1]!==void 0).map(([a])=>a);if(s.length===0)return;if(t===void 0||o===void 0)throw O("Reproducible process execution requires PM_CLOCK and PM_SEED together.","incomplete",t===void 0?f.clock:f.seed,s);if(o.trim().length===0)throw O(`${f.seed} must not be empty.`,"invalid_value",f.seed,s);if(!V(t))throw O(`${f.clock} must be a valid ISO-8601 instant with Z or a numeric UTC offset.`,"invalid_value",f.clock,s);let r=n===void 0?1:Number(n);if(n?.trim().length===0||!Number.isSafeInteger(r)||r<0)throw O(`${f.tickMs} must be a non-negative integer.`,"invalid_value",f.tickMs,s);return $({clock:t,seed:o,tickMs:r})}function je(e){let t=Ue(e);return t===void 0?n=>n():R(t)}async function Lt(e,t){return je(e)(t)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="94bdb20f-d193-5767-91f2-8207169b82d1")}catch{}})();var te=new Set([...Object.values(B),...z,"--full","--brief","--compact","--summary","--fields","--section","--token-budget"]),ne=new Set(["--full-changed-fields","--no-changed-fields","--id-only"]);function zt(e,t){if(!["block","unblock"].includes(e)||t.includes(e)||!t.includes("update"))return;let n=new Set(h("update").map(o=>o.flag));if((e==="block"?["--blocked-by","--blocked-reason"]:["--unset","--unblock-note"]).every(o=>n.has(o)))return e==="block"?{examples:[["update","<item-id>","--blocked-by","<blocker-id>","--blocked-reason","<reason>"]],nextSteps:["Choose the actual item and blocker identifiers before running update. --blocked-by records the blocker field and its blocked_by relationship."]}:{examples:[["update","<item-id>","--unset","blocked-by","--unset","blocked-reason","--unblock-note","<note>"]],nextSteps:[`Inspect the item's blockers before running update. --unset blocked-by removes the blocker field and the blocked_by rows naming it; other blocked_by relationships stay, so remove one with --dep-remove "id=<id>,kind=blocked_by" or all with --dep-remove kind=blocked_by. --unset blocked-reason clears the stale reason. --unblock-note alone records a note and does not unblock the item.`,"If your project also uses a blocked lifecycle status, choose its appropriate next status separately with update --status."]}}function qe(e,t){let n=e.includes("="),o=n?e.slice(e.indexOf("=")+1):t;if(!(!o||o.startsWith("--")))return{consumed:n?1:2,replacement:["--from",o],conflicts:["--from"]}}var Ke=["--depth","--output-include","--fields","--section","--for"];function Ye(e){let t=L(p(e.trim().toLowerCase()));if(t===void 0)return;let n=h(t),o=n.flatMap(a=>[a.flag,...a.aliases??[]]),s=[...W(t).keys()].filter(a=>o.includes(`--${a}`)),r=[...n.find(a=>a.flag==="--depth")?.values??[]];if(!(s.length===0&&r.length===0))return{command:t,modes:s,depth_values:r,declared_flags:o}}function Gt(e){return[...e.depth_values.length>0?[`--depth ${e.depth_values.join("|")}`]:[],...e.modes.map(t=>`--${t}`)].join(", ")}function Xe(e,t,n,o){let s=Ye(e);if(s===void 0||s.declared_flags.includes(t))return;let r=[...Ke,...s.modes.map(i=>`--${i}`)].filter(i=>i!==t);if(t==="--depth"){let i=n.includes("="),l=(i?n.slice(n.indexOf("=")+1):o)?.trim().toLowerCase();if(!l)return;let c=i?1:2;return s.modes.includes(l)?{consumed:c,replacement:[`--${l}`],conflicts:r}:l==="standard"?{consumed:c,replacement:[],conflicts:r}:void 0}let a=t.slice(2);return n===t&&s.depth_values.includes(a)?{consumed:1,replacement:["--depth",a],conflicts:r}:void 0}function Je(e,t,n,o){return t==="--since"&&e==="activity"?qe(n,o):t==="--toon"&&n===t?{consumed:1,replacement:["--output-format","toon"],conflicts:["--json","--format","--output-format","--stream"]}:Xe(e,t,n,o)}function Ze(e){let t=g(e);if(t===void 0)return;let n=e[t].trim().toLowerCase(),o=`${n} ${e[t+1]?.trim().toLowerCase()??""}`,s=p(o);return s!==o.trim()?s:n==="ctx"?"context":p(n)}function Wt(e,t,n){let o=e==="ctx"?"context":p(e);if(L(o)===void 0||t.includes("--")||Ze(t)!==o)return;let s=n.split("=",1)[0],r=t.flatMap((d,m)=>d===s||d.startsWith(`${s}=`)?[m]:[]);if(r.length!==1)return;let a=r[0],i=Je(o,s,t[a],t[a+1]);if(!i)return;let{replacement:l,consumed:c,conflicts:u}=i;if(!t.some(d=>u.includes(d.split("=",1)[0])))return[...t.slice(0,a),...l,...t.slice(a+c)]}function oe(e){let t=e.split("=",1)[0].replaceAll("_","-");return te.has(t)||t.length>=5&&[...te].some(n=>n.startsWith(t))}function Ut(e,t){let n=e.split("=",1)[0].replaceAll("_","-");return oe(n)?!ne.has(t):ne.has(n)?!oe(t):!0}function se(e){return e.trim().match(/--[a-z0-9][a-z0-9_-]*/i)?.[0]?.replaceAll("_","-").toLowerCase()}function jt(e){if(!(!Array.isArray(e)||e.length===0))return C(e)}function He(e,t){let n=se(t);if(!n)return;let o=h(e).find(s=>s.flag===n||s.aliases?.includes(n));return o?o.value_type==="boolean"?null:`<${o.value_name??"value"}>`:"<value>"}function qt(e,t,n){let o=[...e],s=o.indexOf("--"),r=s<0?o.length:s;for(let a of n){let i=se(a);if(!i||o.slice(0,r).some(u=>u===i||u.startsWith(`${i}=`)))continue;let l=He(t,i),c=l?[i,l]:[i];o.splice(r,0,...c),r+=c.length}return o.length===e.length?void 0:D(o)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="bd9a8d3b-bc6f-5309-a3fb-7e5f41ef9dab")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="12066389-daef-5fce-b7a6-0ecffa926d66")}catch{}})();function Qt(e,t){let n=e.trim().split(/\s+/u);if(!(n.length<2||t.includes(n.join(" "))))for(let o=1;o<n.length;o+=1){if(!t.includes(n.slice(0,o).join(" ")))return;let s=n.slice(o).join(" "),r=I(s),a=new Set(t.filter(i=>i===s||i.endsWith(` ${s}`)||i===r?.canonical).map(i=>I(i)?.canonical??i).filter(i=>t.includes(i)));if(a.size>0)return a.size===1?[...a][0]:void 0}}var Qe={add:["create","append"],fetch:["get"],inspect:["get","health"],log:["history","comments","notes"],ls:["list"],pause:["release"],read:["get"],remove:["delete"],rm:["delete"],show:["get"],start:["start-task"]};function ie(e,t){let n=e.trim().toLowerCase(),o=t.trim().toLowerCase();if(o.length===0)return Number.POSITIVE_INFINITY;let s=n.split(" "),r=Qe[o]?.indexOf(p(n));if(r!==void 0&&r>=0)return r;if(n===o)return 10;if(s.includes(o))return 11;if(s.some(l=>l.startsWith(o)))return 12;let a=o.length>=5?2:1,i=Number.POSITIVE_INFINITY;for(let l of s){let c=v(l,o,a);c!==null&&(i=Math.min(i,c))}return Number.isFinite(i)?20+i:n.includes(o)?30:Number.POSITIVE_INFINITY}function en(e,t){return e.map(n=>({path:n,score:ie(n,t)})).filter(n=>Number.isFinite(n.score)).sort((n,o)=>n.score!==o.score?n.score-o.score:n.path===o.path?0:n.path<o.path?-1:1).map(n=>n.path)}function tn(e,t,n){let o=new Set(t),s=E.filter(i=>i.lifecycle==="deprecated").slice().sort((i,l)=>l.alias.length-i.alias.length),r=[],a=e.flatMap(i=>{let l=s.find(u=>i===u.alias||i.startsWith(`${u.alias} `)),c=i;if(l){let u=i.slice(l.alias.length);if(!o.has(`${l.canonical}${u}`))return[];c=`${l.canonical_argv.join(" ")}${u}`}return n!==void 0&&ie(i,n)<10&&r.push(c),[c]});return[...new Set(r.length>0?r:a)]}export{nt as a,K as b,Y as c,ye as d,Z as e,_e as f,T as g,we as h,bt as i,Ce as j,yt as k,Re as l,Be as m,_t as n,wt as o,St as p,f as q,Ue as r,je as s,Lt as t,zt as u,Ye as v,Gt as w,Wt as x,oe as y,Ut as z,jt as A,He as B,qt as C,Qt as D,ie as E,en as F,tn as G};
|
|
2
|
+
//# sourceMappingURL=chunk-L4F4ZHGR.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Tc as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{Tc as o}from"./chunk-TCYIGAQG.js";import{sa as d}from"./chunk-UFZQPKQS.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="41b0b451-a696-5d06-a19d-df1d6b28963c")}catch{}})();function i(e,t,n){return o(e,d(t),n)}export{i as a};
|
|
2
|
+
//# sourceMappingURL=chunk-LKVFPQNY.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as ve}from"./chunk-OFIXSWJS.js";import{Cd as g,Dd as b,Gc as ge,Hb as x,Hc as ye,Ib as k,Ob as _e,ad as Ie,hb as T,ib as ce,jb as B,kb as ae,lb as de,ob as le,pb as fe,qb as ue,rb as me,sb as he,tb as pe,ub as N}from"./chunk-FOT5K5OM.js";import{$b as p,Fa as X,Ha as J,N as V,Na as Q,Ta as Z,W as Y,Zi as se,ae as ie,hb as ee,ib as te,ki as re,ud as ne,ve as v,we as w,za as j,zf as oe}from"./chunk-PZI6CR24.js";import{A as u,C as l,z as W}from"./chunk-O4ZLEN4T.js";import{readdir as Ke}from"node:fs/promises";import H from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a319e7d9-e248-573b-bf1f-35217ce49fd0")}catch{}})();function D(e,t){return(t===void 0?void 0:J(e,t))?.execution_role??j[e.trim().toLowerCase()]??"agent"}var O="blocked_by",be="blocks",Le=Object.freeze([O,be]),A="no-active-blocker";function d(e){return e.trim().toLowerCase()}function E(e,t){return t?`external:${e}`:`local:${d(e)}`}function _(e){let t=new Map,n=typeof e.blocked_by=="string"?e.blocked_by.trim():"";if(n.length>0&&d(n)!==A){let i=g(n);t.set(E(n,i),i?n:d(n))}for(let i of e.dependencies??[]){let o=typeof i.id=="string"?i.id.trim():"";if(p(i.kind)===O&&o.length>0&&d(o)!==A){let r=g(o)||b(i.source_kind);t.set(E(o,r),r?o:d(o))}}return[...t.values()].sort((i,o)=>i.localeCompare(o))}function C(e){let t=new Map;for(let n of e){let i=d(n.id);i.length!==0&&t.set(i,new Set(_(n)))}for(let n of e){let i=d(n.id);if(i.length!==0)for(let o of n.dependencies??[]){let r=p(o.kind)===be&&typeof o.id=="string"?d(o.id):"";if(r.length===0||r===A)continue;let c=t.get(r)??new Set;c.add(i),t.set(r,c)}}return new Map([...t].map(([n,i])=>[n,[...i].sort((o,r)=>o.localeCompare(r))]))}function we(e,t){let n=d(e.id);return n.length>0?C(t).get(n)??_(e):_(e)}function L(e,t,n,i){let o=e,r=typeof o.id=="string"?i?.get(d(o.id))??we(o,[...t.values()]):_(e),c=new Set((e.dependencies??[]).filter(s=>p(s.kind)===O&&b(s.source_kind)&&typeof s.id=="string"&&s.id.trim().length>0).map(s=>E(s.id.trim(),!0)));return r.map(s=>{if(g(s)||c.has(E(s,!0)))return{id:s,title:null,status:null,resolved:!1,external:!0,...typeof e.updated_at=="string"?{blocked_since:e.updated_at}:{},resolver:null};let a=t.get(d(s));return a?{id:s,title:a.title,status:a.status,resolved:w(a.status,n)}:{id:s,title:null,status:null,resolved:!1}})}function M(e,t,n){return L(e,t,n)}function Me(e,t){let n=new Map(e.map(c=>[d(c.id),c])),i=C(e),o=new Set([...xe(t),...t.blocked_statuses]),r=new Set;for(let c of e){let s=v(c.status,t);o.has(s)&&(t.blocked_statuses.has(s)||L(c,n,t,i).some(a=>!a.resolved))&&r.add(d(c.id))}return r}function He(e,t,n={},i){let o=[...e.ready,...e.decisions,...e.gates];n.includeContainers===!0&&o.push(...e.containers.filter(c=>c.open_blockers.length===0&&!t.blocked_statuses.has(v(c.item.status,t))));let r={ready:[],decisions:[],gates:[]};for(let c of o){let s=D(c.item.type,i);s==="human"&&n.includeDecisions!==!0?r.decisions.push(c):s==="gate"&&n.includeGates!==!0?r.gates.push(c):r.ready.push(c)}return r}function xe(e){return e.active_statuses.size>0?e.active_statuses:new Set([e.open_status])}function Pe(e,t,n){let i=[d(e)],o=new Set;for(;i.length>0;){let r=i.pop();if(!o.has(r)){o.add(r);for(let c of t.get(r)??[]){if(!w(c.status,n))return!0;i.push(d(c.id))}}}return!1}function $e(e){let t=new Map,n=new Map,i=new Map,o=C(e);for(let r of e){t.set(d(r.id),r);let c=typeof r.parent=="string"?r.parent.trim():"";if(c.length>0){let s=d(c),a=n.get(s)??[];a.push(r),n.set(s,a)}for(let s of o.get(d(r.id))){let a=d(s),m=i.get(a)??[];m.push(r.id),i.set(a,m)}}return{itemsById:t,childrenByParent:n,blockedByReverse:i,blockerIdsByItem:o}}function Fe(e,t,n,i){let{itemsById:o,childrenByParent:r,blockedByReverse:c,blockerIdsByItem:s}=$e(t),a=new Set([...xe(n),...n.blocked_statuses]),m=new Set(t.filter(f=>!w(f.status,n)).map(f=>d(f.id))),F=[],K=[],S=[],U=[],G=[],q=0;for(let f of e){if(!a.has(v(f.status,n)))continue;q+=1;let z=L(f,o,n,s).filter(h=>!h.resolved),Ae=(c.get(d(f.id))??[]).filter(h=>m.has(d(h))).sort((h,Oe)=>h.localeCompare(Oe)),I={item:f,open_blockers:z,unblocks:Ae};if(Pe(f.id,r,n)){S.push(I);continue}let De=n.blocked_statuses.has(v(f.status,n));if(z.length===0&&!De){let h=D(f.type,i);h==="human"?U.push(I):h==="gate"?G.push(I):F.push(I)}else K.push(I)}return{ready:F,blocked:K,containers:S,decisions:U,gates:G,active_count:q,container_count:S.length}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="ae1c56b3-148d-502d-9450-e807fdfab4da")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e9b7731d-e6f5-51a8-970b-462c0b728a9c")}catch{}})();function Ue(e,t){let n=new Map;for(let i of e){let o=i.external?i.id:t.get(i.id.toLowerCase())?.id??i.id;n.set(i.external?`external:${o}`:`local:${o.toLowerCase()}`,{...i,id:o})}return[...n.values()]}async function P(e,t){let n=H.basename(e),i=(await Ke(H.dirname(e)).catch(o=>{throw ge("Cannot verify the blocker's physical file identity",{exitCode:u.GENERIC_FAILURE,context:{code:"blocker_identity_read_failed",required:"Restore access to the blocker item directory, then retry the item read."},cause:o})})).filter(o=>o.toLowerCase()===n.toLowerCase()).sort((o,r)=>+(r===n)-+(o===n)||o.localeCompare(r)).map(o=>H.parse(o).name)[0];if(i===void 0)throw new l(`Blocker canonical file disappeared during identity verification: ${t}`,u.CONFLICT,{code:"item_identity_conflict",required:"Restore the canonical blocker file and validate storage integrity before retrying the item read."});return i}async function ht(e){let t=_(e.metadata);if(t.length===0)return[];let n=new Map([e.metadata.blocked_by,...(e.metadata.dependencies??[]).filter(o=>p(o.kind)==="blocked_by").map(o=>o.id)].filter(o=>typeof o=="string").map(o=>[o.trim().toLowerCase(),o.trim()])),i=new Map;for(let o of t){if(g(o)||!/^(?!\.{1,2}$)[^/\\:\0]+$/u.test(o)||e.metadata.dependencies?.some(s=>s.id.trim()===o&&p(s.kind)==="blocked_by"&&b(s.source_kind)))continue;let r=await x(e.pmRoot,n.get(o),e.settings.id_prefix,e.settings.item_format,e.typeToFolder);if(r===null)continue;let c=await k(r,{schema:e.settings.schema});if(r.id=await P(r.itemPath,r.id),c.document.metadata.id!==r.id)throw new l(`Blocker identity differs from its canonical file: ${r.id}`,u.CONFLICT,{code:"item_identity_conflict",required:"Restore the canonical blocker identity and validate storage integrity before retrying the item read."});i.set(o.toLowerCase(),c.document.metadata)}return Ue(M({blocked_by:e.metadata.blocked_by,dependencies:e.metadata.dependencies,updated_at:e.metadata.updated_at},i,ie(e.settings.schema)),i)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="222cbba7-e2df-5afb-8d75-14f9f99b3bd2")}catch{}})();var Ee="item_revision_conflict",Ge=10,Ce=/^[0-9a-f]{64}$/u;function y(e,t){return new l(`Invalid expected revision ${JSON.stringify(e)}: ${t}.`,u.USAGE,{code:"expect_hash_invalid",value:e,required:"Pass the 64-character item_hash from pm get <id> --json, optionally as <id>=<item_hash>.",examples:["--expect-hash <item_hash>","--expect-hash pm-a1b2=<item_hash>"]})}function Re(e){let t=typeof e=="string"?e.trim().toLowerCase():"";if(!Ce.test(t))throw y(String(e),"the revision is not a 64-character hexadecimal item_hash");return t}function qe(e){return(e===void 0?[]:typeof e=="string"?[e]:e).flatMap(t=>{if(typeof t!="string")throw y(String(t),"expected a string");let n=t.split(",").map(o=>o.trim()).filter(o=>o.length>0);if(n.length===0)throw y(t,"the value is empty");let i=o=>te(t)===t?o:ee;return n.map(o=>{let r=o.lastIndexOf("="),c=r===-1?void 0:o.slice(0,r).trim();if(c!==void 0&&c.length===0)throw y(i(o),"the item id before = is empty");let s=r===-1?o:o.slice(r+1);if(!Ce.test(s.trim().toLowerCase()))throw y(i(s),"the revision is not a 64-character hexadecimal item_hash");let a=Re(s);return c===void 0?{itemHash:a}:{id:c,itemHash:a}})})}async function Se(e,t){let n=await se(e),i=X(n,ne()).type_to_folder,o=await x(e,t,n.id_prefix,n.item_format,i);if(o){let{document:r}=await k(o,{schema:n.schema});if(r.metadata.id!==await P(o.itemPath,o.id))throw new l(`Item file ${o.id} embeds the id ${r.metadata.id}; no revision can be bound to an item whose identity is in conflict.`,u.CONFLICT,{code:"item_identity_conflict",item_id:o.id,required:`Repair ${o.id}'s identity first (pm validate reports it; pm restore ${o.id} <version> recovers a recorded state), then read its item_hash again.`});return{id:r.metadata.id,document:r}}try{return{id:(await ve(e,t,n,i)).id,document:W}}catch{throw await _e(e,t,n.id_prefix,i)}}function $(e){return Q(e.cwd??process.cwd(),e.pmRoot)}async function Dt(e,t={}){let n=await Se($(t),e);return{id:n.id,item_hash:re(n.document)}}async function Te(e,t,n){let i=[];for(let o of t){let r=o.id??n;if(r===void 0||r.trim().length===0)throw new l("A bare expected revision needs an item to bind to.",u.USAGE,{code:"expect_hash_target_required",required:"This command has no single item argument; name each target as --expect-hash <id>=<item_hash>.",examples:["--expect-hash pm-a1b2=<item_hash>"]});i.push({id:(await Se(e,r)).id,itemHash:o.itemHash})}return i}function ze(e){return[...new Set(e.patch.map(t=>{let n=t.path.split("/");return String(n[1]==="metadata"?n[2]:n[1])}))].sort()}async function We(e,t,n){let i;try{i=await oe(Z(e,t),t)}catch{return}let o=-1;for(let s=i.length-1;s>=0;s-=1){let a=i[s];if(a.after_hash===n){o=s+1;break}if(a.before_hash===n){o=s;break}}if(o===-1)return{expected_revision_recorded:!1,changes_since:[],changes_since_omitted:0};let r=i.slice(o),c=r.slice(-Ge);return{expected_revision_recorded:!0,changes_since:c.map(s=>({ts:s.ts,op:s.op,author:s.author,fields:ze(s)})),changes_since_omitted:r.length-c.length}}async function Ot(e,t){if(!R(e))return{};let n=await Be(e,t);return{error_code:Ee,expected_revision:String(n.context.expected_revision),current_revision:String(n.context.current_revision),details:n.context.details}}function R(e){return ye(e)&&e.context.code===Ee}function Lt(e){let t=e.find(n=>R(n));if(t!==void 0)throw t}function Mt(){return new l("--expect-hash cannot guard an invocation an extension override rewrote: which item it writes is not provable.",u.USAGE,{code:"expect_hash_invocation_rewritten",required:"Run the command without the rewriting extension (--no-extensions), or drop --expect-hash.",why:"An extension parser or preflight override changed this invocation's tracker or arguments, and final dispatch, the extension SDK client and the guard do not share one rewritten view."})}function Ve(e,t){if(t===void 0||!R(e)||typeof e.context.item_id!="string"||he(e))return e;let n=e.context.reason===fe;if(!n&&e.context.reason!==le)return e;let i=pe(N(e,new l(e.message,e.exitCode,{...e.context,...ue(e.context.item_id,n,t)})));return i.stack=e.stack,i}async function Be(e,t,n){if(!me(e,t))return e;let i=Ve(e,n);if(!R(i)||i.context.details!==void 0)return i;let o=i.context.item_id,r=i.context.expected_revision;if(typeof o!="string"||typeof r!="string")return i;let c;try{c=await We(t,o,r)}catch{return i}if(c===void 0)return i;let s={expected_revision_recorded:c.expected_revision_recorded,changes_since:c.changes_since.map(m=>({ts:m.ts,op:m.op,author:m.author,fields:[...m.fields]})),changes_since_omitted:c.changes_since_omitted},a=N(i,new l(i.message,i.exitCode,{...i.context,details:s}));return a.stack=i.stack,a}async function Ne(e,t,n){try{return{result:await ce(e,t),...ae(e)}}catch(i){throw e.pmRoot===void 0?i:await Be(i,e.pmRoot,n)}}function Ye(e){return e.cwd===void 0&&e.pmRoot===void 0?void 0:{scopeArgs:["--pm-path",$(e)]}}async function Ht(e,t,n={}){return Ne(await je(e,n),t,Ye(n))}async function je(e,t={}){let n=$(t),i=e.map(({id:r,itemHash:c})=>({id:r,itemHash:Re(c)})),o=T();return B(o,n,await Te(n,i)),o}function Pt(e){let t=de(e);return t===void 0||t.length>0}function Xe(e){return`expect_hash_unchecked:${e}:no_locked_write_reached_this_item`}var ke=new Set(V);function Je(e,t={}){let n=e.trim().replace(/\s+/gu,"-"),i=ke.has(n)?n:e;if(ke.has(i)&&(!Ie(i)||i==="deps")&&!Y.has(i))throw Qe(i);if((i==="test"||i==="test-all")&&t.background===!0)throw new l(`--expect-hash cannot guard ${i} --background: the worker runs in another process.`,u.USAGE,{code:"expect_hash_background_unsupported",required:`Run ${i} in the foreground to guard its result recording, or drop --expect-hash for a background run.`})}function Qe(e){return new l(`--expect-hash guards item writes, and ${e} is not a mutation.`,u.USAGE,{code:"expect_hash_requires_mutation",required:"Use --expect-hash (MCP/SDK expectHash) only on a command or action that writes items."})}function Ze(e,t){if(t.length===0||typeof e!="object"||e===null||Array.isArray(e))return e;let n=e,i=Array.isArray(n.warnings)?n.warnings:[];return{...n,warnings:[...i,...t.map(Xe)]}}async function $t(e){let t=e.expectHash;if(t!==void 0&&typeof t!="string"&&!(Array.isArray(t)&&t.every(r=>typeof r=="string")))throw y(JSON.stringify(t)??String(t),"expected a string or an array of strings");let n=qe(t);if(n.length===0)return e.run();Je(e.action,{background:e.background===!0||e.options?.background===!0});let i=T();B(i,e.pmRoot,await Te(e.pmRoot,n,e.defaultId));let o=await Ne(i,e.run,e.invocation);return Ze(o.result,o.unchecked)}export{D as a,Le as b,_ as c,C as d,we as e,M as f,Me as g,He as h,Fe as i,ht as j,Ee as k,Ge as l,Re as m,qe as n,Dt as o,Te as p,We as q,Ot as r,R as s,Lt as t,Mt as u,Ve as v,Be as w,Ne as x,Ht as y,je as z,Pt as A,Xe as B,Je as C,Qe as D,$t as E};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{b as ve}from"./chunk-CO7RWLCM.js";import{Cd as g,Dd as b,Gc as ge,Hb as x,Hc as ye,Ib as k,Ob as _e,ad as Ie,hb as T,ib as ce,jb as B,kb as ae,lb as de,ob as le,pb as fe,qb as ue,rb as me,sb as he,tb as pe,ub as N}from"./chunk-UFZQPKQS.js";import{Ad as ne,Be as v,Ce as w,Fa as X,Ff as oe,Ha as J,N as V,Na as Q,Ta as Z,W as Y,dj as se,fc as p,ge as ie,hb as ee,ib as te,qi as re,za as j}from"./chunk-HQINCDF6.js";import{A as u,C as l,z as W}from"./chunk-O4ZLEN4T.js";import{readdir as Ke}from"node:fs/promises";import H from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a319e7d9-e248-573b-bf1f-35217ce49fd0")}catch{}})();function D(e,t){return(t===void 0?void 0:J(e,t))?.execution_role??j[e.trim().toLowerCase()]??"agent"}var O="blocked_by",be="blocks",Le=Object.freeze([O,be]),A="no-active-blocker";function d(e){return e.trim().toLowerCase()}function E(e,t){return t?`external:${e}`:`local:${d(e)}`}function _(e){let t=new Map,n=typeof e.blocked_by=="string"?e.blocked_by.trim():"";if(n.length>0&&d(n)!==A){let i=g(n);t.set(E(n,i),i?n:d(n))}for(let i of e.dependencies??[]){let o=typeof i.id=="string"?i.id.trim():"";if(p(i.kind)===O&&o.length>0&&d(o)!==A){let r=g(o)||b(i.source_kind);t.set(E(o,r),r?o:d(o))}}return[...t.values()].sort((i,o)=>i.localeCompare(o))}function C(e){let t=new Map;for(let n of e){let i=d(n.id);i.length!==0&&t.set(i,new Set(_(n)))}for(let n of e){let i=d(n.id);if(i.length!==0)for(let o of n.dependencies??[]){let r=p(o.kind)===be&&typeof o.id=="string"?d(o.id):"";if(r.length===0||r===A)continue;let c=t.get(r)??new Set;c.add(i),t.set(r,c)}}return new Map([...t].map(([n,i])=>[n,[...i].sort((o,r)=>o.localeCompare(r))]))}function we(e,t){let n=d(e.id);return n.length>0?C(t).get(n)??_(e):_(e)}function L(e,t,n,i){let o=e,r=typeof o.id=="string"?i?.get(d(o.id))??we(o,[...t.values()]):_(e),c=new Set((e.dependencies??[]).filter(s=>p(s.kind)===O&&b(s.source_kind)&&typeof s.id=="string"&&s.id.trim().length>0).map(s=>E(s.id.trim(),!0)));return r.map(s=>{if(g(s)||c.has(E(s,!0)))return{id:s,title:null,status:null,resolved:!1,external:!0,...typeof e.updated_at=="string"?{blocked_since:e.updated_at}:{},resolver:null};let a=t.get(d(s));return a?{id:s,title:a.title,status:a.status,resolved:w(a.status,n)}:{id:s,title:null,status:null,resolved:!1}})}function M(e,t,n){return L(e,t,n)}function Me(e,t){let n=new Map(e.map(c=>[d(c.id),c])),i=C(e),o=new Set([...xe(t),...t.blocked_statuses]),r=new Set;for(let c of e){let s=v(c.status,t);o.has(s)&&(t.blocked_statuses.has(s)||L(c,n,t,i).some(a=>!a.resolved))&&r.add(d(c.id))}return r}function He(e,t,n={},i){let o=[...e.ready,...e.decisions,...e.gates];n.includeContainers===!0&&o.push(...e.containers.filter(c=>c.open_blockers.length===0&&!t.blocked_statuses.has(v(c.item.status,t))));let r={ready:[],decisions:[],gates:[]};for(let c of o){let s=D(c.item.type,i);s==="human"&&n.includeDecisions!==!0?r.decisions.push(c):s==="gate"&&n.includeGates!==!0?r.gates.push(c):r.ready.push(c)}return r}function xe(e){return e.active_statuses.size>0?e.active_statuses:new Set([e.open_status])}function Pe(e,t,n){let i=[d(e)],o=new Set;for(;i.length>0;){let r=i.pop();if(!o.has(r)){o.add(r);for(let c of t.get(r)??[]){if(!w(c.status,n))return!0;i.push(d(c.id))}}}return!1}function $e(e){let t=new Map,n=new Map,i=new Map,o=C(e);for(let r of e){t.set(d(r.id),r);let c=typeof r.parent=="string"?r.parent.trim():"";if(c.length>0){let s=d(c),a=n.get(s)??[];a.push(r),n.set(s,a)}for(let s of o.get(d(r.id))){let a=d(s),m=i.get(a)??[];m.push(r.id),i.set(a,m)}}return{itemsById:t,childrenByParent:n,blockedByReverse:i,blockerIdsByItem:o}}function Fe(e,t,n,i){let{itemsById:o,childrenByParent:r,blockedByReverse:c,blockerIdsByItem:s}=$e(t),a=new Set([...xe(n),...n.blocked_statuses]),m=new Set(t.filter(f=>!w(f.status,n)).map(f=>d(f.id))),F=[],K=[],S=[],U=[],G=[],q=0;for(let f of e){if(!a.has(v(f.status,n)))continue;q+=1;let z=L(f,o,n,s).filter(h=>!h.resolved),Ae=(c.get(d(f.id))??[]).filter(h=>m.has(d(h))).sort((h,Oe)=>h.localeCompare(Oe)),I={item:f,open_blockers:z,unblocks:Ae};if(Pe(f.id,r,n)){S.push(I);continue}let De=n.blocked_statuses.has(v(f.status,n));if(z.length===0&&!De){let h=D(f.type,i);h==="human"?U.push(I):h==="gate"?G.push(I):F.push(I)}else K.push(I)}return{ready:F,blocked:K,containers:S,decisions:U,gates:G,active_count:q,container_count:S.length}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="ae1c56b3-148d-502d-9450-e807fdfab4da")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e9b7731d-e6f5-51a8-970b-462c0b728a9c")}catch{}})();function Ue(e,t){let n=new Map;for(let i of e){let o=i.external?i.id:t.get(i.id.toLowerCase())?.id??i.id;n.set(i.external?`external:${o}`:`local:${o.toLowerCase()}`,{...i,id:o})}return[...n.values()]}async function P(e,t){let n=H.basename(e),i=(await Ke(H.dirname(e)).catch(o=>{throw ge("Cannot verify the blocker's physical file identity",{exitCode:u.GENERIC_FAILURE,context:{code:"blocker_identity_read_failed",required:"Restore access to the blocker item directory, then retry the item read."},cause:o})})).filter(o=>o.toLowerCase()===n.toLowerCase()).sort((o,r)=>+(r===n)-+(o===n)||o.localeCompare(r)).map(o=>H.parse(o).name)[0];if(i===void 0)throw new l(`Blocker canonical file disappeared during identity verification: ${t}`,u.CONFLICT,{code:"item_identity_conflict",required:"Restore the canonical blocker file and validate storage integrity before retrying the item read."});return i}async function ht(e){let t=_(e.metadata);if(t.length===0)return[];let n=new Map([e.metadata.blocked_by,...(e.metadata.dependencies??[]).filter(o=>p(o.kind)==="blocked_by").map(o=>o.id)].filter(o=>typeof o=="string").map(o=>[o.trim().toLowerCase(),o.trim()])),i=new Map;for(let o of t){if(g(o)||!/^(?!\.{1,2}$)[^/\\:\0]+$/u.test(o)||e.metadata.dependencies?.some(s=>s.id.trim()===o&&p(s.kind)==="blocked_by"&&b(s.source_kind)))continue;let r=await x(e.pmRoot,n.get(o),e.settings.id_prefix,e.settings.item_format,e.typeToFolder);if(r===null)continue;let c=await k(r,{schema:e.settings.schema});if(r.id=await P(r.itemPath,r.id),c.document.metadata.id!==r.id)throw new l(`Blocker identity differs from its canonical file: ${r.id}`,u.CONFLICT,{code:"item_identity_conflict",required:"Restore the canonical blocker identity and validate storage integrity before retrying the item read."});i.set(o.toLowerCase(),c.document.metadata)}return Ue(M({blocked_by:e.metadata.blocked_by,dependencies:e.metadata.dependencies,updated_at:e.metadata.updated_at},i,ie(e.settings.schema)),i)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="222cbba7-e2df-5afb-8d75-14f9f99b3bd2")}catch{}})();var Ee="item_revision_conflict",Ge=10,Ce=/^[0-9a-f]{64}$/u;function y(e,t){return new l(`Invalid expected revision ${JSON.stringify(e)}: ${t}.`,u.USAGE,{code:"expect_hash_invalid",value:e,required:"Pass the 64-character item_hash from pm get <id> --json, optionally as <id>=<item_hash>.",examples:["--expect-hash <item_hash>","--expect-hash pm-a1b2=<item_hash>"]})}function Re(e){let t=typeof e=="string"?e.trim().toLowerCase():"";if(!Ce.test(t))throw y(String(e),"the revision is not a 64-character hexadecimal item_hash");return t}function qe(e){return(e===void 0?[]:typeof e=="string"?[e]:e).flatMap(t=>{if(typeof t!="string")throw y(String(t),"expected a string");let n=t.split(",").map(o=>o.trim()).filter(o=>o.length>0);if(n.length===0)throw y(t,"the value is empty");let i=o=>te(t)===t?o:ee;return n.map(o=>{let r=o.lastIndexOf("="),c=r===-1?void 0:o.slice(0,r).trim();if(c!==void 0&&c.length===0)throw y(i(o),"the item id before = is empty");let s=r===-1?o:o.slice(r+1);if(!Ce.test(s.trim().toLowerCase()))throw y(i(s),"the revision is not a 64-character hexadecimal item_hash");let a=Re(s);return c===void 0?{itemHash:a}:{id:c,itemHash:a}})})}async function Se(e,t){let n=await se(e),i=X(n,ne()).type_to_folder,o=await x(e,t,n.id_prefix,n.item_format,i);if(o){let{document:r}=await k(o,{schema:n.schema});if(r.metadata.id!==await P(o.itemPath,o.id))throw new l(`Item file ${o.id} embeds the id ${r.metadata.id}; no revision can be bound to an item whose identity is in conflict.`,u.CONFLICT,{code:"item_identity_conflict",item_id:o.id,required:`Repair ${o.id}'s identity first (pm validate reports it; pm restore ${o.id} <version> recovers a recorded state), then read its item_hash again.`});return{id:r.metadata.id,document:r}}try{return{id:(await ve(e,t,n,i)).id,document:W}}catch{throw await _e(e,t,n.id_prefix,i)}}function $(e){return Q(e.cwd??process.cwd(),e.pmRoot)}async function Dt(e,t={}){let n=await Se($(t),e);return{id:n.id,item_hash:re(n.document)}}async function Te(e,t,n){let i=[];for(let o of t){let r=o.id??n;if(r===void 0||r.trim().length===0)throw new l("A bare expected revision needs an item to bind to.",u.USAGE,{code:"expect_hash_target_required",required:"This command has no single item argument; name each target as --expect-hash <id>=<item_hash>.",examples:["--expect-hash pm-a1b2=<item_hash>"]});i.push({id:(await Se(e,r)).id,itemHash:o.itemHash})}return i}function ze(e){return[...new Set(e.patch.map(t=>{let n=t.path.split("/");return String(n[1]==="metadata"?n[2]:n[1])}))].sort()}async function We(e,t,n){let i;try{i=await oe(Z(e,t),t)}catch{return}let o=-1;for(let s=i.length-1;s>=0;s-=1){let a=i[s];if(a.after_hash===n){o=s+1;break}if(a.before_hash===n){o=s;break}}if(o===-1)return{expected_revision_recorded:!1,changes_since:[],changes_since_omitted:0};let r=i.slice(o),c=r.slice(-Ge);return{expected_revision_recorded:!0,changes_since:c.map(s=>({ts:s.ts,op:s.op,author:s.author,fields:ze(s)})),changes_since_omitted:r.length-c.length}}async function Ot(e,t){if(!R(e))return{};let n=await Be(e,t);return{error_code:Ee,expected_revision:String(n.context.expected_revision),current_revision:String(n.context.current_revision),details:n.context.details}}function R(e){return ye(e)&&e.context.code===Ee}function Lt(e){let t=e.find(n=>R(n));if(t!==void 0)throw t}function Mt(){return new l("--expect-hash cannot guard an invocation an extension override rewrote: which item it writes is not provable.",u.USAGE,{code:"expect_hash_invocation_rewritten",required:"Run the command without the rewriting extension (--no-extensions), or drop --expect-hash.",why:"An extension parser or preflight override changed this invocation's tracker or arguments, and final dispatch, the extension SDK client and the guard do not share one rewritten view."})}function Ve(e,t){if(t===void 0||!R(e)||typeof e.context.item_id!="string"||he(e))return e;let n=e.context.reason===fe;if(!n&&e.context.reason!==le)return e;let i=pe(N(e,new l(e.message,e.exitCode,{...e.context,...ue(e.context.item_id,n,t)})));return i.stack=e.stack,i}async function Be(e,t,n){if(!me(e,t))return e;let i=Ve(e,n);if(!R(i)||i.context.details!==void 0)return i;let o=i.context.item_id,r=i.context.expected_revision;if(typeof o!="string"||typeof r!="string")return i;let c;try{c=await We(t,o,r)}catch{return i}if(c===void 0)return i;let s={expected_revision_recorded:c.expected_revision_recorded,changes_since:c.changes_since.map(m=>({ts:m.ts,op:m.op,author:m.author,fields:[...m.fields]})),changes_since_omitted:c.changes_since_omitted},a=N(i,new l(i.message,i.exitCode,{...i.context,details:s}));return a.stack=i.stack,a}async function Ne(e,t,n){try{return{result:await ce(e,t),...ae(e)}}catch(i){throw e.pmRoot===void 0?i:await Be(i,e.pmRoot,n)}}function Ye(e){return e.cwd===void 0&&e.pmRoot===void 0?void 0:{scopeArgs:["--pm-path",$(e)]}}async function Ht(e,t,n={}){return Ne(await je(e,n),t,Ye(n))}async function je(e,t={}){let n=$(t),i=e.map(({id:r,itemHash:c})=>({id:r,itemHash:Re(c)})),o=T();return B(o,n,await Te(n,i)),o}function Pt(e){let t=de(e);return t===void 0||t.length>0}function Xe(e){return`expect_hash_unchecked:${e}:no_locked_write_reached_this_item`}var ke=new Set(V);function Je(e,t={}){let n=e.trim().replace(/\s+/gu,"-"),i=ke.has(n)?n:e;if(ke.has(i)&&(!Ie(i)||i==="deps")&&!Y.has(i))throw Qe(i);if((i==="test"||i==="test-all")&&t.background===!0)throw new l(`--expect-hash cannot guard ${i} --background: the worker runs in another process.`,u.USAGE,{code:"expect_hash_background_unsupported",required:`Run ${i} in the foreground to guard its result recording, or drop --expect-hash for a background run.`})}function Qe(e){return new l(`--expect-hash guards item writes, and ${e} is not a mutation.`,u.USAGE,{code:"expect_hash_requires_mutation",required:"Use --expect-hash (MCP/SDK expectHash) only on a command or action that writes items."})}function Ze(e,t){if(t.length===0||typeof e!="object"||e===null||Array.isArray(e))return e;let n=e,i=Array.isArray(n.warnings)?n.warnings:[];return{...n,warnings:[...i,...t.map(Xe)]}}async function $t(e){let t=e.expectHash;if(t!==void 0&&typeof t!="string"&&!(Array.isArray(t)&&t.every(r=>typeof r=="string")))throw y(JSON.stringify(t)??String(t),"expected a string or an array of strings");let n=qe(t);if(n.length===0)return e.run();Je(e.action,{background:e.background===!0||e.options?.background===!0});let i=T();B(i,e.pmRoot,await Te(e.pmRoot,n,e.defaultId));let o=await Ne(i,e.run,e.invocation);return Ze(o.result,o.unchecked)}export{D as a,Le as b,_ as c,C as d,we as e,M as f,Me as g,He as h,Fe as i,ht as j,Ee as k,Ge as l,Re as m,qe as n,Dt as o,Te as p,We as q,Ot as r,R as s,Lt as t,Mt as u,Ve as v,Be as w,Ne as x,Ht as y,je as z,Pt as A,Xe as B,Je as C,Qe as D,$t as E};
|
|
2
|
+
//# sourceMappingURL=chunk-O6PBQMD7.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{$b as He,Sb as ze,Tb as Be,Vb as ne,Yb as Ve,Za as te,_b as Ye,a as xe,vc as Xe}from"./chunk-GDS4DC5A.js";import{u as We}from"./chunk-5NGGI7JC.js";import{qc as Je}from"./chunk-UTNPDAID.js";import{b as N,c as Q,d as Ge,e as ee,f as qe}from"./chunk-OBTU2BHJ.js";import{qa as Ke,vb as U,wa as Le,yb as j}from"./chunk-PS2YAPXC.js";import{Lb as Fe,Mc as Pe,Va as Z,d as be,gb as C,ia as Ne,ka as I,t as Ee,u as Oe,v as W}from"./chunk-FOT5K5OM.js";import{$d as Ie,Fa as B,Oa as Te,Oi as Ue,Si as je,Vd as Me,Wb as $e,Xd as Y,Yd as Re,Zi as De,_e as Ce,a as Se,de as O,fi as R,je as H,ki as X,td as ke,ud as V,zf as A}from"./chunk-PZI6CR24.js";import{A as u,C as d,G as z,I as Ae,J as k,l as ge,q as $,t as ve,y as _e}from"./chunk-O4ZLEN4T.js";import ue from"node:crypto";import{constants as se}from"node:fs";import{cp as mn,lstat as vt,mkdir as fn,mkdtemp as _t,open as hn,readdir as yn,realpath as St,rm as bt,stat as pe,writeFile as Et}from"node:fs/promises";import{tmpdir as Ot}from"node:os";import l from"node:path";import ct from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="01728cbc-2037-50d2-8318-5f106714b8da")}catch{}})();var b=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...ge,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function Ze(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return b.has(t)?t:e}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="6456f85b-e076-5048-9c21-03d477267259")}catch{}})();function D(e,t,n){let r=e?.estimatedMinutes;if(!(r===void 0||typeof r=="string"))throw new d(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,u.USAGE,{code:"mutation_option_value_invalid",required:'Pass estimatedMinutes as a string, for example "45", in raw mutation options.',why:"Raw options use the create/update command option types; item documents accept numeric estimated_minutes instead.",nextSteps:["Quote the estimatedMinutes value or use an item document with numeric estimated_minutes, then retry the transaction."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a17df3f5-aee8-5734-b1ce-b643482be3a7")}catch{}})();var re=["op","id","reason","options","unique","match"],Ct=[...re,"ref"],Qe=[...Ct,"item"],Nt="mutate-",et="row-",tt=["schema_version","mutations"],dt="[a-z][a-z0-9._-]{0,63}",nt=new RegExp(`^${dt}$`,"u"),ut=new RegExp(`(^|,)id=@(${dt})(?=,|$)`,"gu"),rt=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),F=["item","item_hash","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],pt=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Ut=new Set([...pt,"completed_at","id"]),lt={create:U.map(e=>e.target),update:j.map(e=>e.target),close:Ke.map(e=>rt(e.flag)).filter(e=>e!=="reason"),release:Le.map(e=>rt(e.flag))};function tr(e){let t=ct.createHash("sha256").update(e).digest("hex");return`${Nt}${t.slice(0,24)}`}function nr(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new d("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let r of["lockTtlSeconds","lockWaitMs"]){let i=e[r];if(i===void 0)continue;let o=typeof i=="number"||typeof i=="string"&&i.trim().length>0?Number(i):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new d(`${r} must be a positive safe integer.`,u.USAGE);t[r]=o}return t}function w(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function P(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=$e(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function E(e,t,n){let r=P(t,n);return new d(r===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${r}"?`,u.USAGE,{code:"stdin_json_unknown_key",required:`Use documented ${e} keys only.`,why:"Strict structured input prevents silent typos from creating incomplete or unintended mutations.",nextSteps:[r===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${r}".`]})}function ae(e,t){try{return JSON.parse(e)}catch(n){let r=n instanceof Error?n.message:String(n);throw new d(`${t} must be valid JSON: ${r}`,u.USAGE,{code:"stdin_json_invalid",required:`Pipe one valid JSON ${t.toLowerCase()} into stdin.`,why:"Structured mutation input must parse deterministically before any tracker write begins."})}}function jt(e,t){if(!w(e))throw new d(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!re.includes(n))throw E(`mutation ${t+1}`,n,re);return e}function Dt(e,t,n,r){if(e===void 0)return;if(!w(e))throw new d(`Mutation ${n+1} options must be an object.`,u.USAGE);let i=[...lt[t],...ht(t,r)];for(let o of Object.keys(e))if(!i.includes(o))throw E(`mutation ${n+1} ${t} options`,o,i);return D(e,t,n),e}function it(e,t,n,r){if(e===void 0)return;let i=r==="unique"?"create":"update";if(t!==i)throw new d(`Mutation ${n+1} ${r} is only valid for ${i} operations.`,u.USAGE);let o=w(e)&&typeof e.key=="string"?e.key.trim():"";if(!w(e)||o.length===0||e.value===void 0||e.value===null)throw new d(`Mutation ${n+1} ${r} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Ft(e,t,n){let r=jt(e,t),{op:i,id:o,reason:a}=r;if(i!=="create"&&i!=="update"&&i!=="close"&&i!=="release")throw new d(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=Dt(r.options,i,t,n),c=it(r.unique,i,t,"unique"),m=it(r.match,i,t,"match");if(typeof o!="string"||o.trim().length===0)throw new d(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let p=o.trim();if(i==="close"){if(typeof a!="string"||a.trim().length===0)throw new d(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:i,id:p,reason:a.trim(),...s===void 0?{}:{options:s}}}if(i==="release")return{op:i,id:p,...s===void 0?{}:{options:s}};if(!w(s))throw new d(`Mutation ${t+1} ${i} requires an options object.`,u.USAGE);return{op:i,id:p,options:s,...c===void 0?{}:{unique:c},...m===void 0?{}:{match:m}}}function mt(e,t={}){let n=ae(e,"Mutation batch"),r=Array.isArray(n)?n:w(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(r===void 0||r.length===0)throw new d("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let i=t.runtimeFields??[];return r.map((o,a)=>{let s=Ft(o,a,i);return s.options!==void 0&&Ee(s.options),s})}function Pt(e,t,n){let r=ct.createHash("sha256").update(e).update("\0").update(t).digest("hex"),i=BigInt(`0x${r.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Ne(n)}${i}`}function ot(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),r=t[n];if(r===void 0)throw new d(`Unknown mutation reference "${e}".`,u.USAGE);return r}function at(e,t){if(typeof e!="string")return e;let n=e.replace(ut,(r,i,o)=>{let a=t[o];if(a===void 0)throw new d(`Unknown mutation reference "@${o}".`,u.USAGE);return`${i}id=${a}`});if(/(^|,)id=@/u.test(n))throw new d(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function xt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(ut)].map(t=>t[1]).filter(t=>t!==void 0)}function Gt(e,t){let n=new Map;for(let[a,s]of e.entries()){let c=t[a];if(c===void 0)continue;let m=w(s.options)?s.options:{},p=Array.isArray(m.dep)?m.dep:m.dep===void 0?[]:[m.dep];n.set(c,[m.parent,m.blockedBy,...p].flatMap(xt))}let r=new Set,i=new Set,o=a=>{if(r.has(a))throw new d(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!i.has(a)){r.add(a);for(let s of n.get(a))n.has(s)&&o(s);r.delete(a),i.add(a)}};for(let a of n.keys())o(a)}function qt(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),r=n[0];if(!r.ok&&(r.line.startsWith("[")||r.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&w(o.value)))return null;let i=[];for(let o of n){if(!o.ok)throw new d(`Mutation document line ${o.number} must be one valid JSON object: ${Pe(o.error)}`,u.USAGE,{code:"stdin_json_invalid",required:"Provide one JSON object per line (JSON Lines), a JSON array, or a {schema_version, mutations} document.",why:"Structured mutation input must parse deterministically before any tracker write begins."});if(!w(o.value))throw new d(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);i.push(o.value)}return i}function Kt(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Lt(e){let t;try{t=ae(e,"Mutation document")}catch(n){let r=qt(e);if(r===null)throw n;return{schema_version:1,mutations:r}}return Array.isArray(t)?{schema_version:1,mutations:t}:w(t)&&!Kt(t)?{schema_version:1,mutations:[t]}:t}function Jt(e,t){let n=Object.hasOwn(e,"op")?Wt(e,t):zt(e,t);if(n.op==="create"&&n.id===void 0&&w(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new d(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function Wt(e,t){for(let n of Object.keys(e))if(!Qe.includes(n))throw E(`mutation ${t+1}`,n,Qe);if(e.item!==void 0&&e.op!=="create")throw new d(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new d(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function zt(e,t){let{ref:n,id:r,item:i,...o}=e,a=i!==void 0?i:o;if(i!==void 0&&Object.keys(o).length>0)throw new d(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!w(a))throw new d(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...r===void 0?{}:{id:r},item:a}}function Bt(e){let t=Lt(e);if(!w(t))throw new d("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!tt.includes(n))throw E("mutation document",n,tt);if(t.schema_version!==void 0&&t.schema_version!==1)throw new d("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new d("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,r)=>{if(!w(n))throw new d(`Mutation ${r+1} must be an object.`,u.USAGE);return Jt(n,r)})}function Vt(e,t,n){let r=new Set(Object.values(wt(t,n,Object.create(null))));for(let i of t)i.op==="create"&&typeof i.id=="string"&&i.id.trim().length>0&&r.add(I(i.id,n.idPrefix));return{...e,existing:e.existing.filter(i=>!r.has(i.id))}}function Yt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,r]of e.entries()){if(r.op!=="create"||r.ref!==void 0||typeof r.id=="string"&&r.id.trim().length>0)continue;let i=`${et}${n+1}`;if(t.has(i))throw new d(`Mutation ${n+1} receives the synthesized ref "${i}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${et}<n> aliases are reserved for rows without one.`,u.USAGE);r.ref=i}}function ft(e,t,n){let r=ln(JSON.stringify(e),t,{},n);return delete r.stdinJson,delete r.documentAnnotationSnapshot,r}function ht(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>O(n))}function Ht(e,t){for(let n of e)w(n.item)&&(n.options=ft(n.item,"create",t),delete n.item)}function yt(e,t){return t.some(n=>n.metadata_key===e)?e:Ze(e)}function ie(e,t,n){let r=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(w(e.item)){if(e.item[t]!==void 0)return e.item[t];if(yt(r,n)===t&&e.item[r]!==void 0)return e.item[r]}let i=w(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&i[O(o)]!==void 0?i[O(o)]:i[t]!==void 0?i[t]:i[r]!==void 0?i[r]:(Array.isArray(i.field)?i.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function Xt(e,t){return e<t?-1:+(e!==t)}function oe(e){return Array.isArray(e)?e.map(oe):w(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>Xt(t,n)).map(([t,n])=>[t,oe(n)])):e}function _(e){return typeof e=="string"?e.trim():JSON.stringify(oe(e))}function Zt(e,t,n,r,i){let o=t.key.trim();if(o.length===0)throw new d("Upsert key must be a non-empty field name.",u.USAGE);let a=Qt(t.existing),s=new Map,c=new Set;for(let[m,p]of e.entries()){if(p.op!=="create")continue;let h=en(p,o,m,s,r),f=tn(a.get(h)??[],o,h);if(f===void 0){p.unique={key:o,value:ie(p,o,r)};continue}let y=I(f,n);typeof p.ref=="string"&&(i[p.ref]=y),nn(p,y,r,{key:o,value:ie(p,o,r)}),c.add(m)}return c}function Qt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let r=_(n.value);t.set(r,[...t.get(r)??[],n.id])}return t}function en(e,t,n,r,i){let o=ie(e,t,i);if(o==null||o==="")throw new d(`Mutation ${n+1} is missing the upsert key "${t}".`,u.USAGE,{code:"upsert_key_missing",required:`Every create record must carry a non-empty "${t}" value when --upsert-key ${t} is set.`,why:"Keyed upsert identifies existing items by that field; a record without it cannot be matched or safely created."});let a=_(o),s=r.get(a);if(s!==void 0)throw new d(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,u.USAGE,{code:"upsert_key_duplicate",required:"Each record must carry a distinct upsert key value within one batch.",why:"Two records with the same key would race for the same existing item."});return r.set(a,n),a}function tn(e,t,n){if(e.length>1)throw new d(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,u.CONFLICT,{code:"upsert_key_ambiguous",required:"Resolve the duplicate existing items or choose a key that is unique per item.",why:"An ambiguous key cannot select one item to update without guessing."});return e[0]}function nn(e,t,n,r){let i=new Set([...lt.update,...ht("update",n)]),o=w(e.item)?ft(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>i.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=r}function wt(e,t,n){for(let[r,i]of e.entries())if(i.ref!==void 0){if(i.op!=="create")throw new d(`Mutation ${r+1} ref is only valid for create operations.`,u.USAGE);if(typeof i.ref!="string"||!nt.test(i.ref))throw new d(`Mutation ${r+1} ref must match ${nt.source}.`,u.USAGE);if(n[i.ref]!==void 0)throw new d(`Duplicate mutation ref "${i.ref}".`,u.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?I(i.id,t.idPrefix):Pt(t.transactionId,i.ref,t.idPrefix)}return n}function rr(e,t){let n=Bt(e);Yt(n);let r=n.map(p=>typeof p.ref=="string"?p.ref:void 0),i=Object.create(null),o=t.upsert===void 0?new Set:Zt(n,Vt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],i);Ht(n,t.runtimeFields??[]),wt(n,t,i),Gt(n,r);let a=n.map(p=>{let h={...p},f=typeof h.ref=="string"?h.ref:void 0;if(delete h.ref,f!==void 0?h.id=i[f]:h.id=ot(h.id,i),w(h.options)){let y={...h.options};for(let g of["parent","blockedBy"])y[g]!==void 0&&(y[g]=ot(y[g],i));Array.isArray(y.dep)?y.dep=y.dep.map(g=>at(g,i)):y.dep!==void 0&&(y.dep=at(y.dep,i)),h.options=y}return h}),s=mt(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),c=s.filter(p=>p.op==="create").map(p=>p.id);if(new Set(c).size!==c.length)throw new d("Duplicate resolved create id in mutation document.",u.USAGE);let m=s.map((p,h)=>{let f=r[h];return{index:h,...typeof f=="string"?{ref:f}:{},id:p.id,op:p.op,...o.has(h)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:i,rows:m}}function rn(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let r=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(r)?JSON.stringify(r):r}`}).join(",")}function on(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(w))throw new d(`${n} must be an array of objects.`,u.USAGE);return e.map(r=>rn(r,t))}}function an(e,t){return e==="tags"&&Array.isArray(t)&&t.every(n=>typeof n=="string")?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"?String(t):t}function st(e,t,n=!1){for(let[r,i,o]of Je){let a=t[r],s=on(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(a)?a.filter(c=>!w(c)||c.created_at===void 0):a,o,r);s!==void 0&&s.length>0&&(e[i]=s)}}function sn(e,t){for(let n of Object.keys(e)){if(t){if(!F.includes(n))throw E("item envelope",n,F);continue}if(!b.has(n)&&P(n,[...b])===void 0&&P(n,F)==="item")throw E("item envelope",n,F)}}function cn(e){let t=Object.hasOwn(e,"item");sn(e,t);let n=t?e.item:e;if(!w(n))throw new d("Item document item must be an object.",u.USAGE);return{item:n,...t&&w(e.linked)?{linked:e.linked}:{}}}function dn(e,t,n,r,i,o){if((r==="update"?Ut:pt).has(t))return;let a=i.find(s=>s.metadata_key===t&&s.commands.includes(r));if(a!==void 0){let s=H(o,a);e[O(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!b.has(t)){if(P(t,[...b])!==void 0)throw E("item document",t,[...b]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,c)=>c.toUpperCase())]=an(t,n))}function un(e,t,n){let r=new Set(Object.entries(e).filter(([,o])=>o!==void 0).map(([o])=>o)),i=t==="create"?U:j;for(let{target:o,keys:a}of i)a.some(s=>r.has(s))&&r.add(o);for(let o of n)H(e,o)!==void 0&&r.add(O(o));return r}function pn(e,t,n){let r=t==="create"?U:j;for(let{target:i}of r)i!=="field"&&n.has(i)&&delete e[i]}function ln(e,t,n={},r=[]){let i=ae(e,"Item document");if(!w(i))throw new d("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=cn(i),s={};for(let[h,f]of Object.entries(o)){let y=yt(h,r);y!==h&&Object.hasOwn(o,y)||dn(s,y,f,t,r,n)}st(s,o,t==="update"),a!==void 0&&st(s,a);let c=un(n,t,r);if(pn(s,t,c),t==="update"){let h=Object.fromEntries(["comments","notes","learnings"].filter(f=>Object.hasOwn(o,f)&&!c.has(f.slice(0,-1))).map(f=>[f,o[f].filter(y=>w(y)&&y.created_at!==void 0)]));Object.keys(h).length>0&&(s.documentAnnotationSnapshot=h)}let m={...s,...Object.fromEntries(Object.entries(n).filter(([,h])=>h!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0},p=Object.keys(s).filter(h=>!c.has(h));return Oe(be(m,p),p)}function ir(e){return mt(JSON.stringify(e))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="49806fc6-ff49-5b67-9b3f-c182ace00c20")}catch{}})();async function wn(e,t){if(!je(e))return{schema:Y(t.schema),typeDefinitionsFromFile:[]};let n=await Mn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function gn(e,t,n,r){let i=B({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},V());return(await Fe(e,t.item_format,i.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[r];return a==null?[]:[{id:o.id,value:a}]})}function le(e){let t=new Map,n=async r=>{let i=await De(e),o=await wn(e,i),a=new Map;for(let s of await gn(e,i,o,r)){let c=_(s.value);a.set(c,[...a.get(c)??[],s.id])}return a};return{lookup(r){let i=t.get(r)??n(r);return t.set(r,i),i},async recordCreate(r){for(let[i,o]of t){let a=r[i];if(a==null)continue;let s=await o,c=_(a);s.set(c,[...s.get(c)??[],String(r.id)])}},invalidate(){t.clear()}}}async function vn(e,t){let n=_(t.value),r=(await e.lookup(t.key)).get(n)??[];if(r.length!==0)throw new d(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${r.join(", ")}; the plan was resolved before it existed.`,u.CONFLICT,{code:"upsert_key_conflict",required:"Re-plan the document so the row updates the existing item instead of creating a duplicate.",why:"Keyed upsert is resolved before the writer lock, so every remaining create is re-checked under the lock; concurrent imports therefore cannot create two items for one key value.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan turns the row into an update of the existing item.","Inspect the existing item first when its content should win over the document row."]})}function _n(e,t,n){let r=e.metadata[n.key],i=_(n.value);if(_(r)!==i)throw new d(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(i)}; the plan selected it before the key changed.`,u.CONFLICT,{code:"upsert_match_changed",required:"Re-plan the document so the row is resolved against the current key values.",why:"Keyed upsert selects its target before the writer lock, so the update re-reads the key under the lock instead of updating a mismatched item blindly.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan creates or re-targets the row from the current key values."]})}function gt(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=e;return typeof t.key=="string"&&t.key.trim().length>0&&t.value!==void 0&&t.value!==null}function K(e,t){let n={...e,...t};return e===void 0?n:W(e,n)}async function S(e,t){try{let n=(await te(t,{},{pmRoot:e})).item;return{id:n.id,closedAt:n.closed_at,updatedAt:n.updated_at,assignee:n.assignee,claimPrincipal:n.claim_principal}}catch(n){if(n instanceof d&&n.exitCode===u.NOT_FOUND)return;throw n}}function me(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=ue.createHash("sha256").update(Se(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function Sn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function v(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function M(e,t,n,r){let i=await A(l.join(e,"history",`${t}.jsonl`),t),o=v(n,r,"apply"),a=v(n,r,"compensate");for(let s=i.length-1;s>=0;s-=1){let c=i[s].message;if(c===o)return!0;if(c===a)return!1}return!1}async function fe(e,t){let n=await S(e,t.id);if(n?.updatedAt===void 0)throw new d(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);let r=await A(l.join(e,"history",`${n.id}.jsonl`),n.id);if(r.length===0)throw new d(`Bulk ${t.op} target ${t.id} has no restorable history`,u.NOT_FOUND);return{target_updated_at:n.updatedAt,target_version:String(Z(r)+r.length),target_history_hash:R(r),target_history_length:r.length}}function T(e,t,n){return new d(`Transaction ${e.transactionId} cannot safely compensate incomplete step ${n}; review item ${t} history before recovery.`,u.CONFLICT,{code:"transaction_partial_mutation",item_id:t,required:"Reconcile the item's partial or intervening changes before resuming this transaction.",why:"The retained history does not prove exclusive ownership of the changes to undo. The journal remains compensating instead of claiming a rollback or overwriting another writer.",nextSteps:[`Run pm history ${t} and inspect this transaction's retained compensation data before explicitly restoring or reconciling the item.`]})}function At(e,t){let n=`bulk-item-transaction ${t} `;return[e.message,e.context?.item_transaction_step].some(r=>typeof r=="string"&&r.startsWith(n))}function bn(e,t,n){let{expectedHistory:r,length:i,version:o}=t;if(R(e)===r)return!1;if(typeof i!="number"||!Number.isSafeInteger(i)||i<1||R(e.slice(0,i))!==r||o!==String(Z(e)+i))throw T(n,n.itemId,n.stepId);let a=v(n.transactionId,n.stepId,"apply"),s=e.slice(i),c=f=>f.message===a||f.context?.item_transaction_step===a,m=v(n.transactionId,n.stepId,"compensate");if(s.filter(f=>c(f)||f.message===m).at(-1)?.message===m)return!1;let p=s.filter(c);if(p.length===0)return!1;let h=e.at(-1).after_hash===p.at(-1).after_hash&&s.every(f=>At(f,n.transactionId));if(p.length!==s.length&&!h)throw T(n,n.itemId,n.stepId);return!0}async function L(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;if(i===void 0||typeof i.target_updated_at!="string")return;let o=i.target_updated_at,a=await S(e.pmRoot,t);if(a===void 0)return;let s=await A(l.join(e.pmRoot,"history",`${a.id}.jsonl`),a.id),c=i.target_history_hash;if(typeof c=="string"){if(!bn(s,{expectedHistory:c,length:i.target_history_length,version:i.target_version},{...e,itemId:a.id,stepId:n}))return}else{if(a.updatedAt===o)return;if(!await M(e.pmRoot,a.id,e.transactionId,n))throw T(e,a.id,n)}let m=()=>He(t,typeof i.target_version=="string"?i.target_version:o,{force:!0,author:e.author,message:v(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot});await C({pmRoot:e.pmRoot,id:a.id,validate:p=>{if(X(p)!==s.at(-1).after_hash)throw T(e,a.id,n)}},m)}function Tt(e,t,n){return{id:n,async inspect(){let r=await S(e.pmRoot,t.id);if(r===void 0)return{state:"pending"};if(r.closedAt!==void 0){let i=await A(l.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(i.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new d(`Created item ${r.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:r.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${r.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:r.id,op:"create"}}},async apply(){t.unique!==void 0&&await vn(e.uniqueIndex,t.unique);let r=await ze(K(t.options,{author:e.author,id:t.id,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=r.item;return e.onCreateWarnings?.(String(i.id),r.warnings),await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){await En(e,t.id,n)}}}async function En(e,t,n){let r=await S(e.pmRoot,t);if(r===void 0||e.createCompensation==="close"&&r.closedAt!==void 0)return;let i=await A(l.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=v(e.transactionId,n,"apply"),a=v(e.transactionId,n,"compensate"),s=i.filter(c=>c.message===o||c.message===a).at(-1);if(s?.message!==a){if(s===void 0||!i.every(c=>At(c,e.transactionId)))throw T(e,r.id,n);await C({pmRoot:e.pmRoot,id:r.id,validate:c=>{if(X(c)!==i.at(-1).after_hash)throw T(e,r.id,n)}},async()=>{let c={force:!0,author:e.author,message:a};e.createCompensation==="delete"?await Ye(t,c,{pmRoot:e.pmRoot}):await ne(t,`Compensated: interrupted bulk transaction ${e.transactionId}`,c,{pmRoot:e.pmRoot})})}}function On(e,t,n){return{id:n,compensatePending:!0,async inspect(){let r=await S(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await M(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return fe(e.pmRoot,t)},async apply(){let r=()=>Be(t.id,K(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=t.match,o=i,a=(await C({pmRoot:e.pmRoot,id:String((await te(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:s=>{o!==void 0&&_n(s,t.id,o)},committed:s=>{i!==void 0&&(o={key:i.key,value:structuredClone(s.metadata[i.key])})},historyContext:{item_transaction_step:v(e.transactionId,n,"apply")}},r)).item;return e.uniqueIndex.invalidate(),{id:String(a.id),op:"update"}},async compensate(r){await L(e,t.id,n,r)}}}function An(e,t,n){return{id:n,async inspect(){let r=await S(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await M(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"close"}}:r.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"close"}}},async prepareCompensation(){return fe(e.pmRoot,t)},async apply(){let r=(await ne(t.id,t.reason,K(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"close"}},async compensate(r){await L(e,t.id,n,r)}}}function Tn(e,t,n){return{id:n,async inspect(){let r=await S(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await M(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"release"}}:r.assignee!==void 0||r.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"release"}}},async prepareCompensation(){return fe(e.pmRoot,t)},async apply(){let r=(await Ve(t.id,K(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"release"}},async compensate(r){await L(e,t.id,n,r)}}}function he(e,t,n){let r=me(t,n);switch(t.op){case"create":return Tt(e,t,r);case"update":return On(e,t,r);case"close":return An(e,t,r);case"release":return Tn(e,t,r)}}function $n(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`Bulk mutation ${t+1} must be an object`);if(!["create","update","close","release"].includes(e.op))throw new TypeError(`Bulk mutation ${t+1} op must be create, update, close, or release`);if(typeof e.id!="string"||e.id.trim().length===0)throw new TypeError(`Bulk mutation ${t+1} requires a non-empty id`);if(e.op==="close"&&(typeof e.reason!="string"||e.reason.trim().length===0))throw new TypeError(`Bulk close mutation ${t+1} requires a non-empty reason`);if(e.op==="create"&&e.unique!==void 0&&!gt(e.unique))throw new TypeError(`Bulk create mutation ${t+1} unique must be an object with a non-empty key and a value`);if(e.op==="update"&&e.match!==void 0&&!gt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);D(e.options,e.op,t)}function $t(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,r]of e.entries()){if($n(r,n),r.op!=="create"||r.unique===void 0)continue;let{key:i,value:o}=r.unique,a=t.get(i)??new Map,s=_(o),c=a.get(s);if(c!==void 0)throw new d(`Bulk create mutations ${c+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${i}".`,u.USAGE,{code:"upsert_key_duplicate",required:"Each create must carry a distinct unique key value within one batch.",why:"Direct SDK batches must preserve the same uniqueness invariant as planned document rows."});a.set(s,n),t.set(i,a)}}function kt(e){let t=[...e];return $t(t),t.map(n=>{let r=structuredClone(n);return n.options!==void 0&&r.options!==void 0&&W(n.options,r.options),r})}function Mt(e,t=""){return e===null||typeof e!="object"?[]:Object.entries(e).flatMap(([n,r])=>{let i=`${t}/${n.replaceAll("~","~0").replaceAll("/","~1")}`;return/^(created_at|updated_at|closed_at|completed_at|timestamp)$/u.test(n)?[i]:Mt(r,i)})}async function ce(e,t,n){try{return await n()}catch(r){throw r instanceof d?new d(r.message,r.exitCode,{...r.context,transaction_operation:{index:t,op:e.op,id:e.id}}):r}}function Rt(e,t,n,r){let i=l.relative(e,t),o=i.split(l.sep);return o[0]==="extensions"&&o[2]==="node_modules"&&!r.some(a=>i===a||i.startsWith(`${a}${l.sep}`)||a.startsWith(`${i}${l.sep}`))?!1:["locks","runtime","search"].includes(i.split(l.sep)[0])?r.some(a=>i===a||i.startsWith(`${a}${l.sep}`)||a.startsWith(`${i}${l.sep}`)):i===""||n===void 0||n.some(a=>i===a||i.startsWith(`${a}${l.sep}`)||a.startsWith(`${i}${l.sep}`))}async function G(e,t){let n=await vt(t);if(n.isSymbolicLink())await pe(t);else if(n.isDirectory()||n.isFile())return n;throw k(l.relative(e,t))}async function kn(e,t){let n=await hn(t,se.O_RDONLY|se.O_NOFOLLOW|se.O_NONBLOCK);try{let r=await n.stat();if(!r.isFile())throw k(l.relative(e,t));let i=ue.createHash("sha256");if(r.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:r.size-1,autoClose:!1}))i.update(o);return i.digest()}finally{await n.close()}}async function de(e,t,n){let r=ue.createHash("sha256");async function i(o){for(let a of(await yn(o)).sort()){let s=l.join(o,a);Rt(e,s,t,n)&&((await G(e,s)).isDirectory()?await i(s):(r.update(JSON.stringify(l.relative(e,s))),r.update(await kn(e,s))))}}return await i(e),r.digest("hex")}function x(){return new d("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ye(e){if(!z(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=l.resolve(t),r=n;for(;;)try{let i=await vt(r);return r!==n&&i.isDirectory()}catch(i){if(!z(i))return!1;let o=l.dirname(r);if(o===r)return!1;r=o}}async function q(e,t){let n=l.join(e,t);try{let r=e;for(let i of t.split(l.sep).slice(0,-1))r=l.join(r,i),await G(e,r);if(!(await G(e,n)).isFile())throw k(t);return await Ae(n,k(t))}catch(r){if(await ye(r))return;throw r}}async function It(e,t,n,r){let i=Y(n);for(let[o,a]of Object.entries(i.files)){let s=l.relative(e,Re(e,a,Me[o]));if(s===""||!l.resolve(e,s).startsWith(l.join(e,l.sep)))throw new d("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",u.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});i.files[o]=s;let c=await q(e,s);if(r?.set(s,c),c!==void 0){let m=l.join(t,s);await fn(l.dirname(m),{recursive:!0}),await Et(m,c)}}return Ie(t,i)}async function Mn(e,t){await pe(e);let n=await _t(l.join(Ot(),"pm-schema-plan-"));try{let r=await St(e);return await It(r,l.join(n,"configuration"),t)}catch(r){throw await ye(r)?x():r}finally{await bt(n,{recursive:!0,force:!0})}}async function Rn(e,t,n){let r=new Map,i=await q(e,$);r.set($,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let a=Ue(o),s=a.success?a.data:void 0,c=await It(e,t,s?.schema,r),m=c.schema,p=l.relative(e,Ce(e));r.set(p,await q(e,p));let h=B({..._e,item_types:{definitions:[...s?.item_types?.definitions??[],...c.type_definitions_from_file??[]]}},n),f=Te(e)===e?[...ve.filter(Boolean),$,xe,"transactions",...h.folders,...r.keys()].map(g=>l.normalize(g)):void 0,y=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:m.files}});return{configuration:r,ownedPaths:f,stagedSettings:y,registryFolders:h.folders}}async function In(e,t,n){await pe(e);try{let r=await St(e),i=await Rn(r,l.join(l.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(m=>l.normalize(m)),a=await de(r,i.ownedPaths,o);await mn(r,t,{recursive:!0,dereference:!1,filter:async m=>Rt(r,m,i.ownedPaths,o)?(await G(r,m),!0):!1});let[s,c]=await Promise.all([de(r,i.ownedPaths,o),de(t,i.ownedPaths,o)]);if(a!==s||a!==c)throw x();for(let[m,p]of i.configuration)if(await q(t,m)!==p)throw x();i.stagedSettings!==void 0&&await Et(l.join(t,$),i.stagedSettings)}catch(r){throw await ye(r)?x():r}}async function Ur(e){let t=N(e),n=kt(e.mutations),r=V(),i=await _t(l.join(Ot(),"pm-transaction-preview-")),o=l.join(i,"tracker");try{await In(t.pmRoot,o,r);let a=!1,s=[],c=[],m=new Set;return await Xe({path:o,noExtensions:!0},async()=>{ke(r);let p={...t,pmRoot:o,createCompensation:"close",uniqueIndex:le(o)},h=n.map((f,y)=>{let g=he({...p,onCreateWarnings:(J,we)=>{we.length>0&&s.push({index:y,id:J,op:"create",warnings:we})}},f,y);return{...g,inspect:()=>ce(f,y,()=>g.inspect()),prepareCompensation:()=>ce(f,y,async()=>g.prepareCompensation?.()),apply:()=>ce(f,y,async()=>{let J=await g.apply();return m.add(y),J})}});if(await Q({...t,pmRoot:o,steps:h,onTransition:({transition:f})=>{f==="committed"&&(a=!0)}}),a)for(let[f,y]of n.entries()){let g=(await We(y.id,{path:o},{full:!0})).item;c.push({index:f,id:String(g.id),op:y.op,execution:m.has(f)?"applied":"adopted",item:g,commit_time_fields:Mt(g)})}}),{records:c,validated:a,state:a?"staged_snapshot":"replayed_committed_plan",warnings:s,unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks","derived_extension_dependencies_excluded","generated_timestamps_and_provenance"]}}finally{await bt(i,{recursive:!0,force:!0})}}async function Cn(e){let t=N(e),n=kt(e.mutations),r=e.createCompensation??"close";if(!["close","delete"].includes(r))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={...t,createCompensation:r,uniqueIndex:le(t.pmRoot)},o=await Q({...t,steps:n.map((s,c)=>he(i,s,c)),recoveryData:JSON.parse(JSON.stringify({kind:"item-mutations-v1",mutations:n,createCompensation:r})),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),a={};for(let[s,c]of n.entries()){let m=me(c,s),p=o.results[m];a[Sn(c,s)]=p}return{transactionId:o.transactionId,status:"committed",recovered:o.recovered,results:a}}function Nn(e){let t=[];return e.evidence!==void 0&&Object.keys(e.evidence).length>0&&t.push({op:"update",id:e.id,options:e.evidence}),t.push({op:"close",id:e.id,reason:e.reason,...e.closeOptions===void 0?{}:{options:e.closeOptions}},{op:"release",id:e.id,...e.releaseOptions===void 0?{}:{options:e.releaseOptions}}),t}function jr(e){return Cn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:Nn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Dr={buildCreateStep:Tt,bulkHistoryMarker:v,compensateByRestore:L,deriveStepId:me,isUpdateMarkerApplied:M,readItemSnapshot:S};async function Fr(e,t){let n=await Ge(e,t);return n===void 0?void 0:{journal:n,planDigest:ee(n)}}function Un(e,t){let n=t.recoveryData;if(n===null||typeof n!="object"||Array.isArray(n)||n.kind!=="item-mutations-v1"||!Array.isArray(n.mutations)||!["close","delete"].includes(String(n.createCompensation)))throw new d("Transaction has no supported item recovery plan",u.CONFLICT,{code:"transaction_recovery_plan_missing",required:"Resume with the original plan and its original adapter.",why:"Legacy or foreign journals cannot safely reconstruct item compensation."});let r=n.mutations;$t(r);let i={...e,createCompensation:n.createCompensation,uniqueIndex:le(e.pmRoot)};return r.map((o,a)=>he(i,o,a))}async function Pr(e){let t=N(e),n=await qe({...e,...t,resolveSteps:r=>Un({...e,...t},r)});return{journal:n,planDigest:ee(n)}}export{Ze as a,tr as b,nr as c,mt as d,_ as e,rr as f,ln as g,ir as h,wn as i,gn as j,Mn as k,Ur as l,Cn as m,Nn as n,jr as o,Dr as p,Fr as q,Pr as r};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{$b as He,Sb as ze,Tb as Be,Vb as ne,Yb as Ve,Za as te,_b as Ye,a as xe,vc as Xe}from"./chunk-GXGMMIZN.js";import{u as We}from"./chunk-COTC2QOR.js";import{qc as Je}from"./chunk-TCYIGAQG.js";import{b as N,c as Q,d as Ge,e as ee,f as qe}from"./chunk-5LG5YZYF.js";import{qa as Ke,vb as U,wa as Le,yb as j}from"./chunk-GIAJX2QJ.js";import{Lb as Fe,Mc as Pe,Va as Z,d as be,gb as C,ia as Ne,ka as I,t as Ee,u as Oe,v as W}from"./chunk-UFZQPKQS.js";import{$d as Me,Ad as V,Fa as B,Ff as A,Oa as Te,Ui as Ue,Yi as je,a as Se,ac as $e,be as Y,ce as Re,dj as De,ef as Ce,fe as Ie,je as O,li as R,pe as H,qi as X,zd as ke}from"./chunk-HQINCDF6.js";import{A as u,C as d,G as z,I as Ae,J as k,l as ge,q as $,t as ve,y as _e}from"./chunk-O4ZLEN4T.js";import ue from"node:crypto";import{constants as se}from"node:fs";import{cp as mn,lstat as vt,mkdir as fn,mkdtemp as _t,open as hn,readdir as yn,realpath as St,rm as bt,stat as pe,writeFile as Et}from"node:fs/promises";import{tmpdir as Ot}from"node:os";import l from"node:path";import ct from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="01728cbc-2037-50d2-8318-5f106714b8da")}catch{}})();var b=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...ge,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function Ze(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return b.has(t)?t:e}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="6456f85b-e076-5048-9c21-03d477267259")}catch{}})();function D(e,t,n){let r=e?.estimatedMinutes;if(!(r===void 0||typeof r=="string"))throw new d(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,u.USAGE,{code:"mutation_option_value_invalid",required:'Pass estimatedMinutes as a string, for example "45", in raw mutation options.',why:"Raw options use the create/update command option types; item documents accept numeric estimated_minutes instead.",nextSteps:["Quote the estimatedMinutes value or use an item document with numeric estimated_minutes, then retry the transaction."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a17df3f5-aee8-5734-b1ce-b643482be3a7")}catch{}})();var re=["op","id","reason","options","unique","match"],Ct=[...re,"ref"],Qe=[...Ct,"item"],Nt="mutate-",et="row-",tt=["schema_version","mutations"],dt="[a-z][a-z0-9._-]{0,63}",nt=new RegExp(`^${dt}$`,"u"),ut=new RegExp(`(^|,)id=@(${dt})(?=,|$)`,"gu"),rt=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),F=["item","item_hash","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],pt=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Ut=new Set([...pt,"completed_at","id"]),lt={create:U.map(e=>e.target),update:j.map(e=>e.target),close:Ke.map(e=>rt(e.flag)).filter(e=>e!=="reason"),release:Le.map(e=>rt(e.flag))};function tr(e){let t=ct.createHash("sha256").update(e).digest("hex");return`${Nt}${t.slice(0,24)}`}function nr(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new d("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let r of["lockTtlSeconds","lockWaitMs"]){let i=e[r];if(i===void 0)continue;let o=typeof i=="number"||typeof i=="string"&&i.trim().length>0?Number(i):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new d(`${r} must be a positive safe integer.`,u.USAGE);t[r]=o}return t}function w(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function P(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=$e(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function E(e,t,n){let r=P(t,n);return new d(r===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${r}"?`,u.USAGE,{code:"stdin_json_unknown_key",required:`Use documented ${e} keys only.`,why:"Strict structured input prevents silent typos from creating incomplete or unintended mutations.",nextSteps:[r===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${r}".`]})}function ae(e,t){try{return JSON.parse(e)}catch(n){let r=n instanceof Error?n.message:String(n);throw new d(`${t} must be valid JSON: ${r}`,u.USAGE,{code:"stdin_json_invalid",required:`Pipe one valid JSON ${t.toLowerCase()} into stdin.`,why:"Structured mutation input must parse deterministically before any tracker write begins."})}}function jt(e,t){if(!w(e))throw new d(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!re.includes(n))throw E(`mutation ${t+1}`,n,re);return e}function Dt(e,t,n,r){if(e===void 0)return;if(!w(e))throw new d(`Mutation ${n+1} options must be an object.`,u.USAGE);let i=[...lt[t],...ht(t,r)];for(let o of Object.keys(e))if(!i.includes(o))throw E(`mutation ${n+1} ${t} options`,o,i);return D(e,t,n),e}function it(e,t,n,r){if(e===void 0)return;let i=r==="unique"?"create":"update";if(t!==i)throw new d(`Mutation ${n+1} ${r} is only valid for ${i} operations.`,u.USAGE);let o=w(e)&&typeof e.key=="string"?e.key.trim():"";if(!w(e)||o.length===0||e.value===void 0||e.value===null)throw new d(`Mutation ${n+1} ${r} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Ft(e,t,n){let r=jt(e,t),{op:i,id:o,reason:a}=r;if(i!=="create"&&i!=="update"&&i!=="close"&&i!=="release")throw new d(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=Dt(r.options,i,t,n),c=it(r.unique,i,t,"unique"),m=it(r.match,i,t,"match");if(typeof o!="string"||o.trim().length===0)throw new d(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let p=o.trim();if(i==="close"){if(typeof a!="string"||a.trim().length===0)throw new d(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:i,id:p,reason:a.trim(),...s===void 0?{}:{options:s}}}if(i==="release")return{op:i,id:p,...s===void 0?{}:{options:s}};if(!w(s))throw new d(`Mutation ${t+1} ${i} requires an options object.`,u.USAGE);return{op:i,id:p,options:s,...c===void 0?{}:{unique:c},...m===void 0?{}:{match:m}}}function mt(e,t={}){let n=ae(e,"Mutation batch"),r=Array.isArray(n)?n:w(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(r===void 0||r.length===0)throw new d("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let i=t.runtimeFields??[];return r.map((o,a)=>{let s=Ft(o,a,i);return s.options!==void 0&&Ee(s.options),s})}function Pt(e,t,n){let r=ct.createHash("sha256").update(e).update("\0").update(t).digest("hex"),i=BigInt(`0x${r.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Ne(n)}${i}`}function ot(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),r=t[n];if(r===void 0)throw new d(`Unknown mutation reference "${e}".`,u.USAGE);return r}function at(e,t){if(typeof e!="string")return e;let n=e.replace(ut,(r,i,o)=>{let a=t[o];if(a===void 0)throw new d(`Unknown mutation reference "@${o}".`,u.USAGE);return`${i}id=${a}`});if(/(^|,)id=@/u.test(n))throw new d(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function xt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(ut)].map(t=>t[1]).filter(t=>t!==void 0)}function Gt(e,t){let n=new Map;for(let[a,s]of e.entries()){let c=t[a];if(c===void 0)continue;let m=w(s.options)?s.options:{},p=Array.isArray(m.dep)?m.dep:m.dep===void 0?[]:[m.dep];n.set(c,[m.parent,m.blockedBy,...p].flatMap(xt))}let r=new Set,i=new Set,o=a=>{if(r.has(a))throw new d(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!i.has(a)){r.add(a);for(let s of n.get(a))n.has(s)&&o(s);r.delete(a),i.add(a)}};for(let a of n.keys())o(a)}function qt(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),r=n[0];if(!r.ok&&(r.line.startsWith("[")||r.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&w(o.value)))return null;let i=[];for(let o of n){if(!o.ok)throw new d(`Mutation document line ${o.number} must be one valid JSON object: ${Pe(o.error)}`,u.USAGE,{code:"stdin_json_invalid",required:"Provide one JSON object per line (JSON Lines), a JSON array, or a {schema_version, mutations} document.",why:"Structured mutation input must parse deterministically before any tracker write begins."});if(!w(o.value))throw new d(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);i.push(o.value)}return i}function Kt(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Lt(e){let t;try{t=ae(e,"Mutation document")}catch(n){let r=qt(e);if(r===null)throw n;return{schema_version:1,mutations:r}}return Array.isArray(t)?{schema_version:1,mutations:t}:w(t)&&!Kt(t)?{schema_version:1,mutations:[t]}:t}function Jt(e,t){let n=Object.hasOwn(e,"op")?Wt(e,t):zt(e,t);if(n.op==="create"&&n.id===void 0&&w(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new d(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function Wt(e,t){for(let n of Object.keys(e))if(!Qe.includes(n))throw E(`mutation ${t+1}`,n,Qe);if(e.item!==void 0&&e.op!=="create")throw new d(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new d(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function zt(e,t){let{ref:n,id:r,item:i,...o}=e,a=i!==void 0?i:o;if(i!==void 0&&Object.keys(o).length>0)throw new d(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!w(a))throw new d(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...r===void 0?{}:{id:r},item:a}}function Bt(e){let t=Lt(e);if(!w(t))throw new d("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!tt.includes(n))throw E("mutation document",n,tt);if(t.schema_version!==void 0&&t.schema_version!==1)throw new d("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new d("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,r)=>{if(!w(n))throw new d(`Mutation ${r+1} must be an object.`,u.USAGE);return Jt(n,r)})}function Vt(e,t,n){let r=new Set(Object.values(wt(t,n,Object.create(null))));for(let i of t)i.op==="create"&&typeof i.id=="string"&&i.id.trim().length>0&&r.add(I(i.id,n.idPrefix));return{...e,existing:e.existing.filter(i=>!r.has(i.id))}}function Yt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,r]of e.entries()){if(r.op!=="create"||r.ref!==void 0||typeof r.id=="string"&&r.id.trim().length>0)continue;let i=`${et}${n+1}`;if(t.has(i))throw new d(`Mutation ${n+1} receives the synthesized ref "${i}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${et}<n> aliases are reserved for rows without one.`,u.USAGE);r.ref=i}}function ft(e,t,n){let r=ln(JSON.stringify(e),t,{},n);return delete r.stdinJson,delete r.documentAnnotationSnapshot,r}function ht(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>O(n))}function Ht(e,t){for(let n of e)w(n.item)&&(n.options=ft(n.item,"create",t),delete n.item)}function yt(e,t){return t.some(n=>n.metadata_key===e)?e:Ze(e)}function ie(e,t,n){let r=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(w(e.item)){if(e.item[t]!==void 0)return e.item[t];if(yt(r,n)===t&&e.item[r]!==void 0)return e.item[r]}let i=w(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&i[O(o)]!==void 0?i[O(o)]:i[t]!==void 0?i[t]:i[r]!==void 0?i[r]:(Array.isArray(i.field)?i.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function Xt(e,t){return e<t?-1:+(e!==t)}function oe(e){return Array.isArray(e)?e.map(oe):w(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>Xt(t,n)).map(([t,n])=>[t,oe(n)])):e}function _(e){return typeof e=="string"?e.trim():JSON.stringify(oe(e))}function Zt(e,t,n,r,i){let o=t.key.trim();if(o.length===0)throw new d("Upsert key must be a non-empty field name.",u.USAGE);let a=Qt(t.existing),s=new Map,c=new Set;for(let[m,p]of e.entries()){if(p.op!=="create")continue;let h=en(p,o,m,s,r),f=tn(a.get(h)??[],o,h);if(f===void 0){p.unique={key:o,value:ie(p,o,r)};continue}let y=I(f,n);typeof p.ref=="string"&&(i[p.ref]=y),nn(p,y,r,{key:o,value:ie(p,o,r)}),c.add(m)}return c}function Qt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let r=_(n.value);t.set(r,[...t.get(r)??[],n.id])}return t}function en(e,t,n,r,i){let o=ie(e,t,i);if(o==null||o==="")throw new d(`Mutation ${n+1} is missing the upsert key "${t}".`,u.USAGE,{code:"upsert_key_missing",required:`Every create record must carry a non-empty "${t}" value when --upsert-key ${t} is set.`,why:"Keyed upsert identifies existing items by that field; a record without it cannot be matched or safely created."});let a=_(o),s=r.get(a);if(s!==void 0)throw new d(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,u.USAGE,{code:"upsert_key_duplicate",required:"Each record must carry a distinct upsert key value within one batch.",why:"Two records with the same key would race for the same existing item."});return r.set(a,n),a}function tn(e,t,n){if(e.length>1)throw new d(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,u.CONFLICT,{code:"upsert_key_ambiguous",required:"Resolve the duplicate existing items or choose a key that is unique per item.",why:"An ambiguous key cannot select one item to update without guessing."});return e[0]}function nn(e,t,n,r){let i=new Set([...lt.update,...ht("update",n)]),o=w(e.item)?ft(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>i.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=r}function wt(e,t,n){for(let[r,i]of e.entries())if(i.ref!==void 0){if(i.op!=="create")throw new d(`Mutation ${r+1} ref is only valid for create operations.`,u.USAGE);if(typeof i.ref!="string"||!nt.test(i.ref))throw new d(`Mutation ${r+1} ref must match ${nt.source}.`,u.USAGE);if(n[i.ref]!==void 0)throw new d(`Duplicate mutation ref "${i.ref}".`,u.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?I(i.id,t.idPrefix):Pt(t.transactionId,i.ref,t.idPrefix)}return n}function rr(e,t){let n=Bt(e);Yt(n);let r=n.map(p=>typeof p.ref=="string"?p.ref:void 0),i=Object.create(null),o=t.upsert===void 0?new Set:Zt(n,Vt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],i);Ht(n,t.runtimeFields??[]),wt(n,t,i),Gt(n,r);let a=n.map(p=>{let h={...p},f=typeof h.ref=="string"?h.ref:void 0;if(delete h.ref,f!==void 0?h.id=i[f]:h.id=ot(h.id,i),w(h.options)){let y={...h.options};for(let g of["parent","blockedBy"])y[g]!==void 0&&(y[g]=ot(y[g],i));Array.isArray(y.dep)?y.dep=y.dep.map(g=>at(g,i)):y.dep!==void 0&&(y.dep=at(y.dep,i)),h.options=y}return h}),s=mt(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),c=s.filter(p=>p.op==="create").map(p=>p.id);if(new Set(c).size!==c.length)throw new d("Duplicate resolved create id in mutation document.",u.USAGE);let m=s.map((p,h)=>{let f=r[h];return{index:h,...typeof f=="string"?{ref:f}:{},id:p.id,op:p.op,...o.has(h)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:i,rows:m}}function rn(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let r=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(r)?JSON.stringify(r):r}`}).join(",")}function on(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(w))throw new d(`${n} must be an array of objects.`,u.USAGE);return e.map(r=>rn(r,t))}}function an(e,t){return e==="tags"&&Array.isArray(t)&&t.every(n=>typeof n=="string")?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"?String(t):t}function st(e,t,n=!1){for(let[r,i,o]of Je){let a=t[r],s=on(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(a)?a.filter(c=>!w(c)||c.created_at===void 0):a,o,r);s!==void 0&&s.length>0&&(e[i]=s)}}function sn(e,t){for(let n of Object.keys(e)){if(t){if(!F.includes(n))throw E("item envelope",n,F);continue}if(!b.has(n)&&P(n,[...b])===void 0&&P(n,F)==="item")throw E("item envelope",n,F)}}function cn(e){let t=Object.hasOwn(e,"item");sn(e,t);let n=t?e.item:e;if(!w(n))throw new d("Item document item must be an object.",u.USAGE);return{item:n,...t&&w(e.linked)?{linked:e.linked}:{}}}function dn(e,t,n,r,i,o){if((r==="update"?Ut:pt).has(t))return;let a=i.find(s=>s.metadata_key===t&&s.commands.includes(r));if(a!==void 0){let s=H(o,a);e[O(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!b.has(t)){if(P(t,[...b])!==void 0)throw E("item document",t,[...b]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,c)=>c.toUpperCase())]=an(t,n))}function un(e,t,n){let r=new Set(Object.entries(e).filter(([,o])=>o!==void 0).map(([o])=>o)),i=t==="create"?U:j;for(let{target:o,keys:a}of i)a.some(s=>r.has(s))&&r.add(o);for(let o of n)H(e,o)!==void 0&&r.add(O(o));return r}function pn(e,t,n){let r=t==="create"?U:j;for(let{target:i}of r)i!=="field"&&n.has(i)&&delete e[i]}function ln(e,t,n={},r=[]){let i=ae(e,"Item document");if(!w(i))throw new d("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=cn(i),s={};for(let[h,f]of Object.entries(o)){let y=yt(h,r);y!==h&&Object.hasOwn(o,y)||dn(s,y,f,t,r,n)}st(s,o,t==="update"),a!==void 0&&st(s,a);let c=un(n,t,r);if(pn(s,t,c),t==="update"){let h=Object.fromEntries(["comments","notes","learnings"].filter(f=>Object.hasOwn(o,f)&&!c.has(f.slice(0,-1))).map(f=>[f,o[f].filter(y=>w(y)&&y.created_at!==void 0)]));Object.keys(h).length>0&&(s.documentAnnotationSnapshot=h)}let m={...s,...Object.fromEntries(Object.entries(n).filter(([,h])=>h!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0},p=Object.keys(s).filter(h=>!c.has(h));return Oe(be(m,p),p)}function ir(e){return mt(JSON.stringify(e))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="49806fc6-ff49-5b67-9b3f-c182ace00c20")}catch{}})();async function wn(e,t){if(!je(e))return{schema:Y(t.schema),typeDefinitionsFromFile:[]};let n=await Mn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function gn(e,t,n,r){let i=B({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},V());return(await Fe(e,t.item_format,i.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[r];return a==null?[]:[{id:o.id,value:a}]})}function le(e){let t=new Map,n=async r=>{let i=await De(e),o=await wn(e,i),a=new Map;for(let s of await gn(e,i,o,r)){let c=_(s.value);a.set(c,[...a.get(c)??[],s.id])}return a};return{lookup(r){let i=t.get(r)??n(r);return t.set(r,i),i},async recordCreate(r){for(let[i,o]of t){let a=r[i];if(a==null)continue;let s=await o,c=_(a);s.set(c,[...s.get(c)??[],String(r.id)])}},invalidate(){t.clear()}}}async function vn(e,t){let n=_(t.value),r=(await e.lookup(t.key)).get(n)??[];if(r.length!==0)throw new d(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${r.join(", ")}; the plan was resolved before it existed.`,u.CONFLICT,{code:"upsert_key_conflict",required:"Re-plan the document so the row updates the existing item instead of creating a duplicate.",why:"Keyed upsert is resolved before the writer lock, so every remaining create is re-checked under the lock; concurrent imports therefore cannot create two items for one key value.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan turns the row into an update of the existing item.","Inspect the existing item first when its content should win over the document row."]})}function _n(e,t,n){let r=e.metadata[n.key],i=_(n.value);if(_(r)!==i)throw new d(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(i)}; the plan selected it before the key changed.`,u.CONFLICT,{code:"upsert_match_changed",required:"Re-plan the document so the row is resolved against the current key values.",why:"Keyed upsert selects its target before the writer lock, so the update re-reads the key under the lock instead of updating a mismatched item blindly.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan creates or re-targets the row from the current key values."]})}function gt(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=e;return typeof t.key=="string"&&t.key.trim().length>0&&t.value!==void 0&&t.value!==null}function K(e,t){let n={...e,...t};return e===void 0?n:W(e,n)}async function S(e,t){try{let n=(await te(t,{},{pmRoot:e})).item;return{id:n.id,closedAt:n.closed_at,updatedAt:n.updated_at,assignee:n.assignee,claimPrincipal:n.claim_principal}}catch(n){if(n instanceof d&&n.exitCode===u.NOT_FOUND)return;throw n}}function me(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=ue.createHash("sha256").update(Se(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function Sn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function v(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function M(e,t,n,r){let i=await A(l.join(e,"history",`${t}.jsonl`),t),o=v(n,r,"apply"),a=v(n,r,"compensate");for(let s=i.length-1;s>=0;s-=1){let c=i[s].message;if(c===o)return!0;if(c===a)return!1}return!1}async function fe(e,t){let n=await S(e,t.id);if(n?.updatedAt===void 0)throw new d(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);let r=await A(l.join(e,"history",`${n.id}.jsonl`),n.id);if(r.length===0)throw new d(`Bulk ${t.op} target ${t.id} has no restorable history`,u.NOT_FOUND);return{target_updated_at:n.updatedAt,target_version:String(Z(r)+r.length),target_history_hash:R(r),target_history_length:r.length}}function T(e,t,n){return new d(`Transaction ${e.transactionId} cannot safely compensate incomplete step ${n}; review item ${t} history before recovery.`,u.CONFLICT,{code:"transaction_partial_mutation",item_id:t,required:"Reconcile the item's partial or intervening changes before resuming this transaction.",why:"The retained history does not prove exclusive ownership of the changes to undo. The journal remains compensating instead of claiming a rollback or overwriting another writer.",nextSteps:[`Run pm history ${t} and inspect this transaction's retained compensation data before explicitly restoring or reconciling the item.`]})}function At(e,t){let n=`bulk-item-transaction ${t} `;return[e.message,e.context?.item_transaction_step].some(r=>typeof r=="string"&&r.startsWith(n))}function bn(e,t,n){let{expectedHistory:r,length:i,version:o}=t;if(R(e)===r)return!1;if(typeof i!="number"||!Number.isSafeInteger(i)||i<1||R(e.slice(0,i))!==r||o!==String(Z(e)+i))throw T(n,n.itemId,n.stepId);let a=v(n.transactionId,n.stepId,"apply"),s=e.slice(i),c=f=>f.message===a||f.context?.item_transaction_step===a,m=v(n.transactionId,n.stepId,"compensate");if(s.filter(f=>c(f)||f.message===m).at(-1)?.message===m)return!1;let p=s.filter(c);if(p.length===0)return!1;let h=e.at(-1).after_hash===p.at(-1).after_hash&&s.every(f=>At(f,n.transactionId));if(p.length!==s.length&&!h)throw T(n,n.itemId,n.stepId);return!0}async function L(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;if(i===void 0||typeof i.target_updated_at!="string")return;let o=i.target_updated_at,a=await S(e.pmRoot,t);if(a===void 0)return;let s=await A(l.join(e.pmRoot,"history",`${a.id}.jsonl`),a.id),c=i.target_history_hash;if(typeof c=="string"){if(!bn(s,{expectedHistory:c,length:i.target_history_length,version:i.target_version},{...e,itemId:a.id,stepId:n}))return}else{if(a.updatedAt===o)return;if(!await M(e.pmRoot,a.id,e.transactionId,n))throw T(e,a.id,n)}let m=()=>He(t,typeof i.target_version=="string"?i.target_version:o,{force:!0,author:e.author,message:v(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot});await C({pmRoot:e.pmRoot,id:a.id,validate:p=>{if(X(p)!==s.at(-1).after_hash)throw T(e,a.id,n)}},m)}function Tt(e,t,n){return{id:n,async inspect(){let r=await S(e.pmRoot,t.id);if(r===void 0)return{state:"pending"};if(r.closedAt!==void 0){let i=await A(l.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(i.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new d(`Created item ${r.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:r.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${r.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:r.id,op:"create"}}},async apply(){t.unique!==void 0&&await vn(e.uniqueIndex,t.unique);let r=await ze(K(t.options,{author:e.author,id:t.id,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=r.item;return e.onCreateWarnings?.(String(i.id),r.warnings),await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){await En(e,t.id,n)}}}async function En(e,t,n){let r=await S(e.pmRoot,t);if(r===void 0||e.createCompensation==="close"&&r.closedAt!==void 0)return;let i=await A(l.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=v(e.transactionId,n,"apply"),a=v(e.transactionId,n,"compensate"),s=i.filter(c=>c.message===o||c.message===a).at(-1);if(s?.message!==a){if(s===void 0||!i.every(c=>At(c,e.transactionId)))throw T(e,r.id,n);await C({pmRoot:e.pmRoot,id:r.id,validate:c=>{if(X(c)!==i.at(-1).after_hash)throw T(e,r.id,n)}},async()=>{let c={force:!0,author:e.author,message:a};e.createCompensation==="delete"?await Ye(t,c,{pmRoot:e.pmRoot}):await ne(t,`Compensated: interrupted bulk transaction ${e.transactionId}`,c,{pmRoot:e.pmRoot})})}}function On(e,t,n){return{id:n,compensatePending:!0,async inspect(){let r=await S(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await M(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return fe(e.pmRoot,t)},async apply(){let r=()=>Be(t.id,K(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=t.match,o=i,a=(await C({pmRoot:e.pmRoot,id:String((await te(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:s=>{o!==void 0&&_n(s,t.id,o)},committed:s=>{i!==void 0&&(o={key:i.key,value:structuredClone(s.metadata[i.key])})},historyContext:{item_transaction_step:v(e.transactionId,n,"apply")}},r)).item;return e.uniqueIndex.invalidate(),{id:String(a.id),op:"update"}},async compensate(r){await L(e,t.id,n,r)}}}function An(e,t,n){return{id:n,async inspect(){let r=await S(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await M(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"close"}}:r.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"close"}}},async prepareCompensation(){return fe(e.pmRoot,t)},async apply(){let r=(await ne(t.id,t.reason,K(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"close"}},async compensate(r){await L(e,t.id,n,r)}}}function Tn(e,t,n){return{id:n,async inspect(){let r=await S(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await M(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"release"}}:r.assignee!==void 0||r.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"release"}}},async prepareCompensation(){return fe(e.pmRoot,t)},async apply(){let r=(await Ve(t.id,K(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"release"}},async compensate(r){await L(e,t.id,n,r)}}}function he(e,t,n){let r=me(t,n);switch(t.op){case"create":return Tt(e,t,r);case"update":return On(e,t,r);case"close":return An(e,t,r);case"release":return Tn(e,t,r)}}function $n(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`Bulk mutation ${t+1} must be an object`);if(!["create","update","close","release"].includes(e.op))throw new TypeError(`Bulk mutation ${t+1} op must be create, update, close, or release`);if(typeof e.id!="string"||e.id.trim().length===0)throw new TypeError(`Bulk mutation ${t+1} requires a non-empty id`);if(e.op==="close"&&(typeof e.reason!="string"||e.reason.trim().length===0))throw new TypeError(`Bulk close mutation ${t+1} requires a non-empty reason`);if(e.op==="create"&&e.unique!==void 0&&!gt(e.unique))throw new TypeError(`Bulk create mutation ${t+1} unique must be an object with a non-empty key and a value`);if(e.op==="update"&&e.match!==void 0&&!gt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);D(e.options,e.op,t)}function $t(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,r]of e.entries()){if($n(r,n),r.op!=="create"||r.unique===void 0)continue;let{key:i,value:o}=r.unique,a=t.get(i)??new Map,s=_(o),c=a.get(s);if(c!==void 0)throw new d(`Bulk create mutations ${c+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${i}".`,u.USAGE,{code:"upsert_key_duplicate",required:"Each create must carry a distinct unique key value within one batch.",why:"Direct SDK batches must preserve the same uniqueness invariant as planned document rows."});a.set(s,n),t.set(i,a)}}function kt(e){let t=[...e];return $t(t),t.map(n=>{let r=structuredClone(n);return n.options!==void 0&&r.options!==void 0&&W(n.options,r.options),r})}function Mt(e,t=""){return e===null||typeof e!="object"?[]:Object.entries(e).flatMap(([n,r])=>{let i=`${t}/${n.replaceAll("~","~0").replaceAll("/","~1")}`;return/^(created_at|updated_at|closed_at|completed_at|timestamp)$/u.test(n)?[i]:Mt(r,i)})}async function ce(e,t,n){try{return await n()}catch(r){throw r instanceof d?new d(r.message,r.exitCode,{...r.context,transaction_operation:{index:t,op:e.op,id:e.id}}):r}}function Rt(e,t,n,r){let i=l.relative(e,t),o=i.split(l.sep);return o[0]==="extensions"&&o[2]==="node_modules"&&!r.some(a=>i===a||i.startsWith(`${a}${l.sep}`)||a.startsWith(`${i}${l.sep}`))?!1:["locks","runtime","search"].includes(i.split(l.sep)[0])?r.some(a=>i===a||i.startsWith(`${a}${l.sep}`)||a.startsWith(`${i}${l.sep}`)):i===""||n===void 0||n.some(a=>i===a||i.startsWith(`${a}${l.sep}`)||a.startsWith(`${i}${l.sep}`))}async function G(e,t){let n=await vt(t);if(n.isSymbolicLink())await pe(t);else if(n.isDirectory()||n.isFile())return n;throw k(l.relative(e,t))}async function kn(e,t){let n=await hn(t,se.O_RDONLY|se.O_NOFOLLOW|se.O_NONBLOCK);try{let r=await n.stat();if(!r.isFile())throw k(l.relative(e,t));let i=ue.createHash("sha256");if(r.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:r.size-1,autoClose:!1}))i.update(o);return i.digest()}finally{await n.close()}}async function de(e,t,n){let r=ue.createHash("sha256");async function i(o){for(let a of(await yn(o)).sort()){let s=l.join(o,a);Rt(e,s,t,n)&&((await G(e,s)).isDirectory()?await i(s):(r.update(JSON.stringify(l.relative(e,s))),r.update(await kn(e,s))))}}return await i(e),r.digest("hex")}function x(){return new d("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ye(e){if(!z(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=l.resolve(t),r=n;for(;;)try{let i=await vt(r);return r!==n&&i.isDirectory()}catch(i){if(!z(i))return!1;let o=l.dirname(r);if(o===r)return!1;r=o}}async function q(e,t){let n=l.join(e,t);try{let r=e;for(let i of t.split(l.sep).slice(0,-1))r=l.join(r,i),await G(e,r);if(!(await G(e,n)).isFile())throw k(t);return await Ae(n,k(t))}catch(r){if(await ye(r))return;throw r}}async function It(e,t,n,r){let i=Y(n);for(let[o,a]of Object.entries(i.files)){let s=l.relative(e,Re(e,a,Me[o]));if(s===""||!l.resolve(e,s).startsWith(l.join(e,l.sep)))throw new d("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",u.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});i.files[o]=s;let c=await q(e,s);if(r?.set(s,c),c!==void 0){let m=l.join(t,s);await fn(l.dirname(m),{recursive:!0}),await Et(m,c)}}return Ie(t,i)}async function Mn(e,t){await pe(e);let n=await _t(l.join(Ot(),"pm-schema-plan-"));try{let r=await St(e);return await It(r,l.join(n,"configuration"),t)}catch(r){throw await ye(r)?x():r}finally{await bt(n,{recursive:!0,force:!0})}}async function Rn(e,t,n){let r=new Map,i=await q(e,$);r.set($,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let a=Ue(o),s=a.success?a.data:void 0,c=await It(e,t,s?.schema,r),m=c.schema,p=l.relative(e,Ce(e));r.set(p,await q(e,p));let h=B({..._e,item_types:{definitions:[...s?.item_types?.definitions??[],...c.type_definitions_from_file??[]]}},n),f=Te(e)===e?[...ve.filter(Boolean),$,xe,"transactions",...h.folders,...r.keys()].map(g=>l.normalize(g)):void 0,y=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:m.files}});return{configuration:r,ownedPaths:f,stagedSettings:y,registryFolders:h.folders}}async function In(e,t,n){await pe(e);try{let r=await St(e),i=await Rn(r,l.join(l.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(m=>l.normalize(m)),a=await de(r,i.ownedPaths,o);await mn(r,t,{recursive:!0,dereference:!1,filter:async m=>Rt(r,m,i.ownedPaths,o)?(await G(r,m),!0):!1});let[s,c]=await Promise.all([de(r,i.ownedPaths,o),de(t,i.ownedPaths,o)]);if(a!==s||a!==c)throw x();for(let[m,p]of i.configuration)if(await q(t,m)!==p)throw x();i.stagedSettings!==void 0&&await Et(l.join(t,$),i.stagedSettings)}catch(r){throw await ye(r)?x():r}}async function Ur(e){let t=N(e),n=kt(e.mutations),r=V(),i=await _t(l.join(Ot(),"pm-transaction-preview-")),o=l.join(i,"tracker");try{await In(t.pmRoot,o,r);let a=!1,s=[],c=[],m=new Set;return await Xe({path:o,noExtensions:!0},async()=>{ke(r);let p={...t,pmRoot:o,createCompensation:"close",uniqueIndex:le(o)},h=n.map((f,y)=>{let g=he({...p,onCreateWarnings:(J,we)=>{we.length>0&&s.push({index:y,id:J,op:"create",warnings:we})}},f,y);return{...g,inspect:()=>ce(f,y,()=>g.inspect()),prepareCompensation:()=>ce(f,y,async()=>g.prepareCompensation?.()),apply:()=>ce(f,y,async()=>{let J=await g.apply();return m.add(y),J})}});if(await Q({...t,pmRoot:o,steps:h,onTransition:({transition:f})=>{f==="committed"&&(a=!0)}}),a)for(let[f,y]of n.entries()){let g=(await We(y.id,{path:o},{full:!0})).item;c.push({index:f,id:String(g.id),op:y.op,execution:m.has(f)?"applied":"adopted",item:g,commit_time_fields:Mt(g)})}}),{records:c,validated:a,state:a?"staged_snapshot":"replayed_committed_plan",warnings:s,unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks","derived_extension_dependencies_excluded","generated_timestamps_and_provenance"]}}finally{await bt(i,{recursive:!0,force:!0})}}async function Cn(e){let t=N(e),n=kt(e.mutations),r=e.createCompensation??"close";if(!["close","delete"].includes(r))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={...t,createCompensation:r,uniqueIndex:le(t.pmRoot)},o=await Q({...t,steps:n.map((s,c)=>he(i,s,c)),recoveryData:JSON.parse(JSON.stringify({kind:"item-mutations-v1",mutations:n,createCompensation:r})),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),a={};for(let[s,c]of n.entries()){let m=me(c,s),p=o.results[m];a[Sn(c,s)]=p}return{transactionId:o.transactionId,status:"committed",recovered:o.recovered,results:a}}function Nn(e){let t=[];return e.evidence!==void 0&&Object.keys(e.evidence).length>0&&t.push({op:"update",id:e.id,options:e.evidence}),t.push({op:"close",id:e.id,reason:e.reason,...e.closeOptions===void 0?{}:{options:e.closeOptions}},{op:"release",id:e.id,...e.releaseOptions===void 0?{}:{options:e.releaseOptions}}),t}function jr(e){return Cn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:Nn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Dr={buildCreateStep:Tt,bulkHistoryMarker:v,compensateByRestore:L,deriveStepId:me,isUpdateMarkerApplied:M,readItemSnapshot:S};async function Fr(e,t){let n=await Ge(e,t);return n===void 0?void 0:{journal:n,planDigest:ee(n)}}function Un(e,t){let n=t.recoveryData;if(n===null||typeof n!="object"||Array.isArray(n)||n.kind!=="item-mutations-v1"||!Array.isArray(n.mutations)||!["close","delete"].includes(String(n.createCompensation)))throw new d("Transaction has no supported item recovery plan",u.CONFLICT,{code:"transaction_recovery_plan_missing",required:"Resume with the original plan and its original adapter.",why:"Legacy or foreign journals cannot safely reconstruct item compensation."});let r=n.mutations;$t(r);let i={...e,createCompensation:n.createCompensation,uniqueIndex:le(e.pmRoot)};return r.map((o,a)=>he(i,o,a))}async function Pr(e){let t=N(e),n=await qe({...e,...t,resolveSteps:r=>Un({...e,...t},r)});return{journal:n,planDigest:ee(n)}}export{Ze as a,tr as b,nr as c,mt as d,_ as e,rr as f,ln as g,ir as h,wn as i,gn as j,Mn as k,Ur as l,Cn as m,Nn as n,jr as o,Dr as p,Fr as q,Pr as r};
|
|
2
|
+
//# sourceMappingURL=chunk-O6T24Z3M.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Df as W,Fa as G,Na as E,Rb as B,Zi as H,cf as $,dj as P,ij as L,nc as U,pj as V}from"./chunk-HQINCDF6.js";import{d as K}from"./chunk-RSAN2YUU.js";import{a as X,b as v,c as q}from"./chunk-VS565KBX.js";import{A as b,C as k,E as S,G as j,H as N,K as F}from"./chunk-O4ZLEN4T.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new e.Error().stack;r&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[r]="6d1f8e03-97b4-5d83-b85c-e47f39c07d48")}catch{}})();var se="PM_SOURCE_CONTEXT_ACCESS",ce="PM_ALLOW_SOURCE_CONTEXT_WRITES";function J(e){let r=e[se],i=r===void 0||r.trim().toLowerCase()==="write"?"write":"read_only",t=i==="read_only"&&e[ce]?.trim()==="1";return{access:i,write_override_applied:t,source_writes_allowed:i==="write"||t}}import{access as le,readFile as A,realpath as w}from"node:fs/promises";import{constants as me}from"node:fs";import{execFile as ue}from"node:child_process";import c from"node:path";import{promisify as de}from"node:util";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new e.Error().stack;r&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[r]="b1828465-0619-514c-8956-2a81dea9efbc")}catch{}})();var _=de(ue),T="# pm-cli:merge-drivers:start",pe="# pm-cli:merge-drivers:end",x="# pm-cli:merge-drivers:v2:start",Q="# pm-cli:merge-drivers:v2:end",fe="merge-fence",ge="merge-attributes";function R(e){return`'${e.replaceAll("'",`'"'"'`)}'`}async function he(e,r){let i=await w(e);if(/(?:^|[\\/])bun-node-[^\\/]+[\\/]bun(?:\.exe)?$/iu.test(i))return;let{stdout:t}=await _(e,["--version"],{encoding:"utf8",windowsHide:!0,timeout:1e4});return t.trim()===r?i:void 0}async function we(){let e=U(import.meta.url,["../../.."]),r=process.execPath,i=!1,t=await w(process.execPath),o=process.versions.bun,a=(process.env.PATH??"").split(c.delimiter).filter(n=>c.isAbsolute(n)).map(n=>c.join(n,o===void 0?c.basename(process.execPath):process.platform==="win32"?"bun.exe":"bun")),s=o===void 0?a:[process.env.npm_execpath??"",...a,t].filter(n=>c.isAbsolute(n)&&/^(?:bun|bun\.exe)$/iu.test(c.basename(n)));for(let n of s)try{if(await le(n,me.X_OK),o!==void 0){let p=await he(n,o);if(p!==void 0){r=p,i=!0;break}continue}if(n!==t&&await w(n)===t){r=n;break}}catch{}if(o!==void 0&&!i)throw new k("Cannot install Bun merge drivers without a durable executable matching the current Bun version.",b.DEPENDENCY_FAILED,{code:"merge_bun_launcher_unavailable",why:"The current Bun process may be a temporary bunx launcher that Git cannot reuse after this command exits.",nextSteps:["Run with a durable version-matched Bun executable, expose one on an absolute PATH entry, or invoke pm through a Bun runner that publishes an absolute npm_execpath.","Retry pm merge install, then check pm health --strict-exit before merging branches."]});return`${R(r)} ${R(c.join(e,"dist","cli.js"))}`}var Z=[{key:"pm-item-toon",name:"pm field-aware TOON item document merge",artifact:"item",itemPath:"%P"},{key:"pm-item-markdown",name:"pm field-aware JSON-markdown item document merge",artifact:"item",itemPath:"%P"},{key:"pm-history",name:"pm append-only history stream merge",artifact:"history",itemPath:void 0},{key:"pm-relationship",name:"pm append-only relationship event store merge",artifact:"relationship",itemPath:void 0},{key:"pm-json",name:"pm key-level JSON config merge",artifact:"json",itemPath:void 0}];function ye(e){let r=e.explicitPath?.trim(),i=e.environment.PM_SOURCE_WORKSPACE_ROOT?.trim(),t=e.environment.PM_SOURCE_PM_PATH?.trim(),o=J(e.environment),a=!!(i&&t),s=r===void 0&&a&&(e.dryRun||o.source_writes_allowed);if(r!==void 0){let n=E(e.cwd,r);return{pm_root:n,workspace_start:n,source_coordinates_available:a,source_context_selected:!1,source_policy:o}}return s?{pm_root:c.resolve(t),workspace_start:c.resolve(i),source_coordinates_available:!0,source_context_selected:!0,source_policy:o}:{pm_root:a?E(e.cwd,".agents/pm"):E(e.cwd),workspace_start:e.cwd,source_coordinates_available:a,source_context_selected:!1,source_policy:o}}async function ee(e){try{let{stdout:r}=await _("git",["rev-parse","--show-toplevel"],{cwd:e,env:v(),encoding:"utf8",windowsHide:!0,timeout:1e4});return await w(r.trim())}catch{return null}}async function te(e){let r=await ee(e);if(r===null)throw new k("pm merge install requires a git repository (merge drivers are git configuration).",b.USAGE);return r}function O(e,r){return c.relative(e,r).split(c.sep).join("/")}function z(e){return e.replace(/[\\*?[\]!]/gu,"\\$&")}function h(e){return`"${e.replaceAll("\\","\\\\").replaceAll('"','\\"')}"`}function Y(e,r){if(e[r]!=="'")return null;let i="";for(let t=r+1;t<e.length;t+=1){if(e.startsWith(`'"'"'`,t)){i+="'",t+=4;continue}if(e[t]==="'")return{value:i,nextOffset:t+1};i+=e[t]}return null}async function ve(e,r,i){if(L(r).filter(o=>o.constraint==="exact").some(o=>o.version!==i))return!1;let t=await ee(e);if(t!==null&&t!==await w(r)){let o=await Promise.all([t,r].map(async a=>{let s=await _("git",["rev-parse","--path-format=absolute","--git-common-dir"],{cwd:a,env:v(),timeout:1e4});return w(s.stdout.trim())}));if(o[0]===o[1])return!1}return!0}async function _e(e,r,i){let t=Y(e,0);if(t===null||e[t.nextOffset]!==" ")return!1;let o=Y(e,t.nextOffset+1);if(o===null||e.slice(o.nextOffset)!==r||!/^(?:node|bun)(?:\.exe)?$/iu.test(c.basename(t.value))||c.basename(o.value)!=="cli.js"||c.basename(c.dirname(o.value))!=="dist"||!await S(t.value)||!await S(o.value))return!1;try{let a=c.dirname(c.dirname(o.value)),s=JSON.parse(await A(c.join(a,"package.json"),"utf8")),n=typeof s.bin=="string"?s.bin:s.bin?.pm;return await ve(a,i,s.version)?s.name==="@unbrained/pm-cli"&&n==="dist/cli.js":!1}catch{return!1}}function M(e,r){let i=e.length>0?`${z(e)}/`:"",t=[`${h(`${i}**/*.toon`)} merge=pm-item-toon`,`${h(`${i}**/*.md`)} merge=pm-item-markdown`];for(let o of r){let a=z(o);t.push(`${h(`${i}${a}/*.toon`)} merge=pm-item-toon`),t.push(`${h(`${i}${a}/*.md`)} merge=pm-item-markdown`)}return t.push(`${h(`${i}**/*.jsonl`)} merge=pm-relationship`),t.push(`${h(`${i}history/*.jsonl`)} merge=pm-history`),t.push(`${h(`${i}settings.json`)} merge=pm-json`),t.push(`${h(`${i}**/*.json`)} merge=pm-json`),t.push(`${h(`${i}extensions/**`)} merge=text`),t.push(`${h(`${i}extensions/.managed-extensions.json`)} merge=pm-json`),t}function re(e){let r=[],i=0;for(;i<e.length;){let t=e.indexOf(T,i),o=e.indexOf(x,i),a=t===-1?o:o===-1?t:Math.min(t,o);if(a===-1)break;let s=a===o,n=s?x:T,p=s?Q:pe,u=e.indexOf(p,a+n.length),m=u===-1?e.length:u+p.length;r.push({start:a,end:m,closed:u!==-1,lines:e.slice(a+n.length,u===-1?m:u).split(`
|
|
2
2
|
`).map(l=>l.trim()).filter(Boolean)}),i=m}return r}function ie(e,r,i){let t=new Set(r),o=h(i.length>0?`${i}/`:"").slice(0,-1);return e.some(a=>t.has(a)||a.startsWith(o)&&/^[^/]+\/\*\.(?:toon|md)" merge=pm-item-(?:toon|markdown)$/u.test(a.slice(o.length)))}async function oe(e,r,i,t){let o=c.join(e,".gitattributes"),a=t?null:(await _("git",["rev-parse","--absolute-git-dir"],{cwd:e,env:v(),encoding:"utf8",windowsHide:!0,timeout:1e4})).stdout.trim(),s=a===null?null:await $(a,ge,120,"merge-fence",!1,!0,5e3);try{let n=await N(o)??"",p=[x,...i,Q].join(`
|
|
3
3
|
`),u=re(n),m=u.filter(d=>ie(d.lines,i,r));m.length===0&&r===".agents/pm"&&u.length===1&&u[0].lines.every(d=>!d.includes("/"))&&m.push(u[0]);let l;if(m.length>0){let d=m[0];l=n;for(let y of m.slice(1).reverse())l=`${l.slice(0,y.start)}${l.slice(y.end)}`;l=`${l.slice(0,d.start)}${p}${l.slice(d.end)}`}else{let d=n.trimEnd();l=`${d.length>0?`${d}
|
|
4
4
|
|
|
5
5
|
`:""}${p}
|
|
6
6
|
`}return l===n?{path:o,changed:!1}:(t||await F(o,l),{path:o,changed:!0})}finally{await s?.()}}function ne(e){let r=G(e,null);return[...new Set(Object.values(r.type_to_folder))].sort((i,t)=>i.localeCompare(t))}async function Ve(e,r){let i=c.resolve(e),t=null,o="",a=i;for(let g=0;g<8;g+=1){let ae=c.join(a,".gitattributes");try{let C=await A(ae,"utf8");if(C.includes(x)||C.includes(T)){t=a,o=C;break}}catch{}let D=c.dirname(a);if(D===a)break;a=D}if(t===null)return{status:"not_installed",missing_patterns:[],stale_patterns:[],schema_scope:"project"};let s=c.join(t,".gitattributes"),n=O(t,i),p=re(o),u=M(n,r),m=p.filter(g=>ie(g.lines,u,n)),l=m.flatMap(g=>g.closed?g.lines:[]),d=new Set(l),y=new Set(u),f=u.filter(g=>!d.has(g)),I=l.filter(g=>!y.has(g));return{status:m.length!==1||!m[0].closed||f.length>0||I.length>0?"drift":"ok",path:s,missing_patterns:f,stale_patterns:I,schema_scope:"project"}}async function Ke(e){let r=[],i=[];for(let t of Z){let o=`merge.${t.key}.driver`,a=` merge driver ${t.artifact} "%O" "%A" "%B"${t.itemPath===void 0?"":` --item-path ${t.itemPath}`}`;try{let{stdout:s}=await _("git",["config","--get",o],{cwd:e,env:v(),encoding:"utf8",windowsHide:!0,timeout:1e4}),n=s.trim();await _e(n,a,e)||i.push(o)}catch{r.push(o)}}return{status:r.length>0?"missing":i.length>0?"drift":"ok",missing_keys:r,drifted_keys:i}}async function Xe(e){let r;try{r=await te(c.resolve(e))}catch{return{status:"no_git"}}let i=O(r,c.resolve(e)),t=await P(e),o=W(void 0,t.author_default),a=await $(e,fe,t.locks.ttl_seconds,o,!1,H(t).force_required_for_stale_lock,t.locks.wait_ms);try{let s=c.join(r,".gitattributes"),n;try{n=await A(s,"utf8")}catch(l){if(l instanceof Error&&"code"in l&&j(l))return{status:"not_installed",path:s};throw l}if(!n.includes(x)&&!n.includes(T))return{status:"not_installed",path:s};let p=await P(e),u=ne(p),m=await oe(r,i,M(i,u),!1);return{status:m.changed?"refreshed":"unchanged",path:m.path}}finally{await a()}}async function qe(e,r){let i=ye({cwd:process.cwd(),explicitPath:r.path,dryRun:e.dryRun===!0,environment:process.env}),t=i.pm_root;await V(t);let o=await te(i.workspace_start);return ke({pmRoot:t,workspaceRoot:o,dryRun:e.dryRun===!0,preCommitHook:e.preCommitHook===!0})}async function be(e,r){let i=(await _("git",["rev-parse","--path-format=absolute","--git-common-dir"],{cwd:e,env:v(),timeout:1e4})).stdout.trim(),t=await $(i,"merge-driver-config",120,"merge-install",!1,!0,5e3);try{let o=await q(e),a;try{a=(await _("git",["config",o,"--null","--get-regexp","."],{cwd:e,env:v(),timeout:1e4})).stdout}catch(n){if(typeof n!="object"||n===null||!("code"in n)||n.code!==1)throw n;a=""}let s=new Map(a.split("\0").filter(Boolean).map(n=>{let p=n.indexOf(`
|
|
7
7
|
`);return[n.slice(0,p),n.slice(p+1)]}));for(let n of r)s.get(n.key)!==n.value&&await X(e,[o,n.key,n.value])}finally{await t()}}async function ke(e){let r=c.resolve(e.pmRoot),i=c.resolve(e.workspaceRoot),t=e.dryRun===!0,o,a;try{[o,a]=await Promise.all([w(r),w(i)])}catch(f){throw new k(`Cannot resolve tracker root ${r} or workspace root ${i}: ${String(f)}`,b.NOT_FOUND,{code:"merge_root_not_found",nextSteps:["Initialize the tracker and ensure both paths are accessible.",'Retry "pm merge install" from the repository workspace.']})}let s=O(a,o);if(K(s))throw new k(`Tracker root ${r} is outside the git repository ${i}; there is nothing to configure for this repository.`,b.USAGE);let n=await P(o),p=ne(n),u=M(s,p),m=[],l=await we(),d=e.preCommitHook===!0?await import("./settlement-hook-JHXLUBEN.js").then(async f=>({plan:await f.prepareMergeSettlementHook(a,`${l} --pm-path ${R(s||".")}`),write:f.writeMergeSettlementHook})):void 0;for(let f of Z)m.push({key:`merge.${f.key}.name`,value:f.name}),m.push({key:`merge.${f.key}.driver`,value:`${l} merge driver ${f.artifact} "%O" "%A" "%B"${f.itemPath===void 0?"":` --item-path ${f.itemPath}`}`});if(!t)try{await be(a,m)}catch{throw new k(`Cannot install repository-local merge drivers in ${a}. Ensure the repository Git config is writable and no other Git process holds its lock, then retry.`,b.DEPENDENCY_FAILED,{code:"merge_git_config_unwritable",why:"pm merge install must persist clone-local driver commands before publishing their shared .gitattributes mappings.",nextSteps:["Make the repository Git config writable or wait for the process holding its lock to finish.",'Retry "pm merge install"; the operation is idempotent.','Use "pm merge install --dry-run --json" when the workspace is intentionally read-only.']})}let y=await oe(a,s,u,t);return d!==void 0&&!t&&await d.write(d.plan),{ok:!0,dry_run:t,workspace_root:a,pm_root:o,gitattributes:{path:y.path,changed:y.changed,patterns:u,schema_scope:"project"},git_config:m,...d===void 0?{}:{settlement_hook:{path:d.plan.path,changed:d.plan.changed}},guidance:["Commit .gitattributes so every branch and collaborator shares the merge mapping.",'git config is per-clone: each collaborator (and each fresh worktree/clone) runs "pm merge install" once.','After merging branches, run "pm merge reconcile --dry-run" to inspect the complete receipt and history repair, then apply "pm merge reconcile"; use --force only after explicitly accepting any discarded values.',"Custom item types registered later refresh this fence automatically (pm schema add-type/remove-type); rerun pm merge install only after out-of-band type-folder edits."],generated_at:B()}}export{se as a,ce as b,J as c,T as d,pe as e,x as f,Q as g,ye as h,ee as i,M as j,ne as k,Ve as l,Ke as m,Xe as n,qe as o,ke as p};
|
|
8
|
-
//# sourceMappingURL=chunk-
|
|
8
|
+
//# sourceMappingURL=chunk-OQCVU2SG.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as k,c as I,d as A,e as E,k as T,m as _}from"./chunk-
|
|
1
|
+
import{a as k,c as I,d as A,e as E,k as T,m as _}from"./chunk-COTC2QOR.js";import{lb as b,mb as v,nb as R}from"./chunk-QSSENTXG.js";import{Bc as f,Ec as g,Fc as a,Wc as w}from"./chunk-GIAJX2QJ.js";import{ca as D,nd as H}from"./chunk-UFZQPKQS.js";import{Fd as C,_h as x,bi as m,ci as y}from"./chunk-HQINCDF6.js";import{A as c,C as p}from"./chunk-O4ZLEN4T.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="631e56aa-4d7e-58b6-bbea-a0d320716b82")}catch{}})();(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="0bcdd63c-5fd3-585d-a6c5-9393029ef864")}catch{}})();(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="4dce4f19-071c-54a8-be0d-5975d9e3b34b")}catch{}})();(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="f330a0c5-a967-5383-9c27-efa4a39e0f0d")}catch{}})();(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="f910b36e-c3ed-532e-a679-12547d249443")}catch{}})();function O(t,e){if(typeof t!="string")return;let o=Number.parseInt(t,10);if(!/^\d+$/.test(t.trim())||!Number.isSafeInteger(o))throw new p(`history-compact ${e} must be a non-negative integer.`,c.USAGE);return o}async function S(t,e,o){let r=f(o),n=Date.now(),i=await D(a(e,"ids")),l=i===void 0?void 0:H(i),d=O(e.allOver,"--all-over"),u=O(e.minEntries,"--min-entries");if(e.closed===!0&&e.allStreams===!0)throw new p("history-compact: --closed and --all-streams are mutually exclusive; pick one lifecycle scope.",c.USAGE);let s=e.closed===!0?"closed":e.allStreams===!0?"all-streams":void 0;if((l!==void 0||d!==void 0||s!==void 0)&&typeof e.before=="string")throw new p("history-compact: --before applies only in single-id mode (bulk mode always compacts full streams).",c.USAGE);if(I(t,{ids:l,allOver:d,scope:s}),t!==void 0&&u!==void 0)throw new p("history-compact: --min-entries applies only in bulk mode (single-id mode compacts the named stream).",c.USAGE);if(t===void 0){let h=await A({ids:l,scope:s,allOver:d,minEntries:u,dryRun:e.dryRun===!0,author:a(e,"author"),message:a(e,"message"),force:!!e.force},r);m(h,r),h.totals.items_errored>0&&(process.exitCode=c.GENERIC_FAILURE)}else{let h=await k(t,{before:a(e,"before"),dryRun:e.dryRun===!0,author:a(e,"author"),message:a(e,"message"),force:!!e.force},r);m(h,r)}r.profile&&y(`profile:command=history-compact took_ms=${Date.now()-n}`)}async function N(t,e,o,r){let n=f(r),i=Date.now(),l=await _(t,e,{author:a(o,"author"),message:a(o,"message"),force:!!o.force},n);await w(n,l),m(l,n),n.profile&&y(`profile:command=restore took_ms=${Date.now()-i}`)}async function B(t,e){let o=f(e),r=await T({verify:a(t,"verify"),output:a(t,"output"),hashAlgorithm:a(t,"hashAlgorithm")},o);"format"in r?(C(r),o.quiet||x(`${JSON.stringify(r,null,2)}
|
|
2
2
|
`)):m(r,o),"ok"in r&&!r.ok&&(process.exitCode=c.GENERIC_FAILURE)}function Z(t,e){t.command(e?"attest":"history-attest",{hidden:!e}).summary("Export or verify history proof.").option("--verify <file>","Compare retained streams with a detached JSON proof").option("--output <file>","Create a proof file and return a compact receipt").option("--hash-algorithm <name>","Bundle digest algorithm: sha256 (default) or sha512").description("Export exact-byte history commitments, or verify an independently retained proof without tracker writes.").action(B),t.command("restore",{hidden:!e}).summary("Restore a version.").argument("<id>","Item id").argument("<target>","Restore target timestamp or version number").option("--author <value>","Mutation author").option("--message <value>","History message").option("--force","Force ownership/lock override").description("Restore an item to an earlier timestamp or version.").action(N),t.command(e?"redact":"history-redact",{hidden:!e}).summary("Redact sensitive values.").argument("<id>","Item id").option("--literal <value>","Literal; repeatable",g).option("--regex <value>","Raw RegExp source (repeatable; e.g. /var/[a-z]+) or /pattern/flags. Leading-slash input is a literal only when the final unescaped slash is followed by supported JavaScript flag letters or nothing.",g).option("--replacement <value>",'Default: "[redacted]"').option("--dry-run","Preview; no item/history edits").option("--author <value>","Author").option("--message <value>","Audit marker message").option("--force","Override owner/lock").description("Redact and reseal item history.").action(async(o,r,n)=>{let i=f(n),l=Date.now(),d=Array.isArray(r.literal)?r.literal:void 0,u=Array.isArray(r.regex)?r.regex:void 0,s=await E(o,{literal:d,regex:u,replacement:a(r,"replacement"),dryRun:r.dryRun===!0,author:a(r,"author"),message:a(r,"message"),force:!!r.force},i);s.changed&&!s.dry_run&&await w(i,s),m(s,i),i.profile&&y(`profile:command=history-redact took_ms=${Date.now()-l}`)}),t.command(e?"repair":"history-repair",{hidden:!e}).summary("Repair drift.").argument("[id]","Item id (omit with --all)").option("--salvage-tail","Recover invalid tail; requires verified prefix").option("--all","Scan every stream for drift and repair each drifted stream in one audited pass").option("--dry-run","Preview the re-anchor impact without writing the history file").option("--normalize-provenance","Remove invalid provenance; return aggregate-only evidence").option("--author <value>","Mutation author").option("--message <value>","Audit history message for the repair marker entry").option("--force","Force ownership/lock override").description("Re-anchor a drifted item history chain (recompute hashes, reconcile with the on-disk item) and record an audit marker. Use --all to repair every drifted stream.").action(async(o,r,n)=>{let i=f(n),l=Date.now(),d=r.all===!0;v(o,d);let u={dryRun:r.dryRun===!0,author:a(r,"author"),message:a(r,"message"),force:!!r.force,normalizeProvenance:r.normalizeProvenance===!0,salvageTail:r.salvageTail===!0};if(d){let s=await R(u,i);m(s,i),s.totals.failed>0&&(process.exitCode=c.GENERIC_FAILURE)}else{let s=await b(o,u,i);m(s,i)}i.profile&&y(`profile:command=history-repair took_ms=${Date.now()-l}`)}),t.command(e?"compact":"history-compact",{hidden:!e}).summary("Compact streams.").argument("[id]","Item id (omit when using a bulk selector)").option("--before <value>","Compact entries strictly before this version number or ISO timestamp (single-id mode only)").option("--ids <value>","Bulk IDs: comma/newline text, - stdin, or @path file").option("--all-over <n>","Bulk: compact every stream with more than N entries").option("--closed","Bulk: compact only closed (terminal) items' streams").option("--all-streams","Bulk: compact every history stream regardless of lifecycle state").option("--min-entries <n>","Bulk: skip streams with at most N entries (already compact; default 3)").option("--dry-run","Preview compaction impact without writing the history file").option("--author <value>","Mutation author").option("--message <value>","Audit history message for the compaction marker entry").option("--force","Force ownership/lock override").description("Compact item history streams into a synthetic baseline plus retained tail entries. Pass an item id for one stream, or a bulk selector (--ids/--all-over/--closed/--all-streams) to compact many.").action(S)}export{Z as a};
|
|
3
|
-
//# sourceMappingURL=chunk-
|
|
3
|
+
//# sourceMappingURL=chunk-PUU5DXSV.js.map
|