@unbrained/pm-cli 2026.8.16 → 2026.8.17
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 +2 -2
- package/CHANGELOG.md +30 -3
- package/README.md +13 -13
- package/dist/cli/public.d.ts +2 -0
- package/dist/cli/public.js +21 -0
- package/dist/cli/register-mutation.js +4 -4
- package/dist/cli-bundle/bundle-manifest.json +151 -151
- package/dist/cli-bundle/chunks/{chunk-I2LUWWR5.js → chunk-2QLOXC3V.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-URW4QRMI.js → chunk-3UEGXBMR.js} +22 -22
- package/dist/cli-bundle/chunks/chunk-4JPYF536.js +35 -0
- package/dist/cli-bundle/chunks/chunk-6VDLG2FC.js +13 -0
- package/dist/cli-bundle/chunks/chunk-7IBRGCHX.js +2 -0
- package/dist/cli-bundle/chunks/chunk-HBJAS566.js +8 -0
- package/dist/cli-bundle/chunks/chunk-ION3E43Q.js +197 -0
- package/dist/cli-bundle/chunks/{chunk-73UGEBRS.js → chunk-JOKATURE.js} +4 -4
- package/dist/cli-bundle/chunks/{chunk-RIS565OA.js → chunk-TPXZIBIV.js} +5 -5
- package/dist/cli-bundle/chunks/chunk-YM2YAMF7.js +2 -0
- package/dist/cli-bundle/chunks/{register-list-query-EYCXHZAG.js → register-list-query-Q7KII4G5.js} +2 -2
- package/dist/cli-bundle/chunks/register-mutation-4WBRPXLV.js +20 -0
- package/dist/cli-bundle/chunks/{register-operations-KGDNRMCL.js → register-operations-SSENDH5B.js} +2 -2
- package/dist/cli-bundle/chunks/{register-setup-NVXBOD5I.js → register-setup-DOSFBGKE.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-TZATVC4G.js → chunk-267MUUS6.js} +11 -11
- package/dist/cli-bundle/focused-chunks/chunk-2NNFLLNG.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-HAACPSUW.js → chunk-2QSAKMIH.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-6ROKKT4X.js → chunk-ATEY76SX.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-BUCG4ZI2.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-SSNDYZTM.js → chunk-CYFK5UPB.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-EHXIKD6K.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-J4UFYHOD.js → chunk-KGEXTMPG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-KP2VQQVQ.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-MHPIL773.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-POEEAD2V.js +4 -0
- package/dist/cli-bundle/focused-chunks/{chunk-T46KLOIB.js → chunk-SALH6B6K.js} +47 -47
- package/dist/cli-bundle/focused-chunks/{chunk-CODV5LUT.js → chunk-SYZENPIT.js} +3 -3
- package/dist/cli-bundle/focused-chunks/{chunk-4JPEBFFC.js → chunk-XKAMP5OU.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-NJ5RLEFD.js → chunk-XPIC53VA.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-C7JUBRFP.js → chunk-ZQPGZZWQ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-ZT2DJS27.js +155 -0
- package/dist/cli-bundle/main.js +2 -2
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +1 -1
- package/dist/cli-bundle/sdk-core.js +31 -31
- 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 +32 -32
- 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 +4 -2
- package/dist/core/extensions/loader.js +10 -6
- package/dist/core/extensions/manifest-schema.d.ts +20 -0
- package/dist/core/extensions/manifest-schema.js +52 -0
- package/dist/core/history/replay.js +32 -14
- package/dist/core/schema/fields-file.d.ts +1 -1
- package/dist/core/schema/fields-file.js +2 -2
- package/dist/core/schema/runtime-field-values.js +115 -9
- package/dist/core/schema/runtime-schema.d.ts +3 -1
- package/dist/core/schema/runtime-schema.js +124 -3
- package/dist/core/shared/errors.d.ts +10 -0
- package/dist/core/shared/errors.js +2 -2
- package/dist/core/shared/time.d.ts +2 -0
- package/dist/core/shared/time.js +27 -2
- package/dist/sdk/agent/refusal-reachability.d.ts +46 -6
- package/dist/sdk/agent/refusal-reachability.js +350 -8
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +5 -4
- package/dist/sdk/compose.d.ts +6 -2
- package/dist/sdk/compose.js +33 -3
- package/dist/sdk/context-intent-contracts.d.ts +8 -4
- package/dist/sdk/context-intent-contracts.js +76 -31
- package/dist/sdk/dependency-flag-validation.d.ts +9 -2
- package/dist/sdk/dependency-flag-validation.js +101 -35
- package/dist/sdk/environment/host-environment-errors.js +25 -7
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +26 -2
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +14 -2
- package/dist/sdk/governance/assurance-action.d.ts +3 -7
- package/dist/sdk/governance/assurance-action.js +97 -2
- package/dist/sdk/governance/boundary-fixtures.d.ts +86 -0
- package/dist/sdk/governance/boundary-fixtures.js +201 -0
- package/dist/sdk/governance/defect-recurrence-signals.d.ts +10 -0
- package/dist/sdk/governance/defect-recurrence-signals.js +25 -0
- package/dist/sdk/governance/defect-recurrence.d.ts +242 -0
- package/dist/sdk/governance/defect-recurrence.js +523 -0
- package/dist/sdk/governance.d.ts +2 -0
- package/dist/sdk/governance.js +4 -2
- package/dist/sdk/graph/governance.js +3 -2
- package/dist/sdk/guide-topics.js +191 -2
- package/dist/sdk/index.d.ts +3 -0
- package/dist/sdk/index.js +4 -2
- package/dist/sdk/lifecycle/create.js +4 -2
- package/dist/sdk/lifecycle/update-many.js +15 -2
- package/dist/sdk/lifecycle/update.js +5 -2
- package/dist/sdk/linked-artifacts.js +63 -14
- package/dist/sdk/query/get.d.ts +2 -0
- package/dist/sdk/query/get.js +32 -7
- package/dist/sdk/relationship-analytics.js +90 -14
- package/dist/sdk/relationship-kinds/contract.d.ts +4 -0
- package/dist/sdk/relationship-kinds/contract.js +3 -2
- package/dist/sdk/relationships.d.ts +1 -1
- package/dist/sdk/relationships.js +11 -2
- package/dist/sdk/schema.d.ts +1 -0
- package/dist/sdk/schema.js +2 -2
- package/dist/sdk/test/execution.d.ts +6 -2
- package/dist/sdk/test/execution.js +39 -13
- package/dist/types.d.ts +29 -2
- package/dist/types.js +4 -2
- package/docs/CONFIGURATION.md +58 -1
- package/docs/CONTEXT_INTEGRITY_CONTRACTS.md +58 -0
- package/docs/DEFECT_RECURRENCE.md +134 -0
- package/docs/DEPENDENCY_KIND_CONTRACT.md +12 -2
- package/docs/README.md +2 -0
- package/docs/RELATIONSHIP_GRAPH.md +16 -2
- package/docs/SDK.md +38 -5
- package/docs/SDK_RUNTIME_BOUNDARIES.md +9 -1
- package/docs/TESTING.md +18 -1
- package/docs/TRUSTWORTHY_CONTEXT_EVIDENCE.md +1 -1
- package/marketplace.json +2 -2
- package/package.json +6 -4
- 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/skills/pm-audit/SKILL.md +26 -0
- package/plugins/pm-claude/skills/pm-developer/SKILL.md +26 -0
- package/plugins/pm-claude/skills/pm-planner/SKILL.md +26 -0
- package/plugins/pm-claude/skills/pm-release/SKILL.md +26 -0
- package/plugins/pm-claude/skills/pm-workflow/SKILL.md +26 -0
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/pm-codex/skills/pm-auditor/SKILL.md +26 -0
- package/plugins/pm-codex/skills/pm-native/SKILL.md +26 -0
- package/plugins/pm-codex/skills/pm-release/SKILL.md +26 -0
- package/sdk/public-surface.json +588 -20
- package/dist/cli-bundle/chunks/chunk-47OQEOQB.js +0 -2
- package/dist/cli-bundle/chunks/chunk-HCIYWD6M.js +0 -35
- package/dist/cli-bundle/chunks/chunk-IC5W2T34.js +0 -2
- package/dist/cli-bundle/chunks/chunk-PANOOBIS.js +0 -13
- package/dist/cli-bundle/chunks/chunk-TK6N7HGM.js +0 -8
- package/dist/cli-bundle/chunks/chunk-TOFG2URD.js +0 -197
- package/dist/cli-bundle/chunks/register-mutation-7YVIG54J.js +0 -20
- package/dist/cli-bundle/focused-chunks/chunk-5NMFSX26.js +0 -155
- package/dist/cli-bundle/focused-chunks/chunk-725JSCMP.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-DQ6SMTBF.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-JX5Z344Q.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-L4RDYBIQ.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-QYZERYR5.js +0 -4
- package/dist/cli-bundle/focused-chunks/chunk-WY3WRPVN.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$
|
|
1
|
+
import{$b as wt,$c as Qe,$g as oe,Ah as To,B as Ht,C as g,Dc as q,Dh as Io,E as h,Eh as Oo,Gb as uo,Gh as Ce,H as oo,Hb as mo,He as ko,Ia as ao,Ja as so,Ji as Co,Ka as J,Kh as Qt,Pd as bo,Q as A,Sa as j,Ua as co,Uc as $,Ud as H,Va as be,Vc as K,Vi as Ro,Wc as wo,Wg as xo,Xc as W,Xg as et,Yb as Xt,Yc as ee,Yg as tt,Zb as fo,Zg as So,_b as ho,_c as vo,_g as Eo,aa as ro,ah as Ue,bc as ke,bd as bt,bh as $o,c as x,ca as io,ch as de,d as Qn,da as Q,dc as xe,e as ne,ea as ce,f as z,g as he,gc as go,i as eo,ic as vt,ig as Y,jc as yo,jl as kt,ka as Kt,kc as _o,l as _t,la as Vt,lh as re,ma as Yt,mg as Zt,oh as O,pg as Me,ph as Ee,tg as Se,u as Wt,uc as B,uh as Ao,x as to,xb as lo,y as no,yb as po}from"./chunk-ION3E43Q.js";import{mkdir as es,readFile as ts}from"node:fs/promises";import Lo 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]="6ed4a26f-2ae2-556a-87db-56844108757f")}catch{}})();var en=class extends Error{constructor(t="Workspace transaction interrupted"){super(t),this.name="WorkspaceTransactionInterruptedError"}},ns="sdk-workspace-transaction",os=/^[a-zA-Z0-9._-]+$/,rs=30,is=3e3;function Po(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n||!os.test(n))throw new TypeError(`${t} must match [a-zA-Z0-9._-]+`);return n}function No(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n)throw new TypeError(`${t} must be non-empty`);return n}function Do(e,t,n){let o=e??t;if(!Number.isInteger(o)||o<=0)throw new TypeError(`${n} must be a positive integer`);return o}function Mo(e,t){return Lo.join(e,"transactions","sdk",`${t}.json`)}async function $e(e,t){t.updatedAt=A();let n=Mo(e,t.transactionId);await es(Lo.dirname(n),{recursive:!0}),await he(n,`${JSON.stringify(t,null,2)}
|
|
2
2
|
`)}function as(e){return Number.isInteger(e.attempt)&&typeof e.author=="string"&&typeof e.createdAt=="string"&&typeof e.updatedAt=="string"}function Re(e){return Object.assign(Object.create(null),e)}function ss(e,t){try{let n=JSON.stringify(e,(o,r)=>{if(typeof r=="number"&&!Number.isFinite(r))throw new TypeError(`${t} contains a non-finite number`);if(r===void 0||typeof r=="function"||typeof r=="symbol")throw new TypeError(`${t} contains a non-JSON value`);return r});return JSON.parse(n)}catch(n){throw new TypeError(`${t} must be JSON serializable`,{cause:n})}}function tn(e,t){return e===void 0?void 0:ss(e,t)}function nn(e,t,n,o){let r=tn(n,o);r===void 0?delete e[t]:e[t]=r}function jo(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Fo(e,t){return Array.isArray(e)&&new Set(e).size===e.length&&e.every(n=>typeof n=="string"&&t.includes(n))}function cs(e,t){if(!Fo(e.startedStepIds,t)||!Fo(e.completedStepIds,t)||!jo(e.results)||!jo(e.compensationData))return!1;let n=e.startedStepIds,o=new Set(n),r=e.completedStepIds,i=new Set(r);return Object.keys(e.compensationData).some(a=>!o.has(a))||Object.keys(e.results).some(a=>!i.has(a))?!1:e.status==="committed"?t.every(a=>i.has(a)):e.status!=="compensated"||i.size===0&&o.size===0}function ds(e,t,n){let o;try{o=JSON.parse(e)}catch{throw new TypeError(`Workspace transaction ${t} journal is invalid JSON`)}if(!o||typeof o!="object"||Array.isArray(o))throw new TypeError(`Workspace transaction ${t} journal is invalid`);let r=o,i=r.schemaVersion===1&&r.transactionId===t,a=Array.isArray(r.stepIds)&&r.stepIds.length===n.length&&r.stepIds.every((l,p)=>l===n[p]),s=cs(r,n),c=as(r),d=["applying","compensating","compensated","committed"].includes(String(r.status));if(!i||!a||!s||!c||!d)throw new TypeError(`Workspace transaction ${t} journal does not match the supplied plan`);return{...r,results:Re(r.results),compensationData:Re(r.compensationData)}}async function ls(e,t,n,o,r){let i=r,a=i!==void 0;if(i?.status==="compensating"&&await Uo(e,i),i===void 0||i.status==="compensated"){let s=A();i={schemaVersion:1,transactionId:t,author:n,status:"applying",attempt:(i?.attempt??0)+1,createdAt:i?.createdAt??s,updatedAt:s,stepIds:o,startedStepIds:[],completedStepIds:[],results:Re(),compensationData:Re()},await $e(e.pmRoot,i),await ge(e,i,"prepared")}return{journal:i,recovered:a}}async function ps(e,t,n){try{await ms(t,e.steps),await $e(e.pmRoot,t);let o=new Set(t.completedStepIds),r=new Set(t.startedStepIds);for(let i of e.steps){if(o.has(i.id))continue;let a=await i.inspect(),s=tn(a.result,`Step ${i.id} result`);if(a.state!=="applied"){let c=await i.prepareCompensation?.();nn(t.compensationData,i.id,c,`Step ${i.id} compensation data`),r.add(i.id),t.startedStepIds=e.steps.map(l=>l.id).filter(l=>r.has(l)),await $e(e.pmRoot,t);let d=await i.apply();s=tn(d,`Step ${i.id} result`)}await ge(e,t,"step_applied",i.id),o.add(i.id),t.completedStepIds=e.steps.map(c=>c.id).filter(c=>o.has(c)),nn(t.results,i.id,s,`Step ${i.id} result`),await $e(e.pmRoot,t),await ge(e,t,"step_recorded",i.id)}return await ge(e,t,"committing"),t.status="committed",await $e(e.pmRoot,t),await ge(e,t,"committed"),{transactionId:t.transactionId,status:"committed",recovered:n,results:Re(t.results)}}catch(o){if(o instanceof en||t.status==="committed")throw o;try{await Uo(e,t)}catch(r){throw new AggregateError([o,r],`Workspace transaction failed and compensation failed: ${String(r)}`,{cause:r})}throw o}}async function us(e,t,n){try{return ds(await ts(Mo(e,t),"utf8"),t,n)}catch(o){if(o!==null&&typeof o=="object"&&"code"in o&&ne(o))return;throw o}}async function ge(e,t,n,o){await e.onTransition?.({transactionId:t.transactionId,attempt:t.attempt,transition:n,...o===void 0?{}:{stepId:o}})}async function ms(e,t){let n=new Set,o=Re();for(let r of t){let i=await r.inspect();i.state==="applied"&&(n.add(r.id),nn(o,r.id,i.result,`Step ${r.id} result`))}e.results=o,e.completedStepIds=t.map(r=>r.id).filter(r=>n.has(r))}async function Uo(e,t){t.status="compensating",await $e(e.pmRoot,t),await ge(e,t,"compensating");let n=new Set(t.completedStepIds),o=new Set(t.startedStepIds);for(let r of[...e.steps].reverse()){if(!o.has(r.id)&&!n.has(r.id))continue;let i;try{i=o.has(r.id)&&(await r.inspect()).state==="applied"}catch{i=o.has(r.id)}i&&(await ge(e,t,"step_compensating",r.id),await r.compensate(t.compensationData[r.id])),n.delete(r.id),o.delete(r.id),t.completedStepIds=e.steps.map(a=>a.id).filter(a=>n.has(a)),t.startedStepIds=e.steps.map(a=>a.id).filter(a=>o.has(a)),delete t.results[r.id],delete t.compensationData[r.id],await $e(e.pmRoot,t),await ge(e,t,"step_compensated",r.id)}t.status="compensated",await $e(e.pmRoot,t),await ge(e,t,"compensated")}async function Go(e){let t=No(e.pmRoot,"Transaction pmRoot"),n=Po(e.transactionId,"Transaction id"),o=No(e.author,"Transaction author"),r=Do(e.lockTtlSeconds,rs,"Transaction lock TTL"),i=Do(e.lockWaitMs,is,"Transaction lock wait"),a=[...e.steps];if(a.length===0)throw new TypeError("Workspace transaction requires at least one step");let s=a.map(l=>{let p=Po(l.id,"Transaction step id");if(p!==l.id)throw new TypeError("Transaction step id must not contain surrounding whitespace");return p});if(new Set(s).size!==s.length)throw new TypeError("Workspace transaction step ids must be unique");let c={...e,pmRoot:t,transactionId:n,author:o,steps:a,lockTtlSeconds:r,lockWaitMs:i},d=await Y(t,ns,r,o,!1,!1,i);try{let l=await us(t,n,s),p=l!==void 0;if(l?.status==="committed")return{transactionId:n,status:"committed",recovered:!0,results:Re(l.results)};let u=await ls(c,n,o,s,l);return await ps(c,u.journal,p||u.recovered)}finally{await d()}}import{readFile as fs,writeFile as hs}from"node:fs/promises";import nt 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]="89261a49-97e5-5ffc-a81c-2409f0b529cf")}catch{}})();var Jo="# pm-cli:runtime-cache:start",on="# pm-cli:runtime-cache:end",qo=".agents/pm",gs=["runtime/","search/","locks/","transactions/","checkpoints/"],ys=["search/eval-queries.json"];async function zo(e){try{return await e()}catch(t){throw t instanceof Error&&"code"in t&&typeof t.code=="string"&&["EACCES","EPERM","EROFS"].includes(t.code)?new h("The workspace .gitignore is not writable.",g.GENERIC_FAILURE,{code:"init_gitignore_unwritable",reason:t.code.toLowerCase(),required:"Grant the current user read and write access to the workspace .gitignore before initialization.",why:"pm init must publish its managed runtime-cache ignore fence without replacing unrelated entries.",nextSteps:["Grant read and write access to the workspace .gitignore and rerun pm init.","If the workspace is intentionally read-only, initialize pm in a writable workspace or clone."]}):t}}function Bo(e){return e.replaceAll("\\","/").replace(/^\.\/+/,"").replace(/\/+$/,"")}function rn(e){let t=e.replaceAll("\\","/");return nt.isAbsolute(e)||t===".."||t.startsWith("../")}function _s(e=qo){let t=Bo(e);return[Jo,...gs.map(n=>n==="search/"?`${t}/${n}*`:`${t}/${n}`),...ys.map(n=>`!${t}/${n}`),on].join(`
|
|
3
3
|
`)}async function Wo(e,t={}){let n=nt.join(e,".gitignore"),o=qo;if(t.pmRoot!==void 0){let l=Bo(nt.relative(nt.resolve(e),nt.resolve(t.pmRoot)));if(rn(l))return{path:n,changed:!1};l.length>0&&(o=l)}let r="";try{r=await zo(()=>fs(n,"utf8"))}catch(l){if(!(l instanceof Error&&"code"in l&&ne(l)))throw l}let i=r.indexOf(Jo),a=r.indexOf(on),c=(i>=0&&a>=i?`${r.slice(0,i)}${r.slice(a+on.length)}`:r).trimEnd(),d=`${c.length>0?`${c}
|
|
4
4
|
|
|
@@ -8,12 +8,12 @@ import{$ as ro,$b as ke,$c as bt,$g as $o,B as Ht,Bc as q,Bh as Io,C as g,Ch as
|
|
|
8
8
|
|
|
9
9
|
`:""}${i}
|
|
10
10
|
`;return c===r?{path:o,changed:!1}:(n||await Ss(o,c,"utf8"),{path:o,changed:!0})}function or(e){let t=J(e,null);return[...new Set(Object.values(t.type_to_folder))].sort((n,o)=>n.localeCompare(o))}async function gm(e,t){let n=L.resolve(e),o=null,r="",i=n;for(let v=0;v<8;v+=1){let k=L.join(i,".gitattributes");try{let R=await Et(k,"utf8");if(R.includes(ze)||R.includes(St)){o=i,r=R;break}}catch{}let T=L.dirname(i);if(T===i)break;i=T}if(o===null)return{status:"not_installed",missing_patterns:[],stale_patterns:[],schema_scope:"project"};let a=L.join(o,".gitattributes"),s=r.includes(ze),c=s?ze:St,d=s?cn:Zo,l=r.indexOf(c),p=r.indexOf(d),u=p>l?r.slice(l+c.length,p).split(`
|
|
11
|
-
`).map(v=>v.trim()).filter(v=>v.length>0):[],m=un(pn(o,n),t),y=new Set(u),w=new Set(m),f=m.filter(v=>!y.has(v)),_=u.filter(v=>!w.has(v));return{status:f.length>0||_.length>0?"drift":"ok",path:a,missing_patterns:f,stale_patterns:_,schema_scope:"project"}}async function ym(e){let t=Qo(),n=[],o=[];for(let r of er){let i=`merge.${r.key}.driver`,a=` merge driver ${r.artifact} "%O" "%A" "%B"${r.itemPath===void 0?"":` --item-path ${r.itemPath}`}`,s=`${t}${a}`;try{let{stdout:c}=await dn("git",["config","--local","--get",i],{cwd:e,encoding:"utf8",windowsHide:!0,timeout:1e4}),d=c.trim();d!==s&&!await Is(d,a)&&o.push(i)}catch{n.push(i)}}return{status:n.length>0?"missing":o.length>0?"drift":"ok",missing_keys:n,drifted_keys:o}}async function rr(e){let t;try{t=await tr(L.resolve(e))}catch{return{status:"no_git"}}let n=pn(t,L.resolve(e)),o=await O(e),r=H(void 0,o.author_default),i=await Y(e,As,o.locks.ttl_seconds,r,!1,re(o).force_required_for_stale_lock,o.locks.wait_ms);try{let a=L.join(t,".gitattributes"),s;try{s=await Et(a,"utf8")}catch(p){if(p instanceof Error&&"code"in p&&ne(p))return{status:"not_installed",path:a};throw p}if(!s.includes(ze)&&!s.includes(St))return{status:"not_installed",path:a};let c=await O(e),d=or(c),l=await nr(t,un(n,d),!1);return{status:l.changed?"refreshed":"unchanged",path:l.path}}finally{await i()}}async function _m(e,t){let n=Ts({cwd:process.cwd(),explicitPath:t.path,dryRun:e.dryRun===!0,environment:process.env}),o=n.pm_root;if(!await x(be(o)))throw new h(`Tracker is not initialized at ${o}. Run pm init first.`,g.NOT_FOUND);let r=await tr(n.workspace_start);return mn({pmRoot:o,workspaceRoot:r,dryRun:e.dryRun===!0})}async function mn(e){let t=L.resolve(e.pmRoot),n=L.resolve(e.workspaceRoot),o=e.dryRun===!0,r,i;try{[r,i]=await Promise.all([sn(t),sn(n)])}catch(m){throw new h(`Cannot resolve tracker root ${t} or workspace root ${n}: ${String(m)}`,g.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 a=pn(i,r);if(rn(a))throw new h(`Tracker root ${t} is outside the git repository ${n}; there is nothing to configure for this repository.`,g.USAGE);let s=await O(r),c=or(s),d=un(a,c),l=[],p=Qo();for(let m of er)l.push({key:`merge.${m.key}.name`,value:m.name}),l.push({key:`merge.${m.key}.driver`,value:`${p} merge driver ${m.artifact} "%O" "%A" "%B"${m.itemPath===void 0?"":` --item-path ${m.itemPath}`}`});if(!o)try{for(let m of l)await dn("git",["config","--local",m.key,m.value],{cwd:i,encoding:"utf8",windowsHide:!0,timeout:1e4})}catch{throw new h(`Cannot install repository-local merge drivers in ${i}. Ensure the repository Git config is writable and no other Git process holds its lock, then retry.`,g.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 u=await nr(i,d,o);return{ok:!0,dry_run:o,workspace_root:i,pm_root:r,gitattributes:{path:u.path,changed:u.changed,patterns:d,schema_scope:"project"},git_config:l,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:A()}}import{createHash as _r}from"node:crypto";import Ne from"node:fs/promises";import Ke 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]="
|
|
11
|
+
`).map(v=>v.trim()).filter(v=>v.length>0):[],m=un(pn(o,n),t),y=new Set(u),w=new Set(m),f=m.filter(v=>!y.has(v)),_=u.filter(v=>!w.has(v));return{status:f.length>0||_.length>0?"drift":"ok",path:a,missing_patterns:f,stale_patterns:_,schema_scope:"project"}}async function ym(e){let t=Qo(),n=[],o=[];for(let r of er){let i=`merge.${r.key}.driver`,a=` merge driver ${r.artifact} "%O" "%A" "%B"${r.itemPath===void 0?"":` --item-path ${r.itemPath}`}`,s=`${t}${a}`;try{let{stdout:c}=await dn("git",["config","--local","--get",i],{cwd:e,encoding:"utf8",windowsHide:!0,timeout:1e4}),d=c.trim();d!==s&&!await Is(d,a)&&o.push(i)}catch{n.push(i)}}return{status:n.length>0?"missing":o.length>0?"drift":"ok",missing_keys:n,drifted_keys:o}}async function rr(e){let t;try{t=await tr(L.resolve(e))}catch{return{status:"no_git"}}let n=pn(t,L.resolve(e)),o=await O(e),r=H(void 0,o.author_default),i=await Y(e,As,o.locks.ttl_seconds,r,!1,re(o).force_required_for_stale_lock,o.locks.wait_ms);try{let a=L.join(t,".gitattributes"),s;try{s=await Et(a,"utf8")}catch(p){if(p instanceof Error&&"code"in p&&ne(p))return{status:"not_installed",path:a};throw p}if(!s.includes(ze)&&!s.includes(St))return{status:"not_installed",path:a};let c=await O(e),d=or(c),l=await nr(t,un(n,d),!1);return{status:l.changed?"refreshed":"unchanged",path:l.path}}finally{await i()}}async function _m(e,t){let n=Ts({cwd:process.cwd(),explicitPath:t.path,dryRun:e.dryRun===!0,environment:process.env}),o=n.pm_root;if(!await x(be(o)))throw new h(`Tracker is not initialized at ${o}. Run pm init first.`,g.NOT_FOUND);let r=await tr(n.workspace_start);return mn({pmRoot:o,workspaceRoot:r,dryRun:e.dryRun===!0})}async function mn(e){let t=L.resolve(e.pmRoot),n=L.resolve(e.workspaceRoot),o=e.dryRun===!0,r,i;try{[r,i]=await Promise.all([sn(t),sn(n)])}catch(m){throw new h(`Cannot resolve tracker root ${t} or workspace root ${n}: ${String(m)}`,g.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 a=pn(i,r);if(rn(a))throw new h(`Tracker root ${t} is outside the git repository ${n}; there is nothing to configure for this repository.`,g.USAGE);let s=await O(r),c=or(s),d=un(a,c),l=[],p=Qo();for(let m of er)l.push({key:`merge.${m.key}.name`,value:m.name}),l.push({key:`merge.${m.key}.driver`,value:`${p} merge driver ${m.artifact} "%O" "%A" "%B"${m.itemPath===void 0?"":` --item-path ${m.itemPath}`}`});if(!o)try{for(let m of l)await dn("git",["config","--local",m.key,m.value],{cwd:i,encoding:"utf8",windowsHide:!0,timeout:1e4})}catch{throw new h(`Cannot install repository-local merge drivers in ${i}. Ensure the repository Git config is writable and no other Git process holds its lock, then retry.`,g.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 u=await nr(i,d,o);return{ok:!0,dry_run:o,workspace_root:i,pm_root:r,gitattributes:{path:u.path,changed:u.changed,patterns:d,schema_scope:"project"},git_config:l,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:A()}}import{createHash as _r}from"node:crypto";import Ne from"node:fs/promises";import Ke 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]="2b5a573e-1e36-58b9-b93b-4a4088f71e9a")}catch{}})();var Os=new Set(Vt),Cs=new Set(Yt),ir=new Set([...to.filter(e=>e!=="severity"),"id","title","type","status","priority","tags","assignee","parent","description","body","created_at","updated_at","closed_at","completed_at","author","deadline","estimate","sprint","release","risk","confidence","reviewer","resolution","expected","actual"]),Rs=["create","update"];function dr(e){if(typeof e!="string")return"";let t=e.trim().toLowerCase().replaceAll(/[\s_]+/g,"-");return t.startsWith("--")?t.slice(2):t}function ar(e){return e.replaceAll("_","-")}function Ps(e,t){let n=new Set;for(let o of e){let r=dr(o);r.length>0&&r!==t&&n.add(r)}return[...n].sort((o,r)=>o.localeCompare(r))}function Ns(e){let t=new Set;for(let n of e??[]){let o=n.trim();o.length>0&&t.add(o)}return[...t].sort((n,o)=>n.localeCompare(o))}function Ds(e){let t=new Set,n=[];for(let o of e??[]){let r=o.trim().toLowerCase();if(r.length!==0){if(!Cs.has(r))throw new Error(`Invalid field command "${o}". Allowed: ${Yt.join(", ")}.`);t.has(r)||(t.add(r),n.push(r))}}return e===void 0||n.length===0?[...Rs]:n}function lr(e){let t=$(e.key);if(t.length===0)throw new Error("Field key must not be empty.");if(ir.has(t))throw new Error(`Cannot define custom field "${t}": custom schema field "${t}" collides with built-in item metadata "${t}". Rename the custom field with a project-specific prefix. Reserved fields: ${[...ir].sort((l,p)=>l.localeCompare(p)).join(", ")}.`);let n=typeof e.type=="string"&&e.type.trim().length>0?e.type.trim().toLowerCase():"string";if(!Os.has(n))throw new Error(`Invalid field type "${e.type}". Allowed: ${Vt.join(", ")}.`);let o=n,r=Ds(e.commands),i=dr(e.cliFlag),a=i.length>0&&i!==ar(t)?i:void 0,s=a??ar(t),c=Ps(e.aliases??[],s),d=e.description?.trim();return{key:t,type:o,commands:r,description:d&&d.length>0?d:void 0,cliFlag:a,cliAliases:c,required:e.required===!0,requiredOnCreate:e.requiredOnCreate===!0,allowUnset:e.allowUnset!==!1,requiredTypes:Ns(e.requiredTypes)}}function js(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;let t=e;if(Array.isArray(t.fields))return t.fields;if(Array.isArray(t.definitions))return t.definitions}function Fs(e){let t=js(e);if(!t)return[];let n=[];for(let o of t){if(typeof o!="object"||o===null||Array.isArray(o))continue;let r=o;typeof r.key!="string"||r.key.trim().length===0||n.push(r)}return n}function Je(e){if(e==null||e.trim().length===0)return{fields:[]};let t;try{t=JSON.parse(e)}catch{throw new Error("schema/fields.json contains invalid JSON.")}return{fields:Fs(t)}}function qe(e){return`${JSON.stringify({fields:e.fields},null,2)}
|
|
12
12
|
`}function pr(e,t){let n=e.fields.find(a=>$(a.key)===t.key),o=n!==void 0,r=e.fields.filter(a=>$(a.key)!==t.key),i={...n,key:t.key,type:t.type,commands:[...t.commands]};return sr(i,"description",t.description),sr(i,"cli_flag",t.cliFlag),t.cliAliases.length>0?i.cli_aliases=[...t.cliAliases]:delete i.cli_aliases,cr(i,"required",t.required),cr(i,"required_on_create",t.requiredOnCreate),t.allowUnset===!1?i.allow_unset=!1:delete i.allow_unset,t.requiredTypes.length>0?i.required_types=[...t.requiredTypes]:delete i.required_types,r.push(i),r.sort((a,s)=>$(a.key).localeCompare($(s.key))),{file:{fields:r},definition:i,replaced:o}}function ur(e,t){let n=$(t);if(n.length===0)throw new Error("Field key must not be empty.");let o=[],r=e.fields.filter(i=>$(i.key)===n?(o.push(i),!1):!0);return o.length===0?{file:{fields:r},removed:!1}:{file:{fields:r},removed:!0,definition:o[0]}}function sr(e,t,n){let o=e;n!==void 0&&n.length>0?o[t]=n:delete o[t]}function cr(e,t,n){let o=e;n?o[t]=!0:delete o[t]}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="3eac0218-43c9-5bd2-8eaf-589d02d2c8ad")}catch{}})();var Ls=new Set(Kt),Pe=new Set(wo.map(e=>$(e.id)).filter(e=>e.length>0));function Ms(e){let t=new Set;for(let n of e){let o=$(n);o.length>0&&t.add(o)}return[...t].sort((n,o)=>n.localeCompare(o))}function mr(e){let t=$(e.id);if(t.length===0)throw new Error("Status id must not be empty.");if(Pe.has(t))throw new Error(`Cannot add-status the built-in status "${t}". Built-in statuses are reserved: ${[...Pe].join(", ")}.`);let n;if(e.roles!==void 0){n=[];let a=new Set;for(let s of e.roles){let c=typeof s=="string"?s.trim().toLowerCase():"";if(c.length!==0){if(!Ls.has(c))throw new Error(`Invalid status role "${s}". Allowed roles: ${Kt.join(", ")}.`);a.has(c)||(a.add(c),n.push(c))}}}let o=e.aliases===void 0?void 0:Ms(e.aliases).filter(a=>a!==t),r=e.description?.trim(),i=typeof e.order=="number"&&Number.isFinite(e.order)?Math.trunc(e.order):void 0;return{id:t,roles:n,aliases:o,description:r&&r.length>0?r:void 0,order:i}}function Us(e){if(Array.isArray(e))return e;if(typeof e!="object"||e===null)return;let t=e;if(Array.isArray(t.statuses))return t.statuses;if(Array.isArray(t.definitions))return t.definitions}function Gs(e){let t=Us(e);if(!t)return[];let n=[];for(let o of t){if(typeof o!="object"||o===null||Array.isArray(o))continue;let r=o;typeof r.id!="string"||r.id.trim().length===0||n.push(r)}return n}function Be(e){if(e==null||e.trim().length===0)return{statuses:[]};let t;try{t=JSON.parse(e)}catch{throw new Error("schema/statuses.json contains invalid JSON.")}return{statuses:Gs(t)}}function We(e){return`${JSON.stringify({statuses:e.statuses},null,2)}
|
|
13
13
|
`}function fr(e,t,n){let o=e.statuses.slice(),r=o.findIndex(s=>$(s.id)===t.id),i=r>=0?o[r]:n,a={...i,id:t.id};return t.roles!==void 0&&(t.roles.length>0?a.roles=[...t.roles]:a.roles!==void 0&&delete a.roles),t.aliases!==void 0&&(t.aliases.length>0?a.aliases=[...t.aliases]:a.aliases!==void 0&&delete a.aliases),t.description!==void 0&&(a.description=t.description),t.order!==void 0&&(a.order=t.order),r>=0?o[r]=a:o.push(a),{file:{statuses:o},definition:a,replaced:i!==void 0}}function hr(e,t){let n=$(t);if(n.length===0)throw new Error("Status id must not be empty.");if(Pe.has(n))throw new Error(`Cannot remove built-in status "${n}". Built-in statuses are reserved: ${[...Pe].join(", ")}.`);let o=e.statuses.slice(),r=o.findIndex(a=>$(a.id)===n);if(r<0)return{file:{statuses:o},removed:!1};let[i]=o.splice(r,1);return{file:{statuses:o},removed:!0,definition:i}}function fn(e,t){let n=[e.id,...e.aliases??[]];for(let o of n){let r=$(o);if(r.length===0)continue;let i=t.get(r);if(i!==void 0&&i!==e.id)throw new Error(`Status token "${r}" already belongs to status "${i}". Choose a different id/alias to avoid shadowing it.`)}}(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]="cd777de3-665f-5e01-ac98-8986f2a5a4c2")}catch{}})();function ye(e,t){if(typeof e!="string"||e.trim().length===0)throw new TypeError(`Schema migration ${t} must be non-empty`);return e.trim()}function wr(e){let t=ye(e,"migrationId");if(!/^[a-zA-Z0-9._-]+$/.test(t))throw new TypeError("Schema migration migrationId must match [a-zA-Z0-9._-]+");return t}function vr(e,t){let n=gn(e),o=ye(t,"migrationScope");return`auto-${_r("sha256").update(JSON.stringify({scope:o,request:n})).digest("hex").slice(0,20)}`}function gn(e){let t=e.kind==="rename-type"?{kind:e.kind,from:ye(e.from,"source"),to:ye(e.to,"target")}:e.kind==="rename-field"?{kind:e.kind,from:$(ye(e.from,"source")),to:$(ye(e.to,"target")),...e.type===void 0?{}:{type:ye(e.type,"type")}}:{kind:e.kind,from:$(ye(e.from,"source")),to:$(ye(e.to,"target"))};if(t.from.toLowerCase()===t.to.toLowerCase())throw new TypeError("Schema migration source and target must differ");return t}function zs(e){return e.kind==="rename-type"?"types":e.kind==="rename-field"?"fields":"statuses"}function Js(e,t,n){let o=W(t.schema),r=zs(n);return ee(e,o.files[r],K[r])}function br(e,t){return Ke.join(e,"transactions","schema",`${t}-plan.json`)}function $t(e){return e.length===0?null:JSON.parse(e)}async function He(e){let t=await z(e);return{exists:t!==null,raw:t??""}}async function kr(e,t){t.exists?await he(e,t.raw):await Ne.rm(e,{force:!0})}function qs(e,t,n){let o=oe(e),r=o.definitions.findIndex(a=>a.name.trim().toLowerCase()===t.from.toLowerCase()),i=o.definitions.findIndex(a=>a.name.trim().toLowerCase()===t.to.toLowerCase());if(n==="stage"){if(i>=0)return de(o);if(r<0)throw new TypeError(`Unknown custom type "${t.from}".`);o.definitions.push({...o.definitions[r],name:t.to})}else r>=0&&o.definitions.splice(r,1);return de(o)}function Bs(e,t,n){let o=Je(e),r=o.fields.findIndex(a=>a.key===t.from),i=o.fields.findIndex(a=>a.key===t.to);if(n==="stage"){if(i>=0)return qe(o);if(r<0)throw new TypeError(`Unknown custom field "${t.from}".`);let a=o.fields[r];o.fields.push({...a,key:t.to,metadata_key:t.to,front_matter_key:t.to,cli_flag:t.to.replaceAll("_","-")})}else r>=0&&o.fields.splice(r,1);return qe(o)}function Ws(e,t,n){let o=Be(e),r=o.statuses.findIndex(a=>a.id===t.from),i=o.statuses.findIndex(a=>a.id===t.to);if(n==="stage"){if(i>=0)return We(o);if(r<0)throw new TypeError(`Unknown custom status "${t.from}".`);o.statuses.push({...o.statuses[r],id:t.to})}else r>=0&&o.statuses.splice(r,1);return We(o)}function Hs(e,t,n){return t.kind==="rename-type"?qs(e,t,n):t.kind==="rename-field"?Bs(e,t,n):Ws(e,t,n)}function Ae(e,t){return typeof e=="string"&&e.trim().toLowerCase()===t.from.toLowerCase()?t.to:e}function yn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}function Ve(e){return Array.isArray(e)?e.map(t=>yn(t)).filter(t=>t!==void 0):[]}function Ks(e,t){for(let n of Ve(e.fields))Array.isArray(n.required_types)&&(n.required_types=n.required_types.map(o=>Ae(o,t)));for(let n of Ve(e.type_workflows))n.type=Ae(n.type,t)}function Vs(e,t){for(let o of Ve(e.definitions))o.default_status=Ae(o.default_status,t);let n=yn(e.workflow);if(n)for(let[o,r]of Object.entries(n))n[o]=Ae(r,t);for(let o of Ve(e.type_workflows))Array.isArray(o.allowed_transitions)&&(o.allowed_transitions=o.allowed_transitions.map(r=>Array.isArray(r)?r.map(i=>Ae(i,t)):r))}function Ys(e,t){for(let n of Ve(e.definitions)){for(let o of["required_create_fields","required_create_repeatables"])Array.isArray(n[o])&&(n[o]=n[o].map(r=>Ae(r,t)));for(let o of["options","command_option_policies"])for(let r of Ve(n[o])){let i=o==="options"?"key":"option";r[i]=Ae(r[i],t)}}}function Xs(e,t){let n=yn(e.options);if(!n)return;if(t.kind==="rename-field"){if(!Object.prototype.hasOwnProperty.call(n,t.from))return;if(Object.prototype.hasOwnProperty.call(n,t.to))throw new TypeError(`Schema migration collision in saved template "${String(e.name??"unknown")}": target field "${t.to}" already exists.`);n[t.to]=n[t.from],delete n[t.from];return}let o=t.kind==="rename-type"?"type":"status";n[o]=Ae(n[o],t)}function hn(e,t){let n=JSON.parse(e);if(typeof n!="object"||n===null||Array.isArray(n))return e;let o=n;return t.kind==="rename-type"?Ks(o,t):t.kind==="rename-field"?Ys(o,t):Vs(o,t),Xs(o,t),`${JSON.stringify(o,null,2)}
|
|
14
14
|
`}function xr(e,t){if(t.kind==="rename-type"){let o=oe(e).definitions;return{source:o.some(r=>r.name.trim().toLowerCase()===t.from.toLowerCase()),target:o.some(r=>r.name.trim().toLowerCase()===t.to.toLowerCase())}}if(t.kind==="rename-field"){let o=Je(e).fields;return{source:o.some(r=>r.key===t.from),target:o.some(r=>r.key===t.to)}}let n=Be(e).statuses;return{source:n.some(o=>o.id===t.from),target:n.some(o=>o.id===t.to)}}function Zs(e,t){let n=e;return t.kind==="rename-type"?e.type.toLowerCase()===t.to.toLowerCase()?[]:["type"]:t.kind==="remap-status"?e.status.toLowerCase()===t.to.toLowerCase()?[]:["status"]:Object.prototype.hasOwnProperty.call(n,t.to)&&!Object.prototype.hasOwnProperty.call(n,t.from)?[]:[t.from,t.to]}function Qs(e,t){if(t.kind==="rename-type")return e.type.toLowerCase()===t.from.toLowerCase()?{id:e.id,changes:[{field:"type",before:e.type,after:t.to}]}:null;if(t.kind==="remap-status")return e.status.toLowerCase()===t.from.toLowerCase()?{id:e.id,changes:[{field:"status",before:e.status,after:t.to}]}:null;if(t.type!==void 0&&e.type.toLowerCase()!==t.type.toLowerCase())return null;let n=e;if(!Object.prototype.hasOwnProperty.call(n,t.from))return null;if(Object.prototype.hasOwnProperty.call(n,t.to))throw new TypeError(`Schema migration collision on item "${e.id}": target field "${t.to}" already exists.`);return{id:e.id,changes:[{field:t.from,before:n[t.from],after:void 0},{field:t.to,before:void 0,after:n[t.from]}]}}function Sr(e,t){let n=gn(t.request),o=t.migrationId===void 0?vr(n,t.migrationScope??"plan"):wr(t.migrationId),r=e.map(c=>Qs(c,n)).filter(c=>c!==null).sort((c,d)=>c.id.localeCompare(d.id)),i=_r("sha256").update(JSON.stringify({migrationId:o,request:n,items:r})).digest("hex"),a=new Set([...t.completedItemIds??[]].map(c=>c.trim()).filter(c=>c.length>0)),s=r.filter(c=>!a.has(c.id));return Object.freeze({migration_id:o,request:n,fingerprint:i,affected_item_count:r.length,pending_item_count:s.length,skipped_completed_count:r.length-s.length,items:Object.freeze(s)})}async function ec(e){let t=J(e.settings,B()),n=[...new Set(Object.values(t.type_to_folder))],o=await To(e.pmRoot,n),r=e.request.kind==="rename-type"?{types:[e.request.from]}:e.request.kind==="remap-status"?{statuses:[e.request.from]}:{metadataKeys:[e.request.from],...e.request.type===void 0?{}:{types:[e.request.type]}},i=o?await Ao({pmRoot:e.pmRoot,expectedSourceCursor:o.source_cursor,query:r}):null;return i?{items:i.items,selectionSource:"derived_index",typeToFolder:t.type_to_folder}:{items:await Ce(e.pmRoot,e.settings.item_format,t.type_to_folder,[],e.settings.schema),selectionSource:"scan",typeToFolder:t.type_to_folder}}async function tc(e,t){let n=await z(br(e,t));if(n===null)return null;try{let o=JSON.parse(n);if(o.schema_version!==1||o.plan.migration_id!==t||!Array.isArray(o.plan.items))throw new TypeError("invalid plan envelope");return o.plan}catch(o){throw new h(`Stored schema migration plan "${t}" is invalid: ${oo(o)}`,g.GENERIC_FAILURE)}}async function nc(e,t){let n=br(e,t.migration_id);await Ne.mkdir(Ke.dirname(n),{recursive:!0});let o={schema_version:1,plan:t,created_at:new Date().toISOString()};await he(n,`${JSON.stringify(o,null,2)}
|
|
15
15
|
`)}function oc(e,t){return JSON.stringify(e)===JSON.stringify(t)}async function rc(e){let t=await Io(e.pmRoot,e.id,e.settings.id_prefix,e.settings.item_format,e.typeToFolder);if(!t)throw new h(`Schema migration item "${e.id}" no longer exists.`,g.NOT_FOUND);return(await Oo(t,{schema:e.settings.schema})).document.metadata}function gr(e,t,n){let o=n==="forward"?t.from:t.to,r=n==="forward"?t.to:t.from;if(t.kind==="rename-type"){if(e.metadata.type.toLowerCase()===r.toLowerCase())return[];if(e.metadata.type.toLowerCase()!==o.toLowerCase())throw new TypeError(`Schema migration expected type "${o}" on item "${e.metadata.id}".`);return e.metadata.type=r,["type"]}if(t.kind==="remap-status"){if(e.metadata.status.toLowerCase()===r.toLowerCase())return[];if(e.metadata.status.toLowerCase()!==o.toLowerCase())throw new TypeError(`Schema migration expected status "${o}" on item "${e.metadata.id}".`);return e.metadata.status=r,["status"]}let i=e.metadata;if(Object.prototype.hasOwnProperty.call(i,r)&&!Object.prototype.hasOwnProperty.call(i,o))return[];if(!Object.prototype.hasOwnProperty.call(i,o)||Object.prototype.hasOwnProperty.call(i,r))throw new TypeError(`Schema migration field state changed concurrently on item "${e.metadata.id}".`);return i[r]=i[o],delete i[o],[o,r]}function yr(e){return{id:e.id,inspect:async()=>{let t=await He(e.filePath),n=xr(t.raw,e.request),o=e.phase==="stage"?n.source&&n.target:!n.source&&n.target;return{state:o?"applied":"pending",...o?{result:{phase:e.phase}}:{}}},prepareCompensation:async()=>{let t=await He(e.filePath);return{exists:t.exists,raw:t.raw}},apply:async()=>{let t=await He(e.filePath);return await he(e.filePath,Hs(t.raw,e.request,e.phase)),{phase:e.phase}},compensate:async t=>{if(typeof t!="object"||t===null||Array.isArray(t)||typeof t.exists!="boolean"||typeof t.raw!="string")throw new TypeError(`Missing schema snapshot for ${e.id} compensation.`);await kr(e.filePath,{exists:t.exists,raw:t.raw})}}}function ic(e){return{id:e.stepId,inspect:async()=>{let t=await He(e.filePath);return{state:hn(t.raw,e.request)===t.raw?"applied":"pending"}},prepareCompensation:async()=>{let t=await He(e.filePath);return{exists:t.exists,raw:t.raw}},apply:async()=>{let t=await He(e.filePath);return await he(e.filePath,hn(t.raw,e.request)),{file:e.filePath}},compensate:async t=>{if(typeof t!="object"||t===null||Array.isArray(t)||typeof t.exists!="boolean"||typeof t.raw!="string")throw new TypeError(`Missing schema reference snapshot for ${e.stepId} compensation.`);await kr(e.filePath,{exists:t.exists,raw:t.raw})}}}function ac(e){return{id:`item-${e.id}`,inspect:async()=>{let t=await O(e.pmRoot),n=J(t,B()).type_to_folder,o=await rc({pmRoot:e.pmRoot,settings:t,typeToFolder:n,id:e.id}),r=Zs(o,e.request).length===0;return{state:r?"applied":"pending",...r?{result:{item_id:e.id}}:{}}},apply:async()=>{let t=await O(e.pmRoot),n=J(t,B()).type_to_folder,o=await Qt({pmRoot:e.pmRoot,settings:t,typeToFolder:n,id:e.id,op:`schema_${e.request.kind.replaceAll("-","_")}`,author:e.author,message:`Schema migration ${e.request.kind}: ${e.request.from} -> ${e.request.to}`,force:e.force,skipNoop:!0,mutate(r){return{changedFields:gr(r,e.request,"forward")}}});return{item_id:e.id,changed_fields:o.changedFields}},compensate:async()=>{let t=await O(e.pmRoot),n=J(t,B()).type_to_folder;await Qt({pmRoot:e.pmRoot,settings:t,typeToFolder:n,id:e.id,op:`schema_${e.request.kind.replaceAll("-","_")}_compensate`,author:e.author,message:`Compensate schema migration ${e.request.kind}: ${e.request.to} -> ${e.request.from}`,force:!0,skipNoop:!0,mutate(o){return{changedFields:gr(o,e.request,"reverse")}}})}}}async function sc(e){let t=await tc(e.pmRoot,e.migrationId);if(t){if(!oc(t.request,e.request))throw new h(`Schema migration id "${e.migrationId}" already belongs to a different request.`,g.CONFLICT);return{plan:t,stored:!0}}let n=await ec({pmRoot:e.pmRoot,settings:e.settings,request:e.request});return{plan:{...Sr(n.items,{migrationId:e.migrationId,request:e.request}),selection_source:n.selectionSource},stored:!1}}async function cc(e){let t=xr(await z(e.schemaPath)??"",e.request);if(!t.source)throw new h(`Schema migration source "${e.request.from}" is not a custom definition.`,g.NOT_FOUND);if(t.target)throw new h(`Schema migration target "${e.request.to}" already exists.`,g.CONFLICT);await nc(e.pmRoot,e.plan)}async function dc(e){let t=W(e.settings.schema),n=[...new Set([["types",K.types],["fields",K.fields],["workflows",K.workflows]].map(([r,i])=>ee(e.pmRoot,t.files[r],i)).filter(r=>r!==e.schemaPath))];try{let r=Ke.join(e.pmRoot,"templates"),i=await Ne.readdir(r,{withFileTypes:!0});n.push(...i.filter(a=>a.isFile()&&a.name.toLowerCase().endsWith(".json")).map(a=>Ke.join(r,a.name)))}catch(r){if(typeof r!="object"||r===null||!("code"in r)||!ne(r))throw r}n.sort((r,i)=>r.localeCompare(i));let o=[];for(let r of n){let i=await z(r);i!==null&&hn(i,e.request)!==i&&o.push({filePath:r,beforeRaw:i})}return{paths:n,snapshots:o}}async function lc(e){for(let t of e.snapshots){let n=await Ne.readFile(t.filePath,"utf8"),o=Ke.relative(e.pmRoot,t.filePath).replaceAll("\\","/");await Zt({pmRoot:e.pmRoot,author:e.author,documentPath:o,before:$t(t.beforeRaw),after:$t(n),op:"schema_migration_reference",idempotencyKey:`${e.plan.migration_id}:${e.plan.fingerprint}:${o}`,message:`${e.request.kind}: ${e.request.from} -> ${e.request.to}`,lockTtlSeconds:e.settings.locks.ttl_seconds,lockWaitMs:e.settings.locks.wait_ms})}}async function pc(e,t,n){let o=gn(e),r=j(process.cwd(),n.path);if(!await x(be(r)))throw new h(`Tracker is not initialized at ${r}. Run pm init first.`,g.NOT_FOUND);let i=t.migrationId===void 0?vr(o,await Ne.realpath(r)):wr(t.migrationId),a=await O(r),s=H(t.author,a.author_default),c=await sc({pmRoot:r,settings:a,migrationId:i,request:o}),d=c.plan;if(t.dryRun===!0)return{...d,action:o.kind,applied:!1,recovered:!1,migrated_item_count:0};let l=Js(r,a,o),p=await Ne.readFile(l,"utf8");c.stored||await cc({pmRoot:r,schemaPath:l,request:o,plan:d});let u=await dc({pmRoot:r,schemaPath:l,settings:a,request:o}),m=[yr({id:"stage-schema",filePath:l,request:o,phase:"stage"}),...u.paths.map((_,v)=>ic({filePath:_,request:o,stepId:`reference-${String(v+1).padStart(4,"0")}`})),...d.items.map(_=>ac({pmRoot:r,id:_.id,request:o,author:s,force:t.force===!0})),yr({id:"retire-source",filePath:l,request:o,phase:"retire"})],y=await Go({pmRoot:r,transactionId:`schema-${i}`,author:s,steps:m,lockTtlSeconds:Math.max(a.locks.ttl_seconds,300),lockWaitMs:a.locks.wait_ms}),w=await Ne.readFile(l,"utf8"),{historyPath:f}=await Zt({pmRoot:r,author:s,documentPath:Ke.relative(r,l).replaceAll("\\","/"),before:$t(p),after:$t(w),op:"schema_migration",idempotencyKey:`${d.migration_id}:${d.fingerprint}`,message:`${o.kind}: ${o.from} -> ${o.to}; affected=${d.affected_item_count}`,lockTtlSeconds:a.locks.ttl_seconds,lockWaitMs:a.locks.wait_ms});return await lc({pmRoot:r,author:s,settings:a,request:o,plan:d,snapshots:u.snapshots}),{...d,action:o.kind,applied:!0,recovered:y.recovered,migrated_item_count:d.affected_item_count,workspace_history_path:f}}function uc(e){let t=e.applied?"applied":"dry-run",n=e.recovered?" (recovered)":"";return[`${e.action}: ${e.request.from} -> ${e.request.to} [${t}${n}]`,`migration_id: ${e.migration_id}`,`affected: ${e.affected_item_count}`,`pending: ${e.pending_item_count}`,`fingerprint: ${e.fingerprint}`].join(`
|
|
16
|
-
`)}import yc from"node:path";import{mkdir as _c}from"node:fs/promises";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e3f016bb-8add-5765-bb1a-a7b22423f8d1")}catch{}})();var ot=["agile","ops","research"],mc={agile:[{name:"Story",description:"User-facing outcome or capability slice expressed from a stakeholder perspective.",defaultStatus:"open",folder:"stories",aliases:["user-story"]},{name:"Spike",description:"Time-boxed investigation used to reduce uncertainty before implementation.",defaultStatus:"open",folder:"spikes",aliases:["research-spike"]}],ops:[{name:"Incident",description:"Operational disruption, degradation, or support escalation with recovery tracking.",defaultStatus:"open",folder:"incidents",aliases:["outage"]},{name:"Runbook",description:"Repeatable operational procedure, diagnostic path, or response playbook.",defaultStatus:"open",folder:"runbooks",aliases:["playbook"]}],research:[{name:"Experiment",description:"Validated-learning activity with hypothesis, method, and outcome tracking.",defaultStatus:"open",folder:"experiments",aliases:["study"]},{name:"Hypothesis",description:"Testable claim or assumption that should be supported, rejected, or refined.",defaultStatus:"open",folder:"hypotheses",aliases:["assumption"]}]};function At(e){if(e===void 0)return;let t=e.trim().toLowerCase().replaceAll("-","_");if(t.length===0)throw new Error("Type preset name must not be empty.");if(t==="agile"||t==="ops"||t==="research")return t;throw new Error(`Invalid type preset "${e}". Allowed: ${ot.join(", ")}.`)}function rt(e){return mc[e].map(t=>tt(t))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="3d53ef97-6dd5-5dea-a5c2-9bc9e62d881c")}catch{}})();var fc=/^([A-Za-z][A-Za-z0-9_-]*?)\s*[-:]\s+\S/;function hc(e){let t=fc.exec(e.trim());if(!t)return;let n=t[1];if(!(n.length<2)&&!/^[A-Za-z]\d+$/.test(n))return n.toLowerCase()}function gc(e){return e.split(/[-_]+/).filter(t=>t.length>0).map(t=>`${t.slice(0,1).toUpperCase()}${t.slice(1).toLowerCase()}`).join("")}function Er(e,t={}){let n=typeof t.minCount=="number"&&t.minCount>0?Math.trunc(t.minCount):10,o=typeof t.maxExamples=="number"&&t.maxExamples>0?Math.trunc(t.maxExamples):3,r=new Map;for(let a of e){let s=typeof a=="string"?a.trim():"";if(s.length===0)continue;let c=hc(s);if(c===void 0)continue;let d=r.get(c)??{count:0,examples:[]};d.count+=1,d.examples.length<o&&d.examples.push(s),r.set(c,d)}let i=[];for(let[a,s]of r.entries()){if(s.count<n)continue;let c=gc(a);i.push({name:c,prefix:a,count:s.count,examples:s.examples,shadows_builtin:xo(c)!==void 0})}return i.sort((a,s)=>s.count-a.count||a.name.localeCompare(s.name)),i}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="1a035e10-b8fe-52cd-a9c7-0762dd0ab160")}catch{}})();var $f=["add-type","remove-type","add-status","remove-status","add-field","remove-field","list-fields","show-field","apply-preset","list","show","show-status","rename-type","rename-field","remap-status"],Tt="schema-types",$r="schema-statuses",Ar="schema-fields";function Te(e){return Me({pmRoot:e.pmRoot,filePath:e.filePath,raw:e.raw,op:e.op,author:e.author,lockTtlSeconds:e.settings.locks.ttl_seconds,lockWaitMs:e.settings.locks.wait_ms})}async function Af(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{r=tt({name:e,description:t.description,defaultStatus:t.defaultStatus,folder:t.folder,aliases:t.alias})}catch(m){throw new h(m instanceof Error?m.message:String(m),g.USAGE)}let i=await O(o),a=W(i.schema),s=ee(o,a.files.types,K.types),c=[],d=H(t.author,i.author_default),l=re(i),p=await Y(o,Tt,i.locks.ttl_seconds,d,!!t.force,l.force_required_for_stale_lock,i.locks.wait_ms),u;try{let m=await z(s),y;try{y=oe(m)}catch(w){throw new h(w instanceof Error?w.message:String(w),g.GENERIC_FAILURE)}try{So(r,y);let w=new Map,f=J(i,B());for(let[_,v]of Object.entries(f.type_to_folder)){let k=v.trim().toLowerCase();k.length>0&&!w.has(k)&&w.set(k,_)}Eo(r,y,w)}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}u=Ue(y,r),u.replaced&&u.previousName!==void 0&&u.previousName!==u.definition.name&&c.push(`type_recased:${u.previousName}->${u.definition.name}`),await Te({pmRoot:o,filePath:s,raw:de(u.file),op:"schema:add-type",author:d,settings:i}),await it(o,[u.definition],c,"schema:add-type-folder"),c.push(...await q({path:s,scope:"project",op:"schema:add-type"}))}finally{await p()}return await Tr(o,c),{action:"add-type",registered:!0,replaced:u.replaced,type:u.definition,file:{path:s,definitions:u.file.definitions.length},warnings:Ie(c),generated_at:A()}}async function _e(e){if(!await x(be(e)))throw new h(`Tracker is not initialized at ${e}. Run pm init first.`,g.NOT_FOUND)}async function Tr(e,t){try{let n=await rr(e);n.status==="refreshed"?t.push("merge_fence_refreshed"):n.status==="not_installed"&&t.push('merge_fence_not_installed:type folders lack git merge drivers; run "pm merge install"')}catch{t.push('merge_fence_refresh_failed:run "pm merge install" to reconcile')}}function Ie(e){return[...new Set(e)].sort((t,n)=>t.localeCompare(n))}async function wc(e,t,n,o){let r=J(t,B()),i=o.trim().toLowerCase();return(await Ce(e,t.item_format,r.type_to_folder,[],n)).filter(s=>typeof s.type=="string"&&s.type.toLowerCase()===i).length}async function vc(e,t,n,o){let r=J(t,B()),i=Qe(n),a=$(o);return(await Ce(e,t.item_format,r.type_to_folder,[],n)).filter(c=>{let d=typeof c.status=="string"?c.status:"";return(i.alias_to_id.get($(d))??$(d))===a}).length}async function bc(e,t,n,o,r){if(r.length===0||Pe.has(r))return;let i=await vc(t,n,o,r);i>0&&e.push(`items_using_status:${i}`);let a=Ir(o.workflow,r);a.length>0&&e.push(`status_referenced_by_workflow:${a.join(",")}`)}function Ir(e,t){return[["draft_status",e.draft_status],["open_status",e.open_status],["in_progress_status",e.in_progress_status],["blocked_status",e.blocked_status],["close_status",e.close_status],["canceled_status",e.canceled_status]].filter(([,o])=>o!==void 0&&$(o)===t).map(([o])=>o)}async function Tf(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r=await O(o),i=W(r.schema),a=ee(o,i.files.types,K.types),s=[],c=H(t.author,r.author_default),d=re(r),l=await Y(o,Tt,r.locks.ttl_seconds,c,!!t.force,d.force_required_for_stale_lock,r.locks.wait_ms),p;try{let u=await z(a),m;try{m=oe(u)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.GENERIC_FAILURE)}try{p=$o(m,e)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}if(p.removed){let y=(p.definition?.name??e??"").trim();if(y.length>0){let w=await wc(o,r,i,y);w>0&&s.push(`items_using_type:${w}`)}await Te({pmRoot:o,filePath:a,raw:de(p.file),op:"schema:remove-type",author:c,settings:r}),s.push(...await q({path:a,scope:"project",op:"schema:remove-type"}))}}finally{await l()}return p.removed&&await Tr(o,s),{action:"remove-type",removed:p.removed,...p.definition?{type:p.definition}:{},file:{path:a,definitions:p.file.definitions.length},warnings:Ie(s),generated_at:A()}}function _n(e,t){return ee(e,t.files.statuses,K.statuses)}function It(e,t){return ee(e,t.files.fields,K.fields)}function Or(e,t){return ee(e,t.files.types,K.types)}async function it(e,t,n,o){for(let r of t){let i=so(r.folder??ao(r.name)),a=yc.join(e,i);await x(a)||(await _c(a,{recursive:!0}),n.push(...await q({path:a,scope:"project",op:o})))}}function wn(e){return{key:e.key,type:e.type,commands:[...e.commands],cli_flag:`--${e.cli_flag}`,cli_aliases:e.cli_aliases.map(t=>`--${t}`),...e.description?{description:e.description}:{},required:e.required,required_on_create:e.required_on_create,allow_unset:e.allow_unset,required_types:[...e.required_types]}}function kc(e){if(e)return{id:e.id,...e.roles.length>0?{roles:[...e.roles]}:{},...e.aliases.length>0?{aliases:[...e.aliases]}:{},...e.description?{description:e.description}:{},...typeof e.order=="number"?{order:e.order}:{}}}function xc(e){let t=new Map;for(let n of e){let o=$(n.id);if(o.length!==0){t.set(o,o);for(let r of Array.isArray(n.aliases)?n.aliases:[]){let i=$(r);i.length>0&&!t.has(i)&&t.set(i,o)}}}return t}async function If(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{r=mr({id:e,roles:t.role,aliases:t.alias,description:t.description,order:t.order})}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}let i=await O(o),a=W(i.schema),s=_n(o,a),c=Qe(a);try{fn(r,c.alias_to_id)}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}let d=kc(c.by_id.get(r.id)),l=[],p=H(t.author,i.author_default),u=re(i),m=await Y(o,$r,i.locks.ttl_seconds,p,!!t.force,u.force_required_for_stale_lock,i.locks.wait_ms),y;try{let w=await z(s),f;try{f=Be(w)}catch(v){throw new h(v instanceof Error?v.message:String(v),g.GENERIC_FAILURE)}let _=xc(f.statuses);try{fn(r,_)}catch(v){throw new h(v instanceof Error?v.message:String(v),g.USAGE)}y=fr(f,r,d),await Te({pmRoot:o,filePath:s,raw:We(y.file),op:"schema:add-status",author:p,settings:i}),l.push(...await q({path:s,scope:"project",op:"schema:add-status"}))}finally{await m()}return{action:"add-status",registered:!0,replaced:y.replaced,status:y.definition,file:{path:s,statuses:y.file.statuses.length},warnings:Ie(l),generated_at:A()}}async function Of(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r=await O(o),i=W(r.schema),a=_n(o,i),s=[],c=H(t.author,r.author_default),d=re(r),l=await Y(o,$r,r.locks.ttl_seconds,c,!!t.force,d.force_required_for_stale_lock,r.locks.wait_ms),p;try{let u=await z(a),m;try{m=Be(u)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.GENERIC_FAILURE)}try{p=hr(m,e)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}if(p.removed){let y=$(p.definition?.id??e);await bc(s,o,r,i,y),await Te({pmRoot:o,filePath:a,raw:We(p.file),op:"schema:remove-status",author:c,settings:r}),s.push(...await q({path:a,scope:"project",op:"schema:remove-status"}))}}finally{await l()}return{action:"remove-status",removed:p.removed,...p.definition?{status:p.definition}:{},file:{path:a,statuses:p.file.statuses.length},warnings:Ie(s),generated_at:A()}}function Cr(e){return{name:e.name,folder:e.folder,aliases:Array.isArray(e.aliases)?[...e.aliases]:[],...e.default_status?{default_status:e.default_status}:{},...e.description?{description:e.description}:{}}}function Sc(e,t,n){return{...Cr(e),source:t,...n?{extension:n}:{},required_create_fields:[...e.required_create_fields],required_create_repeatables:[...e.required_create_repeatables],options:structuredClone(e.options),command_option_policies:structuredClone(e.command_option_policies)}}function Rr(e){return{id:e.id,source:Pe.has(e.id)?"builtin":"custom",roles:Array.isArray(e.roles)?[...e.roles]:[],aliases:Array.isArray(e.aliases)?[...e.aliases]:[],...e.description?{description:e.description}:{},...typeof e.order=="number"?{order:e.order}:{}}}function Pr(e,t,n){let o=e.toLowerCase();return n.has(o)?"extension":t.has(o)?"custom":"builtin"}function Ec(){let e=new Map,t=B();for(let n of t?.item_types??[]){let o=n.types;if(Array.isArray(o))for(let r of o){if(typeof r!="object"||r===null||Array.isArray(r))continue;let i=r.name;typeof i=="string"&&i.trim().length>0&&e.set(i.trim().toLowerCase(),{layer:n.layer,name:n.name})}}return e}function $c(e){let t=Qe(e),n=[],o=[];for(let r of t.definitions){let i=Rr(r);i.source==="builtin"?n.push(i):o.push(i)}return{builtin:n,custom:o}}async function at(e){let t=j(process.cwd(),e.path);await _e(t);let n=await O(t),o=W(n.schema),r=ee(t,o.files.types,K.types),i=_n(t,o),a=J(n,B()),s=Ec(),c=new Set((n.item_types?.definitions??[]).map(d=>d.name.trim().toLowerCase()).filter(d=>d.length>0&&!s.has(d)));return{pmRoot:t,typesPath:r,statusesPath:i,byType:a.by_type,customNames:c,extensionProvenance:s,schema:o}}async function Cf(e){let t=await at(e),n=[],o=[],r=[];for(let s of Object.values(t.byType).sort((c,d)=>c.name.localeCompare(d.name))){let c=Pr(s.name,t.customNames,new Set(t.extensionProvenance.keys())),d=Cr(s);c==="extension"?r.push(d):c==="custom"?o.push(d):n.push(d)}let i=$c(t.schema),a=bt(t.schema).definitions.map(wn);return{action:"list",builtin:n,custom:o,extension:r,counts:{builtin:n.length,custom:o.length,extension:r.length,total:n.length+o.length+r.length},statuses:{builtin:i.builtin,custom:i.custom,counts:{builtin:i.builtin.length,custom:i.custom.length,total:i.builtin.length+i.custom.length}},fields:{custom:a,counts:{total:a.length}},file:{path:t.typesPath},generated_at:A()}}async function Rf(e,t){let n=(e??"").trim();if(n.length===0)throw new h("Type name must not be empty.",g.USAGE);let o=await at(t),r=Object.values(o.byType).find(i=>i.name.toLowerCase()===n.toLowerCase()||i.aliases.some(a=>a.toLowerCase()===n.toLowerCase()));if(!r)throw new h(`Unknown item type "${n}". Run pm schema list to inspect registered types, or pm schema add-type "${et(n)}" to register it.`,g.NOT_FOUND,{code:"unknown_item_type"});return{action:"show",type:Sc(r,Pr(r.name,o.customNames,new Set(o.extensionProvenance.keys())),o.extensionProvenance.get(r.name.toLowerCase())),file:{path:o.typesPath},generated_at:A()}}async function Pf(e,t){let n=$(e);if(n.length===0)throw new h("Status id must not be empty.",g.USAGE);let o=await at(t),r=Qe(o.schema),i=r.alias_to_id.get(n)??n,a=r.by_id.get(i);if(!a)throw new h(`Unknown status "${e}". Run pm schema list to inspect registered statuses, or pm schema add-status "${et(e??"")}" to register it.`,g.NOT_FOUND,{code:"unknown_status"});return{action:"show-status",status:Rr(a),file:{path:o.statusesPath},generated_at:A()}}async function Nf(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{r=lr({key:e,type:t.type,commands:t.commands,description:t.description,cliFlag:t.cliFlag,aliases:t.alias,required:t.required,requiredOnCreate:t.requiredOnCreate,allowUnset:t.allowUnset,requiredTypes:t.requiredTypes})}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}let i=await O(o),a=W(i.schema),s=It(o,a),c=[],d=kt(r.key);d&&c.push(`custom_field_mcp_input_collision:${d.field}:${d.property}:${d.owner}:use=${d.nested_path}`);let l=H(t.author,i.author_default),p=re(i),u=await Y(o,Ar,i.locks.ttl_seconds,l,!!t.force,p.force_required_for_stale_lock,i.locks.wait_ms),m;try{let y=await z(s),w;try{w=Je(y)}catch(f){throw new h(f instanceof Error?f.message:String(f),g.GENERIC_FAILURE)}m=pr(w,r),await Te({pmRoot:o,filePath:s,raw:qe(m.file),op:"schema:add-field",author:l,settings:i}),c.push(...await q({path:s,scope:"project",op:"schema:add-field"}))}finally{await u()}return{action:"add-field",registered:!0,replaced:m.replaced,field:m.definition,file:{path:s,fields:m.file.fields.length},warnings:Ie(c),generated_at:A()}}async function Ac(e,t,n,o){let r=J(t,B());return(await Ce(e,t.item_format,r.type_to_folder,[],n)).filter(a=>{let s=a[o];return s==null?!1:Array.isArray(s)?s.length>0:typeof s=="string"?s.trim().length>0:!0}).length}async function Df(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r=await O(o),i=W(r.schema),a=It(o,i),s=[],c=H(t.author,r.author_default),d=re(r),l=await Y(o,Ar,r.locks.ttl_seconds,c,!!t.force,d.force_required_for_stale_lock,r.locks.wait_ms),p;try{let u=await z(a),m;try{m=Je(u)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.GENERIC_FAILURE)}try{p=ur(m,e)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}if(p.removed){let y=$(p.definition?.key??e),w=$(p.definition?.metadata_key??p.definition?.front_matter_key??y);if(w.length>0){let f=await Ac(o,r,i,w);f>0&&s.push(`items_using_field:${f}`)}await Te({pmRoot:o,filePath:a,raw:qe(p.file),op:"schema:remove-field",author:c,settings:r}),s.push(...await q({path:a,scope:"project",op:"schema:remove-field"}))}}finally{await l()}return{action:"remove-field",removed:p.removed,...p.definition?{field:p.definition}:{},file:{path:a,fields:p.file.fields.length},warnings:Ie(s),generated_at:A()}}async function jf(e){let t=await at(e),n=bt(t.schema).definitions.map(wn);return{action:"list-fields",fields:n,counts:{total:n.length},file:{path:It(t.pmRoot,t.schema)},generated_at:A()}}async function Ff(e,t){let n=$(e);if(n.length===0)throw new h("Field key must not be empty.",g.USAGE);let o=await at(t),r=bt(o.schema).by_key.get(n);if(!r)throw new h(`Unknown custom field "${e}". Run pm schema list-fields to inspect registered fields, or pm schema add-field "${et(e??"")}" to register it.`,g.NOT_FOUND,{code:"unknown_field"});return{action:"show-field",field:wn(r),file:{path:It(o.pmRoot,o.schema)},generated_at:A()}}async function Lf(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{let w=At(e);if(w===void 0)throw new Error(`Type preset name is required. Allowed: ${ot.join(", ")}.`);r=w}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}let i=await O(o),a=W(i.schema),s=Or(o,a),c=[],d=H(t.author,i.author_default),l=re(i),p=[],u=[],m,y=await Y(o,Tt,i.locks.ttl_seconds,d,!!t.force,l.force_required_for_stale_lock,i.locks.wait_ms);try{let w=await z(s),f;try{f=oe(w)}catch(v){throw new h(v instanceof Error?v.message:String(v),g.GENERIC_FAILURE)}let _=f;for(let v of rt(r)){let k=Ue(_,v);_=k.file,(k.replaced?u:p).push(k.definition.name)}m=_.definitions.length,await Te({pmRoot:o,filePath:s,raw:de(_),op:"schema:apply-preset",author:d,settings:i}),await it(o,rt(r),c,"schema:apply-preset-folder"),c.push(...await q({path:s,scope:"project",op:"schema:apply-preset"}))}finally{await y()}return{action:"apply-preset",preset:r,registered:p,replaced:u,file:{path:s,definitions:m},warnings:Ie(c),generated_at:A()}}function Tc(e){if(e===void 0)return 10;if(!Number.isInteger(e)||e<1)throw new h("--min-count must be a positive integer (>= 1).",g.USAGE);return e}async function Mf(e,t){let n=j(process.cwd(),t.path);await _e(n);let o=await O(n),r=W(o.schema),i=Or(n,r),a=Tc(e.minCount),s=J(o,B()),d=(await Ce(n,o.item_format,s.type_to_folder,[],r)).map(k=>typeof k.title=="string"?k.title:""),l=Er(d,{minCount:a}),p=[],u=[],m=[],y=[],w;if(!e.apply){let k;try{k=oe(await z(i))}catch(T){throw new h(T instanceof Error?T.message:String(T),g.GENERIC_FAILURE)}return w=k.definitions.length,{action:"infer-types",applied:!1,min_count:a,candidates:l,registered:u,replaced:m,skipped:y,file:{path:i,definitions:w},warnings:p,generated_at:A()}}let f=H(e.author,o.author_default),_=re(o),v=await Y(n,Tt,o.locks.ttl_seconds,f,!!e.force,_.force_required_for_stale_lock,o.locks.wait_ms);try{let k=await z(i),T;try{T=oe(k)}catch(C){throw new h(C instanceof Error?C.message:String(C),g.GENERIC_FAILURE)}let R=T;for(let C of l){if(C.shadows_builtin){y.push({name:C.name,reason:"shadows_builtin"});continue}let se;try{se=tt({name:C.name})}catch{y.push({name:C.name,reason:"invalid_type_token"});continue}let fe=Ue(R,se);R=fe.file,(fe.replaced?m:u).push(fe.definition.name)}w=R.definitions.length,await Te({pmRoot:n,filePath:i,raw:de(R),op:"schema:infer-types",author:f,settings:o}),await it(n,R.definitions.filter(C=>u.includes(C.name)||m.includes(C.name)),p,"schema:infer-types-folder"),p.push(...await q({path:i,scope:"project",op:"schema:infer-types"}))}finally{await v()}return{action:"infer-types",applied:!0,min_count:a,candidates:l,registered:u,replaced:m,skipped:y,file:{path:i,definitions:w},warnings:Ie(p),generated_at:A()}}function Uf(e){let t=e.replaced?"Updated":"Registered",n=e.type.aliases&&e.type.aliases.length>0?` (aliases: ${e.type.aliases.join(", ")})`:"";return`${t} custom item type "${e.type.name}"${n} in ${e.file.path}. Run: pm create "${et(e.type.name)}" "<title>"`}function Gf(e){return e.removed?`Removed custom item type "${e.type?.name??"(unknown)"}" from ${e.file.path}.`:`No custom item type matched; nothing removed from ${e.file.path}.`}function zf(e){let t=e.replaced?"Updated":"Registered",n=e.status.roles&&e.status.roles.length>0?` (roles: ${e.status.roles.join(", ")})`:"",o=e.status.aliases&&e.status.aliases.length>0?` (aliases: ${e.status.aliases.join(", ")})`:"";return`${t} status "${e.status.id}"${n}${o} in ${e.file.path}.`}function Jf(e){return e.removed?`Removed custom status "${e.status?.id??"(unknown)"}" from ${e.file.path}.`:`No custom status matched; nothing removed from ${e.file.path}.`}function qf(e){let t=[`Schema types: ${e.counts.total} total (${e.counts.builtin} builtin, ${e.counts.custom} custom, ${e.counts.extension} extension)`];for(let[n,o]of[["builtin",e.builtin],["custom",e.custom],["extension",e.extension]])o.length!==0&&t.push(`${n}: ${o.map(r=>r.name).join(", ")}`);t.push(`statuses: ${e.statuses.counts.total} total (${e.statuses.counts.builtin} builtin, ${e.statuses.counts.custom} custom)`);for(let[n,o]of[["builtin statuses",e.statuses.builtin],["custom statuses",e.statuses.custom]])o.length!==0&&t.push(`${n}: ${o.map(r=>r.id).join(", ")}`);return t.push(`custom fields: ${e.fields.counts.total} total`),e.fields.custom.length>0&&t.push(`fields: ${e.fields.custom.map(n=>`${n.key} (${n.type}, ${n.cli_flag})`).join(", ")}`),t.push("Inspect one: pm schema show <Type>"),t.push("Inspect one status: pm schema show-status <status>"),t.push("Inspect one field: pm schema show-field <key>"),t.join(`
|
|
16
|
+
`)}import yc from"node:path";import{mkdir as _c}from"node:fs/promises";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e3f016bb-8add-5765-bb1a-a7b22423f8d1")}catch{}})();var ot=["agile","ops","research"],mc={agile:[{name:"Story",description:"User-facing outcome or capability slice expressed from a stakeholder perspective.",defaultStatus:"open",folder:"stories",aliases:["user-story"]},{name:"Spike",description:"Time-boxed investigation used to reduce uncertainty before implementation.",defaultStatus:"open",folder:"spikes",aliases:["research-spike"]}],ops:[{name:"Incident",description:"Operational disruption, degradation, or support escalation with recovery tracking.",defaultStatus:"open",folder:"incidents",aliases:["outage"]},{name:"Runbook",description:"Repeatable operational procedure, diagnostic path, or response playbook.",defaultStatus:"open",folder:"runbooks",aliases:["playbook"]}],research:[{name:"Experiment",description:"Validated-learning activity with hypothesis, method, and outcome tracking.",defaultStatus:"open",folder:"experiments",aliases:["study"]},{name:"Hypothesis",description:"Testable claim or assumption that should be supported, rejected, or refined.",defaultStatus:"open",folder:"hypotheses",aliases:["assumption"]}]};function At(e){if(e===void 0)return;let t=e.trim().toLowerCase().replaceAll("-","_");if(t.length===0)throw new Error("Type preset name must not be empty.");if(t==="agile"||t==="ops"||t==="research")return t;throw new Error(`Invalid type preset "${e}". Allowed: ${ot.join(", ")}.`)}function rt(e){return mc[e].map(t=>tt(t))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="3d53ef97-6dd5-5dea-a5c2-9bc9e62d881c")}catch{}})();var fc=/^([A-Za-z][A-Za-z0-9_-]*?)\s*[-:]\s+\S/;function hc(e){let t=fc.exec(e.trim());if(!t)return;let n=t[1];if(!(n.length<2)&&!/^[A-Za-z]\d+$/.test(n))return n.toLowerCase()}function gc(e){return e.split(/[-_]+/).filter(t=>t.length>0).map(t=>`${t.slice(0,1).toUpperCase()}${t.slice(1).toLowerCase()}`).join("")}function Er(e,t={}){let n=typeof t.minCount=="number"&&t.minCount>0?Math.trunc(t.minCount):10,o=typeof t.maxExamples=="number"&&t.maxExamples>0?Math.trunc(t.maxExamples):3,r=new Map;for(let a of e){let s=typeof a=="string"?a.trim():"";if(s.length===0)continue;let c=hc(s);if(c===void 0)continue;let d=r.get(c)??{count:0,examples:[]};d.count+=1,d.examples.length<o&&d.examples.push(s),r.set(c,d)}let i=[];for(let[a,s]of r.entries()){if(s.count<n)continue;let c=gc(a);i.push({name:c,prefix:a,count:s.count,examples:s.examples,shadows_builtin:xo(c)!==void 0})}return i.sort((a,s)=>s.count-a.count||a.name.localeCompare(s.name)),i}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="2ab8a5a9-dbea-526f-a541-b7ca2b106ac5")}catch{}})();var $f=["add-type","remove-type","add-status","remove-status","add-field","remove-field","list-fields","show-field","apply-preset","list","show","show-status","rename-type","rename-field","remap-status"],Tt="schema-types",$r="schema-statuses",Ar="schema-fields";function Te(e){return Me({pmRoot:e.pmRoot,filePath:e.filePath,raw:e.raw,op:e.op,author:e.author,lockTtlSeconds:e.settings.locks.ttl_seconds,lockWaitMs:e.settings.locks.wait_ms})}async function Af(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{r=tt({name:e,description:t.description,defaultStatus:t.defaultStatus,folder:t.folder,aliases:t.alias})}catch(m){throw new h(m instanceof Error?m.message:String(m),g.USAGE)}let i=await O(o),a=W(i.schema),s=ee(o,a.files.types,K.types),c=[],d=H(t.author,i.author_default),l=re(i),p=await Y(o,Tt,i.locks.ttl_seconds,d,!!t.force,l.force_required_for_stale_lock,i.locks.wait_ms),u;try{let m=await z(s),y;try{y=oe(m)}catch(w){throw new h(w instanceof Error?w.message:String(w),g.GENERIC_FAILURE)}try{So(r,y);let w=new Map,f=J(i,B());for(let[_,v]of Object.entries(f.type_to_folder)){let k=v.trim().toLowerCase();k.length>0&&!w.has(k)&&w.set(k,_)}Eo(r,y,w)}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}u=Ue(y,r),u.replaced&&u.previousName!==void 0&&u.previousName!==u.definition.name&&c.push(`type_recased:${u.previousName}->${u.definition.name}`),await Te({pmRoot:o,filePath:s,raw:de(u.file),op:"schema:add-type",author:d,settings:i}),await it(o,[u.definition],c,"schema:add-type-folder"),c.push(...await q({path:s,scope:"project",op:"schema:add-type"}))}finally{await p()}return await Tr(o,c),{action:"add-type",registered:!0,replaced:u.replaced,type:u.definition,file:{path:s,definitions:u.file.definitions.length},warnings:Ie(c),generated_at:A()}}async function _e(e){if(!await x(be(e)))throw new h(`Tracker is not initialized at ${e}. Run pm init first.`,g.NOT_FOUND)}async function Tr(e,t){try{let n=await rr(e);n.status==="refreshed"?t.push("merge_fence_refreshed"):n.status==="not_installed"&&t.push('merge_fence_not_installed:type folders lack git merge drivers; run "pm merge install"')}catch{t.push('merge_fence_refresh_failed:run "pm merge install" to reconcile')}}function Ie(e){return[...new Set(e)].sort((t,n)=>t.localeCompare(n))}async function wc(e,t,n,o){let r=J(t,B()),i=o.trim().toLowerCase();return(await Ce(e,t.item_format,r.type_to_folder,[],n)).filter(s=>typeof s.type=="string"&&s.type.toLowerCase()===i).length}async function vc(e,t,n,o){let r=J(t,B()),i=Qe(n),a=$(o);return(await Ce(e,t.item_format,r.type_to_folder,[],n)).filter(c=>{let d=typeof c.status=="string"?c.status:"";return(i.alias_to_id.get($(d))??$(d))===a}).length}async function bc(e,t,n,o,r){if(r.length===0||Pe.has(r))return;let i=await vc(t,n,o,r);i>0&&e.push(`items_using_status:${i}`);let a=Ir(o.workflow,r);a.length>0&&e.push(`status_referenced_by_workflow:${a.join(",")}`)}function Ir(e,t){return[["draft_status",e.draft_status],["open_status",e.open_status],["in_progress_status",e.in_progress_status],["blocked_status",e.blocked_status],["close_status",e.close_status],["canceled_status",e.canceled_status]].filter(([,o])=>o!==void 0&&$(o)===t).map(([o])=>o)}async function Tf(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r=await O(o),i=W(r.schema),a=ee(o,i.files.types,K.types),s=[],c=H(t.author,r.author_default),d=re(r),l=await Y(o,Tt,r.locks.ttl_seconds,c,!!t.force,d.force_required_for_stale_lock,r.locks.wait_ms),p;try{let u=await z(a),m;try{m=oe(u)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.GENERIC_FAILURE)}try{p=$o(m,e)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}if(p.removed){let y=(p.definition?.name??e??"").trim();if(y.length>0){let w=await wc(o,r,i,y);w>0&&s.push(`items_using_type:${w}`)}await Te({pmRoot:o,filePath:a,raw:de(p.file),op:"schema:remove-type",author:c,settings:r}),s.push(...await q({path:a,scope:"project",op:"schema:remove-type"}))}}finally{await l()}return p.removed&&await Tr(o,s),{action:"remove-type",removed:p.removed,...p.definition?{type:p.definition}:{},file:{path:a,definitions:p.file.definitions.length},warnings:Ie(s),generated_at:A()}}function _n(e,t){return ee(e,t.files.statuses,K.statuses)}function It(e,t){return ee(e,t.files.fields,K.fields)}function Or(e,t){return ee(e,t.files.types,K.types)}async function it(e,t,n,o){for(let r of t){let i=so(r.folder??ao(r.name)),a=yc.join(e,i);await x(a)||(await _c(a,{recursive:!0}),n.push(...await q({path:a,scope:"project",op:o})))}}function wn(e){return{key:e.key,type:e.type,commands:[...e.commands],cli_flag:`--${e.cli_flag}`,cli_aliases:e.cli_aliases.map(t=>`--${t}`),...e.description?{description:e.description}:{},required:e.required,required_on_create:e.required_on_create,allow_unset:e.allow_unset,required_types:[...e.required_types]}}function kc(e){if(e)return{id:e.id,...e.roles.length>0?{roles:[...e.roles]}:{},...e.aliases.length>0?{aliases:[...e.aliases]}:{},...e.description?{description:e.description}:{},...typeof e.order=="number"?{order:e.order}:{}}}function xc(e){let t=new Map;for(let n of e){let o=$(n.id);if(o.length!==0){t.set(o,o);for(let r of Array.isArray(n.aliases)?n.aliases:[]){let i=$(r);i.length>0&&!t.has(i)&&t.set(i,o)}}}return t}async function If(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{r=mr({id:e,roles:t.role,aliases:t.alias,description:t.description,order:t.order})}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}let i=await O(o),a=W(i.schema),s=_n(o,a),c=Qe(a);try{fn(r,c.alias_to_id)}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}let d=kc(c.by_id.get(r.id)),l=[],p=H(t.author,i.author_default),u=re(i),m=await Y(o,$r,i.locks.ttl_seconds,p,!!t.force,u.force_required_for_stale_lock,i.locks.wait_ms),y;try{let w=await z(s),f;try{f=Be(w)}catch(v){throw new h(v instanceof Error?v.message:String(v),g.GENERIC_FAILURE)}let _=xc(f.statuses);try{fn(r,_)}catch(v){throw new h(v instanceof Error?v.message:String(v),g.USAGE)}y=fr(f,r,d),await Te({pmRoot:o,filePath:s,raw:We(y.file),op:"schema:add-status",author:p,settings:i}),l.push(...await q({path:s,scope:"project",op:"schema:add-status"}))}finally{await m()}return{action:"add-status",registered:!0,replaced:y.replaced,status:y.definition,file:{path:s,statuses:y.file.statuses.length},warnings:Ie(l),generated_at:A()}}async function Of(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r=await O(o),i=W(r.schema),a=_n(o,i),s=[],c=H(t.author,r.author_default),d=re(r),l=await Y(o,$r,r.locks.ttl_seconds,c,!!t.force,d.force_required_for_stale_lock,r.locks.wait_ms),p;try{let u=await z(a),m;try{m=Be(u)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.GENERIC_FAILURE)}try{p=hr(m,e)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}if(p.removed){let y=$(p.definition?.id??e);await bc(s,o,r,i,y),await Te({pmRoot:o,filePath:a,raw:We(p.file),op:"schema:remove-status",author:c,settings:r}),s.push(...await q({path:a,scope:"project",op:"schema:remove-status"}))}}finally{await l()}return{action:"remove-status",removed:p.removed,...p.definition?{status:p.definition}:{},file:{path:a,statuses:p.file.statuses.length},warnings:Ie(s),generated_at:A()}}function Cr(e){return{name:e.name,folder:e.folder,aliases:Array.isArray(e.aliases)?[...e.aliases]:[],...e.default_status?{default_status:e.default_status}:{},...e.description?{description:e.description}:{}}}function Sc(e,t,n){return{...Cr(e),source:t,...n?{extension:n}:{},required_create_fields:[...e.required_create_fields],required_create_repeatables:[...e.required_create_repeatables],options:structuredClone(e.options),command_option_policies:structuredClone(e.command_option_policies)}}function Rr(e){return{id:e.id,source:Pe.has(e.id)?"builtin":"custom",roles:Array.isArray(e.roles)?[...e.roles]:[],aliases:Array.isArray(e.aliases)?[...e.aliases]:[],...e.description?{description:e.description}:{},...typeof e.order=="number"?{order:e.order}:{}}}function Pr(e,t,n){let o=e.toLowerCase();return n.has(o)?"extension":t.has(o)?"custom":"builtin"}function Ec(){let e=new Map,t=B();for(let n of t?.item_types??[]){let o=n.types;if(Array.isArray(o))for(let r of o){if(typeof r!="object"||r===null||Array.isArray(r))continue;let i=r.name;typeof i=="string"&&i.trim().length>0&&e.set(i.trim().toLowerCase(),{layer:n.layer,name:n.name})}}return e}function $c(e){let t=Qe(e),n=[],o=[];for(let r of t.definitions){let i=Rr(r);i.source==="builtin"?n.push(i):o.push(i)}return{builtin:n,custom:o}}async function at(e){let t=j(process.cwd(),e.path);await _e(t);let n=await O(t),o=W(n.schema),r=ee(t,o.files.types,K.types),i=_n(t,o),a=J(n,B()),s=Ec(),c=new Set((n.item_types?.definitions??[]).map(d=>d.name.trim().toLowerCase()).filter(d=>d.length>0&&!s.has(d)));return{pmRoot:t,typesPath:r,statusesPath:i,byType:a.by_type,customNames:c,extensionProvenance:s,schema:o}}async function Cf(e){let t=await at(e),n=[],o=[],r=[];for(let s of Object.values(t.byType).sort((c,d)=>c.name.localeCompare(d.name))){let c=Pr(s.name,t.customNames,new Set(t.extensionProvenance.keys())),d=Cr(s);c==="extension"?r.push(d):c==="custom"?o.push(d):n.push(d)}let i=$c(t.schema),a=bt(t.schema).definitions.map(wn);return{action:"list",builtin:n,custom:o,extension:r,counts:{builtin:n.length,custom:o.length,extension:r.length,total:n.length+o.length+r.length},statuses:{builtin:i.builtin,custom:i.custom,counts:{builtin:i.builtin.length,custom:i.custom.length,total:i.builtin.length+i.custom.length}},fields:{custom:a,counts:{total:a.length}},file:{path:t.typesPath},generated_at:A()}}async function Rf(e,t){let n=(e??"").trim();if(n.length===0)throw new h("Type name must not be empty.",g.USAGE);let o=await at(t),r=Object.values(o.byType).find(i=>i.name.toLowerCase()===n.toLowerCase()||i.aliases.some(a=>a.toLowerCase()===n.toLowerCase()));if(!r)throw new h(`Unknown item type "${n}". Run pm schema list to inspect registered types, or pm schema add-type "${et(n)}" to register it.`,g.NOT_FOUND,{code:"unknown_item_type"});return{action:"show",type:Sc(r,Pr(r.name,o.customNames,new Set(o.extensionProvenance.keys())),o.extensionProvenance.get(r.name.toLowerCase())),file:{path:o.typesPath},generated_at:A()}}async function Pf(e,t){let n=$(e);if(n.length===0)throw new h("Status id must not be empty.",g.USAGE);let o=await at(t),r=Qe(o.schema),i=r.alias_to_id.get(n)??n,a=r.by_id.get(i);if(!a)throw new h(`Unknown status "${e}". Run pm schema list to inspect registered statuses, or pm schema add-status "${et(e??"")}" to register it.`,g.NOT_FOUND,{code:"unknown_status"});return{action:"show-status",status:Rr(a),file:{path:o.statusesPath},generated_at:A()}}async function Nf(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{r=lr({key:e,type:t.type,commands:t.commands,description:t.description,cliFlag:t.cliFlag,aliases:t.alias,required:t.required,requiredOnCreate:t.requiredOnCreate,allowUnset:t.allowUnset,requiredTypes:t.requiredTypes})}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}let i=await O(o),a=W(i.schema),s=It(o,a),c=[],d=kt(r.key);d&&c.push(`custom_field_mcp_input_collision:${d.field}:${d.property}:${d.owner}:use=${d.nested_path}`);let l=H(t.author,i.author_default),p=re(i),u=await Y(o,Ar,i.locks.ttl_seconds,l,!!t.force,p.force_required_for_stale_lock,i.locks.wait_ms),m;try{let y=await z(s),w;try{w=Je(y)}catch(f){throw new h(f instanceof Error?f.message:String(f),g.GENERIC_FAILURE)}m=pr(w,r),await Te({pmRoot:o,filePath:s,raw:qe(m.file),op:"schema:add-field",author:l,settings:i}),c.push(...await q({path:s,scope:"project",op:"schema:add-field"}))}finally{await u()}return{action:"add-field",registered:!0,replaced:m.replaced,field:m.definition,file:{path:s,fields:m.file.fields.length},warnings:Ie(c),generated_at:A()}}async function Ac(e,t,n,o){let r=J(t,B());return(await Ce(e,t.item_format,r.type_to_folder,[],n)).filter(a=>{let s=a[o];return s==null?!1:Array.isArray(s)?s.length>0:typeof s=="string"?s.trim().length>0:!0}).length}async function Df(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r=await O(o),i=W(r.schema),a=It(o,i),s=[],c=H(t.author,r.author_default),d=re(r),l=await Y(o,Ar,r.locks.ttl_seconds,c,!!t.force,d.force_required_for_stale_lock,r.locks.wait_ms),p;try{let u=await z(a),m;try{m=Je(u)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.GENERIC_FAILURE)}try{p=ur(m,e)}catch(y){throw new h(y instanceof Error?y.message:String(y),g.USAGE)}if(p.removed){let y=$(p.definition?.key??e),w=$(p.definition?.metadata_key??p.definition?.front_matter_key??y);if(w.length>0){let f=await Ac(o,r,i,w);f>0&&s.push(`items_using_field:${f}`)}await Te({pmRoot:o,filePath:a,raw:qe(p.file),op:"schema:remove-field",author:c,settings:r}),s.push(...await q({path:a,scope:"project",op:"schema:remove-field"}))}}finally{await l()}return{action:"remove-field",removed:p.removed,...p.definition?{field:p.definition}:{},file:{path:a,fields:p.file.fields.length},warnings:Ie(s),generated_at:A()}}async function jf(e){let t=await at(e),n=bt(t.schema).definitions.map(wn);return{action:"list-fields",fields:n,counts:{total:n.length},file:{path:It(t.pmRoot,t.schema)},generated_at:A()}}async function Ff(e,t){let n=$(e);if(n.length===0)throw new h("Field key must not be empty.",g.USAGE);let o=await at(t),r=bt(o.schema).by_key.get(n);if(!r)throw new h(`Unknown custom field "${e}". Run pm schema list-fields to inspect registered fields, or pm schema add-field "${et(e??"")}" to register it.`,g.NOT_FOUND,{code:"unknown_field"});return{action:"show-field",field:wn(r),file:{path:It(o.pmRoot,o.schema)},generated_at:A()}}async function Lf(e,t,n){let o=j(process.cwd(),n.path);await _e(o);let r;try{let w=At(e);if(w===void 0)throw new Error(`Type preset name is required. Allowed: ${ot.join(", ")}.`);r=w}catch(w){throw new h(w instanceof Error?w.message:String(w),g.USAGE)}let i=await O(o),a=W(i.schema),s=Or(o,a),c=[],d=H(t.author,i.author_default),l=re(i),p=[],u=[],m,y=await Y(o,Tt,i.locks.ttl_seconds,d,!!t.force,l.force_required_for_stale_lock,i.locks.wait_ms);try{let w=await z(s),f;try{f=oe(w)}catch(v){throw new h(v instanceof Error?v.message:String(v),g.GENERIC_FAILURE)}let _=f;for(let v of rt(r)){let k=Ue(_,v);_=k.file,(k.replaced?u:p).push(k.definition.name)}m=_.definitions.length,await Te({pmRoot:o,filePath:s,raw:de(_),op:"schema:apply-preset",author:d,settings:i}),await it(o,rt(r),c,"schema:apply-preset-folder"),c.push(...await q({path:s,scope:"project",op:"schema:apply-preset"}))}finally{await y()}return{action:"apply-preset",preset:r,registered:p,replaced:u,file:{path:s,definitions:m},warnings:Ie(c),generated_at:A()}}function Tc(e){if(e===void 0)return 10;if(!Number.isInteger(e)||e<1)throw new h("--min-count must be a positive integer (>= 1).",g.USAGE);return e}async function Mf(e,t){let n=j(process.cwd(),t.path);await _e(n);let o=await O(n),r=W(o.schema),i=Or(n,r),a=Tc(e.minCount),s=J(o,B()),d=(await Ce(n,o.item_format,s.type_to_folder,[],r)).map(k=>typeof k.title=="string"?k.title:""),l=Er(d,{minCount:a}),p=[],u=[],m=[],y=[],w;if(!e.apply){let k;try{k=oe(await z(i))}catch(T){throw new h(T instanceof Error?T.message:String(T),g.GENERIC_FAILURE)}return w=k.definitions.length,{action:"infer-types",applied:!1,min_count:a,candidates:l,registered:u,replaced:m,skipped:y,file:{path:i,definitions:w},warnings:p,generated_at:A()}}let f=H(e.author,o.author_default),_=re(o),v=await Y(n,Tt,o.locks.ttl_seconds,f,!!e.force,_.force_required_for_stale_lock,o.locks.wait_ms);try{let k=await z(i),T;try{T=oe(k)}catch(C){throw new h(C instanceof Error?C.message:String(C),g.GENERIC_FAILURE)}let R=T;for(let C of l){if(C.shadows_builtin){y.push({name:C.name,reason:"shadows_builtin"});continue}let se;try{se=tt({name:C.name})}catch{y.push({name:C.name,reason:"invalid_type_token"});continue}let fe=Ue(R,se);R=fe.file,(fe.replaced?m:u).push(fe.definition.name)}w=R.definitions.length,await Te({pmRoot:n,filePath:i,raw:de(R),op:"schema:infer-types",author:f,settings:o}),await it(n,R.definitions.filter(C=>u.includes(C.name)||m.includes(C.name)),p,"schema:infer-types-folder"),p.push(...await q({path:i,scope:"project",op:"schema:infer-types"}))}finally{await v()}return{action:"infer-types",applied:!0,min_count:a,candidates:l,registered:u,replaced:m,skipped:y,file:{path:i,definitions:w},warnings:Ie(p),generated_at:A()}}function Uf(e){let t=e.replaced?"Updated":"Registered",n=e.type.aliases&&e.type.aliases.length>0?` (aliases: ${e.type.aliases.join(", ")})`:"";return`${t} custom item type "${e.type.name}"${n} in ${e.file.path}. Run: pm create "${et(e.type.name)}" "<title>"`}function Gf(e){return e.removed?`Removed custom item type "${e.type?.name??"(unknown)"}" from ${e.file.path}.`:`No custom item type matched; nothing removed from ${e.file.path}.`}function zf(e){let t=e.replaced?"Updated":"Registered",n=e.status.roles&&e.status.roles.length>0?` (roles: ${e.status.roles.join(", ")})`:"",o=e.status.aliases&&e.status.aliases.length>0?` (aliases: ${e.status.aliases.join(", ")})`:"";return`${t} status "${e.status.id}"${n}${o} in ${e.file.path}.`}function Jf(e){return e.removed?`Removed custom status "${e.status?.id??"(unknown)"}" from ${e.file.path}.`:`No custom status matched; nothing removed from ${e.file.path}.`}function qf(e){let t=[`Schema types: ${e.counts.total} total (${e.counts.builtin} builtin, ${e.counts.custom} custom, ${e.counts.extension} extension)`];for(let[n,o]of[["builtin",e.builtin],["custom",e.custom],["extension",e.extension]])o.length!==0&&t.push(`${n}: ${o.map(r=>r.name).join(", ")}`);t.push(`statuses: ${e.statuses.counts.total} total (${e.statuses.counts.builtin} builtin, ${e.statuses.counts.custom} custom)`);for(let[n,o]of[["builtin statuses",e.statuses.builtin],["custom statuses",e.statuses.custom]])o.length!==0&&t.push(`${n}: ${o.map(r=>r.id).join(", ")}`);return t.push(`custom fields: ${e.fields.counts.total} total`),e.fields.custom.length>0&&t.push(`fields: ${e.fields.custom.map(n=>`${n.key} (${n.type}, ${n.cli_flag})`).join(", ")}`),t.push("Inspect one: pm schema show <Type>"),t.push("Inspect one status: pm schema show-status <status>"),t.push("Inspect one field: pm schema show-field <key>"),t.join(`
|
|
17
17
|
`)}function Bf(e){let t=[`type: ${e.type.name}`,`source: ${e.type.source}`,`folder: ${e.type.folder}`];return e.type.default_status&&t.push(`default_status: ${e.type.default_status}`),e.type.aliases.length>0&&t.push(`aliases: ${e.type.aliases.join(", ")}`),e.type.description&&t.push(`description: ${e.type.description}`),e.type.options.length>0&&t.push(`options: ${e.type.options.map(n=>n.key).join(", ")}`),t.join(`
|
|
18
18
|
`)}function Wf(e){let t=[`status: ${e.status.id}`,`source: ${e.status.source}`];return e.status.roles.length>0&&t.push(`roles: ${e.status.roles.join(", ")}`),e.status.aliases.length>0&&t.push(`aliases: ${e.status.aliases.join(", ")}`),e.status.description&&t.push(`description: ${e.status.description}`),typeof e.status.order=="number"&&t.push(`order: ${e.status.order}`),t.join(`
|
|
19
19
|
`)}function Ic(e){let t=[];e.required&&t.push("required"),e.required_on_create&&t.push("required_on_create"),e.allow_unset||t.push("no_unset");let n=t.length>0?` [${t.join(", ")}]`:"";return`${e.key} (${e.type}) ${e.cli_flag} commands=${e.commands.join("/")}${n}`}function Hf(e){return`${e.replaced?"Updated":"Registered"} custom field "${e.field.key}" in ${e.file.path}. Use it: pm create "<title>" --${(e.field.cli_flag??e.field.key).replaceAll("_","-")} <value>`}function Kf(e){return e.removed?`Removed custom field "${e.field?.key??"(unknown)"}" from ${e.file.path}.`:`No custom field matched; nothing removed from ${e.file.path}.`}function Vf(e){let t=[`Custom fields: ${e.counts.total} total`];for(let n of e.fields)t.push(` ${Ic(n)}`);return t.push("Inspect one: pm schema show-field <key>"),t.join(`
|
|
@@ -74,4 +74,4 @@ Agent guidance check
|
|
|
74
74
|
`),V.write(`Telemetry helps improve reliability and can be disabled anytime via pm config.
|
|
75
75
|
`);let c=t?"Y/n":"y/N",d=await n.question(`Enable telemetry for this project? [${c}] `),l=Ua(d,t);return V.write(`
|
|
76
76
|
`),{prefix:r,preset:s,telemetry_enabled:l}}finally{n.close()}}function xu(e){return{presetFromOption:Vn(e.preset),useDefaults:e.defaults===!0,authorFromOption:ja(e.author),installBundledPackages:e.withPackages===!0,agentGuidanceMode:Ma(e.agentGuidance),typePreset:Da(e.typePreset)}}function Su(e){let t=[];return e.prefixArg!==void 0&&e.settings.id_prefix!==e.normalizedPrefix&&t.push("id_prefix"),e.presetFromOption!==void 0&&e.settings.governance.preset!==e.presetFromOption&&t.push("governance_preset"),e.authorFromOption!==void 0&&e.settings.author_default!==e.authorFromOption&&t.push("author_default"),t}function Eu(e,t,n,o){if(t.length===0||n)return;let r=o.discovery==="ancestor";throw new h(`${r?`No tracker exists in ${o.requested_cwd}; pm init found an ancestor tracker at ${o.tracker_root}. `:""}Refusing to update existing tracker settings at ${e} without --force.`,g.USAGE,{code:"init_existing_settings_requires_force",type:"urn:pm-cli:error:init_existing_settings_requires_force",required:`--force for ${t.join(", ")}`,why:r?"Ancestor discovery is useful for normal commands, but init must make the selected existing workspace explicit before changing its identity or policy settings.":"pm init is safe to rerun, but changing id prefix, governance preset, or default author on an existing tracker can corrupt long-lived project context when an agent meant to initialize a sandbox path.",resolved_path:o.tracker_root,requested_path:o.requested_cwd,suggested_path:o.suggested_current_tracker_root,examples:["pm init --yes","pm init ./sandbox-pm --yes",...r?['pm init <name> --yes --pm-path "$PWD/.agents/pm"']:[],"pm init acme --yes --force"],nextSteps:[...r?['To create a new tracker in the current directory, rerun with --pm-path "$PWD/.agents/pm".']:[],"If you meant to initialize a sandbox tracker, pass a path-like positional such as ./sandbox-pm or /tmp/pm-test.","If you intentionally want to rewrite this existing tracker's init-managed settings, rerun with --force."]})}function $u(e){let t=!1;return e.prefixArg!==void 0&&e.settings.id_prefix!==e.normalizedPrefix&&(e.settings.id_prefix=e.normalizedPrefix,e.warnings.push(`updated:id_prefix:${e.normalizedPrefix}`),t=!0),e.presetFromOption!==void 0&&e.settings.governance.preset!==e.presetFromOption&&(Yn(e.settings,e.presetFromOption),e.warnings.push(`updated:governance_preset:${e.presetFromOption}`),t=!0),e.authorFromOption!==void 0&&e.settings.author_default!==e.authorFromOption&&(e.settings.author_default=e.authorFromOption,e.warnings.push(`updated:author_default:${e.authorFromOption}`),t=!0),t}async function Au(e){let t=await O(e.pmRoot);e.warnings.push(`already_exists:${e.settingsPath}`);let n=Su({settings:t,normalizedPrefix:e.normalizedPrefix,prefixArg:e.prefixArg,presetFromOption:e.normalizedOptions.presetFromOption,authorFromOption:e.normalizedOptions.authorFromOption});return Eu(e.settingsPath,n,e.options.force===!0,e.target),$u({settings:t,normalizedPrefix:e.normalizedPrefix,prefixArg:e.prefixArg,presetFromOption:e.normalizedOptions.presetFromOption,authorFromOption:e.normalizedOptions.authorFromOption,warnings:e.warnings})&&await Ee(e.pmRoot,t),{settings:t,normalizedPrefix:e.normalizedPrefix,chosenPreset:e.normalizedOptions.presetFromOption,wizardUsed:!1}}async function Tu(e){let t=e.normalizedPrefix,n=e.normalizedOptions.presetFromOption,o,r=!1;if(e.normalizedOptions.presetFromOption===void 0&&!e.normalizedOptions.useDefaults&&process.stdin.isTTY===!0&&process.stdout.isTTY===!0){let c=await Wa(t,Ht.telemetry.enabled);t=c.prefix,n=c.preset,o=c.telemetry_enabled,r=!0}let i=n??"minimal",a=vu();a.id_prefix=t,Yn(a,i);let s=bo()?.trim()||void 0;return a.author_default=e.normalizedOptions.authorFromOption??s??"",o!==void 0&&(a.telemetry.enabled=o,a.telemetry.first_run_prompt_completed=!0),await Ee(e.pmRoot,a),{settings:a,normalizedPrefix:t,chosenPreset:n,wizardUsed:r}}async function Ca(e){return e.settingsExists?await Au(e):await Tu({pmRoot:e.pmRoot,normalizedPrefix:e.normalizedPrefix,normalizedOptions:e.normalizedOptions})}async function Iu(e){let t=await Oa({pm_root:e.pmRoot,cwd:e.cwd,mode:e.agentGuidanceMode,interactive:process.stdin.isTTY===!0&&process.stdout.isTTY===!0,settings:e.settings});return e.warnings.push(...t.warnings),t.settings_changed&&await Ee(e.pmRoot,e.settings),{...t.summary,next_steps:t.next_steps}}async function Ou(e,t){let n=[],o=[],r=await vo(e,t.schema);for(let i of r.created_paths)n.push(i),o.push(...await q({path:i,scope:"project",op:"init:runtime_schema_file"}));return{createdDirs:n,warnings:o}}async function Cu(e){if(e.typePreset===void 0)return;let t=await za(e.pmRoot,e.settings,e.typePreset);return e.warnings.push(`registered_type_preset:${e.typePreset}`),e.warnings.push(...await q({path:t.file,scope:"project",op:"init:type_preset"})),t}async function Ru(e){let n=J(e.settings,B()).folders.filter(r=>!Wt.includes(r)),o=await Ba(e.pmRoot,n);e.createdDirs.push(...o.createdDirs),e.warnings.push(...o.warnings)}function Pu(e){let t=F.resolve(e.tracker_root),n=F.dirname(t);return F.basename(t)==="pm"&&F.basename(n)===".agents"?F.dirname(n):e.workspace_root}async function Nu(e,t,n,o){if(!e)return;let r=await Jn("all",{install:!0,project:!0},{...t,path:n});o.push(...r.warnings);let i=Ga(r),a=i.packages.filter(s=>!s.ok).map(s=>s.alias);if(!i.installed_all||a.length>0)throw new h(`pm init --with-packages did not install all bundled packages successfully${a.length>0?`: ${a.join(", ")}`:"."}`,g.GENERIC_FAILURE);return i}function Ha(e){let t=o=>xt([...e.target.mode==="workspace-discovery"?[]:["--pm-path",e.target.tracker_root],...o]),n=[`Create your first item: ${t(["create","--type","Task","--title","<title>"])}`,`List active items: ${t(["list"])}`,`Get agent-friendly project context: ${t(["context"])}`];e.installBundledPackages?n.push(`Explore newly-available commands: ${t(["cal"])}, ${t(["templates"])}, ${t(["guide"])}`):(n.push(`Add optional packages for richer workflows: ${t(["install","calendar","--project"])}, ${t(["install","templates","--project"])}, ${t(["install","guide-shell","--project"])}`),n.push(`Or install everything bundled: ${t(["init","--with-packages"])} (idempotent on re-run)`)),e.registeredTypePreset&&n.push(`Inspect registered preset types: ${t(["schema","list"])}, ${t(["schema","show",e.registeredTypePreset.registered[0]??e.registeredTypePreset.updated[0]])}`),n.push("Supported agent harnesses are attributed automatically; use --author or PM_AUTHOR only when an explicit identity override is required.");for(let o of e.agentGuidanceNextSteps){let r=e.target.mode==="workspace-discovery"?o:o.replace(/\bpm (?=[a-z])/g,()=>`${t([])} `);n.includes(r)||n.push(r)}return n}async function Ka(e,t,n,o=mn){if(t===null){n.push("merge_fence_skipped:not_git_repository:run pm merge install after moving the tracker into a Git repository");return}try{let r=await o({pmRoot:e,workspaceRoot:t});r.gitattributes.changed&&n.push(`updated:merge_fence:${r.gitattributes.path}`)}catch(r){if(!(r instanceof h))throw r;n.push(`merge_fence_skipped:install_failed:${r.context.code??"pm_error"}:${r.message}:run pm merge install after resolving the Git repository error`)}}async function y_(e,t,n={}){let o=process.cwd(),r=Fa(o,t,e,n.workspace),i=r.pmRoot;e=La(r.prefixArg,n.idPrefix);let a=xu(n);await qa(i,r.target.mode==="tracker-path",n.force===!0);let s=[],c=[],d=F.join(i,"settings.json"),l=await x(d),p;l&&(p=await Ca({pmRoot:i,settingsPath:d,settingsExists:l,normalizedPrefix:Se(e),prefixArg:e,options:n,normalizedOptions:a,warnings:c,target:r.target}));let u=await Ba(i,Wt);s.push(...u.createdDirs),c.push(...u.warnings),p??=await Ca({pmRoot:i,settingsPath:d,settingsExists:l,normalizedPrefix:Se(e),prefixArg:e,options:n,normalizedOptions:a,warnings:c,target:r.target});let{settings:m}=p,y=Pu(r.target),w=await ln(y??F.dirname(i)),f=y??w,_=await Iu({pmRoot:i,cwd:f??o,agentGuidanceMode:a.agentGuidanceMode,settings:m,warnings:c}),v=await Ou(i,m);s.push(...v.createdDirs),c.push(...v.warnings);let k=await Cu({pmRoot:i,settings:m,typePreset:a.typePreset,warnings:c});if(k&&(m=await O(i)),await Ru({pmRoot:i,settings:m,createdDirs:s,warnings:c}),f&&a.agentGuidanceMode!=="status"){let C=await Wo(f,{pmRoot:i});C.changed&&c.push(`updated:gitignore:${C.path}`)}!l&&n.mergeFence!==!1&&a.agentGuidanceMode!=="status"&&await Ka(i,w,c);let T=await Nu(a.installBundledPackages,t,i,c),R=Ha({installBundledPackages:a.installBundledPackages,registeredTypePreset:k,agentGuidanceNextSteps:_.next_steps,target:r.target});return{ok:!0,path:i,target:r.target,settings:m,created_dirs:s,warnings:c,governance_preset:m.governance.preset,wizard_used:p.wizardUsed,...k?{registered_type_preset:k}:{},...T?{installed_packages:T}:{},next_steps:R,agent_guidance:_}}export{en as a,Go as b,Jo as c,on as d,gs as e,_s as f,Wo as g,Ge as h,vs as i,an as j,xt as k,Yu as l,ks as m,xs as n,Ko as o,St as p,Zo as q,ze as r,cn as s,Ts as t,ln as u,un as v,or as w,gm as x,ym as y,rr as z,_m as A,mn as B,mr as C,Be as D,We as E,fr as F,lr as G,Je as H,qe as I,pr as J,mc as K,vr as L,Sr as M,pc as N,uc as O,$f as P,Af as Q,Tf as R,it as S,If as T,Of as U,Cf as V,Rf as W,Pf as X,Nf as Y,Df as Z,jf as _,Ff as $,Lf as aa,Mf as ba,Uf as ca,Gf as da,zf as ea,Jf as fa,qf as ga,Bf as ha,Wf as ia,Hf as ja,Kf as ka,Vf as la,Yf as ma,Xf as na,Zf as oa,Qf as pa,b as qa,we as ra,Ot as sa,Oc as ta,st as ua,Ct as va,Wr as wa,ni as xa,Nn as ya,gi as za,fg as Aa,xl as Ba,Ci as Ca,Ri as Da,Dn as Ea,hl as Fa,gl as Ga,yl as Ha,wi as Ia,vi as Ja,Jn as Ka,ya as La,By as Ma,Oa as Na,h_ as Oa,g_ as Pa,y_ as Qa};
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
77
|
+
//# sourceMappingURL=chunk-JOKATURE.js.map
|