@herbertgao/pi-extensions 2026.10.13 → 2026.10.14

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 (265) hide show
  1. package/README.md +11 -11
  2. package/THIRD_PARTY_NOTICES.md +2 -2
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
  5. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +1 -0
  6. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +3 -6
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +22 -5
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +44 -14
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/default-mode.ts +1 -5
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +20 -5
  11. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/markdown-enhance.ts +4 -1
  12. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +42 -18
  13. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/layout.ts +12 -3
  14. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +131 -0
  15. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +217 -113
  16. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +12 -5
  17. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/subagent-notification.ts +556 -0
  18. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/ansi-text.ts +50 -0
  19. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/format.ts +11 -0
  20. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/patch-keys.ts +4 -0
  21. package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
  22. package/node_modules/@juicesharp/rpiv-ask-user-question/README.md +1 -0
  23. package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +27 -3
  24. package/node_modules/@juicesharp/rpiv-ask-user-question/config.ts +23 -0
  25. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/configuration.md +15 -0
  26. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/keyboard.md +9 -2
  27. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/de.json +7 -4
  28. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/en.json +8 -5
  29. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/es.json +7 -4
  30. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/fr.json +7 -4
  31. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/pt-BR.json +7 -4
  32. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/pt.json +7 -4
  33. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/ru.json +7 -4
  34. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/uk.json +7 -4
  35. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/zh.json +7 -4
  36. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +4 -3
  37. package/node_modules/@juicesharp/rpiv-ask-user-question/presentation.ts +11 -1
  38. package/node_modules/@juicesharp/rpiv-ask-user-question/state/build-questionnaire.ts +6 -0
  39. package/node_modules/@juicesharp/rpiv-ask-user-question/state/key-router.ts +49 -8
  40. package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +6 -0
  41. package/node_modules/@juicesharp/rpiv-ask-user-question/state/state-reducer.ts +13 -1
  42. package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +2 -0
  43. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-block-renderer.ts +19 -7
  44. package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +36 -7
  45. package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-copy.ts +13 -2
  46. package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +24 -8
  47. package/node_modules/@juicesharp/rpiv-ask-user-question/view/transcript.ts +144 -0
  48. package/node_modules/@narumitw/pi-btw/README.md +7 -2
  49. package/node_modules/@narumitw/pi-btw/dist/index.ts +371 -118
  50. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
  51. package/node_modules/@narumitw/pi-btw/docs/main-context-runtime.md +45 -0
  52. package/node_modules/@narumitw/pi-btw/docs/workflows.md +48 -5
  53. package/node_modules/@narumitw/pi-btw/package.json +1 -1
  54. package/node_modules/@narumitw/pi-btw/src/btw.ts +39 -14
  55. package/node_modules/@narumitw/pi-btw/src/import-main-updates.ts +84 -0
  56. package/node_modules/@narumitw/pi-btw/src/keybindings.ts +29 -4
  57. package/node_modules/@narumitw/pi-btw/src/main-context-snapshot.ts +125 -0
  58. package/node_modules/@narumitw/pi-btw/src/menu.ts +1 -0
  59. package/node_modules/@narumitw/pi-btw/src/side-thread.ts +66 -17
  60. package/node_modules/@narumitw/pi-btw/src/transcript-markdown.ts +5 -5
  61. package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +47 -6
  62. package/node_modules/pi-lens/CHANGELOG.md +440 -0
  63. package/node_modules/pi-lens/README.md +13 -3
  64. package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -0
  65. package/node_modules/pi-lens/dist/chunk-22Y2BM7H.js +23 -0
  66. package/node_modules/pi-lens/dist/{chunk-ATKJFDQN.js → chunk-27VWVB23.js} +12 -14
  67. package/node_modules/pi-lens/dist/{chunk-S2HEXIWI.js → chunk-2FYKETQJ.js} +10 -6
  68. package/node_modules/pi-lens/dist/{chunk-SRYEJNES.js → chunk-2LDMXL2M.js} +2 -2
  69. package/node_modules/pi-lens/dist/{chunk-ZHH37KZL.js → chunk-2SDHYHHO.js} +17 -17
  70. package/node_modules/pi-lens/dist/chunk-2Y6OJRSI.js +38 -0
  71. package/node_modules/pi-lens/dist/chunk-3SNDVPOR.js +507 -0
  72. package/node_modules/pi-lens/dist/{chunk-5OFV52AM.js → chunk-3WCEHYOI.js} +1 -1
  73. package/node_modules/pi-lens/dist/chunk-44X7VIKR.js +73 -0
  74. package/node_modules/pi-lens/dist/{chunk-DEL2U6CM.js → chunk-4FHUGDKU.js} +16 -14
  75. package/node_modules/pi-lens/dist/{chunk-CT4MN5IU.js → chunk-4ODSZ35Z.js} +353 -359
  76. package/node_modules/pi-lens/dist/{chunk-ZIVJBOO3.js → chunk-4U7GDSZQ.js} +2 -2
  77. package/node_modules/pi-lens/dist/chunk-54NIOJJZ.js +25 -0
  78. package/node_modules/pi-lens/dist/{chunk-N5FLEO7W.js → chunk-5DKE4HGX.js} +37 -37
  79. package/node_modules/pi-lens/dist/{chunk-P63GXC37.js → chunk-5LRUKYFA.js} +31 -4
  80. package/node_modules/pi-lens/dist/{chunk-HRNHZA3N.js → chunk-63NMUNYP.js} +12 -16
  81. package/node_modules/pi-lens/dist/{chunk-HWCCCQNX.js → chunk-6XSESGWD.js} +13 -6
  82. package/node_modules/pi-lens/dist/{chunk-UMS2MFPZ.js → chunk-72J27ICO.js} +2 -3
  83. package/node_modules/pi-lens/dist/{chunk-ED36RF6Y.js → chunk-7FLRUH6B.js} +1 -1
  84. package/node_modules/pi-lens/dist/chunk-7IYC4ENJ.js +297 -0
  85. package/node_modules/pi-lens/dist/chunk-7WWQAW5P.js +30 -0
  86. package/node_modules/pi-lens/dist/{chunk-3DA2JDOL.js → chunk-7ZS7MC24.js} +551 -203
  87. package/node_modules/pi-lens/dist/{chunk-WMYE35PX.js → chunk-AHWA4AKM.js} +7 -5
  88. package/node_modules/pi-lens/dist/{chunk-JW3YWBVB.js → chunk-AI3GP74G.js} +17 -19
  89. package/node_modules/pi-lens/dist/{chunk-AGSS7277.js → chunk-APFJKOP6.js} +6 -23
  90. package/node_modules/pi-lens/dist/{chunk-ZVUL7QYY.js → chunk-ASRAO7KG.js} +29 -32
  91. package/node_modules/pi-lens/dist/{chunk-BW5KFIQC.js → chunk-AWQWXSW4.js} +1 -0
  92. package/node_modules/pi-lens/dist/{chunk-TLX72JTG.js → chunk-CG5V25HX.js} +1 -1
  93. package/node_modules/pi-lens/dist/chunk-CKEQFGLT.js +32 -0
  94. package/node_modules/pi-lens/dist/{chunk-Y6GZHWSJ.js → chunk-COOUUC5W.js} +6 -6
  95. package/node_modules/pi-lens/dist/{chunk-XTBDCR27.js → chunk-CPZ5JJW6.js} +4 -4
  96. package/node_modules/pi-lens/dist/{chunk-RKKOYPRA.js → chunk-DS2USX5G.js} +13 -15
  97. package/node_modules/pi-lens/dist/chunk-EA2ZRG44.js +27 -0
  98. package/node_modules/pi-lens/dist/{chunk-GSLNCYGG.js → chunk-EDMLIW6W.js} +13 -14
  99. package/node_modules/pi-lens/dist/{chunk-2EECBNC5.js → chunk-EIKRZ32J.js} +75 -0
  100. package/node_modules/pi-lens/dist/chunk-EKNWOL2I.js +27 -0
  101. package/node_modules/pi-lens/dist/{chunk-R3T7CLQ2.js → chunk-ELZRSR5N.js} +41 -41
  102. package/node_modules/pi-lens/dist/{chunk-GMX5OS7B.js → chunk-EN5AM7PX.js} +11 -12
  103. package/node_modules/pi-lens/dist/{chunk-3RKP3FMS.js → chunk-EWXXLS26.js} +226 -24
  104. package/node_modules/pi-lens/dist/chunk-EX4EXBW7.js +37 -0
  105. package/node_modules/pi-lens/dist/{chunk-XHJBS436.js → chunk-EXVXBSGN.js} +25 -25
  106. package/node_modules/pi-lens/dist/{chunk-MZGQNL3Y.js → chunk-F7BO6FWH.js} +12 -13
  107. package/node_modules/pi-lens/dist/{chunk-V35JG4JB.js → chunk-FEDWAYDS.js} +152 -334
  108. package/node_modules/pi-lens/dist/{chunk-J64T55EI.js → chunk-FWZRGGGY.js} +73 -9
  109. package/node_modules/pi-lens/dist/{chunk-T57LYLZT.js → chunk-G224FADB.js} +1 -1
  110. package/node_modules/pi-lens/dist/chunk-G5UCJFT7.js +26 -0
  111. package/node_modules/pi-lens/dist/{chunk-LLJNQKQW.js → chunk-GLW3YDZZ.js} +20 -13
  112. package/node_modules/pi-lens/dist/{chunk-GXFV6MYU.js → chunk-GTDSYEA2.js} +72 -39
  113. package/node_modules/pi-lens/dist/{chunk-DUO2TU77.js → chunk-GYRZ72R4.js} +10 -4
  114. package/node_modules/pi-lens/dist/chunk-HYVXA3BB.js +49 -0
  115. package/node_modules/pi-lens/dist/{chunk-W66O5E25.js → chunk-IEBJF3PN.js} +13 -15
  116. package/node_modules/pi-lens/dist/{chunk-GAQ7OQG6.js → chunk-IL7K66ZQ.js} +83 -94
  117. package/node_modules/pi-lens/dist/{chunk-T7FEBKXN.js → chunk-JWOVP5BL.js} +7 -9
  118. package/node_modules/pi-lens/dist/{chunk-UBOQLVT2.js → chunk-K2GUZ4DN.js} +4 -4
  119. package/node_modules/pi-lens/dist/{chunk-5VSF4UUQ.js → chunk-K4SZB56V.js} +34 -39
  120. package/node_modules/pi-lens/dist/{chunk-7D6L4MTX.js → chunk-KCBRHV5E.js} +3 -3
  121. package/node_modules/pi-lens/dist/{chunk-GSM5UU7A.js → chunk-KFXCL4OV.js} +38 -28
  122. package/node_modules/pi-lens/dist/{chunk-J6MPGQTS.js → chunk-KJJAVH3X.js} +81 -15
  123. package/node_modules/pi-lens/dist/{chunk-BWD5EPKO.js → chunk-KPVLQHCZ.js} +4 -6
  124. package/node_modules/pi-lens/dist/{chunk-MPNJLASA.js → chunk-KX56K73G.js} +10 -13
  125. package/node_modules/pi-lens/dist/{chunk-AWSCPCN2.js → chunk-LMCTHJ2H.js} +19 -19
  126. package/node_modules/pi-lens/dist/{chunk-IWDLU6K3.js → chunk-MEFLGBCS.js} +4 -6
  127. package/node_modules/pi-lens/dist/{chunk-TOY6QKOH.js → chunk-MKPCELNI.js} +17 -17
  128. package/node_modules/pi-lens/dist/{chunk-POMLXPMY.js → chunk-N3PLNNCW.js} +1 -1
  129. package/node_modules/pi-lens/dist/chunk-N5FBM25N.js +22 -0
  130. package/node_modules/pi-lens/dist/{chunk-CYRKQRPM.js → chunk-NFNVDDGB.js} +2 -4
  131. package/node_modules/pi-lens/dist/{chunk-RMLC67LF.js → chunk-NLIVE7L6.js} +2 -30
  132. package/node_modules/pi-lens/dist/{chunk-24AKHFGP.js → chunk-OMJ3OFBJ.js} +6 -6
  133. package/node_modules/pi-lens/dist/{chunk-IQWN5JCP.js → chunk-OZNCKLOX.js} +13 -14
  134. package/node_modules/pi-lens/dist/chunk-P5XUGPIX.js +31 -0
  135. package/node_modules/pi-lens/dist/{chunk-2KXTHF3M.js → chunk-PJXNTPB2.js} +253 -33
  136. package/node_modules/pi-lens/dist/chunk-PKOXJIVT.js +88 -0
  137. package/node_modules/pi-lens/dist/{chunk-DGUKIYSI.js → chunk-PP2A5V2T.js} +8 -10
  138. package/node_modules/pi-lens/dist/{chunk-KAPJINKN.js → chunk-Q42LJANT.js} +2 -2
  139. package/node_modules/pi-lens/dist/{chunk-UZ2XCLYS.js → chunk-Q4BKKOVC.js} +8 -8
  140. package/node_modules/pi-lens/dist/{chunk-TIQ2PKDW.js → chunk-QT66NEYN.js} +4 -4
  141. package/node_modules/pi-lens/dist/{chunk-U44DJXQP.js → chunk-RCHO5W7M.js} +15 -18
  142. package/node_modules/pi-lens/dist/{chunk-YH5MVY2U.js → chunk-RG3MXTRI.js} +7 -7
  143. package/node_modules/pi-lens/dist/chunk-RG7OODGM.js +57 -0
  144. package/node_modules/pi-lens/dist/{chunk-OHKJ7PQF.js → chunk-RU34BA4D.js} +43 -39
  145. package/node_modules/pi-lens/dist/{chunk-JMYYOTQG.js → chunk-S26LC76R.js} +13 -1
  146. package/node_modules/pi-lens/dist/{chunk-XBJVAEEO.js → chunk-S55TEC7I.js} +3 -2
  147. package/node_modules/pi-lens/dist/{chunk-RVK72CZX.js → chunk-SJHC3BCZ.js} +1397 -481
  148. package/node_modules/pi-lens/dist/{chunk-IYNJ6YPZ.js → chunk-SNEUMLM7.js} +4 -4
  149. package/node_modules/pi-lens/dist/{chunk-S67KYG37.js → chunk-T4NGVFYI.js} +2 -2
  150. package/node_modules/pi-lens/dist/{chunk-YCWYO6TQ.js → chunk-THEXI2QO.js} +48 -45
  151. package/node_modules/pi-lens/dist/{chunk-AMERCH6V.js → chunk-TL2TCJYL.js} +15 -16
  152. package/node_modules/pi-lens/dist/{chunk-KUA4OJ5Y.js → chunk-TPYYEDP5.js} +823 -350
  153. package/node_modules/pi-lens/dist/{chunk-YNE3RP52.js → chunk-TVZRLTG6.js} +8 -1
  154. package/node_modules/pi-lens/dist/{chunk-ROYSX2S5.js → chunk-UCVMSOXF.js} +2 -2
  155. package/node_modules/pi-lens/dist/chunk-UL5SXQVX.js +32 -0
  156. package/node_modules/pi-lens/dist/{chunk-7HXE67BN.js → chunk-UO66IMVP.js} +2 -2
  157. package/node_modules/pi-lens/dist/{chunk-VOOAPROD.js → chunk-UVY4TOJH.js} +3 -3
  158. package/node_modules/pi-lens/dist/{chunk-RKBXZN3A.js → chunk-VIDEKABZ.js} +2 -2
  159. package/node_modules/pi-lens/dist/{chunk-2FN63LPV.js → chunk-VITFDI3O.js} +13 -14
  160. package/node_modules/pi-lens/dist/{chunk-6DLWKFEX.js → chunk-VUAVE3QC.js} +41 -42
  161. package/node_modules/pi-lens/dist/{chunk-FM4RDMKT.js → chunk-WUY4BZEP.js} +10 -12
  162. package/node_modules/pi-lens/dist/{chunk-SD4I7ZO4.js → chunk-X3UTCXAA.js} +43 -53
  163. package/node_modules/pi-lens/dist/chunk-XHDBJODR.js +45 -0
  164. package/node_modules/pi-lens/dist/{chunk-5IUSNGOC.js → chunk-XHLK33VM.js} +28 -21
  165. package/node_modules/pi-lens/dist/{chunk-3KAZU3VR.js → chunk-XI34NWDI.js} +2 -2
  166. package/node_modules/pi-lens/dist/{chunk-QBFBRV2B.js → chunk-XWFIHYCH.js} +4 -2
  167. package/node_modules/pi-lens/dist/{chunk-JUKMK5Y4.js → chunk-Y2TPADJR.js} +10 -11
  168. package/node_modules/pi-lens/dist/{chunk-EBC36LNN.js → chunk-Y5KTA2OB.js} +17 -17
  169. package/node_modules/pi-lens/dist/{chunk-HYGZEMX6.js → chunk-YKVDBNPO.js} +11 -5
  170. package/node_modules/pi-lens/dist/{chunk-KN35K52N.js → chunk-YSDPVDFC.js} +3 -3
  171. package/node_modules/pi-lens/dist/chunk-YWNO5Q4R.js +44 -0
  172. package/node_modules/pi-lens/dist/{chunk-US7ECLD7.js → chunk-YWWG4AQA.js} +119 -28
  173. package/node_modules/pi-lens/dist/{chunk-O4NWQT6I.js → chunk-YXDCRUKQ.js} +4 -4
  174. package/node_modules/pi-lens/dist/{chunk-XYURS6EN.js → chunk-YXGRRORB.js} +15 -17
  175. package/node_modules/pi-lens/dist/{chunk-IUE7SSKV.js → chunk-ZAPSUBLU.js} +13 -7
  176. package/node_modules/pi-lens/dist/{chunk-EUXZEFTV.js → chunk-ZPJM7DID.js} +3 -3
  177. package/node_modules/pi-lens/dist/{chunk-5HSRT26B.js → chunk-ZSUX7KEM.js} +16 -15
  178. package/node_modules/pi-lens/dist/index.js +37155 -32210
  179. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +11 -12
  180. package/node_modules/pi-lens/dist/mcp/cli.js +46 -45
  181. package/node_modules/pi-lens/dist/mcp/server.js +1210 -574
  182. package/node_modules/pi-lens/dist/mcp/worker.js +65 -65
  183. package/node_modules/pi-lens/dist/probes/installer.js +21 -23
  184. package/node_modules/pi-lens/docs/adr/0010-trace-validation-session-lifecycle.md +390 -0
  185. package/node_modules/pi-lens/docs/adr/README.md +1 -0
  186. package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +5 -3
  187. package/node_modules/pi-lens/docs/configuration.md +9 -0
  188. package/node_modules/pi-lens/docs/engineering-principles.md +12 -0
  189. package/node_modules/pi-lens/docs/environment-variables.md +20 -0
  190. package/node_modules/pi-lens/docs/features.md +16 -1
  191. package/node_modules/pi-lens/docs/globalconfig.md +37 -8
  192. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +105 -12
  193. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +37 -18
  194. package/node_modules/pi-lens/docs/pi-lens-fixer.md +22 -1
  195. package/node_modules/pi-lens/docs/pi-lens-investigator.md +14 -0
  196. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +23 -10
  197. package/node_modules/pi-lens/docs/pi-lens-monitor.md +64 -8
  198. package/node_modules/pi-lens/docs/pi-lens-retro.md +2 -2
  199. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +48 -1
  200. package/node_modules/pi-lens/docs/pi-lens-subagent.md +8 -1
  201. package/node_modules/pi-lens/docs/release-qa-baseline.md +19 -7
  202. package/node_modules/pi-lens/docs/servercapabilities.md +47 -47
  203. package/node_modules/pi-lens/docs/settings.md +9 -5
  204. package/node_modules/pi-lens/docs/subagent-compat.md +1 -1
  205. package/node_modules/pi-lens/docs/usage.md +1 -0
  206. package/node_modules/pi-lens/package.json +6 -4
  207. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +17 -0
  208. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-js-test.yml +86 -0
  209. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-test.yml +86 -0
  210. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/unchecked-numeric-parse-python-test.yml +15 -0
  211. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +9 -4
  212. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +119 -0
  213. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +119 -0
  214. package/node_modules/pi-lens/rules/ast-grep-rules/rules/unchecked-numeric-parse-python.yml +13 -2
  215. package/node_modules/pi-lens/rules/rule-catalog.json +25 -1
  216. package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +15 -5
  217. package/node_modules/pi-lens/scripts/lib/is-main-module.mjs +27 -0
  218. package/node_modules/pi-lens/scripts/lib/scratch-home-env.mjs +21 -0
  219. package/node_modules/pi-lens/scripts/rpc-load-check.mjs +4 -6
  220. package/node_modules/pi-lens/scripts/warm-loader-cache.mjs +2 -5
  221. package/node_modules/pi-next-cue/package.json +4 -1
  222. package/node_modules/pi-typesafe/README.md +6 -6
  223. package/node_modules/pi-typesafe/dist/ask.js +9 -2
  224. package/node_modules/pi-typesafe/dist/auth.d.ts +3 -2
  225. package/node_modules/pi-typesafe/dist/auth.js +2 -2
  226. package/node_modules/pi-typesafe/dist/backends.d.ts +20 -5
  227. package/node_modules/pi-typesafe/dist/backends.js +32 -8
  228. package/node_modules/pi-typesafe/dist/batch.d.ts +1 -1
  229. package/node_modules/pi-typesafe/dist/batch.js +2 -2
  230. package/node_modules/pi-typesafe/dist/client.d.ts +1 -1
  231. package/node_modules/pi-typesafe/dist/client.js +24 -12
  232. package/node_modules/pi-typesafe/dist/credentials.d.ts +8 -6
  233. package/node_modules/pi-typesafe/dist/credentials.js +70 -16
  234. package/node_modules/pi-typesafe/dist/extension.js +118 -26
  235. package/node_modules/pi-typesafe/dist/index.d.ts +1 -1
  236. package/node_modules/pi-typesafe/dist/index.js +1 -1
  237. package/node_modules/pi-typesafe/dist/key-prompt.d.ts +1 -1
  238. package/node_modules/pi-typesafe/dist/key-prompt.js +6 -6
  239. package/node_modules/pi-typesafe/dist/login.d.ts +11 -10
  240. package/node_modules/pi-typesafe/dist/login.js +24 -21
  241. package/node_modules/pi-typesafe/dist/schema.d.ts +8 -8
  242. package/node_modules/pi-typesafe/dist/schema.js +29 -7
  243. package/node_modules/pi-typesafe/package.json +2 -2
  244. package/package.json +11 -11
  245. package/node_modules/pi-lens/dist/chunk-3PTHXJXR.js +0 -28
  246. package/node_modules/pi-lens/dist/chunk-3QED2P4V.js +0 -31
  247. package/node_modules/pi-lens/dist/chunk-5WRPDP2A.js +0 -47
  248. package/node_modules/pi-lens/dist/chunk-ABBOA7UD.js +0 -157
  249. package/node_modules/pi-lens/dist/chunk-CUHSHSB6.js +0 -273
  250. package/node_modules/pi-lens/dist/chunk-GL5LUMZE.js +0 -51
  251. package/node_modules/pi-lens/dist/chunk-HAD7QRQI.js +0 -30
  252. package/node_modules/pi-lens/dist/chunk-JORED7EX.js +0 -44
  253. package/node_modules/pi-lens/dist/chunk-KYUB6QDC.js +0 -72
  254. package/node_modules/pi-lens/dist/chunk-LZSEQW6A.js +0 -57
  255. package/node_modules/pi-lens/dist/chunk-M2IFVFWU.js +0 -79
  256. package/node_modules/pi-lens/dist/chunk-M2UD3LPU.js +0 -88
  257. package/node_modules/pi-lens/dist/chunk-MBKQHGA7.js +0 -39
  258. package/node_modules/pi-lens/dist/chunk-R7YOCSNV.js +0 -23
  259. package/node_modules/pi-lens/dist/chunk-SKAMFC7A.js +0 -28
  260. package/node_modules/pi-lens/dist/chunk-SYE6T2EB.js +0 -28
  261. package/node_modules/pi-lens/dist/chunk-TRETHTQO.js +0 -26
  262. package/node_modules/pi-lens/dist/chunk-UA7ZXYDR.js +0 -184
  263. package/node_modules/pi-lens/dist/chunk-XTFDJI3T.js +0 -24
  264. package/node_modules/pi-lens/dist/chunk-Z3CCVDUB.js +0 -76
  265. package/node_modules/pi-next-cue/.github/workflows/publish.yml +0 -20
