@cloop/runner 0.3.55 → 0.3.57

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  serveTakeovers
4
- } from "./chunk-XUPGFORB.js";
5
- import "./chunk-HCAHMQC3.js";
4
+ } from "./chunk-ZPTAWYEW.js";
5
+ import "./chunk-FE2CVSWX.js";
6
6
  import {
7
7
  CAPTURE_TICK_MS,
8
8
  DEFAULT_FALLBACK_MODEL,
@@ -39,7 +39,7 @@ import {
39
39
  systemServices,
40
40
  unitFor,
41
41
  which
42
- } from "./chunk-M2BOHVUC.js";
42
+ } from "./chunk-EWCRSUJM.js";
43
43
  import {
44
44
  MeshSocket,
45
45
  WAKE_TICK_MS,
@@ -57,7 +57,7 @@ import {
57
57
  runnerStatePath,
58
58
  threadsFilePath,
59
59
  writeRunnerState
60
- } from "./chunk-HB76TZWH.js";
60
+ } from "./chunk-TZDLUM3E.js";
61
61
  import {
62
62
  BackgroundReading,
63
63
  BoxToolError,
@@ -107,20 +107,20 @@ import {
107
107
  utcWindow,
108
108
  windowsPowerShellEnv,
109
109
  writeBoxConfig
110
- } from "./chunk-FHAIBI3Z.js";
110
+ } from "./chunk-XAKDSXMW.js";
111
111
  import "./chunk-VK6GV757.js";
112
112
  import {
113
113
  olderThan
114
114
  } from "./chunk-365HFCQQ.js";
115
115
  import "./chunk-PKIEWBR7.js";
116
- import "./chunk-2QKGVFWN.js";
117
- import "./chunk-TKWZ6GLL.js";
116
+ import "./chunk-6Z22QRZA.js";
117
+ import "./chunk-VXBAFPY4.js";
118
118
  import {
119
119
  getMachine
120
120
  } from "./chunk-SBYSVZ7J.js";
121
121
  import {
122
122
  VERSION
123
- } from "./chunk-6CUPNFNR.js";
123
+ } from "./chunk-SOM5GPW2.js";
124
124
  import {
125
125
  getMeshUrl,
126
126
  getOrigin,
@@ -579,6 +579,14 @@ function placeFor(a) {
579
579
  branch: `cloop/${run3}`
580
580
  };
581
581
  }
