@cloop/runner 0.3.23 → 0.3.27

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 (29) hide show
  1. package/README.md +2 -2
  2. package/dist/box-TENZ3P6J.js +2708 -0
  3. package/dist/{chunk-YEO27QQP.js → chunk-365HFCQQ.js} +1 -1
  4. package/dist/{chunk-Z7WF67JW.js → chunk-3OF5FEMG.js} +8 -3
  5. package/dist/{chunk-RKR55PPC.js → chunk-C6EAR65U.js} +1 -1
  6. package/dist/{chunk-IITOGOV7.js → chunk-CC2S6H4W.js} +206 -56
  7. package/dist/{chunk-OZN4V4GC.js → chunk-KDO735VV.js} +5 -5
  8. package/dist/{chunk-IJH4O27H.js → chunk-KYGYU5G2.js} +65 -2
  9. package/dist/{chunk-A5SHBJHU.js → chunk-MRP3S5DT.js} +1 -1
  10. package/dist/{chunk-R3CLO2FB.js → chunk-PKIEWBR7.js} +2 -0
  11. package/dist/{chunk-TNNAPOD5.js → chunk-PUKYUGWD.js} +121 -81
  12. package/dist/{chunk-BKPSZTPK.js → chunk-U57DZQSE.js} +1 -1
  13. package/dist/{chunk-H4WR3GSK.js → chunk-ZYU7Y2SE.js} +6 -6
  14. package/dist/{connect-5AYRHDDA.js → connect-YAFC76SG.js} +9 -8
  15. package/dist/{disconnect-UEH44J7T.js → disconnect-AJBQUDE3.js} +9 -8
  16. package/dist/existing-runner-FWDDD3L2.js +21 -0
  17. package/dist/{hook-session-start-DJ6W2NCO.js → hook-session-start-5JYNMGX4.js} +5 -1
  18. package/dist/index.js +24 -24
  19. package/dist/{login-ECXACUOZ.js → login-TALFCKAD.js} +2 -2
  20. package/dist/{mcp-server-FMYWDRGP.js → mcp-server-RUK3JL4O.js} +5 -5
  21. package/dist/{read-permissions-SPOKGVLO.js → read-permissions-EGSGI4HL.js} +1 -1
  22. package/dist/{runner-PV2WK3ZE.js → runner-GOT6CIJW.js} +3 -3
  23. package/dist/{runs-JCDJL7WU.js → runs-SUZJHP7M.js} +2 -2
  24. package/dist/{statusline-TBZIUD3P.js → statusline-XHSO6GCX.js} +1 -1
  25. package/dist/{takeover-2HUC4IOI.js → takeover-B63GSUZW.js} +4 -4
  26. package/dist/{use-W45QOQUI.js → use-L4CIPDJZ.js} +10 -9
  27. package/package.json +2 -2
  28. package/dist/box-EUWQ7RT5.js +0 -1121
  29. package/dist/existing-runner-CO7FNUAW.js +0 -20
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ConnectFailure,
4
4
  deviceLogin
5
- } from "./chunk-RKR55PPC.js";
5
+ } from "./chunk-C6EAR65U.js";
6
6
  import {
7
7
  ApiError,
8
8
  ReauthError,
@@ -51,14 +51,14 @@ function storedLabel(path) {
51
51
  } catch {
52
52
  }
53
53
  throw new Error(
54
- `local_file_unreadable: Cannot read the existing runner file at ${path}. Run cloop connect --webhook <endpoint> --name <different-name>.`
54
+ `local_file_unreadable: Cannot read the existing cloud agent file at ${path}. Run cloop connect --webhook <endpoint> --name <different-name>.`
55
55
  );
56
56
  }
57
57
  function assertNoPathCollision(path, label) {
58
58
  const existingLabel = storedLabel(path);
59
59
  if (existingLabel && existingLabel !== label) {
60
60
  throw new Error(
61
- `local_file_collision: Runner labels "${existingLabel}" and "${label}" use the same local file ${path}. Run cloop connect --webhook <endpoint> --name <different-name>.`
61
+ `local_file_collision: Cloud agent labels "${existingLabel}" and "${label}" use the same local file ${path}. Run cloop connect --webhook <endpoint> --name <different-name>.`
62
62
  );
63
63
  }
64
64
  }
@@ -259,7 +259,7 @@ async function connectWebhook(argv, attempt) {
259
259
  );
260
260
  }
261
261
  if (existing?.verified) {
262
- console.log(`Cloop runner ${name} is already a verified cloud agent.`);
262
+ console.log(`Cloop machine ${name} is already a verified cloud agent.`);
263
263
  return;
264
264
  }
