@intentic/sandbox-contract 1.366.0 → 1.367.1

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 (104) hide show
  1. package/dist/contracts/agent.contract.d.ts +9 -0
  2. package/dist/contracts/agent.contract.d.ts.map +1 -1
  3. package/dist/contracts/agents.contract.d.ts +2 -0
  4. package/dist/contracts/agents.contract.d.ts.map +1 -1
  5. package/dist/contracts/device.contract.d.ts +43 -0
  6. package/dist/contracts/device.contract.d.ts.map +1 -1
  7. package/dist/contracts/needs.contract.d.ts +237 -0
  8. package/dist/contracts/needs.contract.d.ts.map +1 -1
  9. package/dist/contracts/needs.contract.js +10 -1
  10. package/dist/contracts/needs.contract.js.map +1 -1
  11. package/dist/contracts/ports.contract.d.ts +25 -0
  12. package/dist/contracts/ports.contract.d.ts.map +1 -1
  13. package/dist/contracts/ports.contract.js +29 -1
  14. package/dist/contracts/ports.contract.js.map +1 -1
  15. package/dist/contracts/runner.contract.d.ts +6 -0
  16. package/dist/contracts/runner.contract.d.ts.map +1 -1
  17. package/dist/contracts/sessions.contract.d.ts +1 -0
  18. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  19. package/dist/contracts/system.contract.d.ts +1498 -231
  20. package/dist/contracts/system.contract.d.ts.map +1 -1
  21. package/dist/contracts/system.contract.js +15 -3
  22. package/dist/contracts/system.contract.js.map +1 -1
  23. package/dist/events/agent-events.d.ts +5 -0
  24. package/dist/events/agent-events.d.ts.map +1 -1
  25. package/dist/events/agent-events.js +1 -0
  26. package/dist/events/agent-events.js.map +1 -1
  27. package/dist/events/agent-transcript.d.ts +1 -0
  28. package/dist/events/agent-transcript.d.ts.map +1 -1
  29. package/dist/events/system-events.d.ts +1077 -142
  30. package/dist/events/system-events.d.ts.map +1 -1
  31. package/dist/events/system-events.js +8 -0
  32. package/dist/events/system-events.js.map +1 -1
  33. package/dist/events/transcript.d.ts +6 -0
  34. package/dist/events/transcript.d.ts.map +1 -1
  35. package/dist/events/transcript.js +4 -0
  36. package/dist/events/transcript.js.map +1 -1
  37. package/dist/index.d.ts +1772 -231
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/netd/generated/wire.d.ts +8 -0
  40. package/dist/netd/generated/wire.d.ts.map +1 -1
  41. package/dist/protocol/raw/raw-json-routes.d.ts +3 -0
  42. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  43. package/dist/schemas/dev-rebuild-log.d.ts +2 -0
  44. package/dist/schemas/dev-rebuild-log.d.ts.map +1 -1
  45. package/dist/schemas/dev-rebuild-log.js +7 -1
  46. package/dist/schemas/dev-rebuild-log.js.map +1 -1
  47. package/dist/schemas/device-commands.d.ts +1 -1
  48. package/dist/schemas/device-commands.d.ts.map +1 -1
  49. package/dist/schemas/device-commands.js +1 -1
  50. package/dist/schemas/device-commands.js.map +1 -1
  51. package/dist/schemas/devices.d.ts +249 -0
  52. package/dist/schemas/devices.d.ts.map +1 -1
  53. package/dist/schemas/devices.js +6 -0
  54. package/dist/schemas/devices.js.map +1 -1
  55. package/dist/schemas/egress.d.ts +238 -0
  56. package/dist/schemas/egress.d.ts.map +1 -0
  57. package/dist/schemas/egress.js +192 -0
  58. package/dist/schemas/egress.js.map +1 -0
  59. package/dist/schemas/hosts.d.ts +2 -0
  60. package/dist/schemas/hosts.d.ts.map +1 -1
  61. package/dist/schemas/hosts.js +2 -0
  62. package/dist/schemas/hosts.js.map +1 -1
  63. package/dist/schemas/members.d.ts +4 -0
  64. package/dist/schemas/members.d.ts.map +1 -1
  65. package/dist/schemas/members.js +1 -1
  66. package/dist/schemas/members.js.map +1 -1
  67. package/dist/schemas/needs.d.ts +8 -0
  68. package/dist/schemas/needs.d.ts.map +1 -1
  69. package/dist/schemas/needs.js +8 -1
  70. package/dist/schemas/needs.js.map +1 -1
  71. package/dist/schemas/ports.d.ts +21 -0
  72. package/dist/schemas/ports.d.ts.map +1 -1
  73. package/dist/schemas/ports.js +12 -0
  74. package/dist/schemas/ports.js.map +1 -1
  75. package/dist/state/auth-state.d.ts.map +1 -1
  76. package/dist/state/auth-state.js +1 -0
  77. package/dist/state/auth-state.js.map +1 -1
  78. package/dist/text/transcript-fold.d.ts.map +1 -1
  79. package/dist/text/transcript-fold.js +1 -0
  80. package/dist/text/transcript-fold.js.map +1 -1
  81. package/package.json +5 -5
  82. package/src/contracts/needs.contract.ts +11 -0
  83. package/src/contracts/ports.contract.ts +42 -1
  84. package/src/contracts/system.contract.ts +24 -3
  85. package/src/events/agent-events.ts +2 -0
  86. package/src/events/system-events.ts +22 -1
  87. package/src/events/transcript.ts +5 -0
  88. package/src/netd/generated/netd-wire.json +44 -0
  89. package/src/netd/generated/wire.ts +36 -1
  90. package/src/schemas/dev-rebuild-log.test.ts +10 -1
  91. package/src/schemas/dev-rebuild-log.ts +14 -1
  92. package/src/schemas/device-commands.ts +1 -0
  93. package/src/schemas/devices.ts +14 -0
  94. package/src/schemas/egress-private.test.ts +17 -0
  95. package/src/schemas/egress.test.ts +109 -0
  96. package/src/schemas/egress.ts +331 -0
  97. package/src/schemas/hosts.ts +3 -0
  98. package/src/schemas/members.ts +3 -1
  99. package/src/schemas/needs.ts +9 -1
  100. package/src/schemas/ports.ts +25 -0
  101. package/src/state/auth-state.ts +3 -0
  102. package/src/state/daemon-floor.test.ts +1 -0
  103. package/src/text/transcript-fold.test.ts +7 -0
  104. package/src/text/transcript-fold.ts +1 -0
