@herbertgao/pi-extensions 2026.10.19 → 2026.11.1

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 (288) hide show
  1. package/CHANGELOG.md +759 -0
  2. package/README.md +21 -6
  3. package/THIRD_PARTY_NOTICES.md +53 -2
  4. package/extensions/clef.mjs +1 -1
  5. package/node_modules/@herbertgao/pi-agency/CHANGELOG.md +19 -0
  6. package/node_modules/@herbertgao/pi-agency/package.json +4 -2
  7. package/node_modules/@herbertgao/pi-agency/src/index.ts +1 -1
  8. package/node_modules/@herbertgao/pi-bark/CHANGELOG.md +52 -0
  9. package/node_modules/@herbertgao/pi-bark/package.json +2 -1
  10. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +207 -0
  11. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +7 -5
  12. package/node_modules/@herbertgao/pi-cc-extensions/README.md +10 -7
  13. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +20 -0
  14. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +61 -6
  15. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/core.ts +11 -16
  16. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/index.ts +60 -11
  17. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/compact-thinking.ts +29 -11
  18. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer-layout.ts +54 -6
  19. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer.ts +23 -5
  20. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/session-tokens.ts +52 -0
  21. package/node_modules/@herbertgao/pi-cc-extensions/package.json +5 -4
  22. package/node_modules/@herbertgao/pi-impeccable/CHANGELOG.md +13 -0
  23. package/node_modules/@herbertgao/pi-impeccable/package.json +2 -1
  24. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  25. package/node_modules/@herbertgao/pi-subagents/README.md +142 -45
  26. package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +17 -7
  27. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  28. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +111 -59
  29. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +135 -117
  30. package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +41 -14
  31. package/node_modules/@herbertgao/pi-subagents/src/index.ts +110 -19
  32. package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +8 -0
  33. package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +31 -0
  34. package/node_modules/@herbertgao/sol-pi/CHANGELOG.md +84 -0
  35. package/node_modules/@herbertgao/sol-pi/README.md +3 -3
  36. package/node_modules/@herbertgao/sol-pi/THIRD_PARTY_NOTICES.md +4 -4
  37. package/node_modules/@herbertgao/sol-pi/agents-install.md +3 -3
  38. package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +1 -1
  39. package/node_modules/@herbertgao/sol-pi/package.json +2 -1
  40. package/node_modules/@tintinweb/pi-tasks/CHANGELOG.md +270 -0
  41. package/node_modules/@tintinweb/pi-tasks/CONTRIBUTING.md +67 -0
  42. package/node_modules/@tintinweb/pi-tasks/CUSTOMIZING.md +289 -0
  43. package/node_modules/@tintinweb/pi-tasks/LICENSE +21 -0
  44. package/node_modules/@tintinweb/pi-tasks/README.md +417 -0
  45. package/node_modules/@tintinweb/pi-tasks/SECURITY.md +107 -0
  46. package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.d.ts +64 -0
  47. package/node_modules/@tintinweb/pi-tasks/dist/auto-clear.js +129 -0
  48. package/node_modules/@tintinweb/pi-tasks/dist/index.d.ts +17 -0
  49. package/node_modules/@tintinweb/pi-tasks/dist/index.js +1338 -0
  50. package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.d.ts +29 -0
  51. package/node_modules/@tintinweb/pi-tasks/dist/process-tracker.js +121 -0
  52. package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.d.ts +39 -0
  53. package/node_modules/@tintinweb/pi-tasks/dist/reminder-cadence.js +61 -0
  54. package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.d.ts +48 -0
  55. package/node_modules/@tintinweb/pi-tasks/dist/task-glyphs.js +68 -0
  56. package/node_modules/@tintinweb/pi-tasks/dist/task-paths.d.ts +44 -0
  57. package/node_modules/@tintinweb/pi-tasks/dist/task-paths.js +60 -0
  58. package/node_modules/@tintinweb/pi-tasks/dist/task-sort.d.ts +23 -0
  59. package/node_modules/@tintinweb/pi-tasks/dist/task-sort.js +69 -0
  60. package/node_modules/@tintinweb/pi-tasks/dist/task-store.d.ts +61 -0
  61. package/node_modules/@tintinweb/pi-tasks/dist/task-store.js +397 -0
  62. package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.d.ts +16 -0
  63. package/node_modules/@tintinweb/pi-tasks/dist/tasks-config.js +51 -0
  64. package/node_modules/@tintinweb/pi-tasks/dist/types.d.ts +36 -0
  65. package/node_modules/@tintinweb/pi-tasks/dist/types.js +4 -0
  66. package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.d.ts +15 -0
  67. package/node_modules/@tintinweb/pi-tasks/dist/ui/settings-menu.js +140 -0
  68. package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.d.ts +69 -0
  69. package/node_modules/@tintinweb/pi-tasks/dist/ui/task-widget.js +278 -0
  70. package/node_modules/@tintinweb/pi-tasks/package.json +57 -0
  71. package/node_modules/@tintinweb/pi-tasks/src/auto-clear.ts +134 -0
  72. package/node_modules/@tintinweb/pi-tasks/src/index.ts +1417 -0
  73. package/node_modules/@tintinweb/pi-tasks/src/process-tracker.ts +140 -0
  74. package/node_modules/@tintinweb/pi-tasks/src/reminder-cadence.ts +90 -0
  75. package/node_modules/@tintinweb/pi-tasks/src/task-glyphs.ts +110 -0
  76. package/node_modules/@tintinweb/pi-tasks/src/task-paths.ts +65 -0
  77. package/node_modules/@tintinweb/pi-tasks/src/task-sort.ts +90 -0
  78. package/node_modules/@tintinweb/pi-tasks/src/task-store.ts +402 -0
  79. package/node_modules/@tintinweb/pi-tasks/src/tasks-config.ts +77 -0
  80. package/node_modules/@tintinweb/pi-tasks/src/types.ts +40 -0
  81. package/node_modules/@tintinweb/pi-tasks/src/ui/settings-menu.ts +174 -0
  82. package/node_modules/@tintinweb/pi-tasks/src/ui/task-widget.ts +325 -0
  83. package/node_modules/pi-commandcode-provider/CHANGELOG.md +330 -0
  84. package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +192 -0
  85. package/node_modules/pi-commandcode-provider/LICENSE +21 -0
  86. package/node_modules/pi-commandcode-provider/README.md +243 -0
  87. package/node_modules/pi-commandcode-provider/RELEASE.md +194 -0
  88. package/node_modules/pi-commandcode-provider/index.ts +309 -0
  89. package/node_modules/pi-commandcode-provider/package.json +91 -0
  90. package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +87 -0
  91. package/node_modules/pi-commandcode-provider/scripts/pi-authenticated.mjs +50 -0
  92. package/node_modules/pi-commandcode-provider/scripts/pi-isolated.mjs +79 -0
  93. package/node_modules/pi-commandcode-provider/src/api-key.ts +69 -0
  94. package/node_modules/pi-commandcode-provider/src/auth-server.ts +229 -0
  95. package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +28 -0
  96. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +260 -0
  97. package/node_modules/pi-commandcode-provider/src/converters.ts +477 -0
  98. package/node_modules/pi-commandcode-provider/src/core.ts +836 -0
  99. package/node_modules/pi-commandcode-provider/src/cost.ts +76 -0
  100. package/node_modules/pi-commandcode-provider/src/json-schema.ts +417 -0
  101. package/node_modules/pi-commandcode-provider/src/models.ts +515 -0
  102. package/node_modules/pi-commandcode-provider/src/oauth.ts +229 -0
  103. package/node_modules/pi-commandcode-provider/src/overflow.ts +120 -0
  104. package/node_modules/pi-commandcode-provider/src/pricing.ts +370 -0
  105. package/node_modules/pi-commandcode-provider/src/quota-command.ts +66 -0
  106. package/node_modules/pi-commandcode-provider/src/quota-format.ts +143 -0
  107. package/node_modules/pi-commandcode-provider/src/quota-types.ts +47 -0
  108. package/node_modules/pi-commandcode-provider/src/quota.ts +357 -0
  109. package/node_modules/pi-commandcode-provider/src/responses-stream.ts +249 -0
  110. package/node_modules/pi-commandcode-provider/src/runtime.ts +330 -0
  111. package/node_modules/pi-commandcode-provider/src/transcript.ts +56 -0
  112. package/node_modules/pi-commandcode-provider/src/transport.ts +147 -0
  113. package/node_modules/pi-commandcode-provider/src/types.ts +212 -0
  114. package/node_modules/pi-commandcode-provider/src/usage.ts +261 -0
  115. package/node_modules/pi-lens/CHANGELOG.md +149 -0
  116. package/node_modules/pi-lens/README.md +12 -2
  117. package/node_modules/pi-lens/config/markdownlint/run-no-fix.mjs +36 -0
  118. package/node_modules/pi-lens/dist/{chunk-WME2OQST.js → chunk-2453RRJ2.js} +11 -6
  119. package/node_modules/pi-lens/dist/{chunk-FZKFVUEC.js → chunk-2BKUFQKR.js} +276 -208
  120. package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +31 -0
  121. package/node_modules/pi-lens/dist/{chunk-QHSNL7B2.js → chunk-2ZE3AUJQ.js} +12 -14
  122. package/node_modules/pi-lens/dist/{chunk-MPKRJBPK.js → chunk-35WKJWO5.js} +28 -30
  123. package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +27 -0
  124. package/node_modules/pi-lens/dist/{chunk-4LM3VAZH.js → chunk-3O5EII3W.js} +2 -2
  125. package/node_modules/pi-lens/dist/chunk-447YZL4S.js +25 -0
  126. package/node_modules/pi-lens/dist/{chunk-H7OR7DFZ.js → chunk-4B2YFN4U.js} +25 -21
  127. package/node_modules/pi-lens/dist/{chunk-OSTKYB55.js → chunk-4BKU7PV3.js} +1 -1
  128. package/node_modules/pi-lens/dist/{chunk-RRV3FNNM.js → chunk-4LL2VRNY.js} +27 -28
  129. package/node_modules/pi-lens/dist/{chunk-BZARLRJW.js → chunk-4NBWFYWW.js} +9 -9
  130. package/node_modules/pi-lens/dist/{chunk-KKCK636N.js → chunk-4QG55RRC.js} +12 -12
  131. package/node_modules/pi-lens/dist/{chunk-RQS4QQSD.js → chunk-4W52ZKZX.js} +2 -2
  132. package/node_modules/pi-lens/dist/{chunk-Z2XAOKHK.js → chunk-565VRUP4.js} +2 -2
  133. package/node_modules/pi-lens/dist/{chunk-HWDAVBFU.js → chunk-57X2CDRX.js} +23 -23
  134. package/node_modules/pi-lens/dist/{chunk-MB6PXBUA.js → chunk-5F3XF3SX.js} +7 -15
  135. package/node_modules/pi-lens/dist/{chunk-O4BJFESU.js → chunk-5RNB4HVK.js} +1 -1
  136. package/node_modules/pi-lens/dist/{chunk-ZMAUPOMG.js → chunk-5T5A6YAJ.js} +35 -34
  137. package/node_modules/pi-lens/dist/{chunk-4ZYJHQMB.js → chunk-6FIRFP6A.js} +12 -12
  138. package/node_modules/pi-lens/dist/{chunk-4YHYPW2G.js → chunk-6GMGEKQN.js} +9 -5
  139. package/node_modules/pi-lens/dist/{chunk-4LOE5R5P.js → chunk-6LJOJ6EO.js} +20 -15
  140. package/node_modules/pi-lens/dist/{chunk-3YY7IXIL.js → chunk-6YUNI7B5.js} +3 -3
  141. package/node_modules/pi-lens/dist/{chunk-PKES3ISE.js → chunk-7ANZ7XDD.js} +2 -2
  142. package/node_modules/pi-lens/dist/{chunk-FB5SCCPT.js → chunk-7CGIDRIK.js} +16 -15
  143. package/node_modules/pi-lens/dist/{chunk-L3CMBQMH.js → chunk-7MAD5ZAY.js} +16 -17
  144. package/node_modules/pi-lens/dist/{chunk-WDBICWH3.js → chunk-7TNILKGY.js} +1 -1
  145. package/node_modules/pi-lens/dist/{chunk-RORGS5II.js → chunk-A5GRLYPZ.js} +9 -9
  146. package/node_modules/pi-lens/dist/{chunk-MNJIXFX4.js → chunk-AGGUWKRK.js} +1 -1
  147. package/node_modules/pi-lens/dist/{chunk-ABPKUVA4.js → chunk-BBET6HD6.js} +1 -1
  148. package/node_modules/pi-lens/dist/{chunk-L5JYIU47.js → chunk-BHWW6FAX.js} +14 -13
  149. package/node_modules/pi-lens/dist/{chunk-URCQWAQ4.js → chunk-BOPDQ7AZ.js} +23 -21
  150. package/node_modules/pi-lens/dist/{chunk-KDX35VXP.js → chunk-BQG2QFVO.js} +158 -133
  151. package/node_modules/pi-lens/dist/{chunk-CB4WHS4H.js → chunk-BUZIQDFS.js} +3 -3
  152. package/node_modules/pi-lens/dist/{chunk-2PHMIAKO.js → chunk-CM73PPGD.js} +4 -4
  153. package/node_modules/pi-lens/dist/{chunk-DH5JPM3K.js → chunk-CUDD35TW.js} +10 -9
  154. package/node_modules/pi-lens/dist/{chunk-AWDSEDER.js → chunk-CZL44WFN.js} +2 -2
  155. package/node_modules/pi-lens/dist/{chunk-N5WSK2K7.js → chunk-DIWK3LBC.js} +12 -15
  156. package/node_modules/pi-lens/dist/{chunk-24BILSZW.js → chunk-DYRZGUMA.js} +2 -2
  157. package/node_modules/pi-lens/dist/{chunk-PR6PO3ES.js → chunk-FHEV6T4L.js} +22 -18
  158. package/node_modules/pi-lens/dist/{chunk-DQZFQSR5.js → chunk-FRLAUP2B.js} +4 -4
  159. package/node_modules/pi-lens/dist/{chunk-RZOXUSPC.js → chunk-G5GV2Q7K.js} +2 -2
  160. package/node_modules/pi-lens/dist/{chunk-EKWX4WD3.js → chunk-G6JKM4O7.js} +7 -7
  161. package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +27 -0
  162. package/node_modules/pi-lens/dist/{chunk-XT2HTCJ5.js → chunk-GIRBSBGL.js} +6 -5
  163. package/node_modules/pi-lens/dist/{chunk-PQJFG24Z.js → chunk-GMROJJRN.js} +1292 -946
  164. package/node_modules/pi-lens/dist/{chunk-U6VN4NVL.js → chunk-HHR7WGCI.js} +3 -3
  165. package/node_modules/pi-lens/dist/{chunk-TIQJPRDD.js → chunk-HKIL6DCL.js} +3 -2
  166. package/node_modules/pi-lens/dist/{chunk-SNDXCFRS.js → chunk-HUAM7QG3.js} +11 -11
  167. package/node_modules/pi-lens/dist/{chunk-QOE342SU.js → chunk-HXFUTMX2.js} +2 -2
  168. package/node_modules/pi-lens/dist/{chunk-U7BD2QL7.js → chunk-I22THIHI.js} +12 -12
  169. package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +58 -0
  170. package/node_modules/pi-lens/dist/{chunk-DPGEAHZT.js → chunk-IYVYZQRL.js} +10 -16
  171. package/node_modules/pi-lens/dist/{chunk-3F6BMY53.js → chunk-JBP7KESM.js} +1 -1
  172. package/node_modules/pi-lens/dist/{chunk-U5HPROLA.js → chunk-JE6HKLC7.js} +2 -2
  173. package/node_modules/pi-lens/dist/{chunk-ZE3KXHS7.js → chunk-JPRDTY5S.js} +85 -3
  174. package/node_modules/pi-lens/dist/{chunk-HO6LWE2E.js → chunk-JYLOYTZD.js} +17 -1
  175. package/node_modules/pi-lens/dist/{chunk-KW5JQPO5.js → chunk-JZRP4DGP.js} +2 -2
  176. package/node_modules/pi-lens/dist/{chunk-CPSR3AVL.js → chunk-KZ4ALBCH.js} +2 -2
  177. package/node_modules/pi-lens/dist/{chunk-6IR3ZYIB.js → chunk-L3CLUGDY.js} +3 -3
  178. package/node_modules/pi-lens/dist/{chunk-LV4UMYVH.js → chunk-L4NEVZ4T.js} +28 -27
  179. package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +22 -0
  180. package/node_modules/pi-lens/dist/{chunk-WGRJOXED.js → chunk-LSFXZLPW.js} +1016 -636
  181. package/node_modules/pi-lens/dist/{chunk-LBLBAFG3.js → chunk-MC6VB2E5.js} +4 -4
  182. package/node_modules/pi-lens/dist/{chunk-U2SDMG7C.js → chunk-NM2NWH55.js} +5 -5
  183. package/node_modules/pi-lens/dist/{chunk-T7A2HK2B.js → chunk-NSPVR3FN.js} +19 -18
  184. package/node_modules/pi-lens/dist/{chunk-ZGSJDWQU.js → chunk-O2ARHQKF.js} +2 -2
  185. package/node_modules/pi-lens/dist/{chunk-OXOI55RU.js → chunk-O4N5BQ3T.js} +10 -10
  186. package/node_modules/pi-lens/dist/{chunk-3FRLWYBG.js → chunk-OC7VWJBZ.js} +39 -40
  187. package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +89 -0
  188. package/node_modules/pi-lens/dist/{chunk-HR3OJ3TH.js → chunk-OWTG6UMO.js} +21 -21
  189. package/node_modules/pi-lens/dist/{chunk-75GAYVNO.js → chunk-OY7WZI7Q.js} +6 -6
  190. package/node_modules/pi-lens/dist/{chunk-ZJTT47IG.js → chunk-OZWXLJMX.js} +2 -2
  191. package/node_modules/pi-lens/dist/{chunk-F6X3YJWD.js → chunk-PIQQM32Y.js} +2 -2
  192. package/node_modules/pi-lens/dist/chunk-PKLB2XJL.js +8 -0
  193. package/node_modules/pi-lens/dist/{chunk-EAOK7MIZ.js → chunk-PKSUMEPT.js} +17 -4
  194. package/node_modules/pi-lens/dist/{chunk-YISME6ON.js → chunk-PPKECBPP.js} +1 -1
  195. package/node_modules/pi-lens/dist/{chunk-4L36HG27.js → chunk-R2QQC33W.js} +14 -14
  196. package/node_modules/pi-lens/dist/{chunk-LUBPZN36.js → chunk-R4QWJQ2H.js} +11 -11
  197. package/node_modules/pi-lens/dist/{chunk-V63BC55Q.js → chunk-RGGH6M34.js} +1 -1
  198. package/node_modules/pi-lens/dist/{chunk-Y7F7IEE3.js → chunk-RZG472YW.js} +65 -7
  199. package/node_modules/pi-lens/dist/{chunk-PUZ3E2J4.js → chunk-SDFKOLSF.js} +6 -6
  200. package/node_modules/pi-lens/dist/{chunk-YHC2O2WO.js → chunk-SFLHSL5R.js} +9 -9
  201. package/node_modules/pi-lens/dist/{chunk-CCV2EU7T.js → chunk-SP4TFY5F.js} +14 -13
  202. package/node_modules/pi-lens/dist/{chunk-J6JP25XU.js → chunk-SQC7K3SP.js} +4 -3
  203. package/node_modules/pi-lens/dist/{chunk-3K2F6UDZ.js → chunk-T2S3FNNJ.js} +44 -42
  204. package/node_modules/pi-lens/dist/{chunk-2TF6RXWB.js → chunk-TV6RXRYH.js} +10 -10
  205. package/node_modules/pi-lens/dist/{chunk-GNSIWBAT.js → chunk-U3AS2FR6.js} +3 -3
  206. package/node_modules/pi-lens/dist/{chunk-F7K5IBZG.js → chunk-UHHLR2VY.js} +40 -40
  207. package/node_modules/pi-lens/dist/chunk-UYXV5NIS.js +20 -0
  208. package/node_modules/pi-lens/dist/{chunk-VSFLRN5Y.js → chunk-VLQ7UKZH.js} +1 -1
  209. package/node_modules/pi-lens/dist/{chunk-VUZWQ7UG.js → chunk-VN3L2JWZ.js} +46 -72
  210. package/node_modules/pi-lens/dist/{chunk-NA7SEXHE.js → chunk-VOP4PJKA.js} +7 -7
  211. package/node_modules/pi-lens/dist/{chunk-F5Z6URKM.js → chunk-VOXTCULR.js} +2 -2
  212. package/node_modules/pi-lens/dist/{chunk-LLS45EWB.js → chunk-VPLBLWFO.js} +6 -8
  213. package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +27 -0
  214. package/node_modules/pi-lens/dist/{chunk-ZKXQKGWZ.js → chunk-WC6WRNQT.js} +4 -3
  215. package/node_modules/pi-lens/dist/{chunk-YVHBNSME.js → chunk-WMDUT4KH.js} +1148 -1132
  216. package/node_modules/pi-lens/dist/{chunk-KXF5R4UN.js → chunk-WQV6BI4Q.js} +1 -1
  217. package/node_modules/pi-lens/dist/chunk-WXUDRAG6.js +24 -0
  218. package/node_modules/pi-lens/dist/{chunk-KPPJTH44.js → chunk-X35S7HSB.js} +28 -10
  219. package/node_modules/pi-lens/dist/{chunk-JMEKXFOL.js → chunk-X66YJ2SS.js} +40 -34
  220. package/node_modules/pi-lens/dist/{chunk-CE6VMBCB.js → chunk-XOMGO63G.js} +22 -21
  221. package/node_modules/pi-lens/dist/{chunk-LS3QJRUB.js → chunk-XWIME22V.js} +13 -13
  222. package/node_modules/pi-lens/dist/{chunk-R5MOQM2H.js → chunk-XYLC35E4.js} +119 -87
  223. package/node_modules/pi-lens/dist/{chunk-OE5ZBP7F.js → chunk-YHGYAEFH.js} +18 -18
  224. package/node_modules/pi-lens/dist/{chunk-7E2563GA.js → chunk-ZFORSIED.js} +13 -13
  225. package/node_modules/pi-lens/dist/{chunk-E7HJ56Y7.js → chunk-ZKLTNLAW.js} +64 -73
  226. package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +74 -0
  227. package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +30 -0
  228. package/node_modules/pi-lens/dist/{chunk-RC2Z6K47.js → chunk-ZZDIOAAJ.js} +15 -6
  229. package/node_modules/pi-lens/dist/index.js +6993 -5396
  230. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +10 -10
  231. package/node_modules/pi-lens/dist/mcp/cli.js +44 -42
  232. package/node_modules/pi-lens/dist/mcp/server.js +1627 -504
  233. package/node_modules/pi-lens/dist/mcp/worker.js +62 -61
  234. package/node_modules/pi-lens/dist/probes/installer.js +20 -19
  235. package/node_modules/pi-lens/docs/adr/0003-git-guard-latch-writer.md +11 -6
  236. package/node_modules/pi-lens/docs/agent-tools.md +18 -8
  237. package/node_modules/pi-lens/docs/alignment-families.md +29 -0
  238. package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +6 -4
  239. package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +126 -0
  240. package/node_modules/pi-lens/docs/configuration.md +99 -3
  241. package/node_modules/pi-lens/docs/defect-shapes.md +55 -12
  242. package/node_modules/pi-lens/docs/engineering-principles.md +27 -2
  243. package/node_modules/pi-lens/docs/features.md +2 -2
  244. package/node_modules/pi-lens/docs/invariants/git-guard-host.md +7 -3
  245. package/node_modules/pi-lens/docs/invariants/language-config.md +15 -4
  246. package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +16 -2
  247. package/node_modules/pi-lens/docs/invariants/paths-os.md +4 -2
  248. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +119 -39
  249. package/node_modules/pi-lens/docs/merge-queue-rollout.md +1 -1
  250. package/node_modules/pi-lens/docs/pi-lens-fixer.md +24 -17
  251. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +20 -11
  252. package/node_modules/pi-lens/docs/pi-lens-monitor.md +9 -0
  253. package/node_modules/pi-lens/docs/pi-lens-orchestration.md +4 -1
  254. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +5 -5
  255. package/node_modules/pi-lens/docs/pi-lens-subagent.md +6 -3
  256. package/node_modules/pi-lens/docs/public-api-stability.md +18 -2
  257. package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +10 -0
  258. package/node_modules/pi-lens/docs/settings.md +10 -6
  259. package/node_modules/pi-lens/docs/word-index.md +17 -5
  260. package/node_modules/pi-lens/package.json +5 -3
  261. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-accumulating-spread-js-test.yml +37 -0
  262. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ts-redundant-filter-map-test.yml +12 -1
  263. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-js-test.yml +12 -0
  264. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests-disabled/filter-then-map-test.yml +25 -0
  265. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-accumulating-spread-js.yml +49 -1
  266. package/node_modules/pi-lens/rules/ast-grep-rules/rules/ts-redundant-filter-map.yml +9 -1
  267. package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map-js.yml +17 -0
  268. package/node_modules/pi-lens/rules/ast-grep-rules/rules-disabled/filter-then-map.yml +36 -0
  269. package/node_modules/pi-lens/rules/ast-grep-rules/self-scan-baseline.json +1 -1
  270. package/node_modules/pi-provider-qoder/README.md +22 -0
  271. package/node_modules/pi-provider-qoder/dist/index.js +375 -12
  272. package/node_modules/pi-provider-qoder/package.json +5 -2
  273. package/package.json +17 -13
  274. package/node_modules/@tifan/pi-preferred-thinking/README.md +0 -54
  275. package/node_modules/@tifan/pi-preferred-thinking/package.json +0 -43
  276. package/node_modules/@tifan/pi-preferred-thinking/src/index.ts +0 -236
  277. package/node_modules/pi-lens/dist/chunk-46TNM7XZ.js +0 -88
  278. package/node_modules/pi-lens/dist/chunk-72OKUXSD.js +0 -31
  279. package/node_modules/pi-lens/dist/chunk-7GLOLOSH.js +0 -57
  280. package/node_modules/pi-lens/dist/chunk-AKUUMGD5.js +0 -26
  281. package/node_modules/pi-lens/dist/chunk-ASUXV767.js +0 -22
  282. package/node_modules/pi-lens/dist/chunk-CTADOKYM.js +0 -25
  283. package/node_modules/pi-lens/dist/chunk-JJ2RRESP.js +0 -58
  284. package/node_modules/pi-lens/dist/chunk-LSC3VADM.js +0 -23
  285. package/node_modules/pi-lens/dist/chunk-SHLDT3OI.js +0 -27
  286. package/node_modules/pi-lens/dist/chunk-UF7RTZSO.js +0 -27
  287. package/node_modules/pi-lens/dist/chunk-W4WP2ERB.js +0 -30
  288. package/node_modules/pi-lens/dist/chunk-YES5CACN.js +0 -73
