@intentic/sandbox-contract 1.409.0 → 1.410.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 (82) hide show
  1. package/dist/contracts/accounts.contract.d.ts +0 -16
  2. package/dist/contracts/accounts.contract.d.ts.map +1 -1
  3. package/dist/contracts/capabilities.contract.d.ts +0 -12
  4. package/dist/contracts/capabilities.contract.d.ts.map +1 -1
  5. package/dist/contracts/hub.contract.d.ts +121 -0
  6. package/dist/contracts/hub.contract.d.ts.map +1 -0
  7. package/dist/contracts/hub.contract.js +32 -0
  8. package/dist/contracts/hub.contract.js.map +1 -0
  9. package/dist/contracts/secrets.contract.d.ts +1 -73
  10. package/dist/contracts/secrets.contract.d.ts.map +1 -1
  11. package/dist/contracts/secrets.contract.js +4 -20
  12. package/dist/contracts/secrets.contract.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/protocol/doors/runner-wake.d.ts +46 -0
  18. package/dist/protocol/doors/runner-wake.d.ts.map +1 -0
  19. package/dist/protocol/doors/runner-wake.js +21 -0
  20. package/dist/protocol/doors/runner-wake.js.map +1 -0
  21. package/dist/protocol/raw/raw-json-routes.d.ts +14 -145
  22. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  23. package/dist/protocol/raw/raw-json-routes.js +1 -6
  24. package/dist/protocol/raw/raw-json-routes.js.map +1 -1
  25. package/dist/protocol/raw/raw-routes.d.ts +4 -16
  26. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  27. package/dist/protocol/raw/raw-routes.js +1 -4
  28. package/dist/protocol/raw/raw-routes.js.map +1 -1
  29. package/dist/schemas/capabilities.d.ts +0 -8
  30. package/dist/schemas/capabilities.d.ts.map +1 -1
  31. package/dist/schemas/capabilities.js +0 -4
  32. package/dist/schemas/capabilities.js.map +1 -1
  33. package/dist/schemas/connection-hub.d.ts +347 -0
  34. package/dist/schemas/connection-hub.d.ts.map +1 -0
  35. package/dist/schemas/connection-hub.js +118 -0
  36. package/dist/schemas/connection-hub.js.map +1 -0
  37. package/dist/schemas/diagnostics.d.ts +22 -1
  38. package/dist/schemas/diagnostics.d.ts.map +1 -1
  39. package/dist/schemas/diagnostics.js +13 -1
  40. package/dist/schemas/diagnostics.js.map +1 -1
  41. package/dist/schemas/links.d.ts +0 -21
  42. package/dist/schemas/links.d.ts.map +1 -1
  43. package/dist/schemas/links.js +1 -9
  44. package/dist/schemas/links.js.map +1 -1
  45. package/dist/schemas/providers/provider-oauth.d.ts +0 -16
  46. package/dist/schemas/providers/provider-oauth.d.ts.map +1 -1
  47. package/dist/schemas/providers/provider-oauth.js +0 -4
  48. package/dist/schemas/providers/provider-oauth.js.map +1 -1
  49. package/dist/schemas/sandbox-passwords.d.ts +0 -142
  50. package/dist/schemas/sandbox-passwords.d.ts.map +1 -1
  51. package/dist/schemas/sandbox-passwords.js +1 -33
  52. package/dist/schemas/sandbox-passwords.js.map +1 -1
  53. package/dist/state/auth-state.d.ts.map +1 -1
  54. package/dist/state/auth-state.js +1 -0
  55. package/dist/state/auth-state.js.map +1 -1
  56. package/dist/state/definition.d.ts +0 -8
  57. package/dist/state/definition.d.ts.map +1 -1
  58. package/package.json +5 -5
  59. package/src/contracts/hub.contract.ts +39 -0
  60. package/src/contracts/secrets.contract.ts +5 -21
  61. package/src/index.ts +3 -3
  62. package/src/protocol/doors/runner-wake.ts +36 -0
  63. package/src/protocol/raw/raw-json-routes.ts +0 -10
  64. package/src/protocol/raw/raw-routes.ts +2 -7
  65. package/src/schemas/capabilities.ts +0 -6
  66. package/src/schemas/connection-hub.test.ts +28 -0
  67. package/src/schemas/connection-hub.ts +191 -0
  68. package/src/schemas/diagnostics.ts +19 -2
  69. package/src/schemas/links.ts +4 -15
  70. package/src/schemas/providers/provider-oauth.ts +0 -6
  71. package/src/schemas/sandbox-passwords.ts +5 -46
  72. package/src/state/auth-state.ts +3 -0
  73. package/dist/contracts/sharing.contract.d.ts +0 -58
  74. package/dist/contracts/sharing.contract.d.ts.map +0 -1
  75. package/dist/contracts/sharing.contract.js +0 -41
  76. package/dist/contracts/sharing.contract.js.map +0 -1
  77. package/dist/schemas/providers/account-sharing.d.ts +0 -277
  78. package/dist/schemas/providers/account-sharing.d.ts.map +0 -1
  79. package/dist/schemas/providers/account-sharing.js +0 -68
  80. package/dist/schemas/providers/account-sharing.js.map +0 -1
  81. package/src/contracts/sharing.contract.ts +0 -54
  82. package/src/schemas/providers/account-sharing.ts +0 -123
