@unbrained/pm-cli 2026.10.22 → 2026.10.24
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 +38 -0
- package/dist/cli/error-guidance.d.ts +12 -0
- package/dist/cli/error-guidance.js +2 -2
- package/dist/cli/register-setup.js +1 -1
- package/dist/cli-bundle/bundle-manifest.json +1 -1
- package/dist/cli-bundle/chunks/{chunk-2B5HAZFK.js → chunk-3S5FLCG7.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-PCPOTFJP.js → chunk-3VI4XDP2.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UYYTV2TX.js → chunk-4PNAUT2E.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-E3JC3WQL.js → chunk-CDR5ES7Q.js} +54 -54
- package/dist/cli-bundle/chunks/chunk-CNEUJHA4.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-AOAQDCXX.js → chunk-CSE47ZAN.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-MV3KYY2A.js → chunk-FASDGYQC.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-HZNFNETE.js +127 -0
- package/dist/cli-bundle/chunks/{chunk-7OTYULIJ.js → chunk-KGZGXC7T.js} +29 -29
- package/dist/cli-bundle/chunks/{chunk-HC2DCGFA.js → chunk-MA7SNKYK.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-GWIGZDRS.js → chunk-R7KWBFM2.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-TZYQ4JDZ.js +6 -0
- package/dist/cli-bundle/chunks/chunk-URZB3USE.js +113 -0
- package/dist/cli-bundle/chunks/chunk-UY5UHI4I.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-TNU3XVPC.js → chunk-VPMQEVU6.js} +14 -14
- package/dist/cli-bundle/chunks/{chunk-URV4VHQ4.js → chunk-VSSHB6XI.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-LIC5EUQS.js → chunk-YEI4N4A6.js} +48 -48
- package/dist/cli-bundle/chunks/chunk-Z62RXNHW.js +3 -0
- package/dist/cli-bundle/chunks/chunk-ZDVTXLA6.js +9 -0
- package/dist/cli-bundle/chunks/{indexed-receipt-blobs-L3BOTMZN.js → indexed-receipt-blobs-XANVELIV.js} +2 -2
- package/dist/cli-bundle/chunks/{mutation-admission-TATOFEXF.js → mutation-admission-NVTBZ7DH.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-GULR2IYO.js → register-list-query-2FE6K7FQ.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-HLSQ4WVW.js → register-mutation-KZXQUZUH.js} +2 -2
- package/dist/cli-bundle/chunks/{register-operations-FE3GGA7O.js → register-operations-BOCBWNKJ.js} +2 -2
- package/dist/cli-bundle/chunks/register-setup-P3VLCTDY.js +2 -0
- package/dist/cli-bundle/chunks/{settlement-hook-UVFYSBMU.js → settlement-hook-YUVCO65H.js} +2 -2
- package/dist/cli-bundle/chunks/{stage-QCPZBZRC.js → stage-WRDTMCCF.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-UQ5JPBY2.js → chunk-3QYTS4OY.js} +4 -4
- package/dist/cli-bundle/focused-chunks/{chunk-46HBJC6J.js → chunk-5MKNVJCM.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-QGDKWULS.js → chunk-6HJCSHBG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-7RQOFHMH.js +26 -0
- package/dist/cli-bundle/focused-chunks/chunk-AGCEWJ27.js +21 -0
- package/dist/cli-bundle/focused-chunks/{chunk-3LWH2RJC.js → chunk-BUZ2Z4P3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-2GFTVXKZ.js → chunk-CEEOWDB7.js} +3 -3
- package/dist/cli-bundle/focused-chunks/{chunk-25NQRZ7J.js → chunk-ES2NGVHZ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-GXAXDPD4.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-VYAZND5Q.js → chunk-IUAYTD2S.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-TMN3RAXZ.js → chunk-JYXA4JIP.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-A52W6GLA.js → chunk-NFFPNMTH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-KM77WU5U.js → chunk-NX7TVNUM.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-CX5FNEFC.js → chunk-POLMFGPQ.js} +3 -3
- package/dist/cli-bundle/focused-chunks/chunk-R536272H.js +9 -0
- package/dist/cli-bundle/focused-chunks/{chunk-W2CND3BD.js → chunk-RSEGFZTY.js} +54 -54
- package/dist/cli-bundle/focused-chunks/{chunk-EHPRSWJE.js → chunk-RVUGTIIU.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-CB7TSZ7P.js → chunk-SBJ2IKTH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-SXVJRLLP.js → chunk-SHUPX6G2.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-GVKYTDOH.js → chunk-TAHSXKAT.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-X5YRJMAY.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-XTYEASIY.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-ZMWLV2CE.js +91 -0
- package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-AAQOKO5B.js → indexed-receipt-blobs-FVOA3XMI.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{mutation-admission-TBKR4KRM.js → mutation-admission-PB6YFY7S.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{settlement-hook-MNCHFCAX.js → settlement-hook-2VXEB6PP.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{stage-RM6MJIMT.js → stage-MQE4PFWT.js} +2 -2
- package/dist/cli-bundle/main.js +21 -21
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +5 -2
- package/dist/cli-bundle/sdk-core.js +33 -33
- 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 +58 -58
- 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 +12 -9
- package/dist/core/checkpoint/mutation-checkpoint.d.ts +6 -3
- package/dist/core/checkpoint/mutation-checkpoint.js +2 -2
- package/dist/core/checkpoint/mutation-context.d.ts +10 -0
- package/dist/core/checkpoint/mutation-context.js +2 -0
- package/dist/core/config/nested-settings.js +1 -1
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/version-diagnostics.d.ts +2 -0
- package/dist/core/extensions/version-diagnostics.js +2 -0
- package/dist/core/lock/lock.d.ts +40 -6
- package/dist/core/lock/lock.js +3 -3
- package/dist/core/shared/errors.d.ts +28 -0
- package/dist/core/shared/errors.js +1 -1
- package/dist/core/store/item-store.js +1 -1
- package/dist/mcp/http-server.js +2 -2
- package/dist/mcp/server.js +2 -2
- package/dist/sdk/agent/command-recovery.d.ts +1 -0
- package/dist/sdk/agent/command-recovery.js +1 -1
- package/dist/sdk/agent/linked-resource-recovery.d.ts +13 -0
- package/dist/sdk/agent/linked-resource-recovery.js +2 -0
- package/dist/sdk/cli-contracts/agent-output-contracts.js +1 -1
- package/dist/sdk/cli-contracts/grammar-contracts.js +1 -1
- package/dist/sdk/cli-contracts/typed-action-inputs.d.ts +3 -2
- package/dist/sdk/contracts.d.ts +1 -0
- package/dist/sdk/contracts.js +1 -1
- package/dist/sdk/core.d.ts +1 -1
- package/dist/sdk/core.js +1 -1
- package/dist/sdk/extension/doctor.js +1 -1
- package/dist/sdk/extension/install-receipts.js +1 -1
- package/dist/sdk/extension/install-snapshot.d.ts +11 -0
- package/dist/sdk/extension/install-snapshot.js +1 -1
- package/dist/sdk/extension.d.ts +12 -0
- package/dist/sdk/extension.js +1 -1
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -1
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +1 -1
- package/dist/sdk/governance/health.d.ts +1 -0
- package/dist/sdk/governance/health.js +2 -2
- package/dist/sdk/index.d.ts +4 -2
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/lifecycle/checkpoint-rollback.d.ts +7 -0
- package/dist/sdk/lifecycle/checkpoint-rollback.js +2 -0
- package/dist/sdk/lifecycle/close-many.d.ts +1 -1
- package/dist/sdk/lifecycle/close-many.js +1 -1
- package/dist/sdk/lifecycle/hierarchy-mutation-lock.js +1 -1
- package/dist/sdk/lifecycle/restore.js +1 -1
- package/dist/sdk/lifecycle/update-many.d.ts +1 -1
- package/dist/sdk/lifecycle/update-many.js +1 -1
- package/dist/sdk/mcp/executable.d.ts +13 -0
- package/dist/sdk/mcp/executable.js +5 -0
- package/dist/sdk/public-surface.json +1 -1
- package/dist/sdk/query/context.d.ts +2 -1
- package/dist/sdk/query/context.js +1 -1
- package/dist/sdk/query/get.d.ts +2 -1
- package/dist/sdk/query/get.js +1 -1
- package/dist/sdk/query/list.d.ts +2 -1
- package/dist/sdk/query/list.js +1 -1
- package/dist/sdk/query/search/types.d.ts +2 -1
- package/dist/sdk/query.d.ts +1 -0
- package/dist/sdk/query.js +1 -1
- package/dist/sdk/read-output-contracts.d.ts +10 -2
- package/dist/sdk/read-output-contracts.js +1 -1
- package/dist/sdk/runtime-input.js +1 -1
- package/dist/sdk/runtime-primitives.d.ts +2 -1
- package/dist/sdk/runtime-primitives.js +1 -1
- package/dist/sdk/runtime.d.ts +11 -11
- package/dist/sdk/runtime.js +1 -1
- package/dist/sdk/test/batch.js +2 -2
- package/dist/sdk/test/entry.d.ts +5 -1
- package/dist/sdk/test/entry.js +2 -1
- package/dist/sdk/test/execution.js +2 -2
- package/dist/sdk/workspace-snapshot.d.ts +5 -1
- package/dist/sdk/workspace-snapshot.js +3 -3
- package/dist/sdk/workspace.js +2 -2
- package/docs/COMMANDS.md +21 -2
- package/docs/CONFIGURATION.md +19 -3
- package/docs/EXTENSION_AUTHOR_CONTRACTS.md +2 -1
- package/docs/EXTENSION_LIFECYCLE.md +47 -0
- package/docs/MCP_REMOTE_TRANSPORT_SECURITY.md +16 -1
- package/docs/READ_OUTPUT_CONTRACTS.md +15 -0
- package/docs/RELEASING.md +9 -0
- package/docs/SDK.md +84 -5
- package/docs/SDK_STORAGE_LIFECYCLE.md +2 -1
- package/docs/TESTING.md +39 -7
- package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +8 -3
- 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-35ISFIPC.js +0 -113
- package/dist/cli-bundle/chunks/chunk-5LSN7K4N.js +0 -2
- package/dist/cli-bundle/chunks/chunk-BAIVTLJM.js +0 -6
- package/dist/cli-bundle/chunks/chunk-C37RDYZI.js +0 -3
- package/dist/cli-bundle/chunks/chunk-J444ZX23.js +0 -126
- package/dist/cli-bundle/chunks/chunk-O67N62DT.js +0 -2
- package/dist/cli-bundle/chunks/chunk-VO3KDIU7.js +0 -9
- package/dist/cli-bundle/chunks/register-setup-XUIKAIZA.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-25L3L2PF.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-DVNUHTVK.js +0 -9
- package/dist/cli-bundle/focused-chunks/chunk-GC4VMLXL.js +0 -20
- package/dist/cli-bundle/focused-chunks/chunk-QWKCQ5PW.js +0 -91
- package/dist/cli-bundle/focused-chunks/chunk-SOVXHW6Z.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-UUPJ6OZL.js +0 -26
- package/dist/cli-bundle/focused-chunks/chunk-XX5JQCLF.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as he}from"./chunk-3S5FLCG7.js";import{Rb as je,Sb as Fe,Ub as W,Xb as Pe,Ya as z,Zb as Ge,_b as xe,a as ye,uc as qe}from"./chunk-CDR5ES7Q.js";import{ac as De}from"./chunk-KGZGXC7T.js";import{b as Oe,c as J}from"./chunk-YEI4N4A6.js";import{Le as Ce,M as Me,Oe as Ne,Za as Re,db as ke,g as Ie,i as O,nc as $e,pc as Ue,r as Ae}from"./chunk-HZNFNETE.js";import{Db as me,Nc as fe,Oc as q,Pa as le,Rg as Se,fg as we,hg as K,ig as ge,lg as ve,og as _e,pa as x,pg as E,pi as be,qh as L,rg as Ee,ti as Te,ya as pe,zi as M}from"./chunk-URZB3USE.js";import{A as u,C as c,G,I as ue,J as A,l as se,q as I,t as ce,y as de}from"./chunk-R7KWBFM2.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]="01728cbc-2037-50d2-8318-5f106714b8da")}catch{}})();var S=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...se,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function R(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return S.has(t)?t:e}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="6456f85b-e076-5048-9c21-03d477267259")}catch{}})();function k(e,t,n){let i=e?.estimatedMinutes;if(!(i===void 0||typeof i=="string"))throw new c(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,u.USAGE,{code:"mutation_option_value_invalid",required:'Pass estimatedMinutes as a string, for example "45", in raw mutation options.',why:"Raw options use the create/update command option types; item documents accept numeric estimated_minutes instead.",nextSteps:["Quote the estimatedMinutes value or use an item document with numeric estimated_minutes, then retry the transaction."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7b430d12-7a5b-52c2-9a6b-e4c33a39da76")}catch{}})();var V=["op","id","reason","options","unique","match"],bt=[...V,"ref"],Ke=[...bt,"item"],Tt="mutate-",Le="row-",Je=["schema_version","mutations"],Ze="[a-z][a-z0-9._-]{0,63}",ze=new RegExp(`^${Ze}$`,"u"),Qe=new RegExp(`(^|,)id=@(${Ze})(?=,|$)`,"gu"),We=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),$=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],et=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),It=new Set([...et,"completed_at","id"]),tt={create:Ce.map(e=>e.target),update:Ne.map(e=>e.target),close:Re.map(e=>We(e.flag)).filter(e=>e!=="reason"),release:ke.map(e=>We(e.flag))};function nt(e){let t=Xe.createHash("sha256").update(e).digest("hex");return`${Tt}${t.slice(0,24)}`}function _i(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new c("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let i of["lockTtlSeconds","lockWaitMs"]){let r=e[i];if(r===void 0)continue;let o=typeof r=="number"||typeof r=="string"&&r.trim().length>0?Number(r):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new c(`${i} must be a positive safe integer.`,u.USAGE);t[i]=o}return t}function y(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function U(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),i;for(let r of t){let o=me(e,r,n);o!==null&&(i===void 0||o<i.distance)&&(i={key:r,distance:o})}return i?.key}function b(e,t,n){let i=U(t,n);return new c(i===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${i}"?`,u.USAGE,{code:"stdin_json_unknown_key",required:`Use documented ${e} keys only.`,why:"Strict structured input prevents silent typos from creating incomplete or unintended mutations.",nextSteps:[i===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${i}".`]})}function H(e,t){try{return JSON.parse(e)}catch(n){let i=n instanceof Error?n.message:String(n);throw new c(`${t} must be valid JSON: ${i}`,u.USAGE,{code:"stdin_json_invalid",required:`Pipe one valid JSON ${t.toLowerCase()} into stdin.`,why:"Structured mutation input must parse deterministically before any tracker write begins."})}}function At(e,t){if(!y(e))throw new c(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!V.includes(n))throw b(`mutation ${t+1}`,n,V);return e}function Mt(e,t,n,i){if(e===void 0)return;if(!y(e))throw new c(`Mutation ${n+1} options must be an object.`,u.USAGE);let r=[...tt[t],...ot(t,i)];for(let o of Object.keys(e))if(!r.includes(o))throw b(`mutation ${n+1} ${t} options`,o,r);return k(e,t,n),e}function Ve(e,t,n,i){if(e===void 0)return;let r=i==="unique"?"create":"update";if(t!==r)throw new c(`Mutation ${n+1} ${i} is only valid for ${r} operations.`,u.USAGE);let o=y(e)&&typeof e.key=="string"?e.key.trim():"";if(!y(e)||o.length===0||e.value===void 0||e.value===null)throw new c(`Mutation ${n+1} ${i} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Ot(e,t,n){let i=At(e,t),{op:r,id:o,reason:a}=i;if(r!=="create"&&r!=="update"&&r!=="close"&&r!=="release")throw new c(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=Mt(i.options,r,t,n),d=Ve(i.unique,r,t,"unique"),l=Ve(i.match,r,t,"match");if(typeof o!="string"||o.trim().length===0)throw new c(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let p=o.trim();if(r==="close"){if(typeof a!="string"||a.trim().length===0)throw new c(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:r,id:p,reason:a.trim(),...s===void 0?{}:{options:s}}}if(r==="release")return{op:r,id:p,...s===void 0?{}:{options:s}};if(!y(s))throw new c(`Mutation ${t+1} ${r} requires an options object.`,u.USAGE);return{op:r,id:p,options:s,...d===void 0?{}:{unique:d},...l===void 0?{}:{match:l}}}function it(e,t={}){let n=H(e,"Mutation batch"),i=Array.isArray(n)?n:y(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(i===void 0||i.length===0)throw new c("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let r=t.runtimeFields??[];return i.map((o,a)=>{let s=Ot(o,a,r);return s.options!==void 0&&$e(s.options),s})}function Rt(e,t,n){let i=Xe.createHash("sha256").update(e).update("\0").update(t).digest("hex"),r=BigInt(`0x${i.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Ie(n)}${r}`}function Be(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),i=t[n];if(i===void 0)throw new c(`Unknown mutation reference "${e}".`,u.USAGE);return i}function Ye(e,t){if(typeof e!="string")return e;let n=e.replace(Qe,(i,r,o)=>{let a=t[o];if(a===void 0)throw new c(`Unknown mutation reference "@${o}".`,u.USAGE);return`${r}id=${a}`});if(/(^|,)id=@/u.test(n))throw new c(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function kt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(Qe)].map(t=>t[1]).filter(t=>t!==void 0)}function $t(e,t){let n=new Map;for(let[a,s]of e.entries()){let d=t[a];if(d===void 0)continue;let l=y(s.options)?s.options:{},p=Array.isArray(l.dep)?l.dep:l.dep===void 0?[]:[l.dep];n.set(d,[l.parent,l.blockedBy,...p].flatMap(kt))}let i=new Set,r=new Set,o=a=>{if(i.has(a))throw new c(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!r.has(a)){i.add(a);for(let s of n.get(a))n.has(s)&&o(s);i.delete(a),r.add(a)}};for(let a of n.keys())o(a)}function Ut(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),i=n[0];if(!i.ok&&(i.line.startsWith("[")||i.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&y(o.value)))return null;let r=[];for(let o of n){if(!o.ok)throw new c(`Mutation document line ${o.number} must be one valid JSON object: ${he(o.error)}`,u.USAGE,{code:"stdin_json_invalid",required:"Provide one JSON object per line (JSON Lines), a JSON array, or a {schema_version, mutations} document.",why:"Structured mutation input must parse deterministically before any tracker write begins."});if(!y(o.value))throw new c(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);r.push(o.value)}return r}function Ct(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Nt(e){let t;try{t=H(e,"Mutation document")}catch(n){let i=Ut(e);if(i===null)throw n;return{schema_version:1,mutations:i}}return Array.isArray(t)?{schema_version:1,mutations:t}:y(t)&&!Ct(t)?{schema_version:1,mutations:[t]}:t}function Dt(e,t){let n=Object.hasOwn(e,"op")?jt(e,t):Ft(e,t);if(n.op==="create"&&n.id===void 0&&y(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new c(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function jt(e,t){for(let n of Object.keys(e))if(!Ke.includes(n))throw b(`mutation ${t+1}`,n,Ke);if(e.item!==void 0&&e.op!=="create")throw new c(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new c(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function Ft(e,t){let{ref:n,id:i,item:r,...o}=e,a=r!==void 0?r:o;if(r!==void 0&&Object.keys(o).length>0)throw new c(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!y(a))throw new c(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...i===void 0?{}:{id:i},item:a}}function Pt(e){let t=Nt(e);if(!y(t))throw new c("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!Je.includes(n))throw b("mutation document",n,Je);if(t.schema_version!==void 0&&t.schema_version!==1)throw new c("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new c("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,i)=>{if(!y(n))throw new c(`Mutation ${i+1} must be an object.`,u.USAGE);return Dt(n,i)})}function Gt(e,t,n){let i=new Set(Object.values(st(t,n,Object.create(null))));for(let r of t)r.op==="create"&&typeof r.id=="string"&&r.id.trim().length>0&&i.add(O(r.id,n.idPrefix));return{...e,existing:e.existing.filter(r=>!i.has(r.id))}}function xt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,i]of e.entries()){if(i.op!=="create"||i.ref!==void 0||typeof i.id=="string"&&i.id.trim().length>0)continue;let r=`${Le}${n+1}`;if(t.has(r))throw new c(`Mutation ${n+1} receives the synthesized ref "${r}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${Le}<n> aliases are reserved for rows without one.`,u.USAGE);i.ref=r}}function rt(e,t,n){let i=en(JSON.stringify(e),t,{},n);return delete i.stdinJson,delete i.documentAnnotationSnapshot,i}function ot(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>E(n))}function qt(e,t){for(let n of e)y(n.item)&&(n.options=rt(n.item,"create",t),delete n.item)}function at(e,t){return t.some(n=>n.metadata_key===e)?e:R(e)}function B(e,t,n){let i=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(y(e.item)){if(e.item[t]!==void 0)return e.item[t];if(at(i,n)===t&&e.item[i]!==void 0)return e.item[i]}let r=y(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&r[E(o)]!==void 0?r[E(o)]:r[t]!==void 0?r[t]:r[i]!==void 0?r[i]:(Array.isArray(r.field)?r.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function Kt(e,t){return e<t?-1:+(e!==t)}function Y(e){return Array.isArray(e)?e.map(Y):y(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>Kt(t,n)).map(([t,n])=>[t,Y(n)])):e}function v(e){return typeof e=="string"?e.trim():JSON.stringify(Y(e))}function Lt(e,t,n,i,r){let o=t.key.trim();if(o.length===0)throw new c("Upsert key must be a non-empty field name.",u.USAGE);let a=Jt(t.existing),s=new Map,d=new Set;for(let[l,p]of e.entries()){if(p.op!=="create")continue;let f=zt(p,o,l,s,i),w=Wt(a.get(f)??[],o,f);if(w===void 0){p.unique={key:o,value:B(p,o,i)};continue}let h=O(w,n);typeof p.ref=="string"&&(r[p.ref]=h),Vt(p,h,i,{key:o,value:B(p,o,i)}),d.add(l)}return d}function Jt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let i=v(n.value);t.set(i,[...t.get(i)??[],n.id])}return t}function zt(e,t,n,i,r){let o=B(e,t,r);if(o==null||o==="")throw new c(`Mutation ${n+1} is missing the upsert key "${t}".`,u.USAGE,{code:"upsert_key_missing",required:`Every create record must carry a non-empty "${t}" value when --upsert-key ${t} is set.`,why:"Keyed upsert identifies existing items by that field; a record without it cannot be matched or safely created."});let a=v(o),s=i.get(a);if(s!==void 0)throw new c(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,u.USAGE,{code:"upsert_key_duplicate",required:"Each record must carry a distinct upsert key value within one batch.",why:"Two records with the same key would race for the same existing item."});return i.set(a,n),a}function Wt(e,t,n){if(e.length>1)throw new c(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,u.CONFLICT,{code:"upsert_key_ambiguous",required:"Resolve the duplicate existing items or choose a key that is unique per item.",why:"An ambiguous key cannot select one item to update without guessing."});return e[0]}function Vt(e,t,n,i){let r=new Set([...tt.update,...ot("update",n)]),o=y(e.item)?rt(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>r.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=i}function st(e,t,n){for(let[i,r]of e.entries())if(r.ref!==void 0){if(r.op!=="create")throw new c(`Mutation ${i+1} ref is only valid for create operations.`,u.USAGE);if(typeof r.ref!="string"||!ze.test(r.ref))throw new c(`Mutation ${i+1} ref must match ${ze.source}.`,u.USAGE);if(n[r.ref]!==void 0)throw new c(`Duplicate mutation ref "${r.ref}".`,u.USAGE);n[r.ref]=typeof r.id=="string"&&r.id.trim().length>0?O(r.id,t.idPrefix):Rt(t.transactionId,r.ref,t.idPrefix)}return n}function ct(e,t){let n=Pt(e);xt(n);let i=n.map(p=>typeof p.ref=="string"?p.ref:void 0),r=Object.create(null),o=t.upsert===void 0?new Set:Lt(n,Gt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],r);qt(n,t.runtimeFields??[]),st(n,t,r),$t(n,i);let a=n.map(p=>{let f={...p},w=typeof f.ref=="string"?f.ref:void 0;if(delete f.ref,w!==void 0?f.id=r[w]:f.id=Be(f.id,r),y(f.options)){let h={...f.options};for(let g of["parent","blockedBy"])h[g]!==void 0&&(h[g]=Be(h[g],r));Array.isArray(h.dep)?h.dep=h.dep.map(g=>Ye(g,r)):h.dep!==void 0&&(h.dep=Ye(h.dep,r)),f.options=h}return f}),s=it(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),d=s.filter(p=>p.op==="create").map(p=>p.id);if(new Set(d).size!==d.length)throw new c("Duplicate resolved create id in mutation document.",u.USAGE);let l=s.map((p,f)=>{let w=i[f];return{index:f,...typeof w=="string"?{ref:w}:{},id:p.id,op:p.op,...o.has(f)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:r,rows:l}}function Bt(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let i=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(i)?JSON.stringify(i):i}`}).join(",")}function Yt(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(y))throw new c(`${n} must be an array of objects.`,u.USAGE);return e.map(i=>Bt(i,t))}}function Ht(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 He(e,t,n=!1){for(let[i,r,o]of De){let a=t[i],s=Yt(n&&["comments","notes","learnings"].includes(i)&&Array.isArray(a)?a.filter(d=>!y(d)||d.created_at===void 0):a,o,i);s!==void 0&&s.length>0&&(e[r]=s)}}function Xt(e,t){for(let n of Object.keys(e)){if(t){if(!$.includes(n))throw b("item envelope",n,$);continue}if(!S.has(n)&&U(n,[...S])===void 0&&U(n,$)==="item")throw b("item envelope",n,$)}}function Zt(e){let t=Object.hasOwn(e,"item");Xt(e,t);let n=t?e.item:e;if(!y(n))throw new c("Item document item must be an object.",u.USAGE);return{item:n,...t&&y(e.linked)?{linked:e.linked}:{}}}function Qt(e,t,n,i,r,o){if((i==="update"?It:et).has(t))return;let a=r.find(s=>s.metadata_key===t&&s.commands.includes(i));if(a!==void 0){let s=Ee(o,a);e[E(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!S.has(t)){if(U(t,[...S])!==void 0)throw b("item document",t,[...S]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,d)=>d.toUpperCase())]=Ht(t,n))}function en(e,t,n={},i=[]){let r=H(e,"Item document");if(!y(r))throw new c("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=Zt(r),s={};for(let[d,l]of Object.entries(o)){let p=at(d,i);p!==d&&Object.hasOwn(o,p)||Qt(s,p,l,t,i,n)}if(He(s,o,t==="update"),a!==void 0&&He(s,a),t==="update"){let d=Object.fromEntries(["comments","notes","learnings"].filter(l=>Object.hasOwn(o,l)).map(l=>[l,o[l].filter(p=>y(p)&&p.created_at!==void 0)]));Object.keys(d).length>0&&(s.documentAnnotationSnapshot=d)}return{...s,...Object.fromEntries(Object.entries(n).filter(([,d])=>d!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0}}function Ei(e){return it(JSON.stringify(e))}import ee from"node:crypto";import{constants as X}from"node:fs";import{cp as tn,lstat as ut,mkdir as nn,mkdtemp as pt,open as rn,readdir as on,realpath as lt,rm as mt,stat as te,writeFile as ft}from"node:fs/promises";import{tmpdir as yt}from"node:os";import m 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]="89f9137d-876a-5aa7-8272-f83df5edf9e9")}catch{}})();async function ne(e,t){if(!Te(e))return{schema:K(t.schema),typeDefinitionsFromFile:[]};let n=await fn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function ie(e,t,n,i){let r=x({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},q());return(await Me(e,t.item_format,r.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[i];return a==null?[]:[{id:o.id,value:a}]})}function ht(e){let t=new Map,n=async i=>{let r=await M(e),o=await ne(e,r),a=new Map;for(let s of await ie(e,r,o,i)){let d=v(s.value);a.set(d,[...a.get(d)??[],s.id])}return a};return{lookup(i){let r=t.get(i)??n(i);return t.set(i,r),r},async recordCreate(i){for(let[r,o]of t){let a=i[r];if(a==null)continue;let s=await o,d=v(a);s.set(d,[...s.get(d)??[],String(i.id)])}},invalidate(){t.clear()}}}async function an(e,t){let n=v(t.value),i=(await e.lookup(t.key)).get(n)??[];if(i.length!==0)throw new c(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${i.join(", ")}; the plan was resolved before it existed.`,u.CONFLICT,{code:"upsert_key_conflict",required:"Re-plan the document so the row updates the existing item instead of creating a duplicate.",why:"Keyed upsert is resolved before the writer lock, so every remaining create is re-checked under the lock; concurrent imports therefore cannot create two items for one key value.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan turns the row into an update of the existing item.","Inspect the existing item first when its content should win over the document row."]})}function sn(e,t,n){let i=e.metadata[n.key],r=v(n.value);if(v(i)!==r)throw new c(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(r)}; the plan selected it before the key changed.`,u.CONFLICT,{code:"upsert_match_changed",required:"Re-plan the document so the row is resolved against the current key values.",why:"Keyed upsert selects its target before the writer lock, so the update re-reads the key under the lock instead of updating a mismatched item blindly.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan creates or re-targets the row from the current key values."]})}function dt(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=e;return typeof t.key=="string"&&t.key.trim().length>0&&t.value!==void 0&&t.value!==null}function j(e,t){let n={...e,...t};return e===void 0?n:Ue(e,n)}async function _(e,t){try{let n=(await z(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 c&&n.exitCode===u.NOT_FOUND)return;throw n}}function re(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),i=ee.createHash("sha256").update(le(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${i}`}function cn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function T(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function F(e,t,n,i){let r=await L(m.join(e,"history",`${t}.jsonl`),t),o=T(n,i,"apply"),a=T(n,i,"compensate");for(let s=r.length-1;s>=0;s-=1){let d=r[s].message;if(d===o)return!0;if(d===a)return!1}return!1}async function oe(e,t){let n=await _(e,t.id);if(n?.updatedAt===void 0)throw new c(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);return{target_updated_at:n.updatedAt}}async function P(e,t,n,i){let r=i!==null&&typeof i=="object"&&!Array.isArray(i)?i.target_updated_at:void 0;typeof r=="string"&&await _(e.pmRoot,t)!==void 0&&await xe(t,r,{force:!0,author:e.author,message:T(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot})}function wt(e,t,n){return{id:n,async inspect(){let i=await _(e.pmRoot,t.id);if(i===void 0)return{state:"pending"};if(i.closedAt!==void 0){let r=await L(m.join(e.pmRoot,"history",`${i.id}.jsonl`),i.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(r.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new c(`Created item ${i.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:i.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${i.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:i.id,op:"create"}}},async apply(){t.unique!==void 0&&await an(e.uniqueIndex,t.unique);let i=await je(j(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot}),r=i.item;return e.onCreateWarnings?.(String(r.id),i.warnings),await e.uniqueIndex.recordCreate(r),{id:String(r.id),op:"create"}},async compensate(){let i=await _(e.pmRoot,t.id);if(i!==void 0){if(e.createCompensation==="delete"){await Ge(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}i.closedAt===void 0&&await W(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function dn(e,t,n){return{id:n,async inspect(){let i=await _(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=()=>Fe(t.id,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),r=t.match,o=(r===void 0?await i():await Ae({pmRoot:e.pmRoot,id:String((await z(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:a=>sn(a,t.id,r)},i)).item;return e.uniqueIndex.invalidate(),{id:String(o.id),op:"update"}},async compensate(i){await P(e,t.id,n,i)}}}function un(e,t,n){return{id:n,async inspect(){let i=await _(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"close"}}:i.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:i.id,op:"close"}}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=(await W(t.id,t.reason,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(i.id),op:"close"}},async compensate(i){await P(e,t.id,n,i)}}}function pn(e,t,n){return{id:n,async inspect(){let i=await _(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"release"}}:i.assignee!==void 0||i.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:i.id,op:"release"}}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=(await Pe(t.id,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(i.id),op:"release"}},async compensate(i){await P(e,t.id,n,i)}}}function gt(e,t,n){let i=re(t,n);switch(t.op){case"create":return wt(e,t,i);case"update":return dn(e,t,i);case"close":return un(e,t,i);case"release":return pn(e,t,i)}}function ln(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`Bulk mutation ${t+1} must be an object`);if(!["create","update","close","release"].includes(e.op))throw new TypeError(`Bulk mutation ${t+1} op must be create, update, close, or release`);if(typeof e.id!="string"||e.id.trim().length===0)throw new TypeError(`Bulk mutation ${t+1} requires a non-empty id`);if(e.op==="close"&&(typeof e.reason!="string"||e.reason.trim().length===0))throw new TypeError(`Bulk close mutation ${t+1} requires a non-empty reason`);if(e.op==="create"&&e.unique!==void 0&&!dt(e.unique))throw new TypeError(`Bulk create mutation ${t+1} unique must be an object with a non-empty key and a value`);if(e.op==="update"&&e.match!==void 0&&!dt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);k(e.options,e.op,t)}function vt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,i]of e.entries()){if(ln(i,n),i.op!=="create"||i.unique===void 0)continue;let{key:r,value:o}=i.unique,a=t.get(r)??new Map,s=v(o),d=a.get(s);if(d!==void 0)throw new c(`Bulk create mutations ${d+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${r}".`,u.USAGE,{code:"upsert_key_duplicate",required:"Each create must carry a distinct unique key value within one batch.",why:"Direct SDK batches must preserve the same uniqueness invariant as planned document rows."});a.set(s,n),t.set(r,a)}}async function Z(e,t,n){try{return await n()}catch(i){throw i instanceof c?new c(i.message,i.exitCode,{...i.context,transaction_operation:{index:t,op:e.op,id:e.id}}):i}}function _t(e,t,n,i){let r=m.relative(e,t);return["locks","runtime","search"].includes(r.split(m.sep)[0])?i.some(o=>r===o||r.startsWith(`${o}${m.sep}`)||o.startsWith(`${r}${m.sep}`)):r===""||n===void 0||n.some(o=>r===o||r.startsWith(`${o}${m.sep}`)||o.startsWith(`${r}${m.sep}`))}async function N(e,t){let n=await ut(t);if(n.isSymbolicLink())await te(t);else if(n.isDirectory()||n.isFile())return n;throw A(m.relative(e,t))}async function mn(e,t){let n=await rn(t,X.O_RDONLY|X.O_NOFOLLOW|X.O_NONBLOCK);try{let i=await n.stat();if(!i.isFile())throw A(m.relative(e,t));let r=ee.createHash("sha256");if(i.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:i.size-1,autoClose:!1}))r.update(o);return r.digest()}finally{await n.close()}}async function Q(e,t,n){let i=ee.createHash("sha256");async function r(o){for(let a of(await on(o)).sort()){let s=m.join(o,a);_t(e,s,t,n)&&((await N(e,s)).isDirectory()?await r(s):(i.update(JSON.stringify(m.relative(e,s))),i.update(await mn(e,s))))}}return await r(e),i.digest("hex")}function C(){return new c("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ae(e){if(!G(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),i=n;for(;;)try{let r=await ut(i);return i!==n&&r.isDirectory()}catch(r){if(!G(r))return!1;let o=m.dirname(i);if(o===i)return!1;i=o}}async function D(e,t){let n=m.join(e,t);try{let i=e;for(let r of t.split(m.sep).slice(0,-1))i=m.join(i,r),await N(e,i);if(!(await N(e,n)).isFile())throw A(t);return await ue(n,A(t))}catch(i){if(await ae(i))return;throw i}}async function Et(e,t,n,i){let r=K(n);for(let[o,a]of Object.entries(r.files)){let s=m.relative(e,ge(e,a,we[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new c("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",u.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});r.files[o]=s;let d=await D(e,s);if(i?.set(s,d),d!==void 0){let l=m.join(t,s);await nn(m.dirname(l),{recursive:!0}),await ft(l,d)}}return ve(t,r)}async function fn(e,t){await te(e);let n=await pt(m.join(yt(),"pm-schema-plan-"));try{let i=await lt(e);return await Et(i,m.join(n,"configuration"),t)}catch(i){throw await ae(i)?C():i}finally{await mt(n,{recursive:!0,force:!0})}}async function yn(e,t,n){let i=new Map,r=await D(e,I);i.set(I,r);let o;try{o=JSON.parse(r??"null")}catch{o=null}let a=be(o),s=a.success?a.data:void 0,d=await Et(e,t,s?.schema,i),l=d.schema,p=m.relative(e,Se(e));i.set(p,await D(e,p));let f=x({...de,item_types:{definitions:[...s?.item_types?.definitions??[],...d.type_definitions_from_file??[]]}},n),w=pe(e)===e?[...ce.filter(Boolean),I,ye,"transactions",...f.folders,...i.keys()].map(g=>m.normalize(g)):void 0,h=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:l.files}});return{configuration:i,ownedPaths:w,stagedSettings:h,registryFolders:f.folders}}async function hn(e,t,n){await te(e);try{let i=await lt(e),r=await yn(i,m.join(m.dirname(t),"configuration"),n),o=[...r.configuration.keys(),...r.registryFolders].map(l=>m.normalize(l)),a=await Q(i,r.ownedPaths,o);await tn(i,t,{recursive:!0,dereference:!1,filter:async l=>_t(i,l,r.ownedPaths,o)?(await N(i,l),!0):!1});let[s,d]=await Promise.all([Q(i,r.ownedPaths,o),Q(t,r.ownedPaths,o)]);if(a!==s||a!==d)throw C();for(let[l,p]of r.configuration)if(await D(t,l)!==p)throw C();r.stagedSettings!==void 0&&await ft(m.join(t,I),r.stagedSettings)}catch(i){throw await ae(i)?C():i}}async function St(e){let t=Oe(e),n=[...e.mutations];vt(n);let i=q(),r=await pt(m.join(yt(),"pm-transaction-preview-")),o=m.join(r,"tracker");try{await hn(t.pmRoot,o,i);let a=!1,s=[];return await qe({path:o,noExtensions:!0},async()=>{fe(i);let d={...t,pmRoot:o,createCompensation:"close",uniqueIndex:ht(o)},l=n.map((p,f)=>{let w=gt({...d,onCreateWarnings:(h,g)=>{g.length>0&&s.push({index:f,id:h,op:"create",warnings:g})}},p,f);return{...w,inspect:()=>Z(p,f,()=>w.inspect()),prepareCompensation:()=>Z(p,f,async()=>w.prepareCompensation?.()),apply:()=>Z(p,f,()=>w.apply())}});await J({...t,pmRoot:o,steps:l,onTransition:({transition:p})=>{p==="committed"&&(a=!0)}})}),{validated:a,state:a?"staged_snapshot":"replayed_committed_plan",warnings:s,unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks"]}}finally{await mt(r,{recursive:!0,force:!0})}}async function wn(e){let t=[...e.mutations];vt(t);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n,uniqueIndex:ht(e.pmRoot)},r=await J({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((a,s)=>gt(i,a,s)),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),o={};for(let[a,s]of t.entries()){let d=re(s,a),l=r.results[d];o[cn(s,a)]=l}return{transactionId:r.transactionId,status:"committed",recovered:r.recovered,results:o}}function gn(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 Bi(e){return wn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:gn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Yi={buildCreateStep:wt,bulkHistoryMarker:T,compensateByRestore:P,deriveStepId:re,isUpdateMarkerApplied:F,readItemSnapshot:_};(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]="3041c268-69c8-58e5-8a68-eaaa3c0dbd3b")}catch{}})();async function rr(e){let{plan:t}=e,n=await St({pmRoot:e.pmRoot,author:e.author,transactionId:t.transaction_id,mutations:t.mutations}),i=new Map(n.warnings.map(o=>[o.index,o.warnings])),r=t.rows.map(o=>{let a={...o};delete a.warnings;let s=i.get(o.index);return s!==void 0&&(a.warnings=s),a});return{validation:n,rows:r}}async function or(e){let t=e.upsertKey?.trim();if(t!==void 0&&t.length===0)throw new c("Upsert key must be a non-empty field name.",u.USAGE);let n=e.settings??await M(e.pmRoot),i=e.transactionId?.trim()??"",r=i.length>0?i:nt(e.input),o=await ne(e.pmRoot,n),a=_e(o.schema).definitions,s=(a.find(l=>l.metadata_key===t)??a.find(l=>l.key===t||E(l)===t))?.metadata_key??R(t),d=s===void 0?void 0:{key:s,existing:await ie(e.pmRoot,n,o,s)};return{...ct(e.input,{transactionId:r,idPrefix:n.id_prefix,runtimeFields:a,...d===void 0?{}:{upsert:d}}),transaction_id:r,transaction_id_source:i.length>0?"explicit":"derived",...d===void 0?{}:{upsert_key:d.key}}}export{nt as a,_i as b,it as c,v as d,ct as e,en as f,Ei as g,ne as h,ie as i,fn as j,St as k,wn as l,gn as m,Bi as n,Yi as o,rr as p,or as q};
|
|
2
|
+
//# sourceMappingURL=chunk-CNEUJHA4.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as k,c as I,d as A,e as _,k as T,m as C}from"./chunk-
|
|
1
|
+
import{a as k,c as I,d as A,e as _,k as T,m as C}from"./chunk-TZYQ4JDZ.js";import{Db as b,Eb as v,Fb as R}from"./chunk-VPMQEVU6.js";import{Nf as f,Qf as g,Rc as x,Rf as a,gg as w,ze as H}from"./chunk-HZNFNETE.js";import{Kf as D,Nf as m,Of as y,Tc as E}from"./chunk-URZB3USE.js";import{A as c,C as p}from"./chunk-R7KWBFM2.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-CSE47ZAN.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Ei as V,Rf as W,Se as U,bf as $,oh as H,pa as B,ui as L,xa as E,z as G,zi as P}from"./chunk-URZB3USE.js";import{d as K}from"./chunk-ZDVTXLA6.js";import{a as X,b as v,c as q}from"./chunk-VS565KBX.js";import{A as b,C as k,E as S,G as j,H as N,K as F}from"./chunk-R7KWBFM2.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new e.Error().stack;r&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[r]="6d1f8e03-97b4-5d83-b85c-e47f39c07d48")}catch{}})();var se="PM_SOURCE_CONTEXT_ACCESS",ce="PM_ALLOW_SOURCE_CONTEXT_WRITES";function J(e){let r=e[se],i=r===void 0||r.trim().toLowerCase()==="write"?"write":"read_only",t=i==="read_only"&&e[ce]?.trim()==="1";return{access:i,write_override_applied:t,source_writes_allowed:i==="write"||t}}import{access as le,readFile as A,realpath as w}from"node:fs/promises";import{constants as me}from"node:fs";import{execFile as ue}from"node:child_process";import c from"node:path";import{promisify as de}from"node:util";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new e.Error().stack;r&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[r]="b1828465-0619-514c-8956-2a81dea9efbc")}catch{}})();var _=de(ue),T="# pm-cli:merge-drivers:start",pe="# pm-cli:merge-drivers:end",x="# pm-cli:merge-drivers:v2:start",Q="# pm-cli:merge-drivers:v2:end",fe="merge-fence",ge="merge-attributes";function R(e){return`'${e.replaceAll("'",`'"'"'`)}'`}async function he(e,r){let i=await w(e);if(/(?:^|[\\/])bun-node-[^\\/]+[\\/]bun(?:\.exe)?$/iu.test(i))return;let{stdout:t}=await _(e,["--version"],{encoding:"utf8",windowsHide:!0,timeout:1e4});return t.trim()===r?i:void 0}async function we(){let e=G(import.meta.url,["../../.."]),r=process.execPath,i=!1,t=await w(process.execPath),o=process.versions.bun,a=(process.env.PATH??"").split(c.delimiter).filter(n=>c.isAbsolute(n)).map(n=>c.join(n,o===void 0?c.basename(process.execPath):process.platform==="win32"?"bun.exe":"bun")),s=o===void 0?a:[process.env.npm_execpath??"",...a,t].filter(n=>c.isAbsolute(n)&&/^(?:bun|bun\.exe)$/iu.test(c.basename(n)));for(let n of s)try{if(await le(n,me.X_OK),o!==void 0){let p=await he(n,o);if(p!==void 0){r=p,i=!0;break}continue}if(n!==t&&await w(n)===t){r=n;break}}catch{}if(o!==void 0&&!i)throw new k("Cannot install Bun merge drivers without a durable executable matching the current Bun version.",b.DEPENDENCY_FAILED,{code:"merge_bun_launcher_unavailable",why:"The current Bun process may be a temporary bunx launcher that Git cannot reuse after this command exits.",nextSteps:["Run with a durable version-matched Bun executable, expose one on an absolute PATH entry, or invoke pm through a Bun runner that publishes an absolute npm_execpath.","Retry pm merge install, then check pm health --strict-exit before merging branches."]});return`${R(r)} ${R(c.join(e,"dist","cli.js"))}`}var Z=[{key:"pm-item-toon",name:"pm field-aware TOON item document merge",artifact:"item",itemPath:"%P"},{key:"pm-item-markdown",name:"pm field-aware JSON-markdown item document merge",artifact:"item",itemPath:"%P"},{key:"pm-history",name:"pm append-only history stream merge",artifact:"history",itemPath:void 0},{key:"pm-relationship",name:"pm append-only relationship event store merge",artifact:"relationship",itemPath:void 0},{key:"pm-json",name:"pm key-level JSON config merge",artifact:"json",itemPath:void 0}];function ye(e){let r=e.explicitPath?.trim(),i=e.environment.PM_SOURCE_WORKSPACE_ROOT?.trim(),t=e.environment.PM_SOURCE_PM_PATH?.trim(),o=J(e.environment),a=!!(i&&t),s=r===void 0&&a&&(e.dryRun||o.source_writes_allowed);if(r!==void 0){let n=E(e.cwd,r);return{pm_root:n,workspace_start:n,source_coordinates_available:a,source_context_selected:!1,source_policy:o}}return s?{pm_root:c.resolve(t),workspace_start:c.resolve(i),source_coordinates_available:!0,source_context_selected:!0,source_policy:o}:{pm_root:a?E(e.cwd,".agents/pm"):E(e.cwd),workspace_start:e.cwd,source_coordinates_available:a,source_context_selected:!1,source_policy:o}}async function ee(e){try{let{stdout:r}=await _("git",["rev-parse","--show-toplevel"],{cwd:e,env:v(),encoding:"utf8",windowsHide:!0,timeout:1e4});return await w(r.trim())}catch{return null}}async function te(e){let r=await ee(e);if(r===null)throw new k("pm merge install requires a git repository (merge drivers are git configuration).",b.USAGE);return r}function O(e,r){return c.relative(e,r).split(c.sep).join("/")}function z(e){return e.replace(/[\\*?[\]!]/gu,"\\$&")}function h(e){return`"${e.replaceAll("\\","\\\\").replaceAll('"','\\"')}"`}function Y(e,r){if(e[r]!=="'")return null;let i="";for(let t=r+1;t<e.length;t+=1){if(e.startsWith(`'"'"'`,t)){i+="'",t+=4;continue}if(e[t]==="'")return{value:i,nextOffset:t+1};i+=e[t]}return null}async function ve(e,r,i){if(V(r).filter(o=>o.constraint==="exact").some(o=>o.version!==i))return!1;let t=await ee(e);if(t!==null&&t!==await w(r)){let o=await Promise.all([t,r].map(async a=>{let s=await _("git",["rev-parse","--path-format=absolute","--git-common-dir"],{cwd:a,env:v(),timeout:1e4});return w(s.stdout.trim())}));if(o[0]===o[1])return!1}return!0}async function _e(e,r,i){let t=Y(e,0);if(t===null||e[t.nextOffset]!==" ")return!1;let o=Y(e,t.nextOffset+1);if(o===null||e.slice(o.nextOffset)!==r||!/^(?:node|bun)(?:\.exe)?$/iu.test(c.basename(t.value))||c.basename(o.value)!=="cli.js"||c.basename(c.dirname(o.value))!=="dist"||!await S(t.value)||!await S(o.value))return!1;try{let a=c.dirname(c.dirname(o.value)),s=JSON.parse(await A(c.join(a,"package.json"),"utf8")),n=typeof s.bin=="string"?s.bin:s.bin?.pm;return await ve(a,i,s.version)?s.name==="@unbrained/pm-cli"&&n==="dist/cli.js":!1}catch{return!1}}function M(e,r){let i=e.length>0?`${z(e)}/`:"",t=[`${h(`${i}**/*.toon`)} merge=pm-item-toon`,`${h(`${i}**/*.md`)} merge=pm-item-markdown`];for(let o of r){let a=z(o);t.push(`${h(`${i}${a}/*.toon`)} merge=pm-item-toon`),t.push(`${h(`${i}${a}/*.md`)} merge=pm-item-markdown`)}return t.push(`${h(`${i}**/*.jsonl`)} merge=pm-relationship`),t.push(`${h(`${i}history/*.jsonl`)} merge=pm-history`),t.push(`${h(`${i}settings.json`)} merge=pm-json`),t.push(`${h(`${i}**/*.json`)} merge=pm-json`),t.push(`${h(`${i}extensions/**`)} merge=text`),t.push(`${h(`${i}extensions/.managed-extensions.json`)} merge=pm-json`),t}function re(e){let r=[],i=0;for(;i<e.length;){let t=e.indexOf(T,i),o=e.indexOf(x,i),a=t===-1?o:o===-1?t:Math.min(t,o);if(a===-1)break;let s=a===o,n=s?x:T,p=s?Q:pe,u=e.indexOf(p,a+n.length),m=u===-1?e.length:u+p.length;r.push({start:a,end:m,closed:u!==-1,lines:e.slice(a+n.length,u===-1?m:u).split(`
|
|
2
2
|
`).map(l=>l.trim()).filter(Boolean)}),i=m}return r}function ie(e,r,i){let t=new Set(r),o=h(i.length>0?`${i}/`:"").slice(0,-1);return e.some(a=>t.has(a)||a.startsWith(o)&&/^[^/]+\/\*\.(?:toon|md)" merge=pm-item-(?:toon|markdown)$/u.test(a.slice(o.length)))}async function oe(e,r,i,t){let o=c.join(e,".gitattributes"),a=t?null:(await _("git",["rev-parse","--absolute-git-dir"],{cwd:e,env:v(),encoding:"utf8",windowsHide:!0,timeout:1e4})).stdout.trim(),s=a===null?null:await $(a,ge,120,"merge-fence",!1,!0,5e3);try{let n=await N(o)??"",p=[x,...i,Q].join(`
|
|
3
3
|
`),u=re(n),m=u.filter(d=>ie(d.lines,i,r));m.length===0&&r===".agents/pm"&&u.length===1&&u[0].lines.every(d=>!d.includes("/"))&&m.push(u[0]);let l;if(m.length>0){let d=m[0];l=n;for(let y of m.slice(1).reverse())l=`${l.slice(0,y.start)}${l.slice(y.end)}`;l=`${l.slice(0,d.start)}${p}${l.slice(d.end)}`}else{let d=n.trimEnd();l=`${d.length>0?`${d}
|
|
4
4
|
|
|
5
5
|
`:""}${p}
|
|
6
6
|
`}return l===n?{path:o,changed:!1}:(t||await F(o,l),{path:o,changed:!0})}finally{await s?.()}}function ne(e){let r=B(e,null);return[...new Set(Object.values(r.type_to_folder))].sort((i,t)=>i.localeCompare(t))}async function Ve(e,r){let i=c.resolve(e),t=null,o="",a=i;for(let g=0;g<8;g+=1){let ae=c.join(a,".gitattributes");try{let C=await A(ae,"utf8");if(C.includes(x)||C.includes(T)){t=a,o=C;break}}catch{}let D=c.dirname(a);if(D===a)break;a=D}if(t===null)return{status:"not_installed",missing_patterns:[],stale_patterns:[],schema_scope:"project"};let s=c.join(t,".gitattributes"),n=O(t,i),p=re(o),u=M(n,r),m=p.filter(g=>ie(g.lines,u,n)),l=m.flatMap(g=>g.closed?g.lines:[]),d=new Set(l),y=new Set(u),f=u.filter(g=>!d.has(g)),I=l.filter(g=>!y.has(g));return{status:m.length!==1||!m[0].closed||f.length>0||I.length>0?"drift":"ok",path:s,missing_patterns:f,stale_patterns:I,schema_scope:"project"}}async function Ke(e){let r=[],i=[];for(let t of Z){let o=`merge.${t.key}.driver`,a=` merge driver ${t.artifact} "%O" "%A" "%B"${t.itemPath===void 0?"":` --item-path ${t.itemPath}`}`;try{let{stdout:s}=await _("git",["config","--get",o],{cwd:e,env:v(),encoding:"utf8",windowsHide:!0,timeout:1e4}),n=s.trim();await _e(n,a,e)||i.push(o)}catch{r.push(o)}}return{status:r.length>0?"missing":i.length>0?"drift":"ok",missing_keys:r,drifted_keys:i}}async function Xe(e){let r;try{r=await te(c.resolve(e))}catch{return{status:"no_git"}}let i=O(r,c.resolve(e)),t=await P(e),o=H(void 0,t.author_default),a=await $(e,fe,t.locks.ttl_seconds,o,!1,L(t).force_required_for_stale_lock,t.locks.wait_ms);try{let s=c.join(r,".gitattributes"),n;try{n=await A(s,"utf8")}catch(l){if(l instanceof Error&&"code"in l&&j(l))return{status:"not_installed",path:s};throw l}if(!n.includes(x)&&!n.includes(T))return{status:"not_installed",path:s};let p=await P(e),u=ne(p),m=await oe(r,i,M(i,u),!1);return{status:m.changed?"refreshed":"unchanged",path:m.path}}finally{await a()}}async function qe(e,r){let i=ye({cwd:process.cwd(),explicitPath:r.path,dryRun:e.dryRun===!0,environment:process.env}),t=i.pm_root;await W(t);let o=await te(i.workspace_start);return ke({pmRoot:t,workspaceRoot:o,dryRun:e.dryRun===!0,preCommitHook:e.preCommitHook===!0})}async function be(e,r){let i=(await _("git",["rev-parse","--path-format=absolute","--git-common-dir"],{cwd:e,env:v(),timeout:1e4})).stdout.trim(),t=await $(i,"merge-driver-config",120,"merge-install",!1,!0,5e3);try{let o=await q(e),a;try{a=(await _("git",["config",o,"--null","--get-regexp","."],{cwd:e,env:v(),timeout:1e4})).stdout}catch(n){if(typeof n!="object"||n===null||!("code"in n)||n.code!==1)throw n;a=""}let s=new Map(a.split("\0").filter(Boolean).map(n=>{let p=n.indexOf(`
|
|
7
|
-
`);return[n.slice(0,p),n.slice(p+1)]}));for(let n of r)s.get(n.key)!==n.value&&await X(e,[o,n.key,n.value])}finally{await t()}}async function ke(e){let r=c.resolve(e.pmRoot),i=c.resolve(e.workspaceRoot),t=e.dryRun===!0,o,a;try{[o,a]=await Promise.all([w(r),w(i)])}catch(f){throw new k(`Cannot resolve tracker root ${r} or workspace root ${i}: ${String(f)}`,b.NOT_FOUND,{code:"merge_root_not_found",nextSteps:["Initialize the tracker and ensure both paths are accessible.",'Retry "pm merge install" from the repository workspace.']})}let s=O(a,o);if(K(s))throw new k(`Tracker root ${r} is outside the git repository ${i}; there is nothing to configure for this repository.`,b.USAGE);let n=await P(o),p=ne(n),u=M(s,p),m=[],l=await we(),d=e.preCommitHook===!0?await import("./settlement-hook-
|
|
8
|
-
//# sourceMappingURL=chunk-
|
|
7
|
+
`);return[n.slice(0,p),n.slice(p+1)]}));for(let n of r)s.get(n.key)!==n.value&&await X(e,[o,n.key,n.value])}finally{await t()}}async function ke(e){let r=c.resolve(e.pmRoot),i=c.resolve(e.workspaceRoot),t=e.dryRun===!0,o,a;try{[o,a]=await Promise.all([w(r),w(i)])}catch(f){throw new k(`Cannot resolve tracker root ${r} or workspace root ${i}: ${String(f)}`,b.NOT_FOUND,{code:"merge_root_not_found",nextSteps:["Initialize the tracker and ensure both paths are accessible.",'Retry "pm merge install" from the repository workspace.']})}let s=O(a,o);if(K(s))throw new k(`Tracker root ${r} is outside the git repository ${i}; there is nothing to configure for this repository.`,b.USAGE);let n=await P(o),p=ne(n),u=M(s,p),m=[],l=await we(),d=e.preCommitHook===!0?await import("./settlement-hook-YUVCO65H.js").then(async f=>({plan:await f.prepareMergeSettlementHook(a,`${l} --pm-path ${R(s||".")}`),write:f.writeMergeSettlementHook})):void 0;for(let f of Z)m.push({key:`merge.${f.key}.name`,value:f.name}),m.push({key:`merge.${f.key}.driver`,value:`${l} merge driver ${f.artifact} "%O" "%A" "%B"${f.itemPath===void 0?"":` --item-path ${f.itemPath}`}`});if(!t)try{await be(a,m)}catch{throw new k(`Cannot install repository-local merge drivers in ${a}. Ensure the repository Git config is writable and no other Git process holds its lock, then retry.`,b.DEPENDENCY_FAILED,{code:"merge_git_config_unwritable",why:"pm merge install must persist clone-local driver commands before publishing their shared .gitattributes mappings.",nextSteps:["Make the repository Git config writable or wait for the process holding its lock to finish.",'Retry "pm merge install"; the operation is idempotent.','Use "pm merge install --dry-run --json" when the workspace is intentionally read-only.']})}let y=await oe(a,s,u,t);return d!==void 0&&!t&&await d.write(d.plan),{ok:!0,dry_run:t,workspace_root:a,pm_root:o,gitattributes:{path:y.path,changed:y.changed,patterns:u,schema_scope:"project"},git_config:m,...d===void 0?{}:{settlement_hook:{path:d.plan.path,changed:d.plan.changed}},guidance:["Commit .gitattributes so every branch and collaborator shares the merge mapping.",'git config is per-clone: each collaborator (and each fresh worktree/clone) runs "pm merge install" once.','After merging branches, run "pm merge reconcile --dry-run" to inspect the complete receipt and history repair, then apply "pm merge reconcile"; use --force only after explicitly accepting any discarded values.',"Custom item types registered later refresh this fence automatically (pm schema add-type/remove-type); rerun pm merge install only after out-of-band type-folder edits."],generated_at:U()}}export{se as a,ce as b,J as c,T as d,pe as e,x as f,Q as g,ye as h,ee as i,M as j,ne as k,Ve as l,Ke as m,Xe as n,qe as o,ke as p};
|
|
8
|
+
//# sourceMappingURL=chunk-FASDGYQC.js.map
|