@ours.network/fleet 1.2.0-nightly.5 → 1.2.0-nightly.51

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 (330) hide show
  1. package/README.md +263 -53
  2. package/dist/account-origin.d.ts +2 -0
  3. package/dist/account-origin.js +6 -0
  4. package/dist/agent-ours/bridge.js +9 -0
  5. package/dist/agent-ours/correspondence.d.ts +10 -0
  6. package/dist/agent-ours/correspondence.js +1 -0
  7. package/dist/agent-ours/harness.js +8 -0
  8. package/dist/agent-ours/runtime.d.ts +6 -0
  9. package/dist/agent-ours/runtime.js +36 -0
  10. package/dist/agent-ours/service.js +33 -13
  11. package/dist/application/codex-models.d.ts +15 -0
  12. package/dist/application/codex-models.js +56 -0
  13. package/dist/application/conversation-history.d.ts +25 -0
  14. package/dist/application/conversation-history.js +189 -0
  15. package/dist/application/fleet-query-service.d.ts +1 -1
  16. package/dist/application/fleet-query-service.js +2 -2
  17. package/dist/application/legacy-supervisor-identity.d.ts +7 -0
  18. package/dist/application/legacy-supervisor-identity.js +43 -0
  19. package/dist/application/model-catalog.d.ts +1 -1
  20. package/dist/application/model-catalog.js +5 -2
  21. package/dist/application/preset-provenance.d.ts +19 -0
  22. package/dist/application/preset-provenance.js +59 -0
  23. package/dist/application/role-creation-service.js +1 -1
  24. package/dist/application/role-removal-service.js +2 -0
  25. package/dist/application/role-repository.js +2 -2
  26. package/dist/application/room-layout-definitions.d.ts +45 -0
  27. package/dist/application/room-layout-definitions.js +130 -0
  28. package/dist/application/session-control.d.ts +30 -0
  29. package/dist/application/session-control.js +72 -3
  30. package/dist/application/supervisor-ours-tools.d.ts +159 -0
  31. package/dist/application/supervisor-ours-tools.js +113 -0
  32. package/dist/application/task-layouts.d.ts +91 -0
  33. package/dist/application/task-layouts.js +249 -0
  34. package/dist/application/task-room-service.d.ts +99 -3
  35. package/dist/application/task-room-service.js +296 -31
  36. package/dist/atomic-file.d.ts +5 -0
  37. package/dist/atomic-file.js +62 -1
  38. package/dist/briefing.d.ts +2 -0
  39. package/dist/briefing.js +8 -1
  40. package/dist/build-info.json +7 -4
  41. package/dist/capabilities.d.ts +6 -1
  42. package/dist/capabilities.js +8 -0
  43. package/dist/cli.js +376 -34
  44. package/dist/client-profile.d.ts +5 -17
  45. package/dist/client-profile.js +4 -127
  46. package/dist/config.d.ts +28 -0
  47. package/dist/config.js +41 -6
  48. package/dist/creation.js +2 -2
  49. package/dist/daemon-recovery.d.ts +1 -8
  50. package/dist/daemon-recovery.js +8 -113
  51. package/dist/docs.d.ts +3 -3
  52. package/dist/docs.js +126 -22
  53. package/dist/doctor.d.ts +1 -1
  54. package/dist/doctor.js +55 -60
  55. package/dist/erased-resources.d.ts +9 -0
  56. package/dist/erased-resources.js +87 -0
  57. package/dist/fleet-command-audit.d.ts +7 -0
  58. package/dist/fleet-command-audit.js +26 -9
  59. package/dist/harness/claude-code.js +9 -1
  60. package/dist/harness/claude-runtime.d.ts +12 -0
  61. package/dist/harness/claude-runtime.js +43 -0
  62. package/dist/harness/codex-app-server-proxy.d.ts +4 -1
  63. package/dist/harness/codex-app-server-proxy.js +41 -5
  64. package/dist/harness/codex-reasoning.d.ts +5 -0
  65. package/dist/harness/codex-reasoning.js +12 -0
  66. package/dist/harness/codex-runtime.d.ts +11 -1
  67. package/dist/harness/codex-runtime.js +31 -4
  68. package/dist/harness/codex.d.ts +3 -2
  69. package/dist/harness/codex.js +20 -11
  70. package/dist/init-wizard.d.ts +2 -0
  71. package/dist/init-wizard.js +38 -19
  72. package/dist/isolation/policy.js +2 -0
  73. package/dist/isolation/types.d.ts +5 -0
  74. package/dist/managed-cli.d.ts +253 -0
  75. package/dist/managed-cli.js +923 -0
  76. package/dist/minimal-setup.d.ts +2 -0
  77. package/dist/minimal-setup.js +44 -0
  78. package/dist/monitor.d.ts +1 -34
  79. package/dist/monitor.js +24 -151
  80. package/dist/notifications/fleet-producer.d.ts +19 -0
  81. package/dist/notifications/fleet-producer.js +208 -0
  82. package/dist/notifications/outbox.d.ts +46 -0
  83. package/dist/notifications/outbox.js +158 -0
  84. package/dist/notifications/target-cleanup.d.ts +8 -0
  85. package/dist/notifications/target-cleanup.js +41 -0
  86. package/dist/ops.js +5 -1
  87. package/dist/owner-channel/channel.d.ts +3 -0
  88. package/dist/owner-channel/channel.js +34 -6
  89. package/dist/owner-channel/commands.d.ts +4 -0
  90. package/dist/owner-channel/commands.js +8 -0
  91. package/dist/owner-channel/lifecycle-outbox.js +4 -3
  92. package/dist/owner-channel/ours-client.js +2 -17
  93. package/dist/paths.d.ts +2 -0
  94. package/dist/paths.js +2 -0
  95. package/dist/preset-migration.js +25 -0
  96. package/dist/resolved-plan.js +1 -0
  97. package/dist/rooms-tasks/add-member.d.ts +48 -0
  98. package/dist/rooms-tasks/add-member.js +83 -0
  99. package/dist/rooms-tasks/archived-absence.d.ts +8 -0
  100. package/dist/rooms-tasks/archived-absence.js +48 -0
  101. package/dist/rooms-tasks/cli.js +34 -5
  102. package/dist/rooms-tasks/close.d.ts +5 -2
  103. package/dist/rooms-tasks/close.js +208 -28
  104. package/dist/rooms-tasks/config.d.ts +1 -1
  105. package/dist/rooms-tasks/config.js +11 -4
  106. package/dist/rooms-tasks/cowork-adapter.d.ts +6 -4
  107. package/dist/rooms-tasks/cowork-adapter.js +8 -121
  108. package/dist/rooms-tasks/deletion.d.ts +1 -1
  109. package/dist/rooms-tasks/deletion.js +74 -5
  110. package/dist/rooms-tasks/erasure.d.ts +6 -0
  111. package/dist/rooms-tasks/erasure.js +169 -0
  112. package/dist/rooms-tasks/external-worker.d.ts +1 -1
  113. package/dist/rooms-tasks/external-worker.js +3 -4
  114. package/dist/rooms-tasks/layout-binding-client.d.ts +11 -0
  115. package/dist/rooms-tasks/layout-binding-client.js +56 -0
  116. package/dist/rooms-tasks/layout-binding-grants.d.ts +21 -0
  117. package/dist/rooms-tasks/layout-binding-grants.js +128 -0
  118. package/dist/rooms-tasks/layout-cli.d.ts +4 -0
  119. package/dist/rooms-tasks/layout-cli.js +107 -0
  120. package/dist/rooms-tasks/layout-config.d.ts +11 -0
  121. package/dist/rooms-tasks/layout-config.js +89 -0
  122. package/dist/rooms-tasks/layout-control.d.ts +21 -0
  123. package/dist/rooms-tasks/layout-control.js +52 -0
  124. package/dist/rooms-tasks/layout-service.d.ts +42 -0
  125. package/dist/rooms-tasks/layout-service.js +185 -0
  126. package/dist/rooms-tasks/layout.d.ts +114 -0
  127. package/dist/rooms-tasks/layout.js +250 -0
  128. package/dist/rooms-tasks/live-readiness.d.ts +18 -0
  129. package/dist/rooms-tasks/live-readiness.js +85 -0
  130. package/dist/rooms-tasks/member-startup.d.ts +1 -0
  131. package/dist/rooms-tasks/member-startup.js +2 -0
  132. package/dist/rooms-tasks/provision.d.ts +14 -0
  133. package/dist/rooms-tasks/provision.js +173 -46
  134. package/dist/rooms-tasks/room-state.d.ts +4 -2
  135. package/dist/rooms-tasks/room-state.js +53 -8
  136. package/dist/rooms-tasks/task-state.d.ts +42 -7
  137. package/dist/rooms-tasks/task-state.js +153 -23
  138. package/dist/rooms-tasks/types.d.ts +28 -0
  139. package/dist/rooms-tasks/workspace-artifacts.d.ts +6 -0
  140. package/dist/rooms-tasks/workspace-artifacts.js +93 -0
  141. package/dist/rooms-tasks/workspace.d.ts +26 -0
  142. package/dist/rooms-tasks/workspace.js +195 -0
  143. package/dist/runner.d.ts +19 -3
  144. package/dist/runner.js +128 -45
  145. package/dist/session/acp.d.ts +9 -1
  146. package/dist/session/acp.js +31 -6
  147. package/dist/session/arbiter.d.ts +5 -0
  148. package/dist/session/arbiter.js +28 -2
  149. package/dist/session/codex-app-server.d.ts +5 -0
  150. package/dist/session/codex-app-server.js +36 -3
  151. package/dist/session/control.d.ts +12 -1
  152. package/dist/session/control.js +68 -3
  153. package/dist/session/conversation-normalizer.d.ts +2 -1
  154. package/dist/session/conversation-normalizer.js +1 -1
  155. package/dist/session/conversation-store.d.ts +1 -1
  156. package/dist/session/conversation-store.js +7 -11
  157. package/dist/session/conversation-types.d.ts +7 -3
  158. package/dist/session/task-notice.d.ts +14 -0
  159. package/dist/session/task-notice.js +13 -0
  160. package/dist/session/types.d.ts +6 -0
  161. package/dist/setup-tunnel-preflight.d.ts +34 -0
  162. package/dist/setup-tunnel-preflight.js +62 -0
  163. package/dist/socket-path.d.ts +2 -0
  164. package/dist/socket-path.js +22 -0
  165. package/dist/spawn.js +8 -1
  166. package/dist/startup-readiness.d.ts +13 -0
  167. package/dist/startup-readiness.js +38 -0
  168. package/dist/subscriptions/cli.d.ts +91 -0
  169. package/dist/subscriptions/cli.js +223 -0
  170. package/dist/subscriptions/launch.d.ts +37 -0
  171. package/dist/subscriptions/launch.js +93 -0
  172. package/dist/subscriptions/login.d.ts +75 -0
  173. package/dist/subscriptions/login.js +182 -0
  174. package/dist/subscriptions/observed.d.ts +7 -0
  175. package/dist/subscriptions/observed.js +44 -0
  176. package/dist/subscriptions/probe.d.ts +10 -0
  177. package/dist/subscriptions/probe.js +73 -0
  178. package/dist/subscriptions/service.d.ts +102 -0
  179. package/dist/subscriptions/service.js +364 -0
  180. package/dist/subscriptions/store.d.ts +71 -0
  181. package/dist/subscriptions/store.js +140 -0
  182. package/dist/supervisor/launchd.js +2 -1
  183. package/dist/supervisor/systemd.js +9 -23
  184. package/dist/temp-idle.d.ts +17 -0
  185. package/dist/temp-idle.js +42 -0
  186. package/dist/temp-lifecycle.d.ts +6 -1
  187. package/dist/temp-lifecycle.js +29 -13
  188. package/dist/tunnel-setup-completion.d.ts +7 -0
  189. package/dist/tunnel-setup-completion.js +13 -0
  190. package/dist/tunnel-setup-input.d.ts +19 -0
  191. package/dist/tunnel-setup-input.js +124 -0
  192. package/dist/web/agent-attachments.d.ts +29 -0
  193. package/dist/web/agent-attachments.js +162 -0
  194. package/dist/web/auth.d.ts +29 -1
  195. package/dist/web/auth.js +82 -7
  196. package/dist/web/available-port.d.ts +2 -0
  197. package/dist/web/available-port.js +23 -0
  198. package/dist/web/control.d.ts +3 -3
  199. package/dist/web/control.js +10 -8
  200. package/dist/web/fleet-config-service.d.ts +4 -1
  201. package/dist/web/fleet-config-service.js +46 -15
  202. package/dist/web/prefix-gateway.d.ts +32 -0
  203. package/dist/web/prefix-gateway.js +234 -0
  204. package/dist/web/runtime.d.ts +3 -1
  205. package/dist/web/runtime.js +116 -31
  206. package/dist/web/server.d.ts +16 -0
  207. package/dist/web/server.js +592 -53
  208. package/dist/web/service.d.ts +11 -2
  209. package/dist/web/service.js +30 -4
  210. package/dist/web/workspace-devices.d.ts +36 -0
  211. package/dist/web/workspace-devices.js +101 -0
  212. package/dist/web/workspace-tunnel.d.ts +1 -0
  213. package/dist/web/workspace-tunnel.js +34 -0
  214. package/dist/workspace-enrollment.d.ts +82 -0
  215. package/dist/workspace-enrollment.js +566 -0
  216. package/dist/workspace-replacement.d.ts +66 -0
  217. package/dist/workspace-replacement.js +220 -0
  218. package/docs/live-voice.md +13 -0
  219. package/docs/room-layouts.md +227 -0
  220. package/docs/task-workspaces.md +130 -0
  221. package/docs/validation/managed-cli-permissions.md +421 -0
  222. package/examples/room-layouts/fresh.yaml +27 -0
  223. package/examples/room-layouts/scoped.yaml +21 -0
  224. package/examples/room-layouts/shared.yaml +19 -0
  225. package/package.json +15 -18
  226. package/presets/README.md +78 -0
  227. package/presets/brain-catalog.json +8 -2
  228. package/presets/fleet/agent_templates/Critic.yaml +1 -1
  229. package/presets/fleet/agent_templates/Developer.yaml +1 -1
  230. package/presets/fleet/agent_templates/Engineer.yaml +5 -0
  231. package/presets/fleet/agent_templates/LocalCoordinator.yaml +1 -1
  232. package/presets/fleet/agents/FleetCoordinator.yaml +1 -1
  233. package/presets/fleet/brains/claude-fable-5-1-high.yaml +5 -0
  234. package/presets/fleet/brains/claude-fable-5-1-low.yaml +5 -0
  235. package/presets/fleet/brains/claude-fable-5-1-max.yaml +5 -0
  236. package/presets/fleet/brains/claude-fable-5-1-medium.yaml +5 -0
  237. package/presets/fleet/brains/claude-fable-5-1-xhigh.yaml +5 -0
  238. package/presets/fleet/brains/claude-fable-5-high.yaml +1 -1
  239. package/presets/fleet/brains/claude-fable-5-low.yaml +1 -1
  240. package/presets/fleet/brains/claude-fable-5-max.yaml +1 -1
  241. package/presets/fleet/brains/claude-fable-5-medium.yaml +1 -1
  242. package/presets/fleet/brains/claude-fable-5-xhigh.yaml +1 -1
  243. package/presets/fleet/brains/claude-haiku-4-5-20251001-default.yaml +4 -0
  244. package/presets/fleet/brains/claude-opus-5-5-high.yaml +5 -0
  245. package/presets/fleet/brains/claude-opus-5-5-low.yaml +5 -0
  246. package/presets/fleet/brains/claude-opus-5-5-max.yaml +5 -0
  247. package/presets/fleet/brains/claude-opus-5-5-medium.yaml +5 -0
  248. package/presets/fleet/brains/claude-opus-5-5-xhigh.yaml +5 -0
  249. package/presets/fleet/brains/claude-opus-5-high.yaml +1 -1
  250. package/presets/fleet/brains/claude-opus-5-low.yaml +1 -1
  251. package/presets/fleet/brains/claude-opus-5-max.yaml +1 -1
  252. package/presets/fleet/brains/claude-opus-5-medium.yaml +1 -1
  253. package/presets/fleet/brains/claude-opus-5-xhigh.yaml +1 -1
  254. package/presets/fleet/brains/claude-sonnet-5-high.yaml +1 -1
  255. package/presets/fleet/brains/claude-sonnet-5-low.yaml +1 -1
  256. package/presets/fleet/brains/claude-sonnet-5-max.yaml +1 -1
  257. package/presets/fleet/brains/claude-sonnet-5-medium.yaml +1 -1
  258. package/presets/fleet/brains/claude-sonnet-5-xhigh.yaml +1 -1
  259. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-high.yaml +1 -1
  260. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-low.yaml +1 -1
  261. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-medium.yaml +1 -1
  262. package/presets/fleet/brains/codex-gpt-5-3-codex-spark-xhigh.yaml +1 -1
  263. package/presets/fleet/brains/codex-gpt-5-4-high.yaml +1 -1
  264. package/presets/fleet/brains/codex-gpt-5-4-low.yaml +1 -1
  265. package/presets/fleet/brains/codex-gpt-5-4-medium.yaml +1 -1
  266. package/presets/fleet/brains/codex-gpt-5-4-mini-high.yaml +1 -1
  267. package/presets/fleet/brains/codex-gpt-5-4-mini-low.yaml +1 -1
  268. package/presets/fleet/brains/codex-gpt-5-4-mini-medium.yaml +1 -1
  269. package/presets/fleet/brains/codex-gpt-5-4-mini-xhigh.yaml +1 -1
  270. package/presets/fleet/brains/codex-gpt-5-4-xhigh.yaml +1 -1
  271. package/presets/fleet/brains/codex-gpt-5-5-high.yaml +1 -1
  272. package/presets/fleet/brains/codex-gpt-5-5-low.yaml +1 -1
  273. package/presets/fleet/brains/codex-gpt-5-5-medium.yaml +1 -1
  274. package/presets/fleet/brains/codex-gpt-5-5-xhigh.yaml +1 -1
  275. package/presets/fleet/brains/codex-gpt-5-6-luna-high.yaml +1 -1
  276. package/presets/fleet/brains/codex-gpt-5-6-luna-low.yaml +1 -1
  277. package/presets/fleet/brains/codex-gpt-5-6-luna-max.yaml +1 -1
  278. package/presets/fleet/brains/codex-gpt-5-6-luna-medium.yaml +1 -1
  279. package/presets/fleet/brains/codex-gpt-5-6-luna-xhigh.yaml +1 -1
  280. package/presets/fleet/brains/codex-gpt-5-6-sol-high.yaml +1 -1
  281. package/presets/fleet/brains/codex-gpt-5-6-sol-low.yaml +1 -1
  282. package/presets/fleet/brains/codex-gpt-5-6-sol-max.yaml +1 -1
  283. package/presets/fleet/brains/codex-gpt-5-6-sol-medium.yaml +1 -1
  284. package/presets/fleet/brains/codex-gpt-5-6-sol-ultra.yaml +1 -1
  285. package/presets/fleet/brains/codex-gpt-5-6-sol-xhigh.yaml +1 -1
  286. package/presets/fleet/brains/codex-gpt-5-6-terra-high.yaml +1 -1
  287. package/presets/fleet/brains/codex-gpt-5-6-terra-low.yaml +1 -1
  288. package/presets/fleet/brains/codex-gpt-5-6-terra-max.yaml +1 -1
  289. package/presets/fleet/brains/codex-gpt-5-6-terra-medium.yaml +1 -1
  290. package/presets/fleet/brains/codex-gpt-5-6-terra-ultra.yaml +1 -1
  291. package/presets/fleet/brains/codex-gpt-5-6-terra-xhigh.yaml +1 -1
  292. package/presets/fleet/brains/codex-gpt-6-1-sol-high.yaml +5 -0
  293. package/presets/fleet/brains/codex-gpt-6-1-sol-low.yaml +5 -0
  294. package/presets/fleet/brains/codex-gpt-6-1-sol-max.yaml +5 -0
  295. package/presets/fleet/brains/codex-gpt-6-1-sol-medium.yaml +5 -0
  296. package/presets/fleet/brains/codex-gpt-6-1-sol-ultra.yaml +5 -0
  297. package/presets/fleet/brains/codex-gpt-6-1-sol-xhigh.yaml +5 -0
  298. package/presets/fleet/brains/codex-gpt-6-astra-high.yaml +1 -1
  299. package/presets/fleet/brains/codex-gpt-6-astra-low.yaml +1 -1
  300. package/presets/fleet/brains/codex-gpt-6-astra-max.yaml +1 -1
  301. package/presets/fleet/brains/codex-gpt-6-astra-medium.yaml +1 -1
  302. package/presets/fleet/brains/codex-gpt-6-astra-ultra.yaml +1 -1
  303. package/presets/fleet/brains/codex-gpt-6-astra-xhigh.yaml +1 -1
  304. package/presets/fleet/brains/codex-gpt-6-luna-high.yaml +5 -0
  305. package/presets/fleet/brains/codex-gpt-6-luna-low.yaml +5 -0
  306. package/presets/fleet/brains/codex-gpt-6-luna-max.yaml +5 -0
  307. package/presets/fleet/brains/codex-gpt-6-luna-medium.yaml +5 -0
  308. package/presets/fleet/brains/codex-gpt-6-luna-xhigh.yaml +5 -0
  309. package/presets/fleet/brains/codex-gpt-6-sol-high.yaml +5 -0
  310. package/presets/fleet/brains/codex-gpt-6-sol-low.yaml +5 -0
  311. package/presets/fleet/brains/codex-gpt-6-sol-max.yaml +5 -0
  312. package/presets/fleet/brains/codex-gpt-6-sol-medium.yaml +5 -0
  313. package/presets/fleet/brains/codex-gpt-6-sol-ultra.yaml +5 -0
  314. package/presets/fleet/brains/codex-gpt-6-sol-xhigh.yaml +5 -0
  315. package/presets/fleet/roles/Coordinator.yaml +34 -11
  316. package/presets/fleet/roles/Engineer.yaml +40 -0
  317. package/presets/fleet/room_layouts/engineering.yaml +25 -0
  318. package/presets/fleet/room_layouts/pair.yaml +24 -0
  319. package/presets/fleet/room_layouts/single.yaml +17 -0
  320. package/presets/fleet/room_layouts/team.yaml +30 -0
  321. package/presets/fleet/room_templates/engineering.yaml +19 -0
  322. package/presets/manifest.json +2 -2
  323. package/dist/web-app/assets/index-59GF-gsZ.css +0 -1
  324. package/dist/web-app/assets/index-C0h3ALvs.js +0 -10
  325. package/dist/web-app/icons/ours-fleet-maskable.svg +0 -4
  326. package/dist/web-app/icons/ours-fleet.svg +0 -4
  327. package/dist/web-app/index.html +0 -17
  328. package/dist/web-app/manifest.webmanifest +0 -15
  329. package/dist/web-app/offline.html +0 -18
  330. package/dist/web-app/sw.js +0 -51
