@cloop/runner 0.3.15 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,6 +12,8 @@ cloop install # register the MCP server with Claude Code / others
12
12
 
13
13
  Credentials live in `~/.cloop/credentials.json`. The API origin comes from `CLOOP_ORIGIN`, the stored value, or the staging default.
14
14
 
15
+ `npx -y @cloop/runner@latest connect` makes this machine a runner. As its last step, it adds the remote Cloop MCP server to each Claude Code and Codex on the machine, and signs it in with OAuth on a terminal. It runs the usual lines: `claude mcp add -s user --transport http cloop https://app.mycloop.com/api/mcp/mcp` and `codex mcp add cloop --url https://app.mycloop.com/api/mcp/mcp`, then `claude mcp login cloop` and `codex mcp login cloop`. Staging uses the name `cloop-staging` and `https://mcp-staging.mycloop.com/mcp`. When an entry under any name already has the URL, `connect` adds nothing. This step never makes `connect` fail. Details: `docs/runbooks/cloop-local.md`, "Connect", step 5.
16
+
15
17
  To disconnect a runner, use Disconnect in its ⋯ menu on the Threads page.
16
18
 
17
19
  ### Windows
@@ -5,13 +5,14 @@ import {
5
5
  } from "./chunk-IJH4O27H.js";
6
6
  import {
7
7
  serveTakeovers
8
- } from "./chunk-3J5FFRLN.js";
9
- import "./chunk-NMVZPTFM.js";
8
+ } from "./chunk-7OBTF35R.js";
9
+ import "./chunk-NNPOMXCM.js";
10
10
  import {
11
11
  DEFAULT_FALLBACK_MODEL,
12
12
  T3Client,
13
13
  awaitDaemon,
14
14
  claudeDialect,
15
+ cmdWord,
15
16
  codexDialect,
16
17
  connectCommand,
17
18
  findNpx,
@@ -25,6 +26,7 @@ import {
25
26
  probeClaudePermissions,
26
27
  probeCodex,
27
28
  programFor,
29
+ psQuote,
28
30
  runBoxTool,
29
31
  runSteps,
30
32
  serviceEnv,
@@ -32,7 +34,7 @@ import {
32
34
  systemServices,
33
35
  unitFor,
34
36
  which
35
- } from "./chunk-RT5UZNMQ.js";
37
+ } from "./chunk-HVXCQQWG.js";
36
38
  import {
37
39
  BoxWatch,
38
40
  lockThreadsFile,
@@ -40,7 +42,7 @@ import {
40
42
  runnerStatePath,
41
43
  threadsFilePath,
42
44
  writeRunnerState
43
- } from "./chunk-BGXIAFPO.js";
45
+ } from "./chunk-QINWGIXU.js";
44
46
  import {
45
47
  LocalDriver,
46
48
  T3Driver,
@@ -50,8 +52,9 @@ import {
50
52
  runnerEnvironment,
51
53
  runnerPath,
52
54
  showsOtherThreads,
55
+ windowsPowerShellEnv,
53
56
  writeBoxConfig
54
- } from "./chunk-B2ZI2UWS.js";
57
+ } from "./chunk-R22774MI.js";
55
58
  import {
56
59
  getMachine
57
60
  } from "./chunk-NTXQLEMQ.js";
@@ -60,12 +63,12 @@ import {
60
63
  olderThan
61
64
  } from "./chunk-YEO27QQP.js";
62
65
  import "./chunk-R3CLO2FB.js";
63
- import "./chunk-NYJ6XMD4.js";
64
- import "./chunk-M4Y4YZ46.js";
66
+ import "./chunk-LORK2EOG.js";
67
+ import "./chunk-EIBHDWUG.js";
65
68
  import "./chunk-ES5BRAKJ.js";
66
69
  import {
67
70
  VERSION
68
- } from "./chunk-BLSH7SNK.js";
71
+ } from "./chunk-OBFJRACJ.js";
69
72
  import {
70
73
  getMeshUrl,
71
74
  getToken,
@@ -222,23 +225,45 @@ function recordFailed(version, env) {
222
225
  log(`could not record ${version} as failed: ${err.code ?? err}`);
223
226
  }
224
227
  }
