PlotDirector/Docs/WordCompanion/WindowsHandover/2026-11-09-chapter-sync.md

73 lines
8.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Windows handover: chapter synchronisation, candidate 1.0.0.23
Use only `codex/word-companion-native-phase1-20261104`. Atlas implementation/deployment evidence and the exact handover commits are in [the implementation report](../2026-11-09-chapter-sync-implementation.md). Fetch the configured tracking remote, inspect/preserve the worktree, and fast-forward only. Stop on divergence. No branches, worktrees, rebase, force pushes, trust-store changes or installer redesign.
Expected tested Atlas executable-source commit: **`f171d8b1969b343eb1fbc28f9402acfd51624d21`** (with documentation-only descendants acceptable). Development is deployed at that commit with SQL 245–247; no server migration is required from Windows. Verify `git merge-base --is-ancestor f171d8b1969b343eb1fbc28f9402acfd51624d21 HEAD` before building. The installed .22 baseline remains untouched.
## Non-interactive build first
Do not use Computer Use, launch Word, steal focus, close applications or install anything during unattended qualification. Identify the actual Windows user/profile; a sandbox registry does not establish installation for the interactive author. Atlas did not build the VSTO, sign, package or install this candidate.
The managed/native-source changes are:
- `Protocol/Manuscript/ChapterFingerprint.cs`, `Messages.cs`, `TrayContracts.cs`: optional `chapter-sync-v1`; exact fingerprints, bounded chapter frames and server-owned progress.
- `Client/AgentLink.cs`, `Agent/PipeHost.cs`, `SessionManager.cs`, `TrayCoordinator.Chapters.cs`, `TrayCoordinator.cs`, `CloudGateway.cs`: negotiated current-chapter checking, progressive/resumable acceptance, changed-chapter-only upload under the existing synchronisation preference or explicit repair permit.
- `Vsto/WordChapterRead.cs` (explicitly included in `PlotDirector.WordAddIn.csproj`), `WordAdapter.cs`, `NativeRibbon.cs`, `Ribbon.xml`: owner-thread staged Range reads, no selection, compact chapter status and Synchronise/Repair/Troubleshooting. No permanent paragraph markers or prose edits.
- `Agent/TrayApplication.cs`: displays the existing server chapter progress in the compact guidance area; authentication/association/installer architecture retained.
Run serially from the existing checkout:
```powershell
.\PlotDirector.NativeCompanion\WindowsValidation\Update-WordCompanion.ps1
# Optional existing signing identity when discovery is ambiguous:
# ... -CertificateThumbprint '<existing thumbprint>'
dotnet run --project PlotDirector.NativeCompanion/Tests -- --chapter-sync
dotnet run --project PlotLine.Tests -- --chapter-sync
dotnet run --project PlotLine.Tests -- --paragraph-manuscripts
```
The update script builds the signed VSTO and managed components and prepares a developer package; it does **not** install. Expected package: the real user's Downloads known folder, `PlotDirectorWordCompanion\1.0.0.23-<first-eight-source-SHA>`. Verify `package.json`, both payload versions and clean source SHA. Preserve the installed 1.0.0.22 package. If a Windows compiler/API error occurs, make only a focused native compatibility fix, test, commit and push this same branch.
Use the existing unified installer, after build validation:
```powershell
.\PlotDirector.NativeCompanion\WindowsValidation\Setup\Build-Setup.ps1 `
-PackagePath '<verified developer package directory>' `
-ExpectedSourceCommit '<exact clean package SHA>' `
-OutputDirectory '<new candidate output directory>' `
-CertificateThumbprint '<existing thumbprint>'
```
`WindowsValidation/Setup/Release.json` selects application **1.0.0.23**, MSI **1.0.23**, a fresh ProductCode and unchanged upgrade family/baseline pins. Keep those qualified baseline pins; they are not invented hashes for .22. Verify using `Setup/README.md` and the existing `Test-SetupPackage.ps1` procedure. Deliver **PlotDirectorCompanionSetup.exe** with both VSTO and agent. Do not substitute a loose `.vsto` file. Installation is a separate explicitly scheduled step; do not open approval prompts unattended. Preserve protected credentials, settings and associations. Do not forcibly close Word or other applications.
## Native benchmark — scheduled interactive session only
Use a copy of an author-owned test manuscript, saved, with a representative complete Heading 1 chapter selected by the human. Do not automate that selection. Attach to already running Word:
```powershell
powershell.exe -STA -File .\PlotDirector.NativeCompanion\WindowsValidation\Measure-ChapterSync.ps1 `
-ProtocolAssembly '<verified netstandard2.0 protocol DLL from the package/build>' `
-OutputFile '<new absolute JSON report path>'
# Optional explicitly expensive, capped legacy baseline:
# ... -IncludeLegacyParagraphXml -MaximumParagraphs 100
```
The script never launches, selects, saves or closes Word. It records Range.Text, exact SHA-256, one chapter WordOpenXML, portable native-ID parsing and optional capped per-paragraph XML timings. Unsupported XML is recorded as a parse error, not hidden. Cross-process COM wall time is **not** in-add-in UI occupancy: also collect existing `chapter-range-text`, `chapter-range-xml`, `chapter-next-heading-identity` and `chapter-ui-step` metrics from Advanced/Troubleshooting. Report actual chapter sizes, max/median timings, observed typing/scrolling/save/cursor behaviour. No speed claim without measurements.
## Functional acceptance
First use disposable books and copied documents; never reimport/reset/delete book 10152 to test this work.
1. Verify both .23 binaries, retained sign-in/settings/book association and negotiated chapter capability. Development must expose `chapterSyncSupported=true`; .22 remains on its old path.
2. Open a previously indexed, unchanged Heading 1 manuscript in a new Word session. The active chapter should be checked first, then remaining chapters progressively. Confirm current Context scene across chapters, including a chapter not yet checked. No full snapshot request, per-paragraph XML loop, automatic AI call, passive `navigate`, Range.Select or prose edit should occur.
3. Measure the **target**, not an assumed result: current chapter following returns in seconds; individual COM steps aim around 20–30 ms where practical. A single Word COM call cannot be preempted; oversized/complex chapters must report review/fallback rather than freeze or guess.
4. Manual mode: edit/save a chapter, verify `Changed` without prose upload. Explicit Synchronise/Repair authorises that chapter only. On-save mode: verify changed chapter reconciliation, unchanged GUIDs/scenes, later chapters' shifted positions and no AI restart. Word saving must never await Companion.
5. Stop Companion, edit/save, restart. Validate actual chapter evidence again; do not reuse old absolute offsets merely because the book/session looks familiar.
6. Cancel after some chapters are accepted, reconnect/restart and Repair. Previously accepted current-session checkpoints resume; a new session revalidates cheaply. Chapter rename with stable identity may reconcile; inserted/deleted/moved chapter boundaries and duplicate native IDs must require review without canonical reassignment.
7. Switch three documents/books rapidly while checking; close one; terminate/restart the agent. Late frames must not affect another document. No flashing from repeated ribbon invalidation, unexpected focus or selection change. Repeated cursor notifications cannot command Word.
8. Inspect blank/headingless documents, tables/fields/track changes, large chapters and repeated prose. Fast-path refusal is safe; the explicit full snapshot fallback remains available. Do not use fallback automatically or claim unsupported content passed.
9. Check compact progress, book/chapter/scene tooltip, Sync, Repair and Troubleshooting; top-right website Word connection dialog and book → Manuscript structure and evidence show consistent server acceptance. A requested repair must not inherit an earlier green completion.
10. Backup/restore a disposable indexed book. Paragraph/native GUID evidence, canonical remapping, source fingerprints and author decisions must survive. Restored books start Manual and have no live-session trust.
Only after synthetic qualification, with the author's agreement, use **Repair Manuscript Synchronisation** on the existing 10152 import. Keep its 48 chapters/290 scenes/paragraph GUIDs and SI/author decisions. Missing checkpoints are not corruption. Do not rerun import or analysis. Compare accepted data before/after; stop on ambiguity. Report real Word results separately from automated/HTTP tests, with exact commits and installer hashes.