@0perator/operator 0.1.352 → 0.1.354
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/dist/acp/agent.js +4 -2
- package/dist/acp/tool-map.js +5 -4
- package/dist/autonomy/delegate.js +55 -2
- package/dist/autonomy/headless.js +4 -1
- package/dist/autonomy/session-factory.js +1 -0
- package/dist/background/index.js +86 -10
- package/dist/background/notices.js +16 -4
- package/dist/cli.js +1072 -178
- package/dist/config/home.js +6 -0
- package/dist/config/memory-sections.js +92 -0
- package/dist/config/persona.js +144 -26
- package/dist/config/settings.js +15 -4
- package/dist/consolidation/scheduler.js +9 -2
- package/dist/consolidation/sleep.js +39 -278
- package/dist/engine/agent.js +547 -92
- package/dist/engine/anthropic-chat.js +13 -2
- package/dist/engine/aurora.js +135 -30
- package/dist/engine/batch-scheduler.js +27 -3
- package/dist/engine/compaction.js +12 -5
- package/dist/engine/continuation.js +51 -22
- package/dist/engine/contract.js +1 -1
- package/dist/engine/decision-points.js +7 -1
- package/dist/engine/front-door.js +59 -0
- package/dist/engine/grandmaster.js +13 -1
- package/dist/engine/loop-guard.js +694 -0
- package/dist/engine/net-error.js +2 -1
- package/dist/engine/owner-act.js +52 -0
- package/dist/engine/selfheal.js +48 -0
- package/dist/engine/verify-gate.js +52 -0
- package/dist/flywheel/processor.js +3 -1
- package/dist/flywheel/srft.js +8 -4
- package/dist/hooks/index.js +12 -8
- package/dist/mcp/index.js +9 -4
- package/dist/permissions/index.js +32 -11
- package/dist/permissions/modes.js +42 -0
- package/dist/permissions/plan-review.js +100 -0
- package/dist/permissions/policy.js +16 -5
- package/dist/permissions/signature.js +8 -3
- package/dist/remote/safe-commands.js +1 -1
- package/dist/router/read-rates.js +152 -0
- package/dist/selfimprove/backfill.js +174 -0
- package/dist/selfimprove/index.js +146 -57
- package/dist/selfimprove/lessons.js +429 -0
- package/dist/selfimprove/sync.js +58 -0
- package/dist/session.js +375 -31
- package/dist/skills/finder.js +219 -0
- package/dist/tools/deferred.js +28 -18
- package/dist/tools/executor.js +7 -3
- package/dist/tools/registry.js +34 -4
- package/dist/ui/ActivitySpinner.js +21 -12
- package/dist/ui/App.js +107 -30
- package/dist/ui/ApprovalPrompt.js +5 -3
- package/dist/ui/ArtifactPicker.js +3 -3
- package/dist/ui/BgPanel.js +105 -5
- package/dist/ui/Composer.js +85 -9
- package/dist/ui/PlanPane.js +72 -8
- package/dist/ui/QuestionPrompt.js +6 -4
- package/dist/ui/SecretPrompt.js +8 -3
- package/dist/ui/SessionPicker.js +2 -2
- package/dist/ui/SkillFinder.js +153 -0
- package/dist/ui/StatusRule.js +5 -2
- package/dist/ui/SummaryCard.js +3 -1
- package/dist/ui/ThinkingSpinner.js +11 -2
- package/dist/ui/ToolBatch.js +11 -2
- package/dist/ui/ToolStep.js +36 -13
- package/dist/ui/Transcript.js +13 -2
- package/dist/ui/actNow.js +61 -0
- package/dist/ui/batchLine.js +165 -0
- package/dist/ui/conversations.js +154 -0
- package/dist/ui/decodeHealth.js +77 -0
- package/dist/ui/expand.js +17 -0
- package/dist/ui/fit.js +40 -0
- package/dist/ui/fitTail.js +14 -0
- package/dist/ui/fold.js +149 -0
- package/dist/ui/format.js +46 -2
- package/dist/ui/liveTools.js +163 -13
- package/dist/ui/modelPicker.js +78 -6
- package/dist/ui/nextStep.js +103 -0
- package/dist/ui/pending.js +57 -0
- package/dist/ui/phase.js +105 -0
- package/dist/ui/planExit.js +0 -5
- package/dist/ui/progressbar.js +4 -26
- package/dist/ui/readForecast.js +44 -0
- package/dist/ui/readProgress.js +119 -0
- package/dist/ui/reportLine.js +62 -0
- package/dist/ui/slashCommands.js +1 -1
- package/dist/ui/theme.js +1 -0
- package/dist/ui/turnFlow.js +72 -0
- package/dist/ui/turnLedger.js +121 -0
- package/dist/ui/turnScope.js +11 -0
- package/dist/util/slash.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// When the phase line offers ctrl+y — "use what you have" (TUI A3.3) — and what it says. Three measured triggers: one
|
|
2
|
+
// reasoning stream running 30 s or more with no answer text and no tool call; a prompt read of 30 s or more (it arms,
|
|
3
|
+
// and answers think-off the moment the read ends); the loop guard refusing a repeated call. Pure, so each trigger and
|
|
4
|
+
// every width is unit-tested; the shell feeds it from its turn handlers and the existing 500 ms clock (no new timer).
|
|
5
|
+
import { seg } from "./fit.js";
|
|
6
|
+
export const ACT_NOW_HINT_MS = 30_000;
|
|
7
|
+
export const ACT_NOW_KEY = "ctrl+y";
|
|
8
|
+
export function actNowOffer(st, now, o = { thinking: true }) {
|
|
9
|
+
const hint = o.hintMs ?? ACT_NOW_HINT_MS;
|
|
10
|
+
if (st.armedTools)
|
|
11
|
+
return { kind: "tools" };
|
|
12
|
+
if (st.armed)
|
|
13
|
+
return { kind: "read", armed: true }; // pressed before the first token — queued or still reading
|
|
14
|
+
if (st.guard)
|
|
15
|
+
return { kind: "loop", detail: st.guard };
|
|
16
|
+
if (st.reasoningSince !== undefined && now - st.reasoningSince >= hint)
|
|
17
|
+
return { kind: "reasoning", ms: now - st.reasoningSince };
|
|
18
|
+
// A read only has reasoning to skip when thinking is on; with it off the answer already starts the moment the read ends.
|
|
19
|
+
if (o.thinking && st.readingSince !== undefined && now - st.readingSince >= hint)
|
|
20
|
+
return { kind: "read", armed: false };
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/** The loop guard's own words in a batch's results, said short: "bash ×8 with identical args, refused". */
|
|
24
|
+
export function guardDetail(results) {
|
|
25
|
+
for (const r of results) {
|
|
26
|
+
const text = String(r.result ?? "");
|
|
27
|
+
const loop = /^Loop guard: "([\w:.-]+)" has been called (\d+) times/.exec(text);
|
|
28
|
+
if (loop)
|
|
29
|
+
return `${loop[1]} ×${loop[2]} with identical args, refused`;
|
|
30
|
+
const status = /^Loop guard: "([\w:.-]+)" already returned your status/.exec(text);
|
|
31
|
+
if (status)
|
|
32
|
+
return `${status[1]} polled with no change, refused`;
|
|
33
|
+
const repeat = /^Repeated action: "([\w:.-]+)"/.exec(text);
|
|
34
|
+
if (repeat)
|
|
35
|
+
return `${repeat[1]} repeats a finished call, refused`;
|
|
36
|
+
const capped = /^Blocked ([\w:.-]+): /.exec(text);
|
|
37
|
+
if (capped)
|
|
38
|
+
return `${capped[1]} over its per-turn cap, refused`;
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const fmt = (ms) => { const s = Math.round(ms / 1000); return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m ${s % 60}s`; };
|
|
43
|
+
/** The phase line with the offer, as fit segments (sep ""): the detail gives way first, then "⏎ steer"; "ctrl+y use what
|
|
44
|
+
* you have" and "esc stop" always stay. `phase` is the line's own phase text. Null offer → null (the plain line). */
|
|
45
|
+
export function actNowLine(phase, offer) {
|
|
46
|
+
if (!offer)
|
|
47
|
+
return null;
|
|
48
|
+
if (offer.kind === "tools")
|
|
49
|
+
return [seg(` ${phase}`), seg([" · ▸ armed: answers once these tools finish", " · ▸ armed"], 7, true), seg(" · esc stop")];
|
|
50
|
+
if (offer.kind === "read") {
|
|
51
|
+
return offer.armed
|
|
52
|
+
? [seg(` ${phase}`), seg([" · ▸ armed: answers think-off the moment the read ends", " · ▸ armed"], 7, true), seg(" · esc stop")]
|
|
53
|
+
: [seg(` ${phase}`), seg([` · ${ACT_NOW_KEY} skip the reasoning once the read ends`, ` · ${ACT_NOW_KEY} skip reasoning`], 7, true), seg(" · esc stop")];
|
|
54
|
+
}
|
|
55
|
+
const head = offer.kind === "loop"
|
|
56
|
+
? [seg(" loop"), seg(` · ${offer.detail}`, 7)]
|
|
57
|
+
: [seg(` ${phase} ${fmt(offer.ms)}`), seg(" · no answer or tool call yet", 7)];
|
|
58
|
+
return [...head, seg(` · ${ACT_NOW_KEY} use what you have`), seg(" · ⏎ steer", 5), seg(" · esc stop")];
|
|
59
|
+
}
|
|
60
|
+
/** Under 45 columns the line is just the keys. */
|
|
61
|
+
export const ACT_NOW_NARROW = ` ${ACT_NOW_KEY} · esc`;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Live tool rows (TUI plan #8): one fixed row per call from its first draft until the batch settles — the result rides
|
|
2
|
+
// on the row, never under it, so the block stays 1 + min(N, MAX) rows for its whole life. Every row is fitted to
|
|
3
|
+
// cols−1 on PLAIN text (no OSC-8 path links: clipping an escaped string cuts the escape). Narrowing gives up, in order:
|
|
4
|
+
// a draft's bulk sizes, the elapsed time, then the path's directories (the basename stays).
|
|
5
|
+
import { cellWidth, truncateToWidth } from "./StatusRule.js";
|
|
6
|
+
import { fmtElapsed, formatDuration } from "./format.js";
|
|
7
|
+
import { argsPreview } from "./ToolStep.js";
|
|
8
|
+
import { computeEditDiff } from "./editdiff.js";
|
|
9
|
+
import { fitSegments, seg } from "./fit.js";
|
|
10
|
+
import { fmtTok } from "./format.js";
|
|
11
|
+
import { humanStep } from "./BgPanel.js";
|
|
12
|
+
const SHELL_TOOLS = new Set(["bash", "shell_exec", "shell_background"]);
|
|
13
|
+
const PATH_KEYS = ["path", "file", "filename"];
|
|
14
|
+
/** A row's time: sub-second precision while short ("80ms", "1.1s"), minutes past one ("2m 13s"). */
|
|
15
|
+
const rowTime = (ms) => (ms < 60_000 ? formatDuration(ms) : fmtElapsed(ms));
|
|
16
|
+
/** "src/ui/StatusRule.tsx" → "…/StatusRule.tsx": the basename is what identifies the file at a glance. */
|
|
17
|
+
export function shortPath(p) {
|
|
18
|
+
const i = p.lastIndexOf("/");
|
|
19
|
+
return i > 0 ? `…/${p.slice(i + 1)}` : p;
|
|
20
|
+
}
|
|
21
|
+
function tail(step, now) {
|
|
22
|
+
if (step.status === "selected") {
|
|
23
|
+
if (step.drafting) {
|
|
24
|
+
const t = `drafting ${fmtElapsed(now - (step.startedAt ?? now))}`;
|
|
25
|
+
return { full: t, short: "drafting" };
|
|
26
|
+
}
|
|
27
|
+
return { full: "waiting its turn", short: "waiting" };
|
|
28
|
+
}
|
|
29
|
+
if (step.status === "running")
|
|
30
|
+
return { full: rowTime(now - (step.startedAt ?? now)), short: "" };
|
|
31
|
+
const parts = [];
|
|
32
|
+
if (step.outcome === "blocked")
|
|
33
|
+
parts.push(`blocked${step.summary ? `: ${step.summary}` : ""}`);
|
|
34
|
+
else if (step.outcome === "cancelled")
|
|
35
|
+
parts.push("cancelled");
|
|
36
|
+
else if (step.exitCode !== undefined)
|
|
37
|
+
parts.push(`exit ${step.exitCode}`);
|
|
38
|
+
else if (step.status === "done") {
|
|
39
|
+
const diff = computeEditDiff(step.name, step.args);
|
|
40
|
+
if (diff)
|
|
41
|
+
parts.push(`+${diff.added} -${diff.removed}`);
|
|
42
|
+
else if (step.lines)
|
|
43
|
+
parts.push(`${step.lines} line${step.lines === 1 ? "" : "s"}`);
|
|
44
|
+
}
|
|
45
|
+
const ms = step.durationMs ?? (step.endedAt !== undefined && step.startedAt !== undefined ? step.endedAt - step.startedAt : undefined);
|
|
46
|
+
const short = parts.join(" · ");
|
|
47
|
+
return { full: [...parts, ...(ms !== undefined ? [rowTime(ms)] : [])].join(" · "), short };
|
|
48
|
+
}
|
|
49
|
+
/** One live row: `head` (the tool name, or "$" for a shell call — colored by its kind) and `rest`, fitted so the whole
|
|
50
|
+
* row (padding + status glyph + space + head + rest) stays within cols−1. A name wider than 60% of the row clips first
|
|
51
|
+
* (an MCP name runs to 50-odd cells), so the call's outcome still shows. The first candidate that fits wins: the full
|
|
52
|
+
* row, then without a draft's sizes, then the short tail (no elapsed), then the path's basename only, then no tail. */
|
|
53
|
+
export function liveRow(step, cols, now = Date.now()) {
|
|
54
|
+
const t = tail(step, now);
|
|
55
|
+
const max = cols - 1 - 4; // paddingLeft + the status glyph (counted wide, as cellWidth does) + space
|
|
56
|
+
const shell = SHELL_TOOLS.has(step.name) && typeof step.args?.command === "string";
|
|
57
|
+
const head = shell ? "$" : truncateToWidth(step.name, Math.max(1, Math.min(max - 2, Math.max(12, Math.floor(max * 0.6)))));
|
|
58
|
+
const args = step.args ?? {};
|
|
59
|
+
if (step.name === "delegate_task" && typeof args.task === "string") { // its title is the task the specialist works on
|
|
60
|
+
const task = ` · ${args.task.replace(/\s+/g, " ").trim()}`;
|
|
61
|
+
const roomD = Math.max(1, max - cellWidth(head));
|
|
62
|
+
const withT = t.full ? `${task} · ${t.full}` : task;
|
|
63
|
+
return { head, rest: cellWidth(withT) <= roomD ? withT : t.full ? `${truncateToWidth(task, Math.max(1, roomD - cellWidth(t.full) - 3))} · ${t.full}` : truncateToWidth(task, roomD) };
|
|
64
|
+
}
|
|
65
|
+
const pathKey = PATH_KEYS.find((k) => typeof args[k] === "string");
|
|
66
|
+
const [sized, plain, short] = shell
|
|
67
|
+
? Array(3).fill(` ${String(args.command).replace(/\s+/g, " ").trim()}`)
|
|
68
|
+
: [
|
|
69
|
+
`(${argsPreview(args, { link: false, sizes: step.sizes })})`,
|
|
70
|
+
`(${argsPreview(args, { link: false })})`,
|
|
71
|
+
`(${argsPreview(pathKey ? { ...args, [pathKey]: shortPath(args[pathKey]) } : args, { link: false })})`,
|
|
72
|
+
];
|
|
73
|
+
const withTail = (body, tl) => (tl ? `${body} · ${tl}` : body);
|
|
74
|
+
const candidates = [withTail(sized, t.full), withTail(plain, t.full), withTail(plain, t.short), withTail(short, t.short), short];
|
|
75
|
+
const room = Math.max(1, max - cellWidth(head));
|
|
76
|
+
return { head, rest: candidates.find((c) => cellWidth(c) <= room) ?? truncateToWidth(short, room) };
|
|
77
|
+
}
|
|
78
|
+
/** The block's one header line, changing only as calls change state, fitted to the block's width (`cols` less its
|
|
79
|
+
* 1-cell padding) so it never wraps mid-batch: "waiting its turn" shortens, then the counts leave — waiting, drafting,
|
|
80
|
+
* done, running — and a failure goes last; "⇉ N calls" stays. */
|
|
81
|
+
export function batchHeader(rows, cols = 1000) {
|
|
82
|
+
const n = rows.length;
|
|
83
|
+
if (n && rows.every((r) => r.status === "selected" && r.drafting))
|
|
84
|
+
return fitSegments([seg([`drafting ${n} tool call${n === 1 ? "" : "s"}`, `drafting ${n}`], 1, true)], cols - 1);
|
|
85
|
+
const count = (f) => rows.filter(f).length;
|
|
86
|
+
const running = count((r) => r.status === "running");
|
|
87
|
+
const drafting = count((r) => r.status === "selected" && !!r.drafting);
|
|
88
|
+
const waiting = count((r) => r.status === "selected" && !r.drafting);
|
|
89
|
+
const failed = count((r) => r.status === "error");
|
|
90
|
+
const done = count((r) => r.status === "done");
|
|
91
|
+
return fitSegments([
|
|
92
|
+
seg(`⇉ ${n} call${n === 1 ? "" : "s"}`),
|
|
93
|
+
...(running ? [seg(`${running} running`, 3)] : []),
|
|
94
|
+
...(done ? [seg(`${done} done`, 4)] : []),
|
|
95
|
+
...(failed ? [seg(`${failed} failed`, 2)] : []),
|
|
96
|
+
...(drafting ? [seg(`${drafting} drafting`, 5)] : []),
|
|
97
|
+
...(waiting ? [seg([`${waiting} waiting its turn`, `${waiting} waiting`], 6)] : []),
|
|
98
|
+
], cols - 1);
|
|
99
|
+
}
|
|
100
|
+
/** The delegation's own motion (James, 11/04: "a new tui animation for delegation … make it unique"): a mark relayed
|
|
101
|
+
* along a three-cell track, planner → specialist, then a beat of rest — nothing else in the TUI moves this way. */
|
|
102
|
+
const RELAY = ["▸▹▹", "▹▸▹", "▹▹▸", "▹▹▹"];
|
|
103
|
+
const RELAY_TICKS = 2; // shared-clock ticks per step (~240 ms)
|
|
104
|
+
export function relayFrame(frame) {
|
|
105
|
+
return RELAY[Math.floor(frame / RELAY_TICKS) % RELAY.length];
|
|
106
|
+
}
|
|
107
|
+
/** The child line under a running delegate_task (TUI plan #9): the specialist, its round, what it is doing, its ledger
|
|
108
|
+
* and tokens. Narrowing drops the tokens, then the ledger, then the model — "r4 · reading discovery.ts" stays. */
|
|
109
|
+
export function delegateLine(p, cols) {
|
|
110
|
+
const doing = p.tool ? `${humanStep(p.tool)}${p.arg ? ` ${p.arg}` : ""}` : p.thinking ? "thinking" : p.round ? "between rounds" : "starting";
|
|
111
|
+
const shortDoing = p.tool && p.arg ? `${humanStep(p.tool)} ${p.arg.split("/").pop()}` : doing;
|
|
112
|
+
const ledger = [p.writes ? `wrote ${p.writes}` : "", p.reads ? `read ${p.reads}` : "", p.commands ? `ran ${p.commands}` : ""].filter(Boolean).join(" · ");
|
|
113
|
+
return fitSegments([
|
|
114
|
+
seg(p.model, 3),
|
|
115
|
+
seg([`round ${p.round + 1}`, `r${p.round + 1}`], 2, true),
|
|
116
|
+
seg([doing, shortDoing], 1, true),
|
|
117
|
+
...(ledger ? [seg(ledger, 4)] : []),
|
|
118
|
+
...(p.tokens ? [seg(`${fmtTok(p.tokens)} tok`, 5)] : []),
|
|
119
|
+
], cols, { lead: " ▸▹▹ " }).slice(" ▸▹▹ ".length);
|
|
120
|
+
}
|
|
121
|
+
const base = (p) => p.split("/").pop() || p;
|
|
122
|
+
const words = (cmd, n) => cmd.replace(/\s+/g, " ").trim().split(" ").slice(0, n).join(" ");
|
|
123
|
+
/** One call as a chip: its outcome glyph and a few words that identify it ("BgPanel.tsx 195", "npm test exit 1"). */
|
|
124
|
+
export function chipOf(step) {
|
|
125
|
+
const a = step.args ?? {};
|
|
126
|
+
const tone = step.outcome ?? (step.status === "error" ? "error" : "done");
|
|
127
|
+
const glyph = tone === "done" ? "✓" : tone === "error" ? "✗" : "⊘";
|
|
128
|
+
const path = PATH_KEYS.map((k) => a[k]).find((v) => typeof v === "string");
|
|
129
|
+
let label;
|
|
130
|
+
if (SHELL_TOOLS.has(step.name) && typeof a.command === "string")
|
|
131
|
+
label = words(a.command, 2);
|
|
132
|
+
else if (/grep|search|find|glob/.test(step.name) && typeof (a.pattern ?? a.query) === "string")
|
|
133
|
+
label = `${/find|glob/.test(step.name) ? "find" : "grep"} "${String(a.pattern ?? a.query).slice(0, 24)}"`;
|
|
134
|
+
else if (step.name === "web_fetch" && typeof a.url === "string")
|
|
135
|
+
label = a.url.replace(/^https?:\/\//, "").split("/")[0];
|
|
136
|
+
else if (step.name === "delegate_task")
|
|
137
|
+
label = "delegate";
|
|
138
|
+
else if (path)
|
|
139
|
+
label = base(path);
|
|
140
|
+
else
|
|
141
|
+
label = step.name;
|
|
142
|
+
const tail = step.outcome === "blocked" ? "blocked" : step.outcome === "cancelled" ? "cancelled"
|
|
143
|
+
: step.exitCode !== undefined ? `exit ${step.exitCode}`
|
|
144
|
+
: (() => { const d = step.status === "done" ? computeEditDiff(step.name, step.args) : undefined; return d ? `+${d.added} -${d.removed}` : step.lines && !SHELL_TOOLS.has(step.name) ? String(step.lines) : ""; })();
|
|
145
|
+
return { tone, glyph, label: tail ? `${label} ${tail}` : label, name: step.name };
|
|
146
|
+
}
|
|
147
|
+
/** The chip line: "⇉ 4 calls · 3.4s", then chips while they fit in cols−1, the rest folded into "+3 ✓ +1 ✗", then the
|
|
148
|
+
* ctrl+o hint. Failures are never lost to the fold — the caller breaks every failed or refused call out underneath. */
|
|
149
|
+
export function batchChips(steps, durationMs, cols) {
|
|
150
|
+
const head = `⇉ ${steps.length} calls · ${rowTime(durationMs)}`;
|
|
151
|
+
const all = steps.map(chipOf);
|
|
152
|
+
const hint = "ctrl+o";
|
|
153
|
+
const max = cols - 1;
|
|
154
|
+
const width = (chips, folded, h) => cellWidth(head) + chips.reduce((n, c) => n + 2 + cellWidth(`${c.glyph} ${c.label}`), 0) + (folded ? 2 + cellWidth(folded) : 0) + (h ? 3 + cellWidth(h) : 0);
|
|
155
|
+
const foldOf = (rest) => {
|
|
156
|
+
const ok = rest.filter((c) => c.tone === "done").length, bad = rest.length - ok;
|
|
157
|
+
return [ok ? `+${ok} ✓` : "", bad ? `+${bad} ✗` : ""].filter(Boolean).join(" ");
|
|
158
|
+
};
|
|
159
|
+
for (let n = all.length; n >= 0; n--) {
|
|
160
|
+
const shown = all.slice(0, n), folded = foldOf(all.slice(n));
|
|
161
|
+
if (width(shown, folded, hint) <= max)
|
|
162
|
+
return { head, chips: shown, folded, hint };
|
|
163
|
+
}
|
|
164
|
+
return { head: truncateToWidth(head, max), chips: [], folded: cellWidth(head) + 2 + cellWidth(foldOf(all)) <= max ? foldOf(all) : "", hint: "" };
|
|
165
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { fitSegments, seg } from "./fit.js";
|
|
2
|
+
import { cellWidth } from "./StatusRule.js";
|
|
3
|
+
import { ENGINE_NOTE_PREFIX } from "../engine/continuation.js";
|
|
4
|
+
const live = (a) => a.status === "working" || a.status === "queued";
|
|
5
|
+
const nameOf = (a) => a.name ?? a.id;
|
|
6
|
+
/** "@Nova <text>" → the sub-agent it names and the message, as typed; "@all stop" → every one. Names match whole
|
|
7
|
+
* (multiword ones too, longest first — parseAgentCommand's rule). An agent that already finished still matches, so the
|
|
8
|
+
* shell answers "Vega already finished" instead of handing "@Vega …" to the main model (review F5); a live agent wins a
|
|
9
|
+
* name a finished one had. Null when the @token names no agent at all, so "@src/x.ts" stays a file mention. */
|
|
10
|
+
export function agentMention(text, agents) {
|
|
11
|
+
const t = text.trim();
|
|
12
|
+
if (!t.startsWith("@") || t.includes("\n"))
|
|
13
|
+
return null;
|
|
14
|
+
const body = t.slice(1);
|
|
15
|
+
if (/^all\s+stop$/i.test(body))
|
|
16
|
+
return { target: "all", message: "stop" };
|
|
17
|
+
const lower = body.toLowerCase();
|
|
18
|
+
const names = [...agents.filter(live), ...agents.filter((a) => !live(a))]
|
|
19
|
+
.flatMap((a) => [a.id, a.name].filter((n) => !!n).map((n) => ({ a, n })))
|
|
20
|
+
.sort((x, y) => y.n.length - x.n.length); // stable: same length keeps the live agent first
|
|
21
|
+
const hit = names.find(({ n }) => lower === n.toLowerCase() || lower.startsWith(`${n.toLowerCase()} `));
|
|
22
|
+
return hit ? { target: hit.a, message: body.slice(hit.n.length).trim() } : null;
|
|
23
|
+
}
|
|
24
|
+
/** The @ menu while the draft is a bare "@token" being typed: the live agents whose name or id starts with it, then the
|
|
25
|
+
* "@all stop" row. Null when the draft is not a bare @token, or no live agent exists. */
|
|
26
|
+
export function matchAgentMentions(draft, agents) {
|
|
27
|
+
const m = /^@([\w.-]*)$/.exec(draft);
|
|
28
|
+
if (!m)
|
|
29
|
+
return null;
|
|
30
|
+
const running = agents.filter(live);
|
|
31
|
+
if (!running.length)
|
|
32
|
+
return null;
|
|
33
|
+
const q = m[1].toLowerCase();
|
|
34
|
+
const hits = running.filter((a) => nameOf(a).toLowerCase().startsWith(q) || a.id.toLowerCase().startsWith(q));
|
|
35
|
+
if ("all".startsWith(q))
|
|
36
|
+
hits.push("all");
|
|
37
|
+
return hits.length ? hits : null;
|
|
38
|
+
}
|
|
39
|
+
/** What Tab completes the highlighted @ row to. */
|
|
40
|
+
export function mentionCompletion(m) {
|
|
41
|
+
return m === "all" ? "@all stop" : `@${nameOf(m)} `;
|
|
42
|
+
}
|
|
43
|
+
/** The one-line @ menu, fitted to cols−1: " @ Nova (researcher · round 6) · Atlas (builder · round 3) · @all stop ·
|
|
44
|
+
* ⏎ sends to Nova, no main turn". Narrow: names only, then only the highlighted one. */
|
|
45
|
+
export function mentionMenuLine(matches, sel, cols) {
|
|
46
|
+
const hi = matches[Math.min(Math.max(sel, 0), matches.length - 1)];
|
|
47
|
+
const label = (m, full) => m === "all" ? "@all stop" : `${nameOf(m)}${full ? ` (${[m.title, m.status === "queued" ? "queued" : m.round ? `round ${m.round}` : ""].filter(Boolean).join(" · ")})` : ""}`;
|
|
48
|
+
const mark = (m) => (m === hi ? "▸" : "");
|
|
49
|
+
if (cols < 40)
|
|
50
|
+
return fitSegments([seg(`${mark(hi)}${label(hi, false)}`)], cols, { lead: " @ " });
|
|
51
|
+
const full = matches.map((m) => `${mark(m)}${label(m, true)}`).join(" · ");
|
|
52
|
+
const names = matches.map((m) => `${mark(m)}${label(m, false)}`).join(" · ");
|
|
53
|
+
const list = cols >= 80 && cellWidth(` @ ${full}`) <= cols - 1 ? full : names; // role and round only when they all fit
|
|
54
|
+
return fitSegments([seg(list), ...(hi !== "all" ? [seg(` · ⏎ sends to ${nameOf(hi)}, no main turn`, 1)] : [])], cols, { lead: " @ ", sep: "" });
|
|
55
|
+
}
|
|
56
|
+
export const MAIN = "main";
|
|
57
|
+
/** main first, then every sub-agent with a conversation to show: the live ones, then the finished ones still retained. */
|
|
58
|
+
export function conversationList(agents, retired, hasTranscript) {
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
const out = [{ id: MAIN, label: "main" }];
|
|
61
|
+
for (const a of [...agents, ...[...retired].reverse()]) {
|
|
62
|
+
if (seen.has(a.id) || !hasTranscript(a.id))
|
|
63
|
+
continue;
|
|
64
|
+
seen.add(a.id);
|
|
65
|
+
out.push({ id: a.id, label: a.name ?? a.id, status: a.status });
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/** The centre of the mode line. Unfocused: "↓ main · Nova · Atlas" (the open one marked ●). Focused: the highlighted one
|
|
70
|
+
* in brackets and the keys. Fitted to `width`; "" when main is the only conversation. */
|
|
71
|
+
/** A key while the switcher has focus. The selection is a conversation id, never a position: an agent spawned or finished
|
|
72
|
+
* while it has focus moves the list, not the selection (review F13). A selected conversation that left the list counts
|
|
73
|
+
* as main. */
|
|
74
|
+
export function switcherKey(convs, sel, k) {
|
|
75
|
+
if (k === "back")
|
|
76
|
+
return { back: true };
|
|
77
|
+
const at = Math.max(0, convs.findIndex((c) => c.id === sel));
|
|
78
|
+
if (k === "open")
|
|
79
|
+
return { open: convs[at]?.id ?? MAIN };
|
|
80
|
+
const n = Math.max(1, convs.length);
|
|
81
|
+
return { sel: convs[(at + (k === "left" ? n - 1 : 1)) % n]?.id ?? MAIN };
|
|
82
|
+
}
|
|
83
|
+
export function switcherLine(convs, o, width) {
|
|
84
|
+
if (convs.length < 2 || width < 8)
|
|
85
|
+
return "";
|
|
86
|
+
const names = convs.map((c, i) => {
|
|
87
|
+
const open = c.id === o.open ? "●" : "";
|
|
88
|
+
return o.focused && i === o.sel ? `[${open}${c.label}]` : `${open}${c.label}`;
|
|
89
|
+
});
|
|
90
|
+
const segs = o.focused
|
|
91
|
+
? [seg("◂ "), seg(names.join(" · ")), seg(" ▸"), seg(" · ⏎ open · ↑ back", 1)]
|
|
92
|
+
: [seg("↓ ", 2), seg(names.join(" · "))];
|
|
93
|
+
return fitSegments(segs, width + 1, { sep: "" });
|
|
94
|
+
}
|
|
95
|
+
const oneLine = (s) => s.replace(/\s+/g, " ").trim();
|
|
96
|
+
const argsPreview = (args) => {
|
|
97
|
+
try {
|
|
98
|
+
const o = JSON.parse(args);
|
|
99
|
+
const v = o.path ?? o.file_path ?? o.command ?? o.query ?? o.url ?? o.pattern ?? Object.values(o)[0];
|
|
100
|
+
return typeof v === "string" ? v : JSON.stringify(v ?? "");
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return args;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/** The open conversation's body: exactly `rows` lines (padded), each fitted to cols−1 — the pane keeps one height for
|
|
107
|
+
* as long as it is open (plan ground rule 3), and new lines push old ones off the top. */
|
|
108
|
+
export function transcriptLines(msgs, cols, rows) {
|
|
109
|
+
const lines = [];
|
|
110
|
+
let first = true;
|
|
111
|
+
for (const m of msgs) {
|
|
112
|
+
const text = typeof m.content === "string" ? m.content : "";
|
|
113
|
+
if (m.role === "system")
|
|
114
|
+
continue;
|
|
115
|
+
if (m.role === "user") {
|
|
116
|
+
if (text.startsWith(ENGINE_NOTE_PREFIX))
|
|
117
|
+
lines.push(` · ${oneLine(text.slice(ENGINE_NOTE_PREFIX.length))}`);
|
|
118
|
+
else {
|
|
119
|
+
lines.push(`${first ? "▸ brief" : "❯"} ${oneLine(text)}`);
|
|
120
|
+
first = false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (m.role === "assistant") {
|
|
124
|
+
if (text.trim())
|
|
125
|
+
lines.push(`⏺ ${oneLine(text)}`);
|
|
126
|
+
for (const c of m.tool_calls ?? [])
|
|
127
|
+
lines.push(`▶ ${c.function?.name ?? "tool"}(${oneLine(argsPreview(c.function?.arguments ?? ""))})`);
|
|
128
|
+
}
|
|
129
|
+
else if (m.role === "tool") {
|
|
130
|
+
const head = text.split("\n").find((l) => l.trim()) ?? "";
|
|
131
|
+
lines.push(` ⤷ ${oneLine(head)}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const tail = lines.slice(-rows).map((l) => fitSegments([seg(l)], cols));
|
|
135
|
+
while (tail.length < rows)
|
|
136
|
+
tail.unshift("");
|
|
137
|
+
return tail;
|
|
138
|
+
}
|
|
139
|
+
/** The pane's header line: who it is, what it is doing, and the keys. */
|
|
140
|
+
export function transcriptHeader(a, cols) {
|
|
141
|
+
const state = a.status === "working" ? "running" : a.status === "queued" ? "queued" : a.status === "idle" ? "done" : "stopped";
|
|
142
|
+
const who = [a.name ?? a.id, a.title, a.model, a.round ? `round ${a.round}` : "", state].filter(Boolean).join(" · ");
|
|
143
|
+
const keys = a.status === "working" || a.status === "queued" ? " · type to message it · ↓ switch" : " · finished, read-only · ↓ switch";
|
|
144
|
+
return fitSegments([seg(`── ${who} ──`), seg(keys, 1)], cols, { sep: "" });
|
|
145
|
+
}
|
|
146
|
+
/** Padding that puts the switcher at the true centre of the mode line when the left side allows it (else right after
|
|
147
|
+
* it), keeping the whole row at cols−1: left · pad · centre · pad · right. */
|
|
148
|
+
export function centreLayout(leftW, centreW, rightW, cols) {
|
|
149
|
+
const total = Math.max(0, cols - 1);
|
|
150
|
+
const ideal = Math.floor((total - centreW) / 2);
|
|
151
|
+
const before = Math.max(1, Math.min(ideal - leftW, total - leftW - centreW - rightW - 1));
|
|
152
|
+
const after = Math.max(1, total - leftW - before - centreW - rightW);
|
|
153
|
+
return { before, after };
|
|
154
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The decode readout (TUI plan #13): while the model generates, the phase line says how fast, at what context depth,
|
|
2
|
+
// and — when this session measured the same model shallower — how fast it was there, which names both the cause of a
|
|
3
|
+
// slow stretch (depth) and its lever (/compact). Early repetition gets a calm, informative note (James, 11/04: "make
|
|
4
|
+
// this look less like an error"): no ⚠, no error color, and it never stops anything — the engine's own hard stop and
|
|
5
|
+
// its 16k threshold are untouched. Pure bookkeeping; the shell feeds it, and runs the guard's detector on its tick.
|
|
6
|
+
import { seg } from "./fit.js";
|
|
7
|
+
/** A depth or a length, rounded the way the readout says it: "84k context", "the last 8k chars". */
|
|
8
|
+
const k = (n) => (n < 1000 ? String(Math.round(n)) : `${Math.round(n / 1000)}k`);
|
|
9
|
+
const WINDOW_MS = 5000;
|
|
10
|
+
const MIN_SPAN_MS = 1500;
|
|
11
|
+
export function createDecode() {
|
|
12
|
+
return { samples: [], roundStartTok: 0, history: new Map(), checkedChars: 0, repeatingChars: 0 };
|
|
13
|
+
}
|
|
14
|
+
/** A new round: the window restarts (the previous round's rate is history now). */
|
|
15
|
+
export function decodeRound(d, tok) {
|
|
16
|
+
d.samples = [];
|
|
17
|
+
d.roundStartTok = tok;
|
|
18
|
+
d.roundStartAt = undefined;
|
|
19
|
+
d.checkedChars = 0;
|
|
20
|
+
d.repeatingChars = 0;
|
|
21
|
+
}
|
|
22
|
+
/** The live token count at `now` (≈1 per streamed delta; onTokens corrects it at the round's end). */
|
|
23
|
+
export function noteDecode(d, tok, now) {
|
|
24
|
+
d.roundStartAt ??= now;
|
|
25
|
+
d.samples.push({ t: now, tok });
|
|
26
|
+
while (d.samples.length > 2 && d.samples[1].t <= now - WINDOW_MS)
|
|
27
|
+
d.samples.shift();
|
|
28
|
+
}
|
|
29
|
+
/** Tokens per second over the last ~5 s; undefined until the window spans 1.5 s. */
|
|
30
|
+
export function decodeRate(d) {
|
|
31
|
+
const a = d.samples[0], b = d.samples[d.samples.length - 1];
|
|
32
|
+
if (!a || !b || b.t - a.t < MIN_SPAN_MS)
|
|
33
|
+
return undefined;
|
|
34
|
+
return ((b.tok - a.tok) / (b.t - a.t)) * 1000;
|
|
35
|
+
}
|
|
36
|
+
/** The round ended: keep its average rate against its depth, for this model's comparisons. */
|
|
37
|
+
export function noteRoundRate(d, model, depth, tok, now) {
|
|
38
|
+
if (!depth || d.roundStartAt === undefined)
|
|
39
|
+
return;
|
|
40
|
+
const ms = now - d.roundStartAt, made = tok - d.roundStartTok;
|
|
41
|
+
if (ms < 2000 || made < 20)
|
|
42
|
+
return;
|
|
43
|
+
const list = [...(d.history.get(model) ?? []), { depth, rate: (made / ms) * 1000 }];
|
|
44
|
+
d.history.set(model, list.slice(-16));
|
|
45
|
+
}
|
|
46
|
+
/** The newest finished round of this model at under half the current depth, if this session has one. */
|
|
47
|
+
export function shallower(d, model, depth) {
|
|
48
|
+
return [...(d.history.get(model) ?? [])].reverse().find((h) => h.depth < depth / 2);
|
|
49
|
+
}
|
|
50
|
+
/** Whether to run the repetition check now: every 2k new streamed characters. */
|
|
51
|
+
export function dueCheck(d, chars) {
|
|
52
|
+
if (chars - d.checkedChars < 2000)
|
|
53
|
+
return false;
|
|
54
|
+
d.checkedChars = chars;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/** How much of the tail the check reads — the guard's detector, run early, on at most this much. */
|
|
58
|
+
export const CHECK_TAIL = 8000;
|
|
59
|
+
/** Whether a stream's deltas only approximate its tokens: llama.cpp (the default transport) sends one token per delta;
|
|
60
|
+
* a vendor on the OpenAI or Anthropic wire packs several into one event, so a rate or count from deltas is "≈". */
|
|
61
|
+
export function deltasApprox(transport) {
|
|
62
|
+
return transport !== undefined && transport !== "llama";
|
|
63
|
+
}
|
|
64
|
+
/** The phase line's decode segments, in give-way order: the comparison first, then the depth, then the rate; the
|
|
65
|
+
* repetition note outranks them all and only shortens. `approx` marks a transport whose deltas carry several tokens. */
|
|
66
|
+
export function decodeSegs(v) {
|
|
67
|
+
const out = [];
|
|
68
|
+
if (v.rate !== undefined) {
|
|
69
|
+
const r = `${v.approx ? "≈" : ""}${Math.max(0, Math.round(v.rate))} tok/s`;
|
|
70
|
+
const deep = v.depth ? `${r} at ${k(v.depth)} context` : r;
|
|
71
|
+
const cmp = v.compare && !v.repeatingChars ? `${deep} (${Math.round(v.compare.rate)} tok/s at ${k(v.compare.depth)} earlier this session)` : deep;
|
|
72
|
+
out.push(seg([...new Set([cmp, deep, r])], 4));
|
|
73
|
+
}
|
|
74
|
+
if (v.repeatingChars)
|
|
75
|
+
out.push(seg([`↻ the last ${k(v.repeatingChars)} chars mostly repeat one passage`, "↻ repeating"], 1.5, true));
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** ctrl+o, the same pure-helper shape as Composer's isBackgroundKey / isContextCycleKey. */
|
|
2
|
+
export function isExpandKey(ch, key) {
|
|
3
|
+
return !!key.ctrl && ch === "o";
|
|
4
|
+
}
|
|
5
|
+
const MAX_COLLAPSED = 50;
|
|
6
|
+
export function pushCollapsed(stack, item) {
|
|
7
|
+
const next = [...stack.filter((c) => !(c.kind === item.kind && c.id === item.id)), item];
|
|
8
|
+
return next.length > MAX_COLLAPSED ? next.slice(next.length - MAX_COLLAPSED) : next;
|
|
9
|
+
}
|
|
10
|
+
/** The newest collapsed item and the stack without it (nothing when the stack is empty). */
|
|
11
|
+
export function popCollapsed(stack) {
|
|
12
|
+
return stack.length ? { item: stack[stack.length - 1], rest: stack.slice(0, -1) } : { rest: stack };
|
|
13
|
+
}
|
|
14
|
+
/** Drop an item expanded some other way (`/agents <name> report`), so ctrl+o does not repeat it. */
|
|
15
|
+
export function dropCollapsed(stack, item) {
|
|
16
|
+
return stack.filter((c) => !(c.kind === item.kind && c.id === item.id));
|
|
17
|
+
}
|
package/dist/ui/fit.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// One fitter for every live line (TUI plan, ground rule 2). A line is a list of segments; each segment has a rank and
|
|
2
|
+
// one or more forms (full first, then shorter). While the line is wider than cols−1 cells, the highest-ranked segment
|
|
3
|
+
// that can still give something up steps to its next form, or leaves when it has none left; truncateToWidth(cols−1) is
|
|
4
|
+
// the last guard. cols−1, never cols: a line exactly as wide as the terminal wraps to a second row Ink's height
|
|
5
|
+
// accounting misses, and the whole frame creeps up the screen (StatusRule.ruleFill). Clip a label BEFORE fileLink adds
|
|
6
|
+
// OSC-8 escapes: truncating an escaped string cuts the escape.
|
|
7
|
+
import { cellWidth, truncateToWidth } from "./StatusRule.js";
|
|
8
|
+
/** A segment: one text, or its forms from full to shortest. */
|
|
9
|
+
export function seg(text, rank, keep = false) {
|
|
10
|
+
return { forms: (Array.isArray(text) ? text : [text]).filter((f) => f !== ""), rank, keep };
|
|
11
|
+
}
|
|
12
|
+
export function fitSegments(segs, cols, opts = {}) {
|
|
13
|
+
const lead = opts.lead ?? "";
|
|
14
|
+
const sep = opts.sep ?? " · ";
|
|
15
|
+
const state = segs.filter((s) => s.forms.length).map((s) => ({ s, i: 0, gone: false }));
|
|
16
|
+
const render = () => lead + state.filter((x) => !x.gone).map((x) => x.s.forms[x.i]).join(sep);
|
|
17
|
+
const max = cols - 1;
|
|
18
|
+
let line = render();
|
|
19
|
+
while (cellWidth(line) > max) {
|
|
20
|
+
let pick = -1;
|
|
21
|
+
for (let k = 0; k < state.length; k++) {
|
|
22
|
+
const x = state[k];
|
|
23
|
+
if (x.gone || x.s.rank === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
if (x.i >= x.s.forms.length - 1 && x.s.keep)
|
|
26
|
+
continue;
|
|
27
|
+
if (pick < 0 || x.s.rank >= (state[pick].s.rank ?? 0))
|
|
28
|
+
pick = k;
|
|
29
|
+
}
|
|
30
|
+
if (pick < 0)
|
|
31
|
+
break;
|
|
32
|
+
const x = state[pick];
|
|
33
|
+
if (x.i < x.s.forms.length - 1)
|
|
34
|
+
x.i++;
|
|
35
|
+
else
|
|
36
|
+
x.gone = true;
|
|
37
|
+
line = render();
|
|
38
|
+
}
|
|
39
|
+
return truncateToWidth(line, max);
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// A line that ends in free text — a message preview, a description — on top of the one fitter (fit.ts): the segments
|
|
2
|
+
// are fitted with the tail's first `tailMin` cells reserved, then the tail is cut at the window. Without it a long
|
|
3
|
+
// preview makes every key hint give way first, even on a wide terminal, before the preview itself is cut.
|
|
4
|
+
import { fitSegments } from "./fit.js";
|
|
5
|
+
import { cellWidth, truncateToWidth } from "./StatusRule.js";
|
|
6
|
+
export function fitWithTail(segs, tail, cols, o = {}) {
|
|
7
|
+
const join = tail ? o.join ?? "" : "";
|
|
8
|
+
const reserve = Math.min(cellWidth(tail), o.tailMin ?? 24) + cellWidth(join);
|
|
9
|
+
const head = fitSegments(segs, Math.max(2, cols - reserve), { lead: o.lead, sep: o.sep });
|
|
10
|
+
if (!tail)
|
|
11
|
+
return truncateToWidth(head, Math.max(0, cols - 1));
|
|
12
|
+
const room = cols - 1 - cellWidth(head) - cellWidth(join);
|
|
13
|
+
return room > 0 ? head + join + truncateToWidth(tail, room) : truncateToWidth(head, Math.max(0, cols - 1));
|
|
14
|
+
}
|