@code-yeongyu/senpi 2026.9.10 → 2026.9.11

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 (337) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/core/agent-session.d.ts +57 -0
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +130 -20
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/auth-storage.d.ts +2 -0
  7. package/dist/core/auth-storage.d.ts.map +1 -1
  8. package/dist/core/auth-storage.js +49 -17
  9. package/dist/core/auth-storage.js.map +1 -1
  10. package/dist/core/brand.d.ts +5 -0
  11. package/dist/core/brand.d.ts.map +1 -1
  12. package/dist/core/brand.js +13 -0
  13. package/dist/core/brand.js.map +1 -1
  14. package/dist/core/changelog-source.d.ts +8 -0
  15. package/dist/core/changelog-source.d.ts.map +1 -0
  16. package/dist/core/changelog-source.js +19 -0
  17. package/dist/core/changelog-source.js.map +1 -0
  18. package/dist/core/credential-accounts.d.ts +3 -0
  19. package/dist/core/credential-accounts.d.ts.map +1 -1
  20. package/dist/core/credential-accounts.js +20 -1
  21. package/dist/core/credential-accounts.js.map +1 -1
  22. package/dist/core/credential-pool/classify.d.ts.map +1 -1
  23. package/dist/core/credential-pool/classify.js +8 -0
  24. package/dist/core/credential-pool/classify.js.map +1 -1
  25. package/dist/core/extensions/builtin/account/index.d.ts.map +1 -1
  26. package/dist/core/extensions/builtin/account/index.js +7 -3
  27. package/dist/core/extensions/builtin/account/index.js.map +1 -1
  28. package/dist/core/extensions/builtin/account-display-name.d.ts +7 -0
  29. package/dist/core/extensions/builtin/account-display-name.d.ts.map +1 -0
  30. package/dist/core/extensions/builtin/account-display-name.js +40 -0
  31. package/dist/core/extensions/builtin/account-display-name.js.map +1 -0
  32. package/dist/core/extensions/builtin/ask-user/format.d.ts.map +1 -1
  33. package/dist/core/extensions/builtin/ask-user/format.js +7 -2
  34. package/dist/core/extensions/builtin/ask-user/format.js.map +1 -1
  35. package/dist/core/extensions/builtin/ask-user/pending.d.ts.map +1 -1
  36. package/dist/core/extensions/builtin/ask-user/pending.js +3 -0
  37. package/dist/core/extensions/builtin/ask-user/pending.js.map +1 -1
  38. package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts.map +1 -1
  39. package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js +21 -9
  40. package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js.map +1 -1
  41. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.d.ts +1 -0
  42. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.d.ts.map +1 -1
  43. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.js +11 -6
  44. package/dist/core/extensions/builtin/claude-sdk-oauth/account-management.js.map +1 -1
  45. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.d.ts +9 -0
  46. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.d.ts.map +1 -1
  47. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.js +10 -1
  48. package/dist/core/extensions/builtin/claude-sdk-oauth/accounts.js.map +1 -1
  49. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +3 -0
  50. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
  51. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
  52. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +19 -10
  53. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
  54. package/dist/core/extensions/builtin/claude-sdk-oauth/settings.d.ts.map +1 -1
  55. package/dist/core/extensions/builtin/claude-sdk-oauth/settings.js +3 -9
  56. package/dist/core/extensions/builtin/claude-sdk-oauth/settings.js.map +1 -1
  57. package/dist/core/extensions/builtin/config-reload/routine-settings.d.ts.map +1 -1
  58. package/dist/core/extensions/builtin/config-reload/routine-settings.js +1 -0
  59. package/dist/core/extensions/builtin/config-reload/routine-settings.js.map +1 -1
  60. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.d.ts.map +1 -1
  61. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js +5 -3
  62. package/dist/core/extensions/builtin/cursor-cli-oauth/account-command.js.map +1 -1
  63. package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.d.ts +1 -0
  64. package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.d.ts.map +1 -1
  65. package/dist/core/extensions/builtin/cursor-cli-oauth/accounts.js.map +1 -1
  66. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.d.ts.map +1 -1
  67. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js +3 -9
  68. package/dist/core/extensions/builtin/cursor-cli-oauth/settings.js.map +1 -1
  69. package/dist/core/extensions/builtin/goal/agent-end-continuation.d.ts.map +1 -1
  70. package/dist/core/extensions/builtin/goal/agent-end-continuation.js +13 -1
  71. package/dist/core/extensions/builtin/goal/agent-end-continuation.js.map +1 -1
  72. package/dist/core/extensions/builtin/goal/prompt.d.ts.map +1 -1
  73. package/dist/core/extensions/builtin/goal/prompt.js +11 -8
  74. package/dist/core/extensions/builtin/goal/prompt.js.map +1 -1
  75. package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts +1 -0
  76. package/dist/core/extensions/builtin/goal/terminal-provider-error.d.ts.map +1 -1
  77. package/dist/core/extensions/builtin/goal/terminal-provider-error.js +28 -0
  78. package/dist/core/extensions/builtin/goal/terminal-provider-error.js.map +1 -1
  79. package/dist/core/extensions/builtin/goal/todo-gate.js +2 -2
  80. package/dist/core/extensions/builtin/goal/todo-gate.js.map +1 -1
  81. package/dist/core/extensions/builtin/goal/tool-registration.js +2 -2
  82. package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
  83. package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -1
  84. package/dist/core/extensions/builtin/gpt-account.js +19 -8
  85. package/dist/core/extensions/builtin/gpt-account.js.map +1 -1
  86. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.d.ts +3 -0
  87. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.d.ts.map +1 -0
  88. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.js +19 -0
  89. package/dist/core/extensions/builtin/prompt-preset/deepseek-v4-1-flash.js.map +1 -0
  90. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +6 -6
  91. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -1
  92. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +26 -7
  93. package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -1
  94. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  95. package/dist/core/extensions/builtin/prompt-preset/presets.js +29 -0
  96. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  97. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  98. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  99. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  100. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  101. package/dist/core/high-reasoning-warning.d.ts.map +1 -1
  102. package/dist/core/high-reasoning-warning.js +5 -1
  103. package/dist/core/high-reasoning-warning.js.map +1 -1
  104. package/dist/core/manual-continue.d.ts +14 -0
  105. package/dist/core/manual-continue.d.ts.map +1 -1
  106. package/dist/core/manual-continue.js +13 -0
  107. package/dist/core/manual-continue.js.map +1 -1
  108. package/dist/core/model-runtime.d.ts.map +1 -1
  109. package/dist/core/model-runtime.js +2 -2
  110. package/dist/core/model-runtime.js.map +1 -1
  111. package/dist/core/remote-catalog-merge.d.ts +16 -0
  112. package/dist/core/remote-catalog-merge.d.ts.map +1 -0
  113. package/dist/core/remote-catalog-merge.js +75 -0
  114. package/dist/core/remote-catalog-merge.js.map +1 -0
  115. package/dist/core/remote-catalog-provider.d.ts +3 -0
  116. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  117. package/dist/core/remote-catalog-provider.js +12 -40
  118. package/dist/core/remote-catalog-provider.js.map +1 -1
  119. package/dist/core/session-entry-materializer.d.ts +12 -0
  120. package/dist/core/session-entry-materializer.d.ts.map +1 -0
  121. package/dist/core/session-entry-materializer.js +26 -0
  122. package/dist/core/session-entry-materializer.js.map +1 -0
  123. package/dist/core/session-manager.d.ts +36 -1
  124. package/dist/core/session-manager.d.ts.map +1 -1
  125. package/dist/core/session-manager.js +38 -8
  126. package/dist/core/session-manager.js.map +1 -1
  127. package/dist/core/settings-manager.d.ts +3 -0
  128. package/dist/core/settings-manager.d.ts.map +1 -1
  129. package/dist/core/settings-manager.js +10 -0
  130. package/dist/core/settings-manager.js.map +1 -1
  131. package/dist/modes/app-server/daemon/process.d.ts +6 -1
  132. package/dist/modes/app-server/daemon/process.d.ts.map +1 -1
  133. package/dist/modes/app-server/daemon/process.js +23 -4
  134. package/dist/modes/app-server/daemon/process.js.map +1 -1
  135. package/dist/modes/app-server/protocol/account.d.ts +2 -0
  136. package/dist/modes/app-server/protocol/account.d.ts.map +1 -1
  137. package/dist/modes/app-server/protocol/account.js.map +1 -1
  138. package/dist/modes/interactive/components/ask-user-question-keys.d.ts +1 -1
  139. package/dist/modes/interactive/components/ask-user-question-keys.d.ts.map +1 -1
  140. package/dist/modes/interactive/components/ask-user-question-keys.js +65 -17
  141. package/dist/modes/interactive/components/ask-user-question-keys.js.map +1 -1
  142. package/dist/modes/interactive/components/ask-user-question-render.d.ts +2 -1
  143. package/dist/modes/interactive/components/ask-user-question-render.d.ts.map +1 -1
  144. package/dist/modes/interactive/components/ask-user-question-render.js +39 -9
  145. package/dist/modes/interactive/components/ask-user-question-render.js.map +1 -1
  146. package/dist/modes/interactive/components/ask-user-question-state.d.ts +14 -4
  147. package/dist/modes/interactive/components/ask-user-question-state.d.ts.map +1 -1
  148. package/dist/modes/interactive/components/ask-user-question-state.js +63 -6
  149. package/dist/modes/interactive/components/ask-user-question-state.js.map +1 -1
  150. package/dist/modes/interactive/components/ask-user-question.d.ts +2 -0
  151. package/dist/modes/interactive/components/ask-user-question.d.ts.map +1 -1
  152. package/dist/modes/interactive/components/ask-user-question.js +27 -14
  153. package/dist/modes/interactive/components/ask-user-question.js.map +1 -1
  154. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  155. package/dist/modes/interactive/components/footer.js +51 -19
  156. package/dist/modes/interactive/components/footer.js.map +1 -1
  157. package/dist/modes/interactive/components/login-dialog.d.ts +11 -0
  158. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  159. package/dist/modes/interactive/components/login-dialog.js +29 -9
  160. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  161. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  162. package/dist/modes/interactive/components/tree-selector.js +7 -0
  163. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  164. package/dist/modes/interactive/help-content.d.ts.map +1 -1
  165. package/dist/modes/interactive/help-content.js +4 -0
  166. package/dist/modes/interactive/help-content.js.map +1 -1
  167. package/dist/modes/interactive/interactive-mode.d.ts +13 -4
  168. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  169. package/dist/modes/interactive/interactive-mode.js +44 -15
  170. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  171. package/dist/modes/interactive/tips/catalog/input-tips.js +1 -1
  172. package/dist/modes/interactive/tips/catalog/input-tips.js.map +1 -1
  173. package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
  174. package/dist/modes/rpc/connection-handler.js +3 -1
  175. package/dist/modes/rpc/connection-handler.js.map +1 -1
  176. package/dist/modes/rpc/connection-question-bridge.js +1 -1
  177. package/dist/modes/rpc/connection-question-bridge.js.map +1 -1
  178. package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
  179. package/dist/modes/rpc/host-ensure.js +33 -11
  180. package/dist/modes/rpc/host-ensure.js.map +1 -1
  181. package/dist/modes/rpc/host-lifecycle.d.ts +14 -0
  182. package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
  183. package/dist/modes/rpc/host-lifecycle.js +31 -5
  184. package/dist/modes/rpc/host-lifecycle.js.map +1 -1
  185. package/dist/modes/rpc/rpc-input-validation.d.ts.map +1 -1
  186. package/dist/modes/rpc/rpc-input-validation.js +2 -0
  187. package/dist/modes/rpc/rpc-input-validation.js.map +1 -1
  188. package/dist/modes/rpc/rpc-types.d.ts +2 -0
  189. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  190. package/dist/modes/rpc/rpc-types.js.map +1 -1
  191. package/dist/utils/changelog.d.ts +3 -1
  192. package/dist/utils/changelog.d.ts.map +1 -1
  193. package/dist/utils/changelog.js +89 -23
  194. package/dist/utils/changelog.js.map +1 -1
  195. package/dist/utils/paths.d.ts +5 -0
  196. package/dist/utils/paths.d.ts.map +1 -1
  197. package/dist/utils/paths.js +14 -1
  198. package/dist/utils/paths.js.map +1 -1
  199. package/docs/app-server.md +6 -0
  200. package/docs/extensions.md +19 -3
  201. package/docs/rpc.md +10 -0
  202. package/docs/settings.md +2 -1
  203. package/docs/tui.md +1 -1
  204. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +28 -0
  205. package/node_modules/@code-yeongyu/senpi-codemode/README.md +5 -4
  206. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  207. package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output-buffer.ts +58 -0
  208. package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output.ts +9 -64
  209. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +1 -1
  210. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  211. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.d.ts +17 -0
  212. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.d.ts.map +1 -0
  213. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.js +90 -0
  214. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/discovery.js.map +1 -0
  215. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.d.ts +23 -0
  216. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.d.ts.map +1 -0
  217. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.js +71 -0
  218. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/frames.js.map +1 -0
  219. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.d.ts +873 -0
  220. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.d.ts.map +1 -0
  221. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.js +303 -0
  222. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/gen/cascade_pb.js.map +1 -0
  223. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.d.ts +12 -0
  224. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.d.ts.map +1 -0
  225. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.js +35 -0
  226. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/metadata.js.map +1 -0
  227. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.d.ts +23 -0
  228. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.d.ts.map +1 -0
  229. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.js +23 -0
  230. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/paths.js.map +1 -0
  231. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.d.ts +24 -0
  232. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.d.ts.map +1 -0
  233. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.js +116 -0
  234. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/request.js.map +1 -0
  235. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.d.ts +20 -0
  236. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.d.ts.map +1 -0
  237. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.js +153 -0
  238. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/stream-state.js.map +1 -0
  239. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.d.ts +12 -0
  240. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.d.ts.map +1 -0
  241. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.js +3 -0
  242. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/types.js.map +1 -0
  243. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.d.ts +6 -0
  244. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.d.ts.map +1 -0
  245. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.js +6 -0
  246. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent/wire.js.map +1 -0
  247. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.d.ts +14 -0
  248. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.d.ts.map +1 -0
  249. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.js +162 -0
  250. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.js.map +1 -0
  251. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.d.ts +5 -0
  252. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.d.ts.map +1 -0
  253. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.js +23 -0
  254. package/node_modules/@earendil-works/pi-ai/dist/api/devin-agent.lazy.js.map +1 -0
  255. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.d.ts +25 -0
  256. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.d.ts.map +1 -0
  257. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.js +124 -0
  258. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-callback.js.map +1 -0
  259. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.d.ts +18 -0
  260. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.d.ts.map +1 -0
  261. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.js +101 -0
  262. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin-token.js.map +1 -0
  263. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.d.ts +14 -0
  264. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.d.ts.map +1 -0
  265. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.js +111 -0
  266. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/devin.js.map +1 -0
  267. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
  268. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +5 -1
  269. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js.map +1 -1
  270. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.d.ts +24 -0
  271. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.d.ts.map +1 -0
  272. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.js +86 -0
  273. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-identity.js.map +1 -0
  274. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts +2 -0
  275. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts.map +1 -1
  276. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +5 -0
  277. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js.map +1 -1
  278. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +51 -4
  279. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
  280. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +196 -7
  281. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
  282. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +8 -0
  283. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
  284. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +10 -0
  285. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
  286. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +9 -1
  287. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
  288. package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
  289. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts.map +1 -1
  290. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +2 -0
  291. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js.map +1 -1
  292. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +1 -0
  293. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
  294. package/node_modules/@earendil-works/pi-ai/dist/compat.js +3 -0
  295. package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
  296. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +4 -4
  297. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  298. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +1 -1
  299. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
  300. package/node_modules/@earendil-works/pi-ai/dist/models.js +14 -5
  301. package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
  302. package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
  303. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +2 -0
  304. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
  305. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  306. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  307. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  308. package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  309. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  310. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  311. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  313. package/node_modules/@earendil-works/pi-ai/dist/providers/data/venice.json +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  315. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.d.ts +12 -0
  316. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.d.ts.map +1 -0
  317. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.js +62 -0
  318. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.js.map +1 -0
  319. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.d.ts +10 -0
  320. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.d.ts.map +1 -0
  321. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.js +28 -0
  322. package/node_modules/@earendil-works/pi-ai/dist/providers/devin.models.js.map +1 -0
  323. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +3 -1
  324. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  325. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  326. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  327. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +4 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  329. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  330. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  331. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  332. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.d.ts +1 -1
  333. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.d.ts.map +1 -1
  334. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.js +55 -16
  335. package/node_modules/@earendil-works/pi-tui/dist/dollar-invocation-autocomplete.js.map +1 -1
  336. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  337. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"kimi-coding.js","sourceRoot":"","sources":["../../../src/auth/oauth/kimi-coding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,CAAC;AAC5C,MAAM,6BAA6B,GAAG,CAAC,CAAC;AACxC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AACrC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAiB9B,SAAS,YAAY;IACpB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,IAAI,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACvG,OAAO,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,aAAa,CAAC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EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACxE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;AAChG,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAc;IACzC,IAAI,EAAE,0BAA0B;IAChC,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,wBAAwB;IAEpC,KAAK,EAAE,eAAe;IAEtB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,YAAY,EAAE,EAAE,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAU;QACtB,OAAO,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;IACtE,CAAC;CACD,CAAC","sourcesContent":["/**\n * Kimi Code (subscription) OAuth flow\n *\n * RFC 8628 device authorization grant against https://auth.kimi.com with JSON\n * responses. The access token authenticates requests to\n * https://api.kimi.com/coding as an `Authorization: Bearer` header.\n */\n\nimport { getProviderEnvValue } from \"../../utils/provider-env.ts\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { OAuthAuth, OAuthCredential, ProviderAuthInteraction } from \"../types.ts\";\nimport { pollOAuthDeviceCodeFlow } from \"./device-code.ts\";\n\nconst CLIENT_ID = \"17e5f671-d194-4dfb-9706-5516cb48c098\";\nconst DEFAULT_OAUTH_HOST = \"https://auth.kimi.com\";\nconst DEVICE_CODE_TIMEOUT_SECONDS = 15 * 60;\nconst DEFAULT_POLL_INTERVAL_SECONDS = 5;\nconst REQUEST_TIMEOUT_MS = 30 * 1000;\nconst REFRESH_MAX_RETRIES = 3;\n\ntype DeviceAuthorization = {\n\tdeviceCode: string;\n\tuserCode: string;\n\tverificationUri: string;\n\tverificationUriComplete: string;\n\tintervalSeconds: number;\n\texpiresInSeconds: number;\n};\n\ntype TokenResponse = {\n\taccess: string;\n\trefresh: string;\n\texpires: number;\n};\n\nfunction getOauthHost(): string {\n\tconst override = getProviderEnvValue(\"KIMI_CODE_OAUTH_HOST\") || getProviderEnvValue(\"KIMI_OAUTH_HOST\");\n\treturn (override || DEFAULT_OAUTH_HOST).replace(/\\/+$/, \"\");\n}\n\nfunction requestSignal(signal: AbortSignal): AbortSignal {\n\treturn AbortSignal.any([AbortSignal.timeout(REQUEST_TIMEOUT_MS), signal]);\n}\n\nfunction formUrlEncode(fields: Record<string, string>): string {\n\treturn new URLSearchParams(fields).toString();\n}\n\nasync function readJson(response: Response): Promise<Record<string, unknown> | null> {\n\ttry {\n\t\tconst json = await response.json();\n\t\treturn json && typeof json === \"object\" ? (json as Record<string, unknown>) : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** The verification URI is opened in the user's browser; only http(s) URLs are trusted. */\nfunction trustedHttpUrl(value: unknown): string | null {\n\tif (typeof value !== \"string\" || !value) return null;\n\ttry {\n\t\tconst url = new URL(value);\n\t\tif (url.protocol !== \"https:\" && url.protocol !== \"http:\") return null;\n\t\treturn url.href;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function startDeviceAuthorization(oauthHost: string, signal: AbortSignal): Promise<DeviceAuthorization> {\n\tconst response = await fetch(`${oauthHost}/api/oauth/device_authorization`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\tAccept: \"application/json\",\n\t\t},\n\t\tbody: formUrlEncode({ client_id: CLIENT_ID }),\n\t\tsignal: requestSignal(signal),\n\t});\n\n\tif (!response.ok) {\n\t\tconst text = await response.text().catch(() => \"\");\n\t\tthrow new Error(`Kimi Code device authorization failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tconst json = await readJson(response);\n\tconst deviceCode = json?.device_code;\n\tconst userCode = json?.user_code;\n\tconst verificationUri = json?.verification_uri;\n\tconst verificationUriComplete = json?.verification_uri_complete;\n\tif (\n\t\ttypeof deviceCode !== \"string\" ||\n\t\ttypeof userCode !== \"string\" ||\n\t\ttypeof verificationUri !== \"string\" ||\n\t\ttypeof verificationUriComplete !== \"string\" ||\n\t\t!trustedHttpUrl(verificationUriComplete) ||\n\t\t!trustedHttpUrl(verificationUri)\n\t) {\n\t\tthrow new Error(`Invalid Kimi Code device authorization response: ${JSON.stringify(json)}`);\n\t}\n\n\tconst interval = json?.interval;\n\tconst expiresIn = json?.expires_in;\n\treturn {\n\t\tdeviceCode,\n\t\tuserCode,\n\t\tverificationUri,\n\t\tverificationUriComplete,\n\t\tintervalSeconds:\n\t\t\ttypeof interval === \"number\" && Number.isFinite(interval) && interval > 0\n\t\t\t\t? interval\n\t\t\t\t: DEFAULT_POLL_INTERVAL_SECONDS,\n\t\texpiresInSeconds:\n\t\t\ttypeof expiresIn === \"number\" && Number.isFinite(expiresIn) && expiresIn > 0\n\t\t\t\t? expiresIn\n\t\t\t\t: DEVICE_CODE_TIMEOUT_SECONDS,\n\t};\n}\n\nfunction parseTokenResponse(json: Record<string, unknown> | null, operation: string): TokenResponse {\n\tconst accessToken = json?.access_token;\n\tconst refreshToken = json?.refresh_token;\n\tconst expiresIn = json?.expires_in;\n\tif (\n\t\ttypeof accessToken !== \"string\" ||\n\t\t!accessToken ||\n\t\ttypeof refreshToken !== \"string\" ||\n\t\t!refreshToken ||\n\t\ttypeof expiresIn !== \"number\" ||\n\t\t!Number.isFinite(expiresIn) ||\n\t\texpiresIn <= 0\n\t) {\n\t\tthrow new Error(`Kimi Code token ${operation} response missing fields: ${JSON.stringify(json)}`);\n\t}\n\treturn {\n\t\taccess: accessToken,\n\t\trefresh: refreshToken,\n\t\texpires: Date.now() + expiresIn * 1000,\n\t};\n}\n\nasync function pollForToken(\n\toauthHost: string,\n\tdevice: DeviceAuthorization,\n\tsignal: AbortSignal,\n): Promise<TokenResponse> {\n\treturn pollOAuthDeviceCodeFlow<TokenResponse>({\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t\twaitBeforeFirstPoll: true,\n\t\tsignal,\n\t\tpoll: async () => {\n\t\t\tconst response = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tdevice_code: device.deviceCode,\n\t\t\t\t\tgrant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tconst text = await response.text().catch(() => \"\");\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tmessage: `Kimi Code device token request failed with status ${response.status}${text ? `: ${text}` : \"\"}`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst json = await readJson(response);\n\t\t\tif (response.ok && typeof json?.access_token === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn { status: \"complete\", value: parseTokenResponse(json, \"poll\") };\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn { status: \"failed\", message: error instanceof Error ? error.message : String(error) };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst error = json?.error;\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tif (error === \"authorization_pending\") {\n\t\t\t\treturn { status: \"pending\" };\n\t\t\t}\n\t\t\tif (error === \"slow_down\") {\n\t\t\t\tconst interval = json?.interval;\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"slow_down\",\n\t\t\t\t\tintervalSeconds: typeof interval === \"number\" && interval > 0 ? interval : undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (error === \"expired_token\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code device authorization expired. Please restart login.\" };\n\t\t\t}\n\t\t\tif (error === \"access_denied\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code login was denied.\" };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tmessage: `Kimi Code device token request failed (status ${response.status})${typeof error === \"string\" ? `: ${error}${description}` : \"\"}`,\n\t\t\t};\n\t\t},\n\t});\n}\n\nfunction isRetryableRefreshFailure(response: Response): boolean {\n\treturn response.status === 429 || response.status >= 500;\n}\n\nasync function refreshToken(oauthHost: string, refreshTokenValue: string, signal: AbortSignal): Promise<TokenResponse> {\n\tlet lastError: Error | undefined;\n\tfor (let attempt = 0; attempt <= REFRESH_MAX_RETRIES; attempt++) {\n\t\tif (attempt > 0) {\n\t\t\tawait sleep(1000 * 2 ** (attempt - 1), signal);\n\t\t}\n\t\tif (signal.aborted) {\n\t\t\tthrow new Error(\"Kimi Code token refresh aborted\");\n\t\t}\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\t\trefresh_token: refreshTokenValue,\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst json = await readJson(response);\n\t\tif (response.ok) {\n\t\t\treturn parseTokenResponse(json, \"refresh\");\n\t\t}\n\n\t\t// Unauthorized: the stored credential is dead; Models clears it and prompts re-login.\n\t\tif (response.status === 401 || response.status === 403 || json?.error === \"invalid_grant\") {\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tthrow new Error(`Kimi Code token refresh unauthorized (status ${response.status})${description}`);\n\t\t}\n\n\t\tif (isRetryableRefreshFailure(response) && attempt < REFRESH_MAX_RETRIES) {\n\t\t\tlastError = new Error(`Kimi Code token refresh failed with status ${response.status}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst text = JSON.stringify(json);\n\t\tthrow new Error(`Kimi Code token refresh failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tthrow lastError ?? new Error(\"Kimi Code token refresh failed\");\n}\n\nasync function loginKimiCoding(interaction: ProviderAuthInteraction): Promise<OAuthCredential> {\n\tconst oauthHost = getOauthHost();\n\tconst device = await startDeviceAuthorization(oauthHost, interaction.signal);\n\tinteraction.notify({\n\t\ttype: \"device_code\",\n\t\tuserCode: device.userCode,\n\t\tverificationUri: device.verificationUriComplete,\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t});\n\tconst token = await pollForToken(oauthHost, device, interaction.signal);\n\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n}\n\nexport const kimiCodingOAuth: OAuthAuth = {\n\tname: \"Kimi Code (subscription)\",\n\tisSubscription: true,\n\tloginLabel: \"Sign in with Kimi Code\",\n\n\tlogin: loginKimiCoding,\n\n\trefresh: async (credential, signal) => {\n\t\tconst token = await refreshToken(getOauthHost(), credential.refresh, signal);\n\t\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n\t},\n\n\tasync toAuth(credential) {\n\t\treturn { headers: { Authorization: `Bearer ${credential.access}` } };\n\t},\n};\n"]}
