@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,57 @@
|
|
|
1
|
+
// What the owner has typed while a turn runs (TUI A3.1 / A3.2). A steer goes in before the next model call; an after-turn
|
|
2
|
+
// item waits for the turn to end; a staged command runs alone when the turn ends, never joined into a text turn (a
|
|
3
|
+
// "/model cortana" joined with other queued text used to reach the MODEL as plain text). Pure, so the order rules and the
|
|
4
|
+
// hint widths are unit-tested without a TTY.
|
|
5
|
+
import { seg } from "./fit.js";
|
|
6
|
+
import { fitWithTail } from "./fitTail.js";
|
|
7
|
+
const PREVIEW_MIN = 24; // cells a preview keeps before the key hints give way (fitTail.ts)
|
|
8
|
+
const preview = (texts) => texts.join("\n").replace(/\s*\n\s*/g, " / ");
|
|
9
|
+
/** ↑ / ⌫ act on the most recent pending item, whichever kind it is. */
|
|
10
|
+
export function popLatest(items) {
|
|
11
|
+
if (!items.length)
|
|
12
|
+
return { rest: [] };
|
|
13
|
+
return { item: items[items.length - 1], rest: items.slice(0, -1) };
|
|
14
|
+
}
|
|
15
|
+
/** Every steer, oldest first, out of the list — the engine folds them in as one owner message at the next round. */
|
|
16
|
+
export function takeSteers(items) {
|
|
17
|
+
return { steers: items.filter((i) => i.kind === "steer").map((i) => i.text), rest: items.filter((i) => i.kind !== "steer") };
|
|
18
|
+
}
|
|
19
|
+
/** What runs when the turn ends: staged commands one by one, then one text turn — steers the turn never reached first
|
|
20
|
+
* (nothing typed is lost), then the after-turn messages in the order they were typed. */
|
|
21
|
+
export function drainPlan(items) {
|
|
22
|
+
const commands = items.filter((i) => i.kind === "command").map((i) => i.text);
|
|
23
|
+
const steers = items.filter((i) => i.kind === "steer").map((i) => i.text);
|
|
24
|
+
const after = items.filter((i) => i.kind === "after").map((i) => i.text);
|
|
25
|
+
return { commands, text: [...steers, ...after].join("\n") };
|
|
26
|
+
}
|
|
27
|
+
/** The pending hint above the composer: one line for steers, one for after-turn items, each fitted to cols−1. The ↑/⌫
|
|
28
|
+
* keys ride on the line that holds the most recent item. `phase` is what the turn is doing now ("reasoning",
|
|
29
|
+
* "running bash"). Drop order as the window narrows: the phase, then the keys, then the long head. */
|
|
30
|
+
export function pendingLines(items, cols, phase) {
|
|
31
|
+
const steers = items.filter((i) => i.kind === "steer").map((i) => i.text);
|
|
32
|
+
const after = items.filter((i) => i.kind !== "steer").map((i) => i.text);
|
|
33
|
+
const latest = items[items.length - 1]?.kind;
|
|
34
|
+
const keys = (n) => seg(n > 1 ? " · ↑ edit last · ⌫ cancel last" : " · ↑ edit · ⌫ cancel", 2);
|
|
35
|
+
const out = [];
|
|
36
|
+
if (steers.length) {
|
|
37
|
+
const segs = [
|
|
38
|
+
seg([steers.length > 1 ? `↳ ${steers.length} steers · go in before the next model call` : "↳ steer · goes in before the next model call", "↳ steer"], 1, true),
|
|
39
|
+
...(phase ? [seg(` (now: ${phase})`, 3)] : []),
|
|
40
|
+
...(latest === "steer" ? [keys(steers.length)] : []),
|
|
41
|
+
];
|
|
42
|
+
out.push(fitWithTail(segs, preview(steers), cols, { sep: "", join: ": ", tailMin: PREVIEW_MIN }));
|
|
43
|
+
}
|
|
44
|
+
if (after.length) {
|
|
45
|
+
const segs = [
|
|
46
|
+
seg([after.length > 1 ? `⏎ after this turn (${after.length})` : "⏎ after this turn", "⏎ after turn"], 1, true),
|
|
47
|
+
...(latest && latest !== "steer" ? [keys(after.length)] : []),
|
|
48
|
+
];
|
|
49
|
+
out.push(fitWithTail(segs, preview(after), cols, { sep: "", join: ": ", tailMin: PREVIEW_MIN }));
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The keys a running turn takes, for the phase line's tail (ui/phase.ts puts "esc to interrupt" after them): Enter
|
|
54
|
+
* steers, Tab queues for after the turn. "tab after turn" gives way first on a narrow window, then "⏎ steer". */
|
|
55
|
+
export function turnKeySegs() {
|
|
56
|
+
return [seg("⏎ steer", 5), seg("tab after turn", 6)];
|
|
57
|
+
}
|
package/dist/ui/phase.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The honest phase line (TUI plan #2): the dim line under the spinner names only what the engine measured. It used to
|
|
2
|
+
// fall back to "reasoning" whenever no prefill label was set, so a request parked behind a sub-agent, a server still
|
|
3
|
+
// loading the model and a mid-turn compaction all read as "reasoning" under a rotating "Untangling…". Each phase here is
|
|
4
|
+
// set by a real signal (cli.tsx): waiting at the turn start and after every tool round, loading from the on-demand
|
|
5
|
+
// Aurora notice, reading from prompt_progress, thinking from a reasoning chunk, writing from a content chunk, tools from
|
|
6
|
+
// onToolStart, recovering from onSelfHeal, compacting from the compaction start. Always one row: the cause drops first.
|
|
7
|
+
import { fitSegments, seg } from "./fit.js";
|
|
8
|
+
import { fmtElapsed, fmtTok } from "./format.js";
|
|
9
|
+
import { readLine } from "./readProgress.js";
|
|
10
|
+
import { decodeSegs } from "./decodeHealth.js";
|
|
11
|
+
const VERB = {
|
|
12
|
+
waiting: "Waiting", queued: "Waiting", sent: "Waiting", loading: "Loading", reading: "Reading", thinking: "Thinking", writing: "Writing",
|
|
13
|
+
drafting: "Drafting", tools: "Running", recovering: "Recovering", compacting: "Compacting",
|
|
14
|
+
};
|
|
15
|
+
const WORD = {
|
|
16
|
+
waiting: "waiting for the model", queued: "waiting for a slot", sent: "request sent", loading: "loading the model", reading: "reading",
|
|
17
|
+
thinking: "thinking", writing: "writing", drafting: "drafting", tools: "running tools", recovering: "recovering", compacting: "compacting",
|
|
18
|
+
};
|
|
19
|
+
/** The phase in a few words, for the main lane (BgPanel lanes). */
|
|
20
|
+
export function phaseWord(phase) {
|
|
21
|
+
return WORD[phase];
|
|
22
|
+
}
|
|
23
|
+
/** The spinner verb for a measured phase; undefined when nothing is known (the spinner then rotates its pool). A read
|
|
24
|
+
* the server has finished is waiting for its first token, not reading. */
|
|
25
|
+
export function phaseVerb(phase, read) {
|
|
26
|
+
if (phase === "reading" && read?.complete)
|
|
27
|
+
return "Waiting";
|
|
28
|
+
return phase ? VERB[phase] : undefined;
|
|
29
|
+
}
|
|
30
|
+
const ESC = seg(["esc to interrupt", "esc"], 1, true);
|
|
31
|
+
/** A gate owner label as the owner reads it: "main" → the main turn, a sub-agent's name → "Iris (sub-agent)". */
|
|
32
|
+
export function holderLabel(owner) {
|
|
33
|
+
if (!owner)
|
|
34
|
+
return undefined;
|
|
35
|
+
if (owner === "main")
|
|
36
|
+
return "the main turn";
|
|
37
|
+
if (owner === "compaction")
|
|
38
|
+
return "a compaction";
|
|
39
|
+
if (owner === "sub-agent")
|
|
40
|
+
return "a sub-agent";
|
|
41
|
+
return `${owner} (sub-agent)`;
|
|
42
|
+
}
|
|
43
|
+
function tokSeg(tokens) {
|
|
44
|
+
return tokens ? [seg([`${fmtTok(tokens)} tok this turn`, `${fmtTok(tokens)} tok`], 2, true)] : [];
|
|
45
|
+
}
|
|
46
|
+
/** The phase line: `meter` (reading only, ≥100 cols) is drawn in its own color before `text`. */
|
|
47
|
+
export function phaseLine(v, cols, frame = 0) {
|
|
48
|
+
const tail = [...(v.hint ? [seg(v.hint, 2)] : []), ...(v.keys ?? []), ESC];
|
|
49
|
+
const fit = (segs) => ({ text: fitSegments([...segs, ...tail], cols, { lead: " " }).slice(2) });
|
|
50
|
+
const model = v.model ?? "the model";
|
|
51
|
+
switch (v.phase) {
|
|
52
|
+
case "reading":
|
|
53
|
+
if (v.read)
|
|
54
|
+
return readLine(v.read, cols, { model: v.model, frame, tail });
|
|
55
|
+
return fit([seg("reading the prompt")]);
|
|
56
|
+
case "queued": {
|
|
57
|
+
const who = holderLabel(v.queue?.holder);
|
|
58
|
+
const line = fitSegments([
|
|
59
|
+
seg(`waiting for ${model}`),
|
|
60
|
+
...(who ? [seg([`${who} holds its slot`, `${who.replace(/ \(sub-agent\)$/, "")} holds it`], 4)] : []),
|
|
61
|
+
seg(v.queue?.ahead ? `${v.queue.ahead} ahead` : "next in line", 3),
|
|
62
|
+
...tail,
|
|
63
|
+
], cols, { lead: " ◌ " });
|
|
64
|
+
return { text: line.slice(2) };
|
|
65
|
+
}
|
|
66
|
+
case "sent":
|
|
67
|
+
return fit([seg(`request sent to ${model}`), v.expect ? seg(v.expect, 3, true) : seg("no reply yet", 4)]);
|
|
68
|
+
case "loading":
|
|
69
|
+
return fit([seg([`loading ${model} (it was unloaded)`, `loading ${model}`], 3, true), seg("your turn starts the moment it is up", 4)]);
|
|
70
|
+
case "thinking":
|
|
71
|
+
return fit([seg("thinking"), ...tokSeg(v.tokens), ...(v.decode ? decodeSegs(v.decode) : [])]);
|
|
72
|
+
case "writing":
|
|
73
|
+
return fit([seg("writing"), ...tokSeg(v.tokens), ...(v.decode ? decodeSegs(v.decode) : [])]);
|
|
74
|
+
case "drafting":
|
|
75
|
+
return fit([seg("drafting"), ...tokSeg(v.tokens), ...(v.decode ? decodeSegs(v.decode) : [])]);
|
|
76
|
+
case "tools":
|
|
77
|
+
return fit([seg("running tools")]);
|
|
78
|
+
case "recovering":
|
|
79
|
+
return fit([seg(v.label || "recovering")]);
|
|
80
|
+
case "compacting": {
|
|
81
|
+
const c = v.compaction;
|
|
82
|
+
if (!c)
|
|
83
|
+
return fit([seg(v.label || "compacting context")]);
|
|
84
|
+
const r = c.read;
|
|
85
|
+
// The span is cached, so the summarizer reads a few thousand new tokens and then writes for most of the
|
|
86
|
+
// compaction: once its read is done, or its first delta lands, the line says so (review F2).
|
|
87
|
+
const wrote = c.wrote ? `${c.approx ? "≈" : ""}${fmtTok(c.wrote)} tok` : undefined;
|
|
88
|
+
const phase = wrote ? [seg([`writing the summary · ${wrote}`, `writing · ${wrote}`], 3, true)]
|
|
89
|
+
: r && r.done >= r.fresh ? [seg(`summarizer read ${fmtTok(r.fresh)} new`, 4), seg(["writing the summary", "writing"], 3, true)]
|
|
90
|
+
: r ? [seg([r.cache > 0 ? `summarizer reading ${fmtTok(r.done)} new (${fmtTok(r.cache)} reused)` : `summarizer reading ${fmtTok(r.done)} of ${fmtTok(r.fresh)} new`, `summarizer ${Math.round(r.fraction * 100)}%`], 3)]
|
|
91
|
+
: [];
|
|
92
|
+
return fit([seg(`compacting ${fmtTok(c.before)} tokens`), ...phase]);
|
|
93
|
+
}
|
|
94
|
+
default: // waiting
|
|
95
|
+
return fit([seg("waiting for the model"), v.expect ? seg(v.expect, 3, true) : seg("nothing back yet", 4)]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** The receipt when a server held a request ≥5 s before it began reading: busy with another client, or loading. */
|
|
99
|
+
export function holdReceipt(model, heldMs, cols) {
|
|
100
|
+
return fitSegments([seg(`${model} began reading ${fmtElapsed(heldMs)} after the request was sent`), seg("(the server was busy, or loading the model)", 2)], cols, { lead: " ▸ ", sep: " " });
|
|
101
|
+
}
|
|
102
|
+
/** The receipt when a compaction finished and freed something: before → after, and how long it took. */
|
|
103
|
+
export function compactReceipt(before, after, ms, cols, tail) {
|
|
104
|
+
return fitSegments([seg(`compacted ${fmtTok(before)} → ${fmtTok(after)} in ${fmtElapsed(ms)}`), ...(tail ? [seg(tail, 2)] : [])], cols, { lead: " ▸ " });
|
|
105
|
+
}
|
package/dist/ui/planExit.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
// Plan-mode "Approve & run": exiting plan mode after the model has actually proposed a plan
|
|
2
|
-
// shouldn't silently flip modes and leave the owner to shift+tab out AND re-type "go" — it should
|
|
3
|
-
// offer the choice inline. These are pure decision functions (no React, no Session), mirroring
|
|
4
|
-
// questionKey in QuestionPrompt.tsx, so the whole gate + answer-mapping is testable without a TTY.
|
|
5
|
-
// cli.tsx's applyMode is the one place that wires them to the real mode switch + turn submission.
|
|
6
1
|
export const PLAN_EXIT_OPTIONS = ["Approve & run", "Keep planning", "Cancel"];
|
|
7
2
|
export const APPROVED_PLAN_MESSAGE = "Proceed with the approved plan.";
|
|
8
3
|
/** Should exiting plan mode surface the picker instead of switching modes silently? Only when the
|
package/dist/ui/progressbar.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Pure, testable progress-bar primitives shared by the media-gen
|
|
2
|
-
//
|
|
1
|
+
// Pure, testable progress-bar primitives shared by the media-gen sweep (ToolStep.tsx) and the compaction
|
|
2
|
+
// bar (ActivitySpinner.tsx). Font-safe per toolicons.ts's rule: only ▰ (U+25B0 filled) and
|
|
3
3
|
// ▱ (U+25B1 empty), both Geometric Shapes — no new Unicode blocks introduced.
|
|
4
4
|
const FILLED = "▰";
|
|
5
5
|
const EMPTY = "▱";
|
|
@@ -11,8 +11,8 @@ export function renderBar(fraction, width = 10) {
|
|
|
11
11
|
return FILLED.repeat(filled) + EMPTY.repeat(width - filled);
|
|
12
12
|
}
|
|
13
13
|
/** An indeterminate "sweep" bar: a `litWidth`-cell bright window that starts at `frame % width` and wraps
|
|
14
|
-
* around the track — for a process with no knowable percentage (
|
|
15
|
-
* media
|
|
14
|
+
* around the track — for a process with no knowable percentage (a compaction that reports no read progress,
|
|
15
|
+
* a media render). It never fills. `frame` is the shared ticker's frame index (see tick.ts). */
|
|
16
16
|
export function renderSweepBar(frame, width = 10, litWidth = 3) {
|
|
17
17
|
const start = ((frame % width) + width) % width; // frame is always >=0 from useTick, but stay safe
|
|
18
18
|
let out = "";
|
|
@@ -22,25 +22,3 @@ export function renderSweepBar(frame, width = 10, litWidth = 3) {
|
|
|
22
22
|
}
|
|
23
23
|
return out;
|
|
24
24
|
}
|
|
25
|
-
// ETA heuristics for media-gen tools (image_generate / video_generate): the flux/video brokers report no
|
|
26
|
-
// percentage, so progress is derived from elapsed-time-vs-estimate instead. video scales with frame count —
|
|
27
|
-
// LTX on the flux/video workers runs ~210s at the 97-frame default, roughly linear below that.
|
|
28
|
-
const IMAGE_ETA_MS = 40_000;
|
|
29
|
-
const VIDEO_BASE_FRAMES = 97;
|
|
30
|
-
const VIDEO_BASE_ETA_MS = 210_000;
|
|
31
|
-
const VIDEO_MIN_ETA_MS = 60_000;
|
|
32
|
-
/** Estimated total duration for a media-gen tool call, from its own args when available. */
|
|
33
|
-
export function mediaEtaMs(toolName, args) {
|
|
34
|
-
if (/video_generate/i.test(toolName)) {
|
|
35
|
-
const frames = typeof args?.num_frames === "number" ? args.num_frames : VIDEO_BASE_FRAMES;
|
|
36
|
-
return Math.max(VIDEO_MIN_ETA_MS, (frames / VIDEO_BASE_FRAMES) * VIDEO_BASE_ETA_MS);
|
|
37
|
-
}
|
|
38
|
-
return IMAGE_ETA_MS; // image_generate (and any other media-kind tool) — flat-rate estimate
|
|
39
|
-
}
|
|
40
|
-
/** elapsed/ETA as a progress fraction, capped at 95% — a job can legitimately run past its estimate, and
|
|
41
|
-
* reading 100% before the real result arrives would make the bar lie while the user keeps waiting. */
|
|
42
|
-
export function mediaProgressFraction(elapsedMs, etaMs) {
|
|
43
|
-
if (etaMs <= 0)
|
|
44
|
-
return 0.95;
|
|
45
|
-
return Math.min(0.95, elapsedMs / etaMs);
|
|
46
|
-
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The cold-read forecast (TUI plan #10): at the moment of choice — /model, a finished compaction, a gateway fallback,
|
|
2
|
+
// a route change — say what the next request may have to read, while the owner can still change course. "May … up
|
|
3
|
+
// to": a model switched back to can still hold the prefix, and so can llama.cpp's host-RAM cache. The time is shown
|
|
4
|
+
// only from THIS process's own measured cold read on that model, at half the forecast depth or deeper (prefill slows
|
|
5
|
+
// with depth), and it is never drawn as a bar. Otherwise the line gives the size alone.
|
|
6
|
+
import { fitSegments, seg } from "./fit.js";
|
|
7
|
+
import { fmtElapsed, fmtTok } from "./format.js";
|
|
8
|
+
/** A cold read this small says little about a deep one. */
|
|
9
|
+
export const COLD_SAMPLE_MIN = 4096;
|
|
10
|
+
const KEEP = 8;
|
|
11
|
+
/** Record one measured read: only a cold one (nothing cached) of COLD_SAMPLE_MIN fresh tokens or more counts. */
|
|
12
|
+
export function noteColdRead(store, model, r, at = Date.now()) {
|
|
13
|
+
if (r.cache !== 0 || r.fresh < COLD_SAMPLE_MIN || r.elapsedMs <= 0)
|
|
14
|
+
return;
|
|
15
|
+
const list = [...(store.get(model) ?? []), { depth: r.fresh, rate: r.fresh / (r.elapsedMs / 1000), at }];
|
|
16
|
+
store.set(model, list.slice(-KEEP));
|
|
17
|
+
}
|
|
18
|
+
/** The rate to forecast `tokens` with: the newest measured cold read at half that depth or deeper, else none. */
|
|
19
|
+
export function forecastRate(store, model, tokens) {
|
|
20
|
+
return [...(store.get(model) ?? [])].reverse().find((s) => s.depth >= tokens / 2);
|
|
21
|
+
}
|
|
22
|
+
export function forecast(store, model, tokens) {
|
|
23
|
+
const s = forecastRate(store, model, tokens);
|
|
24
|
+
return s ? { model, tokens, ms: (tokens / s.rate) * 1000, rate: Math.round(s.rate) } : { model, tokens };
|
|
25
|
+
}
|
|
26
|
+
/** The Static line under /model: "the next message may re-read up to ~60.1k tokens on cortana (~3m 50s at its last
|
|
27
|
+
* measured 261 tok/s)". The parenthetical shortens below 100 cols and leaves below 60. */
|
|
28
|
+
export function forecastLine(f, cols) {
|
|
29
|
+
const head = `the next message may re-read up to ~${fmtTok(f.tokens)} tokens on ${f.model}`;
|
|
30
|
+
if (f.ms === undefined)
|
|
31
|
+
return fitSegments([seg(head)], cols);
|
|
32
|
+
const at = `~${fmtElapsed(f.ms)}`;
|
|
33
|
+
return fitSegments([seg(head), seg([`(${at} at its last measured ${f.rate} tok/s)`, `(${at})`], 2)], cols, { sep: " " });
|
|
34
|
+
}
|
|
35
|
+
/** The tail on the compaction receipt: "the next round reads up to ~42.4k fresh (~2m 40s at 261 tok/s)". */
|
|
36
|
+
export function forecastTail(f) {
|
|
37
|
+
return `the next round reads up to ~${fmtTok(f.tokens)} fresh${f.ms !== undefined ? ` (~${fmtElapsed(f.ms)} at ${f.rate} tok/s)` : ""}`;
|
|
38
|
+
}
|
|
39
|
+
/** The phase line's segments between Enter and the server's first progress chunk; the measured read line replaces them. */
|
|
40
|
+
export function expectSegs(f) {
|
|
41
|
+
return f.ms !== undefined
|
|
42
|
+
? [`expect up to ~${fmtTok(f.tokens)} new · ~${fmtElapsed(f.ms)} at ${f.model}'s last measured ${f.rate} tok/s`, `expect up to ~${fmtTok(f.tokens)} new · ~${fmtElapsed(f.ms)}`, `expect ~${fmtTok(f.tokens)} new`]
|
|
43
|
+
: [`expect up to ~${fmtTok(f.tokens)} new to read on ${f.model}`, `expect ~${fmtTok(f.tokens)} new`];
|
|
44
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The measured read line (TUI plan #1). While llama.cpp reads the prompt it sends prompt_progress {total, cache,
|
|
2
|
+
// processed, time_ms} after every batch; the shell used to keep only processed/total — and processed INCLUDES the cached
|
|
3
|
+
// prefix, so a warm read jumped to ~97% and a cold one gave no sense of speed. Every number here is the server's own:
|
|
4
|
+
// new = total − cache, done = processed − cache, the rate is Δdone over the server's clock (time_ms; the shell's clock
|
|
5
|
+
// only when a server omits it), and the ETA is recomputed per chunk, coarsened, and hidden before a rate exists.
|
|
6
|
+
import { cellWidth } from "./StatusRule.js";
|
|
7
|
+
import { fitSegments, seg } from "./fit.js";
|
|
8
|
+
import { fmtElapsed, fmtTok } from "./format.js";
|
|
9
|
+
const RING_MAX = 64;
|
|
10
|
+
const RATE_WINDOW_MS = 3000;
|
|
11
|
+
/** Add one chunk. A chunk whose total changed, or whose processed count went back, is a new request: the ring restarts. */
|
|
12
|
+
export function pushSample(ring, s) {
|
|
13
|
+
const last = ring[ring.length - 1];
|
|
14
|
+
if (!last || last.total !== s.total || s.processed < last.processed)
|
|
15
|
+
return [s];
|
|
16
|
+
const next = [...ring, s];
|
|
17
|
+
return next.length > RING_MAX ? next.slice(next.length - RING_MAX) : next;
|
|
18
|
+
}
|
|
19
|
+
function clock(a, b) {
|
|
20
|
+
return a.timeMs !== undefined && b.timeMs !== undefined ? [a.timeMs, b.timeMs] : [a.at, b.at];
|
|
21
|
+
}
|
|
22
|
+
const ETA_MIN_MS = 2500; // under this the read is all but done, and a floored "~5s left" would contradict its own count
|
|
23
|
+
function coarsen(ms) {
|
|
24
|
+
const s = ms / 1000;
|
|
25
|
+
const step = s < 60 ? 5 : 10;
|
|
26
|
+
return Math.max(step, Math.ceil(s / step) * step) * 1000;
|
|
27
|
+
}
|
|
28
|
+
/** Stats for the current request's ring. `origin` is when the request started, for a server that sends no time_ms. */
|
|
29
|
+
export function readStats(ring, origin) {
|
|
30
|
+
const last = ring[ring.length - 1];
|
|
31
|
+
if (!last || last.total <= 0)
|
|
32
|
+
return undefined;
|
|
33
|
+
const cache = Math.min(last.cache, last.total);
|
|
34
|
+
const fresh = last.total - cache;
|
|
35
|
+
const done = Math.max(0, Math.min(fresh, last.processed - cache));
|
|
36
|
+
let rate;
|
|
37
|
+
for (let i = ring.length - 2; i >= 0; i--) {
|
|
38
|
+
const [t0, t1] = clock(ring[i], last);
|
|
39
|
+
if (t1 - t0 < RATE_WINDOW_MS)
|
|
40
|
+
continue;
|
|
41
|
+
const gained = (last.processed - ring[i].processed);
|
|
42
|
+
if (gained > 0)
|
|
43
|
+
rate = gained / ((t1 - t0) / 1000);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
const left = Math.max(0, last.total - last.processed);
|
|
47
|
+
const leftMs = rate && left > 0 ? (left / rate) * 1000 : undefined;
|
|
48
|
+
const etaMs = leftMs !== undefined && leftMs >= ETA_MIN_MS ? coarsen(leftMs) : undefined;
|
|
49
|
+
const elapsedMs = last.timeMs ?? Math.max(0, last.at - (origin ?? ring[0].at));
|
|
50
|
+
return { total: last.total, cache, fresh, done, fraction: fresh > 0 ? done / fresh : 1, rate, etaMs, elapsedMs, complete: last.processed >= last.total };
|
|
51
|
+
}
|
|
52
|
+
function fmtEta(ms) {
|
|
53
|
+
const s = Math.round(ms / 1000);
|
|
54
|
+
if (s < 60)
|
|
55
|
+
return `${s}s`;
|
|
56
|
+
const r = s % 60;
|
|
57
|
+
return `${Math.floor(s / 60)}m${r ? ` ${r}s` : ""}`;
|
|
58
|
+
}
|
|
59
|
+
// The read meter has its own motion, unlike the compaction bar's ▰▱ (James, 11/04: "different than our compacting
|
|
60
|
+
// animation and unique"): braille cells fill like lines on a page — the same language as the read tool's glyph — and the
|
|
61
|
+
// cell at the head of the measured fill slowly writes itself in. The fill is measured; only the head cell moves.
|
|
62
|
+
const FULL = "⣿";
|
|
63
|
+
const EMPTY = "⣀";
|
|
64
|
+
const HEAD = ["⣀", "⣄", "⣤", "⣦", "⣶", "⣷"];
|
|
65
|
+
const HEAD_TICKS = 3; // shared-clock ticks per head step (~360 ms): calm, not a spinner
|
|
66
|
+
export function readMeter(fraction, width = 8, frame = 0) {
|
|
67
|
+
const f = Math.max(0, Math.min(1, fraction));
|
|
68
|
+
const full = Math.floor(f * width);
|
|
69
|
+
if (full >= width)
|
|
70
|
+
return FULL.repeat(width);
|
|
71
|
+
return FULL.repeat(full) + HEAD[Math.floor(frame / HEAD_TICKS) % HEAD.length] + EMPTY.repeat(width - full - 1);
|
|
72
|
+
}
|
|
73
|
+
const METER_MIN_COLS = 100;
|
|
74
|
+
/** The line under the spinner while the server reads: the meter (≥100 cols, and only when everything else fits) and
|
|
75
|
+
* the fitted text. Drop order as cols shrink: meter → the cache note → the rate → "of N new" → "esc to interrupt". */
|
|
76
|
+
export function readLine(st, cols, opts = {}) {
|
|
77
|
+
const segs = [];
|
|
78
|
+
if (st.cache > 0)
|
|
79
|
+
segs.push(seg(`reused ${fmtTok(st.cache)} cached`, 4));
|
|
80
|
+
if (st.complete) { // the whole prompt is read: say so, not "reading 30.5k of 30.5k" (review F8)
|
|
81
|
+
const read = `read ${fmtTok(st.fresh)} new`;
|
|
82
|
+
segs.push(seg(st.fresh > 0 ? [`${read} in ${fmtElapsed(st.elapsedMs)}`, read] : "nothing new to read", 2, true));
|
|
83
|
+
segs.push(seg(["waiting for the first token", "waiting"], 3, true));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
segs.push(seg([`reading ${fmtTok(st.done)} of ${fmtTok(st.fresh)} new`, `reading ${fmtTok(st.done)}/${fmtTok(st.fresh)}`], 2, true));
|
|
87
|
+
if (st.rate)
|
|
88
|
+
segs.push(seg(`${Math.round(st.rate)} tok/s`, 3));
|
|
89
|
+
if (st.etaMs !== undefined)
|
|
90
|
+
segs.push(seg(`~${fmtEta(st.etaMs)} left`));
|
|
91
|
+
}
|
|
92
|
+
if (st.cache === 0 && opts.model)
|
|
93
|
+
segs.push(seg(`nothing cached on ${opts.model}`, 4));
|
|
94
|
+
segs.push(...(opts.tail ?? [seg(["esc to interrupt", "esc"], 1, true)]));
|
|
95
|
+
if (cols >= METER_MIN_COLS) {
|
|
96
|
+
const meter = readMeter(st.fraction, 8, opts.frame ?? 0);
|
|
97
|
+
const lead = ` ${meter} `;
|
|
98
|
+
const unfitted = lead + segs.map((s) => s.forms[0]).join(" · ");
|
|
99
|
+
if (cellWidth(unfitted) <= cols - 1)
|
|
100
|
+
return { meter, text: fitSegments(segs, cols, { lead }).slice(lead.length) };
|
|
101
|
+
}
|
|
102
|
+
return { text: fitSegments(segs, cols, { lead: " " }).slice(2) };
|
|
103
|
+
}
|
|
104
|
+
const RATE_MIN_FRESH = 2048; // one llama.cpp batch
|
|
105
|
+
/** Reads shorter than this settle no receipt: the live line already said everything worth saying. */
|
|
106
|
+
export const RECEIPT_MIN_MS = 10_000;
|
|
107
|
+
/** The one dim line that settles into scrollback at the first token after a long read. */
|
|
108
|
+
export function readReceipt(st, cols, opts) {
|
|
109
|
+
const secs = st.elapsedMs / 1000;
|
|
110
|
+
// Under one batch of fresh tokens the server's clock is mostly restoring the cached prefix (live 11/04: "148 new
|
|
111
|
+
// tokens in 12s"), so an average over them would read as a 12 tok/s server. The time and the cache note say it.
|
|
112
|
+
const avg = secs > 0 && st.fresh >= RATE_MIN_FRESH ? Math.round(st.fresh / secs) : 0;
|
|
113
|
+
const head = `read ${fmtTok(st.fresh)} new tokens in ${fmtElapsed(st.elapsedMs)}`;
|
|
114
|
+
return fitSegments([
|
|
115
|
+
seg(avg ? [`${head} (${avg} tok/s)`, head] : head, 1, true),
|
|
116
|
+
seg(st.cache > 0 ? `${fmtTok(st.cache)} reused from cache` : opts.model ? `nothing was cached on ${opts.model}` : "nothing was cached", 3),
|
|
117
|
+
seg(`first token at ${fmtElapsed(opts.firstTokenMs)}`, 2),
|
|
118
|
+
], cols, { lead: " ▸ " });
|
|
119
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A finished sub-agent as ONE line (TUI plan #4). The old "done" path printed a 500-char dump — often the raw partial-
|
|
2
|
+
// report header written for the model — and the wake turn then printed every paragraph of every queued report as its
|
|
3
|
+
// own "⤷" line. Now: who, how it ended (and who stopped it), verify badge, what it wrote or gathered, and the first
|
|
4
|
+
// sentence of its report; the full text is one command away (/agents <name> report, or ctrl+o while it is the newest
|
|
5
|
+
// collapsed item). Static, but still fitted: the headline drops first, then the ledger, the verify badge and the
|
|
6
|
+
// duration; glyph · name · outcome · hint stay.
|
|
7
|
+
import { fitSegments, seg } from "./fit.js";
|
|
8
|
+
import { fmtElapsed } from "./format.js";
|
|
9
|
+
export function reportTone(a) {
|
|
10
|
+
if (a.endKind === "failed" || a.endKind === "error")
|
|
11
|
+
return "error";
|
|
12
|
+
if (a.endKind === "done" || (!a.endKind && a.status === "idle"))
|
|
13
|
+
return "done";
|
|
14
|
+
return "stopped";
|
|
15
|
+
}
|
|
16
|
+
const GLYPH = { done: "⤷", stopped: "■", error: "✗" };
|
|
17
|
+
/** The command that appends this agent's full report. */
|
|
18
|
+
export function reportCommand(a) {
|
|
19
|
+
return `/agents ${(a.name ?? a.id).toLowerCase()} report`;
|
|
20
|
+
}
|
|
21
|
+
function outcome(a) {
|
|
22
|
+
const dur = a.durationMs != null ? fmtElapsed(a.durationMs) : undefined;
|
|
23
|
+
const rounds = a.round ? ` after ${a.round} round${a.round === 1 ? "" : "s"}` : "";
|
|
24
|
+
switch (a.endKind) {
|
|
25
|
+
case "stopped": {
|
|
26
|
+
const why = a.endReason ?? "stopped";
|
|
27
|
+
return [...new Set([`${why}${rounds}`, why, why.replace(/ \(stop_agent\)$/, ""), "stopped"])];
|
|
28
|
+
}
|
|
29
|
+
case "stalled": return [`${a.endReason ?? "stalled"}${rounds}`, "stalled"];
|
|
30
|
+
case "engine": return [`stopped by the engine: ${a.endReason ?? "no progress"}`, "stopped by the engine"];
|
|
31
|
+
case "failed":
|
|
32
|
+
case "error": return [a.endReason ?? "errored", "errored"];
|
|
33
|
+
default: return dur ? [`done in ${dur}`, "done"] : ["done"];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function ledger(a) {
|
|
37
|
+
if (a.written?.length)
|
|
38
|
+
return `wrote ${a.written.slice(-2).map((p) => p.split("/").pop()).join(", ")}${a.written.length > 2 ? ` +${a.written.length - 2}` : ""}`;
|
|
39
|
+
return a.endKind !== "done" && a.headline?.startsWith("partial:") ? a.headline : undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The fitted line and where its parts sit, so the renderer can color the glyph, the name and the hint. */
|
|
42
|
+
export function reportLine(a, cols) {
|
|
43
|
+
const tone = reportTone(a);
|
|
44
|
+
const name = a.name ?? a.id;
|
|
45
|
+
// The exact command, never a bare "ctrl+o": ctrl+o walks newest first, so on an older line it reaches a newer item.
|
|
46
|
+
const hint = reportCommand(a);
|
|
47
|
+
const segs = [
|
|
48
|
+
seg([`${name.padEnd(6)} ${a.title ?? "sub-agent"}`, name], 2.5, true),
|
|
49
|
+
seg(outcome(a), 1, true),
|
|
50
|
+
...(a.verified === true ? [seg("✓ verified", 3)] : a.verified === false ? [seg("✗ unverified", 3)] : []),
|
|
51
|
+
...(ledger(a) ? [seg(ledger(a), 4)] : []),
|
|
52
|
+
...(tone === "done" && a.headline ? [seg(`"${a.headline}"`, 5)] : []),
|
|
53
|
+
seg([hint, "ctrl+o"], 0.5, true), // the outcome's detail gives way before the command does
|
|
54
|
+
];
|
|
55
|
+
const line = fitSegments(segs, cols, { lead: `${GLYPH[tone]} ` });
|
|
56
|
+
const shown = line.endsWith(hint) ? hint : line.endsWith("ctrl+o") ? "ctrl+o" : "";
|
|
57
|
+
return { tone, line, hint: shown };
|
|
58
|
+
}
|
|
59
|
+
/** The wake turn's one hand-off line, instead of one line per paragraph of every report. */
|
|
60
|
+
export function deliveredLine(owners, model, cols) {
|
|
61
|
+
return fitSegments([seg(`delivered to ${model}: ${owners.join(" · ")}`)], cols, { lead: "⤷ " });
|
|
62
|
+
}
|
package/dist/ui/slashCommands.js
CHANGED
|
@@ -16,7 +16,7 @@ export const SLASH_COMMANDS = [
|
|
|
16
16
|
{ name: "remote", description: "remote control: let a follower attach and drive this session", args: "[on|off]" },
|
|
17
17
|
{ name: "pair", description: "pair a phone to drive this session — shows a QR for the Operator app (end-to-end encrypted)" },
|
|
18
18
|
{ name: "plan", description: "plan mode: read-only research + propose a plan (/plan again executes)" },
|
|
19
|
-
{ name: "mode", description: "set operating mode:
|
|
19
|
+
{ name: "mode", description: "set operating mode: autonomous · manual · plan · gated", args: "[auto|manual|plan|gated]" },
|
|
20
20
|
{ name: "think", description: "toggle extended reasoning (think before answering)" },
|
|
21
21
|
{ name: "ultrathink", description: "toggle deep, exhaustive reasoning for hard problems" },
|
|
22
22
|
{ name: "agents", description: "detailed sub-agent status: running/queued/done/errored + metrics" },
|
package/dist/ui/theme.js
CHANGED
|
@@ -19,6 +19,7 @@ const PALETTE = {
|
|
|
19
19
|
success: { hex: "#5fd38a", ansi: "green", hc: "greenBright" }, // done / verified
|
|
20
20
|
error: { hex: "#ff6b6b", ansi: "red", hc: "redBright" }, // failed / unverified
|
|
21
21
|
warn: { hex: "#e8c14d", ansi: "yellow", hc: "yellowBright" }, // malformed / caution
|
|
22
|
+
blocked: { hex: "#c9a25a", ansi: "yellow", hc: "yellowBright" }, // muted amber: a call the engine refused (⊘) — not a failure, not a success
|
|
22
23
|
running: { hex: "#e8a33d", ansi: "yellow", hc: "yellowBright" }, // in-flight amber (tool running, star heartbeat)
|
|
23
24
|
starBright: { hex: "#ffe2a0", ansi: "yellowBright", hc: "whiteBright" }, // the star's bright burst
|
|
24
25
|
textBright: { hex: "#ffffff", ansi: "whiteBright", hc: "whiteBright" }, // emphasized foreground
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The shell's turn order (cli.tsx). One turn at a time: a turn asked for while a turn or a compaction runs waits in the
|
|
2
|
+
// pending list as an after-turn message — never a second Session.send, which threw "in flight", lost the text and marked
|
|
3
|
+
// the shell idle under the running turn (review F2). When a turn or a compaction ends the drain runs what waited:
|
|
4
|
+
// staged commands one by one, each on its own, then one text turn with the steers the turn never reached and the
|
|
5
|
+
// after-turn messages. A sub-agent report, or a job notice in wake mode, starts a turn only when nothing waits;
|
|
6
|
+
// otherwise it rides on the next. What a compaction was started FOR ("compact, then continue", /model's compact-first)
|
|
7
|
+
// is its follow-up: it runs when the compaction ends, before the drain can start anything — never chained on the
|
|
8
|
+
// promise. Free of React and I/O: the shell's refs come in as `fx`, so the order is tested without a TTY.
|
|
9
|
+
import { drainPlan } from "./pending.js";
|
|
10
|
+
export function createTurnFlow(fx) {
|
|
11
|
+
let draining = false; // a staged /compact ends in its own drain call: that one must not run anything
|
|
12
|
+
let followUp;
|
|
13
|
+
const flow = {
|
|
14
|
+
send: (text, opts = {}) => {
|
|
15
|
+
if (fx.idle()) {
|
|
16
|
+
fx.start(text, opts);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!opts.wake && text)
|
|
20
|
+
fx.setPending([...fx.pending(), { kind: "after", text }]);
|
|
21
|
+
},
|
|
22
|
+
drain: () => {
|
|
23
|
+
if (draining)
|
|
24
|
+
return;
|
|
25
|
+
const { commands, text } = drainPlan(fx.pending());
|
|
26
|
+
if (!commands.length && !text) {
|
|
27
|
+
flow.wake();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
fx.setPending([]);
|
|
31
|
+
draining = true;
|
|
32
|
+
void (async () => {
|
|
33
|
+
try {
|
|
34
|
+
for (const c of commands)
|
|
35
|
+
await fx.command(c);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
draining = false;
|
|
39
|
+
}
|
|
40
|
+
// What was typed while the commands ran waits behind the text the turn left, and is drained with it — it used to
|
|
41
|
+
// sit on screen unsent, blocking every wake (review F4). A command that started a turn of its own
|
|
42
|
+
// (/deep-research) keeps both for after that turn, whose drain sends them; never a steer into it.
|
|
43
|
+
const typed = fx.pending();
|
|
44
|
+
if (typed.length || !fx.idle()) {
|
|
45
|
+
fx.setPending([...(text ? [{ kind: "after", text }] : []), ...typed]);
|
|
46
|
+
if (fx.idle())
|
|
47
|
+
flow.drain();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (text)
|
|
51
|
+
fx.submit(text);
|
|
52
|
+
else
|
|
53
|
+
flow.wake();
|
|
54
|
+
})();
|
|
55
|
+
},
|
|
56
|
+
wake: () => {
|
|
57
|
+
if (!fx.wakeDue())
|
|
58
|
+
return;
|
|
59
|
+
if (!fx.idle() || fx.pending().length)
|
|
60
|
+
return;
|
|
61
|
+
flow.send("", { wake: true });
|
|
62
|
+
},
|
|
63
|
+
afterCompaction: (then) => { followUp = then; },
|
|
64
|
+
compacted: () => {
|
|
65
|
+
const then = followUp;
|
|
66
|
+
followUp = undefined;
|
|
67
|
+
then?.();
|
|
68
|
+
flow.drain();
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
return flow;
|
|
72
|
+
}
|