265
265
  if (!existing || argv.includes("--rotate-secret")) {
@@ -303,7 +303,7 @@ The command will now wait for your endpoint to answer while you set it up.`
303
303
  attempt.step = "webhook_verify";
304
304
  await waitForVerification(name);
305
305
  console.log(`[workstation:cloud-connect] Verified ${name}.`);
306
- console.log(`Cloop runner ${name} is a verified cloud agent.`);
306
+ console.log(`Cloop machine ${name} is a verified cloud agent.`);
307
307
  }
308
308
  async function runnerCommand(argv) {
309
309
  switch (argv[0]) {
@@ -1,5 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // src/wake.ts
4
+ var WAKE_TICK_MS = 5e3;
5
+ var SLEEP_GAP_MS = 3e4;
6
+ var systemClocks = { wall: () => Date.now(), mono: () => performance.now() };
7
+ function wakeWatch(clocks = systemClocks) {
8
+ let wall = clocks.wall();
9
+ let mono = clocks.mono();
10
+ return () => {
11
+ const nowWall = clocks.wall();
12
+ const nowMono = clocks.mono();
13
+ const gap = nowWall - wall - (nowMono - mono);
14
+ wall = nowWall;
15
+ mono = nowMono;
16
+ return gap > SLEEP_GAP_MS ? { slept_ms: Math.round(gap), woke_at: new Date(nowWall).toISOString() } : null;
17
+ };
18
+ }
19
+
3
20
  // src/mesh-socket.ts
4
21
  var WS_OPEN = 1;
5
22
  function backoffDelay(attempt, { base = 1e3, max = 6e4, jitter = 0.2 } = {}, rand = Math.random) {
@@ -7,6 +24,15 @@ function backoffDelay(attempt, { base = 1e3, max = 6e4, jitter = 0.2 } = {}, ran
7
24
  const spread = raw * jitter;
8
25
  return Math.round(raw - spread + rand() * spread * 2);
9
26
  }
27
+ var CALL_GRACE_MS = 15e3;
28
+ var PING_RTT_MAX_MS = 1e4;
29
+ var PING_CLOCKS_AGREE_MS = 1e3;
30
+ function freshness(deadline, now, offset) {
31
+ if (deadline === void 0 || offset === null) return "fresh";
32
+ const meshNow = now + offset;
33
+ if (meshNow <= deadline) return "fresh";
34
+ return meshNow > deadline + CALL_GRACE_MS ? "expired" : "late";
35
+ }
10
36
  function wsUrl(meshUrl, sessionKey, kind) {
11
37
  const base = meshUrl.replace(/^http/, "ws").replace(/\/+$/, "");
12
38
  const kindParam = kind && kind !== "agent" ? `&kind=${encodeURIComponent(kind)}` : "";
@@ -26,6 +52,8 @@ var MeshSocket = class {
26
52
  token;
27
53
  /** The newest beat the caller gave, sent again each time the socket opens. */
28
54
  presence = null;
55
+ ping_ = null;
56
+ offset = null;
29
57
  /** Connect again with a new device token, after a refusal of the old one. */
30
58
  restart(token) {
31
59
  this.token = token;
@@ -54,6 +82,7 @@ var MeshSocket = class {
54
82
  this.open = true;
55
83
  this.attempt = 0;
56
84
  if (this.presence) this.send({ type: "presence", ...this.presence });
85
+ if (this.opts.kind === "workstation") this.ping();
57
86
  this.opts.onOpen?.();
58
87
  });
59
88
  ws.on("message", (data) => this.handleMessage(data));
@@ -84,13 +113,19 @@ var MeshSocket = class {
84
113
  type: "call",
85
114
  id: frame.id,
86
115
  tool: frame.tool,
87
- args: frame.args ?? {}
116
+ args: frame.args ?? {},
117
+ ...typeof frame.deadline === "number" && Number.isFinite(frame.deadline) ? { deadline: frame.deadline } : {}
88
118
  });
89
119
  }
90
120
  return;
91
121
  }
92
122
  if (frame.type === "ack") {
93
- if (typeof frame.of === "string") this.opts.onAck?.(frame.of, frame.ok !== false);
123
+ if (frame.of === "ping") this.measureOffset(frame.now);
124
+ else if (typeof frame.of === "string") this.opts.onAck?.(frame.of, frame.ok !== false);
125
+ return;
126
+ }
127
+ if (frame.type === "result_ack") {
128
+ if (typeof frame.id === "string") this.opts.onResultAck?.(frame.id);
94
129
  return;
95
130
  }
96
131
  if (frame.type !== "delegate" && frame.type !== "dm") return;
@@ -112,6 +147,31 @@ var MeshSocket = class {
112
147
  }, delay);
113
148
  this.timer.unref?.();
114
149
  }
150
+ /**
151
+ * Send a ping and time its round trip. Only a ping this socket sent and
152
+ * timed measures the offset, never a queued call frame, whose delay is
153
+ * exactly what the offset must not absorb.
154
+ */
155
+ ping() {
156
+ const clocks = this.opts.clocks ?? systemClocks;
157
+ const sent = { wall: clocks.wall(), mono: clocks.mono() };
158
+ if (this.send({ type: "ping" })) this.ping_ = sent;
159
+ }
160
+ /** The mesh's clock minus this machine's, from the latest timed ping. Null until one answers with its clock. */
161
+ clockOffset() {
162
+ return this.offset;
163
+ }
164
+ measureOffset(meshNow) {
165
+ const sent = this.ping_;
166
+ this.ping_ = null;
167
+ if (!sent || typeof meshNow !== "number" || !Number.isFinite(meshNow)) return;
168
+ const clocks = this.opts.clocks ?? systemClocks;
169
+ const rtt = clocks.mono() - sent.mono;
170
+ const wallRtt = clocks.wall() - sent.wall;
171
+ if (rtt < 0 || wallRtt > PING_RTT_MAX_MS || Math.abs(wallRtt - rtt) > PING_CLOCKS_AGREE_MS)
172
+ return;
173
+ this.offset = Math.round(meshNow - (sent.wall + rtt / 2));
174
+ }
115
175
  isConnected() {
116
176
  return this.open && this.ws?.readyState === WS_OPEN;
117
177
  }
@@ -152,6 +212,9 @@ async function defaultSocketFactory() {
152
212
  }
153
213
 
154
214
  export {
215
+ WAKE_TICK_MS,
216
+ wakeWatch,
217
+ freshness,
155
218
  MeshSocket,
156
219
  defaultSocketFactory
157
220
  };
@@ -9,7 +9,7 @@ import {
9
9
  runHarness,
10
10
  runLogDir,
11
11
  runLogPath
12
- } from "./chunk-TNNAPOD5.js";
12
+ } from "./chunk-PUKYUGWD.js";
13
13
  import {
14
14
  sanitizeLabel,
15
15
  stripControl
@@ -29,6 +29,8 @@ var READ_TOOLS = [
29
29
  "mcp__cloop__get_task_context",
30
30
  "mcp__cloop__list_tasks",
31
31
  "mcp__cloop__search",
32
+ // Lists and reads Cloop's playbooks; a skill writes nothing itself.
33
+ "mcp__cloop__skill",
32
34
  ...READ_PREFIXES.map((prefix) => `Bash(${prefix} *)`)
33
35
  ];
34
36
  var FLAGS = {
@@ -63,26 +63,80 @@ function serviceIdentity(kind, env) {
63
63
  };
64
64
  }
65
65
 
66
+ // src/runner-config.ts
67
+ import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
68
+ import { dirname, join as join2 } from "path";
69
+ var BOX_FILE = "box.json";
70
+ function boxPath(env = runnerEnvironment()) {
71
+ return runnerPath(env, process.env.CLOOP_BOX_FILE, (dir) => join2(dir, BOX_FILE));
72
+ }
73
+ function isLocal(cfg) {
74
+ return cfg.driver === "claude-code" || cfg.driver === "codex";
75
+ }
76
+ function isHosted(cfg) {
77
+ return cfg.driver === "cloudroom";
78
+ }
79
+ function isT3(cfg) {
80
+ return cfg.driver === void 0 || cfg.driver === "t3";
81
+ }
82
+ function showsOtherThreads(cfg) {
83
+ return cfg?.hideOtherThreads !== true;
84
+ }
85
+ function otherThreadsChoice(argv, previous) {
86
+ if (argv.includes("--hide-other-threads")) return true;
87
+ if (argv.includes("--show-other-threads")) return false;
88
+ return previous?.hideOtherThreads === true;
89
+ }
90
+ function readRunnerConfig(env) {
91
+ let parsed;
92
+ try {
93
+ parsed = JSON.parse(readFileSync(boxPath(env), "utf-8"));
94
+ } catch {
95
+ return null;
96
+ }
97
+ if (parsed.driver === "claude-code" || parsed.driver === "codex") {
98
+ const ok = typeof parsed.deviceToken === "string" && typeof parsed.environmentId === "string" && typeof parsed.bin === "string" && Array.isArray(parsed.repos);
99
+ return ok ? parsed : null;
100
+ }
101
+ if (parsed.driver === "cloudroom") {
102
+ const ok = ["harness", "coreUrl", "coreToken", "deviceToken", "origin", "environmentId"].every(
103
+ (key) => typeof parsed[key] === "string" && parsed[key]
104
+ );
105
+ return ok && /^[a-z0-9-]{1,40}$/.test(parsed.harness) ? parsed : null;
106
+ }
107
+ if (typeof parsed.t3Url !== "string" || typeof parsed.token !== "string") return null;
108
+ return parsed;
109
+ }
110
+ function writeBoxConfig(cfg) {
111
+ const path = boxPath();
112
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
113
+ const temp = `${path}.${process.pid}.tmp`;
114
+ writeFileSync(temp, `${JSON.stringify(cfg, null, 2)}
115
+ `, { mode: 384 });
116
+ chmodSync(temp, 384);
117
+ renameSync(temp, path);
118
+ }
119
+
66
120
  // src/run-log.ts
67
121
  import {
68
122
  appendFileSync,
69
- chmodSync,
70
- mkdirSync,
123
+ chmodSync as chmodSync2,
124
+ mkdirSync as mkdirSync2,
71
125
  readdirSync,
72
- renameSync,
126
+ renameSync as renameSync2,
73
127
  statSync,
74
128
  unlinkSync
75
129
  } from "fs";
76
- import { dirname, join as join2 } from "path";
130
+ import { dirname as dirname2, join as join3 } from "path";
77
131
  var RUN_LOG_LINE_MAX = 500;
78
132
  var RUN_LOG_MAX_BYTES = 5 * 1024 * 1024;
79
133
  var RUN_LOG_KEEP_MS = 14 * 24 * 36e5;
80
134
  var SAFE_ID = /^[\w-]{1,100}$/;
81
135
  function runLogDir(runsFile) {
82
- return join2(dirname(runsFile), "runs");
136
+ return join3(dirname2(runsFile), "runs");
83
137
  }
84
138
  function runLogPath(dir, workId) {
85
- return SAFE_ID.test(workId) ? join2(dir, `${workId}.log`) : null;
139
+ return SAFE_ID.test(workId) ? join3(dir, `${workId}.log`) : null;
86
140
  }
87
141
  var SECRETS = [
88
142
  [/-----BEGIN [A-Z ]*PRIVATE KEY-----.*/g, "[redacted private key]"],
@@ -143,18 +197,18 @@ function appendRunLog(dir, workId, text3, { now = Date.now(), maxBytes = RUN_LOG
143
197
  if (!path) return;
144
198
  const line = `${stamp(now)} ${logText(text3)}
145
199
  `;
146
- mkdirSync(dir, { recursive: true, mode: 448 });
200
+ mkdirSync2(dir, { recursive: true, mode: 448 });
147
201
  const size = sizeOf(path);
148
- if (size > 0 && size + Buffer.byteLength(line) > maxBytes) renameSync(path, `${path}.1`);
202
+ if (size > 0 && size + Buffer.byteLength(line) > maxBytes) renameSync2(path, `${path}.1`);
149
203
  appendFileSync(path, line, { mode: 384 });
150
204
  }
151
205
  function pruneRunLogs(dir, now = Date.now(), keepMs = RUN_LOG_KEEP_MS) {
152
- mkdirSync(dir, { recursive: true, mode: 448 });
153
- chmodSync(dir, 448);
206
+ mkdirSync2(dir, { recursive: true, mode: 448 });
207
+ chmodSync2(dir, 448);
154
208
  let removed = 0;
155
209
  for (const name of readdirSync(dir)) {
156
210
  if (!/\.log(\.1)?$/.test(name)) continue;
157
- const path = join2(dir, name);
211
+ const path = join3(dir, name);
158
212
  try {
159
213
  if (statSync(path).mtimeMs < now - keepMs) {
160
214
  unlinkSync(path);
@@ -242,7 +296,7 @@ function windowsPowerShellEnv(env = process.env) {
242
296
  // src/t3-bin.ts
243
297
  import { execFileSync as execFileSync2 } from "child_process";
244
298
  import { existsSync, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
245
- import { join as join3 } from "path";
299
+ import { join as join4 } from "path";
246
300
  var CLEAN_ENV = () => ({
247
301
  HOME: process.env.HOME,
248
302
  USER: process.env.USER,
@@ -252,7 +306,7 @@ function defaultT3BinSources(home, stored) {
252
306
  return {
253
307
  env: process.env,
254
308
  home,
255
- appDirs: process.platform === "darwin" ? ["/Applications", join3(home, "Applications")] : [],
309
+ appDirs: process.platform === "darwin" ? ["/Applications", join4(home, "Applications")] : [],
256
310
  onPath: () => whichAll("t3"),
257
311
  ...stored ? { stored } : {}
258
312
  };
@@ -273,9 +327,9 @@ function bundleBinaries(appDir) {
273
327
  return [];
274
328
  }
275
329
  return bundles.flatMap((bundle) => {
276
- const root = join3(appDir, bundle);
330
+ const root = join4(appDir, bundle);
277
331
  try {
278
- return readdirSync2(root, { recursive: true }).filter((rel) => rel === "t3" || rel.endsWith("/t3")).map((rel) => join3(root, rel)).filter(isExecutable);
332
+ return readdirSync2(root, { recursive: true }).filter((rel) => rel === "t3" || rel.endsWith("/t3")).map((rel) => join4(root, rel)).filter(isExecutable);
279
333
  } catch {
280
334
  return [];
281
335
  }
@@ -284,8 +338,8 @@ function bundleBinaries(appDir) {
284
338
  function t3Candidates(serverVersion, sources) {
285
339
  const ordered = [
286
340
  sources.env.T3_BIN,
287
- join3(sources.home, ".t3", "runtime", "versions", serverVersion, "t3"),
288
- join3(sources.env.T3CODE_HOME || join3(sources.home, ".t3"), "bin", "t3"),
341
+ join4(sources.home, ".t3", "runtime", "versions", serverVersion, "t3"),
342
+ join4(sources.env.T3CODE_HOME || join4(sources.home, ".t3"), "bin", "t3"),
289
343
  ...sources.appDirs.flatMap(bundleBinaries),
290
344
  ...sources.onPath(),
291
345
  sources.stored
@@ -513,8 +567,9 @@ var RESULT_INSTRUCTION = [
513
567
  "```cloop-result",
514
568
  '{"summary": "One or two sentences on what you did.", "outputs": [{"kind": "pr", "title": "fix: the thing", "url": "https://github.com/org/repo/pull/1"}], "checks": [{"name": "Tests", "outcome": "passed"}]}',
515
569
  "```",
516
- "An output kind is one of: pr or link (title, url), draft (title, body, optional to, optional url), doc (title, optional url or body), file (title, path). A check outcome is passed, failed or skipped.",
570
+ "An output kind is one of: pr or link (title, url), draft (title, body, optional to, optional url), doc (title, optional url or body), file (title, path), wizard (title, steps). A check outcome is passed, failed or skipped.",
517
571
  "A draft's body is the message itself, as the recipient will read it; if you saved it somewhere (a Gmail draft), put that link in url, never in body. A doc's body is the whole page in GitHub Markdown: headings, lists, bold and tables all show; a table suits one row per item. Give every product, page or source you mention as a full https link.",
572
+ 'A wizard is for steps only the user can do by hand: a sign-in, an app permission, a key from a dashboard, or a change in a dashboard or console you cannot make yourself. When the work needs such a step, return a wizard for it, not only words. A wizard has 1 to 6 steps in order, each {"title", "body" in Markdown, optional https "url"}. Never ask the user to paste a password, key or other secret anywhere. The user sees a wizard as a walkthrough: in your own words, call it a walkthrough, never a wizard.',
518
573
  "List as outputs only what this run made. A PR or page you only read, checked or cited goes in the summary, never in outputs.",
519
574
  "When the ask is to find, compare, summarise or research something, put the whole answer in a doc output with a body, so the owner has one page to read; the summary stays one or two sentences."
520
575
  ].join("\n");
