Skip to content

Commit 1880e69

Browse files
authored
feat(coven): submit, watch and cancel familiar missions (#351)
* feat(coven): submit, watch and cancel familiar missions Add CovenMissionsClient for the mission contract (OpenCoven/coven#1313), following the approved design (#349). Submit and cancel send one spec command envelope each over the existing Automations transports, which now rebuild mission requests before sending. A lost submit answer is resent under the same adoption key; a still-unknown outcome throws CovenMissionUncertain with the derived mission id. Views are checked for internal consistency, and watch refuses views for another principal or familiar. Client vectors M-01, M-02, M-11 and M-14 are covered. Coven-Harness: claude-code / claude-opus-5-5 * test(coven): pin the mission contract fixtures Copy the mission schema, common schema and declarations from the coven spec PR, with provenance, and check the public mission types against the producer's declarations in both directions. Coven-Harness: claude-code / claude-opus-5-5 * test(coven): pin the mission fixtures to the merged contract OpenCoven/coven#1330 merged as b2ad03b2 with the same bytes as its reviewed head, so only the pinned commit changes. Coven-Harness: claude-code / claude-opus-5-5 * fix(coven): poll the mission view and carry refusal details The producer settled that mission events carry no projected state (OpenCoven/coven#1347), so watch now reads the view every interval instead of waiting on the occurrence stream, which could miss a change that emits no event. A restarted client resumes with afterRevision. CovenMissionError now exposes the settled view a refused cancel carries (M-09) and the familiar's current revision on REVISION_CONFLICT (M-04), both checked before they are shown. Coven-Harness: claude-code / claude-opus-5-5
1 parent ef8e32d commit 1880e69

20 files changed

Lines changed: 3873 additions & 18 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@opencoven/coven-client": minor
3+
---
4+
5+
Add `CovenMissionsClient` for the Coven mission contract (OpenCoven/coven#1313):
6+
`submit`, `get`, `cancel` and `watch` one owner-local familiar mission, over the
7+
same Unix and Windows transports as `CovenAutomationsClient`. Submit and cancel
8+
send one spec command envelope each, and only when the producer advertises the
9+
`coven.automations.mission.*.v1` action. A submit whose answer is lost is resent
10+
with the same adoption key up to three times within the deadline; if the outcome
11+
is still unknown it throws `CovenMissionUncertain` with the key and the mission
12+
id derived from it. Daemon refusals throw `CovenMissionError` with the typed
13+
code. `watch` ends at the first terminal view and refuses views for another
14+
principal or familiar with `CovenMissionContextMismatch`. The transports'
15+
`sendCommand` and `readDefinitions` hooks now also accept mission requests.

‎api-baselines/coven.d.ts‎

Lines changed: 269 additions & 5 deletions
Large diffs are not rendered by default.

‎api-baselines/coven.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
2424
"CovenClientError",
2525
"CovenDaemonResponseError",
2626
"CovenIpcError",
27+
"CovenMissionContextMismatch",
28+
"CovenMissionError",
29+
"CovenMissionUncertain",
30+
"CovenMissionsClient",
2731
"CovenSessionPolicyClient",
2832
"CovenSessionPolicyError",
2933
"computeDefinitionDigest",
3034
"createCovenAutomationsClient",
3135
"createCovenAutomationsUnixTransport",
3236
"createCovenAutomationsWindowsTransport",
3337
"createCovenClient",
38+
"createCovenMissionsClient",
3439
"createCovenSessionPolicyClient",
3540
"createCovenSessionPolicyUnixTransport",
3641
"createCovenUnixTransport",

‎docs/superpowers/specs/2026-10-18-coven-missions-client-design.md‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Coven missions client design
22

3-
Status: **design approved with the producer contract on 2026-10-18 (Val); not implemented**.
3+
Status: **design approved with the producer contract on 2026-10-18 (Val); implemented in
4+
`packages/coven/src/missions*.ts`**. See *As built* for where the code differs.
45

56
The SDK binding for the mission contract drafted in OpenCoven/coven#1314
67
(issue OpenCoven/coven#1313, design doc
@@ -128,9 +129,31 @@ None now. The client ships in a later minor of `@opencoven/coven`, after the
128129
producer contract is approved and released. The packages are still unpublished
129130
(#41).
130131

131-
## Open questions
132-
133-
1. Should `watch` also poll with `get` on an interval as a heartbeat, or rely on
134-
the subscription's own liveness?
135-
2. Is three retries within the deadline the right default for an uncertain
136-
submit, or should the caller choose?
132+
## As built
133+
134+
- **The package is `@opencoven/coven-client`**, and the factory is
135+
`createCovenMissionsClient`, beside `createCovenAutomationsClient`.
136+
- **The recorded principal is a client option.** Every command envelope needs
137+
`origin.principal`, so `CovenMissionsClientOptions` takes a `principalId`,
138+
recorded with each command and never an authority grant. Binding it once means
139+
a resend under the same key cannot change it.
140+
- **No new error codes.** The producer kept the frozen v1 vocabulary: a stale
141+
revision is `REVISION_CONFLICT`, an envelope it does not enforce is
142+
`CAPABILITY_UNSUPPORTED`, and a past `validUntil` is `VALIDATION_FAILED`.
143+
- **Refusals carry two details.** `currentRevisionId` on a mission's
144+
`REVISION_CONFLICT`, and the settled view as `mission` on a cancel's
145+
`ILLEGAL_TRANSITION` (M-09). Both are checked like the rest of the answer.
146+
- **The transports carry missions.** `sendCommand` and `readDefinitions` accept
147+
mission requests, and the built-in Unix and Windows transports rebuild each one
148+
from its own data fields before sending, as they do for lifecycle commands.
149+
150+
## Open questions, resolved
151+
152+
1. **`watch` polls the view.** An `events.subscribe.v1` read returns one page and
153+
ends on an empty one, so the subscription has no liveness of its own. The
154+
producer also settled that mission events carry no projected state (coven
155+
PR 2b, OpenCoven/coven#1347): clients read it with `mission.get`. `watch`
156+
reads the view every `pollIntervalMs` (default 1 000 ms), and a restarted
157+
client resumes with `afterRevision`, which covers M-14 without an event
158+
cursor.
159+
2. **Three resends is fixed.** The caller bounds the total with its deadline.

‎packages/coven/README.md‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ and [support policy](https://github.com/OpenCoven/sdk/blob/main/SUPPORT.md).
3434
capability GET and allowlisted read-action POST requests.
3535
Inject `automationsTransport` into `CovenClient` to share its operation defaults,
3636
or keep using the standalone client.
37+
- `createCovenMissionsClient(...)` submits, reads, watches and cancels one
38+
familiar mission over the same Automations transports. See
39+
[Missions](#missions).
3740

3841
## Automations phase 1: capability discovery and diagnostic reads
3942

@@ -665,6 +668,106 @@ const created = await automations.createDraft({
665668

666669
These commands need a producer with the command envelope ([coven#1176](https://github.com/OpenCoven/coven/pull/1176)); `createDraft` and `revise` also need rich-definition support ([coven#1185](https://github.com/OpenCoven/coven/pull/1185)).
667670

671+
### Missions
672+
673+
A mission is one owner-submitted, one-shot run of an exact familiar revision on
674+
one project ([OpenCoven/coven#1313](https://github.com/OpenCoven/coven/issues/1313)).
675+
`CovenMissionsClient` submits, reads, watches and cancels one. It keeps no state
676+
and stores nothing: every state it reports is the daemon's `MissionView`.
677+
678+
```ts
679+
import {
680+
CovenMissionUncertain, createCovenAutomationsUnixTransport, createCovenMissionsClient,
681+
} from '@opencoven/coven-client';
682+
683+
const missions = createCovenMissionsClient({
684+
transport: createCovenAutomationsUnixTransport(endpoint, { security }),
685+
principalId: 'principal:chat',
686+
});
687+
688+
const adoptionKey = crypto.randomUUID(); // store it before you send
689+
try {
690+
const { missionId } = await missions.submit({
691+
familiar: { rootId, revisionId },
692+
envelope: { id: 'r0-read.1', descriptorDigest },
693+
project: { cwd: '/Users/me/project' },
694+
task: { statement: 'Diagnose the failing build', prompt: 'Read the last CI log and report the cause.' },
695+
limits: { timeoutMinutes: 10 },
696+
validUntil: new Date(Date.now() + 10 * 60_000).toISOString(),
697+
}, { adoptionKey });
698+
for await (const view of missions.watch(missionId)) render(view);
699+
} catch (error) {
700+
if (error instanceof CovenMissionUncertain) showChecking(error.missionId);
701+
else throw error;
702+
}
703+
```
704+
705+
**Ids.** The daemon derives a mission's id from the submit's adoption key, so a
706+
caller that stored only the key can re-attach:
707+
`CovenMissionsClient.missionIdFor(adoptionKey)` is `mission-` followed by the
708+
first 32 hex digits of SHA-256 over the key. It is pure.
709+
710+
**Submit.** `submit(input, options?)` binds the familiar revision, the runtime
711+
envelope, the project directory, the task, the timeout and `validUntil`.
712+
Everything is validated before any I/O: the statement is 1 to 200 characters,
713+
the prompt is at most 32 KiB of UTF-8, the timeout is 1 to 60 minutes, and the
714+
directory is absolute. A bad value fails with `invalid_options`. The adoption key
715+
is generated with `crypto.randomUUID()` when you don't pass one, and is returned
716+
on the result. The result is `committed`, or `replayed` when the key had already
717+
committed; a replay never launches again. The answer must carry the id derived
718+
from the key and bind the familiar revision, envelope, statement and expiry that
719+
were sent. Anything else is treated as an unknown outcome.
720+
721+
**A lost answer.** Once a submit is handed to the transport, no failure proves
722+
it was not applied. The client resends the same bytes under the same key, up to
723+
three times within the deadline. If the outcome is still unknown, `submit`
724+
throws `CovenMissionUncertain` (`code: 'outcome_unknown'`), carrying
725+
`adoptionKey` and `missionId`. Show "checking", call `get(missionId)`, and
726+
resubmit with the same key and input only if it answers `NOT_FOUND`. Never show
727+
"nothing happened".
728+
729+
**Refusals.** A daemon refusal throws `CovenMissionError` with the typed `code`
730+
and `statusCode`, and nothing was committed by the request. `CONCURRENCY_LIMIT`
731+
means another mission for this familiar is active in this project.
732+
`ADOPTION_REPLAY_MISMATCH` carries `conflictOutcome`, saying what the key
733+
actually committed. A familiar revision that is no longer current is
734+
`REVISION_CONFLICT`, with the current one in `currentRevisionId`. An envelope
735+
the daemon does not enforce is `CAPABILITY_UNSUPPORTED`. A cancel of a mission
736+
that has already settled is `ILLEGAL_TRANSITION`, with its terminal view in
737+
`mission`. Daemon messages are not copied.
738+
739+
**Get.** `get(missionId)` returns the current view. A mission that does not
740+
exist, or that belongs to another principal, is `CovenMissionError` with
741+
`NOT_FOUND`, never an empty view. The view is checked for internal consistency:
742+
a terminal view carries its result, a refused or failed one carries its reason,
743+
and the prompt is never echoed.
744+
745+
**Watch.** `watch(missionId, options?)` yields a view each time its `revision`
746+
increases, and ends after the first terminal view. The view is the daemon's
747+
authority, so `watch` reads it every `pollIntervalMs` (100 to 60 000 ms,
748+
default 1 000) rather than inferring change from events. A client that
749+
restarts resumes by passing the last `revision` it showed as `afterRevision`.
750+
`timeoutMs` bounds each read, not the watch; end it with `signal` or `return()`.
751+
With `expect: { principalId, familiar }`, a view for another principal or
752+
familiar is not yielded and the iterator throws `CovenMissionContextMismatch`.
753+
754+
**Cancel.** `cancel(missionId, { reason? }, options?)` carries its own adoption
755+
key; replaying it returns the same cancellation. The receipt's `outcome` is
756+
`cancelled`, `pending`, `lost_to_completion` or `recovery_required`. The client
757+
never infers it: `lost_to_completion` means the mission completed.
758+
759+
**Authority.** `principalId` is recorded with each command; it is not an
760+
authority grant. The daemon takes the mission's principal from the owner-only
761+
socket or pipe, which is the only place the built-in transports connect, and
762+
refuses mission commands over TCP. Commands are sent only when the daemon
763+
advertises `coven.automations.command.v1` and the command's own
764+
`coven.automations.mission.*.v1` action; otherwise they fail with
765+
`capability_unsupported` and nothing is sent.
766+
767+
Missions need a Coven daemon that implements the mission commands. Until
768+
Runtime Authority exists (OpenCoven/coven#857), a submitted mission settles
769+
`unavailable` with reason `authority_unavailable` and launches nothing.
770+
668771
### Occurrence history
669772

670773
```ts

0 commit comments

Comments
 (0)