@cloop/runner 0.3.30 → 0.3.33

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.
Files changed (25) hide show
  1. package/dist/{box-NK3P3ESD.js → box-PZHNXUDE.js} +158 -37
  2. package/dist/{chunk-OTZDNYX4.js → chunk-5BJGP7FY.js} +2 -2
  3. package/dist/{chunk-HGKTPD5Z.js → chunk-6N6FIYOS.js} +1 -1
  4. package/dist/{chunk-3YJD6J2N.js → chunk-7BLD64A4.js} +1 -1
  5. package/dist/{chunk-IYZLO64O.js → chunk-FAHTEHXP.js} +5 -5
  6. package/dist/{chunk-J4YN6KXM.js → chunk-FIBH3C5S.js} +951 -73
  7. package/dist/{chunk-JQGHB2EJ.js → chunk-FNHXCSH2.js} +1 -1
  8. package/dist/{chunk-DYA2BUDB.js → chunk-LZ2XFUEA.js} +6 -6
  9. package/dist/{chunk-NTXQLEMQ.js → chunk-SBYSVZ7J.js} +94 -2
  10. package/dist/{chunk-EOWS3JIY.js → chunk-WE5HZZLE.js} +25 -10
  11. package/dist/{connect-RYIPSXZK.js → connect-V6SFHRT4.js} +7 -8
  12. package/dist/{disconnect-FLRZVPXW.js → disconnect-VVEZIJU2.js} +7 -8
  13. package/dist/{existing-runner-ATMNX2FX.js → existing-runner-ZEGFLOH2.js} +7 -8
  14. package/dist/{hook-activity-GAJ5NABA.js → hook-activity-3T6IMEM6.js} +2 -3
  15. package/dist/{hook-session-start-5JYNMGX4.js → hook-session-start-DLP77G4H.js} +5 -7
  16. package/dist/index.js +20 -17
  17. package/dist/{login-CNTB5SXY.js → login-3COLQ4I6.js} +3 -3
  18. package/dist/{mcp-server-35YMJHA6.js → mcp-server-5KJ5WZOX.js} +8 -10
  19. package/dist/{runner-JDJUWIGC.js → runner-COQXHA6D.js} +4 -4
  20. package/dist/{runs-CKN4DINY.js → runs-W4K74UPN.js} +2 -2
  21. package/dist/{statusline-UD4OFVWL.js → statusline-C4LLNBIE.js} +1 -1
  22. package/dist/{takeover-M4KKYDHN.js → takeover-ATMQCTKQ.js} +5 -6
  23. package/dist/{use-AFCJUIGA.js → use-KMNUETBR.js} +7 -8
  24. package/package.json +1 -1
  25. package/dist/chunk-ES5BRAKJ.js +0 -88
@@ -1,17 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  serveTakeovers
4
- } from "./chunk-DYA2BUDB.js";
5
- import "./chunk-HGKTPD5Z.js";
4
+ } from "./chunk-LZ2XFUEA.js";
5
+ import "./chunk-6N6FIYOS.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,
15
+ captureCursorPath,
11
16
  classifyError,
12
17
  claudeDialect,
18
+ claudeHome,
13
19
  cmdWord,
14
20
  codexDialect,
21
+ codexHome,
15
22
  connectCommand,
16
23
  findNpx,
17
24
  installedService,
@@ -31,7 +38,7 @@ import {
31
38
  systemServices,
32
39
  unitFor,
33
40
  which
34
- } from "./chunk-J4YN6KXM.js";
41
+ } from "./chunk-FIBH3C5S.js";
35
42
  import {
36
43
  MeshSocket,
37
44
  WAKE_TICK_MS,
@@ -48,7 +55,7 @@ import {
48
55
  runnerStatePath,
49
56
  threadsFilePath,
50
57
  writeRunnerState
51
- } from "./chunk-3YJD6J2N.js";
58
+ } from "./chunk-7BLD64A4.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-EOWS3JIY.js";
96
- import {
97
- getMachine
98
- } from "./chunk-NTXQLEMQ.js";
102
+ } from "./chunk-WE5HZZLE.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-OTZDNYX4.js";
105
- import "./chunk-IYZLO64O.js";
106
- import "./chunk-ES5BRAKJ.js";
108
+ import "./chunk-5BJGP7FY.js";
109
+ import "./chunk-FAHTEHXP.js";
110
+ import {
111
+ getMachine
112
+ } from "./chunk-SBYSVZ7J.js";
107
113
  import {
108
114
  VERSION
109
- } from "./chunk-JQGHB2EJ.js";
115
+ } from "./chunk-FNHXCSH2.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 facts = harnessFacts(this.harness);
802
- const account = facts.account ? await this.core.account(facts.account.kind) : null;
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: facts.name,
813
+ name: facts2.name,
808
814
  version: null,
