@herbertgao/pi-extensions 2026.11.3 → 2026.11.4

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 (203) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +7 -7
  3. package/THIRD_PARTY_NOTICES.md +2 -2
  4. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
  5. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
  6. package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +33 -5
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +72 -17
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -2
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/tool-io.ts +16 -7
  11. package/node_modules/@herbertgao/pi-cc-extensions/package.json +7 -5
  12. package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-dark-hc.json +92 -0
  13. package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-light-hc.json +92 -0
  14. package/node_modules/pi-commandcode-provider/CHANGELOG.md +27 -0
  15. package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +64 -5
  16. package/node_modules/pi-commandcode-provider/README.md +40 -26
  17. package/node_modules/pi-commandcode-provider/RELEASE.md +25 -0
  18. package/node_modules/pi-commandcode-provider/index.ts +212 -38
  19. package/node_modules/pi-commandcode-provider/package.json +9 -8
  20. package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +6 -13
  21. package/node_modules/pi-commandcode-provider/scripts/typecheck-entrypoint.mjs +88 -0
  22. package/node_modules/pi-commandcode-provider/src/api-key.ts +43 -2
  23. package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +1 -1
  24. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +9 -2
  25. package/node_modules/pi-commandcode-provider/src/cost.ts +3 -37
  26. package/node_modules/pi-commandcode-provider/src/diagnostics.ts +215 -0
  27. package/node_modules/pi-commandcode-provider/src/oauth.ts +1 -1
  28. package/node_modules/pi-commandcode-provider/src/quota-command.ts +1 -1
  29. package/node_modules/pi-commandcode-provider/src/routing.ts +166 -0
  30. package/node_modules/pi-commandcode-provider/src/runtime.ts +15 -9
  31. package/node_modules/pi-commandcode-provider/src/transport.ts +79 -85
  32. package/node_modules/pi-commandcode-provider/src/types.ts +20 -39
  33. package/node_modules/pi-commandcode-provider/src/usage.ts +1 -1
  34. package/node_modules/pi-lens/CHANGELOG-USER.md +31 -0
  35. package/node_modules/pi-lens/CHANGELOG.md +178 -0
  36. package/node_modules/pi-lens/README.md +2 -1
  37. package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -1
  38. package/node_modules/pi-lens/dist/{chunk-3O5EII3W.js → chunk-2VZ3VN3N.js} +2 -2
  39. package/node_modules/pi-lens/dist/{chunk-SDFKOLSF.js → chunk-3HTZDY3C.js} +8 -6
  40. package/node_modules/pi-lens/dist/{chunk-A5GRLYPZ.js → chunk-3NPWO5UO.js} +7 -13
  41. package/node_modules/pi-lens/dist/{chunk-AGGUWKRK.js → chunk-47UCC4MM.js} +1 -1
  42. package/node_modules/pi-lens/dist/chunk-4ENEJHF4.js +198 -0
  43. package/node_modules/pi-lens/dist/{chunk-WXUDRAG6.js → chunk-5GEYJJHG.js} +10 -12
  44. package/node_modules/pi-lens/dist/{chunk-HHR7WGCI.js → chunk-5YSEQHJN.js} +3 -3
  45. package/node_modules/pi-lens/dist/{chunk-L3CLUGDY.js → chunk-6GPB3JLL.js} +3 -3
  46. package/node_modules/pi-lens/dist/{chunk-5F3XF3SX.js → chunk-7R5GZIA6.js} +6 -6
  47. package/node_modules/pi-lens/dist/{chunk-CUDD35TW.js → chunk-7UTSNTWM.js} +4 -4
  48. package/node_modules/pi-lens/dist/{chunk-DYRZGUMA.js → chunk-7YTRG6YW.js} +2 -2
  49. package/node_modules/pi-lens/dist/{chunk-JZRP4DGP.js → chunk-AACN5GNE.js} +2 -2
  50. package/node_modules/pi-lens/dist/{chunk-7ANZ7XDD.js → chunk-ACRJ2GZ5.js} +2 -2
  51. package/node_modules/pi-lens/dist/{chunk-6FIRFP6A.js → chunk-C3YRO3EU.js} +10 -12
  52. package/node_modules/pi-lens/dist/{chunk-GMROJJRN.js → chunk-CB7PEVOJ.js} +9 -1
  53. package/node_modules/pi-lens/dist/{chunk-BBET6HD6.js → chunk-CDFJF5YD.js} +1 -1
  54. package/node_modules/pi-lens/dist/{chunk-NSPVR3FN.js → chunk-CJS6WE66.js} +17 -19
  55. package/node_modules/pi-lens/dist/{chunk-6YUNI7B5.js → chunk-CM6BDY4E.js} +14 -60
  56. package/node_modules/pi-lens/dist/{chunk-G5GV2Q7K.js → chunk-CZCAZVTD.js} +16 -2
  57. package/node_modules/pi-lens/dist/chunk-DGKFWQK4.js +23 -0
  58. package/node_modules/pi-lens/dist/{chunk-VOP4PJKA.js → chunk-E65WJVI5.js} +7 -9
  59. package/node_modules/pi-lens/dist/{chunk-TV6RXRYH.js → chunk-EKNYSXFB.js} +8 -10
  60. package/node_modules/pi-lens/dist/{chunk-4LL2VRNY.js → chunk-EY6LY2HO.js} +16 -18
  61. package/node_modules/pi-lens/dist/{chunk-MC6VB2E5.js → chunk-F6BEQWAK.js} +17 -5
  62. package/node_modules/pi-lens/dist/{chunk-R2QQC33W.js → chunk-FGNSESAC.js} +12 -14
  63. package/node_modules/pi-lens/dist/{chunk-OC7VWJBZ.js → chunk-FRUBVFXV.js} +35 -37
  64. package/node_modules/pi-lens/dist/{chunk-7CGIDRIK.js → chunk-G22UNQID.js} +14 -16
  65. package/node_modules/pi-lens/dist/{chunk-L4NEVZ4T.js → chunk-GQTQUNCG.js} +25 -27
  66. package/node_modules/pi-lens/dist/{chunk-ZKLTNLAW.js → chunk-H3BVMK47.js} +6 -6
  67. package/node_modules/pi-lens/dist/chunk-H6FLQ5NW.js +28 -0
  68. package/node_modules/pi-lens/dist/{chunk-2ZE3AUJQ.js → chunk-HEA3EM23.js} +13 -15
  69. package/node_modules/pi-lens/dist/{chunk-CZL44WFN.js → chunk-HSOBIN22.js} +2 -2
  70. package/node_modules/pi-lens/dist/{chunk-PKSUMEPT.js → chunk-HYSKJMZK.js} +3 -3
  71. package/node_modules/pi-lens/dist/{chunk-VN3L2JWZ.js → chunk-IICERRFF.js} +5 -5
  72. package/node_modules/pi-lens/dist/{chunk-O4N5BQ3T.js → chunk-IILEH3ZC.js} +8 -10
  73. package/node_modules/pi-lens/dist/{chunk-WC6WRNQT.js → chunk-J3Q2NYJR.js} +2 -2
  74. package/node_modules/pi-lens/dist/{chunk-SFLHSL5R.js → chunk-JUZ67QZQ.js} +18 -7
  75. package/node_modules/pi-lens/dist/chunk-KR5VGMVT.js +25 -0
  76. package/node_modules/pi-lens/dist/{chunk-UHHLR2VY.js → chunk-KV6GQOGN.js} +38 -41
  77. package/node_modules/pi-lens/dist/{chunk-HUAM7QG3.js → chunk-KXMJLOZF.js} +25 -23
  78. package/node_modules/pi-lens/dist/{chunk-BUZIQDFS.js → chunk-L4Y3ROKQ.js} +3 -3
  79. package/node_modules/pi-lens/dist/{chunk-JBP7KESM.js → chunk-L6WBJGQS.js} +1 -1
  80. package/node_modules/pi-lens/dist/{chunk-35WKJWO5.js → chunk-L7O774U7.js} +14 -14
  81. package/node_modules/pi-lens/dist/{chunk-BOPDQ7AZ.js → chunk-LAHHGNAY.js} +19 -21
  82. package/node_modules/pi-lens/dist/{chunk-RGGH6M34.js → chunk-LT62P654.js} +1 -1
  83. package/node_modules/pi-lens/dist/{chunk-5T5A6YAJ.js → chunk-LWOM6LVS.js} +33 -34
  84. package/node_modules/pi-lens/dist/{chunk-JYLOYTZD.js → chunk-MKPDIAZH.js} +5 -1
  85. package/node_modules/pi-lens/dist/{chunk-CM73PPGD.js → chunk-MN635QYA.js} +3 -4
  86. package/node_modules/pi-lens/dist/{chunk-BQG2QFVO.js → chunk-MQ4PPCJB.js} +21 -29
  87. package/node_modules/pi-lens/dist/{chunk-HXFUTMX2.js → chunk-MRLH4MYU.js} +2 -2
  88. package/node_modules/pi-lens/dist/{chunk-XOMGO63G.js → chunk-N56BNAA6.js} +19 -21
  89. package/node_modules/pi-lens/dist/{chunk-7MAD5ZAY.js → chunk-N5CEGQPG.js} +14 -16
  90. package/node_modules/pi-lens/dist/{chunk-ZFORSIED.js → chunk-NCLO6E6N.js} +13 -33
  91. package/node_modules/pi-lens/dist/{chunk-SQC7K3SP.js → chunk-NL5LSKVD.js} +2 -2
  92. package/node_modules/pi-lens/dist/{chunk-I22THIHI.js → chunk-NMUSOZ2D.js} +10 -12
  93. package/node_modules/pi-lens/dist/{chunk-4NBWFYWW.js → chunk-NOWH2VA2.js} +8 -33
  94. package/node_modules/pi-lens/dist/{chunk-NM2NWH55.js → chunk-NUSXS6YB.js} +6 -5
  95. package/node_modules/pi-lens/dist/{chunk-OZWXLJMX.js → chunk-OSEKJEUU.js} +2 -2
  96. package/node_modules/pi-lens/dist/{chunk-2BKUFQKR.js → chunk-OUYAUXAT.js} +405 -181
  97. package/node_modules/pi-lens/dist/{chunk-JPRDTY5S.js → chunk-PBZNYHMM.js} +8 -10
  98. package/node_modules/pi-lens/dist/{chunk-JE6HKLC7.js → chunk-PIIUNJIT.js} +2 -4
  99. package/node_modules/pi-lens/dist/{chunk-ZZDIOAAJ.js → chunk-PRHYIA6X.js} +6 -6
  100. package/node_modules/pi-lens/dist/{chunk-4W52ZKZX.js → chunk-PXQ45SGD.js} +2 -2
  101. package/node_modules/pi-lens/dist/chunk-Q6JQKWPK.js +25 -0
  102. package/node_modules/pi-lens/dist/{chunk-PIQQM32Y.js → chunk-QB7T2PHK.js} +2 -2
  103. package/node_modules/pi-lens/dist/{chunk-HKIL6DCL.js → chunk-QGITU23N.js} +1 -1
  104. package/node_modules/pi-lens/dist/chunk-QJJKOHLH.js +57 -0
  105. package/node_modules/pi-lens/dist/{chunk-6LJOJ6EO.js → chunk-QP33NKYC.js} +14 -16
  106. package/node_modules/pi-lens/dist/{chunk-DIWK3LBC.js → chunk-QVBOXT3L.js} +8 -10
  107. package/node_modules/pi-lens/dist/{chunk-IYVYZQRL.js → chunk-RNJFRXEN.js} +5 -7
  108. package/node_modules/pi-lens/dist/{chunk-G6JKM4O7.js → chunk-RNXOWDM6.js} +10 -10
  109. package/node_modules/pi-lens/dist/{chunk-5RNB4HVK.js → chunk-RTFMDIKV.js} +1 -1
  110. package/node_modules/pi-lens/dist/{chunk-XWIME22V.js → chunk-SIQHOB6P.js} +11 -13
  111. package/node_modules/pi-lens/dist/{chunk-T2S3FNNJ.js → chunk-SLSMJPEF.js} +41 -42
  112. package/node_modules/pi-lens/dist/chunk-T5QSLSMM.js +50 -0
  113. package/node_modules/pi-lens/dist/chunk-TGQDAG4B.js +88 -0
  114. package/node_modules/pi-lens/dist/{chunk-6GMGEKQN.js → chunk-THYHUIDR.js} +39 -12
  115. package/node_modules/pi-lens/dist/{chunk-WMDUT4KH.js → chunk-TMNUTMT5.js} +72 -89
  116. package/node_modules/pi-lens/dist/{chunk-7TNILKGY.js → chunk-TOE2RRCS.js} +1 -1
  117. package/node_modules/pi-lens/dist/chunk-TYHPVE5H.js +25 -0
  118. package/node_modules/pi-lens/dist/chunk-UAKO2M6B.js +73 -0
  119. package/node_modules/pi-lens/dist/chunk-UC5AXW5Z.js +20 -0
  120. package/node_modules/pi-lens/dist/chunk-UTJP6WOS.js +28 -0
  121. package/node_modules/pi-lens/dist/{chunk-FRLAUP2B.js → chunk-UXTQ3QPD.js} +4 -4
  122. package/node_modules/pi-lens/dist/{chunk-4QG55RRC.js → chunk-V2WDBOLZ.js} +10 -12
  123. package/node_modules/pi-lens/dist/{chunk-FHEV6T4L.js → chunk-V67D6TMU.js} +8 -10
  124. package/node_modules/pi-lens/dist/{chunk-VLQ7UKZH.js → chunk-VCRVNLE7.js} +135 -2
  125. package/node_modules/pi-lens/dist/{chunk-KZ4ALBCH.js → chunk-VO4JFPTV.js} +2 -2
  126. package/node_modules/pi-lens/dist/{chunk-GIRBSBGL.js → chunk-VWLSU3XV.js} +3 -3
  127. package/node_modules/pi-lens/dist/{chunk-2453RRJ2.js → chunk-W5E72HJA.js} +59 -22
  128. package/node_modules/pi-lens/dist/{chunk-VPLBLWFO.js → chunk-W7TY6HYX.js} +1 -1
  129. package/node_modules/pi-lens/dist/{chunk-SP4TFY5F.js → chunk-WSSLVMDA.js} +11 -13
  130. package/node_modules/pi-lens/dist/{chunk-PPKECBPP.js → chunk-WTB4GKMH.js} +10 -1
  131. package/node_modules/pi-lens/dist/{chunk-X35S7HSB.js → chunk-X5BJ3G2P.js} +41 -30
  132. package/node_modules/pi-lens/dist/{chunk-X66YJ2SS.js → chunk-XKFO2SZV.js} +33 -34
  133. package/node_modules/pi-lens/dist/{chunk-OWTG6UMO.js → chunk-XLAI7UYY.js} +75 -22
  134. package/node_modules/pi-lens/dist/{chunk-4B2YFN4U.js → chunk-XO756WE5.js} +45 -33
  135. package/node_modules/pi-lens/dist/{chunk-VOXTCULR.js → chunk-XVB3Q2PG.js} +2 -4
  136. package/node_modules/pi-lens/dist/{chunk-XYLC35E4.js → chunk-YOXCCJDF.js} +517 -308
  137. package/node_modules/pi-lens/dist/{chunk-O2ARHQKF.js → chunk-ZCQBNPRH.js} +2 -2
  138. package/node_modules/pi-lens/dist/chunk-ZD4KVFXI.js +234 -0
  139. package/node_modules/pi-lens/dist/{chunk-LSFXZLPW.js → chunk-ZDMFGACN.js} +184 -235
  140. package/node_modules/pi-lens/dist/{chunk-4BKU7PV3.js → chunk-ZMMHHXSW.js} +1 -1
  141. package/node_modules/pi-lens/dist/{chunk-OY7WZI7Q.js → chunk-ZPM7ZIFL.js} +6 -6
  142. package/node_modules/pi-lens/dist/{chunk-R4QWJQ2H.js → chunk-ZVCDHYWZ.js} +9 -11
  143. package/node_modules/pi-lens/dist/{chunk-RZG472YW.js → chunk-ZZN74OGD.js} +83 -46
  144. package/node_modules/pi-lens/dist/{chunk-BHWW6FAX.js → chunk-ZZSJAR76.js} +37 -19
  145. package/node_modules/pi-lens/dist/index.js +4910 -4218
  146. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +12 -17
  147. package/node_modules/pi-lens/dist/mcp/cli.js +41 -42
  148. package/node_modules/pi-lens/dist/mcp/server.js +1451 -648
  149. package/node_modules/pi-lens/dist/mcp/worker.js +59 -60
  150. package/node_modules/pi-lens/dist/probes/installer.js +17 -19
  151. package/node_modules/pi-lens/docs/agent-tools.md +40 -8
  152. package/node_modules/pi-lens/docs/analysisall.md +1 -1
  153. package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +7 -5
  154. package/node_modules/pi-lens/docs/configuration.md +51 -9
  155. package/node_modules/pi-lens/docs/defect-shapes.md +52 -3
  156. package/node_modules/pi-lens/docs/environment-variables.md +18 -1
  157. package/node_modules/pi-lens/docs/features.md +12 -5
  158. package/node_modules/pi-lens/docs/globalconfig.md +11 -3
  159. package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +9 -2
  160. package/node_modules/pi-lens/docs/invariants/session-telemetry.md +2 -2
  161. package/node_modules/pi-lens/docs/language-coverage.md +1 -0
  162. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +57 -35
  163. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +4 -1
  164. package/node_modules/pi-lens/docs/merge-queue-rollout.md +10 -8
  165. package/node_modules/pi-lens/docs/module-report-read-symbol.md +34 -23
  166. package/node_modules/pi-lens/docs/pi-lens-fixer.md +11 -1
  167. package/node_modules/pi-lens/docs/pi-lens-investigator.md +3 -0
  168. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +15 -7
  169. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +1 -1
  170. package/node_modules/pi-lens/docs/pi-lens-subagent.md +13 -0
  171. package/node_modules/pi-lens/docs/public-api-stability.md +39 -5
  172. package/node_modules/pi-lens/docs/release-qa-baseline.md +7 -4
  173. package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +11 -2
  174. package/node_modules/pi-lens/docs/servercapabilities.md +3 -1
  175. package/node_modules/pi-lens/docs/settings.md +2 -2
  176. package/node_modules/pi-lens/docs/word-index.md +3 -2
  177. package/node_modules/pi-lens/package.json +8 -3
  178. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +1 -2
  179. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +1 -2
  180. package/node_modules/pi-lens/scripts/download-grammars.js +3 -2
  181. package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +5 -1
  182. package/node_modules/pi-provider-qoder/dist/index.js +473 -62
  183. package/node_modules/pi-provider-qoder/package.json +1 -1
  184. package/package.json +10 -8
  185. package/node_modules/pi-commandcode-provider/src/converters.ts +0 -419
  186. package/node_modules/pi-commandcode-provider/src/core.ts +0 -861
  187. package/node_modules/pi-commandcode-provider/src/json-schema.ts +0 -417
  188. package/node_modules/pi-commandcode-provider/src/transcript.ts +0 -56
  189. package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +0 -31
  190. package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +0 -27
  191. package/node_modules/pi-lens/dist/chunk-447YZL4S.js +0 -25
  192. package/node_modules/pi-lens/dist/chunk-565VRUP4.js +0 -136
  193. package/node_modules/pi-lens/dist/chunk-57X2CDRX.js +0 -49
  194. package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +0 -27
  195. package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +0 -58
  196. package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +0 -22
  197. package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +0 -89
  198. package/node_modules/pi-lens/dist/chunk-U3AS2FR6.js +0 -106
  199. package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +0 -27
  200. package/node_modules/pi-lens/dist/chunk-WQV6BI4Q.js +0 -48
  201. package/node_modules/pi-lens/dist/chunk-YHGYAEFH.js +0 -443
  202. package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +0 -74
  203. package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +0 -30
