@intentic/sandbox-contract 1.420.0 → 1.422.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 (108) hide show
  1. package/dist/contracts/ci.contract.d.ts +30 -0
  2. package/dist/contracts/ci.contract.d.ts.map +1 -1
  3. package/dist/contracts/ci.contract.js +10 -1
  4. package/dist/contracts/ci.contract.js.map +1 -1
  5. package/dist/contracts/device.contract.d.ts +46 -0
  6. package/dist/contracts/device.contract.d.ts.map +1 -1
  7. package/dist/contracts/device.contract.js +2 -0
  8. package/dist/contracts/device.contract.js.map +1 -1
  9. package/dist/contracts/offload.contract.d.ts +51 -0
  10. package/dist/contracts/offload.contract.d.ts.map +1 -1
  11. package/dist/contracts/offload.contract.js +3 -3
  12. package/dist/contracts/offload.contract.js.map +1 -1
  13. package/dist/contracts/runner.contract.d.ts +308 -246
  14. package/dist/contracts/runner.contract.d.ts.map +1 -1
  15. package/dist/contracts/settings.contract.d.ts +2 -0
  16. package/dist/contracts/settings.contract.d.ts.map +1 -1
  17. package/dist/events/agent-events.d.ts +5 -0
  18. package/dist/events/agent-events.d.ts.map +1 -1
  19. package/dist/events/agent-events.js +2 -1
  20. package/dist/events/agent-events.js.map +1 -1
  21. package/dist/events/requests.js +1 -1
  22. package/dist/events/requests.js.map +1 -1
  23. package/dist/events/sandbox-notice.d.ts +12 -0
  24. package/dist/events/sandbox-notice.d.ts.map +1 -1
  25. package/dist/events/sandbox-notice.js +5 -1
  26. package/dist/events/sandbox-notice.js.map +1 -1
  27. package/dist/models/account-moves.d.ts.map +1 -1
  28. package/dist/models/account-moves.js +10 -2
  29. package/dist/models/account-moves.js.map +1 -1
  30. package/dist/models/plan-pools.d.ts +3 -1
  31. package/dist/models/plan-pools.d.ts.map +1 -1
  32. package/dist/models/plan-pools.js +26 -3
  33. package/dist/models/plan-pools.js.map +1 -1
  34. package/dist/protocol/doors/runner-protocol.d.ts +42 -0
  35. package/dist/protocol/doors/runner-protocol.d.ts.map +1 -1
  36. package/dist/protocol/doors/runner-protocol.js +23 -0
  37. package/dist/protocol/doors/runner-protocol.js.map +1 -1
  38. package/dist/protocol/raw/raw-json-routes.d.ts +4 -0
  39. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  40. package/dist/protocol/raw/raw-routes.d.ts +8 -0
  41. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  42. package/dist/protocol/raw/raw-routes.js +2 -0
  43. package/dist/protocol/raw/raw-routes.js.map +1 -1
  44. package/dist/schemas/ci.d.ts +69 -0
  45. package/dist/schemas/ci.d.ts.map +1 -1
  46. package/dist/schemas/ci.js +30 -0
  47. package/dist/schemas/ci.js.map +1 -1
  48. package/dist/schemas/device-files.d.ts +71 -0
  49. package/dist/schemas/device-files.d.ts.map +1 -0
  50. package/dist/schemas/device-files.js +53 -0
  51. package/dist/schemas/device-files.js.map +1 -0
  52. package/dist/schemas/devices.d.ts.map +1 -1
  53. package/dist/schemas/devices.js.map +1 -1
  54. package/dist/schemas/hosts.d.ts +3 -0
  55. package/dist/schemas/hosts.d.ts.map +1 -1
  56. package/dist/schemas/hosts.js +3 -0
  57. package/dist/schemas/hosts.js.map +1 -1
  58. package/dist/schemas/night-hours.d.ts +5 -1
  59. package/dist/schemas/night-hours.d.ts.map +1 -1
  60. package/dist/schemas/night-hours.js +24 -2
  61. package/dist/schemas/night-hours.js.map +1 -1
  62. package/dist/schemas/offload.d.ts +40 -0
  63. package/dist/schemas/offload.d.ts.map +1 -1
  64. package/dist/schemas/offload.js +21 -0
  65. package/dist/schemas/offload.js.map +1 -1
  66. package/dist/schemas/providers/plan-limits.d.ts +1 -0
  67. package/dist/schemas/providers/plan-limits.d.ts.map +1 -1
  68. package/dist/schemas/providers/plan-limits.js +5 -1
  69. package/dist/schemas/providers/plan-limits.js.map +1 -1
  70. package/dist/schemas/settings.d.ts +2 -0
  71. package/dist/schemas/settings.d.ts.map +1 -1
  72. package/dist/schemas/settings.js +2 -2
  73. package/dist/schemas/settings.js.map +1 -1
  74. package/dist/state/definition.d.ts +4 -0
  75. package/dist/state/definition.d.ts.map +1 -1
  76. package/dist/text/land-rows.d.ts +7 -4
  77. package/dist/text/land-rows.d.ts.map +1 -1
  78. package/dist/text/land-rows.js +8 -4
  79. package/dist/text/land-rows.js.map +1 -1
  80. package/dist/text/transcript-fold.d.ts.map +1 -1
  81. package/dist/text/transcript-fold.js +6 -4
  82. package/dist/text/transcript-fold.js.map +1 -1
  83. package/package.json +5 -5
  84. package/src/contracts/ci.contract.ts +13 -0
  85. package/src/contracts/device.contract.ts +5 -0
  86. package/src/contracts/offload.contract.ts +3 -2
  87. package/src/events/agent-events.ts +3 -1
  88. package/src/events/requests.ts +1 -1
  89. package/src/events/sandbox-notice.ts +13 -2
  90. package/src/models/account-moves.test.ts +9 -1
  91. package/src/models/account-moves.ts +22 -7
  92. package/src/models/plan-pools.test.ts +57 -20
  93. package/src/models/plan-pools.ts +48 -8
  94. package/src/protocol/doors/runner-protocol.ts +42 -2
  95. package/src/protocol/raw/raw-routes.ts +5 -0
  96. package/src/schemas/automations.ts +3 -3
  97. package/src/schemas/ci.ts +42 -0
  98. package/src/schemas/device-files.ts +90 -0
  99. package/src/schemas/devices.ts +5 -4
  100. package/src/schemas/hosts.ts +15 -3
  101. package/src/schemas/night-hours.test.ts +32 -1
  102. package/src/schemas/night-hours.ts +46 -3
  103. package/src/schemas/offload.ts +39 -2
  104. package/src/schemas/providers/plan-limits.ts +7 -1
  105. package/src/schemas/settings.ts +2 -2
  106. package/src/text/land-rows.ts +18 -6
  107. package/src/text/transcript-fold.test.ts +17 -0
  108. package/src/text/transcript-fold.ts +8 -5
@@ -4,6 +4,7 @@ import {
4
4
  CiFixResponseSchema,
5
5
  CiForgetParamSchema,
6
6
  CiJobsResponseSchema,
7
+ CiMainResponseSchema,
7
8
  CiRunParamSchema,
8
9
  CiRunsResponseSchema,
9
10
  } from "../schemas/ci.js";
