@bubblebrain-ai/bubble 0.0.12 → 0.0.14

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 (180) hide show
  1. package/dist/agent/execution-governor.js +1 -1
  2. package/dist/agent/input-controller.d.ts +11 -0
  3. package/dist/agent/input-controller.js +30 -0
  4. package/dist/agent/tool-intent.js +1 -0
  5. package/dist/agent.d.ts +8 -4
  6. package/dist/agent.js +623 -312
  7. package/dist/approval/controller.d.ts +1 -0
  8. package/dist/approval/controller.js +20 -3
  9. package/dist/approval/tool-helper.js +2 -0
  10. package/dist/approval/types.d.ts +14 -1
  11. package/dist/context/compact.js +9 -3
  12. package/dist/context/projector.js +27 -12
  13. package/dist/debug-trace.d.ts +27 -0
  14. package/dist/debug-trace.js +385 -0
  15. package/dist/feishu/agent-host/approval-card.js +9 -0
  16. package/dist/feishu/serve.js +7 -1
  17. package/dist/main.js +86 -9
  18. package/dist/model-catalog.js +1 -0
  19. package/dist/orchestrator/default-hooks.js +19 -8
  20. package/dist/orchestrator/hooks.d.ts +1 -0
  21. package/dist/prompt/environment.js +2 -0
  22. package/dist/prompt/reminders.d.ts +5 -6
  23. package/dist/prompt/reminders.js +8 -9
  24. package/dist/prompt/runtime.js +2 -2
  25. package/dist/provider-openai-codex.d.ts +7 -0
  26. package/dist/provider-openai-codex.js +265 -124
  27. package/dist/provider-registry.d.ts +2 -0
  28. package/dist/provider-registry.js +58 -9
  29. package/dist/provider.d.ts +3 -0
  30. package/dist/provider.js +5 -1
  31. package/dist/session-log.js +13 -1
  32. package/dist/slash-commands/commands.js +39 -0
  33. package/dist/slash-commands/types.d.ts +12 -0
  34. package/dist/stats/usage.d.ts +52 -0
  35. package/dist/stats/usage.js +414 -0
  36. package/dist/tools/apply-patch.d.ts +9 -0
  37. package/dist/tools/apply-patch.js +330 -0
  38. package/dist/tools/bash.js +205 -44
  39. package/dist/tools/edit-apply.d.ts +5 -2
  40. package/dist/tools/edit-apply.js +221 -31
  41. package/dist/tools/edit.js +12 -3
  42. package/dist/tools/file-mutation-queue.d.ts +1 -0
  43. package/dist/tools/file-mutation-queue.js +12 -1
  44. package/dist/tools/index.d.ts +2 -0
  45. package/dist/tools/index.js +7 -1
  46. package/dist/tools/patch-apply.d.ts +41 -0
  47. package/dist/tools/patch-apply.js +312 -0
  48. package/dist/tools/server-manager.d.ts +36 -0
  49. package/dist/tools/server-manager.js +234 -0
  50. package/dist/tools/server.d.ts +6 -0
  51. package/dist/tools/server.js +245 -0
  52. package/dist/tools/write.d.ts +3 -6
  53. package/dist/tools/write.js +26 -46
  54. package/dist/tui/clipboard.d.ts +1 -0
  55. package/dist/tui/clipboard.js +53 -0
  56. package/dist/tui/detect-theme.d.ts +2 -0
  57. package/dist/tui/detect-theme.js +87 -0
  58. package/dist/tui/display-history.d.ts +63 -0
  59. package/dist/tui/display-history.js +306 -0
  60. package/dist/tui/edit-diff.d.ts +11 -0
  61. package/dist/tui/edit-diff.js +57 -0
  62. package/dist/tui/escape-confirmation.d.ts +15 -0
  63. package/dist/tui/escape-confirmation.js +30 -0
  64. package/dist/tui/file-mentions.d.ts +29 -0
  65. package/dist/tui/file-mentions.js +174 -0
  66. package/dist/tui/global-key-router.d.ts +3 -0
  67. package/dist/tui/global-key-router.js +87 -0
  68. package/dist/tui/image-paste.d.ts +95 -0
  69. package/dist/tui/image-paste.js +505 -0
  70. package/dist/tui/input-history.d.ts +16 -0
  71. package/dist/tui/input-history.js +79 -0
  72. package/dist/tui/markdown-inline.d.ts +22 -0
  73. package/dist/tui/markdown-inline.js +68 -0
  74. package/dist/tui/markdown-theme-rules.d.ts +23 -0
  75. package/dist/tui/markdown-theme-rules.js +164 -0
  76. package/dist/tui/markdown-theme.d.ts +5 -0
  77. package/dist/tui/markdown-theme.js +27 -0
  78. package/dist/tui/model-picker-data.d.ts +10 -0
  79. package/dist/tui/model-picker-data.js +32 -0
  80. package/dist/tui/opencode-spinner.d.ts +22 -0
  81. package/dist/tui/opencode-spinner.js +216 -0
  82. package/dist/tui/prompt-keybindings.d.ts +42 -0
  83. package/dist/tui/prompt-keybindings.js +35 -0
  84. package/dist/tui/recent-activity.d.ts +8 -0
  85. package/dist/tui/recent-activity.js +71 -0
  86. package/dist/tui/render-signature.d.ts +1 -0
  87. package/dist/tui/render-signature.js +7 -0
  88. package/dist/tui/run.d.ts +45 -0
  89. package/dist/tui/run.js +9359 -0
  90. package/dist/tui/session-display.d.ts +6 -0
  91. package/dist/tui/session-display.js +12 -0
  92. package/dist/tui/sidebar-mcp.d.ts +31 -0
  93. package/dist/tui/sidebar-mcp.js +62 -0
  94. package/dist/tui/sidebar-state.d.ts +12 -0
  95. package/dist/tui/sidebar-state.js +69 -0
  96. package/dist/tui/streaming-tool-args.d.ts +15 -0
  97. package/dist/tui/streaming-tool-args.js +30 -0
  98. package/dist/tui/tool-renderers/fallback.d.ts +2 -0
  99. package/dist/tui/tool-renderers/fallback.js +75 -0
  100. package/dist/tui/tool-renderers/registry.d.ts +3 -0
  101. package/dist/tui/tool-renderers/registry.js +11 -0
  102. package/dist/tui/tool-renderers/subagent.d.ts +2 -0
  103. package/dist/tui/tool-renderers/subagent.js +135 -0
  104. package/dist/tui/tool-renderers/types.d.ts +36 -0
  105. package/dist/tui/tool-renderers/types.js +1 -0
  106. package/dist/tui/tool-renderers/write-preview.d.ts +12 -0
  107. package/dist/tui/tool-renderers/write-preview.js +32 -0
  108. package/dist/tui/tool-renderers/write.d.ts +6 -0
  109. package/dist/tui/tool-renderers/write.js +88 -0
  110. package/dist/tui/trace-groups.d.ts +27 -0
  111. package/dist/tui/trace-groups.js +419 -0
  112. package/dist/tui/wordmark.d.ts +15 -0
  113. package/dist/tui/wordmark.js +179 -0
  114. package/dist/tui-ink/app.js +45 -9
  115. package/dist/tui-ink/approval/approval-dialog.js +7 -1
  116. package/dist/tui-ink/display-history.d.ts +1 -0
  117. package/dist/tui-ink/display-history.js +5 -4
  118. package/dist/tui-ink/message-list.js +23 -9
  119. package/dist/tui-ink/theme.d.ts +3 -9
  120. package/dist/tui-ink/theme.js +39 -45
  121. package/dist/tui-ink/trace-groups.js +1 -1
  122. package/dist/tui-ink/welcome.js +22 -78
  123. package/dist/tui-opentui/app.d.ts +54 -0
  124. package/dist/tui-opentui/app.js +1365 -0
  125. package/dist/tui-opentui/approval/approval-dialog.d.ts +15 -0
  126. package/dist/tui-opentui/approval/approval-dialog.js +145 -0
  127. package/dist/tui-opentui/approval/diff-view.d.ts +9 -0
  128. package/dist/tui-opentui/approval/diff-view.js +43 -0
  129. package/dist/tui-opentui/approval/select.d.ts +37 -0
  130. package/dist/tui-opentui/approval/select.js +91 -0
  131. package/dist/tui-opentui/detect-theme.d.ts +2 -0
  132. package/dist/tui-opentui/detect-theme.js +87 -0
  133. package/dist/tui-opentui/display-history.d.ts +56 -0
  134. package/dist/tui-opentui/display-history.js +130 -0
  135. package/dist/tui-opentui/edit-diff.d.ts +11 -0
  136. package/dist/tui-opentui/edit-diff.js +57 -0
  137. package/dist/tui-opentui/feedback-dialog.d.ts +21 -0
  138. package/dist/tui-opentui/feedback-dialog.js +164 -0
  139. package/dist/tui-opentui/feishu-setup-picker.d.ts +7 -0
  140. package/dist/tui-opentui/feishu-setup-picker.js +272 -0
  141. package/dist/tui-opentui/file-mentions.d.ts +29 -0
  142. package/dist/tui-opentui/file-mentions.js +174 -0
  143. package/dist/tui-opentui/footer.d.ts +26 -0
  144. package/dist/tui-opentui/footer.js +40 -0
  145. package/dist/tui-opentui/image-paste.d.ts +54 -0
  146. package/dist/tui-opentui/image-paste.js +288 -0
  147. package/dist/tui-opentui/input-box.d.ts +34 -0
  148. package/dist/tui-opentui/input-box.js +471 -0
  149. package/dist/tui-opentui/input-history.d.ts +16 -0
  150. package/dist/tui-opentui/input-history.js +79 -0
  151. package/dist/tui-opentui/markdown.d.ts +66 -0
  152. package/dist/tui-opentui/markdown.js +127 -0
  153. package/dist/tui-opentui/message-list.d.ts +31 -0
  154. package/dist/tui-opentui/message-list.js +128 -0
  155. package/dist/tui-opentui/model-picker.d.ts +63 -0
  156. package/dist/tui-opentui/model-picker.js +450 -0
  157. package/dist/tui-opentui/plan-confirm.d.ts +9 -0
  158. package/dist/tui-opentui/plan-confirm.js +124 -0
  159. package/dist/tui-opentui/question-dialog.d.ts +10 -0
  160. package/dist/tui-opentui/question-dialog.js +110 -0
  161. package/dist/tui-opentui/recent-activity.d.ts +8 -0
  162. package/dist/tui-opentui/recent-activity.js +71 -0
  163. package/dist/tui-opentui/run-session-picker.d.ts +10 -0
  164. package/dist/tui-opentui/run-session-picker.js +28 -0
  165. package/dist/tui-opentui/run.d.ts +38 -0
  166. package/dist/tui-opentui/run.js +48 -0
  167. package/dist/tui-opentui/session-picker.d.ts +12 -0
  168. package/dist/tui-opentui/session-picker.js +120 -0
  169. package/dist/tui-opentui/theme.d.ts +89 -0
  170. package/dist/tui-opentui/theme.js +157 -0
  171. package/dist/tui-opentui/todos.d.ts +9 -0
  172. package/dist/tui-opentui/todos.js +45 -0
  173. package/dist/tui-opentui/trace-groups.d.ts +27 -0
  174. package/dist/tui-opentui/trace-groups.js +419 -0
  175. package/dist/tui-opentui/use-terminal-size.d.ts +4 -0
  176. package/dist/tui-opentui/use-terminal-size.js +5 -0
  177. package/dist/tui-opentui/welcome.d.ts +25 -0
  178. package/dist/tui-opentui/welcome.js +77 -0
  179. package/dist/types.d.ts +36 -2
  180. package/package.json +5 -1
