@intentic/sandbox-contract 1.427.0 → 1.429.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 (171) hide show
  1. package/README.md +22 -5
  2. package/dist/contracts/accounts.contract.d.ts +4 -0
  3. package/dist/contracts/accounts.contract.d.ts.map +1 -1
  4. package/dist/contracts/agent.contract.d.ts +60 -0
  5. package/dist/contracts/agent.contract.d.ts.map +1 -1
  6. package/dist/contracts/agents.contract.d.ts +617 -0
  7. package/dist/contracts/agents.contract.d.ts.map +1 -1
  8. package/dist/contracts/agents.contract.js +11 -0
  9. package/dist/contracts/agents.contract.js.map +1 -1
  10. package/dist/contracts/bases.contract.d.ts +43 -0
  11. package/dist/contracts/bases.contract.d.ts.map +1 -0
  12. package/dist/contracts/bases.contract.js +33 -0
  13. package/dist/contracts/bases.contract.js.map +1 -0
  14. package/dist/contracts/ci.contract.d.ts +17 -0
  15. package/dist/contracts/ci.contract.d.ts.map +1 -1
  16. package/dist/contracts/loops.contract.d.ts +2 -0
  17. package/dist/contracts/loops.contract.d.ts.map +1 -1
  18. package/dist/contracts/needs.contract.d.ts +52 -0
  19. package/dist/contracts/needs.contract.d.ts.map +1 -1
  20. package/dist/contracts/offload.contract.d.ts +14 -14
  21. package/dist/contracts/runner.contract.d.ts +62 -14
  22. package/dist/contracts/runner.contract.d.ts.map +1 -1
  23. package/dist/contracts/seal.contract.d.ts +10 -0
  24. package/dist/contracts/seal.contract.d.ts.map +1 -1
  25. package/dist/contracts/sessions.contract.d.ts +6 -0
  26. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  27. package/dist/contracts/settings.contract.d.ts +4 -0
  28. package/dist/contracts/settings.contract.d.ts.map +1 -1
  29. package/dist/contracts/system.contract.d.ts +370 -4
  30. package/dist/contracts/system.contract.d.ts.map +1 -1
  31. package/dist/contracts/system.contract.js +45 -0
  32. package/dist/contracts/system.contract.js.map +1 -1
  33. package/dist/contracts/translator.contract.d.ts +8 -0
  34. package/dist/contracts/translator.contract.d.ts.map +1 -1
  35. package/dist/contracts/usage.contract.d.ts +110 -0
  36. package/dist/contracts/usage.contract.d.ts.map +1 -1
  37. package/dist/contracts/usage.contract.js +18 -0
  38. package/dist/contracts/usage.contract.js.map +1 -1
  39. package/dist/contracts/workflows.contract.d.ts +3 -0
  40. package/dist/contracts/workflows.contract.d.ts.map +1 -1
  41. package/dist/events/agent-events.d.ts +26 -0
  42. package/dist/events/agent-events.d.ts.map +1 -1
  43. package/dist/events/agent-events.js +4 -0
  44. package/dist/events/agent-events.js.map +1 -1
  45. package/dist/events/agent-transcript.d.ts +6 -0
  46. package/dist/events/agent-transcript.d.ts.map +1 -1
  47. package/dist/events/system-events.d.ts +222 -0
  48. package/dist/events/system-events.d.ts.map +1 -1
  49. package/dist/events/system-events.js +6 -0
  50. package/dist/events/system-events.js.map +1 -1
  51. package/dist/events/transcript.d.ts +30 -0
  52. package/dist/events/transcript.d.ts.map +1 -1
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +2 -0
  56. package/dist/index.js.map +1 -1
  57. package/dist/models/plan-pools.d.ts +8 -7
  58. package/dist/models/plan-pools.d.ts.map +1 -1
  59. package/dist/models/plan-pools.js +63 -40
  60. package/dist/models/plan-pools.js.map +1 -1
  61. package/dist/models/verdict/current-windows.d.ts +9 -0
  62. package/dist/models/verdict/current-windows.d.ts.map +1 -0
  63. package/dist/models/verdict/current-windows.js +60 -0
  64. package/dist/models/verdict/current-windows.js.map +1 -0
  65. package/dist/models/verdict/refusal-verdict.d.ts +6 -3
  66. package/dist/models/verdict/refusal-verdict.d.ts.map +1 -1
  67. package/dist/models/verdict/refusal-verdict.js +71 -18
  68. package/dist/models/verdict/refusal-verdict.js.map +1 -1
  69. package/dist/models/verdict/window-period.d.ts +7 -1
  70. package/dist/models/verdict/window-period.d.ts.map +1 -1
  71. package/dist/models/verdict/window-period.js +21 -2
  72. package/dist/models/verdict/window-period.js.map +1 -1
  73. package/dist/protocol/raw/raw-routes.d.ts +13 -0
  74. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  75. package/dist/protocol/raw/raw-routes.js +4 -0
  76. package/dist/protocol/raw/raw-routes.js.map +1 -1
  77. package/dist/schemas/agents-list.d.ts +4 -0
  78. package/dist/schemas/agents-list.d.ts.map +1 -1
  79. package/dist/schemas/agents.d.ts +6 -0
  80. package/dist/schemas/agents.d.ts.map +1 -1
  81. package/dist/schemas/agents.js +2 -0
  82. package/dist/schemas/agents.js.map +1 -1
  83. package/dist/schemas/bases.d.ts +52 -0
  84. package/dist/schemas/bases.d.ts.map +1 -0
  85. package/dist/schemas/bases.js +31 -0
  86. package/dist/schemas/bases.js.map +1 -0
  87. package/dist/schemas/ci.d.ts +35 -0
  88. package/dist/schemas/ci.d.ts.map +1 -1
  89. package/dist/schemas/ci.js +25 -0
  90. package/dist/schemas/ci.js.map +1 -1
  91. package/dist/schemas/context-continues.d.ts +5 -0
  92. package/dist/schemas/context-continues.d.ts.map +1 -0
  93. package/dist/schemas/context-continues.js +17 -0
  94. package/dist/schemas/context-continues.js.map +1 -0
  95. package/dist/schemas/device-stacks.d.ts +161 -0
  96. package/dist/schemas/device-stacks.d.ts.map +1 -0
  97. package/dist/schemas/device-stacks.js +65 -0
  98. package/dist/schemas/device-stacks.js.map +1 -0
  99. package/dist/schemas/hosts.d.ts +2 -0
  100. package/dist/schemas/hosts.d.ts.map +1 -1
  101. package/dist/schemas/hosts.js +2 -0
  102. package/dist/schemas/hosts.js.map +1 -1
  103. package/dist/schemas/loops.d.ts +4 -0
  104. package/dist/schemas/loops.d.ts.map +1 -1
  105. package/dist/schemas/loops.js +7 -0
  106. package/dist/schemas/loops.js.map +1 -1
  107. package/dist/schemas/needs.d.ts +50 -1
  108. package/dist/schemas/needs.d.ts.map +1 -1
  109. package/dist/schemas/needs.js +16 -2
  110. package/dist/schemas/needs.js.map +1 -1
  111. package/dist/schemas/proceed-without-asking.d.ts +9 -0
  112. package/dist/schemas/proceed-without-asking.d.ts.map +1 -0
  113. package/dist/schemas/proceed-without-asking.js +17 -0
  114. package/dist/schemas/proceed-without-asking.js.map +1 -0
  115. package/dist/schemas/providers/capacity.d.ts +291 -0
  116. package/dist/schemas/providers/capacity.d.ts.map +1 -0
  117. package/dist/schemas/providers/capacity.js +64 -0
  118. package/dist/schemas/providers/capacity.js.map +1 -0
  119. package/dist/schemas/providers/plan-limits.d.ts +14 -0
  120. package/dist/schemas/providers/plan-limits.d.ts.map +1 -1
  121. package/dist/schemas/providers/plan-limits.js +9 -2
  122. package/dist/schemas/providers/plan-limits.js.map +1 -1
  123. package/dist/schemas/providers/provider-oauth.d.ts +4 -0
  124. package/dist/schemas/providers/provider-oauth.d.ts.map +1 -1
  125. package/dist/schemas/providers/refusals.d.ts +8 -0
  126. package/dist/schemas/providers/refusals.d.ts.map +1 -1
  127. package/dist/schemas/providers/refusals.js +8 -0
  128. package/dist/schemas/providers/refusals.js.map +1 -1
  129. package/dist/schemas/run-targets.d.ts +1 -0
  130. package/dist/schemas/run-targets.d.ts.map +1 -1
  131. package/dist/schemas/run-targets.js +2 -1
  132. package/dist/schemas/run-targets.js.map +1 -1
  133. package/dist/schemas/settings.d.ts +4 -0
  134. package/dist/schemas/settings.d.ts.map +1 -1
  135. package/dist/schemas/settings.js +6 -8
  136. package/dist/schemas/settings.js.map +1 -1
  137. package/dist/schemas/workflows.d.ts +5 -0
  138. package/dist/schemas/workflows.d.ts.map +1 -1
  139. package/dist/state/definition.d.ts +8 -0
  140. package/dist/state/definition.d.ts.map +1 -1
  141. package/package.json +5 -5
  142. package/src/contracts/agents.contract.ts +13 -0
  143. package/src/contracts/bases.contract.ts +38 -0
  144. package/src/contracts/system.contract.ts +66 -0
  145. package/src/contracts/usage.contract.ts +21 -0
  146. package/src/events/agent-events.ts +8 -0
  147. package/src/events/system-events.ts +11 -0
  148. package/src/index.ts +3 -0
  149. package/src/models/plan-pools.test.ts +271 -39
  150. package/src/models/plan-pools.ts +132 -70
  151. package/src/models/verdict/current-windows.ts +95 -0
  152. package/src/models/verdict/refusal-verdict.ts +124 -30
  153. package/src/models/verdict/window-period.ts +53 -6
  154. package/src/protocol/raw/raw-routes.ts +9 -0
  155. package/src/schemas/agents.ts +2 -0
  156. package/src/schemas/bases.ts +48 -0
  157. package/src/schemas/ci.ts +35 -0
  158. package/src/schemas/context-continues.ts +40 -0
  159. package/src/schemas/device-stacks.ts +126 -0
  160. package/src/schemas/hosts.ts +4 -0
  161. package/src/schemas/loops.ts +10 -0
  162. package/src/schemas/needs.ts +25 -2
  163. package/src/schemas/proceed-without-asking.ts +37 -0
  164. package/src/schemas/providers/capacity.ts +91 -0
  165. package/src/schemas/providers/plan-limits.ts +20 -3
  166. package/src/schemas/providers/refusals.ts +17 -0
  167. package/src/schemas/run-targets.ts +4 -3
  168. package/src/schemas/settings.ts +6 -14
  169. package/src/state/daemon-floor.test.ts +2 -0
  170. package/src/state/workspace-state.test.ts +3 -3
  171. package/src/state/workspace-state.ts +1 -1
