@intentic/sandbox-contract 1.406.0 → 1.407.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 (86) hide show
  1. package/dist/contracts/agent.contract.d.ts +1 -0
  2. package/dist/contracts/agent.contract.d.ts.map +1 -1
  3. package/dist/contracts/device.contract.d.ts +3 -0
  4. package/dist/contracts/device.contract.d.ts.map +1 -1
  5. package/dist/contracts/runner.contract.d.ts +252 -250
  6. package/dist/contracts/runner.contract.d.ts.map +1 -1
  7. package/dist/contracts/settings.contract.d.ts +2 -0
  8. package/dist/contracts/settings.contract.d.ts.map +1 -1
  9. package/dist/contracts/system.contract.d.ts +15 -0
  10. package/dist/contracts/system.contract.d.ts.map +1 -1
  11. package/dist/contracts/system.contract.js +19 -1
  12. package/dist/contracts/system.contract.js.map +1 -1
  13. package/dist/events/agent-events.d.ts +2 -0
  14. package/dist/events/agent-events.d.ts.map +1 -1
  15. package/dist/events/agent-events.js +1 -0
  16. package/dist/events/agent-events.js.map +1 -1
  17. package/dist/events/sandbox-notice.d.ts +5 -0
  18. package/dist/events/sandbox-notice.d.ts.map +1 -1
  19. package/dist/events/sandbox-notice.js +1 -0
  20. package/dist/events/sandbox-notice.js.map +1 -1
  21. package/dist/ids/conversation-ids.d.ts +5 -0
  22. package/dist/ids/conversation-ids.d.ts.map +1 -1
  23. package/dist/ids/conversation-ids.js +20 -109
  24. package/dist/ids/conversation-ids.js.map +1 -1
  25. package/dist/ids/conversation-words.d.ts +2 -0
  26. package/dist/ids/conversation-words.d.ts.map +1 -0
  27. package/dist/ids/conversation-words.js +35 -0
  28. package/dist/ids/conversation-words.js.map +1 -0
  29. package/dist/models/model-roles.d.ts +8 -0
  30. package/dist/models/model-roles.d.ts.map +1 -1
  31. package/dist/models/model-roles.js +8 -0
  32. package/dist/models/model-roles.js.map +1 -1
  33. package/dist/policy/failure-codes.d.ts +5 -0
  34. package/dist/policy/failure-codes.d.ts.map +1 -1
  35. package/dist/policy/failure-codes.js +1 -0
  36. package/dist/policy/failure-codes.js.map +1 -1
  37. package/dist/protocol/doors/runner-protocol.d.ts +17 -0
  38. package/dist/protocol/doors/runner-protocol.d.ts.map +1 -1
  39. package/dist/protocol/doors/runner-protocol.js +22 -0
  40. package/dist/protocol/doors/runner-protocol.js.map +1 -1
  41. package/dist/protocol/peer-dial.d.ts +1 -0
  42. package/dist/protocol/peer-dial.d.ts.map +1 -1
  43. package/dist/protocol/peer-dial.js +1 -1
  44. package/dist/protocol/peer-dial.js.map +1 -1
  45. package/dist/schemas/agent.d.ts +4 -0
  46. package/dist/schemas/agent.d.ts.map +1 -1
  47. package/dist/schemas/keyring.d.ts +6 -0
  48. package/dist/schemas/keyring.d.ts.map +1 -1
  49. package/dist/schemas/keyring.js +3 -0
  50. package/dist/schemas/keyring.js.map +1 -1
  51. package/dist/schemas/offload.d.ts +5 -0
  52. package/dist/schemas/offload.d.ts.map +1 -1
  53. package/dist/schemas/offload.js +2 -0
  54. package/dist/schemas/offload.js.map +1 -1
  55. package/dist/schemas/push.d.ts +6 -0
  56. package/dist/schemas/push.d.ts.map +1 -1
  57. package/dist/schemas/push.js +2 -0
  58. package/dist/schemas/push.js.map +1 -1
  59. package/dist/schemas/settings.d.ts +2 -0
  60. package/dist/schemas/settings.d.ts.map +1 -1
  61. package/dist/schemas/settings.js +1 -1
  62. package/dist/schemas/settings.js.map +1 -1
  63. package/dist/schemas/system.d.ts +23 -0
  64. package/dist/schemas/system.d.ts.map +1 -1
  65. package/dist/schemas/system.js +13 -0
  66. package/dist/schemas/system.js.map +1 -1
  67. package/dist/state/definition.d.ts +4 -4
  68. package/package.json +5 -5
  69. package/src/contracts/system.contract.ts +33 -1
  70. package/src/events/agent-events.ts +3 -0
  71. package/src/events/sandbox-notice.ts +3 -0
  72. package/src/ids/conversation-ids.test.ts +83 -12
  73. package/src/ids/conversation-ids.ts +39 -117
  74. package/src/ids/conversation-words.ts +40 -0
  75. package/src/models/model-roles.ts +10 -0
  76. package/src/policy/failure-codes.ts +3 -0
  77. package/src/policy/tests/failure-codes.test.ts +4 -1
  78. package/src/protocol/doors/runner-protocol.test.ts +22 -0
  79. package/src/protocol/doors/runner-protocol.ts +44 -0
  80. package/src/protocol/peer-dial.test.ts +30 -1
  81. package/src/protocol/peer-dial.ts +4 -1
  82. package/src/schemas/keyring.ts +4 -0
  83. package/src/schemas/offload.ts +13 -1
  84. package/src/schemas/push.ts +7 -0
  85. package/src/schemas/settings.ts +3 -2
  86. package/src/schemas/system.ts +25 -0
