@parcha/agentrun-computer 0.1.0-beta.51 → 0.1.0-beta.52

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/README.md CHANGED
@@ -374,7 +374,8 @@ Tar archives move whole trees without holding an archive in memory, and no line
374
374
  open when it ends are ended with it.
375
375
  - `tar.push.begin {path}` makes the directory if missing and returns `{id}`; `tar.push.write {id, data}` hands it the
376
376
  next bytes (send each after the last one's reply), and extraction runs as they come; `tar.push.end {id}` returns
377
- `{entries}`. Files, directories and symlinks are extracted with their modes and never chowned; a directory keeps
377
+ `{entries}`. Files, directories and symlinks are extracted with their modes and never chowned; a file gets its
378
+ header's mtime, as tar gives it (a synced folder's push sets `PUSHED_MTIME`, 2000-01-01); a directory keeps
378
379
  owner access until the archive ends, then gets its mode, deepest first, whether the push made it or found it. An
379
380
  entry that is absolute, has a `..` part, or has a symlink or a file on its way is `denied`, and ends the push;
380
381
  entries before it stay. A symlink at an entry's own name is replaced, never followed. A file is written beside its
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.51",
3
- "source": "sha256:e4c673ff5826d1db1bf27c6c237a80753cae1b5e218ab4d17d123af0075ccb4b"
2
+ "version": "0.1.0-beta.52",
3
+ "source": "sha256:704cb76aa815c7c8e06d6efb4c386314effcdfc1c88b6c1ee55b981abad45d8d"
4
4
  }
@@ -23,7 +23,7 @@ import { MOUNT_KINDS, readBackOf, WORKSPACE } from "../../mount.js";
23
23
  import { syncingClient } from "../../mount-archil.js";
24
24
  import { MAX_LIST_DEPTH, MAX_OUTPUT_BYTES } from "../../protocol.js";
25
25
  import { ok } from "../../result.js";
26
- import { FolderSync, SYNC_MAX_ENTRIES } from "../../sync-folder.js";
26
+ import { FolderSync, PUSHED_MTIME, SYNC_MAX_ENTRIES } from "../../sync-folder.js";
27
27
  import { tarStream } from "../../tar.js";
28
28
  import { assertIsolated, assertRootRunsClosed } from "./isolation.js";
29
29
  import { b64, CASE_LABEL, decode } from "./util.js";
@@ -263,9 +263,10 @@ class CopySink {
263
263
  }
264
264
  }
265
265
  /**
266
- * A computer made with a synced folder, its copy `entries` held by the runner and pushed into /workspace as one tar
267
- * (none: an empty folder), the computer's listing read as the manifest, and its client under syncingClient, as a runner
268
- * hands it to the tools: each call that may change the folder answers once its delta is on the copy.
266
+ * A computer made with a synced folder, its copy `entries` held by the runner and pushed into /workspace as one tar, each
267
+ * file at PUSHED_MTIME (none: an empty folder), the computer's listing read as the manifest, and its client under
268
+ * syncingClient, as a runner hands it to the tools: each call that may change the folder answers once its delta is on
269
+ * the copy.
269
270
  */
