@cjhyy/code-shell 0.1.0-alpha.0 → 0.1.0-alpha.2

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 (281) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +8 -0
  3. package/dist/anthropic-P5VETAFI.cjs +10 -0
  4. package/dist/{anthropic-NENYS535.js → anthropic-W2GU3D76.js} +3 -2
  5. package/dist/arena/context/context-tools.d.ts +1 -1
  6. package/dist/arena/index.cjs +4 -4
  7. package/dist/arena/index.js +3 -3
  8. package/dist/arena/providers/index.d.ts +19 -3
  9. package/dist/arena/strategies/utils.d.ts +6 -1
  10. package/dist/arena/types.d.ts +10 -1
  11. package/dist/{arena-46QQ6BZQ.js → arena-ENHBHB2W.js} +5 -7
  12. package/dist/{arena-HZZZ2GJH.cjs → arena-HHDYYVHJ.cjs} +19 -21
  13. package/dist/{chunk-BE6IPRDM.js → chunk-2EUAE7AY.js} +1 -1
  14. package/dist/{chunk-WFQF3RT4.cjs → chunk-3CAZIWUA.cjs} +11 -8
  15. package/dist/{chunk-J5XW6UYL.js → chunk-5C5HIOML.js} +63 -4
  16. package/dist/chunk-75E4BBFC.js +224 -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-FA5KD34T.js +54 -0
  21. package/dist/chunk-FV2ARONZ.cjs +224 -0
  22. package/dist/chunk-G76E5FOB.cjs +54 -0
  23. package/dist/{chunk-DICG4AB7.cjs → chunk-GZBD6QRS.cjs} +42 -3
  24. package/dist/{chunk-FVP7XJGS.cjs → chunk-HOXQLX5R.cjs} +406 -196
  25. package/dist/{chunk-4PKZPFCD.js → chunk-I57ZD5IQ.js} +47 -14
  26. package/dist/{chunk-7RMAR2Y3.js → chunk-ID6EJUHP.js} +1959 -473
  27. package/dist/chunk-JHNCK7JP.cjs +202 -0
  28. package/dist/{chunk-R32DJSJE.cjs → chunk-JHXNOB5G.cjs} +8 -5
  29. package/dist/{chunk-UK2SU23S.cjs → chunk-KOGV6PDQ.cjs} +20 -2
  30. package/dist/{chunk-VKGNCYRL.js → chunk-LMEKCQX4.js} +95 -13
  31. package/dist/{chunk-3EAEC566.cjs → chunk-M2QI5X3X.cjs} +51 -18
  32. package/dist/{chunk-YZ25SSWJ.js → chunk-M2SVOKC6.js} +46 -4
  33. package/dist/chunk-OMRGA6TI.js +4753 -0
  34. package/dist/{chunk-NG73UR3L.cjs → chunk-OP57WUWQ.cjs} +23 -1
  35. package/dist/{chunk-ZXYDDJEJ.js → chunk-OUC2DFA7.js} +2 -2
  36. package/dist/{chunk-6JOOLG6F.js → chunk-REFCCVDM.js} +5 -2
  37. package/dist/{chunk-O6F2EF2Z.js → chunk-SCDKLTN3.js} +41 -2
  38. package/dist/{chunk-BHGIJ2DJ.js → chunk-SW3L7HIM.js} +6 -3
  39. package/dist/chunk-TATCTZSB.cjs +4753 -0
  40. package/dist/{chunk-QHDYFC5U.cjs → chunk-VWFET3MG.cjs} +2132 -646
  41. package/dist/{chunk-3EUDE77E.cjs → chunk-X2DNIMPC.cjs} +19 -19
  42. package/dist/{chunk-SQZHPD3S.js → chunk-Y7TSCDF6.js} +297 -87
  43. package/dist/{chunk-WHRTARDJ.cjs → chunk-YAFCN7ZW.cjs} +112 -30
  44. package/dist/{chunk-LRAY5IYC.cjs → chunk-YD7XTI7T.cjs} +65 -6
  45. package/dist/{chunk-S74VVJBF.js → chunk-ZLPJJZUW.js} +23 -1
  46. package/dist/chunk-ZRVPCXI7.js +202 -0
  47. package/dist/cli/commands/builtin/advanced-commands.d.ts +1 -1
  48. package/dist/cli/commands/builtin/extra-commands.d.ts +2 -2
  49. package/dist/cli/commands/builtin/more-commands.d.ts +1 -3
  50. package/dist/cli/commands/registry.d.ts +8 -0
  51. package/dist/cli/cost-tracker.d.ts +6 -0
  52. package/dist/cli/main.cjs +3576 -2036
  53. package/dist/cli/main.js +3613 -2073
  54. package/dist/cli/onboarding.d.ts +67 -14
  55. package/dist/client-base-TOVE25FA.js +9 -0
  56. package/dist/client-base-VDDIADAC.cjs +9 -0
  57. package/dist/compaction-D3KV2NWY.cjs +31 -0
  58. package/dist/{compaction-CCHWA4G6.js → compaction-YNWCEF7B.js} +1 -2
  59. package/dist/context/manager.d.ts +9 -0
  60. package/dist/data/openrouter-models.d.ts +35 -0
  61. package/dist/data/openrouter-sync.d.ts +16 -0
  62. package/dist/{devtools-KIY3LWQJ.js → devtools-IRQQPIRY.js} +1 -1
  63. package/dist/{devtools-LRP47DDV.cjs → devtools-WTC3NFNE.cjs} +1 -1
  64. package/dist/engine/engine.d.ts +39 -4
  65. package/dist/engine/turn-loop.d.ts +13 -4
  66. package/dist/engine/turn-state.d.ts +6 -0
  67. package/dist/index.cjs +19 -28
  68. package/dist/index.d.ts +1 -1
  69. package/dist/index.js +28 -37
  70. package/dist/llm/client-base.d.ts +7 -0
  71. package/dist/llm/model-pool.d.ts +4 -0
  72. package/dist/logging/logger.d.ts +69 -8
  73. package/dist/manager-FWLOVEEK.cjs +7 -0
  74. package/dist/manager-GEXJLOIS.js +7 -0
  75. package/dist/{mcp-manager-OKXHHWYR.js → mcp-manager-37GQLFGX.js} +2 -2
  76. package/dist/mcp-manager-U77NEXBY.cjs +8 -0
  77. package/dist/memory-ADGOWADP.cjs +9 -0
  78. package/dist/memory-EPFDBPII.js +9 -0
  79. package/dist/native-ts/yoga-layout/index.d.ts +2 -2
  80. package/dist/{openai-5HQGBL4L.js → openai-RXU5URYI.js} +3 -2
  81. package/dist/openai-SQW4H2K4.cjs +10 -0
  82. package/dist/openrouter-models-OL725CL6.js +15 -0
  83. package/dist/openrouter-models-UM3AOGZ4.cjs +15 -0
  84. package/dist/openrouter-sync-CWD5VNW2.js +11 -0
  85. package/dist/openrouter-sync-HYZZC6RX.cjs +11 -0
  86. package/dist/product/index.cjs +12 -16
  87. package/dist/product/index.js +11 -15
  88. package/dist/product/types.d.ts +2 -7
  89. package/dist/protocol/types.d.ts +11 -3
  90. package/dist/{ink → render}/hooks/use-input.d.ts +1 -1
  91. package/dist/run/EngineRunner.d.ts +3 -1
  92. package/dist/run/RunManager.d.ts +6 -0
  93. package/dist/run/factory.d.ts +7 -1
  94. package/dist/run/index.cjs +12 -16
  95. package/dist/run/index.js +11 -15
  96. package/dist/session/memory.d.ts +23 -3
  97. package/dist/session/session-manager.d.ts +4 -1
  98. package/dist/{session-manager-UQKB564H.cjs → session-manager-HRSKENKB.cjs} +2 -2
  99. package/dist/{session-manager-JIIBCFTC.js → session-manager-NEKFEHF3.js} +1 -1
  100. package/dist/settings/manager.d.ts +9 -0
  101. package/dist/settings/schema.d.ts +48 -39
  102. package/dist/{tool-summary-J2ICNMWP.js → tool-summary-2RUFL5QK.js} +1 -1
  103. package/dist/{tool-summary-5P2GKRA4.cjs → tool-summary-RYNR4DDB.cjs} +2 -2
  104. package/dist/tool-system/builtin/agent-registry.d.ts +36 -0
  105. package/dist/tool-system/builtin/agent.d.ts +7 -26
  106. package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
  107. package/dist/tool-system/builtin/apply-patch/index.d.ts +19 -0
  108. package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
  109. package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
  110. package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
  111. package/dist/tool-system/builtin/arena.d.ts +18 -5
  112. package/dist/tool-system/builtin/ask-user.d.ts +6 -6
  113. package/dist/tool-system/builtin/index.d.ts +11 -1
  114. package/dist/tool-system/builtin/tool-search.d.ts +2 -3
  115. package/dist/tool-system/context.d.ts +74 -0
  116. package/dist/tool-system/executor.d.ts +16 -0
  117. package/dist/tool-system/permission.d.ts +40 -5
  118. package/dist/tool-system/registry.d.ts +8 -0
  119. package/dist/types.d.ts +34 -1
  120. package/dist/ui/App.d.ts +1 -1
  121. package/dist/ui/components/AgentBlock.d.ts +1 -1
  122. package/dist/ui/components/AskUserPrompt.d.ts +7 -0
  123. package/dist/ui/components/MessageContent.d.ts +7 -3
  124. package/dist/ui/components/ModelManager.d.ts +35 -0
  125. package/dist/ui/components/ModelSelector.d.ts +10 -0
  126. package/dist/ui/components/OnboardingPrompt.d.ts +7 -0
  127. package/dist/ui/components/PermissionPrompt.d.ts +5 -2
  128. package/dist/ui/components/SessionPicker.d.ts +14 -0
  129. package/dist/ui/components/StatusLine.d.ts +4 -2
  130. package/dist/ui/components/ThemedBox.d.ts +1 -1
  131. package/dist/ui/components/ToolCall.d.ts +8 -1
  132. package/dist/ui/components/WelcomeTips.d.ts +5 -0
  133. package/dist/ui/onboarding-runner.d.ts +2 -0
  134. package/dist/ui/store.d.ts +1 -0
  135. package/dist/{updater-URVNPDPW.cjs → updater-M7L42ASZ.cjs} +4 -4
  136. package/dist/{updater-AVD4LKTQ.js → updater-ZRTONIR4.js} +4 -4
  137. package/dist/utils/debug.d.ts +17 -33
  138. package/package.json +4 -4
  139. package/dist/anthropic-XMTTVNSH.cjs +0 -9
  140. package/dist/bridge-4ZRXVWBN.js +0 -98
  141. package/dist/bridge-W476QDFH.cjs +0 -98
  142. package/dist/chunk-4RRUP4MM.js +0 -86
  143. package/dist/chunk-4SFPFHMG.js +0 -132
  144. package/dist/chunk-5LHVI777.cjs +0 -246
  145. package/dist/chunk-6ZIROYXX.js +0 -207
  146. package/dist/chunk-C7JBCO5V.js +0 -80
  147. package/dist/chunk-CSO5EOEP.cjs +0 -132
  148. package/dist/chunk-FGZGCFJX.cjs +0 -207
  149. package/dist/chunk-HD7MT5XU.cjs +0 -86
  150. package/dist/chunk-IMMTBZ33.cjs +0 -63
  151. package/dist/chunk-JT2WSQSR.cjs +0 -335
  152. package/dist/chunk-NZ4DQ72D.cjs +0 -664
  153. package/dist/chunk-OG4MIQJ6.js +0 -335
  154. package/dist/chunk-WRZJUQ5Z.js +0 -664
  155. package/dist/chunk-X4HAERTQ.js +0 -63
  156. package/dist/chunk-XHC2JMEC.cjs +0 -80
  157. package/dist/chunk-ZRSSGYA5.js +0 -246
  158. package/dist/compaction-44I55TLI.cjs +0 -32
  159. package/dist/coordinator-5HY7ALO2.js +0 -7
  160. package/dist/coordinator-INDLPVMF.cjs +0 -7
  161. package/dist/cost-tracker-IWYAUPXH.js +0 -9
  162. package/dist/cost-tracker-JXTJQQWE.cjs +0 -9
  163. package/dist/loader-DXFSUB4R.cjs +0 -91
  164. package/dist/loader-J5UID6CV.js +0 -91
  165. package/dist/manager-ETWDOCHN.cjs +0 -9
  166. package/dist/manager-HGMQNEJB.cjs +0 -11
  167. package/dist/manager-HUAQOORS.js +0 -9
  168. package/dist/manager-VJIZ2CQC.js +0 -11
  169. package/dist/mcp-manager-G4G2QASE.cjs +0 -8
  170. package/dist/memory-AP747G5H.js +0 -7
  171. package/dist/memory-BH3BYUN5.cjs +0 -7
  172. package/dist/onboarding-6WEPV7C2.js +0 -11
  173. package/dist/onboarding-QM5DY2TU.cjs +0 -11
  174. package/dist/openai-656VWUQW.cjs +0 -9
  175. package/dist/skills-63RBYQRX.js +0 -13
  176. package/dist/skills-V3BPLW3D.cjs +0 -13
  177. package/dist/token-counter-CHAXW5O7.cjs +0 -13
  178. package/dist/token-counter-DSOZGZ5Q.js +0 -13
  179. package/dist/utils/log.d.ts +0 -56
  180. package/dist/voice-KTZ7PAGO.js +0 -80
  181. package/dist/voice-KZE25GKB.cjs +0 -80
  182. /package/dist/{ink → render}/Ansi.d.ts +0 -0
  183. /package/dist/{ink → render}/bidi.d.ts +0 -0
  184. /package/dist/{ink → render}/clearTerminal.d.ts +0 -0
  185. /package/dist/{ink → render}/colorize.d.ts +0 -0
  186. /package/dist/{ink → render}/components/AlternateScreen.d.ts +0 -0
  187. /package/dist/{ink → render}/components/App.d.ts +0 -0
  188. /package/dist/{ink → render}/components/AppContext.d.ts +0 -0
  189. /package/dist/{ink → render}/components/Box.d.ts +0 -0
  190. /package/dist/{ink → render}/components/Button.d.ts +0 -0
  191. /package/dist/{ink → render}/components/ClockContext.d.ts +0 -0
  192. /package/dist/{ink → render}/components/CursorDeclarationContext.d.ts +0 -0
  193. /package/dist/{ink → render}/components/ErrorOverview.d.ts +0 -0
  194. /package/dist/{ink → render}/components/Link.d.ts +0 -0
  195. /package/dist/{ink → render}/components/Newline.d.ts +0 -0
  196. /package/dist/{ink → render}/components/NoSelect.d.ts +0 -0
  197. /package/dist/{ink → render}/components/RawAnsi.d.ts +0 -0
  198. /package/dist/{ink → render}/components/ScrollBox.d.ts +0 -0
  199. /package/dist/{ink → render}/components/Spacer.d.ts +0 -0
  200. /package/dist/{ink → render}/components/StdinContext.d.ts +0 -0
  201. /package/dist/{ink → render}/components/TerminalFocusContext.d.ts +0 -0
  202. /package/dist/{ink → render}/components/TerminalSizeContext.d.ts +0 -0
  203. /package/dist/{ink → render}/components/Text.d.ts +0 -0
  204. /package/dist/{ink → render}/constants.d.ts +0 -0
  205. /package/dist/{ink → render}/cursor.d.ts +0 -0
  206. /package/dist/{ink → render}/devtools.d.ts +0 -0
  207. /package/dist/{ink → render}/dom.d.ts +0 -0
  208. /package/dist/{ink → render}/events/click-event.d.ts +0 -0
  209. /package/dist/{ink → render}/events/dispatcher.d.ts +0 -0
  210. /package/dist/{ink → render}/events/emitter.d.ts +0 -0
  211. /package/dist/{ink → render}/events/event-handlers.d.ts +0 -0
  212. /package/dist/{ink → render}/events/event.d.ts +0 -0
  213. /package/dist/{ink → render}/events/focus-event.d.ts +0 -0
  214. /package/dist/{ink → render}/events/input-event.d.ts +0 -0
  215. /package/dist/{ink → render}/events/keyboard-event.d.ts +0 -0
  216. /package/dist/{ink → render}/events/paste-event.d.ts +0 -0
  217. /package/dist/{ink → render}/events/resize-event.d.ts +0 -0
  218. /package/dist/{ink → render}/events/terminal-event.d.ts +0 -0
  219. /package/dist/{ink → render}/events/terminal-focus-event.d.ts +0 -0
  220. /package/dist/{ink → render}/focus.d.ts +0 -0
  221. /package/dist/{ink → render}/frame.d.ts +0 -0
  222. /package/dist/{ink → render}/get-max-width.d.ts +0 -0
  223. /package/dist/{ink → render}/hit-test.d.ts +0 -0
  224. /package/dist/{ink → render}/hooks/use-animation-frame.d.ts +0 -0
  225. /package/dist/{ink → render}/hooks/use-app.d.ts +0 -0
  226. /package/dist/{ink → render}/hooks/use-declared-cursor.d.ts +0 -0
  227. /package/dist/{ink → render}/hooks/use-interval.d.ts +0 -0
  228. /package/dist/{ink → render}/hooks/use-search-highlight.d.ts +0 -0
  229. /package/dist/{ink → render}/hooks/use-selection.d.ts +0 -0
  230. /package/dist/{ink → render}/hooks/use-stdin.d.ts +0 -0
  231. /package/dist/{ink → render}/hooks/use-tab-status.d.ts +0 -0
  232. /package/dist/{ink → render}/hooks/use-terminal-focus.d.ts +0 -0
  233. /package/dist/{ink → render}/hooks/use-terminal-title.d.ts +0 -0
  234. /package/dist/{ink → render}/hooks/use-terminal-viewport.d.ts +0 -0
  235. /package/dist/{ink → render}/index.d.ts +0 -0
  236. /package/dist/{ink → render}/ink.d.ts +0 -0
  237. /package/dist/{ink → render}/instances.d.ts +0 -0
  238. /package/dist/{ink → render}/layout/engine.d.ts +0 -0
  239. /package/dist/{ink → render}/layout/geometry.d.ts +0 -0
  240. /package/dist/{ink → render}/layout/node.d.ts +0 -0
  241. /package/dist/{ink → render}/layout/yoga.d.ts +0 -0
  242. /package/dist/{ink → render}/line-width-cache.d.ts +0 -0
  243. /package/dist/{ink → render}/log-update.d.ts +0 -0
  244. /package/dist/{ink → render}/measure-element.d.ts +0 -0
  245. /package/dist/{ink → render}/measure-text.d.ts +0 -0
  246. /package/dist/{ink → render}/node-cache.d.ts +0 -0
  247. /package/dist/{ink → render}/optimizer.d.ts +0 -0
  248. /package/dist/{ink → render}/output.d.ts +0 -0
  249. /package/dist/{ink → render}/parse-keypress.d.ts +0 -0
  250. /package/dist/{ink → render}/reconciler.d.ts +0 -0
  251. /package/dist/{ink → render}/render-border.d.ts +0 -0
  252. /package/dist/{ink → render}/render-node-to-output.d.ts +0 -0
  253. /package/dist/{ink → render}/render-to-screen.d.ts +0 -0
  254. /package/dist/{ink → render}/renderer.d.ts +0 -0
  255. /package/dist/{ink → render}/root.d.ts +0 -0
  256. /package/dist/{ink → render}/screen.d.ts +0 -0
  257. /package/dist/{ink → render}/searchHighlight.d.ts +0 -0
  258. /package/dist/{ink → render}/selection.d.ts +0 -0
  259. /package/dist/{ink → render}/squash-text-nodes.d.ts +0 -0
  260. /package/dist/{ink → render}/stringWidth.d.ts +0 -0
  261. /package/dist/{ink → render}/styles.d.ts +0 -0
  262. /package/dist/{ink → render}/supports-hyperlinks.d.ts +0 -0
  263. /package/dist/{ink → render}/tabstops.d.ts +0 -0
  264. /package/dist/{ink → render}/terminal-focus-state.d.ts +0 -0
  265. /package/dist/{ink → render}/terminal-querier.d.ts +0 -0
  266. /package/dist/{ink → render}/terminal.d.ts +0 -0
  267. /package/dist/{ink → render}/termio/ansi.d.ts +0 -0
  268. /package/dist/{ink → render}/termio/csi.d.ts +0 -0
  269. /package/dist/{ink → render}/termio/dec.d.ts +0 -0
  270. /package/dist/{ink → render}/termio/esc.d.ts +0 -0
  271. /package/dist/{ink → render}/termio/osc.d.ts +0 -0
  272. /package/dist/{ink → render}/termio/parser.d.ts +0 -0
  273. /package/dist/{ink → render}/termio/sgr.d.ts +0 -0
  274. /package/dist/{ink → render}/termio/tokenize.d.ts +0 -0
  275. /package/dist/{ink → render}/termio/types.d.ts +0 -0
  276. /package/dist/{ink → render}/termio.d.ts +0 -0
  277. /package/dist/{ink → render}/useTerminalNotification.d.ts +0 -0
  278. /package/dist/{ink → render}/warn.d.ts +0 -0
  279. /package/dist/{ink → render}/widest-line.d.ts +0 -0
  280. /package/dist/{ink → render}/wrap-text.d.ts +0 -0
  281. /package/dist/{ink → render}/wrapAnsi.d.ts +0 -0
