/* Brain of Reese — doc edit screen (phase 59, task 06). * * The standalone, admin-gated flow page * ``/doc-edit.html?draft=``: load the draft the chat page's * "Save as doc" action (task 05) just created, edit the three fields * (title, in-repo path, markdown body), and push — the commit lands on * the .env-configured docs branch of the .env-configured repo, and the * owner opens the PR themselves (D3: no PR tooling anywhere). * * The page is static; the API is the authority. The whoami gate is the * ``sources-gate`` pattern (phases 16/35/50): anonymous visitors see * the sign-in gate and NO /api/doc-drafts call is made (the draft * endpoints are admin-only regardless — no draft data can leak through * the page). * * Boot (admin): read ``?draft=`` — missing → the error banner * "No draft specified."; a malformed (non-uuid) token is treated as * unknown → "Draft not found." with NO fetch (the shared.js malformed- * token precedent) — then ``GET /api/doc-drafts/``: 404 → * "Draft not found.", any other non-2xx → the server's detail line, a * network failure → the fixed one-line copy. On 200 the three fields * are filled with VALUES (``.value`` only — never as markup; the body * is user-derived markdown). * * Push (the §7.4 never-stale lifecycle, on #push-doc-btn): * 1. client-side sanity FIRST — non-empty title/body, no ".." in the * path (the server re-runs its guard-rails and is the authority; * the browser's native ``required`` is the first line, these the * second); * 2. the button disables + relabels "Pushing…" and the live region * says "Pushing…"; * 3. ``PUT /api/doc-drafts/`` with all three fields — the * push endpoint (task 04) commits the ROW's title/path/body, so * the current edits must land on the row first (an unsaved edit * would otherwise push the stale text); * 4. ``POST /api/doc-drafts//push``: * • 200 → the live region: `Pushed to — commit .` * (the full sha comes from the API, the first seven chars are * shown — a re-push after further edits is a NEW commit on the * same branch, the D3 ASSUMPTION); the button re-enables with * its idle label; * • non-2xx → the #push-error banner with the API's detail — for * a git failure (502) that is git's stderr, trimmed to its * first meaningful lines; the fields are PRESERVED (the fix is * an edit, not a re-type) and the button re-enables; * • network failure → the fixed one-line copy, same recovery. * * The shared header module loads through this script's own relative * import ("./header.js") — a hoisted import evaluated before this body * runs (single-evaluation design: no direct