@0perator/operator 0.1.352 → 0.1.353

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.
Files changed (90) hide show
  1. package/dist/acp/agent.js +2 -2
  2. package/dist/acp/tool-map.js +5 -4
  3. package/dist/autonomy/delegate.js +54 -1
  4. package/dist/autonomy/headless.js +2 -0
  5. package/dist/autonomy/session-factory.js +1 -0
  6. package/dist/background/index.js +86 -10
  7. package/dist/background/notices.js +16 -4
  8. package/dist/cli.js +1066 -175
  9. package/dist/config/home.js +6 -0
  10. package/dist/config/memory-sections.js +92 -0
  11. package/dist/config/persona.js +144 -26
  12. package/dist/config/settings.js +15 -4
  13. package/dist/consolidation/scheduler.js +9 -2
  14. package/dist/consolidation/sleep.js +39 -278
  15. package/dist/engine/agent.js +444 -76
  16. package/dist/engine/anthropic-chat.js +13 -2
  17. package/dist/engine/aurora.js +43 -19
  18. package/dist/engine/batch-scheduler.js +27 -3
  19. package/dist/engine/compaction.js +12 -5
  20. package/dist/engine/continuation.js +14 -12
  21. package/dist/engine/contract.js +1 -1
  22. package/dist/engine/decision-points.js +7 -1
  23. package/dist/engine/front-door.js +59 -0
  24. package/dist/engine/grandmaster.js +13 -1
  25. package/dist/engine/loop-guard.js +694 -0
  26. package/dist/engine/owner-act.js +52 -0
  27. package/dist/engine/verify-gate.js +52 -0
  28. package/dist/flywheel/processor.js +3 -1
  29. package/dist/flywheel/srft.js +8 -4
  30. package/dist/hooks/index.js +12 -8
  31. package/dist/mcp/index.js +9 -4
  32. package/dist/permissions/index.js +32 -11
  33. package/dist/permissions/modes.js +42 -0
  34. package/dist/permissions/plan-review.js +100 -0
  35. package/dist/permissions/policy.js +16 -5
  36. package/dist/permissions/signature.js +8 -3
  37. package/dist/remote/safe-commands.js +1 -1
  38. package/dist/router/read-rates.js +152 -0
  39. package/dist/selfimprove/backfill.js +174 -0
  40. package/dist/selfimprove/index.js +146 -57
  41. package/dist/selfimprove/lessons.js +429 -0
  42. package/dist/selfimprove/sync.js +58 -0
  43. package/dist/session.js +350 -30
  44. package/dist/skills/finder.js +219 -0
  45. package/dist/tools/deferred.js +28 -18
  46. package/dist/tools/executor.js +7 -3
  47. package/dist/tools/registry.js +34 -4
  48. package/dist/ui/ActivitySpinner.js +21 -12
  49. package/dist/ui/App.js +107 -30
  50. package/dist/ui/ApprovalPrompt.js +5 -3
  51. package/dist/ui/ArtifactPicker.js +3 -3
  52. package/dist/ui/BgPanel.js +105 -5
  53. package/dist/ui/Composer.js +85 -9
  54. package/dist/ui/PlanPane.js +72 -8
  55. package/dist/ui/QuestionPrompt.js +6 -4
  56. package/dist/ui/SecretPrompt.js +8 -3
  57. package/dist/ui/SessionPicker.js +2 -2
  58. package/dist/ui/SkillFinder.js +153 -0
  59. package/dist/ui/StatusRule.js +5 -2
  60. package/dist/ui/SummaryCard.js +3 -1
  61. package/dist/ui/ThinkingSpinner.js +11 -2
  62. package/dist/ui/ToolBatch.js +11 -2
  63. package/dist/ui/ToolStep.js +36 -13
  64. package/dist/ui/Transcript.js +13 -2
  65. package/dist/ui/actNow.js +61 -0
  66. package/dist/ui/batchLine.js +165 -0
  67. package/dist/ui/conversations.js +154 -0
  68. package/dist/ui/decodeHealth.js +77 -0
  69. package/dist/ui/expand.js +17 -0
  70. package/dist/ui/fit.js +40 -0
  71. package/dist/ui/fitTail.js +14 -0
  72. package/dist/ui/fold.js +149 -0
  73. package/dist/ui/format.js +46 -2
  74. package/dist/ui/liveTools.js +163 -13
  75. package/dist/ui/modelPicker.js +78 -6
  76. package/dist/ui/nextStep.js +103 -0
  77. package/dist/ui/pending.js +57 -0
  78. package/dist/ui/phase.js +105 -0
  79. package/dist/ui/planExit.js +0 -5
  80. package/dist/ui/progressbar.js +4 -26
  81. package/dist/ui/readForecast.js +44 -0
  82. package/dist/ui/readProgress.js +119 -0
  83. package/dist/ui/reportLine.js +62 -0
  84. package/dist/ui/slashCommands.js +1 -1
  85. package/dist/ui/theme.js +1 -0
  86. package/dist/ui/turnFlow.js +72 -0
  87. package/dist/ui/turnLedger.js +121 -0
  88. package/dist/ui/turnScope.js +11 -0
  89. package/dist/util/slash.js +18 -0
  90. package/package.json +1 -1
package/dist/ui/App.js CHANGED
@@ -2,9 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  // Composes the UI lane into the SPEC §6 shell. This is the whole UI/engine contract surface —
3
3
  // the engine lane wires state + callbacks into these props; nothing below reaches into
4
4
  // src/engine, src/tools, or src/router.
5
- import { useEffect, useRef, useState } from "react";
6
- import { Box, Text, measureElement } from "ink";
7
- import { useTerminalSize } from "./term.js";
5
+ import React, { useEffect, useRef, useState } from "react";
6
+ import { Box, Text, measureElement, useInput } from "ink";
7
+ import { useTerminalSize, termCols } from "./term.js";
8
8
  import { caps } from "./capabilities.js";
9
9
  import { MouseProvider, useOnWheel, useMouse } from "./MouseProvider.js";
10
10
  import { StatusRule } from "./StatusRule.js";
@@ -13,54 +13,116 @@ import { Transcript } from "./Transcript.js";
13
13
  import { Composer } from "./Composer.js";
14
14
  import { ThinkingSpinner } from "./ThinkingSpinner.js";
15
15
  import { StepSpinner, RecoverSpinner } from "./ActivitySpinner.js";
16
- import { BgPanel } from "./BgPanel.js";
16
+ import { BgPanel, Lanes, liveWorkers } from "./BgPanel.js";
17
17
  import { PlanPane } from "./PlanPane.js";
18
- import { ToolStep } from "./ToolStep.js";
18
+ import { liveRow, batchHeader, delegateLine, relayFrame } from "./batchLine.js";
19
+ import { glyphFor, toolKind } from "./toolicons.js";
19
20
  import { backgroundHint } from "./liveTools.js";
20
21
  import { useTick } from "./tick.js";
22
+ import { phaseLine, phaseWord } from "./phase.js";
23
+ import { KIND_HUE } from "./toolicons.js";
24
+ import { foldLine } from "./fold.js";
25
+ import { isExpandKey } from "./expand.js";
26
+ import { theme } from "./theme.js";
21
27
  import { ApprovalPrompt } from "./ApprovalPrompt.js";
22
28
  import { QuestionPrompt } from "./QuestionPrompt.js";
23
29
  import { SecretPrompt } from "./SecretPrompt.js";
24
30
  import { ArtifactPicker } from "./ArtifactPicker.js";
25
31
  import { SessionPicker } from "./SessionPicker.js";