@@ -579,6 +634,8 @@ function cleanOutput(o) {
579
634
  }
580
635
  case "file":
581
636
  return text(out.path, 400) ? { kind: "file", title, path: out.path } : null;
637
+ case "wizard":
638
+ return Array.isArray(out.steps) ? { kind: "wizard", title, steps: out.steps } : null;
582
639
  default:
583
640
  return null;
584
641
  }
@@ -622,6 +679,12 @@ function readRunResult(message) {
622
679
  return none;
623
680
  }
624
681
  }
682
+ function hasResultBlock(text3) {
683
+ return /```cloop-result\s*\n/.test(text3 ?? "");
684
+ }
685
+ function resultText(final, earlier) {
686
+ return (hasResultBlock(final) ? final : hasResultBlock(earlier) ? earlier : final) ?? void 0;
687
+ }
625
688
  function parseRunResult(message) {
626
689
  return readRunResult(message).result;
627
690
  }
@@ -655,6 +718,9 @@ function isProgressSentence(value) {
655
718
  }
656
719
  var PROGRESS_MS = 3e4;
657
720
  var RUN_TEXT_MAX = 4e3;
721
+ function finalWords(text3) {
722
+ return text3.replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").replace(/\n{3,}/g, "\n\n").trim();
723
+ }
658
724
  function nextProgress(clock, text3, now, ms = PROGRESS_MS, force = false) {
659
725
  const summary = (parseRunResult(text3)?.summary ?? text3.split("```cloop-result")[0] ?? "").replace(/\s+/g, " ").trim().slice(0, RUN_TEXT_MAX);
660
726
  if (!isProgressSentence(summary)) return null;
@@ -702,7 +768,7 @@ import { createHash } from "crypto";
702
768
  var TOKEN_SCOPE = "agent session logs on this machine";
703
769
  var MISSING_DIAGNOSTICS = {
704
770
  status: "missing_permission",
705
- hint: "This runner's T3 pairing cannot read token usage. Run `cloop connect` on that machine; if it asks for a pairing link, make one with the diagnostics permission."
771
+ hint: "This machine's T3 pairing cannot read token usage. Run `cloop connect` on that machine; if it asks for a pairing link, make one with the diagnostics permission."
706
772
  };
707
773
  var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
708
774
  var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
@@ -1076,8 +1142,10 @@ function outcomeOf(p) {
1076
1142
  const run2 = latestRun(p.runs ?? []);
1077
1143
  const status = run2?.status ?? "pending";
1078
1144
  const settled = TERMINAL_RUN.has(status) || Boolean(p.thread.settledAt);
1079
- const text3 = (p.messages ?? []).filter((m) => m.role === "assistant" && m.text).at(-1)?.text?.trim();
1080
- const { result, dropped } = readRunResult(text3);
1145
+ const said = (p.messages ?? []).filter((m) => m.role === "assistant" && m.text);
1146
+ const text3 = said.at(-1)?.text?.trim();
1147
+ const block = said.filter((m) => (!run2 || m.runId === run2.id) && hasResultBlock(m.text)).at(-1)?.text?.trim();
1148
+ const { result, dropped } = readRunResult(resultText(text3, block));
1081
1149
  return {
1082
1150
  status,
1083
1151
  settled,
@@ -1880,9 +1948,9 @@ ${RESULT_INSTRUCTION}`
1880
1948
 
1881
1949
  // src/drivers/local.ts
1882
1950
  import { execFile as execFile2, execFileSync as execFileSync4, spawn } from "child_process";
1883
- import { chmodSync as chmodSync2, mkdirSync as mkdirSync2, readFileSync, renameSync as renameSync2, writeFileSync } from "fs";
1951
+ import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync3, writeFileSync as writeFileSync2 } from "fs";
1884
1952
  import { hostname } from "os";
1885
- import { basename, dirname as dirname2, join as join4 } from "path";
1953
+ import { basename, dirname as dirname3, join as join5 } from "path";
1886
1954
  import { createInterface } from "readline";
1887
1955
 
1888
1956
  // src/drivers/harness-check.ts
@@ -1968,7 +2036,7 @@ function failedEnd(harness, run2) {
1968
2036
  return { summary: `${lead}${quoted}"`, ...error };
1969
2037
  }
1970
2038
  function localRunsFilePath(env) {
1971
- return runnerPath(env, process.env.CLOOP_LOCAL_RUNS_FILE, (dir) => join4(dir, "local-runs.json"));
2039
+ return runnerPath(env, process.env.CLOOP_LOCAL_RUNS_FILE, (dir) => join5(dir, "local-runs.json"));
1972
2040
  }
1973
2041
  function pickRepo(repos, repository) {
1974
2042
  if (!repository) {
@@ -2310,7 +2378,7 @@ ${a.text}` : a.text;
2310
2378
  const r = this.runs.get(id);
2311
2379
  const unwatch = () => set.delete(onEvent);
2312
2380
  if (!r) {
2313
- onEvent({ kind: "failed", summary: "This run is not on the runner any more." });
2381
+ onEvent({ kind: "failed", summary: "This run is not on the machine any more." });
2314
2382
  return unwatch;
2315
2383
  }
2316
2384
  if (r.end) {
@@ -2395,6 +2463,7 @@ ${a.text}` : a.text;
2395
2463
  }
2396
2464
  }
2397
2465
  spawnRun(r, prompt, resume) {
2466
+ r.block_text = void 0;
2398
2467
  const dialect = this.dialectOf(r);
2399
2468
  r.used_permission = dialect.permission?.(r);
2400
2469
  const command = commandFor(dialect.bin, dialect.args(r, resume));
@@ -2447,6 +2516,7 @@ ${RESULT_INSTRUCTION}`));
2447
2516
  return;
2448
2517
  case "text":
2449
2518
  r.last_text = item.text.slice(0, 1e5);
2519
+ if (hasResultBlock(item.text)) r.block_text = r.last_text;
2450
2520
  this.progress(r, live, item.text, false);
2451
2521
  return;
2452
2522
  case "tool": {
@@ -2496,11 +2566,11 @@ ${RESULT_INSTRUCTION}`));
2496
2566
  }