@@ -0,0 +1,21 @@
1
+ import * as path from "node:path";
2
+
3
+ /**
4
+ * The home pin an operator script or gate gives every child it spawns (#4789,
5
+ * AGENTS.md shape 82: one home variable pinned, the rest left at the real
6
+ * home). `home` becomes HOME and USERPROFILE (`os.homedir()`'s source on
7
+ * Windows), the three XDG base directories sit under it, and `lensHome` is
8
+ * PI_LENS_HOME (default: `home`). Pure: no I/O and no `process.env` reads, so
9
+ * the caller decides whether the pin lands in a child env object or in
10
+ * `process.env` itself.
11
+ */
12
+ export function scratchHomeEnv(home, lensHome = home) {
13
+ return {
14
+ HOME: home,
15
+ USERPROFILE: home,
16
+ XDG_CONFIG_HOME: path.join(home, ".config"),
17
+ XDG_CACHE_HOME: path.join(home, ".cache"),
18
+ XDG_DATA_HOME: path.join(home, ".local", "share"),
19
+ PI_LENS_HOME: lensHome,
20
+ };
21
+ }
@@ -55,7 +55,8 @@ import * as fs from "node:fs";
55
55
  import * as http from "node:http";
56
56
  import * as os from "node:os";
57
57
  import * as path from "node:path";
