@0perator/operator 0.1.62 → 0.1.154
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/CHANGELOG.md +1035 -0
- package/LICENSE +19 -0
- package/dist/acp/agent.js +103 -0
- package/dist/acp/run.js +23 -0
- package/dist/auth/client.js +4 -1
- package/dist/auth/login-intent.js +12 -0
- package/dist/autonomy/board-run.js +65 -0
- package/dist/autonomy/board.js +83 -0
- package/dist/autonomy/dream.js +71 -0
- package/dist/autonomy/headless.js +70 -0
- package/dist/autonomy/index.js +260 -0
- package/dist/autonomy/keepawake.js +84 -0
- package/dist/autonomy/loop.js +82 -0
- package/dist/autonomy/reporter.js +54 -0
- package/dist/autonomy/routine-run.js +25 -0
- package/dist/autonomy/routines.js +173 -0
- package/dist/autonomy/session-factory.js +61 -0
- package/dist/background/index.js +275 -20
- package/dist/background/worktree.js +62 -0
- package/dist/cli.js +518 -95
- package/dist/config/brand.js +81 -0
- package/dist/config/operator-harness.js +86 -0
- package/dist/config/persona.js +174 -0
- package/dist/config/settings.js +98 -9
- package/dist/engine/agent.js +447 -51
- package/dist/engine/aurora.js +180 -64
- package/dist/engine/compaction.js +97 -5
- package/dist/engine/grandmaster.js +69 -10
- package/dist/engine/router-adapter.js +3 -0
- package/dist/engine/selfheal.js +35 -0
- package/dist/engine/verify-gate.js +81 -0
- package/dist/mcp/index.js +1 -1
- package/dist/permissions/index.js +13 -7
- package/dist/router/models.js +1 -1
- package/dist/router/router.js +46 -7
- package/dist/selfimprove/index.js +88 -0
- package/dist/services/preflight.js +42 -1
- package/dist/session.js +239 -22
- package/dist/telemetry/events.js +9 -0
- package/dist/tools/executor.js +62 -24
- package/dist/tools/git-status.js +71 -0
- package/dist/tools/mutating.js +9 -0
- package/dist/tools/registry.js +247 -26
- package/dist/tools/result-cap.js +23 -0
- package/dist/tools/searxng.js +42 -2
- package/dist/tools/shell-context.js +17 -0
- package/dist/ui/ActivitySpinner.js +6 -5
- package/dist/ui/App.js +23 -5
- package/dist/ui/AuthScreen.js +1 -1
- package/dist/ui/BgPanel.js +60 -5
- package/dist/ui/Composer.js +135 -13
- package/dist/ui/Header.js +6 -4
- package/dist/ui/InputRule.js +2 -1
- package/dist/ui/Markdown.js +69 -10
- package/dist/ui/Masthead.js +6 -4
- package/dist/ui/PlanPane.js +23 -0
- package/dist/ui/QuestionPrompt.js +22 -8
- package/dist/ui/StatsCard.js +15 -0
- package/dist/ui/StatusRule.js +13 -4
- package/dist/ui/SummaryCard.js +18 -0
- package/dist/ui/Table.js +114 -0
- package/dist/ui/ThinkingSpinner.js +6 -4
- package/dist/ui/ToolBatch.js +12 -0
- package/dist/ui/ToolStep.js +12 -4
- package/dist/ui/Transcript.js +30 -6
- package/dist/ui/chart.js +34 -0
- package/dist/ui/editdiff.js +84 -0
- package/dist/ui/highlight.js +89 -0
- package/dist/ui/osc.js +32 -0
- package/dist/ui/planExit.js +26 -0
- package/dist/ui/term.js +16 -0
- package/dist/ui/theme.js +60 -0
- package/dist/ui/tree.js +71 -0
- package/dist/util/slash.js +15 -0
- package/dist/util/throttle.js +28 -0
- package/package.json +11 -2
package/dist/ui/AuthScreen.js
CHANGED
|
@@ -13,5 +13,5 @@ export function AuthScreen({ version, ctxWindow, authBase, pending, error, onCho
|
|
|
13
13
|
else if (key.return || c === "g")
|
|
14
14
|
onChoice("guest");
|
|
15
15
|
});
|
|
16
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Masthead, { info: `Operator${ctxWindow
|
|
16
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Masthead, { info: `Operator${ctxWindow ? ` · ${ctxWindow >= 1_000_000 ? "1M" : `${Math.round(ctxWindow / 1024)}K`}` : ""} · v${version}` }), _jsx(Box, { marginTop: 1, flexDirection: "column", paddingLeft: 1, children: pending ? (_jsxs(_Fragment, { children: [_jsxs(Text, { children: ["Signing in \u2014 open ", _jsx(Text, { color: "cyanBright", children: pending.url })] }), _jsxs(Text, { children: ["and enter code ", _jsx(Text, { bold: true, color: "whiteBright", children: pending.userCode })] }), _jsx(Text, { dimColor: true, children: "Waiting for approval in your browser\u2026 (Esc to cancel)" })] })) : (_jsxs(_Fragment, { children: [_jsx(Text, { color: "whiteBright", children: "Welcome to Operator." }), _jsx(Text, { dimColor: true, children: "A local terminal coding agent on your own model." }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: " s" }), " Sign in ", _jsx(Text, { dimColor: true, children: "\u2014 connect your account (browser approval)" })] }), _jsxs(Text, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: " u" }), " Create account ", _jsxs(Text, { dimColor: true, children: ["\u2014 register at ", authBase.replace(/^https?:\/\//, "")] })] }), _jsxs(Text, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: " \u21B5" }), " Continue as guest ", _jsx(Text, { dimColor: true, children: "\u2014 no account needed; sign in later with /login" })] })] }), error ? _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "red", children: error }) }) : null] })) })] }));
|
|
17
17
|
}
|
package/dist/ui/BgPanel.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
3
|
import { OrbitGlyph } from "./ActivitySpinner.js";
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
import { theme } from "./theme.js";
|
|
5
|
+
const GLYPH = { queued: "◌", working: "●", idle: "✓", stopped: "✗" };
|
|
6
|
+
const COLOR = { queued: theme.muted, working: theme.running, idle: theme.success, stopped: theme.error };
|
|
7
|
+
const DISPLAY_STATUS = { queued: "queued", working: "running", idle: "done", stopped: "errored" };
|
|
6
8
|
const toks = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`);
|
|
7
9
|
// Live per-agent metrics: tokens generated + elapsed. While working, elapsed is derived from
|
|
8
10
|
// startedAt at render time (updates each round tick); once finished, the wall time is frozen.
|
|
@@ -21,12 +23,36 @@ function metrics(a) {
|
|
|
21
23
|
// verified badge + malformed warning. Terminals have no hover, so the verify failure
|
|
22
24
|
// reason is shown inline (capped) instead of as a tooltip; success collapses to a bare ✓.
|
|
23
25
|
const cap = (s, n = 60) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
|
|
26
|
+
// Humanize a tool name into the verb an owner reads at a glance ("editing cli.py", not "file_edit cli.py").
|
|
27
|
+
// Falls back to the raw name (underscores→spaces) for anything not in the table, so a new/MCP tool never
|
|
28
|
+
// prints blank.
|
|
29
|
+
const ACTIVITY_VERB = {
|
|
30
|
+
file_read: "reading", file_write: "writing", file_edit: "editing", bash: "running", shell_exec: "running",
|
|
31
|
+
shell_background: "running", bash_output: "checking", search_tool: "searching", grep: "searching",
|
|
32
|
+
task_add: "planning", task_update: "planning", task_clear: "planning", spawn_agent: "delegating",
|
|
33
|
+
message_agent: "messaging", web_search: "searching web", web_fetch: "fetching",
|
|
34
|
+
};
|
|
35
|
+
const humanStep = (name) => ACTIVITY_VERB[name] ?? name.replace(/_/g, " ");
|
|
36
|
+
// One short phrase for what THIS round is actually doing, next to "round N" — the round counter alone is
|
|
37
|
+
// just a number; this is the "editing cli.py" a glance needs. Prefers the in-flight tool call, then falls
|
|
38
|
+
// back to the live reasoning tail, then the last settled step, so it's never blank while the agent is
|
|
39
|
+
// visibly doing something.
|
|
40
|
+
export function roundActivity(a) {
|
|
41
|
+
const steps = a.steps ?? [];
|
|
42
|
+
const running = [...steps].reverse().find((s) => s.running);
|
|
43
|
+
if (running)
|
|
44
|
+
return `${humanStep(running.name)}${running.arg ? ` ${running.arg}` : ""}`;
|
|
45
|
+
if (a.thought)
|
|
46
|
+
return a.thought.replace(/^…/, "").trim();
|
|
47
|
+
const last = steps[steps.length - 1];
|
|
48
|
+
return last ? `${humanStep(last.name)}${last.arg ? ` ${last.arg}` : ""}` : undefined;
|
|
49
|
+
}
|
|
24
50
|
function GrandmasterLine({ a }) {
|
|
25
51
|
const hasModel = a.model != null || a.lane != null;
|
|
26
52
|
const hasVerify = a.verified != null;
|
|
27
53
|
if (!hasModel && !hasVerify && !a.malformed)
|
|
28
54
|
return null;
|
|
29
|
-
return (_jsxs(Box, { paddingLeft: 2, children: [hasModel && _jsxs(Text, { dimColor: true, children: [a.model ?? "?", a.lane != null ? ` · ${a.lane}` : ""] }), hasVerify && (_jsxs(Text, { color: a.verified ?
|
|
55
|
+
return (_jsxs(Box, { paddingLeft: 2, children: [hasModel && _jsxs(Text, { dimColor: true, children: [a.model ?? "?", a.lane != null ? ` · ${a.lane}` : ""] }), hasVerify && (_jsxs(Text, { color: a.verified ? theme.success : theme.error, children: [hasModel ? " " : "", a.verified ? "✓ verified" : `✗ unverified${a.verifyDetail ? `: ${cap(a.verifyDetail)}` : ""}`] })), a.malformed ? _jsxs(Text, { color: theme.warn, children: [(hasModel || hasVerify) ? " " : "", "\u26A0 malformed"] }) : null] }));
|
|
30
56
|
}
|
|
31
57
|
// Live activity for a WORKING child (SPEC §7 observability): the tools it is running (in-flight
|
|
32
58
|
// marked with …) and the tail of its current reasoning — so the owner sees thoughts / steps / reads
|
|
@@ -43,8 +69,37 @@ function ActivityLines({ a }) {
|
|
|
43
69
|
return null;
|
|
44
70
|
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 2, children: [stepLine ? _jsxs(Text, { dimColor: true, children: ["\u21B3 ", cap(stepLine, 72)] }) : null, a.thought ? _jsxs(Text, { dimColor: true, children: ["⋮ ", cap(a.thought, 72)] }) : null] }));
|
|
45
71
|
}
|
|
46
|
-
|
|
72
|
+
// Cap how many agent rows the DYNAMIC panel renders. Each agent is ~3 lines; a full fan-out (6–8 agents)
|
|
73
|
+
// makes the non-Static frame tall AND it re-renders on every sub-agent token — so when it sits near the
|
|
74
|
+
// terminal bottom, Ink's inline redraw loses its anchor and orphans a STALE copy of the whole frame into
|
|
75
|
+
// scrollback on each re-render (the duplicated-plan "mess", v0.1.104). Showing the active few + an overflow
|
|
76
|
+
// count keeps the frame short so the in-place redraw stays reliable. Working agents rank first.
|
|
77
|
+
const BG_MAX_VISIBLE = 3;
|
|
78
|
+
const bgRank = (s) => (s === "working" ? 0 : s === "queued" ? 2 : 1);
|
|
79
|
+
export function BgPanel({ agents, title = "sub-agents" }) {
|
|
47
80
|
if (agents.length === 0)
|
|
48
81
|
return null;
|
|
49
|
-
|
|
82
|
+
// Borderless: DYNAMIC-region pane. A box border here orphans its rows into scrollback each time the
|
|
83
|
+
// Static transcript grows during a long turn (the v0.1.92 line-flood). Instead, a designated region:
|
|
84
|
+
// a top-margin gap detaches it from the plan list above, and a labeled full-width RULE (a single Text
|
|
85
|
+
// line — no border rows to orphan) heads it, so sub-agents read as their own zone instead of crammed
|
|
86
|
+
// under the plan. Rule width uses termCols() (guarded against the minimized-terminal 0).
|
|
87
|
+
const shown = [...agents].sort((a, b) => bgRank(a.status) - bgRank(b.status)).slice(0, BG_MAX_VISIBLE);
|
|
88
|
+
const hidden = agents.length - shown.length;
|
|
89
|
+
// Header states running vs queued so a throttled queue (2 run at a time on the shared endpoint, the rest
|
|
90
|
+
// wait for a slot) reads as "progressing", not "stuck/broken". Working first, then queued.
|
|
91
|
+
const running = agents.filter((a) => a.status === "working").length;
|
|
92
|
+
const queued = agents.filter((a) => a.status === "queued").length;
|
|
93
|
+
const done = agents.filter((a) => a.status === "idle").length;
|
|
94
|
+
const errored = agents.filter((a) => a.status === "stopped").length;
|
|
95
|
+
const counts = [running ? `${running} running` : "", queued ? `${queued} queued` : "", done ? `${done} done` : "", errored ? `${errored} errored` : ""].filter(Boolean).join(" · ");
|
|
96
|
+
const label = `${title}${counts ? ` · ${counts}` : ` (${agents.length})`}`;
|
|
97
|
+
// A designated, bounded zone (per request): a dim rounded box with the section label as its first line,
|
|
98
|
+
// detached from the plan list above by a top margin — sub-agents read as their own region instead of
|
|
99
|
+
// crammed under the plan. TRADE-OFF: a border in the DYNAMIC frame can orphan its top/bottom rows into
|
|
100
|
+
// scrollback while the Static transcript grows mid-turn (the v0.1.92 line-flood). Mitigated by keeping the
|
|
101
|
+
// frame SHORT — BG_MAX_VISIBLE caps rows, activity lines are capped — so the box stays a few rows tall.
|
|
102
|
+
// If stray border rows ever reappear on a very long turn, drop `borderStyle`/`borderColor` for the
|
|
103
|
+
// borderless column (the label line alone still heads it).
|
|
104
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsx(Text, { dimColor: true, children: label }), shown.map((a) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { justifyContent: "space-between", children: [_jsxs(Text, { children: [a.status === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: COLOR[a.status], children: GLYPH[a.status] }), " ", a.label, a.round != null ? ` · round ${a.round}` : "", a.status === "working" && roundActivity(a) ? _jsxs(Text, { color: theme.accent, children: [" \u00B7 ", cap(roundActivity(a), 28)] }) : null] }), _jsx(Text, { dimColor: true, children: (() => { const m = metrics(a); const ds = DISPLAY_STATUS[a.status]; return m ? `${m} · ${ds}` : ds; })() })] }), _jsx(ActivityLines, { a: a }), _jsx(GrandmasterLine, { a: a }), a.status === "idle" && _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "result posted \u2014 scroll up or /agents to review" }) }), a.status === "stopped" && _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: "errored \u2014 check transcript for details" }) })] }, a.id))), hidden > 0 ? _jsx(Text, { dimColor: true, children: ` +${hidden} more running` }) : null] }));
|
|
50
105
|
}
|
package/dist/ui/Composer.js
CHANGED
|
@@ -2,8 +2,11 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
// Sticky multi-line input (SPEC §6). Three behaviors that are easy to get wrong and are
|
|
3
3
|
// explicitly called out in the contract:
|
|
4
4
|
// 1. Bracketed paste: the terminal wraps a paste in \x1b[200~ ... \x1b[201~. We intercept the
|
|
5
|
-
// raw stdin bytes (below Ink's own per-keystroke useInput dispatch) so a paste
|
|
6
|
-
// collapsed "[Pasted #N]"
|
|
5
|
+
// raw stdin bytes (below Ink's own per-keystroke useInput dispatch) so a multi-line/long paste
|
|
6
|
+
// lands as ONE collapsed "[Pasted #N · L lines]" chip instead of flooding useInput with one
|
|
7
|
+
// call per character. The chip is DISPLAY ONLY — the real payload is kept in pasteStoreRef and
|
|
8
|
+
// re-expanded into the outgoing text on submit (expandPastes), so the model receives the full
|
|
9
|
+
// paste, not the label. Short single-line pastes are shown inline (no chip) — they read fine.
|
|
7
10
|
// 2. Non-bracketed paste: on a terminal without bracketed-paste, a multi-line paste arrives as
|
|
8
11
|
// plain bytes, each embedded "\n" indistinguishable from the user pressing Enter. Submitting
|
|
9
12
|
// on the first embedded newline would send a fraction of the paste. Fix: on Enter, peek
|
|
@@ -16,10 +19,13 @@ import { Box, Text, useInput, useStdin } from "ink";
|
|
|
16
19
|
import { InputHistory } from "./useInputHistory.js";
|
|
17
20
|
const PASTE_START = "\x1b[200~";
|
|
18
21
|
const PASTE_END = "\x1b[201~";
|
|
19
|
-
export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended, onCycleMode,
|
|
22
|
+
export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended, onCycleMode, prompt = "› " }) {
|
|
20
23
|
const [value, setValue] = useState("");
|
|
21
24
|
const pasteCountRef = useRef(0);
|
|
22
25
|
const pasteBufRef = useRef(null); // non-null while inside a bracketed paste
|
|
26
|
+
const pasteGuardRef = useRef(false); // true for the ENTIRE tick a paste is being committed — useInput must not echo
|
|
27
|
+
const pasteTimerRef = useRef(null); // idle fallback for unterminated pastes
|
|
28
|
+
const pasteStoreRef = useRef(new Map()); // chip #N -> real pasted payload
|
|
23
29
|
const historyRef = useRef(null);
|
|
24
30
|
if (!historyRef.current)
|
|
25
31
|
historyRef.current = new InputHistory();
|
|
@@ -29,43 +35,80 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
|
|
|
29
35
|
if (!isRawModeSupported || !stdin)
|
|
30
36
|
return;
|
|
31
37
|
process.stdout.write("\x1b[?2004h"); // enable bracketed paste mode
|
|
38
|
+
const armPasteTimeout = () => {
|
|
39
|
+
if (pasteTimerRef.current)
|
|
40
|
+
clearTimeout(pasteTimerRef.current);
|
|
41
|
+
pasteTimerRef.current = setTimeout(() => {
|
|
42
|
+
pasteTimerRef.current = null;
|
|
43
|
+
if (pasteBufRef.current !== null)
|
|
44
|
+
commitPaste(); // flush whatever accumulated
|
|
45
|
+
}, 50);
|
|
46
|
+
};
|
|
47
|
+
const clearPasteTimeout = () => {
|
|
48
|
+
if (pasteTimerRef.current) {
|
|
49
|
+
clearTimeout(pasteTimerRef.current);
|
|
50
|
+
pasteTimerRef.current = null;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
32
53
|
const onData = (chunk) => {
|
|
33
54
|
const s = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
34
55
|
if (pasteBufRef.current !== null) {
|
|
35
56
|
const end = s.indexOf(PASTE_END);
|
|
36
57
|
if (end === -1) {
|
|
37
58
|
pasteBufRef.current += s;
|
|
59
|
+
armPasteTimeout(); // reset idle clock — more chunks expected
|
|
38
60
|
return;
|
|
39
61
|
}
|
|
62
|
+
clearPasteTimeout();
|
|
40
63
|
pasteBufRef.current += s.slice(0, end);
|
|
41
64
|
commitPaste();
|
|
42
65
|
return;
|
|
43
66
|
}
|
|
44
67
|
const start = s.indexOf(PASTE_START);
|
|
45
68
|
if (start === -1)
|
|
46
|
-
return;
|
|
69
|
+
return; // normal keystroke chunk — pass through to useInput
|
|
70
|
+
pasteGuardRef.current = true; // block useInput for the rest of this tick
|
|
47
71
|
const buf = s.slice(start + PASTE_START.length);
|
|
48
72
|
const end = buf.indexOf(PASTE_END);
|
|
49
|
-
|
|
50
|
-
|
|
73
|
+
if (end !== -1) {
|
|
74
|
+
pasteBufRef.current = buf.slice(0, end);
|
|
51
75
|
commitPaste();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
pasteBufRef.current = buf; // waiting for end marker in a later chunk
|
|
79
|
+
armPasteTimeout();
|
|
80
|
+
}
|
|
52
81
|
};
|
|
53
82
|
const commitPaste = () => {
|
|
83
|
+
const body = (pasteBufRef.current ?? "").replace(/\r\n?/g, "\n");
|
|
54
84
|
pasteBufRef.current = null;
|
|
85
|
+
// pasteGuardRef stays true until the next microtask — Ink's useInput calls for THIS chunk are
|
|
86
|
+
// still pending in the same event-loop tick, so they'll see the guard and return early.
|
|
87
|
+
queueMicrotask(() => { pasteGuardRef.current = false; });
|
|
88
|
+
const { inline, label } = pasteChip(body);
|
|
89
|
+
if (inline) {
|
|
90
|
+
setValue((v) => v + body);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
55
93
|
pasteCountRef.current += 1;
|
|
56
|
-
|
|
94
|
+
const n = pasteCountRef.current;
|
|
95
|
+
pasteStoreRef.current.set(n, body);
|
|
96
|
+
setValue((v) => `${v}[Pasted #${n} · ${label}]`);
|
|
57
97
|
};
|
|
58
|
-
stdin
|
|
98
|
+
// prependListener: our handler MUST fire before Ink's stdin handler so pasteBufRef/pasteGuardRef
|
|
99
|
+
// are set by the time useInput runs — otherwise Ink echoes the raw marker bytes + paste content.
|
|
100
|
+
stdin.prependListener("data", onData);
|
|
59
101
|
return () => {
|
|
60
102
|
stdin.off("data", onData);
|
|
103
|
+
clearPasteTimeout();
|
|
61
104
|
process.stdout.write("\x1b[?2004l");
|
|
62
105
|
};
|
|
63
106
|
}, [stdin, isRawModeSupported]);
|
|
64
107
|
useInput((ch, key) => {
|
|
65
108
|
if (suspended)
|
|
66
109
|
return; // an approval prompt owns the keyboard — don't consume or echo keystrokes
|
|
67
|
-
if (pasteBufRef.current !== null)
|
|
68
|
-
return; //
|
|
110
|
+
if (pasteBufRef.current !== null || pasteGuardRef.current)
|
|
111
|
+
return; // paste bytes owned by onData
|
|
69
112
|
// Shift+Tab cycles the operating mode (Claude-Code parity). Terminals send backtab as ESC[Z, which
|
|
70
113
|
// Ink surfaces as key.tab + key.shift. Handled before text so it never lands a character in the draft.
|
|
71
114
|
if (key.tab && key.shift) {
|
|
@@ -85,10 +128,12 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
|
|
|
85
128
|
setValue((v) => `${v}\n`); // more bytes queued — this Enter is mid-paste, not a real submit
|
|
86
129
|
return;
|
|
87
130
|
}
|
|
88
|
-
|
|
131
|
+
const text = expandPastes(value, pasteStoreRef.current); // chips -> real payload; the model gets the full paste, not "[Pasted #1]"
|
|
132
|
+
if (!text.trim())
|
|
89
133
|
return;
|
|
90
|
-
const text = value;
|
|
91
134
|
setValue("");
|
|
135
|
+
pasteStoreRef.current.clear(); // payloads consumed; restart chip numbering for the next message
|
|
136
|
+
pasteCountRef.current = 0;
|
|
92
137
|
historyRef.current.push(text);
|
|
93
138
|
if (disabled && onQueue)
|
|
94
139
|
onQueue(text);
|
|
@@ -126,9 +171,86 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
|
|
|
126
171
|
// Surface any image/video paths in the draft as attachment chips so the user can see multiple
|
|
127
172
|
// media are attached (dragged/pasted paths land in the text). De-duped, basename only.
|
|
128
173
|
const attachments = Array.from(new Set(value.match(MEDIA_RE) ?? []));
|
|
129
|
-
return (_jsxs(Box, { flexDirection: "column", children: [lines.map((line, i) => (_jsxs(Text, { children: [i === 0 ? prompt : " ", line, i === lines.length - 1 ? "▌" : ""] }, i))), attachments.length > 0 && (_jsx(Text, { dimColor: true, children: " " + attachments.map((a) => `${VIDEO_RE.test(a) ? "▷ vid" : "◇ img"}:${a.split("/").pop()}`).join(" ") }))
|
|
174
|
+
return (_jsxs(Box, { flexDirection: "column", children: [lines.map((line, i) => (_jsxs(Text, { children: [i === 0 ? prompt : " ", line, i === lines.length - 1 ? "▌" : ""] }, i))), attachments.length > 0 && (_jsx(Text, { dimColor: true, children: " " + attachments.map((a) => `${VIDEO_RE.test(a) ? "▷ vid" : "◇ img"}:${a.split("/").pop()}`).join(" ") }))] }));
|
|
130
175
|
}
|
|
131
176
|
// Recognize media file paths in the draft. IMAGE covers the common still formats, VIDEO the moving
|
|
132
177
|
// ones; a path matching VIDEO is chipped as video, otherwise image. Extensions only — no I/O.
|
|
133
178
|
const MEDIA_RE = /\S+\.(?:png|jpe?g|gif|webp|bmp|svg|heic|heif|mp4|mov|webm|mkv|avi|m4v)\b/gi;
|
|
134
179
|
const VIDEO_RE = /\.(?:mp4|mov|webm|mkv|avi|m4v)$/i;
|
|
180
|
+
// --- Paste state machine (pure, exported for tests) -----------------------------------------------
|
|
181
|
+
// Extracted so the split-chunk, guard, and timeout logic can be tested without React/Ink.
|
|
182
|
+
export class PasteStateMachine {
|
|
183
|
+
buf = null;
|
|
184
|
+
guard = false;
|
|
185
|
+
timer = null;
|
|
186
|
+
count = 0;
|
|
187
|
+
store = new Map();
|
|
188
|
+
committed = [];
|
|
189
|
+
feed(chunk) {
|
|
190
|
+
if (this.buf !== null) {
|
|
191
|
+
const end = chunk.indexOf(PASTE_END);
|
|
192
|
+
if (end === -1) {
|
|
193
|
+
this.buf += chunk;
|
|
194
|
+
this.armTimeout();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.clearTimeout();
|
|
198
|
+
this.buf += chunk.slice(0, end);
|
|
199
|
+
this.commit();
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const start = chunk.indexOf(PASTE_START);
|
|
203
|
+
if (start === -1)
|
|
204
|
+
return;
|
|
205
|
+
this.guard = true;
|
|
206
|
+
const after = chunk.slice(start + PASTE_START.length);
|
|
207
|
+
const end = after.indexOf(PASTE_END);
|
|
208
|
+
if (end !== -1) {
|
|
209
|
+
this.buf = after.slice(0, end);
|
|
210
|
+
this.commit();
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this.buf = after;
|
|
214
|
+
this.armTimeout();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
commit() {
|
|
218
|
+
const body = (this.buf ?? "").replace(/\r\n?/g, "\n");
|
|
219
|
+
this.buf = null;
|
|
220
|
+
queueMicrotask(() => { this.guard = false; });
|
|
221
|
+
const { inline, label } = pasteChip(body);
|
|
222
|
+
if (!inline) {
|
|
223
|
+
this.count++;
|
|
224
|
+
this.store.set(this.count, body);
|
|
225
|
+
}
|
|
226
|
+
this.committed.push({ body, inline, label });
|
|
227
|
+
}
|
|
228
|
+
armTimeout() {
|
|
229
|
+
this.clearTimeout();
|
|
230
|
+
this.timer = setTimeout(() => { this.timer = null; if (this.buf !== null)
|
|
231
|
+
this.commit(); }, 50);
|
|
232
|
+
}
|
|
233
|
+
clearTimeout() {
|
|
234
|
+
if (this.timer) {
|
|
235
|
+
clearTimeout(this.timer);
|
|
236
|
+
this.timer = null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// --- Paste collapse/expand (pure, exported for tests; the component just applies these) ---------
|
|
241
|
+
// A bracketed paste is either shown inline (short, single-line) or collapsed to a "[Pasted #N · …]"
|
|
242
|
+
// chip whose payload is held in the store and re-expanded on submit. Kept pure so the round-trip is
|
|
243
|
+
// unit-testable without a TTY (same reducer-under-test pattern as questionKey in QuestionPrompt).
|
|
244
|
+
/** Decide how a paste body renders: inline verbatim, or as a chip with a size label. */
|
|
245
|
+
export function pasteChip(body) {
|
|
246
|
+
const s = body.replace(/\r\n?/g, "\n");
|
|
247
|
+
const lineCount = s === "" ? 0 : s.replace(/\n$/, "").split("\n").length;
|
|
248
|
+
const inline = lineCount <= 1 && s.length <= 80;
|
|
249
|
+
const label = lineCount <= 1 ? `${s.length} chars` : `${lineCount} lines`;
|
|
250
|
+
return { inline, lineCount, label };
|
|
251
|
+
}
|
|
252
|
+
/** Swap every "[Pasted #N · …]" chip back to its stored payload. An unknown #N (e.g. the user
|
|
253
|
+
* backspaced into the chip and broke it) is left as literal text rather than dropped. */
|
|
254
|
+
export function expandPastes(text, store) {
|
|
255
|
+
return text.replace(/\[Pasted #(\d+)[^\]]*\]/g, (m, n) => store.get(Number(n)) ?? m);
|
|
256
|
+
}
|
package/dist/ui/Header.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
+
import { termCols } from "./term.js";
|
|
4
|
+
import { theme } from "./theme.js";
|
|
3
5
|
const STAR = "✷"; // ✷ — the AXE signal star (brand glyph, matches ThinkingSpinner)
|
|
4
6
|
function tierLabel(ctx) {
|
|
5
7
|
if (!ctx)
|
|
6
8
|
return "";
|
|
7
9
|
if (ctx >= 1_000_000)
|
|
8
10
|
return "1M";
|
|
9
|
-
if (ctx >=
|
|
10
|
-
return `${Math.round(ctx /
|
|
11
|
+
if (ctx >= 1024)
|
|
12
|
+
return `${Math.round(ctx / 1024)}K`; // /1024 so 307200→"300K", 131072→"128K" (KiB-tokens, truthful)
|
|
11
13
|
return String(ctx);
|
|
12
14
|
}
|
|
13
15
|
// The status line shows the OUTWARD name only: the internal model ids (operator-1m, or the legacy
|
|
@@ -17,12 +19,12 @@ function prettyRoute(r) {
|
|
|
17
19
|
return /^(operator|aurora)(-|$)/i.test(r) ? "Operator" : r;
|
|
18
20
|
}
|
|
19
21
|
export function Header({ version, route = "operator", ctxWindow, user, build }) {
|
|
20
|
-
const cols =
|
|
22
|
+
const cols = termCols();
|
|
21
23
|
const tier = tierLabel(ctxWindow);
|
|
22
24
|
const model = `${prettyRoute(route)}${tier ? ` · ${tier}` : ""}`; // Operator · 1M
|
|
23
25
|
const who = user ? `⬤ ${user}` : "guest"; // ⬤ email | guest
|
|
24
26
|
const left = ` ${STAR} OPERATOR`;
|
|
25
27
|
const right = `${model} · v${version}${build ? ` ·${build}` : ""} · ${who} `;
|
|
26
28
|
const gap = Math.max(1, cols - left.length - right.length);
|
|
27
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color:
|
|
29
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: theme.accent, bold: true, children: ` ${STAR} ` }), _jsx(Text, { bold: true, color: theme.textBright, children: "OPERATOR" }), _jsx(Text, { children: " ".repeat(gap) }), _jsx(Text, { dimColor: true, children: `${model} · v${version}${build ? ` ·${build}` : ""} · ` }), _jsx(Text, { color: user ? theme.success : undefined, dimColor: !user, children: who + " " })] }), _jsx(Text, { dimColor: true, children: "─".repeat(cols) })] }));
|
|
28
30
|
}
|
package/dist/ui/InputRule.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
+
import { termCols } from "./term.js";
|
|
3
4
|
export function InputRule() {
|
|
4
|
-
const cols =
|
|
5
|
+
const cols = termCols();
|
|
5
6
|
return (_jsx(Box, { children: _jsx(Text, { dimColor: true, children: "─".repeat(Math.max(1, cols - 1)) }) }));
|
|
6
7
|
}
|
package/dist/ui/Markdown.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
-
|
|
3
|
+
import { termCols } from "./term.js";
|
|
4
|
+
import { parseTable, MarkdownTable } from "./Table.js";
|
|
5
|
+
import { link, hyperlinksEnabled } from "./osc.js";
|
|
6
|
+
import { theme } from "./theme.js";
|
|
7
|
+
import { tokenize } from "./highlight.js";
|
|
8
|
+
import { renderTree } from "./tree.js";
|
|
9
|
+
// Map a highlighter token kind to a theme color (undefined = default fg). Comments also render dim.
|
|
10
|
+
const TOKEN_COLOR = {
|
|
11
|
+
comment: theme.muted, string: theme.success, number: theme.running,
|
|
12
|
+
keyword: theme.accent, call: theme.info, plain: undefined,
|
|
13
|
+
};
|
|
14
|
+
// Split one line into styled inline spans: [text](url), **bold**, `code`, *italic* / _italic_, bare URLs.
|
|
15
|
+
// Longest/most-specific markers first so a link isn't torn apart by the emphasis rules.
|
|
4
16
|
function renderInline(text, kp) {
|
|
5
17
|
const nodes = [];
|
|
6
|
-
const re = /(
|
|
18
|
+
const re = /(\[[^\]]+\]\([^)\s]+\)|\*\*[^*]+\*\*|`[^`]+`|\*[^*\s][^*]*\*|_[^_\s][^_]*_|https?:\/\/[^\s)]+)/g;
|
|
7
19
|
let last = 0;
|
|
8
20
|
let m;
|
|
9
21
|
let i = 0;
|
|
@@ -11,10 +23,19 @@ function renderInline(text, kp) {
|
|
|
11
23
|
if (m.index > last)
|
|
12
24
|
nodes.push(_jsx(Text, { children: text.slice(last, m.index) }, `${kp}t${i++}`));
|
|
13
25
|
const tok = m[0];
|
|
14
|
-
if (tok.startsWith("
|
|
26
|
+
if (tok.startsWith("[")) {
|
|
27
|
+
// [label](url) → clickable label (OSC 8) where supported, else "label (url)".
|
|
28
|
+
const mm = /^\[([^\]]+)\]\(([^)\s]+)\)$/.exec(tok);
|
|
29
|
+
const [, label, url] = mm;
|
|
30
|
+
const shown = hyperlinksEnabled() ? link(label, url) : `${label} (${url})`;
|
|
31
|
+
nodes.push(_jsx(Text, { color: theme.info, underline: true, children: shown }, `${kp}l${i++}`));
|
|
32
|
+
}
|
|
33
|
+
else if (tok.startsWith("**"))
|
|
15
34
|
nodes.push(_jsx(Text, { bold: true, children: tok.slice(2, -2) }, `${kp}b${i++}`));
|
|
16
35
|
else if (tok.startsWith("`"))
|
|
17
|
-
nodes.push(_jsx(Text, { color:
|
|
36
|
+
nodes.push(_jsx(Text, { color: theme.info, children: tok.slice(1, -1) }, `${kp}c${i++}`));
|
|
37
|
+
else if (tok.startsWith("http"))
|
|
38
|
+
nodes.push(_jsx(Text, { color: theme.info, underline: true, children: hyperlinksEnabled() ? link(tok, tok) : tok }, `${kp}u${i++}`));
|
|
18
39
|
else
|
|
19
40
|
nodes.push(_jsx(Text, { italic: true, children: tok.slice(1, -1) }, `${kp}i${i++}`));
|
|
20
41
|
last = m.index + tok.length;
|
|
@@ -28,13 +49,24 @@ export function Markdown({ content }) {
|
|
|
28
49
|
const blocks = [];
|
|
29
50
|
let inFence = false;
|
|
30
51
|
let fence = [];
|
|
52
|
+
let fenceLang = "";
|
|
31
53
|
let k = 0;
|
|
32
54
|
const flushFence = () => {
|
|
33
|
-
// Fenced code:
|
|
34
|
-
|
|
55
|
+
// Fenced code: syntax-highlighted per the fence's language, indented. No inline markdown inside.
|
|
56
|
+
const lang = fenceLang;
|
|
57
|
+
if (lang === "tree") {
|
|
58
|
+
// A ```tree block: render the indented outline with box-drawing connectors (dim), not highlighted.
|
|
59
|
+
blocks.push(_jsx(Box, { flexDirection: "column", paddingLeft: 1, children: renderTree(fence.join("\n")).map((l, idx) => _jsx(Text, { dimColor: true, children: l.length ? l : " " }, idx)) }, `f${k++}`));
|
|
60
|
+
fence = [];
|
|
61
|
+
fenceLang = "";
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
blocks.push(_jsx(Box, { flexDirection: "column", paddingLeft: 1, children: fence.map((l, idx) => l.length === 0 ? (_jsx(Text, { children: " " }, idx)) : (_jsx(Text, { children: tokenize(l, lang).map((tok, ti) => (_jsx(Text, { color: TOKEN_COLOR[tok.k], dimColor: tok.k === "comment", children: tok.t }, ti))) }, idx))) }, `f${k++}`));
|
|
35
65
|
fence = [];
|
|
66
|
+
fenceLang = "";
|
|
36
67
|
};
|
|
37
|
-
for (
|
|
68
|
+
for (let li = 0; li < lines.length; li++) {
|
|
69
|
+
const line = lines[li];
|
|
38
70
|
if (/^\s*```/.test(line)) {
|
|
39
71
|
if (inFence) {
|
|
40
72
|
flushFence();
|
|
@@ -42,21 +74,48 @@ export function Markdown({ content }) {
|
|
|
42
74
|
}
|
|
43
75
|
else {
|
|
44
76
|
inFence = true;
|
|
45
|
-
|
|
77
|
+
fenceLang = /^\s*```\s*([\w+#-]+)?/.exec(line)?.[1] ?? "";
|
|
78
|
+
} // capture the language
|
|
46
79
|
continue;
|
|
47
80
|
}
|
|
48
81
|
if (inFence) {
|
|
49
82
|
fence.push(line);
|
|
50
83
|
continue;
|
|
51
84
|
}
|
|
85
|
+
// GFM table: header + separator + rows. Consumes the whole block at once (Static-safe).
|
|
86
|
+
const table = parseTable(lines, li);
|
|
87
|
+
if (table) {
|
|
88
|
+
blocks.push(_jsx(MarkdownTable, { table: table }, `tbl${k++}`));
|
|
89
|
+
li += table.consumed - 1; // -1: the loop's li++ advances past the last consumed line
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
52
92
|
const h = /^(#{1,6})\s+(.*)$/.exec(line);
|
|
53
93
|
if (h) {
|
|
54
|
-
blocks.push(_jsx(Text, { bold: true, children: renderInline(h[2], `h${k}`) }, `h${k++}`));
|
|
94
|
+
blocks.push(_jsx(Text, { bold: true, color: theme.accent, children: renderInline(h[2], `h${k}`) }, `h${k++}`));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
// Horizontal rule: ---, ***, ___ (3+), possibly spaced. A full-width dim divider.
|
|
98
|
+
if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(line)) {
|
|
99
|
+
const cols = termCols();
|
|
100
|
+
blocks.push(_jsx(Text, { dimColor: true, children: "─".repeat(Math.max(1, cols - 1)) }, `hr${k++}`));
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
// Blockquote: > text (one level; nested > collapse to a single bar). Dim bar + dim text.
|
|
104
|
+
const q = /^\s*>\s?(.*)$/.exec(line);
|
|
105
|
+
if (q) {
|
|
106
|
+
blocks.push(_jsxs(Text, { children: [_jsx(Text, { color: theme.muted, children: "\u258F " }), _jsx(Text, { dimColor: true, children: renderInline(q[1].replace(/^>\s?/, ""), `q${k}`) })] }, `q${k++}`));
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
// Task list: - [ ] / - [x] (checkbox), before the plain bullet rule.
|
|
110
|
+
const t = /^(\s*)[-*+]\s+\[([ xX])\]\s+(.*)$/.exec(line);
|
|
111
|
+
if (t) {
|
|
112
|
+
const done = t[2].toLowerCase() === "x";
|
|
113
|
+
blocks.push(_jsxs(Text, { children: [t[1], _jsx(Text, { color: done ? theme.success : theme.muted, children: done ? "☑ " : "☐ " }), renderInline(t[3], `t${k}`)] }, `t${k++}`));
|
|
55
114
|
continue;
|
|
56
115
|
}
|
|
57
116
|
const b = /^(\s*)[-*+]\s+(.*)$/.exec(line);
|
|
58
117
|
if (b) {
|
|
59
|
-
blocks.push(_jsxs(Text, { children: [b[1], _jsx(Text, { color:
|
|
118
|
+
blocks.push(_jsxs(Text, { children: [b[1], _jsx(Text, { color: theme.info, children: "\u2022 " }), renderInline(b[2], `b${k}`)] }, `b${k++}`));
|
|
60
119
|
continue;
|
|
61
120
|
}
|
|
62
121
|
const n = /^(\s*)(\d+)\.\s+(.*)$/.exec(line);
|
package/dist/ui/Masthead.js
CHANGED
|
@@ -11,7 +11,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
// below it, so no reflow hazard). NOT used inside App's dynamic tree.
|
|
12
12
|
import React from "react";
|
|
13
13
|
import { Box, Text } from "ink";
|
|
14
|
+
import { termCols } from "./term.js";
|
|
14
15
|
import chalk from "chalk";
|
|
16
|
+
import { GRAD } from "./theme.js";
|
|
15
17
|
// 5-row block glyphs (█ U+2588, BMP). Only the letters of OPERATOR are needed.
|
|
16
18
|
const GLYPHS = {
|
|
17
19
|
O: [" ███ ", "█ █", "█ █", "█ █", " ███ "],
|
|
@@ -21,8 +23,8 @@ const GLYPHS = {
|
|
|
21
23
|
A: [" ███ ", "█ █", "█████", "█ █", "█ █"],
|
|
22
24
|
T: ["█████", " █ ", " █ ", " █ ", " █ "],
|
|
23
25
|
};
|
|
24
|
-
// violet→magenta ramp, one step per letter of OPERATOR (8 letters, 8 stops).
|
|
25
|
-
|
|
26
|
+
// violet→magenta ramp, one step per letter of OPERATOR (8 letters, 8 stops). Sourced from theme.GRAD so
|
|
27
|
+
// the brand gradient lives in one palette; chalk.hex downsamples each stop at low color levels.
|
|
26
28
|
const WORD = "OPERATOR";
|
|
27
29
|
const GLYPH_W = 5; // each block glyph is 5 cols wide
|
|
28
30
|
const WORD_W = WORD.length * GLYPH_W + (WORD.length - 1); // 8*5 + 7 gaps = 47 visible cols
|
|
@@ -48,7 +50,7 @@ function pad(cols, visibleWidth) {
|
|
|
48
50
|
* (e.g. "aurora · 1M · v0.1.21"). Falls back to a compact one-line wordmark on a narrow terminal
|
|
49
51
|
* so the block letters never wrap (a wrapped glyph row is unreadable).
|
|
50
52
|
*/
|
|
51
|
-
export function mastheadLines(info, cols =
|
|
53
|
+
export function mastheadLines(info, cols = termCols()) {
|
|
52
54
|
if (cols < WORD_W + 4) {
|
|
53
55
|
// compact fallback: single-line gradient wordmark + tagline
|
|
54
56
|
const compact = WORD.split("").map((c, i) => chalk.hex(GRAD[i])(c)).join("");
|
|
@@ -69,7 +71,7 @@ export function mastheadLines(info, cols = process.stdout.columns ?? 80) {
|
|
|
69
71
|
}
|
|
70
72
|
/** Ink render of design #29 — for static screens only (AuthScreen). Not for App's live tree. */
|
|
71
73
|
export function Masthead({ info }) {
|
|
72
|
-
const cols =
|
|
74
|
+
const cols = termCols();
|
|
73
75
|
if (cols < WORD_W + 4) {
|
|
74
76
|
return (_jsxs(Box, { children: [_jsx(Text, { color: GRAD[5], bold: true, children: ` ${STAR} ` }), WORD.split("").map((c, i) => (_jsx(Text, { color: GRAD[i], bold: true, children: c }, i))), _jsx(Text, { dimColor: true, children: ` ${info}` })] }));
|
|
75
77
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { theme } from "./theme.js";
|
|
4
|
+
import { bar } from "./chart.js";
|
|
5
|
+
const GLYPH = { pending: "☐", in_progress: "◐", done: "☑" };
|
|
6
|
+
const COLOR = { pending: theme.muted, in_progress: theme.running, done: theme.success };
|
|
7
|
+
/** The header count "n/total done" (pure, testable). */
|
|
8
|
+
export function planProgress(tasks) {
|
|
9
|
+
const done = tasks.filter((t) => t.status === "done").length;
|
|
10
|
+
return `${done}/${tasks.length} done`;
|
|
11
|
+
}
|
|
12
|
+
export function PlanPane({ tasks, title = "plan" }) {
|
|
13
|
+
if (!tasks.length)
|
|
14
|
+
return null;
|
|
15
|
+
// A fully-completed plan clears itself — once every step is done it has no live value and shouldn't keep
|
|
16
|
+
// occupying the frame. The per-step ✓ already showed as each landed; the finished list drops away.
|
|
17
|
+
if (tasks.every((t) => t.status === "done"))
|
|
18
|
+
return null;
|
|
19
|
+
// Borderless: this pane renders in Ink's DYNAMIC region; a box border there orphans its rows into
|
|
20
|
+
// scrollback whenever the Static transcript grows during a long turn (the v0.1.92 line-flood). The
|
|
21
|
+
// dim header labels the group without a border.
|
|
22
|
+
return (_jsxs(Box, { flexDirection: "column", paddingLeft: 1, children: [_jsxs(Text, { dimColor: true, children: [`${title} · ${planProgress(tasks)} `, _jsx(Text, { color: theme.success, children: bar(tasks.filter((t) => t.status === "done").length, tasks.length, 8) })] }), tasks.map((t) => (_jsxs(Text, { children: [_jsxs(Text, { color: COLOR[t.status], children: [GLYPH[t.status], " "] }), _jsx(Text, { dimColor: t.status === "done", strikethrough: t.status === "done", children: t.text })] }, t.id)))] }));
|
|
23
|
+
}
|
|
@@ -20,7 +20,7 @@ export function questionKey(st, input, key, options) {
|
|
|
20
20
|
if (key.return)
|
|
21
21
|
return { resolve: st.buffer.trim() || DISCUSS };
|
|
22
22
|
if (key.escape)
|
|
23
|
-
return { state: { mode: "choose", buffer: "" } }; // back to the menu
|
|
23
|
+
return { state: { mode: "choose", buffer: "", highlight: st.highlight } }; // back to the menu
|
|
24
24
|
if (key.backspace || key.delete)
|
|
25
25
|
return { state: { ...st, buffer: st.buffer.slice(0, -1) } };
|
|
26
26
|
if (input && !key.ctrl && !key.meta)
|
|
@@ -29,17 +29,31 @@ export function questionKey(st, input, key, options) {
|
|
|
29
29
|
}
|
|
30
30
|
if (key.ctrl && input.toLowerCase() === "c")
|
|
31
31
|
return { resolve: DISCUSS }; // bail = discuss, NEVER a silently-picked real answer
|
|
32
|
-
const
|
|
32
|
+
const total = options.length + 1; // options + chat escape
|
|
33
|
+
if (key.upArrow) {
|
|
34
|
+
const next = st.highlight <= 0 ? total - 1 : st.highlight - 1;
|
|
35
|
+
return { state: { ...st, highlight: next } };
|
|
36
|
+
}
|
|
37
|
+
if (key.downArrow) {
|
|
38
|
+
const next = st.highlight >= total - 1 ? 0 : st.highlight + 1;
|
|
39
|
+
return { state: { ...st, highlight: next } };
|
|
40
|
+
}
|
|
41
|
+
if (key.return) {
|
|
42
|
+
const chatIndex = options.length; // 0-based
|
|
43
|
+
if (st.highlight === chatIndex)
|
|
44
|
+
return { state: { mode: "type", buffer: "", highlight: st.highlight } };
|
|
45
|
+
return { resolve: options[st.highlight] };
|
|
46
|
+
}
|
|
33
47
|
const n = Number(input);
|
|
34
48
|
if (Number.isInteger(n) && n >= 1 && n <= options.length)
|
|
35
49
|
return { resolve: options[n - 1] };
|
|
36
|
-
if (n ===
|
|
37
|
-
return { state: { mode: "type", buffer: "" } }; // open the free-text line
|
|
50
|
+
if (n === options.length + 1)
|
|
51
|
+
return { state: { mode: "type", buffer: "", highlight: options.length } }; // open the free-text line
|
|
38
52
|
return {};
|
|
39
53
|
}
|
|
40
54
|
export function QuestionPrompt({ pending }) {
|
|
41
|
-
const [st, setSt] = useState({ mode: "choose", buffer: "" });
|
|
42
|
-
useEffect(() => { setSt({ mode: "choose", buffer: "" }); }, [pending]); // reset for each new question
|
|
55
|
+
const [st, setSt] = useState({ mode: "choose", buffer: "", highlight: 0 });
|
|
56
|
+
useEffect(() => { setSt({ mode: "choose", buffer: "", highlight: 0 }); }, [pending]); // reset for each new question
|
|
43
57
|
useInput((input, key) => {
|
|
44
58
|
if (!pending)
|
|
45
59
|
return;
|
|
@@ -51,6 +65,6 @@ export function QuestionPrompt({ pending }) {
|
|
|
51
65
|
}, { isActive: !!pending });
|
|
52
66
|
if (!pending)
|
|
53
67
|
return null;
|
|
54
|
-
const chatIndex = pending.options.length
|
|
55
|
-
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, children: ["? ", _jsx(Text, { color: "white", children: pending.question })] }), pending.options.map((o, i) => (_jsxs(Text, { children: [" ", _jsxs(Text, { color: "cyan", children: ["[", i + 1, "]"] }), " ", o] }, i))), _jsxs(Text, { children: [" ", _jsxs(Text, { color: "cyan", children: ["[", chatIndex, "]"] }), " ", _jsx(Text, { color: "magenta", children: CHAT_LABEL })] }), st.mode === "type" ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: "magenta", children: "› " }), st.buffer, _jsx(Text, { color: "cyan", children: "\u258C" })] }), _jsx(Text, { dimColor: true, children: " type your reply · Enter to send · Esc for the menu" })] })) : (
|
|
68
|
+
const chatIndex = pending.options.length; // 0-based highlight index for the chat escape
|
|
69
|
+
return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Text, { color: "cyan", bold: true, children: ["? ", _jsx(Text, { color: "white", children: pending.question })] }), pending.options.map((o, i) => (_jsxs(Text, { children: [" ", st.mode === "choose" && st.highlight === i ? _jsx(Text, { color: "cyan", bold: true, children: "❯ " }) : _jsx(Text, { children: " " }), _jsxs(Text, { color: "cyan", children: ["[", i + 1, "]"] }), " ", _jsx(Text, { bold: st.mode === "choose" && st.highlight === i, children: o })] }, i))), _jsxs(Text, { children: [" ", st.mode === "choose" && st.highlight === chatIndex ? _jsx(Text, { color: "cyan", bold: true, children: "❯ " }) : _jsx(Text, { children: " " }), _jsxs(Text, { color: "cyan", children: ["[", chatIndex + 1, "]"] }), " ", _jsx(Text, { color: "magenta", bold: st.mode === "choose" && st.highlight === chatIndex, children: CHAT_LABEL })] }), st.mode === "type" ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: "magenta", children: "› " }), st.buffer, _jsx(Text, { color: "cyan", children: "\u258C" })] }), _jsx(Text, { dimColor: true, children: " type your reply · Enter to send · Esc for the menu" })] })) : (_jsxs(Text, { dimColor: true, children: [" ↑/↓ to move · Enter to pick · or press 1-", chatIndex + 1, " to jump"] }))] }));
|
|
56
70
|
}
|