@@ -136,6 +136,25 @@ export type Presence = z.infer<typeof PresenceSchema>;
136
136
  export const AgentsSchema = z.object({ kind: z.literal("agents"), agents: z.array(AgentSummarySchema), rev: z.number() });
137
137
  export type Agents = z.infer<typeof AgentsSchema>;
138
138
 
139
+ // Only the cards running turns moved since this connection's previous roster frame (`since`, that frame's `rev`): what a
140
+ // connection that asked for changes (`roster: "changes"` on /events) gets in place of the whole roster on each progress
141
+ // tick, since resending every card to every window on every tool call made the roster the daemon's costliest send. Each
142
+ // card is whole, an upsert by id; a card leaving the board is never a change, it goes out as an `agents` snapshot. A
143
+ // browser holding an older roster than `since` missed a frame and reads GET /agents again. Sent even when the reader may
144
+ // see none of the cards, so the revision line it follows has no hole in it.
145
+ export const AgentsChangedSchema = z.object({
146
+ kind: z.literal("agentsChanged"),
147
+ agents: z.array(AgentSummarySchema),
148
+ rev: z.number(),
149
+ since: z.number(),
150
+ });
151
+ export type AgentsChanged = z.infer<typeof AgentsChangedSchema>;
152
+
153
+ // How a connection takes the roster as running agents make progress (/events `roster`): whole every time (`snapshots`,
154
+ // the default), or only the cards that moved (`changes`, as `agentsChanged` frames).
155
+ export const RosterFramesSchema = z.enum(["snapshots", "changes"]);
156
+ export type RosterFrames = z.infer<typeof RosterFramesSchema>;
157
+
139
158
  // An account's headroom just moved, keyed as the daemon's store keys it. Snapshot per account, last frame wins; `usage`
140
159
  // absent means the account was disconnected.
