gsd-pi 2.34.0 → 2.35.0-dev.39eee32

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 (505) hide show
  1. package/dist/cli.js +7 -2
  2. package/dist/resource-loader.d.ts +1 -1
  3. package/dist/resource-loader.js +13 -1
  4. package/dist/resources/extensions/async-jobs/await-tool.js +0 -2
  5. package/dist/resources/extensions/async-jobs/job-manager.js +0 -6
  6. package/dist/resources/extensions/bg-shell/output-formatter.js +1 -19
  7. package/dist/resources/extensions/bg-shell/process-manager.js +0 -4
  8. package/dist/resources/extensions/bg-shell/types.js +0 -2
  9. package/dist/resources/extensions/context7/index.js +5 -0
  10. package/dist/resources/extensions/get-secrets-from-user.js +2 -30
  11. package/dist/resources/extensions/google-search/index.js +5 -0
  12. package/dist/resources/extensions/gsd/auto-dispatch.js +43 -1
  13. package/dist/resources/extensions/gsd/auto-loop.js +10 -1
  14. package/dist/resources/extensions/gsd/auto-recovery.js +35 -0
  15. package/dist/resources/extensions/gsd/auto-start.js +35 -2
  16. package/dist/resources/extensions/gsd/auto.js +59 -4
  17. package/dist/resources/extensions/gsd/changelog.js +162 -0
  18. package/dist/resources/extensions/gsd/commands-bootstrap.js +1 -0
  19. package/dist/resources/extensions/gsd/commands-handlers.js +2 -2
  20. package/dist/resources/extensions/gsd/commands-inspect.js +10 -3
  21. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +5 -1
  22. package/dist/resources/extensions/gsd/commands.js +8 -1
  23. package/dist/resources/extensions/gsd/docs/preferences-reference.md +10 -0
  24. package/dist/resources/extensions/gsd/doctor-checks.js +113 -5
  25. package/dist/resources/extensions/gsd/doctor-environment.js +26 -17
  26. package/dist/resources/extensions/gsd/doctor-proactive.js +22 -0
  27. package/dist/resources/extensions/gsd/doctor.js +36 -0
  28. package/dist/resources/extensions/gsd/files.js +11 -2
  29. package/dist/resources/extensions/gsd/gitignore.js +54 -7
  30. package/dist/resources/extensions/gsd/guided-flow.js +5 -3
  31. package/dist/resources/extensions/gsd/health-widget-core.js +96 -0
  32. package/dist/resources/extensions/gsd/health-widget.js +97 -46
  33. package/dist/resources/extensions/gsd/index.js +10 -1
  34. package/dist/resources/extensions/gsd/migrate-external.js +55 -2
  35. package/dist/resources/extensions/gsd/milestone-ids.js +3 -2
  36. package/dist/resources/extensions/gsd/paths.js +74 -7
  37. package/dist/resources/extensions/gsd/post-unit-hooks.js +4 -1
  38. package/dist/resources/extensions/gsd/preferences-validation.js +54 -1
  39. package/dist/resources/extensions/gsd/preferences.js +2 -0
  40. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
  41. package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  42. package/dist/resources/extensions/gsd/roadmap-mutations.js +55 -0
  43. package/dist/resources/extensions/gsd/session-lock.js +26 -2
  44. package/dist/resources/extensions/gsd/state.js +2 -1
  45. package/dist/resources/extensions/gsd/templates/plan.md +8 -0
  46. package/dist/resources/extensions/gsd/worktree-resolver.js +12 -0
  47. package/dist/resources/extensions/mcp-client/index.js +2 -1
  48. package/dist/resources/extensions/remote-questions/remote-command.js +2 -22
  49. package/dist/resources/extensions/shared/mod.js +1 -1
  50. package/dist/resources/extensions/shared/sanitize.js +30 -0
  51. package/dist/resources/extensions/subagent/index.js +6 -14
  52. package/dist/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
  53. package/package.json +2 -1
  54. package/packages/native/dist/native.d.ts +0 -2
  55. package/packages/native/dist/native.js +0 -2
  56. package/packages/native/src/native.ts +0 -3
  57. package/packages/pi-agent-core/dist/agent-loop.d.ts +14 -0
  58. package/packages/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  59. package/packages/pi-agent-core/dist/agent-loop.js +24 -27
  60. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  61. package/packages/pi-agent-core/dist/agent.d.ts +1 -0
  62. package/packages/pi-agent-core/dist/agent.d.ts.map +1 -1
  63. package/packages/pi-agent-core/dist/agent.js +11 -22
  64. package/packages/pi-agent-core/dist/agent.js.map +1 -1
  65. package/packages/pi-agent-core/dist/proxy.d.ts +1 -25
  66. package/packages/pi-agent-core/dist/proxy.d.ts.map +1 -1
  67. package/packages/pi-agent-core/dist/proxy.js +3 -9
  68. package/packages/pi-agent-core/dist/proxy.js.map +1 -1
  69. package/packages/pi-agent-core/src/agent-loop.ts +30 -27
  70. package/packages/pi-agent-core/src/agent.ts +12 -23
  71. package/packages/pi-agent-core/src/proxy.ts +3 -9
  72. package/packages/pi-ai/dist/api-registry.d.ts +0 -2
  73. package/packages/pi-ai/dist/api-registry.d.ts.map +1 -1
  74. package/packages/pi-ai/dist/api-registry.js +0 -10
  75. package/packages/pi-ai/dist/api-registry.js.map +1 -1
  76. package/packages/pi-ai/dist/providers/anthropic.d.ts +0 -8
  77. package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  78. package/packages/pi-ai/dist/providers/anthropic.js +1 -1
  79. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  80. package/packages/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
  81. package/packages/pi-ai/dist/providers/azure-openai-responses.js +5 -41
  82. package/packages/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
  83. package/packages/pi-ai/dist/providers/github-copilot-headers.d.ts +0 -1
  84. package/packages/pi-ai/dist/providers/github-copilot-headers.d.ts.map +1 -1
  85. package/packages/pi-ai/dist/providers/github-copilot-headers.js +1 -1
  86. package/packages/pi-ai/dist/providers/github-copilot-headers.js.map +1 -1
  87. package/packages/pi-ai/dist/providers/google-gemini-cli.d.ts +1 -43
  88. package/packages/pi-ai/dist/providers/google-gemini-cli.d.ts.map +1 -1
  89. package/packages/pi-ai/dist/providers/google-gemini-cli.js +2 -2
  90. package/packages/pi-ai/dist/providers/google-gemini-cli.js.map +1 -1
  91. package/packages/pi-ai/dist/providers/google-shared.d.ts +0 -4
  92. package/packages/pi-ai/dist/providers/google-shared.d.ts.map +1 -1
  93. package/packages/pi-ai/dist/providers/google-shared.js +1 -1
  94. package/packages/pi-ai/dist/providers/google-shared.js.map +1 -1
  95. package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  96. package/packages/pi-ai/dist/providers/openai-completions.js +10 -73
  97. package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
  98. package/packages/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
  99. package/packages/pi-ai/dist/providers/openai-responses.js +9 -80
  100. package/packages/pi-ai/dist/providers/openai-responses.js.map +1 -1
  101. package/packages/pi-ai/dist/providers/openai-shared.d.ts +65 -0
  102. package/packages/pi-ai/dist/providers/openai-shared.d.ts.map +1 -0
  103. package/packages/pi-ai/dist/providers/openai-shared.js +146 -0
  104. package/packages/pi-ai/dist/providers/openai-shared.js.map +1 -0
  105. package/packages/pi-ai/dist/providers/register-builtins.d.ts +0 -1
  106. package/packages/pi-ai/dist/providers/register-builtins.d.ts.map +1 -1
  107. package/packages/pi-ai/dist/providers/register-builtins.js +1 -1
  108. package/packages/pi-ai/dist/providers/register-builtins.js.map +1 -1
  109. package/packages/pi-ai/dist/utils/event-stream.d.ts +0 -2
  110. package/packages/pi-ai/dist/utils/event-stream.d.ts.map +1 -1
  111. package/packages/pi-ai/dist/utils/event-stream.js +0 -4
  112. package/packages/pi-ai/dist/utils/event-stream.js.map +1 -1
  113. package/packages/pi-ai/dist/utils/oauth/google-antigravity.d.ts.map +1 -1
  114. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js +7 -135
  115. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js.map +1 -1
  116. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -1
  117. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js +7 -135
  118. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js.map +1 -1
  119. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts +46 -0
  120. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.d.ts.map +1 -0
  121. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js +160 -0
  122. package/packages/pi-ai/dist/utils/oauth/google-oauth-utils.js.map +1 -0
  123. package/packages/pi-ai/dist/utils/overflow.d.ts +0 -4
  124. package/packages/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  125. package/packages/pi-ai/dist/utils/overflow.js +0 -6
  126. package/packages/pi-ai/dist/utils/overflow.js.map +1 -1
  127. package/packages/pi-ai/dist/utils/validation.d.ts +0 -8
  128. package/packages/pi-ai/dist/utils/validation.d.ts.map +1 -1
  129. package/packages/pi-ai/dist/utils/validation.js +0 -14
  130. package/packages/pi-ai/dist/utils/validation.js.map +1 -1
  131. package/packages/pi-ai/src/api-registry.ts +0 -12
  132. package/packages/pi-ai/src/providers/anthropic.ts +1 -1
  133. package/packages/pi-ai/src/providers/azure-openai-responses.ts +11 -45
  134. package/packages/pi-ai/src/providers/github-copilot-headers.ts +1 -1
  135. package/packages/pi-ai/src/providers/google-gemini-cli.ts +2 -2
  136. package/packages/pi-ai/src/providers/google-shared.ts +1 -1
  137. package/packages/pi-ai/src/providers/openai-completions.ts +16 -86
  138. package/packages/pi-ai/src/providers/openai-responses.ts +16 -96
  139. package/packages/pi-ai/src/providers/openai-shared.ts +193 -0
  140. package/packages/pi-ai/src/providers/register-builtins.ts +1 -1
  141. package/packages/pi-ai/src/utils/event-stream.ts +0 -5
  142. package/packages/pi-ai/src/utils/oauth/google-antigravity.ts +14 -162
  143. package/packages/pi-ai/src/utils/oauth/google-gemini-cli.ts +13 -161
  144. package/packages/pi-ai/src/utils/oauth/google-oauth-utils.ts +201 -0
  145. package/packages/pi-ai/src/utils/overflow.ts +1 -8
  146. package/packages/pi-ai/src/utils/validation.ts +0 -15
  147. package/packages/pi-coding-agent/dist/config.d.ts +0 -9
  148. package/packages/pi-coding-agent/dist/config.d.ts.map +1 -1
  149. package/packages/pi-coding-agent/dist/config.js +4 -8
  150. package/packages/pi-coding-agent/dist/config.js.map +1 -1
  151. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +16 -63
  152. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  153. package/packages/pi-coding-agent/dist/core/agent-session.js +104 -641
  154. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  155. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +0 -1
  156. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  157. package/packages/pi-coding-agent/dist/core/auth-storage.js +4 -35
  158. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  159. package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  160. package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js +5 -43
  161. package/packages/pi-coding-agent/dist/core/compaction/branch-summarization.js.map +1 -1
  162. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
  163. package/packages/pi-coding-agent/dist/core/compaction/compaction.js +11 -69
  164. package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
  165. package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts +40 -0
  166. package/packages/pi-coding-agent/dist/core/compaction/utils.d.ts.map +1 -1
  167. package/packages/pi-coding-agent/dist/core/compaction/utils.js +78 -0
  168. package/packages/pi-coding-agent/dist/core/compaction/utils.js.map +1 -1
  169. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts +77 -0
  170. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.d.ts.map +1 -0
  171. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js +331 -0
  172. package/packages/pi-coding-agent/dist/core/compaction-orchestrator.js.map +1 -0
  173. package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.d.ts +0 -4
  174. package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  175. package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.js +1 -1
  176. package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.js.map +1 -1
  177. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +2 -2
  178. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  179. package/packages/pi-coding-agent/dist/core/extensions/index.js +1 -1
  180. package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  181. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +15 -5
  182. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
  183. package/packages/pi-coding-agent/dist/core/extensions/runner.js +129 -256
  184. package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
  185. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +49 -42
  186. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  187. package/packages/pi-coding-agent/dist/core/extensions/types.js +2 -21
  188. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  189. package/packages/pi-coding-agent/dist/core/keybindings.d.ts +0 -8
  190. package/packages/pi-coding-agent/dist/core/keybindings.d.ts.map +1 -1
  191. package/packages/pi-coding-agent/dist/core/keybindings.js +2 -2
  192. package/packages/pi-coding-agent/dist/core/keybindings.js.map +1 -1
  193. package/packages/pi-coding-agent/dist/core/lock-utils.d.ts +39 -0
  194. package/packages/pi-coding-agent/dist/core/lock-utils.d.ts.map +1 -0
  195. package/packages/pi-coding-agent/dist/core/lock-utils.js +89 -0
  196. package/packages/pi-coding-agent/dist/core/lock-utils.js.map +1 -0
  197. package/packages/pi-coding-agent/dist/core/lsp/client.d.ts +0 -17
  198. package/packages/pi-coding-agent/dist/core/lsp/client.d.ts.map +1 -1
  199. package/packages/pi-coding-agent/dist/core/lsp/client.js +3 -62
  200. package/packages/pi-coding-agent/dist/core/lsp/client.js.map +1 -1
  201. package/packages/pi-coding-agent/dist/core/lsp/config.d.ts +1 -1
  202. package/packages/pi-coding-agent/dist/core/lsp/config.d.ts.map +1 -1
  203. package/packages/pi-coding-agent/dist/core/lsp/config.js +2 -6
  204. package/packages/pi-coding-agent/dist/core/lsp/config.js.map +1 -1
  205. package/packages/pi-coding-agent/dist/core/lsp/edits.d.ts +0 -5
  206. package/packages/pi-coding-agent/dist/core/lsp/edits.d.ts.map +1 -1
  207. package/packages/pi-coding-agent/dist/core/lsp/edits.js +1 -1
  208. package/packages/pi-coding-agent/dist/core/lsp/edits.js.map +1 -1
  209. package/packages/pi-coding-agent/dist/core/lsp/index.d.ts.map +1 -1
  210. package/packages/pi-coding-agent/dist/core/lsp/index.js +52 -107
  211. package/packages/pi-coding-agent/dist/core/lsp/index.js.map +1 -1
  212. package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts +0 -1
  213. package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts.map +1 -1
  214. package/packages/pi-coding-agent/dist/core/lsp/lspmux.js +3 -22
  215. package/packages/pi-coding-agent/dist/core/lsp/lspmux.js.map +1 -1
  216. package/packages/pi-coding-agent/dist/core/lsp/types.d.ts +0 -1
  217. package/packages/pi-coding-agent/dist/core/lsp/types.d.ts.map +1 -1
  218. package/packages/pi-coding-agent/dist/core/lsp/types.js +0 -28
  219. package/packages/pi-coding-agent/dist/core/lsp/types.js.map +1 -1
  220. package/packages/pi-coding-agent/dist/core/lsp/utils.d.ts +1 -6
  221. package/packages/pi-coding-agent/dist/core/lsp/utils.d.ts.map +1 -1
  222. package/packages/pi-coding-agent/dist/core/lsp/utils.js +1 -28
  223. package/packages/pi-coding-agent/dist/core/lsp/utils.js.map +1 -1
  224. package/packages/pi-coding-agent/dist/core/messages.d.ts +0 -8
  225. package/packages/pi-coding-agent/dist/core/messages.d.ts.map +1 -1
  226. package/packages/pi-coding-agent/dist/core/messages.js +5 -5
  227. package/packages/pi-coding-agent/dist/core/messages.js.map +1 -1
  228. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +0 -3
  229. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  230. package/packages/pi-coding-agent/dist/core/model-registry.js +1 -3
  231. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  232. package/packages/pi-coding-agent/dist/core/model-resolver.d.ts +1 -26
  233. package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
  234. package/packages/pi-coding-agent/dist/core/model-resolver.js +3 -59
  235. package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
  236. package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
  237. package/packages/pi-coding-agent/dist/core/package-manager.js +2 -4
  238. package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
  239. package/packages/pi-coding-agent/dist/core/prompt-templates.d.ts +0 -17
  240. package/packages/pi-coding-agent/dist/core/prompt-templates.d.ts.map +1 -1
  241. package/packages/pi-coding-agent/dist/core/prompt-templates.js +2 -2
  242. package/packages/pi-coding-agent/dist/core/prompt-templates.js.map +1 -1
  243. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +2 -4
  244. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
  245. package/packages/pi-coding-agent/dist/core/resource-loader.js +46 -60
  246. package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  247. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +87 -0
  248. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -0
  249. package/packages/pi-coding-agent/dist/core/retry-handler.js +295 -0
  250. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -0
  251. package/packages/pi-coding-agent/dist/core/session-manager.d.ts +0 -5
  252. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  253. package/packages/pi-coding-agent/dist/core/session-manager.js +5 -32
  254. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  255. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +8 -12
  256. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  257. package/packages/pi-coding-agent/dist/core/settings-manager.js +78 -168
  258. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  259. package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
  260. package/packages/pi-coding-agent/dist/core/skills.js +1 -3
  261. package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
  262. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  263. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  264. package/packages/pi-coding-agent/dist/index.js +1 -1
  265. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  266. package/packages/pi-coding-agent/dist/migrations.d.ts +0 -16
  267. package/packages/pi-coding-agent/dist/migrations.d.ts.map +1 -1
  268. package/packages/pi-coding-agent/dist/migrations.js +2 -2
  269. package/packages/pi-coding-agent/dist/migrations.js.map +1 -1
  270. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.d.ts +0 -2
  271. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  272. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js +2 -2
  273. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  274. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts +1 -1
  275. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  276. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js +9 -26
  277. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js.map +1 -1
  278. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  279. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +1 -13
  280. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  281. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts +44 -0
  282. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.d.ts.map +1 -0
  283. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js +61 -0
  284. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-render-utils.js.map +1 -0
  285. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  286. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +6 -9
  287. package/packages/pi-coding-agent/dist/modes/interactive/components/tree-selector.js.map +1 -1
  288. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +1 -24
  289. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  290. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +50 -512
  291. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  292. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts +71 -0
  293. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -0
  294. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +514 -0
  295. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -0
  296. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts +65 -4
  297. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  298. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js +6 -23
  299. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js.map +1 -1
  300. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts +12 -0
  301. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.d.ts.map +1 -0
  302. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +175 -0
  303. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -0
  304. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts +6 -0
  305. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.d.ts.map +1 -0
  306. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js +15 -0
  307. package/packages/pi-coding-agent/dist/modes/interactive/utils/shorten-path.js.map +1 -0
  308. package/packages/pi-coding-agent/dist/modes/print-mode.d.ts.map +1 -1
  309. package/packages/pi-coding-agent/dist/modes/print-mode.js +2 -30
  310. package/packages/pi-coding-agent/dist/modes/print-mode.js.map +1 -1
  311. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  312. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js +2 -28
  313. package/packages/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
  314. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts +19 -0
  315. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.d.ts.map +1 -0
  316. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js +45 -0
  317. package/packages/pi-coding-agent/dist/modes/shared/command-context-actions.js.map +1 -0
  318. package/packages/pi-coding-agent/dist/utils/changelog.d.ts +0 -4
  319. package/packages/pi-coding-agent/dist/utils/changelog.d.ts.map +1 -1
  320. package/packages/pi-coding-agent/dist/utils/changelog.js +1 -1
  321. package/packages/pi-coding-agent/dist/utils/changelog.js.map +1 -1
  322. package/packages/pi-coding-agent/dist/utils/clipboard-image.d.ts +0 -1
  323. package/packages/pi-coding-agent/dist/utils/clipboard-image.d.ts.map +1 -1
  324. package/packages/pi-coding-agent/dist/utils/clipboard-image.js +1 -1
  325. package/packages/pi-coding-agent/dist/utils/clipboard-image.js.map +1 -1
  326. package/packages/pi-coding-agent/dist/utils/error.d.ts +5 -0
  327. package/packages/pi-coding-agent/dist/utils/error.d.ts.map +1 -0
  328. package/packages/pi-coding-agent/dist/utils/error.js +7 -0
  329. package/packages/pi-coding-agent/dist/utils/error.js.map +1 -0
  330. package/packages/pi-coding-agent/dist/utils/photon.d.ts +0 -19
  331. package/packages/pi-coding-agent/dist/utils/photon.d.ts.map +1 -1
  332. package/packages/pi-coding-agent/dist/utils/photon.js +1 -120
  333. package/packages/pi-coding-agent/dist/utils/photon.js.map +1 -1
  334. package/packages/pi-coding-agent/dist/utils/tools-manager.d.ts +0 -1
  335. package/packages/pi-coding-agent/dist/utils/tools-manager.d.ts.map +1 -1
  336. package/packages/pi-coding-agent/dist/utils/tools-manager.js +1 -1
  337. package/packages/pi-coding-agent/dist/utils/tools-manager.js.map +1 -1
  338. package/packages/pi-coding-agent/package.json +1 -1
  339. package/packages/pi-coding-agent/src/config.ts +5 -10
  340. package/packages/pi-coding-agent/src/core/agent-session.ts +117 -745
  341. package/packages/pi-coding-agent/src/core/auth-storage.ts +4 -38
  342. package/packages/pi-coding-agent/src/core/compaction/branch-summarization.ts +7 -53
  343. package/packages/pi-coding-agent/src/core/compaction/compaction.ts +14 -74
  344. package/packages/pi-coding-agent/src/core/compaction/utils.ts +100 -0
  345. package/packages/pi-coding-agent/src/core/compaction-orchestrator.ts +424 -0
  346. package/packages/pi-coding-agent/src/core/export-html/ansi-to-html.ts +1 -1
  347. package/packages/pi-coding-agent/src/core/extensions/index.ts +1 -21
  348. package/packages/pi-coding-agent/src/core/extensions/runner.ts +119 -256
  349. package/packages/pi-coding-agent/src/core/extensions/types.ts +50 -69
  350. package/packages/pi-coding-agent/src/core/keybindings.ts +2 -2
  351. package/packages/pi-coding-agent/src/core/lock-utils.ts +113 -0
  352. package/packages/pi-coding-agent/src/core/lsp/client.ts +3 -73
  353. package/packages/pi-coding-agent/src/core/lsp/config.ts +2 -10
  354. package/packages/pi-coding-agent/src/core/lsp/edits.ts +1 -1
  355. package/packages/pi-coding-agent/src/core/lsp/index.ts +83 -152
  356. package/packages/pi-coding-agent/src/core/lsp/lspmux.ts +3 -23
  357. package/packages/pi-coding-agent/src/core/lsp/types.ts +0 -29
  358. package/packages/pi-coding-agent/src/core/lsp/utils.ts +1 -33
  359. package/packages/pi-coding-agent/src/core/messages.ts +5 -5
  360. package/packages/pi-coding-agent/src/core/model-registry.ts +0 -2
  361. package/packages/pi-coding-agent/src/core/model-resolver.ts +3 -77
  362. package/packages/pi-coding-agent/src/core/package-manager.ts +1 -4
  363. package/packages/pi-coding-agent/src/core/prompt-templates.ts +2 -2
  364. package/packages/pi-coding-agent/src/core/resource-loader.ts +56 -69
  365. package/packages/pi-coding-agent/src/core/retry-handler.ts +359 -0
  366. package/packages/pi-coding-agent/src/core/session-manager.ts +5 -34
  367. package/packages/pi-coding-agent/src/core/settings-manager.ts +87 -166
  368. package/packages/pi-coding-agent/src/core/skills.ts +1 -4
  369. package/packages/pi-coding-agent/src/index.ts +1 -7
  370. package/packages/pi-coding-agent/src/migrations.ts +2 -2
  371. package/packages/pi-coding-agent/src/modes/interactive/components/session-selector-search.ts +2 -2
  372. package/packages/pi-coding-agent/src/modes/interactive/components/session-selector.ts +17 -29
  373. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +1 -13
  374. package/packages/pi-coding-agent/src/modes/interactive/components/tree-render-utils.ts +81 -0
  375. package/packages/pi-coding-agent/src/modes/interactive/components/tree-selector.ts +14 -19
  376. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +50 -561
  377. package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +653 -0
  378. package/packages/pi-coding-agent/src/modes/interactive/theme/theme.ts +7 -26
  379. package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +196 -0
  380. package/packages/pi-coding-agent/src/modes/interactive/utils/shorten-path.ts +14 -0
  381. package/packages/pi-coding-agent/src/modes/print-mode.ts +2 -30
  382. package/packages/pi-coding-agent/src/modes/rpc/rpc-mode.ts +2 -28
  383. package/packages/pi-coding-agent/src/modes/shared/command-context-actions.ts +53 -0
  384. package/packages/pi-coding-agent/src/utils/changelog.ts +1 -1
  385. package/packages/pi-coding-agent/src/utils/clipboard-image.ts +1 -1
  386. package/packages/pi-coding-agent/src/utils/error.ts +6 -0
  387. package/packages/pi-coding-agent/src/utils/photon.ts +0 -137
  388. package/packages/pi-coding-agent/src/utils/tools-manager.ts +1 -1
  389. package/packages/pi-tui/dist/components/editor.d.ts +0 -10
  390. package/packages/pi-tui/dist/components/editor.d.ts.map +1 -1
  391. package/packages/pi-tui/dist/components/editor.js +1 -1
  392. package/packages/pi-tui/dist/components/editor.js.map +1 -1
  393. package/packages/pi-tui/dist/components/markdown.d.ts +5 -0
  394. package/packages/pi-tui/dist/components/markdown.d.ts.map +1 -1
  395. package/packages/pi-tui/dist/components/markdown.js +25 -31
  396. package/packages/pi-tui/dist/components/markdown.js.map +1 -1
  397. package/packages/pi-tui/dist/keys.d.ts +0 -4
  398. package/packages/pi-tui/dist/keys.d.ts.map +1 -1
  399. package/packages/pi-tui/dist/keys.js +94 -162
  400. package/packages/pi-tui/dist/keys.js.map +1 -1
  401. package/packages/pi-tui/dist/overlay-layout.d.ts +55 -0
  402. package/packages/pi-tui/dist/overlay-layout.d.ts.map +1 -0
  403. package/packages/pi-tui/dist/overlay-layout.js +288 -0
  404. package/packages/pi-tui/dist/overlay-layout.js.map +1 -0
  405. package/packages/pi-tui/dist/tui.d.ts +0 -22
  406. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  407. package/packages/pi-tui/dist/tui.js +6 -272
  408. package/packages/pi-tui/dist/tui.js.map +1 -1
  409. package/packages/pi-tui/dist/utils.d.ts +0 -7
  410. package/packages/pi-tui/dist/utils.d.ts.map +1 -1
  411. package/packages/pi-tui/dist/utils.js +0 -44
  412. package/packages/pi-tui/dist/utils.js.map +1 -1
  413. package/packages/pi-tui/src/components/editor.ts +1 -1
  414. package/packages/pi-tui/src/components/markdown.ts +25 -29
  415. package/packages/pi-tui/src/keys.ts +94 -173
  416. package/packages/pi-tui/src/overlay-layout.ts +372 -0
  417. package/packages/pi-tui/src/tui.ts +11 -312
  418. package/packages/pi-tui/src/utils.ts +0 -43
  419. package/pkg/dist/core/export-html/ansi-to-html.d.ts +0 -4
  420. package/pkg/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  421. package/pkg/dist/core/export-html/ansi-to-html.js +1 -1
  422. package/pkg/dist/core/export-html/ansi-to-html.js.map +1 -1
  423. package/pkg/dist/modes/interactive/theme/theme.d.ts +65 -4
  424. package/pkg/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  425. package/pkg/dist/modes/interactive/theme/theme.js +6 -23
  426. package/pkg/dist/modes/interactive/theme/theme.js.map +1 -1
  427. package/pkg/dist/modes/interactive/theme/themes.d.ts +12 -0
  428. package/pkg/dist/modes/interactive/theme/themes.d.ts.map +1 -0
  429. package/pkg/dist/modes/interactive/theme/themes.js +175 -0
  430. package/pkg/dist/modes/interactive/theme/themes.js.map +1 -0
  431. package/pkg/package.json +1 -1
  432. package/src/resources/extensions/async-jobs/await-tool.ts +0 -2
  433. package/src/resources/extensions/async-jobs/job-manager.ts +0 -7
  434. package/src/resources/extensions/bg-shell/output-formatter.ts +0 -17
  435. package/src/resources/extensions/bg-shell/process-manager.ts +0 -4
  436. package/src/resources/extensions/bg-shell/types.ts +0 -12
  437. package/src/resources/extensions/context7/index.ts +7 -0
  438. package/src/resources/extensions/get-secrets-from-user.ts +2 -35
  439. package/src/resources/extensions/google-search/index.ts +7 -0
  440. package/src/resources/extensions/gsd/auto-dispatch.ts +49 -1
  441. package/src/resources/extensions/gsd/auto-loop.ts +11 -1
  442. package/src/resources/extensions/gsd/auto-recovery.ts +39 -0
  443. package/src/resources/extensions/gsd/auto-start.ts +42 -2
  444. package/src/resources/extensions/gsd/auto.ts +61 -3
  445. package/src/resources/extensions/gsd/changelog.ts +213 -0
  446. package/src/resources/extensions/gsd/commands-bootstrap.ts +1 -0
  447. package/src/resources/extensions/gsd/commands-handlers.ts +2 -2
  448. package/src/resources/extensions/gsd/commands-inspect.ts +10 -3
  449. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +5 -1
  450. package/src/resources/extensions/gsd/commands.ts +9 -1
  451. package/src/resources/extensions/gsd/docs/preferences-reference.md +10 -0
  452. package/src/resources/extensions/gsd/doctor-checks.ts +107 -5
  453. package/src/resources/extensions/gsd/doctor-environment.ts +26 -16
  454. package/src/resources/extensions/gsd/doctor-proactive.ts +24 -0
  455. package/src/resources/extensions/gsd/doctor-types.ts +9 -1
  456. package/src/resources/extensions/gsd/doctor.ts +35 -0
  457. package/src/resources/extensions/gsd/files.ts +12 -2
  458. package/src/resources/extensions/gsd/gitignore.ts +54 -7
  459. package/src/resources/extensions/gsd/guided-flow.ts +5 -3
  460. package/src/resources/extensions/gsd/health-widget-core.ts +129 -0
  461. package/src/resources/extensions/gsd/health-widget.ts +103 -59
  462. package/src/resources/extensions/gsd/index.ts +10 -1
  463. package/src/resources/extensions/gsd/migrate-external.ts +47 -2
  464. package/src/resources/extensions/gsd/milestone-ids.ts +3 -2
  465. package/src/resources/extensions/gsd/paths.ts +73 -7
  466. package/src/resources/extensions/gsd/post-unit-hooks.ts +5 -1
  467. package/src/resources/extensions/gsd/preferences-validation.ts +54 -1
  468. package/src/resources/extensions/gsd/preferences.ts +2 -0
  469. package/src/resources/extensions/gsd/prompts/complete-milestone.md +2 -0
  470. package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  471. package/src/resources/extensions/gsd/roadmap-mutations.ts +66 -0
  472. package/src/resources/extensions/gsd/session-lock.ts +29 -2
  473. package/src/resources/extensions/gsd/state.ts +2 -1
  474. package/src/resources/extensions/gsd/templates/plan.md +8 -0
  475. package/src/resources/extensions/gsd/tests/commands-inspect-open-db.test.ts +46 -0
  476. package/src/resources/extensions/gsd/tests/doctor-git.test.ts +98 -2
  477. package/src/resources/extensions/gsd/tests/doctor-runtime.test.ts +59 -3
  478. package/src/resources/extensions/gsd/tests/files-loadfile-eisdir.test.ts +20 -0
  479. package/src/resources/extensions/gsd/tests/gitignore-tracked-gsd.test.ts +214 -0
  480. package/src/resources/extensions/gsd/tests/health-widget.test.ts +158 -0
  481. package/src/resources/extensions/gsd/tests/paths.test.ts +113 -0
  482. package/src/resources/extensions/gsd/tests/preferences.test.ts +40 -2
  483. package/src/resources/extensions/gsd/tests/queue-reorder-e2e.test.ts +26 -0
  484. package/src/resources/extensions/gsd/tests/test-utils.ts +165 -0
  485. package/src/resources/extensions/gsd/tests/validate-directory.test.ts +15 -0
  486. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +7 -0
  487. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +32 -0
  488. package/src/resources/extensions/gsd/worktree-resolver.ts +11 -0
  489. package/src/resources/extensions/mcp-client/index.ts +2 -1
  490. package/src/resources/extensions/remote-questions/remote-command.ts +2 -23
  491. package/src/resources/extensions/shared/mod.ts +1 -1
  492. package/src/resources/extensions/shared/sanitize.ts +36 -0
  493. package/src/resources/extensions/subagent/index.ts +6 -12
  494. package/src/resources/skills/create-gsd-extension/references/events-reference.md +4 -4
  495. package/dist/resources/extensions/shared/wizard-ui.js +0 -478
  496. package/packages/pi-coding-agent/dist/modes/interactive/theme/dark.json +0 -85
  497. package/packages/pi-coding-agent/dist/modes/interactive/theme/light.json +0 -84
  498. package/packages/pi-coding-agent/dist/modes/interactive/theme/theme-schema.json +0 -335
  499. package/packages/pi-coding-agent/src/modes/interactive/theme/dark.json +0 -85
  500. package/packages/pi-coding-agent/src/modes/interactive/theme/light.json +0 -84
  501. package/packages/pi-coding-agent/src/modes/interactive/theme/theme-schema.json +0 -335
  502. package/pkg/dist/modes/interactive/theme/dark.json +0 -85
  503. package/pkg/dist/modes/interactive/theme/light.json +0 -84
  504. package/pkg/dist/modes/interactive/theme/theme-schema.json +0 -335
  505. package/src/resources/extensions/shared/wizard-ui.ts +0 -551