32
+ import { SkillFinder } from "./SkillFinder.js";
33
+ import { pendingLines, turnKeySegs } from "./pending.js";
34
+ import { nextStepLine } from "./nextStep.js";
35
+ import { centreLayout, switcherLine } from "./conversations.js";
36
+ import { cellWidth } from "./StatusRule.js";
37
+ import { ACT_NOW_NARROW, actNowLine } from "./actNow.js";
38
+ import { fitSegments } from "./fit.js";
39
+ // The footer's mode badge. Gated is outside the shift+tab cycle (permissions/modes.ts); shift+tab leaves it.
40
+ const MODE_BADGE = { auto: "⎈ Autonomous", manual: "⊙ Manual", plan: "◑ Plan", gated: "⊘ Gated" };
26
41
  // Cap on live rows shown at once for a parallel tool batch — keeps the dynamic (non-Static) frame
27
42
  // bounded (same render-collapse concern liveTail guards in Transcript.tsx: Ink corrupts the frame once
28
43
  // the non-Static portion approaches the terminal height). A batch rarely runs more than a handful of
29
44
  // calls at once; anything past the cap is summarized as a count instead of another row.
30
45
  const MAX_LIVE_TOOL_ROWS = 6;
31
- /** The yellow line above the composer while messages wait for the turn to end: count, the keys that act on the queue,
32
- * then a one-line preview of everything queued (newlines as " / ", capped at 120 chars). */
33
- export function queuedHint(queued) {
34
- const preview = queued.join("\n").replace(/\n/g, " / ");
35
- const head = queued.length > 1 ? `⏎ ${queued.length} queued · send together when this turn ends` : "⏎ queued · sends when this turn ends";
36
- const keys = queued.length > 1 ? "Esc send now · ↑ edit last · ⌫ cancel last" : "Esc send now · ↑ edit · ⌫ cancel";
37
- return `${head} · ${keys}: ${preview.slice(0, 120)}${preview.length > 120 ? "…" : ""}`;
46
+ // One live tool row (ui/batchLine.ts): the status glyph (the kind's own motion while running, ○ while drafting or
47
+ // waiting its turn), the tool name in its kind's color, and the rest — the result rides on the row, never under it.
48
+ function LiveRow({ step }) {
49
+ const moving = step.status === "running" || (step.status === "selected" && !!step.drafting);
50
+ const frame = useTick(moving);
51
+ const { head, rest } = liveRow(step, termCols(), Date.now());
52
+ const hue = KIND_HUE[toolKind(step.name)];
53
+ const glyph = step.status === "running" ? glyphFor(step.name, "running", frame) : step.status === "selected" ? "○" : step.outcome ? "⊘" : step.status === "error" ? "✗" : "✓";
54
+ const color = step.status === "running" ? hue : step.status === "selected" ? theme.muted : step.outcome === "blocked" ? theme.blocked : step.outcome ? theme.muted : step.status === "error" ? theme.error : theme.success;
55
+ return (_jsxs(Text, { children: [_jsx(Text, { color: color, bold: true, children: glyph }), " ", _jsx(Text, { color: hue, children: head }), _jsx(Text, { dimColor: step.status !== "running", children: rest })] }));
38
56
  }
39
- // Muted "ctrl+b to run in the background" tail on the phase line, once a shell command has run past ~2s. Ticks
40
- // on the shared animation clock only while a shell command is running, so it appears without any other event.
41
- function BackgroundHint({ rows }) {
42
- const watching = rows.some((r) => (r.name === "bash" || r.name === "shell_exec") && r.status === "running");
43
- useTick(watching);
44
- const hint = backgroundHint(rows);
45
- return hint ? _jsx(Text, { dimColor: true, children: ` · ${hint}` }) : null;
57
+ // Which running delegate_task row a child's progress belongs to: the one whose task matches (whitespace aside — the
58
+ // emitter trims it, live 11/04), else the only one running (delegate_task is a scheduler barrier, so one runs at a time).
59
+ const normTask = (t) => String(t ?? "").replace(/\s+/g, " ").trim();
60
+ export function delegateRow(rows, view) {
61
+ const running = rows.filter((r) => r.name === "delegate_task" && r.status === "running");
62
+ return (running.find((r) => normTask(r.args?.task) === normTask(view.task)) ?? (running.length === 1 ? running[0] : undefined))?.id;
63
+ }
64
+ // The specialist's live line under its running delegate_task (TUI plan #9), led by the delegation's own relay motion.
65
+ function DelegateChild({ view }) {
66
+ const frame = useTick(true);
67
+ return (_jsxs(Text, { children: [" ", _jsx(Text, { color: KIND_HUE.agent, children: relayFrame(frame) }), " ", _jsx(Text, { dimColor: true, children: delegateLine(view, termCols()) })] }));
68
+ }
69
+ // The phase line (ui/phase.ts): one dim row naming what the turn is measurably doing, then the keys that act on it
70
+ // (Enter steers, Tab queues, Esc stops), fitted to cols−1. It ticks on the shared clock only while it has something
71
+ // that moves — the read meter's head, or a shell command that may cross the ~2 s mark where the "ctrl+b to run in the
72
+ // background" hint appears without any other event. A ctrl+y offer (ui/actNow.ts — a long reasoning stream, a long
73
+ // read, the loop guard refusing) takes the line over.
74
+ function PhaseLine({ view, rows, offer = null }) {
75
+ const cols = termCols();
76
+ const watchingShell = view.phase === "tools" && rows.some((r) => (r.name === "bash" || r.name === "shell_exec") && r.status === "running");
77
+ const frame = useTick(watchingShell || (view.phase === "reading" && !!view.read));
78
+ const act = actNowLine(phaseWord(view.phase), offer);
79
+ if (act)
80
+ return _jsx(Text, { dimColor: true, children: cols < 45 ? ACT_NOW_NARROW : fitSegments(act, cols, { sep: "" }) });
81
+ // No steer keys while compacting: a manual /compact is no turn to steer — what is typed waits for it.
82
+ const { meter, text } = phaseLine({ ...view, hint: view.phase === "tools" ? backgroundHint(rows) : null, keys: view.phase === "compacting" ? undefined : turnKeySegs() }, cols, frame);
83
+ return (_jsxs(Text, { dimColor: true, children: [" ", meter ? _jsx(Text, { color: KIND_HUE.read, children: `${meter} ` }) : null, text] }));
84
+ }
85
+ // ctrl+o appends the newest collapsed item (a sub-agent report, a settled batch). Its own listener, so the composer only
86
+ // has to swallow the key; inactive while an overlay owns the keyboard.
87
+ function ExpandKey({ onExpand, active }) {
88
+ useInput((ch, key) => { if (isExpandKey(ch, key))
89
+ onExpand(); }, { isActive: active });
90
+ return null;
46
91
  }
47
92
  export function App(props) {
48
- const { messages, live = null, status, thinkingVerb, verbs, stepLabel, prefill = "", liveTools = [], route, ctxPct, ctxWindow, version, build, fullscreen = false, metrics, sessionTokens, authUser, tier, planMode, thinkMode, bgAgents, shellJobs = [], onBackground, tasks = [], onSubmit, onQueue, queuedPreview = [], onEditQueued, onDropQueued, onInterrupt, onCycleMode, onCycleContext, opMode, rcConnected = false, rcActive = false, caffeinated = false, approval = null, onApprovalDecide, question = null, modelPicker = null, secretPrompt = null, planExitPicker = null, artifactsPicker = null, sessionsPicker = null } = props;
49
- useTerminalSize(); // subscribe so the inline pinned UI (status rule, composer, footer) reflows the instant the terminal resizes
93
+ const { messages, live = null, status, thinkingVerb, verbs, stepLabel, phase = null, fold = null, delegate = null, liveTools = [], route, ctxPct, ctxWindow, version, build, fullscreen = false, metrics, sessionTokens, authUser, tier, planMode, thinkMode, bgAgents, shellJobs = [], mainLane = null, mainServing, maxRunning, onBackground, tasks = [], planNow, onSubmit, onQueue, onSteer, pending = [], onEditQueued, onDropQueued, nextSteps, onPickNext, onDismissNext, agents = [], onAgentMessage, conversations = [], switcher, onSwitcher, onFocusSwitcher, conversationPane = null, onSendTo, actOffer = null, onActNow, finder = null, onOpenFinder, onInterrupt, onExpand, onCycleMode, onCycleContext, opMode, rcConnected = false, rcActive = false, caffeinated = false, approval = null, onApprovalDecide, question = null, modelPicker = null, secretPrompt = null, planExitPicker = null, artifactsPicker = null, sessionsPicker = null } = props;
94
+ const cols = useTerminalSize().cols; // subscribe so the inline pinned UI (status rule, composer, footer) reflows the instant the terminal resizes
50
95
  const thinking = status === "thinking" || status === "streaming";
51
- // A parallel batch (2+ live rows) gets its own per-call view instead of the single-line StepSpinner —
52
- // a lone call isn't worth a bordered block, the braille spinner + name already says enough.
53
- const showParallelRows = status === "executing" && liveTools.length > 1;
54
- const showSpinner = status === "recovering" || status === "compacting" || (status === "executing" && !showParallelRows) || thinking;
96
+ // Tool rows exist before their calls run (TUI plan #8): from the first streamed argument (drafting) through waiting
97
+ // its turn to running and settled — one row per call, a lone call included, instead of the bare "⠋ name…".
98
+ const showLiveRows = liveTools.length > 0 && (status === "executing" || phase?.phase === "drafting");
99
+ const showSpinner = status === "recovering" || status === "compacting" || (status === "executing" && !showLiveRows) || thinking;
55
100
  // The live activity band (spinner / parallel-tool view) and the bg-agents panel — shared by both layouts.
56
101
  const activity = (_jsxs(_Fragment, { children: [showSpinner && (_jsx(Box, { marginTop: 1, marginBottom: 1, children: status === "recovering" || status === "compacting" ? _jsx(RecoverSpinner, { active: true, label: stepLabel })
57
102
  : status === "executing" ? _jsx(StepSpinner, { active: true, label: stepLabel })
58
- : _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), showParallelRows && (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, paddingLeft: 1, children: [_jsxs(Text, { dimColor: true, children: ["running ", liveTools.length, " tools in parallel"] }), liveTools.slice(0, MAX_LIVE_TOOL_ROWS).map((step) => _jsx(ToolStep, { step: step }, step.id)), liveTools.length > MAX_LIVE_TOOL_ROWS ? _jsxs(Text, { dimColor: true, children: [" +", liveTools.length - MAX_LIVE_TOOL_ROWS, " more\u2026"] }) : null] })), _jsx(PlanPane, { tasks: tasks }), _jsx(BgPanel, { agents: bgAgents, jobs: shellJobs }), (thinking || status === "executing" || status === "recovering") && (_jsxs(Text, { dimColor: true, children: [` ${status === "executing" ? "running tools" : status === "recovering" ? "recovering" : status === "streaming" ? "writing" : prefill || "reasoning"} · esc to interrupt`, status === "executing" ? _jsx(BackgroundHint, { rows: liveTools }) : null] }))] }));
59
- // Interactive prompts own the keyboard while up; kept out of the fullscreen clip region so they can't
60
- // be scrolled off. The Composer is `suspended` (keystrokes route to the decision, not the draft).
61
- const prompts = (_jsxs(_Fragment, { children: [_jsx(ApprovalPrompt, { approval: approval, onDecide: onApprovalDecide ?? (() => { }) }), _jsx(QuestionPrompt, { pending: question }), _jsx(QuestionPrompt, { pending: modelPicker }), _jsx(SecretPrompt, { pending: secretPrompt }), _jsx(QuestionPrompt, { pending: planExitPicker }), _jsx(ArtifactPicker, { pending: artifactsPicker }), _jsx(SessionPicker, { pending: sessionsPicker })] }));
103
+ : _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), showLiveRows && (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, paddingLeft: 1, children: [_jsx(Text, { dimColor: true, children: batchHeader(liveTools, termCols()) }), liveTools.slice(0, MAX_LIVE_TOOL_ROWS).map((step) => (_jsxs(React.Fragment, { children: [_jsx(LiveRow, { step: step }), delegate && step.id === delegateRow(liveTools, delegate) ? _jsx(DelegateChild, { view: delegate }) : null] }, step.id))), liveTools.length > MAX_LIVE_TOOL_ROWS ? _jsxs(Text, { dimColor: true, children: [" +", liveTools.length - MAX_LIVE_TOOL_ROWS, " more\u2026"] }) : null] })), fold ? (() => { const line = foldLine(fold, termCols(), true); return _jsxs(Text, { children: [_jsx(Text, { color: theme.blocked, children: line.slice(0, 1) }), _jsx(Text, { dimColor: true, children: line.slice(1) })] }); })() : null, _jsx(PlanPane, { tasks: tasks, now: planNow }), liveWorkers(mainLane, bgAgents, shellJobs) >= 2
104
+ ? _jsx(Lanes, { main: mainLane, agents: bgAgents, jobs: shellJobs, mainServing: mainServing, maxRunning: maxRunning })
105
+ : _jsx(BgPanel, { agents: bgAgents, jobs: shellJobs }), (thinking || status === "executing" || status === "recovering" || status === "compacting") && (_jsx(PhaseLine, { view: phase ?? { phase: status === "executing" ? "tools" : status === "recovering" ? "recovering" : status === "compacting" ? "compacting" : status === "streaming" ? "writing" : "waiting", label: stepLabel }, rows: liveTools, offer: actOffer }))] }));
106
+ // One input owner at a time. An open overlay — the finder, the focused switcher — keeps the keyboard; a prompt that
107
+ // arrives under it (an approval, an ask_user, the plan review) is drawn, waiting, and answered only once the overlay
108
+ // closes, so nothing typed into the overlay can answer it. With no overlay open a pending prompt owns the keyboard and
109
+ // the composer gives way, its next-step strip with it. Overlays open only from the composer, so never over a prompt.
110
+ const promptUp = !!approval || !!question || !!modelPicker || !!secretPrompt || !!planExitPicker || !!artifactsPicker || !!sessionsPicker;
111
+ const owner = finder ? "finder" : switcher?.focused ? "switcher" : promptUp ? "prompt" : "composer";
112
+ const held = owner === "finder" || owner === "switcher";
113
+ const waiting = owner === "finder" ? "esc closes the finder, then answer here" : "↑ hands the keyboard back, then answer here";
114
+ // Prompts are kept out of the fullscreen clip region so they can't be scrolled off.
115
+ const prompts = (_jsxs(_Fragment, { children: [_jsx(ApprovalPrompt, { approval: approval, onDecide: onApprovalDecide ?? (() => { }), suspended: held, waiting: waiting }), _jsx(QuestionPrompt, { pending: question, suspended: held, waiting: waiting }), _jsx(QuestionPrompt, { pending: modelPicker, suspended: held, waiting: waiting }), _jsx(SecretPrompt, { pending: secretPrompt, suspended: held }), _jsx(QuestionPrompt, { pending: planExitPicker, suspended: held, waiting: waiting }), _jsx(ArtifactPicker, { pending: artifactsPicker, suspended: held }), _jsx(SessionPicker, { pending: sessionsPicker, suspended: held }), _jsx(SkillFinder, { pending: finder })] }));
62
116
  // The pinned bottom band: status rule, composer, bottom rule, then the mode/cycle FOOTER below the rule.
