@bubblebrain-ai/bubble 0.0.1

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 (248) hide show
  1. package/README.md +70 -0
  2. package/dist/agent/evidence-tracker.d.ts +15 -0
  3. package/dist/agent/evidence-tracker.js +93 -0
  4. package/dist/agent/execution-governor.d.ts +30 -0
  5. package/dist/agent/execution-governor.js +169 -0
  6. package/dist/agent/subtask-policy.d.ts +14 -0
  7. package/dist/agent/subtask-policy.js +60 -0
  8. package/dist/agent/task-classifier.d.ts +3 -0
  9. package/dist/agent/task-classifier.js +36 -0
  10. package/dist/agent/tool-arbiter.d.ts +7 -0
  11. package/dist/agent/tool-arbiter.js +33 -0
  12. package/dist/agent/tool-intent.d.ts +20 -0
  13. package/dist/agent/tool-intent.js +176 -0
  14. package/dist/agent.d.ts +95 -0
  15. package/dist/agent.js +672 -0
  16. package/dist/approval/controller.d.ts +48 -0
  17. package/dist/approval/controller.js +78 -0
  18. package/dist/approval/danger.d.ts +13 -0
  19. package/dist/approval/danger.js +55 -0
  20. package/dist/approval/diff-hunks.d.ts +12 -0
  21. package/dist/approval/diff-hunks.js +32 -0
  22. package/dist/approval/session-cache.d.ts +35 -0
  23. package/dist/approval/session-cache.js +68 -0
  24. package/dist/approval/tool-helper.d.ts +14 -0
  25. package/dist/approval/tool-helper.js +32 -0
  26. package/dist/approval/types.d.ts +56 -0
  27. package/dist/approval/types.js +8 -0
  28. package/dist/bubble-home.d.ts +8 -0
  29. package/dist/bubble-home.js +19 -0
  30. package/dist/cli.d.ts +19 -0
  31. package/dist/cli.js +82 -0
  32. package/dist/config.d.ts +41 -0
  33. package/dist/config.js +144 -0
  34. package/dist/context/budget.d.ts +21 -0
  35. package/dist/context/budget.js +72 -0
  36. package/dist/context/compact-llm.d.ts +16 -0
  37. package/dist/context/compact-llm.js +132 -0
  38. package/dist/context/compact.d.ts +15 -0
  39. package/dist/context/compact.js +251 -0
  40. package/dist/context/overflow.d.ts +9 -0
  41. package/dist/context/overflow.js +46 -0
  42. package/dist/context/projector.d.ts +26 -0
  43. package/dist/context/projector.js +150 -0
  44. package/dist/context/prune.d.ts +9 -0
  45. package/dist/context/prune.js +111 -0
  46. package/dist/lsp/config.d.ts +18 -0
  47. package/dist/lsp/config.js +58 -0
  48. package/dist/lsp/diagnostics.d.ts +24 -0
  49. package/dist/lsp/diagnostics.js +103 -0
  50. package/dist/lsp/index.d.ts +3 -0
  51. package/dist/lsp/index.js +3 -0
  52. package/dist/lsp/service.d.ts +85 -0
  53. package/dist/lsp/service.js +695 -0
  54. package/dist/main.d.ts +5 -0
  55. package/dist/main.js +352 -0
  56. package/dist/mcp/client.d.ts +68 -0
  57. package/dist/mcp/client.js +163 -0
  58. package/dist/mcp/config.d.ts +26 -0
  59. package/dist/mcp/config.js +127 -0
  60. package/dist/mcp/manager.d.ts +55 -0
  61. package/dist/mcp/manager.js +296 -0
  62. package/dist/mcp/name.d.ts +26 -0
  63. package/dist/mcp/name.js +40 -0
  64. package/dist/mcp/transports.d.ts +53 -0
  65. package/dist/mcp/transports.js +248 -0
  66. package/dist/mcp/types.d.ts +111 -0
  67. package/dist/mcp/types.js +14 -0
  68. package/dist/memory/db.d.ts +62 -0
  69. package/dist/memory/db.js +313 -0
  70. package/dist/memory/index.d.ts +9 -0
  71. package/dist/memory/index.js +9 -0
  72. package/dist/memory/paths.d.ts +18 -0
  73. package/dist/memory/paths.js +38 -0
  74. package/dist/memory/phase1.d.ts +23 -0
  75. package/dist/memory/phase1.js +172 -0
  76. package/dist/memory/phase2.d.ts +19 -0
  77. package/dist/memory/phase2.js +100 -0
  78. package/dist/memory/prompts.d.ts +19 -0
  79. package/dist/memory/prompts.js +99 -0
  80. package/dist/memory/reset.d.ts +1 -0
  81. package/dist/memory/reset.js +13 -0
  82. package/dist/memory/start.d.ts +24 -0
  83. package/dist/memory/start.js +50 -0
  84. package/dist/memory/storage.d.ts +10 -0
  85. package/dist/memory/storage.js +82 -0
  86. package/dist/memory/store.d.ts +43 -0
  87. package/dist/memory/store.js +193 -0
  88. package/dist/memory/usage.d.ts +1 -0
  89. package/dist/memory/usage.js +38 -0
  90. package/dist/model-catalog.d.ts +20 -0
  91. package/dist/model-catalog.js +99 -0
  92. package/dist/model-config.d.ts +32 -0
  93. package/dist/model-config.js +59 -0
  94. package/dist/model-pricing.d.ts +23 -0
  95. package/dist/model-pricing.js +46 -0
  96. package/dist/oauth/index.d.ts +3 -0
  97. package/dist/oauth/index.js +2 -0
  98. package/dist/oauth/openai-codex.d.ts +9 -0
  99. package/dist/oauth/openai-codex.js +173 -0
  100. package/dist/oauth/storage.d.ts +18 -0
  101. package/dist/oauth/storage.js +60 -0
  102. package/dist/oauth/types.d.ts +15 -0
  103. package/dist/oauth/types.js +1 -0
  104. package/dist/orchestrator/default-hooks.d.ts +2 -0
  105. package/dist/orchestrator/default-hooks.js +96 -0
  106. package/dist/orchestrator/hooks.d.ts +78 -0
  107. package/dist/orchestrator/hooks.js +52 -0
  108. package/dist/orchestrator/workflow.d.ts +10 -0
  109. package/dist/orchestrator/workflow.js +22 -0
  110. package/dist/permission/mode.d.ts +23 -0
  111. package/dist/permission/mode.js +20 -0
  112. package/dist/permissions/rule.d.ts +39 -0
  113. package/dist/permissions/rule.js +234 -0
  114. package/dist/permissions/settings.d.ts +71 -0
  115. package/dist/permissions/settings.js +202 -0
  116. package/dist/permissions/types.d.ts +61 -0
  117. package/dist/permissions/types.js +14 -0
  118. package/dist/prompt/compose.d.ts +12 -0
  119. package/dist/prompt/compose.js +67 -0
  120. package/dist/prompt/environment.d.ts +12 -0
  121. package/dist/prompt/environment.js +38 -0
  122. package/dist/prompt/provider-prompts/anthropic.d.ts +1 -0
  123. package/dist/prompt/provider-prompts/anthropic.js +5 -0
  124. package/dist/prompt/provider-prompts/codex.d.ts +1 -0
  125. package/dist/prompt/provider-prompts/codex.js +5 -0
  126. package/dist/prompt/provider-prompts/default.d.ts +1 -0
  127. package/dist/prompt/provider-prompts/default.js +6 -0
  128. package/dist/prompt/provider-prompts/gemini.d.ts +1 -0
  129. package/dist/prompt/provider-prompts/gemini.js +5 -0
  130. package/dist/prompt/provider-prompts/gpt.d.ts +1 -0
  131. package/dist/prompt/provider-prompts/gpt.js +5 -0
  132. package/dist/prompt/reminders.d.ts +30 -0
  133. package/dist/prompt/reminders.js +164 -0
  134. package/dist/prompt/runtime.d.ts +12 -0
  135. package/dist/prompt/runtime.js +31 -0
  136. package/dist/prompt/skills.d.ts +2 -0
  137. package/dist/prompt/skills.js +4 -0
  138. package/dist/provider-openai-codex.d.ts +14 -0
  139. package/dist/provider-openai-codex.js +409 -0
  140. package/dist/provider-registry.d.ts +56 -0
  141. package/dist/provider-registry.js +244 -0
  142. package/dist/provider-transform.d.ts +10 -0
  143. package/dist/provider-transform.js +69 -0
  144. package/dist/provider.d.ts +31 -0
  145. package/dist/provider.js +269 -0
  146. package/dist/question/controller.d.ts +22 -0
  147. package/dist/question/controller.js +97 -0
  148. package/dist/question/index.d.ts +2 -0
  149. package/dist/question/index.js +2 -0
  150. package/dist/question/types.d.ts +42 -0
  151. package/dist/question/types.js +6 -0
  152. package/dist/session-log.d.ts +16 -0
  153. package/dist/session-log.js +267 -0
  154. package/dist/session-types.d.ts +55 -0
  155. package/dist/session-types.js +1 -0
  156. package/dist/session.d.ts +32 -0
  157. package/dist/session.js +135 -0
  158. package/dist/skills/discovery.d.ts +12 -0
  159. package/dist/skills/discovery.js +148 -0
  160. package/dist/skills/format.d.ts +2 -0
  161. package/dist/skills/format.js +47 -0
  162. package/dist/skills/frontmatter.d.ts +5 -0
  163. package/dist/skills/frontmatter.js +60 -0
  164. package/dist/skills/invocation.d.ts +8 -0
  165. package/dist/skills/invocation.js +51 -0
  166. package/dist/skills/registry.d.ts +17 -0
  167. package/dist/skills/registry.js +42 -0
  168. package/dist/skills/types.d.ts +32 -0
  169. package/dist/skills/types.js +1 -0
  170. package/dist/slash-commands/commands.d.ts +7 -0
  171. package/dist/slash-commands/commands.js +779 -0
  172. package/dist/slash-commands/index.d.ts +4 -0
  173. package/dist/slash-commands/index.js +8 -0
  174. package/dist/slash-commands/registry.d.ts +31 -0
  175. package/dist/slash-commands/registry.js +70 -0
  176. package/dist/slash-commands/types.d.ts +44 -0
  177. package/dist/slash-commands/types.js +1 -0
  178. package/dist/slash-commands/unified.d.ts +38 -0
  179. package/dist/slash-commands/unified.js +38 -0
  180. package/dist/system-prompt.d.ts +34 -0
  181. package/dist/system-prompt.js +7 -0
  182. package/dist/tools/bash.d.ts +6 -0
  183. package/dist/tools/bash.js +135 -0
  184. package/dist/tools/edit.d.ts +16 -0
  185. package/dist/tools/edit.js +95 -0
  186. package/dist/tools/exa-mcp.d.ts +3 -0
  187. package/dist/tools/exa-mcp.js +74 -0
  188. package/dist/tools/exit-plan-mode.d.ts +17 -0
  189. package/dist/tools/exit-plan-mode.js +68 -0
  190. package/dist/tools/glob.d.ts +5 -0
  191. package/dist/tools/glob.js +129 -0
  192. package/dist/tools/grep.d.ts +5 -0
  193. package/dist/tools/grep.js +111 -0
  194. package/dist/tools/index.d.ts +36 -0
  195. package/dist/tools/index.js +59 -0
  196. package/dist/tools/lsp.d.ts +4 -0
  197. package/dist/tools/lsp.js +92 -0
  198. package/dist/tools/memory.d.ts +3 -0
  199. package/dist/tools/memory.js +90 -0
  200. package/dist/tools/question.d.ts +3 -0
  201. package/dist/tools/question.js +174 -0
  202. package/dist/tools/read.d.ts +7 -0
  203. package/dist/tools/read.js +83 -0
  204. package/dist/tools/sensitive-paths.d.ts +3 -0
  205. package/dist/tools/sensitive-paths.js +24 -0
  206. package/dist/tools/skill.d.ts +5 -0
  207. package/dist/tools/skill.js +51 -0
  208. package/dist/tools/task.d.ts +2 -0
  209. package/dist/tools/task.js +57 -0
  210. package/dist/tools/todo.d.ts +12 -0
  211. package/dist/tools/todo.js +151 -0
  212. package/dist/tools/tool-search.d.ts +23 -0
  213. package/dist/tools/tool-search.js +124 -0
  214. package/dist/tools/web-fetch.d.ts +6 -0
  215. package/dist/tools/web-fetch.js +75 -0
  216. package/dist/tools/web-search.d.ts +5 -0
  217. package/dist/tools/web-search.js +49 -0
  218. package/dist/tools/write.d.ts +11 -0
  219. package/dist/tools/write.js +77 -0
  220. package/dist/tui/display-history.d.ts +35 -0
  221. package/dist/tui/display-history.js +243 -0
  222. package/dist/tui/file-mentions.d.ts +29 -0
  223. package/dist/tui/file-mentions.js +174 -0
  224. package/dist/tui/image-paste.d.ts +54 -0
  225. package/dist/tui/image-paste.js +288 -0
  226. package/dist/tui/markdown-theme-rules.d.ts +23 -0
  227. package/dist/tui/markdown-theme-rules.js +164 -0
  228. package/dist/tui/markdown-theme.d.ts +5 -0
  229. package/dist/tui/markdown-theme.js +27 -0
  230. package/dist/tui/opencode-spinner.d.ts +21 -0
  231. package/dist/tui/opencode-spinner.js +216 -0
  232. package/dist/tui/prompt-keybindings.d.ts +41 -0
  233. package/dist/tui/prompt-keybindings.js +28 -0
  234. package/dist/tui/recent-activity.d.ts +8 -0
  235. package/dist/tui/recent-activity.js +71 -0
  236. package/dist/tui/run.d.ts +39 -0
  237. package/dist/tui/run.js +5696 -0
  238. package/dist/tui/sidebar-mcp.d.ts +31 -0
  239. package/dist/tui/sidebar-mcp.js +62 -0
  240. package/dist/tui/sidebar-state.d.ts +12 -0
  241. package/dist/tui/sidebar-state.js +69 -0
  242. package/dist/types.d.ts +219 -0
  243. package/dist/types.js +4 -0
  244. package/dist/variant/thinking-level.d.ts +5 -0
  245. package/dist/variant/thinking-level.js +25 -0
  246. package/dist/variant/variant-resolver.d.ts +4 -0
  247. package/dist/variant/variant-resolver.js +12 -0
  248. package/package.json +47 -0
