@drisp/protocol 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nadeem Mohammed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # @drisp/protocol
2
+
3
+ The wire contract between a drisp **runner** (the CLI's `drisp runner` process) and the
4
+ **hub** (the dashboard): zod schemas and inferred types for every
5
+ instance-socket frame, the Workflow **Run**, the **Turn**, the **Interruption**
6
+ a Run parks on, and the event stream — plus a JSON Schema export of the same.
7
+
8
+ Vocabulary follows the repo's domain docs (`UBIQUITOUS_LANGUAGE.md`,
9
+ `CONTEXT.md`, ADR 0014–0016); this package does not define a second one.
10
+
11
+ ```ts
12
+ import {
13
+ PROTOCOL_VERSION,
14
+ hello,
15
+ normalizeFrame,
16
+ toLegacyFrame,
17
+ FrameSchema,
18
+ } from '@drisp/protocol';
19
+
20
+ // First frame either side sends.
21
+ socket.send(JSON.stringify(hello({role: 'runner', instanceId})));
22
+
23
+ // Any inbound frame, under either name set, becomes one canonical value.
24
+ const frame = normalizeFrame(JSON.parse(raw));
25
+ if (frame.type === 'run.start') admit(frame.runId, frame.runSpec);
26
+
27
+ // A runner that still speaks the old names on the wire.
28
+ socket.send(JSON.stringify(toLegacyFrame(frame)));
29
+ ```
30
+
31
+ ## Frame names: old → new
32
+
33
+ Both name sets parse. `normalizeFrame()` returns the canonical (new-name) form;
34
+ `toLegacyFrame()` is its inverse for frames that have an old name. Each old name
35
+ maps to exactly one new name (`FRAME_NAME_MAP`).
36
+
37
+ | Old name (CLI emits/consumes today) | New name | Direction | Notes |
38
+ | ----------------------------------- | -------------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------- |
39
+ | `job_assignment` | `run.start` | hub → runner | `{runId, runSpec?, runnerId?}` |
40
+ | `dashboard_decision` | `answer` | hub → runner | `{athenaSessionId, requestId, decision}` |
41
+ | `cancel` | `stop` | hub → runner | `{runId, runnerId?}` |
42
+ | `run_event` | `event` + `stream: 'run'` | runner → hub | compatibility per-Run stream (`seq`, `kind`, `payload`) |
43
+ | `feed_event` | `event` + `stream: 'feed'` | runner → hub | canonical FeedEvent channel (`deliverySeq`, `envelope`) |
44
+ | `ping` | `ping` | runner → hub | unchanged |
45
+ | `pong` | `pong` | hub → runner | unchanged |
46
+ | `assignment_accepted` | `assignment_accepted` | runner → hub | unchanged |
47
+ | `assignment_rejected` | `assignment_rejected` | runner → hub | unchanged |
48
+ | `decision_ack` | `decision_ack` | runner → hub | unchanged |
49
+ | `feed_ack` | `feed_ack` | hub → runner | unchanged |
50
+ | `attachments.changed` | `attachments.changed` | hub → runner | unchanged |
51
+ | `error` | `error` | either | unchanged |
52
+ | — | `hello` | either | **new** — carries `protocolVersion` (`PROTOCOL_VERSION`); a runner's also carries `workflows` (its installed Workflows) |
53
+ | — | `steer` | hub → runner | **new** — a human turn text for a Run |
54
+ | — | `needs_human` | runner → hub | **new** — a Run parking in `awaiting_attention` with an Interruption |
55
+ | — | `workflows.changed` | runner → hub | **new** — full-list replace of the runner's installed Workflows (`InstalledWorkflow[]`) |
56
+
57
+ The `event` frame folds two old names into one, told apart by `stream`. Every
58
+ other mapping is a pure rename of `type`; bodies are shared.
59
+
60
+ ## Events on the feed stream
61
+
62
+ The feed stream carries FeedEvents opaquely (`FeedEventSchema` keeps unknown
63
+ `kind`s and `data`), and names the ones the hub is expected to render:
64
+
65
+ | `kind` | `data` | When |
66
+ | ------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
67
+ | `phase` | `PhaseEvent` | The Workflow Run moved to a new workflow step, as the Journal's Turn Protocol block names it — one per _change_ of step, not per Turn. `runId` is the Workflow Run; `turn` the Turn that named it; `stepIndex` / `stepTotal` only when the block gave them. `PhaseFeedEventSchema` narrows a FeedEvent to this shape. |
68
+
69
+ The runner (the CLI's `drisp runner` process) is wired to this package: it parses
70
+ every inbound frame with `safeNormalizeFrame()`, sends a versioned `hello`
71
+ first, and builds every outbound frame under its canonical name. Which name set
72
+ actually reaches the wire is decided per connection by the hub's `hello` — see
73
+ `docs/protocol/runtime-dashboard-protocol.md` §17 for the rule.
74
+
75
+ ## Versioning
76
+
77
+ `PROTOCOL_VERSION` is the version this package speaks and is carried on every
78
+ `hello`. It bumps only on an incompatible frame change; adding an optional
79
+ field or a new frame name does not bump it.
80
+
81
+ ## JSON Schema
82
+
83
+ `schema/*.json` (draft 2020-12) is generated from the zod schemas:
84
+
85
+ ```sh
86
+ npm run schema:generate # from the repo root
87
+ ```
88
+
89
+ `src/jsonSchema.test.ts` fails when the checked-in files differ from a fresh
90
+ generation, so they cannot drift.
91
+
92
+ | File | Zod export |
93
+ | -------------------------------- | ------------------------- |
94
+ | `schema/frame.json` | `FrameSchema` |
95
+ | `schema/canonical-frame.json` | `CanonicalFrameSchema` |
96
+ | `schema/legacy-frame.json` | `LegacyFrameSchema` |
97
+ | `schema/hello.json` | `HelloFrameSchema` |
98
+ | `schema/run.json` | `RunSchema` |
99
+ | `schema/turn.json` | `TurnSchema` |
100
+ | `schema/interruption.json` | `InterruptionSchema` |
101
+ | `schema/installed-workflow.json` | `InstalledWorkflowSchema` |
102
+ | `schema/run-spec.json` | `RunSpecSchema` |
103
+ | `schema/runtime-decision.json` | `RuntimeDecisionSchema` |
104
+ | `schema/run-stream-event.json` | `RunStreamEventSchema` |
105
+ | `schema/feed-event.json` | `FeedEventSchema` |
106
+ | `schema/feed-envelope.json` | `FeedEnvelopeSchema` |
107
+ | `schema/phase-event.json` | `PhaseEventSchema` |
108
+ | `schema/phase-feed-event.json` | `PhaseFeedEventSchema` |
109
+
110
+ ## Layout
111
+
112
+ ```
113
+ src/version.ts PROTOCOL_VERSION
114
+ src/domain.ts Run, Turn, Interruption, RunSpec, RuntimeDecision, Attachment, InstalledWorkflow
115
+ src/events.ts RunStreamEvent, FeedEvent, FeedEnvelope, PhaseEvent, PhaseFeedEvent
116
+ src/frames.ts every frame under its old and new name; hello()
117
+ src/normalize.ts FRAME_NAME_MAP, normalizeFrame(), toLegacyFrame()
118
+ src/jsonSchema.ts buildJsonSchemas()
119
+ scripts/ schema generator
120
+ schema/ generated JSON Schema (checked in)
121
+ ```
122
+
123
+ Released independently of `@drisp/cli` via release-please (component
124
+ `protocol`, tag `protocol-vX.Y.Z`). The CLI inlines this package into its
125
+ bundle, so a published CLI has no registry dependency on it.