317 Commits

Author SHA1 Message Date
58e95b5443 Merge pull request 'Milestone v1 (v2.0.0): Mokosh — Session Capture' (#1) from gsd/phase-04-harden-clean-up-optional into main
Reviewed-on: #1
v1.0
2026-05-31 15:34:17 +00:00
0d1726bf75 docs(phase-04): closure ceremony — milestone v1 complete
phase.complete CLI ran (commit n/a — CLI in-mem only) with documented
defects per recurring state.record-session bug:
- completed_phases stuck at 3 (should be 4)
- percent regressed to 75% (3/4 math; should be 100% — milestone-complete)
- ROADMAP Phase 4 row still [ ] despite roadmap_updated:true claim

Manual fix applied per saved memory (canonical workaround for CLI bug):

STATE.md:
- completed_phases: 3 → 4
- percent: 75 → 100
- progress bar: [█████████▓] 97% → [██████████] 100%

ROADMAP.md:
- Phase 4 row: [ ] → [x] with comprehensive closure annotation
  (8 plans + 3 debug sessions + 4 ROADMAP SCs + 5 D-P4-* + UAT
  33→36 + vitest 171→188 + bundle gates 6/6 + Tier-1 12 + Tier-2 added
  + operator ack 2026-05-26 + verifier audit PASSED 8ffc6cb)

Phase 4 closed end-to-end. Milestone v1 v2.0.0 complete (status:
milestone_complete already correctly set by CLI). Ready for v1.0 tag +
alpha redistribution per D-P4-04 (user routes out-of-band).
2026-05-26 14:44:25 +02:00
8ffc6cbbd4 docs(04-verification): independent gsd-verifier audit — Phase 4 PASSED (4/4 ROADMAP SCs + all spot-checks GREEN)
Goal-backward verification of Phase 4 (harden-clean-up-optional) against the
actual codebase. Supersedes and replaces the Plan 04-07 executor aggregator
with the canonical independent audit document.

Spot-checks performed against live codebase (HEAD c27ad53):
- 36 harness drivers confirmed in harness.test.ts (A1-A35 incl. A33 env-gated)
- 12 FORBIDDEN_HOOK_STRINGS counted verbatim in no-test-hooks-in-prod-bundle.test.ts
- Tier-2 synthetic-display-source gate confirmed in test + dist/ grep = 0
- --mks-mark-stroke in tokens.css :root ONLY (single occurrence; NOT in .dark block)
- mokosh-mark.svg stroke="currentColor" confirmed
- welcome.ts ?raw + DOMParser + replaceChildren (no innerHTML) confirmed
- No dispatchSaveArchive helper in src/ (test-only helper in tests/ only)
- A35 with 5 sub-checks including A35.5 light+dark equality confirmed
- generate-icons.cjs present; generate-icons.js absent (SC #3)
- permissions.request absent from src/ (SC #4)
- new Function count in dist/assets/index.ts-*.js = 0 (H1)
- P1 #11/#14/#15 fixes confirmed at src/content/index.ts lines 194/214/31/318

Status: passed (0 overrides; 11/11 truths VERIFIED; operator empirical ack RECEIVED 2026-05-26)
Pending: orchestrator closure ceremony (ROADMAP Phase 4 [x] + completed_phases:3→4)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 14:25:42 +02:00
c27ad53d02 docs(04-07): complete harden-clean-up-optional plan 04-07 — Phase 4 closure aggregator + v1 milestone close-prep (2 tasks; 04-VERIFICATION.md + 4 marker file flips)
Plan 04-07 closure SUMMARY. Phase 4 closure-prep complete; pending
independent gsd-verifier audit + closure-ceremony marker flips per
Phase 1-3 precedent.

Deliverables:
- .planning/phases/04-harden-clean-up-optional/04-VERIFICATION.md
  (253 lines; 13 ## sections; 67 Plan 04-0 citations; 9 operator-ack
  literal hits; 44 commit refs; covers all 8 Phase 4 plans + 3 /gsd-debug
  sessions + 4 ROADMAP SC + 3 audit P1 + 6 cross-cutting hardening +
  5/5 D-P4-* charters + Phases 1-4 cumulative gates)
- .planning/REQUIREMENTS.md (4 Phase 4 closure notes appended; trailing
  footer updated; no existing REQ-* lines modified)
- .planning/ROADMAP.md (Plan 04-07 row [x] flipped + progress table
  updated 7/8 → 8/8; Phase 4 row [ ] LEFT unflipped per Phase 1-3 precedent)
- .planning/STATE.md (completed_plans 29→30 + percent 93→97;
  completed_phases STAYS 3 + status STAYS executing; Plan 04-07 closure
  section + decisions + metric + session continuity)
- .planning/PROJECT.md (NEW Validated in Phase 4 section; Active section
  evolution to closure ceremony + v1.1/v2 deferred items)

Acceptance criteria all PASS (gates per Plan 04-07 verify block):
- 04-VERIFICATION.md exists, parseable YAML, 13 ## sections (>= 5),
  253 lines (>= 120), 67 Plan 04-0 citations (>= 6), 9 operator-ack
  literal hits (>= 1), 44 commit refs (>= 6)
- ROADMAP.md Plan 04-07 [x] = 1; Phase 4 [x] = 0 (correctly LEFT unflipped)
- STATE.md completed_phases: 3 (UNCHANGED); completed_plans: 30 (+1);
  status: executing (UNCHANGED); percent: 97 (+4)
- REQUIREMENTS.md Phase 4 closure notes = 4 (>= 3); PROJECT.md
  Validated in Phase 4 = 1
- git diff --stat HEAD~3 HEAD shows only .planning/ files dirty
  (T-04-07-02 threat mitigation honored — docs-only closure)

Phase 4 cumulative tally (final via Plan 04-07 aggregator):
- 8 plans closed (04-01..04-08; inserted Plan 04-08 Wave 5.5 post-debug)
- 31 plans total across Phases 1-4 (14 + 4 + 5 + 8)
- UAT harness 33 → 36 GREEN (+A33 + A34 + A35)
- vitest 171 → 188 GREEN (+17 across Plans 04-01/02/06/08)
- Pre-checkpoint bundle gates 6/6 PASS (Gate 2 polarity flipped 1→0)
- Tier-1 FORBIDDEN_HOOK_STRINGS unchanged at 12 entries
- NEW Tier-2 production-bundle filename-leak gate (Plan 04-08)
- 3 /gsd-debug sessions documented + resolved
- 5/5 D-P4-* charter closures (D-P4-01..D-P4-05)
- 1 operator-empirical ack 2026-05-26: "Confirmed fixed — close Plan 04-06"

Next step (orchestrator workstream): independent gsd-verifier audit
against 04-VERIFICATION.md → Phase 4 row [x] flip + STATE.md
completed_phases 3→4 + status:executing→completed → v1.0 tag + alpha
redistribution per D-P4-04 charter (out-of-band).
2026-05-26 14:12:03 +02:00
5d0b40c9b6 docs(04-07): closure markers — REQUIREMENTS + ROADMAP + STATE + PROJECT for Phase 4 v1 close-prep
Task 2 of Plan 04-07 — 4 marker file flips landing Phase 4 closure-prep
(NOT formal Phase 4 closure; that happens at the ceremony AFTER the
independent gsd-verifier audit per Phase 1-3 precedent).

ROADMAP.md:
- Plan 04-07 row flipped [ ] → [x] with full closure annotation (04-VERIFICATION.md
  citation + Phase 4 cumulative totals + D-P4-05 backfill verification + closure-
  ceremony deferral note)
- Phase 4 progress table cell updated 7/8 → 8/8 with full closure-prep narrative
- Phase 4 row [ ] LEFT UNFLIPPED — verifier audit + closure ceremony flips it

STATE.md:
- progress.completed_plans: 29 → 30 + progress.percent: 93 → 97
- progress.completed_phases: 3 (UNCHANGED) + status: executing (UNCHANGED)
- stopped_at + last_updated + last_activity updated for Plan 04-07 closure
- Current Position block updated to reflect Plan 04-07 completion + pending
  closure ceremony
- Plan 04-07 closure section added at top of body
- Performance metrics row added for Phase 04 P07
- Session Continuity entry prepended for Plan 04-07
- 2 Phase 04-07 decisions appended to Decisions list

REQUIREMENTS.md:
- 4 Phase 4 closure notes appended to existing REQ blocks (no existing REQ-*
  lines modified):
  - REQ-video-ring-buffer: ROADMAP SC #1 via Plan 04-08 (methodology reframe)
  - REQ-rrweb-dom-buffer: A29 cs-injection-world + UAT 33→36 GREEN summary
  - REQ-user-event-log: ROADMAP SC #2 via Plan 04-05 + audit P1 #11/#14/#15
    via Plan 04-01
  - REQ-install-clean: ROADMAP SC #3/SC #4/Plan 04-02 build hygiene + Plan
    04-08 Tier-2 leak gate
- Trailing footer line updated with 2026-05-26 Phase 4 closure citation

PROJECT.md:
- NEW Validated in Phase 4 section added (7 bullets covering all closures)
- Active section evolved from Phase 4 backlog → Phase 4 closure-ceremony
  workstream + Deferred-to-v1.1/v2 maintenance milestone items
- Trailing footer line updated with 2026-05-26 Phase 4 closure citation

Acceptance criteria gates (all PASS per Plan 04-07 Task 2):
- ROADMAP.md 04-07 row [x] = 1
- ROADMAP.md Phase 4 row [x] = 0 (correctly LEFT unflipped)
- STATE.md completed_phases: 3 = 2 (frontmatter + body — UNCHANGED per spec)
- STATE.md completed_plans: 30 = 1 (incremented by 1)
- STATE.md status: executing = 1 (UNCHANGED per spec)
- REQUIREMENTS.md "Phase 4 closure note" mentions = 4 (>= 3)
- PROJECT.md "Validated in Phase 4" section = 1
- git diff --stat HEAD~1 HEAD shows only .planning/ files dirty (T-04-07-02
  threat mitigation gate honored — docs-only commit; no source/test changes)

Phase 4 row + completed_phases bump + status:completed flip explicitly
DEFERRED to closure ceremony after the independent gsd-verifier audit
per Phase 1-3 precedent (executor creates VERIFICATION.md; verifier
independently re-validates with goal-backward audit; orchestrator flips
markers post-verifier-audit).
2026-05-26 14:08:17 +02:00
7a69865843 docs(04-07): Phase 4 closure — 04-VERIFICATION.md aggregator (4/4 ROADMAP SCs + 3/3 audit P1 + 6/6 hardening items GREEN)
Task 1 of Plan 04-07 — executor-created aggregator covering all 8 Phase 4
plans + 3 /gsd-debug sessions + 4 ROADMAP SC closures + 3 audit P1 polish
items + 6 cross-cutting hardening items + 36/36 UAT harness + 188/188
vitest + 6/6 pre-checkpoint bundle gates (Gate 2 polarity flipped 1→0
via Plan 04-02) + Tier-1 FORBIDDEN_HOOK_STRINGS unchanged at 12 + NEW
Tier-2 leak gate added via Plan 04-08 + operator empirical ack 'Confirmed
fixed — close Plan 04-06' 2026-05-26.

- Per-Requirement Scorecard: 4/4 ROADMAP SC + 3/3 audit P1 + 6/6 hardening
- Cross-Cutting Gates: vitest 171→188; UAT 33→36; Tier-1 12; Tier-2 NEW
- Operator-Empirical Acks: Plan 04-06 cycle-2 'Confirmed fixed' 2026-05-26
- /gsd-debug Session Inventory: 3 sessions (canvas-throttling REFUTED-arch
  via sessions 1+2; Plan 04-06 dark-mode mark decoupling; A33.1 SAVE-ack
  race resolved at 7e0da63)
- D-P4-* Charter Closures: 5/5 (D-P4-01..D-P4-05)
- ROADMAP backfill verification (D-P4-05): Plans 01-08..01-14 rows all
  present at lines 90-96 with [x] closure annotations
- Per-Phase Plans Across Phases 1-4: 14+4+5+8 = 31 plans total
- Threat Surface Scan: no new production surface; Plan 04-08 added
  test-only WebM asset (Tier-2 gate verifies 0 hits in dist/)
- Deferred Items: 8 entries (rrweb v2 + SW-RAM measurement + REQ-password-
  confidentiality + spike script + alpha-tester + A29/A30/A31 flake +
  04-CONTEXT #9/#10 parallel-vitest + A33 SAVE-ack race resolved)

Acceptance criteria:
- 13 ## sections (>= 5)
- 67 'Plan 04-0' citations (>= 6)
- 9 operator-ack literal hits (>= 1)
- 253 lines (>= 120)
- 44 commit mentions (>= 6)

Status: executor-created aggregator; independent gsd-verifier audit runs
after Plan 04-07 closure to elevate to formally-CLOSED state.
2026-05-26 13:32:18 +02:00
c790c6a8b3 docs(04-06): complete visual polish + dark-logo decoupling — D-P4-03 closed (UAT 36/36 GREEN; 188/188 vitest with #9/#10 flake tolerated; operator re-confirmed 2026-05-26)
Plan 04-06 closure — the most ceremony-heavy plan in Phase 4: 3 planner
passes + 2 plan-checker passes + 4 task commits + 1 /gsd-debug fix cycle
+ this closure commit. D-P4-03 (locked, 04-CONTEXT.md) CLOSED — both
visual polish items: (a) cursor visibility verification + (b) dark-surface
logo contrast.

Closure trail:
  6a989e8 mis-diagnosed strict-meta-json deferred-items entry
  b59bd24 re-plan iter-1 — correct false jsdom premise + back-patch lines
  deb68df re-plan-checker iter-1 — ITERATE-NEEDED (2 BLOCKER)
  f3baa3a re-plan iter-2 — real A35 + corrected 184/184 baseline
  48c7053 re-plan-checker iter-2 — PASSED (0B + 0W + 3 cosmetic-advisories)
  f0b88d4 Task 1 — Wave 0 RED inline-SVG source-contract + cursor pin
  c416143 Task 2 — Wave 1 GREEN SVG+welcome.ts+globals.d.ts
  3f8e31a Task 3 — A35 driver + A17.8 narrowed + back-patch + correction
  d66cbf6 Task 4 artifact — operator-empirical screenshot harness
  (Task 4 first operator empirical: TWEAK verdict 2026-05-26)
  a8bcc17 debug-fix — decouple via --mks-mark-stroke + A35.5 sub-check
  (Task 4 re-empirical: CONFIRMED FIXED 2026-05-26)
  THIS    closure (SUMMARY + STATE.md + ROADMAP.md + debug archive)

Key deliverables:
- mokosh-mark.svg stroke="#181b2a" -> stroke="currentColor"
- welcome.ts ?url/<img> -> ?raw/DOMParser/replaceChildren inline-<svg>
- globals.d.ts *.svg?raw ambient decl
- src/shared/tokens.css NEW --mks-mark-stroke = var(--mks-linen-50) in :root
  (NOT overridden in .dark — theme-independent brand-component token)
- src/welcome/welcome.css .welcome-hero__mark rewired to --mks-mark-stroke
- NEW A35 host-side harness (5 sub-checks incl. A35.5 light+dark equality
  decouple-proof) at tests/uat/lib/harness-page-driver.ts
- A17.8 honestly narrowed to SOURCE-BUNDLING only; points to A35
- tests/welcome/inline-svg.test.ts (3 source-contract tests)
- tests/build/cursor-visibility.test.ts (1 regression pin)
- scripts/04-06-welcome-hero-screenshots.mjs (reproducible artifact)
- 01-07-SUMMARY back-patch (5 stale lines flipped; 4 historical left)
- deferred-items.md mis-diagnosis correction

Baselines preserved:
- vitest 188/188 GREEN (most recent 187/188 with 04-CONTEXT #9/#10
  webm-remux flake; passes in isolation; tolerated per Task 2 gate)
- UAT 36/36 GREEN; FORBIDDEN_HOOK_STRINGS unchanged at 12
- Pre-checkpoint bundle gates 6/6 PASS at both checkpoint + re-checkpoint
- All 4 ROADMAP SC CLOSED; D-P4-03 CLOSED

Phase 4 progress: 6/8 -> 7/8 (Plan 04-07 NEXT).

SUMMARY: .planning/phases/04-harden-clean-up-optional/04-06-SUMMARY.md
Debug session archived: .planning/debug/resolved/04-06-dark-mode-mark-decouple.md
2026-05-26 13:14:41 +02:00
a8bcc17822 fix(debug 04-06): decouple welcome-hero mark stroke via --mks-mark-stroke
Operator-empirical Task 4 checkpoint flagged the dark-mode mark stroke
as muddy ink-on-madder. Root cause: .welcome-hero__mark used
`color: var(--mks-fg-inverse)`, which is a SEMANTIC text-foreground-on-
inverse-surface token that flips to ink-900 in the dark theme
(tokens.css line 244). The mark sits on a theme-independent madder-600
circle, so the stroke must be theme-independent too.

Fix: introduce a dedicated BRAND-COMPONENT token --mks-mark-stroke =
var(--mks-linen-50) in the universal :root block. CRUCIALLY NOT
overridden in the .dark/[data-theme="dark"] block — stays linen-50 on
every surface. Rewire .welcome-hero__mark to point at the new token.

SVG (mokosh-mark.svg) unchanged — `stroke="currentColor"` cascade
plumbing identical; only the wrapper's color source changed.

A35 strengthened: extracted live-DOM probe into a helper, now probes
BOTH light + dark themes (data-theme="dark" toggle on documentElement),
and added A35.5 — the decouple proof that light.computedStroke ===
dark.computedStroke === "rgb(250, 247, 241)" (linen-50). No new
__MOKOSH_UAT__ symbol; FORBIDDEN_HOOK_STRINGS stays at 12.

Scope expansion note: src/welcome/welcome.css was not in Plan 04-06
re-plan iter-2 files_modified. The edit is authorized by the operator's
TWEAK verdict on Task 4 checkpoint.

Verification:
- /tmp/04-06-welcome-hero-{light,dark}.png re-shot — both show identical
  crisp linen-on-madder grid icon.
- A35.5 LIVE-DOM probe (UAT): light="rgb(250, 247, 241)", dark=same.
- UAT 36/36 GREEN; vitest 187 + 1 tolerated webm-remux flake.
- 6/6 pre-checkpoint bundle gates PASS; FORBIDDEN_HOOK_STRINGS = 12.

Debug session: .planning/debug/04-06-dark-mode-mark-decouple.md

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 12:54:54 +02:00
d66cbf6900 chore(04-06): add operator-empirical screenshot harness (Task 4 artifact)
Per the orchestrator checkpoint protocol + the saved-memory feedback
"trust harness over manual UAT", Task 4's dark-mode aesthetic
judgment uses Puppeteer-produced screenshots (NOT a manual Chrome
session). This script:

1. Loads dist/ via puppeteer.launch enableExtensions.
2. Resolves the runtime extension ID via the canonical
   browser.extensions() Map (mirrors tests/uat/lib/launch.ts
   resolveExtensionIdWithPolling).
3. Opens chrome-extension://<id>/src/welcome/welcome.html.
4. Captures the .welcome-hero bounding-box region in LIGHT surface
   (default OS appearance — the regression-baseline shot, matching
   the Plan 01-10 cycle-2 operator ack 2026-05-20).
5. Sets [data-theme="dark"] on <html> (Mokosh's tokens.css cascade
   uses the explicit .dark / [data-theme="dark"] selector at line
   234; emulateMediaFeatures alone does NOT trigger it because
   tokens.css has no @media (prefers-color-scheme: dark) block — a
   fact verified live this session). emulateMediaFeatures is also
   set, forward-compatible with any future @media block.
6. Re-screenshot the hero region — the DARK-surface aesthetic shot.

Output paths (canonical per the 04-06-PLAN Task 4 contract):
  - /tmp/04-06-welcome-hero-light.png
  - /tmp/04-06-welcome-hero-dark.png

Run results (this session):
  - LIGHT: computed stroke = rgb(250, 247, 241) — linen-50; the
    --mks-fg-inverse value on the LIGHT cascade flowing through
    .welcome-hero__mark to the inline <svg>'s currentColor.
  - DARK:  computed stroke = rgb(24, 27, 42) — ink-900; the
    --mks-fg-inverse value AFTER the .dark cascade override
    (tokens.css 244 sets --mks-fg-inverse: var(--mks-ink-900)) —
    the strategy's contrast flip is empirically verified.

Implementation notes (deviation Rule 3 — observed environment
constraints fixed inline):
  - Initial extension ID resolver used browser.targets() polling +
    regex; rewritten to use the canonical Puppeteer 22.x
    browser.extensions() Map approach.
  - Initial screenshot used ElementHandle.screenshot(); Puppeteer
    Runtime.callFunctionOn timed out on the second elementHandle
    evaluate in headless extension page context. Rewritten to a
    single page.evaluate() that returns getBoundingClientRect() +
    computedStroke in one CDP round trip, then page.screenshot({clip})
    against those coordinates — succeeds reliably.
  - protocolTimeout set to 120s to match the UAT harness baseline.

References:
  - .planning/phases/04-harden-clean-up-optional/04-06-PLAN.md Task 4.
  - tests/uat/lib/launch.ts (the canonical extension-loading pattern).
  - https://pptr.dev/api/puppeteer.browser.extensions
  - https://pptr.dev/api/puppeteer.page.screenshot
2026-05-26 09:11:46 +02:00
3f8e31a329 feat(04-06): A35 live-DOM inline-SVG harness check + A17.8 raw-source update + back-patch
Closes the iter-2 BLOCKER 1 resolution end-to-end: the inline-SVG
strategy now has HONEST automated coverage at two layers — source
contract (Task 1 unit tests + the narrowed A17.8 source-bundling
grep) and live-DOM cascade (the NEW host-side A35 harness assertion
that opens welcome.html as a real Puppeteer tab).

- tests/uat/extension-page-harness.ts (A17.8 NARROWED HONESTLY):
  swap the data:image/svg+xml URL-grep + .svg filename-grep target
  for a raw-source grep — A17.8 now asserts the welcome chunk JS
  contains the raw SVG signature `stroke="currentColor"` AND the
  canonical `viewBox="0 0 32 32"` (the `?raw` import's output). The
  explanatory comment block now DISAVOWS the live-DOM claim and
  points at the NEW A35 driver for the runtime injection + cascade
  proof. A17.8 is honest source-bundling only.
- tests/uat/lib/harness-page-driver.ts (NEW host-side driveA35):
  appended LAST per the iter-2 ADV-2C concern (any driver-pollution
  worry is moot since nothing reads A35's return value, AND
  welcomePage.close() in finally guarantees no tab leak). driveA35
  opens chrome-extension://<id>/src/welcome/welcome.html in a fresh
  browser.newPage() tab, waits for the `.welcome-hero__mark svg`
  selector at DOMContentLoaded, then runs a single page.evaluate()
  that reads four signals: A35.1 inline <svg> present, A35.2
  stroke=currentColor, A35.3 getComputedStyle().stroke resolves to
  a non-default colour (the real cascade proof), A35.4 no legacy
  <img> in the slot. Host-side pattern mirrors driveA32/A33/A34.
- tests/uat/harness.test.ts (orchestrator wiring):
  + driveA35 added to the import block from './lib/harness-page-driver'.
  + driveA35Wrapped closure capturing handles.browser + handles.extensionId
    (alongside driveA33Wrapped/driveA34Wrapped).
  + { name: 'A35', drive: driveA35Wrapped } appended as the LAST
    entry of the `drivers` array. Total auto-increments via
    `drivers.length + 1` (line 580) — no hardcoded count to bump.
  + Architecture banner string (line 283) refreshed with A33, A34,
    A35 inline (ADV-2A cosmetic advisory — banner was already stale
    pre-04-06; A33+A34 added at the same time).
- .planning/phases/01-stabilize-video-pipeline/01-07-SUMMARY.md
  (back-patch, DEFECT 2 resolution):
  Flipped 5 lines (22, 47, 82, 135, 205) that carried the now-stale
  "deferred to Phase 5" framing for cursor visibility — the
  `cursor: 'always'` constraint was opportunistically shipped in
  Plan 01-09 (recorder.ts:285) and is verified by Plan 04-06 Task 1
  (tests/build/cursor-visibility.test.ts). Each flip is surgical
  (single line / single bullet, with explicit "back-patched in
  Phase 4 Plan 04-06" citation). Historical commit-description
  lines 40, 89, 109, 110 are LEFT unchanged — they describe what
  the Phase-1-closure commits literally did at the time, not
  forward-looking deferrals.
- .planning/phases/04-harden-clean-up-optional/deferred-items.md
  (correction, BLOCKER 2 resolution):
  Corrected the misdiagnosed entry from commit 6a989e8. The prior
  entry named tests/build/strict-meta-json-validation.test.ts as
  failing on a clean tree — that diagnosis was WRONG (the test is
  8/8 GREEN in isolation). The real root cause is the pre-existing
  04-CONTEXT #9 + #10 parallel-vitest / ffprobe-timeout flake
  family (lands non-deterministically on whichever ffprobe / race
  test loses the worker race; observed instance this session was
  tests/background/webm-remux.test.ts > ffprobe -count_frames,
  which is also 5/5 GREEN in isolation). True clean baseline is
  184/184 GREEN; 188/188 after Plan 04-06's +4 new tests.

Gates run:
- npx tsc --noEmit exit 0.
- npm run build:test exit 0; dist-test/assets/welcome-CMygHJ_J.js
  carries the raw SVG source.
- HEADLESS=1 SKIP_PROD_REBUILD=0 SKIP_LONG_UAT=1 npm run test:uat:
  36/36 UAT assertions GREEN (was 35/35; +A35). A17.8 PASS:
  currentColorStroke=true, canonicalViewBox=true. A35 live-DOM
  probe: svgPresent=true strokeAttr=currentColor
  computedStroke="rgb(250, 247, 241)" (linen-50, the
  --mks-fg-inverse value flowing through the cascade — the
  currentColor strategy WORKS in real Chrome) imgPresent=false.
- All Task 3 acceptance greps PASS: driveA35 count in
  harness-page-driver.ts=5, in harness.test.ts=6; name:'A35'=1;
  getComputedStyle=6; stroke="currentColor" in
  extension-page-harness.ts=4; data:image/svg+xml=0 (grep target
  and comment refs both removed).

References:
- 04-06-PLAN.md iter-2 BLOCKER 1 + BLOCKER 2 resolutions.
- .planning/phases/04-harden-clean-up-optional/04-UI-SPEC.md
  §"Implementation amendment" (Option A currentColor + inline-SVG).
2026-05-26 08:48:43 +02:00
c4161431e7 feat(04-06): Wave 1 GREEN — dark-logo currentColor strategy + inline-SVG injection
UI-SPEC Option A landed end-to-end at the source layer:

- src/shared/brand/mokosh-mark.svg: single-attribute change on the root
  <svg> — stroke="#181b2a" → stroke="currentColor". The 12 <line> + 1
  <rect> children inherit stroke from the root and are UNCHANGED. This
  switches the mark from a hardcoded near-black ink to inheriting the
  parent CSS `color` cascade (W3C SVG2 §13.3).
- src/welcome/welcome.ts: `import markUrl from '..mokosh-mark.svg?url'`
  → `import markSvg from '..mokosh-mark.svg?raw'`. populateMark()
  rewritten to inline-inject the SVG via DOMParser + replaceChildren
  (NOT <img>, NEVER innerHTML — MV3 CSP discipline / T-04-06-01).
  The inline <svg> inherits `color: var(--mks-fg-inverse)` from the
  `.welcome-hero__mark` wrapper (welcome.css:67); on the dark surface
  the `.dark` token override (tokens.css 234-251) flips the resolved
  colour automatically — contrast-correct on both surfaces, no JS
  branching. The bare class selector `.welcome-hero__mark-img`
  (welcome.css:91-95) is tag-agnostic so width/height/display rules
  apply identically to the injected <svg>. role='img' + aria-label
  preserve the prior accessibility shape.
- globals.d.ts: append the `declare module '*.svg?raw'` ambient block
  alongside the existing `*.svg?url` + `*.webm?url` blocks so tsc
  accepts the new import.

Gates run:
- npx tsc --noEmit exit 0.
- npm test against tests/welcome/inline-svg.test.ts + tests/build/
  cursor-visibility.test.ts: 4/4 GREEN (the 3 Wave-0 RED inline-svg
  tests flipped to GREEN; cursor-visibility stays GREEN).
- Full vitest: 187 passed / 1 failed (188 total). The single RED is
  tests/background/webm-remux.test.ts > ffprobe -count_frames timeout
  — the documented 04-CONTEXT #9/#10 parallel-vitest / ffprobe flake
  family. Re-run in isolation: 5/5 GREEN. TOLERATED per the Task 2
  VITEST GATE LOGIC (isolation-passing flake is NOT a regression).
- npm run build exit 0; the welcome chunk JS bundles the raw SVG
  source (currentColor + viewBox="0 0 32 32" both present in
  dist/assets/welcome-Bkrf1_bZ.js).

References:
- 04-UI-SPEC.md §"Implementation amendment" (the 2-part technique).
- Vite ?raw query: https://vite.dev/guide/assets.html#importing-asset-as-string
- W3C SVG2 §13.3 (currentColor inheritance).
- DOMParser is CSP-safe per MDN (no script execution).
2026-05-26 07:58:06 +02:00
f0b88d4d17 test(04-06): Wave 0 — inline-SVG source-contract RED + cursor-visibility regression pin
- tests/welcome/inline-svg.test.ts (NEW; 3 tests, node-env source-contract):
  - Test A: mokosh-mark.svg carries stroke="currentColor" + viewBox="0 0 32 32"
    (currently RED — SVG still has stroke="#181b2a").
  - Test B: welcome.ts uses ?raw import + DOMParser + replaceChildren and
    does NOT use innerHTML (MV3 CSP discipline / T-04-06-01).
    Currently RED — welcome.ts still ?url + <img>.
  - Test C: globals.d.ts declares the *.svg?raw ambient module.
    Currently RED — only *.svg?url + *.webm?url declared.
- tests/build/cursor-visibility.test.ts (NEW; 1 test, node-env file-grep):
  - GREEN-on-arrival regression pin for the cursor: 'always' literal at
    src/offscreen/recorder.ts:285 (shipped opportunistically Plan 01-09).
- Mirrors the canonical tests/i18n/manifest-i18n.test.ts scaffold
  (readFileSync + expect(text).toContain(...)) — vitest is environment:'node'
  and the project ships no DOM-emulation library, so the inline-svg test
  pins source TEXT only; the live-DOM injection + currentColor cascade is
  verified by the host-side harness assertion A35 (Task 3).
2026-05-26 07:52:41 +02:00
48c70535ff docs(04-06): re-plan-checker iter-2 — PASSED on f3baa3a (0 BLOCKER + 3 cosmetic-advisories)
Validation of the iter-2 re-plan against commit f3baa3a. Both iter-1
BLOCKERs are correctly resolved; 3 iter-1 advisories all fixed.

BLOCKER 1 (fictitious A17.8 delegation) → RESOLVED via genuine new
host-side A35 driver. Every test-infrastructure claim was spot-checked
against live code this session:
- vite.test.config.ts:95 — welcome.html builds to dist-test/src/welcome/
- welcome.ts:194-198 — populateMark runs at DOMContentLoaded (verified)
- A17 already uses chrome.runtime.getURL('src/welcome/welcome.html') —
  same canonical URL A35 will use via page.goto
- driveA33 signature (page, browser, extensionId, downloadsDir) at
  line 2622-2627 — driveA35 is a sound subset
- harness.test.ts:580 total = drivers.length + 1 (auto-increments)
- Browser + Page imported at harness-page-driver.ts:43
- launch.ts:473-542 opens only victimPage + harnessPage
- welcome-hero__mark zero hits in all current harness files
- welcome.css:72 sets color: var(--mks-fg-inverse) on .welcome-hero__mark
  (cascade target); .welcome-hero__mark-img is bare selector (matches svg)

BLOCKER 2 (phantom failing test) → RESOLVED via behavior-based gate that
distinguishes flake from regression by isolation re-run (no test filename
hard-coded). Verified live this session:
- Full vitest run: 184/184 GREEN (flake did NOT fire this run)
- strict-meta-json in isolation: 8/8 GREEN
- webm-remux in isolation: 5/5 GREEN
- Confirms iter-1's diagnosis: the '1 fail' is the 04-CONTEXT #9/#10
  parallel-vitest/ffprobe family, not a named test.

DEFECT 2 line classification (22/47/82/135/205 flip; 40/89/109/110 leave)
preserved unchanged. welcome.css drop preserved. Thesis preserved
(currentColor Option A + cursor verification-only + operator empirical
Task 4). FORBIDDEN_HOOK_STRINGS stays at 12. Atomic-commit structure +
frontmatter + gsd-sdk verify.plan-structure all GREEN.

3 NEW cosmetic-advisories (all non-blocking):
- ADVISORY-2A: stale banner string at harness.test.ts:283 (does not
  include A33/A34 today; planner's 'append A35' instruction has a
  slightly stale premise; banner is cosmetic, no gate depends on it)
- ADVISORY-2B: Task 3 rationale prose says SKIP_PROD_REBUILD gates
  dist-test rebuild; actually it gates dist/ (the A0 grep gate); the
  command behavior is correct, only the prose is slightly off
- ADVISORY-2C: threat model could note A35 is appended LAST in drivers
  array (which makes the pollution-of-future-drivers concern moot;
  verified independently safe)

VERDICT: PASSED. Proceed to /gsd:execute-phase 04-06.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 18:20:28 +02:00
f3baa3a9a8 docs(04-06): re-plan iter-2 — real inline-SVG coverage + corrected 184/184 baseline
Re-plan-checker iter-1 (commit deb68df) flagged 2 BLOCKERs against the
iter-1 re-plan (b59bd24). Both fixed below; 3 advisories fixed; iter-1
verified-correct items preserved. EVERY test-infrastructure claim
re-verified against actual code this session before being written into
the plan — extension-page-harness.ts, harness-page-driver.ts, launch.ts,
harness.test.ts, vitest.config.ts, vite.config.ts, vite.test.config.ts,
full vitest run. No third false premise.

BLOCKER 1 — fictitious A17.8 live-DOM delegation. The iter-1 re-plan
claimed live-DOM injection + currentColor cascade was "delegated to
A17.8 in real Chrome". Verified false: assertA17 reaches welcome.html
only via fetch + DETACHED DOMParser string-parse; A17.8 is 100%
string-grep on jsText; the harness opens exactly two pages (victimPage
file://, harnessPage extension-page-harness.html — launch.ts:473-542);
populateMark() never runs in the harness. Fixed: a NEW host-side
harness assertion A35 is added (Task 3, modeled on driveA32/33/34) —
opens welcome.html via browser.newPage() + page.goto, lets
populateMark() run at DOMContentLoaded, then querySelector
'.welcome-hero__mark svg' + getComputedStyle().stroke proves the
LIVE currentColor cascade. welcome.html is a real web-accessible
extension page (builds to dist-test/src/welcome/welcome.html);
launchHarnessBrowser returns browser + extensionId so the new tab is
cheaply reachable. A35 is genuine new harness work (new driver +
drivers-array entry + banner-string update + import). A17.8 is
narrowed honestly to a source-bundling check only. No fictitious
delegation.

BLOCKER 2 — DEFECT 3 named the wrong failing test. The iter-1 re-plan
claimed strict-meta-json-validation.test.ts "fails on a clean tree" and
hard-coded a Task 2 gate "failure set EXACTLY == {strict-meta-json}".
Verified false this session: strict-meta-json in isolation = 8/8 GREEN;
a full vitest run reproduced 183 passed / 1 failed where the RED was
tests/background/webm-remux.test.ts (ffprobe -count_frames, timeout) —
NOT strict-meta-json. webm-remux in isolation = 5/5 GREEN. The "1
failed" is a non-deterministic ffprobe/parallel-vitest timeout flake —
exactly 04-CONTEXT #9 + #10. Fixed: baseline corrected to 184/184 GREEN
when the flake doesn't fire; target after Plan 04-06 = 188/188 GREEN
(+4 new tests). Task 2 gate now: 188/188 -> pass; 1 RED that passes on
isolation re-run -> tolerate as the known flake; reproducible RED or
2+ RED -> regression. No test filename hard-coded. deferred-items.md
mis-diagnosis corrected (Task 3 Edit 5).

Advisories (all fixed):
- A1: Task 3 action and verify both use SKIP_PROD_REBUILD=0 (intentional
  — harness must rebuild dist-test against Task 2 source edits).
- A2: requirements:[] kept (Phase 4 has no new REQ-* per ROADMAP);
  charter linkage via the `charter-d-p4-03` tag — non-blocking.
- A3: Task 1 acceptance criterion reworded to grep only import
  statements + the @vitest-environment directive, so the file's header
  prose explaining "no DOM-emulation library" doesn't trip it.

Preserved (iter-1 verified-correct):
- DEFECT 2 back-patch line classification (22/47/82/135/205 flip;
  40/89/109/110 leave).
- welcome.css drop from files_modified (bare class selector matches
  <svg>; color is inherited).
- Thesis: currentColor Option A + cursor verification-only +
  operator-empirical Task 4 + PNG icons untouched.
- FORBIDDEN_HOOK_STRINGS stays at 12 (no new __MOKOSH_UAT__ symbols).
- Frontmatter shape (phase:04 / slug / plan:06 / type:execute / wave:5
  / autonomous:false / depends_on:[01..05]). files_modified extended by
  3 new entries (harness-page-driver.ts + harness.test.ts + the
  corrected deferred-items.md).

Validation:
- gsd-sdk frontmatter.validate --schema plan: valid:true (all 8
  required fields present).
- gsd-sdk verify.plan-structure: valid:true, 0 errors, 0 warnings,
  4 tasks each with Files+Action+Verify+Done; Task 4 is
  checkpoint:human-verify per autonomous:false.

Orchestrator: run the re-plan checker again on this iter-2 commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 17:24:17 +02:00
deb68dff86 docs(04-06): re-plan-checker iter-1 — ITERATE-NEEDED (2 BLOCKER)
Re-plan b59bd24 validated against canonical plan-quality criteria.

DEFECT 2 (back-patch line numbers 22/47/82/135/205 flip; 40/89/109/110
leave) — RESOLVED, verified correct against live 01-07-SUMMARY.md.
welcome.css drop, thesis preservation, frontmatter, FORBIDDEN_HOOK_STRINGS
lockstep (12), atomic-commit structure — all correct.

BLOCKER 1: DEFECT 1's "live-DOM injection + currentColor cascade delegated
to A17.8 harness in real Chrome" is fictitious — assertA17 runs in an
extension-internal page and only fetch()+string-greps welcome.html/jsText;
no live welcome tab, no populateMark() run, no querySelector. Task 3's own
escape hatch ships A17.8a-only, leaving the inline-SVG behavior with zero
automated coverage.

BLOCKER 2: DEFECT 3 names the wrong failing test — strict-meta-json-
validation.test.ts is GREEN on a clean tree (8/8 isolated). The full-suite
"1 failed" is a non-deterministic ffprobe/parallel-vitest timeout flake
(04-CONTEXT #9/#10); this run it hit webm-remux.test.ts. The hard-coded
"failure set EXACTLY {strict-meta-json...}" gate will fail spuriously.
True baseline 184/184; target 188/188.

Verdict: ITERATE-NEEDED — spawn planner for second re-plan.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 16:28:47 +02:00
b59bd24354 docs(04-06): re-plan — correct false jsdom premise + stale back-patch lines + baseline
Full re-plan via /gsd-plan-phase ceremony. The prior 04-06-PLAN.md hit a
blocking checkpoint (plan-assumption defect). Three defects corrected;
thesis preserved (dark-logo currentColor Option A + cursor verification-only
+ A17.8 + operator-empirical Task 4).

DEFECT 1 — false jsdom premise: prior Task 1 assumed vitest configures a
jsdom environment. FALSE — vitest.config.ts:18 sets environment:'node' and
no DOM-emulation library is in node_modules. Resolution: STRATEGY (a) —
reframe tests/welcome/inline-svg.test.ts as a node-env source-contract test
(the canonical tests/i18n/manifest-i18n.test.ts file-read + string-assert
pattern); delegate live-DOM injection + currentColor cascade verification to
the A17.8 harness sub-check in real Chrome. Rejected (b) jsdom devDependency
(deviates from a twice-reaffirmed no-DOM-library stance) and (c) manual
DOMParser stub (fragile for SVG-namespace fidelity).

DEFECT 2 — stale back-patch line numbers: verified the genuine stale
'deferred to Phase 5' lines in 01-07-SUMMARY.md are 22/47/82/135/205;
historical commit-description lines 40/89/109/110 left unchanged.

DEFECT 3 — wrong vitest baseline: real baseline is 183 GREEN / 1 pre-existing
RED (strict-meta-json-validation.test.ts, logged to deferred-items.md, routed
to /gsd-debug). Test-count target reframed to 187 GREEN / 1 pre-existing RED.

revision_history block added. files_modified updated (welcome.css dropped —
the bare class selector matches <svg> identically; no CSS edit needed).
must_haves truths/artifacts/key_links updated to match the corrected plan.
frontmatter.validate + verify.plan-structure both green.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 16:22:04 +02:00
6a989e8339 docs(04-06): log out-of-scope strict-meta-json test failure to deferred-items
- tests/build/strict-meta-json-validation.test.ts fails on clean tree
  (183/184, not the 184/184 the plan baseline assumed)
- SAVE_ARCHIVE meta.json runtime path — unrelated to Plan 04-06 surface
- resembles the pre-existing Plan 04-08 A33 SAVE-ack channel flake
- routed to /gsd-debug; NOT fixed in Plan 04-06 per scope boundary

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 15:44:11 +02:00
7e0da63ff2 fix(debug): A33.1 SAVE-ack race — gate on race-free fresh-archive signal
Root cause: driveA33's A33.1 hard-gated on the chrome.runtime.sendMessage
SAVE_ARCHIVE callback ack. After the Puppeteer CDP worker.close() SW kill,
the SAVE_ARCHIVE message wakes a fresh SW instance; that instance runs the
multi-step saveArchive() pipeline (offscreen video-keepalive port
re-establishment + REQUEST_BUFFER round-trip + rrweb collection + zip
build). The harness's original sendMessage response port has its own MV3
lifetime — on a 5-min-aged SW the pipeline INTERMITTENTLY outruns it,
surfacing chrome.runtime.lastError "message port closed before a response
was received". The archive is still written correctly every time, which is
why A33.2/A33.3 always passed (Plan 04-05 full-mode UAT: A33.1 FAIL while
A33.2/A33.3 PASS at 1.56 MB). A33.1 was gating a CI assertion on a
best-effort transport ack with inherent MV3 non-determinism.

Fix (harness-side only, Option A — race-free reframe): A33.1 now gates on
the durable race-free signal — a fresh archive on disk — via the canonical
snapshotExistingZips + pollForNewOrUpdatedZip helpers (also used by
driveA12/A13/A27). The sendMessage ack is demoted to a soft non-gating
diagnostic. This is exactly the signal the proven-reliable spike already
uses. A33.2/A33.3 substantive checks are intact and now read the verified
fresh zip. No new symbol; FORBIDDEN_HOOK_STRINGS unchanged at 12. The SW
SAVE_ARCHIVE handler is a correct MV3 async pattern — no production change.

Verified: full-mode A33 (genuine 5-min idle) 3/3 GREEN; skip-mode UAT
35/35 GREEN; tsc + build:test exit 0; vitest 184/184.

Debug session: .planning/debug/a33-save-ack-race.md

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 15:33:22 +02:00
28ebc1fe4e docs(04-05): complete A34 fetch+XHR network_error empirical plan
- 04-05-SUMMARY.md: A34 assertion closes ROADMAP SC #2 (fetch + XHR
  network_error capture); Plan 04-01 P1 #11 Request-narrow fix
  validated end-to-end; skip-mode UAT 34->35/35 GREEN
- STATE.md: position advanced (6/8 plans); Plan 04-05 closure note;
  decision-log entry; A33 full-mode SAVE-ack flake logged as Blocker
  (routed to /gsd-debug — Plan 04-08 deliverable, out of scope here)
- ROADMAP.md: SC #2 STATUS CLOSED; 04-05 row [x]; Phase 4 progress 6/8
- All 4 ROADMAP success criteria now closed (SC #1 Plan 04-08, SC #2
  this plan, SC #3+#4 Plan 04-02)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 13:02:58 +02:00
0712c245a1 feat(04-05): A34 host-side + orchestrator — fetch+XHR network_error empirical (ROADMAP SC #2 GREEN)
- Append driveA34 host-side: JSZip-parse logs/events.json + filter
  network_error entries by '404-fetch-a34' / '404-xhr-a34' target
  marker; assert >=1 of each + meta.status === 404
- readMetaStatus helper narrows UserEvent.meta.status (typed
  Record<string,unknown>) to number without an unchecked any cast
- 3-site orchestrator wiring in harness.test.ts: import binding,
  driveA34Wrapped (downloadsDir closure), drivers-array push entry
- UAT harness 34 -> 35; skip-mode (SKIP_LONG_UAT=1) 35/35 GREEN
- A34 empirical: fetch entry target carries the real URL
  (https://example.com/404-fetch-a34-<stamp>), NOT '[object Request]'
  — Plan 04-01 P1 #11 fix validated end-to-end at the SAVE->archive
  layer; XHR entry confirms the distinct prototype-wrapper path;
  both meta.status === 404 (ROADMAP SC #2 closed)
- vitest baseline 184/184 GREEN preserved (no unit tests this plan)
- FORBIDDEN_HOOK_STRINGS unchanged at 12

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 12:26:14 +02:00
a20372a8b8 feat(04-05): A34 page-side — cs-injection-world fetch + XHR 404 injection
- Append assertA34 after assertA31 — cs-injection-world skeleton
  (verbatim from assertA30/A31; ROADMAP SC #2 empirical)
- chrome.scripting.executeScript ISOLATED injects TWO 404 triggers
  into the content-script realm: fetch(404) + XMLHttpRequest(404)
- fetch trigger validates Plan 04-01 P1 #11 (Request-narrow URL
  extraction) end-to-end in a real Chrome page context
- XHR trigger covers the distinct XMLHttpRequest.prototype wrapper
  path that A30 did not exercise
- Date.now() uniqueness stamp on both probe URLs (T-04-05-02)
- assertA34 registered in Window interface + __mokoshHarness literal
- Tier-1 FORBIDDEN_HOOK_STRINGS unchanged at 12 (rides production
  window.fetch + XMLHttpRequest.prototype + chrome.scripting/tabs)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 11:37:12 +02:00
125269dcc5 docs(04-08): complete harden-clean-up-optional plan 04-08 — STATE.md advance to 6/7
State counter advance after Plan 04-08 closure:
- progress.completed_plans: 27 -> 28
- Current Plan position: 5 -> 6 (Plan 04-05 fetch+XHR queued next)
- last_updated timestamp + last_activity bumped to 2026-05-22

Note: the human-readable "Plan: 6 of 7" line in Current Position reflects the
original Phase 4 plan-count of 7; the ROADMAP-side phase tracker now shows
5/8 (Plan 04-08 inserted Wave 5.5 per debug session-2 verdict authorization).
This is a known cosmetic gap in the SDK's state.advance-plan handler; the
frontmatter total_plans=31 / completed_plans=28 are correct.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 11:08:30 +02:00
4d6c00526e feat(04-08): A33 SW state persistence harness assertion — methodology reframe (34/34 GREEN; ROADMAP SC #1 CLOSED)
Task 2 of Plan 04-08 (revive A33 under valid methodology + close ROADMAP SC #1):

- Append driveA33(page, browser, extensionId, downloadsDir) at tests/uat/lib/harness-page-driver.ts:2516-2697 per Plan 04-04 Pattern 4 verbatim
- 3 checks: A33.1 SAVE_ARCHIVE ack success after 5-min idle + SW kill; A33.2 video size > 0; A33.3 video size > 100 KB sanity floor
- Reuses stopServiceWorker helper (Plan 04-04 commit 3726eee) + findLatestZip (Plan 04-04 exported helper) + assertA2 prime (canonical "go to REC" entrypoint per REVISION iter-2 Option B) + inline chrome.runtime.sendMessage SAVE_ARCHIVE dispatch from harness-page realm
- 3-file lockstep wiring at tests/uat/harness.test.ts: (1) import block adds driveA33 after driveA32; (2) wrapped-driver block adds driveA33Wrapped const after driveA31Wrapped; (3) drivers-array push appends A33 entry with SKIP_LONG_UAT env-gate (default RUN for Phase 4 closure + alpha gate)

Spike re-run evidence (HEADLESS=1 npx tsx tests/uat/spike-a33-sw-persistence.ts; 309.5s wall-clock):
- SPIKE PROBE [POST-PRIME]: segments.length=0  (baseline; no rotations yet)
- SPIKE PROBE [PRE-KILL]:   segments.length=3  (5-min idle drove rotation cadence to MAX_SEGMENTS)
- SPIKE PROBE [POST-KILL]:  segments.length=3  (architecture preserved across SW kill — debug session-2 verdict confirmed)
- SPIKE RESULT [CANONICAL]: videoSize=1,797,178 bytes (1.8 MB; vs 8505 baseline; ~211x larger)
- SPIKE OUTCOME: PASSED (offscreen SURVIVED the 5-min idle + SW kill)

Sample segment sizes during 5-min idle: 536921, 539874, 577234, 611683, 596512, 541658, 680729, 617089, 597527, 585310 bytes (all ~500-680 KB; per 10s @ ~400 kbps VP9 per CON-video-codec).

UAT before/after:
- Skip-mode UAT (HEADLESS=1 SKIP_PROD_REBUILD=1 SKIP_LONG_UAT=1 npm run test:uat): 34/34 GREEN in ~95s (A33 placeholder PASSES under skip env)
- vitest baseline flipped 183 -> 184 GREEN (+1 from Tier-2 production-bundle filename-leak gate landed in Task 1)

ROADMAP SC #1 closure (.planning/ROADMAP.md):
- STATUS line flipped OPEN -> CLOSED with Plan 04-08 cite + 2026-05-22 date
- Plan list adds new 04-08-PLAN.md row + amends 04-04-PLAN.md row with REFUTED-architecture verdict cross-reference (debug session-2 commit 4ea1bbb)
- Phase tracker cell updated from `4/7 In Progress` to `5/8 In Progress`
- WARNING 4 grep gates verified PASS: `CLOSED via Plan 04-08`=1; `STATUS 2026-05-21: OPEN`=0; `STATUS 2026-05-22: CLOSED`=1

Pre-checkpoint bundle gates 6/6 PASS:
- new Function=0 + eval=0 + Buffer.=1 (pre-existing JSZip polyfill) + window./document.=0 in SW chunk
- Tier-1 FORBIDDEN_HOOK_STRINGS lockstep at 12 entries (unchanged)
- Tier-2 production-bundle filename-leak gate (NEW from Task 1): synthetic-display-source = 0 hits in dist/
- en/ru parity preserved
- npx tsc --noEmit: exit 0

Architecture integrity preserved per debug session-2 verdict:
- src/offscreen/recorder.ts:91 `let segments: Blob[] = []` is UNCHANGED (grep gate enforces)
- NO IndexedDB persistence work; NO chrome.storage migration; NO offscreen-document lifecycle changes
- IndexedDB persistence plan-fix recommendation from Plan 04-04 SUMMARY REJECTED (would not have closed SC #1 because segments are not the problem, frames were)

Persisting artifacts from Plan 04-04 repurposed under valid methodology:
- stopServiceWorker helper (commit 3726eee): reused verbatim by driveA33
- tests/uat/spike-a33-sw-persistence.ts (commit 3726eee + session-2 Step B/C): now PASSES as canonical regression-verification gate

Self-Check: PASSED. All claims verified per executor protocol §self_check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 11:07:48 +02:00
81d9935b65 feat(04-08): video-file MediaStream + sync-install/lazy-first-frame + explicit WAR — methodology reframe per debug session-2 + iter-2 BLOCKER fixes
Task 1 of Plan 04-08 (methodology reframe of ROADMAP SC #1):

- Bundle 1.9 MB VP9 WebM fixture at tests/uat/fixtures/synthetic-display-source.webm (copy of internal Plan 01-07 fixture; CC0-equivalent project-owned)
- Add globals.d.ts ambient `*.webm?url` module decl (mirrors Plan 01-10 `*.svg?url`)
- Add manifest.json web_accessible_resources entry for `assets/*.webm` (iter-2 BLOCKER 1 — pre-decided to avoid executor improvisation; inert in production where dist/ has zero *.webm)
- Rewrite installFakeDisplayMedia() at src/test-hooks/offscreen-hooks.ts:
  * Replace canvas.captureStream(30) with HTMLVideoElement.captureStream(30) — bypasses Chrome bug 653548 invisible-canvas throttling (debug session-2 root cause)
  * Function signature remains SYNCHRONOUS (`: void`; iter-2 BLOCKER 2 — eager-install contract preserved at lines 528-537)
  * Video element creation + DOM append + monkey-patch assignment execute synchronously
  * canplay wait + .play() deferred INTO fakeGetDisplayMedia closure (lazy first-frame pattern)
  * fakeVideoReadyPromise kicked off at install time so first call observes resolved Promise
  * WARNING 1 (autoplay reject): explicit error class identifier 'autoplay-blocked or codec-unsupported in headless context'
  * displaySurface monkey-patch preserved verbatim
  * A23 lastGetDisplayMediaConstraints capture preserved
  * uninstallFakeDisplayMedia teardown adapted for videoEl (pauses + removes + nulls)
  * All 6 bridge ops UNCHANGED in their sync return-false form
- Add Tier-2 production-bundle filename-leak gate at tests/background/no-test-hooks-in-prod-bundle.test.ts (iter-2 WARNING 5 — synthetic-display-source string must be 0 hits in dist/)

Verification:
- npx tsc --noEmit: exit 0
- npm run build: dist/ produced; 0 *.webm files; 0 synthetic-display-source hits
- npm run build:test: dist-test/assets/synthetic-display-source-mbtR1t3u.webm emitted (1.9 MB; Vite ?url asset)
- Code-only grep (comment-filtered) on offscreen-hooks.ts: 0 canvas refs; 15 video refs
- installFakeDisplayMedia signature unchanged: `: void` 2x; `: Promise` 0x; `await installFakeDisplayMedia` 0x
- Architectural invariant unchanged: `let segments: Blob[] = []` at recorder.ts:91 (1 hit; grep gate enforces)
- Tier-1 FORBIDDEN_HOOK_STRINGS unchanged at 12 entries
- Tier-2 vitest gate PASSES: 14/14 GREEN under SKIP_BUILD=1 (12 Tier-1 + 1 build verify + 1 Tier-2)

Per iter-3 checker advisory 1: the wrong-display-surface throw lives at recorder.ts:313-321 (not line 294 as plan text states; off by ~25 lines but unambiguous).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 10:33:04 +02:00
dd8a56453c docs(04-08): plan-checker iter-3 — PASSED-WITH-RESIDUAL on polish revision
Validates iter-3 polish revision of Plan 04-08 (commit 17e55dd) against
iter-2 PASSED verdict (1 WARNING + 4 cosmetic-advisories).

Resolution status:
- iter-2 NEW WARNING (displaySurface sub-gate scope): RESOLVED via clean
  drop of --check-display-surface-only mode; HIGH-LATENCY catch path
  locked in (spike re-run's assertA2 fast-fail).
- iter-2 cosmetic-advisory 1 (collectDistFiles symbol mismatch):
  RESOLVED — replaced with listAllFilesRecursive(DIST_DIR) +
  countOccurrencesInFile at correct line numbers (152, 185, 133).
- iter-2 cosmetic-advisory 2 (WARNING 1 SUMMARY-write practice):
  RESOLVED — inline comment at code snippet (lines 730-737) + Step 6
  SUMMARY content list bullet.
- iter-2 cosmetic-advisory 3 (vitest math 183 -> 184): RESOLVED —
  anchored to Tier-2 test block in 5 locations consistently.
- iter-2 cosmetic-advisory 4 (duration=N/A rationale): PARTIALLY
  RESOLVED — added to SUMMARY content list with forward-pointer from
  PLAN body; in-body reasoning preserved (planner's "moved" claim
  language slightly overstates the change but end-state behavior is
  fine).

Two NEW iter-3 cosmetic-advisories (NON-BLOCKING):
1. recorder.ts:294 mis-citation — actual displaySurface throw is at
   lines 313-321 (line 294 is a comment block). Off by ~25 lines but
   unambiguous; only one wrong-display-surface throw exists in
   recorder.ts. Executor will land on the right gate.
2. duration=N/A "moved" framing vs preserved+forward-ref'd reality —
   revision_history claim language slightly overstates; end-state fine.

Pre-execution validation: gsd-sdk verify.plan-structure returns
valid=true; both tasks have files+action+verify+done; 14 frontmatter
fields including revision_history with all three iters logged.
Pure polish pass: +51/-22 lines on PLAN.md only; no thesis edits, no
scope changes, BLOCKER fixes from iter-2 preserved verbatim.

Verdict: PASSED-WITH-RESIDUAL (0 BLOCKER + 0 WARNING + 2 cosmetic-
advisories). Both residuals are documentation-cosmetic (line-number
citation + framing-of-iter-3-polish-claim); orchestrator's call between
immediate execution OR optional iter-4. Recommended: PROCEED to execute
Plan 04-08.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 10:18:42 +02:00
17e55ddbb9 docs(04-08): polish per iter-2 advisories — symbol mismatch + display-surface mode lock-in + cosmetic clarifications
iter-3 polish pass on Plan 04-08 per checker iter-2 verdict PASSED
(commit 9c334b7). Five cosmetic-level fixes; no thesis/scope changes;
BLOCKER fixes from iter-2 + WARNING fixes from iter-2 preserved verbatim.

Remediations:
- WARNING 1 (low-severity; displaySurface sub-gate scope ambiguity):
  HIGH-LATENCY catch path locked in; the under-specified
  `--check-display-surface-only` spike-script mode is dropped (would have
  required 5-10 LOC of executor improvisation for no meaningful latency
  win over the canonical spike re-run's assertA2 fast-fail at <30s).
- Advisory 1 (symbol-name mismatch): Tier-2 snippet's `collectDistFiles`
  replaced with the actual helper `listAllFilesRecursive(DIST_DIR)` from
  tests/background/no-test-hooks-in-prod-bundle.test.ts:152; also uses
  the existing `countOccurrencesInFile` for binary-extension-aware grep.
- Advisory 2 (SUMMARY-write practice for WARNING 1): explicit note added
  that 04-08-SUMMARY.md documents the WARNING 1 closure path (no Plan B
  fallback; explicit error-class identifier; observable via offscreen
  console capture).
- Advisory 3 (vitest math): 183 -> 184 clarified consistently across
  must_haves truth + Step 5 body + acceptance_criteria + verification +
  success_criteria (+1 from the new Tier-2 `test(...)` block).
- Advisory 4 (duration-N/A rationale): moved out of the PLAN body into
  the SUMMARY content list (Step 6); PLAN keeps only the load-bearing
  size gate + loop-attr behavioral assertion + spike-re-run empirical
  catch; 1.9 MB / ~400 kbps / ~38s decoded-timeline reasoning lands at
  SUMMARY-time.

Frontmatter:
- Added iter-2 entry to revision_history (iter-3 polish closure).
- Tag flipped planner-iter-2-revision -> planner-iter-3-revision.

Plan validates via gsd-sdk frontmatter.validate + verify.plan-structure:
- valid: true; 0 errors; 0 warnings; 2 tasks; all 4 task elements present.

Diff: +51/-22 lines (5640 chars net). Branch ready for plan-checker
iter-3 (cosmetic-only polish review expected to PASS without further
findings).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 10:05:38 +02:00
9c334b77e8 docs(04-08): plan-checker iter-2 — PASSED (0 BLOCKER + 1 WARNING + 4 advisory)
Verifies iter-2 plan revision at 1f2eb2e against iter-1 findings (051813e):

BLOCKER 1 (Vite ?url asset-emission path) — RESOLVED via explicit
web_accessible_resources entry for assets/*.webm in manifest.json
(Option B from iter-1 remediation; pre-decided + grep-gated; inert in
production because dist/ has zero *.webm assets).

BLOCKER 2 (eager-install contract preservation) — RESOLVED via SYNC
install + LAZY first-frame closure (Option A from iter-1 remediation).
installFakeDisplayMedia() remains synchronous; canplay wait + .play()
deferred into fakeGetDisplayMedia closure. Three grep gates codify the
contract (sync signature present + NOT async + no await callers).

All 5 iter-1 WARNINGs addressed concretely with grep-gated remediations.
All 3 iter-1 cosmetic-advisories addressed.

New iter-2 findings: 1 WARNING (displaySurface sub-gate scope ambiguity;
alternative documented; non-blocking) + 4 cosmetic-advisories (symbol
name lookup, SUMMARY-write practice, vitest math, duration rationale).
Below PASSED threshold.

Recommendation: proceed to execute Plan 04-08 Wave 5.5.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 09:44:11 +02:00
1f2eb2e818 fix(04-08): revise plan per iter-1 BLOCKER fixes — bundling strategy + sync monkey-patch + async closure
iter-2 revision of Plan 04-08 (video-file MediaStream methodology reframe)
addressing the 2 BLOCKERs + 5 WARNINGs + 3 advisories from plan-checker
iter-1 (commit 051813e, .planning/phases/04-harden-clean-up-optional/04-08-CHECKER-iter-1.md).

BLOCKER 1 (Vite ?url asset emission for >=1 MB WebM): pre-decide the
bundling strategy. The 1.9 MB WebM is three orders of magnitude above
Vite's assetsInlineLimit (4096); it follows the extracted-asset path
(dist-test/assets/<hash>.webm), not the data-URI-inline path the
Plan 01-10 SVG precedent uses. The @crxjs/vite-plugin auto-WAR
behavior for extracted media assets in offscreen-document context is
empirically untested in this codebase. Resolution: add an explicit
web_accessible_resources entry for assets/*.webm in manifest.json
alongside the existing src/welcome/welcome.html entry. Production
dist/ has zero *.webm assets so the entry is inert; test dist-test/
has the hashed asset and the entry authorizes chrome-extension://<id>/
assets/<hash>.webm URL access from the offscreen document context.
No executor improvisation; the bundling strategy is locked-in BEFORE
Task 1 begins.

BLOCKER 2 (installFakeDisplayMedia async conversion breaks eager-install
contract): preserve the SYNCHRONOUS function signature. The existing
eager call at src/test-hooks/offscreen-hooks.ts:528-537 + the top-
level await at src/offscreen/recorder.ts:46-48 establish a contract
that navigator.mediaDevices.getDisplayMedia is monkey-patched BEFORE
recorder.bootstrap runs. Converting installFakeDisplayMedia() to
async would create a race window where recorder.startRecording calls
the REAL getDisplayMedia (Chrome screen-share picker hangs in
headless). Resolution: SYNC install (videoEl creation + DOM append +
monkey-patch assignment) + LAZY first-frame closure (await readyState
HAVE_FUTURE_DATA + .play() deferred INTO fakeGetDisplayMedia body).
First getDisplayMedia call may block ~50-500ms while video decodes;
subsequent calls observe the resolved readiness Promise + proceed
immediately. Bridge handler + eager-install try/catch remain sync.

WARNING 1 (autoplay reliability): explicit error class identifier
('autoplay-blocked or codec-unsupported in headless context') in the
.play() reject path; spike surface root cause instead of mysterious
0-frames.

WARNING 2 (patchDisplaySurface compatibility): new sub-gate in Task 1
verify that mints a stream + asserts track.getSettings().displaySurface
=== 'monitor'. Optional executor implementation as a --check-display-
surface-only mode on the spike script; spike re-run is the fallback
high-latency catch.

WARNING 3 (spike probe-value asserts): surfaced as explicit grep gates
in Task 2 verify block. POST-PRIME=0, PRE-KILL>=3, POST-KILL>=3 per
debug session-2 baseline.

WARNING 4 (ROADMAP.md edit): pre-specified exact pre-edit string +
replacement + grep gate (CLOSED via Plan 04-08 must appear; STATUS
2026-05-21: OPEN must disappear).

WARNING 5 (synthetic-display-source filename leak): new Tier-2 sub-
invariant in tests/background/no-test-hooks-in-prod-bundle.test.ts;
catches accidental test-hook inlining into production chunk. Tier-1
inventory at 12 entries unchanged.

advisory 1: commit message corrected to reference Task 1 + Task 2
only (not Task 3, which doesn't exist).

advisory 2: src/offscreen/recorder.ts:91 segments invariant added as
grep gate in Task 1 verify block.

advisory 3: dual-location fixture note added to Task 1 Step 1 (the
original tests/fixtures/last_30sec.webm remains in place; the new
tests/uat/fixtures/synthetic-display-source.webm is a SECOND copy
under the UAT subtree).

Plan validates via gsd-sdk frontmatter.validate --schema plan (valid:
true, no missing fields) AND gsd-sdk verify.plan-structure (valid:
true, 0 errors, 0 warnings, 2 tasks with full 4-element shapes).
files_modified updated to include tests/background/no-test-hooks-in-
prod-bundle.test.ts (Tier-2 gate location).

Iter-2 architectural thesis unchanged: HTMLVideoElement.captureStream
bypasses the canvas-throttling root cause per debug session-2 verdict.
The revision is methodology-tightening, not re-architecture.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 09:17:33 +02:00
051813ee6e docs(04-08): plan-checker iter-1 — ITERATE-NEEDED (2 BLOCKER + 5 WARNING + 3 advisory)
Plan 04-08's core thesis (HTMLVideoElement.captureStream bypasses canvas
throttling per debug session-2 verdict) IS the correct path to close
ROADMAP SC #1. But two blocking issues prevent reliable delivery:

BLOCKER 1: Vite `?url` asset-emission analog mis-applied — mokosh-mark.svg
is 877 bytes (inlined as data:image/svg+xml URI) so the Plan 01-10 "?url
+ crxjs auto-WAR" precedent is NOT a direct analog for the 1.9 MB WebM
which will emit as a separate dist-test/assets/<hash>.webm file. WAR
auto-generation for extracted assets is unverified in this codebase.
Remediation: probe-then-decide OR Blob URL from ?raw ArrayBuffer.

BLOCKER 2: installFakeDisplayMedia()'s eager-install-at-module-load
contract is silently broken by the proposed async conversion. The race
window opens because recorder.ts:48 resolves before the async install
completes; recorder.startRecording → real getDisplayMedia → headless
hang. Remediation: keep sync monkey-patch; defer the canplay wait into
fakeGetDisplayMedia closure (lazy first-frame).

WARNINGS surface unverified headless autoplay reliability, displaySurface
monkey-patch portability to HTMLVideoElement tracks, spike probe-value
gates not surfaced as automated verify, and ROADMAP.md flip without grep
enforcement.

Architectural alignment confirmed (segments: Blob[] preserved; IDB
correctly rejected; D-P4-01 honored). iter-2 is a methodology-tightening
pass, not re-architecture. Estimated ~150-300 lines of plan edits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 09:03:08 +02:00
504d9dccf3 docs(04-08): create plan — video-file MediaStream methodology reframe + A33 revival
Inserts Plan 04-08 between Plans 04-06 and 04-07 (Wave 5.5) per
debug session-2 verdict (REFUTED-architecture; canvas-captureStream
issue). Scope: replace canvas.captureStream(30) source in
installFakeDisplayMedia() at src/test-hooks/offscreen-hooks.ts:139-264
with HTMLVideoElement.captureStream backed by a bundled VP9 WebM at
tests/uat/fixtures/synthetic-display-source.webm. Bundled via Vite ?url
import per Plan 01-10 mokosh-mark precedent. Revives the A33 harness
assertion (Plan 04-04 Pattern 4 verbatim) under valid methodology;
stopServiceWorker helper from Plan 04-04 reused. Closes ROADMAP SC #1
within v1. Architecture (offscreen-RAM segments: Blob[]) UNCHANGED
per debug session-2 segment-count probe evidence.

2 tasks atomic: (1) bundle fixture + rewrite installFakeDisplayMedia
+ ambient *.webm?url decl; (2) re-run spike + land driveA33 +
orchestrator wiring + SKIP_LONG_UAT env-gate + SUMMARY + STATE/ROADMAP
markers. UAT 33 -> 34 GREEN target. FORBIDDEN_HOOK_STRINGS unchanged
at 12. Pre-checkpoint bundle gates 6/6 PASS preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 08:41:51 +02:00
c1501e7a81 docs(04-04): amend SUMMARY post-debug session-2 — REFUTED-architecture verdict
Session-2 (/gsd-debug continuation) empirically refuted the SUMMARY's
original 'architecture broken → IndexedDB plan-fix needed' interpretation:

- Pre-kill probe: segments.length=3 (segments accumulated correctly during 5-min idle)
- Post-kill probe: segments.length=3 (offscreen-RAM survives SW kill structurally)
- Step C (no worker.close, just 5-min idle): identical 8505 bytes (CDP not the cause)
- Remux logs: each segment trackInfo=320x180 but 0 frames per segment
- 7/7 spike runs deterministic at 8505 bytes (canvas-captureStream throttling)

Root cause: installFakeDisplayMedia() at src/test-hooks/offscreen-hooks.ts:139-264
mints canvas.captureStream(30) on hidden -9999px-offset canvas; headless-Chromium
throttles MediaRecorder on invisible-canvas (Chrome bug 653548). Segments exist
but contain zero VP9 frames over 5-min idle.

Routing: Plan 04-08 inserted (user-authorized ceremony 2026-05-22) — video-file
MediaStream methodology reframe (Option 2 from session-2). IndexedDB plan-fix
recommendation REJECTED — would not close SC#1 because frames are the problem,
not segments.

stopServiceWorker helper + spike script + launch.ts:225 race-tolerant fix all
remain valid persisting artifacts for Plan 04-08.
2026-05-22 08:14:44 +02:00
4ea1bbb7a8 docs(debug): SC#1 sw-offscreen-persistence investigation session 2 — REFUTED-architecture (canvas-captureStream issue)
Session-2 (continuation of d614462 INCONCLUSIVE) executed disambiguation
plan and converged on a definitive verdict. Three independent observations
ruled out ALL architectural-failure hypotheses:

  Step A: race-tolerant offscreen target attach (committed separately;
  enabled visibility into the offscreen recorder + remux pipeline).

  Step B: pre-kill and post-kill segment-count probes via the existing
  `__mokoshOffscreenQuery 'get-segment-count'` bridge op (no new
  test-only symbols introduced; FORBIDDEN_HOOK_STRINGS inventory
  unchanged at 12 entries). Observed segments.length transition:
    POST-PRIME=0 → PRE-KILL=3 → POST-KILL=3
  Segments structurally survive the SW kill (offscreen still responds
  to bridge query post-kill). Hypothesis A (architectural RAM loss
  across SW termination) REFUTED.

  Step C: SPIKE_SKIP_SW_KILL=1 env-var mode skips worker.close(). The
  resulting videoSize is IDENTICAL to the canonical run (8505 bytes).
  Hypothesis C (CDP-induced offscreen collateral teardown) REFUTED.
  Since SW was not killed, its console listener stayed connected,
  exposing the full Remux pipeline output:
    [SW:Remux] Segment ts=1: 0 frames, duration=0ms, trackInfo=320x180
    [SW:Remux] Segment ts=2: 0 frames, duration=0ms, trackInfo=320x180
    [SW:Remux] Segment ts=3: 0 frames, duration=0ms, trackInfo=320x180
    [SW:Remux] Remux complete: 0 frames, total timeline=0ms, output=8505 bytes
  Each segment Blob has a valid track header (PixelWidth/Height parsed
  successfully) but ZERO VP9 frames. Hypothesis B (canvas-captureStream
  throttling in headless idle) CONFIRMED.

VERDICT: REFUTED-architecture (canvas-captureStream issue).

The architecture (offscreen-RAM `segments: Blob[] = []`) works
correctly; the spike's test methodology is invalid. The
`installFakeDisplayMedia` synthetic stream (canvas.captureStream(30)
on a hidden -9999px-offset 320x180 canvas) cannot sustain frame
production during a 5-min headless idle window despite the
`setInterval(drawFrame, 33ms)` belt-and-suspenders mitigation. This
matches the documented Chromium throttling of MediaRecorder on
invisible-canvas sources (Chrome bug 653548; auto-throttled-screen-capture
design doc; sendrec.eu blog "Why Canvas Breaks Your Screen Recorder").

ROUTING RECOMMENDATION (out of scope for this debug session):
  - Do NOT proceed with the IndexedDB persistence plan-fix proposed by
    Plan 04-04 SUMMARY. The plan-fix would NOT close SC #1 because the
    spike would STILL produce 8505 bytes after IDB lands — the failure
    is in the test's fake stream, not in segment persistence.
  - Open a new plan slot (likely Plan 04-08 or a Phase 5 plan) that
    reframes SC #1 verification methodology. Options:
      (a) real getDisplayMedia in non-headless Puppeteer with
          --auto-select-desktop-capture-source;
      (b) video-file-backed MediaStream source (HTMLVideoElement
          playing a bundled WebM) — bypasses canvas-captureStream
          throttling entirely;
      (c) reduce SC #1 wall-clock idle threshold to a value short
          enough that canvas-captureStream survives (e.g., 30s) AND
          add a separate manual operator-empirical test for 5-min.

ROADMAP SC #1 status: REMAINS OPEN. The architecture is sound; the
empirical verification gate is broken. Plan 04-04 SUMMARY's
characterization ("spike FAILED → architectural plan-fix needed") is
TECHNICALLY CORRECT on the first clause but INCORRECT on the second —
the spike's failure mode is in test infrastructure, not in production
code.

Files in this commit:
  - tests/uat/spike-a33-sw-persistence.ts: added probeSegmentCount
    helper using existing __mokoshOffscreenQuery bridge op; 3
    checkpoints (POST-PRIME / PRE-KILL / POST-KILL); SPIKE_SKIP_SW_KILL=1
    env-var skips worker.close() for Step C disambiguation.
  - .planning/debug/sw-offscreen-persistence-investigation-session-2.md:
    NEW session-2 debug note documenting full evidence trail + verdict
    derivation + routing recommendation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 08:02:24 +02:00
9ac580869d fix(debug): race-tolerant offscreen target attach in UAT launch
Plan-04-04 debug session-2 root cause: the offscreen-console capture
in tests/uat/lib/launch.ts:registerOffscreenConsoleAttach matched zero
offscreen targets across 4 spike runs, creating a critical observability
gap that prevented disambiguation of Plan 04-04 Wave 0 spike failure
mode.

Empirical investigation (tests/uat/spike-diagnose-offscreen-target.ts,
NEW): when chrome.offscreen.createDocument fires, Puppeteer's
`targetcreated` event fires with `type='other'` and `url=''` BEFORE the
CDP target metadata stabilizes. The previous filter (whether
`background_page` or `page`) never matched at event time. By the time
the metadata stabilizes (visible via `browser.targets()`), the
target's type is `'background_page'` (not `'page'` — MV2's
background_page type IS still used by Chrome's CDP for invisible
extension documents, despite MV3 abolishing classic background pages).

Fix:
  - Match the offscreen target by URL pattern (load-bearing criterion;
    type field is intentionally unchecked because it's unreliable at
    targetcreated time).
  - Bind to BOTH `targetcreated` AND `targetchanged` events (the latter
    fires when the URL stabilizes after navigation).
  - Add a `browser.targets()` enumeration race-free safety net for
    cases where the offscreen target exists at registration time.

Verification: tests/uat/spike-diagnose-offscreen-target.ts now emits
`(launch: offscreen console attached — url=chrome-extension://.../src/offscreen/index.html)`
followed by `[off:log] [OS:Recorder] Recording started ...` (zero such
lines in any prior spike run).

Test-infra correctness fix; ZERO production source changes. FORBIDDEN_HOOK_STRINGS
inventory unchanged at 12 entries. No new test-only `__MOKOSH_UAT__` symbols.

References:
  - .planning/debug/sw-offscreen-persistence-investigation-session-2.md
    (session-2 debug note documenting empirical root cause)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 07:16:27 +02:00
d614462694 docs(debug): SC#1 sw-offscreen-persistence investigation — INCONCLUSIVE
Pre-commit-ceremony verification of Plan 04-04 Wave 0 SPIKE finding
(videoSize=8505 bytes after 5-min SW idle + Puppeteer worker.close()).

Reproducibility: 4/4 runs (incl. prior 3726eee) produced identical
8505-byte WebM. Deterministic.

Chrome docs research: chrome.offscreen DISPLAY_MEDIA reason has NO
lifetime limit; offscreen "may outlive" its SW; Puppeteer #9995 +
crbug 1371432 document CDP attach distorting SW lifecycle; chromium
auto-throttled-screen-capture + Chrome Bug 653548 document canvas-
captureStream throttling on invisible/background tabs.

Verdict: INCONCLUSIVE — the spike's 8505-byte result is consistent
with THREE competing root causes (test-invalid headless throttling;
CDP-artifact collateral teardown; architectural offscreen-RAM-loss)
and the spike cannot disambiguate between them. Observability gaps:
launch.ts:225 filters offscreen console on background_page (MV2)
when MV3 offscreen is type 'page' → zero offscreen logs in all spike
runs.

Recommendation: PAUSE the ~2-4h IndexedDB plan-fix. Three cheap
disambiguation steps (~75 min total) can isolate the actual root
cause before committing. Detailed in the debug note's
routing_recommendation block.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 21:12:46 +02:00
e8a2e7696d docs(04-04): complete harden-clean-up-optional plan 04-04 — SW persistence spike FAILED, plan-fix ceremony required
Plan 04-04 (spike→auto) closes at Task 1 (Wave 0 SPIKE) with an empirical
NO on the RESEARCH Q2 MEDIUM-confidence hypothesis A3 (offscreen-document
independent lifecycle anchored by active MediaRecorder). Task 2 (Wave 1
A33 verification-only harness assertion) BLOCKED by the plan's explicit
gating condition (videoSize > 100_000); ROADMAP SC #1 remains OPEN.

Spike empirical numbers (one HEADLESS=1 run; 308.7s wall-clock; full log
at /tmp/04-04-spike.log; reproducible via the committed spike script):
  - assertA2 prime:        PASSED (REC state established)
  - 5-min wall-clock idle: elapsed cleanly
  - stopServiceWorker CDP: succeeded (worker.close() returned)
  - SAVE_ARCHIVE ack:      {success: true} (event-driven SW respawn worked)
  - video/last_30sec.webm: 8505 bytes (sanity floor 100 KB; healthy 1-3 MB)
  - ffprobe on extracted:  'End of file' + 'Duplicate element' (no clusters)
  - rrweb/session.json:    [] (empty)
  - logs/events.json:      [] (empty)
  - meta.urls:             chrome-extension://* only (real-page URLs LOST)

Conclusion: src/offscreen/recorder.ts:91 `let segments: Blob[] = []` RAM-
only architecture does NOT survive 5-min SW idle + Puppeteer CDP worker.
close(). Architectural change required to close ROADMAP SC #1 (canonical
recommendation per 04-RESEARCH.md Q2 sub-question b Option C: IndexedDB
persistence in offscreen — Blobs serialize cleanly via structured-clone;
per-segment write ~3 MB; ~3 writes per 30s window). Per saved memory
`feedback-gsd-ceremony-for-fixes.md` the architectural fix routes through
/gsd-plan-phase rewrite OR /gsd-debug ceremony — NOT improvised inline
inside Plan 04-04.

Task 1 persisting artifacts (committed at 3726eee):
  - tests/uat/lib/harness-page-driver.ts: +43/-6 lines
    - Browser type added to puppeteer import
    - stopServiceWorker(browser, extensionId) helper (Chrome devrel
      canonical pattern; Puppeteer >=22.1.0 worker.close())
    - findLatestZip exported (was module-internal)
  - tests/uat/spike-a33-sw-persistence.ts NEW +202 lines
    - One-shot reproducible empirical investigation script
    - Reusable for future SW-lifecycle regression (the eventual plan-fix
      re-runs this script as its A33-verification gate)
    - Committed (not deleted) per the spike-FAILED forensic-evidence pattern

Task 2 was NOT committed (BLOCKED by gating condition); UAT count stays
33/33; Tier-1 FORBIDDEN_HOOK_STRINGS inventory unchanged at 12; A33 not
introduced.

Pre-checkpoint bundle gates (per saved memory feedback-pre-checkpoint-
bundle-gates.md): 6/6 GREEN unchanged from Plan 04-03 baseline (zero
production source changes in Plan 04-04).
  - SW chunk new Function: 0 (Plan 04-02 polarity preserved)
  - SW chunk eval:         0 (preserved)
  - SW chunk Buffer.:      1 (pre-existing JSZip polyfill; logged deferred)
  - SW chunk window./doc.: 0/0 (preserved)
  - dist/ grep × 12 hooks: 0 matches (Tier-1 inventory invariant held)
  - Manifest:              validates clean

vitest baseline: 183 tests total. Sequential `npm test` showed 180/183 with
3 pre-existing flakes in tests/background/blob-url-download.test.ts +
tests/background/webm-remux.test.ts + tests/offscreen/webm-playback.test.ts;
all 3 PASS in isolation. Per 04-CONTEXT.md items 9-10 these are documented
pre-existing issues (parallel-vitest Tier-1-build-step race + 2 ffprobe/
ffmpeg flakes pre-dating Phase 3) — NOT a Plan 04-04 regression (Plan 04-04
made zero source-code changes that could possibly affect them).

Files committed:
  - .planning/phases/04-harden-clean-up-optional/04-04-SUMMARY.md NEW
  - .planning/STATE.md: position advanced 4→5 / 7; progress 87% → 90%;
    2 decision entries logged; session metadata updated
  - .planning/ROADMAP.md: Phase 4 row count 2/7 → 4/7; Plan 04-04
    checklist box ticked with full SPIKE FAILED annotation; SC #1 marked
    OPEN with empirical evidence inline

Next step (out of Plan 04-04 scope; routed per spike-first contract):
plan-fix ceremony for IndexedDB persistence layer at src/offscreen/*.
The plan-checker/planner owns whether to (a) rewrite Plan 04-04 in-place,
(b) insert a new plan slot (e.g., 04-08), or (c) close Plan 04-04 as
spike-findings + open a fresh follow-up plan. Recommendation in SUMMARY:
option (b) or (c) — keep Plan 04-04 as the canonical spike-findings record.
2026-05-21 20:02:42 +02:00
3726eee39f feat(04-04): Wave 0 spike — stopServiceWorker helper + 5-min SW idle empirical result
SPIKE OUTCOME: FAILED (offscreen DIED across 5-min SW idle + worker.close())

Per Plan 04-04 spike-first contract, Wave 0 empirically investigated whether
the offscreen document's RAM-only `segments: Blob[] = []` at
src/offscreen/recorder.ts:91 survives a 5-min SW idle followed by Puppeteer
CDP-driven `worker.close()`. RESEARCH Q2 hypothesis (MEDIUM confidence): yes,
the offscreen has its own lifecycle anchored by active MediaRecorder. Spike
result REFUTES that hypothesis.

Empirical measurement (HEADLESS=1; one full run; reproducible via the
committed spike script):

  - assertA2 priming: PASSED (badge=REC; offscreen + MediaRecorder live)
  - 5-min idle:        elapsed cleanly (308.7s total wall-clock)
  - stopServiceWorker: succeeded (worker.close() returned)
  - SAVE_ARCHIVE ack:  {success: true} (SW respawned + processed message)
  - video/last_30sec.webm size: 8505 bytes (well below 100 KB floor)
  - meta.urls: only chrome-extension://* origins; real-page URLs LOST
  - rrweb/session.json: []
  - logs/events.json: []
  - ffprobe on extracted webm: 'End of file' + 'Duplicate element' errors
    (corrupt/truncated; not a valid 30s segment cluster sequence)

Interpretation: offscreen-document lifecycle is NOT independent of the SW
under Puppeteer CDP-driven worker.close() conditions. The 8505 bytes are
likely stale/partial header bytes from a re-initialized empty offscreen
context after SW respawn, not a surviving 30s buffer. The plan's Task 2
GATING CONDITION (videoSize > 100_000) is NOT satisfied; Task 2 is BLOCKED.

Per saved memory `feedback-gsd-ceremony-for-fixes.md`: architectural changes
(moving segments from offscreen RAM to IndexedDB per RESEARCH Q2 sub-question
b Option C) MUST route through proper plan-fix ceremony, NOT improvised
inline inside Plan 04-04. Plan 04-04 SUMMARY flags the failure mode + cites
exact remediation path. ROADMAP SC #1 remains OPEN pending the persistence-
layer plan-fix.

Task 1 persisting artifacts (this commit):
  - tests/uat/lib/harness-page-driver.ts:
    + Browser type import (puppeteer)
    + stopServiceWorker(browser, extensionId) helper (verbatim from Chrome
      devrel canonical pattern — Puppeteer >=22.1.0; project pin ^25 OK)
    + findLatestZip exported (was module-internal) so the spike script can
      reuse the canonical mtime-sort selection logic without duplication
  - tests/uat/spike-a33-sw-persistence.ts (NEW):
    + One-shot empirical investigation script; reusable for future SW-
      lifecycle regression testing (e.g., verifying the eventual IndexedDB
      persistence layer actually closes ROADMAP SC #1)
    + Step 1 reuses __mokoshHarness.assertA2 (canonical fresh-recording
      prime; not the non-existent dispatchSaveArchive that REVISION iter-2
      explicitly forbids)
    + Step 5 dispatches SAVE_ARCHIVE via chrome.runtime.sendMessage inline
      from harness-page realm (Option B per plan-checker BLOCKER 2;
      matches A5/A11/A12/A13/A26/A28/A29/A30/A31 pattern)

Verification (Task 1 acceptance criteria):
  - npx tsc --noEmit: exits 0
  - HEADLESS=1 tsx tests/uat/spike-a33-sw-persistence.ts: ran to completion
    (no Puppeteer throw); SPIKE RESULT line emitted with explicit
    videoSize=8505 bytes; SAVE_ARCHIVE ack received
  - grep -c 'dispatchSaveArchive' tests/uat/spike-a33-sw-persistence.ts: 0
  - grep -c "type: 'SAVE_ARCHIVE'" tests/uat/spike-a33-sw-persistence.ts: 1
  - Total spike wall-clock: 308.7s (~5min idle + ~8s orchestration)

References:
  - Plan 04-04 PLAN.md spike contract (lines 64-72)
  - 04-RESEARCH.md Q2 sub-question (b) — Chrome MV3 offscreen lifecycle
  - https://developer.chrome.com/docs/extensions/how-to/test/test-serviceworker-termination-with-puppeteer
  - Saved memory: feedback-gsd-ceremony-for-fixes.md (no inline architectural
    fixes; route through plan-fix ceremony)
2026-05-21 18:44:45 +02:00
303644f8cc docs(04-03): complete harden-clean-up-optional plan 04-03 — A29 flake fix
A29 (rrweb DOM verification) rewritten in-place via the canonical cs-
injection-world pattern + strict-sentinel filter. Closes ~2/3 flake
documented in Plans 03-02 + 03-03 SUMMARYs (A29 was "passing" by
reading iana.org leftover DOM events from A27/A28's still-open probe
tabs; a real rrweb regression at src/content/index.ts:284 would have
been masked).

Plan 04-03 task commits (atomic; sequential foreground mode):
- 73eb9b6: Task 1 — A29 page-side cs-injection-world skeleton +
  sentinel-bearing <div> injection
- b341a71: Task 2 — A29 host-side strict-sentinel filter (RESEARCH Q3
  Code Example Pattern 3); IncrementalSource added to @rrweb/types
  import binding; A29.2 PASS × 5/5 consecutive UAT runs

Empirical evidence:
- vitest 183/183 GREEN preserved (Plan 04-02 baseline)
- UAT harness 33/33 GREEN × 5 consecutive runs
- A29 strict-sentinel: mutationEvents=1, sentinelEvents=1 in ALL 5 runs
- Tier-1 FORBIDDEN_HOOK_STRINGS unchanged at 12
- SW chunk: 0 new Function, 0 eval (Plan 04-02 baseline held)
- Pre-checkpoint bundle gates 5/5 PASS

STATE.md + ROADMAP.md updated per sequential workflow:
- Plan counter advanced 3 → 4 of 7
- Progress 83% → 87% (26/30 plans complete)
- Decision log entry added for Plan 04-03
- ROADMAP Phase 4 04-03 row flipped to [x]
2026-05-21 17:01:58 +02:00
b341a712c0 feat(04-03): A29 host-side strict-sentinel filter + 5/5 PASS stress test
Replace the loose-EventType grep with a strict-sentinel filter pipeline
per RESEARCH Q3 Code Example Pattern 3:

- Import IncrementalSource from @rrweb/types (new binding alongside the
  existing EventType import)
- Filter events for (e.type === EventType.IncrementalSnapshot &&
  e.data?.source === IncrementalSource.Mutation)
- Descend into each filtered event's data.adds[*].node.textContent and
  search for the page-side-injected 'a29-mutation-sentinel' string
- A29.2: assert sentinelEvents.length >= 1 — proves the captured
  mutation came from OUR injection, not from iana.org leftovers

Defense-in-depth preserved:
- A29.3: rrweb emitted at least one Meta event (renumbered)
- A29.4: rrweb emitted at least one FullSnapshot (renumbered)
The previous A29.5 (loose IncrementalSnapshot >=1) is subsumed by the
A29.2 strict-sentinel check (which requires IncrementalSnapshot AND
Mutation source AND injected sentinel — strictly stronger).

Empirical verification (all 33/33 GREEN preserved, A29 flake closed):
- npx tsc --noEmit  →  0
- npm test          →  183/183 GREEN preserved (Plan 04-02 baseline)
- npm run test:uat  →  33/33 GREEN × 5 consecutive runs
- A29 mutationEvents=1 + sentinelEvents=1 in ALL 5 runs (no flake)

A29 historical flake rate of ~2/3 (documented Plan 03-02 + 03-03
SUMMARYs) is closed end-to-end: the iana.org leftover DOM mutations
no longer satisfy A29 because the strict-sentinel filter requires the
EXACT string 'a29-mutation-sentinel' that only the page-side
chrome.scripting.executeScript injection produces.

Pre-checkpoint bundle gates verified (per feedback-pre-checkpoint-
bundle-gates.md):
- Gate 1: Tier-1 FORBIDDEN_HOOK_STRINGS — 13/13 sub-tests PASS, count
  unchanged at 12
- Gate 2: SW CSP-safety — new Function=0, eval=0 (Plan 04-02 baseline)
- Gate 3+4: Buffer / window / document counts unchanged from Plan 04-02
  (Plan 04-03 modifies tests/ only)
- Gate 5: manifest validates clean against locked DEC-011 Amendment 1
2026-05-21 16:27:00 +02:00
73eb9b654c feat(04-03): A29 page-side rewrite — cs-injection-world + sentinel
Replace harness-page-mutation approach with verbatim port of the
canonical cs-injection-world pattern from Plan 03-02 (assertA30) +
Plan 03-03 (assertA31):

- chrome.tabs.create(https://example.com/, active:true) opens probe
  tab where content script + rrweb's record() attach normally
  (chrome-extension:// is NOT covered by <all_urls> per Chrome
  match-pattern spec; was the root flake cause)
- 1.5s tab-attach + 11s segment-settle waits (canonical A27/A30/A31)
- chrome.scripting.executeScript world: 'ISOLATED' injects a sentinel-
  bearing <div> (textContent='a29-mutation-sentinel') into document.body
  — rrweb's MutationObserver lives in the same ISOLATED world so the
  IncrementalSnapshot's data.adds[*].node.textContent will carry the
  sentinel
- 500ms MutationObserver-enqueue settle
- SAVE_ARCHIVE while probe tab is active (SW harvests rrweb/session.json
  from there)
- try/finally chrome.tabs.remove with silent-ignore (T-02-04-04 parity)

A29 constants block extended: A29_TAB_NAVIGATION_WAIT_MS,
A29_PROBE_TAB_URL, A29_MUTATION_SENTINEL, A29_PROBE_DIV_ID.

This closes the documented ~2/3 success-rate flake from Plans 03-02 +
03-03 where A29 "passed" by reading iana.org leftover DOM mutations
from A27/A28's probe tabs — a real rrweb regression at
src/content/index.ts:284 would have been masked because iana.org's
home page emits plenty of mutations during normal rendering.

Tier-1 FORBIDDEN_HOOK_STRINGS unchanged at 12; assertA30 + assertA31
untouched; __mokoshHarness wiring unchanged. Host-side driveA29
strict-sentinel filter lands in Task 2.

Verify:
- npx tsc --noEmit → 0
- npm run build:test → 0
- grep -c 'A29_MUTATION_SENTINEL' tests/uat/extension-page-harness.ts → 3
- grep -nE "world: 'ISOLATED'" tests/uat/extension-page-harness.ts → 3
  call sites (A29 + A30 + A31) — ISOLATED parity per RESEARCH Pitfall 5
2026-05-21 15:48:18 +02:00
6a1fc32826 docs(04-02): complete harden-clean-up-optional plan 04-02 — build hygiene
Plan 04-02 closes three independent build-hygiene fixes consolidated into
one plan because they share the build-gate-grep test-scaffold pattern:

1. **setimmediate polyfill replacement** — layered 4-mechanism CSP-hardening
   eliminates the `new Function` literal from the SW chunk (grep -c flips
   1→0 across all three SW chunks). Runtime guard + nodePolyfills exclude
   + resolve.alias + Rollup post-transform plugin. Option α (force JSZip
   unbundled lib/index.js) attempted + reverted because it broke
   readable-stream-browser propagation causing UAT A30+ regressions;
   Option β (post-transform plugin) preserves JSZip's pre-bundled
   distribution verbatim while excising the offending literal.

2. **ROADMAP SC #3** (generate-icons ESM/CJS) — `git mv generate-icons.js
   generate-icons.cjs` resolves the `require('fs')` under
   `package.json type: module` via Node's `.cjs`-as-CJS rule.

3. **ROADMAP SC #4** (dead-code grep) — `tests/build/dead-code-grep.test.ts`
   regression-pins `permissions.request` absence in `src/`.

Plus closure of Plan 01-12 Wave 7's setimmediate deferred-items entry.

Task commits:
  - 630d40c test(04-02): Wave 0 RED — no-new-function + dead-code-grep
  - f251297 feat(04-02): Wave 1 GREEN — setimmediate replacement + CJS rename + closure

Verification:
  - vitest 180/180 → 183/183 GREEN on clean run (+3 net new tests)
  - UAT harness 33/33 GREEN preserved (REVISION iter-2 WARNING 1 empirical pin)
  - Pre-checkpoint bundle gates 5/5 PASS; SW CSP-safety polarity flipped 1→0
  - tsc-clean preserved; npm run build exit 0; node generate-icons.cjs exit 0

STATE.md: Plan 3/7 (Plan 04-02 complete); 25/30 total plans; 83% progress.
ROADMAP.md: Phase 4 progress 2/7 plans complete (04-01 + 04-02).
deferred-items.md: Plan 01-12 Wave 7 setimmediate entry CLOSED end-to-end.

SUMMARY at `.planning/phases/04-harden-clean-up-optional/04-02-SUMMARY.md`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:41:54 +02:00
f251297256 feat(04-02): Wave 1 — setimmediate polyfill replaced + generate-icons.cjs + deferred-items closure
Coherent 5-edit Wave 1 GREEN landing per Plan 04-02 Task 2; RED gate from
Task 1 (`tests/build/no-new-function-in-sw-chunk.test.ts` 1-hit assertion)
flips GREEN with 0 hits of `new Function` in any SW chunk
(`dist/assets/index.ts-*.js` glob).

## Threat T-04-02-01 mitigation (Elevation of Privilege — `new Function` literal)

Three layered mechanisms cooperate to drop the CSP-unsafe `new Function`
literal from the SW chunk while preserving JSZip's zip-assembly correctness
end-to-end (REVISION iter-2 WARNING 1 empirically pinned at UAT harness 33/33):

1. **Runtime polyfill prelude** at top-of-module of `src/background/index.ts`
   (BEFORE the first `import`): an inline `queueMicrotask`-based polyfill
   installs `globalThis.setImmediate` at SW boot. JSZip's pre-bundled
   `dist/jszip.min.js` IIFE guards its internal setimmediate polyfill behind
   `if(!s.setImmediate){...}`, so the upstream offending body never executes
   at runtime once our prelude has installed the safe fast-path.

2. **`vite-plugin-node-polyfills` `exclude: ['setimmediate']`** in vite.config.ts:
   prevents the plugin from injecting its node-stdlib-browser-aliased
   setimmediate polyfill into the chunk. NOTE: this alone is insufficient
   because JSZip's `dist/jszip.min.js` ships its OWN bundled-in setimmediate
   (via the package.json `"browser"` field that maps `./lib/index` →
   `./dist/jszip.min.js`); the plugin's `exclude` only filters the plugin's
   own contributions.

3. **`resolve.alias.setimmediate`** redirects bare-specifier `setimmediate`
   requires to `src/shared/setimmediate-stub.ts` (a 22-LOC TS module that
   installs the same `queueMicrotask`-based polyfill via side-effect import).
   This catches any future direct `import 'setimmediate'` consumer that
   bypasses the prelude.

4. **`stripSetimmediateNewFunction()` Rollup post-transform plugin** in
   vite.config.ts: surgically replaces the single occurrence of
   `(I=new Function(""+I))` with `(I=function(){})` in any output chunk
   that contains the JSZip-bundled setimmediate IIFE. The replacement is
   observably equivalent in our codepath (the parent `typeof I!="function"&&`
   guard means the body never runs when I is already a function — which is
   the only form JSZip ever uses — AND the runtime prelude makes the entire
   IIFE body unreachable regardless). Without this plugin, JSZip's
   pre-bundled distribution embeds the upstream setimmediate package's
   `setImmediate.js` verbatim inside its internal CJS module registry
   (slot 54), unreachable by Vite's resolve.alias or the polyfill plugin's
   exclude.

## Architecture decision log

**Option α (force JSZip unbundled `lib/index.js` via `resolve.alias.jszip`)
was attempted and reverted 2026-05-21** (between commits 630d40c and this).
Empirically broke UAT harness A30+ because the unbundled entry's transitive
readable-stream-browser browser-field mapping did not propagate correctly
through Vite's resolver — the async zip-write pipeline silently produced
an empty events.json. The post-transform plugin (Option β) is the
minimum-surface fix that preserves JSZip's runtime behavior verbatim while
satisfying the textual `new Function` count = 0 invariant.

## Verification

**Build / static gates:**
- `npm run build` exits 0; SW chunk `dist/assets/index.ts-DfBxWCT9.js`
  (378.92 kB) contains 0 occurrences of `new Function` (was 1 in pre-fix
  `index.ts-8LkXuqac.js`).
- `npx tsc --noEmit` exits 0.
- `grep -rn 'permissions.request' src/` returns 0 hits (Plan 04-02 ROADMAP
  SC #4 regression pin GREEN).
- `node generate-icons.cjs` exits 0; old `generate-icons.js` no longer
  exists (rename via `git mv` preserves history).
- `grep -c "exclude: \\['setimmediate'\\]" vite.config.ts` returns 1.
- `grep -c "queueMicrotask" src/background/index.ts` returns ≥1.
- `grep -c "Resolved in Phase 4 Plan 04-02" .planning/phases/01-stabilize-video-pipeline/deferred-items.md` returns ≥1.

**Test gates:**
- Focused: `npm test -- tests/build/no-new-function-in-sw-chunk.test.ts tests/build/dead-code-grep.test.ts --run` → 3/3 GREEN (Task 1's RED gate flipped GREEN).
- Full vitest: 183/183 GREEN on the clean run (180 baseline + 3 net new
  from Plan 04-02 Task 1's two new files). Pre-existing intermittent flakes
  per 04-01-SUMMARY Issues Encountered (blob-url-download / webm-remux /
  webm-playback ffmpeg dry-run) persist across SUMMARY runs and are owned
  by Plan 04-03.

**Pre-checkpoint bundle gates (per saved memory feedback-pre-checkpoint-bundle-gates.md):**
1. Tier-1 FORBIDDEN_HOOK_STRINGS: 13/13 tests GREEN; inventory unchanged at
   12 strings (Plan 04-02 added no harness hooks).
2. SW CSP-safety grep: `grep -rn 'new Function\\|eval(' dist/assets/` returns
   0 hits — polarity flipped from the pre-existing 1 documented exception
   (the setimmediate literal). T-04-02-01 mitigation pin lands.
3. Node-globals: `Buffer.copy / .isView / .length / .push / .shift / .slice
   / .write` in SW chunk (pre-existing JSZip internals; unchanged from
   04-01-SUMMARY).
4. DOM-globals: `document.createElement / .createTextNode / .documentElement
   / .F` + `window.Math / .console / .localStorage / .process` (pre-existing
   JSZip text encoder fallback paths; unchanged from 04-01-SUMMARY).
5. manifest.json: present, MV3, `name: __MSG_extName__` (chrome.i18n intact).

**Empirical UAT harness (REVISION iter-2 WARNING 1):**
- `HEADLESS=1 SKIP_PROD_REBUILD=0 npm run test:uat` → 33/33 assertions
  passed (verbatim `UAT harness: 33/33 assertions passed` in stdout).
  Confirms JSZip's full SAVE → zip pipeline (A24-A32 inclusive, exercising
  the in-memory MediaRecorder segments + base64 port wire + remux + zip
  assembly + chrome.downloads + events.json + meta.json + screenshot)
  operates correctly under the new bundle. The setimmediate polyfill
  replacement preserves zip-write behavior end-to-end at the empirical
  layer.

## Files

- **vite.config.ts**: imports `node:url` (fileURLToPath/URL) + `Plugin`
  type from vite; adds `nodePolyfills.exclude: ['setimmediate']`;
  adds `resolve.alias.setimmediate` → `src/shared/setimmediate-stub.ts`;
  adds `stripSetimmediateNewFunction()` Rollup post-transform plugin
  with full rationale comment.
- **src/background/index.ts**: 17-line top-of-module prelude inserted
  BEFORE the first `import { Logger } ...` line. Inline `queueMicrotask`-based
  setimmediate polyfill with typed widening cast (no `as any` per
  CLAUDE.md). Reversible by `git revert`.
- **src/shared/setimmediate-stub.ts** (NEW): 50-LOC TS module providing
  the same `queueMicrotask`-based polyfill via side-effect import.
  Documented as the resolve.alias target.
- **generate-icons.js → generate-icons.cjs**: `git mv` preserving history.
  Node 14+ treats `.cjs` as CJS regardless of `package.json` "type":
  "module" per https://nodejs.org/api/packages.html#determining-module-system.
  No code change; `require('fs')` + `require('path')` resolve cleanly.
  No other references to the old `.js` path elsewhere in the codebase
  outside the `.planning/` audit trail.
- **.planning/phases/01-stabilize-video-pipeline/deferred-items.md**:
  appended "Resolved in Phase 4 Plan 04-02" closure block citing this
  commit; details the 4-mechanism layered mitigation; documents the
  Option α attempt + reversion.

References:
  - .planning/phases/04-harden-clean-up-optional/04-RESEARCH.md §Q1
  - .planning/phases/04-harden-clean-up-optional/04-PATTERNS.md
    §vite.config.ts + §src/background/index.ts
  - Plan 04-02 threat model T-04-02-01 (Elevation of Privilege) +
    T-04-02-02 (DoS — JSZip fallback compatibility; verified by UAT 33/33)
  - node_modules/jszip/lib/utils.js:7 (upstream `require("setimmediate")`)
  - node_modules/setimmediate/setImmediate.js (upstream polyfill source)
  - Plan 01-12 Wave 7 deferred-items.md disclosure (Phase 5 → Phase 4 target)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:16:44 +02:00
630d40c4f8 test(04-02): Wave 0 — no-new-function-in-sw-chunk RED + dead-code-grep regression pin
Two new build-gate vitest files at `tests/build/` per Plan 04-02 Wave 0
TDD-strict RED-first contract:

- `no-new-function-in-sw-chunk.test.ts`: SW-chunk CSP-hardening grep gate.
  Narrows the file walk to `dist/assets/index.ts-*.js` (the SW + loader
  chunks; cf. plan-checker iter-1 BLOCKER 1 fix). RED today: 1 occurrence
  of `new Function` in the SW chunk (the pre-existing `setimmediate` npm
  package fallback bundled transitively by vite-plugin-node-polyfills,
  per .planning/phases/01-stabilize-video-pipeline/deferred-items.md).
  Flips GREEN after Task 2's setimmediate replacement lands. Build-prep
  gate (npm run build + dist/assets/ existence + ≥1 SW chunk match)
  precedes the grep gate so the test is self-bootstrapping under
  SKIP_BUILD=0 and self-asserting under SKIP_BUILD=1.

- `dead-code-grep.test.ts`: ROADMAP SC #4 regression pin against `src/`.
  Asserts absence of `permissions.request` (removed in Phase 1 Plan
  01-05 SW shrink). GREEN-on-arrival today; acts as regression guard so
  re-introducing the deleted permission-request flow breaks CI. The
  offscreen-inline-string sub-test is documented as delegated to the
  vite.config.ts review + tests/build/no-remote-fonts.test.ts (no single
  literal sentinel pinnable post-Plan-01-06 collapse).

Polarity confirmation:
  - Acceptance grep: `grep -v '^//' tests/build/no-new-function-in-sw-chunk.test.ts | grep -c 'new Function'` returns 3 (≥2 required).
  - Acceptance grep: `grep -v '^//' tests/build/dead-code-grep.test.ts | grep -c 'permissions.request'` returns 2 (≥2 required).
  - SKIP_BUILD=1 npm test -- tests/build/no-new-function-in-sw-chunk.test.ts tests/build/dead-code-grep.test.ts --run: 2 passed + 1 failed (the expected RED gate).
  - Full vitest: 180 passed + 3 failed (1 = this task's expected RED + 2 = pre-existing ffmpeg/ffprobe flakes per 04-01-SUMMARY Issues Encountered — owned by Plan 04-03).

References:
  - .planning/phases/04-harden-clean-up-optional/04-PATTERNS.md §"tests/build/no-new-function-in-sw-chunk.test.ts" + §"tests/build/dead-code-grep.test.ts"
  - .planning/phases/04-harden-clean-up-optional/04-RESEARCH.md §Q1
  - Plan 04-02 threat model T-04-02-01 (Elevation of Privilege) + T-04-02-03 (Information Disclosure regression pin)
  - tests/build/no-remote-fonts.test.ts (Plan 01-12 analog scaffold)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:39:48 +02:00
f72bca5c46 docs(04-01): complete audit-p1-polish-content-script plan
Plan 04-01 closure marker — 04-01-SUMMARY.md + STATE.md position advance
(Plan 1 of 7 -> Plan 2 of 7; Plan 04-02 build hygiene queued NEXT in Wave 1)
+ ROADMAP plan-progress table flip ([ ] -> [x] 04-01-PLAN.md row).

Plan delivered (per SUMMARY):
- Audit P1 #11 fetch URL extraction fix (TWO sites; instanceof Request narrow)
- Audit P1 #14 navigation URL tracking fix (module-level previousUrl)
- Audit P1 #15 rrweb emit timestamp normalization (Date.now() Unix epoch)
- 9 new vitest tests under tests/content/; baseline 171 -> 180/180 GREEN
- tsc-clean preserved; Tier-1 hook-strings inventory unchanged at 12
- Audit P1 polish backlog CLOSED 3/3

Per-task commits (TDD pair):
- 3dbc51c test(04-01): Wave 0 RED — content-script test scaffolds
- 7da30af feat(04-01): Wave 1 GREEN — 3 surgical edits in src/content/index.ts

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:34:03 +02:00
7da30afa0a feat(04-01): Wave 1 GREEN — fix audit P1 #11 fetch URL + #14 nav URL + #15 rrweb timestamps
Three surgical edits in src/content/index.ts flip the 7 RED tests from
commit 3dbc51c to GREEN (full vitest 180/180; tsc-clean preserved).

* P1 #11 — fetch URL extraction (TWO sites, identical narrow):
  - line ~190 (ok-branch of setupNetworkLogging)
  - line ~210 (catch-branch of setupNetworkLogging)
  Both replace the implicit-coercion `target: args[0]?.toString() || 'unknown'`
  with the explicit type-narrow
  `target: (args[0] instanceof Request ? args[0].url : String(args[0])) || 'unknown'`.
  This unmasks the failing URL when the page calls `fetch(new Request(url))`
  — the original code captured the literal '[object Request]' (Request has
  no custom toString and falls back to Object.prototype.toString).

* P1 #14 — navigation URL tracking via module-level previousUrl:
  - ADD `let previousUrl = window.location.href;` at module scope (line 29;
    typeof window guard keeps node-env unit tests importable).
  - REWRITE handleNavigation to swap-then-emit:
      const fromUrl = previousUrl;
      const toUrl = window.location.href;
      previousUrl = toUrl;
      addUserEvent({ ..., meta: { previousUrl: fromUrl } });
  This replaces `meta: { previousUrl: history.state?.url || 'unknown' }`
  which always emitted 'unknown' in apps that don't populate history.state
  (almost all of them) — making meta.previousUrl useless for support
  reproducing where the operator was before a failing navigation.

* P1 #15 — rrweb emit timestamp normalization:
  - Prepend `event.timestamp = Date.now();` inside the rrweb record() emit
    callback at ~line 312. rrweb-internal timestamps are page-load-relative
    small ints; without normalization the cleanupOldEvents arithmetic at
    ~line 33 `(now - event.timestamp) < RRWEB_RETENTION_MS` is a category
    error (Date.now() - 42 ≫ 10 min retention).

Plan: 04-01 Wave 1 (closes Wave 0 RED gate from 3dbc51c)
Files:
- src/content/index.ts (~30 lines added; 3 surgical edits + Plan-citing comments)

Verification (GREEN gate):
- npm test -- tests/content/ --run → 9 passed (9)
- npm test -- --run → 180 passed (180); was 171/171 pre-Plan-04-01
- npx tsc --noEmit → exit 0
- grep -c "instanceof Request" src/content/index.ts → 3 (≥2 expected)
- grep -cE "args\[0\]\?\.toString" src/content/index.ts → 0 (old pattern purged)
- grep -cE "^let previousUrl" src/content/index.ts → 1
- grep -cE "meta: \{ previousUrl: fromUrl \}" src/content/index.ts → 1
- grep -cE "event\.timestamp = Date\.now\(\)" src/content/index.ts → 2
  (1 in addUserEvent normalization at line 54 + 1 new in rrweb emit at line 315)

Pre-checkpoint bundle gates:
- npm run build → 4.66s; dist/ ships cleanly
- Tier-1 FORBIDDEN_HOOK_STRINGS test (no-test-hooks-in-prod-bundle.test.ts)
  → 13/13 GREEN; inventory at 12 strings (unchanged — Plan 04-01 added no
  harness hooks).
- SW CSP-safety: 1 `new Function("...")` in SW chunk — pre-existing
  setimmediate polyfill from vite-plugin-node-polyfills, NOT a Plan 04-01
  regression; documented at .planning/phases/01-stabilize-video-pipeline/
  deferred-items.md as Plan 04-02 fix scope.
- Node-globals / DOM-globals in SW chunk: 1 Buffer + 4 window/document
  references — all from JSZip internals (pre-existing across all Phase 1+2+3
  builds; lower-case `Buffer` field names + DOM shimming inside zip
  assembly).
- manifest.json: present, name uses chrome.i18n __MSG_extName__ message
  resolution (no en↔ru parity surface touched by Plan 04-01).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:25:09 +02:00
3dbc51cdcd test(04-01): Wave 0 RED — audit P1 #11/#14/#15 content-script test scaffolds
Three new test files at tests/content/ (NEW directory mirroring src/content/)
pin the canonical Plan 04-01 contracts; 7 of 9 tests are RED today and flip
GREEN once src/content/index.ts gains the three surgical edits in Task 2.

* tests/content/fetch-interception.test.ts (4 tests; A+C pass today via the
  identity String(string)===string coincidence, B+D RED — they fetch a
  `new Request(url)` and assert target === request.url under the canonical
  `args[0] instanceof Request ? args[0].url : String(args[0])` narrow).
* tests/content/navigation-tracking.test.ts (3 tests; all 3 RED — popstate
  + hashchange + history.pushState wrap all read meta.previousUrl which is
  permanently 'unknown' under today's `history.state?.url || 'unknown'`
  emit; GREEN after module-level `let previousUrl` lands).
* tests/content/rrweb-timestamps.test.ts (2 tests; both RED — Test A asserts
  rrweb-emit normalizes timestamps to Date.now()-class >1e12 instead of the
  rrweb-internal page-load-relative small int; Test B regresses
  cleanupOldEvents arithmetic correctness when both sides are Unix-epoch).

Scaffold mirrors tests/background/start-video-capture-no-tab.test.ts (Plan
01-09): vi.resetModules() in beforeEach, minimal chrome.* + window/document/
history/Request stubs installed on globalThis before
`await import('../../src/content/index')`. rrweb is mocked via vi.mock so the
content-script's `import { record } from 'rrweb'` short-circuits to a no-op
factory (avoids the rrweb-lib ESM-in-CJS transform crash). userEvents and
rrwebEvents are read back through the canonical GET_RRWEB_EVENTS chrome.
runtime.onMessage path the production archive pipeline uses.

Also folds in the .planning/config.json `use_worktrees: false` flip the
orchestrator staged before respawning this executor in foreground mode.

Plan: 04-01 Wave 0
Files:
- tests/content/fetch-interception.test.ts
- tests/content/navigation-tracking.test.ts
- tests/content/rrweb-timestamps.test.ts
- .planning/config.json (worktree mode disabled)

Verification (RED gate):
- npm test -- tests/content/ --run → 7 failed | 2 passed (9)
- grep -c "instanceof Request" tests/content/fetch-interception.test.ts → 5
- grep -c "previousUrl" tests/content/navigation-tracking.test.ts → 24
- grep -cE "Date\.now\(\)" tests/content/rrweb-timestamps.test.ts → 9

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:19:39 +02:00
9ad5069f70 docs(state): mark phase 04 executing — begin-phase tick
Set status=executing, current focus=Phase 04, position=Plan 1 of 7.
2026-05-21 13:32:53 +02:00
3ceca875e5 docs(state): resume-work — HANDOFF.json consumed; user routed to /gsd-execute-phase 4
Session continuity updated; .continue-here.md preserved as secondary fallback.
2026-05-21 10:31:20 +02:00
dbcf4827f6 wip: phase-04 paused — 7 plans validated iter-2 PASSED, ready for execution .planning/phases/04-harden-clean-up-optional/.continue-here.md .planning/HANDOFF.json 2026-05-21 10:25:29 +02:00
55369b80ad docs(state): record phase 4 plan-phase closure — iter-2 PASSED + 3 cosmetic advisories fixed
state.record-session CLI bug recurred (status: completed because 23/30 partial
match triggered; restored: status=ready_to_execute). total_plans correctly
bumped 23 → 30 (Phase 1: 14 + Phase 2: 4 + Phase 3: 5 + Phase 4: 7).

Phase 4 plan-phase ceremony complete:
- 7 plans across 6 waves (Wave 1: 04-01+04-02 parallel; Waves 2-6 single-plan)
- Plan-checker iter-1: 2 BLOCKER + 4 WARNING (fixed)
- Plan-checker iter-2: VERIFICATION PASSED with 3 cosmetic advisories
- 3 cosmetic advisories now fixed (commit 3c1280e):
  * Dim 11 RESEARCH.md Open Questions (RESOLVED) suffix
  * Dim 12 PATTERNS.md:886 DEPRECATED banner citing Plan 04-04 Option B
  * VALIDATION.md frontmatter revision count 4 → 5

Phase 4 ready for execution: 7 plans (~30 anticipated files; 7 new test files;
A33+A34 harness extensions; setimmediate polyfill replacement; dead-code grep;
SW state persistence spike+impl; dark-logo currentColor; cursor verification
+ stale-note correction; closure aggregator + ROADMAP backfill).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 10:21:44 +02:00
3c1280ed2d docs(04): plan-phase closure — 3 cosmetic advisories from checker iter-2 resolved
Plan-checker iter-2 returned VERIFICATION PASSED with 3 cosmetic advisories:
- Dim 11: RESEARCH.md "## Open Questions" missing "(RESOLVED)" suffix → fixed
- Dim 12: PATTERNS.md:886 stale dispatchSaveArchiveForA33 example → added
  DEPRECATED banner citing Plan 04-04 REVISION iter-2 Option B canonical pattern
- VALIDATION.md frontmatter "4 revised tasks" mismatched per-task map (5 rows) → fixed

All 4 BLOCKER+WARNING issues from iter-1 verified resolved by iter-2 plan-checker
(VERIFICATION PASSED). 3 cosmetic items now resolved as well. 2 advisory items
left as-is per iter-1 (W2 scope-sanity at 04-06; W3 conservative 04-03 dep).

Phase 4 plans cleared for execution:
- 7 plans across 6 waves (Wave 1: 04-01+04-02 parallel; Waves 2-6 single-plan)
- Plan-checker iter-2 VERIFICATION PASSED
- Test baselines preserved: vitest 171/171 · UAT harness 33/33 · Tier-1 12

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 10:21:03 +02:00