@@ -0,0 +1,5 @@
1
+ import { SyntaxStyle } from "@opentui/core";
2
+ import { type MarkdownThemePalette } from "./markdown-theme-rules.js";
3
+ export type { MarkdownThemePalette } from "./markdown-theme-rules.js";
4
+ export declare function createMarkdownSyntaxStyle(theme: MarkdownThemePalette): SyntaxStyle;
5
+ export declare function createSubtleMarkdownSyntaxStyle(theme: MarkdownThemePalette, opacity?: number): SyntaxStyle;
@@ -0,0 +1,27 @@
1
+ import { SyntaxStyle } from "@opentui/core";
2
+ import { buildMarkdownThemeRules } from "./markdown-theme-rules.js";
3
+ export function createMarkdownSyntaxStyle(theme) {
4
+ return SyntaxStyle.fromTheme(buildMarkdownThemeRules(theme));
5
+ }
6
+ export function createSubtleMarkdownSyntaxStyle(theme, opacity = 0.6) {
7
+ const alpha = Math.max(0, Math.min(1, opacity));
8
+ return SyntaxStyle.fromTheme(buildMarkdownThemeRules(theme).map((rule) => ({
9
+ ...rule,
10
+ style: {
11
+ ...rule.style,
12
+ foreground: rule.style.foreground
13
+ ? applyAlpha(rule.style.foreground, alpha)
14
+ : rule.style.foreground,
15
+ },
16
+ })));
17
+ }
18
+ function applyAlpha(color, opacity) {
19
+ if (!color.startsWith("#"))
20
+ return color;
21
+ const hex = color.slice(1);
22
+ if (hex.length !== 6 && hex.length !== 8)
23
+ return color;
24
+ const rgb = hex.slice(0, 6);
25
+ const alpha = Math.round(opacity * 255).toString(16).padStart(2, "0");
26
+ return `#${rgb}${alpha}`;
27
+ }
@@ -0,0 +1,21 @@
1
+ import type { ColorInput } from "@opentui/core";
2
+ import { RGBA } from "@opentui/core";
3
+ import type { ColorGenerator } from "opentui-spinner";
4
+ export declare function deriveTrailColors(brightColor: ColorInput, steps?: number): RGBA[];
5
+ export declare function deriveInactiveColor(brightColor: ColorInput, factor?: number): RGBA;
6
+ export type KnightRiderStyle = "blocks" | "diamonds";
7
+ export interface KnightRiderOptions {
8
+ width?: number;
9
+ style?: KnightRiderStyle;
10
+ holdStart?: number;
11
+ holdEnd?: number;
12
+ colors?: ColorInput[];
13
+ color?: ColorInput;
14
+ trailSteps?: number;
15
+ defaultColor?: ColorInput;
16
+ inactiveFactor?: number;
17
+ enableFading?: boolean;
18
+ minAlpha?: number;
19
+ }
20
+ export declare function createFrames(options?: KnightRiderOptions): string[];
21
+ export declare function createColors(options?: KnightRiderOptions): ColorGenerator;
@@ -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,41 @@
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 isModeCycleKeyEvent(input: {
38
+ name?: string;
39
+ raw?: string;
40
+ sequence?: string;
41
+ }): boolean;
@@ -0,0 +1,28 @@
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 isModeCycleKeyEvent(input) {
23
+ const name = String(input.name || "").toLowerCase();
24
+ return name === "tab"
25
+ || name === "backtab"
26
+ || name === "shift+tab"
27
+ || isModeCycleSequence(input.raw || input.sequence);
28
+ }
@@ -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,39 @@
1
+ import type { Agent } from "../agent.js";
2
+ import type { CliArgs } from "../cli.js";
3
+ import type { SessionManager } from "../session.js";
4
+ import type { PlanDecision, Provider } from "../types.js";
5
+ import type { ProviderRegistry } from "../provider-registry.js";
6
+ import type { SkillRegistry } from "../skills/registry.js";
7
+ import { type LspService } from "../lsp/index.js";
8
+ import { type BashAllowlist } from "../approval/session-cache.js";
9
+ import type { SettingsManager } from "../permissions/settings.js";
10
+ import type { McpManager } from "../mcp/manager.js";
11
+ import type { ApprovalDecision, ApprovalRequest } from "../approval/types.js";
12
+ import type { QuestionController } from "../question/index.js";
13
+ import type { MemoryScope } from "../memory/index.js";
14
+ export interface PlanHandlerRef {
15
+ current?: (plan: string) => Promise<PlanDecision>;
16
+ }
17
+ export interface ApprovalHandlerRef {
18
+ current?: (req: ApprovalRequest) => Promise<ApprovalDecision>;
19
+ }
20
+ export interface RunTuiOptions {
21
+ sessionManager?: SessionManager;
22
+ createProvider?: (providerId: string, apiKey: string, baseURL: string) => Provider;
23
+ registry?: ProviderRegistry;
24
+ skillRegistry?: SkillRegistry;
25
+ planHandlerRef?: PlanHandlerRef;
26
+ approvalHandlerRef?: ApprovalHandlerRef;
27
+ questionController?: QuestionController;
28
+ bashAllowlist?: BashAllowlist;
29
+ settingsManager?: SettingsManager;
30
+ lspService?: LspService;
31
+ mcpManager?: McpManager;
32
+ bypassEnabled?: boolean;
33
+ theme?: Record<string, string>;
34
+ flushMemory?: () => Promise<void>;
35
+ runMemoryCompaction?: () => Promise<string>;
36
+ runMemorySummary?: (scope?: MemoryScope) => Promise<string>;
37
+ runMemoryRefresh?: (scope?: MemoryScope) => Promise<string>;
38
+ }
39
+ export declare function runTui(agent: Agent, args: CliArgs, options?: RunTuiOptions): Promise<void>;