staysfixed 0.13.0 → 0.14.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,59 @@ numbers follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.14.0] — 2026-09-02
10
+
11
+ Four defects, every one of them found by WATCHING this tool work rather than by reading it.
12
+ The owner could not find its live window, then recorded four minutes of it running and the
13
+ recording contained three faults nobody had noticed in a month of testing.
14
+
15
+ ### A system dialog can no longer stall a run in silence
16
+
17
+ A real check froze for two of its four minutes behind a macOS alert — *"A keychain cannot be
18
+ found to store 'Terminal Deck Key'"* — while a journey waited for a person who was never going
19
+ to arrive. The run finished and reported one journey with no answer, and never said why.
20
+
21
+ Every adapter here starts the product under test in a throwaway settings folder, which is
22
+ exactly the condition that makes an application ask the operating system for something it has
23
+ never been granted. These dialogs are a normal consequence of how this tool works, so they are
24
+ its problem.
25
+
26
+ - Modal boxes belonging to an application **this run started** are noticed, closed and reported
27
+ with their own words. Nothing else is touched.
28
+ - The button pressed comes from a fixed list that decline, dismiss or close — never one that
29
+ grants, resets, deletes or agrees. On the alert that started this, the other button was
30
+ *Reset To Defaults*, on a keychain, and it was the default.
31
+ - A dialog with nothing safe on it is **left exactly as it is** and named in the result instead.
32
+ - `AXModal` is the test, not the subrole: an ordinary Terminal window reports the same
33
+ `AXDialog` subrole the real alert does, so matching on that would send this tool hunting for
34
+ buttons to press in somebody's actual work.
35
+
36
+ ### The report survives the findings
37
+
38
+ When a verdict landed, everything the run had spent four minutes drawing — the walk, every
39
+ journey and its address count, the wobble, what survived, what was not checked — vanished. The
40
+ footer holding "Needs a person" had no cap, so seventeen findings grew it past the height of the
41
+ panel and squeezed the body to **eighteen pixels holding 41,115** of content.
42
+
43
+ The footer is capped and its list scrolls inside itself; the body keeps a floor. Held both ways
44
+ by a guard, including against the first over-correction, which lost the same detail from the
45
+ other end by letting the footer collapse to its label.
46
+
47
+ ### The live window says that it exists
48
+
49
+ `--watch` is off by default, the window opens behind your work on purpose, and nothing anywhere
50
+ ever mentioned it. Three correct decisions adding up to a feature nobody could find. `check` now
51
+ says one line on a project that has a screen: that the window is there and how to open it, or,
52
+ when it is open, which side of the screen it went to.
53
+
54
+ ### Something added is no longer described as a deletion
55
+
56
+ An escalation read *"SessionBar is there now and was not before"* and then, one line below,
57
+ *"Say whether that deletion is meant to happen."* A sealed class says what a change TOUCHES; it
58
+ says nothing about which way it moved, and the sentence a person is asked to rule on has to
59
+ describe what actually happened.
60
+
61
+
9
62
  ### The self-check corpus knows about the five false all-clears found on 2026-08-31
10
63
 
11
64
  Five defects were found and fixed that day, each of which could have blessed a broken build,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "staysfixed",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Prove that what already worked still works after an agent changed the code. Picture checks, guards for fixed bugs, a pre-release walkthrough, and known-good markers \u2014 as a CLI and as an MCP server.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/v2/check.js CHANGED
@@ -32,7 +32,7 @@ import { createHash } from 'node:crypto';
32
32
  import { promisify } from 'node:util';
33
33
 
34
34
  import { StaysFixedError, messageOf } from '../core/errors.js';
35
- import { warn, detail, shortPath } from '../core/log.js';
35
+ import { say, warn, detail, shortPath } from '../core/log.js';
36
36
  import { findConfigFile, rootForConfig } from '../core/paths.js';
37
37
  import { sha256 } from '../core/hash.js';
38
38
 
@@ -46,6 +46,7 @@ import { whatChanged, NOT_THE_TOOLS_OWN_FOLDER } from './rank.js';
46
46
 
47
47
  import { attachWatcher, watchOptionsFrom } from './watch/index.js';
48
48
  import { guardTheScreen, describeGuard } from './watch/focus.js';
49
+ import { watchForDialogs, describeDialogs } from './watch/dialogs.js';
49
50
  import {
50
51
  isOffScreen, moveWindowByPid, offScreen, windowBoundsByPid, withoutTakingTheScreen,
51
52
  } from './watch/window.js';
