@intentic/sandbox-contract 1.363.0 → 1.365.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 (233) hide show
  1. package/README.md +7 -0
  2. package/dist/contracts/access-profiles.contract.d.ts +91 -0
  3. package/dist/contracts/access-profiles.contract.d.ts.map +1 -0
  4. package/dist/contracts/access-profiles.contract.js +33 -0
  5. package/dist/contracts/access-profiles.contract.js.map +1 -0
  6. package/dist/contracts/agent.contract.d.ts +18 -0
  7. package/dist/contracts/agent.contract.d.ts.map +1 -1
  8. package/dist/contracts/agents.contract.d.ts +260 -0
  9. package/dist/contracts/agents.contract.d.ts.map +1 -1
  10. package/dist/contracts/agents.contract.js +18 -0
  11. package/dist/contracts/agents.contract.js.map +1 -1
  12. package/dist/contracts/automations.contract.d.ts +5 -0
  13. package/dist/contracts/automations.contract.d.ts.map +1 -1
  14. package/dist/contracts/extensions.contract.d.ts +6 -0
  15. package/dist/contracts/extensions.contract.d.ts.map +1 -1
  16. package/dist/contracts/needs.contract.d.ts +246 -0
  17. package/dist/contracts/needs.contract.d.ts.map +1 -1
  18. package/dist/contracts/needs.contract.js +11 -1
  19. package/dist/contracts/needs.contract.js.map +1 -1
  20. package/dist/contracts/org.contract.d.ts +49 -0
  21. package/dist/contracts/org.contract.d.ts.map +1 -1
  22. package/dist/contracts/runner.contract.d.ts +38 -0
  23. package/dist/contracts/runner.contract.d.ts.map +1 -1
  24. package/dist/contracts/services.contract.d.ts +26 -0
  25. package/dist/contracts/services.contract.d.ts.map +1 -0
  26. package/dist/contracts/services.contract.js +33 -0
  27. package/dist/contracts/services.contract.js.map +1 -0
  28. package/dist/contracts/sessions.contract.d.ts +2 -0
  29. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  30. package/dist/contracts/settings.contract.d.ts +2 -0
  31. package/dist/contracts/settings.contract.d.ts.map +1 -1
  32. package/dist/contracts/system.contract.d.ts +36 -0
  33. package/dist/contracts/system.contract.d.ts.map +1 -1
  34. package/dist/contracts/workspace.contract.d.ts +232 -0
  35. package/dist/contracts/workspace.contract.d.ts.map +1 -1
  36. package/dist/contracts/workspace.contract.js +12 -1
  37. package/dist/contracts/workspace.contract.js.map +1 -1
  38. package/dist/events/agent-events.d.ts +22 -0
  39. package/dist/events/agent-events.d.ts.map +1 -1
  40. package/dist/events/agent-events.js +5 -1
  41. package/dist/events/agent-events.js.map +1 -1
  42. package/dist/events/agent-transcript.d.ts +2 -0
  43. package/dist/events/agent-transcript.d.ts.map +1 -1
  44. package/dist/events/sandbox-notice.d.ts +14 -0
  45. package/dist/events/sandbox-notice.d.ts.map +1 -1
  46. package/dist/events/sandbox-notice.js +13 -1
  47. package/dist/events/sandbox-notice.js.map +1 -1
  48. package/dist/events/system-events.d.ts +26 -0
  49. package/dist/events/system-events.d.ts.map +1 -1
  50. package/dist/events/tool-update.d.ts +6 -0
  51. package/dist/events/tool-update.d.ts.map +1 -0
  52. package/dist/events/tool-update.js +12 -0
  53. package/dist/events/tool-update.js.map +1 -0
  54. package/dist/events/transcript.d.ts +11 -0
  55. package/dist/events/transcript.d.ts.map +1 -1
  56. package/dist/events/transcript.js +4 -0
  57. package/dist/events/transcript.js.map +1 -1
  58. package/dist/index.d.ts +1014 -43
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +4 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/models/device-deadlines.d.ts +34 -0
  63. package/dist/models/device-deadlines.d.ts.map +1 -0
  64. package/dist/models/device-deadlines.js +28 -0
  65. package/dist/models/device-deadlines.js.map +1 -0
  66. package/dist/models/model-setups.d.ts.map +1 -1
  67. package/dist/models/model-setups.js.map +1 -1
  68. package/dist/policy/control-scopes.d.ts +3 -0
  69. package/dist/policy/control-scopes.d.ts.map +1 -1
  70. package/dist/policy/control-scopes.js +2 -0
  71. package/dist/policy/control-scopes.js.map +1 -1
  72. package/dist/policy/org-locks.d.ts +1 -1
  73. package/dist/policy/org-locks.d.ts.map +1 -1
  74. package/dist/policy/org-locks.js +3 -1
  75. package/dist/policy/org-locks.js.map +1 -1
  76. package/dist/protocol/member-reach.d.ts +18 -0
  77. package/dist/protocol/member-reach.d.ts.map +1 -0
  78. package/dist/protocol/member-reach.js +31 -0
  79. package/dist/protocol/member-reach.js.map +1 -0
  80. package/dist/protocol/raw/raw-json-routes.d.ts +423 -1
  81. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  82. package/dist/protocol/raw/raw-json-routes.js +7 -2
  83. package/dist/protocol/raw/raw-json-routes.js.map +1 -1
  84. package/dist/protocol/raw/raw-routes.d.ts +18 -0
  85. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  86. package/dist/protocol/raw/raw-routes.js +8 -3
  87. package/dist/protocol/raw/raw-routes.js.map +1 -1
  88. package/dist/schemas/access-profiles.d.ts +153 -0
  89. package/dist/schemas/access-profiles.d.ts.map +1 -0
  90. package/dist/schemas/access-profiles.js +56 -0
  91. package/dist/schemas/access-profiles.js.map +1 -0
  92. package/dist/schemas/agents-list.d.ts +27 -0
  93. package/dist/schemas/agents-list.d.ts.map +1 -1
  94. package/dist/schemas/agents.d.ts +50 -0
  95. package/dist/schemas/agents.d.ts.map +1 -1
  96. package/dist/schemas/agents.js +17 -0
  97. package/dist/schemas/agents.js.map +1 -1
  98. package/dist/schemas/automations.d.ts +10 -0
  99. package/dist/schemas/automations.d.ts.map +1 -1
  100. package/dist/schemas/automations.js +7 -0
  101. package/dist/schemas/automations.js.map +1 -1
  102. package/dist/schemas/dev-rebuild-log.d.ts +16 -0
  103. package/dist/schemas/dev-rebuild-log.d.ts.map +1 -1
  104. package/dist/schemas/dev-rebuild-log.js +38 -2
  105. package/dist/schemas/dev-rebuild-log.js.map +1 -1
  106. package/dist/schemas/device-commands.d.ts +7 -1
  107. package/dist/schemas/device-commands.d.ts.map +1 -1
  108. package/dist/schemas/device-commands.js +14 -2
  109. package/dist/schemas/device-commands.js.map +1 -1
  110. package/dist/schemas/environment.d.ts +32 -0
  111. package/dist/schemas/environment.d.ts.map +1 -1
  112. package/dist/schemas/environment.js +12 -0
  113. package/dist/schemas/environment.js.map +1 -1
  114. package/dist/schemas/extension-updates.d.ts +12 -0
  115. package/dist/schemas/extension-updates.d.ts.map +1 -1
  116. package/dist/schemas/links.d.ts +6 -1
  117. package/dist/schemas/links.d.ts.map +1 -1
  118. package/dist/schemas/links.js +8 -1
  119. package/dist/schemas/links.js.map +1 -1
  120. package/dist/schemas/members.d.ts +127 -0
  121. package/dist/schemas/members.d.ts.map +1 -1
  122. package/dist/schemas/members.js +32 -0
  123. package/dist/schemas/members.js.map +1 -1
  124. package/dist/schemas/needs.d.ts +23 -0
  125. package/dist/schemas/needs.d.ts.map +1 -1
  126. package/dist/schemas/needs.js +3 -0
  127. package/dist/schemas/needs.js.map +1 -1
  128. package/dist/schemas/organisation.d.ts +164 -0
  129. package/dist/schemas/organisation.d.ts.map +1 -1
  130. package/dist/schemas/organisation.js +17 -0
  131. package/dist/schemas/organisation.js.map +1 -1
  132. package/dist/schemas/personas.d.ts.map +1 -1
  133. package/dist/schemas/personas.js +2 -2
  134. package/dist/schemas/personas.js.map +1 -1
  135. package/dist/schemas/providers/handoff.d.ts +24 -0
  136. package/dist/schemas/providers/handoff.d.ts.map +1 -1
  137. package/dist/schemas/providers/handoff.js +32 -0
  138. package/dist/schemas/providers/handoff.js.map +1 -1
  139. package/dist/schemas/providers/usage.d.ts +6 -0
  140. package/dist/schemas/providers/usage.d.ts.map +1 -1
  141. package/dist/schemas/providers/usage.js +2 -0
  142. package/dist/schemas/providers/usage.js.map +1 -1
  143. package/dist/schemas/services.d.ts +24 -0
  144. package/dist/schemas/services.d.ts.map +1 -0
  145. package/dist/schemas/services.js +19 -0
  146. package/dist/schemas/services.js.map +1 -0
  147. package/dist/schemas/settings-experiments.d.ts.map +1 -1
  148. package/dist/schemas/settings-experiments.js +1 -1
  149. package/dist/schemas/settings-experiments.js.map +1 -1
  150. package/dist/schemas/settings.d.ts +2 -0
  151. package/dist/schemas/settings.d.ts.map +1 -1
  152. package/dist/schemas/settings.js +9 -3
  153. package/dist/schemas/settings.js.map +1 -1
  154. package/dist/schemas/tool-ceiling.d.ts +24 -0
  155. package/dist/schemas/tool-ceiling.d.ts.map +1 -0
  156. package/dist/schemas/tool-ceiling.js +86 -0
  157. package/dist/schemas/tool-ceiling.js.map +1 -0
  158. package/dist/schemas/workspace/workspace-search.d.ts +93 -0
  159. package/dist/schemas/workspace/workspace-search.d.ts.map +1 -1
  160. package/dist/schemas/workspace/workspace-search.js +10 -0
  161. package/dist/schemas/workspace/workspace-search.js.map +1 -1
  162. package/dist/state/definition.d.ts +4 -0
  163. package/dist/state/definition.d.ts.map +1 -1
  164. package/dist/state/locked-folders.d.ts +2 -0
  165. package/dist/state/locked-folders.d.ts.map +1 -0
  166. package/dist/state/locked-folders.js +11 -0
  167. package/dist/state/locked-folders.js.map +1 -0
  168. package/dist/state/runtime-state.d.ts +3 -0
  169. package/dist/state/runtime-state.d.ts.map +1 -1
  170. package/dist/state/runtime-state.js +1 -0
  171. package/dist/state/runtime-state.js.map +1 -1
  172. package/dist/text/land-rows.d.ts.map +1 -1
  173. package/dist/text/land-rows.js +5 -2
  174. package/dist/text/land-rows.js.map +1 -1
  175. package/dist/text/notice-rows.d.ts +8 -0
  176. package/dist/text/notice-rows.d.ts.map +1 -0
  177. package/dist/text/notice-rows.js +14 -0
  178. package/dist/text/notice-rows.js.map +1 -0
  179. package/dist/text/transcript-fold.d.ts.map +1 -1
  180. package/dist/text/transcript-fold.js +25 -26
  181. package/dist/text/transcript-fold.js.map +1 -1
  182. package/package.json +5 -5
  183. package/src/contracts/access-profiles.contract.ts +43 -0
  184. package/src/contracts/agents.contract.ts +21 -0
  185. package/src/contracts/needs.contract.ts +14 -0
  186. package/src/contracts/services.contract.ts +40 -0
  187. package/src/contracts/workspace.contract.ts +15 -1
  188. package/src/events/agent-events.ts +11 -1
  189. package/src/events/sandbox-notice.ts +17 -1
  190. package/src/events/tool-update.ts +18 -0
  191. package/src/events/transcript.ts +5 -0
  192. package/src/index.ts +4 -0
  193. package/src/models/device-deadlines.ts +62 -0
  194. package/src/models/model-roles.ts +2 -2
  195. package/src/models/model-setups.ts +3 -4
  196. package/src/policy/control-scopes.ts +5 -0
  197. package/src/policy/org-locks.ts +5 -2
  198. package/src/protocol/member-reach.test.ts +221 -0
  199. package/src/protocol/member-reach.ts +78 -0
  200. package/src/protocol/raw/raw-json-routes.ts +15 -1
  201. package/src/protocol/raw/raw-routes.ts +12 -4
  202. package/src/schemas/access-profiles.test.ts +50 -0
  203. package/src/schemas/access-profiles.ts +104 -0
  204. package/src/schemas/agents.ts +30 -0
  205. package/src/schemas/automations.ts +15 -1
  206. package/src/schemas/dev-rebuild-log.test.ts +46 -1
  207. package/src/schemas/dev-rebuild-log.ts +71 -3
  208. package/src/schemas/device-commands.ts +30 -2
  209. package/src/schemas/environment.ts +31 -0
  210. package/src/schemas/links.ts +13 -2
  211. package/src/schemas/members.ts +59 -1
  212. package/src/schemas/needs.ts +4 -0
  213. package/src/schemas/organisation.ts +25 -0
  214. package/src/schemas/personas.ts +15 -11
  215. package/src/schemas/providers/handoff.test.ts +23 -1
  216. package/src/schemas/providers/handoff.ts +49 -0
  217. package/src/schemas/providers/usage.ts +4 -0
  218. package/src/schemas/services.ts +32 -0
  219. package/src/schemas/settings-experiments.ts +5 -1
  220. package/src/schemas/settings.test.ts +23 -1
  221. package/src/schemas/settings.ts +17 -4
  222. package/src/schemas/shared.ts +1 -1
  223. package/src/schemas/tool-ceiling.test.ts +70 -0
  224. package/src/schemas/tool-ceiling.ts +113 -0
  225. package/src/schemas/workspace/workspace-search.ts +16 -0
  226. package/src/state/locked-folders.test.ts +29 -0
  227. package/src/state/locked-folders.ts +17 -0
  228. package/src/state/runtime-state.ts +5 -0
  229. package/src/state/workspace-state.ts +1 -1
  230. package/src/text/land-rows.ts +6 -2
  231. package/src/text/notice-rows.ts +21 -0
  232. package/src/text/transcript-fold.test.ts +102 -2
  233. package/src/text/transcript-fold.ts +29 -30
