@cloop/runner 0.3.64 → 0.3.67

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-FN2G5ZWH.js";
5
- import "./chunk-QYPDDIJL.js";
4
+ } from "./chunk-7ZL3Z3IO.js";
5
+ import "./chunk-TCNIRZLU.js";
6
6
  import {
7
7
  CAPTURE_TICK_MS,
8
8
  DEFAULT_FALLBACK_MODEL,
@@ -40,7 +40,7 @@ import {
40
40
  systemServices,
41
41
  unitFor,
42
42
  which
43
- } from "./chunk-MSCSQNNI.js";
43
+ } from "./chunk-IK7YYRMU.js";
44
44
  import {
45
45
  MeshSocket,
46
46
  WAKE_TICK_MS,
@@ -58,10 +58,11 @@ import {
58
58
  runnerStatePath,
59
59
  threadsFilePath,
60
60
  writeRunnerState
61
- } from "./chunk-7AB5JOZN.js";
61
+ } from "./chunk-7LPSTDZE.js";
62
62
  import {
63
63
  BackgroundReading,
64
64
  BoxToolError,
65
+ CLAUDE_AUTH_LOCKED,
65
66
  HARNESS_LIMIT,
66
67
  HARNESS_STALE_MS,
67
68
  IDLE_SETTLE_MS,
@@ -110,20 +111,20 @@ import {
110
111
  utcWindow,
111
112
  windowsPowerShellEnv,
112
113
  writeBoxConfig
113
- } from "./chunk-DXX7OIZK.js";
114
+ } from "./chunk-6LYMSWSB.js";
114
115
  import "./chunk-VK6GV757.js";
115
116
  import {
116
117
  olderThan
117
118
  } from "./chunk-365HFCQQ.js";
118
119
  import "./chunk-PKIEWBR7.js";
119
- import "./chunk-GJVUF4SB.js";
120
- import "./chunk-RTLLZQWP.js";
120
+ import "./chunk-OIHUQBA4.js";
121
+ import "./chunk-QKRGJKJN.js";
121
122
  import {
122
123
  getMachine
123
124
  } from "./chunk-SBYSVZ7J.js";
