quoxcli 0.2.0 → 0.3.1

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 (327) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -0
  3. package/bin/quox.js +99 -126
  4. package/lib/api/endpoints/admin.js +26 -0
  5. package/lib/api/endpoints/agent-schedules.js +26 -0
  6. package/lib/api/endpoints/agents.js +7 -0
  7. package/lib/api/endpoints/assistants.js +12 -0
  8. package/lib/api/endpoints/away.js +15 -0
  9. package/lib/api/endpoints/chat.js +7 -0
  10. package/lib/api/endpoints/contactsq.js +2 -0
  11. package/lib/api/endpoints/conversations.js +14 -0
  12. package/lib/api/endpoints/executions.js +13 -0
  13. package/lib/api/endpoints/fetchAllowlist.js +27 -0
  14. package/lib/api/endpoints/files.js +14 -0
  15. package/lib/api/endpoints/hat.js +30 -0
  16. package/lib/api/endpoints/inbox.js +20 -0
  17. package/lib/api/endpoints/index.js +14 -0
  18. package/lib/api/endpoints/memory.js +19 -0
  19. package/lib/api/endpoints/mind.js +13 -0
  20. package/lib/api/endpoints/mon.js +6 -0
  21. package/lib/api/endpoints/objectives.js +6 -0
  22. package/lib/api/endpoints/plugins.js +18 -0
  23. package/lib/api/endpoints/presence.js +33 -0
  24. package/lib/api/endpoints/quoxplan.js +7 -0
  25. package/lib/api/endpoints/quoxseo.js +6 -0
  26. package/lib/api/endpoints/router.js +17 -0
  27. package/lib/api/endpoints/safety.js +7 -0
  28. package/lib/api/endpoints/skills.js +20 -0
  29. package/lib/api/endpoints/stepup.js +20 -0
  30. package/lib/api/endpoints/teams.js +2 -2
  31. package/lib/api/endpoints/triggers.js +26 -0
  32. package/lib/api/endpoints/v1.js +86 -0
  33. package/lib/api/endpoints/ward.js +7 -0
  34. package/lib/api/endpoints/workflows.js +7 -0
  35. package/lib/api/endpoints/x.js +8 -0
  36. package/lib/commands/actions.js +61 -0
  37. package/lib/commands/admin.js +16 -0
  38. package/lib/commands/agent.js +163 -27
  39. package/lib/commands/agentAttach.js +94 -6
  40. package/lib/commands/approvals.js +73 -1
  41. package/lib/commands/aside.js +24 -0
  42. package/lib/commands/ask.js +144 -0
  43. package/lib/commands/assistant.js +59 -4
  44. package/lib/commands/auth.js +8 -2
  45. package/lib/commands/backup.js +8 -4
  46. package/lib/commands/brain.js +105 -14
  47. package/lib/commands/build.js +19 -5
  48. package/lib/commands/chat.js +57 -2
  49. package/lib/commands/claude.js +34 -8
  50. package/lib/commands/contacts.js +49 -0
  51. package/lib/commands/conversation.js +35 -4
  52. package/lib/commands/dashboard.js +43 -0
  53. package/lib/commands/department.js +28 -7
  54. package/lib/commands/devResident.js +15 -3
  55. package/lib/commands/devSupervisor.js +13 -1
  56. package/lib/commands/discord.js +75 -39
  57. package/lib/commands/done.js +98 -28
  58. package/lib/commands/engagement.js +17 -6
  59. package/lib/commands/fetchAllowlist.js +71 -0
  60. package/lib/commands/file.js +38 -1
  61. package/lib/commands/fleet.js +311 -4
  62. package/lib/commands/governance.js +12 -3
  63. package/lib/commands/gripe.js +44 -13
  64. package/lib/commands/hat.js +178 -9
  65. package/lib/commands/helpers.js +18 -1
  66. package/lib/commands/hyperion.js +58 -0
  67. package/lib/commands/inbox.js +74 -23
  68. package/lib/commands/licence.js +14 -155
  69. package/lib/commands/lucid.js +10 -4
  70. package/lib/commands/memory.js +85 -8
  71. package/lib/commands/mind.js +71 -0
  72. package/lib/commands/mon.js +69 -2
  73. package/lib/commands/monitoring.js +1 -1
  74. package/lib/commands/motion.js +2 -2
  75. package/lib/commands/nucleus.js +48 -17
  76. package/lib/commands/objective.js +11 -0
  77. package/lib/commands/offload.js +89 -0
  78. package/lib/commands/onboard.js +2 -1
  79. package/lib/commands/org.js +11 -1
  80. package/lib/commands/peek.js +28 -0
  81. package/lib/commands/plan.js +38 -0
  82. package/lib/commands/plugin.js +110 -0
  83. package/lib/commands/presence.js +89 -0
  84. package/lib/commands/provider.js +159 -0
  85. package/lib/commands/qlarity.js +19 -3
  86. package/lib/commands/quoxchat.js +13 -4
  87. package/lib/commands/quoxseo.js +38 -0
  88. package/lib/commands/reach.js +2 -1
  89. package/lib/commands/router.js +77 -0
  90. package/lib/commands/rows.js +358 -0
  91. package/lib/commands/run.js +64 -9
  92. package/lib/commands/server.js +292 -0
  93. package/lib/commands/setup.js +33 -7
  94. package/lib/commands/skills.js +48 -5
  95. package/lib/commands/slot.js +260 -7
  96. package/lib/commands/status.js +1 -1
  97. package/lib/commands/team.js +3 -1
  98. package/lib/commands/tips.js +23 -0
  99. package/lib/commands/tool.js +133 -45
  100. package/lib/commands/trace.js +12 -7
  101. package/lib/commands/trigger.js +95 -0
  102. package/lib/commands/update.js +46 -0
  103. package/lib/commands/vault.js +31 -8
  104. package/lib/commands/vm.js +237 -0
  105. package/lib/commands/voice.js +34 -3
  106. package/lib/commands/volt.js +45 -3
  107. package/lib/commands/walkthrough.js +32 -0
  108. package/lib/commands/watch.js +73 -21
  109. package/lib/commands/welcome.js +14 -0
  110. package/lib/commands/workflow.js +189 -32
  111. package/lib/commands/x.js +13 -4
  112. package/lib/core/actingAs.js +2 -2
  113. package/lib/core/activeSummary.js +186 -0
  114. package/lib/core/aside.js +54 -0
  115. package/lib/core/askDecision.js +60 -0
  116. package/lib/core/auth.js +164 -13
  117. package/lib/core/callerSource.js +1 -1
  118. package/lib/core/cliBuild.js +62 -0
  119. package/lib/core/client.js +144 -35
  120. package/lib/core/commandRegistrars.js +121 -0
  121. package/lib/core/config.js +142 -24
  122. package/lib/core/customHats.js +168 -0
  123. package/lib/core/doneEngineFetch.js +8 -0
  124. package/lib/core/errors.js +329 -20
  125. package/lib/core/global-flags.js +105 -5
  126. package/lib/core/hyperion.js +102 -0
  127. package/lib/core/inboxResolution.js +65 -0
  128. package/lib/core/lazyCommands.js +4 -1
  129. package/lib/core/offload.js +504 -0
  130. package/lib/core/org-override.js +1 -1
  131. package/lib/core/orgResolve.js +70 -0
  132. package/lib/core/output.js +4 -4
  133. package/lib/core/peek.js +126 -0
  134. package/lib/core/profileUsers.js +51 -0
  135. package/lib/core/promptCancel.js +18 -0
  136. package/lib/core/repoPath.js +11 -0
  137. package/lib/core/residentSeed.js +3 -1
  138. package/lib/core/rootOptions.js +39 -0
  139. package/lib/core/router.js +168 -0
  140. package/lib/core/selfUpdate.js +188 -0
  141. package/lib/core/sessionsOverview.js +64 -0
  142. package/lib/core/slotKeeper.js +248 -3
  143. package/lib/core/slotWake.js +120 -0
  144. package/lib/core/supervisorEngine.js +71 -2
  145. package/lib/core/version.js +1 -1
  146. package/lib/core/vm.js +361 -0
  147. package/lib/core/vmTui.js +86 -0
  148. package/lib/core/walkthrough.js +35 -0
  149. package/lib/hyperion/deck.js +29 -0
  150. package/lib/lucid/LucidCard.jsx +68 -0
  151. package/lib/lucid/LucidIntro.jsx +45 -58
  152. package/lib/lucid/cards.js +86 -0
  153. package/lib/lucid/markdown.js +81 -0
  154. package/lib/lucid/motion.js +56 -0
  155. package/lib/quoxon/activity.js +14 -2
  156. package/lib/quoxon/aocl.js +117 -0
  157. package/lib/quoxon/api.js +504 -25
  158. package/lib/quoxon/app.js +3000 -230
  159. package/lib/quoxon/approvalFacts.js +94 -0
  160. package/lib/quoxon/approvalsView.js +325 -0
  161. package/lib/quoxon/asideView.js +40 -0
  162. package/lib/quoxon/ask.js +121 -0
  163. package/lib/quoxon/away.js +52 -0
  164. package/lib/quoxon/bang.js +224 -0
  165. package/lib/quoxon/bulkRisk.js +17 -0
  166. package/lib/quoxon/capabilities.js +13 -6
  167. package/lib/quoxon/cells.js +53 -0
  168. package/lib/quoxon/commandShort.js +112 -0
  169. package/lib/quoxon/commands.js +363 -38
  170. package/lib/quoxon/connect.js +210 -23
  171. package/lib/quoxon/connectCard.js +19 -2
  172. package/lib/quoxon/consent.js +86 -0
  173. package/lib/quoxon/copy.js +4 -3
  174. package/lib/quoxon/countdownLine.js +11 -0
  175. package/lib/quoxon/demo.autoplay.js +29 -0
  176. package/lib/quoxon/demo.fixtures.js +1 -1
  177. package/lib/quoxon/demo.js +44 -3
  178. package/lib/quoxon/devObserver.js +20 -0
  179. package/lib/quoxon/dividerAocl.js +191 -0
  180. package/lib/quoxon/dividerRule.js +57 -0
  181. package/lib/quoxon/dragonModes.js +150 -0
  182. package/lib/quoxon/dragonView.js +41 -0
  183. package/lib/quoxon/earlyInput.js +40 -0
  184. package/lib/quoxon/echo.js +15 -0
  185. package/lib/quoxon/egg.js +2 -2
  186. package/lib/quoxon/events.js +244 -25
  187. package/lib/quoxon/feedback.js +50 -0
  188. package/lib/quoxon/gallery.js +21 -7
  189. package/lib/quoxon/handoffOffer.js +78 -0
  190. package/lib/quoxon/hatSwitch.js +37 -0
  191. package/lib/quoxon/headless.js +161 -0
  192. package/lib/quoxon/hostUrls.js +41 -0
  193. package/lib/quoxon/indicator.js +6 -2
  194. package/lib/quoxon/intent.js +12 -1
  195. package/lib/quoxon/keys.js +49 -6
  196. package/lib/quoxon/launcher.js +103 -0
  197. package/lib/quoxon/main.js +92 -160
  198. package/lib/quoxon/markdown.js +45 -21
  199. package/lib/quoxon/markdownSettle.js +19 -0
  200. package/lib/quoxon/matrixDomains.json +46 -0
  201. package/lib/quoxon/mentions.js +90 -0
  202. package/lib/quoxon/mind.js +103 -0
  203. package/lib/quoxon/mode.js +46 -0
  204. package/lib/quoxon/model.js +132 -26
  205. package/lib/quoxon/modelPrefs.js +345 -0
  206. package/lib/quoxon/motion/clock.js +3 -2
  207. package/lib/quoxon/motion/level.js +91 -0
  208. package/lib/quoxon/mouse.js +211 -0
  209. package/lib/quoxon/noai.js +57 -0
  210. package/lib/quoxon/objects/away.js +72 -0
  211. package/lib/quoxon/objects/fetch.js +17 -5
  212. package/lib/quoxon/objects/fleet.js +149 -0
  213. package/lib/quoxon/objects/health.js +186 -0
  214. package/lib/quoxon/objects/index.js +24 -3
  215. package/lib/quoxon/objects/mirror.js +137 -0
  216. package/lib/quoxon/objects/peek.js +17 -0
  217. package/lib/quoxon/objects/prove.js +130 -0
  218. package/lib/quoxon/objects/replay.js +125 -0
  219. package/lib/quoxon/objects/sitrep.js +58 -0
  220. package/lib/quoxon/objects/view.js +11 -0
  221. package/lib/quoxon/onboarding/copy.js +32 -4
  222. package/lib/quoxon/onboarding/credential.js +17 -4
  223. package/lib/quoxon/onboarding/dockerOffer.js +45 -0
  224. package/lib/quoxon/onboarding/failureCause.js +33 -0
  225. package/lib/quoxon/onboarding/finish.js +15 -0
  226. package/lib/quoxon/onboarding/index.js +34 -7
  227. package/lib/quoxon/onboarding/installRunner.js +64 -5
  228. package/lib/quoxon/onboarding/preflight.js +17 -3
  229. package/lib/quoxon/onboarding/probe.js +65 -0
  230. package/lib/quoxon/onboarding/view.js +76 -19
  231. package/lib/quoxon/orgLabel.js +10 -0
  232. package/lib/quoxon/orgSwitch.js +33 -0
  233. package/lib/quoxon/ownBroadcast.js +22 -0
  234. package/lib/quoxon/palette.js +43 -0
  235. package/lib/quoxon/print.js +9 -5
  236. package/lib/quoxon/profileSwitch.js +53 -0
  237. package/lib/quoxon/promptHistory.js +41 -0
  238. package/lib/quoxon/providers.js +48 -0
  239. package/lib/quoxon/qart.js +20 -51
  240. package/lib/quoxon/qdragon.js +410 -0
  241. package/lib/quoxon/qdragonFly.js +61 -0
  242. package/lib/quoxon/qdragonScenes.js +282 -0
  243. package/lib/quoxon/qeyes.js +213 -0
  244. package/lib/quoxon/qmotion.js +58 -37
  245. package/lib/quoxon/render.js +638 -119
  246. package/lib/quoxon/resend.js +72 -0
  247. package/lib/quoxon/roster.js +95 -9
  248. package/lib/quoxon/route.js +6 -5
  249. package/lib/quoxon/rows.js +711 -0
  250. package/lib/quoxon/rowsStore.js +80 -0
  251. package/lib/quoxon/screenContext.js +150 -0
  252. package/lib/quoxon/screenFrames.js +254 -0
  253. package/lib/quoxon/session.js +172 -2
  254. package/lib/quoxon/sessionDead.js +17 -0
  255. package/lib/quoxon/signin.js +125 -0
  256. package/lib/quoxon/slash/agents.js +112 -0
  257. package/lib/quoxon/slash/argSources.js +65 -0
  258. package/lib/quoxon/slash/args.js +65 -0
  259. package/lib/quoxon/slash/automate.js +89 -0
  260. package/lib/quoxon/slash/broadcast.js +140 -0
  261. package/lib/quoxon/slash/broadcastRun.js +108 -0
  262. package/lib/quoxon/slash/card.js +30 -0
  263. package/lib/quoxon/slash/challenge.js +114 -0
  264. package/lib/quoxon/slash/cliCommand.js +53 -0
  265. package/lib/quoxon/slash/cliLeaves.json +948 -0
  266. package/lib/quoxon/slash/compact.js +1 -1
  267. package/lib/quoxon/slash/confirm.js +30 -0
  268. package/lib/quoxon/slash/crystallize.js +69 -0
  269. package/lib/quoxon/slash/dashboard.js +136 -0
  270. package/lib/quoxon/slash/draft.js +54 -0
  271. package/lib/quoxon/slash/hatWalk.js +206 -0
  272. package/lib/quoxon/slash/inverses.js +77 -0
  273. package/lib/quoxon/slash/killer.js +24 -0
  274. package/lib/quoxon/slash/killerApi.js +16 -0
  275. package/lib/quoxon/slash/ledger.js +13 -8
  276. package/lib/quoxon/slash/listView.js +3 -1
  277. package/lib/quoxon/slash/modelCmd.js +261 -0
  278. package/lib/quoxon/slash/palette.js +21 -7
  279. package/lib/quoxon/slash/paletteController.js +117 -7
  280. package/lib/quoxon/slash/panels.js +21 -6
  281. package/lib/quoxon/slash/picker.js +20 -2
  282. package/lib/quoxon/slash/restart.js +71 -13
  283. package/lib/quoxon/slash/rowCmd.js +157 -0
  284. package/lib/quoxon/slash/rowWalk.js +175 -0
  285. package/lib/quoxon/slash/settings.js +16 -6
  286. package/lib/quoxon/slash/spawn.js +177 -0
  287. package/lib/quoxon/slash/stepUp.js +274 -0
  288. package/lib/quoxon/slash/stepUpCard.js +60 -0
  289. package/lib/quoxon/slash/stepUpCmds.js +78 -0
  290. package/lib/quoxon/slash/undoApi.js +38 -0
  291. package/lib/quoxon/slash/undoCmd.js +49 -0
  292. package/lib/quoxon/slash/undoWish.js +15 -0
  293. package/lib/quoxon/slash/watch.js +164 -0
  294. package/lib/quoxon/slash/wish.js +23 -0
  295. package/lib/quoxon/slash/wishCmd.js +32 -0
  296. package/lib/quoxon/slotChat.js +300 -0
  297. package/lib/quoxon/slotFormat.js +195 -0
  298. package/lib/quoxon/slotRun.js +131 -0
  299. package/lib/quoxon/sound/mapping.js +2 -1
  300. package/lib/quoxon/stray.js +22 -0
  301. package/lib/quoxon/suggestCommand.js +59 -0
  302. package/lib/quoxon/term.js +46 -11
  303. package/lib/quoxon/textBuffer.js +176 -2
  304. package/lib/quoxon/theme.js +58 -25
  305. package/lib/quoxon/tips.js +433 -0
  306. package/lib/quoxon/toolError.js +41 -0
  307. package/lib/quoxon/transcript.js +42 -4
  308. package/lib/quoxon/web/qface.js +18 -10
  309. package/lib/quoxon/welcome.js +1 -1
  310. package/lib/quoxon/whatsnew.js +136 -0
  311. package/lib/quoxon/whatsnew.jsonl +89 -0
  312. package/lib/quoxon/windowOrg.js +113 -0
  313. package/lib/server/diag.js +129 -0
  314. package/lib/server/doctor.js +71 -0
  315. package/lib/server/install.js +149 -0
  316. package/lib/server/pluginEnable.js +161 -0
  317. package/lib/server/skew.js +56 -0
  318. package/lib/server/snapshot.js +131 -0
  319. package/lib/server/status.js +128 -0
  320. package/lib/server/sys.js +65 -0
  321. package/lib/server/uninstall.js +63 -0
  322. package/lib/server/update.js +234 -0
  323. package/lib/toolOutputShape.js +315 -0
  324. package/lib/tui/views/HyperionDeck.jsx +79 -0
  325. package/lib/tui/views/LucidDeck.jsx +209 -217
  326. package/package.json +4 -1
  327. package/lib/core/websiteSession.js +0 -148