@@ -24,6 +25,18 @@ export const ciContract = {
24
25
  "What the forges are reporting for every workspace repo that has a remote, served from a cache and filled in on demand. Repos whose notifications are not wired up say so.",
25
26
  })
26
27
  .output(CiRunsResponseSchema),
28
+ // The agent token reaches it (`agents ci`): what an agent meeting a failure asks before blaming itself or re-running
29
+ // main. Read from the CI store alone, never the forge, so any number of agents asking costs no API call.
30
+ main: procedure
31
+ .route({
32
+ method: "GET",
33
+ path: "/ci/main",
34
+ summary: "What main's CI is known to fail on now",
35
+ description:
36
+ "Each job failing on a workspace repository's main line, with the run and commit it last failed in, when the daemon read it, and the failing tests and errors its log named. Answered from the runs already heard, without asking the forge; a main line nothing is known of says so.",
37
+ })
38
+ .meta({ agent: true })
39
+ .output(CiMainResponseSchema),
27
40
  rerun: procedure
28
41
  .route({
29
42
  method: "POST",
@@ -8,6 +8,7 @@ import { LoopbackCatchEventSchema, LoopbackCatchSchema } from "../schemas/loopba
8
8
  import { OkSchema } from "../schemas/shared.js";
9
9
  import { ProjectDeliveryResultSchema, ProjectDeliverySchema } from "../schemas/project-delivery.js";
10
10
  import { DialLoopbackSchema, StageArtifactResultSchema, StageArtifactSchema } from "../schemas/device-artifacts.js";
11
+ import { CopyFileResultSchema, CopyFileSchema } from "../schemas/device-files.js";
11
12
  import {
12
13
  KeyringCaptureItemSchema,
13
14
  KeyringCaptureResultSchema,
@@ -66,6 +67,10 @@ export const deviceContract = {
66
67
  // Only the daemon calls it, for the agent's `devices push`, and only on an agent advertising `programs`; the machine
67
68
  // refuses every op unless "Run programs this sandbox sends" is on.
68
69
  stageArtifact: oc.input(StageArtifactSchema).output(StageArtifactResultSchema),
70
+ // A file or a folder copied to or from a path the agent names (schemas/device-files.ts), in chunks. Only the daemon
71
+ // calls it, for the agent's `devices copy`, and only on an agent advertising `file-copy`; the machine holds every op
72
+ // to its folders, and a copy onto it to "Create and change files" as well, as its file tools are.
73
+ copyFile: oc.input(CopyFileSchema).output(CopyFileResultSchema),
69
74
  // A connection to the sandbox side of a `devices reach` tunnel: the machine dials its own 127.0.0.1:<port> and, once
70
75
  // that answered, opens a WebSocket back to /system/hosts/tunnel with the ticket. Answers once the local port took
71
76
  // the connection, or throws (nothing listening there, the switch is off). Advertised with `programs`; the machine
@@ -8,6 +8,7 @@ import {
8
8
  OffloadKindSchema,
9
9
  OffloadRecordSchema,
10
10
  OffloadRunSchema,
11
+ OffloadTargetInputSchema,
11
12
  OffloadTargetSchema,
12
13
  } from "../schemas/offload.js";
13
14
  import { OkSchema } from "../schemas/shared.js";
@@ -24,9 +25,9 @@ export const offloadContract = {
24
25
  path: "/offload/runners/{runner}",
25
26
  summary: "Whether a runner can take a heavy command",
26
27
  description:
27
- "Answers whether the runner a kind of heavy work is sent to is connected and able to run it, before anything is copied to it. When it is not, the command runs in this sandbox and says why.",
28
+ "Answers whether the runner a kind of heavy work is sent to is connected and able to run it, before anything is copied to it. When it is not, the command runs in this sandbox and says why. Naming what the command needs (memory, a GPU) rules out a machine short of it; for \"auto\" it picks the machine with room that fits.",
28
29
  })
29
- .input(z.object({ runner: z.string().min(1) }))
30
+ .input(OffloadTargetInputSchema)
30
31
  .output(OffloadTargetSchema),
31
32
  run: offloadRoute
32
33
  .route({
@@ -18,6 +18,7 @@ import { TranscriptPatchSchema, TranscriptRowSchema, TurnNoteSchema } from "./tr
18
18
  import { TranscriptEditorContextSchema } from "./prompt-origins.js";
19
19
  import { ReviewFindingsSchema } from "./review.js";
20
20
  import { agentNoticeEvent, agentStatusEvent } from "./agent-ui.js";
21
+ import { WorktreeSyncCauseSchema } from "./sandbox-notice.js";
21
22
 
22
23
  // Every frame an agent turn streams, as one `kind`-discriminated union: turn facts (session, standing, cost) and the
23
24
  // attach stream a window joins through. One closed vocabulary, kept in one file.
@@ -133,7 +134,8 @@ export const AgentEventSchema = z.discriminatedUnion("kind", [
133
134
  branch: z.string(),
134
135
  base: z.string(),
135
136
  unenforced: z.boolean().optional(),
136
- sync: z.object({ commits: z.number(), blocked: z.array(z.string()) }).optional(),
137
+ // `cause`: when the rebase ran (sandbox-notice.ts WorktreeSyncCauseSchema); absent on a frame from before it was said.
138
+ sync: z.object({ commits: z.number(), blocked: z.array(z.string()), cause: WorktreeSyncCauseSchema.optional() }).optional(),
137
139
  // The runner this turn executes on, when the conversation is placed remotely; absent means this sandbox.
138
140
  remote: z.string().optional(),
139
141
  }),
@@ -68,7 +68,7 @@ export const ChildRunSchema = z.object({
68
68
  account: z
69
69
  .string()
70
70
  .optional()
71
- .describe("Which of that provider's connected accounts pays for it. Absent is whichever has the most room when it starts."),
71
+ .describe("Which of that provider's connected accounts pays for it. Absent is the sandbox's pick when it starts: the one whose allowance renews first among those not nearly out, then the most room."),
72
72
  effort: z.string().optional().describe("How hard it thinks, where the model offers a choice. Absent is the model's own default."),
73
73
  thinking: z.boolean().optional().describe("Whether it reasons before it answers, where the model offers the choice."),
74
74
  fast: z.boolean().optional().describe("Whether it asks for the faster rate, at the higher price."),
@@ -1,5 +1,12 @@
1
1
  import { z } from "zod";
2
2
 
3
+ // When the daemon rebased a conversation's branch onto the main line: as its turn opened (`turn-open`), after the person
4
+ // answered a card it waited on (`answer`), or mid-turn between two of the agent's tool calls (`between-tools`), which the
5
+ // agent never waited for. The shinobi-society audit (2026-11-17): a mid-turn catch-up said "while this agent waited", and
6
+ // the agent hunted for what had reset its fix.
7
+ export const WorktreeSyncCauseSchema = z.enum(["turn-open", "answer", "between-tools"]);
8
+ export type WorktreeSyncCause = z.infer<typeof WorktreeSyncCauseSchema>;
9
+
3
10
  // The sandbox's own notice rows (a land, a hold, a renewal, a stop), as a code and the facts they were worded from. The
4
11
  // row's `text` stays the English sentence, which older apps, stored transcripts and agents reading their own history
5
12
  // go on reading; `noticeCode` beside it is what lets an app say the same thing in the reader's language and words.
@@ -64,8 +71,12 @@ export const SandboxNoticeSchema = z.discriminatedUnion("code", [
64
71
  // The conversation's view of the workspace failed to come up, and `layers` of its dependency layers were set aside
65
72
  // for fresh ones before the turn went on (agent-events.ts workspace_repaired).
66
73
  z.object({ code: z.literal("workspaceRepaired"), params: z.object({ layers: count }) }),
67
- // The branch was rebased onto `commits` new commits, and/or could not be in the repos named in `blocked`.
68
- z.object({ code: z.literal("synced"), params: z.object({ commits: count, blocked: z.string().optional() }) }),
74
+ // The branch was rebased onto `commits` new commits, and/or could not be in the repos named in `blocked`; `cause` says
75
+ // when (absent reads as a turn's opening, as before it was said), `base` the commit it now sits on.
76
+ z.object({
77
+ code: z.literal("synced"),
78
+ params: z.object({ commits: count, blocked: z.string().optional(), cause: WorktreeSyncCauseSchema.optional(), base: z.string().optional() }),
79
+ }),
69
80
  z.object({ code: z.literal("intoParent") }),
70
81
  z.object({ code: z.literal("intoParentClash"), params: z.object({ files: count }) }),
71
82
  z.object({ code: z.literal("landHeld") }),
@@ -8,7 +8,15 @@ const SEATLESS: AccountState = { kind: "blocked", fix: "admin", reason: "no seat
8
8
 
9
9
  test("proven room wins wherever the provider publishes an allowance, and nothing else does", () => {
10
10
  expect(moveDestination([entry("unread", UNREAD), entry("low", { kind: "ready", room: 5 }), entry("high", { kind: "ready", room: 60 })], true)?.id).toBe("high");
11
- expect(moveDestination([entry("unread", UNREAD), entry("spent", SPENT)], true)).toBeUndefined();
11
+ expect(moveDestination([entry("unread", UNREAD), entry("line", { kind: "ready", room: 0 })], true)).toBeUndefined();
12
+ });
13
+
14
+ // The shinobi-society audit (2026-11-17): a Claude account refused for its seat, the other's reading aged out.
15
+ test("where every account with a reading is refused, an unread one qualifies even where the provider publishes an allowance", () => {
16
+ expect(moveDestination([entry("unread", UNREAD), entry("spent", SPENT)], true)?.id).toBe("unread");
17
+ expect(moveDestination([entry("seatless", SEATLESS), entry("flapping", UNREAD, true), entry("steady", UNREAD)], true)?.id).toBe("steady");
18
+ expect(moveDestination([entry("unread", UNREAD)], true)?.id).toBe("unread");
19
+ expect(moveDestination([], true)).toBeUndefined();
12
20
  });
13
21
 
14
22
  // The 2026-10-29 sandbox: a Devin account refused for its weekly quota, two connected beside it that nothing had refused.
@@ -1,5 +1,5 @@
1
1
  import type { AccountState } from "../schemas/providers/plan-limits.js";
2
- import { preferredAccount, roomiestAccount } from "./plan-pools.js";
2
+ import { bestWithRoom, preferredAccount } from "./plan-pools.js";
3
3
 
4
4
  /* WHERE A TURN GOES OFF AN ACCOUNT THAT CANNOT SERVE IT, for every provider whose accounts a turn can name. Read by the
5
5
  daemon's limit move (sibling-account.ts) and its move off a blocked account (blocked-account.ts), and by the editor's
@@ -10,17 +10,32 @@ import { preferredAccount, roomiestAccount } from "./plan-pools.js";
10
10
  sign-in) never proves room, so there a move may also land on an account nothing has refused, since a refusal is the
11
11
  only thing that marks one spent. Before this, a Devin turn refused on a spent account was held for a press, with two
12
12
  accounts beside it that nothing had refused (2026-10-29). The turn cannot bounce back and forth: by the time the next
13
- move is read, the account it just left is on file as spent. */
13
+ move is read, the account it just left is on file as spent.
14
+
15
+ Where every account with a reading is refused (spent or blocked), an unread one qualifies on a provider that does
16
+ publish an allowance too: a reading that went stale is no refusal. 2026-11-17, the shinobi-society audit: a Claude
17
+ account whose organisation turned Claude Code off left its conversation dead for hours, with a second account beside
18
+ it whose reading had simply aged out. An account at the line still has a reading that is no refusal, so it keeps the
19
+ unread ones out as before. */
14
20
 
15
21
  interface MovableAccount {
16
22
  readonly state: AccountState;
17
23
  readonly flapping?: boolean | undefined;
18
24
  }
19
25
 
26
+ // An account whose reading says it cannot serve.
27
+ const refused = (state: AccountState): boolean => state.kind === "spent" || state.kind === "blocked";
28
+
20
29
  /**
21
- * The account a turn moves to among `others` (the account it leaves already left out). That is the roomiest with proven
22
- * room, else, where `readable` is false (the provider publishes no allowance), the steadiest unmeasured one. Ties keep the
23
- * caller's order. Undefined: nowhere to go.
30
+ * The account a turn moves to among `others` (the account it leaves already left out). That is the best with proven room
31
+ * (plan-pools.ts bestWithRoom: the first to renew unless nearly out, then the most room), else the steadiest unmeasured one where `readable` is false (the provider publishes no allowance) or every
32
+ * account with a reading is refused. Ties keep the caller's order. Undefined: nowhere to go.
24
33
  */
25
- export const moveDestination = <T extends MovableAccount>(others: readonly T[], readable: boolean): T | undefined =>
26
- roomiestAccount(others) ?? (readable ? undefined : preferredAccount(others.filter((entry) => entry.state.kind === "unknown")));
34
+ export const moveDestination = <T extends MovableAccount>(others: readonly T[], readable: boolean): T | undefined => {
35
+ const withRoom = bestWithRoom(others);
36
+ if (withRoom !== undefined) {
37
+ return withRoom;
38
+ }
39
+ const open = !readable || others.every((entry) => entry.state.kind === "unknown" || refused(entry.state));
40
+ return open ? preferredAccount(others.filter((entry) => entry.state.kind === "unknown")) : undefined;
41
+ };
@@ -13,7 +13,9 @@ import {
13
13
  refusalVerdict,
14
14
  refusedInstant,
15
15
  refusedPoolReset,
16
- roomiestAccount,
16
+ bestWithRoom,
17
+ NEARLY_OUT_ROOM,
18
+ renewalOf,
17
19
  scopedWindow,
18
20
  uncoveredModels,
19
21
  serviceState,
@@ -179,8 +181,8 @@ test("spent is the contract's one line: 99.5% still has room, 100% is spent unti
179
181
  test("a pool read at 100 in whole percents is at the line with no room, until a refusal proves it empty", () => {
180
182
  const week = window({ kind: "seven_day", utilization: 100, resetsAt: 900, rounded: true });
181
183
  const atLine = usage(window({ kind: "five_hour", utilization: 75, rounded: true }), week);
182
- expect(readingHeadroom(atLine)).toEqual({ kind: "ready", room: 0 });
183
- expect(readingHeadroom(atLine, { id: "claude-opus-5-5" })).toEqual({ kind: "ready", room: 0 });
184
+ expect(readingHeadroom(atLine)).toEqual({ kind: "ready", room: 0, renewsAt: 900 });
185
+ expect(readingHeadroom(atLine, { id: "claude-opus-5-5" })).toEqual({ kind: "ready", room: 0, renewsAt: 900 });
184
186
  // A precise 100 is still spent.
185
187
  expect(readingHeadroom(usage(window({ kind: "seven_day", utilization: 100, resetsAt: 900 })))).toEqual({ kind: "spent", reopensAt: 900 });
186
188
  // The provider refused it: spent until the pool reopens, and a reading still at the line does not answer that.
@@ -349,7 +351,7 @@ test("a spent allowance with no instant named is stamped with its pool's reset,
349
351
  const lapsed = at(500, window({ kind: "five_hour", utilization: 0, lapsedAt: reset }), window({ kind: "seven_day", utilization: 40, resetsAt: 900 }));
350
352
  expect(refusedPoolReset(spent, [{ account: "a", usage: lapsed }])).toBe(900);
351
353
  expect(refusalVerdict(filed, [{ account: "a", usage: lapsed }], reset * 1000)).toBe("answered");
352
- expect(serviceStates([{ account: "a", usage: lapsed }], [filed], undefined, reset * 1000).get("a")).toEqual({ kind: "ready", room: 60 });
354
+ expect(serviceStates([{ account: "a", usage: lapsed }], [filed], undefined, reset * 1000).get("a")).toEqual({ kind: "ready", room: 60, renewsAt: 900 });
353
355
  });
354
356
 
355
357
  // 2026-10-21: Claude refused at 5h 98% and weekly 97% (rounded) with no time named, so the refusal was stamped with the
@@ -378,7 +380,7 @@ test("a stamped reset ends a refusal only where no reading since it says the poo
378
380
  expect(serviceStates([{ account: "a", usage: weeklyFull }], [stamped], undefined, now).get("a")).toEqual(unstampedVerdict);
379
381
  expect(fleetCapacity([{ account: "a", usage: weeklyFull }], [stamped], undefined, now)).toMatchObject({ kind: "spent", reopensAt: weeklyReset });
380
382
  // Nothing read since the stamp: it ends there. Read with room since: over.
381
- expect(serviceStates([{ account: "a", usage: refusedIn }], [stamped], undefined, now).get("a")).toEqual({ kind: "ready", room: 2 });
383
+ expect(serviceStates([{ account: "a", usage: refusedIn }], [stamped], undefined, now).get("a")).toEqual({ kind: "ready", room: 2, renewsAt: weeklyReset });
382
384
  const roomSince = at((fiveHourReset + 600) * 1000, window({ kind: "five_hour", utilization: 4, resetsAt: fiveHourReset + 18_000 }), window({ kind: "seven_day", utilization: 60, resetsAt: weeklyReset }));
383
385
  expect(refusalVerdict(stamped, [{ account: "a", usage: roomSince }], now)).toBe("answered");
384
386
  });
@@ -436,9 +438,9 @@ test("each account answers to the newest refusal on file that still stands over
436
438
  b: { kind: "blocked", fix: "reconnect", reason: "no." },
437
439
  });
438
440
  // Only the provider's last one: the first account is back at the line, no room but not proven spent.
439
- expect(serviceStates(accounts, [elsewhere], undefined, 9_999).get("a")).toEqual({ kind: "ready", room: 0 });
441
+ expect(serviceStates(accounts, [elsewhere], undefined, 9_999).get("a")).toEqual({ kind: "ready", room: 0, renewsAt: 20 });
440
442
  // Past the instant the provider named, its refusal is over and the reading speaks alone.
441
- expect(serviceStates(accounts, [elsewhere, own], undefined, 20_000).get("a")).toEqual({ kind: "ready", room: 0 });
443
+ expect(serviceStates(accounts, [elsewhere, own], undefined, 20_000).get("a")).toEqual({ kind: "ready", room: 0, renewsAt: 20 });
442
444
  // A newer refusal on the same account outranks the older one.
443
445
  const revoked = refusal({ kind: "auth", account: "a", at: 6_000 });
444
446
  expect(serviceStates(accounts, [own, revoked], undefined, 9_999).get("a")).toEqual({ kind: "blocked", fix: "reconnect", reason: "no." });
@@ -491,14 +493,14 @@ test("refusals naming their accounts hold a 31-account Google fleet steady acros
491
493
  expect(fleetCapacity(accounts, refused, flash, reread)).toMatchObject({ kind: "serving", serving: 2, accounts: 31 });
492
494
  const states = serviceStates(accounts, refused, opus, reread);
493
495
  expect(states.get("tried-0")).toEqual({ kind: "spent", reopensAt: opusBack, pool: "Claude and GPT models" });
494
- expect(states.get("svichita09")).toEqual({ kind: "ready", room: 100 });
496
+ expect(states.get("svichita09")).toEqual({ kind: "ready", room: 100, renewsAt: opusBack });
495
497
  }
496
498
  // The same refusal filed under no account is answered on each account by its own reading alone: the account with
497
499
  // room frees itself, never one whose reading since says nothing.
498
500
  const nameless = refusal({ kind: "limit", at: refusedAt, model: "claude-opus-4-6-thinking", resetsAt: opusBack });
499
501
  const onlyOneRead = fleet(refusedAt - 30_000).map((facts) => (facts.account === "svichita09" ? { ...facts, usage: pools(reread, 0, 19.42) } : facts));
500
502
  const states = serviceStates([...onlyOneRead, { account: "unread" }], [nameless], opus, reread);
501
- expect(states.get("svichita09")).toEqual({ kind: "ready", room: 100 });
503
+ expect(states.get("svichita09")).toEqual({ kind: "ready", room: 100, renewsAt: opusBack });
502
504
  expect(states.get("unread")).toMatchObject({ kind: "spent", reopensAt: opusBack });
503
505
  });
504
506
 
@@ -528,8 +530,43 @@ test("an unnamed turn takes the most room, then an unmeasured account, then a sp
528
530
  expect(preferredAccount([entry("seatless", blocked), entry("spent", { kind: "spent" })])?.id).toBe("spent");
529
531
  expect(preferredAccount([entry("seatless", blocked), entry("other", blocked)])?.id).toBe("seatless");
530
532
  expect(preferredAccount([entry("first", { kind: "ready", room: 60 }), entry("second", { kind: "ready", room: 60 })])?.id).toBe("first");
531
- expect(roomiestAccount([entry("seatless", blocked), entry("unread", { kind: "unknown" })])).toBeUndefined();
532
- expect(roomiestAccount([entry("low", { kind: "ready", room: 5 }), entry("high", { kind: "ready", room: 60 })])?.id).toBe("high");
533
+ expect(bestWithRoom([entry("seatless", blocked), entry("unread", { kind: "unknown" })])).toBeUndefined();
534
+ expect(bestWithRoom([entry("low", { kind: "ready", room: 5 }), entry("high", { kind: "ready", room: 60 })])?.id).toBe("high");
535
+ });
536
+
537
+ /* 2026-11-17: Claude's Ultra plan meters no five-hour window. One account had 70 weekly points left renewing in six days,
538
+ the other 40 renewing in ten hours, and the most-room pick spent the first while the second's reset unspent. */
539
+ test("between accounts with room, the one whose allowance renews first wins, unless it is nearly out", () => {
540
+ const entry = (id: string, state: AccountState) => ({ id, state });
541
+ const now = 1_800_000_000;
542
+ const later = entry("later", { kind: "ready", room: 70, renewsAt: now + 144 * 3_600 });
543
+ const sooner = entry("sooner", { kind: "ready", room: 40, renewsAt: now + 10 * 3_600 });
544
+ expect(preferredAccount([later, sooner])?.id).toBe("sooner");
545
+ expect(bestWithRoom([later, sooner])?.id).toBe("sooner");
546
+ // Nearly out, it ranks after every account with more, however soon it renews; among those, room decides.
547
+ const nearlyOut = entry("nearly-out", { kind: "ready", room: NEARLY_OUT_ROOM, renewsAt: now + 3_600 });
548
+ expect(preferredAccount([nearlyOut, later])?.id).toBe("later");
549
+ expect(preferredAccount([nearlyOut, entry("lower", { kind: "ready", room: 4, renewsAt: now })])?.id).toBe("nearly-out");
550
+ // A reset nobody published never outranks a known one; between two unknown, room decides as before.
551
+ expect(preferredAccount([entry("unknown", { kind: "ready", room: 90 }), sooner])?.id).toBe("sooner");
552
+ expect(preferredAccount([entry("a", { kind: "ready", room: 50 }), entry("b", { kind: "ready", room: 60 })])?.id).toBe("b");
553
+ // The same moment: room decides.
554
+ expect(preferredAccount([sooner, entry("roomier", { kind: "ready", room: 80, renewsAt: now + 10 * 3_600 })])?.id).toBe("roomier");
555
+ });
556
+
557
+ test("an allowance renews when the longest pool the turn spends resets, never when a five-hour one does", () => {
558
+ const now = 1_800_000_000;
559
+ const weekly = (utilization: number, resetsAt: number): UsageWindow => ({ kind: "seven_day", utilization, resetsAt, gates: "all" });
560
+ const fiveHour: UsageWindow = { kind: "five_hour", utilization: 90, resetsAt: now + 3_600, gates: "all" };
561
+ expect(renewalOf([fiveHour, weekly(40, now + 20 * 3_600)])).toBe(now + 20 * 3_600);
562
+ // Two weekly pools (the whole plan's and Opus's slice): the first of them to reset.
563
+ expect(renewalOf([weekly(40, now + 50 * 3_600), { ...weekly(10, now + 30 * 3_600), kind: "seven_day_opus", gates: { models: ["opus"] } }])).toBe(now + 30 * 3_600);
564
+ // The weekly pool has lapsed (its reset passed, nothing re-read it): what renews is unknown, not the five-hour reset.
565
+ expect(renewalOf([fiveHour, { kind: "seven_day", utilization: 0, gates: "all", lapsedAt: now }])).toBeUndefined();
566
+ // No pool names its length: the first to reset decides.
567
+ expect(renewalOf([{ kind: "pool:a", utilization: 10, resetsAt: now + 7_200, gates: "all" }, { kind: "pool:b", utilization: 10, resetsAt: now + 3_600, gates: "all" }])).toBe(now + 3_600);
568
+ // The verdict carries it, read off the pools still open.
569
+ expect(readingHeadroom({ windows: [fiveHour, weekly(40, now + 20 * 3_600)], measuredAt: now * 1000 })).toEqual({ kind: "ready", room: 10, renewsAt: now + 20 * 3_600 });
533
570
  });
534
571
 
535
572
  test("an account at the line is tried after an unmeasured one and before a spent one, and never a move's destination", () => {
@@ -539,8 +576,8 @@ test("an account at the line is tried after an unmeasured one and before a spent
539
576
  expect(preferredAccount([entry("line", atLine), entry("unread", { kind: "unknown" })])?.id).toBe("unread");
540
577
  expect(preferredAccount([entry("spent", { kind: "spent" }), entry("line", atLine)])?.id).toBe("line");
541
578
  // A move lands only on proven room: two accounts at the line would otherwise hand a refused turn back and forth.
542
- expect(roomiestAccount([entry("line", atLine), entry("spent", { kind: "spent" })])).toBeUndefined();
543
- expect(roomiestAccount([entry("line", atLine), entry("low", { kind: "ready", room: 2 })])?.id).toBe("low");
579
+ expect(bestWithRoom([entry("line", atLine), entry("spent", { kind: "spent" })])).toBeUndefined();
580
+ expect(bestWithRoom([entry("line", atLine), entry("low", { kind: "ready", room: 2 })])?.id).toBe("low");
544
581
  });
545
582
 
546
583
  // The 2026-10-27/28 account: switched off, served for an evening (most room on its reading), switched off again.
@@ -548,9 +585,9 @@ test("an account its organisation keeps switching off goes behind every steady o
548
585
  const entry = (id: string, state: AccountState, flapping?: boolean) => ({ id, state, flapping });
549
586
  const flapping = entry("flapping", { kind: "ready", room: 90 }, true);
550
587
  expect(preferredAccount([flapping, entry("steady", { kind: "ready", room: 5 })])?.id).toBe("steady");
551
- expect(roomiestAccount([flapping, entry("steady", { kind: "ready", room: 5 }, false)])?.id).toBe("steady");
588
+ expect(bestWithRoom([flapping, entry("steady", { kind: "ready", room: 5 }, false)])?.id).toBe("steady");
552
589
  expect(preferredAccount([flapping, entry("unread", { kind: "unknown" }), entry("line", { kind: "ready", room: 0 })])?.id).toBe("flapping");
553
- expect(roomiestAccount([flapping, entry("line", { kind: "ready", room: 0 })])?.id).toBe("flapping");
590
+ expect(bestWithRoom([flapping, entry("line", { kind: "ready", room: 0 })])?.id).toBe("flapping");
554
591
  // Among flapping accounts, room decides again.
555
592
  expect(preferredAccount([flapping, entry("roomier", { kind: "ready", room: 95 }, true)])?.id).toBe("roomier");
556
593
  expect(preferredAccount([entry("off", { kind: "unknown" }, true), entry("on", { kind: "unknown" })])?.id).toBe("on");
@@ -588,8 +625,8 @@ test("an account whose only named pools are full, with models no pool covers, is
588
625
  test("a reading contradicted by an answered turn holds that model's full pools at the line, not spent", () => {
589
626
  const full = usage(window({ kind: "google:gemini-weekly", utilization: 100, resetsAt: 9_000, gates: { models: ["gemini"] } }));
590
627
  const contradicted: AccountUsage = { ...full, contradicted: { at: 1, model: "gemini-3.8-flash-high" } };
591
- expect(readingHeadroom(contradicted, { id: "gemini-3.8-flash-high" })).toEqual({ kind: "ready", room: 0 });
592
- expect(readingHeadroom(contradicted)).toEqual({ kind: "ready", room: 0 });
628
+ expect(readingHeadroom(contradicted, { id: "gemini-3.8-flash-high" })).toEqual({ kind: "ready", room: 0, renewsAt: 9_000 });
629
+ expect(readingHeadroom(contradicted)).toEqual({ kind: "ready", room: 0, renewsAt: 9_000 });
593
630
  // Another family's pool is not what the turn proved anything about.
594
631
  const other: AccountUsage = { ...full, contradicted: { at: 1, model: "claude-opus-4-6-thinking" } };
595
632
  expect(readingHeadroom(other, { id: "gemini-3.8-flash-high" })).toEqual({ kind: "spent", reopensAt: 9_000 });
@@ -645,7 +682,7 @@ test("a refusal's instant is judged against the pools a reading since publishes:
645
682
  const renewed = codex(Math.floor(now / 1000) + 6 * DAY);
646
683
  expect(refusedInstant(sol, renewed)).toBe("renewed");
647
684
  expect(refusalVerdict(sol, [{ account: "a", usage: renewed }], now)).toBe("answered");
648
- expect(serviceStates([{ account: "a", usage: renewed }], [sol], { id: "gpt-6.1-sol" }, now).get("a")).toEqual({ kind: "ready", room: 64 });
685
+ expect(serviceStates([{ account: "a", usage: renewed }], [sol], { id: "gpt-6.1-sol" }, now).get("a")).toEqual({ kind: "ready", room: 64, renewsAt: Math.floor(now / 1000) + 6 * DAY });
649
686
  // Renewed but already spent again: still held, by the window itself.
650
687
  expect(refusedInstant(sol, codex(Math.floor(now / 1000) + 6 * DAY, 100))).toBe("unpublished");
651
688
 
@@ -655,8 +692,8 @@ test("a refusal's instant is judged against the pools a reading since publishes:
655
692
  expect(refusedInstant(sol, unnamed)).toBe("unpublished");
656
693
  expect(refusalVerdict(sol, [{ account: "a", usage: unnamed }], now)).toBe("standing");
657
694
  expect(serviceState({ account: "a", usage: unnamed }, [sol], { id: "gpt-6.1-sol" }, now)).toEqual({ kind: "spent", reopensAt: instant, pool: "GPT 6.1 Sol" });
658
- expect(serviceState({ account: "a", usage: unnamed }, [sol], { id: "gpt-6-luna" }, now)).toEqual({ kind: "ready", room: 64 });
659
- expect(serviceState({ account: "a", usage: unnamed }, [sol], undefined, now)).toEqual({ kind: "ready", room: 64 });
695
+ expect(serviceState({ account: "a", usage: unnamed }, [sol], { id: "gpt-6-luna" }, now)).toEqual({ kind: "ready", room: 64, renewsAt: Math.floor(filed / 1000) + 5 * DAY });
696
+ expect(serviceState({ account: "a", usage: unnamed }, [sol], undefined, now)).toEqual({ kind: "ready", room: 64, renewsAt: Math.floor(filed / 1000) + 5 * DAY });
660
697
 
661
698
  // Nothing read since the refusal, or a pool with no reset to judge by: the instant outranks, on the pool the model spends.
662
699
  expect(refusedInstant(sol, { ...unnamed, measuredAt: filed - 1 })).toBe("unjudged");
@@ -109,6 +109,21 @@ const holdingPools = (full: readonly UsageWindow[], open: readonly UsageWindow[]
109
109
  return open.length === 0 ? full : [];
110
110
  };
111
111
 
112
+ /* WHEN AN ACCOUNT'S ALLOWANCE RENEWS, which is what a pick between accounts with room weighs first (preferredAccount).
113
+ What is left of a pool when it resets is gone: on 2026-11-17, with Claude's Ultra plan metering no five-hour window,
114
+ the pick kept every turn on the account with the most weekly room, resetting six days out, while another account's
115
+ 40% reset unspent ten hours later. The pool that decides is the longest the turn spends, since a shorter one refills
116
+ within the day whichever account is picked; among several of that length (Claude's weekly pool beside its weekly Opus
117
+ slice), the first to reset. Undefined where those publish no reset, or no pool names its length and none resets. */
118
+ export const renewalOf = (windows: readonly UsageWindow[]): number | undefined => {
119
+ const periods = windows.map((window) => windowPeriod(window)?.seconds);
120
+ const known = periods.filter((seconds) => seconds !== undefined);
121
+ const longest = known.length === 0 ? undefined : Math.max(...known);
122
+ const deciding = longest === undefined ? windows : windows.filter((_, index) => periods[index] === longest);
123
+ const resets = deciding.flatMap((window) => (window.resetsAt === undefined ? [] : [window.resetsAt]));
124
+ return resets.length === 0 ? undefined : Math.min(...resets);
125
+ };
126
+
112
127
  /**
113
128
  * What a reading says, at the contract's one spent line, never whether the account can serve: that is `serviceStates`,
114
129
  * which first lays every standing refusal on the reading (judgedReading). A provider that rounds its percentages (Claude
@@ -129,7 +144,9 @@ export const readingHeadroom = (usage: AccountUsage | undefined, model?: ModelRe
129
144
  const open = windows.filter((window) => !provenFull(window));
130
145
  const holding = holdingPools(full, open, model);
131
146
  if (holding.length === 0) {
132
- return { kind: "ready", room: Math.max(0, SPENT_UTILIZATION - Math.max(...open.map((window) => window.utilization))) };
147
+ const room = Math.max(0, SPENT_UTILIZATION - Math.max(...open.map((window) => window.utilization)));
148
+ const renewsAt = renewalOf(open);
149
+ return renewsAt === undefined ? { kind: "ready", room } : { kind: "ready", room, renewsAt };
133
150
  }
134
151
  const sliced = model === undefined && !holding.some((window) => window.gates === "all");
135
152
  // Every per-model slice this reading names is full, but it names none for some models the account serves: whether
@@ -361,20 +378,43 @@ const ranksAbove = (next: RankedAccount, best: RankedAccount): boolean => {
361
378
  if ((next.flapping === true) !== (best.flapping === true)) {
362
379
  return best.flapping === true;
363
380
  }
364
- return next.state.kind === "ready" && best.state.kind === "ready" && next.state.room > best.state.room;
381
+ return next.state.kind === "ready" && best.state.kind === "ready" && readyAbove(next.state, best.state);
382
+ };
383
+
384
+ /** Room at or below this, in points of the fullest pool, is an account nearly out: it ranks after every one with more. */
385
+ export const NEARLY_OUT_ROOM = 10;
386
+
387
+ /* BETWEEN TWO ACCOUNTS WITH ROOM, THE ONE WHOSE ALLOWANCE RENEWS FIRST (renewalOf), unless it is nearly out. Points left
388
+ in a pool at its reset are lost, so spending the pool that resets first wastes the least of what the plans pay for,
389
+ and the later one is still there when the first has renewed. Most room decides only between accounts renewing at the
390
+ same moment, between accounts no reset is known for, and among accounts nearly out, where room is what keeps the next
391
+ turn from being refused. This reads no load: the daemon's own Claude pick (budget-planner.ts pickAccount) orders the
392
+ same way among the accounts its projection says carry the turn with what already runs on them. */
393
+ const readyAbove = (next: AccountState & { kind: "ready" }, best: AccountState & { kind: "ready" }): boolean => {
394
+ const nextOpen = next.room > NEARLY_OUT_ROOM;
395
+ if (nextOpen !== best.room > NEARLY_OUT_ROOM) {
396
+ return nextOpen;
397
+ }
398
+ const nextRenews = next.renewsAt ?? Number.POSITIVE_INFINITY;
399
+ const bestRenews = best.renewsAt ?? Number.POSITIVE_INFINITY;
400
+ if (nextOpen && nextRenews !== bestRenews) {
401
+ return nextRenews < bestRenews;
402
+ }
403
+ return next.room > best.room;
365
404
  };
366
405
 
367
406
  /**
368
- * The account an unnamed turn runs on: ready by most room, then unmeasured, then at the line, then spent, blocked only
369
- * when that is all there is; within each, a flapping account after the steady ones. Ties keep the caller's order.
407
+ * The account an unnamed turn runs on: ready, then unmeasured, then at the line, then spent, blocked only when that is
408
+ * all there is; within each, a flapping account after the steady ones; among ready ones, the first to renew of those not
409
+ * nearly out, then the most room (readyAbove). Ties keep the caller's order.
370
410
  */
371
411
  export const preferredAccount = <T extends RankedAccount>(entries: readonly T[]): T | undefined =>
372
412
  entries.reduce<T | undefined>((best, next) => (best === undefined || ranksAbove(next, best) ? next : best), undefined);
373
413
 
374
414
  /**
375
- * The roomiest account with proven room, or none: what a move off a refused account may land on. Ties keep the caller's
376
- * order. An account at the line is left out: a move there could be refused in turn, and two such accounts would hand the
377
- * turn back and forth.
415
+ * The best account with proven room, by the same order, or none: what a move off a refused account may land on. Ties keep
416
+ * the caller's order. An account at the line is left out: a move there could be refused in turn, and two such accounts
417
+ * would hand the turn back and forth.
378
418
  */
379
- export const roomiestAccount = <T extends RankedAccount>(entries: readonly T[]): T | undefined =>
419
+ export const bestWithRoom = <T extends RankedAccount>(entries: readonly T[]): T | undefined =>
380
420
  preferredAccount(entries.filter((entry) => entry.state.kind === "ready" && entry.state.room > 0));
@@ -173,6 +173,9 @@ export const RunnerFactsSchema = z.object({
173
173
  // Absent where the kernel does not report it.
174
174
  cpuPressure: z.number().nonnegative().optional(),
175
175
  memoryStall: z.number().nonnegative().optional(),
176
+ // The GPUs a program there can use (passed through to the container), by name and memory; empty where there is none,
177
+ // absent from a runner that predates the question. What a heavy command that needs one is placed by.
178
+ gpus: z.array(z.object({ name: z.string(), memoryMb: z.number().int().nonnegative() })).optional(),
176
179
  });
177
180
  export type RunnerFacts = z.infer<typeof RunnerFactsSchema>;
178
181
 
@@ -291,6 +294,18 @@ export const OFFLOAD_REF_PREFIX = "refs/intentic-offload/";
291
294
  export const offloadRef = (runId: string): string => `${OFFLOAD_REF_PREFIX}${runId}`;
292
295
  const OffloadRunIdSchema = z.string().regex(/^[a-z0-9][a-z0-9-]{7,63}$/u);
293
296
  const EnvNameSchema = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/u);
297
+ const Sha256Schema = z.string().regex(/^[0-9a-f]{64}$/u);
298
+
299
+ // A path an offloaded line makes that its caller needs back besides edits: a binary it built, a picture it rendered.
300
+ // Repo-relative, ignored paths included (`target/debug/integra`), or absolute under /tmp; a directory brings back every
301
+ // file under it. Never anywhere else on the runner, and never out of the repo by `..`.
302
+ export const OffloadOutputPathSchema = z
303
+ .string()
304
+ .min(1)
305
+ .max(1024)
306
+ .refine((path) => !path.split("/").includes(".."), "must not climb out by ..")
307
+ .refine((path) => !path.startsWith("/") || path.startsWith("/tmp/"), "an absolute output must be under /tmp/");
308
+ export const isTmpOutput = (path: string): boolean => path.startsWith("/tmp/");
294
309
 
295
310
  export const RunnerCommandSchema = z.object({
296
311
  runId: OffloadRunIdSchema,
@@ -306,6 +321,11 @@ export const RunnerCommandSchema = z.object({
306
321
  // Variables the line writes a file to (a report path): the runner points each at a scratch file and hands the file
307
322
  // back with the exit.
308
323
  exports: z.array(EnvNameSchema).max(8).default([]),
324
+ // Paths the line makes that come back whole, as `file` frames before the exit (OffloadOutputPathSchema).
325
+ outputs: z.array(OffloadOutputPathSchema).max(16).default([]),
326
+ // What the caller already holds at an output path (a directory's files by their own paths), by sha256: a file the
327
+ // same byte for byte is said, not sent.
328
+ have: z.record(z.string(), Sha256Schema).default({}),
309
329
  // The heavy-command rule it matched here, named in the runner's own output and queue.
310
330
  label: z.string().min(1).max(80),
311
331
  timeoutMs: z
@@ -317,12 +337,25 @@ export const RunnerCommandSchema = z.object({
317
337
  });
318
338
  export type RunnerCommand = z.infer<typeof RunnerCommandSchema>;
319
339
 
340
+ // One output file coming back, in pieces sent in order: each `data` is one gzip member of the next bytes, base64, and
341
+ // the last piece carries `end` with the whole file's size, mode and sha256, which the caller checks before it puts the
342
+ // file in place. `same` instead of data says the caller already holds it byte for byte.
343
+ export const RunnerFileFrameSchema = z.object({
344
+ kind: z.literal("file"),
345
+ path: z.string().min(1),
346
+ data: z.string().optional(),
347
+ end: z.object({ size: z.number().int().nonnegative(), mode: z.number().int().nonnegative(), sha256: Sha256Schema }).optional(),
348
+ same: z.boolean().optional(),
349
+ });
350
+ export type RunnerFileFrame = z.infer<typeof RunnerFileFrameSchema>;
351
+
320
352
  // What a running command streams back: narration of the runner's own steps (fetch, install, queue), the line's output
321
- // as it comes, and last its end: the exit, every file it changed as a binary git patch against the snapshot, and the
322
- // exported files, base64.
353
+ // as it comes, the output files asked for, and last its end: the exit, every file it changed as a binary git patch
354
+ // against the snapshot, and the exported files, base64.
323
355
  export const RunnerCommandFrameSchema = z.union([
324
356
  z.object({ kind: z.literal("status"), text: z.string() }),
325
357
  z.object({ kind: z.literal("output"), stream: z.enum(["stdout", "stderr"]), text: z.string() }),
358
+ RunnerFileFrameSchema,
326
359
  z.object({
327
360
  kind: z.literal("exit"),
328
361
  code: z.number().int(),
@@ -333,6 +366,13 @@ export const RunnerCommandFrameSchema = z.union([
333
366
  ran: z.boolean().default(true),
334
367
  patchBase64: z.string().optional(),
335
368
  files: z.record(EnvNameSchema, z.string()).default({}),
369
+ // How heavy the line was there, for the parent's command profiles (offload/command-profiles.ts): the most
370
+ // memory everything it started held at once, and how long it ran. Absent where the runner could not measure.
371
+ peakMemoryMb: z.number().int().nonnegative().optional(),
372
+ durationMs: z.number().int().nonnegative().optional(),
373
+ // Outputs asked for that the line never made, and ones too big to bring back.
374
+ missing: z.array(z.string()).optional(),
375
+ tooBig: z.array(z.string()).optional(),
336
376
  }),
337
377
  ]);
338
378
  export type RunnerCommandFrame = z.infer<typeof RunnerCommandFrameSchema>;
@@ -180,6 +180,11 @@ export const RAW_ROUTES = {
180
180
  // The `devices push` CLI: a program the agent built, carried to one of the owner's computers in chunks; held to the
181
181
  // devices the calling conversation's turn mounts, and refused by the machine itself unless "Run programs" is on.
182
182
  "POST /devices/{name}/artifacts": { agent: true, control: "never" },
183
+ // The `devices copy` CLI: a file or a folder carried to a path on one of the owner's computers, or back off it, in
184
+ // chunks (hosts/device-files.routes.ts); held to the same rule, and the machine holds each chunk to its folders and,
185
+ // onto it, its "Create and change files" switch.
186
+ "POST /devices/{name}/files": { agent: true, control: "never" },
187
+ "GET /devices/{name}/files": { agent: true, control: "never" },
183
188
  // The rest of the `devices` command, held to the same rule (hosts/device-door.routes.ts): the device's app_start for a
184
189
  // shell, and its loopback ports reached from the sandbox (hosts/device-tunnels.ts).
185
190
  "POST /devices/{name}/apps": { agent: true, control: "never" },
@@ -397,9 +397,9 @@ export const AutomationSchema = z.object({
397
397
  "Which models this automation may run on, best first. Required when it starts a new agent, and nothing is chosen for you: work that fires while nobody is watching spends a real allowance, so it names the models it spends rather than inheriting one. Tried in order, so a spent account does not silently stop the job. Not needed to continue a conversation, which runs on its own model, or to only notify.",
398
398
  ),
399
399
  // Absent means the daemon's pick: the account its conversation runs on for a continuing thread (moved off one that
400
- // can no longer serve), else the one that can serve with the most room. Named, it is a pin, run whatever its state,
401
- // so a refused account says so rather than being swapped; pinning matters more here than for a chat, since nobody
402
- // is watching to notice a stuck one.
400
+ // can no longer serve), else the sandbox's pick among those that can serve (the first to renew unless nearly out).
401
+ // Named, it is a pin, run whatever its state, so a refused account says so rather than being swapped; pinning
402
+ // matters more here than for a chat, since nobody is watching to notice a stuck one.
403
403
  account: z.string().optional().describe("Which account pays for it."),
404
404
  // Absent means the wake reaches no logged-in account at all, the strictest default here, since nobody is at the
405
405
  // composer when it fires. Posture only: what the wake may reach is `runAs`'s (docs/architecture/access.md).
package/src/schemas/ci.ts CHANGED
@@ -265,6 +265,48 @@ export const CiRunsResponseSchema = z.object({
265
265
  ),
266
266
  });
267
267
  export type CiRunsResponse = z.infer<typeof CiRunsResponseSchema>;
268
+ // 2026-11-17, the shinobi-society audit: conversation after conversation spent calls finding out whether a test that
269
+ // failed for it was its own or already failing on main (stashing its work, re-running main, comparing), while the daemon
270
+ // had already read every failed main-line job's log. `GET /ci/main` (`agents ci`) answers from what it heard, asking no
271
+ // forge: each job failing on a main line, the run and commit it last failed in, when that was read, and what its log
272
+ // named. A main line nothing is known of says so, so silence never reads as a passing main.
273
+ export const CiMainJobSchema = z.object({
274
+ workflow: z.string().describe("The workflow it is a job of, by the forge's name. `ci` on a forge that runs one pipeline per commit."),
275
+ job: z.string().describe("The job, by name."),
276
+ runId: z.number().optional().describe("The run it last failed in. Absent for a failure heard before the daemon kept it."),
277
+ sha: z.string().optional().describe("That run's commit, where the forge said."),
278
+ readAt: z.number().optional().describe("When the daemon read that failure, in milliseconds."),
279
+ errors: z
280
+ .array(z.string())
281
+ .optional()
282
+ .describe(
283
+ "What its failed steps printed, one line each and bounded: failing tests by name (`(fail) …`, `test … FAILED`), type and lint errors, failed checks, and how a task ended (a signal's exit code, a heap run out). Empty when its log named nothing of the kind; absent when the log was not read.",
284
+ ),
285
+ timedOut: z.boolean().optional().describe("Whether it failed by running out of time. Absent when it did not."),
286
+ });
287
+ export type CiMainJob = z.infer<typeof CiMainJobSchema>;
288
+ export const CiMainBranchSchema = z.object({
289
+ repo: z.string().describe("Which workspace repository."),
290
+ branch: z.string().optional().describe("Its main line. Absent when neither the forge nor the clone named a default branch and no run of one was heard."),
291
+ state: z
292
+ .enum(["failing", "clear", "unread"])
293
+ .describe(
294
+ "`failing`: the jobs below fail on it now. `clear`: a finished run of it was heard and no job of main's own code is known to fail. `unread`: no finished run of it has been heard, so nothing is known.",
295
+ ),
296
+ since: z.number().optional().describe("When its first job failed, on a failing one, in milliseconds."),
297
+ jobs: z.array(CiMainJobSchema).describe("The jobs failing on it now, in the order they began failing. Empty unless it is failing."),
298
+ lastRun: z
299
+ .object({ status: z.enum(["success", "failed"]), at: z.number() })
300
+ .optional()
301
+ .describe("The newest finished run of it the daemon heard, any workflow: how it ended and when it was heard. Absent when none was."),
302
+ fixer: z.string().optional().describe("The fix agent on its failure, when one is."),
303
+ });
304
+ export type CiMainBranch = z.infer<typeof CiMainBranchSchema>;
305
+ export const CiMainResponseSchema = z.object({
306
+ text: z.string().describe("The whole answer in words, as `agents ci` prints it."),
307
+ branches: z.array(CiMainBranchSchema).describe("Each repository wired to CI, and any main line still failing in one no longer wired."),
308
+ });
309
+ export type CiMainResponse = z.infer<typeof CiMainResponseSchema>;
268
310
  // Re-resolves repo → project + token on every call, so a stale card can't act on a mapping the workspace no longer has.
269
311
  export const CiRunParamSchema = z.object({
270
312
  repo: z