809
815
  ready: account ? account.state === "connected" : true,
810
816
  signedIn,
811
- account: account && signedIn ? facts.account?.label(account.plan) ?? null : null,
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 facts = await this.repos.facts(tree.clone, tree.branch, path, inUse);
1011
- const fate = worktreeFate(facts);
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, facts.head);
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 ${facts.head}.`;
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 { homedir, hostname, tmpdir } from "os";
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 claudeHome = opts.claudeHome ?? (process.env.CLAUDE_CONFIG_DIR || join3(homedir(), ".claude"));
1561
- const codexHome = opts.codexHome ?? (process.env.CODEX_HOME || join3(homedir(), ".codex"));
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: claudeHome,
1573
+ home: claudeHome2,
1568
1574
  // projects/<project>/<session>.jsonl and projects/<project>/<session>/subagents/agent-*.jsonl
1569
- roots: [{ dir: join3(claudeHome, "projects"), depth: 4 }],
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: codexHome,
1584
+ home: codexHome2,
1579
1585
  roots: [
1580
- { dir: join3(codexHome, "sessions"), depth: 4 },
1581
- { dir: join3(codexHome, "archived_sessions"), depth: 1 }
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)
@@ -1676,12 +1682,12 @@ function lastKnown(read, initial, { ms, what, onFail }) {
1676
1682
  // src/outside-sessions.ts
1677
1683
  import { createReadStream as createReadStream2 } from "fs";
1678
1684
  import { readdir as readdir2, stat as stat2 } from "fs/promises";
1679
- import { homedir as homedir2 } from "os";
1685
+ import { homedir } from "os";
1680
1686
  import { join as join4 } from "path";
1681
1687
  import { createInterface as createInterface2 } from "readline";
1682
1688
  var seen = /* @__PURE__ */ new Map();
1683
1689
  var UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
1684
- async function listOutsideSessions(root = join4(homedir2(), ".claude", "projects"), own = /* @__PURE__ */ new Set(), now = Date.now()) {
1690
+ async function listOutsideSessions(root = join4(homedir(), ".claude", "projects"), own = /* @__PURE__ */ new Set(), now = Date.now()) {
1685
1691
  const files = [];
1686
1692
  for (const project of await readdir2(root, { withFileTypes: true }).catch(() => [])) {
1687
1693
  if (!project.isDirectory()) continue;
@@ -1806,7 +1812,7 @@ import {
1806
1812
  rmSync as rmSync2,
1807
1813
  symlinkSync
1808
1814
  } from "fs";
1809
- import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
1815
+ import { homedir as homedir2, tmpdir as tmpdir2 } from "os";
1810
1816
  import { join as join5 } from "path";
1811
1817
  var SKILL_DIRS = [".agents/skills", ".claude/skills", ".codex/skills"];
1812
1818
  var GUIDE_FILES = [".agents/AGENTS.md", ".claude/CLAUDE.md", ".codex/AGENTS.md"];
@@ -1850,7 +1856,7 @@ function stage(setup) {
1850
1856
  if (setup.guide) copyFileSync(setup.guide, join5(dir, ".agents", "owner-guide.md"));
1851
1857
  return dir;
1852
1858
  }
1853
- async function packSkills(home = homedir3(), capBytes = SKILLS_CAP_BYTES, tarBin = "tar") {
1859
+ async function packSkills(home = homedir2(), capBytes = SKILLS_CAP_BYTES, tarBin = "tar") {
1854
1860
  const setup = findSetup(home);
1855
1861
  if (setup.skills.length === 0 && !setup.guide) return { ok: false, reason: "no_skills" };
1856
1862
  let dir;
@@ -2007,10 +2013,10 @@ function readText(path) {
2007
2013
  return "";
2008
2014
  }
2009
2015
  }
2010
- function readRemoteMcp(home = homedir3(), codexHome = process.env.CODEX_HOME || join5(home, ".codex")) {
2016
+ function readRemoteMcp(home = homedir2(), codexHome2 = process.env.CODEX_HOME || join5(home, ".codex")) {
2011
2017
  return remoteMcp([
2012
2018
  ...claudeRemoteMcp(readText(join5(home, ".claude.json"))),
2013
- ...codexRemoteMcp(readText(join5(codexHome, "config.toml")))
2019
+ ...codexRemoteMcp(readText(join5(codexHome2, "config.toml")))
2014
2020
  ]);
2015
2021
  }
2016
2022
  async function sendSkills(tar, deps) {
@@ -2085,6 +2091,104 @@ var SetupShare = class {
2085
2091
  }
2086
2092
  };
2087
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
+
2088
2192
  // src/update.ts
2089
2193
  import { execFile as execFile2, spawn as spawn4 } from "child_process";
2090
2194
  import {
@@ -2096,7 +2200,7 @@ import {
2096
2200
  rmSync as rmSync3,
2097
2201
  writeFileSync
2098
2202
  } from "fs";
2099
- import { homedir as homedir4 } from "os";
2203
+ import { homedir as homedir3 } from "os";
2100
2204
  import { dirname, join as join6 } from "path";
2101
2205
  var REGISTRY_LATEST = "https://registry.npmjs.org/@cloop/runner/latest";
2102
2206
  var FIRST_CHECK_MS = 10 * 6e4;
@@ -2202,7 +2306,7 @@ function servicePath(kind, platform) {
2202
2306
  platform,
2203
2307
  kind,
2204
2308
  environment: runnerEnvironment(),
2205
- home: homedir4(),
2309
+ home: homedir3(),
2206
2310
  uid: process.getuid?.() ?? 0,
2207
2311
  ...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
2208
2312
  }).path;
@@ -2344,7 +2448,7 @@ async function adopt(from, kind, { services: given, script = process.argv[1] ??
2344
2448
  const where = {
2345
2449
  platform: services.platform,
2346
2450
  kind,
2347
- home: homedir4(),
2451
+ home: homedir3(),
2348
2452
  uid: process.getuid?.() ?? 0,
2349
2453
  ...process.env.CLOOP_UNIT_DIR ? { dir: process.env.CLOOP_UNIT_DIR } : {}
2350
2454
  };
@@ -2744,6 +2848,23 @@ async function run2() {
2744
2848
  wake.unsent = !socket.send({ type: "wake", ...woke });
2745
2849
  void beat();
2746
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
+ }
2747
2868
  const stop = (code = 0) => {
2748
2869
  log2("stopping");
2749
2870
  watch.stop();
@@ -2,12 +2,12 @@
2
2
  import {
3
3
  ConnectFailure,
4
4
  deviceLogin
5
- } from "./chunk-IYZLO64O.js";
5
+ } from "./chunk-FAHTEHXP.js";
6
6
  import {
7
7
  ApiError,
8
8
  ReauthError,
9
9
  api
10
- } from "./chunk-ES5BRAKJ.js";
10
+ } from "./chunk-SBYSVZ7J.js";
11
11
  import {
12
12
  CONFIG_DIR,
13
13
  getOrigin,
@@ -9,7 +9,7 @@ import {
9
9
  runHarness,
10
10
  runLogDir,
11
11
  runLogPath
12
- } from "./chunk-EOWS3JIY.js";
12
+ } from "./chunk-WE5HZZLE.js";
13
13
  import {
14
14
  sanitizeLabel,
15
15
  stripControl
@@ -3,7 +3,7 @@ import {
3
3
  RUN_TEXT_MAX,
4
4
  boxPath,
5
5
  runnerPath
6
- } from "./chunk-EOWS3JIY.js";
6
+ } from "./chunk-WE5HZZLE.js";
7
7
 
8
8
  // src/box-watch.ts
9
9
  import { randomUUID } from "crypto";
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  ApiError,
4
- api
5
- } from "./chunk-ES5BRAKJ.js";
4
+ api,
5
+ defaultDeviceName
6
+ } from "./chunk-SBYSVZ7J.js";
6
7
  import {
7
8
  VERSION
8
- } from "./chunk-JQGHB2EJ.js";
9
+ } from "./chunk-FNHXCSH2.js";
9
10
  import {
10
11
  getOrigin,
11
12
  readCredentials,
@@ -14,7 +15,6 @@ import {
14
15
 
15
16
  // src/commands/login.ts
16
17
  import { execFile } from "child_process";
17
- import { hostname } from "os";
18
18
 
19
19
  // src/connect-report.ts
20
20
  import { randomUUID } from "crypto";
@@ -142,7 +142,7 @@ function openUrl(url) {
142
142
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
143
143
  async function loginCommand(argv = process.argv.slice(2)) {
144
144
  const origin = getOrigin();
145
- const deviceName = parseDeviceName(argv) ?? hostname();
145
+ const deviceName = parseDeviceName(argv) ?? defaultDeviceName();
146
146
  const existing = readCredentials();
147
147
  let token;
148
148
  try {