63
- const bottom = (_jsxs(_Fragment, { children: [_jsx(StatusRule, { route: route, ctxPct: ctxPct, ctxWindow: ctxWindow, version: version, build: build, user: authUser, tier: tier, planMode: planMode, thinkMode: thinkMode, sessionTokens: sessionTokens }), queuedPreview.length ? _jsx(Text, { color: "yellow", children: queuedHint(queuedPreview) }) : null, _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, queued: queuedPreview.length, onEditQueued: onEditQueued, onDropQueued: onDropQueued, onInterrupt: onInterrupt, onBackground: onBackground, onCycleMode: onCycleMode, onCycleContext: onCycleContext, disabled: status !== "idle", suspended: !!approval || !!question || !!modelPicker || !!secretPrompt || !!planExitPicker || !!artifactsPicker || !!sessionsPicker }), _jsx(InputRule, {}), opMode && (_jsxs(Box, { justifyContent: "space-between", children: [_jsx(Text, { dimColor: true, children: ` ${opMode === "auto" ? "⎈ Autonomous" : opMode === "manual" ? "⊙ Manual" : "◑ Plan"} · shift+tab to cycle` }), _jsx(Text, { color: rcConnected ? "green" : rcActive ? "yellow" : "gray", bold: rcConnected || rcActive, dimColor: !rcConnected && !rcActive, children: `${caffeinated ? "☕ " : ""}${rcConnected ? "▮ rc live" : rcActive ? "▮ rc on" : "▯ rc"} ` })] }))] }));
117
+ // The mode line: the mode on the left, the conversation switcher in the centre, remote control on the right. The centre
118
+ // gets what the two sides leave, so the row stays at cols−1.
119
+ const modeText = opMode ? ` ${MODE_BADGE[opMode]} · shift+tab to cycle` : "";
120
+ const rcText = `${caffeinated ? "☕ " : ""}${rcConnected ? "▮ rc live" : rcActive ? "▮ rc on" : "▯ rc"} `;
121
+ const centre = switcher ? switcherLine(conversations, switcher, Math.max(0, cols - 1 - cellWidth(modeText) - cellWidth(rcText) - 2)) : "";
122
+ const bottom = (_jsxs(_Fragment, { children: [_jsx(SwitcherKeys, { active: owner === "switcher", onKey: onSwitcher }), conversationPane ? (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "magenta", children: conversationPane.header }), conversationPane.lines.map((l, i) => _jsx(Text, { dimColor: !l.startsWith("⏺") && !l.startsWith("❯"), children: l || " " }, i))] })) : null, _jsx(StatusRule, { route: route, ctxPct: ctxPct, ctxWindow: ctxWindow, version: version, build: build, user: authUser, tier: tier, planMode: planMode, thinkMode: thinkMode, sessionTokens: sessionTokens }), owner === "composer" && status === "idle" && nextSteps?.length ? _jsx(Text, { color: "cyan", children: nextStepLine(nextSteps, cols) }) : null, pendingLines(pending, cols, phase ? phaseWord(phase.phase) : undefined).map((line, i) => _jsx(Text, { color: "yellow", children: line }, i)), onExpand ? _jsx(ExpandKey, { onExpand: onExpand, active: owner === "composer" }) : null, _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onSteer: onSteer, queued: pending.length, nextSteps: owner === "composer" && status === "idle" ? nextSteps?.length ?? 0 : 0, onPickNext: onPickNext, onDismissNext: onDismissNext, agents: agents, onAgentMessage: onAgentMessage, onSendTo: conversationPane ? onSendTo : undefined, onFocusSwitcher: onFocusSwitcher, onActNow: onActNow, onOpenFinder: onOpenFinder, prompt: conversationPane ? `${conversationPane.target} › ` : undefined, onEditQueued: onEditQueued, onDropQueued: onDropQueued, onInterrupt: onInterrupt, onBackground: onBackground, onCycleMode: onCycleMode, onCycleContext: onCycleContext, disabled: status !== "idle", suspended: owner !== "composer" }), _jsx(InputRule, {}), opMode && (_jsxs(Box, { justifyContent: "space-between", children: [_jsx(Text, { dimColor: true, children: modeText }), centre ? (() => {
123
+ const pad = centreLayout(cellWidth(modeText), cellWidth(centre), cellWidth(rcText), cols);
124
+ return _jsx(Text, { color: switcher?.focused ? "cyan" : undefined, dimColor: !switcher?.focused, children: " ".repeat(pad.before) + centre + " ".repeat(Math.max(0, pad.after - 1)) });
125
+ })() : null, _jsx(Text, { color: rcConnected ? "green" : rcActive ? "yellow" : "gray", bold: rcConnected || rcActive, dimColor: !rcConnected && !rcActive, children: rcText })] }))] }));
64
126
  // Fullscreen (opt-in): a full-terminal-height column. The transcript fills a clipped, bottom-anchored