@@ -1,7 +1,9 @@
1
1
  // A conversation's id is the most public string this app produces: the git branch, the worktree directory, the URL, and
2
- // the card title. `adjective-noun-tail` reads at a glance; the tail keeps it unique and must satisfy
2
+ // the card title. `word-tail` reads at a glance; the tail keeps it unique and must satisfy
3
3
  // ConversationIdSchema. Sandbox-started conversations use their own prefixed, derived ids instead.
4
4
 
5
+ import { CONVERSATION_WORDS } from "./conversation-words.js";
6
+
5
7
  // The injection guard every path that interpolates a conversation id relies on: is this safe to put in a path.
6
8
  export const CONVERSATION_ID = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
7
9
 
@@ -15,117 +17,14 @@ export const CONVERSATION_TITLE_MAX = 80;
15
17
  export const clipTitle = (title: string): string =>
16
18
  title.length <= CONVERSATION_TITLE_MAX ? title : `${title.slice(0, CONVERSATION_TITLE_MAX - 1).trimEnd()}…`;
17
19
 
18
- // Short (nothing over seven letters) and visually distinct: no near-rhymes, no shared first syllable.
19
- const ADJECTIVES = [
20
- "amber",
21
- "brave",
22
- "brisk",
23
- "calm",
24
- "clear",
25
- "coral",
26
- "crisp",
27
- "deft",
28
- "eager",
29
- "fair",
30
- "fleet",
31
- "glad",
32
- "grand",
33
- "keen",
34
- "kind",
35
- "lively",
36
- "lucid",
37
- "mellow",
38
- "merry",
39
- "mild",
40
- "noble",
41
- "plain",
42
- "prime",
43
- "proud",
44
- "quick",
45
- "quiet",
46
- "rapid",
47
- "ready",
48
- "rich",
49
- "ripe",
50
- "sharp",
51
- "sleek",
52
- "smart",
53
- "snug",
54
- "solid",
55
- "spry",
56
- "stark",
57
- "steady",
58
- "still",
59
- "stout",
60
- "sunny",
61
- "swift",
62
- "tidy",
63
- "true",
64
- "vivid",
65
- "warm",
66
- "wise",
67
- "witty",
68
- ] as const;
69
-
70
- const NOUNS = [
71
- "alder",
72
- "anchor",
73
- "arbor",
74
- "arrow",
75
- "aspen",
76
- "badger",
77
- "basin",
78
- "beacon",
79
- "birch",
80
- "bison",
81
- "cedar",
82
- "cinder",
83
- "comet",
84
- "condor",
85
- "cove",
86
- "crane",
87
- "delta",
88
- "ember",
89
- "falcon",
90
- "fern",
91
- "fjord",
92
- "forge",
93
- "gale",
94
- "glade",
95
- "harbor",
96
- "heron",
97
- "ivy",
98
- "lantern",
99
- "ledger",
100
- "lichen",
101
- "lynx",
102
- "maple",
103
- "marsh",
104
- "meadow",
105
- "mesa",
106
- "moth",
107
- "otter",
108
- "pebble",
109
- "pine",
110
- "quarry",
111
- "quill",
112
- "raven",
113
- "reef",
114
- "ridge",
115
- "rowan",
116
- "sable",
117
- "sage",
118
- "shale",
119
- "spruce",
120
- "summit",
121
- "thistle",
122
- "tundra",
123
- "vale",
124
- "willow",
125
- "wren",
126
- ] as const;
127
-
128
- // Four base36 characters is 1.7M values per word pair, far past any workspace's collision risk.
20
+ // One word and a tail: `otter-k7mq`, about ten characters, since every letter counts on the board's rows. The word is
21
+ // what a person reads and says; the tail is what keeps it unique.
22
+ //
23
+ // The tail is lowercase on purpose. The id is also the branch and the worktree directory, and both reach Windows and
24
+ // macOS filesystems that fold case, where `otter-K7mq` and `otter-k7mq` would be one folder. So the tail's alphabet is
25
+ // base36 with the characters people misread dropped (0/o, 1/l/i): 31 symbols, four of them 923,521 values per word,
26
+ // and with the word list about 2^29 ids in all, far past any workspace's collision risk.
27
+ export const TAIL_ALPHABET = "23456789abcdefghjkmnpqrstuvwxyz";
129
28
  const TAIL_LENGTH = 4;
130
29
 
131
30
  // Rejects the short remainder above the last full bucket rather than folding it back with `%`, which would bias the
