PlotDirector/Docs/Writer/Unified-Manuscript-Focus-20261123.md

14 KiB
Raw Blame History

Unified manuscript focus — implementation and qualification

Development only, 23 November 2026. Existing feature branch: codex/word-companion-native-phase1-20261104. The application commit, release directory, hashes and post-deployment results are recorded in the deployment evidence linked below.

Audit and architectural choice

Previously, NarrativeFocus stored personal chapter/scene navigation, with browser storage/focus events supplying recovery. Review's chapter GET could change that state. Context principally followed native/Office presence and its navigation endpoint requested a Word command, which made it ineffective without Word. Review's paragraph selection updated review tools and the explicit Word target, but did not publish a common manuscript position.

Context already owned one native-presence SignalR connection per window, independent cached tabs, split panes, layout persistence, window identity and duplicate-window detection. Its invalidation handler already allowed an earlier-scene change to invalidate later-scene projections; it must remain independent of navigation. Snapshot windows previously skipped connection setup. The main application already had a shared native-presence connection, and the native tray Companion already had a validated command queue, asynchronous agent wake notifications, exact document sessions and acknowledgements.

The implementation extends these paths. It does not introduce another hub, Context connection, manuscript copy, editor owner, focus polling loop or Intent surface. Existing content/status checks remain. The current Windows VSTO/tray architecture is the Word implementation target; the older Office.js task-pane shell remains unchanged and is not advertised as a shared-focus client.

Server contract

Forward-only migrations 314–317 extend the existing NarrativeFocus row with canonical manuscript/paragraph and originating-window IDs; add a per-origin sequence replay ledger; replace implicit objective seeding and read-time redirection; and resolve Word positions from exact-session verified chapter evidence. Backup /var/opt/mssql/backup/shared-manuscript-focus-20261123T125506Z.bak completed with COPY_ONLY/CHECKSUM and passed VERIFYONLY before the initial migrations. The chapter-only/empty-chapter boundary correction in 317 used a further verified backup, /var/opt/mssql/backup/shared-focus-boundary-20261123T134529Z.bak. VERIFYONLY is not a restore test.

GET /NarrativeFocus/Shared?projectID=…&bookID=… retrieves authoritative focus. Antiforgery-protected POSTs to /NarrativeFocus/Shared/Publish, /Resolve and /Validate accept existing identifiers. Resolve performs held local navigation; Validate checks a retained reference; neither publishes. Every operation verifies active authenticated access, project/book membership, canonical manuscript identity and chapter/scene/paragraph compatibility in stored procedures accessed through Dapper. Navigation remains available to read-only subscription accounts.

The packet contains ProjectID, BookID, ManuscriptID, ChapterID, optional SceneID/ParagraphID, OriginWindowID, Version, IsValid and Changed. It contains no prose, Word offsets or contextual datasets. The server locks the existing focus row and assigns increasing revisions atomically. Different clients are ordered by accepted server revisions, without client timestamps. Duplicate/older per-window sequences and unchanged effective targets do not create another revision. A stale stored reference is returned as invalid, without silently moving it. Clients process validity metadata even when the focus revision is unchanged, so Release never reuses a cached valid flag for a now-invalid shared point.

ManuscriptFocusChanged uses the existing authenticated NativeCompanionPresenceHub.UserGroup. ManuscriptFocusDelivery reports unavailable Word mapping without blocking other clients. Browser clients scope-filter messages, reject obsolete/duplicate revisions, serialize rapid local intent and recover on connect/reconnect. Ordinary GETs, refreshes, passive observations and received navigation do not publish. Existing explicit browser navigation delegates to the coordinator; server GET hooks no longer write focus.

A future editor can use the same identifier-only contract and existing authenticated transport without changing manuscript content ownership.

Clients and Hold