@@ -1447,7 +1448,29 @@ async function mindTheScreen(project, events) {
1447
1448
  // Nothing will appear and nobody asked for a window: there is no screen to look after.
1448
1449
  if (!wantsPanel && !couldShow) return null;
1449
1450
 
1451
+ // A WINDOW NOBODY KNOWS ABOUT IS A WINDOW THAT DOES NOT EXIST.
1452
+ //
1453
+ // This tool draws a live view of a run — surfaces, journeys ticking, the reference it is
1454
+ // measuring against, the findings as they land. It is off unless somebody types `--watch`,
1455
+ // and even then it opens BEHIND their work on purpose and never comes forward again. All
1456
+ // three of those are right on their own, and together they meant the owner ran this tool
1457
+ // for weeks and never once saw the window, because nothing anywhere told him it was there.
1458
+ // `staysfixed init` mentions it, which helps exactly once and only if you read the setup.
1459
+ //
1460
+ // So the run itself says it, once, on a project where there is something to watch.
1461
+ if (!wantsPanel) {
1462
+ say('There is a live window for this run — add --watch to open it beside what is being checked.');
1463
+ }
1464
+
1450
1465
  const guard = guardTheScreen();
1466
+ // THE BOXES THIS RUN CAUSES ARE THIS RUN'S PROBLEM.
1467
+ //
1468
+ // Every adapter starts the thing under test in a throwaway settings folder, which is exactly
1469
+ // the condition that makes an application ask the operating system for something it has never
1470
+ // been granted. On 2026-09-01 that was a keychain, and the alert it raised sat on screen for
1471
+ // two minutes of a four-minute run while a journey waited behind it for a person who was
1472
+ // never going to arrive. Only ours, only harmless buttons, and everything seen is reported.
1473
+ const dialogs = watchForDialogs({ elapsed: () => events.elapsed() });
1451
1474
  // Said under --verbose rather than always, because a person who was not interrupted
1452
1475
  // should not be told about the machinery that did not interrupt them. It is here at all
1453
1476
  // so that "the guard is running" is something anybody can see rather than take on trust.
@@ -1473,6 +1496,14 @@ async function mindTheScreen(project, events) {
1473
1496
  // AND --watch-front is somebody asking, in so many words, for this window in front.
1474
1497
  // Claiming it would have the guard undoing the flag a second after it was obeyed.
1475
1498
  onOpen: (browser) => {
1499
+ // AND SAY WHERE IT WENT. The window opens behind whatever the person is doing and
1500
+ // never asks for the screen again, which is the behaviour they asked for — but it
1501
+ // makes a window that came up correctly look exactly like one that never came up.
1502
+ // One line, at the moment it opens, is the whole difference between the two.
1503
+ say(
1504
+ `The live window is open on the ${watch.side === 'left' ? 'left' : 'right'} of your screen` +
1505
+ (watch.foreground === true ? '.' : ", behind what you are working on — it will not come forward on its own."),
1506
+ );
1476
1507
  if (browser.borrowed || watch.foreground === true) return;
1477
1508
  guard.claim(browser.name);
1478
1509
  },
@@ -1489,6 +1520,7 @@ async function mindTheScreen(project, events) {
1489
1520
  // Claimed the instant the process exists, before it has drawn anything. A moment
1490
1521
  // later and its first appearance is read as the person choosing it.
1491
1522
  guard.claim(app.name);
1523
+ dialogs.claim(app.name);
1492
1524
  events.emit({
1493
1525
  type: 'note',
1494
1526
  at: events.elapsed(),
@@ -1506,7 +1538,14 @@ async function mindTheScreen(project, events) {
1506
1538
  handingBack ??= (async () => {
1507
1539
  stopped = true;
1508
1540
  stopListening();
1541
+ // One last look before letting go: a box that came up during the final journey is the
1542
+ // one most likely to explain a missing answer, and the periodic sweep may not have
1543
+ // come round again before the run ended.
1544
+ await dialogs.sweepNow().catch(() => {});
1545
+ await dialogs.stop();
1509
1546
  await guard.release();
1547
+ const said = describeDialogs(dialogs.report());
1548
+ if (said) events.emit({ type: 'note', at: events.elapsed(), message: said });
1510
1549
  const line = describeGuard(guard.report());
1511
1550
  if (line) events.emit({ type: 'note', at: events.elapsed(), message: line });
1512
1551
  await Promise.allSettled(placing);
@@ -609,6 +609,31 @@ function buildEscalations(product, record, verdict) {
609
609
  };
610
610
  }
611
611
 
612
+ /**
613
+ * Which way a finding moved, read off the differences it stands for.
614
+ *
615
+ * A sealed class says what a change TOUCHES. It does not say what the change DID, and the
616
+ * two were treated as one thing until 2026-09-01, when a real run on a real product printed
617
+ * `"SessionBar" is there now and was not before` and then asked, one line below it, "Say
618
+ * whether that deletion is meant to happen." Nothing had been deleted. That sentence is the
619
+ * one a person is asked to rule on, and it described the opposite of what happened.
620
+ *
621
+ * So the direction is read rather than assumed. 'gone' only when something actually went
622
+ * away, 'new' only when everything is an arrival, and 'changed' for a mix or anything else —
623
+ * because a sentence that has to hedge is still better than one that is wrong.
624
+ *
625
+ * @param {DecidedFinding} f
626
+ * @returns {'gone'|'new'|'changed'}
627
+ */
628
+ function whichWay(f) {
629
+ const kinds = (f.differences ?? []).map((d) => d && d.kind).filter(Boolean);
630
+ if (kinds.length === 0 && f.sample && f.sample.kind) kinds.push(f.sample.kind);
631
+ if (kinds.length === 0) return 'changed';
632
+ if (kinds.every((k) => k === 'vanished')) return 'gone';
633
+ if (kinds.every((k) => k === 'appeared')) return 'new';
634
+ return 'changed';
635
+ }
636
+
612
637
  /**
613
638
  * @param {DecidedFinding} f
614
639
  * @returns {string}
@@ -619,7 +644,15 @@ function sealedTodo(f) {
619
644
  if (cls === 'guard') return 'This is a bug you already reported once, coming back. Say whether it goes back on the list, or the guard was wrong.';
620
645
  if (cls === 'money') return 'Say whether that is the amount you wanted. If it is, shipping makes it the new normal; if it is not, nothing ships.';
621
646
  if (cls === 'sign-in') return 'Say whether signing in is meant to behave like that now. Nothing ships until you do.';
622
- if (cls === 'data-loss') return 'Say whether that deletion is meant to happen. This one is worth thirty seconds before anything ships.';
647
+ if (cls === 'data-loss') {
648
+ // The class means "this touches losing data". Which way it moved is a separate fact, and
649
+ // saying the wrong one at somebody who is about to rule on it is worse than saying less.
650
+ const worth = ' This one is worth thirty seconds before anything ships.';
651
+ const way = whichWay(f);
652
+ if (way === 'gone') return `Say whether that deletion is meant to happen.${worth}`;
653
+ if (way === 'new') return `Say whether that is meant to be there. It can lose data.${worth}`;
654
+ return `Say whether that change is meant to happen. It can lose data.${worth}`;
655
+ }
623
656
  if (cls === 'crash') return 'This has to be fixed before anything ships. Nobody needs to decide anything, but you should know it happened.';
624
657
  return `Say whether that is what you wanted${where ? `, at ${where}` : ''}. If it is, ship — shipping is what makes it the new normal.`;
625
658
  }
package/src/v2/init.js CHANGED
@@ -2256,6 +2256,21 @@ function nextCommands(readiness, project) {
2256
2256
  ? 'The first real run. It walks everything and shows you what it sees. It cannot record what "working" means — only shipping does that.'
2257
2257
  : 'The first real run. Nothing here is fully set up yet, so it walks what it can reach and says plainly what it left out — which is more useful than waiting.',
2258
2258
  });
2259
+ // Nothing said this existed, anywhere. A person ran a check, watched a blank terminal for
2260
+ // minutes, and reasonably asked why there was no window — the panel was there the whole
2261
+ // time behind a flag nobody had been told about. A run that looks like nothing is
2262
+ // happening is indistinguishable from a run that is stuck, which is the state somebody
2263
+ // kills it in. Said once, here, where a person is deciding what to type next.
2264
+ // Measured 2026-09-01.
2265
+ const hasAScreen =
2266
+ (project.pages?.length ?? 0) > 0
2267
+ || project.products.some((p) => ['web', 'electron', 'ios', 'android', 'macos', 'linux', 'windows', 'extension'].includes(String(p.surface)));
2268
+ if (hasAScreen) {
2269
+ next.push({
2270
+ command: 'staysfixed check --watch',
2271
+ what: 'The same run, with a window beside it drawing every screen as it is walked. Worth it once, to see what this actually does. It opens behind what you are working on; --watch-front brings it forward.',
2272
+ });
2273
+ }
2259
2274
  }
2260
2275
  if (project.tests.files > 0) {
2261
2276
  next.push({ command: 'staysfixed check --journeys suite', what: `Walk the ${project.tests.files} test${project.tests.files === 1 ? '' : 's'} this project already has, under instrumentation.` });
@@ -0,0 +1,410 @@
1
+ /**
2
+ * The system dialogs this tool causes, and what to do about them.
3
+ *
4
+ * ## What went wrong, 2026-09-01
5
+ *
6
+ * A real check on a real product ran for four minutes and spent the last two of them frozen.
7
+ * The owner recorded it. On screen, over everything, was a macOS alert:
8
+ *
9
+ * Keychain Not Found
10
+ * A keychain cannot be found to store "Terminal Deck Key."
11
+ * [?] [Cancel] [Reset To Defaults]
12
+ *
13
+ * The panel sat on "Walking ask the private channel voice:status to answer" at 23 of 27
14
+ * journeys and never moved. When the run finally gave up it said only that one journey had no
15
+ * answer. It never said WHY, and the why was a modal box waiting for a person who was not
16
+ * going to be there — on a machine where nobody had been asked to sit and watch.
17
+ *
18
+ * ## Why this is the tool's problem and not the product's
19
+ *
20
+ * Every adapter here starts the thing under test in a THROWAWAY settings folder, on its own
21
+ * ports, under its own name, so that a run can never touch the real install. That isolation is
22
+ * the whole design, and a fresh settings folder is exactly the condition that makes an
23
+ * application ask the operating system for something it has never been granted: a keychain, a
24
+ * microphone, the Documents folder, permission to control another app. So these dialogs are a
25
+ * NORMAL consequence of how this tool works. A tool that causes them and then hangs behind
26
+ * them, silently, is broken in its own right.
27
+ *
28
+ * ## The three rules, and why each one is a rule
29
+ *
30
+ * ONLY OURS. A dialog is touched only when it belongs to an application this run started, and
31
+ * the caller supplies that list — the same `ours` bookkeeping the screen guard keeps. His own
32
+ * apps ask him things all day and none of it is any of this tool's business. Getting this
33
+ * wrong would mean a background check silently answering a prompt in his email client.
34
+ *
35
+ * ONLY HARMLESS BUTTONS. The button pressed comes from a fixed list of ones that decline,
36
+ * dismiss or close, and nothing else is ever pressed. On the very dialog that started this,
37
+ * the other button was "Reset To Defaults" — on a keychain — which is a change to the machine
38
+ * that no automated run may make on somebody's behalf. When there is no harmless button, the
39
+ * dialog is left exactly as it is and reported instead. A tool that cannot act safely says so;
40
+ * it does not guess.
41
+ *
42
+ * SAY IT HAPPENED. Every dialog seen is recorded with its words, whether it could be dismissed
43
+ * or not, and the check reports it. "No answer for one journey" is a fact with no cause in it.
44
+ * "No answer, because your app put up a box saying a keychain cannot be found, and I closed it"
45
+ * is the same fact with the thing a person needs in order to act.
46
+ *
47
+ * Everything here is best effort and every failure is swallowed: no window server, no Apple
48
+ * Events permission, a locked screen or a machine that is not a Mac all mean there are no
49
+ * dialogs to clear, which is never a reason to fail a check.
50
+ */
51
+
52
+ import { execFile } from 'node:child_process';
53
+ import { promisify } from 'node:util';
54
+
55
+ import { detail } from '../../core/log.js';
56
+
57
+ const run = promisify(execFile);
58
+
59
+ /** How often to look. Dialogs are not urgent — a person would take a second to notice one too. */
60
+ const LOOK_EVERY_MS = 1200;
61
+
62
+ /**
63
+ * The only buttons this file will ever press.
64
+ *
65
+ * Every one of them declines, dismisses or closes. Nothing here grants anything, changes a
66
+ * setting, deletes anything or agrees to anything. The list is deliberately short and
67
+ * deliberately literal: a fuzzy match would eventually press "Allow" because it contained
68
+ * "low", and the whole safety of this file is that it cannot.
69
+ */
70
+ const SAFE_BUTTONS = [
71
+ 'Cancel',
72
+ "Don't Allow",
73
+ 'Don’t Allow',
74
+ 'Deny',
75
+ 'Not Now',
76
+ 'Later',
77
+ 'Close',
78
+ 'Dismiss',
79
+ 'No',
80
+ 'Quit',
81
+ ];
82
+
83
+ /**
84
+ * Buttons that must never be pressed even if some future edit adds them above.
85
+ *
86
+ * A second, independent gate. `SAFE_BUTTONS` is the allow-list and this is the veto, and a
87
+ * button has to get past both. It exists because the failure this file guards against is not
88
+ * "the wrong button was pressed once" — it is "somebody widened the allow-list a year from now
89
+ * and nobody noticed what it now includes".
90
+ */
91
+ const NEVER_PRESS = [
92
+ 'reset',
93
+ 'allow',
94
+ 'delete',
95
+ 'erase',
96
+ 'remove',
97
+ 'ok',
98
+ 'yes',
99
+ 'continue',
100
+ 'agree',
101
+ 'accept',
102
+ 'grant',
103
+ 'always',
104
+ 'trust',
105
+ 'update',
106
+ 'install',
107
+ 'send',
108
+ 'share',
109
+ ];
110
+
111
+ /**
112
+ * @typedef {object} SeenDialog
113
+ * @property {string} app The application it belongs to.
114
+ * @property {string} title Its window title, when it has one.
115
+ * @property {string} says The text on it, joined into one line.
116
+ * @property {string|null} closed The button pressed, or null when it was left alone.
117
+ * @property {string|null} why Why it was left alone, when it was.
118
+ * @property {number} at Milliseconds into the run.
119
+ */
120
+
121
+ /**
122
+ * Is this a button this file is allowed to press?
123
+ *
124
+ * @param {string} label
125
+ * @returns {boolean}
126
+ */
127
+ export function mayPress(label) {
128
+ const name = String(label ?? '').trim();
129
+ if (name.length === 0) return false;
130
+ const lower = name.toLowerCase();
131
+ // The veto runs first and on the whole label, so "Reset To Defaults" is refused before
132
+ // anything else gets a chance to like the look of it.
133
+ for (const banned of NEVER_PRESS) {
134
+ if (lower.split(/[^a-z’']+/).includes(banned)) return false;
135
+ }
136
+ return SAFE_BUTTONS.some((safe) => safe.toLowerCase() === lower);
137
+ }
138
+
139
+ /**
140
+ * Pick the button to press out of what a dialog offers.
141
+ *
142
+ * @param {string[]} labels
143
+ * @returns {string|null}
144
+ */
145
+ export function safeButton(labels) {
146
+ const offered = (labels ?? []).map((l) => String(l ?? '').trim()).filter(Boolean);
147
+ // In SAFE_BUTTONS order rather than in the dialog's order, so the answer does not depend on
148
+ // how somebody laid their buttons out.
149
+ for (const wanted of SAFE_BUTTONS) {
150
+ const hit = offered.find((l) => l.toLowerCase() === wanted.toLowerCase() && mayPress(l));
151
+ if (hit) return hit;
152
+ }
153
+ return null;
154
+ }
155
+
156
+ /**
157
+ * Every modal box currently up, for the applications named.
158
+ *
159
+ * WHAT COUNTS AS A DIALOG, and this took measuring rather than guessing. The obvious test is
160
+ * the window's subrole, and it is wrong: on this Mac an ordinary Terminal window, Activity
161
+ * Monitor and System Settings all report `AXDialog`, the same value the real keychain alert
162
+ * reports. A tool matching on that would go hunting for buttons to press on somebody's actual
163
+ * work. The attribute that does separate them is **AXModal** — measured true on the alert and
164
+ * false on all four of his open Terminal windows — which is also the honest definition of the
165
+ * thing being fixed here: a box that blocks. Sheets are included because a sheet is modal to
166
+ * the window it hangs off whatever it says about itself.
167
+ *
168
+ * One `osascript` call for the whole sweep. The output is one record per line, tab separated,
169
+ * because parsing AppleScript's own list syntax is a worse idea than choosing a separator.
170
+ *
171
+ * @param {string[]} apps
172
+ * @returns {Promise<{app: string, title: string, says: string, buttons: string[]}[]>}
173
+ */
174
+ export async function dialogsUp(apps) {
175
+ if (process.platform !== 'darwin' || !apps || apps.length === 0) return [];
176
+ const list = '{' + apps.map((a) => JSON.stringify(String(a))).join(', ') + '}';
177
+ const script = `
178
+ set out to ""
179
+ tell application "System Events"
180
+ repeat with wanted in ${list}
181
+ repeat with proc in (every application process whose name is (wanted as string))
182
+ try
183
+ repeat with win in (every window of proc)
184
+ set isDialog to false
185
+ try
186
+ if (value of attribute "AXModal" of win) is true then set isDialog to true
187
+ end try
188
+ try
189
+ if subrole of win is "AXSystemDialog" then set isDialog to true
190
+ end try
191
+ -- NOT "sheets". Inside a System Events tell block that word is an element name,
192
+ -- so "set sheets to {}" is read as "set every sheet to {}" and throws -10006.
193
+ -- The error was swallowed by the try around this loop and the whole sweep came
194
+ -- back empty, which looked exactly like a machine with no dialogs on it.
195
+ set sheetCount to 0
196
+ set firstSheet to missing value
197
+ try
198
+ set theSheets to every sheet of win
199
+ set sheetCount to (count of theSheets)
200
+ if sheetCount > 0 then set firstSheet to item 1 of theSheets
201
+ end try
202
+ if (isDialog) or (sheetCount > 0) then
203
+ set target to win
204
+ if sheetCount > 0 then set target to firstSheet
205
+ set theTitle to ""
206
+ try
207
+ set theTitle to name of target as string
208
+ end try
209
+ set theText to ""
210
+ try
211
+ repeat with t in (every static text of target)
212
+ set theText to theText & (value of t as string) & " "
213
+ end repeat
214
+ end try
215
+ set theButtons to ""
216
+ try
217
+ repeat with b in (every button of target)
218
+ set theButtons to theButtons & (name of b as string) & "|"
219
+ end repeat
220
+ end try
221
+ set out to out & (name of proc as string) & tab & theTitle & tab & theText & tab & theButtons & linefeed
222
+ end if
223
+ end repeat
224
+ end try
225
+ end repeat
226
+ end repeat
227
+ end tell
228
+ return out
229
+ `;
230
+ try {
231
+ const { stdout } = await run('osascript', ['-e', script], { timeout: 6000 });
232
+ return stdout
233
+ .split('\n')
234
+ .map((line) => line.replace(/\r$/, ''))
235
+ .filter((line) => line.trim().length > 0)
236
+ .map((line) => {
237
+ const [app = '', title = '', says = '', buttons = ''] = line.split('\t');
238
+ return {
239
+ app: app.trim(),
240
+ title: title.trim(),
241
+ says: says.replace(/\s+/g, ' ').trim(),
242
+ buttons: buttons.split('|').map((b) => b.trim()).filter(Boolean),
243
+ };
244
+ })
245
+ .filter((d) => d.app.length > 0);
246
+ } catch {
247
+ // No window server, no permission, a locked screen. There is nothing to clear.
248
+ return [];
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Press one button on one application's frontmost dialog.
254
+ *
255
+ * @param {string} app
256
+ * @param {string} button
257
+ * @returns {Promise<boolean>}
258
+ */
259
+ export async function pressButton(app, button) {
260
+ if (process.platform !== 'darwin') return false;
261
+ if (!mayPress(button)) return false;
262
+ const script = `
263
+ tell application "System Events"
264
+ tell (first application process whose name is ${JSON.stringify(app)})
265
+ repeat with win in (every window of it)
266
+ try
267
+ set target to win
268
+ try
269
+ if (count of (every sheet of win)) > 0 then set target to item 1 of (every sheet of win)
270
+ end try
271
+ click (first button of target whose name is ${JSON.stringify(button)})
272
+ return "pressed"
273
+ end try
274
+ end repeat
275
+ end tell
276
+ end tell
277
+ return "no"
278
+ `;
279
+ try {
280
+ const { stdout } = await run('osascript', ['-e', script], { timeout: 6000 });
281
+ return stdout.trim() === 'pressed';
282
+ } catch {
283
+ return false;
284
+ }
285
+ }
286
+
287
+ /**
288
+ * @typedef {object} DialogWatcher
289
+ * @property {(name: string) => void} claim Name an application this run started.
290
+ * @property {() => Promise<void>} stop Stop watching. Safe to call twice.
291
+ * @property {() => SeenDialog[]} report Every dialog seen, in the order they appeared.
292
+ * @property {() => Promise<void>} sweepNow Look once, right now. For tests and for the end of a run.
293
+ */
294
+
295
+ /**
296
+ * Watch for modal boxes belonging to what this run started, close the harmless ones, and
297
+ * remember all of them.
298
+ *
299
+ * `look` and `press` exist for the same reason the screen guard has them: the decisions here —
300
+ * whose dialog it is, which button qualifies, what gets recorded when nothing can be pressed —
301
+ * are the part that has to be right, and they are unreachable behind two `osascript` calls
302
+ * that answer differently on every machine and not at all on most.
303
+ *
304
+ * @param {{claims?: string[], everyMs?: number, elapsed?: () => number, look?: (apps: string[]) => Promise<any[]>, press?: (app: string, button: string) => Promise<boolean>}} [opts]
305
+ * @returns {DialogWatcher}
306
+ */
307
+ export function watchForDialogs(opts = {}) {
308
+ const everyMs = opts.everyMs ?? LOOK_EVERY_MS;
309
+ const look = opts.look ?? dialogsUp;
310
+ const press = opts.press ?? pressButton;
311
+ const elapsed = opts.elapsed ?? (() => 0);
312
+
313
+ /** @type {Set<string>} */
314
+ const ours = new Set(opts.claims ?? []);
315
+ /** @type {SeenDialog[]} */
316
+ const seen = [];
317
+ /** Dialogs already recorded, so one box sitting there for a minute is one line, not fifty. */
318
+ const already = new Set();
319
+ let stopped = process.platform !== 'darwin' && !opts.look;
320
+ /** @type {ReturnType<typeof setTimeout>|null} */
321
+ let timer = null;
322
+
323
+ const sweep = async () => {
324
+ if (stopped || ours.size === 0) return;
325
+ let up = [];
326
+ try {
327
+ up = await look([...ours]);
328
+ } catch {
329
+ return;
330
+ }
331
+ for (const d of up ?? []) {
332
+ const key = `${d.app}${d.title}${d.says}`;
333
+ if (already.has(key)) continue;
334
+ const button = safeButton(d.buttons ?? []);
335
+ let closed = null;
336
+ let why = null;
337
+ if (button) {
338
+ const done = await press(d.app, button).catch(() => false);
339
+ if (done) closed = button;
340
+ else why = `tried to press "${button}" and the click did not land`;
341
+ } else {
342
+ // Recorded, not guessed at. The offered buttons go into the reason so a person reading
343
+ // the run knows exactly what they are being asked and why nothing was pressed.
344
+ why =
345
+ (d.buttons ?? []).length > 0
346
+ ? `nothing on it is safe for a machine to press: ${(d.buttons ?? []).join(', ')}`
347
+ : 'it offered no button this tool could find';
348
+ }
349
+ already.add(key);
350
+ seen.push({ app: d.app, title: d.title ?? '', says: d.says ?? '', closed, why, at: elapsed() });
351
+ detail(
352
+ `A dialog from ${d.app} said "${d.says || d.title}" — ` +
353
+ (closed ? `closed it with "${closed}".` : `left it alone: ${why}.`),
354
+ );
355
+ }
356
+ };
357
+
358
+ const tick = async () => {
359
+ await sweep();
360
+ if (!stopped) timer = setTimeout(tick, everyMs);
361
+ };
362
+ if (!stopped) timer = setTimeout(tick, everyMs);
363
+
364
+ return {
365
+ claim: (name) => {
366
+ if (name) ours.add(name);
367
+ },
368
+ stop: async () => {
369
+ stopped = true;
370
+ if (timer) clearTimeout(timer);
371
+ timer = null;
372
+ },
373
+ report: () => seen.slice(),
374
+ sweepNow: sweep,
375
+ };
376
+ }
377
+
378
+ /**
379
+ * One plain sentence about the dialogs a run met, or nothing when it met none.
380
+ *
381
+ * Written to be read after the verdict, by somebody who has just been told a journey had no
382
+ * answer and needs to know why.
383
+ *
384
+ * @param {SeenDialog[]} seen
385
+ * @returns {string|null}
386
+ */
387
+ export function describeDialogs(seen) {
388
+ const all = seen ?? [];
389
+ if (all.length === 0) return null;
390
+ const closed = all.filter((d) => d.closed);
391
+ const left = all.filter((d) => !d.closed);
392
+ const parts = [];
393
+ if (closed.length > 0) {
394
+ const first = closed[0];
395
+ parts.push(
396
+ `${closed.length === 1 ? 'A box' : `${closed.length} boxes`} came up from the app this run started and ` +
397
+ `${closed.length === 1 ? 'was' : 'were'} closed with "${first.closed}"` +
398
+ `${first.says ? `: "${first.says}"` : ''}. Anything walked while it was up may have had no answer for that reason.`,
399
+ );
400
+ }
401
+ if (left.length > 0) {
402
+ const first = left[0];
403
+ parts.push(
404
+ `${left.length === 1 ? 'A box is' : `${left.length} boxes are`} still up and ${left.length === 1 ? 'was' : 'were'} ` +
405
+ `left alone, because ${first.why}${first.says ? `. It says: "${first.says}"` : ''}. ` +
406
+ 'Nothing here presses a button that could change your machine.',
407
+ );
408
+ }
409
+ return parts.join(' ');
410
+ }
@@ -568,7 +568,10 @@ button { font: inherit; color: inherit; }
568
568
  }
569
569
 
570
570
  /* --- the scrolling body -------------------------------------------------- */
571
- .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 0 var(--pad) 18px; }
571
+ /* A FLOOR, so the report can never be reduced to a slit again. Whatever else is on screen,
572
+ the body keeps enough height to show a heading and a few rows under it — which is the
573
+ difference between "there is more here, scroll" and "the detail is gone". */
574
+ .scroll { flex: 1 1 auto; min-height: 132px; overflow-y: auto; overflow-x: hidden; padding: 0 var(--pad) 18px; }
572
575
  .scroll::-webkit-scrollbar { width: 9px; }
573
576
  .scroll::-webkit-scrollbar-thumb { background: var(--resting); border-radius: 999px; }
574
577
  .scroll::-webkit-scrollbar-track { background: transparent; }
@@ -778,8 +781,25 @@ button { font: inherit; color: inherit; }
778
781
  .nothing { padding: 30px 16px; color: var(--faint); font-size: var(--t-body); line-height: 1.8; text-align: center; }
779
782
 
780
783
  /* --- the only thing that ever reaches a person --------------------------- */
784
+ /* THE FOOTER MAY NEVER EAT THE WINDOW.
785
+ It used to be "flex: 0 0 auto" with nothing capping it, so its height was simply however
786
+ many things needed a person. On a real run that found seventeen, the footer grew past the
787
+ height of the whole panel and squeezed the scrolling body — the walk, the wobble, what
788
+ survived, what was not checked, every journey and its address count — down to EIGHTEEN
789
+ PIXELS holding 41,115 of content. Measured, not guessed: clientHeight 18, scrollHeight
790
+ 41115. What a person saw at the end of a run was one clipped line of text where the whole
791
+ report had been a second earlier, which reads exactly like the tool throwing its detail
792
+ away at the moment it finishes.
793
+ So it shrinks now, the list inside it scrolls, and the body below keeps a floor. */
781
794
  .foot {
795
+ /* Sizes to its content, and stops at half the window. Not "0 1 auto": that let the flex
796
+ row below it take every pixel and shrank the footer to its label, so seventeen things
797
+ needing a person rendered at zero height — the same detail lost, from the other end. */
782
798
  flex: 0 0 auto;
799
+ max-height: 52%;
800
+ min-height: 0;
801
+ display: flex;
802
+ flex-direction: column;
783
803
  padding: 13px var(--pad) 15px;
784
804
  background: var(--glass);
785
805
  backdrop-filter: blur(22px) saturate(120%);
@@ -787,6 +807,12 @@ button { font: inherit; color: inherit; }
787
807
  border-top: 1px solid var(--line);
788
808
  animation: arrive 340ms var(--ease) both;
789
809
  }
810
+ /* The label above and the sentence below stay put; only the list moves. A person reading
811
+ "Needs a person" must never have to scroll to find out that is what they are reading. */
812
+ #needs { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }
813
+ #needs::-webkit-scrollbar { width: 9px; }
814
+ #needs::-webkit-scrollbar-thumb { background: var(--resting); border-radius: 999px; }
815
+ #needs::-webkit-scrollbar-track { background: transparent; }
790
816
  .nextlabel {
791
817
  font-size: var(--t-label); font-weight: 600; letter-spacing: 0.2em;
792
818
  text-transform: uppercase; color: var(--wait); margin-bottom: 8px;