@@ -5,22 +5,31 @@
5
5
  import React from 'react';
6
6
  import chalk from 'chalk';
7
7
  import { Box, Text, useStdout } from 'ink';
8
- import { graphemes, lineCol } from './textBuffer.js';
8
+ import stringWidth from 'string-width';
9
+ import { graphemes, lineCol, selection, composerFrom } from './textBuffer.js';
9
10
 
10
11
  const h = React.createElement;
11
12
  /** Coloured runs (from theme.paintLine/paintRuns) as Text children; the characters are unchanged. */
12
13
  const runs = (rs) => rs.map((r, i) => (r.role ? h(Text, { key: i, color: c(r.role) }, r.text) : r.text));
13
14
 
14
- import { COLORS, MODE_COLOR, MIN_COLS, mono, c, clampCols, clip, paintLine, paintRuns, agentColor, proto } from './theme.js';
15
+ import { COLORS, MODE_COLOR, MIN_COLS, mono, c, clampCols, clip, paintLine, paintRuns, agentColor, proto, toneText, stripMarks, providerOf, providerColor } from './theme.js';
15
16
  import { reducedMotion, motionAllowed } from './motion/clock.js';
16
17
  import { ruleColors, ringStep, ringMode } from './motion/ring.js';
17
18
  import { useFrame } from './motion/frame.js';
18
19
  import { rgbStr, hexRgb, mix, clamp01, mixOk, pulse01 } from './motion/color.js';
19
20
  import { revealCells, TIMING } from './motion/reveal.js';
21
+ import { handoffFrame } from './motion/level.js';
22
+ import { dividerRuleEl } from './dividerRule.js';
20
23
  import * as themeNs from './theme.js';
21
24
  import { qArt, qArtFrame } from '../core/banner.js';
22
- import { Markdown, markdownRows, wrapRows, WText, Heading } from './markdown.js';
25
+ import { cmd } from './palette.js';
26
+ import { themeRole, rowParts, clipParts, labelWidth } from './rows.js';
27
+ import { Markdown, wrapCell, markdownRows, wrapRows, WText, Heading } from './markdown.js';
28
+ import { parseAsk, keysLabel, askText } from './ask.js';
29
+ import { parseAsideNote } from './asideView.js';
30
+ import { formatSlotBody, inlineable, codeRows } from './slotFormat.js';
23
31
  import { termRows } from './term.js';
32
+ import { cellWidth, ambiguousWide } from './cells.js';
24
33
  import { welcomeModel } from './welcome.js';
25
34
  import { Q_GLYPH, qColor, stateWord, indicatorState, fmtTokens, wordFrame, wordColor } from './indicator.js';
26
35
 