@@ -0,0 +1,216 @@
1
+ import { RGBA } from "@opentui/core";
2
+ function getScannerState(frameIndex, totalChars, options) {
3
+ const { direction = "forward", holdFrames = {} } = options;
4
+ if (direction === "bidirectional") {
5
+ const forwardFrames = totalChars;
6
+ const holdEndFrames = holdFrames.end ?? 0;
7
+ const backwardFrames = totalChars - 1;
8
+ if (frameIndex < forwardFrames) {
9
+ return {
10
+ activePosition: frameIndex,
11
+ isHolding: false,
12
+ holdProgress: 0,
13
+ holdTotal: 0,
14
+ movementProgress: frameIndex,
15
+ movementTotal: forwardFrames,
16
+ isMovingForward: true,
17
+ };
18
+ }
19
+ if (frameIndex < forwardFrames + holdEndFrames) {
20
+ return {
21
+ activePosition: totalChars - 1,
22
+ isHolding: true,
23
+ holdProgress: frameIndex - forwardFrames,
24
+ holdTotal: holdEndFrames,
25
+ movementProgress: 0,
26
+ movementTotal: 0,
27
+ isMovingForward: true,
28
+ };
29
+ }
30
+ if (frameIndex < forwardFrames + holdEndFrames + backwardFrames) {
31
+ const backwardIndex = frameIndex - forwardFrames - holdEndFrames;
32
+ return {
33
+ activePosition: totalChars - 2 - backwardIndex,
34
+ isHolding: false,
35
+ holdProgress: 0,
36
+ holdTotal: 0,
37
+ movementProgress: backwardIndex,
38
+ movementTotal: backwardFrames,
39
+ isMovingForward: false,
40
+ };
41
+ }
42
+ return {
43
+ activePosition: 0,
44
+ isHolding: true,
45
+ holdProgress: frameIndex - forwardFrames - holdEndFrames - backwardFrames,
46
+ holdTotal: holdFrames.start ?? 0,
47
+ movementProgress: 0,
48
+ movementTotal: 0,
49
+ isMovingForward: false,
50
+ };
51
+ }
52
+ if (direction === "backward") {
53
+ return {
54
+ activePosition: totalChars - 1 - (frameIndex % totalChars),
55
+ isHolding: false,
56
+ holdProgress: 0,
57
+ holdTotal: 0,
58
+ movementProgress: frameIndex % totalChars,
59
+ movementTotal: totalChars,
60
+ isMovingForward: false,
61
+ };
62
+ }
63
+ return {
64
+ activePosition: frameIndex % totalChars,
65
+ isHolding: false,
66
+ holdProgress: 0,
67
+ holdTotal: 0,
68
+ movementProgress: frameIndex % totalChars,
69
+ movementTotal: totalChars,
70
+ isMovingForward: true,
71
+ };
72
+ }
73
+ function calculateColorIndex(frameIndex, charIndex, totalChars, options, state) {
74
+ const { trailLength } = options;
75
+ const { activePosition, isHolding, holdProgress, isMovingForward } = state ?? getScannerState(frameIndex, totalChars, options);
76
+ const directionalDistance = isMovingForward
77
+ ? activePosition - charIndex
78
+ : charIndex - activePosition;
79
+ if (isHolding)
80
+ return directionalDistance + holdProgress;
81
+ if (directionalDistance > 0 && directionalDistance < trailLength)
82
+ return directionalDistance;
83
+ if (directionalDistance === 0)
84
+ return 0;
85
+ return -1;
86
+ }
87
+ function createKnightRiderTrail(options) {
88
+ const { colors, defaultColor, enableFading = true, minAlpha = 0 } = options;
89
+ const defaultRgba = defaultColor instanceof RGBA ? defaultColor : RGBA.fromHex(defaultColor || "#000000");
90
+ const baseInactiveAlpha = defaultRgba.a;
91
+ let cachedFrameIndex = -1;
92
+ let cachedState = null;
93
+ return (frameIndex, charIndex, _totalFrames, totalChars) => {
94
+ if (frameIndex !== cachedFrameIndex) {
95
+ cachedFrameIndex = frameIndex;
96
+ cachedState = getScannerState(frameIndex, totalChars, options);
97
+ }
98
+ const state = cachedState;
99
+ const index = calculateColorIndex(frameIndex, charIndex, totalChars, options, state);
100
+ const { isHolding, holdProgress, holdTotal, movementProgress, movementTotal } = state;
101
+ let fadeFactor = 1.0;
102
+ if (enableFading) {
103
+ if (isHolding && holdTotal > 0) {
104
+ const progress = Math.min(holdProgress / holdTotal, 1);
105
+ fadeFactor = Math.max(minAlpha, 1 - progress * (1 - minAlpha));
106
+ }
107
+ else if (!isHolding && movementTotal > 0) {
108
+ const progress = Math.min(movementProgress / Math.max(1, movementTotal - 1), 1);
109
+ fadeFactor = minAlpha + progress * (1 - minAlpha);
110
+ }
111
+ }
112
+ defaultRgba.a = baseInactiveAlpha * fadeFactor;
113
+ if (index === -1)
114
+ return defaultRgba;
115
+ return colors[index] ?? defaultRgba;
116
+ };
117
+ }
118
+ export function deriveTrailColors(brightColor, steps = 6) {
119
+ const baseRgba = brightColor instanceof RGBA ? brightColor : RGBA.fromHex(brightColor);
120
+ const colors = [];
121
+ for (let i = 0; i < steps; i++) {
122
+ let alpha;
123
+ let brightnessFactor;
124
+ if (i === 0) {
125
+ alpha = 1.0;
126
+ brightnessFactor = 1.0;
127
+ }
128
+ else if (i === 1) {
129
+ alpha = 0.9;
130
+ brightnessFactor = 1.15;
131
+ }
132
+ else {
133
+ alpha = Math.pow(0.65, i - 1);
134
+ brightnessFactor = 1.0;
135
+ }
136
+ const r = Math.min(1.0, baseRgba.r * brightnessFactor);
137
+ const g = Math.min(1.0, baseRgba.g * brightnessFactor);
138
+ const b = Math.min(1.0, baseRgba.b * brightnessFactor);
139
+ colors.push(RGBA.fromValues(r, g, b, alpha));
140
+ }
141
+ return colors;
142
+ }
143
+ export function deriveInactiveColor(brightColor, factor = 0.2) {
144
+ const baseRgba = brightColor instanceof RGBA ? brightColor : RGBA.fromHex(brightColor);
145
+ return RGBA.fromValues(baseRgba.r, baseRgba.g, baseRgba.b, factor);
146
+ }
147
+ export function createFrames(options = {}) {
148
+ const width = options.width ?? 8;
149
+ const style = options.style ?? "diamonds";
150
+ const holdStart = options.holdStart ?? 30;
151
+ const holdEnd = options.holdEnd ?? 9;
152
+ const colors = options.colors ??
153
+ (options.color
154
+ ? deriveTrailColors(options.color, options.trailSteps)
155
+ : [
156
+ RGBA.fromHex("#ff0000"),
157
+ RGBA.fromHex("#ff5555"),
158
+ RGBA.fromHex("#dd0000"),
159
+ RGBA.fromHex("#aa0000"),
160
+ RGBA.fromHex("#770000"),
161
+ RGBA.fromHex("#440000"),
162
+ ]);
163
+ const defaultColor = options.defaultColor ??
164
+ (options.color ? deriveInactiveColor(options.color, options.inactiveFactor) : RGBA.fromHex("#330000"));
165
+ const trailOptions = {
166
+ colors,
167
+ trailLength: colors.length,
168
+ defaultColor,
169
+ direction: "bidirectional",
170
+ holdFrames: { start: holdStart, end: holdEnd },
171
+ enableFading: options.enableFading,
172
+ minAlpha: options.minAlpha,
173
+ };
174
+ const totalFrames = width + holdEnd + (width - 1) + holdStart;
175
+ return Array.from({ length: totalFrames }, (_, frameIndex) => {
176
+ return Array.from({ length: width }, (_, charIndex) => {
177
+ const index = calculateColorIndex(frameIndex, charIndex, width, trailOptions);
178
+ if (style === "diamonds") {
179
+ const shapes = ["⬥", "◆", "⬩", "⬪"];
180
+ if (index >= 0 && index < trailOptions.colors.length) {
181
+ return shapes[Math.min(index, shapes.length - 1)];
182
+ }
183
+ return "·";
184
+ }
185
+ const isActive = index >= 0 && index < trailOptions.colors.length;
186
+ return isActive ? "■" : "⬝";
187
+ }).join("");
188
+ });
189
+ }
190
+ export function createColors(options = {}) {
191
+ const holdStart = options.holdStart ?? 30;
192
+ const holdEnd = options.holdEnd ?? 9;
193
+ const colors = options.colors ??
194
+ (options.color
195
+ ? deriveTrailColors(options.color, options.trailSteps)
196
+ : [
197
+ RGBA.fromHex("#ff0000"),
198
+ RGBA.fromHex("#ff5555"),
199
+ RGBA.fromHex("#dd0000"),
200
+ RGBA.fromHex("#aa0000"),
201
+ RGBA.fromHex("#770000"),
202
+ RGBA.fromHex("#440000"),
203
+ ]);
204
+ const defaultColor = options.defaultColor ??
205
+ (options.color ? deriveInactiveColor(options.color, options.inactiveFactor) : RGBA.fromHex("#330000"));
206
+ const trailOptions = {
207
+ colors,
208
+ trailLength: colors.length,
209
+ defaultColor,
210
+ direction: "bidirectional",
211
+ holdFrames: { start: holdStart, end: holdEnd },
212
+ enableFading: options.enableFading,
213
+ minAlpha: options.minAlpha,
214
+ };
215
+ return createKnightRiderTrail(trailOptions);
216
+ }
@@ -0,0 +1,42 @@
1
+ export declare const PROMPT_TEXTAREA_KEYBINDINGS: ({
2
+ name: string;
3
+ action: "submit";
4
+ shift?: undefined;
5
+ ctrl?: undefined;
6
+ meta?: undefined;
7
+ } | {
8
+ name: string;
9
+ shift: true;
10
+ action: "newline";
11
+ ctrl?: undefined;
12
+ meta?: undefined;
13
+ } | {
14
+ name: string;
15
+ ctrl: true;
16
+ action: "newline";
17
+ shift?: undefined;
18
+ meta?: undefined;
19
+ } | {
20
+ name: string;
21
+ meta: true;
22
+ action: "newline";
23
+ shift?: undefined;
24
+ ctrl?: undefined;
25
+ } | {
26
+ name: string;
27
+ action: "newline";
28
+ shift?: undefined;
29
+ ctrl?: undefined;
30
+ meta?: undefined;
31
+ })[];
32
+ export declare function isModifiedEnterSequence(input: {
33
+ raw?: string;
34
+ sequence?: string;
35
+ }): boolean;
36
+ export declare function isModeCycleSequence(value?: string): boolean;
37
+ export declare function isEscapeSequence(value?: string): boolean;
38
+ export declare function isModeCycleKeyEvent(input: {
39
+ name?: string;
40
+ raw?: string;
41
+ sequence?: string;
42
+ }): boolean;
@@ -0,0 +1,35 @@
1
+ export const PROMPT_TEXTAREA_KEYBINDINGS = [
2
+ { name: "return", action: "submit" },
3
+ { name: "return", shift: true, action: "newline" },
4
+ { name: "return", ctrl: true, action: "newline" },
5
+ { name: "return", meta: true, action: "newline" },
6
+ { name: "j", ctrl: true, action: "newline" },
7
+ { name: "linefeed", action: "newline" },
8
+ ];
9
+ export function isModifiedEnterSequence(input) {
10
+ const value = input.sequence || input.raw || "";
11
+ return /^\x1b\[13;[2-9]\d*[u~]$/.test(value)
12
+ || /^\x1b\[27;[2-9]\d*;13~$/.test(value);
13
+ }
14
+ export function isModeCycleSequence(value) {
15
+ if (!value)
16
+ return false;
17
+ return value === "\t"
18
+ || value === "\x1b[Z"
19
+ || /^\x1b\[(?:9|57346);[12]u$/.test(value)
20
+ || /^\x1b\[27;2;9~$/.test(value);
21
+ }
22
+ export function isEscapeSequence(value) {
23
+ if (!value)
24
+ return false;
25
+ return value === "\x1b"
26
+ || /^\x1b\[(?:27|57344)(?:;[1-9]\d*(?::[1-3])?)?u$/.test(value)
27
+ || /^\x1b\[27;[1-9]\d*(?::[1-3])?;(?:27|57344)~$/.test(value);
28
+ }
29
+ export function isModeCycleKeyEvent(input) {
30
+ const name = String(input.name || "").toLowerCase();
31
+ return name === "tab"
32
+ || name === "backtab"
33
+ || name === "shift+tab"
34
+ || isModeCycleSequence(input.raw || input.sequence);
35
+ }
@@ -0,0 +1,8 @@
1
+ export interface RecentSession {
2
+ file: string;
3
+ modifiedAt: number;
4
+ preview: string;
5
+ }
6
+ export declare function getRecentSessions(cwd: string, limit?: number): RecentSession[];
7
+ export declare function formatRelativeTime(timestampMs: number, now?: number): string;
8
+ export declare function truncatePreview(preview: string, maxLen: number): string;
@@ -0,0 +1,71 @@
1
+ import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { getSessionsDir } from "../session.js";
4
+ export function getRecentSessions(cwd, limit = 3) {
5
+ const dir = getSessionsDir(cwd);
6
+ if (!existsSync(dir))
7
+ return [];
8
+ const files = readdirSync(dir).filter((f) => f.endsWith(".jsonl"));
9
+ const withMtime = files.map((f) => {
10
+ const full = path.join(dir, f);
11
+ try {
12
+ return { file: f, full, modifiedAt: statSync(full).mtimeMs };
13
+ }
14
+ catch {
15
+ return { file: f, full, modifiedAt: 0 };
16
+ }
17
+ });
18
+ withMtime.sort((a, b) => b.modifiedAt - a.modifiedAt);
19
+ return withMtime.slice(0, limit).map(({ file, full, modifiedAt }) => ({
20
+ file,
21
+ modifiedAt,
22
+ preview: extractFirstUserMessage(full) ?? "(no messages)",
23
+ }));
24
+ }
25
+ export function formatRelativeTime(timestampMs, now = Date.now()) {
26
+ const diffSec = Math.max(0, Math.floor((now - timestampMs) / 1000));
27
+ if (diffSec < 60)
28
+ return "just now";
29
+ if (diffSec < 3600)
30
+ return `${Math.floor(diffSec / 60)}m ago`;
31
+ if (diffSec < 86400)
32
+ return `${Math.floor(diffSec / 3600)}h ago`;
33
+ if (diffSec < 604800)
34
+ return `${Math.floor(diffSec / 86400)}d ago`;
35
+ const weeks = Math.floor(diffSec / 604800);
36
+ if (weeks < 5)
37
+ return `${weeks}w ago`;
38
+ const months = Math.floor(diffSec / (30 * 86400));
39
+ return `${months}mo ago`;
40
+ }
41
+ function extractFirstUserMessage(file) {
42
+ let raw;
43
+ try {
44
+ raw = readFileSync(file, "utf-8");
45
+ }
46
+ catch {
47
+ return null;
48
+ }
49
+ const lines = raw.split("\n");
50
+ for (const line of lines) {
51
+ if (!line.trim())
52
+ continue;
53
+ let entry;
54
+ try {
55
+ entry = JSON.parse(line);
56
+ }
57
+ catch {
58
+ continue;
59
+ }
60
+ if (entry.type === "user_message" && typeof entry.message?.content === "string") {
61
+ return entry.message.content;
62
+ }
63
+ }
64
+ return null;
65
+ }
66
+ export function truncatePreview(preview, maxLen) {
67
+ const firstLine = preview.split("\n")[0]?.trim() ?? "";
68
+ if (firstLine.length <= maxLen)
69
+ return firstLine;
70
+ return firstLine.slice(0, Math.max(1, maxLen - 1)) + "…";
71
+ }
@@ -0,0 +1 @@
1
+ export declare function hashString(value: string): string;
@@ -0,0 +1,7 @@
1
+ export function hashString(value) {
2
+ let hash = 5381;
3
+ for (let index = 0; index < value.length; index++) {
4
+ hash = ((hash << 5) + hash) ^ value.charCodeAt(index);
5
+ }
6
+ return (hash >>> 0).toString(36);
7
+ }
@@ -0,0 +1,45 @@
1
+ import { type Agent } from "../agent.js";
2
+ import type { CliArgs } from "../cli.js";
3
+ import type { ThemeMode } from "../config.js";
4
+ import type { SessionManager } from "../session.js";
5
+ import type { PlanDecision, Provider } from "../types.js";
6
+ import type { ProviderRegistry } from "../provider-registry.js";
7
+ import type { SkillRegistry } from "../skills/registry.js";
8
+ import { type LspService } from "../lsp/index.js";
9
+ import { type BashAllowlist } from "../approval/session-cache.js";
10
+ import type { SettingsManager } from "../permissions/settings.js";
11
+ import type { McpManager } from "../mcp/manager.js";
12
+ import type { ApprovalDecision, ApprovalRequest } from "../approval/types.js";
13
+ import type { QuestionController } from "../question/index.js";
14
+ import type { MemoryScope } from "../memory/index.js";
15
+ import type { ResolvedTheme } from "./detect-theme.js";
16
+ export interface PlanHandlerRef {
17
+ current?: (plan: string) => Promise<PlanDecision>;
18
+ }
19
+ export interface ApprovalHandlerRef {
20
+ current?: (req: ApprovalRequest) => Promise<ApprovalDecision>;
21
+ }
22
+ export interface RunTuiOptions {
23
+ sessionManager?: SessionManager;
24
+ createProvider?: (providerId: string, apiKey: string, baseURL: string) => Provider;
25
+ registry?: ProviderRegistry;
26
+ skillRegistry?: SkillRegistry;
27
+ planHandlerRef?: PlanHandlerRef;
28
+ approvalHandlerRef?: ApprovalHandlerRef;
29
+ questionController?: QuestionController;
30
+ bashAllowlist?: BashAllowlist;
31
+ settingsManager?: SettingsManager;
32
+ lspService?: LspService;
33
+ mcpManager?: McpManager;
34
+ themeMode?: ThemeMode;
35
+ themeOverrides?: Record<string, string>;
36
+ detectedTheme?: ResolvedTheme;
37
+ onThemeModeChange?: (mode: ThemeMode) => void;
38
+ /** Legacy dark-palette overrides. Prefer themeOverrides for new callers. */
39
+ theme?: Record<string, string>;
40
+ flushMemory?: () => Promise<void>;
41
+ runMemoryCompaction?: () => Promise<string>;
42
+ runMemorySummary?: (scope?: MemoryScope) => Promise<string>;
43
+ runMemoryRefresh?: (scope?: MemoryScope) => Promise<string>;
44
+ }
45
+ export declare function runTui(agent: Agent, args: CliArgs, options?: RunTuiOptions): Promise<void>;