@prestyj/cli 4.2.15 → 4.2.44

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 (286) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -7
  3. package/dist/cli.js +457 -225
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +1 -0
  6. package/dist/config.d.ts.map +1 -1
  7. package/dist/config.js +66 -0
  8. package/dist/config.js.map +1 -1
  9. package/dist/core/agent-session.d.ts +22 -0
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +184 -23
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/agents.d.ts +0 -2
  14. package/dist/core/agents.d.ts.map +1 -1
  15. package/dist/core/agents.js +1 -5
  16. package/dist/core/agents.js.map +1 -1
  17. package/dist/core/auth-storage.d.ts +2 -0
  18. package/dist/core/auth-storage.d.ts.map +1 -1
  19. package/dist/core/auth-storage.js +66 -17
  20. package/dist/core/auth-storage.js.map +1 -1
  21. package/dist/core/auto-update.js +1 -1
  22. package/dist/core/auto-update.js.map +1 -1
  23. package/dist/core/compaction/compactor.d.ts +36 -5
  24. package/dist/core/compaction/compactor.d.ts.map +1 -1
  25. package/dist/core/compaction/compactor.js +222 -63
  26. package/dist/core/compaction/compactor.js.map +1 -1
  27. package/dist/core/compaction/compactor.test.js +377 -32
  28. package/dist/core/compaction/compactor.test.js.map +1 -1
  29. package/dist/core/compaction/token-estimator.d.ts +5 -0
  30. package/dist/core/compaction/token-estimator.d.ts.map +1 -1
  31. package/dist/core/compaction/token-estimator.js +41 -2
  32. package/dist/core/compaction/token-estimator.js.map +1 -1
  33. package/dist/core/compaction/token-estimator.test.js +43 -21
  34. package/dist/core/compaction/token-estimator.test.js.map +1 -1
  35. package/dist/core/event-bus.d.ts +6 -0
  36. package/dist/core/event-bus.d.ts.map +1 -1
  37. package/dist/core/event-bus.js +7 -0
  38. package/dist/core/event-bus.js.map +1 -1
  39. package/dist/core/file-lock.d.ts +6 -0
  40. package/dist/core/file-lock.d.ts.map +1 -0
  41. package/dist/core/file-lock.js +76 -0
  42. package/dist/core/file-lock.js.map +1 -0
  43. package/dist/core/index.d.ts +2 -2
  44. package/dist/core/index.d.ts.map +1 -1
  45. package/dist/core/index.js +1 -1
  46. package/dist/core/index.js.map +1 -1
  47. package/dist/core/mcp/client.d.ts +0 -26
  48. package/dist/core/mcp/client.d.ts.map +1 -1
  49. package/dist/core/mcp/client.js +34 -141
  50. package/dist/core/mcp/client.js.map +1 -1
  51. package/dist/core/mcp/defaults.d.ts.map +1 -1
  52. package/dist/core/mcp/defaults.js +4 -8
  53. package/dist/core/mcp/defaults.js.map +1 -1
  54. package/dist/core/mcp/types.d.ts +0 -2
  55. package/dist/core/mcp/types.d.ts.map +1 -1
  56. package/dist/core/model-registry.d.ts +2 -1
  57. package/dist/core/model-registry.d.ts.map +1 -1
  58. package/dist/core/model-registry.js +16 -5
  59. package/dist/core/model-registry.js.map +1 -1
  60. package/dist/core/oauth/anthropic.d.ts.map +1 -1
  61. package/dist/core/oauth/anthropic.js +3 -3
  62. package/dist/core/oauth/anthropic.js.map +1 -1
  63. package/dist/core/prompt-commands.d.ts.map +1 -1
  64. package/dist/core/prompt-commands.js +21 -0
  65. package/dist/core/prompt-commands.js.map +1 -1
  66. package/dist/core/session-manager.d.ts +34 -2
  67. package/dist/core/session-manager.d.ts.map +1 -1
  68. package/dist/core/session-manager.js +160 -54
  69. package/dist/core/session-manager.js.map +1 -1
  70. package/dist/core/settings-manager.d.ts +2 -2
  71. package/dist/core/skills.d.ts +2 -1
  72. package/dist/core/skills.d.ts.map +1 -1
  73. package/dist/core/skills.js +8 -8
  74. package/dist/core/skills.js.map +1 -1
  75. package/dist/core/slash-commands.d.ts +4 -0
  76. package/dist/core/slash-commands.d.ts.map +1 -1
  77. package/dist/core/slash-commands.js +22 -0
  78. package/dist/core/slash-commands.js.map +1 -1
  79. package/dist/core/telegram.d.ts +94 -0
  80. package/dist/core/telegram.d.ts.map +1 -0
  81. package/dist/core/telegram.js +227 -0
  82. package/dist/core/telegram.js.map +1 -0
  83. package/dist/interactive.d.ts.map +1 -1
  84. package/dist/interactive.js +36 -5
  85. package/dist/interactive.js.map +1 -1
  86. package/dist/modes/index.d.ts +1 -0
  87. package/dist/modes/index.d.ts.map +1 -1
  88. package/dist/modes/index.js +1 -0
  89. package/dist/modes/index.js.map +1 -1
  90. package/dist/modes/json-mode.d.ts.map +1 -1
  91. package/dist/modes/json-mode.js +2 -1
  92. package/dist/modes/json-mode.js.map +1 -1
  93. package/dist/modes/print-mode.d.ts.map +1 -1
  94. package/dist/modes/print-mode.js +2 -1
  95. package/dist/modes/print-mode.js.map +1 -1
  96. package/dist/modes/rpc-mode.d.ts +28 -0
  97. package/dist/modes/rpc-mode.d.ts.map +1 -0
  98. package/dist/modes/rpc-mode.js +146 -0
  99. package/dist/modes/rpc-mode.js.map +1 -0
  100. package/dist/modes/serve-mode.d.ts +21 -0
  101. package/dist/modes/serve-mode.d.ts.map +1 -0
  102. package/dist/modes/serve-mode.js +650 -0
  103. package/dist/modes/serve-mode.js.map +1 -0
  104. package/dist/system-prompt.d.ts +1 -1
  105. package/dist/system-prompt.d.ts.map +1 -1
  106. package/dist/system-prompt.js +45 -10
  107. package/dist/system-prompt.js.map +1 -1
  108. package/dist/tools/bash.d.ts +4 -1
  109. package/dist/tools/bash.d.ts.map +1 -1
  110. package/dist/tools/bash.js +58 -5
  111. package/dist/tools/bash.js.map +1 -1
  112. package/dist/tools/edit.d.ts +4 -1
  113. package/dist/tools/edit.d.ts.map +1 -1
  114. package/dist/tools/edit.js +9 -5
  115. package/dist/tools/edit.js.map +1 -1
  116. package/dist/tools/enter-plan.d.ts +8 -0
  117. package/dist/tools/enter-plan.d.ts.map +1 -0
  118. package/dist/tools/enter-plan.js +28 -0
  119. package/dist/tools/enter-plan.js.map +1 -0
  120. package/dist/tools/exit-plan.d.ts +8 -0
  121. package/dist/tools/exit-plan.d.ts.map +1 -0
  122. package/dist/tools/exit-plan.js +35 -0
  123. package/dist/tools/exit-plan.js.map +1 -0
  124. package/dist/tools/grep.d.ts +2 -1
  125. package/dist/tools/grep.d.ts.map +1 -1
  126. package/dist/tools/grep.js +7 -8
  127. package/dist/tools/grep.js.map +1 -1
  128. package/dist/tools/index.d.ts +17 -0
  129. package/dist/tools/index.d.ts.map +1 -1
  130. package/dist/tools/index.js +26 -7
  131. package/dist/tools/index.js.map +1 -1
  132. package/dist/tools/ls.d.ts +2 -1
  133. package/dist/tools/ls.d.ts.map +1 -1
  134. package/dist/tools/ls.js +4 -4
  135. package/dist/tools/ls.js.map +1 -1
  136. package/dist/tools/operations.d.ts +39 -0
  137. package/dist/tools/operations.d.ts.map +1 -0
  138. package/dist/tools/operations.js +27 -0
  139. package/dist/tools/operations.js.map +1 -0
  140. package/dist/tools/path-utils.d.ts +5 -0
  141. package/dist/tools/path-utils.d.ts.map +1 -1
  142. package/dist/tools/path-utils.js +18 -0
  143. package/dist/tools/path-utils.js.map +1 -1
  144. package/dist/tools/plan-mode.test.d.ts +2 -0
  145. package/dist/tools/plan-mode.test.d.ts.map +1 -0
  146. package/dist/tools/plan-mode.test.js +214 -0
  147. package/dist/tools/plan-mode.test.js.map +1 -0
  148. package/dist/tools/read.d.ts +2 -1
  149. package/dist/tools/read.d.ts.map +1 -1
  150. package/dist/tools/read.js +6 -5
  151. package/dist/tools/read.js.map +1 -1
  152. package/dist/tools/skill.d.ts +10 -0
  153. package/dist/tools/skill.d.ts.map +1 -0
  154. package/dist/tools/skill.js +36 -0
  155. package/dist/tools/skill.js.map +1 -0
  156. package/dist/tools/subagent.d.ts +3 -1
  157. package/dist/tools/subagent.d.ts.map +1 -1
  158. package/dist/tools/subagent.js +46 -4
  159. package/dist/tools/subagent.js.map +1 -1
  160. package/dist/tools/tasks.d.ts +2 -2
  161. package/dist/tools/web-fetch.d.ts.map +1 -1
  162. package/dist/tools/web-fetch.js +47 -0
  163. package/dist/tools/web-fetch.js.map +1 -1
  164. package/dist/tools/write.d.ts +4 -1
  165. package/dist/tools/write.d.ts.map +1 -1
  166. package/dist/tools/write.js +17 -6
  167. package/dist/tools/write.js.map +1 -1
  168. package/dist/ui/App.d.ts +35 -1
  169. package/dist/ui/App.d.ts.map +1 -1
  170. package/dist/ui/App.js +367 -73
  171. package/dist/ui/App.js.map +1 -1
  172. package/dist/ui/components/ActivityIndicator.d.ts +2 -1
  173. package/dist/ui/components/ActivityIndicator.d.ts.map +1 -1
  174. package/dist/ui/components/ActivityIndicator.js +25 -4
  175. package/dist/ui/components/ActivityIndicator.js.map +1 -1
  176. package/dist/ui/components/AnimationContext.d.ts +22 -0
  177. package/dist/ui/components/AnimationContext.d.ts.map +1 -0
  178. package/dist/ui/components/AnimationContext.js +35 -0
  179. package/dist/ui/components/AnimationContext.js.map +1 -0
  180. package/dist/ui/components/AssistantMessage.d.ts.map +1 -1
  181. package/dist/ui/components/AssistantMessage.js +6 -1
  182. package/dist/ui/components/AssistantMessage.js.map +1 -1
  183. package/dist/ui/components/Banner.d.ts.map +1 -1
  184. package/dist/ui/components/Banner.js +4 -7
  185. package/dist/ui/components/Banner.js.map +1 -1
  186. package/dist/ui/components/CompactionNotice.d.ts.map +1 -1
  187. package/dist/ui/components/CompactionNotice.js +4 -8
  188. package/dist/ui/components/CompactionNotice.js.map +1 -1
  189. package/dist/ui/components/Footer.d.ts +2 -1
  190. package/dist/ui/components/Footer.d.ts.map +1 -1
  191. package/dist/ui/components/Footer.js +8 -15
  192. package/dist/ui/components/Footer.js.map +1 -1
  193. package/dist/ui/components/InputArea.d.ts +3 -1
  194. package/dist/ui/components/InputArea.d.ts.map +1 -1
  195. package/dist/ui/components/InputArea.js +23 -25
  196. package/dist/ui/components/InputArea.js.map +1 -1
  197. package/dist/ui/components/PlanApproval.d.ts +8 -0
  198. package/dist/ui/components/PlanApproval.d.ts.map +1 -0
  199. package/dist/ui/components/PlanApproval.js +44 -0
  200. package/dist/ui/components/PlanApproval.js.map +1 -0
  201. package/dist/ui/components/PlanBanner.d.ts +6 -0
  202. package/dist/ui/components/PlanBanner.d.ts.map +1 -0
  203. package/dist/ui/components/PlanBanner.js +14 -0
  204. package/dist/ui/components/PlanBanner.js.map +1 -0
  205. package/dist/ui/components/PlanOverlay.d.ts +11 -0
  206. package/dist/ui/components/PlanOverlay.d.ts.map +1 -0
  207. package/dist/ui/components/PlanOverlay.js +263 -0
  208. package/dist/ui/components/PlanOverlay.js.map +1 -0
  209. package/dist/ui/components/ServerToolExecution.d.ts +1 -0
  210. package/dist/ui/components/ServerToolExecution.d.ts.map +1 -1
  211. package/dist/ui/components/ServerToolExecution.js +12 -3
  212. package/dist/ui/components/ServerToolExecution.js.map +1 -1
  213. package/dist/ui/components/SkillsOverlay.d.ts +7 -0
  214. package/dist/ui/components/SkillsOverlay.d.ts.map +1 -0
  215. package/dist/ui/components/SkillsOverlay.js +158 -0
  216. package/dist/ui/components/SkillsOverlay.js.map +1 -0
  217. package/dist/ui/components/Spinner.d.ts.map +1 -1
  218. package/dist/ui/components/Spinner.js +5 -9
  219. package/dist/ui/components/Spinner.js.map +1 -1
  220. package/dist/ui/components/StreamingArea.d.ts +2 -1
  221. package/dist/ui/components/StreamingArea.d.ts.map +1 -1
  222. package/dist/ui/components/StreamingArea.js +11 -4
  223. package/dist/ui/components/StreamingArea.js.map +1 -1
  224. package/dist/ui/components/SubAgentPanel.d.ts.map +1 -1
  225. package/dist/ui/components/SubAgentPanel.js +27 -29
  226. package/dist/ui/components/SubAgentPanel.js.map +1 -1
  227. package/dist/ui/components/TaskOverlay.d.ts.map +1 -1
  228. package/dist/ui/components/TaskOverlay.js +7 -3
  229. package/dist/ui/components/TaskOverlay.js.map +1 -1
  230. package/dist/ui/components/ThinkingBlock.d.ts.map +1 -1
  231. package/dist/ui/components/ThinkingBlock.js +4 -1
  232. package/dist/ui/components/ThinkingBlock.js.map +1 -1
  233. package/dist/ui/components/ThinkingIndicator.d.ts.map +1 -1
  234. package/dist/ui/components/ThinkingIndicator.js +8 -33
  235. package/dist/ui/components/ThinkingIndicator.js.map +1 -1
  236. package/dist/ui/components/ToolExecution.d.ts.map +1 -1
  237. package/dist/ui/components/ToolExecution.js +95 -41
  238. package/dist/ui/components/ToolExecution.js.map +1 -1
  239. package/dist/ui/components/ToolGroupExecution.d.ts +7 -0
  240. package/dist/ui/components/ToolGroupExecution.d.ts.map +1 -0
  241. package/dist/ui/components/ToolGroupExecution.js +115 -0
  242. package/dist/ui/components/ToolGroupExecution.js.map +1 -0
  243. package/dist/ui/components/UserMessage.js +1 -1
  244. package/dist/ui/components/UserMessage.js.map +1 -1
  245. package/dist/ui/components/index.d.ts +1 -0
  246. package/dist/ui/components/index.d.ts.map +1 -1
  247. package/dist/ui/components/index.js +1 -0
  248. package/dist/ui/components/index.js.map +1 -1
  249. package/dist/ui/hooks/useAgentLoop.d.ts +8 -0
  250. package/dist/ui/hooks/useAgentLoop.d.ts.map +1 -1
  251. package/dist/ui/hooks/useAgentLoop.js +320 -220
  252. package/dist/ui/hooks/useAgentLoop.js.map +1 -1
  253. package/dist/ui/hooks/useTerminalSize.d.ts +21 -9
  254. package/dist/ui/hooks/useTerminalSize.d.ts.map +1 -1
  255. package/dist/ui/hooks/useTerminalSize.js +33 -16
  256. package/dist/ui/hooks/useTerminalSize.js.map +1 -1
  257. package/dist/ui/hooks/useTerminalTitle.d.ts.map +1 -1
  258. package/dist/ui/hooks/useTerminalTitle.js +8 -16
  259. package/dist/ui/hooks/useTerminalTitle.js.map +1 -1
  260. package/dist/ui/live-item-flush.d.ts +11 -1
  261. package/dist/ui/live-item-flush.d.ts.map +1 -1
  262. package/dist/ui/live-item-flush.js +81 -2
  263. package/dist/ui/live-item-flush.js.map +1 -1
  264. package/dist/ui/login.d.ts +1 -1
  265. package/dist/ui/login.d.ts.map +1 -1
  266. package/dist/ui/login.js +30 -6
  267. package/dist/ui/login.js.map +1 -1
  268. package/dist/ui/render.d.ts +11 -0
  269. package/dist/ui/render.d.ts.map +1 -1
  270. package/dist/ui/render.js +24 -10
  271. package/dist/ui/render.js.map +1 -1
  272. package/dist/ui/sessions.d.ts +2 -0
  273. package/dist/ui/sessions.d.ts.map +1 -0
  274. package/dist/ui/sessions.js +208 -0
  275. package/dist/ui/sessions.js.map +1 -0
  276. package/dist/ui/theme/dark.json +3 -1
  277. package/dist/ui/theme/light.json +3 -1
  278. package/dist/ui/theme/theme.d.ts +2 -0
  279. package/dist/ui/theme/theme.d.ts.map +1 -1
  280. package/dist/utils/error-handler.d.ts.map +1 -1
  281. package/dist/utils/error-handler.js +17 -5
  282. package/dist/utils/error-handler.js.map +1 -1
  283. package/dist/utils/image.d.ts.map +1 -1
  284. package/dist/utils/image.js +60 -5
  285. package/dist/utils/image.js.map +1 -1
  286. package/package.json +9 -9