141
160
  export const AccountUsageChangedSchema = z.object({
@@ -168,7 +187,8 @@ export const TreeChangedSchema = WorkspaceTreeDeltaSchema.extend({ kind: z.liter
168
187
  export type TreeChanged = z.infer<typeof TreeChangedSchema>;
169
188
 
170
189
  // The /events stream union: hello, heartbeats, boot progress, workspace/repo/ref/runtime/shadow/tree changes, presence
171
- // and fleet rosters, account headroom and refusal changes. oRPC validates every frame against this.
190
+ // and fleet rosters (whole, or the cards that moved), account headroom and refusal changes. oRPC validates every frame
191
+ // against this.
172
192
  export const SystemEventSchema = z.discriminatedUnion("kind", [
173
193
  HelloSchema,
174
194
  HeartbeatSchema,
@@ -181,6 +201,7 @@ export const SystemEventSchema = z.discriminatedUnion("kind", [
181
201
  RuntimeChangedSchema,
182
202
  PresenceSchema,
183
203
  AgentsSchema,
204
+ AgentsChangedSchema,
184
205
  AccountUsageChangedSchema,
185
206
  ProviderRefusalChangedSchema,
186
207
  ]);
@@ -115,6 +115,10 @@ export const TranscriptToolSchema: z.ZodType<TranscriptTool> = z.lazy(() =>
115
115
  ),
116
116
  status: ToolCallStatusSchema.describe("How it went."),
117
117
  target: z.string().optional().describe("What it acted on, in one line: a file, a command, an address."),
118
+ description: z
119
+ .string()
120
+ .optional()
121
+ .describe("The agent's own words for what the call does, where its input carried them beside a target (a shell command's description)."),
118
122
  locations: z.array(ToolCallLocationSchema).optional().describe("The files it touched."),
119
123
  content: z.array(ToolCallContentSchema).optional().describe("What it produced: text, a change to a file, or a picture."),
120
124
  children: z
@@ -188,6 +192,7 @@ export interface TranscriptTool {
188
192
  category: ToolKind;
189
193
  status: ToolCallStatus;
190
194
  target?: string | undefined;
195
+ description?: string | undefined;
191
196
  locations?: ToolCallLocation[] | undefined;
192
197
  content?: ToolCallContent[] | undefined;
193
198
  children?: TranscriptTool[] | undefined;
@@ -134,6 +134,17 @@
134
134
  }
135
135
  ]
136
136
  },
137
+ "previewGuard": {
138
+ "anyOf": [
139
+ {
140
+ "$ref": "#/$defs/PreviewGuard"
141
+ },
142
+ {
143
+ "type": "null"
144
+ }
145
+ ],
146
+ "description": "The owner's guard on preview hosts arriving from outside; absent, every preview host is open to anyone with its\naddress, as before the guard existed (2026-10-27). An older netd ignores it."
147
+ },
137
148
  "previewProbePath": {
138
149
  "description": "A preview path Node answers whatever its host resolves to.",
139
150
  "type": "string"
@@ -204,6 +215,39 @@
204
215
  ],
205
216
  "type": "object"
206
217
  },
218
+ "PreviewGuard": {
219
+ "description": "Which preview hosts need the sandbox's pass, and how netd checks one (2026-10-27). netd applies it to requests on\nthe preview port and the tunnel only, never on the machine's loopback port, and never to the outbox (`public-`).\nA covered host lets through a pass that verifies (its cookie taken off before the upstream sees it), the probe, a\nCORS preflight, and the pass's exchange (handed back to Node); a navigation without a pass is handed back for Node's\npage, and anything else is answered 401 by netd itself, without asking Node.",
220
+ "properties": {
221
+ "cookie": {
222
+ "description": "The cookie a pass rides in: `v1.<expiry in unix seconds>.<signature>`, the signature unpadded base64url\nHMAC-SHA256 of `v1.<expiry>` under `key`.",
223
+ "type": "string"
224
+ },
225
+ "key": {
226
+ "description": "The HMAC key, as its text's bytes; Node replaces it to end every pass at once.",
227
+ "type": "string"
228
+ },
229
+ "panels": {
230
+ "description": "Panel previews (`preview-<panel>-<id>`) need a pass.",
231
+ "type": "boolean"
232
+ },
233
+ "passPath": {
234
+ "description": "The path a pass is exchanged on for its cookie, which netd hands back to Node marked `pass`.",
235
+ "type": "string"
236
+ },
237
+ "ports": {
238
+ "description": "Forwarded ports (`port-<slot>-<id>`) need a pass.",
239
+ "type": "boolean"
240
+ }
241
+ },
242
+ "required": [
243
+ "panels",
244
+ "ports",
245
+ "cookie",
246
+ "key",
247
+ "passPath"
248
+ ],
249
+ "type": "object"
250
+ },
207
251
  "PreviewRoute": {
208
252
  "description": "What becomes of a preview host's request, decided by Node once, when asked.",
209
253
  "oneOf": [
@@ -33,7 +33,12 @@ frameAncestors: Array<string>,
33
33
  /**
34
34
  * A preview path Node answers whatever its host resolves to.
35
35
  */
36
- previewProbePath: string, };
36
+ previewProbePath: string,
37
+ /**
38
+ * The owner's guard on preview hosts arriving from outside; absent, every preview host is open to anyone with its
39
+ * address, as before the guard existed (2026-10-27). An older netd ignores it.
40
+ */
41
+ previewGuard?: PreviewGuard, };
37
42
 
38
43
  export type NetdAnswer = { "answer": "sync", generations: Array<number | null>, };
39
44
 
@@ -53,6 +58,36 @@ export type NetdQuestion = { "question": "sync", dirs: Array<string>, };
53
58
  */
54
59
  export type Page = { status: number, headers: { [key in string]: string }, body: string, };
55
60
 
61
+ /**
62
+ * Which preview hosts need the sandbox's pass, and how netd checks one (2026-10-27). netd applies it to requests on
63
+ * the preview port and the tunnel only, never on the machine's loopback port, and never to the outbox (`public-`).
64
+ * A covered host lets through a pass that verifies (its cookie taken off before the upstream sees it), the probe, a
65
+ * CORS preflight, and the pass's exchange (handed back to Node); a navigation without a pass is handed back for Node's
66
+ * page, and anything else is answered 401 by netd itself, without asking Node.
67
+ */
68
+ export type PreviewGuard = {
69
+ /**
70
+ * Panel previews (`preview-<panel>-<id>`) need a pass.
71
+ */
72
+ panels: boolean,
73
+ /**
74
+ * Forwarded ports (`port-<slot>-<id>`) need a pass.
75
+ */
76
+ ports: boolean,
77
+ /**
78
+ * The cookie a pass rides in: `v1.<expiry in unix seconds>.<signature>`, the signature unpadded base64url
79
+ * HMAC-SHA256 of `v1.<expiry>` under `key`.
80
+ */
81
+ cookie: string,
82
+ /**
83
+ * The HMAC key, as its text's bytes; Node replaces it to end every pass at once.
84
+ */
85
+ key: string,
86
+ /**
87
+ * The path a pass is exchanged on for its cookie, which netd hands back to Node marked `pass`.
88
+ */
89
+ passPath: string, };
90
+
56
91
  /**
57
92
  * What becomes of a preview host's request, decided by Node once, when asked.
58
93
  */
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DEV_REBUILD_ALIVE_MARK,
2
3
  DEV_REBUILD_CANCEL_MARK,
3
4
  DEV_REBUILD_EXIT_MARK,
4
5
  DEV_REBUILD_HOLD_MARK,
@@ -76,7 +77,15 @@ test("reads the hold file's state and turbo's count, which the read prints befor
76
77
 
77
78
  // An older daemon's read says neither, which is "unknown" rather than "not held": the card then offers no choice.
78
79
  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
+ expect(readDevRebuildLog(answer("3", "building"))).toMatchObject({ hold: undefined, tasks: undefined, alive: undefined });
81
+ });
82
+
83
+ // The guard's own test, printed for the card: whether the build's process is there is a fact the log's silence is not.
84
+ test("reads whether the build's process is alive, which the read prints before the tail", () => {
85
+ const held = readDevRebuildLog(answer("14400", `${DEV_REBUILD_ALIVE_MARK} 1`, "#27 DONE 223.2s", DEV_REBUILD_WAITING_MARK));
86
+ expect(held).toMatchObject({ alive: true, waiting: true, quietFor: 14400 });
87
+ expect(held.lines).toEqual(["#27 DONE 223.2s"]);
88
+ expect(readDevRebuildLog(answer("-", `${DEV_REBUILD_ALIVE_MARK} 0`))).toMatchObject({ alive: false, missing: true });
80
89
  });
81
90
 
82
91
  // The gate's two words, in order: holding, then let through. Whichever came last is where it stands.
@@ -26,6 +26,13 @@ export const DEV_REBUILD_EXIT_MARK = "@intentic-rebuild-exit";
26
26
  export const DEV_REBUILD_QUIET_MARK = "@intentic-rebuild-quiet";
27
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
28
  export const DEV_REBUILD_HOLD_MARK = "@intentic-rebuild-hold";
29
+ // `dev-rebuild-log` prints whether the build's session is alive right now: `1` when the pid file names a live
30
+ // `rebuild:sandbox` process, `0` otherwise. It is the same test the device's guard runs before starting another
31
+ // rebuild, so the card and the guard cannot disagree about whether one is running. Without it the card guessed from
32
+ // the log's silence, and a build held at its swap gate (silent by design) dropped off the card after two minutes while
33
+ // the guard went on refusing every new rebuild (rog, 2026-10-27: four hours with no card and no way to cancel).
34
+ // Absent from an older daemon's read.
35
+ export const DEV_REBUILD_ALIVE_MARK = "@intentic-rebuild-alive";
29
36
  // `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
37
  // 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
38
  // "Running build in N packages" is the packages in scope, a quarter of the tasks), so the total is `-` until turbo's own
@@ -55,6 +62,8 @@ export interface DevRebuildLog {
55
62
  readonly exitCode: number | undefined;
56
63
  /** Ended because somebody cancelled it (`dev-rebuild-cancel`), not because it failed. */
57
64
  readonly cancelled: boolean;
65
+ /** Whether the build's process is running right now (DEV_REBUILD_ALIVE_MARK); undefined from a daemon too old to say. */
66
+ readonly alive: boolean | undefined;
58
67
  /** Whether the hold file is there; undefined from a daemon too old to say. */
59
68
  readonly hold: boolean | undefined;
60
69
  /** The gate is holding right now: the images are built, the container untouched, the restart waiting to be let through. */
@@ -86,6 +95,7 @@ export const readDevRebuildLog = (text: string): DevRebuildLog => {
86
95
  let exitCode: number | undefined;
87
96
  let cancelled = false;
88
97
  let hold: boolean | undefined;
98
+ let alive: boolean | undefined;
89
99
  let tasks: DevRebuildTasks | undefined;
90
100
  // The last of the gate's two words: the tail is in order, so whichever came last is where the gate stands.
91
101
  let gate: `waiting` | `swap` | undefined;
@@ -95,6 +105,7 @@ export const readDevRebuildLog = (text: string): DevRebuildLog => {
95
105
  const quiet = markValue(line, DEV_REBUILD_QUIET_MARK);
96
106
  const exit = markValue(line, DEV_REBUILD_EXIT_MARK);
97
107
  const held = markValue(line, DEV_REBUILD_HOLD_MARK);
108
+ const living = markValue(line, DEV_REBUILD_ALIVE_MARK);
98
109
  const counted = markValue(line, DEV_REBUILD_TASKS_MARK);
99
110
  if (quiet !== undefined) {
100
111
  missing = quiet === "-";
@@ -102,6 +113,8 @@ export const readDevRebuildLog = (text: string): DevRebuildLog => {
102
113
  } else if (exit !== undefined) {
103
114
  // A mark whose status is unreadable still means the build ENDED, and not well.
104
115
  exitCode = wholeNumber(exit) ?? 1;
116
+ } else if (living !== undefined) {
117
+ alive = living === `1`;
105
118
  } else if (held !== undefined) {
106
119
  hold = held === `1`;
107
120
  } else if (counted !== undefined) {
@@ -122,5 +135,5 @@ export const readDevRebuildLog = (text: string): DevRebuildLog => {
122
135
  }
123
136
  // A gate still holding has printed nothing since its word, and a build that ended is holding nothing.
124
137
  const waiting = gate === `waiting` && exitCode === undefined;
125
- return { missing, quietFor, exitCode, cancelled, hold, waiting, swapping, tasks, lines };
138
+ return { missing, quietFor, exitCode, cancelled, alive, hold, waiting, swapping, tasks, lines };
126
139
  };
@@ -41,6 +41,7 @@ export type DeviceSyncSwitch = z.infer<typeof DeviceSyncSwitchSchema>;
41
41
 
42
42
  // Where a detached rebuild reports itself, and the reader of that report (dev-rebuild-log.ts).
43
43
  export {
44
+ DEV_REBUILD_ALIVE_MARK,
44
45
  DEV_REBUILD_CANCEL_MARK,
45
46
  DEV_REBUILD_EXIT_MARK,
46
47
  DEV_REBUILD_HOLD_MARK,
@@ -3,6 +3,7 @@ import { z } from "zod";
3
3
  import { PortNumberSchema } from "./device-commands.js";
4
4
  import { DeviceBridgeHoldSchema, DeviceConflictSchema, DeviceCopySchema, DeviceLowDiskSchema } from "./device-folder.js";
5
5
  import { parseHostConnection, type DeviceFacts, DeviceFactsSchema, MachineIdentitySchema, MachineIdSchema, userDistrosOf, WslEnvironmentSchema } from "./hosts.js";
6
+ import { EgressOwnerKeysSchema, EgressPolicySchema, EgressProofSchema, EgressStatusSchema } from "./egress.js";
6
7
  import { RollbackTargetSchema, UpdateOutcomeSchema } from "./updates.js";
7
8
  import { DEV_VERSION } from "../state/versions.js";
8
9
  // Desktop-sync report shape shared by the agent, daemon and browser, produced only by the agent's own `deviceReport`.
@@ -79,6 +80,9 @@ export const DeviceSandboxSchema = z.object({
79
80
  resources: SandboxResourcesSchema.optional(),
80
81
  // The update `ic sandbox prepare` built and left waiting for this sandbox; absent when nothing is staged.
81
82
  staged: z.object({ image: z.string(), version: z.string().optional(), channel: z.string().optional() }).optional(),
83
+ // (2026-10-27) What ic holds and enforces for the sandbox's outbound traffic (egress.ts). Absent from an ic older
84
+ // than `ic sandbox egress`, and from a row whose container docker would not inspect.
85
+ egress: EgressStatusSchema.optional(),
82
86
  // Everything below is read off an `ic` new enough to know it; an older ic's listing simply lacks it.
83
87
  // What the running image says it is.
84
88
  version: z.string().optional(),
@@ -136,6 +140,10 @@ export const DeviceSandboxOpSchema = z.enum([
136
140
  "reshape",
137
141
  "set-shape",
138
142
  "forget-shape",
143
+ // (2026-10-27) Sets the sandbox's whole egress policy through `ic sandbox egress` (egress.ts). A change that only
144
+ // tightens is carried out as it comes; any other needs `egressProof`, the owner's passkey over it, which the machine
145
+ // agent checks against the passkeys it pinned for this sandbox. Sent only to an agent advertising `egress`.
146
+ "set-egress",
139
147
  "remove",
140
148
  "logs",
141
149
  // The two ops that redeem a fresh setup code; every other one recreates a container from its own existing env.
@@ -167,6 +175,12 @@ export const DeviceSandboxFlowSchema = z.strictObject({
167
175
  // reader): an order carrying a field this agent does not know is refused rather than carried out without it.
168
176
  shape: z.strictObject(SandboxShapeSchema.shape).optional(),
169
177
  when: SandboxShapeWhenSchema.optional(),
178
+ // `set-egress` only: the whole policy (required), the owner's passkey over a change that loosens it, and,
179
+ // daemon-filled and never the caller's, the owner's passkeys the agent pins on the first `set-egress` and replaces
180
+ // only under a proof signed by a key it already pins.
181
+ egress: EgressPolicySchema.optional(),
182
+ egressProof: EgressProofSchema.optional(),
183
+ egressOwnerKeys: EgressOwnerKeysSchema.optional(),
170
184
  // READ-ONLY for one release, from pages served by sandboxes older than `set-shape`: the old `reshape` op's delta,
171
185
  // and `later` to save it for the next restart instead. Nothing new sends either.
172
186
  resources: SandboxResourcesAskSchema.optional(),
@@ -0,0 +1,17 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { packageRoot } from "@intentic/constants/node";
4
+ import { EGRESS_PRIVATE_V4, EGRESS_PRIVATE_V6 } from "./egress.js";
5
+
6
+ // ic renders these ranges into its nftables rules (_sandbox/ic/src/sandbox/egress/render.rs), and its Rust test reads the
7
+ // same golden, so a range added here and not there fails one side or the other instead of fencing differently.
8
+ // SAFETY: the golden is this package's own file; the assertions below fail on any field it lacks.
9
+ const GOLDEN = JSON.parse(readFileSync(join(packageRoot(import.meta.url), "golden", "egress-private.json"), "utf8")) as {
10
+ readonly v4: string[];
11
+ readonly v6: string[];
12
+ };
13
+
14
+ test("the private ranges internet-only refuses are the ones ic renders", () => {
15
+ expect([...EGRESS_PRIVATE_V4]).toEqual(GOLDEN.v4);
16
+ expect([...EGRESS_PRIVATE_V6]).toEqual(GOLDEN.v6);
17
+ });
@@ -0,0 +1,109 @@
1
+ import { DeviceSandboxFlowSchema } from "./devices.js";
2
+ import {
3
+ canonicalEgressOwnerKeysJson,
4
+ canonicalEgressPolicy,
5
+ canonicalEgressPolicyJson,
6
+ EgressAllowSchema,
7
+ EgressChangeDocumentSchema,
8
+ egressChangeDocumentText,
9
+ egressDestinationKind,
10
+ egressOnlyTightens,
11
+ EgressPolicySchema,
12
+ icEgressSetArgs,
13
+ OPEN_EGRESS,
14
+ type EgressPolicy,
15
+ } from "./egress.js";
16
+
17
+ // The fence's words are read by ic (Rust), the machine agent and the editor, so what a destination is, what a
18
+ // tightening is and how a policy is spelled to ic are pinned here.
19
+
20
+ const fenced = (allow: EgressPolicy["allow"]): EgressPolicy => ({ profile: "internet-only", allow });
21
+
22
+ test("a destination is an address or prefix of either family, a hostname, or the word host", () => {
23
+ expect(egressDestinationKind("192.168.1.20")).toBe("v4");
24
+ expect(egressDestinationKind("10.0.0.0/8")).toBe("v4");
25
+ expect(egressDestinationKind("fd00::/8")).toBe("v6");
26
+ expect(egressDestinationKind("fe80::1")).toBe("v6");
27
+ expect(egressDestinationKind("host")).toBe("host");
28
+ expect(egressDestinationKind("nas.lan")).toBe("name");
29
+ expect(egressDestinationKind("printer")).toBe("name");
30
+ // A typo'd address is never read as a hostname.
31
+ expect(egressDestinationKind("300.1.1.1")).toBeUndefined();
32
+ expect(egressDestinationKind("10.0.0.0/40")).toBeUndefined();
33
+ expect(egressDestinationKind("fd00::zz")).toBeUndefined();
34
+ expect(egressDestinationKind("-bad.lan")).toBeUndefined();
35
+ });
36
+
37
+ test("ports are single ports or upward ranges inside 1-65535", () => {
38
+ expect(EgressAllowSchema.safeParse({ to: "nas.lan", ports: [445, "8000-8100"] }).success).toBe(true);
39
+ expect(EgressAllowSchema.safeParse({ to: "nas.lan", ports: ["8100-8000"] }).success).toBe(false);
40
+ expect(EgressAllowSchema.safeParse({ to: "nas.lan", ports: [0] }).success).toBe(false);
41
+ expect(EgressAllowSchema.safeParse({ to: "nas.lan", ports: ["1-70000"] }).success).toBe(false);
42
+ // Strict: a field this side does not know is refused, never dropped.
43
+ expect(EgressAllowSchema.safeParse({ to: "nas.lan", via: "vpn" }).success).toBe(false);
44
+ });
45
+
46
+ test("two policies that fence the same way spell the same", () => {
47
+ const a = fenced([
48
+ { to: "NAS.lan.", ports: [445, 139, 445] },
49
+ { to: "192.168.1.20", protocol: "tcp", ports: [22] },
50
+ ]);
51
+ const b = fenced([
52
+ { to: "192.168.1.20", ports: [22], protocol: "tcp" },
53
+ { to: "nas.lan", ports: [139, 445] },
54
+ { to: "nas.lan", ports: [445, 139] },
55
+ ]);
56
+ expect(canonicalEgressPolicyJson(a)).toBe(canonicalEgressPolicyJson(b));
57
+ expect(canonicalEgressPolicy(a).allow.map((entry) => entry.to)).toEqual(["192.168.1.20", "nas.lan"]);
58
+ });
59
+
60
+ test("turning the fence on, or dropping an exception, only tightens", () => {
61
+ expect(egressOnlyTightens(OPEN_EGRESS, fenced([{ to: "host" }]))).toBe(true);
62
+ expect(egressOnlyTightens(fenced([{ to: "nas.lan", ports: [445] }, { to: "host" }]), fenced([{ to: "nas.lan", ports: [445] }]))).toBe(true);
63
+ // A note or a card name changes nothing about what is reachable.
64
+ expect(egressOnlyTightens(fenced([{ to: "nas.lan", ports: [445] }]), fenced([{ to: "nas.lan", ports: [445], note: "the NAS", from: "netdisk:nas" }]))).toBe(true);
65
+ });
66
+
67
+ test("turning the fence off, adding an exception or widening one loosens", () => {
68
+ expect(egressOnlyTightens(fenced([]), OPEN_EGRESS)).toBe(false);
69
+ expect(egressOnlyTightens(fenced([]), fenced([{ to: "192.168.1.20" }]))).toBe(false);
70
+ expect(egressOnlyTightens(fenced([{ to: "nas.lan", ports: [445] }]), fenced([{ to: "nas.lan" }]))).toBe(false);
71
+ expect(egressOnlyTightens(fenced([{ to: "nas.lan", protocol: "tcp" }]), fenced([{ to: "nas.lan" }]))).toBe(false);
72
+ // Written differently is asked about, not reasoned about: a narrower prefix still needs the owner.
73
+ expect(egressOnlyTightens(fenced([{ to: "192.168.0.0/16" }]), fenced([{ to: "192.168.1.0/24" }]))).toBe(false);
74
+ });
75
+
76
+ test("ic is handed the canonical policy as one JSON argument", () => {
77
+ const args = icEgressSetArgs("work", fenced([{ to: "nas.lan", ports: [445] }]));
78
+ expect(args.slice(0, 4)).toEqual(["sandbox", "egress", "work", "--policy"]);
79
+ expect(EgressPolicySchema.parse(JSON.parse(args[4] ?? ""))).toEqual({ profile: "internet-only", allow: [{ to: "nas.lan", ports: [445] }] });
80
+ });
81
+
82
+ test("the owner keys hash the same whatever order the daemon lists them in", () => {
83
+ const one = { id: "a", alg: -7 as const, jwk: { kty: "EC", crv: "P-256", x: "x1", y: "y1" }, name: "laptop" };
84
+ const two = { id: "b", alg: -8 as const, jwk: { x: "x2", kty: "OKP", crv: "Ed25519" } };
85
+ expect(canonicalEgressOwnerKeysJson({ rpId: "intentic.dev", origins: ["https://app.intentic.dev", "android:apk-key-hash:abc"], keys: [one, two] })).toBe(
86
+ canonicalEgressOwnerKeysJson({ rpId: "intentic.dev", origins: ["android:apk-key-hash:abc", "https://app.intentic.dev"], keys: [two, { ...one, jwk: { y: "y1", x: "x1", crv: "P-256", kty: "EC" } }] }),
87
+ );
88
+ });
89
+
90
+ test("a signed change parses back from the text it was signed as", () => {
91
+ const document = {
92
+ v: 1 as const,
93
+ purpose: "intentic-egress-change" as const,
94
+ machineId: "m-0123456789",
95
+ environment: "wsl:archlinux",
96
+ slug: "work",
97
+ basedOn: "none",
98
+ policy: fenced([{ to: "nas.lan", ports: [445] }]),
99
+ keys: "0".repeat(64),
100
+ expiresAt: 1_800_000_000_000,
101
+ nonce: "abcdefghijklmnop",
102
+ };
103
+ expect(EgressChangeDocumentSchema.parse(JSON.parse(egressChangeDocumentText(document)))).toEqual(document);
104
+ });
105
+
106
+ test("a set-egress order carries the policy, and refuses a field the agent does not know", () => {
107
+ expect(DeviceSandboxFlowSchema.safeParse({ op: "set-egress", slug: "work", egress: fenced([]) }).success).toBe(true);
108
+ expect(DeviceSandboxFlowSchema.safeParse({ op: "set-egress", slug: "work", egress: { profile: "internet-only", allow: [], extra: true } }).success).toBe(false);
109
+ });