@@ -0,0 +1,39 @@
1
+ import { procedure } from "../protocol/route-meta.js";
2
+ import { HubSavedSchema, HubSaveSchema, HubStateSchema, HubTakenSchema, HubTakeSchema } from "../schemas/connection-hub.js";
3
+
4
+ // The connections hub (schemas/connection-hub.ts): the keyring on one of the owner's computers holding the connections
5
+ // they want in more than one sandbox. Saving puts a credential in motion and taking asks the computer for one, so these
6
+ // are the operating tier's and no token's; the computer still asks its person before either happens.
7
+ const hubRoute = procedure.meta({ floor: "maintainer", control: "never", panel: false });
8
+
9
+ export const hubContract = {
10
+ state: hubRoute
11
+ .route({
12
+ method: "GET",
13
+ path: "/hub",
14
+ summary: "Connections on your computer, and which held here can go there",
15
+ description:
16
+ "The owner's computers whose keyring can hold connections; every card and model account held here, whether it can go to the hub and why not, which were saved there from here and which were made here from it; and any entry shared here that could not be made into a connection. No credential is in the answer.",
17
+ })
18
+ .output(HubStateSchema),
19
+ save: hubRoute
20
+ .route({
21
+ method: "POST",
22
+ path: "/hub/save",
23
+ summary: "Save a connection to your computer",
24
+ description:
25
+ "Sends one card or static model account to the named computer's keyring, sealed to it, to keep as a hub entry shared back here. The person at the computer says yes first; a locked keyring holds it until the next unlock. Saving the same connection again replaces that entry, so every sandbox using it gets the new value.",
26
+ })
27
+ .input(HubSaveSchema)
28
+ .output(HubSavedSchema),
29
+ take: hubRoute
30
+ .route({
31
+ method: "POST",
32
+ path: "/hub/take",
33
+ summary: "Use a connection saved on your computer",
34
+ description:
35
+ "Asks the owner's computers for a saved connection of this kind. The keyring offers the person what matches and shares the one they pick here; it is then made into a card or account here and follows that entry from then on.",
36
+ })
37
+ .input(HubTakeSchema)
38
+ .output(HubTakenSchema),
39
+ };
@@ -26,7 +26,7 @@ import {
26
26
  SecretRevealSchema,
27
27
  SecretSetSchema,
28
28
  } from "../schemas/secrets.js";
29
- import { SandboxNeedsSchema, SandboxPasswordsActivitySchema, SandboxPasswordsSchema, SecretWantResultSchema, SecretWantSchema } from "../schemas/sandbox-passwords.js";
29
+ import { SandboxNeedsSchema, SecretWantResultSchema, SecretWantSchema } from "../schemas/sandbox-passwords.js";
30
30
  import { OkSchema } from "../schemas/shared.js";
31
31
 
32
32
  // Credentials are the operating tier's, reads included: maintainer is the highest revokable grant, and no token's.
