@cloop/runner 0.3.29 → 0.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/{box-6TJMXQXM.js → box-RFAHCXZS.js} +239 -69
- package/dist/chunk-52CUSFDQ.js +401 -0
- package/dist/{chunk-P56EL4D4.js → chunk-7AHYPGSU.js} +2 -2
- package/dist/{chunk-65KJPIZC.js → chunk-FKYVJUIR.js} +1 -1
- package/dist/{chunk-4FXRG3Q3.js → chunk-GL77IQQE.js} +1 -1
- package/dist/{chunk-SVHQXVCH.js → chunk-MEAVT5SJ.js} +986 -205
- package/dist/{chunk-AIOOLVM7.js → chunk-R73PVAM2.js} +182 -88
- package/dist/{chunk-NTXQLEMQ.js → chunk-SBYSVZ7J.js} +94 -2
- package/dist/{chunk-PSA5EC65.js → chunk-UERK5AHI.js} +6 -6
- package/dist/{chunk-TWDKR7XV.js → chunk-WYU74GLG.js} +5 -5
- package/dist/{chunk-GURADB5L.js → chunk-YLVOEZWH.js} +1 -1
- package/dist/{connect-HVUNZ6A2.js → connect-WRTLQW5H.js} +10 -9
- package/dist/{disconnect-NXVDABS5.js → disconnect-I44BWWFB.js} +8 -9
- package/dist/existing-runner-SP6SNFH4.js +20 -0
- package/dist/{hook-activity-GAJ5NABA.js → hook-activity-3T6IMEM6.js} +2 -3
- package/dist/{hook-session-start-5JYNMGX4.js → hook-session-start-DLP77G4H.js} +5 -7
- package/dist/index.js +20 -17
- package/dist/{login-PH2RZNOE.js → login-LH2KF7N2.js} +3 -3
- package/dist/{mcp-server-U2H4U4BZ.js → mcp-server-SGIWNLLL.js} +9 -11
- package/dist/{runner-YTGTJPPR.js → runner-SXUQH5IU.js} +4 -4
- package/dist/{runs-D7XT2PYS.js → runs-3YZO57MX.js} +2 -2
- package/dist/{statusline-U4K2IQIT.js → statusline-UHZTCNCB.js} +1 -1
- package/dist/{takeover-M2SDWTVK.js → takeover-M4QHMXTZ.js} +5 -6
- package/dist/{use-7OUFEREN.js → use-YB75NHTE.js} +8 -9
- package/package.json +1 -1
- package/dist/chunk-ES5BRAKJ.js +0 -88
- package/dist/chunk-KYGYU5G2.js +0 -220
- package/dist/existing-runner-7E6RUUJH.js +0 -21
package/README.md
CHANGED
|
@@ -72,3 +72,10 @@ npm install
|
|
|
72
72
|
npm run build
|
|
73
73
|
npm test
|
|
74
74
|
```
|
|
75
|
+
|
|
76
|
+
## OAuth fallback
|
|
77
|
+
|
|
78
|
+
Claude Code and Codex can carry each other's runs after a provider login failure.
|
|
79
|
+
This works for direct CLI runners and T3 runners.
|
|
80
|
+
See [the runbook](../docs/runbooks/runner-oauth-fallback.md) for restrictions and release steps.
|
|
81
|
+
After the release merges, run `bash tools/ops/runner-oauth-fallback-wizard.sh` from the repository root to approve and install it.
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
serveTakeovers
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-UERK5AHI.js";
|
|
5
|
+
import "./chunk-FKYVJUIR.js";
|
|
6
6
|
import {
|
|
7
|
+
CAPTURE_TICK_MS,
|
|
7
8
|
DEFAULT_FALLBACK_MODEL,
|
|
9
|
+
HOST_ID_MAX,
|
|
8
10
|
SUBSCRIPTIONS,
|
|
11
|
+
TITLE_MAX,
|
|
12
|
+
ThreadCapture,
|
|
9
13
|
answerCall,
|
|
10
14
|
awaitDaemon,
|
|
11
|
-
|
|
15
|
+
captureCursorPath,
|
|
12
16
|
classifyError,
|
|
13
17
|
claudeDialect,
|
|
18
|
+
claudeHome,
|
|
14
19
|
cmdWord,
|
|
15
20
|
codexDialect,
|
|
21
|
+
codexHome,
|
|
16
22
|
connectCommand,
|
|
17
23
|
findNpx,
|
|
18
24
|
installedService,
|
|
@@ -27,19 +33,20 @@ import {
|
|
|
27
33
|
programFor,
|
|
28
34
|
psQuote,
|
|
29
35
|
runSteps,
|
|
30
|
-
runnerLog,
|
|
31
36
|
serviceEnv,
|
|
32
37
|
stopService,
|
|
33
38
|
systemServices,
|
|
34
39
|
unitFor,
|
|
35
40
|
which
|
|
36
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-MEAVT5SJ.js";
|
|
37
42
|
import {
|
|
38
43
|
MeshSocket,
|
|
39
44
|
WAKE_TICK_MS,
|
|
45
|
+
buildDiag,
|
|
40
46
|
defaultSocketFactory,
|
|
47
|
+
runnerLog,
|
|
41
48
|
wakeWatch
|
|
42
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-52CUSFDQ.js";
|
|
43
50
|
import {
|
|
44
51
|
BoxWatch,
|
|
45
52
|
hostedThreadsFilePath,
|
|
@@ -48,7 +55,7 @@ import {
|
|
|
48
55
|
runnerStatePath,
|
|
49
56
|
threadsFilePath,
|
|
50
57
|
writeRunnerState
|
|
51
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-YLVOEZWH.js";
|
|
52
59
|
import {
|
|
53
60
|
BackgroundReading,
|
|
54
61
|
BoxToolError,
|
|
@@ -92,21 +99,20 @@ import {
|
|
|
92
99
|
utcWindow,
|
|
93
100
|
windowsPowerShellEnv,
|
|
94
101
|
writeBoxConfig
|
|
95
|
-
} from "./chunk-
|
|
96
|
-
import {
|
|
97
|
-
getMachine
|
|
98
|
-
} from "./chunk-NTXQLEMQ.js";
|
|
102
|
+
} from "./chunk-R73PVAM2.js";
|
|
99
103
|
import "./chunk-VK6GV757.js";
|
|
100
104
|
import {
|
|
101
105
|
olderThan
|
|
102
106
|
} from "./chunk-365HFCQQ.js";
|
|
103
107
|
import "./chunk-PKIEWBR7.js";
|
|
104
|
-
import "./chunk-
|
|
105
|
-
import "./chunk-
|
|
106
|
-
import
|
|
108
|
+
import "./chunk-7AHYPGSU.js";
|
|
109
|
+
import "./chunk-WYU74GLG.js";
|
|
110
|
+
import {
|
|
111
|
+
getMachine
|
|
112
|
+
} from "./chunk-SBYSVZ7J.js";
|
|
107
113
|
import {
|
|
108
114
|
VERSION
|
|
109
|
-
} from "./chunk-
|
|
115
|
+
} from "./chunk-GL77IQQE.js";
|
|
110
116
|
import {
|
|
111
117
|
getMeshUrl,
|
|
112
118
|
getOrigin,
|
|
@@ -798,17 +804,17 @@ var CloudroomDriver = class {
|
|
|
798
804
|
async reports(harnesses) {
|
|
799
805
|
const info = harnesses.find((h) => h.id === this.harness);
|
|
800
806
|
if (!info) return [];
|
|
801
|
-
const
|
|
802
|
-
const account =
|
|
807
|
+
const facts2 = harnessFacts(this.harness);
|
|
808
|
+
const account = facts2.account ? await this.core.account(facts2.account.kind) : null;
|
|
803
809
|
const signedIn = account ? SIGNED_IN.has(account.state) : true;
|
|
804
810
|
return [
|
|
805
811
|
{
|
|
806
812
|
id: this.harness,
|
|
807
|
-
name:
|
|
813
|
+
name: facts2.name,
|
|
808
814
|
version: null,
|
|
809
815
|
ready: account ? account.state === "connected" : true,
|
|
810
816
|
signedIn,
|
|
811
|
-
account: account && signedIn ?
|
|
817
|
+
account: account && signedIn ? facts2.account?.label(account.plan) ?? null : null,
|
|
812
818
|
defaultModel: info.model,
|
|
813
819
|
experimental: true
|
|
814
820
|
}
|
|
@@ -1007,10 +1013,10 @@ var CloudroomDriver = class {
|
|
|
1007
1013
|
const inUse = (await this.core.sessions()).some(
|
|
1008
1014
|
(x) => x.workspace === s.workspace && busy(x)
|
|
1009
1015
|
);
|
|
1010
|
-
const
|
|
1011
|
-
const fate = worktreeFate(
|
|
1016
|
+
const facts2 = await this.repos.facts(tree.clone, tree.branch, path, inUse);
|
|
1017
|
+
const fate = worktreeFate(facts2);
|
|
1012
1018
|
this.log(`worktree ${fate} thread=${id} path=${path}`);
|
|
1013
|
-
if (fate !== "remove") return keptLine(fate, path,
|
|
1019
|
+
if (fate !== "remove") return keptLine(fate, path, facts2.head);
|
|
1014
1020
|
try {
|
|
1015
1021
|
await this.repos.remove(tree.clone, tree.branch, path);
|
|
1016
1022
|
return null;
|
|
@@ -1018,7 +1024,7 @@ var CloudroomDriver = class {
|
|
|
1018
1024
|
this.log(
|
|
1019
1025
|
`worktree not removed thread=${id}: ${err instanceof Error ? err.message : String(err)}`
|
|
1020
1026
|
);
|
|
1021
|
-
return `The work is kept in ${path} on branch ${
|
|
1027
|
+
return `The work is kept in ${path} on branch ${facts2.head}.`;
|
|
1022
1028
|
}
|
|
1023
1029
|
});
|
|
1024
1030
|
if (!line) return end;
|
|
@@ -1295,7 +1301,7 @@ ${line}` : line;
|
|
|
1295
1301
|
import { spawn as spawn2 } from "child_process";
|
|
1296
1302
|
import { createReadStream } from "fs";
|
|
1297
1303
|
import { readdir, realpath, stat } from "fs/promises";
|
|
1298
|
-
import {
|
|
1304
|
+
import { hostname, tmpdir } from "os";
|
|
1299
1305
|
import { join as join3 } from "path";
|
|
1300
1306
|
import { createInterface } from "readline";
|
|
1301
1307
|
var PROBE_TIMEOUT_MS = 1e4;
|
|
@@ -1557,16 +1563,16 @@ async function scanTokenUsage(opts = {}) {
|
|
|
1557
1563
|
const window = utcWindow(opts.now ?? Date.now(), TOKEN_DAYS);
|
|
1558
1564
|
const sinceMs = Date.parse(`${window.sinceDay}T00:00:00Z`);
|
|
1559
1565
|
const days = /* @__PURE__ */ new Map();
|
|
1560
|
-
const
|
|
1561
|
-
const
|
|
1566
|
+
const claudeHome2 = opts.claudeHome ?? claudeHome();
|
|
1567
|
+
const codexHome2 = opts.codexHome ?? codexHome();
|
|
1562
1568
|
const claude = claudeReader(window, days);
|
|
1563
1569
|
const sources = [
|
|
1564
1570
|
await scanSource(
|
|
1565
1571
|
{
|
|
1566
1572
|
provider: "claude",
|
|
1567
|
-
home:
|
|
1573
|
+
home: claudeHome2,
|
|
1568
1574
|
// projects/<project>/<session>.jsonl and projects/<project>/<session>/subagents/agent-*.jsonl
|
|
1569
|
-
roots: [{ dir: join3(
|
|
1575
|
+
roots: [{ dir: join3(claudeHome2, "projects"), depth: 4 }],
|
|
1570
1576
|
match: (name) => name.endsWith(".jsonl"),
|
|
1571
1577
|
reader: () => claude.read
|
|
1572
1578
|
},
|
|
@@ -1575,10 +1581,10 @@ async function scanTokenUsage(opts = {}) {
|
|
|
1575
1581
|
await scanSource(
|
|
1576
1582
|
{
|
|
1577
1583
|
provider: "codex",
|
|
1578
|
-
home:
|
|
1584
|
+
home: codexHome2,
|
|
1579
1585
|
roots: [
|
|
1580
|
-
{ dir: join3(
|
|
1581
|
-
{ dir: join3(
|
|
1586
|
+
{ dir: join3(codexHome2, "sessions"), depth: 4 },
|
|
1587
|
+
{ dir: join3(codexHome2, "archived_sessions"), depth: 1 }
|
|
1582
1588
|
],
|
|
1583
1589
|
match: (name) => name.startsWith("rollout-") && name.endsWith(".jsonl"),
|
|
1584
1590
|
reader: codexReader(window, days)
|
|
@@ -1647,15 +1653,41 @@ var LocalUsage = class {
|
|
|
1647
1653
|
}
|
|
1648
1654
|
};
|
|
1649
1655
|
|
|
1656
|
+
// src/last-known.ts
|
|
1657
|
+
function lastKnown(read, initial, { ms, what, onFail }) {
|
|
1658
|
+
let last = initial;
|
|
1659
|
+
let out2 = null;
|
|
1660
|
+
return async () => {
|
|
1661
|
+
out2 ??= read().then((value) => {
|
|
1662
|
+
last = value;
|
|
1663
|
+
return value;
|
|
1664
|
+
}).finally(() => {
|
|
1665
|
+
out2 = null;
|
|
1666
|
+
});
|
|
1667
|
+
let timer;
|
|
1668
|
+
const late = new Promise((_, reject) => {
|
|
1669
|
+
timer = setTimeout(() => reject(new Error(`${what} timed out after ${ms / 1e3}s`)), ms);
|
|
1670
|
+
});
|
|
1671
|
+
try {
|
|
1672
|
+
await Promise.race([out2, late]);
|
|
1673
|
+
} catch (err) {
|
|
1674
|
+
onFail(err);
|
|
1675
|
+
} finally {
|
|
1676
|
+
clearTimeout(timer);
|
|
1677
|
+
}
|
|
1678
|
+
return last;
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1650
1682
|
// src/outside-sessions.ts
|
|
1651
1683
|
import { createReadStream as createReadStream2 } from "fs";
|
|
1652
1684
|
import { readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
1653
|
-
import { homedir
|
|
1685
|
+
import { homedir } from "os";
|
|
1654
1686
|
import { join as join4 } from "path";
|
|
1655
1687
|
import { createInterface as createInterface2 } from "readline";
|
|
1656
1688
|
var seen = /* @__PURE__ */ new Map();
|
|
1657
1689
|
var UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
|
|
1658
|
-
async function listOutsideSessions(root = join4(
|
|
1690
|
+
async function listOutsideSessions(root = join4(homedir(), ".claude", "projects"), own = /* @__PURE__ */ new Set(), now = Date.now()) {
|
|
1659
1691
|
const files = [];
|
|
1660
1692
|
for (const project of await readdir2(root, { withFileTypes: true }).catch(() => [])) {
|
|
1661
1693
|
if (!project.isDirectory()) continue;
|
|
@@ -1780,7 +1812,7 @@ import {
|
|
|
1780
1812
|
rmSync as rmSync2,
|
|
1781
1813
|
symlinkSync
|
|
1782
1814
|
} from "fs";
|
|
1783
|
-
import { homedir as
|
|
1815
|
+
import { homedir as homedir2, tmpdir as tmpdir2 } from "os";
|
|
1784
1816
|
import { join as join5 } from "path";
|
|
1785
1817
|
var SKILL_DIRS = [".agents/skills", ".claude/skills", ".codex/skills"];
|
|
1786
1818
|
var GUIDE_FILES = [".agents/AGENTS.md", ".claude/CLAUDE.md", ".codex/AGENTS.md"];
|
|
@@ -1824,7 +1856,7 @@ function stage(setup) {
|
|
|
1824
1856
|
if (setup.guide) copyFileSync(setup.guide, join5(dir, ".agents", "owner-guide.md"));
|
|
1825
1857
|
return dir;
|
|
1826
1858
|
}
|
|
1827
|
-
async function packSkills(home =
|
|
1859
|
+
async function packSkills(home = homedir2(), capBytes = SKILLS_CAP_BYTES, tarBin = "tar") {
|
|
1828
1860
|
const setup = findSetup(home);
|
|
1829
1861
|
if (setup.skills.length === 0 && !setup.guide) return { ok: false, reason: "no_skills" };
|
|
1830
1862
|
let dir;
|
|
@@ -1981,10 +2013,10 @@ function readText(path) {
|
|
|
1981
2013
|
return "";
|
|
1982
2014
|
}
|
|
1983
2015
|
}
|
|
1984
|
-
function readRemoteMcp(home =
|
|
2016
|
+
function readRemoteMcp(home = homedir2(), codexHome2 = process.env.CODEX_HOME || join5(home, ".codex")) {
|
|
1985
2017
|
return remoteMcp([
|
|
1986
2018
|
...claudeRemoteMcp(readText(join5(home, ".claude.json"))),
|
|
1987
|
-
...codexRemoteMcp(readText(join5(
|
|
2019
|
+
...codexRemoteMcp(readText(join5(codexHome2, "config.toml")))
|
|
1988
2020
|
]);
|
|
1989
2021
|
}
|
|
1990
2022
|
async function sendSkills(tar, deps) {
|
|
@@ -2059,6 +2091,104 @@ var SetupShare = class {
|
|
|
2059
2091
|
}
|
|
2060
2092
|
};
|
|
2061
2093
|
|
|
2094
|
+
// src/threads/t3-threads.ts
|
|
2095
|
+
var T3_REFRESH_MS = 2 * 6e4;
|
|
2096
|
+
var LOOKBACK_MS = 48 * 60 * 6e4;
|
|
2097
|
+
var PROJECTIONS_PER_READ = 25;
|
|
2098
|
+
var SHELL_HEADERS = { "x-t3-orchestration-protocol": "2" };
|
|
2099
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2100
|
+
function isSettled(t) {
|
|
2101
|
+
if (t.archivedAt || t.deletedAt) return true;
|
|
2102
|
+
if (t.settledOverride === "settled") return true;
|
|
2103
|
+
if (t.settledOverride === "unsettled") return false;
|
|
2104
|
+
return typeof t.settledAt === "string";
|
|
2105
|
+
}
|
|
2106
|
+
function facts(t) {
|
|
2107
|
+
const parent = t.lineage?.parentThreadId;
|
|
2108
|
+
const title = typeof t.title === "string" ? t.title.trim() : "";
|
|
2109
|
+
return {
|
|
2110
|
+
host: "t3",
|
|
2111
|
+
threadId: t.id.slice(0, HOST_ID_MAX),
|
|
2112
|
+
...t.createdBy === "agent" && typeof parent === "string" && parent ? { parentId: parent.slice(0, HOST_ID_MAX) } : {},
|
|
2113
|
+
...title ? { title: title.slice(0, TITLE_MAX) } : {},
|
|
2114
|
+
delegated: t.createdBy === "agent",
|
|
2115
|
+
settled: isSettled(t)
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
function harnessKey(t) {
|
|
2119
|
+
const history = Array.isArray(t.providerInstanceHistory) ? t.providerInstanceHistory.length : 0;
|
|
2120
|
+
return `${String(t.providerInstanceId)}#${history}`;
|
|
2121
|
+
}
|
|
2122
|
+
var T3Threads = class {
|
|
2123
|
+
constructor(client, log3, now = Date.now) {
|
|
2124
|
+
this.client = client;
|
|
2125
|
+
this.log = log3;
|
|
2126
|
+
this.now = now;
|
|
2127
|
+
}
|
|
2128
|
+
client;
|
|
2129
|
+
log;
|
|
2130
|
+
now;
|
|
2131
|
+
/** Harness session id to T3 thread id. A session's thread never changes. */
|
|
2132
|
+
threadOf = /* @__PURE__ */ new Map();
|
|
2133
|
+
/** T3 thread id to the harness key its sessions were read at. */
|
|
2134
|
+
resolvedAt = /* @__PURE__ */ new Map();
|
|
2135
|
+
facts = /* @__PURE__ */ new Map();
|
|
2136
|
+
readAt = Number.NEGATIVE_INFINITY;
|
|
2137
|
+
/** Session id to what T3 says about its thread. */
|
|
2138
|
+
async bySession() {
|
|
2139
|
+
await this.refresh();
|
|
2140
|
+
const out2 = /* @__PURE__ */ new Map();
|
|
2141
|
+
for (const [session, threadId] of this.threadOf) {
|
|
2142
|
+
out2.set(
|
|
2143
|
+
session,
|
|
2144
|
+
this.facts.get(threadId) ?? { host: "t3", threadId, delegated: false, settled: true }
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
return out2;
|
|
2148
|
+
}
|
|
2149
|
+
async refresh() {
|
|
2150
|
+
const now = this.now();
|
|
2151
|
+
const t3 = this.client();
|
|
2152
|
+
if (!t3 || now - this.readAt < T3_REFRESH_MS) return;
|
|
2153
|
+
this.readAt = now;
|
|
2154
|
+
try {
|
|
2155
|
+
const shell = await t3.http(
|
|
2156
|
+
"/api/orchestration/shell",
|
|
2157
|
+
SHELL_HEADERS
|
|
2158
|
+
);
|
|
2159
|
+
const threads = (shell.threads ?? []).filter(
|
|
2160
|
+
(t) => typeof t.id === "string" && t.creationSource !== "provider"
|
|
2161
|
+
);
|
|
2162
|
+
const known = /* @__PURE__ */ new Map();
|
|
2163
|
+
for (const t of threads) known.set(t.id, facts(t));
|
|
2164
|
+
const knownThreads = new Set(this.threadOf.values());
|
|
2165
|
+
for (const id of knownThreads) {
|
|
2166
|
+
const prior = this.facts.get(id);
|
|
2167
|
+
if (!known.has(id) && prior) known.set(id, { ...prior, settled: true });
|
|
2168
|
+
}
|
|
2169
|
+
this.facts = known;
|
|
2170
|
+
const ask = threads.filter(
|
|
2171
|
+
(t) => this.resolvedAt.get(t.id) !== harnessKey(t) && typeof t.updatedAt === "string" && now - Date.parse(t.updatedAt) <= LOOKBACK_MS
|
|
2172
|
+
).sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt))).slice(0, PROJECTIONS_PER_READ);
|
|
2173
|
+
for (const thread of ask) {
|
|
2174
|
+
const projection = await t3.rpc("orchestration.getThreadProjection", {
|
|
2175
|
+
threadId: thread.id
|
|
2176
|
+
});
|
|
2177
|
+
const ids = (projection.providerThreads ?? []).flatMap((p) => {
|
|
2178
|
+
const id = p.nativeThreadRef?.nativeId;
|
|
2179
|
+
return typeof id === "string" && UUID2.test(id) ? [id.toLowerCase()] : [];
|
|
2180
|
+
});
|
|
2181
|
+
if (ids.length === 0) continue;
|
|
2182
|
+
this.resolvedAt.set(thread.id, harnessKey(thread));
|
|
2183
|
+
for (const id of ids) this.threadOf.set(id, thread.id);
|
|
2184
|
+
}
|
|
2185
|
+
} catch (err) {
|
|
2186
|
+
const reason2 = err instanceof Error ? err.message : String(err);
|
|
2187
|
+
this.log(`[runner-threads:t3] t3_read_failed reason=${reason2.slice(0, 120)}`);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
|
|
2062
2192
|
// src/update.ts
|
|
2063
2193
|
import { execFile as execFile2, spawn as spawn4 } from "child_process";
|
|
2064
2194
|
import {
|
|
@@ -2070,7 +2200,7 @@ import {
|
|
|
2070
2200
|
rmSync as rmSync3,
|
|
2071
2201
|
writeFileSync
|
|
2072
2202
|
} from "fs";
|
|
2073
|
-
import { homedir as
|
|
2203
|
+
import { homedir as homedir3 } from "os";
|
|
2074
2204
|
import { dirname, join as join6 } from "path";
|
|
2075
2205
|
var REGISTRY_LATEST = "https://registry.npmjs.org/@cloop/runner/latest";
|
|
2076
2206
|
var FIRST_CHECK_MS = 10 * 6e4;
|
|
@@ -2176,7 +2306,7 @@ function servicePath(kind, platform) {
|
|
|
2176
2306
|
platform,
|
|
2177
2307
|
kind,
|
|
2178
2308
|
environment: runnerEnvironment(),
|
|
2179
|
-
home:
|
|
2309
|
+
home: homedir3(),
|
|
2180
2310
|
uid: process.getuid?.() ?? 0,
|
|
2181
2311
|
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
2182
2312
|
}).path;
|
|
@@ -2318,7 +2448,7 @@ async function adopt(from, kind, { services: given, script = process.argv[1] ??
|
|
|
2318
2448
|
const where = {
|
|
2319
2449
|
platform: services.platform,
|
|
2320
2450
|
kind,
|
|
2321
|
-
home:
|
|
2451
|
+
home: homedir3(),
|
|
2322
2452
|
uid: process.getuid?.() ?? 0,
|
|
2323
2453
|
...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
|
|
2324
2454
|
};
|
|
@@ -2366,6 +2496,7 @@ async function adopt(from, kind, { services: given, script = process.argv[1] ??
|
|
|
2366
2496
|
|
|
2367
2497
|
// src/commands/box.ts
|
|
2368
2498
|
var BEAT_MS = 6e4;
|
|
2499
|
+
var DRIVER_READ_MS = 2e4;
|
|
2369
2500
|
var RESEND_MS = 5 * 6e4;
|
|
2370
2501
|
var RECENT_CALLS = 20;
|
|
2371
2502
|
var REPAIR_BEFORE_MS = 2 * 24 * 36e5;
|
|
@@ -2587,8 +2718,8 @@ async function run2() {
|
|
|
2587
2718
|
resendResults();
|
|
2588
2719
|
if (wake.unsent && wake.last) wake.unsent = !socket.send({ type: "wake", ...wake.last });
|
|
2589
2720
|
},
|
|
2590
|
-
onClose: (code) => log2(
|
|
2591
|
-
code === REVOKED_CLOSE ? "disconnected by Cloop (revoked), checking" : "disconnected, reconnecting"
|
|
2721
|
+
onClose: (code, drop) => log2(
|
|
2722
|
+
drop ? `${drop.reason.replace("_", " ")} ${Math.round(drop.ms / 1e3)}s, reconnecting` : code === REVOKED_CLOSE ? "disconnected by Cloop (revoked), checking" : "disconnected, reconnecting"
|
|
2592
2723
|
),
|
|
2593
2724
|
onRefused: () => void (async () => {
|
|
2594
2725
|
const fresh = await awaitNewDeviceToken(token ?? "", () => readRunnerConfig()?.deviceToken);
|
|
@@ -2644,45 +2775,67 @@ async function run2() {
|
|
|
2644
2775
|
process.platform,
|
|
2645
2776
|
(error, ver) => socket.send(runnerLog("update_failed", { error, ver }))
|
|
2646
2777
|
);
|
|
2647
|
-
const
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
let running = 0;
|
|
2651
|
-
let outsideThreads = [];
|
|
2652
|
-
const shown = showsOtherThreads(readRunnerConfig());
|
|
2653
|
-
try {
|
|
2778
|
+
const readDriver = lastKnown(
|
|
2779
|
+
async () => {
|
|
2780
|
+
const shown = showsOtherThreads(readRunnerConfig());
|
|
2654
2781
|
const own = shown && driver.name === "claude-code";
|
|
2655
2782
|
const listed = await driver.listThreads({
|
|
2656
2783
|
scope: own ? "all" : "unsettled",
|
|
2657
2784
|
limit: own ? 200 : 1
|
|
2658
2785
|
});
|
|
2659
|
-
|
|
2786
|
+
let outsideThreads = [];
|
|
2660
2787
|
if (shown && driver instanceof T3Driver) outsideThreads = await driver.outsideThreads(20);
|
|
2661
2788
|
if (own)
|
|
2662
2789
|
outsideThreads = await listOutsideSessions(
|
|
2663
2790
|
void 0,
|
|
2664
2791
|
new Set(listed.threads.map((t) => t.id))
|
|
2665
2792
|
);
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2793
|
+
return { shown, running: listed.running, outsideThreads };
|
|
2794
|
+
},
|
|
2795
|
+
{ shown: showsOtherThreads(readRunnerConfig()), running: 0, outsideThreads: [] },
|
|
2796
|
+
{
|
|
2797
|
+
ms: DRIVER_READ_MS,
|
|
2798
|
+
what: `${driver.name} read`,
|
|
2799
|
+
onFail: (err) => {
|
|
2800
|
+
log2(`${driver.name} unreachable: ${err instanceof Error ? err.message : String(err)}`);
|
|
2801
|
+
socket.send(runnerLog("driver_unreachable", { error: classifyError(err, driver.name) }));
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
);
|
|
2805
|
+
const renew = lastKnown(renewT3, void 0, {
|
|
2806
|
+
ms: DRIVER_READ_MS,
|
|
2807
|
+
what: "T3 session renewal",
|
|
2808
|
+
onFail: (err) => {
|
|
2809
|
+
t3.renewalFailed = true;
|
|
2810
|
+
log2(err instanceof Error ? err.message : String(err));
|
|
2811
|
+
}
|
|
2812
|
+
});
|
|
2813
|
+
let beating = false;
|
|
2814
|
+
const beat = async () => {
|
|
2815
|
+
if (beating) return;
|
|
2816
|
+
beating = true;
|
|
2817
|
+
try {
|
|
2818
|
+
await renew();
|
|
2819
|
+
const callsBefore = callsStarted;
|
|
2820
|
+
const { shown, running, outsideThreads } = await readDriver();
|
|
2821
|
+
lastBeatAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2822
|
+
socket.sendPresence(
|
|
2823
|
+
boxPresence({
|
|
2824
|
+
sessionKey,
|
|
2825
|
+
driver: driver.name,
|
|
2826
|
+
capabilities: driver.capabilities,
|
|
2827
|
+
machine,
|
|
2828
|
+
outsideThreads,
|
|
2829
|
+
otherThreads: shown,
|
|
2830
|
+
running,
|
|
2831
|
+
t3: cfg && isT3(cfg) ? t3Presence(cfg, t3.renewalFailed) : null,
|
|
2832
|
+
...hosted ? { hosted: hosted.harness } : {}
|
|
2833
|
+
})
|
|
2834
|
+
);
|
|
2835
|
+
update?.beat({ running, inFlight: inFlight + callsStarted - callsBefore });
|
|
2836
|
+
} finally {
|
|
2837
|
+
beating = false;
|
|
2669
2838
|
}
|
|
2670
|
-
lastBeatAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2671
|
-
socket.ping();
|
|
2672
|
-
socket.sendPresence(
|
|
2673
|
-
boxPresence({
|
|
2674
|
-
sessionKey,
|
|
2675
|
-
driver: driver.name,
|
|
2676
|
-
capabilities: driver.capabilities,
|
|
2677
|
-
machine,
|
|
2678
|
-
outsideThreads,
|
|
2679
|
-
otherThreads: shown,
|
|
2680
|
-
running,
|
|
2681
|
-
t3: cfg && isT3(cfg) ? t3Presence(cfg, t3.renewalFailed) : null,
|
|
2682
|
-
...hosted ? { hosted: hosted.harness } : {}
|
|
2683
|
-
})
|
|
2684
|
-
);
|
|
2685
|
-
update?.beat({ running, inFlight: inFlight + callsStarted - callsBefore });
|
|
2686
2839
|
};
|
|
2687
2840
|
void beat();
|
|
2688
2841
|
setInterval(() => void beat(), BEAT_MS);
|
|
@@ -2695,6 +2848,23 @@ async function run2() {
|
|
|
2695
2848
|
wake.unsent = !socket.send({ type: "wake", ...woke });
|
|
2696
2849
|
void beat();
|
|
2697
2850
|
}, WAKE_TICK_MS).unref();
|
|
2851
|
+
if (!hosted) {
|
|
2852
|
+
const t3Threads = t3.client ? new T3Threads(
|
|
2853
|
+
() => t3.client,
|
|
2854
|
+
(line) => console.error(line)
|
|
2855
|
+
) : null;
|
|
2856
|
+
const capture = new ThreadCapture({
|
|
2857
|
+
cursorFile: captureCursorPath(threadsFile),
|
|
2858
|
+
origin: cfg.origin ?? getOrigin(),
|
|
2859
|
+
deviceToken: () => token,
|
|
2860
|
+
...driver instanceof LocalDriver ? {
|
|
2861
|
+
ownSessions: async () => (await driver.listThreads({ scope: "all", limit: 200 })).threads.map((t) => t.id)
|
|
2862
|
+
} : {},
|
|
2863
|
+
...t3Threads ? { hostThreads: () => t3Threads.bySession() } : {},
|
|
2864
|
+
log: (line) => console.error(line)
|
|
2865
|
+
});
|
|
2866
|
+
setInterval(() => void capture.tick(), CAPTURE_TICK_MS).unref();
|
|
2867
|
+
}
|
|
2698
2868
|
const stop = (code = 0) => {
|
|
2699
2869
|
log2("stopping");
|
|
2700
2870
|
watch.stop();
|