@@ -1,25 +1,31 @@
1
- import { describe, it, expect } from "vitest";
2
- import { estimateTokens, estimateMessageTokens, estimateConversationTokens, } from "./token-estimator.js";
1
+ import { describe, it, expect, beforeAll } from "vitest";
2
+ import { estimateTokens, estimateMessageTokens, estimateConversationTokens, setEstimatorModel, } from "./token-estimator.js";
3
+ // Use a known model so the chars-per-token ratio is deterministic in tests.
4
+ // "claude-sonnet-4-6" → ratio = 3.2
5
+ beforeAll(() => {
6
+ setEstimatorModel("claude-sonnet-4-6");
7
+ });
3
8
  describe("estimateTokens", () => {
4
9
  it("returns 0 for empty string", () => {
5
10
  expect(estimateTokens("")).toBe(0);
6
11
  });
7
- it("estimates at ~4 chars per token", () => {
8
- expect(estimateTokens("abcd")).toBe(1);
9
- expect(estimateTokens("abcdefgh")).toBe(2);
10
- expect(estimateTokens("abc")).toBe(1); // ceil(3/4) = 1
12
+ it("estimates using model-specific ratio", () => {
13
+ // claude ratio = 3.2
14
+ expect(estimateTokens("abc")).toBe(1); // ceil(3/3.2) = 1
15
+ expect(estimateTokens("abcdefgh")).toBe(3); // ceil(8/3.2) = 3
16
+ expect(estimateTokens("a".repeat(32))).toBe(10); // ceil(32/3.2) = 10
11
17
  });
12
18
  it("handles long text", () => {
13
19
  const text = "a".repeat(1000);
14
- expect(estimateTokens(text)).toBe(250);
20
+ expect(estimateTokens(text)).toBe(313); // ceil(1000/3.2) = 313
15
21
  });
16
22
  });
17
23
  describe("estimateMessageTokens", () => {
18
24
  it("estimates string content message", () => {
19
25
  const msg = { role: "user", content: "Hello world" };
20
26
  const tokens = estimateMessageTokens(msg);
21
- // ceil(11/4) = 3 + 4 overhead = 7
22
- expect(tokens).toBe(7);
27
+ // ceil(11/3.2) = 4 + 4 overhead = 8
28
+ expect(tokens).toBe(8);
23
29
  });
24
30
  it("includes per-message overhead", () => {
25
31
  const msg = { role: "user", content: "" };
@@ -32,7 +38,7 @@ describe("estimateMessageTokens", () => {
32
38
  content: [{ type: "text", text: "Hello" }],
33
39
  };
34
40
  const tokens = estimateMessageTokens(msg);
35
- // ceil(5/4) = 2 + 4 overhead = 6
41
+ // ceil(5/3.2) = 2 + 4 overhead = 6
36
42
  expect(tokens).toBe(6);
37
43
  });
38
44
  it("estimates tool call parts", () => {
@@ -48,10 +54,10 @@ describe("estimateMessageTokens", () => {
48
54
  ],
49
55
  };
50
56
  const tokens = estimateMessageTokens(msg);
51
- // name "read_file" = ceil(9/4) = 3
52
- // args JSON '{"path":"/foo/bar.ts"}' = ceil(21/4) = 6
53
- // + 4 overhead = 13
54
- expect(tokens).toBe(13);
57
+ // name "read_file" = ceil(9/3.2) = 3
58
+ // args JSON '{"path":"/foo/bar.ts"}' = ceil(21/3.2) = 7
59
+ // + 4 overhead = 14
60
+ expect(tokens).toBe(14);
55
61
  });
56
62
  it("estimates tool result parts", () => {
57
63
  const msg = {
@@ -65,8 +71,8 @@ describe("estimateMessageTokens", () => {
65
71
  ],
66
72
  };
67
73
  const tokens = estimateMessageTokens(msg);
68
- // "file contents here" = ceil(18/4) = 5 + 4 overhead = 9
69
- expect(tokens).toBe(9);
74
+ // "file contents here" = ceil(18/3.2) = 6 + 4 overhead = 10
75
+ expect(tokens).toBe(10);
70
76
  });
71
77
  it("sums multiple content parts", () => {
72
78
  const msg = {
@@ -77,8 +83,8 @@ describe("estimateMessageTokens", () => {
77
83
  ],
78
84
  };
79
85
  const tokens = estimateMessageTokens(msg);
80
- // ceil(19/4) = 5 + ceil(4/4) = 1 + 4 overhead = 10
81
- expect(tokens).toBe(10);
86
+ // ceil(19/3.2) = 6 + ceil(4/3.2) = 2 + 4 overhead = 12
87
+ expect(tokens).toBe(12);
82
88
  });
83
89
  });
84
90
  describe("estimateConversationTokens", () => {
@@ -87,10 +93,10 @@ describe("estimateConversationTokens", () => {
87
93
  });
88
94
  it("sums all message estimates", () => {
89
95
  const messages = [
90
- { role: "system", content: "You are helpful." }, // ceil(16/4)=4 + 4 = 8
91
- { role: "user", content: "Hi" }, // ceil(2/4)=1 + 4 = 5
96
+ { role: "system", content: "You are helpful." }, // ceil(16/3.2)=5 + 4 = 9
97
+ { role: "user", content: "Hi" }, // ceil(2/3.2)=1 + 4 = 5
92
98
  ];
93
- expect(estimateConversationTokens(messages)).toBe(13);
99
+ expect(estimateConversationTokens(messages)).toBe(14);
94
100
  });
95
101
  it("handles a full conversation with tool calls", () => {
96
102
  const messages = [
@@ -112,4 +118,20 @@ describe("estimateConversationTokens", () => {
112
118
  expect(total).toBeGreaterThanOrEqual(5 * 4);
113
119
  });
114
120
  });
121
+ describe("setEstimatorModel", () => {
122
+ it("uses different ratios for different model families", () => {
123
+ const text = "a".repeat(100);
124
+ setEstimatorModel("claude-opus-4-6");
125
+ const claudeTokens = estimateTokens(text); // 100/3.2 = 32
126
+ setEstimatorModel("gpt-4.1");
127
+ const gptTokens = estimateTokens(text); // 100/3.7 = 28
128
+ setEstimatorModel("glm-5");
129
+ const glmTokens = estimateTokens(text); // 100/2.5 = 40
130
+ // GLM should estimate MORE tokens (smaller chars/token ratio = more tokens per char)
131
+ expect(glmTokens).toBeGreaterThan(claudeTokens);
132
+ expect(claudeTokens).toBeGreaterThan(gptTokens);
133
+ // Reset for other tests
134
+ setEstimatorModel("claude-sonnet-4-6");
135
+ });
136
+ });
115
137
  //# sourceMappingURL=token-estimator.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"token-estimator.test.js","sourceRoot":"","sources":["../../../src/core/compaction/token-estimator.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAG9B,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;QAC3B,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,GAAG,GAAY,EAAE,IAAI,EAAE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,YAAY,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe;QAE1D,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC7B,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe;QAEvD,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3B,MAAM,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe;QAEvD,qFAAqF;QACrF,MAAM,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;QAChD,MAAM,CAAC,YAAY,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAEhD,wBAAwB;QACxB,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -67,6 +67,10 @@ export interface BusEventMap {
67
67
  originalCount: number;
68
68
  newCount: number;
69
69
  };
70
+ branch_created: {
71
+ leafId: string;
72
+ messagesKept: number;
73
+ };
70
74
  user_input: {
71
75
  content: string;
72
76
  };
@@ -83,6 +87,8 @@ export declare class EventBus {
83
87
  off<K extends EventKey>(event: K, handler: EventHandler<K>): void;
84
88
  emit<K extends EventKey>(event: K, payload: BusEventMap[K]): void;
85
89
  once<K extends EventKey>(event: K, handler: EventHandler<K>): () => void;
90
+ /** Remove all listeners, freeing closures that may retain large scopes. */
91
+ removeAllListeners(): void;
86
92
  forwardAgentEvent(event: AgentEvent): void;
87
93
  }
88
94
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../../src/core/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,MAAM,WAAW,WAAW;IAE1B,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,cAAc,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAA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E,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAQjE,IAAI,CAAC,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAQxE,2EAA2E;IAC3E,kBAAkB,IAAI,IAAI;IAO1B,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;CA6D3C"}
@@ -27,6 +27,13 @@ export class EventBus {
27
27
  };
28
28
  return this.on(event, wrapper);
29
29
  }
30
+ /** Remove all listeners, freeing closures that may retain large scopes. */
31
+ removeAllListeners() {
32
+ for (const set of this.listeners.values()) {
33
+ set.clear();
34
+ }
35
+ this.listeners.clear();
36
+ }
30
37
  forwardAgentEvent(event) {
31
38
  switch (event.type) {
32
39
  case "text_delta":
@@ -1 +1 @@
1
- {"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../src/core/event-bus.ts"],"names":[],"mappings":"AA6CA,8DAA8D;AAE9D,MAAM,OAAO,QAAQ;IACnB,8DAA8D;IACtD,SAAS,GAAG,IAAI,GAAG,EAAyC,CAAC;IAErE,EAAE,CAAqB,KAAQ,EAAE,OAAwB;QACvD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,GAAG,CAAqB,KAAQ,EAAE,OAAwB;QACxD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7C,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AI,CAAC,UAAU,EAAE;oBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,YAAY;gBACf,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;oBACtB,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;iBAC7B,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,kBAAkB;gBACrB,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;oBAC5B,EAAE,EAAE,KAAK,CAAC,EAAE;oBACZ,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;iBACnB,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,oBAAoB;gBACvB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;oBAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;oBAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAC;gBACH,MAAM;YACR,KAAK,OAAO;gBACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;gBAC3C,MAAM;QACV,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Simple file-based lock with PID tracking and stale detection.
3
+ * Uses atomic file creation (wx flag) to prevent races.
4
+ */
5
+ export declare function withFileLock<T>(filePath: string, fn: () => Promise<T>): Promise<T>;
6
+ //# sourceMappingURL=file-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-lock.d.ts","sourceRoot":"","sources":["../../src/core/file-lock.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAQxF"}
@@ -0,0 +1,76 @@
1
+ import fs from "node:fs/promises";
2
+ import { setTimeout } from "node:timers/promises";
3
+ const STALE_TIMEOUT_MS = 10_000; // Lock is stale after 10s
4
+ const RETRY_INTERVAL_MS = 50; // Retry every 50ms
5
+ const MAX_WAIT_MS = 5_000; // Give up after 5s
6
+ /**
7
+ * Simple file-based lock with PID tracking and stale detection.
8
+ * Uses atomic file creation (wx flag) to prevent races.
9
+ */
10
+ export async function withFileLock(filePath, fn) {
11
+ const lockPath = filePath + ".lock";
12
+ await acquireLock(lockPath);
13
+ try {
14
+ return await fn();
15
+ }
16
+ finally {
17
+ await releaseLock(lockPath);
18
+ }
19
+ }
20
+ async function acquireLock(lockPath) {
21
+ const startTime = Date.now();
22
+ while (true) {
23
+ try {
24
+ // O_EXCL: fail if file exists — atomic lock acquisition
25
+ const info = { pid: process.pid, timestamp: Date.now() };
26
+ await fs.writeFile(lockPath, JSON.stringify(info), { flag: "wx" });
27
+ return; // Lock acquired
28
+ }
29
+ catch (err) {
30
+ if (err.code !== "EEXIST")
31
+ throw err;
32
+ // Lock file exists — check if it's stale
33
+ try {
34
+ const content = await fs.readFile(lockPath, "utf-8");
35
+ const info = JSON.parse(content);
36
+ // Check if the holding process is still alive
37
+ const isProcessAlive = isAlive(info.pid);
38
+ const isStale = Date.now() - info.timestamp > STALE_TIMEOUT_MS;
39
+ if (!isProcessAlive || isStale) {
40
+ // Stale lock — remove and retry
41
+ await fs.unlink(lockPath).catch(() => { });
42
+ continue;
43
+ }
44
+ }
45
+ catch {
46
+ // Corrupt lock file — remove and retry
47
+ await fs.unlink(lockPath).catch(() => { });
48
+ continue;
49
+ }
50
+ // Lock is held by a live process — wait and retry
51
+ if (Date.now() - startTime > MAX_WAIT_MS) {
52
+ // Timeout — force break the lock (better than deadlocking)
53
+ await fs.unlink(lockPath).catch(() => { });
54
+ continue;
55
+ }
56
+ await setTimeout(RETRY_INTERVAL_MS);
57
+ }
58
+ }
59
+ }
60
+ async function releaseLock(lockPath) {
61
+ await fs.unlink(lockPath).catch(() => { });
62
+ }
63
+ function isAlive(pid) {
64
+ try {
65
+ process.kill(pid, 0); // Signal 0 = check existence without killing
66
+ return true;
67
+ }
68
+ catch (err) {
69
+ // EPERM = process exists but belongs to a different user — still alive
70
+ if (err.code === "EPERM")
71
+ return true;
72
+ // ESRCH = no such process — it's dead
73
+ return false;
74
+ }
75
+ }
76
+ //# sourceMappingURL=file-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../../src/core/file-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,gBAAgB,GAAG,MAAM,CAAC,CAAC,0BAA0B;AAC3D,MAAM,iBAAiB,GAAG,EAAE,CAAC,CAAC,mBAAmB;AACjD,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,mBAAmB;AAO9C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAI,QAAgB,EAAE,EAAoB;IAC1E,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC5B,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,QAAgB;IACzC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,wDAAwD;YACxD,MAAM,IAAI,GAAa,EAAE,GAAG,EAAE,O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C,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBAC1C,SAAS;YACX,CAAC;YAED,MAAM,UAAU,CAAC,iBAAiB,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,QAAgB;IACzC,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,OAAO,CAAC,GAAW;IAC1B,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,6CAA6C;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,uEAAuE;QACvE,IAAK,GAA6B,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;QACjE,sCAAsC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -2,7 +2,7 @@ export { EventBus, type BusEventMap } from "./event-bus.js";
2
2
  export { MODELS, getModel, getModelsForProvider, getDefaultModel, getContextWindow, type ModelInfo, } from "./model-registry.js";
3
3
  export { AuthStorage, NotLoggedInError } from "./auth-storage.js";
4
4
  export { SettingsManager, DEFAULT_SETTINGS, type Settings } from "./settings-manager.js";
5
- export { SessionManager, type SessionEntry, type MessageEntry, type SessionInfo, type SessionHeader, } from "./session-manager.js";
5
+ export { SessionManager, type SessionEntry, type MessageEntry, type SessionInfo, type SessionHeader, type BranchInfo, } from "./session-manager.js";
6
6
  export { AgentSession, type AgentSessionOptions, type AgentSessionState } from "./agent-session.js";
7
7
  export { SlashCommandRegistry, createBuiltinCommands, type SlashCommand, type SlashCommandContext, } from "./slash-commands.js";
8
8
  export { discoverSkills, parseSkillFile, formatSkillsForPrompt, type Skill } from "./skills.js";
@@ -10,5 +10,5 @@ export { ExtensionLoader } from "./extensions/loader.js";
10
10
  export type { Extension, ExtensionContext, ExtensionFactory } from "./extensions/types.js";
11
11
  export { shouldCompact, compact, type CompactionResult } from "./compaction/compactor.js";
12
12
  export { initLogger, log, attachToEventBus, closeLogger } from "./logger.js";
13
- export { estimateTokens, estimateMessageTokens, estimateConversationTokens, } from "./compaction/token-estimator.js";
13
+ export { estimateTokens, estimateMessageTokens, estimateConversationTokens, setEstimatorModel, } from "./compaction/token-estimator.js";
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,MAAM,EACN,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,KAAK,SAAS,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACzF,OAAO,EACL,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBA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AAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC"}
@@ -9,5 +9,5 @@ export { discoverSkills, parseSkillFile, formatSkillsForPrompt } from "./skills.
9
9
  export { ExtensionLoader } from "./extensions/loader.js";
10
10
  export { shouldCompact, compact } from "./compaction/compactor.js";
11
11
  export { initLogger, log, attachToEventBus, closeLogger } from "./logger.js";
12
- export { estimateTokens, estimateMessageTokens, estimateConversationTokens, } from "./compaction/token-estimator.js";
12
+ export { estimateTokens, estimateMessageTokens, estimateConversationTokens, setEstimatorModel, } from "./compaction/token-estimator.js";
13
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,MAAM,EACN,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAiB,MAAM,uBAAuB,CAAC;AACzF,OAAO,EACL,cAAc,GAKf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAoD,MAAM,oBAAoB,CAAC;AACpG,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GAGtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAyB,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,MAAM,EACN,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAiB,MAAM,uBAAuB,CAAC;AACzF,OAAO,EACL,cAAc,GAMf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAoD,MAAM,oBAAoB,CAAC;AACpG,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GAGtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAyB,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC"}
@@ -2,34 +2,8 @@ import type { AgentTool } from "@prestyj/agent";
2
2
  import type { MCPServerConfig } from "./types.js";
3
3
  export declare class MCPClientManager {
4
4
  private servers;
5
- private pending;
6
- /**
7
- * Connect servers that can be connected eagerly (non-lazy),
8
- * and register lazy placeholder tools for the rest.
9
- *
10
- * Servers with `lazy: true` in their config (or all servers by default
11
- * when using `registerLazy`) won't connect until a tool is actually invoked.
12
- */
13
5
  connectAll(configs: MCPServerConfig[]): Promise<AgentTool[]>;
14
- /**
15
- * Register servers lazily — no connections are made until a tool is invoked.
16
- * Returns placeholder tools that trigger connection on first execute().
17
- */
18
- registerLazy(configs: MCPServerConfig[]): AgentTool[];
19
- /**
20
- * Create a placeholder tool for a lazy server.
21
- * The tool name uses the server name, and on first call it connects,
22
- * discovers the real tools, and delegates to the right one.
23
- */
24
- private createLazyTool;
25
- /**
26
- * Ensure a pending server is connected. Uses a shared promise to avoid
27
- * duplicate connections if multiple calls arrive concurrently.
28
- */
29
- private ensureConnected;
30
- private connectPending;
31
6
  private connectServer;
32
- private createConnection;
33
7
  dispose(): Promise<void>;
34
8
  }
35
9
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/core/mcp/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAsBlD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,OAAO,CAAuB;IAEtC;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAsBlE;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE;IAmBrD;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAyDtB;;;OAGG;YACW,eAAe;YASf,cAAc;YAqBd,aAAa;YA6Cb,gBAAgB;IA4CxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAW/B"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/core/mcp/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAQlD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAyB;IAElC,UAAU,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YAsBpD,aAAa;IAkFrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAU/B"}
@@ -6,14 +6,6 @@ import { z } from "zod";
6
6
  import { log } from "../logger.js";
7
7
  export class MCPClientManager {
8
8
  servers = [];
9
- pending = [];
10
- /**
11
- * Connect servers that can be connected eagerly (non-lazy),
12
- * and register lazy placeholder tools for the rest.
13
- *
14
- * Servers with `lazy: true` in their config (or all servers by default
15
- * when using `registerLazy`) won't connect until a tool is actually invoked.
16
- */
17
9
  async connectAll(configs) {
18
10
  const enabled = configs.filter((c) => c.enabled !== false);
19
11
  if (enabled.length === 0)
@@ -34,142 +26,12 @@ export class MCPClientManager {
34
26
  log("INFO", "mcp", `Connected ${this.servers.length} MCP server(s), ${tools.length} tool(s)`);
35
27
  return tools;
36
28
  }
37
- /**
38
- * Register servers lazily — no connections are made until a tool is invoked.
39
- * Returns placeholder tools that trigger connection on first execute().
40
- */
41
- registerLazy(configs) {
42
- const enabled = configs.filter((c) => c.enabled !== false);
43
- if (enabled.length === 0)
44
- return [];
45
- const tools = [];
46
- for (const config of enabled) {
47
- const pending = { config };
48
- this.pending.push(pending);
49
- tools.push(this.createLazyTool(config, pending));
50
- }
51
- log("INFO", "mcp", `Registered ${enabled.length} lazy MCP server(s) (will connect on first use)`);
52
- return tools;
53
- }
54
- /**
55
- * Create a placeholder tool for a lazy server.
56
- * The tool name uses the server name, and on first call it connects,
57
- * discovers the real tools, and delegates to the right one.
58
- */
59
- createLazyTool(config, pending) {
60
- const toolName = `mcp__${config.name}`;
61
- return {
62
- name: toolName,
63
- description: `MCP server "${config.name}" (connects on first use). Call with {"tool": "<tool_name>", ...args} to invoke a tool on this server.`,
64
- parameters: z.record(z.string(), z.unknown()),
65
- rawInputSchema: {
66
- type: "object",
67
- properties: {
68
- tool: { type: "string", description: "The tool name to call on this MCP server" },
69
- },
70
- additionalProperties: true,
71
- },
72
- execute: async (args) => {
73
- try {
74
- await this.ensureConnected(pending);
75
- const callArgs = args;
76
- const targetTool = callArgs.tool ?? "";
77
- if (!targetTool) {
78
- // List available tools
79
- const toolList = pending.tools ? [...pending.tools.keys()].join(", ") : "none";
80
- return `Available tools on "${config.name}": ${toolList}`;
81
- }
82
- // Find the original tool name
83
- const originalName = pending.tools?.get(targetTool) ?? targetTool;
84
- const { tool: _, ...toolArgs } = callArgs;
85
- const result = await pending.client.callTool({ name: originalName, arguments: toolArgs }, undefined, { timeout: config.timeout ?? 60_000 });
86
- if (!("content" in result) || !Array.isArray(result.content)) {
87
- return "(empty response)";
88
- }
89
- const texts = [];
90
- for (const item of result.content) {
91
- if (item != null &&
92
- typeof item === "object" &&
93
- "text" in item &&
94
- typeof item.text === "string") {
95
- texts.push(item.text);
96
- }
97
- }
98
- return texts.join("\n") || "(empty response)";
99
- }
100
- catch (err) {
101
- return `MCP tool error: ${err instanceof Error ? err.message : String(err)}`;
102
- }
103
- },
104
- };
105
- }
106
- /**
107
- * Ensure a pending server is connected. Uses a shared promise to avoid
108
- * duplicate connections if multiple calls arrive concurrently.
109
- */
110
- async ensureConnected(pending) {
111
- if (pending.client)
112
- return; // Already connected
113
- if (!pending.connectPromise) {
114
- pending.connectPromise = this.connectPending(pending);
115
- }
116
- await pending.connectPromise;
117
- }
118
- async connectPending(pending) {
119
- const config = pending.config;
120
- const timeout = config.timeout ?? 30_000;
121
- log("INFO", "mcp", `Lazy-connecting MCP server "${config.name}"...`);
122
- const { client, transport } = await this.createConnection(config, timeout);
123
- pending.client = client;
124
- pending.transport = transport;
125
- this.servers.push({ name: config.name, client, transport });
126
- const { tools } = await client.listTools(undefined, { timeout });
127
- pending.tools = new Map();
128
- for (const tool of tools) {
129
- pending.tools.set(tool.name, tool.name);
130
- }
131
- log("INFO", "mcp", `Lazy-connected MCP server "${config.name}" with ${tools.length} tool(s)`);
132
- }
133
29
  async connectServer(config) {
134
30
  const timeout = config.timeout ?? 30_000;
135
- const { client, transport } = await this.createConnection(config, timeout);
136
- this.servers.push({ name: config.name, client, transport });
137
- const { tools } = await client.listTools(undefined, { timeout });
138
- return tools.map((tool) => {
139
- const toolName = `mcp__${config.name}__${tool.name}`;
140
- return {
141
- name: toolName,
142
- description: tool.description ?? "",
143
- parameters: z.record(z.string(), z.unknown()),
144
- rawInputSchema: tool.inputSchema,
145
- execute: async (args) => {
146
- try {
147
- const result = await client.callTool({ name: tool.name, arguments: args }, undefined, { timeout: config.timeout ?? 60_000 });
148
- if (!("content" in result) || !Array.isArray(result.content)) {
149
- return "(empty response)";
150
- }
151
- const texts = [];
152
- for (const item of result.content) {
153
- if (item != null &&
154
- typeof item === "object" &&
155
- "text" in item &&
156
- typeof item.text === "string") {
157
- texts.push(item.text);
158
- }
159
- }
160
- return texts.join("\n") || "(empty response)";
161
- }
162
- catch (err) {
163
- return `MCP tool error: ${err instanceof Error ? err.message : String(err)}`;
164
- }
165
- },
166
- };
167
- });
168
- }
169
- async createConnection(config, timeout) {
170
31
  let client;
171
32
  let transport;
172
33
  if (config.command) {
34
+ // Stdio transport for local processes
173
35
  transport = new StdioClientTransport({
174
36
  command: config.command,
175
37
  args: config.args,
@@ -180,6 +42,7 @@ export class MCPClientManager {
180
42
  await client.connect(transport, { timeout });
181
43
  }
182
44
  else {
45
+ // HTTP transport — try StreamableHTTP first, fall back to SSE
183
46
  const url = new URL(config.url);
184
47
  const reqInit = config.headers ? { headers: config.headers } : undefined;
185
48
  try {
@@ -203,7 +66,38 @@ export class MCPClientManager {
203
66
  await client.connect(transport, { timeout });
204
67
  }
205
68
  }
206
- return { client, transport };
69
+ this.servers.push({ name: config.name, client, transport });
70
+ const { tools } = await client.listTools(undefined, { timeout });
71
+ return tools.map((tool) => {
72
+ const toolName = `mcp__${config.name}__${tool.name}`;
73
+ return {
74
+ name: toolName,
75
+ description: tool.description ?? "",
76
+ parameters: z.record(z.string(), z.unknown()),
77
+ rawInputSchema: tool.inputSchema,
78
+ execute: async (args) => {
79
+ try {
80
+ const result = await client.callTool({ name: tool.name, arguments: args }, undefined, { timeout: config.timeout ?? 60_000 });
81
+ if (!("content" in result) || !Array.isArray(result.content)) {
82
+ return "(empty response)";
83
+ }
84
+ const texts = [];
85
+ for (const item of result.content) {
86
+ if (item != null &&
87
+ typeof item === "object" &&
88
+ "text" in item &&
89
+ typeof item.text === "string") {
90
+ texts.push(item.text);
91
+ }
92
+ }
93
+ return texts.join("\n") || "(empty response)";
94
+ }
95
+ catch (err) {
96
+ return `MCP tool error: ${err instanceof Error ? err.message : String(err)}`;
97
+ }
98
+ },
99
+ };
100
+ });
207
101
  }
208
102
  async dispose() {
209
103
  for (const server of this.servers) {
@@ -215,7 +109,6 @@ export class MCPClientManager {
215
109
  }
216
110
  }
217
111
  this.servers = [];
218
- this.pending = [];
219
112
  }
220
113
  }
221
114
  /**