@cloop/runner 0.3.28 → 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.
@@ -560,6 +560,8 @@ function parseFrames(data) {
560
560
  // src/drivers/t3.ts
561
561
  import { execFile, execFileSync as execFileSync3 } from "child_process";
562
562
  import { randomUUID } from "crypto";
563
+ import { existsSync as existsSync2 } from "fs";
564
+ import { join as join6 } from "path";
563
565
 
564
566
  // ../clo0p-app/contracts/run-result.ts
565
567
  var WIZARD_STEPS_MAX = 6;
@@ -862,11 +864,27 @@ function limitedModel(said) {
862
864
  function refusedModel(said) {
863
865
  return /The '([^']+)' model is not supported/i.exec(said ?? "")?.[1] ?? null;
864
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;
865
868
  var LIMIT_HOLD_MS = 60 * 6e4;
866
- 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") {
867
885
  return `${prompt}
868
886
 
869
- ${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.`;
870
888
  }
871
889
 
872
890
  // src/drivers/usage.ts
@@ -1266,26 +1284,66 @@ function permissionOf(runtimeMode) {
1266
1284
  return runtimeMode === "full-access" ? "full" : "ask";
1267
1285
  }
1268
1286
  var CODEX_PROVIDER = "codex";
1287
+ var CLAUDE_PROVIDER = "claudeAgent";
1269
1288
  var PROVIDER_NAMES = { claudeAgent: "Claude Code", codex: "Codex" };
1270
- function providerName(instanceId) {
1289
+ function providerName(instanceId, cfg) {
1290
+ const displayName = cfg?.providers.find((p) => p.instanceId === instanceId)?.displayName;
1291
+ if (displayName) return displayName;
1271
1292
  return instanceId && PROVIDER_NAMES[instanceId] || instanceId || "The harness";
1272
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
+ }
1273
1332
  var PROVIDER_HARNESS = {
1274
1333
  claudeAgent: "claude-code",
1275
1334
  codex: "codex"
1276
1335
  };
1277
- function providerHarness(instanceId) {
1278
- return instanceId ? { harness: PROVIDER_HARNESS[instanceId] ?? instanceId } : {};
1279
- }
1280
- function codexProvider(cfg) {
1281
- const p = cfg.providers.find((x) => (x.driver ?? x.instanceId) === CODEX_PROVIDER && x.enabled);
1282
- if (!p || p.auth && p.auth.status !== "authenticated") return null;
1283
- const model = p.models?.find((m) => m.isDefault)?.slug ?? p.models?.[0]?.slug;
1284
- 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 };
1285
1341
  }