@@ -5,7 +5,10 @@
5
5
  * https://api.commandcode.ai/provider/v1
6
6
  */
7
7
 
8
- import { AssistantMessageEventStream } from "@earendil-works/pi-ai"
8
+ import {
9
+ createAssistantMessageEventStream,
10
+ type AssistantMessageEventStream,
11
+ } from "@earendil-works/pi-ai"
9
12
  import * as piAiCompat from "@earendil-works/pi-ai/compat"
10
13
  import { streamSimple as streamNativeProvider } from "@earendil-works/pi-ai/compat"
11
14
  import {
@@ -15,11 +18,16 @@ import {
15
18
  type ProviderConfig,
16
19
  } from "@earendil-works/pi-coding-agent"
17
20
  import { join } from "node:path"
21
+ import { readFile } from "node:fs/promises"
22
+ import * as hostPackage from "@earendil-works/pi-coding-agent"
23
+ import { createRequestDiagnostics, formatDiagnostics, priceStatus } from "./src/diagnostics.ts"
18
24
 
19
- import { getConfiguredApiKey } from "./src/api-key.ts"
20
- import { pickCommandCodeApiKey, withResolvedCommandCodeApiKey } from "./src/converters.ts"
21
- import { createStreamCommandCode } from "./src/core.ts"
22
- import { calculateCommandCodeCost, commandCodeNativeCostRatesAt } from "./src/cost.ts"
25
+ import {
26
+ getConfiguredApiKey,
27
+ pickCommandCodeApiKey,
28
+ withResolvedCommandCodeApiKey,
29
+ } from "./src/api-key.ts"
30
+ import { commandCodeNativeCostRatesAt } from "./src/cost.ts"
23
31
  import {
24
32
  apiForModelId,
25
33
  baseUrlForModel,
@@ -40,8 +48,16 @@ import { MODEL_COSTS, ZERO_MODEL_COST } from "./src/pricing.ts"
40
48
  import { registerCommandCodeQuota } from "./src/quota-command.ts"
41
49
  import { normalizeCommandCodeResponsesResponse } from "./src/responses-stream.ts"
42
50
  import { createCommandCodeRuntime } from "./src/runtime.ts"
51
+ import {
52
+ compatForEndpoint,
53
+ endpointChoiceForModel,
54
+ isEndpointChoice,
55
+ loadEndpointOverrides,
56
+ resolveEndpoint,
57
+ saveEndpointChoice,
58
+ type EndpointOverrides,
59
+ } from "./src/routing.ts"
43
60
  import { createCommandCodeUsageProvider, type UsageProvider } from "./src/usage.ts"
44
- import { transcriptReadersFrom, withTranscriptPromptAndTools } from "./src/transcript.ts"
45
61
  import { createCommandCodeTransportRouter } from "./src/transport.ts"
46
62
 
47
63
  const COMMAND_CODE_API = "commandcode-custom"
@@ -111,7 +127,22 @@ function commandCodeHeaders(): Record<string, string> | undefined {
111
127
  */
112
128
  type CommandCodeProviderConfig = ProviderConfig & { usage?: UsageProvider }
113
129
 
114
- type CommandCodeModelCompat = NonNullable<ProviderConfig["models"]>[number]["compat"]
130
+ type NativeModel = Parameters<typeof streamNativeProvider>[0]
131
+ type HostContext = Parameters<typeof streamNativeProvider>[1]
132
+ type HostReasoning = NonNullable<
133
+ NonNullable<Parameters<typeof streamNativeProvider>[2]>["reasoning"]
134
+ >
135
+ // Host-specific passthrough flags may be absent from Pi's declarations.
136
+ type CommandCodeModelCompat = NonNullable<NativeModel["compat"]> & {
137
+ supportsToolReferences?: boolean
138
+ // OMP's completions encoder requires this opt-in; Pi ignores the extra flag.
139
+ // Verified in @oh-my-pi/pi-ai 18.16.0, src/providers/openai-completions.ts.
140
+ replayReasoningContent?: boolean
141
+ // Private registration metadata, preserved through host/user compat overlays.
142
+ commandCodeWire?: CommandCodeApi
143
+ }
144
+ // OMP exposes sparse authored/user overrides here; Pi uses `compat`.
145
+ type HostModel = NativeModel & { compatConfig?: CommandCodeModelCompat }
115
146
 
116
147
  /**
117
148
  * Compatibility flags per wire. Chat Completions mirrors what the Provider API
@@ -140,6 +171,7 @@ function compatForModel(model: CommandCodeModel): CommandCodeModelCompat {
140
171
  supportsStore: false,
141
172
  supportsDeveloperRole: false,
142
173
  supportsReasoningEffort: MODEL_EFFORTS[model.id] !== undefined,
174
+ replayReasoningContent: model.reasoning,
143
175
  maxTokensField: "max_tokens",
144
176
  }
145
177
  }
@@ -159,7 +191,7 @@ function createProviderConfig(
159
191
  headers,
160
192
  // Same alpha endpoints and credentials as the /commandcode-quota command.
161
193
  usage: createCommandCodeUsageProvider({
162
- apiBase: legacyApiBase(apiBase),
194
+ apiBase: quotaApiBase(apiBase),
163
195
  headers,
164
196
  }),
165
197
  oauth: {
@@ -176,20 +208,54 @@ function createProviderConfig(
176
208
  reasoning: model.reasoning,
177
209
  ...(thinkingMetadataForModel(model.id) ?? {}),
178
210
  input: [...inputModalitiesForModel(model.id)],
179
- cost: MODEL_COSTS[model.id] ?? ZERO_MODEL_COST,
211
+ // Registration hands mutable metadata to the host, never the readonly catalog.
212
+ cost: {
213
+ ...(MODEL_COSTS[model.id] ?? ZERO_MODEL_COST),
214
+ tiers: MODEL_COSTS[model.id]?.tiers?.map((tier) => ({ ...tier })),
215
+ },
180
216
  contextWindow: model.contextWindow,
181
217
  maxTokens: model.maxTokens,
182
218
  headers,
183
- compat: compatForModel(model),
219
+ compat: { ...compatForModel(model), commandCodeWire: model.api },
184
220
  })),
185
221
  }
186
222
  }
187
223
 
188
- function legacyApiBase(providerApiBase: string): string {
224
+ function quotaApiBase(providerApiBase: string): string {
189
225
  return providerApiBase.replace(/\/provider\/v1\/?$/, "")
190
226
  }
191
227
 
192
228
  export default async function (pi: ExtensionAPI) {
229
+ let pluginVersion = "unknown"
230
+ try {
231
+ const packageData: unknown = JSON.parse(
232
+ await readFile(new URL("./package.json", import.meta.url), "utf8"),
233
+ )
234
+ if (
235
+ typeof packageData === "object" &&
236
+ packageData !== null &&
237
+ "version" in packageData &&
238
+ typeof packageData.version === "string"
239
+ )
240
+ pluginVersion = packageData.version
241
+ } catch {
242
+ // Optional support metadata must not prevent loading the provider.
243
+ }
244
+ const hostVersion =
245
+ "VERSION" in hostPackage && typeof hostPackage.VERSION === "string"
246
+ ? hostPackage.VERSION
247
+ : "unknown"
248
+ const diagnostics = createRequestDiagnostics()
249
+ const warnedPrices = new Set<string>()
250
+ pi.on("before_agent_start", (_event, ctx) => {
251
+ if (ctx.model?.provider !== "commandcode" || warnedPrices.has(ctx.model.id)) return
252
+ if (priceStatus(ctx.model.id) === "known") return
253
+ warnedPrices.add(ctx.model.id)
254
+ ctx.ui.notify(
255
+ "Command Code display price is unknown or needs review. A zero estimate does not mean free usage; check /commandcode-diagnostics.",
256
+ "warning",
257
+ )
258
+ })
193
259
  // Hosts may select their built-in Command Code model before loading extensions.
194
260
  // Rebind that stale selection to our registered transport before the first turn.
195
261
  pi.on("session_start", async (_event, ctx) => {
@@ -204,30 +270,87 @@ export default async function (pi: ExtensionAPI) {
204
270
  const modelsTimeoutMs = getModelsTimeoutMs()
205
271
  const modelsCachePath =
206
272
  process.env.COMMANDCODE_MODELS_CACHE ?? join(getAgentDir(), "commandcode-models.json")
207
- const streamGenerate = createStreamCommandCode({
208
- createStream: () => new AssistantMessageEventStream(),
209
- calculateCost: calculateCommandCodeCost,
210
- apiBase: legacyApiBase(apiBase),
211
- })
212
273
  const resolveStreamOptions = (options?: Parameters<typeof streamNativeProvider>[2]) =>
213
274
  withResolvedCommandCodeApiKey(options, getConfiguredApiKey())
214
- // The provider transport delegates to pi-ai, which reads the transcript
215
- // itself. The generate transport builds its own request body and needs the
216
- // flat prompt and tool fields that pi 0.86+ no longer passes.
217
- const transcriptReaders = transcriptReadersFrom(piAiCompat)
218
275
  // The host dispatches every Command Code model through one custom api id, so
219
276
  // the wire each model answers on is resolved here from the catalog that
220
277
  // `createProviderConfig` registered. Unknown ids fall back to the id rule.
221
- const modelApis = new Map<string, CommandCodeApi>()
222
- const resolveModelApi = (modelId: string): CommandCodeApi =>
223
- modelApis.get(modelId) ?? apiForModelId(modelId)
278
+ const catalogModels = new Map<string, CommandCodeModel>()
279
+ const routingPath = join(getAgentDir(), "commandcode-routing.json")
280
+ let routing: EndpointOverrides = {}
281
+ let routingWarning: string | undefined
282
+ try {
283
+ routing = await loadEndpointOverrides(routingPath)
284
+ } catch (error) {
285
+ routingWarning = `${error instanceof Error ? error.message : "Invalid commandcode-routing.json"}; using catalog routing. Use /commandcode-endpoint <model-id> auto|responses|chat-completions to repair it explicitly.`
286
+ console.error(`[commandcode] routing warning: ${routingWarning}`)
287
+ }
288
+ const resolveModelApi = (modelId: string): CommandCodeApi => {
289
+ const model = catalogModels.get(modelId)
290
+ return model ? resolveEndpoint(model, routing) : apiForModelId(modelId)
291
+ }
292
+ pi.on("before_agent_start", (_event, ctx) => {
293
+ if (routingWarning && ctx.model?.provider === "commandcode") {
294
+ ctx.ui.notify(routingWarning, "warning")
295
+ }
296
+ })
297
+ // waitForIdle is not a lock: serialize command writes within this host so
298
+ // simultaneous callers cannot overwrite one another's unrelated choices.
299
+ let routingWrite = Promise.resolve()
300
+ pi.registerCommand("commandcode-endpoint", {
301
+ description: "Choose a persistent model endpoint: <model-id> auto|responses|chat-completions",
302
+ handler: async (args, ctx) => {
303
+ const [modelId, choice, extra] = args.trim().split(/\s+/)
304
+ if (!modelId || !isEndpointChoice(choice) || extra) {
305
+ ctx.ui.notify(
306
+ "Usage: /commandcode-endpoint <catalog-model-id> auto|responses|chat-completions",
307
+ "warning",
308
+ )
309
+ return
310
+ }
311
+ await ctx.waitForIdle()
312
+ routingWrite = routingWrite
313
+ .catch(() => {})
314
+ .then(async () => {
315
+ try {
316
+ // A refresh can finish while the command is waiting for the current turn.
317
+ const model = catalogModels.get(modelId)
318
+ if (!model) {
319
+ ctx.ui.notify(
320
+ "Unknown catalog model; refresh the catalog or use a listed model ID",
321
+ "warning",
322
+ )
323
+ return
324
+ }
325
+ resolveEndpoint(model, { [model.id]: choice })
326
+ const saved = await saveEndpointChoice(routingPath, model.id, choice)
327
+ routing = saved.overrides
328
+ routingWarning = undefined
329
+ ctx.ui.notify(
330
+ `Command Code endpoint for ${model.id}: ${resolveModelApi(model.id)} (${choice === "auto" ? "catalog" : "user override"}). Applies to the next request and survives refresh/restart.` +
331
+ (saved.backupFile
332
+ ? ` Invalid routing choices were replaced; previous contents saved as ${saved.backupFile} in the agent directory.`
333
+ : ""),
334
+ saved.backupFile ? "warning" : "info",
335
+ )
336
+ } catch (error) {
337
+ ctx.ui.notify(
338
+ error instanceof Error ? error.message : "Could not save routing configuration",
339
+ "error",
340
+ )
341
+ }
342
+ })
343
+ await routingWrite
344
+ },
345
+ })
224
346
  // Diagnostic for /commandcode-status: reflects the most recent Responses
225
347
  // request, so a one-off malformed stream does not stick until restart.
226
348
  let streamWarning: string | undefined
227
- const transport = createCommandCodeTransportRouter({
228
- createStream: () => new AssistantMessageEventStream(),
349
+ const transport = createCommandCodeTransportRouter<HostModel, HostContext, HostReasoning>({
350
+ createStream: createAssistantMessageEventStream,
229
351
  streamProvider: (model, context, options) => {
230
352
  const wire = resolveModelApi(model.id)
353
+ const catalogModel = catalogModels.get(model.id)
231
354
  const resolvedOptions: Parameters<typeof streamNativeProvider>[2] =
232
355
  resolveStreamOptions(options)
233
356
  const nativeOptions =
@@ -251,18 +374,19 @@ export default async function (pi: ExtensionAPI) {
251
374
  api: wire,
252
375
  // Native hosts receive mutable tiers without owning the readonly catalog.
253
376
  cost: commandCodeNativeCostRatesAt(model.id, model.cost),
254
- compat: model.compatConfig ?? model.compat,
377
+ // Preserve same-wire host/user settings, but replace unknown/stale
378
+ // compatibility metadata rather than merge flags across wires.
379
+ compat: compatForEndpoint(
380
+ catalogModel,
381
+ wire,
382
+ model.compatConfig ?? model.compat,
383
+ compatForModel,
384
+ ),
255
385
  },
256
386
  context,
257
387
  nativeOptions,
258
388
  )
259
389
  },
260
- streamGenerate: (model, context, options) =>
261
- streamGenerate(
262
- model,
263
- withTranscriptPromptAndTools(context, transcriptReaders),
264
- resolveStreamOptions(options),
265
- ),
266
390
  })
267
391
 
268
392
  // pi dispatches the main chat through the registered provider, but sibling
@@ -272,8 +396,19 @@ export default async function (pi: ExtensionAPI) {
272
396
  // custom api there so those calls reach the same transport. The registry
273
397
  // resolves no credentials for extension providers, so fall back to the
274
398
  // configured key when the caller passes none or a placeholder.
275
- const compatStream: CompatStreamFunction = (model, context, options) =>
276
- transport.stream(model, context, resolveStreamOptions(options)) as AssistantMessageEventStream
399
+ const measuredStream = (
400
+ model: Parameters<typeof transport.stream>[0],
401
+ context: Parameters<typeof transport.stream>[1],
402
+ options?: Parameters<typeof streamNativeProvider>[2],
403
+ ) =>
404
+ diagnostics.stream(
405
+ transport.stream,
406
+ createAssistantMessageEventStream,
407
+ model,
408
+ context,
409
+ resolveStreamOptions(options),
410
+ )
411
+ const compatStream: CompatStreamFunction = measuredStream
277
412
  registerCompatApiProvider(compatStream)
278
413
 
279
414
  pi.on("message_end", async (event, ctx) => {
@@ -283,7 +418,7 @@ export default async function (pi: ExtensionAPI) {
283
418
  })
284
419
 
285
420
  registerCommandCodeQuota(pi, {
286
- apiBase: legacyApiBase(apiBase),
421
+ apiBase: quotaApiBase(apiBase),
287
422
  headers: commandCodeHeaders(),
288
423
  })
289
424
 
@@ -299,12 +434,51 @@ export default async function (pi: ExtensionAPI) {
299
434
  }),
300
435
  loadCachedModels: () => loadCachedCommandCodeModels(modelsCachePath),
301
436
  createProviderConfig: (models) => {
302
- for (const model of models) modelApis.set(model.id, model.api)
303
- return createProviderConfig(models, apiBase, transport.stream)
437
+ catalogModels.clear()
438
+ for (const model of models) catalogModels.set(model.id, model)
439
+ return createProviderConfig(models, apiBase, measuredStream)
440
+ },
441
+ getDiagnostics: (model) => {
442
+ let route = "not selected"
443
+ if (model?.provider === "commandcode") {
444
+ try {
445
+ route = `${transport.getTransport()}/${resolveModelApi(model.id)}`
446
+ } catch {
447
+ route = "invalid routing configuration"
448
+ }
449
+ }
450
+ let endpointStatus = "model endpoint: no Command Code model selected"
451
+ if (model?.provider === "commandcode") {
452
+ const choice = endpointChoiceForModel(model.id, routing)
453
+ try {
454
+ if (catalogModels.has(model.id)) {
455
+ const source = choice === "auto" ? "catalog" : "user override"
456
+ endpointStatus = `model endpoint: ${resolveModelApi(model.id)} (${choice}; ${source})`
457
+ } else {
458
+ endpointStatus = `model endpoint: ${resolveModelApi(model.id)} (id-rule fallback; model absent from catalog, stored choices ignored)`
459
+ }
460
+ } catch {
461
+ endpointStatus = "model endpoint: invalid choice for the current catalog; use auto"
462
+ }
463
+ }
464
+ return [
465
+ formatDiagnostics({
466
+ pluginVersion,
467
+ host: compatApiProviderRegistrar() ? "pi" : "omp-compatible",
468
+ hostVersion,
469
+ modelId: model?.provider === "commandcode" ? model.id : undefined,
470
+ route,
471
+ request: diagnostics.snapshot(),
472
+ }),
473
+ endpointStatus,
474
+ routingWarning,
475
+ ]
476
+ .filter(Boolean)
477
+ .join("\n")
304
478
  },
305
479
  getTransport: transport.getTransport,
306
480
  resetTransport: transport.reset,
307
- getStreamWarning: () => streamWarning,
481
+ getStreamWarning: () => [routingWarning, streamWarning].filter(Boolean).join("\n") || undefined,
308
482
  })
309
483
 
310
484
  pi.on("session_shutdown", () => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-commandcode-provider",
3
- "version": "0.7.12",
3
+ "version": "0.8.0",
4
4
  "description": "pi custom provider for Command Code API (commandcode.ai)",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -29,8 +29,9 @@
29
29
  "LICENSE"
30
30
  ],
31
31
  "scripts": {
32
- "test": "npm run typecheck && node --test tests/test-release.mjs tests/test-pi-child-cleanup.mjs && tsx tests/test-package-manifest.ts && tsx tests/test-api-key.ts && tsx tests/test-pure-functions.ts && tsx tests/test-models.ts && tsx tests/test-model-metadata-check.ts && tsx tests/test-runtime.ts && tsx tests/test-pricing.ts && tsx tests/test-pricing-check.ts && tsx tests/test-cost.ts && tsx tests/test-oauth.ts && tsx tests/test-abort.ts && tsx tests/test-overflow.ts && tsx tests/test-stream.ts && tsx tests/test-quota.ts && tsx tests/test-quota-command.ts && tsx tests/test-usage.ts && tsx tests/test-retry.ts && tsx tests/test-transport.ts && node tests/test-pi-isolated.mjs && node tests/test-pi-authenticated.mjs && node tests/test-pi-local.mjs && node tests/test-omp-compat.mjs",
32
+ "test": "npm run typecheck && npm run test:diagnostics && npm run test:routing && node --test tests/test-release.mjs tests/test-maintenance-alert.mjs tests/test-pi-child-cleanup.mjs tests/test-entrypoint-typecheck.mjs tests/test-host-protocol-helpers.mjs && tsx tests/test-package-manifest.ts && tsx tests/test-api-key.ts && tsx tests/test-pure-functions.ts && tsx tests/test-models.ts && tsx tests/test-model-metadata-check.ts && tsx tests/test-runtime.ts && tsx tests/test-pricing.ts && tsx tests/test-pricing-check.ts && tsx tests/test-cost.ts && tsx tests/test-oauth.ts && tsx tests/test-overflow.ts && tsx tests/test-quota.ts && tsx tests/test-quota-command.ts && tsx tests/test-usage.ts && tsx tests/test-transport.ts && node tests/test-pi-isolated.mjs && node tests/test-pi-authenticated.mjs && node tests/test-pi-local.mjs && node tests/test-omp-compat.mjs && node tests/test-host-protocols.mjs && node tests/test-endpoint-routing.mjs",
33
33
  "typecheck": "tsc --noEmit",
34
+ "typecheck:entrypoint": "node scripts/typecheck-entrypoint.mjs",
34
35
  "format:check": "prettier --check '**/*.{ts,mjs,json,md}'",
35
36
  "format": "prettier --write '**/*.{ts,mjs,json,md}'",
36
37
  "pi:isolated": "node scripts/pi-isolated.mjs",
@@ -40,29 +41,29 @@
40
41
  "sync:commandcode-catalog": "tsx .github/scripts/check-commandcode-model-metadata.ts command-code@latest --write",
41
42
  "test:quota": "tsx tests/test-quota.ts && tsx tests/test-quota-command.ts && tsx tests/test-usage.ts",
42
43
  "test:usage": "tsx tests/test-usage.ts",
43
- "test:unit": "tsx tests/test-api-key.ts && tsx tests/test-pure-functions.ts && tsx tests/test-models.ts && tsx tests/test-model-metadata-check.ts && tsx tests/test-runtime.ts && tsx tests/test-pricing.ts && tsx tests/test-pricing-check.ts && tsx tests/test-cost.ts && tsx tests/test-oauth.ts && tsx tests/test-abort.ts && tsx tests/test-overflow.ts && tsx tests/test-stream.ts && tsx tests/test-quota.ts && tsx tests/test-quota-command.ts && tsx tests/test-usage.ts && tsx tests/test-retry.ts && tsx tests/test-transport.ts",
44
+ "test:unit": "npm run test:diagnostics && npm run test:routing && tsx tests/test-api-key.ts && tsx tests/test-pure-functions.ts && tsx tests/test-models.ts && tsx tests/test-model-metadata-check.ts && tsx tests/test-runtime.ts && tsx tests/test-pricing.ts && tsx tests/test-pricing-check.ts && tsx tests/test-cost.ts && tsx tests/test-oauth.ts && tsx tests/test-overflow.ts && tsx tests/test-quota.ts && tsx tests/test-quota-command.ts && tsx tests/test-usage.ts && tsx tests/test-transport.ts",
44
45
  "test:api-key": "tsx tests/test-api-key.ts",
45
46
  "test:models": "tsx tests/test-models.ts && tsx tests/test-model-metadata-check.ts",
47
+ "test:diagnostics": "tsx tests/test-diagnostics.ts",
48
+ "test:routing": "tsx tests/test-routing.ts",
49
+ "test:routing-hosts": "node tests/test-endpoint-routing.mjs",
46
50
  "test:runtime": "tsx tests/test-runtime.ts",
47
51
  "test:pricing": "tsx tests/test-pricing.ts",
48
52
  "test:pricing-check": "tsx tests/test-pricing-check.ts",
49
53
  "test:oauth": "tsx tests/test-oauth.ts",
50
- "test:abort": "tsx tests/test-abort.ts",
51
54
  "test:overflow": "tsx tests/test-overflow.ts",
52
- "test:stream": "tsx tests/test-stream.ts",
53
- "test:retry": "tsx tests/test-retry.ts",
54
55
  "test:transport": "tsx tests/test-transport.ts",
55
56
  "test:pi-isolated": "node tests/test-pi-isolated.mjs",
56
57
  "test:pi-authenticated": "node tests/test-pi-authenticated.mjs",
57
58
  "test:pi-local": "node tests/test-pi-local.mjs",
59
+ "test:host-protocols": "node --test tests/test-host-protocol-helpers.mjs && node tests/test-host-protocols.mjs",
58
60
  "test:smoke": "node tests/test-smoke.mjs",
59
61
  "test:release": "node --test tests/test-release.mjs",
60
62
  "test:release-package": "node tests/test-release-package.mjs",
61
63
  "test:e2e:live": "node tests/test-live-e2e.mjs",
62
- "test:e2e:live:go": "node scripts/live-e2e-profile.mjs go",
63
64
  "test:e2e:live:goat": "node scripts/live-e2e-profile.mjs goat",
64
65
  "test:e2e:live:provider": "node scripts/live-e2e-profile.mjs provider",
65
- "test:e2e:live:all": "node scripts/live-e2e-profile.mjs go goat",
66
+ "test:e2e:live:all": "node scripts/live-e2e-profile.mjs goat provider",
66
67
  "test:cost": "tsx tests/test-cost.ts"
67
68
  },
68
69
  "pi": {
@@ -11,19 +11,16 @@ const profiles = process.argv.slice(2)
11
11
 
12
12
  if (
13
13
  profiles.length === 0 ||
14
- profiles.some((profile) => profile !== "go" && profile !== "goat" && profile !== "provider")
14
+ profiles.some((profile) => profile !== "goat" && profile !== "provider")
15
15
  ) {
16
- console.error("Usage: node scripts/live-e2e-profile.mjs <go|goat|provider> [go|goat|provider]")
16
+ console.error(
17
+ "Usage: node scripts/live-e2e-profile.mjs <goat|provider> [goat|provider] (Go has no Provider API access)",
18
+ )
17
19
  process.exit(2)
18
20
  }
19
21
 
20
22
  async function credentialFor(profile) {
21
- const prefix =
22
- profile === "go"
23
- ? "COMMANDCODE_E2E_GO"
24
- : profile === "goat"
25
- ? "COMMANDCODE_E2E_GOAT"
26
- : "COMMANDCODE_E2E_PROVIDER"
23
+ const prefix = profile === "goat" ? "COMMANDCODE_E2E_GOAT" : "COMMANDCODE_E2E_PROVIDER"
27
24
  const direct = process.env[`${prefix}_API_KEY`]?.trim()
28
25
  const file = process.env[`${prefix}_API_KEY_FILE`]
29
26
 
@@ -40,11 +37,7 @@ async function credentialFor(profile) {
40
37
 
41
38
  function runProfile(profile, apiKey) {
42
39
  const modelVariable =
43
- profile === "go"
44
- ? "COMMANDCODE_E2E_GO_MODEL"
45
- : profile === "goat"
46
- ? "COMMANDCODE_E2E_GOAT_MODEL"
47
- : "COMMANDCODE_E2E_PROVIDER_MODEL"
40
+ profile === "goat" ? "COMMANDCODE_E2E_GOAT_MODEL" : "COMMANDCODE_E2E_PROVIDER_MODEL"
48
41
  const model =
49
42
  process.env[modelVariable] ??
50
43
  (profile === "goat" ? "xai/grok-4.6" : "deepseek/deepseek-v4-flash")
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ /** Check the entrypoint against an installed Pi host, without installing private peers. */
3
+ import { readFileSync } from "node:fs"
4
+ import { dirname, resolve } from "node:path"
5
+ import { fileURLToPath } from "node:url"
6
+ import ts from "typescript"
7
+
8
+ const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
9
+
10
+ function installedHostEntry(hostDir) {
11
+ try {
12
+ const manifest = JSON.parse(readFileSync(resolve(hostDir, "package.json"), "utf8"))
13
+ if (
14
+ manifest?.name !== "@earendil-works/pi-coding-agent" ||
15
+ typeof manifest.types !== "string" ||
16
+ !manifest.types.endsWith(".d.ts")
17
+ )
18
+ throw new Error("Expected an installed Pi package with a declaration entrypoint")
19
+ return resolve(hostDir, manifest.types)
20
+ } catch (error) {
21
+ throw new Error(`Cannot read installed Pi declarations: ${error.message}`)
22
+ }
23
+ }
24
+
25
+ export function entrypointProgram(hostDir, root = repoRoot) {
26
+ const configPath = resolve(root, "tsconfig.entrypoint.json")
27
+ const config = ts.readConfigFile(configPath, ts.sys.readFile)
28
+ if (config.error) return { diagnostics: [config.error] }
29
+ const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, root)
30
+ if (parsed.errors.length) return { diagnostics: parsed.errors }
31
+
32
+ // A path is required when Pi is installed globally (as in CI). Otherwise use
33
+ // locally resolvable optional peers. Never substitute ambient host stubs.
34
+ const hostEntry = hostDir
35
+ ? installedHostEntry(hostDir)
36
+ : ts.resolveModuleName(
37
+ "@earendil-works/pi-coding-agent",
38
+ resolve(root, "index.ts"),
39
+ parsed.options,
40
+ ts.sys,
41
+ ).resolvedModule?.resolvedFileName
42
+ if (!hostEntry || !ts.sys.fileExists(hostEntry)) {
43
+ throw new Error(
44
+ "Pi declarations not found. Pass its installed package directory: npm run typecheck:entrypoint -- /path/to/@earendil-works/pi-coding-agent",
45
+ )
46
+ }
47
+ const resolveAi = (specifier) => {
48
+ const entry = ts.resolveModuleName(specifier, hostEntry, parsed.options, ts.sys).resolvedModule
49
+ ?.resolvedFileName
50
+ if (!entry || !/\.d\.[cm]?ts$/.test(entry)) {
51
+ throw new Error(`Installed Pi does not expose declarations for ${specifier}`)
52
+ }
53
+ return entry
54
+ }
55
+ const options = {
56
+ ...parsed.options,
57
+ paths: {
58
+ "@earendil-works/pi-coding-agent": [hostEntry],
59
+ "@earendil-works/pi-ai": [resolveAi("@earendil-works/pi-ai")],
60
+ "@earendil-works/pi-ai/compat": [resolveAi("@earendil-works/pi-ai/compat")],
61
+ },
62
+ }
63
+ const program = ts.createProgram(parsed.fileNames, options)
64
+ return { program, diagnostics: ts.getPreEmitDiagnostics(program) }
65
+ }
66
+
67
+ if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
68
+ try {
69
+ if (process.argv.length > 3)
70
+ throw new Error("Expected at most one installed Pi package directory")
71
+ const { diagnostics } = entrypointProgram(process.argv[2])
72
+ if (diagnostics.length) {
73
+ console.error(
74
+ ts.formatDiagnosticsWithColorAndContext(diagnostics, {
75
+ getCanonicalFileName: (path) => path,
76
+ getCurrentDirectory: () => repoRoot,
77
+ getNewLine: () => "\n",
78
+ }),
79
+ )
80
+ process.exitCode = 1
81
+ } else {
82
+ console.log("[typecheck:entrypoint] PASS — index.ts and host-boundary contracts")
83
+ }
84
+ } catch (error) {
85
+ console.error(`[typecheck:entrypoint] FAIL — ${error.message}`)
86
+ process.exitCode = 1
87
+ }
88
+ }
@@ -40,8 +40,8 @@ export interface ApiKeyLookupOptions {
40
40
  }
41
41
 
42
42
  /**
43
- * The single credential reader shared by the Provider API path, the generate
44
- * fallback, and the quota/usage commands: environment first, then the auth
43
+ * The single credential reader shared by the Provider API path and the
44
+ * quota/usage commands: environment first, then the auth
45
45
  * files above. Hosts resolve their own stored credentials before this runs;
46
46
  * this is the ambient fallback for keys they do not know about.
47
47
  */
@@ -83,3 +83,44 @@ export function getConfiguredApiKey(options: ApiKeyLookupOptions = {}): string |
83
83
 
84
84
  return undefined
85
85
  }
86
+
87
+ // Hosts such as OMP may pass a literal env-var name as the "resolved" registry
88
+ // key instead of the actual credential. Treat those as unresolved.
89
+ export const COMMAND_CODE_PLACEHOLDER_KEYS = new Set([
90
+ "$COMMAND_CODE_API_KEY",
91
+ "COMMAND_CODE_API_KEY",
92
+ "$COMMANDCODE_API_KEY",
93
+ "COMMANDCODE_API_KEY",
94
+ ])
95
+
96
+ function usableCommandCodeApiKey(value: string | undefined): string | undefined {
97
+ const trimmed = typeof value === "string" ? value.trim() : undefined
98
+ if (!trimmed) return undefined
99
+ if (COMMAND_CODE_PLACEHOLDER_KEYS.has(trimmed)) return undefined
100
+ return trimmed
101
+ }
102
+
103
+ /**
104
+ * Pick the real API key from a host registry value and/or the env/auth-file
105
+ * fallback, never returning a literal placeholder or an empty/whitespace value.
106
+ * Pure/testable.
107
+ */
108
+ export function pickCommandCodeApiKey(
109
+ registryKey: string | undefined,
110
+ hostKey: string | undefined,
111
+ ): string | undefined {
112
+ return usableCommandCodeApiKey(registryKey) ?? usableCommandCodeApiKey(hostKey)
113
+ }
114
+
115
+ /**
116
+ * Replace a host-supplied placeholder (or missing key) with the configured
117
+ * fallback. Used for both registerProvider and the Provider API stream path.
118
+ */
119
+ export function withResolvedCommandCodeApiKey<T extends { apiKey?: string }>(
120
+ options: T | undefined,
121
+ configuredKey: string | undefined,
122
+ ): T | { apiKey?: string } {
123
+ const apiKey = pickCommandCodeApiKey(options?.apiKey, configuredKey)
124
+ if (options && apiKey === options.apiKey) return options
125
+ return { ...options, apiKey }
126
+ }
@@ -11,7 +11,7 @@ import type { CommandCodeReasoningEffort } from "./commandcode-catalog.ts"
11
11
  * be removed by hand.
12
12
  *
13
13
  * An entry only takes effect for a model the generated catalog already marks as
14
- * reasoning-capable: `src/core.ts` drops `reasoning_effort` when `model.reasoning`
14
+ * reasoning-capable: native hosts omit reasoning options when `model.reasoning`
15
15
  * is false, and a model missing from `MODEL_REASONING` stays false. Upstream emits
16
16
  * the flag whenever it emits efforts, so a sync that brings in new efforts brings
17
17
  * the flag with it.