@parcha/agentrun-computer 0.1.0-beta.57 → 0.1.0-beta.59

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 (131) hide show
  1. package/README.md +187 -62
  2. package/box/Dockerfile +4 -3
  3. package/box/install.sh +57 -11
  4. package/dist/agent37.js +6 -9
  5. package/dist/attach.d.ts +24 -4
  6. package/dist/attach.js +50 -19
  7. package/dist/boxd.js +22 -9
  8. package/dist/browserbase.d.ts +6 -2
  9. package/dist/browserbase.js +50 -7
  10. package/dist/child-env.d.ts +11 -0
  11. package/dist/child-env.js +22 -0
  12. package/dist/chrome.d.ts +5 -2
  13. package/dist/chrome.js +5 -2
  14. package/dist/cloudflare.d.ts +2 -0
  15. package/dist/cloudflare.js +5 -3
  16. package/dist/computerd-linux-amd64 +0 -0
  17. package/dist/computerd-linux-arm64 +0 -0
  18. package/dist/computerd.json +1 -1
  19. package/dist/conformance/agent37.d.ts +10 -38
  20. package/dist/conformance/agent37.js +25 -113
  21. package/dist/conformance/archil.d.ts +13 -3
  22. package/dist/conformance/archil.js +22 -17
  23. package/dist/conformance/boxd.d.ts +8 -31
  24. package/dist/conformance/boxd.js +19 -74
  25. package/dist/conformance/browserbase.d.ts +3 -6
  26. package/dist/conformance/browserbase.js +6 -17
  27. package/dist/conformance/cases/health.js +6 -3
  28. package/dist/conformance/cli.d.ts +3 -1
  29. package/dist/conformance/cli.js +69 -9
  30. package/dist/conformance/cloudflare.d.ts +3 -6
  31. package/dist/conformance/cloudflare.js +7 -15
  32. package/dist/conformance/daytona.d.ts +6 -20
  33. package/dist/conformance/daytona.js +22 -57
  34. package/dist/conformance/dial-only.d.ts +4 -3
  35. package/dist/conformance/dial-only.js +3 -3
  36. package/dist/conformance/docker.d.ts +4 -5
  37. package/dist/conformance/docker.js +8 -14
  38. package/dist/conformance/e2b.d.ts +10 -36
  39. package/dist/conformance/e2b.js +27 -84
  40. package/dist/conformance/fly.d.ts +3 -6
  41. package/dist/conformance/fly.js +2 -6
  42. package/dist/conformance/groundbox.d.ts +7 -23
  43. package/dist/conformance/groundbox.js +16 -56
  44. package/dist/conformance/index.d.ts +1 -0
  45. package/dist/conformance/index.js +1 -0
  46. package/dist/conformance/kernel.d.ts +3 -6
  47. package/dist/conformance/kernel.js +5 -15
  48. package/dist/conformance/kind.d.ts +0 -6
  49. package/dist/conformance/kind.js +0 -4
  50. package/dist/conformance/local-chrome.d.ts +5 -7
  51. package/dist/conformance/local-chrome.js +7 -11
  52. package/dist/conformance/modal.d.ts +10 -38
  53. package/dist/conformance/modal.js +27 -74
  54. package/dist/conformance/module-kit.d.ts +87 -0
  55. package/dist/conformance/module-kit.js +88 -0
  56. package/dist/conformance/morph.d.ts +7 -23
  57. package/dist/conformance/morph.js +20 -66
  58. package/dist/conformance/orgo.d.ts +5 -10
  59. package/dist/conformance/orgo.js +15 -27
  60. package/dist/conformance/phone-harness.d.ts +3 -5
  61. package/dist/conformance/phone-harness.js +3 -11
  62. package/dist/conformance/runner.d.ts +13 -3
  63. package/dist/conformance/runner.js +32 -11
  64. package/dist/conformance/smolcloud.d.ts +7 -23
  65. package/dist/conformance/smolcloud.js +16 -49
  66. package/dist/conformance/sweep.d.ts +10 -5
  67. package/dist/conformance/sweep.js +91 -38
  68. package/dist/conformance/tti.d.ts +69 -0
  69. package/dist/conformance/tti.js +205 -0
  70. package/dist/conformance/types.d.ts +9 -2
  71. package/dist/daytona.js +60 -20
  72. package/dist/descriptor.d.ts +10 -0
  73. package/dist/descriptor.js +7 -0
  74. package/dist/descriptors/browserbase.d.ts +3 -0
  75. package/dist/descriptors/browserbase.js +4 -0
  76. package/dist/descriptors/docker.d.ts +1 -0
  77. package/dist/descriptors/docker.js +3 -0
  78. package/dist/descriptors/env-names.d.ts +32 -0
  79. package/dist/descriptors/env-names.js +60 -0
  80. package/dist/descriptors/index.d.ts +9 -2
  81. package/dist/descriptors/kernel.d.ts +3 -0
  82. package/dist/descriptors/kernel.js +2 -0
  83. package/dist/descriptors/local-chrome.d.ts +1 -1
  84. package/dist/descriptors/local-chrome.js +5 -3
  85. package/dist/descriptors/phone-harness.d.ts +1 -1
  86. package/dist/descriptors/phone-harness.js +4 -2
  87. package/dist/docker/egress.d.ts +7 -0
  88. package/dist/docker/egress.js +8 -0
  89. package/dist/docker/image.d.ts +5 -1
  90. package/dist/docker/image.js +12 -8
  91. package/dist/docker.d.ts +63 -15
  92. package/dist/docker.js +181 -98
  93. package/dist/drift.js +6 -6
  94. package/dist/e2b.d.ts +2 -2
  95. package/dist/e2b.js +2 -3
  96. package/dist/groundbox.js +6 -6
  97. package/dist/host.d.ts +23 -0
  98. package/dist/hosted/download.d.ts +23 -0
  99. package/dist/hosted/download.js +144 -0
  100. package/dist/hosted/process.d.ts +5 -0
  101. package/dist/hosted/process.js +20 -0
  102. package/dist/hosted/provider.js +120 -48
  103. package/dist/hosted/rest.d.ts +19 -8
  104. package/dist/hosted/rest.js +47 -14
  105. package/dist/hosted/scripts.d.ts +10 -0
  106. package/dist/hosted/scripts.js +23 -2
  107. package/dist/index.d.ts +3 -1
  108. package/dist/index.js +3 -1
  109. package/dist/janitor.d.ts +7 -1
  110. package/dist/janitor.js +2 -2
  111. package/dist/kernel.js +1 -1
  112. package/dist/local-chrome.d.ts +5 -2
  113. package/dist/local-chrome.js +4 -2
  114. package/dist/local-supervisor.js +1 -0
  115. package/dist/modal.d.ts +6 -5
  116. package/dist/modal.js +7 -7
  117. package/dist/morph.js +5 -8
  118. package/dist/orgo-channel.d.ts +3 -2
  119. package/dist/orgo-channel.js +3 -3
  120. package/dist/orgo-desktop.js +2 -4
  121. package/dist/orgo.js +2 -4
  122. package/dist/phone-harness.d.ts +7 -5
  123. package/dist/phone-harness.js +60 -61
  124. package/dist/protocol.d.ts +10 -0
  125. package/dist/protocol.js +17 -0
  126. package/dist/provider.d.ts +6 -2
  127. package/dist/screen-watch.d.ts +6 -1
  128. package/dist/screen-watch.js +166 -12
  129. package/dist/vendor-sdk.d.ts +9 -0
  130. package/dist/vendor-sdk.js +26 -0
  131. package/package.json +8 -1