1286
1342
  function pickProject(projects, repository) {
1287
1343
  if (!repository) {
1288
- const repos = projects.filter((p) => p.repositoryIdentity);
1344
+ const repos = projects.filter(
1345
+ (p) => p.repositoryIdentity || existsSync2(join6(p.workspaceRoot, ".git"))
1346
+ );
1289
1347
  const pool = repos.length > 0 ? repos : projects;
1290
1348
  const only = pool.length === 1 ? pool[0] : void 0;
1291
1349
  if (only) return only;
@@ -1370,6 +1428,8 @@ var T3Driver = class {
1370
1428
  held = /* @__PURE__ */ new Map();
1371
1429
  /** Threads this daemon launched. A restart forgets them, and a forgotten thread is not moved. */
1372
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 = [];
1373
1433
  /** Until then, a launch that names no harness starts on Codex: the Claude account is at its limit. */
1374
1434
  limitedUntil = 0;
1375
1435
  get capabilities() {
@@ -1499,6 +1559,7 @@ var T3Driver = class {
1499
1559
  this.t3.rpc("server.getConfig", {}),
1500
1560
  this.t3.http("/api/orchestration/shell", SHELL_HEADERS)
1501
1561
  ]);
1562
+ this.providers = cfg.providers;
1502
1563
  const project = pickProject(shell.projects ?? [], a.repository);
1503
1564
  const runtimeMode = a.runtime_mode ?? cfg.settings?.defaultRuntimeMode;
1504
1565
  if (!runtimeMode || !RUNTIME_MODES.has(runtimeMode))
@@ -1506,9 +1567,9 @@ var T3Driver = class {
1506
1567
  const permission = permissionOf(runtimeMode);
1507
1568
  const named = Boolean(a.harness || a.model);
1508
1569
  const held = !named && permission === "full" && this.now() < this.limitedUntil;
1509
- const own = cfg.settings?.defaultModelSelection?.instanceId ?? "claudeAgent";
1510
- const codex = held && own !== CODEX_PROVIDER ? codexProvider(cfg) : null;
1511
- 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;
1512
1573
  const harness = a.harness ?? fallback?.instanceId ?? "claudeAgent";
1513
1574
  const provider = cfg.providers.find((p) => p.instanceId === harness && p.enabled);
1514
1575
  if (!provider) throw new BoxToolError("harness_unavailable");
@@ -1517,7 +1578,10 @@ var T3Driver = class {
1517
1578
  const model = a.model ?? (fallback?.instanceId === harness ? fallback.model : void 0) ?? provider.models?.find((m) => m.isDefault)?.slug;
1518
1579
  if (!model) throw new BoxToolError("harness_unavailable");
1519
1580
  const modelSelection = !a.model && fallback?.instanceId === harness ? fallback : { instanceId: harness, model };
1520
- 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
+ );
1521
1585
  const photos2 = await this.photos(a);
1522
1586
  const launched = await this.t3.rpc(
1523
1587
  "orchestration.launchThread",
@@ -1543,16 +1607,21 @@ var T3Driver = class {
1543
1607
  this.launched.set(launched.threadId, {
1544
1608
  named,
1545
1609
  permission,
1546
- ...codex ? {
1610
+ ...move ? {
1547
1611
  movedFrom: "",
1548
- 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
+ )
1549
1618
  } : {}
1550
1619
  });
1551
1620
  return {
1552
1621
  thread_id: launched.threadId,
1553
1622
  resumed: launched.resumed,
1554
1623
  permission,
1555
- ...providerHarness(modelSelection.instanceId),
1624
+ ...providerHarness(modelSelection.instanceId, cfg),
1556
1625
  // A resumed thread kept its first message: these photos did not go in.
1557
1626
  ...launched.resumed ? {} : delivery(a.attachments, photos2.attachments.length)
1558
1627
  };
@@ -1834,13 +1903,11 @@ var T3Driver = class {
1834
1903
  finishing = false;
1835
1904
  return;
1836
1905
  }
1837
- 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) {
1838
1908
  finishing = false;
1839
1909
  if (stopped) return;
1840
- onEvent({
1841
- kind: "progress",
1842
- summary: `${providerName(turn.providerInstanceId)} is at its usage limit, so I moved this to Codex`
1843
- });
1910
+ onEvent({ kind: "progress", summary: moving });
1844
1911
  if (!live) void follow();
1845
1912
  return;
1846
1913
  }
@@ -1853,25 +1920,24 @@ var T3Driver = class {
1853
1920
  if (outcome.kind === "failed") {
1854
1921
  const said = outcome.last_assistant_text?.replace(/\s+/g, " ").trim();
1855
1922
  const limited = outcome.status === "failed" && HARNESS_LIMIT.test(said ?? "");
1856
- const end = limited ? {
1857
- summary: `${opening}${providerName(turn?.providerInstanceId)} said: "${said}"`.slice(
1858
- 0,
1859
- RUN_TEXT_MAX
1860
- ),
1861
- error: "harness_limit"
1862
- } : 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}.` };
1863
1929
  onEvent({
1864
1930
  kind: "failed",
1865
1931
  ...end,
1866
1932
  ...outcome.result ? pr : {},
1867
- ...providerHarness(turn?.providerInstanceId)
1933
+ ...providerHarness(turn?.providerInstanceId, { providers: this.providers })
1868
1934
  });
1869
1935
  } else {
1870
1936
  const lost = outcome.dropped ? droppedLine(outcome.dropped, threadId) : null;
1871
1937
  if (lost) this.log(lost);
1872
1938
  onEvent({
1873
1939
  kind: "settled",
1874
- ...providerHarness(turn?.providerInstanceId),
1940
+ ...providerHarness(turn?.providerInstanceId, { providers: this.providers }),
1875
1941
  ...outcome.result ? { result: outcome.result } : {},
1876
1942
  ...outcome.last_assistant_text ? { summary: `${opening}${outcome.last_assistant_text}`.slice(0, RUN_TEXT_MAX) } : {},
1877
1943
  ...pr
@@ -1962,59 +2028,74 @@ var T3Driver = class {
1962
2028
  }
1963
2029
  /**
1964
2030
  * Once per thread: a run that failed at a Claude usage limit carries on in
1965
- * the same thread on Codex. T3 switches the thread's provider and hands
1966
- * Codex the thread so far; the worktree, with any edits, stays. A limit
1967
- * that names no model holds the account, so launches start on Codex for
1968
- * LIMIT_HOLD_MS. A thread whose Task named its harness or model stays, and
1969
- * so does one without full access, because Codex asks nothing. So does a
1970
- * 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.
1971
2040
  */
1972
- async moveToCodex(threadId, turn, outcome) {
2041
+ async handOver(threadId, turn, outcome, p) {
2042
+ if (outcome.status !== "failed") return null;
1973
2043
  const said = outcome.last_assistant_text ?? "";
1974
- 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;
1975
2046
  const from = turn.providerInstanceId;
1976
- if (from === CODEX_PROVIDER) return false;
1977
- 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
+ }
1978
2051
  const entry = this.launched.get(threadId);
1979
- if (!entry || entry.named || entry.permission !== "full" || entry.movedFrom !== void 0)
1980
- return false;
2052
+ if (!entry || entry.named || entry.movedFrom !== void 0) return null;
1981
2053
  try {
1982
- return await this.dispatchToCodex(threadId, turn, entry);
2054
+ return await this.dispatchHandover(threadId, turn, entry, reason);
1983
2055
  } catch (err) {
1984
2056
  this.log(
1985
2057
  `fallback failed thread=${threadId}: ${err instanceof Error ? err.message : String(err)}`
1986
2058
  );
1987
- return false;
2059
+ return null;
1988
2060
  }
1989
2061
  }
1990
- async dispatchToCodex(threadId, turn, entry) {
1991
- const codex = codexProvider(await this.t3.rpc("server.getConfig", {}));
1992
- if (!codex) {
1993
- this.log(`limit thread=${threadId}: Codex is not on or not signed in; the run fails`);
1994
- 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;
1995
2074
  }
1996
- const name = providerName(turn.providerInstanceId);
1997
2075
  const id = randomUUID();
1998
2076
  await this.dispatch({
1999
2077
  type: "message.dispatch",
2000
2078
  commandId: id,
2001
2079
  threadId,
2002
2080
  messageId: id,
2003
- 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(
2004
2082
  `
2005
2083
 
2006
2084
  ${RESULT_INSTRUCTION}`
2007
2085
  ),
2008
2086
  attachments: [],
2009
- modelSelection: codex,
2087
+ modelSelection: to,
2010
2088
  dispatchMode: { type: "start_immediately" },
2011
2089
  createdBy: "user",
2012
2090
  creationSource: "mcp"
2013
2091
  });
2092
+ const toName = providerName(to.instanceId, cfg);
2014
2093
  entry.movedFrom = turn.id;
2015
- entry.switched = `${name} was at its usage limit, so Codex did this run.`;
2016
- this.log(`fallback thread=${threadId} provider=${codex.instanceId} model=${codex.model}`);
2017
- 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);
2018
2099
  }
2019
2100
  now() {
2020
2101
  return this.deps.now?.() ?? Date.now();
@@ -2096,7 +2177,7 @@ ${RESULT_INSTRUCTION}`
2096
2177
  import { execFile as execFile2, execFileSync as execFileSync4, spawn } from "child_process";
2097
2178
  import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync3, writeFileSync as writeFileSync2 } from "fs";
2098
2179
  import { hostname } from "os";
2099
- import { basename, dirname as dirname3, join as join6 } from "path";
2180
+ import { basename, dirname as dirname3, join as join7 } from "path";
2100
2181
  import { createInterface } from "readline";
2101
2182
 
2102
2183
  // src/drivers/harness-check.ts
@@ -2158,13 +2239,7 @@ function runHarness(run2, own) {
2158
2239
  const bin = harness === driver && own?.bin ? own.bin : harness === "codex" ? "codex" : "claude";
2159
2240
  return { harness, bin };
2160
2241
  }
2161
- var MOVE_STATE = {
2162
- limit: "at its usage limit",
2163
- signed_out: "signed out here",
2164
- missing: "not installed here"
2165
- };
2166
- var movedLine = (move, from, to) => `${harnessName(from)} ${move.at === "run" ? "was" : "is"} ${MOVE_STATE[move.reason]}, so ${harnessName(to)} did this run.`;
2167
- 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");
2168
2243
  function failedEnd(harness, run2) {
2169
2244
  const said = run2.result?.text?.trim() || run2.lastText;
2170
2245
  const limited = HARNESS_LIMIT.test(run2.result?.text ?? "");
@@ -2182,7 +2257,7 @@ function failedEnd(harness, run2) {
2182
2257
  return { summary: `${lead}${quoted}"`, ...error };
2183
2258
  }
2184
2259
  function localRunsFilePath(env) {
2185
- return runnerPath(env, process.env.CLOOP_LOCAL_RUNS_FILE, (dir) => join6(dir, "local-runs.json"));
2260
+ return runnerPath(env, process.env.CLOOP_LOCAL_RUNS_FILE, (dir) => join7(dir, "local-runs.json"));
2186
2261
  }
2187
2262
  function pickRepo(repos, repository) {
2188
2263
  if (!repository) {
@@ -2409,7 +2484,8 @@ ${photos2.line}` : a.prompt,
2409
2484
  ...a.model && !moved ? { model: a.model } : {},
2410
2485
  ...a.runtime_mode ? { runtime_mode: a.runtime_mode } : {},
2411
2486
  ...a.harness ? { harness_named: true } : {},
2412
- ...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) } : {},
2413
2489
  pid: null,
2414
2490
  started_at: new Date(this.now()).toISOString(),
2415
2491
  head_at_launch: head
@@ -2571,7 +2647,8 @@ ${a.text}` : a.text;
2571
2647
  /**
2572
2648
  * A Task that names its harness stays on it. Otherwise a run starts on the
2573
2649
  * fallback while the runner's own harness is held at its limit, or when the
2574
- * 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.
2575
2652
  */
2576
2653
  async route(a) {
2577
2654
  const own = this.deps.dialect;
@@ -2582,7 +2659,7 @@ ${a.text}` : a.text;
2582
2659
  return { dialect: to, moved: { reason: "limit", at: "launch" } };
2583
2660
  const harness = await own.probe();
2584
2661
  if (harness?.signedIn) return { dialect: own };
2585
- if (to && await ready())
2662
+ if (to && !a.model && await ready())
2586
2663
  return {
2587
2664
  dialect: to,
2588
2665
  moved: { reason: harness ? "signed_out" : "missing", at: "launch" }
@@ -2600,7 +2677,7 @@ ${a.text}` : a.text;
2600
2677
  const { images, missed } = await fetchImages(a.attachments, { log });
2601
2678
  const paths = await saveImages(
2602
2679
  images,
2603
- join6(dirname3(this.file), "attachments", a.work_id)
2680
+ join7(dirname3(this.file), "attachments", a.work_id)
2604
2681
  ).catch((err) => {
2605
2682
  log(`attachments_unsaved reason=${err.message.slice(0, 120)}`);
2606
2683
  return [];
@@ -2713,6 +2790,9 @@ ${RESULT_INSTRUCTION}`, images));
2713
2790
  if (wasAsked) this.askNext(r, live);
2714
2791
  return;
2715
2792
  }
2793
+ case "signed_out":
2794
+ live.signedOut = true;
2795
+ return;
2716
2796
  case "result":
2717
2797
  live.outstanding--;
2718
2798
  live.result = { ok: item.ok, ...item.text ? { text: item.text } : {} };
@@ -2767,9 +2847,14 @@ ${RESULT_INSTRUCTION}`, images));
2767
2847
  if (end.error) this.log(`limit work=${r.work_id} error=${end.error}`);
2768
2848
  if (end.error === "harness_limit") {
2769
2849
  if (this.fallBack(r, live.result?.text)) return;
2770
- if (await this.moveHarness(r, live.result?.text)) return;
2850
+ if (await this.moveHarness(r, live.result?.text, "limit")) return;
2771
2851
  }
2772
- 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 });
2773
2858
  }
2774
2859
  /**
2775
2860
  * Once per run: a run stopped by its model's usage limit resumes its own
@@ -2821,7 +2906,7 @@ ${RESULT_INSTRUCTION}`, images));
2821
2906
  if (!next)
2822
2907
  this.log(`model work=${r.work_id} refused=${refused} next=none catalog=${listed.length}`);
2823
2908
  if (!next || this.stopping || r.end) return false;
2824
- 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;
2825
2910
  r.refused = tried;
2826
2911
  r.model = next;
2827
2912
  r.session_id = null;
@@ -2833,24 +2918,28 @@ ${RESULT_INSTRUCTION}`, images));
2833
2918
  this.log(`model work=${r.work_id} refused=${refused} next=${next}`);
2834
2919
  this.spawnRun(
2835
2920
  r,
2836
- 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,
2837
2922
  false
2838
2923
  );
2839
2924
  return true;
2840
2925
  }
2841
2926
  /**
2842
- * Once per run: a run its own harness cannot carry on starts again on the
2843
- * fallback harness, in the same checkout, so the edits so far carry over.
2844
- * The session does not: the prompt goes again, with a note to read the
2845
- * checkout first. A limit that names no model holds the account, so new
2846
- * runs start on the fallback for LIMIT_HOLD_MS. It does not move a run
2847
- * 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.
2848
2936
  */
2849
- async moveHarness(r, said) {
2937
+ async moveHarness(r, said, reason) {
2850
2938
  const to = this.deps.fallbackHarness;
2851
2939
  if (!to || r.harness) return false;
2852
- if (!limitedModel(said)) this.limitedUntil = this.now() + LIMIT_HOLD_MS;
2853
- 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;
2854
2943
  this.recovering.add(r.work_id);
2855
2944
  try {
2856
2945
  const probe = await to.probe().catch(() => null);
@@ -2859,16 +2948,19 @@ ${RESULT_INSTRUCTION}`, images));
2859
2948
  this.recovering.delete(r.work_id);
2860
2949
  }
2861
2950
  const from = this.deps.dialect.name;
2862
- const move = { reason: "limit", at: "run" };
2951
+ const move = { reason, at: "run" };
2863
2952
  r.harness = to.name;
2864
2953
  r.moved = move;
2865
2954
  r.session_id = null;
2866
2955
  r.model = void 0;
2867
- r.switched = movedLine(move, from, to.name);
2956
+ r.switched = switchedLine(move, from, to.name);
2868
2957
  this.save();
2869
- this.log(`fallback work=${r.work_id} harness=${to.name} reason=limit`);
2870
- this.emit(r.work_id, { kind: "progress", summary: movingLine(move, from, to.name) });
2871
- 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);
2872
2964
  return true;
2873
2965
  }
2874
2966
  /**
@@ -2958,6 +3050,7 @@ export {
2958
3050
  nextProgress,
2959
3051
  isYes,
2960
3052
  HARNESS_LIMIT,
3053
+ HARNESS_SIGNED_OUT,
2961
3054
  ENVIRONMENTS,
2962
3055
  environmentOf,
2963
3056
  runnerEnvironment,
@@ -9,7 +9,7 @@ import {
9
9
  runHarness,
10
10
  runLogDir,
11
11
  runLogPath
12
- } from "./chunk-3S2ECJTO.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-3I6NDELL.js";
8
+ } from "./chunk-JQGHB2EJ.js";
9
9
  import {
10
10
  getOrigin,
11
11
  readCredentials,