@mattstack/rt-client 0.16.0 → 0.19.1

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/dist/client.d.ts CHANGED
@@ -195,3 +195,36 @@ export declare function gateClose(a: Commands["gate:close"]["payload"], o?: RtCl
195
195
  export declare function gateSubscribe(a: Commands["gate:subscribe"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["gate:subscribe"]["data"]>>;
196
196
  export declare function gateUnsubscribe(a: Commands["gate:unsubscribe"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["gate:unsubscribe"]["data"]>>;
197
197
  export declare function gateSubscriptions(a: Commands["gate:subscriptions"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["gate:subscriptions"]["data"]>>;
198
+ /** Provisions the room, workspace and subscription before it answers, so it
199
+ gets the same 60s budget as a spawn rather than the 10s default. */
200
+ export declare function herdStart(a: Commands["herd:start"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:start"]["data"]>>;
201
+ /** Worktree provision plus agent launch; the 10s default cannot cover it. */
202
+ export declare function herdSpawn(a: Commands["herd:spawn"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:spawn"]["data"]>>;
203
+ export declare function herdAsk(a: Commands["herd:ask"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:ask"]["data"]>>;
204
+ export declare function herdMilestone(a: Commands["herd:milestone"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:milestone"]["data"]>>;
205
+ export declare function herdAnswer(a: Commands["herd:answer"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:answer"]["data"]>>;
206
+ /** A disposable job's report also closes its pane, one herdr CLI call under the runner's own 15s budget. */
207
+ export declare function herdReport(a: Commands["herd:report"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:report"]["data"]>>;
208
+ export declare function herdGates(a: Commands["herd:gates"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:gates"]["data"]>>;
209
+ export declare function herdStatus(a: Commands["herd:status"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:status"]["data"]>>;
210
+ export declare function herdList(a?: Commands["herd:list"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:list"]["data"]>>;
211
+ export declare function herdResume(a: Commands["herd:resume"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:resume"]["data"]>>;
212
+ /** Closes a herdr pane, one CLI call under the runner's own 15s budget. */
213
+ export declare function herdClose(a: Commands["herd:close"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:close"]["data"]>>;
214
+ /** Three sequential herdr CLI calls (pane get, tab create, pane run), each under the runner's own 15s budget. */
215
+ export declare function herdAttend(a: Commands["herd:attend"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:attend"]["data"]>>;
216
+ /** Closes panes, disposes worktrees and archives the room in one pass; the
217
+ worktree disposals alone can outrun a spawn's budget. */
218
+ export declare function herdWrapUp(a: Commands["herd:wrap-up"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:wrap-up"]["data"]>>;
219
+ /** Runs `herdr session stop`, one CLI call under the runner's own 15s budget. */
220
+ export declare function herdStopHidden(_a: Commands["herd:stop-hidden"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["herd:stop-hidden"]["data"]>>;
221
+ /** A cold ensure spawns `herdr server`, waits out bg-service's own 10s
222
+ readyTimeoutMs, then runs its parity probes sequentially -- the 15s
223
+ default budget every other rt-client call inherits can lose that race,
224
+ so this is the one wrapper that widens its own. */
225
+ export declare function bgEnsure(a?: Commands["bg:ensure"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["bg:ensure"]["data"]>>;
226
+ /** Never ensures/spawns; a plain read of the current state. */
227
+ export declare function bgStatus(o?: RtClientOptions): Promise<RtResponse<Commands["bg:status"]["data"]>>;
228
+ /** Asks the daemon to stop the background server; refuses (ok:false) while any claim is live, naming the owners. */
229
+ export declare function bgStop(o?: RtClientOptions): Promise<RtResponse<Commands["bg:stop"]["data"]>>;
230
+ export declare function bgRelease(a: Commands["bg:release"]["payload"], o?: RtClientOptions): Promise<RtResponse<Commands["bg:release"]["data"]>>;
@@ -128,6 +128,7 @@ export interface GateAnswer {
128
128
  }>;
129
129
  by: string;
130
130
  answeredAt: number;
131
+ overridden?: boolean;
131
132
  }
132
133
  export interface GateRow {
133
134
  id: string;
@@ -143,6 +144,8 @@ export interface GateRow {
143
144
  parkedAt: number | null;
144
145
  closedAt: number | null;
145
146
  closedReason: "abandoned" | "superseded" | "pruned" | null;
147
+ /** Set only when `closedReason` is "superseded": the id of the gate that superseded this one. */
148
+ supersededBy: string | null;
146
149
  agent: string | null;
147
150
  pane: string | null;
148
151
  nudge: {
@@ -153,6 +156,8 @@ export interface GateRow {
153
156
  at: number;
154
157
  } | null;
155
158
  released: boolean;
159
+ owner: string | null;
160
+ escalatedAt: number | null;
156
161
  }
157
162
  export interface GateSubscription {
158
163
  id: string;
@@ -164,6 +169,66 @@ export interface GateSubscription {
164
169
  at: number;
165
170
  } | null;
166
171
  dead: boolean;
172
+ scope: "prefix" | "owner";
173
+ ownerRef: string | null;
174
+ }
175
+ export interface HerdInfo {
176
+ id: string;
177
+ repo: string;
178
+ room: string;
179
+ workspace: string;
180
+ shepherdSession: string;
181
+ shepherdHandle: string;
182
+ herdrSocket: string | null;
183
+ hidden: boolean;
184
+ status: "active" | "wrapped";
185
+ createdAt: number;
186
+ wrappedAt: number | null;
187
+ }
188
+ /** A herd row as `herd:list` reports it: the registry row plus how many jobs hang off it. */
189
+ export interface HerdListRow extends HerdInfo {
190
+ jobs: number;
191
+ }
192
+ export interface HerdJobInfo {
193
+ herd: string;
194
+ name: string;
195
+ worktree: string;
196
+ branch: string | null;
197
+ tree: string | null;
198
+ pane: string | null;
199
+ agentSession: string | null;
200
+ agentId: string | null;
201
+ handle: string;
202
+ status: "spawning" | "active" | "at-gate" | "at-milestone" | "done" | "closed" | "crashed";
203
+ disposable: boolean;
204
+ lastGate: string | null;
205
+ lastReport: number | null;
206
+ createdAt: number;
207
+ updatedAt: number;
208
+ }
209
+ /** `lastGateStatus`/`lastGateDelivery` come from the job's `lastGate` row: an `answered` gate whose delivery is `dead-pane` is the "answered, worker not woken" case the shepherd must act on. */
210
+ export interface HerdStatusData {
211
+ herd: HerdInfo;
212
+ jobs: Array<HerdJobInfo & {
213
+ openGate: string | null;
214
+ paneStatus: string | null;
215
+ lastGateStatus: GateStatus | null;
216
+ lastGateDelivery: "delivered" | "dead-pane" | null;
217
+ }>;
218
+ unread: number;
219
+ lifecycleConnected: boolean;
220
+ hiddenUp: boolean | null;
221
+ /** The shepherd session's own `herd:<id>/` subscription row, or null when none is live. */
222
+ subscription: {
223
+ id: string;
224
+ dead: boolean;
225
+ lastDelivery: GateSubscription["lastDelivery"];
226
+ } | null;
227
+ /** Whether the shepherd session's own inbox socket is reachable right now, probed fresh on every status call -- honest liveness, not the subscription row's bookkeeping. */
228
+ push: {
229
+ state: "reachable" | "unreachable";
230
+ lastDelivery: GateSubscription["lastDelivery"];
231
+ };
167
232
  }
168
233
  /**
169
234
  * Duplicated shape on purpose, same reasoning as EventsBusEvent above:
@@ -285,9 +350,13 @@ export interface PaneSendResult {
285
350
  delivered: PaneDelivery;
286
351
  reason?: string;
287
352
  }
353
+ /** `attendTab` is set only for a `bg:` ref: focus for a background pane IS
354
+ the attend flow (a visible tab running a terminal attach), and this is
355
+ that tab's id. */
288
356
  export interface PaneFocusResult {
289
357
  paneId: string;
290
358
  focused: boolean;
359
+ attendTab?: string;
291
360
  }
292
361
  export type Attention = {
293
362
  needs: boolean;
@@ -559,9 +628,12 @@ export interface WorktreeCreateData {
559
628
  }
560
629
  export interface WorktreeDisposeData {
561
630
  disposed: string[];
631
+ /** `detail` is set only for a refusal whose bare `reason` code can't name
632
+ what a human needs to act on it (the run id and stage for `running-run`). */
562
633
  refused: Array<{
563
634
  tree: string;
564
635
  reason: string;
636
+ detail?: string;
565
637
  }>;
566
638
  recoverable: Array<{
567
639
  tree: string;
@@ -587,6 +659,7 @@ export interface WorktreeAdoptData {
587
659
  refused: Array<{
588
660
  tree: string;
589
661
  reason: string;
662
+ detail?: string;
590
663
  }>;
591
664
  }
592
665
  /** Duplicated shape on purpose: mirrors lib/endpoint/store.ts's EndpointClaim. */
@@ -1019,6 +1092,10 @@ export interface Commands {
1019
1092
  workspace?: string;
1020
1093
  tab?: string;
1021
1094
  extraArgs?: string;
1095
+ env?: Record<string, string>;
1096
+ herdrSocket?: string;
1097
+ handle?: string;
1098
+ bg?: boolean;
1022
1099
  };
1023
1100
  data: AgentRecord;
1024
1101
  };
@@ -1108,9 +1185,12 @@ export interface Commands {
1108
1185
  };
1109
1186
  data: PaneSendResult;
1110
1187
  };
1188
+ /** `callerWorkspace` (HERDR_WORKSPACE_ID) is required only for a `bg:`
1189
+ ref, whose focus opens an attend tab in the caller's own workspace. */
1111
1190
  "pane:focus": {
1112
1191
  payload: {
1113
1192
  paneId: string;
1193
+ callerWorkspace?: string;
1114
1194
  };
1115
1195
  data: PaneFocusResult;
1116
1196
  };
@@ -1304,12 +1384,21 @@ export interface Commands {
1304
1384
  * `conflict:true` and the WINNING row, so every consumer gets the winner
1305
1385
  * typed with no envelope hacks. `ok:false` is reserved for
1306
1386
  * not-found/closed/validation failures.
1387
+ *
1388
+ * Owner enforcement adds two structured rejections beyond the plain
1389
+ * `{ok:false, error:string}` shape (see `GateAnswerResult` in
1390
+ * `lib/daemon/handlers/gate.ts`): a herd-owned gate answered by anyone but
1391
+ * the owning shepherd's session, the answering pane, or an explicit human
1392
+ * `override` returns `{ok:false, error:"owned-by", owner}`; a closed gate
1393
+ * returns `{ok:false, error:"gate-closed", reason, supersededBy?}`.
1307
1394
  */
1308
1395
  "gate:answer": {
1309
1396
  payload: {
1310
1397
  id: string;
1311
1398
  answers: GateAnswer["answers"];
1312
1399
  by: string;
1400
+ session?: string;
1401
+ override?: boolean;
1313
1402
  };
1314
1403
  data: {
1315
1404
  row: GateRow;
@@ -1366,6 +1455,8 @@ export interface Commands {
1366
1455
  payload: {
1367
1456
  subjectPrefix: string;
1368
1457
  session: string;
1458
+ scope?: "owner";
1459
+ ownerRef?: string;
1369
1460
  };
1370
1461
  data: {
1371
1462
  id: string;
@@ -1390,6 +1481,180 @@ export interface Commands {
1390
1481
  subscriptions: GateSubscription[];
1391
1482
  };
1392
1483
  };
1484
+ "herd:start": {
1485
+ payload: {
1486
+ name: string;
1487
+ repo: string;
1488
+ session: string;
1489
+ hidden?: boolean;
1490
+ };
1491
+ data: {
1492
+ herd: string;
1493
+ room: string;
1494
+ workspace: string;
1495
+ subscription: string;
1496
+ handle: string;
1497
+ hidden: boolean;
1498
+ };
1499
+ };
1500
+ "herd:resume": {
1501
+ payload: {
1502
+ herd: string;
1503
+ session: string;
1504
+ };
1505
+ data: {
1506
+ subscription: string;
1507
+ gates: GateRow[];
1508
+ unread: number;
1509
+ status: HerdStatusData;
1510
+ handle: string;
1511
+ };
1512
+ };
1513
+ "herd:status": {
1514
+ payload: {
1515
+ herd: string;
1516
+ };
1517
+ data: HerdStatusData;
1518
+ };
1519
+ /** Active herds only unless `all`, so a shepherd's "which herd am I on" question has one answer. */
1520
+ "herd:list": {
1521
+ payload: {
1522
+ all?: boolean;
1523
+ };
1524
+ data: {
1525
+ herds: HerdListRow[];
1526
+ };
1527
+ };
1528
+ "herd:close": {
1529
+ payload: {
1530
+ herd: string;
1531
+ job: string;
1532
+ };
1533
+ data: {
1534
+ job: string;
1535
+ status: "closed"; /** Advisory: a resumable run can still write into this job's worktree after close, so this warns rather than blocking. */
1536
+ warning?: string;
1537
+ };
1538
+ };
1539
+ /** `brief` is the brief TEXT, not a path: the CLI reads the file. It is stored at `<jobsRoot>/<herd>/<job>/job.md`, so a respawn with `dir` and no `brief` reads it back. */
1540
+ "herd:spawn": {
1541
+ payload: {
1542
+ herd: string;
1543
+ job: string;
1544
+ brief?: string;
1545
+ dir?: string;
1546
+ model?: string;
1547
+ effort?: string;
1548
+ account?: string;
1549
+ disposable?: boolean;
1550
+ };
1551
+ data: {
1552
+ herd: string;
1553
+ job: string;
1554
+ pane: string;
1555
+ worktree: string;
1556
+ branch: string | null;
1557
+ tree: string | null; /** null = no provisioning ran (--dir); false = cold create, worth announcing. */
1558
+ wasOnDeck: boolean | null;
1559
+ agentId: string;
1560
+ sessionId: string;
1561
+ handle: string;
1562
+ };
1563
+ };
1564
+ "herd:gates": {
1565
+ payload: {
1566
+ herd: string;
1567
+ };
1568
+ data: {
1569
+ gates: GateRow[];
1570
+ };
1571
+ };
1572
+ "herd:ask": {
1573
+ payload: {
1574
+ herd: string;
1575
+ job: string;
1576
+ session: string;
1577
+ pane?: string;
1578
+ questions: GateQuestion[];
1579
+ context?: string;
1580
+ };
1581
+ data: {
1582
+ gate: string;
1583
+ };
1584
+ };
1585
+ "herd:milestone": {
1586
+ payload: {
1587
+ herd: string;
1588
+ job: string;
1589
+ session: string;
1590
+ pane?: string;
1591
+ artifact: string;
1592
+ summary?: string;
1593
+ };
1594
+ data: {
1595
+ gate: string;
1596
+ message: number;
1597
+ };
1598
+ };
1599
+ "herd:answer": {
1600
+ payload: {
1601
+ gate: string;
1602
+ };
1603
+ data: {
1604
+ gate: string;
1605
+ status: GateStatus;
1606
+ answer: GateAnswer | null;
1607
+ closedReason: GateRow["closedReason"];
1608
+ };
1609
+ };
1610
+ "herd:report": {
1611
+ payload: {
1612
+ herd: string;
1613
+ job: string;
1614
+ body: string;
1615
+ };
1616
+ data: {
1617
+ message: number;
1618
+ };
1619
+ };
1620
+ /** `callerWorkspace` is the attending session's own HERDR_WORKSPACE_ID: the attached tab opens there, not in the herd's workspace. */
1621
+ "herd:attend": {
1622
+ payload: {
1623
+ herd: string;
1624
+ job: string;
1625
+ callerWorkspace: string;
1626
+ };
1627
+ data: {
1628
+ tab: string;
1629
+ pane: string;
1630
+ };
1631
+ };
1632
+ "herd:stop-hidden": {
1633
+ payload: Record<string, never>;
1634
+ data: {
1635
+ stopped: boolean;
1636
+ };
1637
+ };
1638
+ "herd:wrap-up": {
1639
+ payload: {
1640
+ herd: string;
1641
+ closePanes?: boolean;
1642
+ dispose?: string[];
1643
+ deleteJobDirs?: boolean;
1644
+ archiveRoom?: boolean;
1645
+ };
1646
+ data: {
1647
+ closed: string[];
1648
+ workspaceClosed: boolean;
1649
+ disposed: string[];
1650
+ refused: Array<{
1651
+ tree: string;
1652
+ reason: string;
1653
+ }>;
1654
+ deletedJobDirs: boolean;
1655
+ archived: boolean;
1656
+ };
1657
+ };
1393
1658
  /** Wire reply on success is always `{ok:true, repaired}` (no `data`
1394
1659
  * wrapper) — `data` here documents the extra field the same way PingData
1395
1660
  * does for `ping`, not the literal wire nesting (R3). */
@@ -1488,6 +1753,46 @@ export interface Commands {
1488
1753
  };
1489
1754
  data: WorktreeAdoptData;
1490
1755
  };
1756
+ "bg:ensure": {
1757
+ payload: {
1758
+ claim?: string;
1759
+ };
1760
+ data: {
1761
+ socket: string;
1762
+ started: boolean;
1763
+ parity: {
1764
+ ok: boolean;
1765
+ drift: string[];
1766
+ } | null;
1767
+ };
1768
+ };
1769
+ "bg:status": {
1770
+ payload: Record<string, never>;
1771
+ data: {
1772
+ up: boolean;
1773
+ socket: string;
1774
+ claims: Array<{
1775
+ owner: string;
1776
+ pane: string | null;
1777
+ createdAt: number;
1778
+ }>;
1779
+ };
1780
+ };
1781
+ /** Rejects (`ok:false`) naming every live claim owner while any claim is held. */
1782
+ "bg:stop": {
1783
+ payload: Record<string, never>;
1784
+ data: {
1785
+ stopped: boolean;
1786
+ };
1787
+ };
1788
+ "bg:release": {
1789
+ payload: {
1790
+ claim: string;
1791
+ };
1792
+ data: {
1793
+ released: boolean;
1794
+ };
1795
+ };
1491
1796
  }
1492
1797
  export type CommandName = keyof Commands;
1493
1798
  export declare const COMMAND_NAMES: readonly CommandName[];
package/dist/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  export { rtCommand, DEFAULT_SOCK } from "./transport.ts";
2
2
  export type { RtResponse, RtClientOptions } from "./transport.ts";
3
- export { readProjectMRs, readDiscussions, readMrsByBranch, readBranchCache, resolveForgeToken, listRuns, getRun, abandonRun, chatJoin, chatLeave, chatAck, chatClaim, chatRelease, chatPost, chatRead, chatRooms, chatWho, chatMark, chatMessages, chatSignIn, chatSignOut, chatAway, chatBack, chatBuddies, chatDm, chatArchive, chatDmOpen, eventsHead, eventsEmit, eventsWait, eventsList, agentStart, agentResume, agentGet, agentList, paneList, panePeek, paneSpawn, paneAccounts, paneDirectories, chatInvite, paneSend, paneFocus, gateOpen, gateAnswer, gateWait, gateList, gatePark, gateClose, gateSubscribe, gateUnsubscribe, gateSubscriptions, } from "./client.ts";
3
+ export { readProjectMRs, readDiscussions, readMrsByBranch, readBranchCache, resolveForgeToken, listRuns, getRun, abandonRun, chatJoin, chatLeave, chatAck, chatClaim, chatRelease, chatPost, chatRead, chatRooms, chatWho, chatMark, chatMessages, chatSignIn, chatSignOut, chatAway, chatBack, chatBuddies, chatDm, chatArchive, chatDmOpen, eventsHead, eventsEmit, eventsWait, eventsList, agentStart, agentResume, agentGet, agentList, paneList, panePeek, paneSpawn, paneAccounts, paneDirectories, chatInvite, paneSend, paneFocus, gateOpen, gateAnswer, gateWait, gateList, gatePark, gateClose, gateSubscribe, gateUnsubscribe, gateSubscriptions, herdStart, herdSpawn, herdAsk, herdMilestone, herdAnswer, herdReport, herdGates, herdStatus, herdList, herdResume, herdClose, herdAttend, herdWrapUp, herdStopHidden, bgEnsure, bgStatus, bgStop, bgRelease, } from "./client.ts";
4
4
  export { COMMAND_NAMES, GATE_BY_PANE, gateOptionValue, gateOptionLabel } from "./commands.ts";
5
- export type { Discussion, DemandDecl, ProjectMRsScope, ProjectMRsData, DiscussionsData, MrByBranchEntry, MrByBranchData, BranchEnrichment, Commands, CommandName, ForgeSlug, ForgeTokenData, Attention, RunSummary, RunStageRow, RunFieldRow, RunDecisionRow, RunDetail, WakeMode, ChatMember, ChatMessage, ChatClaimOutcome, RoomSummary, BuddyStatus, PresenceRow, AgentRecord, AgentSurface, AgentStatus, ChatPane, PaneAccount, PaneDirectory, InviteResult, PaneDelivery, PaneSendResult, PaneFocusResult, GateStatus, GateOption, GateOrigin, GateQuestion, GateAnswer, GateRow, GateSubscription, } from "./commands.ts";
5
+ export type { Discussion, DemandDecl, ProjectMRsScope, ProjectMRsData, DiscussionsData, MrByBranchEntry, MrByBranchData, BranchEnrichment, Commands, CommandName, ForgeSlug, ForgeTokenData, Attention, RunSummary, RunStageRow, RunFieldRow, RunDecisionRow, RunDetail, WakeMode, ChatMember, ChatMessage, ChatClaimOutcome, RoomSummary, BuddyStatus, PresenceRow, AgentRecord, AgentSurface, AgentStatus, ChatPane, PaneAccount, PaneDirectory, InviteResult, PaneDelivery, PaneSendResult, PaneFocusResult, GateStatus, GateOption, GateOrigin, GateQuestion, GateAnswer, GateRow, GateSubscription, HerdInfo, HerdListRow, HerdJobInfo, HerdStatusData, } from "./commands.ts";
6
6
  export { subscribe, createRelay, DEFAULT_WS_URL } from "./relay.ts";
7
7
  export type { RelayEventType } from "./relay.ts";
8
8
  export { daemonHealth } from "./health.ts";
9
9
  export { repoNameForPath } from "./repos.ts";
10
10
  export { decidePlacement, openSmartPane } from "./smart-pane.ts";
11
11
  export type { Placement, PlacementOpts, HerdrCall } from "./smart-pane.ts";
12
+ export { BG_PREFIX, parsePaneRef, formatPaneRef } from "./pane-ref.ts";
13
+ export type { PaneServer, PaneRef } from "./pane-ref.ts";
12
14
  export { getSetting, listSettings, explainSetting, expandVariables, SCOPE_ORDER, setSettingsWarnSink } from "./settings/resolve.ts";
13
15
  export type { Scope, Provenance, ResolveOpts, Resolved, InvalidScope, ListedSetting, ExplainRow, ExpandCtx, } from "./settings/resolve.ts";
14
16
  export { setSetting, unsetSetting } from "./settings/write.ts";