@@ -1,6 +1,14 @@
1
- // How long a pool's window runs, read off the provider's own key and whatever name it published. One implementation,
2
- // because two things need it and must agree: a narrow column names the window by `short`, and a reading with no
3
- // published reset instant may only be trusted for `seconds` past the moment it was taken.
1
+ // How long a pool's window runs. One implementation, because two things need it and must agree: a narrow column names
2
+ // the window by `short`, and a reading with no published reset instant may only be trusted for `seconds` past the moment
3
+ // it was taken.
4
+ //
5
+ // The reader that parsed the provider's answer states the length where the answer says it (`periodSeconds`), and that
6
+ // statement is what every judgement reads. Before 2026-11-19 the length was worked out again on every judgement, in the
7
+ // daemon and in every open window, from the words of the pool's key and name ("5 hours", "weekly", "seven days"), and
8
+ // those words are still how a window filed without a statement is read: every reading before then, and a pool whose
9
+ // answer states nothing but whose name does. Re-reading the words each time was rejected, since a fact the provider gave
10
+ // once had to be recovered from a label on every judgement, and a pool named without period words (a Claude model's
11
+ // weekly slice, "Fable") read as having no length at all.
4
12
 
5
13
  export interface WindowPeriod {
6
14
  readonly seconds: number;
@@ -8,8 +16,18 @@ export interface WindowPeriod {
8
16
  readonly short: string;
9
17
  }
10
18
 
19
+ /** What a period is read off: the pool's key and name, and the length its reader stated, where it stated one. */
20
+ export interface PeriodSource {
21
+ readonly kind: string;
22
+ readonly label?: string | undefined;
23
+ readonly periodSeconds?: number | undefined;
24
+ }
25
+
26
+ const MINUTE_SECONDS = 60;
11
27
  const HOUR_SECONDS = 3_600;
12
28
  const DAY_SECONDS = 86_400;
29
+ // A month as the plans sell it: ChatGPT states its monthly window as 30 days, and a calendar month runs 28 to 31.
30
+ const MONTH_DAYS = { least: 28, most: 31 } as const;
13
31
 
14
32
  /** Kind and label as space-padded lowercase words, underscores split, so `\b` matches across both spellings. */
15
33
  export const periodWords = (pool: { readonly kind: string; readonly label?: string | undefined }): string =>
@@ -39,8 +57,11 @@ const dayPeriod = (words: string, days: number | undefined): WindowPeriod | unde
39
57
  return days === undefined ? undefined : { seconds: days * DAY_SECONDS, short: `${days}d` };
40
58
  };