65
127
  // region (non-Static tail) so the newest output sits just above a composer pinned to the very bottom —
66
128
  // no dead space. Off by default: inline keeps the terminal's native scrollback (mouse-scroll + copy).
@@ -75,6 +137,21 @@ export function App(props) {
75
137
  // The composer is measured (MeasuredComposer) so an open picker's click anchor knows what sits below it.
76
138
  return (_jsx(MouseProvider, { enabled: caps().mouse, children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Transcript, { entries: messages, live: live }), activity, _jsxs(MeasuredStack, { children: [prompts, bottom] })] }) }));
77
139
  }
140
+ // Keys while the conversation switcher has focus (the composer is suspended meanwhile): ←/→ (or ↓) pick, Enter opens,
141
+ // ↑ or Esc hands the keyboard back to the composer.
142
+ function SwitcherKeys({ active, onKey }) {
143
+ useInput((_input, key) => {
144
+ if (key.leftArrow)
145
+ onKey?.("left");
146
+ else if (key.rightArrow || key.downArrow || key.tab)
147
+ onKey?.("right");
148
+ else if (key.return)
149
+ onKey?.("open");
150
+ else if (key.upArrow || key.escape)
151
+ onKey?.("back");
152
+ }, { isActive: active });
153
+ return null;
154
+ }
78
155
  // Measures the overlay stack (open picker + the composer block below it) as ONE block and publishes its
79
156
  // height to the mouse layer. An open picker is the top of this stack, so its top row = frameBottom −
80
157
  // stackHeight + 1 — the single measurement folds in the composer height and every inter-element margin, so
@@ -24,7 +24,7 @@ function summarize(name, args) {
24
24
  }
25
25
  }
26
26
  }
27
- export function ApprovalPrompt({ approval, onDecide }) {
27
+ export function ApprovalPrompt({ approval, onDecide, suspended = false, waiting }) {
28
28
  useInput((input, key) => {
29
29
  if (!approval)
30
30
  return;
@@ -37,9 +37,11 @@ export function ApprovalPrompt({ approval, onDecide }) {
37
37
  onDecide(true, true); // allow always (this session)
38
38
  else if (c === "d" || key.escape)
39
39
  onDecide(false, false); // deny
40
- }, { isActive: !!approval });
40
+ }, { isActive: !!approval && !suspended });
41
41
  if (!approval)
42
42
  return null;
43
43
  const detail = summarize(approval.name, approval.args);
44
- return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [_jsxs(Text, { color: "yellow", bold: true, children: ["⚠ Operator wants to run ", _jsx(Text, { color: "magenta", children: approval.name })] }), detail ? _jsx(Text, { dimColor: true, children: " " + detail }) : null, _jsxs(Text, { children: [" ", _jsx(Text, { color: "green", children: "[a]" }), " allow once ", _jsx(Text, { color: "cyan", children: "[s]" }), " allow always ", _jsx(Text, { color: "red", children: "[d]" }), " deny ", _jsx(Text, { dimColor: true, children: "(Enter=allow \u00B7 Esc=deny)" })] })] }));
44
+ return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, borderStyle: "round", borderColor: "yellow", paddingX: 1, children: [_jsxs(Text, { color: "yellow", bold: true, children: ["⚠ Operator wants to run ", _jsx(Text, { color: "magenta", children: approval.name })] }), detail ? _jsx(Text, { dimColor: true, children: " " + detail }) : null, suspended
45
+ ? _jsx(Text, { dimColor: true, children: " waiting · " + (waiting ?? "another prompt has the keyboard") })
46
+ : _jsxs(Text, { children: [" ", _jsx(Text, { color: "green", children: "[a]" }), " allow once ", _jsx(Text, { color: "cyan", children: "[s]" }), " allow always ", _jsx(Text, { color: "red", children: "[d]" }), " deny ", _jsx(Text, { dimColor: true, children: "(Enter=allow \u00B7 Esc=deny)" })] })] }));
45
47
  }