@@ -224,31 +224,15 @@ export const secretsContract = {
224
224
  .meta({ agent: true })
225
225
  .input(SecretWantSchema)
226
226
  .output(SecretWantResultSchema),
227
- passwords: secretRoute
227
+ // The want's other half: what this sandbox asked for that still waits, drawn in the Secrets view's "Needs attention".
228
+ wants: secretRoute
228
229
  .route({
229
230
  method: "GET",
230
- path: "/secrets/passwords",
231
- summary: "The passwords this sandbox may use",
232
- description:
233
- "Every entry the keyrings on the owner's computers share with this sandbox, where each works and how this sandbox may use it, and each computer's Passwords state. Names and places only, never values.",
234
- })
235
- .output(SandboxPasswordsSchema),
236
- passwordNeeds: secretRoute
237
- .route({
238
- method: "GET",
239
- path: "/secrets/passwords/needs",
231
+ path: "/secrets/wants",
240
232
  summary: "Credentials this sandbox asked for that wait for an answer",
241
- description: "The needs this sandbox raised (`secrets want`) that the owner has not answered yet, and on which computer each waits.",
233
+ description: "The credentials this sandbox asked the owner's computers for (`secrets want`) that nobody has answered yet, and on which computer each waits. Names and places only, never a value.",
242
234
  })
243
235
  .output(SandboxNeedsSchema),
244
- passwordActivity: secretRoute
245
- .route({
246
- method: "GET",
247
- path: "/secrets/passwords/activity",
248
- summary: "This sandbox's uses of the owner's passwords",
249
- description: "Each time this sandbox used a password one of the owner's keyrings keeps, newest first, from its own use ledger. Never a value.",
250
- })
251
- .output(SandboxPasswordsActivitySchema),
252
236
  // The credential gateway's say over one connection: how its credential reaches the agent, and what it may do there.
253
237
  policy: secretRoute
254
238
  .route({
package/src/index.ts CHANGED
@@ -22,6 +22,7 @@ import { exitContract } from "./contracts/exit.contract.js";
22
22
  import { extensionsContract } from "./contracts/extensions.contract.js";
23
23
  import { gitContract } from "./contracts/git.contract.js";
24
24
  import { historyContract } from "./contracts/history.contract.js";
25
+ import { hubContract } from "./contracts/hub.contract.js";
25
26
  import { intenticContract } from "./contracts/intentic.contract.js";
26
27
  import { inventoryContract } from "./contracts/inventory.contract.js";
27
28
  import { issuesContract } from "./contracts/issues.contract.js";
@@ -47,7 +48,6 @@ import { sessionsContract } from "./contracts/sessions.contract.js";
47
48
  import { settingsContract } from "./contracts/settings.contract.js";
48
49
  import { sealContract } from "./contracts/seal.contract.js";
49
50
  import { shareContract } from "./contracts/share.contract.js";
50
- import { sharingContract } from "./contracts/sharing.contract.js";
51
51
  import { skillsContract } from "./contracts/skills.contract.js";
52
52
  import { systemContract } from "./contracts/system.contract.js";
53
53
  import { translatorContract } from "./contracts/translator.contract.js";
@@ -81,6 +81,7 @@ export const sandboxContract: {
81
81
  extensions: typeof extensionsContract;
82
82
  git: typeof gitContract;
83
83
  history: typeof historyContract;
84
+ hub: typeof hubContract;
84
85
  intentic: typeof intenticContract;
85
86
  inventory: typeof inventoryContract;
86
87
  issues: typeof issuesContract;
@@ -106,7 +107,6 @@ export const sandboxContract: {
106
107
  settings: typeof settingsContract;
107
108
  seal: typeof sealContract;
108
109
  share: typeof shareContract;
109
- sharing: typeof sharingContract;
110
110
  skills: typeof skillsContract;
111
111
  system: typeof systemContract;
112
112
  translator: typeof translatorContract;
@@ -134,6 +134,7 @@ export const sandboxContract: {
134
134
  extensions: extensionsContract,
135
135
  git: gitContract,
136
136
  history: historyContract,
137
+ hub: hubContract,
137
138
  intentic: intenticContract,
138
139
  inventory: inventoryContract,
139
140
  issues: issuesContract,
@@ -159,7 +160,6 @@ export const sandboxContract: {
159
160
  settings: settingsContract,
160
161
  seal: sealContract,
161
162
  share: shareContract,
162
- sharing: sharingContract,
163
163
  skills: skillsContract,
164
164
  system: systemContract,
165
165
  translator: translatorContract,
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ import { MessageReceiptSchema } from "../../schemas/agent.js";
3
+ import { TurnErrandSchema } from "../../schemas/speaker.js";
4
+
5
+ // The wake door: words the runner's own sandbox has for a conversation its parent dispatched there (a watch that fired,
6
+ // a background job that ended, a child's report), handed to the parent, which owns the conversation. The parent says
7
+ // them as it would its own wake, so the turn they start is dispatched from the parent like any other: the parent's card,
8
+ // board and record follow it, and its work comes back to land. Kept apart from runner-protocol.ts, which schemas/agent.ts
9
+ // imports and so cannot import the receipt from.
10
+ export const runnerWakeUrl = (parentUrl: string): string => `${parentUrl.replace(/\/$/, "")}/system/runners/wake`;
11
+
12
+ export const RunnerWakeRequestSchema = z.object({
13
+ conversationId: z.string().min(1),
14
+ prompt: z.string(),
15
+ // Nobody at a composer: the runner's sandbox, or an agent there (a child reporting).
16
+ voice: z.enum(["sandbox", "agent"]),
17
+ // The source of outside content in the prompt; whatever turn it reaches is tainted by it.
18
+ outside: z.string().optional(),
19
+ errand: TurnErrandSchema.optional(),
20
+ // What on the runner sent it (`automation:<id>`, a job), said on the row it opens.
21
+ source: z.string().optional(),
22
+ // The id its words wait under, so the same wake sent twice is delivered once.
23
+ messageId: z.string().optional(),
24
+ });
25
+ export type RunnerWakeRequest = z.infer<typeof RunnerWakeRequestSchema>;
26
+
27
+ // `forwarded: false`: the conversation is not one the parent dispatched to this runner, so the runner keeps the wake.
28
+ // Otherwise what the parent did with it: a receipt, or why it took nothing (`invalid`, `why`), as a local wake answers.
29
+ export const RunnerWakeAnswerSchema = z.union([
30
+ z.object({ forwarded: z.literal(false) }),
31
+ z.object({
32
+ forwarded: z.literal(true),
33
+ said: z.union([MessageReceiptSchema, z.object({ invalid: z.string() }), z.object({ why: z.string() })]),
34
+ }),
35
+ ]);
36
+ export type RunnerWakeAnswer = z.infer<typeof RunnerWakeAnswerSchema>;
@@ -88,14 +88,9 @@ import {
88
88
  } from "../../state/arrival.js";
89
89
  import { DefinitionDiffSchema, DefinitionExportSchema, WorkspacePublishResultSchema, WorkspacePublishSchema, WorkspaceRemoteSchema } from "../../state/definition.js";
90
90
  import {
91
- RunnerCredentialRefreshRequestSchema,
92
- RunnerCredentialRefreshSchema,
93
- RunnerCredentialRequestSchema,
94
- RunnerCredentialSchema,
95
91
  RunnerDefinitionAppliedSchema,
96
92
  RunnersListSchema,
97
93
  } from "../doors/runner-protocol.js";
98
- import { LinkAccountCopySchema, LinkAccountsSchema, SharedAccountRefSchema } from "../../schemas/providers/account-sharing.js";
99
94
  import type { RawRouteKey } from "./raw-routes.js";
100
95
 
101
96
  // What a raw route that answers plain JSON takes and answers, under its RAW_ROUTES key. `input` is the JSON body a write
@@ -211,11 +206,6 @@ export const RAW_JSON_ROUTES = {
211
206
  "POST /link/operate/write": { input: LinkWriteSchema, output: LinkWriteAnswerSchema },
212
207
  "POST /diagnostics": { input: DiagnosticsAskSchema, output: DiagnosticsAnswerSchema },
213
208
  "GET /fleet/{handle}/bundle": { output: ConversationBundleSchema },
214
- // An accounts link: what it may use, one static key's copy, and a lent sign-in's per-turn credential.
215
- "GET /link/accounts": { output: LinkAccountsSchema },
216
- "POST /link/accounts/copy": { input: SharedAccountRefSchema, output: LinkAccountCopySchema },
217
- "POST /link/credentials": { input: RunnerCredentialRequestSchema, output: RunnerCredentialSchema },
218
- "POST /link/credentials/refresh": { input: RunnerCredentialRefreshRequestSchema, output: RunnerCredentialRefreshSchema },
219
209
  "GET /system/control/tokens": { output: ControlTokensListSchema },
220
210
  "POST /system/control/tokens": { input: ControlTokenMintSchema, output: ControlTokenMintedSchema },
221
211
  "DELETE /system/control/tokens/{id}": { output: OkSchema },
@@ -270,6 +270,8 @@ export const RAW_ROUTES = {
270
270
  "POST /system/runners/git/{repo}/git-receive-pack": { auth: "door", control: "never", lane: "bulk" },
271
271
  "POST /system/runners/credentials": { auth: "door", control: "never" },
272
272
  "POST /system/runners/credentials/refresh": { auth: "door", control: "never" },
273
+ // A runner's wake for a conversation dispatched there (runner-wake.ts): said here, so its turn is the parent's.
274
+ "POST /system/runners/wake": { auth: "door", control: "never" },
273
275
  [`ALL ${runnerTranslatorPath}/*` as const]: { auth: "door", control: "never" },
274
276
  // The privacy shield's gateway: every shielded runtime's model requests, on the signed session its base URL carries
275
277
  // (privacy/gateway/session-token.ts), which names the provider and the only upstream it may forward to. Held open
@@ -314,13 +316,6 @@ export const RAW_ROUTES = {
314
316
  "POST /link/operate/exec/{id}/stop": { auth: "door", control: "never" },
315
317
  "POST /link/operate/read": { auth: "door", control: "never" },
316
318
  "POST /link/operate/write": { auth: "door", control: "never" },
317
- // An accounts link's doors (schemas/providers/account-sharing.ts): the accounts its terms name, a static key's copy,
318
- // and a lent sign-in's access token per turn, re-minted mid-turn. The refresh token never leaves; each door checks the
319
- // link token itself and answers only for what the terms name.
320
- "GET /link/accounts": { auth: "door", control: "never" },
321
- "POST /link/accounts/copy": { auth: "door", control: "never" },
322
- "POST /link/credentials": { auth: "door", control: "never" },
323
- "POST /link/credentials/refresh": { auth: "door", control: "never" },
324
319
  "POST /system/control/tokens": { control: "never" },
325
320
  "GET /system/control/tokens": { floor: "maintainer", control: "never" },
326
321
  "DELETE /system/control/tokens/{id}": { control: "never" },
@@ -354,12 +354,6 @@ export const LinkConfigSchema = z.object({
354
354
  token: z.string().min(1).describe("The link token that sandbox minted for this one. Stored, never echoed back."),
355
355
  name: z.string().max(100).optional().describe("What the other sandbox is called, as its owner named it."),
356
356
  sandboxId: z.string().max(100).optional().describe("The other sandbox's id on the owner's account."),
357
- purpose: z
358
- .enum(["tasks", "accounts"])
359
- .optional()
360
- .describe(
361
- "What the link is for: tasks to hand over (absent), or model accounts this sandbox borrows from that one (schemas/providers/account-sharing.ts), which mounts no delegate tool.",
362
- ),
363
357
  });
364
358
  export type LinkConfig = z.infer<typeof LinkConfigSchema>;
365
359
  export type McpConfig = z.infer<typeof McpConfigSchema>;
@@ -0,0 +1,28 @@
1
+ import { KEYRING_NAME_RE } from "./keyring.js";
2
+ import { ConnectionEnvelopeSchema, hubEntryName, hubHostOf, isHubEntryName, wantOfItem, withoutHubEntries } from "./connection-hub.js";
3
+
4
+ // A hub entry is found by its host and kept apart from the copies an agent spends, so these rules are what makes a saved
5
+ // connection reachable from another sandbox and unreachable as a raw value.
6
+
7
+ test("a connector's card is asked for by its connector alone; a tool server or endpoint by its kind", () => {
8
+ const github = { type: "card", id: "github", kind: "cli", connector: "github", config: { provider: "github", token: "t" } } as const;
9
+ expect(hubHostOf(wantOfItem(github))).toBe("github.cli.connections.invalid");
10
+ expect(hubHostOf({ type: "card", kind: "cli", connector: "cloudflare" })).not.toBe(hubHostOf(wantOfItem(github)));
11
+ expect(hubHostOf(wantOfItem({ type: "card", id: "notion", kind: "mcp", config: { url: "https://mcp.notion.com" } }))).toBe("mcp.connections.invalid");
12
+ expect(hubHostOf({ type: "account", provider: "cursor" })).toBe("cursor.account.connections.invalid");
13
+ });
14
+
15
+ test("an entry name is a keyring name that says what it holds, and only those are the hub's", () => {
16
+ const name = hubEntryName({ type: "card", id: "gh", kind: "cli", connector: "git-hub", config: {} }, "a1f3");
17
+ expect(name).toBe("CONNECTION_GIT_HUB_A1F3");
18
+ expect(KEYRING_NAME_RE.test(name)).toBe(true);
19
+ expect(isHubEntryName(name)).toBe(true);
20
+ expect(withoutHubEntries({ [name]: "{}", VPN_PASSWORD: "x" })).toEqual({ VPN_PASSWORD: "x" });
21
+ });
22
+
23
+ test("an envelope with a field this build does not know is refused rather than half read", () => {
24
+ const envelope = { intentic: "connection", v: 1, label: "Cursor", from: { sandbox: "dev", at: 1 }, item: { type: "account", provider: "cursor", account: { apiKey: "k" } } };
25
+ expect(ConnectionEnvelopeSchema.safeParse(envelope).success).toBe(true);
26
+ expect(ConnectionEnvelopeSchema.safeParse({ ...envelope, extra: true }).success).toBe(false);
27
+ expect(ConnectionEnvelopeSchema.safeParse({ ...envelope, item: { ...envelope.item, provider: "claude" } }).success).toBe(false);
28
+ });
@@ -0,0 +1,191 @@
1
+ import { z } from "zod";
2
+ import { KEYRING_NAME_RE } from "./keyring.js";
3
+
4
+ // THE CONNECTIONS HUB: the keyring on one of the owner's computers as the place their connections live, so a sandbox can
5
+ // put one there and any other of their sandboxes can take it. Nothing new runs on the computer: a hub item is an
6
+ // ordinary keyring `text` entry whose value is the envelope below, put there through the keyring's inbox (a person's
7
+ // yes at the computer) and shared back in `copy` mode, so a sandbox holds a sealed copy that works with the computer off
8
+ // and changes when the entry does. The sandbox turns each copy it holds into the card or account the envelope describes,
9
+ // and takes it away again when the computer stops sharing it.
10
+ //
11
+ // Only credentials that do not rotate travel. A sign-in whose refresh token is renewed (a Claude or Codex subscription,
12
+ // an OAuth card) would sign the other copies out at its first renewal, so each sandbox signs in to those itself.
13
+
14
+ // Every hub entry's name starts so; the rest is a readable slug and a random tail, since a sandbox cannot see the entries
15
+ // another put there and an inbox item under a name already taken replaces that entry.
16
+ export const HUB_ENTRY_PREFIX = "CONNECTION_";
17
+ export const isHubEntryName = (name: string): boolean => name.startsWith(HUB_ENTRY_PREFIX) && KEYRING_NAME_RE.test(name);
18
+
19
+ /** The keyring copies an agent may spend by name: every one but the hub's own, which only the daemon reads. */
20
+ export const withoutHubEntries = (copies: Readonly<Record<string, string>>): Readonly<Record<string, string>> =>
21
+ Object.fromEntries(Object.entries(copies).filter(([name]) => !isHubEntryName(name)));
22
+
23
+ // The guard a hub entry carries as its only host. `.invalid` never resolves (RFC 2606), so the copy, which the sandbox
24
+ // keeps like any secret, can never be sent anywhere by a `{{secret:…}}` reference; and a sandbox asking for one finds it
25
+ // by this host through the keyring's ordinary need, which matches entries by host.
26
+ export const HUB_HOST_SUFFIX = "connections.invalid";
27
+
28
+ // The card kinds that travel: a CLI connector (its provider's own card), a remote tool server, a model endpoint. Every
29
+ // other kind is tied to where it was made (a computer, a disk, a link) or runs something of its own.
30
+ export const HubCardKindSchema = z.enum(["cli", "mcp", "endpoint"]);
31
+ export type HubCardKind = z.infer<typeof HubCardKindSchema>;
32
+
33
+ // The model providers whose account is a key that does not rotate: what a sign-in there would write is the whole
34
+ // account: Cursor and Devin keys, and the minted Z.ai and Meta keys. (Endpoints are cards, above.)
35
+ export const HUB_ACCOUNT_PROVIDERS = ["cursor", "devin", "zai", "meta"] as const;
36
+ export const HubAccountProviderSchema = z.enum(HUB_ACCOUNT_PROVIDERS);
37
+ export type HubAccountProvider = z.infer<typeof HubAccountProviderSchema>;
38
+
39
+ // One static account, the fields every static store keeps. Only a sandbox's daemon ever reads one.
40
+ export const StaticAccountCopySchema = z.object({
41
+ label: z.string().max(200).optional(),
42
+ email: z.string().max(320).optional(),
43
+ variant: z.string().max(100).optional().describe("Which sign-in estate a minted key belongs to (Z.ai's international or mainland plan)."),
44
+ plan: z.string().max(100).optional(),
45
+ apiKey: z.string().min(1).max(8192),
46
+ apiKeyExpiresAtMs: z.number().optional(),
47
+ backendUrl: z.string().max(500).optional(),
48
+ });
49
+ export type StaticAccountCopy = z.infer<typeof StaticAccountCopySchema>;
50
+
51
+ const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,40}$/u;
52
+
53
+ // What one hub entry holds. `card.config` carries the card's credential fields beside its settings, which the receiving
54
+ // sandbox vaults exactly as a card added there would be; it is checked against that sandbox's own card schema there.
55
+ export const HubCardItemSchema = z
56
+ .object({
57
+ type: z.literal("card"),
58
+ id: z.string().min(1).max(60).describe("The card's id where it was saved, kept where it is free."),
59
+ kind: HubCardKindSchema,
60
+ connector: z.string().regex(SLUG_RE).optional().describe("A CLI card's connector (its `provider`), which another sandbox asks for it by."),
61
+ config: z.record(z.string(), z.unknown()),
62
+ })
63
+ .strict();
64
+ export const HubAccountItemSchema = z.object({ type: z.literal("account"), provider: HubAccountProviderSchema, account: StaticAccountCopySchema }).strict();
65
+ export const HubItemSchema = z.discriminatedUnion("type", [HubCardItemSchema, HubAccountItemSchema]);
66
+ export type HubItem = z.infer<typeof HubItemSchema>;
67
+
68
+ export const ConnectionEnvelopeSchema = z
69
+ .object({
70
+ intentic: z.literal("connection"),
71
+ v: z.literal(1),
72
+ label: z.string().min(1).max(200).describe("What the connection is called, for the rows that list it."),
73
+ from: z.object({ sandbox: z.string().max(200), at: z.number() }).strict().describe("Where and when it was saved."),
74
+ item: HubItemSchema,
75
+ })
76
+ .strict();
77
+ export type ConnectionEnvelope = z.infer<typeof ConnectionEnvelopeSchema>;
78
+
79
+ // What a sandbox asks the computer for: one connector's card, any card of a kind that has no connector (a tool server,
80
+ // a model endpoint), or one provider's static account.
81
+ export const HubWantSchema = z.discriminatedUnion("type", [
82
+ z.object({ type: z.literal("card"), kind: HubCardKindSchema, connector: z.string().regex(SLUG_RE).optional() }).strict(),
83
+ z.object({ type: z.literal("account"), provider: HubAccountProviderSchema }).strict(),
84
+ ]);
85
+ export type HubWant = z.infer<typeof HubWantSchema>;
86
+
87
+ /** The host a hub entry for `want` carries, and a need for it asks by. A connector's card is found by its connector alone. */
88
+ export const hubHostOf = (want: HubWant): string => {
89
+ if (want.type === "account") {
90
+ return `${want.provider}.account.${HUB_HOST_SUFFIX}`;
91
+ }
92
+ return want.kind === "cli" && want.connector !== undefined ? `${hubSlug(want.connector)}.cli.${HUB_HOST_SUFFIX}` : `${want.kind}.${HUB_HOST_SUFFIX}`;
93
+ };
94
+
95
+ /** What a hub item answers to: the want a sandbox would ask with to be offered it. */
96
+ export const wantOfItem = (item: HubItem): HubWant => {
97
+ if (item.type === "account") {
98
+ return { type: "account", provider: item.provider };
99
+ }
100
+ return item.kind === "cli" && item.connector !== undefined ? { type: "card", kind: item.kind, connector: item.connector } : { type: "card", kind: item.kind };
101
+ };
102
+
103
+ /** A fresh entry name for an item: readable in the Passwords app, and unlikely to meet another sandbox's. */
104
+ export const hubEntryName = (item: HubItem, tail: string): string => {
105
+ const what = item.type === "account" ? item.provider : (item.connector ?? item.kind);
106
+ const readable = what
107
+ .toUpperCase()
108
+ .replace(/[^A-Z0-9]+/gu, "_")
109
+ .replace(/^_+|_+$/gu, "")
110
+ .slice(0, 40);
111
+ return `${HUB_ENTRY_PREFIX}${readable === "" ? "ITEM" : readable}_${tail.toUpperCase().replace(/[^A-Z0-9]/gu, "")}`;
112
+ };
113
+
114
+ /** A connector id as a hub slug: lower case, letters, digits and dashes. */
115
+ export const hubSlug = (value: string): string =>
116
+ value
117
+ .toLowerCase()
118
+ .replace(/[^a-z0-9-]+/gu, "-")
119
+ .replace(/^-+|-+$/gu, "")
120
+ .slice(0, 40) || "x";
121
+
122
+ /* THE ROUTES, called by the owner's editor. */
123
+
124
+ // What a saved or taken connection is here: a card by its id, or a provider's account by its id there.
125
+ export const HubTargetSchema = z.discriminatedUnion("type", [
126
+ z.object({ type: z.literal("card"), id: z.string().min(1).max(60) }).strict(),
127
+ z.object({ type: z.literal("account"), provider: HubAccountProviderSchema, id: z.string().min(1).max(200) }).strict(),
128
+ ]);
129
+ export type HubTarget = z.infer<typeof HubTargetSchema>;
130
+ export const sameHubTarget = (a: HubTarget, b: HubTarget): boolean =>
131
+ a.type === "card" ? b.type === "card" && a.id === b.id : b.type === "account" && a.provider === b.provider && a.id === b.id;
132
+
133
+ // A computer whose keyring could hold the hub.
134
+ export const HubComputerSchema = z.object({
135
+ machine: z.string(),
136
+ online: z.boolean(),
137
+ setUp: z.boolean().describe("Its keyring is installed and set up, so it can take a connection in."),
138
+ locked: z.boolean().optional(),
139
+ });
140
+ export type HubComputer = z.infer<typeof HubComputerSchema>;
141
+
142
+ // One card or account held here, and whether it can go to the hub.
143
+ export const HubHoldingSchema = z.object({
144
+ target: HubTargetSchema,
145
+ label: z.string(),
146
+ want: HubWantSchema.optional().describe("What another sandbox asks with to be offered it. Absent when it cannot go."),
147
+ reason: z.string().optional().describe("Why it cannot go to the hub, in words a person can act on. Absent when it can."),
148
+ saved: z
149
+ .object({
150
+ entry: z.string().regex(KEYRING_NAME_RE),
151
+ machine: z.string(),
152
+ at: z.number(),
153
+ pending: z.boolean().describe("It waits for a yes at the computer (the keyring was locked when it was sent)."),
154
+ })
155
+ .optional()
156
+ .describe("It was saved to the hub from here: which entry, on which computer."),
157
+ from: z
158
+ .object({ entry: z.string(), machine: z.string().optional() })
159
+ .optional()
160
+ .describe("It was made here from a hub entry: which, and the computer that shares it. It goes when that computer stops sharing it."),
161
+ });
162
+ export type HubHolding = z.infer<typeof HubHoldingSchema>;
163
+
164
+ // A hub entry shared here that could not be turned into a connection, with why.
165
+ export const HubFailureSchema = z.object({ entry: z.string(), machine: z.string().optional(), message: z.string(), at: z.number() });
166
+ export type HubFailure = z.infer<typeof HubFailureSchema>;
167
+
168
+ export const HubStateSchema = z.object({
169
+ computers: z.array(HubComputerSchema),
170
+ holdings: z.array(HubHoldingSchema),
171
+ failures: z.array(HubFailureSchema),
172
+ });
173
+ export type HubState = z.infer<typeof HubStateSchema>;
174
+
175
+ export const HubSaveSchema = z.object({ target: HubTargetSchema, machine: z.string().min(1).max(128) }).strict();
176
+ export type HubSave = z.infer<typeof HubSaveSchema>;
177
+ export const HubSavedSchema = z.object({
178
+ entry: z.string(),
179
+ machine: z.string(),
180
+ pending: z.boolean().describe("It waits for the next unlock at that computer, where the person says yes."),
181
+ });
182
+ export type HubSaved = z.infer<typeof HubSavedSchema>;
183
+
184
+ export const HubTakeSchema = z.object({ want: HubWantSchema, why: z.string().min(1).max(300).optional() }).strict();
185
+ export type HubTake = z.infer<typeof HubTakeSchema>;
186
+ export const HubTakenSchema = z.object({
187
+ outcome: z.enum(["taken", "waiting", "none"]).describe("Shared and made here; waiting for a yes at the computer; nothing saved there answers it."),
188
+ message: z.string(),
189
+ target: HubTargetSchema.optional().describe("What it was made into here, once taken."),
190
+ });
191
+ export type HubTaken = z.infer<typeof HubTakenSchema>;
@@ -1,7 +1,8 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  // THE DIAGNOSTICS QUERIES: read-only questions over what a sandbox's daemon already recorded (its log, the editor's
4
- // reports, slow spans and rollups, the turn ledger, the resource series, its boots, one conversation's timeline). One
4
+ // reports, slow spans and rollups, the turn ledger, the resource series, its boots, one conversation's timeline, the
5
+ // commands agents ran that failed). One
5
6
  // set of arguments serves every door that asks them: the `diagnostics` tools a turn mounts, the `diagnostics` command on
6
7
  // the agent's PATH (POST /diagnostics), and a linked sandbox reading this one's records (POST /link/records/diagnostics).
7
8
  // Each answers with text written to be read, never the raw lines, and each takes a window.
@@ -102,6 +103,21 @@ export const DiagnosticsTimelineArgs = {
102
103
  limit: z.number().int().min(1).max(DIAGNOSTICS_MAX_LINES).optional().describe("The newest this many events. Defaults to 100."),
103
104
  };
104
105
 
106
+ /** `failures`: the shell commands agents ran that failed, kept a month, grouped by kind across conversations. */
107
+ export const DiagnosticsFailuresArgs = {
108
+ sinceMinutes: minutes().describe("How far back to look. Leave it out for everything kept (about a month)."),
109
+ conversationId: z.string().max(200).optional().describe("Narrow to one conversation; its failures are then listed one by one."),
110
+ contains: z.string().max(200).optional().describe("Case-insensitive substring of the failure's line: a program, a path, an error."),
111
+ group: z
112
+ .boolean()
113
+ .optional()
114
+ .describe(
115
+ "true: one row per kind of failure (program and error), most widespread first, each marked ongoing, stopped or quiet. " +
116
+ "false: every failure, newest first. Left out, kinds are grouped unless a conversation is named.",
117
+ ),
118
+ limit: limit(),
119
+ };
120
+
105
121
  // One query, named by `query`, with that query's own arguments.
106
122
  export const DiagnosticsQuerySchema = z.discriminatedUnion("query", [
107
123
  z.object({ query: z.literal("errors"), ...DiagnosticsErrorsArgs }),
@@ -110,10 +126,11 @@ export const DiagnosticsQuerySchema = z.discriminatedUnion("query", [
110
126
  z.object({ query: z.literal("resources"), ...DiagnosticsResourcesArgs }),
111
127
  z.object({ query: z.literal("restarts"), ...DiagnosticsRestartsArgs }),
112
128
  z.object({ query: z.literal("timeline"), ...DiagnosticsTimelineArgs }),
129
+ z.object({ query: z.literal("failures"), ...DiagnosticsFailuresArgs }),
113
130
  ]);
114
131
  export type DiagnosticsQuery = z.infer<typeof DiagnosticsQuerySchema>;
115
132
  export type DiagnosticsQueryName = DiagnosticsQuery["query"];
116
- export const DIAGNOSTICS_QUERY_NAMES = ["errors", "slow", "turns", "resources", "restarts", "timeline"] as const satisfies readonly DiagnosticsQueryName[];
133
+ export const DIAGNOSTICS_QUERY_NAMES = ["errors", "slow", "turns", "resources", "restarts", "timeline", "failures"] as const satisfies readonly DiagnosticsQueryName[];
117
134
 
118
135
  // POST /diagnostics: one query of this sandbox's records, or, with `on`, of the linked sandbox that card names, read
119
136
  // through the link (its owner must share records on it).
@@ -1,7 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { AskQuestionSchema } from "../events/requests.js";
3
3
  import { entryId } from "./internal.js";
4
- import { SharedAccountRefSchema } from "./providers/account-sharing.js";
5
4
 
6
5
  // LINKED SANDBOXES: one of the owner's sandboxes handing tasks to another. The sandbox that hands work over holds a
7
6
  // `link` capability card (schemas/capabilities.ts LinkConfigSchema); the one that takes it holds an inbound link, minted
@@ -35,7 +34,7 @@ const turnsPerHourTerm = z
35
34
  .describe("How many turns the link may start in an hour, new tasks and follow-ups alike. Words said into a turn already running are not counted.");
36
35
  const tasksTerm = z
37
36
  .boolean()
38
- .describe("Whether the link may hand this sandbox tasks at all. An accounts link is minted without: it only borrows and copies the accounts below.");
37
+ .describe("Whether the link may hand this sandbox tasks at all. Without, it only reads records or operates, as those terms allow.");
39
38
  const recordsTerm = z
40
39
  .boolean()
41
40
  .describe(
@@ -46,12 +45,6 @@ const operateTerm = z
46
45
  .describe(
47
46
  "Whether the asking sandbox may operate this one as its owner does from their own terminal: run commands, and read and write files, in this sandbox's main checkout. They run as root, or, while conversations here can be private, inside the same jail every person's shell gets (the history volume out of reach). Anything the owner's terminal can do, including reading this sandbox's secrets. Every call is logged here. Off unless its owner turns it on.",
48
47
  );
49
- const accountsTerm = z
50
- .array(SharedAccountRefSchema)
51
- .max(64)
52
- .describe(
53
- "The model accounts the asking sandbox may use (schemas/providers/account-sharing.ts): a static key it may copy, a sign-in it borrows turn by turn. Empty lends nothing.",
54
- );
55
48
 
56
49
  export const LinkTermsSchema = z.object({
57
50
  actsAs: entryId
@@ -70,7 +63,6 @@ export const LinkTermsSchema = z.object({
70
63
  tasks: tasksTerm.default(true),
71
64
  records: recordsTerm.default(false),
72
65
  operate: operateTerm.default(false),
73
- accounts: accountsTerm.default([]),
74
66
  });
75
67
  export type LinkTerms = z.infer<typeof LinkTermsSchema>;
76
68
 
@@ -119,9 +111,8 @@ export const InboundLinkMintedSchema = z.object({ id: z.string(), token: z.strin
119
111
  export type InboundLinkMinted = z.infer<typeof InboundLinkMintedSchema>;
120
112
  // POST /system/links/{id}: new terms, whole fields replaced, the rest kept. `null` on the persona or the service takes it
121
113
  // off (2026-10-26): absence keeps a field, so before this neither could be cleared once set. Spelled field by field rather
122
- // than as LinkTermsSchema.partial(): zod still fills a partial's inner defaults, so a change naming only `accounts`
123
- // read as `approve: false, turnsPerHour: 20, tasks: true` and quietly turned an accounts link into one taking tasks
124
- // (2026-10-29).
114
+ // than as LinkTermsSchema.partial(): zod still fills a partial's inner defaults, so a change naming one field would read
115
+ // as `approve: false, turnsPerHour: 20, tasks: true` and quietly reset the rest (2026-10-29).
125
116
  export const InboundLinkTermsUpdateSchema = z.object({
126
117
  label: z.string().trim().min(1).max(60).optional(),
127
118
  actsAs: entryId.nullable().optional().describe("The persona every task wears; null takes it off."),
@@ -131,7 +122,6 @@ export const InboundLinkTermsUpdateSchema = z.object({
131
122
  tasks: tasksTerm.optional(),
132
123
  records: recordsTerm.optional(),
133
124
  operate: operateTerm.optional(),
134
- accounts: accountsTerm.optional(),
135
125
  });
136
126
  export type InboundLinkTermsUpdate = z.infer<typeof InboundLinkTermsUpdateSchema>;
137
127
  // POST /system/links/{id}/requests/{request}: the owner's answer to one waiting task.
@@ -148,9 +138,8 @@ export const LinkHelloSchema = z.object({
148
138
  approve: z.boolean(),
149
139
  turnsPerHour: z.number().int(),
150
140
  persona: z.string().optional().describe("The name of the persona its tasks wear, when they wear one."),
151
- // Absent from a sandbox older than accounts links, which takes tasks and lends nothing.
141
+ // Absent from a sandbox older than 2026-10-29, which takes tasks.
152
142
  tasks: z.boolean().optional(),
153
- accounts: z.number().int().nonnegative().optional().describe("How many accounts the link may use."),
154
143
  // Absent from a sandbox older than records over links, which shares none.
155
144
  records: z.boolean().optional().describe("Whether the link may read this sandbox's records (its conversations, logs and diagnostics)."),
156
145
  // Absent from a sandbox older than operating over links, which allows none.
@@ -44,12 +44,6 @@ export const OauthAccountSchema = z.object({
44
44
  usage: AccountUsageSchema.optional().describe(
45
45
  "How full its plan limits were when last measured, so a picker can show what is left before committing work to it. Absent until a reading exists, which reads as unknown rather than as nothing left.",
46
46
  ),
47
- borrowedFrom: z
48
- .object({ name: z.string(), sandboxId: z.string().optional() })
49
- .optional()
50
- .describe(
51
- "Another of the owner's sandboxes holds this sign-in and lends it here turn by turn (schemas/providers/account-sharing.ts). Absent means it is this sandbox's own.",
52
- ),
53
47
  });
54
48
  export type OauthAccount = z.infer<typeof OauthAccountSchema>;
55
49
  export const OauthAccountListSchema = z.object({