genesis-ai-cli 7.4.5

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 (227) hide show
  1. package/.env.example +78 -0
  2. package/README.md +282 -0
  3. package/dist/src/active-inference/actions.d.ts +75 -0
  4. package/dist/src/active-inference/actions.js +250 -0
  5. package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
  6. package/dist/src/active-inference/autonomous-loop.js +289 -0
  7. package/dist/src/active-inference/core.d.ts +85 -0
  8. package/dist/src/active-inference/core.js +555 -0
  9. package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
  10. package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
  11. package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
  12. package/dist/src/active-inference/demo-value-integration.js +174 -0
  13. package/dist/src/active-inference/index.d.ts +32 -0
  14. package/dist/src/active-inference/index.js +88 -0
  15. package/dist/src/active-inference/integration.d.ts +114 -0
  16. package/dist/src/active-inference/integration.js +698 -0
  17. package/dist/src/active-inference/memory-integration.d.ts +51 -0
  18. package/dist/src/active-inference/memory-integration.js +232 -0
  19. package/dist/src/active-inference/observations.d.ts +67 -0
  20. package/dist/src/active-inference/observations.js +147 -0
  21. package/dist/src/active-inference/test-active-inference.d.ts +8 -0
  22. package/dist/src/active-inference/test-active-inference.js +320 -0
  23. package/dist/src/active-inference/test-value-integration.d.ts +6 -0
  24. package/dist/src/active-inference/test-value-integration.js +168 -0
  25. package/dist/src/active-inference/types.d.ts +150 -0
  26. package/dist/src/active-inference/types.js +59 -0
  27. package/dist/src/active-inference/value-integration.d.ts +164 -0
  28. package/dist/src/active-inference/value-integration.js +459 -0
  29. package/dist/src/agents/base-agent.d.ts +53 -0
  30. package/dist/src/agents/base-agent.js +178 -0
  31. package/dist/src/agents/builder.d.ts +67 -0
  32. package/dist/src/agents/builder.js +537 -0
  33. package/dist/src/agents/critic.d.ts +35 -0
  34. package/dist/src/agents/critic.js +322 -0
  35. package/dist/src/agents/ethicist.d.ts +54 -0
  36. package/dist/src/agents/ethicist.js +393 -0
  37. package/dist/src/agents/explorer.d.ts +26 -0
  38. package/dist/src/agents/explorer.js +216 -0
  39. package/dist/src/agents/feeling.d.ts +41 -0
  40. package/dist/src/agents/feeling.js +320 -0
  41. package/dist/src/agents/index.d.ts +111 -0
  42. package/dist/src/agents/index.js +222 -0
  43. package/dist/src/agents/memory.d.ts +69 -0
  44. package/dist/src/agents/memory.js +404 -0
  45. package/dist/src/agents/message-bus.d.ts +88 -0
  46. package/dist/src/agents/message-bus.js +267 -0
  47. package/dist/src/agents/narrator.d.ts +90 -0
  48. package/dist/src/agents/narrator.js +473 -0
  49. package/dist/src/agents/planner.d.ts +38 -0
  50. package/dist/src/agents/planner.js +341 -0
  51. package/dist/src/agents/predictor.d.ts +73 -0
  52. package/dist/src/agents/predictor.js +506 -0
  53. package/dist/src/agents/sensor.d.ts +88 -0
  54. package/dist/src/agents/sensor.js +377 -0
  55. package/dist/src/agents/test-agents.d.ts +6 -0
  56. package/dist/src/agents/test-agents.js +73 -0
  57. package/dist/src/agents/types.d.ts +194 -0
  58. package/dist/src/agents/types.js +7 -0
  59. package/dist/src/brain/index.d.ts +185 -0
  60. package/dist/src/brain/index.js +843 -0
  61. package/dist/src/brain/trace.d.ts +91 -0
  62. package/dist/src/brain/trace.js +327 -0
  63. package/dist/src/brain/types.d.ts +165 -0
  64. package/dist/src/brain/types.js +51 -0
  65. package/dist/src/cli/chat.d.ts +237 -0
  66. package/dist/src/cli/chat.js +1959 -0
  67. package/dist/src/cli/dispatcher.d.ts +182 -0
  68. package/dist/src/cli/dispatcher.js +718 -0
  69. package/dist/src/cli/human-loop.d.ts +170 -0
  70. package/dist/src/cli/human-loop.js +543 -0
  71. package/dist/src/cli/index.d.ts +12 -0
  72. package/dist/src/cli/index.js +28 -0
  73. package/dist/src/cli/interactive.d.ts +141 -0
  74. package/dist/src/cli/interactive.js +757 -0
  75. package/dist/src/cli/ui.d.ts +205 -0
  76. package/dist/src/cli/ui.js +632 -0
  77. package/dist/src/consciousness/attention-schema.d.ts +154 -0
  78. package/dist/src/consciousness/attention-schema.js +432 -0
  79. package/dist/src/consciousness/global-workspace.d.ts +149 -0
  80. package/dist/src/consciousness/global-workspace.js +422 -0
  81. package/dist/src/consciousness/index.d.ts +186 -0
  82. package/dist/src/consciousness/index.js +476 -0
  83. package/dist/src/consciousness/phi-calculator.d.ts +119 -0
  84. package/dist/src/consciousness/phi-calculator.js +445 -0
  85. package/dist/src/consciousness/phi-decisions.d.ts +169 -0
  86. package/dist/src/consciousness/phi-decisions.js +383 -0
  87. package/dist/src/consciousness/phi-monitor.d.ts +153 -0
  88. package/dist/src/consciousness/phi-monitor.js +465 -0
  89. package/dist/src/consciousness/types.d.ts +260 -0
  90. package/dist/src/consciousness/types.js +44 -0
  91. package/dist/src/daemon/dream-mode.d.ts +115 -0
  92. package/dist/src/daemon/dream-mode.js +470 -0
  93. package/dist/src/daemon/index.d.ts +162 -0
  94. package/dist/src/daemon/index.js +542 -0
  95. package/dist/src/daemon/maintenance.d.ts +139 -0
  96. package/dist/src/daemon/maintenance.js +549 -0
  97. package/dist/src/daemon/process.d.ts +82 -0
  98. package/dist/src/daemon/process.js +442 -0
  99. package/dist/src/daemon/scheduler.d.ts +90 -0
  100. package/dist/src/daemon/scheduler.js +494 -0
  101. package/dist/src/daemon/types.d.ts +213 -0
  102. package/dist/src/daemon/types.js +50 -0
  103. package/dist/src/epistemic/index.d.ts +74 -0
  104. package/dist/src/epistemic/index.js +225 -0
  105. package/dist/src/grounding/epistemic-stack.d.ts +100 -0
  106. package/dist/src/grounding/epistemic-stack.js +408 -0
  107. package/dist/src/grounding/feedback.d.ts +98 -0
  108. package/dist/src/grounding/feedback.js +276 -0
  109. package/dist/src/grounding/index.d.ts +123 -0
  110. package/dist/src/grounding/index.js +224 -0
  111. package/dist/src/grounding/verifier.d.ts +149 -0
  112. package/dist/src/grounding/verifier.js +484 -0
  113. package/dist/src/healing/detector.d.ts +110 -0
  114. package/dist/src/healing/detector.js +436 -0
  115. package/dist/src/healing/fixer.d.ts +138 -0
  116. package/dist/src/healing/fixer.js +572 -0
  117. package/dist/src/healing/index.d.ts +23 -0
  118. package/dist/src/healing/index.js +43 -0
  119. package/dist/src/hooks/index.d.ts +135 -0
  120. package/dist/src/hooks/index.js +317 -0
  121. package/dist/src/index.d.ts +23 -0
  122. package/dist/src/index.js +1266 -0
  123. package/dist/src/kernel/index.d.ts +155 -0
  124. package/dist/src/kernel/index.js +795 -0
  125. package/dist/src/kernel/invariants.d.ts +153 -0
  126. package/dist/src/kernel/invariants.js +355 -0
  127. package/dist/src/kernel/test-kernel.d.ts +6 -0
  128. package/dist/src/kernel/test-kernel.js +108 -0
  129. package/dist/src/kernel/test-real-mcp.d.ts +10 -0
  130. package/dist/src/kernel/test-real-mcp.js +295 -0
  131. package/dist/src/llm/index.d.ts +146 -0
  132. package/dist/src/llm/index.js +428 -0
  133. package/dist/src/llm/router.d.ts +136 -0
  134. package/dist/src/llm/router.js +510 -0
  135. package/dist/src/mcp/index.d.ts +85 -0
  136. package/dist/src/mcp/index.js +657 -0
  137. package/dist/src/mcp/resilient.d.ts +139 -0
  138. package/dist/src/mcp/resilient.js +417 -0
  139. package/dist/src/memory/cache.d.ts +118 -0
  140. package/dist/src/memory/cache.js +356 -0
  141. package/dist/src/memory/cognitive-workspace.d.ts +231 -0
  142. package/dist/src/memory/cognitive-workspace.js +521 -0
  143. package/dist/src/memory/consolidation.d.ts +99 -0
  144. package/dist/src/memory/consolidation.js +443 -0
  145. package/dist/src/memory/episodic.d.ts +114 -0
  146. package/dist/src/memory/episodic.js +394 -0
  147. package/dist/src/memory/forgetting.d.ts +134 -0
  148. package/dist/src/memory/forgetting.js +324 -0
  149. package/dist/src/memory/index.d.ts +211 -0
  150. package/dist/src/memory/index.js +367 -0
  151. package/dist/src/memory/indexer.d.ts +123 -0
  152. package/dist/src/memory/indexer.js +479 -0
  153. package/dist/src/memory/procedural.d.ts +136 -0
  154. package/dist/src/memory/procedural.js +479 -0
  155. package/dist/src/memory/semantic.d.ts +132 -0
  156. package/dist/src/memory/semantic.js +497 -0
  157. package/dist/src/memory/types.d.ts +193 -0
  158. package/dist/src/memory/types.js +15 -0
  159. package/dist/src/orchestrator.d.ts +65 -0
  160. package/dist/src/orchestrator.js +317 -0
  161. package/dist/src/persistence/index.d.ts +257 -0
  162. package/dist/src/persistence/index.js +763 -0
  163. package/dist/src/pipeline/executor.d.ts +51 -0
  164. package/dist/src/pipeline/executor.js +695 -0
  165. package/dist/src/pipeline/index.d.ts +7 -0
  166. package/dist/src/pipeline/index.js +11 -0
  167. package/dist/src/self-production.d.ts +67 -0
  168. package/dist/src/self-production.js +205 -0
  169. package/dist/src/subagents/executor.d.ts +58 -0
  170. package/dist/src/subagents/executor.js +283 -0
  171. package/dist/src/subagents/index.d.ts +37 -0
  172. package/dist/src/subagents/index.js +53 -0
  173. package/dist/src/subagents/registry.d.ts +23 -0
  174. package/dist/src/subagents/registry.js +167 -0
  175. package/dist/src/subagents/types.d.ts +79 -0
  176. package/dist/src/subagents/types.js +14 -0
  177. package/dist/src/tools/bash.d.ts +139 -0
  178. package/dist/src/tools/bash.js +583 -0
  179. package/dist/src/tools/edit.d.ts +125 -0
  180. package/dist/src/tools/edit.js +424 -0
  181. package/dist/src/tools/git.d.ts +179 -0
  182. package/dist/src/tools/git.js +504 -0
  183. package/dist/src/tools/index.d.ts +21 -0
  184. package/dist/src/tools/index.js +163 -0
  185. package/dist/src/types.d.ts +145 -0
  186. package/dist/src/types.js +7 -0
  187. package/dist/src/world-model/decoder.d.ts +163 -0
  188. package/dist/src/world-model/decoder.js +517 -0
  189. package/dist/src/world-model/digital-twin.d.ts +219 -0
  190. package/dist/src/world-model/digital-twin.js +695 -0
  191. package/dist/src/world-model/encoder.d.ts +141 -0
  192. package/dist/src/world-model/encoder.js +564 -0
  193. package/dist/src/world-model/index.d.ts +221 -0
  194. package/dist/src/world-model/index.js +772 -0
  195. package/dist/src/world-model/predictor.d.ts +161 -0
  196. package/dist/src/world-model/predictor.js +681 -0
  197. package/dist/src/world-model/test-value-jepa.d.ts +8 -0
  198. package/dist/src/world-model/test-value-jepa.js +430 -0
  199. package/dist/src/world-model/types.d.ts +341 -0
  200. package/dist/src/world-model/types.js +69 -0
  201. package/dist/src/world-model/value-jepa.d.ts +247 -0
  202. package/dist/src/world-model/value-jepa.js +622 -0
  203. package/dist/test/brain.test.d.ts +11 -0
  204. package/dist/test/brain.test.js +358 -0
  205. package/dist/test/cli/dispatcher.test.d.ts +4 -0
  206. package/dist/test/cli/dispatcher.test.js +332 -0
  207. package/dist/test/cli/human-loop.test.d.ts +4 -0
  208. package/dist/test/cli/human-loop.test.js +270 -0
  209. package/dist/test/grounding/feedback.test.d.ts +4 -0
  210. package/dist/test/grounding/feedback.test.js +462 -0
  211. package/dist/test/grounding/verifier.test.d.ts +4 -0
  212. package/dist/test/grounding/verifier.test.js +442 -0
  213. package/dist/test/grounding.test.d.ts +6 -0
  214. package/dist/test/grounding.test.js +246 -0
  215. package/dist/test/healing/detector.test.d.ts +4 -0
  216. package/dist/test/healing/detector.test.js +266 -0
  217. package/dist/test/healing/fixer.test.d.ts +4 -0
  218. package/dist/test/healing/fixer.test.js +369 -0
  219. package/dist/test/integration.test.d.ts +5 -0
  220. package/dist/test/integration.test.js +290 -0
  221. package/dist/test/tools/bash.test.d.ts +4 -0
  222. package/dist/test/tools/bash.test.js +348 -0
  223. package/dist/test/tools/edit.test.d.ts +4 -0
  224. package/dist/test/tools/edit.test.js +350 -0
  225. package/dist/test/tools/git.test.d.ts +4 -0
  226. package/dist/test/tools/git.test.js +350 -0
  227. package/package.json +60 -0