@@ -0,0 +1,202 @@
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/logging/logger.ts
6
+ _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _fs = require('fs');
15
+ var _path = require('path');
16
+ var _os = require('os');
17
+ var LEVEL_ORDER = {
18
+ debug: 0,
19
+ info: 1,
20
+ warn: 2,
21
+ error: 3
22
+ };
23
+ var LOGS_DIR = _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "logs");
24
+ var MAX_LOG_FILES = 7;
25
+ var MAX_IN_MEMORY_ERRORS = 100;
26
+ function isLocalDev() {
27
+ if (process.env.CODE_SHELL_DEV === "1") return true;
28
+ if (process.argv.includes("--debug") || process.argv.includes("-d")) return true;
29
+ if (process.argv.some((a) => a.startsWith("--debug="))) return true;
30
+ if (process.env.NODE_ENV === "test" || process.env.BUN_TEST === "1") return false;
31
+ if (process.argv.some((a) => a.includes("/tests/") || a.endsWith(".test.ts"))) return false;
32
+ const entry = _nullishCoalesce(process.argv[1], () => ( ""));
33
+ if (entry.includes(`${"/"}src${"/"}`)) return true;
34
+ return false;
35
+ }
36
+ function resolveDefaultLevel() {
37
+ const raw = _optionalChain([process, 'access', _ => _.env, 'access', _2 => _2.CODE_SHELL_LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4(), 'access', _5 => _5.trim, 'call', _6 => _6()]);
38
+ if (raw && Object.hasOwn(LEVEL_ORDER, raw)) return raw;
39
+ return isLocalDev() ? "debug" : "info";
40
+ }
41
+ function resolveCategoryFilter() {
42
+ const cliArg = process.argv.find((a) => a.startsWith("--debug="));
43
+ let raw;
44
+ if (cliArg) raw = cliArg.slice("--debug=".length);
45
+ else {
46
+ const env = process.env.CODE_SHELL_DEBUG;
47
+ if (env && env !== "1" && env !== "true") raw = env;
48
+ }
49
+ if (!raw) return null;
50
+ const set = new Set(
51
+ raw.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean)
52
+ );
53
+ return set.size > 0 ? set : null;
54
+ }
55
+ var _currentSid = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
56
+ function setCurrentSid(sid) {
57
+ _currentSid = sid;
58
+ }
59
+ function getCurrentSid() {
60
+ return _currentSid;
61
+ }
62
+ var inMemoryErrors = [];
63
+ var errorLogSink = null;
64
+ var Logger = (_class = class _Logger {
65
+ constructor(context = {}) {;_class.prototype.__init.call(this);
66
+ this.context = context;
67
+ this.enabled = process.env.CODE_SHELL_LOG !== "0";
68
+ this.minLevel = resolveDefaultLevel();
69
+ this.categoryFilter = resolveCategoryFilter();
70
+ this.stderrEcho = process.env.CODE_SHELL_DEBUG === "1" || process.argv.includes("--debug-to-stderr") || process.argv.includes("-d2e");
71
+ }
72
+
73
+
74
+
75
+
76
+ __init() {this.dirReady = false}
77
+ child(extra) {
78
+ return new _Logger({ ...this.context, ...extra });
79
+ }
80
+ /**
81
+ * Set the session id stamped on every subsequent log entry written by
82
+ * any logger in the process. Called by Engine once a run's
83
+ * authoritative session id is known.
84
+ */
85
+ setSid(sid) {
86
+ setCurrentSid(sid);
87
+ }
88
+ getSid() {
89
+ return getCurrentSid();
90
+ }
91
+ debug(msg, data) {
92
+ this.write("debug", msg, data);
93
+ }
94
+ info(msg, data) {
95
+ this.write("info", msg, data);
96
+ }
97
+ warn(msg, data) {
98
+ this.write("warn", msg, data);
99
+ }
100
+ error(msgOrErr, data) {
101
+ let msg;
102
+ let entryData;
103
+ let errObj;
104
+ if (typeof msgOrErr === "string") {
105
+ msg = msgOrErr;
106
+ if (data instanceof Error) {
107
+ errObj = data;
108
+ entryData = { error: data.message, stack: data.stack };
109
+ } else {
110
+ entryData = data;
111
+ }
112
+ } else if (msgOrErr instanceof Error) {
113
+ msg = msgOrErr.message;
114
+ errObj = msgOrErr;
115
+ entryData = { stack: msgOrErr.stack };
116
+ } else {
117
+ msg = String(msgOrErr);
118
+ }
119
+ this.recordError(msg, entryData);
120
+ this.write("error", msg, entryData);
121
+ if (errObj) _optionalChain([errorLogSink, 'optionalAccess', _7 => _7.logError, 'call', _8 => _8(errObj)]);
122
+ }
123
+ recordError(msg, data) {
124
+ if (inMemoryErrors.length >= MAX_IN_MEMORY_ERRORS) inMemoryErrors.shift();
125
+ inMemoryErrors.push({ msg, t: (/* @__PURE__ */ new Date()).toISOString(), data });
126
+ }
127
+ write(level, msg, data) {
128
+ if (!this.enabled) return;
129
+ if (LEVEL_ORDER[level] < LEVEL_ORDER[this.minLevel]) return;
130
+ const cat = _nullishCoalesce(_optionalChain([data, 'optionalAccess', _9 => _9.cat]), () => ( this.context.cat));
131
+ if (level === "debug" && this.categoryFilter) {
132
+ if (!cat || !this.categoryFilter.has(cat.toLowerCase())) return;
133
+ }
134
+ const t = (/* @__PURE__ */ new Date()).toISOString();
135
+ const entry = { t, l: level, msg, ...this.context };
136
+ if (cat && !entry.cat) entry.cat = cat;
137
+ if (entry.sid === void 0) entry.sid = _currentSid;
138
+ if (data) entry.d = data;
139
+ const line = JSON.stringify(entry) + "\n";
140
+ if (this.stderrEcho) {
141
+ process.stderr.write(line);
142
+ return;
143
+ }
144
+ try {
145
+ if (!this.dirReady) {
146
+ if (!_fs.existsSync.call(void 0, LOGS_DIR)) _fs.mkdirSync.call(void 0, LOGS_DIR, { recursive: true });
147
+ this.dirReady = true;
148
+ }
149
+ const dateStr = t.slice(0, 10);
150
+ _fs.appendFileSync.call(void 0, _path.join.call(void 0, LOGS_DIR, `${dateStr}.log`), line, "utf-8");
151
+ } catch (e) {
152
+ }
153
+ }
154
+ getMinLevel() {
155
+ return this.minLevel;
156
+ }
157
+ isCategoryActive(cat) {
158
+ return !this.categoryFilter || this.categoryFilter.has(cat.toLowerCase());
159
+ }
160
+ /**
161
+ * Open a span: writes a `<name>.begin` debug entry now and returns a handle
162
+ * whose `end()` writes `<name>.end` with `duration_ms` populated. Use for
163
+ * any "I want begin → end + how long" pattern (tool exec, LLM request,
164
+ * permission ask, etc.) so the begin/end pair is grouped under one cat
165
+ * and the duration is computed once instead of by hand from timestamps.
166
+ */
167
+ span(name, data) {
168
+ const startedAt = Date.now();
169
+ this.write("debug", `${name}.begin`, data);
170
+ return {
171
+ end: (extra) => {
172
+ const duration_ms = Date.now() - startedAt;
173
+ this.write("info", `${name}.end`, { ...data, ...extra, duration_ms });
174
+ },
175
+ fail: (err, extra) => {
176
+ const duration_ms = Date.now() - startedAt;
177
+ const message = err instanceof Error ? err.message : String(err);
178
+ this.write("error", `${name}.fail`, { ...data, ...extra, duration_ms, error: message });
179
+ }
180
+ };
181
+ }
182
+ }, _class);
183
+ var logger = new Logger();
184
+ function rotateLogs() {
185
+ try {
186
+ if (!_fs.existsSync.call(void 0, LOGS_DIR)) return;
187
+ const files = _fs.readdirSync.call(void 0, LOGS_DIR).filter((f) => f.endsWith(".log")).sort();
188
+ if (files.length <= MAX_LOG_FILES) return;
189
+ for (const f of files.slice(0, files.length - MAX_LOG_FILES)) {
190
+ try {
191
+ _fs.unlinkSync.call(void 0, _path.join.call(void 0, LOGS_DIR, f));
192
+ } catch (e2) {
193
+ }
194
+ }
195
+ } catch (e3) {
196
+ }
197
+ }
198
+
199
+
200
+
201
+
202
+ exports.logger = logger; exports.rotateLogs = rotateLogs;
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
3
 
