@herbertgao/pi-extensions 2026.10.12 → 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 (269) hide show
  1. package/README.md +11 -11
  2. package/THIRD_PARTY_NOTICES.md +3 -3
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +7 -9
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +7 -9
  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 +14 -8
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +22 -5
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer.ts +28 -6
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +33 -12
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +60 -17
  11. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/default-mode.ts +1 -5
  12. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +20 -5
  13. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/markdown-enhance.ts +4 -1
  14. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +42 -18
  15. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/layout.ts +12 -3
  16. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +131 -0
  17. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +217 -113
  18. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +12 -5
  19. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/subagent-notification.ts +556 -0
  20. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/ansi-text.ts +50 -0
  21. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/format.ts +11 -0
  22. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/patch-keys.ts +4 -0
  23. package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
  24. package/node_modules/@juicesharp/rpiv-ask-user-question/README.md +1 -0
  25. package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +27 -3
  26. package/node_modules/@juicesharp/rpiv-ask-user-question/config.ts +23 -0
  27. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/configuration.md +15 -0
  28. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/keyboard.md +9 -2
  29. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/de.json +7 -4
  30. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/en.json +8 -5
  31. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/es.json +7 -4
  32. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/fr.json +7 -4
  33. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/pt-BR.json +7 -4
  34. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/pt.json +7 -4
  35. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/ru.json +7 -4
  36. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/uk.json +7 -4
  37. package/node_modules/@juicesharp/rpiv-ask-user-question/locales/zh.json +7 -4
  38. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +4 -3
  39. package/node_modules/@juicesharp/rpiv-ask-user-question/presentation.ts +11 -1
  40. package/node_modules/@juicesharp/rpiv-ask-user-question/state/build-questionnaire.ts +6 -0
  41. package/node_modules/@juicesharp/rpiv-ask-user-question/state/key-router.ts +49 -8
  42. package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +6 -0
  43. package/node_modules/@juicesharp/rpiv-ask-user-question/state/state-reducer.ts +13 -1
  44. package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +2 -0
  45. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-block-renderer.ts +19 -7
  46. package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +36 -7
  47. package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-copy.ts +13 -2
  48. package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +24 -8
  49. package/node_modules/@juicesharp/rpiv-ask-user-question/view/transcript.ts +144 -0
  50. package/node_modules/@narumitw/pi-btw/README.md +7 -2
  51. package/node_modules/@narumitw/pi-btw/dist/index.ts +371 -118
  52. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
  53. package/node_modules/@narumitw/pi-btw/docs/main-context-runtime.md +45 -0
  54. package/node_modules/@narumitw/pi-btw/docs/workflows.md +48 -5
  55. package/node_modules/@narumitw/pi-btw/package.json +1 -1
  56. package/node_modules/@narumitw/pi-btw/src/btw.ts +39 -14
  57. package/node_modules/@narumitw/pi-btw/src/import-main-updates.ts +84 -0
  58. package/node_modules/@narumitw/pi-btw/src/keybindings.ts +29 -4
  59. package/node_modules/@narumitw/pi-btw/src/main-context-snapshot.ts +125 -0
  60. package/node_modules/@narumitw/pi-btw/src/menu.ts +1 -0
  61. package/node_modules/@narumitw/pi-btw/src/side-thread.ts +66 -17
  62. package/node_modules/@narumitw/pi-btw/src/transcript-markdown.ts +5 -5
  63. package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +47 -6
  64. package/node_modules/pi-lens/CHANGELOG.md +440 -0
  65. package/node_modules/pi-lens/README.md +13 -3
  66. package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -0
  67. package/node_modules/pi-lens/dist/chunk-22Y2BM7H.js +23 -0
  68. package/node_modules/pi-lens/dist/{chunk-ATKJFDQN.js → chunk-27VWVB23.js} +12 -14
  69. package/node_modules/pi-lens/dist/{chunk-S2HEXIWI.js → chunk-2FYKETQJ.js} +10 -6
  70. package/node_modules/pi-lens/dist/{chunk-SRYEJNES.js → chunk-2LDMXL2M.js} +2 -2
  71. package/node_modules/pi-lens/dist/{chunk-ZHH37KZL.js → chunk-2SDHYHHO.js} +17 -17
  72. package/node_modules/pi-lens/dist/chunk-2Y6OJRSI.js +38 -0
  73. package/node_modules/pi-lens/dist/chunk-3SNDVPOR.js +507 -0
  74. package/node_modules/pi-lens/dist/{chunk-5OFV52AM.js → chunk-3WCEHYOI.js} +1 -1
  75. package/node_modules/pi-lens/dist/chunk-44X7VIKR.js +73 -0
  76. package/node_modules/pi-lens/dist/{chunk-DEL2U6CM.js → chunk-4FHUGDKU.js} +16 -14
  77. package/node_modules/pi-lens/dist/{chunk-CT4MN5IU.js → chunk-4ODSZ35Z.js} +353 -359
  78. package/node_modules/pi-lens/dist/{chunk-ZIVJBOO3.js → chunk-4U7GDSZQ.js} +2 -2
  79. package/node_modules/pi-lens/dist/chunk-54NIOJJZ.js +25 -0
  80. package/node_modules/pi-lens/dist/{chunk-N5FLEO7W.js → chunk-5DKE4HGX.js} +37 -37
  81. package/node_modules/pi-lens/dist/{chunk-P63GXC37.js → chunk-5LRUKYFA.js} +31 -4
  82. package/node_modules/pi-lens/dist/{chunk-HRNHZA3N.js → chunk-63NMUNYP.js} +12 -16
  83. package/node_modules/pi-lens/dist/{chunk-HWCCCQNX.js → chunk-6XSESGWD.js} +13 -6
  84. package/node_modules/pi-lens/dist/{chunk-UMS2MFPZ.js → chunk-72J27ICO.js} +2 -3
  85. package/node_modules/pi-lens/dist/{chunk-ED36RF6Y.js → chunk-7FLRUH6B.js} +1 -1
  86. package/node_modules/pi-lens/dist/chunk-7IYC4ENJ.js +297 -0
  87. package/node_modules/pi-lens/dist/chunk-7WWQAW5P.js +30 -0
  88. package/node_modules/pi-lens/dist/{chunk-3DA2JDOL.js → chunk-7ZS7MC24.js} +551 -203
  89. package/node_modules/pi-lens/dist/{chunk-WMYE35PX.js → chunk-AHWA4AKM.js} +7 -5
  90. package/node_modules/pi-lens/dist/{chunk-JW3YWBVB.js → chunk-AI3GP74G.js} +17 -19
  91. package/node_modules/pi-lens/dist/{chunk-AGSS7277.js → chunk-APFJKOP6.js} +6 -23
  92. package/node_modules/pi-lens/dist/{chunk-ZVUL7QYY.js → chunk-ASRAO7KG.js} +29 -32
  93. package/node_modules/pi-lens/dist/{chunk-BW5KFIQC.js → chunk-AWQWXSW4.js} +1 -0
  94. package/node_modules/pi-lens/dist/{chunk-TLX72JTG.js → chunk-CG5V25HX.js} +1 -1
  95. package/node_modules/pi-lens/dist/chunk-CKEQFGLT.js +32 -0
  96. package/node_modules/pi-lens/dist/{chunk-Y6GZHWSJ.js → chunk-COOUUC5W.js} +6 -6
  97. package/node_modules/pi-lens/dist/{chunk-XTBDCR27.js → chunk-CPZ5JJW6.js} +4 -4
  98. package/node_modules/pi-lens/dist/{chunk-RKKOYPRA.js → chunk-DS2USX5G.js} +13 -15
  99. package/node_modules/pi-lens/dist/chunk-EA2ZRG44.js +27 -0
  100. package/node_modules/pi-lens/dist/{chunk-GSLNCYGG.js → chunk-EDMLIW6W.js} +13 -14
  101. package/node_modules/pi-lens/dist/{chunk-2EECBNC5.js → chunk-EIKRZ32J.js} +75 -0
  102. package/node_modules/pi-lens/dist/chunk-EKNWOL2I.js +27 -0
  103. package/node_modules/pi-lens/dist/{chunk-R3T7CLQ2.js → chunk-ELZRSR5N.js} +41 -41
  104. package/node_modules/pi-lens/dist/{chunk-GMX5OS7B.js → chunk-EN5AM7PX.js} +11 -12
  105. package/node_modules/pi-lens/dist/{chunk-3RKP3FMS.js → chunk-EWXXLS26.js} +226 -24
  106. package/node_modules/pi-lens/dist/chunk-EX4EXBW7.js +37 -0
  107. package/node_modules/pi-lens/dist/{chunk-XHJBS436.js → chunk-EXVXBSGN.js} +25 -25
  108. package/node_modules/pi-lens/dist/{chunk-MZGQNL3Y.js → chunk-F7BO6FWH.js} +12 -13
  109. package/node_modules/pi-lens/dist/{chunk-V35JG4JB.js → chunk-FEDWAYDS.js} +152 -334
  110. package/node_modules/pi-lens/dist/{chunk-J64T55EI.js → chunk-FWZRGGGY.js} +73 -9
  111. package/node_modules/pi-lens/dist/{chunk-T57LYLZT.js → chunk-G224FADB.js} +1 -1
  112. package/node_modules/pi-lens/dist/chunk-G5UCJFT7.js +26 -0
  113. package/node_modules/pi-lens/dist/{chunk-LLJNQKQW.js → chunk-GLW3YDZZ.js} +20 -13
  114. package/node_modules/pi-lens/dist/{chunk-GXFV6MYU.js → chunk-GTDSYEA2.js} +72 -39
  115. package/node_modules/pi-lens/dist/{chunk-DUO2TU77.js → chunk-GYRZ72R4.js} +10 -4
  116. package/node_modules/pi-lens/dist/chunk-HYVXA3BB.js +49 -0
  117. package/node_modules/pi-lens/dist/{chunk-W66O5E25.js → chunk-IEBJF3PN.js} +13 -15
  118. package/node_modules/pi-lens/dist/{chunk-GAQ7OQG6.js → chunk-IL7K66ZQ.js} +83 -94
  119. package/node_modules/pi-lens/dist/{chunk-T7FEBKXN.js → chunk-JWOVP5BL.js} +7 -9
  120. package/node_modules/pi-lens/dist/{chunk-UBOQLVT2.js → chunk-K2GUZ4DN.js} +4 -4
  121. package/node_modules/pi-lens/dist/{chunk-5VSF4UUQ.js → chunk-K4SZB56V.js} +34 -39
  122. package/node_modules/pi-lens/dist/{chunk-7D6L4MTX.js → chunk-KCBRHV5E.js} +3 -3
  123. package/node_modules/pi-lens/dist/{chunk-GSM5UU7A.js → chunk-KFXCL4OV.js} +38 -28
  124. package/node_modules/pi-lens/dist/{chunk-J6MPGQTS.js → chunk-KJJAVH3X.js} +81 -15
  125. package/node_modules/pi-lens/dist/{chunk-BWD5EPKO.js → chunk-KPVLQHCZ.js} +4 -6
  126. package/node_modules/pi-lens/dist/{chunk-MPNJLASA.js → chunk-KX56K73G.js} +10 -13
  127. package/node_modules/pi-lens/dist/{chunk-AWSCPCN2.js → chunk-LMCTHJ2H.js} +19 -19
  128. package/node_modules/pi-lens/dist/{chunk-IWDLU6K3.js → chunk-MEFLGBCS.js} +4 -6
  129. package/node_modules/pi-lens/dist/{chunk-TOY6QKOH.js → chunk-MKPCELNI.js} +17 -17
  130. package/node_modules/pi-lens/dist/{chunk-POMLXPMY.js → chunk-N3PLNNCW.js} +1 -1
  131. package/node_modules/pi-lens/dist/chunk-N5FBM25N.js +22 -0
  132. package/node_modules/pi-lens/dist/{chunk-CYRKQRPM.js → chunk-NFNVDDGB.js} +2 -4
  133. package/node_modules/pi-lens/dist/{chunk-RMLC67LF.js → chunk-NLIVE7L6.js} +2 -30
  134. package/node_modules/pi-lens/dist/{chunk-24AKHFGP.js → chunk-OMJ3OFBJ.js} +6 -6
  135. package/node_modules/pi-lens/dist/{chunk-IQWN5JCP.js → chunk-OZNCKLOX.js} +13 -14
  136. package/node_modules/pi-lens/dist/chunk-P5XUGPIX.js +31 -0
  137. package/node_modules/pi-lens/dist/{chunk-2KXTHF3M.js → chunk-PJXNTPB2.js} +253 -33
  138. package/node_modules/pi-lens/dist/chunk-PKOXJIVT.js +88 -0
  139. package/node_modules/pi-lens/dist/{chunk-DGUKIYSI.js → chunk-PP2A5V2T.js} +8 -10
  140. package/node_modules/pi-lens/dist/{chunk-KAPJINKN.js → chunk-Q42LJANT.js} +2 -2
  141. package/node_modules/pi-lens/dist/{chunk-UZ2XCLYS.js → chunk-Q4BKKOVC.js} +8 -8
  142. package/node_modules/pi-lens/dist/{chunk-TIQ2PKDW.js → chunk-QT66NEYN.js} +4 -4
  143. package/node_modules/pi-lens/dist/{chunk-U44DJXQP.js → chunk-RCHO5W7M.js} +15 -18
  144. package/node_modules/pi-lens/dist/{chunk-YH5MVY2U.js → chunk-RG3MXTRI.js} +7 -7
  145. package/node_modules/pi-lens/dist/chunk-RG7OODGM.js +57 -0
  146. package/node_modules/pi-lens/dist/{chunk-OHKJ7PQF.js → chunk-RU34BA4D.js} +43 -39
  147. package/node_modules/pi-lens/dist/{chunk-JMYYOTQG.js → chunk-S26LC76R.js} +13 -1
  148. package/node_modules/pi-lens/dist/{chunk-XBJVAEEO.js → chunk-S55TEC7I.js} +3 -2
  149. package/node_modules/pi-lens/dist/{chunk-RVK72CZX.js → chunk-SJHC3BCZ.js} +1397 -481
  150. package/node_modules/pi-lens/dist/{chunk-IYNJ6YPZ.js → chunk-SNEUMLM7.js} +4 -4
  151. package/node_modules/pi-lens/dist/{chunk-S67KYG37.js → chunk-T4NGVFYI.js} +2 -2
  152. package/node_modules/pi-lens/dist/{chunk-YCWYO6TQ.js → chunk-THEXI2QO.js} +48 -45
  153. package/node_modules/pi-lens/dist/{chunk-AMERCH6V.js → chunk-TL2TCJYL.js} +15 -16
  154. package/node_modules/pi-lens/dist/{chunk-KUA4OJ5Y.js → chunk-TPYYEDP5.js} +823 -350
  155. package/node_modules/pi-lens/dist/{chunk-YNE3RP52.js → chunk-TVZRLTG6.js} +8 -1
  156. package/node_modules/pi-lens/dist/{chunk-ROYSX2S5.js → chunk-UCVMSOXF.js} +2 -2
  157. package/node_modules/pi-lens/dist/chunk-UL5SXQVX.js +32 -0
  158. package/node_modules/pi-lens/dist/{chunk-7HXE67BN.js → chunk-UO66IMVP.js} +2 -2
  159. package/node_modules/pi-lens/dist/{chunk-VOOAPROD.js → chunk-UVY4TOJH.js} +3 -3
  160. package/node_modules/pi-lens/dist/{chunk-RKBXZN3A.js → chunk-VIDEKABZ.js} +2 -2
  161. package/node_modules/pi-lens/dist/{chunk-2FN63LPV.js → chunk-VITFDI3O.js} +13 -14
  162. package/node_modules/pi-lens/dist/{chunk-6DLWKFEX.js → chunk-VUAVE3QC.js} +41 -42
  163. package/node_modules/pi-lens/dist/{chunk-FM4RDMKT.js → chunk-WUY4BZEP.js} +10 -12
  164. package/node_modules/pi-lens/dist/{chunk-SD4I7ZO4.js → chunk-X3UTCXAA.js} +43 -53
  165. package/node_modules/pi-lens/dist/chunk-XHDBJODR.js +45 -0
  166. package/node_modules/pi-lens/dist/{chunk-5IUSNGOC.js → chunk-XHLK33VM.js} +28 -21
  167. package/node_modules/pi-lens/dist/{chunk-3KAZU3VR.js → chunk-XI34NWDI.js} +2 -2
  168. package/node_modules/pi-lens/dist/{chunk-QBFBRV2B.js → chunk-XWFIHYCH.js} +4 -2
  169. package/node_modules/pi-lens/dist/{chunk-JUKMK5Y4.js → chunk-Y2TPADJR.js} +10 -11
  170. package/node_modules/pi-lens/dist/{chunk-EBC36LNN.js → chunk-Y5KTA2OB.js} +17 -17
  171. package/node_modules/pi-lens/dist/{chunk-HYGZEMX6.js → chunk-YKVDBNPO.js} +11 -5
  172. package/node_modules/pi-lens/dist/{chunk-KN35K52N.js → chunk-YSDPVDFC.js} +3 -3
  173. package/node_modules/pi-lens/dist/chunk-YWNO5Q4R.js +44 -0
  174. package/node_modules/pi-lens/dist/{chunk-US7ECLD7.js → chunk-YWWG4AQA.js} +119 -28
  175. package/node_modules/pi-lens/dist/{chunk-O4NWQT6I.js → chunk-YXDCRUKQ.js} +4 -4
  176. package/node_modules/pi-lens/dist/{chunk-XYURS6EN.js → chunk-YXGRRORB.js} +15 -17
  177. package/node_modules/pi-lens/dist/{chunk-IUE7SSKV.js → chunk-ZAPSUBLU.js} +13 -7
  178. package/node_modules/pi-lens/dist/{chunk-EUXZEFTV.js → chunk-ZPJM7DID.js} +3 -3
  179. package/node_modules/pi-lens/dist/{chunk-5HSRT26B.js → chunk-ZSUX7KEM.js} +16 -15
  180. package/node_modules/pi-lens/dist/index.js +37155 -32210
  181. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +11 -12
  182. package/node_modules/pi-lens/dist/mcp/cli.js +46 -45
  183. package/node_modules/pi-lens/dist/mcp/server.js +1210 -574
  184. package/node_modules/pi-lens/dist/mcp/worker.js +65 -65
  185. package/node_modules/pi-lens/dist/probes/installer.js +21 -23
  186. package/node_modules/pi-lens/docs/adr/0010-trace-validation-session-lifecycle.md +390 -0
  187. package/node_modules/pi-lens/docs/adr/README.md +1 -0
  188. package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +5 -3
  189. package/node_modules/pi-lens/docs/configuration.md +9 -0
  190. package/node_modules/pi-lens/docs/engineering-principles.md +12 -0
  191. package/node_modules/pi-lens/docs/environment-variables.md +20 -0
  192. package/node_modules/pi-lens/docs/features.md +16 -1
  193. package/node_modules/pi-lens/docs/globalconfig.md +37 -8
  194. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +105 -12
  195. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +37 -18
  196. package/node_modules/pi-lens/docs/pi-lens-fixer.md +22 -1
  197. package/node_modules/pi-lens/docs/pi-lens-investigator.md +14 -0
  198. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +23 -10
  199. package/node_modules/pi-lens/docs/pi-lens-monitor.md +64 -8
  200. package/node_modules/pi-lens/docs/pi-lens-retro.md +2 -2
  201. package/node_modules/pi-lens/docs/pi-lens-reviewer.md +48 -1
  202. package/node_modules/pi-lens/docs/pi-lens-subagent.md +8 -1
  203. package/node_modules/pi-lens/docs/release-qa-baseline.md +19 -7
  204. package/node_modules/pi-lens/docs/servercapabilities.md +47 -47
  205. package/node_modules/pi-lens/docs/settings.md +9 -5
  206. package/node_modules/pi-lens/docs/subagent-compat.md +1 -1
  207. package/node_modules/pi-lens/docs/usage.md +1 -0
  208. package/node_modules/pi-lens/package.json +6 -4
  209. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-return-value-in-generator-test.yml +17 -0
  210. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-js-test.yml +86 -0
  211. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-sql-in-code-execute-test.yml +86 -0
  212. package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/unchecked-numeric-parse-python-test.yml +15 -0
  213. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-return-value-in-generator.yml +9 -4
  214. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +119 -0
  215. package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +119 -0
  216. package/node_modules/pi-lens/rules/ast-grep-rules/rules/unchecked-numeric-parse-python.yml +13 -2
  217. package/node_modules/pi-lens/rules/rule-catalog.json +25 -1
  218. package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +15 -5
  219. package/node_modules/pi-lens/scripts/lib/is-main-module.mjs +27 -0
  220. package/node_modules/pi-lens/scripts/lib/scratch-home-env.mjs +21 -0
  221. package/node_modules/pi-lens/scripts/rpc-load-check.mjs +4 -6
  222. package/node_modules/pi-lens/scripts/warm-loader-cache.mjs +2 -5
  223. package/node_modules/pi-next-cue/package.json +4 -1
  224. package/node_modules/pi-provider-qoder/dist/index.js +438 -283
  225. package/node_modules/pi-provider-qoder/package.json +1 -1
  226. package/node_modules/pi-typesafe/README.md +6 -6
  227. package/node_modules/pi-typesafe/dist/ask.js +9 -2
  228. package/node_modules/pi-typesafe/dist/auth.d.ts +3 -2
  229. package/node_modules/pi-typesafe/dist/auth.js +2 -2
  230. package/node_modules/pi-typesafe/dist/backends.d.ts +20 -5
  231. package/node_modules/pi-typesafe/dist/backends.js +32 -8
  232. package/node_modules/pi-typesafe/dist/batch.d.ts +1 -1
  233. package/node_modules/pi-typesafe/dist/batch.js +2 -2
  234. package/node_modules/pi-typesafe/dist/client.d.ts +1 -1
  235. package/node_modules/pi-typesafe/dist/client.js +24 -12
  236. package/node_modules/pi-typesafe/dist/credentials.d.ts +8 -6
  237. package/node_modules/pi-typesafe/dist/credentials.js +70 -16
  238. package/node_modules/pi-typesafe/dist/extension.js +118 -26
  239. package/node_modules/pi-typesafe/dist/index.d.ts +1 -1
  240. package/node_modules/pi-typesafe/dist/index.js +1 -1
  241. package/node_modules/pi-typesafe/dist/key-prompt.d.ts +1 -1
  242. package/node_modules/pi-typesafe/dist/key-prompt.js +6 -6
  243. package/node_modules/pi-typesafe/dist/login.d.ts +11 -10
  244. package/node_modules/pi-typesafe/dist/login.js +24 -21
  245. package/node_modules/pi-typesafe/dist/schema.d.ts +8 -8
  246. package/node_modules/pi-typesafe/dist/schema.js +29 -7
  247. package/node_modules/pi-typesafe/package.json +2 -2
  248. package/package.json +12 -12
  249. package/node_modules/pi-lens/dist/chunk-3PTHXJXR.js +0 -28
  250. package/node_modules/pi-lens/dist/chunk-3QED2P4V.js +0 -31
  251. package/node_modules/pi-lens/dist/chunk-5WRPDP2A.js +0 -47
  252. package/node_modules/pi-lens/dist/chunk-ABBOA7UD.js +0 -157
  253. package/node_modules/pi-lens/dist/chunk-CUHSHSB6.js +0 -273
  254. package/node_modules/pi-lens/dist/chunk-GL5LUMZE.js +0 -51
  255. package/node_modules/pi-lens/dist/chunk-HAD7QRQI.js +0 -30
  256. package/node_modules/pi-lens/dist/chunk-JORED7EX.js +0 -44
  257. package/node_modules/pi-lens/dist/chunk-KYUB6QDC.js +0 -72
  258. package/node_modules/pi-lens/dist/chunk-LZSEQW6A.js +0 -57
  259. package/node_modules/pi-lens/dist/chunk-M2IFVFWU.js +0 -79
  260. package/node_modules/pi-lens/dist/chunk-M2UD3LPU.js +0 -88
  261. package/node_modules/pi-lens/dist/chunk-MBKQHGA7.js +0 -39
  262. package/node_modules/pi-lens/dist/chunk-R7YOCSNV.js +0 -23
  263. package/node_modules/pi-lens/dist/chunk-SKAMFC7A.js +0 -28
  264. package/node_modules/pi-lens/dist/chunk-SYE6T2EB.js +0 -28
  265. package/node_modules/pi-lens/dist/chunk-TRETHTQO.js +0 -26
  266. package/node_modules/pi-lens/dist/chunk-UA7ZXYDR.js +0 -184
  267. package/node_modules/pi-lens/dist/chunk-XTFDJI3T.js +0 -24
  268. package/node_modules/pi-lens/dist/chunk-Z3CCVDUB.js +0 -76
  269. package/node_modules/pi-next-cue/.github/workflows/publish.yml +0 -20
