@kangentic/protocol 0.14.0 → 0.16.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.
@@ -8,8 +8,17 @@
8
8
  * the desktop's capability router (Phase 2) still has to implement and
9
9
  * wire a handler, and a device's roster entry still has to include it in
10
10
  * its CapabilitySet.
11
+ *
12
+ * Append only. The desktop mirrors this tuple by hand in its import-free
13
+ * types module and pins the two equal INDEX for index, so a verb inserted
14
+ * mid-list fails that parity test even when both lists hold the same names.
15
+ *
16
+ * `start-session` is the second lifecycle verb beside `move-task`: it spawns
17
+ * or resumes a task's session in the column the task is already in, so a
18
+ * phone's "Session ended" state can bring the agent back without moving the
19
+ * task. A live session is an idempotent no-op; nothing is ever stopped.
11
20
  */
12
- export declare const CAPABILITY_VERBS: readonly ["read-stream", "read-board", "read-diff", "send-user-message", "move-task", "answer-permission-prompt", "interactive-terminal", "board-tool-read", "board-tool-write", "register-push"];
21
+ export declare const CAPABILITY_VERBS: readonly ["read-stream", "read-board", "read-diff", "send-user-message", "move-task", "answer-permission-prompt", "interactive-terminal", "board-tool-read", "board-tool-write", "register-push", "start-session"];
13
22
  export type CapabilityVerb = (typeof CAPABILITY_VERBS)[number];
14
23
  export declare function isCapabilityVerb(value: string): value is CapabilityVerb;
15
24
  /** Deny-by-default: a verb absent from the set is not authorized. */
@@ -27,6 +27,7 @@
27
27
  * event before its router dispatches on `kind`.
28
28
  */
29
29
  import type { JsonValue } from '../wire/messages';
30
+ import { type ReadStreamSessionStatusWire } from '../wire/payloads';
30
31
  import { type ActivityReasonWire, type ActivityStateWire, type SessionEventWire, type SessionUsageWire, type TerminalDimensionsWire, type TranscriptEventPayload } from './payloads';
