18 KiB
Superseded rollout status: Companion 1.0.0.18 is now installed. Development rollout, automatic import capture and portable backup support are documented in completion report. Earlier staged/off/backup restrictions below describe the historical foundation, not the current rollout.
Paragraph manuscript synchronisation foundation — 7 November 2026
Delivery and operational boundaries
This is a staged, opt-in foundation, not an enabled Development or production rollout. Features:ParagraphManuscripts defaults to false. Native source version is 1.0.0.18; the separately qualified unified installer remains pinned to 1.0.0.17. No installer, signing, installation or Word automation was performed on Atlas.
The independently committed import recovery fix 2c0e02c7c9f68a9d1a4b6f9139c8798f80b83929 was published to Development from an archive of that exact commit, after the author explicitly confirmed the failed import was stopped and a restart was safe. Deployment release: /srv/apps/plotdirector-dev/releases/2c0e02c-20261107T195222Z; previous deployment preserved at /srv/apps/plotdirector-dev/current-before-2c0e02c-20261107T195222Z. Public health request returned HTTP 200 and plotdirector-dev was active. That deployment contained none of this unfinished-at-the-time foundation. The author was told they could resume their existing import. Do not restart Development again on the strength of the earlier approval. No Production changes.
Migration PlotLine/Sql/240_ParagraphManuscripts.sql was applied and exercised only in guarded synthetic database PlotDirector_Phase2_20261103_2305, after a unique COPY_ONLY/CHECKSUM backup and RESTORE VERIFYONLY. No Development schema migration or feature activation was performed. SQL fixtures roll back their own newly created accounts, books, prose and events.
Architecture and consent
flowchart LR
Word[Word STA / bounded reader] -->|Value fragments; optional native paragraph hint| Agent[Existing per-user agent]
Agent -->|Existing authenticated capture endpoint; full snapshot or delta| Server[Existing native capture service]
Wizard[Existing manuscript import wizard] -->|Explicit import / opt-in| Server
Workspace[Book: manuscript structure and evidence] -->|Owner-approved modes and edits; revision check| Domain[Paragraph manuscript service]
Server --> Domain
Domain -->|Dapper stored procedures| SQL[(Canonical scenes / prose / events + paragraph state)]
SQL -->|Exact session and revision position index| Presence[Existing native presence / Context / Intent]
Server -->|Canonical occurrence IDs and acknowledgement| Agent
There is no new agent process, local server, identity system or SignalR hub. Existing installation approval, token renewal, account scoping, named-pipe backpressure and document sessions remain in use. Old agents and Office.js workflows keep their existing capture method. New paragraph-snapshots-v1 capability and StartParagraphManuscriptScan hub method are additive.
With the feature enabled on an isolated server, the import wizard offers an unchecked paragraph-tracking consent option. Checking it alone transfers nothing. Clicking Import requests the existing native bounded reader and retains the complete raw paragraph stream in the accepted capture. The established chapter/character/import pipeline still owns import; no new scene-by-scene approval requirement is introduced. On successful opt-in build, paragraph tracking starts in On Save mode as described by the consent text.
An owner can instead adopt a completed native capture from Book → Manuscript structure and evidence. Adoption is Manual by default, uses only that preview's canonical scene mappings, refuses an incomplete/non-reversible map, and never incorporates unrelated scene sources. Sections excluded in the accepted import remain captured but outside canonical story prose during later sync.
Modes:
- Manual: explicit Synchronise from Word only.
- On Save: explicit continuing authorisation for a saved/reconnected associated document. More than one eligible document, another manuscript GUID, incomplete import, active Story Intelligence job or lost owner authority prevents automatic transfer.
- Off: no automatic transfer; an explicit manual snapshot is still an author action.
No idle/keystroke-triggered prose upload or automatic AI analysis was added. A successful save is observed through Word's saved state; neither the before-save handler nor IPC waits for the server. An unchanged, already-saved document avoids another extraction. A changed save or reconnect still requires a bounded document read; this is not an implementation of Word incremental change tracking.
Paragraph identity and reconciliation
Shared value logic is in Protocol/Manuscript/ParagraphIdentity.cs and ParagraphDelta.cs; the agent and server use the same implementation.
Each occurrence has an opaque GUID, current ordinal and Word positions, a SHA-256 content fingerprint, native hint, adjacent occurrence IDs, previous text, reconciliation reason and movement/change state. A text hash is never an identity. Native hints are only candidates. Unique native matches preserve ordinary edited/moved occurrences; unique contextual pairs and recognised neighbours provide fallback. Identical dialogue and copies retain independent identities. An ambiguous occurrence gets a new GUID; its old evidence remains unresolved rather than being assigned by a text-only guess.
VSTO reads w14:paraId from a first-character Range.WordOpenXML range once per paragraph, on Word's thread and within the existing measured extraction scheduler. The parser reads only the main document part, bounds XML to 256 Ki characters, and prohibits DTDs/external entities. Unavailable hints fall back to context. It does not read full-document XML or insert per-paragraph controls/bookmarks. An unpersisted manuscript identity can be written as one existing PlotDirector-owned document property only on explicitly requested paragraph capture; Word is marked unsaved, never forcibly saved. Read-only documents require a writable copy.
Microsoft documents paraId as unique within a document part, not as a permanent authoring identity. Regeneration, repeated ambiguous passages and simultaneous move/rewrite may be unresolvable. That uncertainty is intentional. Primary references:
The agent keeps value snapshots in memory only (up to eight sessions and 32 Mi characters across entries), scoped to authentication context and manuscript. It sends ordered occurrence IDs plus changed paragraph text when the server's base hash matches. Repeated source text can reference another prior paragraph's text, never its identity or events. A restart/base mismatch sends one full authorised snapshot and adopts the server's canonical occurrence IDs from its acknowledgement. No plaintext manuscript queue is written to disk. Offline changes stay in Word and are reconciled after reconnection/save or an explicit request.
Bounds include 100,000 paragraphs, 16 Mi characters per snapshot, existing bounded fragment queues, a 100 MiB HTTP request ceiling, 128 MiB SQL JSON ceiling, and bounded undo/evidence budgets. Delta expansion validates unique IDs, base revision, source-text references, ordering, spans and total length. Request hashes reject altered retries; revision CAS prevents a stale snapshot overwriting newer accepted structure.
Scene groupings and evidence
ParagraphManuscriptEngine maintains opaque scene GUIDs mapped to canonical SceneIDs. Headings/front matter/excluded sections remain stored; every included story paragraph belongs to one current scene. Existing H1/marker-based chapter sections and accepted import exclusions are retained. Unknown headings/ambiguous boundaries are flagged; their raw snapshots are retained while canonical scene prose is kept at its last accepted projection. Authors can adjust or explicitly confirm a proposed grouping, separately from confirming factual evidence. The foundation does not automatically create new canonical chapters from later Word edits. Losing an excluded section boundary refuses the update instead of guessing which prose was approved for the book.
A tracked chapter containing an unmapped author scene is refused rather than silently renumbering that scene. Newer archive/chapter decisions made through existing tools likewise cause a conflict instead of being undone by a snapshot.
The book workspace provides paginated paragraphs, scene split, adjacent boundary movement, same-chapter adjacent merge and bounded undo. Moves/reordering of actual prose happen in Word, then reconcile; the server never reorders Word prose. Reliable complete scene movement preserves scene identity. Merge retains the retired canonical scene and its metadata; it does not automatically combine divergent planning, chronology or participant records into the surviving scene. Undo is invalidated by a changed manuscript snapshot or newer conflicting event positions.
Optional primary/supporting evidence attaches to existing Knowledge/Relationship events using paragraph IDs and optional character offsets/ranges. Exact original, author-confirmed and current passages are retained. States are Verified, Needs review and Missing. Changed or deleted text never deletes its event. The workspace provides before/after text, positions, confirm, relink, detach while retaining the event, and access to the existing scene event editor for editing/removal.
SQL derives an event's canonical scene only from verified primary evidence. Unanchored events retain normal scene-based behaviour. Evidence display state is excluded from legacy event JSON so old backup/checkpoint hashes do not change. Knowledge facts/regression checks and relationship state/continuity projections exclude unverified primary evidence while keeping it visible for review. The existing deterministic relationship checker runs inside the save transaction; no whole-book AI is scheduled. Statistics refresh is subsequent derived work and cannot turn a committed snapshot into a falsely reported rollback.
An indexed current-position projection requires the exact manuscript GUID, live session and Word revision. A stale revision returns no scene and does not fall back to old imported offsets. Existing native presence carries the resolved scene to web workspaces. Paragraph-capable agents include cursor movement in their presence change key, even inside an older local marker range.
AI range recovery and confidence compatibility
The 97-versus-99 fixture represents 97 numbered structural inputs, 99 raw source paragraphs (including heading/blank), and a final structural paragraph at Word index 3,551. The prompt contained 97 explicit numbered paragraphs, not 99 numbered inputs or global Word coordinates. The returned 1–99 range was a nonconforming AI proposal. There is no conversion that should turn 97 into 99.
Recovery retains the affected chapter as one StructuralFallback scene, with exact accepted source sequence, rejected proposal JSON, diagnostic and a refinement warning; it invents neither confidence nor narrative summary. It does not clamp the invalid end. Valid chapter checkpoints are reused; identical fallback checkpoints also avoid repeating already-completed provider work. A corrupt source map is still refused rather than hidden. Safely discarding an empty trailing proposal after all real paragraphs are covered remains compatible with older imports.
New opted-in chapter requests use prompt V3, schema 2.0 and strict provider integer confidence 0–100 contracts. The response schema's paragraph maxima are generated from the actual submitted count. Integer JSON remains in persisted parsed output; the existing domain boundary converts once to normalized decimals for legacy consumers. Schema 1.0 decimal output remains readable. The new request version field is omitted when zero, preserving in-flight request/checkpoint hashes; old captures do not silently switch prompts/contracts. Other pre-existing AI stages are not globally re-versioned by this change. Actual provider execution of the new strict contract remains unverified here.
Schema and recovery limitations
Migration 240 adds BookParagraphManuscripts, BookParagraphPositions, ManuscriptEvidenceIndex, the scoped ParagraphManuscript procedure and evidence projection procedure, and updates deterministic continuity/recovery guards. It does not migrate existing captures, rewrite planning, replay jobs, create credentials or delete author events. Writes require the existing project-owner role; readers require active project access. Book deletion cascades new state.
Important staged-release limitation: downloaded backups/saved-point replacement do not yet have a qualified portable/remapped paragraph-evidence contract. Legacy recovery is explicitly refused for tracked projects, before incomplete export or replacement, rather than silently losing new author decisions. Do not enable this feature on a real author book until that extension is implemented and round-trip tested. Test using isolated books. The default-off gate and this refusal are deliberate; the feature is not ready for general author rollout.
Other remaining qualification: actual Word native hint behaviour on paste/split/merge/reopen, Word UI responsiveness and first-character XML costs, the new browser workspace's interactive layout/actions, real desktop-to-server execution, live Context/Intent after paragraph edits, and strict AI provider execution. Atlas tests do not establish these.
Reproduction and verification
Run serially from the repository root:
dotnet build PlotLine.slnx
dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj
dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj -- --paragraph-manuscripts
dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj -- --native-import-corrections
dotnet run --project PlotDirector.NativeCompanion/Tests/PlotDirector.Companion.Tests.csproj
Browser regressions: first render the fixture using dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj -- --paragraph-view, then from PlotLine.Tests/Browser run node native-import-connection.cjs and node paragraph-manuscript.cjs. It exercises disconnected/expired/wrong-book states, explicit-only transfer, legacy method compatibility and the new unchecked/explicit paragraph consent path, using isolated browser fixtures, not an author's live import.
Database fixture: PlotLine.Tests/Sql/ParagraphManuscripts.sql, only on its exact named synthetic database with the PlotDirector.Phase2.SyntheticOnly=true guard, after applying migration 240 there. Assertions compare exact prose, canonical event locations, identity/revision state, duplicate acknowledgements, stale position refusal, new scene allocation, cross-account refusal and explicit backup omission protection. Fixture changes are rolled back.
Acceptance evidence covers initial occurrence IDs, serialized reopen/reconnect simulation, movement with attached event, copies, identical dialogue, rewritten/missing evidence, scene split/boundary/merge/undo, continuity exclusion and legacy/in-flight compatibility. The 250,000+ word fixture measures shared in-memory reconciliation, not COM. Final command results and commit references are recorded in the Windows handover.
Final Atlas verification
- Solution build: succeeded, zero warnings/errors; managed Windows target compiled, VSTO host not built/run.
- Application executable harness: 455 reported PASS checks, successful exit.
- Focused paragraph suite: 38 PASS checks, including completed-build adoption/exclusions, save/reconnect, cancellation, permission/refinement and preference-only Off.
- Focused native import recovery/integer contract: 19 PASS checks.
- Native executable harness: 270 checks, successful exit; Linux pipe execution is not Windows ACL/COM evidence.
- Actual compiled Razor workspace rendered through an isolated HTTP fixture; scoped routes, antiforgery, encoded prose, typed evidence selection and 100-paragraph pagination checked.
- Playwright:
native-import-connection.cjsandparagraph-manuscript.cjspassed, using isolated fixtures/compiled Razor output. This does not claim full shared-shell theme/layout or interactive Windows qualification. - Synthetic SQL migration and six assertion groups passed: exact prose/revision/idempotency/missing evidence; canonical split and verified event move; uncertain grouping retains raw source without canonical overwrite; unmapped author scene refusal; backup omission protection; cross-account denial/rollback. SQL emitted only expected null-elimination aggregate warnings for an empty scene.
- 250,000+ word in-memory fixture: 372 ms in the final focused run, not a Word responsiveness measurement.
- Synthetic backup:
/var/opt/mssql/backup/paragraph-foundation-20261107-201718.bak, COPY_ONLY/CHECKSUM, RESTORE VERIFYONLY valid. No Development migration. - Recovery-only deployed DLL SHA-256 matches the archived
2c0e02cpublication:520762918cdd7cb5dc33f23ed17c6c55aba99d1bbe34679f302e68f5ec86ddf3.
For tracked test books, use the per-book Off preference to stop transfers while retaining the paragraph read/review infrastructure. Do not treat hiding the feature with a server-wide rollback as a qualified migration/recovery procedure. The portable backup extension remains a general-rollout blocker.
Application source was committed as 5d755461078e1e6137fa2aa8a8a7af255ce6cf0a on the existing shared branch. The subsequent Windows handover is a documentation-only descendant; see the exact Windows instructions.