Review publishes deliberate paragraph clicks, paragraph keyboard navigation and chapter/scene selectors, including when Word is closed. Accepted content remains authoritative. Incoming focus uses the existing partial chapter/scene positioning pipeline, preserves open editors and review tools, and explains missing precise paragraph/scene mapping before showing a deterministic scene/chapter fallback. A missing held passage stops positioning and offers local reselection/Release, without moving to another paragraph. Scrolling does not publish.

Context dropdown, Previous, Next and Go to Focus use shared focus directly, without a Word navigation request. Each window retains its panes, tools, divider, cached tab state and layout. Snapshot windows also keep data notifications. Focus changes only invalidate panels whose scope changed. Data invalidation is independent of Hold and conservatively refreshes affected visible relationship/character panels across scenes; hidden panels are marked stale until activated. Structural invalidation retains the held reference and offers another local selection or Release Hold.

Browser Hold is stored in session storage under authenticated-user/window identity, separately from global book preferences. An ordinary refresh retains Hold and local position. Existing Context identity arbitration plus browser identity claims prevent duplicated storage from sharing Hold. New windows default to Follow. Release obtains current authoritative focus, then follows it; it never publishes the held position. With no valid shared focus, it retains the local position and follows without creating one. Failed recovery retains Hold.

The static Hold control and status appear in Review/application ribbons and Context. Hold remains visible when the installed PWA compacts Previous/Go/Next into its existing menu. Labels explicitly say Following/Held and Release Hold; colour is supplementary.

Native Word adds Hold/Follow to the existing ribbon and uses a distinct state/identity for each actual Word window. The adapter distinguishes foreground mouse/navigation-key selection events from passive observations and suppresses incoming-navigation publication. Deliberate observations pass through existing framed IPC and native presence, then resolve canonical paragraph IDs using saved, fresh, exact-session verified chapter positions. Existing agent wake/command/receipt delivery supplies background following. Shared commands use Window.ScrollIntoView, not Select, Activate or a foreground-window call; editing selection/content ownership is retained. Unmapped, unsaved and busy states are explicit. Word Outline view cannot use this API and requires changing view before retrying (Microsoft API contract). Window state rejects old/duplicate deliveries and Release can catch the same window's own previously published shared position.

Explicit Open in Word controls are retained, including paragraph navigation: physical native replacement qualification is not complete, so removing these controls would be premature. They remain useful for unsupported/disconnected/held/unmapped Word sessions and opening the manuscript. Shared paragraph/Context selection never automatically launches Word.

Verification

  • Solution build: zero warnings/errors; full executable regression harness: 786 passing checks.
  • Native portable regression harness: 320 passing checks, including the dedicated per-window Hold/revision cases. These exercise managed production logic and IPC, not Word COM.
  • Development rollback-only SQL tests cover no initial publication, canonical paragraph resolution, monotonic revisions, unchanged-target suppression, replay rejection, held resolution without mutation, canonical cross-chapter stepping, chapter-only and empty-chapter boundaries, endpoint paragraph preservation, invalid references, verified Word offsets, exact-session isolation and authorisation. The updated historical six-phase SQL regression also passes with no implicit seed/redirection.
  • Sixteen real concurrent SQL connections verify contiguous unique accepted revisions and a final durable read equal to the highest revision. Real coordinator/SQL/native-queue integration also verifies Word-only publication, browser-to-Word chapter crossing, passive suppression, Hold/release, failed receipts, unsaved documents, delivery renewal after a saved Word/snapshot revision, and exact-session isolation through a recording transport.
  • Real authenticated Chromium and installed standalone Chromium PWA tests use the actual controllers, SQL and SignalR with a synthetic isolated project/manuscript. They cover Context alone; Review/Context without Word; local scrolling; exact paragraphs and chapter crossing; independent Hold; local held Review navigation; refresh and release without publication; rapid and obsolete ordering; new/duplicated-window isolation; reconnect; responsive widths; hidden tabs; a synthetic missing-accepted-passage resolver check that prevents held Review fallback navigation; and relationship edits in an earlier scene refreshing both held panes. The refreshed later-scene graph is checked for the new note, not just a refresh request.
  • Actual loopback server restart passed: durable focus recovered, SignalR reconnected, and the held window detected an offline structural change without redirecting. Browser structural archival acceptance passed. Final public Development smoke results are recorded in deployment evidence. Browser fixtures are isolated and archived after testing; no real manuscript text or relationships are edited.

