aether-code 0.43.1 → 0.43.3
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/LICENSE +21 -21
- package/bin/aether-code.js +23 -18
- package/package.json +2 -4
- package/skills/adult-creative-writing.md +60 -60
- package/skills/debugging.md +51 -51
- package/skills/game-modding.md +73 -73
- package/skills/reverse-engineering.md +41 -41
- package/skills/scraping-automation.md +77 -77
- package/skills/security-research.md +67 -67
- package/src/agent.js +311 -175
- package/src/api.js +32 -22
- package/src/box-input.js +36 -141
- package/src/config.js +38 -38
- package/src/diff.js +49 -49
- package/src/ink-input.js +91 -91
- package/src/mcp-cli.js +94 -94
- package/src/mcp-registry.js +266 -266
- package/src/mcp.js +260 -259
- package/src/menu.js +83 -83
- package/src/project-context.js +712 -0
- package/src/render.js +254 -288
- package/src/repl.js +441 -408
- package/src/sessions.js +167 -0
- package/src/setup.js +8 -6
- package/src/tools.js +393 -16
- package/src/update-check.js +7 -64
- package/src/version.js +15 -0
- package/scripts/postinstall.js +0 -182
package/src/render.js
CHANGED
|
@@ -1,288 +1,254 @@
|
|
|
1
|
-
// ANSI helpers — no chalk dependency.
|
|
2
|
-
|
|
3
|
-
const isTty = process.stdout.isTTY;
|
|
4
|
-
const noColor = !!process.env.NO_COLOR || !isTty;
|
|
5
|
-
|
|
6
|
-
function wrap(open, close) {
|
|
7
|
-
return (s) => (noColor ? String(s) : `\x1b[${open}m${s}\x1b[${close}m`);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const c = {
|
|
11
|
-
bold: wrap(1, 22),
|
|
12
|
-
dim: wrap(2, 22),
|
|
13
|
-
red: wrap(31, 39),
|
|
14
|
-
green: wrap(32, 39),
|
|
15
|
-
yellow: wrap(33, 39),
|
|
16
|
-
blue: wrap(34, 39),
|
|
17
|
-
magenta: wrap(35, 39),
|
|
18
|
-
cyan: wrap(36, 39),
|
|
19
|
-
gray: wrap(90, 39),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export function divider() {
|
|
23
|
-
const w = process.stdout.columns || 60;
|
|
24
|
-
return c.gray("─".repeat(Math.min(60, w)));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const stripAnsi = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
case "
|
|
81
|
-
case "
|
|
82
|
-
case "
|
|
83
|
-
case "
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (!summary) {
|
|
256
|
-
summary = name === "read_file" ? `${out.split("\n").length} lines` : ellip(firstLine, 100);
|
|
257
|
-
}
|
|
258
|
-
return ` ${branch} ${c.gray(summary)}`;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const MODEL_TOKEN_RE = /<\|[a-z_]*\|?>|<[a-z_]+\|>/gi;
|
|
262
|
-
|
|
263
|
-
export function stripModelTokens(text) {
|
|
264
|
-
return text.replace(MODEL_TOKEN_RE, "");
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export function makeTokenStripper() {
|
|
268
|
-
let buf = "";
|
|
269
|
-
return {
|
|
270
|
-
push(text) {
|
|
271
|
-
buf = (buf + text).replace(MODEL_TOKEN_RE, "");
|
|
272
|
-
const partial = buf.match(/<[|a-z_/]*$/i);
|
|
273
|
-
if (partial) {
|
|
274
|
-
const emit = buf.slice(0, partial.index);
|
|
275
|
-
buf = buf.slice(partial.index);
|
|
276
|
-
return emit;
|
|
277
|
-
}
|
|
278
|
-
const emit = buf;
|
|
279
|
-
buf = "";
|
|
280
|
-
return emit;
|
|
281
|
-
},
|
|
282
|
-
flush() {
|
|
283
|
-
const out = buf.replace(MODEL_TOKEN_RE, "");
|
|
284
|
-
buf = "";
|
|
285
|
-
return out;
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
}
|
|
1
|
+
// ANSI helpers — no chalk dependency.
|
|
2
|
+
|
|
3
|
+
const isTty = process.stdout.isTTY;
|
|
4
|
+
const noColor = !!process.env.NO_COLOR || !isTty;
|
|
5
|
+
|
|
6
|
+
function wrap(open, close) {
|
|
7
|
+
return (s) => (noColor ? String(s) : `\x1b[${open}m${s}\x1b[${close}m`);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const c = {
|
|
11
|
+
bold: wrap(1, 22),
|
|
12
|
+
dim: wrap(2, 22),
|
|
13
|
+
red: wrap(31, 39),
|
|
14
|
+
green: wrap(32, 39),
|
|
15
|
+
yellow: wrap(33, 39),
|
|
16
|
+
blue: wrap(34, 39),
|
|
17
|
+
magenta: wrap(35, 39),
|
|
18
|
+
cyan: wrap(36, 39),
|
|
19
|
+
gray: wrap(90, 39),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function divider() {
|
|
23
|
+
const w = process.stdout.columns || 60;
|
|
24
|
+
return c.gray("─".repeat(Math.min(60, w)));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const stripAnsi = (s) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
28
|
+
|
|
29
|
+
// Draw a bordered box around content lines, returning the rows as an array (so
|
|
30
|
+
// boxes can be composed side by side). Rounded box-drawing chars.
|
|
31
|
+
export function boxLines(lines, { color = c.gray, padX = 2, minInner = 0 } = {}) {
|
|
32
|
+
const inner = Math.max(minInner, 0, ...lines.map((l) => stripAnsi(l).length));
|
|
33
|
+
const w = inner + padX * 2;
|
|
34
|
+
const top = color("╭" + "─".repeat(w) + "╮");
|
|
35
|
+
const bot = color("╰" + "─".repeat(w) + "╯");
|
|
36
|
+
const mid = lines.map(
|
|
37
|
+
(l) => color("│") + " ".repeat(padX) + l + " ".repeat(inner - stripAnsi(l).length + padX) + color("│"),
|
|
38
|
+
);
|
|
39
|
+
return [top, ...mid, bot];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function box(lines, opts) {
|
|
43
|
+
return boxLines(lines, opts).join("\n");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Join two blocks of lines horizontally with a gap, padding the left block to a
|
|
47
|
+
// uniform width so the right block aligns. Shorter block is padded with blanks.
|
|
48
|
+
export function sideBySide(a, b, gap = 3) {
|
|
49
|
+
const wa = Math.max(0, ...a.map((l) => stripAnsi(l).length));
|
|
50
|
+
const h = Math.max(a.length, b.length);
|
|
51
|
+
const out = [];
|
|
52
|
+
for (let i = 0; i < h; i++) {
|
|
53
|
+
const la = a[i] ?? "";
|
|
54
|
+
const lb = b[i] ?? "";
|
|
55
|
+
out.push(la + " ".repeat(wa - stripAnsi(la).length + gap) + lb);
|
|
56
|
+
}
|
|
57
|
+
return out.join("\n");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function turn(n) {
|
|
61
|
+
return c.gray(`turn ${n}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function toolHeader(name, args) {
|
|
65
|
+
// Format args compactly. If any value is huge, truncate it.
|
|
66
|
+
const compact = JSON.stringify(args);
|
|
67
|
+
const trimmed = compact.length > 120 ? compact.slice(0, 117) + "..." : compact;
|
|
68
|
+
return `${c.cyan(c.bold(name))}${c.gray("(")}${c.gray(trimmed)}${c.gray(")")}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ellip = (s, n) => (s && s.length > n ? s.slice(0, n - 1) + "…" : s || "");
|
|
72
|
+
|
|
73
|
+
// Clean one-line label for a tool call — a verb + its key argument, instead of
|
|
74
|
+
// dumping raw JSON (which buried file contents / queries in noise).
|
|
75
|
+
export function toolLabel(name, args) {
|
|
76
|
+
const a = args || {};
|
|
77
|
+
const verb = (v) => c.bold(v);
|
|
78
|
+
const arg = (s) => ellip(String(s), 72);
|
|
79
|
+
switch (name) {
|
|
80
|
+
case "read_file": return `${verb("Read")} ${arg(a.path)}`;
|
|
81
|
+
case "write_file": return `${verb("Write")} ${arg(a.path)}`;
|
|
82
|
+
case "edit_file": return `${verb("Edit")} ${arg(a.path)}`;
|
|
83
|
+
case "list_dir": return `${verb("List")} ${arg(a.path)}`;
|
|
84
|
+
case "glob_files": return `${verb("Glob")} ${arg(a.pattern)}`;
|
|
85
|
+
case "search_files": return `${verb("Grep")} ${arg(`/${a.pattern}/${a.path ? ` in ${a.path}` : ""}`)}`;
|
|
86
|
+
case "run_shell": return `${verb("Bash")} ${c.dim(ellip(String(a.command), 72))}`;
|
|
87
|
+
case "web_search": return `${verb("Search")} ${arg(a.query ?? "")}`;
|
|
88
|
+
case "web_fetch": return `${verb("Fetch")} ${arg(a.url)}`;
|
|
89
|
+
case "todo_write": return "";
|
|
90
|
+
case "ask_user": return "";
|
|
91
|
+
case "git_status": return `${verb("Git")} ${arg("status")}`;
|
|
92
|
+
case "git_diff": return `${verb("Git")} ${arg("diff" + (a.staged ? " --staged" : "") + (a.base ? ` ${a.base}...${a.head || "HEAD"}` : ""))}`;
|
|
93
|
+
case "git_log": return `${verb("Git")} ${arg("log" + (a.file ? ` -- ${a.file}` : "") + (a.branch ? ` ${a.branch}` : ""))}`;
|
|
94
|
+
case "git_commit": return `${verb("Git")} ${arg(`commit "${ellip(a.message || "", 50)}"`)}`
|
|
95
|
+
case "git_branch": return `${verb("Git")} ${arg(`branch ${a.name}`)}`;
|
|
96
|
+
case "git_push": return `${verb("Git")} ${arg("push" + (a.force ? " --force" : ""))}`;
|
|
97
|
+
case "git_create_pr": return `${verb("Git")} ${arg(`pr "${ellip(a.title || "", 50)}"`)}`
|
|
98
|
+
default: return `${verb(name)} ${arg(JSON.stringify(a))}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Set the terminal window/tab title (so cmd.exe shows "Aether", not the node
|
|
103
|
+
// path). OSC 0 — supported by cmd.exe, Windows Terminal, and POSIX terminals.
|
|
104
|
+
export function setTerminalTitle(title) {
|
|
105
|
+
if (process.stdout.isTTY) process.stdout.write(`\x1b]0;${title}\x07`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Live "working…" spinner. Rewrites a single line in place (\r) with a rotating
|
|
109
|
+
// half-circle (Geometric Shapes — same block as ●, so cmd.exe-safe) + elapsed
|
|
110
|
+
// seconds, so the user sees the agent is alive while the model thinks or a slow
|
|
111
|
+
// tool runs. stop() clears the line and restores the cursor. No-op in non-TTY.
|
|
112
|
+
export function startSpinner(label) {
|
|
113
|
+
if (!process.stdout.isTTY) return { stop: () => {} };
|
|
114
|
+
const frames = ["◐", "◓", "◑", "◒"];
|
|
115
|
+
const t0 = Date.now();
|
|
116
|
+
let i = 0;
|
|
117
|
+
process.stdout.write("\x1b[?25l"); // hide cursor
|
|
118
|
+
const render = () => {
|
|
119
|
+
const s = Math.floor((Date.now() - t0) / 1000);
|
|
120
|
+
const tail = s > 0 ? c.gray(` ${s}s`) : "";
|
|
121
|
+
process.stdout.write(`\r\x1b[K${c.cyan(frames[i % frames.length])} ${c.gray(label + "…")}${tail}`);
|
|
122
|
+
i++;
|
|
123
|
+
};
|
|
124
|
+
render();
|
|
125
|
+
const timer = setInterval(render, 120);
|
|
126
|
+
if (typeof timer.unref === "function") timer.unref(); // don't keep the process alive
|
|
127
|
+
return {
|
|
128
|
+
stop: () => {
|
|
129
|
+
clearInterval(timer);
|
|
130
|
+
process.stdout.write("\r\x1b[K\x1b[?25h"); // clear line + show cursor
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Terse one-line result summary instead of dumping raw JSON / file contents.
|
|
136
|
+
// Tools whose handlers already render rich output (diffs, the shell stream, the
|
|
137
|
+
// plan) just get a check — the detail was already printed.
|
|
138
|
+
export function toolSummary(name, result) {
|
|
139
|
+
const ok = result.ok;
|
|
140
|
+
// A tree branch links the result to the action above it (modern CLI style).
|
|
141
|
+
const branch = ok ? c.green("└─") : c.red("└─");
|
|
142
|
+
const out = result.output ?? "";
|
|
143
|
+
const firstLine = out.split("\n").find((l) => l.trim()) ?? "";
|
|
144
|
+
|
|
145
|
+
if (name === "run_shell") {
|
|
146
|
+
let code = null;
|
|
147
|
+
try { code = JSON.parse(out).exit_code; } catch { /* ignore */ }
|
|
148
|
+
return ` ${branch} ${c.gray(code === null ? (ok ? "done" : "failed") : `exit ${code}`)}`;
|
|
149
|
+
}
|
|
150
|
+
if (name === "todo_write") return ""; // the Plan is its own feedback
|
|
151
|
+
if (name === "ask_user") return ""; // the menu already showed the answer
|
|
152
|
+
if (name === "git_commit" || name === "git_push" || name === "git_create_pr") {
|
|
153
|
+
return ` ${branch} ${c.gray(ellip(firstLine, 100))}`;
|
|
154
|
+
}
|
|
155
|
+
if (name === "git_status") {
|
|
156
|
+
try {
|
|
157
|
+
const s = JSON.parse(out);
|
|
158
|
+
if (s.clean) return ` ${branch} ${c.gray("clean")}`;
|
|
159
|
+
const parts = [];
|
|
160
|
+
if (s.staged?.length) parts.push(`${s.staged.length} staged`);
|
|
161
|
+
if (s.unstaged?.length) parts.push(`${s.unstaged.length} modified`);
|
|
162
|
+
if (s.untracked?.length) parts.push(`${s.untracked.length} untracked`);
|
|
163
|
+
return ` ${branch} ${c.gray(parts.join(", "))}`;
|
|
164
|
+
} catch { /* fall through */ }
|
|
165
|
+
}
|
|
166
|
+
if (name === "git_diff") {
|
|
167
|
+
if (out === "(no changes)") return ` ${branch} ${c.gray("no changes")}`;
|
|
168
|
+
const diffLines = out.split("\n").length;
|
|
169
|
+
return ` ${branch} ${c.gray(`${diffLines} lines of diff`)}`;
|
|
170
|
+
}
|
|
171
|
+
if (name === "git_log") {
|
|
172
|
+
const logLines = out.trim().split("\n").filter((l) => l.trim()).length;
|
|
173
|
+
return ` ${branch} ${c.gray(`${logLines} lines`)}`;
|
|
174
|
+
}
|
|
175
|
+
if (name === "git_branch") {
|
|
176
|
+
return ` ${branch} ${c.gray(ellip(firstLine, 100))}`;
|
|
177
|
+
}
|
|
178
|
+
if (name === "write_file" || name === "edit_file") {
|
|
179
|
+
// Handler already printed the diff; echo its short status line.
|
|
180
|
+
return ` ${branch} ${c.gray(ellip(firstLine, 100))}`;
|
|
181
|
+
}
|
|
182
|
+
let summary = "";
|
|
183
|
+
try {
|
|
184
|
+
const j = JSON.parse(out);
|
|
185
|
+
if (Array.isArray(j)) summary = `${j.length} result${j.length === 1 ? "" : "s"}`;
|
|
186
|
+
else if (Array.isArray(j.files)) summary = `${j.files.length} file${j.files.length === 1 ? "" : "s"}`;
|
|
187
|
+
else if (Array.isArray(j.matches)) summary = `${j.matches.length} match${j.matches.length === 1 ? "" : "es"}`;
|
|
188
|
+
} catch { /* not JSON */ }
|
|
189
|
+
if (!summary) {
|
|
190
|
+
summary = name === "read_file" ? `${out.split("\n").length} lines` : ellip(firstLine, 100);
|
|
191
|
+
}
|
|
192
|
+
return ` ${branch} ${c.gray(summary)}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Strip model "harmony"/channel control tokens (<|channel|>, <|message|>,
|
|
196
|
+
// <|tool_response|>, <channel|>, …) that occasionally leak into the text
|
|
197
|
+
// stream. Belt-and-suspenders alongside the server-side scrub.
|
|
198
|
+
// Only strips tokens containing a PIPE — the harmony/channel control tokens
|
|
199
|
+
// (<|channel|>, <|tool_response|>, <channel|>) always have one. Real code like
|
|
200
|
+
// <div>, Vec<T>, a < b has no pipe and is left untouched.
|
|
201
|
+
const MODEL_TOKEN_RE = /<\|[a-z_]*\|?>|<[a-z_]+\|>/gi;
|
|
202
|
+
|
|
203
|
+
export function stripModelTokens(text) {
|
|
204
|
+
return text.replace(MODEL_TOKEN_RE, "");
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Streaming-safe stripper: the leaked tokens (<|channel|>, <|tool_response|>, …)
|
|
208
|
+
// can be split across stream chunks ("<chann" then "el|>"), which a per-delta
|
|
209
|
+
// regex misses. This buffers any trailing "<…" that might be the start of a
|
|
210
|
+
// token and only emits it once it's confirmed not-a-token (or on flush).
|
|
211
|
+
export function makeTokenStripper() {
|
|
212
|
+
let buf = "";
|
|
213
|
+
return {
|
|
214
|
+
push(text) {
|
|
215
|
+
buf = (buf + text).replace(MODEL_TOKEN_RE, "");
|
|
216
|
+
const partial = buf.match(/<[|a-z_/]*$/i); // possible token start at the tail
|
|
217
|
+
if (partial) {
|
|
218
|
+
const emit = buf.slice(0, partial.index);
|
|
219
|
+
buf = buf.slice(partial.index);
|
|
220
|
+
return emit;
|
|
221
|
+
}
|
|
222
|
+
const emit = buf;
|
|
223
|
+
buf = "";
|
|
224
|
+
return emit;
|
|
225
|
+
},
|
|
226
|
+
flush() {
|
|
227
|
+
const out = buf.replace(MODEL_TOKEN_RE, "");
|
|
228
|
+
buf = "";
|
|
229
|
+
return out;
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function toolResult(text, ok = true) {
|
|
235
|
+
const prefix = ok ? c.green(" ● ") : c.red(" × ");
|
|
236
|
+
// First line bold-ish, then dim continuation
|
|
237
|
+
const lines = text.split("\n");
|
|
238
|
+
const head = lines[0].slice(0, 200);
|
|
239
|
+
const rest = lines.slice(1, 6).join("\n").slice(0, 600);
|
|
240
|
+
return `${prefix}${head}${rest ? "\n" + c.dim(rest) : ""}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function assistant(text) {
|
|
244
|
+
// Indent each line for visual separation from tool calls
|
|
245
|
+
return text.split("\n").map((l) => ` ${l}`).join("\n");
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function errorLine(msg) {
|
|
249
|
+
return `${c.red(c.bold("Error:"))} ${msg}`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function note(msg) {
|
|
253
|
+
return c.dim(msg);
|
|
254
|
+
}
|