@intentic/sandbox-contract 1.364.0 → 1.366.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 (138) hide show
  1. package/README.md +3 -0
  2. package/dist/contracts/agents.contract.d.ts +253 -0
  3. package/dist/contracts/agents.contract.d.ts.map +1 -1
  4. package/dist/contracts/agents.contract.js +18 -0
  5. package/dist/contracts/agents.contract.js.map +1 -1
  6. package/dist/contracts/needs.contract.d.ts +232 -0
  7. package/dist/contracts/needs.contract.d.ts.map +1 -1
  8. package/dist/contracts/needs.contract.js +11 -1
  9. package/dist/contracts/needs.contract.js.map +1 -1
  10. package/dist/contracts/runner.contract.d.ts +32 -0
  11. package/dist/contracts/runner.contract.d.ts.map +1 -1
  12. package/dist/contracts/settings.contract.d.ts +2 -0
  13. package/dist/contracts/settings.contract.d.ts.map +1 -1
  14. package/dist/contracts/system.contract.d.ts +33 -0
  15. package/dist/contracts/system.contract.d.ts.map +1 -1
  16. package/dist/contracts/workspace.contract.d.ts +232 -0
  17. package/dist/contracts/workspace.contract.d.ts.map +1 -1
  18. package/dist/contracts/workspace.contract.js +12 -1
  19. package/dist/contracts/workspace.contract.js.map +1 -1
  20. package/dist/events/agent-events.d.ts +14 -0
  21. package/dist/events/agent-events.d.ts.map +1 -1
  22. package/dist/events/agent-events.js +5 -1
  23. package/dist/events/agent-events.js.map +1 -1
  24. package/dist/events/sandbox-notice.d.ts +14 -0
  25. package/dist/events/sandbox-notice.d.ts.map +1 -1
  26. package/dist/events/sandbox-notice.js +13 -1
  27. package/dist/events/sandbox-notice.js.map +1 -1
  28. package/dist/events/system-events.d.ts +26 -0
  29. package/dist/events/system-events.d.ts.map +1 -1
  30. package/dist/events/tool-update.d.ts +6 -0
  31. package/dist/events/tool-update.d.ts.map +1 -0
  32. package/dist/events/tool-update.js +12 -0
  33. package/dist/events/tool-update.js.map +1 -0
  34. package/dist/events/transcript.d.ts +1 -0
  35. package/dist/events/transcript.d.ts.map +1 -1
  36. package/dist/events/transcript.js +4 -0
  37. package/dist/events/transcript.js.map +1 -1
  38. package/dist/index.d.ts +752 -0
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/models/device-deadlines.d.ts +34 -0
  41. package/dist/models/device-deadlines.d.ts.map +1 -0
  42. package/dist/models/device-deadlines.js +28 -0
  43. package/dist/models/device-deadlines.js.map +1 -0
  44. package/dist/protocol/member-reach.d.ts +18 -0
  45. package/dist/protocol/member-reach.d.ts.map +1 -0
  46. package/dist/protocol/member-reach.js +31 -0
  47. package/dist/protocol/member-reach.js.map +1 -0
  48. package/dist/protocol/raw/raw-json-routes.d.ts +114 -0
  49. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  50. package/dist/protocol/raw/raw-json-routes.js +4 -1
  51. package/dist/protocol/raw/raw-json-routes.js.map +1 -1
  52. package/dist/protocol/raw/raw-routes.d.ts +16 -0
  53. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  54. package/dist/protocol/raw/raw-routes.js +6 -3
  55. package/dist/protocol/raw/raw-routes.js.map +1 -1
  56. package/dist/schemas/agents-list.d.ts +26 -0
  57. package/dist/schemas/agents-list.d.ts.map +1 -1
  58. package/dist/schemas/agents.d.ts +50 -0
  59. package/dist/schemas/agents.d.ts.map +1 -1
  60. package/dist/schemas/agents.js +17 -0
  61. package/dist/schemas/agents.js.map +1 -1
  62. package/dist/schemas/environment.d.ts +5 -0
  63. package/dist/schemas/environment.d.ts.map +1 -1
  64. package/dist/schemas/environment.js +3 -0
  65. package/dist/schemas/environment.js.map +1 -1
  66. package/dist/schemas/members.d.ts +52 -0
  67. package/dist/schemas/members.d.ts.map +1 -1
  68. package/dist/schemas/members.js +15 -0
  69. package/dist/schemas/members.js.map +1 -1
  70. package/dist/schemas/needs.d.ts +7 -0
  71. package/dist/schemas/needs.d.ts.map +1 -1
  72. package/dist/schemas/needs.js +3 -0
  73. package/dist/schemas/needs.js.map +1 -1
  74. package/dist/schemas/providers/handoff.d.ts +24 -0
  75. package/dist/schemas/providers/handoff.d.ts.map +1 -1
  76. package/dist/schemas/providers/handoff.js +32 -0
  77. package/dist/schemas/providers/handoff.js.map +1 -1
  78. package/dist/schemas/providers/usage.d.ts +6 -0
  79. package/dist/schemas/providers/usage.d.ts.map +1 -1
  80. package/dist/schemas/providers/usage.js +2 -0
  81. package/dist/schemas/providers/usage.js.map +1 -1
  82. package/dist/schemas/settings-experiments.d.ts.map +1 -1
  83. package/dist/schemas/settings-experiments.js +1 -1
  84. package/dist/schemas/settings-experiments.js.map +1 -1
  85. package/dist/schemas/settings.d.ts +2 -0
  86. package/dist/schemas/settings.d.ts.map +1 -1
  87. package/dist/schemas/settings.js +6 -0
  88. package/dist/schemas/settings.js.map +1 -1
  89. package/dist/schemas/workspace/workspace-search.d.ts +93 -0
  90. package/dist/schemas/workspace/workspace-search.d.ts.map +1 -1
  91. package/dist/schemas/workspace/workspace-search.js +10 -0
  92. package/dist/schemas/workspace/workspace-search.js.map +1 -1
  93. package/dist/state/definition.d.ts +4 -0
  94. package/dist/state/definition.d.ts.map +1 -1
  95. package/dist/state/runtime-state.d.ts +3 -0
  96. package/dist/state/runtime-state.d.ts.map +1 -1
  97. package/dist/state/runtime-state.js +1 -0
  98. package/dist/state/runtime-state.js.map +1 -1
  99. package/dist/text/land-rows.d.ts.map +1 -1
  100. package/dist/text/land-rows.js +5 -2
  101. package/dist/text/land-rows.js.map +1 -1
  102. package/dist/text/notice-rows.d.ts +8 -0
  103. package/dist/text/notice-rows.d.ts.map +1 -0
  104. package/dist/text/notice-rows.js +14 -0
  105. package/dist/text/notice-rows.js.map +1 -0
  106. package/dist/text/transcript-fold.d.ts.map +1 -1
  107. package/dist/text/transcript-fold.js +25 -26
  108. package/dist/text/transcript-fold.js.map +1 -1
  109. package/package.json +5 -5
  110. package/src/contracts/agents.contract.ts +21 -0
  111. package/src/contracts/needs.contract.ts +14 -0
  112. package/src/contracts/workspace.contract.ts +15 -1
  113. package/src/events/agent-events.ts +11 -1
  114. package/src/events/sandbox-notice.ts +17 -1
  115. package/src/events/tool-update.ts +18 -0
  116. package/src/events/transcript.ts +5 -0
  117. package/src/models/device-deadlines.ts +62 -0
  118. package/src/protocol/member-reach.test.ts +221 -0
  119. package/src/protocol/member-reach.ts +78 -0
  120. package/src/protocol/raw/raw-json-routes.ts +12 -1
  121. package/src/protocol/raw/raw-routes.ts +10 -4
  122. package/src/schemas/agents.ts +30 -0
  123. package/src/schemas/environment.ts +9 -0
  124. package/src/schemas/members.ts +34 -4
  125. package/src/schemas/needs.ts +4 -0
  126. package/src/schemas/providers/handoff.test.ts +23 -1
  127. package/src/schemas/providers/handoff.ts +49 -0
  128. package/src/schemas/providers/usage.ts +4 -0
  129. package/src/schemas/settings-experiments.ts +5 -1
  130. package/src/schemas/settings.ts +12 -0
  131. package/src/schemas/shared.ts +1 -1
  132. package/src/schemas/workspace/workspace-search.ts +16 -0
  133. package/src/state/runtime-state.ts +5 -0
  134. package/src/state/workspace-state.ts +1 -1
  135. package/src/text/land-rows.ts +6 -2
  136. package/src/text/notice-rows.ts +21 -0
  137. package/src/text/transcript-fold.test.ts +102 -2
  138. package/src/text/transcript-fold.ts +29 -30
