@cjhyy/code-shell 0.1.0-alpha.1 → 0.1.0-alpha.3

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 (275) hide show
  1. package/README.md +8 -0
  2. package/dist/anthropic-P5VETAFI.cjs +10 -0
  3. package/dist/{anthropic-NENYS535.js → anthropic-W2GU3D76.js} +3 -2
  4. package/dist/arena/context/context-tools.d.ts +1 -1
  5. package/dist/arena/index.cjs +4 -4
  6. package/dist/arena/index.js +3 -3
  7. package/dist/arena/providers/index.d.ts +19 -3
  8. package/dist/arena/strategies/utils.d.ts +6 -1
  9. package/dist/arena/types.d.ts +10 -1
  10. package/dist/{arena-46QQ6BZQ.js → arena-ENHBHB2W.js} +5 -7
  11. package/dist/{arena-HZZZ2GJH.cjs → arena-HHDYYVHJ.cjs} +19 -21
  12. package/dist/{chunk-BE6IPRDM.js → chunk-2EUAE7AY.js} +1 -1
  13. package/dist/{chunk-WYKNZ54E.cjs → chunk-3CAZIWUA.cjs} +6 -6
  14. package/dist/{chunk-J5XW6UYL.js → chunk-5C5HIOML.js} +63 -4
  15. package/dist/chunk-75E4BBFC.js +224 -0
  16. package/dist/chunk-BF4LXLQV.cjs +4753 -0
  17. package/dist/{chunk-ZJV3YSY3.cjs → chunk-BUJ5KYCI.cjs} +53 -11
  18. package/dist/{chunk-BMH65OVB.cjs → chunk-C7C7ZZY4.cjs} +8 -8
  19. package/dist/{chunk-KO2FPF7G.js → chunk-F5BS3GUC.js} +20 -2
  20. package/dist/chunk-FPFTIKEJ.js +4753 -0
  21. package/dist/chunk-FV2ARONZ.cjs +224 -0
  22. package/dist/{chunk-DICG4AB7.cjs → chunk-GZBD6QRS.cjs} +42 -3
  23. package/dist/{chunk-FVP7XJGS.cjs → chunk-HOXQLX5R.cjs} +406 -196
  24. package/dist/{chunk-4PKZPFCD.js → chunk-I57ZD5IQ.js} +47 -14
  25. package/dist/{chunk-JUHRV2XF.js → chunk-ID6EJUHP.js} +1703 -438
  26. package/dist/chunk-JHNCK7JP.cjs +202 -0
  27. package/dist/{chunk-MOILS4WE.cjs → chunk-JHXNOB5G.cjs} +3 -3
  28. package/dist/{chunk-UK2SU23S.cjs → chunk-KOGV6PDQ.cjs} +20 -2
  29. package/dist/{chunk-VKGNCYRL.js → chunk-LMEKCQX4.js} +95 -13
  30. package/dist/{chunk-3EAEC566.cjs → chunk-M2QI5X3X.cjs} +51 -18
  31. package/dist/{chunk-YZ25SSWJ.js → chunk-M2SVOKC6.js} +46 -4
  32. package/dist/{chunk-NG73UR3L.cjs → chunk-OP57WUWQ.cjs} +23 -1
  33. package/dist/{chunk-ZXYDDJEJ.js → chunk-OUC2DFA7.js} +2 -2
  34. package/dist/{chunk-AP5F6VYE.js → chunk-REFCCVDM.js} +1 -1
  35. package/dist/{chunk-O6F2EF2Z.js → chunk-SCDKLTN3.js} +41 -2
  36. package/dist/{chunk-FECTK5KJ.js → chunk-SW3L7HIM.js} +1 -1
  37. package/dist/chunk-TDXBHD24.js +54 -0
  38. package/dist/chunk-VIPLU4RY.cjs +54 -0
  39. package/dist/{chunk-Q6BYFYGD.cjs → chunk-VWFET3MG.cjs} +1886 -621
  40. package/dist/{chunk-3EUDE77E.cjs → chunk-X2DNIMPC.cjs} +19 -19
  41. package/dist/{chunk-SQZHPD3S.js → chunk-Y7TSCDF6.js} +297 -87
  42. package/dist/{chunk-WHRTARDJ.cjs → chunk-YAFCN7ZW.cjs} +112 -30
  43. package/dist/{chunk-LRAY5IYC.cjs → chunk-YD7XTI7T.cjs} +65 -6
  44. package/dist/{chunk-S74VVJBF.js → chunk-ZLPJJZUW.js} +23 -1
  45. package/dist/chunk-ZRVPCXI7.js +202 -0
  46. package/dist/cli/commands/builtin/advanced-commands.d.ts +1 -1
  47. package/dist/cli/commands/builtin/extra-commands.d.ts +2 -2
  48. package/dist/cli/commands/builtin/more-commands.d.ts +1 -3
  49. package/dist/cli/commands/registry.d.ts +8 -0
  50. package/dist/cli/cost-tracker.d.ts +6 -0
  51. package/dist/cli/main.cjs +3556 -1995
  52. package/dist/cli/main.js +3658 -2097
  53. package/dist/cli/onboarding.d.ts +67 -14
  54. package/dist/client-base-TOVE25FA.js +9 -0
  55. package/dist/client-base-VDDIADAC.cjs +9 -0
  56. package/dist/compaction-D3KV2NWY.cjs +31 -0
  57. package/dist/{compaction-CCHWA4G6.js → compaction-YNWCEF7B.js} +1 -2
  58. package/dist/context/manager.d.ts +9 -0
  59. package/dist/data/openrouter-models.d.ts +35 -0
  60. package/dist/data/openrouter-sync.d.ts +16 -0
  61. package/dist/{devtools-KIY3LWQJ.js → devtools-IRQQPIRY.js} +1 -1
  62. package/dist/{devtools-LRP47DDV.cjs → devtools-WTC3NFNE.cjs} +1 -1
  63. package/dist/engine/engine.d.ts +29 -6
  64. package/dist/engine/turn-loop.d.ts +7 -0
  65. package/dist/engine/turn-state.d.ts +6 -0
  66. package/dist/index.cjs +19 -28
  67. package/dist/index.js +28 -37
  68. package/dist/llm/client-base.d.ts +7 -0
  69. package/dist/llm/model-pool.d.ts +4 -0
  70. package/dist/logging/logger.d.ts +69 -8
  71. package/dist/manager-FWLOVEEK.cjs +7 -0
  72. package/dist/manager-GEXJLOIS.js +7 -0
  73. package/dist/{mcp-manager-OKXHHWYR.js → mcp-manager-37GQLFGX.js} +2 -2
  74. package/dist/mcp-manager-U77NEXBY.cjs +8 -0
  75. package/dist/memory-ADGOWADP.cjs +9 -0
  76. package/dist/memory-EPFDBPII.js +9 -0
  77. package/dist/native-ts/yoga-layout/index.d.ts +2 -2
  78. package/dist/{openai-5HQGBL4L.js → openai-RXU5URYI.js} +3 -2
  79. package/dist/openai-SQW4H2K4.cjs +10 -0
  80. package/dist/openrouter-models-2FM3H4SQ.js +15 -0
  81. package/dist/openrouter-models-PLCWZZYE.cjs +15 -0
  82. package/dist/openrouter-sync-K2WK3A2A.cjs +11 -0
  83. package/dist/openrouter-sync-SO3AWEAM.js +11 -0
  84. package/dist/product/index.cjs +12 -16
  85. package/dist/product/index.js +11 -15
  86. package/dist/protocol/types.d.ts +11 -3
  87. package/dist/{ink → render}/hooks/use-input.d.ts +1 -1
  88. package/dist/run/index.cjs +12 -16
  89. package/dist/run/index.js +11 -15
  90. package/dist/session/memory.d.ts +23 -3
  91. package/dist/session/session-manager.d.ts +4 -1
  92. package/dist/{session-manager-UQKB564H.cjs → session-manager-HRSKENKB.cjs} +2 -2
  93. package/dist/{session-manager-JIIBCFTC.js → session-manager-NEKFEHF3.js} +1 -1
  94. package/dist/settings/manager.d.ts +9 -0
  95. package/dist/settings/schema.d.ts +48 -39
  96. package/dist/{tool-summary-J2ICNMWP.js → tool-summary-2RUFL5QK.js} +1 -1
  97. package/dist/{tool-summary-5P2GKRA4.cjs → tool-summary-RYNR4DDB.cjs} +2 -2
  98. package/dist/tool-system/builtin/agent.d.ts +3 -26
  99. package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
  100. package/dist/tool-system/builtin/apply-patch/index.d.ts +19 -0
  101. package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
  102. package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
  103. package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
  104. package/dist/tool-system/builtin/arena.d.ts +18 -5
  105. package/dist/tool-system/builtin/ask-user.d.ts +6 -6
  106. package/dist/tool-system/builtin/index.d.ts +11 -1
  107. package/dist/tool-system/builtin/tool-search.d.ts +2 -3
  108. package/dist/tool-system/context.d.ts +74 -0
  109. package/dist/tool-system/executor.d.ts +16 -0
  110. package/dist/tool-system/permission.d.ts +40 -5
  111. package/dist/tool-system/registry.d.ts +2 -0
  112. package/dist/types.d.ts +28 -1
  113. package/dist/ui/App.d.ts +1 -1
  114. package/dist/ui/components/AgentBlock.d.ts +1 -1
  115. package/dist/ui/components/AskUserPrompt.d.ts +7 -0
  116. package/dist/ui/components/MessageContent.d.ts +7 -3
  117. package/dist/ui/components/ModelManager.d.ts +35 -0
  118. package/dist/ui/components/ModelSelector.d.ts +10 -0
  119. package/dist/ui/components/OnboardingPrompt.d.ts +7 -0
  120. package/dist/ui/components/PermissionPrompt.d.ts +5 -2
  121. package/dist/ui/components/SessionPicker.d.ts +14 -0
  122. package/dist/ui/components/StatusLine.d.ts +4 -2
  123. package/dist/ui/components/ThemedBox.d.ts +1 -1
  124. package/dist/ui/components/ToolCall.d.ts +8 -1
  125. package/dist/ui/components/WelcomeTips.d.ts +5 -0
  126. package/dist/ui/onboarding-runner.d.ts +2 -0
  127. package/dist/ui/store.d.ts +1 -0
  128. package/dist/{updater-2N6745WR.cjs → updater-J7L7R6BY.cjs} +7 -5
  129. package/dist/{updater-PV7FKSUI.js → updater-LDBNYCAO.js} +7 -5
  130. package/dist/utils/debug.d.ts +17 -33
  131. package/package.json +7 -5
  132. package/scripts/check-node.cjs +21 -0
  133. package/dist/anthropic-XMTTVNSH.cjs +0 -9
  134. package/dist/bridge-4ZRXVWBN.js +0 -98
  135. package/dist/bridge-W476QDFH.cjs +0 -98
  136. package/dist/chunk-4RRUP4MM.js +0 -86
  137. package/dist/chunk-4SFPFHMG.js +0 -132
  138. package/dist/chunk-5LHVI777.cjs +0 -246
  139. package/dist/chunk-6ZIROYXX.js +0 -207
  140. package/dist/chunk-C7JBCO5V.js +0 -80
  141. package/dist/chunk-CSO5EOEP.cjs +0 -132
  142. package/dist/chunk-FGZGCFJX.cjs +0 -207
  143. package/dist/chunk-HD7MT5XU.cjs +0 -86
  144. package/dist/chunk-IMMTBZ33.cjs +0 -63
  145. package/dist/chunk-JT2WSQSR.cjs +0 -335
  146. package/dist/chunk-NZ4DQ72D.cjs +0 -664
  147. package/dist/chunk-OG4MIQJ6.js +0 -335
  148. package/dist/chunk-WRZJUQ5Z.js +0 -664
  149. package/dist/chunk-X4HAERTQ.js +0 -63
  150. package/dist/chunk-XHC2JMEC.cjs +0 -80
  151. package/dist/chunk-ZRSSGYA5.js +0 -246
  152. package/dist/compaction-44I55TLI.cjs +0 -32
  153. package/dist/coordinator-5HY7ALO2.js +0 -7
  154. package/dist/coordinator-INDLPVMF.cjs +0 -7
  155. package/dist/cost-tracker-IWYAUPXH.js +0 -9
  156. package/dist/cost-tracker-JXTJQQWE.cjs +0 -9
  157. package/dist/loader-DXFSUB4R.cjs +0 -91
  158. package/dist/loader-J5UID6CV.js +0 -91
  159. package/dist/manager-ETWDOCHN.cjs +0 -9
  160. package/dist/manager-HGMQNEJB.cjs +0 -11
  161. package/dist/manager-HUAQOORS.js +0 -9
  162. package/dist/manager-VJIZ2CQC.js +0 -11
  163. package/dist/mcp-manager-G4G2QASE.cjs +0 -8
  164. package/dist/memory-AP747G5H.js +0 -7
  165. package/dist/memory-BH3BYUN5.cjs +0 -7
  166. package/dist/onboarding-6WEPV7C2.js +0 -11
  167. package/dist/onboarding-QM5DY2TU.cjs +0 -11
  168. package/dist/openai-656VWUQW.cjs +0 -9
  169. package/dist/skills-63RBYQRX.js +0 -13
  170. package/dist/skills-V3BPLW3D.cjs +0 -13
  171. package/dist/token-counter-CHAXW5O7.cjs +0 -13
  172. package/dist/token-counter-DSOZGZ5Q.js +0 -13
  173. package/dist/utils/log.d.ts +0 -56
  174. package/dist/voice-KTZ7PAGO.js +0 -80
  175. package/dist/voice-KZE25GKB.cjs +0 -80
  176. /package/dist/{ink → render}/Ansi.d.ts +0 -0
  177. /package/dist/{ink → render}/bidi.d.ts +0 -0
  178. /package/dist/{ink → render}/clearTerminal.d.ts +0 -0
  179. /package/dist/{ink → render}/colorize.d.ts +0 -0
  180. /package/dist/{ink → render}/components/AlternateScreen.d.ts +0 -0
  181. /package/dist/{ink → render}/components/App.d.ts +0 -0
  182. /package/dist/{ink → render}/components/AppContext.d.ts +0 -0
  183. /package/dist/{ink → render}/components/Box.d.ts +0 -0
  184. /package/dist/{ink → render}/components/Button.d.ts +0 -0
  185. /package/dist/{ink → render}/components/ClockContext.d.ts +0 -0
  186. /package/dist/{ink → render}/components/CursorDeclarationContext.d.ts +0 -0
  187. /package/dist/{ink → render}/components/ErrorOverview.d.ts +0 -0
  188. /package/dist/{ink → render}/components/Link.d.ts +0 -0
  189. /package/dist/{ink → render}/components/Newline.d.ts +0 -0
  190. /package/dist/{ink → render}/components/NoSelect.d.ts +0 -0
  191. /package/dist/{ink → render}/components/RawAnsi.d.ts +0 -0
  192. /package/dist/{ink → render}/components/ScrollBox.d.ts +0 -0
  193. /package/dist/{ink → render}/components/Spacer.d.ts +0 -0
  194. /package/dist/{ink → render}/components/StdinContext.d.ts +0 -0
  195. /package/dist/{ink → render}/components/TerminalFocusContext.d.ts +0 -0
  196. /package/dist/{ink → render}/components/TerminalSizeContext.d.ts +0 -0
  197. /package/dist/{ink → render}/components/Text.d.ts +0 -0
  198. /package/dist/{ink → render}/constants.d.ts +0 -0
  199. /package/dist/{ink → render}/cursor.d.ts +0 -0
  200. /package/dist/{ink → render}/devtools.d.ts +0 -0
  201. /package/dist/{ink → render}/dom.d.ts +0 -0
  202. /package/dist/{ink → render}/events/click-event.d.ts +0 -0
  203. /package/dist/{ink → render}/events/dispatcher.d.ts +0 -0
  204. /package/dist/{ink → render}/events/emitter.d.ts +0 -0
  205. /package/dist/{ink → render}/events/event-handlers.d.ts +0 -0
  206. /package/dist/{ink → render}/events/event.d.ts +0 -0
  207. /package/dist/{ink → render}/events/focus-event.d.ts +0 -0
  208. /package/dist/{ink → render}/events/input-event.d.ts +0 -0
  209. /package/dist/{ink → render}/events/keyboard-event.d.ts +0 -0
  210. /package/dist/{ink → render}/events/paste-event.d.ts +0 -0
  211. /package/dist/{ink → render}/events/resize-event.d.ts +0 -0
  212. /package/dist/{ink → render}/events/terminal-event.d.ts +0 -0
  213. /package/dist/{ink → render}/events/terminal-focus-event.d.ts +0 -0
  214. /package/dist/{ink → render}/focus.d.ts +0 -0
  215. /package/dist/{ink → render}/frame.d.ts +0 -0
  216. /package/dist/{ink → render}/get-max-width.d.ts +0 -0
  217. /package/dist/{ink → render}/hit-test.d.ts +0 -0
  218. /package/dist/{ink → render}/hooks/use-animation-frame.d.ts +0 -0
  219. /package/dist/{ink → render}/hooks/use-app.d.ts +0 -0
  220. /package/dist/{ink → render}/hooks/use-declared-cursor.d.ts +0 -0
  221. /package/dist/{ink → render}/hooks/use-interval.d.ts +0 -0
  222. /package/dist/{ink → render}/hooks/use-search-highlight.d.ts +0 -0
  223. /package/dist/{ink → render}/hooks/use-selection.d.ts +0 -0
  224. /package/dist/{ink → render}/hooks/use-stdin.d.ts +0 -0
  225. /package/dist/{ink → render}/hooks/use-tab-status.d.ts +0 -0
  226. /package/dist/{ink → render}/hooks/use-terminal-focus.d.ts +0 -0
  227. /package/dist/{ink → render}/hooks/use-terminal-title.d.ts +0 -0
  228. /package/dist/{ink → render}/hooks/use-terminal-viewport.d.ts +0 -0
  229. /package/dist/{ink → render}/index.d.ts +0 -0
  230. /package/dist/{ink → render}/ink.d.ts +0 -0
  231. /package/dist/{ink → render}/instances.d.ts +0 -0
  232. /package/dist/{ink → render}/layout/engine.d.ts +0 -0
  233. /package/dist/{ink → render}/layout/geometry.d.ts +0 -0
  234. /package/dist/{ink → render}/layout/node.d.ts +0 -0
  235. /package/dist/{ink → render}/layout/yoga.d.ts +0 -0
  236. /package/dist/{ink → render}/line-width-cache.d.ts +0 -0
  237. /package/dist/{ink → render}/log-update.d.ts +0 -0
  238. /package/dist/{ink → render}/measure-element.d.ts +0 -0
  239. /package/dist/{ink → render}/measure-text.d.ts +0 -0
  240. /package/dist/{ink → render}/node-cache.d.ts +0 -0
  241. /package/dist/{ink → render}/optimizer.d.ts +0 -0
  242. /package/dist/{ink → render}/output.d.ts +0 -0
  243. /package/dist/{ink → render}/parse-keypress.d.ts +0 -0
  244. /package/dist/{ink → render}/reconciler.d.ts +0 -0
  245. /package/dist/{ink → render}/render-border.d.ts +0 -0
  246. /package/dist/{ink → render}/render-node-to-output.d.ts +0 -0
  247. /package/dist/{ink → render}/render-to-screen.d.ts +0 -0
  248. /package/dist/{ink → render}/renderer.d.ts +0 -0
  249. /package/dist/{ink → render}/root.d.ts +0 -0
  250. /package/dist/{ink → render}/screen.d.ts +0 -0
  251. /package/dist/{ink → render}/searchHighlight.d.ts +0 -0
  252. /package/dist/{ink → render}/selection.d.ts +0 -0
  253. /package/dist/{ink → render}/squash-text-nodes.d.ts +0 -0
  254. /package/dist/{ink → render}/stringWidth.d.ts +0 -0
  255. /package/dist/{ink → render}/styles.d.ts +0 -0
  256. /package/dist/{ink → render}/supports-hyperlinks.d.ts +0 -0
  257. /package/dist/{ink → render}/tabstops.d.ts +0 -0
  258. /package/dist/{ink → render}/terminal-focus-state.d.ts +0 -0
  259. /package/dist/{ink → render}/terminal-querier.d.ts +0 -0
  260. /package/dist/{ink → render}/terminal.d.ts +0 -0
  261. /package/dist/{ink → render}/termio/ansi.d.ts +0 -0
  262. /package/dist/{ink → render}/termio/csi.d.ts +0 -0
  263. /package/dist/{ink → render}/termio/dec.d.ts +0 -0
  264. /package/dist/{ink → render}/termio/esc.d.ts +0 -0
  265. /package/dist/{ink → render}/termio/osc.d.ts +0 -0
  266. /package/dist/{ink → render}/termio/parser.d.ts +0 -0
  267. /package/dist/{ink → render}/termio/sgr.d.ts +0 -0
  268. /package/dist/{ink → render}/termio/tokenize.d.ts +0 -0
  269. /package/dist/{ink → render}/termio/types.d.ts +0 -0
  270. /package/dist/{ink → render}/termio.d.ts +0 -0
  271. /package/dist/{ink → render}/useTerminalNotification.d.ts +0 -0
  272. /package/dist/{ink → render}/warn.d.ts +0 -0
  273. /package/dist/{ink → render}/widest-line.d.ts +0 -0
  274. /package/dist/{ink → render}/wrap-text.d.ts +0 -0
  275. /package/dist/{ink → render}/wrapAnsi.d.ts +0 -0
