@cloop/runner 0.3.27 → 0.3.28

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-ZYU7Y2SE.js";
5
- import "./chunk-MRP3S5DT.js";
4
+ } from "./chunk-7GLIYYIB.js";
5
+ import "./chunk-EGO3GOXI.js";
6
6
  import {
7
7
  DEFAULT_FALLBACK_MODEL,
8
8
  SUBSCRIPTIONS,
@@ -33,7 +33,7 @@ import {
33
33
  systemServices,
34
34
  unitFor,
35
35
  which
36
- } from "./chunk-CC2S6H4W.js";
36
+ } from "./chunk-ER5JS3RP.js";
37
37
  import {
38
38
  MeshSocket,
39
39
  WAKE_TICK_MS,
@@ -48,7 +48,7 @@ import {
48
48
  runnerStatePath,
49
49
  threadsFilePath,
50
50
  writeRunnerState
51
- } from "./chunk-3OF5FEMG.js";
51
+ } from "./chunk-EKLBEP32.js";
52
52
  import {
53
53
  BackgroundReading,
54
54
  BoxToolError,
@@ -64,8 +64,11 @@ import {
64
64
  TOKEN_SCOPE,
65
65
  TOKEN_TTL_MS,
66
66
  addTokens,
67
+ attachedLine,
67
68
  commandFor,
69
+ delivery,
68
70
  failedEnd,
71
+ fetchImages,
69
72
  finalWords,
70
73
  hasResultBlock,
71
74
  isHosted,
@@ -82,13 +85,14 @@ import {
82
85
  runnerDir,
83
86
  runnerEnvironment,
84
87
  runnerPath,
88
+ saveImages,
85
89
  showsOtherThreads,
86
90
  sortedDays,
87
91
  sourceKey,
88
92
  utcWindow,
89
93
  windowsPowerShellEnv,
90
94
  writeBoxConfig
91
- } from "./chunk-PUKYUGWD.js";
95
+ } from "./chunk-3S2ECJTO.js";
92
96
  import {
93
97
  getMachine
94
98
  } from "./chunk-NTXQLEMQ.js";
@@ -97,12 +101,12 @@ import {
97
101
  olderThan
98
102
  } from "./chunk-365HFCQQ.js";
99
103
  import "./chunk-PKIEWBR7.js";
100
- import "./chunk-KDO735VV.js";
101
- import "./chunk-C6EAR65U.js";
104
+ import "./chunk-W4QJS3GR.js";
105
+ import "./chunk-MVMKRRE2.js";
102
106
  import "./chunk-ES5BRAKJ.js";
103
107
  import {
104
108
  VERSION
105
- } from "./chunk-U57DZQSE.js";
109
+ } from "./chunk-3I6NDELL.js";
106
110
  import {
107
111
  getMeshUrl,
108
112
  getOrigin,
@@ -337,6 +341,7 @@ function sseRecord(block) {
337
341
 
338
342
  // src/drivers/cloudroom.ts
339
343
  import { createHash } from "crypto";
344
+ import { join as join2 } from "path";
340
345
 
341
346
  // src/drivers/cloudroom-repos.ts
342
347
  import { execFile, spawn } from "child_process";
@@ -550,13 +555,15 @@ function placeFor(a) {
550
555
  branch: `cloop/${run3}`
551
556
  };
552
557
  }
553
- function launchText(prompt, place) {
558
+ function launchText(prompt, place, photos = "") {
554
559
  const where = place.kind === "worktree" ? `
555
560
 
556
561
  This folder is a git worktree of ${place.repository} on its own branch, \`${place.branch}\`, made for this Task. Other Tasks on this repository work in other folders at the same time. Commit here, and push the branch when the work should leave the box.` : place.named ? `
557
562
 
558
563
  The Task names the repository ${place.named}. This folder is empty: clone it here first.` : "";
559
- return `${prompt}${where}
564
+ return `${prompt}${where}${photos ? `
565
+
566
+ ${photos}` : ""}
560
567
 
561
568
  ${RESULT_INSTRUCTION}`;
562
569
  }
@@ -746,6 +753,7 @@ var sleep = (ms) => new Promise((resolve) => {
746
753
  const timer = setTimeout(resolve, ms);
747
754
  timer.unref?.();
748
755
  });
756
+ var ATTACHMENTS_ROOT = "/code/.attachments";
749
757
  var CloudroomDriver = class {
750
758
  constructor(deps) {
751
759
  this.deps = deps;
@@ -869,6 +877,11 @@ var CloudroomDriver = class {
869
877
  const thread = `cr_${start}`;
870
878
  const prompt = coreRequestId("run", a.work_id);
871
879
  const place = placeFor(a);
880
+ let photos;
881
+ const photosOnce = async () => {
882
+ photos ??= await this.photos(a, place);
883
+ return photos;
884
+ };
872
885
  const go = async () => {
873
886
  const existing2 = await this.core.session(thread);
874
887
  if (existing2?.receipts[prompt]) return existing2;
@@ -898,7 +911,7 @@ var CloudroomDriver = class {
898
911
  if (this.stopped.has(thread)) throw STOPPED_IN_PREPARATION;
899
912
  await this.core.command(thread, "prompts", {
900
913
  request_id: prompt,
901
- text: launchText(a.prompt, place)
914
+ text: launchText(a.prompt, place, (await photosOnce()).line)
902
915
  });
903
916
  this.preparing.delete(thread);
904
917
  if (this.stopped.has(thread))
@@ -911,13 +924,20 @@ var CloudroomDriver = class {
911
924
  };
912
925
  const answer = (resumed) => {
913
926
  this.log(`launch work=${a.work_id} thread=${thread}${resumed ? " resumed" : ""}`);
914
- return { thread_id: thread, resumed, permission: "full" };
927
+ return {
928
+ thread_id: thread,
929
+ resumed,
930
+ permission: "full",
931
+ harness: this.harness,
932
+ ...photos ? delivery(a.attachments, photos.attached) : {}
933
+ };
915
934
  };
916
935
  if (place.kind === "folder") return answer(Boolean(await go()));
917
936
  const existing = await this.core.session(thread);
918
937
  if (existing?.receipts[prompt]) return answer(true);
919
938
  const again = this.preparing.has(thread);
920
939
  if (!again) {
940
+ if (a.attachments?.length) await photosOnce();
921
941
  const prep = this.repos.locked(place.clone, go).then(() => {
922
942
  this.preparing.delete(thread);
923
943
  });
@@ -1061,6 +1081,28 @@ ${line}` : line;
1061
1081
  this.log(`interrupt thread=${id} was_running=${was_running}`);
1062
1082
  return { ok: true, was_running };
1063
1083
  }
1084
+ /**
1085
+ * The Task's photos, saved where the harness can open them, and the line
1086
+ * that names them. Core takes a prompt as text only, so the files are the
1087
+ * way in. Empty when the Task has none.
1088
+ */
1089
+ async photos(a, place) {
1090
+ if (!a.attachments?.length) return { line: "", attached: 0 };
1091
+ const log3 = (line) => this.log(`${line} work=${a.work_id}`);
1092
+ const { images } = await fetchImages(a.attachments, { log: log3, fetch: this.deps.fetch });
1093
+ const dir = join2(this.deps.attachments ?? ATTACHMENTS_ROOT, place.workspace);
1094
+ const paths = await saveImages(images, dir).catch((err) => {
1095
+ log3(`attachments_unsaved reason=${err.message.slice(0, 120)}`);
1096
+ return [];
1097
+ });
1098
+ this.log(
1099
+ `attachments work=${a.work_id} attached=${paths.length} missed=${a.attachments.length - paths.length}`
1100
+ );
1101
+ return {
1102
+ line: attachedLine(paths.length, a.attachments.length - paths.length, paths),
1103
+ attached: paths.length
1104
+ };
1105
+ }
1064
1106
  /**
1065
1107
  * Read the run's history after the last record seen, then follow its live
1066
1108
  * stream. When the stream ends or fails, core stopped or the connection
@@ -1072,7 +1114,10 @@ ${line}` : line;
1072
1114
  * while a child works or a turn waits, and looks again every
1073
1115
  * CHILDREN_WAIT_MS in case a child ends without a reply.
1074
1116
  */
1075
- watch(id, onEvent) {
1117
+ watch(id, report) {
1118
+ const onEvent = (event) => report(
1119
+ event.kind === "settled" || event.kind === "failed" ? { ...event, harness: this.harness } : event
1120
+ );
1076
1121
  let fold = NEW_FOLD;
1077
1122
  let stopped = false;
1078
1123
  let live = null;
@@ -1251,7 +1296,7 @@ import { spawn as spawn2 } from "child_process";
1251
1296
  import { createReadStream } from "fs";
1252
1297
  import { readdir, realpath, stat } from "fs/promises";
1253
1298
  import { homedir, hostname, tmpdir } from "os";
1254
- import { join as join2 } from "path";
1299
+ import { join as join3 } from "path";
1255
1300
  import { createInterface } from "readline";
1256
1301
  var PROBE_TIMEOUT_MS = 1e4;
1257
1302
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
@@ -1366,7 +1411,7 @@ async function probeCodexQuota(bin = "codex", timeoutMs = PROBE_TIMEOUT_MS) {
1366
1411
  }
1367
1412
  async function listLogs(dir, depth, match, found) {
1368
1413
  for (const entry of await readdir(dir, { withFileTypes: true })) {
1369
- const path = join2(dir, entry.name);
1414
+ const path = join3(dir, entry.name);
1370
1415
  if (entry.isFile() && match(entry.name)) found.files.push(path);
1371
1416
  else if (entry.isDirectory() && depth > 1)
1372
1417
  await listLogs(path, depth - 1, match, found).catch(() => {
@@ -1512,8 +1557,8 @@ async function scanTokenUsage(opts = {}) {
1512
1557
  const window = utcWindow(opts.now ?? Date.now(), TOKEN_DAYS);
1513
1558
  const sinceMs = Date.parse(`${window.sinceDay}T00:00:00Z`);
1514
1559
  const days = /* @__PURE__ */ new Map();
1515
- const claudeHome = opts.claudeHome ?? (process.env.CLAUDE_CONFIG_DIR || join2(homedir(), ".claude"));
1516
- const codexHome = opts.codexHome ?? (process.env.CODEX_HOME || join2(homedir(), ".codex"));
1560
+ const claudeHome = opts.claudeHome ?? (process.env.CLAUDE_CONFIG_DIR || join3(homedir(), ".claude"));
1561
+ const codexHome = opts.codexHome ?? (process.env.CODEX_HOME || join3(homedir(), ".codex"));
1517
1562
  const claude = claudeReader(window, days);
1518
1563
  const sources = [
1519
1564
  await scanSource(
@@ -1521,7 +1566,7 @@ async function scanTokenUsage(opts = {}) {
1521
1566
  provider: "claude",
1522
1567
  home: claudeHome,
1523
1568
  // projects/<project>/<session>.jsonl and projects/<project>/<session>/subagents/agent-*.jsonl
1524
- roots: [{ dir: join2(claudeHome, "projects"), depth: 4 }],
1569
+ roots: [{ dir: join3(claudeHome, "projects"), depth: 4 }],
1525
1570
  match: (name) => name.endsWith(".jsonl"),
1526
1571
  reader: () => claude.read
1527
1572
  },
@@ -1532,8 +1577,8 @@ async function scanTokenUsage(opts = {}) {
1532
1577
  provider: "codex",
1533
1578
  home: codexHome,
1534
1579
  roots: [
1535
- { dir: join2(codexHome, "sessions"), depth: 4 },
1536
- { dir: join2(codexHome, "archived_sessions"), depth: 1 }
1580
+ { dir: join3(codexHome, "sessions"), depth: 4 },
1581
+ { dir: join3(codexHome, "archived_sessions"), depth: 1 }
1537
1582
  ],
1538
1583
  match: (name) => name.startsWith("rollout-") && name.endsWith(".jsonl"),
1539
1584
  reader: codexReader(window, days)
@@ -1606,21 +1651,21 @@ var LocalUsage = class {
1606
1651
  import { createReadStream as createReadStream2 } from "fs";
1607
1652
  import { readdir as readdir2, stat as stat2 } from "fs/promises";
1608
1653
  import { homedir as homedir2 } from "os";
1609
- import { join as join3 } from "path";
1654
+ import { join as join4 } from "path";
1610
1655
  import { createInterface as createInterface2 } from "readline";
1611
1656
  var seen = /* @__PURE__ */ new Map();
1612
1657
  var UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
1613
- async function listOutsideSessions(root = join3(homedir2(), ".claude", "projects"), own = /* @__PURE__ */ new Set(), now = Date.now()) {
1658
+ async function listOutsideSessions(root = join4(homedir2(), ".claude", "projects"), own = /* @__PURE__ */ new Set(), now = Date.now()) {
1614
1659
  const files = [];
1615
1660
  for (const project of await readdir2(root, { withFileTypes: true }).catch(() => [])) {
1616
1661
  if (!project.isDirectory()) continue;
1617
- for (const entry of await readdir2(join3(root, project.name), { withFileTypes: true }).catch(
1662
+ for (const entry of await readdir2(join4(root, project.name), { withFileTypes: true }).catch(
1618
1663
  () => []
1619
1664
  )) {
1620
1665
  if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
1621
1666
  const id = entry.name.slice(0, -6);
1622
1667
  if (!UUID.test(id) || own.has(id)) continue;
1623
- const path = join3(root, project.name, entry.name);
1668
+ const path = join4(root, project.name, entry.name);
1624
1669
  const info = await stat2(path).catch(() => null);
1625
1670
  if (info && info.mtimeMs >= now - 7 * 864e5)
1626
1671
  files.push({ id, project: project.name.slice(0, 200), file: path, mtime: info.mtimeMs });
@@ -1736,7 +1781,7 @@ import {
1736
1781
  symlinkSync
1737
1782
  } from "fs";
1738
1783
  import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
1739
- import { join as join4 } from "path";
1784
+ import { join as join5 } from "path";
1740
1785
  var SKILL_DIRS = [".agents/skills", ".claude/skills", ".codex/skills"];
1741
1786
  var GUIDE_FILES = [".agents/AGENTS.md", ".claude/CLAUDE.md", ".codex/AGENTS.md"];
1742
1787
  var SKILLS_CAP_BYTES = 25 * 1024 * 1024;
@@ -1754,13 +1799,13 @@ function findSetup(home) {
1754
1799
  for (const dir of SKILL_DIRS) {
1755
1800
  let entries;
1756
1801
  try {
1757
- entries = readdirSync(join4(home, dir)).sort();
1802
+ entries = readdirSync(join5(home, dir)).sort();
1758
1803
  } catch {
1759
1804
  continue;
1760
1805
  }
1761
1806
  for (const name of entries) {
1762
- const path = join4(home, dir, name);
1763
- if (names.has(name) || !existsSync2(join4(path, "SKILL.md"))) continue;
1807
+ const path = join5(home, dir, name);
1808
+ if (names.has(name) || !existsSync2(join5(path, "SKILL.md"))) continue;
1764
1809
  const real = realpath2(path);
1765
1810
  if (!real || reals.has(real)) continue;
1766
1811
  names.add(name);
@@ -1768,15 +1813,15 @@ function findSetup(home) {
1768
1813
  skills.push({ name, path: real });
1769
1814
  }
1770
1815
  }
1771
- const guide = GUIDE_FILES.map((file) => realpath2(join4(home, file))).find((p) => p !== null) ?? null;
1816
+ const guide = GUIDE_FILES.map((file) => realpath2(join5(home, file))).find((p) => p !== null) ?? null;
1772
1817
  return { skills, guide };
1773
1818
  }
1774
1819
  function stage(setup) {
1775
- const dir = mkdtempSync(join4(tmpdir2(), "cloop-setup-"));
1776
- mkdirSync2(join4(dir, ".agents", "skills"), { recursive: true });
1820
+ const dir = mkdtempSync(join5(tmpdir2(), "cloop-setup-"));
1821
+ mkdirSync2(join5(dir, ".agents", "skills"), { recursive: true });
1777
1822
  for (const skill of setup.skills)
1778
- symlinkSync(skill.path, join4(dir, ".agents", "skills", skill.name), "junction");
1779
- if (setup.guide) copyFileSync(setup.guide, join4(dir, ".agents", "owner-guide.md"));
1823
+ symlinkSync(skill.path, join5(dir, ".agents", "skills", skill.name), "junction");
1824
+ if (setup.guide) copyFileSync(setup.guide, join5(dir, ".agents", "owner-guide.md"));
1780
1825
  return dir;
1781
1826
  }
1782
1827
  async function packSkills(home = homedir3(), capBytes = SKILLS_CAP_BYTES, tarBin = "tar") {
@@ -1936,10 +1981,10 @@ function readText(path) {
1936
1981
  return "";
1937
1982
  }
1938
1983
  }
1939
- function readRemoteMcp(home = homedir3(), codexHome = process.env.CODEX_HOME || join4(home, ".codex")) {
1984
+ function readRemoteMcp(home = homedir3(), codexHome = process.env.CODEX_HOME || join5(home, ".codex")) {
1940
1985
  return remoteMcp([
1941
- ...claudeRemoteMcp(readText(join4(home, ".claude.json"))),
1942
- ...codexRemoteMcp(readText(join4(codexHome, "config.toml")))
1986
+ ...claudeRemoteMcp(readText(join5(home, ".claude.json"))),
1987
+ ...codexRemoteMcp(readText(join5(codexHome, "config.toml")))
1943
1988
  ]);
1944
1989
  }
1945
1990
  async function sendSkills(tar, deps) {
@@ -2026,7 +2071,7 @@ import {
2026
2071
  writeFileSync
2027
2072
  } from "fs";
2028
2073
  import { homedir as homedir4 } from "os";
2029
- import { dirname, join as join5 } from "path";
2074
+ import { dirname, join as join6 } from "path";
2030
2075
  var REGISTRY_LATEST = "https://registry.npmjs.org/@cloop/runner/latest";
2031
2076
  var FIRST_CHECK_MS = 10 * 6e4;
2032
2077
  var CHECK_EVERY_MS = 6 * 36e5;
@@ -2066,10 +2111,10 @@ function updateDir(env) {
2066
2111
  return runnerPath(env, process.env.CLOOP_UPDATE_DIR, (dir) => dir);
2067
2112
  }
2068
2113
  function updateLogPath() {
2069
- return join5(updateDir(), "update.log");
2114
+ return join6(updateDir(), "update.log");
2070
2115
  }
2071
2116
  function statePath(env) {
2072
- return join5(updateDir(env), "update.json");
2117
+ return join6(updateDir(env), "update.json");
2073
2118
  }
2074
2119
  function readFailed() {
2075
2120
  try {
@@ -2117,7 +2162,7 @@ var adoptWords = (npx, to, kind) => [
2117
2162
  kind
2118
2163
  ];
2119
2164
  function adoptScriptPath() {
2120
- return join5(updateDir(), "adopt.cmd");
2165
+ return join6(updateDir(), "adopt.cmd");
2121
2166
  }
2122
2167
  function adoptScript(npx, to, kind, log3) {
2123
2168
  return [
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/version.ts
4
- var VERSION = true ? "0.3.27" : "0.0.0-dev";
4
+ var VERSION = true ? "0.3.28" : "0.0.0-dev";
5
5
 
6
6
  export {
7
7
  VERSION