@@ -146,12 +45,35 @@ const randomBelow = (upperBound: number): number => {
146
45
  // get the same name.
147
46
  const pick = <T>(values: readonly T[]): T => values[randomBelow(values.length)]!;
148
47
 
149
- // Lowercase base36, one character per draw: 0-9a-z, all of which the id guard accepts.
150
- const tail = (): string => Array.from({ length: TAIL_LENGTH }, () => randomBelow(36).toString(36)).join("");
48
+ // One TAIL_ALPHABET character per draw, all of which the id guard accepts.
49
+ const TAIL_SYMBOLS = [...TAIL_ALPHABET];
50
+ const tail = (): string => Array.from({ length: TAIL_LENGTH }, () => pick(TAIL_SYMBOLS)).join("");
51
+
52
+ // A fresh id: `<word>-<tail>`, e.g. `otter-k7mq`; about ten characters against a UUID's thirty-six.
53
+ export const newConversationId = (): string => `${pick(CONVERSATION_WORDS)}-${tail()}`;
54
+
55
+ // A DRAWN ID WORN UNDER A PREFIX. Three kinds of conversation draw an id like any other and say what they are in front
56
+ // of it: a spawned subagent (`sub-otter-k7mq`), a conversation a link opened here (`link-…`) and the roster entry for a
57
+ // task running on a linked sandbox (`linked-…`). Kept here beside the word list, since no word may read as one of them.
58
+ export const SUBAGENT_PREFIX = "sub-";
59
+ export const LINK_CONVERSATION_PREFIX = "link-";
60
+ export const LINKED_PREFIX = "linked-";
61
+ const WRAPPING_PREFIXES = [SUBAGENT_PREFIX, LINK_CONVERSATION_PREFIX, LINKED_PREFIX];
62
+ const unwrapped = (id: string): string => {
63
+ const prefix = WRAPPING_PREFIXES.find((candidate) => id.startsWith(candidate));
64
+ return prefix === undefined ? id : id.slice(prefix.length);
65
+ };
151
66
 
152
- // A fresh id: `<adjective>-<noun>-<tail>`, e.g. `swift-otter-k9m2`; about sixteen characters against a UUID's
153
- // thirty-six.
154
- export const newConversationId = (): string => `${pick(ADJECTIVES)}-${pick(NOUNS)}-${tail()}`;
67
+ // Whether an id is shaped like one `newConversationId` draws, or like the `adjective-noun-xxxx` ids it drew before,
68
+ // bare or under one of the prefixes above. For telling an instance apart from a route (perf rollups), not a guard: a
69
+ // derived id can still look like one.
70
+ const WORDS = new Set(CONVERSATION_WORDS);
71
+ const DRAWN_ID = new RegExp(`^([a-z]+)-[${TAIL_ALPHABET}]{${TAIL_LENGTH}}$`);
72
+ const LEGACY_DRAWN_ID = /^[a-z]+-[a-z]+-[a-z0-9]{4}$/;
73
+ export const looksDrawn = (id: string): boolean => {
74
+ const drawn = unwrapped(id);
75
+ return WORDS.has(DRAWN_ID.exec(drawn)?.[1] ?? "") || LEGACY_DRAWN_ID.test(drawn);
76
+ };
155
77
 
156
78
  // Derived, not drawn, so a re-computed id says whether an agent is already on this failure and a second press continues
157
79
  // it. The repo is included (one run id per project) and slugified, not hashed, since people read it.
@@ -0,0 +1,40 @@
1
+ // The words a fresh conversation id is drawn from (`newConversationId`): everyday concrete nouns (animals, food,
2
+ // nature, things, places) that a non-native English speaker reads and spells at sight, three to six letters, lowercase
3
+ // a-z only. Kept out: rare or hard-to-spell words, slang and words with a rude second meaning, and words that already
4
+ // mean something in git or in this app's id space (`main`, `fork`, `branch`, `home`, `link`, `sub`, `job`, `web`, `watch`), so an
5
+ // id never reads as a ref, a command or one of the derived, prefixed ids. Alphabetical, one space apart, so a
6
+ // duplicate shows; the test holds the rules.
7
+ export const CONVERSATION_WORDS: readonly string[] = `
8
+ acorn alley almond alpaca amber anchor ant apple apron arena arrow aspen atlas atom attic aurora autumn avenue
9
+ badge badger bag bagel bakery ball bamboo banana banjo banner barn barrel basil basket bay beach bean bear
10
+ beaver bed bee beet beetle bell belt bench berry bike birch bird bison boat book boot bottle bowl box bread
11
+ breeze brick bridge brook broom brush bucket bud bun bunny burger bus bush butter button cabin cactus cafe cake
12
+ calf camel camera canal canary candle candy canoe canvas canyon car card carpet carrot cart cashew castle cat
13
+ cave cedar celery cellar cello cereal chair chalk cheese cherry chess chick chili cider city clam cliff clock
14
+ cloud clover coast coat cobra cocoa cod coffee coin comb comet comic cookie copper coral cork corn cosmos cougar
15
+ coyote crab crane crater crayon cream creek crepe crown cub cup curry daisy dawn deer delta desert desk dew
16
+ diary dice dish dog doll domino donkey donut door dove dream dress drum duck dune dusk eagle earth echo egg elk
17
+ ember emu eraser falcon fan farm fawn fence fern ferret field fig fish flag flame floor flour flower flute foal
18
+ fog forest fox frame frog frost fudge galaxy garage garden garlic gate gecko gem ginger glass globe glove glue
19
+ goat gold gong goose grape grass grove guava guitar gulf gull hail hammer harbor hare harp hat hawk hazel helmet
20
+ hen herb heron hill hippo honey hoodie hook horn horse hotel hut ice igloo iguana inn iris iron island ivy
21
+ jacket jade jaguar jam jar jelly jet jewel juice jungle kale kayak kettle kiosk kite kitten kiwi knot koala
22
+ ladder lagoon lake lamb lamp laser latte lava leaf lemon lens lilac lily lime lion lizard llama lobby lodge loft
23
+ lotus lynx magnet mango map maple marble market marsh mask meadow medal melody melon meteor milk mill mint
24
+ mirror mist mitten mocha monkey moon moose moss moth mouse movie muffin mug mule museum nail napkin nebula
25
+ nectar needle noodle noon novel oak oar oasis oat ocean olive onion opal orange orbit orca orchid otter oven owl
26
+ oyster paddle paint palace palm pan panda papaya paper parcel park parrot pasta pea peach peak peanut pear pearl
27
+ pebble pen pencil pepper petal phone photo piano pickle pie pier pigeon pillow pine pixel pizza plane planet
28
+ plate plaza plum pocket poem pollen pond pony pool poppy porch poster pot potato puddle puffin puma puppy purse
29
+ puzzle quartz quilt rabbit radio radish raft rain rake ramen ranch raven reed reef rhino ribbon rice ridge ring
30
+ river robin robot rock rocket roof rope rose ruby rug ruler saddle sage sail salad salmon salt sand sauce scarf
31
+ scone sea seal seed sesame shark sheep shelf shield ship shirt shoe shop shore shovel shrimp silver skate ski
32
+ sky sled sloth smile snail snake snow soap sock soda sofa soil song soup spark spider sponge spoon sprout squash
33
+ squid stamp star statue stone stool stork storm stream street studio sugar summer summit sun sunset sushi swan
34
+ syrup taco tape taxi tea teapot teddy temple tent ticket tide tiger toad toast toffee tofu tomato torch toucan
35
+ towel tower town toy train tram tray tree trophy trout truck tub tuba tulip tuna tundra tunnel turnip turtle
36
+ twig valley van vase vine violet violin wafer waffle wagon wallet walnut walrus wave whale wheel willow
37
+ wind winter wolf wood yak yard yogurt zebra zipper
38
+ `
39
+ .trim()
40
+ .split(/\s+/);
@@ -95,6 +95,16 @@ export const MODEL_ROLES = [
95
95
  icon: "sparkles",
96
96
  setup: "low",
97
97
  },
98
+ {
99
+ // Asked only when a spawned subagent nobody placed could take one of a runner's last free slots while this
100
+ // sandbox still has room for light work (runners/child-placement.ts roomContested); never on a quiet fleet.
101
+ id: "subagent-sizing",
102
+ label: "Subagent sizing",
103
+ blurb: "Whether a subagent's task reads as heavy (builds, tests) or light, when a runner's last free slots should go to the heavier work.",
104
+ kind: "helper",
105
+ icon: "server",
106
+ setup: "low",
107
+ },
98
108
  {
99
109
  id: "pipeline-fix",
100
110
  label: "Pipeline fixes",
@@ -98,6 +98,9 @@ export const FAILURE_CODES = {
98
98
  "model-unavailable": { kind: "model", course: "door", anotherModelClears: true },
99
99
  "context-window-too-small": { kind: "contextFull", course: "door", anotherModelClears: true },
100
100
  "model-helper-only": { kind: "model", course: "door", anotherModelClears: true },
101
+ // The endpoint the turn would run on is no longer connected. Not `repeats`: that names a wall no other model gets
102
+ // past (wayOut.ts), and this one any other model does.
103
+ "endpoint-gone": { kind: "model", course: "door", anotherModelClears: true },
101
104
  // The privacy shield refused an untrusted provider on a runtime it cannot read by content at all.
102
105
  "privacy-unshielded": { kind: "privacy", course: "door" },
103
106
  // The turn carries a tool list its runtime cannot keep.
@@ -13,7 +13,7 @@ test("every code the wire names has a row, and the table names no code the wire
13
13
  });
14
14
 
15
15
  // The door course names the codes refused before the model saw a word.
16
- test("the codes turned away at the door are exactly the nineteen refused before the model saw a word", () => {
16
+ test("the codes turned away at the door are exactly the twenty refused before the model saw a word", () => {
17
17
  const door = codesWhere((code) => failureCourseOf(code) === "door");
18
18
  expect(door).toEqual(
19
19
  [
@@ -23,6 +23,7 @@ test("the codes turned away at the door are exactly the nineteen refused before
23
23
  "unknown-command",
24
24
  "context-window-too-small",
25
25
  "model-helper-only",
26
+ "endpoint-gone",
26
27
  "privacy-unshielded",
27
28
  "tools-unenforced",
28
29
  "agent-domain-refused",
@@ -48,6 +49,7 @@ test("another model clears exactly the refusals about the model, its trial or it
48
49
  "account-not-allowed",
49
50
  "context-window-too-small",
50
51
  "model-helper-only",
52
+ "endpoint-gone",
51
53
  "trial-unavailable",
52
54
  "trial-model-unavailable",
53
55
  "trial-exhausted",
@@ -95,6 +97,7 @@ test("every code keeps the kind the board named it by", () => {
95
97
  "model-unavailable": "model",
96
98
  "trial-model-unavailable": "model",
97
99
  "model-helper-only": "model",
100
+ "endpoint-gone": "model",
98
101
  "context-window-too-small": "contextFull",
99
102
  "context-overflow": "contextFull",
100
103
  "engine-version-floor": "update",
@@ -0,0 +1,22 @@
1
+ import { runnerLinkReading, RunnerLinkReadingSchema } from "./runner-protocol.js";
2
+
3
+ // What the machine's keeper reads to tell a runner whose link is down from one that is up (runner-protocol.ts).
4
+
5
+ const PARENT = "https://sandbox-a4ba63bf2aa5.sbx.intentic.dev";
6
+
7
+ test("an open link says so and nothing about an outage it is not in", () => {
8
+ const reading = runnerLinkReading({ state: () => "open", outage: () => undefined }, PARENT, false, 0, 1_000);
9
+ expect(reading).toEqual({ at: 1_000, parent: PARENT, state: "open", working: 0 });
10
+ expect(RunnerLinkReadingSchema.parse(reading)).toEqual(reading);
11
+ });
12
+
13
+ test("a failing link says since when, how many tries, and the work a restart would cut", () => {
14
+ const reading = runnerLinkReading({ state: () => "connecting", outage: () => ({ failures: 7, since: 500 }) }, PARENT, false, 2, 1_000);
15
+ expect(reading).toEqual({ at: 1_000, parent: PARENT, state: "connecting", since: 500, failures: 7, working: 2 });
16
+ });
17
+
18
+ test("a refused enrollment is said, since only re-pairing brings that runner back", () => {
19
+ const reading = runnerLinkReading({ state: () => "closed", outage: () => undefined }, PARENT, true, 0, 1_000);
20
+ expect(reading.revoked).toBe(true);
21
+ expect(reading.state).toBe("closed");
22
+ });
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { NeedsActionSchema } from "../../policy/needs-action.js";
3
+ import type { PeerLink } from "../peer-dial.js";
3
4
 
4
5
  // The runner link's edges: the /system/runners/connect handshake, boot env, and turn placement (procedures live in
5
6
  // contracts/runner.contract.ts). A runner is a sandbox image in runner mode, no browser owner or tunnel, that dials its
@@ -42,6 +43,49 @@ export const RUNNER_HEARTBEAT_MS = 30_000;
42
43
 
43
44
  export const runnerConnectUrl = (parentUrl: string): string => `${parentUrl.replace(/^http/, "ws").replace(/\/$/, "")}/system/runners/connect`;
44
45
 
46
+ /* WHAT A RUNNER SAYS OF ITS OWN LINK, FOR THE MACHINE IT RUNS ON (2026-11-09). A runner can be up, its daemon answering,
47
+ and still be no use to anyone: its socket to the parent is the whole point of it, and only the runner can see it. It
48
+ writes this file inside its container (never on /health, which answers the public address) on every change of the
49
+ link and once a minute, and the machine agent's keeper reads it through `docker exec` to bring back a runner whose
50
+ link stays down while its parent answers that machine (machine: device/sandbox-rounds/runner-keeper.ts). */
51
+ export const RUNNER_LINK_PATH = "/run/intentic/runner-link.json";
52
+
53
+ export const RunnerLinkReadingSchema = z.object({
54
+ // When this was written: a reading that stops moving is a daemon that stopped writing it.
55
+ at: z.number(),
56
+ // The parent's public address, which the keeper asks from the machine itself before it blames the runner.
57
+ parent: z.string(),
58
+ state: z.enum(["open", "connecting", "closed"]),
59
+ // The first failure of the outage the link is in, absent while it is open or before its first attempt has failed.
60
+ since: z.number().optional(),
61
+ failures: z.number().optional(),
62
+ // The parent refused this runner's enrollment (close 1008): its loop has stopped, and only re-pairing brings it back.
63
+ revoked: z.boolean().optional(),
64
+ // Work a restart would cut (bootstrap/working-now.ts, purpose "restart"): a held turn carries on with its parent away.
65
+ working: z.number(),
66
+ });
67
+ export type RunnerLinkReading = z.infer<typeof RunnerLinkReadingSchema>;
68
+
69
+ // The reading the machine's keeper judges the link by (RUNNER_LINK_PATH above). Pure.
70
+ export const runnerLinkReading = (
71
+ link: Pick<PeerLink, "state" | "outage">,
72
+ parent: string,
73
+ revoked: boolean,
74
+ working: number,
75
+ now: number,
76
+ ): RunnerLinkReading => {
77
+ const outage = link.outage();
78
+ const reading: RunnerLinkReading = { at: now, parent, state: link.state(), working };
79
+ if (outage !== undefined) {
80
+ reading.since = outage.since;
81
+ reading.failures = outage.failures;
82
+ }
83
+ if (revoked) {
84
+ reading.revoked = true;
85
+ }
86
+ return reading;
87
+ };
88
+
45
89
  // Where a runner redeems its pairing for a durable token, once, over plain HTTPS.
46
90
  export const runnerEnrollUrl = (parentUrl: string): string => `${parentUrl.replace(/\/$/, "")}/system/runners/enroll`;
47
91
 
@@ -65,7 +65,7 @@ const ladder = (delay = 1_000) => {
65
65
  return rungs;
66
66
  };
67
67
 
68
- const dialling = (delay?: number) => {
68
+ const dialling = (delay?: number, longOutageMs?: number) => {
69
69
  const sockets: FakeSocket[] = [];
70
70
  const attached: FakeSocket[] = [];
71
71
  const said: string[] = [];
@@ -81,6 +81,7 @@ const dialling = (delay?: number) => {
81
81
  attach: (socket) => void attached.push(socket),
82
82
  backoff,
83
83
  silenceMs: SILENCE_MS,
84
+ longOutageMs,
84
85
  log: (message) => void said.push(message),
85
86
  revoked,
86
87
  });
@@ -273,6 +274,34 @@ test.each([
273
274
  // The ladder caps at 30s and would stay there forever. Right for the first minutes, absurd after the first week: a
274
275
  // link to a sandbox that no longer exists spent 2,880 attempts a day saying so. It is never given up — a laptop closed
275
276
  // for a fortnight has to find its sandboxes again — it just stops asking every half minute.
277
+ // A runner exists for its parent alone: the parent coming back (a restart, an update, a wake) is when it is wanted, so
278
+ // its long outage rests a minute between tries rather than a quarter of an hour (runners/runner-link.ts).
279
+ test("a door can rest a long outage for less than the default, and still rests past the ladder", async () => {
280
+ jest.useFakeTimers();
281
+ try {
282
+ const RUNG_MS = 30_000;
283
+ const REST_MS = 60_000;
284
+ const { link, sockets } = dialling(RUNG_MS, REST_MS);
285
+ for (let attempt = 1; attempt <= LONG_OUTAGE_ATTEMPTS; attempt += 1) {
286
+ // one drop per attempt is serial by definition
287
+ await waitFor(() => expect(sockets).toHaveLength(attempt));
288
+ sockets.at(-1)?.drops(1006);
289
+ if (attempt < LONG_OUTAGE_ATTEMPTS) {
290
+ // ditto
291
+ await advanceTimersByTimeAsync(RUNG_MS);
292
+ }
293
+ }
294
+ await advanceTimersByTimeAsync(REST_MS + RUNG_MS - 1);
295
+ expect(sockets).toHaveLength(LONG_OUTAGE_ATTEMPTS);
296
+ await advanceTimersByTimeAsync(1);
297
+ await waitFor(() => expect(sockets).toHaveLength(LONG_OUTAGE_ATTEMPTS + 1));
298
+ link.stop();
299
+ await link.done;
300
+ } finally {
301
+ jest.useRealTimers();
302
+ }
303
+ });
304
+
276
305
  test("a link nobody has answered in a long time rests between tries, and is never given up", async () => {
277
306
  jest.useFakeTimers();
278
307
  try {
@@ -63,6 +63,9 @@ export interface PeerDialSpec<S extends SocketLike> {
63
63
  readonly backoff: { readonly next: (heldMs: number) => number; readonly reset: () => void };
64
64
  /* How long this socket may hear nothing before the link is presumed dead: `peerLinkSilenceMs` of the heartbeat the door's own hub pings on. */
65
65
  readonly silenceMs: number;
66
+ /* The rest a long outage takes between tries (LONG_OUTAGE_MS when absent). A door whose far end is the only reason it
67
+ exists, a runner and its parent, rests far less: the parent coming back is the moment it is wanted. */
68
+ readonly longOutageMs?: number | undefined;
66
69
  readonly log: (message: string) => void;
67
70
  // Sandbox refused the enrollment (1008); the loop has already stopped, this is where the peer says so.
68
71
  readonly revoked: () => void;
@@ -197,7 +200,7 @@ export const dialPeer = <S extends SocketLike>(spec: PeerDialSpec<S>): PeerLink
197
200
  openedAt = undefined;
198
201
  // The rest is added to the ladder's draw rather than replacing it: a flat fifteen minutes would bring back in
199
202
  // lockstep every link that entered the long outage together.
200
- const delay = outage.fail() >= LONG_OUTAGE_ATTEMPTS ? LONG_OUTAGE_MS + rung : rung;
203
+ const delay = outage.fail() >= LONG_OUTAGE_ATTEMPTS ? (spec.longOutageMs ?? LONG_OUTAGE_MS) + rung : rung;
201
204
  outage.complain(said, delay);
202
205
  ladder.wait(delay, open);
203
206
  };
@@ -104,6 +104,10 @@ export const KeyringStateSchema = z.object({
104
104
  pendingInbox: z.number().int().nonnegative().describe("Values sent to be kept that wait for the next unlock."),
105
105
  pendingCaptures: z.number().int().nonnegative().optional().describe("Credentials seen in use while locked, kept sealed until the next unlock. Absent from a keyring older than 2026-10-19."),
106
106
  remember: KeyringRememberSchema.optional().describe("Which sources the person let the keyring remember passwords from, so a collector knows whether to send one. Absent before setup and from an older keyring."),
107
+ // The fields below are absent before setup and from a keyring older than 2026-11-09.
108
+ helloAddable: z.boolean().optional().describe("Windows Hello signs here but the vault was set up without it, so it asks for the recovery key: `add-hello` turns Hello on."),
109
+ masterPassword: z.boolean().optional().describe("The person set a master password, asked for instead of the recovery key where Hello or polkit cannot answer."),
110
+ recentlyDeleted: z.number().int().nonnegative().optional().describe("Removed entries kept in Recently deleted, which `undo-remove` puts back."),
107
111
  });
108
112
  export type KeyringState = z.infer<typeof KeyringStateSchema>;
109
113
 
@@ -6,7 +6,9 @@ import { AgentHarnessSchema, AgentProviderSchema } from "./agent.js";
6
6
  // sandbox hands a runner on one of the owner's machines instead of running it itself.
7
7
 
8
8
  // Whether a runner can take a line right now, asked before the tree is snapshotted, so a machine that is asleep costs
9
- // nothing. `name` is the machine the runner sits on, the word the owner picked it by.
9
+ // nothing. `name` is the machine the runner sits on, the word the owner picked it by. Asked for OFFLOAD_ANY_RUNNER, it
10
+ // answers with the runner it picked, or not ready with no `why` when this sandbox has room, which runs the line here
11
+ // in silence.
10
12
  export const OffloadTargetSchema = z.object({
11
13
  runner: z.string().min(1),
12
14
  name: z.string().min(1),
@@ -16,6 +18,11 @@ export const OffloadTargetSchema = z.object({
16
18
  });
17
19
  export type OffloadTarget = z.infer<typeof OffloadTargetSchema>;
18
20
 
21
+ // What settings `offload.commands` names instead of one runner: whichever has the most room at the moment the command
22
+ // starts, and only while this sandbox is busy (runners/fleet-advice.ts `roomierRunner`). While this sandbox is calm the
23
+ // command runs here without a word. Reserved: no runner is ever enrolled under it.
24
+ export const OFFLOAD_ANY_RUNNER = "auto";
25
+
19
26
  export const OffloadRunSchema = RunnerCommandSchema.extend({ runner: z.string().min(1) });
20
27
  export type OffloadRun = z.infer<typeof OffloadRunSchema>;
21
28
 
@@ -118,3 +125,8 @@ export const FleetAdviceSchema = z.object({
118
125
  suggestion: z.object({ runner: z.string().min(1), name: z.string().min(1) }).optional(),
119
126
  });
120
127
  export type FleetAdvice = z.infer<typeof FleetAdviceSchema>;
128
+
129
+ // While this sandbox is full and at least one runner is calm, the machines with room by the word the owner knows each by:
130
+ // what a turn is told so that work it can send elsewhere goes there. Absent otherwise.
131
+ export const FleetPressureSchema = z.object({ roomy: z.array(z.string().min(1)).min(1) });
132
+ export type FleetPressure = z.infer<typeof FleetPressureSchema>;
@@ -35,6 +35,13 @@ export const RelayChannelSchema = z.object({
35
35
  ),
36
36
  });
37
37
  export type RelayChannel = z.infer<typeof RelayChannelSchema>;
38
+ // The relay's own word that a relay channel will never deliver again: the device is gone, the relay has no row for it, or
39
+ // its secret was rotated. It rides as the `data` of the relay's refusal (the platform's push-relay.routes.ts), and the
40
+ // daemon forgets a channel only on it (push/senders/relay.ts). (2026-11-09) A status alone used to be enough, and a 403
41
+ // or 404 is also what a proxy in front of a platform that is down answers (an HTML page, Cloudflare's), so an outage
42
+ // silently unregistered every phone.
43
+ export const RELAY_CHANNEL_GONE = "gone";
44
+ export const RelayGoneSchema = z.object({ data: z.object({ channel: z.literal(RELAY_CHANNEL_GONE) }) });
38
45
  export const PushChannelSchema = z.discriminatedUnion("kind", [WebPushChannelSchema, RelayChannelSchema]);
39
46
  export type PushChannel = z.infer<typeof PushChannelSchema>;
40
47
  // The one identity every push route uses (subscribe, unsubscribe, config); derived from the channel's own shape so the
@@ -547,7 +547,8 @@ export const SandboxSettingsSchema = z.object({
547
547
  "Whether each workspace repo keeps up with the remote branch it tracks. Every couple of minutes it is fetched, and what arrived is brought into the main tree: a fast-forward when you have no commits of your own, else a merge commit. Only while it is quiet (no turn working in the main tree, no merge or rebase of yours open), and never half-way: a conflict, or an uncommitted file in the way, leaves the repo exactly as it was until the next try. Following never pushes; the back-up rule does that, when you switch it on. Off, nothing is fetched.",
548
548
  ),
549
549
  // Where heavy work runs: a runner (the same image, on one of the owner's machines) instead of this sandbox. Keyed by
550
- // the heavy-command rule an agent's command matched (workload/heavy-commands.ts), each naming a runner id. A
550
+ // the heavy-command rule an agent's command matched (workload/heavy-commands.ts), each naming a runner id, or "auto"
551
+ // (OFFLOAD_ANY_RUNNER) for whichever runner has the most room while this sandbox is busy. A
551
552
  // runner that is offline, outdated or full hands the work back here, which the command's output says. Never pushed
552
553
  // to a runner itself (definition/definition.ts), which must not pass work on again.
553
554
  // `sessions`: what a new conversation is told when this machine is busy and a runner has room
@@ -560,7 +561,7 @@ export const SandboxSettingsSchema = z.object({
560
561
  })
561
562
  .default({ commands: {}, sessions: "suggest" })
562
563
  .describe(
563
- "Which work runs on a runner on one of your machines instead of this sandbox. `commands`: agents' heavy commands by the kind the heavy-command rules sort them into (tests, typechecks, verify…); the code travels as it stands, uncommitted work included, the output streams back, and any file the command changed comes back with it, while a machine that is offline, outdated or busy hands the work back to this sandbox, and the output says so. `sessions`: what happens to a new conversation while this machine is busy and one of your runners has room: `suggest` offers that machine above the composer, `auto` starts it there unless you keep it here, `off` says nothing.",
564
+ "Which work runs on a runner on one of your machines instead of this sandbox. `commands`: agents' heavy commands by the kind the heavy-command rules sort them into (tests, typechecks, verify…), each sent to one runner, or to `auto`: whichever runner has the most room at the moment the command starts, and only while this sandbox is busy (while it is calm the command runs here as usual). The code travels as it stands, uncommitted work included, the output streams back, and any file the command changed comes back with it, while a machine that is offline, outdated or busy hands the work back to this sandbox, and the output says so. `sessions`: what happens to a new conversation while this machine is busy and one of your runners has room: `suggest` offers that machine above the composer, `auto` starts it there unless you keep it here, `off` says nothing.",
564
565
  ),
565
566
  // A person answering a need is exactly the moment they want the work to go on (docs/architecture/needs.md), unlike a
566
567
  // restart nobody watched, so this one is on to begin with.
@@ -217,6 +217,31 @@ export const DaemonSessionSchema = z.object({
217
217
  });
218
218
  export type DaemonSession = z.infer<typeof DaemonSessionSchema>;
219
219
 
220
+ // (2026-11-09) The owner's name for the sandbox and its switcher logo, as the sandbox last heard them from the platform,
221
+ // which holds them. The sandbox keeps a copy so a client that reaches it while the platform is down still shows both.
222
+ // Its own routes (system.presentation, system.presentationRefresh) rather than fields on /info: /info is read often,
223
+ // and a logo is a data URL of up to 150 KB.
224
+ export const SandboxPresentationSchema = z.object({
225
+ name: z.string().describe("What the owner calls this sandbox, as the switcher shows it."),
226
+ image: z.string().nullable().describe("Its logo, as an image data URL. Null for none: the switcher draws the name's monogram instead."),
227
+ at: z.string().describe("When the sandbox heard this copy from the platform (ISO)."),
228
+ });
229
+ export type SandboxPresentation = z.infer<typeof SandboxPresentationSchema>;
230
+ export const PresentationReadSchema = z.object({
231
+ presentation: SandboxPresentationSchema.nullable().describe(
232
+ "The copy the sandbox holds. Null until it has heard one, which takes reaching the platform once.",
233
+ ),
234
+ });
235
+ export type PresentationRead = z.infer<typeof PresentationReadSchema>;
236
+ export const PresentationRefreshSchema = PresentationReadSchema.extend({
237
+ refreshed: z
238
+ .boolean()
239
+ .describe(
240
+ "Whether the platform answered. False means it could not be reached or refused, and `presentation` is the copy the sandbox already held, which a failed ask never removes.",
241
+ ),
242
+ });
243
+ export type PresentationRefresh = z.infer<typeof PresentationRefreshSchema>;
244
+
220
245
  // Passkeys registered with one sandbox, and the owner's rule that a passkey is the only proof that opens it. The
221
246
  // daemon is the WebAuthn relying party; these are the shapes its /system/passkeys routes and the 428 step-up carry.
222
247