@herbertgao/pi-extensions 2026.10.19 → 2026.11.0

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.
Files changed (261) hide show
  1. package/README.md +19 -4
  2. package/THIRD_PARTY_NOTICES.md +53 -2
  3. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  4. package/node_modules/@herbertgao/pi-subagents/README.md +142 -45
  5. package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +17 -7
  6. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  7. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +111 -59
  8. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +135 -117
  9. package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +41 -14
  10. package/node_modules/@herbertgao/pi-subagents/src/index.ts +110 -19
  11. package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +8 -0
  12. package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +31 -0
  13. package/node_modules/@tintinweb/pi-tasks/CHANGELOG.md +270 -0
  14. package/node_modules/@tintinweb/pi-tasks/CONTRIBUTING.md +67 -0
  15. package/node_modules/@tintinweb/pi-tasks/CUSTOMIZING.md +289 -0
  16. package/node_modules/@tintinweb/pi-tasks/LICENSE +21 -0
  17. package/node_modules/@tintinweb/pi-tasks/README.md +417 -0
  18. package/node_modules/@tintinweb/pi-tasks/SECURITY.md +107 -0
  19. package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.d.ts +64 -0
  20. package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.js +129 -0
  21. package/node_modules/@tintinweb/pi-tasks/dist/index.d.ts +17 -0
  22. package/node_modules/@tintinweb/pi-tasks/dist/index.js +1338 -0
  23. package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.d.ts +29 -0
  24. package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.js +121 -0
  25. package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.d.ts +39 -0
  26. package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.js +61 -0
  27. package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.d.ts +48 -0
  28. package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.js +68 -0
  29. package/node_modules/@tintinweb/pi-tasks/dist/task-paths.d.ts +44 -0
  30. package/node_modules/@tintinweb/pi-tasks/dist/task-paths.js +60 -0
  31. package/node_modules/@tintinweb/pi-tasks/dist/task-sort.d.ts +23 -0
  32. package/node_modules/@tintinweb/pi-tasks/dist/task-sort.js +69 -0
  33. package/node_modules/@tintinweb/pi-tasks/dist/task-store.d.ts +61 -0
  34. package/node_modules/@tintinweb/pi-tasks/dist/task-store.js +397 -0
  35. package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.d.ts +16 -0
  36. package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.js +51 -0
  37. package/node_modules/@tintinweb/pi-tasks/dist/types.d.ts +36 -0
  38. package/node_modules/@tintinweb/pi-tasks/dist/types.js +4 -0
  39. package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.d.ts +15 -0
  40. package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.js +140 -0
  41. package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.d.ts +69 -0
  42. package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.js +278 -0
  43. package/node_modules/@tintinweb/pi-tasks/package.json +57 -0
  44. package/node_modules/@tintinweb/pi-tasks/src/auto-clear.ts +134 -0
  45. package/node_modules/@tintinweb/pi-tasks/src/index.ts +1417 -0
  46. package/node_modules/@tintinweb/pi-tasks/src/process-tracker.ts +140 -0
  47. package/node_modules/@tintinweb/pi-tasks/src/reminder-cadence.ts +90 -0
  48. package/node_modules/@tintinweb/pi-tasks/src/task-glyphs.ts +110 -0
  49. package/node_modules/@tintinweb/pi-tasks/src/task-paths.ts +65 -0
  50. package/node_modules/@tintinweb/pi-tasks/src/task-sort.ts +90 -0
  51. package/node_modules/@tintinweb/pi-tasks/src/task-store.ts +402 -0
  52. package/node_modules/@tintinweb/pi-tasks/src/tasks-config.ts +77 -0
  53. package/node_modules/@tintinweb/pi-tasks/src/types.ts +40 -0
  54. package/node_modules/@tintinweb/pi-tasks/src/ui/settings-menu.ts +174 -0
  55. package/node_modules/@tintinweb/pi-tasks/src/ui/task-widget.ts +325 -0
  56. package/node_modules/pi-commandcode-provider/CHANGELOG.md +330 -0
  57. package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +192 -0
  58. package/node_modules/pi-commandcode-provider/LICENSE +21 -0
  59. package/node_modules/pi-commandcode-provider/README.md +243 -0
  60. package/node_modules/pi-commandcode-provider/RELEASE.md +194 -0
  61. package/node_modules/pi-commandcode-provider/index.ts +309 -0
  62. package/node_modules/pi-commandcode-provider/package.json +91 -0
  63. package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +87 -0
  64. package/node_modules/pi-commandcode-provider/scripts/pi-authenticated.mjs +50 -0
  65. package/node_modules/pi-commandcode-provider/scripts/pi-isolated.mjs +79 -0
  66. package/node_modules/pi-commandcode-provider/src/api-key.ts +69 -0
  67. package/node_modules/pi-commandcode-provider/src/auth-server.ts +229 -0
  68. package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +28 -0
  69. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +260 -0
  70. package/node_modules/pi-commandcode-provider/src/converters.ts +477 -0
  71. package/node_modules/pi-commandcode-provider/src/core.ts +836 -0
  72. package/node_modules/pi-commandcode-provider/src/cost.ts +76 -0
  73. package/node_modules/pi-commandcode-provider/src/json-schema.ts +417 -0
  74. package/node_modules/pi-commandcode-provider/src/models.ts +515 -0
  75. package/node_modules/pi-commandcode-provider/src/oauth.ts +229 -0
  76. package/node_modules/pi-commandcode-provider/src/overflow.ts +120 -0
  77. package/node_modules/pi-commandcode-provider/src/pricing.ts +370 -0
  78. package/node_modules/pi-commandcode-provider/src/quota-command.ts +66 -0
  79. package/node_modules/pi-commandcode-provider/src/quota-format.ts +143 -0
  80. package/node_modules/pi-commandcode-provider/src/quota-types.ts +47 -0
  81. package/node_modules/pi-commandcode-provider/src/quota.ts +357 -0
  82. package/node_modules/pi-commandcode-provider/src/responses-stream.ts +249 -0
  83. package/node_modules/pi-commandcode-provider/src/runtime.ts +330 -0
  84. package/node_modules/pi-commandcode-provider/src/transcript.ts +56 -0
  85. package/node_modules/pi-commandcode-provider/src/transport.ts +147 -0
  86. package/node_modules/pi-commandcode-provider/src/types.ts +212 -0
  87. package/node_modules/pi-commandcode-provider/src/usage.ts +261 -0
  88. package/node_modules/pi-lens/CHANGELOG.md +149 -0
  89. package/node_modules/pi-lens/README.md +12 -2
  90. package/node_modules/pi-lens/config/markdownlint/run-no-fix.mjs +36 -0
  91. package/node_modules/pi-lens/dist/{chunk-WME2OQST.js → chunk-2453RRJ2.js} +11 -6
  92. package/node_modules/pi-lens/dist/{chunk-FZKFVUEC.js → chunk-2BKUFQKR.js} +276 -208
  93. package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +31 -0
  94. package/node_modules/pi-lens/dist/{chunk-QHSNL7B2.js → chunk-2ZE3AUJQ.js} +12 -14
  95. package/node_modules/pi-lens/dist/{chunk-MPKRJBPK.js → chunk-35WKJWO5.js} +28 -30
  96. package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +27 -0
  97. package/node_modules/pi-lens/dist/{chunk-4LM3VAZH.js → chunk-3O5EII3W.js} +2 -2
  98. package/node_modules/pi-lens/dist/chunk-447YZL4S.js +25 -0
  99. package/node_modules/pi-lens/dist/{chunk-H7OR7DFZ.js → chunk-4B2YFN4U.js} +25 -21
  100. package/node_modules/pi-lens/dist/{chunk-OSTKYB55.js → chunk-4BKU7PV3.js} +1 -1
  101. package/node_modules/pi-lens/dist/{chunk-RRV3FNNM.js → chunk-4LL2VRNY.js} +27 -28
  102. package/node_modules/pi-lens/dist/{chunk-BZARLRJW.js → chunk-4NBWFYWW.js} +9 -9
  103. package/node_modules/pi-lens/dist/{chunk-KKCK636N.js → chunk-4QG55RRC.js} +12 -12
  104. package/node_modules/pi-lens/dist/{chunk-RQS4QQSD.js → chunk-4W52ZKZX.js} +2 -2
  105. package/node_modules/pi-lens/dist/{chunk-Z2XAOKHK.js → chunk-565VRUP4.js} +2 -2
  106. package/node_modules/pi-lens/dist/{chunk-HWDAVBFU.js → chunk-57X2CDRX.js} +23 -23
  107. package/node_modules/pi-lens/dist/{chunk-MB6PXBUA.js → chunk-5F3XF3SX.js} +7 -15
  108. package/node_modules/pi-lens/dist/{chunk-O4BJFESU.js → chunk-5RNB4HVK.js} +1 -1
  109. package/node_modules/pi-lens/dist/{chunk-ZMAUPOMG.js → chunk-5T5A6YAJ.js} +35 -34
  110. package/node_modules/pi-lens/dist/{chunk-4ZYJHQMB.js → chunk-6FIRFP6A.js} +12 -12
  111. package/node_modules/pi-lens/dist/{chunk-4YHYPW2G.js → chunk-6GMGEKQN.js} +9 -5
  112. package/node_modules/pi-lens/dist/{chunk-4LOE5R5P.js → chunk-6LJOJ6EO.js} +20 -15
  113. package/node_modules/pi-lens/dist/{chunk-3YY7IXIL.js → chunk-6YUNI7B5.js} +3 -3
  114. package/node_modules/pi-lens/dist/{chunk-PKES3ISE.js → chunk-7ANZ7XDD.js} +2 -2
  115. package/node_modules/pi-lens/dist/{chunk-FB5SCCPT.js → chunk-7CGIDRIK.js} +16 -15
  116. package/node_modules/pi-lens/dist/{chunk-L3CMBQMH.js → chunk-7MAD5ZAY.js} +16 -17
  117. package/node_modules/pi-lens/dist/{chunk-WDBICWH3.js → chunk-7TNILKGY.js} +1 -1
  118. package/node_modules/pi-lens/dist/{chunk-RORGS5II.js → chunk-A5GRLYPZ.js} +9 -9
  119. package/node_modules/pi-lens/dist/{chunk-MNJIXFX4.js → chunk-AGGUWKRK.js} +1 -1
  120. package/node_modules/pi-lens/dist/{chunk-ABPKUVA4.js → chunk-BBET6HD6.js} +1 -1
  121. package/node_modules/pi-lens/dist/{chunk-L5JYIU47.js → chunk-BHWW6FAX.js} +14 -13
  122. package/node_modules/pi-lens/dist/{chunk-URCQWAQ4.js → chunk-BOPDQ7AZ.js} +23 -21
  123. package/node_modules/pi-lens/dist/{chunk-KDX35VXP.js → chunk-BQG2QFVO.js} +158 -133
  124. package/node_modules/pi-lens/dist/{chunk-CB4WHS4H.js → chunk-BUZIQDFS.js} +3 -3
  125. package/node_modules/pi-lens/dist/{chunk-2PHMIAKO.js → chunk-CM73PPGD.js} +4 -4
  126. package/node_modules/pi-lens/dist/{chunk-DH5JPM3K.js → chunk-CUDD35TW.js} +10 -9
  127. package/node_modules/pi-lens/dist/{chunk-AWDSEDER.js → chunk-CZL44WFN.js} +2 -2
  128. package/node_modules/pi-lens/dist/{chunk-N5WSK2K7.js → chunk-DIWK3LBC.js} +12 -15
  129. package/node_modules/pi-lens/dist/{chunk-24BILSZW.js → chunk-DYRZGUMA.js} +2 -2
  130. package/node_modules/pi-lens/dist/{chunk-PR6PO3ES.js → chunk-FHEV6T4L.js} +22 -18
  131. package/node_modules/pi-lens/dist/{chunk-DQZFQSR5.js → chunk-FRLAUP2B.js} +4 -4
  132. package/node_modules/pi-lens/dist/{chunk-RZOXUSPC.js → chunk-G5GV2Q7K.js} +2 -2
  133. package/node_modules/pi-lens/dist/{chunk-EKWX4WD3.js → chunk-G6JKM4O7.js} +7 -7
  134. package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +27 -0
  135. package/node_modules/pi-lens/dist/{chunk-XT2HTCJ5.js → chunk-GIRBSBGL.js} +6 -5
  136. package/node_modules/pi-lens/dist/{chunk-PQJFG24Z.js → chunk-GMROJJRN.js} +1292 -946
  137. package/node_modules/pi-lens/dist/{chunk-U6VN4NVL.js → chunk-HHR7WGCI.js} +3 -3
  138. package/node_modules/pi-lens/dist/{chunk-TIQJPRDD.js → chunk-HKIL6DCL.js} +3 -2
  139. package/node_modules/pi-lens/dist/{chunk-SNDXCFRS.js → chunk-HUAM7QG3.js} +11 -11
  140. package/node_modules/pi-lens/dist/{chunk-QOE342SU.js → chunk-HXFUTMX2.js} +2 -2
  141. package/node_modules/pi-lens/dist/{chunk-U7BD2QL7.js → chunk-I22THIHI.js} +12 -12
  142. package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +58 -0
  143. package/node_modules/pi-lens/dist/{chunk-DPGEAHZT.js → chunk-IYVYZQRL.js} +10 -16
  144. package/node_modules/pi-lens/dist/{chunk-3F6BMY53.js → chunk-JBP7KESM.js} +1 -1
  145. package/node_modules/pi-lens/dist/{chunk-U5HPROLA.js → chunk-JE6HKLC7.js} +2 -2
  146. package/node_modules/pi-lens/dist/{chunk-ZE3KXHS7.js → chunk-JPRDTY5S.js} +85 -3
  147. package/node_modules/pi-lens/dist/{chunk-HO6LWE2E.js → chunk-JYLOYTZD.js} +17 -1
  148. package/node_modules/pi-lens/dist/{chunk-KW5JQPO5.js → chunk-JZRP4DGP.js} +2 -2
  149. package/node_modules/pi-lens/dist/{chunk-CPSR3AVL.js → chunk-KZ4ALBCH.js} +2 -2
  150. package/node_modules/pi-lens/dist/{chunk-6IR3ZYIB.js → chunk-L3CLUGDY.js} +3 -3
  151. package/node_modules/pi-lens/dist/{chunk-LV4UMYVH.js → chunk-L4NEVZ4T.js} +28 -27
  152. package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +22 -0
  153. package/node_modules/pi-lens/dist/{chunk-WGRJOXED.js → chunk-LSFXZLPW.js} +1016 -636
  154. package/node_modules/pi-lens/dist/{chunk-LBLBAFG3.js → chunk-MC6VB2E5.js} +4 -4
  155. package/node_modules/pi-lens/dist/{chunk-U2SDMG7C.js → chunk-NM2NWH55.js} +5 -5
  156. package/node_modules/pi-lens/dist/{chunk-T7A2HK2B.js → chunk-NSPVR3FN.js} +19 -18
  157. package/node_modules/pi-lens/dist/{chunk-ZGSJDWQU.js → chunk-O2ARHQKF.js} +2 -2
  158. package/node_modules/pi-lens/dist/{chunk-OXOI55RU.js → chunk-O4N5BQ3T.js} +10 -10
  159. package/node_modules/pi-lens/dist/{chunk-3FRLWYBG.js → chunk-OC7VWJBZ.js} +39 -40
  160. package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +89 -0
  161. package/node_modules/pi-lens/dist/{chunk-HR3OJ3TH.js → chunk-OWTG6UMO.js} +21 -21
  162. package/node_modules/pi-lens/dist/{chunk-75GAYVNO.js → chunk-OY7WZI7Q.js} +6 -6
  163. package/node_modules/pi-lens/dist/{chunk-ZJTT47IG.js → chunk-OZWXLJMX.js} +2 -2
  164. package/node_modules/pi-lens/dist/{chunk-F6X3YJWD.js → chunk-PIQQM32Y.js} +2 -2
  165. package/node_modules/pi-lens/dist/chunk-PKLB2XJL.js +8 -0
  166. package/node_modules/pi-lens/dist/{chunk-EAOK7MIZ.js → chunk-PKSUMEPT.js} +17 -4
  167. package/node_modules/pi-lens/dist/{chunk-YISME6ON.js → chunk-PPKECBPP.js} +1 -1
  168. package/node_modules/pi-lens/dist/{chunk-4L36HG27.js → chunk-R2QQC33W.js} +14 -14
  169. package/node_modules/pi-lens/dist/{chunk-LUBPZN36.js → chunk-R4QWJQ2H.js} +11 -11
  170. package/node_modules/pi-lens/dist/{chunk-V63BC55Q.js → chunk-RGGH6M34.js} +1 -1
  171. package/node_modules/pi-lens/dist/{chunk-Y7F7IEE3.js → chunk-RZG472YW.js} +65 -7
  172. package/node_modules/pi-lens/dist/{chunk-PUZ3E2J4.js → chunk-SDFKOLSF.js} +6 -6
  173. package/node_modules/pi-lens/dist/{chunk-YHC2O2WO.js → chunk-SFLHSL5R.js} +9 -9
  174. package/node_modules/pi-lens/dist/{chunk-CCV2EU7T.js → chunk-SP4TFY5F.js} +14 -13
  175. package/node_modules/pi-lens/dist/{chunk-J6JP25XU.js → chunk-SQC7K3SP.js} +4 -3
  176. package/node_modules/pi-lens/dist/{chunk-3K2F6UDZ.js → chunk-T2S3FNNJ.js} +44 -42
  177. package/node_modules/pi-lens/dist/{chunk-2TF6RXWB.js → chunk-TV6RXRYH.js} +10 -10
  178. package/node_modules/pi-lens/dist/{chunk-GNSIWBAT.js → chunk-U3AS2FR6.js} +3 -3
  179. package/node_modules/pi-lens/dist/{chunk-F7K5IBZG.js → chunk-UHHLR2VY.js} +40 -40
  180. package/node_modules/pi-lens/dist/chunk-UYXV5NIS.js +20 -0
  181. package/node_modules/pi-lens/dist/{chunk-VSFLRN5Y.js → chunk-VLQ7UKZH.js} +1 -1
  182. package/node_modules/pi-lens/dist/{chunk-VUZWQ7UG.js → chunk-VN3L2JWZ.js} +46 -72
  183. package/node_modules/pi-lens/dist/{chunk-NA7SEXHE.js → chunk-VOP4PJKA.js} +7 -7
  184. package/node_modules/pi-lens/dist/{chunk-F5Z6URKM.js → chunk-VOXTCULR.js} +2 -2
  185. package/node_modules/pi-lens/dist/{chunk-LLS45EWB.js → chunk-VPLBLWFO.js} +6 -8
  186. package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +27 -0
  187. package/node_modules/pi-lens/dist/{chunk-ZKXQKGWZ.js → chunk-WC6WRNQT.js} +4 -3
  188. package/node_modules/pi-lens/dist/{chunk-YVHBNSME.js → chunk-WMDUT4KH.js} +1148 -1132
  189. package/node_modules/pi-lens/dist/{chunk-KXF5R4UN.js → chunk-WQV6BI4Q.js} +1 -1
  190. package/node_modules/pi-lens/dist/chunk-WXUDRAG6.js +24 -0
  191. package/node_modules/pi-lens/dist/{chunk-KPPJTH44.js → chunk-X35S7HSB.js} +28 -10
  192. package/node_modules/pi-lens/dist/{chunk-JMEKXFOL.js → chunk-X66YJ2SS.js} +40 -34
  193. package/node_modules/pi-lens/dist/{chunk-CE6VMBCB.js → chunk-XOMGO63G.js} +22 -21
  194. package/node_modules/pi-lens/dist/{chunk-LS3QJRUB.js → chunk-XWIME22V.js} +13 -13
  195. package/node_modules/pi-lens/dist/{chunk-R5MOQM2H.js → chunk-XYLC35E4.js} +119 -87
  196. package/node_modules/pi-lens/dist/{chunk-OE5ZBP7F.js → chunk-YHGYAEFH.js} +18 -18
  197. package/node_modules/pi-lens/dist/{chunk-7E2563GA.js → chunk-ZFORSIED.js} +13 -13
  198. package/node_modules/pi-lens/dist/{chunk-E7HJ56Y7.js → chunk-ZKLTNLAW.js} +64 -73
  199. package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +74 -0
  200. package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +30 -0
  201. package/node_modules/pi-lens/dist/{chunk-RC2Z6K47.js → chunk-ZZDIOAAJ.js} +15 -6
  202. package/node_modules/pi-lens/dist/index.js +6993 -5396
  203. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -10
  204. package/node_modules/pi-lens/dist/mcp/cli.js +44 -42
  205. package/node_modules/pi-lens/dist/mcp/server.js +1627 -504
  206. package/node_modules/pi-lens/dist/mcp/worker.js +62 -61
  207. package/node_modules/pi-lens/dist/probes/installer.js +20 -19
  208. package/node_modules/pi-lens/docs/adr/0003-git-guard-latch-writer.md +11 -6
  209. package/node_modules/pi-lens/docs/agent-tools.md +18 -8
  210. package/node_modules/pi-lens/docs/alignment-families.md +29 -0
  211. package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +6 -4
  212. package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +126 -0
  213. package/node_modules/pi-lens/docs/configuration.md +99 -3
  214. package/node_modules/pi-lens/docs/defect-shapes.md +55 -12
  215. package/node_modules/pi-lens/docs/engineering-principles.md +27 -2
  216. package/node_modules/pi-lens/docs/features.md +2 -2
  217. package/node_modules/pi-lens/docs/invariants/git-guard-host.md +7 -3
  218. package/node_modules/pi-lens/docs/invariants/language-config.md +15 -4
  219. package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +16 -2
  220. package/node_modules/pi-lens/docs/invariants/paths-os.md +4 -2
  221. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +119 -39
  222. package/node_modules/pi-lens/docs/merge-queue-rollout.md +1 -1
  223. package/node_modules/pi-lens/docs/pi-lens-fixer.md +24 -17
  224. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +20 -11
  225. package/node_modules/pi-lens/docs/pi-lens-monitor.md +9 -0
  226. package/node_modules/pi-lens/docs/pi-lens-orchestration.md +4 -1
  227. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +5 -5
  228. package/node_modules/pi-lens/docs/pi-lens-subagent.md +6 -3
  229. package/node_modules/pi-lens/docs/public-api-stability.md +18 -2
  230. package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +10 -0
  231. package/node_modules/pi-lens/docs/settings.md +10 -6
  232. package/node_modules/pi-lens/docs/word-index.md +17 -5
  233. package/node_modules/pi-lens/package.json +5 -3
  234. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-accumulating-spread-js-test.yml +37 -0
  235. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ts-redundant-filter-map-test.yml +12 -1
  236. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-js-test.yml +12 -0
  237. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-test.yml +25 -0
  238. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-accumulating-spread-js.yml +49 -1
  239. package/node_modules/pi-lens/rules/ast-grep-rules/rules/ts-redundant-filter-map.yml +9 -1
  240. package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map-js.yml +17 -0
  241. package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map.yml +36 -0
  242. package/node_modules/pi-lens/rules/ast-grep-rules/self-scan-baseline.json +1 -1
  243. package/node_modules/pi-provider-qoder/README.md +22 -0
  244. package/node_modules/pi-provider-qoder/dist/index.js +370 -11
  245. package/node_modules/pi-provider-qoder/package.json +5 -2
  246. package/package.json +11 -8
  247. package/node_modules/@tifan/pi-preferred-thinking/README.md +0 -54
  248. package/node_modules/@tifan/pi-preferred-thinking/package.json +0 -43
  249. package/node_modules/@tifan/pi-preferred-thinking/src/index.ts +0 -236
  250. package/node_modules/pi-lens/dist/chunk-46TNM7XZ.js +0 -88
  251. package/node_modules/pi-lens/dist/chunk-72OKUXSD.js +0 -31
  252. package/node_modules/pi-lens/dist/chunk-7GLOLOSH.js +0 -57
  253. package/node_modules/pi-lens/dist/chunk-AKUUMGD5.js +0 -26
  254. package/node_modules/pi-lens/dist/chunk-ASUXV767.js +0 -22
  255. package/node_modules/pi-lens/dist/chunk-CTADOKYM.js +0 -25
  256. package/node_modules/pi-lens/dist/chunk-JJ2RRESP.js +0 -58
  257. package/node_modules/pi-lens/dist/chunk-LSC3VADM.js +0 -23
  258. package/node_modules/pi-lens/dist/chunk-SHLDT3OI.js +0 -27
  259. package/node_modules/pi-lens/dist/chunk-UF7RTZSO.js +0 -27
  260. package/node_modules/pi-lens/dist/chunk-W4WP2ERB.js +0 -30
  261. package/node_modules/pi-lens/dist/chunk-YES5CACN.js +0 -73