124
125
  import {
125
126
  VERSION
126
- } from "./chunk-BRDSWUDJ.js";
127
+ } from "./chunk-KYDTE53W.js";
127
128
  import {
128
129
  getMeshUrl,
129
130
  getOrigin,
@@ -548,6 +549,9 @@ function coreRequestId(kind, id) {
548
549
  }
549
550
  var CLOOP_SESSION_PREFIX = "cr_cloop-";
550
551
  var isCloopSession = (s) => s.session_id.startsWith(CLOOP_SESSION_PREFIX);
552
+ function workOf(thread) {
553
+ return thread.startsWith(CLOOP_SESSION_PREFIX) ? thread.slice(CLOOP_SESSION_PREFIX.length) : null;
554
+ }
551
555
  var MOVES_MAX = 16;
552
556
  function movedSessionId(thread, n) {
553
557
  const id = `${thread.replace(/^cr_/, "")}-m${n}`;
@@ -634,6 +638,19 @@ function openTurn(fold) {
634
638
  function turnOf(fold, request) {
635
639
  return request ? fold.turns.find((t) => t.id === request) : openTurn(fold);
636
640
  }
641
+ function awaiting(fold, request) {
642
+ if (fold.turns.some((t) => t.id === request)) return { ...fold, ended: false };
643
+ const turn = {
644
+ id: request,
645
+ state: "accepted",
646
+ error: null,
647
+ cancelled: false,
648
+ limited: false,
649
+ item: null,
650
+ text: ""
651
+ };
652
+ return { ...fold, ended: false, turns: [...fold.turns, turn] };
653
+ }
637
654
  function apply(fold, r) {
638
655
  switch (r.kind) {
639
656
  case "receipt": {
@@ -809,6 +826,9 @@ var UNSENT_SUMMARY = "The runner restarted while it prepared this run, so the Ta
809
826
  var CHILDREN_WAIT_MS = 5e3;
810
827
  var RETRY_MIN_MS = 1e3;
811
828
  var RETRY_MAX_MS = 3e4;
829
+ var AUTH_LOCK_WAIT_MS = 7e4;
830
+ var AUTH_LOCK_TRIES = 2;
831
+ var AUTH_LOCK_CONTINUE = "Claude Code stopped because it could not refresh its sign-in, and that is clear now. Continue the work from where you stopped. Do not repeat a step that already took effect, such as a sent message, a push or a booking. If the work is already done, say so in one sentence.";
812
832
  var STOPPED_IN_PREPARATION = new Error("stopped while being prepared");
813
833
  function unpreparedEnd(harness, err) {
814
834
  if (err === STOPPED_IN_PREPARATION)
@@ -938,6 +958,8 @@ var CloudroomDriver = class {
938
958
  kept;
939
959
  /** Runs looking for the next model, by thread. */
940
960
  moving = /* @__PURE__ */ new Set();
961
+ /** Runs that wait out the OAuth refresh lock, by thread: wakes the wait on a Stop. */
962
+ waking = /* @__PURE__ */ new Map();
941
963
  /** Runs that wait after a turn without a result, by thread: ends the run on a Stop. */
942
964
  resting = /* @__PURE__ */ new Map();
943
965
  /** The account's models, best first, while CATALOG_MS lasts. */
@@ -1024,8 +1046,7 @@ var CloudroomDriver = class {
1024
1046
  }
1025
1047
  /** A hold's step, to the mesh (runner-log HoldCode), by the run's work id. */
1026
1048
  holdLog(code, thread, ms) {
1027
- const work = thread.startsWith(CLOOP_SESSION_PREFIX) ? thread.slice(CLOOP_SESSION_PREFIX.length) : null;
1028
- this.deps.holdLog?.(code, work, ms);
1049
+ this.deps.holdLog?.(code, workOf(thread), ms);
1029
1050
  }
1030
1051
  /** Named after the thread, not the process: a restarted daemon writes or removes the same lease. */
1031
1052
  leaseFile(thread) {
@@ -1417,6 +1438,13 @@ ${line}` : line;
1417
1438
  this.log(`interrupt thread=${id} while moving model`);
1418
1439
  return { ok: true, was_running: true };
1419
1440
  }
1441
+ const wake = this.waking.get(id);
1442
+ if (wake && !this.stopped.has(id)) {
1443
+ this.stopped.add(id);
1444
+ this.log(`interrupt thread=${id} while waiting out the auth lock`);
1445
+ wake();
1446
+ return { ok: true, was_running: true };
1447
+ }
1420
1448
  const stopped = await this.stopRun(this.carrier(id), commandId);
1421
1449
  if (!stopped.was_running && this.resting.get(id)?.()) return { ok: true, was_running: true };
1422
1450
  return stopped;
@@ -1493,13 +1521,16 @@ ${line}` : line;
1493
1521
  * A run the account refused its model moves to a new session (moveModel)
1494
1522
  * and the watch follows that one under the same thread, from the run's
1495
1523
  * kept facts after a restart too.
1524
+ *
1525
+ * A Claude Code run that stopped on the OAuth refresh lock carries on in
1526
+ * the same session after the lock goes stale (carryOnPastAuthLock).
1496
1527
  */
1497
1528
  watch(id, report) {
1498
1529
  const onEvent = (event) => {
1499
1530
  const ends = event.kind === "settled" || event.kind === "failed";
1500
1531
  if (ends) this.folded.delete(id);
1501
1532
  if (ends && this.runModels.has(id))
1502
- this.keep(id, { ended_at: new Date(this.now()).toISOString() });
1533
+ this.keep(id, { ended_at: new Date(this.now()).toISOString(), auth_retries: void 0 });
1503
1534
  report(ends ? { ...event, harness: this.harness } : event);
1504
1535
  };
1505
1536
  let session = this.carrier(id);
@@ -1538,6 +1569,21 @@ ${line}` : line;
1538
1569
  return;
1539
1570
  }
1540
1571
  }
1572
+ const locked = event.kind === "failed" && !event.error && this.harness === "claude-code" && CLAUDE_AUTH_LOCKED.test(event.summary ?? "");
1573
+ if (locked) {
1574
+ const failed = fold.turns.filter((t) => !t.cancelled).at(-1)?.id;
1575
+ const carried = await this.carryOnPastAuthLock(id, session, failed, () => stopped);
1576
+ if (stopped) return;
1577
+ if (carried === "stopped") {
1578
+ stop();
1579
+ onEvent({ kind: "failed", summary: STOPPED_SUMMARY, error: "interrupted" });
1580
+ return;
1581
+ }
1582
+ if (carried) {
1583
+ fold = awaiting(fold, carried);
1584
+ return;
1585
+ }
1586
+ }
1541
1587
  if (event.error !== "interrupted" && await this.working(session)) {
1542
1588
  if (stopped) return;
1543
1589
  fold = { ...fold, ended: false };
@@ -1731,6 +1777,74 @@ ${line}` : line;
1731
1777
  );
1732
1778
  return move;
1733
1779
  }
1780
+ /**
1781
+ * Claude Code stops a turn when another Claude Code process holds its
1782
+ * OAuth refresh lock. It tries for a few seconds only, and in a container
1783
+ * it cannot prove a dead holder gone, so a lock left behind blocks for up
1784
+ * to 60 s (12 November 2026, a production run failed 7 s after launch).
1785
+ * The run waits AUTH_LOCK_WAIT_MS, then the same session hears
1786
+ * AUTH_LOCK_CONTINUE and the failed turn's own prompt, so a run that did
1787
+ * work before the stop carries on and a run that did none starts. At most
1788
+ * AUTH_LOCK_TRIES times per run; the count is kept (RunModel), so it
1789
+ * holds after a restart. The prompt's id is made from the session and
1790
+ * the try, so a try made again sends nothing twice. Returns the prompt's
1791
+ * request id, null when the run ends as it is, `stopped` when a Stop came.
1792
+ */
1793
+ async carryOnPastAuthLock(thread, session, failed, gone) {
1794
+ const work = workOf(thread);
1795
+ const n = (this.runModels.get(thread)?.auth_retries ?? 0) + 1;
1796
+ if (n > AUTH_LOCK_TRIES) {
1797
+ this.log(`auth lock thread=${thread} gave up tries=${n - 1}`);
1798
+ this.deps.authLockLog?.("auth_lock_failed", work, n - 1);
1799
+ return null;
1800
+ }
1801
+ this.keep(thread, { auth_retries: n });
1802
+ this.log(
1803
+ `auth lock thread=${thread} session=${session} try=${n}/${AUTH_LOCK_TRIES} wait_ms=${AUTH_LOCK_WAIT_MS}`
1804
+ );
1805
+ this.deps.authLockLog?.("auth_lock_retry", work, n, AUTH_LOCK_WAIT_MS);
1806
+ let request;
1807
+ try {
1808
+ await new Promise((resolve) => {
1809
+ const timer = setTimeout(resolve, AUTH_LOCK_WAIT_MS);
1810
+ timer.unref?.();
1811
+ this.waking.set(thread, () => {
1812
+ clearTimeout(timer);
1813
+ resolve();
1814
+ });
1815
+ });
1816
+ if (this.stopped.delete(thread)) return "stopped";
1817
+ if (gone()) return null;
1818
+ const s = await this.session(session);
1819
+ const asked = failed ? s.prompts[failed] : void 0;
1820
+ const text = asked ? `${AUTH_LOCK_CONTINUE}
1821
+
1822
+ The request you were working on:
1823
+
1824
+ ${asked}` : AUTH_LOCK_CONTINUE;
1825
+ request = coreRequestId("auth", `${session}-${n}`);
1826
+ if (!s.receipts[request])
1827
+ await this.core.command(session, "prompts", { request_id: request, text });
1828
+ } catch (err) {
1829
+ this.log(
1830
+ `auth lock carry-on failed thread=${thread}: ${err instanceof Error ? err.message : String(err)}`
1831
+ );
1832
+ this.deps.authLockLog?.("auth_lock_failed", work, n);
1833
+ return null;
1834
+ } finally {
1835
+ this.waking.delete(thread);
1836
+ }
1837
+ if (this.stopped.delete(thread)) {
1838
+ await this.stopRun(session, `auth-${request}`).catch(
1839
+ (err) => this.log(
1840
+ `interrupt after auth lock carry-on failed thread=${thread}: ${err instanceof Error ? err.message : String(err)}`
1841
+ )
1842
+ );
1843
+ return "stopped";
1844
+ }
1845
+ this.log(`auth lock thread=${thread} carried on try=${n} request=${request}`);
1846
+ return request;
1847
+ }
1734
1848
  /**
1735
1849
  * Refuse at once every child spawned without `--shared-sandbox`. Core
1736
1850
  * would run it here after 15 s anyway; the refusal makes the agent add
@@ -3100,7 +3214,9 @@ async function run2() {
3100
3214
  // Called only once calls arrive, so the socket below exists by then.
3101
3215
  followUpLost: ({ work, n, error }) => socket.send(runnerLog("followup_lost", { work, n, tool: "thread.send", error })),
3102
3216
  // Watches start after the socket too: a held run's steps, for the hold monitor.
3103
- holdLog: (code, work, ms) => socket.send(runnerLog(code, { work, ms }))
3217
+ holdLog: (code, work, ms) => socket.send(runnerLog(code, { work, ms })),
3218
+ // A Claude Code run that carries on past the OAuth refresh lock, or fails on it after its last try.
3219
+ authLockLog: (code, work, n, ms) => socket.send(runnerLog(code, { work, n, ms }))
3104
3220
  }) : local && (name === "claude-code" || name === "codex") ? await localDriver(local, name) : new T3Driver({
3105
3221
  client: () => t3.client,
3106
3222
  t3Bin: isT3(cfg) ? cfg.t3Bin : null,
@@ -98,6 +98,7 @@ var RESULT_INSTRUCTION = [
98
98
  "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.",
99
99
  `A wizard is for ${WIZARD_FOR}. When the work needs such a step, return a wizard for it, not only words. A wizard has 1 to ${WIZARD_STEPS_MAX} 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.`,
100
100
  "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.",
101
+ "When you push a branch and open no PR, list the branch as a link output with its GitHub address, https://github.com/org/repo/tree/<branch>: Cloop asks the owner whether to open one.",
101
102
  `When an open GitHub PR or issue already does this Task and you found it, not made it, add "underway": [{"title": "feat: the thing", "url": "https://github.com/org/repo/pull/1"}] to the block, at most ${UNDERWAY_MAX}: Cloop links each one to the Task. Never list it in outputs.`,
102
103
  'Your answer shows in the chat as GitHub Markdown, so most answers need no page: write the whole answer above the cloop-result block, and keep the summary to your conclusion or what you did. Make a doc output only when the answer is a document the owner will keep or share, such as a report, a plan or research longer than about 400 words, with its own headings. Then the summary is your conclusion in one or two sentences, such as "I recommend X, because Y.", the doc holds the method and caveats, and it does not repeat the summary. Title a doc for what it says, never "Full answer" or "Summary".'
103
104
  ].join("\n");
@@ -364,6 +365,7 @@ function apiErrorWords(said) {
364
365
  }
365
366
  }
366
367
  var HARNESS_SIGNED_OUT = /^\s*(Failed to authenticate:\s*OAuth session expired and could not be refreshed\b|Your access token could not be refreshed\b|Your authentication session could not be refreshed\b|Not signed in\. Please run 'codex login'|unexpected status 401\b)/i;
368
+ var CLAUDE_AUTH_LOCKED = /another Claude Code process is refreshing/i;
367
369
  var LIMIT_HOLD_MS = 60 * 6e4;
368
370
  var HARNESS_STATE = {
369
371
  limit: "at its usage limit",
@@ -1783,6 +1785,12 @@ function threadView(t) {
1783
1785
  updatedAt: t.updatedAt
1784
1786
  };
1785
1787
  }
1788
+ function lastActivity(t) {
1789
+ const times = [t.latestUserMessageAt, t.latestRunStartedAt, t.latestRunCompletedAt].filter(
1790
+ (at) => typeof at === "string"
1791
+ );
1792
+ return times.length ? times.reduce((a, b) => b > a ? b : a) : t.updatedAt;
1793
+ }
1786
1794
  function orderThreads(threads, limit) {
1787
1795
  const byRecency = (a, b) => b.updatedAt.localeCompare(a.updatedAt);
1788
1796
  const running = threads.filter((t) => t.status === "running").sort(byRecency);
@@ -1859,12 +1867,17 @@ var T3Driver = class {
1859
1867
  * call waits.
1860
1868
  */
1861
1869
  t3State = { value: null, at: 0, refreshing: null };
1870
+ /** T3's shell, each thread dated by its last work (`lastActivity`), so every reader orders and reports the same time. */
1871
+ async readShell() {
1872
+ const shell = await this.t3.http("/api/orchestration/shell", SHELL_HEADERS);
1873
+ return { ...shell, threads: shell.threads?.map((t) => ({ ...t, updatedAt: lastActivity(t) })) };
1874
+ }
1862
1875
  readT3State() {
1863
1876
  const cache = this.t3State;
1864
1877
  if (!cache.refreshing && Date.now() - cache.at > STATUS_TTL_MS) {
1865
1878
  cache.refreshing = Promise.all([
1866
1879
  this.t3.rpc("server.getConfig", {}),
1867
- this.t3.http("/api/orchestration/shell", SHELL_HEADERS)
1880
+ this.readShell()
1868
1881
  ]).then((value) => {
1869
1882
  cache.value = value;
1870
1883
  cache.at = Date.now();
@@ -1959,7 +1972,7 @@ var T3Driver = class {
1959
1972
  scope,
1960
1973
  limit
1961
1974
  }) {
1962
- const shell = await this.t3.http("/api/orchestration/shell", SHELL_HEADERS);
1975
+ const shell = await this.readShell();
1963
1976
  const all = (shell.threads ?? []).filter((t) => !isChild(t));
1964
1977
  const threads = scope === "all" ? all : all.filter(isUnsettled);
1965
1978
  const listed = orderThreads(threads, limit);
@@ -2015,7 +2028,7 @@ var T3Driver = class {
2015
2028
  if (known) return { thread_id: known.thread_id, resumed: true };
2016
2029
  const [cfg, shell] = await Promise.all([
2017
2030
  this.t3.rpc("server.getConfig", {}),
2018
- this.t3.http("/api/orchestration/shell", SHELL_HEADERS)
2031
+ this.readShell()
2019
2032
  ]);
2020
2033
  this.providers = cfg.providers;
2021
2034
  const project = pickProject(shell.projects ?? [], a.repository);
@@ -3700,6 +3713,7 @@ export {
3700
3713
  refusedModelLine,
3701
3714
  apiErrorWords,
3702
3715
  HARNESS_SIGNED_OUT,
3716
+ CLAUDE_AUTH_LOCKED,
3703
3717
  ENVIRONMENTS,
3704
3718
  environmentOf,
3705
3719
  runnerEnvironment,
@@ -9,7 +9,7 @@ import {
9
9
  imageExt,
10
10
  mediaExt,
11
11
  runnerPath
12
- } from "./chunk-DXX7OIZK.js";
12
+ } from "./chunk-6LYMSWSB.js";
13
13
 
14
14
  // src/run-previews.ts
15
15
  import { execFile as execFile2, spawn } from "child_process";
@@ -2,17 +2,17 @@
2
2
  import {
3
3
  findRun,
4
4
  ownHarness
5
- } from "./chunk-QYPDDIJL.js";
5
+ } from "./chunk-TCNIRZLU.js";
6
6
  import {
7
7
  lockThreadsFile,
8
8
  threadsFilePath
9
- } from "./chunk-7AB5JOZN.js";
9
+ } from "./chunk-7LPSTDZE.js";
10
10
  import {
11
11
  localRunsFilePath,
12
12
  readRunRecords,
13
13
  runHarness,
14
14
  takeoverSummary
15
- } from "./chunk-DXX7OIZK.js";
15
+ } from "./chunk-6LYMSWSB.js";
16
16
  import {
17
17
  sanitizeLabel
18
18
  } from "./chunk-VK6GV757.js";
@@ -9,7 +9,7 @@ import {
9
9
  readRunnerState,
10
10
  runnerStatePath,
11
11
  threadsFilePath
12
- } from "./chunk-7AB5JOZN.js";
12
+ } from "./chunk-7LPSTDZE.js";
13
13
  import {
14
14
  BoxToolError,
15
15
  CLOOP_THREAD_PREFIX,
@@ -50,7 +50,7 @@ import {
50
50
  windowsExecutable,
51
51
  windowsPowerShellEnv,
52
52
  writeBoxConfig
53
- } from "./chunk-DXX7OIZK.js";
53
+ } from "./chunk-6LYMSWSB.js";
54
54
  import {
55
55
  CLAUDE_FLOOR,
56
56
  CODEX_FLOOR,
@@ -64,14 +64,14 @@ import {
64
64
  } from "./chunk-PKIEWBR7.js";
65
65
  import {
66
66
  connectWebhook
67
- } from "./chunk-GJVUF4SB.js";
67
+ } from "./chunk-OIHUQBA4.js";
68
68
  import {
69
69
  ConnectFailure,
70
70
  connectReport,
71
71
  deviceLogin,
72
72
  newAttempt,
73
73
  sendConnectReport
74
- } from "./chunk-RTLLZQWP.js";
74
+ } from "./chunk-QKRGJKJN.js";
75
75
  import {
76
76
  defaultDeviceName,
77
77
  getMachine,
@@ -79,7 +79,7 @@ import {
79
79
  } from "./chunk-SBYSVZ7J.js";
80
80
  import {
81
81
  VERSION
82
- } from "./chunk-BRDSWUDJ.js";
82
+ } from "./chunk-KYDTE53W.js";
83
83
  import {
84
84
  STAGING_ORIGIN,
85
85
  getOrigin,
@@ -585,6 +585,29 @@ async function answerCall(ctx, frame, io) {
585
585
  return outcome;
586
586
  }
587
587
 
588
+ // src/device-check.ts
589
+ var RELINK_WITHIN_MS = 14 * 864e5;
590
+ async function checkOwnDevice(origin, deviceToken, fetchFn = fetch) {
591
+ try {
592
+ const res = await fetchFn(`${origin}/api/agent/mesh/device`, {
593
+ headers: { authorization: `Bearer ${deviceToken}`, accept: "application/json" },
594
+ signal: AbortSignal.timeout(1e4)
595
+ });
596
+ const body = await res.json().catch(() => null);
597
+ if (res.status === 401 && body?.error === "reauth") return { state: "refused" };
598
+ if (res.ok && typeof body?.kind === "string" && typeof body.expires_at === "string" && (typeof body.environment_id === "string" || body.environment_id === null))
599
+ return {
600
+ state: "live",
601
+ kind: body.kind,
602
+ environmentId: body.environment_id,
603
+ expiresAt: body.expires_at
604
+ };
605
+ return { state: "unchecked" };
606
+ } catch {
607
+ return { state: "unchecked" };
608
+ }
609
+ }
610
+
588
611
  // src/device-revoke.ts
589
612
  function tokenGone(revoke) {
590
613
  return revoke === "revoked" || revoke === "already_revoked" || revoke === "no_device";
@@ -1896,7 +1919,7 @@ function fold(cursor, signals, out2) {
1896
1919
  case "agent": {
1897
1920
  for (const call of signal.calls ?? []) follow(cursor, call);
1898
1921
  if (!signal.text && !signal.actions?.length) break;
1899
- cursor.live = { at: signal.at, state: "working" };
1922
+ if (signal.text || signal.calls?.length) cursor.live = { at: signal.at, state: "working" };
1900
1923
  if (cursor.verdict !== "owner") break;
1901
1924
  if (!cursor.open) cursor.open = { seq: cursor.seq++, at: signal.at, text: "", actions: [] };
1902
1925
  const open = cursor.open;
@@ -2626,6 +2649,67 @@ async function revokeReplaced(previous, kind, revoke, say) {
2626
2649
  tokenGone(await revoke(previous.deviceToken)) ? " Revoked the old device on Cloop." : " Could not revoke the old device. Press Disconnect on its card on the Threads page."
2627
2650
  );
2628
2651
  }
2652
+ async function storedDevice(opts) {
2653
+ const { previous, kind } = opts;
2654
+ if (opts.asked) return { relink: opts.asked };
2655
+ if (!previous || isHosted(previous) || !previous.deviceToken) return { relink: "no_token" };
2656
+ if (isLocal(previous) !== (kind === "local")) return { relink: "other_kind" };
2657
+ const issuedBy = previous.origin ?? opts.replacedOrigin;
2658
+ if (issuedBy && issuedBy !== opts.origin) return { relink: "other_cloop" };
2659
+ if (previous.environmentId !== opts.environmentId) return { relink: "other_machine" };
2660
+ const device = await opts.check(previous.deviceToken);
2661
+ if (device.state !== "live") return { relink: device.state };
2662
+ if (device.kind !== kind || device.environmentId !== opts.environmentId)
2663
+ return { relink: "other_machine" };
2664
+ if (Date.parse(device.expiresAt) - (opts.now ?? Date.now()) <= RELINK_WITHIN_MS)
2665
+ return { relink: "expiring" };
2666
+ return { token: previous.deviceToken, expiresAt: device.expiresAt };
2667
+ }
2668
+ var RELINK_LINE = {
2669
+ asked: "--relink: approve this computer again in the browser.",
2670
+ named: "--name renames this computer on Cloop, so approve it again in the browser.",
2671
+ no_token: null,
2672
+ other_kind: null,
2673
+ other_cloop: "The device token on this computer is from another Cloop, so approve this one in the browser.",
2674
+ other_machine: "The device token on this computer was approved for another T3 Code or machine, so approve this one in the browser.",
2675
+ refused: "Cloop no longer accepts the device token on this computer: it was disconnected, it expired, or Cloop is off for this account. Approve it again in the browser.",
2676
+ expiring: `The device token on this computer ends within ${RELINK_WITHIN_MS / 864e5} days, so approve it again in the browser to renew it.`,
2677
+ unchecked: "Could not reach Cloop to check the device token on this computer, so approve it again in the browser."
2678
+ };
2679
+ function relinkLine(reason) {
2680
+ return RELINK_LINE[reason];
2681
+ }
2682
+ function keptLine(expiresAt) {
2683
+ return `${bold("Cloop machine")} Cloop still accepts this computer, until ${expiresAt.slice(0, 10)}. No browser step. To approve it again, run: cloop connect --relink`;
2684
+ }
2685
+ async function deviceFor(argv, attempt, previous, login) {
2686
+ attempt.step = "login";
2687
+ const origin = getOrigin();
2688
+ const stored = await storedDevice({
2689
+ previous,
2690
+ kind: login.device.kind,
2691
+ environmentId: login.device.environmentId,
2692
+ origin,
2693
+ ...attempt.replacedOrigin ? { replacedOrigin: attempt.replacedOrigin } : {},
2694
+ asked: argv.includes("--relink") ? "asked" : flag(argv, "--name") ? "named" : null,
2695
+ check: (token) => checkOwnDevice(origin, token)
2696
+ });
2697
+ console.error(
2698
+ `[runner:connect] device=${"token" in stored ? "kept" : "approved"} relink=${"relink" in stored ? stored.relink : "none"}`
2699
+ );
2700
+ if ("token" in stored) {
2701
+ attempt.deviceLogin = "kept";
2702
+ attempt.deviceToken = stored.token;
2703
+ out(keptLine(stored.expiresAt));
2704
+ return stored.token;
2705
+ }
2706
+ attempt.relink = stored.relink;
2707
+ const why = relinkLine(stored.relink);
2708
+ if (why) out(`${bold("Cloop machine")} ${why}`);
2709
+ attempt.deviceToken = await deviceLogin({ origin, ...login });
2710
+ attempt.deviceLogin = "approved";
2711
+ return attempt.deviceToken;
2712
+ }
2629
2713
  function fallbackLine(reason, driver) {
2630
2714
  return `T3 Code is running but would not pair (${reason}). Connecting ${HARNESS_NAME[driver]} instead. To use T3, create a pairing link in T3 Code (Settings, Connections) and run: cloop connect --t3-pair <link>`;
2631
2715
  }
@@ -3229,20 +3313,15 @@ async function connectT3(argv, attempt, fallback, chosen, services) {
3229
3313
  );
3230
3314
  }
3231
3315
  },
3232
- deviceLogin: async (environment) => {
3233
- attempt.step = "login";
3234
- attempt.deviceToken = await deviceLogin({
3235
- origin: getOrigin(),
3236
- deviceName: flag(argv, "--name") ?? shortMachineName(),
3237
- device: {
3238
- kind: "workstation",
3239
- environmentId: environment.environmentId,
3240
- label: environment.label,
3241
- version: environment.serverVersion
3242
- }
3243
- });
3244
- return attempt.deviceToken;
3245
- },
3316
+ deviceLogin: (environment) => deviceFor(argv, attempt, previous, {
3317
+ deviceName: flag(argv, "--name") ?? shortMachineName(),
3318
+ device: {
3319
+ kind: "workstation",
3320
+ environmentId: environment.environmentId,
3321
+ label: environment.label,
3322
+ version: environment.serverVersion
3323
+ }
3324
+ }),
3246
3325
  writeBoxConfig: (cfg2) => writeBoxConfig({
3247
3326
  ...cfg2,
3248
3327
  origin: getOrigin(),
@@ -3298,9 +3377,7 @@ async function connectLocal(driver, found, argv, attempt, chosen, services) {
3298
3377
  out(
3299
3378
  `${bold("Cloop machine")} Connecting ${deviceName} as a local machine with ${harnessLine(harness)}, using @cloop/runner ${VERSION}.`
3300
3379
  );
3301
- attempt.step = "login";
3302
- const deviceToken = await deviceLogin({ origin: getOrigin(), deviceName, device });
3303
- attempt.deviceToken = deviceToken;
3380
+ const deviceToken = await deviceFor(argv, attempt, previous, { deviceName, device });
3304
3381
  const cfg = {
3305
3382
  hideOtherThreads: otherThreadsChoice(argv, previous),
3306
3383
  driver,
@@ -3658,6 +3735,8 @@ export {
3658
3735
  fallbackDriver,
3659
3736
  isWorkstation,
3660
3737
  revokeReplaced,
3738
+ storedDevice,
3739
+ relinkLine,
3661
3740
  fallbackLine,
3662
3741
  connectChosen,
3663
3742
  systemdAssignment,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/version.ts
4
- var VERSION = true ? "0.3.64" : "0.0.0-dev";
4
+ var VERSION = true ? "0.3.67" : "0.0.0-dev";
5
5
 
6
6
  export {
7
7
  VERSION
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ConnectFailure,
4
4
  deviceLogin
5
- } from "./chunk-RTLLZQWP.js";
5
+ } from "./chunk-QKRGJKJN.js";
6
6
  import {
7
7
  ApiError,
8
8
  ReauthError,
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-SBYSVZ7J.js";
7
7
  import {
8
8
  VERSION
9
- } from "./chunk-BRDSWUDJ.js";
9
+ } from "./chunk-KYDTE53W.js";
10
10
  import {
11
11
  getOrigin,
12
12
  readCredentials,
@@ -42,7 +42,9 @@ function newAttempt(now = Date.now()) {
42
42
  claudeInstall: null,
43
43
  mcpRegistered: [],
44
44
  mcpSignedIn: [],
45
- deviceToken: null
45
+ deviceToken: null,
46
+ deviceLogin: null,
47
+ relink: null
46
48
  };
47
49
  }
48
50
  function shortMachineLabel(machine) {
@@ -65,6 +67,8 @@ function connectReport(attempt, error, machine, now = Date.now()) {
65
67
  claude_install: attempt.claudeInstall,
66
68
  mcp_registered: attempt.mcpRegistered,
67
69
  mcp_signed_in: attempt.mcpSignedIn,
70
+ device_login: attempt.deviceLogin,
71
+ relink: attempt.relink,
68
72
  step: attempt.step,
69
73
  outcome: error ? "failed" : "ok",
70
74
  error_code: error,
@@ -9,7 +9,7 @@ import {
9
9
  runHarness,
10
10
  runLogDir,
11
11
  runLogPath
12
- } from "./chunk-DXX7OIZK.js";
12
+ } from "./chunk-6LYMSWSB.js";
13
13
  import {
14
14
  sanitizeLabel,
15
15
  stripControl
@@ -37,6 +37,7 @@ import {
37
37
  programFor,
38
38
  psQuote,
39
39
  registerTaskScript,
40
+ relinkLine,
40
41
  rememberedDriver,
41
42
  rerunCommand,
42
43
  resolveRepos,
@@ -45,6 +46,7 @@ import {
45
46
  runSteps,
46
47
  serviceEnv,
47
48
  sessionFromLink,
49
+ storedDevice,
48
50
  systemServices,
49
51
  systemdAssignment,
50
52
  systemdWord,
@@ -55,17 +57,17 @@ import {
55
57
  which,
56
58
  workFolder,
57
59
  workFolderLine
58
- } from "./chunk-MSCSQNNI.js";
60
+ } from "./chunk-IK7YYRMU.js";
59
61
  import "./chunk-5RB7XKPB.js";
60
- import "./chunk-7AB5JOZN.js";
61
- import "./chunk-DXX7OIZK.js";
62
+ import "./chunk-7LPSTDZE.js";
63
+ import "./chunk-6LYMSWSB.js";
62
64
  import "./chunk-VK6GV757.js";
63
65
  import "./chunk-365HFCQQ.js";
64
66
  import "./chunk-PKIEWBR7.js";
65
- import "./chunk-GJVUF4SB.js";
66
- import "./chunk-RTLLZQWP.js";
67
+ import "./chunk-OIHUQBA4.js";
68
+ import "./chunk-QKRGJKJN.js";
67
69
  import "./chunk-SBYSVZ7J.js";
68
- import "./chunk-BRDSWUDJ.js";
70
+ import "./chunk-KYDTE53W.js";
69
71
  import "./chunk-D5UZW42X.js";
70
72
  export {
71
73
  DEFAULT_T3_URL,
@@ -105,6 +107,7 @@ export {
105
107
  programFor,
106
108
  psQuote,
107
109
  registerTaskScript,
110
+ relinkLine,
108
111
  rememberedDriver,
109
112
  rerunCommand,
110
113
  resolveRepos,
@@ -113,6 +116,7 @@ export {
113
116
  runSteps,
114
117
  serviceEnv,
115
118
  sessionFromLink,
119
+ storedDevice,
116
120
  systemServices,
117
121
  systemdAssignment,
118
122
  systemdWord,
@@ -7,17 +7,17 @@ import {
7
7
  runnerOrigin,
8
8
  stopService,
9
9
  unitOrigin
10
- } from "./chunk-MSCSQNNI.js";
10
+ } from "./chunk-IK7YYRMU.js";
11
11
  import "./chunk-5RB7XKPB.js";
12
- import "./chunk-7AB5JOZN.js";
13
- import "./chunk-DXX7OIZK.js";
12
+ import "./chunk-7LPSTDZE.js";
13
+ import "./chunk-6LYMSWSB.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-365HFCQQ.js";
16
16
  import "./chunk-PKIEWBR7.js";
17
- import "./chunk-GJVUF4SB.js";
18
- import "./chunk-RTLLZQWP.js";
17
+ import "./chunk-OIHUQBA4.js";
18
+ import "./chunk-QKRGJKJN.js";
19
19
  import "./chunk-SBYSVZ7J.js";
20
- import "./chunk-BRDSWUDJ.js";
20
+ import "./chunk-KYDTE53W.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-MSCSQNNI.js";
5
+ } from "./chunk-IK7YYRMU.js";
6
6
  import "./chunk-5RB7XKPB.js";
7
- import "./chunk-7AB5JOZN.js";
8
- import "./chunk-DXX7OIZK.js";
7
+ import "./chunk-7LPSTDZE.js";
8
+ import "./chunk-6LYMSWSB.js";
9
9
  import "./chunk-VK6GV757.js";
10
10
  import "./chunk-365HFCQQ.js";
11
11
  import "./chunk-PKIEWBR7.js";
12
- import "./chunk-GJVUF4SB.js";
13
- import "./chunk-RTLLZQWP.js";
12
+ import "./chunk-OIHUQBA4.js";
13
+ import "./chunk-QKRGJKJN.js";
14
14
  import "./chunk-SBYSVZ7J.js";
15
- import "./chunk-BRDSWUDJ.js";
15
+ import "./chunk-KYDTE53W.js";
16
16
  import "./chunk-D5UZW42X.js";
17
17
  export {
18
18
  existingRunnerEnvironment,
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-365HFCQQ.js";
5
5
  import {
6
6
  VERSION
7
- } from "./chunk-BRDSWUDJ.js";
7
+ } from "./chunk-KYDTE53W.js";
8
8
  import {
9
9
  applyEnvironmentFlag
10
10
  } from "./chunk-D5UZW42X.js";
@@ -31,7 +31,7 @@ Usage:
31
31
  cloop hook activity Lifecycle hook: records what this session is doing
32
32
  cloop connect [--repo <path>]... [--driver t3|claude-code|codex] [--fallback-model <list>]
33
33
  [--no-service] [--no-start] [--ask] [--ask-everything] [--t3-pair <link>]
34
- [--hide-other-threads | --show-other-threads]
34
+ [--hide-other-threads | --show-other-threads] [--relink]
35
35
  Make this computer a Cloop machine: T3 Code, else
36
36
  Claude Code or Codex in the folders you name,
37
37
  else ~/Cloop. No repository is needed. --ask
@@ -43,7 +43,10 @@ Usage:
43
43
  started yourself; --hide-other-threads hides them.
44
44
  Cloop also reads what you and your agents say
45
45
  and do in those threads, redacted here, never
46
- tool output or files
46
+ tool output or files. Run again on a connected
47
+ computer, it keeps the approval Cloop still
48
+ accepts and only rewrites and restarts the
49
+ service; --relink approves it in the browser again
47
50
  cloop use t3|claude-code|codex Run Cloop work here with that harness. It reconnects
48
51
  this machine, swaps its service, and keeps the choice
49
52
  cloop disconnect [--yes] Stop being a Cloop machine in one environment: revoke
@@ -69,7 +72,7 @@ Add --staging to any command to use Cloop staging instead of production.
69
72
  A production machine and a staging machine can run side by side on one computer.
70
73
  `;
71
74
  async function pinExistingRunner() {
72
- const { pinExistingRunner: pin } = await import("./existing-runner-ZCFTLQ3Q.js");
75
+ const { pinExistingRunner: pin } = await import("./existing-runner-NNXJGK2R.js");
73
76
  const { note } = pin();
74
77
  if (note) console.error(note);
75
78
  }
@@ -77,7 +80,7 @@ async function main() {
77
80
  switch (command) {
78
81
  case "login":
79
82
  case "auth": {
80
- const { loginCommand } = await import("./login-NTPTTFH6.js");
83
+ const { loginCommand } = await import("./login-COK223KI.js");
81
84
  await loginCommand(argv);
82
85
  break;
83
86
  }
@@ -87,61 +90,61 @@ async function main() {
87
90
  break;
88
91
  }
89
92
  case "serve": {
90
- const { startMcpServer } = await import("./mcp-server-3HANVJQE.js");
93
+ const { startMcpServer } = await import("./mcp-server-5525QT5K.js");
91
94
  await startMcpServer();
92
95
  break;
93
96
  }
94
97
  case "statusline": {
95
- const { statuslineCommand } = await import("./statusline-3TMAMI7F.js");
98
+ const { statuslineCommand } = await import("./statusline-QHEED6IO.js");
96
99
  statuslineCommand();
97
100
  break;
98
101
  }
99
102
  case "connect": {
100
- const { connectCommand } = await import("./connect-TSDASBHE.js");
103
+ const { connectCommand } = await import("./connect-3GG5D7XC.js");
101
104
  await connectCommand(argv.slice(1));
102
105
  break;
103
106
  }
104
107
  case "use": {
105
- const { useCommand } = await import("./use-N27RLY7L.js");
108
+ const { useCommand } = await import("./use-J6CNF6JU.js");
106
109
  process.exitCode = await useCommand(argv.slice(1));
107
110
  break;
108
111
  }
109
112
  case "disconnect": {
110
- const { disconnectCommand } = await import("./disconnect-MI2MKB37.js");
113
+ const { disconnectCommand } = await import("./disconnect-VK3CZIDQ.js");
111
114
  await disconnectCommand(argv.slice(1));
112
115
  break;
113
116
  }
114
117
  case "box": {
115
- const { boxCommand } = await import("./box-OQO3DWIN.js");
118
+ const { boxCommand } = await import("./box-NMG35YB2.js");
116
119
  await boxCommand(argv.slice(1));
117
120
  break;
118
121
  }
119
122
  case "runs": {
120
123
  await pinExistingRunner();
121
- const { runsCommand } = await import("./runs-Q3ONIMHU.js");
124
+ const { runsCommand } = await import("./runs-DOFU45TW.js");
122
125
  process.exitCode = runsCommand();
123
126
  break;
124
127
  }
125
128
  case "watch": {
126
129
  await pinExistingRunner();
127
- const { watchCommand } = await import("./runs-Q3ONIMHU.js");
130
+ const { watchCommand } = await import("./runs-DOFU45TW.js");
128
131
  process.exitCode = await watchCommand(argv.slice(1));
129
132
  break;
130
133
  }
131
134
  case "takeover": {
132
135
  await pinExistingRunner();
133
- const { takeoverCommand } = await import("./takeover-GTOQXWAM.js");
136
+ const { takeoverCommand } = await import("./takeover-U2EHJ5GW.js");
134
137
  process.exitCode = await takeoverCommand(argv.slice(1));
135
138
  break;
136
139
  }
137
140
  case "resume": {
138
141
  await pinExistingRunner();
139
- const { resumeCommand } = await import("./runs-Q3ONIMHU.js");
142
+ const { resumeCommand } = await import("./runs-DOFU45TW.js");
140
143
  process.exitCode = await resumeCommand(argv.slice(1));
141
144
  break;
142
145
  }
143
146
  case "runner": {
144
- const { runnerCommand } = await import("./runner-UUSWMN54.js");
147
+ const { runnerCommand } = await import("./runner-NSFLXWNP.js");
145
148
  await runnerCommand(argv.slice(1));
146
149
  break;
147
150
  }
@@ -3,9 +3,9 @@ import {
3
3
  deviceLogin,
4
4
  loginCommand,
5
5
  refusalSentence
6
- } from "./chunk-RTLLZQWP.js";
6
+ } from "./chunk-QKRGJKJN.js";
7
7
  import "./chunk-SBYSVZ7J.js";
8
- import "./chunk-BRDSWUDJ.js";
8
+ import "./chunk-KYDTE53W.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  deviceLogin,
@@ -31,7 +31,7 @@ import {
31
31
  } from "./chunk-SBYSVZ7J.js";
32
32
  import {
33
33
  VERSION
34
- } from "./chunk-BRDSWUDJ.js";
34
+ } from "./chunk-KYDTE53W.js";
35
35
  import {
36
36
  getMeshUrl,
37
37
  getToken
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  connectWebhook,
4
4
  runnerCommand
5
- } from "./chunk-GJVUF4SB.js";
6
- import "./chunk-RTLLZQWP.js";
5
+ } from "./chunk-OIHUQBA4.js";
6
+ import "./chunk-QKRGJKJN.js";
7
7
  import "./chunk-SBYSVZ7J.js";
8
- import "./chunk-BRDSWUDJ.js";
8
+ import "./chunk-KYDTE53W.js";
9
9
  import "./chunk-D5UZW42X.js";
10
10
  export {
11
11
  connectWebhook,
@@ -9,8 +9,8 @@ import {
9
9
  runsCommand,
10
10
  sessionFolder,
11
11
  watchCommand
12
- } from "./chunk-QYPDDIJL.js";
13
- import "./chunk-DXX7OIZK.js";
12
+ } from "./chunk-TCNIRZLU.js";
13
+ import "./chunk-6LYMSWSB.js";
14
14
  import "./chunk-VK6GV757.js";
15
15
  import "./chunk-D5UZW42X.js";
16
16
  export {
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-VK6GV757.js";
8
8
  import {
9
9
  VERSION
10
- } from "./chunk-BRDSWUDJ.js";
10
+ } from "./chunk-KYDTE53W.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-FN2G5ZWH.js";
13
- import "./chunk-QYPDDIJL.js";
14
- import "./chunk-7AB5JOZN.js";
15
- import "./chunk-DXX7OIZK.js";
12
+ } from "./chunk-7ZL3Z3IO.js";
13
+ import "./chunk-TCNIRZLU.js";
14
+ import "./chunk-7LPSTDZE.js";
15
+ import "./chunk-6LYMSWSB.js";
16
16
  import "./chunk-VK6GV757.js";
17
17
  import "./chunk-SBYSVZ7J.js";
18
18
  import "./chunk-D5UZW42X.js";
@@ -3,20 +3,20 @@ import {
3
3
  DRIVER_NAME,
4
4
  pinExistingRunner,
5
5
  runConnect
6
- } from "./chunk-MSCSQNNI.js";
6
+ } from "./chunk-IK7YYRMU.js";
7
7
  import "./chunk-5RB7XKPB.js";
8
- import "./chunk-7AB5JOZN.js";
8
+ import "./chunk-7LPSTDZE.js";
9
9
  import {
10
10
  isLocal,
11
11
  readRunnerConfig
12
- } from "./chunk-DXX7OIZK.js";
12
+ } from "./chunk-6LYMSWSB.js";
13
13
  import "./chunk-VK6GV757.js";
14
14
  import "./chunk-365HFCQQ.js";
15
15
  import "./chunk-PKIEWBR7.js";
16
- import "./chunk-GJVUF4SB.js";
17
- import "./chunk-RTLLZQWP.js";
16
+ import "./chunk-OIHUQBA4.js";
17
+ import "./chunk-QKRGJKJN.js";
18
18
  import "./chunk-SBYSVZ7J.js";
19
- import "./chunk-BRDSWUDJ.js";
19
+ import "./chunk-KYDTE53W.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.64",
3
+ "version": "0.3.67",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Make your computer and your agents Cloop machines: device login, the machine daemon, the Cloop MCP server, and Claude Code hooks.",