1
+ {"version":3,"file":"kimi-coding.js","sourceRoot":"","sources":["../../../src/auth/oauth/kimi-coding.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,MAAM,SAAS,GAAG,sCAAsC,CAAC;AACzD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,CAAC;AAC5C,MAAM,6BAA6B,GAAG,CAAC,CAAC;AACxC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AACrC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAiB9B,SAAS,YAAY;IACpB,MAAM,QAAQ,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,IAAI,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;IACvG,OAAO,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,aAAa,CAAC,MAAmB;IACzC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,aAAa,CAAC,MAA8B;IACpD,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC/C,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,QAAkB;IACzC,IAAI,CAAC;QAC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;AAED,MAAM,CAAC,MAAM,eAAe,GAAc;IACzC,IAAI,EAAE,0BAA0B;IAChC,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,wBAAwB;IAEpC,KAAK,EAAE,eAAe;IAEtB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,YAAY,EAAE,EAAE,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAChG,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAU;QACtB,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,uBAAuB,EAAE,EAAE,aAAa,EAAE,UAAU,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC;IACpG,CAAC;CACD,CAAC","sourcesContent":["/**\n * Kimi Code (subscription) OAuth flow\n *\n * RFC 8628 device authorization grant against https://auth.kimi.com with JSON\n * responses. The access token authenticates requests to\n * https://api.kimi.com/coding as an `Authorization: Bearer` header.\n */\n\nimport { getProviderEnvValue } from \"../../utils/provider-env.ts\";\nimport { sleep } from \"../../utils/sleep.ts\";\nimport type { OAuthAuth, OAuthCredential, ProviderAuthInteraction } from \"../types.ts\";\nimport { pollOAuthDeviceCodeFlow } from \"./device-code.ts\";\nimport { kimiCodeIdentityHeaders } from \"./kimi-identity.ts\";\n\nconst CLIENT_ID = \"17e5f671-d194-4dfb-9706-5516cb48c098\";\nconst DEFAULT_OAUTH_HOST = \"https://auth.kimi.com\";\nconst DEVICE_CODE_TIMEOUT_SECONDS = 15 * 60;\nconst DEFAULT_POLL_INTERVAL_SECONDS = 5;\nconst REQUEST_TIMEOUT_MS = 30 * 1000;\nconst REFRESH_MAX_RETRIES = 3;\n\ntype DeviceAuthorization = {\n\tdeviceCode: string;\n\tuserCode: string;\n\tverificationUri: string;\n\tverificationUriComplete: string;\n\tintervalSeconds: number;\n\texpiresInSeconds: number;\n};\n\ntype TokenResponse = {\n\taccess: string;\n\trefresh: string;\n\texpires: number;\n};\n\nfunction getOauthHost(): string {\n\tconst override = getProviderEnvValue(\"KIMI_CODE_OAUTH_HOST\") || getProviderEnvValue(\"KIMI_OAUTH_HOST\");\n\treturn (override || DEFAULT_OAUTH_HOST).replace(/\\/+$/, \"\");\n}\n\nfunction requestSignal(signal: AbortSignal): AbortSignal {\n\treturn AbortSignal.any([AbortSignal.timeout(REQUEST_TIMEOUT_MS), signal]);\n}\n\nfunction formUrlEncode(fields: Record<string, string>): string {\n\treturn new URLSearchParams(fields).toString();\n}\n\nasync function readJson(response: Response): Promise<Record<string, unknown> | null> {\n\ttry {\n\t\tconst json = await response.json();\n\t\treturn json && typeof json === \"object\" ? (json as Record<string, unknown>) : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** The verification URI is opened in the user's browser; only http(s) URLs are trusted. */\nfunction trustedHttpUrl(value: unknown): string | null {\n\tif (typeof value !== \"string\" || !value) return null;\n\ttry {\n\t\tconst url = new URL(value);\n\t\tif (url.protocol !== \"https:\" && url.protocol !== \"http:\") return null;\n\t\treturn url.href;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function startDeviceAuthorization(oauthHost: string, signal: AbortSignal): Promise<DeviceAuthorization> {\n\tconst response = await fetch(`${oauthHost}/api/oauth/device_authorization`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t...kimiCodeIdentityHeaders(),\n\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\tAccept: \"application/json\",\n\t\t},\n\t\tbody: formUrlEncode({ client_id: CLIENT_ID }),\n\t\tsignal: requestSignal(signal),\n\t});\n\n\tif (!response.ok) {\n\t\tconst text = await response.text().catch(() => \"\");\n\t\tthrow new Error(`Kimi Code device authorization failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tconst json = await readJson(response);\n\tconst deviceCode = json?.device_code;\n\tconst userCode = json?.user_code;\n\tconst verificationUri = json?.verification_uri;\n\tconst verificationUriComplete = json?.verification_uri_complete;\n\tif (\n\t\ttypeof deviceCode !== \"string\" ||\n\t\ttypeof userCode !== \"string\" ||\n\t\ttypeof verificationUri !== \"string\" ||\n\t\ttypeof verificationUriComplete !== \"string\" ||\n\t\t!trustedHttpUrl(verificationUriComplete) ||\n\t\t!trustedHttpUrl(verificationUri)\n\t) {\n\t\tthrow new Error(`Invalid Kimi Code device authorization response: ${JSON.stringify(json)}`);\n\t}\n\n\tconst interval = json?.interval;\n\tconst expiresIn = json?.expires_in;\n\treturn {\n\t\tdeviceCode,\n\t\tuserCode,\n\t\tverificationUri,\n\t\tverificationUriComplete,\n\t\tintervalSeconds:\n\t\t\ttypeof interval === \"number\" && Number.isFinite(interval) && interval > 0\n\t\t\t\t? interval\n\t\t\t\t: DEFAULT_POLL_INTERVAL_SECONDS,\n\t\texpiresInSeconds:\n\t\t\ttypeof expiresIn === \"number\" && Number.isFinite(expiresIn) && expiresIn > 0\n\t\t\t\t? expiresIn\n\t\t\t\t: DEVICE_CODE_TIMEOUT_SECONDS,\n\t};\n}\n\nfunction parseTokenResponse(json: Record<string, unknown> | null, operation: string): TokenResponse {\n\tconst accessToken = json?.access_token;\n\tconst refreshToken = json?.refresh_token;\n\tconst expiresIn = json?.expires_in;\n\tif (\n\t\ttypeof accessToken !== \"string\" ||\n\t\t!accessToken ||\n\t\ttypeof refreshToken !== \"string\" ||\n\t\t!refreshToken ||\n\t\ttypeof expiresIn !== \"number\" ||\n\t\t!Number.isFinite(expiresIn) ||\n\t\texpiresIn <= 0\n\t) {\n\t\tthrow new Error(`Kimi Code token ${operation} response missing fields: ${JSON.stringify(json)}`);\n\t}\n\treturn {\n\t\taccess: accessToken,\n\t\trefresh: refreshToken,\n\t\texpires: Date.now() + expiresIn * 1000,\n\t};\n}\n\nasync function pollForToken(\n\toauthHost: string,\n\tdevice: DeviceAuthorization,\n\tsignal: AbortSignal,\n): Promise<TokenResponse> {\n\treturn pollOAuthDeviceCodeFlow<TokenResponse>({\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t\twaitBeforeFirstPoll: true,\n\t\tsignal,\n\t\tpoll: async () => {\n\t\t\tconst response = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t...kimiCodeIdentityHeaders(),\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tdevice_code: device.deviceCode,\n\t\t\t\t\tgrant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\n\t\t\tif (response.status >= 500) {\n\t\t\t\tconst text = await response.text().catch(() => \"\");\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tmessage: `Kimi Code device token request failed with status ${response.status}${text ? `: ${text}` : \"\"}`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst json = await readJson(response);\n\t\t\tif (response.ok && typeof json?.access_token === \"string\") {\n\t\t\t\ttry {\n\t\t\t\t\treturn { status: \"complete\", value: parseTokenResponse(json, \"poll\") };\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn { status: \"failed\", message: error instanceof Error ? error.message : String(error) };\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst error = json?.error;\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tif (error === \"authorization_pending\") {\n\t\t\t\treturn { status: \"pending\" };\n\t\t\t}\n\t\t\tif (error === \"slow_down\") {\n\t\t\t\tconst interval = json?.interval;\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"slow_down\",\n\t\t\t\t\tintervalSeconds: typeof interval === \"number\" && interval > 0 ? interval : undefined,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (error === \"expired_token\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code device authorization expired. Please restart login.\" };\n\t\t\t}\n\t\t\tif (error === \"access_denied\") {\n\t\t\t\treturn { status: \"failed\", message: \"Kimi Code login was denied.\" };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tmessage: `Kimi Code device token request failed (status ${response.status})${typeof error === \"string\" ? `: ${error}${description}` : \"\"}`,\n\t\t\t};\n\t\t},\n\t});\n}\n\nfunction isRetryableRefreshFailure(response: Response): boolean {\n\treturn response.status === 429 || response.status >= 500;\n}\n\nasync function refreshToken(oauthHost: string, refreshTokenValue: string, signal: AbortSignal): Promise<TokenResponse> {\n\tlet lastError: Error | undefined;\n\tfor (let attempt = 0; attempt <= REFRESH_MAX_RETRIES; attempt++) {\n\t\tif (attempt > 0) {\n\t\t\tawait sleep(1000 * 2 ** (attempt - 1), signal);\n\t\t}\n\t\tif (signal.aborted) {\n\t\t\tthrow new Error(\"Kimi Code token refresh aborted\");\n\t\t}\n\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(`${oauthHost}/api/oauth/token`, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t...kimiCodeIdentityHeaders(),\n\t\t\t\t\t\"Content-Type\": \"application/x-www-form-urlencoded\",\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t},\n\t\t\t\tbody: formUrlEncode({\n\t\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\t\trefresh_token: refreshTokenValue,\n\t\t\t\t}),\n\t\t\t\tsignal: requestSignal(signal),\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst json = await readJson(response);\n\t\tif (response.ok) {\n\t\t\treturn parseTokenResponse(json, \"refresh\");\n\t\t}\n\n\t\t// Unauthorized: the stored credential is dead; Models clears it and prompts re-login.\n\t\tif (response.status === 401 || response.status === 403 || json?.error === \"invalid_grant\") {\n\t\t\tconst description = typeof json?.error_description === \"string\" ? `: ${json.error_description}` : \"\";\n\t\t\tthrow new Error(`Kimi Code token refresh unauthorized (status ${response.status})${description}`);\n\t\t}\n\n\t\tif (isRetryableRefreshFailure(response) && attempt < REFRESH_MAX_RETRIES) {\n\t\t\tlastError = new Error(`Kimi Code token refresh failed with status ${response.status}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst text = JSON.stringify(json);\n\t\tthrow new Error(`Kimi Code token refresh failed with status ${response.status}${text ? `: ${text}` : \"\"}`);\n\t}\n\n\tthrow lastError ?? new Error(\"Kimi Code token refresh failed\");\n}\n\nasync function loginKimiCoding(interaction: ProviderAuthInteraction): Promise<OAuthCredential> {\n\tconst oauthHost = getOauthHost();\n\tconst device = await startDeviceAuthorization(oauthHost, interaction.signal);\n\tinteraction.notify({\n\t\ttype: \"device_code\",\n\t\tuserCode: device.userCode,\n\t\tverificationUri: device.verificationUriComplete,\n\t\tintervalSeconds: device.intervalSeconds,\n\t\texpiresInSeconds: device.expiresInSeconds,\n\t});\n\tconst token = await pollForToken(oauthHost, device, interaction.signal);\n\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n}\n\nexport const kimiCodingOAuth: OAuthAuth = {\n\tname: \"Kimi Code (subscription)\",\n\tisSubscription: true,\n\tloginLabel: \"Sign in with Kimi Code\",\n\n\tlogin: loginKimiCoding,\n\n\trefresh: async (credential, signal) => {\n\t\tconst token = await refreshToken(getOauthHost(), credential.refresh, signal);\n\t\treturn { type: \"oauth\", access: token.access, refresh: token.refresh, expires: token.expires };\n\t},\n\n\tasync toAuth(credential) {\n\t\treturn { headers: { ...kimiCodeIdentityHeaders(), Authorization: `Bearer ${credential.access}` } };\n\t},\n};\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Kimi Code client identity headers.
3
+ *
4
+ * `api.kimi.com/coding` identifies its clients by a product `User-Agent` plus
5
+ * an `X-Msh-*` device header set, and the official Kimi Code client sends that
6
+ * set on every OAuth and managed-API request (MoonshotAI/kimi-code
7
+ * `packages/oauth/src/identity.ts`). senpi sent none of them, so a
8
+ * subscription session never identified itself as a Kimi client at all.
9
+ *
10
+ * Three contract details that are not visible from the code: values must be
11
+ * printable ASCII (the endpoint sits behind a CDN that answers 520 on raw
12
+ * non-ASCII header bytes), the device id is expected to be stable per install,
13
+ * and the platform string names a client family rather than the host product.
14
+ * Device-id persistence is deliberately best-effort — an unwritable agent dir
15
+ * must degrade to a per-process id, never throw, because these headers are
16
+ * built for every request.
17
+ *
18
+ * Subscription (OAuth) path only: the api-key path authenticates with a
19
+ * platform key rather than a client session and stays header-free.
20
+ */
21
+ /** Test seam: forget the memoized id so a fresh agent dir is re-read. */
22
+ export declare function resetKimiDeviceIdForTests(): void;
23
+ export declare function kimiCodeIdentityHeaders(): Record<string, string>;
24
+ //# sourceMappingURL=kimi-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kimi-identity.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/kimi-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AA0DH,yEAAyE;AACzE,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUhE"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Kimi Code client identity headers.
3
+ *
4
+ * `api.kimi.com/coding` identifies its clients by a product `User-Agent` plus
5
+ * an `X-Msh-*` device header set, and the official Kimi Code client sends that
6
+ * set on every OAuth and managed-API request (MoonshotAI/kimi-code
7
+ * `packages/oauth/src/identity.ts`). senpi sent none of them, so a
8
+ * subscription session never identified itself as a Kimi client at all.
9
+ *
10
+ * Three contract details that are not visible from the code: values must be
11
+ * printable ASCII (the endpoint sits behind a CDN that answers 520 on raw
12
+ * non-ASCII header bytes), the device id is expected to be stable per install,
13
+ * and the platform string names a client family rather than the host product.
14
+ * Device-id persistence is deliberately best-effort — an unwritable agent dir
15
+ * must degrade to a per-process id, never throw, because these headers are
16
+ * built for every request.
17
+ *
18
+ * Subscription (OAuth) path only: the api-key path authenticates with a
19
+ * platform key rather than a client session and stays header-free.
20
+ */
21
+ import { randomUUID } from "node:crypto";
22
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
23
+ import { arch, hostname, platform, release } from "node:os";
24
+ import { join } from "node:path";
25
+ import { getProviderEnvValue } from "../../utils/provider-env.js";
26
+ const KIMI_CLIENT_PLATFORM = "kimi_cli";
27
+ const KIMI_CLIENT_VERSION = "1.0";
28
+ const DEVICE_ID_FILENAME = "kimi-device-id";
29
+ function sanitizeHeaderValue(value, fallback = "unknown") {
30
+ const sanitized = value.replace(/[^\x20-\x7E]/g, "").trim();
31
+ return sanitized || fallback;
32
+ }
33
+ function agentDir() {
34
+ const configured = getProviderEnvValue("SENPI_CODING_AGENT_DIR") ?? getProviderEnvValue("CODING_AGENT_DIR");
35
+ if (configured)
36
+ return configured.replace(/\/$/, "");
37
+ const home = getProviderEnvValue("HOME") ?? ".";
38
+ return `${home.replace(/\/$/, "")}/.senpi/agent`;
39
+ }
40
+ function deviceModel() {
41
+ const current = platform();
42
+ const label = current === "darwin" ? "macOS" : current === "win32" ? "Windows" : current === "linux" ? "Linux" : current;
43
+ return [label, release(), arch()].filter(Boolean).join(" ").trim();
44
+ }
45
+ function readOrMintDeviceId() {
46
+ const directory = agentDir();
47
+ const path = join(directory, DEVICE_ID_FILENAME);
48
+ try {
49
+ const existing = readFileSync(path, "utf-8").trim();
50
+ if (existing)
51
+ return existing;
52
+ }
53
+ catch {
54
+ // Absent or unreadable: fall through and mint a replacement.
55
+ }
56
+ const minted = randomUUID().replace(/-/g, "");
57
+ try {
58
+ mkdirSync(directory, { recursive: true });
59
+ writeFileSync(path, `${minted}\n`, { mode: 0o600 });
60
+ }
61
+ catch {
62
+ // Unwritable agent dir: this id lives for the current process only.
63
+ }
64
+ return minted;
65
+ }
66
+ let cachedDeviceId;
67
+ function deviceId() {
68
+ cachedDeviceId ??= readOrMintDeviceId();
69
+ return cachedDeviceId;
70
+ }
71
+ /** Test seam: forget the memoized id so a fresh agent dir is re-read. */
72
+ export function resetKimiDeviceIdForTests() {
73
+ cachedDeviceId = undefined;
74
+ }
75
+ export function kimiCodeIdentityHeaders() {
76
+ return {
77
+ "User-Agent": `KimiCLI/${KIMI_CLIENT_VERSION}`,
78
+ "X-Msh-Platform": KIMI_CLIENT_PLATFORM,
79
+ "X-Msh-Version": KIMI_CLIENT_VERSION,
80
+ "X-Msh-Device-Name": sanitizeHeaderValue(hostname()),
81
+ "X-Msh-Device-Model": sanitizeHeaderValue(deviceModel()),
82
+ "X-Msh-Os-Version": sanitizeHeaderValue(release()),
83
+ "X-Msh-Device-Id": sanitizeHeaderValue(deviceId()),
84
+ };
85
+ }
86
+ //# sourceMappingURL=kimi-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kimi-identity.js","sourceRoot":"","sources":["../../../src/auth/oauth/kimi-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE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kBAAkB,CAAC,CAAC;IACjD,IAAI,CAAC;QACJ,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QACpD,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACR,6DAA6D;IAC9D,CAAC;IAED,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9C,IAAI,CAAC;QACJ,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,aAAa,CAAC,IAAI,EAAE,GAAG,MAAM,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACR,oEAAoE;IACrE,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,IAAI,cAAkC,CAAC;AAEvC,SAAS,QAAQ;IAChB,cAAc,KAAK,kBAAkB,EAAE,CAAC;IACxC,OAAO,cAAc,CAAC;AACvB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,yBAAyB;IACxC,cAAc,GAAG,SAAS,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,uBAAuB;IACtC,OAAO;QACN,YAAY,EAAE,WAAW,mBAAmB,EAAE;QAC9C,gBAAgB,EAAE,oBAAoB;QACtC,eAAe,EAAE,mBAAmB;QACpC,mBAAmB,EAAE,mBAAmB,CAAC,QAAQ,EAAE,CAAC;QACpD,oBAAoB,EAAE,mBAAmB,CAAC,WAAW,EAAE,CAAC;QACxD,kBAAkB,EAAE,mBAAmB,CAAC,OAAO,EAAE,CAAC;QAClD,iBAAiB,EAAE,mBAAmB,CAAC,QAAQ,EAAE,CAAC;KAClD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Kimi Code client identity headers.\n *\n * `api.kimi.com/coding` identifies its clients by a product `User-Agent` plus\n * an `X-Msh-*` device header set, and the official Kimi Code client sends that\n * set on every OAuth and managed-API request (MoonshotAI/kimi-code\n * `packages/oauth/src/identity.ts`). senpi sent none of them, so a\n * subscription session never identified itself as a Kimi client at all.\n *\n * Three contract details that are not visible from the code: values must be\n * printable ASCII (the endpoint sits behind a CDN that answers 520 on raw\n * non-ASCII header bytes), the device id is expected to be stable per install,\n * and the platform string names a client family rather than the host product.\n * Device-id persistence is deliberately best-effort — an unwritable agent dir\n * must degrade to a per-process id, never throw, because these headers are\n * built for every request.\n *\n * Subscription (OAuth) path only: the api-key path authenticates with a\n * platform key rather than a client session and stays header-free.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { arch, hostname, platform, release } from \"node:os\";\nimport { join } from \"node:path\";\nimport { getProviderEnvValue } from \"../../utils/provider-env.ts\";\n\nconst KIMI_CLIENT_PLATFORM = \"kimi_cli\";\nconst KIMI_CLIENT_VERSION = \"1.0\";\nconst DEVICE_ID_FILENAME = \"kimi-device-id\";\n\nfunction sanitizeHeaderValue(value: string, fallback = \"unknown\"): string {\n\tconst sanitized = value.replace(/[^\\x20-\\x7E]/g, \"\").trim();\n\treturn sanitized || fallback;\n}\n\nfunction agentDir(): string {\n\tconst configured = getProviderEnvValue(\"SENPI_CODING_AGENT_DIR\") ?? getProviderEnvValue(\"CODING_AGENT_DIR\");\n\tif (configured) return configured.replace(/\\/$/, \"\");\n\tconst home = getProviderEnvValue(\"HOME\") ?? \".\";\n\treturn `${home.replace(/\\/$/, \"\")}/.senpi/agent`;\n}\n\nfunction deviceModel(): string {\n\tconst current = platform();\n\tconst label =\n\t\tcurrent === \"darwin\" ? \"macOS\" : current === \"win32\" ? \"Windows\" : current === \"linux\" ? \"Linux\" : current;\n\treturn [label, release(), arch()].filter(Boolean).join(\" \").trim();\n}\n\nfunction readOrMintDeviceId(): string {\n\tconst directory = agentDir();\n\tconst path = join(directory, DEVICE_ID_FILENAME);\n\ttry {\n\t\tconst existing = readFileSync(path, \"utf-8\").trim();\n\t\tif (existing) return existing;\n\t} catch {\n\t\t// Absent or unreadable: fall through and mint a replacement.\n\t}\n\n\tconst minted = randomUUID().replace(/-/g, \"\");\n\ttry {\n\t\tmkdirSync(directory, { recursive: true });\n\t\twriteFileSync(path, `${minted}\\n`, { mode: 0o600 });\n\t} catch {\n\t\t// Unwritable agent dir: this id lives for the current process only.\n\t}\n\treturn minted;\n}\n\nlet cachedDeviceId: string | undefined;\n\nfunction deviceId(): string {\n\tcachedDeviceId ??= readOrMintDeviceId();\n\treturn cachedDeviceId;\n}\n\n/** Test seam: forget the memoized id so a fresh agent dir is re-read. */\nexport function resetKimiDeviceIdForTests(): void {\n\tcachedDeviceId = undefined;\n}\n\nexport function kimiCodeIdentityHeaders(): Record<string, string> {\n\treturn {\n\t\t\"User-Agent\": `KimiCLI/${KIMI_CLIENT_VERSION}`,\n\t\t\"X-Msh-Platform\": KIMI_CLIENT_PLATFORM,\n\t\t\"X-Msh-Version\": KIMI_CLIENT_VERSION,\n\t\t\"X-Msh-Device-Name\": sanitizeHeaderValue(hostname()),\n\t\t\"X-Msh-Device-Model\": sanitizeHeaderValue(deviceModel()),\n\t\t\"X-Msh-Os-Version\": sanitizeHeaderValue(release()),\n\t\t\"X-Msh-Device-Id\": sanitizeHeaderValue(deviceId()),\n\t};\n}\n"]}
@@ -7,6 +7,7 @@ type OAuthFlowLoaders = {
7
7
  kimiCoding: () => OAuthAuth | Promise<OAuthAuth>;
8
8
  xai: () => OAuthAuth | Promise<OAuthAuth>;
9
9
  cursor: () => OAuthAuth | Promise<OAuthAuth>;
10
+ devin: () => OAuthAuth | Promise<OAuthAuth>;
10
11
  radius: (options: {
11
12
  name: string;
12
13
  gateway: string;
@@ -21,6 +22,7 @@ export declare const loadOpenRouterOAuth: () => Promise<OAuthAuth>;
21
22
  export declare const loadKimiCodingOAuth: () => Promise<OAuthAuth>;
22
23
  export declare const loadXaiOAuth: () => Promise<OAuthAuth>;
23
24
  export declare const loadCursorOAuth: () => Promise<OAuthAuth>;
25
+ export declare const loadDevinOAuth: () => Promise<OAuthAuth>;
24
26
  export declare const loadRadiusOAuth: (options: {
25
27
  name: string;
26
28
  gateway: string;
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/load.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAa7C,KAAK,gBAAgB,GAAG;IACvB,SAAS,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAChD,WAAW,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAClD,aAAa,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACpD,UAAU,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,UAAU,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,GAAG,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7C,MAAM,EAAE,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACvF,CAAC;AAIF,4EAA4E;AAC5E,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAE/E;AAED,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,SAAS,CAG5D,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,SAAS,CAG9D,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAa,OAAO,CAAC,SAAS,CAGhE,CAAC;AAEF,eAAO,M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,4EAA4E;AAC5E,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAE/E;AAED,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,SAAS,CAG5D,CAAC;AAEF,eAAO,MAAM,oBAAoB,QAAa,OAAO,CAAC,SAAS,CAG9D,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAa,OAAO,CAAC,SAAS,CAGhE,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAAC,SAAS,CAG7D,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAAC,SAAS,CAG7D,CAAC;AAEF,eAAO,MAAM,YAAY,QAAa,OAAO,CAAC,SAAS,CAGtD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAa,OAAO,CAAC,SAAS,CAGzD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,SAAS,CAGxD,CAAC;AAEF,eAAO,MAAM,eAAe,YAAmB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KAAG,OAAO,CAAC,SAAS,CAOnG,CAAC"}
@@ -56,6 +56,11 @@ export const loadCursorOAuth = async () => {
56
56
  return bundledLoaders.cursor();
57
57
  return (await importOAuthModule("./cursor.ts")).cursorOAuth;
58
58
  };
59
+ export const loadDevinOAuth = async () => {
60
+ if (bundledLoaders)
61
+ return bundledLoaders.devin();
62
+ return (await importOAuthModule("./devin.ts")).devinOAuth;
63
+ };
59
64
  export const loadRadiusOAuth = async (options) => {
60
65
  if (bundledLoaders)
61
66
  return bundledLoaders.radius(options);
@@ -1 +1 @@
1
- {"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/auth/oauth/load.ts"],"names":[],"mappings":";;;;;;;;AAEA;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAoB,EAAE;IACjE,MAAM,gBAAgB,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,Q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E;IACjE,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,UAAU,EAAE,CAAC;IACvD,OAAQ,CAAC,MAAM,iBAAiB,CAAC,kBAAkB,CAAC,CAAoC,CAAC,eAAe,CAAC;AAC1G,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAwB,EAAE;IAC1D,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,GAAG,EAAE,CAAC;IAChD,OAAQ,CAAC,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAA6B,CAAC,QAAQ,CAAC;AACpF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,IAAwB,EAAE;IAC7D,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,MAAM,EAAE,CAAC;IACnD,OAAQ,CAAC,MAAM,iBAAiB,CAAC,aAAa,CAAC,CAAgC,CAAC,WAAW,CAAC;AAC7F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,OAA0C,EAAsB,EAAE;IACvG,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1D,OACC,CAAC,MAAM,iBAAiB,CAAC,aAAa,CAAC,CAGvC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import type { OAuthAuth } from \"../types.ts\";\n\n/**\n * Loads an OAuth flow module through a variable specifier so bundlers cannot\n * follow the import into Node-only flow code (`node:http` callback servers,\n * `node:crypto` PKCE). The `.ts`/`.js` rewrite keeps the trick working from\n * both source and built output.\n */\nconst importOAuthModule = (specifier: string): Promise<unknown> => {\n\tconst runtimeSpecifier = import.meta.url.endsWith(\".js\") ? specifier.replace(/\\.ts$/, \".js\") : specifier;\n\treturn import(runtimeSpecifier);\n};\n\ntype OAuthFlowLoaders = {\n\tanthropic: () => OAuthAuth | Promise<OAuthAuth>;\n\topenaiCodex: () => OAuthAuth | Promise<OAuthAuth>;\n\tgithubCopilot: () => OAuthAuth | Promise<OAuthAuth>;\n\topenrouter: () => OAuthAuth | Promise<OAuthAuth>;\n\tkimiCoding: () => OAuthAuth | Promise<OAuthAuth>;\n\txai: () => OAuthAuth | Promise<OAuthAuth>;\n\tcursor: () => OAuthAuth | Promise<OAuthAuth>;\n\tradius: (options: { name: string; gateway: string }) => OAuthAuth | Promise<OAuthAuth>;\n};\n\nlet bundledLoaders: OAuthFlowLoaders | undefined;\n\n/** Registers statically bundled OAuth flows for standalone Bun binaries. */\nexport function registerBundledOAuthFlowLoaders(loaders: OAuthFlowLoaders): void {\n\tbundledLoaders = loaders;\n}\n\nexport const loadAnthropicOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.anthropic();\n\treturn ((await importOAuthModule(\"./anthropic.ts\")) as { anthropicOAuth: OAuthAuth }).anthropicOAuth;\n};\n\nexport const loadOpenAICodexOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.openaiCodex();\n\treturn ((await importOAuthModule(\"./openai-codex.ts\")) as { openaiCodexOAuth: OAuthAuth }).openaiCodexOAuth;\n};\n\nexport const loadGitHubCopilotOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.githubCopilot();\n\treturn ((await importOAuthModule(\"./github-copilot.ts\")) as { githubCopilotOAuth: OAuthAuth }).githubCopilotOAuth;\n};\n\nexport const loadOpenRouterOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.openrouter();\n\treturn ((await importOAuthModule(\"./openrouter.ts\")) as { openRouterOAuth: OAuthAuth }).openRouterOAuth;\n};\n\nexport const loadKimiCodingOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.kimiCoding();\n\treturn ((await importOAuthModule(\"./kimi-coding.ts\")) as { kimiCodingOAuth: OAuthAuth }).kimiCodingOAuth;\n};\n\nexport const loadXaiOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.xai();\n\treturn ((await importOAuthModule(\"./xai.ts\")) as { xaiOAuth: OAuthAuth }).xaiOAuth;\n};\n\nexport const loadCursorOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.cursor();\n\treturn ((await importOAuthModule(\"./cursor.ts\")) as { cursorOAuth: OAuthAuth }).cursorOAuth;\n};\n\nexport const loadRadiusOAuth = async (options: { name: string; gateway: string }): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.radius(options);\n\treturn (\n\t\t(await importOAuthModule(\"./radius.ts\")) as {\n\t\t\tcreateRadiusOAuth: (input: { name: string; gateway: string }) => OAuthAuth;\n\t\t}\n\t).createRadiusOAuth(options);\n};\n"]}
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../../../src/auth/oauth/load.ts"],"names":[],"mappings":";;;;;;;;AAEA;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAoB,EAAE;IACjE,MAAM,gBAAgB,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzG,OAAO,MAAM,kCAAC,gBAAgB,EAAC,CAAC;AACjC,CAAC,CAAC;AAcF,IAAI,cAA4C,CAAC;AAEjD,4EAA4E;AAC5E,MAAM,UAAU,+BAA+B,CAAC,OAAyB;IACxE,cAAc,GAAG,OAAO,CAAC;AAC1B,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAwB,EAAE;IAChE,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,SAAS,EAAE,CAAC;IACtD,OAAQ,CAAC,MAAM,iBAAiB,CAAC,gBAAgB,CAAC,CAAmC,CAAC,cAAc,CAAC;AACtG,CAAC,CAAC;AAEF,MAAM,CAA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AC,CAAgC,CAAC,WAAW,CAAC;AAC7F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAAwB,EAAE;IAC5D,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,KAAK,EAAE,CAAC;IAClD,OAAQ,CAAC,MAAM,iBAAiB,CAAC,YAAY,CAAC,CAA+B,CAAC,UAAU,CAAC;AAC1F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,OAA0C,EAAsB,EAAE;IACvG,IAAI,cAAc;QAAE,OAAO,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1D,OACC,CAAC,MAAM,iBAAiB,CAAC,aAAa,CAAC,CAGvC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import type { OAuthAuth } from \"../types.ts\";\n\n/**\n * Loads an OAuth flow module through a variable specifier so bundlers cannot\n * follow the import into Node-only flow code (`node:http` callback servers,\n * `node:crypto` PKCE). The `.ts`/`.js` rewrite keeps the trick working from\n * both source and built output.\n */\nconst importOAuthModule = (specifier: string): Promise<unknown> => {\n\tconst runtimeSpecifier = import.meta.url.endsWith(\".js\") ? specifier.replace(/\\.ts$/, \".js\") : specifier;\n\treturn import(runtimeSpecifier);\n};\n\ntype OAuthFlowLoaders = {\n\tanthropic: () => OAuthAuth | Promise<OAuthAuth>;\n\topenaiCodex: () => OAuthAuth | Promise<OAuthAuth>;\n\tgithubCopilot: () => OAuthAuth | Promise<OAuthAuth>;\n\topenrouter: () => OAuthAuth | Promise<OAuthAuth>;\n\tkimiCoding: () => OAuthAuth | Promise<OAuthAuth>;\n\txai: () => OAuthAuth | Promise<OAuthAuth>;\n\tcursor: () => OAuthAuth | Promise<OAuthAuth>;\n\tdevin: () => OAuthAuth | Promise<OAuthAuth>;\n\tradius: (options: { name: string; gateway: string }) => OAuthAuth | Promise<OAuthAuth>;\n};\n\nlet bundledLoaders: OAuthFlowLoaders | undefined;\n\n/** Registers statically bundled OAuth flows for standalone Bun binaries. */\nexport function registerBundledOAuthFlowLoaders(loaders: OAuthFlowLoaders): void {\n\tbundledLoaders = loaders;\n}\n\nexport const loadAnthropicOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.anthropic();\n\treturn ((await importOAuthModule(\"./anthropic.ts\")) as { anthropicOAuth: OAuthAuth }).anthropicOAuth;\n};\n\nexport const loadOpenAICodexOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.openaiCodex();\n\treturn ((await importOAuthModule(\"./openai-codex.ts\")) as { openaiCodexOAuth: OAuthAuth }).openaiCodexOAuth;\n};\n\nexport const loadGitHubCopilotOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.githubCopilot();\n\treturn ((await importOAuthModule(\"./github-copilot.ts\")) as { githubCopilotOAuth: OAuthAuth }).githubCopilotOAuth;\n};\n\nexport const loadOpenRouterOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.openrouter();\n\treturn ((await importOAuthModule(\"./openrouter.ts\")) as { openRouterOAuth: OAuthAuth }).openRouterOAuth;\n};\n\nexport const loadKimiCodingOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.kimiCoding();\n\treturn ((await importOAuthModule(\"./kimi-coding.ts\")) as { kimiCodingOAuth: OAuthAuth }).kimiCodingOAuth;\n};\n\nexport const loadXaiOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.xai();\n\treturn ((await importOAuthModule(\"./xai.ts\")) as { xaiOAuth: OAuthAuth }).xaiOAuth;\n};\n\nexport const loadCursorOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.cursor();\n\treturn ((await importOAuthModule(\"./cursor.ts\")) as { cursorOAuth: OAuthAuth }).cursorOAuth;\n};\n\nexport const loadDevinOAuth = async (): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.devin();\n\treturn ((await importOAuthModule(\"./devin.ts\")) as { devinOAuth: OAuthAuth }).devinOAuth;\n};\n\nexport const loadRadiusOAuth = async (options: { name: string; gateway: string }): Promise<OAuthAuth> => {\n\tif (bundledLoaders) return bundledLoaders.radius(options);\n\treturn (\n\t\t(await importOAuthModule(\"./radius.ts\")) as {\n\t\t\tcreateRadiusOAuth: (input: { name: string; gateway: string }) => OAuthAuth;\n\t\t}\n\t).createRadiusOAuth(options);\n};\n"]}
@@ -3,7 +3,10 @@ export type { Credential };
3
3
  export declare const DEFAULT_SLOT_NAME = "default";
4
4
  export type CredentialSlotSource = "login" | "import" | "env";
5
5
  export type CredentialSlot = {
6
+ /** Immutable operational identity. */
6
7
  name: string;
8
+ /** Optional presentation metadata; never used for credential selection. */
9
+ displayName?: string;
7
10
  source?: CredentialSlotSource;
8
11
  key?: string;
9
12
  access?: string;
@@ -15,6 +18,23 @@ export type PooledCredential = Credential & {
15
18
  pinned?: string;
16
19
  };
17
20
  export declare function assertValidSlotName(name: string): void;
21
+ /**
22
+ * Labels are bounded in terminal columns, not UTF-16 code units: 80 code units
23
+ * of CJK render ~170 columns, which no footer segment can hold, while 41 emoji
24
+ * render 82 columns yet count 82 code units. The bound is what the footer's
25
+ * parenthesised provider segment can carry alongside a provider id.
26
+ */
27
+ export declare const DISPLAY_NAME_MAX_COLUMNS = 32;
28
+ /** Terminal columns a label occupies, measured per grapheme cluster. */
29
+ export declare function displayNameColumns(value: string): number;
30
+ /** Treat persisted metadata as untrusted presentation input. */
31
+ export declare function accountDisplayName(value: unknown): string | undefined;
32
+ export declare function accountLabel(account: {
33
+ name: string;
34
+ displayName?: string;
35
+ }): string;
36
+ /** Pure metadata update; callers serialize this against the latest stored credential. */
37
+ export declare function renameSlotDisplayName(credential: PooledCredential, name: string, value: string | null): PooledCredential;
18
38
  /**
19
39
  * A flat credential written by a build predating pools is read as a one-slot pool
20
40
  * without writing anything back; the caller decides whether a write ever happens.
@@ -54,11 +74,38 @@ export declare function projectSlot(credential: PooledCredential | undefined, na
54
74
  * instead of being overwritten by the second login.
55
75
  *
56
76
  * A login result that already carries its own populated `accounts` array is a
57
- * provider-owned pool: it IS the complete post-login credential, so it is
58
- * written through untouched. Reading its top-level fields as a flat credential
59
- * would append the provider's placeholder material as a second slot.
77
+ * provider-owned pool, and a provider that already holds a POOL names the
78
+ * account this login created itself. That pool is MERGED onto `current` rather
79
+ * than written through: a pre-browser-flow snapshot must never overwrite what
80
+ * concurrent writers stored meanwhile. A flat `current` keeps the whole-write
81
+ * shape - the provider echoes the flat fields it read, so there is nothing to
82
+ * preserve and the login must not be dropped on a name collision.
83
+ *
84
+ * `onAllocated` reports the account this login committed, so a caller can name
85
+ * it in a receipt without re-reading storage.
86
+ */
87
+ export declare function appendLoginSlot(current: PooledCredential | undefined, flat: Credential, onAllocated?: (name: string, origin: "generated" | "provider") => void): Credential;
88
+ /**
89
+ * Material a provider writes into the flat credential when the real token lives
90
+ * outside auth.json (an SDK subprocess or a vendor CLI owns it): the literal
91
+ * `<providerId>-managed` in both OAuth fields. It is a marker, never a token.
92
+ */
93
+ export declare function managedSentinelMaterial(providerId: string): string;
94
+ /**
95
+ * A POOL SLOT carrying that marker can never authenticate: `projectSlot` hands
96
+ * it to the provider's `check`, which rejects it, and the request dies with
97
+ * "Provider is not configured". Slots like that exist only because a shipped
98
+ * build appended a provider-owned pool's flat sentinel as a generated `login-N`
99
+ * slot.
100
+ */
101
+ export declare function isManagedSentinelSlot(providerId: string, slot: CredentialSlot): boolean;
102
+ /**
103
+ * Drops those poisoned slots from a stored credential, clearing a pin that
104
+ * named one. Returns `undefined` when the credential holds none, so a caller
105
+ * can tell a repair from a no-op and only rewrite storage when the bytes
106
+ * actually change.
60
107
  */
61
- export declare function appendLoginSlot(current: PooledCredential | undefined, flat: Credential): Credential;
108
+ export declare function repairManagedSentinelSlots(providerId: string, credential: Credential): PooledCredential | undefined;
62
109
  /**
63
110
  * Merges a rotated OAuth credential back into the pool: the slot whose material
64
111
  * matches the pre-refresh flat fields is updated in place together with those
@@ -1 +1 @@
1
- {"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAC3C,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAMtD;AAmBD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,GAAG,cAAc,EAAE,CAIpF;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAE3G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,EAAE,IAAI,EAAE,cAAc,GAAG,gBAAgB,CAc3G;AAiBD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAA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AgB,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAGpF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAU1G;AA+CD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,gBAAgB,GAAG,SAAS,EACrC,IAAI,EAAE,UAAU,EAChB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,UAAU,KAAK,IAAI,GACpE,UAAU,CA2BZ;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAGvF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAQnH;AAED;;;;;GAKG;AACH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAS7G;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,GAAG,UAAU,CAe3F"}
@@ -5,6 +5,117 @@ export function assertValidSlotName(name) {
5
5
  throw new Error(`Invalid account name '${name}': use letters, digits, '-' or '_', starting with a letter or digit`);
6
6
  }
7
7
  }
8
+ const UNSAFE_DISPLAY_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
9
+ /**
10
+ * Labels are bounded in terminal columns, not UTF-16 code units: 80 code units
11
+ * of CJK render ~170 columns, which no footer segment can hold, while 41 emoji
12
+ * render 82 columns yet count 82 code units. The bound is what the footer's
13
+ * parenthesised provider segment can carry alongside a provider id.
14
+ */
15
+ export const DISPLAY_NAME_MAX_COLUMNS = 32;
16
+ /** Code points that advance a cell without painting anything a user can see. */
17
+ const BLANK_DISPLAY_CHARACTER = /^[\s\p{M}\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]$/u;
18
+ /** Invisible code points that are not whitespace, so trimming never removes them. */
19
+ const INVISIBLE_DISPLAY_CHARACTER = /^[\p{M}\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]$/u;
20
+ const WIDE_DISPLAY_CHARACTER = /^(?:[\u1100-\u115f\u2329\u232a\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\ua960-\ua97f\uac00-\ud7a3\uf900-\ufaff\ufe10-\ufe19\ufe30-\ufe6f\uff00-\uff60\uffe0-\uffe6]|[\u{1f300}-\u{1faff}]|[\u{20000}-\u{3fffd}])$/u;
21
+ /**
22
+ * Latin lookalikes for the Cyrillic letters a homoglyph label would use. Folded
23
+ * only for the uniqueness comparison; the stored label keeps the user's script.
24
+ */
25
+ const CYRILLIC_LOOKALIKES = {
26
+ "\u0430": "a",
27
+ "\u0432": "b",
28
+ "\u0435": "e",
29
+ "\u043a": "k",
30
+ "\u043c": "m",
31
+ "\u043d": "h",
32
+ "\u043e": "o",
33
+ "\u0440": "p",
34
+ "\u0441": "c",
35
+ "\u0442": "t",
36
+ "\u0443": "y",
37
+ "\u0445": "x",
38
+ "\u0455": "s",
39
+ "\u0456": "i",
40
+ "\u0458": "j",
41
+ };
42
+ const displayNameGraphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
43
+ /** Terminal columns a label occupies, measured per grapheme cluster. */
44
+ export function displayNameColumns(value) {
45
+ let columns = 0;
46
+ for (const { segment } of displayNameGraphemes.segment(value)) {
47
+ const codePoint = segment.codePointAt(0);
48
+ if (codePoint === undefined)
49
+ continue;
50
+ const base = String.fromCodePoint(codePoint);
51
+ if (INVISIBLE_DISPLAY_CHARACTER.test(base))
52
+ continue;
53
+ columns += WIDE_DISPLAY_CHARACTER.test(base) || segment.includes("\ufe0f") ? 2 : 1;
54
+ }
55
+ return columns;
56
+ }
57
+ /** The stored form: NFC, trimmed, internal whitespace runs collapsed to one space. */
58
+ function normalizeDisplayName(value) {
59
+ return value.normalize("NFC").trim().replace(/\s+/gu, " ");
60
+ }
61
+ /**
62
+ * Comparison key for "unique per provider": compatibility-folded (fullwidth and
63
+ * other compatibility forms), case-folded, invisible code points dropped, and
64
+ * Cyrillic lookalikes mapped to Latin, so two labels that render identically
65
+ * cannot both be stored.
66
+ */
67
+ function displayNameKey(value) {
68
+ return [...normalizeDisplayName(value).normalize("NFKC").toLowerCase()]
69
+ .filter((character) => !INVISIBLE_DISPLAY_CHARACTER.test(character))
70
+ .map((character) => CYRILLIC_LOOKALIKES[character] ?? character)
71
+ .join("");
72
+ }
73
+ /** Treat persisted metadata as untrusted presentation input. */
74
+ export function accountDisplayName(value) {
75
+ if (typeof value !== "string" || UNSAFE_DISPLAY_CHARACTERS.test(value))
76
+ return undefined;
77
+ const normalized = normalizeDisplayName(value);
78
+ const characters = [...normalized];
79
+ // A leading combining mark glues the label onto whatever precedes it, and a
80
+ // label made only of blank-rendering code points is indistinguishable from none.
81
+ if (characters.length === 0 || /^\p{M}$/u.test(characters[0]))
82
+ return undefined;
83
+ if (characters.every((character) => BLANK_DISPLAY_CHARACTER.test(character)))
84
+ return undefined;
85
+ return displayNameColumns(normalized) <= DISPLAY_NAME_MAX_COLUMNS ? normalized : undefined;
86
+ }
87
+ export function accountLabel(account) {
88
+ const displayName = accountDisplayName(account.displayName);
89
+ return displayName === undefined ? account.name : `${displayName} (${account.name})`;
90
+ }
91
+ /** Pure metadata update; callers serialize this against the latest stored credential. */
92
+ export function renameSlotDisplayName(credential, name, value) {
93
+ assertValidSlotName(name);
94
+ const accounts = Array.isArray(credential.accounts) ? credential.accounts : listSlots(credential);
95
+ const target = accounts.find((slot) => slot.name === name);
96
+ if (!target)
97
+ throw new Error(`Stored provider account not found: ${name}`);
98
+ if (target.source === "env")
99
+ throw new Error(`Environment provider account cannot be renamed: ${name}`);
100
+ const displayName = value === null ? undefined : accountDisplayName(value);
101
+ if (value !== null && displayName === undefined) {
102
+ throw new Error(`Display name must be 1-${DISPLAY_NAME_MAX_COLUMNS} terminal columns of visible text without control or formatting characters.`);
103
+ }
104
+ if (displayName !== undefined &&
105
+ accounts.some((slot) => slot.name !== name &&
106
+ displayNameKey(accountDisplayName(slot.displayName) ?? "") === displayNameKey(displayName))) {
107
+ throw new Error("Display name is already used by another account for this provider.");
108
+ }
109
+ return {
110
+ ...credential,
111
+ accounts: accounts.map((slot) => {
112
+ if (slot.name !== name)
113
+ return slot;
114
+ const { displayName: _displayName, ...unchanged } = slot;
115
+ return displayName === undefined ? unchanged : { ...unchanged, displayName };
116
+ }),
117
+ };
118
+ }
8
119
  function storedSlots(credential) {
9
120
  return Array.isArray(credential.accounts) ? credential.accounts : [];
10
121
  }
@@ -136,6 +247,23 @@ function nextLoginSlotName(credential) {
136
247
  }
137
248
  throw new Error("Credential pool is full");
138
249
  }
250
+ function providedSlots(credential) {
251
+ const accounts = credential.accounts;
252
+ return Array.isArray(accounts) && accounts.length > 0 ? accounts : undefined;
253
+ }
254
+ /**
255
+ * Unions a provider-owned pool onto the value read under the credential lock.
256
+ * `current` wins for every name it already holds: the provider built its
257
+ * object from a snapshot taken BEFORE the interactive browser round trip, so a
258
+ * sibling account that rotated its refresh token or earned a rate-limit block
259
+ * during that window must not be rewound to the snapshot. Only names that do
260
+ * not exist yet are appended.
261
+ */
262
+ function mergeProvidedPool(current, existing, provided) {
263
+ const known = new Set(existing.map((slot) => slot.name));
264
+ const added = provided.filter((slot) => !known.has(slot.name));
265
+ return added.length === 0 ? current : { ...current, accounts: [...existing, ...added] };
266
+ }
139
267
  /**
140
268
  * Appends an unnamed flat credential to a pool as a generated `login-N` slot.
141
269
  * An absent current entry keeps today's whole-write shape; a flat current entry
@@ -143,18 +271,79 @@ function nextLoginSlotName(credential) {
143
271
  * instead of being overwritten by the second login.
144
272
  *
145
273
  * A login result that already carries its own populated `accounts` array is a
146
- * provider-owned pool: it IS the complete post-login credential, so it is
147
- * written through untouched. Reading its top-level fields as a flat credential
148
- * would append the provider's placeholder material as a second slot.
274
+ * provider-owned pool, and a provider that already holds a POOL names the
275
+ * account this login created itself. That pool is MERGED onto `current` rather
276
+ * than written through: a pre-browser-flow snapshot must never overwrite what
277
+ * concurrent writers stored meanwhile. A flat `current` keeps the whole-write
278
+ * shape - the provider echoes the flat fields it read, so there is nothing to
279
+ * preserve and the login must not be dropped on a name collision.
280
+ *
281
+ * `onAllocated` reports the account this login committed, so a caller can name
282
+ * it in a receipt without re-reading storage.
149
283
  */
150
- export function appendLoginSlot(current, flat) {
151
- if ("accounts" in flat && Array.isArray(flat.accounts) && flat.accounts.length > 0) {
152
- return flat;
284
+ export function appendLoginSlot(current, flat, onAllocated) {
285
+ const provided = providedSlots(flat);
286
+ if (provided) {
287
+ // Provider-owned envelopes identify an addition by immutable ID, never by
288
+ // token equality or array position. Ambiguous envelopes have no receipt.
289
+ const previous = new Set((current && Array.isArray(current.accounts) ? current.accounts : listSlots(current)).map((slot) => slot.name));
290
+ const added = provided.filter((slot) => !previous.has(slot.name));
291
+ if (added.length === 1 && SLOT_NAME_PATTERN.test(added[0].name) && added[0].source !== "env") {
292
+ onAllocated?.(added[0].name, "provider");
293
+ }
153
294
  }
154
295
  if (!current) {
296
+ if (!provided)
297
+ onAllocated?.(DEFAULT_SLOT_NAME, "generated");
155
298
  return flat;
156
299
  }
157
- return upsertSlot(current, slotFromFlatCredentialNamed(flat, nextLoginSlotName(current)));
300
+ const storedAccounts = Array.isArray(current.accounts) ? current.accounts : undefined;
301
+ if (provided) {
302
+ // A pool merges onto the stored pool; a flat current keeps the whole-write
303
+ // shape because the provider's accounts already carry this login.
304
+ return storedAccounts ? mergeProvidedPool(current, storedAccounts, provided) : flat;
305
+ }
306
+ const name = nextLoginSlotName(current);
307
+ const next = upsertSlot(current, slotFromFlatCredentialNamed(flat, name));
308
+ onAllocated?.(name, "generated");
309
+ return next;
310
+ }
311
+ /**
312
+ * Material a provider writes into the flat credential when the real token lives
313
+ * outside auth.json (an SDK subprocess or a vendor CLI owns it): the literal
314
+ * `<providerId>-managed` in both OAuth fields. It is a marker, never a token.
315
+ */
316
+ export function managedSentinelMaterial(providerId) {
317
+ return `${providerId}-managed`;
318
+ }
319
+ /**
320
+ * A POOL SLOT carrying that marker can never authenticate: `projectSlot` hands
321
+ * it to the provider's `check`, which rejects it, and the request dies with
322
+ * "Provider is not configured". Slots like that exist only because a shipped
323
+ * build appended a provider-owned pool's flat sentinel as a generated `login-N`
324
+ * slot.
325
+ */
326
+ export function isManagedSentinelSlot(providerId, slot) {
327
+ const sentinel = managedSentinelMaterial(providerId);
328
+ return slot.access === sentinel && slot.refresh === sentinel;
329
+ }
330
+ /**
331
+ * Drops those poisoned slots from a stored credential, clearing a pin that
332
+ * named one. Returns `undefined` when the credential holds none, so a caller
333
+ * can tell a repair from a no-op and only rewrite storage when the bytes
334
+ * actually change.
335
+ */
336
+ export function repairManagedSentinelSlots(providerId, credential) {
337
+ const pooled = credential;
338
+ if (!Array.isArray(pooled.accounts))
339
+ return undefined;
340
+ const kept = pooled.accounts.filter((slot) => !isManagedSentinelSlot(providerId, slot));
341
+ if (kept.length === pooled.accounts.length)
342
+ return undefined;
343
+ const repaired = { ...pooled, accounts: kept };
344
+ if (repaired.pinned !== undefined && !kept.some((slot) => slot.name === repaired.pinned))
345
+ delete repaired.pinned;
346
+ return repaired;
158
347
  }
159
348
  /**
160
349
  * Merges a rotated OAuth credential back into the pool: the slot whose material