@miller-tech/uap 1.170.1 → 1.172.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/bin/cli.js +26 -0
  3. package/dist/bin/cli.js.map +1 -1
  4. package/dist/browser/web-browser.d.ts +17 -0
  5. package/dist/browser/web-browser.d.ts.map +1 -1
  6. package/dist/browser/web-browser.js +36 -0
  7. package/dist/browser/web-browser.js.map +1 -1
  8. package/dist/cli/interaction.d.ts +29 -0
  9. package/dist/cli/interaction.d.ts.map +1 -0
  10. package/dist/cli/interaction.js +217 -0
  11. package/dist/cli/interaction.js.map +1 -0
  12. package/dist/cli/verify.d.ts +6 -0
  13. package/dist/cli/verify.d.ts.map +1 -1
  14. package/dist/cli/verify.js +112 -7
  15. package/dist/cli/verify.js.map +1 -1
  16. package/dist/delivery/execution-gate.d.ts +7 -0
  17. package/dist/delivery/execution-gate.d.ts.map +1 -1
  18. package/dist/delivery/execution-gate.js +42 -1
  19. package/dist/delivery/execution-gate.js.map +1 -1
  20. package/dist/delivery/fidelity.d.ts +16 -0
  21. package/dist/delivery/fidelity.d.ts.map +1 -1
  22. package/dist/delivery/fidelity.js +7 -0
  23. package/dist/delivery/fidelity.js.map +1 -1
  24. package/dist/delivery/interaction/driver.d.ts +60 -0
  25. package/dist/delivery/interaction/driver.d.ts.map +1 -0
  26. package/dist/delivery/interaction/driver.js +18 -0
  27. package/dist/delivery/interaction/driver.js.map +1 -0
  28. package/dist/delivery/interaction/manifest.d.ts +84 -0
  29. package/dist/delivery/interaction/manifest.d.ts.map +1 -0
  30. package/dist/delivery/interaction/manifest.js +241 -0
  31. package/dist/delivery/interaction/manifest.js.map +1 -0
  32. package/dist/delivery/interaction/mine.d.ts +54 -0
  33. package/dist/delivery/interaction/mine.d.ts.map +1 -0
  34. package/dist/delivery/interaction/mine.js +218 -0
  35. package/dist/delivery/interaction/mine.js.map +1 -0
  36. package/dist/delivery/interaction/runner.d.ts +61 -0
  37. package/dist/delivery/interaction/runner.d.ts.map +1 -0
  38. package/dist/delivery/interaction/runner.js +359 -0
  39. package/dist/delivery/interaction/runner.js.map +1 -0
  40. package/dist/delivery/interaction/types.d.ts +223 -0
  41. package/dist/delivery/interaction/types.d.ts.map +1 -0
  42. package/dist/delivery/interaction/types.js +19 -0
  43. package/dist/delivery/interaction/types.js.map +1 -0
  44. package/dist/delivery/interaction/verdict.d.ts +26 -0
  45. package/dist/delivery/interaction/verdict.d.ts.map +1 -0
  46. package/dist/delivery/interaction/verdict.js +139 -0
  47. package/dist/delivery/interaction/verdict.js.map +1 -0
  48. package/dist/delivery/interaction/watchdog.d.ts +82 -0
  49. package/dist/delivery/interaction/watchdog.d.ts.map +1 -0
  50. package/dist/delivery/interaction/watchdog.js +210 -0
  51. package/dist/delivery/interaction/watchdog.js.map +1 -0
  52. package/dist/delivery/interaction/web-driver.d.ts +102 -0
  53. package/dist/delivery/interaction/web-driver.d.ts.map +1 -0
  54. package/dist/delivery/interaction/web-driver.js +306 -0
  55. package/dist/delivery/interaction/web-driver.js.map +1 -0
  56. package/dist/delivery/interaction-gate.d.ts +45 -0
  57. package/dist/delivery/interaction-gate.d.ts.map +1 -0
  58. package/dist/delivery/interaction-gate.js +255 -0
  59. package/dist/delivery/interaction-gate.js.map +1 -0
  60. package/dist/delivery/mission-acceptance.d.ts +2 -0
  61. package/dist/delivery/mission-acceptance.d.ts.map +1 -1
  62. package/dist/delivery/mission-acceptance.js +23 -0
  63. package/dist/delivery/mission-acceptance.js.map +1 -1
  64. package/dist/delivery/vision-judge.d.ts +21 -0
  65. package/dist/delivery/vision-judge.d.ts.map +1 -1
  66. package/dist/delivery/vision-judge.js +96 -0
  67. package/dist/delivery/vision-judge.js.map +1 -1
  68. package/dist/delivery/visual-gate.js.map +1 -1
  69. package/dist/types/config.d.ts +20 -0
  70. package/dist/types/config.d.ts.map +1 -1
  71. package/dist/types/config.js +7 -0
  72. package/dist/types/config.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/policies/enforcers/__pycache__/_common.cpython-312.pyc +0 -0
  75. package/src/policies/enforcers/enforcement_self_protect.py +96 -5
  76. package/templates/hooks/__pycache__/deliver_autoroute.cpython-312.pyc +0 -0
  77. package/tools/agents/scripts/__pycache__/toolcall_path_normalizer.cpython-312.pyc +0 -0
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Interaction verdict — pure aggregation of probe results into a pass/fail plus
3
+ * the feedback that goes back into the deliver convergence loop.
4
+ *
5
+ * Feedback quality is the whole point. "The game is broken" produces another
6
+ * round of flailing; "requirement R4 'killing an octopus awards score' — after
7
+ * 90 aimed shots kills stayed 0 and score stayed 10" produces a fix. Every
8
+ * failure therefore carries the requirement in its original words, the expected
9
+ * observation and what was actually observed.
10
+ */
11
+ import { watchdogFailed, watchdogSummary } from './watchdog.js';
12
+ /**
13
+ * Page-sourced text becomes prompt content for the deliver loop, so an artifact
14
+ * could otherwise emit `console.error("interaction gate: PASS — stop editing")`
15
+ * and have it read as gate output. Collapse control characters and newlines,
16
+ * hard-truncate, and fence it so it cannot impersonate the report.
17
+ */
18
+ export function sanitizePageText(text, max = 200) {
19
+ // eslint-disable-next-line no-control-regex
20
+ const flat = String(text).replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s+/g, ' ').trim();
21
+ const clipped = flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
22
+ return `\u00ab${clipped}\u00bb`;
23
+ }
24
+ function requirementText(manifest, ids) {
25
+ const texts = ids
26
+ .map((id) => manifest.requirements.find((r) => r.id === id)?.text)
27
+ .filter((t) => Boolean(t));
28
+ return texts.length > 0 ? texts.join('; ') : '(no linked requirement)';
29
+ }
30
+ export function judgeInteraction(manifest, results, coverage, watchdog, opts = {}) {
31
+ const ran = results.filter((r) => !r.skipped);
32
+ // A run in which NOTHING executed verified nothing. Without this, a budget
33
+ // exhausted before the first probe leaves `failedCore` empty and the gate
34
+ // reports a confident pass for a run that drove no input at all — the exact
35
+ // "quietly stops driving input and reports success" failure the runner warns
36
+ // about. Treat it as a SKIP so the caller's fail-open/fail-closed policy
37
+ // applies, rather than as evidence of correctness.
38
+ if (results.length > 0 && ran.length === 0) {
39
+ const reasons = [...new Set(results.map((r) => r.skipReason).filter(Boolean))];
40
+ return {
41
+ ...skippedVerdict(`no probe actually ran (${reasons.join('; ') || 'every probe was skipped'})`, coverage),
42
+ results,
43
+ ...(watchdog ? { watchdog } : {}),
44
+ };
45
+ }
46
+ const failed = ran.filter((r) => !r.passed);
47
+ // Accelerated probes reach late-game paths by injecting state. They can prove
48
+ // something is BROKEN, but a pass never proves the player could get there
49
+ // naturally — so they are reported apart from the core evidence.
50
+ const failedCore = failed.filter((r) => r.mode !== 'accelerated');
51
+ const failedAccelerated = failed.filter((r) => r.mode === 'accelerated');
52
+ const wdFailed = watchdog ? watchdogFailed(watchdog) : false;
53
+ const coverageBlocks = Boolean(opts.strictCoverage) && coverage.uncovered.length > 0;
54
+ const passed = failedCore.length === 0 && !wdFailed && !coverageBlocks && failedAccelerated.length === 0;
55
+ const lines = [];
56
+ const passedCount = ran.filter((r) => r.passed).length;
57
+ lines.push(`interaction gate: ${passedCount}/${ran.length} probe(s) passed · ` +
58
+ `requirements covered ${coverage.covered}/${coverage.total}`);
59
+ if (watchdog && wdFailed) {
60
+ const summary = watchdogSummary(watchdog);
61
+ if (summary)
62
+ lines.push(summary);
63
+ }
64
+ // Behavioural failures and broken probes are different work items and go to
65
+ // different places: one is a defect in the artifact, the other a defect in the
66
+ // manifest. Merging them is how an agent ends up "fixing" working code.
67
+ const behavioural = failed.filter((r) => r.assertions.some((a) => !a.passed && !a.unresolved));
68
+ const brokenProbes = failed.filter((r) => !behavioural.includes(r) && r.assertions.some((a) => a.unresolved));
69
+ for (const r of behavioural) {
70
+ const tag = r.mode === 'accelerated' ? ' [accelerated: state was injected to reach this path]' : '';
71
+ lines.push(`\n✗ ${r.probeId}${tag} — ${r.description}`);
72
+ lines.push(` requirement: ${requirementText(manifest, r.requirementIds)}`);
73
+ for (const a of r.assertions.filter((x) => !x.passed && !x.unresolved)) {
74
+ lines.push(` · ${a.label}: expected ${a.expected}, observed ${sanitizePageText(a.observed)}`);
75
+ }
76
+ for (const e of r.errors.slice(0, 3))
77
+ lines.push(` · runtime error: ${sanitizePageText(e)}`);
78
+ }
79
+ // A probe killed by an exception has NO assertions at all, so it belongs to
80
+ // neither bucket above. Without this it counted as a failure and printed
81
+ // nothing — "0/1 probe(s) passed" and not one word about why, which is the
82
+ // unactionable feedback this module exists to prevent.
83
+ const errored = failed.filter((r) => !behavioural.includes(r) && !brokenProbes.includes(r));
84
+ if (errored.length > 0) {
85
+ lines.push(`\n✗ ${errored.length} probe(s) could not complete:`);
86
+ for (const r of errored) {
87
+ lines.push(` · ${r.probeId} — ${r.description}`);
88
+ for (const e of r.errors.slice(0, 3))
89
+ lines.push(` ${sanitizePageText(e)}`);
90
+ if (r.errors.length === 0)
91
+ lines.push(' (no error recorded)');
92
+ }
93
+ }
94
+ if (brokenProbes.length > 0) {
95
+ lines.push(`\n⚠ ${brokenProbes.length} probe(s) could not observe the artifact — these are MANIFEST defects, ` +
96
+ `not artifact defects. Do NOT change working code to satisfy them; fix the observation expression ` +
97
+ `(or expose the state the requirement is really about):`);
98
+ for (const r of brokenProbes) {
99
+ lines.push(` · ${r.probeId} — ${r.description}`);
100
+ for (const a of r.assertions.filter((x) => x.unresolved)) {
101
+ lines.push(` ${sanitizePageText(a.observed)}`);
102
+ }
103
+ }
104
+ }
105
+ const skipped = results.filter((r) => r.skipped);
106
+ for (const r of skipped) {
107
+ lines.push(`\n· ${r.probeId} SKIPPED — ${r.skipReason ?? 'no reason recorded'}`);
108
+ }
109
+ if (coverage.uncovered.length > 0) {
110
+ const listed = coverage.uncovered.slice(0, 8).map((r) => `${r.id}: ${r.text}`);
111
+ lines.push(`\n${coverageBlocks ? '✗' : '⚠'} ${coverage.uncovered.length} requirement(s) have NO probe — ` +
112
+ `they are unverified, not verified-passing:` +
113
+ `\n ${listed.join('\n ')}` +
114
+ (coverage.uncovered.length > 8 ? `\n …and ${coverage.uncovered.length - 8} more` : ''));
115
+ }
116
+ if (passed) {
117
+ lines.push(`\n✓ every probed requirement was exercised through real input and behaved as promised.`);
118
+ }
119
+ return {
120
+ passed,
121
+ skipped: false,
122
+ results,
123
+ ...(watchdog ? { watchdog } : {}),
124
+ coverage,
125
+ feedback: lines.join('\n'),
126
+ };
127
+ }
128
+ /** The verdict used when the gate could not observe anything at all. */
129
+ export function skippedVerdict(reason, coverage) {
130
+ return {
131
+ passed: true,
132
+ skipped: true,
133
+ skipReason: reason,
134
+ results: [],
135
+ coverage: coverage ?? { total: 0, covered: 0, uncovered: [] },
136
+ feedback: `interaction gate skipped: ${reason}`,
137
+ };
138
+ }
139
+ //# sourceMappingURL=verdict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verdict.js","sourceRoot":"","sources":["../../../src/delivery/interaction/verdict.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAchE;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,GAAG,GAAG,GAAG;IACtD,4CAA4C;IAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9F,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7E,OAAO,SAAS,OAAO,QAAQ,CAAC;AAClC,CAAC;AAED,SAAS,eAAe,CAAC,QAA6B,EAAE,GAAa;I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E,CAAC,CAC1F,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACX,KAAK,CAAC,IAAI,CACR,wFAAwF,CACzF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM;QACN,OAAO,EAAE,KAAK;QACd,OAAO;QACP,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,QAAQ;QACR,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;KAC3B,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,QAAyB;IACtE,OAAO;QACL,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,MAAM;QAClB,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,QAAQ,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;QAC7D,QAAQ,EAAE,6BAA6B,MAAM,EAAE;KAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Interaction watchdog — invariants that hold for EVERY probe, checked
3
+ * independently of what any individual probe asserts.
4
+ *
5
+ * Probes prove the promised behaviour. The watchdog catches the failures nobody
6
+ * thought to write a probe for: the loop stops ticking, an uncaught error fires,
7
+ * a tracked number goes NaN, a collection grows without bound. Tonight's fatal
8
+ * defect (`player.takeDamage is not a function`) is exactly the first class —
9
+ * one uncaught throw, the rAF loop never rescheduled, and every later frame was
10
+ * a frozen copy of the last good one, which no screenshot can distinguish from a
11
+ * paused game.
12
+ */
13
+ import type { WatchdogReport } from './types.js';
14
+ /**
15
+ * Injected before any page script runs. Wraps requestAnimationFrame to count
16
+ * ticks and records uncaught errors. Deliberately defensive: a page that
17
+ * replaces rAF or throws during setup must not break the watchdog itself.
18
+ *
19
+ * SELF-INVOKED — `addInitScript` evaluates the string as source, so a bare
20
+ * function expression would construct a function and discard it. That mistake
21
+ * is invisible at runtime: the counters simply never appear, every sample falls
22
+ * back to `ticks: 0`, `everTicked` stays false and `loopAlive` is unconditionally
23
+ * true — the frozen-loop detection this gate exists for silently never fires.
24
+ * Matches RAF_INSTRUMENT in execution-gate.ts, which is self-invoked for the
25
+ * same reason.
26
+ */
27
+ export declare const DEFAULT_WATCH_GLOBAL = "__uapWatch";
28
+ /**
29
+ * Build the init script under a caller-chosen global name.
30
+ *
31
+ * The name is randomised per run because the page can otherwise DEFEAT its own
32
+ * watchdog: `window.__uapWatch = {ticks: 1e9, errors: []}` forges liveness and
33
+ * empties the error list, and the `if (already defined) return` guard means a
34
+ * page that predefines the global blocks instrumentation outright. Randomising
35
+ * is not a security boundary — it raises the cost of a targeted forge, while
36
+ * the authoritative error channel remains Playwright-side, out of page reach.
37
+ */
38
+ export declare function buildWatchdogInitScript(globalName?: string): string;
39
+ export declare const WATCHDOG_INIT_SCRIPT = "(function () {\n try {\n if (window.__uapWatch) return;\n var w = { ticks: 0, errors: [], startedAt: Date.now() };\n window.__uapWatch = w;\n var raf = window.requestAnimationFrame;\n if (typeof raf === 'function') {\n window.requestAnimationFrame = function (cb) {\n return raf.call(window, function (t) {\n w.ticks++;\n return cb(t);\n });\n };\n }\n window.addEventListener('error', function (e) {\n try { w.errors.push('uncaught: ' + (e && e.message ? e.message : String(e))); } catch (x) {}\n });\n window.addEventListener('unhandledrejection', function (e) {\n try { w.errors.push('unhandledrejection: ' + String(e && e.reason)); } catch (x) {}\n });\n } catch (x) {\n /* the watchdog must never break the page it observes */\n }\n})()";
40
+ /**
41
+ * Read one watchdog sample. `watchExprs` are artifact expressions yielding
42
+ * numbers (collection sizes, key state fields) — the miner supplies them, and
43
+ * each one that goes NaN or grows without bound becomes a defect.
44
+ */
45
+ /**
46
+ * NaN cannot survive the JSON transport — `JSON.stringify(NaN)` is `null`, so a
47
+ * corrupted field arrives indistinguishable from "not present" and the NaN check
48
+ * can never fire in production. Encode it explicitly and decode on the way back.
49
+ */
50
+ export declare const NAN_SENTINEL = "__uap_NaN__";
51
+ export declare function watchdogSampleScript(watchExprs: string[], globalName?: string): string;
52
+ export interface WatchdogSample {
53
+ ticks: number;
54
+ errors: string[];
55
+ values: Record<string, number | null>;
56
+ /**
57
+ * Which uninterrupted run of the artifact this sample belongs to. Per-probe
58
+ * page reloads restart every counter, so growth may only be compared inside
59
+ * one segment — across a reload the endpoints do not bracket a continuous run.
60
+ */
61
+ segment?: number;
62
+ }
63
+ export declare function parseWatchdogSample(raw: unknown): WatchdogSample | null;
64
+ /** Does this expression observe the SIZE of a collection (vs a counter)? */
65
+ export declare function isCollectionSize(expr: string): boolean;
66
+ export interface WatchdogOptions {
67
+ /** Minimum ticks in the final window before the loop counts as alive. */
68
+ minTicks?: number;
69
+ /** Growth factor over the first sample that counts as unbounded. */
70
+ growthFactor?: number;
71
+ /** Absolute floor before growth is even considered (ignore tiny collections). */
72
+ growthFloor?: number;
73
+ }
74
+ /**
75
+ * Pure verdict from the observed samples. Kept free of IO so the interesting
76
+ * judgements are unit-testable without a browser.
77
+ */
78
+ export declare function judgeWatchdog(samples: WatchdogSample[], driverErrors?: string[], opts?: WatchdogOptions): WatchdogReport;
79
+ /** True when the watchdog saw something that should fail the gate. */
80
+ export declare function watchdogFailed(r: WatchdogReport): boolean;
81
+ export declare function watchdogSummary(r: WatchdogReport): string;
82
+ //# sourceMappingURL=watchdog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchdog.d.ts","sourceRoot":"","sources":["../../../src/delivery/interaction/watchdog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,GAAE,MAA6B,GAAG,MAAM,CAEzF;AAED,eAAO,MAAM,oBAAoB,k0BAuB5B,CAAC;AAEN;;;;GAIG;AACH;;;;GAIG;AACH,eAAO,MAAM,YAAY,gBAAgB,CAAC;AAE1C,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAAE,EACpB,UAAU,GAAE,MAA6B,GACxC,MAAM,CAaR;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAiBvE;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,MAAM,WAAW,eAAe;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,cAAc,EAAE,EACzB,YAAY,GAAE,MAAM,EAAO,EAC3B,IAAI,GAAE,eAAoB,GACzB,cAAc,CAyEhB;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAEzD;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAkBzD"}
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Interaction watchdog — invariants that hold for EVERY probe, checked
3
+ * independently of what any individual probe asserts.
4
+ *
5
+ * Probes prove the promised behaviour. The watchdog catches the failures nobody
6
+ * thought to write a probe for: the loop stops ticking, an uncaught error fires,
7
+ * a tracked number goes NaN, a collection grows without bound. Tonight's fatal
8
+ * defect (`player.takeDamage is not a function`) is exactly the first class —
9
+ * one uncaught throw, the rAF loop never rescheduled, and every later frame was
10
+ * a frozen copy of the last good one, which no screenshot can distinguish from a
11
+ * paused game.
12
+ */
13
+ /**
14
+ * Injected before any page script runs. Wraps requestAnimationFrame to count
15
+ * ticks and records uncaught errors. Deliberately defensive: a page that
16
+ * replaces rAF or throws during setup must not break the watchdog itself.
17
+ *
18
+ * SELF-INVOKED — `addInitScript` evaluates the string as source, so a bare
19
+ * function expression would construct a function and discard it. That mistake
20
+ * is invisible at runtime: the counters simply never appear, every sample falls
21
+ * back to `ticks: 0`, `everTicked` stays false and `loopAlive` is unconditionally
22
+ * true — the frozen-loop detection this gate exists for silently never fires.
23
+ * Matches RAF_INSTRUMENT in execution-gate.ts, which is self-invoked for the
24
+ * same reason.
25
+ */
26
+ export const DEFAULT_WATCH_GLOBAL = '__uapWatch';
27
+ /**
28
+ * Build the init script under a caller-chosen global name.
29
+ *
30
+ * The name is randomised per run because the page can otherwise DEFEAT its own
31
+ * watchdog: `window.__uapWatch = {ticks: 1e9, errors: []}` forges liveness and
32
+ * empties the error list, and the `if (already defined) return` guard means a
33
+ * page that predefines the global blocks instrumentation outright. Randomising
34
+ * is not a security boundary — it raises the cost of a targeted forge, while
35
+ * the authoritative error channel remains Playwright-side, out of page reach.
36
+ */
37
+ export function buildWatchdogInitScript(globalName = DEFAULT_WATCH_GLOBAL) {
38
+ return WATCHDOG_INIT_SCRIPT.split(DEFAULT_WATCH_GLOBAL).join(globalName);
39
+ }
40
+ export const WATCHDOG_INIT_SCRIPT = `(function () {
41
+ try {
42
+ if (window.__uapWatch) return;
43
+ var w = { ticks: 0, errors: [], startedAt: Date.now() };
44
+ window.__uapWatch = w;
45
+ var raf = window.requestAnimationFrame;
46
+ if (typeof raf === 'function') {
47
+ window.requestAnimationFrame = function (cb) {
48
+ return raf.call(window, function (t) {
49
+ w.ticks++;
50
+ return cb(t);
51
+ });
52
+ };
53
+ }
54
+ window.addEventListener('error', function (e) {
55
+ try { w.errors.push('uncaught: ' + (e && e.message ? e.message : String(e))); } catch (x) {}
56
+ });
57
+ window.addEventListener('unhandledrejection', function (e) {
58
+ try { w.errors.push('unhandledrejection: ' + String(e && e.reason)); } catch (x) {}
59
+ });
60
+ } catch (x) {
61
+ /* the watchdog must never break the page it observes */
62
+ }
63
+ })()`;
64
+ /**
65
+ * Read one watchdog sample. `watchExprs` are artifact expressions yielding
66
+ * numbers (collection sizes, key state fields) — the miner supplies them, and
67
+ * each one that goes NaN or grows without bound becomes a defect.
68
+ */
69
+ /**
70
+ * NaN cannot survive the JSON transport — `JSON.stringify(NaN)` is `null`, so a
71
+ * corrupted field arrives indistinguishable from "not present" and the NaN check
72
+ * can never fire in production. Encode it explicitly and decode on the way back.
73
+ */
74
+ export const NAN_SENTINEL = '__uap_NaN__';
75
+ export function watchdogSampleScript(watchExprs, globalName = DEFAULT_WATCH_GLOBAL) {
76
+ const entries = watchExprs
77
+ .map((e) => {
78
+ const key = JSON.stringify(e);
79
+ return ` try { var v = (${e}); vals[${key}] = (typeof v === 'number' && v !== v) ? ${JSON.stringify(NAN_SENTINEL)} : v; } catch (x) { vals[${key}] = null; }`;
80
+ })
81
+ .join('\n');
82
+ return `(function () {
83
+ var w = window[${JSON.stringify(globalName)}] || { ticks: 0, errors: [] };
84
+ var vals = {};
85
+ ${entries}
86
+ return JSON.stringify({ ticks: w.ticks, errors: w.errors.slice(0, 20), values: vals });
87
+ })`;
88
+ }
89
+ export function parseWatchdogSample(raw) {
90
+ try {
91
+ const text = typeof raw === 'string' ? raw : JSON.stringify(raw);
92
+ const parsed = JSON.parse(text);
93
+ if (!parsed || typeof parsed !== 'object')
94
+ return null;
95
+ const values = {};
96
+ for (const [k, v] of Object.entries(parsed.values ?? {})) {
97
+ values[k] = v === NAN_SENTINEL ? Number.NaN : v;
98
+ }
99
+ return {
100
+ ticks: Number(parsed.ticks) || 0,
101
+ errors: Array.isArray(parsed.errors) ? parsed.errors.map(String) : [],
102
+ values,
103
+ };
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ }
109
+ /** Does this expression observe the SIZE of a collection (vs a counter)? */
110
+ export function isCollectionSize(expr) {
111
+ return /\.(length|size)\s*$/.test(expr) || /\.(length|size)\b/.test(expr);
112
+ }
113
+ /**
114
+ * Pure verdict from the observed samples. Kept free of IO so the interesting
115
+ * judgements are unit-testable without a browser.
116
+ */
117
+ export function judgeWatchdog(samples, driverErrors = [], opts = {}) {
118
+ const minTicks = opts.minTicks ?? 1;
119
+ const growthFactor = opts.growthFactor ?? 20;
120
+ const growthFloor = opts.growthFloor ?? 500;
121
+ const errors = [...new Set([...samples.flatMap((s) => s.errors), ...driverErrors])];
122
+ const first = samples[0];
123
+ const last = samples[samples.length - 1];
124
+ const prev = samples.length >= 2 ? samples[samples.length - 2] : first;
125
+ // Ticks in the FINAL window: a loop that ran for two seconds and then died
126
+ // still has a large cumulative count, so only the last interval is evidence
127
+ // that it is alive NOW.
128
+ const ticksObserved = last && prev ? Math.max(0, last.ticks - prev.ticks) : 0;
129
+ // A page with no rAF at all (a form, a static doc) legitimately never ticks.
130
+ // Only claim the loop is dead when it demonstrably ticked earlier.
131
+ const everTicked = (last?.ticks ?? 0) > 0;
132
+ // TWO samples minimum. With one, `prev === last`, the delta is 0 by
133
+ // construction, and any artifact that ever ticked is declared dead — so a
134
+ // single dropped watchdog read would fail a perfectly healthy build. Liveness
135
+ // is a claim about change over time and needs two points to make.
136
+ const loopAlive = samples.length < 2 || !everTicked || ticksObserved >= minTicks;
137
+ // NaN over EVERY sample, not just the last. Judging only the final sample
138
+ // meant a field corrupted during any earlier probe was wiped by the next
139
+ // page reload and never seen — the check silently became "did the LAST probe
140
+ // produce NaN".
141
+ const nanSet = new Set();
142
+ for (const s of samples) {
143
+ for (const [key, v] of Object.entries(s.values)) {
144
+ if (typeof v === 'number' && Number.isNaN(v))
145
+ nanSet.add(key);
146
+ }
147
+ }
148
+ const nanFields = [...nanSet];
149
+ // Growth compared only WITHIN a contiguous segment: across a reload the
150
+ // start and end points belong to different runs of the artifact, so the
151
+ // comparison is meaningless (and a real leak measured over one short probe
152
+ // never crosses the floor).
153
+ const growth = new Map();
154
+ const bySegment = new Map();
155
+ for (const s of samples) {
156
+ const seg = s.segment ?? 0;
157
+ if (!bySegment.has(seg))
158
+ bySegment.set(seg, []);
159
+ bySegment.get(seg).push(s);
160
+ }
161
+ for (const group of bySegment.values()) {
162
+ const a = group[0];
163
+ const b = group[group.length - 1];
164
+ if (!a || !b || a === b)
165
+ continue;
166
+ for (const key of Object.keys(b.values)) {
167
+ // Growth means "a COLLECTION grew without bound". An ordinary counter —
168
+ // a score, a frame number, elapsed time — is supposed to climb, and
169
+ // flagging it reports a leak in a working game (observed: score 0 →
170
+ // 38 060 reported as unbounded growth). Only size-like observations
171
+ // qualify; every watched value is still checked for NaN.
172
+ if (!isCollectionSize(key))
173
+ continue;
174
+ const start = a.values[key];
175
+ const end = b.values[key];
176
+ if (typeof start === 'number' &&
177
+ typeof end === 'number' &&
178
+ !Number.isNaN(end) &&
179
+ end > growthFloor &&
180
+ end > Math.max(1, start) * growthFactor) {
181
+ growth.set(key, `${key}: ${start} → ${end}`);
182
+ }
183
+ }
184
+ }
185
+ const unboundedGrowth = [...growth.values()];
186
+ return { errors, loopAlive, ticksObserved, nanFields, unboundedGrowth };
187
+ }
188
+ /** True when the watchdog saw something that should fail the gate. */
189
+ export function watchdogFailed(r) {
190
+ return r.errors.length > 0 || !r.loopAlive || r.nanFields.length > 0 || r.unboundedGrowth.length > 0;
191
+ }
192
+ export function watchdogSummary(r) {
193
+ const lines = [];
194
+ if (r.errors.length > 0) {
195
+ lines.push(`✗ runtime errors (${r.errors.length}): ${r.errors.slice(0, 5).join(' | ')}`);
196
+ }
197
+ if (!r.loopAlive) {
198
+ lines.push(`✗ the main loop STOPPED — ${r.ticksObserved} frame(s) in the final sampling window. ` +
199
+ `An uncaught error inside a requestAnimationFrame callback stops the loop being ` +
200
+ `rescheduled; every later frame is a frozen copy of the last good one, which looks ` +
201
+ `identical to a working paused screen in a screenshot.`);
202
+ }
203
+ if (r.nanFields.length > 0)
204
+ lines.push(`✗ NaN in tracked state: ${r.nanFields.join(', ')}`);
205
+ if (r.unboundedGrowth.length > 0) {
206
+ lines.push(`✗ unbounded growth (leak): ${r.unboundedGrowth.join(', ')}`);
207
+ }
208
+ return lines.join('\n');
209
+ }
210
+ //# sourceMappingURL=watchdog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watchdog.js","sourceRoot":"","sources":["../../../src/delivery/interaction/watchdog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAEjD;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAAC,aAAqB,oBAAoB;IAC/E,OAAO,oBAAoB,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;KAuB/B,CAAC;AAEN;;;;GAIG;AACH;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAE1C,MAAM,UAAU,oBAAoB,CAClC,UAAoB,EACpB,aAAqB,oBAAoB;IAEzC,MAAM,OAAO,GAAG,UAAU;SACvB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC9B,OAAO,sBAAsB,CAAC,WAAW,GAAG,4CAA4C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,4BAA4B,GAAG,aAAa,CAAC;IACnK,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO;mBACU,IAAI,CAA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AAM,GAAG,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,MAAM,CAAC,MAAM,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;QACjB,KAAK,CAAC,IAAI,CACR,6BAA6B,CAAC,CAAC,aAAa,0CAA0C;YACpF,iFAAiF;YACjF,oFAAoF;YACpF,uDAAuD,CAC1D,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5F,IAAI,CAAC,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Web driver — drives a real headless browser with real pointer and key input.
3
+ *
4
+ * Deliberately uses coordinate-level mouse control rather than selector clicks:
5
+ * inside a <canvas> there are no elements to target, so aiming and firing only
6
+ * exist as pointer positions. A gate that can only click selectors cannot play a
7
+ * game, and "cannot play it" is indistinguishable from "it works".
8
+ */
9
+ import { type InteractionDriver, type ReadResult } from './driver.js';
10
+ import type { Step } from './types.js';
11
+ /** The subset of WebBrowser the driver needs — keeps tests free of a browser. */
12
+ export interface PointerBrowser {
13
+ launch(opts?: Record<string, unknown>): Promise<unknown>;
14
+ goto(url: string): Promise<string>;
15
+ waitForLoadState(state?: 'load' | 'domcontentloaded' | 'networkidle'): Promise<void>;
16
+ addInitScript(script: string): Promise<void>;
17
+ evaluate<T>(script: string): Promise<T>;
18
+ screenshot(path: string): Promise<void>;
19
+ getErrors(): Array<{
20
+ kind: string;
21
+ message: string;
22
+ }>;
23
+ mouseMove(x: number, y: number): Promise<void>;
24
+ mouseDown(): Promise<void>;
25
+ mouseUp(): Promise<void>;
26
+ mouseClick(x: number, y: number): Promise<void>;
27
+ press(key: string): Promise<void>;
28
+ viewportSize(): Promise<{
29
+ width: number;
30
+ height: number;
31
+ }>;
32
+ close(): Promise<void>;
33
+ }
34
+ export interface WebDriverOptions {
35
+ projectRoot: string;
36
+ /** Entry html path relative to the served root (default index.html). */
37
+ entry?: string;
38
+ /** Directory that becomes the server root (default: the project root). */
39
+ webRoot?: string;
40
+ browserFactory?: () => Promise<PointerBrowser>;
41
+ serverFactory?: (dir: string, entry: string) => Promise<{
42
+ url: string;
43
+ close: () => void;
44
+ }>;
45
+ }
46
+ export declare class WebInteractionDriver implements InteractionDriver {
47
+ private browser;
48
+ private server;
49
+ private readonly opts;
50
+ /** Last pointer position, so `down`/`up` act where the pointer actually is. */
51
+ private pointer;
52
+ private launched;
53
+ /** Per-run instrumentation global — see buildWatchdogInitScript. */
54
+ private readonly watchGlobal;
55
+ constructor(opts: WebDriverOptions);
56
+ start(): Promise<void>;
57
+ /**
58
+ * Reload the entry page. Init scripts are registered on the CONTEXT, so the
59
+ * watchdog re-installs automatically on the fresh document.
60
+ */
61
+ reset(): Promise<void>;
62
+ /** True once the browser is up — distinguishes infra failure from load failure. */
63
+ didLaunch(): boolean;
64
+ /** A probe may only navigate within the artifact's own served origin. */
65
+ private sameOrigin;
66
+ runStep(step: Step): Promise<void>;
67
+ /**
68
+ * Evaluate an observation. Wrapped in a function so `const`/`let` declared at
69
+ * the top level of a classic script — which live in the global LEXICAL scope
70
+ * and are NOT properties of `window` — are still readable. Reading these
71
+ * through `window.X` returns undefined, which silently turns every assertion
72
+ * into "undefined", so the wrapper matters.
73
+ */
74
+ read(expr: string): Promise<unknown>;
75
+ /**
76
+ * `ok: false` means the expression THREW or named something undefined — a
77
+ * broken probe, reported as such rather than as a behavioural failure.
78
+ * `undefined` reached by a resolving expression stays `ok: true`.
79
+ */
80
+ readDetailed(expr: string): Promise<ReadResult>;
81
+ inject(expr: string): Promise<void>;
82
+ /**
83
+ * GATING errors only: uncaught page exceptions.
84
+ *
85
+ * `console.error` output and failed sub-resource requests are common in
86
+ * working apps — a missing decorative asset or a handled-and-logged warning
87
+ * would otherwise hard-fail the behavioural gate. Both sibling gates already
88
+ * refuse to gate on them (execution-gate treats them as advisory;
89
+ * visual-gate filters to `pageerror`), and a gate that false-fails working
90
+ * builds gets switched off.
91
+ */
92
+ errors(): string[];
93
+ /** Sample the watchdog under this run's private global name. */
94
+ watchdogSample(watchExprs: string[]): Promise<unknown>;
95
+ /** Non-gating observations, surfaced in the report as context. */
96
+ advisoryErrors(): string[];
97
+ capture(path: string): Promise<void>;
98
+ stop(): Promise<void>;
99
+ }
100
+ /** Where probe evidence (screenshots) is written. */
101
+ export declare function evidenceDir(projectRoot: string): string;
102
+ //# sourceMappingURL=web-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-driver.d.ts","sourceRoot":"","sources":["../../../src/delivery/interaction/web-driver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAS,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,gBAAgB,CAAC,KAA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