@@ -719,6 +719,24 @@ function buildThinkingLevelMap(entry) {
719
719
  }
720
720
  return void 0;
721
721
  }
722
+ function buildThinkingConfig(entry) {
723
+ const tc = entry.thinking_config;
724
+ const efforts = tc?.enabled?.efforts;
725
+ if (!efforts || typeof efforts !== "object") return void 0;
726
+ const supported = new Set(Object.keys(efforts));
727
+ const ordered = PI_THINKING_LEVELS.filter((level) => supported.has(level));
728
+ if (ordered.length === 0) return void 0;
729
+ const defaultLevel = PI_THINKING_LEVELS.find((level) => efforts[level]?.is_default);
730
+ return {
731
+ mode: "effort",
732
+ efforts: ordered,
733
+ ...defaultLevel ? { defaultLevel } : {},
734
+ // Qoder's catalog marks a `disabled` branch when thinking can be turned
735
+ // off. Without it reasoning is mandatory upstream, so omp clamps "off" to
736
+ // the lowest supported effort instead of disabling.
737
+ requiresEffort: !tc?.disabled
738
+ };
739
+ }
722
740
  function getCachedModels(mode) {
723
741
  const data = readParsedModelCache(mode);
724
742
  if (data && Array.isArray(data.models)) {
@@ -730,7 +748,7 @@ function getCachedModels(mode) {
730
748
  if (staticModel) return { ...model, id: staticModel.id, name: staticModel.name };
731
749
  return model.name ? { ...model, id: toQoderModelId(model.name) } : model;
732
750
  });
733
- if (data.configs && typeof data.configs === "object" && !data.configs.auto) {
751
+ if (data.configs && typeof data.configs === "object" && !data.configs.auto && !data.configs.Auto) {
734
752
  return models.filter((model) => model.id.toLowerCase() !== "auto");
735
753
  }
736
754
  return models;
@@ -830,6 +848,7 @@ async function updateQoderModelsCache(authToken, userID, name, email, mode) {
830
848
  const isReasoning = !!entry.is_reasoning || !!entry.thinking_config;
831
849
  const supportsEffort = !!entry.thinking_config?.enabled?.efforts;
832
850
  const thinkingLevelMap = buildThinkingLevelMap(entry);
851
+ const thinking = buildThinkingConfig(entry);
833
852
  const modelInfo = { id: toQoderModelId(display), name: display };
834
853
  configs[modelInfo.id] = entry;
835
854
  newModels.push({
@@ -841,6 +860,7 @@ async function updateQoderModelsCache(authToken, userID, name, email, mode) {
841
860
  reasoning: isReasoning,
842
861
  supportsEffort,
843
862
  thinkingLevelMap,
863
+ thinking,
844
864
  input: isVL ? ["text", "image"] : ["text"],
845
865
  cost: ZERO_COST,
846
866
  contextWindow: ctxLen,
@@ -9830,6 +9850,61 @@ function transformMessagesForQoder(messages) {
9830
9850
  }
9831
9851
 
9832
9852
  // src/protocol/stream.ts
9853
+ var MODEL_BUSY_CODE = "10605";
9854
+ var DEFAULT_MODEL_BUSY_RETRIES = 2;
9855
+ var MAX_MODEL_BUSY_RETRIES = 10;
9856
+ var MODEL_BUSY_MAX_WAIT_MS = 5e3;
9857
+ var QoderModelBusyError = class extends Error {
9858
+ constructor(message, retryAfterMs, sawModelOutput = false) {
9859
+ super(message);
9860
+ this.retryAfterMs = retryAfterMs;
9861
+ this.sawModelOutput = sawModelOutput;
9862
+ this.name = "QoderModelBusyError";
9863
+ }
9864
+ retryAfterMs;
9865
+ sawModelOutput;
9866
+ };
9867
+ function parseJsonObject(value, depth = 0) {
9868
+ if (depth > 4) return void 0;
9869
+ if (typeof value === "string") {
9870
+ try {
9871
+ return parseJsonObject(JSON.parse(value), depth + 1);
9872
+ } catch {
9873
+ return void 0;
9874
+ }
9875
+ }
9876
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
9877
+ }
9878
+ function parseModelBusyRejection(body) {
9879
+ const outer = parseJsonObject(body);
9880
+ const busy = parseJsonObject(outer?.message);
9881
+ if (busy?.code !== MODEL_BUSY_CODE) return void 0;
9882
+ const queue = parseJsonObject(busy.message);
9883
+ if (!queue) return void 0;
9884
+ if (queue.isQueued !== false || queue.serviceAvailable !== true) return void 0;
9885
+ const seconds = queue.retryAfterSeconds;
9886
+ const retryAfterMs = typeof seconds === "number" && Number.isFinite(seconds) && seconds > 0 ? Math.round(seconds * 1e3) : 0;
9887
+ return { retryAfterMs };
9888
+ }
9889
+ function sleepWithAbort(ms, signal) {
9890
+ if (signal?.aborted) return Promise.reject(new Error("Aborted"));
9891
+ if (ms <= 0) return Promise.resolve();
9892
+ return new Promise((resolve2, reject) => {
9893
+ if (signal?.aborted) {
9894
+ reject(new Error("Aborted"));
9895
+ return;
9896
+ }
9897
+ const onAbort = () => {
9898
+ clearTimeout(timer);
9899
+ reject(new Error("Aborted"));
9900
+ };
9901
+ const timer = setTimeout(() => {
9902
+ signal?.removeEventListener("abort", onAbort);
9903
+ resolve2();
9904
+ }, ms);
9905
+ signal?.addEventListener("abort", onAbort, { once: true });
9906
+ });
9907
+ }
9833
9908
  function refreshToolIndexes(output, toolCalls) {
9834
9909
  const lastToolState = toolCalls.lastToolState;
9835
9910
  if (!lastToolState || output.content[lastToolState.contentIndex] === lastToolState.block) return;
@@ -10052,7 +10127,9 @@ function streamQoder(model, context, options) {
10052
10127
  const toolsRaw = resolved.tools.length > 0 ? transformTools(resolved.tools) : void 0;
10053
10128
  const recordID = stableChatRecordID(qoderModel, normalizedMessages, toolsRaw, maxTokens);
10054
10129
  const requestedLevel = options?.reasoning;
10055
- const clamped = requestedLevel ? clampThinkingLevel(model, requestedLevel) : void 0;
10130
+ const extOptions = options;
10131
+ const explicitlyOff = extOptions?.disableReasoning === true || extOptions?.forceReasoningOff === true || requestedLevel === false || requestedLevel === "off";
10132
+ const clamped = !explicitlyOff && requestedLevel ? clampThinkingLevel(model, requestedLevel) : void 0;
10056
10133
  const reasoningLevel = clamped === "off" ? void 0 : clamped;
10057
10134
  const parameters = { max_tokens: maxTokens };
10058
10135
  if (reasoningLevel) {
@@ -10064,6 +10141,11 @@ function streamQoder(model, context, options) {
10064
10141
  }
10065
10142
  } else {
10066
10143
  parameters.enable_thinking = false;
10144
+ const tc = modelConfig?.thinking_config;
10145
+ const lacksDisabledBranch = tc?.enabled?.efforts && !tc.disabled || model.thinkingLevelMap?.off === null;
10146
+ if (!lacksDisabledBranch) {
10147
+ parameters.reasoning_effort = "none";
10148
+ }
10067
10149
  }
10068
10150
  const reqBody = {
10069
10151
  request_id: crypto3.randomUUID(),
@@ -10097,14 +10179,14 @@ function streamQoder(model, context, options) {
10097
10179
  context: [],
10098
10180
  modelConfig: {
10099
10181
  key: qoderModel,
10100
- is_reasoning: isReasoning
10182
+ is_reasoning: reasoningLevel ? isReasoning : false
10101
10183
  },
10102
10184
  originalContent: lastUserText
10103
10185
  },
10104
10186
  features: [],
10105
10187
  text: lastUserText
10106
10188
  },
10107
- model_config: modelConfig,
10189
+ model_config: reasoningLevel ? modelConfig : { ...modelConfig, is_reasoning: false },
10108
10190
  business: {
10109
10191
  product: "cli",
10110
10192
  version: "1.0.0",
@@ -10115,328 +10197,401 @@ function streamQoder(model, context, options) {
10115
10197
  begin_at: Date.now()
10116
10198
  }
10117
10199
  };
10118
- const bodyBytes = Buffer.from(JSON.stringify(reqBody));
10119
- const encodedBytes = qoderEncodeBody(bodyBytes);
10120
10200
  const chatURL = getQoderChatURL(providerMode);
10121
- const headers = buildAuthHeaders(encodedBytes, chatURL, {
10201
+ const modelSource = modelConfig.source || "system";
10202
+ const requestedRetries = options?.maxRetries;
10203
+ const modelBusyRetries = Math.min(
10204
+ Math.max(
10205
+ 0,
10206
+ typeof requestedRetries === "number" && Number.isFinite(requestedRetries) ? Math.floor(requestedRetries) : DEFAULT_MODEL_BUSY_RETRIES
10207
+ ),
10208
+ MAX_MODEL_BUSY_RETRIES
10209
+ );
10210
+ const requestedMaxWaitMs = options?.maxRetryDelayMs;
10211
+ const modelBusyMaxWaitMs = typeof requestedMaxWaitMs === "number" && Number.isFinite(requestedMaxWaitMs) && requestedMaxWaitMs > 0 ? Math.min(MODEL_BUSY_MAX_WAIT_MS, requestedMaxWaitMs) : MODEL_BUSY_MAX_WAIT_MS;
10212
+ let encodedBytes = qoderEncodeBody(Buffer.from(JSON.stringify(reqBody)));
10213
+ let headers = buildAuthHeaders(encodedBytes, chatURL, {
10122
10214
  userID,
10123
10215
  authToken: accessToken,
10124
10216
  name,
10125
10217
  email,
10126
10218
  machineID
10127
10219
  });
10128
- const modelSource = modelConfig.source || "system";
10129
- const response = await fetch(chatURL, {
10130
- method: "POST",
10131
- headers: {
10132
- "Content-Type": "application/json",
10133
- Accept: "text/event-stream",
10134
- "Cache-Control": "no-cache",
10135
- "Accept-Encoding": "identity",
10136
- "X-Model-Key": qoderModel,
10137
- "X-Model-Source": modelSource,
10138
- ...headers
10139
- },
10140
- body: encodedBytes,
10141
- signal: options?.signal
10142
- });
10143
- if (!response.ok) {
10144
- const errText = await response.text();
10145
- throw new Error(`Qoder API request failed: ${response.status} ${response.statusText}. Response: ${errText}`);
10146
- }
10147
- const reader = response.body?.getReader();
10148
- if (!reader) throw new Error("No response body");
10149
- const decoder = new TextDecoder();
10150
- let buffer = "";
10151
- let bufferStart = 0;
10152
- let contentBlockIndex = -1;
10153
- let thinkingBlockIndex = -1;
10154
- let rawReasoningTail = "";
10155
- let toolCalls;
10156
10220
  const thinkingEnabled = options?.reasoning !== false && options?.reasoning !== "off";
10157
- const thinkingParser = thinkingEnabled ? new ThinkingTagParser(output, stream) : null;
10158
10221
  stream.push({ type: "start", partial: output });
10159
- let sawDone = false;
10160
- try {
10161
- while (!sawDone) {
10162
- const { done, value } = await reader.read();
10163
- if (done) break;
10164
- if (bufferStart > 0) {
10165
- buffer = buffer.substring(bufferStart);
10166
- bufferStart = 0;
10167
- }
10168
- buffer += decoder.decode(value, { stream: true });
10169
- while (true) {
10170
- const lineEnd = buffer.indexOf("\n", bufferStart);
10171
- if (lineEnd === -1) break;
10172
- const line = buffer.substring(bufferStart, lineEnd).trim();
10173
- bufferStart = lineEnd + 1;
10174
- if (!line.startsWith("data:")) continue;
10175
- const dataStr = line.substring(5).trim();
10176
- if (dataStr === "[DONE]") {
10177
- sawDone = true;
10178
- break;
10222
+ const runAttempt = async () => {
10223
+ options?.signal?.throwIfAborted();
10224
+ output.stopReason = "stop";
10225
+ output.errorMessage = void 0;
10226
+ output.responseId = void 0;
10227
+ output.responseModel = void 0;
10228
+ output.usage = {
10229
+ input: 0,
10230
+ output: 0,
10231
+ cacheRead: 0,
10232
+ cacheWrite: 0,
10233
+ totalTokens: 0,
10234
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
10235
+ };
10236
+ const response = await fetch(chatURL, {
10237
+ method: "POST",
10238
+ headers: {
10239
+ "Content-Type": "application/json",
10240
+ Accept: "text/event-stream",
10241
+ "Cache-Control": "no-cache",
10242
+ "Accept-Encoding": "identity",
10243
+ "X-Model-Key": qoderModel,
10244
+ "X-Model-Source": modelSource,
10245
+ ...headers
10246
+ },
10247
+ body: encodedBytes,
10248
+ signal: options?.signal
10249
+ });
10250
+ if (!response.ok) {
10251
+ const errText = await response.text();
10252
+ throw new Error(`Qoder API request failed: ${response.status} ${response.statusText}. Response: ${errText}`);
10253
+ }
10254
+ const reader = response.body?.getReader();
10255
+ if (!reader) throw new Error("No response body");
10256
+ const decoder = new TextDecoder();
10257
+ let buffer = "";
10258
+ let bufferStart = 0;
10259
+ let contentBlockIndex = -1;
10260
+ let thinkingBlockIndex = -1;
10261
+ let rawReasoningTail = "";
10262
+ let toolCalls;
10263
+ const thinkingParser = thinkingEnabled ? new ThinkingTagParser(output, stream) : null;
10264
+ let sawModelOutput = false;
10265
+ let sawDone = false;
10266
+ try {
10267
+ while (!sawDone) {
10268
+ const { done, value } = await reader.read();
10269
+ if (done) break;
10270
+ if (bufferStart > 0) {
10271
+ buffer = buffer.substring(bufferStart);
10272
+ bufferStart = 0;
10179
10273
  }
10180
- try {
10181
- const envelope = JSON.parse(dataStr);
10182
- if (envelope.statusCodeValue && envelope.statusCodeValue !== 200) {
10183
- throw new Error(`Upstream status ${envelope.statusCodeValue}: ${envelope.body}`);
10184
- }
10185
- const innerStr = envelope.body;
10186
- if (innerStr === "[DONE]") {
10274
+ buffer += decoder.decode(value, { stream: true });
10275
+ while (true) {
10276
+ const lineEnd = buffer.indexOf("\n", bufferStart);
10277
+ if (lineEnd === -1) break;
10278
+ const line = buffer.substring(bufferStart, lineEnd).trim();
10279
+ bufferStart = lineEnd + 1;
10280
+ if (!line.startsWith("data:")) continue;
10281
+ const dataStr = line.substring(5).trim();
10282
+ if (dataStr === "[DONE]") {
10187
10283
  sawDone = true;
10188
10284
  break;
10189
10285
  }
10190
- if (!innerStr) continue;
10191
- const inner = JSON.parse(innerStr);
10192
- if (inner.id) output.responseId = inner.id;
10193
- if (inner.model) output.responseModel = inner.model;
10194
- if (inner.usage) {
10195
- applyQoderCredits(output.usage, inner.usage, model.provider === "qoder-cn" ? "qoder-cn" : "qoder");
10196
- const u = inner.usage;
10197
- const promptTokens = u.prompt_tokens ?? 0;
10198
- const cacheReadTokens = u.prompt_tokens_details?.cached_tokens ?? 0;
10199
- const cacheWriteTokens = u.prompt_tokens_details?.cache_write_tokens ?? 0;
10200
- output.usage.input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
10201
- output.usage.output = u.completion_tokens ?? 0;
10202
- output.usage.totalTokens = u.total_tokens ?? 0;
10203
- output.usage.cacheRead = cacheReadTokens;
10204
- output.usage.cacheWrite = cacheWriteTokens;
10205
- }
10206
- if (inner.choices && inner.choices.length > 0) {
10207
- const choice = inner.choices[0];
10208
- const delta = choice.delta;
10209
- if (delta) {
10210
- if (delta.reasoning_content) {
10211
- rawReasoningTail = (rawReasoningTail + delta.reasoning_content).slice(-512);
10212
- const reasoningChunk = stripDsmlResidue(stripThinkingTags(delta.reasoning_content));
10213
- if (reasoningChunk) {
10214
- if (thinkingBlockIndex === -1) {
10215
- thinkingBlockIndex = output.content.length;
10216
- output.content.push({ type: "thinking", thinking: "" });
10217
- stream.push({ type: "thinking_start", contentIndex: thinkingBlockIndex, partial: output });
10218
- }
10219
- const block = output.content[thinkingBlockIndex];
10220
- block.thinking += reasoningChunk;
10221
- stream.push({
10222
- type: "thinking_delta",
10223
- contentIndex: thinkingBlockIndex,
10224
- delta: reasoningChunk,
10225
- partial: output
10226
- });
10227
- }
10286
+ try {
10287
+ const envelope = JSON.parse(dataStr);
10288
+ if (envelope.statusCodeValue && envelope.statusCodeValue !== 200) {
10289
+ const busy = parseModelBusyRejection(envelope.body);
10290
+ if (busy) {
10291
+ throw new QoderModelBusyError(
10292
+ `Upstream status ${envelope.statusCodeValue}: ${envelope.body}`,
10293
+ busy.retryAfterMs,
10294
+ sawModelOutput
10295
+ );
10228
10296
  }
10229
- if (delta.content) {
10230
- if (thinkingBlockIndex !== -1) {
10231
- const block = output.content[thinkingBlockIndex];
10232
- stream.push({
10233
- type: "thinking_end",
10234
- contentIndex: thinkingBlockIndex,
10235
- content: block.thinking,
10236
- partial: output
10237
- });
10238
- thinkingBlockIndex = -1;
10297
+ throw new Error(`Upstream status ${envelope.statusCodeValue}: ${envelope.body}`);
10298
+ }
10299
+ const innerStr = envelope.body;
10300
+ if (innerStr === "[DONE]") {
10301
+ sawDone = true;
10302
+ break;
10303
+ }
10304
+ if (!innerStr) continue;
10305
+ const inner = JSON.parse(innerStr);
10306
+ if (inner.id) output.responseId = inner.id;
10307
+ if (inner.model) output.responseModel = inner.model;
10308
+ if (inner.usage) {
10309
+ applyQoderCredits(output.usage, inner.usage, model.provider === "qoder-cn" ? "qoder-cn" : "qoder");
10310
+ const u = inner.usage;
10311
+ const promptTokens = u.prompt_tokens ?? 0;
10312
+ const cacheReadTokens = u.prompt_tokens_details?.cached_tokens ?? 0;
10313
+ const cacheWriteTokens = u.prompt_tokens_details?.cache_write_tokens ?? 0;
10314
+ output.usage.input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
10315
+ output.usage.output = u.completion_tokens ?? 0;
10316
+ output.usage.totalTokens = u.total_tokens ?? 0;
10317
+ output.usage.cacheRead = cacheReadTokens;
10318
+ output.usage.cacheWrite = cacheWriteTokens;
10319
+ }
10320
+ if (inner.choices && inner.choices.length > 0) {
10321
+ const choice = inner.choices[0];
10322
+ const delta = choice.delta;
10323
+ if (delta) {
10324
+ if (delta.reasoning_content || delta.content || Array.isArray(delta.tool_calls) && delta.tool_calls.length > 0) {
10325
+ sawModelOutput = true;
10239
10326
  }
10240
- if (thinkingParser) {
10241
- thinkingParser.processChunk(delta.content);
10242
- if (toolCalls?.lastToolState) refreshToolIndexes(output, toolCalls);
10243
- } else {
10244
- if (contentBlockIndex === -1) {
10245
- contentBlockIndex = output.content.length;
10246
- output.content.push({ type: "text", text: "" });
10247
- stream.push({ type: "text_start", contentIndex: contentBlockIndex, partial: output });
10327
+ if (delta.reasoning_content) {
10328
+ rawReasoningTail = (rawReasoningTail + delta.reasoning_content).slice(-512);
10329
+ const reasoningChunk = stripDsmlResidue(stripThinkingTags(delta.reasoning_content));
10330
+ if (reasoningChunk) {
10331
+ if (thinkingBlockIndex === -1) {
10332
+ thinkingBlockIndex = output.content.length;
10333
+ output.content.push({ type: "thinking", thinking: "" });
10334
+ stream.push({ type: "thinking_start", contentIndex: thinkingBlockIndex, partial: output });
10335
+ }
10336
+ const block = output.content[thinkingBlockIndex];
10337
+ block.thinking += reasoningChunk;
10338
+ stream.push({
10339
+ type: "thinking_delta",
10340
+ contentIndex: thinkingBlockIndex,
10341
+ delta: reasoningChunk,
10342
+ partial: output
10343
+ });
10248
10344
  }
10249
- const block = output.content[contentBlockIndex];
10250
- block.text += delta.content;
10251
- stream.push({
10252
- type: "text_delta",
10253
- contentIndex: contentBlockIndex,
10254
- delta: delta.content,
10255
- partial: output
10256
- });
10257
10345
  }
10258
- }
10259
- if (delta.tool_calls && Array.isArray(delta.tool_calls)) {
10260
- for (const tc of delta.tool_calls) {
10261
- const id = tc.id || "";
10262
- const name2 = tc.function?.name || "";
10263
- const argDelta = tc.function?.arguments ?? "";
10264
- if (typeof id !== "string" || typeof name2 !== "string") {
10265
- throw new Error("Tool-call identity conflict: invalid metadata");
10346
+ if (delta.content) {
10347
+ if (thinkingBlockIndex !== -1) {
10348
+ const block = output.content[thinkingBlockIndex];
10349
+ stream.push({
10350
+ type: "thinking_end",
10351
+ contentIndex: thinkingBlockIndex,
10352
+ content: block.thinking,
10353
+ partial: output
10354
+ });
10355
+ thinkingBlockIndex = -1;
10266
10356
  }
10267
- if (typeof argDelta !== "string") throw new Error("Invalid tool-call argument fragment");
10268
- if (!id && !name2 && !argDelta) continue;
10269
- toolCalls ??= {
10270
- states: [],
10271
- byId: /* @__PURE__ */ new Map(),
10272
- byIndex: /* @__PURE__ */ new Map(),
10273
- unscopedCandidates: /* @__PURE__ */ new Set(),
10274
- statesByBlock: /* @__PURE__ */ new Map()
10275
- };
10276
- const index = typeof tc.index === "number" ? tc.index : void 0;
10277
- let candidates;
10278
- if (index !== void 0) {
10279
- candidates = toolCalls.byIndex.get(index);
10280
- if (!candidates) {
10281
- candidates = { states: /* @__PURE__ */ new Set(), complete: /* @__PURE__ */ new Set(), unique: void 0 };
10282
- toolCalls.byIndex.set(index, candidates);
10357
+ if (thinkingParser) {
10358
+ thinkingParser.processChunk(delta.content);
10359
+ if (toolCalls?.lastToolState) refreshToolIndexes(output, toolCalls);
10360
+ } else {
10361
+ if (contentBlockIndex === -1) {
10362
+ contentBlockIndex = output.content.length;
10363
+ output.content.push({ type: "text", text: "" });
10364
+ stream.push({ type: "text_start", contentIndex: contentBlockIndex, partial: output });
10283
10365
  }
10366
+ const block = output.content[contentBlockIndex];
10367
+ block.text += delta.content;
10368
+ stream.push({
10369
+ type: "text_delta",
10370
+ contentIndex: contentBlockIndex,
10371
+ delta: delta.content,
10372
+ partial: output
10373
+ });
10284
10374
  }
10285
- let state = id ? toolCalls.byId.get(id) : void 0;
10286
- let associated = !!state && !!candidates && candidates.states.has(state);
10287
- if (id && candidates && !associated && candidates.complete.size > 0) {
10288
- retireCompleteCandidates(toolCalls, candidates);
10289
- }
10290
- const available = candidates?.states ?? toolCalls.unscopedCandidates;
10291
- if (!state) {
10292
- const only = available.size === 1 ? candidates ? candidates.unique : available.values().next().value : void 0;
10293
- if (!id && available.size > 1) {
10294
- throw new Error(`Ambiguous tool-call continuation (candidates=${available.size})`);
10375
+ }
10376
+ if (delta.tool_calls && Array.isArray(delta.tool_calls)) {
10377
+ for (const tc of delta.tool_calls) {
10378
+ const id = tc.id || "";
10379
+ const name2 = tc.function?.name || "";
10380
+ const argDelta = tc.function?.arguments ?? "";
10381
+ if (typeof id !== "string" || typeof name2 !== "string") {
10382
+ throw new Error("Tool-call identity conflict: invalid metadata");
10295
10383
  }
10296
- if (only && (!id || !only.id)) {
10297
- state = only;
10298
- associated = candidates !== void 0;
10299
- } else {
10300
- state = {
10301
- argumentChunks: [],
10302
- argumentLength: 0,
10303
- depth: 0,
10304
- inString: false,
10305
- escaped: false,
10306
- complete: false,
10307
- id: "",
10308
- name: "",
10309
- contentIndex: -1,
10310
- candidates: /* @__PURE__ */ new Set(),
10311
- unindexed: index === void 0
10312
- };
10313
- toolCalls.states.push(state);
10384
+ if (typeof argDelta !== "string") throw new Error("Invalid tool-call argument fragment");
10385
+ if (!id && !name2 && !argDelta) continue;
10386
+ toolCalls ??= {
10387
+ states: [],
10388
+ byId: /* @__PURE__ */ new Map(),
10389
+ byIndex: /* @__PURE__ */ new Map(),
10390
+ unscopedCandidates: /* @__PURE__ */ new Set(),
10391
+ statesByBlock: /* @__PURE__ */ new Map()
10392
+ };
10393
+ const index = typeof tc.index === "number" ? tc.index : void 0;
10394
+ let candidates;
10395
+ if (index !== void 0) {
10396
+ candidates = toolCalls.byIndex.get(index);
10397
+ if (!candidates) {
10398
+ candidates = { states: /* @__PURE__ */ new Set(), complete: /* @__PURE__ */ new Set(), unique: void 0 };
10399
+ toolCalls.byIndex.set(index, candidates);
10400
+ }
10314
10401
  }
10315
- }
10316
- if (name2 && state.name && name2 !== state.name) {
10317
- throw new Error("Tool-call identity conflict: inconsistent name");
10318
- }
10319
- const newlyIdentified = !!id && !state.id;
10320
- const newlyNamed = !!name2 && !state.name;
10321
- if (newlyIdentified) {
10322
- state.id = id;
10323
- toolCalls.byId.set(id, state);
10324
- }
10325
- if (newlyNamed) state.name = name2;
10326
- if (!associated) {
10327
- toolCalls.unscopedCandidates.add(state);
10328
- if (candidates) {
10329
- state.unindexed = false;
10330
- state.candidates.add(candidates);
10331
- candidates.states.add(state);
10332
- candidates.unique = candidates.states.size === 1 ? state : void 0;
10333
- if (state.complete && state.id) candidates.complete.add(state);
10402
+ let state = id ? toolCalls.byId.get(id) : void 0;
10403
+ let associated = !!state && !!candidates && candidates.states.has(state);
10404
+ if (id && candidates && !associated && candidates.complete.size > 0) {
10405
+ retireCompleteCandidates(toolCalls, candidates);
10334
10406
  }
10335
- }
10336
- const wasComplete = state.complete;
10337
- if (argDelta) appendToolArguments(state, argDelta);
10338
- if (state.complete && state.id && (!wasComplete || newlyIdentified)) {
10339
- for (const scope of state.candidates) scope.complete.add(state);
10340
- }
10341
- if (!state.block && (state.id || state.name)) {
10342
- state.block = { type: "toolCall", id: state.id, name: state.name, arguments: {} };
10343
- state.contentIndex = output.content.length;
10344
- output.content.push(state.block);
10345
- toolCalls.statesByBlock.set(state.block, state);
10346
- toolCalls.lastToolState = state;
10347
- stream.push({ type: "toolcall_start", contentIndex: state.contentIndex, partial: output });
10348
- for (const fragment of state.argumentChunks) {
10349
- stream.push({
10350
- type: "toolcall_delta",
10351
- contentIndex: state.contentIndex,
10352
- delta: fragment,
10353
- partial: output
10354
- });
10407
+ const available = candidates?.states ?? toolCalls.unscopedCandidates;
10408
+ if (!state) {
10409
+ const only = available.size === 1 ? candidates ? candidates.unique : available.values().next().value : void 0;
10410
+ if (!id && available.size > 1) {
10411
+ throw new Error(`Ambiguous tool-call continuation (candidates=${available.size})`);
10412
+ }
10413
+ if (only && (!id || !only.id)) {
10414
+ state = only;
10415
+ associated = candidates !== void 0;
10416
+ } else {
10417
+ state = {
10418
+ argumentChunks: [],
10419
+ argumentLength: 0,
10420
+ depth: 0,
10421
+ inString: false,
10422
+ escaped: false,
10423
+ complete: false,
10424
+ id: "",
10425
+ name: "",
10426
+ contentIndex: -1,
10427
+ candidates: /* @__PURE__ */ new Set(),
10428
+ unindexed: index === void 0
10429
+ };
10430
+ toolCalls.states.push(state);
10431
+ }
10432
+ }
10433
+ if (name2 && state.name && name2 !== state.name) {
10434
+ throw new Error("Tool-call identity conflict: inconsistent name");
10435
+ }
10436
+ const newlyIdentified = !!id && !state.id;
10437
+ const newlyNamed = !!name2 && !state.name;
10438
+ if (newlyIdentified) {
10439
+ state.id = id;
10440
+ toolCalls.byId.set(id, state);
10355
10441
  }
10356
- } else if (state.block) {
10357
- if (newlyIdentified) state.block.id = state.id;
10358
- if (newlyNamed) state.block.name = state.name;
10359
- if (argDelta) {
10360
- stream.push({
10361
- type: "toolcall_delta",
10362
- contentIndex: state.contentIndex,
10363
- delta: argDelta,
10364
- partial: output
10365
- });
10442
+ if (newlyNamed) state.name = name2;
10443
+ if (!associated) {
10444
+ toolCalls.unscopedCandidates.add(state);
10445
+ if (candidates) {
10446
+ state.unindexed = false;
10447
+ state.candidates.add(candidates);
10448
+ candidates.states.add(state);
10449
+ candidates.unique = candidates.states.size === 1 ? state : void 0;
10450
+ if (state.complete && state.id) candidates.complete.add(state);
10451
+ }
10452
+ }
10453
+ const wasComplete = state.complete;
10454
+ if (argDelta) appendToolArguments(state, argDelta);
10455
+ if (state.complete && state.id && (!wasComplete || newlyIdentified)) {
10456
+ for (const scope of state.candidates) scope.complete.add(state);
10457
+ }
10458
+ if (!state.block && (state.id || state.name)) {
10459
+ state.block = { type: "toolCall", id: state.id, name: state.name, arguments: {} };
10460
+ state.contentIndex = output.content.length;
10461
+ output.content.push(state.block);
10462
+ toolCalls.statesByBlock.set(state.block, state);
10463
+ toolCalls.lastToolState = state;
10464
+ stream.push({ type: "toolcall_start", contentIndex: state.contentIndex, partial: output });
10465
+ for (const fragment of state.argumentChunks) {
10466
+ stream.push({
10467
+ type: "toolcall_delta",
10468
+ contentIndex: state.contentIndex,
10469
+ delta: fragment,
10470
+ partial: output
10471
+ });
10472
+ }
10473
+ } else if (state.block) {
10474
+ if (newlyIdentified) state.block.id = state.id;
10475
+ if (newlyNamed) state.block.name = state.name;
10476
+ if (argDelta) {
10477
+ stream.push({
10478
+ type: "toolcall_delta",
10479
+ contentIndex: state.contentIndex,
10480
+ delta: argDelta,
10481
+ partial: output
10482
+ });
10483
+ }
10366
10484
  }
10367
10485
  }
10368
10486
  }
10369
10487
  }
10488
+ if (choice.finish_reason) {
10489
+ output.stopReason = choice.finish_reason;
10490
+ }
10370
10491
  }
10371
- if (choice.finish_reason) {
10372
- output.stopReason = choice.finish_reason;
10373
- }
10374
- }
10375
- } catch (e) {
10376
- if (e instanceof SyntaxError) {
10377
- if (process.env.QODER_DEBUG) {
10378
- console.error("[pi-provider-qoder] skipping malformed SSE line:", dataStr.slice(0, 200));
10492
+ } catch (e) {
10493
+ if (e instanceof SyntaxError) {
10494
+ if (process.env.QODER_DEBUG) {
10495
+ console.error("[pi-provider-qoder] skipping malformed SSE line:", dataStr.slice(0, 200));
10496
+ }
10497
+ continue;
10379
10498
  }
10380
- continue;
10499
+ throw e;
10381
10500
  }
10382
- throw e;
10383
10501
  }
10384
10502
  }
10385
- }
10386
- } finally {
10387
- try {
10388
- await reader.cancel().catch(() => {
10389
- });
10390
10503
  } finally {
10391
- reader.releaseLock();
10392
- }
10393
- }
10394
- if (thinkingParser) {
10395
- thinkingParser.finalize();
10396
- if (toolCalls?.lastToolState) refreshToolIndexes(output, toolCalls);
10397
- }
10398
- if (thinkingBlockIndex !== -1) {
10399
- const block = output.content[thinkingBlockIndex];
10400
- stream.push({
10401
- type: "thinking_end",
10402
- contentIndex: thinkingBlockIndex,
10403
- content: block.thinking,
10404
- partial: output
10405
- });
10406
- }
10407
- if (toolCalls) {
10408
- for (const state of toolCalls.states) {
10409
- if (!state.id || !state.name) {
10410
- throw new Error(`Unresolved tool-call identity (characters=${state.argumentLength})`);
10504
+ try {
10505
+ await reader.cancel().catch(() => {
10506
+ });
10507
+ } finally {
10508
+ reader.releaseLock();
10411
10509
  }
10412
- parseToolArguments(state);
10413
10510
  }
10414
- for (const [block, state] of toolCalls.statesByBlock) {
10415
- block.arguments = parseToolArguments(state);
10511
+ if (thinkingParser) {
10512
+ thinkingParser.finalize();
10513
+ if (toolCalls?.lastToolState) refreshToolIndexes(output, toolCalls);
10514
+ }
10515
+ if (thinkingBlockIndex !== -1) {
10516
+ const block = output.content[thinkingBlockIndex];
10416
10517
  stream.push({
10417
- type: "toolcall_end",
10418
- contentIndex: state.contentIndex,
10419
- toolCall: block,
10518
+ type: "thinking_end",
10519
+ contentIndex: thinkingBlockIndex,
10520
+ content: block.thinking,
10420
10521
  partial: output
10421
10522
  });
10422
10523
  }
10423
- if (toolCalls.statesByBlock.size > 0 && output.stopReason !== "length") {
10424
- output.stopReason = "toolUse";
10524
+ if (toolCalls) {
10525
+ for (const state of toolCalls.states) {
10526
+ if (!state.id || !state.name) {
10527
+ throw new Error(`Unresolved tool-call identity (characters=${state.argumentLength})`);
10528
+ }
10529
+ parseToolArguments(state);
10530
+ }
10531
+ for (const [block, state] of toolCalls.statesByBlock) {
10532
+ block.arguments = parseToolArguments(state);
10533
+ stream.push({
10534
+ type: "toolcall_end",
10535
+ contentIndex: state.contentIndex,
10536
+ toolCall: block,
10537
+ partial: output
10538
+ });
10539
+ }
10540
+ if (toolCalls.statesByBlock.size > 0 && output.stopReason !== "length") {
10541
+ output.stopReason = "toolUse";
10542
+ }
10425
10543
  }
10426
- }
10427
- if (isDegenerateDsmlTurn(output, rawReasoningTail)) {
10428
- output.stopReason = "error";
10429
- output.errorMessage = "Qoder server error: degenerate model output (unparseable DSML tool-call markup, no tool call executed)";
10430
- stream.push({ type: "error", reason: "error", error: output });
10544
+ if (isDegenerateDsmlTurn(output, rawReasoningTail)) {
10545
+ output.stopReason = "error";
10546
+ output.errorMessage = "Qoder server error: degenerate model output (unparseable DSML tool-call markup, no tool call executed)";
10547
+ stream.push({ type: "error", reason: "error", error: output });
10548
+ stream.end();
10549
+ return;
10550
+ }
10551
+ stream.push({
10552
+ type: "done",
10553
+ reason: output.stopReason,
10554
+ message: output
10555
+ });
10431
10556
  stream.end();
10432
- return;
10557
+ };
10558
+ for (let attempt = 0; ; attempt++) {
10559
+ try {
10560
+ await runAttempt();
10561
+ return;
10562
+ } catch (e) {
10563
+ if (!(e instanceof QoderModelBusyError)) throw e;
10564
+ if (e.sawModelOutput || output.content.length > 0) {
10565
+ throw new Error("Qoder model rejected the request after partial output (10605 RESOURCE_LIMIT)");
10566
+ }
10567
+ const requestedWaitMs = e.retryAfterMs ?? 0;
10568
+ if (attempt >= modelBusyRetries) {
10569
+ throw new QoderModelBusyError(
10570
+ `Qoder server error: model is busy (10605 RESOURCE_LIMIT, retryAfterSeconds=${Math.round(requestedWaitMs / 1e3)}, attempts=${attempt + 1})`,
10571
+ requestedWaitMs
10572
+ );
10573
+ }
10574
+ if (requestedWaitMs > modelBusyMaxWaitMs) {
10575
+ throw new QoderModelBusyError(
10576
+ `Qoder server error: model is busy (10605 RESOURCE_LIMIT, requested delay ${requestedWaitMs}ms exceeds local cap ${modelBusyMaxWaitMs}ms)`,
10577
+ requestedWaitMs
10578
+ );
10579
+ }
10580
+ await sleepWithAbort(requestedWaitMs, options?.signal);
10581
+ options?.signal?.throwIfAborted();
10582
+ const nextId = crypto3.randomUUID();
10583
+ reqBody.request_id = nextId;
10584
+ reqBody.chat_record_id = nextId;
10585
+ encodedBytes = qoderEncodeBody(Buffer.from(JSON.stringify(reqBody)));
10586
+ headers = buildAuthHeaders(encodedBytes, chatURL, {
10587
+ userID,
10588
+ authToken: accessToken,
10589
+ name,
10590
+ email,
10591
+ machineID
10592
+ });
10593
+ }
10433
10594
  }
10434
- stream.push({
10435
- type: "done",
10436
- reason: output.stopReason,
10437
- message: output
10438
- });
10439
- stream.end();
10440
10595
  } catch (e) {
10441
10596
  output.stopReason = options?.signal?.aborted ? "aborted" : "error";
10442
10597
  output.errorMessage = e instanceof Error ? e.message : String(e);