taskquoin 0.0.0-stage → 2026.12.0

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 (160) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +55 -0
  3. package/README.md +227 -2
  4. package/SECURITY.md +26 -0
  5. package/adapters/git/src/git.js +250 -0
  6. package/adapters/git/src/index.js +1 -0
  7. package/adapters/hooks-claude/src/canonical.js +45 -0
  8. package/adapters/hooks-claude/src/index.js +2 -0
  9. package/adapters/hooks-claude/src/main.js +58 -0
  10. package/adapters/hooks-claude/src/payload.js +40 -0
  11. package/adapters/host-probe/src/index.js +2 -0
  12. package/adapters/host-probe/src/ollama.js +18 -0
  13. package/adapters/host-probe/src/probe.js +107 -0
  14. package/adapters/local-tool/src/fingerprint.js +56 -0
  15. package/adapters/local-tool/src/index.js +4 -0
  16. package/adapters/local-tool/src/local-tool.js +22 -0
  17. package/adapters/local-tool/src/sandboxed.js +105 -0
  18. package/adapters/local-tool/src/scan.js +52 -0
  19. package/adapters/memory-claude-mem/src/claude-mem.js +115 -0
  20. package/adapters/memory-claude-mem/src/index.js +1 -0
  21. package/adapters/process-runner/src/index.js +1 -0
  22. package/adapters/process-runner/src/runner.js +123 -0
  23. package/adapters/runtime-api/src/capabilities.json +116 -0
  24. package/adapters/runtime-api/src/executor.js +131 -0
  25. package/adapters/runtime-api/src/index.js +1 -0
  26. package/adapters/runtime-claude/src/capabilities.json +375 -0
  27. package/adapters/runtime-claude/src/command.js +34 -0
  28. package/adapters/runtime-claude/src/executor.js +162 -0
  29. package/adapters/runtime-claude/src/index.js +4 -0
  30. package/adapters/runtime-claude/src/permissions.js +76 -0
  31. package/adapters/runtime-claude/src/stream.js +60 -0
  32. package/adapters/runtime-codex/src/capabilities.json +192 -0
  33. package/adapters/runtime-codex/src/command.js +36 -0
  34. package/adapters/runtime-codex/src/executor.js +83 -0
  35. package/adapters/runtime-codex/src/index.js +4 -0
  36. package/adapters/runtime-codex/src/scratch.js +32 -0
  37. package/adapters/runtime-codex/src/stream.js +39 -0
  38. package/adapters/runtime-opencode/src/capabilities.json +149 -0
  39. package/adapters/runtime-opencode/src/config.js +33 -0
  40. package/adapters/runtime-opencode/src/credentials.js +130 -0
  41. package/adapters/runtime-opencode/src/executor.js +127 -0
  42. package/adapters/runtime-opencode/src/facts.js +43 -0
  43. package/adapters/runtime-opencode/src/hosts.js +16 -0
  44. package/adapters/runtime-opencode/src/hosts.json +3 -0
  45. package/adapters/runtime-opencode/src/index.js +6 -0
  46. package/adapters/runtime-opencode/src/mounts.js +58 -0
  47. package/adapters/runtime-opencode/src/stream.js +63 -0
  48. package/adapters/skill-store/src/index.js +1 -0
  49. package/adapters/skill-store/src/skill-store.js +162 -0
  50. package/adapters/store-fs/src/index.js +2 -0
  51. package/adapters/store-fs/src/store.js +201 -0
  52. package/adapters/store-fs/src/trusted-dir.js +37 -0
  53. package/apps/cli/src/console.js +432 -0
  54. package/apps/cli/src/dashboard-approve.js +259 -0
  55. package/apps/cli/src/dashboard-data.js +424 -0
  56. package/apps/cli/src/dashboard.js +500 -0
  57. package/apps/cli/src/history.js +35 -0
  58. package/apps/cli/src/home.js +18 -0
  59. package/apps/cli/src/i18n/en.js +527 -0
  60. package/apps/cli/src/i18n/index.js +90 -0
  61. package/apps/cli/src/i18n/languages.js +25 -0
  62. package/apps/cli/src/i18n/locales/ar.json +526 -0
  63. package/apps/cli/src/i18n/locales/de.json +505 -0
  64. package/apps/cli/src/i18n/locales/es.json +505 -0
  65. package/apps/cli/src/i18n/locales/fa.json +505 -0
  66. package/apps/cli/src/i18n/locales/fr.json +505 -0
  67. package/apps/cli/src/i18n/locales/he.json +505 -0
  68. package/apps/cli/src/i18n/locales/hi.json +505 -0
  69. package/apps/cli/src/i18n/locales/id.json +491 -0
  70. package/apps/cli/src/i18n/locales/it.json +505 -0
  71. package/apps/cli/src/i18n/locales/ja.json +491 -0
  72. package/apps/cli/src/i18n/locales/ko.json +491 -0
  73. package/apps/cli/src/i18n/locales/nl.json +505 -0
  74. package/apps/cli/src/i18n/locales/pl.json +512 -0
  75. package/apps/cli/src/i18n/locales/pt-BR.json +505 -0
  76. package/apps/cli/src/i18n/locales/ru.json +512 -0
  77. package/apps/cli/src/i18n/locales/th.json +491 -0
  78. package/apps/cli/src/i18n/locales/tr.json +505 -0
  79. package/apps/cli/src/i18n/locales/uk.json +512 -0
  80. package/apps/cli/src/i18n/locales/vi.json +491 -0
  81. package/apps/cli/src/i18n/locales/zh-CN.json +491 -0
  82. package/apps/cli/src/i18n/locales/zh-TW.json +491 -0
  83. package/apps/cli/src/i18n/width.js +40 -0
  84. package/apps/cli/src/layout.js +18 -0
  85. package/apps/cli/src/main.js +830 -0
  86. package/apps/cli/src/preferences.js +46 -0
  87. package/apps/cli/src/runtime-notices.js +41 -0
  88. package/apps/cli/src/safe-text.js +3 -0
  89. package/apps/cli/src/shortcut.js +82 -0
  90. package/apps/cli/src/skills-cli.js +112 -0
  91. package/apps/cli/src/tui/caps.js +31 -0
  92. package/apps/cli/src/tui/components/agent-list.js +58 -0
  93. package/apps/cli/src/tui/components/approval-center.js +145 -0
  94. package/apps/cli/src/tui/components/approval.js +95 -0
  95. package/apps/cli/src/tui/components/dashboard-frame.js +293 -0
  96. package/apps/cli/src/tui/components/diff-viewer.js +549 -0
  97. package/apps/cli/src/tui/components/event-viewer.js +46 -0
  98. package/apps/cli/src/tui/components/help-panel.js +59 -0
  99. package/apps/cli/src/tui/components/home.js +185 -0
  100. package/apps/cli/src/tui/components/logo.js +67 -0
  101. package/apps/cli/src/tui/components/panel.js +70 -0
  102. package/apps/cli/src/tui/components/status-bar.js +96 -0
  103. package/apps/cli/src/tui/components/timeline.js +120 -0
  104. package/apps/cli/src/tui/keys.js +139 -0
  105. package/apps/cli/src/tui/neutral.js +68 -0
  106. package/apps/cli/src/tui/screen.js +111 -0
  107. package/apps/cli/src/tui/text.js +165 -0
  108. package/apps/cli/src/tui/tokens.js +89 -0
  109. package/apps/cli/src/tui/view.js +64 -0
  110. package/apps/cli/src/upgrade-check.js +86 -0
  111. package/apps/cli/src/upgrade-cli.js +168 -0
  112. package/apps/cli/src/workflow-cli.js +674 -0
  113. package/package.json +29 -4
  114. package/packages/application/src/index.js +8 -0
  115. package/packages/application/src/lib/digest.js +7 -0
  116. package/packages/application/src/ports/memory.js +1 -0
  117. package/packages/application/src/ports/runtime-executor.js +1 -0
  118. package/packages/application/src/projection/run-view.js +194 -0
  119. package/packages/application/src/projection/squad-view.js +33 -0
  120. package/packages/application/src/use-cases/prepare-run.js +68 -0
  121. package/packages/application/src/workflow/feature-governed.js +420 -0
  122. package/packages/application/src/workflow/gate-signals.js +40 -0
  123. package/packages/application/src/workflow/prompts.js +81 -0
  124. package/packages/config/src/config.js +372 -0
  125. package/packages/config/src/index.js +1 -0
  126. package/packages/domain/src/capabilities.js +13 -0
  127. package/packages/domain/src/capability-matrix.js +63 -0
  128. package/packages/domain/src/enforcement.js +95 -0
  129. package/packages/domain/src/index.js +4 -0
  130. package/packages/domain/src/policy.js +32 -0
  131. package/packages/rules/src/glob.js +47 -0
  132. package/packages/rules/src/index.js +5 -0
  133. package/packages/rules/src/inherit.js +19 -0
  134. package/packages/rules/src/lists.js +41 -0
  135. package/packages/rules/src/rules.js +79 -0
  136. package/packages/rules/src/shell.js +83 -0
  137. package/packages/skills/src/index.js +1 -0
  138. package/packages/skills/src/skills.js +108 -0
  139. package/skills/code-review/SKILL.md +51 -0
  140. package/skills/egm-design/LICENSE +202 -0
  141. package/skills/egm-design/SKILL.md +68 -0
  142. package/skills/egm-design/references/feature-spec-standard.md +39 -0
  143. package/skills/egm-implementation-readiness/LICENSE +202 -0
  144. package/skills/egm-implementation-readiness/SKILL.md +67 -0
  145. package/skills/egm-implementation-readiness/references/implementation-readiness-standard.md +37 -0
  146. package/skills/first-party.lock.json +10 -0
  147. package/skills/planning-contract/SKILL.md +51 -0
  148. package/skills/ponytail/LICENSE +21 -0
  149. package/skills/ponytail/SKILL.md +56 -0
  150. package/skills/security-review/SKILL.md +58 -0
  151. package/skills/tdd/SKILL.md +52 -0
  152. package/skills/unslop/LICENSE +396 -0
  153. package/skills/unslop/SKILL.md +239 -0
  154. package/skills/unslop/references/cjk.md +34 -0
  155. package/skills/unslop/references/effects.md +113 -0
  156. package/skills/unslop/references/refs.md +17 -0
  157. package/skills/unslop/references/rtl.md +111 -0
  158. package/skills/unslop/references/signs.md +122 -0
  159. package/skills/unslop/references/tokens.md +139 -0
  160. package/skills/unslop/references/visuals.md +84 -0