@@ -62,7 +62,7 @@ function windowFor(n, hi) {
62
62
  start = Math.max(0, Math.min(start, n - VISIBLE_ROWS));
63
63
  return { start, end: start + VISIBLE_ROWS };
64
64
  }
65
- export function ArtifactPicker({ pending }) {
65
+ export function ArtifactPicker({ pending, suspended = false }) {
66
66
  const [st, setSt] = useState({ mode: "list", query: "", highlight: 0 });
67
67
  const wasOpen = useRef(false);
68
68
  useEffect(() => {
@@ -79,7 +79,7 @@ export function ArtifactPicker({ pending }) {
79
79
  setSt(a.state);
80
80
  if (a.intent)
81
81
  pending.onIntent(a.intent);
82
- }, { isActive: !!pending });
82
+ }, { isActive: !!pending && !suspended });
83
83
  // Row layout for click-to-select (hooks must run every render, so compute from safe defaults before the
84
84
  // early return). Rows below the box top: 1 border + 1 title (+1 search line in search mode). Each item is
85
85
  // one line. Click a row → highlight it; Enter still runs the primary action, per the footer help.
@@ -91,7 +91,7 @@ export function ArtifactPicker({ pending }) {
91
91
  const headerLines = 1 /* marginTop */ + 1 /* top border */ + 1 /* title */ + (st.mode === "search" ? 1 : 0);
92
92
  useClickList({
93
93
  id: "artifact-list",
94
- active: !!pending && !pending.loading && !pending.error,
94
+ active: !!pending && !suspended && !pending.loading && !pending.error,
95
95
  headerLines, rowHeight: 1, windowStart: start, visibleCount: end - start,
96
96
  onPick: (idx) => setSt((s) => ({ ...s, highlight: idx, confirmDeleteId: undefined })),
97
97
  });
@@ -3,9 +3,18 @@ import { Box, Text } from "ink";
3
3
  import { OrbitGlyph } from "./ActivitySpinner.js";
4
4
  import { theme } from "./theme.js";
5
5
  import { useTick } from "./tick.js";
6
+ import { termCols, termRows } from "./term.js";
7
+ import { cellWidth, truncateToWidth } from "./StatusRule.js";
8
+ import { fmtElapsed, fmtTok } from "./format.js";
6
9
  const GLYPH = { queued: "◌", working: "●", idle: "✓", stopped: "✗" };
7
10
  const COLOR = { queued: theme.muted, working: theme.running, idle: theme.success, stopped: theme.error };
8
11
  const DISPLAY_STATUS = { queued: "queued", working: "running", idle: "done", stopped: "errored" };
12
+ // A stop by the owner, the orchestrator, the stall watchdog or the engine is a STOP, not an error (TUI plan #4): ■ in
13
+ // muted amber and the word "stopped". Only a failed start or a thrown error reads ✗ errored.
14
+ const deliberateStop = (a) => a.status === "stopped" && !!a.endKind && a.endKind !== "failed" && a.endKind !== "error";
15
+ const glyphOf = (a) => (deliberateStop(a) ? "■" : GLYPH[a.status]);
16
+ const colorOf = (a) => (deliberateStop(a) ? theme.blocked : COLOR[a.status]);
17
+ const statusOf = (a) => (deliberateStop(a) ? "stopped" : DISPLAY_STATUS[a.status]);
9
18
  const toks = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`);
10
19
  // Live per-agent metrics: tokens generated + elapsed. While working, elapsed is derived from
11
20
  // startedAt at render time (updates each round tick); once finished, the wall time is frozen.
@@ -31,7 +40,7 @@ const ACTIVITY_VERB = {
31
40
  task_add: "planning", task_update: "planning", task_clear: "planning", spawn_agent: "delegating",
32
41
  message_agent: "messaging", web_search: "searching web", web_fetch: "fetching",
33
42
  };
34
- const humanStep = (name) => ACTIVITY_VERB[name] ?? name.replace(/_/g, " ");
43
+ export const humanStep = (name) => ACTIVITY_VERB[name] ?? name.replace(/_/g, " ");
35
44
  // One short phrase for what THIS round is actually doing, next to "round N" — the round counter alone is
36
45
  // just a number; this is the "editing cli.py" a glance needs. Prefers the in-flight tool call, then falls
37
46
  // back to the live reasoning tail, then the last settled step, so it's never blank while the agent is
@@ -68,10 +77,14 @@ export function ledgerLine(a) {
68
77
  export function detailLine(a) {
69
78
  if (a.status === "working" && a.stuck)
70
79
  return { text: `⚠ stuck: ${a.stuck} — /agents ${a.id} msg <steer> · /agents ${a.id} stop`, tone: "stuck" };
80
+ // A message the owner sent (@Name) takes the detail line until the agent takes it — the panel keeps its three rows.
81
+ if ((a.status === "working" || a.status === "queued") && a.pendingMessages) {
82
+ return { text: `✉ ${a.pendingMessages} message${a.pendingMessages > 1 ? "s" : ""} waiting · ${a.status === "queued" ? "lands when it starts" : "lands at its next round"}`, tone: "dim" };
83
+ }
71
84
  if (a.status === "idle")
72
85
  return { text: "result posted — scroll up or /agents to review", tone: "dim" };
73
86
  if (a.status === "stopped")
74
- return { text: "errored — check transcript for details", tone: "dim" };
87
+ return { text: a.endReason ?? "errored — check transcript for details", tone: "dim" };
75
88
  if (a.status === "queued")
76
89
  return { text: "waiting for a free slot", tone: "dim" };
77
90
  const steps = a.steps ?? [];
@@ -85,7 +98,7 @@ export function detailLine(a) {
85
98
  // every tick, and Ink repainted the whole frame (the flashing, 10/31).
86
99
  function AgentRows({ a }) {
87
100
  const d = detailLine(a);
88
- return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Box, { flexGrow: 1, flexShrink: 1, children: _jsxs(Text, { wrap: "truncate-end", children: [a.status === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: COLOR[a.status], children: GLYPH[a.status] }), " ", _jsx(Text, { bold: true, children: a.name ?? a.label }), a.name ? _jsx(Text, { dimColor: true, children: ` · ${cap(a.label, 40)}` }) : null, a.round != null ? ` · round ${a.round}` : "", a.status === "working" && missionLine(a) ? _jsxs(Text, { color: theme.accent, children: [" \u00B7 ", cap(missionLine(a), 36)] }) : null] }) }), _jsx(Box, { flexShrink: 0, marginLeft: 1, children: _jsx(Text, { dimColor: true, children: (() => { const m = metrics(a); const ds = DISPLAY_STATUS[a.status]; return m ? `${m} · ${ds}` : ds; })() }) })] }), _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: ledgerLine(a) }) }), _jsx(Box, { paddingLeft: 2, children: d.tone === "stuck" ? _jsx(Text, { color: theme.error, wrap: "truncate-end", children: d.text }) : _jsx(Text, { dimColor: true, wrap: "truncate-end", children: cap(d.text, 110) }) })] }));
101
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Box, { flexGrow: 1, flexShrink: 1, children: _jsxs(Text, { wrap: "truncate-end", children: [a.status === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: colorOf(a), children: glyphOf(a) }), " ", _jsx(Text, { bold: true, children: a.name ?? a.label }), a.name ? _jsx(Text, { dimColor: true, children: ` · ${cap(a.label, 40)}` }) : null, a.round != null ? ` · round ${a.round}` : "", a.status === "working" && missionLine(a) ? _jsxs(Text, { color: theme.accent, children: [" \u00B7 ", cap(missionLine(a), 36)] }) : null] }) }), _jsx(Box, { flexShrink: 0, marginLeft: 1, children: _jsx(Text, { dimColor: true, children: (() => { const m = metrics(a); const ds = statusOf(a); return m ? `${m} · ${ds}` : ds; })() }) })] }), _jsx(Box, { paddingLeft: 2, children: _jsx(Text, { dimColor: true, wrap: "truncate-end", children: ledgerLine(a) }) }), _jsx(Box, { paddingLeft: 2, children: d.tone === "stuck" ? _jsx(Text, { color: theme.error, wrap: "truncate-end", children: d.text }) : _jsx(Text, { dimColor: true, wrap: "truncate-end", children: cap(d.text, 110) }) })] }));
89
102
  }
90
103
  // Cap how many agent rows the DYNAMIC panel renders. Each agent is ~3 lines; a full fan-out (6–8 agents)
91
104
  // makes the non-Static frame tall AND it re-renders on every sub-agent token — so when it sits near the
@@ -126,8 +139,9 @@ export function BgPanel({ agents, jobs = [], title = "sub-agents" }) {
126
139
  const running = agents.filter((a) => a.status === "working").length;
127
140
  const queued = agents.filter((a) => a.status === "queued").length;
128
141
  const done = agents.filter((a) => a.status === "idle").length;
129
- const errored = agents.filter((a) => a.status === "stopped").length;
130
- const counts = [running ? `${running} running` : "", queued ? `${queued} queued` : "", done ? `${done} done` : "", errored ? `${errored} errored` : ""].filter(Boolean).join(" · ");
142
+ const stopped = agents.filter(deliberateStop).length;
143
+ const errored = agents.filter((a) => a.status === "stopped").length - stopped;
144
+ const counts = [running ? `${running} running` : "", queued ? `${queued} queued` : "", done ? `${done} done` : "", stopped ? `${stopped} stopped` : "", errored ? `${errored} errored` : ""].filter(Boolean).join(" · ");
131
145
  const label = `${title}${counts ? ` · ${counts}` : ` (${agents.length})`}`;
132
146
  // A designated, bounded zone (per request): a dim rounded box with the section label as its first line,
133
147
  // detached from the plan list above by a top margin — sub-agents read as their own region instead of
@@ -138,3 +152,89 @@ export function BgPanel({ agents, jobs = [], title = "sub-agents" }) {
138
152
  // borderless column (the label line alone still heads it).
139
153
  return (_jsxs(Box, { flexDirection: "column", marginTop: 1, borderStyle: "round", borderColor: theme.muted, paddingX: 1, children: [_jsx(Text, { dimColor: true, children: label }), shown.map((a) => _jsx(AgentRows, { a: a }, a.id)), hidden > 0 ? _jsx(Text, { dimColor: true, children: ` +${hidden} more running` }) : null, _jsx(ShellJobs, { jobs: jobs })] }));
140
154
  }
155
+ const LANE_GLYPH = {
156
+ main: "✷", working: "◠", waiting: "◌", queued: "◌", done: "✓", stopped: "■", error: "✗", stuck: "⚠", job: "▶", jobDone: "✓", jobFailed: "✗",
157
+ };
158
+ const LANE_COLOR = {
159
+ main: theme.accent, working: theme.accent, waiting: theme.blocked, queued: theme.muted, done: theme.success, stopped: theme.blocked,
160
+ error: theme.error, stuck: theme.warn, job: theme.info, jobDone: theme.success, jobFailed: theme.error,
161
+ };
162
+ /** A gate owner label as a lane says it: "main", or the sub-agent's name. */
163
+ const holderShort = (h) => (!h || h === "sub-agent" ? "another agent" : h === "compaction" ? "a compaction" : h);
164
+ export function mainLaneOf(m) {
165
+ return { key: "main", tone: "main", name: "main", role: m.model, mission: m.activity, elapsedMs: m.elapsedMs, tokens: m.tokens };
166
+ }
167
+ /** One sub-agent as a lane: its round and mission, who holds the slot it waits for, why it stopped. Pure. */
168
+ export function agentLaneOf(a, now, ctx = {}) {
169
+ const elapsedMs = a.status === "working" ? (a.startedAt !== undefined ? now - a.startedAt : undefined) : a.durationMs;
170
+ const base = { key: a.id, name: a.name ?? a.id, role: a.title ?? "sub-agent", elapsedMs, tokens: a.tokens };
171
+ const ledger = [a.written?.length ? `wrote ${a.written.length}` : "", a.reads ? `read ${a.reads}` : "", a.commands ? `ran ${a.commands}` : ""].filter(Boolean).join(" · ");
172
+ const join = (...xs) => xs.filter(Boolean).join(" · ");
173
+ if (a.status === "queued")
174
+ return { ...base, tone: "queued", mission: ctx.maxRunning ? `queued: ${ctx.running ?? ctx.maxRunning} of ${ctx.maxRunning} agent slots busy` : "queued for a free agent slot" };
175
+ if (a.status === "idle")
176
+ return { ...base, tone: "done", mission: join("done", a.verified === true ? "✓ verified" : a.verified === false ? "✗ unverified" : undefined, a.written?.length ? `wrote ${a.written.slice(-1).map((p) => p.split("/").pop()).join("")}` : undefined, "report delivered") };
177
+ if (a.status === "stopped") {
178
+ const err = a.endKind === "failed" || a.endKind === "error" || !a.endKind;
179
+ return { ...base, tone: err ? "error" : "stopped", mission: join(a.endReason ?? "errored", a.headline?.startsWith("partial:") ? "partial notes delivered" : undefined) };
180
+ }
181
+ if (a.stuck)
182
+ return { ...base, tone: "stuck", mission: `stuck: ${a.stuck} · /agents ${(a.name ?? a.id).toLowerCase()} msg | stop` };
183
+ if (a.slotWaitSince !== undefined) {
184
+ return { ...base, tone: "waiting", mission: join(`waiting ${fmtElapsed(now - a.slotWaitSince)}: ${a.model ?? "its model"}'s slot is held by ${holderShort(a.slotHolder)}`, ledger || undefined) };
185
+ }
186
+ const where = a.model && ctx.mainServing ? (a.model === ctx.mainServing ? "shares main's slot" : "own server") : undefined;
187
+ return { ...base, tone: "working", mission: join(a.round ? `r${a.round}` : undefined, missionLine(a), ledger || undefined, where) };
188
+ }
189
+ export function jobLaneOf(j, now) {
190
+ const tone = j.status === "running" ? "job" : j.status === "done" ? "jobDone" : "jobFailed";
191
+ return { key: j.id, tone, name: j.id, role: "", mission: j.cmd.replace(/\s+/g, " ").trim(), elapsedMs: j.status === "running" ? now - j.startedAt : j.elapsedMs, status: j.status === "running" ? "running" : j.status === "failed" ? `exit ${j.code ?? "?"}` : j.status };
192
+ }
193
+ /** How many workers are live at once — lanes mode is two or more. */
194
+ export function liveWorkers(main, agents, jobs) {
195
+ return (main ? 1 : 0) + agents.filter((a) => a.status === "working" || a.status === "queued").length + jobs.filter((j) => j.status === "running").length;
196
+ }
197
+ /** One lane as text (pure): the name and role columns, the mission clipped to fill, the right column (elapsed · tokens,
198
+ * or a job's state) right-aligned so the row ends at cols−1. 80–99 cols drop the role, 60–79 the tokens, and under 60
199
+ * only glyph · name · mission · elapsed stay. */
200
+ export function laneRow(l, cols) {
201
+ const lead = 4; // padding + the glyph (counted wide) + a space
202
+ const role = cols >= 100 && l.role ? ` ${l.role.slice(0, 11).padEnd(11)}` : "";
203
+ const left = `${l.name.slice(0, 6).padEnd(6)}${role} `;
204
+ const time = l.elapsedMs !== undefined ? fmtElapsed(l.elapsedMs) : "";
205
+ const tail = l.status ?? (cols >= 60 && l.tokens ? `${fmtTok(l.tokens)} tok` : "");
206
+ const right = cols >= 60 ? [time, tail].filter(Boolean).join(" · ") : time;
207
+ const room = cols - 1 - lead - cellWidth(left) - (right ? cellWidth(right) + 2 : 0);
208
+ const mission = truncateToWidth(l.mission, Math.max(0, room));
209
+ return { left, mission: mission + " ".repeat(Math.max(0, room - cellWidth(mission))), right };
210
+ }
211
+ /** The lanes header: counts, a rule, and the commands that act on them (dropped under 80 cols) — cols−1 wide. */
212
+ export function laneHeader(lanes, cols) {
213
+ const n = (t) => lanes.filter((l) => t.includes(l.tone)).length;
214
+ const running = n(["main", "working", "stuck"]), waiting = n(["waiting"]), queued = n(["queued"]), jobs = n(["job"]);
215
+ const counts = [`${lanes.length} lanes`, running ? `${running} running` : "", waiting ? `${waiting} waiting for a slot` : "", queued ? `${queued} queued` : "", jobs ? `${jobs} shell job${jobs === 1 ? "" : "s"}` : ""].filter(Boolean).join(" · ");
216
+ const hint = cols >= 80 ? " /agents · /jobs" : "";
217
+ const head = truncateToWidth(` ⇶ ${counts} `, cols - 1 - cellWidth(hint) - 1);
218
+ return head + "─".repeat(Math.max(1, cols - 1 - cellWidth(head) - cellWidth(hint))) + hint;
219
+ }
220
+ /** Rows below this cap the lanes at three, plus "+N more · /agents". */
221
+ export const LANES_SHORT_ROWS = 30;
222
+ function LaneRow({ lane, cols }) {
223
+ const { left, mission, right } = laneRow(lane, cols);
224
+ return (_jsxs(Text, { children: [" ", lane.tone === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: LANE_COLOR[lane.tone], children: LANE_GLYPH[lane.tone] }), " ", _jsx(Text, { bold: true, children: left.slice(0, 6) }), _jsx(Text, { dimColor: true, children: left.slice(6) }), _jsx(Text, { color: lane.tone === "stuck" ? theme.warn : undefined, dimColor: lane.tone !== "stuck" && lane.tone !== "main" && lane.tone !== "working", children: mission }), right ? _jsx(Text, { dimColor: true, children: ` ${right}` }) : null] }));
225
+ }
226
+ /** The lanes view: one row per live worker, finished agents lingering until they are reaped. */
227
+ export function Lanes({ main, agents, jobs, mainServing, maxRunning }) {
228
+ const cols = termCols();
229
+ const now = Date.now();
230
+ const running = agents.filter((a) => a.status === "working").length;
231
+ const order = (a) => (a.status === "working" ? (a.slotWaitSince !== undefined ? 1 : 0) : a.status === "queued" ? 2 : 3);
232
+ const lanes = [
233
+ ...(main ? [mainLaneOf(main)] : []),
234
+ ...[...agents].sort((a, b) => order(a) - order(b)).map((a) => agentLaneOf(a, now, { mainServing, running, maxRunning })),
235
+ ...jobs.map((j) => jobLaneOf(j, now)),
236
+ ];
237
+ const cap = termRows() < LANES_SHORT_ROWS ? 3 : 8;
238
+ const shown = lanes.slice(0, cap);
239
+ return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, children: laneHeader(lanes, cols) }), shown.map((l) => _jsx(LaneRow, { lane: l, cols: cols }, l.key)), lanes.length > shown.length ? _jsx(Text, { dimColor: true, children: ` +${lanes.length - shown.length} more · /agents` }) : null] }));
240
+ }
@@ -17,11 +17,15 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
17
17
  import { useEffect, useRef, useState } from "react";