@@ -28,7 +37,10 @@ import { qSize, qDims, orbitFrame, qLines, labSize, introPlan, qCells, cellsToAn
28
37
  import { glyphStill, glyphMode, colorDepth } from './qglyph.js';
29
38
  export { INTRO_MS };
30
39
  import { QGlyph, cellNodes } from './qmotion.js';
40
+ import { CLIPS as DRAGON_CLIPS, clipCells } from './qdragonScenes.js';
41
+ import { dragonLayout } from './qdragon.js';
31
42
  import { ObjectView } from './objects/view.js';
43
+ import { aoclLineSegs, aoclTableLines } from './aocl.js';
32
44
  export { COLORS, MODE_COLOR, MIN_COLS, clampCols, clip, reducedMotion };
33
45
 
34
46
  // ---- working indicator (the one animated line) -------------------------------------------------
@@ -50,7 +62,7 @@ export const STATIC_RAIN = 'クオック'.slice(0, RAIN);
50
62
  export function describeActivity(state) {
51
63
  const running = state.blocks.filter(b => b.kind === 'tool' && b.status === 'running');
52
64
  if (state.approvals.length) return 'Waiting for approval';
53
- if (running.length) return `Running ${running[running.length - 1].tool}`;
65
+ if (running.length) { const r = running[running.length - 1]; return r.agentName ? `Delegating to ${r.agentName}` : `Running ${r.tool}`; }
54
66
  if (state.turn?.status === 'interrupting') return 'Stopping';
55
67
  return state.turn?.stage || 'Working';
56
68
  }
@@ -60,7 +72,7 @@ export function describeActivity(state) {
60
72
  * is on, once a second otherwise) and passes `now`. `motion` false = static word and colour (reduced motion);
61
73
  * colour is separately off under NO_COLOR.
62
74
  */
63
- export const Working = ({ activity, since, interrupting, escLabel, state, failing = false, tokens = 0, act = null, now: nowProp, motion = !reducedMotion() }) => {
75
+ export const Working = ({ activity, since, interrupting, escLabel, state, failing = false, tokens = 0, act = null, now: nowProp, motion = !reducedMotion(), handoff = false }) => {
64
76
  const now = useFrame(nowProp);
65
77
  const quiet = !motion;
66
78
  const t = Math.floor(now / 120); // the indicator's colour periods are in 120 ms ticks
@@ -77,7 +89,12 @@ export const Working = ({ activity, since, interrupting, escLabel, state, failin
77
89
  // clock, ~30% scrambled at a time, cascades of 2..4 half-width katakana resolving with a flash. Reduced
78
90
  // motion: a still, coloured, plain word. NO_COLOR: the motion stays, the colour goes. Elapsed, tokens and
79
91
  // hints are never scrambled.
80
- const plain = clip(stateWord(st, act ? act.word : activity), 40);
92
+ // Silent wait (FW1): after 3 s on one activity with no answer text, say what it is waiting on, live.
93
+ const actSecs = act ? Math.max(0, Math.floor((now - act.since) / 1000)) : 0;
94
+ const longWait = Boolean(act) && st === 'working' && actSecs >= 3 && act.word !== 'Writing';
95
+ const waitTool = longWait && act.tool ? act.tool : null;
96
+ const stale = longWait && !act.tool && (act.word === 'Sending' || act.word === 'Routing');
97
+ const plain = clip(stateWord(st, stale ? 'Thinking' : (act ? act.word : activity)), 40);
81
98
  const scramble = st === 'working' && !quiet;
82
99
  const cst = st === 'working' && (act ? act.word : activity) === 'Writing' ? 'writing' : st;
83
100
  const cells = scramble ? wordFrame(plain, now, { since: seenRef.current.at }) : [...plain].map(ch => ({ ch, glyph: false, flash: false }));
@@ -87,14 +104,18 @@ export const Working = ({ activity, since, interrupting, escLabel, state, failin
87
104
  color: mono() ? undefined : `rgb(${wordColor(cst, i, n, now, g.flash ? 'flash' : g.glyph ? 'glyph' : 'letter', quiet).join(',')})`
88
105
  }, g.ch));
89
106
  const ell = st === 'failing' ? null : h(Text, { key: 'e', color: mono() ? undefined : `rgb(${wordColor(cst, n, n + 1, now, 'letter', quiet).join(',')})` }, '…');
90
- const detail = act?.detail && st !== 'failing' ? clip(act.detail, 28) : '';
91
- const word = h(Text, { wrap: 'truncate-end' }, h(Text, null, ...wordNodes, ell),
92
- detail ? h(Text, { color: c('dim') }, ` · ${detail} · `) : (st === 'failing' ? '' : ' '));
107
+ const detail = waitTool ? clip(`waiting on ${waitTool}`, 40) : (act?.detail && st !== 'failing' ? clip(act.detail, 28) : '');
108
+ // Expressive: while delegating, a dot travels from Quox to the agent it is handing to (motion/level.js).
109
+ const delegating = handoff && !quiet && st === 'working' && (act ? act.word : activity) === 'Delegating';
110
+ const track = delegating ? h(Text, { key: 'ho' }, ' ', ...handoffFrame(now, 5, { mono: mono() }).map((cl, i) => h(Text, { key: i, color: cl.rgb ? rgbStr(cl.rgb) : undefined }, cl.ch))) : null;
111
+ const word = h(Text, { wrap: 'truncate-end' }, h(Text, null, ...wordNodes, ell), track,
112
+ detail ? h(Text, { color: c('dim') }, ` ${delegating ? '' : '· '}${detail}`) : '');
93
113
  const { stdout: so } = useStdout();
94
114
  const narrow = (so?.columns || 100) < 60; // keep the line on one row: short hint, tokens still shown
95
115
  const tok = tokens > 0 ? ` · ↓ ${fmtTokens(tokens)} tokens` : '';
96
- const tail = st === 'failing' ? '' : `${secs}s${tok} · ${interrupting ? 'stopping; waiting for the server to confirm' : (narrow ? 'Esc' : (escLabel || 'Esc to stop'))}`;
97
- return h(Box, { paddingLeft: 2 }, q, h(Text, null, ' '), word, h(Text, { color: c('dim') }, tail));
116
+ const sep = st === 'failing' ? '' : (detail ? ' · ' : ' '); // the separator lives in the tail so a squeezed word never swallows it
117
+ const tail = st === 'failing' ? '' : `${sep}${waitTool ? actSecs : secs}s${tok} · ${interrupting ? 'stopping; waiting for the server to confirm' : (narrow ? 'Esc' : (escLabel || 'Esc to stop'))}`;
118
+ return h(Box, { paddingLeft: 2 }, q, h(Text, null, ' '), word, h(Text, { color: c('dim'), wrap: 'truncate-end' }, tail));
98
119
  };
99
120
 
100
121
  // ---- drop-in reveals (motion/reveal.js) ------------------------------------------------------------
@@ -197,13 +218,38 @@ export function fitResult(summary, max) {
197
218
  return ''; // not even one whole pair fits: show none rather than a value without its key
198
219
  }
199
220
 
200
- export function ToolRow({ b, cols, fx = null, pulse = null }) {
221
+ /**
222
+ * The ignition glow's colour (expressive motion): `hex` flared by g 0..1. Dark terminals flare towards a warm
223
+ * white, light ones towards amber (white would vanish on a light background). g 0 returns hex untouched.
224
+ */
225
+ export function igniteColor(col, g, light = themeNs.isLight()) {
226
+ const rgb = Array.isArray(col) ? col : typeof col === 'string' && /^#[0-9a-f]{6}$/i.test(col) ? hexRgb(col) : null;
227
+ if (!(g > 0) || !rgb) return Array.isArray(col) ? rgbStr(col) : col;
228
+ return rgbStr(mix(rgb, light ? [217, 119, 6] : [255, 244, 214], Math.min(1, g) * (light ? 0.7 : 0.85)));
229
+ }
230
+
231
+ /** Pure: the delegation row text. body while running names the target and the task; the result names the outcome. */
232
+ export function delegationText(b) {
233
+ const who = b.agentName;
234
+ const body = b.status === 'running' ? `Delegating to ${who}${b.taskGist ? ` \u00b7 ${b.taskGist}` : ''}` : `${who}${b.taskGist ? ` \u00b7 ${b.taskGist}` : ''}`;
235
+ if (b.status === 'running') return { body, result: '', warn: false };
236
+ if (b.status === 'ok' && Number.isFinite(b.toolsUsed)) {
237
+ return b.toolsUsed === 0
238
+ ? { body, result: `${who} did nothing (0 tools)`, warn: true }
239
+ : { body, result: `${who} finished \u00b7 used ${b.toolsUsed} tool${b.toolsUsed === 1 ? '' : 's'}`, warn: false };
240
+ }
241
+ return { body, result: '', warn: false };
242
+ }
243
+
244
+ export function ToolRow({ b, cols, fx = null, pulse = null, ignite = 0 }) {
201
245
  const glyph = STATUS_GLYPH[b.status] || '◐';
202
246
  const tone = STATUS_TONE[b.status] || 'sky';
203
247
  const dur = fmtDuration(b.durationMs);
204
248
  const { family, verb } = toolLabel(b.tool);
205
249
  const name = clip(family, 10);
206
- const body0 = b.summary && b.summary !== b.tool ? b.summary : verb;
250
+ // QUOXON-FW3: a delegation names WHO ran it, what it was for, and whether it did anything.
251
+ const deleg = b.agentName ? delegationText(b) : null;
252
+ const body0 = deleg ? deleg.body : b.summary && b.summary !== b.tool ? b.summary : verb;
207
253
  const room = Math.max(4, cols - 2 - 2 - gw(name) - 3); // indent, glyph + space, family, ' │ '
208
254
  const running = b.status === 'running';
209
255
  // the facts after the result: duration, then witnessing state
@@ -214,7 +260,7 @@ export function ToolRow({ b, cols, fx = null, pulse = null }) {
214
260
  } else if (!running) {
215
261
  after = [dur, b.envelopeId ? `envelope ${String(b.envelopeId).slice(0, 8)}` : '', b.envelopeId ? 'witnessing pending' : ''].filter(Boolean);
216
262
  }
217
- const result = running ? '' : (b.resultSummary ? `${b.status === 'unknown' ? 'unknown: ' : ''}${b.resultSummary}` : b.status);
263
+ const result = running ? '' : deleg && deleg.result ? deleg.result : (b.resultSummary ? `${b.status === 'unknown' ? 'unknown: ' : ''}${b.resultSummary}` : b.status);
218
264
  const bodyStr = clipWords(body0, running || !result ? room : Math.max(6, Math.min(gw(body0), Math.floor(room / 2))));
219
265
  const tailRoom = room - gw(bodyStr) - 3;
220
266
  let tail = '';
@@ -227,9 +273,13 @@ export function ToolRow({ b, cols, fx = null, pulse = null }) {
227
273
  const verified = b.receipt?.verified === true;
228
274
  const glyphColor = b.receipt && !running ? (verified ? 'ok' : 'warn') : tone;
229
275
  // Running: one glyph whose colour pulses sky <-> violet in OKLab (never a spinner of different glyphs).
230
- const runColor = running && pulse != null && !mono() ? rgbStr(mixOk(hexRgb(COLORS.sky), hexRgb(COLORS.violet), pulse01(pulse, 1200))) : null;
231
- const tailRuns = tail ? paintRuns(tail, tone === 'ok' ? 'value' : tone).map(r => (/^(witnessed)$/.test(r.text.trim()) ? { ...r, role: 'ok' } : r)) : [];
232
- const head = [{ t: ' ' }, { t: glyph, color: runColor || glyphColor }, { t: ' ' }, { t: name, color: agentColor(name), bold: true }, { t: ' │ ', color: 'muted' }, { t: bodyStr, color: 'text' }];
276
+ const runRgb = running && pulse != null && !mono() ? mixOk(hexRgb(COLORS.sky), hexRgb(COLORS.violet), pulse01(pulse, 1200)) : null;
277
+ const runColor = runRgb ? rgbStr(runRgb) : null;
278
+ const tailRuns = tail ? paintRuns(tail, deleg && deleg.warn ? 'warn' : tone === 'ok' ? 'value' : tone).map(r => (/^(witnessed)$/.test(r.text.trim()) ? { ...r, role: 'ok' } : r)) : [];
279
+ // Expressive: the row ignites as the tool starts (a short warm flare on the glyph and the family, motion/level.js).
280
+ const lit = running && ignite > 0 && !mono();
281
+ const glyphC = lit ? igniteColor(runRgb || c(glyphColor) || COLORS.sky, ignite) : runColor || glyphColor;
282
+ const head = [{ t: ' ' }, { t: glyph, color: glyphC, bold: lit && ignite > 0.5 }, { t: ' ' }, { t: name, color: lit ? igniteColor(agentColor(name), ignite * 0.7) : agentColor(name), bold: true }, { t: ' │ ', color: 'muted' }, { t: bodyStr, color: 'text' }];
233
283
  const tailSegs = tail ? [{ t: ' │ ', color: 'muted' }, ...tailRuns.map(r => ({ t: r.text, color: r.role }))] : [];
234
284
  // Settle (running -> result): the glyph flashes once and the result decodes in behind it.
235
285
  if (fx?.settle != null && !running) {
@@ -271,6 +321,37 @@ function protoIconColor(protocol, { pulse = null, fx = null } = {}) {
271
321
  return rgbStr(col);
272
322
  }
273
323
 
324
+ /**
325
+ * Pure: a protocol row body wrapped into at most `max` lines of `room` cells, breaking only at spaces (a word
326
+ * longer than a whole line is the one thing ever cut). Overflow ends the last line with " …" after a whole word.
327
+ */
328
+ export function wrapTrace(body, room, max = 4) {
329
+ const words = String(body || '').split(' ').filter(Boolean);
330
+ const w = (s) => [...s].length;
331
+ const lines = [];
332
+ let cur = '';
333
+ let i = 0;
334
+ for (; i < words.length && lines.length < max; i++) {
335
+ let word = words[i];
336
+ if (!cur && w(word) > room) { // longer than a line: the only hard break
337
+ while (w(word) > room && lines.length < max) { lines.push([...word].slice(0, room).join('')); word = [...word].slice(room).join(''); }
338
+ if (lines.length >= max) { i++; break; }
339
+ cur = word; continue;
340
+ }
341
+ if (!cur) { cur = word; continue; }
342
+ if (w(cur) + 1 + w(word) <= room) { cur += ' ' + word; continue; }
343
+ lines.push(cur); cur = '';
344
+ i--; // place this word on the next line
345
+ }
346
+ if (cur && lines.length < max) lines.push(cur);
347
+ if (i < words.length) { // more than fits: end on a whole word plus an ellipsis
348
+ let last = lines.length ? lines[lines.length - 1] : '';
349
+ while (last && w(last) + 2 > room) last = last.includes(' ') ? last.slice(0, last.lastIndexOf(' ')) : [...last].slice(0, Math.max(0, room - 2)).join('');
350
+ lines[Math.max(0, lines.length - 1)] = `${last} …`;
351
+ }
352
+ return lines;
353
+ }
354
+
274
355
  export function TraceRow({ b, cols, fx = null, pulse = null }) {
275
356
  const [g, label] = PROTO[b.protocol] || ['·', String(b.protocol || 'TRACE').toUpperCase()];
276
357
  const ref = b.ref != null ? ` · ${String(b.ref).slice(0, 8)}` : '';
@@ -286,25 +367,37 @@ export function TraceRow({ b, cols, fx = null, pulse = null }) {
286
367
  if (!fx) return h(Box, null, h(Text, null, ' ', icon, labelNode, h(Text, { color: c('muted') }, afterIcon.slice(labelSeg.length) + body)));
287
368
  return h(Box, null, h(Text, null, ' '), icon, ...fxNodes([{ t: labelSeg, color: 'proto:' + b.protocol }, { t: afterIcon.slice(labelSeg.length) + body, color: 'muted' }], fx, 5));
288
369
  }
289
- // Too long even when compacted: wrap onto indented lines (at most 4) rather than hiding the end.
290
- const chars = [...body]; const pad = ' '.repeat([...head].length); const lines = [];
291
- for (let i = 0; i < chars.length && lines.length < 4; i += room) lines.push((lines.length ? pad : afterIcon) + chars.slice(i, i + room).join(''));
292
- if (chars.length > room * 4) lines[3] = clip(lines[3], [...head].length + room);
370
+ // Too long even when compacted: wrap at word boundaries onto indented lines (at most 4) rather than hiding the end.
371
+ const pad = ' '.repeat([...head].length);
372
+ const lines = wrapTrace(body, room, 4).map((l, i) => (i ? pad : afterIcon) + l);
293
373
  return h(Box, { flexDirection: 'column' }, ...lines.map((l, i) => (i === 0
294
374
  ? h(Text, { key: i }, ' ', icon, labelNode, h(Text, { color: c('muted') }, l.slice(labelSeg.length)))
295
375
  : h(Text, { key: i, color: c('muted') }, l))));
296
376
  }
297
377
 
298
378
  export function HelpView({ model, cols }) {
379
+ // TUI-UX #6: the key column is sized from the usage text (capped), always followed by a two-space gutter. A usage that
380
+ // does not fit its column goes on its own line with the description underneath, so the two never run together.
299
381
  const keyW = Math.min(24, Math.max(...model.filter(m => m.key).map(m => [...m.key].length), 8) + 2);
300
382
  return h(Box, { flexDirection: 'column', marginTop: 1, width: cols }, ...model.map((m, i) => {
301
383
  if (m.kind === 'gap') return h(Text, { key: i }, ' ');
302
384
  if (m.kind === 'head') return m.dim ? h(Text, { key: i, bold: true, color: c('muted') }, m.text) : h(Heading, { key: i, text: m.text });
303
385
  if (m.kind === 'row' || (m.kind === 'dim' && m.key)) {
304
386
  const dim = m.kind === 'dim';
305
- return h(Box, { key: i },
306
- h(Box, { width: keyW + 2, flexShrink: 0 }, h(Text, { color: c('muted') }, ' ', ...(dim ? [m.key] : runs(paintRuns(m.key, 'key').map(r => (r.role === 'muted' || r.role === 'key' ? r : { ...r, role: /^\s*(just type|paste|status line)\s*$/.test(m.key) ? 'label' : 'key' })))))),
307
- h(Box, { flexGrow: 1, flexShrink: 1 }, h(Text, { color: c(dim ? 'muted' : 'text') }, ...(dim ? [m.text] : runs(paintRuns(m.text, 'text'))))));
387
+ const keyRole = (r) => (r.role === 'muted' || r.role === 'key' ? r : { ...r, role: /^\s*(just type|paste|status line)\s*$/.test(m.key) ? 'label' : 'key' });
388
+ const keyNode = (txt) => h(Text, { color: c('muted') }, ...(dim ? [txt] : runs(paintRuns(txt, 'key').map(keyRole))));
389
+ const descNode = (txt) => h(Text, { color: c(dim ? 'muted' : 'text') }, ...(dim ? [txt] : runs(paintRuns(txt, 'text'))));
390
+ // Both columns are wrapped here, by words, so no continuation line starts with a stray space and none collides.
391
+ const descLines = wrapCell(m.text, Math.max(10, cols - keyW - 4));
392
+ if ([...m.key].length + 2 <= keyW) { // usage plus a two-space gutter fits the key column
393
+ return h(Box, { key: i, flexDirection: 'column' }, ...descLines.map((d, k) => h(Box, { key: k },
394
+ h(Box, { width: keyW + 2, flexShrink: 0 }, k === 0 ? h(Text, null, ' ', keyNode(m.key)) : h(Text, null, ' ')),
395
+ h(Box, { flexGrow: 1, flexShrink: 1 }, descNode(d)))));
396
+ }
397
+ const keyLines = wrapCell(m.key, Math.max(10, cols - 8)).map((l, k) => (k ? ' ' : ' ') + l);
398
+ return h(Box, { key: i, flexDirection: 'column' },
399
+ ...keyLines.map((l, k) => h(Text, { key: `k${k}` }, keyNode(l))),
400
+ ...descLines.map((d, k) => h(Box, { key: `d${k}`, paddingLeft: keyW + 2 }, descNode(d))));
308
401
  }
309
402
  return h(Text, { key: i, color: c(m.kind === 'dim' ? 'muted' : 'text') }, ...runs(paintRuns(m.text, m.kind === 'dim' ? 'muted' : 'text')));
310
403
  }));
@@ -337,23 +430,38 @@ export const introAnimates = (isTTY) => motionAllowed(isTTY);
337
430
  /**
338
431
  * Text rows of the Q for a terminal size and progress (0..1 of the plan; 1 = settled). Lab sizing (labSize: the
339
432
  * compact particle Q under 60 cols or 12 rows) and the lab timeline (introPlan: Orbit & Lock in INTRO_MS, then
340
- * the Dragon's Eye when the launch egg fired). Exported so tests can assert on frames.
433
+ * the dragon greeting when `dragon`). Exported so tests can assert on frames.
341
434
  */
342
- export function introArt(cols, rows, progress = 1, color = !mono(), { eye = false } = {}) {
435
+ export function introArt(cols, rows, progress = 1, color = !mono(), { dragon = false, theme = themeNs.isLight() ? 'light' : 'dark' } = {}) {
343
436
  const size = labSize(cols, rows);
344
- const plan = introPlan(size, { eye, color });
345
- const t = progress >= 1 ? Infinity : Math.max(0, progress) * plan.ms;
346
- return { size, w: qDims(size).cols, ms: plan.ms, lines: cellsToAnsi(t === Infinity ? qCells(size, { color }) : plan.at(t)) };
437
+ const plan = introPlan(size, { color });
438
+ const ms = dragon ? INTRO_MS + DRAGON_CLIPS.greeting.dur + 300 : plan.ms;
439
+ const t = progress >= 1 ? Infinity : Math.max(0, progress) * ms;
440
+ if (dragon && t !== Infinity) {
441
+ // Cinematic: the settled Q opens its eyes, looks at you and winks (the dragon greeting, qdragonScenes.js). The
442
+ // dragon is drawn at the Q's OWN size (the compact dragon under 60 cols) on the Q's left edge, and the box keeps
443
+ // the dragon's height and width for the whole sequence (Orbit & Lock frames are padded), so nothing jumps.
444
+ const L = dragonLayout(qDims(size).cols + 6, { size, lm: 0 }), w = Math.max(qDims(size).cols, L.cols);
445
+ if (t >= INTRO_MS) return { size, w, ms, lines: cellsToAnsi(clipCells('greeting', t - INTRO_MS, { cols: L.cols, size, lm: 0, theme, mono: !color, label: false })) };
446
+ const q = cellsToAnsi(plan.at(Math.min(t, plan.ms)));
447
+ return { size, w, ms, lines: [...q, ...Array.from({ length: Math.max(0, L.rows - q.length) }, () => '')] };
448
+ }
449
+ return { size, w: qDims(size).cols, ms, lines: cellsToAnsi(t === Infinity ? qCells(size, { color }) : plan.at(Math.min(t, plan.ms))) };
347
450
  }
348
451
 
349
- export function Intro({ item, cols, progress = 1, rows, eye = false }) {
452
+ export const INTRO_HEAD = "Hi, I'm Quox!";
453
+ export const INTRO_LINES = ['Tell me what you want. Watch me work.', '/help for commands, or just ask me anything.'];
454
+
455
+ export function Intro({ item, cols, progress = 1, rows, dragon = false }) {
350
456
  const { stdout } = useStdout();
351
- const art = introArt(cols, rows ?? termRows(stdout) ?? 40, progress, !mono(), { eye });
352
- const wide = cols >= 60;
353
- const info = h(Box, { flexDirection: 'column', justifyContent: 'center', marginLeft: wide ? 2 : 0, marginTop: wide ? 0 : 1 },
354
- h(Grad, { text: 'Quox' }),
355
- h(Text, { color: c('dim') }, clip(item.text, cols - (wide ? art.w + 4 : 2))),
356
- h(Text, { color: c('dim') }, 'Talk to Quox. /help for everything.'));
457
+ const art = introArt(cols, rows ?? termRows(stdout) ?? 40, progress, !mono(), { dragon });
458
+ // Beside the art only when the longest line fits there; otherwise the text goes under the art, left-aligned and wrapped, never clipped.
459
+ const need = Math.max(...[INTRO_HEAD, ...INTRO_LINES, item.text].map(l => [...l].length));
460
+ const wide = cols >= 60 && cols - 2 - art.w - 2 >= need;
461
+ const info = h(Box, { flexDirection: 'column', justifyContent: 'center', marginLeft: wide ? 2 : 0, marginTop: wide ? 0 : 1, flexShrink: 1, ...(wide ? {} : { width: Math.max(10, cols - 4) }) },
462
+ h(Grad, { text: INTRO_HEAD }),
463
+ ...INTRO_LINES.map((l, k) => h(Text, { key: k, color: c('text'), wrap: 'wrap' }, l)),
464
+ h(Text, { color: c('label'), wrap: 'wrap' }, item.text)); // version/build line: quieter (normal weight, soft brand tint), never grey
357
465
  return h(Box, { flexDirection: wide ? 'row' : 'column', marginTop: 1, marginBottom: 2, marginLeft: 2 }, h(Box, { flexDirection: 'column' }, ...art.lines.map((l, k) => h(Text, { key: k, wrap: 'truncate' }, l))), info);
358
466
  }
359
467
 
@@ -368,10 +476,57 @@ export function revealTimingFor(item) {
368
476
  }
369
477
  }
370
478
 
371
- export function HistoryItem({ item, cols, live = false, fx = null, pulse = null }) {
479
+ // QUOXON-AOCL: ONE line per turn ("▤ AOCL 11/11 ✔ · 9 passed · 2 bypassed · 34 ms"), red naming the layer
480
+ // on a reject; with table:true, the /aocl per-layer table. White on dark, never grey (owner rule).
481
+ const AOCL_TONE = { ok: 'ok', fail: 'fail', warn: 'warn', text: 'input', error: 'fail', accent: 'sky' };
482
+ export function AoclRow({ item, cols }) {
483
+ const icon = h(Text, { color: protoIconColor('aocl') }, '▤');
484
+ const label = h(Text, { color: proto('aocl'), bold: true }, ' AOCL ');
485
+ if (item.table) {
486
+ const rows = aoclTableLines(item.sum);
487
+ return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols }, ...rows.map(([t, tone], i) => h(Text, { key: i, color: c(AOCL_TONE[tone] || 'input') }, clip(i === 0 ? t : ' ' + t, cols - 4))));
488
+ }
489
+ let room = Math.max(10, cols - 10);
490
+ const segs = [];
491
+ for (const sg of aoclLineSegs(item.sum).segs) {
492
+ if (room <= 0) break;
493
+ const t = clip(sg.t, room);
494
+ room -= [...t].length;
495
+ segs.push(h(Text, { key: segs.length, color: c(AOCL_TONE[sg.tone] || 'input') }, t));
496
+ }
497
+ return h(Box, { width: cols }, h(Text, null, ' ', icon, label, ...segs));
498
+ }
499
+
500
+ /**
501
+ * Visual rhythm, decided in ONE place (the history renderer), never per producer. Blank rows BEFORE an item given
502
+ * the item above it (an item never carries a trailing blank, so two blanks in a row cannot happen):
503
+ * - a blank row between EVERY distinct block (user message, tool group, answer, notice group, AOCL footer, tip
504
+ * frame, bang block); tight only inside a block: a run of tool rows, a run of notices, the AOCL + Thought
505
+ * footer lines. A blank follows the prompt, separates the answer from the footer, and follows the footer.
506
+ * - items that draw their own leading blank (intro, welcome, help, object cards) add none here
507
+ * - under 20 terminal rows nothing is padded: only a new turn keeps its blank
508
+ */
509
+ const SELF_SPACED = new Set(['intro', 'welcome', 'help', 'object']);
510
+ const GROUP = { tool: 'tools', trace: 'tools', note: 'notice', error: 'notice', aocl: 'footer', summary: 'footer' };
511
+ const FOOTER = new Set(['aocl', 'summary']);
512
+ export function historyGap(prev, item, rows = null) {
513
+ if (!item || SELF_SPACED.has(item.kind)) return 0;
514
+ if (item.kind === 'user') return 1;
515
+ if (!prev) return item.kind === 'text' ? 1 : 0;
516
+ if (rows != null && rows < 20) return 0;
517
+ if (FOOTER.has(item.kind) && FOOTER.has(prev.kind)) return 0; // the AOCL line and the Thought line are one footer block
518
+ const g = GROUP[item.kind];
519
+ if (g && g === GROUP[prev.kind]) return 0; // a run of tool rows, or of notices, is one block
520
+ return 1; // every other pair of distinct blocks (each tip frame is its own block)
521
+ }
522
+
523
+ export function HistoryItem({ item, cols, live = false, fx = null, pulse = null, ignite = 0, gap }) {
524
+ if (gap !== undefined && gap > 0 && !['user', 'text'].includes(item.kind)) {
525
+ return h(Box, { marginTop: gap, flexDirection: 'column' }, h(HistoryItem, { item, cols, live, fx, pulse, ignite, gap: 0 }));
526
+ }
372
527
  switch (item.kind) {
373
528
  case 'intro': return h(Intro, { item, cols });
374
- case 'user': return h(Box, { marginTop: 1, width: cols }, // gutter box + wrapping text box = hanging indent
529
+ case 'user': return h(Box, { marginTop: gap ?? 1, width: cols }, // gutter box + wrapping text box = hanging indent
375
530
  h(Box, { width: 2, flexShrink: 0 }, h(Text, { color: c('sky'), bold: true }, item.queued ? '» ' : '› ')),
376
531
  h(Box, { flexGrow: 1, flexShrink: 1 }, h(WText, { color: c('input') }, item.text)));
377
532
  case 'welcome': return h(WelcomeView, { version: item.version, cols });
@@ -384,11 +539,17 @@ export function HistoryItem({ item, cols, live = false, fx = null, pulse = null
384
539
  ? h(Text, { key: i }, ...fxNodes(segs(l), { e: fx.e - i * 0.05, timing: fx.timing }, 11 + i))
385
540
  : h(Text, { key: i, color: c('dim') }, ...runs(paintRuns(l, 'muted'))))));
386
541
  }
387
- case 'text': return h(Box, { marginTop: 1, paddingLeft: 2, flexDirection: 'column' }, h(Markdown, { text: item.text, cols: cols - 2, live }));
388
- case 'tool': return h(ToolRow, { b: item, cols, fx, pulse });
542
+ case 'text': return h(Box, { marginTop: gap ?? 1, paddingLeft: 2, flexDirection: 'column' }, h(Markdown, { text: item.text, cols: cols - 2, live }));
543
+ case 'tool': return h(ToolRow, { b: item, cols, fx, pulse, ignite });
389
544
  case 'trace': return h(TraceRow, { b: item, cols, fx, pulse });
390
- case 'error': return h(Box, { paddingLeft: 2 }, fx ? h(Text, null, ...fxNodes([{ t: `✖ ${clip(item.text, cols - 6)}`, color: 'fail' }], fx, 13)) : h(Text, { color: c('fail') }, `✖ ${clip(item.text, cols - 6)}`));
545
+ case 'aocl': return h(AoclRow, { item, cols });
546
+ case 'error': return h(ErrorView, { item, cols, fx });
391
547
  case 'note': return h(NoteView, { item, cols, fx });
548
+ case 'slotmsg': return h(SlotMsgView, { item, cols });
549
+ case 'tip': return h(TipView, { item, cols });
550
+ case 'whatsnew': return h(WhatsNewView, { item, cols });
551
+ case 'bcard': return h(BroadcastCardView, { item, cols });
552
+ case 'bang': return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols }, ...String(item.text).split('\n').map((l, i) => h(Text, { key: i, color: c('text') }, l || ' ')));
392
553
  default: return null;
393
554
  }
394
555
  }
@@ -398,26 +559,206 @@ const SEP = ' · ';
398
559
  /** Lines of a note at `width`: one line when it fits; a ' · ' list breaks only at separators. */
399
560
  export function noteLines(text, width) {
400
561
  const t = String(text ?? '');
401
- if (!t.includes(SEP) || t.includes('\n') || wrapRows(t, width) === 1) return [t];
562
+ if (!t.includes(SEP) || t.includes('\n') || wrapRows(stripMarks(t), width) === 1) return [t];
402
563
  const lines = [];
403
564
  let cur = '';
404
565
  for (const seg of t.split(SEP)) {
405
566
  const next = cur ? cur + SEP + seg : seg;
406
- if (!cur || graphemes(next).length <= width) cur = next;
567
+ if (!cur || graphemes(stripMarks(next)).length <= width) cur = next;
407
568
  else { lines.push(cur); cur = seg; }
408
569
  }
409
570
  lines.push(cur);
410
571
  return lines;
411
572
  }
412
- export const noteRows = (text, cols) => noteLines(text, cols - 2).reduce((n, l) => n + wrapRows(l, cols - 2), 0);
573
+ /** A note line that is one bare URL longer than the row: never hard-wrapped (a break inside a token breaks copy and click). */
574
+ const longUrl = (l, width) => { const t = stripMarks(l); return /^https?:\/\/\S+$/.test(t) && graphemes(t).length > width; };
575
+ export const noteRows = (text, cols, tone) => noteLines(toneText(text, tone), cols - 2).reduce((n, l) => n + (longUrl(l, cols - 2) ? 1 : wrapRows(stripMarks(l), cols - 2)), 0);
576
+
577
+ /**
578
+ * Z2H-7B3: a failure message can be several lines (what ran, what did not, the advice). Every line shows,
579
+ * wrapped at the row width, never clipped to one: the first line leads with a red ✖, the rest indent under it.
580
+ */
581
+ export const errorRows = (text, cols) => String(text ?? '').split('\n').reduce((n, l) => n + Math.max(1, wrapRows(stripMarks(l), Math.max(10, cols - 4))), 0);
582
+ function ErrorView({ item, cols, fx }) {
583
+ const raw = String(item.text ?? '');
584
+ const lines = raw.split('\n');
585
+ const paint = (l) => paintRuns(l, 'prose').map(r => ({ t: r.text, color: r.role || 'prose' }));
586
+ if (lines.length === 1 && wrapRows(stripMarks(raw), Math.max(10, cols - 4)) === 1) {
587
+ const parts = [{ t: '✖ ', color: 'error' }, ...paint(raw)];
588
+ return h(Box, { paddingLeft: 2 }, fx ? h(Text, null, ...fxNodes(parts, fx, 13)) : h(Text, null, ...parts.map((p, i) => h(Text, { key: i, color: c(p.color) }, p.t))));
589
+ }
590
+ return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols },
591
+ ...lines.map((l, i) => h(Box, { key: i },
592
+ h(Box, { width: 2, flexShrink: 0 }, h(Text, { color: c('error') }, i === 0 ? '✖ ' : ' ')),
593
+ h(Box, { flexGrow: 1, flexShrink: 1 }, h(WText, { color: c('prose') }, ...runs(paintRuns(l || ' ', 'prose')))))));
594
+ }
595
+
596
+ /**
597
+ * /aside: a read-only side answer, drawn apart from the conversation: a violet ┃ bar down the left, the question
598
+ * as its header, the answer as markdown, a quiet read-only footer. Rows: margin + header + body + footer (asideRows).
599
+ */
600
+ function AsideView({ item, cols }) {
601
+ const { head, body, foot } = parseAsideNote(item.text);
602
+ const w = Math.max(10, cols - 5);
603
+ return h(Box, { marginLeft: 2, marginTop: 1, flexDirection: 'column', width: cols - 2, borderStyle: 'bold', borderTop: false, borderRight: false, borderBottom: false, borderLeftColor: c('violet'), paddingLeft: 1 },
604
+ h(Text, { color: c('violet'), bold: true }, clip(head, w)),
605
+ h(Markdown, { text: body.join('\n') || '(no answer)', cols: w }),
606
+ ...(foot ? [h(Text, { key: 'f', color: c('quiet') }, clip(foot, w))] : []));
607
+ }
608
+ export const asideRows = (text, cols) => { const { body, foot } = parseAsideNote(text); return 2 + Math.max(1, markdownRows(body.join('\n') || '(no answer)', Math.max(10, cols - 5))) + (foot ? 1 : 0); };
413
609
 
414
610
  function NoteView({ item, cols, fx = null }) {
415
- const tone = item.tone === 'warn' ? 'warn' : item.tone === 'ok' ? 'ok' : item.tone === 'accent' ? 'sky' : 'dim';
416
- const color = c(tone);
611
+ if (item.tone === 'ask') return h(AskCard, { text: item.text, cols }); // QUOXON-ASK: every ask is the approval card
612
+ if (item.tone === 'aside') return h(AsideView, { item, cols });
613
+ // RECO-HIGHLIGHT: the recommended option of a decision card: bold, accent colour, never grey.
614
+ if (item.tone === 'reco') return h(Box, { paddingLeft: 2, width: cols }, h(WText, { color: c('sky'), bold: true }, stripMarks(item.text)));
615
+ // Tone shows as a glyph (⚠ ✖ ✔) in front; the sentence stays prose so commands and values keep their own colours.
616
+ const color = c('prose');
617
+ const text = toneText(item.text, item.tone);
417
618
  // While it reveals, a line that fits decodes in; a line that wraps keeps plain wrapping (never mis-measured).
418
- return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols }, ...noteLines(item.text, cols - 2).map((l, i) => (fx && wrapRows(l, cols - 2) === 1
419
- ? h(Text, { key: i }, ...fxNodes(paintLine(l, item.tone).map(r => (typeof r === 'string' ? { t: r, color: tone } : { t: r.text, color: r.role || tone })), { e: fx.e - i * 0.05, timing: fx.timing }, 17 + i))
420
- : h(WText, { key: i, color }, ...runs(paintLine(l, item.tone))))));
619
+ return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols }, ...noteLines(text, cols - 2).map((l, i) => longUrl(l, cols - 2)
620
+ ? h(Box, { key: i, width: graphemes(stripMarks(l)).length, flexShrink: 0 }, h(Text, { color: c('link'), wrap: 'truncate-end' }, stripMarks(l)))
621
+ : (fx && wrapRows(stripMarks(l), cols - 2) === 1
622
+ ? h(Text, { key: i }, ...fxNodes(paintLine(l, item.tone).map(r => (typeof r === 'string' ? { t: r, color: 'prose' } : { t: r.text, color: r.role || 'prose' })), { e: fx.e - i * 0.05, timing: fx.timing }, 17 + i))
623
+ : h(WText, { key: i, color, bold: item.tone === 'ask' }, ...runs(paintLine(l, item.tone))))));
624
+ }
625
+
626
+ /**
627
+ * QUOXON-MESH: a slot chat line. Incoming "◆ quox2 (Adam) 04:56 hello" (violet: another session speaking),
628
+ * outgoing "→ quox2 04:56 hello ✔" (sky: you). A file shows its name, three lines and a /slot log pointer;
629
+ * /slot log prints the whole file (`full`).
630
+ */
631
+ function SlotMsgView({ item, cols }) {
632
+ const l = item.line || {};
633
+ if (l.roomLine) { // QUOXON-ROOMS: `#group-chat QUOXON: text`, a stable colour per sender
634
+ return h(Box, { paddingLeft: 2, width: cols },
635
+ h(WText, null,
636
+ h(Text, { color: c('label') }, `#${l.room} `),
637
+ h(Text, { color: c(l.color || 'sky'), bold: true }, `${l.who}: `),
638
+ h(Text, { color: c('text') }, String(l.text ?? ''))));
639
+ }
640
+ const role = l.out ? 'sky' : l.urgent ? 'error' : 'violet';
641
+ const body = String(l.text ?? '');
642
+ // SLOT-RUN A (owner 2026-10-16 "messy needs a format"): one tidy header line (sender, no-reply marker, time);
643
+ // a short plain line stays on it, anything longer or with markdown renders below as formatted rows.
644
+ const time = l.time ? ` ${l.time}` : '';
645
+ const headLen = graphemes(`${l.glyph || '◆'} ${l.who || ''}${!l.out && l.noReply ? ' (no reply address)' : ''}${time} `).length;
646
+ const run = !l.out && l.run ? l.run : null;
647
+ const inline = !run && (Boolean(l.file) || l.out || inlineable(body, cols - 2 - headLen - 2));
648
+ const segRow = (segs, key) => h(Box, { key, paddingLeft: 4, width: cols }, segs.length ? h(Text, null, ...segs.map((sg, i) => h(Text, { key: i, color: c(sg.role || 'text'), bold: sg.bold || undefined }, sg.t))) : h(Text, null, ' '));
649
+ const out = [h(Box, { key: 'h', paddingLeft: 2, width: cols },
650
+ h(WText, null,
651
+ h(Text, { color: c(role), bold: true }, `${l.glyph || '◆'} ${l.who || ''}`),
652
+ !l.out && l.noReply ? h(Text, { color: c('label') }, ' (no reply address)') : null,
653
+ h(Text, { color: c('label') }, `${time} `),
654
+ inline ? h(Text, { color: c(l.urgent ? 'error' : 'text') }, body) : null,
655
+ l.out && l.delivered ? h(Text, { color: c('ok') }, ' ✔') : null))];
656
+ if (!inline && !l.file && !run && body.trim()) formatSlotBody(body, cols - 6, { role: l.urgent ? 'error' : 'text' }).forEach((segs, i) => out.push(segRow(segs, `b${i}`)));
657
+ // SLOT-RUN B: a run request shows the shared ask, the FULL command (never clipped), and its answer line.
658
+ // ASK-SETTLE: an answered or expired run request is one line (what was asked and the answer), never a live card.
659
+ if (run && run.settled) out.push(h(Box, { key: 'run', paddingLeft: 4, width: cols }, h(WText, { color: c('prose') }, ...runs(paintLine(toneText(run.settled, run.settledTone), run.settledTone)))));
660
+ else if (run) out.push(h(Box, { key: 'run' }, h(NeedsYouCard, { // QUOXON-ASK: a run request is the approval card too
661
+ cols, title: `⚠ ${run.who} asks you to run this here`, rows: run.why ? [['why', run.why]] : [], block: codeRows([run.cmd], cols - 4),
662
+ notes: run.runnable ? [] : [`✖ Not offered: ${run.refuse}. Copy it yourself only if you trust it.`],
663
+ footer: run.danger ? `▶ ${run.danger}. Type run to run it, n to skip? run · n no · c chat` : '▶ Run it? y yes · n no · c chat',
664
+ arming: run.runnable ? null : h(Text, null, '') })));
665
+ if (l.file && !l.out) {
666
+ const lines = l.full ? String(l.file.body).split('\n') : l.file.preview;
667
+ lines.forEach((t, i) => out.push(h(Box, { key: `f${i}`, paddingLeft: 6, width: cols }, h(Text, { color: c('text') }, clip(t || ' ', cols - 8)))));
668
+ if (!l.full && l.file.lines > lines.length) out.push(h(Box, { key: 'more', paddingLeft: 6 }, h(Text, { color: c('prose') }, `… ${l.file.lines - lines.length} more line${l.file.lines - lines.length === 1 ? '' : 's'}: `), h(Text, { color: c('command') }, '/slot log')));
669
+ else if (!l.full) out.push(h(Box, { key: 'more', paddingLeft: 6 }, h(Text, { color: c('prose') }, 'full file: '), h(Text, { color: c('command') }, '/slot log')));
670
+ }
671
+ return h(Box, { flexDirection: 'column' }, ...out);
672
+ }
673
+
674
+ export const TIP_HINT = `${cmd('/tip')} for another · ${cmd('/tip-settings off')} to stop`;
675
+ /** Word-wrap plain text to `width` columns (a word longer than the width is hard-split). */
676
+ function wrapPlain(text, width) {
677
+ const out = []; let line = '';
678
+ for (const w0 of String(text ?? '').split(/\s+/).filter(Boolean)) {
679
+ let w = w0;
680
+ while ([...w].length > width) { if (line) { out.push(line); line = ''; } out.push([...w].slice(0, width).join('')); w = [...w].slice(width).join(''); }
681
+ if (line && [...line].length + 1 + [...w].length > width) { out.push(line); line = w; } else line = line ? `${line} ${w}` : w;
682
+ }
683
+ if (line) out.push(line);
684
+ return out.length ? out : [''];
685
+ }
686
+
687
+ /**
688
+ * A tip in a rounded brand-accent frame: width min(cols - 4, 76), 1-col padding, wrapped text, "Try:" on its own
689
+ * line in the command colour, the /tip hint as the last line inside. Under 40 cols or NO_COLOR: a plain "Tip:" block.
690
+ */
691
+ function TipView({ item, cols }) {
692
+ if (mono() || cols < 40) {
693
+ const w = Math.max(10, cols - 2);
694
+ const lines = [...wrapPlain(`Tip: ${item.text}`, w), `Try: ${item.cmd}`, ...wrapPlain(stripMarks(TIP_HINT), w)];
695
+ return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols }, ...lines.map((l, i) => h(Text, { key: i }, l)));
696
+ }
697
+ const W = Math.min(cols - 4, 76), inner = W - 4, edge = { color: c('brand') };
698
+ const row = (key, kids, len) => h(Box, { key }, h(Text, edge, '│ '), h(Text, null, ...kids), h(Text, null, ' '.repeat(Math.max(0, inner - len))), h(Text, edge, ' │'));
699
+ const body = wrapPlain(item.text, inner).map((l, i) => row(`t${i}`, [h(Text, { key: 0, color: c('prose') }, l)], [...l].length));
700
+ const cmdText = clip(item.cmd, inner - 5);
701
+ const tryRow = row('try', [h(Text, { key: 0, color: c('prose'), bold: true }, 'Try: '), h(Text, { key: 1, color: c('command') }, cmdText)], 5 + [...cmdText].length);
702
+ const hintRow = row('hint', runs(paintRuns(TIP_HINT, 'quiet')), [...stripMarks(TIP_HINT)].length);
703
+ return h(Box, { paddingLeft: 2, flexDirection: 'column' },
704
+ h(Text, edge, '╭─ ', h(Text, { bold: true }, 'Tip'), ' ', '─'.repeat(W - 8), '╮'),
705
+ ...body, tryRow, hintRow,
706
+ h(Text, edge, '╰', '─'.repeat(W - 2), '╯'));
707
+ }
708
+
709
+ /**
710
+ * The startup "What's new since you last ran Quox" box: same frame as a tip, one title row (+ a "Try:" row) per entry,
711
+ * then ALWAYS a "Try: /whatsnew" footer ("+N more. Try: /whatsnew" when more are unseen), so the way to the full list
712
+ * never depends on which entries happen to be newest. The compact head variant (item.head, the new-commands line)
713
+ * already ends "/whatsnew for more" and gets no footer. Under 40 cols or NO_COLOR: plain lines, no frame.
714
+ */
715
+ function WhatsNewView({ item, cols }) {
716
+ const HEAD = item.head || "What's new since you last ran Quox";
717
+ const lead = item.more > 0 ? `+${item.more} more. ` : '';
718
+ const more = item.head ? '' : `${lead}Try: /whatsnew`;
719
+ if (mono() || cols < 40) {
720
+ const w = Math.max(10, cols - 2);
721
+ const lines = [HEAD, ...item.items.flatMap(it => [`- ${it.title}`, ...(it.cmd ? [` Try: ${it.cmd}`] : [])]), ...(more ? [more] : [])].flatMap(l => wrapPlain(l, w));
722
+ return h(Box, { paddingLeft: 2, flexDirection: 'column', width: cols }, ...lines.map((l, i) => h(Text, { key: i }, l)));
723
+ }
724
+ const W = Math.min(cols - 4, 76), inner = W - 4, edge = { color: c('brand') };
725
+ const row = (key, kids, len) => h(Box, { key }, h(Text, edge, '│ '), h(Text, null, ...kids), h(Text, null, ' '.repeat(Math.max(0, inner - len))), h(Text, edge, ' │'));
726
+ const rows = item.items.flatMap((it, i) => {
727
+ const t = clip(it.title, inner - 2);
728
+ const out = [row(`t${i}`, [h(Text, { key: 0, color: c('prose'), bold: true }, `• ${t}`)], 2 + [...t].length)];
729
+ if (it.cmd) { const k = clip(it.cmd, inner - 7); out.push(row(`c${i}`, [h(Text, { key: 0, color: c('prose') }, ' Try: '), h(Text, { key: 1, color: c('command') }, k)], 7 + [...k].length)); }
730
+ return out;
731
+ });
732
+ if (more) rows.push(row('more', [h(Text, { key: 0, color: c('prose') }, lead), h(Text, { key: 1, color: c('prose'), bold: true }, 'Try: '), h(Text, { key: 2, color: c('command') }, '/whatsnew')], [...more].length));
733
+ if (item.pad) { rows.unshift(row('p0', [], 0)); rows.push(row('p1', [], 0)); }
734
+ return h(Box, { paddingLeft: 2, flexDirection: 'column' },
735
+ h(Text, edge, '╭─ ', h(Text, { bold: true }, HEAD), ' ', '─'.repeat(Math.max(1, W - 5 - HEAD.length)), '╮'),
736
+ ...rows,
737
+ h(Text, edge, '╰', '─'.repeat(W - 2), '╯'));
738
+ }
739
+
740
+ /**
741
+ * QUOXON-BROADCAST: the sender's delivery card. Rounded frame in the card's tone (green all in, gold pending, red a
742
+ * real failure), one row per fact, the id and the status hint in the bottom edge. Widths are measured in cells so the
743
+ * emoji does not skew the edge. Under 50 cols: the model's one-line form.
744
+ */
745
+ function BroadcastCardView({ item, cols }) {
746
+ const m = item.card;
747
+ if (cols < 50) return h(Box, { paddingLeft: 1, width: cols }, h(WText, { color: c('prose') }, m.narrow));
748
+ const W = Math.min(cols - 4, 76), inner = W - 4, edge = { color: c(m.tone) };
749
+ const cut = (t, room) => { let o = ''; for (const ch of [...t]) { if (stringWidth(o + ch) > room - 1) return o + '…'; o += ch; } return o; };
750
+ const fit = (t, room) => (stringWidth(t) > room ? cut(t, room) : t);
751
+ const rows = m.rows.map((segs, i) => {
752
+ let left = inner;
753
+ const kids = segs.map(([t, role], k) => { const x = fit(t, left); left -= stringWidth(x); return h(Text, { key: k, color: c(role) }, x); });
754
+ return h(Box, { key: i }, h(Text, edge, '│ '), h(Text, null, ...kids), h(Text, null, ' '.repeat(Math.max(0, left))), h(Text, edge, ' │'));
755
+ });
756
+ const title = fit(m.title, W - 5);
757
+ const foot = fit(m.foot, W - 5);
758
+ return h(Box, { paddingLeft: 2, flexDirection: 'column' },
759
+ h(Text, edge, '╭─ ', h(Text, { bold: true, color: c('prose') }, title), ' ', '─'.repeat(Math.max(1, W - 5 - stringWidth(title))), '╮'),
760
+ ...rows,
761
+ h(Text, edge, '╰─ ', h(Text, { color: c('quiet') }, foot), ' ', '─'.repeat(Math.max(1, W - 5 - stringWidth(foot))), '╯'));
421
762
  }
