@cloop/runner 0.3.29 → 0.3.30

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.
@@ -864,11 +864,27 @@ function limitedModel(said) {
864
864
  function refusedModel(said) {
865
865
  return /The '([^']+)' model is not supported/i.exec(said ?? "")?.[1] ?? null;
866
866
  }
867
+ 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;
867
868
  var LIMIT_HOLD_MS = 60 * 6e4;
868
- function handoverPrompt(prompt, from) {
869
+ var HARNESS_STATE = {
870
+ limit: "at its usage limit",
871
+ signed_out: "signed out here",
872
+ missing: "not installed here"
873
+ };
874
+ function movedLine(reason, from, to, tense) {
875
+ return `${from} ${tense} ${HARNESS_STATE[reason]}, so ${to} did this run.`;
876
+ }
877
+ function movingLine(reason, from, to) {
878
+ return `${from} is ${HARNESS_STATE[reason]}, so I moved this to ${to}`;
879
+ }
880
+ var STOPPED_BECAUSE = {
881
+ limit: "stopped at its usage limit",
882
+ signed_out: "could not sign in"
883
+ };
884
+ function handoverPrompt(prompt, from, reason = "limit") {
869
885
  return `${prompt}
870
886
 
871
- ${from} started this work and stopped at its usage limit. Its changes, if any, are in this checkout. Read \`git status\` and \`git log\` first, and carry on from there.`;
887
+ ${from} started this work and ${STOPPED_BECAUSE[reason]}. Its changes, if any, are in this checkout. Read \`git status\` and \`git log\` first, and carry on from there.`;
872
888
  }
873
889
 
874
890
  // src/drivers/usage.ts
@@ -1268,22 +1284,60 @@ function permissionOf(runtimeMode) {
1268
1284
  return runtimeMode === "full-access" ? "full" : "ask";
1269
1285
  }
1270
1286
  var CODEX_PROVIDER = "codex";
1287
+ var CLAUDE_PROVIDER = "claudeAgent";
1271
1288
  var PROVIDER_NAMES = { claudeAgent: "Claude Code", codex: "Codex" };
1272
- function providerName(instanceId) {
1289
+ function providerName(instanceId, cfg) {
1290
+ const displayName = cfg?.providers.find((p) => p.instanceId === instanceId)?.displayName;
1291
+ if (displayName) return displayName;
1273
1292
  return instanceId && PROVIDER_NAMES[instanceId] || instanceId || "The harness";
1274
1293
  }
1294
+ function readyProvider(cfg, driver) {
1295
+ const candidates = [...cfg.providers].sort(
1296
+ (a, b) => Number(b.instanceId === driver) - Number(a.instanceId === driver)
1297
+ );
1298
+ for (const p of candidates) {
1299
+ if ((p.driver ?? p.instanceId) !== driver || !p.enabled || !p.installed) continue;
1300
+ if (p.auth && p.auth.status !== "authenticated") continue;
1301
+ const model = p.models?.find((m) => m.isDefault)?.slug ?? p.models?.[0]?.slug;
1302
+ if (model) return { instanceId: p.instanceId, model };
1303
+ }
1304
+ return null;
1305
+ }
1306
+ function otherDriver(cfg, instanceId) {
1307
+ const p = cfg.providers.find((x) => x.instanceId === instanceId);
1308
+ const driver = p?.driver ?? p?.instanceId ?? instanceId;
1309
+ return driver === CODEX_PROVIDER ? CLAUDE_PROVIDER : driver === CLAUDE_PROVIDER ? CODEX_PROVIDER : null;
1310
+ }
1311
+ function signedOutWords(p, run2) {
1312
+ if (run2.status !== "failed") return null;
1313
+ const said = (p.messages ?? []).filter((m) => m.role === "assistant" && m.runId === run2.id && m.text?.trim()).at(-1)?.text?.trim();
1314
+ const words = said && HARNESS_SIGNED_OUT.test(said) ? said : null;
1315
+ const failure = (p.turnItems ?? []).filter((i) => i.type === "error" && i.runId === run2.id).at(-1)?.failure;
1316
+ if (!failure) return words;
1317
+ if (failure.class && failure.class !== "provider_error") return null;
1318
+ const message = failure.message?.trim() ?? "";
1319
+ const signedOut = failure.code === "unauthorized" || /^Claude could not authenticate\b/.test(message) || HARNESS_SIGNED_OUT.test(message);
1320
+ return signedOut ? words ?? (message || null) : null;
1321
+ }
1322
+ function launchMove(cfg, own, permission, held) {
1323
+ const codex = held && own !== CODEX_PROVIDER ? readyProvider(cfg, CODEX_PROVIDER) : null;
1324
+ if (codex) return { to: codex, reason: "limit" };
1325
+ const auth = cfg.providers.find((p) => p.instanceId === own && p.enabled)?.auth;
1326
+ if (!auth || auth.status === "authenticated") return null;
1327
+ const driver = otherDriver(cfg, own);
1328
+ if (!driver || driver === CODEX_PROVIDER && permission !== "full") return null;
1329
+ const to = readyProvider(cfg, driver);
1330
+ return to ? { to, reason: "signed_out" } : null;
1331
+ }
1275
1332
  var PROVIDER_HARNESS = {
1276
1333
  claudeAgent: "claude-code",
1277
1334
  codex: "codex"
1278
1335
  };
1279
- function providerHarness(instanceId) {
1280
- return instanceId ? { harness: PROVIDER_HARNESS[instanceId] ?? instanceId } : {};
1281
- }
1282
- function codexProvider(cfg) {
1283
- const p = cfg.providers.find((x) => (x.driver ?? x.instanceId) === CODEX_PROVIDER && x.enabled);
1284
- if (!p || p.auth && p.auth.status !== "authenticated") return null;
1285
- const model = p.models?.find((m) => m.isDefault)?.slug ?? p.models?.[0]?.slug;
1286
- return model ? { instanceId: p.instanceId, model } : null;
1336
+ function providerHarness(instanceId, cfg) {
1337
+ if (!instanceId) return {};
1338
+ const p = cfg?.providers.find((x) => x.instanceId === instanceId);
1339
+ const id = p?.driver ?? instanceId;
1340
+ return { harness: PROVIDER_HARNESS[id] ?? id };
1287
1341
  }
1288
1342
  function pickProject(projects, repository) {
1289
1343
  if (!repository) {
@@ -1374,6 +1428,8 @@ var T3Driver = class {
1374
1428
  held = /* @__PURE__ */ new Map();
1375
1429
  /** Threads this daemon launched. A restart forgets them, and a forgotten thread is not moved. */
1376
1430
  launched = /* @__PURE__ */ new Map();
1431
+ /** The box's providers as last read, so a run's end names a custom provider by its driver. */
1432
+ providers = [];
1377
1433
  /** Until then, a launch that names no harness starts on Codex: the Claude account is at its limit. */
1378
1434
  limitedUntil = 0;
1379
1435
  get capabilities() {
@@ -1503,6 +1559,7 @@ var T3Driver = class {
1503
1559
  this.t3.rpc("server.getConfig", {}),
1504
1560
  this.t3.http("/api/orchestration/shell", SHELL_HEADERS)
1505
1561
  ]);
1562
+ this.providers = cfg.providers;
1506
1563
  const project = pickProject(shell.projects ?? [], a.repository);
1507
1564
  const runtimeMode = a.runtime_mode ?? cfg.settings?.defaultRuntimeMode;
1508
1565
  if (!runtimeMode || !RUNTIME_MODES.has(runtimeMode))
@@ -1510,9 +1567,9 @@ var T3Driver = class {
1510
1567
  const permission = permissionOf(runtimeMode);
1511
1568
  const named = Boolean(a.harness || a.model);
1512
1569
  const held = !named && permission === "full" && this.now() < this.limitedUntil;
1513
- const own = cfg.settings?.defaultModelSelection?.instanceId ?? "claudeAgent";
1514
- const codex = held && own !== CODEX_PROVIDER ? codexProvider(cfg) : null;
1515
- const fallback = codex ?? cfg.settings?.defaultModelSelection;
1570
+ const own = cfg.settings?.defaultModelSelection?.instanceId ?? CLAUDE_PROVIDER;
1571
+ const move = named ? null : launchMove(cfg, own, permission, held);
1572
+ const fallback = move?.to ?? cfg.settings?.defaultModelSelection;
1516
1573
  const harness = a.harness ?? fallback?.instanceId ?? "claudeAgent";
1517
1574
  const provider = cfg.providers.find((p) => p.instanceId === harness && p.enabled);
1518
1575
  if (!provider) throw new BoxToolError("harness_unavailable");
@@ -1521,7 +1578,10 @@ var T3Driver = class {
1521
1578
  const model = a.model ?? (fallback?.instanceId === harness ? fallback.model : void 0) ?? provider.models?.find((m) => m.isDefault)?.slug;
1522
1579
  if (!model) throw new BoxToolError("harness_unavailable");
1523
1580
  const modelSelection = !a.model && fallback?.instanceId === harness ? fallback : { instanceId: harness, model };
1524
- if (codex) this.log(`limit hold: launch work=${a.work_id} starts on ${codex.instanceId}`);
1581
+ if (move)
1582
+ this.log(
1583
+ `${move.reason === "limit" ? "limit hold" : "signed out"}: launch work=${a.work_id} starts on ${move.to.instanceId}`
1584
+ );
1525
1585
  const photos2 = await this.photos(a);
1526
1586
  const launched = await this.t3.rpc(
1527
1587
  "orchestration.launchThread",
@@ -1547,16 +1607,21 @@ var T3Driver = class {
1547
1607
  this.launched.set(launched.threadId, {
1548
1608
  named,
1549
1609
  permission,
1550
- ...codex ? {
1610
+ ...move ? {
1551
1611
  movedFrom: "",
1552
- switched: `${providerName(own)} is at its usage limit, so Codex did this run.`
1612
+ switched: movedLine(
1613
+ move.reason,
1614
+ providerName(own, cfg),
1615
+ providerName(move.to.instanceId, cfg),
1616
+ "is"
1617
+ )
1553
1618
  } : {}
1554
1619
  });
1555
1620
  return {
1556
1621
  thread_id: launched.threadId,
1557
1622
  resumed: launched.resumed,
1558
1623
  permission,
1559
- ...providerHarness(modelSelection.instanceId),
1624
+ ...providerHarness(modelSelection.instanceId, cfg),
1560
1625
  // A resumed thread kept its first message: these photos did not go in.
1561
1626
  ...launched.resumed ? {} : delivery(a.attachments, photos2.attachments.length)
1562
1627
  };
@@ -1838,13 +1903,11 @@ var T3Driver = class {
1838
1903
  finishing = false;
1839
1904
  return;
1840
1905
  }
1841
- if (outcome.kind === "failed" && turn && await this.moveToCodex(threadId, turn, outcome)) {
1906
+ const moving = outcome.kind === "failed" && turn ? await this.handOver(threadId, turn, outcome, p) : null;
1907
+ if (moving) {
1842
1908
  finishing = false;
1843
1909
  if (stopped) return;
1844
- onEvent({
1845
- kind: "progress",
1846
- summary: `${providerName(turn.providerInstanceId)} is at its usage limit, so I moved this to Codex`
1847
- });
1910
+ onEvent({ kind: "progress", summary: moving });
1848
1911
  if (!live) void follow();
1849
1912
  return;
1850
1913
  }
@@ -1857,25 +1920,24 @@ var T3Driver = class {
1857
1920
  if (outcome.kind === "failed") {
1858
1921
  const said = outcome.last_assistant_text?.replace(/\s+/g, " ").trim();
1859
1922
  const limited = outcome.status === "failed" && HARNESS_LIMIT.test(said ?? "");
1860
- const end = limited ? {
1861
- summary: `${opening}${providerName(turn?.providerInstanceId)} said: "${said}"`.slice(
1862
- 0,
1863
- RUN_TEXT_MAX
1864
- ),
1865
- error: "harness_limit"
1866
- } : outcome.status === "interrupted" ? { summary: STOPPED_IN_T3, error: "interrupted" } : { summary: `${opening}The run ended ${outcome.status}.` };
1923
+ const signedOut = !limited && turn ? signedOutWords(p, turn) : null;
1924
+ const quoted = (words) => `${opening}${providerName(turn?.providerInstanceId)} said: "${words}"`.slice(
1925
+ 0,
1926
+ RUN_TEXT_MAX
1927
+ );
1928
+ const end = limited ? { summary: quoted(said), error: "harness_limit" } : signedOut ? { summary: quoted(signedOut.replace(/\s+/g, " ")), error: "harness_signed_out" } : outcome.status === "interrupted" ? { summary: STOPPED_IN_T3, error: "interrupted" } : { summary: `${opening}The run ended ${outcome.status}.` };
1867
1929
  onEvent({
1868
1930
  kind: "failed",
1869
1931
  ...end,
1870
1932
  ...outcome.result ? pr : {},
1871
- ...providerHarness(turn?.providerInstanceId)
1933
+ ...providerHarness(turn?.providerInstanceId, { providers: this.providers })
1872
1934
  });
1873
1935
  } else {
1874
1936
  const lost = outcome.dropped ? droppedLine(outcome.dropped, threadId) : null;
1875
1937
  if (lost) this.log(lost);
1876
1938
  onEvent({
1877
1939
  kind: "settled",
1878
- ...providerHarness(turn?.providerInstanceId),
1940
+ ...providerHarness(turn?.providerInstanceId, { providers: this.providers }),
1879
1941
  ...outcome.result ? { result: outcome.result } : {},
1880
1942
  ...outcome.last_assistant_text ? { summary: `${opening}${outcome.last_assistant_text}`.slice(0, RUN_TEXT_MAX) } : {},
1881
1943
  ...pr
@@ -1966,59 +2028,74 @@ var T3Driver = class {
1966
2028
  }
1967
2029
  /**
1968
2030
  * Once per thread: a run that failed at a Claude usage limit carries on in
1969
- * the same thread on Codex. T3 switches the thread's provider and hands
1970
- * Codex the thread so far; the worktree, with any edits, stays. A limit
1971
- * that names no model holds the account, so launches start on Codex for
1972
- * LIMIT_HOLD_MS. A thread whose Task named its harness or model stays, and
1973
- * so does one without full access, because Codex asks nothing. So does a
1974
- * thread this daemon did not launch: a restart forgets what the Task named.
2031
+ * the same thread on Codex, and a run whose harness could not sign in
2032
+ * carries on with the other harness, Claude Code or Codex, either way. T3
2033
+ * switches the thread's provider and hands it the thread so far; the
2034
+ * worktree, with any edits, stays. A limit that names no model holds the
2035
+ * account, so launches start on Codex for LIMIT_HOLD_MS; a sign-in failure
2036
+ * holds nothing. A thread whose Task named its harness or model stays, and
2037
+ * so does one without full access that would move to Codex, because Codex
2038
+ * asks nothing. So does a thread this daemon did not launch: a restart
2039
+ * forgets what the Task named. Returns the progress line of the move.
1975
2040
  */
1976
- async moveToCodex(threadId, turn, outcome) {
2041
+ async handOver(threadId, turn, outcome, p) {
2042
+ if (outcome.status !== "failed") return null;
1977
2043
  const said = outcome.last_assistant_text ?? "";
1978
- if (outcome.status !== "failed" || !HARNESS_LIMIT.test(said)) return false;
2044
+ const reason = HARNESS_LIMIT.test(said) ? "limit" : signedOutWords(p, turn) ? "signed_out" : null;
2045
+ if (!reason) return null;
1979
2046
  const from = turn.providerInstanceId;
1980
- if (from === CODEX_PROVIDER) return false;
1981
- if (!limitedModel(said)) this.limitedUntil = this.now() + LIMIT_HOLD_MS;
2047
+ if (reason === "limit") {
2048
+ if (from === CODEX_PROVIDER) return null;
2049
+ if (!limitedModel(said)) this.limitedUntil = this.now() + LIMIT_HOLD_MS;
2050
+ }
1982
2051
  const entry = this.launched.get(threadId);
1983
- if (!entry || entry.named || entry.permission !== "full" || entry.movedFrom !== void 0)
1984
- return false;
2052
+ if (!entry || entry.named || entry.movedFrom !== void 0) return null;
1985
2053
  try {
1986
- return await this.dispatchToCodex(threadId, turn, entry);
2054
+ return await this.dispatchHandover(threadId, turn, entry, reason);
1987
2055
  } catch (err) {
1988
2056
  this.log(
1989
2057
  `fallback failed thread=${threadId}: ${err instanceof Error ? err.message : String(err)}`
1990
2058
  );
1991
- return false;
2059
+ return null;
1992
2060
  }
1993
2061
  }
1994
- async dispatchToCodex(threadId, turn, entry) {
1995
- const codex = codexProvider(await this.t3.rpc("server.getConfig", {}));
1996
- if (!codex) {
1997
- this.log(`limit thread=${threadId}: Codex is not on or not signed in; the run fails`);
1998
- return false;
2062
+ async dispatchHandover(threadId, turn, entry, reason) {
2063
+ const cfg = await this.t3.rpc("server.getConfig", {});
2064
+ this.providers = cfg.providers;
2065
+ const driver = reason === "limit" ? CODEX_PROVIDER : otherDriver(cfg, turn.providerInstanceId);
2066
+ if (!driver || driver === CODEX_PROVIDER && entry.permission !== "full") return null;
2067
+ const to = readyProvider(cfg, driver);
2068
+ const name = providerName(turn.providerInstanceId, cfg);
2069
+ if (!to) {
2070
+ this.log(
2071
+ `${reason} thread=${threadId}: ${providerName(driver)} is not on or not signed in; the run fails`
2072
+ );
2073
+ return null;
1999
2074
  }
2000
- const name = providerName(turn.providerInstanceId);
2001
2075
  const id = randomUUID();
2002
2076
  await this.dispatch({
2003
2077
  type: "message.dispatch",
2004
2078
  commandId: id,
2005
2079
  threadId,
2006
2080
  messageId: id,
2007
- text: handoverPrompt("Carry on with the task in this thread.", name).concat(
2081
+ text: handoverPrompt("Carry on with the task in this thread.", name, reason).concat(
2008
2082
  `
2009
2083
 
2010
2084
  ${RESULT_INSTRUCTION}`
2011
2085
  ),
2012
2086
  attachments: [],
2013
- modelSelection: codex,
2087
+ modelSelection: to,
2014
2088
  dispatchMode: { type: "start_immediately" },
2015
2089
  createdBy: "user",
2016
2090
  creationSource: "mcp"
2017
2091
  });
2092
+ const toName = providerName(to.instanceId, cfg);
2018
2093
  entry.movedFrom = turn.id;
2019
- entry.switched = `${name} was at its usage limit, so Codex did this run.`;
2020
- this.log(`fallback thread=${threadId} provider=${codex.instanceId} model=${codex.model}`);
2021
- return true;
2094
+ entry.switched = movedLine(reason, name, toName, "was");
2095
+ this.log(
2096
+ `fallback thread=${threadId} provider=${to.instanceId} model=${to.model} reason=${reason}`
2097
+ );
2098
+ return movingLine(reason, name, toName);
2022
2099
  }
2023
2100
  now() {
2024
2101
  return this.deps.now?.() ?? Date.now();
@@ -2162,13 +2239,7 @@ function runHarness(run2, own) {
2162
2239
  const bin = harness === driver && own?.bin ? own.bin : harness === "codex" ? "codex" : "claude";
2163
2240
  return { harness, bin };
2164
2241
  }
2165
- var MOVE_STATE = {
2166
- limit: "at its usage limit",
2167
- signed_out: "signed out here",
2168
- missing: "not installed here"
2169
- };
2170
- var movedLine = (move, from, to) => `${harnessName(from)} ${move.at === "run" ? "was" : "is"} ${MOVE_STATE[move.reason]}, so ${harnessName(to)} did this run.`;
2171
- var movingLine = (move, from, to) => `${harnessName(from)} is ${MOVE_STATE[move.reason]}, so I moved this to ${harnessName(to)}`;
2242
+ var switchedLine = (move, from, to) => movedLine(move.reason, harnessName(from), harnessName(to), move.at === "run" ? "was" : "is");
2172
2243
  function failedEnd(harness, run2) {
2173
2244
  const said = run2.result?.text?.trim() || run2.lastText;
2174
2245
  const limited = HARNESS_LIMIT.test(run2.result?.text ?? "");
@@ -2413,7 +2484,8 @@ ${photos2.line}` : a.prompt,
2413
2484
  ...a.model && !moved ? { model: a.model } : {},
2414
2485
  ...a.runtime_mode ? { runtime_mode: a.runtime_mode } : {},
2415
2486
  ...a.harness ? { harness_named: true } : {},
2416
- ...moved ? { harness: dialect.name, moved, switched: movedLine(moved, own.name, dialect.name) } : {},
2487
+ ...a.model ? { model_named: true } : {},
2488
+ ...moved ? { harness: dialect.name, moved, switched: switchedLine(moved, own.name, dialect.name) } : {},
2417
2489
  pid: null,
2418
2490
  started_at: new Date(this.now()).toISOString(),
2419
2491
  head_at_launch: head
@@ -2575,7 +2647,8 @@ ${a.text}` : a.text;
2575
2647
  /**
2576
2648
  * A Task that names its harness stays on it. Otherwise a run starts on the
2577
2649
  * fallback while the runner's own harness is held at its limit, or when the
2578
- * own harness is signed out or not installed and the fallback is signed in.
2650
+ * own harness is signed out or not installed and the fallback is signed in,
2651
+ * unless the Task named its model.
2579
2652
  */
2580
2653
  async route(a) {
2581
2654
  const own = this.deps.dialect;
@@ -2586,7 +2659,7 @@ ${a.text}` : a.text;
2586
2659
  return { dialect: to, moved: { reason: "limit", at: "launch" } };
2587
2660
  const harness = await own.probe();
2588
2661
  if (harness?.signedIn) return { dialect: own };
2589
- if (to && await ready())
2662
+ if (to && !a.model && await ready())
2590
2663
  return {
2591
2664
  dialect: to,
2592
2665
  moved: { reason: harness ? "signed_out" : "missing", at: "launch" }
@@ -2717,6 +2790,9 @@ ${RESULT_INSTRUCTION}`, images));
2717
2790
  if (wasAsked) this.askNext(r, live);
2718
2791
  return;
2719
2792
  }
2793
+ case "signed_out":
2794
+ live.signedOut = true;
2795
+ return;
2720
2796
  case "result":
2721
2797
  live.outstanding--;
2722
2798
  live.result = { ok: item.ok, ...item.text ? { text: item.text } : {} };
@@ -2771,9 +2847,14 @@ ${RESULT_INSTRUCTION}`, images));
2771
2847
  if (end.error) this.log(`limit work=${r.work_id} error=${end.error}`);
2772
2848
  if (end.error === "harness_limit") {
2773
2849
  if (this.fallBack(r, live.result?.text)) return;
2774
- if (await this.moveHarness(r, live.result?.text)) return;
2850
+ if (await this.moveHarness(r, live.result?.text, "limit")) return;
2775
2851
  }
2776
- await this.end(r, { kind: "failed", ...end });
2852
+ if (live.signedOut) {
2853
+ this.log(`signed_out work=${r.work_id} harness=${this.dialectOf(r).name}`);
2854
+ if (await this.moveHarness(r, live.result?.text, "signed_out")) return;
2855
+ }
2856
+ const signedOut = !end.error && live.signedOut ? { error: "harness_signed_out" } : {};
2857
+ await this.end(r, { kind: "failed", ...end, ...signedOut });
2777
2858
  }
2778
2859
  /**
2779
2860
  * Once per run: a run stopped by its model's usage limit resumes its own
@@ -2825,7 +2906,7 @@ ${RESULT_INSTRUCTION}`, images));
2825
2906
  if (!next)
2826
2907
  this.log(`model work=${r.work_id} refused=${refused} next=none catalog=${listed.length}`);
2827
2908
  if (!next || this.stopping || r.end) return false;
2828
- const moved = r.harness && r.moved ? movedLine(r.moved, this.deps.dialect.name, r.harness) : null;
2909
+ const moved = r.harness && r.moved ? switchedLine(r.moved, this.deps.dialect.name, r.harness) : null;
2829
2910
  r.refused = tried;
2830
2911
  r.model = next;
2831
2912
  r.session_id = null;
@@ -2837,24 +2918,28 @@ ${RESULT_INSTRUCTION}`, images));
2837
2918
  this.log(`model work=${r.work_id} refused=${refused} next=${next}`);
2838
2919
  this.spawnRun(
2839
2920
  r,
2840
- r.moved?.at === "run" ? handoverPrompt(r.prompt, harnessName(this.deps.dialect.name)) : r.prompt,
2921
+ r.moved?.at === "run" ? handoverPrompt(r.prompt, harnessName(this.deps.dialect.name), r.moved.reason) : r.prompt,
2841
2922
  false
2842
2923
  );
2843
2924
  return true;
2844
2925
  }
2845
2926
  /**
2846
- * Once per run: a run its own harness cannot carry on starts again on the
2847
- * fallback harness, in the same checkout, so the edits so far carry over.
2848
- * The session does not: the prompt goes again, with a note to read the
2849
- * checkout first. A limit that names no model holds the account, so new
2850
- * runs start on the fallback for LIMIT_HOLD_MS. It does not move a run
2851
- * whose Task named its harness, nor one the fallback may not carry.
2927
+ * Once per run: a run its own harness cannot carry on, at its usage limit
2928
+ * or signed out, starts again on the fallback harness, in the same
2929
+ * checkout, so the edits so far carry over. The session does not: the
2930
+ * prompt goes again, with a note to read the checkout first. A limit that
2931
+ * names no model holds the account, so new runs start on the fallback for
2932
+ * LIMIT_HOLD_MS; a sign-in failure holds nothing, because the next run's
2933
+ * check may find the harness signed in again. It does not move a run whose
2934
+ * Task named its harness, a signed-out run whose Task named its model, nor
2935
+ * one the fallback may not carry.
2852
2936
  */
2853
- async moveHarness(r, said) {
2937
+ async moveHarness(r, said, reason) {
2854
2938
  const to = this.deps.fallbackHarness;
2855
2939
  if (!to || r.harness) return false;
2856
- if (!limitedModel(said)) this.limitedUntil = this.now() + LIMIT_HOLD_MS;
2857
- if (r.harness_named || !this.carrier(r, r.used_permission) || !r.prompt) return false;
2940
+ if (reason === "limit" && !limitedModel(said)) this.limitedUntil = this.now() + LIMIT_HOLD_MS;
2941
+ if (r.harness_named || reason === "signed_out" && r.model_named) return false;
2942
+ if (!this.carrier(r, r.used_permission) || !r.prompt) return false;
2858
2943
  this.recovering.add(r.work_id);
2859
2944
  try {
2860
2945
  const probe = await to.probe().catch(() => null);
@@ -2863,16 +2948,19 @@ ${RESULT_INSTRUCTION}`, images));
2863
2948
  this.recovering.delete(r.work_id);
2864
2949
  }
2865
2950
  const from = this.deps.dialect.name;
2866
- const move = { reason: "limit", at: "run" };
2951
+ const move = { reason, at: "run" };
2867
2952
  r.harness = to.name;
2868
2953
  r.moved = move;
2869
2954
  r.session_id = null;
2870
2955
  r.model = void 0;
2871
- r.switched = movedLine(move, from, to.name);
2956
+ r.switched = switchedLine(move, from, to.name);
2872
2957
  this.save();
2873
- this.log(`fallback work=${r.work_id} harness=${to.name} reason=limit`);
2874
- this.emit(r.work_id, { kind: "progress", summary: movingLine(move, from, to.name) });
2875
- this.spawnRun(r, handoverPrompt(r.prompt, harnessName(from)), false);
2958
+ this.log(`fallback work=${r.work_id} harness=${to.name} reason=${reason}`);
2959
+ this.emit(r.work_id, {
2960
+ kind: "progress",
2961
+ summary: movingLine(reason, harnessName(from), harnessName(to.name))
2962
+ });
2963
+ this.spawnRun(r, handoverPrompt(r.prompt, harnessName(from), reason), false);
2876
2964
  return true;
2877
2965
  }
2878
2966
  /**
@@ -2962,6 +3050,7 @@ export {
2962
3050
  nextProgress,
2963
3051
  isYes,
2964
3052
  HARNESS_LIMIT,
3053
+ HARNESS_SIGNED_OUT,
2965
3054
  ENVIRONMENTS,
2966
3055
  environmentOf,
2967
3056
  runnerEnvironment,
@@ -9,7 +9,7 @@ import {
9
9
  runHarness,
10
10
  runLogDir,
11
11
  runLogPath
12
- } from "./chunk-AIOOLVM7.js";
12
+ } from "./chunk-EOWS3JIY.js";
13
13
  import {
14
14
  sanitizeLabel,
15
15
  stripControl
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-ES5BRAKJ.js";
6
6
  import {
7
7
  VERSION
8
- } from "./chunk-4FXRG3Q3.js";
8
+ } from "./chunk-JQGHB2EJ.js";
9
9
  import {
10
10
  getOrigin,
11
11
  readCredentials,