@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.
- package/dist/contracts/ci.contract.d.ts +30 -0
- package/dist/contracts/ci.contract.d.ts.map +1 -1
- package/dist/contracts/ci.contract.js +10 -1
- package/dist/contracts/ci.contract.js.map +1 -1
- package/dist/contracts/device.contract.d.ts +46 -0
- package/dist/contracts/device.contract.d.ts.map +1 -1
- package/dist/contracts/device.contract.js +2 -0
- package/dist/contracts/device.contract.js.map +1 -1
- package/dist/contracts/offload.contract.d.ts +51 -0
- package/dist/contracts/offload.contract.d.ts.map +1 -1
- package/dist/contracts/offload.contract.js +3 -3
- package/dist/contracts/offload.contract.js.map +1 -1
- package/dist/contracts/runner.contract.d.ts +308 -246
- package/dist/contracts/runner.contract.d.ts.map +1 -1
- package/dist/contracts/settings.contract.d.ts +2 -0
- package/dist/contracts/settings.contract.d.ts.map +1 -1
- package/dist/events/agent-events.d.ts +5 -0
- package/dist/events/agent-events.d.ts.map +1 -1
- package/dist/events/agent-events.js +2 -1
- package/dist/events/agent-events.js.map +1 -1
- package/dist/events/requests.js +1 -1
- package/dist/events/requests.js.map +1 -1
- package/dist/events/sandbox-notice.d.ts +12 -0
- package/dist/events/sandbox-notice.d.ts.map +1 -1
- package/dist/events/sandbox-notice.js +5 -1
- package/dist/events/sandbox-notice.js.map +1 -1
- package/dist/models/account-moves.d.ts.map +1 -1
- package/dist/models/account-moves.js +10 -2
- package/dist/models/account-moves.js.map +1 -1
- package/dist/models/plan-pools.d.ts +3 -1
- package/dist/models/plan-pools.d.ts.map +1 -1
- package/dist/models/plan-pools.js +26 -3
- package/dist/models/plan-pools.js.map +1 -1
- package/dist/protocol/doors/runner-protocol.d.ts +42 -0
- package/dist/protocol/doors/runner-protocol.d.ts.map +1 -1
- package/dist/protocol/doors/runner-protocol.js +23 -0
- package/dist/protocol/doors/runner-protocol.js.map +1 -1
- package/dist/protocol/raw/raw-json-routes.d.ts +4 -0
- package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-routes.d.ts +8 -0
- package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-routes.js +2 -0
- package/dist/protocol/raw/raw-routes.js.map +1 -1
- package/dist/schemas/ci.d.ts +69 -0
- package/dist/schemas/ci.d.ts.map +1 -1
- package/dist/schemas/ci.js +30 -0
- package/dist/schemas/ci.js.map +1 -1
- package/dist/schemas/device-files.d.ts +71 -0
- package/dist/schemas/device-files.d.ts.map +1 -0
- package/dist/schemas/device-files.js +53 -0
- package/dist/schemas/device-files.js.map +1 -0
- package/dist/schemas/devices.d.ts.map +1 -1
- package/dist/schemas/devices.js.map +1 -1
- package/dist/schemas/hosts.d.ts +3 -0
- package/dist/schemas/hosts.d.ts.map +1 -1
- package/dist/schemas/hosts.js +3 -0
- package/dist/schemas/hosts.js.map +1 -1
- package/dist/schemas/night-hours.d.ts +5 -1
- package/dist/schemas/night-hours.d.ts.map +1 -1
- package/dist/schemas/night-hours.js +24 -2
- package/dist/schemas/night-hours.js.map +1 -1
- package/dist/schemas/offload.d.ts +40 -0
- package/dist/schemas/offload.d.ts.map +1 -1
- package/dist/schemas/offload.js +21 -0
- package/dist/schemas/offload.js.map +1 -1
- package/dist/schemas/providers/plan-limits.d.ts +1 -0
- package/dist/schemas/providers/plan-limits.d.ts.map +1 -1
- package/dist/schemas/providers/plan-limits.js +5 -1
- package/dist/schemas/providers/plan-limits.js.map +1 -1
- package/dist/schemas/settings.d.ts +2 -0
- package/dist/schemas/settings.d.ts.map +1 -1
- package/dist/schemas/settings.js +2 -2
- package/dist/schemas/settings.js.map +1 -1
- package/dist/state/definition.d.ts +4 -0
- package/dist/state/definition.d.ts.map +1 -1
- package/dist/text/land-rows.d.ts +7 -4
- package/dist/text/land-rows.d.ts.map +1 -1
- package/dist/text/land-rows.js +8 -4
- package/dist/text/land-rows.js.map +1 -1
- package/dist/text/transcript-fold.d.ts.map +1 -1
- package/dist/text/transcript-fold.js +6 -4
- package/dist/text/transcript-fold.js.map +1 -1
- package/package.json +5 -5
- package/src/contracts/ci.contract.ts +13 -0
- package/src/contracts/device.contract.ts +5 -0
- package/src/contracts/offload.contract.ts +3 -2
- package/src/events/agent-events.ts +3 -1
- package/src/events/requests.ts +1 -1
- package/src/events/sandbox-notice.ts +13 -2
- package/src/models/account-moves.test.ts +9 -1
- package/src/models/account-moves.ts +22 -7
- package/src/models/plan-pools.test.ts +57 -20
- package/src/models/plan-pools.ts +48 -8
- package/src/protocol/doors/runner-protocol.ts +42 -2
- package/src/protocol/raw/raw-routes.ts +5 -0
- package/src/schemas/automations.ts +3 -3
- package/src/schemas/ci.ts +42 -0
- package/src/schemas/device-files.ts +90 -0
- package/src/schemas/devices.ts +5 -4
- package/src/schemas/hosts.ts +15 -3
- package/src/schemas/night-hours.test.ts +32 -1
- package/src/schemas/night-hours.ts +46 -3
- package/src/schemas/offload.ts +39 -2
- package/src/schemas/providers/plan-limits.ts +7 -1
- package/src/schemas/settings.ts +2 -2
- package/src/text/land-rows.ts +18 -6
- package/src/text/transcript-fold.test.ts +17 -0
- package/src/text/transcript-fold.ts +8 -5
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ARTIFACT_CHUNK_BYTES } from "./device-artifacts.js";
|
|
3
|
+
|
|
4
|
+
// A FILE OR A FOLDER COPIED BETWEEN THIS SANDBOX AND A CONNECTED COMPUTER (`devices copy`), either way, to a path the
|
|
5
|
+
// agent names. 2026-11-17, the shinobi-society audit: to move a 12 MB tarball or a built binary, agents ran `docker exec …
|
|
6
|
+
// && docker cp …` on rog through run_command, which works only where the sandbox's own container is on that very machine,
|
|
7
|
+
// needs its container name, and passes every guard by. read_file and write_file carry text alone, through the model.
|
|
8
|
+
// The CLI reads and writes the bytes in the agent's own shell (its view of /work), the daemon relays them over the device
|
|
9
|
+
// link in chunks through `copyFile`, and the machine checks every chunk against the same rules as its file tools: the
|
|
10
|
+
// folders it may touch for both ways, and "Create and change files" (`write`) for a copy onto it.
|
|
11
|
+
|
|
12
|
+
// One chunk's decoded size: the artifact push's, which a tunnel already carries.
|
|
13
|
+
export const FILE_COPY_CHUNK_BYTES = ARTIFACT_CHUNK_BYTES;
|
|
14
|
+
// The most one copy carries, decoded: a thousand chunks, minutes on a good link. Anything bigger is a disk image or a
|
|
15
|
+
// backup, which a command on the computer moves better than a relay through the sandbox.
|
|
16
|
+
export const FILE_COPY_MAX_BYTES = 2 * 1024 * 1024 * 1024;
|
|
17
|
+
// How long packing or unpacking a folder may take on the computer; the daemon waits that plus the device's answer.
|
|
18
|
+
export const FILE_COPY_TAR_TIMEOUT_MS = 10 * 60_000;
|
|
19
|
+
|
|
20
|
+
const Sha256Schema = z.string().regex(/^[0-9a-f]{64}$/, "a lowercase hex sha256");
|
|
21
|
+
const CopyIdSchema = z.string().regex(/^[0-9a-f]{32}$/);
|
|
22
|
+
// A path on the computer as the agent wrote it; the machine resolves it, links and all, against its folders.
|
|
23
|
+
const DevicePathSchema = z.string().min(1).max(4096);
|
|
24
|
+
// The source's own name, which a copy into a folder that exists lands under: one path segment, never `.` or `..`.
|
|
25
|
+
export const CopyNameSchema = z
|
|
26
|
+
.string()
|
|
27
|
+
.min(1)
|
|
28
|
+
.max(255)
|
|
29
|
+
.refine((name) => !/[/\\\0]/.test(name) && name !== "." && name !== "..", "a plain file or folder name");
|
|
30
|
+
// `file` is one file; `tar` a folder, packed by whichever side holds it and unpacked by the other.
|
|
31
|
+
export const CopyKindSchema = z.enum(["file", "tar"]);
|
|
32
|
+
export type CopyKind = z.infer<typeof CopyKindSchema>;
|
|
33
|
+
const ChunkDataSchema = z.string().max(Math.ceil(FILE_COPY_CHUNK_BYTES / 3) * 4);
|
|
34
|
+
|
|
35
|
+
export const CopyFileSchema = z.discriminatedUnion("op", [
|
|
36
|
+
// Onto the computer: where it will land (`path`, or `path/name` when `path` is a folder that exists), refused when
|
|
37
|
+
// that is taken unless `overwrite`. `executable` carries the sandbox file's x bit to a POSIX computer. `probe` asks
|
|
38
|
+
// every question and opens nothing, so a refusal is read before the first byte is sent.
|
|
39
|
+
z
|
|
40
|
+
.object({
|
|
41
|
+
op: z.literal("put-open"),
|
|
42
|
+
copy: CopyIdSchema,
|
|
43
|
+
path: DevicePathSchema,
|
|
44
|
+
name: CopyNameSchema,
|
|
45
|
+
kind: CopyKindSchema,
|
|
46
|
+
size: z.int().nonnegative().max(FILE_COPY_MAX_BYTES),
|
|
47
|
+
overwrite: z.boolean(),
|
|
48
|
+
executable: z.boolean(),
|
|
49
|
+
probe: z.boolean().optional(),
|
|
50
|
+
})
|
|
51
|
+
.strict(),
|
|
52
|
+
// One piece, at its offset; pieces arrive in order and a gap is refused.
|
|
53
|
+
z.object({ op: z.literal("put-chunk"), copy: CopyIdSchema, offset: z.int().nonnegative(), data: ChunkDataSchema }).strict(),
|
|
54
|
+
// The last word: the machine checks size and hash, then puts it in place. A mismatch throws the copy away.
|
|
55
|
+
z.object({ op: z.literal("put-commit"), copy: CopyIdSchema, sha256: Sha256Schema }).strict(),
|
|
56
|
+
// Off the computer: a file as it is, a folder packed as one tar first.
|
|
57
|
+
z.object({ op: z.literal("get-open"), copy: CopyIdSchema, path: DevicePathSchema }).strict(),
|
|
58
|
+
// The piece at `offset`, in order.
|
|
59
|
+
z.object({ op: z.literal("get-chunk"), copy: CopyIdSchema, offset: z.int().nonnegative() }).strict(),
|
|
60
|
+
// A copy finished or given up on: a put's part file is deleted, a get's handle and packed tar let go.
|
|
61
|
+
z.object({ op: z.literal("close"), copy: CopyIdSchema }).strict(),
|
|
62
|
+
]);
|
|
63
|
+
export type CopyFile = z.infer<typeof CopyFileSchema>;
|
|
64
|
+
|
|
65
|
+
export const CopyFileResultSchema = z.object({
|
|
66
|
+
// Where it is on the computer: where a put lands or landed, what a get reads.
|
|
67
|
+
path: z.string().optional(),
|
|
68
|
+
// A get-open's: what is coming, how big, under what name, and whether a POSIX computer has it executable.
|
|
69
|
+
kind: CopyKindSchema.optional(),
|
|
70
|
+
size: z.int().nonnegative().optional(),
|
|
71
|
+
name: z.string().optional(),
|
|
72
|
+
executable: z.boolean().optional(),
|
|
73
|
+
// How many bytes of a put the machine holds, answered to every put-chunk.
|
|
74
|
+
received: z.int().nonnegative().optional(),
|
|
75
|
+
// A get-chunk's bytes, base64.
|
|
76
|
+
data: ChunkDataSchema.optional(),
|
|
77
|
+
// On a get's last chunk: the hash of everything it served, which the daemon checks what it relayed against.
|
|
78
|
+
sha256: Sha256Schema.optional(),
|
|
79
|
+
});
|
|
80
|
+
export type CopyFileResult = z.infer<typeof CopyFileResultSchema>;
|
|
81
|
+
|
|
82
|
+
// What `POST /devices/{name}/files` answers the CLI; a GET answers the bytes, with these in `x-intentic-copy-*` headers.
|
|
83
|
+
export const CopiedFileSchema = z.object({
|
|
84
|
+
device: z.string(),
|
|
85
|
+
path: z.string(),
|
|
86
|
+
kind: CopyKindSchema,
|
|
87
|
+
size: z.int().nonnegative(),
|
|
88
|
+
sha256: Sha256Schema,
|
|
89
|
+
});
|
|
90
|
+
export type CopiedFile = z.infer<typeof CopiedFileSchema>;
|
package/src/schemas/devices.ts
CHANGED
|
@@ -209,10 +209,11 @@ export const DeviceFlowLineSchema = z.discriminatedUnion("kind", [
|
|
|
209
209
|
export type DeviceFlowLine = z.infer<typeof DeviceFlowLineSchema>;
|
|
210
210
|
// Every op stops the resident process mid-command; a stream ending with no terminal frame is normal, not a failure, and
|
|
211
211
|
// confirmation is the version moving on the next poll. `restart` is just a bare `intentic-machine run`.
|
|
212
|
-
// `forget-unreachable` drops the machine's links to sandboxes
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
212
|
+
// `forget-unreachable` drops the machine's links to sandboxes the platform has said no longer exist (the edge's final
|
|
213
|
+
// `unknown-sandbox`, which the machine's link marks as `goneSince`) — never one that is merely down, since it is offered
|
|
214
|
+
// on every sandbox's page and a sibling restarting or asleep must keep this machine, and never the link carrying the
|
|
215
|
+
// request, which is by definition answering. Before 2026-11-17 it took any link that had failed twenty dials (about
|
|
216
|
+
// eight minutes), and one sandbox's button disconnected the machine from another.
|
|
216
217
|
export const DeviceAgentOpSchema = z.enum(["upgrade", "restart", "forget-unreachable"]);
|
|
217
218
|
export type DeviceAgentOp = z.infer<typeof DeviceAgentOpSchema>;
|
|
218
219
|
export const DeviceAgentFlowSchema = z.strictObject({ op: DeviceAgentOpSchema });
|
package/src/schemas/hosts.ts
CHANGED
|
@@ -76,9 +76,11 @@ export const DeviceFactsSchema = z.object({
|
|
|
76
76
|
wsl: WslEnvironmentSchema.optional(),
|
|
77
77
|
// Windows only: the distros `wsl -l -q` lists, the names `run_command`'s `in: "wsl:<name>"` accepts.
|
|
78
78
|
wslDistros: z.array(z.string()).optional(),
|
|
79
|
-
// What this machine's agent is holding links to, and how
|
|
80
|
-
//
|
|
81
|
-
//
|
|
79
|
+
// What this machine's agent is holding links to, and how many of them are to sandboxes the platform has said no
|
|
80
|
+
// longer exist (since 2026-11-17; before, any link that had failed twenty dials, a sandbox merely down included).
|
|
81
|
+
// COUNTS AND AN AGE ONLY: the rest are other sandboxes' addresses, and a sandbox has no business learning its
|
|
82
|
+
// siblings'. Absent from an agent older than this field, which is why "none unreachable" is not the same value as
|
|
83
|
+
// "did not say".
|
|
82
84
|
links: z.object({ total: z.number(), unreachable: z.number(), unreachableSince: z.number().optional() }).optional(),
|
|
83
85
|
// Which of the optional ops this agent AND the `ic` it drives implement (DeviceFeatureSchema), for a page to offer
|
|
84
86
|
// only what works and for the daemon to refuse an op before sending it. Strings on the wire, so a newer agent's
|
|
@@ -192,6 +194,9 @@ export const DeviceFeatureSchema = z.enum([
|
|
|
192
194
|
// (2026-11-11) The `move-prepare`, `move-out` and `move-in` ops: an agent that has them driving an ic that says
|
|
193
195
|
// `sandbox-move` (`ic sandbox move-out` / `move-in`), so a sandbox can be carried to another of the owner's computers.
|
|
194
196
|
"sandbox-move",
|
|
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
|
+
// folders and the write switch the file tools are.
|
|
199
|
+
"file-copy",
|
|
195
200
|
]);
|
|
196
201
|
export type DeviceFeature = z.infer<typeof DeviceFeatureSchema>;
|
|
197
202
|
export const DEVICE_FEATURE_RESHAPE_LATER: DeviceFeature = "reshape-later";
|
|
@@ -207,6 +212,7 @@ export const DEVICE_FEATURE_EGRESS: DeviceFeature = "egress";
|
|
|
207
212
|
export const DEVICE_FEATURE_REACHABLE_WAYS_BACK: DeviceFeature = "reachable-ways-back";
|
|
208
213
|
export const DEVICE_FEATURE_REACH_NETWORK: DeviceFeature = "reach-network";
|
|
209
214
|
export const DEVICE_FEATURE_SANDBOX_MOVE: DeviceFeature = "sandbox-move";
|
|
215
|
+
export const DEVICE_FEATURE_FILE_COPY: DeviceFeature = "file-copy";
|
|
210
216
|
// What `ic features --json` answers (_sandbox/ic/src/features.rs, golden/ic-features.json): the optional ops that ic
|
|
211
217
|
// implements, as strings, since a newer ic's word means nothing to an older agent.
|
|
212
218
|
export const IcFeaturesAnswerSchema = z.object({ features: z.array(z.string()) });
|
|
@@ -245,6 +251,12 @@ export const windowsPathOf = (distro: string, linuxPath: string): string => `\\\
|
|
|
245
251
|
// own — but the owner connected a computer, not a shell, so the grant, the row and the tools are the machine's.
|
|
246
252
|
export const HOST_NATIVE_ENVIRONMENT = "native";
|
|
247
253
|
|
|
254
|
+
// What a device card's status says of a machine that is paired and holds no socket right now (the device handler's
|
|
255
|
+
// `awayHint`, beside a `pending` state). Shared so the editor can read it as offline, which waits on the machine, rather
|
|
256
|
+
// than as a setup to finish, which a fresh pairing would: a machine whose sandbox had restarted read "needs setup" with a
|
|
257
|
+
// Connect button beside it (2026-11-17).
|
|
258
|
+
export const DEVICE_AWAY_DETAIL = "the device is offline";
|
|
259
|
+
|
|
248
260
|
// Which environment a machine is describing when it connects: the distro by the name WSL registered (what `wsl -l -q`
|
|
249
261
|
// prints and `in: "wsl:<name>"` takes), or the metal. Facts arrive at connect and no scope withholds them, so this is
|
|
250
262
|
// always answerable — unlike `environmentOf` (devices.ts), which weighs a report too and may hold no evidence at all.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { asZone, UTC } from "../time/zone.js";
|
|
2
|
-
import { NightHoursSchema, nightLength, withinNight } from "./night-hours.js";
|
|
2
|
+
import { morningAfter, nightAt, nightByHandUntil, NightHoursSchema, nightLength, withinNight } from "./night-hours.js";
|
|
3
3
|
|
|
4
4
|
// The window is read on a named clock, so every instant below is built in that zone's own terms.
|
|
5
5
|
const WARSAW = asZone("Europe/Warsaw")!;
|
|
@@ -41,6 +41,37 @@ test("read on the sandbox's own clock, summer and winter alike, not the containe
|
|
|
41
41
|
expect(withinNight(night, WARSAW, at("2026-11-05T06:30:00Z"))).toBe(false);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
+
test("the morning after an instant is the next time the clock reads `to`, today's or tomorrow's", () => {
|
|
45
|
+
expect(morningAfter({ to: "07:00" }, UTC, at("2026-11-04T21:40:00Z"))).toBe(at("2026-11-05T07:00:00Z"));
|
|
46
|
+
expect(morningAfter({ to: "07:00" }, UTC, at("2026-11-05T02:00:00Z"))).toBe(at("2026-11-05T07:00:00Z"));
|
|
47
|
+
// `to` itself is already the morning: the one after it is a day away.
|
|
48
|
+
expect(morningAfter({ to: "07:00" }, UTC, at("2026-11-05T07:00:00Z"))).toBe(at("2026-11-06T07:00:00Z"));
|
|
49
|
+
// On the sandbox's clock: 07:00 in Warsaw is 06:00 UTC in winter, 05:00 UTC in summer.
|
|
50
|
+
expect(morningAfter({ to: "07:00" }, WARSAW, at("2026-11-04T21:40:00Z"))).toBe(at("2026-11-05T06:00:00Z"));
|
|
51
|
+
expect(morningAfter({ to: "07:00" }, WARSAW, at("2026-07-04T21:40:00Z"))).toBe(at("2026-07-05T05:00:00Z"));
|
|
52
|
+
// Across the October changeover the clock goes back an hour overnight; the morning is still 07:00 on the wall.
|
|
53
|
+
expect(morningAfter({ to: "07:00" }, WARSAW, at("2026-10-24T20:00:00Z"))).toBe(at("2026-10-25T06:00:00Z"));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("a night begun by hand lasts until that morning, whatever the hours or the switch say", () => {
|
|
57
|
+
const hours = NightHoursSchema.parse({ on: false, asleepSince: at("2026-11-04T21:40:00Z") });
|
|
58
|
+
expect(nightByHandUntil(hours, UTC, at("2026-11-04T21:40:00Z"))).toBe(at("2026-11-05T07:00:00Z"));
|
|
59
|
+
expect(nightAt(hours, UTC, at("2026-11-04T22:00:00Z"))).toBe(true);
|
|
60
|
+
expect(nightAt(hours, UTC, at("2026-11-05T06:59:00Z"))).toBe(true);
|
|
61
|
+
expect(nightAt(hours, UTC, at("2026-11-05T07:00:00Z"))).toBe(false);
|
|
62
|
+
// Read a minute behind the press (a fast browser, a clock that ticks by the minute), it has begun all the same.
|
|
63
|
+
expect(nightAt(hours, UTC, at("2026-11-04T21:39:00Z"))).toBe(true);
|
|
64
|
+
// Long before the press it was an ordinary evening, and the next evening is one again.
|
|
65
|
+
expect(nightAt(hours, UTC, at("2026-11-04T21:00:00Z"))).toBe(false);
|
|
66
|
+
expect(nightAt(hours, UTC, at("2026-11-05T23:30:00Z"))).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("without a night begun by hand, it is night only inside switched-on hours", () => {
|
|
70
|
+
expect(nightAt(NightHoursSchema.parse({ on: true }), UTC, at("2026-11-04T23:30:00Z"))).toBe(true);
|
|
71
|
+
expect(nightAt(NightHoursSchema.parse({ on: false }), UTC, at("2026-11-04T23:30:00Z"))).toBe(false);
|
|
72
|
+
expect(nightByHandUntil(NightHoursSchema.parse({ on: true }), UTC, at("2026-11-04T23:30:00Z"))).toBeUndefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
44
75
|
test("its length is said in minutes across midnight", () => {
|
|
45
76
|
expect(nightLength({ from: "23:00", to: "07:00" })).toBe(8 * 60);
|
|
46
77
|
expect(nightLength({ from: "01:30", to: "09:15" })).toBe(7 * 60 + 45);
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Read on the sandbox's own clock (`timezone`, the zone every wall-clock rule here is meant in), and only in force while
|
|
6
6
|
// nobody is at the editor: someone up past their night's start and at a screen is asked as on any other evening.
|
|
7
|
+
//
|
|
8
|
+
// A night can also be begun by hand (`asleepSince`, the Agents board's moon), for an evening the owner goes to bed
|
|
9
|
+
// early: from that press to the next `to` it is night as surely as inside the window, the editor rule included.
|
|
7
10
|
|
|
8
11
|
import { z } from "zod";
|
|
9
|
-
import type
|
|
12
|
+
import { civilDayIn, nextDayStartIn, wallClockInstant, type Zone } from "../time/zone.js";
|
|
10
13
|
|
|
11
14
|
/** A time of day on a wall clock, as `HH:MM` from 00:00 to 23:59. */
|
|
12
15
|
export const ClockTimeSchema = z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "A time of day as HH:MM, 00:00 to 23:59.");
|
|
@@ -23,12 +26,24 @@ export const NightHoursSchema = z.object({
|
|
|
23
26
|
on: z
|
|
24
27
|
.boolean()
|
|
25
28
|
.default(false)
|
|
26
|
-
.describe("Whether the
|
|
29
|
+
.describe("Whether the night comes by itself, every day at these hours. Off, every question waits for an answer, whatever the hour, except on a night you begin by hand (`asleepSince`)."),
|
|
27
30
|
from: ClockTimeSchema.default("23:00").describe("When the night begins, as HH:MM on the sandbox's clock."),
|
|
28
|
-
to: ClockTimeSchema.default("07:00").describe(
|
|
31
|
+
to: ClockTimeSchema.default("07:00").describe(
|
|
32
|
+
"When it ends, as HH:MM on the sandbox's clock: also the morning that ends a night begun by hand. Earlier than `from` runs past midnight; equal to it is no night at all.",
|
|
33
|
+
),
|
|
29
34
|
questions: NightQuestionsSchema.default("decide").describe(
|
|
30
35
|
"What a question an agent asks during night hours, with nobody at the editor, gets. `decide`: it is answered with the option the agent recommends, and the agent lists what was decided for you in its last message, so you can overturn any of it. `defer`: the agent is told it waits for the morning, finishes everything that does not depend on the answer, and ends with the question at the top of its last message.",
|
|
31
36
|
),
|
|
37
|
+
// A night begun by hand (the board's moon): the owner going to bed before their hours begin, or on a day they keep
|
|
38
|
+
// none. It lasts until the next `to`, so it ends by itself in the morning and nothing has to remember to clear it.
|
|
39
|
+
asleepSince: z
|
|
40
|
+
.number()
|
|
41
|
+
.int()
|
|
42
|
+
.nonnegative()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe(
|
|
45
|
+
"When you said good night by hand, in milliseconds since the epoch. From then until the next `to` on the sandbox's clock it is night, whether or not night hours are on and whatever `from` says. Absent, or once that morning has come, only the hours count.",
|
|
46
|
+
),
|
|
32
47
|
});
|
|
33
48
|
export type NightHours = z.infer<typeof NightHoursSchema>;
|
|
34
49
|
|
|
@@ -56,6 +71,34 @@ export const withinNight = (hours: Pick<NightHours, "from" | "to">, zone: Zone,
|
|
|
56
71
|
return from < to ? now >= from && now < to : now >= from || now < to;
|
|
57
72
|
};
|
|
58
73
|
|
|
74
|
+
/** The first instant after `at` that a named clock reads `to`: the morning that ends a night begun at `at`. */
|
|
75
|
+
export const morningAfter = (hours: Pick<NightHours, "to">, zone: Zone, at: number): number => {
|
|
76
|
+
const minutes = minutesOf(hours.to);
|
|
77
|
+
const on = (day: number): number => wallClockInstant(civilDayIn(day, zone), Math.floor(minutes / 60), minutes % 60, zone);
|
|
78
|
+
const today = on(at);
|
|
79
|
+
return today > at ? today : on(nextDayStartIn(at, zone));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// How far ahead of the clock reading it a press may be stamped and still count as begun: the browser that stamped it
|
|
83
|
+
// may run fast, and the board reads it off a clock that ticks once a minute. Further ahead is no night at all.
|
|
84
|
+
const STAMP_AHEAD_MS = 15 * 60_000;
|
|
85
|
+
|
|
86
|
+
/** The morning a night begun by hand ends at, while it has not come yet; undefined when there is none in force. */
|
|
87
|
+
export const nightByHandUntil = (hours: Pick<NightHours, "to" | "asleepSince">, zone: Zone, at: number): number | undefined => {
|
|
88
|
+
if (hours.asleepSince === undefined || hours.asleepSince - at > STAMP_AHEAD_MS) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const morning = morningAfter(hours, zone, hours.asleepSince);
|
|
92
|
+
return at < morning ? morning : undefined;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether it is night at an instant on a named clock, nobody at the editor aside: begun by hand and its morning not
|
|
97
|
+
* yet come, or night hours on and the instant inside their window.
|
|
98
|
+
*/
|
|
99
|
+
export const nightAt = (hours: NightHours, zone: Zone, at: number): boolean =>
|
|
100
|
+
nightByHandUntil(hours, zone, at) !== undefined || (hours.on && withinNight(hours, zone, at));
|
|
101
|
+
|
|
59
102
|
/** How long a night window lasts, in minutes: what the settings row says beside the two times. */
|
|
60
103
|
export const nightLength = (hours: Pick<NightHours, "from" | "to">): number => (minutesOf(hours.to) - minutesOf(hours.from) + 24 * 60) % (24 * 60);
|
|
61
104
|
|
package/src/schemas/offload.ts
CHANGED
|
@@ -18,9 +18,30 @@ export const OffloadTargetSchema = z.object({
|
|
|
18
18
|
});
|
|
19
19
|
export type OffloadTarget = z.infer<typeof OffloadTargetSchema>;
|
|
20
20
|
|
|
21
|
+
// What a line needs of the machine it runs on, said by whoever starts it (`remote-run --needs mem=12G,gpu`); the
|
|
22
|
+
// daemon adds what the line's own profile measured (offload/command-profiles.ts). A machine short of it is never picked.
|
|
23
|
+
export const OffloadNeedsSchema = z.object({
|
|
24
|
+
memoryMb: z.number().int().positive().optional(),
|
|
25
|
+
gpu: z.boolean().optional(),
|
|
26
|
+
});
|
|
27
|
+
export type OffloadNeeds = z.infer<typeof OffloadNeedsSchema>;
|
|
28
|
+
|
|
29
|
+
// The question `offload-run` asks before it snapshots anything. `eager` (remote-run's) picks the machine with the most
|
|
30
|
+
// room that fits even while this sandbox is calm; without it a line leaves only a busy sandbox, or one it does not fit.
|
|
31
|
+
// `label` and `command` name the line, so what it measured on earlier runs counts.
|
|
32
|
+
export const OffloadTargetInputSchema = z.object({
|
|
33
|
+
runner: z.string().min(1),
|
|
34
|
+
memoryMb: z.coerce.number().int().positive().optional(),
|
|
35
|
+
gpu: z.stringbool().optional(),
|
|
36
|
+
eager: z.stringbool().optional(),
|
|
37
|
+
label: z.string().min(1).max(80).optional(),
|
|
38
|
+
command: z.string().max(4000).optional(),
|
|
39
|
+
});
|
|
40
|
+
export type OffloadTargetInput = z.infer<typeof OffloadTargetInputSchema>;
|
|
41
|
+
|
|
21
42
|
// What settings `offload.commands` names instead of one runner: whichever has the most room at the moment the command
|
|
22
|
-
// starts, and only while this sandbox is busy (runners/fleet-advice.ts `
|
|
23
|
-
// command runs here without a word. Reserved: no runner is ever enrolled under it.
|
|
43
|
+
// starts, and only while this sandbox is busy or cannot fit the line (runners/fleet-advice.ts `placeCommand`). While
|
|
44
|
+
// this sandbox is calm the command runs here without a word. Reserved: no runner is ever enrolled under it.
|
|
24
45
|
export const OFFLOAD_ANY_RUNNER = "auto";
|
|
25
46
|
|
|
26
47
|
export const OffloadRunSchema = RunnerCommandSchema.extend({ runner: z.string().min(1) });
|
|
@@ -43,9 +64,25 @@ export const OffloadRecordSchema = z.object({
|
|
|
43
64
|
endedAt: z.number().optional(),
|
|
44
65
|
code: z.number().int().optional(),
|
|
45
66
|
failure: z.string().optional(),
|
|
67
|
+
// What the runner measured: the most memory the line held at once, and how long it ran there.
|
|
68
|
+
peakMemoryMb: z.number().int().nonnegative().optional(),
|
|
69
|
+
durationMs: z.number().int().nonnegative().optional(),
|
|
46
70
|
});
|
|
47
71
|
export type OffloadRecord = z.infer<typeof OffloadRecordSchema>;
|
|
48
72
|
|
|
73
|
+
// What earlier runs of one kind of line measured (offload/command-profiles.ts), keyed by its rule and the parts of the
|
|
74
|
+
// line that decide its size (`cargo test -p shinobi-society`, not the test filter after it).
|
|
75
|
+
export const CommandProfileSchema = z.object({
|
|
76
|
+
key: z.string().min(1),
|
|
77
|
+
runs: z.number().int().positive(),
|
|
78
|
+
// The most any of the last few runs held: memory is planned for the worst recent run, not the average.
|
|
79
|
+
peakMemoryMb: z.number().int().nonnegative().optional(),
|
|
80
|
+
// A moving average of how long it ran, on whichever machine.
|
|
81
|
+
durationMs: z.number().int().nonnegative().optional(),
|
|
82
|
+
lastAt: z.number(),
|
|
83
|
+
});
|
|
84
|
+
export type CommandProfile = z.infer<typeof CommandProfileSchema>;
|
|
85
|
+
|
|
49
86
|
// One kind of heavy work the owner can send elsewhere: a heavy-command rule this sandbox queues (its id, as settings
|
|
50
87
|
// `offload.commands` keys it) and the pattern that sorts a line into it.
|
|
51
88
|
export const OffloadKindSchema = z.object({ id: z.string().min(1), pattern: z.string() });
|
|
@@ -97,7 +97,13 @@ export const AccountStateSchema = z.discriminatedUnion("kind", [
|
|
|
97
97
|
room: z
|
|
98
98
|
.number()
|
|
99
99
|
.describe(
|
|
100
|
-
"How much of the fullest pool that gates the turn is left, in percent (0 up to 100).
|
|
100
|
+
"How much of the fullest pool that gates the turn is left, in percent (0 up to 100). 0 is a rounded pool read at 100: at the line, tried after an unmeasured account, never a limit move's destination. An account nearly out (plan-pools.ts NEARLY_OUT_ROOM) ranks after every one with more.",
|
|
101
|
+
),
|
|
102
|
+
renewsAt: z
|
|
103
|
+
.number()
|
|
104
|
+
.optional()
|
|
105
|
+
.describe(
|
|
106
|
+
"When the longest pool that gates the turn resets, in epoch seconds: the moment what is left of it goes unspent for good. Pickers take the account that renews soonest among those not nearly out, then the most room. Absent where no such pool publishes a reset.",
|
|
101
107
|
),
|
|
102
108
|
}),
|
|
103
109
|
z.object({
|
package/src/schemas/settings.ts
CHANGED
|
@@ -582,7 +582,7 @@ export const SandboxSettingsSchema = z.object({
|
|
|
582
582
|
// sandbox rather than parking the turn until morning. Off until the owner sets the hours: a sleep window guessed for
|
|
583
583
|
// them would decide things in their name at an hour they never chose.
|
|
584
584
|
nightHours: NightHoursSchema.prefault({}).describe(
|
|
585
|
-
"The hours you sleep, on this sandbox's clock. While
|
|
585
|
+
"The hours you sleep, on this sandbox's clock, and a night you begin early by hand, which lasts until the next morning. While it is night and nobody is at the editor, a question an agent asks no longer stops its turn until morning: it is answered with the agent's own recommendation, or kept for the morning while the agent finishes everything else, as `questions` says. A plan an agent chose to make is approved the same way under `decide`; permissions, held commands and anything asked of a named person still wait for you.",
|
|
586
586
|
),
|
|
587
587
|
// Which repositories' own declarations (`<repo>/.intentic/checks.json`) the owner has switched on, each against the
|
|
588
588
|
// fingerprint of what was declared when they did. A declaration that has since changed no longer matches its
|
|
@@ -683,7 +683,7 @@ export const SandboxSettingsSchema = z.object({
|
|
|
683
683
|
childRerunHorizonHours: z.number().int().min(0).max(24).default(6).describe(
|
|
684
684
|
"How long a subagent refused for a spent allowance waits for the provider's reset before it goes again by itself. Past it, or at 0, it stops and its parent hears where else the work can go. One spawned with fallbacks waits at most 90 minutes and then moves to them.",
|
|
685
685
|
),
|
|
686
|
-
subagentBudget: z.boolean().default(true).describe("Start a subagent only where an account's allowance can carry it through its windows, on the account left
|
|
686
|
+
subagentBudget: z.boolean().default(true).describe("Start a subagent only where an account's allowance can carry it through its windows, on the account whose allowance renews first among those that can carry it, since what is left of an allowance at its reset is lost. The rest wait as pending and start by themselves as running ones end or a window reopens. Off, every subagent starts at once, on the account that renews first or, where none carries it, the one that holds out longest."),
|
|
687
687
|
subagentReservePercent: z.number().int().min(0).max(50).default(10).describe("How much of each allowance window, in points of 100, subagents leave for your own conversations: a fan-out is planned against what is left past it."),
|
|
688
688
|
// Width again, for a team-chat automation rather than a turn: each thread a message lands in is a conversation of
|
|
689
689
|
// its own, and threads of one automation are worked on side by side up to this many (automations/scheduler.ts in
|
package/src/text/land-rows.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentEvent } from "../events/agent-events.js";
|
|
2
2
|
import type { TranscriptRow } from "../events/transcript.js";
|
|
3
|
-
import { noticeCode } from "../events/sandbox-notice.js";
|
|
3
|
+
import { noticeCode, type WorktreeSyncCause } from "../events/sandbox-notice.js";
|
|
4
4
|
|
|
5
5
|
// The notices a turn's work leaves as it moves: an install starting, the branch rebased onto the workspace while it
|
|
6
6
|
// waited, and where the finished work went (landed, held, conflicted, or into a parent's checkout).
|
|
@@ -50,12 +50,24 @@ export const installRow = (event: { readonly reach: "own-copy" | "main-tree"; re
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
// One line reporting the daemon's rebase of this agent's branch onto the current workspace; `blocked` names repos it
|
|
53
|
-
// couldn't rebase, where the turn ran from an older base.
|
|
54
|
-
|
|
53
|
+
// couldn't rebase, where the turn ran from an older base. Worded by when it ran: a frame with no `cause` predates it and
|
|
54
|
+
// reads as a turn's opening, as it always did. A mid-turn catch-up only ever moves the branch where the main line touched
|
|
55
|
+
// none of the files it changed (land/sync.ts, the `clear` gate), and says so with the commit to diff against: in the
|
|
56
|
+
// shinobi-society audit (2026-11-17) "while this agent waited" sent an agent hunting for what had reset its fix.
|
|
57
|
+
export interface SyncFacts {
|
|
58
|
+
readonly commits: number;
|
|
59
|
+
readonly blocked: readonly string[];
|
|
60
|
+
readonly cause?: WorktreeSyncCause | undefined;
|
|
61
|
+
}
|
|
62
|
+
export const syncLine = (sync: SyncFacts, base?: string): string => {
|
|
63
|
+
const plural = sync.commits === 1 ? `` : `s`;
|
|
64
|
+
const onto = base === undefined || base === `` ? `` : ` \`git diff ${base}\` shows this agent's own changes on top of the new base.`;
|
|
55
65
|
const moved =
|
|
56
|
-
sync.commits
|
|
57
|
-
?
|
|
58
|
-
:
|
|
66
|
+
sync.commits === 0
|
|
67
|
+
? undefined
|
|
68
|
+
: sync.cause === `between-tools`
|
|
69
|
+
? `The main line moved on during this turn: its ${sync.commits} newer commit${plural} ${sync.commits === 1 ? `was` : `were`} rebased under this agent's branch between two of its tool calls. None of the files this agent changed were touched.${onto}`
|
|
70
|
+
: `Your workspace moved on while this agent waited, its branch was rebased onto your latest ${sync.commits} commit${plural}.`;
|
|
59
71
|
const blocked =
|
|
60
72
|
sync.blocked.length > 0
|
|
61
73
|
? `Couldn't rebase onto your workspace in ${sync.blocked.join(`, `)}: the turn is running from the older base, so its land may need a resolve.`
|
|
@@ -425,6 +425,23 @@ describe("foldTurn", () => {
|
|
|
425
425
|
});
|
|
426
426
|
});
|
|
427
427
|
|
|
428
|
+
// The shinobi-society audit (2026-11-17): a catch-up between two tool calls read "while this agent waited".
|
|
429
|
+
it("words a rebase by when it ran, a frame from before the cause was said reading as it always did", () => {
|
|
430
|
+
const frame = (cause?: "turn-open" | "answer" | "between-tools"): AgentEvent => {
|
|
431
|
+
const sync = cause === undefined ? { commits: 1, blocked: [] } : { commits: 1, blocked: [], cause };
|
|
432
|
+
return { kind: "worktree", branch: "agent/x", base: "abc1234", sync };
|
|
433
|
+
};
|
|
434
|
+
const waited = "Your workspace moved on while this agent waited, its branch was rebased onto your latest 1 commit.";
|
|
435
|
+
expect(foldOf("go", [frame()]).at(-1)?.text).toBe(waited);
|
|
436
|
+
expect(foldOf("go", [frame("turn-open")]).at(-1)?.text).toBe(waited);
|
|
437
|
+
expect(foldOf("go", [frame("answer")]).at(-1)?.text).toBe(waited);
|
|
438
|
+
expect(foldOf("go", [frame("between-tools")]).at(-1)).toEqual({
|
|
439
|
+
role: "notice",
|
|
440
|
+
text: "The main line moved on during this turn: its 1 newer commit was rebased under this agent's branch between two of its tool calls. None of the files this agent changed were touched. `git diff abc1234` shows this agent's own changes on top of the new base.",
|
|
441
|
+
noticeCode: { code: "synced", params: { commits: 1, cause: "between-tools", base: "abc1234" } },
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
428
445
|
it("writes the turn's own events down as notices", () => {
|
|
429
446
|
const events: AgentEvent[] = [
|
|
430
447
|
{ kind: "worktree", branch: "agent/x", base: "abc1234", sync: { commits: 2, blocked: [] } },
|
|
@@ -21,7 +21,7 @@ import { unspokenPromptRow } from "../events/agent-words.js";
|
|
|
21
21
|
import { takeToolUpdate } from "../events/tool-update.js";
|
|
22
22
|
import { needRowText } from "../events/need-wake.js";
|
|
23
23
|
import { noticeCode, sandboxNoticeOf } from "../events/sandbox-notice.js";
|
|
24
|
-
import { installRow, landedRow, syncLine } from "./land-rows.js";
|
|
24
|
+
import { installRow, landedRow, type SyncFacts, syncLine } from "./land-rows.js";
|
|
25
25
|
|
|
26
26
|
// Folds a turn's frames into rows once, live and for the settled record alike, so a reopened chat matches what was on
|
|
27
27
|
// screen. The main turn's frames are its rows; a frame a subagent produced (tagged with the call that spawned it) nests
|
|
@@ -250,7 +250,7 @@ export class TranscriptFold {
|
|
|
250
250
|
return line === undefined || notice === undefined ? [] : this.pushRow({ role: "notice", text: line, noticeCode: noticeCode(notice) });
|
|
251
251
|
}
|
|
252
252
|
case "worktree":
|
|
253
|
-
return this.synced(event.sync);
|
|
253
|
+
return this.synced(event.sync, event.base);
|
|
254
254
|
case "landed":
|
|
255
255
|
return this.pushRow(landedRow(event));
|
|
256
256
|
case "compact":
|
|
@@ -669,15 +669,18 @@ export class TranscriptFold {
|
|
|
669
669
|
|
|
670
670
|
// The rebase notice, less what a resolve turn was sent to fix: that turn opens because the branch couldn't rebase, so
|
|
671
671
|
// saying so again one row under its own errand only repeats it. What did move is still told.
|
|
672
|
-
private synced(sync:
|
|
672
|
+
private synced(sync: SyncFacts | undefined, base: string): TranscriptPatch[] {
|
|
673
673
|
if (sync === undefined) {
|
|
674
674
|
return [];
|
|
675
675
|
}
|
|
676
676
|
const opener = this.opener === undefined ? undefined : this.rows[this.opener];
|
|
677
677
|
const told = opener !== undefined && isLandConflict(opener.text) ? { ...sync, blocked: [] } : sync;
|
|
678
|
-
|
|
678
|
+
// The base is named only where the line says it (a mid-turn catch-up); every other row stays as it was.
|
|
679
|
+
const named = told.cause === `between-tools` && base !== `` ? base : undefined;
|
|
680
|
+
const text = syncLine(told, named);
|
|
679
681
|
const blocked = told.blocked.length > 0 ? told.blocked.join(`, `) : undefined;
|
|
680
|
-
|
|
682
|
+
const params = { commits: told.commits, blocked, cause: told.cause, base: named };
|
|
683
|
+
return text === "" ? [] : this.pushRow({ role: "notice", text, noticeCode: noticeCode({ code: "synced", params }) });
|
|
681
684
|
}
|
|
682
685
|
|
|
683
686
|
private stampOpener(mutate: (row: TranscriptRow) => void): TranscriptPatch[] {
|