@@ -0,0 +1,515 @@
1
+ import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises"
2
+ import { basename, dirname, join } from "node:path"
3
+
4
+ import { MODEL_EFFORT_OVERRIDES } from "./commandcode-catalog-overrides.ts"
5
+ import {
6
+ MODEL_EFFORTS as CATALOG_MODEL_EFFORTS,
7
+ MODEL_INPUT_MODALITIES,
8
+ MODEL_MAX_OUTPUT_TOKENS,
9
+ MODEL_REASONING,
10
+ type CommandCodeInputType,
11
+ type CommandCodeReasoningEffort,
12
+ } from "./commandcode-catalog.ts"
13
+
14
+ /** Upstream CLI efforts with the manual overrides merged over them. */
15
+ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasoningEffort[]>> = {
16
+ ...CATALOG_MODEL_EFFORTS,
17
+ ...MODEL_EFFORT_OVERRIDES,
18
+ }
19
+
20
+ export { MODEL_INPUT_MODALITIES, MODEL_MAX_OUTPUT_TOKENS, MODEL_REASONING }
21
+ export type { CommandCodeInputType }
22
+
23
+ export const DEFAULT_PROVIDER_API_BASE = "https://api.commandcode.ai/provider/v1"
24
+ export const DEFAULT_MODELS_URL = `${DEFAULT_PROVIDER_API_BASE}/models`
25
+ export const DEFAULT_MODELS_TIMEOUT_MS = 10_000
26
+
27
+ const DEFAULT_MAX_OUTPUT_TOKENS = 65_536
28
+ const MODEL_CACHE_VERSION = 2
29
+
30
+ /**
31
+ * Provider API route serving a model over the OpenAI Responses wire. The
32
+ * models list advertises, per model, the routes that answer it.
33
+ */
34
+ const RESPONSES_ENDPOINT = "/responses"
35
+
36
+ export type CommandCodeApi = "openai-completions" | "openai-responses" | "anthropic-messages"
37
+
38
+ const COMMAND_CODE_APIS: readonly string[] = [
39
+ "openai-completions",
40
+ "openai-responses",
41
+ "anthropic-messages",
42
+ ]
43
+
44
+ function isCommandCodeApi(value: unknown): value is CommandCodeApi {
45
+ return typeof value === "string" && COMMAND_CODE_APIS.includes(value)
46
+ }
47
+
48
+ const TEXT_INPUT_ONLY = ["text"] as const
49
+
50
+ /**
51
+ * Input modalities for a model.
52
+ *
53
+ * The generated catalog is a snapshot of one Command Code CLI release, so a
54
+ * model published afterwards is absent and silently degrades to text-only.
55
+ * The host's resolved `model.input` is authoritative when present: it already
56
+ * carries `models.yml`/`models.json` overrides and is what decides whether the
57
+ * user can attach an image at all.
58
+ */
59
+ export function inputModalitiesForModel(
60
+ modelId: string,
61
+ hostInput?: readonly string[],
62
+ ): readonly CommandCodeInputType[] {
63
+ if (hostInput && hostInput.length > 0) {
64
+ return hostInput.filter(
65
+ (input): input is CommandCodeInputType => input === "text" || input === "image",
66
+ )
67
+ }
68
+ return MODEL_INPUT_MODALITIES[modelId] ?? TEXT_INPUT_ONLY
69
+ }
70
+
71
+ export function modelSupportsImageInput(modelId: string, hostInput?: readonly string[]): boolean {
72
+ return inputModalitiesForModel(modelId, hostInput).includes("image")
73
+ }
74
+
75
+ export type PiThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"
76
+
77
+ const PI_THINKING_LEVELS: readonly PiThinkingLevel[] = [
78
+ "off",
79
+ "minimal",
80
+ "low",
81
+ "medium",
82
+ "high",
83
+ "xhigh",
84
+ "max",
85
+ ]
86
+
87
+ export function thinkingLevelMapForEfforts(
88
+ efforts: readonly string[],
89
+ ): Partial<Record<PiThinkingLevel, string | null>> {
90
+ const map: Partial<Record<PiThinkingLevel, string | null>> = {}
91
+ for (const level of PI_THINKING_LEVELS) {
92
+ if (level === "off") continue
93
+ map[level] = efforts.includes(level) ? level : null
94
+ }
95
+ return map
96
+ }
97
+
98
+ export interface ThinkingMetadata {
99
+ thinkingLevelMap: Partial<Record<PiThinkingLevel, string | null>>
100
+ thinking?: {
101
+ mode: "effort"
102
+ effortMap: Partial<Record<CommandCodeReasoningEffort, string>>
103
+ efforts: readonly CommandCodeReasoningEffort[]
104
+ }
105
+ }
106
+
107
+ export function thinkingMetadataForModel(modelId: string): ThinkingMetadata | undefined {
108
+ const efforts = MODEL_EFFORTS[modelId]
109
+ if (efforts) {
110
+ return {
111
+ thinkingLevelMap: thinkingLevelMapForEfforts(efforts),
112
+ thinking: {
113
+ mode: "effort",
114
+ effortMap: Object.fromEntries(efforts.map((effort) => [effort, effort])),
115
+ efforts,
116
+ },
117
+ }
118
+ }
119
+ if (!isReasoningModel(modelId)) return undefined
120
+ return { thinkingLevelMap: thinkingLevelMapForEfforts([]) }
121
+ }
122
+
123
+ function isReasoningModel(modelId: string): boolean {
124
+ return MODEL_REASONING[modelId] === true
125
+ }
126
+
127
+ function maxOutputTokensForModel(modelId: string, contextLength: number): number {
128
+ return Math.min(contextLength, MODEL_MAX_OUTPUT_TOKENS[modelId] ?? DEFAULT_MAX_OUTPUT_TOKENS)
129
+ }
130
+
131
+ interface ApiModel {
132
+ id: string
133
+ name: string
134
+ contextLength: number
135
+ supportedEndpoints?: readonly string[]
136
+ }
137
+
138
+ export interface CommandCodeModel {
139
+ id: string
140
+ name: string
141
+ api: CommandCodeApi
142
+ reasoning: boolean
143
+ contextWindow: number
144
+ maxTokens: number
145
+ }
146
+
147
+ /**
148
+ * Resolves a model to the Provider API wire that serves it.
149
+ *
150
+ * Claude models answer on `/v1/messages` only. Every other model answers on
151
+ * `/v1/chat/completions`, and `/provider/v1/models` advertises which of them
152
+ * also serve `/v1/responses`; those use the OpenAI Responses wire. Without
153
+ * endpoint metadata the model keeps Chat Completions, which every non-Claude
154
+ * model serves, so a catalog that omits the field never breaks.
155
+ */
156
+ export function apiForModelId(id: string, supportedEndpoints?: readonly string[]): CommandCodeApi {
157
+ if (id.startsWith("claude-")) return "anthropic-messages"
158
+ return supportedEndpoints?.includes(RESPONSES_ENDPOINT)
159
+ ? "openai-responses"
160
+ : "openai-completions"
161
+ }
162
+
163
+ export function baseUrlForModel(apiBase: string, api: CommandCodeApi): string {
164
+ const normalized = apiBase.replace(/\/+$/g, "")
165
+ if (api !== "anthropic-messages") return normalized
166
+ return normalized.endsWith("/v1") ? normalized.slice(0, -3) : normalized
167
+ }
168
+
169
+ interface FetchCommandCodeModelsOptions {
170
+ url?: string
171
+ fetchImpl?: typeof fetch
172
+ signal?: AbortSignal
173
+ timeoutMs?: number
174
+ }
175
+
176
+ interface LoadCommandCodeModelsOptions extends FetchCommandCodeModelsOptions {
177
+ cachePath: string
178
+ }
179
+
180
+ export interface LoadCommandCodeModelsResult {
181
+ models: readonly CommandCodeModel[]
182
+ source: "live" | "cache" | "empty"
183
+ warning?: string
184
+ }
185
+
186
+ function isRecord(value: unknown): value is Record<string, unknown> {
187
+ return typeof value === "object" && value !== null && !Array.isArray(value)
188
+ }
189
+
190
+ function stringField(record: Record<string, unknown>, key: string): string {
191
+ const value = record[key]
192
+ if (typeof value !== "string" || value.length === 0) {
193
+ throw new Error(`Expected ${key} to be a non-empty string`)
194
+ }
195
+ return value
196
+ }
197
+
198
+ /** Optional string-array field. Unknown shapes are ignored so discovery keeps working. */
199
+ function optionalStringArrayField(
200
+ record: Record<string, unknown>,
201
+ key: string,
202
+ ): readonly string[] | undefined {
203
+ const value = record[key]
204
+ if (!Array.isArray(value)) return undefined
205
+ const strings = value.filter((entry): entry is string => typeof entry === "string")
206
+ return strings.length > 0 ? strings : undefined
207
+ }
208
+
209
+ function booleanField(record: Record<string, unknown>, key: string): boolean {
210
+ const value = record[key]
211
+ if (typeof value !== "boolean") throw new Error(`Expected ${key} to be a boolean`)
212
+ return value
213
+ }
214
+
215
+ function positiveNumberField(record: Record<string, unknown>, key: string): number {
216
+ const value = record[key]
217
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
218
+ throw new Error(`Expected ${key} to be a positive number`)
219
+ }
220
+ return value
221
+ }
222
+
223
+ function parseApiModel(value: unknown): ApiModel {
224
+ if (!isRecord(value)) throw new Error("Expected model entry to be an object")
225
+
226
+ const supportedEndpoints = optionalStringArrayField(value, "supported_endpoints")
227
+ return {
228
+ id: stringField(value, "id"),
229
+ name: stringField(value, "name"),
230
+ contextLength: positiveNumberField(value, "context_length"),
231
+ ...(supportedEndpoints ? { supportedEndpoints } : {}),
232
+ }
233
+ }
234
+
235
+ function parseCachedModel(value: unknown): CommandCodeModel {
236
+ if (!isRecord(value)) throw new Error("Expected cached model entry to be an object")
237
+
238
+ const id = stringField(value, "id")
239
+ booleanField(value, "reasoning")
240
+ positiveNumberField(value, "maxTokens")
241
+ const contextWindow = positiveNumberField(value, "contextWindow")
242
+ const api = value.api
243
+ return {
244
+ id,
245
+ name: stringField(value, "name"),
246
+ api: isCommandCodeApi(api) ? api : apiForModelId(id),
247
+ reasoning: isReasoningModel(id),
248
+ contextWindow,
249
+ maxTokens: maxOutputTokensForModel(id, contextWindow),
250
+ }
251
+ }
252
+
253
+ function requireModels(models: readonly CommandCodeModel[]): readonly CommandCodeModel[] {
254
+ if (models.length === 0) throw new Error("Command Code returned an empty model catalog")
255
+ return models
256
+ }
257
+
258
+ function errorMessage(error: unknown): string {
259
+ return error instanceof Error ? error.message : String(error)
260
+ }
261
+
262
+ function abortError(reason: unknown): Error {
263
+ if (reason instanceof Error) return reason
264
+ return new DOMException("The operation was aborted", "AbortError")
265
+ }
266
+
267
+ function configuredTimeoutMs(timeoutMs: number | undefined): number {
268
+ return timeoutMs !== undefined && Number.isFinite(timeoutMs) && timeoutMs > 0
269
+ ? timeoutMs
270
+ : DEFAULT_MODELS_TIMEOUT_MS
271
+ }
272
+
273
+ export function getModelsTimeoutMs(env: NodeJS.ProcessEnv = process.env): number {
274
+ const raw = env.COMMANDCODE_MODELS_TIMEOUT_MS
275
+ if (!raw) return DEFAULT_MODELS_TIMEOUT_MS
276
+
277
+ const parsed = Number(raw)
278
+ return configuredTimeoutMs(parsed)
279
+ }
280
+
281
+ class ModelDiscoveryTimeoutError extends Error {
282
+ constructor(timeoutMs: number) {
283
+ super(`Command Code model discovery timed out after ${timeoutMs}ms`)
284
+ this.name = "ModelDiscoveryTimeoutError"
285
+ }
286
+ }
287
+
288
+ function runWithTimeout<T>(
289
+ operation: (signal: AbortSignal) => Promise<T>,
290
+ timeoutMs: number,
291
+ externalSignal: AbortSignal | undefined,
292
+ ): Promise<T> {
293
+ const controller = new AbortController()
294
+ let timer: ReturnType<typeof setTimeout> | undefined
295
+ let settled = false
296
+ let onExternalAbort: (() => void) | undefined
297
+
298
+ return new Promise<T>((resolve, reject) => {
299
+ const cleanup = () => {
300
+ if (timer !== undefined) clearTimeout(timer)
301
+ if (onExternalAbort && externalSignal) {
302
+ externalSignal.removeEventListener("abort", onExternalAbort)
303
+ }
304
+ }
305
+
306
+ const resolveOnce = (value: T) => {
307
+ if (settled) return
308
+ settled = true
309
+ cleanup()
310
+ resolve(value)
311
+ }
312
+
313
+ const rejectOnce = (error: unknown) => {
314
+ if (settled) return
315
+ settled = true
316
+ cleanup()
317
+ reject(error)
318
+ }
319
+
320
+ const abort = (reason: unknown) => {
321
+ const error = abortError(reason)
322
+ controller.abort(error)
323
+ rejectOnce(error)
324
+ }
325
+
326
+ if (externalSignal?.aborted) {
327
+ abort(externalSignal.reason)
328
+ return
329
+ }
330
+
331
+ onExternalAbort = () => abort(externalSignal?.reason)
332
+ externalSignal?.addEventListener("abort", onExternalAbort, { once: true })
333
+ timer = setTimeout(() => abort(new ModelDiscoveryTimeoutError(timeoutMs)), timeoutMs)
334
+
335
+ Promise.resolve()
336
+ .then(() => operation(controller.signal))
337
+ .then(resolveOnce, rejectOnce)
338
+ })
339
+ }
340
+
341
+ export function commandCodeModelsFromApiResponse(value: unknown): readonly CommandCodeModel[] {
342
+ if (!isRecord(value)) throw new Error("Expected models response to be an object")
343
+ if (value.object !== "list") throw new Error("Expected models response object to be 'list'")
344
+
345
+ const data = value.data
346
+ if (!Array.isArray(data)) throw new Error("Expected models response data to be an array")
347
+
348
+ return data.map(parseApiModel).map((model) => ({
349
+ id: model.id,
350
+ name: `${model.name} (CC)`,
351
+ api: apiForModelId(model.id, model.supportedEndpoints),
352
+ reasoning: isReasoningModel(model.id),
353
+ contextWindow: model.contextLength,
354
+ maxTokens: maxOutputTokensForModel(model.id, model.contextLength),
355
+ }))
356
+ }
357
+
358
+ export function commandCodeModelsFromCache(value: unknown): readonly CommandCodeModel[] {
359
+ if (!isRecord(value)) throw new Error("Expected model cache to be an object")
360
+ if (value.version !== MODEL_CACHE_VERSION) {
361
+ throw new Error(`Expected model cache version ${MODEL_CACHE_VERSION}`)
362
+ }
363
+ if (!Array.isArray(value.models)) throw new Error("Expected cached models to be an array")
364
+
365
+ return requireModels(value.models.map(parseCachedModel))
366
+ }
367
+
368
+ export async function fetchCommandCodeModels(
369
+ options: FetchCommandCodeModelsOptions = {},
370
+ ): Promise<readonly CommandCodeModel[]> {
371
+ const url = options.url ?? DEFAULT_MODELS_URL
372
+ const fetchImpl = options.fetchImpl ?? fetch
373
+ const body: unknown = await runWithTimeout(
374
+ async (signal) => {
375
+ const response = await fetchImpl(url, {
376
+ headers: {
377
+ accept: "application/json",
378
+ },
379
+ signal,
380
+ })
381
+
382
+ if (!response.ok) {
383
+ throw new Error(
384
+ `Failed to fetch Command Code models: ${response.status} ${response.statusText}`,
385
+ )
386
+ }
387
+
388
+ return await response.json()
389
+ },
390
+ configuredTimeoutMs(options.timeoutMs),
391
+ options.signal,
392
+ )
393
+ return requireModels(commandCodeModelsFromApiResponse(body))
394
+ }
395
+
396
+ async function readCommandCodeModelsCache(cachePath: string): Promise<readonly CommandCodeModel[]> {
397
+ const contents = await readFile(cachePath, "utf-8")
398
+ const parsed: unknown = JSON.parse(contents)
399
+ return commandCodeModelsFromCache(parsed)
400
+ }
401
+
402
+ /** Reads the cached catalog without touching the network; empty when missing or invalid. */
403
+ export async function loadCachedCommandCodeModels(
404
+ cachePath: string,
405
+ ): Promise<readonly CommandCodeModel[]> {
406
+ try {
407
+ return await readCommandCodeModelsCache(cachePath)
408
+ } catch {
409
+ return []
410
+ }
411
+ }
412
+
413
+ /** Temporary cache files older than this are treated as orphaned and swept. */
414
+ const STALE_TEMPORARY_CACHE_MS = 60 * 60 * 1000
415
+
416
+ async function removeStaleTemporaryCaches(
417
+ cachePath: string,
418
+ currentTemporaryEntry: string,
419
+ ): Promise<void> {
420
+ // A host killed between the temp write and the rename below leaves an
421
+ // orphaned `<cache>.<pid>.tmp` behind (see #130): the background refresh
422
+ // is fire-and-forget, so exiting pi mid-write never reaches cleanup.
423
+ // Sweep those orphans on the next successful refresh. Files written
424
+ // recently are kept so concurrent hosts never delete each other's
425
+ // in-progress temp file.
426
+ const directory = dirname(cachePath)
427
+ const prefix = `${basename(cachePath)}.`
428
+ let entries: string[]
429
+ try {
430
+ entries = await readdir(directory)
431
+ } catch {
432
+ return
433
+ }
434
+ const now = Date.now()
435
+ await Promise.all(
436
+ entries
437
+ .filter(
438
+ (entry) =>
439
+ entry !== currentTemporaryEntry && entry.startsWith(prefix) && entry.endsWith(".tmp"),
440
+ )
441
+ .map(async (entry) => {
442
+ try {
443
+ const mtime = (await stat(join(directory, entry))).mtimeMs
444
+ if (now - mtime < STALE_TEMPORARY_CACHE_MS) return
445
+ await rm(join(directory, entry), { force: true })
446
+ } catch {
447
+ // Best-effort: a concurrent host may already have removed it.
448
+ }
449
+ }),
450
+ )
451
+ }
452
+
453
+ async function writeCommandCodeModelsCache(
454
+ cachePath: string,
455
+ models: readonly CommandCodeModel[],
456
+ ): Promise<void> {
457
+ await mkdir(dirname(cachePath), { recursive: true })
458
+ // Unique per attempt so two concurrent hosts never share a temp file.
459
+ const temporaryEntry = `${basename(cachePath)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`
460
+ const temporaryPath = join(dirname(cachePath), temporaryEntry)
461
+
462
+ try {
463
+ await removeStaleTemporaryCaches(cachePath, temporaryEntry)
464
+ await writeFile(
465
+ temporaryPath,
466
+ `${JSON.stringify({ version: MODEL_CACHE_VERSION, models }, null, 2)}\n`,
467
+ { encoding: "utf-8", mode: 0o600 },
468
+ )
469
+ await rename(temporaryPath, cachePath)
470
+ } finally {
471
+ try {
472
+ await rm(temporaryPath, { force: true })
473
+ } catch {
474
+ // Best-effort cleanup must not hide the original cache write error.
475
+ }
476
+ }
477
+ }
478
+
479
+ export async function loadCommandCodeModels(
480
+ options: LoadCommandCodeModelsOptions,
481
+ ): Promise<LoadCommandCodeModelsResult> {
482
+ const cachePath = options.cachePath
483
+
484
+ try {
485
+ const models = await fetchCommandCodeModels(options)
486
+
487
+ try {
488
+ await writeCommandCodeModelsCache(cachePath, models)
489
+ return { models, source: "live" }
490
+ } catch (error) {
491
+ return {
492
+ models,
493
+ source: "live",
494
+ warning: `Loaded the live Command Code model catalog but could not update ${cachePath}: ${errorMessage(error)}`,
495
+ }
496
+ }
497
+ } catch (liveError) {
498
+ if (options.signal?.aborted) throw abortError(options.signal.reason ?? liveError)
499
+
500
+ try {
501
+ const models = await readCommandCodeModelsCache(cachePath)
502
+ return {
503
+ models,
504
+ source: "cache",
505
+ warning: `Could not refresh the Command Code model catalog (${errorMessage(liveError)}). Using the cached catalog from ${cachePath}.`,
506
+ }
507
+ } catch (cacheError) {
508
+ return {
509
+ models: [],
510
+ source: "empty",
511
+ warning: `Could not refresh the Command Code model catalog (${errorMessage(liveError)}), and no valid cached catalog is available at ${cachePath} (${errorMessage(cacheError)}). Command Code models will remain unavailable until /commandcode-refresh succeeds.`,
512
+ }
513
+ }
514
+ }
515
+ }