aether-code 0.31.0 → 0.32.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.
package/src/repl.js CHANGED
@@ -1,293 +1,291 @@
1
- // Interactive REPL — Claude-CLI-style. Launched when `aether-code` is run
2
- // without a task argument.
3
- //
4
- // Behaviors:
5
- // - Banner on startup (version, model, balance, cwd, mode)
6
- // - Persistent message history across prompts within the session
7
- // - Slash commands: /help, /exit, /clear, /balance, /cwd, /yes, /turns
8
- // - Bottom status line is rendered after each turn
9
- // - Ctrl+C: first press cancels in-progress turn, second press exits
10
-
11
- import path from "node:path";
12
- import { runAgent } from "./agent.js";
13
- import { fetchBalance, AetherError } from "./api.js";
14
- import { runSetup } from "./setup.js";
15
- import { c, errorLine, boxLines, sideBySide } from "./render.js";
16
- import { checkForUpdate } from "./update-check.js";
17
- import { promptBox, EXIT_SIGNAL } from "./box-input.js";
18
-
19
- const VERSION = "0.31.0";
20
- const MODEL_NAME = "Aether Core";
21
-
22
- // /model aliases → { id, name }. id=null = server default (gemma / Aether Core).
23
- // Premium models are gated SERVER-SIDE: if you haven't purchased credits, the
24
- // server transparently uses Core instead — selecting one here can't bypass that.
25
- const MODEL_ALIASES = {
26
- core: { id: null, name: "Aether Core" },
27
- gemma: { id: null, name: "Aether Core" },
28
- ultra: { id: "claude-opus-4-6", name: "Aether Ultra" },
29
- opus: { id: "claude-opus-4-6", name: "Aether Ultra" },
30
- max: { id: "grok-4-3", name: "Aether Max" },
31
- grok: { id: "grok-4-3", name: "Aether Max" },
32
- };
33
-
34
- const SHORTCUTS = `
35
- ${c.cyan("/help")} Show this help
36
- ${c.cyan("/exit")} Exit (or Ctrl+C twice)
37
- ${c.cyan("/clear")} Clear conversation history (start fresh)
38
- ${c.cyan("/balance")} Refresh and show credit balance
39
- ${c.cyan("/cwd")} ${c.gray("[path]")} Show or change working directory
40
- ${c.cyan("/yes")} Toggle auto-approve mode (skip y/N prompts)
41
- ${c.cyan("/turns")} ${c.gray("<n>")} Set max turns per prompt (default 25)
42
- ${c.cyan("/model")} ${c.gray("[core|ultra|max]")} Show or switch model (ultra=Opus, max=Grok — premium)
43
-
44
- ${c.gray("Anything else is sent to the agent as your next message.")}
45
- ${c.gray("Conversation history is kept across messages until you /clear.")}
46
- `;
47
-
48
- export async function runRepl({ cwd: initialCwd, autoYes: initialAutoYes, unsafePaths: initialUnsafePaths, maxTurns: initialMaxTurns, model: initialModel = null, mcpManager = null }) {
49
- const initialAlias = Object.values(MODEL_ALIASES).find((a) => a.id === initialModel);
50
- const state = {
51
- cwd: initialCwd,
52
- autoYes: !!initialAutoYes,
53
- unsafePaths: !!initialUnsafePaths,
54
- maxTurns: initialMaxTurns ?? 25,
55
- model: initialModel ?? null,
56
- modelName: initialAlias?.name ?? MODEL_NAME,
57
- messages: [], // accumulates across turns
58
- balance: null,
59
- sessionCredits: 0,
60
- sessionIn: 0,
61
- sessionOut: 0,
62
- };
63
-
64
- // Kick off the npm update check concurrently with the balance fetch so it
65
- // adds no startup latency; the nudge (if any) prints just under the banner.
66
- const updatePromise = checkForUpdate().catch(() => null);
67
-
68
- // Free balance check up front. If no key configured, walk through first-time
69
- // setup flow (open browser → paste key → verify → save).
70
- let needsSetup = false;
71
- try {
72
- const me = await fetchBalance();
73
- state.balance = me.balance;
74
- state.plan = me.plan;
75
- } catch (err) {
76
- if (err instanceof AetherError && (err.code === "NO_API_KEY" || err.status === 401)) {
77
- needsSetup = true;
78
- } else {
79
- // Transient network or other — surface but don't block
80
- console.log(c.gray(`(could not fetch balance: ${err.message})`));
81
- }
82
- }
83
-
84
- if (needsSetup) {
85
- const ok = await runSetup();
86
- if (!ok) {
87
- console.log(c.gray("Aborting — no valid API key."));
88
- process.exit(1);
89
- }
90
- // Re-fetch balance now that the key is saved
91
- try {
92
- const me = await fetchBalance();
93
- state.balance = me.balance;
94
- state.plan = me.plan;
95
- } catch { /* tolerate — banner just won't show balance */ }
96
- }
97
-
98
- printBanner(state);
99
- const updateNudge = await updatePromise;
100
- if (updateNudge) console.log(updateNudge + "\n");
101
-
102
- // Input: a bordered raw-mode box (box-input.js) — cmd.exe-safe and identical
103
- // everywhere. (Ink's live redraw ghosts in the legacy Windows console, so we
104
- // don't use it.) Each prompt is independent; the tool y/N prompts and the
105
- // ask_user menu run BETWEEN prompts in raw mode too, so nothing overlaps.
106
- const inputHistory = [];
107
-
108
- while (true) {
109
- const raw = await promptBox({ history: inputHistory });
110
- if (raw === EXIT_SIGNAL) { console.log(c.gray("bye.")); return; }
111
- const line = (raw ?? "").trim();
112
- if (!line) continue;
113
-
114
- // promptBox already echoes "› <line>" on submit, so no echo needed here.
115
- inputHistory.push(line);
116
-
117
- // Slash command?
118
- if (line.startsWith("/") || line === "?") {
119
- const handled = await handleSlash(line, state);
120
- if (handled === "exit") return;
121
- printStatusLine(state);
122
- continue;
123
- }
124
-
125
- // Otherwise — send as a message to the agent
126
- const result = await runAgent({
127
- initialPrompt: line,
128
- priorMessages: state.messages.length > 0 ? state.messages : undefined,
129
- cwd: state.cwd,
130
- autoYes: state.autoYes,
131
- unsafePaths: state.unsafePaths,
132
- model: state.model,
133
- maxTurns: state.maxTurns,
134
- mcpManager,
135
- });
136
-
137
- state.sessionCredits += result.totalCredits ?? 0;
138
- state.sessionIn += result.totalIn ?? 0;
139
- state.sessionOut += result.totalOut ?? 0;
140
- if (typeof result.balance === "number") state.balance = result.balance;
141
- if (result.messages) state.messages = result.messages;
142
-
143
- if (!result.ok && result.error) {
144
- console.log("\n" + errorLine(result.error.message || String(result.error)));
145
- // Don't kill the session on a single error — surface it and continue.
146
- }
147
-
148
- printStatusLine(state);
149
- }
150
- }
151
-
152
- /* ───────── slash commands ───────── */
153
-
154
- async function handleSlash(line, state) {
155
- const [cmd, ...rest] = line.replace(/^\//, "").split(/\s+/);
156
- const arg = rest.join(" ").trim();
157
-
158
- switch ((cmd || "").toLowerCase()) {
159
- case "":
160
- case "help":
161
- case "?":
162
- console.log(SHORTCUTS);
163
- break;
164
- case "exit":
165
- case "quit":
166
- case "q":
167
- console.log(c.gray("bye."));
168
- return "exit";
169
- case "clear":
170
- state.messages = [];
171
- state.sessionCredits = 0;
172
- state.sessionIn = 0;
173
- state.sessionOut = 0;
174
- console.log(c.gray("Conversation cleared."));
175
- break;
176
- case "balance": {
177
- try {
178
- const me = await fetchBalance();
179
- state.balance = me.balance;
180
- state.plan = me.plan;
181
- console.log(
182
- c.cyan(`balance: ${me.balance.toLocaleString()} credits`) +
183
- c.gray(` · plan: ${me.plan} (${me.planCredits} plan + ${me.topupCredits} topup)`),
184
- );
185
- } catch (err) {
186
- console.log(errorLine(err.message || String(err)));
187
- }
188
- break;
189
- }
190
- case "cwd":
191
- if (arg) {
192
- const next = path.resolve(arg);
193
- try {
194
- process.chdir(next);
195
- state.cwd = next;
196
- console.log(c.gray(`cwd → ${state.cwd}`));
197
- } catch (err) {
198
- console.log(errorLine(err.message));
199
- }
200
- } else {
201
- console.log(c.gray(`cwd: ${state.cwd}`));
202
- }
203
- break;
204
- case "yes":
205
- state.autoYes = !state.autoYes;
206
- console.log(c.gray(`auto-yes: ${state.autoYes ? "on (writes/shells will skip y/N)" : "off"}`));
207
- break;
208
- case "turns": {
209
- const n = parseInt(arg, 10);
210
- if (!Number.isFinite(n) || n < 1 || n > 200) {
211
- console.log(errorLine(`/turns expects 1..200, got "${arg}"`));
212
- } else {
213
- state.maxTurns = n;
214
- console.log(c.gray(`max turns: ${state.maxTurns}`));
215
- }
216
- break;
217
- }
218
- case "model": {
219
- const key = (arg || "").trim().toLowerCase();
220
- if (!key) {
221
- console.log(c.gray(`model: ${state.modelName}`));
222
- console.log(c.gray("switch with /model core | ultra | max (ultra=Opus, max=Grok — premium, need credits)"));
223
- } else if (MODEL_ALIASES[key]) {
224
- state.model = MODEL_ALIASES[key].id;
225
- state.modelName = MODEL_ALIASES[key].name;
226
- const premium = state.model !== null;
227
- console.log(
228
- c.gray(`model → ${c.cyan(state.modelName)}`) +
229
- (premium ? c.gray(" (premium — needs purchased credits, else falls back to Core)") : ""),
230
- );
231
- } else {
232
- console.log(errorLine(`Unknown model "${key}". Try: core, ultra, max`));
233
- }
234
- break;
235
- }
236
- default:
237
- console.log(errorLine(`Unknown command: /${cmd}. Type ${c.cyan("/help")} for shortcuts.`));
238
- }
239
- return null;
240
- }
241
-
242
- /* ───────── banner + status ───────── */
243
-
244
- const visLen = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
245
- const shortenPath = (p, max) => (p.length <= max ? p : "..." + p.slice(p.length - max + 3));
246
-
247
- // Short, hand-curated highlights shown in the "What's new" box. Update with
248
- // notable releases — keep it to ~3 lines so it balances the banner height.
249
- const WHATS_NEW = [
250
- "Files now save to your Desktop",
251
- "Live thinking spinner + loop guard",
252
- "Asks you when a task is unclear",
253
- ];
254
-
255
- function printBanner(state) {
256
- const mode = state.autoYes ? (state.unsafePaths ? "skip-permissions" : "auto-yes") : "review mode";
257
- const credits = state.balance != null ? `${state.balance.toLocaleString()} credits` : "";
258
- const left = boxLines(
259
- [
260
- c.bold(c.magenta("aether")) + c.gray(" · ") + c.bold(state.modelName) + c.gray(" v" + VERSION),
261
- c.gray("uncensored AI coding agent"),
262
- c.gray((credits ? credits + " · " : "") + mode),
263
- c.gray(shortenPath(state.cwd, 52)),
264
- ],
265
- { color: c.magenta, padX: 2 },
266
- );
267
- const right = boxLines(
268
- [c.bold(c.cyan("What's new")), ...WHATS_NEW.map((s) => c.gray("• " + s))],
269
- { color: c.cyan, padX: 2 },
270
- );
271
-
272
- console.log("");
273
- const cols = process.stdout.columns || 80;
274
- // Only place the two boxes side by side when there's room; otherwise the
275
- // banner alone (narrow terminals would wrap and tear the second box).
276
- if (cols >= visLen(left[0]) + visLen(right[0]) + 4) {
277
- console.log(sideBySide(left, right, 3));
278
- } else {
279
- console.log(left.join("\n"));
280
- }
281
- console.log("");
282
- }
283
-
284
- function printStatusLine(state) {
285
- const parts = [];
286
- parts.push(c.gray(`session: ${state.sessionCredits} cr · ${state.sessionIn}→${state.sessionOut} tokens`));
287
- if (state.balance != null) parts.push(c.gray(`balance: ${state.balance.toLocaleString()}`));
288
- if (state.messages.length > 0) {
289
- parts.push(c.gray(`history: ${state.messages.length} msg${state.messages.length === 1 ? "" : "s"}`));
290
- }
291
- parts.push(c.cyan(state.autoYes ? "auto-yes" : "review"));
292
- console.log(c.dim(parts.join(" · ")));
293
- }
1
+ // Interactive REPL — Claude-CLI-style. Launched when `aether-code` is run
2
+ // without a task argument.
3
+ //
4
+ // Behaviors:
5
+ // - Banner on startup (version, model, balance, cwd, mode)
6
+ // - Persistent message history across prompts within the session
7
+ // - Slash commands: /help, /exit, /clear, /balance, /cwd, /yes, /turns
8
+ // - Bottom status line is rendered after each turn
9
+ // - Ctrl+C: first press cancels in-progress turn, second press exits
10
+
11
+ import path from "node:path";
12
+ import { runAgent } from "./agent.js";
13
+ import { fetchBalance, AetherError } from "./api.js";
14
+ import { runSetup } from "./setup.js";
15
+ import { c, errorLine, boxLines, sideBySide } from "./render.js";
16
+ import { checkForUpdate } from "./update-check.js";
17
+ import { promptBox, EXIT_SIGNAL } from "./box-input.js";
18
+
19
+ const VERSION = "0.32.0";
20
+ const MODEL_NAME = "Aether Core";
21
+
22
+ // /model aliases → { id, name }. id=null = server default (gemma / Aether Core).
23
+ // Premium models are gated SERVER-SIDE: if you haven't purchased credits, the
24
+ // server transparently uses Core instead — selecting one here can't bypass that.
25
+ const MODEL_ALIASES = {
26
+ core: { id: null, name: "Aether Core" },
27
+ gemma: { id: null, name: "Aether Core" },
28
+ ultra: { id: "claude-opus-4-6", name: "Aether Ultra" },
29
+ opus: { id: "claude-opus-4-6", name: "Aether Ultra" },
30
+ };
31
+
32
+ const SHORTCUTS = `
33
+ ${c.cyan("/help")} Show this help
34
+ ${c.cyan("/exit")} Exit (or Ctrl+C twice)
35
+ ${c.cyan("/clear")} Clear conversation history (start fresh)
36
+ ${c.cyan("/balance")} Refresh and show credit balance
37
+ ${c.cyan("/cwd")} ${c.gray("[path]")} Show or change working directory
38
+ ${c.cyan("/yes")} Toggle auto-approve mode (skip y/N prompts)
39
+ ${c.cyan("/turns")} ${c.gray("<n>")} Set max turns per prompt (default 25)
40
+ ${c.cyan("/model")} ${c.gray("[core|ultra]")} Show or switch model (ultra=Opus — premium)
41
+
42
+ ${c.gray("Anything else is sent to the agent as your next message.")}
43
+ ${c.gray("Conversation history is kept across messages until you /clear.")}
44
+ `;
45
+
46
+ export async function runRepl({ cwd: initialCwd, autoYes: initialAutoYes, unsafePaths: initialUnsafePaths, maxTurns: initialMaxTurns, model: initialModel = null, mcpManager = null }) {
47
+ const initialAlias = Object.values(MODEL_ALIASES).find((a) => a.id === initialModel);
48
+ const state = {
49
+ cwd: initialCwd,
50
+ autoYes: !!initialAutoYes,
51
+ unsafePaths: !!initialUnsafePaths,
52
+ maxTurns: initialMaxTurns ?? 25,
53
+ model: initialModel ?? null,
54
+ modelName: initialAlias?.name ?? MODEL_NAME,
55
+ messages: [], // accumulates across turns
56
+ balance: null,
57
+ sessionCredits: 0,
58
+ sessionIn: 0,
59
+ sessionOut: 0,
60
+ };
61
+
62
+ // Kick off the npm update check concurrently with the balance fetch so it
63
+ // adds no startup latency; the nudge (if any) prints just under the banner.
64
+ const updatePromise = checkForUpdate().catch(() => null);
65
+
66
+ // Free balance check up front. If no key configured, walk through first-time
67
+ // setup flow (open browser → paste key → verify → save).
68
+ let needsSetup = false;
69
+ try {
70
+ const me = await fetchBalance();
71
+ state.balance = me.balance;
72
+ state.plan = me.plan || "FREE";
73
+ } catch (err) {
74
+ if (err instanceof AetherError && (err.code === "NO_API_KEY" || err.status === 401)) {
75
+ needsSetup = true;
76
+ } else {
77
+ // Transient network or other — surface but don't block
78
+ console.log(c.gray(`(could not fetch balance: ${err.message})`));
79
+ }
80
+ }
81
+
82
+ if (needsSetup) {
83
+ const ok = await runSetup();
84
+ if (!ok) {
85
+ console.log(c.gray("Aborting — no valid API key."));
86
+ process.exit(1);
87
+ }
88
+ // Re-fetch balance now that the key is saved
89
+ try {
90
+ const me = await fetchBalance();
91
+ state.balance = me.balance;
92
+ state.plan = me.plan || "FREE";
93
+ } catch { /* tolerate — banner just won't show balance */ }
94
+ }
95
+
96
+ printBanner(state);
97
+ const updateNudge = await updatePromise;
98
+ if (updateNudge) console.log(updateNudge + "\n");
99
+
100
+ // Input: a bordered raw-mode box (box-input.js) — cmd.exe-safe and identical
101
+ // everywhere. (Ink's live redraw ghosts in the legacy Windows console, so we
102
+ // don't use it.) Each prompt is independent; the tool y/N prompts and the
103
+ // ask_user menu run BETWEEN prompts in raw mode too, so nothing overlaps.
104
+ const inputHistory = [];
105
+
106
+ while (true) {
107
+ const raw = await promptBox({ history: inputHistory });
108
+ if (raw === EXIT_SIGNAL) { console.log(c.gray("bye.")); return; }
109
+ const line = (raw ?? "").trim();
110
+ if (!line) continue;
111
+
112
+ // promptBox already echoes "› <line>" on submit, so no echo needed here.
113
+ inputHistory.push(line);
114
+
115
+ // Slash command?
116
+ if (line.startsWith("/") || line === "?") {
117
+ const handled = await handleSlash(line, state);
118
+ if (handled === "exit") return;
119
+ printStatusLine(state);
120
+ continue;
121
+ }
122
+
123
+ // Otherwise — send as a message to the agent
124
+ const result = await runAgent({
125
+ initialPrompt: line,
126
+ priorMessages: state.messages.length > 0 ? state.messages : undefined,
127
+ cwd: state.cwd,
128
+ autoYes: state.autoYes,
129
+ unsafePaths: state.unsafePaths,
130
+ model: state.model,
131
+ maxTurns: state.maxTurns,
132
+ mcpManager,
133
+ });
134
+
135
+ state.sessionCredits += result.totalCredits ?? 0;
136
+ state.sessionIn += result.totalIn ?? 0;
137
+ state.sessionOut += result.totalOut ?? 0;
138
+ if (typeof result.balance === "number") state.balance = result.balance;
139
+ if (result.messages) state.messages = result.messages;
140
+
141
+ if (!result.ok && result.error) {
142
+ console.log("\n" + errorLine(result.error.message || String(result.error)));
143
+ // Don't kill the session on a single error — surface it and continue.
144
+ }
145
+
146
+ printStatusLine(state);
147
+ }
148
+ }
149
+
150
+ /* ───────── slash commands ───────── */
151
+
152
+ async function handleSlash(line, state) {
153
+ const [cmd, ...rest] = line.replace(/^\//, "").split(/\s+/);
154
+ const arg = rest.join(" ").trim();
155
+
156
+ switch ((cmd || "").toLowerCase()) {
157
+ case "":
158
+ case "help":
159
+ case "?":
160
+ console.log(SHORTCUTS);
161
+ break;
162
+ case "exit":
163
+ case "quit":
164
+ case "q":
165
+ console.log(c.gray("bye."));
166
+ return "exit";
167
+ case "clear":
168
+ state.messages = [];
169
+ state.sessionCredits = 0;
170
+ state.sessionIn = 0;
171
+ state.sessionOut = 0;
172
+ console.log(c.gray("Conversation cleared."));
173
+ break;
174
+ case "balance": {
175
+ try {
176
+ const me = await fetchBalance();
177
+ state.balance = me.balance;
178
+ state.plan = me.plan || "FREE";
179
+ console.log(
180
+ c.cyan(`balance: ${me.balance.toLocaleString()} credits`) +
181
+ c.gray(` · plan: ${me.plan || "FREE"} (${me.planCredits ?? 0} plan + ${me.topupCredits ?? 0} topup)`),
182
+ );
183
+ } catch (err) {
184
+ console.log(errorLine(err.message || String(err)));
185
+ }
186
+ break;
187
+ }
188
+ case "cwd":
189
+ if (arg) {
190
+ const next = path.resolve(arg);
191
+ try {
192
+ process.chdir(next);
193
+ state.cwd = next;
194
+ console.log(c.gray(`cwd → ${state.cwd}`));
195
+ } catch (err) {
196
+ console.log(errorLine(err.message));
197
+ }
198
+ } else {
199
+ console.log(c.gray(`cwd: ${state.cwd}`));
200
+ }
201
+ break;
202
+ case "yes":
203
+ state.autoYes = !state.autoYes;
204
+ console.log(c.gray(`auto-yes: ${state.autoYes ? "on (writes/shells will skip y/N)" : "off"}`));
205
+ break;
206
+ case "turns": {
207
+ const n = parseInt(arg, 10);
208
+ if (!Number.isFinite(n) || n < 1 || n > 200) {
209
+ console.log(errorLine(`/turns expects 1..200, got "${arg}"`));
210
+ } else {
211
+ state.maxTurns = n;
212
+ console.log(c.gray(`max turns: ${state.maxTurns}`));
213
+ }
214
+ break;
215
+ }
216
+ case "model": {
217
+ const key = (arg || "").trim().toLowerCase();
218
+ if (!key) {
219
+ console.log(c.gray(`model: ${state.modelName}`));
220
+ console.log(c.gray("switch with /model core | ultra (ultra=Opus — premium, need credits)"));
221
+ } else if (MODEL_ALIASES[key]) {
222
+ state.model = MODEL_ALIASES[key].id;
223
+ state.modelName = MODEL_ALIASES[key].name;
224
+ const premium = state.model !== null;
225
+ console.log(
226
+ c.gray(`model → ${c.cyan(state.modelName)}`) +
227
+ (premium ? c.gray(" (premium — needs purchased credits, else falls back to Core)") : ""),
228
+ );
229
+ } else {
230
+ console.log(errorLine(`Unknown model "${key}". Try: core, ultra`));
231
+ }
232
+ break;
233
+ }
234
+ default:
235
+ console.log(errorLine(`Unknown command: /${cmd}. Type ${c.cyan("/help")} for shortcuts.`));
236
+ }
237
+ return null;
238
+ }
239
+
240
+ /* ───────── banner + status ───────── */
241
+
242
+ const visLen = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
243
+ const shortenPath = (p, max) => (p.length <= max ? p : "..." + p.slice(p.length - max + 3));
244
+
245
+ // Short, hand-curated highlights shown in the "What's new" box. Update with
246
+ // notable releases — keep it to ~3 lines so it balances the banner height.
247
+ const WHATS_NEW = [
248
+ "Files now save to your Desktop",
249
+ "Live thinking spinner + loop guard",
250
+ "Asks you when a task is unclear",
251
+ ];
252
+
253
+ function printBanner(state) {
254
+ const mode = state.autoYes ? (state.unsafePaths ? "skip-permissions" : "auto-yes") : "review mode";
255
+ const credits = state.balance != null ? `${state.balance.toLocaleString()} credits` : "";
256
+ const left = boxLines(
257
+ [
258
+ c.bold(c.magenta("aether")) + c.gray(" · ") + c.bold(state.modelName) + c.gray(" v" + VERSION),
259
+ c.gray("uncensored AI coding agent"),
260
+ c.gray((credits ? credits + " · " : "") + mode),
261
+ c.gray(shortenPath(state.cwd, 52)),
262
+ ],
263
+ { color: c.magenta, padX: 2 },
264
+ );
265
+ const right = boxLines(
266
+ [c.bold(c.cyan("What's new")), ...WHATS_NEW.map((s) => c.gray("• " + s))],
267
+ { color: c.cyan, padX: 2 },
268
+ );
269
+
270
+ console.log("");
271
+ const cols = process.stdout.columns || 80;
272
+ // Only place the two boxes side by side when there's room; otherwise the
273
+ // banner alone (narrow terminals would wrap and tear the second box).
274
+ if (cols >= visLen(left[0]) + visLen(right[0]) + 4) {
275
+ console.log(sideBySide(left, right, 3));
276
+ } else {
277
+ console.log(left.join("\n"));
278
+ }
279
+ console.log("");
280
+ }
281
+
282
+ function printStatusLine(state) {
283
+ const parts = [];
284
+ parts.push(c.gray(`session: ${state.sessionCredits} cr · ${state.sessionIn}→${state.sessionOut} tokens`));
285
+ if (state.balance != null) parts.push(c.gray(`balance: ${state.balance.toLocaleString()}`));
286
+ if (state.messages.length > 0) {
287
+ parts.push(c.gray(`history: ${state.messages.length} msg${state.messages.length === 1 ? "" : "s"}`));
288
+ }
289
+ parts.push(c.cyan(state.autoYes ? "auto-yes" : "review"));
290
+ console.log(c.dim(parts.join(" · ")));
291
+ }