@0perator/operator 0.1.61 → 0.1.153
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 +1037 -1
- 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 +269 -20
- package/dist/background/worktree.js +62 -0
- package/dist/cli.js +535 -112
- 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 +13 -4
- 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 +228 -21
- package/dist/telemetry/events.js +9 -0
- package/dist/tools/executor.js +48 -24
- package/dist/tools/git-status.js +71 -0
- package/dist/tools/mutating.js +9 -0
- package/dist/tools/registry.js +214 -11
- package/dist/tools/result-cap.js +23 -0
- package/dist/tools/searxng.js +42 -2
- 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 +14 -6
- 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 +10 -1
package/dist/ui/StatusRule.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
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";
|
|
5
|
+
import { ring } from "./chart.js";
|
|
3
6
|
// Compact token count for the status rule: 1234 -> "1.2k", 45231 -> "45k", 800 -> "800".
|
|
4
7
|
function fmtK(n) {
|
|
5
8
|
if (n < 1000)
|
|
@@ -42,12 +45,18 @@ export function truncateToWidth(s, max) {
|
|
|
42
45
|
// which keeps the leading fill ≥ 1 and the whole line at cols-1, so the rule never becomes the line that
|
|
43
46
|
// wraps (the creep bug) no matter how many badges are lit or how narrow the window.
|
|
44
47
|
export function statusRight(p, cols) {
|
|
45
|
-
const who = p.user ?
|
|
48
|
+
const who = p.user ? `◆ ${p.user} · ` : "";
|
|
46
49
|
const seat = p.tier && p.tier !== "admin" ? `⛨ ${p.tier} · ` : ""; // a narrowed seat shows; owner's admin doesn't
|
|
47
50
|
const plan = p.planMode ? `◔ plan · ` : ""; // read-only research mode is visible while active
|
|
48
51
|
const think = p.thinkMode === "ultrathink" ? `✲✲ ultrathink · ` : p.thinkMode === "think" ? `✲ think · ` : "";
|
|
49
52
|
const tok = p.sessionTokens && p.sessionTokens > 0 ? `Σ${fmtK(p.sessionTokens)} · ` : ""; // session token total
|
|
50
|
-
|
|
53
|
+
// ctx as a fill ring (○◔◑◕●) + the exact % — a glance shows how full the context window is, the number keeps precision.
|
|
54
|
+
// Display-only: show the Aurora model under an aurora-* name (operator-1m → aurora-300k) without touching
|
|
55
|
+
// the internal model id — routing, /model, and persisted settings still key on the real id. The "-1m"
|
|
56
|
+
// suffix renders as "-300k" because the server's real window is 300K (standardized 2026-09-27); showing
|
|
57
|
+
// "1m" would be untruthful. Other routes (operator-128k, moa, custom) pass through unchanged.
|
|
58
|
+
const routeLabel = p.route.replace(/^operator-/, "aurora-").replace(/-1m$/, "-300k");
|
|
59
|
+
let info = `${think}${plan}${seat}${who}${routeLabel} · ${ring(p.ctxPct)} ${Math.round(p.ctxPct)}% · ${tok}v${p.version}${p.build ? ` ·${p.build}` : ""}`;
|
|
51
60
|
let right = `✷ OPERATOR · ${info} ─`;
|
|
52
61
|
const maxRight = cols - 3; // leaves fill ≥ 1 and total = cols-1
|
|
53
62
|
if (cellWidth(right) > maxRight) {
|
|
@@ -65,10 +74,10 @@ export function ruleFill(right, cols) {
|
|
|
65
74
|
return Math.max(1, cols - cellWidth(right) - 2);
|
|
66
75
|
}
|
|
67
76
|
export function StatusRule(props) {
|
|
68
|
-
const cols =
|
|
77
|
+
const cols = termCols();
|
|
69
78
|
const { info, right } = statusRight(props, cols);
|
|
70
79
|
const fill = ruleFill(right, cols);
|
|
71
80
|
// Enterprise header: a dim rule sweeping to a magenta ✷ mark + bright OPERATOR wordmark + dim info,
|
|
72
81
|
// sitting just above the composer (the input is bounded between this and the InputRule below).
|
|
73
|
-
return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: "─".repeat(fill) + " " }), _jsx(Text, { color:
|
|
82
|
+
return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: "─".repeat(fill) + " " }), _jsx(Text, { color: theme.accent, children: "\u2737 " }), _jsx(Text, { bold: true, children: "OPERATOR" }), _jsx(Text, { dimColor: true, children: ` · ${info} ─` })] }));
|
|
74
83
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
const fmtDur = (ms) => (ms < 1000 ? `${Math.round(ms)}ms` : ms < 60_000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`);
|
|
5
|
+
const fmtTok = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`);
|
|
6
|
+
/** The metrics line (pure) — kept separate so the exact layout is unit-testable without a render. */
|
|
7
|
+
export function summaryLine(s) {
|
|
8
|
+
const parts = [fmtDur(s.durationMs), `${fmtTok(s.tokens)} tok${s.tps ? ` @ ${s.tps} tok/s` : ""}`];
|
|
9
|
+
if (s.prefill)
|
|
10
|
+
parts.push(`${fmtTok(s.prefill)} prefill`);
|
|
11
|
+
parts.push(`${s.rounds} round${s.rounds === 1 ? "" : "s"}`);
|
|
12
|
+
if (s.tools)
|
|
13
|
+
parts.push(`${s.tools} tool${s.tools === 1 ? "" : "s"}`);
|
|
14
|
+
return parts.join(" · ");
|
|
15
|
+
}
|
|
16
|
+
export function SummaryCard({ summary }) {
|
|
17
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: theme.accent, children: "\u2726 " }), _jsx(Text, { bold: true, children: "turn complete" }), _jsx(Text, { dimColor: true, children: ` ${summaryLine(summary)}` })] }), summary.unverified ? (_jsx(Text, { color: theme.warn, children: "\u26A0 changed files \u00B7 not verified (no passing check ran)" })) : null] }));
|
|
18
|
+
}
|
package/dist/ui/Table.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// GFM markdown tables in assistant output (SPEC §6, TUI wave item 02). A coding agent constantly wants to
|
|
3
|
+
// present structured comparisons — flags, options, before/after, cost breakdowns — and prose bullet-soup
|
|
4
|
+
// buries that. This renders a `| a | b |` / `|---|` block as a box-drawn, column-aligned Ink table.
|
|
5
|
+
// Rendered ONLY on settled transcript entries (Markdown is), so it never fights the live per-token stream.
|
|
6
|
+
// Dependency-free; the width math reuses cellWidth/truncateToWidth (the same conservative accounting that
|
|
7
|
+
// keeps the status rule from wrapping) so a double-width glyph never skews a column. CLI-only.
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { Box, Text } from "ink";
|
|
10
|
+
import { termCols } from "./term.js";
|
|
11
|
+
import { cellWidth, truncateToWidth } from "./StatusRule.js";
|
|
12
|
+
import { theme } from "./theme.js";
|
|
13
|
+
const MIN_COL = 3; // never shrink a column below this many cells (keeps "…" legible)
|
|
14
|
+
// A line is table-ish if it has at least one unescaped pipe with content around it.
|
|
15
|
+
function looksLikeRow(line) {
|
|
16
|
+
return line.includes("|") && line.trim().length > 0;
|
|
17
|
+
}
|
|
18
|
+
// The separator row under the header: each cell is dashes with optional leading/trailing colons. Requires
|
|
19
|
+
// at least one dash so a plain prose line with a stray pipe is never mistaken for a separator.
|
|
20
|
+
function isSeparator(line) {
|
|
21
|
+
return line.includes("-") && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(line);
|
|
22
|
+
}
|
|
23
|
+
// Split "| a | b |" into ["a","b"] — strip one leading/trailing pipe, split on unescaped pipes, trim.
|
|
24
|
+
export function splitRow(line) {
|
|
25
|
+
let s = line.trim();
|
|
26
|
+
if (s.startsWith("|"))
|
|
27
|
+
s = s.slice(1);
|
|
28
|
+
if (s.endsWith("|"))
|
|
29
|
+
s = s.slice(0, -1);
|
|
30
|
+
return s.split(/(?<!\\)\|/).map((c) => c.replace(/\\\|/g, "|").trim());
|
|
31
|
+
}
|
|
32
|
+
function alignOf(sep) {
|
|
33
|
+
const t = sep.trim();
|
|
34
|
+
const l = t.startsWith(":");
|
|
35
|
+
const r = t.endsWith(":");
|
|
36
|
+
return l && r ? "center" : r ? "right" : "left"; // GFM: :--: center, --: right, else left
|
|
37
|
+
}
|
|
38
|
+
/** Parse a GFM table starting at lines[start], or null if it isn't one. Pure — no rendering. A valid table
|
|
39
|
+
* is a header row, a separator row with matching column count, then zero+ data rows. */
|
|
40
|
+
export function parseTable(lines, start) {
|
|
41
|
+
if (start + 1 >= lines.length)
|
|
42
|
+
return null;
|
|
43
|
+
if (!looksLikeRow(lines[start]) || !isSeparator(lines[start + 1]))
|
|
44
|
+
return null;
|
|
45
|
+
const header = splitRow(lines[start]);
|
|
46
|
+
const seps = splitRow(lines[start + 1]);
|
|
47
|
+
if (seps.length !== header.length)
|
|
48
|
+
return null; // separator must describe the same columns
|
|
49
|
+
const aligns = seps.map(alignOf);
|
|
50
|
+
const rows = [];
|
|
51
|
+
let i = start + 2;
|
|
52
|
+
for (; i < lines.length; i++) {
|
|
53
|
+
if (!looksLikeRow(lines[i]) || isSeparator(lines[i]))
|
|
54
|
+
break;
|
|
55
|
+
const cells = splitRow(lines[i]);
|
|
56
|
+
// normalize ragged rows to the header's column count (pad short, clip long)
|
|
57
|
+
while (cells.length < header.length)
|
|
58
|
+
cells.push("");
|
|
59
|
+
rows.push(cells.slice(0, header.length));
|
|
60
|
+
}
|
|
61
|
+
return { header, aligns, rows, consumed: i - start };
|
|
62
|
+
}
|
|
63
|
+
/** Natural column widths = the widest cell (header or body) per column, measured in terminal cells. */
|
|
64
|
+
export function naturalWidths(t) {
|
|
65
|
+
return t.header.map((h, c) => Math.max(cellWidth(h), ...t.rows.map((r) => cellWidth(r[c] ?? ""))));
|
|
66
|
+
}
|
|
67
|
+
/** Shrink column widths so the whole table fits `maxWidth` terminal cells, trimming the widest columns
|
|
68
|
+
* first and never below MIN_COL. Pure so the fit is unit-testable. Frame per row = 1 leading '│' plus
|
|
69
|
+
* '│'+space+space per column (3 cells each): total = 1 + Σ(w+3). */
|
|
70
|
+
export function fitWidths(natural, maxWidth) {
|
|
71
|
+
const w = [...natural];
|
|
72
|
+
const frame = 1 + 3 * w.length;
|
|
73
|
+
const budget = Math.max(w.length * MIN_COL, maxWidth - frame); // content cells available
|
|
74
|
+
let sum = w.reduce((a, b) => a + b, 0);
|
|
75
|
+
let guard = 10_000;
|
|
76
|
+
while (sum > budget && guard-- > 0) {
|
|
77
|
+
let widest = 0;
|
|
78
|
+
for (let c = 1; c < w.length; c++)
|
|
79
|
+
if (w[c] > w[widest])
|
|
80
|
+
widest = c;
|
|
81
|
+
if (w[widest] <= MIN_COL)
|
|
82
|
+
break; // can't shrink further without destroying legibility
|
|
83
|
+
w[widest] -= 1;
|
|
84
|
+
sum -= 1;
|
|
85
|
+
}
|
|
86
|
+
return w;
|
|
87
|
+
}
|
|
88
|
+
/** Fit one cell to a column: truncate to width, then pad per alignment. Pure string op. */
|
|
89
|
+
export function padCell(text, width, align) {
|
|
90
|
+
const t = truncateToWidth(text, width);
|
|
91
|
+
const gap = width - cellWidth(t);
|
|
92
|
+
if (gap <= 0)
|
|
93
|
+
return t;
|
|
94
|
+
if (align === "right")
|
|
95
|
+
return " ".repeat(gap) + t;
|
|
96
|
+
if (align === "center") {
|
|
97
|
+
const left = Math.floor(gap / 2);
|
|
98
|
+
return " ".repeat(left) + t + " ".repeat(gap - left);
|
|
99
|
+
}
|
|
100
|
+
return t + " ".repeat(gap);
|
|
101
|
+
}
|
|
102
|
+
// Box-drawing rule pieces (all ≤ U+257F, so cellWidth counts them as one cell — no column skew).
|
|
103
|
+
function rule(widths, left, mid, right, fill = "─") {
|
|
104
|
+
return left + widths.map((w) => fill.repeat(w + 2)).join(mid) + right;
|
|
105
|
+
}
|
|
106
|
+
export function MarkdownTable({ table }) {
|
|
107
|
+
const cols = termCols();
|
|
108
|
+
const widths = fitWidths(naturalWidths(table), Math.max(20, cols - 1));
|
|
109
|
+
const top = rule(widths, "┌", "┬", "┐");
|
|
110
|
+
const sep = rule(widths, "├", "┼", "┤");
|
|
111
|
+
const bot = rule(widths, "└", "┴", "┘");
|
|
112
|
+
const dataRow = (cells, bold, key) => (_jsxs(Text, { children: [_jsx(Text, { color: theme.muted, children: "\u2502" }), widths.map((w, c) => (_jsxs(React.Fragment, { children: [_jsx(Text, { children: " " }), _jsx(Text, { bold: bold, children: padCell(cells[c] ?? "", w, table.aligns[c] ?? "left") }), _jsx(Text, { children: " " }), _jsx(Text, { color: theme.muted, children: "\u2502" })] }, c)))] }, key));
|
|
113
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: theme.muted, children: top }), dataRow(table.header, true, "th"), _jsx(Text, { color: theme.muted, children: sep }), table.rows.map((r, i) => dataRow(r, false, `tr${i}`)), _jsx(Text, { color: theme.muted, children: bot })] }));
|
|
114
|
+
}
|
|
@@ -6,14 +6,15 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
|
6
6
|
// the live token/time metrics (formerly on StatusRule) ride beside that.
|
|
7
7
|
import { useEffect, useState } from "react";
|
|
8
8
|
import { Box, Text } from "ink";
|
|
9
|
+
import { theme } from "./theme.js";
|
|
9
10
|
const DEFAULT_VERBS = [
|
|
10
11
|
"Thinking", "Reasoning", "Noodling", "Synthesizing", "Percolating", "Untangling", "Weighing",
|
|
11
12
|
];
|
|
12
13
|
// Ink render props per tone — the truecolor equivalents of star_signal.py's ANSI TONES.
|
|
13
14
|
const TONE_STYLE = {
|
|
14
|
-
amber: { color:
|
|
15
|
-
bright: { color:
|
|
16
|
-
dim: { color:
|
|
15
|
+
amber: { color: theme.running },
|
|
16
|
+
bright: { color: theme.starBright, bold: true },
|
|
17
|
+
dim: { color: theme.running, dim: true },
|
|
17
18
|
faint: { dim: true },
|
|
18
19
|
};
|
|
19
20
|
// (tone, glyph, ticks) — ticks is how many beats the frame holds. Sun → point → silence → burst.
|
|
@@ -38,7 +39,8 @@ export function expandStar(frames = FRAMES) {
|
|
|
38
39
|
return out;
|
|
39
40
|
}
|
|
40
41
|
const SEQUENCE = expandStar();
|
|
41
|
-
export function ThinkingSpinner({ active, verb, verbs = DEFAULT_VERBS, verbIntervalMs = 2000, tickMs =
|
|
42
|
+
export function ThinkingSpinner({ active, verb, verbs = DEFAULT_VERBS, verbIntervalMs = 2000, tickMs = 150, // 150ms (~7fps): the star still reads as animated, but each tick re-renders the whole inline frame — the dominant streaming-phase driver, kept slow to reduce flashing
|
|
43
|
+
metrics, }) {
|
|
42
44
|
const [tick, setTick] = useState(0);
|
|
43
45
|
const [verbIdx, setVerbIdx] = useState(0);
|
|
44
46
|
useEffect(() => {
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { ToolStep } from "./ToolStep.js";
|
|
5
|
+
const fmtDur = (ms) => ms < 1000 ? `${Math.round(ms)}ms` : ms < 60_000 ? `${(ms / 1000).toFixed(1)}s` : `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`;
|
|
6
|
+
/** The batch header (pure) — kept separate so the exact wording/layout is unit-testable without a render. */
|
|
7
|
+
export function batchHeader(count, durationMs) {
|
|
8
|
+
return `${count} tools in parallel · ${fmtDur(durationMs)}`;
|
|
9
|
+
}
|
|
10
|
+
export function ToolBatch({ steps, durationMs }) {
|
|
11
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: theme.accent, children: "\u21C9 " }), _jsx(Text, { bold: true, children: `${steps.length} tools in parallel` }), _jsx(Text, { dimColor: true, children: ` ${fmtDur(durationMs)}` })] }), steps.map((step) => _jsx(ToolStep, { step: step }, step.id))] }));
|
|
12
|
+
}
|
package/dist/ui/ToolStep.js
CHANGED
|
@@ -4,8 +4,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
import { Box, Text } from "ink";
|
|
6
6
|
import { formatDuration } from "./format.js";
|
|
7
|
+
import { fileLink } from "./osc.js";
|
|
8
|
+
import { theme } from "./theme.js";
|
|
9
|
+
import { computeEditDiff } from "./editdiff.js";
|
|
10
|
+
const PATH_KEYS = new Set(["path", "file", "filename"]);
|
|
7
11
|
const GLYPH = { selected: "○", running: "◐", done: "✓", error: "✗" };
|
|
8
|
-
const COLOR = { selected:
|
|
12
|
+
const COLOR = { selected: theme.muted, running: theme.running, done: theme.success, error: theme.error };
|
|
9
13
|
// Args that identify WHAT a tool acted on — a path, a command, a URL. These are shown FIRST and IN FULL
|
|
10
14
|
// (never truncated), so you can always read the exact file name / path a tool wrote or read. Order matters:
|
|
11
15
|
// path-like keys first.
|
|
@@ -21,7 +25,8 @@ export function argsPreview(args) {
|
|
|
21
25
|
for (const k of KEY_ARGS) {
|
|
22
26
|
const v = args[k];
|
|
23
27
|
if (v != null && (typeof v === "string" || typeof v === "number")) {
|
|
24
|
-
|
|
28
|
+
const shown = PATH_KEYS.has(k) && typeof v === "string" ? fileLink(v) : String(v); // clickable path (OSC 8)
|
|
29
|
+
parts.push(`${k}: ${shown}`);
|
|
25
30
|
seen.add(k);
|
|
26
31
|
}
|
|
27
32
|
}
|
|
@@ -48,7 +53,7 @@ export function ToolStep({ step }) {
|
|
|
48
53
|
useEffect(() => {
|
|
49
54
|
if (step.status !== "running" || !step.startedAt)
|
|
50
55
|
return;
|
|
51
|
-
const id = setInterval(() => setNow(Date.now()),
|
|
56
|
+
const id = setInterval(() => setNow(Date.now()), 250); // 250ms: the tool-elapsed readout only needs ~quarter-second granularity; 100ms re-rendered the whole frame 10×/s (flashing)
|
|
52
57
|
return () => clearInterval(id);
|
|
53
58
|
}, [step.status, step.startedAt]);
|
|
54
59
|
const elapsed = step.durationMs ??
|
|
@@ -57,5 +62,8 @@ export function ToolStep({ step }) {
|
|
|
57
62
|
: step.endedAt && step.startedAt
|
|
58
63
|
? step.endedAt - step.startedAt
|
|
59
64
|
: undefined);
|
|
60
|
-
|
|
65
|
+
// Enterprise "what changed at a glance": only on a SETTLED edit (not mid-run, not errored — the write
|
|
66
|
+
// may never have landed), and only when the tool's own args are actually diffable.
|
|
67
|
+
const editDiff = step.status === "done" ? computeEditDiff(step.name, step.args) : undefined;
|
|
68
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: COLOR[step.status], children: GLYPH[step.status] }), " ", step.name, "(", argsPreview(step.args), ")", elapsed != null ? _jsxs(Text, { dimColor: true, children: [" ", formatDuration(elapsed)] }) : null, editDiff ? (_jsxs(Text, { children: [" ", _jsxs(Text, { color: theme.success, children: ["+", editDiff.added] }), " ", _jsxs(Text, { color: theme.error, children: ["-", editDiff.removed] })] })) : null] }), step.summary ? _jsxs(Text, { dimColor: true, children: [" ", step.summary] }) : null, editDiff?.preview?.map((l, i) => (_jsxs(Text, { color: l.kind === "add" ? theme.success : theme.error, children: [" ", l.kind === "add" ? "+ " : "- ", l.text] }, i)))] }));
|
|
61
69
|
}
|
package/dist/ui/Transcript.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Static, Text } from "ink";
|
|
3
3
|
import { ToolStep } from "./ToolStep.js";
|
|
4
4
|
import { Markdown } from "./Markdown.js";
|
|
5
|
+
import { SummaryCard } from "./SummaryCard.js";
|
|
6
|
+
import { StatsCard } from "./StatsCard.js";
|
|
7
|
+
import { ToolBatch } from "./ToolBatch.js";
|
|
8
|
+
import { termCols, termRows } from "./term.js";
|
|
9
|
+
// In fullscreen we can't use <Static> (it targets the scrollback the alt-screen buffer hides), so render
|
|
10
|
+
// the last N entries as a plain column the parent region clips to the visible height. N is generous — the
|
|
11
|
+
// parent's overflow:hidden + justifyContent:flex-end shows only what fits, bottom-anchored.
|
|
12
|
+
const BOUNDED_TAIL = 80;
|
|
5
13
|
function entryKey(entry) {
|
|
6
|
-
return entry.kind === "message" ? entry.message.id : entry.step.id;
|
|
14
|
+
return entry.kind === "message" ? entry.message.id : entry.kind === "tool" ? entry.step.id : entry.kind === "summary" ? entry.summary.id : entry.id;
|
|
7
15
|
}
|
|
8
16
|
// Rows the live frame must leave free for the spinner + status/input rules + composer + margins. The live
|
|
9
17
|
// streaming message is tailed to (terminal rows - this) so the DYNAMIC (non-Static) frame never grows
|
|
@@ -16,13 +24,18 @@ function entryKey(entry) {
|
|
|
16
24
|
// stream, while the full text always renders complete via <Static> once it settles. Pure (dimensions
|
|
17
25
|
// passed in) so the bound is unit-testable.
|
|
18
26
|
export function liveTail(s, rows, cols) {
|
|
19
|
-
|
|
27
|
+
// Clamp degenerate dimensions: a minimized/detached terminal reports 0, and cols=0 divides to
|
|
28
|
+
// Infinity/NaN below — which walks `start` to 0 and returns the WHOLE message unbounded, ballooning the
|
|
29
|
+
// dynamic frame and stacking the streaming line into scrollback (the minimize-duplication bug). Guard
|
|
30
|
+
// here too (not just at the call site) since this is the pure, unit-tested unit — it must not trust its caller.
|
|
31
|
+
const c = cols > 0 ? cols : 80;
|
|
32
|
+
const budget = Math.max(6, Math.min((rows > 0 ? rows : 24) - 14, 16)); // rendered rows the live frame may occupy
|
|
20
33
|
const lines = s.split("\n");
|
|
21
34
|
// Walk up from the last line, counting the PHYSICAL rows each takes after wrapping, and keep only what
|
|
22
35
|
// fits the budget — so even all-long-wrapping lines can't push the dynamic frame past the window.
|
|
23
36
|
let used = 0, start = lines.length;
|
|
24
37
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
25
|
-
const wrapped = Math.max(1, Math.ceil(lines[i].length /
|
|
38
|
+
const wrapped = Math.max(1, Math.ceil(lines[i].length / c));
|
|
26
39
|
if (used + wrapped > budget && start !== lines.length)
|
|
27
40
|
break;
|
|
28
41
|
used += wrapped;
|
|
@@ -35,6 +48,12 @@ export function liveTail(s, rows, cols) {
|
|
|
35
48
|
return { text: lines.slice(start).join("\n"), clipped: start };
|
|
36
49
|
}
|
|
37
50
|
function renderEntry(entry, live = false) {
|
|
51
|
+
if (entry.kind === "summary")
|
|
52
|
+
return _jsx(SummaryCard, { summary: entry.summary });
|
|
53
|
+
if (entry.kind === "stats")
|
|
54
|
+
return _jsx(StatsCard, { stats: entry.stats });
|
|
55
|
+
if (entry.kind === "toolBatch")
|
|
56
|
+
return _jsx(ToolBatch, { steps: entry.steps, durationMs: entry.durationMs });
|
|
38
57
|
if (entry.kind === "message") {
|
|
39
58
|
const { message } = entry;
|
|
40
59
|
if (message.role === "user") {
|
|
@@ -53,7 +72,7 @@ function renderEntry(entry, live = false) {
|
|
|
53
72
|
const src = message.content ? message.content : (message.reasoning ?? "");
|
|
54
73
|
if (!src)
|
|
55
74
|
return _jsx(Box, { marginBottom: 1 });
|
|
56
|
-
const { text, clipped } = liveTail(src,
|
|
75
|
+
const { text, clipped } = liveTail(src, termRows(), termCols());
|
|
57
76
|
const dim = !message.content; // reasoning is dim; the answer is full weight
|
|
58
77
|
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [clipped > 0 ? _jsx(Text, { dimColor: true, children: `⋯ +${clipped} more line${clipped === 1 ? "" : "s"} above (full text shown when complete)` }) : null, _jsx(Text, { dimColor: dim, children: text })] }));
|
|
59
78
|
}
|
|
@@ -62,6 +81,11 @@ function renderEntry(entry, live = false) {
|
|
|
62
81
|
}
|
|
63
82
|
return _jsx(ToolStep, { step: entry.step });
|
|
64
83
|
}
|
|
65
|
-
export function Transcript({ entries, live }) {
|
|
84
|
+
export function Transcript({ entries, live, bounded }) {
|
|
85
|
+
if (bounded) {
|
|
86
|
+
// Fullscreen: no <Static>; render the tail as a plain column the parent clips + bottom-anchors.
|
|
87
|
+
const tail = entries.length > BOUNDED_TAIL ? entries.slice(-BOUNDED_TAIL) : entries;
|
|
88
|
+
return (_jsxs(Box, { flexDirection: "column", children: [entries.length > tail.length ? (_jsx(Text, { dimColor: true, children: `⋯ ${entries.length - tail.length} earlier line(s) scrolled off` })) : null, tail.map((entry) => _jsx(Box, { children: renderEntry(entry) }, entryKey(entry))), live ? _jsx(Box, { children: renderEntry(live, true) }) : null] }));
|
|
89
|
+
}
|
|
66
90
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: entries, children: (entry) => _jsx(Box, { children: renderEntry(entry) }, entryKey(entry)) }), live ? _jsx(Box, { children: renderEntry(live, true) }) : null] }));
|
|
67
91
|
}
|
package/dist/ui/chart.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Tiny terminal charts (SPEC §6, TUI wave item): sparklines, progress bars, and percentage rings from
|
|
2
|
+
// plain numbers — the primitives the richer panes (plan progress, sub-task bars, a cost/throughput
|
|
3
|
+
// dashboard) draw with. Pure string builders, no deps, BMP glyphs only (render in Menlo/Terminal.app).
|
|
4
|
+
// NOTE: the block glyphs are ≥U+2580, which cellWidth() counts as width-2 — fine INSIDE a flex pane (its
|
|
5
|
+
// own box does the wrapping), but do NOT place these in the status/input rules, whose width math must be
|
|
6
|
+
// exact (the frame-creep bug). Panes only.
|
|
7
|
+
const RAMP = "▁▂▃▄▅▆▇█"; // 8 levels for sparklines (U+2581..U+2588)
|
|
8
|
+
/** A sparkline for a series — each value mapped to one of 8 block heights across the series' min..max.
|
|
9
|
+
* An empty series is "", a flat series is all mid-height. Great for a per-turn tok/s trend. */
|
|
10
|
+
export function sparkline(values) {
|
|
11
|
+
if (!values.length)
|
|
12
|
+
return "";
|
|
13
|
+
const min = Math.min(...values);
|
|
14
|
+
const max = Math.max(...values);
|
|
15
|
+
const span = max - min;
|
|
16
|
+
return values
|
|
17
|
+
.map((v) => (span === 0 ? RAMP[3] : RAMP[Math.min(RAMP.length - 1, Math.max(0, Math.round(((v - min) / span) * (RAMP.length - 1))))]))
|
|
18
|
+
.join("");
|
|
19
|
+
}
|
|
20
|
+
/** A horizontal progress/level bar of `width` cells: filled (█) up to value/max, rest light (░). Clamps to
|
|
21
|
+
* [0,max]; width ≥ 1. E.g. bar(2, 5, 10) → "████░░░░░░". */
|
|
22
|
+
export function bar(value, max, width = 10) {
|
|
23
|
+
const w = Math.max(1, Math.floor(width));
|
|
24
|
+
if (max <= 0)
|
|
25
|
+
return "░".repeat(w);
|
|
26
|
+
const filled = Math.max(0, Math.min(w, Math.round((value / max) * w)));
|
|
27
|
+
return "█".repeat(filled) + "░".repeat(w - filled);
|
|
28
|
+
}
|
|
29
|
+
const RING = "○◔◑◕●"; // 0, 25, 50, 75, 100 %
|
|
30
|
+
/** A single-glyph percentage ring (0–100) — five quarter steps. For a compact ctx%/progress dot. */
|
|
31
|
+
export function ring(pct) {
|
|
32
|
+
const p = Math.max(0, Math.min(100, pct));
|
|
33
|
+
return RING[Math.min(RING.length - 1, Math.round((p / 100) * (RING.length - 1)))];
|
|
34
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const MAX_PREVIEW_LINES = 4;
|
|
2
|
+
const MAX_LINE_WIDTH = 100; // a single preview line is truncated, never left to wrap/flood the row
|
|
3
|
+
const EDIT_TOOL_NAMES = new Set(["file_edit", "multi_edit"]);
|
|
4
|
+
const WRITE_TOOL_NAMES = new Set(["file_write"]);
|
|
5
|
+
function splitLines(s) {
|
|
6
|
+
return s === "" ? [] : s.split("\n");
|
|
7
|
+
}
|
|
8
|
+
function truncateLine(s) {
|
|
9
|
+
return s.length > MAX_LINE_WIDTH ? `${s.slice(0, MAX_LINE_WIDTH - 1)}…` : s;
|
|
10
|
+
}
|
|
11
|
+
/** Line-level LCS diff. old/new are a tool's old_string/new_string — typically a small snippet — so the
|
|
12
|
+
* O(n*m) table is cheap. Returns the edit script in the order it actually happened (adds and deletes
|
|
13
|
+
* interleaved), not grouped by type, so a preview reads top-to-bottom like the real change. */
|
|
14
|
+
function lineDiff(oldLines, newLines) {
|
|
15
|
+
const n = oldLines.length;
|
|
16
|
+
const m = newLines.length;
|
|
17
|
+
const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));
|
|
18
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
19
|
+
for (let j = m - 1; j >= 0; j--) {
|
|
20
|
+
dp[i][j] = oldLines[i] === newLines[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const script = [];
|
|
24
|
+
let i = 0;
|
|
25
|
+
let j = 0;
|
|
26
|
+
while (i < n && j < m) {
|
|
27
|
+
if (oldLines[i] === newLines[j]) {
|
|
28
|
+
i++;
|
|
29
|
+
j++;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (dp[i + 1][j] >= dp[i][j + 1]) {
|
|
33
|
+
script.push({ kind: "del", text: oldLines[i] });
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
script.push({ kind: "add", text: newLines[j] });
|
|
38
|
+
j++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
while (i < n) {
|
|
42
|
+
script.push({ kind: "del", text: oldLines[i] });
|
|
43
|
+
i++;
|
|
44
|
+
}
|
|
45
|
+
while (j < m) {
|
|
46
|
+
script.push({ kind: "add", text: newLines[j] });
|
|
47
|
+
j++;
|
|
48
|
+
}
|
|
49
|
+
return script;
|
|
50
|
+
}
|
|
51
|
+
/** Pure: derive +N/-M (and a capped preview) from a settled file-edit/file-write tool row's args.
|
|
52
|
+
* Returns undefined when the tool isn't a recognized file edit, or has no diffable args — the row
|
|
53
|
+
* then renders exactly as it always has (no guessing at a diff that isn't really there). */
|
|
54
|
+
export function computeEditDiff(name, args) {
|
|
55
|
+
if (!args)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (EDIT_TOOL_NAMES.has(name)) {
|
|
58
|
+
const oldStr = args.old_string;
|
|
59
|
+
const newStr = args.new_string;
|
|
60
|
+
if (typeof oldStr !== "string" || typeof newStr !== "string")
|
|
61
|
+
return undefined;
|
|
62
|
+
if (oldStr === newStr)
|
|
63
|
+
return { added: 0, removed: 0 };
|
|
64
|
+
const script = lineDiff(splitLines(oldStr), splitLines(newStr));
|
|
65
|
+
const added = script.filter((l) => l.kind === "add").length;
|
|
66
|
+
const removed = script.filter((l) => l.kind === "del").length;
|
|
67
|
+
const preview = script.length <= MAX_PREVIEW_LINES ? script.map((l) => ({ kind: l.kind, text: truncateLine(l.text) })) : undefined;
|
|
68
|
+
return { added, removed, preview };
|
|
69
|
+
}
|
|
70
|
+
if (WRITE_TOOL_NAMES.has(name)) {
|
|
71
|
+
const content = args.content;
|
|
72
|
+
if (typeof content !== "string")
|
|
73
|
+
return undefined;
|
|
74
|
+
const lines = splitLines(content);
|
|
75
|
+
const preview = lines.length <= MAX_PREVIEW_LINES ? lines.map((text) => ({ kind: "add", text: truncateLine(text) })) : undefined;
|
|
76
|
+
return { added: lines.length, removed: 0, preview };
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
/** The plain-text "+N -M" label (no color) — kept separate so the exact count formatting is
|
|
81
|
+
* unit-testable without a render; ToolStep colors added/removed independently with theme tokens. */
|
|
82
|
+
export function editDiffLabel(result) {
|
|
83
|
+
return `+${result.added} -${result.removed}`;
|
|
84
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Lightweight, dependency-free syntax highlighter for fenced code blocks in assistant answers (SPEC §6,
|
|
2
|
+
// TUI wave item 07). A coding agent's output is mostly code, so a flat monochrome fence is the biggest
|
|
3
|
+
// missed win — this tints keywords / strings / comments / numbers / calls so a diff or snippet reads like
|
|
4
|
+
// an editor. Deliberately line-based and heuristic (not a real lexer): terminal display, not compilation,
|
|
5
|
+
// so a torn multi-line string is cosmetic, never wrong. Pure `tokenize()` — the colors are applied by the
|
|
6
|
+
// caller (Markdown.tsx) from the theme, so this stays render-agnostic and unit-testable.
|
|
7
|
+
// A broad keyword set spanning the languages a coding agent emits most (py / js-ts / go / rust / shell / c).
|
|
8
|
+
// Over-inclusion is harmless — a word only lights up when it stands alone as an identifier.
|
|
9
|
+
const KEYWORDS = new Set([
|
|
10
|
+
"const", "let", "var", "function", "def", "class", "return", "if", "else", "elif", "for", "while", "do",
|
|
11
|
+
"switch", "case", "break", "continue", "import", "from", "export", "default", "async", "await", "yield",
|
|
12
|
+
"new", "delete", "try", "except", "catch", "finally", "raise", "throw", "with", "as", "in", "of", "is",
|
|
13
|
+
"not", "and", "or", "lambda", "pass", "public", "private", "protected", "static", "void", "struct", "enum",
|
|
14
|
+
"impl", "trait", "fn", "pub", "mut", "use", "mod", "match", "type", "interface", "extends", "implements",
|
|
15
|
+
"this", "self", "super", "null", "nil", "None", "True", "False", "true", "false", "undefined", "then", "fi",
|
|
16
|
+
"done", "elif", "echo", "local", "func", "package", "defer", "go", "chan", "map", "range", "select",
|
|
17
|
+
]);
|
|
18
|
+
// Comment prefix by language family. Default handles both # and // when the language is unknown.
|
|
19
|
+
function commentStarts(lang) {
|
|
20
|
+
const l = lang.toLowerCase();
|
|
21
|
+
if (/^(py|python|rb|ruby|sh|bash|zsh|shell|yaml|yml|toml|ini|makefile|make|dockerfile|r|perl)$/.test(l))
|
|
22
|
+
return ["#"];
|
|
23
|
+
if (/^(js|jsx|ts|tsx|javascript|typescript|go|rust|rs|c|cpp|cc|h|hpp|java|kt|kotlin|swift|scala|php|json5)$/.test(l))
|
|
24
|
+
return ["//"];
|
|
25
|
+
return ["#", "//"];
|
|
26
|
+
}
|
|
27
|
+
/** Split one line of code into typed tokens. Longest/most-greedy constructs first (comments, then strings)
|
|
28
|
+
* so a `#` inside a string isn't mistaken for a comment. Pure string → tokens; no color here. */
|
|
29
|
+
export function tokenize(line, lang = "") {
|
|
30
|
+
const out = [];
|
|
31
|
+
const comments = commentStarts(lang);
|
|
32
|
+
let i = 0;
|
|
33
|
+
const push = (t, k) => { if (t)
|
|
34
|
+
out.push({ t, k }); };
|
|
35
|
+
while (i < line.length) {
|
|
36
|
+
const rest = line.slice(i);
|
|
37
|
+
// line comment — consumes to end of line
|
|
38
|
+
const cs = comments.find((c) => rest.startsWith(c));
|
|
39
|
+
if (cs) {
|
|
40
|
+
push(line.slice(i), "comment");
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
// string — ", ', or ` with escape handling; if unterminated, take the rest (torn line, cosmetic)
|
|
44
|
+
const q = rest[0];
|
|
45
|
+
if (q === '"' || q === "'" || q === "`") {
|
|
46
|
+
let j = 1;
|
|
47
|
+
while (j < rest.length && rest[j] !== q) {
|
|
48
|
+
if (rest[j] === "\\")
|
|
49
|
+
j++;
|
|
50
|
+
j++;
|
|
51
|
+
}
|
|
52
|
+
const str = rest.slice(0, Math.min(j + 1, rest.length));
|
|
53
|
+
push(str, "string");
|
|
54
|
+
i += str.length;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
// number
|
|
58
|
+
const num = /^(?:0x[0-9a-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)/.exec(rest);
|
|
59
|
+
if (num) {
|
|
60
|
+
push(num[0], "number");
|
|
61
|
+
i += num[0].length;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// identifier (maybe a keyword, or a call when followed by "(")
|
|
65
|
+
const id = /^[A-Za-z_$][\w$]*/.exec(rest);
|
|
66
|
+
if (id) {
|
|
67
|
+
const word = id[0];
|
|
68
|
+
const after = rest.slice(word.length);
|
|
69
|
+
const kind = KEYWORDS.has(word) ? "keyword" : /^\s*\(/.test(after) ? "call" : "plain";
|
|
70
|
+
push(word, kind);
|
|
71
|
+
i += word.length;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// run of non-token chars (whitespace, punctuation) — kept plain, coalesced. Excludes # and / so the
|
|
75
|
+
// loop STOPS before a potential comment start and re-checks it next iteration (else " # note" would be
|
|
76
|
+
// swallowed as plain and never seen as a comment). A lone / or # that isn't a comment falls to the
|
|
77
|
+
// single-char safety push below.
|
|
78
|
+
const other = /^[^A-Za-z_$0-9"'`#/]+/.exec(rest);
|
|
79
|
+
if (other) {
|
|
80
|
+
push(other[0], "plain");
|
|
81
|
+
i += other[0].length;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// safety: consume one char so we never spin
|
|
85
|
+
push(rest[0], "plain");
|
|
86
|
+
i += 1;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
package/dist/ui/osc.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// OSC 8 hyperlinks — make file paths and URLs clickable in terminals that support it (iTerm2 ≥3.5,
|
|
2
|
+
// Ghostty, WezTerm, Kitty, VS Code's terminal). Degrades safely everywhere else: an unsupporting terminal
|
|
3
|
+
// (incl. macOS Terminal.app) renders just the visible LABEL, and ansi-regex/string-width (Ink's own deps)
|
|
4
|
+
// treat the escapes as zero-width, so column math and truncation stay correct. Pure string ops.
|
|
5
|
+
import { resolve, isAbsolute } from "node:path";
|
|
6
|
+
const OPEN = "\x1b]8;;"; // OSC 8 ; params ; URI — params empty
|
|
7
|
+
const ST = "\x1b\\"; // string terminator
|
|
8
|
+
/** True when we should emit hyperlink escapes: a real TTY, not explicitly disabled. Non-TTY (piped/
|
|
9
|
+
* headless) output must stay plain so captured logs aren't polluted with escapes. */
|
|
10
|
+
export function hyperlinksEnabled() {
|
|
11
|
+
return process.env.KODE_NO_HYPERLINKS !== "1" && !!process.stdout.isTTY;
|
|
12
|
+
}
|
|
13
|
+
/** Wrap `label` as a clickable hyperlink to `url`: OPEN+url+ST + label + OPEN+ST (empty = close). */
|
|
14
|
+
export function link(label, url) {
|
|
15
|
+
return `${OPEN}${url}${ST}${label}${OPEN}${ST}`;
|
|
16
|
+
}
|
|
17
|
+
/** Linkify a value that looks like a file path or an http(s) URL; return it unchanged otherwise. A
|
|
18
|
+
* `path:line[:col]` suffix stays in the visible label but is stripped from the file:// target. No-op
|
|
19
|
+
* when hyperlinks are disabled or the string isn't path/URL-shaped. */
|
|
20
|
+
export function fileLink(value, cwd = process.cwd()) {
|
|
21
|
+
if (!hyperlinksEnabled())
|
|
22
|
+
return value;
|
|
23
|
+
const v = value.trim();
|
|
24
|
+
if (/^https?:\/\//.test(v))
|
|
25
|
+
return link(value, v);
|
|
26
|
+
const looksPath = isAbsolute(v) || v.startsWith("./") || v.startsWith("../") || (v.includes("/") && !/\s/.test(v));
|
|
27
|
+
if (!looksPath)
|
|
28
|
+
return value;
|
|
29
|
+
const bare = v.replace(/:\d+(:\d+)?$/, ""); // drop :line[:col] from the click target
|
|
30
|
+
const abs = isAbsolute(bare) ? bare : resolve(cwd, bare);
|
|
31
|
+
return link(value, `file://${abs}`);
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export const PLAN_EXIT_OPTIONS = ["Approve & run", "Keep planning", "Cancel"];
|
|
7
|
+
export const APPROVED_PLAN_MESSAGE = "Proceed with the approved plan.";
|
|
8
|
+
/** Should exiting plan mode surface the picker instead of switching modes silently? Only when the
|
|
9
|
+
* session is actually LEAVING plan mode (current="plan", next!=="plan") AND a plan was proposed
|
|
10
|
+
* this plan-mode session — toggling plan on/off with no proposal keeps the old silent behavior. */
|
|
11
|
+
export function shouldPromptPlanExit(current, next, planProposed) {
|
|
12
|
+
return current === "plan" && next !== "plan" && planProposed;
|
|
13
|
+
}
|
|
14
|
+
/** Maps the picker's resolved answer to the outcome cli.tsx applies. QuestionPrompt always adds its
|
|
15
|
+
* own "chat about it" free-text escape on top of the given options (§ComponentDoc) — any answer that
|
|
16
|
+
* isn't a recognized option (that escape, or typed text) is treated as "keep": the safe default that
|
|
17
|
+
* changes nothing rather than silently executing or discarding the plan. */
|
|
18
|
+
export function resolvePlanExit(answer) {
|
|
19
|
+
if (answer === "Approve & run") {
|
|
20
|
+
return { action: "approve", performSwitch: true, submitText: APPROVED_PLAN_MESSAGE, message: "◆ plan approved — executing…" };
|
|
21
|
+
}
|
|
22
|
+
if (answer === "Cancel") {
|
|
23
|
+
return { action: "cancel", performSwitch: true, message: "plan cancelled — back to normal execution." };
|
|
24
|
+
}
|
|
25
|
+
return { action: "keep", performSwitch: false, message: "" };
|
|
26
|
+
}
|
package/dist/ui/term.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Terminal dimensions, floored to a sane minimum — the ONE place layout reads the window size.
|
|
2
|
+
// process.stdout.columns/rows report 0 (not undefined) when the window is minimized, hidden, or the
|
|
3
|
+
// stream is momentarily detached, and `process.stdout.columns ?? 80` does NOT catch 0 (?? only falls
|
|
4
|
+
// back on null/undefined). A 0 that leaks into layout is catastrophic: it divides in liveTail's wrap
|
|
5
|
+
// math (→ Infinity/NaN → the whole streaming message renders unbounded), and it desyncs Ink's own
|
|
6
|
+
// erase-by-line-count so every later render APPENDS instead of overwriting — the "minimize duplicated
|
|
7
|
+
// the streaming line ~30× into scrollback" bug. Read dimensions ONLY through these, so a degenerate 0
|
|
8
|
+
// can never reach the frame.
|
|
9
|
+
export function termCols(fallback = 80) {
|
|
10
|
+
const c = process.stdout.columns;
|
|
11
|
+
return typeof c === "number" && c > 0 ? c : fallback;
|
|
12
|
+
}
|
|
13
|
+
export function termRows(fallback = 24) {
|
|
14
|
+
const r = process.stdout.rows;
|
|
15
|
+
return typeof r === "number" && r > 0 ? r : fallback;
|
|
16
|
+
}
|