422
763
 
423
764
  /** Rows a live block takes as HistoryItem renders it (sizes the live region; keep in step with HistoryItem). */
@@ -425,8 +766,10 @@ export function liveRows(blocks, cols) {
425
766
  return blocks.reduce((n, b) => {
426
767
  switch (b.kind) {
427
768
  case 'text': return n + 1 + markdownRows(b.text, cols - 2, true);
428
- case 'note': return n + noteRows(b.text, cols);
769
+ case 'note': return n + (b.tone === 'ask' ? askCardRows(b.text, cols) : b.tone === 'aside' ? asideRows(b.text, cols) : noteRows(b.text, cols, b.tone));
429
770
  case 'summary': return n + noteLines(b.text, cols - 4).length;
771
+ case 'error': return n + errorRows(b.text, cols);
772
+ case 'slotmsg': return n + (b.line?.run && !b.line.run.settled ? 9 + Math.ceil(String(b.line.run.cmd || '').length / Math.max(10, cols - 8)) : 1); // ASK-SETTLE: an armed run card is held live
430
773
  default: return n + 1;
431
774
  }
432
775
  }, 0);
@@ -442,11 +785,34 @@ export const Grad = ({ text }) => {
442
785
  }));
443
786
  };
444
787
 
788
+ /**
789
+ * Pure: the model as the composer's bottom-rule label (`──── anthropic claude-sonnet-5-5 ─`). Degrades to fit,
790
+ * never wraps: full, then a shortened provider (`anth claude-sonnet-5-5`), then the model alone, then the
791
+ * model clipped. Leaves at least four rule cells on the left. Below 30 cols, or no model: ''.
792
+ */
793
+ export function modelRuleLabel(cols, model) {
794
+ const full = String(model || '').trim();
795
+ if (!full || cols < 30) return '';
796
+ const room = cols - 7; // ' label ' + one trailing dash + four leading dashes
797
+ const fits = (t) => cellWidth(t) <= room; // cells under the ambiguous-width policy (cells.js)
798
+ if (fits(full)) return full;
799
+ const segs = full.split(' · ');
800
+ const tailSeg = segs[segs.length - 1];
801
+ const words = (segs.length > 1 ? segs[0] : full).split(' ');
802
+ const name = segs.length > 1 ? tailSeg : words.slice(1).join(' ') || words[0];
803
+ const provider = segs.length > 1 ? segs[0] : words.length > 1 ? words[0] : '';
804
+ if (provider) { const short = `${provider.slice(0, 4)} ${name}`; if (fits(short)) return short; }
805
+ if (fits(name)) return name;
806
+ return clip(name, room);
807
+ }
808
+
445
809
  /** Pure: the rule split around a right-aligned session name: `───── name ─`. Below 30 cols, or no name: plain. */