@@ -66,6 +66,27 @@ export const agentsContract = {
66
66
  })
67
67
  .meta({ guest: true })
68
68
  .output(HomeConversationSchema),
69
+ // Your own home, like `home`: the id is the verified caller's, never a body's. Refused mid-turn, as a rewind is.
70
+ startFreshHome: procedure
71
+ .route({
72
+ method: "POST",
73
+ path: "/agents/home/fresh",
74
+ summary: "Start your home conversation fresh",
75
+ description:
76
+ "Makes your next message to your home conversation open a fresh session: a summary of the conversation where a model is set for hand-off summaries, its latest messages and the work it has in hand, instead of the whole conversation re-read on every call. Every message stays in the chat; only what the model reads starts over. It also starts fresh by itself once it grows past the sandbox's `homeFreshOver`. Refused while it is working.",
77
+ })
78
+ .meta({ floor: "collaborator", guest: true })
79
+ .output(OkSchema),
80
+ clearHomeHistory: procedure
81
+ .route({
82
+ method: "POST",
83
+ path: "/agents/home/clear",
84
+ summary: "Clear your home conversation's history",
85
+ description:
86
+ "Deletes every message of your home conversation and the saved points to go back to, and makes your next message open a fresh session that knows only the work it has in hand: its subagents and what they hold. Nothing it already landed or committed is touched, and neither are its subagents. Refused while it is working.",
87
+ })
88
+ .meta({ floor: "collaborator", guest: true })
89
+ .output(z.object({ dropped: z.number().describe("How many messages were deleted.") })),
69
90
  archived: procedure
