10 KiB
Manuscript Reader — live updates and persistent Focus Reading
This extends Phase 1 without changing the accepted manuscript store, Word Companion, reconciliation, installers, SQL schema or Maps.
Change detection and server overhead
An authenticated GET to /manuscript/reader/changes checks immediately on opening a selected chapter and every 12 seconds while visible. It carries book/chapter IDs, the last observed accepted book revision and chapter fingerprint. Existing ParagraphManuscript status, Book_Get and Chapter_Get stored procedures enforce book access and validate the active chapter. Stable polls perform three small stored-procedure reads and transfer only a small JSON response; they do not retrieve paragraph JSON or prose.
When the accepted book revision differs, the service uses the existing read-only projection to compute a SHA-256 fingerprint over the selected chapter's ordered paragraph GUIDs, exact text and heading flags, with length-delimited encoding. The returned revision is the revision of the snapshot actually read. A preference revision, unchanged successful synchronisation or another chapter's update does not replace the selected chapter when its fingerprint is unchanged. Pending/rejected submissions never enter the committed source.
Only a changed chapter fingerprint causes the browser to GET /manuscript/reader/chapter, which returns that chapter's JSON paragraphs and accurately sourced timestamps. Both new GET endpoints retain authentication, access checks, no-store responses, safe generic errors and no-index headers. Browser rendering uses textContent, never manuscript HTML insertion. Revisions travel as decimal strings to avoid JavaScript integer precision loss.
The existing storage API still reads/deserialises the book aggregate on the server to calculate a chapter fingerprint after a revision change and to retrieve a changed chapter. This happens on candidate changes, not every polling interval; a genuine selected-chapter change can therefore cause two aggregate reads. There is no new SQL projection, persistent cache, database object or browser book preload. The normal metadata-only path is approximately 15 small stored-procedure calls per minute per visible Reader tab. No polling occurs while hidden.
Reading session behaviour
Updates preserve a visible paragraph GUID and its vertical screen offset, using nearby surviving GUIDs or exact paragraph text when needed. Scroll restoration is instantaneous (including under themes that enable smooth scrolling). Replacements retain Focus Reading. If no usable anchor survives, the page offers an explicit update instead of forcibly resetting the reading session.
A non-collapsed browser selection defers both full chapter retrieval and DOM replacement. Metadata checks can continue tracking the newest accepted version, but the page does not repeatedly fetch or replace the deferred chapter. Clearing the selection fetches the latest accepted chapter. A second selection/pause check after the full fetch protects selections made while that request was running.
Pause automatic updates while listening retains the current text and offers Show updated chapter. The latter is an explicit user action and may clear selection to display the pending chapter. No proprietary text-to-speech API or reliable extension-playback detection exists. Extensions without a browser selection should use the pause control; interruption-free third-party playback cannot be guaranteed during an automatic replacement.
There is one serial polling loop. Hidden pages suspend polling and abort outstanding requests, visible/online pages check promptly, transient errors retain prose and retry, and access/authentication failures stop polling with an unobtrusive message. Requests are cancelled/ignored on navigation. Reinitialisation disposes the old timer and listeners. Browsers restoring a Reader from the back/forward cache rearm its loop.
Focus Reading navigation
Focus Reading is a Reader viewing preference carried by the Reader URL (focus=true), chapter links and chapter form. The server renders the focused state, and CSS applies it before the deferred script executes. Next, Previous, the chapter selector and Reader refresh links preserve it. Explicit exit/Escape removes it; navigating away does not apply focus to other workspaces. No manuscript state or browser prose storage is involved.
Each newly navigated chapter starts at its beginning; automatic updates within the same chapter preserve position. Normal navigation and first/last chapter boundaries are unchanged.
Verification
- Application build, full executable regression harness and the original 24-combination Reader browser suite.
- Focused service tests cover initial/stable metadata-only checks, genuine accepted content, unchanged successful synchronisation, another chapter's update, pending/rejected isolation, chapter/account access and timestamp provenance.
PlotLine.Tests/Browser/manuscript-reader-live.cjscovers actual controller/cache/access boundaries plus simulated accepted updates: no page reload, normal/focused paragraph anchors, deferred/latest version while selected, listening pause/manual action, hidden/visible lifecycle, offline/recovery, reinitialisation/single loop, in-flight navigation, Next/Previous/dropdown focus persistence, top-of-new-chapter and first/last boundaries. It runs desktop/mobile, ordinary browser/simulated PWA, with all four themes checked. It does not write a database or drive real Word.
Example browser invocation against the isolated fixture host:
PD_BROWSER_FIXTURE_URL=http://127.0.0.1:5249 node PlotLine.Tests/Browser/manuscript-reader-live.cjs
The author reports Word-to-server acceptance and manual-refresh Reader visibility were verified before this task. This task's synchronisation-change browser fixtures are simulations, not evidence of another real Word run. Actual installed Windows PWA and text-to-speech extension playback must be qualified on Windows.
Development delivery — 13 November 2026
- Implementation/deployed commit:
7855ff1ac104380e59d65a5a40e5762b1617a693, shared branchcodex/word-companion-native-phase1-20261104. - Target: https://dev.plotdirector.com/;
plotdirector-devon Atlas with verified effective databasePlotDirector_Development. Production was untouched. - Qualified gates passed: solution build (zero warnings/errors), full executable regression harness, original Reader browser suite (three widths × four themes × browser/PWA) and new live-update suite (desktop/mobile × browser/PWA × normal/focused). New live tests also cover loss of every anchor/manual fallback, selection beginning during a fetch, safe HTML-like updated text and network-recovery status.
- Publish/install/smoke window: 20:22:55–20:25:20 UTC, 144.68 seconds (2 minutes 25 seconds), within the 10-minute limit. Installation/startup checks finished after 55.86 seconds. Source was exported immutably from the candidate before publish to exclude concurrent work.
- Published/deployed DLL SHA-256:
95dfff9df4b91f7dbf0b330d2d5529fc3eabee21dceb64850bf598c13698a8a1; deployed metadata contains the exact candidate commit. - Release archive:
/srv/apps/plotdirector-dev/releases/reader-live-7855ff1-20261113T202255Z. - Code-only rollback:
/srv/apps/plotdirector-dev/current-before-reader-live-7855ff1-20261113T202255Z. Prior deployed code wasdad70a1, including the separately completed geographical fixes, with DLL SHA-2565b8df4a389591885ad28163a40587621c157e4e50b41cca463a4a7546bc8f7ca. No Maps code was changed in this delivery. - Active-work restart gate passed before deployment and again immediately before interruption. Normal rsync exclusions retained settings, data-protection material, uploads and logs. Protected configuration/key fingerprints match. No SQL, configuration, Companion/agent/installer or synchronisation-contract change was required.
- Live HTTPS GET, login controls, Reader/new change/chapter route login redirects, Reader assets (including the new polling script), existing Chapter/Book routes and native API credential boundaries passed. The service is active. Native cursor presence was observed after restart. The existing local HTTP HTTPS-port warning remains; public TLS checks passed normally.
- A read-only helper loading the deployed assembly verified 537 exact ordered paragraphs in first/middle/last chapters of an existing accepted manuscript, timestamp provenance, the stable metadata path, revision-change fingerprint comparison with unchanged prose, and foreign-account refusal. It exported no prose and made no manuscript changes.
- Pre-deployment versus final post-smoke aggregate fingerprints match for all paragraph manuscript payloads/revisions/request IDs (including GUIDs/checkpoints), paragraph positions, chapter validations, manuscript bindings and database object definitions. No schema or manuscript/synchronisation state was modified.
- Live authenticated browser acceptance remains unverified: no existing author session or supplied credentials were available. Public authentication boundaries and deployed-assembly/database tests are distinct from a live signed-in DOM test. Browser update tests use synthetic accepted versions; no real author prose was edited to manufacture a change.
Windows acceptance for this improvement
- Sign in to Development, open an existing accepted chapter in Manuscript Reader, enable Focus Reading and read partway down. Keep the tab visible.
- In Windows Word using the current Companion, make an identifiable normal edit in that chapter, save, and wait for successful Companion acceptance.
- With no browser text selection and automatic updates unpaused, confirm the new text appears within approximately 12 seconds plus request time, without a page reload, focus exit or paragraph-position reset.
- Repeat while several Reader paragraphs are selected: the update indication should appear while the selection and displayed text remain intact. Clear the selection and confirm the newest accepted version appears. For text-to-speech playback without a persistent browser selection, enable Pause automatic updates while listening, then apply updates explicitly when ready.
- Use Next, Previous and the chapter selector. Each new chapter should start at the beginning and remain focused. Changes to the old chapter must not replace the new chapter. Explicitly exit focus/Escape or leave the Reader when finished.
This new real Word-to-automatic-Reader acceptance procedure was not performed on Atlas.