# Local protocol v1 Shared `.NET Standard 2.0` value contracts; no Office references, RCWs, arbitrary object graphs or BinaryFormatter. Transport is asynchronous local Windows named pipes with current-user server ACL and independent server-process SID verification in the add-in. Portable tests use private pipe names; Linux's underlying Unix-domain sockets do not prove Windows security. Each frame: four-byte unsigned little-endian payload length, then DataContract JSON. Length must be 1–262,144 bytes before payload allocation. ReadExactly handles partial reads. All requests/responses have protocol version and nonempty CorrelationId; client accepts only the matching response. One exchange per connection is in flight. Three-second handshake/exchange deadline closes hung I/O on a worker; one-second idle ping detects a vanished idle agent. No Word callback performs transport I/O or waits for it. Handshake offers Version=1 and capabilities `sessions-v1,positional-selection-v1,batched-snapshot-v1`. Both sides require these capabilities, accept additional optional capabilities and reject incompatible versions. Future required features need a negotiated version/capability, not inferred compatibility. Native protocol negotiation does not change existing browser/Office.js SignalR signatures. | Kind | Identity and effect | |---|---| | hello | WordInstanceId; server binds it to this connection's generated lease and replies ready. Current-user access is not server authentication. | | reconcile | Complete current list of at most 32 DocumentDescriptors for this Word instance. Replaces this instance's state after reconnect. Descriptor contains separate SessionId / ManuscriptId, nullable project/book, observation Revision, IdentityPersisted and untrusted AssociationVerified. No raw document path/name. | | document | Add/update descriptor. Older revision or changed persistent identity within the same session is refused. Increasing revision invalidates pending/completed structural state. | | close | Retire this exact instance/session and pending snapshots; never another Word process. Cancelled Word close must not emit this message. | | active | Current session for this Word instance. Latest per-client active slot coalesces bursts. Future browser active-manuscript policy is separate and is not inferred from latest-connected Word presence. | | selection | Range.Start/End, session and exact observation Revision. Agent resolves from completed structural boundaries; repeated prose is not used for positional matching. Latest selection per session is coalesced. | | snapshot-begin | Nonempty SnapshotId, observation Revision, expected final document End. Replaces unfinished snapshot for this session. | | snapshot-fragment | Same snapshot/revision; ordered contiguous Word positions; paragraph ordinal, OutlineLevel, at most 2,048 text characters, bounded raw control/bookmark tags, completes-paragraph flag. | | snapshot-end | Commits only if snapshot/revision still current, positions reach declared end and the final paragraph fragment is complete. Agent parses structure, retains bounded boundaries and a fingerprint, and releases assembling prose. | | snapshot-cancel | Drops only matching pending snapshot; an older cancellation cannot cancel a replacement snapshot. | | metrics | Bounded COM-call/batch/UI tick timing measurements and queue depth; no prose. | | ping | Worker keepalive; no Word access. | Non-hello requests are assigned increasing Sequence at actual send time (not producer time, because queues coalesce/reorder selection vs lifecycle work). Repeated/older sequence, wrong connection lease, foreign session, stale revision and obsolete snapshot are refused. Errors return explicit statuses; native extraction stops on refusal rather than pretending partial completion. Responses identify instance/session/revision/snapshot and may contain resolved chapter/scene IDs/titles. Native display accepts results only for the currently active matching session/revision. Resource bounds: eight Word connections, 32 documents per instance, 64 FIFO frames + 32 latest-selection slots + one active slot per client, 64 UI scheduler actions. Assembling snapshots share a global 200k-fragment limit and 64 Mi storage-budget units, with 16 Mi per document; units include text/marker characters and a fixed metadata allowance. Completed structures have at most 8,192 boundaries/document and 32,768 globally; titles are limited to 200 characters. These are defensive limits, not measured Word capacity promises. Disconnect detaches only the connection's current instance lease. Old disconnect callbacks cannot retire a replacement lease. Client reconnect discards stale transport backlog, reconciles still-open documents and requests fresh extraction on the UI scheduler. A pending snapshot frame under backpressure is retained as a value; Word is not reread or blocked. Lifecycle backpressure forces reconciliation rather than silently forgetting a closed/open document. Protocol v1 exposes **no remote Word mutation operation** and no server integration. Native marker helper code is UI-only and not callable through IPC. Any future command requires explicit target instance/session, document binding, expected revision, bounded ranges, authorization and acknowledgement states. Existing Office.js markers/settings and server business rules remain authoritative for the legacy path until a reviewed migration exists. ## Optional Phase 2 structural review `structure-review-v1` is additive to v1's required capabilities. New agents advertise it in `ready`; a new add-in must check it before setting `RequestAnalysis` on `snapshot-begin`. Old clients send ordinary snapshots and keep original behavior. The existing endpoint/version is retained; deploy native add-in/client/protocol and agent developer outputs together for qualification. Analysis uses the same bounded paragraph stream. `snapshot-fragment` acknowledgements include progress percentage. A successful requested `snapshot-end` replies `analysis-complete`, `Progress=100` and the first `AnalysisPage`. `analysis-page` requires exact session/revision/snapshot and uses `Start` as zero-based row offset; it returns at most 40 rows. Candidate rows are suggestions (kind, Word position, paragraph ordinal, bounded title, confidence, evidence), never authorization to import or navigate a server scene. Summary includes approximate words, paragraphs, candidate totals and truncation notice. See Phase 2 report for heuristics and limits. Analysis is incremental in the agent; no COM object crosses IPC and no analysis operation mutates Word. Candidate counts are bounded to 8,192/document and 32,768 globally. Cancellation uses existing `snapshot-cancel`; late replies are refused by the review's session/revision/snapshot guard. Disconnect invalidates the cache: reanalyse after reconnect. Native Context/Intent/server authentication is still deferred. ## Optional Phase 3 chapter AI `chapter-ai-v2` advertises the additive native feature. `cloud-connect` sends only an author-selected HTTPS root; `cloud-status` returns sign-in status and at most 200 authorized book choices; `cloud-signout` discards the agent's memory-only grant and cancels native AI jobs. Credentials never enter IPC. The agent performs verifier-bound browser pairing over HTTPS; the browser uses normal PlotDirector cookie login and antiforgery approval. After explicit author upload confirmation, `ai-begin` specifies one chapter's Start/End, book and request SnapshotId under the exact existing document session/revision. `ai-fragment` reuses the bounded paragraph DTO and chapter-local paragraph ordinals. `ai-submit` starts asynchronous agent HTTP processing and returns promptly; duplicate submits do not create another call. `ai-status` polls that request and pages results using Start as zero-based result offset (40 rows). `ai-cancel` cancels the exact job and best-effort server request. Lifecycle/revision retirement also cancels the job. The live session ID must be unique across Word instances; a foreign duplicate is refused. Chapter capture is limited to 120,000 positions/text characters and 10,000 paragraphs. The server returns at most 500 validated AI scenes per chapter; the agent frames only 40 at a time. Suggested boundaries retain actual Word positions, provenance `AI`, confidence and bounded reasoning. Local/marker suggestions remain separate; their chapter ranges provide the upload bounds. No API or IPC operation imports scenes, rewrites text or inserts markers. Network uncertainty is not auto-replayed; explicit author retry is required and may incur a charge. Server deduplication is bounded to its process lifetime and a 30-minute cache. The `chapter-ai-v2` capability pins author consent to a nonsecret AuthenticationContext nonce in addition to document session, local snapshot and book. The agent rotates the context on connect/sign-out/expiry and cancels jobs on account/site change. `ai-begin` and submission refuse old context before HTTP upload; Word invalidates queued consent and book selection across instances. This nonce is not a bearer credential. HTTP chapter DTOs remain unchanged.