2497
2567
  if (code === 0 && live.result?.ok) {
2498
2568
  const text3 = live.result.text?.trim() || r.last_text;
2499
- const { result, dropped } = readRunResult(text3);
2569
+ const { result, dropped } = readRunResult(resultText(text3, r.block_text));
2500
2570
  const lost = droppedLine(dropped, r.work_id);
2501
2571
  if (lost) this.log(lost);
2502
2572
  const { pr, note } = await this.outcome(r, text3);
2503
- const summary = [r.switched, note, text3].filter(Boolean).join(" ").replace(/\s+/g, " ");
2573
+ const summary = finalWords([r.switched, note, text3].filter(Boolean).join("\n\n"));
2504
2574
  await this.end(r, {
2505
2575
  kind: "settled",
2506
2576
  ...result ? { result } : {},
@@ -2677,17 +2747,17 @@ ${RESULT_INSTRUCTION}`));
2677
2747
  return readRunRecords(this.file).filter((r) => !(r.end && Date.parse(r.end.at) < cutoff));
2678
2748
  }
2679
2749
  save() {
2680
- mkdirSync2(dirname2(this.file), { recursive: true, mode: 448 });
2750
+ mkdirSync3(dirname3(this.file), { recursive: true, mode: 448 });
2681
2751
  const tmp = `${this.file}.tmp`;
2682
- writeFileSync(tmp, `${JSON.stringify([...this.runs.values()], null, 2)}
2752
+ writeFileSync2(tmp, `${JSON.stringify([...this.runs.values()], null, 2)}
2683
2753
  `, { mode: 384 });
2684
- chmodSync2(tmp, 384);
2685
- renameSync2(tmp, this.file);
2754
+ chmodSync3(tmp, 384);
2755
+ renameSync3(tmp, this.file);
2686
2756
  }
2687
2757
  };
2688
2758
  function readRunRecords(file = localRunsFilePath()) {
2689
2759
  try {
2690
- const raw = JSON.parse(readFileSync(file, "utf-8"));
2760
+ const raw = JSON.parse(readFileSync2(file, "utf-8"));
2691
2761
  return Array.isArray(raw) ? raw.filter(
2692
2762
  (r) => typeof r?.work_id === "string" && typeof r?.repo === "string"
2693
2763
  ) : [];
@@ -2696,55 +2766,21 @@ function readRunRecords(file = localRunsFilePath()) {
2696
2766
  }
2697
2767
  }
2698
2768
 
2699
- // src/runner-config.ts
2700
- import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync3, writeFileSync as writeFileSync2 } from "fs";
2701
- import { dirname as dirname3, join as join5 } from "path";
2702
- var BOX_FILE = "box.json";
2703
- function boxPath(env = runnerEnvironment()) {
2704
- return runnerPath(env, process.env.CLOOP_BOX_FILE, (dir) => join5(dir, BOX_FILE));
2705
- }
2706
- function isLocal(cfg) {
2707
- return cfg.driver === "claude-code" || cfg.driver === "codex";
2708
- }
2709
- function showsOtherThreads(cfg) {
2710
- return cfg?.hideOtherThreads !== true;
2711
- }
2712
- function otherThreadsChoice(argv, previous) {
2713
- if (argv.includes("--hide-other-threads")) return true;
2714
- if (argv.includes("--show-other-threads")) return false;
2715
- return previous?.hideOtherThreads === true;
2716
- }
2717
- function readRunnerConfig(env) {
2718
- let parsed;
2719
- try {
2720
- parsed = JSON.parse(readFileSync2(boxPath(env), "utf-8"));
2721
- } catch {
2722
- return null;
2723
- }
2724
- if (parsed.driver === "claude-code" || parsed.driver === "codex") {
2725
- const ok = typeof parsed.deviceToken === "string" && typeof parsed.environmentId === "string" && typeof parsed.bin === "string" && Array.isArray(parsed.repos);
2726
- return ok ? parsed : null;
2727
- }
2728
- if (typeof parsed.t3Url !== "string" || typeof parsed.token !== "string") return null;
2729
- return parsed;
2730
- }
2731
- function writeBoxConfig(cfg) {
2732
- const path = boxPath();
2733
- mkdirSync3(dirname3(path), { recursive: true, mode: 448 });
2734
- const temp = `${path}.${process.pid}.tmp`;
2735
- writeFileSync2(temp, `${JSON.stringify(cfg, null, 2)}
2736
- `, { mode: 384 });
2737
- chmodSync3(temp, 384);
2738
- renameSync3(temp, path);
2739
- }
2740
-
2741
2769
  export {
2770
+ RESULT_INSTRUCTION,
2771
+ resultPrUrl,
2772
+ readRunResult,
2773
+ hasResultBlock,
2774
+ resultText,
2742
2775
  RUNTIME_MODES,
2743
2776
  BoxToolError,
2744
2777
  CLOOP_THREAD_PREFIX,
2745
2778
  questionLine,
2746
2779
  RUN_TEXT_MAX,
2780
+ finalWords,
2781
+ nextProgress,
2747
2782
  isYes,
2783
+ HARNESS_LIMIT,
2748
2784
  ENVIRONMENTS,
2749
2785
  environmentOf,
2750
2786
  runnerEnvironment,
@@ -2752,6 +2788,14 @@ export {
2752
2788
  runnerPath,
2753
2789
  cloopCommand,
2754
2790
  serviceIdentity,
2791
+ boxPath,
2792
+ isLocal,
2793
+ isHosted,
2794
+ isT3,
2795
+ showsOtherThreads,
2796
+ otherThreadsChoice,
2797
+ readRunnerConfig,
2798
+ writeBoxConfig,
2755
2799
  runLogDir,
2756
2800
  runLogPath,
2757
2801
  STOPPED_SUMMARY,
@@ -2781,16 +2825,12 @@ export {
2781
2825
  addTokens,
2782
2826
  sortedDays,
2783
2827
  sourceKey,
2828
+ orderThreads,
2784
2829
  T3Driver,
2785
2830
  takeoverSummary,
2786
2831
  runHarness,
2832
+ failedEnd,
2787
2833
  localRunsFilePath,
2788
2834
  LocalDriver,
2789
- readRunRecords,
2790
- boxPath,
2791
- isLocal,
2792
- showsOtherThreads,
2793
- otherThreadsChoice,
2794
- readRunnerConfig,
2795
- writeBoxConfig
2835
+ readRunRecords
2796
2836
  };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/version.ts
4
- var VERSION = true ? "0.3.23" : "0.0.0-dev";
4
+ var VERSION = true ? "0.3.27" : "0.0.0-dev";
5
5
 
6
6
  export {
7
7
  VERSION
@@ -2,17 +2,17 @@
2
2
  import {
3
3
  findRun,
4
4
  ownHarness
5
- } from "./chunk-A5SHBJHU.js";
5
+ } from "./chunk-MRP3S5DT.js";
6
6
  import {
7
7
  lockThreadsFile,
8
8
  threadsFilePath
9
- } from "./chunk-Z7WF67JW.js";
9
+ } from "./chunk-3OF5FEMG.js";
10
10
  import {
11
11
  localRunsFilePath,
12
12
  readRunRecords,
13
13
  runHarness,
14
14
  takeoverSummary
15
- } from "./chunk-TNNAPOD5.js";
15
+ } from "./chunk-PUKYUGWD.js";
16
16
  import {
17
17
  shortMachineName
18
18
  } from "./chunk-NTXQLEMQ.js";
@@ -190,7 +190,7 @@ async function takeoverCommand(args, deps = {}) {
190
190
  try {
191
191
  if (run.pid !== null && (deps.alive ?? processAlive)(run.pid))
192
192
  return fail(
193
- `The runner is not running, but the run's process (pid ${run.pid}) is. Start the runner, or stop the process, then run this again.`,
193
+ `Cloop is not running on this machine, but the run's process (pid ${run.pid}) is. Start Cloop, or stop the process, then run this again.`,
194
194
  "orphan"
195
195
  );
196
196
  endInFile(file, run.work_id, machine, now());
@@ -213,12 +213,12 @@ async function takeoverCommand(args, deps = {}) {
213
213
  const refused = takeTakeoverReply(dir, run.work_id);
214
214
  if (refused)
215
215
  return fail(
216
- `The runner could not stop the run (${refused}). Stop it from Threads, then run: cloop resume ${short}`,
216
+ `The machine could not stop the run (${refused}). Stop it from Threads, then run: cloop resume ${short}`,
217
217
  `refused:${refused}`
218
218
  );
219
219
  if (Date.now() > deadline)
220
220
  return fail(
221
- `The runner did not stop the run. Stop it from Threads, then run: cloop resume ${short}`,
221
+ `The machine did not stop the run. Stop it from Threads, then run: cloop resume ${short}`,
222
222
  "daemon_silent"
223
223
  );
224
224
  await sleep(deps.pollMs ?? 250);
@@ -52,17 +52,18 @@ import {
52
52
  which,
53
53
  workFolder,
54
54
  workFolderLine
55
- } from "./chunk-IITOGOV7.js";
56
- import "./chunk-Z7WF67JW.js";
57
- import "./chunk-TNNAPOD5.js";
55
+ } from "./chunk-CC2S6H4W.js";
56
+ import "./chunk-KYGYU5G2.js";
57
+ import "./chunk-3OF5FEMG.js";
58
+ import "./chunk-PUKYUGWD.js";
58
59
  import "./chunk-NTXQLEMQ.js";
59
60
  import "./chunk-VK6GV757.js";
60
- import "./chunk-YEO27QQP.js";
61
- import "./chunk-R3CLO2FB.js";
62
- import "./chunk-OZN4V4GC.js";
63
- import "./chunk-RKR55PPC.js";
61
+ import "./chunk-365HFCQQ.js";
62
+ import "./chunk-PKIEWBR7.js";
63
+ import "./chunk-KDO735VV.js";
64
+ import "./chunk-C6EAR65U.js";
64
65
  import "./chunk-ES5BRAKJ.js";
65
- import "./chunk-BKPSZTPK.js";
66
+ import "./chunk-U57DZQSE.js";
66
67
  import "./chunk-D5UZW42X.js";
67
68
  export {
68
69
  DEFAULT_T3_URL,