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,500 @@
1
+ import { artifactSha, createWatcher, freshApproval, freshPending, loadDocs } from "./dashboard-data.js";
2
+ import { approvalForm, approvalRecord, spawnApprove } from "./dashboard-approve.js";
3
+ import { t } from "./i18n/index.js";
4
+ import { n, nLog } from "./tui/neutral.js";
5
+ import { clock } from "./tui/text.js";
6
+ import { glyph, mark } from "./tui/tokens.js";
7
+ import { keyDecoder } from "./tui/keys.js";
8
+ import { withTerminal } from "./tui/screen.js";
9
+ import { geometry, openViewer, settle, sized, viewerKey } from "./tui/components/diff-viewer.js";
10
+ import { initialUi, layoutMode, renderDashboard } from "./tui/components/dashboard-frame.js";
11
+ const ORDER = ['pipeline', 'approvals', 'runs', 'agents', 'events'];
12
+ const TABBED = ['runs', 'agents', 'events'];
13
+ const PAGE = 10;
14
+ export const POLL_MS = 500;
15
+ export const TICK_MS = 1000;
16
+ export const FLUSH_MS = 50;
17
+ /** How far each panel's cursor (Runs) or offset (Agents, Events) can go; Pipeline and Approvals do not scroll. */
18
+ function last(focus, m) {
19
+ switch (focus) {
20
+ case 'runs': return Math.max(0, m.runs.length - 1);
21
+ case 'agents': return Math.max(0, m.fixed.squad.length - 1);
22
+ case 'events': return Math.max(0, (m.selected?.events.length ?? 0) - 1);
23
+ default: return 0;
24
+ }
25
+ }
26
+ const focused = (ui, focus) => ({ ...ui, focus, ...(TABBED.includes(focus) ? { tab: focus } : {}) });
27
+ function keyOf(key) {
28
+ switch (key.name) {
29
+ case 'char': return key.ch === 'G' ? 'G' : key.ch.toLowerCase();
30
+ case 'up': return 'k';
31
+ case 'down': return 'j';
32
+ case 'home': return 'g';
33
+ case 'end': return 'G';
34
+ default: return undefined;
35
+ }
36
+ }
37
+ /** One key in the viewer: typing a search query owns every key; otherwise `? d v p q` here and the rest to the viewer. */
38
+ function viewerStep(ui, key, effects, vh, multi) {
39
+ const v = ui.viewer;
40
+ if (key.name === 'ctrl-c') {
41
+ if (ui.help)
42
+ return { ...ui, help: false };
43
+ effects.push({ kind: 'quit' });
44
+ return ui;
45
+ }
46
+ const isChar = key.name === 'char';
47
+ if (ui.help)
48
+ return key.name === 'esc' || (isChar && (key.ch === '?' || key.ch === 'q')) ? { ...ui, help: false } : ui;
49
+ if (!v.search?.typing && isChar) {
50
+ if (key.ch === '?')
51
+ return { ...ui, help: true };
52
+ if (key.ch === 'd') {
53
+ effects.push({ kind: 'open-viewer', which: 'review' });
54
+ return ui;
55
+ }
56
+ if (key.ch === 'v') {
57
+ effects.push({ kind: 'open-viewer', which: 'verify' });
58
+ return ui;
59
+ }
60
+ if (key.ch === 'p') {
61
+ if (!multi)
62
+ effects.push({ kind: 'open-center' });
63
+ return ui;
64
+ } // alone in its chunk, never type-ahead
65
+ }
66
+ const r = viewerKey(v, { keys: [key], multi: false }, vh);
67
+ if (r.close) {
68
+ const { viewer: _v, ...rest } = ui;
69
+ return { ...rest, screen: 'main' };
70
+ }
71
+ const { notice: _n, ...nv } = r.v;
72
+ return { ...ui, viewer: nv };
73
+ }
74
+ /** Apply one key; `effects` collects what the loop must do. */
75
+ function step(ui, key, m, effects, vh, multi) {
76
+ if (ui.quit) {
77
+ // the quit question: q (or Ctrl+C) quits, Esc stays, nothing else acts
78
+ if (key.name === 'esc') {
79
+ const { quit: _q, ...rest } = ui;
80
+ return rest;
81
+ }
82
+ if (key.name === 'ctrl-c' || (key.name === 'char' && key.ch.toLowerCase() === 'q'))
83
+ effects.push({ kind: 'quit', confirmed: true });
84
+ return ui;
85
+ }
86
+ if (ui.screen === 'center')
87
+ return ui; // the form owns the keyboard (the loop hands it the raw chunks)
88
+ if (ui.screen === 'viewer' && ui.viewer)
89
+ return viewerStep(ui, key, effects, vh, multi);
90
+ if (key.name === 'paste')
91
+ return ui;
92
+ if (key.name === 'ctrl-c') {
93
+ if (ui.help)
94
+ return { ...ui, help: false };
95
+ effects.push({ kind: 'quit' });
96
+ return ui;
97
+ }
98
+ if (key.name === 'esc') {
99
+ const { notice: _gone, ...rest } = ui;
100
+ return { ...rest, help: false };
101
+ }
102
+ const c = keyOf(key);
103
+ if (c === 'q' && key.name === 'char') {
104
+ effects.push({ kind: 'quit' });
105
+ return ui;
106
+ }
107
+ if (key.name === 'char' && c === '?')
108
+ return { ...ui, help: !ui.help };
109
+ if (ui.help)
110
+ return ui; // the overlay owns the keyboard: only ?, Esc, Ctrl+C and q act
111
+ if (key.name === 'tab' || key.name === 'backtab') {
112
+ const at = ORDER.indexOf(ui.focus);
113
+ return focused(ui, ORDER[(at + (key.name === 'tab' ? 1 : ORDER.length - 1)) % ORDER.length]);
114
+ }
115
+ if (key.name === 'char') {
116
+ if (c === 'r')
117
+ return focused(ui, 'runs');
118
+ if (c === 'a')
119
+ return focused(ui, 'agents');
120
+ if (c === 'l')
121
+ return focused(ui, 'events');
122
+ if (c === 'p') {
123
+ // the centre opens only for a key pressed alone, for a gate that waits, when this dashboard can approve
124
+ if (!multi && ui.approveHere && m.selected?.view.pending)
125
+ effects.push({ kind: 'open-center' });
126
+ return { ...ui, focus: 'approvals' };
127
+ }
128
+ if (c === 'd') {
129
+ effects.push({ kind: 'open-viewer', which: 'review' });
130
+ return ui;
131
+ }
132
+ if (c === 'v') {
133
+ effects.push({ kind: 'open-viewer', which: 'verify' });
134
+ return ui;
135
+ }
136
+ }
137
+ let delta;
138
+ let to;
139
+ if (key.name === 'pageup')
140
+ delta = -PAGE;
141
+ else if (key.name === 'pagedown')
142
+ delta = PAGE;
143
+ else if (key.name === 'char' || key.name === 'up' || key.name === 'down' || key.name === 'home' || key.name === 'end') {
144
+ if (c === 'j')
145
+ delta = 1;
146
+ else if (c === 'k')
147
+ delta = -1;
148
+ else if (c === 'g')
149
+ to = 0;
150
+ else if (c === 'G')
151
+ to = Number.MAX_SAFE_INTEGER;
152
+ }
153
+ if (delta === undefined && to === undefined)
154
+ return ui; // anything else is ignored
155
+ const max = last(ui.focus, m);
156
+ const from = Math.min(ui.pos[ui.focus], max);
157
+ const next = clampPos(to ?? from + delta, max);
158
+ if (next === ui.pos[ui.focus] && ui.pos[ui.focus] <= max)
159
+ return ui;
160
+ if (ui.focus === 'runs' && m.runs[next])
161
+ effects.push({ kind: 'select', runId: m.runs[next].runId });
162
+ return { ...ui, pos: { ...ui.pos, [ui.focus]: next } };
163
+ }
164
+ const clampPos = (v, max) => Math.max(0, Math.min(max, v));
165
+ /** The next UI state and effects for the keys of one input chunk, applied in order (a quit ends the chunk). Pure. */
166
+ export function onKey(ui, chunk, m, vh = 20) {
167
+ const effects = [];
168
+ let next = ui;
169
+ for (const key of chunk.keys) {
170
+ next = step(next, key, m, effects, vh, chunk.multi);
171
+ if (effects.some((e) => e.kind === 'quit' || e.kind === 'open-viewer' || e.kind === 'open-center'))
172
+ break;
173
+ }
174
+ return { ui: next, effects };
175
+ }
176
+ const shortOf = (runId) => { const last = runId.split('-').at(-1) ?? ''; return n(last === '' ? runId : last); };
177
+ /** Runs until `q` (or Ctrl+C); resolves 0. Signals and errors leave through withTerminal, which gives the terminal back. */
178
+ export async function runDashboard(d) {
179
+ const now = d.now ?? (() => Date.now());
180
+ const timers = d.timers ?? { setInterval: (...a) => setInterval(...a), clearInterval: (h) => { clearInterval(h); } };
181
+ const watcher = createWatcher(d.store, d.fixed, { ...(d.runId !== undefined ? { runId: d.runId } : {}), now: () => new Date(now()), ...(d.isAlive ? { isAlive: d.isAlive } : {}) });
182
+ if (d.runId === undefined) {
183
+ // newest running or waiting run, else (the watcher's choice) the newest
184
+ const pick = watcher.model().runs.find((r) => r.status === 'running' || r.status === 'waiting-approval');
185
+ if (pick)
186
+ watcher.select(pick.runId);
187
+ }
188
+ const started = [];
189
+ const code = await withTerminal(d.tty, d.signals, async (screen) => {
190
+ let caps = d.caps(d.tty.size());
191
+ let ui = { ...initialUi(), ...(d.approve ? { approveHere: true } : {}) };
192
+ const m0 = watcher.model();
193
+ const at = m0.runs.findIndex((r) => r.runId === m0.selected?.runId);
194
+ if (at > 0)
195
+ ui = { ...ui, pos: { ...ui.pos, runs: at } };
196
+ const read = d.read ?? new Set();
197
+ const decoder = keyDecoder();
198
+ let tick;
199
+ let flushTimer;
200
+ let poll;
201
+ const offs = [];
202
+ let done;
203
+ let closed = false;
204
+ let approver; // asked once per dashboard session, kept in memory only
205
+ let form;
206
+ let loopError; // set by guard(): the footer says the read failed until a poll sees a change
207
+ const draw = () => {
208
+ if (closed)
209
+ return;
210
+ const m = watcher.model();
211
+ screen.draw(renderDashboard(loopError !== undefined && m.readError === undefined ? { ...m, readError: loopError } : m, ui, caps, now()));
212
+ };
213
+ /** A key, a poll or a resize that throws keeps the last frame and says the read failed: the dashboard never dies of it. */
214
+ const guard = (f) => {
215
+ try {
216
+ f();
217
+ }
218
+ catch {
219
+ loopError = t('dashboard.data.stateInvalid');
220
+ try {
221
+ draw();
222
+ }
223
+ catch { /* the last frame stays on screen */ }
224
+ }
225
+ };
226
+ const wantsTick = () => {
227
+ const s = watcher.model().selected;
228
+ return s !== undefined && s.view.status === 'running' && s.liveness === 'live' && s.view.steps.some((st) => st.state === 'running');
229
+ };
230
+ const syncTick = () => {
231
+ if (wantsTick()) {
232
+ if (tick === undefined)
233
+ tick = timers.setInterval(draw, TICK_MS);
234
+ }
235
+ else if (tick !== undefined) {
236
+ timers.clearInterval(tick);
237
+ tick = undefined;
238
+ }
239
+ };
240
+ /** The viewer sized for this terminal, with what it has shown counted as read (a session-long Set of artifact names). */
241
+ const fitViewer = () => {
242
+ if (ui.screen !== 'viewer' || !ui.viewer)
243
+ return;
244
+ let v = sized(ui.viewer, caps, caps.rows);
245
+ v = settle(v, geometry(caps, caps.rows).rows);
246
+ if (v.docs.length > 0 && v.readToEnd.every(Boolean))
247
+ read.add(v.artifact);
248
+ ui = { ...ui, viewer: v };
249
+ };
250
+ const open = (which) => {
251
+ const id = watcher.model().selected?.runId;
252
+ const r = id === undefined ? { error: t('dashboard.viewer.noRun') } : loadDocs(d.store, id, which);
253
+ if ('error' in r) {
254
+ ui = ui.viewer ? { ...ui, viewer: { ...ui.viewer, notice: r.error } } : { ...ui, notice: r.error };
255
+ return;
256
+ }
257
+ const { notice: _n, ...rest } = ui;
258
+ ui = { ...rest, screen: 'viewer', viewer: openViewer(r, geometry(caps, caps.rows).rows) };
259
+ fitViewer();
260
+ };
261
+ // ---- the approval center and the process it starts ----------------------------------------------------------
262
+ const outcomeLine = (o) => {
263
+ const sep = ` ${mark('sep', caps)} `;
264
+ switch (o.kind) {
265
+ case 'started': return `${glyph('running', caps)} ${t('dashboard.center.started', { pid: o.pid })}`;
266
+ case 'approved': return `${glyph('done', caps)} ${t('dashboard.center.approved', { as: n(o.as), time: clock(o.at), pid: o.pid })}`;
267
+ case 'refused': return `${glyph('failed', caps)} ${t('dashboard.center.refused', { exit: n(o.exit) })}${sep}${t('dashboard.center.nothing')}`;
268
+ case 'failed': return `${glyph('failed', caps)} ${t('dashboard.center.notStarted', { message: n(o.message) })}${sep}${t('dashboard.center.nothing')}`;
269
+ }
270
+ };
271
+ /** Outside the centre, the latest process's outcome is the footer's notice; an approval recorded by any of them (`recorded`) too. */
272
+ const notify = (s, recorded = false) => { if (ui.screen !== 'center' && (recorded || started.at(-1) === s))
273
+ ui = { ...ui, notice: outcomeLine(s.outcome) }; };
274
+ /** What the store says now about a started approval: recorded → approved (the process may still run). */
275
+ const recordOf = (s) => {
276
+ const now = freshApproval(d.store, s.runId);
277
+ return approvalRecord(now.state, now.events, s, s.before);
278
+ };
279
+ const finish = (s, r) => {
280
+ s.alive = false;
281
+ if (s.outcome.kind === 'approved')
282
+ return;
283
+ const rec = recordOf(s);
284
+ if (rec)
285
+ s.outcome = { kind: 'approved', pid: s.child.pid, as: s.as, at: rec.at ?? new Date(now()).toISOString() };
286
+ else
287
+ s.outcome = { kind: 'refused', exit: r.code !== null ? String(r.code) : r.signal ?? '?', tail: (s.child?.tail() ?? '').split('\n').filter((l) => l.trim() !== '').slice(-3) };
288
+ };
289
+ /** Each poll while an approval is in flight: the store, not the exit code, says whether it was approved. */
290
+ const watch = () => {
291
+ let changed = false;
292
+ for (const s of started) {
293
+ if (s.outcome.kind !== 'started')
294
+ continue;
295
+ const rec = recordOf(s);
296
+ if (rec) {
297
+ s.outcome = { kind: 'approved', pid: s.child.pid, as: s.as, at: rec.at ?? new Date(now()).toISOString() };
298
+ notify(s, true);
299
+ changed = true;
300
+ }
301
+ }
302
+ return changed;
303
+ };
304
+ const startApprove = (f, runId, gate, expect, as) => {
305
+ const st = f.state();
306
+ const binding = st.step === 'sent' ? st.shown.binding : '';
307
+ const s = { runId, short: shortOf(runId), gate, binding, as, form: f, alive: false, outcome: { kind: 'failed', message: '' }, before: freshApproval(d.store, runId) };
308
+ started.push(s);
309
+ try {
310
+ const child = spawnApprove({ ...d.approve, runId, gate, expect, as });
311
+ s.child = child;
312
+ s.alive = true;
313
+ s.outcome = { kind: 'started', pid: child.pid };
314
+ void child.exited.then((r) => {
315
+ const was = s.outcome.kind;
316
+ finish(s, r);
317
+ if (!closed)
318
+ guard(() => { notify(s, was !== 'approved' && s.outcome.kind === 'approved'); draw(); });
319
+ });
320
+ }
321
+ catch (e) {
322
+ s.outcome = { kind: 'failed', message: nLog(String(e?.message ?? e)) };
323
+ }
324
+ };
325
+ const openCenter = () => {
326
+ const sel = watcher.model().selected;
327
+ const gate = sel?.view.pending?.gate;
328
+ const { viewer: _v, notice: _n, ...rest } = ui;
329
+ if (!d.approve || !sel || !gate) {
330
+ ui = { ...rest, screen: 'main', focus: 'approvals' };
331
+ return;
332
+ }
333
+ decoder.flush(); // input held from before the form: never typed into it
334
+ const runId = sel.runId;
335
+ // an approval of this run still starting (or its process still running at this gate): its outcome, never a second send
336
+ const inFlight = started.findLast((s) => s.runId === runId && (s.outcome.kind === 'started' || (s.alive && s.gate === gate)));
337
+ if (inFlight) {
338
+ form = { f: inFlight.form, runId };
339
+ ui = { ...rest, screen: 'center', focus: 'approvals', center: { render: (c, h) => inFlight.form.render(c, h, inFlight.outcome) } };
340
+ return;
341
+ }
342
+ const f = approvalForm({
343
+ runId, gate, ...(approver !== undefined ? { approver } : {}),
344
+ pending: () => freshPending(d.store, runId),
345
+ approve: (r, g, expect, as) => { startApprove(f, r, g, expect, as); },
346
+ onName: (name) => { approver = name; },
347
+ context: () => {
348
+ const m = watcher.model(), s = m.selected?.runId === runId ? m.selected : sel;
349
+ return { view: s.view, request: s.request, read, acceptedRisks: d.fixed.acceptedRisks, waiting: m.runs.filter((r) => r.status === 'waiting-approval').length };
350
+ },
351
+ now: () => new Date(now()),
352
+ });
353
+ f.open();
354
+ form = { f, runId };
355
+ ui = { ...rest, screen: 'center', focus: 'approvals', center: { render: (c, h) => f.render(c, h, started.find((s) => s.form === f)?.outcome) } };
356
+ };
357
+ const closeCenter = () => {
358
+ const f = form?.f;
359
+ form = undefined;
360
+ const { center: _c, ...rest } = ui;
361
+ ui = { ...rest, screen: 'main', focus: 'approvals' };
362
+ const st = f?.state().step;
363
+ const mine = started.find((s) => s.form === f);
364
+ if (mine)
365
+ ui = { ...ui, notice: outcomeLine(mine.outcome) };
366
+ else if (st === 'cancelled')
367
+ ui = { ...ui, notice: t('dashboard.center.cancelled') };
368
+ };
369
+ /** A raw input chunk while the centre is open: the form's, or — once the form is done — a key that closes it. */
370
+ const centerKey = (chunk) => {
371
+ const f = form.f;
372
+ if (layoutMode(caps) === 'too-small') {
373
+ f.typeAhead(chunk);
374
+ return;
375
+ } // nothing is typed blind
376
+ const st = f.state().step;
377
+ if (st === 'name' || st === 'hash') {
378
+ void f.key(chunk).catch(() => { });
379
+ draw();
380
+ return;
381
+ }
382
+ const dec = keyDecoder();
383
+ const keys = [...dec.feed(chunk), ...dec.flush()].flatMap((c) => c.keys);
384
+ const only = keys.length === 1 ? keys[0] : undefined;
385
+ if (st === 'stale' && only?.name === 'char' && only.ch.toLowerCase() === 'd') {
386
+ closeCenter();
387
+ open('review');
388
+ draw();
389
+ return;
390
+ }
391
+ const closes = keys.some((k) => k.name === 'esc' || k.name === 'ctrl-c' || (k.name === 'char' && k.ch.toLowerCase() === 'q') || (k.name === 'enter' && st !== 'sent'));
392
+ if (closes) {
393
+ closeCenter();
394
+ draw();
395
+ }
396
+ };
397
+ const apply = (chunks) => {
398
+ if (chunks.length === 0)
399
+ return;
400
+ for (const chunk of chunks) {
401
+ if (ui.screen === 'center')
402
+ break; // what follows the opening key is type-ahead: never the form's
403
+ const r = onKey(ui, chunk, watcher.model(), geometry(caps, caps.rows).rows);
404
+ ui = r.ui;
405
+ for (const e of r.effects) {
406
+ if (e.kind === 'quit') {
407
+ const live = started.find((s) => s.alive && s.child);
408
+ if (live && !e.confirmed) {
409
+ ui = { ...ui, help: false, quit: { short: live.short, pid: live.child.pid } };
410
+ continue;
411
+ }
412
+ done?.(0);
413
+ return;
414
+ }
415
+ if (e.kind === 'select')
416
+ watcher.select(e.runId);
417
+ else if (e.kind === 'open-viewer')
418
+ open(e.which);
419
+ else
420
+ openCenter();
421
+ }
422
+ fitViewer();
423
+ }
424
+ syncTick();
425
+ draw();
426
+ };
427
+ /** After a poll that saw a change: is the viewer's tree still the one waiting for approval, and its artifact unchanged? */
428
+ const recheck = () => {
429
+ const v = ui.viewer, id = watcher.model().selected?.runId;
430
+ if (ui.screen !== 'viewer' || !v?.binding || id === undefined)
431
+ return;
432
+ const current = freshPending(d.store, id)?.binding === v.binding.hash && artifactSha(d.store, id, v.artifact) === v.sha;
433
+ if (current !== v.binding.current)
434
+ ui = { ...ui, viewer: { ...v, binding: { ...v.binding, current } } };
435
+ };
436
+ const clearFlush = () => { if (flushTimer !== undefined) {
437
+ timers.clearInterval(flushTimer);
438
+ flushTimer = undefined;
439
+ } };
440
+ try {
441
+ draw();
442
+ syncTick();
443
+ return await new Promise((resolve) => {
444
+ done = resolve;
445
+ poll = timers.setInterval(() => guard(() => {
446
+ let changed = false;
447
+ try {
448
+ changed = watcher.poll();
449
+ }
450
+ catch { /* an unreadable store is the watcher's business; keep the last frame */ }
451
+ if (changed) {
452
+ loopError = undefined;
453
+ recheck();
454
+ syncTick();
455
+ }
456
+ const outcome = watch();
457
+ if (ui.screen === 'center')
458
+ form?.f.refresh(); // the binding re-read each poll (shown, never acted on)
459
+ if (changed || outcome || ui.screen === 'center')
460
+ draw();
461
+ }), POLL_MS);
462
+ offs.push(d.tty.onData((chunk) => guard(() => {
463
+ if (ui.screen === 'center' && form) {
464
+ clearFlush();
465
+ centerKey(chunk);
466
+ return;
467
+ }
468
+ apply(decoder.feed(chunk));
469
+ clearFlush();
470
+ flushTimer = timers.setInterval(() => guard(() => { clearFlush(); apply(decoder.flush()); }), FLUSH_MS);
471
+ })));
472
+ offs.push(d.tty.onResize(() => guard(() => {
473
+ caps = d.caps(d.tty.size());
474
+ fitViewer();
475
+ screen.invalidate();
476
+ draw();
477
+ })));
478
+ });
479
+ }
480
+ finally {
481
+ closed = true;
482
+ for (const off of offs) {
483
+ try {
484
+ off();
485
+ }
486
+ catch { /* nothing to undo */ }
487
+ }
488
+ if (poll !== undefined)
489
+ timers.clearInterval(poll);
490
+ if (tick !== undefined)
491
+ timers.clearInterval(tick);
492
+ clearFlush();
493
+ }
494
+ });
495
+ // the terminal is back: say which approval processes go on, and where their output is
496
+ for (const s of started)
497
+ if (s.alive && s.child)
498
+ d.err?.(t('dashboard.childContinues', { run: n(s.runId), pid: s.child.pid, log: n(s.child.logPath) }));
499
+ return code;
500
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Per-repository console history (↑/↓): `<repo store>/console-history`, mode 0600, the last 500 lines.
3
+ * Only `/` commands are ever kept: a name typed at the approval name prompt, a retyped hash and free text never are.
4
+ */
5
+ import { chmodSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ const MAX = 500;
8
+ const CONTROL = /[\x00-\x1f\x7f]/;
9
+ const keep = (l) => l.startsWith('/') && !CONTROL.test(l);
10
+ const fileOf = (store) => join(store.root, 'console-history');
11
+ /** Oldest first. A missing or unreadable file is an empty history. */
12
+ export function loadHistory(store) {
13
+ try {
14
+ return existsSync(fileOf(store)) ? readFileSync(fileOf(store), 'utf8').split('\n').filter(keep).slice(-MAX) : [];
15
+ }
16
+ catch {
17
+ return [];
18
+ }
19
+ }
20
+ export function appendHistory(store, line) {
21
+ const l = line.trim();
22
+ if (!keep(l))
23
+ return;
24
+ try {
25
+ const f = fileOf(store);
26
+ writeFileSync(f, [...loadHistory(store), l].slice(-MAX).join('\n') + '\n', { mode: 0o600 });
27
+ chmodSync(f, 0o600);
28
+ }
29
+ catch { /* history is a convenience: never breaks the console */ }
30
+ }
31
+ /** readline records every line it reads (the newest first) before emitting it: take back what is not a command. */
32
+ export function scrubReadlineHistory(rl, line) {
33
+ if (!keep(line.trim()) && rl.history?.[0] === line)
34
+ rl.history.shift();
35
+ }
@@ -0,0 +1,18 @@
1
+ import { userInfo } from 'node:os';
2
+ import { isAbsolute } from 'node:path';
3
+ /**
4
+ * The home directory, only when it is an absolute path: `$HOME`, else the account's home (passwd), else undefined.
5
+ * `os.homedir()` is not enough: it returns `$HOME` as it is, so an empty, `.` or relative HOME pointed the probe and
6
+ * the installer at the current directory — the repository, whose `.npmrc` or `.claude/` would then apply.
7
+ */
8
+ export function absoluteHome(env = process.env, account = () => userInfo().homedir) {
9
+ if (env.HOME && isAbsolute(env.HOME))
10
+ return env.HOME;
11
+ try {
12
+ const h = account();
13
+ return h && isAbsolute(h) ? h : undefined;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ } // no passwd entry
18
+ }