@cloop/runner 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,39 +1,42 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  LocalDriver
4
- } from "./chunk-CDG4IEQY.js";
4
+ } from "./chunk-KOOAVO2C.js";
5
5
  import {
6
6
  MeshSocket,
7
7
  defaultSocketFactory
8
8
  } from "./chunk-ZILLDYL4.js";
9
+ import "./chunk-VK6GV757.js";
9
10
  import {
10
11
  BoxWatch,
11
12
  DEFAULT_FALLBACK_MODEL,
12
13
  T3Client,
13
- T3Driver,
14
14
  claudeDialect,
15
15
  codexDialect,
16
16
  connectCommand,
17
- isLocal,
18
17
  lockThreadsFile,
19
18
  mintSession,
20
19
  probeClaude,
21
20
  probeClaudePermissions,
22
21
  probeCodex,
23
- readRunnerConfig,
24
22
  runBoxTool,
25
23
  threadsFilePath,
26
- writeBoxConfig,
27
24
  writeRunnerState
28
- } from "./chunk-KKFRQ4HQ.js";
25
+ } from "./chunk-2FLM3ESE.js";
26
+ import {
27
+ T3Driver,
28
+ isLocal,
29
+ readRunnerConfig,
30
+ writeBoxConfig
31
+ } from "./chunk-G6JAEE2Y.js";
29
32
  import {
30
33
  getMachine
31
34
  } from "./chunk-JX6VG5FE.js";
32
35
  import "./chunk-R3CLO2FB.js";
33
- import "./chunk-TIXA2YXR.js";
34
- import "./chunk-F4WCO6Z4.js";
36
+ import "./chunk-53M5DK6D.js";
37
+ import "./chunk-4XDYJZLF.js";
35
38
  import "./chunk-AG6SI6I2.js";
