@unbrained/pm-cli 2026.8.5 → 2026.8.7
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 +44 -0
- package/dist/cli/main.js +14 -37
- package/dist/cli/register-operations.js +11 -2
- package/dist/cli/register-setup.d.ts +1 -1
- package/dist/cli/register-setup.js +46 -20
- package/dist/cli/stats-analytics-json.d.ts +9 -0
- package/dist/cli/stats-analytics-json.js +69 -0
- package/dist/cli-bundle/bundle-manifest.json +403 -403
- package/dist/cli-bundle/chunks/append-7BXBFDGD.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-PMXJEU3F.js → chunk-2AXF3VSK.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-MHK6LIWE.js → chunk-2XS43CCV.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-3A6KWB72.js +8 -0
- package/dist/cli-bundle/chunks/chunk-3ISTDB42.js +8 -0
- package/dist/cli-bundle/chunks/{chunk-45G53IU4.js → chunk-4MTI7XOV.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-7C4PTJG6.js → chunk-6BX5UDCN.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-4YUBDMQM.js → chunk-6QPO7KLR.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HWRRMBJO.js → chunk-7MXHZHSQ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-3FTILRJ2.js → chunk-7ZPMJW4U.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-2WFXWAYX.js → chunk-AGYNSNCI.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-B4H7FEFH.js +5 -0
- package/dist/cli-bundle/chunks/{chunk-43HQQI6S.js → chunk-B4KLBBMN.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-VCKLFEUN.js → chunk-CALJHNBL.js} +12 -12
- package/dist/cli-bundle/chunks/{chunk-CSI3WS5I.js → chunk-CFIGP5LY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-V3EUXXOF.js → chunk-CS6MRHG7.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-YSO3YFZ4.js → chunk-CUGNQQKH.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-D4FPS43D.js +164 -0
- package/dist/cli-bundle/chunks/{chunk-BXQLRKWF.js → chunk-H5Y5YE6A.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-54FNT7U2.js → chunk-H5Y6UV6E.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UP7DTVMD.js → chunk-H7KGWPDF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-E2RKBKWB.js → chunk-HFSD77TQ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-V3774P7D.js → chunk-HX2GTA6L.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UZBWIUYD.js → chunk-J2IEKAVR.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HNFD72UK.js → chunk-K44PYFXH.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-5ZBOIPGP.js → chunk-K4KGEEBT.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-KFLK5TRH.js +21 -0
- package/dist/cli-bundle/chunks/{chunk-OMXVBQ2N.js → chunk-KL6IEBV2.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-7A5OT5J2.js → chunk-KWQZDZSS.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-M72BKL5Q.js → chunk-KZ4X3DGU.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-LD77HJMQ.js +13 -0
- package/dist/cli-bundle/chunks/{chunk-VN5VITU3.js → chunk-ME2JJ4LA.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-NFLJ3FHD.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-A62CYISG.js → chunk-NG6OXIBR.js} +8 -8
- package/dist/cli-bundle/chunks/{chunk-42E7YPLG.js → chunk-NYIGHWQY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-RKAVWO3O.js → chunk-NZ75GNSA.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-DXDREUXT.js → chunk-PCJWJNC2.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-ZYHOB3SN.js → chunk-PD3225AM.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-OTHLDSFP.js → chunk-PDEGKG7P.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-PIE5HBNA.js +2 -0
- package/dist/cli-bundle/chunks/chunk-PW2H7YJR.js +56 -0
- package/dist/cli-bundle/chunks/{chunk-L3AZOELJ.js → chunk-TPKN3S7S.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-LKDGK44W.js → chunk-TPXAXTCO.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-UFWUJO4V.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-R546TPDE.js → chunk-UQLZQVFW.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-BPELKUQD.js → chunk-VT3Z5G7D.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-WOD3WWUN.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-4VN6GS4U.js → chunk-WSJEIGJF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UN66FZRO.js → chunk-WYNUU7ZW.js} +49 -46
- package/dist/cli-bundle/chunks/{chunk-NY4T3JWN.js → chunk-YGPNCCXZ.js} +2 -2
- package/dist/cli-bundle/chunks/close-CMY3BAUG.js +2 -0
- package/dist/cli-bundle/chunks/close-many-SA4XZCTK.js +2 -0
- package/dist/cli-bundle/chunks/comments-EZ556ZD3.js +2 -0
- package/dist/cli-bundle/chunks/copy-ZSGPA52X.js +2 -0
- package/dist/cli-bundle/chunks/{create-XLKTXTUF.js → create-I5DVV4YG.js} +2 -2
- package/dist/cli-bundle/chunks/delete-RL3JACSW.js +2 -0
- package/dist/cli-bundle/chunks/{deps-ITTY3GIC.js → deps-S7UBCECS.js} +2 -2
- package/dist/cli-bundle/chunks/{docs-W4OSRTYR.js → docs-ZZNVBBYO.js} +2 -2
- package/dist/cli-bundle/chunks/{files-EOK4AZI4.js → files-27C337VT.js} +2 -2
- package/dist/cli-bundle/chunks/focus-5Z2SG7LU.js +2 -0
- package/dist/cli-bundle/chunks/{history-compact-7UGTMLL3.js → history-compact-HJQK67CZ.js} +2 -2
- package/dist/cli-bundle/chunks/{history-redact-4DZRMD6Z.js → history-redact-PWC6PDWA.js} +2 -2
- package/dist/cli-bundle/chunks/{history-repair-UPOSZW5R.js → history-repair-N3CY4WBF.js} +2 -2
- package/dist/cli-bundle/chunks/{learnings-GMRNCBS3.js → learnings-4FH23XDT.js} +2 -2
- package/dist/cli-bundle/chunks/{profile-2MUUMHRE.js → profile-5Y5XXH5N.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-LR3SQ5ZF.js → register-list-query-FJZCJ67O.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-SUOHFVWM.js → register-mutation-YGYPW3BL.js} +3 -3
- package/dist/cli-bundle/chunks/register-operations-WMDSUMQF.js +2 -0
- package/dist/cli-bundle/chunks/register-setup-DL7FFABC.js +2 -0
- package/dist/cli-bundle/chunks/restore-6KYBV5BY.js +2 -0
- package/dist/cli-bundle/chunks/{schema-FJ4EA3XF.js → schema-EQGKBYXJ.js} +2 -2
- package/dist/cli-bundle/chunks/update-QVTYOD6I.js +2 -0
- package/dist/cli-bundle/chunks/update-many-DJSBU525.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-MJ7HWSFK.js → chunk-2ECLECMK.js} +3 -3
- package/dist/cli-bundle/focused-chunks/{chunk-A7BJ5SS6.js → chunk-3K4XV2BF.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-PIMMYG7Q.js → chunk-4EX25PXM.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-4VJQTS3P.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-73JUDYXT.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-WVIVUWVL.js → chunk-CIXVQPB7.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-DLTS3IHM.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-FGKY4MBE.js → chunk-DQ6FKGL3.js} +10 -10
- package/dist/cli-bundle/focused-chunks/{chunk-QVHKCI4T.js → chunk-HNL6IFGS.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-JLG2C4EQ.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-G6ETT4QK.js → chunk-MHMTKV5V.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-7J5TUBUJ.js → chunk-MOTJFQ3F.js} +22 -22
- package/dist/cli-bundle/focused-chunks/{chunk-UIL2M2NA.js → chunk-NBJKQP4S.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-RUR5I3TK.js → chunk-QHRTT7WT.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-B7LJWAZE.js → chunk-R2LEMEV5.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-SV3O7TSH.js → chunk-RPNYG5MO.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-RW5IYD4J.js +4 -0
- package/dist/cli-bundle/focused-chunks/chunk-TIKDBG4D.js +29 -0
- package/dist/cli-bundle/focused-chunks/{chunk-IPWSFADF.js → chunk-VZFU2R4M.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-WEM2E2PE.js → chunk-YZEZAPJK.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-ZJIMJHDB.js +2 -0
- package/dist/cli-bundle/main.js +13 -13
- 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 +29 -28
- 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 +1 -1
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +1 -1
- package/dist/core/extensions/activation-summary.d.ts +4 -0
- package/dist/core/extensions/activation-summary.js +5 -2
- package/dist/core/extensions/contribution-inventory.d.ts +1 -0
- package/dist/core/extensions/contribution-inventory.js +35 -2
- package/dist/core/extensions/extension-hook-runtime.js +5 -3
- package/dist/core/extensions/extension-types.d.ts +18 -1
- package/dist/core/extensions/extension-types.js +2 -2
- package/dist/core/extensions/loader.js +5 -13
- package/dist/core/extensions/preflight-ownership.d.ts +5 -0
- package/dist/core/extensions/preflight-ownership.js +42 -0
- package/dist/core/extensions/reserved-host-flags.js +3 -2
- package/dist/core/history/workspace-history.d.ts +22 -2
- package/dist/core/history/workspace-history.js +60 -36
- package/dist/core/output/output.d.ts +2 -0
- package/dist/core/output/output.js +3 -2
- package/dist/core/shared/command-types.d.ts +2 -0
- package/dist/core/shared/command-types.js +2 -2
- package/dist/mcp/tool-definitions.js +6 -2
- package/dist/sdk/author-attribution.js +23 -7
- package/dist/sdk/cli-bootstrap.d.ts +2 -0
- package/dist/sdk/cli-bootstrap.js +7 -2
- package/dist/sdk/cli-contracts/completeness.js +51 -4
- package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
- package/dist/sdk/cli-contracts/flag-contracts.js +9 -2
- package/dist/sdk/cli-contracts/registration-helpers.js +3 -2
- package/dist/sdk/cli-contracts/runtime-contracts.js +16 -9
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +116 -10
- package/dist/sdk/cli-contracts/tool-schema.js +18 -2
- package/dist/sdk/cli-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts.js +3 -3
- package/dist/sdk/cli-program.js +3 -2
- package/dist/sdk/completion.js +5 -2
- package/dist/sdk/compose.d.ts +2 -2
- package/dist/sdk/compose.js +7 -2
- package/dist/sdk/contracts.d.ts +1 -0
- package/dist/sdk/contracts.js +2 -2
- package/dist/sdk/core.d.ts +3 -1
- package/dist/sdk/core.js +4 -3
- package/dist/sdk/define.d.ts +3 -1
- package/dist/sdk/define.js +3 -8
- package/dist/sdk/extension/install-sources.d.ts +43 -5
- package/dist/sdk/extension/install-sources.js +36 -2
- package/dist/sdk/extension/migrations.d.ts +114 -0
- package/dist/sdk/extension/migrations.js +175 -0
- package/dist/sdk/extension/scaffold.js +14 -9
- package/dist/sdk/extension/source-resolution.d.ts +50 -0
- package/dist/sdk/extension/source-resolution.js +66 -0
- package/dist/sdk/extension.d.ts +5 -1
- package/dist/sdk/extension.js +31 -35
- package/dist/sdk/generated-error-code-catalog.js +112 -2
- package/dist/sdk/governance/health.js +11 -2
- package/dist/sdk/history-analytics.d.ts +141 -0
- package/dist/sdk/history-analytics.js +283 -0
- package/dist/sdk/improvement-ledger-validation.d.ts +3 -0
- package/dist/sdk/improvement-ledger-validation.js +63 -0
- package/dist/sdk/improvement-ledger.d.ts +139 -0
- package/dist/sdk/improvement-ledger.js +261 -0
- package/dist/sdk/index.d.ts +11 -3
- package/dist/sdk/index.js +12 -4
- package/dist/sdk/lifecycle/plan.js +6 -3
- package/dist/sdk/merge/install.js +10 -2
- package/dist/sdk/package-migrations.d.ts +10 -0
- package/dist/sdk/package-migrations.js +21 -0
- package/dist/sdk/read-output-budget.js +24 -22
- package/dist/sdk/read-output-contracts.d.ts +10 -2
- package/dist/sdk/read-output-contracts.js +124 -65
- package/dist/sdk/read-output-rows.d.ts +29 -0
- package/dist/sdk/read-output-rows.js +100 -0
- package/dist/sdk/read-output-session.d.ts +69 -0
- package/dist/sdk/read-output-session.js +200 -0
- package/dist/sdk/runtime-input.d.ts +2 -0
- package/dist/sdk/runtime-input.js +14 -2
- package/dist/sdk/runtime-primitives.d.ts +1 -1
- package/dist/sdk/runtime-primitives.js +3 -3
- package/dist/sdk/runtime-stats-options.d.ts +9 -0
- package/dist/sdk/runtime-stats-options.js +38 -0
- package/dist/sdk/runtime.d.ts +3 -0
- package/dist/sdk/runtime.js +10 -27
- package/dist/sdk/stats.d.ts +40 -0
- package/dist/sdk/stats.js +112 -29
- package/docs/COMMANDS.md +9 -0
- package/docs/EXTENSIONS.md +2 -2
- package/docs/EXTENSION_LIFECYCLE.md +46 -0
- package/docs/IMPROVEMENT_ANALYTICS.md +103 -0
- package/docs/OUTPUT_PROJECTION_CONTRACTS.md +5 -5
- package/docs/README.md +2 -0
- package/docs/READ_OUTPUT_CONTRACTS.md +60 -1
- package/docs/RELEASING.md +33 -20
- package/docs/SDK.md +31 -3
- package/marketplace.json +2 -2
- package/package.json +5 -5
- 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-codex/.codex-plugin/plugin.json +1 -1
- package/sdk/public-surface.json +566 -815
- package/dist/cli-bundle/chunks/append-VXXGOXSG.js +0 -2
- package/dist/cli-bundle/chunks/chunk-6MSQJOTG.js +0 -13
- package/dist/cli-bundle/chunks/chunk-EGJ4JTUG.js +0 -55
- package/dist/cli-bundle/chunks/chunk-FPBQHMFT.js +0 -8
- package/dist/cli-bundle/chunks/chunk-GE4KCSZP.js +0 -164
- package/dist/cli-bundle/chunks/chunk-LN2WFEU4.js +0 -2
- package/dist/cli-bundle/chunks/chunk-OPVH7SKD.js +0 -8
- package/dist/cli-bundle/chunks/chunk-Q35VBGOQ.js +0 -5
- package/dist/cli-bundle/chunks/chunk-SSF4PIUR.js +0 -2
- package/dist/cli-bundle/chunks/chunk-WRL4KNDL.js +0 -20
- package/dist/cli-bundle/chunks/chunk-XCEZYMNI.js +0 -2
- package/dist/cli-bundle/chunks/chunk-YEWNL576.js +0 -2
- package/dist/cli-bundle/chunks/close-VZ3OQPN5.js +0 -2
- package/dist/cli-bundle/chunks/close-many-SB4TI27P.js +0 -2
- package/dist/cli-bundle/chunks/comments-BIF3Q4KY.js +0 -2
- package/dist/cli-bundle/chunks/copy-6AI5Z57X.js +0 -2
- package/dist/cli-bundle/chunks/delete-ZY2VHQTP.js +0 -2
- package/dist/cli-bundle/chunks/focus-DLBNWL7L.js +0 -2
- package/dist/cli-bundle/chunks/register-operations-ARRRKOVN.js +0 -2
- package/dist/cli-bundle/chunks/register-setup-O6AYP6NP.js +0 -2
- package/dist/cli-bundle/chunks/restore-ZVCVHTB5.js +0 -2
- package/dist/cli-bundle/chunks/update-YHV52CSS.js +0 -2
- package/dist/cli-bundle/chunks/update-many-M6YHVNXM.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-BIMTMOS7.js +0 -4
- package/dist/cli-bundle/focused-chunks/chunk-GJ2TG2CW.js +0 -28
- package/dist/cli-bundle/focused-chunks/chunk-N5XU5UVK.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-PG2RIZBX.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-VLYOEYML.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-W7BJEWHX.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-Y4LDYLLT.js +0 -2
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as o}from"./chunk-45G53IU4.js";import"./chunk-A62CYISG.js";import"./chunk-BPELKUQD.js";import"./chunk-RSIC5OPE.js";import"./chunk-5ZBOIPGP.js";import"./chunk-A6KGKEWT.js";import"./chunk-42E7YPLG.js";import"./chunk-M72BKL5Q.js";import"./chunk-GE4KCSZP.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},d=new e.Error().stack;d&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[d]="d79c73c8-07a5-5a39-aca5-4058264684d6")}catch{}})();export{o as runAppend};
|
|
2
|
-
//# sourceMappingURL=append-VXXGOXSG.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import{a as L,b as Nt,c as At,u as V}from"./chunk-RKAVWO3O.js";import{a as Ot,b as Fe,c as Mt,d as Ft}from"./chunk-BXQLRKWF.js";import{va as Dt}from"./chunk-YEWNL576.js";import{v as It,w as $t}from"./chunk-A62CYISG.js";import{a as Tt}from"./chunk-5ZBOIPGP.js";import{A as f,Ad as wt,Af as M,Bb as pt,C as m,Cc as yt,Da as de,If as fe,La as N,Md as kt,Nc as H,Oa as ue,Of as me,Pc as _t,R as O,Rd as bt,Sd as vt,T as b,Td as Ct,Ub as gt,V as G,Wd as St,ad as v,b as ae,bb as mt,bd as C,cd as Me,d as lt,lc as le,lf as xt,mf as Et,od as X,ra as W,wa as Oe,wc as ht,xa as ce,z as ft,zd as Y}from"./chunk-GE4KCSZP.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8b010e79-a73a-5760-ac05-8dc88484cd69")}catch{}})();var pe={version:1,aliases:{}};function Lt(e=[]){let t=new Set(X),n=r=>{/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(r)&&t.add(r)};for(let r of e){for(let o of Object.keys(r.provenance_environment_keys??{}))n(o);for(let o of Object.keys(r.provenance_resolvers??{}))n(o);for(let o of r.provenance_unavailable_dimensions??[])n(o)}return[...t].sort()}function Rt(e){if(e===void 0)return;let n=(typeof e=="string"?[e]:e).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0);return n.length===0?void 0:new Set(n)}function Re(e,t){if(e.agent_harness?.trim())return{agent_harness:e.agent_harness,harness_source:"recorded"};let n=t.aliases[e.author];return n?{agent_harness:n,harness_source:"vocabulary"}:{harness_source:"unresolved"}}function Un(e,t=X){let n=new Set(t),r=new Map,o=e.provenance===void 0?[]:typeof e.provenance=="string"?[e.provenance]:e.provenance;for(let i of o.flatMap(s=>s.split(","))){let s=i.indexOf("=");if(s<0)throw new m(`Provenance predicate must use dimension=value; received "${i.trim()}".`,f.USAGE,{code:"invalid_provenance_predicate"});let a=i.slice(0,s).trim().toLowerCase(),d=i.slice(s+1).trim();if(!n.has(a))throw new m(`Unknown provenance dimension "${a||i.trim()}". Declared dimensions: ${[...n].sort().join(", ")}.`,f.USAGE,{code:"unknown_provenance_dimension"});if(d.length===0)throw new m(`Provenance predicate must use dimension=value; received "${i.trim()}".`,f.USAGE,{code:"invalid_provenance_predicate"});let c=r.get(a)??new Set;c.add(d),r.set(a,c)}return r}function Ut(e,t=pe,n={}){let r=Re(e,t);return{...n.itemId===void 0?{}:{item_id:n.itemId},...n.version===void 0?{}:{version:n.version},ts:e.ts,op:e.op,author:e.author,...e.author_source===void 0?{}:{author_source:e.author_source},...r,vocabulary_version:t.version,...e.agent_instance===void 0?{}:{agent_instance:e.agent_instance},agent_provenance:e.agent_provenance??{},...e.message===void 0?{}:{message:e.message}}}function Us(e,t,n=pe,r=X){return Le(t,n,r)(e)}function Le(e,t=pe,n=X){let r=Rt(e.harness),o=Rt(e.agentInstance),i=Un(e,n);return s=>{let d=Re(s,t).agent_harness;if(r&&(!d||!r.has(d))||o&&!o.has(s.agent_instance??""))return!1;for(let[c,u]of i){let l=s.agent_provenance?.[c];if(!l||!u.has(l.value))return!1}return!0}}function Pt(e,t=pe,n=X){let r=new Set(n),o=new Map,i=0;for(let s of e){for(let d of Object.keys(s.agent_provenance??{}))r.add(d);Re(s,t).agent_harness?i+=1:o.set(s.author,(o.get(s.author)??0)+1)}return{entries:e.length,vocabulary_version:t.version,harness:{resolved:i,unresolved:e.length-i,unresolved_authors:[...o].map(([s,a])=>({author:s,entries:a})).sort((s,a)=>a.entries-s.entries||s.author.localeCompare(a.author)).slice(0,20)},dimensions:[...r].sort().map(s=>{let a=0,d=0;for(let c of e){let u=c.agent_provenance?.[s];u===null?d+=1:u!==void 0&&(a+=1)}return{dimension:s,observed:a,unavailable:d,legacy_missing:e.length-a-d}})}}import Pn from"node:fs/promises";import Bt 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]="a7efa5e0-5610-51ca-8288-4f5410dbcf51")}catch{}})();var jn=20,Bn=5;function Ue(e,t){if(e===void 0)return;let n=e.trim();if(n.length===0)throw new m(`${t} must not be empty`,f.USAGE);return n}function jt(e,t,n){if(e===void 0)return;let r=e.trim();if(r.length===0)throw new m("Activity time bounds must not be empty",f.USAGE);let o=n==="--from"&&/^\d+[hdwm]$/iu.test(r)?`-${r}`:r;return G(o,new Date(t),n)}function zn(e,t,n){return!(e.ts.length===0&&(t||n)||t&&b(e.ts,t)<0||n&&b(e.ts,n)>=0)}function Gn(e,t){return t===void 0?e:e.slice(0,t)}function K(e,t=""){return typeof e=="string"?e:t}function Wn(e,t){return{...t,id:e,ts:K(t.ts),author:K(t.author,"unknown"),op:K(t.op,"unknown"),patch:Array.isArray(t.patch)?t.patch:[],before_hash:K(t.before_hash),after_hash:K(t.after_hash)}}function Hn(e){return[...e].sort((t,n)=>{let r=n.ts.localeCompare(t.ts);if(r!==0)return r;let o=t.id.localeCompare(n.id);return o!==0?o:t.op.localeCompare(n.op)})}async function Xn(e){try{return(await Pn.readdir(e)).filter(t=>t.endsWith(".jsonl")).sort((t,n)=>t.localeCompare(n))}catch(t){if(t.code==="ENOENT")return[];throw t}}function qn(e){let t=O(),n=jt(e.from,t,"--from"),r=jt(e.to,t,"--to");if(n&&r&&b(n,r)>=0)throw new m("Activity --from must be before --to",f.USAGE);let o=Tt(e.limit);if(e.unbounded===!0&&o!==void 0)throw new m("Activity --unbounded cannot be combined with --limit",f.USAGE);return{id:Ue(e.id,"Activity --id"),op:Ue(e.op,"Activity --op"),author:Ue(e.author,"Activity --author"),from:n,to:r,limit:e.unbounded===!0?void 0:o??(e.compact===!0?jn:Bn),limitSource:e.unbounded===!0||o!==void 0?"explicit":"default",harness:e.harness,agentInstance:e.agentInstance,provenance:e.provenanceFilter}}async function Yn(e){let t=N(process.cwd(),e.path);if(!await ae(ue(t)))throw new m(`Tracker is not initialized at ${t}. Run pm init first.`,f.NOT_FOUND);return{pmRoot:t,settings:await M(t)}}async function Vn(e){let t=de(e.settings,le()),n=await me(e.pmRoot,e.settings.item_format,t.type_to_folder,void 0,e.settings.schema);await xt({pmRoot:e.pmRoot,settings:e.settings,itemIds:n.map(o=>o.id),commandLabel:"activity"});let r=Bt.join(e.pmRoot,"history");return await ht({path:r,scope:"project"}),r}function Kn(e,t,n){return n.op&&e.op!==n.op||n.author&&e.author!==n.author?!1:zn(t,n.from,n.to)}async function Jn(e,t){let n=[];for(let r of await Xn(e)){let o=r.slice(0,-6);if(t.id&&o!==t.id)continue;let i=await wt(Bt.join(e,r),o);for(let s of i){let a=Wn(o,s);Kn(s,a,t)&&n.push(a)}}return n}function Zn(e){return e.map(t=>({id:t.id,op:t.op,ts:t.ts,author:t.author,...t.message?{msg:t.message}:{}}))}async function zt(e,t){let n=await Yn(t),r=qn(e),o=await Vn(n),i=Lt(n.settings.agent_identity.harness_signals),s=n.settings.agent_identity.identity_vocabulary,a=Le({harness:r.harness,agentInstance:r.agentInstance,provenance:r.provenance},s,i),d=Hn(await Jn(o,r)).filter(a),c=Gn(d,r.limit),u=e.compact===!0,l=u?Zn(c):void 0,p=e.provenance===!0?c.map(S=>Ut(S,s,{itemId:S.id})):void 0,g=d.length-c.length,w=e.provenance===!0?"provenance":u?"compact":"full";return{...{compact:{compact_activity:l},provenance:{provenance_activity:p},full:{activity:c}}[w],compact:u,projection:{mode:w,row_key:w==="compact"?"compact_activity":w==="provenance"?"provenance_activity":"activity"},omission_receipt:kt("activity",w),count:c.length,total_count:d.length,limit:r.limit??null,omitted_count:g,has_more:g>0,...e.provenanceSummary===!0?{provenance_summary:Pt(d,s,i)}:{},applied_bound:{kind:r.limit===void 0?"unbounded":"limit",source:r.limitSource,value:r.limit??null}}}import{encode as Qn}from"@toon-format/toon";(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]="f1677c6e-872e-5c42-ae3d-f73f4ec73616")}catch{}})();var Pe=["agenda","day","week","month"],je=["markdown","toon","json"],er=["sun","mon","tue","wed","thu","fri","sat"],tr=365,nr=365,Ht=28,rr=1e3;function Be(e,t){if(e===void 0)return;let n=Number(e);if(!Number.isInteger(n)||n<0)throw new m(`${t} must be a non-negative integer`,f.USAGE);return n}function or(e){if(!e)return new Set(["deadlines","reminders","events"]);let t=e.trim().toLowerCase();if(t==="all")return new Set(["deadlines","reminders","events"]);let n=t.split(/[|,]/).map(o=>o.trim()).filter(o=>o.length>0);if(n.length===0)throw new m("Calendar include filter must not be empty",f.USAGE);let r=new Set;for(let o of n){if(o==="deadlines"||o==="deadline"){r.add("deadlines");continue}if(o==="reminders"||o==="reminder"){r.add("reminders");continue}if(o==="events"||o==="event"||o==="scheduled"){r.add("events");continue}throw new m("Calendar include filter must be deadlines|reminders|events|scheduled|all",f.USAGE)}return r}function Xt(e,t){let n;for(let r of t){let o=mt(e,r,2);o!==null&&(n===void 0||o<n.distance)&&(n={choice:r,distance:o})}return n?.choice}function ir(e){if(!e)return"agenda";let t=e.trim().toLowerCase();if(!Pe.includes(t)){let n=Xt(t,Pe);throw new m(`Calendar view must be one of ${Pe.join("|")}${n?`. Did you mean "${n}"?`:"."}`,f.USAGE)}return t}function sr(e){if(!e)return;let t=e.trim().toLowerCase();if(!je.includes(t)){let n=Xt(t,je);throw new m(`Calendar format must be one of ${je.join("|")}${n?`. Did you mean "${n}"?`:"."}`,f.USAGE)}return t}function Zs(e,t){let n=sr(e.format);if(t.json&&n&&n!=="json")throw new m("Cannot combine --json with --format markdown|toon",f.USAGE);return t.json?"json":n??"markdown"}function ar(e,t){if(e===void 0)return;let n=v(e,t);if(!n){let r=t.definitions.map(o=>o.id);throw new m(`Calendar status filter must be one of ${r.join("|")}`,f.USAGE)}return n}function cr(e){if(e===void 0)return;let t=e.trim().toLowerCase();if(!t)throw new m("Calendar assignee filter must be one of assigned|unassigned",f.USAGE);if(t!=="assigned"&&t!=="unassigned")throw new m(`Invalid calendar assignee filter "${e}". Allowed: assigned|unassigned`,f.USAGE);return t}function ge(e){return new Date(e).toISOString().slice(0,10)}function qt(e,t){if(!t||t==="UTC")return ge(e);try{let n=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(new Date(e)),r=n.find(s=>s.type==="year")?.value,o=n.find(s=>s.type==="month")?.value,i=n.find(s=>s.type==="day")?.value;if(r&&o&&i)return`${r}-${o}-${i}`}catch{}return ge(e)}function He(e){let t=new Date(e);return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),0,0,0,0)).toISOString()}function A(e,t){let n=new Date(e);return new Date(n.getTime()+t*24*60*60*1e3).toISOString()}function Yt(e){let t=new Date(He(e)),n=t.getUTCDay(),r=n===0?-6:1-n;return A(t.toISOString(),r)}function dr(e){let t=new Date(e);return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),1,0,0,0,0)).toISOString()}function ur(e){let t=new Date(e);return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth()+1,1,0,0,0,0)).toISOString()}function lr(e,t){return b(e,t)>=0?e:t}function Gt(e){return Object.fromEntries([...e.entries()].sort(([t],[n])=>t.localeCompare(n)))}function Wt(e,t){e.set(t,(e.get(t)??0)+1)}function fr(e){if(!e)return null;let t=[`freq=${e.freq}`];if(e.interval!==void 0&&t.push(`interval=${e.interval}`),e.count!==void 0&&t.push(`count=${e.count}`),e.until&&t.push(`until=${e.until}`),e.by_weekday&&e.by_weekday.length>0){let n=[...e.by_weekday].sort((r,o)=>W(r)-W(o));t.push(`by_weekday=${n.join("|")}`)}if(e.by_month_day&&e.by_month_day.length>0){let n=[...e.by_month_day].sort((r,o)=>r-o);t.push(`by_month_day=${n.join("|")}`)}if(e.exdates&&e.exdates.length>0){let n=[...e.exdates].sort((r,o)=>r.localeCompare(o));t.push(`exdates=${n.join("|")}`)}return t.join(",")}function Vt(e,t,n,r){let o=new Date(Date.UTC(e,t,n,r.getUTCHours(),r.getUTCMinutes(),r.getUTCSeconds(),r.getUTCMilliseconds()));if(!(o.getUTCFullYear()!==e||o.getUTCMonth()!==t||o.getUTCDate()!==n))return o.toISOString()}function Kt(e){return er[new Date(e).getUTCDay()]}function mr(e){let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toISOString():null}function pr(e){let t=new Set;for(let n of e??[]){let r=mr(n);r&&t.add(r)}return t}function gr(e,t,n,r,o){let i=e??A(n,-(r??nr)),s=t??A(e??n,o??tr);return{start:i,end:b(s,i)>0?s:A(i,1)}}function hr(e,t,n,r){let o=t.by_weekday!==void 0?[...t.by_weekday]:[Kt(e)],i=t.by_month_day!==void 0?[...t.by_month_day]:[new Date(e).getUTCDate()];return{startAt:e,startDate:new Date(e),window:n,maxOccurrences:r??rr,interval:t.interval??1,countLimit:t.count??Number.POSITIVE_INFINITY,until:t.until,excluded:pr(t.exdates),weekdayFilter:t.by_weekday!==void 0?new Set(t.by_weekday):void 0,monthDayFilter:t.by_month_day!==void 0?new Set(t.by_month_day):void 0,sortedWeekdays:[...new Set(o)].sort((s,a)=>W(s)-W(a)),sortedMonthDays:[...new Set(i)].sort((s,a)=>s-a),occurrences:[],produced:0}}function he(e,t){return b(t,e.startAt)<0?"continue":e.until&&b(t,e.until)>0||b(t,e.window.end)>=0?"stop":e.excluded.has(t)?"continue":(e.produced+=1,b(t,e.window.start)>=0&&e.occurrences.push(t),e.produced>=e.countLimit||e.occurrences.length>=e.maxOccurrences?"stop":"continue")}function ye(e,t){let n=Kt(t),r=new Date(t).getUTCDate(),o=!e.weekdayFilter||e.weekdayFilter.has(n),i=!e.monthDayFilter||e.monthDayFilter.has(r);return o&&i}function yr(e){let t=e.startAt;for(let n=0;n<e.maxOccurrences&&!(ye(e,t)&&he(e,t)==="stop");n+=1)t=A(t,e.interval);return e.occurrences}function _r(e,t,n){let r=W(n),o=A(t,r),i=new Date(o);return new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),e.startDate.getUTCHours(),e.startDate.getUTCMinutes(),e.startDate.getUTCSeconds(),e.startDate.getUTCMilliseconds())).toISOString()}function wr(e){let t=Yt(e.startAt);for(let n=0;n<e.maxOccurrences;n+=1){let r=A(t,n*e.interval*7);for(let o of e.sortedWeekdays){let i=_r(e,r,o);if(ye(e,i)&&he(e,i)==="stop")return e.occurrences}}return e.occurrences}function kr(e){let t=e.startDate.getUTCFullYear(),n=e.startDate.getUTCMonth();for(let r=0;r<e.maxOccurrences;r+=1){let o=new Date(Date.UTC(t,n+r*e.interval,1,0,0,0,0));for(let i of e.sortedMonthDays){let s=Vt(o.getUTCFullYear(),o.getUTCMonth(),i,e.startDate);if(!(!s||!ye(e,s))&&he(e,s)==="stop")return e.occurrences}}return e.occurrences}function br(e){let t=e.startDate.getUTCFullYear(),n=e.startDate.getUTCMonth();for(let r=0;r<e.maxOccurrences;r+=1){let o=t+r*e.interval;for(let i of e.sortedMonthDays){let s=Vt(o,n,i,e.startDate);if(!(!s||!ye(e,s))&&he(e,s)==="stop")return e.occurrences}}return e.occurrences}function vr(e,t,n,r){let o=hr(e,t,n,r);return t.freq==="daily"?yr(o):t.freq==="weekly"?wr(o):t.freq==="monthly"?kr(o):br(o)}function Jt(e){return[...e].sort((t,n)=>{let r=b(t.at,n.at);if(r!==0)return r;let o=t.item_priority-n.item_priority;if(o!==0)return o;let i=t.item_id.localeCompare(n.item_id);if(i!==0)return i;let s=t.kind.localeCompare(n.kind);if(s!==0)return s;let a=String(t.event_title).localeCompare(String(n.event_title));return a!==0?a:String(t.reminder_text).localeCompare(String(n.reminder_text))})}function Xe(e){return{item_id:e.id,item_title:e.title,item_type:e.type,item_status:e.status,item_priority:e.priority,item_assignee:e.assignee??null,item_deadline:e.deadline??null,item_tags:e.tags}}function Cr(e){return e.deadline?{at:e.deadline,date:ge(e.deadline),kind:"deadline",reminder_text:null,event_title:null,event_end:null,event_location:null,event_all_day:null,event_timezone:null,event_recurring:null,event_recurrence_rule:null,...Xe(e),item_deadline:e.deadline}:null}function Sr(e){return(e.reminders??[]).map(t=>({at:t.at,date:ge(t.at),kind:"reminder",reminder_text:t.text,event_title:null,event_end:null,event_location:null,event_all_day:null,event_timezone:null,event_recurring:null,event_recurrence_rule:null,...Xe(e)}))}function xr(e,t){if(!t)return null;let n=Date.parse(t)-Date.parse(e);return Number.isFinite(n)&&n>0?n:null}function Er(e,t,n){return t.recurrence&&n!==null?new Date(new Date(e).getTime()+n).toISOString():t.end_at??null}function Tr(e,t,n,r){let o=fr(t.recurrence),i=xr(t.start_at,t.end_at);return(t.recurrence?vr(t.start_at,t.recurrence,n,r):[t.start_at]).map(a=>({at:a,date:t.all_day===!0?a.slice(0,10):qt(a,t.timezone),kind:"event",reminder_text:t.description??null,event_title:t.title??e.title,event_end:Er(a,t,i),event_location:t.location??null,event_all_day:t.all_day??null,event_timezone:t.timezone??null,event_recurring:!!t.recurrence,event_recurrence_rule:o,...Xe(e)}))}function Ir(e,t,n,r){let o=[];for(let i of e){let s=n.has("deadlines")?Cr(i):null;s&&o.push(s),n.has("reminders")&&o.push(...Sr(i));for(let a of n.has("events")?i.events??[]:[])o.push(...Tr(i,a,t,r))}return Jt(o)}function $r(e,t,n,r,o){let i=At(t.type,n),s=t.tag?.trim().toLowerCase(),a=Nt(t.priority),d=ar(t.status,r),c=t.assignee?.trim(),u=cr(t.assigneeFilter),l=t.sprint?.trim(),p=t.release?.trim();if(c&&(c.toLowerCase()==="none"||c.toLowerCase()==="null"))throw new m('--assignee no longer accepts "none" or "null". Use --assignee-filter unassigned.',f.USAGE);if(c!==void 0&&u==="unassigned")throw new m("Cannot combine --assignee with --assignee-filter unassigned",f.USAGE);return e.filter(g=>Dr(g,{typeFilter:i,tagFilter:s,priorityFilter:a,statusFilter:d,assigneeFilter:c,assigneeModeFilter:u,sprintFilter:l,releaseFilter:p,runtimeFieldFilters:o}))}function Dr(e,t){return Nr(e,t)&&Ar(e,t)&&$t(e,t.runtimeFieldFilters)}function Nr(e,t){return!(t.typeFilter&&e.type!==t.typeFilter||t.tagFilter&&!e.tags.some(n=>n.trim().toLowerCase()===t.tagFilter)||t.priorityFilter!==void 0&&e.priority!==t.priorityFilter||t.statusFilter&&e.status!==t.statusFilter)}function Ar(e,t){return!(t.assigneeModeFilter==="assigned"&&!e.assignee||t.assigneeModeFilter==="unassigned"&&e.assignee||t.assigneeFilter!==void 0&&e.assignee!==t.assigneeFilter||t.sprintFilter!==void 0&&e.sprint!==t.sprintFilter||t.releaseFilter!==void 0&&e.release!==t.releaseFilter)}function Or(e,t,n){return!(t&&b(e.at,t)<0||n&&b(e.at,n)>=0)}function ze(e,t,n){return e.trim().toLowerCase()==="today"?He(t):G(e,new Date(t),n)}function Mr(e,t,n){let r=t.date?ze(t.date,n,"--date"):n,o=t.past===!0,i=t.fullPeriod===!0,s=t.from?ze(t.from,n,"--from"):void 0,a=t.to?ze(t.to,n,"--to"):void 0;if(s&&a&&b(s,a)>=0)throw new m("Calendar --from must be before --to",f.USAGE);if(e!=="agenda"&&(t.from!==void 0||t.to!==void 0))throw new m("--from and --to are only supported for --view agenda",f.USAGE);if(e==="agenda")return Fr(r,t,n,o,i,s,a);if(e==="day"){let c=He(r);return Ge(r,n,o,i,c,A(c,1))}if(e==="week"){let c=Yt(r);return Ge(r,n,o,i,c,A(c,7))}let d=dr(r);return Ge(r,n,o,i,d,ur(r))}function Fr(e,t,n,r,o,i,s){if(o)throw new m("--full-period is only supported for --view day|week|month. For agenda windows, use --from and --to.",f.USAGE);return{anchor:e,start:i??(t.date?e:r?void 0:n),end:s,fullPeriod:!1}}function Ge(e,t,n,r,o,i){let s=n||r;return{anchor:e,start:s?o:lr(o,t),end:i,periodStart:o,periodEnd:i,fullPeriod:s}}function Rr(e){let t=new Map;for(let n of e){let r=t.get(n.date)??[];r.push(n),t.set(n.date,r)}return[...t.entries()].sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>({date:n,count:r.length,events:Jt(r)}))}function Lr(e){let t=new Set,n=new Map,r=new Map,o=0,i=0,s=0,a=0;for(let d of e)t.add(d.item_id),Wt(n,d.item_type),Wt(r,d.item_status),d.kind==="deadline"?o+=1:d.kind==="reminder"?i+=1:(s+=1,d.event_recurring===!0&&(a+=1));return{events:e.length,items:t.size,deadlines:o,reminders:i,scheduled:s,by_kind:{deadline:o,reminder:i,event:s},by_type:Gt(n),by_status:Gt(r),recurring_events:a}}function Ur(e){let t=e.start??"unbounded",n=e.end??"unbounded";return`${t} -> ${n}`}function Zt(e,t){if(t&&t!=="UTC")try{let n=new Intl.DateTimeFormat("en-GB",{timeZone:t,hour:"2-digit",minute:"2-digit",hourCycle:"h23"}).formatToParts(new Date(e)),r=n.find(i=>i.type==="hour")?.value,o=n.find(i=>i.type==="minute")?.value;if(r&&o)return`${r}:${o}`}catch{}return`${new Date(e).toISOString().slice(11,16)}Z`}function We(e){let t=Object.entries(e);return t.length===0?"empty":t.map(([n,r])=>`${n}=${r}`).join(", ")}function Pr(e){return e.event_end?e.event_all_day===!0?e.event_end.slice(0,10):e.date===qt(e.event_end,e.event_timezone)?Zt(e.event_end,e.event_timezone):e.event_end:null}function jr(e){let t=`${Zt(e.at,e.event_timezone)} [${e.kind}] ${e.item_id} type=${e.item_type} p${e.item_priority} ${e.item_status} ${e.item_title}`;if(e.kind==="reminder"){let n=e.reminder_text??"";return`${t} \u2014 ${n} reminder=${JSON.stringify(n)}`}if(e.kind==="event"){let n=[],r=e.event_title??e.item_title;e.event_title!==null&&e.event_title!==e.item_title&&(n.push(r),n.push(`title=${JSON.stringify(r)}`)),e.event_recurring&&(n.push("(recurring)"),n.push("recurring=true"));let i=Pr(e);return i&&n.push(`end=${i}`),e.event_all_day!==null&&n.push(`all_day=${e.event_all_day?"true":"false"}`),e.event_timezone&&n.push(`timezone=${e.event_timezone}`),e.event_location&&(n.push(`@ ${e.event_location}`),n.push(`location=${JSON.stringify(e.event_location)}`)),e.event_recurrence_rule&&n.push(`recurrence=${e.event_recurrence_rule}`),e.reminder_text&&n.push(`description=${JSON.stringify(e.reminder_text)}`),`${t} \u2014 ${n.join(" ")}`}return t}function Qs(e){let t=[];if(t.push(`# pm calendar (${e.view})`),t.push(""),t.push(`- now: ${e.now}`),t.push(`- window: ${Ur(e.range)}`),e.range.period_start&&e.range.period_end&&(t.push(`- period: ${e.range.period_start} -> ${e.range.period_end}`),t.push(`- period-mode: ${e.range.full_period?"full-period":"active-window"}`)),t.push(`- events: ${e.summary.events} (deadlines: ${e.summary.deadlines}, reminders: ${e.summary.reminders}, scheduled: ${e.summary.scheduled})`),t.push(`- items: ${e.summary.items}`),t.push(`- by-kind: ${We(e.summary.by_kind)}`),t.push(`- by-type: ${We(e.summary.by_type)}`),t.push(`- by-status: ${We(e.summary.by_status)}`),t.push(`- recurring-events: ${e.summary.recurring_events}`),t.push(""),e.events.length===0)return t.push("No calendar events matched the selected filters."),t.join(`
|
|
2
|
-
`);for(let n of e.days){t.push(`## ${n.date} (${n.count})`);for(let r of n.events)t.push(`- ${jr(r)}`);t.push("")}if(e.warnings&&e.warnings.length>0){t.push("### warnings");for(let n of e.warnings)t.push(`- ${n}`);t.push("")}return Br(t.join(`
|
|
3
|
-
`))}function ea(e){return Qn(e)}function Br(e){let t=e.length;for(;t>0&&e[t-1]===`
|
|
4
|
-
`;)t-=1;return e.slice(0,t)}function zr(e){let t=O(),n=ir(e.view),r=Mr(n,e,t),o=L(e.limit),i=or(e.include),s=Be(e.recurrenceLookaheadDays,"Calendar recurrence lookahead days"),a=Be(e.recurrenceLookbackDays,"Calendar recurrence lookback days"),d=Be(e.occurrenceLimit,"Calendar occurrence limit");if(d!==void 0&&d<1)throw new m("Calendar occurrence limit must be >= 1",f.USAGE);let c=i.has("events")&&!i.has("deadlines")&&!i.has("reminders"),u=e.to!==void 0||s!==void 0||a!==void 0||d!==void 0,l=c&&!u;return{nowValue:t,view:n,rangeBounds:r,limit:o,includeSources:i,occurrenceLimit:d,recurrenceLookaheadDays:l?Ht:s,recurrenceLookbackWindowDays:l&&a===void 0?0:a,eventsOnlyCapApplied:l}}function Gr(e,t){t&&e.push(`recurring_events_default_cap_applied:lookback=0d,lookahead=${Ht}d -- use --recurrence-lookback-days/--recurrence-lookahead-days or --to for wider range`)}function Wr(e,t){return{type:e.type??null,tag:e.tag??null,priority:e.priority??null,status:e.status??null,assignee:e.assignee??null,assignee_filter:e.assigneeFilter??null,sprint:e.sprint??null,release:e.release??null,runtime_filters:t,limit:e.limit??null,include:e.include??null,full_period:e.fullPeriod===!0?"true":null,recurrence_lookahead_days:e.recurrenceLookaheadDays??null,recurrence_lookback_days:e.recurrenceLookbackDays??null,occurrence_limit:e.occurrenceLimit??null}}function Hr(e,t){return{start:t.start??null,end:t.end??null,period_start:t.periodStart??null,period_end:t.periodEnd??null,full_period:t.fullPeriod,past:e.past===!0,from:e.from??null,to:e.to??null}}async function Qt(e,t){let n=N(process.cwd(),t.path);if(!await ae(ue(n)))throw new m(`Tracker is not initialized at ${n}. Run pm init first.`,f.NOT_FOUND);let r=zr(e),o=await M(n),i=H(o.schema),s=_t(o.schema),a=It(e,s,"calendar"),d=de(o,le()),c=[];Gr(c,r.eventsOnlyCapApplied);let u=await me(n,o.item_format,d.type_to_folder,c,o.schema),l=$r(u,e,d,i,a),p=gr(r.rangeBounds.start,r.rangeBounds.end,r.nowValue,r.recurrenceLookbackWindowDays,r.recurrenceLookaheadDays),w=Ir(l,p,r.includeSources,r.occurrenceLimit).filter(k=>Or(k,r.rangeBounds.start,r.rangeBounds.end)),h=r.limit===void 0?w:w.slice(0,r.limit),S=Rr(h),_=[...new Set(c)].sort((k,x)=>k.localeCompare(x));return{view:r.view,output_default:"markdown",now:r.nowValue,anchor:r.rangeBounds.anchor,range:Hr(e,r.rangeBounds),filters:Wr(e,a),summary:Lr(h),events:h,days:S,..._.length>0?{warnings:_}:{}}}(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]="1f898377-b606-5bfd-932d-6ce5f2f9c717")}catch{}})();var qe=["structural","recency","activity_density","graph_proximity","claim_focus","priority_pressure","risk_pressure","deadline_pressure","knowledge_density","author_affinity","usage_affinity","semantic_similarity"],Xr=Symbol("no-context-author"),qr=Symbol("no-item-assignee");function en(e,t){if(typeof e!="string")return t;let n=e.trim().toLowerCase();return n.length>0?n:t}function Yr(e,t){let n=typeof e=="number"?e:typeof e=="string"?Number.parseFloat(e):Number.NaN;return Number.isFinite(n)?1-Math.min(Math.max(n,0),t)/t:0}function Vr(e,t){let n=typeof e=="string"?Date.parse(e):e instanceof Date?e.getTime():typeof e=="number"?e:Number.NaN;if(!Number.isFinite(n)||!Number.isFinite(t))return 0;let r=(n-t)/864e5;return r<=0?1:1/(1+r/30)}function Kr(e){let t=typeof e=="string"?e.trim().toLowerCase():void 0;return t==="critical"||t==="high"?1:t==="medium"?.5:t==="low"?.1:0}function _e(e,t,n){return e?.[t]??n}function we(e,t){let n=c=>{if(typeof c!="string")return"";try{return G(c,new Date(Number.NaN),"updated_at")}catch{return""}},r=[...e].sort((c,u)=>{let l=n(c.updated_at),p=n(u.updated_at);return b(p,l)||c.id.localeCompare(u.id)}),o=new Map(r.map((c,u)=>[c.id,u])),i=Math.max(e.length-1,1),s=en(t.author,Xr),a=v("in_progress",t.statusRegistry),d=Date.parse(t.now);return e.map(c=>{let u=en(c.assignee,qr)===s,l=(c.comments?.length??0)+(c.notes?.length??0)+(c.learnings?.length??0);return{id:c.id,item:c,signals:{recency:e.length===1?1:1-o.get(c.id)/i,activity_density:t.activityDensity?.[c.id],graph_proximity:_e(t.graphProximity,c.id,c.parent?.3:0),claim_focus:_e(t.claimFocus,c.id,C(c.status,t.statusRegistry)===a?1:u?.75:0),priority_pressure:Yr(c.priority,4),risk_pressure:Kr(c.risk),deadline_pressure:Vr(c.deadline,d),knowledge_density:_e(t.knowledgeDensity,c.id,Math.min(l/5,1)),author_affinity:_e(t.authorAffinity,c.id,u?1:0),usage_affinity:t.usageAffinity?.[c.id],semantic_similarity:t.semanticSimilarity?.[c.id]}}})}var Jr="context_relevance",Zr={structural:.4,recency:.35,activity_density:.25,graph_proximity:.15,claim_focus:.6,priority_pressure:.35,risk_pressure:.2,deadline_pressure:.45,knowledge_density:.25,author_affinity:.2,usage_affinity:.3,semantic_similarity:.5},Qr=new TextEncoder;function eo(e){let t=new Set;for(let n of e){if(typeof n.id!="string"||n.id.trim().length===0||t.has(n.id))throw new TypeError("Context relevance candidates require unique non-empty ids");t.add(n.id);for(let[r,o]of Object.entries(n.signals??{})){if(r==="structural"||!qe.includes(r))throw new TypeError(`Unknown context relevance signal: ${r}`);if(o!==void 0&&(!Number.isFinite(o)||o<0||o>1))throw new TypeError(`Context relevance signal ${r} must be a finite number from 0 to 1`)}}}function to(e){let t={...Zr};for(let[n,r]of Object.entries(e??{}))r!==void 0&&qe.includes(n)&&(t[n]=r);for(let[n,r]of Object.entries(t))if(!Number.isFinite(r)||r<0)throw new TypeError(`Context relevance weight ${n} must be a finite non-negative number`);return t}function nn(e,t={}){eo(e);let n=to(t.weights),r=Math.max(e.length-1,1),o=new Set(["structural"]);for(let a of e)for(let[d,c]of Object.entries(a.signals??{}))c!==void 0&&o.add(d);let i=qe.filter(a=>o.has(a)),s=e.map((a,d)=>{let c={structural:e.length===1?1:1-d/r,...a.signals},u={},l=0,p=0;for(let g of i){let w=c[g];if(w===void 0)continue;let h=w*n[g];u[g]=h,l+=h,p+=n[g]}return{...a,baseline_rank:d+1,rank:0,score:p===0?0:l/p,contributions:u}});return s.sort((a,d)=>d.score-a.score||a.baseline_rank-d.baseline_rank),s.forEach((a,d)=>{a.rank=d+1}),{model:"default-weighted-v1",available_signals:i,ranked:s}}async function no(e,t={}){let n=nn(e,t);if(!t.scorer)return n;let r=await t.scorer({candidates:e,default_report:n}),o=new Map;for(let s of r){if(o.has(s.id)||!Number.isFinite(s.score))throw new TypeError("Context relevance scorer must return one finite score for every candidate");o.set(s.id,s.score)}if(o.size!==e.length||e.some(s=>!o.has(s.id)))throw new TypeError("Context relevance scorer must return one finite score for every candidate");let i=n.ranked.map(s=>{let a=o.get(s.id);return{...s,score:a,contributions:{custom:a}}});return i.sort((s,a)=>a.score-s.score||s.baseline_rank-a.baseline_rank),i.forEach((s,a)=>{s.rank=a+1}),{model:"custom",available_signals:n.available_signals,ranked:i}}async function ke(e,t,n={}){let r=nn(t,n),o=await yt(Jr,{surface:e,candidates:t,default_report:r});if(!o.handled)return o.warnings.length>0?{...r,warnings:o.warnings}:r;if(!Array.isArray(o.result)||!o.result.every(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.score=="number"&&Number.isFinite(i.score)))return{...r,warnings:[...o.warnings,"extension_context_relevance_invalid_result"]};try{let i=await no(t,{...n,scorer:()=>o.result});return o.warnings.length>0?{...i,warnings:o.warnings}:i}catch{return{...r,warnings:[...o.warnings,"extension_context_relevance_invalid_result"]}}}var ro=["ndcg","reciprocal_rank","required_recall","continuity_coverage","token_budget_adherence"];function tn(e,t){return e.length===0?1:e.filter(n=>t.has(n)).length/e.length}function oo(e){if(!Number.isFinite(e.actual_tokens)||e.actual_tokens<0||!Number.isFinite(e.token_budget)||e.token_budget<=0)throw new TypeError("Context ranking token counts require actual_tokens >= 0 and token_budget > 0");let t=e.judgments??{},n=e.ranked_ids.map(c=>Math.max(0,t[c]??0)),r=Object.values(t).map(c=>Math.max(0,c)).sort((c,u)=>u-c).slice(0,n.length||1),o=c=>c.reduce((u,l,p)=>u+(2**l-1)/Math.log2(p+2),0),i=o(r),s=n.findIndex(c=>c>0),a=new Set(e.ranked_ids),d=e.actual_tokens<=e.token_budget;return{ndcg:i===0?1:o(n)/i,reciprocal_rank:s<0?0:1/(s+1),required_recall:tn(e.required_ids??[],a),continuity_coverage:tn(e.continuity_ids??[],a),token_budget_adherence:d?1:e.token_budget/e.actual_tokens,within_token_budget:d}}function io(e){return Math.ceil(Qr.encode(JSON.stringify(e)).byteLength/4)}function so(e){return Math.round(e*1e4)/1e4}function ao(e,t){let n=t==="context"?[...e.high_level??[],...e.low_level??[],...e.blocked_fallback??[]].map(i=>i.id):[...e.recommended?[e.recommended]:[],...e.ready??[]].map(i=>i.id),r=new Set(n),o=(e.ranking?.items??[]).filter(i=>r.has(i.id)).map(i=>({id:i.id,contributions:i.contributions}));return{rankedIds:n,attribution:o}}async function co(e,t){if(e.id.trim().length===0||e.rationale.trim().length===0)throw new TypeError("Context evaluation scenarios require non-empty id and rationale values");let n=e.surface==="context"?await t.context({...e.options,explainRanking:!0}):await t.next({...e.options,explainRanking:!0}),{rankedIds:r,attribution:o}=ao(n,e.surface),i={...n,ranking:void 0},s=io(i);return{id:e.id,surface:e.surface,rationale:e.rationale,ranked_ids:r,actual_tokens:s,metrics:oo({ranked_ids:r,judgments:e.judgments,required_ids:e.required_ids,continuity_ids:e.continuity_ids,actual_tokens:s,token_budget:e.token_budget}),attribution:o}}function uo(e,t){if(e.length===0)throw new TypeError("Context evaluation requires at least one scenario report");let n=ro;for(let i of n)if(!Number.isFinite(t[i]))throw new TypeError(`Context evaluation threshold ${i} must be a finite number`);let r=Object.fromEntries(n.map(i=>[i,so(e.reduce((s,a)=>s+a.metrics[i],0)/e.length)])),o=n.filter(i=>r[i]<t[i]).map(i=>`${i}:${r[i]}<${t[i]}`);return{scenario_count:e.length,aggregate:r,scenarios:[...e],passed:o.length===0,failures:o}}async function ia(e,t,n){let r=[];for(let o of e)r.push(await co(o,t));return uo(r,n)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b5c90a16-c075-5dc6-a326-ad2da7a6ef6d")}catch{}})();var lo={balanced:{redundancyPenalty:.35,uncertaintyPenalty:.2},context:{redundancyPenalty:.45,uncertaintyPenalty:.15},next:{redundancyPenalty:.25,uncertaintyPenalty:.3}},fo=["identity","summary","full"];function mo(e){if(!e.id.trim()||!Number.isInteger(e.rank)||e.rank<1)throw new TypeError("Context packing candidates require a non-empty id and positive integer rank");if(!Number.isFinite(e.score)||e.score<0)throw new TypeError("Context packing candidate scores must be finite and non-negative");let t=fo.map(n=>e.token_costs[n]);if(t.some(n=>!Number.isInteger(n)||n<1)||t[0]>t[1]||t[1]>t[2])throw new TypeError("Context projection costs must be positive monotone integers");if(e.uncertainty!==void 0&&(!Number.isFinite(e.uncertainty)||e.uncertainty<0))throw new TypeError("Context packing uncertainty must be finite and non-negative")}function po(e){if(!Number.isInteger(e.tokenBudget)||e.tokenBudget<1)throw new TypeError("Context packing tokenBudget must be a positive integer");let t=e.profile??"balanced",n=lo[t];if(!n)throw new TypeError("Unknown context packing profile");let r=e.redundancyPenalty??n.redundancyPenalty,o=e.uncertaintyPenalty??n.uncertaintyPenalty;if(!Number.isFinite(r)||r<0||r>1||!Number.isFinite(o)||o<0)throw new TypeError("Context packing penalties must be finite and within their supported ranges");if(e.latencyBudgetMs!==void 0&&(!Number.isFinite(e.latencyBudgetMs)||e.latencyBudgetMs<=0))throw new TypeError("Context packing latencyBudgetMs must be positive");return{redundancy:r,uncertainty:o,profile:t}}function go(e){let t=new Set;for(let n of e){if(mo(n),t.has(n.id))throw new TypeError("Context packing candidates require unique ids");t.add(n.id)}return[...e].sort((n,r)=>n.rank-r.rank||n.id.localeCompare(r.id))}function ho(e,t,n,r,o){let i=-1,s=0;for(let a=0;a<e.length;a+=1){if(a%128===0&&o()>=r)return{index:i,evaluated:s,timedOut:!0};let d=e[a];if(d.token_costs.identity>t)continue;s+=1;let c=i<0?void 0:e[i],u=n(d)/d.token_costs.identity,l=c===void 0?Number.NEGATIVE_INFINITY:n(c)/c.token_costs.identity;(u>l||u===l&&c!==void 0&&(d.rank<c.rank||d.rank===c.rank&&d.id.localeCompare(c.id)<0))&&(i=a)}return{index:i,evaluated:s,timedOut:!1}}function yo(e){let t=new Set,n=[],r=e.tokenBudget,o=c=>{let u=c.lineage??c.cluster,l=u&&t.has(u)?1-e.redundancyPenalty:1;return Math.max(0,(c.score-e.uncertaintyPenalty*(c.uncertainty??0))*l)},i=c=>{let u=c.token_costs.identity;n.push({...c,projection:"identity",tokens:u,marginal_value:o(c)}),r-=u;let l=c.lineage??c.cluster;l&&t.add(l)};for(let c of e.ordered.filter(u=>u.required))c.token_costs.identity<=r&&i(c);let s=e.ordered.filter(c=>!c.required),a=!0,d=0;for(;s.length>0;){let c=ho(s,r,o,e.deadline,e.readClock);if(d+=c.evaluated,c.timedOut&&(a=!1),c.index<0||c.timedOut)break;i(s.splice(c.index,1)[0])}return{included:n,remaining:r,selectionComplete:a,evaluatedCandidates:d}}function _o(e,t){let n=t;for(let r of["summary","full"]){let o=r==="summary"?"identity":"summary",i=[...e].sort((s,a)=>{let d=s.token_costs[r]-s.token_costs[o],c=a.token_costs[r]-a.token_costs[o];return a.marginal_value/Math.max(c,1)-s.marginal_value/Math.max(d,1)||s.rank-a.rank||s.id.localeCompare(a.id)});for(let s of i){if(s.projection!==o)continue;let a=s.token_costs[r]-s.tokens;a>n||(s.projection=r,s.tokens+=a,n-=a)}}return n}function rn(e,t){let n=po(t),r=go(e),o=t.readClock??performance.now.bind(performance),i=t.latencyBudgetMs===void 0?Number.POSITIVE_INFINITY:o()+t.latencyBudgetMs,s=yo({ordered:r,tokenBudget:t.tokenBudget,redundancyPenalty:n.redundancy,uncertaintyPenalty:n.uncertainty,deadline:i,readClock:o}),{included:a}=s,d=_o(a,s.remaining);a.sort((u,l)=>u.rank-l.rank||u.id.localeCompare(l.id));let c=new Set(a.map(u=>u.id));return{included:a,omitted_ids:r.filter(u=>!c.has(u.id)).map(u=>u.id),token_budget:t.tokenBudget,used_tokens:t.tokenBudget-d,remaining_tokens:d,complete:s.selectionComplete&&a.length===e.length&&a.every(u=>u.projection==="full"),selection_complete:s.selectionComplete,termination_reason:s.selectionComplete?"exhausted":"latency_budget",evaluated_candidates:s.evaluatedCandidates,latency_budget_ms:t.latencyBudgetMs??null,profile:n.profile,degradation_ladder:["full","summary","identity"]}}import{randomUUID as wo}from"node:crypto";import{appendFile as ko,mkdir as bo,readFile as vo,rename as Co,stat as So,writeFile as xo}from"node:fs/promises";import on 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]="5f4ccd28-a001-54aa-8378-893025c69b96")}catch{}})();var sn=2048,an=30,cn=864e5,Eo=262144,To="context-usage-ledger",I=class extends TypeError{code="context_usage_validation_failed";constructor(t){super(t),this.name="ContextUsageValidationError"}};function dn(e){return on.join(e,"runtime","context-usage.jsonl")}function J(e){let t=e.now??new Date().toISOString(),n=Date.parse(t);if(!Number.isFinite(n))throw new I("Context usage now must be a valid timestamp");return{iso:new Date(n).toISOString(),ms:n}}async function un(e){try{let n=(await vo(dn(e.pmRoot),"utf8")).split(`
|
|
5
|
-
`).filter(Boolean).flatMap(s=>{try{return[JSON.parse(s)]}catch{return[]}}),r=e.maxEvents??sn,o=e.retentionDays??an,i=J(e).ms-o*cn;return n.filter(s=>Date.parse(s.at)>=i).slice(-r)}catch{return[]}}async function ln(e,t){let n=e.maxEvents??sn,r=e.retentionDays??an;if(!Number.isInteger(n)||n<1||!Number.isFinite(r)||r<=0)throw new I("Context usage retention requires positive maxEvents and retentionDays");let o=dn(e.pmRoot),i=on.dirname(o),s=await Et(e.pmRoot,To,30,`context-usage:${process.pid}`,!1,!1,3e3);try{if(await bo(i,{recursive:!0}),await ko(o,t.map(u=>`${JSON.stringify(u)}
|
|
6
|
-
`).join(""),"utf8"),!(e.maxEvents!==void 0||e.retentionDays!==void 0)&&(await So(o)).size<=Eo)return;let d=await un(e),c=`${o}.${process.pid}.${wo()}.tmp`;await xo(c,`${d.map(u=>JSON.stringify(u)).join(`
|
|
7
|
-
`)}
|
|
8
|
-
`,"utf8"),await Co(c,o)}finally{await s()}}async function fn(e,t){await ln(e,[t])}async function be(e){if(!(process.env.PM_CONTEXT_USAGE_DISABLED==="1"||e.enabled===!1)){if(!e.author.trim()||e.rows.some(t=>!t.id.trim()||!Number.isInteger(t.rank)||t.rank<1))throw new I("Context usage serving requires an author and valid ranked rows");await fn(e,{kind:"serve",at:J(e).iso,author:e.author.trim(),surface:e.surface,profile:e.profile.trim()||"balanced",rows:e.rows})}}async function fa(e){if(!(process.env.PM_CONTEXT_USAGE_DISABLED==="1"||e.enabled===!1)){if(!e.author.trim()||!e.itemId.trim()||!e.intent.trim())throw new I("Context usage touch requires author, itemId, and intent");await fn(e,{kind:"touch",at:J(e).iso,author:e.author.trim(),item_id:e.itemId.trim(),intent:e.intent.trim()})}}async function ma(e){if(process.env.PM_CONTEXT_USAGE_DISABLED==="1"||e.enabled===!1||e.itemIds.length===0)return;let t=e.author.trim(),n=e.intent.trim();if(!t||!n)throw new I("Context usage touch requires author and intent");let r=new Set;for(let s of e.itemIds){if(typeof s!="string")throw new I("Context usage touch requires string itemIds");let a=s.trim();if(!a)throw new I("Context usage touch requires non-empty itemId");r.add(a)}let o=J(e).iso,i=[...r].map(s=>({kind:"touch",at:o,author:t,item_id:s,intent:n}));await ln(e,i)}function Io(e,t,n,r){return e.find(({entry:o,time:i})=>o.item_id===t&&i>=n&&i-n<=r)?.time}async function ve(e){if(process.env.PM_CONTEXT_USAGE_DISABLED==="1"||e.enabled===!1)return{affinity:{},positive_judgments:0,serving_events:0};let t=await un(e),n=J(e).ms,r=(e.horizonHours??24)*36e5;if(!Number.isFinite(r)||r<=0)throw new I("Context usage horizonHours must be positive");let o=e.author.trim(),i=t.filter(l=>l.kind==="touch"&&l.author===o).map(l=>({entry:l,time:Date.parse(l.at)})),s=new Map,a=0,d=0;for(let l of t){if(l.kind!=="serve"||l.author!==o)continue;a+=1;let p=Date.parse(l.at);for(let g of l.rows){if(!g.included)continue;let w=Io(i,g.id,p,r);if(w===void 0)continue;d+=1;let h=Math.max(0,(n-w)/cn);s.set(g.id,(s.get(g.id)??0)+Math.exp(-h/14))}}let c=Math.max(0,...s.values());return{affinity:Object.fromEntries([...s.entries()].map(([l,p])=>[l,.05+.95*(c>0?p/c:0)])),positive_judgments:d,serving_events:a}}import Z from"node:fs/promises";import Q from"node:path";import{createHash as $o,randomUUID as Do}from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a502be8f-57da-53c2-8de0-118a15688d93")}catch{}})();var Ye=1,Ve=1,mn=["recency","activity_density","graph_proximity","priority_pressure","risk_pressure","knowledge_density"];function Ce(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function pn(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1}function No(e){let t={};for(let n of mn){let r=e[n];if(r!==void 0){if(!pn(r))throw new TypeError(`Context relevance signal ${n} must be a finite number from 0 to 1`);t[n]=r}}return t}function Ao(e,t){let n=e.map(o=>[o.id,t(o)]),r=Math.max(0,...n.map(([,o])=>o));return Object.fromEntries(n.map(([o,i])=>[o,r===0?0:i/r]))}function Oo(e){let t=new Map(e.map(o=>[o.id,0])),n=o=>{t.set(o,(t.get(o)??0)+1)};for(let o of e){typeof o.parent=="string"&&o.parent.trim()&&(n(o.id),n(o.parent.trim()));for(let i of o.dependencies??[])typeof i.id!="string"||!i.id.trim()||(n(o.id),n(i.id.trim()))}let r=Math.max(0,...t.values());return Object.fromEntries(e.map(o=>[o.id,r===0?0:t.get(o.id)/r]))}function Mo(e,t){return{...t,activityDensity:t.activityDensity??Ao(e,n=>(n.comments?.length??0)+(n.notes?.length??0)+(n.learnings?.length??0)+(n.test_runs?.length??0)),graphProximity:t.graphProximity??Oo(e)}}function Fo(e){if(!Ce(e)||typeof e.id!="string"||!Ce(e.signals))return null;let t={},n=new Set(mn);for(let[r,o]of Object.entries(e.signals)){if(!n.has(r)||!pn(o))return null;t[r]=o}return{id:e.id,signals:t}}function Ro(e){if(!Ce(e)||e.format_version!==Ye||e.signal_set_version!==Ve||typeof e.source_cursor!="string"||e.source_cursor.trim().length===0||typeof e.generated_at!="string"||!Number.isFinite(Date.parse(e.generated_at))||e.source!=="derived_index"&&e.source!=="scan_fallback"||!Array.isArray(e.items))return null;let t=e.items.map(Fo);if(t.some(r=>r===null))return null;let n=t;return new Set(n.map(r=>r.id)).size!==n.length||n.some(r=>r.id.trim().length===0)?null:{format_version:Ye,signal_set_version:Ve,source_cursor:e.source_cursor,generated_at:e.generated_at,source:e.source,items:n.sort((r,o)=>r.id.localeCompare(o.id))}}function Lo(e,t){if(typeof t.sourceCursor!="string"||t.sourceCursor.trim().length===0)throw new TypeError("Context signal source cursor must be non-empty");if(!Number.isFinite(Date.parse(t.now)))throw new TypeError("Context signal snapshot clock must be a valid timestamp");if(t.source!=="derived_index"&&t.source!=="scan_fallback")throw new TypeError("Context signal snapshot source must be derived_index or scan_fallback");let n=we(e,Mo(e,t)).map(({id:r,signals:o})=>({id:r,signals:No(o)})).sort((r,o)=>r.id.localeCompare(o.id));return Object.freeze({format_version:Ye,signal_set_version:Ve,source_cursor:t.sourceCursor,generated_at:t.now,source:t.source,items:Object.freeze(n.map(r=>Object.freeze(r)))})}var Ke=class{filePath;constructor(t){if(typeof t!="string"||t.trim().length===0)throw new TypeError("Context signal store path must be non-empty");this.filePath=Q.resolve(t)}async read(){try{return JSON.parse(await Z.readFile(this.filePath,"utf8"))}catch(t){if(Ce(t)&&t.code==="ENOENT")return null;throw t}}async write(t){let n=Q.dirname(this.filePath);await Z.mkdir(n,{recursive:!0});let r=Q.join(n,`.${Q.basename(this.filePath)}.${Do()}.tmp`);try{await Z.writeFile(r,`${JSON.stringify(t)}
|
|
9
|
-
`,{encoding:"utf8",flag:"wx"}),await Z.rename(r,this.filePath)}finally{try{await Z.rm(r,{force:!0})}catch{}}}},Je=class{adapter;constructor(t){this.adapter=t}async readOrRebuild(t,n){let r=[],o=null;try{let l=await this.adapter.read();o=Ro(l),l!==null&&o===null&&r.push("context_signal_store_invalid")}catch{r.push("context_signal_store_invalid")}let i=t.map(l=>l.id).sort((l,p)=>l.localeCompare(p)),s=o?.items.map(l=>l.id)??[],a=o!==null&&o.source_cursor===n.sourceCursor&&o.source===n.source&&s.length===i.length&&s.every((l,p)=>l===i[p]),d;if(a&&o!==null)d=o;else{o!==null&&r.push("context_signal_store_stale"),d=Lo(t,n);try{await this.adapter.write(d)}catch{r.push("context_signal_store_write_failed")}}let c=new Map(d.items.map(l=>[l.id,l.signals])),u=we(t,n);return{snapshot:d,candidates:u.map(l=>({...l,signals:{...l.signals,...c.get(l.id)}})),cache_status:a?"fresh":"rebuilt",warnings:r}}};function Uo(e){let t=$o("sha256");for(let n of[...e].sort((r,o)=>r.id.localeCompare(o.id)))t.update(JSON.stringify([n.id,n.updated_at,n.status,n.parent??null,n.priority??null,n.risk??null,(n.dependencies??[]).map(r=>r.id).sort(),n.comments?.length??0,n.notes?.length??0,n.learnings?.length??0,n.test_runs?.length??0]));return`scan:${t.digest("hex")}`}async function Se(e,t){let n=t.sourceCursor!==void 0,r=t.source!==void 0;if(n!==r)throw new TypeError("Context signal source and source cursor must be provided together");if(t.storeKey!==void 0&&!/^[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?$/u.test(t.storeKey))throw new TypeError("Context signal store key must be a filesystem-safe identifier");let o=n?null:await fe(t.pmRoot),i=t.sourceCursor??o?.source_cursor??Uo(e),s=t.source??(o===null?"scan_fallback":"derived_index");return new Je(new Ke(Q.join(t.pmRoot,"runtime",t.storeKey?`context-signals-${t.storeKey}.json`:"context-signals.json"))).readOrRebuild(e,{...t,sourceCursor:i,source:s})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a19662f9-f8b3-5988-bc04-1b5a5edaaaa5")}catch{}})();function Po(e){for(let t of e.patch){if(t.path==="/metadata/status"||t.path==="/front_matter/status"){if(typeof t.value=="string")return t.value.trim().toLowerCase();continue}if(t.path!==""||typeof t.value!="object")continue;let n=t.value,r=n.metadata??n.front_matter;if(typeof r?.status=="string")return r.status.trim().toLowerCase()}}function jo(e,t,n){let r,o;for(let i of t){let s=Po(i);if(s===void 0)continue;let a=n.has(s)&&(r!==void 0&&!n.has(r)||r===void 0&&i.op==="create");r=s,a&&Number.isFinite(Date.parse(i.ts))&&(o={id:e,completed_at:i.ts,history_op:i.op})}return o}function gn(e){return e.completed_at!==void 0?{resolved:!0,timestamp:e.completed_at,source:"completed_at",fallback:!1}:e.closed_at!==void 0?{resolved:!0,timestamp:e.closed_at,source:"closed_at",fallback:!0}:e.updated_at!==void 0?{resolved:!0,timestamp:e.updated_at,source:"updated_at",fallback:!0}:{resolved:!1}}function ba(e,t,n){let r=[];for(let o of e){if(o.completed_at!==void 0||!n.has(o.status.trim().toLowerCase()))continue;let i=jo(o.id,t.get(o.id)??[],n);i!==void 0&&r.push(i)}return r.sort((o,i)=>o.id.localeCompare(i.id))}import Bo from"node:path";import{createHash as zo}from"node:crypto";import Go 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]="2e225010-1b53-59e9-8188-dcbe4a4f7eb7")}catch{}})();var hn=1,Wo=1e4,yn=12;function Ho(e){let t=new Date(e);return`${t.getUTCFullYear()}-Q${Math.floor(t.getUTCMonth()/3)+1}`}function Xo(e,t){let n=new Set,r=e.parent;for(;r&&!n.has(r);){n.add(r);let o=t.get(r);if(!o)return;if(o.type.toLowerCase()==="epic")return o;r=o.parent}}function qo(e){let t=[...e.items].sort((o,i)=>i.completion.timestamp.localeCompare(o.completion.timestamp)||o.item.id.localeCompare(i.item.id)),n=new Set,r=0;for(let{item:o}of t){let i=o.resolution??o.close_reason;i?.trim()&&n.add(i.trim()),r+=(o.notes?.length??0)+(o.learnings?.length??0)}return{kind:e.kind,key:e.key,label:e.label,item_count:t.length,first_closed_at:t.at(-1).completion.timestamp,last_closed_at:t[0].completion.timestamp,representative_items:t.slice(0,5).map(({item:{id:o,title:i}})=>({id:o,title:i})),outcomes:[...n].sort().slice(0,5),knowledge_entries:r}}function Yo(e,t){if(!t.sourceCursor.trim())throw new TypeError("Workspace memory source cursor must be non-empty");if(!Number.isFinite(Date.parse(t.now)))throw new TypeError("Workspace memory clock must be a valid timestamp");let n=e.filter(i=>t.statusRegistry.terminal_done_statuses.has(C(i.status,t.statusRegistry))).map(i=>{let s=gn(i);if(!s.resolved)throw new TypeError(`Completed item ${i.id} has no reporting timestamp`);return{item:i,completion:s}}),r=new Map(e.map(i=>[i.id,i])),o=new Map;for(let i of n){let{item:s,completion:a}=i,d=Ho(a.timestamp),c=`epoch:${d}`,u=o.get(c)??{kind:"epoch",key:d,label:d,items:[]};u.items.push(i),o.set(c,u);let l=Xo(s,r);if(l){let p=`epic:${l.id}`,g=o.get(p)??{kind:"epic",key:l.id,label:l.title,items:[]};g.items.push(i),o.set(p,g)}}return{format_version:hn,source_cursor:t.sourceCursor,source_item_count:e.length,generated_at:t.now,completion_time_sources:n.reduce((i,{completion:s})=>(i[s.source]+=1,i),{completed_at:0,closed_at:0,updated_at:0}),rollups:[...o.values()].map(qo).sort((i,s)=>s.last_closed_at.localeCompare(i.last_closed_at)||i.kind.localeCompare(s.kind)||i.key.localeCompare(s.key))}}function Vo(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"&&e.id.length>0&&"title"in e&&typeof e.title=="string"}function Ko(e){if(typeof e!="object"||e===null)return!1;let t=e,n=[t.key,t.label].every(o=>typeof o=="string"&&o.length>0),r=[t.first_closed_at,t.last_closed_at].every(o=>typeof o=="string"&&Number.isFinite(Date.parse(o)));return(t.kind==="epoch"||t.kind==="epic")&&n&&Number.isSafeInteger(t.item_count)&&t.item_count>0&&r&&Array.isArray(t.representative_items)&&t.representative_items.every(Vo)&&Array.isArray(t.outcomes)&&t.outcomes.every(o=>typeof o=="string")&&Number.isSafeInteger(t.knowledge_entries)&&t.knowledge_entries>=0}function Jo(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;let t=e;return t.format_version!==hn||typeof t.source_cursor!="string"||!t.source_cursor.trim()||!Number.isSafeInteger(t.source_item_count)||t.source_item_count<0||typeof t.generated_at!="string"||!Number.isFinite(Date.parse(t.generated_at))||!Array.isArray(t.rollups)?null:t.rollups.every(Ko)?t:null}function Zo(e){return`scan:${zo("sha256").update(pt(e.map(t=>[t.id,t.updated_at,t.status,t.parent]).sort(([t],[n])=>String(t).localeCompare(String(n))))).digest("hex")}`}async function Qo(e,t,n){return n!==void 0?n:(await fe(t))?.source_cursor??Zo(e)}async function ei(e){try{let t=Jo(JSON.parse(await Go.readFile(e,"utf8")));return{snapshot:t,invalid:t===null}}catch(t){return{snapshot:null,invalid:!(typeof t=="object"&&t!==null&&"code"in t&&t.code==="ENOENT")}}}async function _n(e,t){let n=Math.max(1,Math.floor(t.minimumItems??Wo));if(e.length<n)return{snapshot:null,cache_status:"skipped",warnings:[]};let r=await Qo(e,t.pmRoot,t.sourceCursor),o=Bo.join(t.pmRoot,"runtime","workspace-memory.json"),i=[],s=await ei(o),a=s.snapshot;if(s.invalid&&i.push("workspace_memory_invalid"),a?.source_cursor===r&&a.source_item_count===e.length)return{snapshot:a,cache_status:"fresh",warnings:i};a&&i.push("workspace_memory_stale");let d=Yo(e,{statusRegistry:t.statusRegistry,sourceCursor:r,now:t.now});try{await lt(o,`${JSON.stringify(d)}
|
|
10
|
-
`)}catch{i.push("workspace_memory_write_failed")}return{snapshot:d,cache_status:"rebuilt",warnings:i}}function ti(e,t,n=yn){let r=Math.max(0,Math.floor(t)),o=0,i=[];for(let s of e.rollups){if(i.length>=Math.max(0,Math.floor(n)))break;let a=Math.ceil(JSON.stringify(s).length/4);o+a>r||(i.push(s),o+=a)}return i}function wn(e,t,n=yn){if(e.snapshot===null)return;let r=ti(e.snapshot,t,n);if(r.length!==0)return{cache_status:e.cache_status==="fresh"?"fresh":"rebuilt",source_cursor:e.snapshot.source_cursor,...e.snapshot.completion_time_sources?{completion_time_sources:{...e.snapshot.completion_time_sources}}:{},rollups:r}}function ni(e,t,n=5){if(e===null)return[];let r=t.trim().toLowerCase().split(/\s+/u).filter(Boolean);return r.length===0?[]:e.rollups.map(o=>({rollup:o,score:r.filter(i=>[o.key,o.label,...o.outcomes,...o.representative_items.flatMap(s=>[s.id,s.title])].join(" ").toLowerCase().includes(i)).length})).filter(({score:o})=>o>0).sort((o,i)=>i.score-o.score||i.rollup.last_closed_at.localeCompare(o.rollup.last_closed_at)||o.rollup.key.localeCompare(i.rollup.key)).slice(0,Math.max(0,Math.floor(n))).map(({rollup:o})=>o)}function Na(e,t,n=5){let r=ni(e.snapshot,t,n);if(r.length!==0)return{cache_status:e.cache_status==="fresh"?"fresh":"rebuilt",matches:r}}(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]="dbcd4e0e-3fa0-5ce9-8bbc-6de05779d729")}catch{}})();var ri=["markdown","toon","json","ndjson"],te=new Set(["Epic","Feature"]),xn=10,En=1e4,Tn=["hierarchy","activity","progress","recently_created","unparented","workload"],oi=[...Tn,"blockers","files","staleness","tests"],ii=/^(\d{4})-(\d{2})-(\d{2})/,si=/^(\d{4})(\d{2})(\d{2})(?:[T ]?\d{2}|$)/,ai=/^(\d{4})(\d{2})(\d{2})$/,ci=/^(\d{4})(\d{2})(\d{2})(?:[T\s]?)(\d{2})(\d{2})(\d{2})?(Z|[+-]\d{2}:?\d{2})?$/i;function di(e){if(!e)return;let t=e.trim().toLowerCase();if(!ri.includes(t))throw new m("Context format must be one of markdown|toon|json|ndjson",f.USAGE);return t}var kn=new Set(["id","title","type","status","priority","order","deadline","assignee","tags","tags_inherited","updated_at","parent","children_total","children_closed","completion_pct","blocked","blocker_ids","created_at"]);function ui(e){if(e===void 0)return;let t=[];for(let n of e.split(",")){let r=n.trim().toLowerCase();if(r.length!==0){if(!kn.has(r))throw new m(`Context --fields value not projectable: ${r} (valid: ${[...kn].join(", ")})`,f.USAGE);t.includes(r)||t.push(r)}}if(t.length===0)throw new m("Context --fields requires at least one field name",f.USAGE);return t}function ee(e,t){return e.map(n=>{let r={},o=n;for(let i of t)r[i]=o[i]??null;return r})}function qa(e,t){let n=di(e.format);if(t.json&&n&&n!=="json"&&n!=="ndjson")throw new m("Cannot combine --json with --format markdown|toon",f.USAGE);return t.json?n==="ndjson"?"ndjson":"json":n??"toon"}function li(e,t){return L(e,"--limit")??(t==="full"?Number.MAX_SAFE_INTEGER:xn)}function et(e,t){if(e===void 0)return t;let n=typeof e=="number"?e:Number(e);if(!Number.isInteger(n)||n<1)throw new m("--token-budget must be a positive integer",f.USAGE);return n}function fi(e,t){return t>=En&&e===Number.MAX_SAFE_INTEGER?xn:e}function mi(e,t){if(!e)return t.default_depth;let n=e.trim().toLowerCase();if(!Oe.includes(n))throw new m(`Context --depth must be one of ${Oe.join("|")}`,f.USAGE);return n}function pi(e,t,n){if(e&&e.length>0){let o=[];for(let i of e){let s=i.trim().toLowerCase();if(!ce.includes(s))throw new m(`Context --section must be one of ${ce.join("|")}`,f.USAGE);o.includes(s)||o.push(s)}return o}return t==="brief"?[]:t==="full"?[...ce]:(t==="deep"?oi:Tn).filter(o=>n.sections[o])}function gi(e,t){return e?L(e,"--activity-limit")??t.activity_limit:t.activity_limit}function hi(e,t){if(!e)return t.stale_threshold_days;let n=e.trim().toLowerCase(),r=/^(\d+)d?$/.exec(n);if(!r)throw new m("--stale-threshold must be a number of days (e.g. 7 or 7d)",f.USAGE);let o=parseInt(r[1],10);if(o<=0)throw new m("--stale-threshold must be positive",f.USAGE);return o}function bn(e,t){let n=C(e,t),r=v("in_progress",t),o=v("open",t),i=v("blocked",t),s=v("draft",t);return r&&n===r?0:o&&n===o?1:i&&n===i?2:s&&n===s?3:t.active_statuses.has(n)?4:t.blocked_statuses.has(n)?5:t.terminal_statuses.has(n)?7:6}function ne(e,t){let n=v("closed",t);return C(e,t)===n}function tt(e,t){let n=v("in_progress",t);return C(e,t)===n}function In(e,t){let n=v("open",t);return C(e,t)===n}function yi(e,t){return t.blocked_statuses.has(C(e,t))}var _i=["compact","brief","fields","includeBody","include_body","parent"];function wi(e){let t={...e};for(let n of _i)delete t[n];return t}function nt(e,t){let n=t.trim().toLowerCase(),r=e.find(a=>a.id.trim().toLowerCase()===n);if(!r)return{ids:new Set,found:!1};let o=q(e),i=re(r.id,o);return{ids:new Set([r.id,...i.map(a=>a.id)].map(a=>a.trim().toLowerCase())),found:!0}}function ki(e){if(e===void 0)return;let t=e.trim();if(t.length===0)throw new m("Context --parent requires an item id",f.USAGE);return t}function bi(e,t){let n=e??null,r=t??null;return n===null&&r===null?0:n===null?1:r===null?-1:n-r}function vi(e,t){let n=e??null,r=t??null;return n===null&&r===null?0:n===null?1:r===null?-1:b(n,r)}function Ci(e,t){return new Date(Date.UTC(e,t+1,0)).getUTCDate()}function Si(e){let t=ii.exec(e)??si.exec(e);if(!t)return!0;let n=Number.parseInt(t[1],10),r=Number.parseInt(t[2],10),o=Number.parseInt(t[3],10);return r>=1&&r<=12&&o>=1&&o<=Ci(n,r-1)}function xi(e){let t=ai.exec(e);if(t)return`${t[1]}-${t[2]}-${t[3]}`;let n=ci.exec(e);if(n){let[,r,o,i,s,a,d,c]=n,u=d?`:${d}`:"",l=c&&c.length===5&&c!=="Z"?`${c.slice(0,3)}:${c.slice(3)}`:c??"";return`${r}-${o}-${i}T${s}:${a}${u}${l}`}return e}function $n(e){if(typeof e!="string")return Number.NaN;let t=e.trim();if(t.length===0||!Si(t))return Number.NaN;let n=Date.parse(xi(t));return Number.isFinite(n)?n:Number.NaN}function Qe(e){let t=$n(e);return Number.isFinite(t)?new Date(t).toISOString():""}function Ei(e){let t=$n(e);return Number.isFinite(t)?new Date(t).toISOString().slice(0,10):"unknown"}function rt(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function U(e,t,n){let r=bn(e.status,n)-bn(t.status,n);if(r!==0)return r;let o=e.priority-t.priority;if(o!==0)return o;let i=bi(e.order,t.order);if(i!==0)return i;let s=vi(e.deadline,t.deadline);if(s!==0)return s;let a=b(Qe(t.updated_at),Qe(e.updated_at)),d=e.id.localeCompare(t.id);return a!==0?a:d}function Ze(e){return Math.max(1,Math.ceil(Buffer.byteLength(JSON.stringify(e),"utf8")/4))}function ot(e,t,n=new Set,r="context"){return rn(e.ranked.map(o=>({id:o.id,item:o.item,rank:o.rank,score:o.score,required:n.has(o.id),cluster:o.item.parent?.trim()||o.item.type,token_costs:{identity:Ze({id:o.id,title:o.item.title}),summary:Ze({id:o.id,title:o.item.title,type:o.item.type,status:o.item.status,priority:o.item.priority,parent:o.item.parent}),full:Ze(o.item)}})),{tokenBudget:t,profile:r,latencyBudgetMs:25})}function it(e){return{...e,included:e.included.map(t=>({id:t.id,projection:t.projection,tokens:t.tokens}))}}function st(e,t){return{model:e.model,available_signals:e.available_signals,items:e.ranked.map(n=>({id:n.id,rank:n.rank,baseline_rank:n.baseline_rank,score:n.score,contributions:n.contributions})),...t?{feature_store:{source:t.snapshot.source,cache_status:t.cache_status,source_cursor:t.snapshot.source_cursor,generated_at:t.snapshot.generated_at}}:{}}}function Dn(e,t){return t>0?Math.round(e/t*100):0}function q(e){let t=new Map;for(let n of e){let r=rt(n.parent);if(!r)continue;let o=t.get(r)??[];o.push(n),t.set(r,o)}return t}function oe(e,t,n){let r={id:e.id,title:e.title,type:e.type,status:e.status,priority:e.priority,order:e.order??null,deadline:e.deadline??null,assignee:e.assignee??null,tags:Array.isArray(e.tags)?[...e.tags]:[],updated_at:e.updated_at,parent:rt(e.parent)};if(t&&n){let o=re(e.id,n),i=o.length;if(i>0){let s=o.filter(a=>ne(a.status,t)).length;r.children_total=i,r.children_closed=s,r.completion_pct=Dn(s,i)}}return r}function Ti(e){let t=0,n=0,r=0,o=new Set;for(let i of e){if(o.add(i.item_id),i.kind==="deadline"){t+=1;continue}if(i.kind==="reminder"){n+=1;continue}r+=1}return{events:e.length,items:o.size,deadlines:t,reminders:n,scheduled:r}}function xe(...e){return[...new Set(e.flatMap(t=>t??[]))].sort((t,n)=>t.localeCompare(n))}function Ii(e,t){return e.filter(n=>!t.terminal_statuses.has(C(n.item_status,t)))}function $i(e,t,n,r){let o=new Map;for(let d of e)o.set(d.id,d);let i=q(e),s=new Set(t.filter(d=>te.has(d.type)).map(d=>d.id)),a=[];for(let d of s){let c=o.get(d);if(!c)continue;let u=re(d,i),l=i.get(d)??[],p=0,g=0,w=0,h=0;for(let _ of u)ne(_.status,n)?p++:tt(_.status,n)?w++:yi(_.status,n)?h++:In(_.status,n)&&g++;let S=l.sort((_,k)=>U(_,k,n)).slice(0,r).map(_=>{let k=re(_.id,i),x=k.filter($=>ne($.status,n)).length;return{id:_.id,title:_.title,type:_.type,status:_.status,children_total:k.length,children_closed:x}});a.push({id:c.id,title:c.title,type:c.type,status:c.status,children_total:u.length,children_closed:p,children_open:g,children_in_progress:w,children_blocked:h,children:S})}return a.sort((d,c)=>{let u=o.get(d.id),l=o.get(c.id);return U(u,l,n)}).slice(0,r)}function re(e,t){let n=[],r=[e],o=new Set;for(;r.length>0;){let i=r.pop();if(o.has(i))continue;o.add(i);let s=t.get(i)??[];for(let a of s)n.push(a),r.push(a.id)}return n}async function Di(e,t){return(await zt({compact:!0,limit:String(e)},t)).compact_activity??[]}function Ni(e,t,n,r,o){let i=new Map;for(let d of e){if(!d.parent)continue;let c=i.get(d.parent)??[];c.push(d),i.set(d.parent,c)}let s=t.filter(d=>te.has(d.type)),a=[];for(let d of s){let c=re(d.id,i),u=c.length;if(u===0)continue;let l=0,p=0,g=0,w=0;for(let h of c)ne(h.status,r)?l++:n.has(h.id.trim().toLowerCase())?w++:tt(h.status,r)?g++:In(h.status,r)&&p++;a.push({id:d.id,title:d.title,type:d.type,total:u,closed:l,open:p,in_progress:g,blocked:w,completion_pct:Dn(l,u)})}return a.sort((d,c)=>d.completion_pct-c.completion_pct).slice(0,o)}function Ai(e,t,n,r){let o=new Map(t.map(i=>[i.id.trim().toLowerCase(),i]));return e.slice(0,r).map(i=>{let s=Fe(i,o,n),a=s.find(c=>!c.resolved)?.id??s[0]?.id??null,d=a?o.get(a.trim().toLowerCase()):void 0;return{id:i.id,title:i.title,blocked_by:a,blocked_by_title:d?.title??null,blocked_by_status:d?.status??null,blocked_reason:i.blocked_reason??null,unblock_note:i.unblock_note??null}})}function Oi(e,t){let n=new Map;for(let r of e)for(let o of r.files??[]){let i=n.get(o.path)??new Set;i.add(r.id),n.set(o.path,i)}return[...n.entries()].map(([r,o])=>({path:r,references:o.size,items:[...o].sort()})).sort((r,o)=>o.references-r.references).slice(0,t)}function Mi(e,t,n){let r=new Map;for(let o of e){let i=o.assignee??null,s=r.get(i)??[];s.push(o),r.set(i,s)}return[...r.entries()].map(([o,i])=>({assignee:o,active:i.length,in_progress:i.filter(s=>tt(s.status,t)).length,items:i.map(s=>s.id).sort()})).sort((o,i)=>i.active-o.active).slice(0,n)}function Fi(e,t,n,r){let o=new Date(n).getTime()-t*24*60*60*1e3;return e.filter(i=>new Date(i.updated_at).getTime()<o).map(i=>({id:i.id,title:i.title,status:i.status,updated_at:i.updated_at,stale_days:Math.floor((new Date(n).getTime()-new Date(i.updated_at).getTime())/(1440*60*1e3))})).sort((i,s)=>s.stale_days-i.stale_days).slice(0,r)}function Ri(e,t,n,r){return e.map(o=>({item:o,sortKey:Qe(o.created_at)})).sort((o,i)=>{let s=b(i.sortKey,o.sortKey);return s!==0?s:o.item.id.localeCompare(i.item.id)}).slice(0,r).map(({item:o})=>({...oe(o,t,n),created_at:o.created_at}))}function Li(e,t,n,r){return e.filter(o=>!rt(o.parent)&&!te.has(o.type)).sort((o,i)=>U(o,i,t)).slice(0,r).map(o=>oe(o,t,n))}function Ui(e){let t=0,n=0,r=0,o=0,i=0,s=[];for(let a of e){(a.tests??[]).length>0&&t++;let d=a.test_runs??[];if(d.length>0){n++;let c=!1;for(let u of d)r+=u.passed??0,o+=u.failed??0,i+=u.skipped??0,(u.failed??0)>0&&(c=!0);c&&s.push(a.id)}}return{items_with_tests:t,items_with_recent_runs:n,recent_runs:{passed:r,failed:o,skipped:i},items_failing:s.sort()}}function vn(e){return`${new Date(e).toISOString().slice(11,16)}Z`}function Nn(e){let t=e.order===null?"-":String(e.order),n=e.deadline??"-",r=e.parent?` parent:${e.parent}`:"",o=e.children_total!==void 0&&e.children_closed!==void 0&&e.completion_pct!==void 0?` children:${e.children_closed}/${e.children_total} done:${e.completion_pct}%`:"",i=e.blocked===!0?` blocked:${e.blocker_ids?.join(",")||"lifecycle"}`:"";return`${e.id} p${e.priority} ${e.status} ${e.type} order:${t} deadline:${n}${r}${o}${i} ${e.title}`}function Pi(e,t){let n=e;return t.map(r=>{let o=n[r];return Array.isArray(o)?`${r}:${o.join(",")}`:`${r}:${o??"-"}`}).join(" ")}function ji(e){if("reference_only"in e){let n=e.kind==="reminder"?` \u2014 ${e.reminder_text??"reminder"}`:e.kind==="event"?` \u2014 ${e.event_title??"event"}${e.event_recurring?" (recurring)":""}`:"";return`${vn(e.at)} [${e.kind}] ${e.item_id} (see focus item)${n}`}let t=`${vn(e.at)} [${e.kind}] ${e.item_id} p${e.item_priority} ${e.item_status} ${e.item_title}`;if(e.kind==="reminder")return`${t} \u2014 ${e.reminder_text}`;if(e.kind==="event"){let n=e.event_recurring?" (recurring)":"",r=e.event_title??e.item_title;return`${t} \u2014 ${r}${n}`}return t}function Cn(e,t,n,r,o){if(e.push(`## ${t}`),n.length===0)e.push(r);else for(let i of n)e.push(`- ${o(i)}`);e.push("")}function Bi(e,t,n){if(t.blocked_fallback.length!==0){e.push("## Blocked fallback");for(let r of t.blocked_fallback)e.push(`- ${n(r)}`);e.push("")}}function zi(e,t){if(e.push("## Agenda"),e.push(`- events: ${t.agenda.summary.events} (deadlines: ${t.agenda.summary.deadlines}, reminders: ${t.agenda.summary.reminders}, scheduled: ${t.agenda.summary.scheduled})`),t.agenda.events.length===0)e.push("No agenda events matched the selected filters.");else for(let n of t.agenda.events)e.push(`- ${ji(n)}`);e.push("")}function Gi(e,t){if(!(!t.hierarchy||t.hierarchy.length===0)){e.push("## Hierarchy");for(let n of t.hierarchy){let r=n.children_total>0?Math.round(n.children_closed/n.children_total*100):0;e.push(`- ${n.id} ${n.type} ${n.status} "${n.title}" [${n.children_closed}/${n.children_total} done ${r}%]`);for(let o of n.children){let i=o.children_total>0?Math.round(o.children_closed/o.children_total*100):0;e.push(` - ${o.id} ${o.type} ${o.status} "${o.title}" [${o.children_closed}/${o.children_total} done ${i}%]`)}}e.push("")}}function Wi(e,t){if(!(!t.progress||t.progress.length===0)){e.push("## Progress");for(let n of t.progress)e.push(`- ${n.id} "${n.title}" ${n.completion_pct}% (${n.closed}/${n.total} closed, ${n.in_progress} wip, ${n.open} open, ${n.blocked} blocked)`);e.push("")}}function Hi(e,t,n,r){if(!(!t.recently_created||t.recently_created.length===0)){e.push("## Recently created");for(let o of t.recently_created)e.push(n?`- ${r(o)}`:`- ${Ei(o.created_at)} ${Nn(o)}`);e.push("")}}function Xi(e,t,n){if(!(!t.unparented||t.unparented.length===0)){e.push("## Unparented");for(let r of t.unparented)e.push(`- ${n(r)}`);e.push("")}}function qi(e,t){if(!(!t.activity||t.activity.length===0)){e.push("## Recent activity");for(let n of t.activity){let r=n.msg?` ${n.msg}`:"";e.push(`- ${n.ts.slice(0,16)}Z ${n.id} ${n.op} by:${n.author}${r}`)}e.push("")}}function Yi(e,t){if(!(!t.blockers||t.blockers.length===0)){e.push("## Blockers");for(let n of t.blockers){let r=n.blocked_by?`blocked_by:${n.blocked_by}(${n.blocked_by_status??"?"})`:"blocked_by:-",o=n.blocked_reason?` reason:"${n.blocked_reason}"`:"",i=n.unblock_note?` unblock:"${n.unblock_note}"`:"";e.push(`- ${n.id} "${n.title}" ${r}${o}${i}`)}e.push("")}}function Vi(e,t){if(!(!t.files||t.files.length===0)){e.push("## Hot files");for(let n of t.files)e.push(`- ${n.path} refs:${n.references} items:[${n.items.join(",")}]`);e.push("")}}function Ki(e,t){if(!(!t.workload||t.workload.length===0)){e.push("## Workload");for(let n of t.workload){let r=n.assignee??"(unassigned)";e.push(`- ${r} active:${n.active} wip:${n.in_progress} items:[${n.items.join(",")}]`)}e.push("")}}function Ji(e,t){if(!(!t.staleness||t.staleness.length===0)){e.push("## Stale items");for(let n of t.staleness)e.push(`- ${n.id} ${n.status} stale:${n.stale_days}d last:${n.updated_at.slice(0,10)} "${n.title}"`);e.push("")}}function Zi(e,t){t.tests&&(e.push("## Test health"),e.push(`- items_with_tests: ${t.tests.items_with_tests}`),e.push(`- items_with_recent_runs: ${t.tests.items_with_recent_runs}`),e.push(`- passed: ${t.tests.recent_runs.passed}, failed: ${t.tests.recent_runs.failed}, skipped: ${t.tests.recent_runs.skipped}`),t.tests.items_failing.length>0&&e.push(`- items_failing: [${t.tests.items_failing.join(",")}]`),e.push(""))}function Qi(e,t){t.summary.active_items===0&&t.summary.blocked===0&&t.agenda.summary.events===0&&(e.push("## Suggestions"),e.push("No active work items or upcoming events. Consider:"),e.push('- `pm create --type Task --title "..."` to add a new work item'),e.push("- `pm list --status closed --limit 5` to review recent completions"),e.push("- `pm search <keywords>` to find related past work"),e.push("- `pm aggregate` for a full project status overview"))}function Ya(e){let t=[],n=e.focus_fields,r=i=>n?Pi(i,n):Nn(i);if(t.push("# pm context"),t.push(""),t.push(`- now: ${e.now}`),t.push(`- depth: ${e.depth}`),e.filters.parent&&t.push(`- scope: subtree of ${e.filters.parent}`),t.push(`- active_items: ${e.summary.active_items} (in_progress: ${e.summary.in_progress}, open: ${e.summary.open})`),e.summary.total_items!==void 0&&t.push(`- total_items: ${e.summary.total_items} (closed: ${e.summary.closed??0}, canceled: ${e.summary.canceled??0})`),t.push(`- agenda_events: ${e.summary.agenda_events}`),t.push(`- blocked_fallback_used: ${e.summary.blocked_fallback_used}`),e.extension_health){let i=e.extension_health.packages.filter(s=>s.status==="degraded").map(s=>s.name);t.push(`- extensions: ${e.extension_health.ok} ok, ${e.extension_health.degraded} degraded${i.length>0?` (${i.join(", ")})`:""}`)}let o=e.sections_included.filter(i=>i!=="blockers"||(e.blockers?.length??0)>0);if(o.length>0&&t.push(`- sections: ${o.join(", ")}`),t.push(""),Cn(t,"High-level focus",e.high_level,"No high-level active items.",r),Cn(t,"Low-level focus",e.low_level,"No low-level active items.",r),Bi(t,e,r),zi(t,e),e.workspace_memory){t.push("## Workspace memory");for(let i of e.workspace_memory.rollups)t.push(`- ${i.kind}:${i.key} \u2014 ${i.label} (${i.item_count} completed, latest ${i.last_closed_at})`);t.push("")}return Gi(t,e),Wi(t,e),Hi(t,e,n,r),Xi(t,e,r),qi(t,e),Yi(t,e),Vi(t,e),Ki(t,e),Ji(t,e),Zi(t,e),Qi(t,e),t.join(`
|
|
11
|
-
`)}async function es(e,t){let n=N(process.cwd(),t.path),r=await M(n),o=r.context??ft.context,i=H(r.schema),s=mi(e.depth,o),a=li(e.limit??e.maxItems,s);return{settings:r,contextSettings:o,statusRegistry:i,depth:s,limit:a,sectionsIncluded:pi(e.section,s,o),activityLimit:gi(e.activityLimit,o),staleThresholdDays:hi(e.staleThreshold,o),parentScope:ki(e.parent),focusFields:ui(e.fields),baseListOptions:wi(e)}}function at(e){return e.some(t=>["hierarchy","progress","blockers","staleness","recently_created","unparented"].includes(t))}function ts(e,t){return{...e,...t,noTruncate:!0,limit:void 0,offset:void 0,after:void 0}}async function ns(e,t){let n=at(t.sectionsIncluded),r=await V(void 0,ts(t.baseListOptions,{excludeTerminal:!1}),e),o=r.items,i=o.filter(d=>!Me(d.status,t.statusRegistry)),s=n||t.parentScope!==void 0?o:i,a=rs(t.parentScope,o);return a&&(i=i.filter(d=>a.has(d.id.trim().toLowerCase())),s=s.filter(d=>a.has(d.id.trim().toLowerCase()))),{listed:r,listedItemMetadata:i,allItems:s,fullCorpus:o,subtreeIds:a}}function rs(e,t){if(e===void 0)return;let n=nt(t,e);if(!n.found)throw new m(`Context --parent item not found: ${e}`,f.NOT_FOUND);return n.ids}async function os(e,t,n,r,o,i,s,a,d,c,u,l,p,g){let w=[...e].sort((y,z)=>U(y,z,o)),h=await ve({pmRoot:p,author:d,enabled:process.env.PM_CONTEXT_USAGE_DISABLED!=="1"}),S=await Se(w,{pmRoot:p,storeKey:"context",statusRegistry:o,now:a,author:d,usageAffinity:h.affinity}),_=await ke("context",S.candidates),k=_.ranked.map(y=>y.item),x=o.active_statuses,$=k.filter(y=>x.has(C(y.status,o))),P=l?St($,c,u,y=>y.id):0,E=l?$.slice(P,P+s):$,ie=l&&E.length>0&&P+E.length<$.length,se=ie&&E.length>0?Ct(u,E[E.length-1].id,P+E.length-1):void 0,Ie=k.filter(y=>r.has(y.id.trim().toLowerCase())),$e=new Set([...E.map(y=>y.id),...Ie.slice(0,s).map(y=>y.id)]),F=ot({..._,ranked:_.ranked.filter(y=>$e.has(y.id))},g),j=F.included.map(y=>y.item),R=j.filter(y=>x.has(C(y.status,o))),B=j.filter(y=>r.has(y.id.trim().toLowerCase())),De=q(t),Ne=at(i)?De:void 0,D=new Map(n.map(y=>[y.id.trim().toLowerCase(),y])),T=y=>{let z=oe(y,o,Ne);return r.has(y.id.trim().toLowerCase())&&(z.blocked=!0,z.blocker_ids=Fe(y,D,o).filter(Ae=>!Ae.resolved).map(Ae=>Ae.id)),z},Rn=R.filter(y=>te.has(y.type)).slice(0,l?E.length:s).map(T),Ln=R.filter(y=>!te.has(y.type)).slice(0,l?E.length:s).map(T),ut=$.length===0;return{activeItems:R,blockedItems:B,highLevel:Rn,lowLevel:Ln,blockedFallback:ut?B.slice(0,s).map(T):[],blockedFallbackUsed:ut,ranking:_,packing:F,featureStore:S,pageExtras:{...l?{applied_limit:s}:{},...ie?{has_more:!0,truncated:!0}:{},...se?{next_cursor:se}:{}}}}function is(e){return vt("context",bt(e,Dt))}function ss(e,t){return e.limit!==void 0||e.maxItems!==void 0||e.after!==void 0||t>=En}async function as(e,t,n,r){let o={...t.baseListOptions,view:"agenda",include:"all",limit:t.parentScope===void 0?String(t.limit):void 0},i=await Qt(o,e),s=n===void 0?i.events:i.events.filter(c=>n.has(c.item_id.trim().toLowerCase())),a=Ii(s,t.statusRegistry).slice(0,t.limit),d=a.map(c=>r.has(c.item_id)?{at:c.at,date:c.date,kind:c.kind,item_id:c.item_id,reference_only:!0,...c.kind==="reminder"?{reminder_text:c.reminder_text}:{},...c.kind==="event"?{event_title:c.event_title,event_recurring:c.event_recurring}:{}}:c);return{agenda:i,agendaEvents:d,agendaSummary:Ti(a)}}function Sn(e,t,n){let r=String(t);return e.filter(o=>C(o.status,n)===r).length}async function cs(e){let{runtime:t,allItems:n,fullCorpus:r,blockedIds:o,focusGroups:i,now:s,global:a}=e,d=q(n),c=n.filter(l=>!Me(l.status,t.statusRegistry)),u=l=>t.sectionsIncluded.includes(l);return{hierarchy:u("hierarchy")?$i(n,i.activeItems,t.statusRegistry,t.limit):void 0,activity:u("activity")?await Di(t.activityLimit,a):void 0,progress:u("progress")?Ni(n,i.activeItems,o,t.statusRegistry,t.limit):void 0,blockersSection:u("blockers")?Ai(i.blockedItems,r,t.statusRegistry,t.limit):void 0,recentlyCreated:u("recently_created")?Ri(c,t.statusRegistry,d,t.limit):void 0,unparented:u("unparented")?Li(c,t.statusRegistry,d,t.limit):void 0,filesSection:u("files")?Oi(i.activeItems,t.limit):void 0,workload:u("workload")?Mi(i.activeItems,t.statusRegistry,t.limit):void 0,staleness:u("staleness")?Fi(c,t.staleThresholdDays,s,t.limit):void 0,tests:u("tests")?Ui(i.activeItems):void 0}}function ds(e,t,n){if(!e)return{};let r=v("canceled",n);return{total_items:t.length,closed:t.filter(o=>ne(o.status,n)).length,canceled:t.filter(o=>C(o.status,n)===r).length}}function us(e,t){t.hierarchy&&(e.hierarchy=t.hierarchy),t.activity&&(e.activity=t.activity),t.progress&&(e.progress=t.progress),t.blockersSection&&(e.blockers=t.blockersSection),t.recentlyCreated&&(e.recently_created=t.recentlyCreated),t.unparented&&(e.unparented=t.unparented),t.filesSection&&(e.files=t.filesSection),t.workload&&(e.workload=t.workload),t.staleness&&(e.staleness=t.staleness),t.tests&&(e.tests=t.tests)}function ls(e,t){t&&(e.focus_fields=t,e.high_level=ee(e.high_level,t),e.low_level=ee(e.low_level,t),e.blocked_fallback=ee(e.blocked_fallback,t),e.recently_created&&(e.recently_created=ee(e.recently_created,t)),e.unparented&&(e.unparented=ee(e.unparented,t)))}function fs(e,t){let n=[e.high_level,e.low_level,e.blocked_fallback,e.recently_created??[],e.unparented??[]].flat();if(t){for(let i of n)delete i.tags,delete i.tags_inherited;return}let r=new Map(n.map(i=>[i.id,i])),o=new Map(n.map(i=>[i.id,i.tags?[...i.tags].sort().join("\0"):void 0]));for(let i of n){if(!i.parent||!i.tags)continue;let s=r.get(i.parent);s&&o.get(i.id)===o.get(s.id)&&(delete i.tags,i.tags_inherited=s.id)}}function ms(e,t,n){t.length>0||n.length>0||e.agenda.events.length>0||(e.suggestions=['pm create --type Task --title "..." to add a new work item',"pm list --status closed --limit 5 to review recent completions","pm search <keywords> to find related past work","pm aggregate for a full project status overview"])}async function ps(e,t,n,r){try{let o=new Set(t.packing.included.map(i=>i.id));await be({pmRoot:n,author:r,surface:"context",profile:t.packing.profile,rows:t.ranking.ranked.map(i=>({id:i.id,rank:i.rank,included:o.has(i.id)})),enabled:process.env.PM_CONTEXT_USAGE_DISABLED!=="1"})}catch{e.warnings=xe(e.warnings,["context_usage_feedback_write_failed"])}}async function gs(e,t,n){if(e)return{};let o=(await gt({pmRoot:t,settings:n,cwd:process.cwd(),noExtensions:!1})).discovered.map(s=>({name:s.name??s.directory,status:s.status==="ok"?"ok":"degraded"})).sort((s,a)=>s.name.localeCompare(a.name)),i=o.filter(s=>s.status==="degraded").length;return o.length===0?{}:{extension_health:{total:o.length,ok:o.length-i,degraded:i,packages:o.slice(0,20),...o.length>20?{truncated:!0}:{}}}}async function Va(e,t){let n=N(process.cwd(),t.path),r=await es(e,t),o=await ns(t,r),i=fi(r.limit,o.fullCorpus.length),s={...r,limit:i,tokenBudget:et(e.tokenBudget,Math.max(256,i*160))},a=Y(void 0,s.settings.author_default),d=gs(e.noExtensionHealth===!0,n,s.settings),c=Mt(o.fullCorpus,s.statusRegistry),u=await os(o.listedItemMetadata,o.allItems,o.fullCorpus,c,s.statusRegistry,s.sectionsIncluded,s.limit,O(),a,e.after,is(e),ss(e,o.fullCorpus.length),n,s.tokenBudget),l=await as(t,s,o.subtreeIds,new Set([...u.highLevel,...u.lowLevel,...u.blockedFallback].map(x=>x.id))),p=await _n(o.fullCorpus,{pmRoot:n,statusRegistry:s.statusRegistry,now:l.agenda.now}),g=xe(o.listed.warnings,l.agenda.warnings,u.ranking.warnings,[...u.featureStore.warnings],p.warnings),w=Sn(u.activeItems,v("in_progress",s.statusRegistry),s.statusRegistry),h=Sn(u.activeItems,v("open",s.statusRegistry),s.statusRegistry),S=await cs({runtime:s,allItems:o.allItems,fullCorpus:o.fullCorpus,blockedIds:c,focusGroups:u,now:l.agenda.now,global:t}),_=ds(at(s.sectionsIncluded),o.allItems,s.statusRegistry),k={output_default:"toon",now:l.agenda.now,depth:s.depth,sections_included:s.sectionsIncluded,window:{anchor:l.agenda.anchor,start:l.agenda.range.start,end:l.agenda.range.end,past:l.agenda.range.past,from:l.agenda.range.from,to:l.agenda.range.to},filters:{type:e.type??null,tag:e.tag??null,priority:e.priority??null,assignee:e.assignee??null,assignee_filter:e.assigneeFilter??null,sprint:e.sprint??null,release:e.release??null,limit:e.limit??e.maxItems??null,parent:s.parentScope??null,token_budget:s.tokenBudget,runtime_filters:o.listed.filters.runtime_filters??l.agenda.filters.runtime_filters??{}},summary:{active_items:u.activeItems.length,in_progress:w,open:h,blocked:u.blockedItems.length,blocked_fallback_used:u.blockedFallbackUsed,high_level:u.highLevel.length,low_level:u.lowLevel.length,agenda_events:l.agendaSummary.events,..._},high_level:u.highLevel,low_level:u.lowLevel,blocked_fallback:u.blockedFallback,agenda:{summary:l.agendaSummary,events:l.agendaEvents},...u.pageExtras};return k.workspace_memory=wn(p,Math.min(800,Math.floor(s.tokenBudget*.2))),Object.assign(k,await d),us(k,S),fs(k,e.noTags===!0),e.explainRanking===!0&&(k.ranking=st(u.ranking,u.featureStore),k.packing=it(u.packing)),ls(k,s.focusFields),g.length>0&&(k.warnings=g),ms(k,u.activeItems,u.blockedItems),await ps(k,u,n,a),k}(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]="3431d4d4-e053-5416-b3d1-6dbfbed0142d")}catch{}})();var hs=["markdown","toon","json"],ys=5,_s=1440*60*1e3;function ws(e){if(!e)return;let t=e.trim().toLowerCase();if(!hs.includes(t))throw new m("Next format must be one of markdown|toon|json",f.USAGE);return t}function sc(e,t){let n=ws(e.format);if(t.json&&n&&n!=="json")throw new m("Cannot combine --json with --format markdown|toon",f.USAGE);return t.json?"json":n??"toon"}function An(e,t,n){let r=L(e,t);return r===void 0||r<=0?n:r}function ct(e,t,n,r){return{...oe(e.item,t,n),open_blocker_count:e.open_blockers.length,blockers:e.open_blockers.map(o=>({id:o.id,title:o.title,status:o.status})),unblocks:e.unblocks,rank:r}}function ks(e,t,n,r){let o=e.item,i=[],s=v("in_progress",t);return i.push(C(o.status,t)===s?"in progress \u2014 resume to finish":"open and ready to start"),r&&i.push("completed container \u2014 governance closeout"),i.push(`priority p${o.priority}${o.priority===0?" (highest)":""}`),typeof o.deadline=="string"&&o.deadline.trim().length>0&&i.push(vs(o.deadline,n)),i.push(Ot(o).length>0?"all blockers resolved":"no blockers"),typeof o.parent=="string"&&o.parent.trim().length>0&&i.push(`advances ${o.parent.trim()}`),e.unblocks.length>0&&i.push(`unblocks ${e.unblocks.length} item(s): ${e.unblocks.join(", ")}`),i}function Mn(e,t,n){let r=Y(n,t),o=[],i=[];for(let s of e){let a=typeof s.item.assignee=="string"?s.item.assignee.trim():"";a.length>0&&a!==r?i.push({id:s.item.id,assignee:a}):o.push(s)}return{available:o,held:i}}var ac={partitionCallerOwnedReady:Mn,resolveNextCallerAuthor:(e,t)=>Fn(e,t)};function bs(e,t){let n=e.filter(r=>r.item.type.trim().toLowerCase()==="decision");return{agent:t?e:e.filter(r=>r.item.type.trim().toLowerCase()!=="decision"),decisions:t?[]:n}}function vs(e,t){let n=Date.parse(e);if(!Number.isFinite(n))return`deadline ${e.trim()}`;let r=new Date(n).toISOString().slice(0,10),o=new Date(Date.parse(t)).toISOString().slice(0,10),i=Math.round((Date.parse(r)-Date.parse(o))/_s);return i<0?`deadline ${r} (overdue ${-i}d)`:i===0?`deadline ${r} (due today)`:`deadline ${r} (in ${i}d)`}function Cs(e,t){let n=v("in_progress",t);return e.filter(r=>C(r.status,t)===n).length}function dt(e,t){return(t.get(e.id.trim().toLowerCase())??[]).length>0}function Ss(e,t){return{type:e.type,tag:e.tag,priority:typeof e.priority=="number"?String(e.priority):e.priority,assignee:e.assignee,assigneeFilter:e.assigneeFilter,sprint:e.sprint,release:e.release,noTruncate:!0,...t}}function On(e,t,n){return[...e].sort((r,o)=>{let i=dt(r.item,t),s=dt(o.item,t);return i!==s?Number(i)-Number(s):U(r.item,o.item,n)})}function xs(e){return e.projectedReady.length===0?null:{...e.readyRows[0],reasons:ks(e.projectedReady[0],e.statusRegistry,e.now,e.completedContainer)}}function Es(e,t){if(e===null){if(t.length>0){let n=t.find(r=>r.blockers.length>0);return[n?`${t.length} item(s) are blocked; unblock the top one by closing ${n.blockers.map(r=>r.id).join(", ")}`:`${t.length} item(s) are blocked; add blocker context or move the top item back to an active status`,"pm next --ready-only after a blocker closes to re-check ready work",'pm create --type Task --title "..." to add new ready work']}return['pm create --type Task --title "..." to add a new work item',"pm list --status in_progress to review work already underway","pm context --depth deep for the full project snapshot"]}}function Ts(e,t,n){let r={};return e>n&&(r.decision_needed_total=e),t>n&&(r.held_by_others_total=t),Object.keys(r).length>0?r:void 0}async function Is(e){try{let t=new Set(e.packing.included.map(n=>n.id));await be({pmRoot:e.pmRoot,author:e.author,surface:"next",profile:e.packing.profile,rows:e.ranking.ranked.map(n=>({id:n.id,rank:n.rank,included:t.has(n.id)})),enabled:process.env.PM_CONTEXT_USAGE_DISABLED!=="1"})}catch{e.result.warnings=xe(e.result.warnings,["context_usage_feedback_write_failed"])}}async function $s(e){let t=[...new Set([...e.candidatesWarnings??[],...e.corpusWarnings??[],...e.readyRanking.warnings??[],...e.featureStore.warnings])].sort((n,r)=>n.localeCompare(r));return t.length>0&&(e.result.warnings=t),e.explainRanking&&(e.result.ranking=st(e.readyRanking,e.featureStore),e.result.packing=it(e.packing)),e.result.suggestions=Es(e.recommended,e.blockedRows),await Is({result:e.result,pmRoot:e.pmRoot,author:e.author,packing:e.packing,ranking:e.readyRanking}),e.result}function Ds(e,t,n){if(!n)return e;let r=nt(t,n);if(!r.found)throw new m(`Next --parent item not found: ${n}`,f.NOT_FOUND);return e.filter(o=>r.ids.has(o.id.trim().toLowerCase()))}async function Ns(e,t,n,r,o,i,s){let a=e.filter(h=>!dt(h.item,t)),d=a.length>0?a:e,c=await ve({pmRoot:i,author:o,enabled:process.env.PM_CONTEXT_USAGE_DISABLED!=="1"}),u=await Se(d.map(h=>h.item),{pmRoot:i,storeKey:"next",statusRegistry:n,now:r,author:o,usageAffinity:c.affinity}),l=await ke("next",u.candidates),p=ot(l,s,new Set,"next"),g=new Map(d.map(h=>[h.item.id,h]));return{projectedReady:l.ranked.map(h=>g.get(h.id)).filter(h=>h!==void 0),ranking:l,completedContainer:a.length===0,packing:p,featureStore:u}}function Fn(e,t){let n=e.assignee?.trim();return Y(e.callerAuthor??(n&&n.length>0?n:void 0),t)}async function cc(e,t){let n=N(process.cwd(),t.path),r=await M(n),o=Fn(e,r.author_default),i=H(r.schema),s=O(),a=An(e.limit,"--limit",ys),d=et(e.tokenBudget,Math.max(192,a*128)),c=An(e.blockedLimit,"--blocked-limit",a),u=e.readyOnly===!0,l=typeof e.parent=="string"?e.parent.trim():"",p=await V(void 0,Ss(e,{excludeTerminal:!0}),t),g=await V(void 0,{excludeTerminal:!1,noTruncate:!0},t),w=Ds(p.items,g.items,l),h=g.items,S=Ft(w,h,i),_=q(h),k=bs(S.ready,e.includeDecisions===!0),x=Mn(k.agent,r.author_default,o),$=On(x.available,_,i),P=[...S.blocked].sort((D,T)=>U(D.item,T.item,i)),{projectedReady:E,ranking:ie,completedContainer:se,packing:Ie,featureStore:$e}=await Ns($,_,i,s,o,n,d),F=E.map((D,T)=>ct(D,i,_,T+1)),j=P.map((D,T)=>ct(D,i,_,T+1)),R=On(k.decisions,_,i).map((D,T)=>ct(D,i,_,T+1)),B=xs({projectedReady:E,readyRows:F,statusRegistry:i,now:s,completedContainer:se}),De=Ts(R.length,x.held.length,a),Ne={output_default:"toon",now:s,recommended:B,ready:F.slice(1,a+1),decision_needed:R.slice(0,a),blocked:u?[]:j.slice(0,c),held_by_others:x.held.slice(0,a),summary:{recommended:B!==null,ready:F.length,blocked:j.length,in_progress:Cs(F,i),candidates:S.active_count,containers:S.container_count,decision_needed:R.length,held_by_others:x.held.length},filters:{type:e.type??null,tag:e.tag??null,priority:e.priority??null,assignee:e.assignee??null,assignee_filter:e.assigneeFilter??null,sprint:e.sprint??null,release:e.release??null,parent:l.length>0?l:null,limit:a,blocked_limit:c,ready_only:u,include_decisions:e.includeDecisions===!0,token_budget:d},truncation:De};return $s({result:Ne,recommended:B,blockedRows:j,candidatesWarnings:p.warnings,corpusWarnings:g.warnings,readyRanking:ie,explainRanking:e.explainRanking===!0,pmRoot:n,author:o,packing:Ie,featureStore:$e})}function dc(e){let t=["# pm next","",...As(e)];if(t.push(...Ee("Recommended",Os(e.recommended),"No ready work.")),t.push(...Ee("Decision needed",(e.decision_needed??[]).map(n=>`- ${Te(n)}`),"No human-gated decisions.")),t.push(...Ee("Ready",e.ready.map(n=>`- ${Te(n)}`),"No ready items.")),e.filters.ready_only||t.push(...Ee("Blocked",e.blocked.map(n=>`- ${Ms(n)}`),"No blocked items.")),e.suggestions&&e.suggestions.length>0){t.push("## Suggestions");for(let n of e.suggestions)t.push(`- ${n}`)}return t.join(`
|
|
12
|
-
`).trimEnd()}function As(e){let t=[`- now: ${e.now}`,`- ready: ${e.summary.ready} (in_progress: ${e.summary.in_progress}), blocked: ${e.summary.blocked}, candidates: ${e.summary.candidates}`];return e.filters.parent&&t.push(`- scope: subtree of ${e.filters.parent}`),t.push(""),t}function Os(e){return e?[`- ${Te(e)}`,` why: ${e.reasons.join("; ")}`]:[]}function Ee(e,t,n){return[`## ${e}`,...t.length===0?[n]:t,""]}function Ms(e){let t=e.blockers.map(n=>`${n.id}(${n.status??"?"})`).join(", ");return`${Te(e)} blocked_by:${t}`}function Te(e){let t=e.deadline??"-",n=e.parent?` parent:${e.parent}`:"",r=e.unblocks.length>0?` unblocks:${e.unblocks.length}`:"";return`${Number.isInteger(e.rank)?`#${e.rank} `:""}${e.id} p${e.priority} ${e.status} ${e.type} deadline:${t}${n}${r} ${e.title}`}(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]="412fc2d2-daee-5d87-82ab-5411a1503087")}catch{}})();function lc(e,t){let n=t??{};return e.filter(r=>n[r.id]!==r.updated_at).map(r=>r.id).sort((r,o)=>r.localeCompare(o))}export{pe as a,Lt as b,Un as c,Ut as d,Us as e,Le as f,Pt as g,zt as h,Zs as i,Qs as j,ea as k,Qt as l,qe as m,we as n,Jr as o,nn as p,no as q,ke as r,ro as s,oo as t,co as u,uo as v,ia as w,lo as x,rn as y,I as z,be as A,fa as B,ma as C,ve as D,Ye as E,Ve as F,Ro as G,Lo as H,Ke as I,Je as J,Se as K,gn as L,ba as M,Wo as N,Yo as O,_n as P,ti as Q,wn as R,ni as S,Na as T,ri as U,ui as V,ee as W,qa as X,et as Y,mi as Z,pi as _,nt as $,U as aa,ot as ba,it as ca,st as da,q as ea,oe as fa,xe as ga,Ya as ha,fs as ia,Va as ja,hs as ka,sc as la,ac as ma,bs as na,cc as oa,dc as pa,lc as qa};
|
|
13
|
-
//# sourceMappingURL=chunk-6MSQJOTG.js.map
|