@@ -0,0 +1,549 @@
1
+ /**
2
+ * The diff and artifact viewer: files, line numbers, search, "read to the end" and a stale marker. A diff is the most
3
+ * hostile text the dashboard shows, so it is neutralised ONCE, when it is parsed (`parseDiff`, `textDocs`): every
4
+ * control, escape, C1, bidi, invisible and tag character becomes a visible, counted marker, CRLF becomes LF and tabs
5
+ * are expanded; the renderers only measure, cut and paint what is already neutral. Nothing here reads or writes a file.
6
+ * A line is never longer than 20 000 characters after parsing and a document keeps its first 100 000 lines, both said
7
+ * on screen. The percentage in the document title is the one real ratio: lines scrolled past / lines in the file.
8
+ */
9
+ import { t, tn } from "../../i18n/index.js";
10
+ import { displayWidth } from "../../i18n/width.js";
11
+ import { cutNeutral, neutralize } from "../neutral.js";
12
+ import { bold, ellipsis, glyph, lineBg, mark, paint } from "../tokens.js";
13
+ import { clip, cut, expandTabs, pad } from "../text.js";
14
+ import { renderFooter } from "./status-bar.js";
15
+ import { panel } from "./panel.js";
16
+ export const MAX_LINES = 100_000;
17
+ export const MAX_LINE = 20_000;
18
+ const MAX_HITS = 10_000;
19
+ const MAX_QUERY = 100;
20
+ // ---- parsing ------------------------------------------------------------------------------------------------------
21
+ /** One stored line: cut to MAX_LINE, neutralised (strict), tabs expanded. `marked` counts what was made visible. */
22
+ function prep(raw) {
23
+ let r = raw, cutAt = false;
24
+ if (r.length > MAX_LINE) {
25
+ r = r.slice(0, MAX_LINE);
26
+ const c = r.charCodeAt(r.length - 1);
27
+ if (c >= 0xd800 && c <= 0xdbff)
28
+ r = r.slice(0, -1);
29
+ cutAt = true;
30
+ }
31
+ const z = neutralize(r);
32
+ return { text: expandTabs(z.text) + (cutAt ? '…' : ''), marked: z.marked };
33
+ }
34
+ const splitLines = (text) => {
35
+ const lines = text.replace(/\r\n/g, '\n').split('\n');
36
+ if (lines.length > 1 && lines.at(-1) === '')
37
+ lines.pop();
38
+ return lines;
39
+ };
40
+ const name1 = (raw) => { const z = neutralize(raw, { singleLine: true }); return { text: z.text, marked: z.marked }; };
41
+ const stripSide = (p, side) => {
42
+ let s = p.split('\t')[0].trim();
43
+ if (s.startsWith('"') && s.endsWith('"') && s.length >= 2)
44
+ s = s.slice(1, -1);
45
+ return s.startsWith(`${side}/`) ? s.slice(2) : s;
46
+ };
47
+ /** `diff --git a/X b/X` → X (a rename keeps the new name through the later `+++` line). */
48
+ function gitName(rest) {
49
+ const h = (rest.length - 1) / 2;
50
+ if (Number.isInteger(h) && rest[h] === ' ' && rest.slice(0, h).startsWith('a/') && rest.slice(h + 1).startsWith('b/') && rest.slice(2, h) === rest.slice(h + 3))
51
+ return rest.slice(h + 3);
52
+ const at = rest.lastIndexOf(' b/');
53
+ return at >= 0 ? stripSide(rest.slice(at + 1), 'b') : rest;
54
+ }
55
+ const HUNK = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
56
+ /** A unified diff (`git diff` output) as one document per file. Neutralises every path and line. */
57
+ export function parseDiff(text) {
58
+ const docs = [];
59
+ const extra = new WeakMap();
60
+ let cur;
61
+ let hunk;
62
+ let binary = false, sawMinus = false, sawPlus = false, nameMarks = 0;
63
+ const start = (name) => {
64
+ const z = name1(name);
65
+ cur = { name: z.text, added: 0, removed: 0, lines: [], marked: z.marked };
66
+ nameMarks = z.marked;
67
+ docs.push(cur);
68
+ hunk = undefined;
69
+ binary = false;
70
+ sawMinus = false;
71
+ sawPlus = false;
72
+ };
73
+ const rename = (name) => { const z = name1(name); cur.marked += z.marked - nameMarks; nameMarks = z.marked; cur.name = z.text; };
74
+ const push = (kind, raw, nums = {}) => {
75
+ const d = cur;
76
+ if (kind === 'add')
77
+ d.added++;
78
+ else if (kind === 'del')
79
+ d.removed++;
80
+ if (d.lines.length >= MAX_LINES) {
81
+ extra.set(d, (extra.get(d) ?? 0) + 1);
82
+ return;
83
+ }
84
+ const p = prep(raw);
85
+ d.marked += p.marked;
86
+ d.lines.push({ kind, ...nums, text: p.text });
87
+ };
88
+ const note = () => {
89
+ if (!binary) {
90
+ binary = true;
91
+ cur.binary = true;
92
+ cur.lines.push({ kind: 'meta', text: t('dashboard.viewer.binary') });
93
+ }
94
+ };
95
+ for (const raw of splitLines(text)) {
96
+ if (hunk && (hunk.ro > 0 || hunk.rn > 0)) {
97
+ const c = raw[0];
98
+ if (c === '+') {
99
+ push('add', raw.slice(1), { new: hunk.n++ });
100
+ hunk.rn--;
101
+ continue;
102
+ }
103
+ if (c === '-') {
104
+ push('del', raw.slice(1), { old: hunk.o++ });
105
+ hunk.ro--;
106
+ continue;
107
+ }
108
+ if (c === ' ' || raw === '') {
109
+ push('ctx', raw.slice(1), { old: hunk.o++, new: hunk.n++ });
110
+ hunk.ro--;
111
+ hunk.rn--;
112
+ continue;
113
+ }
114
+ if (c !== '\\')
115
+ hunk = undefined;
116
+ }
117
+ if (raw.startsWith('diff --git ')) {
118
+ start(gitName(raw.slice(11)));
119
+ continue;
120
+ }
121
+ if (cur && binary)
122
+ continue; // the base85 block of a binary patch is never shown
123
+ if (raw.startsWith('--- ')) {
124
+ if (!cur || sawMinus)
125
+ start(stripSide(raw.slice(4), 'a'));
126
+ sawMinus = true;
127
+ continue;
128
+ }
129
+ if (raw.startsWith('+++ ') && cur && !sawPlus) {
130
+ sawPlus = true;
131
+ const p = raw.slice(4).split('\t')[0].trim();
132
+ if (p !== '/dev/null')
133
+ rename(stripSide(p, 'b'));
134
+ continue;
135
+ }
136
+ const h = HUNK.exec(raw);
137
+ if (h) {
138
+ if (!cur)
139
+ start(t('dashboard.viewer.preamble'));
140
+ hunk = { o: Number(h[1]), n: Number(h[3]), ro: h[2] === undefined ? 1 : Number(h[2]), rn: h[4] === undefined ? 1 : Number(h[4]) };
141
+ push('hunk', raw);
142
+ continue;
143
+ }
144
+ if (raw === 'GIT binary patch' || /^Binary files .* differ$/.test(raw)) {
145
+ if (!cur)
146
+ start(t('dashboard.viewer.preamble'));
147
+ note();
148
+ continue;
149
+ }
150
+ if (!cur) {
151
+ if (raw.trim() === '')
152
+ continue;
153
+ start(t('dashboard.viewer.preamble'));
154
+ }
155
+ push('meta', raw);
156
+ }
157
+ for (const d of docs) {
158
+ const more = extra.get(d);
159
+ if (more)
160
+ d.lines.push({ kind: 'meta', text: t('dashboard.viewer.truncated', { count: more }) });
161
+ }
162
+ return docs;
163
+ }
164
+ /** Plain text (a plan, a challenge, a verify log) as documents, one per name; lines are numbered. */
165
+ export function textDocs(named) {
166
+ return named.map(({ name, text }) => {
167
+ const z = name1(name);
168
+ const doc = { name: z.text, added: 0, removed: 0, lines: [], marked: z.marked };
169
+ const lines = text === '' ? [] : splitLines(text);
170
+ lines.forEach((raw, i) => {
171
+ if (i >= MAX_LINES)
172
+ return;
173
+ const p = prep(raw);
174
+ doc.marked += p.marked;
175
+ doc.lines.push({ kind: 'text', new: i + 1, text: p.text });
176
+ });
177
+ if (lines.length > MAX_LINES)
178
+ doc.lines.push({ kind: 'meta', text: t('dashboard.viewer.truncated', { count: lines.length - MAX_LINES }) });
179
+ return doc;
180
+ });
181
+ }
182
+ // ---- units: a marker or a code point is never split -----------------------------------------------------------------
183
+ const UNIT = /‹(?:[A-Z]{2,3}|U\+[0-9A-F]{4,6})›|[\s\S]/gu;
184
+ function* units(text) {
185
+ for (const [u] of text.matchAll(UNIT))
186
+ yield [u, displayWidth(u)];
187
+ }
188
+ /** `text` cut to `width` columns: a cut line ends with `→` at the last column; never splits a marker. */
189
+ function cutLine(text, width, caps) {
190
+ if (width <= 0)
191
+ return '';
192
+ const arrow = mark('arrow', caps), aw = displayWidth(arrow);
193
+ let out = '', fit = '', w = 0;
194
+ for (const [u, uw] of units(text)) {
195
+ if (w + uw > width)
196
+ return aw > width ? '' : fit + arrow;
197
+ out += u;
198
+ w += uw;
199
+ if (w <= width - aw)
200
+ fit = out;
201
+ }
202
+ return out;
203
+ }
204
+ /** `text` as rows of at most `width` columns (wrapping): a marker is never split across rows. */
205
+ function wrapRows(text, width) {
206
+ if (width <= 0)
207
+ return [''];
208
+ const rows = [];
209
+ let row = '', w = 0;
210
+ for (const [u, uw] of units(text)) {
211
+ if (w + uw > width && row !== '') {
212
+ rows.push(row);
213
+ row = '';
214
+ w = 0;
215
+ }
216
+ row += u;
217
+ w += uw;
218
+ }
219
+ rows.push(row);
220
+ return rows;
221
+ }
222
+ // ---- geometry -----------------------------------------------------------------------------------------------------
223
+ const numWOf = new WeakMap();
224
+ function numW(doc) {
225
+ let w = numWOf.get(doc);
226
+ if (w === undefined) {
227
+ let max = 0;
228
+ for (const l of doc.lines) {
229
+ if (l.old !== undefined && l.old > max)
230
+ max = l.old;
231
+ if (l.new !== undefined && l.new > max)
232
+ max = l.new;
233
+ }
234
+ w = Math.max(3, String(max).length);
235
+ numWOf.set(doc, w);
236
+ }
237
+ return w;
238
+ }
239
+ const numbered = (d) => d.lines.some((l) => l.kind === 'text') && !d.lines.some((l) => l.kind === 'add' || l.kind === 'del' || l.kind === 'ctx');
240
+ const gutterW = (d) => (numbered(d) ? 2 + numW(d) + 1 : 2 + numW(d) * 2 + 4);
241
+ /** The document area: `rows` is what scrolls (before the one-line warning of a file with neutralised characters). */
242
+ export function geometry(caps, height) {
243
+ const wide = caps.columns >= 120 && height >= 8;
244
+ if (wide)
245
+ return { wide, listW: 36, width: caps.columns - 36 - 1 - 4, rows: Math.max(1, height - 4) };
246
+ return { wide, listW: 0, width: caps.columns, rows: Math.max(1, height - 3) };
247
+ }
248
+ const rowsFor = (doc, base) => Math.max(1, base - (doc && doc.marked > 0 ? 1 : 0));
249
+ // ---- the keys -----------------------------------------------------------------------------------------------------
250
+ const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
251
+ const cur = (v) => v.docs[v.file];
252
+ /** How many whole logical lines the screen shows from `top` (wrapping makes a line take several rows). */
253
+ function linesOnScreen(v, rows) {
254
+ const doc = cur(v);
255
+ if (!doc)
256
+ return 0;
257
+ if (!v.wrap || v.width === undefined)
258
+ return Math.min(rows, doc.lines.length - v.top);
259
+ const tw = Math.max(1, v.width - gutterW(doc));
260
+ let used = 0, k = 0;
261
+ for (let i = v.top; i < doc.lines.length; i++) {
262
+ used += wrapRows(doc.lines[i].text, tw).length;
263
+ if (used > rows)
264
+ break;
265
+ k++;
266
+ }
267
+ return Math.max(k, Math.min(1, doc.lines.length - v.top));
268
+ }
269
+ /** Marks as read to the end every document whose last line is on screen now. `height` as in `viewerKey`. */
270
+ export function settle(v, height) {
271
+ const doc = cur(v);
272
+ if (!doc || v.readToEnd[v.file])
273
+ return v;
274
+ if (v.top + linesOnScreen(v, rowsFor(doc, height)) < doc.lines.length)
275
+ return v;
276
+ const readToEnd = v.readToEnd.slice();
277
+ readToEnd[v.file] = true;
278
+ return { ...v, readToEnd };
279
+ }
280
+ /** The viewer for freshly loaded documents; the first screen counts as seen. */
281
+ export function openViewer(o, height) {
282
+ const v = {
283
+ title: o.title, docs: o.docs, file: 0, top: 0, wrap: false, readToEnd: o.docs.map(() => false), artifact: o.artifact, sha: o.sha,
284
+ ...(o.binding !== undefined ? { binding: { hash: o.binding, current: true } } : {}),
285
+ };
286
+ return settle(v, height);
287
+ }
288
+ /** Records the document area's width (wrapping needs it to know what is on screen). */
289
+ export function sized(v, caps, height) {
290
+ const g = geometry(caps, height);
291
+ return v.width === g.width ? v : settle({ ...v, width: g.width }, g.rows);
292
+ }
293
+ function findHits(docs, query) {
294
+ const q = query.toLowerCase(), hits = [];
295
+ if (q === '')
296
+ return hits;
297
+ for (let f = 0; f < docs.length; f++) {
298
+ const lines = docs[f].lines;
299
+ for (let i = 0; i < lines.length; i++) {
300
+ if (lines[i].text.toLowerCase().includes(q)) {
301
+ hits.push({ file: f, line: i });
302
+ if (hits.length >= MAX_HITS)
303
+ return hits;
304
+ }
305
+ }
306
+ }
307
+ return hits;
308
+ }
309
+ function toHit(v, at, height) {
310
+ const s = v.search;
311
+ const hit = s?.hits[at];
312
+ if (!s || !hit)
313
+ return v;
314
+ const doc = v.docs[hit.file], rows = rowsFor(doc, height);
315
+ const inView = hit.file === v.file && hit.line >= v.top && hit.line < v.top + rows;
316
+ const top = inView ? v.top : clamp(hit.line - Math.floor(rows / 3), 0, Math.max(0, doc.lines.length - rows));
317
+ return { ...v, file: hit.file, top, search: { ...s, at } };
318
+ }
319
+ function typed(v, query, height) {
320
+ const s = v.search;
321
+ const hits = findHits(v.docs, query);
322
+ return toHit({ ...v, search: { ...s, query, hits, at: 0 } }, 0, height);
323
+ }
324
+ /** The last top from which scrolling makes sense: unwrapped, the one that fills the screen; wrapped, the last line itself. */
325
+ function endTop(v, doc, rows) {
326
+ const len = doc?.lines.length ?? 0;
327
+ if (!doc || !v.wrap || v.width === undefined)
328
+ return Math.max(0, len - rows);
329
+ const tw = Math.max(1, v.width - gutterW(doc));
330
+ let used = 0, top = len;
331
+ while (top > 0) {
332
+ used += wrapRows(doc.lines[top - 1].text, tw).length;
333
+ if (used > rows)
334
+ break;
335
+ top--;
336
+ }
337
+ return Math.max(0, Math.min(len - 1, top));
338
+ }
339
+ function oneKey(v, key, height) {
340
+ const doc = cur(v);
341
+ const rows = rowsFor(doc, height);
342
+ const maxTop = endTop(v, doc, rows);
343
+ const s = v.search;
344
+ if (s?.typing) {
345
+ if (key.name === 'esc') {
346
+ const { search: _s, ...rest } = v;
347
+ return { v: rest };
348
+ }
349
+ if (key.name === 'enter')
350
+ return { v: s.query === '' ? (({ search: _s, ...rest }) => rest)(v) : { ...v, search: { ...s, typing: false } } };
351
+ if (key.name === 'backspace')
352
+ return { v: typed(v, [...s.query].slice(0, -1).join(''), height) };
353
+ if (key.name === 'char' && [...s.query].length < MAX_QUERY)
354
+ return { v: typed(v, s.query + key.ch, height) };
355
+ if (key.name === 'paste') {
356
+ const add = neutralize(key.text, { singleLine: true }).text;
357
+ return { v: typed(v, [...(s.query + add)].slice(0, MAX_QUERY).join(''), height) };
358
+ }
359
+ return { v };
360
+ }
361
+ const to = (top) => ({ v: { ...v, top: clamp(top, 0, maxTop) } });
362
+ const file = (f) => (f < 0 || f >= v.docs.length || f === v.file ? { v } : { v: { ...v, file: f, top: 0 } });
363
+ switch (key.name) {
364
+ case 'esc':
365
+ if (s) {
366
+ const { search: _s, ...rest } = v;
367
+ return { v: rest };
368
+ }
369
+ return { v, close: true };
370
+ case 'down': return to(v.top + 1);
371
+ case 'up': return to(v.top - 1);
372
+ case 'pagedown': return to(v.top + Math.max(1, rows - 1));
373
+ case 'pageup': return to(v.top - Math.max(1, rows - 1));
374
+ case 'home': return to(0);
375
+ case 'end': return to(maxTop);
376
+ case 'char': break;
377
+ default: return { v };
378
+ }
379
+ switch (key.ch) {
380
+ case 'q': return { v, close: true };
381
+ case 'j': return to(v.top + 1);
382
+ case 'k': return to(v.top - 1);
383
+ case 'g': return to(0);
384
+ case 'G': return to(maxTop);
385
+ case 'w': return { v: { ...v, wrap: !v.wrap } };
386
+ case '/': return { v: { ...v, search: { query: '', typing: true, hits: [], at: 0 } } };
387
+ case 'n':
388
+ case 'N': {
389
+ const fwd = key.ch === 'n';
390
+ if (s && s.hits.length > 0)
391
+ return { v: toHit(v, (s.at + (fwd ? 1 : s.hits.length - 1)) % s.hits.length, height) };
392
+ if (s)
393
+ return { v };
394
+ return file(v.file + (fwd ? 1 : -1));
395
+ }
396
+ default: return { v };
397
+ }
398
+ }
399
+ /**
400
+ * Applies the keys of one chunk. `height` is the number of document rows on screen before the one-line warning of a
401
+ * file with neutralised characters (`geometry(caps, rows).rows`). A document is read to the end once its last line was on screen.
402
+ */
403
+ export function viewerKey(v, chunk, height) {
404
+ let cur_ = v;
405
+ for (const key of chunk.keys) {
406
+ const r = oneKey(cur_, key, height);
407
+ if (r.close)
408
+ return { v: cur_, close: true };
409
+ cur_ = settle(r.v, height);
410
+ }
411
+ return { v: cur_ };
412
+ }
413
+ // ---- rendering ----------------------------------------------------------------------------------------------------
414
+ const minus = (caps) => (caps.charset === 'utf8' ? '−' : '-');
415
+ const counts = (a, r, caps) => [a > 0 ? `+${a}` : '', r > 0 ? `${minus(caps)}${r}` : ''].filter((x) => x !== '').join(' ');
416
+ /** A translated string on an ASCII terminal: the typographic characters of the catalogs get their ASCII twins. */
417
+ const tx = (s, caps) => (caps.charset === 'utf8' ? s : s.replaceAll('\u00b7', '-').replaceAll('\u2014', '-').replaceAll('\u2026', '...'));
418
+ const sep = (caps) => ` ${mark('sep', caps)} `;
419
+ function percent(doc, top) {
420
+ return doc.lines.length === 0 ? 0 : Math.round(100 * top / doc.lines.length);
421
+ }
422
+ function lineRows(v, doc, caps, rows, width) {
423
+ const out = [];
424
+ const nw = numW(doc), gw = gutterW(doc), num = numbered(doc), tw = Math.max(1, width - gw);
425
+ const hit = v.search?.hits[v.search.at];
426
+ const sign = (k) => (k === 'add' ? '+' : k === 'del' ? minus(caps) : ' ');
427
+ const n = (x) => (x === undefined ? ' '.repeat(nw) : String(x).padStart(nw));
428
+ for (let i = v.top; i < doc.lines.length && out.length < rows; i++) {
429
+ const L = doc.lines[i];
430
+ let text = L.text;
431
+ if (caps.charset !== 'utf8' && doc.binary && L.kind === 'meta' && text === t('dashboard.viewer.binary'))
432
+ text = text.replace('—', '-');
433
+ const here = hit !== undefined && hit.file === v.file && hit.line === i;
434
+ const cursor = here ? mark('cursor', caps) : ' ';
435
+ if (L.kind === 'hunk' || L.kind === 'meta') {
436
+ const body = v.wrap ? wrapRows(tx(text, caps), width - 2) : [cutLine(tx(text, caps), width - 2, caps)];
437
+ body.forEach((seg, k) => { if (out.length < rows)
438
+ out.push(pad(`${k === 0 ? cursor : ' '} ${L.kind === 'hunk' ? paint('cyan', seg, caps) : paint('muted', seg, caps)}`, width)); });
439
+ continue;
440
+ }
441
+ const segs = v.wrap ? wrapRows(text, tw) : [cutLine(text, tw, caps)];
442
+ segs.forEach((seg, k) => {
443
+ if (out.length >= rows)
444
+ return;
445
+ const lead = k === 0 ? cursor : ' ';
446
+ const gutter = num ? `${lead} ${k === 0 ? n(L.new) : n(undefined)} ` : `${lead} ${k === 0 ? n(L.old) : n(undefined)} ${k === 0 ? n(L.new) : n(undefined)} ${k === 0 ? sign(L.kind) : ' '} `;
447
+ const g = paint('muted', gutter, caps);
448
+ if (L.kind === 'add' || L.kind === 'del') {
449
+ const body = paint(L.kind === 'add' ? 'green' : 'red', pad(seg, tw), caps);
450
+ out.push(lineBg(L.kind, g + body, caps));
451
+ }
452
+ else
453
+ out.push(g + seg);
454
+ });
455
+ }
456
+ return out;
457
+ }
458
+ function header(v, caps) {
459
+ const cols = caps.columns;
460
+ const lead = ` ${caps.charset === 'utf8' ? '▙' : '#'} `;
461
+ const a = v.docs.reduce((x, d) => x + d.added, 0), r = v.docs.reduce((x, d) => x + d.removed, 0);
462
+ const right = [tn('dashboard.viewer.filesCount', v.docs.length), counts(a, r, caps)].filter((x) => x !== '').join(' ');
463
+ let room = Math.max(0, cols - displayWidth(lead) - displayWidth(right) - 1);
464
+ const title = cut(tx(v.title, caps), room, ellipsis(caps));
465
+ room -= displayWidth(title);
466
+ let bind = '';
467
+ if (v.binding && room > displayWidth(sep(caps))) {
468
+ const word = v.binding.current
469
+ ? `${t('dashboard.viewer.waiting', { hash: neutralize(v.binding.hash.slice(0, 12), { singleLine: true }).text })} ${glyph('done', caps)} ${t('dashboard.viewer.current')}`
470
+ : `${glyph('failed', caps)} ${t('dashboard.viewer.stale')}`;
471
+ const shown = cut(tx(word, caps), room - displayWidth(sep(caps)), ellipsis(caps));
472
+ bind = sep(caps) + paint(v.binding.current ? 'green' : 'red', shown, caps);
473
+ }
474
+ const left = paint('mint', lead, caps) + bold(title, caps) + bind;
475
+ const used = displayWidth(lead) + displayWidth(title) + displayWidth(bind);
476
+ return left + ' '.repeat(Math.max(1, cols - used - displayWidth(right))) + paint('muted', right, caps);
477
+ }
478
+ function footer(v, caps) {
479
+ const s = v.search;
480
+ const keys = [
481
+ ['j k', t('dashboard.viewer.key.scroll')], ['n N', s ? t('dashboard.viewer.key.match') : t('dashboard.viewer.key.file')],
482
+ ['/', t('dashboard.viewer.key.search')], ['w', t('dashboard.viewer.key.wrap')], ['p', t('dashboard.viewer.key.approval')], ['q', t('dashboard.viewer.key.back')],
483
+ ];
484
+ let right = '';
485
+ if (v.notice)
486
+ right = tx(v.notice, caps);
487
+ else if (s) {
488
+ const q = `/${s.query}${s.typing ? mark('caret', caps) : ''}`;
489
+ right = s.hits.length > 0 ? `${q} ${s.at + 1}/${s.hits.length}` : s.query === '' ? q : `${q} ${t('dashboard.viewer.searchNone')}`;
490
+ }
491
+ return renderFooter(keys, right, caps, v.notice ? 'amber' : 'muted');
492
+ }
493
+ function filesBody(v, width, rows, caps) {
494
+ const out = [];
495
+ const list = Math.max(1, rows - 5);
496
+ const start = clamp(v.file - Math.floor(list / 2), 0, Math.max(0, v.docs.length - list));
497
+ for (let i = start; i < Math.min(v.docs.length, start + list); i++) {
498
+ const d = v.docs[i];
499
+ const c = counts(d.added, d.removed, caps);
500
+ const warn = d.marked > 0 ? `${mark('warn', caps)} ` : '';
501
+ const lead = `${i === v.file ? mark('cursor', caps) : ' '} ${warn}`;
502
+ const room = Math.max(1, width - displayWidth(lead) - (c === '' ? 0 : displayWidth(c) + 1));
503
+ const name = cutNeutral(d.name, room, { ascii: caps.charset !== 'utf8' });
504
+ const gap = ' '.repeat(Math.max(1, width - displayWidth(lead) - displayWidth(name) - displayWidth(c)));
505
+ out.push(paint(d.marked > 0 ? 'red' : 'muted', lead, caps) + (i === v.file ? bold(name, caps) : name) + (c === '' ? '' : gap + paint('muted', c, caps)));
506
+ }
507
+ const a = v.docs.reduce((x, d) => x + d.added, 0), r = v.docs.reduce((x, d) => x + d.removed, 0);
508
+ const read = v.readToEnd.filter(Boolean).length;
509
+ out.push('', paint('muted', cut(`${tn('dashboard.viewer.filesCount', v.docs.length)}${a + r > 0 ? sep(caps) + counts(a, r, caps) : ''}`, width, ellipsis(caps)), caps), '');
510
+ out.push(cut(tx(t('dashboard.viewer.readCount', { k: read, n: v.docs.length }), caps), width, ellipsis(caps)));
511
+ out.push(paint(v.readToEnd[v.file] ? 'green' : 'muted', cut(t(v.readToEnd[v.file] ? 'dashboard.viewer.toEndYes' : 'dashboard.viewer.toEndNo'), width, ellipsis(caps)), caps));
512
+ return out;
513
+ }
514
+ /** The viewer screen: exactly `height` lines, each within `caps.columns`; everything shown is already neutral. */
515
+ export function renderViewer(v, caps, height) {
516
+ const g = geometry(caps, height);
517
+ const doc = cur(v);
518
+ const base = g.rows - (doc && doc.marked > 0 ? 1 : 0);
519
+ const body = [];
520
+ if (doc) {
521
+ if (doc.marked > 0)
522
+ body.push(paint('red', cut(`${mark('warn', caps)} ${tn('dashboard.viewer.warn', doc.marked)}`, g.width, ellipsis(caps)), caps));
523
+ body.push(...lineRows(v, doc, caps, Math.max(1, base), g.width));
524
+ }
525
+ const stats = doc ? [counts(doc.added, doc.removed, caps), `${percent(doc, v.top)} %`].filter((x) => x !== '').join(sep(caps)) : '';
526
+ let lines;
527
+ if (g.wide) {
528
+ const mid = height - 2;
529
+ const left = panel({ title: t('dashboard.viewer.files'), right: `${Math.min(v.file + 1, v.docs.length)}/${v.docs.length}`, body: filesBody(v, g.listW - 4, mid - 2, caps), width: g.listW, height: mid, focused: false }, caps);
530
+ const right = panel({ title: doc?.name ?? '', ...(stats ? { right: stats } : {}), body, width: caps.columns - g.listW - 1, height: mid, focused: true }, caps);
531
+ lines = [header(v, caps), ...left.map((l, i) => `${l} ${right[i] ?? ''}`), footer(v, caps)];
532
+ }
533
+ else {
534
+ const rt = stats;
535
+ const head = `${Math.min(v.file + 1, v.docs.length)}/${v.docs.length} ${doc?.name ?? ''}`;
536
+ const room = Math.max(0, caps.columns - displayWidth(rt) - 1);
537
+ const h2 = cutNeutral(head, room, { ascii: caps.charset !== 'utf8' });
538
+ const fileLine = paint('mint', h2, caps) + ' '.repeat(Math.max(1, caps.columns - displayWidth(h2) - displayWidth(rt))) + paint('muted', rt, caps);
539
+ lines = [header(v, caps), fileLine, ...body, footer(v, caps)];
540
+ while (lines.length < height)
541
+ lines.splice(lines.length - 1, 0, '');
542
+ if (lines.length > height)
543
+ lines = [...lines.slice(0, height - 1), lines.at(-1)];
544
+ }
545
+ const out = [];
546
+ for (let i = 0; i < height; i++)
547
+ out.push(clip(lines[i] ?? '', caps.columns));
548
+ return out;
549
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The Events panel body: newest first, `HH:MM:SS subject text`, exactly `height` lines. An event that carried
3
+ * hostile characters is followed by a red line saying how many were neutralised (AC-4: counted, never silent); the
4
+ * count of lines the reader could not parse and the "older events not shown" notice sit at the bottom. Strings arrive
5
+ * neutral from the model and are re-neutralised here (idempotent). No percentage, no bar. Pure.
6
+ */
7
+ import { tn, t } from "../../i18n/index.js";
8
+ import { displayWidth } from "../../i18n/width.js";
9
+ import { n } from "../neutral.js";
10
+ import { clock, cut, pad } from "../text.js";
11
+ import { ellipsis, mark, paint } from "../tokens.js";
12
+ const SUBJECT_MAX = 12;
13
+ export function renderEvents(lines, o, caps) {
14
+ const { height, width } = o;
15
+ if (height <= 0)
16
+ return [];
17
+ const more = ellipsis(caps);
18
+ // Notices at the bottom, kept when there is room for them and at least one event line.
19
+ const notes = [];
20
+ if (o.skipped > 0)
21
+ notes.push(paint('amber', cut(tn('dashboard.events.skipped', o.skipped), width, more), caps));
22
+ if (o.cut)
23
+ notes.push(paint('muted', cut(t('dashboard.events.cut'), width, more), caps));
24
+ const room = height - (height > notes.length ? notes.length : 0);
25
+ const shownNotes = height > notes.length ? notes : [];
26
+ const visible = lines.slice(Math.max(0, o.offset));
27
+ const subjects = visible.slice(0, Math.max(1, height)).map((l) => displayWidth(n(l.subject)));
28
+ const sw = Math.min(SUBJECT_MAX, Math.max(0, ...subjects));
29
+ const out = [];
30
+ for (const l of visible) {
31
+ if (out.length >= room)
32
+ break;
33
+ const time = clock(l.at);
34
+ const head = `${time} ${pad(cut(n(l.subject), sw, more), sw)} `;
35
+ const textRoom = Math.max(0, width - displayWidth(head));
36
+ const text = cut(n(l.text), textRoom, more);
37
+ out.push(`${paint('muted', head, caps)}${l.tone ? paint(l.tone, text, caps) : text}`);
38
+ if (l.marked > 0 && out.length < room) {
39
+ const indent = ' '.repeat(Math.min(displayWidth(head), Math.max(0, width - 1)));
40
+ out.push(indent + paint('red', cut(`${mark('warn', caps)} ${tn('dashboard.events.marked', l.marked)}`, Math.max(0, width - displayWidth(indent)), more), caps));
41
+ }
42
+ }
43
+ while (out.length < room)
44
+ out.push('');
45
+ return [...out.slice(0, room), ...shownNotes];
46
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The help overlay (`?`): the dashboard's key table and the reminder that no key approves. The table lives here and
3
+ * the loop (dashboard.ts) is tested against it, so help cannot name a key the loop ignores. Pure.
4
+ */
5
+ import { t } from "../../i18n/index.js";
6
+ import { displayWidth } from "../../i18n/width.js";
7
+ import { bold } from "../tokens.js";
8
+ import { wrap } from "../text.js";
9
+ import { panel } from "./panel.js";
10
+ /** Every key the dashboard acts on; `label` is what help says it does. Upper case equals lower case except `G`. */
11
+ export const KEY_TABLE = [
12
+ { keys: 'r', label: () => t('dashboard.frame.key.runs') },
13
+ { keys: 'a', label: () => t('dashboard.frame.key.agents') },
14
+ { keys: 'l', label: () => t('dashboard.frame.key.log') },
15
+ { keys: 'd', label: () => t('dashboard.frame.key.diff') },
16
+ { keys: 'v', label: () => t('dashboard.frame.key.verify') },
17
+ { keys: 'p', label: () => t('dashboard.frame.key.approvals') },
18
+ { keys: '?', label: () => t('dashboard.frame.key.help') },
19
+ { keys: 'q', label: () => t('dashboard.frame.key.quit') },
20
+ { keys: 'Tab', label: () => t('dashboard.help.next') },
21
+ { keys: 'Shift+Tab', label: () => t('dashboard.help.prev') },
22
+ { keys: 'j k', label: () => t('dashboard.help.move') },
23
+ { keys: 'g G', label: () => t('dashboard.help.ends') },
24
+ { keys: 'PgUp PgDn', label: () => t('dashboard.help.page') },
25
+ { keys: 'Esc', label: () => t('dashboard.help.close') },
26
+ ];
27
+ /** The viewer's keys (the diff and artifact viewer); the loop and the viewer act on exactly these. */
28
+ export const VIEWER_KEY_TABLE = [
29
+ { keys: 'j k', label: () => t('dashboard.help.move') },
30
+ { keys: 'g G', label: () => t('dashboard.help.ends') },
31
+ { keys: 'PgUp PgDn', label: () => t('dashboard.help.page') },
32
+ { keys: '/', label: () => t('dashboard.help.search') },
33
+ { keys: 'n N', label: () => t('dashboard.help.fileMatch') },
34
+ { keys: 'w', label: () => t('dashboard.help.wrap') },
35
+ { keys: 'd', label: () => t('dashboard.frame.key.diff') },
36
+ { keys: 'v', label: () => t('dashboard.frame.key.verify') },
37
+ { keys: 'p', label: () => t('dashboard.frame.key.approvals') },
38
+ { keys: '?', label: () => t('dashboard.frame.key.help') },
39
+ { keys: 'q Esc', label: () => t('dashboard.help.back') },
40
+ ];
41
+ /** The overlay box, at most `width` columns wide (52 at most); its height is its content. */
42
+ export function renderHelp(screen, width, caps, here = false) {
43
+ const w = Math.max(1, Math.min(width, 52)), inner = Math.max(1, w - 4);
44
+ const entries = (screen === 'viewer' ? VIEWER_KEY_TABLE : KEY_TABLE).map((e) => ({ plain: `${e.keys} ${e.label()}`, styled: `${bold(e.keys, caps)} ${e.label()}` }));
45
+ const body = [];
46
+ let line = { plain: '', styled: '' };
47
+ const flush = () => { if (line.plain !== '')
48
+ body.push(line.styled); line = { plain: '', styled: '' }; };
49
+ for (const e of entries) {
50
+ if (line.plain !== '' && displayWidth(line.plain) + 3 + displayWidth(e.plain) > inner)
51
+ flush();
52
+ line = line.plain === '' ? e : { plain: `${line.plain} ${e.plain}`, styled: `${line.styled} ${e.styled}` };
53
+ }
54
+ flush();
55
+ if (w >= 48)
56
+ body.push('');
57
+ body.push(...wrap(t('dashboard.help.hash'), inner), ...wrap(t(here ? 'dashboard.help.center' : 'dashboard.help.route'), inner));
58
+ return panel({ title: t('dashboard.help.title'), body, width: w, height: body.length + 2, focused: true }, caps);
59
+ }