@@ -1,9 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkZJV3YSY3cjs = require('./chunk-ZJV3YSY3.cjs');
4
- require('./chunk-DICG4AB7.cjs');
5
- require('./chunk-EL2RL5DG.cjs');
6
- require('./chunk-IJSHQGMP.cjs');
7
-
8
-
9
- exports.AnthropicClient = _chunkZJV3YSY3cjs.AnthropicClient;
@@ -1,98 +0,0 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-DI7RDLOS.js";
4
-
5
- // src/remote/bridge.ts
6
- init_esm_shims();
7
- import { spawn } from "child_process";
8
- import { createInterface } from "readline";
9
- var RemoteBridge = class {
10
- constructor(config) {
11
- this.config = config;
12
- }
13
- ssh;
14
- connected = false;
15
- /**
16
- * Connect to the remote host via SSH and start code-shell in NDJSON mode.
17
- */
18
- async connect() {
19
- const sshArgs = this.buildSSHArgs();
20
- const remoteCmd = this.config.remoteCommand ?? "code-shell run --output stream-json";
21
- this.ssh = spawn("ssh", [...sshArgs, remoteCmd], {
22
- stdio: ["pipe", "pipe", "pipe"]
23
- });
24
- return new Promise((resolve, reject) => {
25
- const timer = setTimeout(() => {
26
- reject(new Error("SSH connection timed out"));
27
- this.disconnect();
28
- }, 3e4);
29
- this.ssh.stdout?.once("data", () => {
30
- clearTimeout(timer);
31
- this.connected = true;
32
- resolve();
33
- });
34
- this.ssh.on("error", (err) => {
35
- clearTimeout(timer);
36
- reject(err);
37
- });
38
- this.ssh.on("exit", (code) => {
39
- this.connected = false;
40
- if (!this.connected) {
41
- clearTimeout(timer);
42
- reject(new Error(`SSH exited with code ${code}`));
43
- }
44
- });
45
- });
46
- }
47
- /**
48
- * Send a message to the remote code-shell.
49
- */
50
- send(message) {
51
- if (!this.connected || !this.ssh?.stdin) {
52
- throw new Error("Not connected");
53
- }
54
- this.ssh.stdin.write(JSON.stringify(message) + "\n");
55
- }
56
- /**
57
- * Async iterator for messages from the remote code-shell.
58
- */
59
- async *messages() {
60
- if (!this.ssh?.stdout) return;
61
- const rl = createInterface({ input: this.ssh.stdout, crlfDelay: Infinity });
62
- for await (const line of rl) {
63
- const trimmed = line.trim();
64
- if (!trimmed) continue;
65
- try {
66
- yield JSON.parse(trimmed);
67
- } catch {
68
- }
69
- }
70
- }
71
- /**
72
- * Disconnect from the remote host.
73
- */
74
- disconnect() {
75
- this.connected = false;
76
- if (this.ssh) {
77
- this.ssh.kill();
78
- this.ssh = void 0;
79
- }
80
- }
81
- get isConnected() {
82
- return this.connected;
83
- }
84
- buildSSHArgs() {
85
- const args = ["-T"];
86
- if (this.config.port) args.push("-p", String(this.config.port));
87
- if (this.config.identityFile) args.push("-i", this.config.identityFile);
88
- if (this.config.user) {
89
- args.push(`${this.config.user}@${this.config.host}`);
90
- } else {
91
- args.push(this.config.host);
92
- }
93
- return args;
94
- }
95
- };
96
- export {
97
- RemoteBridge
98
- };
@@ -1,98 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
-
3
- var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
4
-
5
- // src/remote/bridge.ts
6
- _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
7
- var _child_process = require('child_process');
8
- var _readline = require('readline');
9
- var RemoteBridge = (_class = class {
10
- constructor(config) {;_class.prototype.__init.call(this);
11
- this.config = config;
12
- }
13
-
14
- __init() {this.connected = false}
15
- /**
16
- * Connect to the remote host via SSH and start code-shell in NDJSON mode.
17
- */
18
- async connect() {
19
- const sshArgs = this.buildSSHArgs();
20
- const remoteCmd = _nullishCoalesce(this.config.remoteCommand, () => ( "code-shell run --output stream-json"));
21
- this.ssh = _child_process.spawn.call(void 0, "ssh", [...sshArgs, remoteCmd], {
22
- stdio: ["pipe", "pipe", "pipe"]
23
- });
24
- return new Promise((resolve, reject) => {
25
- const timer = setTimeout(() => {
26
- reject(new Error("SSH connection timed out"));
27
- this.disconnect();
28
- }, 3e4);
29
- _optionalChain([this, 'access', _ => _.ssh, 'access', _2 => _2.stdout, 'optionalAccess', _3 => _3.once, 'call', _4 => _4("data", () => {
30
- clearTimeout(timer);
31
- this.connected = true;
32
- resolve();
33
- })]);
34
- this.ssh.on("error", (err) => {
35
- clearTimeout(timer);
36
- reject(err);
37
- });
38
- this.ssh.on("exit", (code) => {
39
- this.connected = false;
40
- if (!this.connected) {
41
- clearTimeout(timer);
42
- reject(new Error(`SSH exited with code ${code}`));
43
- }
44
- });
45
- });
46
- }
47
- /**
48
- * Send a message to the remote code-shell.
49
- */
50
- send(message) {
51
- if (!this.connected || !_optionalChain([this, 'access', _5 => _5.ssh, 'optionalAccess', _6 => _6.stdin])) {
52
- throw new Error("Not connected");
53
- }
54
- this.ssh.stdin.write(JSON.stringify(message) + "\n");
55
- }
56
- /**
57
- * Async iterator for messages from the remote code-shell.
58
- */
59
- async *messages() {
60
- if (!_optionalChain([this, 'access', _7 => _7.ssh, 'optionalAccess', _8 => _8.stdout])) return;
61
- const rl = _readline.createInterface.call(void 0, { input: this.ssh.stdout, crlfDelay: Infinity });
62
- for await (const line of rl) {
63
- const trimmed = line.trim();
64
- if (!trimmed) continue;
65
- try {
66
- yield JSON.parse(trimmed);
67
- } catch (e) {
68
- }
69
- }
70
- }
71
- /**
72
- * Disconnect from the remote host.
73
- */
74
- disconnect() {
75
- this.connected = false;
76
- if (this.ssh) {
77
- this.ssh.kill();
78
- this.ssh = void 0;
79
- }
80
- }
81
- get isConnected() {
82
- return this.connected;
83
- }
84
- buildSSHArgs() {
85
- const args = ["-T"];
86
- if (this.config.port) args.push("-p", String(this.config.port));
87
- if (this.config.identityFile) args.push("-i", this.config.identityFile);
88
- if (this.config.user) {
89
- args.push(`${this.config.user}@${this.config.host}`);
90
- } else {
91
- args.push(this.config.host);
92
- }
93
- return args;
94
- }
95
- }, _class);
96
-
97
-
98
- exports.RemoteBridge = RemoteBridge;
@@ -1,86 +0,0 @@
1
- import {
2
- __esm,
3
- init_esm_shims
4
- } from "./chunk-DI7RDLOS.js";
5
-
6
- // src/context/token-counter.ts
7
- function estimateStringTokens(text) {
8
- if (!text) return 0;
9
- const cjkChars = (text.match(/[\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff\uac00-\ud7af]/g) ?? []).length;
10
- const cjkRatio = cjkChars / text.length;
11
- if (cjkRatio > 0.3) {
12
- const cjkTokens = cjkChars / RATIOS.cjk;
13
- const otherChars = text.length - cjkChars;
14
- const otherTokens = otherChars / RATIOS.english;
15
- return Math.ceil(cjkTokens + otherTokens);
16
- }
17
- const codeIndicators = ["{", "}", "(", ")", ";", "=>", "import ", "function ", "class ", "const "];
18
- const codeScore = codeIndicators.reduce((s, ind) => s + (text.includes(ind) ? 1 : 0), 0);
19
- if (codeScore >= 3) return Math.ceil(text.length / RATIOS.code);
20
- if (text.startsWith("{") || text.startsWith("[")) return Math.ceil(text.length / RATIOS.json);
21
- return Math.ceil(text.length / RATIOS.english);
22
- }
23
- function estimateMessagesTokens(messages) {
24
- let total = 0;
25
- for (const msg of messages) {
26
- total += 4;
27
- if (typeof msg.content === "string") {
28
- total += estimateStringTokens(msg.content);
29
- } else if (Array.isArray(msg.content)) {
30
- for (const block of msg.content) {
31
- total += estimateBlockTokens(block);
32
- }
33
- }
34
- }
35
- return total;
36
- }
37
- function estimateBlockTokens(block) {
38
- let tokens = 2;
39
- if (block.text) tokens += estimateStringTokens(block.text);
40
- if (block.content && typeof block.content === "string") {
41
- tokens += estimateStringTokens(block.content);
42
- }
43
- if (block.input) {
44
- tokens += estimateStringTokens(JSON.stringify(block.input));
45
- }
46
- if (block.name) tokens += estimateStringTokens(block.name);
47
- return tokens;
48
- }
49
- function calculateContextUsage(messages, systemPrompt, maxTokens) {
50
- const systemPromptTokens = estimateStringTokens(systemPrompt);
51
- const messagesTokens = estimateMessagesTokens(messages);
52
- const usedTokens = systemPromptTokens + messagesTokens;
53
- return {
54
- usedTokens,
55
- maxTokens,
56
- usagePercent: usedTokens / maxTokens * 100,
57
- systemPromptTokens,
58
- messagesTokens,
59
- headroom: maxTokens - usedTokens
60
- };
61
- }
62
- var RATIOS;
63
- var init_token_counter = __esm({
64
- "src/context/token-counter.ts"() {
65
- init_esm_shims();
66
- RATIOS = {
67
- english: 4,
68
- // ~4 chars per token for English prose
69
- code: 3.2,
70
- // ~3.2 chars per token for code (more tokens per char)
71
- json: 3.5,
72
- // JSON structures
73
- mixed: 3.6,
74
- // Mixed content (typical for tool results)
75
- cjk: 1.5
76
- // CJK characters: ~1.5 chars per token
77
- };
78
- }
79
- });
80
-
81
- export {
82
- estimateStringTokens,
83
- estimateMessagesTokens,
84
- calculateContextUsage,
85
- init_token_counter
86
- };
@@ -1,132 +0,0 @@
1
- import {
2
- init_esm_shims
3
- } from "./chunk-DI7RDLOS.js";
4
-
5
- // src/skills/index.ts
6
- init_esm_shims();
7
-
8
- // src/skills/scanner.ts
9
- init_esm_shims();
10
- import { existsSync, readdirSync, readFileSync, statSync } from "fs";
11
- import { join, resolve } from "path";
12
- import { homedir } from "os";
13
- function scanSkills(cwd) {
14
- const skills = [];
15
- const seen = /* @__PURE__ */ new Set();
16
- const dirs = [
17
- // Project-level
18
- join(cwd, ".code-shell", "skills"),
19
- join(cwd, ".claude", "skills"),
20
- // User-level
21
- join(homedir(), ".code-shell", "skills"),
22
- join(homedir(), ".claude", "skills")
23
- ];
24
- for (const dir of dirs) {
25
- if (!existsSync(dir)) continue;
26
- try {
27
- const files = readdirSync(dir).filter(
28
- (f) => f.endsWith(".md") && statSync(join(dir, f)).isFile()
29
- );
30
- for (const file of files) {
31
- const filePath = resolve(join(dir, file));
32
- if (seen.has(filePath)) continue;
33
- seen.add(filePath);
34
- const skill = parseSkillFile(filePath);
35
- if (skill) skills.push(skill);
36
- }
37
- } catch {
38
- }
39
- }
40
- return skills;
41
- }
42
- function parseSkillFile(filePath) {
43
- try {
44
- const raw = readFileSync(filePath, "utf-8");
45
- const match = raw.match(/^---\n([\s\S]*?)\n---\n\n?([\s\S]*)$/);
46
- if (!match) return null;
47
- const frontmatter = match[1];
48
- const content = match[2].trim();
49
- const name = extractField(frontmatter, "name");
50
- if (!name) return null;
51
- const description = extractField(frontmatter, "description") ?? "";
52
- const whenToUse = extractField(frontmatter, "when_to_use") ?? "";
53
- const keywords = extractList(frontmatter, "keywords");
54
- const tools = extractList(frontmatter, "tools");
55
- const intents = extractList(frontmatter, "intents");
56
- return {
57
- name,
58
- description,
59
- triggers: { keywords, tools, intents },
60
- whenToUse,
61
- content,
62
- filePath
63
- };
64
- } catch {
65
- return null;
66
- }
67
- }
68
- function extractField(frontmatter, field) {
69
- const match = frontmatter.match(new RegExp(`^${field}:\\s*(.+)$`, "m"));
70
- return match?.[1]?.trim();
71
- }
72
- function extractList(frontmatter, field) {
73
- const match = frontmatter.match(new RegExp(`${field}:\\s*\\[([^\\]]+)\\]`));
74
- if (!match) return [];
75
- return match[1].split(",").map((s) => s.trim().replace(/^['"]|['"]$/g, ""));
76
- }
77
-
78
- // src/skills/matcher.ts
79
- init_esm_shims();
80
- function matchSkillsByInput(skills, input) {
81
- const inputLower = input.toLowerCase();
82
- const results = [];
83
- for (const skill of skills) {
84
- let bestScore = 0;
85
- let matchedBy = "";
86
- if (skill.triggers.keywords) {
87
- for (const kw of skill.triggers.keywords) {
88
- if (inputLower.includes(kw.toLowerCase())) {
89
- const score = kw.length / input.length * 10 + 5;
90
- if (score > bestScore) {
91
- bestScore = score;
92
- matchedBy = "keyword";
93
- }
94
- }
95
- }
96
- }
97
- if (skill.triggers.intents) {
98
- for (const intent of skill.triggers.intents) {
99
- if (inputLower.includes(intent.toLowerCase())) {
100
- const score = 8;
101
- if (score > bestScore) {
102
- bestScore = score;
103
- matchedBy = "intent";
104
- }
105
- }
106
- }
107
- }
108
- if (bestScore > 0) {
109
- results.push({ skill, score: bestScore, matchedBy });
110
- }
111
- }
112
- return results.sort((a, b) => b.score - a.score);
113
- }
114
- function matchSkillsByTool(skills, toolName) {
115
- return skills.filter((s) => s.triggers.tools?.includes(toolName)).map((skill) => ({ skill, score: 10, matchedBy: "tool" }));
116
- }
117
- function buildSkillListing(skills) {
118
- if (skills.length === 0) return "";
119
- const lines = skills.map(
120
- (s) => `- **${s.name}**: ${s.description}${s.whenToUse ? ` \u2014 Use when: ${s.whenToUse}` : ""}`
121
- );
122
- return `# Available Skills
123
-
124
- ${lines.join("\n")}`;
125
- }
126
-
127
- export {
128
- scanSkills,
129
- matchSkillsByInput,
130
- matchSkillsByTool,
131
- buildSkillListing
132
- };
@@ -1,246 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
2
-
3
- var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
4
-
5
- // src/cli/cost-tracker.ts
6
- _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
7
- var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
8
- function pricing(input, output) {
9
- return { input, output, cacheRead: input * 0.1, cacheWrite: input * 1.25 };
10
- }
11
- var MODEL_PRICING = {
12
- // Anthropic (per 1M tokens, USD)
13
- "claude-opus-4.6": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
14
- "claude-opus-4-6": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
15
- // alias
16
- "claude-opus-4.5": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
17
- "claude-opus-4.1": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
18
- "claude-opus-4": { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 },
19
- "claude-sonnet-4.6": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
20
- "claude-sonnet-4-6": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
21
- // alias
22
- "claude-sonnet-4.5": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
23
- "claude-sonnet-4": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
24
- "claude-3.7-sonnet": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
25
- "claude-3-7-sonnet": { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
26
- "claude-3.5-haiku": { input: 0.8, output: 4, cacheRead: 0.08, cacheWrite: 1 },
27
- "claude-haiku-4.5": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
28
- "claude-haiku-4-5": { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 },
29
- // alias
30
- // OpenAI
31
- "gpt-5.4": pricing(5, 20),
32
- "gpt-5.4-mini": pricing(1.5, 6),
33
- "gpt-5.4-pro": pricing(10, 40),
34
- "gpt-5": pricing(5, 20),
35
- "gpt-4o": pricing(2.5, 10),
36
- "gpt-4o-mini": pricing(0.15, 0.6),
37
- "gpt-4.1": pricing(2, 8),
38
- "gpt-4.1-mini": pricing(0.4, 1.6),
39
- "o4-mini": pricing(1.1, 4.4),
40
- "o3": pricing(10, 40),
41
- "o3-mini": pricing(1.1, 4.4),
42
- // Google
43
- "gemini-2.5-pro": pricing(1.25, 10),
44
- "gemini-2.5-pro-preview": pricing(1.25, 10),
45
- "gemini-2.5-flash": pricing(0.15, 0.6),
46
- "gemini-3.1-pro-preview": pricing(2, 10),
47
- "gemini-3-flash-preview": pricing(0.15, 0.6),
48
- "gemini-2.0-flash": pricing(0.1, 0.4),
49
- // DeepSeek
50
- "deepseek-v3.2": pricing(0.14, 0.28),
51
- "deepseek-chat": pricing(0.14, 0.28),
52
- "deepseek-r1": pricing(0.55, 2.19),
53
- "deepseek-reasoner": pricing(0.55, 2.19),
54
- // Qwen
55
- "qwen3-coder": pricing(0.3, 0.6),
56
- "qwen3-235b-a22b": pricing(0.3, 1.2),
57
- "qwen3-30b-a3b": pricing(0.1, 0.3),
58
- "qwen3-max": pricing(0.5, 2),
59
- // Meta
60
- "llama-4-maverick": pricing(0.2, 0.8),
61
- "llama-4-scout": pricing(0.15, 0.4),
62
- // Mistral
63
- "devstral-medium": pricing(0.5, 1.5),
64
- "mistral-large": pricing(2, 6),
65
- "devstral-small": pricing(0.1, 0.3)
66
- };
67
- var DEFAULT_PRICING = pricing(3, 15);
68
- function getCanonicalName(model) {
69
- const slashIdx = model.lastIndexOf("/");
70
- const base = slashIdx >= 0 ? model.slice(slashIdx + 1) : model;
71
- return base.replace(/-\d{8}$/, "");
72
- }
73
- var CostTracker = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
74
- __init() {this.records = []}
75
- __init2() {this.sessionStart = Date.now()}
76
- __init3() {this._hasUnknownModel = false}
77
- record(model, promptTokens, completionTokens, isSubAgent = false, cacheReadTokens = 0, cacheWriteTokens = 0) {
78
- const canonical = getCanonicalName(model);
79
- if (!MODEL_PRICING[canonical] && !MODEL_PRICING[model]) {
80
- this._hasUnknownModel = true;
81
- }
82
- this.records.push({
83
- model: canonical,
84
- promptTokens,
85
- completionTokens,
86
- cacheReadTokens,
87
- cacheWriteTokens,
88
- totalTokens: promptTokens + completionTokens,
89
- timestamp: Date.now(),
90
- isSubAgent
91
- });
92
- }
93
- getTotalTokens() {
94
- let prompt = 0;
95
- let completion = 0;
96
- for (const r of this.records) {
97
- prompt += r.promptTokens;
98
- completion += r.completionTokens;
99
- }
100
- return { prompt, completion, total: prompt + completion };
101
- }
102
- getEstimatedCost() {
103
- let totalCost = 0;
104
- for (const r of this.records) {
105
- const p = _nullishCoalesce(MODEL_PRICING[r.model], () => ( DEFAULT_PRICING));
106
- const uncachedInput = Math.max(0, r.promptTokens - r.cacheReadTokens - r.cacheWriteTokens);
107
- totalCost += uncachedInput / 1e6 * p.input;
108
- totalCost += r.completionTokens / 1e6 * p.output;
109
- totalCost += r.cacheReadTokens / 1e6 * p.cacheRead;
110
- totalCost += r.cacheWriteTokens / 1e6 * p.cacheWrite;
111
- }
112
- return totalCost;
113
- }
114
- getRequestCount() {
115
- return this.records.length;
116
- }
117
- getSessionDuration() {
118
- return Date.now() - this.sessionStart;
119
- }
120
- /** Estimate cost for a specific set of tokens without recording them. */
121
- estimateForTokens(model, promptTokens, completionTokens, cacheReadTokens = 0, cacheWriteTokens = 0) {
122
- const canonical = getCanonicalName(model);
123
- const p = _nullishCoalesce(_nullishCoalesce(MODEL_PRICING[canonical], () => ( MODEL_PRICING[model])), () => ( DEFAULT_PRICING));
124
- const uncachedInput = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
125
- return uncachedInput / 1e6 * p.input + completionTokens / 1e6 * p.output + cacheReadTokens / 1e6 * p.cacheRead + cacheWriteTokens / 1e6 * p.cacheWrite;
126
- }
127
- /**
128
- * Get total cache token counts.
129
- */
130
- getCacheTokens() {
131
- let cacheRead = 0;
132
- let cacheWrite = 0;
133
- for (const r of this.records) {
134
- cacheRead += r.cacheReadTokens;
135
- cacheWrite += r.cacheWriteTokens;
136
- }
137
- return { cacheRead, cacheWrite };
138
- }
139
- /**
140
- * Format a styled cost summary for terminal display.
141
- */
142
- formatSummary() {
143
- const tokens = this.getTotalTokens();
144
- const cache = this.getCacheTokens();
145
- const cost = this.getEstimatedCost();
146
- const requests = this.getRequestCount();
147
- const duration = this.getSessionDuration();
148
- const lines = [];
149
- lines.push(` ${_chalk2.default.bold.cyan("Cost Summary")}`);
150
- lines.push(_chalk2.default.dim(" \u2500".repeat(25)));
151
- lines.push(` ${_chalk2.default.dim("Requests:")} ${_chalk2.default.white(String(requests))}`);
152
- lines.push(` ${_chalk2.default.dim("Input tokens:")} ${_chalk2.default.white(formatNumber(tokens.prompt))}`);
153
- lines.push(` ${_chalk2.default.dim("Output tokens:")} ${_chalk2.default.white(formatNumber(tokens.completion))}`);
154
- if (cache.cacheRead > 0 || cache.cacheWrite > 0) {
155
- lines.push(` ${_chalk2.default.dim("Cache read:")} ${_chalk2.default.white(formatNumber(cache.cacheRead))}`);
156
- lines.push(` ${_chalk2.default.dim("Cache write:")} ${_chalk2.default.white(formatNumber(cache.cacheWrite))}`);
157
- }
158
- lines.push(` ${_chalk2.default.dim("Total cost:")} ${_chalk2.default.green(formatCost(cost))}`);
159
- lines.push(` ${_chalk2.default.dim("Duration:")} ${_chalk2.default.white(formatDuration(duration))}`);
160
- const modelMap = /* @__PURE__ */ new Map();
161
- for (const r of this.records) {
162
- const existing = _nullishCoalesce(modelMap.get(r.model), () => ( { prompt: 0, completion: 0, cacheRead: 0, cacheWrite: 0, count: 0 }));
163
- existing.prompt += r.promptTokens;
164
- existing.completion += r.completionTokens;
165
- existing.cacheRead += r.cacheReadTokens;
166
- existing.cacheWrite += r.cacheWriteTokens;
167
- existing.count++;
168
- modelMap.set(r.model, existing);
169
- }
170
- if (modelMap.size >= 1) {
171
- lines.push("");
172
- lines.push(` ${_chalk2.default.dim("By model:")}`);
173
- for (const [model, stats] of modelMap) {
174
- const p = _nullishCoalesce(MODEL_PRICING[model], () => ( DEFAULT_PRICING));
175
- const uncachedInput = Math.max(0, stats.prompt - stats.cacheRead - stats.cacheWrite);
176
- const modelCost = uncachedInput / 1e6 * p.input + stats.completion / 1e6 * p.output + stats.cacheRead / 1e6 * p.cacheRead + stats.cacheWrite / 1e6 * p.cacheWrite;
177
- const tokenDetail = `${formatNumber(stats.prompt)} in, ${formatNumber(stats.completion)} out` + (stats.cacheRead > 0 ? `, ${formatNumber(stats.cacheRead)} cache` : "");
178
- lines.push(
179
- ` ${_chalk2.default.dim(model)} \u2014 ${tokenDetail}, ${formatCost(modelCost)} (${stats.count} reqs)`
180
- );
181
- }
182
- }
183
- if (this._hasUnknownModel) {
184
- lines.push("");
185
- lines.push(_chalk2.default.dim(" (costs may be inaccurate due to usage of unknown models)"));
186
- }
187
- return lines.join("\n");
188
- }
189
- /**
190
- * Format a compact one-line cost display for the prompt footer.
191
- */
192
- formatCompact() {
193
- const tokens = this.getTotalTokens();
194
- const cost = this.getEstimatedCost();
195
- return _chalk2.default.dim(
196
- `tokens: ${formatNumber(tokens.total)} | cost: ${formatCost(cost)}`
197
- );
198
- }
199
- reset() {
200
- this.records = [];
201
- this.sessionStart = Date.now();
202
- }
203
- /** Serialize cost state for session persistence. */
204
- serialize() {
205
- const tokens = this.getTotalTokens();
206
- return {
207
- records: this.records,
208
- sessionStart: this.sessionStart,
209
- totalPromptTokens: tokens.prompt,
210
- totalCompletionTokens: tokens.completion,
211
- estimatedCost: this.getEstimatedCost()
212
- };
213
- }
214
- /** Restore cost state from a previous session. */
215
- restore(state) {
216
- this.records = _nullishCoalesce(state.records, () => ( []));
217
- this.sessionStart = _nullishCoalesce(state.sessionStart, () => ( Date.now()));
218
- }
219
- }, _class);
220
- function formatCost(cost) {
221
- if (cost >= 0.5) return `$${Math.round(cost * 100) / 100}`;
222
- if (cost >= 0.01) return `$${cost.toFixed(4)}`;
223
- if (cost > 0) return `$${cost.toFixed(6)}`;
224
- return "$0.00";
225
- }
226
- function formatNumber(n) {
227
- if (n >= 1e6) return (n / 1e6).toFixed(1) + "M";
228
- if (n >= 1e3) return (n / 1e3).toFixed(1) + "K";
229
- return String(n);
230
- }
231
- function formatDuration(ms) {
232
- const s = Math.floor(ms / 1e3);
233
- if (s < 60) return `${s}s`;
234
- const m = Math.floor(s / 60);
235
- const rs = s % 60;
236
- if (m < 60) return `${m}m ${rs}s`;
237
- const h = Math.floor(m / 60);
238
- const rm = m % 60;
239
- return `${h}h ${rm}m`;
240
- }
241
- var costTracker = new CostTracker();
242
-
243
-
244
-
245
-
246
- exports.CostTracker = CostTracker; exports.costTracker = costTracker;