diff --git a/darknode.js b/darknode.js index dcee127..e717500 100755 --- a/darknode.js +++ b/darknode.js @@ -63,7 +63,7 @@ const { getSnippet, saveBody, expandSnippet } = require("./lib/cli/snippets"); / const { expandAts } = require("./lib/cli/at-mentions"); // @path → inlined file contents (TUI + line mode) const Branches = require("./lib/cli/branches"); // /branch files: what is saved, what a switch restores const { conversationText, exportMarkdown } = require("./lib/cli/convo-text"); // /find: the whole conversation (with tool output) as searchable text // /pager: read a whole tool output in-place (less-style keys + search) // click a URL / CVE / GHSA / CWE in the transcript to open it // answer markdown: highlighted code, tables, quotes, links -const { asText, sanitizeTerm, charWidth, strWidth, cutIdx, toolResultView, bootHeader, welcomeCard, idleHome, footerLine, helpLines, padRight: padRightV, ansiWrap, modelLabel, effortLabel, explainEngineError } = require("./lib/cli/tui-format"); // pure TUI layout helpers (compact boot header + model/effort display names) +const { asText, sanitizeTerm, charWidth, strWidth, cutIdx, toolResultView, bootHeader, welcomeCard, idleHome, MARK_ORBIT, orbitGlyph, activityLabel, footerLine, helpLines, padRight: padRightV, ansiWrap, modelLabel, effortLabel, explainEngineError } = require("./lib/cli/tui-format"); // pure TUI layout helpers (compact boot header + model/effort display names) const Composer = require("./lib/cli/composer"); // pure composer model + key dispatch + per-project history (lib/cli/composer.js) const Ask = require("./lib/cli/ask"); // pure renderer + key reducer for the model's ask_user multiple-choice prompt (lib/cli/ask.js) const CompactAnim = require("./lib/cli/compact-anim"); @@ -2721,9 +2721,7 @@ async function nexusRun(argv) { // Full-screen chat TUI (alt-screen, scrolling transcript, fixed bottom input box). No deps. // Whimsical status verbs — Claude Code's set PLUS Nexus-originals (marked below). -const FORGE = ["Accomplishing", "Actioning", "Actualizing", "Baking", "Booping", "Brewing", "Calculating", "Cerebrating", "Channelling", "Churning", "Coalescing", "Cogitating", "Combobulating", "Computing", "Concocting", "Conjuring", "Considering", "Cooking", "Crafting", "Creating", "Crunching", "Deliberating", "Determining", "Discombobulating", "Divining", "Doing", "Effecting", "Elucidating", "Enchanting", "Envisioning", "Finagling", "Flibbertigibbeting", "Forging", "Forming", "Frolicking", "Generating", "Germinating", "Hatching", "Herding", "Honking", "Hustling", "Ideating", "Imagining", "Incubating", "Inferring", "Jiving", "Kneading", "Manifesting", "Marinating", "Meandering", "Moseying", "Mulling", "Mustering", "Musing", "Noodling", "Percolating", "Perusing", "Philosophising", "Pondering", "Pontificating", "Processing", "Puttering", "Puzzling", "Reticulating", "Ruminating", "Scheming", "Schlepping", "Shimmying", "Shucking", "Simmering", "Smooshing", "Spelunking", "Spinning", "Stewing", "Sussing", "Synthesizing", "Thinking", "Tinkering", "Transmuting", "Unfurling", "Vibing", "Wandering", "Whirring", "Wibbling", "Wizarding", "Working", "Wrangling", - // Nexus-original verbs (built from scratch): - "Nexusing", "Nebulizing", "Weaving", "Orchestrating", "Constellating", "Tessellating", "Kindling", "Untangling", "Refracting", "Distilling", "Alchemizing", "Threading", "Warping", "Grokking", "Percussing", "Lucubrating", "Quantizing", "Foraging", "Splicing", "Braiding", "Zhuzhing", "Effervescing", "Crystallizing", "Cascading"]; +// The working line names what the turn is doing (activityLabel), not a random verb. // Feature tips shown while a turn is running. NEXUS_TIPS are engine-agnostic (Nexus's own // features); ENGINE_TIPS list ONLY what that specific AI actually offers — never mixed. const NEXUS_TIPS = [ @@ -3228,7 +3226,6 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { const cur = () => transcript[transcript.length - 1]; const ensureText = (b) => { if (!b) b = cur(); if (!b.items) b.items = []; let last = b.items[b.items.length - 1]; if (!last || last.type !== "text") { last = { type: "text", full: "", shown: 0 }; b.items.push(last); } return last; }; // ---- render body ---- - const spin = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; // Darknode logo — the official 2x2 mark (four navy rounded boxes, one yellow). // index 0 1 (TL TR) // 2 3 (BL BR) clockwise from BR: 3 -> 2 -> 0 -> 1 -> 3 @@ -3243,13 +3240,12 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { // gradient (dim end -> bright end) so it always matches /theme and /gradient. // Wall-clock driven so the cadence stays steady and frameDiff rewrites only // the one cell that changes each tick. - const _WORK = ["·", "✧", "✦", "✶", "✷", "✸", "✹", "✺", "✹", "✸", "✷", "✶", "✦", "✧"]; - const workGlyph = () => { - const i = Math.floor(Date.now() / 90) % _WORK.length, peak = _WORK.length >> 1; - const lvl = 1 - Math.abs(i - peak) / peak; // 0 at the faint point, 1 at the burst - const code = GRAD[Math.round((1 - lvl) * (GRAD.length - 1))]; // lvl 1 -> GRAD[0], the head of the theme gradient - return useColor ? "\x1b[" + code + "m" + _WORK[i] + "\x1b[0m" : _WORK[i]; - }; + // Working animation: the Darknode 2x2 mark in one cell, its lit quadrant walking + // clockwise in the accent colour. Wall-clock driven, so frameDiff rewrites one cell. + const workGlyph = () => cyan(orbitGlyph(Date.now(), 110)); + // Launch intro: the amber box walks once round the mark in the welcome header, then + // settles bottom-right where the real logo has it. markLit is part of the body signature. + let markLit = 3; // One welcome tip chosen once per session (stable across every render so the // card never flickers), rotated by start time for a little variety. const _welcomeTip = NEXUS_TIPS[Math.floor(Date.now() / 1000) % NEXUS_TIPS.length]; @@ -3264,7 +3260,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { const m = transcript[transcript.length - 1]; let last = ""; if (m) { last = (m.role || "") + ":" + (m.text ? m.text.length : 0); if (m.items) { last += ":" + m.items.length; for (const it of m.items) last += "," + (it.status || "") + "." + (it.label ? it.label.length : 0) + "." + (it.detail ? it.detail.length : 0) + "." + (it.result ? String(it.result).length : 0) + "." + (it.diff ? it.diff.length : 0) + (it.type === "text" ? "." + String(it.full || "").length + "/" + (it.shown | 0) : ""); } } // text progress too: an async command (/commit, /review ...) fills its reply after the turn ends, and a stale cache hid it - return transcript.length + "|" + cols() + "|" + (expanded ? 1 : 0) + "|" + (useColor ? 1 : 0) + "|" + effort + "|" + engine + "|" + shownModel() + "|" + guard + "|" + (gitBranch || "") + "|" + mcpServers.filter((s) => s && !s.error).length + "|" + (_welcomeTip || "") + "|" + nextQueue.length + "/" + nextQueue.join("\u0001").length + "|" + last; + return markLit + "|" + transcript.length + "|" + cols() + "|" + (expanded ? 1 : 0) + "|" + (useColor ? 1 : 0) + "|" + effort + "|" + engine + "|" + shownModel() + "|" + guard + "|" + (gitBranch || "") + "|" + mcpServers.filter((s) => s && !s.error).length + "|" + (_welcomeTip || "") + "|" + nextQueue.length + "/" + nextQueue.join("\u0001").length + "|" + last; }; let _blCache = null, _blSig = ""; // Per-message memo for the BUSY path. The whole-transcript cache above is off @@ -3318,7 +3314,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { // (model/engine/project/context), and a two-column quick-start grid that // also surfaces the customization commands (/settings, /theme). One // accent colour, no gradients. - const paint = useColor ? { brand: (t) => bold(cyan(t)), border: gray, muted: gray, faint: (t) => t, accent: (t) => bold(cyan(t)), label: (t) => gray(t), key: (t) => bold(cyan(t)) } : null; + const paint = useColor ? { brand: (t) => bold(t), border: gray, muted: gray, faint: (t) => dim(gray(t)), accent: (t) => cyan(t), label: (t) => gray(t), key: (t) => cyan(t), box: (t) => "\x1b[38;5;250m" + t + "\x1b[0m", lit: (t) => "\x1b[38;5;214m" + t + "\x1b[0m" } : null; const _liveMcp = mcpServers.filter((s) => s && !s.error).length; const cardLines = welcomeCard({ version: VERSION, model: modelLabel(shownModel()), engineLabel: (ENGINES[engine] || {}).label || engine, @@ -3326,7 +3322,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { effort: (ENGINES[engine] && ENGINES[engine].kind === "stream" && effort) ? effortLabel(effort) : "", contextLabel: Math.round((sess.ctxWindow || 200000) / 1000) + "K", guard: guard === "enforce" ? "on" : guard, - mcp: _liveMcp, tip: _welcomeTip, + mcp: _liveMcp, tip: _welcomeTip, lit: markLit, }); for (const ln of cardLines) L.push(ln); continue; @@ -3367,14 +3363,10 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { if (m.role === "recap") { recapLines(m.text).forEach((x) => L.push(x)); L.push(""); continue; } if (m.role === "system") { if (m.lines) for (const ln of m.lines) L.push(gray("│ ") + ln); else for (const ln of wrap(m.text)) L.push(" " + ln); L.push(""); continue; } if (m.role === "user") { - // the submitted prompt sits on a full-width grey block (the Claude-Code - // look): a 236 background that spans to the right margin, re-asserted - // after every reset so the coloured ❯/bold tokens don't punch holes. const w = wrap(m.text); - const _uw = Math.max(0, cols() - 3); // inner width of the grey block (flush-left ❯, Claude-Code look) - const chatHl = (c) => "\x1b[48;5;236m" + String(c).replace(/\x1b\[0m/g, "\x1b[0m\x1b[48;5;236m") + " ".repeat(Math.max(0, _uw - strWidth(c))) + " \x1b[0m"; - L.push(chatHl(cyan("❯ ") + bold(w[0] || ""))); - for (let i = 1; i < w.length; i++) L.push(chatHl(" " + bold(w[i]))); + // the submitted prompt: an accent bar down its left edge, text in bold + L.push(cyan("▌") + " " + bold(w[0] || "")); + for (let i = 1; i < w.length; i++) L.push(cyan("▌") + " " + bold(w[i])); L.push(""); continue; } // nexus turn: ordered items. Each text block opens with a plain bullet, @@ -3385,16 +3377,16 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { if (prevType) L.push(""); const vis = it.full.slice(0, it.shown); let first = true; - for (const ln of mdLines(it, vis, Math.max(1, cols() - 4))) { const lead = first && stripA(ln).trim() ? "● " : " "; if (stripA(ln).trim()) first = false; L.push(lead + ln); } + for (const ln of mdLines(it, vis, Math.max(1, cols() - 4))) { const lead = first && stripA(ln).trim() ? cyan("▪") + " " : " "; if (stripA(ln).trim()) first = false; L.push(lead + ln); } prevType = "text"; } else if (it.type === "thinking") { if (prevType) L.push(""); - L.push(dim(gray("∴ Thinking" + (expanded ? "" : " (ctrl+o to expand)")))); + L.push(dim(gray("· thinking" + (expanded ? "" : " ctrl+o to read")))); if (expanded) for (const ln of wrap(it.full).slice(0, 24)) L.push(" " + dim(gray(ln))); prevType = "thinking"; } else if (it.type === "tool") { if (prevType) L.push(""); - const dot = it.status === "run" || it.status === "wait" ? cyan(spin[Math.floor(Date.now() / 90) % spin.length]) : it.status === "err" ? red("●") : green("●"); + const dot = it.status === "run" || it.status === "wait" ? workGlyph() : it.status === "err" ? red("✗") : green("✓"); const rawSec = it.end ? (it.end - it.start) / 1000 : (Date.now() - it.start) / 1000; const secs = rawSec < 0.1 ? "<0.1s" : fmtDur(rawSec); const _lp = it.label.indexOf("("); @@ -3405,7 +3397,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { const d = it.diff, dw = Math.max(12, Math.min(cols() - 7, 120)); const _pl = (n, w) => n + " " + w + (n === 1 ? "" : "s"), _fn = (it.label.match(/\((.*)\)$/) || [])[1] || "file"; const cnt = /^Write\(/.test(it.label) ? "Wrote " + _pl(d.added, "line") + " to " + bold(_fn) : !(d.added + d.removed) ? "No changes to " + bold(_fn) : "Updated " + bold(_fn) + " with " + [d.added ? _pl(d.added, "addition") : "", d.removed ? _pl(d.removed, "removal") : ""].filter(Boolean).join(" and "); - L.push(" " + gray("⎿") + " " + cnt); + L.push(" " + gray("╰─") + " " + cnt); const cap = expanded ? 200 : 16; const rows = d.rows.slice(0, cap); const gw = rows.reduce((w, r) => Math.max(w, r.ln ? String(r.ln).length : 0), 0); // line-number gutter (0 = no numbers known) @@ -3438,7 +3430,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { // a todo checklist, red "Error: …" — not the raw tool JSON. const v = toolResultView(it.name, it.input, it.result !== undefined ? it.result : it.detail, { isError: it.status === "err" && !it.interrupted, interrupted: it.interrupted, expanded, secs }); let first = true; - const pre = () => { const p = first ? " " + gray("⎿") + " " : " "; first = false; return p; }; + const pre = () => { const p = first ? " " + gray("╰─") + " " : " "; first = false; return p; }; for (const ln of v.lines) { if (ln.k === "todo") { L.push(pre() + (ln.s === "done" ? gray("☒ ") + dim(strike(ln.text)) : ln.s === "active" ? bold("☐ " + ln.text) : "☐ " + ln.text)); continue; } for (const w of wrap(stripA(ln.text)).slice(0, expanded ? 40 : 2)) L.push(pre() + (ln.k === "err" ? red(w) : ln.k === "out" ? w : gray(w))); @@ -3447,14 +3439,14 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { } else if (it.status === "run" && (it.name === "Bash" || it.name === "run_command")) { // live tail: the last lines the command printed, so you can see what it is doing right now const tl = it.live ? Tail.tailLines(it.live, expanded ? 12 : 3) : []; - if (!tl.length) L.push(" " + gray("⎿") + " " + gray("Running…")); - tl.forEach((x, k) => L.push((k ? " " : " " + gray("⎿") + " ") + dim(clip(x, Math.max(8, cols() - 9))))); + if (!tl.length) L.push(" " + gray("╰─") + " " + gray("Running…")); + tl.forEach((x, k) => L.push((k ? " " : " " + gray("╰─") + " ") + dim(clip(x, Math.max(8, cols() - 9))))); const seen = it.live ? Tail.lineCount(it.live) : 0; if (seen > tl.length) L.push(gray(" " + seen.toLocaleString("en-US") + " lines so far · /pager to read all")); } else if (it.detail && (done || expanded)) { const dl = wrap(stripA(it.detail)).filter((x) => x.trim()); const n = expanded ? 8 : 1; - dl.slice(0, n).forEach((x, k) => L.push((k ? " " : " " + cyan("⎿") + " ") + gray(x))); + dl.slice(0, n).forEach((x, k) => L.push((k ? " " : " " + cyan("╰─") + " ") + gray(x))); if (dl.length > n) L.push(gray(" … +" + (dl.length - n) + " line" + (dl.length - n > 1 ? "s" : "") + " (ctrl+o to expand)")); } prevType = "tool"; @@ -3467,10 +3459,10 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { const et = ENGINE_TIPS[engine] || [], tips = []; for (let k = 0; k < Math.max(NEXUS_TIPS.length, et.length); k++) { if (et[k]) tips.push(et[k]); if (NEXUS_TIPS[k]) tips.push(NEXUS_TIPS[k]); } // interleave so an engine-specific tip shows first L.push(""); - L.push(workGlyph() + " " + cyan(busyWord + "…") + gray(" (" + fmtElapsed(el) + tok + " · esc to interrupt)")); - if (tips.length) L.push(" " + gray("⎿ Tip: " + tips[Math.floor(el / 4) % tips.length])); + L.push(workGlyph() + " " + cyan(clip(busyWord || activityLabel(m.items), Math.max(10, cols() - 34))) + gray(" " + fmtElapsed(el) + tok + " · esc to stop")); + if (tips.length) L.push(" " + gray("╰─ ") + dim(gray("tip " + tips[Math.floor(el / 6) % tips.length]))); } else if (m.summary) { - L.push(" " + cyan("⎿") + " " + gray(m.summary)); + L.push(" " + cyan("╰─") + " " + gray(m.summary)); } if (m.recap && !(busy && m === cur())) recapLines(m.recap).forEach((x) => L.push(x)); L.push(""); @@ -3482,10 +3474,9 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { // and a live project pulse — so a fresh session reads as a product, not a void. if (transcript.length === 1 && transcript[0].role === "art" && !busy) { loadIdleInfo(); - const paint = useColor ? { brand: (t) => bold(cyan(t)), accent: (t) => bold(cyan(t)), muted: gray, faint: (t) => dim(gray(t)), key: (t) => bold(cyan(t)) } : null; - const grad = useColor ? (line) => { let o = ""; for (let c = 0; c < line.length; c++) { const ch = line[c]; if (ch === " ") { o += " "; continue; } const code = GRAD[Math.min(GRAD.length - 1, Math.floor((c / Math.max(1, line.length)) * GRAD.length))]; o += "\x1b[" + code + "m" + ch + "\x1b[0m"; } return o; } : null; + const paint = useColor ? { accent: (t) => cyan(t), muted: gray, faint: (t) => dim(gray(t)), key: (t) => cyan(t) } : null; const project = gitBranch ? { name: base(cwd), branch: gitBranch.replace(/\*$/, ""), dirty: /\*$/.test(gitBranch), files: idleInfo ? idleInfo.files : undefined, commits: idleInfo ? idleInfo.commits : undefined, last: idleInfo ? idleInfo.last : undefined } : null; - for (const ln of idleHome({ cols: cols(), paint, grad, project })) L.push(ln); + for (const ln of idleHome({ cols: cols(), paint, project })) L.push(ln); } // Live task panel (todo_write) — a persistent checklist like Claude Code's // TodoWrite, shown at the bottom of the transcript while any task is open. @@ -4331,7 +4322,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { const relOf = (p) => { try { return path.relative(cwd, path.resolve(cwd, p)); } catch (_) { return null; } }; const ckTree = nexusCheckpoint(cwd); // every engine can now modify files, so always checkpoint (null if not a git repo) let ckObj = null; if (ckTree) { ckObj = { tree: ckTree, label: oneline(text, 40), ts: Date.now() }; checkpoints.push(ckObj); } - busy = true; busyStart = Date.now(); busyWord = FORGE[Math.floor(Math.random() * FORGE.length)]; sess.liveOut = 0; curTurnFromQueue = _nextFromQueue; _nextFromQueue = false; setTitle("● " + (sessionTitle || "Nexus")); + busy = true; busyStart = Date.now(); busyWord = ""; sess.liveOut = 0; curTurnFromQueue = _nextFromQueue; _nextFromQueue = false; setTitle("● " + (sessionTitle || "Nexus")); ctl = makeCtl(); // local engine checks .stopped; claude overrides .kill with a process kill startTick(); render(); const finish = (res) => { @@ -6889,7 +6880,11 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) { // No animation, no starfield, no latency: render the compact header (see the // "art" transcript row) straight away. fastBoot/NO_MOTION kept for parity. finishBoot(); - void fastBoot; + if (!fastBoot && useColor && transcript.length === 1 && transcript[0].role === "art") { + let step = 0; + const intro = setInterval(() => { step++; markLit = MARK_ORBIT[step % MARK_ORBIT.length]; if (step >= MARK_ORBIT.length) { clearInterval(intro); markLit = 3; } try { render(); } catch (_) { clearInterval(intro); } }, 170); + if (intro.unref) intro.unref(); + } }); } // add `.nexus/` to .gitignore (Nexus's state dir shouldn't clutter git); returns true if it added it diff --git a/lib/cli/tui-format.js b/lib/cli/tui-format.js index 193b653..041c735 100644 --- a/lib/cli/tui-format.js +++ b/lib/cli/tui-format.js @@ -235,136 +235,110 @@ function modelLabel(id) { // caller can omit it rather than invent a level. function effortLabel(effort) { const e = String(effort || "").trim(); return e ? e + " effort" : ""; } -// Welcome card shown at the top of a fresh session: a rounded box with the -// product name + version, the active model/engine, the working directory and -// branch, and one line of starter hints. opts: { version, model, engineLabel, -// cwd, branch, home, cols, paint }. paint roles: brand, border, muted, faint. -// Plain (no escapes) when paint is omitted; fits 40-120 cols. +// The Darknode mark for the terminal: the official 2x2 grid of square boxes, +// three neutral and one brand amber. Each box is 3 cols x 1.5 rows (terminal +// cells are about 1:2, so it reads square), drawn with full and upper-half +// blocks so the gap between the rows is half a cell. `lit` picks the amber box +// (0 TL, 1 TR, 2 BL, 3 BR = the real logo); the intro animation walks it round +// the grid once. paint roles: box (neutral), lit (amber). Returns 4 rows, 7 wide. +const MARK_W = 7; +function logoMark(opts) { + opts = opts || {}; + const P = opts.paint || {}, id = (s) => s; + const box = P.box || id, hot = P.lit || id; + const lit = opts.lit == null ? 3 : ((opts.lit % 4) + 4) % 4; + const c = (i, g) => (i === lit ? hot : box)(g.repeat(3)); + return [c(0, "█") + " " + c(1, "█"), c(0, "▀") + " " + c(1, "▀"), c(2, "█") + " " + c(3, "█"), c(2, "▀") + " " + c(3, "▀")]; +} +// Clockwise orbit of the amber box used by the intro: BR -> BL -> TL -> TR -> BR. +const MARK_ORBIT = [3, 2, 0, 1]; + +// Welcome header shown at the top of a fresh session: the Darknode mark with the +// session beside it (product + version, model and engine, project and branch, +// context / guard / MCP), then one row of commands and one tip. Everything sits +// on one left edge; no box, no wordmark. opts: { version, model, engineLabel, +// effort, cwd, branch, home, cols, contextLabel, guard, mcp, tip, lit, paint }. +// paint roles: brand, accent, muted, faint, key, label, box, lit. Plain when +// paint is omitted; fits 30+ cols. function welcomeCard(opts) { opts = opts || {}; const cols = Math.max(30, opts.cols || 80); - const W = Math.min(cols - 2, 74); // outer width incl. borders - const inner = W - 4; // text width between "│ " and " │" - const narrow = inner < 46; // drop to a compact layout on small terminals + const W = cols - 2; // usable width (renderer adds a 1-col gutter) const P = opts.paint || {}; const id = (s) => s; - const brand = P.brand || id, border = P.border || id, muted = P.muted || id, faint = P.faint || id; - const accent = P.accent || brand, label = P.label || muted, key = P.key || brand; + const brand = P.brand || id, muted = P.muted || id, faint = P.faint || id; + const accent = P.accent || brand, key = P.key || brand; const version = opts.version ? "v" + String(opts.version).replace(/^v/, "") : ""; - const row = (s) => border("│") + " " + padRight(fitWidth(s, inner), inner) + " " + border("│"); - const rule = () => border("├" + "─".repeat(W - 2) + "┤"); - const lines = [""]; - lines.push(border("╭" + "─".repeat(W - 2) + "╮")); - // ---- title: brand + tagline on the left, version on the right ---- - const tagline = "agentic coding in your terminal"; - const titleFull = brand("Nexus") + " " + faint(tagline); - if (!narrow && inner - visLen(titleFull) - version.length >= 2) { - lines.push(row(titleFull + " ".repeat(inner - visLen(titleFull) - version.length) + faint(version))); - } else { - const b = brand("Nexus"); const g = inner - visLen(b) - version.length; - lines.push(row(g >= 2 ? b + " ".repeat(g) + faint(version) : b)); - } - lines.push(rule()); - // ---- session details: aligned label / value rows ---- - const kv = (k, v) => lines.push(row(" " + label(padRight(k, 10)) + v)); - if (opts.model) kv("Model", brand(opts.model) + (opts.effort ? muted(" · ") + faint(opts.effort) : "")); - if (opts.engineLabel) kv("Engine", opts.engineLabel); - // Give the path whatever room the branch leaves, but keep a small floor so a - // long branch never starves the path to "" and drops the whole row — the - // branch is the most useful "where am I" cue, so the row must survive. kv() - // fitWidth-truncates the combined value, so neither side can overflow. + const sep = muted(" · "); + const withMark = W >= MARK_W + 2 + 24; // mark beside the text; dropped on tiny terminals + const tw = withMark ? W - 1 - MARK_W - 3 : W - 1; + const info = []; + info.push(brand("Nexus") + (version ? " " + faint(version) : "")); + const who = []; + if (opts.model) who.push(accent(opts.model) + (opts.effort ? " " + faint(opts.effort) : "")); + if (opts.engineLabel) who.push(muted(opts.engineLabel)); + info.push(who.join(sep)); const branchStr = opts.branch || ""; - const where = opts.cwd ? shortenPath(opts.cwd, Math.max(6, inner - 12 - (branchStr ? branchStr.length + 5 : 0)), opts.home) : ""; - if (where || branchStr) kv("Project", muted(where) + (branchStr ? (where ? muted(" · ") : "") + accent(branchStr) : "")); + const where = opts.cwd ? shortenPath(opts.cwd, Math.max(6, tw - (branchStr ? branchStr.length + 5 : 0)), opts.home) : ""; + info.push(where || branchStr ? muted(where) + (branchStr ? (where ? sep : "") + accent(branchStr) : "") : ""); const sess = []; if (opts.contextLabel) sess.push(opts.contextLabel + " context"); if (opts.guard) sess.push("guard " + opts.guard); if (opts.mcp) sess.push(opts.mcp + " MCP server" + (opts.mcp > 1 ? "s" : "")); - if (sess.length) kv("Session", muted(sess.join(" · "))); - // ---- quick start: two-column command grid (surfaces customization too) ---- - lines.push(rule()); - lines.push(row(accent("Quick start"))); - const QUICK = opts.quickCommands || [ - ["/help", "all commands"], ["/open", "web dashboard"], - ["/model", "switch model"], ["/agents", "background agents"], - ["/mcp", "manage servers"], ["/settings", "preferences"], - ["/theme", "colors & look"], ["/resume", "resume a session"], - ]; - const kw = 11; // command-name column width - const cell = (pair, w) => padRight(key(pair[0]), kw) + muted(fitWidth(pair[1], Math.max(4, w - kw))); - if (narrow) { - for (const p of QUICK) lines.push(row(" " + cell(p, inner - 2))); + info.push(faint(sess.join(" · "))); + const lines = [""]; + if (withMark) { + const mk = logoMark({ lit: opts.lit, paint: P }); + for (let r = 0; r < 4; r++) lines.push(mk[r] + " " + fitWidth(info[r], tw)); } else { - const half = Math.floor((inner - 2) / 2); - for (let i = 0; i < QUICK.length; i += 2) { - const l = cell(QUICK[i], half); - const r = QUICK[i + 1] ? cell(QUICK[i + 1], inner - 2 - half) : ""; - lines.push(row(" " + padRight(l, half) + r)); - } + for (const r of info) if (visLen(r)) lines.push(fitWidth(r, tw)); + } + lines.push(""); + // ---- commands: one row, as many as fit ---- + const QUICK = opts.quickCommands || [["/help", "commands"], ["/model", "switch model"], ["/resume", "last session"], ["/theme", "look"], ["/agents", "background"], ["/settings", "preferences"]]; + let row = "", rw = 0; + for (const [k, d] of QUICK) { + const cell = key(k) + " " + muted(d), cw = k.length + 1 + d.length + (row ? 4 : 0); + if (rw + cw > W - 1) break; + row += (row ? " " : "") + cell; rw += cw; } - // ---- tip line ---- + if (row) lines.push(row); + // ---- tip: wrapped under its label ---- if (opts.tip) { - // word-wrap the tip under its label instead of truncating it with "…" - lines.push(rule()); - const tw = Math.max(10, inner - 10), out = []; + const lw = 5, ww = Math.max(10, W - 1 - lw), out = []; let cur = ""; for (const w of String(opts.tip).split(/\s+/).filter(Boolean)) { - if (cur && visLen(cur) + 1 + visLen(w) > tw) { out.push(cur); cur = w; } else cur = cur ? cur + " " + w : w; + if (cur && visLen(cur) + 1 + visLen(w) > ww) { out.push(cur); cur = w; } else cur = cur ? cur + " " + w : w; } if (cur) out.push(cur); - out.slice(0, 3).forEach((t, i) => lines.push(row((i ? " ".repeat(10) : label(padRight("Tip", 10))) + faint(t)))); + out.slice(0, 3).forEach((t, i) => lines.push((i ? " ".repeat(lw) : muted(padRight("tip", lw))) + faint(fitWidth(t, ww)))); } - lines.push(border("╰" + "─".repeat(W - 2) + "╯")); lines.push(""); return lines; } -// Idle "home" shown below the welcome card while the chat is still empty, so a -// fresh session fills the screen instead of a dark void: a large gradient NEXUS -// wordmark, a one-line positioning strip, a few real "try asking" starter prompts, -// and a live one-line project pulse. Pure layout — every colour comes from -// opts.paint / opts.grad, so it degrades to readable plain text under NO_COLOR. -// opts: { cols, paint, grad, suggestions:[string], project:{name,branch,dirty,files,commits,last} } -// paint roles: brand, accent, muted, faint, key. grad(plainLine)->coloured (hero only). -const _NX_GLYPHS = { - N: ["█ █", "██ █", "█ █ █", "█ ██", "█ █"], - E: ["█████", "█ ", "████ ", "█ ", "█████"], - X: ["█ █", " █ █ ", " █ ", " █ █ ", "█ █"], - U: ["█ █", "█ █", "█ █", "█ █", "█████"], - S: ["█████", "█ ", "█████", " █", "█████"], -}; +// Idle "home" shown below the welcome header while the chat is still empty: +// a few real starter prompts and a live one-line project pulse, on the same left +// edge as the header. Pure layout; colours come from opts.paint, so it reads as +// plain text under NO_COLOR. +// opts: { cols, paint, suggestions:[string], project:{name,branch,dirty,files,commits,last} } +// paint roles: accent, muted, faint, key. function idleHome(opts) { opts = opts || {}; const cols = Math.max(30, opts.cols || 80); - const W = cols - 2; // usable width (the renderer adds a 1-col gutter) + const W = cols - 2; const P = opts.paint || {}; const id = (s) => s; - const brand = P.brand || id, accent = P.accent || id, muted = P.muted || id, faint = P.faint || id, key = P.key || brand; - const grad = opts.grad || null; - const center = (s, w) => " ".repeat(Math.max(0, Math.floor((W - w) / 2))) + s; // w = visible width of `s` - const L = ["", ""]; - // ---- hero wordmark: NEXUS in 5-row block letters, swept with the theme gradient ---- - const hero = ["", "", "", "", ""]; - "NEXUS".split("").forEach((ch, li) => { const g = _NX_GLYPHS[ch]; for (let r = 0; r < 5; r++) hero[r] += (li ? " " : "") + g[r]; }); - const heroW = hero[0].length; // 29 for NEXUS - if (heroW <= W) { for (const r of hero) L.push(center(grad ? grad(r) : brand(r), heroW)); } - else { const w = "N E X U S"; L.push(center(brand(w), w.length)); } // compact fallback on a very narrow terminal - L.push(""); - const sub = "runs on your machine · your keys & data stay yours · six engines, one agent"; - if (visLen(sub) <= W) L.push(center(faint(sub), visLen(sub))); - L.push(""); L.push(""); - // ---- try asking: real starter prompts, left-aligned under a centred heading ---- + const accent = P.accent || id, muted = P.muted || id, faint = P.faint || id, key = P.key || accent; + const L = [""]; const sugg = (opts.suggestions && opts.suggestions.length ? opts.suggestions : [ "explain what this project does and how it is structured", "find a bug, fix it, and run the tests", "scan this repository for leaked secrets", "review my uncommitted changes", - ]).map((s) => fitWidth(s, Math.max(10, W - 4))); - const blockW = sugg.reduce((m, s) => Math.max(m, visLen(s) + 2), 0); // +2 for the "❯ " prefix - L.push(center(accent("Try asking"), 10)); - L.push(""); - for (const s of sugg) L.push(center(key("❯ ") + muted(s), blockW)); - // ---- project pulse: one live line of real repo context ---- + ]).map((s) => fitWidth(s, Math.max(10, W - 5))); + L.push(muted("start with")); + for (const s of sugg) L.push(key("›") + " " + s); const pr = opts.project; if (pr && pr.name) { const seg = [accent(pr.name)]; @@ -372,15 +346,42 @@ function idleHome(opts) { if (typeof pr.files === "number") seg.push(muted(pr.files + " file" + (pr.files === 1 ? "" : "s"))); if (pr.commits) seg.push(muted(pr.commits + " commit" + (pr.commits === 1 ? "" : "s"))); seg.push(muted(pr.dirty ? "uncommitted changes" : "working tree clean")); - const line = seg.join(faint(" · ")); - L.push(""); L.push(""); - L.push(center(fitWidth(line, W), Math.min(visLen(line), W))); - if (pr.last) { const last = faint("latest " + pr.last); L.push(center(fitWidth(last, W), Math.min(visLen(last), W))); } + L.push(""); + L.push(fitWidth(seg.join(faint(" · ")), W - 1)); + if (pr.last) L.push(fitWidth(faint("latest " + pr.last), W - 1)); } L.push(""); return L; } +// Activity glyph: one quadrant of a 2x2 cell lit, walking clockwise round it +// (TL, TR, BR, BL), the Darknode mark in a single character. Wall-clock driven. +const ORBIT_GLYPHS = ["▘", "▝", "▗", "▖"]; +function orbitGlyph(now, period) { const n = Math.floor((now == null ? Date.now() : now) / (period || 110)); return ORBIT_GLYPHS[((n % 4) + 4) % 4]; } + +// What a running turn is doing right now, from its items: the running tool +// ("Reading app.js", "Running npm test"), else thinking / writing. Plain text. +function activityLabel(items) { + const list = Array.isArray(items) ? items : []; + for (let i = list.length - 1; i >= 0; i--) { + const it = list[i]; + if (!it) continue; + if (it.type === "tool" && (it.status === "run" || it.status === "wait")) { + const lab = String(it.label || it.name || "tool"); + const m = lab.match(/^([A-Za-z_:.-]+)\((.*)\)$/); + const name = m ? m[1] : lab, arg = m ? m[2] : ""; + const VERB = { Read: "Reading", Write: "Writing", Edit: "Editing", Update: "Editing", MultiEdit: "Editing", Bash: "Running", Search: "Searching", Grep: "Searching", Glob: "Finding", Fetch: "Fetching", WebFetch: "Fetching", List: "Listing", Plan: "Planning", Task: "Delegating", Agent: "Delegating" }; + const v = VERB[name]; + if (it.status === "wait") return "Waiting for approval" + (arg ? ": " + name + " " + arg : ""); + return v ? v + (arg ? " " + arg : "") : "Using " + name + (arg ? " " + arg : ""); + } + if (it.type === "thinking") return "Thinking"; + if (it.type === "text") return "Writing"; + if (it.type === "tool") return "Working"; + } + return "Thinking"; +} + // One footer row: `left` hint text and `right` status text, right-aligned to // `cols`. When both don't fit, the left side is shortened first, then dropped; // the right side is clipped last. Returns the row (ANSI preserved). @@ -529,4 +530,4 @@ function toolResultView(name, input, content, opts) { return clipOut(all.filter((l) => l.trim()), "out"); } -module.exports = { asText, sanitizeTerm, charWidth, strWidth, cutIdx, toolResultView, ccName, stripAnsi, visLen, fitWidth, ansiWrap, padRight, shortenPath, bootHeader, welcomeCard, idleHome, footerLine, helpLines, modelLabel, effortLabel, explainEngineError }; +module.exports = { asText, sanitizeTerm, charWidth, strWidth, cutIdx, toolResultView, ccName, stripAnsi, visLen, fitWidth, ansiWrap, padRight, shortenPath, bootHeader, welcomeCard, idleHome, logoMark, MARK_ORBIT, orbitGlyph, activityLabel, footerLine, helpLines, modelLabel, effortLabel, explainEngineError }; diff --git a/test/composer.test.js b/test/composer.test.js index 6f62dd8..ee87d16 100644 --- a/test/composer.test.js +++ b/test/composer.test.js @@ -313,10 +313,10 @@ group("shortenPath — zero/negative width yields empty, like fitWidth"); group("idleHome — fills the empty-chat screen, never overflows, stays plain under NO_COLOR"); { const L = TF.idleHome({ cols: 80, project: { name: "proj", branch: "main", dirty: true, files: 7, commits: 3, last: "init" } }); - ok("returns several rows of content", L.length >= 15); - ok("renders the NEXUS wordmark (block letters)", L.some((r) => /█/.test(r))); + ok("returns several rows of content", L.length >= 8); + ok("no block-letter wordmark (the mark lives in the header)", !L.some((r) => /█/.test(r))); ok("no row exceeds the usable width (cols-2)", Math.max.apply(null, L.map((r) => TF.visLen(r))) <= 78); - ok("shows the Try asking heading", L.some((r) => /Try asking/.test(r))); + ok("shows the starter-prompt heading", L.some((r) => /start with/.test(r))); ok("includes a real starter prompt", L.some((r) => /scan this repository for leaked secrets/.test(r))); ok("project pulse shows name + branch + file/commit counts", L.some((r) => /proj/.test(r)) && L.some((r) => /7 files/.test(r) && /3 commits/.test(r))); ok("dirty tree is reported", L.some((r) => /uncommitted changes/.test(r))); @@ -327,7 +327,7 @@ group("idleHome — fills the empty-chat screen, never overflows, stays plain un const noRepo = TF.idleHome({ cols: 80 }); ok("no project pulse when not in a repo", !noRepo.some((r) => /working tree clean|\d+ files?|\d+ commits?/.test(r))); const narrow = TF.idleHome({ cols: 30 }); - ok("narrow terminal uses the compact wordmark without overflow", Math.max.apply(null, narrow.map((r) => TF.visLen(r))) <= 28); + ok("narrow terminal does not overflow", Math.max.apply(null, narrow.map((r) => TF.visLen(r))) <= 28); } group("persisted prefs — /style and /redact round-trip; dead defaults removed"); diff --git a/test/tui-layout.test.js b/test/tui-layout.test.js index 49f1a1e..bb01009 100644 --- a/test/tui-layout.test.js +++ b/test/tui-layout.test.js @@ -31,7 +31,9 @@ group("welcomeCard fits its column budget at every width"); let bad = ""; for (const w of WIDTHS) if (!fits(WC(w), w)) bad = bad || ("overflow/escape at " + w); ok("every row fits 36..200 cols with no stray escapes", !bad); - ok("the box is balanced (equal corner rows)", (() => { const L = WC(80).filter((l) => l.trim()); return /^╭/.test(stripAnsi(L[0])) && /╯$/.test(stripAnsi(L[L.length - 1])); })()); + ok("draws the Darknode 2x2 mark beside the session", (() => { const L = WC(80).map(stripAnsi); return L.some((l) => /^███ ███ Nexus/.test(l)) && L.filter((l) => /^(███|▀▀▀) (███|▀▀▀)/.test(l)).length === 4; })()); + ok("lit moves the amber box (paint.lit) round the grid", (() => { const P = { box: (t) => "b" + t, lit: (t) => "L" + t }; const m = F.logoMark({ paint: P, lit: 0 }); return m[0].startsWith("L███") && !m[2].includes("L") && F.logoMark({ paint: P })[2].includes("L███"); })()); + ok("drops the mark on a tiny terminal but keeps the text", (() => { const s = stripAnsi(WC(30).join("\n")); return !s.includes("███") && /Nexus/.test(s); })()); ok("plain output (no paint) carries no ANSI escapes", plainClean(WC(80))); ok("shows product, model, engine and a quick-start command", (() => { const s = WC(80).join("\n"); return /Nexus/.test(s) && /Opus 5\.5/.test(s) && /Claude Code/.test(s) && /\/help/.test(s); })()); } @@ -43,7 +45,7 @@ group("welcomeCard keeps the branch even when it is long and the terminal is nar ok("branch (possibly truncated) is still shown at 36 cols", stripAnsi(WC(36).join("\n")).includes("ui/tui")); for (const w of [40, 50]) ok("branch is still shown at " + w + " cols", stripAnsi(WC(w).join("\n")).includes("ui/tui-pol")); ok("a card with only a branch (no cwd) still shows it", stripAnsi(WC(80, { cwd: "" }).join("\n")).includes("ui/tui-polish-20261101")); - ok("a card with neither cwd nor branch omits the Project row", !/Project/.test(stripAnsi(WC(80, { cwd: "", branch: "" }).join("\n")))); + ok("a card with neither cwd nor branch shows no path", !/darknode-cli|~\//.test(stripAnsi(WC(80, { cwd: "", branch: "" }).join("\n")))); } group("idleHome fills the screen without overflowing"); @@ -53,9 +55,9 @@ group("idleHome fills the screen without overflowing"); for (const w of WIDTHS) if (!fits(mk(w), w)) bad = bad || ("overflow/escape at " + w); ok("every row fits 36..200 cols with no stray escapes", !bad); ok("plain output carries no ANSI escapes", plainClean(mk(80))); - ok("renders the NEXUS hero wordmark", mk(80).join("\n").includes("█")); + ok("lists starter prompts with no block-letter wordmark", (() => { const s = mk(80).join("\n"); return /start with/.test(s) && /› review my uncommitted changes/.test(s) && !s.includes("█"); })()); ok("surfaces the live project pulse (name + branch)", (() => { const s = stripAnsi(mk(80).join("\n")); return s.includes("darknode-cli") && /\bmain\b/.test(s); })()); - ok("falls back to a compact wordmark on a very narrow terminal", stripAnsi(idleHome({ cols: 20 }).join("\n")).includes("N E X U S")); + ok("still fits on a very narrow terminal", fits(idleHome({ cols: 20 }), 30)); } group("footerLine right-aligns status and never overflows"); @@ -81,5 +83,14 @@ group("helpLines aligns names and wraps long descriptions under the column"); ok("wraps a long description onto continuation rows (name column stays empty)", (() => { const L = helpLines(sections, 60).map(stripAnsi); const i = L.findIndex((l) => /\/fixshell/.test(l)); if (i < 0 || i + 1 >= L.length) return false; const cont = L[i + 1]; const indent = (s) => s.length - s.replace(/^ +/, "").length; return cont.trim().length > 0 && !/\/fixshell/.test(cont) && indent(cont) > indent(L[i]); })()); } +group("activity line names what the turn is doing"); +{ + ok("a running tool reads as a verb + target", F.activityLabel([{ type: "text" }, { type: "tool", status: "run", label: "Bash(npm test)" }]) === "Running npm test"); + ok("a tool waiting on approval says so", /^Waiting for approval/.test(F.activityLabel([{ type: "tool", status: "wait", label: "Edit(a.js)" }]))); + ok("thinking / writing / nothing yet", F.activityLabel([{ type: "thinking" }]) === "Thinking" && F.activityLabel([{ type: "text" }]) === "Writing" && F.activityLabel([]) === "Thinking"); + ok("an unknown tool falls back to Using ", F.activityLabel([{ type: "tool", status: "run", label: "repo_map()" }]) === "Using repo_map"); + ok("the orbit glyph walks the four quadrants clockwise", [0, 110, 220, 330, 440].map((t) => F.orbitGlyph(t, 110)).join("") === "▘▝▗▖▘"); +} + console.log("\n" + (fail ? "\x1b[31m" : "\x1b[32m") + pass + " passed, " + fail + " failed\x1b[0m" + " (tui layout)"); process.exit(fail ? 1 : 0);