@@ -8,7 +8,9 @@ export interface SweepCounts {
8
8
  leftAlone: number;
9
9
  }
10
10
  export interface SweepMachinesOptions {
11
- /** The labels every machine swept carries, over agentrun.computer=1. */
11
+ /** The conformance run whose machines are deleted: those whose RUN_LABEL is this id. */
12
+ run: string;
13
+ /** The labels the listing asks for, over agentrun.computer=1. */
12
14
  labels?: Record<string, string>;
13
15
  /** Ids that were there before: never touched. */
14
16
  before?: ReadonlySet<string>;
@@ -24,11 +26,11 @@ export interface SweepMachinesOptions {
24
26
  onWords?: (words: string) => void;
25
27
  }
26
28
  /**
27
- * The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, that carries a
28
- * conformance run's label is deleted and read back gone; one without it is left alone and counted. A listing the
29
- * vendor refused is the error, with nothing deleted.
29
+ * The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, whose RUN_LABEL is
30
+ * `run` is deleted and read back gone; any other is left alone and counted. A listing the vendor refused is the error,
31
+ * with nothing deleted, as is a run that is not a run id: nothing is listed then.
30
32
  */
31
- export declare function sweepMachines(host: MachineHost, { labels, before, waitMs, pollMs, requestMs, listMs, onWords }?: SweepMachinesOptions): Promise<Result<SweepCounts>>;
33
+ export declare function sweepMachines(host: MachineHost, { run, labels, before, waitMs, pollMs, requestMs, listMs, onWords }: SweepMachinesOptions): Promise<Result<SweepCounts>>;
32
34
  /** A stream as main writes to it: done is called once the text is handed on. */
33
35
  export interface Writer {
34
36
  write(text: string, done?: (error?: Error | null) => void): unknown;
@@ -47,4 +49,7 @@ export interface SweepIo {
47
49
  /** The pause between two reads of one machine; default 2 s. */
48
50
  pollMs?: number;
49
51
  }
52
+ /** The registry's providers on the shared machine-host adapter, in its order: each whose conformance module has
53
+ * createHost (what moduleOf asks of one). Read from the modules, so a provider added there is listed with no edit. */
54
+ export declare function sweepableProviders(): Promise<string[]>;
50
55
  export declare function main(argv: string[], io?: SweepIo): Promise<number>;
@@ -4,40 +4,49 @@
4
4
  // node packages/computer/dist/conformance/sweep.js --provider <id> --before <file>
5
5
  // node packages/computer/dist/conformance/sweep.js --provider <id> --after <file>
6
6
  //
7
- // --before records into <file> the id of every machine the vendor lists with the adapter's label agentrun.computer=1.
8
- // --after lists them again, deletes every one whose id is not in <file> and that carries a conformance run's label
9
- // (agentrun.conformance, RUN_LABEL), then reads each of those back by get until the vendor no longer has it, up to 60 s
10
- // each, and prints one JSON line, {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every
11
- // conformance machine it found that was not there before, gone + stillThere.length = swept, and leftAlone counts the new
12
- // labelled machines with no conformance label, which another user of the account made during the run: never touched. A
13
- // machine in <file> is never touched either: no call names it, and a before file of another provider is refused, as is
14
- // one listed elsewhere for a provider whose module names where it lists (sweepScope: an app and a server), since
15
- // every machine there would read as new.
16
- // Exit 0 when every swept machine is gone, 1 when one is still there, 2 on a usage error, a before file it cannot read,
17
- // missing settings, or a listing the vendor refused (nothing is deleted then). It makes nothing, so it needs no live switch.
7
+ // --before records into <file> the id of every machine the vendor lists with the adapter's label agentrun.computer=1,
8
+ // and a run id it mints for the run it wraps, which it prints: {"recorded":n,"file":...,"run":"<id>"}. The run is given
9
+ // that id with the conformance CLI's --run (runConformance's run), and every machine it makes carries it as
10
+ // agentrun.conformance (RUN_LABEL). <file> must not be there yet: --before makes it, and refuses one that is, with
11
+ // nothing listed, since another run's --after may read it (each run takes its own, from mktemp -d).
12
+ // --after lists them again, deletes every one whose id is not in <file> and whose RUN_LABEL is the file's run, then
13
+ // reads each of those back by get until the vendor no longer has it, up to 60 s each, and prints one JSON line,
14
+ // {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}: swept is every machine of the run it found that was not there
15
+ // before, gone + stillThere.length = swept, and leftAlone counts the other new labelled machines, which another user of
16
+ // the account or another conformance run made during the run: never touched. A machine in <file> is never touched
17
+ // either: no call names it, and a before file of another provider is refused, as is one that names no run, and one
18
+ // listed elsewhere for a provider whose module names where it lists (sweepScope: an app and a server), since every
19
+ // machine there would read as new.
20
+ // Exit 0 when every swept machine is gone, 1 when one is still there, 2 on a usage error, a before file it cannot read
21
+ // (or, for --before, one that is there already), missing settings, or a listing the vendor refused (nothing is deleted
22
+ // then). It makes nothing, so it needs no live switch.
18
23
  //
19
- // The conformance runner runs the same sweep (sweepMachines) at the end of every run of a hosted provider, over the
20
- // run's own label: its report's cleanup.sweep, whose stillThere must be empty for Core to pass.
21
- import { readFileSync, writeFileSync } from "node:fs";
24
+ // The conformance runner runs the same sweep (sweepMachines) at the end of every run of a hosted provider, over its own
25
+ // labels, the run's and the runner's (RUNNER_LABEL): its report's cleanup.sweep, whose stillThere must be empty for Core
26
+ // to pass.
27
+ import { closeSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
22
28
  import { COMPUTER_LABEL } from "../drift.js";
23
29
  import { isCommand } from "../entry.js";
24
30
  import { hostCall } from "../hosted/process.js";
25
31
  import { foundBy, listedBy, NAME_LABEL, settle } from "../hosted/provider.js";
26
- import { providerModule } from "../providers.js";
27
- import { ok } from "../result.js";
28
- import { RUN_LABEL } from "./runner.js";
32
+ import { providerIds, providerModule } from "../providers.js";
33
+ import { fail, ok } from "../result.js";
34
+ import { newRunId, RUN_ID, RUN_LABEL } from "./runner.js";
29
35
  /**
30
- * The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, that carries a
31
- * conformance run's label is deleted and read back gone; one without it is left alone and counted. A listing the
32
- * vendor refused is the error, with nothing deleted.
36
+ * The sweep over host: every machine listed with agentrun.computer=1 and `labels`, not in `before`, whose RUN_LABEL is
37
+ * `run` is deleted and read back gone; any other is left alone and counted. A listing the vendor refused is the error,
38
+ * with nothing deleted, as is a run that is not a run id: nothing is listed then.
33
39
  */
34
- export async function sweepMachines(host, { labels = {}, before = new Set(), waitMs = 60_000, pollMs = 2_000, requestMs = 30_000, listMs = 60_000, onWords = () => { } } = {}) {
40
+ export async function sweepMachines(host, { run, labels = {}, before = new Set(), waitMs = 60_000, pollMs = 2_000, requestMs = 30_000, listMs = 60_000, onWords = () => { } }) {
41
+ // A caller with no run (undefined) would otherwise match every machine that carries no run label.
42
+ if (typeof run !== "string" || !RUN_ID.test(run))
43
+ return fail("invalid", `run is a conformance run's id, 12 hex characters; got ${JSON.stringify(run)}`);
35
44
  const listed = await foundBy(host, "the listing", { ...labels, [COMPUTER_LABEL]: "1" }, { listMs, requestMs });
36
45
  if (!listed.ok)
37
46
  return listed;
38
47
  const added = listed.value.filter((machine) => !before.has(machine.id));
39
- // Only a conformance run's machines: one another user of the account made during the run is not this sweep's.
40
- const fresh = added.filter((machine) => Object.hasOwn(machine.labels, RUN_LABEL));
48
+ // Only this run's machines: one another user of the account, or another conformance run, made meanwhile is not its.
49
+ const fresh = added.filter((machine) => machine.labels[RUN_LABEL] === run);
41
50
  const leftAlone = added.length - fresh.length;
42
51
  for (const machine of fresh) {
43
52
  const deleted = await hostCall(host, `the delete of ${machine.id}`, (ctx) => host.delete(machine.id, ctx), requestMs);
@@ -55,14 +64,30 @@ export async function sweepMachines(host, { labels = {}, before = new Set(), wai
55
64
  const stillThere = fresh.filter((_, i) => !gone[i]).map((machine) => machine.id);
56
65
  return ok({ swept: fresh.length, gone: fresh.length - stillThere.length, stillThere, leftAlone });
57
66
  }
58
- const USAGE = `usage: node packages/computer/dist/conformance/sweep.js --provider <id> --before <file> | --after <file>
59
- --provider <id> a provider on the shared machine-host adapter (e2b, agent37, morph, daytona, boxd, smolcloud, groundbox)
60
- --before <file> record the id of every machine the vendor lists with ${COMPUTER_LABEL}=1 into <file>
61
- --after <file> delete every machine listed with ${COMPUTER_LABEL}=1 and ${RUN_LABEL} whose id is not in <file>, read
62
- each back until the vendor no longer has it (up to 60 s each), and print
63
- {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; a new one with no ${RUN_LABEL} is left alone
67
+ /** The registry's providers on the shared machine-host adapter, in its order: each whose conformance module has
68
+ * createHost (what moduleOf asks of one). Read from the modules, so a provider added there is listed with no edit. */
69
+ export async function sweepableProviders() {
70
+ const ids = [];
71
+ for (const id of providerIds) {
72
+ const module = (await providerModule(id)
73
+ .then((one) => one.conformance?.())
74
+ .catch(() => undefined));
75
+ if (typeof module?.createHost === "function")
76
+ ids.push(id);
77
+ }
78
+ return ids;
79
+ }
80
+ const usage = async () => `usage: node packages/computer/dist/conformance/sweep.js --provider <id> --before <file> | --after <file>
81
+ --provider <id> a provider on the shared machine-host adapter (${(await sweepableProviders()).join(", ")})
82
+ --before <file> record the id of every machine the vendor lists with ${COMPUTER_LABEL}=1 into <file>, with a run id
83
+ it mints and prints ({"recorded":n,"file":...,"run":"<id>"}): give it to the run's --run.
84
+ <file> must not be there yet (each run its own, from mktemp -d): an existing one is refused
85
+ --after <file> delete every machine listed with ${COMPUTER_LABEL}=1 whose id is not in <file> and whose ${RUN_LABEL}
86
+ is <file>'s run, read each back until the vendor no longer has it (up to 60 s each), and print
87
+ {"swept":n,"gone":m,"stillThere":[ids],"leftAlone":k}; any other new one is left alone
64
88
  settings: the provider's conformance module's (COMPUTER_<VENDOR>_*), never the vendor's own names
65
- exit: 0 every swept machine is gone, 1 one is still there, 2 usage error, unreadable before file, no settings, or a refused listing`;
89
+ exit: 0 every swept machine is gone, 1 one is still there, 2 usage error, unreadable before file, a --before file there
90
+ already, no settings, or a refused listing`;
66
91
  class Usage extends Error {
67
92
  }
68
93
  const write = (stream, text) => new Promise((resolve) => void stream.write(text, () => resolve()));
@@ -92,8 +117,11 @@ function parse(argv) {
92
117
  throw new Usage("give --before <file> or --after <file>, one of them");
93
118
  return { provider, ...found };
94
119
  }
95
- /** The ids a before file of this provider (and of this scope, when the provider names one) holds, or why it is not one. */
96
- function beforeIds(file, provider, scope) {
120
+ /**
121
+ * The ids a before file of this provider (and of this scope, when the provider names one) holds and the run it minted,
122
+ * or why it is not one.
123
+ */
124
+ function beforeOf(file, provider, scope) {
97
125
  let text;
98
126
  try {
99
127
  text = readFileSync(file, "utf8");
@@ -118,7 +146,11 @@ function beforeIds(file, provider, scope) {
118
146
  const words = typeof listed === "string" && listed !== "" ? `was listed in ${listed}` : "names no place it was listed in";
119
147
  throw new Usage(`${file} ${words}, and the settings name ${scope} now: every machine there would read as new, so nothing was listed or deleted`);
120
148
  }
121
- return new Set(ids);
149
+ const run = record.run;
150
+ if (typeof run !== "string" || !RUN_ID.test(run)) {
151
+ throw new Usage(`${file} names no conformance run ("run", 12 hex characters): record it again with --before, and give the run it prints to the conformance CLI's --run; nothing was listed or deleted`);
152
+ }
153
+ return { ids: new Set(ids), run };
122
154
  }
123
155
  /** The provider's conformance module, for its host and scope. */
124
156
  async function moduleOf(provider) {
@@ -153,26 +185,47 @@ export async function main(argv, io = {}) {
153
185
  const module = io.host === undefined ? await moduleOf(args.provider) : undefined;
154
186
  scope = io.host === undefined ? scopeOf(module, env) : io.scope;
155
187
  if (args.mode === "after")
156
- before = beforeIds(args.file, args.provider, scope);
188
+ before = beforeOf(args.file, args.provider, scope);
157
189
  host = io.host ?? (await module.createHost({ env }));
158
190
  }
159
191
  catch (error) {
160
- await write(stderr, `${error.message}\n${error instanceof Usage ? `${USAGE}\n` : ""}`);
192
+ await write(stderr, `${error.message}\n${error instanceof Usage ? `${await usage()}\n` : ""}`);
161
193
  return 2;
162
194
  }
163
195
  if (before === undefined) {
196
+ // The file is made here, before the listing, and only if it is not there ("wx"): a before file another run
197
+ // recorded is never written over, or that run's --after would read this run's id and delete this run's machines.
198
+ let fd;
199
+ try {
200
+ fd = openSync(args.file, "wx");
201
+ }
202
+ catch (error) {
203
+ const why = error.code === "EEXIST" ? "is there already, and --before never writes over a before file: another run's --after may read it. Give each run a file of its own (mktemp -d)" : `cannot be made: ${error.message}`;
204
+ await write(stderr, `${args.file} ${why}; nothing was listed\n`);
205
+ return 2;
206
+ }
164
207
  const listed = await listedBy(host, "the listing", { [COMPUTER_LABEL]: "1" }, 60_000);
165
208
  if (!listed.ok) {
209
+ // The empty file this --before made goes, so the same path takes the next one.
210
+ closeSync(fd);
211
+ rmSync(args.file, { force: true });
166
212
  await write(stderr, `listing the machines carrying ${COMPUTER_LABEL}=1 failed, so nothing was recorded: ${listed.error.message}\n`);
167
213
  return 2;
168
214
  }
169
215
  const ids = listed.value.map((machine) => machine.id).sort();
170
- writeFileSync(args.file, `${JSON.stringify({ provider: args.provider, ...(scope === undefined ? {} : { scope }), label: `${COMPUTER_LABEL}=1`, at: new Date().toISOString(), ids }, null, 2)}\n`);
171
- await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file })}\n`);
216
+ // The run this sweep wraps: its --after deletes only the machines labelled with this id, never another run's.
217
+ const run = newRunId();
218
+ try {
219
+ writeFileSync(fd, `${JSON.stringify({ provider: args.provider, ...(scope === undefined ? {} : { scope }), label: `${COMPUTER_LABEL}=1`, run, at: new Date().toISOString(), ids }, null, 2)}\n`);
220
+ }
221
+ finally {
222
+ closeSync(fd);
223
+ }
224
+ await write(stdout, `${JSON.stringify({ recorded: ids.length, file: args.file, run })}\n`);
172
225
  return 0;
173
226
  }
174
227
  const said = [];
175
- const swept = await sweepMachines(host, { before, waitMs, pollMs, onWords: (words) => said.push(words) });
228
+ const swept = await sweepMachines(host, { run: before.run, before: before.ids, waitMs, pollMs, onWords: (words) => said.push(words) });
176
229
  for (const words of said)
177
230
  await write(stderr, `${words}\n`);
178
231
  if (!swept.ok) {
@@ -0,0 +1,69 @@
1
+ import type { ComputerProvider } from "../provider.js";
2
+ import type { ComputerDaemon, ComputerNote, ConformanceOptions, ConformanceReport } from "./types.js";
3
+ export interface TtiStats {
4
+ median: number;
5
+ p95: number;
6
+ p99: number;
7
+ }
8
+ /** One shape of the run: one computer at a time (serial) or all at once (burst). */
9
+ export interface TtiShape {
10
+ /** Computers asked for. */
11
+ n: number;
12
+ /** Computers that ran their first command. */
13
+ ok: number;
14
+ /** ok / n. */
15
+ successRate: number;
16
+ /** Each computer's TTI in ms, of those that came up, in the order they did. */
17
+ ttiMs: number[];
18
+ stats: TtiStats;
19
+ /** ComputeSDK's composite score, 0 to 100 (ttiScore). */
20
+ score: number;
21
+ /** Why the rest did not come up: each distinct reason and how many computers gave it. */
22
+ errors: Array<{
23
+ words: string;
24
+ count: number;
25
+ }>;
26
+ }
27
+ export interface TtiReport {
28
+ provider: string;
29
+ providerVersion: string;
30
+ kind: ConformanceReport["kind"];
31
+ daemonMode: ConformanceReport["daemonMode"];
32
+ image: string;
33
+ /** The first command each computer runs. */
34
+ command: string[];
35
+ /** Whether any computer ran its first command; why: the first reason one did not, when none did. */
36
+ cameUp: boolean;
37
+ why?: string;
38
+ serial?: TtiShape;
39
+ burst?: TtiShape;
40
+ /** Every computer came up and the run left nothing behind. */
41
+ pass: boolean;
42
+ cleanup: ConformanceReport["cleanup"];
43
+ computers: ConformanceReport["computers"];
44
+ daemons: ComputerDaemon[];
45
+ notes?: string[];
46
+ providerNotes?: ComputerNote[];
47
+ }
48
+ export interface TtiOptions extends Omit<ConformanceOptions, "cases" | "only" | "kind" | "concurrency"> {
49
+ /** Computers made one at a time, each deleted before the next: the serial shape. 0 for none. */
50
+ iterations: number;
51
+ /** Computers made all at once: the burst shape. 0 for none. */
52
+ burst: number;
53
+ }
54
+ /** ComputeSDK's statistics: 5% of the values trimmed from each end when that leaves some, then median, p95 and p99. */
55
+ export declare function ttiStats(values: readonly number[]): TtiStats;
56
+ /**
57
+ * ComputeSDK's composite score: median, p95 and p99 each scored 100 * (1 - ms / 10000), 0 at or past 10 s, weighted
58
+ * 0.6, 0.25 and 0.15, times the success rate, to two decimals. No computer up scores 0.
59
+ */
60
+ export declare function ttiScore(stats: TtiStats, successRate: number): number;
61
+ /**
62
+ * Measures the provider's TTI: `iterations` computers one at a time, each its own case (made, timed, deleted), then
63
+ * `burst` computers all at once in one case. Each computer has 150 s to come up; one that does not counts against its
64
+ * shape's success rate with its words. The run's cleanup is the conformance runner's: every computer carries the run's
65
+ * label, a janitor provider is swept by it, and the label is listed to show nothing is left.
66
+ */
67
+ export declare function measureTti(provider: ComputerProvider, options: TtiOptions): Promise<TtiReport>;
68
+ /** The report as a person reads it: came up, one line per shape, its errors under it, the cleanup, the verdict last. */
69
+ export declare function formatTti(report: TtiReport): string;
@@ -0,0 +1,205 @@
1
+ import { runConformance } from "./runner.js";
2
+ /** How long one computer has to come up: ComputeSDK's create bound (120 s) and its first command's (30 s). */
3
+ const COME_UP_MS = 150_000;
4
+ /** Each of median, p95 and p99 scores 100 at 0 ms and 0 at this or more (ComputeSDK's ceiling). */
5
+ const CEILING_MS = 10_000;
6
+ const WEIGHTS = { median: 0.6, p95: 0.25, p99: 0.15 };
7
+ /** The share of the fastest and of the slowest TTIs left out of the statistics, each (ComputeSDK's trim). */
8
+ const TRIM = 0.05;
9
+ /** At most this many kinds of error are printed under a shape's line; --json carries them all. */
10
+ const ERRORS_SHOWN = 5;
11
+ /** ComputeSDK's percentile: nearest rank over values sorted ascending. */
12
+ function percentile(sorted, p) {
13
+ if (sorted.length === 0)
14
+ return 0;
15
+ const at = Math.max(0, Math.ceil((p / 100) * sorted.length) - 1);
16
+ return sorted[Math.min(at, sorted.length - 1)];
17
+ }
18
+ /** ComputeSDK's statistics: 5% of the values trimmed from each end when that leaves some, then median, p95 and p99. */
19
+ export function ttiStats(values) {
20
+ if (values.length === 0)
21
+ return { median: 0, p95: 0, p99: 0 };
22
+ const sorted = [...values].sort((a, b) => a - b);
23
+ const cut = Math.floor(sorted.length * TRIM);
24
+ const kept = cut > 0 && sorted.length - 2 * cut > 0 ? sorted.slice(cut, sorted.length - cut) : sorted;
25
+ const mid = Math.floor(kept.length / 2);
26
+ const median = kept.length % 2 === 0 ? (kept[mid - 1] + kept[mid]) / 2 : kept[mid];
27
+ return { median, p95: percentile(kept, 95), p99: percentile(kept, 99) };
28
+ }
29
+ /**
30
+ * ComputeSDK's composite score: median, p95 and p99 each scored 100 * (1 - ms / 10000), 0 at or past 10 s, weighted
31
+ * 0.6, 0.25 and 0.15, times the success rate, to two decimals. No computer up scores 0.
32
+ */
33
+ export function ttiScore(stats, successRate) {
34
+ if (successRate === 0)
35
+ return 0;
36
+ const metric = (ms) => Math.max(0, 100 * (1 - ms / CEILING_MS));
37
+ const timing = WEIGHTS.median * metric(stats.median) + WEIGHTS.p95 * metric(stats.p95) + WEIGHTS.p99 * metric(stats.p99);
38
+ return Math.round(timing * successRate * 100) / 100;
39
+ }
40
+ const words = (error) => (error instanceof Error ? error.message : String(error)).replace(/\s*\n\s*/g, " ");
41
+ /**
42
+ * One computer: create, connect, the first command, timed on the run's clock from create's call to the command's
43
+ * answer. The runner deletes it when its case ends, outside the time, as ComputeSDK leaves out destroy.
44
+ */
45
+ async function comeUp(t, command) {
46
+ const start = t.clock.now();
47
+ const ref = await t.create();
48
+ const connection = await t.connect(ref);
49
+ const ran = await t.exec(command, {}, connection.client);
50
+ if (ran.exitCode !== 0)
51
+ throw new Error(`the first command, ${command.join(" ")}, exited ${ran.exitCode ?? ran.signal}${ran.err.trim() === "" ? "" : `: ${ran.err.trim()}`}`);
52
+ return t.clock.now() - start;
53
+ }
54
+ /** Skips the case when the provider runs no command: TTI is time to the first one. */
55
+ function needsExec(t) {
56
+ const { groups } = t.provider.capabilities();
57
+ if (!(Array.isArray(groups) && groups.includes("exec")))
58
+ t.skip("the provider declares no exec: TTI is time to the first command, and its computers run none");
59
+ }
60
+ /** The shape's numbers from what each computer gave. */
61
+ function shape(came) {
62
+ const ttiMs = came.flatMap((one) => ("ms" in one ? [one.ms] : []));
63
+ const errors = [];
64
+ for (const one of came) {
65
+ if (!("error" in one))
66
+ continue;
67
+ const seen = errors.find((error) => error.words === one.error);
68
+ if (seen)
69
+ seen.count += 1;
70
+ else
71
+ errors.push({ words: one.error, count: 1 });
72
+ }
73
+ const successRate = came.length === 0 ? 0 : ttiMs.length / came.length;
74
+ const stats = ttiStats(ttiMs);
75
+ return { n: came.length, ok: ttiMs.length, successRate, ttiMs, stats, score: ttiScore(stats, successRate), errors };
76
+ }
77
+ /**
78
+ * Measures the provider's TTI: `iterations` computers one at a time, each its own case (made, timed, deleted), then
79
+ * `burst` computers all at once in one case. Each computer has 150 s to come up; one that does not counts against its
80
+ * shape's success rate with its words. The run's cleanup is the conformance runner's: every computer carries the run's
81
+ * label, a janitor provider is swept by it, and the label is listed to show nothing is left.
82
+ */
83
+ export async function measureTti(provider, options) {
84
+ const { iterations, burst, ...rest } = options;
85
+ for (const [name, value] of [
86
+ ["iterations", iterations],
87
+ ["burst", burst],
88
+ ]) {
89
+ if (!(Number.isSafeInteger(value) && value >= 0))
90
+ throw new TypeError(`${name} is a whole number of computers, 0 or more; got ${value}`);
91
+ }
92
+ if (iterations + burst === 0)
93
+ throw new TypeError("a TTI run makes at least one computer: give iterations or burst");
94
+ // ComputeSDK runs `node -v`; an image need not carry node, so the first command is the shell's echo, Windows' too.
95
+ const command = provider.capabilities().os === "windows" ? ["cmd.exe", "/d", "/c", "echo agentrun"] : ["echo", "agentrun"];
96
+ const serialMs = new Map();
97
+ const bursted = [];
98
+ const cases = Array.from({ length: iterations }, (_, i) => ({
99
+ id: `tti.serial-${i + 1}`,
100
+ level: "full",
101
+ group: "tti",
102
+ needs: [],
103
+ computer: "none",
104
+ timeoutMs: COME_UP_MS,
105
+ async run(t) {
106
+ needsExec(t);
107
+ serialMs.set(`tti.serial-${i + 1}`, await comeUp(t, command));
108
+ },
109
+ }));
110
+ if (burst > 0) {
111
+ cases.push({
112
+ id: "tti.burst",
113
+ level: "full",
114
+ group: "tti",
115
+ needs: [],
116
+ computer: "none",
117
+ timeoutMs: COME_UP_MS,
118
+ async run(t) {
119
+ needsExec(t);
120
+ // Each computer is recorded as it comes up or fails; once the case's time is out, what is left is counted
121
+ // with the case's own reason below, and a late answer is not recorded.
122
+ const record = (one) => {
123
+ if (!t.signal.aborted)
124
+ bursted.push(one);
125
+ };
126
+ await Promise.all(Array.from({ length: burst }, () => comeUp(t, command).then((ms) => record({ ms }), (error) => record({ error: words(error) }))));
127
+ const failed = bursted.filter((one) => "error" in one).length;
128
+ if (failed > 0)
129
+ throw new Error(`${failed} of ${burst} computers did not come up`);
130
+ },
131
+ });
132
+ }
133
+ const report = await runConformance(provider, { ...rest, cases });
134
+ const resultOf = (id) => report.results.find((result) => result.id === id);
135
+ const serial = Array.from({ length: iterations }, (_, i) => {
136
+ const id = `tti.serial-${i + 1}`;
137
+ const ms = serialMs.get(id);
138
+ return resultOf(id)?.status === "pass" && ms !== undefined ? { ms } : { error: resultOf(id)?.reason ?? `${id} did not run` };
139
+ });
140
+ const burstCame = [...bursted, ...Array.from({ length: burst - bursted.length }, () => ({ error: resultOf("tti.burst")?.reason ?? "tti.burst did not run" }))];
141
+ const shapes = { ...(iterations > 0 ? { serial: shape(serial) } : {}), ...(burst > 0 ? { burst: shape(burstCame) } : {}) };
142
+ const all = [...serial, ...burstCame];
143
+ const cameUp = all.some((one) => "ms" in one);
144
+ const firstError = all.find((one) => "error" in one);
145
+ const clean = report.cleanup.left.length === 0 && report.cleanup.errors.length === 0;
146
+ return {
147
+ provider: report.provider,
148
+ providerVersion: report.providerVersion,
149
+ kind: report.kind,
150
+ daemonMode: report.daemonMode,
151
+ image: report.image,
152
+ command,
153
+ cameUp,
154
+ ...(cameUp || firstError === undefined ? {} : { why: firstError.error }),
155
+ ...shapes,
156
+ pass: firstError === undefined && clean,
157
+ cleanup: report.cleanup,
158
+ computers: report.computers,
159
+ daemons: report.daemons,
160
+ ...(report.notes === undefined ? {} : { notes: report.notes }),
161
+ };
162
+ }
163
+ /** The report as a person reads it: came up, one line per shape, its errors under it, the cleanup, the verdict last. */
164
+ export function formatTti(report) {
165
+ const lines = [`computer tti · ${report.provider} · ${report.kind}, daemon ${report.daemonMode} · image ${report.image}`];
166
+ lines.push(report.cameUp ? "came up: yes" : `came up: no: ${report.why ?? "no computer was asked for"}`);
167
+ const ms = (value) => `${Math.round(value)} ms`;
168
+ for (const [label, one] of [
169
+ ["serial", report.serial],
170
+ ["burst ", report.burst],
171
+ ]) {
172
+ if (one === undefined)
173
+ continue;
174
+ const shown = `n ${one.n}${label === "burst " ? " at once" : ""} · ok ${one.ok}/${one.n} (${Math.round(one.successRate * 100)}%)`;
175
+ lines.push(`${label} ${shown} · median ${ms(one.stats.median)} · p95 ${ms(one.stats.p95)} · p99 ${ms(one.stats.p99)} · score ${one.score}`);
176
+ for (const error of one.errors.slice(0, ERRORS_SHOWN))
177
+ lines.push(` ✗ ${error.count}x ${error.words}`);
178
+ if (one.errors.length > ERRORS_SHOWN)
179
+ lines.push(` ✗ and ${one.errors.length - ERRORS_SHOWN} more kinds of error (--json has them all)`);
180
+ }
181
+ const { cleanup } = report;
182
+ if (cleanup.late.length > 0)
183
+ lines.push(`cleanup - deleted after their case ended: ${cleanup.late.join(", ")}`);
184
+ if (cleanup.left.length === 0 && cleanup.errors.length === 0)
185
+ lines.push(`cleanup ✓ 0 left · ${cleanup.deleted.length} deleted`);
186
+ else {
187
+ lines.push(`cleanup ✗ ${cleanup.left.length > 0 ? `left ${cleanup.left.join(", ")}` : "could not show nothing was left"}`);
188
+ for (const error of cleanup.errors)
189
+ lines.push(` ✗ ${error}`);
190
+ }
191
+ lines.push(`computers alive at once: ${report.computers.peak} at most`);
192
+ for (const note of report.notes ?? [])
193
+ lines.push(`note: ${note}`);
194
+ for (const { computer, note } of report.providerNotes ?? [])
195
+ lines.push(`provider note ${computer}: ${note}`);
196
+ const shapes = [report.serial, report.burst].filter((one) => one !== undefined);
197
+ const total = shapes.reduce((sum, one) => sum + one.n, 0);
198
+ const down = total - shapes.reduce((sum, one) => sum + one.ok, 0);
199
+ const reasons = [
200
+ ...(down > 0 ? [`${down} of ${total} computers did not come up`] : []),
201
+ ...(cleanup.left.length > 0 || cleanup.errors.length > 0 ? ["the cleanup did not show nothing was left"] : []),
202
+ ];
203
+ lines.push(reasons.length === 0 ? `tti PASS: ${total} of ${total} computers came up` : `tti FAIL: ${reasons.join("; ")}`);
204
+ return `${lines.join("\n")}\n`;
205
+ }
@@ -10,7 +10,7 @@ import type { KindVerdict } from "./kind.js";
10
10
  /** Core: what a computer of its kind must do. Full: an optional capability, tested only where it is declared. */
11
11
  export type Level = "core" | "full";
12
12
  /** The suite's own grouping of its cases, the first part of each case id; not the protocol's Group. */
13
- export type CaseGroup = "health" | "exec" | "files" | "process" | "provider" | "drift" | "isolation" | "mount" | "screen" | "input" | "touch" | "apps" | "ui" | "lifetime" | "browser" | "gpu";
13
+ export type CaseGroup = "health" | "exec" | "files" | "process" | "provider" | "drift" | "isolation" | "mount" | "screen" | "input" | "touch" | "apps" | "ui" | "lifetime" | "browser" | "gpu" | "tti";
14
14
  /**
15
15
  * What a case needs: a group (declared by both the provider's capabilities().groups and the computer's hello), a
16
16
  * network the provider declares, the janitor as the keeper of deadlines, a spec.user the provider takes, a release that
@@ -66,7 +66,7 @@ export interface CaseContext {
66
66
  /** A connection of the case's own to that computer, after hello: computerd, or the provider itself (daemon none). */
67
67
  readonly client: ComputerClient;
68
68
  readonly hello: HelloResult;
69
- /** The label every computer of this run carries. */
69
+ /** The labels every computer of this runner carries: the run's id (agentrun.conformance) and the runner's own. */
70
70
  readonly runLabels: Record<string, string>;
71
71
  /** How long a case waits on a program before it fails: a bound, never a claim about speed. */
72
72
  readonly patience: number;
@@ -307,6 +307,13 @@ export interface ConformanceOptions {
307
307
  * computer, is refused, in words.
308
308
  */
309
309
  kind?: ComputerSettingKind;
310
+ /**
311
+ * The run's id, which every computer it makes carries as agentrun.conformance: the one the live sweep's --before
312
+ * minted, so its --after deletes this run's computers and no other's (12 hex characters). Default a fresh one. Several
313
+ * runners may share one: each also labels its computers with an id of its own (agentrun.conformance.runner), and its
314
+ * end-of-run sweeps go by that too, so the first to end never deletes another's.
315
+ */
316
+ run?: string;
310
317
  signal?: AbortSignal;
311
318
  /** The cases to run; default casesFor the provider's machine kind: a browser's own cases, else every case of the suite. */
312
319
  cases?: Case[];