@@ -0,0 +1,140 @@
1
+ /**
2
+ * process-tracker.ts — Background process management for tasks.
3
+ *
4
+ * Tracks spawned child processes, buffers their output, and supports
5
+ * blocking wait and graceful stop (SIGTERM → 5s → SIGKILL).
6
+ */
7
+
8
+ import type { ChildProcess } from "node:child_process";
9
+ import type { BackgroundProcess } from "./types.js";
10
+
11
+ export interface ProcessOutput {
12
+ output: string;
13
+ status: BackgroundProcess["status"];
14
+ exitCode?: number;
15
+ startedAt: number;
16
+ completedAt?: number;
17
+ command?: string;
18
+ }
19
+
20
+ export class ProcessTracker {
21
+ private processes = new Map<string, BackgroundProcess>();
22
+
23
+ /** Register a spawned process for a task. */
24
+ track(taskId: string, proc: ChildProcess, command?: string): void {
25
+ const bp: BackgroundProcess = {
26
+ taskId,
27
+ pid: proc.pid!,
28
+ command,
29
+ output: [],
30
+ status: "running",
31
+ startedAt: Date.now(),
32
+ proc,
33
+ abortController: new AbortController(),
34
+ waiters: [],
35
+ };
36
+
37
+ // Buffer stdout
38
+ proc.stdout?.on("data", (data: Buffer) => {
39
+ bp.output.push(data.toString());
40
+ });
41
+
42
+ // Buffer stderr
43
+ proc.stderr?.on("data", (data: Buffer) => {
44
+ bp.output.push(data.toString());
45
+ });
46
+
47
+ // Handle process exit
48
+ proc.on("close", (code, _signal) => {
49
+ if (bp.status === "running") {
50
+ bp.status = code === 0 ? "completed" : "error";
51
+ }
52
+ bp.exitCode = code ?? undefined;
53
+ bp.completedAt = Date.now();
54
+ // Notify all waiters
55
+ for (const resolve of bp.waiters) resolve();
56
+ bp.waiters = [];
57
+ });
58
+
59
+ proc.on("error", (err) => {
60
+ if (bp.status === "running") {
61
+ bp.status = "error";
62
+ bp.output.push(`Process error: ${err.message}`);
63
+ bp.completedAt = Date.now();
64
+ for (const resolve of bp.waiters) resolve();
65
+ bp.waiters = [];
66
+ }
67
+ });
68
+
69
+ this.processes.set(taskId, bp);
70
+ }
71
+
72
+ /** Get current output and status for a task's process. */
73
+ getOutput(taskId: string): ProcessOutput | undefined {
74
+ const bp = this.processes.get(taskId);
75
+ if (!bp) return undefined;
76
+ return {
77
+ output: bp.output.join(""),
78
+ status: bp.status,
79
+ exitCode: bp.exitCode,
80
+ startedAt: bp.startedAt,
81
+ completedAt: bp.completedAt,
82
+ command: bp.command,
83
+ };
84
+ }
85
+
86
+ /** Wait for a task's process to complete, with timeout. */
87
+ waitForCompletion(taskId: string, timeout: number, signal?: AbortSignal): Promise<ProcessOutput | undefined> {
88
+ const bp = this.processes.get(taskId);
89
+ if (!bp) return Promise.resolve(undefined);
90
+ if (bp.status !== "running") return Promise.resolve(this.getOutput(taskId));
91
+
92
+ return new Promise<ProcessOutput | undefined>((resolve) => {
93
+ let settled = false;
94
+ const timer = setTimeout(finish, timeout);
95
+
96
+ function finish() {
97
+ if (settled) return;
98
+ settled = true;
99
+ clearTimeout(timer);
100
+ resolve(self.getOutput(taskId));
101
+ }
102
+
103
+ const self = this;
104
+ bp.waiters.push(finish);
105
+ signal?.addEventListener("abort", finish, { once: true });
106
+ });
107
+ }
108
+
109
+ /** Stop a task's background process. SIGTERM → 5s → SIGKILL. */
110
+ async stop(taskId: string): Promise<boolean> {
111
+ const bp = this.processes.get(taskId);
112
+ if (!bp || bp.status !== "running") return false;
113
+
114
+ bp.status = "stopped";
115
+ bp.proc.kill("SIGTERM");
116
+
117
+ // Wait up to 5s for graceful exit
118
+ await new Promise<void>((resolve) => {
119
+ const timer = setTimeout(() => {
120
+ try { bp.proc.kill("SIGKILL"); } catch { /* already dead */ }
121
+ resolve();
122
+ }, 5000);
123
+
124
+ bp.proc.on("close", () => {
125
+ clearTimeout(timer);
126
+ resolve();
127
+ });
128
+ });
129
+
130
+ bp.completedAt = Date.now();
131
+ for (const resolve of bp.waiters) resolve();
132
+ bp.waiters = [];
133
+ return true;
134
+ }
135
+
136
+ /** Get the process record for a task. */
137
+ getProcess(taskId: string): BackgroundProcess | undefined {
138
+ return this.processes.get(taskId);
139
+ }
140
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Pure cadence logic for the system-reminder injection.
3
+ *
4
+ * Decisions are made here as plain functions so they're easy to unit-test
5
+ * without spinning up the whole extension. The default export of the
6
+ * extension wires these into the `tool_result` and `context` hooks.
7
+ */
8
+
9
+ /** Internal cadence state. Plain object so it round-trips through tests. */
10
+ export interface CadenceState {
11
+ currentTurn: number;
12
+ lastTaskToolUseTurn: number;
13
+ reminderInjectedThisCycle: boolean;
14
+ reminderDue: boolean;
15
+ }
16
+
17
+ export interface CadenceConfig {
18
+ /** Turns without a task-tool call before a reminder is considered due. */
19
+ reminderInterval: number;
20
+ /** Set of tool names that count as "task tool usage" and reset cadence. */
21
+ taskToolNames: ReadonlySet<string>;
22
+ }
23
+
24
+ export function createCadenceState(): CadenceState {
25
+ return {
26
+ currentTurn: 0,
27
+ lastTaskToolUseTurn: 0,
28
+ reminderInjectedThisCycle: false,
29
+ reminderDue: false,
30
+ };
31
+ }
32
+
33
+ export function resetCadenceState(state: CadenceState): void {
34
+ state.currentTurn = 0;
35
+ state.lastTaskToolUseTurn = 0;
36
+ state.reminderInjectedThisCycle = false;
37
+ state.reminderDue = false;
38
+ }
39
+
40
+ /** Increment the turn counter at `turn_start`. */
41
+ export function onTurnStart(state: CadenceState): void {
42
+ state.currentTurn++;
43
+ }
44
+
45
+ export interface ToolResultDecision {
46
+ /** True when caller should mark `reminderDue` for the next `context` event. */
47
+ markDue: boolean;
48
+ }
49
+
50
+ /**
51
+ * Decide what cadence change a tool_result implies. Mutates `state` in place
52
+ * (resets the timer when a task tool was used) and returns whether the
53
+ * reminder should be queued for the next LLM call.
54
+ */
55
+ export function evaluateToolResult(
56
+ state: CadenceState,
57
+ toolName: string,
58
+ hasTasks: boolean,
59
+ config: CadenceConfig,
60
+ ): ToolResultDecision {
61
+ // Task tool usage resets cadence and clears any pending reminder.
62
+ if (config.taskToolNames.has(toolName)) {
63
+ state.lastTaskToolUseTurn = state.currentTurn;
64
+ state.reminderInjectedThisCycle = false;
65
+ state.reminderDue = false;
66
+ return { markDue: false };
67
+ }
68
+
69
+ // Cheap guards first.
70
+ if (state.currentTurn - state.lastTaskToolUseTurn < config.reminderInterval) {
71
+ return { markDue: false };
72
+ }
73
+ if (state.reminderInjectedThisCycle) return { markDue: false };
74
+ if (!hasTasks) return { markDue: false };
75
+
76
+ state.reminderDue = true;
77
+ return { markDue: true };
78
+ }
79
+
80
+ /**
81
+ * Drain the pending reminder when `context` fires. Returns true if the
82
+ * caller should inject the reminder into the upcoming LLM call's messages.
83
+ */
84
+ export function drainReminderForContext(state: CadenceState): boolean {
85
+ if (!state.reminderDue) return false;
86
+ state.reminderDue = false;
87
+ state.reminderInjectedThisCycle = true;
88
+ state.lastTaskToolUseTurn = state.currentTurn;
89
+ return true;
90
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * task-glyphs.ts — The glyphs the task widget and the /tasks menu are drawn with.
3
+ *
4
+ * Glyphs are pure data — there is deliberately no executable config file, because
5
+ * `.pi/` lives inside cloned repositories. A hand-edited config must never break
6
+ * the widget, so anything unrecognised falls back to the built-in glyph.
7
+ */
8
+
9
+ /** A fully resolved glyph set — what the render sites consume. */
10
+ export interface TaskGlyphs {
11
+ /** Completed task rows, in the widget and the /tasks list. */
12
+ completed: string;
13
+ /** In-progress rows that are not being executed right now. */
14
+ inProgress: string;
15
+ /** Rows not started yet. */
16
+ pending: string;
17
+ /** Frames for the actively-executing row, one per widget tick. */
18
+ spinner: readonly string[];
19
+ /** The `N completed` line that `collapseCompleted` puts in place of the rows. */
20
+ completedSummary: string;
21
+ /** The bullet on the widget's summary line. */
22
+ header: string;
23
+ /** The `and N more` line standing in for rows the visible limit hid. */
24
+ overflow: string;
25
+ /** Introduces the `blocked by #1, #2` suffix on a blocked row. */
26
+ blocked: string;
27
+ /** Precedes the input token count on the active row. */
28
+ inputTokens: string;
29
+ /** Precedes the output token count on the active row. */
30
+ outputTokens: string;
31
+ /** Between elapsed time and token counts: `(2m 49s · ↑ 4.1k)`. */
32
+ statsSeparator: string;
33
+ /** Closes the active row's text, marking the action as still running. */
34
+ trailingEllipsis: string;
35
+ /** Marks a line clipped at the terminal's right edge. */
36
+ truncation: string;
37
+ }
38
+
39
+ /** Glyphs as written in `tasks-config.json`: every resolved glyph, all optional.
40
+ * Derived rather than restated, so a glyph cannot be added to one list and
41
+ * forgotten in the other. `spinner` is respelled because the resolved form is
42
+ * readonly while JSON hands us a plain array. */
43
+ export type TaskGlyphsConfig = Partial<Omit<TaskGlyphs, "spinner">> & { spinner?: string[] };
44
+
45
+ /** Every glyph's built-in default. `completedSummary` is deliberately absent: it has
46
+ * no literal of its own and inherits whatever `completed` resolves to.
47
+ *
48
+ * The spinner walks the dingbat block. Claude Code's own spinner is a shorter
49
+ * mirrored sequence (`· ✢ ✳ ✶ ✻ ✽` and its reverse, with a ghostty variant);
50
+ * this one is deliberately ours.
51
+ *
52
+ * `truncation` is three ASCII dots rather than `…` because that is pi-tui's own
53
+ * default, and the widget has always clipped with it. */
54
+ const DEFAULT_GLYPHS: Omit<TaskGlyphs, "completedSummary"> = {
55
+ completed: "✔",
56
+ inProgress: "◼",
57
+ pending: "◻",
58
+ spinner: ["✳", "✴", "✵", "✶", "✷", "✸", "✹", "✺", "✻", "✼", "✽"],
59
+ header: "●",
60
+ overflow: "…",
61
+ blocked: "›",
62
+ inputTokens: "↑",
63
+ outputTokens: "↓",
64
+ statsSeparator: "·",
65
+ trailingEllipsis: "…",
66
+ truncation: "...",
67
+ };
68
+
69
+ /** Control characters would break the widget's one-line-per-entry contract or steer
70
+ * the terminal itself (a glyph carrying `ESC ]0;…` retitles the window), and bidi
71
+ * overrides reorder the line around the glyph. A `tasks-config.json` that arrived
72
+ * with a cloned repository must not be able to do either. */
73
+ const UNSAFE_GLYPH = /[\p{Cc}\u200E\u200F\u202A-\u202E\u2066-\u2069]/u;
74
+
75
+ /** A glyph may be any non-empty string, not just one character — `[x]`, `⣾⣾` and an
76
+ * emoji with a variation selector are all valid, as glyphs and as spinner frames. */
77
+ const isGlyph = (value: unknown): value is string =>
78
+ typeof value === "string" && value.length > 0 && !UNSAFE_GLYPH.test(value);
79
+
80
+ function isSpinner(value: unknown): value is string[] {
81
+ return Array.isArray(value) && value.length > 0 && value.every(isGlyph);
82
+ }
83
+
84
+ /** Resolve configured glyphs against the defaults. Never throws and never rejects
85
+ * loudly: config files are hand-edited, and a malformed one must not break the
86
+ * widget. Each glyph falls back on its own; the spinner falls back as a whole,
87
+ * because half a frame sequence is not an animation. */
88
+ export function resolveTaskGlyphs(glyphs: TaskGlyphsConfig | undefined): TaskGlyphs {
89
+ const glyph = (value: unknown, fallback: string) => isGlyph(value) ? value : fallback;
90
+ const completed = glyph(glyphs?.completed, DEFAULT_GLYPHS.completed);
91
+ const spinner = glyphs?.spinner;
92
+ return {
93
+ completed,
94
+ inProgress: glyph(glyphs?.inProgress, DEFAULT_GLYPHS.inProgress),
95
+ pending: glyph(glyphs?.pending, DEFAULT_GLYPHS.pending),
96
+ spinner: isSpinner(spinner) ? spinner : DEFAULT_GLYPHS.spinner,
97
+ // Falls back to the resolved `completed` rather than to a literal of its own:
98
+ // a config that sets only `completed` should not leave the line that stands in
99
+ // for those rows marked with a different glyph.
100
+ completedSummary: glyph(glyphs?.completedSummary, completed),
101
+ header: glyph(glyphs?.header, DEFAULT_GLYPHS.header),
102
+ overflow: glyph(glyphs?.overflow, DEFAULT_GLYPHS.overflow),
103
+ blocked: glyph(glyphs?.blocked, DEFAULT_GLYPHS.blocked),
104
+ inputTokens: glyph(glyphs?.inputTokens, DEFAULT_GLYPHS.inputTokens),
105
+ outputTokens: glyph(glyphs?.outputTokens, DEFAULT_GLYPHS.outputTokens),
106
+ statsSeparator: glyph(glyphs?.statsSeparator, DEFAULT_GLYPHS.statsSeparator),
107
+ trailingEllipsis: glyph(glyphs?.trailingEllipsis, DEFAULT_GLYPHS.trailingEllipsis),
108
+ truncation: glyph(glyphs?.truncation, DEFAULT_GLYPHS.truncation),
109
+ };
110
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * task-paths.ts — Where session task files live.
3
+ *
4
+ * `session` scope keeps them in the workspace, as it always has. `session-global`
5
+ * keeps them under pi's agent directory instead, beside pi's own per-workspace
6
+ * session logs, for people who would rather their repositories stayed clean.
7
+ *
8
+ * The choice only ever decides where a *new* file is created. A session already
9
+ * holding a file in the workspace keeps using it under either setting, so opting
10
+ * in moves nothing and opting back out strands nothing.
11
+ */
12
+
13
+ import { existsSync, rmdirSync } from "node:fs";
14
+ import { join, resolve } from "node:path";
15
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
16
+ import type { TasksConfig } from "./tasks-config.js";
17
+
18
+ type TaskScope = NonNullable<TasksConfig["taskScope"]>;
19
+
20
+ /**
21
+ * Directory name standing for one workspace.
22
+ *
23
+ * Mirrors the encoding pi uses for its own session logs
24
+ * (`<agent-dir>/sessions/--Users-me-work-repo--/<timestamp>_<id>.jsonl`), so a
25
+ * workspace's task files are named the same way as its transcripts and can be
26
+ * found by eye.
27
+ */
28
+ export function projectKey(cwd: string): string {
29
+ return `--${resolve(cwd).replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
30
+ }
31
+
32
+ /** Where `session-global` collects one workspace's session files.
33
+ * Resolved per call, never captured: `getAgentDir()` reads the environment. */
34
+ export function globalSessionTasksDir(cwd: string): string {
35
+ return join(getAgentDir(), "tasks", "sessions", projectKey(cwd));
36
+ }
37
+
38
+ /** The in-workspace location, unchanged since session scope was introduced. */
39
+ export function workspaceSessionTaskFile(cwd: string, sessionId: string): string {
40
+ return join(cwd, ".pi", "tasks", `tasks-${sessionId}.json`);
41
+ }
42
+
43
+ /**
44
+ * File backing one persisted session.
45
+ *
46
+ * Under `session-global` the workspace is still consulted first: a session that
47
+ * already has a file there is still that file's session, and reading it is the
48
+ * whole reason no migration is needed.
49
+ */
50
+ export function sessionTaskFile(cwd: string, sessionId: string, scope: TaskScope): string {
51
+ const inWorkspace = workspaceSessionTaskFile(cwd, sessionId);
52
+ if (scope !== "session-global") return inWorkspace;
53
+ return existsSync(inWorkspace) ? inWorkspace : join(globalSessionTasksDir(cwd), `tasks-${sessionId}.json`);
54
+ }
55
+
56
+ /**
57
+ * Remove a workspace's global session directory once it holds nothing.
58
+ *
59
+ * Only the global tree is ever reclaimed. `<workspace>/.pi/tasks/` is left alone
60
+ * even when it empties, because that is what every release so far has done and
61
+ * `.pi/` holds project config that is not ours.
62
+ */
63
+ export function reclaimGlobalSessionTasksDir(cwd: string): void {
64
+ try { rmdirSync(globalSessionTasksDir(cwd)); } catch { /* other sessions still stored */ }
65
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * task-sort.ts — Task ordering for the widget.
3
+ *
4
+ * `sortOrder` is either a built-in preset name or a sort spec: an ordered list of
5
+ * comparison keys. Specs are pure data — there is deliberately no executable config
6
+ * file, because `.pi/` lives inside cloned repositories.
7
+ */
8
+
9
+ import type { Task, TaskStatus } from "./types.js";
10
+
11
+ export type SortField = "id" | "status" | "updatedAt";
12
+ export type SortDirection = "asc" | "desc";
13
+
14
+ export interface SortKey {
15
+ field: SortField;
16
+ /** Default "asc". Reverses this key only, status rank included. */
17
+ direction?: SortDirection;
18
+ /** `status` only. Statuses left out of the rank sort last and tie. */
19
+ rank?: TaskStatus[];
20
+ }
21
+
22
+ export type SortSpec = SortKey[];
23
+ export type BuiltInSortOrder = "id" | "status" | "active" | "recent" | "oldest";
24
+ export type TaskSortOrder = BuiltInSortOrder | SortSpec;
25
+
26
+ const SORT_FIELDS: SortField[] = ["id", "status", "updatedAt"];
27
+ const STATUSES: TaskStatus[] = ["pending", "in_progress", "completed"];
28
+
29
+ /** Also used when a status key omits `rank`. */
30
+ const DEFAULT_STATUS_RANK: TaskStatus[] = ["completed", "in_progress", "pending"];
31
+
32
+ /** Built-in presets, expressed as specs. All but `active` reproduce the original
33
+ * comparators exactly, tie-breaks included. */
34
+ const PRESETS: Record<BuiltInSortOrder, SortSpec> = {
35
+ id: [{ field: "id" }],
36
+ status: [{ field: "status", rank: DEFAULT_STATUS_RANK }, { field: "id" }],
37
+ active: [{ field: "status", rank: ["in_progress", "pending", "completed"] }, { field: "id" }],
38
+ recent: [{ field: "updatedAt", direction: "desc" }, { field: "id", direction: "desc" }],
39
+ oldest: [{ field: "updatedAt" }, { field: "id" }],
40
+ };
41
+
42
+ export const BUILT_IN_SORT_ORDERS = Object.keys(PRESETS) as BuiltInSortOrder[];
43
+
44
+ function isSortKey(value: unknown): value is SortKey {
45
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
46
+ const { field, direction, rank } = value as Record<string, unknown>;
47
+ if (!SORT_FIELDS.includes(field as SortField)) return false;
48
+ if (direction !== undefined && direction !== "asc" && direction !== "desc") return false;
49
+ if (rank !== undefined && (!Array.isArray(rank) || !rank.every(s => STATUSES.includes(s as TaskStatus)))) return false;
50
+ return true;
51
+ }
52
+
53
+ /** Resolve a configured order to a spec. Never throws and never rejects loudly:
54
+ * config files are hand-edited, and a malformed one must not break the widget. */
55
+ function toSpec(order: unknown): SortSpec {
56
+ if (typeof order === "string") {
57
+ // hasOwn, not `in` — "toString" is on the prototype chain.
58
+ return Object.hasOwn(PRESETS, order) ? PRESETS[order as BuiltInSortOrder] : PRESETS.id;
59
+ }
60
+ if (Array.isArray(order) && order.length > 0 && order.every(isSortKey)) return order;
61
+ return PRESETS.id;
62
+ }
63
+
64
+ function statusIndex(status: TaskStatus, rank: TaskStatus[]): number {
65
+ const index = rank.indexOf(status);
66
+ return index === -1 ? rank.length : index;
67
+ }
68
+
69
+ function compareKey(a: Task, b: Task, key: SortKey): number {
70
+ if (key.field === "status") {
71
+ const rank = key.rank ?? DEFAULT_STATUS_RANK;
72
+ return statusIndex(a.status, rank) - statusIndex(b.status, rank);
73
+ }
74
+ return key.field === "id" ? Number(a.id) - Number(b.id) : a.updatedAt - b.updatedAt;
75
+ }
76
+
77
+ function buildComparator(spec: SortSpec): (a: Task, b: Task) => number {
78
+ return (a, b) => {
79
+ for (const key of spec) {
80
+ const delta = compareKey(a, b, key);
81
+ if (delta !== 0) return key.direction === "desc" ? -delta : delta;
82
+ }
83
+ return 0;
84
+ };
85
+ }
86
+
87
+ /** Return a sorted copy, leaving the input untouched. */
88
+ export function sortTasks(tasks: readonly Task[], order: TaskSortOrder = "id"): Task[] {
89
+ return [...tasks].sort(buildComparator(toSpec(order)));
90
+ }