agent-relay 1.0.21 → 1.1.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 (283) hide show
  1. package/dist/bridge/shadow-cli.d.ts +17 -0
  2. package/dist/bridge/shadow-cli.d.ts.map +1 -0
  3. package/dist/bridge/shadow-cli.js +75 -0
  4. package/dist/bridge/shadow-cli.js.map +1 -0
  5. package/dist/bridge/shadow-config.d.ts +87 -0
  6. package/dist/bridge/shadow-config.d.ts.map +1 -0
  7. package/dist/bridge/shadow-config.js +134 -0
  8. package/dist/bridge/shadow-config.js.map +1 -0
  9. package/dist/bridge/spawner.d.ts +15 -1
  10. package/dist/bridge/spawner.d.ts.map +1 -1
  11. package/dist/bridge/spawner.js +164 -4
  12. package/dist/bridge/spawner.js.map +1 -1
  13. package/dist/bridge/types.d.ts +55 -0
  14. package/dist/bridge/types.d.ts.map +1 -1
  15. package/dist/cli/index.js +796 -11
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/cloud/api/auth.d.ts +19 -0
  18. package/dist/cloud/api/auth.d.ts.map +1 -0
  19. package/dist/cloud/api/auth.js +216 -0
  20. package/dist/cloud/api/auth.js.map +1 -0
  21. package/dist/cloud/api/billing.d.ts +17 -0
  22. package/dist/cloud/api/billing.d.ts.map +1 -0
  23. package/dist/cloud/api/billing.js +353 -0
  24. package/dist/cloud/api/billing.js.map +1 -0
  25. package/dist/cloud/api/coordinators.d.ts +8 -0
  26. package/dist/cloud/api/coordinators.d.ts.map +1 -0
  27. package/dist/cloud/api/coordinators.js +347 -0
  28. package/dist/cloud/api/coordinators.js.map +1 -0
  29. package/dist/cloud/api/daemons.d.ts +12 -0
  30. package/dist/cloud/api/daemons.d.ts.map +1 -0
  31. package/dist/cloud/api/daemons.js +320 -0
  32. package/dist/cloud/api/daemons.js.map +1 -0
  33. package/dist/cloud/api/middleware/planLimits.d.ts +36 -0
  34. package/dist/cloud/api/middleware/planLimits.d.ts.map +1 -0
  35. package/dist/cloud/api/middleware/planLimits.js +164 -0
  36. package/dist/cloud/api/middleware/planLimits.js.map +1 -0
  37. package/dist/cloud/api/onboarding.d.ts +8 -0
  38. package/dist/cloud/api/onboarding.d.ts.map +1 -0
  39. package/dist/cloud/api/onboarding.js +407 -0
  40. package/dist/cloud/api/onboarding.js.map +1 -0
  41. package/dist/cloud/api/providers.d.ts +7 -0
  42. package/dist/cloud/api/providers.d.ts.map +1 -0
  43. package/dist/cloud/api/providers.js +435 -0
  44. package/dist/cloud/api/providers.js.map +1 -0
  45. package/dist/cloud/api/repos.d.ts +7 -0
  46. package/dist/cloud/api/repos.d.ts.map +1 -0
  47. package/dist/cloud/api/repos.js +314 -0
  48. package/dist/cloud/api/repos.js.map +1 -0
  49. package/dist/cloud/api/teams.d.ts +7 -0
  50. package/dist/cloud/api/teams.d.ts.map +1 -0
  51. package/dist/cloud/api/teams.js +279 -0
  52. package/dist/cloud/api/teams.js.map +1 -0
  53. package/dist/cloud/api/usage.d.ts +7 -0
  54. package/dist/cloud/api/usage.d.ts.map +1 -0
  55. package/dist/cloud/api/usage.js +98 -0
  56. package/dist/cloud/api/usage.js.map +1 -0
  57. package/dist/cloud/api/workspaces.d.ts +7 -0
  58. package/dist/cloud/api/workspaces.d.ts.map +1 -0
  59. package/dist/cloud/api/workspaces.js +510 -0
  60. package/dist/cloud/api/workspaces.js.map +1 -0
  61. package/dist/cloud/billing/index.d.ts +9 -0
  62. package/dist/cloud/billing/index.d.ts.map +1 -0
  63. package/dist/cloud/billing/index.js +9 -0
  64. package/dist/cloud/billing/index.js.map +1 -0
  65. package/dist/cloud/billing/plans.d.ts +39 -0
  66. package/dist/cloud/billing/plans.d.ts.map +1 -0
  67. package/dist/cloud/billing/plans.js +232 -0
  68. package/dist/cloud/billing/plans.js.map +1 -0
  69. package/dist/cloud/billing/service.d.ts +80 -0
  70. package/dist/cloud/billing/service.d.ts.map +1 -0
  71. package/dist/cloud/billing/service.js +388 -0
  72. package/dist/cloud/billing/service.js.map +1 -0
  73. package/dist/cloud/billing/types.d.ts +135 -0
  74. package/dist/cloud/billing/types.d.ts.map +1 -0
  75. package/dist/cloud/billing/types.js +7 -0
  76. package/dist/cloud/billing/types.js.map +1 -0
  77. package/dist/cloud/config.d.ts +59 -0
  78. package/dist/cloud/config.d.ts.map +1 -0
  79. package/dist/cloud/config.js +83 -0
  80. package/dist/cloud/config.js.map +1 -0
  81. package/dist/cloud/db/drizzle.d.ts +132 -0
  82. package/dist/cloud/db/drizzle.d.ts.map +1 -0
  83. package/dist/cloud/db/drizzle.js +613 -0
  84. package/dist/cloud/db/drizzle.js.map +1 -0
  85. package/dist/cloud/db/index.d.ts +30 -0
  86. package/dist/cloud/db/index.d.ts.map +1 -0
  87. package/dist/cloud/db/index.js +44 -0
  88. package/dist/cloud/db/index.js.map +1 -0
  89. package/dist/cloud/db/schema.d.ts +1792 -0
  90. package/dist/cloud/db/schema.d.ts.map +1 -0
  91. package/dist/cloud/db/schema.js +234 -0
  92. package/dist/cloud/db/schema.js.map +1 -0
  93. package/dist/cloud/index.d.ts +11 -0
  94. package/dist/cloud/index.d.ts.map +1 -0
  95. package/dist/cloud/index.js +37 -0
  96. package/dist/cloud/index.js.map +1 -0
  97. package/dist/cloud/provisioner/index.d.ts +51 -0
  98. package/dist/cloud/provisioner/index.d.ts.map +1 -0
  99. package/dist/cloud/provisioner/index.js +676 -0
  100. package/dist/cloud/provisioner/index.js.map +1 -0
  101. package/dist/cloud/server.d.ts +16 -0
  102. package/dist/cloud/server.d.ts.map +1 -0
  103. package/dist/cloud/server.js +190 -0
  104. package/dist/cloud/server.js.map +1 -0
  105. package/dist/cloud/services/coordinator.d.ts +62 -0
  106. package/dist/cloud/services/coordinator.d.ts.map +1 -0
  107. package/dist/cloud/services/coordinator.js +389 -0
  108. package/dist/cloud/services/coordinator.js.map +1 -0
  109. package/dist/cloud/services/planLimits.d.ts +110 -0
  110. package/dist/cloud/services/planLimits.d.ts.map +1 -0
  111. package/dist/cloud/services/planLimits.js +254 -0
  112. package/dist/cloud/services/planLimits.js.map +1 -0
  113. package/dist/cloud/vault/index.d.ts +76 -0
  114. package/dist/cloud/vault/index.d.ts.map +1 -0
  115. package/dist/cloud/vault/index.js +219 -0
  116. package/dist/cloud/vault/index.js.map +1 -0
  117. package/dist/daemon/agent-manager.d.ts +87 -0
  118. package/dist/daemon/agent-manager.d.ts.map +1 -0
  119. package/dist/daemon/agent-manager.js +412 -0
  120. package/dist/daemon/agent-manager.js.map +1 -0
  121. package/dist/daemon/agent-registry.d.ts +2 -0
  122. package/dist/daemon/agent-registry.d.ts.map +1 -1
  123. package/dist/daemon/agent-registry.js +3 -0
  124. package/dist/daemon/agent-registry.js.map +1 -1
  125. package/dist/daemon/api.d.ts +69 -0
  126. package/dist/daemon/api.d.ts.map +1 -0
  127. package/dist/daemon/api.js +425 -0
  128. package/dist/daemon/api.js.map +1 -0
  129. package/dist/daemon/cloud-sync.d.ts +101 -0
  130. package/dist/daemon/cloud-sync.d.ts.map +1 -0
  131. package/dist/daemon/cloud-sync.js +261 -0
  132. package/dist/daemon/cloud-sync.js.map +1 -0
  133. package/dist/daemon/index.d.ts +4 -0
  134. package/dist/daemon/index.d.ts.map +1 -1
  135. package/dist/daemon/index.js +6 -0
  136. package/dist/daemon/index.js.map +1 -1
  137. package/dist/daemon/orchestrator.d.ts +155 -0
  138. package/dist/daemon/orchestrator.d.ts.map +1 -0
  139. package/dist/daemon/orchestrator.js +736 -0
  140. package/dist/daemon/orchestrator.js.map +1 -0
  141. package/dist/daemon/router.d.ts +24 -0
  142. package/dist/daemon/router.d.ts.map +1 -1
  143. package/dist/daemon/router.js +71 -1
  144. package/dist/daemon/router.js.map +1 -1
  145. package/dist/daemon/server.d.ts +37 -0
  146. package/dist/daemon/server.d.ts.map +1 -1
  147. package/dist/daemon/server.js +191 -16
  148. package/dist/daemon/server.js.map +1 -1
  149. package/dist/daemon/types.d.ts +127 -0
  150. package/dist/daemon/types.d.ts.map +1 -0
  151. package/dist/daemon/types.js +6 -0
  152. package/dist/daemon/types.js.map +1 -0
  153. package/dist/daemon/workspace-manager.d.ts +75 -0
  154. package/dist/daemon/workspace-manager.d.ts.map +1 -0
  155. package/dist/daemon/workspace-manager.js +289 -0
  156. package/dist/daemon/workspace-manager.js.map +1 -0
  157. package/dist/dashboard/out/404.html +1 -1
  158. package/dist/dashboard/out/_next/static/chunks/693-7b3301d8f6bc5014.js +1 -0
  159. package/dist/dashboard/out/_next/static/chunks/713-f78477eb185f1f4d.js +1 -0
  160. package/dist/dashboard/out/_next/static/chunks/766-e53e1cfe39b0b5b5.js +1 -0
  161. package/dist/dashboard/out/_next/static/chunks/900-037c64bfd797fb2a.js +1 -0
  162. package/dist/dashboard/out/_next/static/chunks/app/app/page-e3d9e1f4466b9bae.js +1 -0
  163. package/dist/dashboard/out/_next/static/chunks/app/history/page-b6edd4dde8d08194.js +1 -0
  164. package/dist/dashboard/out/_next/static/chunks/app/layout-2433bb48965f4333.js +1 -0
  165. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-e68825a81db67ba1.js +1 -0
  166. package/dist/dashboard/out/_next/static/chunks/app/page-cc108bf68c8a657f.js +1 -0
  167. package/dist/dashboard/out/_next/static/chunks/app/pricing/page-d80e03a5297f95b6.js +1 -0
  168. package/dist/dashboard/out/_next/static/chunks/main-app-5d692157a8eb1fd9.js +1 -0
  169. package/dist/dashboard/out/_next/static/chunks/{main-e0a1f53fe0617a63.js → main-c2f423b9c9f4591b.js} +1 -1
  170. package/dist/dashboard/out/_next/static/chunks/{webpack-c81f7fd28659d64f.js → webpack-a5acc2831d094776.js} +1 -1
  171. package/dist/dashboard/out/_next/static/css/79b80143647a07d7.css +1 -0
  172. package/dist/dashboard/out/_next/static/css/8cf277370ad48cfe.css +1 -0
  173. package/dist/dashboard/out/alt-logos/agent-relay-logo-128.png +0 -0
  174. package/dist/dashboard/out/alt-logos/agent-relay-logo-256.png +0 -0
  175. package/dist/dashboard/out/alt-logos/agent-relay-logo-32.png +0 -0
  176. package/dist/dashboard/out/alt-logos/agent-relay-logo-512.png +0 -0
  177. package/dist/dashboard/out/alt-logos/agent-relay-logo-64.png +0 -0
  178. package/dist/dashboard/out/alt-logos/agent-relay-logo.svg +45 -0
  179. package/dist/dashboard/out/alt-logos/logo.svg +38 -0
  180. package/dist/dashboard/out/alt-logos/monogram-logo-128.png +0 -0
  181. package/dist/dashboard/out/alt-logos/monogram-logo-256.png +0 -0
  182. package/dist/dashboard/out/alt-logos/monogram-logo-32.png +0 -0
  183. package/dist/dashboard/out/alt-logos/monogram-logo-512.png +0 -0
  184. package/dist/dashboard/out/alt-logos/monogram-logo-64.png +0 -0
  185. package/dist/dashboard/out/alt-logos/monogram-logo.svg +38 -0
  186. package/dist/dashboard/out/app.html +14 -0
  187. package/dist/dashboard/out/app.txt +7 -0
  188. package/dist/dashboard/out/history.html +1 -0
  189. package/dist/dashboard/out/history.txt +7 -0
  190. package/dist/dashboard/out/index.html +1 -1
  191. package/dist/dashboard/out/index.txt +2 -2
  192. package/dist/dashboard/out/metrics.html +1 -515
  193. package/dist/dashboard/out/metrics.txt +2 -2
  194. package/dist/dashboard/out/pricing.html +13 -0
  195. package/dist/dashboard/out/pricing.txt +7 -0
  196. package/dist/dashboard-server/metrics.d.ts.map +1 -1
  197. package/dist/dashboard-server/metrics.js +3 -2
  198. package/dist/dashboard-server/metrics.js.map +1 -1
  199. package/dist/dashboard-server/server.d.ts.map +1 -1
  200. package/dist/dashboard-server/server.js +1279 -56
  201. package/dist/dashboard-server/server.js.map +1 -1
  202. package/dist/protocol/types.d.ts +10 -1
  203. package/dist/protocol/types.d.ts.map +1 -1
  204. package/dist/resiliency/context-persistence.d.ts +140 -0
  205. package/dist/resiliency/context-persistence.d.ts.map +1 -0
  206. package/dist/resiliency/context-persistence.js +397 -0
  207. package/dist/resiliency/context-persistence.js.map +1 -0
  208. package/dist/resiliency/health-monitor.d.ts +97 -0
  209. package/dist/resiliency/health-monitor.d.ts.map +1 -0
  210. package/dist/resiliency/health-monitor.js +291 -0
  211. package/dist/resiliency/health-monitor.js.map +1 -0
  212. package/dist/resiliency/index.d.ts +63 -0
  213. package/dist/resiliency/index.d.ts.map +1 -0
  214. package/dist/resiliency/index.js +63 -0
  215. package/dist/resiliency/index.js.map +1 -0
  216. package/dist/resiliency/logger.d.ts +114 -0
  217. package/dist/resiliency/logger.d.ts.map +1 -0
  218. package/dist/resiliency/logger.js +250 -0
  219. package/dist/resiliency/logger.js.map +1 -0
  220. package/dist/resiliency/metrics.d.ts +115 -0
  221. package/dist/resiliency/metrics.d.ts.map +1 -0
  222. package/dist/resiliency/metrics.js +239 -0
  223. package/dist/resiliency/metrics.js.map +1 -0
  224. package/dist/resiliency/provider-context.d.ts +100 -0
  225. package/dist/resiliency/provider-context.d.ts.map +1 -0
  226. package/dist/resiliency/provider-context.js +360 -0
  227. package/dist/resiliency/provider-context.js.map +1 -0
  228. package/dist/resiliency/supervisor.d.ts +109 -0
  229. package/dist/resiliency/supervisor.d.ts.map +1 -0
  230. package/dist/resiliency/supervisor.js +337 -0
  231. package/dist/resiliency/supervisor.js.map +1 -0
  232. package/dist/storage/adapter.d.ts +2 -0
  233. package/dist/storage/adapter.d.ts.map +1 -1
  234. package/dist/storage/adapter.js +12 -2
  235. package/dist/storage/adapter.js.map +1 -1
  236. package/dist/storage/sqlite-adapter.d.ts.map +1 -1
  237. package/dist/storage/sqlite-adapter.js +18 -14
  238. package/dist/storage/sqlite-adapter.js.map +1 -1
  239. package/dist/utils/index.d.ts +1 -0
  240. package/dist/utils/index.d.ts.map +1 -1
  241. package/dist/utils/index.js +1 -0
  242. package/dist/utils/index.js.map +1 -1
  243. package/dist/utils/logger.d.ts +40 -0
  244. package/dist/utils/logger.d.ts.map +1 -0
  245. package/dist/utils/logger.js +84 -0
  246. package/dist/utils/logger.js.map +1 -0
  247. package/dist/wrapper/client.d.ts +16 -1
  248. package/dist/wrapper/client.d.ts.map +1 -1
  249. package/dist/wrapper/client.js +32 -1
  250. package/dist/wrapper/client.js.map +1 -1
  251. package/dist/wrapper/parser.d.ts +3 -0
  252. package/dist/wrapper/parser.d.ts.map +1 -1
  253. package/dist/wrapper/parser.js +121 -18
  254. package/dist/wrapper/parser.js.map +1 -1
  255. package/dist/wrapper/pty-wrapper.d.ts +28 -1
  256. package/dist/wrapper/pty-wrapper.d.ts.map +1 -1
  257. package/dist/wrapper/pty-wrapper.js +166 -30
  258. package/dist/wrapper/pty-wrapper.js.map +1 -1
  259. package/dist/wrapper/tmux-wrapper.d.ts +5 -0
  260. package/dist/wrapper/tmux-wrapper.d.ts.map +1 -1
  261. package/dist/wrapper/tmux-wrapper.js +58 -18
  262. package/dist/wrapper/tmux-wrapper.js.map +1 -1
  263. package/docs/CLOUD-ARCHITECTURE.md +652 -0
  264. package/docs/CLOUD-ONBOARDING-DESIGN.md +1983 -0
  265. package/docs/TESTING_PRESENCE_FEATURES.md +327 -0
  266. package/docs/agent-relay-snippet.md +107 -4
  267. package/docs/guides/CLOUD.md +236 -0
  268. package/docs/guides/LOCAL.md +535 -0
  269. package/docs/guides/SELF-HOSTED.md +494 -0
  270. package/docs/proposals/shadow-as-subagent.md +765 -0
  271. package/docs/proposals/slack-bot-integration.md +1457 -0
  272. package/package.json +33 -4
  273. package/dist/dashboard/out/_next/static/chunks/app/layout-c9d8c5d95e48c6bf.js +0 -1
  274. package/dist/dashboard/out/_next/static/chunks/app/metrics/page-8aa9936bc6c771ab.js +0 -1
  275. package/dist/dashboard/out/_next/static/chunks/app/page-49055e5d2b5e34ec.js +0 -1
  276. package/dist/dashboard/out/_next/static/chunks/main-app-bae2e535de00de50.js +0 -1
  277. package/dist/dashboard/out/_next/static/css/50ed6996e3df7bdd.css +0 -1
  278. /package/dist/dashboard/out/_next/static/{gZXwjIKGDKJ0hiTH-HMeJ → 6HHWb2ZmnJ4OSm0zUP7h4}/_buildManifest.js +0 -0
  279. /package/dist/dashboard/out/_next/static/{gZXwjIKGDKJ0hiTH-HMeJ → 6HHWb2ZmnJ4OSm0zUP7h4}/_ssgManifest.js +0 -0
  280. /package/dist/dashboard/out/_next/static/chunks/{117-3bef7b19f3e60751.js → 117-b2cd8d6485aacf2b.js} +0 -0
  281. /package/dist/dashboard/out/_next/static/chunks/{648-6cf686106c891ad3.js → 648-8f3f26864ce515e5.js} +0 -0
  282. /package/dist/dashboard/out/_next/static/chunks/app/_not-found/{page-8ff6572bc7c9bc61.js → page-0b990dbb71d72a98.js} +0 -0
  283. /package/dist/dashboard/out/_next/static/chunks/{fd9d1056-26bd8d656b496dba.js → fd9d1056-bf46c09eb57e019c.js} +0 -0