4
- var _chunkQHDYFC5Ucjs = require('./chunk-QHDYFC5U.cjs');
4
+ var _chunkVWFET3MGcjs = require('./chunk-VWFET3MG.cjs');
5
5
 
6
6
 
7
7
  var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
@@ -15,8 +15,8 @@ var _path = require('path');
15
15
  var _os = require('os');
16
16
  function createRunManager(options) {
17
17
  const runsDir = _nullishCoalesce(options.runsDir, () => ( _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell", "runs")));
18
- const store = new (0, _chunkQHDYFC5Ucjs.FileRunStore)(runsDir);
19
- return new (0, _chunkQHDYFC5Ucjs.RunManager)({
18
+ const store = new (0, _chunkVWFET3MGcjs.FileRunStore)(runsDir);
19
+ return new (0, _chunkVWFET3MGcjs.RunManager)({
20
20
  store,
21
21
  executor: {
22
22
  llm: options.llm,
@@ -28,11 +28,14 @@ function createRunManager(options) {
28
28
  enabledBuiltinTools: options.enabledBuiltinTools,
29
29
  disabledBuiltinTools: options.disabledBuiltinTools,
30
30
  customSystemPrompt: options.customSystemPrompt,
31
- appendSystemPrompt: options.appendSystemPrompt
31
+ appendSystemPrompt: options.appendSystemPrompt,
32
+ hooks: options.hooks
32
33
  },
33
34
  concurrency: _nullishCoalesce(options.concurrency, () => ( 1)),
34
35
  runsDir,
35
- evaluator: options.evaluator
36
+ evaluator: options.evaluator,
37
+ defaultTags: options.defaultTags,
38
+ defaultMetadata: options.defaultMetadata
36
39
  });
37
40
  }
38
41
 
@@ -4,6 +4,17 @@ var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
4
4
 
5
5
  // src/llm/model-pool.ts
6
6
  _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
7
+ var BUILTIN_CONTEXT_WINDOWS = [
8
+ // DeepSeek V4 family — 1M context (api-docs.deepseek.com)
9
+ [/^deepseek-v4(?:-|$)/i, 1e6],
10
+ [/(?:^|\/)deepseek-v4(?:-|$)/i, 1e6]
11
+ ];
12
+ function lookupBuiltinContextWindow(model) {
13
+ for (const [re, tokens] of BUILTIN_CONTEXT_WINDOWS) {
14
+ if (re.test(model)) return tokens;
15
+ }
16
+ return void 0;
17
+ }
7
18
  var ModelPool = (_class = class {
8
19
  __init() {this.models = /* @__PURE__ */ new Map()}
9
20
 
@@ -14,7 +25,7 @@ var ModelPool = (_class = class {
14
25
  constructor(entries, defaultKey) {;_class.prototype.__init.call(this);
15
26
  if (entries) {
16
27
  for (const e of entries) {
17
- this.models.set(e.key, e);
28
+ this.models.set(e.key, this.withBuiltinDefaults(e));
18
29
  }
19
30
  }
20
31
  if (defaultKey && this.models.has(defaultKey)) {
@@ -25,11 +36,18 @@ var ModelPool = (_class = class {
25
36
  }
26
37
  /** Register a model at runtime. */
27
38
  register(entry) {
28
- this.models.set(entry.key, entry);
39
+ this.models.set(entry.key, this.withBuiltinDefaults(entry));
29
40
  if (!this.activeKey) {
30
41
  this.activeKey = entry.key;
31
42
  }
32
43
  }
44
+ /** Fill in known defaults (e.g. context window for DeepSeek V4) when the entry doesn't specify them. */
45
+ withBuiltinDefaults(entry) {
46
+ if (entry.maxContextTokens != null) return entry;
47
+ const builtin = lookupBuiltinContextWindow(entry.model);
48
+ if (builtin == null) return entry;
49
+ return { ...entry, maxContextTokens: builtin };
50
+ }
33
51
  /** Switch the active model. Throws if key not found. */
34
52
  switch(key) {
35
53
  const entry = this.models.get(key);
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  LLMClientBase
3
- } from "./chunk-O6F2EF2Z.js";
3
+ } from "./chunk-SCDKLTN3.js";
4
4
  import {
5
5
  ContextLimitError,
6
6
  LLMError,
7
7
  LLMRateLimitError
8
8
  } from "./chunk-FUOKLKR2.js";
9
+ import {
10
+ logger
11
+ } from "./chunk-ZRVPCXI7.js";
9
12
  import {
10
13
  init_esm_shims
11
14
  } from "./chunk-DI7RDLOS.js";
@@ -34,10 +37,28 @@ var OpenAIClient = class extends LLMClientBase {
34
37
  return this.withRetry(async () => {
35
38
  const messages = this.buildMessages(options.systemPrompt, options.messages);
36
39
  const tools = options.tools?.length ? this.convertTools(options.tools) : void 0;
37
- if (options.stream && options.onChunk) {
38
- return this.streamMessage(options, messages, tools);
40
+ const span = logger.span("llm.request", {
41
+ cat: "llm",
42
+ provider: this.provider,
43
+ model: this.model,
44
+ stream: !!(options.stream && options.onChunk),
45
+ messageCount: messages.length,
46
+ toolCount: tools?.length ?? 0
47
+ });
48
+ try {
49
+ const response = options.stream && options.onChunk ? await this.streamMessage(options, messages, tools) : await this.nonStreamMessage(options, messages, tools);
50
+ span.end({
51
+ stopReason: response.stopReason,
52
+ promptTokens: response.usage?.promptTokens,
53
+ completionTokens: response.usage?.completionTokens,
54
+ cacheReadTokens: response.usage?.cacheReadTokens,
55
+ cacheCreationTokens: response.usage?.cacheCreationTokens
56
+ });
57
+ return response;
58
+ } catch (err) {
59
+ span.fail(err);
60
+ throw err;
39
61
  }
40
- return this.nonStreamMessage(options, messages, tools);
41
62
  });
42
63
  }
43
64
  async nonStreamMessage(options, messages, tools) {
@@ -81,15 +102,31 @@ var OpenAIClient = class extends LLMClientBase {
81
102
  { signal: options.signal }
82
103
  );
83
104
  let text = "";
105
+ let reasoningContent = "";
84
106
  const toolCallsMap = /* @__PURE__ */ new Map();
85
107
  let streamUsage;
108
+ const streamStartedAt = Date.now();
109
+ let firstByteLogged = false;
86
110
  for await (const chunk of stream) {
87
111
  if (chunk.usage) {
88
112
  streamUsage = chunk.usage;
89
113
  }
90
114
  const delta = chunk.choices[0]?.delta;
91
115
  if (!delta) continue;
116
+ const reasoningDelta = delta.reasoning_content;
117
+ if (typeof reasoningDelta === "string" && reasoningDelta.length > 0) {
118
+ reasoningContent += reasoningDelta;
119
+ }
92
120
  if (delta.content) {
121
+ if (!firstByteLogged) {
122
+ firstByteLogged = true;
123
+ logger.debug("llm.first_byte", {
124
+ cat: "llm",
125
+ provider: this.provider,
126
+ model: this.model,
127
+ ttft_ms: Date.now() - streamStartedAt
128
+ });
129
+ }
93
130
  text += delta.content;
94
131
  options.onChunk?.({ type: "text", text: delta.content });
95
132
  }
@@ -106,7 +143,19 @@ var OpenAIClient = class extends LLMClientBase {
106
143
  const existing = toolCallsMap.get(idx);
107
144
  if (tc.id) existing.id = tc.id;
108
145
  if (tc.function?.name) existing.name = tc.function.name;
109
- if (tc.function?.arguments) existing.args += tc.function.arguments;
146
+ if (tc.function?.arguments) {
147
+ existing.args += tc.function.arguments;
148
+ if (existing.id) {
149
+ try {
150
+ const parsed = JSON.parse(existing.args || "{}");
151
+ options.onChunk?.({
152
+ type: "tool_use_delta",
153
+ toolCall: { id: existing.id, toolName: existing.name, args: parsed }
154
+ });
155
+ } catch {
156
+ }
157
+ }
158
+ }
110
159
  }
111
160
  }
112
161
  if (chunk.choices[0]?.finish_reason) {
@@ -128,7 +177,13 @@ var OpenAIClient = class extends LLMClientBase {
128
177
  totalTokens: streamUsage?.total_tokens ?? 0
129
178
  };
130
179
  this.recordUsage(usage);
131
- return { text, toolCalls, usage, stopReason: "stop" };
180
+ return {
181
+ text,
182
+ toolCalls,
183
+ usage,
184
+ stopReason: "stop",
185
+ ...reasoningContent ? { reasoningContent } : {}
186
+ };
132
187
  } catch (err) {
133
188
  this.handleApiError(err);
134
189
  throw err;
@@ -151,17 +206,27 @@ var OpenAIClient = class extends LLMClientBase {
151
206
  });
152
207
  }
153
208
  }
154
- return { text, toolCalls, usage, stopReason: choice.finish_reason ?? void 0 };
209
+ const reasoningContent = extractReasoningContent(
210
+ choice.message
211
+ );
212
+ return {
213
+ text,
214
+ toolCalls,
215
+ usage,
216
+ stopReason: choice.finish_reason ?? void 0,
217
+ ...reasoningContent ? { reasoningContent } : {}
218
+ };
155
219
  }
156
220
  buildMessages(systemPrompt, messages) {
157
- const result = [
158
- { role: "system", content: systemPrompt }
159
- ];
221
+ const result = [{ role: "system", content: systemPrompt }];
222
+ const needsReasoningBackfill = isDeepSeekThinkingModel(this.model);
160
223
  for (const msg of messages) {
161
224
  if (msg.role === "system") continue;
162
225
  if (msg.role === "assistant") {
226
+ const param = { role: "assistant" };
227
+ let reasoningContent;
163
228
  if (typeof msg.content === "string") {
164
- result.push({ role: "assistant", content: msg.content });
229
+ param.content = msg.content;
165
230
  } else {
166
231
  const textParts = [];
167
232
  const toolCalls = [];
@@ -177,13 +242,23 @@ var OpenAIClient = class extends LLMClientBase {
177
242
  arguments: JSON.stringify(block.input ?? {})
178
243
  }
179
244
  });
245
+ } else if (block.type === "reasoning" && block.reasoningContent) {
246
+ reasoningContent = block.reasoningContent;
247
+ }
248
+ if (!reasoningContent && block.reasoningContent) {
249
+ reasoningContent = block.reasoningContent;
180
250
  }
181
251
  }
182
- const param = { role: "assistant" };
183
252
  if (textParts.length) param.content = textParts.join("\n");
184
253
  if (toolCalls.length) param.tool_calls = toolCalls;
185
- result.push(param);
186
254
  }
255
+ if (!reasoningContent && needsReasoningBackfill) {
256
+ reasoningContent = "";
257
+ }
258
+ if (reasoningContent !== void 0) {
259
+ param.reasoning_content = reasoningContent;
260
+ }
261
+ result.push(param);
187
262
  } else if (msg.role === "tool") {
188
263
  result.push({
189
264
  role: "tool",
@@ -252,6 +327,13 @@ var OpenAIClient = class extends LLMClientBase {
252
327
  throw err;
253
328
  }
254
329
  };
330
+ function extractReasoningContent(msg) {
331
+ const candidate = msg.reasoning_content ?? msg.reasoning;
332
+ return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
333
+ }
334
+ function isDeepSeekThinkingModel(model) {
335
+ return /^deepseek-v4(?:-|$)/i.test(model);
336
+ }
255
337
 
256
338
  export {
257
339
  OpenAIClient
@@ -1,4 +1,4 @@
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; }
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
2
 
3
3
  var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
4
4
 
@@ -7,16 +7,30 @@ _chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
7
7
  var _fs = require('fs');
8
8
  var _path = require('path');
9
9
  var _os = require('os');
10
- var MemoryManager = class {
10
+ function resolveMemoryBaseDir(override) {
11
+ if (override) return override;
12
+ const fromEnv = process.env.CODE_SHELL_HOME;
13
+ if (fromEnv && fromEnv.length > 0) return fromEnv;
14
+ return _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell");
15
+ }
16
+ var MemoryManager = (_class = class {
11
17
 
12
18
 
13
- constructor(projectDir) {
14
- const baseDir = _path.join.call(void 0, _os.homedir.call(void 0, ), ".code-shell");
15
- if (projectDir) {
16
- const projectHash = projectDir.replace(/[/\\:]/g, "-").replace(/^-/, "");
17
- this.memoryDir = _path.join.call(void 0, baseDir, "projects", projectHash, "memory");
19
+
20
+ // Per-instance cache of {fileName -> {name, description}} so the
21
+ // index can be rewritten without re-reading every memory file
22
+ // every time a single entry is saved/deleted (the previous code
23
+ // path called loadAll() on every save, giving O(N²) total I/O).
24
+ // null = "not initialized yet, fall back to disk on next access."
25
+ __init() {this.indexCache = null}
26
+ constructor(options) {;_class.prototype.__init.call(this);
27
+ const opts = typeof options === "string" ? { projectDir: options } : _nullishCoalesce(options, () => ( {}));
28
+ this.baseDir = resolveMemoryBaseDir(opts.baseDir);
29
+ if (opts.projectDir) {
30
+ const projectHash = opts.projectDir.replace(/[/\\:]/g, "-").replace(/^-/, "");
31
+ this.memoryDir = _path.join.call(void 0, this.baseDir, "projects", projectHash, "memory");
18
32
  } else {
19
- this.memoryDir = _path.join.call(void 0, baseDir, "memory");
33
+ this.memoryDir = _path.join.call(void 0, this.baseDir, "memory");
20
34
  }
21
35
  this.indexPath = _path.join.call(void 0, this.memoryDir, "MEMORY.md");
22
36
  _fs.mkdirSync.call(void 0, this.memoryDir, { recursive: true });
@@ -39,7 +53,9 @@ type: ${entry.type}
39
53
  ${entry.content}
40
54
  `;
41
55
  _fs.writeFileSync.call(void 0, filePath, content, "utf-8");
42
- this.updateIndex();
56
+ const cache = this.ensureIndexCache();
57
+ cache.set(fileName, { name: entry.name, description: entry.description });
58
+ this.writeIndex(cache);
43
59
  return fileName;
44
60
  }
45
61
  /**
@@ -88,7 +104,9 @@ ${entry.content}
88
104
  if (!entry) return false;
89
105
  try {
90
106
  _fs.unlinkSync.call(void 0, _path.join.call(void 0, this.memoryDir, entry.fileName));
91
- this.updateIndex();
107
+ const cache = this.ensureIndexCache();
108
+ cache.delete(entry.fileName);
109
+ this.writeIndex(cache);
92
110
  return true;
93
111
  } catch (e3) {
94
112
  return false;
@@ -116,21 +134,36 @@ The following memories from previous sessions may be relevant:
116
134
 
117
135
  ` + lines.join("\n") + `
118
136
 
119
- To read a specific memory, check ~/.code-shell/memory/`;
137
+ To read a specific memory, check ${this.memoryDir}/`;
120
138
  }
121
- updateIndex() {
122
- const entries = this.loadAll();
123
- const lines = entries.map(
124
- (e) => `- [${e.name}](${e.fileName}) \u2014 ${e.description}`
125
- );
139
+ /**
140
+ * Lazy-build the in-memory index from disk on first use, then
141
+ * keep it in sync incrementally via save/delete. Avoids the
142
+ * O() re-read of every memory file on every save.
143
+ */
144
+ ensureIndexCache() {
145
+ if (this.indexCache !== null) return this.indexCache;
146
+ const cache = /* @__PURE__ */ new Map();
147
+ for (const entry of this.loadAll()) {
148
+ cache.set(entry.fileName, { name: entry.name, description: entry.description });
149
+ }
150
+ this.indexCache = cache;
151
+ return cache;
152
+ }
153
+ writeIndex(cache) {
154
+ const lines = [];
155
+ for (const [fileName, meta] of cache) {
156
+ lines.push(`- [${meta.name}](${fileName}) \u2014 ${meta.description}`);
157
+ }
126
158
  const content = lines.length > 0 ? lines.join("\n") + "\n" : "(no memories stored)\n";
127
159
  _fs.writeFileSync.call(void 0, this.indexPath, content, "utf-8");
128
160
  }
129
161
  slugify(text) {
130
162
  return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60);
131
163
  }
132
- };
164
+ }, _class);
165
+
133
166
 
134
167
 
135
168
 
136
- exports.MemoryManager = MemoryManager;
169
+ exports.resolveMemoryBaseDir = resolveMemoryBaseDir; exports.MemoryManager = MemoryManager;
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  LLMClientBase
3
- } from "./chunk-O6F2EF2Z.js";
3
+ } from "./chunk-SCDKLTN3.js";
4
4
  import {
5
5
  ContextLimitError,
6
6
  LLMError,
7
7
  LLMRateLimitError
8
8
  } from "./chunk-FUOKLKR2.js";
9
+ import {
10
+ logger
11
+ } from "./chunk-ZRVPCXI7.js";
9
12
  import {
10
13
  init_esm_shims
11
14
  } from "./chunk-DI7RDLOS.js";
@@ -34,10 +37,28 @@ var AnthropicClient = class extends LLMClientBase {
34
37
  return this.withRetry(async () => {
35
38
  const messages = this.buildMessages(options.messages);
36
39
  const tools = options.tools ? this.convertTools(options.tools) : void 0;
37
- if (options.stream && options.onChunk) {
38
- return this.streamMessage(options, messages, tools);
40
+ const span = logger.span("llm.request", {
41
+ cat: "llm",
42
+ provider: this.provider,
43
+ model: this.model,
44
+ stream: !!(options.stream && options.onChunk),
45
+ messageCount: messages.length,
46
+ toolCount: tools?.length ?? 0
47
+ });
48
+ try {
49
+ const response = options.stream && options.onChunk ? await this.streamMessage(options, messages, tools) : await this.nonStreamMessage(options, messages, tools);
50
+ span.end({
51
+ stopReason: response.stopReason,
52
+ promptTokens: response.usage?.promptTokens,
53
+ completionTokens: response.usage?.completionTokens,
54
+ cacheReadTokens: response.usage?.cacheReadTokens,
55
+ cacheCreationTokens: response.usage?.cacheCreationTokens
56
+ });
57
+ return response;
58
+ } catch (err) {
59
+ span.fail(err);
60
+ throw err;
39
61
  }
40
- return this.nonStreamMessage(options, messages, tools);
41
62
  });
42
63
  }
43
64
  async nonStreamMessage(options, messages, tools) {
@@ -96,7 +117,18 @@ var AnthropicClient = class extends LLMClientBase {
96
117
  let currentToolName = "";
97
118
  let currentToolId = "";
98
119
  let currentToolInput = "";
120
+ const streamStartedAt = Date.now();
121
+ let firstByteLogged = false;
99
122
  stream.on("text", (text) => {
123
+ if (!firstByteLogged) {
124
+ firstByteLogged = true;
125
+ logger.debug("llm.first_byte", {
126
+ cat: "llm",
127
+ provider: this.provider,
128
+ model: this.model,
129
+ ttft_ms: Date.now() - streamStartedAt
130
+ });
131
+ }
100
132
  currentText += text;
101
133
  options.onChunk?.({ type: "text", text });
102
134
  });
@@ -113,6 +145,16 @@ var AnthropicClient = class extends LLMClientBase {
113
145
  });
114
146
  stream.on("inputJson", (_delta, snapshot) => {
115
147
  currentToolInput = JSON.stringify(snapshot);
148
+ if (currentToolId) {
149
+ options.onChunk?.({
150
+ type: "tool_use_delta",
151
+ toolCall: {
152
+ id: currentToolId,
153
+ toolName: currentToolName,
154
+ args: snapshot ?? {}
155
+ }
156
+ });
157
+ }
116
158
  });
117
159
  const finalMessage = await stream.finalMessage();
118
160
  const usage = {