@@ -0,0 +1,78 @@
1
+ import type { AgentAccess } from "../schemas/members.js";
2
+ import { type MemberRole, roleAtLeast } from "../schemas/shared.js";
3
+ import { defaultFloor } from "./route-meta.js";
4
+ import { isAttachmentPath } from "../state/workspace-state.js";
5
+ import { sandboxRouteFor } from "../index.js";
6
+
7
+ // Role floors: the minimum trust tier each route demands, read from the route's own RouteMeta (route-meta.ts). One
8
+ // function for both sides: the daemon's bearer middleware refuses with it right after the caller's role resolves, and
9
+ // the editor asks it before sending, so a request the daemon would refuse is never sent and the two cannot disagree.
10
+ // A floor, not the whole answer: operating routes still keep their own in-route maintainer gates; membership stays
11
+ // owner-only.
12
+
13
+ // `target` is the upload's `?path=`, written by the caller: isAttachmentPath folds `..` first, so a traversal out of
14
+ // the attachments dir never buys an attachment's floor.
15
+ const attachment = (target: string | undefined): boolean => target !== undefined && isAttachmentPath(target);
16
+
17
+ // Why a member was refused, in a word the editor can act on without reading the sentence: below the route's tier,
18
+ // running agents is off for them, or a guest asking for a door not on its list.
19
+ export type MemberRefusalReason = "floor" | "agents-off" | "guest";
20
+
21
+ // The body of that refusal, as the daemon sends it and as the editor predicts it before sending.
22
+ export interface MemberRefusal {
23
+ readonly error: string;
24
+ readonly floor: MemberRole;
25
+ readonly reason: MemberRefusalReason;
26
+ }
27
+
28
+ // The one refusal the bearer middleware hands a verified member: the tier a route wants, or a guest asking for a door
29
+ // not on its list. Undefined admits. `target` is the upload's `?path=`, the one route whose floor depends on where
30
+ // the bytes land.
31
+ export const memberRefusal = (
32
+ caller: {
33
+ readonly role: MemberRole;
34
+ readonly areas?: readonly string[] | undefined;
35
+ readonly agents?: AgentAccess | undefined;
36
+ readonly lands?: true | undefined;
37
+ },
38
+ method: string,
39
+ path: string,
40
+ target?: string,
41
+ ): MemberRefusal | undefined => {
42
+ if (caller.role === "guest") {
43
+ return guestReach(method, path, target) || homeReach(caller, method, path)
44
+ ? undefined
45
+ : { error: "not open to a guest member", floor: "viewer", reason: "guest" };
46
+ }
47
+ const floor = routeFloor(method, path, target);
48
+ if (!roleAtLeast(caller.role, floor)) {
49
+ return { error: `${floor} access required`, floor, reason: "floor" };
50
+ }
51
+ // The collaborator floor is driving agents. A person who edits files by hand without running agents holds the
52
+ // writer tier, which clears that floor by rank: their own answer keeps them off it.
53
+ return floor === "collaborator" && caller.agents === "off" ? { error: "running agents is not on for you here", floor, reason: "agents-off" } : undefined;
54
+ };
55
+
56
+ // Whether a guest member may reach this request at all: a route on the guest's list, or an upload into the attachments
57
+ // that ride with its own message. A route added later is closed to a guest until it says otherwise.
58
+ export const guestReach = (method: string, path: string, target?: string): boolean => {
59
+ const meta = sandboxRouteFor(method, path)?.meta;
60
+ return meta?.guest === true || (meta?.attachmentFloor !== undefined && attachment(target));
61
+ };
62
+
63
+ // What a home-only guest reaches beyond the guest list: the land press, when their home lands by itself (`landsHere`),
64
+ // which the route then admits on that home alone (conversations/home/home-conversation.ts refuseUnlessHome).
65
+ const homeReach = (caller: { readonly agents?: AgentAccess | undefined; readonly lands?: true | undefined }, method: string, path: string): boolean =>
66
+ caller.agents === "home" && caller.lands === true && homeLandReach(method, path);
67
+
68
+ // Whether a route is the land press a home-only member who lands may make (route-meta.ts `home`).
69
+ export const homeLandReach = (method: string, path: string): boolean => sandboxRouteFor(method, path)?.meta.home === "land";
70
+
71
+ // `target` is the workspace path a byte-write addresses (upload's `?path=`); absent for every other route.
72
+ export const routeFloor = (method: string, path: string, target?: string): MemberRole => {
73
+ const meta = sandboxRouteFor(method, path)?.meta;
74
+ if (meta?.attachmentFloor !== undefined && attachment(target)) {
75
+ return meta.attachmentFloor;
76
+ }
77
+ return meta?.floor ?? defaultFloor(method);
78
+ };
@@ -7,6 +7,7 @@ import {
7
7
  BundleTicketSchema,
8
8
  EnvironmentApproveSchema,
9
9
  EnvironmentContentsSchema,
10
+ EnvironmentDevSwapWhenIdleSchema,
10
11
  EnvironmentRebuildWhenIdleSchema,
11
12
  EnvironmentRemoveSchema,
12
13
  EnvironmentRuntimeDecisionSchema,
@@ -15,7 +16,15 @@ import {
15
16
  import { SyncStatusSchema } from "../../schemas/devices.js";
16
17
  import { HostsListSchema } from "../../schemas/hosts.js";
17
18
  import { VoicesViewSchema } from "../../schemas/voice.js";
18
- import { MemberEmailSchema, MemberGrantSchema, MemberSelfSchema, MembersListSchema, MembersRosterSchema } from "../../schemas/members.js";
19
+ import {
20
+ AccessAskSchema,
21
+ AccessRequestsSchema,
22
+ MemberEmailSchema,
23
+ MemberGrantSchema,
24
+ MemberSelfSchema,
25
+ MembersListSchema,
26
+ MembersRosterSchema,
27
+ } from "../../schemas/members.js";
19
28
  import { PhonesListSchema, PhoneWakeRegistrationSchema } from "../../schemas/phone.js";
20
29
  import {
21
30
  PhoneKeyringsResultSchema,
@@ -99,6 +108,9 @@ export const RAW_JSON_ROUTES = {
99
108
  "DELETE /members": { input: MemberEmailSchema, output: MembersListSchema },
100
109
  "DELETE /members/self": { output: OkSchema },
101
110
  "GET /members/self": { output: MemberSelfSchema },
111
+ "POST /members/requests": { input: AccessAskSchema, output: MemberSelfSchema },
112
+ "GET /members/requests": { output: AccessRequestsSchema },
113
+ "DELETE /members/requests": { input: MemberEmailSchema, output: AccessRequestsSchema },
102
114
  // Every environment write answers the environment after it. `/environment/contents` takes `?refresh` to probe again.
103
115
  "GET /environment": { output: EnvironmentSchema },
104
116
  "GET /environment/contents": { output: EnvironmentContentsSchema },
@@ -108,6 +120,8 @@ export const RAW_JSON_ROUTES = {
108
120
  "POST /environment/remove": { input: EnvironmentRemoveSchema, output: EnvironmentSchema },
109
121
  "POST /environment/rebuild-when-idle": { input: EnvironmentRebuildWhenIdleSchema, output: EnvironmentSchema },
110
122
  "DELETE /environment/rebuild-when-idle": { output: EnvironmentSchema },
123
+ "POST /environment/dev-swap-when-idle": { input: EnvironmentDevSwapWhenIdleSchema, output: EnvironmentSchema },
124
+ "DELETE /environment/dev-swap-when-idle": { output: EnvironmentSchema },
111
125
  "GET /engines": { output: EnginesViewSchema },
112
126
  "POST /engines/channel": { input: EngineChannelInputSchema, output: EngineWriteResultSchema },
113
127
  "POST /engines/update": { input: EngineUpdateInputSchema, output: EngineWriteResultSchema },
@@ -84,13 +84,19 @@ export const RAW_ROUTES = {
84
84
  "GET /intake/{id}/config": { auth: "door", embedded: true },
85
85
  "GET /intake/{id}/challenge": { auth: "door", embedded: true },
86
86
  "POST /intake/{id}/report": { auth: "door", embedded: true },
87
- // The roster is ownership's to change; giving up one's own grant is every tier's.
88
- "GET /members": { control: "never" },
87
+ // The roster is ownership's to read and change; giving up one's own grant is every tier's. Reading it is floored at
88
+ // the owner here as well as in its handler (members.routes.ts), so the editor knows before asking.
89
+ "GET /members": { floor: "owner", control: "never" },
89
90
  "POST /members": { control: "never" },
90
91
  "DELETE /members": { control: "never" },
91
92
  "DELETE /members/self": { floor: "viewer", guest: true, control: "never" },
92
93
  // What one's own grant allows, read by the editor to offer only what will be taken.
93
94
  "GET /members/self": { floor: "viewer", guest: true, control: "never" },
95
+ // Asking the owner for more access is every member's, a guest's included, from wherever they were refused; reading
96
+ // and dismissing the requests is the owner's, beside the roster they are answered on (schemas/members.ts).
97
+ "POST /members/requests": { floor: "viewer", guest: true, control: "never" },
98
+ "GET /members/requests": { floor: "owner", control: "never" },
99
+ "DELETE /members/requests": { floor: "owner", control: "never" },
94
100
  // The owner's Reconnect: register with the platform now, having it adopt the sandbox first when it holds no record.
95
101
  "POST /platform/relink": { control: "never" },
96
102
  "GET /environment": {},
@@ -101,11 +107,13 @@ export const RAW_ROUTES = {
101
107
  "POST /environment/remove": {},
102
108
  "POST /environment/rebuild-when-idle": {},
103
109
  "DELETE /environment/rebuild-when-idle": {},
110
+ "POST /environment/dev-swap-when-idle": {},
111
+ "DELETE /environment/dev-swap-when-idle": {},
104
112
  "GET /engines": {},
105
113
  "POST /engines/channel": {},
106
114
  "POST /engines/update": {},
107
115
  "POST /engines/revert": {},
108
- "GET /bundles": { control: "never" },
116
+ "GET /bundles": { floor: "maintainer", control: "never" },
109
117
  "POST /bundles": { control: "never" },
110
118
  "DELETE /bundles": { control: "never" },
111
119
  "POST /bundles/ticket": { control: "never" },
@@ -265,7 +273,7 @@ export const RAW_ROUTES = {
265
273
  "POST /link/conversations/{id}/answer": { auth: "door", control: "never" },
266
274
  "POST /link/conversations/{id}/stop": { auth: "door", control: "never" },
267
275
  "POST /system/control/tokens": { control: "never" },
268
- "GET /system/control/tokens": { control: "never" },
276
+ "GET /system/control/tokens": { floor: "maintainer", control: "never" },
269
277
  "DELETE /system/control/tokens/{id}": { control: "never" },
270
278
  // One's own passkeys are identity, like staying signed in; the policy and recovery codes are ownership's.
271
279
  "GET /system/passkeys": { guest: true, control: "never" },
@@ -0,0 +1,50 @@
1
+ import { AccessProfileSchema, profileAccess } from "./access-profiles.js";
2
+ import { accessRefusal, tierOf } from "./members.js";
3
+
4
+ // A profile reads like a roster row that never manages: `run` when it does not say, no hand edits for a chat or a home,
5
+ // and the tier its holders get is what those answers add up to.
6
+
7
+ describe(`profileAccess`, () => {
8
+ it(`runs agents when it does not say, and edits nowhere`, () => {
9
+ expect(profileAccess({})).toEqual({ manage: false, agents: `run`, see: undefined, edit: `none` });
10
+ expect(tierOf(profileAccess({}))).toBe(`collaborator`);
11
+ });
12
+
13
+ it(`makes the tier its answers add up to`, () => {
14
+ expect(tierOf(profileAccess({ agents: `chat`, areas: [`support`] }))).toBe(`guest`);
15
+ expect(tierOf(profileAccess({ agents: `off` }))).toBe(`viewer`);
16
+ expect(tierOf(profileAccess({ agents: `run`, areas: [`web`], edit: [`web`] }))).toBe(`writer`);
17
+ });
18
+
19
+ it(`never lets a chat or a home edit by hand, and keeps lands for a home alone`, () => {
20
+ expect(profileAccess({ agents: `chat`, areas: [`support`], edit: `all` }).edit).toBe(`none`);
21
+ expect(profileAccess({ agents: `home`, lands: true })).toEqual({ manage: false, agents: `home`, see: undefined, edit: `none`, lands: true });
22
+ expect(profileAccess({ agents: `run`, lands: true })).toEqual({ manage: false, agents: `run`, see: undefined, edit: `none` });
23
+ });
24
+
25
+ it(`refuses what a grant would refuse`, () => {
26
+ expect(accessRefusal(profileAccess({ agents: `chat` }))).toBe(
27
+ `chatting with assistants needs at least one area: the assistants that work there are the ones they talk to`,
28
+ );
29
+ expect(accessRefusal(profileAccess({ areas: [`web`], edit: [`ops`] }))).toBe(`they can only edit where they can see: ops is not among their areas`);
30
+ });
31
+ });
32
+
33
+ describe(`AccessProfileSchema`, () => {
34
+ it(`takes a profile naming only an id, which limits nothing`, () => {
35
+ expect(AccessProfileSchema.parse({ id: `everyone` })).toEqual({ id: `everyone` });
36
+ });
37
+
38
+ it(`keeps every answer it is given`, () => {
39
+ const profile = {
40
+ id: `marketing`,
41
+ label: `Marketing`,
42
+ areas: [`site`],
43
+ credentials: { capabilities: [`reddit-work`], secrets: [] },
44
+ aiAccounts: [`claude:work`],
45
+ tools: { shell: false },
46
+ assistants: [`copywriter`],
47
+ };
48
+ expect(AccessProfileSchema.parse(profile)).toEqual(profile);
49
+ });
50
+ });
@@ -0,0 +1,104 @@
1
+ import { z } from "zod";
2
+ import { entryId } from "./internal.js";
3
+ import {
4
+ type AgentAccess,
5
+ AgentAccessSchema,
6
+ AiAccountKeySchema,
7
+ CredentialReachSchema,
8
+ type EditScope,
9
+ EditScopeSchema,
10
+ type MemberAccess,
11
+ } from "./members.js";
12
+ import { GrantedRoleSchema } from "./shared.js";
13
+ import { ToolCeilingSchema } from "./tool-ceiling.js";
14
+
15
+ // AN ACCESS PROFILE: the hard half of access, named and reusable (docs/architecture/access.md). One shape serves every
16
+ // kind of principal: a person holds one instead of answers of their own, and a service (schemas/services.ts) holds one
17
+ // to narrow what it does for its steward. So an intern and the marketing bot can be pointed at the same thing, and
18
+ // widening what both may spend is one edit.
19
+ // Every answer means what the same field on a roster row means (schemas/members.ts), absent included: absent areas is
20
+ // the whole workspace, absent credentials every one, absent AI accounts every one, absent tools no limit. `agents`,
21
+ // `edit`, `lands` and `assistants` are a person's answers and mean nothing for a service, which drives no editor.
22
+ // A profile cannot make a maintainer: that tier holds the owner's operating authority and is granted to a person,
23
+ // never through something shared.
24
+ export const AccessProfileSchema = z.object({
25
+ id: entryId.describe("The profile's id, the name a roster row or a service points at."),
26
+ label: z.string().max(60).optional().describe("What to call it on screen. Absent falls back to the id."),
27
+ brief: z.string().max(200).optional().describe("What this access is for, in one line, so whoever grants it can tell what they are handing over."),
28
+ areas: z
29
+ .array(z.string().min(1))
30
+ .max(20)
31
+ .optional()
32
+ .describe("The areas its holders see and their agents work in. Absent means the whole workspace."),
33
+ agents: AgentAccessSchema.optional().describe(
34
+ "For a person: whether their conversations run agents (off, chat, run, home). Absent means run. A service ignores it.",
35
+ ),
36
+ edit: EditScopeSchema.optional().describe("For a person: where they change files by hand. Absent means nowhere. A service ignores it."),
37
+ lands: z
38
+ .boolean()
39
+ .optional()
40
+ .describe("For a home-only person: whether their home conversation lands its work by itself. Absent means no."),
41
+ credentials: CredentialReachSchema.optional().describe(
42
+ "The connected capabilities and stored secrets its holders' conversations may spend. Absent means every one, including any connected later.",
43
+ ),
44
+ aiAccounts: z
45
+ .array(AiAccountKeySchema)
46
+ .max(500)
47
+ .optional()
48
+ .describe("The AI accounts its holders' turns may run on, `provider:account` or a provider alone. Absent means every one."),
49
+ tools: ToolCeilingSchema.optional().describe("The most its holders' turns' tools may be; a persona only narrows inside it. Absent means no limit."),
50
+ assistants: z
51
+ .array(entryId)
52
+ .max(50)
53
+ .optional()
54
+ .describe("For a guest who chats: which assistants working in their areas they may talk to. Absent means every one that works there."),
55
+ });
56
+ export type AccessProfile = z.infer<typeof AccessProfileSchema>;
57
+
58
+ // Where a profile listed beside the sandbox's own came from: the sandbox, or the organisation it is bound to, whose
59
+ // profiles arrive with its policy (schemas/organisation.ts) and are read-only here.
60
+ export const AccessProfileOriginSchema = z.enum(["sandbox", "org"]);
61
+ export type AccessProfileOrigin = z.infer<typeof AccessProfileOriginSchema>;
62
+
63
+ export const AccessProfileEntrySchema = AccessProfileSchema.extend({
64
+ origin: AccessProfileOriginSchema.describe("The sandbox's own, or the organisation's, which nobody here can change."),
65
+ });
66
+ export type AccessProfileEntry = z.infer<typeof AccessProfileEntrySchema>;
67
+
68
+ export const AccessProfilesListSchema = z.object({
69
+ profiles: z.array(AccessProfileEntrySchema).describe("Every profile this sandbox grants: its own, then its organisation's."),
70
+ });
71
+ export type AccessProfilesList = z.infer<typeof AccessProfilesListSchema>;
72
+
73
+ export const AccessProfileIdParamSchema = z.object({ id: entryId.describe("Which profile.") });
74
+
75
+ // What a profile save answers: each person holding it, with the tier their rewritten row now makes, so the editor can
76
+ // bring the platform's copy of their tier along (the daemon only enforces its own).
77
+ export const AccessProfileHolderSchema = z.object({
78
+ email: z.string().describe("Who holds it, lowercased."),
79
+ role: GrantedRoleSchema.exclude(["maintainer"]).describe("The tier the profile makes for them now."),
80
+ });
81
+ export const AccessProfileSavedSchema = z.object({
82
+ ok: z.literal(true),
83
+ holders: z.array(AccessProfileHolderSchema).describe("The people whose rows were rewritten, with the tier each now holds."),
84
+ });
85
+ export type AccessProfileSaved = z.infer<typeof AccessProfileSavedSchema>;
86
+
87
+ // The fields of a profile that decide a person's access, in the shape `memberAccess` reads a row in.
88
+ interface ProfileAccessFields {
89
+ readonly areas?: readonly string[] | undefined;
90
+ readonly agents?: AgentAccess | undefined;
91
+ readonly edit?: EditScope | undefined;
92
+ readonly lands?: boolean | undefined;
93
+ }
94
+
95
+ /**
96
+ * The access a profile gives a person: never managing, `run` when it does not say, and no hand edits for a chatting or
97
+ * home-only one, as a roster row reads (schemas/members.ts `memberAccess`). Its tier is `tierOf` of this.
98
+ */
99
+ export const profileAccess = (profile: ProfileAccessFields): MemberAccess => {
100
+ const agents = profile.agents ?? "run";
101
+ const handsOff = agents === "chat" || agents === "home";
102
+ const access: MemberAccess = { manage: false, agents, see: profile.areas, edit: handsOff ? "none" : (profile.edit ?? "none") };
103
+ return profile.lands === true && agents === "home" ? { ...access, lands: true } : access;
104
+ };
@@ -239,6 +239,19 @@ export type LandedMessageDraft = z.infer<typeof LandedMessageDraftSchema>;
239
239
  // offer the press that clears a refusal without knowing whose refusal it is.
240
240
  export const LandConflictReasonSchema = z.enum(["workspace", "diverged", "binary"]);
241
241
  export type LandConflictReason = z.infer<typeof LandConflictReasonSchema>;
242
+ // One land of a home conversation's, as committed: the land its transcript row names, and each repository's commit.
243
+ export const HomeCommitSchema = z.object({
244
+ land: z.string().describe("The land's id, as its `landed` transcript row names it."),
245
+ at: z.number().describe("When it was committed, in milliseconds."),
246
+ subject: z.string().describe("The commit's subject line."),
247
+ commits: z
248
+ .array(z.object({ repo: z.string().describe('Which repository: "root" for the workspace itself, else its folder.'), sha: z.string().describe("The commit, in full.") }))
249
+ .describe("The commit each repository the land reached took, in the order they were made."),
250
+ });
251
+ export type HomeCommit = z.infer<typeof HomeCommitSchema>;
252
+ // How many of a home's commits its card keeps.
253
+ export const HOME_COMMITS_KEPT = 20;
254
+
242
255
  export const AgentSummarySchema = z.object({
243
256
  id: z.string().describe("The conversation id, which is how every other call addresses it."),
244
257
  sessionId: z.string().optional().describe("The provider session behind the last turn. It is retired whenever the model or account changes."),
@@ -391,6 +404,23 @@ export const AgentSummarySchema = z.object({
391
404
  .describe(
392
405
  "This is its owner's home conversation in this sandbox: the one long-running chat the master view opens, which orchestrates its own subagents, holds their work until it accepts it, and lands and commits by itself. Only its owner and the sandbox's owner see it. Absent for every other conversation.",
393
406
  ),
407
+ // A home's own record of what its lands became in history (conversations/land/version-landed.ts): each land's commit,
408
+ // under the land id its transcript row names (`landed` notice), so the chat can say what was committed and offer its
409
+ // revert. The newest few only, newest last.
410
+ commits: z
411
+ .array(HomeCommitSchema)
412
+ .optional()
413
+ .describe(
414
+ "A home conversation's latest lands as they were committed, newest last: which land, when, under what subject, and the commit each repository took. Kept for the last few only. Absent for every other conversation.",
415
+ ),
416
+ // Set by Start fresh or Clear history (agents.startFresh / clearHistory) and cleared by the turn that opens the fresh
417
+ // session: what lets the chat say its next message starts over.
418
+ freshPending: z
419
+ .enum(["asked", "cleared"])
420
+ .optional()
421
+ .describe(
422
+ "A home conversation whose next message opens a fresh session, because its person asked (`asked`) or cleared its history (`cleared`). Absent once that message has gone, and for every other conversation.",
423
+ ),
394
424
  // Root repo's short base sha; per-repo bases stay daemon-internal.
395
425
  base: z.string().optional().describe("The commit its private copy started from, shortened."),
396
426
  costUsd: z.number().optional().describe("What it has cost so far, in dollars. A subagent's spend is its own and is not folded in here."),
@@ -308,6 +308,11 @@ export const SenderRuleSchema = z
308
308
  .optional()
309
309
  .describe("Group ids the service reports on a sender, a Discord role. Only for a source whose messages carry them."),
310
310
  actsAs: entryId.optional().describe("Which persona their wakes speak as. Absent is no persona: the full toolbox, reaching no account."),
311
+ // The service (schemas/services.ts) their wakes act as, in place of the automation's own: a narrower one for
312
+ // strangers, a wider one for people the owner trusts. Never more than that service's steward may.
313
+ runAs: entryId
314
+ .optional()
315
+ .describe("Which service their wakes act as, in place of the automation's own. Absent means the automation's own service."),
311
316
  // Tightens, never loosens: the automation's own `requireApproval` still holds everyone.
312
317
  requireApproval: z.boolean().optional().describe("Hold their wakes for a person, even when the automation itself does not."),
313
318
  })
@@ -397,8 +402,15 @@ export const AutomationSchema = z.object({
397
402
  // is watching to notice a stuck one.
398
403
  account: z.string().optional().describe("Which account pays for it."),
399
404
  // Absent means the wake reaches no logged-in account at all, the strictest default here, since nobody is at the
400
- // composer when it fires.
405
+ // composer when it fires. Posture only: what the wake may reach is `runAs`'s (docs/architecture/access.md).
401
406
  actsAs: entryId.optional().describe("Which persona it speaks as. An unwatched turn naming none reaches no signed-in account at all."),
407
+ // Who its wakes act for (schemas/services.ts): that service's steward, held to the service's access profile. Absent
408
+ // keeps what a wake always did: it acts for the sandbox's owner with no profile, its persona the only narrowing.
409
+ runAs: entryId
410
+ .optional()
411
+ .describe(
412
+ "Which service it acts as: whose authority its wakes use, held to that service's access profile. Absent means the sandbox's owner, limited only by its persona.",
413
+ ),
402
414
  // Listener triggers on a source that identifies senders only (TriggerSource.sender); refused elsewhere at upsert.
403
415
  // Absent means everyone the filters admit, wearing `actsAs`.
404
416
  senders: SendersSchema.optional().describe(
@@ -462,6 +474,8 @@ export const AutomationApprovalSchema = z.object({
462
474
  // The persona the fire resolved to (a sender rule's, or the automation's), snapshotted at hold time and worn by the
463
475
  // approved run; also what a project-scoped board files the wake under.
464
476
  actsAs: entryId.optional().describe("Which persona the approved run speaks as, decided when it was held."),
477
+ // The service the fire resolved to (a sender rule's, or the automation's), snapshotted beside the persona.
478
+ runAs: entryId.optional().describe("Which service the approved run acts as, decided when it was held."),
465
479
  createdAt: z.number().describe("When it started waiting, in milliseconds."),
466
480
  // When the daemon may run this itself, for a `holdForSeconds` hold; absent for a `requireApproval` hold, which only
467
481
  // the owner releases.
@@ -1,4 +1,15 @@
1
- import { DEV_REBUILD_EXIT_MARK, DEV_REBUILD_QUIET_MARK, devRebuildLogPath, readDevRebuildLog } from "./dev-rebuild-log.js";
1
+ import {
2
+ DEV_REBUILD_CANCEL_MARK,
3
+ DEV_REBUILD_EXIT_MARK,
4
+ DEV_REBUILD_HOLD_MARK,
5
+ DEV_REBUILD_QUIET_MARK,
6
+ DEV_REBUILD_SWAP_MARK,
7
+ DEV_REBUILD_TASKS_MARK,
8
+ DEV_REBUILD_WAITING_MARK,
9
+ devRebuildHoldPath,
10
+ devRebuildLogPath,
11
+ readDevRebuildLog,
12
+ } from "./dev-rebuild-log.js";
2
13
 
3
14
  // The one account a detached rebuild gives of itself. The daemon builds the shell that writes this text and the browser
4
15
  // draws what it means, so the grammar is pinned here, where both of them read it.
@@ -52,3 +63,37 @@ test("treats an answer with no marks as log text, not as an error", () => {
52
63
  test("names one log per sandbox, beside the logs ic writes for its own recreates", () => {
53
64
  expect(devRebuildLogPath("work-abc")).toBe("~/.intentic/logs/dev-rebuild-work-abc.log");
54
65
  });
66
+
67
+ test("reads the hold file's state and turbo's count, which the read prints before the tail", () => {
68
+ const log = readDevRebuildLog(answer("3", `${DEV_REBUILD_HOLD_MARK} 1`, `${DEV_REBUILD_TASKS_MARK} 23 -`, "@intentic/sandbox:build: $ tsc"));
69
+ expect(log).toMatchObject({ hold: true, tasks: { started: 23, total: undefined } });
70
+ expect(log.lines).toEqual(["@intentic/sandbox:build: $ tsc"]);
71
+ expect(readDevRebuildLog(answer("3", `${DEV_REBUILD_HOLD_MARK} 0`, `${DEV_REBUILD_TASKS_MARK} 48 48`))).toMatchObject({
72
+ hold: false,
73
+ tasks: { started: 48, total: 48 },
74
+ });
75
+ });
76
+
77
+ // An older daemon's read says neither, which is "unknown" rather than "not held": the card then offers no choice.
78
+ test("leaves the hold and the count unknown when the read does not print them", () => {
79
+ expect(readDevRebuildLog(answer("3", "building"))).toMatchObject({ hold: undefined, tasks: undefined });
80
+ });
81
+
82
+ // The gate's two words, in order: holding, then let through. Whichever came last is where it stands.
83
+ test("reads the gate holding until it says it let the swap through", () => {
84
+ const holding = readDevRebuildLog(answer("40", "#27 naming to intentic-sandbox:dev", DEV_REBUILD_WAITING_MARK));
85
+ expect(holding).toMatchObject({ waiting: true, swapping: false });
86
+ expect(holding.lines).toEqual(["#27 naming to intentic-sandbox:dev"]);
87
+ const through = readDevRebuildLog(answer("1", DEV_REBUILD_WAITING_MARK, DEV_REBUILD_SWAP_MARK, "intentic: [recreate] starting"));
88
+ expect(through).toMatchObject({ waiting: false, swapping: true });
89
+ });
90
+
91
+ test("reads a cancelled build as ended by somebody asking, not as a failure of its own", () => {
92
+ const log = readDevRebuildLog(answer("0", "#12 [builder 4/9] RUN pnpm install", "", DEV_REBUILD_CANCEL_MARK, `${DEV_REBUILD_EXIT_MARK} 130`));
93
+ expect(log).toMatchObject({ cancelled: true, exitCode: 130, waiting: false });
94
+ expect(log.lines).toEqual(["#12 [builder 4/9] RUN pnpm install"]);
95
+ });
96
+
97
+ test("keeps the gate's hold file beside the log it belongs to", () => {
98
+ expect(devRebuildHoldPath("work-abc")).toBe("~/.intentic/logs/dev-rebuild-work-abc.hold");
99
+ });
@@ -8,6 +8,15 @@
8
8
  // browser names the same path to a reader whose rebuild never came back.
9
9
  export const devRebuildLogPath = (slug: string): string => `~/.intentic/logs/dev-rebuild-${slug}.log`;
10
10
 
11
+ // THE SWAP GATE'S FILE. While it exists, ic stops a dev recreate after the images are built and before anything touches
12
+ // the container (INTENTIC_SWAP_GATE, recreate.rs), and waits for it to go. `dev-rebuild-hold` makes it, `dev-rebuild-release`
13
+ // removes it, and `dev-rebuild` clears one a previous run left behind before it starts.
14
+ export const devRebuildHoldPath = (slug: string): string => `~/.intentic/logs/dev-rebuild-${slug}.hold`;
15
+
16
+ // The build's process: its session leader, written by the build's own shell as it starts, so `dev-rebuild-cancel` can
17
+ // stop the whole tree (pnpm, turbo, docker's client, ic) rather than the one shell it would otherwise know about.
18
+ export const devRebuildPidPath = (slug: string): string => `~/.intentic/logs/dev-rebuild-${slug}.pid`;
19
+
11
20
  // The build's own shell appends this when the build ends, with its exit status: since the log outlives the daemon, the
12
21
  // container and the page that started it, this mark is the only thing that can say a rebuild is OVER rather than slow.
13
22
  export const DEV_REBUILD_EXIT_MARK = "@intentic-rebuild-exit";
@@ -15,6 +24,27 @@ export const DEV_REBUILD_EXIT_MARK = "@intentic-rebuild-exit";
15
24
  // that machine at all. A running build goes quiet for a minute at a time inside a docker layer; a build whose machine
16
25
  // slept never writes its exit mark, and only this tells the two apart.
17
26
  export const DEV_REBUILD_QUIET_MARK = "@intentic-rebuild-quiet";
27
+ // `dev-rebuild-log` prints whether the hold file is there right now: `1` held, `0` not. Absent from an older daemon's read.
28
+ export const DEV_REBUILD_HOLD_MARK = "@intentic-rebuild-hold";
29
+ // `dev-rebuild-log` prints how many of turbo's tasks have started in the WHOLE log, not the tail — the tail is 80 lines
30
+ // of a log that runs to thousands, so a count kept from it would miss most of them. Turbo names no total up front (its
31
+ // "Running build in N packages" is the packages in scope, a quarter of the tasks), so the total is `-` until turbo's own
32
+ // summary line says it at the end; a reader that remembers the last run's total is what gives "of 48" before then.
33
+ export const DEV_REBUILD_TASKS_MARK = "@intentic-rebuild-tasks";
34
+ // The gate's own words, printed into the log by ic: it is holding (built, waiting for the hold file to go), and it let
35
+ // the swap through. Past the second, the container is being replaced and nothing may stop the build any more.
36
+ export const DEV_REBUILD_WAITING_MARK = "@intentic-rebuild-waiting";
37
+ export const DEV_REBUILD_SWAP_MARK = "@intentic-rebuild-swap";
38
+ // `dev-rebuild-cancel` appends this, then an exit mark of 130, once it has stopped the build: a run that ended because
39
+ // somebody asked, rather than one that failed.
40
+ export const DEV_REBUILD_CANCEL_MARK = "@intentic-rebuild-cancelled";
41
+
42
+ export interface DevRebuildTasks {
43
+ /** Turbo's tasks that have started, cache hits included. */
44
+ readonly started: number;
45
+ /** How many it runs in all, once its summary has said; undefined before. */
46
+ readonly total: number | undefined;
47
+ }
18
48
 
19
49
  export interface DevRebuildLog {
20
50
  /** Nothing has ever rebuilt this sandbox from a checkout on that machine. */
@@ -23,30 +53,66 @@ export interface DevRebuildLog {
23
53
  readonly quietFor: number | undefined;
24
54
  /** The build's own exit status, present only once it has ended. */
25
55
  readonly exitCode: number | undefined;
26
- /** The tail as the machine printed it, both marks removed. */
56
+ /** Ended because somebody cancelled it (`dev-rebuild-cancel`), not because it failed. */
57
+ readonly cancelled: boolean;
58
+ /** Whether the hold file is there; undefined from a daemon too old to say. */
59
+ readonly hold: boolean | undefined;
60
+ /** The gate is holding right now: the images are built, the container untouched, the restart waiting to be let through. */
61
+ readonly waiting: boolean;
62
+ /** The gate let the swap through: the container is being replaced. */
63
+ readonly swapping: boolean;
64
+ /** Turbo's count, from the whole log; undefined from a daemon too old to count. */
65
+ readonly tasks: DevRebuildTasks | undefined;
66
+ /** The tail as the machine printed it, every mark removed. */
27
67
  readonly lines: readonly string[];
28
68
  }
29
69
 
30
70
  // Reads `dev-rebuild-log`'s stdout. Shared rather than parsed at the reader, so the shell line that produces this and the
31
71
  // card that draws it cannot drift apart. Unparseable is never an error: an answer with no marks at all is simply a log
32
72
  // with nothing to say yet.
33
- const markValue = (line: string, mark: string): string | undefined => (line.startsWith(`${mark} `) ? line.slice(mark.length + 1).trim() : undefined);
73
+ const markValue = (line: string, mark: string): string | undefined =>
74
+ line === mark ? `` : line.startsWith(`${mark} `) ? line.slice(mark.length + 1).trim() : undefined;
34
75
  const wholeNumber = (value: string): number | undefined => (/^\d+$/.test(value) ? Number(value) : undefined);
35
76
 
77
+ const readTasks = (value: string): DevRebuildTasks | undefined => {
78
+ const [started, total] = value.split(/\s+/);
79
+ const count = wholeNumber(started ?? ``);
80
+ return count === undefined ? undefined : { started: count, total: wholeNumber(total ?? ``) };
81
+ };
82
+
36
83
  export const readDevRebuildLog = (text: string): DevRebuildLog => {
37
84
  let missing = false;
38
85
  let quietFor: number | undefined;
39
86
  let exitCode: number | undefined;
87
+ let cancelled = false;
88
+ let hold: boolean | undefined;
89
+ let tasks: DevRebuildTasks | undefined;
90
+ // The last of the gate's two words: the tail is in order, so whichever came last is where the gate stands.
91
+ let gate: `waiting` | `swap` | undefined;
92
+ let swapping = false;
40
93
  const lines: string[] = [];
41
94
  for (const line of text.split(/\r?\n/)) {
42
95
  const quiet = markValue(line, DEV_REBUILD_QUIET_MARK);
43
96
  const exit = markValue(line, DEV_REBUILD_EXIT_MARK);
97
+ const held = markValue(line, DEV_REBUILD_HOLD_MARK);
98
+ const counted = markValue(line, DEV_REBUILD_TASKS_MARK);
44
99
  if (quiet !== undefined) {
45
100
  missing = quiet === "-";
46
101
  quietFor = wholeNumber(quiet);
47
102
  } else if (exit !== undefined) {
48
103
  // A mark whose status is unreadable still means the build ENDED, and not well.
49
104
  exitCode = wholeNumber(exit) ?? 1;
105
+ } else if (held !== undefined) {
106
+ hold = held === `1`;
107
+ } else if (counted !== undefined) {
108
+ tasks = readTasks(counted);
109
+ } else if (markValue(line, DEV_REBUILD_CANCEL_MARK) !== undefined) {
110
+ cancelled = true;
111
+ } else if (markValue(line, DEV_REBUILD_WAITING_MARK) !== undefined) {
112
+ gate = `waiting`;
113
+ } else if (markValue(line, DEV_REBUILD_SWAP_MARK) !== undefined) {
114
+ gate = `swap`;
115
+ swapping = true;
50
116
  } else {
51
117
  lines.push(line);
52
118
  }
@@ -54,5 +120,7 @@ export const readDevRebuildLog = (text: string): DevRebuildLog => {
54
120
  while (lines.at(-1)?.trim() === "") {
55
121
  lines.pop();
56
122
  }
57
- return { missing, quietFor, exitCode, lines };
123
+ // A gate still holding has printed nothing since its word, and a build that ended is holding nothing.
124
+ const waiting = gate === `waiting` && exitCode === undefined;
125
+ return { missing, quietFor, exitCode, cancelled, hold, waiting, swapping, tasks, lines };
58
126
  };
@@ -16,17 +16,45 @@ export const DeviceCommandSchema = z.enum([
16
16
  "dev-restart",
17
17
  "dev-rebuild",
18
18
  "dev-rebuild-log",
19
+ // The rebuild's three levers, each a file beside its log on the machine (dev-rebuild-log.ts): hold the restart at
20
+ // the swap gate, let it through, or stop the build before the gate is passed.
21
+ "dev-rebuild-hold",
22
+ "dev-rebuild-release",
23
+ "dev-rebuild-cancel",
19
24
  "sync-install",
20
25
  ]);
21
26
  export type DeviceCommand = z.infer<typeof DeviceCommandSchema>;
22
27
  // The reversible sync switches: the subset a device's own row drives with a pair of buttons, as opposed to the two
23
28
  // commands a card elsewhere issues once. Its own type so those button tables stay total without carrying entries for
24
29
  // commands they can never send.
25
- export const DeviceSyncSwitchSchema = DeviceCommandSchema.exclude(["dev-restart", "dev-rebuild", "dev-rebuild-log", "sync-install", "sync-clean"]);
30
+ export const DeviceSyncSwitchSchema = DeviceCommandSchema.exclude([
31
+ "dev-restart",
32
+ "dev-rebuild",
33
+ "dev-rebuild-log",
34
+ "dev-rebuild-hold",
35
+ "dev-rebuild-release",
36
+ "dev-rebuild-cancel",
37
+ "sync-install",
38
+ "sync-clean",
39
+ ]);
26
40
  export type DeviceSyncSwitch = z.infer<typeof DeviceSyncSwitchSchema>;
27
41
 
28
42
  // Where a detached rebuild reports itself, and the reader of that report (dev-rebuild-log.ts).
29
- export { DEV_REBUILD_EXIT_MARK, DEV_REBUILD_QUIET_MARK, type DevRebuildLog, devRebuildLogPath, readDevRebuildLog } from "./dev-rebuild-log.js";
43
+ export {
44
+ DEV_REBUILD_CANCEL_MARK,
45
+ DEV_REBUILD_EXIT_MARK,
46
+ DEV_REBUILD_HOLD_MARK,
47
+ DEV_REBUILD_QUIET_MARK,
48
+ DEV_REBUILD_SWAP_MARK,
49
+ DEV_REBUILD_TASKS_MARK,
50
+ DEV_REBUILD_WAITING_MARK,
51
+ type DevRebuildLog,
52
+ type DevRebuildTasks,
53
+ devRebuildHoldPath,
54
+ devRebuildLogPath,
55
+ devRebuildPidPath,
56
+ readDevRebuildLog,
57
+ } from "./dev-rebuild-log.js";
30
58
 
31
59
  // Machine's sandbox id (absent = every paired sandbox); must start alphanumeric, else it parses as a CLI flag.
32
60
  export const DeviceSandboxIdSchema = z