@cloop/runner 0.2.1 → 0.2.3

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,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ LocalDriver
4
+ } from "./chunk-CDG4IEQY.js";
2
5
  import {
3
6
  MeshSocket,
4
7
  defaultSocketFactory
@@ -6,7 +9,6 @@ import {
6
9
  import {
7
10
  BoxWatch,
8
11
  DEFAULT_FALLBACK_MODEL,
9
- LocalDriver,
10
12
  T3Client,
11
13
  T3Driver,
12
14
  claudeDialect,
@@ -16,25 +18,81 @@ import {
16
18
  lockThreadsFile,
17
19
  mintSession,
18
20
  probeClaude,
21
+ probeClaudePermissions,
19
22
  probeCodex,
20
23
  readRunnerConfig,
21
24
  runBoxTool,
22
25
  threadsFilePath,
23
26
  writeBoxConfig,
24
27
  writeRunnerState
25
- } from "./chunk-2ZVYM4JU.js";
26
- import "./chunk-AQGBNKUG.js";
28
+ } from "./chunk-KKFRQ4HQ.js";
27
29
  import {
28
30
  getMachine
29
31
  } from "./chunk-JX6VG5FE.js";
32
+ import "./chunk-R3CLO2FB.js";
33
+ import "./chunk-TIXA2YXR.js";
34
+ import "./chunk-F4WCO6Z4.js";
30
35
  import "./chunk-AG6SI6I2.js";
31
- import "./chunk-OKF4BDBH.js";
36
+ import "./chunk-FW7MMQQV.js";
32
37
  import {
33
38
  getMeshUrl,
34
39
  getToken,
35
40
  readCredentials
36
41
  } from "./chunk-3DIGCVL4.js";
37
42
 
43
+ // src/outside-sessions.ts
44
+ import { createReadStream } from "fs";
45
+ import { readdir, stat } from "fs/promises";
46
+ import { homedir } from "os";
47
+ import { join } from "path";
48
+ import { createInterface } from "readline";
49
+ var UUID = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i;
50
+ async function listOutsideSessions(root = join(homedir(), ".claude", "projects"), own = /* @__PURE__ */ new Set(), now = Date.now()) {
51
+ const files = [];
52
+ for (const project of await readdir(root, { withFileTypes: true }).catch(() => [])) {
53
+ if (!project.isDirectory()) continue;
54
+ for (const entry of await readdir(join(root, project.name), { withFileTypes: true }).catch(
55
+ () => []
56
+ )) {
57
+ if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
58
+ const id = entry.name.slice(0, -6);
59
+ if (!UUID.test(id) || own.has(id)) continue;
60
+ const path = join(root, project.name, entry.name);
61
+ const info = await stat(path).catch(() => null);
62
+ if (info && info.mtimeMs >= now - 7 * 864e5)
63
+ files.push({ id, project: project.name.slice(0, 200), file: path, mtime: info.mtimeMs });
64
+ }
65
+ }
66
+ const results = [];
67
+ for (const file of files.sort((a, b) => b.mtime - a.mtime).slice(0, 20)) {
68
+ let title;
69
+ const stream = createReadStream(file.file, { encoding: "utf8" });
70
+ const lines = createInterface({ input: stream, crlfDelay: Number.POSITIVE_INFINITY });
71
+ try {
72
+ for await (const line of lines) {
73
+ if (!/^\s*\{\s*"type"\s*:\s*"(?:summary|custom-title|title)"/.test(line)) continue;
74
+ try {
75
+ const record = JSON.parse(line);
76
+ const value = record.type === "summary" ? record.summary : record.type === "custom-title" ? record.customTitle : record.title;
77
+ if (typeof value === "string" && value.trim()) title = value.trim().slice(0, 120);
78
+ } catch {
79
+ }
80
+ }
81
+ } finally {
82
+ lines.close();
83
+ stream.destroy();
84
+ }
85
+ results.push({
86
+ id: file.id,
87
+ project: file.project,
88
+ updatedAt: new Date(file.mtime).toISOString(),
89
+ status: "idle",
90
+ ...title ? { title } : {}
91
+ });
92
+ }
93
+ return results;
94
+ }
95
+
38
96
  // src/commands/box.ts
39
97
  var BEAT_MS = 6e4;
40
98
  var RESEND_MS = 5 * 6e4;
@@ -59,10 +117,12 @@ async function machineHarnesses(cfg) {
59
117
  ]);
60
118
  return [claude, codex].filter((h) => h !== null);
61
119
  }
62
- function localDriver(cfg, name) {
120
+ async function localDriver(cfg, name) {
63
121
  const bin = cfg.driver === name ? cfg.bin : void 0;
64
122
  return new LocalDriver({
65
- dialect: name === "claude-code" ? claudeDialect(bin, cfg.fallbackModels ?? DEFAULT_FALLBACK_MODEL) : codexDialect(bin),
123
+ dialect: name === "claude-code" ? claudeDialect(bin, cfg.fallbackModels ?? DEFAULT_FALLBACK_MODEL, cfg.askEverything, {
124
+ ...await probeClaudePermissions(bin)
125
+ }) : codexDialect(bin),
66
126
  repos: cfg.repos,
67
127
  label: cfg.label,
68
128
  harnesses: () => machineHarnesses(cfg),
@@ -103,7 +163,7 @@ async function run() {
103
163
  out(`${red("\u2717")} Another \`cloop box run\` is running (pid ${lock.heldBy}). Stop it first.`);
104
164
  process.exit(1);
105
165
  }
106
- const driver = local && name !== "t3" ? localDriver(local, name) : new T3Driver({
166
+ const driver = local && name !== "t3" ? await localDriver(local, name) : new T3Driver({
107
167
  client: () => t3.client,
108
168
  t3Bin: isLocal(cfg) ? null : cfg.t3Bin,
109
169
  scope: () => cfg && !isLocal(cfg) ? cfg.scope : void 0,
@@ -122,7 +182,11 @@ async function run() {
122
182
  const onCall = async (frame) => {
123
183
  const started = Date.now();
124
184
  const result = await runBoxTool(
125
- { driver, onLaunch: (workId, threadId) => watch.add(workId, threadId) },
185
+ {
186
+ driver,
187
+ onLaunch: (workId, threadId) => watch.add(workId, threadId),
188
+ onResume: (threadId) => watch.resume(threadId)
189
+ },
126
190
  frame.tool,
127
191
  frame.args
128
192
  );
@@ -178,6 +242,7 @@ async function run() {
178
242
  ...await mintSession(cfg.t3Url, { stored: cfg.t3Bin }),
179
243
  // Read from disk: `cloop connect` may have replaced it since.
180
244
  deviceToken: disk?.deviceToken ?? cfg.deviceToken,
245
+ showOtherThreads: disk?.showOtherThreads ?? false,
181
246
  ...disk?.origin ?? cfg.origin ? { origin: disk?.origin ?? cfg.origin } : {}
182
247
  };
183
248
  cfg = renewed;
@@ -191,8 +256,26 @@ async function run() {
191
256
  const beat = async () => {
192
257
  await renewT3();
193
258
  let running = 0;
259
+ let outsideThreads = [];
194
260
  try {
195
- running = (await driver.listThreads({ scope: "unsettled", limit: 1 })).running;
261
+ const enabled = readRunnerConfig()?.showOtherThreads === true;
262
+ const listed = await driver.listThreads({
263
+ scope: enabled ? "all" : "unsettled",
264
+ limit: enabled ? 200 : 1
265
+ });
266
+ running = listed.running;
267
+ if (enabled && driver.name === "t3")
268
+ outsideThreads = listed.threads.filter((t) => !t.cloop).slice(0, 20).map((t) => ({
269
+ id: t.id,
270
+ title: t.title.slice(0, 120),
271
+ updatedAt: t.updatedAt,
272
+ status: t.status
273
+ }));
274
+ if (enabled && driver.name === "claude-code")
275
+ outsideThreads = await listOutsideSessions(
276
+ void 0,
277
+ new Set(listed.threads.map((t) => t.id))
278
+ );
196
279
  } catch (err) {
197
280
  log(`${driver.name} unreachable: ${err instanceof Error ? err.message : String(err)}`);
198
281
  }
@@ -203,7 +286,7 @@ async function run() {
203
286
  capabilities: [...driver.capabilities],
204
287
  platform: "workstation",
205
288
  machine,
206
- surface: {},
289
+ surface: { driver: driver.name, outsideThreads },
207
290
  status: running > 0 ? "active" : "idle",
208
291
  event: running > 0 ? `${running} running` : ""
209
292
  });