Reproducible entry points: PlotLine.Tests --shared-focus-database <disposable-scope-file> (rollback); --shared-focus-browser-setup <disposable-scope-file>; --shared-focus-browser-host (loopback only, real auth/SQL/hub, no hosted workers); --shared-focus-concurrent; --shared-focus-cleanup. Browser: PlotLine.Tests/Browser/shared-manuscript-focus.cjs, optionally --installed, --structure, or the externally coordinated --restart case, with private disposable identity supplied through PD_CONTEXT_IDENTITY. Portable native: --shared-focus. No credentials are in the report or repository.

Windows qualification still required

This Linux host cannot compile/load the Office/VSTO project or run physical Word, Windows foreground handling or multiple monitors. The main .NET build deliberately excludes that project. Browser and portable native passes are not physical Word acceptance; no new Word binary has been installed or published by this task.

  1. On an Office-equipped Windows development machine, use the existing shared branch and PlotDirector.NativeCompanion/WindowsValidation/Update-WordCompanion.ps1 workflow at the recorded commit. Build/sign/verify the package, then use its existing explicit development installation procedure. Verify the loaded add-in/agent commit before testing.
  2. Associate/save a disposable Development manuscript and complete chapter position verification. With Word alone, click and keyboard-select paragraphs across chapter/scene boundaries. Inspect shared revisions, then open Review/Context and verify initialization at the latest position without a new publication.
  3. Exercise Word+Review, Word+Context and all three, with two Context windows (one Held) and split panes. Scroll Word and Review without changing shared focus. Select paragraphs/chapter/scene deliberately in each client and verify only followers move.
  4. Keep Review foreground on another monitor. Select a paragraph there; verify Word reveals the exact target while the Windows foreground process, insertion point, selection and manuscript text remain unchanged. Repeat while Word has a dialog, protected view or editing activity; verify explicit busy/unmapped handling without activation.
  5. Hold each Word window independently, including two windows on the same document. Navigate/edit locally; verify content synchronization continues and shared revision is unchanged. Release to the latest shared point, including one originally published by that same window. Close/reopen a window and verify new Follow identity.
  6. Close each client in turn, including Word unexpectedly, and verify remaining pairs still navigate. Reconnect/restart the agent/service, rapidly alternate publications, and replay/delay notifications; verify newest accepted focus wins without an echo. Test saved/unsaved and stale/expired mapping transitions and independent manuscripts/accounts.
  7. Repeat the earlier-scene relationship edit while a later-scene diagram is Held; verify data changes without movement. Archive a disposable held scene and verify explicit invalid-reference recovery. Confirm existing editing, synchronization, review tools, launch actions and ribbon layout.

Older native installations do not advertise the new capability. They retain editing, content synchronisation and explicit Word navigation, but must be updated before participating in shared focus; passive legacy cursor-following is replaced rather than promoted into deliberate focus. Existing connection details and Review status make that upgrade requirement explicit. Precise native following requires fresh verified saved chapter positions; legacy paragraph-only offsets are not guessed. Historical Office.js hosting requires separate host-specific implementation/qualification before shared-focus support can be claimed there.

Deployment evidence: Unified-Manuscript-Focus-Deployment-20261123.md.

Windows follow-up: .45 build, ribbon/Context reuse, Development deployment and pending physical installation. This records actual Office/VSTO build and package qualification; installed Word remains .44 pending the owner's safe save/close window. Portable/browser results do not replace the listed physical tests.