36
- import "./chunk-FW7MMQQV.js";
39
+ import "./chunk-BFVL3E2C.js";
37
40
  import {
38
41
  getMeshUrl,
39
42
  getToken,
@@ -66,10 +69,19 @@ async function listOutsideSessions(root = join(homedir(), ".claude", "projects")
66
69
  const results = [];
67
70
  for (const file of files.sort((a, b) => b.mtime - a.mtime).slice(0, 20)) {
68
71
  let title;
72
+ let cwd;
69
73
  const stream = createReadStream(file.file, { encoding: "utf8" });
70
74
  const lines = createInterface({ input: stream, crlfDelay: Number.POSITIVE_INFINITY });
71
75
  try {
72
76
  for await (const line of lines) {
77
+ if (!cwd && line.includes('"cwd"')) {
78
+ try {
79
+ const record = JSON.parse(line);
80
+ if (typeof record.cwd === "string" && record.cwd.startsWith("/") && record.cwd.length <= 500)
81
+ cwd = record.cwd;
82
+ } catch {
83
+ }
84
+ }
73
85
  if (!/^\s*\{\s*"type"\s*:\s*"(?:summary|custom-title|title)"/.test(line)) continue;
74
86
  try {
75
87
  const record = JSON.parse(line);
@@ -87,6 +99,7 @@ async function listOutsideSessions(root = join(homedir(), ".claude", "projects")
87
99
  project: file.project,
88
100
  updatedAt: new Date(file.mtime).toISOString(),
89
101
  status: "idle",
102
+ ...cwd ? { cwd } : {},
90
103
  ...title ? { title } : {}
91
104
  });
92
105
  }
@@ -97,6 +110,7 @@ async function listOutsideSessions(root = join(homedir(), ".claude", "projects")
97
110
  var BEAT_MS = 6e4;
98
111
  var RESEND_MS = 5 * 6e4;
99
112
  var REPAIR_BEFORE_MS = 2 * 24 * 36e5;
113
+ var EXPIRING_BEFORE_MS = 3 * 24 * 36e5;
100
114
  var out = (line) => console.log(line);
101
115
  var red = (s) => `\x1B[31m${s}\x1B[0m`;
102
116
  var log = (line) => console.error(`[workstation:daemon] ${line}`);
@@ -110,6 +124,29 @@ async function awaitNewDeviceToken(current, read, { tries = 3, delayMs = 2e3 } =
110
124
  }
111
125
  return null;
112
126
  }
127
+ function t3Presence(cfg, renewalFailed, now = Date.now()) {
128
+ const left = Date.parse(cfg.expiresAt) - now;
129
+ if (Number.isNaN(left)) return null;
130
+ const state = left <= 0 ? "expired" : renewalFailed ? "renewal_failed" : left < EXPIRING_BEFORE_MS ? "expiring" : "ok";
131
+ return { expiresAt: cfg.expiresAt, renewable: Boolean(cfg.t3Bin), state };
132
+ }
133
+ function boxPresence(beat) {
134
+ return {
135
+ session_key: beat.sessionKey,
136
+ name: beat.driver === "t3" ? "Cloop box" : "Cloop runner",
137
+ kind: "workstation",
138
+ capabilities: [...beat.capabilities],
139
+ platform: "workstation",
140
+ machine: beat.machine,
141
+ surface: {
142
+ driver: beat.driver,
143
+ outsideThreads: beat.outsideThreads,
144
+ ...beat.t3 ? { t3: beat.t3 } : {}
145
+ },
146
+ status: beat.running > 0 ? "active" : "idle",
147
+ event: beat.running > 0 ? `${beat.running} running` : ""
148
+ };
149
+ }
113
150
  async function machineHarnesses(cfg) {
114
151
  const [claude, codex] = await Promise.all([
115
152
  probeClaude(cfg.driver === "claude-code" ? cfg.bin : void 0),
@@ -154,7 +191,10 @@ async function run() {
154
191
  );
155
192
  process.exit(1);
156
193
  }
157
- const t3 = { client: isLocal(cfg) ? null : new T3Client(cfg.t3Url, cfg.token) };
194
+ const t3 = {
195
+ client: isLocal(cfg) ? null : new T3Client(cfg.t3Url, cfg.token),
196
+ renewalFailed: false
197
+ };
158
198
  const machine = getMachine();
159
199
  const sessionKey = `box:${machine}`;
160
200
  const factory = await defaultSocketFactory();
@@ -221,6 +261,7 @@ async function run() {
221
261
  token = fresh;
222
262
  cfg = next;
223
263
  if (!isLocal(next)) t3.client = new T3Client(next.t3Url, next.token);
264
+ t3.renewalFailed = false;
224
265
  socket.restart(fresh);
225
266
  return;
226
267
  }
@@ -248,8 +289,10 @@ async function run() {
248
289
  cfg = renewed;
249
290
  writeBoxConfig(renewed);
250
291
  t3.client = new T3Client(renewed.t3Url, renewed.token);
292
+ t3.renewalFailed = false;
251
293
  log(`T3 session renewed until ${renewed.expiresAt}`);
252
294
  } catch (err) {
295
+ t3.renewalFailed = true;
253
296
  log(`T3 session renewal failed: ${err instanceof Error ? err.message : String(err)}`);
254
297
  }
255
298
  };
@@ -279,17 +322,17 @@ async function run() {
279
322
  } catch (err) {
280
323
  log(`${driver.name} unreachable: ${err instanceof Error ? err.message : String(err)}`);
281
324
  }
282
- socket.sendPresence({
283
- session_key: sessionKey,
284
- name: driver.name === "t3" ? "Cloop box" : "Cloop runner",
285
- kind: "workstation",
286
- capabilities: [...driver.capabilities],
287
- platform: "workstation",
288
- machine,
289
- surface: { driver: driver.name, outsideThreads },
290
- status: running > 0 ? "active" : "idle",
291
- event: running > 0 ? `${running} running` : ""
292
- });
325
+ socket.sendPresence(
326
+ boxPresence({
327
+ sessionKey,
328
+ driver: driver.name,
329
+ capabilities: driver.capabilities,
330
+ machine,
331
+ outsideThreads,
332
+ running,
333
+ t3: cfg && !isLocal(cfg) ? t3Presence(cfg, t3.renewalFailed) : null
334
+ })
335
+ );
293
336
  };
294
337
  void beat();
295
338
  setInterval(() => void beat(), BEAT_MS);
@@ -325,6 +368,8 @@ export {
325
368
  REFUSED_LINE,
326
369
  awaitNewDeviceToken,
327
370
  boxCommand,
371
+ boxPresence,
328
372
  recordConnected,
329
- run
373
+ run,
374
+ t3Presence
330
375
  };