amness 0.0.0-stage → 0.1.0
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 -0
- package/README.md +212 -2
- package/dist/cli/acpcli.d.ts +7 -0
- package/dist/cli/acpcli.js +14 -0
- package/dist/cli/amness.d.ts +2 -0
- package/dist/cli/amness.js +693 -0
- package/dist/cli/benchcli.d.ts +5 -0
- package/dist/cli/benchcli.js +160 -0
- package/dist/cli/config.d.ts +79 -0
- package/dist/cli/config.js +54 -0
- package/dist/cli/demo.d.ts +13 -0
- package/dist/cli/demo.js +44 -0
- package/dist/cli/detect.d.ts +2 -0
- package/dist/cli/detect.js +20 -0
- package/dist/cli/evalcli.d.ts +15 -0
- package/dist/cli/evalcli.js +198 -0
- package/dist/cli/format.d.ts +5 -0
- package/dist/cli/format.js +55 -0
- package/dist/cli/headless.d.ts +2 -0
- package/dist/cli/headless.js +169 -0
- package/dist/cli/model.d.ts +11 -0
- package/dist/cli/model.js +19 -0
- package/dist/cli/plugincli.d.ts +2 -0
- package/dist/cli/plugincli.js +176 -0
- package/dist/cli/schedulecli.d.ts +2 -0
- package/dist/cli/schedulecli.js +66 -0
- package/dist/cli/state.d.ts +11 -0
- package/dist/cli/state.js +19 -0
- package/dist/cli/tui/ansi.d.ts +38 -0
- package/dist/cli/tui/ansi.js +142 -0
- package/dist/cli/tui/app.d.ts +328 -0
- package/dist/cli/tui/app.js +1358 -0
- package/dist/cli/tui/blocks.d.ts +151 -0
- package/dist/cli/tui/blocks.js +128 -0
- package/dist/cli/tui/brand.d.ts +9 -0
- package/dist/cli/tui/brand.js +16 -0
- package/dist/cli/tui/canvas.d.ts +92 -0
- package/dist/cli/tui/canvas.js +199 -0
- package/dist/cli/tui/cards.d.ts +44 -0
- package/dist/cli/tui/cards.js +215 -0
- package/dist/cli/tui/clipboard.d.ts +5 -0
- package/dist/cli/tui/clipboard.js +29 -0
- package/dist/cli/tui/commands.d.ts +10 -0
- package/dist/cli/tui/commands.js +649 -0
- package/dist/cli/tui/complete.d.ts +39 -0
- package/dist/cli/tui/complete.js +113 -0
- package/dist/cli/tui/custom.d.ts +9 -0
- package/dist/cli/tui/custom.js +34 -0
- package/dist/cli/tui/diffview.d.ts +25 -0
- package/dist/cli/tui/diffview.js +130 -0
- package/dist/cli/tui/editor.d.ts +60 -0
- package/dist/cli/tui/editor.js +230 -0
- package/dist/cli/tui/full.d.ts +86 -0
- package/dist/cli/tui/full.js +630 -0
- package/dist/cli/tui/keys.d.ts +31 -0
- package/dist/cli/tui/keys.js +134 -0
- package/dist/cli/tui/markdown.d.ts +37 -0
- package/dist/cli/tui/markdown.js +155 -0
- package/dist/cli/tui/mentions.d.ts +15 -0
- package/dist/cli/tui/mentions.js +48 -0
- package/dist/cli/tui/modal.d.ts +26 -0
- package/dist/cli/tui/modal.js +107 -0
- package/dist/cli/tui/overlays.d.ts +98 -0
- package/dist/cli/tui/overlays.js +237 -0
- package/dist/cli/tui/pager.d.ts +15 -0
- package/dist/cli/tui/pager.js +66 -0
- package/dist/cli/tui/pricing.d.ts +9 -0
- package/dist/cli/tui/pricing.js +23 -0
- package/dist/cli/tui/rich.d.ts +16 -0
- package/dist/cli/tui/rich.js +72 -0
- package/dist/cli/tui/screen.d.ts +30 -0
- package/dist/cli/tui/screen.js +62 -0
- package/dist/cli/tui/session.d.ts +77 -0
- package/dist/cli/tui/session.js +103 -0
- package/dist/cli/tui/sidebar.d.ts +84 -0
- package/dist/cli/tui/sidebar.js +114 -0
- package/dist/cli/tui/text.d.ts +15 -0
- package/dist/cli/tui/text.js +94 -0
- package/dist/cli/tui/theme.d.ts +59 -0
- package/dist/cli/tui/theme.js +148 -0
- package/dist/cli/tui/themes.d.ts +56 -0
- package/dist/cli/tui/themes.js +80 -0
- package/dist/cli/tui/tokens.d.ts +39 -0
- package/dist/cli/tui/tokens.js +71 -0
- package/dist/cli/tui/view.d.ts +60 -0
- package/dist/cli/tui/view.js +178 -0
- package/dist/cli/ui.d.ts +34 -0
- package/dist/cli/ui.js +224 -0
- package/dist/src/acp.d.ts +28 -0
- package/dist/src/acp.js +111 -0
- package/dist/src/agents.d.ts +23 -0
- package/dist/src/agents.js +71 -0
- package/dist/src/anthropic.d.ts +30 -0
- package/dist/src/anthropic.js +91 -0
- package/dist/src/approver.d.ts +15 -0
- package/dist/src/approver.js +40 -0
- package/dist/src/bench.d.ts +67 -0
- package/dist/src/bench.js +201 -0
- package/dist/src/bundle.d.ts +36 -0
- package/dist/src/bundle.js +55 -0
- package/dist/src/chaos.d.ts +15 -0
- package/dist/src/chaos.js +26 -0
- package/dist/src/code.d.ts +187 -0
- package/dist/src/code.js +590 -0
- package/dist/src/codeindex.d.ts +65 -0
- package/dist/src/codeindex.js +300 -0
- package/dist/src/deep.d.ts +62 -0
- package/dist/src/deep.js +177 -0
- package/dist/src/diff.d.ts +8 -0
- package/dist/src/diff.js +74 -0
- package/dist/src/dynamic.d.ts +42 -0
- package/dist/src/dynamic.js +133 -0
- package/dist/src/embed.d.ts +8 -0
- package/dist/src/embed.js +25 -0
- package/dist/src/evalcases.d.ts +11 -0
- package/dist/src/evalcases.js +196 -0
- package/dist/src/evals.d.ts +197 -0
- package/dist/src/evals.js +340 -0
- package/dist/src/gitflow.d.ts +27 -0
- package/dist/src/gitflow.js +56 -0
- package/dist/src/grade.d.ts +42 -0
- package/dist/src/grade.js +96 -0
- package/dist/src/guidance.d.ts +15 -0
- package/dist/src/guidance.js +68 -0
- package/dist/src/hardcases.d.ts +2 -0
- package/dist/src/hardcases.js +94 -0
- package/dist/src/harness.d.ts +411 -0
- package/dist/src/harness.js +725 -0
- package/dist/src/hooks.d.ts +44 -0
- package/dist/src/hooks.js +116 -0
- package/dist/src/images.d.ts +13 -0
- package/dist/src/images.js +27 -0
- package/dist/src/index.d.ts +57 -0
- package/dist/src/index.js +57 -0
- package/dist/src/ledger.d.ts +58 -0
- package/dist/src/ledger.js +78 -0
- package/dist/src/live.d.ts +16 -0
- package/dist/src/live.js +80 -0
- package/dist/src/lsp.d.ts +31 -0
- package/dist/src/lsp.js +147 -0
- package/dist/src/memory.d.ts +128 -0
- package/dist/src/memory.js +390 -0
- package/dist/src/metrics.d.ts +3 -0
- package/dist/src/metrics.js +42 -0
- package/dist/src/mining.d.ts +49 -0
- package/dist/src/mining.js +126 -0
- package/dist/src/openai.d.ts +50 -0
- package/dist/src/openai.js +307 -0
- package/dist/src/parallel.d.ts +66 -0
- package/dist/src/parallel.js +135 -0
- package/dist/src/patch.d.ts +45 -0
- package/dist/src/patch.js +219 -0
- package/dist/src/permissions.d.ts +46 -0
- package/dist/src/permissions.js +245 -0
- package/dist/src/plugins.d.ts +148 -0
- package/dist/src/plugins.js +225 -0
- package/dist/src/pluginscan.d.ts +8 -0
- package/dist/src/pluginscan.js +20 -0
- package/dist/src/procs.d.ts +41 -0
- package/dist/src/procs.js +94 -0
- package/dist/src/profiles.d.ts +36 -0
- package/dist/src/profiles.js +61 -0
- package/dist/src/progress.d.ts +29 -0
- package/dist/src/progress.js +75 -0
- package/dist/src/prompts.d.ts +10 -0
- package/dist/src/prompts.js +28 -0
- package/dist/src/ratelimit.d.ts +34 -0
- package/dist/src/ratelimit.js +116 -0
- package/dist/src/replay.d.ts +25 -0
- package/dist/src/replay.js +99 -0
- package/dist/src/review.d.ts +20 -0
- package/dist/src/review.js +49 -0
- package/dist/src/route.d.ts +9 -0
- package/dist/src/route.js +30 -0
- package/dist/src/router.d.ts +61 -0
- package/dist/src/router.js +126 -0
- package/dist/src/sandbox.d.ts +13 -0
- package/dist/src/sandbox.js +68 -0
- package/dist/src/schedule.d.ts +20 -0
- package/dist/src/schedule.js +59 -0
- package/dist/src/schema.d.ts +13 -0
- package/dist/src/schema.js +36 -0
- package/dist/src/secrets.d.ts +10 -0
- package/dist/src/secrets.js +41 -0
- package/dist/src/shell.d.ts +34 -0
- package/dist/src/shell.js +95 -0
- package/dist/src/skills.d.ts +20 -0
- package/dist/src/skills.js +112 -0
- package/dist/src/snapshot.d.ts +20 -0
- package/dist/src/snapshot.js +93 -0
- package/dist/src/stats.d.ts +24 -0
- package/dist/src/stats.js +62 -0
- package/dist/src/strategies.d.ts +16 -0
- package/dist/src/strategies.js +35 -0
- package/dist/src/suites.d.ts +30 -0
- package/dist/src/suites.js +112 -0
- package/dist/src/trace.d.ts +63 -0
- package/dist/src/trace.js +153 -0
- package/dist/src/tune.d.ts +38 -0
- package/dist/src/tune.js +49 -0
- package/dist/src/web.d.ts +19 -0
- package/dist/src/web.js +56 -0
- package/dist/src/worktree.d.ts +24 -0
- package/dist/src/worktree.js +85 -0
- package/docs/agent-loop.md +222 -0
- package/docs/architecture.md +228 -0
- package/docs/bench.md +293 -0
- package/docs/budgets.md +185 -0
- package/docs/build-your-own-harness.md +424 -0
- package/docs/cookbook.md +375 -0
- package/docs/development.md +150 -0
- package/docs/evaluation.md +450 -0
- package/docs/features.md +1320 -0
- package/docs/getting-started.md +196 -0
- package/docs/headless.md +183 -0
- package/docs/images/approval.png +0 -0
- package/docs/images/chat.png +0 -0
- package/docs/images/daylight.png +0 -0
- package/docs/images/loop.png +0 -0
- package/docs/images/palette.png +0 -0
- package/docs/images/running.png +0 -0
- package/docs/images/subagent-done.png +0 -0
- package/docs/images/subagent-running.png +0 -0
- package/docs/images/welcome.png +0 -0
- package/docs/index.md +25 -0
- package/docs/library.md +276 -0
- package/docs/plugins.md +691 -0
- package/docs/providers.md +175 -0
- package/docs/safety.md +237 -0
- package/docs/usage.md +348 -0
- package/docs/why.md +155 -0
- package/docs/writing-guide.md +39 -0
- package/package.json +72 -4
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { mix, parseAnsi } from "./ansi.js";
|
|
2
|
+
import { langOf, renderDiffRows } from "./diffview.js";
|
|
3
|
+
import { highlightWith, renderMarkdown } from "./markdown.js";
|
|
4
|
+
import { BOLD, F, ITAL, chip, fit, split, themeSkin } from "./rich.js";
|
|
5
|
+
import { cellWidth, clipWidth, strip, wrapAnsi } from "./text.js";
|
|
6
|
+
import { toolLabel, argSummary } from "./view.js";
|
|
7
|
+
import { codeBlocks } from "./clipboard.js";
|
|
8
|
+
const SPIN = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
|
|
9
|
+
const MARGIN = 2;
|
|
10
|
+
const fmtMs = (ms) => (ms < 1000 ? `${Math.round(ms)}ms` : ms < 60_000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.floor(ms / 60_000)}m${Math.round((ms % 60_000) / 1000)}s`);
|
|
11
|
+
/** Short, honest one-line summary of a tool result for the card header. */
|
|
12
|
+
export function summarize(name, raw, result) {
|
|
13
|
+
const lines = result.split("\n"), count = (re = /./) => lines.filter((l) => re.test(l)).length;
|
|
14
|
+
switch (name) {
|
|
15
|
+
case "read_file": return `${count()} line${count() === 1 ? "" : "s"}`;
|
|
16
|
+
case "list_files": return `${count()} file${count() === 1 ? "" : "s"}`;
|
|
17
|
+
case "grep": {
|
|
18
|
+
if (/^no matches/.test(result))
|
|
19
|
+
return "no matches";
|
|
20
|
+
const hits = lines.filter(Boolean), files = new Set(hits.map((l) => l.split(":")[0]));
|
|
21
|
+
return `${hits.length} match${hits.length === 1 ? "" : "es"} in ${files.size} file${files.size === 1 ? "" : "s"}`;
|
|
22
|
+
}
|
|
23
|
+
case "sh": return (lines[0] ?? "").replace("exit=", "exit ");
|
|
24
|
+
case "web_search": return `${(result.match(/^\d+\./gm) ?? []).length} results`;
|
|
25
|
+
case "fetch_url": return `${result.length.toLocaleString()} chars`;
|
|
26
|
+
case "task": return "done";
|
|
27
|
+
case "memory_save":
|
|
28
|
+
case "memory_forget": return strip(result).slice(0, 40);
|
|
29
|
+
default: return strip(lines.find(Boolean) ?? "").slice(0, 44);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Tool calls that only look at things. A run of them collapses into one "Explored" row; edits, commands and failures always stand alone. */
|
|
33
|
+
export const isQuiet = (b) => b.kind === "tool" && (!b.agent || b.agent === "lead") && b.status !== "fail" && !b.edit && ["read_file", "list_files", "grep", "web_search", "fetch_url", "memory_search"].includes(b.name);
|
|
34
|
+
/** "3 files read · 2 searches": what a group of quiet tool calls did, in one phrase. */
|
|
35
|
+
export function groupSummary(bs) {
|
|
36
|
+
const n = (names) => bs.filter((b) => names.includes(b.name)).length, parts = [];
|
|
37
|
+
const add = (k, one, many) => { if (k)
|
|
38
|
+
parts.push(`${k} ${k === 1 ? one : many}`); };
|
|
39
|
+
add(n(["read_file"]), "file read", "files read");
|
|
40
|
+
add(n(["grep"]), "search", "searches");
|
|
41
|
+
add(n(["list_files"]), "listing", "listings");
|
|
42
|
+
add(n(["web_search", "fetch_url"]), "web lookup", "web lookups");
|
|
43
|
+
add(n(["memory_search"]), "memory lookup", "memory lookups");
|
|
44
|
+
return parts.join(" · ");
|
|
45
|
+
}
|
|
46
|
+
export function renderGroup(bs, open, c) {
|
|
47
|
+
const t = c.theme, bw = c.width - MARGIN * 2, rows = [], hits = [], bg = t.surface;
|
|
48
|
+
const running = bs.filter((b) => b.status === "running"), cur = running[running.length - 1];
|
|
49
|
+
if (!c.tight)
|
|
50
|
+
rows.push("");
|
|
51
|
+
const ms = bs.reduce((n, b) => n + (b.ms ?? 0), 0);
|
|
52
|
+
const status = cur ? F(t.accent2, SPIN[c.frame % SPIN.length]) + F(t.dim, ` ${clipWidth(`${toolLabel(cur.name)} ${argSummary(cur.name, cur.args)}`, Math.max(10, bw - 40))}`)
|
|
53
|
+
: F(t.ok, "✓ ") + F(t.dim, `${bs.length} steps`) + (ms >= 50 ? F(t.faint, ` · ${fmtMs(ms)}`) : "");
|
|
54
|
+
rows.push(split(` ${F(t.faint, open ? "▾" : "▸")} ${F(t.tool.read, "●")} ${BOLD(F(t.text, cur ? "Exploring" : "Explored"))} ${F(t.dim, groupSummary(bs))}`, status + " ", bw, bg));
|
|
55
|
+
hits.push({ row: rows.length - 1, x0: MARGIN, x1: c.width - MARGIN, kind: "toggle", id: bs[0].id });
|
|
56
|
+
if (open)
|
|
57
|
+
for (const b of bs) {
|
|
58
|
+
const res = b.status === "running" ? F(t.accent2, "…") : F(t.faint, summarize(b.name, b.args, b.result ?? ""));
|
|
59
|
+
rows.push(fit(` ${F(t.faint, "│")} ${F(t.dim, toolLabel(b.name).padEnd(7))} ${F(t.text, clipWidth(argSummary(b.name, b.args), bw - 30))} ${res}`, bw, t.bg));
|
|
60
|
+
}
|
|
61
|
+
const cells = rows.map((r) => padLeft(parseAnsi(" ".repeat(MARGIN) + r), c.width));
|
|
62
|
+
return { rows: cells, hits, text: cells.map((r) => r.map((x) => x.ch).join("").replace(/\s+$/, "")) };
|
|
63
|
+
}
|
|
64
|
+
export function renderBlock(b, c) {
|
|
65
|
+
const t = c.theme, bw = c.width - MARGIN * 2, rows = [], hits = [];
|
|
66
|
+
const blank = () => rows.push("");
|
|
67
|
+
const done = () => {
|
|
68
|
+
const cells = rows.map((r) => padLeft(parseAnsi(" ".repeat(MARGIN) + r), c.width));
|
|
69
|
+
return { rows: cells, hits, text: cells.map((r) => r.map((x) => x.ch).join("").replace(/\s+$/, "")) };
|
|
70
|
+
};
|
|
71
|
+
if (b.kind === "user") {
|
|
72
|
+
blank();
|
|
73
|
+
const inner = bw - 4, bar = F(t.accent, "▎"), lines = b.text.split("\n").flatMap((l) => wrapAnsi(l, inner, 0));
|
|
74
|
+
rows.push(fit(bar, bw, t.surface2));
|
|
75
|
+
lines.forEach((l, i) => rows.push(i === 0 && b.queued ? split(`${bar} ${F(t.text, l)}`, chip("queued", t.onAccent, t.warn), bw, t.surface2) : fit(`${bar} ${F(t.text, l)}`, bw, t.surface2)));
|
|
76
|
+
if (b.note)
|
|
77
|
+
rows.push(fit(`${bar} ${F(t.faint, ITAL(b.note))}`, bw, t.surface2));
|
|
78
|
+
rows.push(fit(bar, bw, t.surface2));
|
|
79
|
+
return done();
|
|
80
|
+
}
|
|
81
|
+
if (b.kind === "assistant") {
|
|
82
|
+
blank();
|
|
83
|
+
const md = renderMarkdown(b.text || " ", bw - 3, themeSkin(t));
|
|
84
|
+
const cursor = b.streaming && c.live && Math.floor(c.frame / 4) % 2 === 0 ? F(t.accent, "▍") : "";
|
|
85
|
+
(md.length ? md : [""]).forEach((l, i) => rows.push((i === 0 ? F(c.brand.color, BOLD(c.brand.icon)) + " " : " ") + l + (i === md.length - 1 || md.length === 0 ? cursor : "")));
|
|
86
|
+
// each code block's "copy" label is a button: find its header rows (in order) and pair them with the fenced blocks of the source
|
|
87
|
+
const codes = codeBlocks(b.text);
|
|
88
|
+
let k = 0;
|
|
89
|
+
md.forEach((l, i) => { if (k < codes.length && /^ ?[\w+#.-]+\s+copy\s*$/.test(strip(l)))
|
|
90
|
+
hits.push({ row: rows.length - md.length + i, x0: MARGIN + 3 + bw - 3 - 6, x1: MARGIN + bw, kind: "copy", id: b.id, text: codes[k++] }); });
|
|
91
|
+
return done();
|
|
92
|
+
}
|
|
93
|
+
if (b.kind === "summary") {
|
|
94
|
+
blank();
|
|
95
|
+
const md = renderMarkdown(b.text, bw - 6, themeSkin(t));
|
|
96
|
+
rows.push(fit(F(t.ok, "▎") + " " + chip("✓ done", t.onAccent, t.ok, true), bw, t.surface));
|
|
97
|
+
md.forEach((l) => rows.push(fit(F(t.ok, "▎") + " " + l, bw, t.surface)));
|
|
98
|
+
rows.push(fit(F(t.ok, "▎"), bw, t.surface));
|
|
99
|
+
return done();
|
|
100
|
+
}
|
|
101
|
+
if (b.kind === "notice") {
|
|
102
|
+
const col = b.level === "error" ? t.err : b.level === "warn" ? t.warn : b.level === "ok" ? t.ok : t.dim, icon = b.level === "error" ? "✗" : b.level === "warn" ? "⚠" : b.level === "ok" ? "✓" : "·";
|
|
103
|
+
if (b.level === "info")
|
|
104
|
+
rows.push("");
|
|
105
|
+
for (const l of wrapAnsi(b.text, bw - 4, 0))
|
|
106
|
+
rows.push(b.level === "error" ? fit(` ${F(col, icon)} ${F(col, l)}`, bw, mix(t.surface, t.err, 0.12)) : ` ${F(col, icon)} ${F(b.level === "info" ? t.dim : t.text, l)}`);
|
|
107
|
+
return done();
|
|
108
|
+
}
|
|
109
|
+
if (b.kind === "raw") {
|
|
110
|
+
for (const l of b.lines)
|
|
111
|
+
rows.push(l);
|
|
112
|
+
return done();
|
|
113
|
+
}
|
|
114
|
+
if (b.kind === "thinking") {
|
|
115
|
+
const open = b.expanded ?? false, label = b.active ? `thinking${".".repeat(1 + (Math.floor(c.frame / 3) % 3))}` : `thought for ${fmtMs(b.ms ?? 0)}`;
|
|
116
|
+
rows.push(`${F(t.faint, open || b.active ? "▾" : "▸")} ${F(t.accent2, "✻")} ${F(t.faint, ITAL(label))}`);
|
|
117
|
+
if (b.active || open)
|
|
118
|
+
for (const l of wrapAnsi(b.text.replace(/\s+/g, " ").trim(), bw - 6, 0).slice(b.active ? -3 : 0))
|
|
119
|
+
rows.push(` ${F(t.faint, ITAL(l))}`);
|
|
120
|
+
hits.push({ row: 0, x0: MARGIN, x1: c.width - MARGIN, kind: "toggle", id: b.id });
|
|
121
|
+
return done();
|
|
122
|
+
}
|
|
123
|
+
// ---------------------------------------------------------------- tool card
|
|
124
|
+
const sub = !!b.agent && b.agent !== "lead", failed = b.status === "fail", edit = b.edit;
|
|
125
|
+
const hue = failed ? t.err : ({ read_file: t.tool.read, list_files: t.tool.read, grep: t.tool.read, write_file: t.tool.edit, edit_file: t.tool.edit, apply_patch: t.tool.edit, sh: t.tool.shell, web_search: t.tool.web, fetch_url: t.tool.web, memory_save: t.tool.memory, memory_forget: t.tool.memory, memory_search: t.tool.read, todo_write: t.tool.plan, exit_plan_mode: t.tool.plan, task: t.tool.explore })[b.name] ?? (b.name.includes("__") ? t.tool.web : t.tool.generic);
|
|
126
|
+
const expanded = c.expandAll ? true : b.expanded ?? (!!edit || failed);
|
|
127
|
+
const bg = failed ? mix(t.surface, t.err, 0.14) : t.surface, spinner = SPIN[c.frame % SPIN.length];
|
|
128
|
+
const label = BOLD(F(failed ? t.err : t.text, toolLabel(b.name))), args = F(t.dim, argSummary(b.name, b.args));
|
|
129
|
+
const status = b.status === "running"
|
|
130
|
+
? F(t.accent2, spinner) + F(t.dim, ` ${fmtMs(c.now - b.t0)}`)
|
|
131
|
+
: edit ? (edit.created ? chip("new", t.onAccent, t.ok) + " " : "") + F(t.addFg, `+${edit.added}`) + " " + F(t.delFg, `−${edit.removed}`) + (b.ms !== undefined && b.ms >= 50 ? F(t.faint, ` · ${fmtMs(b.ms)}`) : "")
|
|
132
|
+
: F(failed ? t.err : t.ok, failed ? "✗ " : "✓ ") + F(failed ? t.err : t.dim, summarize(b.name, b.args, b.result ?? "")) + (b.ms !== undefined && b.ms >= 50 ? F(t.faint, ` · ${fmtMs(b.ms)}`) : "");
|
|
133
|
+
const kids = !sub && b.name === "task" ? c.kids?.(b.callId) ?? [] : [];
|
|
134
|
+
const hasBody = (b.status !== "running" || kids.length > 0) && !!(edit || kids.length || (b.result && b.result.trim()));
|
|
135
|
+
const caret = F(t.faint, hasBody ? (expanded ? "▾" : "▸") : " ");
|
|
136
|
+
if (!sub && (!c.tight || (hasBody && expanded)))
|
|
137
|
+
blank(); // collapsed one-liners stack tightly; a card with a body gets air above it
|
|
138
|
+
const head = `${caret} ${F(hue, "●")} ${label} ${args}`;
|
|
139
|
+
rows.push(sub ? ` ${F(t.faint, "│")} ${F(hue, "●")} ${F(t.dim, toolLabel(b.name))} ${F(t.faint, argSummary(b.name, b.args))}` : split(" " + head, status + " ", bw, bg));
|
|
140
|
+
if (!sub && hasBody)
|
|
141
|
+
hits.push({ row: rows.length - 1, x0: MARGIN, x1: c.width - MARGIN, kind: "toggle", id: b.id });
|
|
142
|
+
if (kids.length) { // a subagent's steps, inside its own card: the newest few while it runs, a one-line summary when done, all of them when opened
|
|
143
|
+
const line = (k) => fit(` ${F(t.faint, "│")} ${k.status === "running" ? F(t.accent2, spinner) : k.status === "fail" ? F(t.err, "✗") : F(t.ok, "✓")} ${F(t.dim, toolLabel(k.name).padEnd(7))} ${F(t.text, clipWidth(argSummary(k.name, k.args), bw - 24))}`, bw, t.bg);
|
|
144
|
+
const running = b.status === "running", shown = expanded ? kids : running ? kids.slice(-3) : [];
|
|
145
|
+
if (!expanded && running && kids.length > 3)
|
|
146
|
+
rows.push(fit(` ${F(t.faint, "│ … " + (kids.length - 3) + " earlier step" + (kids.length - 3 === 1 ? "" : "s"))}`, bw, t.bg));
|
|
147
|
+
for (const k of shown)
|
|
148
|
+
rows.push(line(k));
|
|
149
|
+
if (!running && !expanded)
|
|
150
|
+
rows.push(fit(` ${F(t.faint, "│")} ${F(t.dim, `${kids.length} step${kids.length === 1 ? "" : "s"} · ${groupSummary(kids) || "no lookups"}`)} ${F(t.faint, "(click to see them)")}`, bw, t.bg));
|
|
151
|
+
}
|
|
152
|
+
if (!sub && hasBody && expanded && (edit || (b.result && b.result.trim()))) {
|
|
153
|
+
const bar = F(hue, "▏"), body = (s) => rows.push(fit(bar + " " + s, bw, bg));
|
|
154
|
+
if (edit) {
|
|
155
|
+
const mode = c.diffMode === "auto" ? (bw >= 120 ? "split" : "stacked") : c.diffMode, max = b.more ? Infinity : 16;
|
|
156
|
+
const d = renderDiffRows(edit.diff, { width: bw - 2, theme: t, lang: langOf(edit.path), mode, maxRows: max });
|
|
157
|
+
for (const r of d.rows)
|
|
158
|
+
rows.push(bar + " " + r);
|
|
159
|
+
if (d.hidden > 0) {
|
|
160
|
+
rows.push(fit(`${bar} ${F(t.accent2, `▾ show ${d.hidden} more line${d.hidden === 1 ? "" : "s"}`)}`, bw, t.surface2));
|
|
161
|
+
hits.push({ row: rows.length - 1, x0: MARGIN, x1: c.width - MARGIN, kind: "more", id: b.id });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const res = b.result ?? "", hl = (k, s) => F(k === "plain" ? t.syn.plain : t.syn[k], s);
|
|
166
|
+
let lines = res.split("\n"), cap = c.expandAll ? 200 : 60;
|
|
167
|
+
if (b.name === "sh") {
|
|
168
|
+
let cmd = "";
|
|
169
|
+
try {
|
|
170
|
+
cmd = JSON.parse(b.args).cmd;
|
|
171
|
+
}
|
|
172
|
+
catch { /* leave empty */ }
|
|
173
|
+
body(F(t.accent, "$ ") + F(t.text, clipWidth(cmd, bw - 8)));
|
|
174
|
+
lines = lines.slice(1);
|
|
175
|
+
if (!lines.some((l) => l.trim()))
|
|
176
|
+
lines = [F(t.faint, "(no output)")];
|
|
177
|
+
}
|
|
178
|
+
const lang = b.name === "read_file" ? (() => { try {
|
|
179
|
+
return langOf(JSON.parse(b.args).path);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return "";
|
|
183
|
+
} })() : "";
|
|
184
|
+
for (const l of lines.slice(0, cap)) {
|
|
185
|
+
if (b.name === "read_file") {
|
|
186
|
+
const m = l.match(/^(\d+)\t(.*)$/);
|
|
187
|
+
body(m ? F(t.faint, m[1].padStart(4) + " ") + highlightWith(clipWidth(m[2], bw - 10), lang, hl) : F(t.dim, l));
|
|
188
|
+
}
|
|
189
|
+
else
|
|
190
|
+
for (const w of wrapAnsi(l.includes("\x1b") ? l : F(failed && /error|✖|fail|exception|assert|panic|traceback|denied/i.test(l) ? t.err : t.dim, l), bw - 4, 0))
|
|
191
|
+
body(w); // only the lines that look like errors are red
|
|
192
|
+
}
|
|
193
|
+
if (lines.length > cap)
|
|
194
|
+
body(F(t.faint, `… ${lines.length - cap} more lines (ctrl+o expands everything)`));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return done();
|
|
198
|
+
}
|
|
199
|
+
/** Pad or clip a cell row to exactly `width` cells (default-background padding, so the canvas background shows through). */
|
|
200
|
+
function padLeft(cells, width) {
|
|
201
|
+
const out = [];
|
|
202
|
+
let w = 0;
|
|
203
|
+
for (const c of cells) {
|
|
204
|
+
if (w + c.w > width)
|
|
205
|
+
break;
|
|
206
|
+
out.push(c);
|
|
207
|
+
w += c.w;
|
|
208
|
+
}
|
|
209
|
+
while (w < width) {
|
|
210
|
+
out.push({ ch: " ", w: 1, fg: -1, bg: -1, attr: 0 });
|
|
211
|
+
w++;
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
void cellWidth;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copy text to the user's clipboard from a terminal app: OSC 52 (works over SSH in most modern terminals) plus the platform tool when local.
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
export function copyToClipboard(out, text, local) {
|
|
4
|
+
out.write(`\x1b]52;c;${Buffer.from(text).toString("base64")}\x07`);
|
|
5
|
+
if (!local)
|
|
6
|
+
return;
|
|
7
|
+
const cmd = process.platform === "darwin" ? ["pbcopy"] : process.platform === "win32" ? ["clip"] : process.env.WAYLAND_DISPLAY ? ["wl-copy"] : ["xclip", "-selection", "clipboard"];
|
|
8
|
+
try {
|
|
9
|
+
const p = spawn(cmd[0], cmd.slice(1), { stdio: ["pipe", "ignore", "ignore"] });
|
|
10
|
+
p.on("error", () => { });
|
|
11
|
+
p.stdin.on("error", () => { });
|
|
12
|
+
p.stdin.end(text);
|
|
13
|
+
}
|
|
14
|
+
catch { /* no clipboard tool: OSC 52 only */ }
|
|
15
|
+
}
|
|
16
|
+
/** The bodies of the ``` fenced code blocks in a markdown string, in order. */
|
|
17
|
+
export function codeBlocks(md) {
|
|
18
|
+
const L = md.split("\n"), out = [];
|
|
19
|
+
for (let i = 0; i < L.length; i++) {
|
|
20
|
+
const f = L[i].match(/^(\s*)(`{3,}|~{3,})/);
|
|
21
|
+
if (!f)
|
|
22
|
+
continue;
|
|
23
|
+
const body = [];
|
|
24
|
+
for (i++; i < L.length && !/^\s*(`{3,}|~{3,})\s*$/.test(L[i]); i++)
|
|
25
|
+
body.push(L[i].slice(Math.min(f[1].length, L[i].length - L[i].trimStart().length)));
|
|
26
|
+
out.push(body.join("\n"));
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { App } from "./app.ts";
|
|
2
|
+
export type Cmd = {
|
|
3
|
+
name: string;
|
|
4
|
+
help: string;
|
|
5
|
+
alias?: string;
|
|
6
|
+
args?: string; /** safe to run while the agent is working */
|
|
7
|
+
live?: boolean;
|
|
8
|
+
run(app: App, args: string): Promise<void> | void;
|
|
9
|
+
};
|
|
10
|
+
export declare function buildCommands(): Cmd[];
|