270
271
  async function synced(t, name, entries = []) {
271
272
  const copy = new CopySink();
@@ -283,8 +284,9 @@ async function synced(t, name, entries = []) {
283
284
  };
284
285
  const { ref } = await mounted(t, kept, EPOCH, name);
285
286
  const connected = await t.connect(ref);
287
+ const pushed = entries.map((entry) => (entry.type === "file" ? { ...entry, mtime: PUSHED_MTIME } : entry));
286
288
  if (entries.length > 0)
287
- t.ok(await pushTar(connected.client, WORKSPACE, tarStream(entries)), `tar.push of the run's folder into ${WORKSPACE}`);
289
+ t.ok(await pushTar(connected.client, WORKSPACE, tarStream(pushed)), `tar.push of the run's folder into ${WORKSPACE}`);
288
290
  const folder = new FolderSync(connected.client, copy);
289
291
  t.ok(await folder.baseline(), `files.list of ${WORKSPACE} pushed in, as the manifest`);
290
292
  const client = syncingClient(connected.client, async () => {
package/dist/index.d.ts CHANGED
@@ -7,8 +7,8 @@ export * from "./mount.js";
7
7
  export { type CallOptions, DaemonClient, type DaemonStream, findNodes, refusedStep, type UiActOptions, type UiQuery, UiSession } from "./client.js";
8
8
  export { type ActionFailure, type CheckActionsOptions, checkActions, isKey } from "./actions.js";
9
9
  export { pullTar, pullTarStream, pushTar, readFile, writeFile, type PulledTar } from "./files.js";
10
- export { type FolderMeta, FolderSync, folderPathProblem, SYNC_MAX_BYTES, SYNC_MAX_ENTRIES, type SyncCounts, type SyncSink } from "./sync-folder.js";
11
- export { type TarEntry, TarReader, tarEntry, tarOf, tarStream, untar, untarStream } from "./tar.js";
10
+ export { type FolderMeta, FolderSync, folderPathProblem, PUSHED_MTIME, SYNC_MAX_BYTES, SYNC_MAX_ENTRIES, type SyncCounts, type SyncSink } from "./sync-folder.js";
11
+ export { MAX_TAR_MTIME, type TarEntry, TarReader, tarEntry, tarOf, tarStream, untar, untarStream } from "./tar.js";
12
12
  export { listProcesses, readAll, type ReadAllResult } from "./processes.js";
13
13
  export { type ActionMapper, createActionMapper, daemonWatch, redactWords, type ScreenFrame, type ScreenFrames, type ScreenWatch, ScreenWatchError, type ScreenWatchHandlers, toAction, type ViewerEvent, type WatchEndCode, watchEndCode, type WatchOptions, watchScreen, } from "./screen-watch.js";
14
14
  export type { HostCall, HostFacts, Machine, MachineHost, MachineProcess, MachineRequest } from "./host.js";
package/dist/index.js CHANGED
@@ -7,8 +7,8 @@ export * from "./mount.js";
7
7
  export { DaemonClient, findNodes, refusedStep, UiSession } from "./client.js";
8
8
  export { checkActions, isKey } from "./actions.js";
9
9
  export { pullTar, pullTarStream, pushTar, readFile, writeFile } from "./files.js";
10
- export { FolderSync, folderPathProblem, SYNC_MAX_BYTES, SYNC_MAX_ENTRIES } from "./sync-folder.js";
11
- export { TarReader, tarEntry, tarOf, tarStream, untar, untarStream } from "./tar.js";
10
+ export { FolderSync, folderPathProblem, PUSHED_MTIME, SYNC_MAX_BYTES, SYNC_MAX_ENTRIES } from "./sync-folder.js";
11
+ export { MAX_TAR_MTIME, TarReader, tarEntry, tarOf, tarStream, untar, untarStream } from "./tar.js";
12
12
  export { listProcesses, readAll } from "./processes.js";
13
13
  export { createActionMapper, daemonWatch, redactWords, ScreenWatchError, toAction, watchEndCode, watchScreen, } from "./screen-watch.js";
14
14
  export { HostedProvider, hostedDaemonPath } from "./hosted/provider.js";
@@ -4,6 +4,13 @@ import { type Result } from "./result.js";
4
4
  export declare const SYNC_MAX_ENTRIES = 20000;
5
5
  /** The most bytes a synced folder's files hold together: over it, a sync fails, kind limit. */
6
6
  export declare const SYNC_MAX_BYTES: number;
7
+ /**
8
+ * The mtime (whole seconds) a push into a synced folder gives each file, in its tar header, which computerd's extraction
9
+ * keeps: 2000-01-01T00:00:00Z. Older than any reading of the computer's clock, so a write after the push, even in its
10
+ * own clock tick, never leaves a file at it, and the newest mtime in a listing that holds such a write is still one of
11
+ * the computer's clock, as the racy rule needs. Not 1970: a zip of the folder can't hold a time before 1980.
12
+ */
13
+ export declare const PUSHED_MTIME = 946684800;
7
14
  /**
8
15
  * The folder's modes and links: what an object store keeps no record of. A mode is listed where it is not the default
9
16
  * (0644 for a file, 0755 for a directory); a link by its target, as written, never followed.
@@ -48,8 +55,9 @@ export declare class FolderSync {
48
55
  now?: () => number;
49
56
  });
50
57
  /**
51
- * The manifest of a folder just pushed from the sink, read, never guessed (extraction sets no mtime): what it lists is
52
- * what the sink holds, so nothing is pulled. Over a cap, it fails, kind limit.
58
+ * The manifest of a folder just pushed from the sink, each file at PUSHED_MTIME, read, never guessed: what it lists is
59
+ * what the sink holds, so nothing is pulled, and a later write moves a file's mtime off the one it lists. Over a cap,
60
+ * it fails, kind limit.
53
61
  */
54
62
  baseline(options?: {
55
63
  signal?: AbortSignal;
@@ -4,10 +4,12 @@
4
4
  // bytes that changed. Directories, modes and links come from the listing alone, with no bytes.
5
5
  //
6
6
  // Known miss: a write that leaves a file's size and mtime both as they were (`touch -d`, `cp -p` onto a file of the same
7
- // size) is not seen. A same-size rewrite within the same millisecond is, by the racy rule (git's): a file whose mtime is
8
- // within 1 s of the newest in its listing is pulled again at the first sync at least 1 s later. Bytes read that are the
9
- // ones last put there (that re-read, a touch) are not put again. While a directory the computer's user can't read hides
10
- // what the sink holds under it (files.list lists one without what it holds), a sync writes nothing and fails in words.
7
+ // size, a pushed file among them) is not seen. A same-size rewrite in the push's own clock tick is: the push gives every
8
+ // file PUSHED_MTIME, a time no clock gives a later write, so any write moves it. A same-size rewrite within the same
9
+ // millisecond as a sync's listing is too, by the racy rule (git's): a file whose mtime is within 1 s of the newest in its
10
+ // listing is pulled again at the first sync at least 1 s later. Bytes read that are the ones last put there (that
11
+ // re-read, a touch) are not put again. While a directory the computer's user can't read hides what the sink holds under
12
+ // it (files.list lists one without what it holds), a sync writes nothing and fails in words.
11
13
  import { createHash } from "node:crypto";
12
14
  import { pullTarStream } from "./files.js";
13
15
  import { WORKSPACE } from "./mount.js";
@@ -22,6 +24,13 @@ export const SYNC_MAX_BYTES = 2 * 1024 ** 3;
22
24
  const IN_FLIGHT = 8;
23
25
  /** A file whose mtime is within this of the newest in its listing may be rewritten unseen in the same millisecond. */
24
26
  const RACY_MS = 1000;
27
+ /**
28
+ * The mtime (whole seconds) a push into a synced folder gives each file, in its tar header, which computerd's extraction
29
+ * keeps: 2000-01-01T00:00:00Z. Older than any reading of the computer's clock, so a write after the push, even in its
30
+ * own clock tick, never leaves a file at it, and the newest mtime in a listing that holds such a write is still one of
31
+ * the computer's clock, as the racy rule needs. Not 1970: a zip of the folder can't hold a time before 1980.
32
+ */
33
+ export const PUSHED_MTIME = 946_684_800;
25
34
  const TOO_MANY = `the run's folder holds more than ${SYNC_MAX_ENTRIES} entries, the most a synced folder holds`;
26
35
  const FILE_MODE = 0o644;
27
36
  const DIR_MODE = 0o755;
@@ -123,8 +132,9 @@ export class FolderSync {
123
132
  this.#now = now;
124
133
  }
125
134
  /**
126
- * The manifest of a folder just pushed from the sink, read, never guessed (extraction sets no mtime): what it lists is
127
- * what the sink holds, so nothing is pulled. Over a cap, it fails, kind limit.
135
+ * The manifest of a folder just pushed from the sink, each file at PUSHED_MTIME, read, never guessed: what it lists is
136
+ * what the sink holds, so nothing is pulled, and a later write moves a file's mtime off the one it lists. Over a cap,
137
+ * it fails, kind limit.
128
138
  */
129
139
  async baseline(options = {}) {
130
140
  const listed = await this.#list(options.signal);
package/dist/tar.d.ts CHANGED
@@ -4,7 +4,14 @@ export interface TarEntry {
4
4
  mode: number;
5
5
  body?: Uint8Array;
6
6
  link?: string;
7
+ /**
8
+ * The mtime its header carries, in whole seconds since the epoch, 0 to MAX_TAR_MTIME (ustar's 11 octal digits, 2242);
9
+ * now where none is given. Any other value is refused (a RangeError) before the entry is written. untar leaves it out.
10
+ */
11
+ mtime?: number;
7
12
  }
13
+ /** The latest mtime a ustar header holds: 11 octal digits of seconds. */
14
+ export declare const MAX_TAR_MTIME: number;
8
15
  /** One entry's blocks: a pax header first where its name or link does not fit ustar's 100 bytes, then its own, its body and the padding. */
9
16
  export declare function tarEntry(entry: TarEntry): Buffer[];
10
17
  /** A whole archive of these entries. */
package/dist/tar.js CHANGED
@@ -1,11 +1,13 @@
1
1
  // Just enough tar to move a folder through computerd's tar.push and tar.pull without the host's tar, streaming both
2
2
  // ways: ustar out, with a pax header for a name or a link target past ustar's 100 bytes; ustar, pax and GNU long names
3
3
  // in, one entry at a time, each with its whole body, so what is held is one entry, never the archive.
4
+ /** The latest mtime a ustar header holds: 11 octal digits of seconds. */
5
+ export const MAX_TAR_MTIME = 8 ** 11 - 1;
4
6
  const BLOCK = 512;
5
7
  const END = Buffer.alloc(2 * BLOCK);
6
8
  const TYPE_FLAG = { file: "0", dir: "5", symlink: "2", other: "0" };
7
9
  const pad = (length) => Buffer.alloc((BLOCK - (length % BLOCK)) % BLOCK);
8
- function header(name, type, mode, size, link) {
10
+ function header(name, type, mode, size, link, mtime = Math.floor(Date.now() / 1000)) {
9
11
  const block = Buffer.alloc(BLOCK);
10
12
  const field = (at, length, value) => block.write(value, at, length, "utf8");
11
13
  const octal = (value, width) => `${value.toString(8).padStart(width - 1, "0")}\0`;
@@ -14,7 +16,7 @@ function header(name, type, mode, size, link) {
14
16
  field(108, 8, octal(0, 8));
15
17
  field(116, 8, octal(0, 8));
16
18
  field(124, 12, octal(size, 12));
17
- field(136, 12, octal(Math.floor(Date.now() / 1000), 12));
19
+ field(136, 12, octal(mtime, 12));
18
20
  field(148, 8, " ");
19
21
  field(156, 1, type);
20
22
  field(157, 100, link);
@@ -36,6 +38,10 @@ function record(key, value) {
36
38
  }
37
39
  /** One entry's blocks: a pax header first where its name or link does not fit ustar's 100 bytes, then its own, its body and the padding. */
38
40
  export function tarEntry(entry) {
41
+ const { mtime } = entry;
42
+ if (mtime !== undefined && !(Number.isInteger(mtime) && mtime >= 0 && mtime <= MAX_TAR_MTIME)) {
43
+ throw new RangeError(`${entry.name}: mtime ${mtime} is no whole number of seconds from 0 to ${MAX_TAR_MTIME}, which a ustar header holds`);
44
+ }
39
45
  const body = entry.type === "file" ? Buffer.from(entry.body ?? new Uint8Array()) : Buffer.alloc(0);
40
46
  const link = entry.link ?? "";
41
47
  const records = [...(Buffer.byteLength(entry.name) > 100 ? [record("path", entry.name)] : []), ...(Buffer.byteLength(link) > 100 ? [record("linkpath", link)] : [])].join("");
@@ -44,7 +50,7 @@ export function tarEntry(entry) {
44
50
  const pax = Buffer.from(records);
45
51
  blocks.push(header("././@PaxHeader", "x", 0o644, pax.length, ""), pax, pad(pax.length));
46
52
  }
47
- blocks.push(header(entry.name, TYPE_FLAG[entry.type], entry.mode, body.length, link), body, pad(body.length));
53
+ blocks.push(header(entry.name, TYPE_FLAG[entry.type], entry.mode, body.length, link, entry.mtime), body, pad(body.length));
48
54
  return blocks;
49
55
  }
50
56
  /** A whole archive of these entries. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.51",
3
+ "version": "0.1.0-beta.52",
4
4
  "description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
5
5
  "keywords": [
6
6
  "agentrun",