582
+ function withHeld(prompt, held) {
583
+ if (!held.length) return prompt;
584
+ return `${prompt}
585
+
586
+ The owner added this while the run was being prepared:
587
+
588
+ ${held.join("\n\n")}`;
589
+ }
582
590
  function launchText(prompt, place, photos = "") {
583
591
  const where = place.kind === "worktree" ? `
584
592
 
@@ -874,6 +882,11 @@ var CloudroomDriver = class {
874
882
  * Core has no session for them yet; they go in once the run's prompt is in.
875
883
  */
876
884
  early = /* @__PURE__ */ new Map();
885
+ /**
886
+ * The command ids of follow-ups in each live run's prompt, by thread, so a
887
+ * resend sends nothing. A failed prompt or the run's end drops them.
888
+ */
889
+ folded = /* @__PURE__ */ new Map();
877
890
  /** Runs stopped while still being prepared, or while moving off a refused model. */
878
891
  stopped = /* @__PURE__ */ new Set();
879
892
  /** Runs' model facts, by thread, as the store keeps them. */
@@ -1077,6 +1090,7 @@ var CloudroomDriver = class {
1077
1090
  this.keep(thread, { named: a.model });
1078
1091
  const place = placeFor(a);
1079
1092
  let photos;
1093
+ let inPrompt = 0;
1080
1094
  const photosOnce = async () => {
1081
1095
  photos ??= await this.photos(a, place);
1082
1096
  return photos;
@@ -1109,10 +1123,16 @@ var CloudroomDriver = class {
1109
1123
  folder(existing2 ?? await this.session(thread))
1110
1124
  );
1111
1125
  if (this.stopped.has(thread)) throw STOPPED_IN_PREPARATION;
1126
+ const photoLine = (await photosOnce()).line;
1127
+ const held = this.foldEarly(thread);
1128
+ inPrompt = held.length;
1129
+ if (held.length)
1130
+ this.log(`launch work=${a.work_id} thread=${thread} followups_in_prompt=${held.length}`);
1112
1131
  await this.core.command(thread, "prompts", {
1113
1132
  request_id: prompt,
1114
- text: launchText(a.prompt, place, (await photosOnce()).line)
1133
+ text: launchText(withHeld(a.prompt, held), place, photoLine)
1115
1134
  });
1135
+ inPrompt = 0;
1116
1136
  this.preparing.delete(thread);
1117
1137
  if (this.stopped.has(thread))
1118
1138
  await this.stopRun(thread, `prepared-${a.work_id}`).catch(
@@ -1144,8 +1164,9 @@ var CloudroomDriver = class {
1144
1164
  return this.sendEarly(thread, a.work_id);
1145
1165
  });
1146
1166
  prep.catch((err) => {
1147
- const dropped = this.early.get(thread)?.size ?? 0;
1167
+ const dropped = (this.early.get(thread)?.size ?? 0) + inPrompt;
1148
1168
  this.early.delete(thread);
1169
+ this.folded.delete(thread);
1149
1170
  if (dropped && err !== STOPPED_IN_PREPARATION)
1150
1171
  this.deps.followUpLost?.({ work: a.work_id, n: dropped });
1151
1172
  this.log(
@@ -1165,6 +1186,7 @@ var CloudroomDriver = class {
1165
1186
  */
1166
1187
  async send(a) {
1167
1188
  const id = this.carrier(a.thread_id);
1189
+ if (this.folded.get(id)?.has(a.command_id)) return { delivered: "queue" };
1168
1190
  const early = this.early.get(id);
1169
1191
  if (early && !a.answer) {
1170
1192
  early.set(a.command_id, early.get(a.command_id) ?? a);
@@ -1173,18 +1195,31 @@ var CloudroomDriver = class {
1173
1195
  }
1174
1196
  return this.sendNow(id, a);
1175
1197
  }
1198
+ /** Takes the follow-ups held so far, in the order they came, for the run's prompt. Later ones still wait. */
1199
+ foldEarly(thread) {
1200
+ const early = this.early.get(thread);
1201
+ if (!early) return [];
1202
+ const held = [...early.values()];
1203
+ early.clear();
1204
+ if (!held.length) return [];
1205
+ const ids = this.folded.get(thread) ?? /* @__PURE__ */ new Set();
1206
+ for (const a of held) ids.add(a.command_id);
1207
+ this.folded.set(thread, ids);
1208
+ return held.map((a) => a.text);
1209
+ }
1176
1210
  /**
1177
- * The follow-ups that came while the run was prepared, in the order they
1178
- * came. One that comes while these go in joins the end of the line. Each
1179
- * goes as a resume: core may not have counted the run's prompt yet. The
1180
- * app already told the owner each one is queued, so a failure here goes to
1181
- * the mesh as `followup_lost`, the one place it is seen.
1211
+ * The follow-ups that came while the run's prompt was on its way, in the
1212
+ * order they came. One that comes while these go in joins the end of the
1213
+ * line. Each waits as the next prompt, never a steer into a turn just
1214
+ * starting; it goes as a resume, as core may not have counted the run's
1215
+ * prompt yet. The app already told the owner each one is queued, so a
1216
+ * failure here goes to the mesh as `followup_lost`, the one place it is seen.
1182
1217
  */
1183
1218
  async sendEarly(thread, work) {
1184
1219
  const early = this.early.get(thread);
1185
1220
  if (!early) return;
1186
1221
  for (const a of early.values()) {
1187
- await this.sendNow(thread, { ...a, resume: true }).then(
1222
+ await this.sendNow(thread, { ...a, mode: "queue", resume: true }).then(
1188
1223
  (r) => this.log(`send thread=${thread} after its prompt delivered=${r.delivered}`),
1189
1224
  (err) => {
1190
1225
  this.deps.followUpLost?.({
@@ -1371,6 +1406,7 @@ ${line}` : line;
1371
1406
  watch(id, report) {
1372
1407
  const onEvent = (event) => {
1373
1408
  const ends = event.kind === "settled" || event.kind === "failed";
1409
+ if (ends) this.folded.delete(id);
1374
1410
  if (ends && this.runModels.has(id))
1375
1411
  this.keep(id, { ended_at: new Date(this.now()).toISOString() });
1376
1412
  report(ends ? { ...event, harness: this.harness } : event);
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ConnectFailure,
4
4
  deviceLogin
5
- } from "./chunk-TKWZ6GLL.js";
5
+ } from "./chunk-VXBAFPY4.js";
6
6
  import {
7
7
  ApiError,
8
8
  ReauthError,
@@ -9,7 +9,7 @@ import {
9
9
  readRunnerState,
10
10
  runnerStatePath,
11
11
  threadsFilePath
12
- } from "./chunk-HB76TZWH.js";
12
+ } from "./chunk-TZDLUM3E.js";
13
13
  import {
14
14
  BoxToolError,
15
15
  CLOOP_THREAD_PREFIX,
@@ -50,7 +50,7 @@ import {
50
50
  windowsExecutable,
51
51
  windowsPowerShellEnv,
52
52
  writeBoxConfig
53
- } from "./chunk-FHAIBI3Z.js";
53
+ } from "./chunk-XAKDSXMW.js";
54
54
  import {
55
55
  CLAUDE_FLOOR,
56
56
  CODEX_FLOOR,
@@ -64,14 +64,14 @@ import {
64
64
  } from "./chunk-PKIEWBR7.js";
65
65
  import {
66
66
  connectWebhook
67
- } from "./chunk-2QKGVFWN.js";
67
+ } from "./chunk-6Z22QRZA.js";
68
68
  import {
69
69
  ConnectFailure,
70
70
  connectReport,
71
71
  deviceLogin,
72
72
  newAttempt,
73
73
  sendConnectReport
74
- } from "./chunk-TKWZ6GLL.js";
74
+ } from "./chunk-VXBAFPY4.js";
75
75
  import {
76
76
  defaultDeviceName,
77
77
  getMachine,
@@ -79,7 +79,7 @@ import {
79
79
  } from "./chunk-SBYSVZ7J.js";
80
80
  import {
81
81
  VERSION
82
- } from "./chunk-6CUPNFNR.js";
82
+ } from "./chunk-SOM5GPW2.js";
83
83
  import {
84
84
  STAGING_ORIGIN,
85
85
  getOrigin,
@@ -9,7 +9,7 @@ import {
9
9
  runHarness,
10
10
  runLogDir,
11
11
  runLogPath
12
- } from "./chunk-FHAIBI3Z.js";
12
+ } from "./chunk-XAKDSXMW.js";
13
13
  import {
14
14
  sanitizeLabel,
15
15
  stripControl
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/version.ts
4
- var VERSION = true ? "0.3.55" : "0.0.0-dev";
4
+ var VERSION = true ? "0.3.57" : "0.0.0-dev";
5
5
 
6
6
  export {
7
7
  VERSION
@@ -1,22 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- RUN_IMAGES_MAX,
4
- RUN_IMAGE_MAX_BYTES,
5
- RUN_IMAGE_TYPES,
3
+ RUN_MEDIA_CLASSES,
4
+ RUN_MEDIA_TYPES,
6
5
  RUN_PREVIEWS_MAX,
7
6
  RUN_TEXT_MAX,
8
7
  boxPath,
9
8
  commandFor,
10
9
  imageExt,
10
+ mediaExt,
11
11
  runnerPath
12
- } from "./chunk-FHAIBI3Z.js";
12
+ } from "./chunk-XAKDSXMW.js";
13
13
 