18
18
  import { Box, Text, useInput, useStdin } from "ink";
19
19
  import { InputHistory } from "./useInputHistory.js";
20
+ import { isExpandKey } from "./expand.js";
20
21
  import { matchSlashCommands } from "./slashCommands.js";
21
22
  import { touchInput } from "../idle/activity.js";
23
+ import { isSlashCommand } from "../util/slash.js";
24
+ import { agentMention, matchAgentMentions, mentionCompletion, mentionMenuLine } from "./conversations.js";
25
+ import { termCols } from "./term.js";
22
26
  const PASTE_START = "\x1b[200~";
23
27
  const PASTE_END = "\x1b[201~";
24
- export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended, onCycleMode, onCycleContext, onBackground, queued = 0, onEditQueued, onDropQueued, prompt = "› " }) {
28
+ export function Composer({ onSubmit, onInterrupt, onQueue, onSteer, disabled, suspended, onCycleMode, onCycleContext, onBackground, queued = 0, onEditQueued, onDropQueued, nextSteps = 0, onPickNext, onDismissNext, agents = [], onAgentMessage, onSendTo, onFocusSwitcher, onActNow, onOpenFinder, prompt = "› " }) {
25
29
  const [value, setValue] = useState("");
26
30
  const suspendedRef = useRef(suspended); // read by the raw-stdin paste listener, registered once below
27
31
  suspendedRef.current = suspended;
@@ -41,6 +45,9 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
41
45
  // handlers below); ↑/↓ move it without touching the draft.
42
46
  const menuMatches = matchSlashCommands(value);
43
47
  const menuSel = menuMatches.length ? Math.min(selIdx, menuMatches.length - 1) : 0;
48
+ // The "@" menu (A3.4): a bare "@token" lists the live sub-agents it can reach; Tab completes the highlighted one.
49
+ const atMatches = onAgentMessage ? matchAgentMentions(value, agents) : null;
50
+ const atSel = atMatches ? Math.min(selIdx, atMatches.length - 1) : 0;
44
51
  useEffect(() => {
45
52
  if (!isRawModeSupported || !stdin)
46
53
  return;
@@ -144,11 +151,18 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
144
151
  onCycleMode?.();
145
152
  return;
146
153
  }
147
- // Plain Tab completes the "/" menu to the highlighted command (with a trailing space, ready for args).
148
- // Always swallow a lone Tab so a literal tab character can never land in the draft.
154
+ // Plain Tab completes the "/" menu to the highlighted command (with a trailing space, ready for args); with no menu
155
+ // open and a turn running, it queues the draft for after the turn. Always swallowed: a literal tab never lands.
149
156
  if (key.tab) {
150
157
  if (menuMatches.length)
151
158
  setValue(`/${menuMatches[menuSel].name} `);
159
+ else if (atMatches)
160
+ setValue(mentionCompletion(atMatches[atSel]));
161
+ else if (disabled && onQueue) {
162
+ const text = commitDraft();
163
+ if (text !== null)
164
+ onQueue(text);
165
+ }
152
166
  return;
153
167
  }
154
168
  // ctrl+b moves the running command to the background (matches Claude Code). Inside tmux the first ctrl+b is
@@ -162,9 +176,26 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
162
176
  onCycleContext?.();
163
177
  return;
164
178
  }
179
+ if (isExpandKey(ch, key))
180
+ return; // ctrl+o expands the newest collapsed item — App owns the action; never lands in the draft
181
+ // ctrl+y — "use what you have": acts mid-turn whatever the draft holds, like ctrl+b. Swallowed either way.
182
+ if (isActNowKey(ch, key)) {
183
+ onActNow?.();
184
+ return;
185
+ }
186
+ // ctrl+g opens the skills and tools finder, idle or mid-turn; the draft stays as it is.
187
+ if (isFinderKey(ch, key)) {
188
+ onOpenFinder?.();
189
+ return;
190
+ }
165
191
  // ESC / Ctrl+C: apply the pure interruptPlan. ESC mid-turn with a pending draft flushes it into
166
192
  // the queue (so it goes through right after the interrupt, via the turn-finally drain), then
167
193
  // interrupts; an empty-draft ESC and every Ctrl+C are plain interrupts. See interruptPlan below.
194
+ // With the next-step strip up, Esc closes it; Ctrl+C keeps its meaning (at rest: quit) — review F13.
195
+ if (key.escape && nextSteps > 0) {
196
+ onDismissNext?.();
197
+ return;
198
+ }
168
199
  if (key.escape || (key.ctrl && ch === "c")) {
169
200
  const plan = interruptPlan({ escape: key.escape, ctrlC: key.ctrl && ch === "c" }, { disabled, hasQueue: !!onQueue, draftNonEmpty: !!expandPastes(value, pasteStoreRef.current).trim() });
170
201
  if (plan.flushDraft) {
@@ -176,6 +207,15 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
176
207
  onInterrupt();
177
208
  return;
178
209
  }
210
+ // After a stop, a digit on an empty draft picks a next step; any other typed key hides the strip and types normally.
211
+ if (nextSteps > 0) {
212
+ if (value === "" && /^[1-9]$/.test(ch) && Number(ch) <= nextSteps && !key.ctrl && !key.meta) {
213
+ onPickNext?.(Number(ch));
214
+ return;
215
+ }
216
+ if (ch && !key.ctrl && !key.meta)
217
+ onDismissNext?.();
218
+ }
179
219
  if (key.return) {
180
220
  if (key.shift) {
181
221
  setValue((v) => `${v}\n`);
@@ -188,7 +228,20 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
188
228
  const text = commitDraft(); // chips -> real payload; the model gets the full paste, not "[Pasted #1]"
189
229
  if (text === null)
190
230
  return;
191
- if (disabled && onQueue)
231
+ // "@Nova <text>" never queues and never costs a main-model turn, idle or mid-turn; an @token that names no live
232
+ // sub-agent falls through, so a file mention still reaches the model.
233
+ if (onAgentMessage && agentMention(text, agents)) {
234
+ onAgentMessage(text);
235
+ return;
236
+ }
237
+ if (onSendTo && !isSlashCommand(text)) {
238
+ onSendTo(text);
239
+ return;
240
+ }
241
+ const route = enterRoute(text, { disabled, canSteer: !!onSteer, canQueue: !!onQueue });
242
+ if (route === "steer")
243
+ onSteer(text);
244
+ else if (route === "queue")
192
245
  onQueue(text);
193
246
  else
194
247
  onSubmit(text);
@@ -207,13 +260,16 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
207
260
  onDropQueued?.();
208
261
  return;
209
262
  }
210
- // ↑/↓ navigate the "/" menu when it's open — takes priority over history recall so arrows move the
211
- // highlight instead of clobbering the "/command" draft. Wraps around.
212
- if ((key.upArrow || key.downArrow) && menuMatches.length > 0) {
213
- const n = menuMatches.length;
263
+ // ↑/↓ navigate the "/" or "@" menu when it's open — takes priority over history recall so arrows move the
264
+ // highlight instead of clobbering the draft. Wraps around.
265
+ if ((key.upArrow || key.downArrow) && (menuMatches.length > 0 || atMatches)) {
266
+ const n = menuMatches.length || atMatches.length;
214
267
  setSelIdx((i) => (key.upArrow ? (i - 1 + n) % n : (i + 1) % n));
215
268
  return;
216
269
  }
270
+ // ↓ with nothing to recall moves focus to the conversation switcher on the mode line (A3.4).
271
+ if (key.downArrow && value === "" && !historyRef.current.recalling && onFocusSwitcher?.())
272
+ return;
217
273
  // History recall (shell-style): only on a single-line buffer, so ↑/↓ stay free for navigating
218
274
  // a multi-line draft instead of clobbering it. See useInputHistory.ts for the ring/draft model.
219
275
  if ((key.upArrow || key.downArrow) && !value.includes("\n")) {
@@ -250,7 +306,7 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
250
306
  const on = i === menuSel;
251
307
  const label = `/${c.name}${c.args ? " " + c.args : ""}`.padEnd(24);
252
308
  return (_jsxs(Text, { children: [_jsx(Text, { color: on ? "green" : undefined, bold: on, children: (on ? "▸ " : " ") + label }), _jsx(Text, { dimColor: true, children: c.description })] }, c.name));
253
- }), menuMatches.length > 10 && _jsx(Text, { dimColor: true, children: ` …and ${menuMatches.length - 10} more` })] }))] }));
309
+ }), menuMatches.length > 10 && _jsx(Text, { dimColor: true, children: ` …and ${menuMatches.length - 10} more` })] })), atMatches ? _jsx(Text, { dimColor: true, children: mentionMenuLine(atMatches, atSel, termCols()) }) : null] }));
254
310
  }