@@ -0,0 +1,193 @@
1
+ /**
2
+ * Shared utilities for OpenAI Completions and Responses providers.
3
+ *
4
+ * This module consolidates code that is identical (or near-identical) across
5
+ * openai-completions.ts and openai-responses.ts to reduce duplication while
6
+ * preserving the subtle behavioural differences of each provider.
7
+ */
8
+
9
+ import type OpenAI from "openai";
10
+ import type {
11
+ Api,
12
+ AssistantMessage,
13
+ Context,
14
+ Model,
15
+ StopReason,
16
+ } from "../types.js";
17
+ import type { AssistantMessageEventStream } from "../utils/event-stream.js";
18
+ import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
19
+
20
+ // =============================================================================
21
+ // Lazy SDK loading
22
+ // =============================================================================
23
+
24
+ let _openAIClass: typeof OpenAI | undefined;
25
+
26
+ /**
27
+ * Lazy-load the OpenAI SDK default export.
28
+ * Shared between Completions and Responses providers so the module is only
29
+ * imported once regardless of which provider is used first.
30
+ */
31
+ export async function getOpenAIClass(): Promise<typeof OpenAI> {
32
+ if (!_openAIClass) {
33
+ const mod = await import("openai");
34
+ _openAIClass = mod.default;
35
+ }
36
+ return _openAIClass;
37
+ }
38
+
39
+ // =============================================================================
40
+ // Client creation
41
+ // =============================================================================
42
+
43
+ export interface CreateClientOptions {
44
+ /** Extra headers from the options bag (merged last, can override defaults). */
45
+ optionsHeaders?: Record<string, string>;
46
+ /** Provider-specific client constructor options (e.g. timeout, maxRetries for Z.ai). */
47
+ extraClientOptions?: Record<string, unknown>;
48
+ }
49
+
50
+ /**
51
+ * Create an OpenAI SDK client instance.
52
+ *
53
+ * Handles:
54
+ * - API key resolution (explicit > env)
55
+ * - GitHub Copilot dynamic headers
56
+ * - Options header merging
57
+ * - Lazy SDK loading
58
+ */
59
+ export async function createOpenAIClient<TApi extends Api>(
60
+ model: Model<TApi>,
61
+ context: Context,
62
+ apiKey: string | undefined,
63
+ options?: CreateClientOptions,
64
+ ): Promise<OpenAI> {
65
+ if (!apiKey) {
66
+ if (!process.env.OPENAI_API_KEY) {
67
+ throw new Error(
68
+ "OpenAI API key is required. Set OPENAI_API_KEY environment variable or pass it as an argument.",
69
+ );
70
+ }
71
+ apiKey = process.env.OPENAI_API_KEY;
72
+ }
73
+
74
+ const headers = { ...model.headers };
75
+ if (model.provider === "github-copilot") {
76
+ const hasImages = hasCopilotVisionInput(context.messages);
77
+ const copilotHeaders = buildCopilotDynamicHeaders({
78
+ messages: context.messages,
79
+ hasImages,
80
+ });
81
+ Object.assign(headers, copilotHeaders);
82
+ }
83
+
84
+ // Merge options headers last so they can override defaults
85
+ if (options?.optionsHeaders) {
86
+ Object.assign(headers, options.optionsHeaders);
87
+ }
88
+
89
+ const OpenAIClass = await getOpenAIClass();
90
+ return new OpenAIClass({
91
+ apiKey,
92
+ baseURL: model.baseUrl,
93
+ dangerouslyAllowBrowser: true,
94
+ defaultHeaders: headers,
95
+ ...options?.extraClientOptions,
96
+ });
97
+ }
98
+
99
+ // =============================================================================
100
+ // Initial output construction
101
+ // =============================================================================
102
+
103
+ /**
104
+ * Build the initial AssistantMessage output object used by all OpenAI stream
105
+ * handlers. Every field is initialised to its zero/default value.
106
+ */
107
+ export function buildInitialOutput<TApi extends Api>(model: Model<TApi>): AssistantMessage {
108
+ return {
109
+ role: "assistant",
110
+ content: [],
111
+ api: model.api as Api,
112
+ provider: model.provider,
113
+ model: model.id,
114
+ usage: {
115
+ input: 0,
116
+ output: 0,
117
+ cacheRead: 0,
118
+ cacheWrite: 0,
119
+ totalTokens: 0,
120
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
121
+ },
122
+ stopReason: "stop",
123
+ timestamp: Date.now(),
124
+ };
125
+ }
126
+
127
+ // =============================================================================
128
+ // Stream lifecycle helpers
129
+ // =============================================================================
130
+
131
+ /**
132
+ * Shared post-stream checks. Call after the provider-specific stream loop
133
+ * finishes successfully (before pushing the "done" event).
134
+ *
135
+ * Throws if the request was aborted or the output indicates an error.
136
+ */
137
+ export function assertStreamSuccess(output: AssistantMessage, signal?: AbortSignal): void {
138
+ if (signal?.aborted) {
139
+ throw new Error("Request was aborted");
140
+ }
141
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
142
+ throw new Error("An unknown error occurred");
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Emit the "done" event and close the stream.
148
+ */
149
+ export function finalizeStream(
150
+ stream: AssistantMessageEventStream,
151
+ output: AssistantMessage,
152
+ ): void {
153
+ stream.push({ type: "done", reason: output.stopReason as Extract<StopReason, "stop" | "length" | "toolUse">, message: output });
154
+ stream.end();
155
+ }
156
+
157
+ /**
158
+ * Handle an error during streaming.
159
+ *
160
+ * Cleans up any leftover `index` properties on content blocks, sets the
161
+ * appropriate stop reason and error message, then emits the "error" event.
162
+ */
163
+ export function handleStreamError(
164
+ stream: AssistantMessageEventStream,
165
+ output: AssistantMessage,
166
+ error: unknown,
167
+ signal?: AbortSignal,
168
+ /** Extra error metadata to append (e.g. OpenRouter raw metadata). */
169
+ extraMessage?: string,
170
+ ): void {
171
+ for (const block of output.content) delete (block as { index?: number }).index;
172
+ output.stopReason = signal?.aborted ? "aborted" : "error";
173
+ output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
174
+ if (extraMessage) output.errorMessage += `\n${extraMessage}`;
175
+ stream.push({ type: "error", reason: output.stopReason, error: output });
176
+ stream.end();
177
+ }
178
+
179
+ // =============================================================================
180
+ // Reasoning helpers
181
+ // =============================================================================
182
+
183
+ /**
184
+ * Clamp reasoning effort for models that don't support all levels.
185
+ * gpt-5.x models don't support "minimal" -- map to "low".
186
+ *
187
+ * Used by both openai-responses.ts and azure-openai-responses.ts.
188
+ */
189
+ export function clampReasoningForModel(modelName: string, effort: string): string {
190
+ const name = modelName.includes("/") ? modelName.split("/").pop()! : modelName;
191
+ if (name.startsWith("gpt-5") && effort === "minimal") return "low";
192
+ return effort;
193
+ }
@@ -116,7 +116,7 @@ function streamSimpleBedrockLazy(
116
116
  return outer;
117
117
  }
118
118
 
119
- export function registerBuiltInApiProviders(): void {
119
+ function registerBuiltInApiProviders(): void {
120
120
  registerApiProvider({
121
121
  api: "anthropic-messages",
122
122
  stream: streamAnthropic,
@@ -80,8 +80,3 @@ export class AssistantMessageEventStream extends EventStream<AssistantMessageEve
80
80
  );
81
81
  }
82
82
  }
83
-
84
- /** Factory function for AssistantMessageEventStream (for use in extensions) */
85
- export function createAssistantMessageEventStream(): AssistantMessageEventStream {
86
- return new AssistantMessageEventStream();
87
- }
@@ -6,7 +6,13 @@
6
6
  * It is only intended for CLI use, not browser environments.
7
7
  */
8
8
 
9
- import type { Server } from "node:http";
9
+ import {
10
+ type CallbackServerInfo,
11
+ getGoogleUserEmail,
12
+ parseRedirectUrl,
13
+ refreshGoogleOAuthToken,
14
+ startCallbackServer,
15
+ } from "./google-oauth-utils.js";
10
16
  import { generatePKCE } from "./pkce.js";
11
17
  import type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderInterface } from "./types.js";
12
18
 
@@ -14,14 +20,6 @@ type AntigravityCredentials = OAuthCredentials & {
14
20
  projectId: string;
15
21
  };
16
22
 
17
- let _createServer: typeof import("node:http").createServer | null = null;
18
- let _httpImportPromise: Promise<void> | null = null;
19
- if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
20
- _httpImportPromise = import("node:http").then((m) => {
21
- _createServer = m.createServer;
22
- });
23
- }
24
-
25
23
  // Antigravity OAuth credentials (different from Gemini CLI)
