13 KiB
Native Word Companion Phase 3.5 integration
Outcome and boundaries
Developer build 1.0.0.6 extends Phase 3 on the same shared branch. Existing authenticated chapter AI, bounded extraction, local detection, named pipes and separate .NET 10 agent are retained. There is no replacement architecture, new UI framework, schema migration, native live SignalR protocol or manuscript rewriting.
The useful integrated path is: local detection → explicit chapter AI → source-labelled review → bounded cross-page chapter/scene selection → authenticated read-only import preview. Native commit is deliberately unavailable. This is the largest safe import portion delivered under the assignment's fallback; it must not be described as completed native importing.
Architecture and ownership
flowchart LR
W[Word STA scheduler and ribbon] <-->|value-only bounded IPC| A[Per-user .NET 10 agent]
W --> R[Modeless review: per-document book binding]
A -->|bearer HTTPS| N[Existing native API plus workflow endpoints]
N --> P[Existing book ownership and subscription checks]
N --> C[Existing Context and chapter workflow services]
N --> I[Existing manuscript eligibility and validation]
N --> AI[Existing chapter AI service]
A -->|explicit open only| B[Pinned saved Context / Intent or book browser page]
L[Existing Office.js SignalR connection] --> V[Ordinary live browser Context / Intent]
No HTTP, credentials, parsing, database operations or AI execute in VSTO. New saved-data/preview responses use optional workspace-review-v1 capability negotiation. Existing core IPC and chapter-ai-v2 remain compatible. Existing Office.js routes, hub methods, event contracts and ordinary multi-screen live following are retained.
Experience audit and repairs
| Finding | Repair / actual resulting behaviour |
|---|---|
| A previous successful sign-in string could look current after outages | Shared ConnectionHealth / ConnectionPresentation; IPC failure overrides cached server/auth/book state, server checks have a freshness limit, 401 rotates the authentication scope and clears access. |
| One book combo was not an authorised per-document context | DocumentBinding and DocumentWorkspaceWork bind exact session/revision/book/authentication/binding IDs. Switching clears prior saved data immediately; delayed replies are discarded. |
| Native Context / Intent had no useful saved-data integration | Read-only summaries from existing scene Context and chapter workflow/goals, with source labels, book/chapter/scene title and explicit missing-data messages. Foreign saved markers are rejected. |
| Opening a browser URL could start following the legacy latest Word connection | Explicit pinned=true snapshot mode suppresses live subscription, global story-position listeners and window registration for these views. Manual scene/tab navigation remains; ordinary live views are unchanged. |
| Review and import were disconnected | Checked rows survive page changes and document switching (80-row bound), target is authorised, metadata-only upload requires confirmation, existing validation/eligibility reports conflicts. No commit is implied. |
| Duplicate Analyse / Synchronise alias controls confused local detection with sync | Removed the duplicate ribbon action. Detect structure remains local; explicit chapter AI is separately labelled. |
| Ribbon Cancel could be active without work; save could leave an old preview loading | Cancel enabled only for active work; client cancellation invalidates request ID immediately, agent generation suppresses delayed completion. Save never waits or cancels Word's save. |
| Status text could be too wide; large selections lost across pages | Ribbon status split across two labels; modeless wrapping action layout, long book dropdown, hierarchical 40-row pages, full inspector, bounded selection shared across tabs. DPI/layout still requires Word qualification. |
Connection semantics
Word loadedis local host state; connected means successful local IPC, never server or AI health./api/native-companion/connectionis bearer-authenticated and verifies current entitlement/configuration. It does not submit a paid AI probe.- Server/auth verification is considered current for 90 seconds. Status reads may initiate at most one health check per two minutes; an explicit Check connection initiates a check immediately. The deliberate intervening
unverifiedstate avoids a stale success claim without frequent network polling. - Cached grants/books remain distinguishable from live verification. Known four-hour expiry and server 401 invalidate authentication scope; book data must be reselected/revalidated after sign-out/restart.
- AI
configured,not-configured,not-entitled,unknown,last-request-succeededandrequest-faileddescribe evidence, not a guarantee of provider availability. Local analysis remains available offline. - Saved-data requests have 15-second timeouts, bounded 1MiB responses, four concurrent workspace fetches, 350ms position coalescing and replacement suppression. Preview has at most four in-flight requests, no automatic retries or commits. Cancelled read-only HTTP may finish within its timeout; its result cannot restore UI state.
- No diagnostics contain prose or credentials. Health explanatory text is available in the protocol; native status displays the distinct states and operation-specific result/error text.
Document lifecycle
The existing persistent manuscript GUID and live session remain distinct. Word-derived positional scene/chapter markers are verified against the selected book through GetBookStructureAsync, not trusted as arbitrary database IDs. Book selection remains per open document; account/agent change invalidates it. Observed revision changes reset the saved binding and reauthorise the retained book. Document close/revision clearing releases agent workspace state. Existing limited same-length-edit detection remains: review results describe a captured snapshot, so re-detect after editing.
Import: what works and what does not
NativeImportPreview.Build checks bounded current identity/selection, nonblank bounded titles, positive/nonoverlapping ranges, unique boundaries, parent chapters and at least one selected scene per selected chapter. It orders by Word positions, never invents placeholder scenes, and invokes the same WordCompanionService.ValidImportStructure validator used by the existing importer. The controller checks authenticated ownership and Import entitlement before the existing AnalyseManuscriptAsync eligibility operation. Linked manuscript counts, existing planned chapters/scenes and refusal reasons are returned. Metadata contains titles/positions and identity only; prose is not uploaded, and word counts are explicitly unknown/zero.
The old WordCompanionService.ImportManuscriptAsync and SQL import (migration 219) also own document binding/structure and planned-content decisions; its existing linked/planned checks precede its transaction. Canonical onboarding additionally owns prose sources, chapter AI review, resumable marker build and save acknowledgement. Calling that write path directly from the native preview would not provide safe idempotent prose/binding/recovery semantics. No unsafe direct database path, automatic replacement or new partial-import retry mechanism was added.
The UI always reports Created: 0 / Replaced: 0, CommitAvailable=false. Continue in PlotDirector opens the authorised book in the existing application. Selections are not transferred. Existing web importing remains the committing workflow, with its existing author confirmation. Repeated native previews are read-only and cannot create duplicates; they do not claim to solve transaction/idempotency guarantees for a future native commit. Full commit is a separate remaining capability, not a hidden success state.
Context and Intent
Native tabs distinguish saved information from local structural/AI suggestions. Context uses saved scene summary, then chapter/book summary where applicable. Intent uses saved scene-purpose notes and chapter goal/emotional-goal/reader-takeaway/must-include fields. Neither generates AI information nor saves changes. Book-level absence is useful explicit guidance, not a fabricated writing objective.
Full browser views reuse existing rendering and access validation. Native links pin project/book/verified chapter/scene and opt out of legacy latest-connection follow. Multiple independently opened pinned views keep their scopes. This is saved snapshot integration, not native live multi-screen SignalR following. Existing Office.js live Context/Intent multi-screen behaviour is preserved for its ordinary views. A future native live protocol still requires session-aware routing and explicit follow policy.
Main evidence references
Protocol/WorkflowContracts.cs,Protocol/Messages.cs: optional capability and bounded value contracts.Agent/CloudGateway.cs: auth expiry, HTTP verification, status, scoped browser opening;DocumentWorkspaceWork.cs: per-session saved scope, coalescing and preview suppression;SessionManager.cs: current snapshot/identity checks and lifecycle.Client/DocumentBinding.cs,ConnectionPresentation.cs: shared presentation and stale-response guards.Vsto/WordAdapter.cs: UI-thread value exchange, exact-document commands, save/cancel safety;AnalysisWindow.cs,NativeRibbon.cs,Ribbon.xml: native experience.PlotLine/Controllers/NativeCompanionWorkflowController.cs: authenticated connection/workspace/preview;Services/NativeCompanion/NativeImportPreview.cs; existingServices/WordCompanionService.csshared validation/eligibility.WritingController.cs, Context/Intent Razor views,wwwroot/js/writing-follow.js: pinned mode with preserved live mode.- Existing investigation:
Docs/Investigations/2026-11-04-word-companion-investigation.md; previous report:2026-11-05-phase3-ai-integration.md.
Verification and remaining qualification
Evidence and exact final checks/deployment outcome are recorded alongside this report under Evidence/2026-11-05-phase35/. Automated checks exercise real controller/HTTP routes with synthetic authenticated principals/provider and fail-on-write repositories, agent lifecycle/state, browser response races, package tamper refusal and VSTO source syntax. They do not claim a live author's database import, provider availability or real Office execution.
There are no new database migrations or configuration secrets/settings. The server needs the existing desktop pairing/auth infrastructure, subscription entitlement and configured existing AI provider; the Phase 3 migration 230 prerequisite remains. Preparing Windows packages does not alter the working laptop installation.
Windows COM semantics, compilation against installed Office, signed manifests, installation, visual DPI/layout and actual typing/scroll/save responsiveness remain unverified on Atlas. Native import commit, native live SignalR following, full prose sync and a complete edit journal remain out of scope. Windows steps and tonight's checklist use the existing Update/Install scripts and version 1.0.0.6.
Recorded final results
| Check | Result |
|---|---|
dotnet build PlotLine.slnx |
PASS, 0 warnings / 0 errors |
| Full executable application regression harness | 408 PASS checks |
| Native managed assertions | 183 PASS, including stationary-cursor snapshot-to-saved-scene refresh |
--native-workflow |
PASS saved Context/Intent, ownership/marker membership, importer eligibility, duplicate/overlap/orphan/negative scene range refusal, entitlement and no-write assertions |
--native-companion-http |
PASS actual HTTP pairing/antiforgery/bearer/stamp, book/subscription security, canonical AI/idempotency, connection/workspace/preview (synthetic provider, no database) |
| Word Companion Playwright regressions | PASS delayed responses, abort, stale errors, chapter-only identity, both pinned modes and Writer launcher |
| PowerShell | All seven scripts parse; portable package/hash tamper and non-Windows fail-closed tests PASS |
| Native host | Roslyn syntax only PASS; no Office compile/runtime/installation/performance claim |
| Release server publish | PASS |
Development was updated to server source 0075bb5; subsequent native-only lifecycle/UI changes do not change that server payload. Release: /srv/apps/plotdirector-dev/releases/native-word-phase35-0075bb5-20261105142037, with a matching timestamped current-before application backup. Pre-restart Development jobs/import gate was idle; migration 230 ownership procedure presence/hash verified read-only. Published and deployed application/protocol SHA-256 hashes match (see evidence). Service active; local GET and public TLS-validated GET returned 200. The new connection/workspace/preview endpoints returned 401 without bearer. No recent service warning/error entries were observed. Live author authentication, saved records and UI interaction still require Windows qualification; no additional paid AI call was needed to test this integration change.
The existing update script now runs the new workflow regression gate, and version props/assembly metadata agree on 1.0.0.6. Connect uses a resizable DPI-aware layout and rejects malformed site roots before sending a request. Preparation/installation scripts are source-ready for Windows qualification, not Windows-executed here. No database migration, configuration change, Production deployment or laptop installation was performed.