58
- import { pathToFileURL } from "node:url";
58
+ import { isMainModule } from "./lib/is-main-module.mjs";
59
+ import { scratchHomeEnv } from "./lib/scratch-home-env.mjs";
59
60
  import {
60
61
  parseNdjsonEntries,
61
62
  phaseWasLogged,
@@ -367,7 +368,7 @@ export async function run(piBin, { extension, failWorker }) {
367
368
  const env = {
368
369
  ...process.env,
369
370
  PI_CODING_AGENT_DIR: agentDir,
370
- PI_LENS_HOME: lensHome,
371
+ ...scratchHomeEnv(path.join(scratch, "home"), lensHome),
371
372
  PI_OFFLINE: "1",
372
373
  PI_SKIP_VERSION_CHECK: "1",
373
374
  };
@@ -578,10 +579,7 @@ async function main(argv) {
578
579
  return result.code;
579
580
  }
580
581
 
581
- if (
582
- process.argv[1] &&
583
- import.meta.url === pathToFileURL(process.argv[1]).href
584
- ) {
582
+ if (isMainModule(import.meta.url)) {
585
583
  main(process.argv.slice(2)).then(
586
584
  (code) => process.exit(code),
587
585
  (err) => {
@@ -27,6 +27,7 @@ import * as os from "node:os";
27
27
  import * as path from "node:path";
28
28
  import { fileURLToPath, pathToFileURL } from "node:url";
29
29
  import { HOST_PROVIDED_PACKAGES } from "./lib/host-provided-deps.mjs";
30
+ import { isMainModule } from "./lib/is-main-module.mjs";
30
31
  import {
31
32
  appendBounded,
32
33
  buildStubAliases,
@@ -226,10 +227,6 @@ export async function run(work = main) {
226
227
  }
227
228
  }
228
229
 
229
- const invokedPath = process.argv[1];
230
- const invokedDirectly =
231
- typeof invokedPath === "string" &&
232
- pathToFileURL(path.resolve(invokedPath)).href === import.meta.url;
233
- if (invokedDirectly) {
230
+ if (isMainModule(import.meta.url)) {
234
231
  await run();
235
232
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-next-cue",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Predicts your next prompt after each agent turn — Tab to fill, Enter to send.",
5
5
  "keywords": [
6
6
  "pi",
@@ -17,6 +17,9 @@
17
17
  "bugs": {
18
18
  "url": "https://github.com/ouzhenkun/pi-next-cue/issues"
19
19
  },
20
+ "files": [
21
+ "index.ts"
22
+ ],
20
23
  "peerDependencies": {
21
24
  "@earendil-works/pi-coding-agent": "*"
22
25
  },
@@ -20,7 +20,7 @@ pi install npm:pi-typesafe
20
20
 
21
21
  Then, inside Pi:
22
22
 
23
- 1. `/typesafe login` and paste a key from [console.typesafe.ai](https://console.typesafe.ai). Input is hidden; the key is verified against the API and saved to `~/.pi/agent/pi-typesafe/auth.json` with owner-only permissions.
23
+ 1. `/typesafe login` and paste a key from [console.typesafe.ai](https://console.typesafe.ai). Input is hidden; the key is verified against the API and saved to `~/.pi/agent/pi-typesafe/auth.json` with owner-only permissions. `/typesafe login <backend>` does the same for OpenRouter, Command Code, Liquid AI, SubQ, or an endpoint you name, keeping each key under its own name in the same store.
24
24
  2. `/typesafe test` sends one built-in sample request and shows the answers.
25
25
  3. `/typesafe enable` lets the agent call the tool for this session, after you confirm the data notice.
26
26
 
@@ -74,7 +74,7 @@ The [TypeSafe docs](https://docs.typesafe.ai/primitives) cover each primitive in
74
74
  An enabled extension with no usable key looks exactly like a working one — one evaluation ran keyless for hours before anyone noticed. Three answers exist now, and `/typesafe status` prints all of them:
75
75
 
76
76
  - **Is Jev reachable?** `authState()` reports the key source, whether it has been accepted, and the last failure that degraded it; `describeAuth()` turns that into a level and one safe line. The extension calls both at session start and after an authentication rejection, so a headless run says judgments are skipped instead of quietly falling back to its offline path.
77
- - **What has this run cost?** `getSpend()` returns session counters, today's persisted counters, and the cap currently reached. Cost is estimated from input tokens only, because output is free.
77
+ - **What has this run cost?** `getSpend()` returns session counters, today's persisted counters, and the cap currently reached. Cost is estimated from input tokens only, because output is free; a count the API did not report counts as nothing.
78
78
  - **When does it stop?** `maxRequests` bounds a client instance. Three caps bound a local day, survive restarts, and stop a request before it is submitted:
79
79
 
80
80
  | Option | Environment | Bounds |
@@ -91,8 +91,8 @@ Need more than one request? `evaluateAll(request)` asks any number of questions
91
91
 
92
92
  | Command | Effect |
93
93
  | --- | --- |
94
- | `/typesafe login` | Enter and verify an API key (hidden input), then store it |
95
- | `/typesafe logout` | Delete the stored key and disable the tool |
94
+ | `/typesafe login [backend]` | Enter and verify a backend's API key (hidden input), then store it under that backend; no argument means the session's backend. Refuses while that backend's environment variable is set, because the variable wins |
95
+ | `/typesafe logout [backend]` | Delete that backend's stored key, and turn judgments off when it was the session's backend; no argument means the session's backend |
96
96
  | `/typesafe setup` | Check which key is in use; starts login if none |
97
97
  | `/typesafe status` | Opt-in state, key state, session and today's counters, cost estimate, any reached cap |
98
98
  | `/typesafe enable` | Confirm the data notice and allow agent tool calls this session |
@@ -114,7 +114,7 @@ Whatever TypeSafe bills for the input tokens of your state and questions; output
114
114
  The main model can answer any of these questions in prose. It is slower, costs more per call, and grades its own work. Jev returns a calibrated number your code or the agent can branch on, in a quarter of a second, from a separate model. That matters most when the same question is asked many times: every tool call, every file, every issue in a list.
115
115
 
116
116
  **What is sent?**
117
- Only the state and questions you (or the agent, once enabled) submit, to `https://api.typesafe.ai` only. No files, conversation history, or telemetry. Error messages never include upstream response bodies, headers, keys, or your submitted state.
117
+ Only the state and questions you (or the agent, once enabled) submit, to the backend that serves the session: `https://api.typesafe.ai` by default, otherwise the host `PI_TYPESAFE_BACKEND` names, which `/typesafe status` reports. No files, conversation history, or telemetry. Error messages never include upstream response bodies, headers, keys, or your submitted state.
118
118
 
119
119
  **Limits?**
120
120
  Per request: 32 questions (16 on SubQ) and 64 KiB of JSON. Per session: 20 attempts, 15-second timeout, no automatic retries. Per day: no cap unless you set one. Session limits reset when a session starts or reloads; daily counters live in `~/.pi/agent/pi-typesafe/usage.json` and roll over at local midnight. The SDK's `TYPESAFE_BASE_URL` and `TYPESAFE_LOG_LEVEL` overrides are ignored.
@@ -142,7 +142,7 @@ if (!answer.ok) return { skipped: answer.errorCode === "budget" }; // never thr
142
142
 
143
143
  Your extension owns its own user consent and budget; `/typesafe enable` applies only to this package's tool. Check `authState()` rather than your own consent flag before you report that judgments are on.
144
144
 
145
- Judgments can also go through OpenRouter: `createTypeSafe({ backend: "openrouter" })` sends them to `openrouter.ai` with the key from `OPENROUTER_API_KEY`. Command Code serves the same protocol: `createTypeSafe({ backend: "commandcode" })` sends them to `api.commandcode.ai` with the key from `COMMANDCODE_API_KEY` and the model `typesafe/jev`. So does Liquid AI: `createTypeSafe({ backend: "liquid" })` sends them to `api.liquid.ai` with the key from `LIQUID_API_KEY` and the model `d1:free`, which is free; pass `model: "d1"` for the paid model, priced at $0.040 per million input tokens. Liquid counts the state once per question, where TypeSafe counts it once per request, so a request with N questions costs about N times the state on Liquid. Speed, measured on 2026-10-03 with one request at a time: `d1:free` took a median of about 14 seconds and sometimes failed with HTTP 504 after about 46 seconds, while `d1` took about 0.5 seconds. With `d1:free`, raise `timeoutMs` above its 15-second default, or pass `model: "d1"`. SubQ too: `createTypeSafe({ backend: "subq" })` sends them to `api.subq.ai` with the key from `SUBQ_API_KEY` and the model `subq-snap-preview`, priced at $0.05 per million input tokens. SubQ takes at most 16 questions in one request, a Choice of at least 2 options, and a Score of at most 10 levels: `evaluate` refuses a larger request before it sends it, `evaluateAll` splits to 16, and `client.limits` tells you the limit without a request. Or pass a `BackendEndpoint` object as `backend` to name any host that serves the protocol: it brings its own key variable, never reads `TYPESAFE_API_KEY`, and `backendHost()` reports its destination host for your consent text. These backends have no login store, so `/typesafe login` does not apply to them. Pass the same `backend` to `authState`, `keySituation`, and `ensureApiKey`, or the status you report describes the TypeSafe key while the requests use another one. The `/typesafe` commands and the `typesafe_evaluate` tool always use the TypeSafe backend. Every export — the client, `ask`, batching, the usage ledger, auth state, and the `pi-typesafe/calibrate` and `pi-typesafe/ui` entry points — is in [docs/api.md](docs/api.md).
145
+ Judgments can also go through OpenRouter: `createTypeSafe({ backend: "openrouter" })` sends them to `openrouter.ai` with the key from `OPENROUTER_API_KEY`. Command Code serves the same protocol: `createTypeSafe({ backend: "commandcode" })` sends them to `api.commandcode.ai` with the key from `COMMANDCODE_API_KEY` and the model `typesafe/jev`. So does Liquid AI: `createTypeSafe({ backend: "liquid" })` sends them to `api.liquid.ai` with the key from `LIQUID_API_KEY` and the model `d1:free`, which is free; pass `model: "d1"` for the paid model, priced at $0.040 per million input tokens. Liquid counts the state once per question, where TypeSafe counts it once per request, so a request with N questions costs about N times the state on Liquid. Speed, measured on 2026-10-03 with one request at a time: `d1:free` took a median of about 14 seconds and sometimes failed with HTTP 504 after about 46 seconds, while `d1` took about 0.5 seconds. With `d1:free`, raise `timeoutMs` above its 15-second default, or pass `model: "d1"`. SubQ too: `createTypeSafe({ backend: "subq" })` sends them to `api.subq.ai` with the key from `SUBQ_API_KEY` and the model `subq-snap-preview`, priced at $0.05 per million input tokens. SubQ takes at most 16 questions in one request, a Choice of at least 2 options, and a Score of at most 10 levels: `evaluate` refuses a larger request before it sends it, `evaluateAll` splits to 16, and `client.limits` tells you the limit without a request. Or pass a `BackendEndpoint` object as `backend` to name any host that serves the protocol: it brings its own key variable, never reads `TYPESAFE_API_KEY`, and `backendHost()` reports its destination host for your consent text. Each backend's key can also be stored with `/typesafe login <backend>`: it prompts once, proves the key with the backend's model list where that list checks the key and otherwise with one judge request, and saves it under that backend's name, so a key stored for one backend is never sent to another. A backend's own environment variable still wins over its stored key. Pass the same `backend` to `authState`, `keySituation`, and `ensureApiKey`, or the status you report describes the TypeSafe key while the requests use another one. The `/typesafe` commands and the `typesafe_evaluate` tool follow `PI_TYPESAFE_BACKEND` (`typesafe` by default) and name that backend's host, key variable, and model in their consent and status text — so the extension sends judgments where it says it sends them. A name the registry does not know is a `configuration` error at session start, not a silent fallback. `PI_TYPESAFE_MODEL` overrides the backend's default model, written as that backend's own id is written (`jev-1.14`; it is mapped to the backend's id form, so OpenRouter sends `typesafe/jev-1.14`). `/typesafe login [backend]` and `/typesafe logout [backend]` act on the backend they name, or on the session's own backend when they name none, and on a backend whose environment variable is set they say that the variable wins. Every export — the client, `ask`, batching, the usage ledger, auth state, the `PI_TYPESAFE_BACKEND` and `PI_TYPESAFE_MODEL` readers, and the `pi-typesafe/calibrate` and `pi-typesafe/ui` entry points — is in [docs/api.md](docs/api.md).
146
146
 
147
147
  ## Development
148
148
 
@@ -11,8 +11,12 @@ const FALLBACK_MESSAGE = "TypeSafe request failed.";
11
11
  * share `prepareEvaluationRequest`, so what one accepts the other accepts.
12
12
  */
13
13
  export async function ask(judge, request, options = {}) {
14
- const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_ASK_TIMEOUT_MS);
15
- const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
14
+ // AbortSignal.timeout's timer is unref'd, so a deadline that is the only pending work never fires: node:test on
15
+ // Node 22.19 reported this promise as never settling (CI run 39945731438). A ref'd timer, cleared when the ask
16
+ // settles, makes the documented deadline real and leaves no handle behind.
17
+ const deadline = new AbortController();
18
+ const timer = setTimeout(() => deadline.abort(), options.timeoutMs ?? DEFAULT_ASK_TIMEOUT_MS);
19
+ const signal = options.signal ? AbortSignal.any([options.signal, deadline.signal]) : deadline.signal;
16
20
  try {
17
21
  const result = await judge.evaluate(request, { signal });
18
22
  return { ok: true, answers: result.answers, model: result.model, usage: result.usage, elapsedMs: result.elapsedMs };
@@ -22,4 +26,7 @@ export async function ask(judge, request, options = {}) {
22
26
  return { ok: false, error: error.message, errorCode: error.code };
23
27
  return { ok: false, error: FALLBACK_MESSAGE };
24
28
  }
29
+ finally {
30
+ clearTimeout(timer);
31
+ }
25
32
  }
@@ -27,8 +27,9 @@ export interface AuthState {
27
27
  /** Short human label for the key source: `TYPESAFE_API_KEY`, `OPENROUTER_API_KEY`, `/typesafe login`, `no key`, `unusable key`. */
28
28
  readonly keyName: string;
29
29
  /**
30
- * True when the key in effect was accepted by the backend (login verifies a TypeSafe key; a successful request proves
31
- * any key). The record is shared across backends: switching backends keeps the last outcome until the next request.
30
+ * True when the key in effect was accepted by the backend (a login proves the backend it was asked for; a successful
31
+ * request proves any key). The record is shared across backends: switching backends keeps the last outcome until the
32
+ * next request.
32
33
  */
33
34
  readonly verified: boolean;
34
35
  readonly verifiedAt?: string;
@@ -1,6 +1,6 @@
1
1
  import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { DEFAULT_BACKEND, TYPESAFE_KEY_ENV, resolveBackend, usesTypesafeKey } from "./backends.js";
3
+ import { DEFAULT_BACKEND, TYPESAFE_KEY_ENV, resolveBackend } from "./backends.js";
4
4
  import { credentialsPath, keySituation, keySourceLabel, piTypesafeDir } from "./credentials.js";
5
5
  import { TypeSafeIntegrationError } from "./errors.js";
6
6
  const AUTH_VERSION = 1;
@@ -107,7 +107,7 @@ export function describeAuth(state = authState()) {
107
107
  const label = `${config.label} key`;
108
108
  const since = state.lastFailure ? ` Last failure: ${state.lastFailure.message}${state.lastFailure.at ? ` (${state.lastFailure.at})` : ""}` : "";
109
109
  if (state.kind === "missing") {
110
- const how = usesTypesafeKey(config) ? `a key is configured (/typesafe login or ${TYPESAFE_KEY_ENV})` : `${config.keyEnv} is set in the environment`;
110
+ const how = `a key is configured (/typesafe login${config.name && config.name !== DEFAULT_BACKEND ? ` ${config.name}` : ""} or ${config.keyEnv})`;
111
111
  return { level: "error", text: `${label}: missing — every Jev judgment is skipped until ${how}.${since}` };
112
112
  }
113
113
  if (state.kind === "unusable") {
@@ -55,6 +55,21 @@ export declare const TYPESAFE_KEY_ENV = "TYPESAFE_API_KEY";
55
55
  export declare const DECISIONS_BACKENDS: Record<TypeSafeBackend, RegistryBackendConfig>;
56
56
  /** The registry entry for a backend name; a `configuration` error for a name the registry does not know. */
57
57
  export declare function backendConfig(name: TypeSafeBackend): RegistryBackendConfig;
58
+ /** The environment variable naming the judgment backend a Pi session uses; unset means `typesafe`. */
59
+ export declare const BACKEND_ENV = "PI_TYPESAFE_BACKEND";
60
+ /** The environment variable overriding the backend's default model; unset sends the backend's own default. */
61
+ export declare const MODEL_ENV = "PI_TYPESAFE_MODEL";
62
+ /**
63
+ * The backend a Pi session uses, from `PI_TYPESAFE_BACKEND`. An unset or blank variable means the default backend; a
64
+ * name the registry does not know is a `configuration` error naming the valid names, so a typo fails loudly at
65
+ * session start instead of silently sending judgments to a host the operator did not choose.
66
+ */
67
+ export declare function backendFromEnvironment(env?: NodeJS.ProcessEnv): TypeSafeBackend;
68
+ /**
69
+ * The model the Pi session sends, from `PI_TYPESAFE_MODEL`; `undefined` when unset or blank, so the backend's own
70
+ * default applies. Returned as the caller wrote it: the client maps it to the backend's id form.
71
+ */
72
+ export declare function modelFromEnvironment(env?: NodeJS.ProcessEnv): string | undefined;
58
73
  /**
59
74
  * The model id to send for a caller's `model` on this backend. OpenRouter routes a bare Jev id under the `typesafe`
60
75
  * author: `jev-latest` becomes its alias form `~typesafe/jev-latest`, and a bare `jev-<major>.<minor>` — with or
@@ -65,16 +80,16 @@ export declare function backendConfig(name: TypeSafeBackend): RegistryBackendCon
65
80
  export declare function backendModelId(backend: TypeSafeBackend, model: string): string;
66
81
  /** The model a client sends when the caller names none: the backend's own default, in the form that backend accepts. */
67
82
  export declare function defaultModelId(backend: TypeSafeBackend): string;
83
+ /**
84
+ * The model id a request carries on this backend: the caller's id mapped to the backend's id form, or the backend's
85
+ * own default when the caller names none. The client sends this value and callers print it, so the two cannot disagree.
86
+ */
87
+ export declare function sentModelId(backend: TypeSafeBackend, model?: string): string;
68
88
  /**
69
89
  * The registry's price for a model, in USD per million input tokens, or undefined when the backend names none.
70
90
  * `model` is the id as sent. A caller-supplied endpoint has no prices.
71
91
  */
72
92
  export declare function backendPrice(backend: ResolvedBackend, model: string): number | undefined;
73
- /**
74
- * Whether a backend's key comes from the TypeSafe resolution (`TYPESAFE_API_KEY`, then the login store) or only from
75
- * its own environment variable. Only the TypeSafe backend has a login store; every other backend is environment-only.
76
- */
77
- export declare function usesTypesafeKey(backend: BackendConfig): boolean;
78
93
  /**
79
94
  * Resolve a registry name or a caller-supplied endpoint into the validated form the client uses. A name resolves to
80
95
  * its registry entry unchanged; an endpoint is validated field by field and returned as a fresh object whose `host`
@@ -50,11 +50,35 @@ export const DECISIONS_BACKENDS = {
50
50
  };
51
51
  /** The registry entry for a backend name; a `configuration` error for a name the registry does not know. */
52
52
  export function backendConfig(name) {
53
- const backend = DECISIONS_BACKENDS[name];
53
+ // A bare lookup finds `toString` on Object.prototype, so only an own entry is a backend.
54
+ const backend = Object.hasOwn(DECISIONS_BACKENDS, name) ? DECISIONS_BACKENDS[name] : undefined;
54
55
  if (!backend)
55
56
  throw new TypeSafeIntegrationError("configuration", `Unknown judgment backend "${name}". Valid backends: ${Object.keys(DECISIONS_BACKENDS).join(", ")}.`);
56
57
  return backend;
57
58
  }
59
+ /** The environment variable naming the judgment backend a Pi session uses; unset means `typesafe`. */
60
+ export const BACKEND_ENV = "PI_TYPESAFE_BACKEND";
61
+ /** The environment variable overriding the backend's default model; unset sends the backend's own default. */
62
+ export const MODEL_ENV = "PI_TYPESAFE_MODEL";
63
+ /**
64
+ * The backend a Pi session uses, from `PI_TYPESAFE_BACKEND`. An unset or blank variable means the default backend; a
65
+ * name the registry does not know is a `configuration` error naming the valid names, so a typo fails loudly at
66
+ * session start instead of silently sending judgments to a host the operator did not choose.
67
+ */
68
+ export function backendFromEnvironment(env = process.env) {
69
+ const name = env[BACKEND_ENV]?.trim();
70
+ if (!name)
71
+ return DEFAULT_BACKEND;
72
+ backendConfig(name);
73
+ return name;
74
+ }
75
+ /**
76
+ * The model the Pi session sends, from `PI_TYPESAFE_MODEL`; `undefined` when unset or blank, so the backend's own
77
+ * default applies. Returned as the caller wrote it: the client maps it to the backend's id form.
78
+ */
79
+ export function modelFromEnvironment(env = process.env) {
80
+ return env[MODEL_ENV]?.trim() || undefined;
81
+ }
58
82
  /** Each backend's default model id as the caller writes it, before mapping: OpenRouter pins a version, TypeSafe follows latest. */
59
83
  const DEFAULT_MODEL = {
60
84
  typesafe: "jev-latest",
@@ -84,6 +108,13 @@ export function backendModelId(backend, model) {
84
108
  export function defaultModelId(backend) {
85
109
  return backendModelId(backend, DEFAULT_MODEL[backend]);
86
110
  }
111
+ /**
112
+ * The model id a request carries on this backend: the caller's id mapped to the backend's id form, or the backend's
113
+ * own default when the caller names none. The client sends this value and callers print it, so the two cannot disagree.
114
+ */
115
+ export function sentModelId(backend, model) {
116
+ return model === undefined ? defaultModelId(backend) : backendModelId(backend, model);
117
+ }
87
118
  /**
88
119
  * The registry's price for a model, in USD per million input tokens, or undefined when the backend names none.
89
120
  * `model` is the id as sent. A caller-supplied endpoint has no prices.
@@ -92,13 +123,6 @@ export function backendPrice(backend, model) {
92
123
  const prices = backend.prices;
93
124
  return prices !== undefined && Object.hasOwn(prices, model) ? prices[model] : undefined;
94
125
  }
95
- /**
96
- * Whether a backend's key comes from the TypeSafe resolution (`TYPESAFE_API_KEY`, then the login store) or only from
97
- * its own environment variable. Only the TypeSafe backend has a login store; every other backend is environment-only.
98
- */
99
- export function usesTypesafeKey(backend) {
100
- return (backend.keyEnv ?? TYPESAFE_KEY_ENV) === TYPESAFE_KEY_ENV;
101
- }
102
126
  const KEY_ENV_MESSAGE = "Backend keyEnv must name an environment variable: letters, digits, and underscores, not starting with a digit.";
103
127
  const HOST_MESSAGE = "Backend host must be an absolute https: URL with no user info, path, query, or fragment (http: is allowed only for localhost, 127.0.0.0/8, and [::1]).";
104
128
  function refuse(message) {
@@ -46,7 +46,7 @@ export interface BatchEvaluation<Q extends Questions = Questions> {
46
46
  readonly answers: Partial<Evaluation<Q>["answers"]>;
47
47
  /** The model of the first successful request, when there is one. */
48
48
  readonly model?: string;
49
- /** Usage summed over the requests that succeeded. */
49
+ /** Usage summed over the requests that succeeded; a token count the API did not report adds nothing. */
50
50
  readonly usage: Usage;
51
51
  /** Wall-clock time for the whole batch. */
52
52
  readonly elapsedMs: number;
@@ -54,8 +54,8 @@ function summarize(results, elapsedMs) {
54
54
  }
55
55
  succeeded++;
56
56
  Object.assign(answers, result.value.answers);
57
- inputTokens += result.value.usage.input_tokens;
58
- outputTokens += result.value.usage.output_tokens;
57
+ inputTokens += result.value.usage.input_tokens ?? 0;
58
+ outputTokens += result.value.usage.output_tokens ?? 0;
59
59
  model ??= result.value.model;
60
60
  }
61
61
  return {
@@ -3,7 +3,7 @@ import type { BackendSpec } from "./backends.js";
3
3
  import type { BatchEvaluation, BatchOptions } from "./batch.js";
4
4
  import type { BackendLimits } from "./schema.js";
5
5
  import type { BlockedCap, SpendCaps, UsageLedger, UsageReport } from "./usage.js";
6
- export { backendHost, backendPrice, resolveBackend, DECISIONS_BACKENDS, DEFAULT_BACKEND } from "./backends.js";
6
+ export { BACKEND_ENV, MODEL_ENV, backendFromEnvironment, backendHost, backendPrice, modelFromEnvironment, resolveBackend, sentModelId, DECISIONS_BACKENDS, DEFAULT_BACKEND } from "./backends.js";
7
7
  export type { BackendConfig, BackendEndpoint, BackendSpec, RegistryBackendConfig, ResolvedBackend, TypeSafeBackend } from "./backends.js";
8
8
  export interface TypeSafeOptions {
9
9
  /** Defaults to TYPESAFE_API_KEY, then the key saved by `/typesafe login`; never returned. */
@@ -1,12 +1,12 @@
1
1
  import { TypeSafeClient } from "@typesafe-ai/sdk";
2
2
  import { recordAuthFailure, recordAuthVerified } from "./auth.js";
3
- import { TYPESAFE_KEY_ENV, backendModelId, backendPrice, resolveBackend, usesTypesafeKey } from "./backends.js";
3
+ import { backendPrice, resolveBackend, sentModelId } from "./backends.js";
4
4
  import { evaluateAll, evaluateMany } from "./batch.js";
5
5
  import { keySituation } from "./credentials.js";
6
6
  import { TypeSafeIntegrationError, safeError } from "./errors.js";
7
7
  import { DEFAULT_MAX_INPUT_BYTES, assertWithinByteLimit, prepareEvaluationRequest } from "./schema.js";
8
8
  import { DEFAULT_USD_PER_MTOK, capsFromEnvironment, estimateUsd, mergeCaps, openUsageLedger } from "./usage.js";
9
- export { backendHost, backendPrice, resolveBackend, DECISIONS_BACKENDS, DEFAULT_BACKEND } from "./backends.js";
9
+ export { BACKEND_ENV, MODEL_ENV, backendFromEnvironment, backendHost, backendPrice, modelFromEnvironment, resolveBackend, sentModelId, DECISIONS_BACKENDS, DEFAULT_BACKEND } from "./backends.js";
10
10
  /** The paths the SDK appends to whatever base URL it is given. */
11
11
  const SDK_PATH = "/v1/systemone";
12
12
  const SDK_MODELS_PATH = "/v1/models";
@@ -79,8 +79,9 @@ function validResult(result, questions) {
79
79
  const probability = (value) => Number.isFinite(value) && value >= 0 && value <= 1;
80
80
  if (!result || typeof result.model !== "string" || !result.model || !result.usage || !result.answers)
81
81
  return false;
82
+ // 0.7.0 reports a token count it did not measure as null; that is not malformed, it is unreported.
82
83
  for (const count of [result.usage.input_tokens, result.usage.output_tokens]) {
83
- if (!Number.isSafeInteger(count) || count < 0)
84
+ if (count !== null && (!Number.isSafeInteger(count) || count < 0))
84
85
  return false;
85
86
  }
86
87
  if (Object.keys(result.answers).length !== Object.keys(questions).length)
@@ -94,16 +95,21 @@ function validResult(result, questions) {
94
95
  return false;
95
96
  continue;
96
97
  }
98
+ // A box answer answers a question this package refuses to send, so it never validates.
99
+ if (answer.type === "box")
100
+ return false;
97
101
  if (!probability(answer.confidence) || !answer.probabilities)
98
102
  return false;
103
+ // Rubric length, not its elements: 0.7.0's content type is recursive and mapping it exhausts the compiler.
99
104
  const keys = question.type === "choice" ? Object.keys(question.criteria)
100
- : question.type === "score" ? question.criteria.map((_, index) => String(index)) : [];
105
+ : question.type === "score" ? Array.from({ length: question.criteria.length }, (_, index) => String(index)) : [];
101
106
  const probabilities = new Map(Object.entries(answer.probabilities));
102
107
  if (probabilities.size !== keys.length || keys.some(key => !probability(probabilities.get(key) ?? NaN)))
103
108
  return false;
104
109
  if (answer.type === "choice" && !keys.includes(answer.choice))
105
110
  return false;
106
- if (answer.type === "score" && (!Number.isFinite(answer.score) || answer.score < 0 || answer.score > keys.length - 1 || !answer.legend))
111
+ // Presence of own `legend`, not its value: 0.7.0's legend type carries the recursive content type, which exhausts the compiler.
112
+ if (answer.type === "score" && (!Number.isFinite(answer.score) || answer.score < 0 || answer.score > keys.length - 1 || !Object.hasOwn(answer, "legend")))
107
113
  return false;
108
114
  }
109
115
  return true;
@@ -127,8 +133,9 @@ export function createTypeSafe(options = {}) {
127
133
  const backend = resolveBackend(options.backend);
128
134
  let apiKey = options.apiKey?.trim();
129
135
  const baseURL = backend.host;
130
- // Only a registry backend maps ids; a caller-supplied endpoint's model is sent as the caller wrote it.
131
- const mapModel = (model) => (backend.name === undefined ? model : backendModelId(backend.name, model));
136
+ // Only a registry backend maps ids; a caller-supplied endpoint's model is sent as the caller wrote it. This is the
137
+ // same derivation the extension prints, so the consent text and the request body cannot name different models.
138
+ const mapModel = (model) => (backend.name === undefined ? model : sentModelId(backend.name, model));
132
139
  if (!apiKey) {
133
140
  // The same resolution that authState() and ensureApiKey() report, so the status line and the request agree.
134
141
  const situation = keySituation(options.backend);
@@ -138,7 +145,7 @@ export function createTypeSafe(options = {}) {
138
145
  apiKey = situation.key;
139
146
  }
140
147
  if (!apiKey) {
141
- const how = usesTypesafeKey(backend) ? `Run /typesafe login in Pi, or set ${TYPESAFE_KEY_ENV}` : `Set ${backend.keyEnv}`;
148
+ const how = `Run /typesafe login${backend.name ? ` ${backend.name}` : ""} in Pi, or set ${backend.keyEnv}`;
142
149
  throw new TypeSafeIntegrationError("configuration", `No API key. ${how} in the environment.`);
143
150
  }
144
151
  const timeout = positiveInteger(options.timeoutMs ?? 15_000, "timeoutMs");
@@ -168,6 +175,8 @@ export function createTypeSafe(options = {}) {
168
175
  baseURL,
169
176
  timeout,
170
177
  retry: { maxRetries: 0 },
178
+ // 0.7.0 zstd-compresses any body of 1 KiB or more by default; this package's five backends are unmeasured for it.
179
+ compression: false,
171
180
  logLevel: "off",
172
181
  ...(transport ? { fetch: transport } : {}),
173
182
  });
@@ -238,12 +247,15 @@ export function createTypeSafe(options = {}) {
238
247
  if (!validResult(result, request.questions))
239
248
  throw new TypeSafeIntegrationError("response", "TypeSafe returned an unexpected answer or usage format.");
240
249
  usage.requestsSucceeded += 1;
241
- usage.inputTokens += result.usage.input_tokens;
242
- usage.outputTokens += result.usage.output_tokens;
250
+ // An unreported count is not a count this package can add, price, or charge against a token cap.
251
+ const inputTokens = result.usage.input_tokens ?? 0;
252
+ const outputTokens = result.usage.output_tokens ?? 0;
253
+ usage.inputTokens += inputTokens;
254
+ usage.outputTokens += outputTokens;
243
255
  // Unrounded: a small request must still count toward the cap.
244
- const cost = (result.usage.input_tokens * rateFor(sentModel)) / 1e6;
256
+ const cost = (inputTokens * rateFor(sentModel)) / 1e6;
245
257
  sessionUsd += cost;
246
- ledger.recordSuccess(result.usage.input_tokens, result.usage.output_tokens, cost);
258
+ ledger.recordSuccess(inputTokens, outputTokens, cost);
247
259
  if (!verificationRecorded) {
248
260
  verificationRecorded = true;
249
261
  recordAuthVerified();
@@ -27,18 +27,19 @@ export declare function piTypesafeDir(): string;
27
27
  export declare function credentialsPath(): string;
28
28
  /** Accepts the key only when it is a plausible token; never logs or echoes the value. */
29
29
  export declare function normalizeApiKey(value: unknown): string;
30
+ /** Where a stored key belongs: the registry name, or an endpoint's `keyEnv`. Environment variables still win. */
31
+ export declare function credentialId(backend?: BackendSpec): string;
30
32
  /**
31
- * The stored key, or `undefined` when the file is missing, unreadable, or holds no usable value. Throws
33
+ * The stored key for one backend, or `undefined` when the file is missing, unreadable, or holds no usable value. Throws
32
34
  * `configuration` when the file is readable by other users; keySituation() reports that case as `unusable` instead.
33
35
  */
34
- export declare function readStoredApiKey(): string | undefined;
36
+ export declare function readStoredApiKey(backend?: BackendSpec): string | undefined;
35
37
  /**
36
38
  * What the environment, the login store, and file permissions add up to right now for one judgment backend. A valid
37
39
  * backend never throws: the "unusable" kind carries the user-facing reason (a stored key that other local users can
38
40
  * read). An invalid backend — an unknown name or an endpoint object that fails validation — throws the same
39
41
  * `configuration` error as resolveBackend(), so validate a user-supplied endpoint with resolveBackend() first.
40
- * The TypeSafe backend reads `TYPESAFE_API_KEY`, then the login store. Every other backend reads only its own
41
- * environment variable, because the store holds a TypeSafe key and a login verifies against api.typesafe.ai.
42
+ * One rule for every backend: its own environment variable, then the key stored for it, then missing.
42
43
  */
43
44
  export declare function keySituation(backend?: BackendSpec): KeySituation;
44
45
  /** Short phrase naming the source; full sentences stay with the caller. */
@@ -54,5 +55,6 @@ export declare function resolveApiKey(backend?: BackendSpec): {
54
55
  key: string;
55
56
  source: KeySource;
56
57
  } | undefined;
57
- export declare function storeApiKey(value: unknown): string;
58
- export declare function clearStoredApiKey(): boolean;
58
+ export declare function storeApiKey(value: unknown, backend?: BackendSpec): string;
59
+ /** Remove one backend's stored key, or with no argument every stored key. Returns true when a key was removed. */
60
+ export declare function clearStoredApiKey(backend?: BackendSpec): boolean;
@@ -1,7 +1,7 @@
1
1
  import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { dirname, join } from "node:path";
4
- import { DEFAULT_BACKEND, TYPESAFE_KEY_ENV, resolveBackend, usesTypesafeKey } from "./backends.js";
4
+ import { DEFAULT_BACKEND, TYPESAFE_KEY_ENV, resolveBackend } from "./backends.js";
5
5
  import { TypeSafeIntegrationError } from "./errors.js";
6
6
  /** Mirrors Pi's agent directory rule; every pi-typesafe file lives in this one directory. */
7
7
  export function piTypesafeDir() {
@@ -23,20 +23,41 @@ export function normalizeApiKey(value) {
23
23
  }
24
24
  return key;
25
25
  }
26
+ /** Where a stored key belongs: the registry name, or an endpoint's `keyEnv`. Environment variables still win. */
27
+ export function credentialId(backend = DEFAULT_BACKEND) {
28
+ const config = resolveBackend(backend);
29
+ return config.name ?? config.keyEnv;
30
+ }
31
+ /** The stored keys, by credential id. The pre-0.12 shape, a lone `apiKey`, reads as the TypeSafe key. */
32
+ function readStoredKeys() {
33
+ const path = credentialsPath();
34
+ const raw = JSON.parse(readFileSync(path, "utf8"));
35
+ const keys = {};
36
+ if (raw && typeof raw === "object") {
37
+ const record = raw;
38
+ if (record.keys && typeof record.keys === "object" && !Array.isArray(record.keys)) {
39
+ for (const [id, value] of Object.entries(record.keys)) {
40
+ if (typeof value === "string" && value.trim())
41
+ keys[id] = value.trim();
42
+ }
43
+ }
44
+ if (typeof record.apiKey === "string" && record.apiKey.trim())
45
+ keys[DEFAULT_BACKEND] = record.apiKey.trim();
46
+ }
47
+ return keys;
48
+ }
26
49
  /**
27
- * The stored key, or `undefined` when the file is missing, unreadable, or holds no usable value. Throws
50
+ * The stored key for one backend, or `undefined` when the file is missing, unreadable, or holds no usable value. Throws
28
51
  * `configuration` when the file is readable by other users; keySituation() reports that case as `unusable` instead.
29
52
  */
30
- export function readStoredApiKey() {
53
+ export function readStoredApiKey(backend = DEFAULT_BACKEND) {
31
54
  const path = credentialsPath();
32
55
  try {
33
56
  if (process.platform !== "win32" && (statSync(path).mode & 0o077) !== 0) {
34
57
  // Refuse to use a key other local users can read; the user must fix permissions or log in again.
35
58
  throw new TypeSafeIntegrationError("configuration", `Refusing to read ${path}: it is readable by other users. Run chmod 600 on it, or run /typesafe logout and /typesafe login.`);
36
59
  }
37
- const parsed = JSON.parse(readFileSync(path, "utf8"));
38
- const key = parsed && typeof parsed === "object" ? parsed.apiKey : undefined;
39
- return typeof key === "string" && key.trim() ? key.trim() : undefined;
60
+ return readStoredKeys()[credentialId(backend)];
40
61
  }
41
62
  catch (error) {
42
63
  if (error instanceof TypeSafeIntegrationError)
@@ -49,8 +70,7 @@ export function readStoredApiKey() {
49
70
  * backend never throws: the "unusable" kind carries the user-facing reason (a stored key that other local users can
50
71
  * read). An invalid backend — an unknown name or an endpoint object that fails validation — throws the same
51
72
  * `configuration` error as resolveBackend(), so validate a user-supplied endpoint with resolveBackend() first.
52
- * The TypeSafe backend reads `TYPESAFE_API_KEY`, then the login store. Every other backend reads only its own
53
- * environment variable, because the store holds a TypeSafe key and a login verifies against api.typesafe.ai.
73
+ * One rule for every backend: its own environment variable, then the key stored for it, then missing.
54
74
  */
55
75
  export function keySituation(backend = DEFAULT_BACKEND) {
56
76
  const config = resolveBackend(backend);
@@ -58,11 +78,9 @@ export function keySituation(backend = DEFAULT_BACKEND) {
58
78
  const fromEnvironment = process.env[keyEnv]?.trim();
59
79
  if (fromEnvironment)
60
80
  return { kind: "environment", key: fromEnvironment, keyEnv };
61
- if (!usesTypesafeKey(config))
62
- return { kind: "missing" };
63
81
  const path = credentialsPath();
64
82
  try {
65
- const key = readStoredApiKey();
83
+ const key = readStoredApiKey(backend);
66
84
  return key ? { kind: "stored", key, path } : { kind: "missing" };
67
85
  }
68
86
  catch (error) {
@@ -94,22 +112,34 @@ export function resolveApiKey(backend = DEFAULT_BACKEND) {
94
112
  throw new TypeSafeIntegrationError("configuration", situation.reason);
95
113
  return situation.kind === "environment" || situation.kind === "stored" ? { key: situation.key, source: situation.kind } : undefined;
96
114
  }
97
- export function storeApiKey(value) {
115
+ export function storeApiKey(value, backend = DEFAULT_BACKEND) {
98
116
  const key = normalizeApiKey(value);
99
117
  const path = credentialsPath();
118
+ const id = credentialId(backend);
119
+ // A store that cannot be read (wrong permissions, bad JSON) is replaced rather than blocking the login.
120
+ let keys = {};
121
+ try {
122
+ keys = readStoredKeys();
123
+ }
124
+ catch {
125
+ keys = {};
126
+ }
127
+ keys[id] = key;
100
128
  try {
101
129
  mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
130
+ // Written under a temporary name and renamed, so a crash mid-write cannot truncate the other backends' keys.
102
131
  const temporary = `${path}.${process.pid}.tmp`;
103
- writeFileSync(temporary, `${JSON.stringify({ apiKey: key }, null, 2)}\n`, { mode: 0o600, flag: "w" });
132
+ writeFileSync(temporary, `${JSON.stringify({ version: 1, keys }, null, 2)}\n`, { mode: 0o600, flag: "w" });
104
133
  chmodSync(temporary, 0o600);
105
134
  renameSync(temporary, path);
106
135
  }
107
136
  catch {
108
- throw new TypeSafeIntegrationError("configuration", `Could not write ${path}. Check directory permissions, or set TYPESAFE_API_KEY in the environment instead.`);
137
+ throw new TypeSafeIntegrationError("configuration", `Could not write ${path}. Check directory permissions, or set ${resolveBackend(backend).keyEnv} in the environment instead.`);
109
138
  }
110
139
  return path;
111
140
  }
112
- export function clearStoredApiKey() {
141
+ /** Remove one backend's stored key, or with no argument every stored key. Returns true when a key was removed. */
142
+ export function clearStoredApiKey(backend) {
113
143
  const path = credentialsPath();
114
144
  try {
115
145
  statSync(path);
@@ -117,6 +147,30 @@ export function clearStoredApiKey() {
117
147
  catch {
118
148
  return false;
119
149
  }
120
- rmSync(path, { force: true });
150
+ if (backend === undefined) {
151
+ rmSync(path, { force: true });
152
+ return true;
153
+ }
154
+ let keys;
155
+ try {
156
+ keys = readStoredKeys();
157
+ }
158
+ catch {
159
+ rmSync(path, { force: true });
160
+ return true;
161
+ }
162
+ const id = credentialId(backend);
163
+ if (!(id in keys))
164
+ return false;
165
+ delete keys[id];
166
+ if (!Object.keys(keys).length)
167
+ rmSync(path, { force: true });
168
+ else {
169
+ // Same temporary-name-then-rename write as storeApiKey: the remaining backends' keys survive a crash.
170
+ const temporary = `${path}.${process.pid}.tmp`;
171
+ writeFileSync(temporary, `${JSON.stringify({ version: 1, keys }, null, 2)}\n`, { mode: 0o600, flag: "w" });
172
+ chmodSync(temporary, 0o600);
173
+ renameSync(temporary, path);
174
+ }
121
175
  return true;
122
176
  }