31
32
  export interface TranscriptEvent {
32
33
  kind: 'transcript';
@@ -60,16 +61,33 @@ export type ActivityEventPayload = {
60
61
  options?: string[];
61
62
  }
62
63
  /**
63
- * The streamed session's PTY exited. Pushed once by the desktop's
64
- * read-stream subscription right before it tears itself down, so the
65
- * phone learns "this session is over" from the feed itself instead of
66
- * inferring it from silence. `intentional` distinguishes a deliberate
67
- * stop (desktop Stop button, suspend, shutdown) from a crash.
64
+ * The feed's last word: the desktop's read-stream subscription pushes this
65
+ * once, right before it tears itself down, so the phone learns "this
66
+ * session is over" from the feed itself instead of inferring it from
67
+ * silence. Sent when the streamed session's PTY exits. From 0.16.0 it is
68
+ * also sent when a paused row, which the feed holds without a PTY, is
69
+ * replaced or removed. `intentional` distinguishes a deliberate stop
70
+ * (desktop Stop button, suspend, shutdown, a resume replacing a paused row)
71
+ * from a crash.
72
+ *
73
+ * `successorSessionId`, when present, names the session that replaced this
74
+ * one for the same task. A desktop resume never reuses the paused session's
75
+ * id: it spawns a new session and drops the paused row, so a feed held on
76
+ * the paused session can only end, never turn back into `running`. The task
77
+ * continues as the successor; subscribe to it. Its snapshot carries
78
+ * `sessionStatus` (`queued` when the desktop's concurrency limit holds it)
79
+ * and `resuming: true`. Absent when no successor exists (a removed paused
80
+ * row, or a successor whose own spawn failed), and from pre-0.16.0
81
+ * desktops, which never end a feed this way and leave it silent instead. An
82
+ * older phone ignores the field and still sees an ended session.
68
83
  *
69
84
  * `spawnProgressLabel`, when present, means the desktop had a respawn in
70
85
  * flight for this task when the session ended - a same-column respawn
71
86
  * (model switch, agent switch, effort change, isolated-session-track
72
- * switch) rather than a genuine park. Read it as what the desktop
87
+ * switch) or an in-place restart (a model or effort pick on the running
88
+ * task, a board-profile change, or the auto_command escalation that
89
+ * re-sends a command as the resume prompt, "Re-sending command...") rather
90
+ * than a genuine park. Read it as what the desktop
73
91
  * believed, not as a fact about what happens next; the caveats below
74
92
  * bound it. `intentional` cannot carry this distinction on its own:
75
93
  * the desktop's SessionManager.suspend() sets `status = 'suspended'`
@@ -78,7 +96,8 @@ export type ActivityEventPayload = {
78
96
  * the desktop's own display text for what it is doing ("Switching
79
97
  * model...", "Starting agent...", a live git-queue wait count) - treat it
80
98
  * as untrusted display text, not a key to switch on, cap its length, and
81
- * fall back to generic copy rather than parsing it.
99
+ * fall back to generic copy rather than parsing it. From 0.16.0 the desktop
100
+ * sends it sanitized as `BoardTaskWire.spawn_progress` describes.
82
101
  *
83
102
  * INTENT, not a guarantee, on the same terms `BoardColumnWire.spawns_session`
84
103
  * documents: the desktop can suspend without a successor ever landing (a
@@ -104,6 +123,41 @@ export type ActivityEventPayload = {
104
123
  type: 'session-ended';
105
124
  intentional: boolean;
106
125
  spawnProgressLabel?: string;
126
+ successorSessionId?: string;
127
+ }
128
+ /**
129
+ * The streamed session's lifecycle status changed after the subscribe
130
+ * snapshot: `queued` -> `running` when the desktop's concurrency limit
131
+ * frees a slot, -> `suspended` on a pause or a respawn, -> `exited` when the
132
+ * desktop retires a session whose agent already ended. Sent only on an
133
+ * actual change, for the same session id only. A resume is a NEW session
134
+ * id, so suspended -> running never arrives here: see `session-ended`'s
135
+ * `successorSessionId`.
136
+ *
137
+ * A `suspended` push precedes the PTY's `session-ended` when a running
138
+ * session is suspended, so for an instant both say the session is parked.
139
+ *
140
+ * Precedence, matching the desktop card: a non-null `spawn_progress` on the
141
+ * task's board row overrides `suspended` (the desktop suspends a session
142
+ * before every model, agent or effort respawn), and never `running` or
143
+ * `queued`. Read `suspended` alone as "Paused"; read it next to a label as
144
+ * that label.
145
+ *
146
+ * `resuming` and `resumable` repeat the snapshot fields so the payload is
147
+ * complete on its own. The desktop re-reads all three on each lifecycle
148
+ * edge of this session and sends the payload when any of them differs. A
149
+ * move to Done or an archive of a paused task is no edge of its row, so
150
+ * `resumable` here can stay true until the feed ends; gate Resume on
151
+ * `BoardTaskWire.resumable`, which the board event for that move refreshes.
152
+ * Absent from pre-0.16.0 desktops, whose phones drop the unknown
153
+ * type through `isBridgeEvent` and keep inferring status from activity
154
+ * events.
155
+ */
156
+ | {
157
+ type: 'status';
158
+ status: ReadStreamSessionStatusWire;
159
+ resuming: boolean;
160
+ resumable: boolean;
107
161
  }
108
162
  /**
109
163
  * The agent's most recent assistant message, already collapsed to a short
@@ -160,6 +160,12 @@ export interface SessionUsageWire {
160
160
  totalCostUsd: number;
161
161
  totalDurationMs: number;
162
162
  };
163
+ /**
164
+ * Completed tool calls across every run of the session. A resume (an app
165
+ * restart, a pause and resume) is a new run, and the desktop adds the
166
+ * session's earlier runs to the live count. Optional: an older desktop
167
+ * omits it.
168
+ */
163
169
  toolCallCount?: number;
164
170
  model: {
165
171
  id: string;
@@ -325,6 +331,77 @@ export interface BoardTaskWire {
325
331
  archived_at: string | null;
326
332
  created_at: string;
327
333
  updated_at: string;
334
+ /**
335
+ * The task's in-flight spawn-progress label, the text of the desktop card's
336
+ * preparing footer: "Creating worktree...", "Fetching latest...",
337
+ * "Waiting (2 ahead)", "Switching model...", "Starting agent...", a git-queue
338
+ * wait with its elapsed time, and any staleness note the desktop appends
339
+ * ("Starting agent... (base 3 behind)"). The desktop announces every change
340
+ * with a `task-updated` board event, coalesced to at most about one a
341
+ * second per task.
342
+ *
343
+ * Untrusted display text, the same terms as `session-ended`'s
344
+ * `spawnProgressLabel`: never parse it or switch on it, and fall back to
345
+ * generic copy. It can carry text the desktop did not write: a column
346
+ * automation's name, in `Running "<name>"...`, from a config a team may
347
+ * share. From 0.16.0 the desktop strips escape sequences, control characters,
348
+ * invisible format characters (bidi controls, the zero-width space, the soft
349
+ * hyphen, the byte order mark) and tag characters outside the England,
350
+ * Scotland and Wales flag emoji, turns line breaks and tabs into spaces, and
351
+ * caps it at
352
+ * 120 characters ending in "...", but a client still caps it for its own
353
+ * layout.
354
+ *
355
+ * Precedence, matching the desktop card: a label overrides a `suspended`
356
+ * session status (a respawn is in flight behind a session that was just
357
+ * suspended for it), and never a `running` or `queued` one. A client that
358
+ * reads the read-stream feed's `status: 'suspended'` during a model or
359
+ * effort switch shows this label, not "Paused".
360
+ *
361
+ * A spawn path that dies without clearing its label leaves it in place for
362
+ * up to the desktop's 120s spawn-progress TTL, and the TTL expiry sends no
363
+ * board event, so a stale label can outlive its spawn until the next
364
+ * snapshot. Null or absent means no spawn is in flight, or a desktop that
365
+ * predates the field (pre-0.16.0). Under `view: 'sessions'` a task with a
366
+ * label is kept even while its `session_id` is null, so a first start and
367
+ * a respawn's gap stay visible.
368
+ *
369
+ * Declared OPTIONAL (`?`) like `pr_merge_readiness`; `parseBoardTaskWire`
370
+ * populates the key from every real wire response.
371
+ */
372
+ spawn_progress?: string | null;
373
+ /**
374
+ * True when the task's session is paused and the desktop's own task view
375
+ * would offer Resume for it: the task is not in To Do or Done and not
376
+ * archived. It is the desktop's promise that `start-session` for this task
377
+ * resumes the paused session exactly as its Resume button does: the same
378
+ * conversation, the column's model, effort and permission, a "Resuming
379
+ * session..." label, and NO enter automations or column message. Gate a
380
+ * phone's Resume control on THIS field.
381
+ *
382
+ * On the board row because the phone always holds the board: a desktop
383
+ * pause clears the task's `session_id`, so a phone keeps no read-stream on
384
+ * a paused session (the stream's `resumable` covers only an open session
385
+ * screen through the suspend itself). A pause, a resume, a column move and
386
+ * an archive each reach the phone as a `task-updated` board event, after
387
+ * which the next snapshot carries the new value. Under `view: 'sessions'` a
388
+ * resumable task is kept even though its `session_id` is null, so an agent
389
+ * feed can draw it as Paused with a Resume control.
390
+ *
391
+ * Explicit on purpose, never inferred from another field: a pre-0.16.0
392
+ * desktop answers `start-session` by STARTING the column, which re-runs its
393
+ * enter automations and resends its message (a paused task in Code Review
394
+ * would get `/code-review` again). Null or absent means such a desktop; a
395
+ * client offers no Resume then. While `spawn_progress` is non-null a spawn
396
+ * is already in flight and the desktop card shows that label instead of a
397
+ * Resume control; a client applies the same precedence. `start-session`
398
+ * re-checks the column and refuses a To Do, Done or archived task with the
399
+ * desktop's Resume copy, so a value overtaken by a move is safe to act on.
400
+ *
401
+ * Declared OPTIONAL (`?`) like `spawns_session`; `parseBoardTaskWire`
402
+ * populates the key from every real wire response.
403
+ */
404
+ resumable?: boolean | null;
328
405
  }
329
406
  /** Phone-needed subset of the desktop's BacklogTask row. */
330
407
  export interface BacklogItemWire {