446
810
  export function ruleParts(cols, name) {
447
- if (!name || cols < 30) return { left: '─'.repeat(cols), label: '', right: '' };
811
+ // TUI-FOOTER: '─' is East Asian Ambiguous; where the terminal draws it two cells wide, half as many fill the row
812
+ const d = cellWidth('─');
813
+ if (!name || cols < 30) return { left: '─'.repeat(Math.floor(cols / d)), label: '', right: '' };
448
814
  const label = ` ${clip(name, cols - 8)} `;
449
- return { left: '─'.repeat(Math.max(1, cols - [...label].length - 1)), label, right: '─' };
815
+ return { left: '─'.repeat(Math.max(1, Math.floor((cols - cellWidth(label) - d) / d))), label, right: '─' };
450
816
  }
451
817
 
452
818
  /**
@@ -470,26 +836,33 @@ function ringString(str, rgbs, from = 0) {
470
836
  * A composer rule. `ring` (motion only, never under NO_COLOR) = { state, top }: the rule becomes half of the
471
837
  * light ring (motion/ring.js); the session name stays bright on top of it.
472
838
  */
473
- export const Rule = ({ cols, color, name, ring = null }) => {
839
+ export const Rule = ({ cols, color, name, ring = null, labelColor = null }) => {
474
840
  const p = ruleParts(cols, name);
841
+ // `labelColor` (the model on the bottom rule): its own colour, not bold, so it reads as context, not a title
842
+ const lab = labelColor ? { color: labelColor } : null;
475
843
  if (ring && ring.state && ring.state.k > 0 && !mono()) {
476
844
  const rgbs = ruleColors(cols, ring.top, ring.state, COLORS[color] || color);
477
845
  if (!p.label) return h(Text, null, ringString(p.left, rgbs));
478
846
  const ls = [...p.left].length, lb = [...p.label].length;
479
- return h(Text, null, ringString(p.left, rgbs), h(Text, { color: c('violet'), bold: true }, p.label), ringString(p.right, rgbs, ls + lb));
847
+ return h(Text, null, ringString(p.left, rgbs), h(Text, lab || { color: c('violet'), bold: true }, p.label), ringString(p.right, rgbs, ls + lb));
480
848
  }
481
849
  if (!p.label) return h(Text, { color: c(color) }, p.left);
482
- return h(Text, null, h(Text, { color: c(color) }, p.left), h(Text, { color: c('label'), bold: true }, p.label), h(Text, { color: c(color) }, p.right));
850
+ return h(Text, null, h(Text, { color: c(color) }, p.left), h(Text, lab || { color: c('label'), bold: true }, p.label), h(Text, { color: c(color) }, p.right));
483
851
  };
484
852
 
485
853
  /** Split the buffer into visible lines with an inverse cursor cell. */
486
854
  export function composerLines(buf, maxLines = 8) {
487
855
  const lines = buf.text.split('\n');
488
856
  const { line: cl, col } = lineCol(buf.text, buf.cursor);
489
- let from = 0;
490
- if (lines.length > maxLines) from = Math.min(Math.max(0, cl - Math.floor(maxLines / 2)), lines.length - maxLines);
857
+ const from = composerFrom(buf, maxLines);
858
+ const sel = selection(buf);
859
+ const starts = []; { let o = 0; for (const l of lines) { starts.push(o); o += l.length + 1; } }
491
860
  return lines.slice(from, from + maxLines).map((text, i) => {
492
861
  const idx = from + i;
862
+ if (sel) { // QUOXON-MOUSE: the selected span is drawn inverse; no cursor cell while a selection shows
863
+ const a = Math.max(0, Math.min(text.length, sel.from - starts[idx])); const b = Math.max(0, Math.min(text.length, sel.to - starts[idx]));
864
+ return a < b ? { key: idx, pre: text.slice(0, a), sel: text.slice(a, b), post: text.slice(b) } : { text, cursor: null, key: idx };
865
+ }
493
866
  if (idx !== cl) return { text, cursor: null, key: idx };
494
867
  const gs = graphemes(text);
495
868
  return { key: idx, before: gs.slice(0, col).map(g => g.text).join(''), at: gs[col] ? gs[col].text : ' ', after: gs.slice(col + 1).map(g => g.text).join('') };
@@ -503,24 +876,44 @@ export function composerLines(buf, maxLines = 8) {
503
876
  export function RingComposer({ ring: ringIn, ...props }) {
504
877
  const now = useFrame();
505
878
  const ring = ringIn ? (ringIn.ref.current = ringStep(ringIn.ref.current, { active: ringIn.active, mode: ringIn.mode, now })) : null;
506
- return h(Composer, { ...props, ring });
879
+ return h(Composer, { ...props, ring, now });
507
880
  }
508
881
 
509
882
  /** `ring` = a ring state from motion/ring.js, or null for the static rules. Hook-free (pure render). */
510
- export function Composer({ buf, cols, mode, busy, placeholder, name, ring = null }) {
883
+ // TUI-DIVIDER: `divider` = { d, slow } (the AOCL strip state and the per-turn slow-redraw ref), drawn only on the
884
+ // ring path (motion + colour), so NO_COLOR, reduced motion and the lite TUI keep the plain rule.
885
+ /** Does the block directly above the composer close with a rule? Then no spacer and no second rule (one rule only). */
886
+ export function endsInRule({ card = null, asks = [], background = 0, pending = [], steering = [], countdown = false }) {
887
+ if (background > 0 || pending.length || steering.length || countdown) return false;
888
+ if (asks.length) return !askCardModel(asks[asks.length - 1].text).plain && askCardRows(asks[asks.length - 1].text, 80) > 0;
889
+ return Boolean(card);
890
+ }
891
+
892
+ export function Composer({ buf, cols, mode, busy, placeholder, name, model = null, ring = null, divider = null, now = 0, topRule = true }) {
511
893
  const empty = buf.text === '';
512
894
  const lines = composerLines(buf);
513
895
  const body = empty
514
896
  ? [h(Box, { key: 'p' }, h(Text, { color: c('sky'), bold: true }, '› '), h(Text, { inverse: true }, ' '), h(Text, { color: c('placeholder') }, clip(placeholder, cols - 5)))]
515
897
  : lines.map((l, i) => h(Box, { key: l.key },
516
- h(Text, { color: c('sky'), bold: true }, i === 0 ? '› ' : ' '),
517
- l.at === undefined
898
+ h(Box, { flexShrink: 0 }, h(Text, { color: c('sky'), bold: true }, i === 0 ? '› ' : ' ')), // COMPOSER-EDIT: never squeezed, so wrapped rows are cols - 2 wide
899
+ l.sel !== undefined
900
+ ? h(Text, { color: c('input') }, l.pre, h(Text, { inverse: true }, l.sel), l.post)
901
+ : l.at === undefined
518
902
  ? h(Text, { color: c('input') }, l.text || ' ')
519
903
  : h(Text, { color: c('input') }, l.before, h(Text, { inverse: true }, l.at), l.after)));
520
904
  return h(Box, { flexDirection: 'column', width: cols },
521
- h(Rule, { cols, color: MODE_COLOR[mode] || 'sky', name, ring: ring ? { state: ring, top: true } : null }),
905
+ topRule ? h(Rule, { cols, color: MODE_COLOR[mode] || 'sky', name, ring: ring ? { state: ring, top: true } : null }) : null,
522
906
  ...body,
523
- h(Rule, { cols, color: 'dim', ring: ring ? { state: ring, top: false } : null }));
907
+ (ring && divider && dividerRuleEl({ cols, label: modelRuleLabel(cols, model), divider: divider.d, now, ruleColor: c('dim'), labelColor: modelColor(model), mono: mono(), reduced: cellWidth('─') !== 1, slow: divider.slow }))
908
+ || h(Rule, { cols, color: 'dim', name: modelRuleLabel(cols, model), labelColor: modelColor(model), ring: ring ? { state: ring, top: false } : null }));
909
+ }
910
+
911
+ /** The model label's colour: its provider's brand colour, else the label role (never a grey). */
912
+ function modelColor(model) {
913
+ if (mono()) return undefined;
914
+ const [prov, ...rest] = String(model || '').split(' ');
915
+ const pc = providerOf(prov, rest.join(' ')) ? providerColor(prov, rest.join(' ')) : null;
916
+ return pc || c('label');
524
917
  }
525
918
 
526
919
  export function Pending({ pending, steering, cols }) {
@@ -541,81 +934,206 @@ function DrawRule({ cols, color, e, dur = 0.25 }) {
541
934
 
542
935
  export const ARM_BAR = 6;
543
936
  /** `motionE` = seconds since the card appeared, when motion is on: the rule draws in, the title decodes, the arming bar fills. */
544
- export function ApprovalCard({ card, org, cols, armed, draftHint = null, motionE = null }) {
545
- const rows = card.undescribable ? [['tool', card.tool], ['org', org]] : [
546
- ['tool', card.tool], ['target', card.target], ['scope', card.scope], ['risk', card.risk], ['org', org]
937
+ /** Approvals raised by ANOTHER session: a notice line only. It never takes focus or keys; answer through /approvals. */
938
+ export function WaitingNotice({ items = [], cols }) {
939
+ if (!items.length) return null;
940
+ const from = [...new Set(items.map(i => i.origin || 'another session'))].slice(0, 2).join(', ');
941
+ const n = items.length;
942
+ return h(Text, { color: c('ask'), bold: true }, ' ' + clip(`▶ ${n} approval${n === 1 ? '' : 's'} waiting from ${from}${items.some(i => i.privileged) ? ' (privileged)' : ''}: /approvals`, cols - 2));
943
+ }
944
+
945
+ /**
946
+ * QUOXON-ASK (owner 2026-10-16 "every ask should look like an approval card"): THE card frame for anything that needs
947
+ * the human. Approval cards and every other ask render through this one function, so they cannot drift apart:
948
+ * a rule, a bold title saying who is asking, label/value rows (what a yes does, in full, and why), then the
949
+ * "▶ question? keys" footer in the ask colour, and a closing rule. `arming` replaces the footer until keys are live.
950
+ */
951
+ export function NeedsYouCard({ cols, title, rows = [], block = [], notes = [], footer, arming = null, motionE = null }) {
952
+ const e = motionE;
953
+ return h(Box, { flexDirection: 'column', width: cols, marginTop: 1 },
954
+ e == null ? h(Rule, { cols, color: 'warn' }) : h(DrawRule, { cols, color: 'warn', e }),
955
+ e == null ? h(Text, { color: c('warn'), bold: true, wrap: 'wrap' }, title) : h(Text, null, ...fxNodes([{ t: title, color: 'warn', bold: true }], { e: e - 0.1, timing: TIMING.title }, 23)),
956
+ // APPROVAL-WHAT: wrap at word boundaries under the label instead of cutting the action or target off
957
+ ...rows.flatMap(([k, v]) => wrapPlain(String(v), Math.max(10, cols - 10)).slice(0, 8).map((line, i) => h(Text, { key: `${k}${i}`, color: c('text') }, ' ', h(Text, { color: c('label') }, (i ? '' : k).padEnd(7)), h(Text, { color: c(k === 'risk' ? 'warn' : 'value') }, line)))),
958
+ // block: pre-shaped segment rows shown verbatim (a command to run: never word-wrapped, never clipped)
959
+ ...block.map((segs, i) => h(Box, { key: `b${i}`, paddingLeft: 2, width: cols }, h(Text, null, ...segs.map((sg, j) => h(Text, { key: j, color: c(sg.role || 'text'), bold: sg.bold || undefined }, sg.t))))),
960
+ ...notes.map((n, i) => h(Text, { key: `n${i}`, color: c('warn'), bold: true, wrap: 'wrap' }, ` ${n}`)),
961
+ arming || h(Text, { color: c('prose'), bold: true, wrap: 'wrap' }, ' ', ...runs(paintLine(footer, 'ask'))),
962
+ e == null ? h(Rule, { cols, color: 'warn' }) : h(DrawRule, { cols, color: 'warn', e }));
963
+ }
964
+
965
+ /** The card's fields for an ask line (from askText): who asks, what a yes does, why, and the footer. */
966
+ export function askCardModel(text) {
967
+ const a = parseAsk(text);
968
+ const rows = [['do', a.action], ['why', a.reason]].filter(r => r[1]);
969
+ if (a.plain) return { plain: true, title: '', rows: [], footer: String(text).trim() }; // one quiet line, no box (the walkthrough's prompt)
970
+ return { title: a.title ? `⚠ ${a.title}` : `⚠ ${a.who || 'This terminal'} asks: ${a.question}`, rows, footer: `▶ ${a.question} ${keysLabel(a.keys)}`.trim() };
971
+ }
972
+
973
+ /** Any ask (y/N/c and friends) as the approval card frame. `text` is the askText line. */
974
+ export function AskCard({ text, cols }) {
975
+ if (!String(text ?? '').replace(/^\s*▶?\s*/, '').trim()) return null; // an empty ask draws nothing: no rules, no blank line
976
+ const m = askCardModel(text);
977
+ if (m.plain) return h(Box, { width: cols, marginTop: 1 }, h(Text, { color: c('prose'), bold: true, wrap: 'wrap' }, ' ', ...runs(paintLine(m.footer, 'ask'))));
978
+ return h(NeedsYouCard, { cols, title: m.title, rows: m.rows, footer: m.footer });
979
+ }
980
+ /** Rows an AskCard takes (sizes the live region). */
981
+ export const askCardRows = (text, cols) => {
982
+ if (!String(text ?? '').replace(/^\s*▶?\s*/, '').trim()) return 0;
983
+ const m = askCardModel(text);
984
+ if (m.plain) return 1 + wrapRows(m.footer, cols - 2);
985
+ return 4 + wrapRows(m.title, cols) + m.rows.reduce((n, [, v]) => n + Math.min(8, wrapPlain(String(v), Math.max(10, cols - 10)).length), 0) + wrapRows(m.footer, cols - 2);
986
+ };
987
+
988
+ export function ApprovalCard({ card, org, cols, armed, draftHint = null, motionE = null, confirm = false, position = null }) {
989
+ const when = card.askedAt ? String(card.askedAt).replace('T', ' ').slice(0, 16) + ' UTC' : null;
990
+ const rows = card.undescribable ? [['what', card.what], ['from', card.askedBy || card.origin], ['asked', when], ['org', org]].filter(r => r[1]) : [
991
+ ['what', card.what && card.what !== card.tool ? card.what : null], ['tool', card.tool], ['target', card.target], ['scope', card.scope], ['risk', card.risk], ['from', card.foreign ? card.origin : null], ['org', org]
547
992
  ].filter(r => r[1]);
993
+ if (card.privileged) rows.push(['grants', `PRIVILEGED: ${[card.tool, card.target].filter(Boolean).join(' ')}`]);
994
+ // APPROVAL-WWWH: what exactly (verbatim), where, who, why, when, read-only or write. The command is a block: never word-wrapped.
995
+ const f = card.facts || null; const block = [];
996
+ if (f && !card.undescribable) {
997
+ if (f.where && /^\d+ (hosts|targets):/.test(f.where)) { for (const k of ['target', 'what']) { const i = rows.findIndex(r => r[0] === k && (k === 'target' || String(r[1]).includes(f.hostList[1]))); if (i >= 0) rows.splice(i, 1); } }
998
+ if (f.command) { block.push([{ t: f.command.kind === 'input' ? 'input:' : 'command:', role: 'label' }]); block.push(...codeRows(f.command.shown.split('\n'), cols - 4)); }
999
+ for (const r of [['where', f.where], ['who', f.who], ['why', f.why], ['asked', [f.asked && `"${f.asked}"`, f.when].filter(Boolean).join(' · ') || null], ['class', f.access]]) if (r[1]) rows.push(r);
1000
+ }
548
1001
  const e = motionE;
549
- const title = '⚠ Approval needed: execution is held';
1002
+ const title = `⚠ Approval needed${position && position.n > 1 ? ` (${position.i} of ${position.n})` : ''}: execution is held`;
550
1003
  const filled = e == null ? 0 : Math.min(ARM_BAR, Math.floor(clamp01(e / 0.3) * ARM_BAR));
551
1004
  const arming = e == null || mono()
552
1005
  ? h(Text, { color: c('dim') }, e == null ? ' arming…' : ` arming… ${'▰'.repeat(filled)}${'▱'.repeat(ARM_BAR - filled)}`)
553
1006
  : h(Text, null, h(Text, { color: c('dim') }, ' arming… '), h(Text, { color: c('warn') }, '▰'.repeat(filled)), h(Text, { color: c('faint') }, '▱'.repeat(ARM_BAR - filled)));
554
- return h(Box, { flexDirection: 'column', width: cols, marginTop: 1 },
555
- e == null ? h(Rule, { cols, color: 'warn' }) : h(DrawRule, { cols, color: 'warn', e }),
556
- e == null ? h(Text, { color: c('warn'), bold: true }, title) : h(Text, null, ...fxNodes([{ t: title, color: 'warn', bold: true }], { e: e - 0.1, timing: TIMING.title }, 23)),
557
- ...rows.map(([k, v]) => h(Text, { key: k, color: c('text') }, ' ', h(Text, { color: c('label') }, k.padEnd(7)), h(Text, { color: c(k === 'risk' ? 'warn' : 'value') }, clip(v, cols - 10)))),
558
- card.undescribable ? h(Text, { color: c('warn'), bold: true }, ' Quox could not describe this action') : null,
559
- draftHint === 'draft' ? h(Text, { color: c('warn') }, ' clear your draft or press Tab to act on this approval') : null,
560
- draftHint === 'focus' ? h(Text, { color: c('warn') }, ' card focused (Esc returns to your draft)') : null,
561
- !armed ? arming : h(Text, { color: c('muted') }, ...runs(paintLine(card.undescribable ? ' type the word approve to allow · d deny (no default)'
562
- : ' a approve · d deny · o open in dashboard (no default)'))),
563
- e == null ? h(Rule, { cols, color: 'warn' }) : h(DrawRule, { cols, color: 'warn', e }));
1007
+ const footer = card.privileged && confirm ? `▶ Grant ${[card.tool, card.target].filter(Boolean).join(' ')}? press y again to confirm, any other key cancels`
1008
+ : card.undescribable && confirm ? '▶ Quox could not describe this action. Approve it anyway? press y again to confirm, any other key cancels'
1009
+ : draftHint === 'focus' ? askText('Approve it?', { keys: 'y approve · n deny · card focused (Esc returns to your draft)' }) // RESTORE-TUI: every y/n goes through askText (same text)
1010
+ : draftHint === 'draft' ? askText('Approve it?', { keys: 'y/n answer once your draft is empty · Tab to answer the approval card (your draft is kept)' })
1011
+ : '▶ Approve it? y approve · n deny · c chat · Tab later · /approvals all';
1012
+ return h(NeedsYouCard, { cols, title, rows, block, notes: card.undescribable && !confirm ? ['Quox could not describe this action'] : [], footer, arming: armed ? null : arming, motionE: e });
564
1013
  }
565
1014
 
566
- /** Columns the status line's Q takes: 2 for the Braille glyph, 1 for the Ⓠ fallback. */
567
- export const statusGlyphWidth = () => glyphStill('resting', { mono: mono(), mode: glyphMode(process.env) }).width;
1015
+ /** Columns the status line's Q takes: 2 for the Braille glyph, 1 for the Ⓠ fallback (2 where Ambiguous is wide). */
1016
+ export const statusGlyphWidth = () => cellWidth(glyphStill('resting', { mono: mono(), mode: glyphMode(process.env) }).text);
1017
+
1018
+ /** The composer mode in plain words on the status line's context row. */
1019
+ export const MODE_WORDS = { ask: 'ask first', auto: 'auto, acts without asking', plan: 'plan only' };
568
1020
 
569
1021
  /**
570
- * Fit the status line to the width: fields are dropped by priority (org, then the key hint, then mode,
571
- * then profile) and joined by separators, never clipped mid-word or glued to the hint. Pure.
1022
+ * The status as ONE continuous line that wraps (owner 2026-10-17 19:47: "should just make it one long line that wraps
1023
+ * to second or third line if needed ... so much space, looks wrong"; "should say agent: none, when nothing attached").
1024
+ * `● agent X · ⬢ slot S · ⬢ groups a 2, b · profile P · org O · mode ask first · rules · ↻ auto-restart`, wrapped
1025
+ * onto as few rows as it needs, evened out so no item sits alone, broken only between items, every further row at
1026
+ * the same left edge (never inside an item; a
1027
+ * single value too long for a row is split across rows). The key hints are separate: always their own row at that
1028
+ * same left edge, so nothing is right-aligned and no row carries a gap. The model sits on the composer's bottom rule
1029
+ * (modelRuleLabel). Widths are terminal cells under the ambiguous-width policy (cells.js).
1030
+ * Pure: rows of { text, segs, hint, gap, lead } where segs are [text, kind, extra].
572
1031
  */
573
- export function statusLayout({ cols, slot, agent, parts, hint, qw = statusGlyphWidth() }) {
574
- const room = Math.max(10, cols - 1);
575
- const ident = slot ? `⬢ slot ${slot}` : '⬡ no slot';
576
- const ag = agent ? `● ${agent}` : '○ no agent';
577
- const order = ['org', 'rules', 'hint', 'mode', 'profile']; // first dropped first; model is kept longest
578
- let keep = new Set(['profile', 'org', 'model', 'mode', 'hint', 'rules']);
579
- const build = () => {
580
- const tail = ['profile', 'org', 'model', 'mode', 'rules'].filter(k => keep.has(k) && parts[k]).map(k => parts[k]).join(' · ');
581
- const left = ` Ⓠ ✦ ${ident} · ${ag}${tail ? ' · ' + tail : ''}`;
582
- const hintS = keep.has('hint') && hint ? hint : '';
583
- return { left, hint: hintS, width: [...left].length + (qw - 1) + (hintS ? 2 + [...hintS].length : 0) };
1032
+ export function statusRows({ cols, slot, agent, groups = [], parts, hint, qw = statusGlyphWidth(), wide = ambiguousWide() }) {
1033
+ const len = (t) => cellWidth(t, { wide });
1034
+ const W = Math.max(12, cols - 1);
1035
+ const lead = 1 + qw + len(' ✦ '); // ' ' + Q + ' ✦ '
1036
+ const room = Math.max(4, W - lead);
1037
+ // a token: segs to draw, joined to the previous token on the same row by `pre`
1038
+ const tokens = [];
1039
+ tokens.push(agent
1040
+ ? { pre: ' · ', segs: [['● ', 'agentDot', agent], ['agent ', 'label'], [agent, 'agent', agent]] }
1041
+ : { pre: ' · ', segs: [['○ ', 'icon'], ['agent: ', 'label'], ['none', 'value']] });
1042
+ tokens.push({ pre: ' · ', segs: slot ? [['⬢ ', 'icon'], ['slot ', 'label'], [slot, 'value']] : [['⬡ no slot', 'label']] });
1043
+ (groups || []).filter(g => g?.name).forEach((g, i) => tokens.push({ pre: i ? ', ' : ' · ',
1044
+ segs: [...(i ? [] : [['⬢ ', 'icon'], ['groups ', 'label']]), [g.name, 'value'], ...(g.unread ? [[' ' + g.unread, 'number']] : [])] }));
1045
+ const p = parts || {};
1046
+ // every context item says what it is (owner: "profile moo .. ask?? what?"); /help status explains each in a line
1047
+ const word = { profile: 'profile ', org: 'org ', mode: 'mode ' };
1048
+ const val = (k) => k === 'mode' ? (MODE_WORDS[p.mode] || null) : k === 'auto' ? '↻ auto-restart' : String(p[k]);
1049
+ for (const k of ['profile', 'org', 'mode', 'rules', 'auto'].filter(k => p[k])) tokens.push({ pre: ' · ',
1050
+ segs: word[k] && val(k) ? [[word[k], 'label'], [val(k), k === 'mode' && p.mode === 'plan' ? 'violet' : 'value']] : [[k === 'mode' ? String(p[k]) : val(k), 'label']] });
1051
+ const tlen = (tk) => tk.segs.reduce((n, sg) => n + len(sg[0]), 0);
1052
+ // split a token too wide for a row into row-sized pieces (whole characters by cell width, never an ellipsis)
1053
+ const fit = (tk) => {
1054
+ if (tlen(tk) <= room) return [tk];
1055
+ const out = [];
1056
+ let segs = [], w = 0;
1057
+ const flush = () => { out.push({ pre: out.length ? '' : tk.pre, segs, forceBreak: out.length > 0 }); segs = []; w = 0; };
1058
+ for (const [t, k, x] of tk.segs) for (const ch of t) {
1059
+ const cw = len(ch);
1060
+ if (w + cw > room && segs.length) flush();
1061
+ const last = segs[segs.length - 1];
1062
+ if (last && last[1] === k) last[0] += ch; else segs.push([ch, k, x]);
1063
+ w += cw;
1064
+ }
1065
+ if (segs.length) flush();
1066
+ return out;
584
1067
  };
585
- let out = build();
586
- for (const k of order) { if (out.width <= room) break; keep.delete(k); out = build(); }
587
- return out;
1068
+ // fill each row left to right; break only between items (or at a forced piece of an over-long one)
1069
+ const pack = (pieces, limit = room) => {
1070
+ const rows = [];
1071
+ let cur = null, w = 0;
1072
+ for (const tk of pieces) {
1073
+ const need = tlen(tk) + (cur && cur.length ? len(tk.pre) : 0);
1074
+ if (!cur || tk.forceBreak || w + need > limit) { cur = [{ ...tk, pre: '' }]; rows.push(cur); w = tlen(tk); continue; }
1075
+ cur.push(tk); w += need;
1076
+ }
1077
+ return rows;
1078
+ };
1079
+ // as few rows as filling gives, evened out (the narrowest limit that keeps that count): no item left alone on a row
1080
+ const balanced = (pieces) => {
1081
+ const n = pack(pieces).length;
1082
+ if (n < 2) return pack(pieces);
1083
+ let lo = Math.max(1, ...pieces.map(tlen)), hi = room;
1084
+ while (lo < hi) { const m = (lo + hi) >> 1; if (pack(pieces, m).length <= n) hi = m; else lo = m + 1; }
1085
+ return pack(pieces, lo);
1086
+ };
1087
+ const toSegs = (row) => row.flatMap(tk => [...(tk.pre ? [[tk.pre, 'sep']] : []), ...tk.segs]);
1088
+ const rowsOut = balanced(tokens.flatMap(fit)).map(row => ({ segs: toSegs(row), hint: '' }));
1089
+ const hintS = String(hint || '');
1090
+ if (hintS) for (const r of pack(hintS.split(' · ').map(t => ({ pre: ' · ', segs: [[t, 'hint']] })))) rowsOut.push({ segs: [], hint: toSegs(r).map(x => x[0]).join('') });
1091
+ const pad = ' '.repeat(lead);
1092
+ return rowsOut.map((r, i) => {
1093
+ const body = r.segs.map(x => x[0]).join('');
1094
+ const head = i === 0 ? ' ' + 'Ⓠ'.padEnd(qw, ' ') + ' ✦ ' : pad;
1095
+ return { segs: r.segs, hint: r.hint, gap: 0, lead, text: head + body + r.hint };
1096
+ });
1097
+ }
1098
+
1099
+ /** QUOXON-FW17: custom rows, one truncated line each, just above the status line. */
1100
+ export function RowsBar({ rows, cols }) {
1101
+ if (!rows?.length) return null;
1102
+ const shown = rows.slice(0, 3);
1103
+ const labelW = labelWidth(shown); // labels line up across rows
1104
+ return h(Box, { flexDirection: 'column', width: cols },
1105
+ ...shown.map((r) => {
1106
+ const parts = clipParts(rowParts(r, { labelW }), Math.max(1, cols - 2));
1107
+ // ROWS: label, value, tone and trend as their own runs; every role is a palette colour (no grey, owner rule).
1108
+ return h(Text, { key: r.row.id, wrap: 'truncate-end' }, ' ', ...parts.map(([t, role, bold], i) => h(Text, { key: i, color: c(themeRole(role)), bold: Boolean(bold) }, t)));
1109
+ }));
588
1110
  }
589
1111
 
590
- export function StatusLine({ cols, slot, agent, parts, right }) {
591
- const p = Array.isArray(parts) ? { profile: parts[0], org: parts[1], model: parts[2], mode: parts[3], rules: parts[4] } : parts;
592
- const L = statusLayout({ cols, slot, agent, parts: p, hint: right });
593
- const gap = L.hint ? Math.max(2, cols - 1 - [...L.left].length - (statusGlyphWidth() - 1) - [...L.hint].length) : 0;
594
- const lead = ' Ⓠ ✦ ';
595
- const rest = L.left.slice(lead.length);
596
- // The still Q (qglyph.js): two Braille cells, or Ⓠ under NO_COLOR / no Braille. statusLayout reserved its width.
1112
+ export function StatusLine({ cols, slot, agent, groups = [], parts, right }) {
1113
+ const p = Array.isArray(parts) ? { profile: parts[0], org: parts[1], model: parts[2], mode: parts[3], rules: parts[4], auto: parts[5] } : parts;
1114
+ const qw = statusGlyphWidth();
1115
+ const rows = statusRows({ cols, slot, agent, groups, parts: p, hint: right, qw });
1116
+ // The still Q (qglyph.js): two Braille cells, or Ⓠ under NO_COLOR / no Braille. statusRows reserved its width.
597
1117
  const q = glyphStill('resting', { mono: mono(), mode: glyphMode(process.env), depth: colorDepth(process.env) });
598
- return h(Box, { width: cols },
599
- h(Text, { wrap: 'truncate-end' }, ' ', h(Text, { bold: true }, ...cellNodes(q.cells, 'sq')), h(Text, { color: c('icon') }, ' ✦ '),
600
- h(Text, { color: c('text') }, ...statusIdent(rest.split(' · ').slice(0, 2).join(' · '))),
601
- rest.split(' · ').length > 2 ? h(Text, { color: c('label') }, ...runs(paintRuns(' · ' + rest.split(' · ').slice(2).join(' · '), 'label'))) : null,
602
- L.hint ? h(Text, { color: c('muted') }, ' '.repeat(gap), ...runs(paintRuns(L.hint, 'muted'))) : null));
1118
+ const colour = (k, x) => k === 'agentDot' || k === 'agent' ? agentColor(x) : c(k === 'sep' || k === 'hint' ? 'label' : k);
1119
+ return h(Box, { width: cols, flexDirection: 'column' }, ...rows.map((r, i) => h(Text, { key: 'r' + i, wrap: 'truncate-end' },
1120
+ i === 0 ? h(Text, null, ' ', h(Text, { bold: true }, ...cellNodes(q.cells, 'sq')), h(Text, { color: c('icon') }, ' ✦ ')) : ' '.repeat(r.lead),
1121
+ ...r.segs.map(([t, k, x], j) => h(Text, { key: j, color: colour(k, x), bold: k === 'agent' || k === 'number' }, t)),
1122
+ r.hint ? h(Text, { color: c('label') }, ' '.repeat(r.gap), ...hintNodes(r.hint)) : null))); // no grey (owner rule)
603
1123
  }
604
1124
 
605
- /** `⬢ slot NAME · ● AGENT` as runs: glyphs in the icon role, `slot` a label, the agent in its own shade. */
606
- function statusIdent(t) {
607
- const m = t.match(/^(⬢|⬡) (slot |no slot)(.*?) · (●|○) (.*)$/);
608
- if (!m) return [t];
609
- const agent = m[4] === '●';
610
- return [h(Text, { key: 'g', color: c(m[1] === '⬢' ? 'icon' : 'muted') }, m[1] + ' '), h(Text, { key: 's', color: c(m[3] ? 'label' : 'muted') }, m[2]),
611
- m[3] ? h(Text, { key: 'n', color: c('value') }, m[3]) : null, h(Text, { key: 'd', color: c('muted') }, ' · '),
612
- h(Text, { key: 'a', color: agent ? agentColor(m[5]) : c('muted') }, m[4] + ' '), h(Text, { key: 'an', color: agent ? agentColor(m[5]) : c('muted'), bold: agent }, m[5])];
1125
+ /** `Enter send · /help`: each key in the key role, its words and the separators in label (never a grey). */
1126
+ function hintNodes(hint) {
1127
+ return hint.split(' · ').flatMap((part, i) => {
1128
+ const [k, ...rest] = part.split(' ');
1129
+ return [i ? h(Text, { key: 's' + i, color: c('label') }, ' · ') : null, h(Text, { key: 'k' + i, color: c('key') }, k), rest.length ? h(Text, { key: 'w' + i, color: c('label') }, ' ' + rest.join(' ')) : null];
1130
+ }).filter(Boolean);
613
1131
  }
614
1132
 
615
1133
  /** Live, actionable counts under the status line. Never a transcript message. */
616
- export function NotifyBar({ approvals, error, cols, signedOut = false, alerts = [] }) {
1134
+ export function NotifyBar({ approvals, error, cols, signedOut = false, alerts = [], hideCount = false }) {
617
1135
  if (signedOut) return h(Text, { color: c('warn') }, ' ' + clip('not signed in: approvals unavailable until you sign in', cols - 2));
618
- const count = approvals ? h(Text, { key: 'n', color: c('warn') }, ' ' + clip(`⛔ ${approvals} approval${approvals === 1 ? '' : 's'} waiting for you${error ? ' (last known)' : ''} · /approvals`, cols - 3)) : null;
1136
+ const count = approvals && !hideCount ? h(Text, { key: 'n', color: c('ask'), bold: true }, ' ' + clip(`▶ ${approvals} approval${approvals === 1 ? '' : 's'} waiting for you${error ? ' (last known)' : ''} · /approvals`, cols - 3)) : null;
619
1137
  // Background workflows that keep failing: one deduped line each (max 2), never roster rows.
620
1138
  const alertLines = alerts.slice(0, 2).map((t, i) => h(Text, { key: 'a' + i, color: c('fail') }, ' ' + clip(t, cols - 2)));
621
1139
  if (alertLines.length) {
@@ -638,8 +1156,9 @@ export function Roster({ view, peek = [], confirm = null, hint = null, cols, fx
638
1156
  ...view.lines.map((l, i) => {
639
1157
  const e = fx && l.key != null ? fx(l.key) : null; // a row that just appeared decodes in (new rows land on top)
640
1158
  return h(Text, { key: 'r' + i, bold: l.selected, wrap: 'truncate-end' },
641
- h(Text, { color: c(l.selected ? 'text' : ROSTER_TONE[l.state]) }, ' ' + l.marker + l.glyph),
642
- e == null ? h(Text, { color: c(l.selected ? 'text' : l.tone) }, l.rest) : h(Text, null, ...fxNodes([{ t: l.rest, color: l.selected ? 'text' : l.tone }], { e, timing: TIMING.roster }, 29 + i)));
1159
+ h(Text, { color: c(l.selected ? 'text' : (l.glyphRole || ROSTER_TONE[l.state])) }, ' ' + l.marker + l.glyph),
1160
+ e == null ? h(Text, { color: c(l.selected ? 'text' : l.tone) }, l.rest) : h(Text, null, ...fxNodes([{ t: l.rest, color: l.selected ? 'text' : l.tone }], { e, timing: TIMING.roster }, 29 + i)),
1161
+ l.pulse ? h(Text, { color: c(l.pulseRole === 'dim' && l.selected ? 'text' : l.pulseRole) }, l.pulse) : null);
643
1162
  }),
644
1163
  view.more ? h(Text, { key: 'more', color: c('dim') }, ` +${view.more} more · /roster`) : null,
645
1164
  ...peek.map((p, i) => h(Text, { key: 'p' + i, color: c('dim'), wrap: 'truncate-end' }, ' ' + clip(p, cols - 5))),