@@ -0,0 +1,632 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis v7.3 - Modern UI Components
4
+ *
5
+ * Reusable CLI components for beautiful terminal output.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DEFAULT_THINKING_SETTINGS = exports.InputHistory = exports.ProgressBar = exports.ThinkingSpinner = exports.Spinner = exports.highlight = exports.muted = exports.info = exports.warning = exports.error = exports.success = exports.COLORS = void 0;
9
+ exports.style = style;
10
+ exports.c = c;
11
+ exports.highlightCode = highlightCode;
12
+ exports.highlightInlineCode = highlightInlineCode;
13
+ exports.formatMarkdown = formatMarkdown;
14
+ exports.box = box;
15
+ exports.table = table;
16
+ exports.stripAnsi = stripAnsi;
17
+ exports.pad = pad;
18
+ exports.truncate = truncate;
19
+ exports.formatDuration = formatDuration;
20
+ exports.formatBytes = formatBytes;
21
+ exports.banner = banner;
22
+ exports.parseThinkingBlocks = parseThinkingBlocks;
23
+ exports.formatThinkingBlock = formatThinkingBlock;
24
+ exports.formatResponseWithThinking = formatResponseWithThinking;
25
+ // ============================================================================
26
+ // Colors & Styles
27
+ // ============================================================================
28
+ exports.COLORS = {
29
+ reset: '\x1b[0m',
30
+ bold: '\x1b[1m',
31
+ dim: '\x1b[2m',
32
+ italic: '\x1b[3m',
33
+ underline: '\x1b[4m',
34
+ inverse: '\x1b[7m',
35
+ hidden: '\x1b[8m',
36
+ strikethrough: '\x1b[9m',
37
+ // Foreground
38
+ black: '\x1b[30m',
39
+ red: '\x1b[31m',
40
+ green: '\x1b[32m',
41
+ yellow: '\x1b[33m',
42
+ blue: '\x1b[34m',
43
+ magenta: '\x1b[35m',
44
+ cyan: '\x1b[36m',
45
+ white: '\x1b[37m',
46
+ gray: '\x1b[90m',
47
+ // Background
48
+ bgBlack: '\x1b[40m',
49
+ bgRed: '\x1b[41m',
50
+ bgGreen: '\x1b[42m',
51
+ bgYellow: '\x1b[43m',
52
+ bgBlue: '\x1b[44m',
53
+ bgMagenta: '\x1b[45m',
54
+ bgCyan: '\x1b[46m',
55
+ bgWhite: '\x1b[47m',
56
+ bgGray: '\x1b[100m',
57
+ };
58
+ /**
59
+ * Apply multiple styles to text
60
+ */
61
+ function style(text, ...styles) {
62
+ if (styles.length === 0)
63
+ return text;
64
+ const codes = styles.map(s => exports.COLORS[s]).join('');
65
+ return `${codes}${text}${exports.COLORS.reset}`;
66
+ }
67
+ /**
68
+ * Single color function (backwards compatible)
69
+ */
70
+ function c(text, color) {
71
+ return style(text, color);
72
+ }
73
+ // Semantic colors
74
+ const success = (text) => style(text, 'green');
75
+ exports.success = success;
76
+ const error = (text) => style(text, 'red');
77
+ exports.error = error;
78
+ const warning = (text) => style(text, 'yellow');
79
+ exports.warning = warning;
80
+ const info = (text) => style(text, 'cyan');
81
+ exports.info = info;
82
+ const muted = (text) => style(text, 'dim');
83
+ exports.muted = muted;
84
+ const highlight = (text) => style(text, 'bold', 'cyan');
85
+ exports.highlight = highlight;
86
+ // ============================================================================
87
+ // Spinner
88
+ // ============================================================================
89
+ const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
90
+ class Spinner {
91
+ interval = null;
92
+ frame = 0;
93
+ message;
94
+ running = false;
95
+ constructor(message = 'Processing') {
96
+ this.message = message;
97
+ }
98
+ start(message) {
99
+ if (this.running)
100
+ return;
101
+ if (message)
102
+ this.message = message;
103
+ this.running = true;
104
+ this.frame = 0;
105
+ // Initial render
106
+ process.stdout.write(`${style(SPINNER_FRAMES[0], 'cyan')} ${(0, exports.muted)(this.message + '...')}`);
107
+ this.interval = setInterval(() => {
108
+ this.frame = (this.frame + 1) % SPINNER_FRAMES.length;
109
+ process.stdout.write(`\r${style(SPINNER_FRAMES[this.frame], 'cyan')} ${(0, exports.muted)(this.message + '...')}`);
110
+ }, 80);
111
+ }
112
+ update(message) {
113
+ this.message = message;
114
+ if (this.running) {
115
+ process.stdout.write(`\r${style(SPINNER_FRAMES[this.frame], 'cyan')} ${(0, exports.muted)(this.message + '...')}${' '.repeat(20)}`);
116
+ }
117
+ }
118
+ stop(finalMessage, status = 'success') {
119
+ if (!this.running)
120
+ return;
121
+ this.running = false;
122
+ if (this.interval) {
123
+ clearInterval(this.interval);
124
+ this.interval = null;
125
+ }
126
+ const icons = {
127
+ success: style('✓', 'green'),
128
+ error: style('✗', 'red'),
129
+ warning: style('!', 'yellow'),
130
+ info: style('i', 'cyan'),
131
+ };
132
+ // Clear line and print final message
133
+ process.stdout.write('\r\x1b[K'); // Clear line
134
+ if (finalMessage) {
135
+ console.log(`${icons[status]} ${finalMessage}`);
136
+ }
137
+ }
138
+ isRunning() {
139
+ return this.running;
140
+ }
141
+ }
142
+ exports.Spinner = Spinner;
143
+ // ============================================================================
144
+ // Thinking Spinner (v7.3.8) - Shows time, module path, and current action
145
+ // ============================================================================
146
+ const MODULE_ICONS = {
147
+ memory: '🧠',
148
+ llm: '💭',
149
+ grounding: '🔍',
150
+ tools: '🔧',
151
+ healing: '🩹',
152
+ consciousness: '✨',
153
+ kernel: '⚙️',
154
+ done: '✓',
155
+ };
156
+ const MODULE_NAMES = {
157
+ memory: 'Recalling',
158
+ llm: 'Thinking',
159
+ grounding: 'Verifying',
160
+ tools: 'Executing',
161
+ healing: 'Healing',
162
+ consciousness: 'Integrating',
163
+ kernel: 'Coordinating',
164
+ };
165
+ class ThinkingSpinner {
166
+ interval = null;
167
+ frame = 0;
168
+ running = false;
169
+ startTime = 0;
170
+ currentModule = '';
171
+ currentAction = '';
172
+ modulePath = [];
173
+ start() {
174
+ if (this.running)
175
+ return;
176
+ this.running = true;
177
+ this.startTime = Date.now();
178
+ this.frame = 0;
179
+ this.modulePath = [];
180
+ this.currentModule = '';
181
+ this.currentAction = 'Initializing';
182
+ this.render();
183
+ this.interval = setInterval(() => {
184
+ this.frame = (this.frame + 1) % SPINNER_FRAMES.length;
185
+ this.render();
186
+ }, 80);
187
+ }
188
+ render() {
189
+ const elapsed = ((Date.now() - this.startTime) / 1000).toFixed(1);
190
+ const icon = MODULE_ICONS[this.currentModule] || '○';
191
+ const moduleName = MODULE_NAMES[this.currentModule] || this.currentModule || 'Processing';
192
+ // Build module path display (e.g., "memory → llm → tools")
193
+ const pathStr = this.modulePath.length > 0
194
+ ? ` ${style(this.modulePath.join(' → '), 'dim')}`
195
+ : '';
196
+ // Build action display
197
+ const actionStr = this.currentAction
198
+ ? ` ${style('· ' + this.currentAction, 'dim')}`
199
+ : '';
200
+ const line = `${style(SPINNER_FRAMES[this.frame], 'cyan')} ${style(`[${elapsed}s]`, 'yellow')} ${icon} ${moduleName}${actionStr}${pathStr}`;
201
+ process.stdout.write(`\r\x1b[K${line}`);
202
+ }
203
+ setModule(module) {
204
+ if (module && module !== 'done' && module !== this.currentModule) {
205
+ this.currentModule = module;
206
+ if (!this.modulePath.includes(module)) {
207
+ this.modulePath.push(module);
208
+ }
209
+ }
210
+ if (this.running)
211
+ this.render();
212
+ }
213
+ setAction(action) {
214
+ this.currentAction = action;
215
+ if (this.running)
216
+ this.render();
217
+ }
218
+ stop() {
219
+ if (!this.running)
220
+ return;
221
+ this.running = false;
222
+ if (this.interval) {
223
+ clearInterval(this.interval);
224
+ this.interval = null;
225
+ }
226
+ const elapsed = ((Date.now() - this.startTime) / 1000).toFixed(1);
227
+ process.stdout.write(`\r\x1b[K`); // Clear line
228
+ // Optional: show final summary
229
+ // console.log(`${style('✓', 'green')} Completed in ${elapsed}s [${this.modulePath.join(' → ')}]`);
230
+ }
231
+ isRunning() {
232
+ return this.running;
233
+ }
234
+ getElapsed() {
235
+ return Date.now() - this.startTime;
236
+ }
237
+ }
238
+ exports.ThinkingSpinner = ThinkingSpinner;
239
+ class ProgressBar {
240
+ total;
241
+ current = 0;
242
+ width;
243
+ completeChar;
244
+ incompleteChar;
245
+ showPercent;
246
+ showCount;
247
+ label;
248
+ constructor(total, label = '', options = {}) {
249
+ this.total = total;
250
+ this.label = label;
251
+ this.width = options.width ?? 30;
252
+ this.completeChar = options.complete ?? '█';
253
+ this.incompleteChar = options.incomplete ?? '░';
254
+ this.showPercent = options.showPercent ?? true;
255
+ this.showCount = options.showCount ?? true;
256
+ }
257
+ update(current, label) {
258
+ this.current = Math.min(current, this.total);
259
+ if (label)
260
+ this.label = label;
261
+ this.render();
262
+ }
263
+ increment(label) {
264
+ this.update(this.current + 1, label);
265
+ }
266
+ render() {
267
+ const percent = this.total > 0 ? this.current / this.total : 0;
268
+ const filled = Math.round(this.width * percent);
269
+ const empty = this.width - filled;
270
+ const bar = style(this.completeChar.repeat(filled), 'green') +
271
+ style(this.incompleteChar.repeat(empty), 'dim');
272
+ let suffix = '';
273
+ if (this.showPercent) {
274
+ suffix += ` ${(percent * 100).toFixed(0)}%`;
275
+ }
276
+ if (this.showCount) {
277
+ suffix += ` (${this.current}/${this.total})`;
278
+ }
279
+ const prefix = this.label ? `${this.label} ` : '';
280
+ process.stdout.write(`\r${prefix}${bar}${(0, exports.muted)(suffix)}${' '.repeat(10)}`);
281
+ }
282
+ complete() {
283
+ this.current = this.total;
284
+ this.render();
285
+ console.log(); // New line
286
+ }
287
+ }
288
+ exports.ProgressBar = ProgressBar;
289
+ // ============================================================================
290
+ // Code Highlighting
291
+ // ============================================================================
292
+ /**
293
+ * Highlight code blocks in markdown-style text
294
+ */
295
+ function highlightCode(text) {
296
+ // Highlight fenced code blocks
297
+ return text.replace(/```(\w+)?\n([\s\S]*?)```/g, (_, lang, code) => {
298
+ const langLabel = lang ? style(`[${lang}]`, 'dim') + '\n' : '';
299
+ return '\n' + langLabel + style(code.trim(), 'cyan') + '\n';
300
+ });
301
+ }
302
+ /**
303
+ * Highlight inline code
304
+ */
305
+ function highlightInlineCode(text) {
306
+ return text.replace(/`([^`]+)`/g, (_, code) => style(code, 'cyan'));
307
+ }
308
+ /**
309
+ * Full markdown-style formatting
310
+ */
311
+ function formatMarkdown(text) {
312
+ let result = text;
313
+ // Code blocks first
314
+ result = highlightCode(result);
315
+ // Inline code
316
+ result = highlightInlineCode(result);
317
+ // Bold
318
+ result = result.replace(/\*\*([^*]+)\*\*/g, (_, t) => style(t, 'bold'));
319
+ // Italic
320
+ result = result.replace(/\*([^*]+)\*/g, (_, t) => style(t, 'italic'));
321
+ // Headers
322
+ result = result.replace(/^### (.+)$/gm, (_, t) => style(t, 'bold', 'yellow'));
323
+ result = result.replace(/^## (.+)$/gm, (_, t) => style(t, 'bold', 'cyan'));
324
+ result = result.replace(/^# (.+)$/gm, (_, t) => style(t, 'bold', 'green'));
325
+ // Links (just highlight, can't click in terminal)
326
+ result = result.replace(/\[([^\]]+)\]\([^)]+\)/g, (_, t) => style(t, 'underline', 'blue'));
327
+ return result;
328
+ }
329
+ function box(content, options = {}) {
330
+ const lines = Array.isArray(content) ? content : content.split('\n');
331
+ const padding = options.padding ?? 1;
332
+ const borderColor = options.borderColor ?? 'cyan';
333
+ const titleColor = options.titleColor ?? 'bold';
334
+ // Calculate width
335
+ const maxLineLength = Math.max(...lines.map(l => stripAnsi(l).length));
336
+ const innerWidth = maxLineLength + padding * 2;
337
+ const horizontal = '═'.repeat(innerWidth);
338
+ const topBorder = style('╔' + horizontal + '╗', borderColor);
339
+ const bottomBorder = style('╚' + horizontal + '╝', borderColor);
340
+ const result = [];
341
+ // Top border with optional title
342
+ if (options.title) {
343
+ const titleStr = ` ${options.title} `;
344
+ const titleLen = stripAnsi(titleStr).length;
345
+ const leftPad = Math.floor((innerWidth - titleLen) / 2);
346
+ const rightPad = innerWidth - titleLen - leftPad;
347
+ result.push(style('╔' + '═'.repeat(leftPad), borderColor) +
348
+ style(titleStr, titleColor) +
349
+ style('═'.repeat(rightPad) + '╗', borderColor));
350
+ }
351
+ else {
352
+ result.push(topBorder);
353
+ }
354
+ // Content lines
355
+ for (const line of lines) {
356
+ const lineLen = stripAnsi(line).length;
357
+ const rightPad = innerWidth - lineLen - padding;
358
+ result.push(style('║', borderColor) +
359
+ ' '.repeat(padding) +
360
+ line +
361
+ ' '.repeat(Math.max(0, rightPad)) +
362
+ style('║', borderColor));
363
+ }
364
+ result.push(bottomBorder);
365
+ return result.join('\n');
366
+ }
367
+ function table(data, columns) {
368
+ // Calculate column widths
369
+ const widths = columns.map(col => {
370
+ if (col.width)
371
+ return col.width;
372
+ const headerLen = col.header.length;
373
+ const maxDataLen = Math.max(...data.map(row => String(row[col.key] ?? '').length));
374
+ return Math.max(headerLen, maxDataLen);
375
+ });
376
+ const separator = '─'.repeat(widths.reduce((a, b) => a + b + 3, 1));
377
+ const lines = [];
378
+ // Header
379
+ const headerRow = columns.map((col, i) => pad(col.header, widths[i], col.align)).join(' │ ');
380
+ lines.push(style('┌' + separator + '┐', 'dim'));
381
+ lines.push(style('│ ', 'dim') + style(headerRow, 'bold') + style(' │', 'dim'));
382
+ lines.push(style('├' + separator + '┤', 'dim'));
383
+ // Data rows
384
+ for (const row of data) {
385
+ const rowStr = columns.map((col, i) => {
386
+ const value = String(row[col.key] ?? '');
387
+ return pad(value, widths[i], col.align);
388
+ }).join(' │ ');
389
+ lines.push(style('│ ', 'dim') + rowStr + style(' │', 'dim'));
390
+ }
391
+ lines.push(style('└' + separator + '┘', 'dim'));
392
+ return lines.join('\n');
393
+ }
394
+ // ============================================================================
395
+ // Utilities
396
+ // ============================================================================
397
+ /**
398
+ * Strip ANSI codes from string
399
+ */
400
+ function stripAnsi(text) {
401
+ return text.replace(/\x1b\[[0-9;]*m/g, '');
402
+ }
403
+ /**
404
+ * Pad string to width
405
+ */
406
+ function pad(text, width, align = 'left') {
407
+ const len = stripAnsi(text).length;
408
+ if (len >= width)
409
+ return text;
410
+ const padding = width - len;
411
+ switch (align) {
412
+ case 'right':
413
+ return ' '.repeat(padding) + text;
414
+ case 'center':
415
+ const left = Math.floor(padding / 2);
416
+ const right = padding - left;
417
+ return ' '.repeat(left) + text + ' '.repeat(right);
418
+ default:
419
+ return text + ' '.repeat(padding);
420
+ }
421
+ }
422
+ /**
423
+ * Truncate text with ellipsis
424
+ */
425
+ function truncate(text, maxLength) {
426
+ if (text.length <= maxLength)
427
+ return text;
428
+ return text.slice(0, maxLength - 3) + '...';
429
+ }
430
+ /**
431
+ * Format duration in human readable format
432
+ */
433
+ function formatDuration(ms) {
434
+ if (ms < 1000)
435
+ return `${ms}ms`;
436
+ if (ms < 60000)
437
+ return `${(ms / 1000).toFixed(1)}s`;
438
+ const minutes = Math.floor(ms / 60000);
439
+ const seconds = Math.round((ms % 60000) / 1000);
440
+ return `${minutes}m ${seconds}s`;
441
+ }
442
+ /**
443
+ * Format bytes in human readable format
444
+ */
445
+ function formatBytes(bytes) {
446
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
447
+ let i = 0;
448
+ while (bytes >= 1024 && i < units.length - 1) {
449
+ bytes /= 1024;
450
+ i++;
451
+ }
452
+ return `${bytes.toFixed(i > 0 ? 1 : 0)} ${units[i]}`;
453
+ }
454
+ // ============================================================================
455
+ // Input History (for readline enhancement)
456
+ // ============================================================================
457
+ class InputHistory {
458
+ history = [];
459
+ maxSize;
460
+ position = -1;
461
+ constructor(maxSize = 100) {
462
+ this.maxSize = maxSize;
463
+ }
464
+ add(input) {
465
+ // Don't add duplicates of the last entry
466
+ if (input && input !== this.history[0]) {
467
+ this.history.unshift(input);
468
+ if (this.history.length > this.maxSize) {
469
+ this.history.pop();
470
+ }
471
+ }
472
+ this.position = -1;
473
+ }
474
+ previous(current) {
475
+ if (this.position < this.history.length - 1) {
476
+ this.position++;
477
+ return this.history[this.position];
478
+ }
479
+ return null;
480
+ }
481
+ next() {
482
+ if (this.position > 0) {
483
+ this.position--;
484
+ return this.history[this.position];
485
+ }
486
+ if (this.position === 0) {
487
+ this.position = -1;
488
+ return '';
489
+ }
490
+ return null;
491
+ }
492
+ reset() {
493
+ this.position = -1;
494
+ }
495
+ getAll() {
496
+ return [...this.history];
497
+ }
498
+ clear() {
499
+ this.history = [];
500
+ this.position = -1;
501
+ }
502
+ }
503
+ exports.InputHistory = InputHistory;
504
+ // ============================================================================
505
+ // Banner
506
+ // ============================================================================
507
+ function banner(title, subtitle, width = 63) {
508
+ console.log();
509
+ console.log(style('╔' + '═'.repeat(width) + '╗', 'cyan'));
510
+ const titlePadding = width - title.length;
511
+ console.log(style('║', 'cyan') +
512
+ ' ' + style(title, 'bold') +
513
+ ' '.repeat(titlePadding - 2) +
514
+ style('║', 'cyan'));
515
+ if (subtitle) {
516
+ const subPadding = width - subtitle.length;
517
+ console.log(style('║', 'cyan') +
518
+ ' ' + style(subtitle, 'dim') +
519
+ ' '.repeat(subPadding - 2) +
520
+ style('║', 'cyan'));
521
+ }
522
+ console.log(style('╚' + '═'.repeat(width) + '╝', 'cyan'));
523
+ console.log();
524
+ }
525
+ /**
526
+ * Parse thinking blocks from LLM response
527
+ * Supports: <think>...</think>, <thinking>...</thinking>, <reasoning>...</reasoning>
528
+ */
529
+ function parseThinkingBlocks(response) {
530
+ const thinking = [];
531
+ let content = response;
532
+ // Patterns for different thinking block formats
533
+ const patterns = [
534
+ { regex: /<think>([\s\S]*?)<\/think>/gi, type: 'think' },
535
+ { regex: /<thinking>([\s\S]*?)<\/thinking>/gi, type: 'thinking' },
536
+ { regex: /<reasoning>([\s\S]*?)<\/reasoning>/gi, type: 'reasoning' },
537
+ ];
538
+ for (const { regex, type } of patterns) {
539
+ let match;
540
+ while ((match = regex.exec(response)) !== null) {
541
+ thinking.push({
542
+ content: match[1].trim(),
543
+ startIndex: match.index,
544
+ endIndex: match.index + match[0].length,
545
+ type,
546
+ });
547
+ }
548
+ // Remove thinking blocks from content
549
+ content = content.replace(regex, '');
550
+ }
551
+ // Clean up extra whitespace from removal
552
+ content = content.replace(/\n{3,}/g, '\n\n').trim();
553
+ return {
554
+ thinking,
555
+ content,
556
+ hasThinking: thinking.length > 0,
557
+ };
558
+ }
559
+ /**
560
+ * Format a thinking block for display
561
+ * @param block - The thinking block to format
562
+ * @param collapsed - Whether to show collapsed (summary only) or expanded
563
+ * @param maxPreviewLength - Max characters for collapsed preview
564
+ */
565
+ function formatThinkingBlock(block, collapsed = false, maxPreviewLength = 80) {
566
+ const lines = [];
567
+ const icon = '💭';
568
+ const label = block.type === 'reasoning' ? 'Reasoning' : 'Thinking';
569
+ if (collapsed) {
570
+ // Collapsed: show one-line preview
571
+ const preview = block.content
572
+ .replace(/\n/g, ' ')
573
+ .replace(/\s+/g, ' ')
574
+ .trim();
575
+ const truncated = preview.length > maxPreviewLength
576
+ ? preview.slice(0, maxPreviewLength - 3) + '...'
577
+ : preview;
578
+ lines.push(style(` ${icon} [${label}] ${truncated}`, 'dim'));
579
+ }
580
+ else {
581
+ // Expanded: show full thinking with visual distinction
582
+ lines.push(style(` ${icon} ─── ${label} ───`, 'dim'));
583
+ // Indent and dim each line of thinking content
584
+ const thinkingLines = block.content.split('\n');
585
+ for (const line of thinkingLines) {
586
+ lines.push(style(` │ ${line}`, 'dim'));
587
+ }
588
+ lines.push(style(' └───────────────', 'dim'));
589
+ }
590
+ return lines.join('\n');
591
+ }
592
+ /**
593
+ * Format response with thinking blocks
594
+ * @param response - Raw LLM response
595
+ * @param showThinking - Whether to show thinking blocks
596
+ * @param collapsedThinking - Whether thinking should be collapsed
597
+ */
598
+ function formatResponseWithThinking(response, showThinking = true, collapsedThinking = false) {
599
+ const parsed = parseThinkingBlocks(response);
600
+ if (!parsed.hasThinking) {
601
+ return {
602
+ formatted: formatMarkdown(parsed.content),
603
+ hasThinking: false,
604
+ thinkingCount: 0,
605
+ };
606
+ }
607
+ const parts = [];
608
+ // Show thinking blocks first if enabled
609
+ if (showThinking && parsed.thinking.length > 0) {
610
+ for (const block of parsed.thinking) {
611
+ parts.push(formatThinkingBlock(block, collapsedThinking));
612
+ }
613
+ parts.push(''); // Empty line between thinking and response
614
+ }
615
+ else if (parsed.thinking.length > 0) {
616
+ // Just show indicator that thinking was hidden
617
+ parts.push(style(` 💭 [${parsed.thinking.length} thinking block(s) hidden - use /thinking to show]`, 'dim'));
618
+ parts.push('');
619
+ }
620
+ // Add the main response content
621
+ parts.push(formatMarkdown(parsed.content));
622
+ return {
623
+ formatted: parts.join('\n'),
624
+ hasThinking: true,
625
+ thinkingCount: parsed.thinking.length,
626
+ };
627
+ }
628
+ exports.DEFAULT_THINKING_SETTINGS = {
629
+ enabled: true,
630
+ collapsed: false,
631
+ streaming: false,
632
+ };