70
91
  .route({
71
92
  method: "GET",
@@ -6,6 +6,7 @@ import {
6
6
  NeedIdParamSchema,
7
7
  NeedRaisedSchema,
8
8
  NeedRaiseSchema,
9
+ NeedReleaseInputSchema,
9
10
  NeedSchema,
10
11
  NeedSecretInputSchema,
11
12
  NeedsListSchema,
@@ -19,6 +20,9 @@ import {
19
20
 
20
21
  const agentDoor = procedure.meta({ agent: true, control: "never" });
21
22
  const answerRoute = procedure.meta({ floor: "maintainer", control: "never" });
23
+ // A release is the one need its gate answers rather than the tier: the owner names its approvers from the whole roster
24
+ // (secrets.routes.ts `releasableBy`), so any member may reach the route, and the need admits exactly the people it names.
25
+ const releaseRoute = procedure.meta({ floor: "viewer", control: "never" });
22
26
 
23
27
  export const needsContract = {
24
28
  ask: agentDoor
@@ -69,6 +73,16 @@ export const needsContract = {
69
73
  })
70
74
  .input(NeedAnswerInputSchema)
71
75
  .output(NeedSchema),
76
+ release: releaseRoute
77
+ .route({
78
+ method: "POST",
79
+ path: "/needs/{id}/release",
80
+ summary: "Release a gated credential, or decline",
81
+ description:
82
+ "A release need's answer, from one of the approvers its gate names, whatever their tier: release the credential to the conversation that asked, or decline. Any other need is answered through /needs/{id}/answer.",
83
+ })
84
+ .input(NeedReleaseInputSchema)
85
+ .output(NeedSchema),
72
86
  provideSecret: answerRoute
73
87
  .route({
74
88
  method: "POST",
@@ -1,4 +1,5 @@
1
1
  import { procedure } from "../protocol/route-meta.js";
2
+ import { streamOf } from "../protocol/stream-of.js";
2
3
  import { WorkspaceHealthQuerySchema, WorkspaceHealthSchema } from "../schemas/codebase-health.js";
3
4
  import { WorkspaceModulesSchema } from "../schemas/git/git.js";
4
5
  import { OkSchema } from "../schemas/shared.js";
@@ -16,7 +17,7 @@ import {
16
17
  WorkspaceSyncSchema,
17
18
  } from "../schemas/workspace/workspace-repos.js";
18
19
  import { PackageModulesParamSchema, PackageModulesSchema, WorkspaceGraphSchema } from "../schemas/workspace/workspace-graph.js";
19
- import { WorkspaceSearchQuerySchema, WorkspaceSearchResultSchema } from "../schemas/workspace/workspace-search.js";
20
+ import { WorkspaceSearchFrameSchema, WorkspaceSearchQuerySchema, WorkspaceSearchResultSchema } from "../schemas/workspace/workspace-search.js";
20
21
  import { WorkspaceInstallResultSchema, WorkspaceInstallSchema, WorkspaceSetupSchema } from "../schemas/workspace/workspace-setup.js";
21
22
  import {
22
23
  WorkspaceChildrenQuerySchema,
@@ -189,6 +190,19 @@ export const workspaceContract = {
189
190
  .meta({ guest: true, control: "editor" })
190
191
  .input(WorkspaceSearchQuerySchema)
191
192
  .output(WorkspaceSearchResultSchema),
193
+ // Text search only (`mode` find): the same first page, with the files found streamed ahead of it.
194
+ searchStream: procedure
195
+ .route({
196
+ method: "POST",
197
+ path: "/workspace/search/stream",
198
+ summary: "Search the text, watching it as it goes",
199
+ description:
200
+ "The plain-text search a search box runs, streamed: every file with a match is sent as soon as it is found, then the first page of the finished answer, exactly as the search route would have given it, with the cursor for the rest. Matches show while a search over a large tree is still reading it.",
201
+ })
202
+ // A read, POST only because it streams; held open for as long as the search runs.
203
+ .meta({ floor: "viewer", guest: true, stream: true, control: "editor" })
204
+ .input(WorkspaceSearchQuerySchema)
205
+ .output(streamOf(WorkspaceSearchFrameSchema)),
192
206
  // Per-file churn × complexity, index totals, top modules; scoped to a repo, not the whole /work drop.
193
207
  health: procedure
194
208
  .route({
@@ -11,7 +11,7 @@ import { AgentReplySchema, UsageWindowSchema } from "../schemas/providers/plan-l
11
11
  import { PrivacyBypassSchema } from "../schemas/privacy-egress.js";
12
12
  import { SubagentKindSchema, SubagentSdkRecordSchema, SubagentStatusSchema, SubagentVerificationSchema } from "../schemas/terminal.js";
13
13
  import { RetryLadderSchema } from "../schemas/turn-break.js";
14
- import { HandedOffSchema, HandoffOfferSchema } from "../schemas/providers/handoff.js";
14
+ import { FreshStartSchema, HandedOffSchema, HandoffOfferSchema } from "../schemas/providers/handoff.js";
15
15
  import { AgentCommandSchema, browserHelpRequest, capabilityOfferRequest, CapabilityOutcomeSchema, ContextUsageSchema, credentialOfferRequest, CredentialReceiptSchema, pageAskRequest, PageSchema, paymentOfferRequest, PaymentReceiptSchema, PermissionRequestSchema, PlanRequestSchema, QuestionRequestSchema, terminalHelpRequest, TodoItemSchema, ToolCallContentSchema, ToolCallLocationSchema, ToolCallStatusSchema, ToolKindSchema } from "./requests.js";
16
16
  import { TranscriptPatchSchema, TranscriptRowSchema, TurnNoteSchema } from "./transcript.js";
17
17
  import { ReviewFindingsSchema } from "./review.js";
@@ -137,6 +137,8 @@ export const AgentEventSchema = z.discriminatedUnion("kind", [
137
137
  held: z.boolean().optional(),
138
138
  deps: z.object({ missing: z.number(), started: z.array(z.string()), deferred: z.boolean() }).optional(),
139
139
  into: z.string().optional(),
140
+ // This land's own id, which a home conversation's card files the commit it made under (AgentSummary.commits).
141
+ land: z.string().optional(),
140
142
  }),
141
143
  // Notes the daemon prepends to the user's message before the model reads it, verbatim, one per note. Serialized
142
144
  // from the same typed notes the wire prompt uses, so disclosure cannot drift from what the model got.
@@ -146,6 +148,8 @@ export const AgentEventSchema = z.discriminatedUnion("kind", [
146
148
  ContextTrimSchema.extend({ kind: z.literal("context_trim") }),
147
149
  // How a turn a spent allowance held continued the conversation: the whole session, a trimmed copy, or a summary.
148
150
  HandedOffSchema.extend({ kind: z.literal("handoff") }),
151
+ // A home conversation going on in a fresh session rather than re-reading the whole of its old one (handoff.ts).
152
+ FreshStartSchema.extend({ kind: z.literal("fresh_start") }),
149
153
  // The SDK's init handshake; carries the model it actually resolved for the turn.
150
154
  // `prompt` names the parts the cache is keyed on, so a later turn can say which of them changed.
151
155
  z.object({ kind: z.literal("init"), model: z.string(), prompt: PromptFingerprintSchema.optional() }),
@@ -184,6 +188,8 @@ export const AgentEventSchema = z.discriminatedUnion("kind", [
184
188
  content: z.array(ToolCallContentSchema).optional(),
185
189
  // The call's input as bounded JSON text, for a call with no one-line `target` (TranscriptTool.input).
186
190
  input: z.string().optional(),
191
+ // The MCP server the call went to (TranscriptTool.server), which its display name does not say.
192
+ server: z.string().optional(),
187
193
  parentToolUseId: z.string().optional(),
188
194
  }),
189
195
  // A later state of a call, correlated by `id`. Status and/or fresh content/locations REPLACE the prior value
@@ -196,6 +202,10 @@ export const AgentEventSchema = z.discriminatedUnion("kind", [
196
202
  locations: z.array(ToolCallLocationSchema).optional(),
197
203
  // A command's exit code, from a runtime that reports it as a number (TranscriptTool.exitCode).
198
204
  exitCode: z.number().int().optional(),
205
+ // The call's input where the runtime only sends it after the card opened (an ACP agent's rawInput on an update),
206
+ // kept by a card that has neither target nor input yet. Until 2026-10-27 it was dropped: 57% of Devin's tool
207
+ // cards since 10-23 had no input at all.
208
+ input: z.string().optional(),
199
209
  }),
200
210
  // The agent started running Bash in its live `agent-<id>` tmux session; one per turn, reused across all of a turn's
201
211
  // commands including subagents'.
@@ -64,7 +64,11 @@ export const SandboxNoticeSchema = z.discriminatedUnion("code", [
64
64
  z.object({ code: z.literal("landHeld") }),
65
65
  z.object({ code: z.literal("landConflict"), params: z.object({ files: count, repos: z.string() }) }),
66
66
  // `deps` dependencies the turn added or changed, installing now, or `queued` behind any other install.
67
- z.object({ code: z.literal("landed"), params: z.object({ deps: count.optional(), queued: z.boolean().optional() }).optional() }),
67
+ // `land` names this land, which a home conversation's card files its commit under (AgentSummary.commits).
68
+ z.object({
69
+ code: z.literal("landed"),
70
+ params: z.object({ deps: count.optional(), queued: z.boolean().optional(), land: z.string().optional() }).optional(),
71
+ }),
68
72
  z.object({ code: z.literal("retrying"), params: z.object({ ...failure, attempt: count, of: count }) }),
69
73
  z.object({ code: z.literal("retried"), params: z.object({ ...failure, made: count, of: count }) }),
70
74
  z.object({ code: z.literal("outageWaiting"), params: z.object(failure) }),
@@ -108,6 +112,18 @@ export const SandboxNoticeSchema = z.discriminatedUnion("code", [
108
112
  fellBack: z.boolean().optional(),
109
113
  }),
110
114
  }),
115
+ // A home conversation going on in a fresh session (schemas/providers/handoff.ts FreshStartSchema): `why` it did,
116
+ // `from` the context the old session had grown to (worded, "182k"), `model` the one that wrote its summary, and
117
+ // `summarized` false where it opened with the recent conversation alone.
118
+ z.object({
119
+ code: z.literal("freshStart"),
120
+ params: z.object({
121
+ why: z.enum(["budget", "cold", "asked", "cleared"]),
122
+ from: z.string().optional(),
123
+ model: z.string().optional(),
124
+ summarized: z.boolean(),
125
+ }),
126
+ }),
111
127
  // An agent's own dependency install starting: into its conversation's own copy (`ownCopy`) or the main tree; the
112
128
  // workspace root (`root`) and up to three project folders named (`projects`, each with its slash, already joined),
113
129
  // and how many `more` were not named.
@@ -0,0 +1,18 @@
1
+ import type { AgentEvent } from "./agent-events.js";
2
+ import type { TranscriptTool } from "./transcript.js";
3
+
4
+ // The fields a tool_call_update sets on its card by plain replacement (transcript-fold.ts keeps the status and the
5
+ // content, which each move something else too), and the input a card that still has neither target nor input takes:
6
+ // an ACP agent (Devin) sends a call's arguments only on its updates, and until 2026-10-27 57% of its cards since 10-23
7
+ // were left with none.
8
+ export const takeToolUpdate = (tool: TranscriptTool, event: Extract<AgentEvent, { kind: "tool_call_update" }>): void => {
9
+ if (event.exitCode !== undefined) {
10
+ tool.exitCode = event.exitCode;
11
+ }
12
+ if (event.locations !== undefined) {
13
+ tool.locations = event.locations;
14
+ }
15
+ if (event.input !== undefined && tool.target === undefined && tool.input === undefined) {
16
+ tool.input = event.input;
17
+ }
18
+ };
@@ -141,6 +141,10 @@ export const TranscriptToolSchema: z.ZodType<TranscriptTool> = z.lazy(() =>
141
141
  .describe(
142
142
  "What the call was given, as JSON text cut to a few kilobytes, on a call whose input names no one-line target: an MCP tool's arguments, a delegation's prompt. Read afterwards to learn what was asked when the card alone cannot say.",
143
143
  ),
144
+ server: z
145
+ .string()
146
+ .optional()
147
+ .describe("The MCP server the call went to, where its name does not say: `web`'s browser, an account's `browser` server and a device all show as Browser calls."),
144
148
  startedAt: z.number().optional().describe("When the call was seen, in milliseconds. Absent on calls recorded before cards were stamped."),
145
149
  endedAt: z
146
150
  .number()
@@ -193,6 +197,7 @@ export interface TranscriptTool {
193
197
  thinking?: string | undefined;
194
198
  subagent?: TranscriptSubagent | undefined;
195
199
  input?: string | undefined;
200
+ server?: string | undefined;
196
201
  startedAt?: number | undefined;
197
202
  endedAt?: number | undefined;
198
203
  exitCode?: number | undefined;
@@ -0,0 +1,62 @@
1
+ import { z } from "zod";
2
+
3
+ // WHICH DEVICE TOOLS CARRY A DEADLINE OF THEIR OWN (2026-10-27). A post-mortem of 739k agent tool calls found 48 device
4
+ // calls cut at exactly 60.0 s with "The operation timed out.": the agent's MCP client gave up at its own default minute
5
+ // while `run_command`'s schema promised 120 s by default and 600 s at most, and the command ran on with nobody waiting.
6
+ // The machine (which enforces these) and the daemon (which sizes the bridge's wait on each call from them) read this one
7
+ // table, so a call's transport deadline follows the deadline the call itself asked for.
8
+
9
+ /** What passing a call's own deadline ends on the device. */
10
+ export type DeadlineEnds =
11
+ // The command, together with everything it started (run_command, android_shell).
12
+ | "command"
13
+ // Only the wait: the program being watched (app_status, app_logs with waitFor or untilExit) runs on.
14
+ | "wait";
15
+
16
+ // The arguments a deadline is read from. One of the wrong type reads as absent rather than failing the parse: such a
17
+ // call never runs, since the device checks its input against its own schema before anything else.
18
+ export const DeadlineArgumentsSchema = z.looseObject({
19
+ timeoutMs: z.number().positive().optional().catch(undefined),
20
+ waitFor: z.string().optional().catch(undefined),
21
+ untilExit: z.boolean().optional().catch(undefined),
22
+ });
23
+ export type DeadlineArguments = z.infer<typeof DeadlineArgumentsSchema>;
24
+
25
+ export interface OwnDeadline {
26
+ readonly defaultMs: number;
27
+ readonly maxMs: number;
28
+ readonly ends: DeadlineEnds;
29
+ /** Whether a call with these arguments waits at all; absent means it always does. */
30
+ readonly applies?: (args: DeadlineArguments) => boolean;
31
+ }
32
+
33
+ // A wait is asked for, never assumed: app_status and app_logs without one answer at once.
34
+ const appWait: OwnDeadline = {
35
+ defaultMs: 60_000,
36
+ maxMs: 10 * 60_000,
37
+ ends: "wait",
38
+ applies: (args) => args.waitFor !== undefined || args.untilExit === true,
39
+ };
40
+
41
+ /** The device tools whose `timeoutMs` argument bounds them, by tool name. */
42
+ export const DEVICE_OWN_DEADLINES = {
43
+ // Long enough for an install or a test run, short of the hub's 15-minute ceiling.
44
+ run_command: { defaultMs: 120_000, maxMs: 10 * 60_000, ends: "command" },
45
+ android_shell: { defaultMs: 60_000, maxMs: 10 * 60_000, ends: "command" },
46
+ app_status: appWait,
47
+ app_logs: appWait,
48
+ } as const satisfies Readonly<Record<string, OwnDeadline>>;
49
+
50
+ const BY_TOOL = new Map<string, OwnDeadline>(Object.entries(DEVICE_OWN_DEADLINES));
51
+
52
+ /** The longest any device tool's own deadline can be asked to run. */
53
+ export const LONGEST_OWN_DEADLINE_MS = Math.max(...[...BY_TOOL.values()].map((own) => own.maxMs));
54
+
55
+ /** The deadline one call runs under on the device: its own `timeoutMs`, else the tool's default, never past the maximum. */
56
+ export const ownDeadlineOf = (tool: string, args: DeadlineArguments): { readonly ms: number; readonly ends: DeadlineEnds } | undefined => {
57
+ const own = BY_TOOL.get(tool);
58
+ if (own === undefined || own.applies?.(args) === false) {
59
+ return undefined;
60
+ }
61
+ return { ms: Math.min(args.timeoutMs ?? own.defaultMs, own.maxMs), ends: own.ends };
62
+ };
@@ -0,0 +1,221 @@
1
+ import { ATTACHMENTS_DIR } from "../state/workspace-state.js";
2
+ import { guestReach, memberRefusal, routeFloor } from "./member-reach.js";
3
+
4
+ describe("routeFloor", () => {
5
+ test("reads floor at viewer: fleet, transcripts, workspace files, git log", () => {
6
+ expect(routeFloor("GET", "/agents")).toBe("viewer");
7
+ expect(routeFloor("GET", "/agents/abc/transcript")).toBe("viewer");
8
+ expect(routeFloor("GET", "/workspace/file")).toBe("viewer");
9
+ expect(routeFloor("GET", "/events")).toBe("viewer");
10
+ });
11
+
12
+ test("watching and being present are viewer despite being POSTs", () => {
13
+ expect(routeFloor("POST", "/agent/attach")).toBe("viewer");
14
+ expect(routeFloor("POST", "/system/session")).toBe("viewer");
15
+ expect(routeFloor("POST", "/system/presence")).toBe("viewer");
16
+ expect(routeFloor("POST", "/workspace/media-ticket")).toBe("viewer");
17
+ expect(routeFloor("DELETE", "/members/self")).toBe("viewer");
18
+ // One's own passkeys are identity, like staying signed in; the handler holds another member's to the owner.
19
+ expect(routeFloor("GET", "/system/passkeys")).toBe("viewer");
20
+ expect(routeFloor("POST", "/system/passkeys/register/options")).toBe("viewer");
21
+ expect(routeFloor("POST", "/system/passkeys/register")).toBe("viewer");
22
+ expect(routeFloor("DELETE", "/system/passkeys/abc_123")).toBe("viewer");
23
+ });
24
+
25
+ test("driving agents is the collaborator tier", () => {
26
+ expect(routeFloor("POST", "/agent")).toBe("collaborator");
27
+ expect(routeFloor("POST", "/agent/steer")).toBe("collaborator");
28
+ expect(routeFloor("POST", "/agents/abc/rename")).toBe("collaborator");
29
+ expect(routeFloor("POST", "/agents/abc/request-land")).toBe("collaborator");
30
+ expect(routeFloor("POST", "/agents/abc/assign")).toBe("collaborator");
31
+ // Resuming is the same turn again, so it belongs to whoever may start one; arming auto-land does not.
32
+ expect(routeFloor("POST", "/agent/resume")).toBe("collaborator");
33
+ expect(routeFloor("POST", "/agents/abc/break-policy")).toBe("collaborator");
34
+ expect(routeFloor("POST", "/agents/abc/auto-land")).toBe("maintainer");
35
+ // An attachment is part of the message it travels with, so the upload route answers at this tier for
36
+ // the address attachments land at — and only for that one (the workspace write below).
37
+ expect(routeFloor("POST", "/workspace/upload", `${ATTACHMENTS_DIR}/u1/shot.png`)).toBe("collaborator");
38
+ expect(routeFloor("POST", "/system/ws-ticket")).toBe("collaborator");
39
+ expect(routeFloor("POST", "/system/sync/pair")).toBe("collaborator");
40
+ });
41
+
42
+ test("changing files in the shared tree is the writer tier", () => {
43
+ expect(routeFloor("POST", "/workspace/dir")).toBe("writer");
44
+ expect(routeFloor("DELETE", "/workspace/entry")).toBe("writer");
45
+ expect(routeFloor("POST", "/workspace/move")).toBe("writer");
46
+ expect(routeFloor("POST", "/workspace/copy")).toBe("writer");
47
+ expect(routeFloor("POST", "/workspace/extract")).toBe("writer");
48
+ // Writing bytes into the shared tree is that same edit, whichever door it uses: the upload route only
49
+ // drops to collaborator for an attachment address, so a plain file, a missing target, and a path that
50
+ // climbs back out of the attachments dir all land here with move and delete. Where in the tree any of
51
+ // them may land is the fence's answer, not this one (areas/area-fence.integration.test.ts).
52
+ expect(routeFloor("POST", "/workspace/upload", "app/main.ts")).toBe("writer");
53
+ expect(routeFloor("POST", "/workspace/upload")).toBe("writer");
54
+ expect(routeFloor("POST", "/workspace/upload", `${ATTACHMENTS_DIR}/u1/../../../../config/hooks/lint.mjs`)).toBe("writer");
55
+ });
56
+
57
+ test("what leaves the sandbox floors at maintainer: land, discard, approvals", () => {
58
+ expect(routeFloor("POST", "/agents/abc/land")).toBe("maintainer");
59
+ expect(routeFloor("POST", "/agents/abc/discard")).toBe("maintainer");
60
+ expect(routeFloor("POST", "/approvals")).toBe("maintainer");
61
+ expect(routeFloor("DELETE", "/approvals/d1")).toBe("maintainer");
62
+ });
63
+
64
+ test("operating the tree is not editing it, and stays at maintainer", () => {
65
+ expect(routeFloor("POST", "/workspace/setup")).toBe("maintainer");
66
+ expect(routeFloor("POST", "/workspace/setup/install")).toBe("maintainer");
67
+ expect(routeFloor("POST", "/workspace/repos")).toBe("maintainer");
68
+ expect(routeFloor("POST", "/workspace/repos/new")).toBe("maintainer");
69
+ expect(routeFloor("POST", "/workspace/sync")).toBe("maintainer");
70
+ });
71
+
72
+ test("operator reads outrank the GET default: logs, usage, capabilities", () => {
73
+ expect(routeFloor("GET", "/logs")).toBe("maintainer");
74
+ expect(routeFloor("GET", "/system/usage")).toBe("maintainer");
75
+ expect(routeFloor("GET", "/capabilities")).toBe("maintainer");
76
+ });
77
+
78
+ test("the secrets surface belongs to the operating tier, reads included", () => {
79
+ expect(routeFloor("GET", "/secrets")).toBe("maintainer");
80
+ expect(routeFloor("POST", "/secrets")).toBe("maintainer");
81
+ expect(routeFloor("GET", "/secrets/inventory")).toBe("maintainer");
82
+ });
83
+
84
+ test("an unclassified route falls to the fail-safe defaults: viewer for reads, maintainer for mutations", () => {
85
+ expect(routeFloor("GET", "/no/such/route")).toBe("viewer");
86
+ expect(routeFloor("POST", "/no/such/route")).toBe("maintainer");
87
+ expect(routeFloor("POST", "/members")).toBe("maintainer");
88
+ expect(routeFloor("POST", "/system/sessions/revoke")).toBe("maintainer");
89
+ // The require-passkey switch and its recovery codes keep the mutation default under their ownership gate.
90
+ expect(routeFloor("POST", "/system/passkeys/policy")).toBe("maintainer");
91
+ expect(routeFloor("POST", "/system/passkeys/recovery")).toBe("maintainer");
92
+ });
93
+ });
94
+
95
+ describe("guestReach", () => {
96
+ test("the chat a guest drives, the cards it holds, and the reads a composer needs", () => {
97
+ expect(guestReach("POST", "/agent")).toBe(true);
98
+ expect(guestReach("POST", "/agent/attach")).toBe(true);
99
+ expect(guestReach("POST", "/agent/reply")).toBe(true);
100
+ expect(guestReach("GET", "/agents")).toBe(true);
101
+ expect(guestReach("GET", "/agents/abc/transcript")).toBe(true);
102
+ expect(guestReach("GET", "/personas")).toBe(true);
103
+ expect(guestReach("GET", "/providers")).toBe(true);
104
+ expect(guestReach("GET", "/events")).toBe(true);
105
+ expect(guestReach("POST", "/system/session")).toBe(true);
106
+ expect(guestReach("POST", "/speech/transcribe")).toBe(true);
107
+ expect(guestReach("DELETE", "/members/self")).toBe(true);
108
+ expect(guestReach("DELETE", "/system/passkeys/abc_123")).toBe(true);
109
+ expect(guestReach("POST", "/workspace/upload", `${ATTACHMENTS_DIR}/u1/shot.png`)).toBe(true);
110
+ });
111
+
112
+ // Every guest holds an area — the roster refuses one that names none (auth.ts MemberSchema) — and each route below
113
+ // applies that fence itself, so none of them can answer with the whole tree.
114
+ test("a guest reads the workspace, which its own fence then cuts", () => {
115
+ expect(guestReach("GET", "/workspace/tree")).toBe(true);
116
+ expect(guestReach("GET", "/workspace/file")).toBe(true);
117
+ expect(guestReach("GET", "/workspace/search")).toBe(true);
118
+ expect(guestReach("GET", "/workspace/raw")).toBe(true);
119
+ expect(guestReach("GET", "/areas")).toBe(true);
120
+ // Reads only: the tier writes nothing but the attachment that rides with its own message.
121
+ expect(guestReach("POST", "/workspace/upload", "support/note.md")).toBe(false);
122
+ expect(guestReach("DELETE", "/workspace/file")).toBe(false);
123
+ expect(guestReach("POST", "/areas")).toBe(false);
124
+ });
125
+
126
+ test("the past, the box, and every ship control stay shut, and so does anything unnamed", () => {
127
+ expect(guestReach("POST", "/workspace/upload", "app/main.ts")).toBe(false);
128
+ expect(guestReach("POST", "/workspace/upload")).toBe(false);
129
+ expect(guestReach("GET", "/sessions")).toBe(false);
130
+ expect(guestReach("GET", "/agents/search")).toBe(false);
131
+ expect(guestReach("POST", "/agent/route-chat")).toBe(false);
132
+ expect(guestReach("POST", "/personas")).toBe(false);
133
+ expect(guestReach("GET", "/secrets")).toBe(false);
134
+ expect(guestReach("POST", "/agents/abc/land")).toBe(false);
135
+ expect(guestReach("POST", "/agents/abc/request-land")).toBe(false);
136
+ expect(guestReach("POST", "/system/ws-ticket")).toBe(false);
137
+ expect(guestReach("GET", "/no/such/route")).toBe(false);
138
+ });
139
+ });
140
+
141
+ describe("memberRefusal", () => {
142
+ test("a tier below the floor is refused with the floor named; a guest off its list with its own sentence", () => {
143
+ expect(memberRefusal({ role: "viewer" }, "POST", "/agent")).toEqual({ error: "collaborator access required", floor: "collaborator", reason: "floor" });
144
+ expect(memberRefusal({ role: "collaborator" }, "POST", "/agent")).toBeUndefined();
145
+ expect(memberRefusal({ role: "guest", areas: ["support"] }, "POST", "/agent")).toBeUndefined();
146
+ expect(memberRefusal({ role: "guest", areas: ["support"] }, "POST", "/workspace/move")).toEqual({
147
+ error: "not open to a guest member",
148
+ floor: "viewer",
149
+ reason: "guest",
150
+ });
151
+ // A guest never clears a floor by rank: the list is the whole of its admission.
152
+ expect(memberRefusal({ role: "guest", areas: ["support"] }, "GET", "/no/such/route")).toEqual({
153
+ error: "not open to a guest member",
154
+ floor: "viewer",
155
+ reason: "guest",
156
+ });
157
+ expect(memberRefusal({ role: "viewer" }, "GET", "/no/such/route")).toBeUndefined();
158
+ });
159
+
160
+ test("a writer clears the file routes and nothing that ships or operates", () => {
161
+ expect(memberRefusal({ role: "writer", areas: ["support"] }, "POST", "/workspace/move")).toBeUndefined();
162
+ expect(memberRefusal({ role: "writer", areas: ["support"] }, "POST", "/workspace/upload", "support/note.md")).toBeUndefined();
163
+ expect(memberRefusal({ role: "collaborator" }, "POST", "/workspace/move")).toEqual({ error: "writer access required", floor: "writer", reason: "floor" });
164
+ expect(memberRefusal({ role: "writer", areas: ["support"] }, "POST", "/agents/abc/land")).toEqual({
165
+ error: "maintainer access required",
166
+ floor: "maintainer",
167
+ reason: "floor",
168
+ });
169
+ expect(memberRefusal({ role: "writer", areas: ["support"] }, "GET", "/secrets")).toEqual({
170
+ error: "maintainer access required",
171
+ floor: "maintainer",
172
+ reason: "floor",
173
+ });
174
+ });
175
+ });
176
+
177
+ // Editing by hand and running agents are separate answers: a person who edits without agents holds the writer tier,
178
+ // which clears the collaborator floor by rank, and is kept off it by their own answer.
179
+ describe("memberRefusal for a person with agents off", () => {
180
+ test("refuses every agent door and keeps the file doors open", () => {
181
+ const editor = { role: "writer" as const, agents: "off" as const };
182
+ expect(memberRefusal(editor, "POST", "/agent")).toEqual({ error: "running agents is not on for you here", floor: "collaborator", reason: "agents-off" });
183
+ expect(memberRefusal(editor, "POST", "/agents/abc/request-land")).toMatchObject({ floor: "collaborator" });
184
+ expect(memberRefusal(editor, "POST", "/workspace/dir")).toBeUndefined();
185
+ expect(memberRefusal(editor, "GET", "/workspace/tree")).toBeUndefined();
186
+ expect(memberRefusal({ role: "writer", agents: "run" }, "POST", "/agent")).toBeUndefined();
187
+ });
188
+ });
189
+
190
+ // A home-only member is a guest whose one conversation is its home (conversations/home/home-conversation.ts): the guest
191
+ // list, and the land press when its home lands by itself, which the route then admits on that home alone.
192
+ describe("a home-only member", () => {
193
+ const homeOnly = { role: "guest", agents: "home" } as const;
194
+
195
+ test("reaches what a guest reaches, and the land press only when its work lands by itself", () => {
196
+ expect(memberRefusal(homeOnly, "POST", "/agent")).toBeUndefined();
197
+ expect(memberRefusal(homeOnly, "GET", "/agents/home")).toBeUndefined();
198
+ expect(memberRefusal(homeOnly, "POST", "/agents/abc/land")).toEqual({ error: "not open to a guest member", floor: "viewer", reason: "guest" });
199
+ expect(memberRefusal({ ...homeOnly, lands: true }, "POST", "/agents/abc/land")).toBeUndefined();
200
+ });
201
+
202
+ test("never discards, settles, sets a conversation's landing, or commits, whatever it may land", () => {
203
+ const lands = { ...homeOnly, lands: true } as const;
204
+ for (const [method, path] of [
205
+ ["POST", "/agents/abc/discard"],
206
+ ["POST", "/agents/abc/settle"],
207
+ ["POST", "/agents/abc/auto-land"],
208
+ ["POST", "/git/root/commit"],
209
+ ] as const) {
210
+ expect(memberRefusal(lands, method, path)).toEqual({ error: "not open to a guest member", floor: "viewer", reason: "guest" });
211
+ }
212
+ });
213
+
214
+ test("a chatting guest granted nothing of the kind does not reach the land press", () => {
215
+ expect(memberRefusal({ role: "guest", agents: "chat", lands: true }, "POST", "/agents/abc/land")).toEqual({
216
+ error: "not open to a guest member",
217
+ floor: "viewer",
218
+ reason: "guest",
219
+ });
220
+ });
221
+ });
@@ -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
+ };
@@ -16,7 +16,15 @@ import {
16
16
  import { SyncStatusSchema } from "../../schemas/devices.js";
17
17
  import { HostsListSchema } from "../../schemas/hosts.js";
18
18
  import { VoicesViewSchema } from "../../schemas/voice.js";
19
- 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";
20
28
  import { PhonesListSchema, PhoneWakeRegistrationSchema } from "../../schemas/phone.js";
21
29
  import {
22
30
  PhoneKeyringsResultSchema,
@@ -100,6 +108,9 @@ export const RAW_JSON_ROUTES = {
100
108
  "DELETE /members": { input: MemberEmailSchema, output: MembersListSchema },
101
109
  "DELETE /members/self": { output: OkSchema },
102
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 },
103
114
  // Every environment write answers the environment after it. `/environment/contents` takes `?refresh` to probe again.
104
115
  "GET /environment": { output: EnvironmentSchema },
105
116
  "GET /environment/contents": { output: EnvironmentContentsSchema },