225
- function handOverCommand(platform, npx, to, kind) {
226
- const adopt2 = [
227
- npx,
228
- "-y",
229
- `@cloop/runner@${to}`,
230
- "box",
231
- "adopt",
232
- "--from",
233
- VERSION,
234
- "--kind",
235
- kind
236
- ];
228
+ function handOverCommand(platform, npx, to, kind, script = adoptScriptPath()) {
229
+ if (platform === "win32")
230
+ return [
231
+ "powershell",
232
+ "-NoProfile",
233
+ "-NonInteractive",
234
+ "-Command",
235
+ [
236
+ "$ErrorActionPreference = 'Stop'",
237
+ `Start-Process -WindowStyle Hidden -FilePath (Join-Path $env:WINDIR 'System32\\conhost.exe') -ArgumentList ('--headless ' + (Join-Path $env:WINDIR 'System32\\cmd.exe') + ' /d /c ' + [char]34 + ${psQuote(script)} + [char]34)`
238
+ ].join("; ")
239
+ ];
240
+ const adopt2 = adoptWords(npx, to, kind);
237
241
  return platform === "linux" ? ["systemd-run", "--user", "--scope", "--quiet", "--collect", "--", ...adopt2] : adopt2;
238
242
  }
239
- function servicePath(kind) {
243
+ var adoptWords = (npx, to, kind) => [
244
+ npx,
245
+ "-y",
246
+ `@cloop/runner@${to}`,
247
+ "box",
248
+ "adopt",
249
+ "--from",
250
+ VERSION,
251
+ "--kind",
252
+ kind
253
+ ];
254
+ function adoptScriptPath() {
255
+ return join2(updateDir(), "adopt.cmd");
256
+ }
257
+ function adoptScript(npx, to, kind, log3) {
258
+ return [
259
+ "@echo off",
260
+ `call ${adoptWords(npx, to, kind).map(cmdWord).join(" ")} >> ${cmdWord(log3)} 2>&1`,
261
+ ""
262
+ ].join("\r\n");
263
+ }
264
+ function servicePath(kind, platform) {
240
265
  return installedService({
241
- platform: process.platform,
266
+ platform,
242
267
  kind,
243
268
  environment: runnerEnvironment(),
244
269
  home: homedir2(),
@@ -266,11 +291,11 @@ function fetchVersion(npx, version) {
266
291
  );
267
292
  });
268
293
  }
269
- function selfUpdate(kind) {
294
+ function selfUpdate(kind, platform = process.platform) {
270
295
  let latest = null;
271
296
  let handing = false;
272
297
  let lastWhy = null;
273
- const canDetach = process.platform === "darwin" || process.platform === "linux" && which("systemd-run") !== null;
298
+ const canDetach = platform === "darwin" || platform === "win32" || platform === "linux" && which("systemd-run") !== null;
274
299
  const check = async () => {
275
300
  const read = await readLatest();
276
301
  if (!read || read === latest || !olderThan(VERSION, read) || read === readFailed()) return;
@@ -288,10 +313,12 @@ function selfUpdate(kind) {
288
313
  recordFailed(to);
289
314
  return;
290
315
  }
291
- const [command, ...args] = handOverCommand(process.platform, npx, to, kind);
316
+ const [command, ...args] = handOverCommand(platform, npx, to, kind);
292
317
  let fd;
293
318
  try {
294
319
  mkdirSync(updateDir(), { recursive: true, mode: 448 });
320
+ if (platform === "win32")
321
+ writeFileSync(adoptScriptPath(), adoptScript(npx, to, kind, updateLogPath()));
295
322
  fd = openSync(updateLogPath(), "a");
296
323
  } catch (err) {
297
324
  log(`could not open ${updateLogPath()}: ${err.code ?? err}`);
@@ -299,7 +326,11 @@ function selfUpdate(kind) {
299
326
  }
300
327
  handing = true;
301
328
  log(`handing over ${VERSION} -> ${to}; its log is ${updateLogPath()}`);
302
- const child = spawn(command, args, { detached: true, stdio: ["ignore", fd, fd] });
329
+ const child = spawn(
330
+ command,
331
+ args,
332
+ platform === "win32" ? { stdio: "ignore", windowsHide: true, env: windowsPowerShellEnv() } : { detached: true, stdio: ["ignore", fd, fd] }
333
+ );
303
334
  closeSync(fd);
304
335
  child.unref();
305
336
  const failed = (why) => {
@@ -309,8 +340,7 @@ function selfUpdate(kind) {
309
340
  };
310
341
  child.on("error", (err) => failed(err.message));
311
342
  child.on("exit", (code, signal) => {
312
- if (code === 0) handing = false;
313
- else failed(signal ? `signal ${signal}` : `exit ${code}`);
343
+ if (code !== 0) failed(signal ? `signal ${signal}` : `exit ${code}`);
314
344
  });
315
345
  };
316
346
  return {
@@ -319,7 +349,7 @@ function selfUpdate(kind) {
319
349
  const decision = updateDecision({
320
350
  current: VERSION,
321
351
  latest,
322
- unitText: readText(servicePath(kind)),
352
+ unitText: readText(servicePath(kind, platform)),
323
353
  running,
324
354
  inFlight,
325
355
  failed: readFailed(),
@@ -456,12 +486,15 @@ async function machineHarnesses(cfg) {
456
486
  }
457
487
  async function localDriver(cfg, name) {
458
488
  const bin = cfg.driver === name ? cfg.bin : void 0;
489
+ const claude = async (at) => claudeDialect(
490
+ at,
491
+ cfg.fallbackModels ?? DEFAULT_FALLBACK_MODEL,
492
+ cfg.askEverything,
493
+ await probeClaudePermissions(at)
494
+ );
459
495
  const driver = new LocalDriver({
460
- dialect: name === "claude-code" ? claudeDialect(bin, cfg.fallbackModels ?? DEFAULT_FALLBACK_MODEL, cfg.askEverything, {
461
- ...await probeClaudePermissions(bin)
462
- }) : codexDialect(bin),
463
- // Codex on the same machine takes Claude Code's runs while its account is at its usage limit.
464
- ...name === "claude-code" ? { fallbackHarness: codexDialect() } : {},
496
+ dialect: name === "claude-code" ? await claude(bin) : codexDialect(bin),
497
+ fallbackHarness: name === "claude-code" ? codexDialect() : await claude(),
465
498
  repos: cfg.repos,
466
499
  label: cfg.label,
467
500
  harnesses: () => machineHarnesses(cfg),
@@ -700,6 +733,7 @@ export {
700
733
  awaitNewDeviceToken,
701
734
  boxCommand,
702
735
  boxPresence,
736
+ localDriver,
703
737
  machineHarnesses,
704
738
  recordConnected,
705
739
  run,
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- findRun
4
- } from "./chunk-NMVZPTFM.js";
3
+ findRun,
4
+ ownHarness
5
+ } from "./chunk-NNPOMXCM.js";
5
6
  import {
6
7
  lockThreadsFile,
7
8
  threadsFilePath
8
- } from "./chunk-BGXIAFPO.js";
9
+ } from "./chunk-QINWGIXU.js";
9
10
  import {
10
- isLocal,
11
11
  localRunsFilePath,
12
12
  readRunRecords,
13
- readRunnerConfig,
13
+ runHarness,
14
14
  takeoverSummary
15
- } from "./chunk-B2ZI2UWS.js";
15
+ } from "./chunk-R22774MI.js";
16
16
  import {
17
17
  shortMachineName
18
18
  } from "./chunk-NTXQLEMQ.js";
@@ -168,10 +168,7 @@ async function takeoverCommand(args, deps = {}) {
168
168
  err(`This run has ended. Open it with: cloop resume ${short}`);
169
169
  return 1;
170
170
  }
171
- const cfg = deps.harness ? null : readRunnerConfig();
172
- const local = cfg && isLocal(cfg) ? cfg : null;
173
- const harness = deps.harness ?? local?.driver ?? "claude-code";
174
- const bin = deps.bin ?? local?.bin ?? (harness === "codex" ? "codex" : "claude");
171
+ const { harness, bin } = runHarness(run, ownHarness(deps));
175
172
  const session = run.session_id ?? (harness === "claude-code" ? run.work_id : null);
176
173
  if (!session) {
177
174
  err("This run has no session yet. Try again in a few seconds.");
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-ES5BRAKJ.js";
6
6
  import {
7
7
  VERSION
8
- } from "./chunk-BLSH7SNK.js";
8
+ } from "./chunk-OBFJRACJ.js";
9
9
  import {
10
10
  getOrigin,
11
11
  readCredentials,
@@ -39,6 +39,8 @@ function newAttempt(now = Date.now()) {
39
39
  workFolder: false,
40
40
  codexInstall: null,
41
41
  claudeInstall: null,
42
+ mcpRegistered: [],
43
+ mcpSignedIn: [],
42
44
  deviceToken: null
43
45
  };
44
46
  }
@@ -59,6 +61,8 @@ function connectReport(attempt, error, machine, now = Date.now()) {
59
61
  work_folder: attempt.workFolder,
60
62
  codex_install: attempt.codexInstall,
61
63
  claude_install: attempt.claudeInstall,
64
+ mcp_registered: attempt.mcpRegistered,
65
+ mcp_signed_in: attempt.mcpSignedIn,
62
66
  step: attempt.step,
63
67
  outcome: error ? "failed" : "ok",
64
68
  error_code: error,
@@ -3,7 +3,7 @@ import {
3
3
  readRunnerState,
4
4
  runnerStatePath,
5
5
  threadsFilePath
6
- } from "./chunk-BGXIAFPO.js";
6
+ } from "./chunk-QINWGIXU.js";
7
7
  import {
8
8
  BoxToolError,
9
9
  CLOOP_THREAD_PREFIX,
@@ -21,6 +21,7 @@ import {
21
21
  otherThreadsChoice,
22
22
  pickT3Bin,
23
23
  questionLine,
24
+ quoteWindowsArg,
24
25
  readRunnerConfig,
25
26
  runT3,
26
27
  runnerDir,
@@ -31,7 +32,7 @@ import {
31
32
  windowsExecutable,
32
33
  windowsPowerShellEnv,
33
34
  writeBoxConfig
34
- } from "./chunk-B2ZI2UWS.js";
35
+ } from "./chunk-R22774MI.js";
35
36
  import {
36
37
  getMachine,
37
38
  shortMachineName
@@ -49,17 +50,17 @@ import {
49
50
  } from "./chunk-R3CLO2FB.js";
50
51
  import {
51
52
  connectWebhook
52
- } from "./chunk-NYJ6XMD4.js";
53
+ } from "./chunk-LORK2EOG.js";
53
54
  import {
54
55
  ConnectFailure,
55
56
  connectReport,
56
57
  deviceLogin,
57
58
  newAttempt,
58
59
  sendConnectReport
59
- } from "./chunk-M4Y4YZ46.js";
60
+ } from "./chunk-EIBHDWUG.js";
60
61
  import {
61
62
  VERSION
62
- } from "./chunk-BLSH7SNK.js";
63
+ } from "./chunk-OBFJRACJ.js";
63
64
  import {
64
65
  STAGING_ORIGIN,
65
66
  getOrigin,
@@ -78,7 +79,7 @@ import {
78
79
  statSync,
79
80
  writeFileSync
80
81
  } from "fs";
81
- import { homedir as homedir3, userInfo } from "os";
82
+ import { homedir as homedir4, userInfo } from "os";
82
83
  import { basename as basename4, dirname, join as join3, resolve as resolve2 } from "path";
83
84
  import { createInterface } from "readline/promises";
84
85
  import { Writable } from "stream";
@@ -1126,6 +1127,219 @@ function movedLine(connecting) {
1126
1127
  return connecting === "staging" ? line2 : `${line2} It is stopped. Start it again with: cloop connect --staging`;
1127
1128
  }
1128
1129
 
1130
+ // src/mcp-registration.ts
1131
+ import { execFile as execFile3, spawn as spawn2 } from "child_process";
1132
+ import { homedir as homedir3 } from "os";
1133
+ var MCP_HARNESS_NAME = {
1134
+ "claude-code": "Claude Code",
1135
+ codex: "Codex"
1136
+ };
1137
+ var LOGIN_MS = 12e4;
1138
+ function mcpServer(env) {
1139
+ return { name: ENVIRONMENTS[env].mcpName, url: ENVIRONMENTS[env].mcpUrl };
1140
+ }
1141
+ var WORDS = {
1142
+ "claude-code": {
1143
+ bin: "claude",
1144
+ add: ({ name, url }) => ["mcp", "add", "-s", "user", "--transport", "http", name, url],
1145
+ remove: (name) => ["mcp", "remove", "-s", "user", name],
1146
+ login: (name) => ["mcp", "login", name]
1147
+ },
1148
+ codex: {
1149
+ bin: "codex",
1150
+ add: ({ name, url }) => ["mcp", "add", name, "--url", url],
1151
+ remove: (name) => ["mcp", "remove", name],
1152
+ login: (name) => ["mcp", "login", name]
1153
+ }
1154
+ };
1155
+ var OFFLINE = {
1156
+ HTTPS_PROXY: "http://127.0.0.1:9",
1157
+ HTTP_PROXY: "http://127.0.0.1:9",
1158
+ ALL_PROXY: "http://127.0.0.1:9",
1159
+ NO_PROXY: "",
1160
+ no_proxy: ""
1161
+ };
1162
+ function loginArgs(platform, env) {
1163
+ return platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY ? ["--no-browser"] : [];
1164
+ }
1165
+ function complaint(stderr, stdout, fallback) {
1166
+ const lines = `${stderr}
1167
+ ${stdout}`.split("\n").map((line2) => line2.trim()).filter((line2) => line2 && !line2.startsWith("WARNING:"));
1168
+ return lines[0] ?? fallback;
1169
+ }
1170
+ var systemMcpCli = {
1171
+ run: ([bin = "", ...args], env) => {
1172
+ const command = commandFor(bin, args);
1173
+ return new Promise(
1174
+ (resolve3, reject) => execFile3(
1175
+ command.file,
1176
+ command.args,
1177
+ {
1178
+ // A project's own MCP config under the folder connect ran in must not stand in for the user's.
1179
+ cwd: homedir3(),
1180
+ timeout: 45e3,
1181
+ encoding: "utf-8",
1182
+ env: { ...process.env, ...env },
1183
+ ...command.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
1184
+ },
1185
+ (err, stdout, stderr) => err ? reject(new Error(complaint(stderr, stdout, err.message))) : resolve3(stdout)
1186
+ )
1187
+ );
1188
+ },
1189
+ interactive: ([bin = "", ...args], ms) => {
1190
+ const command = commandFor(bin, args);
1191
+ return new Promise((resolve3) => {
1192
+ const ignore = () => {
1193
+ };
1194
+ process.on("SIGINT", ignore);
1195
+ const child = spawn2(command.file, command.args, {
1196
+ cwd: homedir3(),
1197
+ stdio: "inherit",
1198
+ ...command.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
1199
+ });
1200
+ const timer = setTimeout(() => {
1201
+ child.kill();
1202
+ done(false);
1203
+ }, ms);
1204
+ let settled = false;
1205
+ function done(ok) {
1206
+ if (settled) return;
1207
+ settled = true;
1208
+ clearTimeout(timer);
1209
+ process.off("SIGINT", ignore);
1210
+ resolve3(ok);
1211
+ }
1212
+ child.on("error", () => done(false));
1213
+ child.on("exit", (code) => done(code === 0));
1214
+ });
1215
+ }
1216
+ };
1217
+ function sameServer(a, b) {
1218
+ const key = (url) => {
1219
+ try {
1220
+ const { protocol, host, pathname } = new URL(url);
1221
+ return `${protocol}//${host}${pathname.replace(/\/+$/, "")}`;
1222
+ } catch {
1223
+ return null;
1224
+ }
1225
+ };
1226
+ const left = key(a);
1227
+ return left !== null && left === key(b);
1228
+ }
1229
+ function parseClaudeList(text) {
1230
+ const listed = [];
1231
+ for (const line2 of text.split("\n")) {
1232
+ const at = line2.indexOf(": ");
1233
+ if (at <= 0) continue;
1234
+ const rest = line2.slice(at + 2);
1235
+ if (!rest.includes(" - ")) continue;
1236
+ const url = /^(https?:\/\/\S+)/.exec(rest)?.[1] ?? null;
1237
+ listed.push({ name: line2.slice(0, at), url, signedIn: /\bConnected\s*$/.test(rest) });
1238
+ }
1239
+ return listed;
1240
+ }
1241
+ function parseCodexList(json) {
1242
+ const servers = JSON.parse(json);
1243
+ return servers.flatMap(
1244
+ ({ name, transport, auth_status }) => name ? [
1245
+ {
1246
+ name,
1247
+ url: transport?.type === "streamable_http" && transport.url ? transport.url : null,
1248
+ signedIn: auth_status === "o_auth" || auth_status === "bearer_token"
1249
+ }
1250
+ ] : []
1251
+ );
1252
+ }
1253
+ async function listEntries(harness, bin, cli) {
1254
+ return harness === "codex" ? parseCodexList(await cli.run([bin, "mcp", "list", "--json"])) : parseClaudeList(await cli.run([bin, "mcp", "list"]));
1255
+ }
1256
+ async function signedInNow(harness, bin, name, cli) {
1257
+ try {
1258
+ if (harness === "claude-code")
1259
+ return /^\s*Status: .*\bConnected\b/m.test(await cli.run([bin, "mcp", "get", name]));
1260
+ return (await listEntries(harness, bin, cli)).some((e) => e.name === name && e.signedIn);
1261
+ } catch {
1262
+ return false;
1263
+ }
1264
+ }
1265
+ function shellLine(words, platform) {
1266
+ return words.map(
1267
+ (word) => platform === "win32" ? quoteWindowsArg(word) : /^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replace(/'/g, "'\\''")}'`
1268
+ ).join(" ");
1269
+ }
1270
+ async function addCloopMcp(harness, bin, server, deps) {
1271
+ const platform = deps.platform ?? process.platform;
1272
+ const words = WORDS[harness];
1273
+ const login = (name) => [
1274
+ ...words.login(name),
1275
+ ...loginArgs(platform, deps.env ?? process.env)
1276
+ ];
1277
+ const shown = (args) => shellLine([words.bin, ...args], platform);
1278
+ const result = (registered, signedIn2, reason, byHand, as = server.name) => ({
1279
+ harness,
1280
+ url: server.url,
1281
+ as,
1282
+ found: as !== server.name,
1283
+ registered,
1284
+ signedIn: signedIn2,
1285
+ reason,
1286
+ byHand
1287
+ });
1288
+ const why = (err) => err instanceof Error ? err.message : String(err);
1289
+ let entries;
1290
+ try {
1291
+ entries = await listEntries(harness, bin, deps.cli);
1292
+ } catch (err) {
1293
+ return result(false, false, why(err), [shown(words.add(server)), shown(login(server.name))]);
1294
+ }
1295
+ const own = entries.find((entry) => entry.name === server.name);
1296
+ const ours = (entry) => Boolean(entry?.url && sameServer(entry.url, server.url));
1297
+ let signedIn = ours(own) && Boolean(own?.signedIn);
1298
+ if (!ours(own)) {
1299
+ const other = entries.find((entry) => entry.name !== server.name && ours(entry));
1300
+ if (other)
1301
+ return other.signedIn ? result(true, true, null, [], other.name) : result(true, false, "not signed in", [shown(login(other.name))], other.name);
1302
+ if (own) await deps.cli.run([bin, ...words.remove(server.name)]).catch(() => {
1303
+ });
1304
+ try {
1305
+ await deps.cli.run([bin, ...words.add(server)], harness === "codex" ? OFFLINE : void 0);
1306
+ } catch (err) {
1307
+ return result(false, false, why(err), [
1308
+ ...own ? [shown(words.remove(server.name))] : [],
1309
+ shown(words.add(server)),
1310
+ shown(login(server.name))
1311
+ ]);
1312
+ }
1313
+ signedIn = await signedInNow(harness, bin, server.name, deps.cli);
1314
+ }
1315
+ if (signedIn) return result(true, true, null, []);
1316
+ if (!deps.terminal) return result(true, false, "no terminal here", [shown(login(server.name))]);
1317
+ deps.say(
1318
+ `Sign in to Cloop for ${MCP_HARNESS_NAME[harness]}. Approve the sign-in in your browser within ${LOGIN_MS / 6e4} minutes.`
1319
+ );
1320
+ if (await deps.cli.interactive([bin, ...login(server.name)], LOGIN_MS) && await signedInNow(harness, bin, server.name, deps.cli))
1321
+ return result(true, true, null, []);
1322
+ return result(true, false, "the sign-in did not finish", [shown(login(server.name))]);
1323
+ }
1324
+ function mcpByHand(harness, server, platform = process.platform, env = process.env) {
1325
+ const words = WORDS[harness];
1326
+ return [words.add(server), [...words.login(server.name), ...loginArgs(platform, env)]].map(
1327
+ (args) => shellLine([words.bin, ...args], platform)
1328
+ );
1329
+ }
1330
+ function mcpLine(result) {
1331
+ const name = MCP_HARNESS_NAME[result.harness];
1332
+ const run = result.byHand.length ? ` Run: ${result.byHand.join(", then: ")}` : "";
1333
+ if (!result.registered)
1334
+ return `Could not add the Cloop MCP server to ${name} (${result.reason}).${run}`;
1335
+ if (result.found) {
1336
+ const head = `${name} already has the Cloop MCP server as ${result.as}`;
1337
+ return result.signedIn ? `${head}, signed in.` : `${head}. It is not signed in.${run}`;
1338
+ }
1339
+ if (result.signedIn) return `${name} has the Cloop MCP server at ${result.url}, signed in.`;
1340
+ return `${name} has the Cloop MCP server at ${result.url}. It is not signed in (${result.reason}).${run}`;
1341
+ }
1342
+
1129
1343
  // src/t3-pair-link.ts
1130
1344
  var CODE = /^[A-Za-z0-9_-]{8,256}$/;
1131
1345
  function tokenOf(url) {
@@ -1200,7 +1414,7 @@ function boxSession(t3Url, t3Bin, env, token) {
1200
1414
  }
1201
1415
  async function mintSession(t3Url, opts = {}) {
1202
1416
  const env = await workstationEnvironment(t3Url, opts.fetchFn);
1203
- const sources = opts.sources ?? defaultT3BinSources(homedir3(), opts.stored);
1417
+ const sources = opts.sources ?? defaultT3BinSources(homedir4(), opts.stored);
1204
1418
  try {
1205
1419
  const t3Bin = opts.bin ?? pickT3Bin(t3Candidates(env.serverVersion, sources), env.serverVersion);
1206
1420
  if (!t3Bin) throw new Error("no t3 binary found; pass --t3-bin or set T3_BIN");
@@ -1322,7 +1536,7 @@ function boxServiceInstalled() {
1322
1536
  platform: process.platform,
1323
1537
  kind: "workstation",
1324
1538
  environment: runnerEnvironment(),
1325
- home: homedir3(),
1539
+ home: homedir4(),
1326
1540
  uid: process.getuid?.() ?? 0,
1327
1541
  ...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
1328
1542
  }).path
@@ -1704,7 +1918,7 @@ async function reposFor(argv) {
1704
1918
  }
1705
1919
  const here = gitTop(process.cwd());
1706
1920
  if (here) return [{ label: basename4(here), path: here }];
1707
- const home = homedir3();
1921
+ const home = homedir4();
1708
1922
  const work = workFolder(home);
1709
1923
  const found = findCheckouts(home);
1710
1924
  let repos = [work];
@@ -1820,7 +2034,7 @@ async function installService(kind, argv, attempt, services = systemServices) {
1820
2034
  platform: services.platform,
1821
2035
  kind,
1822
2036
  environment,
1823
- home: homedir3(),
2037
+ home: homedir4(),
1824
2038
  program,
1825
2039
  env: serviceEnv(),
1826
2040
  uid: process.getuid?.() ?? 0,
@@ -1974,7 +2188,7 @@ async function connectT3(argv, attempt, fallback, chosen, services) {
1974
2188
  async function connectLocal(driver, found, argv, attempt, chosen, services) {
1975
2189
  attempt.step = "repos";
1976
2190
  const repos = await reposFor(argv);
1977
- const work = workFolder(homedir3()).path;
2191
+ const work = workFolder(homedir4()).path;
1978
2192
  attempt.workFolder = repos.every((r) => r.path === work);
1979
2193
  const harness = driver === "claude-code" ? found.claude : found.codex;
1980
2194
  const bin = which(driver === "claude-code" ? "claude" : "codex") ?? (driver === "claude-code" ? "claude" : "codex");
@@ -2068,8 +2282,8 @@ async function connect(argv, attempt, deps = {}) {
2068
2282
  );
2069
2283
  const t3Url = (flag(argv, "--t3-url") ?? DEFAULT_T3_URL).replace(/\/+$/, "");
2070
2284
  const harnessBin = (name) => process.platform === "win32" ? which(name) ?? name : name;
2071
- findLocalCodex(homedir3());
2072
- findLocalClaude(homedir3());
2285
+ findLocalCodex(homedir4());
2286
+ findLocalClaude(homedir4());
2073
2287
  const readCodex = deps.probes?.codex ?? (() => probeCodex(harnessBin("codex")));
2074
2288
  const readClaude = deps.probes?.claude ?? (() => probeClaude(harnessBin("claude")));
2075
2289
  const found = await detect(
@@ -2082,16 +2296,17 @@ async function connect(argv, attempt, deps = {}) {
2082
2296
  attempt.harnesses = harnessesFound(found);
2083
2297
  const workstation = isWorkstation(previous, boxServiceInstalled());
2084
2298
  const machine = !deps.probes;
2299
+ const terminal = deps.terminal ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
2085
2300
  const current = await prepareAgents(found, forced, workstation, {
2086
- chatGptApp: deps.chatGptApp ?? (() => machine && hasChatGptApp(homedir3())),
2087
- installCodex: deps.installCodex ?? (async () => machine && installCodex(homedir3())),
2088
- installClaude: deps.installClaude ?? (async () => machine && installClaude(homedir3())),
2301
+ chatGptApp: deps.chatGptApp ?? (() => machine && hasChatGptApp(homedir4())),
2302
+ installCodex: deps.installCodex ?? (async () => machine && installCodex(homedir4())),
2303
+ installClaude: deps.installClaude ?? (async () => machine && installClaude(homedir4())),
2089
2304
  readCodex,
2090
2305
  readClaude,
2091
2306
  updateClaude: deps.updateClaude ?? updateClaude,
2092
2307
  signInCodex: deps.signInCodex ?? (() => signInCodex(harnessBin("codex"))),
2093
2308
  signInClaude: deps.signInClaude ?? (() => signInClaude(harnessBin("claude"))),
2094
- terminal: deps.terminal ?? Boolean(process.stdin.isTTY && process.stdout.isTTY),
2309
+ terminal,
2095
2310
  installed: (agent, ok) => {
2096
2311
  attempt[agent === "codex" ? "codexInstall" : "claudeInstall"] = ok ? "ok" : "failed";
2097
2312
  }
@@ -2106,6 +2321,54 @@ async function connect(argv, attempt, deps = {}) {
2106
2321
  fallback: () => fallbackDriver(current, forced, workstation),
2107
2322
  say: (line2) => out(`${bold("Cloop runner")} ${line2}`)
2108
2323
  });
2324
+ const harnesses = [];
2325
+ if (current.claude) harnesses.push({ harness: "claude-code", bin: harnessBin("claude") });
2326
+ if (current.codex) harnesses.push({ harness: "codex", bin: harnessBin("codex") });
2327
+ const mcp = deps.mcp ?? (machine ? { cli: systemMcpCli } : null);
2328
+ if (mcp) await addCloopMcpLast(harnesses, attempt, mcp, terminal);
2329
+ }
2330
+ var MCP_STEP_MS = 6 * 6e4;
2331
+ async function addCloopMcpLast(found, attempt, mcp, terminal) {
2332
+ if (!found.length) return;
2333
+ const server = mcpServer(runnerEnvironment());
2334
+ const say = (line2) => out(`${bold("Cloop runner")} ${line2}`);
2335
+ const left = new Set(found.map(({ harness }) => harness));
2336
+ const byHand = () => [...left].flatMap((harness) => mcpByHand(harness, server)).join(", then: ");
2337
+ let late = false;
2338
+ const step = (async () => {
2339
+ for (const { harness, bin } of found) {
2340
+ const result = await addCloopMcp(harness, bin, server, { cli: mcp.cli, terminal, say });
2341
+ if (late) return;
2342
+ left.delete(harness);
2343
+ if (result.registered) attempt.mcpRegistered.push(harness);
2344
+ if (result.signedIn) attempt.mcpSignedIn.push(harness);
2345
+ console.error(
2346
+ `[runner:mcp] harness=${harness} registered=${result.registered} signed_in=${result.signedIn} reason=${result.reason ?? "none"}`
2347
+ );
2348
+ out(
2349
+ result.registered ? `${bold("Cloop runner")} ${mcpLine(result)}` : `${red("\u2717")} ${mcpLine(result)}`
2350
+ );
2351
+ }
2352
+ })();
2353
+ let timer;
2354
+ const deadline = new Promise((resolve3) => {
2355
+ timer = setTimeout(() => resolve3("late"), mcp.deadlineMs ?? MCP_STEP_MS);
2356
+ });
2357
+ try {
2358
+ if (await Promise.race([step.then(() => "done"), deadline]) === "late") {
2359
+ late = true;
2360
+ console.error("[runner:mcp] outcome=timeout");
2361
+ out(`${red("\u2717")} Adding the Cloop MCP server took too long. Run: ${byHand()}`);
2362
+ }
2363
+ } catch (err) {
2364
+ late = true;
2365
+ console.error("[runner:mcp] outcome=unexpected");
2366
+ out(
2367
+ `${red("\u2717")} Could not add the Cloop MCP server (${err instanceof Error ? err.message : String(err)}). Run: ${byHand()}`
2368
+ );
2369
+ } finally {
2370
+ clearTimeout(timer);
2371
+ }
2109
2372
  }
2110
2373
  async function prepareAgents(found, forced, workstation, deps) {
2111
2374
  if (workstation || forced === "t3") return found;
@@ -2287,6 +2550,7 @@ export {
2287
2550
  systemdWord,
2288
2551
  cmdValue,
2289
2552
  cmdWord,
2553
+ psQuote2 as psQuote,
2290
2554
  registerTaskScript,
2291
2555
  endDaemonScript,
2292
2556
  programFor,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ConnectFailure,
4
4
  deviceLogin
5
- } from "./chunk-M4Y4YZ46.js";
5
+ } from "./chunk-EIBHDWUG.js";
6
6
  import {
7
7
  ApiError,
8
8
  ReauthError,
@@ -6,9 +6,10 @@ import {
6
6
  localRunsFilePath,
7
7
  readRunRecords,
8
8
  readRunnerConfig,
9
+ runHarness,
9
10
  runLogDir,
10
11
  runLogPath
11
- } from "./chunk-B2ZI2UWS.js";
12
+ } from "./chunk-R22774MI.js";
12
13
  import {
13
14
  sanitizeLabel,
14
15
  stripControl
@@ -214,6 +215,11 @@ async function sessionFolder(id, root = join(homedir(), ".claude", "projects"))
214
215
  }
215
216
  return null;
216
217
  }
218
+ function ownHarness(deps) {
219
+ if (deps.harness) return { driver: deps.harness, ...deps.bin ? { bin: deps.bin } : {} };
220
+ const cfg = readRunnerConfig();
221
+ return cfg && isLocal(cfg) ? cfg : null;
222
+ }
217
223
  async function resumeCommand(args, deps = {}) {
218
224
  const { file, out, err } = resolved(deps);
219
225
  const id = args[0];
@@ -221,10 +227,7 @@ async function resumeCommand(args, deps = {}) {
221
227
  err("Usage: cloop resume <id>. List the runs with: cloop runs");
222
228
  return 1;
223
229
  }
224
- const cfg = deps.harness ? null : readRunnerConfig();
225
- const local = cfg && isLocal(cfg) ? cfg : null;
226
- const harness = deps.harness ?? local?.driver ?? "claude-code";
227
- const bin = deps.bin ?? local?.bin ?? (harness === "codex" ? "codex" : "claude");
230
+ const own = ownHarness(deps);
228
231
  const spawn = deps.spawn ?? ((b, a, cwd) => spawnSync(b, a, { cwd, stdio: "inherit" }).status ?? 1);
229
232
  const records = readRunRecords(file);
230
233
  const found = findRun(records, id);
@@ -240,6 +243,7 @@ async function resumeCommand(args, deps = {}) {
240
243
  err(`The repository ${r.repo} is not on this machine any more.`);
241
244
  return 1;
242
245
  }
246
+ const { harness, bin } = runHarness(r, own);
243
247
  const session = r.session_id ?? (harness === "claude-code" ? r.work_id : null);
244
248
  if (!session) {
245
249
  err("This run has no session to resume.");
@@ -251,7 +255,7 @@ async function resumeCommand(args, deps = {}) {
251
255
  const folder = await sessionFolder(id, deps.claudeProjects);
252
256
  if (folder && existsSync(folder)) {
253
257
  out(`Opening the session in ${folder}`);
254
- return spawn(harness === "claude-code" ? bin : "claude", ["--resume", id], folder);
258
+ return spawn(runHarness({ harness: "claude-code" }, own).bin, ["--resume", id], folder);
255
259
  }
256
260
  err(found.error);
257
261
  return 1;
@@ -265,5 +269,6 @@ export {
265
269
  runsCommand,
266
270
  watchCommand,
267
271
  sessionFolder,
272
+ ownHarness,
268
273
  resumeCommand
269
274
  };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/version.ts
4
- var VERSION = true ? "0.3.15" : "0.0.0-dev";
4
+ var VERSION = true ? "0.3.18" : "0.0.0-dev";
5
5
 
6
6
  export {
7
7
  VERSION
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  RUN_TEXT_MAX,
4
4
  runnerPath
5
- } from "./chunk-B2ZI2UWS.js";
5
+ } from "./chunk-R22774MI.js";
6
6
 
7
7
  // src/box-watch.ts
8
8
  import { randomUUID } from "crypto";
@@ -17,13 +17,17 @@ var ENVIRONMENTS = {
17
17
  origin: PRODUCTION_ORIGIN,
18
18
  dir: (home) => join(home, CONFIG_DIR),
19
19
  suffix: "",
20
- flag: ""
20
+ flag: "",
21
+ mcpUrl: "https://app.mycloop.com/api/mcp/mcp",
22
+ mcpName: "cloop"
21
23
  },
22
24
  staging: {
23
25
  origin: STAGING_ORIGIN,
24
26
  dir: (home) => join(home, CONFIG_DIR, "staging"),
25
27
  suffix: "staging",
26
- flag: "--staging"
28
+ flag: "--staging",
29
+ mcpUrl: "https://mcp-staging.mycloop.com/mcp",
30
+ mcpName: "cloop-staging"
27
31
  }
28
32
  };
29
33
  function environmentOf(origin) {
@@ -340,7 +344,8 @@ var RESULT_INSTRUCTION = [
340
344
  "```",
341
345
  "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.",
342
346
  "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.",
343
- "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."
347
+ "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.",
348
+ "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."
344
349
  ].join("\n");
345
350
  var text = (v, max) => typeof v === "string" && v.length <= max;
346
351
  var optionalText = (v, max) => v === void 0 || text(v, max);
@@ -1430,7 +1435,19 @@ var COMMANDS_KEPT = 50;
1430
1435
  var SUMMARY_MAX2 = 200;
1431
1436
  var HARNESS_NAMES = { "claude-code": "Claude Code", codex: "Codex" };
1432
1437
  var harnessName = (name) => HARNESS_NAMES[name] ?? name;
1433
- var movedLine = (from, to) => `${harnessName(from)} was at its usage limit, so ${harnessName(to)} did this run.`;
1438
+ function runHarness(run2, own) {
1439
+ const driver = own?.driver === "codex" ? "codex" : "claude-code";
1440
+ const harness = run2.harness ?? driver;
1441
+ const bin = harness === driver && own?.bin ? own.bin : harness === "codex" ? "codex" : "claude";
1442
+ return { harness, bin };
1443
+ }
1444
+ var MOVE_STATE = {
1445
+ limit: "at its usage limit",
1446
+ signed_out: "signed out here",
1447
+ missing: "not installed here"
1448
+ };
1449
+ var movedLine = (move, from, to) => `${harnessName(from)} ${move.at === "run" ? "was" : "is"} ${MOVE_STATE[move.reason]}, so ${harnessName(to)} did this run.`;
1450
+ var movingLine = (move, from, to) => `${harnessName(from)} is ${MOVE_STATE[move.reason]}, so I moved this to ${harnessName(to)}`;
1434
1451
  function failedEnd(harness, run2) {
1435
1452
  const said = run2.result?.text?.trim() || run2.lastText;
1436
1453
  const limited = HARNESS_LIMIT.test(run2.result?.text ?? "");
@@ -1442,7 +1459,7 @@ function failedEnd(harness, run2) {
1442
1459
  summary: `${opening}${run2.result ? "The run ended with an error." : `The run exited with ${run2.exit}.`}`,
1443
1460
  ...error
1444
1461
  };
1445
- const lead = `${opening}${HARNESS_NAMES[harness] ?? harness} said: "`;
1462
+ const lead = `${opening}${harnessName(harness)} said: "`;
1446
1463
  const room = SUMMARY_MAX2 - lead.length - 1;
1447
1464
  const quoted = words.length > room ? `${words.slice(0, room - 1)}\u2026` : words;
1448
1465
  return { summary: `${lead}${quoted}"`, ...error };
@@ -1643,11 +1660,7 @@ var LocalDriver = class {
1643
1660
  throw new BoxToolError("harness_unavailable");
1644
1661
  const repo = pickRepo(this.deps.repos, a.repository);
1645
1662
  this.refuseBusy(repo.path);
1646
- const moved = a.harness ? null : await this.heldOver(a);
1647
- const dialect = moved ?? own;
1648
- const harness = await dialect.probe();
1649
- if (!harness) throw new BoxToolError("harness_unavailable");
1650
- if (!harness.signedIn) throw new BoxToolError("harness_signed_out");
1663
+ const { dialect, moved } = await this.route(a);
1651
1664
  const head = await this.repo.head(repo.path);
1652
1665
  const concurrent = this.runs.get(a.work_id);
1653
1666
  if (concurrent)
@@ -1667,15 +1680,14 @@ var LocalDriver = class {
1667
1680
  ...a.model && !moved ? { model: a.model } : {},
1668
1681
  ...a.runtime_mode ? { runtime_mode: a.runtime_mode } : {},
1669
1682
  ...a.harness ? { harness_named: true } : {},
1670
- ...moved ? {
1671
- harness: moved.name,
1672
- switched: `${HARNESS_NAMES[own.name]} is at its usage limit, so ${HARNESS_NAMES[moved.name]} did this run.`
1673
- } : {},
1683
+ ...moved ? { harness: dialect.name, moved, switched: movedLine(moved, own.name, dialect.name) } : {},
1674
1684
  pid: null,
1675
1685
  started_at: new Date(this.now()).toISOString(),
1676
1686
  head_at_launch: head
1677
1687
  };
1678
1688
  this.runs.set(a.work_id, record);
1689
+ if (moved)
1690
+ this.log(`fallback work=${a.work_id} harness=${dialect.name} reason=${moved.reason}`);
1679
1691
  this.spawnRun(record, a.prompt, false);
1680
1692
  return {
1681
1693
  thread_id: a.work_id,
@@ -1817,17 +1829,34 @@ ${a.text}` : a.text;
1817
1829
  return fallback && r.harness === fallback.name ? fallback : this.deps.dialect;
1818
1830
  }
1819
1831
  /**
1820
- * The fallback harness, while the runner's own one is at an account-wide
1821
- * limit and the fallback is signed in. Codex asks nothing, so it takes only
1822
- * runs that would have had full access anyway.
1832
+ * The fallback harness, when it may carry this run. A move never gives a
1833
+ * run more access than its own harness would: a run that asks the owner
1834
+ * does not go to a harness that asks nothing.
1823
1835
  */
1824
- async heldOver(a) {
1825
- const fallback = this.deps.fallbackHarness;
1826
- if (!fallback || this.now() >= this.limitedUntil) return null;
1836
+ carrier(run2, own) {
1837
+ const to = this.deps.fallbackHarness;
1838
+ return to && (to.permission?.(run2) !== "full" || own === "full") ? to : null;
1839
+ }
1840
+ /**
1841
+ * A Task that names its harness stays on it. Otherwise a run starts on the
1842
+ * fallback while the runner's own harness is held at its limit, or when the
1843
+ * own harness is signed out or not installed and the fallback is signed in.
1844
+ */
1845
+ async route(a) {
1846
+ const own = this.deps.dialect;
1827
1847
  const mode = a.runtime_mode ? { runtime_mode: a.runtime_mode } : {};
1828
- if (this.deps.dialect.permission?.(mode) !== "full") return null;
1829
- const probe = await fallback.probe().catch(() => null);
1830
- return probe?.signedIn ? fallback : null;
1848
+ const to = a.harness ? null : this.carrier(mode, own.permission?.(mode));
1849
+ const ready = async () => Boolean(to && (await to.probe().catch(() => null))?.signedIn);
1850
+ if (to && this.now() < this.limitedUntil && await ready())
1851
+ return { dialect: to, moved: { reason: "limit", at: "launch" } };
1852
+ const harness = await own.probe();
1853
+ if (harness?.signedIn) return { dialect: own };
1854
+ if (to && await ready())
1855
+ return {
1856
+ dialect: to,
1857
+ moved: { reason: harness ? "signed_out" : "missing", at: "launch" }
1858
+ };
1859
+ throw new BoxToolError(harness ? "harness_signed_out" : "harness_unavailable");
1831
1860
  }
1832
1861
  /** One checkout, one run: two harnesses editing the same files at once would undo each other. */
1833
1862
  refuseBusy(repo) {
@@ -2037,7 +2066,7 @@ ${RESULT_INSTRUCTION}`));
2037
2066
  if (!next)
2038
2067
  this.log(`model work=${r.work_id} refused=${refused} next=none catalog=${listed.length}`);
2039
2068
  if (!next || this.stopping || r.end) return false;
2040
- const moved = r.harness ? movedLine(this.deps.dialect.name, r.harness) : null;
2069
+ const moved = r.harness && r.moved ? movedLine(r.moved, this.deps.dialect.name, r.harness) : null;
2041
2070
  r.refused = tried;
2042
2071
  r.model = next;
2043
2072
  r.session_id = null;
@@ -2049,7 +2078,7 @@ ${RESULT_INSTRUCTION}`));
2049
2078
  this.log(`model work=${r.work_id} refused=${refused} next=${next}`);
2050
2079
  this.spawnRun(
2051
2080
  r,
2052
- r.harness ? handoverPrompt(r.prompt, harnessName(this.deps.dialect.name)) : r.prompt,
2081
+ r.moved?.at === "run" ? handoverPrompt(r.prompt, harnessName(this.deps.dialect.name)) : r.prompt,
2053
2082
  false
2054
2083
  );
2055
2084
  return true;
@@ -2060,14 +2089,13 @@ ${RESULT_INSTRUCTION}`));
2060
2089
  * The session does not: the prompt goes again, with a note to read the
2061
2090
  * checkout first. A limit that names no model holds the account, so new
2062
2091
  * runs start on the fallback for LIMIT_HOLD_MS. It does not move a run
2063
- * whose Task named its harness, nor one without full access, because
2064
- * Codex asks nothing.
2092
+ * whose Task named its harness, nor one the fallback may not carry.
2065
2093
  */
2066
2094
  async moveHarness(r, said) {
2067
2095
  const to = this.deps.fallbackHarness;
2068
2096
  if (!to || r.harness) return false;
2069
2097
  if (!limitedModel(said)) this.limitedUntil = this.now() + LIMIT_HOLD_MS;
2070
- if (r.harness_named || r.used_permission !== "full" || !r.prompt) return false;
2098
+ if (r.harness_named || !this.carrier(r, r.used_permission) || !r.prompt) return false;
2071
2099
  this.recovering.add(r.work_id);
2072
2100
  try {
2073
2101
  const probe = await to.probe().catch(() => null);
@@ -2075,19 +2103,17 @@ ${RESULT_INSTRUCTION}`));
2075
2103
  } finally {
2076
2104
  this.recovering.delete(r.work_id);
2077
2105
  }
2078
- const from = harnessName(this.deps.dialect.name);
2079
- const name = harnessName(to.name);
2106
+ const from = this.deps.dialect.name;
2107
+ const move = { reason: "limit", at: "run" };
2080
2108
  r.harness = to.name;
2109
+ r.moved = move;
2081
2110
  r.session_id = null;
2082
2111
  r.model = void 0;
2083
- r.switched = movedLine(this.deps.dialect.name, to.name);
2112
+ r.switched = movedLine(move, from, to.name);
2084
2113
  this.save();
2085
- this.log(`fallback work=${r.work_id} harness=${to.name}`);
2086
- this.emit(r.work_id, {
2087
- kind: "progress",
2088
- summary: `${from} is at its usage limit, so I moved this to ${name}`
2089
- });
2090
- this.spawnRun(r, handoverPrompt(r.prompt, from), false);
2114
+ this.log(`fallback work=${r.work_id} harness=${to.name} reason=limit`);
2115
+ this.emit(r.work_id, { kind: "progress", summary: movingLine(move, from, to.name) });
2116
+ this.spawnRun(r, handoverPrompt(r.prompt, harnessName(from)), false);
2091
2117
  return true;
2092
2118
  }
2093
2119
  /**
@@ -2222,6 +2248,7 @@ export {
2222
2248
  STOPPED_SUMMARY,
2223
2249
  isEndLogLine,
2224
2250
  commandFor,
2251
+ quoteWindowsArg,
2225
2252
  windowsExecutable,
2226
2253
  windowsPowerShellEnv,
2227
2254
  defaultT3BinSources,
@@ -2231,6 +2258,7 @@ export {
2231
2258
  runT3,
2232
2259
  T3Driver,
2233
2260
  takeoverSummary,
2261
+ runHarness,
2234
2262
  localRunsFilePath,
2235
2263
  LocalDriver,
2236
2264
  readRunRecords,
@@ -32,6 +32,7 @@ import {
32
32
  parsePicks,
33
33
  prepareAgents,
34
34
  programFor,
35
+ psQuote,
35
36
  registerTaskScript,
36
37
  rememberedDriver,
37
38
  rerunCommand,
@@ -51,17 +52,17 @@ import {
51
52
  which,
52
53
  workFolder,
53
54
  workFolderLine
54
- } from "./chunk-RT5UZNMQ.js";
55
- import "./chunk-BGXIAFPO.js";
56
- import "./chunk-B2ZI2UWS.js";
55
+ } from "./chunk-HVXCQQWG.js";
56
+ import "./chunk-QINWGIXU.js";
57
+ import "./chunk-R22774MI.js";
57
58
  import "./chunk-NTXQLEMQ.js";
58
59
  import "./chunk-VK6GV757.js";
59
60
  import "./chunk-YEO27QQP.js";
60
61
  import "./chunk-R3CLO2FB.js";
61
- import "./chunk-NYJ6XMD4.js";
62
- import "./chunk-M4Y4YZ46.js";
62
+ import "./chunk-LORK2EOG.js";
63
+ import "./chunk-EIBHDWUG.js";
63
64
  import "./chunk-ES5BRAKJ.js";
64
- import "./chunk-BLSH7SNK.js";
65
+ import "./chunk-OBFJRACJ.js";
65
66
  import "./chunk-D5UZW42X.js";
66
67
  export {
67
68
  DEFAULT_T3_URL,
@@ -96,6 +97,7 @@ export {
96
97
  parsePicks,
97
98
  prepareAgents,
98
99
  programFor,
100
+ psQuote,
99
101
  registerTaskScript,
100
102
  rememberedDriver,
101
103
  rerunCommand,
@@ -7,17 +7,17 @@ import {
7
7
  runnerOrigin,
8
8
  stopService,
9
9
  unitOrigin
10
- } from "./chunk-RT5UZNMQ.js";
11
- import "./chunk-BGXIAFPO.js";
12
- import "./chunk-B2ZI2UWS.js";
10
+ } from "./chunk-HVXCQQWG.js";
11
+ import "./chunk-QINWGIXU.js";
12
+ import "./chunk-R22774MI.js";
13
13
  import "./chunk-NTXQLEMQ.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-YEO27QQP.js";
16
16
  import "./chunk-R3CLO2FB.js";
17
- import "./chunk-NYJ6XMD4.js";
18
- import "./chunk-M4Y4YZ46.js";
17
+ import "./chunk-LORK2EOG.js";
18
+ import "./chunk-EIBHDWUG.js";
19
19
  import "./chunk-ES5BRAKJ.js";
20
- import "./chunk-BLSH7SNK.js";
20
+ import "./chunk-OBFJRACJ.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-RT5UZNMQ.js";
6
- import "./chunk-BGXIAFPO.js";
7
- import "./chunk-B2ZI2UWS.js";
5
+ } from "./chunk-HVXCQQWG.js";
6
+ import "./chunk-QINWGIXU.js";
7
+ import "./chunk-R22774MI.js";
8
8
  import "./chunk-NTXQLEMQ.js";
9
9
  import "./chunk-VK6GV757.js";
10
10
  import "./chunk-YEO27QQP.js";
11
11
  import "./chunk-R3CLO2FB.js";
12
- import "./chunk-NYJ6XMD4.js";
13
- import "./chunk-M4Y4YZ46.js";
12
+ import "./chunk-LORK2EOG.js";
13
+ import "./chunk-EIBHDWUG.js";
14
14
  import "./chunk-ES5BRAKJ.js";
15
- import "./chunk-BLSH7SNK.js";
15
+ import "./chunk-OBFJRACJ.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-YEO27QQP.js";
5
5
  import {
6
6
  VERSION
7
- } from "./chunk-BLSH7SNK.js";
7
+ } from "./chunk-OBFJRACJ.js";
8
8
  import {
9
9
  applyEnvironmentFlag
10
10
  } from "./chunk-D5UZW42X.js";
@@ -65,7 +65,7 @@ Add --staging to any command to use Cloop staging instead of production.
65
65
  A production runner and a staging runner can run side by side on one machine.
66
66
  `;
67
67
  async function pinExistingRunner() {
68
- const { pinExistingRunner: pin } = await import("./existing-runner-RIW2IIHJ.js");
68
+ const { pinExistingRunner: pin } = await import("./existing-runner-YSP7FXZR.js");
69
69
  const { note } = pin();
70
70
  if (note) console.error(note);
71
71
  }
@@ -73,7 +73,7 @@ async function main() {
73
73
  switch (command) {
74
74
  case "login":
75
75
  case "auth": {
76
- const { loginCommand } = await import("./login-3BUGMP4K.js");
76
+ const { loginCommand } = await import("./login-V75JRH67.js");
77
77
  await loginCommand(argv);
78
78
  break;
79
79
  }
@@ -83,61 +83,61 @@ async function main() {
83
83
  break;
84
84
  }
85
85
  case "serve": {
86
- const { startMcpServer } = await import("./mcp-server-6RK4RQVI.js");
86
+ const { startMcpServer } = await import("./mcp-server-DZDP77CZ.js");
87
87
  await startMcpServer();
88
88
  break;
89
89
  }
90
90
  case "statusline": {
91
- const { statuslineCommand } = await import("./statusline-R4YJZFUC.js");
91
+ const { statuslineCommand } = await import("./statusline-N2KTSLFM.js");
92
92
  statuslineCommand();
93
93
  break;
94
94
  }
95
95
  case "connect": {
96
- const { connectCommand } = await import("./connect-7GU3JGWQ.js");
96
+ const { connectCommand } = await import("./connect-34PDKC55.js");
97
97
  await connectCommand(argv.slice(1));
98
98
  break;
99
99
  }
100
100
  case "use": {
101
- const { useCommand } = await import("./use-TIHWB3AS.js");
101
+ const { useCommand } = await import("./use-MBFWAKLJ.js");
102
102
  process.exitCode = await useCommand(argv.slice(1));
103
103
  break;
104
104
  }
105
105
  case "disconnect": {
106
- const { disconnectCommand } = await import("./disconnect-UC2D3CHK.js");
106
+ const { disconnectCommand } = await import("./disconnect-DCMZAIB6.js");
107
107
  await disconnectCommand(argv.slice(1));
108
108
  break;
109
109
  }
110
110
  case "box": {
111
- const { boxCommand } = await import("./box-XFXJEHHZ.js");
111
+ const { boxCommand } = await import("./box-AF56GPSV.js");
112
112
  await boxCommand(argv.slice(1));
113
113
  break;
114
114
  }
115
115
  case "runs": {
116
116
  await pinExistingRunner();
117
- const { runsCommand } = await import("./runs-4BKFXNM5.js");
117
+ const { runsCommand } = await import("./runs-IZ3AMCHT.js");
118
118
  process.exitCode = runsCommand();
119
119
  break;
120
120
  }
121
121
  case "watch": {
122
122
  await pinExistingRunner();
123
- const { watchCommand } = await import("./runs-4BKFXNM5.js");
123
+ const { watchCommand } = await import("./runs-IZ3AMCHT.js");
124
124
  process.exitCode = await watchCommand(argv.slice(1));
125
125
  break;
126
126
  }
127
127
  case "takeover": {
128
128
  await pinExistingRunner();
129
- const { takeoverCommand } = await import("./takeover-FCKTVLQY.js");
129
+ const { takeoverCommand } = await import("./takeover-3XAMWQPK.js");
130
130
  process.exitCode = await takeoverCommand(argv.slice(1));
131
131
  break;
132
132
  }
133
133
  case "resume": {
134
134
  await pinExistingRunner();
135
- const { resumeCommand } = await import("./runs-4BKFXNM5.js");
135
+ const { resumeCommand } = await import("./runs-IZ3AMCHT.js");
136
136
  process.exitCode = await resumeCommand(argv.slice(1));
137
137
  break;
138
138
  }
139
139
  case "runner": {
140
- const { runnerCommand } = await import("./runner-ICPDXYOC.js");
140
+ const { runnerCommand } = await import("./runner-TFJMSK5R.js");
141
141
  await runnerCommand(argv.slice(1));
142
142
  break;
143
143
  }
@@ -3,9 +3,9 @@ import {
3
3
  deviceLogin,
4
4
  loginCommand,
5
5
  refusalSentence
6
- } from "./chunk-M4Y4YZ46.js";
6
+ } from "./chunk-EIBHDWUG.js";
7
7
  import "./chunk-ES5BRAKJ.js";
8
- import "./chunk-BLSH7SNK.js";
8
+ import "./chunk-OBFJRACJ.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  deviceLogin,
@@ -33,7 +33,7 @@ import {
33
33
  } from "./chunk-ES5BRAKJ.js";
34
34
  import {
35
35
  VERSION
36
- } from "./chunk-BLSH7SNK.js";
36
+ } from "./chunk-OBFJRACJ.js";
37
37
  import {
38
38
  getMeshUrl,
39
39
  getToken
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  connectWebhook,
4
4
  runnerCommand
5
- } from "./chunk-NYJ6XMD4.js";
6
- import "./chunk-M4Y4YZ46.js";
5
+ } from "./chunk-LORK2EOG.js";
6
+ import "./chunk-EIBHDWUG.js";
7
7
  import "./chunk-ES5BRAKJ.js";
8
- import "./chunk-BLSH7SNK.js";
8
+ import "./chunk-OBFJRACJ.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  connectWebhook,
@@ -2,19 +2,21 @@
2
2
  import {
3
3
  findRun,
4
4
  lastLines,
5
+ ownHarness,
5
6
  recentRuns,
6
7
  resumeCommand,
7
8
  runState,
8
9
  runsCommand,
9
10
  sessionFolder,
10
11
  watchCommand
11
- } from "./chunk-NMVZPTFM.js";
12
- import "./chunk-B2ZI2UWS.js";
12
+ } from "./chunk-NNPOMXCM.js";
13
+ import "./chunk-R22774MI.js";
13
14
  import "./chunk-VK6GV757.js";
14
15
  import "./chunk-D5UZW42X.js";
15
16
  export {
16
17
  findRun,
17
18
  lastLines,
19
+ ownHarness,
18
20
  recentRuns,
19
21
  resumeCommand,
20
22
  runState,
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-VK6GV757.js";
8
8
  import {
9
9
  VERSION
10
- } from "./chunk-BLSH7SNK.js";
10
+ } from "./chunk-OBFJRACJ.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-3J5FFRLN.js";
13
- import "./chunk-NMVZPTFM.js";
14
- import "./chunk-BGXIAFPO.js";
15
- import "./chunk-B2ZI2UWS.js";
12
+ } from "./chunk-7OBTF35R.js";
13
+ import "./chunk-NNPOMXCM.js";
14
+ import "./chunk-QINWGIXU.js";
15
+ import "./chunk-R22774MI.js";
16
16
  import "./chunk-NTXQLEMQ.js";
17
17
  import "./chunk-VK6GV757.js";
18
18
  import "./chunk-ES5BRAKJ.js";
@@ -3,20 +3,20 @@ import {
3
3
  DRIVER_NAME,
4
4
  pinExistingRunner,
5
5
  runConnect
6
- } from "./chunk-RT5UZNMQ.js";
7
- import "./chunk-BGXIAFPO.js";
6
+ } from "./chunk-HVXCQQWG.js";
7
+ import "./chunk-QINWGIXU.js";
8
8
  import {
9
9
  isLocal,
10
10
  readRunnerConfig
11
- } from "./chunk-B2ZI2UWS.js";
11
+ } from "./chunk-R22774MI.js";
12
12
  import "./chunk-NTXQLEMQ.js";
13
13
  import "./chunk-VK6GV757.js";
14
14
  import "./chunk-YEO27QQP.js";
15
15
  import "./chunk-R3CLO2FB.js";
16
- import "./chunk-NYJ6XMD4.js";
17
- import "./chunk-M4Y4YZ46.js";
16
+ import "./chunk-LORK2EOG.js";
17
+ import "./chunk-EIBHDWUG.js";
18
18
  import "./chunk-ES5BRAKJ.js";
19
- import "./chunk-BLSH7SNK.js";
19
+ import "./chunk-OBFJRACJ.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.15",
3
+ "version": "0.3.18",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Make your machine and your agents Cloop runners: device login, the runner daemon, the Cloop MCP server, and Claude Code hooks.",