26
24
  const decode = (s: string) => atob(s);
27
25
  const CLIENT_ID = decode(
@@ -42,109 +40,13 @@ const SCOPES = [
42
40
  const AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
43
41
  const TOKEN_URL = "https://oauth2.googleapis.com/token";
44
42
 
43
+ // Callback server configuration
44
+ const CALLBACK_PORT = 51121;
45
+ const CALLBACK_PATH = "/oauth-callback";
46
+
45
47
  // Fallback project ID when discovery fails
46
48
  const DEFAULT_PROJECT_ID = "rising-fact-p41fc";
47
49
 
48
- type CallbackServerInfo = {
49
- server: Server;
50
- cancelWait: () => void;
51
- waitForCode: () => Promise<{ code: string; state: string } | null>;
52
- };
53
-
54
- /**
55
- * Start a local HTTP server to receive the OAuth callback
56
- */
57
- async function getNodeCreateServer(): Promise<typeof import("node:http").createServer> {
58
- if (_createServer) return _createServer;
59
- if (_httpImportPromise) {
60
- await _httpImportPromise;
61
- }
62
- if (_createServer) return _createServer;
63
- throw new Error("Antigravity OAuth is only available in Node.js environments");
64
- }
65
-
66
- async function startCallbackServer(): Promise<CallbackServerInfo> {
67
- const createServer = await getNodeCreateServer();
68
-
69
- return new Promise((resolve, reject) => {
70
- let result: { code: string; state: string } | null = null;
71
- let cancelled = false;
72
-
73
- const server = createServer((req, res) => {
74
- const url = new URL(req.url || "", `http://localhost:51121`);
75
-
76
- if (url.pathname === "/oauth-callback") {
77
- const code = url.searchParams.get("code");
78
- const state = url.searchParams.get("state");
79
- const error = url.searchParams.get("error");
80
-
81
- if (error) {
82
- res.writeHead(400, { "Content-Type": "text/html" });
83
- res.end(
84
- `<html><body><h1>Authentication Failed</h1><p>Error: ${error}</p><p>You can close this window.</p></body></html>`,
85
- );
86
- return;
87
- }
88
-
89
- if (code && state) {
90
- res.writeHead(200, { "Content-Type": "text/html" });
91
- res.end(
92
- `<html><body><h1>Authentication Successful</h1><p>You can close this window and return to the terminal.</p></body></html>`,
93
- );
94
- result = { code, state };
95
- } else {
96
- res.writeHead(400, { "Content-Type": "text/html" });
97
- res.end(
98
- `<html><body><h1>Authentication Failed</h1><p>Missing code or state parameter.</p></body></html>`,
99
- );
100
- }
101
- } else {
102
- res.writeHead(404);
103
- res.end();
104
- }
105
- });
106
-
107
- server.on("error", (err) => {
108
- reject(err);
109
- });
110
-
111
- server.listen(51121, "127.0.0.1", () => {
112
- resolve({
113
- server,
114
- cancelWait: () => {
115
- cancelled = true;
116
- },
117
- waitForCode: async () => {
118
- const sleep = () => new Promise((r) => setTimeout(r, 100));
119
- while (!result && !cancelled) {
120
- await sleep();
121
- }
122
- return result;
123
- },
124
- });
125
- });
126
- });
127
- }
128
-
129
- /**
130
- * Parse redirect URL to extract code and state
131
- */
132
- function parseRedirectUrl(input: string): { code?: string; state?: string } {
133
- const value = input.trim();
134
- if (!value) return {};
135
-
136
- try {
137
- const url = new URL(value);
138
- return {
139
- code: url.searchParams.get("code") ?? undefined,
140
- state: url.searchParams.get("state") ?? undefined,
141
- };
142
- } catch {
143
- // Not a URL, return empty
144
- return {};
145
- }
146
- }
147
-
148
50
  interface LoadCodeAssistPayload {
149
51
  cloudaicompanionProject?: string | { id?: string };
150
52
  currentTier?: { id?: string };
@@ -212,61 +114,11 @@ async function discoverProject(accessToken: string, onProgress?: (message: strin
212
114
  return DEFAULT_PROJECT_ID;
213
115
  }
214
116
 
215
- /**
216
- * Get user email from the access token
217
- */
218
- async function getUserEmail(accessToken: string): Promise<string | undefined> {
219
- try {
220
- const response = await fetch("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
221
- headers: {
222
- Authorization: `Bearer ${accessToken}`,
223
- },
224
- signal: AbortSignal.timeout(30_000),
225
- });
226
-
227
- if (response.ok) {
228
- const data = (await response.json()) as { email?: string };
229
- return data.email;
230
- }
231
- } catch {
232
- // Ignore errors, email is optional
233
- }
234
- return undefined;
235
- }
236
-
237
117
  /**
238
118
  * Refresh Antigravity token
239
119
  */
240
120
  export async function refreshAntigravityToken(refreshToken: string, projectId: string): Promise<OAuthCredentials> {
241
- const response = await fetch(TOKEN_URL, {
242
- method: "POST",
243
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
244
- body: new URLSearchParams({
245
- client_id: CLIENT_ID,
246
- client_secret: CLIENT_SECRET,
247
- refresh_token: refreshToken,
248
- grant_type: "refresh_token",
249
- }),
250
- signal: AbortSignal.timeout(30_000),
251
- });
252
-
253
- if (!response.ok) {
254
- const error = await response.text();
255
- throw new Error(`Antigravity token refresh failed: ${error}`);
256
- }
257
-
258
- const data = (await response.json()) as {
259
- access_token: string;
260
- expires_in: number;
261
- refresh_token?: string;
262
- };
263
-
264
- return {
265
- refresh: data.refresh_token || refreshToken,
266
- access: data.access_token,
267
- expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
268
- projectId,
269
- };
121
+ return refreshGoogleOAuthToken(refreshToken, CLIENT_ID, CLIENT_SECRET, "Antigravity", { projectId });
270
122
  }
271
123
 
272
124
  /**
@@ -286,7 +138,7 @@ export async function loginAntigravity(
286
138
 
287
139
  // Start local server for callback
288
140
  onProgress?.("Starting local server for OAuth callback...");
289
- const server = await startCallbackServer();
141
+ const server: CallbackServerInfo = await startCallbackServer(CALLBACK_PORT, CALLBACK_PATH, "Antigravity");
290
142
 
291
143
  let code: string | undefined;
292
144
 
@@ -415,7 +267,7 @@ export async function loginAntigravity(
415
267
 
416
268
  // Get user email
417
269
  onProgress?.("Getting user info...");
418
- const email = await getUserEmail(tokenData.access_token);
270
+ const email = await getGoogleUserEmail(tokenData.access_token);
419
271
 
420
272
  // Discover project
421
273
  const projectId = await discoverProject(tokenData.access_token, onProgress);
@@ -6,7 +6,13 @@
6
6
  * It is only intended for CLI use, not browser environments.
7
7
  */
8
8
 
9
- import type { Server } from "node:http";
9
+ import {
10
+ type CallbackServerInfo,
11
+ getGoogleUserEmail,
12
+ parseRedirectUrl,
13
+ refreshGoogleOAuthToken,
14
+ startCallbackServer,
15
+ } from "./google-oauth-utils.js";
10
16
  import { generatePKCE } from "./pkce.js";
11
17
  import type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderInterface } from "./types.js";
12
18
 
@@ -14,14 +20,6 @@ type GeminiCredentials = OAuthCredentials & {
14
20
  projectId: string;
15
21
  };
16
22
 
17
- let _createServer: typeof import("node:http").createServer | null = null;
18
- let _httpImportPromise: Promise<void> | null = null;
19
- if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
20
- _httpImportPromise = import("node:http").then((m) => {
21
- _createServer = m.createServer;
22
- });
23
- }
24
-
25
23
  const decode = (s: string) => atob(s);
26
24
  const CLIENT_ID = decode(
27
25
  "NjgxMjU1ODA5Mzk1LW9vOGZ0Mm9wcmRybnA5ZTNhcWY2YXYzaG1kaWIxMzVqLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29t",
@@ -37,105 +35,9 @@ const AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
37
35
  const TOKEN_URL = "https://oauth2.googleapis.com/token";
38
36
  const CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
39
37
 
40
- type CallbackServerInfo = {
41
- server: Server;
42
- cancelWait: () => void;
43
- waitForCode: () => Promise<{ code: string; state: string } | null>;
44
- };
45
-
46
- /**
47
- * Start a local HTTP server to receive the OAuth callback
48
- */
49
- async function getNodeCreateServer(): Promise<typeof import("node:http").createServer> {
50
- if (_createServer) return _createServer;
51
- if (_httpImportPromise) {
52
- await _httpImportPromise;
53
- }
54
- if (_createServer) return _createServer;
55
- throw new Error("Gemini CLI OAuth is only available in Node.js environments");
56
- }
57
-
58
- async function startCallbackServer(): Promise<CallbackServerInfo> {
59
- const createServer = await getNodeCreateServer();
60
-
61
- return new Promise((resolve, reject) => {
62
- let result: { code: string; state: string } | null = null;
63
- let cancelled = false;
64
-
65
- const server = createServer((req, res) => {
66
- const url = new URL(req.url || "", `http://localhost:8085`);
67
-
68
- if (url.pathname === "/oauth2callback") {
69
- const code = url.searchParams.get("code");
70
- const state = url.searchParams.get("state");
71
- const error = url.searchParams.get("error");
72
-
73
- if (error) {
74
- res.writeHead(400, { "Content-Type": "text/html" });
75
- res.end(
76
- `<html><body><h1>Authentication Failed</h1><p>Error: ${error}</p><p>You can close this window.</p></body></html>`,
77
- );
78
- return;
79
- }
80
-
81
- if (code && state) {
82
- res.writeHead(200, { "Content-Type": "text/html" });
83
- res.end(
84
- `<html><body><h1>Authentication Successful</h1><p>You can close this window and return to the terminal.</p></body></html>`,
85
- );
86
- result = { code, state };
87
- } else {
88
- res.writeHead(400, { "Content-Type": "text/html" });
89
- res.end(
90
- `<html><body><h1>Authentication Failed</h1><p>Missing code or state parameter.</p></body></html>`,
91
- );
92
- }
93
- } else {
94
- res.writeHead(404);
95
- res.end();
96
- }
97
- });
98
-
99
- server.on("error", (err) => {
100
- reject(err);
101
- });
102
-
103
- server.listen(8085, "127.0.0.1", () => {
104
- resolve({
105
- server,
106
- cancelWait: () => {
107
- cancelled = true;
108
- },
109
- waitForCode: async () => {
110
- const sleep = () => new Promise((r) => setTimeout(r, 100));
111
- while (!result && !cancelled) {
112
- await sleep();
113
- }
114
- return result;
115
- },
116
- });
117
- });
118
- });
119
- }
120
-
121
- /**
122
- * Parse redirect URL to extract code and state
123
- */
124
- function parseRedirectUrl(input: string): { code?: string; state?: string } {
125
- const value = input.trim();
126
- if (!value) return {};
127
-
128
- try {
129
- const url = new URL(value);
130
- return {
131
- code: url.searchParams.get("code") ?? undefined,
132
- state: url.searchParams.get("state") ?? undefined,
133
- };
134
- } catch {
135
- // Not a URL, return empty
136
- return {};
137
- }
138
- }
38
+ // Callback server configuration
39
+ const CALLBACK_PORT = 8085;
40
+ const CALLBACK_PATH = "/oauth2callback";
139
41
 
140
42
  interface LoadCodeAssistPayload {
141
43
  cloudaicompanionProject?: string;
@@ -356,61 +258,11 @@ async function discoverProject(accessToken: string, onProgress?: (message: strin
356
258
  );
357
259
  }
358
260
 
359
- /**
360
- * Get user email from the access token
361
- */
362
- async function getUserEmail(accessToken: string): Promise<string | undefined> {
363
- try {
364
- const response = await fetch("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
365
- headers: {
366
- Authorization: `Bearer ${accessToken}`,
367
- },
368
- signal: AbortSignal.timeout(30_000),
369
- });
370
-
371
- if (response.ok) {
372
- const data = (await response.json()) as { email?: string };
373
- return data.email;
374
- }
375
- } catch {
376
- // Ignore errors, email is optional
377
- }
378
- return undefined;
379
- }
380
-
381
261
  /**
382
262
  * Refresh Google Cloud Code Assist token
383
263
  */
384
264
  export async function refreshGoogleCloudToken(refreshToken: string, projectId: string): Promise<OAuthCredentials> {
385
- const response = await fetch(TOKEN_URL, {
386
- method: "POST",
387
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
388
- body: new URLSearchParams({
389
- client_id: CLIENT_ID,
390
- client_secret: CLIENT_SECRET,
391
- refresh_token: refreshToken,
392
- grant_type: "refresh_token",
393
- }),
394
- signal: AbortSignal.timeout(30_000),
395
- });
396
-
397
- if (!response.ok) {
398
- const error = await response.text();
399
- throw new Error(`Google Cloud token refresh failed: ${error}`);
400
- }
401
-
402
- const data = (await response.json()) as {
403
- access_token: string;
404
- expires_in: number;
405
- refresh_token?: string;
406
- };
407
-
408
- return {
409
- refresh: data.refresh_token || refreshToken,
410
- access: data.access_token,
411
- expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
412
- projectId,
413
- };
265
+ return refreshGoogleOAuthToken(refreshToken, CLIENT_ID, CLIENT_SECRET, "Google Cloud", { projectId });
414
266
  }
415
267
 
416
268
  /**
@@ -430,7 +282,7 @@ export async function loginGeminiCli(
430
282
 
431
283
  // Start local server for callback
432
284
  onProgress?.("Starting local server for OAuth callback...");
433
- const server = await startCallbackServer();
285
+ const server: CallbackServerInfo = await startCallbackServer(CALLBACK_PORT, CALLBACK_PATH, "Gemini CLI");
434
286
 
435
287
  let code: string | undefined;
436
288
 
@@ -559,7 +411,7 @@ export async function loginGeminiCli(
559
411
 
560
412
  // Get user email
561
413
  onProgress?.("Getting user info...");
562
- const email = await getUserEmail(tokenData.access_token);
414
+ const email = await getGoogleUserEmail(tokenData.access_token);
563
415
 
564
416
  // Discover project
565
417
  const projectId = await discoverProject(tokenData.access_token, onProgress);