41
59
 
42
- /** Window length behind a pool; undefined when neither the key nor the name says how long it runs. */
43
- export const windowPeriod = (pool: { readonly kind: string; readonly label?: string | undefined }): WindowPeriod | undefined => {
60
+ /**
61
+ * Window length the words of a key and a name spell out; undefined where they name none. What a reader with a word for
62
+ * the period and no figure states (Google's bucket `window: "weekly"`), and what a window with no statement is read by.
63
+ */
64
+ export const namedPeriod = (pool: { readonly kind: string; readonly label?: string | undefined }): WindowPeriod | undefined => {
44
65
  const words = periodWords(pool);
45
66
  const hours = counted(words, /\b(\d+) hours?\b/u);
46
67
  // Hours first: a pool named both ("5 hours, weekly cap") runs on the shorter clock.
@@ -53,5 +74,31 @@ export const windowPeriod = (pool: { readonly kind: string; readonly label?: str
53
74
  return day;
54
75
  }
55
76
  const minutes = counted(words, /\b(\d+) minutes?\b/u);
56
- return minutes === undefined ? undefined : { seconds: minutes * 60, short: `${minutes}m` };
77
+ return minutes === undefined ? undefined : { seconds: minutes * MINUTE_SECONDS, short: `${minutes}m` };
57
78
  };
79
+
80
+ // A stated length, named as the words would name it: the week, a day as "24h", a month, else whole days, hours or
81
+ // minutes, and seconds only for a length none of those divides.
82
+ const statedPeriod = (seconds: number): WindowPeriod => {
83
+ const days = seconds / DAY_SECONDS;
84
+ if (Number.isInteger(days)) {
85
+ if (days === 7) {
86
+ return { seconds, short: "wk" };
87
+ }
88
+ if (days === 1) {
89
+ return { seconds, short: "24h" };
90
+ }
91
+ return { seconds, short: days >= MONTH_DAYS.least && days <= MONTH_DAYS.most ? "mo" : `${days}d` };
92
+ }
93
+ if (Number.isInteger(seconds / HOUR_SECONDS)) {
94
+ return { seconds, short: `${seconds / HOUR_SECONDS}h` };
95
+ }
96
+ return { seconds, short: Number.isInteger(seconds / MINUTE_SECONDS) ? `${seconds / MINUTE_SECONDS}m` : `${seconds}s` };
97
+ };
98
+
99
+ /**
100
+ * Window length behind a pool: the one its reader stated (`periodSeconds`), else the one its key and name spell out
101
+ * (namedPeriod); undefined where neither says how long it runs.
102
+ */
103
+ export const windowPeriod = (pool: PeriodSource): WindowPeriod | undefined =>
104
+ pool.periodSeconds !== undefined && pool.periodSeconds > 0 ? statedPeriod(pool.periodSeconds) : namedPeriod(pool);
@@ -166,6 +166,12 @@ export const RAW_ROUTES = {
166
166
  "GET /fleet": { agent: true },
167
167
  "POST /fleet/message": { agent: true },
168
168
  "POST /fleet/resume": { agent: true },
169
+ // Repeating a prompt until a check passes or nothing is left (`agents loop`), making the round in flight the last, and
170
+ // carrying a conversation on in a fresh session (`agents continue`): what a person does with a conversation's card
171
+ // (the sandbox's loops/fleet-loop.routes.ts).
172
+ "POST /fleet/loop": { agent: true },
173
+ "POST /fleet/loop/stop": { agent: true },
174
+ "POST /fleet/continue": { agent: true },
169
175
  "GET /fleet/{handle}": { agent: true },
170
176
  // One conversation's debug bundle (schemas/diagnostics.ts): `agents bundle`, and the editor's download of it. It
171
177
  // carries the daemon's log lines about it, so a person reads it at the floor the logs are read at.
@@ -196,6 +202,9 @@ export const RAW_ROUTES = {
196
202
  "POST /devices/{name}/tunnels": { agent: true, control: "never" },
197
203
  "DELETE /devices/{name}/tunnels/{port}": { agent: true, control: "never" },
198
204
  "GET /devices/tunnels": { agent: true },
205
+ // What a computer said of itself (its OS, shell, home, allowed folders, WSL distros), for `devices exec` to write for
206
+ // it; held to the same rule.
207
+ "GET /devices/{name}/facts": { agent: true, control: "never" },
199
208
  // Where a device dials back with a tunnel's one-time ticket; the ticket is the whole credential, checked by the route.
200
209
  "GET /system/hosts/tunnel": { auth: "door", control: "never" },
201
210
  // An extension gateway's realtime-listener control: /state hands back its connectors' stored credentials, so only the
@@ -9,6 +9,7 @@ import { RepoBranchSchema } from "./shared.js";
9
9
  import { LoopStateSchema } from "./loops.js";
10
10
  import { LimitPolicySchema, MemoryKillPolicySchema, RetryPolicySchema, RoomPolicySchema, TurnBreakPolicySchema, TurnBreakSchema } from "./turn-break.js";
11
11
  import { KeepWarmSchema } from "./keep-warm.js";
12
+ import { proceedOverride } from "./proceed-without-asking.js";
12
13
  import { AgentNeedSchema } from "./needs.js";
13
14
  import { StrandedCloneSchema } from "./stranded-clone.js";
14
15
  import { EMOJI_MAX_LENGTH, isSingleEmoji } from "../text/emoji.js";
@@ -374,6 +375,7 @@ export const AgentSummarySchema = z.object({
374
375
  memoryKillPolicy: MemoryKillPolicySchema.optional().describe(
375
376
  "This conversation's own answer to a turn the sandbox killed because it ran out of memory: `resume` sends it again by itself once memory has stayed free, `wait` holds it for a press. Absent means it follows the sandbox-wide setting.",
376
377
  ),
378
+ proceedWithoutAsking: proceedOverride,
377
379
  // A collaborator's ask to land (collaborators can't merge themselves); cleared by whichever merge or discard
378
380
  // answers it.
379
381
  landRequested: z
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+
3
+ // A base: a read-only checkout of one repository at one commit, where a conversation started (or main's tip, or any
4
+ // commit), shared by every conversation that asks for that commit and removed once none uses it. The `base` command on
5
+ // the agent's PATH asks for one and runs a command in it, so "before" is one command and never touches the agent's own
6
+ // checkout (the daemon's src/conversations/worktrees/bases/base-checkouts.ts).
7
+
8
+ const FullShaSchema = z.string().regex(/^[0-9a-f]{40}$/u, "a full 40-character commit sha");
9
+
10
+ export const BaseAtSchema = z
11
+ .union([z.literal("fork"), z.literal("main"), FullShaSchema])
12
+ .describe("Which commit: `fork`, where the asking checkout's HEAD leaves the main line (the default); `main`, the main line's tip; or a full commit sha.");
13
+ export type BaseAt = z.infer<typeof BaseAtSchema>;
14
+
15
+ export const BaseAskSchema = z.object({
16
+ gitDir: z.string().min(1).describe("The asking checkout's git common dir, absolute: which repository the base is of."),
17
+ head: FullShaSchema.optional().describe("The asking checkout's HEAD, which `fork` is measured from."),
18
+ at: BaseAtSchema.optional(),
19
+ });
20
+ export type BaseAsk = z.infer<typeof BaseAskSchema>;
21
+
22
+ export const BaseDropSchema = BaseAskSchema.partial().extend({
23
+ all: z.boolean().optional().describe("Let go of every base this conversation holds, instead of the one the rest names."),
24
+ });
25
+ export type BaseDrop = z.infer<typeof BaseDropSchema>;
26
+
27
+ // What a seed did for one Cargo target of the base (build-outputs/warm-seed.ts SeedOutcome).
28
+ export const BaseWarmSchema = z.object({
29
+ rel: z.string(),
30
+ state: z.enum(["seeded", "skipped"]),
31
+ from: z.string().optional(),
32
+ reason: z.string().optional(),
33
+ });
34
+
35
+ export const BaseCheckoutSchema = z.object({
36
+ repo: z.string().describe('The repository, as the workspace names it ("root" for the workspace\'s own).'),
37
+ commit: FullShaSchema,
38
+ path: z.string().describe("Where the base stands: the repository's root at that commit."),
39
+ holders: z.array(z.string()).describe("The conversations that asked for it lately; it goes once none does."),
40
+ usedAt: z.number().describe("When it was last asked for, epoch ms."),
41
+ });
42
+ export type BaseCheckout = z.infer<typeof BaseCheckoutSchema>;
43
+
44
+ export const BaseEnsuredSchema = BaseCheckoutSchema.extend({
45
+ created: z.boolean().describe("Whether this ask made it, rather than finding it standing."),
46
+ warm: z.array(BaseWarmSchema).describe("What each of its Cargo targets was seeded from, or why it was left cold."),
47
+ });
48
+ export type BaseEnsured = z.infer<typeof BaseEnsuredSchema>;
package/src/schemas/ci.ts CHANGED
@@ -302,9 +302,44 @@ export const CiMainBranchSchema = z.object({
302
302
  fixer: z.string().optional().describe("The fix agent on its failure, when one is."),
303
303
  });
304
304
  export type CiMainBranch = z.infer<typeof CiMainBranchSchema>;
305
+ // 2026-11-19, the shinobi-society audit: `agents ci` said "nothing known to fail" while sixteen tests failed on main,
306
+ // in suites CI does not run. The sandbox's own record of test runs (output-cleaners' test-outcomes.mjs) knows those: a
307
+ // run on a clean tree at a main commit is that commit's baseline.
308
+ export const CiLocalMainSchema = z.object({
309
+ repo: z.string().describe("Which repository, by the name of its git directory."),
310
+ sha: z.string().describe("The main commit, the newest one with a recorded run in this repository."),
311
+ at: z.number().describe("When the newest run there ended, in milliseconds."),
312
+ runs: z
313
+ .array(
314
+ z.object({
315
+ command: z.string().describe("The command as the agent wrote it."),
316
+ at: z.number().describe("When it ended, in milliseconds."),
317
+ by: z.string().optional().describe("The conversation that ran it, where known."),
318
+ failed: z.number().describe("How many tests it counted failing."),
319
+ passed: z.number().describe("How many it counted passing."),
320
+ }),
321
+ )
322
+ .describe("Every recorded run at that commit, newest first."),
323
+ failed: z
324
+ .array(
325
+ z.object({
326
+ test: z.string().describe("The test, by the id the digest names it with: `crate name`, `file > name`, a node id."),
327
+ line: z.string().optional().describe("The first line of why it failed, where the output said."),
328
+ at: z.number().describe("When the newest run that failed it ended, in milliseconds."),
329
+ }),
330
+ )
331
+ .describe("Each test those runs failed. Empty when they failed none."),
332
+ });
333
+ export type CiLocalMain = z.infer<typeof CiLocalMainSchema>;
305
334
  export const CiMainResponseSchema = z.object({
306
335
  text: z.string().describe("The whole answer in words, as `agents ci` prints it."),
307
336
  branches: z.array(CiMainBranchSchema).describe("Each repository wired to CI, and any main line still failing in one no longer wired."),
337
+ local: z
338
+ .array(CiLocalMainSchema)
339
+ .optional()
340
+ .describe(
341
+ "What this sandbox's own test runs on clean trees at main commits saw fail, newest main commit per repository: suites CI does not run included. Absent from a daemon that keeps no such record.",
342
+ ),
308
343
  });
309
344
  export type CiMainResponse = z.infer<typeof CiMainResponseSchema>;
310
345
  // Re-resolves repo → project + token on every call, so a stale card can't act on a mapping the workspace no longer has.
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+
3
+ // CARRYING ON PAST A LARGE CONTEXT (2026-11-19). A turn that ends by itself because its conversation's context grew
4
+ // large while work is still open ("Steps 8-11 are still open; I stopped because this conversation's context is large")
5
+ // left the next move to the owner: in one audited sandbox the owner restarted three such stops in a row by hand, each
6
+ // within six minutes, and the chain sat idle overnight. The sandbox's loops/context-continue.ts recognises the stop and
7
+ // carries the conversation on in a fresh session seeded with the latest messages, where the work stands, and what the
8
+ // stopped turn said was left, at most this many times in a row. Zero to begin with: a continuation spends the allowance
9
+ // on work nobody is watching, so until the owner raises it the conversation is only told it could carry on.
10
+
11
+ /* When a conversation carries on by itself, with nobody sending it a message: past a large context, once something it
12
+ asked a person for arrives, after a restart. Declared here so settings.ts carries one line for each. */
13
+
14
+ /** The sandbox setting, declared here so settings.ts carries one line for it. */
15
+ export const contextContinuesSetting = z
16
+ .number()
17
+ .int()
18
+ .min(0)
19
+ .max(10)
20
+ .default(0)
21
+ .describe(
22
+ "How many times in a row a conversation carries on by itself, in a fresh session, after its turn stopped because its context had grown large while work was still open. The fresh session opens with the latest messages, where the work stands, and what the stopped turn said was left. A message from anyone else starts the count again. Zero never carries on by itself: the conversation is told it could, and the next move is yours.",
23
+ );
24
+
25
+ // A person answering a need is exactly the moment they want the work to go on (docs/architecture/needs.md), unlike a
26
+ // restart nobody watched, so this one is on to begin with.
27
+ export const continueWhenNeedMetSetting = z
28
+ .boolean()
29
+ .default(true)
30
+ .describe(
31
+ "Whether a conversation carries on by itself once something it asked a person for arrives: a connection made, a secret given, access allowed, a tool built into the image. Off leaves the answer on the conversation's card until someone sends a message.",
32
+ );
33
+
34
+ // A switch rather than a policy: a restart is the one ending with nobody watching it.
35
+ export const autoResumeOnRestartSetting = z
36
+ .boolean()
37
+ .default(false)
38
+ .describe(
39
+ "Whether a turn killed by the sandbox restarting is re-run once it comes back. A switch rather than one of the policies above, because a restart is the one ending with nobody watching it, so there is no in-chat question to answer. Off to begin with: it would spend your allowance on work you are not watching and edit files while you are still waiting for the sandbox to return. Either way the interruption is recorded rather than silently lost. A restart the sandbox traces to memory running out goes by `memoryKillPolicy` instead, whatever this says.",
40
+ );
@@ -0,0 +1,126 @@
1
+ import { z } from "zod";
2
+
3
+ // DOCKER COMPOSE STACKS ON ONE OF THE OWNER'S COMPUTERS: what runs there besides Intentic's own sandboxes, read and
4
+ // driven over the connection the machine already holds open, so a server the owner paired needs no second agent (a
5
+ // Komodo Periphery) to be deployed to. The machine runs `docker compose` itself and checks its own switches: reading and
6
+ // driving a stack takes "Run commands", receiving a repository to deploy takes "Run programs this sandbox sends" too.
7
+ // The daemon relays (_sandbox/sandbox hosts/stacks/device-stacks.ts); the Deployments extension draws the board.
8
+
9
+ // A compose project name as Docker accepts one: lowercase letters, digits, dash and underscore, starting with a letter
10
+ // or a digit. The name is also the folder a deployed stack lives in on the machine, so it is one plain path segment.
11
+ export const StackNameSchema = z
12
+ .string()
13
+ .regex(/^[a-z0-9][a-z0-9_-]{0,62}$/, "lowercase letters, digits, dash and underscore, starting with a letter or digit, at most 63");
14
+ export type StackName = z.infer<typeof StackNameSchema>;
15
+
16
+ // Docker's own container states, plus `unknown` for one a newer engine names that this list does not.
17
+ export const StackContainerStateSchema = z.enum(["running", "restarting", "paused", "exited", "created", "dead", "removing", "unknown"]);
18
+ export type StackContainerState = z.infer<typeof StackContainerStateSchema>;
19
+
20
+ export const StackServiceSchema = z.object({
21
+ // The compose service name (`com.docker.compose.service`).
22
+ service: z.string(),
23
+ container: z.string(),
24
+ image: z.string(),
25
+ state: StackContainerStateSchema,
26
+ // Docker's status prose ("Up 3 hours (healthy)", "Exited (1) 2 minutes ago"), passed through.
27
+ status: z.string(),
28
+ // The healthcheck's verdict, when the service declares one.
29
+ health: z.enum(["healthy", "unhealthy", "starting"]).optional(),
30
+ });
31
+ export type StackService = z.infer<typeof StackServiceSchema>;
32
+
33
+ export const DeviceStackSchema = z.object({
34
+ name: StackNameSchema,
35
+ // Compose's own summary ("running(2)", "exited(1), running(1)"), passed through.
36
+ status: z.string(),
37
+ // The compose files the project was started from, as absolute paths on the machine; empty when compose no longer
38
+ // knows them (a project whose files were deleted still lists its containers).
39
+ configFiles: z.array(z.string()),
40
+ // The project's working directory (`com.docker.compose.project.working_dir`), when its containers record one.
41
+ workingDir: z.string().optional(),
42
+ // Deployed by Intentic into the machine's stacks folder (`root`), rather than started by hand or by another tool.
43
+ managed: z.boolean(),
44
+ // A project whose containers belong to an Intentic sandbox (`dev.intentic.kind`): the Devices view drives those,
45
+ // not a deployments board.
46
+ sandbox: z.boolean(),
47
+ services: z.array(StackServiceSchema),
48
+ });
49
+ export type DeviceStack = z.infer<typeof DeviceStackSchema>;
50
+
51
+ export const DeviceStacksSchema = z.object({
52
+ // Where a stack this sandbox deploys lands on the machine (`<root>/<name>`), as the machine spells its paths.
53
+ root: z.string(),
54
+ stacks: z.array(DeviceStackSchema),
55
+ });
56
+ export type DeviceStacks = z.infer<typeof DeviceStacksSchema>;
57
+
58
+ // `up` applies the compose files as they are (`up -d --remove-orphans`), `pull` fetches newer images and then applies.
59
+ // Nothing here removes a stack or a volume: `down` and `down -v` are a person's to run.
60
+ export const StackOpSchema = z.enum(["up", "restart", "start", "stop", "pull"]);
61
+ export type StackOp = z.infer<typeof StackOpSchema>;
62
+
63
+ // What the machine printed doing it, for the row that asked; a refusal arrives as an error instead.
64
+ export const StackOpResultSchema = z.object({ output: z.string() });
65
+ export type StackOpResult = z.infer<typeof StackOpResultSchema>;
66
+
67
+ export const STACK_LOG_TAIL_DEFAULT = 200;
68
+ export const STACK_LOG_TAIL_MAX = 5000;
69
+ export const StackLogsSchema = z.object({ text: z.string() });
70
+ export type StackLogs = z.infer<typeof StackLogsSchema>;
71
+
72
+ // A compose file inside the deployed repository, relative to its root: forward slashes, no `..`, no leading slash.
73
+ export const ComposeFilePathSchema = z
74
+ .string()
75
+ .min(1)
76
+ .max(300)
77
+ .regex(/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._/-]+$/, "a path inside the repository, like docker-compose.yml or deploy/compose.yaml");
78
+
79
+ // The daemon's route inputs: the device by its card id, then what the machine is asked.
80
+ const DeviceIdSchema = z.string().min(1);
81
+ export const DeviceStacksInputSchema = z.object({ id: DeviceIdSchema });
82
+ export const DeviceStackOpInputSchema = z.object({ id: DeviceIdSchema, name: StackNameSchema, op: StackOpSchema });
83
+ export type DeviceStackOpInput = z.infer<typeof DeviceStackOpInputSchema>;
84
+ export const DeviceStackLogsInputSchema = z.object({
85
+ id: DeviceIdSchema,
86
+ name: StackNameSchema,
87
+ tail: z.coerce.number().int().positive().max(STACK_LOG_TAIL_MAX).optional(),
88
+ });
89
+ export type DeviceStackLogsInput = z.infer<typeof DeviceStackLogsInputSchema>;
90
+
91
+ // Deploy a workspace repository's COMMITTED tree (its HEAD, never the uncommitted edits around it) to a device as a
92
+ // compose stack: the daemon packs it, carries it over the device link, and the machine copies it into `<root>/<name>`
93
+ // and brings it up with `--build`. A `.env` already in that folder is kept and never overwritten or sent: secrets are
94
+ // placed there through an agent turn, where every secret gate applies.
95
+ export const DeviceStackDeployInputSchema = z.object({
96
+ id: DeviceIdSchema,
97
+ name: StackNameSchema,
98
+ // Workspace-relative repository directory, the same `repo` key the rest of the app joins on.
99
+ repo: z.string().min(1).max(500),
100
+ // Absent: the first of compose.yaml, compose.yml, docker-compose.yaml, docker-compose.yml at the repository root.
101
+ composeFile: ComposeFilePathSchema.optional(),
102
+ });
103
+ export type DeviceStackDeployInput = z.infer<typeof DeviceStackDeployInputSchema>;
104
+
105
+ export const DeviceStackDeployResultSchema = z.object({
106
+ stack: StackNameSchema,
107
+ // The folder the stack runs from on the machine.
108
+ path: z.string(),
109
+ // The commit that was deployed, full sha.
110
+ commit: z.string(),
111
+ // What `docker compose up` printed.
112
+ output: z.string(),
113
+ });
114
+ export type DeviceStackDeployResult = z.infer<typeof DeviceStackDeployResultSchema>;
115
+
116
+ // The machine's own tool arguments for a deploy: the folder `stageArtifact` unpacked the bundle into, the stack name,
117
+ // the compose file inside it and the commit, recorded beside the stack.
118
+ export const DeployStackToolArgsSchema = z
119
+ .object({
120
+ source: z.string().min(1),
121
+ name: StackNameSchema,
122
+ composeFile: ComposeFilePathSchema,
123
+ commit: z.string().regex(/^[0-9a-f]{40,64}$/),
124
+ })
125
+ .strict();
126
+ export type DeployStackToolArgs = z.infer<typeof DeployStackToolArgsSchema>;
@@ -197,6 +197,9 @@ export const DeviceFeatureSchema = z.enum([
197
197
  // (2026-11-17) `copyFile`: a file or a folder copied to or from a path the agent names (`devices copy`), held to the
198
198
  // folders and the write switch the file tools are.
199
199
  "file-copy",
200
+ // (2026-11-19) `list_stacks`, `stack_action`, `stack_logs` and `deploy_stack`: Docker compose stacks on the machine,
201
+ // read, driven and deployed to from the Deployments board (schemas/device-stacks.ts).
202
+ "stacks",
200
203
  ]);
201
204
  export type DeviceFeature = z.infer<typeof DeviceFeatureSchema>;
202
205
  export const DEVICE_FEATURE_RESHAPE_LATER: DeviceFeature = "reshape-later";
@@ -213,6 +216,7 @@ export const DEVICE_FEATURE_REACHABLE_WAYS_BACK: DeviceFeature = "reachable-ways
213
216
  export const DEVICE_FEATURE_REACH_NETWORK: DeviceFeature = "reach-network";
214
217
  export const DEVICE_FEATURE_SANDBOX_MOVE: DeviceFeature = "sandbox-move";
215
218
  export const DEVICE_FEATURE_FILE_COPY: DeviceFeature = "file-copy";
219
+ export const DEVICE_FEATURE_STACKS: DeviceFeature = "stacks";
216
220
  // What `ic features --json` answers (_sandbox/ic/src/features.rs, golden/ic-features.json): the optional ops that ic
217
221
  // implements, as strings, since a newer ic's word means nothing to an older agent.
218
222
  export const IcFeaturesAnswerSchema = z.object({ features: z.array(z.string()) });
@@ -82,6 +82,15 @@ export const LoopDocumentSchema = z.object({
82
82
  .record(z.string(), z.unknown())
83
83
  .optional()
84
84
  .describe("The declared answer, for a loop that asked for one, checked against the shape it declared."),
85
+ // A backlog's count, read by the program rather than out of the reason's prose: zero is done whatever `done` says.
86
+ remaining: z
87
+ .number()
88
+ .int()
89
+ .min(0)
90
+ .optional()
91
+ .describe(
92
+ "How many items are still open after this round, when the work is a list (a backlog, failing tests, unfinished steps). Zero means done. Left out when the work is not countable.",
93
+ ),
85
94
  });
86
95
  export type LoopDocument = z.infer<typeof LoopDocumentSchema>;
87
96
  // Bounds a misconfigured loop; one that hasn't converged in 50 rounds is not one round short of it.
@@ -175,6 +184,7 @@ export const LoopIterationSchema = z.object({
175
184
  .optional()
176
185
  .describe("What the check said, in its own words. What a run history is actually read for: why it kept going, and why it stopped."),
177
186
  costUsd: z.number().optional().describe("What the round cost, in dollars."),
187
+ remaining: z.number().int().min(0).optional().describe("How many items the round said were still open, where it counted them."),
178
188
  changed: z.boolean().describe("Whether anything on disk moved. Three unchanged rounds in a row is the shape of a loop that is not working."),
179
189
  sessionId: z.string().optional().describe("The session it ran on, and the way from a history row to a readable record."),
180
190
  });
@@ -8,11 +8,11 @@ import { entryId } from "./internal.js";
8
8
  // it until someone answers, draws it wherever it is waiting, and wakes the conversation when it is met
9
9
  // (docs/architecture/needs.md). Every word on a need is the daemon's except `why`, the agent's own case.
10
10
 
11
- export const NEED_KINDS = ["capability", "secret", "grant", "release", "environment", "automation"] as const;
11
+ export const NEED_KINDS = ["capability", "secret", "grant", "release", "environment", "automation", "instruction"] as const;
12
12
  export const NeedKindSchema = z
13
13
  .enum(NEED_KINDS)
14
14
  .describe(
15
- "What is being asked for: a connection, a secret's value, wider reach, a gated credential, a tool in the image, or an automation to run unattended.",
15
+ "What is being asked for: a connection, a secret's value, wider reach, a gated credential, a tool in the image, an automation to run unattended, or a standing rule written into an AGENTS.md.",
16
16
  );
17
17
  export type NeedKind = z.infer<typeof NeedKindSchema>;
18
18
 
@@ -176,6 +176,22 @@ export const AutomationNeedSchema = z.object({
176
176
  });
177
177
  export type AutomationNeed = z.infer<typeof AutomationNeedSchema>;
178
178
 
179
+ // The longest rule one proposal adds: a sentence or two the owner said, never a document. Every turn pays for AGENTS.md.
180
+ export const INSTRUCTION_MAX = 1000;
181
+
182
+ // A rule the owner stated once ("from now on…", "remember…") that an agent proposes keeping in an AGENTS.md, which the
183
+ // daemon composes into every later conversation's instructions (2026-11-19, the shinobi-society audit: one preference
184
+ // restated in six conversations, rules given in replies that died with them). Nothing is written until a person approves;
185
+ // the yes appends `text` to the file on the main tree, exactly as `diff` shows it.
186
+ export const InstructionNeedSchema = z.object({
187
+ kind: z.literal("instruction"),
188
+ file: z.string().min(1).describe("The AGENTS.md it goes into, relative to the workspace root: `AGENTS.md`, or a repository's `<repo>/AGENTS.md`."),
189
+ text: z.string().min(1).max(INSTRUCTION_MAX).describe("The rule as it would be added, word for word."),
190
+ diff: z.string().describe("The change as a unified diff against the file as it stood when proposed: what approving writes."),
191
+ creates: z.boolean().optional().describe("The file does not exist yet: approving creates it holding this rule alone."),
192
+ });
193
+ export type InstructionNeed = z.infer<typeof InstructionNeedSchema>;
194
+
179
195
  export const NeedSubjectSchema = z
180
196
  .discriminatedUnion("kind", [
181
197
  CapabilityNeedSchema,
@@ -184,6 +200,7 @@ export const NeedSubjectSchema = z
184
200
  ReleaseNeedSchema,
185
201
  EnvironmentNeedSchema,
186
202
  AutomationNeedSchema,
203
+ InstructionNeedSchema,
187
204
  ])
188
205
  .describe("What exactly is asked for.");
189
206
  export type NeedSubject = z.infer<typeof NeedSubjectSchema>;
@@ -241,6 +258,12 @@ export const NeedAskSchema = z.discriminatedUnion("kind", [
241
258
  // Everything the agent proposes, switched on; the daemon checks it as the Automations page would save it, runs a
242
259
  // source's check once for the card, and saves it only on a person's approval.
243
260
  z.object({ kind: z.literal("automation"), automation: AutomationSchema }),
261
+ // The file and the words; the daemon checks the file is an AGENTS.md in the workspace and draws the diff itself.
262
+ z.object({
263
+ kind: z.literal("instruction"),
264
+ file: z.string().min(1).max(400).describe("The AGENTS.md, relative to the workspace root."),
265
+ text: z.string().trim().min(1).max(INSTRUCTION_MAX).describe("The rule, as it should read in the file."),
266
+ }),
244
267
  ]);
245
268
  export type NeedAsk = z.infer<typeof NeedAskSchema>;
246
269
 
@@ -0,0 +1,37 @@
1
+ import { z } from "zod";
2
+
3
+ // PROCEED WITHOUT ASKING (2026-11-19). In the shinobi-society audit 12 of the owner's messages were a bare go-ahead ("Go
4
+ // for all of it", "1. Yes.") arriving 5 to 47 minutes after an agent had stopped to propose, overnight turns stopped to
5
+ // ask while the owner slept, and parents wrote "the owner is asleep, don't ask" into the prompts of the agents they
6
+ // started. On, every turn is told plainly to carry on with its own recommendation and to stop only before something
7
+ // destructive or outward-facing (the daemon's agent/prompt/guidance.ts, entry `proceed`). Words, not a gate: whatever
8
+ // stops a turn regardless (a permission card, a held command, a payment, a credential release) still stops it. Off by
9
+ // default, which leaves every turn as it was. Night hours, while they are in force, say what a question gets instead.
10
+
11
+ /** The sandbox setting, declared here so settings.ts carries one line for it. */
12
+ export const proceedWithoutAskingSetting = z
13
+ .boolean()
14
+ .default(false)
15
+ .describe(
16
+ "Whether agents carry on with their own recommendation instead of stopping to propose or to ask for a go-ahead. They still stop before anything destructive (deleting work or data that cannot be recovered, rewriting shared history) or outward-facing (publishing, sending a message as you, a payment, a deploy, a push), and end with what they decided so you can overturn it. Subagents follow the conversation that started them. Any one conversation can say otherwise. While night hours are in force, they decide instead.",
17
+ );
18
+
19
+ /** A conversation's own answer, as its card carries it; absent where it follows the sandbox (or the conversation that started it). */
20
+ export const proceedOverride = z
21
+ .boolean()
22
+ .optional()
23
+ .describe(
24
+ "This conversation's own answer to whether it proceeds without asking for a go-ahead. Absent means it follows the conversation that started it, if another one did, else the sandbox-wide setting.",
25
+ );
26
+
27
+ /** POST /agents/{id}/proceed: one conversation's own answer, or null to follow again. */
28
+ export const AgentProceedSchema = z.object({
29
+ id: z.string().min(1).describe("Which conversation."),
30
+ proceed: z
31
+ .boolean()
32
+ .nullable()
33
+ .describe(
34
+ "Whether it carries on with its own recommendation instead of stopping for a go-ahead, from its next turn. Null clears its own answer, so it follows the conversation that started it or the sandbox-wide setting again.",
35
+ ),
36
+ });
37
+ export type AgentProceed = z.infer<typeof AgentProceedSchema>;
@@ -0,0 +1,91 @@
1
+ import { z } from "zod";
2
+ import { AccountStateSchema, AccountUsageSchema } from "./plan-limits.js";
3
+ import { ModelCooldownSchema, ProviderRefusalSchema, SwitchOffsSchema } from "./refusals.js";
4
+
5
+ /* WHAT ONE PROVIDER'S ACCOUNTS CAN SERVE, AS THE DAEMON JUDGED IT, IN ONE MESSAGE. Before 2026-11-19 a window assembled
6
+ the same picture from four reads that arrived apart (each provider's account rows, the translator's credentials, every
7
+ reading pushed one account at a time, the refusals on file) and judged it with its own clock: two windows, or a window
8
+ and the daemon, could hold different halves of it at once, and nothing said when the picture would change by the clock
9
+ alone. This is the picture whole: every fact the serviceability rule (models/plan-pools.ts serviceStates) judged, each
10
+ reading as it stood at `judgedAt`, the verdict it reached with no model named, where a turn naming no account would run,
11
+ and the next instant the clock alone changes any of it (`validUntil`), at which the daemon judges again and sends the
12
+ next one. A window asking about one model runs the same rule over these same facts, at the sandbox's clock. */
13
+
14
+ /** One account as the rule read it, and its verdict with no model named. */
15
+ export const CapacityAccountSchema = z.object({
16
+ account: z.string().describe("The daemon's key for the account: a native account's id, a routed credential's auth-file name."),
17
+ label: z.string().optional().describe("How the account is named to a person: its label, a routed credential's address."),
18
+ needsReauth: z.boolean().optional().describe("Its sign-in was refused and has to be renewed on this sandbox."),
19
+ detail: z.string().optional().describe("Why the sign-in needs renewing, in the provider's words, where it gave some."),
20
+ seatRefusal: z.string().optional().describe("Its organisation took its seat away, in the provider's words."),
21
+ cooling: z
22
+ .object({ until: z.number().optional(), reason: z.string().optional(), verify: z.string().optional() })
23
+ .optional()
24
+ .describe("The translator's bench over the whole credential (TranslatorAccount.cooling)."),
25
+ cooldowns: z.array(ModelCooldownSchema).optional().describe("The translator's benches of the credential on single models."),
26
+ usage: AccountUsageSchema.optional().describe("Its plan-limit reading as it stood at `judgedAt`: a window past its reset already lapsed. Absent: unmeasured."),
27
+ models: z.array(z.string()).optional().describe("The model ids its plan runs, where its source can say. Absent: unknown, never none."),
28
+ state: AccountStateSchema.describe("The rule's verdict on it at `judgedAt`, with no model named."),
29
+ flapping: z.literal(true).optional().describe("Its organisation switched it off twice or more this week: a pick ranks it behind every steady account of its tier."),
30
+ });
31
+ export type CapacityAccount = z.infer<typeof CapacityAccountSchema>;
32
+
33
+ /** A provider failing turns for reasons no account's allowance explains: down, or throttling every request for a while. */
34
+ export const ProviderDegradedSchema = z.object({
35
+ cause: z
36
+ .enum(["outage", "throttle"])
37
+ .describe("`outage`: the provider is failing requests (5xx, overloaded, unreachable). `throttle`: it is turning requests away for a moment with a rate limit no allowance explains."),
38
+ retryAt: z.number().describe("When the sandbox tries the provider again, in epoch milliseconds."),
39
+ attempt: z.number().int().optional().describe("How many retries have gone out since it started failing."),
40
+ });
41
+ export type ProviderDegraded = z.infer<typeof ProviderDegradedSchema>;
42
+
43
+ export const ProviderCapacitySchema = z.object({
44
+ provider: z.string().describe("Whose accounts these are."),
45
+ seq: z
46
+ .number()
47
+ .int()
48
+ .describe("Rises with every capacity the daemon sends, across providers, since it started: a window keeps the higher of two it holds for one provider."),
49
+ judgedAt: z.number().describe("The sandbox's clock when these were judged, in epoch milliseconds."),
50
+ validUntil: z
51
+ .number()
52
+ .optional()
53
+ .describe(
54
+ "The next instant the clock alone changes anything here (a window resetting, a refusal's instant, a bench ending, a switch-off ageing out), in epoch milliseconds; the daemon sends the next capacity then. Absent: nothing here changes with time.",
55
+ ),
56
+ accounts: z.array(CapacityAccountSchema).describe("Every connected account, in the provider's own order."),
57
+ refusals: z.array(ProviderRefusalSchema).describe("Every refusal on file for the provider, as the ledger serves it."),
58
+ switchOffs: SwitchOffsSchema.optional().describe("Each account's entitlement switch-offs within the week, the facts `flapping` is judged from."),
59
+ placement: z.string().optional().describe("The account a turn naming no account and no model would run on now, where the provider has a choice to make."),
60
+ degraded: ProviderDegradedSchema.optional().describe("Present while the provider itself is failing or throttling turns."),
61
+ });
62
+ export type ProviderCapacity = z.infer<typeof ProviderCapacitySchema>;
63
+
64
+ export const CapacitySnapshotSchema = z.object({
65
+ providers: z.array(ProviderCapacitySchema).describe("Every provider with an account connected, or anything on file."),
66
+ });
67
+ export type CapacitySnapshot = z.infer<typeof CapacitySnapshotSchema>;
68
+
69
+ /** Where a turn on one model would run, asked of the daemon's one placement (usage.placement). */
70
+ export const PlacementQuerySchema = z.object({
71
+ provider: z.string().min(1).describe("Which provider."),
72
+ model: z.string().optional().describe("The model the turn names; absent for a turn naming none."),
73
+ loop: z
74
+ .string()
75
+ .min(1)
76
+ .optional()
77
+ .describe(
78
+ "The loop the turn runs on (an AgentHarness: `native` or a loop the provider offers), which decides which of its accounts can carry it. Absent, or one the daemon does not know: the provider's default loop.",
79
+ ),
80
+ });
81
+ export const PlacementSchema = z.object({
82
+ account: z.string().optional().describe("The account the daemon would run that turn on now. Absent: the provider has no account to choose, or chooses itself."),
83
+ judgedAt: z.number().describe("The sandbox's clock when it was asked, in epoch milliseconds."),
84
+ narrowed: z
85
+ .literal(true)
86
+ .optional()
87
+ .describe(
88
+ "The answer is the turn the asker would send: placed on the loop asked about, among the accounts the asker may run on (Access ▸ People). Absent from a daemon from before `loop`, whose answer is the sandbox-wide pick on the default loop.",
89
+ ),
90
+ });
91
+ export type Placement = z.infer<typeof PlacementSchema>;