14
14
  // src/run-previews.ts
15
15
  import { execFile as execFile2, spawn } from "child_process";
16
16
  import { createHash as createHash2 } from "crypto";
17
17
  import { createWriteStream } from "fs";
18
18
  import { mkdir as mkdir2, readFile as readFile3, rm as rm2, writeFile as writeFile2 } from "fs/promises";
19
- import { basename, join as join3 } from "path";
19
+ import { basename as basename2, join as join3 } from "path";
20
20
 
21
21
  // src/cloudflared.ts
22
22
  import { execFile } from "child_process";
@@ -133,30 +133,32 @@ async function findPinned(target, asset, platform, digestOf) {
133
133
  // src/run-media.ts
134
134
  import { readFile as readFile2, stat } from "fs/promises";
135
135
  import { homedir as homedir2 } from "os";
136
- import { isAbsolute, join as join2, resolve } from "path";
136
+ import { basename, isAbsolute, join as join2, resolve } from "path";
137
137
  var MEDIA_BUDGET_MS = 3e4;
138
- function hasImages(result) {
139
- return Boolean(
140
- result?.outputs.some((output) => output.kind === "image" && output.path !== void 0)
141
- );
138
+ var isMedia = (output) => output.kind === "image" || output.kind === "file";
139
+ function hasMedia(result) {
140
+ return Boolean(result?.outputs.some((output) => isMedia(output) && output.path !== void 0));
142
141
  }
143
- function imageFile(path, cwd) {
142
+ function outputFile(path, cwd) {
144
143
  if (isAbsolute(path)) return path;
145
144
  if (path === "~" || path.startsWith("~/")) return join2(homedir2(), path.slice(2));
146
145
  return cwd ? resolve(cwd, path) : null;
147
146
  }
148
- async function send(workId, file, deps, signal) {
147
+ async function send(workId, output, file, deps, signal) {
149
148
  try {
150
- if ((await stat(file)).size > RUN_IMAGE_MAX_BYTES) return { media: null, reason: "too_large" };
149
+ if ((await stat(file)).size > RUN_MEDIA_CLASSES[output.kind].maxBytes)
150
+ return { media: null, reason: "too_large" };
151
151
  const bytes = await readFile2(file, { signal });
152
- const ext = imageExt(bytes);
153
- if (!ext) return { media: null, reason: "not_an_image" };
152
+ const name = basename(file);
153
+ const ext = output.kind === "image" ? imageExt(bytes) : mediaExt(bytes, name);
154
+ if (!ext)
155
+ return { media: null, reason: output.kind === "image" ? "not_an_image" : "not_allowed" };
154
156
  const res = await (deps.fetchFn ?? fetch)(
155
- `${deps.origin}/api/agent/runs/${encodeURIComponent(workId)}/media`,
157
+ `${deps.origin}/api/agent/runs/${encodeURIComponent(workId)}/media${output.kind === "file" ? `?name=${encodeURIComponent(name)}` : ""}`,
156
158
  {
157
159
  method: "POST",
158
160
  headers: {
159
- "content-type": RUN_IMAGE_TYPES[ext],
161
+ "content-type": RUN_MEDIA_TYPES[ext].mime,
160
162
  authorization: `Bearer ${deps.deviceToken()}`
161
163
  },
162
164
  body: new Uint8Array(bytes),
@@ -173,9 +175,12 @@ async function send(workId, file, deps, signal) {
173
175
  return { media: body.media };
174
176
  } catch (err) {
175
177
  const code = err.code;
178
+ if (code === "ENOENT") return { media: null, reason: "no_file" };
179
+ if (signal.aborted) return { media: null, reason: "out_of_time" };
176
180
  return {
177
181
  media: null,
178
- reason: code === "ENOENT" ? "no_file" : signal.aborted ? "out_of_time" : code ?? (err instanceof Error ? err.name : "error")
182
+ reason: "read_failed",
183
+ detail: code ?? (err instanceof Error ? err.name : "error")
179
184
  };
180
185
  }
181
186
  }
@@ -187,34 +192,45 @@ function applyPatches(result, ...patches) {
187
192
  )
188
193
  };
189
194
  }
190
- async function imagePatches(workId, result, cwd, deps) {
195
+ async function mediaPatches(workId, result, cwd, deps) {
191
196
  const budget = deps.budgetMs ?? MEDIA_BUDGET_MS;
192
197
  const clock = new AbortController();
193
198
  const timer = setTimeout(() => clock.abort(), budget);
194
199
  const outputs = result.outputs.map((output) => {
195
- if (output.kind !== "image" || output.path === void 0) return output;
196
- const { media: _unsent, ...image } = output;
197
- return image;
200
+ if (!isMedia(output) || output.path === void 0) return output;
201
+ const { media: _claimed, ...rest } = output;
202
+ if (rest.kind === "image") return rest;
203
+ const { unsent: _alsoClaimed, ...file } = rest;
204
+ return file;
198
205
  });
206
+ const notSent = (i, output, reason, detail) => {
207
+ if (output.kind === "file") outputs[i] = { ...output, unsent: reason };
208
+ deps.log(
209
+ `[runner:media] not sent work=${workId} class=${output.kind} reason=${reason}${detail ? ` detail=${detail}` : ""}`
210
+ );
211
+ };
199
212
  const work = (async () => {
200
- let sent = outputs.filter(
201
- (output) => output.kind === "image" && output.path === void 0
202
- ).length;
213
+ const sent = {
214
+ image: outputs.filter((output) => output.kind === "image" && output.path === void 0).length,
215
+ file: 0
216
+ };
203
217
  for (const [i, output] of outputs.entries()) {
204
- if (output.kind !== "image" || output.path === void 0) continue;
205
- if (sent >= RUN_IMAGES_MAX || clock.signal.aborted) {
206
- deps.log(
207
- `[runner:media] not sent work=${workId} reason=${clock.signal.aborted ? "out_of_time" : "too_many"}`
208
- );
218
+ if (!isMedia(output) || output.path === void 0) continue;
219
+ if (clock.signal.aborted) {
220
+ notSent(i, output, "out_of_time");
221
+ continue;
222
+ }
223
+ if (sent[output.kind] >= RUN_MEDIA_CLASSES[output.kind].max) {
224
+ notSent(i, output, "too_many");
209
225
  continue;
210
226
  }
211
- const file = imageFile(output.path, cwd);
212
- const outcome = file ? await send(workId, file, deps, clock.signal) : { media: null, reason: "no_folder" };
227
+ const file = outputFile(output.path, cwd);
228
+ const outcome = file ? await send(workId, output, file, deps, clock.signal) : { media: null, reason: "no_folder" };
213
229
  if (outcome.media !== null) {
214
230
  outputs[i] = { ...output, media: outcome.media };
215
- sent++;
216
- deps.log(`[runner:media] sent work=${workId}`);
217
- } else deps.log(`[runner:media] not sent work=${workId} reason=${outcome.reason}`);
231
+ sent[output.kind]++;
232
+ deps.log(`[runner:media] sent work=${workId} class=${output.kind}`);
233
+ } else notSent(i, output, outcome.reason, outcome.detail);
218
234
  }
219
235
  })();
220
236
  await Promise.race([
@@ -224,9 +240,12 @@ async function imagePatches(workId, result, cwd, deps) {
224
240
  ]);
225
241
  clearTimeout(timer);
226
242
  return new Map(
227
- outputs.flatMap(
228
- (output, i) => output.kind === "image" ? [[i, output]] : []
229
- )
243
+ outputs.flatMap((output, i) => {
244
+ if (!isMedia(output)) return [];
245
+ if (output.kind === "file" && output.path !== void 0 && !output.media && !output.unsent)
246
+ return [[i, { ...output, unsent: "out_of_time" }]];
247
+ return [[i, output]];
248
+ })
230
249
  );
231
250
  }
232
251
 
@@ -345,15 +364,15 @@ async function previewPatches(workId, result, deps) {
345
364
  );
346
365
  }
347
366
  function needsAttach(result) {
348
- return hasImages(result) || hasPreviews(result);
367
+ return hasMedia(result) || hasPreviews(result);
349
368
  }
350
369
  async function attachRunOutputs(workId, result, cwd, deps) {
351
370
  const none = /* @__PURE__ */ new Map();
352
- const [images, previews] = await Promise.all([
353
- hasImages(result) ? imagePatches(workId, result, cwd, deps).catch(() => none) : none,
371
+ const [media, previews] = await Promise.all([
372
+ hasMedia(result) ? mediaPatches(workId, result, cwd, deps).catch(() => none) : none,
354
373
  hasPreviews(result) ? previewPatches(workId, result, deps).catch(() => none) : none
355
374
  ]);
356
- return applyPatches(result, images, previews);
375
+ return applyPatches(result, media, previews);
357
376
  }
358
377
  function runOutputs(deps) {
359
378
  const connector = new PreviewConnector(deps);
@@ -379,7 +398,7 @@ function restartDelayMs(crashes) {
379
398
  return Math.min(RESTART_FIRST_MS * 2 ** crashes, RESTART_MAX_MS);
380
399
  }
381
400
  function isCloudflared(name) {
382
- return basename(name.trim().replace(/\\/g, "/")).toLowerCase().startsWith("cloudflared");
401
+ return basename2(name.trim().replace(/\\/g, "/")).toLowerCase().startsWith("cloudflared");
383
402
  }
384
403
  function processNameOf(pid, platform = process.platform) {
385
404
  return new Promise((done) => {
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-SBYSVZ7J.js";
7
7
  import {
8
8
  VERSION
9
- } from "./chunk-6CUPNFNR.js";
9
+ } from "./chunk-SOM5GPW2.js";
10
10
  import {
11
11
  getOrigin,
12
12
  readCredentials,
@@ -18,13 +18,55 @@ var CHECK_BACK_MAX_MINUTES = 3 * 24 * 60;
18
18
  var CHECK_BACK_WHY_MAX = 300;
19
19
  var RUN_IMAGES_MAX = 6;
20
20
  var RUN_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
21
- var RUN_IMAGE_TYPES = { png: "image/png", jpg: "image/jpeg", webp: "image/webp" };
21
+ var RUN_FILES_MAX = 6;
22
+ var RUN_FILE_MAX_BYTES = 20 * 1024 * 1024;
23
+ var RUN_MEDIA_CLASSES = {
24
+ image: { max: RUN_IMAGES_MAX, maxBytes: RUN_IMAGE_MAX_BYTES },
25
+ file: { max: RUN_FILES_MAX, maxBytes: RUN_FILE_MAX_BYTES }
26
+ };
27
+ var startsWith = (bytes, at, want) => want.every((b, j) => bytes[at + j] === b);
28
+ var ascii = (word) => [...word].map((c) => c.charCodeAt(0));
29
+ var PROOFS = {
30
+ png: (bytes) => startsWith(bytes, 0, [137, 80, 78, 71, 13, 10, 26, 10]),
31
+ jpg: (bytes) => startsWith(bytes, 0, [255, 216, 255]),
32
+ webp: (bytes) => startsWith(bytes, 0, ascii("RIFF")) && startsWith(bytes, 8, ascii("WEBP")),
33
+ pdf: (bytes) => startsWith(bytes, 0, ascii("%PDF-")),
34
+ // A docx, an xlsx and a pptx are each a zip: the bytes say zip, the name says which.
35
+ zip: (bytes) => startsWith(bytes, 0, [80, 75, 3, 4]),
36
+ text: (bytes) => {
37
+ if (bytes.includes(0)) return false;
38
+ try {
39
+ new TextDecoder("utf-8", { fatal: true }).decode(bytes);
40
+ return true;
41
+ } catch {
42
+ return false;
43
+ }
44
+ }
45
+ };
46
+ var RUN_MEDIA_TYPES = {
47
+ png: { mime: "image/png", class: "image", proof: "png" },
48
+ jpg: { mime: "image/jpeg", class: "image", proof: "jpg" },
49
+ webp: { mime: "image/webp", class: "image", proof: "webp" },
50
+ pdf: { mime: "application/pdf", class: "file", proof: "pdf" },
51
+ docx: { mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", class: "file", proof: "zip" },
52
+ xlsx: { mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", class: "file", proof: "zip" },
53
+ pptx: { mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation", class: "file", proof: "zip" },
54
+ csv: { mime: "text/csv", class: "file", proof: "text" },
55
+ txt: { mime: "text/plain", class: "file", proof: "text" },
56
+ md: { mime: "text/markdown", class: "file", proof: "text" }
57
+ };
58
+ var EXTS = Object.keys(RUN_MEDIA_TYPES);
22
59
  function imageExt(bytes) {
23
- const at = (i, ...want) => want.every((b, j) => bytes[i + j] === b);
24
- if (at(0, 137, 80, 78, 71, 13, 10, 26, 10)) return "png";
25
- if (at(0, 255, 216, 255)) return "jpg";
26
- if (at(0, 82, 73, 70, 70) && at(8, 87, 69, 66, 80)) return "webp";
27
- return null;
60
+ return EXTS.find((ext) => RUN_MEDIA_TYPES[ext].class === "image" && PROOFS[RUN_MEDIA_TYPES[ext].proof](bytes)) ?? null;
61
+ }
62
+ function mediaExt(bytes, name) {
63
+ const image = imageExt(bytes);
64
+ if (image) return image;
65
+ const dot = name?.lastIndexOf(".") ?? -1;
66
+ const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
67
+ if (!Object.hasOwn(RUN_MEDIA_TYPES, ext)) return null;
68
+ const type = RUN_MEDIA_TYPES[ext];
69
+ return type.class === "file" && PROOFS[type.proof](bytes) ? ext : null;
28
70
  }
29
71
  var RUN_MEDIA_KEY = runMediaPattern("[0-9a-f-]{36}\\/[0-9a-f-]{36}\\/");
30
72
  var RUN_MEDIA_FILE = runMediaPattern("");
@@ -38,8 +80,12 @@ function isPort(v) {
38
80
  function isPreviewPath(v) {
39
81
  return typeof v === "string" && v.length <= 400 && v.startsWith("/") && !v.startsWith("//") && !/[\s\\]/.test(v);
40
82
  }
83
+ function fileTypes() {
84
+ const files = EXTS.filter((ext) => RUN_MEDIA_TYPES[ext].class === "file");
85
+ return `${files.slice(0, -1).join(", ")} or ${files.at(-1)}`;
86
+ }
41
87
  function runMediaPattern(folder) {
42
- return new RegExp(`^${folder}[0-9a-f-]{36}\\.(${Object.keys(RUN_IMAGE_TYPES).join("|")})$`);
88
+ return new RegExp(`^${folder}[0-9a-f-]{36}\\.(${Object.keys(RUN_MEDIA_TYPES).join("|")})$`);
43
89
  }
44
90
  var RESULT_INSTRUCTION = [
45
91
  "When you finish, end your final message with a fenced block tagged cloop-result containing JSON, for example:",
@@ -55,6 +101,7 @@ var RESULT_INSTRUCTION = [
55
101
  var MACHINE_RESULT_INSTRUCTION = [
56
102
  RESULT_INSTRUCTION,
57
103
  `To show the owner a picture, such as a screenshot of a UI change or a result a picture explains better than words, save it as a PNG, JPEG or WebP file outside the repository (for example in /tmp) and list it as an output: {"kind": "image", "title": "The new sign-in page", "path": "/tmp/sign-in.png"}, with the file's absolute path. Cloop uploads the file and shows it on the run. At most ${RUN_IMAGES_MAX} images, each under ${RUN_IMAGE_MAX_BYTES / (1024 * 1024)} MB. On a Cloop Box, take a picture of a website with the cloop \`browser\` tool: action screenshot shows you the page, and with a title Cloop also attaches the picture to this run and shows it to the owner. You need not list it in your outputs. Use the Playwright browser tool only for a page on localhost, and list its file by path.`,
104
+ `To hand the owner a file you made, such as a spreadsheet, a deck, a document, a PDF or a CSV, list it as an output: {"kind": "file", "title": "Converge model", "path": "/abs/path/Converge_Model.xlsx"}, with the file's absolute path. Cloop uploads it and the owner downloads it from the Task. Never give the owner a path on this machine as the deliverable: they cannot open it. A file is one of ${fileTypes()}, named with its type's extension. At most ${RUN_FILES_MAX} files, each under ${RUN_FILE_MAX_BYTES / (1024 * 1024)} MB.`,
58
105
  `To let the owner open a web app or page you are running on this machine, such as a dev server, leave the server running after your turn ends: start it in the background, detached from your shell (for example \`nohup npm run dev -- --port 5173 > /tmp/dev.log 2>&1 &\`), and check it answers on its port. Then list it as an output: {"kind": "preview", "title": "The new sign-in page", "port": 5173, "path": "/sign-in"}, with the port it listens on and an optional path to open first. Cloop gives the owner a private link to it for ${PREVIEW_HOURS} hours while this machine is on, or ${BOX_PREVIEW_HOURS} hours on a Cloop Box, where a live preview keeps the box awake: say how long when you give the link. At most ${RUN_PREVIEWS_MAX} previews a run.`,
59
106
  `When you started something that keeps running after this turn (a build, a deploy, a long job) or you wait on something outside, do not wait in the turn: add "check_back": {"in_minutes": 120, "why": "Read the training log and report the score."} to the block. Cloop sends you a message in this conversation then, with your why, and you carry on from there. Give ${CHECK_BACK_MIN_MINUTES} to ${CHECK_BACK_MAX_MINUTES} minutes. Leave it out when the work is done.`
60
107
  ].join("\n");
@@ -116,6 +163,9 @@ function readOutput(o) {
116
163
  if (!text(out.path, 400)) return null;
117
164
  return { kind: "image", title, path: out.path, ...media ? { media } : {} };
118
165
  }
166
+ // Only the runner writes a file's `media` or `unsent`, after this read: a run that wrote its own claims nothing.
167
+ case "file":
168
+ return text(out.path, 400) ? { kind: "file", title, path: out.path } : null;
119
169
  case "preview":
120
170
  if (!isPort(out.port) || out.path !== void 0 && !isPreviewPath(out.path)) return null;
121
171
  return {
@@ -3567,10 +3617,10 @@ function readRunRecords(file = localRunsFilePath()) {
3567
3617
  }
3568
3618
 
3569
3619
  export {
3570
- RUN_IMAGES_MAX,
3571
- RUN_IMAGE_MAX_BYTES,
3572
- RUN_IMAGE_TYPES,
3620
+ RUN_MEDIA_CLASSES,
3621
+ RUN_MEDIA_TYPES,
3573
3622
  imageExt,
3623
+ mediaExt,
3574
3624
  RUN_PREVIEWS_MAX,
3575
3625
  MACHINE_RESULT_INSTRUCTION,
3576
3626
  readRunResult,
@@ -2,17 +2,17 @@
2
2
  import {
3
3
  findRun,
4
4
  ownHarness
5
- } from "./chunk-HCAHMQC3.js";
5
+ } from "./chunk-FE2CVSWX.js";
6
6
  import {
7
7
  lockThreadsFile,
8
8
  threadsFilePath
9
- } from "./chunk-HB76TZWH.js";
9
+ } from "./chunk-TZDLUM3E.js";
10
10
  import {
11
11
  localRunsFilePath,
12
12
  readRunRecords,
13
13
  runHarness,
14
14
  takeoverSummary
15
- } from "./chunk-FHAIBI3Z.js";
15
+ } from "./chunk-XAKDSXMW.js";
16
16
  import {
17
17
  sanitizeLabel
18
18
  } from "./chunk-VK6GV757.js";
@@ -54,17 +54,17 @@ import {
54
54
  which,
55
55
  workFolder,
56
56
  workFolderLine
57
- } from "./chunk-M2BOHVUC.js";
57
+ } from "./chunk-EWCRSUJM.js";
58
58
  import "./chunk-BI2Y5ZCL.js";
59
- import "./chunk-HB76TZWH.js";
60
- import "./chunk-FHAIBI3Z.js";
59
+ import "./chunk-TZDLUM3E.js";
60
+ import "./chunk-XAKDSXMW.js";
61
61
  import "./chunk-VK6GV757.js";
62
62
  import "./chunk-365HFCQQ.js";
63
63
  import "./chunk-PKIEWBR7.js";
64
- import "./chunk-2QKGVFWN.js";
65
- import "./chunk-TKWZ6GLL.js";
64
+ import "./chunk-6Z22QRZA.js";
65
+ import "./chunk-VXBAFPY4.js";
66
66
  import "./chunk-SBYSVZ7J.js";
67
- import "./chunk-6CUPNFNR.js";
67
+ import "./chunk-SOM5GPW2.js";
68
68
  import "./chunk-D5UZW42X.js";
69
69
  export {
70
70
  DEFAULT_T3_URL,
@@ -7,17 +7,17 @@ import {
7
7
  runnerOrigin,
8
8
  stopService,
9
9
  unitOrigin
10
- } from "./chunk-M2BOHVUC.js";
10
+ } from "./chunk-EWCRSUJM.js";
11
11
  import "./chunk-BI2Y5ZCL.js";
12
- import "./chunk-HB76TZWH.js";
13
- import "./chunk-FHAIBI3Z.js";
12
+ import "./chunk-TZDLUM3E.js";
13
+ import "./chunk-XAKDSXMW.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-365HFCQQ.js";
16
16
  import "./chunk-PKIEWBR7.js";
17
- import "./chunk-2QKGVFWN.js";
18
- import "./chunk-TKWZ6GLL.js";
17
+ import "./chunk-6Z22QRZA.js";
18
+ import "./chunk-VXBAFPY4.js";
19
19
  import "./chunk-SBYSVZ7J.js";
20
- import "./chunk-6CUPNFNR.js";
20
+ import "./chunk-SOM5GPW2.js";
21
21
  import "./chunk-D5UZW42X.js";
22
22
  export {
23
23
  disconnect,
@@ -2,17 +2,17 @@
2
2
  import {
3
3
  existingRunnerEnvironment,
4
4
  pinExistingRunner
5
- } from "./chunk-M2BOHVUC.js";
5
+ } from "./chunk-EWCRSUJM.js";
6
6
  import "./chunk-BI2Y5ZCL.js";
7
- import "./chunk-HB76TZWH.js";
8
- import "./chunk-FHAIBI3Z.js";
7
+ import "./chunk-TZDLUM3E.js";
8
+ import "./chunk-XAKDSXMW.js";
9
9
  import "./chunk-VK6GV757.js";
10
10
  import "./chunk-365HFCQQ.js";
11
11
  import "./chunk-PKIEWBR7.js";
12
- import "./chunk-2QKGVFWN.js";
13
- import "./chunk-TKWZ6GLL.js";
12
+ import "./chunk-6Z22QRZA.js";
13
+ import "./chunk-VXBAFPY4.js";
14
14
  import "./chunk-SBYSVZ7J.js";
15
- import "./chunk-6CUPNFNR.js";
15
+ import "./chunk-SOM5GPW2.js";
16
16
  import "./chunk-D5UZW42X.js";
17
17
  export {
18
18
  existingRunnerEnvironment,
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-365HFCQQ.js";
5
5
  import {
6
6
  VERSION
7
- } from "./chunk-6CUPNFNR.js";
7
+ } from "./chunk-SOM5GPW2.js";
8
8
  import {
9
9
  applyEnvironmentFlag
10
10
  } from "./chunk-D5UZW42X.js";
@@ -69,7 +69,7 @@ Add --staging to any command to use Cloop staging instead of production.
69
69
  A production machine and a staging machine can run side by side on one computer.
70
70
  `;
71
71
  async function pinExistingRunner() {
72
- const { pinExistingRunner: pin } = await import("./existing-runner-LL6TVNDX.js");
72
+ const { pinExistingRunner: pin } = await import("./existing-runner-KTQ7QWWS.js");
73
73
  const { note } = pin();
74
74
  if (note) console.error(note);
75
75
  }
@@ -77,7 +77,7 @@ async function main() {
77
77
  switch (command) {
78
78
  case "login":
79
79
  case "auth": {
80
- const { loginCommand } = await import("./login-E5DLEZ3N.js");
80
+ const { loginCommand } = await import("./login-5JW54F7H.js");
81
81
  await loginCommand(argv);
82
82
  break;
83
83
  }
@@ -87,61 +87,61 @@ async function main() {
87
87
  break;
88
88
  }
89
89
  case "serve": {
90
- const { startMcpServer } = await import("./mcp-server-DAEOBSRH.js");
90
+ const { startMcpServer } = await import("./mcp-server-NNCIR6YC.js");
91
91
  await startMcpServer();
92
92
  break;
93
93
  }
94
94
  case "statusline": {
95
- const { statuslineCommand } = await import("./statusline-7C6RFBEQ.js");
95
+ const { statuslineCommand } = await import("./statusline-MSNEKQKH.js");
96
96
  statuslineCommand();
97
97
  break;
98
98
  }
99
99
  case "connect": {
100
- const { connectCommand } = await import("./connect-7CEF7GMC.js");
100
+ const { connectCommand } = await import("./connect-MDK3N3SN.js");
101
101
  await connectCommand(argv.slice(1));
102
102
  break;
103
103
  }
104
104
  case "use": {
105
- const { useCommand } = await import("./use-LWHUOHPH.js");
105
+ const { useCommand } = await import("./use-IGVN3B5K.js");
106
106
  process.exitCode = await useCommand(argv.slice(1));
107
107
  break;
108
108
  }
109
109
  case "disconnect": {
110
- const { disconnectCommand } = await import("./disconnect-3E6QHZJF.js");
110
+ const { disconnectCommand } = await import("./disconnect-6JQ3LYUP.js");
111
111
  await disconnectCommand(argv.slice(1));
112
112
  break;
113
113
  }
114
114
  case "box": {
115
- const { boxCommand } = await import("./box-75K3UKFX.js");
115
+ const { boxCommand } = await import("./box-GW7CJC47.js");
116
116
  await boxCommand(argv.slice(1));
117
117
  break;
118
118
  }
119
119
  case "runs": {
120
120
  await pinExistingRunner();
121
- const { runsCommand } = await import("./runs-ULLPAG4X.js");
121
+ const { runsCommand } = await import("./runs-JBC376NJ.js");
122
122
  process.exitCode = runsCommand();
123
123
  break;
124
124
  }
125
125
  case "watch": {
126
126
  await pinExistingRunner();
127
- const { watchCommand } = await import("./runs-ULLPAG4X.js");
127
+ const { watchCommand } = await import("./runs-JBC376NJ.js");
128
128
  process.exitCode = await watchCommand(argv.slice(1));
129
129
  break;
130
130
  }
131
131
  case "takeover": {
132
132
  await pinExistingRunner();
133
- const { takeoverCommand } = await import("./takeover-PBFDJ4UN.js");
133
+ const { takeoverCommand } = await import("./takeover-WY7FPVJ6.js");
134
134
  process.exitCode = await takeoverCommand(argv.slice(1));
135
135
  break;
136
136
  }
137
137
  case "resume": {
138
138
  await pinExistingRunner();
139
- const { resumeCommand } = await import("./runs-ULLPAG4X.js");
139
+ const { resumeCommand } = await import("./runs-JBC376NJ.js");
140
140
  process.exitCode = await resumeCommand(argv.slice(1));
141
141
  break;
142
142
  }
143
143
  case "runner": {
144
- const { runnerCommand } = await import("./runner-U4YNNWWA.js");
144
+ const { runnerCommand } = await import("./runner-UTOJRU4Y.js");
145
145
  await runnerCommand(argv.slice(1));
146
146
  break;
147
147
  }
@@ -3,9 +3,9 @@ import {
3
3
  deviceLogin,
4
4
  loginCommand,
5
5
  refusalSentence
6
- } from "./chunk-TKWZ6GLL.js";
6
+ } from "./chunk-VXBAFPY4.js";
7
7
  import "./chunk-SBYSVZ7J.js";
8
- import "./chunk-6CUPNFNR.js";
8
+ import "./chunk-SOM5GPW2.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  deviceLogin,
@@ -31,7 +31,7 @@ import {
31
31
  } from "./chunk-SBYSVZ7J.js";
32
32
  import {
33
33
  VERSION
34
- } from "./chunk-6CUPNFNR.js";
34
+ } from "./chunk-SOM5GPW2.js";
35
35
  import {
36
36
  getMeshUrl,
37
37
  getToken
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  connectWebhook,
4
4
  runnerCommand
5
- } from "./chunk-2QKGVFWN.js";
6
- import "./chunk-TKWZ6GLL.js";
5
+ } from "./chunk-6Z22QRZA.js";
6
+ import "./chunk-VXBAFPY4.js";
7
7
  import "./chunk-SBYSVZ7J.js";
8
- import "./chunk-6CUPNFNR.js";
8
+ import "./chunk-SOM5GPW2.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  connectWebhook,
@@ -9,8 +9,8 @@ import {
9
9
  runsCommand,
10
10
  sessionFolder,
11
11
  watchCommand
12
- } from "./chunk-HCAHMQC3.js";
13
- import "./chunk-FHAIBI3Z.js";
12
+ } from "./chunk-FE2CVSWX.js";
13
+ import "./chunk-XAKDSXMW.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-D5UZW42X.js";
16
16
  export {
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-VK6GV757.js";
8
8
  import {
9
9
  VERSION
10
- } from "./chunk-6CUPNFNR.js";
10
+ } from "./chunk-SOM5GPW2.js";
11
11
  import {
12
12
  getToken
13
13
  } from "./chunk-D5UZW42X.js";
@@ -9,10 +9,10 @@ import {
9
9
  takeoverDir,
10
10
  writeTakeoverReply,
11
11
  writeTakeoverRequest
12
- } from "./chunk-XUPGFORB.js";
13
- import "./chunk-HCAHMQC3.js";
14
- import "./chunk-HB76TZWH.js";
15
- import "./chunk-FHAIBI3Z.js";
12
+ } from "./chunk-ZPTAWYEW.js";
13
+ import "./chunk-FE2CVSWX.js";
14
+ import "./chunk-TZDLUM3E.js";
15
+ import "./chunk-XAKDSXMW.js";
16
16
  import "./chunk-VK6GV757.js";
17
17
  import "./chunk-SBYSVZ7J.js";
18
18
  import "./chunk-D5UZW42X.js";
@@ -3,20 +3,20 @@ import {
3
3
  DRIVER_NAME,
4
4
  pinExistingRunner,
5
5
  runConnect
6
- } from "./chunk-M2BOHVUC.js";
6
+ } from "./chunk-EWCRSUJM.js";
7
7
  import "./chunk-BI2Y5ZCL.js";
8
- import "./chunk-HB76TZWH.js";
8
+ import "./chunk-TZDLUM3E.js";
9
9
  import {
10
10
  isLocal,
11
11
  readRunnerConfig
12
- } from "./chunk-FHAIBI3Z.js";
12
+ } from "./chunk-XAKDSXMW.js";
13
13
  import "./chunk-VK6GV757.js";
14
14
  import "./chunk-365HFCQQ.js";
15
15
  import "./chunk-PKIEWBR7.js";
16
- import "./chunk-2QKGVFWN.js";
17
- import "./chunk-TKWZ6GLL.js";
16
+ import "./chunk-6Z22QRZA.js";
17
+ import "./chunk-VXBAFPY4.js";
18
18
  import "./chunk-SBYSVZ7J.js";
19
- import "./chunk-6CUPNFNR.js";
19
+ import "./chunk-SOM5GPW2.js";
20
20
  import "./chunk-D5UZW42X.js";
21
21
 
22
22
  // src/commands/use.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloop/runner",
3
- "version": "0.3.55",
3
+ "version": "0.3.57",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Make your computer and your agents Cloop machines: device login, the machine daemon, the Cloop MCP server, and Claude Code hooks.",