255
311
  // Recognize media file paths in the draft. IMAGE covers the common still formats, VIDEO the moving
256
312
  // ones; a path matching VIDEO is chipped as video, otherwise image. Extensions only — no I/O.
@@ -345,6 +401,16 @@ export function interruptPlan(key, ctx) {
345
401
  return { flushDraft: false, interrupt: true };
346
402
  return { flushDraft: false, interrupt: false };
347
403
  }
404
+ /** Where Enter sends a committed draft. At rest it submits. While a turn runs, plain text STEERS — it goes in before the
405
+ * turn's next model call, as an owner message — and a known /command queues (the shell decides whether it runs now or
406
+ * after the turn). Without a steer sink it queues, as before. */
407
+ export function enterRoute(text, ctx) {
408
+ if (!ctx.disabled)
409
+ return "submit";
410
+ if (ctx.canSteer && !isSlashCommand(text))
411
+ return "steer";
412
+ return ctx.canQueue ? "queue" : "submit";
413
+ }
348
414
  /** Pure decision for ↑ / Backspace while messages are queued. Only an EMPTY draft is eligible, so typing, deleting
349
415
  * and history recall are untouched while there is text in the box: ↑ = "edit" (pop the most recent queued message
350
416
  * into the draft), Backspace/Delete = "drop" (discard it). Anything else, or an empty queue, is null. */
@@ -361,6 +427,16 @@ export function queuedKeyPlan(key, ctx) {
361
427
  export function isBackgroundKey(ch, key) {
362
428
  return !!key.ctrl && (ch === "b" || ch === "z");
363
429
  }
430
+ /** ctrl+y — "use what you have" (TUI A3.3). Not ctrl+g: that opens the skills and tools finder. ctrl+y is bound nowhere
431
+ * else in Operator; in readline it is yank, which this composer does not implement, and in raw mode the terminal's
432
+ * delayed-suspend (DSUSP) never sees it. */
433
+ export function isActNowKey(ch, key) {
434
+ return !!key.ctrl && ch === "y";
435
+ }
436
+ /** ctrl+g — the skills and tools finder (TUI A3.3, James: "control+g should be to find tool / skill from our gateway"). */
437
+ export function isFinderKey(ch, key) {
438
+ return !!key.ctrl && ch === "g";
439
+ }
364
440
  /** ctrl+x — cycle the context pin (Ink reports it as "x" with ctrl). */
365
441
  export function isContextCycleKey(ch, key) {
366
442
  return !!key.ctrl && ch === "x";