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.