@spencerboucher/switchyard 0.18.1 → 0.20.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.
Files changed (162) hide show
  1. package/README.md +9 -6
  2. package/dist/bridge/enroll.js +36 -6
  3. package/dist/bridge/switchyard-terminal.js +2 -1
  4. package/dist/policies/worker.js +48 -21
  5. package/dist/switchyard.mjs +1435 -617
  6. package/package.json +1 -1
  7. package/web-dist/assets/AutomationView-B4O_teaB.js +2 -0
  8. package/web-dist/assets/{AutomationView-DU4GvjqD.js.map → AutomationView-B4O_teaB.js.map} +1 -1
  9. package/web-dist/assets/Button-C7TQGuSX.js +2 -0
  10. package/web-dist/assets/Button-C7TQGuSX.js.map +1 -0
  11. package/web-dist/assets/{Card-WONLvqGM.js → Card-DzHrwFrv.js} +2 -2
  12. package/web-dist/assets/{Card-WONLvqGM.js.map → Card-DzHrwFrv.js.map} +1 -1
  13. package/web-dist/assets/{Checkbox-BmiLcC-z.js → Checkbox-BnRsg6ki.js} +2 -2
  14. package/web-dist/assets/{Checkbox-BmiLcC-z.js.map → Checkbox-BnRsg6ki.js.map} +1 -1
  15. package/web-dist/assets/{DangerZone-Ch2KNmob.js → DangerZone-BicyqXv8.js} +2 -2
  16. package/web-dist/assets/{DangerZone-Ch2KNmob.js.map → DangerZone-BicyqXv8.js.map} +1 -1
  17. package/web-dist/assets/Field-Cp-08kpe.js +2 -0
  18. package/web-dist/assets/Field-Cp-08kpe.js.map +1 -0
  19. package/web-dist/assets/{Markdown-Bo-ScAiV.js → Markdown-BPWc6K6m.js} +2 -2
  20. package/web-dist/assets/{Markdown-Bo-ScAiV.js.map → Markdown-BPWc6K6m.js.map} +1 -1
  21. package/web-dist/assets/{Priority-f7KceEZQ.js → Priority-ZGpTH645.js} +2 -2
  22. package/web-dist/assets/{Priority-f7KceEZQ.js.map → Priority-ZGpTH645.js.map} +1 -1
  23. package/web-dist/assets/{SegmentedControl-Ca8Fsw-g.js → SegmentedControl-Cvkz7C_A.js} +2 -2
  24. package/web-dist/assets/{SegmentedControl-Ca8Fsw-g.js.map → SegmentedControl-Cvkz7C_A.js.map} +1 -1
  25. package/web-dist/assets/Select-DHRR7IAK.js +2 -0
  26. package/web-dist/assets/{Select-B04kPhBs.js.map → Select-DHRR7IAK.js.map} +1 -1
  27. package/web-dist/assets/{Switch-DHX-YYPr.js → Switch-D5pVfZgf.js} +2 -2
  28. package/web-dist/assets/{Switch-DHX-YYPr.js.map → Switch-D5pVfZgf.js.map} +1 -1
  29. package/web-dist/assets/Tabs-2GilVMsH.js +2 -0
  30. package/web-dist/assets/{Tabs-BgpFIjqW.js.map → Tabs-2GilVMsH.js.map} +1 -1
  31. package/web-dist/assets/{TextLink-CCc3WEdm.js → TextLink-BGtYWCW9.js} +2 -2
  32. package/web-dist/assets/{TextLink-CCc3WEdm.js.map → TextLink-BGtYWCW9.js.map} +1 -1
  33. package/web-dist/assets/{UINodeRenderer-CHlMHtMT.js → UINodeRenderer-BaANWHvJ.js} +3 -3
  34. package/web-dist/assets/{UINodeRenderer-CHlMHtMT.js.map → UINodeRenderer-BaANWHvJ.js.map} +1 -1
  35. package/web-dist/assets/UnfilteredNote-zVO8ajSi.js +2 -0
  36. package/web-dist/assets/{UnfilteredNote-DzKbzrjZ.js.map → UnfilteredNote-zVO8ajSi.js.map} +1 -1
  37. package/web-dist/assets/ViewSelect-C9gNftWK.js +2 -0
  38. package/web-dist/assets/ViewSelect-C9gNftWK.js.map +1 -0
  39. package/web-dist/assets/api-DMrk4xwq.js +2 -0
  40. package/web-dist/assets/api-DMrk4xwq.js.map +1 -0
  41. package/web-dist/assets/{arrow-down-YwTzxo-r.js → arrow-down-Dn3KG_JI.js} +2 -2
  42. package/web-dist/assets/{arrow-down-YwTzxo-r.js.map → arrow-down-Dn3KG_JI.js.map} +1 -1
  43. package/web-dist/assets/{arrow-up-Bzh112dp.js → arrow-up-BiPtOqqy.js} +2 -2
  44. package/web-dist/assets/{arrow-up-Bzh112dp.js.map → arrow-up-BiPtOqqy.js.map} +1 -1
  45. package/web-dist/assets/attention-B9uawu1d.js +2 -0
  46. package/web-dist/assets/attention-B9uawu1d.js.map +1 -0
  47. package/web-dist/assets/automations-IX9DQNk8.js +2 -0
  48. package/web-dist/assets/{automations-DTTGHyoo.js.map → automations-IX9DQNk8.js.map} +1 -1
  49. package/web-dist/assets/board-BUAI4L7M.js +6 -0
  50. package/web-dist/assets/{board-Blv0pC_z.js.map → board-BUAI4L7M.js.map} +1 -1
  51. package/web-dist/assets/{calendar-clock-CwOgyN2z.js → calendar-clock-DVlat602.js} +2 -2
  52. package/web-dist/assets/{calendar-clock-CwOgyN2z.js.map → calendar-clock-DVlat602.js.map} +1 -1
  53. package/web-dist/assets/check-CEnbWw4D.js +2 -0
  54. package/web-dist/assets/{check-DTN2VHtE.js.map → check-CEnbWw4D.js.map} +1 -1
  55. package/web-dist/assets/chevron-right-BM1IJI2z.js +2 -0
  56. package/web-dist/assets/{chevron-right-aaHL5Igi.js.map → chevron-right-BM1IJI2z.js.map} +1 -1
  57. package/web-dist/assets/code-Dav4E15n.js +25 -0
  58. package/web-dist/assets/code-Dav4E15n.js.map +1 -0
  59. package/web-dist/assets/{core.esm-DZMOHGS9.js → core.esm-C4dCvG0s.js} +2 -2
  60. package/web-dist/assets/{core.esm-DZMOHGS9.js.map → core.esm-C4dCvG0s.js.map} +1 -1
  61. package/web-dist/assets/describe-B66LJTqU.js +2 -0
  62. package/web-dist/assets/describe-B66LJTqU.js.map +1 -0
  63. package/web-dist/assets/{describe-Q2nvYHjg.js → describe-BeFxHr2Y.js} +3 -3
  64. package/web-dist/assets/{describe-Q2nvYHjg.js.map → describe-BeFxHr2Y.js.map} +1 -1
  65. package/web-dist/assets/enroll-GUEF5Uxu.js +2 -0
  66. package/web-dist/assets/{enroll-wAPt550I.js.map → enroll-GUEF5Uxu.js.map} +1 -1
  67. package/web-dist/assets/{external-link-CI-Uzhfh.js → external-link-B3hnazCa.js} +2 -2
  68. package/web-dist/assets/{external-link-CI-Uzhfh.js.map → external-link-B3hnazCa.js.map} +1 -1
  69. package/web-dist/assets/{hand-HCdmhGph.js → hand-B6lvj014.js} +2 -2
  70. package/web-dist/assets/{hand-HCdmhGph.js.map → hand-B6lvj014.js.map} +1 -1
  71. package/web-dist/assets/index-BUZpNu-R.js +22 -0
  72. package/web-dist/assets/index-BUZpNu-R.js.map +1 -0
  73. package/web-dist/assets/index-C9iuCGwg.css +2 -0
  74. package/web-dist/assets/{keyboardLayers-CpCxpJ43.js → keyboardLayers-BZOygMAH.js} +2 -2
  75. package/web-dist/assets/{keyboardLayers-CpCxpJ43.js.map → keyboardLayers-BZOygMAH.js.map} +1 -1
  76. package/web-dist/assets/{link-2-D6l0YZ-8.js → link-2-CCq9WzMy.js} +2 -2
  77. package/web-dist/assets/{link-2-D6l0YZ-8.js.map → link-2-CCq9WzMy.js.map} +1 -1
  78. package/web-dist/assets/logic-BBQ4d1GC.js +4 -0
  79. package/web-dist/assets/logic-BBQ4d1GC.js.map +1 -0
  80. package/web-dist/assets/{logic-CzU-NdeO.js → logic-BnSIy9_P.js} +2 -2
  81. package/web-dist/assets/{logic-CzU-NdeO.js.map → logic-BnSIy9_P.js.map} +1 -1
  82. package/web-dist/assets/more-C1oPXLVM.js +2 -0
  83. package/web-dist/assets/{more-D1YpQrbP.js.map → more-C1oPXLVM.js.map} +1 -1
  84. package/web-dist/assets/{pencil-BtK08_f_.js → pencil-DeML-0z2.js} +2 -2
  85. package/web-dist/assets/{pencil-BtK08_f_.js.map → pencil-DeML-0z2.js.map} +1 -1
  86. package/web-dist/assets/{play-j138GLHB.js → play-NHO6U6cY.js} +2 -2
  87. package/web-dist/assets/{play-j138GLHB.js.map → play-NHO6U6cY.js.map} +1 -1
  88. package/web-dist/assets/{plus-D935l0Os.js → plus-C83uJhbf.js} +2 -2
  89. package/web-dist/assets/{plus-D935l0Os.js.map → plus-C83uJhbf.js.map} +1 -1
  90. package/web-dist/assets/policyLogic-DqKyFQEW.js +2 -0
  91. package/web-dist/assets/policyLogic-DqKyFQEW.js.map +1 -0
  92. package/web-dist/assets/{queue-CdBAajey.js → queue-DWSd1kia.js} +2 -2
  93. package/web-dist/assets/{queue-CdBAajey.js.map → queue-DWSd1kia.js.map} +1 -1
  94. package/web-dist/assets/repo-DRwGWCut.js +2 -0
  95. package/web-dist/assets/repo-DRwGWCut.js.map +1 -0
  96. package/web-dist/assets/{rotate-ccw-mfO3Crkq.js → rotate-ccw-BRrlVEAQ.js} +2 -2
  97. package/web-dist/assets/{rotate-ccw-mfO3Crkq.js.map → rotate-ccw-BRrlVEAQ.js.map} +1 -1
  98. package/web-dist/assets/{search-DdgUAUi7.js → search-C5H14z0D.js} +2 -2
  99. package/web-dist/assets/{search-DdgUAUi7.js.map → search-C5H14z0D.js.map} +1 -1
  100. package/web-dist/assets/settings-B0IbaTOd.js +12 -0
  101. package/web-dist/assets/settings-B0IbaTOd.js.map +1 -0
  102. package/web-dist/assets/{states-f_A68-u-.js → states-hyf_ATdQ.js} +4 -4
  103. package/web-dist/assets/states-hyf_ATdQ.js.map +1 -0
  104. package/web-dist/assets/{terminal-DKqo1lis.js → terminal-CATQN_17.js} +2 -2
  105. package/web-dist/assets/{terminal-DKqo1lis.js.map → terminal-CATQN_17.js.map} +1 -1
  106. package/web-dist/assets/terminal-login-BdkmJdOO.js +2 -0
  107. package/web-dist/assets/{terminal-login-eMNouLWh.js.map → terminal-login-BdkmJdOO.js.map} +1 -1
  108. package/web-dist/assets/{timer-CDGYPIoD.js → timer-DFrvOKOy.js} +2 -2
  109. package/web-dist/assets/{timer-CDGYPIoD.js.map → timer-DFrvOKOy.js.map} +1 -1
  110. package/web-dist/assets/{useBreakpoint-kT0J1Dnk.js → useBreakpoint-BYCN9s8X.js} +2 -2
  111. package/web-dist/assets/{useBreakpoint-kT0J1Dnk.js.map → useBreakpoint-BYCN9s8X.js.map} +1 -1
  112. package/web-dist/assets/useNow-DXyC-YfE.js +2 -0
  113. package/web-dist/assets/{useNow-CjCVyQra.js.map → useNow-DXyC-YfE.js.map} +1 -1
  114. package/web-dist/assets/{useResource-BvhL-G6a.js → useResource-DYNGG9XS.js} +2 -2
  115. package/web-dist/assets/{useResource-BvhL-G6a.js.map → useResource-DYNGG9XS.js.map} +1 -1
  116. package/web-dist/assets/workboard-BJCZsLp5.js +3 -0
  117. package/web-dist/assets/workboard-BJCZsLp5.js.map +1 -0
  118. package/web-dist/index.html +7 -8
  119. package/web-dist/sw.js +1 -1
  120. package/web-dist/sw.js.map +1 -1
  121. package/web-dist/assets/AutomationView-DU4GvjqD.js +0 -2
  122. package/web-dist/assets/Button-BKQW9doW.js +0 -2
  123. package/web-dist/assets/Button-BKQW9doW.js.map +0 -1
  124. package/web-dist/assets/Copy-CdlOSzns.js +0 -2
  125. package/web-dist/assets/Copy-CdlOSzns.js.map +0 -1
  126. package/web-dist/assets/InteractionCard-C3H45DAY.js +0 -4
  127. package/web-dist/assets/InteractionCard-C3H45DAY.js.map +0 -1
  128. package/web-dist/assets/Select-B04kPhBs.js +0 -2
  129. package/web-dist/assets/Tabs-BgpFIjqW.js +0 -2
  130. package/web-dist/assets/UnfilteredNote-DzKbzrjZ.js +0 -2
  131. package/web-dist/assets/ViewSelect-Dz7vh4fq.js +0 -2
  132. package/web-dist/assets/ViewSelect-Dz7vh4fq.js.map +0 -1
  133. package/web-dist/assets/api-C9NJpI9q.js +0 -2
  134. package/web-dist/assets/api-C9NJpI9q.js.map +0 -1
  135. package/web-dist/assets/attention-BMxYQaCW.js +0 -2
  136. package/web-dist/assets/attention-BMxYQaCW.js.map +0 -1
  137. package/web-dist/assets/automations-DTTGHyoo.js +0 -2
  138. package/web-dist/assets/board-Blv0pC_z.js +0 -6
  139. package/web-dist/assets/check-DTN2VHtE.js +0 -2
  140. package/web-dist/assets/chevron-right-aaHL5Igi.js +0 -2
  141. package/web-dist/assets/code-BsVbn6T3.js +0 -25
  142. package/web-dist/assets/code-BsVbn6T3.js.map +0 -1
  143. package/web-dist/assets/enroll-wAPt550I.js +0 -2
  144. package/web-dist/assets/index-9TW72kVM.css +0 -2
  145. package/web-dist/assets/index-Du1kfnPp.js +0 -17
  146. package/web-dist/assets/index-Du1kfnPp.js.map +0 -1
  147. package/web-dist/assets/more-D1YpQrbP.js +0 -2
  148. package/web-dist/assets/policyLogic-Dk_rwjQS.js +0 -2
  149. package/web-dist/assets/policyLogic-Dk_rwjQS.js.map +0 -1
  150. package/web-dist/assets/repo-CTLrFN0k.js +0 -2
  151. package/web-dist/assets/repo-CTLrFN0k.js.map +0 -1
  152. package/web-dist/assets/selection-DDKGpSXL.js +0 -7
  153. package/web-dist/assets/selection-DDKGpSXL.js.map +0 -1
  154. package/web-dist/assets/settings-C3rhTyqj.js +0 -12
  155. package/web-dist/assets/settings-C3rhTyqj.js.map +0 -1
  156. package/web-dist/assets/states-f_A68-u-.js.map +0 -1
  157. package/web-dist/assets/terminal-login-eMNouLWh.js +0 -2
  158. package/web-dist/assets/trackers-BKCB5pxU.js +0 -2
  159. package/web-dist/assets/trackers-BKCB5pxU.js.map +0 -1
  160. package/web-dist/assets/useNow-CjCVyQra.js +0 -2
  161. package/web-dist/assets/workboard-Btp-KIzn.js +0 -3
  162. package/web-dist/assets/workboard-Btp-KIzn.js.map +0 -1
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  **Run [Pi](https://github.com/earendil-works/pi) coding agents on your own machines, and drive them from your phone, your browser or your terminal.**
4
4
 
5
+ Website and documentation: **https://switchyard-site.pages.dev**
6
+
5
7
  A coding agent has to run where your repositories, toolchains and logins are: your laptop, a workstation, a home server. You, on the other hand, are not always sitting in front of that machine. Switchyard keeps the agents where the work is and lets you follow along from anywhere: start a session from your phone, answer the question it asks while you are on your laptop, take over from a terminal, and get a notification when the result is ready for review. Every client looks at the same live session, and closing one never stops the work.
6
8
 
7
9
  Switchyard tracks what you are working on as branches: each has a worktree and one agent session, wherever it runs, and the issues, pull requests and board columns that go with it. On top of that it adds GitHub trackers, scheduled automations and a review flow, so an agent can work through a backlog while you are away and hand everything back for you to accept. Switchyard aims to preserve continuity with your evolving Pi setup: plugins own their workflows and optional adapters translate supported interactions, not arbitrary custom terminal UIs. See [plugin ownership](docs/plugin-boundaries.md).
@@ -37,7 +39,7 @@ There are three kinds of parts:
37
39
 
38
40
  - **The coordinator** is the one always-on service. It keeps tasks, schedules, notifications, devices and the shared view of every session, and it decides what runs where. It never runs an agent and never holds your provider credentials, so it can live anywhere: a container, a small server, or your laptop.
39
41
  - **Hosts** are your machines. A host agent runs Pi as your OS user, with your repositories, worktrees, Pi packages and model logins, and connects *outbound* to the coordinator. A host needs no open ports, and a laptop can come and go: its sessions keep running while the coordinator is down, and the events catch up when it returns.
40
- - **Clients** show views: a view is a saved filter over branches, and a terminal mirror (herdr, tmux) is a surface bound to one view. The web app works on desktop and as an installed app on a phone; in a terminal you get Pi's own TUI for any session (`switchyard tui`, or a whole herdr session mirroring Switchyard), and the scriptable CLI works over the same API. Any client can watch, answer and steer a session; none of them owns it.
42
+ - **Clients** show views: a view is a saved filter over branches, and a terminal (a herdr or tmux session) can mirror one view, everything, or nothing. The web app works on desktop and as an installed app on a phone; in a terminal you get Pi's own TUI for any session (`switchyard tui`, or a whole herdr session mirroring Switchyard), and the scriptable CLI works over the same API. Any client can watch, answer and steer a session; none of them owns it.
41
43
 
42
44
  For a single machine, `switchyard up` runs the coordinator and a host in one process. For more, run the coordinator as a server and enroll each machine as a host. The protocol is the same either way.
43
45
 
@@ -105,9 +107,9 @@ sequenceDiagram
105
107
  | **Tracker** | The GitHub issues assigned to you (or a board's open issues) in one owner, optionally with a Projects board |
106
108
  | **Issue** | One issue a tracker follows, attached to the branch it is worked on |
107
109
  | **Stage** | Where a branch is: Not started, Working, In review, Merged |
108
- | **View** | A saved filter over branches: projects, hosts, pins, and an optional source |
110
+ | **View** | A named part of your work: a set of projects (yours, or a tracker's) and pins, optionally limited to hosts |
109
111
  | **Device** | A signed-in client: a browser, an installed web app or a terminal |
110
- | **Surface** | A herdr or tmux session showing a view, under the device it is signed in with |
112
+ | **Terminal** | A herdr or tmux session: it holds Pi you start there by hand, and mirrors nothing, everything or one view, a tab per active branch |
111
113
  | **Task** | A unit of dispatched work, with an objective and acceptance criteria, on the task board |
112
114
  | **Run** | One attempt at a task, carried out in a session |
113
115
  | **Adapter** | Code that renders a specific Pi plugin's questions and state as structured UI |
@@ -130,7 +132,7 @@ switchyard up
130
132
  ```sh
131
133
  docker run -d --name switchyard -p 127.0.0.1:7400:7400 -v switchyard-data:/data \
132
134
  -e SWITCHYARD_PUBLIC_URL=https://switchyard.example.com \
133
- ghcr.io/justmytwospence/switchyard:0.18.1
135
+ ghcr.io/justmytwospence/switchyard:0.20.0
134
136
  # Single sign-on is required off localhost: see docs/auth.md
135
137
  ```
136
138
 
@@ -166,13 +168,14 @@ Switchyard is young and moving quickly. It is tested against Pi `>=1.4.0 <1.7.0`
166
168
 
167
169
  | Guide | Covers |
168
170
  |---|---|
169
- | [Model](docs/model.md) | Branches, sessions, trackers, views, devices and surfaces, and how they fit together |
171
+ | [Getting started](docs/getting-started.md) | Install, first host, first session, phone and terminal |
172
+ | [Model](docs/model.md) | Branches, sessions, trackers, views, devices and terminals, and how they fit together |
170
173
  | [Trackers](docs/trackers.md) | GitHub issues, worktrees for their branches, Projects board write-back |
171
174
  | [Deployment](docs/deployment.md) | Single machine, server, reverse proxies, VPNs, hosts, environment reference, privilege model |
172
175
  | [Sign-in and devices](docs/auth.md) | The owner model, single sign-on, passkeys, terminal approval, single sign-on, host enrollment, revocation |
173
176
  | [CLI](docs/cli.md) | Every `switchyard` command and credentials |
174
177
  | [Keyboard shortcuts](docs/keyboard-shortcuts.md) | Vim-style app navigation, palette controls and the `?` help sheet |
175
- | [Terminal sessions](docs/terminal-sessions.md) | Pi's own TUI for every session, from any terminal, and the herdr integration |
178
+ | [TUI sessions and terminals](docs/terminal-sessions.md) | Pi's own TUI for every session, from any terminal; herdr and tmux sessions as terminals that mirror views |
176
179
  | [Operations](docs/operations.md) | Backup, restore, migrations, retention, logs, health, diagnostics |
177
180
  | [Policies](docs/policies.md) | Agent tools, guardrails, approvals and budgets |
178
181
  | [GitHub](docs/github.md) | Host authentication, PR review and merge, issue tasks |
@@ -1,14 +1,43 @@
1
+ import { execFileSync } from "node:child_process";
1
2
  import { existsSync, readFileSync } from "node:fs";
2
3
  import { hostname } from "node:os";
3
4
  import { join } from "node:path";
4
5
  import { defaultStateDir } from "./state-dir.js";
5
- /** The client this Pi runs in, as a view client id (`herdr:<session>@<machine>`), or null. */
6
- export function clientId(env, host = hostname()) {
7
- if (env.HERDR_ENV !== "1")
6
+ /** The tmux session this process runs in (`TMUX`), or null. */
7
+ function tmuxSessionName(env) {
8
+ if (!env.TMUX)
8
9
  return null;
9
- const fromSocket = /\/sessions\/([^/]+)\/herdr\.sock$/.exec(env.HERDR_SOCKET_PATH ?? "")?.[1];
10
- const name = fromSocket || env.HERDR_SESSION?.trim() || "default";
11
- return `herdr:${name}@${host}`;
10
+ try {
11
+ const pane = env.TMUX_PANE ? ["-t", env.TMUX_PANE] : [];
12
+ const name = execFileSync("tmux", ["display-message", "-p", ...pane, "#S"], {
13
+ encoding: "utf8",
14
+ timeout: 2000,
15
+ stdio: ["ignore", "pipe", "ignore"],
16
+ }).trim();
17
+ return name || null;
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ }
23
+ /**
24
+ * The terminal this Pi runs in, as Switchyard names terminals (`herdr:<session>@<machine>` or
25
+ * `tmux:<session>@<machine>`), or null. herdr wins when both are set (herdr inside tmux).
26
+ */
27
+ export function clientId(env, host = hostname(), tmuxName = tmuxSessionName) {
28
+ if (env.HERDR_ENV === "1") {
29
+ const fromSocket = /\/sessions\/([^/]+)\/herdr\.sock$/.exec(env.HERDR_SOCKET_PATH ?? "")?.[1];
30
+ const name = fromSocket || env.HERDR_SESSION?.trim() || "default";
31
+ return `herdr:${name}@${host}`;
32
+ }
33
+ const tmux = tmuxName(env);
34
+ return tmux ? `tmux:${tmux}@${host}` : null;
35
+ }
36
+ /** The pane this Pi runs in, in its terminal's ids (`w1:p2`, `%3`), or null. */
37
+ export function paneId(env) {
38
+ if (env.HERDR_ENV === "1")
39
+ return env.HERDR_PANE_ID?.trim() || null;
40
+ return env.TMUX ? env.TMUX_PANE?.trim() || null : null;
12
41
  }
13
42
  /**
14
43
  * The runtime directory to enrol in, or null when this Pi must not enrol: Switchyard started it,
@@ -36,6 +65,7 @@ export function isEnrollMeta(v) {
36
65
  typeof m.cwd === "string" &&
37
66
  m.cwd.startsWith("/") &&
38
67
  (m.client === null || typeof m.client === "string") &&
68
+ (m.pane === undefined || m.pane === null || typeof m.pane === "string") &&
39
69
  typeof m.sessionId === "string" &&
40
70
  m.sessionId.length > 0 &&
41
71
  typeof m.sessionFile === "string" &&
@@ -27,7 +27,7 @@ import { createConnection, createServer } from "node:net";
27
27
  import { fileURLToPath } from "node:url";
28
28
  import { createAgentChannel } from "./agent-channel.js";
29
29
  import { registerAgentTools } from "./agent-tools.js";
30
- import { clientId, enrollRuntimeDir, metaPath } from "./enroll.js";
30
+ import { clientId, enrollRuntimeDir, metaPath, paneId } from "./enroll.js";
31
31
  import { LineSplitter } from "./lines.js";
32
32
  import { createMessageDelivery } from "./message-delivery.js";
33
33
  import { modelInfo } from "./pi-model.js";
@@ -892,6 +892,7 @@ export default function switchyardTerminal(pi) {
892
892
  pid: process.pid,
893
893
  cwd: ctx.cwd ?? process.cwd(),
894
894
  client: clientId(process.env),
895
+ pane: paneId(process.env),
895
896
  sessionId: ctx.sessionManager.getSessionId(),
896
897
  sessionFile: file,
897
898
  startedAt,
@@ -1096,28 +1096,31 @@ var View = z6.object({
1096
1096
  projectIds: z6.array(z6.string()).nullable(),
1097
1097
  hostIds: z6.array(z6.string()).nullable(),
1098
1098
  sessionIds: z6.array(z6.string()),
1099
- /** Deprecated: always empty; see Surface. */
1099
+ /** Deprecated: always empty; see Terminal. */
1100
1100
  clients: z6.array(ViewClient).default([]),
1101
1101
  /** A tracker keeps this view's projects (see docs/trackers.md). */
1102
1102
  trackerId: z6.string().nullable().optional(),
1103
- /**
1104
- * The source surface (`herdr:<session>@<machine>`): sessions started in it
1105
- * (`Session.startedIn`) belong to this view.
1106
- */
1107
- clientId: z6.string().min(1).max(200).nullable().optional(),
1108
1103
  createdAt: Iso,
1109
1104
  updatedAt: Iso
1110
1105
  });
1111
- var SurfaceKind = z6.enum(["herdr", "tmux"]);
1112
- var Surface = z6.object({
1106
+ var TerminalKind = z6.enum(["herdr", "tmux"]);
1107
+ var TerminalMirror = z6.enum(["none", "all", "view"]);
1108
+ var Terminal = z6.object({
1113
1109
  /** `${kind}:${name}@${machine}` */
1114
1110
  id: z6.string().min(1).max(200),
1115
- kind: SurfaceKind,
1111
+ kind: TerminalKind,
1116
1112
  name: z6.string().min(1),
1117
1113
  machine: z6.string().min(1),
1118
1114
  deviceId: Id4,
1119
1115
  hostId: Id4.nullable(),
1116
+ /** What it mirrors (coordinator-owned); older records have only `viewId`. */
1117
+ mirror: TerminalMirror.optional(),
1118
+ /** The view it mirrors when `mirror` is "view" (coordinator-owned). */
1120
1119
  viewId: Id4.nullable(),
1120
+ /** When the binding was recorded; null when it never was (a daemon may seed it once). */
1121
+ bindingSetAt: Iso.nullable().optional(),
1122
+ /** Sessions it shows in mirror tabs or windows now (daemon-owned). */
1123
+ shows: z6.array(Id4).max(1e3).optional(),
1121
1124
  lastSeenAt: Iso,
1122
1125
  createdAt: Iso
1123
1126
  });
@@ -1182,12 +1185,18 @@ var Session = z6.object({
1182
1185
  * in, when known). Switchyard never shows or closes that terminal.
1183
1186
  */
1184
1187
  external: z6.object({ client: z6.string().min(1).max(200).nullable() }).nullable().optional(),
1188
+ /**
1189
+ * Where this Pi last ran by hand (host-owned): the terminal (`herdr:<s>@<m>`, `tmux:<s>@<m>`)
1190
+ * and pane. Kept after it stops; cleared once Switchyard starts it. Older hosts omit it.
1191
+ */
1192
+ place: z6.object({
1193
+ terminalId: z6.string().min(1).max(200),
1194
+ pane: z6.string().min(1).max(200).nullable()
1195
+ }).nullable().optional(),
1185
1196
  /** The session this subagent was started by (coordinator-owned). */
1186
1197
  parentSessionId: Id4.nullable().optional(),
1187
1198
  /** Chosen as its branch's primary session (coordinator-owned); without one the primary is derived. */
1188
1199
  primary: z6.boolean().optional(),
1189
- /** The surface this Pi was started in, e.g. `herdr:default@mac` (coordinator-owned, set once). */
1190
- startedIn: z6.string().min(1).max(200).nullable().optional(),
1191
1200
  /** Set when the session finished or failed with nobody viewing it; cleared when viewed (coordinator-owned). */
1192
1201
  unreadSince: Iso.nullable().optional(),
1193
1202
  /** Identity of the adapter presentation currently installed on the host. */
@@ -2140,13 +2149,15 @@ var EventDataSchemas = {
2140
2149
  "device.updated": Device,
2141
2150
  "issue.updated": TrackedIssue,
2142
2151
  "issue.deleted": z11.object({ id: z11.string() }),
2143
- "surface.updated": Surface,
2144
- "surface.deleted": z11.object({ id: z11.string() }),
2152
+ "terminal.updated": Terminal,
2153
+ "terminal.deleted": z11.object({ id: z11.string() }),
2145
2154
  "settings.updated": z11.object({ dispatchPaused: z11.boolean() })
2146
2155
  };
2147
2156
  var EVENT_TYPES = Object.keys(EventDataSchemas);
2148
2157
  var LEGACY_EVENT_TYPES = {
2149
- "workspace.removed": "workspace.deleted"
2158
+ "workspace.removed": "workspace.deleted",
2159
+ "surface.updated": "terminal.updated",
2160
+ "surface.deleted": "terminal.deleted"
2150
2161
  };
2151
2162
  function canonicalEventType(type) {
2152
2163
  return LEGACY_EVENT_TYPES[type] ?? type;
@@ -3046,7 +3057,17 @@ var MeResponse = z14.object({
3046
3057
  admin: z14.boolean(),
3047
3058
  publicUrl: z14.string()
3048
3059
  });
3049
- var SurfaceReport = Surface.pick({
3060
+ var TerminalBindingInput = z14.object({ mirror: TerminalMirror, viewId: z14.string().min(1).nullable().optional() }).refine((b) => b.mirror === "view" === !!b.viewId, {
3061
+ message: "viewId is required for mirror=view and only then"
3062
+ });
3063
+ var TerminalReport = Terminal.pick({ kind: true, name: true, machine: true }).extend({
3064
+ hostId: z14.string().nullable().optional(),
3065
+ /** Sessions in its mirror tabs or windows; omitted when unchanged or unknown. */
3066
+ shows: z14.array(z14.string()).max(1e3).optional(),
3067
+ /** The binding this terminal had before bindings were recorded (env file); applied only when none is recorded. */
3068
+ seed: TerminalBindingInput.optional()
3069
+ });
3070
+ var SurfaceReport = Terminal.pick({
3050
3071
  kind: true,
3051
3072
  name: true,
3052
3073
  machine: true,
@@ -3056,8 +3077,7 @@ var ViewInput = View.pick({
3056
3077
  name: true,
3057
3078
  mode: true,
3058
3079
  projectIds: true,
3059
- hostIds: true,
3060
- clientId: true
3080
+ hostIds: true
3061
3081
  }).partial({
3062
3082
  mode: true,
3063
3083
  projectIds: true,
@@ -3070,7 +3090,7 @@ var ProjectSuggestionsResponse = z14.object({
3070
3090
  });
3071
3091
 
3072
3092
  // packages/protocol/dist/views.js
3073
- var SURFACE_OPEN_MS = 10 * 6e4;
3093
+ var TERMINAL_OPEN_MS = 10 * 6e4;
3074
3094
 
3075
3095
  // packages/protocol/dist/client-wire.js
3076
3096
  import { z as z15 } from "zod";
@@ -3091,15 +3111,22 @@ var SyncState = z15.object({
3091
3111
  devices: z15.array(Device),
3092
3112
  /** Tracked issues; absent from older coordinators. */
3093
3113
  issues: z15.array(TrackedIssue).default([]),
3094
- /** Terminal surfaces; absent from older coordinators. */
3095
- surfaces: z15.array(Surface).default([]),
3114
+ /** Terminals (herdr and tmux sessions); absent from older coordinators. */
3115
+ terminals: z15.array(Terminal).optional(),
3116
+ /** Deprecated: terminals as older coordinators send them (`terminals` replaces it). */
3117
+ surfaces: z15.array(Terminal).optional(),
3096
3118
  adapters: z15.record(z15.string(), z15.array(AdapterInfo)),
3097
3119
  dispatchPaused: z15.boolean()
3098
3120
  });
3099
3121
  var Presence = z15.object({
3100
3122
  foreground: z15.boolean(),
3101
3123
  interactedAt: z15.string().nullable(),
3102
- viewing: z15.object({ sessionId: z15.string() }).nullable()
3124
+ viewing: z15.object({ sessionId: z15.string() }).nullable(),
3125
+ /**
3126
+ * A herdr or tmux daemon reporting the session focused in its terminal (kept apart from the
3127
+ * device's own presence). Older coordinators ignore it.
3128
+ */
3129
+ terminalId: z15.string().min(1).max(200).optional()
3103
3130
  });
3104
3131
  var CLIENT_CAPABILITIES = ["adapter.slots.v1", "timeline.cards.v1"];
3105
3132
  var ClientToServer = z15.discriminatedUnion("type", [