@unbrained/pm-cli 2026.10.13 → 2026.10.14
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 +19 -0
- package/dist/cli/extension-command-help.js +2 -2
- package/dist/cli/extension-command-options.js +1 -1
- package/dist/cli/main.js +2 -2
- package/dist/cli-bundle/bundle-manifest.json +1 -1
- package/dist/cli-bundle/chunks/{chunk-AM2XOZKE.js → chunk-2UKKO45F.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-3S5SEMEB.js +8 -0
- package/dist/cli-bundle/chunks/{chunk-LBDWFWPK.js → chunk-5LU6PWA4.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-RL45OYTL.js → chunk-66BZVFIK.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-IDEHMKYZ.js +235 -0
- package/dist/cli-bundle/chunks/{chunk-UBTYYZIE.js → chunk-JTF6VMXH.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-YH6H3UVE.js → chunk-LE4IEHDG.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-APWPC4ZZ.js → chunk-LKESCZEN.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HXHFKXLV.js → chunk-LOSRTNNP.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-N5EXRYCZ.js → chunk-MAT4AP7P.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-PSNS537F.js → chunk-PP3BVMFL.js} +28 -28
- package/dist/cli-bundle/chunks/{chunk-IFPJDJUM.js → chunk-UNQZGMJL.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-WYZGZV2M.js → chunk-YXRAYL7H.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-BJ742QOR.js → register-list-query-GBLTOQQL.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-GGGBRIH2.js → register-mutation-TNRHNK4N.js} +2 -2
- package/dist/cli-bundle/chunks/{register-operations-E6HXYHNM.js → register-operations-J3WXP3MA.js} +2 -2
- package/dist/cli-bundle/chunks/{register-setup-4ZVTVEPY.js → register-setup-HLSKKU4V.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-73UNAJHD.js → chunk-23ACMPGB.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-NNW5BS5L.js → chunk-4UA7KY4V.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-KGFRQ34R.js → chunk-AULVKHYX.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-3LQEBXU5.js → chunk-BUAGNTLG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-DVK7VKZL.js → chunk-ELQNEJDA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-SOB7X4FJ.js → chunk-ESOW6PH4.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-HNRI2KBT.js +3 -0
- package/dist/cli-bundle/focused-chunks/{chunk-IIKFTJVC.js → chunk-IGBSAHCA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-F5J3ATMV.js → chunk-JDVZF75H.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-RU6GCFN3.js → chunk-KSMQEB3V.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-LKWDWER4.js +20 -0
- package/dist/cli-bundle/focused-chunks/{chunk-RAA7SVRA.js → chunk-QIU4Y3AB.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-R23T7GFZ.js → chunk-RHQCQTZA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-UPJA45K7.js → chunk-WIXZF5SS.js} +18 -18
- package/dist/cli-bundle/focused-chunks/{chunk-6BTUISKV.js → chunk-Y5A4XOSK.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-QMNAY25P.js → chunk-YJNKISEI.js} +6 -6
- package/dist/cli-bundle/main.js +22 -22
- 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 +22 -22
- 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 +46 -46
- 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 +7 -7
- package/dist/core/extensions/flag-definition-validation.d.ts +13 -0
- package/dist/core/extensions/flag-definition-validation.js +1 -1
- package/dist/core/extensions/flag-value-types.js +1 -1
- package/dist/core/sentry/helpers.d.ts +2 -0
- package/dist/core/sentry/helpers.js +1 -1
- package/dist/core/sentry/instrument.d.ts +2 -0
- package/dist/core/sentry/instrument.js +1 -1
- package/dist/core/telemetry/runtime.d.ts +1 -1
- package/dist/core/telemetry/runtime.js +2 -2
- package/dist/sdk/cli-contracts/runtime-contracts.js +1 -1
- package/dist/sdk/governance/defect-recurrence.js +2 -1
- package/dist/sdk/merge/install.js +1 -1
- package/dist/sdk/public-surface.json +1 -1
- package/dist/sdk/runtime-primitives.d.ts +4 -2
- package/dist/sdk/runtime-primitives.js +1 -1
- package/dist/sdk/testing.d.ts +4 -0
- package/dist/sdk/testing.js +2 -2
- package/docs/CONFIGURATION.md +43 -0
- package/docs/DEFECT_RECURRENCE.md +8 -0
- package/docs/EXTENSIONS.md +1 -1
- package/docs/EXTENSION_AUTHOR_CONTRACTS.md +19 -0
- package/docs/MERGE_SAFETY.md +8 -0
- package/docs/SDK.md +19 -0
- 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-DJDRHJBP.js +0 -234
- package/dist/cli-bundle/chunks/chunk-DUK5DHI6.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-IOTNG6CN.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-S6ITXQ5T.js +0 -20
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as nt,b as Cn,c as yc,d as bc,g as wc,i as zc}from"./chunk-AM2XOZKE.js";import{A as rl,P as er,Y as il,d as Eo,e as Hc,g as Wc,h as Vc,i as Bc,o as Kc,p as Mt,q as Ge,r as Zo,y as Qo}from"./chunk-RL45OYTL.js";import{$c as nl,Aa as pc,Ba as uc,Ca as In,Da as _c,Ea as An,Fa as En,Ga as fc,Gb as Dc,Ia as et,Id as tr,J as Le,Ja as hc,Jb as Mc,Ka as jo,Kb as jc,La as Tn,Ld as _l,Na as tt,Oc as Ho,Pb as Nt,Rc as Ie,Sc as Jc,Tc as Vo,Uc as Yc,Ud as fl,Vc as Xc,Vd as hl,Wa as gc,Wc as ot,Xc as Zc,_c as tl,ad as ol,b as No,bd as Jo,cd as Yo,dd as Xo,fc as On,ga as hn,gd as sl,ha as ac,hd as cl,i as Os,ia as Pt,id as ll,j as $s,ja as h,jd as dl,ka as sc,kd as ml,l as Fs,la as cc,mb as kc,mc as Uc,md as pl,na as Y,nb as Sc,nd as ul,oa as lc,oc as qc,pa as vn,qa as dc,ra as Do,sa as Lt,sb as Go,ta as kn,tb as Uo,ua as Me,ub as qo,va as mc,vc as Dt,wa as Sn,wb as Ic,xa as U,xb as Ac,ya as Mo,yb as zo,za as j}from"./chunk-PSNS537F.js";import{$a as wn,E as Ps,K as Ls,M as Ne,N as Ns,O as yn,P as Ds,Pa as Qe,Q as De,R as Ms,S as bn,T as js,Wa as oc,Z as Gs,aa as Us,c as fa,ca as qs,da as zs,db as rc,ea as Hs,fa as Ws,ga as Vs,gb as ic,ha as Bs,i as gn,ia as Ks,ja as Js,ka as Ys,la as Xs,ma as Zs,na as Qs,oa as ec,pa as tc,qa as nc}from"./chunk-YH6H3UVE.js";import{$a as Ec,Ab as Nc,Eb as Se,Fb as Gc,Gb as xn,Kb as Wo,Vc as Bo,Yb as Qc,Zb as el,_c as Ko,bd as al,d as ua,f as _a,jb as Tc,kb as Cc,lb as Rc,na as de,ob as xc,pb as Oc,qb as $c,rb as Fc,tb as je,ua as vc,ub as Pc,vb as Lc,yb as Rn}from"./chunk-IFPJDJUM.js";import{$ as oe,$d as Di,$e as qi,$m as ks,A as _i,Ad as Li,Al as Xa,B as fi,Bl as ln,C as hi,Cl as dn,Cm as us,D as gi,Df as Vi,Dg as Fe,Dl as mn,Dm as _s,Ed as H,El as pn,Fg as Ye,Fk as Ra,Fm as _n,G as yi,Gf as Ke,Gj as ga,Gl as re,Gm as fs,Go as Rs,Hk as xa,Ii as To,Ij as ya,Il as Za,Ja as co,Ji as Co,Jj as sn,Jl as Qa,Ka as lo,Kf as Bi,Kg as on,Kj as ba,La as mo,Lg as Tt,Ma as po,Mg as ko,Ml as $t,Mm as hs,Nk as Oa,Nl as es,Nm as gs,Ok as $a,Ol as ts,Pi as ca,Pk as Fa,Pl as ns,Pn as Po,Qb as vi,Qd as tn,Qj as wa,Ql as os,R as u,Rb as ki,Rh as Ct,Rm as xo,Rn as Lo,Se as Gi,Sh as Rt,Si as Ze,Sk as Pa,So as xs,T as p,Tm as Oo,Ub as Si,Uf as Ki,Uj as va,V as ye,Va as P,Vc as Zt,Vf as F,Vl as Ro,W as Be,Wa as Yt,Wc as Qt,Wk as La,Wl as rs,X as ro,Xc as en,Xd as Ni,Xk as Na,Xl as Pe,Xm as ys,Y as se,Yd as nn,Ye as Ui,Yg as ea,Yk as Da,Ym as bs,Zc as Oi,Zg as ta,Zj as ka,Zk as Ma,Zl as is,Zm as ws,_g as na,_j as Sa,_k as ja,_l as as,_m as vs,aa as kt,aj as la,ak as Ia,al as Ga,am as un,bb as A,bl as Ua,bn as Ss,ce as Mi,cj as da,cl as qa,cm as ss,cn as Is,dd as _o,dj as ma,dk as Aa,dl as za,dm as cs,dn as As,eb as we,ej as ce,el as Ha,em as ls,en as Ft,f as J,fb as uo,fd as fo,fe as ji,fj as ve,fl as Wa,fn as Es,gd as ho,gn as fn,h as oo,ha as bi,hb as xe,hd as go,hg as Je,hn as Ts,id as yo,if as S,ig as Oe,ij as xt,il as Va,in as $o,j as pi,ja as wi,jd as bo,jg as Ji,jl as cn,jn as Fo,ka as be,kd as wo,kg as Yi,kl as Ba,kn as Cs,ld as vo,lg as $e,li as oa,lj as an,ll as Ka,mc as Ii,md as $,mf as zi,mg as Xi,mi as Xe,na as io,nc as Ai,oc as Ei,of as Hi,oh as So,oj as Ot,om as ds,p as Jt,pc as Ti,pf as ne,pg as V,ph as R,pi as rn,pj as pa,pl as ke,qa as ao,qc as Ci,ql as E,ra as St,rc as Ri,rd as $i,rg as Et,ri as ra,rl as Ja,sc as xi,sd as Fi,sg as Zi,si as ia,sl as Ya,sm as ms,ta as so,tb as It,ti as aa,tk as Ea,u as Ve,ub as At,vd as G,vf as Wi,vi as Io,w as ui,wb as Xt,wg as Qi,wi as Ao,wk as Ta,wm as ps,xj as ha,xk as Ca,yi as T,zd as Pi,zi as sa,zm as le}from"./chunk-DJDRHJBP.js";import{AsyncLocalStorage as Gg}from"node:async_hooks";import{readFile as hp}from"node:fs/promises";import gp 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]="20a3a324-d176-5918-8167-5e548be4abc9")}catch{}})();var nr="context-intents.json";function $n(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function yp(e,t,n){if(!$n(e))throw new TypeError(`${t} context intent at index ${String(n)} must be an object`);let o=e.included_field_groups;if(typeof e.command!="string"||typeof e.intent!="string"||typeof e.description!="string"||!Array.isArray(o)||!o.every(r=>typeof r=="string")||typeof e.token_budget!="number")throw new TypeError(`${t} context intent at index ${String(n)} has an invalid contract shape`);return{command:e.command,intent:e.intent,description:e.description,included_field_groups:o,token_budget:e.token_budget}}function gl(e,t){let n=Array.isArray(e)?e:$n(e)&&Array.isArray(e.intents)?e.intents:void 0;if(!n)throw new TypeError(`${t} context intents must be an array or an object with an intents array`);return n.map((o,r)=>yp(o,t,r))}async function bp(e){let t=gp.join(e,nr),n;try{n=await hp(t,"utf8")}catch(r){if(Be(r))return[];throw await Ki(e),r}let o;try{o=JSON.parse(n)}catch(r){let i=r instanceof Error?r.message:String(r);throw new TypeError(`Invalid ${nr}: ${i}`,{cause:r})}return gl(o,nr)}function wp(e){if(!$n(e))return;let t=e.contextIntents??e.context_intents;if(t!==void 0)return t;let n=e.default;return $n(n)?n.contextIntents??n.context_intents:void 0}function vp(e){return e.flatMap(t=>{let n=wp(t.module);return n===void 0?[]:gl(n,`package ${t.name}`)})}async function kp(e){let t=await bp(e.pmRoot),n=vp(e.packages??[]);return{workspaceContracts:t,packageContracts:n}}async function Fn(e,t){let n=await kp(e);return await Vi(n,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]="0a4abc17-0fcb-573f-8f89-6e505e112261")}catch{}})();async function yl(e,t,n=Wi){try{await n({pmRoot:e,result:t})}catch{if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let o=t,r=Array.isArray(o.warnings)?o.warnings.filter(i=>typeof i=="string"):[];o.warnings=[...new Set([...r,"context_usage_feedback_write_failed"])].sort()}}}import{createHash as xp}from"node:crypto";import{constants as jt}from"node:fs";import{lstat as bl,mkdir as rr,open as wl}from"node:fs/promises";import me 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]="5434ff6f-95af-5983-88cb-fd360d95cb9e")}catch{}})();function or(e,t){if(typeof e!="string"||e.trim().length===0)throw new TypeError(`Relationship event ${t} must be non-empty`);return e.trim()}function ir(e,t){let n=t.require(e.kind),o=n.direction==="undirected"?[e.source,e.target].sort().join("\0"):`${e.source}\0${e.target}`;return`${n.kind}\0${o}`}function Sp(e){return Object.freeze({...e,...e.payload===void 0?{}:{payload:Object.freeze(structuredClone(e.payload))}})}function Ip(e,t,n,o){let r=n.require(e.kind),i=o.outgoingOne.get(`${r.kind}\0${e.source}`);if(i!==void 0&&i!==t)throw new TypeError(`Relationship outgoing cardinality exceeded for ${r.kind}`);let a=o.incomingOne.get(`${r.kind}\0${e.target}`);if(a!==void 0&&a!==t)throw new TypeError(`Relationship incoming cardinality exceeded for ${r.kind}`);let s=ir(e,n),c=o.identities.get(s);if(c!==void 0&&c!==t)throw new TypeError(`Relationship edge already active: ${s}`)}function Ap(e){let t=new Map;for(let n of e)n.action==="remove"?t.delete(n.relationshipId):t.set(n.relationshipId,n.edge);return t}function Ep(e,t,n){if(e.expectedVersion!==void 0&&e.expectedVersion!==t)throw new TypeError(`Relationship event version conflict: expected ${e.expectedVersion}, current ${t}`);let o=or(e.eventId,"eventId");if(n.has(o))throw new TypeError(`Relationship event already exists: ${o}`);if(e.action!=="add"&&e.action!=="remove"&&e.action!=="supersede")throw new TypeError(`Unknown relationship event action: ${e.action}`);if(!Number.isFinite(Date.parse(e.timestamp)))throw new TypeError("Relationship event timestamp must be valid");return{eventId:o,relationshipId:or(e.relationshipId,"relationshipId"),author:or(e.author,"author"),timestamp:new Date(e.timestamp).toISOString()}}function Tp(e,t,n,o,r,i){let a=n.has(t);if(e.action==="add"&&a)throw new TypeError(`Relationship is already active: ${t}`);if(e.action!=="add"&&!a)throw new TypeError(`Relationship is not active: ${t}`);if(e.action==="remove")return;if(!e.edge)throw new TypeError(`Relationship ${e.action} event requires an edge`);let s=typeof e.edge.source=="string"?e.edge.source.trim():"",c=typeof e.edge.target=="string"?e.edge.target.trim():"";if(!o.has(s)||!o.has(c))throw new TypeError(`Relationship endpoint not found: ${s} -> ${c}`);let l=new Ve([s,c],[e.edge],r).edges()[0];return Ip(l,t,r,i),Sp(l)}var Gt=class{#t;#n;#o=[];#i=new Set;#e=new Map;#r={identities:new Map,outgoingOne:new Map,incomingOne:new Map};constructor(t,n={}){this.#t=new Set([...t].filter(o=>typeof o=="string").map(o=>o.trim()).filter(Boolean)),this.#n=n.registry??Jt()}get version(){return this.#o.length}events(){return Object.freeze([...this.#o])}*stream(t={}){let n=t.fromVersion??1,o=t.toVersion??this.version,r=t.batchSize??100;if(!Number.isInteger(n)||n<1)throw new TypeError("Relationship event stream fromVersion must be positive");if(!Number.isInteger(o)||o<0||o>this.version)throw new TypeError(`Relationship event stream toVersion out of range: ${o}`);if(!Number.isInteger(r)||r<1)throw new TypeError("Relationship event stream batchSize must be positive");if(n>o+1)throw new TypeError("Relationship event stream fromVersion exceeds the selected prefix");for(let i=n-1;i<o;i+=r)yield Object.freeze(this.#o.slice(i,Math.min(i+r,o)))}project(t,n,o={}){if(typeof n!="function")throw new TypeError("Relationship event projection requires a reducer");let r=t,i=0,a;for(let s of this.stream({...o,batchSize:256}))for(let c of s)r=n(r,c),i+=1,a=c;return Object.freeze({state:r,version:a?.sequence??Math.max(0,(o.fromVersion??1)-1),processed:i,...a===void 0?{}:{asOf:a.timestamp}})}#a(t,n){let o=this.#n.require(n.kind);this.#r.identities.set(ir(n,this.#n),t),o.outgoing==="one"&&this.#r.outgoingOne.set(`${o.kind}\0${n.source}`,t),o.incoming==="one"&&this.#r.incomingOne.set(`${o.kind}\0${n.target}`,t)}#s(t){let n=this.#n.require(t.kind);this.#r.identities.delete(ir(t,this.#n)),n.outgoing==="one"&&this.#r.outgoingOne.delete(`${n.kind}\0${t.source}`),n.incoming==="one"&&this.#r.incomingOne.delete(`${n.kind}\0${t.target}`)}append(t){let n=Ep(t,this.version,this.#i),o=this.#e.get(n.relationshipId),r=Tp(t,n.relationshipId,this.#e,this.#t,this.#n,this.#r),i=Object.freeze({eventId:n.eventId,relationshipId:n.relationshipId,action:t.action,...r===void 0?{}:{edge:r},author:n.author,timestamp:n.timestamp,...t.reason?.trim()?{reason:t.reason.trim()}:{},sequence:this.version+1});return this.#o.push(i),this.#i.add(n.eventId),o&&this.#s(o),t.action==="remove"?this.#e.delete(n.relationshipId):(this.#e.set(n.relationshipId,r),this.#a(n.relationshipId,r)),i}snapshot(t={}){if(t.atVersion!==void 0&&t.atTimestamp!==void 0)throw new TypeError("Relationship snapshot accepts one target");let n;if(t.atTimestamp!==void 0){let i=Date.parse(t.atTimestamp);if(!Number.isFinite(i))throw new TypeError("Relationship snapshot timestamp must be valid");n=this.#o.filter(a=>Date.parse(a.timestamp)<=i)}else{let i=t.atVersion??this.version;if(!Number.isInteger(i)||i<0||i>this.version)throw new TypeError(`Relationship snapshot version out of range: ${i}`);n=this.#o.slice(0,i)}let o=Ap(n),r=new Ve(this.#t,o.values(),this.#n);return Object.freeze({version:n.at(-1)?.sequence??0,...n.at(-1)?{asOf:n.at(-1).timestamp}:{},edges:r.edges(),graph:r})}page(t){if(!Number.isInteger(t.limit)||t.limit<1)throw new TypeError("Relationship event page limit must be positive");let n=Di("relationship-events",{order:"append-sequence"}),o=t.cursor===void 0?this.version:Number(Mi(t.cursor,n).snapshot);if(!Number.isSafeInteger(o)||o<0||o>this.version)throw new TypeError("Relationship event cursor snapshot version is invalid");let r=ji(this.#o.slice(0,o),{cursor:t.cursor,fingerprint:n,limit:t.limit,readId:i=>i.eventId,snapshot:String(o)});return{version:o,events:r.rows,hasMore:r.has_more,...r.next_cursor?{nextCursor:r.next_cursor}:{}}}},Cp="relationship-event-store",vl=jt.O_NOFOLLOW;function Pn(e){return ne(e,Cp,30,`relationship-store:${process.pid}`,!1,!1,3e3)}async function Ue(e,t="relationships/events.jsonl"){let n=me.resolve(e),o=me.resolve(n,t),r=me.relative(n,o);if(r.length===0)throw new TypeError("Relationship event path must name a file within the tracker root");if(r===".."||r.startsWith(`..${me.sep}`)||me.isAbsolute(r))throw new TypeError("Relationship event path must stay within the tracker root");if(await rr(n,{recursive:!0}),(await bl(n)).isSymbolicLink())throw new TypeError("Relationship event tracker root must not be a symbolic link");let i=n;for(let a of r.split(me.sep)){i=me.join(i,a);try{if((await bl(i)).isSymbolicLink())throw new TypeError("Relationship event path must not contain symbolic links")}catch(s){if(ro(s))break;throw s}}return o}async function Ln(e,t,n){let o=new Gt(t,{registry:n}),r,i;try{i=await wl(e,jt.O_RDONLY|vl),r=await i.readFile("utf8")}catch(s){if(ro(s))return{log:o,raw:""};throw s}finally{await i?.close()}let a=r.split(`
|
|
1
|
+
import{a as nt,b as Cn,c as yc,d as bc,g as wc,i as zc}from"./chunk-2UKKO45F.js";import{A as rl,P as er,Y as il,d as Eo,e as Hc,g as Wc,h as Vc,i as Bc,o as Kc,p as Mt,q as Ge,r as Zo,y as Qo}from"./chunk-66BZVFIK.js";import{$c as nl,Aa as pc,Ba as uc,Ca as In,Da as _c,Ea as An,Fa as En,Ga as fc,Gb as Dc,Ia as et,Id as tr,J as Le,Ja as hc,Jb as Mc,Ka as jo,Kb as jc,La as Tn,Ld as _l,Na as tt,Oc as Ho,Pb as Nt,Rc as Ie,Sc as Jc,Tc as Vo,Uc as Yc,Ud as fl,Vc as Xc,Vd as hl,Wa as gc,Wc as ot,Xc as Zc,_c as tl,ad as ol,b as No,bd as Jo,cd as Yo,dd as Xo,fc as On,ga as hn,gd as sl,ha as ac,hd as cl,i as Os,ia as Pt,id as ll,j as $s,ja as h,jd as dl,ka as sc,kd as ml,l as Fs,la as cc,mb as kc,mc as Uc,md as pl,na as Y,nb as Sc,nd as ul,oa as lc,oc as qc,pa as vn,qa as dc,ra as Do,sa as Lt,sb as Go,ta as kn,tb as Uo,ua as Me,ub as qo,va as mc,vc as Dt,wa as Sn,wb as Ic,xa as U,xb as Ac,ya as Mo,yb as zo,za as j}from"./chunk-PP3BVMFL.js";import{$a as wn,E as Ps,K as Ls,M as Ne,N as Ns,O as yn,P as Ds,Pa as Qe,Q as De,R as Ms,S as bn,T as js,Wa as oc,Z as Gs,aa as Us,c as fa,ca as qs,da as zs,db as rc,ea as Hs,fa as Ws,ga as Vs,gb as ic,ha as Bs,i as gn,ia as Ks,ja as Js,ka as Ys,la as Xs,ma as Zs,na as Qs,oa as ec,pa as tc,qa as nc}from"./chunk-LE4IEHDG.js";import{$a as Ec,Ab as Nc,Eb as Se,Fb as Gc,Gb as xn,Kb as Wo,Vc as Bo,Yb as Qc,Zb as el,_c as Ko,bd as al,d as ua,f as _a,jb as Tc,kb as Cc,lb as Rc,na as de,ob as xc,pb as Oc,qb as $c,rb as Fc,tb as je,ua as vc,ub as Pc,vb as Lc,yb as Rn}from"./chunk-UNQZGMJL.js";import{$ as oe,$c as Oi,$g as ta,$j as ka,$k as Ma,$l as is,$m as ws,A as _i,Ai as T,B as fi,Bd as Pi,Bi as sa,Bm as le,C as hi,Cd as Li,Cl as Xa,D as gi,Dl as ln,El as dn,Em as us,Ff as Vi,Fg as Fe,Fl as mn,Fm as _s,G as yi,Gd as H,Gl as pn,Hg as Ye,Hk as Ra,Hm as _n,If as Ke,Ij as ga,Il as re,Im as fs,Ja as co,Jk as xa,Ka as lo,Ki as To,Kj as ya,Kl as Za,Ko as Rs,La as mo,Li as Co,Lj as sn,Ll as Qa,Ma as po,Mf as Bi,Mg as on,Mj as ba,Ng as Tt,Og as ko,Ol as $t,Om as hs,Pk as Oa,Pl as es,Pm as gs,Qb as vi,Qk as $a,Ql as ts,R as u,Rb as ki,Ri as ca,Rk as Fa,Rl as ns,Sd as tn,Sj as wa,Sl as os,T as p,Th as Ct,Tm as xo,Tn as Po,Ub as Si,Ue as Gi,Uh as Rt,Ui as Ze,Uk as Pa,V as ye,Va as P,Vm as Oo,Vn as Lo,W as Be,Wa as Yt,Wf as Ki,Wj as va,Wo as xs,X as ro,Xc as Zt,Xf as F,Xl as Ro,Y as se,Yc as Qt,Yk as La,Yl as rs,Zc as en,Zd as Ni,Zk as Na,Zl as Pe,Zm as ys,_d as nn,_e as Ui,_g as ea,_k as Da,_m as bs,aa as kt,ah as na,ak as Sa,al as ja,am as as,an as vs,bb as A,be as Di,bf as qi,bn as ks,cj as la,ck as Ia,cl as Ga,cm as un,dl as Ua,dn as Ss,eb as we,ee as Mi,ej as da,el as qa,em as ss,en as Is,f as J,fb as uo,fd as _o,fj as ma,fk as Aa,fl as za,fm as cs,fn as As,gj as ce,gl as Ha,gm as ls,gn as Ft,h as oo,ha as bi,hb as xe,hd as fo,he as ji,hj as ve,hl as Wa,hn as Es,id as ho,in as fn,j as pi,ja as wi,jd as go,jg as Je,jn as Ts,ka as be,kd as yo,kf as S,kg as Oe,kj as xt,kl as Va,kn as $o,ld as bo,lg as Ji,ll as cn,ln as Fo,mc as Ii,md as wo,mg as Yi,ml as Ba,mn as Cs,na as io,nc as Ai,nd as vo,ng as $e,ni as oa,nj as an,nl as Ka,oc as Ei,od as $,of as zi,og as Xi,oi as Xe,p as Jt,pc as Ti,qa as ao,qc as Ci,qf as Hi,qh as So,qj as Ot,qm as ds,ra as St,rc as Ri,rf as ne,rg as V,rh as R,ri as rn,rj as pa,rl as ke,sc as xi,sl as E,ta as so,tb as It,td as $i,tg as Et,ti as ra,tl as Ja,u as Ve,ub as At,ud as Fi,ug as Zi,ui as ia,ul as Ya,um as ms,vi as aa,vk as Ea,w as ui,wb as Xt,xd as G,xf as Wi,xi as Io,yg as Qi,yi as Ao,yk as Ta,ym as ps,zj as ha,zk as Ca}from"./chunk-IDEHMKYZ.js";import{AsyncLocalStorage as Gg}from"node:async_hooks";import{readFile as hp}from"node:fs/promises";import gp 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]="20a3a324-d176-5918-8167-5e548be4abc9")}catch{}})();var nr="context-intents.json";function $n(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function yp(e,t,n){if(!$n(e))throw new TypeError(`${t} context intent at index ${String(n)} must be an object`);let o=e.included_field_groups;if(typeof e.command!="string"||typeof e.intent!="string"||typeof e.description!="string"||!Array.isArray(o)||!o.every(r=>typeof r=="string")||typeof e.token_budget!="number")throw new TypeError(`${t} context intent at index ${String(n)} has an invalid contract shape`);return{command:e.command,intent:e.intent,description:e.description,included_field_groups:o,token_budget:e.token_budget}}function gl(e,t){let n=Array.isArray(e)?e:$n(e)&&Array.isArray(e.intents)?e.intents:void 0;if(!n)throw new TypeError(`${t} context intents must be an array or an object with an intents array`);return n.map((o,r)=>yp(o,t,r))}async function bp(e){let t=gp.join(e,nr),n;try{n=await hp(t,"utf8")}catch(r){if(Be(r))return[];throw await Ki(e),r}let o;try{o=JSON.parse(n)}catch(r){let i=r instanceof Error?r.message:String(r);throw new TypeError(`Invalid ${nr}: ${i}`,{cause:r})}return gl(o,nr)}function wp(e){if(!$n(e))return;let t=e.contextIntents??e.context_intents;if(t!==void 0)return t;let n=e.default;return $n(n)?n.contextIntents??n.context_intents:void 0}function vp(e){return e.flatMap(t=>{let n=wp(t.module);return n===void 0?[]:gl(n,`package ${t.name}`)})}async function kp(e){let t=await bp(e.pmRoot),n=vp(e.packages??[]);return{workspaceContracts:t,packageContracts:n}}async function Fn(e,t){let n=await kp(e);return await Vi(n,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]="0a4abc17-0fcb-573f-8f89-6e505e112261")}catch{}})();async function yl(e,t,n=Wi){try{await n({pmRoot:e,result:t})}catch{if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let o=t,r=Array.isArray(o.warnings)?o.warnings.filter(i=>typeof i=="string"):[];o.warnings=[...new Set([...r,"context_usage_feedback_write_failed"])].sort()}}}import{createHash as xp}from"node:crypto";import{constants as jt}from"node:fs";import{lstat as bl,mkdir as rr,open as wl}from"node:fs/promises";import me 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]="5434ff6f-95af-5983-88cb-fd360d95cb9e")}catch{}})();function or(e,t){if(typeof e!="string"||e.trim().length===0)throw new TypeError(`Relationship event ${t} must be non-empty`);return e.trim()}function ir(e,t){let n=t.require(e.kind),o=n.direction==="undirected"?[e.source,e.target].sort().join("\0"):`${e.source}\0${e.target}`;return`${n.kind}\0${o}`}function Sp(e){return Object.freeze({...e,...e.payload===void 0?{}:{payload:Object.freeze(structuredClone(e.payload))}})}function Ip(e,t,n,o){let r=n.require(e.kind),i=o.outgoingOne.get(`${r.kind}\0${e.source}`);if(i!==void 0&&i!==t)throw new TypeError(`Relationship outgoing cardinality exceeded for ${r.kind}`);let a=o.incomingOne.get(`${r.kind}\0${e.target}`);if(a!==void 0&&a!==t)throw new TypeError(`Relationship incoming cardinality exceeded for ${r.kind}`);let s=ir(e,n),c=o.identities.get(s);if(c!==void 0&&c!==t)throw new TypeError(`Relationship edge already active: ${s}`)}function Ap(e){let t=new Map;for(let n of e)n.action==="remove"?t.delete(n.relationshipId):t.set(n.relationshipId,n.edge);return t}function Ep(e,t,n){if(e.expectedVersion!==void 0&&e.expectedVersion!==t)throw new TypeError(`Relationship event version conflict: expected ${e.expectedVersion}, current ${t}`);let o=or(e.eventId,"eventId");if(n.has(o))throw new TypeError(`Relationship event already exists: ${o}`);if(e.action!=="add"&&e.action!=="remove"&&e.action!=="supersede")throw new TypeError(`Unknown relationship event action: ${e.action}`);if(!Number.isFinite(Date.parse(e.timestamp)))throw new TypeError("Relationship event timestamp must be valid");return{eventId:o,relationshipId:or(e.relationshipId,"relationshipId"),author:or(e.author,"author"),timestamp:new Date(e.timestamp).toISOString()}}function Tp(e,t,n,o,r,i){let a=n.has(t);if(e.action==="add"&&a)throw new TypeError(`Relationship is already active: ${t}`);if(e.action!=="add"&&!a)throw new TypeError(`Relationship is not active: ${t}`);if(e.action==="remove")return;if(!e.edge)throw new TypeError(`Relationship ${e.action} event requires an edge`);let s=typeof e.edge.source=="string"?e.edge.source.trim():"",c=typeof e.edge.target=="string"?e.edge.target.trim():"";if(!o.has(s)||!o.has(c))throw new TypeError(`Relationship endpoint not found: ${s} -> ${c}`);let l=new Ve([s,c],[e.edge],r).edges()[0];return Ip(l,t,r,i),Sp(l)}var Gt=class{#t;#n;#o=[];#i=new Set;#e=new Map;#r={identities:new Map,outgoingOne:new Map,incomingOne:new Map};constructor(t,n={}){this.#t=new Set([...t].filter(o=>typeof o=="string").map(o=>o.trim()).filter(Boolean)),this.#n=n.registry??Jt()}get version(){return this.#o.length}events(){return Object.freeze([...this.#o])}*stream(t={}){let n=t.fromVersion??1,o=t.toVersion??this.version,r=t.batchSize??100;if(!Number.isInteger(n)||n<1)throw new TypeError("Relationship event stream fromVersion must be positive");if(!Number.isInteger(o)||o<0||o>this.version)throw new TypeError(`Relationship event stream toVersion out of range: ${o}`);if(!Number.isInteger(r)||r<1)throw new TypeError("Relationship event stream batchSize must be positive");if(n>o+1)throw new TypeError("Relationship event stream fromVersion exceeds the selected prefix");for(let i=n-1;i<o;i+=r)yield Object.freeze(this.#o.slice(i,Math.min(i+r,o)))}project(t,n,o={}){if(typeof n!="function")throw new TypeError("Relationship event projection requires a reducer");let r=t,i=0,a;for(let s of this.stream({...o,batchSize:256}))for(let c of s)r=n(r,c),i+=1,a=c;return Object.freeze({state:r,version:a?.sequence??Math.max(0,(o.fromVersion??1)-1),processed:i,...a===void 0?{}:{asOf:a.timestamp}})}#a(t,n){let o=this.#n.require(n.kind);this.#r.identities.set(ir(n,this.#n),t),o.outgoing==="one"&&this.#r.outgoingOne.set(`${o.kind}\0${n.source}`,t),o.incoming==="one"&&this.#r.incomingOne.set(`${o.kind}\0${n.target}`,t)}#s(t){let n=this.#n.require(t.kind);this.#r.identities.delete(ir(t,this.#n)),n.outgoing==="one"&&this.#r.outgoingOne.delete(`${n.kind}\0${t.source}`),n.incoming==="one"&&this.#r.incomingOne.delete(`${n.kind}\0${t.target}`)}append(t){let n=Ep(t,this.version,this.#i),o=this.#e.get(n.relationshipId),r=Tp(t,n.relationshipId,this.#e,this.#t,this.#n,this.#r),i=Object.freeze({eventId:n.eventId,relationshipId:n.relationshipId,action:t.action,...r===void 0?{}:{edge:r},author:n.author,timestamp:n.timestamp,...t.reason?.trim()?{reason:t.reason.trim()}:{},sequence:this.version+1});return this.#o.push(i),this.#i.add(n.eventId),o&&this.#s(o),t.action==="remove"?this.#e.delete(n.relationshipId):(this.#e.set(n.relationshipId,r),this.#a(n.relationshipId,r)),i}snapshot(t={}){if(t.atVersion!==void 0&&t.atTimestamp!==void 0)throw new TypeError("Relationship snapshot accepts one target");let n;if(t.atTimestamp!==void 0){let i=Date.parse(t.atTimestamp);if(!Number.isFinite(i))throw new TypeError("Relationship snapshot timestamp must be valid");n=this.#o.filter(a=>Date.parse(a.timestamp)<=i)}else{let i=t.atVersion??this.version;if(!Number.isInteger(i)||i<0||i>this.version)throw new TypeError(`Relationship snapshot version out of range: ${i}`);n=this.#o.slice(0,i)}let o=Ap(n),r=new Ve(this.#t,o.values(),this.#n);return Object.freeze({version:n.at(-1)?.sequence??0,...n.at(-1)?{asOf:n.at(-1).timestamp}:{},edges:r.edges(),graph:r})}page(t){if(!Number.isInteger(t.limit)||t.limit<1)throw new TypeError("Relationship event page limit must be positive");let n=Di("relationship-events",{order:"append-sequence"}),o=t.cursor===void 0?this.version:Number(Mi(t.cursor,n).snapshot);if(!Number.isSafeInteger(o)||o<0||o>this.version)throw new TypeError("Relationship event cursor snapshot version is invalid");let r=ji(this.#o.slice(0,o),{cursor:t.cursor,fingerprint:n,limit:t.limit,readId:i=>i.eventId,snapshot:String(o)});return{version:o,events:r.rows,hasMore:r.has_more,...r.next_cursor?{nextCursor:r.next_cursor}:{}}}},Cp="relationship-event-store",vl=jt.O_NOFOLLOW;function Pn(e){return ne(e,Cp,30,`relationship-store:${process.pid}`,!1,!1,3e3)}async function Ue(e,t="relationships/events.jsonl"){let n=me.resolve(e),o=me.resolve(n,t),r=me.relative(n,o);if(r.length===0)throw new TypeError("Relationship event path must name a file within the tracker root");if(r===".."||r.startsWith(`..${me.sep}`)||me.isAbsolute(r))throw new TypeError("Relationship event path must stay within the tracker root");if(await rr(n,{recursive:!0}),(await bl(n)).isSymbolicLink())throw new TypeError("Relationship event tracker root must not be a symbolic link");let i=n;for(let a of r.split(me.sep)){i=me.join(i,a);try{if((await bl(i)).isSymbolicLink())throw new TypeError("Relationship event path must not contain symbolic links")}catch(s){if(ro(s))break;throw s}}return o}async function Ln(e,t,n){let o=new Gt(t,{registry:n}),r,i;try{i=await wl(e,jt.O_RDONLY|vl),r=await i.readFile("utf8")}catch(s){if(ro(s))return{log:o,raw:""};throw s}finally{await i?.close()}let a=r.split(`
|
|
2
2
|
`);for(let s=0;s<a.length;s+=1){let c=a[s].trim();if(!c)continue;let l;try{l=JSON.parse(c)}catch{throw new TypeError(`Invalid relationship event JSONL at line ${s+1}`)}if(l.sequence!==o.version+1)throw new TypeError(`Invalid relationship event sequence at line ${s+1}`);o.append({eventId:l.eventId,relationshipId:l.relationshipId,action:l.action,...l.edge===void 0?{}:{edge:l.edge},author:l.author,timestamp:l.timestamp,...l.reason===void 0?{}:{reason:l.reason},expectedVersion:o.version})}return{log:o,raw:r}}function Rp(e,t,n,o){let r=Date.parse(t.timestamp),i;return t.action!=="remove"&&t.edge!==void 0&&(i=new Ve(n,[t.edge],o).edges()[0]),e.eventId===t.eventId.trim()&&e.relationshipId===t.relationshipId.trim()&&e.action===t.action&&e.author===t.author.trim()&&Number.isFinite(r)&&e.timestamp===new Date(r).toISOString()&&e.reason===(t.reason?.trim()||void 0)&&It(e.edge)===It(i)}var Nn=class e{#t;#n;#o;#i;#e;constructor(t,n,o,r){this.#t=t.pmRoot,this.#n=n,this.#o=t.registry,this.#i=o,this.#e=r}static async open(t){let n=Object.freeze([...t.nodes]),o=await Ue(t.pmRoot,t.relativePath),r=await Pn(t.pmRoot);try{await Ue(t.pmRoot,o);let{log:i}=await Ln(o,n,t.registry);return new e(t,n,o,i)}finally{await r()}}get path(){return this.#i}async currentVersion(){return this.#e=await this.#r(),this.#e.version}async append(t){let n=await Pn(this.#t);try{let o=await Ue(this.#t,this.#i),{log:r}=await Ln(o,this.#n,this.#o),i=r.append(t);await rr(me.dirname(o),{recursive:!0}),await Ue(this.#t,o);let a=await wl(o,jt.O_APPEND|jt.O_CREAT|jt.O_WRONLY|vl);try{await a.appendFile(`${JSON.stringify(i)}
|
|
3
3
|
`,"utf8")}finally{await a.close()}return this.#e=r,i}finally{await n()}}async appendBatch(t,n={}){let o=await Pn(this.#t);try{let r=await Ue(this.#t,this.#i),{log:i,raw:a}=await Ln(r,this.#n,this.#o),s=i.version,c=new Map(i.events().map(d=>[d.eventId,d])),l=[],m=[];for(let d of t){let _=d.eventId.trim(),f=c.get(_);if(f!==void 0){if(n.existingEventPolicy==="skip_identical"&&Rp(f,d,this.#n,this.#o)){m.push(f.eventId);continue}if(n.existingEventPolicy==="skip_identical")throw new TypeError(`Relationship event id collision with different content: ${_}`)}let w=i.append(d);c.set(w.eventId,w),l.push(w)}if(l.length>0){let d=a.length===0||a.endsWith(`
|
|
4
4
|
`)?a:`${a}
|
|
@@ -2245,4 +2245,4 @@ compdef _pm pm`}(function(){try{var e=typeof window<"u"?window:typeof global<"u"
|
|
|
2245
2245
|
`);M(e.progressEnabled,"writing keyword artifacts"),await oe(t,`${JSON.stringify(e.manifest,null,2)}
|
|
2246
2246
|
`),await oe(n,`${r}
|
|
2247
2247
|
`);let i=[];if(e.mode!=="keyword")try{M(e.progressEnabled,"writing vectorization status ledger"),await Cs(e.pmRoot,e.vectorizationLedgerEntries,e.vectorizationEmbeddingMetadata)}catch(a){i.push(`search_vectorization_status_ledger_write_failed:${a instanceof Error?a.message:String(a)}`)}return i}async function jg(e,t){let n=yg(e.mode),o=gg(e),r=e.full===!0;M(o,`start mode=${n}`);let i=A(process.cwd(),t.path);await F(i);let a=hs(await T(i)).settings,s=null;try{s=await ne(i,gs,a.locks.ttl_seconds,R(void 0,"pm-reindex"),!1,a.governance.force_required_for_stale_lock,a.locks.wait_ms)}catch(c){throw c instanceof p&&c.exitCode===u.CONFLICT?new p("Another pm reindex run is already active for this project. Wait for it to finish before starting a new keyword, semantic, or hybrid reindex.",u.CONFLICT,{code:"reindex_already_running",type:"urn:pm-cli:error:reindex_already_running",why:"Semantic reindex can be expensive and duplicate runs compete for the same local embedding model and vector store.",nextSteps:["Check active pm reindex processes before starting another reindex.","Rerun with --progress when you need non-interactive visibility."]}):c}try{let c=vg(a),l=kg(a),m=Cg({requestedMode:n,pmRoot:i,settings:a,extensionEmbedding:c,extensionVectorAdapter:l}),d=n;M(o,"loading item corpus");let _=await Rg({pmRoot:i,settings:a}),f=_.warnings,{documentCandidates:w,metadataDocuments:k}=_;M(o,`loaded_items=${k.length}`);let y=S(),v=Tg(d,y,k),g=Kt.join(i,ri),I=Kt.join(i,ii),x=d==="keyword"?await si(i,w,a.schema,f):k,N=[],W={},O=null,C=Eg(d);if(d==="keyword"&&await xg({pmRoot:i,settings:a,forceFullSemantic:r,extensionEmbedding:c,reindexWarnings:f}),d!=="keyword"){let te=await Dg({pmRoot:i,settings:a,requestedMode:n,activeEmbeddingProvider:m.activeEmbeddingProvider,activeVectorStore:m.activeVectorStore,extensionEmbedding:c,extensionVectorAdapter:l,documentCandidates:w,metadataDocuments:k,documentsForKeywordArtifacts:x,forceFullSemantic:r,reindexWarnings:f,semanticWarnings:N,semanticSummary:C,progressEnabled:o});x=te.documentsForKeywordArtifacts,W=te.vectorizationLedgerEntries,O=te.vectorizationEmbeddingMetadata}let ae=await Mg({pmRoot:i,mode:d,manifest:v,documentsForKeywordArtifacts:x,settings:a,vectorizationLedgerEntries:W,vectorizationEmbeddingMetadata:O,progressEnabled:o}),Re=[...await G({path:g,scope:"project",op:"reindex:manifest"}),...await G({path:I,scope:"project",op:"reindex:embeddings"}),...await Pi({mode:d,total_items:k.length})];return M(o,"done"),{ok:!0,mode:d,total_items:k.length,semantic:C,artifacts:{manifest:ri,embeddings:ii},warnings:[...f,...N,...ae,...Re],generated_at:y}}finally{await s?.()}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="710f1406-c114-56c7-9f0b-4f7c20b1eea1")}catch{}})();var pp=Symbol("pm.active-extension-host-context");function Q(e){return{fullChangedFields:!0,options:e}}var b=class e{defaults;constructor(t={}){this.defaults={...t.pmRoot===void 0?{}:{path:t.pmRoot},...t.cwd===void 0?{}:{cwd:t.cwd},...t.author===void 0?{}:{author:t.author},...t.noExtensions===void 0?{}:{noExtensions:t.noExtensions}}}static forActiveExtensionHost(t){let n=new e({...t,noExtensions:!0});return n.defaults[pp]=!0,n}run(t,n={}){return Hg({...this.defaults,...n,action:t})}runTyped(t,n={}){return this.run(t,n)}context(t={}){return this.runTyped("context",{options:t})}listAllItemMetadataLight(){return Il(this.defaults.path,this.defaults.cwd)}list(t={}){return this.runTyped("list",{options:t})}async listAllComplete(t={}){return Mn(await this.list(sr(t)))}search(t,n={}){return this.runTyped("search",{query:t,options:n})}get(t,n={}){return this.runTyped("get",{id:t,options:n})}next(t={}){return this.runTyped("next",{options:t})}aggregate(t={}){return this.runTyped("aggregate",{options:t})}stats(t={}){return this.runTyped("stats",{options:t})}duplicates(t={}){return this.runTyped("duplicates",{options:t})}comments(t,n={}){return this.runTyped("comments",{id:t,options:n})}notes(t,n={}){return this.runTyped("notes",{id:t,options:n})}learnings(t,n={}){return this.runTyped("learnings",{id:t,options:n})}files(t,n={}){return this.runTyped("files",{id:t,options:n})}filesDiscover(t,n={}){return this.runTyped("files-discover",{id:t,options:n})}filesLookup(t){return this.runTyped("files-lookup",{options:t})}docs(t,n={}){return this.runTyped("docs",{id:t,options:n})}deps(t,n={}){return this.runTyped("deps",{id:t,options:n})}graph(t,n={},o={}){return this.runTyped("graph",{subcommand:t,...n,options:o})}append(t,n,o={}){return this.runTyped("append",{id:t,...Q(Pt(o,{body:n}))})}init(t,n={}){return this.runTyped("init",{...t===void 0?{}:{prefix:t},options:n})}config(t,n,o,r,i={}){return this.runTyped("config",{scope:t,configAction:n,...o===void 0?{}:{key:o},...r===void 0?{}:{value:r},options:i})}schema(t,n={}){return this.runTyped("schema",{options:{...n,subcommand:t}})}workflowPolicy(t,n,o={}){return this.runTyped("schema",{name:n,options:{...o,subcommand:t}})}schemaList(){return this.runTyped("schema",{options:{subcommand:"list"}})}schemaShow(t){return this.runTyped("schema",{name:t,options:{subcommand:"show"}})}schemaAddType(t,n={}){return this.runTyped("schema",{name:t,options:{...n,subcommand:"add-type"}})}schemaRemoveType(t,n={}){return this.runTyped("schema",{name:t,options:{...n,subcommand:"remove-type"}})}schemaAddStatus(t,n={}){return this.runTyped("schema",{name:t,options:{...n,subcommand:"add-status"}})}schemaRemoveStatus(t,n={}){return this.runTyped("schema",{name:t,options:{...n,subcommand:"remove-status"}})}schemaAddField(t,n={}){let{type:o,...r}=n;return this.runTyped("schema",{name:t,options:{...r,fieldType:o,subcommand:"add-field"}})}schemaRemoveField(t,n={}){return this.runTyped("schema",{name:t,options:{...n,subcommand:"remove-field"}})}schemaListFields(){return this.runTyped("schema",{options:{subcommand:"list-fields"}})}schemaShowField(t){return this.runTyped("schema",{name:t,options:{subcommand:"show-field"}})}schemaApplyPreset(t,n={}){return this.runTyped("schema",{typePreset:t,options:{...n,subcommand:"apply-preset"}})}schemaInferTypes(t={}){return this.runTyped("schema",{options:{...t,subcommand:"add-type",infer:!0}})}schemaRenameType(t,n,o){return this.runTyped("schema",{name:t,options:{...o,subcommand:"rename-type",to:n}})}schemaRenameField(t,n,o,r){return this.runTyped("schema",{name:t,options:{...o,subcommand:"rename-field",to:n,...r?{fieldTypeScope:r}:{}}})}schemaRemapStatus(t,n,o){return this.runTyped("schema",{name:t,options:{...o,subcommand:"remap-status",to:n}})}schemaShowStatus(t){return this.runTyped("schema",{name:t,options:{subcommand:"show-status"}})}profile(t,n={}){return this.runTyped("profile",{options:{...n,subcommand:t}})}profileList(){return this.runTyped("profile",{options:{subcommand:"list"}})}profileShow(t){return this.runTyped("profile",{name:t,options:{subcommand:"show"}})}profileApply(t,n={}){return this.runTyped("profile",{name:t,options:{...n,subcommand:"apply"}})}profileLint(t){return this.runTyped("profile",{name:t,options:{subcommand:"lint"}})}validate(t={}){return this.runTyped("validate",{options:t})}health(t={}){return this.runTyped("health",{options:t})}gc(t={}){return this.runTyped("gc",{options:t})}assurance(t){return this.runTyped("assurance",{options:{...t,subcommand:t.action}})}historyRedact(t,n){return this.runTyped("history-redact",{id:t,options:n})}historyRepair(t,n={}){return this.runTyped("history-repair",{id:t,options:n})}historyRepairAll(t={}){return this.runTyped("history-repair",{options:{...t,all:!0}})}historyAttest(t={}){return this.runTyped("history-attest",{options:t})}historyCompact(t,n={}){return this.runTyped("history-compact",{id:t,options:n})}historyCompactBulk(t){return this.runTyped("history-compact",{options:t})}historyAuthorAcknowledge(t){return this.runTyped("history-author-acknowledge",{historyEvent:(t.events??[]).map(n=>`${n.item_id}:${String(n.line)}`),allActionable:t.all_actionable===!0,dryRun:t.dry_run===!0,planFingerprint:t.plan_fingerprint,limit:t.coordinate_limit,attributedAuthor:t.attributed_author,reviewer:t.reviewer,reason:t.reason})}plan(t,n,o={},r,i){return this.runTyped("plan",{fullChangedFields:!0,...n===void 0?{}:{id:n},...r===void 0?{}:{stepRef:r},...i===void 0?{}:{reorderTo:i},options:Pt(o,{subcommand:t})})}planCreate(t){return this.plan("create",void 0,t)}planShow(t,n={}){return this.plan("show",t,n)}planAddStep(t,n){return this.plan("add-step",t,n)}planUpdateStep(t,n,o){return this.plan("update-step",t,o,n)}planCompleteStep(t,n,o={}){return this.plan("complete-step",t,o,n)}planBlockStep(t,n,o){return this.plan("block-step",t,o,n)}planReorderStep(t,n,o,r={}){return this.plan("reorder-step",t,r,n,o)}planRemoveStep(t,n,o={}){return this.plan("remove-step",t,o,n)}planLink(t,n,o){return this.plan("link",t,o,n)}planUnlink(t,n,o){return this.plan("unlink",t,o,n)}planDecision(t,n){return this.plan("decision",t,n)}planDiscovery(t,n){return this.plan("discovery",t,n)}planValidation(t,n){return this.plan("validation",t,n)}planResume(t,n){return this.plan("resume",t,n)}planApprove(t,n={}){return this.plan("approve",t,n)}planMaterialize(t,n){return this.plan("materialize",t,n)}create(t={}){return this.runTyped("create",Q(t))}update(t,n={}){return this.runTyped("update",{id:t,...Q(n)})}reopen(t,n,o={}){return this.runTyped("item-reopen",{id:t,reason:n,fullChangedFields:!0,options:o})}close(t,n,o={}){return this.runTyped("close",{id:t,reason:n,...Q(o)})}claim(t,n={}){return this.runTyped("claim",{id:t,...Q(n)})}claimNext(t={}){return this.runTyped("claim",{next:!0,...Q(t)})}release(t,n={}){return this.runTyped("release",{id:t,...Q(n)})}copy(t,n={}){return this.runTyped("copy",{id:t,...Q(n)})}delete(t,n={}){return this.runTyped("delete",{id:t,...Q(n)})}restore(t,n,o={}){return this.runTyped("restore",{fullChangedFields:!0,id:t,options:{...o,target:n}})}focus(t,n={}){return this.runTyped("focus",{...t===void 0?{}:{id:t},...Q(n)})}startTask(t,n={}){return this.runTyped("start-task",{id:t,...Q(n)})}pauseTask(t,n={}){return this.runTyped("pause-task",{id:t,...Q(n)})}closeTask(t,n,o={}){return this.runTyped("close-task",{id:t,reason:n,...Q(o)})}extension(t,n={}){return this.runTyped("extension",{...t===void 0?{}:{target:t},options:n})}extensionList(t={}){return this.extension("list",t)}extensionActivate(t,n={}){return this.runTyped("extension-activate",{target:t,options:n})}extensionDeactivate(t,n={}){return this.runTyped("extension-deactivate",{target:t,options:n})}package(t,n={}){return this.runTyped("package",{...t===void 0?{}:{target:t},options:{...n,vocabulary:"package"}})}packageList(t={}){return this.package("list",t)}packageInstall(t,n={}){return this.runTyped("package-install",{target:t,options:n})}packageUninstall(t,n={}){return this.runTyped("package-uninstall",{target:t,options:n})}packageDoctor(t={}){return this.runTyped("package-doctor",{options:t})}packageManage(t,n={}){return this.runTyped("package-manage",{...t===void 0?{}:{target:t},options:n})}packageDescribe(t,n={}){return this.runTyped("package-describe",{...t===void 0?{}:{target:t},options:n})}packageReload(t={}){return this.runTyped("package-reload",{options:t})}packageCatalog(t={}){return this.runTyped("package-catalog",{options:t})}packageActivate(t,n={}){return this.runTyped("package-activate",{target:t,options:n})}packageDeactivate(t,n={}){return this.runTyped("package-deactivate",{target:t,options:n})}packageMigrate(t={}){return this.package(void 0,{...t,migrate:!0})}upgrade(t,n={}){return this.runTyped("upgrade",{...t===void 0?{}:{target:t},options:n})}};function RT(e={},t={}){return new b(t).context(e)}function xT(e={},t={}){return new b(t).list(e)}function OT(e={},t={}){return new b(t).listAllComplete(e)}function $T(e,t={},n={}){return new b(n).search(e,t)}function FT(e,t={},n={}){return new b(n).get(e,t)}function PT(e={},t={}){return new b(t).next(e)}function LT(e={},t={}){return new b(t).aggregate(e)}function NT(e={},t={}){return new b(t).stats(e)}function DT(e={},t={}){return new b(t).duplicates(e)}function MT(e,t={},n={}){return new b(n).comments(e,t)}function jT(e,t={},n={}){return new b(n).notes(e,t)}function GT(e,t={},n={}){return new b(n).learnings(e,t)}function UT(e,t={},n={}){return new b(n).files(e,t)}function qT(e,t={},n={}){return new b(n).filesDiscover(e,t)}function zT(e,t={}){return new b(t).filesLookup(e)}function HT(e,t={},n={}){return new b(n).docs(e,t)}function WT(e,t={},n={}){return new b(n).deps(e,t)}function VT(e,t={},n={},o={}){return new b(o).graph(e,t,n)}function BT(e,t,n={},o={}){return new b(o).append(e,t,n)}function KT(e,t={},n={}){return new b(n).init(e,t)}function JT(e,t,n,o,r={},i={}){return new b(i).config(e,t,n,o,r)}function YT(e,t={},n={}){return new b(n).schema(e,t)}function XT(e={}){return new b(e).schemaList()}function ZT(e,t={}){return new b(t).schemaShow(e)}function QT(e,t={},n={}){return new b(n).schemaAddType(e,t)}function eC(e,t={},n={}){return new b(n).schemaRemoveType(e,t)}function tC(e,t={},n={}){return new b(n).schemaAddStatus(e,t)}function nC(e,t={},n={}){return new b(n).schemaRemoveStatus(e,t)}function oC(e,t={},n={}){return new b(n).schemaAddField(e,t)}function rC(e,t={},n={}){return new b(n).schemaRemoveField(e,t)}function iC(e={}){return new b(e).schemaListFields()}function aC(e,t={}){return new b(t).schemaShowField(e)}function sC(e,t={},n={}){return new b(n).schemaApplyPreset(e,t)}function cC(e={},t={}){return new b(t).schemaInferTypes(e)}function lC(e,t,n,o={}){return new b(o).schemaRenameType(e,t,n)}function dC(e,t,n,o,r={}){return new b(r).schemaRenameField(e,t,n,o)}function mC(e,t,n,o={}){return new b(o).schemaRemapStatus(e,t,n)}function pC(e,t={}){return new b(t).schemaShowStatus(e)}function uC(e,t={},n={}){return new b(n).profile(e,t)}function _C(e={}){return new b(e).profileList()}function fC(e,t={}){return new b(t).profileShow(e)}function hC(e,t={},n={}){return new b(n).profileApply(e,t)}function gC(e,t={}){return new b(t).profileLint(e)}function yC(e={},t={}){return new b(t).validate(e)}function bC(e={},t={}){return new b(t).health(e)}function wC(e={},t={}){return new b(t).gc(e)}function vC(e,t,n={}){return new b(n).historyRedact(e,t)}function kC(e,t={},n={}){return new b(n).historyRepair(e,t)}function SC(e={},t={}){return new b(t).historyRepairAll(e)}function IC(e,t={},n={}){return new b(n).historyCompact(e,t)}function AC(e,t={}){return new b(t).historyCompactBulk(e)}function EC(e={},t={}){return new b(t).create(e)}function TC(e,t={},n={}){return new b(n).update(e,t)}function CC(e,t,n={},o={}){return new b(o).reopen(e,t,n)}function RC(e,t,n={},o={}){return new b(o).close(e,t,n)}function xC(e,t={},n={}){return new b(n).claim(e,t)}function OC(e={},t={}){return new b(t).claimNext(e)}function $C(e,t={},n={}){return new b(n).release(e,t)}function FC(e,t={},n={}){return new b(n).copy(e,t)}function PC(e,t={},n={}){return new b(n).delete(e,t)}function LC(e,t,n={},o={}){return new b(o).restore(e,t,n)}function NC(e,t={},n={}){return new b(n).focus(e,t)}function DC(e,t={},n={}){return new b(n).startTask(e,t)}function MC(e,t={},n={}){return new b(n).pauseTask(e,t)}function jC(e,t,n={},o={}){return new b(o).closeTask(e,t,n)}function GC(e,t={},n={}){return new b(n).extension(e,t)}function UC(e={},t={}){return new b(t).extensionList(e)}function qC(e,t={},n={}){return new b(n).extensionActivate(e,t)}function zC(e,t={},n={}){return new b(n).extensionDeactivate(e,t)}function HC(e,t={},n={}){return new b(n).package(e,t)}function WC(e={},t={}){return new b(t).packageList(e)}function VC(e,t={},n={}){return new b(n).packageInstall(e,t)}function BC(e,t={},n={}){return new b(n).packageUninstall(e,t)}function KC(e={},t={}){return new b(t).packageDoctor(e)}function JC(e,t={},n={}){return new b(n).packageManage(e,t)}function YC(e,t={},n={}){return new b(n).packageDescribe(e,t)}function XC(e={},t={}){return new b(t).packageReload(e)}function ZC(e={},t={}){return new b(t).packageCatalog(e)}function QC(e,t={},n={}){return new b(n).packageActivate(e,t)}function eR(e,t={},n={}){return new b(n).packageDeactivate(e,t)}function tR(e,t={},n={}){return new b(n).upgrade(e,t)}async function nR(e,t={}){let n=typeof e=="string"?{...t,pmRoot:e}:e??t,o={json:!0,quiet:n.quiet??!0,noExtensions:n.noExtensions??!1,noPager:!0,profile:n.profile??!1,path:n.pmRoot};return hn(n,o)}var dp=Oi(),li=new Gg;function no(){fo(Ii()),ho(Ai()),go(Ei()),yo(Ti()),bo(Ci()),wo(Ri()),vo(xi())}async function up(e,t,n,o){return _o(()=>t===void 0?dp.read(()=>mp(e,n,o)):dp.write(()=>qg(t,()=>mp(e,n,o))))}async function oR(e,t){let n=e.cwd;if(li.getStore()===!0&&n===void 0&&e.noExtensions===!0){let r=A(process.cwd(),e.path);return _o(()=>Fn({pmRoot:r},t))}let o=n??process.cwd();return up(vn({path:e.path,noExtensions:e.noExtensions}),n,o,()=>li.run(!0,t))}async function mp(e,t,n){let o=A(t,e.path);if(e.noExtensions)return no(),Fn({pmRoot:o},()=>n(null));if(!await ye(we(o)))return no(),n(null);let r=null,i;try{let a=await T(o),s=await Zt({pmRoot:o,settings:a,cwd:t,noExtensions:!1}),c=await en({...s,loaded:s.loaded});i={loadResult:s,activationResult:c},fo(c.hooks),ho(c.commands),go(c.parsers),yo(c.preflight),bo(c.services),wo(c.renderers),vo(c.registrations),r={registrations:c.registrations,commands:c.commands,pmRoot:o,packages:s.loaded}}catch(a){no(),console.error("[pm-sdk] extension activation failed; continuing without active extensions:",a)}try{return await Fn({pmRoot:o,packages:r?.packages},()=>n(r))}finally{no(),i&&await Qt(i.loadResult,i.activationResult).catch(()=>{})}}function _p(e,t){let n=Me(e);return t?.registrations.commands.find(o=>Me(o.action)===n)?.command??t?.commands.handlers.find(o=>Me(o.command)===n)?.command}async function Ug(e,t,n,o,r){if(!r)throw new p(`Unsupported native pm action: ${e}`,u.USAGE);let i=_p(e,r);if(!i)throw new p(`Unsupported native pm action: ${e}`,u.USAGE);let a=typeof o.author=="string"&&o.author.trim()?o.author.trim():"pm-extension",s=await Li({command:Sn(i),args:U(n.args??t.args),options:Mo(t,n),global:o,pm_root:r.pmRoot,sdk:kl(r.pmRoot,b.forActiveExtensionHost({pmRoot:r.pmRoot,author:a}),a,Sn(i))});if(!s.handled){let c=s.warnings.length>0?` (${s.warnings.join(", ")})`:"";throw new p(`Unsupported native pm action: ${e}${c}`,u.USAGE)}return s.result}async function qg(e,t){let n=process.cwd();process.chdir(e);try{return await t()}finally{process.chdir(n)}}function zg(e){let t=K(e,"action"),n=Me(t),o=fe(cr,n),r=o?.action??n,i={...e,action:r};return o?.options!==void 0&&(i.options={...o.options,...ao(e.options)}),r==="package"&&(i.options={...ao(i.options),vocabulary:"package"}),{action:r,args:i}}async function Hg(e){let t=zg(e),n=vn(t.args),o=mc(t.action),r=h(t.args,"cwd"),i=r??process.cwd();t.action==="init"&&(n[rc]=i),(t.action!=="init"||n.path!==void 0||(process.env.PM_PATH?.trim().length??0)>0)&&(n.path=A(i,n.path));try{return t.action==="history-attest"?await ci(t.action,t.args,n,null):e[pp]===!0||li.getStore()===!0?await ci(t.action,t.args,n,null):await up(n,r,i,a=>ci(t.action,t.args,n,a))}finally{o&&Wr()}}function rR(e=Si){return e.map(t=>{let n=Me(t),o=fe(cr,n),r=o?.action??n,i=fe(Hr,r)!==void 0;return{action:t,resolved_action:r,covered:i,route:i?o?"alias":"native":"missing"}})}async function ci(e,t,n,o){let r=Do(t,e),i=fe(Hr,e),a=i?void 0:_p(e,o),s=a===void 0?e:`extension:${a}`;Ui(s,r),qi(s,r);let c={action:e,args:t,options:r,id:h(t,"id"),force:t.force===!0||r.force===!0,global:n,activeExtensions:o},l=i?await i(c):await Ug(e,t,r,n,o);if(e==="history-attest")return l;{r.resolvedOutputFormat="json";let m=Bi(s,r,l);return await yl(A(process.cwd(),n.path),m),m}}var Wg={closeManyOptionsFromFlat:In,extensionOptionsFromArgs:Mo,globalOptions:vn,mutationListOptions:pc,normalizeActionName:Me,normalizeCommandPath:Sn,normalizeMcpUpdateOptions:_c,normalizeMcpOptionsArrays:dc,optionsWithAuthor:Do,readRequiredString:K,readScalarString:sc,readScalarStringAllowBlank:cc,readStringArray:U,updateManyOptionsFromFlat:An,withAddNoteOption:Lt,withFilesDiscoveryOptions:kn,withMutationCompaction:j};(process.env.NODE_ENV==="test"||process.env.VITEST!==void 0||process.env.VITEST_WORKER_ID!==void 0)&&(globalThis.__pmCliActionRunnerTestHooks=Wg);export{nr as a,gl as b,bp as c,vp as d,kp as e,Fn as f,Gt as g,Nn as h,kl as i,$p as j,Dn as k,sr as l,Sl as m,Mn as n,jp as o,Tl as p,xl as q,$l as r,Nl as s,pr as t,ur as u,_r as v,fr as w,uu as x,ql as y,vr as z,ed as A,id as B,ad as C,at as D,$r as E,H_ as F,lw as G,dw as H,Lr as I,cd as J,Ew as K,Tw as L,dd as M,ud as N,Vw as O,cf as P,qr as Q,df as R,mf as S,Ed as T,Td as U,Cd as V,Rd as W,xd as X,gv as Y,yv as Z,bv as _,wv as $,Od as aa,$d as ba,Ld as ca,Md as da,jd as ea,Gd as fa,K as ga,Wr as ha,KS as ia,JS as ja,YS as ka,XS as la,ZS as ma,Xd as na,QS as oa,uh as pa,hh as qa,wh as ra,vh as sa,kh as ta,z as ua,Sh as va,Ih as wa,Ah as xa,Eh as ya,Br as za,tm as Aa,lt as Ba,Vr as Ca,nm as Da,Th as Ea,om as Fa,Ch as Ga,Rh as Ha,xh as Ia,Oh as Ja,$h as Ka,jh as La,sm as Ma,Gh as Na,Bh as Oa,eg as Pa,ng as Qa,_g as Ra,jg as Sa,b as Ta,RT as Ua,xT as Va,OT as Wa,$T as Xa,FT as Ya,PT as Za,LT as _a,NT as $a,DT as ab,MT as bb,jT as cb,GT as db,UT as eb,qT as fb,zT as gb,HT as hb,WT as ib,VT as jb,BT as kb,KT as lb,JT as mb,YT as nb,XT as ob,ZT as pb,QT as qb,eC as rb,tC as sb,nC as tb,oC as ub,rC as vb,iC as wb,aC as xb,sC as yb,cC as zb,lC as Ab,dC as Bb,mC as Cb,pC as Db,uC as Eb,_C as Fb,fC as Gb,hC as Hb,gC as Ib,yC as Jb,bC as Kb,wC as Lb,vC as Mb,kC as Nb,SC as Ob,IC as Pb,AC as Qb,EC as Rb,TC as Sb,CC as Tb,RC as Ub,xC as Vb,OC as Wb,$C as Xb,FC as Yb,PC as Zb,LC as _b,NC as $b,DC as ac,MC as bc,jC as cc,GC as dc,UC as ec,qC as fc,zC as gc,HC as hc,WC as ic,VC as jc,BC as kc,KC as lc,JC as mc,YC as nc,XC as oc,ZC as pc,QC as qc,eR as rc,tR as sc,nR as tc,oR as uc,Hg as vc,rR as wc};
|
|
2248
|
-
//# sourceMappingURL=chunk-
|
|
2248
|
+
//# sourceMappingURL=chunk-JTF6VMXH.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{$ as oe,Ab as En,Am as
|
|
1
|
+
import{$ as oe,Ab as En,Ai as A,Am as Le,Bi as Ee,Bm as lt,Cb as Wi,Cm as vr,Db as Bi,Dm as br,Em as ce,Fm as Ke,G as ji,Gb as Hi,Gm as kr,Hm as me,Ii as $e,Il as _r,Ko as Gt,L as wn,Mi as pr,N as Li,Nb as Ki,Ni as mr,Oi as Ie,Pi as ur,Q as vn,Qi as fr,R as h,T as f,Ta as Mi,Tc as $n,Tn as xr,Ua as Gi,Uc as nr,V as k,Va as U,Vc as Dt,W as Pt,X as ie,Xc as ke,Xf as Se,Y as G,Zc as xe,Zd as or,Zi as hr,_d as st,ad as ir,ba as K,bb as N,cb as Ui,cd as jt,db as zi,dd as rr,dj as gr,eb as Ji,ed as ar,fa as pe,fc as Vi,gc as Yi,gj as Ft,hc as Xi,hj as Mt,jg as I,k as Ni,ka as Fi,kc as Zi,kf as T,kg as Z,kj as je,lc as Qi,lg as sr,li as In,mg as Y,mh as lr,ng as re,ni as dr,od as W,oi as He,pg as cr,pj as yr,qj as An,rf as V,rg as ct,rh as B,tc as er,tg as Lt,ua as Rt,va as bn,vc as tr,vi as se,w as Di,wa as kn,wb as Nt,xb as qi,xd as H,yb as xn,yc as De,z as Ct,zb as Sn,zm as wr}from"./chunk-IDEHMKYZ.js";import{mkdir as oc,readFile as sc}from"node:fs/promises";import Ar 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]="0bd9a904-c076-5c2a-a9d8-42a543625e33")}catch{}})();var Tn=class extends Error{constructor(t="Workspace transaction interrupted"){super(t),this.name="WorkspaceTransactionInterruptedError"}},cc="sdk-workspace-transaction",lc=/^[a-zA-Z0-9._-]+$/,dc=30,pc=3e3;function Tr(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n||!lc.test(n))throw new TypeError(`${t} must match [a-zA-Z0-9._-]+`);return n}function Sr(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n)throw new TypeError(`${t} must be non-empty`);return n}function mc(e){return{pmRoot:Sr(e.pmRoot,"Transaction pmRoot"),transactionId:Tr(e.transactionId,"Transaction id"),author:Sr(e.author,"Transaction author")}}function Er(e,t,n){let i=e??t;if(!Number.isInteger(i)||i<=0)throw new TypeError(`${n} must be a positive integer`);return i}function Or(e,t){return Ar.join(e,"transactions","sdk",`${t}.json`)}async function Ae(e,t){t.updatedAt=T();let n=Or(e,t.transactionId);await oc(Ar.dirname(n),{recursive:!0}),await oe(n,`${JSON.stringify(t,null,2)}
|
|
2
2
|
`)}function uc(e){return Number.isInteger(e.attempt)&&typeof e.author=="string"&&typeof e.createdAt=="string"&&typeof e.updatedAt=="string"}function Fe(e){return Object.assign(Object.create(null),e)}function fc(e,t){try{let n=JSON.stringify(e,(i,r)=>{if(typeof r=="number"&&!Number.isFinite(r))throw new TypeError(`${t} contains a non-finite number`);if(r===void 0||typeof r=="function"||typeof r=="symbol")throw new TypeError(`${t} contains a non-JSON value`);return r});return JSON.parse(n)}catch(n){throw new TypeError(`${t} must be JSON serializable`,{cause:n})}}function On(e,t){return e===void 0?void 0:fc(e,t)}function Cn(e,t,n,i){let r=On(n,i);r===void 0?delete e[t]:e[t]=r}function $r(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ir(e,t){return Array.isArray(e)&&new Set(e).size===e.length&&e.every(n=>typeof n=="string"&&t.includes(n))}function hc(e,t){if(!Ir(e.startedStepIds,t)||!Ir(e.completedStepIds,t)||!$r(e.results)||!$r(e.compensationData))return!1;let n=e.startedStepIds,i=new Set(n),r=e.completedStepIds,a=new Set(r);return Object.keys(e.compensationData).some(o=>!i.has(o))||Object.keys(e.results).some(o=>!a.has(o))?!1:e.status==="committed"?t.every(o=>a.has(o)):e.status!=="compensated"||a.size===0&&i.size===0}function gc(e,t,n){let i;try{i=JSON.parse(e)}catch{throw new TypeError(`Workspace transaction ${t} journal is invalid JSON`)}if(!i||typeof i!="object"||Array.isArray(i))throw new TypeError(`Workspace transaction ${t} journal is invalid`);let r=i,a=r.schemaVersion===1&&r.transactionId===t,o=Array.isArray(r.stepIds)&&r.stepIds.length===n.length&&r.stepIds.every((d,p)=>d===n[p]),s=hc(r,n),l=uc(r),c=["applying","compensating","compensated","committed"].includes(String(r.status));if(!a||!o||!s||!l||!c)throw new TypeError(`Workspace transaction ${t} journal does not match the supplied plan`);return{...r,results:Fe(r.results),compensationData:Fe(r.compensationData)}}async function yc(e,t,n,i,r){let a=r,o=a!==void 0;if(a?.status==="compensating"&&await Cr(e,a),a===void 0||a.status==="compensated"){let s=T();a={schemaVersion:1,transactionId:t,author:n,status:"applying",attempt:(a?.attempt??0)+1,createdAt:a?.createdAt??s,updatedAt:s,stepIds:i,startedStepIds:[],completedStepIds:[],results:Fe(),compensationData:Fe()},await Ae(e.pmRoot,a),await _e(e,a,"prepared")}return{journal:a,recovered:o}}async function _c(e,t,n){try{await vc(t,e.steps),await Ae(e.pmRoot,t);let i=new Set(t.completedStepIds),r=new Set(t.startedStepIds);for(let a of e.steps){if(i.has(a.id))continue;let o=await a.inspect(),s=On(o.result,`Step ${a.id} result`);if(o.state!=="applied"){let l=await a.prepareCompensation?.();Cn(t.compensationData,a.id,l,`Step ${a.id} compensation data`),r.add(a.id),t.startedStepIds=e.steps.map(d=>d.id).filter(d=>r.has(d)),await Ae(e.pmRoot,t);let c=await a.apply();s=On(c,`Step ${a.id} result`)}await _e(e,t,"step_applied",a.id),i.add(a.id),t.completedStepIds=e.steps.map(l=>l.id).filter(l=>i.has(l)),Cn(t.results,a.id,s,`Step ${a.id} result`),await Ae(e.pmRoot,t),await _e(e,t,"step_recorded",a.id)}return await _e(e,t,"committing"),t.status="committed",await Ae(e.pmRoot,t),await _e(e,t,"committed"),{transactionId:t.transactionId,status:"committed",recovered:n,results:Fe(t.results)}}catch(i){if(i instanceof Tn||t.status==="committed")throw i;try{await Cr(e,t)}catch(r){throw new AggregateError([i,r],`Workspace transaction failed and compensation failed: ${String(r)}`,{cause:r})}throw i}}async function wc(e,t,n){try{return gc(await sc(Or(e,t),"utf8"),t,n)}catch(i){if(i!==null&&typeof i=="object"&&"code"in i&&ie(i))return;throw i}}async function _e(e,t,n,i){await e.onTransition?.({transactionId:t.transactionId,attempt:t.attempt,transition:n,...i===void 0?{}:{stepId:i}})}async function vc(e,t){let n=new Set,i=Fe();for(let r of t){let a=await r.inspect();a.state==="applied"&&(n.add(r.id),Cn(i,r.id,a.result,`Step ${r.id} result`))}e.results=i,e.completedStepIds=t.map(r=>r.id).filter(r=>n.has(r))}async function Cr(e,t){t.status="compensating",await Ae(e.pmRoot,t),await _e(e,t,"compensating");let n=new Set(t.completedStepIds),i=new Set(t.startedStepIds);for(let r of[...e.steps].reverse()){if(!i.has(r.id)&&!n.has(r.id))continue;let a;try{a=i.has(r.id)&&(await r.inspect()).state==="applied"}catch{a=i.has(r.id)}a&&(await _e(e,t,"step_compensating",r.id),await r.compensate(t.compensationData[r.id])),n.delete(r.id),i.delete(r.id),t.completedStepIds=e.steps.map(o=>o.id).filter(o=>n.has(o)),t.startedStepIds=e.steps.map(o=>o.id).filter(o=>i.has(o)),delete t.results[r.id],delete t.compensationData[r.id],await Ae(e.pmRoot,t),await _e(e,t,"step_compensated",r.id)}t.status="compensated",await Ae(e.pmRoot,t),await _e(e,t,"compensated")}async function Pr(e){let{pmRoot:t,transactionId:n,author:i}=mc(e),r=Er(e.lockTtlSeconds,dc,"Transaction lock TTL"),a=Er(e.lockWaitMs,pc,"Transaction lock wait"),o=[...e.steps];if(o.length===0)throw new TypeError("Workspace transaction requires at least one step");let s=o.map(d=>{let p=Tr(d.id,"Transaction step id");if(p!==d.id)throw new TypeError("Transaction step id must not contain surrounding whitespace");return p});if(new Set(s).size!==s.length)throw new TypeError("Workspace transaction step ids must be unique");let l={...e,pmRoot:t,transactionId:n,author:i,steps:o,lockTtlSeconds:r,lockWaitMs:a},c=await V(t,cc,r,i,!1,!1,a);try{let d=await wc(t,n,s),p=d!==void 0;if(d?.status==="committed")return{transactionId:n,status:"committed",recovered:!0,results:Fe(d.results)};let m=await yc(l,n,i,s,d);return await _c(l,m.journal,p||m.recovered)}finally{await c()}}import bc from"node:fs/promises";import kc 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]="7be00b26-4a56-5399-94f6-f2f67cc5c1e6")}catch{}})();function Pn(e){return kc.join(e,"extension-migrations.json")}function Rr(e,t){let n=e.definition.id;return typeof n=="string"&&n.trim().length>0?n.trim():`migration-${String(t+1).padStart(3,"0")}`}function Nr(e,t){return`${e.layer}:${e.name}:${t}`}async function xc(e){let t=Pn(e);if(!await k(t))return{version:1,updated_at:"",entries:[]};let n=JSON.parse(await bc.readFile(t,"utf8"));return{version:1,updated_at:typeof n.updated_at=="string"?n.updated_at:"",entries:Array.isArray(n.entries)?n.entries.filter(i=>typeof i?.key=="string"&&(i.status==="applied"||i.status==="failed")):[]}}async function Sc(e,t){let n=await xc(e),i=new Map(n.entries.map(r=>[r.key,r]));return t.forEach((r,a)=>{let o=Rr(r,a),s=i.get(Nr(r,o));s&&(r.definition.status=s.status,s.status==="failed"?r.definition.reason=s.error:(delete r.definition.reason,delete r.definition.error,delete r.definition.message))}),n}async function Ec(e){let t=await Sc(e.pmRoot,e.migrations),n=new Map(t.entries.map(d=>[d.key,d])),i=[],r=!1,a=e.migrations.map((d,p)=>({migration:d,index:p})).filter(({migration:d})=>e.scope===void 0||d.layer===e.scope);for(let{migration:d,index:p}of a){let m=Rr(d,p),g=Nr(d,m),y=n.get(g),_=String(d.definition.status??"pending").toLowerCase(),u=y?.status??(_==="applied"||_==="failed"?_:"pending");if(u==="applied"){i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"skipped"});continue}if(e.dryRun===!0){i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"pending"});continue}let w=d.runtime_definition?.run??d.definition.run;if(typeof w!="function"){i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"pending"});continue}let v=new Date().toISOString();try{await Promise.resolve(w({id:m,command:"migration",layer:d.layer,extension:d.name,pm_root:e.pmRoot,status:u}));let x={key:g,layer:d.layer,extension:d.name,id:m,status:"applied",attempted_at:v};n.set(g,x),d.definition.status="applied",delete d.definition.reason,delete d.definition.error,delete d.definition.message,i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"applied"}),r=!0}catch(x){let S=x instanceof Error?x.message:String(x),O={key:g,layer:d.layer,extension:d.name,id:m,status:"failed",attempted_at:v,error:S};n.set(g,O),d.definition.status="failed",d.definition.reason=S,i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"failed",error:S}),r=!0}}if(r){let d=await A(e.pmRoot),p={version:1,updated_at:new Date().toISOString(),entries:[...n.values()].sort((m,g)=>m.key.localeCompare(g.key))};await He({pmRoot:e.pmRoot,filePath:Pn(e.pmRoot),raw:`${JSON.stringify(p,null,2)}
|
|
3
3
|
`,op:"extension_migrations_apply",author:e.author,lockTtlSeconds:d.locks.ttl_seconds,lockWaitMs:d.locks.wait_ms})}let o=i.filter(d=>d.outcome==="pending").length,s=i.filter(d=>d.outcome==="applied").length,l=i.filter(d=>d.outcome==="skipped").length,c=i.filter(d=>d.outcome==="failed").length;return{ok:c===0,dry_run:e.dryRun===!0,state_path:Pn(e.pmRoot),total:i.length,pending_count:o,applied_count:s,skipped_count:l,failed_count:c,migrations:i}}async function Dr(e){let t=await A(e.resolvedRoots.settings_root),n=await ke({pmRoot:e.resolvedRoots.pm_root,settings:t,cwd:process.cwd(),noExtensions:e.global.noExtensions===!0}),i=await xe(n);e.warnings.push(...n.warnings,...i.warnings);let r=await Ec({pmRoot:e.resolvedRoots.pm_root,migrations:i.registrations.migrations,author:typeof e.global.author=="string"&&e.global.author.trim().length>0?e.global.author.trim():"pm-extension-migration",dryRun:e.options.dryRun===!0,...e.scope==="global"?{scope:"global"}:{}});return e.withResult({migration:r,load_failure_count:n.failed.length,activation_failure_count:i.failed.length},r.ok)}import{readFile as $c,writeFile as Ic}from"node:fs/promises";import dt 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]="1de99e25-e132-5071-833e-37361b4cc7e6")}catch{}})();var Lr="# pm-cli:runtime-cache:start",Rn="# pm-cli:runtime-cache:end",Fr=".agents/pm",Ac=["runtime/","search/","locks/","transactions/","checkpoints/"],Tc=["search/eval-queries.json"];async function jr(e){try{return await e()}catch(t){throw t instanceof Error&&"code"in t&&typeof t.code=="string"&&["EACCES","EPERM","EROFS"].includes(t.code)?new f("The workspace .gitignore is not writable.",h.GENERIC_FAILURE,{code:"init_gitignore_unwritable",reason:t.code.toLowerCase(),required:"Grant the current user read and write access to the workspace .gitignore before initialization.",why:"pm init must publish its managed runtime-cache ignore fence without replacing unrelated entries.",nextSteps:["Grant read and write access to the workspace .gitignore and rerun pm init.","If the workspace is intentionally read-only, initialize pm in a writable workspace or clone."]}):t}}function Mr(e){return e.replaceAll("\\","/").replace(/^\.\/+/,"").replace(/\/+$/,"")}function Nn(e){let t=e.replaceAll("\\","/");return dt.isAbsolute(e)||t===".."||t.startsWith("../")}function Oc(e=Fr){let t=Mr(e);return[Lr,...Ac.map(n=>n==="search/"?`${t}/${n}*`:`${t}/${n}`),...Tc.map(n=>`!${t}/${n}`),Rn].join(`
|
|
4
4
|
`)}async function Gr(e,t={}){let n=dt.join(e,".gitignore"),i=Fr;if(t.pmRoot!==void 0){let c=Mr(dt.relative(dt.resolve(e),dt.resolve(t.pmRoot)));if(Nn(c))return{path:n,changed:!1};c.length>0&&(i=c)}let r="";try{r=await jr(()=>$c(n,"utf8"))}catch(c){if(!(c instanceof Error&&"code"in c&&ie(c)))throw c}let a=r.indexOf(Lr),o=r.indexOf(Rn),s=(a>=0&&o>=a?`${r.slice(0,a)}${r.slice(o+Rn.length)}`:r).trimEnd(),l=`${s.length>0?`${s}
|
|
5
5
|
|
|
6
6
|
`:""}${Oc(i)}
|
|
7
7
|
`;return l===r?{path:n,changed:!1}:(await jr(()=>Ic(n,l,"utf8")),{path:n,changed:!0})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="184c43e0-a543-5b0b-ac09-9139ba5ded6a")}catch{}})();var Cc=[["beforeCommand","before_command"],["beforeMutation","before_mutation"],["afterCommand","after_command"],["onWrite","on_write"],["onRead","on_read"],["onIndex","on_index"]];function Ve(e,t={}){let n=new Set;t.extensionName!==void 0&&n.add(jt(t.extensionName));for(let u of t.extensionNames??[])n.add(jt(u));let i=u=>n.size===0||n.has(jt(u)),r=(u,w)=>Ur(u.filter(v=>i(v.name)).map(w)),a=(u,w)=>Ur(u.filter(v=>i(v.name)).flatMap(w)),{registrations:o,commands:s,parsers:l,preflight:c,services:d,renderers:p,hooks:m}=e,g=a(o.relationship_kinds??[],u=>u.definitions.map(w=>w.kind)),y=p.overrides.filter(u=>i(u.name)&&((u.commands?.length??0)>0||u.resultDiscriminator!==void 0)).map(u=>({format:u.format,commands:[...u.commands??[]],result_discriminator:u.resultDiscriminator!==void 0})).sort((u,w)=>u.format.localeCompare(w.format)),_=r(o.assurance_providers??[],u=>u.definition.id);return{capabilities:rr(e,t),commands:r(o.commands,u=>u.command),command_overrides:r(s.overrides,u=>u.command),command_handlers:r(s.handlers,u=>u.command),hooks:Cc.filter(([u])=>m[u].some(w=>i(w.name))).map(([,u])=>u),flag_commands:r(o.flags,u=>u.target_command),item_types:a(o.item_types,u=>u.types.map(w=>w.name)),item_fields:a(o.item_fields,u=>u.fields.map(w=>w.name)),...g.length>0?{relationship_kinds:g}:{},migrations:a(o.migrations,u=>typeof u.definition.id=="string"?[u.definition.id]:[]),profiles:r(o.profiles,u=>u.profile.name),importers:r(o.importers,u=>u.importer),exporters:r(o.exporters,u=>u.exporter),search_providers:r(o.search_providers,u=>u.definition.name),vector_store_adapters:r(o.vector_store_adapters,u=>u.definition.name),..._.length>0?{assurance_providers:_}:{},parser_overrides:r(l.overrides,u=>u.command),service_overrides:r(d.overrides,u=>u.service),renderer_overrides:r(p.overrides,u=>u.format),...y.length>0?{renderer_ownership:y}:{},preflight_overrides:c.overrides.filter(u=>i(u.name)).length,preflight_ownership:c.overrides.filter(u=>i(u.name)).map(u=>({commands:[...u.commands??[]]}))}}function Ur(e){return[...new Set(e)].sort((t,n)=>t.localeCompare(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]="6d1f8e03-97b4-5d83-b85c-e47f39c07d48")}catch{}})();var Pc="PM_SOURCE_CONTEXT_ACCESS",Rc="PM_ALLOW_SOURCE_CONTEXT_WRITES";function zr(e){let t=e[Pc],n=t===void 0||t.trim().toLowerCase()==="write"?"write":"read_only",i=n==="read_only"&&e[Rc]?.trim()==="1";return{access:n,write_override_applied:i,source_writes_allowed:n==="write"||i}}import Jr from"node:fs";import zt 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]="2d40ac36-0627-5636-9679-5669dbacf06b")}catch{}})();var pt="@unbrained/pm-cli",Nc=new Set(["append","claim","changelog","close","close-many","close-task","comments","config","copy","create","dedupe-merge","delete","deps","docs","extension","event","events","files","focus","gc","history-author-acknowledge","history-compact","history-redact","history-repair","init","install","item","learnings","meet","merge","normalize","notes","package","packages","pause-task","plan","profile","reindex","release","remind","restore","schema","start-task","test","test-all","test-runs","test-runs-worker","telemetry","templates","twin","update","update-many","upgrade","vcs","workspace"]),qr=new Set(["--author","--output-budget","--output-format","--output-include","--output-limit","--output-session","--path","--pm-path"]),Ln=/\b(\d{4})\.(\d{1,2})\.(\d{1,2})(?:-(\d+))?\b/u,qt="2026.8.31";function X(e,t){return e.some(n=>t.includes(n.split("=",1)[0]))}function Dn(e,t){return["activate","adopt","adopt-all","deactivate","init","install","migrate","reload","uninstall"].includes(t[0]??"")||X(e,["--activate","--adopt","--adopt-all","--deactivate","--fix-managed-state","--init","--install","--output","--reload","--scaffold","--uninstall"])}var Dc={changelog:(e,t)=>{if(t[0]==="generate")return!X(e,["--check"]);let n=e.indexOf("export");return t[0]==="export"&&(X(e,["--output"])||n>=0&&e[n+1]!==void 0&&!e[n+1].startsWith("-"))},comments:e=>X(e,["--add","--delete","--edit","--file","--stdin"]),config:(e,t)=>(t[0]==="project"||t[0]==="global"?t[1]:t[0])==="set",deps:()=>!1,docs:e=>X(e,["--add","--add-glob","--migrate","--remove"]),duplicates:()=>!1,events:()=>!1,extension:Dn,files:(e,t)=>X(e,["--add","--add-glob","--migrate","--remove"])||t[0]==="discover"&&X(e,["--apply"]),health:e=>!X(e,["--check-only","--no-refresh","--skip-vectors"]),learnings:e=>X(e,["--add","--delete","--edit","--file","--stdin"]),merge:(e,t)=>t[0]!=="report",notes:e=>X(e,["--add","--delete","--edit","--file","--stdin"]),package:Dn,packages:Dn,profile:(e,t)=>t[0]==="apply",schema:(e,t)=>["add-field","add-status","add-type","remove-field","remove-status","remove-type","remap-status","rename-field","rename-type"].includes(t[0]??"")&&!(X(e,["--infer"])&&!X(e,["--apply"])),telemetry:(e,t)=>t.slice(0,2).some(n=>["clear","flush"].includes(n)),templates:(e,t)=>t[0]==="save",test:e=>X(e,["--add","--add-json","--background","--measure","--remove","--resume","--run","--stop"]),validate:e=>X(e,["--auto-fix","--prune-missing"]),vcs:(e,t)=>["abandon","create","merge","propose","ref-create"].includes(t[0]??""),workspace:(e,t)=>t[0]==="snapshot"&&["create","delete","restore"].includes(t[1]??"")};function Jt(e){let t=e.match(Ln);return t?[Number(t[1]),Number(t[2]),Number(t[3]),Number(t[4]??0)]:null}function Me(e,t){let n=Jt(e),i=Jt(t);if(!n||!i)return null;for(let r=0;r<n.length;r+=1){let a=n[r]-i[r];if(a!==0)return Math.sign(a)}return 0}function Ut(e){return Me(e,qt)!==-1?3:2}function jc(e,t){if(t===3)return e.filter(n=>n.history_epoch_compatible===!1).map(n=>({...n,declaration:n.declaration??n.version})).sort((n,i)=>Me(n.version,i.version))[0]}function jn(e){try{let t=JSON.parse(Jr.readFileSync(e,"utf8"));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function Lc(e){let t=[...e.matchAll(/(<=|<)\s*v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/gu)].map(i=>({inclusive:i[1]==="<=",version:i[2]})),n=e.match(/\b\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?\s+-\s+v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/u);return n?[...t,{inclusive:!0,version:n[1]}]:t}function Fc(e){let t=e.split("||").map(n=>Lc(n));return{bounded:t.some(n=>n.length>0),compatible:t.some(n=>n.every(i=>{let r=Me(qt,i.version);return r!==null&&(i.inclusive?r!==1:r===-1)}))}}function Mc(e){return["dependencies","devDependencies","optionalDependencies","peerDependencies"].flatMap(t=>{let n=e[t];if(typeof n!="object"||n===null)return[];let i=n[pt],r=typeof i=="string"?i.trim():"",a=/^[<!]/u.test(r)?void 0:r.match(Ln)?.[0];if(!a)return[];let o=/^(?:=|v)?\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?$/u.test(r),s=Fc(r);return[{version:a,constraint:o?"exact":s.bounded?"range":"minimum",...o?{}:{declaration:r},history_epoch_compatible:o?Me(a,qt)!==-1:s.compatible}]})}function Gc(e){let t=jn(zt.join(e,"package-lock.json"))?.packages;if(typeof t!="object"||t===null)return;let n=t["node_modules/@unbrained/pm-cli"];if(typeof n!="object"||n===null)return;let i=n.version;return typeof i=="string"?i:void 0}function Uc(e,t){try{let n=Jr.readFileSync(zt.join(e,t),"utf8").split(/\r?\n/u),i=n.findIndex(o=>o.includes(pt));if(i<0)return;let r=n[i].match(/^\s*/u)[0].length,a=[n[i]];for(let o=i+1;o<n.length;o+=1){let s=n[o],l=s.trim(),c=s.match(/^\s*/u)[0].length;if(l.length>0&&c<=r)break;a.push(s)}return a.join(`
|
|
8
|
-
`).match(/^\s*version(?::\s*|\s+)["']?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/mu)?.[1]??a[0].match(Ln)?.[0]}catch{return}}function Fn(e){let t=[],n=jn(zt.join(e,"package.json"));n&&t.push(...Mc(n).map(a=>({...a,source:"package.json"})));let i=jn(zt.join(e,"node_modules","@unbrained","pm-cli","package.json"))?.version;typeof i=="string"&&Jt(i)&&t.push({version:i,source:"installed-package",constraint:"exact",history_epoch_compatible:Ut(i)===3});let r=Gc(e);r&&Jt(r)&&t.push({version:r,source:"package-lock.json",constraint:"exact",history_epoch_compatible:Ut(r)===3});for(let a of["pnpm-lock.yaml","yarn.lock"]){let o=Uc(e,a);o&&t.push({version:o,source:a,constraint:"exact",history_epoch_compatible:Ut(o)===3})}return t}function Wr(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(qr.has(n)){t+=1;continue}if(!n.startsWith("-"))return{command:n.toLowerCase(),index:t}}}function zc(e){let t=Wr(e);if(!t||X(e,["--help","-h","--dry-run"]))return!1;let{command:n,index:i}=t,r=[];for(let o=i+1;o<e.length;o+=1){let s=e[o];if(qr.has(s)){o+=1;continue}s.startsWith("-")||r.push(s.toLowerCase())}let a=Dc[n];return a?a(e,r):Nc.has(n)}function Jc(e){let t=Wr(e.argv)?.command,n=zc(e.argv),i=Fn(e.projectRoot).filter(d=>Me(d.version,e.executingVersion)!==null).sort((d,p)=>Me(p.version,d.version)),r=i[0],a=r!==void 0&&Me(e.executingVersion,r.version)===-1,o=Ut(e.executingVersion),s=jc(i,o),l=n&&s!==void 0,c=a&&!n?{code:"project_runtime_stale_read",executing_version:e.executingVersion,project_version:r.version,source:r.source,message:"This read is using an older pm runtime than the project requires.",next_steps:[`Run the command through the project's installed ${pt} ${r.version}.`,"Install the project dependencies with its declared package manager if the local executable is missing."]}:void 0;return{compatible:!n||!a&&!l||e.allowStale===!0,executing_version:e.executingVersion,...r?{project_version:r.version,source:r.source}:{},...t?{command:t}:{},mutating:n,stale:a,history_epoch_incompatible:l,writer_item_hash_version:o,...s?{incompatible_project_version:s.declaration,incompatible_source:s.source}:{},...c?{warning:c}:{},override_applied:n&&(a||l)&&e.allowStale===!0}}function sh(e){let t=Jc(e);if(t.compatible)return t;throw t.history_epoch_incompatible?new f(`pm ${t.executing_version} cannot write item-hash epoch ${t.writer_item_hash_version} into a project pinned to pm ${t.incompatible_project_version}.`,h.CONFLICT,{code:"project_runtime_history_epoch_incompatible",reason:t.incompatible_source,why:`The pinned runtime cannot read item_hash_version ${t.writer_item_hash_version}; allowing the write would break its health and validation gates.`,nextSteps:[`Upgrade the project's ${pt} pin to ${qt} or newer before mutating tracker history.`,"For an intentional coordinated migration only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.","Read-only commands remain available without an override."]}):new f(`pm ${t.executing_version} cannot mutate a project pinned to newer pm ${t.project_version}.`,h.CONFLICT,{code:"project_runtime_stale_mutation",reason:t.source,why:"An older runtime can write storage, history, and merge contracts it does not understand.",nextSteps:[`Run this command through the project's installed ${pt} ${t.project_version}.`,"For an intentional recovery only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.","Read-only commands remain available without an override."]})}import{access as Kc,readFile as Un,realpath as Te}from"node:fs/promises";import{constants as Vc}from"node:fs";import{execFile as Yc}from"node:child_process";import P from"node:path";import{promisify as Xc}from"node:util";import{execFile as qc}from"node:child_process";import Wc from"node:path";import{promisify as Bc}from"node:util";import{setTimeout as Hc}from"node:timers/promises";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="f8f33f3d-854e-5cb4-b0bf-8d2d89da27e8")}catch{}})();var Gn=Bc(qc);async function Ye(e,t){let n=performance.now()+5e3,i=25;for(;;)try{await Gn("git",["config",...t],{cwd:e,env:{...ue(),LC_ALL:"C"},timeout:1e4});return}catch(r){let a=n-performance.now();if(typeof r!="object"||r===null||!("stderr"in r)||typeof r.stderr!="string"||!/could not lock config file [^\r\n]+: File exists/u.test(r.stderr)||a<=0)throw r;await Hc(Math.min(i,a)),i=Math.min(i*2,200)}}function ue(){let e={...process.env};for(let t of["GIT_DIR","GIT_WORK_TREE","GIT_COMMON_DIR","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES","GIT_DISCOVERY_ACROSS_FILESYSTEM"])delete e[t];return e}async function Mn(e,t){try{return(await Gn("git",["config","--local",...t==="core.bare"||t==="extensions.worktreeConfig"?["--type=bool"]:[],"--get",t],{cwd:e,env:ue(),timeout:1e4})).stdout.trim()}catch(n){if(typeof n=="object"&&n!==null&&"code"in n&&n.code===1)return;throw n}}async function Br(e){if(await Mn(e,"extensions.worktreeConfig")==="true")return"--worktree";let{stdout:t}=await Gn("git",["rev-parse","--path-format=absolute","--git-dir","--git-common-dir"],{cwd:e,env:ue(),timeout:1e4}),[n,i]=t.trim().split(/\r?\n/);if(n===i)return"--local";let r=Wc.join(i,"config.worktree");for(let a of["core.bare","core.worktree"]){let o=await Mn(e,a);o===void 0||a==="core.bare"&&o!=="true"||(await Ye(e,["--file",r,a,o]),await Ye(e,["--local","--unset-all",a]))}for(let a of["pm-item-toon","pm-item-markdown","pm-history","pm-relationship","pm-json"])for(let o of["name","driver"]){let s=`merge.${a}.${o}`,l=await Mn(e,s);l!==void 0&&await Ye(e,["--file",r,s,l])}return await Ye(e,["--local","extensions.worktreeConfig","true"]),"--worktree"}(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]="36ccb98d-6645-52fe-aac2-be11f3a63c25")}catch{}})();var Ge=Xc(Yc),Wt="# pm-cli:merge-drivers:start",Zc="# pm-cli:merge-drivers:end",mt="# pm-cli:merge-drivers:v2:start",Vr="# pm-cli:merge-drivers:v2:end",Qc="merge-fence",el="merge-attributes";function Hr(e){return`'${e.replaceAll("'",`'"'"'`)}'`}async function tl(e,t){let n=await Te(e);if(/(?:^|[\\/])bun-node-[^\\/]+[\\/]bun(?:\.exe)?$/iu.test(n))return;let{stdout:i}=await Ge(e,["--version"],{encoding:"utf8",windowsHide:!0,timeout:1e4});return i.trim()===t?n:void 0}async function nl(){let e=pe(import.meta.url,["../../.."]),t=process.execPath,n=!1,i=await Te(process.execPath),r=process.versions.bun,a=(process.env.PATH??"").split(P.delimiter).filter(s=>P.isAbsolute(s)).map(s=>P.join(s,r===void 0?P.basename(process.execPath):process.platform==="win32"?"bun.exe":"bun")),o=r===void 0?a:[process.env.npm_execpath??"",...a,i].filter(s=>P.isAbsolute(s)&&/^(?:bun|bun\.exe)$/iu.test(P.basename(s)));for(let s of o)try{if(await Kc(s,Vc.X_OK),r!==void 0){let l=await tl(s,r);if(l!==void 0){t=l,n=!0;break}continue}if(s!==i&&await Te(s)===i){t=s;break}}catch{}if(r!==void 0&&!n)throw new f("Cannot install Bun merge drivers without a durable executable matching the current Bun version.",h.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`${Hr(t)} ${Hr(P.join(e,"dist","cli.js"))}`}var Yr=[{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 il(e){let t=e.explicitPath?.trim(),n=e.environment.PM_SOURCE_WORKSPACE_ROOT?.trim(),i=e.environment.PM_SOURCE_PM_PATH?.trim(),r=zr(e.environment),a=!!(n&&i),o=t===void 0&&a&&(e.dryRun||r.source_writes_allowed);if(t!==void 0){let s=N(e.cwd,t);return{pm_root:s,workspace_start:s,source_coordinates_available:a,source_context_selected:!1,source_policy:r}}return o?{pm_root:P.resolve(i),workspace_start:P.resolve(n),source_coordinates_available:!0,source_context_selected:!0,source_policy:r}:{pm_root:a?N(e.cwd,".agents/pm"):N(e.cwd),workspace_start:e.cwd,source_coordinates_available:a,source_context_selected:!1,source_policy:r}}async function Bt(e){try{let{stdout:t}=await Ge("git",["rev-parse","--show-toplevel"],{cwd:e,env:ue(),encoding:"utf8",windowsHide:!0,timeout:1e4});return await Te(t.trim())}catch{return null}}async function Xr(e){let t=await Bt(e);if(t===null)throw new f("pm merge install requires a git repository (merge drivers are git configuration).",h.USAGE);return t}function zn(e,t){return P.relative(e,t).replaceAll("\\","/")}function le(e){return`"${e.replaceAll("\\","\\\\").replaceAll('"','\\"')}"`}function Kr(e,t){if(e[t]!=="'")return null;let n="";for(let i=t+1;i<e.length;i+=1){if(e.startsWith(`'"'"'`,i)){n+="'",i+=4;continue}if(e[i]==="'")return{value:n,nextOffset:i+1};n+=e[i]}return null}async function rl(e,t,n){if(Fn(t).filter(r=>r.constraint==="exact").some(r=>r.version!==n))return!1;let i=await Bt(e);if(i!==null&&i!==await Te(t)){let r=await Promise.all([i,t].map(async a=>{let o=await Ge("git",["rev-parse","--path-format=absolute","--git-common-dir"],{cwd:a,env:ue(),timeout:1e4});return Te(o.stdout.trim())}));if(r[0]===r[1])return!1}return!0}async function al(e,t,n){let i=Kr(e,0);if(i===null||e[i.nextOffset]!==" ")return!1;let r=Kr(e,i.nextOffset+1);if(r===null||e.slice(r.nextOffset)!==t||!/^(?:node|bun)(?:\.exe)?$/iu.test(P.basename(i.value))||P.basename(r.value)!=="cli.js"||P.basename(P.dirname(r.value))!=="dist"||!await k(i.value)||!await k(r.value))return!1;try{let a=P.dirname(P.dirname(r.value)),o=JSON.parse(await Un(P.join(a,"package.json"),"utf8")),s=typeof o.bin=="string"?o.bin:o.bin?.pm;return await rl(a,n,o.version)?o.name==="@unbrained/pm-cli"&&s==="dist/cli.js":!1}catch{return!1}}function Jn(e,t){let n=e.length>0?`${e}/`:"",i=[`${le(`${n}**/*.toon`)} merge=pm-item-toon`,`${le(`${n}**/*.md`)} merge=pm-item-markdown`];for(let r of t)i.push(`${le(`${n}${r}/*.toon`)} merge=pm-item-toon`),i.push(`${le(`${n}${r}/*.md`)} merge=pm-item-markdown`);return i.push(`${le(`${n}**/*.jsonl`)} merge=pm-relationship`),i.push(`${le(`${n}history/*.jsonl`)} merge=pm-history`),i.push(`${le(`${n}settings.json`)} merge=pm-json`),i.push(`${le(`${n}**/*.json`)} merge=pm-json`),i.push(`${le(`${n}extensions/**`)} -merge`),i.push(`${le(`${n}extensions/.managed-extensions.json`)} merge=pm-json`),i}function Zr(e){let t=[],n=0;for(;n<e.length;){let i=e.indexOf(Wt,n),r=e.indexOf(mt,n),a=i===-1?r:r===-1?i:Math.min(i,r);if(a===-1)break;let o=a===r,s=o?mt:Wt,l=o?Vr:Zc,c=e.indexOf(l,a+s.length),d=c===-1?e.length:c+l.length;t.push({start:a,end:d,closed:c!==-1,lines:e.slice(a+s.length,c===-1?d:c).split(`
|
|
8
|
+
`).match(/^\s*version(?::\s*|\s+)["']?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/mu)?.[1]??a[0].match(Ln)?.[0]}catch{return}}function Fn(e){let t=[],n=jn(zt.join(e,"package.json"));n&&t.push(...Mc(n).map(a=>({...a,source:"package.json"})));let i=jn(zt.join(e,"node_modules","@unbrained","pm-cli","package.json"))?.version;typeof i=="string"&&Jt(i)&&t.push({version:i,source:"installed-package",constraint:"exact",history_epoch_compatible:Ut(i)===3});let r=Gc(e);r&&Jt(r)&&t.push({version:r,source:"package-lock.json",constraint:"exact",history_epoch_compatible:Ut(r)===3});for(let a of["pnpm-lock.yaml","yarn.lock"]){let o=Uc(e,a);o&&t.push({version:o,source:a,constraint:"exact",history_epoch_compatible:Ut(o)===3})}return t}function Wr(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(qr.has(n)){t+=1;continue}if(!n.startsWith("-"))return{command:n.toLowerCase(),index:t}}}function zc(e){let t=Wr(e);if(!t||X(e,["--help","-h","--dry-run"]))return!1;let{command:n,index:i}=t,r=[];for(let o=i+1;o<e.length;o+=1){let s=e[o];if(qr.has(s)){o+=1;continue}s.startsWith("-")||r.push(s.toLowerCase())}let a=Dc[n];return a?a(e,r):Nc.has(n)}function Jc(e){let t=Wr(e.argv)?.command,n=zc(e.argv),i=Fn(e.projectRoot).filter(d=>Me(d.version,e.executingVersion)!==null).sort((d,p)=>Me(p.version,d.version)),r=i[0],a=r!==void 0&&Me(e.executingVersion,r.version)===-1,o=Ut(e.executingVersion),s=jc(i,o),l=n&&s!==void 0,c=a&&!n?{code:"project_runtime_stale_read",executing_version:e.executingVersion,project_version:r.version,source:r.source,message:"This read is using an older pm runtime than the project requires.",next_steps:[`Run the command through the project's installed ${pt} ${r.version}.`,"Install the project dependencies with its declared package manager if the local executable is missing."]}:void 0;return{compatible:!n||!a&&!l||e.allowStale===!0,executing_version:e.executingVersion,...r?{project_version:r.version,source:r.source}:{},...t?{command:t}:{},mutating:n,stale:a,history_epoch_incompatible:l,writer_item_hash_version:o,...s?{incompatible_project_version:s.declaration,incompatible_source:s.source}:{},...c?{warning:c}:{},override_applied:n&&(a||l)&&e.allowStale===!0}}function sh(e){let t=Jc(e);if(t.compatible)return t;throw t.history_epoch_incompatible?new f(`pm ${t.executing_version} cannot write item-hash epoch ${t.writer_item_hash_version} into a project pinned to pm ${t.incompatible_project_version}.`,h.CONFLICT,{code:"project_runtime_history_epoch_incompatible",reason:t.incompatible_source,why:`The pinned runtime cannot read item_hash_version ${t.writer_item_hash_version}; allowing the write would break its health and validation gates.`,nextSteps:[`Upgrade the project's ${pt} pin to ${qt} or newer before mutating tracker history.`,"For an intentional coordinated migration only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.","Read-only commands remain available without an override."]}):new f(`pm ${t.executing_version} cannot mutate a project pinned to newer pm ${t.project_version}.`,h.CONFLICT,{code:"project_runtime_stale_mutation",reason:t.source,why:"An older runtime can write storage, history, and merge contracts it does not understand.",nextSteps:[`Run this command through the project's installed ${pt} ${t.project_version}.`,"For an intentional recovery only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.","Read-only commands remain available without an override."]})}import{access as Kc,readFile as Un,realpath as Te}from"node:fs/promises";import{constants as Vc}from"node:fs";import{execFile as Yc}from"node:child_process";import P from"node:path";import{promisify as Xc}from"node:util";import{execFile as qc}from"node:child_process";import Wc from"node:path";import{promisify as Bc}from"node:util";import{setTimeout as Hc}from"node:timers/promises";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="f8f33f3d-854e-5cb4-b0bf-8d2d89da27e8")}catch{}})();var Gn=Bc(qc);async function Ye(e,t){let n=performance.now()+5e3,i=25;for(;;)try{await Gn("git",["config",...t],{cwd:e,env:{...ue(),LC_ALL:"C"},timeout:1e4});return}catch(r){let a=n-performance.now();if(typeof r!="object"||r===null||!("stderr"in r)||typeof r.stderr!="string"||!/could not lock config file [^\r\n]+: File exists/u.test(r.stderr)||a<=0)throw r;await Hc(Math.min(i,a)),i=Math.min(i*2,200)}}function ue(){let e={...process.env};for(let t of["GIT_DIR","GIT_WORK_TREE","GIT_COMMON_DIR","GIT_INDEX_FILE","GIT_OBJECT_DIRECTORY","GIT_ALTERNATE_OBJECT_DIRECTORIES","GIT_NAMESPACE","GIT_CEILING_DIRECTORIES","GIT_DISCOVERY_ACROSS_FILESYSTEM"])delete e[t];return e}async function Mn(e,t){try{return(await Gn("git",["config","--local",...t==="core.bare"||t==="extensions.worktreeConfig"?["--type=bool"]:[],"--get",t],{cwd:e,env:ue(),timeout:1e4})).stdout.trim()}catch(n){if(typeof n=="object"&&n!==null&&"code"in n&&n.code===1)return;throw n}}async function Br(e){if(await Mn(e,"extensions.worktreeConfig")==="true")return"--worktree";let{stdout:t}=await Gn("git",["rev-parse","--path-format=absolute","--git-dir","--git-common-dir"],{cwd:e,env:ue(),timeout:1e4}),[n,i]=t.trim().split(/\r?\n/);if(n===i)return"--local";let r=Wc.join(i,"config.worktree");for(let a of["core.bare","core.worktree"]){let o=await Mn(e,a);o===void 0||a==="core.bare"&&o!=="true"||(await Ye(e,["--file",r,a,o]),await Ye(e,["--local","--unset-all",a]))}for(let a of["pm-item-toon","pm-item-markdown","pm-history","pm-relationship","pm-json"])for(let o of["name","driver"]){let s=`merge.${a}.${o}`,l=await Mn(e,s);l!==void 0&&await Ye(e,["--file",r,s,l])}return await Ye(e,["--local","extensions.worktreeConfig","true"]),"--worktree"}(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]="98a35fdb-bff9-5556-9c1d-1c345cb39171")}catch{}})();var Ge=Xc(Yc),Wt="# pm-cli:merge-drivers:start",Zc="# pm-cli:merge-drivers:end",mt="# pm-cli:merge-drivers:v2:start",Vr="# pm-cli:merge-drivers:v2:end",Qc="merge-fence",el="merge-attributes";function Hr(e){return`'${e.replaceAll("'",`'"'"'`)}'`}async function tl(e,t){let n=await Te(e);if(/(?:^|[\\/])bun-node-[^\\/]+[\\/]bun(?:\.exe)?$/iu.test(n))return;let{stdout:i}=await Ge(e,["--version"],{encoding:"utf8",windowsHide:!0,timeout:1e4});return i.trim()===t?n:void 0}async function nl(){let e=pe(import.meta.url,["../../.."]),t=process.execPath,n=!1,i=await Te(process.execPath),r=process.versions.bun,a=(process.env.PATH??"").split(P.delimiter).filter(s=>P.isAbsolute(s)).map(s=>P.join(s,r===void 0?P.basename(process.execPath):process.platform==="win32"?"bun.exe":"bun")),o=r===void 0?a:[process.env.npm_execpath??"",...a,i].filter(s=>P.isAbsolute(s)&&/^(?:bun|bun\.exe)$/iu.test(P.basename(s)));for(let s of o)try{if(await Kc(s,Vc.X_OK),r!==void 0){let l=await tl(s,r);if(l!==void 0){t=l,n=!0;break}continue}if(s!==i&&await Te(s)===i){t=s;break}}catch{}if(r!==void 0&&!n)throw new f("Cannot install Bun merge drivers without a durable executable matching the current Bun version.",h.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`${Hr(t)} ${Hr(P.join(e,"dist","cli.js"))}`}var Yr=[{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 il(e){let t=e.explicitPath?.trim(),n=e.environment.PM_SOURCE_WORKSPACE_ROOT?.trim(),i=e.environment.PM_SOURCE_PM_PATH?.trim(),r=zr(e.environment),a=!!(n&&i),o=t===void 0&&a&&(e.dryRun||r.source_writes_allowed);if(t!==void 0){let s=N(e.cwd,t);return{pm_root:s,workspace_start:s,source_coordinates_available:a,source_context_selected:!1,source_policy:r}}return o?{pm_root:P.resolve(i),workspace_start:P.resolve(n),source_coordinates_available:!0,source_context_selected:!0,source_policy:r}:{pm_root:a?N(e.cwd,".agents/pm"):N(e.cwd),workspace_start:e.cwd,source_coordinates_available:a,source_context_selected:!1,source_policy:r}}async function Bt(e){try{let{stdout:t}=await Ge("git",["rev-parse","--show-toplevel"],{cwd:e,env:ue(),encoding:"utf8",windowsHide:!0,timeout:1e4});return await Te(t.trim())}catch{return null}}async function Xr(e){let t=await Bt(e);if(t===null)throw new f("pm merge install requires a git repository (merge drivers are git configuration).",h.USAGE);return t}function zn(e,t){return P.relative(e,t).replaceAll("\\","/")}function le(e){return`"${e.replaceAll("\\","\\\\").replaceAll('"','\\"')}"`}function Kr(e,t){if(e[t]!=="'")return null;let n="";for(let i=t+1;i<e.length;i+=1){if(e.startsWith(`'"'"'`,i)){n+="'",i+=4;continue}if(e[i]==="'")return{value:n,nextOffset:i+1};n+=e[i]}return null}async function rl(e,t,n){if(Fn(t).filter(r=>r.constraint==="exact").some(r=>r.version!==n))return!1;let i=await Bt(e);if(i!==null&&i!==await Te(t)){let r=await Promise.all([i,t].map(async a=>{let o=await Ge("git",["rev-parse","--path-format=absolute","--git-common-dir"],{cwd:a,env:ue(),timeout:1e4});return Te(o.stdout.trim())}));if(r[0]===r[1])return!1}return!0}async function al(e,t,n){let i=Kr(e,0);if(i===null||e[i.nextOffset]!==" ")return!1;let r=Kr(e,i.nextOffset+1);if(r===null||e.slice(r.nextOffset)!==t||!/^(?:node|bun)(?:\.exe)?$/iu.test(P.basename(i.value))||P.basename(r.value)!=="cli.js"||P.basename(P.dirname(r.value))!=="dist"||!await k(i.value)||!await k(r.value))return!1;try{let a=P.dirname(P.dirname(r.value)),o=JSON.parse(await Un(P.join(a,"package.json"),"utf8")),s=typeof o.bin=="string"?o.bin:o.bin?.pm;return await rl(a,n,o.version)?o.name==="@unbrained/pm-cli"&&s==="dist/cli.js":!1}catch{return!1}}function Jn(e,t){let n=e.length>0?`${e}/`:"",i=[`${le(`${n}**/*.toon`)} merge=pm-item-toon`,`${le(`${n}**/*.md`)} merge=pm-item-markdown`];for(let r of t)i.push(`${le(`${n}${r}/*.toon`)} merge=pm-item-toon`),i.push(`${le(`${n}${r}/*.md`)} merge=pm-item-markdown`);return i.push(`${le(`${n}**/*.jsonl`)} merge=pm-relationship`),i.push(`${le(`${n}history/*.jsonl`)} merge=pm-history`),i.push(`${le(`${n}settings.json`)} merge=pm-json`),i.push(`${le(`${n}**/*.json`)} merge=pm-json`),i.push(`${le(`${n}extensions/**`)} merge=text`),i.push(`${le(`${n}extensions/.managed-extensions.json`)} merge=pm-json`),i}function Zr(e){let t=[],n=0;for(;n<e.length;){let i=e.indexOf(Wt,n),r=e.indexOf(mt,n),a=i===-1?r:r===-1?i:Math.min(i,r);if(a===-1)break;let o=a===r,s=o?mt:Wt,l=o?Vr:Zc,c=e.indexOf(l,a+s.length),d=c===-1?e.length:c+l.length;t.push({start:a,end:d,closed:c!==-1,lines:e.slice(a+s.length,c===-1?d:c).split(`
|
|
9
9
|
`).map(p=>p.trim()).filter(Boolean)}),n=d}return t}function Qr(e,t,n){let i=new Set(t),r=le(n.length>0?`${n}/`:"").slice(0,-1);return e.some(a=>i.has(a)||a.startsWith(r)&&/^[^/]+\/\*\.(?:toon|md)" merge=pm-item-(?:toon|markdown)$/u.test(a.slice(r.length)))}async function ea(e,t,n,i){let r=P.join(e,".gitattributes"),a=i?null:(await Ge("git",["rev-parse","--absolute-git-dir"],{cwd:e,env:ue(),encoding:"utf8",windowsHide:!0,timeout:1e4})).stdout.trim(),o=a===null?null:await V(a,el,120,"merge-fence",!1,!0,5e3);try{let s=await G(r)??"",l=[mt,...n,Vr].join(`
|
|
10
10
|
`),c=Zr(s),d=c.filter(m=>Qr(m.lines,n,t));d.length===0&&t===".agents/pm"&&c.length===1&&c[0].lines.every(m=>!m.includes(".agents/pm/"))&&d.push(c[0]);let p;if(d.length>0){let m=d[0];p=s;for(let g of d.slice(1).reverse())p=`${p.slice(0,g.start)}${p.slice(g.end)}`;p=`${p.slice(0,m.start)}${l}${p.slice(m.end)}`}else{let m=s.trimEnd();p=`${m.length>0?`${m}
|
|
11
11
|
|
|
@@ -78,4 +78,4 @@ Agent guidance check
|
|
|
78
78
|
`),ee.write(`Telemetry helps improve reliability and can be disabled anytime via pm config.
|
|
79
79
|
`);let l=t?"Y/n":"y/N",c=await n.question(`Enable telemetry for this project? [${l}] `),d=Bs(c,t);return ee.write(`
|
|
80
80
|
`),{prefix:r,preset:s,telemetry_enabled:d}}finally{n.close()}}function bf(e){return{presetFromOption:Oi(e.preset),useDefaults:e.defaults===!0,authorFromOption:zs(e.author),installBundledPackages:e.withPackages===!0,agentGuidanceMode:Ws(e.agentGuidance),typePreset:Us(e.typePreset)}}function kf(e){let t=[];return e.prefixArg!==void 0&&e.settings.id_prefix!==e.normalizedPrefix&&t.push("id_prefix"),e.presetFromOption!==void 0&&e.settings.governance.preset!==e.presetFromOption&&t.push("governance_preset"),e.authorFromOption!==void 0&&e.settings.author_default!==e.authorFromOption&&t.push("author_default"),t}function xf(e,t,n,i){if(t.length===0||n)return;let r=i.discovery==="ancestor";throw new f(`${r?`No tracker exists in ${i.requested_cwd}; pm init found an ancestor tracker at ${i.tracker_root}. `:""}Refusing to update existing tracker settings at ${e} without --force.`,h.USAGE,{code:"init_existing_settings_requires_force",type:"urn:pm-cli:error:init_existing_settings_requires_force",required:`--force for ${t.join(", ")}`,why:r?"Ancestor discovery is useful for normal commands, but init must make the selected existing workspace explicit before changing its identity or policy settings.":"pm init is safe to rerun, but changing id prefix, governance preset, or default author on an existing tracker can corrupt long-lived project context when an agent meant to initialize a sandbox path.",resolved_path:i.tracker_root,requested_path:i.requested_cwd,suggested_path:i.suggested_current_tracker_root,examples:["pm init --yes","pm init ./sandbox-pm --yes",...r?['pm init <name> --yes --pm-path "$PWD/.agents/pm"']:[],"pm init acme --yes --force"],nextSteps:[...r?['To create a new tracker in the current directory, rerun with --pm-path "$PWD/.agents/pm".']:[],"If you meant to initialize a sandbox tracker, pass a path-like positional such as ./sandbox-pm or /tmp/pm-test.","If you intentionally want to rewrite this existing tracker's init-managed settings, rerun with --force."]})}function Sf(e){let t=!1;return e.prefixArg!==void 0&&e.settings.id_prefix!==e.normalizedPrefix&&(e.settings.id_prefix=e.normalizedPrefix,e.warnings.push(`updated:id_prefix:${e.normalizedPrefix}`),t=!0),e.presetFromOption!==void 0&&e.settings.governance.preset!==e.presetFromOption&&(Ci(e.settings,e.presetFromOption),e.warnings.push(`updated:governance_preset:${e.presetFromOption}`),t=!0),e.authorFromOption!==void 0&&e.settings.author_default!==e.authorFromOption&&(e.settings.author_default=e.authorFromOption,e.warnings.push(`updated:author_default:${e.authorFromOption}`),t=!0),t}async function Ef(e){let t=await A(e.pmRoot);e.warnings.push(`already_exists:${e.settingsPath}`);let n=kf({settings:t,normalizedPrefix:e.normalizedPrefix,prefixArg:e.prefixArg,presetFromOption:e.normalizedOptions.presetFromOption,authorFromOption:e.normalizedOptions.authorFromOption});return xf(e.settingsPath,n,e.options.force===!0,e.target),Sf({settings:t,normalizedPrefix:e.normalizedPrefix,prefixArg:e.prefixArg,presetFromOption:e.normalizedOptions.presetFromOption,authorFromOption:e.normalizedOptions.authorFromOption,warnings:e.warnings})&&await Ee(e.pmRoot,t),{settings:t,normalizedPrefix:e.normalizedPrefix,chosenPreset:e.normalizedOptions.presetFromOption,wizardUsed:!1}}async function $f(e){let t=e.normalizedPrefix,n=e.normalizedOptions.presetFromOption,i,r=!1;if(e.normalizedOptions.presetFromOption===void 0&&!e.normalizedOptions.useDefaults&&process.stdin.isTTY===!0&&process.stdout.isTTY===!0){let l=await Zs(t,vn.telemetry.enabled);t=l.prefix,n=l.preset,i=l.telemetry_enabled,r=!0}let a=n??"minimal",o=_f();o.id_prefix=t,Ci(o,a);let s=lr()?.trim()||void 0;return o.author_default=e.normalizedOptions.authorFromOption??s??"",i!==void 0&&(o.telemetry.enabled=i,o.telemetry.first_run_prompt_completed=!0),await Ee(e.pmRoot,o),{settings:o,normalizedPrefix:t,chosenPreset:n,wizardUsed:r}}async function Ls(e){return e.settingsExists?await Ef(e):await $f({pmRoot:e.pmRoot,normalizedPrefix:e.normalizedPrefix,normalizedOptions:e.normalizedOptions})}async function If(e){let t=await js({pm_root:e.pmRoot,cwd:e.cwd,mode:e.agentGuidanceMode,interactive:process.stdin.isTTY===!0&&process.stdout.isTTY===!0,settings:e.settings});return e.warnings.push(...t.warnings),t.settings_changed&&await Ee(e.pmRoot,e.settings),{...t.summary,next_steps:t.next_steps}}async function Af(e,t){let n=[],i=[],r=await cr(e,t.schema);for(let a of r.created_paths)n.push(a),i.push(...await H({path:a,scope:"project",op:"init:runtime_schema_file"}));return{createdDirs:n,warnings:i}}async function Tf(e){if(e.typePreset===void 0)return;let t=await Ks(e.pmRoot,e.settings,e.typePreset);return e.warnings.push(`registered_type_preset:${e.typePreset}`),e.warnings.push(...await H({path:t.file,scope:"project",op:"init:type_preset"})),t}async function Of(e){let t=U(e.settings,W()).folders.filter(i=>!wn.includes(i)),n=await Xs(e.pmRoot,t);e.createdDirs.push(...n.createdDirs),e.warnings.push(...n.warnings)}function Cf(e){let t=F.resolve(e.tracker_root),n=F.dirname(t);return F.basename(t)==="pm"&&F.basename(n)===".agents"?F.dirname(n):e.workspace_root}async function Pf(e,t,n,i){if(!e)return;let r=await bi("all",{install:!0,project:!0},{...t,path:n});i.push(...r.warnings);let a=Hs(r),o=a.packages.filter(s=>!s.ok).map(s=>s.alias);if(!a.installed_all||o.length>0)throw new f(`pm init --with-packages did not install all bundled packages successfully${o.length>0?`: ${o.join(", ")}`:"."}`,h.GENERIC_FAILURE);return a}function Qs(e){let t=i=>st([...e.target.mode==="workspace-discovery"?[]:["--pm-path",e.target.tracker_root],...i]),n=[`Create your first item: ${t(["create","--type","Task","--title","<title>"])}`,`List active items: ${t(["list"])}`,`Get agent-friendly project context: ${t(["context"])}`];e.installBundledPackages?n.push(`Explore newly-available commands: ${t(["cal"])}, ${t(["templates"])}, ${t(["guide"])}`):(n.push(`Add optional packages for richer workflows: ${t(["install","calendar","--project"])}, ${t(["install","templates","--project"])}, ${t(["install","guide-shell","--project"])}`),n.push(`Or install everything bundled: ${t(["init","--with-packages"])} (idempotent on re-run)`)),e.registeredTypePreset&&n.push(`Inspect registered preset types: ${t(["schema","list"])}, ${t(["schema","show",e.registeredTypePreset.registered[0]??e.registeredTypePreset.updated[0]])}`),n.push("Supported agent harnesses are attributed automatically; use --author or PM_AUTHOR only when an explicit identity override is required.");for(let i of e.agentGuidanceNextSteps){let r=e.target.mode==="workspace-discovery"?i:i.replace(/\bpm (?=[a-z])/g,()=>`${t([])} `);n.includes(r)||n.push(r)}return n}async function ec(e,t,n,i=qn){if(t===null){n.push("merge_fence_skipped:not_git_repository:run pm merge install after moving the tracker into a Git repository");return}try{let r=await i({pmRoot:e,workspaceRoot:t});r.gitattributes.changed&&n.push(`updated:merge_fence:${r.gitattributes.path}`)}catch(r){if(!(r instanceof f))throw r;n.push(`merge_fence_skipped:install_failed:${r.context.code??"pm_error"}:${r.message}:run pm merge install after resolving the Git repository error`)}}async function Rf(e,t,n,i){if(e==null||n==="status")return;let r=await Gr(e,{pmRoot:t});r.changed&&i.push(`updated:gitignore:${r.path}`)}async function Gb(e,t,n={}){let i=t[gf],r=typeof i=="string"?i:process.cwd(),a=Js(r,t,e,n.workspace),o=a.pmRoot;e=qs(a.prefixArg,n.idPrefix);let s=bf(n);await Ys(o,a.target.mode==="tracker-path",n.force===!0);let l=[],c=[],d=F.join(o,"settings.json"),p=await k(d),m;p&&(m=await Ls({pmRoot:o,settingsPath:d,settingsExists:p,normalizedPrefix:$e(e),prefixArg:e,options:n,normalizedOptions:s,warnings:c,target:a.target}));let g=await Xs(o,wn);l.push(...g.createdDirs),c.push(...g.warnings),m??=await Ls({pmRoot:o,settingsPath:d,settingsExists:p,normalizedPrefix:$e(e),prefixArg:e,options:n,normalizedOptions:s,warnings:c,target:a.target});let{settings:y}=m,_=Cf(a.target),u=await Bt(_??F.dirname(o)),w=_??u,v=await If({pmRoot:o,cwd:w??r,agentGuidanceMode:s.agentGuidanceMode,settings:y,warnings:c}),x=await Af(o,y);l.push(...x.createdDirs),c.push(...x.warnings);let S=await Tf({pmRoot:o,settings:y,typePreset:s.typePreset,warnings:c});S&&(y=await A(o)),await Of({pmRoot:o,settings:y,createdDirs:l,warnings:c}),await Rf(w,o,s.agentGuidanceMode,c),!p&&n.mergeFence!==!1&&s.agentGuidanceMode!=="status"&&await ec(o,u,c);let O=await Pf(s.installBundledPackages,t,o,c),ae=Qs({installBundledPackages:s.installBundledPackages,registeredTypePreset:S,agentGuidanceNextSteps:v.next_steps,target:a.target});return{ok:!0,path:o,target:a.target,settings:y,created_dirs:l,warnings:c,governance_preset:y.governance.preset,wizard_used:m.wizardUsed,...S?{registered_type_preset:S}:{},...O?{installed_packages:O}:{},next_steps:ae,agent_guidance:v}}export{Tn as a,mc as b,Pr as c,Pn as d,xc as e,Sc as f,Ec as g,Dr as h,Yp as i,Lr as j,Rn as k,Ac as l,Oc as m,Gr as n,Ve as o,Pc as p,Rc as q,zr as r,qt as s,Me as t,Ut as u,Fn as v,zc as w,Jc as x,sh as y,Wt as z,Zc as A,mt as B,Vr as C,il as D,Bt as E,Jn as F,ta as G,Dh as H,jh as I,na as J,Lh as K,qn as L,ga as M,Qe as N,et as O,ya as P,ua as Q,Xe as R,Ze as S,fa as T,sl as U,Gh as V,qh as W,ra as X,dl as Y,sg as Z,xa as _,Ia as $,Vl as aa,Yl as ba,lw as ca,mw as da,uw as ea,$t as fa,fw as ga,hw as ha,gw as ia,yw as ja,_w as ka,ww as la,vw as ma,bw as na,kw as oa,xw as pa,Sw as qa,Ew as ra,$w as sa,Iw as ta,Aw as ua,Tw as va,Ow as wa,Cw as xa,Pw as ya,Rw as za,Nw as Aa,Dw as Ba,jw as Ca,Lw as Da,Fw as Ea,te as Fa,b as Ga,Xn as Ha,ud as Ia,he as Ja,Vt as Ka,Xl as La,ft as Ma,Yt as Na,za as Oa,Xa as Pa,di as Qa,po as Ra,t_ as Sa,_m as Ta,Wo as Ua,Bo as Va,gi as Wa,xo as Xa,Wp as Ya,Rm as Za,Eo as _a,bi as $a,Ss as ab,fb as bb,js as cb,gf as db,Fb as eb,Mb as fb,Gb as gb};
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
81
|
+
//# sourceMappingURL=chunk-LE4IEHDG.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{e as k,g as I,h as A,i as _,o as T,q as C}from"./chunk-
|
|
1
|
+
import{e as k,g as I,h as A,i as _,o as T,q as C}from"./chunk-66BZVFIK.js";import{Eb as b,Fb as v,Gb as R}from"./chunk-UNQZGMJL.js";import{Ap as w,Qf as D,R as c,T as p,Tf as m,Tn as H,Uf as y,fp as f,hm as x,ip as g,jp as a,rd as E}from"./chunk-IDEHMKYZ.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]="a178bd8b-fc53-5633-84d5-621b61930581")}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 x(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 C(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?(E(r),o.quiet||D(`${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 string to redact (repeatable)",g).option("--regex <value>","Regex pattern to redact (repeatable; accepts /pattern/flags or raw pattern)",g).option("--replacement <value>",'Replacement string (default: "[redacted]")').option("--dry-run","Preview redaction impact without writing item/history files").option("--author <value>","Mutation author").option("--message <value>","Audit history message for the redaction marker entry").option("--force","Force ownership/lock override").description("Redact sensitive literals/patterns from an item history stream and recompute hashes.").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 _(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-LKESCZEN.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Rb as Te,Sb as ve,Ub as U,Xb as Ae,Ya as Se,Zb as Re,_b as be,a as te,uc as Ie}from"./chunk-UBTYYZIE.js";import{yc as Ee}from"./chunk-PSNS537F.js";import{b as me,c as C}from"./chunk-YH6H3UVE.js";import{Bk as ye,F as x,Gi as le,I as S,Ii as ue,L as K,Q as V,Qo as ge,R as p,Sg as ce,T as d,To as _e,Va as q,Vl as he,X as $,Xl as we,Z as Y,_ as T,cb as H,hc as Z,ig as re,kg as ne,ld as Q,lg as ie,md as ee,og as oe,pi as pe,rh as de,sg as ae,tb as X,ug as se,vk as fe}from"./chunk-DJDRHJBP.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]="4175f7f5-a689-5d05-982a-f92e21bc83e7")}catch{}})();import Xe 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]="7599b1e6-1f28-597a-adda-ad856beb35bd")}catch{}})();var D=["op","id","reason","options"],Me=[...D,"ref"],Oe=["schema_version","mutations"],Pe="[a-z][a-z0-9._-]{0,63}",ke=new RegExp(`^${Pe}$`,"u"),je=new RegExp(`(^|,)id=@(${Pe})(?=,|$)`,"gu"),Ne=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),A=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],Fe=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Ze=new Set([...Fe,"completed_at","id"]),v=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...x,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]),$e={create:ge.map(e=>e.target),update:_e.map(e=>e.target),close:fe.map(e=>Ne(e.flag)).filter(e=>e!=="reason"),release:ye.map(e=>Ne(e.flag))};function vr(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new d("createCompensation must be close or delete.",p.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.`,p.USAGE);t[r]=o}return t}function f(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function R(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=Z(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function w(e,t,n){let r=R(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}"?`,p.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 P(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}`,p.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 Qe(e,t){if(!f(e))throw new d(`Mutation ${t+1} must be an object.`,p.USAGE);for(let n of Object.keys(e))if(!D.includes(n))throw w(`mutation ${t+1}`,n,D);return e}function et(e,t,n){if(e!==void 0){if(!f(e))throw new d(`Mutation ${n+1} options must be an object.`,p.USAGE);for(let r of Object.keys(e))if(!$e[t].includes(r))throw w(`mutation ${n+1} ${t} options`,r,$e[t]);return e}}function tt(e,t){let n=Qe(e,t),{op:r,id:i,reason:o}=n;if(r!=="create"&&r!=="update"&&r!=="close"&&r!=="release")throw new d(`Mutation ${t+1} op must be create, update, close, or release.`,p.USAGE);let s=et(n.options,r,t);if(typeof i!="string"||i.trim().length===0)throw new d(`Mutation ${t+1} requires a non-empty id.`,p.USAGE);let a=i.trim();if(r==="close"){if(typeof o!="string"||o.trim().length===0)throw new d(`Mutation ${t+1} close requires a non-empty reason.`,p.USAGE);return{op:r,id:a,reason:o.trim(),...s===void 0?{}:{options:s}}}if(r==="release")return{op:r,id:a,...s===void 0?{}:{options:s}};if(!f(s))throw new d(`Mutation ${t+1} ${r} requires an options object.`,p.USAGE);return{op:r,id:a,options:s}}function Ge(e){let t=P(e,"Mutation batch"),n=Array.isArray(t)?t:f(t)&&Array.isArray(t.mutations)?t.mutations:void 0;if(n===void 0||n.length===0)throw new d("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",p.USAGE);return n.map((r,i)=>{let o=tt(r,i);return o.options!==void 0&&he(o.options),o})}function rt(e,t,n){let r=Xe.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`${le(n)}${i}`}function Ce(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}".`,p.USAGE);return r}function Ue(e,t){if(typeof e!="string")return e;let n=e.replace(je,(r,i,o)=>{let s=t[o];if(s===void 0)throw new d(`Unknown mutation reference "@${o}".`,p.USAGE);return`${i}id=${s}`});if(/(^|,)id=@/u.test(n))throw new d(`Malformed mutation reference in dependency "${e}".`,p.USAGE);return n}function nt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(je)].map(t=>t[1]).filter(t=>t!==void 0)}function it(e){let t=new Map;for(let o of e){if(o.op!=="create"||typeof o.ref!="string")continue;let s=f(o.options)?o.options:{},a=Array.isArray(s.dep)?s.dep:s.dep===void 0?[]:[s.dep];t.set(o.ref,[s.parent,s.blockedBy,...a].flatMap(nt))}let n=new Set,r=new Set,i=o=>{if(n.has(o))throw new d(`Mutation reference cycle includes "@${o}".`,p.USAGE);if(!r.has(o)){n.add(o);for(let s of t.get(o))t.has(s)&&i(s);n.delete(o),r.add(o)}};for(let o of t.keys())i(o)}function ot(e){let t=P(e,"Mutation document"),n=Array.isArray(t)?{schema_version:1,mutations:t}:t;if(!f(n))throw new d("Mutation document must be a JSON array or object.",p.USAGE);for(let r of Object.keys(n))if(!Oe.includes(r))throw w("mutation document",r,Oe);if(n.schema_version!==void 0&&n.schema_version!==1)throw new d("Mutation document schema_version must be 1.",p.USAGE);if(!Array.isArray(n.mutations)||n.mutations.length===0)throw new d("Mutation document requires a non-empty mutations array.",p.USAGE);return n.mutations.map((r,i)=>{if(!f(r))throw new d(`Mutation ${i+1} must be an object.`,p.USAGE);for(let o of Object.keys(r))if(!Me.includes(o))throw w(`mutation ${i+1}`,o,Me);return{...r}})}function at(e,t){let n=Object.create(null);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.`,p.USAGE);if(typeof i.ref!="string"||!ke.test(i.ref))throw new d(`Mutation ${r+1} ref must match ${ke.source}.`,p.USAGE);if(n[i.ref]!==void 0)throw new d(`Duplicate mutation ref "${i.ref}".`,p.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?ue(i.id,t.idPrefix):rt(t.transactionId,i.ref,t.idPrefix)}return n}function Ar(e,t){let n=ot(e),r=at(n,t);it(n);let i=n.map(a=>{let c={...a},l=typeof c.ref=="string"?c.ref:void 0;if(delete c.ref,l!==void 0?c.id=r[l]:c.id=Ce(c.id,r),f(c.options)){let m={...c.options};for(let y of["parent","blockedBy"])m[y]!==void 0&&(m[y]=Ce(m[y],r));Array.isArray(m.dep)?m.dep=m.dep.map(y=>Ue(y,r)):m.dep!==void 0&&(m.dep=Ue(m.dep,r)),c.options=m}return c}),o=Ge(JSON.stringify(i)),s=o.filter(a=>a.op==="create").map(a=>a.id);if(new Set(s).size!==s.length)throw new d("Duplicate resolved create id in mutation document.",p.USAGE);return{schema_version:1,mutations:o,references:r}}function st(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 ct(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(f))throw new d(`${n} must be an array of objects.`,p.USAGE);return e.map(r=>st(r,t))}}function dt(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 De(e,t,n=!1){for(let[r,i,o]of Ee){let s=t[r],a=ct(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(s)?s.filter(c=>!f(c)||c.created_at===void 0):s,o,r);a!==void 0&&a.length>0&&(e[i]=a)}}function pt(e,t){for(let n of Object.keys(e)){if(t){if(!A.includes(n))throw w("item envelope",n,A);continue}if(!v.has(n)&&R(n,[...v])===void 0&&R(n,A)==="item")throw w("item envelope",n,A)}}function lt(e){let t=Object.hasOwn(e,"item");pt(e,t);let n=t?e.item:e;if(!f(n))throw new d("Item document item must be an object.",p.USAGE);return{item:n,...t&&f(e.linked)?{linked:e.linked}:{}}}function ut(e,t,n,r,i,o){if((r==="update"?Ze:Fe).has(t))return;let s=i.find(a=>a.metadata_key===t&&a.commands.includes(r));if(s!==void 0){let a=se(o,s);e[ae(s)]=a!==void 0?a:s.type==="array"||s.type==="object"?JSON.stringify(n):n;return}if(!v.has(t)){if(R(t,[...v])!==void 0)throw w("item document",t,[...v]);let a=Array.isArray(e.field)?e.field:[];a.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=a;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(a,c)=>c.toUpperCase())]=dt(t,n))}function Rr(e,t,n={},r=[]){let i=P(e,"Item document");if(!f(i))throw new d("Item document must be a JSON object.",p.USAGE);let{item:o,linked:s}=lt(i),a={};for(let[c,l]of Object.entries(o))ut(a,c,l,t,r,n);if(De(a,o,t==="update"),s!==void 0&&De(a,s),t==="update"){let c=Object.fromEntries(["comments","notes","learnings"].filter(l=>Object.hasOwn(o,l)).map(l=>[l,o[l].filter(m=>f(m)&&m.created_at!==void 0)]));Object.keys(c).length>0&&(a.documentAnnotationSnapshot=c)}return{...a,...Object.fromEntries(Object.entries(n).filter(([,c])=>c!==void 0)),...Array.isArray(a.field)&&Array.isArray(n.field)?{field:[...a.field,...n.field]}:{},stdinJson:void 0}}function br(e){return Ge(JSON.stringify(e))}import W from"node:crypto";import{constants as j}from"node:fs";import{cp as mt,lstat as Le,mkdir as ft,mkdtemp as yt,open as ht,readdir as wt,realpath as gt,rm as _t,stat as We,writeFile as ze}from"node:fs/promises";import{tmpdir as Et}from"node:os";import u 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]="7ff78f44-c9db-5221-b09a-32b78876b461")}catch{}})();function M(e,t){let n={...e,...t};return e===void 0?n:we(e,n)}async function h(e,t){try{let n=(await Se(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===p.NOT_FOUND)return;throw n}}function z(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=W.createHash("sha256").update(X(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function St(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function g(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function O(e,t,n,r){let i=await de(u.join(e,"history",`${t}.jsonl`),t),o=g(n,r,"apply"),s=g(n,r,"compensate");for(let a=i.length-1;a>=0;a-=1){let c=i[a].message;if(c===o)return!0;if(c===s)return!1}return!1}async function B(e,t){let n=await h(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`,p.NOT_FOUND);return{target_updated_at:n.updatedAt}}async function k(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r.target_updated_at:void 0;typeof i=="string"&&await h(e.pmRoot,t)!==void 0&&await be(t,i,{force:!0,author:e.author,message:g(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot})}function Be(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"create"}}},async apply(){let r=(await Te(M(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"create"}},async compensate(){let r=await h(e.pmRoot,t.id);if(r!==void 0){if(e.createCompensation==="delete"){await Re(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}r.closedAt===void 0&&await U(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function Tt(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await O(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return B(e.pmRoot,t)},async apply(){let r=(await ve(t.id,M(t.options,{author:e.author,message:g(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"update"}},async compensate(r){await k(e,t.id,n,r)}}}function vt(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await O(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 B(e.pmRoot,t)},async apply(){let r=(await U(t.id,t.reason,M(t.options,{author:e.author,message:g(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"close"}},async compensate(r){await k(e,t.id,n,r)}}}function At(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await O(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 B(e.pmRoot,t)},async apply(){let r=(await Ae(t.id,M(t.options,{author:e.author,message:g(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"release"}},async compensate(r){await k(e,t.id,n,r)}}}function Je(e,t,n){let r=z(t,n);switch(t.op){case"create":return Be(e,t,r);case"update":return Tt(e,t,r);case"close":return vt(e,t,r);case"release":return At(e,t,r)}}function xe(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`)}async function F(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 Ke(e,t,n,r){let i=u.relative(e,t);return["locks","runtime","search"].includes(i.split(u.sep)[0])?r.some(o=>i===o||i.startsWith(`${o}${u.sep}`)||o.startsWith(`${i}${u.sep}`)):i===""||n===void 0||n.some(o=>i===o||i.startsWith(`${o}${u.sep}`)||o.startsWith(`${i}${u.sep}`))}async function I(e){let t=await Le(e);if(t.isSymbolicLink())await We(e);else if(t.isDirectory()||t.isFile())return t;throw T()}async function Rt(e){let t=await ht(e,j.O_RDONLY|j.O_NOFOLLOW|j.O_NONBLOCK);try{let n=await t.stat();if(!n.isFile())throw T();let r=W.createHash("sha256");if(n.size>0)for await(let i of t.createReadStream({highWaterMark:64*1024,end:n.size-1,autoClose:!1}))r.update(i);return r.digest()}finally{await t.close()}}async function G(e,t,n){let r=W.createHash("sha256");async function i(o){for(let s of(await wt(o)).sort()){let a=u.join(o,s);Ke(e,a,t,n)&&((await I(a)).isDirectory()?await i(a):(r.update(JSON.stringify(u.relative(e,a))),r.update(await Rt(a))))}}return await i(e),r.digest("hex")}function L(){return new d("Tracker changed while preparing the transaction preview; retry against stable state.",p.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function Ve(e){if(!$(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=u.resolve(t),r=n;for(;;)try{let i=await Le(r);return r!==n&&i.isDirectory()}catch(i){if(!$(i))return!1;let o=u.dirname(r);if(o===r)return!1;r=o}}async function b(e,t){let n=u.join(e,t);try{let r=e;for(let i of t.split(u.sep).slice(0,-1))r=u.join(r,i),await I(r);if(!(await I(n)).isFile())throw T();return await Y(n,T())}catch(r){if(await Ve(r))return;throw r}}async function bt(e,t,n){let r=new Map,i=await b(e,S);r.set(S,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let s=pe(o),a=s.success?s.data:void 0,c=ne(a?.schema);for(let[E,He]of Object.entries(c.files)){let _=u.relative(e,ie(e,He,re[E]));if(_===""||!u.resolve(e,_).startsWith(u.join(e,u.sep)))throw new d("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",p.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${E}`});c.files[E]=_;let N=await b(e,_);if(r.set(_,N),N!==void 0){let J=u.join(t,_);await ft(u.dirname(J),{recursive:!0}),await ze(J,N)}}let l=u.relative(e,ce(e));r.set(l,await b(e,l));let m=await oe(t,c),y=q({...V,item_types:{definitions:[...a?.item_types?.definitions??[],...m.type_definitions_from_file??[]]}},n),Ye=H(e)===e?[...K.filter(Boolean),S,te,"transactions",...y.folders,...r.keys()].map(E=>u.normalize(E)):void 0,qe=a===void 0?void 0:JSON.stringify({...o,schema:{...a.schema,files:c.files}});return{configuration:r,ownedPaths:Ye,stagedSettings:qe,registryFolders:y.folders}}async function It(e,t,n){await We(e);try{let r=await gt(e),i=await bt(r,u.join(u.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(l=>u.normalize(l)),s=await G(r,i.ownedPaths,o);await mt(r,t,{recursive:!0,dereference:!1,filter:async l=>Ke(r,l,i.ownedPaths,o)?(await I(l),!0):!1});let[a,c]=await Promise.all([G(r,i.ownedPaths,o),G(t,i.ownedPaths,o)]);if(s!==a||s!==c)throw L();for(let[l,m]of i.configuration)if(await b(t,l)!==m)throw L();i.stagedSettings!==void 0&&await ze(u.join(t,S),i.stagedSettings)}catch(r){throw await Ve(r)?L():r}}async function Yr(e){let t=me(e),n=[...e.mutations];if(n.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");for(let[s,a]of n.entries())xe(a,s);let r=ee(),i=await yt(u.join(Et(),"pm-transaction-preview-")),o=u.join(i,"tracker");try{await It(t.pmRoot,o,r);let s=!1;return await Ie({path:o,noExtensions:!0},async()=>{Q(r);let a={...t,pmRoot:o,createCompensation:"close"},c=n.map((l,m)=>{let y=Je(a,l,m);return{...y,inspect:()=>F(l,m,()=>y.inspect()),prepareCompensation:()=>F(l,m,async()=>y.prepareCompensation?.()),apply:()=>F(l,m,()=>y.apply())}});await C({...t,pmRoot:o,steps:c,onTransition:({transition:l})=>{l==="committed"&&(s=!0)}})}),{validated:s,state:s?"staged_snapshot":"replayed_committed_plan",unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks"]}}finally{await _t(i,{recursive:!0,force:!0})}}async function Mt(e){let t=[...e.mutations];if(t.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");for(let[s,a]of t.entries())xe(a,s);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let r={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n},i=await C({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((s,a)=>Je(r,s,a)),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),o={};for(let[s,a]of t.entries()){let c=z(a,s),l=i.results[c];o[St(a,s)]=l}return{transactionId:i.transactionId,status:"committed",recovered:i.recovered,results:o}}function Ot(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 qr(e){return Mt({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:Ot(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Hr={buildCreateStep:Be,bulkHistoryMarker:g,compensateByRestore:k,deriveStepId:z,isUpdateMarkerApplied:O,readItemSnapshot:h};export{vr as a,Ge as b,Ar as c,Rr as d,br as e,Yr as f,Mt as g,Ot as h,qr as i,Hr as j};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{Rb as Te,Sb as ve,Ub as U,Xb as Ae,Ya as Se,Zb as Re,_b as be,a as te,uc as Ie}from"./chunk-JTF6VMXH.js";import{yc as Ee}from"./chunk-PP3BVMFL.js";import{b as me,c as C}from"./chunk-LE4IEHDG.js";import{Dk as ye,F as x,I as S,Ii as le,Ki as ue,L as K,Q as V,R as p,T as d,Ug as ce,Uo as ge,Va as q,X as $,Xl as he,Xo as _e,Z as Y,Zl as we,_ as T,cb as H,hc as Z,kg as re,mg as ne,nd as Q,ng as ie,od as ee,qg as oe,ri as pe,tb as X,th as de,ug as ae,wg as se,xk as fe}from"./chunk-IDEHMKYZ.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]="4175f7f5-a689-5d05-982a-f92e21bc83e7")}catch{}})();import Xe 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]="7599b1e6-1f28-597a-adda-ad856beb35bd")}catch{}})();var D=["op","id","reason","options"],Me=[...D,"ref"],Oe=["schema_version","mutations"],Pe="[a-z][a-z0-9._-]{0,63}",ke=new RegExp(`^${Pe}$`,"u"),je=new RegExp(`(^|,)id=@(${Pe})(?=,|$)`,"gu"),Ne=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),A=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],Fe=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Ze=new Set([...Fe,"completed_at","id"]),v=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...x,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]),$e={create:ge.map(e=>e.target),update:_e.map(e=>e.target),close:fe.map(e=>Ne(e.flag)).filter(e=>e!=="reason"),release:ye.map(e=>Ne(e.flag))};function vr(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new d("createCompensation must be close or delete.",p.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.`,p.USAGE);t[r]=o}return t}function f(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function R(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=Z(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function w(e,t,n){let r=R(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}"?`,p.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 P(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}`,p.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 Qe(e,t){if(!f(e))throw new d(`Mutation ${t+1} must be an object.`,p.USAGE);for(let n of Object.keys(e))if(!D.includes(n))throw w(`mutation ${t+1}`,n,D);return e}function et(e,t,n){if(e!==void 0){if(!f(e))throw new d(`Mutation ${n+1} options must be an object.`,p.USAGE);for(let r of Object.keys(e))if(!$e[t].includes(r))throw w(`mutation ${n+1} ${t} options`,r,$e[t]);return e}}function tt(e,t){let n=Qe(e,t),{op:r,id:i,reason:o}=n;if(r!=="create"&&r!=="update"&&r!=="close"&&r!=="release")throw new d(`Mutation ${t+1} op must be create, update, close, or release.`,p.USAGE);let s=et(n.options,r,t);if(typeof i!="string"||i.trim().length===0)throw new d(`Mutation ${t+1} requires a non-empty id.`,p.USAGE);let a=i.trim();if(r==="close"){if(typeof o!="string"||o.trim().length===0)throw new d(`Mutation ${t+1} close requires a non-empty reason.`,p.USAGE);return{op:r,id:a,reason:o.trim(),...s===void 0?{}:{options:s}}}if(r==="release")return{op:r,id:a,...s===void 0?{}:{options:s}};if(!f(s))throw new d(`Mutation ${t+1} ${r} requires an options object.`,p.USAGE);return{op:r,id:a,options:s}}function Ge(e){let t=P(e,"Mutation batch"),n=Array.isArray(t)?t:f(t)&&Array.isArray(t.mutations)?t.mutations:void 0;if(n===void 0||n.length===0)throw new d("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",p.USAGE);return n.map((r,i)=>{let o=tt(r,i);return o.options!==void 0&&he(o.options),o})}function rt(e,t,n){let r=Xe.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`${le(n)}${i}`}function Ce(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}".`,p.USAGE);return r}function Ue(e,t){if(typeof e!="string")return e;let n=e.replace(je,(r,i,o)=>{let s=t[o];if(s===void 0)throw new d(`Unknown mutation reference "@${o}".`,p.USAGE);return`${i}id=${s}`});if(/(^|,)id=@/u.test(n))throw new d(`Malformed mutation reference in dependency "${e}".`,p.USAGE);return n}function nt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(je)].map(t=>t[1]).filter(t=>t!==void 0)}function it(e){let t=new Map;for(let o of e){if(o.op!=="create"||typeof o.ref!="string")continue;let s=f(o.options)?o.options:{},a=Array.isArray(s.dep)?s.dep:s.dep===void 0?[]:[s.dep];t.set(o.ref,[s.parent,s.blockedBy,...a].flatMap(nt))}let n=new Set,r=new Set,i=o=>{if(n.has(o))throw new d(`Mutation reference cycle includes "@${o}".`,p.USAGE);if(!r.has(o)){n.add(o);for(let s of t.get(o))t.has(s)&&i(s);n.delete(o),r.add(o)}};for(let o of t.keys())i(o)}function ot(e){let t=P(e,"Mutation document"),n=Array.isArray(t)?{schema_version:1,mutations:t}:t;if(!f(n))throw new d("Mutation document must be a JSON array or object.",p.USAGE);for(let r of Object.keys(n))if(!Oe.includes(r))throw w("mutation document",r,Oe);if(n.schema_version!==void 0&&n.schema_version!==1)throw new d("Mutation document schema_version must be 1.",p.USAGE);if(!Array.isArray(n.mutations)||n.mutations.length===0)throw new d("Mutation document requires a non-empty mutations array.",p.USAGE);return n.mutations.map((r,i)=>{if(!f(r))throw new d(`Mutation ${i+1} must be an object.`,p.USAGE);for(let o of Object.keys(r))if(!Me.includes(o))throw w(`mutation ${i+1}`,o,Me);return{...r}})}function at(e,t){let n=Object.create(null);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.`,p.USAGE);if(typeof i.ref!="string"||!ke.test(i.ref))throw new d(`Mutation ${r+1} ref must match ${ke.source}.`,p.USAGE);if(n[i.ref]!==void 0)throw new d(`Duplicate mutation ref "${i.ref}".`,p.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?ue(i.id,t.idPrefix):rt(t.transactionId,i.ref,t.idPrefix)}return n}function Ar(e,t){let n=ot(e),r=at(n,t);it(n);let i=n.map(a=>{let c={...a},l=typeof c.ref=="string"?c.ref:void 0;if(delete c.ref,l!==void 0?c.id=r[l]:c.id=Ce(c.id,r),f(c.options)){let m={...c.options};for(let y of["parent","blockedBy"])m[y]!==void 0&&(m[y]=Ce(m[y],r));Array.isArray(m.dep)?m.dep=m.dep.map(y=>Ue(y,r)):m.dep!==void 0&&(m.dep=Ue(m.dep,r)),c.options=m}return c}),o=Ge(JSON.stringify(i)),s=o.filter(a=>a.op==="create").map(a=>a.id);if(new Set(s).size!==s.length)throw new d("Duplicate resolved create id in mutation document.",p.USAGE);return{schema_version:1,mutations:o,references:r}}function st(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 ct(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(f))throw new d(`${n} must be an array of objects.`,p.USAGE);return e.map(r=>st(r,t))}}function dt(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 De(e,t,n=!1){for(let[r,i,o]of Ee){let s=t[r],a=ct(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(s)?s.filter(c=>!f(c)||c.created_at===void 0):s,o,r);a!==void 0&&a.length>0&&(e[i]=a)}}function pt(e,t){for(let n of Object.keys(e)){if(t){if(!A.includes(n))throw w("item envelope",n,A);continue}if(!v.has(n)&&R(n,[...v])===void 0&&R(n,A)==="item")throw w("item envelope",n,A)}}function lt(e){let t=Object.hasOwn(e,"item");pt(e,t);let n=t?e.item:e;if(!f(n))throw new d("Item document item must be an object.",p.USAGE);return{item:n,...t&&f(e.linked)?{linked:e.linked}:{}}}function ut(e,t,n,r,i,o){if((r==="update"?Ze:Fe).has(t))return;let s=i.find(a=>a.metadata_key===t&&a.commands.includes(r));if(s!==void 0){let a=se(o,s);e[ae(s)]=a!==void 0?a:s.type==="array"||s.type==="object"?JSON.stringify(n):n;return}if(!v.has(t)){if(R(t,[...v])!==void 0)throw w("item document",t,[...v]);let a=Array.isArray(e.field)?e.field:[];a.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=a;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(a,c)=>c.toUpperCase())]=dt(t,n))}function Rr(e,t,n={},r=[]){let i=P(e,"Item document");if(!f(i))throw new d("Item document must be a JSON object.",p.USAGE);let{item:o,linked:s}=lt(i),a={};for(let[c,l]of Object.entries(o))ut(a,c,l,t,r,n);if(De(a,o,t==="update"),s!==void 0&&De(a,s),t==="update"){let c=Object.fromEntries(["comments","notes","learnings"].filter(l=>Object.hasOwn(o,l)).map(l=>[l,o[l].filter(m=>f(m)&&m.created_at!==void 0)]));Object.keys(c).length>0&&(a.documentAnnotationSnapshot=c)}return{...a,...Object.fromEntries(Object.entries(n).filter(([,c])=>c!==void 0)),...Array.isArray(a.field)&&Array.isArray(n.field)?{field:[...a.field,...n.field]}:{},stdinJson:void 0}}function br(e){return Ge(JSON.stringify(e))}import W from"node:crypto";import{constants as j}from"node:fs";import{cp as mt,lstat as Le,mkdir as ft,mkdtemp as yt,open as ht,readdir as wt,realpath as gt,rm as _t,stat as We,writeFile as ze}from"node:fs/promises";import{tmpdir as Et}from"node:os";import u 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]="7ff78f44-c9db-5221-b09a-32b78876b461")}catch{}})();function M(e,t){let n={...e,...t};return e===void 0?n:we(e,n)}async function h(e,t){try{let n=(await Se(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===p.NOT_FOUND)return;throw n}}function z(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=W.createHash("sha256").update(X(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function St(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function g(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function O(e,t,n,r){let i=await de(u.join(e,"history",`${t}.jsonl`),t),o=g(n,r,"apply"),s=g(n,r,"compensate");for(let a=i.length-1;a>=0;a-=1){let c=i[a].message;if(c===o)return!0;if(c===s)return!1}return!1}async function B(e,t){let n=await h(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`,p.NOT_FOUND);return{target_updated_at:n.updatedAt}}async function k(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r.target_updated_at:void 0;typeof i=="string"&&await h(e.pmRoot,t)!==void 0&&await be(t,i,{force:!0,author:e.author,message:g(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot})}function Be(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"create"}}},async apply(){let r=(await Te(M(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"create"}},async compensate(){let r=await h(e.pmRoot,t.id);if(r!==void 0){if(e.createCompensation==="delete"){await Re(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}r.closedAt===void 0&&await U(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function Tt(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await O(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return B(e.pmRoot,t)},async apply(){let r=(await ve(t.id,M(t.options,{author:e.author,message:g(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"update"}},async compensate(r){await k(e,t.id,n,r)}}}function vt(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await O(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 B(e.pmRoot,t)},async apply(){let r=(await U(t.id,t.reason,M(t.options,{author:e.author,message:g(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"close"}},async compensate(r){await k(e,t.id,n,r)}}}function At(e,t,n){return{id:n,async inspect(){let r=await h(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await O(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 B(e.pmRoot,t)},async apply(){let r=(await Ae(t.id,M(t.options,{author:e.author,message:g(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return{id:String(r.id),op:"release"}},async compensate(r){await k(e,t.id,n,r)}}}function Je(e,t,n){let r=z(t,n);switch(t.op){case"create":return Be(e,t,r);case"update":return Tt(e,t,r);case"close":return vt(e,t,r);case"release":return At(e,t,r)}}function xe(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`)}async function F(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 Ke(e,t,n,r){let i=u.relative(e,t);return["locks","runtime","search"].includes(i.split(u.sep)[0])?r.some(o=>i===o||i.startsWith(`${o}${u.sep}`)||o.startsWith(`${i}${u.sep}`)):i===""||n===void 0||n.some(o=>i===o||i.startsWith(`${o}${u.sep}`)||o.startsWith(`${i}${u.sep}`))}async function I(e){let t=await Le(e);if(t.isSymbolicLink())await We(e);else if(t.isDirectory()||t.isFile())return t;throw T()}async function Rt(e){let t=await ht(e,j.O_RDONLY|j.O_NOFOLLOW|j.O_NONBLOCK);try{let n=await t.stat();if(!n.isFile())throw T();let r=W.createHash("sha256");if(n.size>0)for await(let i of t.createReadStream({highWaterMark:64*1024,end:n.size-1,autoClose:!1}))r.update(i);return r.digest()}finally{await t.close()}}async function G(e,t,n){let r=W.createHash("sha256");async function i(o){for(let s of(await wt(o)).sort()){let a=u.join(o,s);Ke(e,a,t,n)&&((await I(a)).isDirectory()?await i(a):(r.update(JSON.stringify(u.relative(e,a))),r.update(await Rt(a))))}}return await i(e),r.digest("hex")}function L(){return new d("Tracker changed while preparing the transaction preview; retry against stable state.",p.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function Ve(e){if(!$(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=u.resolve(t),r=n;for(;;)try{let i=await Le(r);return r!==n&&i.isDirectory()}catch(i){if(!$(i))return!1;let o=u.dirname(r);if(o===r)return!1;r=o}}async function b(e,t){let n=u.join(e,t);try{let r=e;for(let i of t.split(u.sep).slice(0,-1))r=u.join(r,i),await I(r);if(!(await I(n)).isFile())throw T();return await Y(n,T())}catch(r){if(await Ve(r))return;throw r}}async function bt(e,t,n){let r=new Map,i=await b(e,S);r.set(S,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let s=pe(o),a=s.success?s.data:void 0,c=ne(a?.schema);for(let[E,He]of Object.entries(c.files)){let _=u.relative(e,ie(e,He,re[E]));if(_===""||!u.resolve(e,_).startsWith(u.join(e,u.sep)))throw new d("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",p.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${E}`});c.files[E]=_;let N=await b(e,_);if(r.set(_,N),N!==void 0){let J=u.join(t,_);await ft(u.dirname(J),{recursive:!0}),await ze(J,N)}}let l=u.relative(e,ce(e));r.set(l,await b(e,l));let m=await oe(t,c),y=q({...V,item_types:{definitions:[...a?.item_types?.definitions??[],...m.type_definitions_from_file??[]]}},n),Ye=H(e)===e?[...K.filter(Boolean),S,te,"transactions",...y.folders,...r.keys()].map(E=>u.normalize(E)):void 0,qe=a===void 0?void 0:JSON.stringify({...o,schema:{...a.schema,files:c.files}});return{configuration:r,ownedPaths:Ye,stagedSettings:qe,registryFolders:y.folders}}async function It(e,t,n){await We(e);try{let r=await gt(e),i=await bt(r,u.join(u.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(l=>u.normalize(l)),s=await G(r,i.ownedPaths,o);await mt(r,t,{recursive:!0,dereference:!1,filter:async l=>Ke(r,l,i.ownedPaths,o)?(await I(l),!0):!1});let[a,c]=await Promise.all([G(r,i.ownedPaths,o),G(t,i.ownedPaths,o)]);if(s!==a||s!==c)throw L();for(let[l,m]of i.configuration)if(await b(t,l)!==m)throw L();i.stagedSettings!==void 0&&await ze(u.join(t,S),i.stagedSettings)}catch(r){throw await Ve(r)?L():r}}async function Yr(e){let t=me(e),n=[...e.mutations];if(n.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");for(let[s,a]of n.entries())xe(a,s);let r=ee(),i=await yt(u.join(Et(),"pm-transaction-preview-")),o=u.join(i,"tracker");try{await It(t.pmRoot,o,r);let s=!1;return await Ie({path:o,noExtensions:!0},async()=>{Q(r);let a={...t,pmRoot:o,createCompensation:"close"},c=n.map((l,m)=>{let y=Je(a,l,m);return{...y,inspect:()=>F(l,m,()=>y.inspect()),prepareCompensation:()=>F(l,m,async()=>y.prepareCompensation?.()),apply:()=>F(l,m,()=>y.apply())}});await C({...t,pmRoot:o,steps:c,onTransition:({transition:l})=>{l==="committed"&&(s=!0)}})}),{validated:s,state:s?"staged_snapshot":"replayed_committed_plan",unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks"]}}finally{await _t(i,{recursive:!0,force:!0})}}async function Mt(e){let t=[...e.mutations];if(t.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");for(let[s,a]of t.entries())xe(a,s);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let r={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n},i=await C({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((s,a)=>Je(r,s,a)),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),o={};for(let[s,a]of t.entries()){let c=z(a,s),l=i.results[c];o[St(a,s)]=l}return{transactionId:i.transactionId,status:"committed",recovered:i.recovered,results:o}}function Ot(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 qr(e){return Mt({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:Ot(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Hr={buildCreateStep:Be,bulkHistoryMarker:g,compensateByRestore:k,deriveStepId:z,isUpdateMarkerApplied:O,readItemSnapshot:h};export{vr as a,Ge as b,Ar as c,Rr as d,br as e,Yr as f,Mt as g,Ot as h,qr as i,Hr as j};
|
|
2
|
+
//# sourceMappingURL=chunk-LOSRTNNP.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Fa as p,Ga as i,Ha as v,Ia as _}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{Fa as p,Ga as i,Ha as v,Ia as _}from"./chunk-LE4IEHDG.js";import{db as h}from"./chunk-IDEHMKYZ.js";import u from"node:fs/promises";import c 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]="846100a9-4314-5f7c-b892-fa16e09bee5b")}catch{}})();function f(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}function y(e){return e!=="invalid"&&e!=="unreadable"}function j(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw new SyntaxError("Invalid settings object");let r=t.extensions;if(r===void 0)return{enabled:[],disabled:[]};if(typeof r!="object"||r===null||Array.isArray(r))throw new SyntaxError("Invalid extensions settings");let n=r;if(n.enabled!==void 0&&(!Array.isArray(n.enabled)||!n.enabled.every(a=>typeof a=="string"))||n.disabled!==void 0&&(!Array.isArray(n.disabled)||!n.disabled.every(a=>typeof a=="string")))throw new SyntaxError("Invalid extension enablement lists");return{enabled:n.enabled??[],disabled:n.disabled??[]}}async function S(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{status:"absent",enabled:[],disabled:[]}:{status:"unreadable",enabled:[],disabled:[],error:{code:"settings_unreadable",path:e}}}try{return{status:"ok",...j(t)}}catch{return{status:"invalid",enabled:[],disabled:[],error:{code:"settings_invalid",path:e}}}}async function A(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){if(f(r))try{if((await u.stat(c.dirname(e))).isDirectory())return{status:"absent",entries:[]}}catch(n){if(f(n))return{status:"absent",entries:[]}}return{status:"unreadable",entries:[],error:{code:"managed_state_unreadable",path:e}}}try{let r=JSON.parse(t),n=_(r);if(!n||typeof r!="object"||r===null||!Array.isArray(r.entries)||n.entries.length!==r.entries.length)throw new SyntaxError("Invalid managed extension state");return{status:"ok",entries:n.entries}}catch{return{status:"invalid",entries:[],error:{code:"managed_state_invalid",path:e}}}}async function I(e){try{return{directories:(await u.readdir(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,r)=>t.localeCompare(r))}}catch(t){return f(t)?{directories:[]}:{directories:[],error:{code:"extensions_unreadable",path:e}}}}async function D(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{manifest:null,error:{code:"manifest_invalid",path:e}}:{manifest:null,error:{code:"manifest_unreadable",path:e}}}try{let r=v(JSON.parse(t));return r?{manifest:r}:{manifest:null,error:{code:"manifest_invalid",path:e}}}catch{return{manifest:null,error:{code:"manifest_invalid",path:e}}}}function M(e){let t=e.manifest?.name??e.directory,r=new Set(p(e.settings.enabled)),n=new Set(p(e.settings.disabled)),a=!y(e.settings.status)||!e.manifest?null:!n.has(t)&&(r.size===0||r.has(t)),o=y(e.managed.status)?e.managed.entries.some(d=>i(d.name)===i(t)||i(d.directory)===i(e.directory)):null;return{name:t,directory:e.directory,scope:e.scope,installed:!0,status:e.manifest?a===!1?"inactive":"installed":"malformed_manifest",configured_enabled:a,managed:o,runtime_active:null,...e.manifest?{version:e.manifest.version}:{}}}async function R(e){let t=e.scope??"project",r=t==="global"?h(e.cwd??process.cwd()):e.pmRoot,n=c.join(r,"extensions"),a=await S(c.join(r,"settings.json")),o=await A(c.join(n,".managed-extensions.json")),d=await I(n),l=[];for(let s of[a,o,d])s.error&&l.push(s.error);let m=e.name?.trim(),b=[];for(let s of d.directories){let x=c.join(n,s,"manifest.json"),g=await D(x);g.error&&l.push(g.error);let w=M({directory:s,scope:t,manifest:g.manifest,settings:a,managed:o});m&&![w.name,s].some(E=>i(E)===i(m))||b.push(w)}return m&&b.length===0&&l.every(s=>s.code!=="extensions_unreadable")&&b.push({name:m,directory:null,scope:t,installed:!1,status:"absent",configured_enabled:y(a.status)?!1:null,managed:y(o.status)?!1:null,runtime_active:null}),{scope:t,complete:l.length===0,settings_status:a.status,managed_state_status:o.status,extensions:b,errors:l}}export{R as a};
|
|
2
|
+
//# sourceMappingURL=chunk-MAT4AP7P.js.map
|