@@ -0,0 +1,765 @@
1
+ # Proposal: Shadow Agents as Subagents
2
+
3
+ ## Summary
4
+
5
+ Replace the current shadow agent implementation (separate full agent processes) with Claude Code's native Task tool subagent model. This reduces resource usage and provides tighter integration, but limits shadow functionality to Claude Code agents.
6
+
7
+ ## Current Architecture
8
+
9
+ ```
10
+ ┌─────────────────┐ ┌─────────────────┐
11
+ │ Primary Agent │ │ Shadow Agent │
12
+ │ (Full Process) │ │ (Full Process) │
13
+ │ │ │ │
14
+ │ - PTY wrapper │ │ - PTY wrapper │
15
+ │ - Relay client │ │ - Relay client │
16
+ │ - Full CLI │ │ - Full CLI │
17
+ └────────┬────────┘ └────────┬────────┘
18
+ │ │
19
+ └───────────┬───────────┘
20
+
21
+ ┌──────▼──────┐
22
+ │ Daemon │
23
+ │ Router │
24
+ │ │
25
+ │ shadowsByPrimary Map │
26
+ │ Message copying │
27
+ │ Trigger emission │
28
+ └─────────────┘
29
+ ```
30
+
31
+ **Problems:**
32
+ 1. Two full agent processes = 2x resource usage
33
+ 2. Shadow spawns as separate process with 3s delay
34
+ 3. Complex message copying through daemon router
35
+ 4. Shadow needs full relay client, PTY wrapper, etc.
36
+
37
+ ## Proposed Architecture
38
+
39
+ ```
40
+ ┌─────────────────────────────────────────┐
41
+ │ Primary Agent (Claude Code) │
42
+ │ │
43
+ │ ┌─────────────────────────────────────┐ │
44
+ │ │ Task Tool Subagent │ │
45
+ │ │ (Shadow Role) │ │
46
+ │ │ │ │
47
+ │ │ - Shares parent context │ │
48
+ │ │ - No separate process │ │
49
+ │ │ - Returns results to parent │ │
50
+ │ └─────────────────────────────────────┘ │
51
+ │ │
52
+ │ - Single PTY wrapper │
53
+ │ - Single relay client │
54
+ └──────────────────────────────────────────┘
55
+ ```
56
+
57
+ **Benefits:**
58
+ 1. Single process, ~50% resource reduction
59
+ 2. Instant subagent spawn (no 3s delay)
60
+ 3. Direct context sharing (no message copying)
61
+ 4. Simpler architecture
62
+
63
+ ## Shadow CLI Selection Logic
64
+
65
+ The shadow approach depends on what the **primary agent** is running:
66
+
67
+ ### Decision Tree
68
+
69
+ ```
70
+ Primary Agent CLI?
71
+
72
+ ├─ Claude Code (`claude`)
73
+ │ └─ Shadow runs as: Claude subagent (Task tool)
74
+
75
+ ├─ OpenCode (`codex`)
76
+ │ └─ Shadow runs as: OpenCode subagent (mode: subagent)
77
+
78
+ └─ Other (gemini, custom, etc.)
79
+ └─ Shadow runs as: External process using best available CLI
80
+
81
+ ├─ Check: Is Claude authenticated?
82
+ │ └─ Yes → Spawn shadow using `claude`
83
+
84
+ └─ Check: Is OpenCode authenticated?
85
+ └─ Yes → Spawn shadow using `codex`
86
+ └─ No → Error: No shadow CLI available
87
+ ```
88
+
89
+ ### Implementation
90
+
91
+ ```typescript
92
+ function selectShadowCli(primaryCli: string): { cli: string; mode: 'subagent' | 'process' } {
93
+ // Native subagent support
94
+ if (primaryCli === 'claude') {
95
+ return { cli: 'claude', mode: 'subagent' };
96
+ }
97
+ if (primaryCli === 'codex' || primaryCli === 'opencode') {
98
+ return { cli: primaryCli, mode: 'subagent' };
99
+ }
100
+
101
+ // Fallback: spawn external shadow process
102
+ // Check authenticated CLIs in preference order
103
+ if (isAuthenticated('claude')) {
104
+ return { cli: 'claude', mode: 'process' };
105
+ }
106
+ if (isAuthenticated('codex')) {
107
+ return { cli: 'codex', mode: 'process' };
108
+ }
109
+
110
+ throw new Error('No shadow-capable CLI authenticated. Install Claude or OpenCode.');
111
+ }
112
+ ```
113
+
114
+ ### Behavior by Mode
115
+
116
+ | Mode | Description | Resource Usage | Latency |
117
+ |------|-------------|----------------|---------|
118
+ | `subagent` | Shadow runs inside primary's context via Task tool | Low (shared process) | ~1s |
119
+ | `process` | Shadow spawns as separate agent process | High (new process) | ~3-5s |
120
+
121
+ ### Authentication Check
122
+
123
+ Need to detect which CLIs are available and authenticated:
124
+
125
+ ```typescript
126
+ async function isAuthenticated(cli: 'claude' | 'codex'): Promise<boolean> {
127
+ try {
128
+ if (cli === 'claude') {
129
+ // Check for Claude API key or OAuth
130
+ const result = await exec('claude --version');
131
+ return result.exitCode === 0;
132
+ }
133
+ if (cli === 'codex') {
134
+ // Check for OpenCode auth
135
+ const result = await exec('codex --version');
136
+ return result.exitCode === 0;
137
+ }
138
+ } catch {
139
+ return false;
140
+ }
141
+ return false;
142
+ }
143
+ ```
144
+
145
+ ### Example Scenarios
146
+
147
+ **Scenario 1: Claude primary agent**
148
+ ```
149
+ Primary: claude (Lead agent)
150
+ Shadow: shadow-reviewer
151
+ → Mode: subagent
152
+ → Shadow invoked via Task tool inside Lead's context
153
+ → No new process spawned
154
+ ```
155
+
156
+ **Scenario 2: OpenCode primary agent**
157
+ ```
158
+ Primary: codex (Implementer)
159
+ Shadow: shadow-auditor
160
+ → Mode: subagent
161
+ → Shadow invoked as OpenCode subagent
162
+ → No new process spawned
163
+ ```
164
+
165
+ **Scenario 3: Custom/Gemini primary agent**
166
+ ```
167
+ Primary: gemini (Analyst)
168
+ Shadow: shadow-reviewer
169
+ → Mode: process (gemini doesn't support subagents)
170
+ → Check: Claude authenticated? Yes
171
+ → Spawn separate `claude` process running shadow-reviewer agent
172
+ → Shadow monitors via relay message copying (current architecture)
173
+ ```
174
+
175
+ **Scenario 4: No shadow CLI available**
176
+ ```
177
+ Primary: custom-agent
178
+ Shadow: shadow-reviewer
179
+ → Check: Claude authenticated? No
180
+ → Check: OpenCode authenticated? No
181
+ → Error: "Shadow agents require Claude or OpenCode. Please authenticate one."
182
+ ```
183
+
184
+ ## Implementation Plan
185
+
186
+ ### Phase 1: Shadow Agent Definition
187
+
188
+ Create shadow agent files in `.claude/agents/` that can be spawned via Task tool:
189
+
190
+ ```markdown
191
+ # .claude/agents/shadow-reviewer.md
192
+ ---
193
+ name: shadow-reviewer
194
+ description: Reviews code changes for quality and security issues
195
+ model: haiku
196
+ agentType: agent
197
+ ---
198
+
199
+ # Shadow Reviewer
200
+
201
+ You are a shadow agent monitoring another agent's work. You receive periodic
202
+ updates about their progress and provide review feedback.
203
+
204
+ ## Triggers
205
+
206
+ You will be invoked when:
207
+ - **CODE_WRITTEN**: Code has been written or modified
208
+ - **REVIEW_REQUEST**: Explicit review requested
209
+ - **SESSION_END**: Work session is ending
210
+
211
+ ## Review Process
212
+
213
+ 1. Analyze the changes provided in your context
214
+ 2. Check for:
215
+ - Security vulnerabilities
216
+ - Code quality issues
217
+ - Missing error handling
218
+ - Test coverage gaps
219
+ 3. Provide concise, actionable feedback
220
+ 4. Flag blocking issues vs suggestions
221
+
222
+ ## Output Format
223
+
224
+ **Review: [PASS/CONCERNS/BLOCK]**
225
+
226
+ [Your feedback here]
227
+ ```
228
+
229
+ ### Phase 2: Shadow Invocation Hook
230
+
231
+ Add a hook or snippet that primary agents include to invoke shadows at trigger points:
232
+
233
+ ```markdown
234
+ # .claude/snippets/shadow-integration.md
235
+
236
+ ## Shadow Integration
237
+
238
+ When configured with a shadow, invoke your shadow agent at these points:
239
+
240
+ ### On Code Written
241
+ After writing significant code changes, invoke shadow:
242
+ \`\`\`
243
+ Use the Task tool with subagent_type="shadow-reviewer" to review your recent changes.
244
+ Provide context: files changed, purpose of changes, any concerns.
245
+ \`\`\`
246
+
247
+ ### On Session End
248
+ Before completing a session, get shadow sign-off:
249
+ \`\`\`
250
+ Use the Task tool with subagent_type="shadow-reviewer" for final review.
251
+ Summarize all changes made this session.
252
+ \`\`\`
253
+
254
+ ### On Explicit Request
255
+ When asked for review or when uncertain:
256
+ \`\`\`
257
+ Use the Task tool with subagent_type="shadow-reviewer" for guidance.
258
+ \`\`\`
259
+ ```
260
+
261
+ ### Phase 3: Automatic Shadow Configuration
262
+
263
+ Update agent frontmatter to declare shadow requirements:
264
+
265
+ ```yaml
266
+ ---
267
+ name: lead-developer
268
+ description: Lead developer agent
269
+ shadow: shadow-reviewer # Auto-invoke this shadow
270
+ shadowTriggers:
271
+ - CODE_WRITTEN
272
+ - SESSION_END
273
+ ---
274
+ ```
275
+
276
+ When an agent with `shadow` config runs:
277
+ 1. Shadow agent definition loaded into context
278
+ 2. Primary agent instructed to invoke shadow at trigger points
279
+ 3. Shadow runs as Task subagent, returns to primary
280
+ 4. Primary incorporates feedback
281
+
282
+ ### Phase 4: Dashboard Integration
283
+
284
+ Update SpawnModal to configure shadow-as-subagent:
285
+
286
+ ```typescript
287
+ interface SpawnConfig {
288
+ name: string;
289
+ command: string;
290
+ // New shadow-as-subagent fields
291
+ shadowAgent?: string; // Name of shadow agent to use
292
+ shadowTriggers?: SpeakOnTrigger[];
293
+ shadowModel?: 'haiku' | 'sonnet' | 'opus';
294
+ }
295
+ ```
296
+
297
+ Dashboard spawns single agent with shadow config injected into its context.
298
+
299
+ ## API Changes
300
+
301
+ ### Remove
302
+ - `shadowOf` field from SpawnAgentRequest (no separate shadow process)
303
+ - `shadowSpeakOn` field from SpawnAgentRequest
304
+ - Shadow binding protocol (SHADOW_BIND, SHADOW_UNBIND)
305
+ - Router shadow copying logic
306
+
307
+ ### Add
308
+ - `shadowAgent` field - which agent definition to use as shadow
309
+ - `shadowTriggers` field - when shadow should be invoked
310
+ - `shadowModel` field - model for shadow subagent (default: haiku for cost)
311
+
312
+ ### Keep (for backwards compat)
313
+ - Existing shadow process model as fallback for non-Claude agents
314
+ - Config file shadow definitions
315
+
316
+ ## Migration Path
317
+
318
+ 1. **Deprecate** process-based shadows for Claude agents
319
+ 2. **Add** subagent shadow support
320
+ 3. **Default** new Claude agent shadows to subagent model
321
+ 4. **Keep** process model for non-Claude agents
322
+ 5. **Remove** process model for Claude after validation period
323
+
324
+ ## File Changes
325
+
326
+ | File | Change |
327
+ |------|--------|
328
+ | `src/bridge/shadow-cli.ts` | **NEW** - Shadow CLI selection logic (`selectShadowCli`, `isAuthenticated`) |
329
+ | `src/bridge/spawner.ts` | Update to use `selectShadowCli`, handle subagent vs process modes |
330
+ | `src/dashboard/types/index.ts` | Add `shadowAgent`, `shadowTriggers`, `shadowMode` fields |
331
+ | `src/dashboard/react-components/SpawnModal.tsx` | Update UI - show shadow mode (subagent/process) based on primary CLI |
332
+ | `.claude/agents/shadow-*.md` | Create Claude Code shadow agent definitions |
333
+ | `.opencode/agent/shadow-*.md` | Create OpenCode shadow agent definitions |
334
+ | `src/cli/index.ts` | Update `--shadow` handling to use new selection logic |
335
+ | `CLAUDE.md` or agent snippets | Add shadow invocation instructions for subagent mode |
336
+
337
+ ## Shadow Agent Profiles
338
+
339
+ ### Claude Code Agents (`.claude/agents/`)
340
+
341
+ #### shadow-reviewer.md
342
+ ```markdown
343
+ ---
344
+ name: shadow-reviewer
345
+ description: Reviews code changes for quality, security, and best practices. Use as a shadow to monitor and review another agent's code output.
346
+ model: haiku
347
+ agentType: agent
348
+ shadowTriggers:
349
+ - CODE_WRITTEN
350
+ - REVIEW_REQUEST
351
+ - EXPLICIT_ASK
352
+ ---
353
+
354
+ # 🔍 Shadow Reviewer
355
+
356
+ You are a shadow reviewer agent. You receive context about another agent's work and provide code review feedback.
357
+
358
+ ## Your Role
359
+
360
+ - **Observe**: You receive summaries of code changes made by the primary agent
361
+ - **Review**: Analyze for quality, security, and best practices
362
+ - **Advise**: Provide actionable feedback, not implementation
363
+
364
+ ## Review Checklist
365
+
366
+ When reviewing code changes:
367
+
368
+ 1. **Security**
369
+ - Input validation present?
370
+ - No hardcoded secrets?
371
+ - SQL injection / XSS risks?
372
+ - Authentication/authorization correct?
373
+
374
+ 2. **Quality**
375
+ - Clear naming conventions?
376
+ - Appropriate error handling?
377
+ - No obvious bugs?
378
+ - Follows existing patterns?
379
+
380
+ 3. **Maintainability**
381
+ - Reasonable complexity?
382
+ - Comments where needed?
383
+ - Tests included?
384
+
385
+ ## Output Format
386
+
387
+ **Review: [PASS | CONCERNS | BLOCK]**
388
+
389
+ **Summary:** [One sentence]
390
+
391
+ **Issues Found:**
392
+ - [Issue 1]: [Severity: Low/Medium/High] - [Description]
393
+ - [Issue 2]: ...
394
+
395
+ **Suggestions:**
396
+ - [Optional improvements]
397
+
398
+ ## Response Guidelines
399
+
400
+ - Be concise - primary agent is working, don't slow them down
401
+ - Focus on blocking issues first
402
+ - PASS if code is acceptable (doesn't need to be perfect)
403
+ - CONCERNS if there are non-blocking issues to address
404
+ - BLOCK only for security vulnerabilities or critical bugs
405
+ ```
406
+
407
+ #### shadow-auditor.md
408
+ ```markdown
409
+ ---
410
+ name: shadow-auditor
411
+ description: Audits agent decisions and session outcomes for compliance and quality. Use as a shadow for end-of-session review.
412
+ model: haiku
413
+ agentType: agent
414
+ shadowTriggers:
415
+ - SESSION_END
416
+ - EXPLICIT_ASK
417
+ ---
418
+
419
+ # 📋 Shadow Auditor
420
+
421
+ You are a shadow auditor agent. You review the decisions and outcomes of another agent's work session.
422
+
423
+ ## Your Role
424
+
425
+ - **Audit**: Review decisions made during the session
426
+ - **Verify**: Check that requirements were met
427
+ - **Report**: Provide session summary and recommendations
428
+
429
+ ## Audit Criteria
430
+
431
+ 1. **Requirement Fulfillment**
432
+ - Did the agent complete the requested task?
433
+ - Were all acceptance criteria met?
434
+ - Any scope creep or missed requirements?
435
+
436
+ 2. **Decision Quality**
437
+ - Were technical decisions reasonable?
438
+ - Any risky shortcuts taken?
439
+ - Appropriate use of tools?
440
+
441
+ 3. **Process Adherence**
442
+ - Followed project conventions?
443
+ - Updated tracking (beads/issues)?
444
+ - Communicated appropriately?
445
+
446
+ ## Output Format
447
+
448
+ **Audit: [APPROVED | NEEDS_REVIEW | REJECTED]**
449
+
450
+ **Session Summary:**
451
+ - Task: [What was requested]
452
+ - Outcome: [What was delivered]
453
+ - Duration: [If known]
454
+
455
+ **Findings:**
456
+ - [Finding 1]: [Category] - [Description]
457
+
458
+ **Recommendations:**
459
+ - [For future sessions]
460
+
461
+ ## Response Guidelines
462
+
463
+ - Review holistically, not line-by-line
464
+ - APPROVED for successful sessions
465
+ - NEEDS_REVIEW if follow-up required
466
+ - REJECTED only for critical failures
467
+ ```
468
+
469
+ #### shadow-active.md
470
+ ```markdown
471
+ ---
472
+ name: shadow-active
473
+ description: Actively monitors all agent activity and provides real-time guidance. Use as a shadow for high-stakes or learning scenarios.
474
+ model: sonnet
475
+ agentType: agent
476
+ shadowTriggers:
477
+ - ALL_MESSAGES
478
+ ---
479
+
480
+ # 👁️ Shadow Active Monitor
481
+
482
+ You are an active shadow agent. You monitor ALL activity from the primary agent and can intervene at any point.
483
+
484
+ ## Your Role
485
+
486
+ - **Monitor**: See every message and action
487
+ - **Guide**: Provide real-time suggestions
488
+ - **Intervene**: Flag issues before they become problems
489
+
490
+ ## When to Speak
491
+
492
+ Speak up when you observe:
493
+ - Security risk about to be introduced
494
+ - Significant architectural mistake
495
+ - Misunderstanding of requirements
496
+ - About to modify wrong files
497
+ - Potential data loss operation
498
+
499
+ Stay silent when:
500
+ - Work is progressing normally
501
+ - Minor style differences
502
+ - Decisions within acceptable range
503
+
504
+ ## Output Format
505
+
506
+ **[GUIDANCE | WARNING | STOP]**
507
+
508
+ [Your message - keep it brief]
509
+
510
+ ## Response Guidelines
511
+
512
+ - Don't micromanage - trust the primary agent
513
+ - Only intervene when value exceeds interruption cost
514
+ - GUIDANCE for suggestions
515
+ - WARNING for concerning patterns
516
+ - STOP for imminent problems
517
+ ```
518
+
519
+ ---
520
+
521
+ ### OpenCode Agents (`.opencode/agent/`)
522
+
523
+ #### shadow-reviewer.md
524
+ ```markdown
525
+ ---
526
+ description: Reviews code changes for quality, security, and best practices. Use as a shadow subagent.
527
+ mode: subagent
528
+ model: anthropic/claude-3-5-haiku-20241022
529
+ temperature: 0.1
530
+ maxSteps: 3
531
+ tools:
532
+ read: true
533
+ write: false
534
+ bash: false
535
+ edit: false
536
+ permission:
537
+ edit: deny
538
+ bash: deny
539
+ ---
540
+
541
+ You are a shadow reviewer agent. You receive context about code changes and provide review feedback.
542
+
543
+ ## Review Checklist
544
+
545
+ 1. **Security**: Input validation, no secrets, injection risks, auth
546
+ 2. **Quality**: Naming, error handling, bugs, patterns
547
+ 3. **Maintainability**: Complexity, comments, tests
548
+
549
+ ## Output Format
550
+
551
+ **Review: [PASS | CONCERNS | BLOCK]**
552
+
553
+ **Summary:** [One sentence]
554
+
555
+ **Issues:** (if any)
556
+ - [Severity]: [Description]
557
+
558
+ Be concise. PASS if acceptable. BLOCK only for critical issues.
559
+ ```
560
+
561
+ #### shadow-auditor.md
562
+ ```markdown
563
+ ---
564
+ description: Audits session decisions and outcomes for compliance. Use as end-of-session shadow.
565
+ mode: subagent
566
+ model: anthropic/claude-3-5-haiku-20241022
567
+ temperature: 0.1
568
+ maxSteps: 2
569
+ tools:
570
+ read: true
571
+ write: false
572
+ bash: false
573
+ permission:
574
+ edit: deny
575
+ ---
576
+
577
+ You are a shadow auditor. Review the session's decisions and outcomes.
578
+
579
+ ## Audit Criteria
580
+
581
+ 1. **Requirements**: Task complete? Criteria met?
582
+ 2. **Decisions**: Reasonable? Any shortcuts?
583
+ 3. **Process**: Conventions followed? Tracking updated?
584
+
585
+ ## Output Format
586
+
587
+ **Audit: [APPROVED | NEEDS_REVIEW | REJECTED]**
588
+
589
+ **Summary:** [Task requested → Outcome delivered]
590
+
591
+ **Findings:** (if any)
592
+
593
+ **Recommendations:** (if any)
594
+ ```
595
+
596
+ #### shadow-active.md
597
+ ```markdown
598
+ ---
599
+ description: Active real-time monitor for high-stakes scenarios. Sees all messages.
600
+ mode: subagent
601
+ model: anthropic/claude-sonnet-4-20250514
602
+ temperature: 0.2
603
+ maxSteps: 5
604
+ tools:
605
+ read: true
606
+ write: false
607
+ bash: false
608
+ permission:
609
+ edit: deny
610
+ ---
611
+
612
+ You are an active shadow monitor. You see all activity and can intervene.
613
+
614
+ ## When to Speak
615
+
616
+ SPEAK when you see:
617
+ - Security risk imminent
618
+ - Architectural mistake
619
+ - Requirements misunderstanding
620
+ - Wrong files about to be modified
621
+
622
+ STAY SILENT when:
623
+ - Work progressing normally
624
+ - Minor style differences
625
+ - Acceptable decisions
626
+
627
+ ## Output Format
628
+
629
+ **[GUIDANCE | WARNING | STOP]**: [Brief message]
630
+
631
+ Don't micromanage. Only intervene when value > interruption cost.
632
+ ```
633
+
634
+ ---
635
+
636
+ ### PRPM Package Structure
637
+
638
+ Distribute shadow agents via prpm for easy installation:
639
+
640
+ ```
641
+ @agent-relay/shadow-agents/
642
+ ├── prpm.json
643
+ ├── claude/
644
+ │ └── agents/
645
+ │ ├── shadow-reviewer.md
646
+ │ ├── shadow-auditor.md
647
+ │ └── shadow-active.md
648
+ └── opencode/
649
+ └── agent/
650
+ ├── shadow-reviewer.md
651
+ ├── shadow-auditor.md
652
+ └── shadow-active.md
653
+ ```
654
+
655
+ #### prpm.json
656
+ ```json
657
+ {
658
+ "name": "@agent-relay/shadow-agents",
659
+ "version": "1.0.0",
660
+ "description": "Shadow agent profiles for code review, auditing, and active monitoring",
661
+ "targets": {
662
+ "claude": {
663
+ "files": {
664
+ "claude/agents/*.md": ".claude/agents/"
665
+ }
666
+ },
667
+ "opencode": {
668
+ "files": {
669
+ "opencode/agent/*.md": ".opencode/agent/"
670
+ }
671
+ }
672
+ },
673
+ "tags": ["shadow", "review", "audit", "agents"],
674
+ "activation": "eager"
675
+ }
676
+ ```
677
+
678
+ #### Installation
679
+ ```bash
680
+ # Install for Claude Code
681
+ prpm install @agent-relay/shadow-agents --target claude
682
+
683
+ # Install for OpenCode
684
+ prpm install @agent-relay/shadow-agents --target opencode
685
+
686
+ # Install for both
687
+ prpm install @agent-relay/shadow-agents
688
+ ```
689
+
690
+ #### Usage After Installation
691
+
692
+ **Claude Code:**
693
+ ```bash
694
+ # Primary agent with shadow reviewer
695
+ claude --shadow shadow-reviewer --shadow-role reviewer
696
+
697
+ # Or via Task tool in agent prompt
698
+ "Use Task with subagent_type='shadow-reviewer' to review changes"
699
+ ```
700
+
701
+ **OpenCode:**
702
+ ```bash
703
+ # Configure in opencode.json
704
+ {
705
+ "agent": {
706
+ "shadow-reviewer": {
707
+ "mode": "subagent"
708
+ }
709
+ }
710
+ }
711
+
712
+ # Then invoke via agent command
713
+ opencode agent shadow-reviewer "Review these changes: ..."
714
+ ```
715
+
716
+ ## Cost Considerations
717
+
718
+ | Model | Shadow Invocations | Est. Cost/Session |
719
+ |-------|-------------------|-------------------|
720
+ | Haiku | 5-10 per session | ~$0.05-0.10 |
721
+ | Sonnet | 5-10 per session | ~$0.50-1.00 |
722
+ | Opus | 5-10 per session | ~$2.50-5.00 |
723
+
724
+ **Recommendation:** Default to Haiku for shadows unless review quality requires higher model.
725
+
726
+ ## Open Questions
727
+
728
+ 1. **Trigger Mechanism**: How does primary know when to invoke shadow?
729
+ - Option A: Explicit instruction in agent prompt (simplest)
730
+ - Option B: Hook that monitors output patterns (automatic)
731
+ - Option C: Periodic invocation (every N tool calls)
732
+ - **Recommendation**: Start with Option A, iterate to B
733
+
734
+ 2. **Context Passing**: What context does shadow receive?
735
+ - Option A: Full conversation history (expensive, thorough)
736
+ - Option B: Recent changes only (efficient, may miss context)
737
+ - Option C: Configurable context window (flexible)
738
+ - **Recommendation**: Option C with sensible defaults
739
+
740
+ 3. **Feedback Integration**: How does primary handle shadow feedback?
741
+ - Option A: Shadow feedback shown to user only
742
+ - Option B: Primary must address feedback before continuing (blocking)
743
+ - Option C: Advisory only, primary decides (non-blocking)
744
+ - **Recommendation**: Option C for reviewer, Option B for BLOCK verdicts
745
+
746
+ 4. **Process Mode Communication**: For non-Claude/OpenCode primaries, how does shadow receive context?
747
+ - Option A: Relay message copying (current architecture)
748
+ - Option B: Periodic context dump to shadow
749
+ - Option C: Shadow polls primary's session state
750
+ - **Recommendation**: Option A (already implemented)
751
+
752
+ ## Success Metrics
753
+
754
+ - [ ] Shadow invocation adds < 5s latency
755
+ - [ ] Resource usage reduced by 40%+
756
+ - [ ] Shadow feedback quality maintained
757
+ - [ ] No breaking changes for existing users
758
+ - [ ] Clear migration path documented
759
+
760
+ ## Timeline
761
+
762
+ - **Week 1**: Create shadow agent definitions, test Task tool invocation
763
+ - **Week 2**: Update SpawnModal UI, implement context injection
764
+ - **Week 3**: Add trigger detection, integrate feedback loop
765
+ - **Week 4**: Testing, documentation, migration guide