11 KiB
Native Word Companion Phase 2: local document analysis
4 November 2026. Shared branch: codex/word-companion-native-phase1-20261104.
Baseline and scope
Started from a clean branch at 726a3d5, matching the fetched remote tip, with Windows fixes 2f0f5a4, f0d1f6b, a0c2d25 and 726a3d5 present. The author identifies this as the successful Windows smoke-tested build 1.0.0.3. The older Windows qualification report predates that smoke test; its pending-load wording is historical. The deployment/package version is not recorded in source (assembly version remains 0.1.0.0); this work does not claim to have reproduced that package or assign a new published version.
The Phase 1 report and component/protocol documentation supplied the baseline and remaining-work plan. There was no separate native Phase 2 implementation plan in the companion documentation. Existing extraction, session management, named pipes, lifecycle/scheduling, native ribbon and marker-based resolution were reused. The registration queue-loop and blank-document fixes are preserved. No new branch, transport, server endpoint, database operation or application deployment was introduced.
This phase implements an end-to-end Word → local agent → Word review workflow. It does not connect native documents to the authenticated PlotDirector website. Existing server chapter/scene analysis (ManuscriptStructureAnalysisService.AnalyseChapterAsync) depends on approved onboarding context, paragraph maps, configured prompts and the Story Intelligence client. It is not a standalone local parser and cannot safely be called without native authentication and binding. Those business services, import approval and scene identity ownership remain on the server. The smallest local extension provides structural evidence and suggestions, not an alternative onboarding or AI pipeline.
Author workflow
- Open a document and wait for the existing agent connection/session registration.
- Choose Analyse Document on the native PlotDirector ribbon.
- A small modeless review window shows extraction/analysis progress. Typing and Word operations retain priority; work waits for quiet periods.
- Review approximate word count, paragraph count and potential chapter/scene boundaries. Rows show paragraph ordinal, title/separator, evidence and confidence. Results are paged, 40 rows at a time.
- Use Cancel in the window or Cancel Analysis on the ribbon. Use Analyse again to acquire a fresh snapshot. Reopening review for the same valid analysis reuses its results instead of reading the manuscript again.
The window follows the active document session. Switching documents retains separate results/work; it never presents another document's results as the current manuscript. A request still waiting to start is stopped if its target has switched or is closing. A started extraction can continue for its exact document in bounded scheduled steps. Closing retires that session; cancelled close requires a new analysis. Save handlers do not delay saving: they stop analysis, invalidate its review and let Word proceed. Disconnect invalidates review/paging; after reconnect the author can analyse again. Closing the review window alone does not cancel work; the ribbon cancellation remains available.
No import, binding change, marker insertion, manuscript overwrite, automatic save, prose upload or AI request is performed by analysis. The separate existing Settings action still offers explicit native identity persistence.
Implementation
sequenceDiagram
actor Author
participant UI as Native ribbon / modeless review
participant STA as Existing Word STA scheduler
participant Pipe as Existing AgentLink / pipe v1
participant Agent as .NET 10 session manager + analysis
Author->>UI: Analyse Document
UI->>STA: Schedule exact active document
STA->>Pipe: Descriptor, snapshot-begin(RequestAnalysis)
loop Bounded extraction with UI yields
STA->>STA: Existing <=2048-character range reads
STA->>Pipe: Ordered paragraph fragment
Pipe->>Agent: Values only; no COM objects
Agent->>Agent: Incremental counts / boundary evidence
Agent-->>Pipe: Progress acknowledgement
Pipe-->>UI: Bounded/coalesced progress, UI timer consumption
end
STA->>Pipe: snapshot-end
Pipe->>Agent: Validate session/revision/completeness
Agent-->>UI: First bounded results page
Author->>UI: Next / previous results
UI->>Agent: analysis-page(exact session/revision/snapshot)
Agent-->>UI: Requested page
opt Cancel, close, observed edit or disconnect
UI->>STA: Cancel/supersede extraction
STA->>Agent: Existing snapshot-cancel or session retirement
UI->>UI: Reject late results
end
- DocumentAnalysis processes each existing fragment on the agent, retaining only a bounded paragraph prefix and candidate rows in addition to Phase 1's temporary snapshot storage. It counts across fragment splits, uses existing
StructuralParser.MarkerIdsemantics, outline levels, common English chapter/part/book labels, standalone numerals and visible separators. Candidate titles are capped at 200 characters. Markers/headings are evidence; text-only labels and separators are explicitly possible/uncertain suggestions. - Existing trusted positional chapter/scene resolution remains separate. Guessed boundaries are never promoted to authorized server scene IDs or used for Context/Intent routing.
- SessionManager binds analysis to the current instance lease, document session, revision and snapshot. Invalid/incomplete/cancelled work cannot commit. Review requests have exact snapshot identity and bounded offsets. Snapshot fragments may not advance beyond the declared document end.
- AnalysisReview holds per-document value-only review state and rejects another document, old revision, old snapshot, stale page and late post-cancellation results. Ordinary selection replies cannot regress a completed review.
- WordAdapter reuses the tested Word access path. All COM stays on the original STA. Preparation, extraction and author cancellation are scheduled without blocking IPC. Review progress is bounded to 32 session slots, drained at most four per UI tick and rendered at most every 250 ms. It does not queue a UI callback per paragraph. Existing cooperative four-fragment/~20 ms extraction batches and COM timing remain in place.
- AnalysisWindow is a small modeless Windows Forms review, with no COM references, embedded website, network calls or import controls.
Compatibility, bounds and privacy
Protocol version remains 1. The optional structure-review-v1 capability is advertised by new agents/clients; original required capabilities and endpoint remain unchanged. New VSTO enables analysis only after the agent advertises it. Old clients still request ordinary snapshots, and new agents keep their normal response behavior. Unknown optional DTO members are additive. Native components should nevertheless be rebuilt together for Windows qualification; an already-running old agent needs to be stopped/restarted to expose the new capability.
RequestAnalysis on snapshot-begin enables incremental analysis. Fragment responses carry Progress; successful snapshot-end returns analysis-complete and the first AnalysisPage. analysis-page uses Start as a zero-based result offset. Results contain counts, total, offset, truncation notice and at most 40 StructureSuggestion values. No prose body is returned. Additional contracts retain the existing 256 KiB frame bound, correlation IDs, timeouts, backpressure and reconnect behavior. No breaking Office.js or browser SignalR change was made.
Candidate storage is capped at 8,192 per document, with explicit truncation, and 32,768 retained candidates globally. Existing snapshot/global storage and fragment bounds remain. Disconnect/close/reconcile/revision replacement release the agent state. Temporary snapshot prose is released after commit; analysis retains only counts and bounded heading/separator excerpts. It is not persisted to disk or written to diagnostic logs. Existing metadata-only offline work queues remain disconnected from a prose sender.
Verification and limits
Linux solution build passed with zero warnings/errors. Native harness passed 146 assertions, including existing capacity-slot checks, not 146 independent end-to-end scenarios. Coverage includes blank documents, chapter labels, marker reuse, ambiguity explanations, split words/paragraphs, synthetic 250,000-word analysis, truncation, framed/paged results, three document sessions, cancellation before/during extraction, stale results/pages, actual named-pipe analysis replies and repeat analysis after actual pipe-host shutdown/restart. Application regression harness passed 406 checks; focused Chromium Context/Intent and Writer launcher regressions passed. All commands exited 0. Retained output and exact commands are in the Phase 2 evidence directory.
VSTO C# syntax and XML were checked, but the VSTO host was not built or executed on Linux. Linux named pipes use Unix-domain sockets. No new Windows COM, modeless-window interaction, Office compatibility, cross-user security or Word responsiveness claim is made. Windows test instructions are here.
Limitations:
- Local deterministic suggestions only. No semantic scene detection, AI, authenticated server integration, import preview/commit or Context/Intent synchronization. Unmarked scenes can be missed; non-English chapter labels need markers/outline levels. Formatting and chapter/scene meaning need author review.
- Word count is approximate whitespace-based local counting, not Word's own statistics. Main document ranges are analyzed; other Word stories such as headers, footnotes and text boxes are not integrated.
- Phase 1 change detection remains positional/first-saved-to-dirty based. Same-length edits while already dirty are not fully detected. Results represent an observed snapshot, not a full edit journal; use Analyse again after edits. Concurrent edits that are not observed can require a repeat analysis. No manuscript import uses these results automatically.
- Single COM calls cannot be preempted. Batching is a cooperative target, not a guaranteed latency bound. Validate with real 190k/250k manuscripts, many short paragraphs and continuous interaction on Windows before acceptance.
- Signing, installation/update distribution, native authentication, server-authorized persistent binding and session-aware SignalR remain subsequent reviewed work. No installed Windows component was modified from Atlas.
Stop after review and Windows qualification. No Production deployment was performed.