@unbrained/pm-cli 2026.11.23 → 2026.11.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/cli/error-guidance.js +5 -5
- package/dist/cli/main.js +5 -5
- package/dist/cli/register-annotations.js +1 -1
- package/dist/cli/runtime/invocation-options.js +1 -1
- package/dist/cli-bundle/bundle-manifest.json +1 -1
- package/dist/cli-bundle/chunks/chunk-4FZH5BTV.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-YYT3MIRF.js → chunk-6OIHST4I.js} +1 -1
- package/dist/cli-bundle/chunks/chunk-7EPYCU7U.js +9 -0
- package/dist/cli-bundle/chunks/{chunk-AEOHUSUI.js → chunk-BVJMVU4Z.js} +68 -68
- package/dist/cli-bundle/chunks/{chunk-2UQU7HRR.js → chunk-C4KIZQHW.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-CNUFU454.js +113 -0
- package/dist/cli-bundle/chunks/chunk-CONBVY2O.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-BSRIVYTM.js → chunk-CZEMEPPQ.js} +3 -3
- package/dist/cli-bundle/chunks/chunk-DF6A7C32.js +2 -0
- package/dist/cli-bundle/chunks/chunk-FHLOGAGA.js +8 -0
- package/dist/cli-bundle/chunks/chunk-FVY7U3SU.js +125 -0
- package/dist/cli-bundle/chunks/{chunk-F2Z6XLZB.js → chunk-GBVF2ZB3.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-GZI7ZAB7.js +2 -0
- package/dist/cli-bundle/chunks/chunk-HZZLSBIJ.js +2 -0
- package/dist/cli-bundle/chunks/chunk-K34FR5CO.js +3 -0
- package/dist/cli-bundle/chunks/{chunk-D6PDUKUG.js → chunk-KHFUHGL3.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-L6VS7F3R.js +2 -0
- package/dist/cli-bundle/chunks/chunk-LOX3VY4T.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-H7JEXRIN.js → chunk-LPW7S5KA.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-5DUP4AZA.js → chunk-MGJMQSN4.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-OS5W4ZG2.js +31 -0
- package/dist/cli-bundle/chunks/{chunk-O7JHS64G.js → chunk-OWK2JL4I.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-SCIPT7WF.js +2 -0
- package/dist/cli-bundle/chunks/chunk-SX76UGEY.js +3 -0
- package/dist/cli-bundle/chunks/{chunk-CFWLQFJM.js → chunk-VA4T37Q4.js} +50 -51
- package/dist/cli-bundle/chunks/chunk-WQOEVGLQ.js +2 -0
- package/dist/cli-bundle/chunks/chunk-XHCIOLJP.js +3 -0
- package/dist/cli-bundle/chunks/{chunk-J2PDAVBC.js → chunk-XKWJONAO.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-YIGBEY7K.js +2 -0
- package/dist/cli-bundle/chunks/chunk-ZBOQEZ2H.js +33 -0
- package/dist/cli-bundle/chunks/chunk-ZLICQPRG.js +3 -0
- package/dist/cli-bundle/chunks/field-option-collisions-QE65APSD.js +2 -0
- package/dist/cli-bundle/chunks/{indexed-receipt-blobs-BPYKN5Q7.js → indexed-receipt-blobs-H3MMNXXG.js} +2 -2
- package/dist/cli-bundle/{focused-chunks/item-revision-YDACCDVY.js → chunks/item-revision-INDHJV6X.js} +2 -2
- package/dist/cli-bundle/chunks/item-transaction-LCKK4XXB.js +2 -0
- package/dist/cli-bundle/chunks/mutation-actor-KU7BMLUN.js +2 -0
- package/dist/cli-bundle/chunks/mutation-admission-3OMCTQD4.js +2 -0
- package/dist/cli-bundle/chunks/{register-list-query-L4IBU64P.js → register-list-query-3GV3LBOT.js} +2 -2
- package/dist/cli-bundle/chunks/register-mutation-GZLF47SX.js +21 -0
- package/dist/cli-bundle/chunks/register-operations-PBJZGCAL.js +2 -0
- package/dist/cli-bundle/chunks/register-setup-ZLJEF6NZ.js +2 -0
- package/dist/cli-bundle/chunks/runtime-schema-Y4SHTEXL.js +2 -0
- package/dist/cli-bundle/chunks/{settlement-hook-6MR32OOC.js → settlement-hook-ESAAEBRM.js} +2 -2
- package/dist/cli-bundle/chunks/stage-3WIZBD4N.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-3Y5PTQ2F.js +27 -0
- package/dist/cli-bundle/focused-chunks/{chunk-Y2ESLKCF.js → chunk-4LQL4EO6.js} +3 -3
- package/dist/cli-bundle/focused-chunks/{chunk-RIE3SJSE.js → chunk-4SX2BN4V.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-ZHWPCVQL.js → chunk-5RBC4WSE.js} +39 -39
- package/dist/cli-bundle/focused-chunks/chunk-7SSGTGZO.js +91 -0
- package/dist/cli-bundle/focused-chunks/chunk-A4R57E4K.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-BOIMP2AR.js +5 -0
- package/dist/cli-bundle/focused-chunks/chunk-BYQK5DGH.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-C3FEDTSD.js +44 -0
- package/dist/cli-bundle/focused-chunks/chunk-IAOKVKWW.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-JOKRDFMQ.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-MB56Y4M6.js +8 -0
- package/dist/cli-bundle/focused-chunks/{chunk-A6VEMCRR.js → chunk-NGFDPEP7.js} +1 -1
- package/dist/cli-bundle/focused-chunks/chunk-OCKKIECS.js +3 -0
- package/dist/cli-bundle/focused-chunks/chunk-PKX2EHE3.js +26 -0
- package/dist/cli-bundle/focused-chunks/chunk-SXC2EO3E.js +3 -0
- package/dist/cli-bundle/focused-chunks/chunk-TQIKDFOD.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-TRL4JDWX.js +8 -0
- package/dist/cli-bundle/focused-chunks/{chunk-IROZDIDX.js → chunk-UWWAVXG4.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-VMYVN36N.js +13 -0
- package/dist/cli-bundle/focused-chunks/chunk-VU2PH4PF.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-WL2R7T5G.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-WVA5KOXF.js +3 -0
- package/dist/cli-bundle/focused-chunks/{chunk-QQIIMMFU.js → chunk-X4EWD6TL.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-XKLBTDJ7.js +100 -0
- package/dist/cli-bundle/focused-chunks/chunk-YYEWIKNI.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-ZLRRII55.js +2 -0
- package/dist/cli-bundle/focused-chunks/field-option-collisions-5ROXGUME.js +2 -0
- package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-EGEJMG3G.js → indexed-receipt-blobs-PG2VJ3MB.js} +2 -2
- package/dist/cli-bundle/focused-chunks/item-revision-KYMSQVZE.js +2 -0
- package/dist/cli-bundle/focused-chunks/item-transaction-I4HLVHEJ.js +2 -0
- package/dist/cli-bundle/focused-chunks/mutation-actor-GGOQKAE6.js +2 -0
- package/dist/cli-bundle/focused-chunks/mutation-admission-OS36ZCMH.js +2 -0
- package/dist/cli-bundle/focused-chunks/runtime-schema-YXPYDD2C.js +2 -0
- package/dist/cli-bundle/focused-chunks/{settlement-hook-FMLGKG7J.js → settlement-hook-4MGRERCT.js} +2 -2
- package/dist/cli-bundle/focused-chunks/stage-4ZFWJUKO.js +2 -0
- package/dist/cli-bundle/main.js +26 -26
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +4 -4
- package/dist/cli-bundle/sdk-core.js +1 -1
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +63 -63
- 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 -12
- package/dist/core/profile/profile-lint.d.ts +1 -1
- package/dist/core/profile/profile-lint.js +1 -1
- package/dist/core/schema/fields-file.js +2 -2
- package/dist/core/schema/runtime-field-values.js +1 -1
- package/dist/core/schema/runtime-schema.d.ts +2 -0
- package/dist/core/schema/runtime-schema.js +1 -1
- package/dist/core/shared/command-line.d.ts +54 -4
- package/dist/core/shared/command-line.js +1 -1
- package/dist/core/shared/errors.d.ts +9 -0
- package/dist/core/shared/secret-rules.js +5 -5
- package/dist/core/shared/url-credentials.d.ts +16 -3
- package/dist/core/shared/url-credentials.js +1 -1
- package/dist/core/store/item-store.d.ts +26 -4
- package/dist/core/store/item-store.js +1 -1
- package/dist/sdk/command-line.d.ts +1 -1
- package/dist/sdk/command-line.js +1 -1
- package/dist/sdk/context-intent-contracts.js +1 -1
- package/dist/sdk/extension/command-options.d.ts +26 -1
- package/dist/sdk/extension/command-options.js +1 -1
- package/dist/sdk/extension-command-context.js +2 -2
- 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/tracked-runtime-cache.js +1 -1
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/lifecycle/claim.d.ts +21 -1
- package/dist/sdk/lifecycle/claim.js +1 -1
- package/dist/sdk/lifecycle/task-composition.js +1 -1
- package/dist/sdk/ownership-source.d.ts +15 -1
- package/dist/sdk/ownership-source.js +1 -1
- package/dist/sdk/public-surface.json +1 -1
- package/dist/sdk/read-output-contracts.d.ts +11 -0
- package/dist/sdk/read-output-contracts.js +1 -1
- package/dist/sdk/runtime-primitives.d.ts +1 -1
- package/dist/sdk/schema/field-flag-spelling.d.ts +22 -0
- package/dist/sdk/schema/field-flag-spelling.js +2 -0
- package/dist/sdk/schema/field-option-collisions.js +1 -1
- package/docs/AGENT_GUIDE.md +2 -2
- package/docs/COMMANDS.md +1 -1
- package/docs/CONFIGURATION.md +1 -0
- package/docs/EXTENSIONS.md +1 -1
- package/docs/MUTATION_INTEGRITY.md +97 -8
- package/docs/READ_OUTPUT_CONTRACTS.md +2 -0
- package/docs/SDK.md +60 -4
- package/docs/SDK_AUDITED_MUTATIONS.md +11 -0
- package/docs/WORKSPACE_POSITION_AND_LIFECYCLE.md +17 -4
- 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-5WZZ5XEN.js +0 -3
- package/dist/cli-bundle/chunks/chunk-6MYJLOSG.js +0 -2
- package/dist/cli-bundle/chunks/chunk-ENKXRSFZ.js +0 -31
- package/dist/cli-bundle/chunks/chunk-FJOEL75F.js +0 -2
- package/dist/cli-bundle/chunks/chunk-GDXCAC52.js +0 -2
- package/dist/cli-bundle/chunks/chunk-KE7HMBEW.js +0 -2
- package/dist/cli-bundle/chunks/chunk-KZHIBEJL.js +0 -33
- package/dist/cli-bundle/chunks/chunk-NGJ5ERBF.js +0 -115
- package/dist/cli-bundle/chunks/chunk-NQ54T7T2.js +0 -2
- package/dist/cli-bundle/chunks/chunk-OKEZF7HU.js +0 -2
- package/dist/cli-bundle/chunks/chunk-OKIKF4FD.js +0 -2
- package/dist/cli-bundle/chunks/chunk-OPJF254V.js +0 -9
- package/dist/cli-bundle/chunks/chunk-RWA5YZ5X.js +0 -2
- package/dist/cli-bundle/chunks/chunk-S32NGRQM.js +0 -2
- package/dist/cli-bundle/chunks/chunk-TZY5MVJF.js +0 -125
- package/dist/cli-bundle/chunks/chunk-ZPS4B6SI.js +0 -8
- package/dist/cli-bundle/chunks/item-revision-FMD4KWBB.js +0 -2
- package/dist/cli-bundle/chunks/item-transaction-SEHTH7N2.js +0 -2
- package/dist/cli-bundle/chunks/mutation-actor-SFGYIRPW.js +0 -2
- package/dist/cli-bundle/chunks/mutation-admission-57LBSKQI.js +0 -2
- package/dist/cli-bundle/chunks/register-mutation-6NUOPHZ3.js +0 -21
- package/dist/cli-bundle/chunks/register-operations-JGYVORNN.js +0 -2
- package/dist/cli-bundle/chunks/register-setup-C44SIXEH.js +0 -2
- package/dist/cli-bundle/chunks/stage-PQ7AB63N.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-6LKTEKHS.js +0 -6
- package/dist/cli-bundle/focused-chunks/chunk-6LPXMFLM.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-HMDQDRV2.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-I66IKYKP.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-IR2J3NOT.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-ITKDHSBR.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-LQYYPXUK.js +0 -26
- package/dist/cli-bundle/focused-chunks/chunk-NQTEE66P.js +0 -13
- package/dist/cli-bundle/focused-chunks/chunk-O7Z73ALG.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-OTMMOKPM.js +0 -91
- package/dist/cli-bundle/focused-chunks/chunk-OXOCZJC6.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-QLAHEDT6.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-TD544C74.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-UFTUNBMY.js +0 -27
- package/dist/cli-bundle/focused-chunks/chunk-XRS3VNC6.js +0 -44
- package/dist/cli-bundle/focused-chunks/chunk-XYPEZGTR.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-YSJKQLFR.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-Z2X7HH3C.js +0 -102
- package/dist/cli-bundle/focused-chunks/item-transaction-UKEQCTKB.js +0 -2
- package/dist/cli-bundle/focused-chunks/mutation-actor-AS465LRX.js +0 -2
- package/dist/cli-bundle/focused-chunks/mutation-admission-E5UHJZFE.js +0 -2
- package/dist/cli-bundle/focused-chunks/stage-36J7YLGI.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Cc as pt,Gc as ht,Ic as V,Mb as D,O as st,Oh as yt,Sh as kt,Tf as oe,Uf as ie,ca as ct,cb as ut,ea as B,eb as _t,nc as ft,sc as F,zc as mt}from"./chunk-CNUFU454.js";import{P as ee,a as N,b as P,d as p,x as lt}from"./chunk-XHCIOLJP.js";import{F as te,J as ne,K as re,N as dt,d as et,e as tt,f as nt,g as rt,m as ot,r as it,z as at}from"./chunk-SX76UGEY.js";import{A as v,C as x,E as Qe,F as le,H as I,I as Ze,J as Te,K as Z,v as Xe,y as u,z as Q}from"./chunk-6OIHST4I.js";import wt from"node:fs/promises";import G from"node:path";var R="_workspace";function W(e){return G.join(e,"history",`${R}.jsonl`)}function Ce(e,t){return{metadata:{id:R,title:"Workspace state",description:"Audited singleton workspace document state.",type:"Chore",status:"open",priority:2,tags:["workspace-history"],created_at:t,updated_at:t,documents:e},body:""}}function U(e,t=e.length){let n=mt();for(let r of e.slice(0,t))n=ht(n,r.patch).document;return pt(n)}function K(e){return"documents"in e.metadata&&typeof e.metadata.documents=="object"&&e.metadata.documents!==null&&!Array.isArray(e.metadata.documents)?e.metadata.documents:{}}function J(e){throw new x(`Workspace history verification failed: ${e.join(", ")}`,v.CONFLICT,{code:"workspace_history_chain_invalid",reason:"workspace_history_chain_verification_failed",verification_errors:[...e],required:"Repair the _workspace history chain before reading, reconciling, restoring, or appending audited singleton state.",why:"Continuing against an unverifiable append-only stream could hide or compound workspace state corruption.",examples:["pm history _workspace --verify --json","pm validate --check-history-drift --fix-hints --json"],nextSteps:["Inspect the exact verification_errors and preserve the corrupt stream as evidence.","Use the history-drift remediation returned by validate before retrying the refused operation."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify --json"}})}function de(e,t){let n=G.resolve(t),r=G.relative(e,n).replaceAll("\\","/");if(r.length===0||r===".."||r.startsWith("../")||G.isAbsolute(r))throw new TypeError("Workspace history document path must stay inside the tracker root");return{documentPath:r,absolutePath:n}}async function Jr(e){let t=await F(W(e),R),n=V(t);n.ok||J(n.errors);let r=K(t.length===0?Q:U(t)),i=[],a=[],s=[],l=[];for(let _ of Object.keys(r).sort()){let f;try{let w=de(e,G.resolve(e,_));if(f=await I(w.absolutePath),f===null){s.push(_);continue}let g=JSON.parse(f);(N(g)===N(r[_])?i:a).push(_)}catch{l.push(_)}}return{ok:a.length===0&&s.length===0&&l.length===0,document_count:Object.keys(r).length,matching_documents:i,mismatched_documents:a,missing_documents:s,unreadable_documents:l}}async function gt(e){let t=W(e.pmRoot),n=await F(t,R),r=V(n);r.ok||J(r.errors);let i=e.idempotencyKey===void 0?void 0:n.find(g=>g.op===`${e.op}:${e.idempotencyKey}`);if(i)return{entry:i,historyPath:t};let a=ee(),s=n.length===0?Q:U(n),l=K(s),_=l[e.documentPath];if(_!==void 0&&N(_)!==N(e.before))throw new x(`Workspace history state for "${e.documentPath}" changed outside the audited mutation path.`,v.CONFLICT,{code:"workspace_history_state_conflict",reason:"out_of_band_workspace_state",required:"Reconcile the singleton document with its matching _workspace history state before retrying the mutation.",why:"Accepting the write would make the append-only audit stream describe a state that was not actually observed.",examples:["pm history _workspace --verify","pm validate --check-history-drift --fix-hints"],nextSteps:["Review the version-control change that altered the singleton and preserve the intended document plus its matching workspace history.","Rerun the original mutation only after the on-disk singleton agrees with the latest audited workspace state."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify"}});let f=Ce({...l,[e.documentPath]:e.after},n.length===0?a:s.metadata.created_at),w=oe({nowIso:a,author:e.author,op:e.idempotencyKey===void 0?e.op:`${e.op}:${e.idempotencyKey}`,before:s,after:f,message:e.message});return await ie(t,w),{entry:w,historyPath:t}}async function Yr(e){let t=await D(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await gt(e)}finally{await t()}}async function Xr(e){let t=await D(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let n=W(e.pmRoot),r=await F(n,R),i=V(r);i.ok||J(i.errors);let a=r.length===0?Q:U(r),s=oe({nowIso:ee(),author:e.author,op:e.op,before:a,after:a,message:e.message,context:e.context});return await ie(n,s),{entry:s,historyPath:n}}finally{await t()}}async function bt(e,t){if(t===e.raw)return!1;let n=t===null?null:JSON.parse(t),r=JSON.parse(e.raw);await Z(e.filePath,e.raw);try{(t!==null||e.recordCreation!==!1)&&await gt({pmRoot:e.pmRoot,documentPath:G.relative(e.pmRoot,e.filePath).replaceAll("\\","/"),before:n,after:r,op:e.op,idempotencyKey:e.idempotencyKey,author:e.author,lockTtlSeconds:e.lockTtlSeconds,lockWaitMs:e.lockWaitMs,message:e.message})}catch(i){throw t===null?await wt.rm(e.filePath,{force:!0}):await Z(e.filePath,t),i}return!0}async function vt(e){let{documentPath:t}=de(e.pmRoot,e.filePath),n=await D(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let r=await I(e.filePath);if(e.dryRun===!0||e.idempotencyKey!==void 0){let a=await F(W(e.pmRoot),R),s=V(a);s.ok||J(s.errors);let l=K(a.length===0?Q:U(a))[t];if(l!==void 0&&N(l)!==N(r===null?null:JSON.parse(r)))throw new x(`Workspace history state for "${t}" changed outside the audited mutation path.`,v.CONFLICT,{code:"workspace_history_state_conflict"});if(e.idempotencyKey!==void 0&&a.some(_=>_.op===`${e.op}:${e.idempotencyKey}`))return{changed:!1,result:void 0,replayed:!0}}let i=await e.mutate(r);return JSON.parse(i.raw),e.dryRun===!0?{changed:r!==i.raw,result:i.result}:{changed:await bt({...e,raw:i.raw},r),result:i.result}}finally{await n()}}async function Qr(e){let t=await D(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await bt(e,await I(e.filePath))}finally{await t()}}async function Zr(e){let t=e.authorizationDecision.trim();if(!t)throw new TypeError("Workspace history reconciliation requires an authorization decision");let n=await D(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let{documentPath:r,absolutePath:i}=de(e.pmRoot,e.filePath),a=W(e.pmRoot),s=await F(a,R),l=V(s);l.ok||J(l.errors);let _=U(s),f=K(_);if(!Object.hasOwn(f,r))throw new TypeError(`Workspace history does not govern document ${r}`);let w=await I(i);if(w===null)throw new TypeError(`Workspace history document is missing: ${r}`);let g=JSON.parse(w);if(N(f[r])===N(g))return{changed:!1,historyPath:a};let S=ee(),X=oe({nowIso:S,author:e.author,op:e.op,before:_,after:Ce({...f,[r]:g},_.metadata.created_at),message:e.message,context:{reason:"out_of_band_workspace_state_reconciliation",document_path:r,authorization_decision:t}});return await ie(a,X),{changed:!0,entry:X,historyPath:a}}finally{await n()}}async function eo(e){let t=await D(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let{documentPath:n,absolutePath:r}=de(e.pmRoot,e.filePath),i=await F(W(e.pmRoot),R),a=V(i);if(a.ok||J(a.errors),!Number.isInteger(e.targetVersion)||e.targetVersion<1||e.targetVersion>i.length)throw new TypeError(`Invalid workspace history target version: ${String(e.targetVersion)}`);let s=K(U(i,e.targetVersion))[n];if(s===void 0)throw new TypeError(`Workspace history version ${e.targetVersion} does not contain ${n}`);let l=await I(r),_=`${JSON.stringify(s,null,2)}
|
|
2
2
|
`;if(l===_)return{document_path:n,restored_from_version:e.targetVersion,changed:!1};let f=U(i),w=ee(),g=oe({nowIso:w,author:e.author,op:e.op,before:f,after:Ce({...K(f),[n]:s},f.metadata.created_at),message:e.message,context:{reason:"workspace_state_restore",document_path:n,restored_from_version:e.targetVersion,replaced_out_of_band_state:!0}});await Z(r,_);try{await ie(W(e.pmRoot),g)}catch(S){throw l===null?await wt.rm(r,{force:!0}):await Z(r,l),S}return{document_path:n,restored_from_version:e.targetVersion,changed:!0}}finally{await t()}}var O={ok:!1,path:[]};function Pe(e,t){return{ok:!1,path:[e,...t.path]}}var c=e=>typeof e=="string"?{ok:!0,value:e}:O,h=e=>typeof e=="boolean"?{ok:!0,value:e}:O;function k(e={}){return t=>typeof t!="number"||!Number.isFinite(t)||e.int&&(!Number.isInteger(t)||!Number.isSafeInteger(t))||e.positive&&t<=0||typeof e.min=="number"&&t<e.min||typeof e.max=="number"&&t>e.max?O:{ok:!0,value:t}}function y(...e){return t=>typeof t=="string"&&e.includes(t)?{ok:!0,value:t}:O}function d(e,t){return n=>{if(!Array.isArray(n)||t!==void 0&&n.length>t)return O;let r=[];for(let[i,a]of n.entries()){let s=e(a);if(!s.ok)return Pe(String(i),s);r.push(s.value)}return{ok:!0,value:r}}}function je(e,t){return n=>typeof n=="string"&&n.length>0&&n.length<=e&&n===n.trim()&&(t===void 0||t.test(n))?{ok:!0,value:n}:O}function o(e){return t=>t===void 0?{ok:!0,value:void 0}:e(t)}function ue(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return O;let n={};for(let[r,i]of Object.entries(t)){let a=e(i);if(!a.ok)return Pe(r,a);n[r]=a.value}return{ok:!0,value:n}}}function m(e){return t=>{if(typeof t!="object"||t===null||Array.isArray(t))return O;let n=t,r={};for(let[i,a]of Object.entries(e)){let s=a(n[i]);if(!s.ok)return Pe(i,s);s.value!==void 0&&(r[i]=s.value)}return{ok:!0,value:r}}}var mn=m({key:c,values:d(c),required:o(h),aliases:o(d(c)),description:o(c)}),pn=m({command:y("create","update"),option:c,required:o(h),visible:o(h),enabled:o(h)}),hn=m({name:c,description:o(c),default_status:o(c),execution_role:o(y("agent","human","gate")),folder:o(c),aliases:o(d(c)),required_create_fields:o(d(c)),required_create_repeatables:o(d(c)),options:o(d(mn)),command_option_policies:o(d(pn))}),yn=m({id:c,aliases:o(d(c)),roles:o(d(y(...et))),description:o(c),order:o(k())}),kn=m({key:c,metadata_key:o(c),front_matter_key:o(c),cli_flag:o(c),cli_aliases:o(d(c)),description:o(c),type:o(y(...tt)),commands:o(d(y(...nt))),repeatable:o(h),required:o(h),required_on_create:o(h),required_types:o(d(c)),allow_unset:o(h)}),wn=e=>{if(!Array.isArray(e)||e.length!==2)return O;let[t,n]=e;return typeof t!="string"||typeof n!="string"?O:{ok:!0,value:[t,n]}},gn=m({type:c,allowed_transitions:d(wn)}),bn=o(m({version:o(k({int:!0})),files:o(m({types:o(c),statuses:o(c),fields:o(c),workflows:o(c)})),statuses:o(d(yn)),fields:o(d(kn)),workflow:o(m({draft_status:o(c),open_status:o(c),in_progress_status:o(c),blocked_status:o(c),close_status:o(c),canceled_status:o(c)})),type_workflows:o(d(gn)),unknown_field_policy:o(y(...rt))})),vn=o(m({preset:o(y(...ot)),ownership_enforcement:o(y("none","warn","strict")),create_mode_default:o(y("progressive","strict")),close_validation_default:o(y("off","warn","strict")),require_close_reason:o(h),parent_reference:o(y("warn","strict_error")),metadata_profile:o(y("core","strict","custom")),force_required_for_stale_lock:o(h),create_default_type:o(c),workflow_enforcement:o(y("off","warn","strict")),start_blocker_enforcement:o(y("off","warn","strict")),duplicate_detection_mode:o(y("off","advisory","strict")),duplicate_detection_threshold:o(k({min:0,max:1})),duplicate_detection_limit:o(k({int:!0,min:0,max:20}))})),xn=m({name:c,disabled:o(h),require_trusted:o(h),require_provenance:o(h),sandbox_profile:o(y("none","restricted","strict")),allowed_capabilities:o(d(c)),blocked_capabilities:o(d(c)),allowed_surfaces:o(d(c)),blocked_surfaces:o(d(c)),allowed_commands:o(d(c)),blocked_commands:o(d(c)),allowed_actions:o(d(c)),blocked_actions:o(d(c)),allowed_services:o(d(c)),blocked_services:o(d(c))}),Ae=y("block","warn"),Sn=e=>typeof e=="string"?Ae(e):m({global:o(Ae),project:o(Ae)})(e),En=o(m({mode:o(y("off","warn","enforce")),trust_mode:o(y("off","warn","enforce")),pm_max_version_exceeded_mode:o(Sn),require_provenance:o(h),trusted_extensions:o(d(c)),default_sandbox_profile:o(y("none","restricted","strict")),allowed_extensions:o(d(c)),blocked_extensions:o(d(c)),allowed_capabilities:o(d(c)),blocked_capabilities:o(d(c)),allowed_surfaces:o(d(c)),blocked_surfaces:o(d(c)),allowed_commands:o(d(c)),blocked_commands:o(d(c)),allowed_actions:o(d(c)),blocked_actions:o(d(c)),allowed_services:o(d(c)),blocked_services:o(d(c)),extension_overrides:o(d(xn))})),$=je(128),On=m({harness:je(128,/^[a-z0-9]+(?:-[a-z0-9]+)*$/u),environment_keys:o(d($,64)),model_environment_keys:o(d($,64)),session_environment_keys:o(d($,64)),provenance_environment_keys:o(ue(d($,64))),provenance_resolvers:o(ue(y("ai_agent_version","claude_session_file"))),provenance_unavailable_dimensions:o(d($,64)),argv_markers:o(d($,64)),client_names:o(d($,64))}),xt={version:k({int:!0}),id_prefix:c,ids:o(m({token_length:o(k({int:!0,min:4,max:12}))})),author_default:c,agent_identity:o(m({probes_enabled:o(h),identity_vocabulary:o(m({version:k({int:!0,positive:!0}),aliases:ue(je(128,/^[a-z0-9]+(?:-[a-z0-9]+)*$/u))})),harness_signals:d(On)})),mutation_guard:o(m({require_attributed_author:o(h),secret_guard:o(y("off","advise","block")),stale_in_progress_hours:o(k({int:!0,positive:!0}))})),item_format:o(y("toon","json_markdown")),locks:m({ttl_seconds:k({int:!0}),wait_ms:o(k({int:!0,min:0}))}),checkpoints:o(m({retention_days:o(k({int:!0,positive:!0}))})),output:m({default_format:y("toon","json")}),ux:o(m({deprecation_hints:o(h)})),history:o(m({missing_stream:y("auto_create","strict_error"),compact_policy:o(m({enabled:o(h),max_entries:o(k({int:!0,positive:!0})),trigger:o(y("health_warn","auto"))}))})),validation:o(m({sprint_release_format:y("warn","strict_error"),parent_reference:o(y("warn","strict_error")),metadata_profile:o(y("core","strict","custom")),metadata_required_fields:o(d(c)),lifecycle_stale_blocker_reason_patterns:o(d(c)),lifecycle_closure_like_blocked_reason_patterns:o(d(c)),lifecycle_closure_like_resolution_patterns:o(d(c)),lifecycle_closure_like_actual_result_patterns:o(d(c)),estimate_defaults_by_type:o(ue(k({int:!0,positive:!0})))})),governance:vn,workflow:o(m({definition_of_done:d(c)})),testing:o(m({record_results_to_items:h,allow_untrusted_linked_tests:o(h)})),telemetry:o(m({enabled:h,first_run_prompt_completed:o(h),capture_level:o(y("minimal","redacted","max")),endpoint:o(c),installation_id:o(c),retention_days:o(k({int:!0,positive:!0}))})),agent_guidance:o(m({prompt_completed:o(h),declined:o(h),declined_at:o(c),template_version:o(k({int:!0,positive:!0})),last_checked_files:o(d(c))})),item_types:o(m({definitions:d(hn)})),schema:bn,context:o(m({default_depth:o(y(...at)),activity_limit:o(k({int:!0,positive:!0})),stale_threshold_days:o(k({int:!0,positive:!0})),next_ranking_policy:o(y("priority_floor","weighted")),sections:o(m({hierarchy:o(h),activity:o(h),progress:o(h),recently_created:o(h),unparented:o(h),blockers:o(h),files:o(h),workload:o(h),staleness:o(h),tests:o(h)}))})),extensions:m({enabled:d(c),disabled:d(c),policy:En}),search:m({score_threshold:k(),hybrid_semantic_weight:o(k()),max_results:k({int:!0}),embedding_model:c,embedding_corpus_max_characters:o(k()),embedding_batch_size:k({int:!0}),embedding_timeout_ms:o(k({int:!0})),scanner_max_batch_retries:k({int:!0}),provider:o(c),default_mode:o(y("auto","keyword","semantic","hybrid")),corpus_fields:o(d(c)),mutation_refresh_policy:o(y("cache_only","semantic_configured","semantic_auto")),query_expansion:o(m({enabled:o(h),provider:o(c)})),rerank:o(m({enabled:o(h),model:o(c),top_k:o(k({int:!0,positive:!0}))})),bm25:o(m({k1:o(k()),b:o(k())}))}),providers:m({openai:m({base_url:c,api_key:c,model:c}),ollama:m({base_url:c,model:c})}),vector_store:m({adapter:o(c),collection_name:o(c),qdrant:m({url:c,api_key:c}),lancedb:m({path:c})})},Tn=m(xt),St=Object.freeze(Object.keys(xt));function _e(e){let t=Tn(e);return t.ok?{success:!0,data:t.value}:{success:!1,path:t.path.join(".")}}import{AsyncLocalStorage as In}from"node:async_hooks";import{lstat as Rn,realpath as Lt}from"node:fs/promises";import qt from"node:path";function fe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ne(e,t,n,r=[]){if(P(e,t)&&(r.length>0||fe(n)))return n;if(P(e,n)||P(t,n))return t;if((e===void 0||fe(e))&&fe(t)&&fe(n)){let i=e??{},a=new Set([...Object.keys(i),...Object.keys(t),...Object.keys(n)]);return Object.fromEntries([...a].flatMap(s=>{let l=Ne(Object.hasOwn(i,s)?i[s]:void 0,Object.hasOwn(t,s)?t[s]:void 0,Object.hasOwn(n,s)?n[s]:void 0,[...r,s]);return l===void 0?[]:[[s,l]]}))}throw new x(`Settings changed concurrently at ${r.join(".")||"<root>"}; read the latest settings and reapply the intended change.`,v.CONFLICT,{reason:"stale_settings_snapshot",required:"Read a fresh settings snapshot and reapply the intended change.",why:"Another writer changed the same setting after this snapshot was read.",examples:["pm config project export --json"],nextSteps:["Read the current settings, then retry the original config operation."]})}var Cn={Epic:2880,Feature:480,Story:480,Milestone:2880,Task:120,Issue:60,Bug:60,Chore:30,Decision:15,Plan:120},Et=120;function Ie(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function Tt(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n.toLowerCase(),r);return t}var An=Tt(Cn),Ot=new WeakMap;function Pn(e){let t=Ot.get(e);if(t)return t;let n=Tt(e);return Ot.set(e,n),n}function co(e,t){let n=(e??"").trim().toLowerCase();if(n.length===0)return Et;if(t){let i=Pn(t).get(n);if(Ie(i))return Math.floor(i)}let r=An.get(n);return Ie(r)?Math.floor(r):Et}function Re(e){let t={};if(e===null||typeof e!="object"||Array.isArray(e))return t;for(let[n,r]of Object.entries(e)){let i=n.trim();i.length===0||!Ie(r)||(t[i]=Math.floor(r))}return t}import{stat as jn}from"node:fs/promises";var me=new Map;function Ct(e){return[...new Set(e.map(t=>t.trim()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}async function Nn(e){try{let t=await jn(e);return{path:e,mtime_ms:t.mtimeMs,size:t.size}}catch{return{path:e,mtime_ms:null,size:null}}}async function L(e){let t=Ct(e),n=await Promise.all(t.map(r=>Nn(r)));return n.sort((r,i)=>r.path.localeCompare(i.path)),n}function ae(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(r.path!==i.path||r.mtime_ms!==i.mtime_ms||r.size!==i.size)return!1}return!0}function At(e){return me.get(e)}function pe(e,t){let n=Ct(t.tracked_paths),r=[...t.signatures].map(i=>({path:i.path,mtime_ms:i.mtime_ms,size:i.size})).sort((i,a)=>i.path.localeCompare(a.path));me.set(e,{tracked_paths:n,signatures:r,value:t.value})}function H(e){if(e){me.delete(e);return}me.clear()}var Me=new In;async function jo(e,t,n=()=>!0){let r=new Set([qt.resolve(e)]);try{r.add(await Lt(e))}catch{}let i=!1,a=[r,()=>!i&&n()];try{return await Me.run([...Me.getStore()??[],a],t)}finally{i=!0}}function Ln(e){let t=qt.resolve(e);return Me.getStore()?.some(([n,r])=>n.has(t)&&r())??!1}var qn="settings:write",zt=Symbol("pm.settings.persist_source"),Mt=Symbol("pm.settings.fallback_origin"),Dt=Symbol("pm.settings.fallback_baseline"),zn=128,Mn=new Set(["off","advisory","strict"]);function Pt(e){return structuredClone(Xe[e])}function Dn(e){return e==="minimal"||e==="default"||e==="strict"||e==="custom"?e:u.governance.preset}var Fn=new Set(it);function Ft(e){return Fn.has(e)}function jt(e,t){let n=typeof t.create_default_type=="string"?t.create_default_type.trim():void 0;return n&&n.length>0&&(e.create_default_type=n),(t.workflow_enforcement==="off"||t.workflow_enforcement==="warn"||t.workflow_enforcement==="strict")&&(e.workflow_enforcement=t.workflow_enforcement),Ft(t.start_blocker_enforcement)&&(e.start_blocker_enforcement=t.start_blocker_enforcement),t.require_close_reason===!1&&(e.require_close_reason=!1),e.duplicate_detection_mode=t.duplicate_detection_mode,e.duplicate_detection_threshold=t.duplicate_detection_threshold,e.duplicate_detection_limit=t.duplicate_detection_limit,e}function Vn(e){return e.preset==="custom"?jt({preset:"custom",ownership_enforcement:e.ownership_enforcement,create_mode_default:e.create_mode_default,close_validation_default:e.close_validation_default,parent_reference:e.parent_reference,metadata_profile:e.metadata_profile,force_required_for_stale_lock:e.force_required_for_stale_lock},e):jt({preset:e.preset},e)}function Wn(e){let t=typeof e.create_default_type=="string"?e.create_default_type.trim():void 0,n={};t&&t.length>0&&(n.create_default_type=t),(e.workflow_enforcement==="off"||e.workflow_enforcement==="warn"||e.workflow_enforcement==="strict")&&(n.workflow_enforcement=e.workflow_enforcement),Ft(e.start_blocker_enforcement)&&(n.start_blocker_enforcement=e.start_blocker_enforcement),typeof e.require_close_reason=="boolean"&&(n.require_close_reason=e.require_close_reason),Mn.has(String(e.duplicate_detection_mode))&&(n.duplicate_detection_mode=e.duplicate_detection_mode);let r=e.duplicate_detection_threshold;[typeof r=="number",Number.isFinite(r),Number(r)>=0,Number(r)<=1].every(Boolean)&&(n.duplicate_detection_threshold=r);let i=e.duplicate_detection_limit;return[typeof i=="number",Number.isSafeInteger(i),Number(i)>=0,Number(i)<=20].every(Boolean)&&(n.duplicate_detection_limit=i),n}function Vt(e){let t=e.governance??{},n=Dn(t.preset),r=Wn(t);if(n==="custom"){let s=Pt("default"),l=r.require_close_reason??s.require_close_reason;return{preset:n,ownership_enforcement:t.ownership_enforcement??s.ownership_enforcement,create_mode_default:t.create_mode_default??s.create_mode_default,close_validation_default:t.close_validation_default??s.close_validation_default,parent_reference:t.parent_reference??s.parent_reference,metadata_profile:t.metadata_profile??s.metadata_profile,force_required_for_stale_lock:t.force_required_for_stale_lock??s.force_required_for_stale_lock,...r,require_close_reason:l,duplicate_detection_mode:r.duplicate_detection_mode??s.duplicate_detection_mode,duplicate_detection_threshold:r.duplicate_detection_threshold??s.duplicate_detection_threshold,duplicate_detection_limit:r.duplicate_detection_limit??s.duplicate_detection_limit}}let i=Pt(n),a=r.require_close_reason??i.require_close_reason;return{preset:n,...i,...r,require_close_reason:a}}function Ve(){return structuredClone(u)}function Wt(e){return e==="cache_only"||e==="semantic_configured"||e==="semantic_auto"?e:u.search.mutation_refresh_policy}function Ut(e){return e==="auto"||e==="keyword"||e==="semantic"||e==="hybrid"?e:"auto"}function $t(e){return typeof e=="boolean"?e:u.search.query_expansion.enabled}function Ht(e){return typeof e!="string"?u.search.query_expansion.provider:e.trim()}function Bt(e){return typeof e=="boolean"?e:u.search.rerank.enabled}function Gt(e){return typeof e!="string"?u.search.rerank.model:e.trim()}function Kt(e){return typeof e=="number"&&Number.isFinite(e)&&Number.isInteger(e)&&e>0?e:u.search.rerank.top_k}function Jt(e){if(typeof e!="string")return u.vector_store.collection_name;let n=e.trim().replaceAll(/[^a-zA-Z0-9_-]/g,"_").slice(0,zn);return n.length>0?n:u.vector_store.collection_name}function Le(e){return{present:Array.isArray(e),values:Array.isArray(e)?structuredClone(e):[]}}function Yt(e,t){let n=e.schema,r=Le(n?.statuses),i=Le(n?.fields),a=Le(n?.type_workflows);return{persisted_settings:structuredClone(e),source_settings:structuredClone(e),has_source_item_type_definitions:Array.isArray(e.item_types?.definitions),source_item_type_definitions:Y(e.item_types?.definitions),has_source_schema_statuses:r.present,source_schema_statuses:r.values,has_source_schema_fields:i.present,source_schema_fields:i.values,has_source_schema_type_workflows:a.present,source_schema_type_workflows:a.values,runtime_item_type_definitions:Y(t.item_types?.definitions),runtime_schema_statuses:structuredClone(t.schema.statuses),runtime_schema_fields:structuredClone(t.schema.fields),runtime_schema_type_workflows:structuredClone(t.schema.type_workflows??[])}}function ke(e,t){Object.defineProperty(e,zt,{value:t,writable:!0,configurable:!0,enumerable:!1})}function We(e){let t=e[zt];if(!(!t||typeof t!="object"))return t}function No(e){let t=We(e);if(t){let n=structuredClone(t);n.source_settings.item_format=e.item_format,ke(e,n)}}function he(e){let t=structuredClone(e.settings),n=We(e.settings);n&&ke(t,n);let r=Ue(e.settings);return r!==void 0&&Xt(t,r),{settings:t,metadata:{has_explicit_item_format:e.metadata.has_explicit_item_format},warnings:[...e.warnings]}}function Un(e,t,n){let r=ne(t);return[n,re(e,r.files.types,te.types),re(e,r.files.statuses,te.statuses),re(e,r.files.fields,te.fields),re(e,r.files.workflows,te.workflows)]}async function $n(e,t,n){let r=await L(t);pe(e,{tracked_paths:t,signatures:r,value:he(n)})}async function Hn(e,t,n){try{await $n(e,t,n)}catch{H(e)}}function Nt(e,t){return e.find(n=>n.path===t)}function Bn(e,t,n){for(let r of n){let i=Nt(e,r),a=Nt(t,r);if(!i||!a||!ae([i],[a]))return!1}return!0}async function qe(e,t,n,r,i){try{let a=await L(t);if(!Bn(r,a,i)){H(e);return}pe(e,{tracked_paths:t,signatures:a,value:he(n)})}catch{H(e)}}function Gn(e,t){let n=ne(e.schema),r=Y(e.item_types?.definitions);if(!t)return{item_type_definitions:r,schema_statuses:n.statuses,schema_fields:n.fields,schema_type_workflows:n.type_workflows};let i=n.type_workflows??[],a=P(r,t.runtime_item_type_definitions),s=P(n.statuses,t.runtime_schema_statuses),l=P(n.fields,t.runtime_schema_fields),_=P(i,t.runtime_schema_type_workflows);return{item_type_definitions:a?t.has_source_item_type_definitions?Y(t.source_item_type_definitions):[]:r,schema_statuses:s?t.has_source_schema_statuses?structuredClone(t.source_schema_statuses):[]:n.statuses,schema_fields:l?t.has_source_schema_fields?structuredClone(t.source_schema_fields):[]:n.fields,schema_type_workflows:_?t.has_source_schema_type_workflows?structuredClone(t.source_schema_type_workflows):void 0:n.type_workflows}}function Xt(e,t){Object.defineProperty(e,Mt,{value:t,writable:!0,configurable:!0,enumerable:!1})}function Io(e){return Ue(e)!==void 0}function Ue(e){let t=e[Mt];return typeof t=="string"?t:void 0}function Kn(e){return e[Dt]}function Jn(e,t){Object.defineProperty(e,Dt,{value:t,writable:!0,configurable:!0,enumerable:!1})}function j(e){let t=Ve();return e!==void 0&&Xt(t,e),{settings:t,metadata:{has_explicit_item_format:!1},warnings:e?[e]:[]}}function Qt(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e.item_format;return t==="toon"||t==="json_markdown"}function De(e){return[...new Set((e??[]).map(t=>t.trim()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}function Zt(e){let t=u.agent_guidance,n=e?.template_version;return{prompt_completed:e?.prompt_completed===!0,declined:e?.declined===!0,declined_at:typeof e?.declined_at=="string"?e.declined_at:t.declined_at,template_version:typeof n=="number"&&Number.isInteger(n)&&n>0?n:t.template_version,last_checked_files:De(e?.last_checked_files??t.last_checked_files)}}function A(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}function Yn(e){return e==="off"||e==="warn"||e==="enforce"?e:u.extensions.policy.mode}function Xn(e){return e==="off"||e==="warn"||e==="enforce"?e:u.extensions.policy.trust_mode}function en(e){return e==="none"||e==="restricted"||e==="strict"?e:u.extensions.policy.default_sandbox_profile}function Qn(e){let t=e.name.trim().toLowerCase();if(t.length===0)return null;let n={name:t};e.disabled===!0&&(n.disabled=!0),e.require_trusted===!0&&(n.require_trusted=!0),e.require_provenance===!0&&(n.require_provenance=!0),e.sandbox_profile!==void 0&&(n.sandbox_profile=en(e.sandbox_profile));let r=A(e.allowed_capabilities),i=A(e.blocked_capabilities),a=A(e.allowed_surfaces),s=A(e.blocked_surfaces),l=A(e.allowed_commands),_=A(e.blocked_commands),f=A(e.allowed_actions),w=A(e.blocked_actions),g=A(e.allowed_services),S=A(e.blocked_services);return r.length>0&&(n.allowed_capabilities=r),i.length>0&&(n.blocked_capabilities=i),a.length>0&&(n.allowed_surfaces=a),s.length>0&&(n.blocked_surfaces=s),l.length>0&&(n.allowed_commands=l),_.length>0&&(n.blocked_commands=_),f.length>0&&(n.allowed_actions=f),w.length>0&&(n.blocked_actions=w),g.length>0&&(n.allowed_services=g),S.length>0&&(n.blocked_services=S),n}function Zn(e){let t=new Map;for(let n of e??[]){let r=Qn(n);r&&t.set(r.name,r)}return[...t.values()].sort((n,r)=>n.name.localeCompare(r.name))}function ze(e){return e==="block"||e==="warn"?e:void 0}function er(e){if(typeof e=="string")return ze(e);if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let t=ze(e.global),n=ze(e.project);return t===void 0&&n===void 0?void 0:{...t!==void 0?{global:t}:{},...n!==void 0?{project:n}:{}}}}function T(e,t){return A(e?.[t]??u.extensions.policy[t])}function tn(e){let t=er(e?.pm_max_version_exceeded_mode);return{mode:Yn(e?.mode),trust_mode:Xn(e?.trust_mode),...t!==void 0?{pm_max_version_exceeded_mode:t}:{},require_provenance:e?.require_provenance===!0,trusted_extensions:T(e,"trusted_extensions"),default_sandbox_profile:en(e?.default_sandbox_profile),allowed_extensions:T(e,"allowed_extensions"),blocked_extensions:T(e,"blocked_extensions"),allowed_capabilities:T(e,"allowed_capabilities"),blocked_capabilities:T(e,"blocked_capabilities"),allowed_surfaces:T(e,"allowed_surfaces"),blocked_surfaces:T(e,"blocked_surfaces"),allowed_commands:T(e,"allowed_commands"),blocked_commands:T(e,"blocked_commands"),allowed_actions:T(e,"allowed_actions"),blocked_actions:T(e,"blocked_actions"),allowed_services:T(e,"allowed_services"),blocked_services:T(e,"blocked_services"),extension_overrides:Zn(e?.extension_overrides??u.extensions.policy.extension_overrides)}}function nn(e){return[...new Set((e??[]).map(n=>n.trim().toLowerCase().replaceAll("-","_")))].filter(n=>n.length>0).sort((n,r)=>n.localeCompare(r)).filter(n=>["author","acceptance_criteria","estimated_minutes","close_reason","reviewer","risk","confidence","sprint","release"].includes(n))}function q(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}function b(e,t){return e===void 0?t:e}function C(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function Fe(e){return Array.isArray(e)?e:[]}function tr(e,t,n){return{...t.validation,...e.validation,parent_reference:n.parent_reference,metadata_profile:n.metadata_profile,metadata_required_fields:nn(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:q(e.validation?.lifecycle_stale_blocker_reason_patterns??t.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:q(e.validation?.lifecycle_closure_like_blocked_reason_patterns??t.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:q(e.validation?.lifecycle_closure_like_resolution_patterns??t.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:q(e.validation?.lifecycle_closure_like_actual_result_patterns??t.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:Re(e.validation?.estimate_defaults_by_type)}}function nr(e,t){return{enabled:e.telemetry?.enabled??t.telemetry.enabled,first_run_prompt_completed:e.telemetry?.first_run_prompt_completed??t.telemetry.first_run_prompt_completed,capture_level:e.telemetry?.capture_level??t.telemetry.capture_level,endpoint:e.telemetry?.endpoint??t.telemetry.endpoint,installation_id:e.telemetry?.installation_id??t.telemetry.installation_id,retention_days:e.telemetry?.retention_days??t.telemetry.retention_days}}function rr(e,t){return{...t.search,...e.search,default_mode:Ut(e.search?.default_mode),mutation_refresh_policy:Wt(e.search?.mutation_refresh_policy),query_expansion:{...t.search.query_expansion,...e.search?.query_expansion,enabled:$t(e.search?.query_expansion?.enabled),provider:Ht(e.search?.query_expansion?.provider)},rerank:{...t.search.rerank,...e.search?.rerank,enabled:Bt(e.search?.rerank?.enabled),model:Gt(e.search?.rerank?.model),top_k:Kt(e.search?.rerank?.top_k)}}}function or(e,t){return{adapter:e.vector_store.adapter??t.vector_store.adapter,collection_name:Jt(e.vector_store.collection_name),qdrant:{...t.vector_store.qdrant,...e.vector_store.qdrant},lancedb:{...t.vector_store.lancedb,...e.vector_store.lancedb}}}function ir(e,t){return e.item_format==="json_markdown"?"toon":e.item_format??t.item_format}function ar(e,t){return{default_depth:e.context?.default_depth??t.context.default_depth,activity_limit:e.context?.activity_limit??t.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??t.context.stale_threshold_days,next_ranking_policy:e.context?.next_ranking_policy??t.context.next_ranking_policy,sections:{...t.context.sections,...e.context?.sections}}}function sr(e,t){return{openai:{...t.providers.openai,...e.providers.openai},ollama:{...t.providers.ollama,...e.providers.ollama}}}function Y(e){let t=(e??[]).map(r=>st(r)).filter(r=>r!==null),n=new Map;for(let r of t)n.set(r.name.toLowerCase(),r);return[...n.values()].sort((r,i)=>r.name.localeCompare(i.name))}function ye(e){let t=Ve(),n=Vt({governance:e.governance??{preset:"default"}});return{...t,...e,item_format:ir(e,t),locks:{...t.locks,...e.locks},ids:{...t.ids,...e.ids},agent_identity:structuredClone(e.agent_identity??t.agent_identity),mutation_guard:{...t.mutation_guard,...e.mutation_guard},checkpoints:{...t.checkpoints,...e.checkpoints},output:{...t.output,...e.output},ux:{...t.ux,...e.ux},history:{...t.history,...e.history,compact_policy:{...t.history.compact_policy,...e.history?.compact_policy}},validation:tr(e,t,n),governance:n,workflow:{definition_of_done:[...e.workflow?.definition_of_done??t.workflow.definition_of_done]},testing:{record_results_to_items:e.testing?.record_results_to_items??t.testing.record_results_to_items,allow_untrusted_linked_tests:e.testing?.allow_untrusted_linked_tests??t.testing.allow_untrusted_linked_tests},telemetry:nr(e,t),agent_guidance:Zt(e.agent_guidance??t.agent_guidance),item_types:{definitions:Y(e.item_types?.definitions)},schema:ne(e.schema??t.schema),context:ar(e,t),extensions:{enabled:[...e.extensions.enabled],disabled:[...e.extensions.disabled],policy:tn(e.extensions.policy??t.extensions.policy)},search:rr(e,t),providers:sr(e,t),vector_store:or(e,t)}}function cr(e){e.agent_identity=p(e.agent_identity,["probes_enabled","identity_vocabulary","harness_signals"]);let t=e.agent_identity;Object.hasOwn(t,"identity_vocabulary")&&(t.identity_vocabulary=p(C(t.identity_vocabulary),["version","aliases"])),e.agent_identity.harness_signals=Fe(e.agent_identity.harness_signals).map(n=>p(C(n),["harness","environment_keys","model_environment_keys","session_environment_keys","provenance_environment_keys","provenance_resolvers","provenance_unavailable_dimensions","argv_markers","client_names"])),e.locks=p(e.locks,["ttl_seconds","wait_ms"]),e.ids=p(e.ids,["token_length"]),e.mutation_guard=p(e.mutation_guard,["require_attributed_author","secret_guard","stale_in_progress_hours"]),e.checkpoints=p(e.checkpoints,["retention_days"]),e.output=p(e.output,["default_format"]),e.ux=p(e.ux,["deprecation_hints"]),e.history=p(e.history,["missing_stream","compact_policy"]),e.validation=p(e.validation,["sprint_release_format","parent_reference","metadata_profile","metadata_required_fields","lifecycle_stale_blocker_reason_patterns","lifecycle_closure_like_blocked_reason_patterns","lifecycle_closure_like_resolution_patterns","lifecycle_closure_like_actual_result_patterns","estimate_defaults_by_type"]),e.governance=p(e.governance,["preset","ownership_enforcement","create_mode_default","close_validation_default","require_close_reason","parent_reference","metadata_profile","force_required_for_stale_lock","create_default_type","workflow_enforcement","duplicate_detection_mode","duplicate_detection_threshold","duplicate_detection_limit"]),e.workflow=p(e.workflow,["definition_of_done"]),e.testing=p(e.testing,["record_results_to_items","allow_untrusted_linked_tests"]),e.telemetry=p(e.telemetry,["enabled","first_run_prompt_completed","capture_level","endpoint","installation_id","retention_days"]),e.agent_guidance=p(e.agent_guidance,["prompt_completed","declined","declined_at","template_version","last_checked_files"]),e.item_types=p(e.item_types,["definitions"]),e.schema=p(e.schema,["version","files","statuses","fields","workflow","type_workflows","unknown_field_policy"]),e.schema.files=p(C(e.schema.files),["types","statuses","fields","workflows"]),e.schema.workflow=p(C(e.schema.workflow),["draft_status","open_status","in_progress_status","blocked_status","close_status","canceled_status"]),e.context=p(e.context,["default_depth","activity_limit","stale_threshold_days","next_ranking_policy","sections"]),e.context.sections=p(C(e.context.sections),["hierarchy","activity","progress","blockers","files","workload","staleness","tests"]),e.extensions=p(e.extensions,["enabled","disabled","policy"]),e.extensions.policy=p(C(e.extensions.policy),["mode","trust_mode","pm_max_version_exceeded_mode","require_provenance","trusted_extensions","default_sandbox_profile","allowed_extensions","blocked_extensions","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services","extension_overrides"]),e.extensions.policy.extension_overrides=Fe(e.extensions.policy.extension_overrides).map(n=>p(C(n),["name","disabled","require_trusted","require_provenance","sandbox_profile","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services"])),e.search=p(e.search,["score_threshold","hybrid_semantic_weight","max_results","embedding_model","embedding_corpus_max_characters","embedding_batch_size","embedding_timeout_ms","scanner_max_batch_retries","provider","default_mode","mutation_refresh_policy","query_expansion","rerank"]),e.search.query_expansion=p(C(e.search.query_expansion),["enabled","provider"]),e.search.rerank=p(C(e.search.rerank),["enabled","model","top_k"]),e.providers=p(e.providers,["openai","ollama"]),e.providers.openai=p(C(e.providers.openai),["base_url","api_key","model"]),e.providers.ollama=p(C(e.providers.ollama),["base_url","model"]),e.vector_store=p(e.vector_store,["adapter","collection_name","qdrant","lancedb"]),e.vector_store.qdrant=p(C(e.vector_store.qdrant),["url","api_key"]),e.vector_store.lancedb=p(C(e.vector_store.lancedb),["path"])}function lr(e){return{...e,locks:b(e.locks,u.locks),ids:b(e.ids,u.ids),agent_identity:b(e.agent_identity,u.agent_identity),mutation_guard:b(e.mutation_guard,u.mutation_guard),checkpoints:b(e.checkpoints,u.checkpoints),output:b(e.output,u.output),ux:b(e.ux,u.ux),history:b(e.history,u.history),validation:b(e.validation,u.validation),workflow:b(e.workflow,u.workflow),testing:b(e.testing,u.testing),telemetry:b(e.telemetry,u.telemetry),agent_guidance:b(e.agent_guidance,u.agent_guidance),item_types:b(e.item_types,u.item_types),schema:b(e.schema,u.schema),context:b(e.context,u.context),extensions:b(e.extensions,u.extensions),search:b(e.search,u.search),providers:b(e.providers,u.providers),vector_store:b(e.vector_store,u.vector_store)}}function dr(e,t){return{...e.validation,parent_reference:t.parent_reference,metadata_profile:t.metadata_profile,metadata_required_fields:nn(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:q(e.validation?.lifecycle_stale_blocker_reason_patterns??u.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:q(e.validation?.lifecycle_closure_like_blocked_reason_patterns??u.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:q(e.validation?.lifecycle_closure_like_resolution_patterns??u.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:q(e.validation?.lifecycle_closure_like_actual_result_patterns??u.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:Re(e.validation?.estimate_defaults_by_type)}}function ur(e){return{...u.search,...e.search,default_mode:Ut(e.search?.default_mode),mutation_refresh_policy:Wt(e.search?.mutation_refresh_policy),query_expansion:{...u.search.query_expansion,...e.search?.query_expansion,enabled:$t(e.search?.query_expansion?.enabled),provider:Ht(e.search?.query_expansion?.provider)},rerank:{...u.search.rerank,...e.search?.rerank,enabled:Bt(e.search?.rerank?.enabled),model:Gt(e.search?.rerank?.model),top_k:Kt(e.search?.rerank?.top_k)}}}function _r(e){return{default_depth:e.context?.default_depth??u.context.default_depth,activity_limit:e.context?.activity_limit??u.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??u.context.stale_threshold_days,next_ranking_policy:e.context?.next_ranking_policy??u.context.next_ranking_policy,sections:{...u.context.sections,...e.context?.sections}}}function fr(e){return{...e.vector_store,adapter:e.vector_store?.adapter??u.vector_store.adapter,collection_name:Jt(e.vector_store?.collection_name),qdrant:{...e.vector_store?.qdrant},lancedb:{...e.vector_store?.lancedb}}}function mr(e,t,n,r){return{...e,item_format:"toon",validation:dr(e,t),governance:t,agent_guidance:Zt(e.agent_guidance),item_types:{definitions:r.item_type_definitions},schema:{...n,statuses:r.schema_statuses,fields:r.schema_fields,type_workflows:r.schema_type_workflows},search:ur(e),context:_r(e),extensions:{enabled:De(e.extensions?.enabled),disabled:De(e.extensions?.disabled),policy:tn(e.extensions?.policy)},vector_store:fr(e)}}function rn(e,t){for(let n of Object.keys(t)){let r=Reflect.get(t,n),i=e[n];typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof i=="object"&&i!==null&&!Array.isArray(i)?rn(i,r):e[n]=structuredClone(r)}}function $e(e,t,n){let r=new Set([...Object.keys(t),...Object.keys(n)]);for(let i of r){let a=t[i],s=n[i];if(!P(a,s)){if(s===void 0){delete e[i];continue}if(typeof a=="object"&&a!==null&&!Array.isArray(a)&&typeof s=="object"&&s!==null&&!Array.isArray(s)){let l=e[i],_=typeof l=="object"&&l!==null&&!Array.isArray(l)?l:{};$e(_,a,s),Object.keys(_).length>0?e[i]=_:delete e[i];continue}e[i]=structuredClone(s)}}}var we=["version","id_prefix","ids","author_default","agent_identity","mutation_guard","item_format","locks","checkpoints","output","ux","history","validation","governance","workflow","testing","telemetry","agent_guidance","item_types","schema","context","extensions","search","providers","vector_store"];function It(e,t){let n=lr(e),r=Vt(n),i=ne(n.schema),a=Gn(n,t),s=mr(n,r,i,a),l=p({...s,governance:Vn(r)},we);return cr(l),l}function on(e,t={}){let n=t.source===void 0?t.persist_source:Yt(t.source.validated,ye(t.source.validated)),r=It(e,n);if(n){let i=ye(n.source_settings);i.item_types={definitions:structuredClone(n.runtime_item_type_definitions)},i.schema={...i.schema,statuses:structuredClone(n.runtime_schema_statuses),fields:structuredClone(n.runtime_schema_fields),type_workflows:structuredClone(n.runtime_schema_type_workflows)};let a=It(i,n);t.source!==void 0&&rn(a,t.source.validated);let s=structuredClone(t.source===void 0?n.source_settings:t.source.raw);return $e(s,a,r),`${JSON.stringify(p(s,we),null,2)}
|
|
3
3
|
`}return`${JSON.stringify(r,null,2)}
|
|
4
4
|
`}async function pr(e){let t;try{t=await Lt(e)}catch(l){if(le(l))return j();throw l}let n=B(t),r;try{r=await Rn(n)}catch(l){if(le(l))return j();throw l}if(!r.isFile())throw Te("settings.json");let i;try{i=await Ze(n,Te("settings.json"))}catch(l){if(le(l))return j();throw l}let a;try{a=JSON.parse(i)}catch{return j("settings_read_invalid_json")}let s=_e(a);return s.success?{settings:ye(s.data),metadata:{has_explicit_item_format:Qt(a)},warnings:s.data.item_format==="json_markdown"?["settings_item_format_legacy_json_markdown_coerced_to_toon"]:[]}:j("settings_read_invalid_schema")}async function an(e){if(Ln(e))return pr(e);let t=B(e),n=[t];await kt({path:t,scope:"project"});let r=At(e);if(r){let f=await L(r.tracked_paths);if(ae(f,r.signatures))return he(r.value)}let i=await L([t]),a;try{a=await I(t)}catch{return j("settings_read_fs_error")}if(a===null){let f=j();return await qe(e,[t],f,i,[t]),f}let s=await L([t]);if(!ae(i,s))return H(e),an(e);let l;try{l=JSON.parse(a)}catch{let f=j("settings_read_invalid_json");return await qe(e,[t],f,s,[t]),f}let _=_e(l);if(!_.success){let f=j("settings_read_invalid_schema");return await qe(e,[t],f,s,[t]),f}try{let f=ye(_.data),w=Un(e,f.schema,t);n=w;let g=await L(w),S=await dt(e,f.schema),X=await L(w),Oe={...f,item_types:{definitions:Y([...f.item_types.definitions,...Fe(S.type_definitions_from_file)])},schema:S.schema};ke(Oe,Yt(_.data,Oe));let Ye={settings:Oe,metadata:{has_explicit_item_format:Qt(l)},warnings:[..._.data.item_format==="json_markdown"?["settings_item_format_legacy_json_markdown_coerced_to_toon"]:[],...S.warnings]};return ae(g,X)?pe(e,{tracked_paths:w,signatures:X,value:he(Ye)}):H(e),Ye}catch{let f=j("settings_read_merge_failed");return await Hn(e,n,f),f}}function hr(e,t=[],n=null){let r=He(n)??{},i=t.filter(s=>!Object.hasOwn(r,s));if(i.length===0)return e;let a=JSON.parse(e);for(let s of i)Reflect.deleteProperty(a,s);return`${JSON.stringify(a,null,2)}
|
|
@@ -6,4 +6,4 @@ import{Ad as D,Aj as yt,Ba as at,Cc as dt,Da as st,Ej as kt,Fh as oe,Gh as ie,Sc
|
|
|
6
6
|
`}function xr(e){try{return JSON.parse(e)}catch{throw new x("Existing settings.json is malformed; the settings write was refused.",v.USAGE,{code:"settings_write_invalid_existing_json",reason:"existing_settings_json_malformed",why:"Writing defaults over malformed settings could destroy intended project configuration.",nextSteps:["Repair the syntax in .agents/pm/settings.json, then retry the original command.","Run pm health to confirm the settings warning has cleared."]})}}async function Ro(e){return(await an(e)).settings}async function Lo(e,t,n=qn,r={}){let i=r.assignedPaths??[];wr(i);let a=B(e),s=We(t),l=s?void 0:Ue(t),_=on(t,{persist_source:s}),f=JSON.parse(_),w=!1;try{if(await vt({pmRoot:e,filePath:a,mutate:g=>{let S=g===null?null:xr(g);return g!==null&&r.skipIfStored?.(S)===!0?(w=!0,{raw:g,result:void 0}):l!==void 0&&g!==null?{raw:vr(S,f,l,i,Kn(t)),result:void 0}:{raw:s?`${JSON.stringify(p(Ne(s.persisted_settings,f,S),we),null,2)}
|
|
7
7
|
`:hr(_,r.omitSections,S),result:void 0}},op:n,author:ft(void 0,t.author_default),lockTtlSeconds:t.locks.ttl_seconds,lockWaitMs:t.locks.wait_ms,recordCreation:!1}),w)return;s?ke(t,{...s,persisted_settings:structuredClone(f)}):l!==void 0&&Jn(t,structuredClone(f)),await yt({path:a,scope:"project",op:n})}finally{H(e)}}import cn from"node:fs";import se from"node:path";import{createRequire as Sr}from"node:module";var ce="@unbrained/pm-cli",Er=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"]),ln=new Set(["--author","--expect-hash","--output-budget","--output-format","--output-include","--output-limit","--output-session","--path","--pm-path"]),Ge=/\b(\d{4})\.(\d{1,2})\.(\d{1,2})(?:-(\d+))?\b/u,xe="2026.8.31";function E(e,t){return e.some(n=>t.includes(n.split("=",1)[0]))}function Be(e,t){return["activate","adopt","adopt-all","deactivate","init","install","migrate","reload","uninstall"].includes(t[0]??"")||E(e,["--activate","--adopt","--adopt-all","--deactivate","--fix-managed-state","--init","--install","--output","--reload","--scaffold","--uninstall"])}var Or={changelog:(e,t)=>{if(t[0]==="generate")return!E(e,["--check"]);let n=e.indexOf("export");return t[0]==="export"&&(E(e,["--output"])||n>=0&&e[n+1]!==void 0&&!e[n+1].startsWith("-"))},comments:e=>E(e,["--add","--delete","--edit","--file","--stdin"]),config:(e,t)=>(t[0]==="project"||t[0]==="global"?t[1]:t[0])==="set",deps:()=>!1,docs:e=>E(e,["--add","--add-glob","--migrate","--remove"]),duplicates:()=>!1,events:()=>!1,extension:Be,files:(e,t)=>E(e,["--add","--add-glob","--migrate","--remove"])||t[0]==="discover"&&E(e,["--apply"]),health:e=>!E(e,["--check-only","--no-refresh","--skip-vectors"]),learnings:e=>E(e,["--add","--delete","--edit","--file","--stdin"]),merge:(e,t)=>t[0]!=="report",notes:e=>E(e,["--add","--delete","--edit","--file","--stdin"]),package:Be,packages:Be,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]??"")&&!(E(e,["--infer"])&&!E(e,["--apply"])),telemetry:(e,t)=>t.slice(0,2).some(n=>["clear","flush"].includes(n)),templates:(e,t)=>t[0]==="save",test:e=>E(e,["--update","--update-index","--add","--add-json","--background","--measure","--remove","--resume","--run","--stop"]),validate:e=>E(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 be(e){let t=e.match(Ge);return t?[Number(t[1]),Number(t[2]),Number(t[3]),Number(t[4]??0)]:null}function z(e,t){let n=be(e),r=be(t);if(!n||!r)return null;for(let i=0;i<n.length;i+=1){let a=n[i]-r[i];if(a!==0)return Math.sign(a)}return 0}function ge(e){return z(e,xe)!==-1?3:2}function Tr(e,t){if(t===3)return e.filter(n=>n.history_epoch_compatible===!1).map(n=>({...n,declaration:n.declaration??n.version})).sort((n,r)=>z(n.version,r.version))[0]}function ve(e){try{let t=JSON.parse(cn.readFileSync(e,"utf8"));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function Cr(e){let t=[...e.matchAll(/(<=|<)\s*v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/gu)].map(r=>({inclusive:r[1]==="<=",version:r[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 Ar(e){let t=e.split("||").map(n=>Cr(n));return{bounded:t.some(n=>n.length>0),compatible:t.some(n=>n.every(r=>{let i=z(xe,r.version);return i!==null&&(r.inclusive?i!==1:i===-1)}))}}function dn(e){return["dependencies","devDependencies","optionalDependencies","peerDependencies"].flatMap(t=>{let n=e[t];if(typeof n!="object"||n===null)return[];let r=n[ce];return typeof r=="string"?[r.trim()]:[]})}function Pr(e){return dn(e).flatMap(t=>{let n=/^[<!]/u.test(t)?void 0:t.match(Ge)?.[0];if(!n)return[];let r=/^(?:=|v)?\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?$/u.test(t),i=Ar(t);return[{version:n,constraint:r?"exact":i.bounded?"range":"minimum",...r?{}:{declaration:t},history_epoch_compatible:r?z(n,xe)!==-1:i.compatible}]})}function jr(e){let n=ve(se.join(e,"package-lock.json"))?.packages;if(typeof n!="object"||n===null)return;let r=n["node_modules/@unbrained/pm-cli"];if(typeof r!="object"||r===null)return;let i=r.version;return typeof i=="string"?i:void 0}function Nr(e,t){try{let n=cn.readFileSync(se.join(e,t),"utf8").split(/\r?\n/u),r=n.findIndex(_=>_.includes(ce));if(r<0)return;let i=n[r].match(/^\s*/u)[0].length,a=[n[r]];for(let _=r+1;_<n.length;_+=1){let f=n[_],w=f.trim(),g=f.match(/^\s*/u)[0].length;if(w.length>0&&g<=i)break;a.push(f)}return a.join(`
|
|
8
8
|
`).match(/^\s*version(?::\s*|\s+)["']?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/mu)?.[1]??a[0].match(Ge)?.[0]}catch{return}}function un(e){let t=[],n=ve(se.join(e,"package.json"));n&&t.push(...Pr(n).map(s=>({...s,source:"package.json"})));let i=ve(se.join(e,"node_modules","@unbrained","pm-cli","package.json"))?.version;typeof i=="string"&&be(i)&&t.push({version:i,source:"installed-package",constraint:"exact",history_epoch_compatible:ge(i)===3});let a=jr(e);a&&be(a)&&t.push({version:a,source:"package-lock.json",constraint:"exact",history_epoch_compatible:ge(a)===3});for(let s of["pnpm-lock.yaml","yarn.lock"]){let l=Nr(e,s);l&&t.push({version:l,source:s,constraint:"exact",history_epoch_compatible:ge(l)===3})}return t}function Ir(e,t){if(t<=1)return;let{minVersion:n,lt:r}=Sr(import.meta.url)("semver"),i=dn(ve(se.join(e,"package.json"))??{}).find(s=>{try{let l=n(s);return l!==null&&r(l,"2026.10.10")}catch{return!1}}),a=i===void 0?un(e).find(s=>z(s.version,"2026.10.10")===-1):{version:i,source:"package.json"};if(a)throw new x(`The project selects pm ${a.version}, which cannot safely refuse item format ${t}.`,v.CONFLICT,{code:"project_runtime_item_format_incompatible",reason:a.source,required:"Upgrade project pins, installed SDKs, CI hosts and Git merge drivers before writing guarded item formats.",nextSteps:["Use a pm runtime supporting the required item format throughout the project; preserve original item and history bytes, and never re-anchor history to satisfy an older host."]})}function $o(e,t){let n=_t(e);n<=1||(Ir(ct(t),n),e.pm_format_version=n)}function _n(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(ln.has(n)){t+=1;continue}if(!n.startsWith("-"))return{command:n.toLowerCase(),index:t}}}function Rr(e){let t=_n(e);if(!t||E(e,["--help","-h","--dry-run"]))return!1;let{command:n,index:r}=t,i=[];for(let s=r+1;s<e.length;s+=1){let l=e[s];if(ln.has(l)){s+=1;continue}l.startsWith("-")||i.push(l.toLowerCase())}let a=Or[n];return a?a(e,i):Er.has(n)}function Lr(e){let t=_n(e.argv)?.command,n=Rr(e.argv),r=un(e.projectRoot).filter(w=>z(w.version,e.executingVersion)!==null).sort((w,g)=>z(g.version,w.version)),i=r[0],a=i!==void 0&&z(e.executingVersion,i.version)===-1,s=ge(e.executingVersion),l=Tr(r,s),_=n&&l!==void 0,f=a&&!n?{code:"project_runtime_stale_read",executing_version:e.executingVersion,project_version:i.version,source:i.source,message:"This read is using an older pm runtime than the project requires.",next_steps:[`Run the command through the project's installed ${ce} ${i.version}.`,"Install the project dependencies with its declared package manager if the local executable is missing."]}:void 0;return{compatible:!n||!a&&!_||e.allowStale===!0,executing_version:e.executingVersion,...i?{project_version:i.version,source:i.source}:{},...t?{command:t}:{},mutating:n,stale:a,history_epoch_incompatible:_,writer_item_hash_version:s,...l?{incompatible_project_version:l.declaration,incompatible_source:l.source}:{},...f?{warning:f}:{},override_applied:n&&(a||_)&&e.allowStale===!0}}function Ho(e){let t=Lr(e);if(t.compatible)return t;throw t.history_epoch_incompatible?new x(`pm ${t.executing_version} cannot write item-hash epoch ${t.writer_item_hash_version} into a project pinned to pm ${t.incompatible_project_version}.`,v.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 ${ce} pin to ${xe} 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 x(`pm ${t.executing_version} cannot mutate a project pinned to newer pm ${t.project_version}.`,v.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 ${ce} ${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 Je from"node:fs/promises";import Se from"node:path";function M(e,t){return typeof e=="object"&&e!==null&&"code"in e&&e.code===t}function fn(e){let t=["--pm-path",e,"init","--defaults","--agent-guidance","skip"];return{suggested_retry:lt(t),suggested_retry_args:t}}function Ee(e){return new x(`Tracker root is not a directory at ${e}.`,v.USAGE,{code:"tracker_root_not_directory",reason:"not_a_directory",resolved_path:e,nextSteps:["Pass a tracker directory, usually <workspace>/.agents/pm, rather than a file path."]})}function Ke(e){return new x(`Tracker root is not readable at ${e}.`,v.GENERIC_FAILURE,{code:"tracker_root_unreadable",reason:"unreadable",resolved_path:e,nextSteps:["Grant read and directory-search permission to the tracker root, then retry."]})}async function qr(e){let t=Se.resolve(e),n=Se.parse(t).root,r=Se.dirname(t);for(;r!==n;){let i;try{i=await Je.stat(r)}catch(a){if(M(a,"ENOTDIR"))throw Ee(e);if(!M(a,"ENOENT"))throw a;r=Se.dirname(r);continue}if(!i.isDirectory())throw Ee(e);return}}async function zr(e){let t;try{t=await Je.stat(e)}catch(n){throw M(n,"ENOENT")?(await qr(e),new x(`Tracker is not initialized at ${e}. Tracker root does not exist. Run pm init first.`,v.NOT_FOUND,{code:"tracker_root_missing",reason:"missing",resolved_path:e,nextSteps:["Confirm the tracker root path or initialize it with the emitted retry."],recovery:fn(e)})):M(n,"ENOTDIR")?Ee(e):M(n,"EACCES")||M(n,"EPERM")?Ke(e):n}if(!t.isDirectory())throw Ee(e);if(process.platform!=="win32"&&((t.mode&292)===0||(t.mode&73)===0))throw Ke(e);try{await(await Je.opendir(e)).close()}catch(n){throw M(n,"EACCES")||M(n,"EPERM")?Ke(e):n}}async function ei(e){if(await zr(e),!await Qe(B(e)))throw new x(`Tracker is not initialized at ${e}. Run pm init first.`,v.NOT_FOUND,{code:"tracker_not_initialized",reason:"settings_missing",resolved_path:e,nextSteps:["Initialize the selected tracker root with the emitted retry."],recovery:fn(e)})}export{R as a,W as b,Jr as c,Yr as d,Xr as e,vt as f,Qr as g,Zr as h,eo as i,St as j,_e as k,co as l,H as m,jo as n,Ln as o,Vt as p,No as q,Io as r,ye as s,on as t,an as u,Ro as v,Lo as w,xe as x,z as y,ge as z,un as A,Ir as B,$o as C,Rr as D,Lr as E,Ho as F,fn as G,zr as H,ei as I};
|
|
9
|
-
//# sourceMappingURL=chunk-
|
|
9
|
+
//# sourceMappingURL=chunk-C4KIZQHW.js.map
|