PlotDirector/Docs/Writer/AudioReview-WindowsContract.md

9.2 KiB
Raw Blame History

Audio Review v1: Atlas / Windows handoff

Status: PlotDirector server/UI and optional shared DTOs only. No Windows GSMTC control, Word text-change detection, ElevenReader integration or native installer is implemented by this sprint. Existing agents remain compatible and media controls remain disabled until valid telemetry advertises operations.

Shared transport and security

Use the existing authenticated HTTPS client, installation grants, normal bearer refresh/revocation and native document presence. Do not introduce a public local web server, unauthenticated named pipe, arbitrary executable/URL operation or second pairing system. Keep protocol v1 required capabilities unchanged. The shared optional DTOs are PlotDirector.NativeCompanion/Protocol/AudioReview.cs; they do not activate any native operation or change local pipe framing.

POST /api/native-companion/instances/{instance}/documents/{document}/audio-review with the existing DesktopPairing bearer token. The instance/document must have a live, matching native presence lease for the same actor, grant and book. Server also checks current project/book ownership. Request size is bounded to 4 KiB. Read/control browser routes use normal cookie authentication and antiforgery. For Reader-only listening, Windows may register a media-only context through the existing native presence endpoint with an opaque nonempty instance/session, the explicitly selected book, wordAvailable: false and wordRunning: false. Existing book authorization and lease expiry still apply; it must not claim a Word manuscript/position. The author then starts/restarts review to bind this context.

The author explicitly starts an Audio Review for a chapter in Writer or Reader. If there is exactly one native session for the book (or exactly one active session), server binds that exact instance/session/grant to the review. A session may represent Word or an explicitly registered media-only review context. An ambiguous or absent document produces an unbound session: elapsed duration can be recorded, but controls and observed playback remain unavailable. End and restart after registering/selecting the native book session; server never silently retargets an existing review.

Discovery and observations

Poll using version: 1, the selected bookID, positive monotonically increasing sequence, reviewID: null, state: "unavailable", and no operations. The reply supplies the active bound reviewID, chapterID and pauseOnEdit, or a null review ID when none matches. Once associated, POST observations with that review ID. A different review ID is refused.

Fields follow ASP.NET's camel-case JSON naming, e.g. reviewID, bookID, mediaKey, positionSeconds, durationSeconds, playbackRate, operations, acknowledgedCommandID, textModified, seeked. Set seeked only for an observed seek event or successfully applied seek command, never merely because telemetry has a gap. Missing positions/duration remain null. State is one of playing, paused, stopped, unavailable, error. Operations are a subset of play, pause, back15, forward15. Times are finite seconds, bounded to a 24-hour media source; rates are 0.25–4. Sequence is scoped to the review, independent of Word revision/presence sequence. Send every 2–5 seconds while reviewing, plus state/seek/text-change observations. Do not replay a disconnected backlog as if it were current playback.

mediaKey is an opaque identifier (at most 100 characters) for the explicitly selected media source. Do not send a browser URL, local path, credentials or media content. Position/duration unavailable is a valid state. The UI expires telemetry after 45 seconds and also requires a live native lease. The agent must report unavailable when discovery fails.

Chrome/GSMTC may expose its most recently active source rather than independent tabs. If that source changes, stop control, report unavailable and require explicit end/restart. Once established, the review's nonempty media key is immutable. Server refuses a different source rather than merging its coverage into the first. Play state is evidence of playback, not proof of attention or alignment to manuscript text.

Commands and acknowledgements

Browser controls request only play, pause, back15, forward15, only when a fresh telemetry capability and matching lease exist. Server creates a command UUID; reply includes commandID, command, relativeSeconds (-15/+15 for seek), the expected mediaKey and expiresUtc (ten seconds). There is one pending command slot per review; newer explicit intent supersedes an older slot.

Before acting, Windows must verify instance/document/review association, current selected media key, capability, expiry and command UUID. Deduplicate UUIDs locally; repeat polling is delivery retry, not permission to repeat a seek. Acknowledge using acknowledgedCommandID and report actual resulting state/position. Never claim success merely because the OS call was queued. Report bounded error text for diagnostics; server displays a generic failure rather than retaining OS/source details. The agent should preserve terminal command receipts long enough to handle acknowledgement loss. An expired command is ignored and acknowledged as an error; it must never run later after reconnection.

These are narrowly scoped commands for the user's selected media source. They do not permit remote shell/OS control, opening URLs, choosing arbitrary browser tabs or manipulating Word content.

Pause on Edit

Consume pauseOnEdit from the bound review. Detect actual Word text modification, not selection, cursor movement, scrolling, browser activity or a document staying open. Perform local Pause immediately when supported, then report textModified: true on the corresponding new observation. The server also requests a bounded Pause if a mutation is reported while still playing and pause capability is available; repeated observations retain the pending Pause UUID. Never automatically Play after an idle/typing timeout. Only an explicit author Play resumes.

The preference is recorded with each review; the latest review preference supplies the next session default. Older agents advertise nothing and do nothing. No current installation should be updated until Windows qualification/packaging is complete.

Accounting and privacy

WriterWorkSessions stores compact session metadata, notes and a union of observed audio intervals. It is not canonical prose storage. Native telemetry sequence is monotonic and locked transactionally; exact/older retries do not add measurements. Gross word additions/deletions continue to come solely from the existing accepted-change ledger.

Only consecutive same-key, same-rate playing samples no more than 30 seconds apart establish playback. Position jumps, gaps, pauses, changed rate/source and duplicate sequence do not manufacture intervals. Playback seconds are bounded by receipt-time elapsed and position advance / rate. Unique coverage is the union of position ranges, so replay can increase playback time without increasing unique seconds. At 4,096 disjoint ranges, coverage remains an explicit partial lower bound rather than growing without limit. End-state tails and missing telemetry are conservatively unmeasured.

Explicit browser sessions measure visible, recently interacted browser engagement separately from elapsed time. They do not measure Word active time. Browser engagement and playback may overlap; UI never sums them into inflated active time. Calendar intervals are attributed to UTC receipt day, including an interval received just after midnight. Native capture/session clocks do not backfill earlier history. Explicit sessions expire after twelve hours; the author starts another session to continue.

Start/end checkpoints reference the accepted book revision and paragraph count. Journey can associate retained accepted changes and changed paragraph identities with the review's time interval and selected chapter, without claiming playback caused the changes. Gross counts shown for such an interval are labelled book-wide, not arbitrarily allocated to chapters. Notes are explicit author-entered text. Normal recording pause, retention and confirmed history erase also cover work/review sessions; account/book deletion cascades new records. Exports/backups remain separate copies.

Required Windows acceptance

  1. Implement optional HTTPS polling/DTO handling using the existing authenticated client; keep required local protocol and old agents compatible.
  2. Implement current-user GSMTC media discovery, capability/state/position reporting and explicit media-key selection. Handle Chrome source changes conservatively.
  3. Implement bounded Play/Pause/relative ±15-second seek, expiry checks and durable UUID deduplication/acknowledgements.
  4. Implement actual Word mutation detection on the established UI/worker boundary. No blocking media/network call on Word callbacks; no pause for scrolling/selection; no auto-resume.
  5. Qualify Word foreground/background, Chrome background, pause/seek/replay, multiple media sources/documents, token refresh/revocation, disconnect/reconnect, agent restart, stale command/ack loss, Windows/PWA and real monitors as appropriate.
  6. Package/version/sign and distribute only after those tests. Atlas qualification does not establish physical Windows acceptance.