aether-code 0.32.2 → 0.33.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/render.js CHANGED
@@ -98,33 +98,69 @@ export function setTerminalTitle(title) {
98
98
  if (process.stdout.isTTY) process.stdout.write(`\x1b]0;${title}\x07`);
99
99
  }
100
100
 
101
- // Live "working…" spinner. Rewrites a single line in place (\r) with a rotating
102
- // half-circle (Geometric Shapes — same block as ●, so cmd.exe-safe) + elapsed
103
- // seconds, so the user sees the agent is alive while the model thinks or a slow
104
- // tool runs. stop() clears the line and restores the cursor. No-op in non-TTY.
101
+ // Live "working…" spinner with optional live metrics (token count, status).
102
+ // Rewrites a single line in place (\r) with a rotating half-circle + elapsed
103
+ // time (mm:ss when > 60s) + any metrics fed via update(). stop() clears the
104
+ // line and restores the cursor. No-op in non-TTY.
105
105
  export function startSpinner(label) {
106
- if (!process.stdout.isTTY) return { stop: () => {} };
106
+ if (!process.stdout.isTTY) return { stop: () => {}, update: () => {} };
107
107
  const frames = ["◐", "◓", "◑", "◒"];
108
108
  const t0 = Date.now();
109
109
  let i = 0;
110
+ let tokenCount = 0;
111
+ let statusText = "";
110
112
  process.stdout.write("\x1b[?25l"); // hide cursor
111
113
  const render = () => {
112
- const s = Math.floor((Date.now() - t0) / 1000);
113
- const tail = s > 0 ? c.gray(` ${s}s`) : "";
114
- process.stdout.write(`\r\x1b[K${c.cyan(frames[i % frames.length])} ${c.gray(label + "…")}${tail}`);
114
+ const ms = Date.now() - t0;
115
+ const secs = Math.floor(ms / 1000);
116
+ const timeFmt = secs >= 60
117
+ ? `${Math.floor(secs / 60)}m ${String(secs % 60).padStart(2, "0")}s`
118
+ : `${secs}s`;
119
+ const parts = [];
120
+ if (secs > 0) parts.push(timeFmt);
121
+ if (tokenCount > 0) parts.push(`↓ ${fmtTokens(tokenCount)} tokens`);
122
+ if (statusText) parts.push(statusText);
123
+ const metrics = parts.length > 0 ? c.gray(` (${parts.join(" · ")})`) : "";
124
+ process.stdout.write(`\r\x1b[K${c.cyan(frames[i % frames.length])} ${c.gray(label + "…")}${metrics}`);
115
125
  i++;
116
126
  };
117
127
  render();
118
128
  const timer = setInterval(render, 120);
119
129
  if (typeof timer.unref === "function") timer.unref(); // don't keep the process alive
120
130
  return {
121
- stop: () => {
131
+ update(data) {
132
+ if (data.tokens != null) tokenCount = data.tokens;
133
+ if (data.status != null) statusText = data.status;
134
+ },
135
+ stop() {
122
136
  clearInterval(timer);
123
137
  process.stdout.write("\r\x1b[K\x1b[?25h"); // clear line + show cursor
124
138
  },
125
139
  };
126
140
  }
127
141
 
142
+ // Human-friendly token count (14.2k, 1.3M, etc.)
143
+ export function fmtTokens(n) {
144
+ if (n >= 1_000_000) return (n / 1_000_000).toFixed(1) + "M";
145
+ if (n >= 1_000) return (n / 1_000).toFixed(1) + "k";
146
+ return String(n);
147
+ }
148
+
149
+ // Compact one-line turn summary printed after each agent turn completes.
150
+ export function turnStats({ elapsed, tokensIn, tokensOut, tools, credits }) {
151
+ const parts = [];
152
+ if (elapsed > 0) {
153
+ const s = Math.floor(elapsed / 1000);
154
+ parts.push(s >= 60 ? `${Math.floor(s / 60)}m ${String(s % 60).padStart(2, "0")}s` : `${s}s`);
155
+ }
156
+ if (tokensIn > 0 || tokensOut > 0) {
157
+ parts.push(`${fmtTokens(tokensIn)}→${fmtTokens(tokensOut)} tokens`);
158
+ }
159
+ if (tools > 0) parts.push(`${tools} tool call${tools === 1 ? "" : "s"}`);
160
+ if (credits > 0) parts.push(`${credits} cr`);
161
+ return parts.length > 0 ? c.dim(` ── ${parts.join(" · ")}`) : "";
162
+ }
163
+
128
164
  // Terse one-line result summary instead of dumping raw JSON / file contents.
129
165
  // Tools whose handlers already render rich output (diffs, the shell stream, the
130
166
  // plan) just get a check — the detail was already printed.
package/src/repl.js CHANGED
@@ -1,291 +1,249 @@
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
- }
1
+ // Interactive REPL — Claude-CLI-style. Launched when `aether-code` is run
2
+ // without a task argument.
3
+
4
+ import path from "node:path";
5
+ import { runAgent } from "./agent.js";
6
+ import { fetchBalance, AetherError } from "./api.js";
7
+ import { runSetup } from "./setup.js";
8
+ import { c, boxLines, errorLine } from "./render.js";
9
+ import { autoUpdate } from "./update-check.js";
10
+ import { promptBox, EXIT_SIGNAL } from "./box-input.js";
11
+
12
+ const VERSION = "0.33.1";
13
+ const MODEL_NAME = "Aether Core";
14
+
15
+ const MODEL_ALIASES = {
16
+ core: { id: null, name: "Aether Core" },
17
+ gemma: { id: null, name: "Aether Core" },
18
+ ultra: { id: "claude-opus-4-6", name: "Aether Ultra" },
19
+ opus: { id: "claude-opus-4-6", name: "Aether Ultra" },
20
+ };
21
+
22
+ const SHORTCUTS = `
23
+ ${c.cyan("/help")} Show this help
24
+ ${c.cyan("/exit")} Exit (or Ctrl+C twice)
25
+ ${c.cyan("/clear")} Clear conversation history (start fresh)
26
+ ${c.cyan("/balance")} Refresh and show credit balance
27
+ ${c.cyan("/cwd")} ${c.gray("[path]")} Show or change working directory
28
+ ${c.cyan("/yes")} Toggle auto-approve mode (skip y/N prompts)
29
+ ${c.cyan("/turns")} ${c.gray("<n>")} Set max turns per prompt (default 25)
30
+ ${c.cyan("/model")} ${c.gray("[core|ultra]")} Show or switch model (ultra=Opus — premium)
31
+
32
+ ${c.gray("Anything else is sent to the agent as your next message.")}
33
+ ${c.gray("Conversation history is kept across messages until you /clear.")}
34
+ `;
35
+
36
+ export async function runRepl({ cwd: initialCwd, autoYes: initialAutoYes, unsafePaths: initialUnsafePaths, maxTurns: initialMaxTurns, model: initialModel = null, mcpManager = null }) {
37
+ const initialAlias = Object.values(MODEL_ALIASES).find((a) => a.id === initialModel);
38
+ const state = {
39
+ cwd: initialCwd,
40
+ autoYes: !!initialAutoYes,
41
+ unsafePaths: !!initialUnsafePaths,
42
+ maxTurns: initialMaxTurns ?? 25,
43
+ model: initialModel ?? null,
44
+ modelName: initialAlias?.name ?? MODEL_NAME,
45
+ messages: [],
46
+ balance: null,
47
+ sessionCredits: 0,
48
+ sessionIn: 0,
49
+ sessionOut: 0,
50
+ };
51
+
52
+ // Auto-update + balance fetch in parallel — zero startup latency added.
53
+ const updatePromise = autoUpdate().catch(() => null);
54
+
55
+ let needsSetup = false;
56
+ try {
57
+ const me = await fetchBalance();
58
+ state.balance = me.balance;
59
+ state.plan = me.plan || "FREE";
60
+ } catch (err) {
61
+ if (err instanceof AetherError && (err.code === "NO_API_KEY" || err.status === 401)) {
62
+ needsSetup = true;
63
+ } else {
64
+ console.log(c.gray(`(could not fetch balance: ${err.message})`));
65
+ }
66
+ }
67
+
68
+ if (needsSetup) {
69
+ const ok = await runSetup();
70
+ if (!ok) {
71
+ console.log(c.gray("Aborting — no valid API key."));
72
+ process.exit(1);
73
+ }
74
+ try {
75
+ const me = await fetchBalance();
76
+ state.balance = me.balance;
77
+ state.plan = me.plan || "FREE";
78
+ } catch { /* tolerate */ }
79
+ }
80
+
81
+ printBanner(state);
82
+ const updateMsg = await updatePromise;
83
+ if (updateMsg) console.log(updateMsg + "\n");
84
+
85
+ const inputHistory = [];
86
+
87
+ while (true) {
88
+ const raw = await promptBox({ history: inputHistory });
89
+ if (raw === EXIT_SIGNAL) { console.log(c.gray("bye.")); return; }
90
+ const line = (raw ?? "").trim();
91
+ if (!line) continue;
92
+
93
+ inputHistory.push(line);
94
+
95
+ if (line.startsWith("/") || line === "?") {
96
+ const handled = await handleSlash(line, state);
97
+ if (handled === "exit") return;
98
+ printStatusLine(state);
99
+ continue;
100
+ }
101
+
102
+ const result = await runAgent({
103
+ initialPrompt: line,
104
+ priorMessages: state.messages.length > 0 ? state.messages : undefined,
105
+ cwd: state.cwd,
106
+ autoYes: state.autoYes,
107
+ unsafePaths: state.unsafePaths,
108
+ model: state.model,
109
+ maxTurns: state.maxTurns,
110
+ mcpManager,
111
+ });
112
+
113
+ state.sessionCredits += result.totalCredits ?? 0;
114
+ state.sessionIn += result.totalIn ?? 0;
115
+ state.sessionOut += result.totalOut ?? 0;
116
+ if (typeof result.balance === "number") state.balance = result.balance;
117
+ if (result.messages) state.messages = result.messages;
118
+
119
+ if (!result.ok && result.error) {
120
+ console.log("\n" + errorLine(result.error.message || String(result.error)));
121
+ }
122
+
123
+ printStatusLine(state);
124
+ }
125
+ }
126
+
127
+ /* ───────── slash commands ───────── */
128
+
129
+ async function handleSlash(line, state) {
130
+ const [cmd, ...rest] = line.replace(/^\//, "").split(/\s+/);
131
+ const arg = rest.join(" ").trim();
132
+
133
+ switch ((cmd || "").toLowerCase()) {
134
+ case "":
135
+ case "help":
136
+ case "?":
137
+ console.log(SHORTCUTS);
138
+ break;
139
+ case "exit":
140
+ case "quit":
141
+ case "q":
142
+ console.log(c.gray("bye."));
143
+ return "exit";
144
+ case "clear":
145
+ state.messages = [];
146
+ state.sessionCredits = 0;
147
+ state.sessionIn = 0;
148
+ state.sessionOut = 0;
149
+ console.log(c.gray("Conversation cleared."));
150
+ break;
151
+ case "balance": {
152
+ try {
153
+ const me = await fetchBalance();
154
+ state.balance = me.balance;
155
+ state.plan = me.plan || "FREE";
156
+ console.log(
157
+ c.cyan(`balance: ${me.balance.toLocaleString()} credits`) +
158
+ c.gray(` · plan: ${me.plan || "FREE"} (${me.planCredits ?? 0} plan + ${me.topupCredits ?? 0} topup)`),
159
+ );
160
+ } catch (err) {
161
+ console.log(errorLine(err.message || String(err)));
162
+ }
163
+ break;
164
+ }
165
+ case "cwd":
166
+ if (arg) {
167
+ const next = path.resolve(arg);
168
+ try {
169
+ process.chdir(next);
170
+ state.cwd = next;
171
+ console.log(c.gray(`cwd → ${state.cwd}`));
172
+ } catch (err) {
173
+ console.log(errorLine(err.message));
174
+ }
175
+ } else {
176
+ console.log(c.gray(`cwd: ${state.cwd}`));
177
+ }
178
+ break;
179
+ case "yes":
180
+ state.autoYes = !state.autoYes;
181
+ console.log(c.gray(`auto-yes: ${state.autoYes ? "on (writes/shells will skip y/N)" : "off"}`));
182
+ break;
183
+ case "turns": {
184
+ const n = parseInt(arg, 10);
185
+ if (!Number.isFinite(n) || n < 1 || n > 200) {
186
+ console.log(errorLine(`/turns expects 1..200, got "${arg}"`));
187
+ } else {
188
+ state.maxTurns = n;
189
+ console.log(c.gray(`max turns: ${state.maxTurns}`));
190
+ }
191
+ break;
192
+ }
193
+ case "model": {
194
+ const key = (arg || "").trim().toLowerCase();
195
+ if (!key) {
196
+ console.log(c.gray(`model: ${state.modelName}`));
197
+ console.log(c.gray("switch with /model core | ultra (ultra=Opus — premium, need credits)"));
198
+ } else if (MODEL_ALIASES[key]) {
199
+ state.model = MODEL_ALIASES[key].id;
200
+ state.modelName = MODEL_ALIASES[key].name;
201
+ const premium = state.model !== null;
202
+ console.log(
203
+ c.gray(`model → ${c.cyan(state.modelName)}`) +
204
+ (premium ? c.gray(" (premium — needs purchased credits, else falls back to Core)") : ""),
205
+ );
206
+ } else {
207
+ console.log(errorLine(`Unknown model "${key}". Try: core, ultra`));
208
+ }
209
+ break;
210
+ }
211
+ default:
212
+ console.log(errorLine(`Unknown command: /${cmd}. Type ${c.cyan("/help")} for shortcuts.`));
213
+ }
214
+ return null;
215
+ }
216
+
217
+ /* ───────── banner + status ───────── */
218
+
219
+ const shortenPath = (p, max) => (p.length <= max ? p : "..." + p.slice(p.length - max + 3));
220
+
221
+ function printBanner(state) {
222
+ const credits = state.balance != null ? `${state.balance.toLocaleString()} credits` : "";
223
+
224
+ // Single clean banner box — Claude Code style
225
+ const lines = [
226
+ c.bold(c.cyan("✦ Aether Code")) + c.gray(" v" + VERSION),
227
+ "",
228
+ c.gray(" " + state.modelName + (credits ? " · " + credits : "")),
229
+ c.gray(" cwd: " + shortenPath(state.cwd, 52)),
230
+ "",
231
+ c.dim(" Ctrl+V paste · @file image · /help"),
232
+ ];
233
+
234
+ const banner = boxLines(lines, { color: c.cyan, padX: 1, minInner: 50 });
235
+ console.log("");
236
+ console.log(banner.join("\n"));
237
+ console.log("");
238
+ }
239
+
240
+ function printStatusLine(state) {
241
+ const parts = [];
242
+ parts.push(c.gray(`session: ${state.sessionCredits} cr · ${state.sessionIn}→${state.sessionOut} tokens`));
243
+ if (state.balance != null) parts.push(c.gray(`balance: ${state.balance.toLocaleString()}`));
244
+ if (state.messages.length > 0) {
245
+ parts.push(c.gray(`history: ${state.messages.length} msg${state.messages.length === 1 ? "" : "s"}`));
246
+ }
247
+ parts.push(c.cyan(state.autoYes ? "auto-yes" : "review"));
248
+ console.log(c.dim(parts.join(" · ")));
249
+ }