package/dist/spawn.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { storeRoomSecret, storeTemporaryLaunch, preparePermanentAssignment } from './agent-ours/service.js';
3
+ import { ensureWorkspace } from './rooms-tasks/workspace.js';
3
4
  import { spawn as spawnChild } from 'node:child_process';
4
5
  import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
5
6
  import { join } from 'node:path';
@@ -321,6 +322,12 @@ export async function spawnTemp(o, binPath, launch = independentSupervisor, crea
321
322
  if (o.isolationFile)
322
323
  readIsolationFile(o.isolationFile); // fail before reserving
323
324
  const prepared = resolvedSpawn(o); // canonical validation before mutation
325
+ if (o.roomMemberStartup?.workspace) {
326
+ const workspace = o.roomMemberStartup.workspace;
327
+ if (prepared.role.cwd !== workspace.path)
328
+ throw new Error('room member cwd must equal its recorded owned workspace');
329
+ ensureWorkspace(workspace);
330
+ }
324
331
  // Retire only supervisors whose recorded owner is definitively stopped. This
325
332
  // bounded pass keeps the active roster clean without deleting old evidence.
326
333
  await reclaimStaleTempState();
@@ -351,7 +358,7 @@ async function spawnTempInner(o, preparedRole, binPath, launch, tx, onStage) {
351
358
  if (role.roomMemberStartup)
352
359
  role.roomMemberStartup = { ...role.roomMemberStartup, invite: '' };
353
360
  onStage?.('writing_role');
354
- const dir = applyRole(role, { temp: true, identityGuarantee: 'unverified' });
361
+ const dir = applyRole(role, { temp: true, identityGuarantee: 'unverified', configPath: o.configPath });
355
362
  const provenance = buildProvenance({
356
363
  role: o.name, lifetime: 'temporary', fleetVersion: VERSION,
357
364
  settings: provenanceSettings(o, cfg.defaults, preparedRole.temporaryLoops),
@@ -0,0 +1,13 @@
1
+ import { type DaemonGenerationProbe } from './daemon-recovery.js';
2
+ export declare const STARTUP_WAIT_MS = 240000;
3
+ export declare const STARTUP_RETRY_MS = 5000;
4
+ interface ReadinessDeps {
5
+ probe(env: NodeJS.ProcessEnv): Promise<DaemonGenerationProbe>;
6
+ now(): number;
7
+ sleep(ms: number): Promise<void>;
8
+ log(message: string): void;
9
+ env: NodeJS.ProcessEnv;
10
+ }
11
+ /** Read-only preflight: never binds identities, starts a harness or edits its ledger. */
12
+ export declare function waitForRoleDaemon(name: string, configPath?: string, partial?: Partial<ReadinessDeps>): Promise<void>;
13
+ export {};
@@ -0,0 +1,38 @@
1
+ import { agentDir } from './paths.js';
2
+ import { findRole, loadConfig } from './config.js';
3
+ import { resolveConfigPath } from './runner.js';
4
+ import { probeDaemonGeneration } from './daemon-recovery.js';
5
+ export const STARTUP_WAIT_MS = 240_000;
6
+ export const STARTUP_RETRY_MS = 5_000;
7
+ /** Read-only preflight: never binds identities, starts a harness or edits its ledger. */
8
+ export async function waitForRoleDaemon(name, configPath, partial = {}) {
9
+ const deps = {
10
+ probe: env => probeDaemonGeneration(((url, init) => globalThis.fetch(url, {
11
+ ...init, signal: AbortSignal.timeout(10_000),
12
+ })), env),
13
+ now: Date.now,
14
+ sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
15
+ log: message => process.stderr.write(message + '\n'),
16
+ env: process.env,
17
+ ...partial,
18
+ };
19
+ const path = resolveConfigPath(agentDir(name), configPath);
20
+ const role = findRole(loadConfig(path), name);
21
+ const env = { ...deps.env, ...role.env };
22
+ const deadline = deps.now() + STARTUP_WAIT_MS;
23
+ let lastReason = '';
24
+ while (deps.now() < deadline) {
25
+ const result = await deps.probe(env);
26
+ if (result.state === 'ready') {
27
+ deps.log(`[${name}] daemon ready; starting supervised agent`);
28
+ return;
29
+ }
30
+ // Only structured diagnostic codes, never endpoint responses or credentials.
31
+ const reason = /^[A-Z][A-Z0-9_]*$/.test(result.reason) ? result.reason : 'DAEMON_UNAVAILABLE';
32
+ if (reason !== lastReason)
33
+ deps.log(`[${name}] waiting for configured daemon: ${reason}`);
34
+ lastReason = reason;
35
+ await deps.sleep(Math.min(STARTUP_RETRY_MS, Math.max(0, deadline - deps.now())));
36
+ }
37
+ throw new Error(`Daemon not ready (${lastReason}); service manager will retry startup`);
38
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Thin adapters over the official CLIs. Nothing here reads or returns a token
3
+ * value: credentials stay in files the CLIs own, and secrets typed by the user
4
+ * (a Claude paste code) travel only over a child's stdin, never argv or logs.
5
+ */
6
+ export interface SubscriptionBinaries {
7
+ claude: string;
8
+ codex: string;
9
+ /** `script(1)`, used to give `claude auth login` the terminal it expects. */
10
+ script: string;
11
+ }
12
+ export declare const defaultBinaries: () => SubscriptionBinaries;
13
+ /**
14
+ * Child env for a profile helper: explicit home for added profiles, the CLI
15
+ * default otherwise. Every credential selector either CLI honours is removed,
16
+ * so a helper can only ever see the profile's own login.
17
+ */
18
+ export declare function profileEnv(homeVar: string, profileId: string, home: string, base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
19
+ export interface ClaudeStatus {
20
+ loggedIn: boolean;
21
+ email?: string;
22
+ plan?: string;
23
+ org?: string;
24
+ authMethod?: string;
25
+ }
26
+ /** `claude auth status --json` (documented: exit 0 when logged in, 1 otherwise). */
27
+ export declare function claudeAuthStatus(bin: string, env: NodeJS.ProcessEnv, timeoutMs?: number): Promise<ClaudeStatus>;
28
+ /**
29
+ * Login expiry timestamps from the Claude credentials file. Field names are
30
+ * observed (Claude Code 2.1.x), not a documented contract, so absence is normal.
31
+ * Only the two numbers are kept; the parsed object is discarded immediately.
32
+ */
33
+ export declare function claudeLoginExpiry(home: string): {
34
+ accessExpiresAt?: number;
35
+ refreshExpiresAt?: number;
36
+ };
37
+ /** Minimal stdio JSON-RPC client for `codex app-server` (the supported transport). */
38
+ export declare class CodexAppServer {
39
+ private readonly child;
40
+ private id;
41
+ private buffer;
42
+ private readonly pending;
43
+ private readonly listeners;
44
+ private closed;
45
+ private constructor();
46
+ static start(bin: string, env: NodeJS.ProcessEnv, initializeTimeoutMs?: number): Promise<CodexAppServer>;
47
+ call<T = unknown>(method: string, params: unknown, timeoutMs?: number): Promise<T>;
48
+ onNotification(fn: (method: string, params: unknown) => void): () => void;
49
+ close(): void;
50
+ private onData;
51
+ }
52
+ /** One-shot use of an app-server for a profile. */
53
+ export declare function withCodex<T>(bin: string, env: NodeJS.ProcessEnv, fn: (s: CodexAppServer) => Promise<T>, initializeTimeoutMs?: number): Promise<T>;
54
+ /** What a Codex runtime offers the account it is signed in to. An empty list is an answer; unknown is not. */
55
+ export type OfferedModels = {
56
+ state: 'known';
57
+ models: string[];
58
+ } | {
59
+ state: 'unknown';
60
+ reason: string;
61
+ };
62
+ /**
63
+ * Ask this Codex executable, with this profile's environment, which models it offers (`model/list`,
64
+ * the call the ACP adapter itself uses). Nothing is inferred when it does not answer.
65
+ */
66
+ export declare function codexOfferedModels(bin: string, env: NodeJS.ProcessEnv, budgetMs?: number): Promise<OfferedModels>;
67
+ export interface UsageWindow {
68
+ id: string;
69
+ label: string;
70
+ usedPercent: number;
71
+ windowMins?: number;
72
+ resetsAt?: string;
73
+ }
74
+ interface CodexWindow {
75
+ usedPercent?: number;
76
+ windowDurationMins?: number | null;
77
+ resetsAt?: number | null;
78
+ }
79
+ interface CodexSnapshot {
80
+ limitId?: string | null;
81
+ limitName?: string | null;
82
+ primary?: CodexWindow | null;
83
+ secondary?: CodexWindow | null;
84
+ }
85
+ /** Flatten `account/rateLimits/read` into display windows. */
86
+ export declare function codexUsageWindows(result: {
87
+ rateLimits?: CodexSnapshot;
88
+ rateLimitsByLimitId?: Record<string, CodexSnapshot | undefined> | null;
89
+ }): UsageWindow[];
90
+ export declare function windowName(mins?: number): string;
91
+ export {};
@@ -0,0 +1,223 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { CONFLICTING_AUTH_ENV } from './launch.js';
5
+ import { DEFAULT_PROFILE_ID } from './store.js';
6
+ export const defaultBinaries = () => ({
7
+ claude: process.env.OURS_FLEET_CLAUDE_BIN ?? 'claude',
8
+ codex: process.env.OURS_FLEET_CODEX_BIN ?? 'codex',
9
+ script: 'script',
10
+ });
11
+ /**
12
+ * Child env for a profile helper: explicit home for added profiles, the CLI
13
+ * default otherwise. Every credential selector either CLI honours is removed,
14
+ * so a helper can only ever see the profile's own login.
15
+ */
16
+ export function profileEnv(homeVar, profileId, home, base = process.env) {
17
+ const env = { ...base, BROWSER: 'true', NO_COLOR: '1' };
18
+ for (const key of [...CONFLICTING_AUTH_ENV.claude, ...CONFLICTING_AUTH_ENV.codex, 'ANTHROPIC_BASE_URL', 'OPENAI_BASE_URL'])
19
+ delete env[key];
20
+ if (profileId !== DEFAULT_PROFILE_ID)
21
+ env[homeVar] = home;
22
+ return env;
23
+ }
24
+ /** `claude auth status --json` (documented: exit 0 when logged in, 1 otherwise). */
25
+ export function claudeAuthStatus(bin, env, timeoutMs = 20_000) {
26
+ return new Promise((resolve, reject) => {
27
+ const child = spawn(bin, ['auth', 'status', '--json'], { env, stdio: ['ignore', 'pipe', 'ignore'] });
28
+ let out = '';
29
+ const timer = setTimeout(() => { child.kill('SIGKILL'); reject(new Error('claude auth status timed out')); }, timeoutMs);
30
+ child.stdout.on('data', d => { out += d; if (out.length > 64 * 1024)
31
+ child.kill('SIGKILL'); });
32
+ child.once('error', error => { clearTimeout(timer); reject(error); });
33
+ child.once('close', code => {
34
+ clearTimeout(timer);
35
+ let parsed = {};
36
+ try {
37
+ parsed = JSON.parse(out);
38
+ }
39
+ catch { /* non-JSON: rely on exit code */ }
40
+ const str = (v) => typeof v === 'string' && v ? v.slice(0, 120) : undefined;
41
+ resolve({
42
+ loggedIn: code === 0 && parsed.loggedIn !== false,
43
+ email: str(parsed.email), plan: str(parsed.subscriptionType), org: str(parsed.orgName),
44
+ authMethod: str(parsed.authMethod),
45
+ });
46
+ });
47
+ });
48
+ }
49
+ /**
50
+ * Login expiry timestamps from the Claude credentials file. Field names are
51
+ * observed (Claude Code 2.1.x), not a documented contract, so absence is normal.
52
+ * Only the two numbers are kept; the parsed object is discarded immediately.
53
+ */
54
+ export function claudeLoginExpiry(home) {
55
+ try {
56
+ const oauth = JSON.parse(readFileSync(join(home, '.credentials.json'), 'utf8')).claudeAiOauth;
57
+ const num = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
58
+ return { accessExpiresAt: num(oauth?.expiresAt), refreshExpiresAt: num(oauth?.refreshTokenExpiresAt) };
59
+ }
60
+ catch {
61
+ return {};
62
+ }
63
+ }
64
+ /** Minimal stdio JSON-RPC client for `codex app-server` (the supported transport). */
65
+ export class CodexAppServer {
66
+ child;
67
+ id = 0;
68
+ buffer = '';
69
+ pending = new Map();
70
+ listeners = new Set();
71
+ closed = false;
72
+ constructor(child) {
73
+ this.child = child;
74
+ child.stdout.on('data', chunk => this.onData(String(chunk)));
75
+ child.stdin.on('error', () => { });
76
+ child.stderr.resume();
77
+ child.once('close', () => {
78
+ this.closed = true;
79
+ for (const p of this.pending.values())
80
+ p.reject(new Error('codex app-server exited'));
81
+ this.pending.clear();
82
+ });
83
+ }
84
+ static async start(bin, env, initializeTimeoutMs = 20_000) {
85
+ const child = spawn(bin, ['app-server'], { env, stdio: ['pipe', 'pipe', 'pipe'] });
86
+ await new Promise((resolve, reject) => { child.once('spawn', resolve); child.once('error', reject); });
87
+ const server = new CodexAppServer(child);
88
+ // A server that does not answer is not handed out, so nobody else can close it: end it here.
89
+ try {
90
+ await server.call('initialize', { clientInfo: { name: 'ours-fleet', title: 'Ours Fleet', version: '1' } }, initializeTimeoutMs);
91
+ }
92
+ catch (error) {
93
+ server.close();
94
+ throw error;
95
+ }
96
+ child.stdin.write(`${JSON.stringify({ method: 'initialized' })}\n`);
97
+ return server;
98
+ }
99
+ call(method, params, timeoutMs = 20_000) {
100
+ if (this.closed)
101
+ return Promise.reject(new Error('codex app-server exited'));
102
+ const id = ++this.id;
103
+ return new Promise((resolve, reject) => {
104
+ const timer = setTimeout(() => { this.pending.delete(id); reject(new Error(`${method} timed out`)); }, timeoutMs);
105
+ this.pending.set(id, {
106
+ resolve: v => { clearTimeout(timer); resolve(v); },
107
+ reject: e => { clearTimeout(timer); reject(e); },
108
+ });
109
+ this.child.stdin.write(`${JSON.stringify({ id, method, params })}\n`);
110
+ });
111
+ }
112
+ onNotification(fn) {
113
+ this.listeners.add(fn);
114
+ return () => this.listeners.delete(fn);
115
+ }
116
+ close() {
117
+ if (!this.closed)
118
+ this.child.kill();
119
+ }
120
+ onData(chunk) {
121
+ this.buffer += chunk;
122
+ for (let i = this.buffer.indexOf('\n'); i >= 0; i = this.buffer.indexOf('\n')) {
123
+ const line = this.buffer.slice(0, i).trim();
124
+ this.buffer = this.buffer.slice(i + 1);
125
+ if (!line)
126
+ continue;
127
+ let message;
128
+ try {
129
+ message = JSON.parse(line);
130
+ }
131
+ catch {
132
+ continue;
133
+ }
134
+ if (typeof message.id === 'number' && this.pending.has(message.id) && !message.method) {
135
+ const p = this.pending.get(message.id);
136
+ this.pending.delete(message.id);
137
+ if (message.error)
138
+ p.reject(Object.assign(new Error(String(message.error.message ?? 'codex error').slice(0, 300)), { rpcCode: message.error.code }));
139
+ else
140
+ p.resolve(message.result);
141
+ }
142
+ else if (message.method) {
143
+ for (const fn of this.listeners)
144
+ fn(message.method, message.params);
145
+ }
146
+ }
147
+ }
148
+ }
149
+ /** One-shot use of an app-server for a profile. */
150
+ export async function withCodex(bin, env, fn, initializeTimeoutMs) {
151
+ const server = await CodexAppServer.start(bin, env, initializeTimeoutMs);
152
+ try {
153
+ return await fn(server);
154
+ }
155
+ finally {
156
+ server.close();
157
+ }
158
+ }
159
+ /**
160
+ * Ask this Codex executable, with this profile's environment, which models it offers (`model/list`,
161
+ * the call the ACP adapter itself uses). Nothing is inferred when it does not answer.
162
+ */
163
+ export async function codexOfferedModels(bin, env, budgetMs = 30_000) {
164
+ // One budget for the whole question: onboarding waits for this answer.
165
+ const deadline = Date.now() + budgetMs;
166
+ const left = () => Math.max(1, deadline - Date.now());
167
+ try {
168
+ return await withCodex(bin, env, async (server) => {
169
+ const models = [];
170
+ let cursor = null;
171
+ while (Date.now() < deadline) {
172
+ const answer = await server.call('model/list', { cursor, limit: null }, left());
173
+ if (!Array.isArray(answer?.data))
174
+ return { state: 'unknown', reason: 'Codex did not return a model list' };
175
+ for (const model of answer.data)
176
+ if (model && typeof model.id === 'string' && model.id && model.hidden !== true)
177
+ models.push(model.id);
178
+ cursor = typeof answer.nextCursor === 'string' && answer.nextCursor ? answer.nextCursor : null;
179
+ if (!cursor)
180
+ return { state: 'known', models: [...new Set(models)] };
181
+ }
182
+ return { state: 'unknown', reason: 'Codex did not finish listing its models in time' };
183
+ }, left());
184
+ }
185
+ catch (error) {
186
+ return { state: 'unknown', reason: error instanceof Error ? error.message : String(error) };
187
+ }
188
+ }
189
+ /** Flatten `account/rateLimits/read` into display windows. */
190
+ export function codexUsageWindows(result) {
191
+ const snapshots = result.rateLimitsByLimitId && Object.keys(result.rateLimitsByLimitId).length
192
+ ? Object.entries(result.rateLimitsByLimitId) : [['codex', result.rateLimits]];
193
+ const windows = [];
194
+ for (const [limitId, snap] of snapshots) {
195
+ if (!snap)
196
+ continue;
197
+ for (const [slot, w] of [['primary', snap.primary], ['secondary', snap.secondary]]) {
198
+ if (!w || typeof w.usedPercent !== 'number')
199
+ continue;
200
+ windows.push({
201
+ id: `${limitId}:${slot}`,
202
+ label: `${snap.limitName ?? limitId} · ${windowName(w.windowDurationMins ?? undefined)}`,
203
+ usedPercent: w.usedPercent,
204
+ windowMins: w.windowDurationMins ?? undefined,
205
+ resetsAt: typeof w.resetsAt === 'number' ? new Date(w.resetsAt * 1000).toISOString() : undefined,
206
+ });
207
+ }
208
+ }
209
+ return windows;
210
+ }
211
+ export function windowName(mins) {
212
+ if (!mins)
213
+ return 'window';
214
+ if (mins === 300)
215
+ return '5h';
216
+ if (mins === 10_080)
217
+ return 'weekly';
218
+ if (mins % 1440 === 0)
219
+ return `${mins / 1440}d`;
220
+ if (mins % 60 === 0)
221
+ return `${mins / 60}h`;
222
+ return `${mins}m`;
223
+ }
@@ -0,0 +1,37 @@
1
+ import { type SubscriptionPin, type SubscriptionProvider } from './store.js';
2
+ /** The subscription provider a harness authenticates with, if Fleet manages it. */
3
+ export declare function providerForHarness(harness: string): SubscriptionProvider | undefined;
4
+ /** Env var that selects the CLI home for each provider. */
5
+ export declare const HOME_ENV: Record<SubscriptionProvider, string>;
6
+ /**
7
+ * Credential sources that would silently outrank the fleet-wide active profile
8
+ * (see Claude Code's documented authentication precedence and Codex's
9
+ * API-key login). While a non-default profile is active they are refused.
10
+ */
11
+ export declare const CONFLICTING_AUTH_ENV: Record<SubscriptionProvider, string[]>;
12
+ /** Claude managed-settings file (Linux), which outranks user settings. */
13
+ export declare const CLAUDE_MANAGED_SETTINGS = "/etc/claude-code/managed-settings.json";
14
+ /**
15
+ * Competing Claude credential sources declared in settings files: an `env`
16
+ * block entry from CONFLICTING_AUTH_ENV, or an `apiKeyHelper`. Settings are
17
+ * shared into profiles, so they can silently outrank a profile's login.
18
+ */
19
+ export declare function claudeSettingsAuthSources(home: string, managed?: string): string[];
20
+ export interface LaunchPin {
21
+ pin: SubscriptionPin;
22
+ /** Added to the harness child env last. Empty for the adopted default. */
23
+ env: Record<string, string>;
24
+ /** Host path the sandbox must mount read-write, if any. */
25
+ writablePath?: string;
26
+ }
27
+ /**
28
+ * Resolve the provider's active profile for a launch and record it in the
29
+ * agent's state dir. Resolution happens once, here: a later switch never
30
+ * changes what this session uses.
31
+ */
32
+ export declare function pinSubscriptionForLaunch(role: {
33
+ name: string;
34
+ harness: string;
35
+ env?: Record<string, string>;
36
+ auth_proxy?: unknown;
37
+ }, stateDir: string, inherited?: NodeJS.ProcessEnv, now?: () => Date): LaunchPin | undefined;
@@ -0,0 +1,93 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { FleetError } from '../application/errors.js';
4
+ import { DEFAULT_PROFILE_ID, profileHome, readSubscriptionState, writePin, } from './store.js';
5
+ /** The subscription provider a harness authenticates with, if Fleet manages it. */
6
+ export function providerForHarness(harness) {
7
+ if (harness === 'claude-code')
8
+ return 'claude';
9
+ if (harness === 'codex')
10
+ return 'codex';
11
+ return undefined;
12
+ }
13
+ /** Env var that selects the CLI home for each provider. */
14
+ export const HOME_ENV = {
15
+ claude: 'CLAUDE_CONFIG_DIR',
16
+ codex: 'CODEX_HOME',
17
+ };
18
+ /**
19
+ * Credential sources that would silently outrank the fleet-wide active profile
20
+ * (see Claude Code's documented authentication precedence and Codex's
21
+ * API-key login). While a non-default profile is active they are refused.
22
+ */
23
+ export const CONFLICTING_AUTH_ENV = {
24
+ claude: [
25
+ 'CLAUDE_CONFIG_DIR', 'ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'CLAUDE_CODE_OAUTH_TOKEN',
26
+ 'CLAUDE_CODE_OAUTH_REFRESH_TOKEN', 'CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR',
27
+ 'CLAUDE_CODE_USE_BEDROCK', 'CLAUDE_CODE_USE_VERTEX', 'CLAUDE_CODE_USE_FOUNDRY', 'ANTHROPIC_PROFILE',
28
+ 'ANTHROPIC_FEDERATION_RULE_ID', 'ANTHROPIC_ORGANIZATION_ID', 'ANTHROPIC_IDENTITY_TOKEN_FILE',
29
+ ],
30
+ codex: ['CODEX_HOME', 'OPENAI_API_KEY', 'CODEX_API_KEY'],
31
+ };
32
+ /** Claude managed-settings file (Linux), which outranks user settings. */
33
+ export const CLAUDE_MANAGED_SETTINGS = '/etc/claude-code/managed-settings.json';
34
+ /**
35
+ * Competing Claude credential sources declared in settings files: an `env`
36
+ * block entry from CONFLICTING_AUTH_ENV, or an `apiKeyHelper`. Settings are
37
+ * shared into profiles, so they can silently outrank a profile's login.
38
+ */
39
+ export function claudeSettingsAuthSources(home, managed = CLAUDE_MANAGED_SETTINGS) {
40
+ const found = [];
41
+ for (const file of [join(home, 'settings.json'), managed]) {
42
+ let settings;
43
+ try {
44
+ settings = JSON.parse(readFileSync(file, 'utf8'));
45
+ }
46
+ catch {
47
+ continue;
48
+ }
49
+ for (const key of CONFLICTING_AUTH_ENV.claude)
50
+ if (settings?.env && typeof settings.env === 'object' && key in settings.env)
51
+ found.push(`${key} (${file})`);
52
+ if (settings?.apiKeyHelper)
53
+ found.push(`apiKeyHelper (${file})`);
54
+ }
55
+ return found;
56
+ }
57
+ /**
58
+ * Resolve the provider's active profile for a launch and record it in the
59
+ * agent's state dir. Resolution happens once, here: a later switch never
60
+ * changes what this session uses.
61
+ */
62
+ export function pinSubscriptionForLaunch(role, stateDir, inherited = process.env, now = () => new Date()) {
63
+ const provider = providerForHarness(role.harness);
64
+ // A loopback auth proxy supplies credentials itself; it is not managed here.
65
+ if (!provider || role.auth_proxy)
66
+ return undefined;
67
+ const profileId = readSubscriptionState().providers[provider].activeProfileId;
68
+ const pin = { provider, profileId, pinnedAt: now().toISOString() };
69
+ if (profileId === DEFAULT_PROFILE_ID) {
70
+ // The adopted default launches exactly as before; credential env that points
71
+ // elsewhere is recorded so the panel can say this session is not managed.
72
+ const unmanaged = CONFLICTING_AUTH_ENV[provider].filter(key => role.env?.[key] !== undefined || inherited[key]);
73
+ if (unmanaged.length)
74
+ pin.unmanaged = unmanaged;
75
+ writePin(stateDir, pin);
76
+ return { pin, env: {} };
77
+ }
78
+ const conflicts = CONFLICTING_AUTH_ENV[provider].filter(key => role.env?.[key] !== undefined || (key !== HOME_ENV[provider] && inherited[key]));
79
+ if (conflicts.length) {
80
+ throw new FleetError('invalid_request', `role '${role.name}': ${conflicts.join(', ')} would bypass the active ${provider} subscription profile; ` +
81
+ 'remove it from the role env / supervisor environment or switch back to the default profile');
82
+ }
83
+ const home = profileHome(provider, profileId);
84
+ if (provider === 'claude') {
85
+ const settings = claudeSettingsAuthSources(home);
86
+ if (settings.length) {
87
+ throw new FleetError('invalid_request', `role '${role.name}': Claude settings declare ${settings.join(', ')}, which would bypass the active subscription profile`);
88
+ }
89
+ }
90
+ pin.home = home;
91
+ writePin(stateDir, pin);
92
+ return { pin, env: { [HOME_ENV[provider]]: home }, writablePath: home };
93
+ }
@@ -0,0 +1,75 @@
1
+ import { type SubscriptionBinaries } from './cli.js';
2
+ import type { SubscriptionProvider } from './store.js';
3
+ /**
4
+ * A short-lived, browser-owned login. The URL comes from the official CLI and
5
+ * is shown only if its origin is on the provider's allowlist; the user's code
6
+ * goes to the CLI's stdin exactly once and is never stored.
7
+ */
8
+ export type LoginState = 'starting' | 'awaiting_user' | 'verifying' | 'succeeded' | 'failed' | 'cancelled' | 'expired';
9
+ export interface LoginView {
10
+ loginId: string;
11
+ provider: SubscriptionProvider;
12
+ kind: 'paste_code' | 'device_code';
13
+ state: LoginState;
14
+ url?: string;
15
+ /** Device code to type at `url`; only exposed while the user still needs it. */
16
+ userCode?: string;
17
+ expiresAt: string;
18
+ error?: string;
19
+ }
20
+ export declare const LOGIN_TTL_MS: number;
21
+ export declare const LOGIN_URL_ALLOWLIST: Record<SubscriptionProvider, string[]>;
22
+ export declare function allowedLoginUrl(provider: SubscriptionProvider, raw: string): string | undefined;
23
+ export interface LoginHandle {
24
+ view(): LoginView;
25
+ /** Browser session that started the login; only it may act on it. */
26
+ readonly owner: string;
27
+ submitCode(code: string): void;
28
+ cancel(): void;
29
+ /** Resolves when the CLI has finished (success or not). */
30
+ readonly done: Promise<boolean>;
31
+ }
32
+ declare abstract class BaseLogin implements LoginHandle {
33
+ readonly provider: SubscriptionProvider;
34
+ readonly owner: string;
35
+ readonly kind: LoginView['kind'];
36
+ readonly loginId: string;
37
+ readonly expiresAt: number;
38
+ state: LoginState;
39
+ url?: string;
40
+ userCode?: string;
41
+ error?: string;
42
+ done: Promise<boolean>;
43
+ protected finish: (ok: boolean) => void;
44
+ private readonly timer;
45
+ constructor(provider: SubscriptionProvider, owner: string, kind: LoginView['kind'], now?: number);
46
+ view(): LoginView;
47
+ abstract submitCode(code: string): void;
48
+ protected abstract stop(): void;
49
+ cancel(): void;
50
+ protected end(state: LoginState, error?: string): void;
51
+ /** Called by the service after verifying the new home. */
52
+ complete(ok: boolean, error?: string): void;
53
+ }
54
+ /** `claude auth login` inside script(1): prints an authorize URL, then reads a paste code. */
55
+ export declare class ClaudeLogin extends BaseLogin {
56
+ private child?;
57
+ private output;
58
+ private submitted;
59
+ /** Resolves with the CLI exit status once it exits. */
60
+ exited: Promise<number | null>;
61
+ constructor(owner: string, bins: SubscriptionBinaries, home: string, profileId: string);
62
+ submitCode(code: string): void;
63
+ protected stop(): void;
64
+ }
65
+ /** Codex device-code login through the app-server's supported account API. */
66
+ export declare class CodexDeviceLogin extends BaseLogin {
67
+ private server?;
68
+ private codexLoginId?;
69
+ /** Resolves true when the app-server reports a successful login. */
70
+ completed: Promise<boolean>;
71
+ constructor(owner: string, bins: SubscriptionBinaries, home: string, profileId: string);
72
+ submitCode(): void;
73
+ protected stop(): void;
74
+ }
75
+ export {};