botholomew 0.9.9 → 0.9.11

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,5 +1,11 @@
1
+ import { mkdir } from "node:fs/promises";
1
2
  import { join } from "node:path";
2
- import { getBotholomewDir, getLogPath } from "../constants.ts";
3
+ import {
4
+ getBotholomewDir,
5
+ getWorkerLogPath,
6
+ getWorkerLogsDir,
7
+ } from "../constants.ts";
8
+ import { uuidv7 } from "../db/uuid.ts";
3
9
  import { logger } from "../utils/logger.ts";
4
10
  import type { WorkerMode } from "./index.ts";
5
11
 
@@ -12,11 +18,14 @@ export interface SpawnWorkerOptions {
12
18
  * Spawn a worker as a detached background process. Unlike the old daemon
13
19
  * model, multiple workers per project are allowed and expected — this just
14
20
  * launches a new one.
21
+ *
22
+ * The parent generates the worker id and opens a per-worker log file before
23
+ * spawning so that the TUI / CLI can later tail just this worker's output.
15
24
  */
16
25
  export async function spawnWorker(
17
26
  projectDir: string,
18
27
  options: SpawnWorkerOptions = {},
19
- ): Promise<{ pid: number }> {
28
+ ): Promise<{ pid: number; workerId: string; logPath: string }> {
20
29
  const dotDir = getBotholomewDir(projectDir);
21
30
  const dirExists = await Bun.file(join(dotDir, "config.json")).exists();
22
31
  if (!dirExists) {
@@ -24,11 +33,20 @@ export async function spawnWorker(
24
33
  process.exit(1);
25
34
  }
26
35
 
27
- const logPath = getLogPath(projectDir);
36
+ const workerId = uuidv7();
37
+ await mkdir(getWorkerLogsDir(projectDir), { recursive: true });
38
+ const logPath = getWorkerLogPath(projectDir, workerId);
28
39
  const logFile = Bun.file(logPath);
29
40
 
30
41
  const workerScript = new URL("./run.ts", import.meta.url).pathname;
31
- const args = ["bun", "run", workerScript, projectDir];
42
+ const args = [
43
+ "bun",
44
+ "run",
45
+ workerScript,
46
+ projectDir,
47
+ `--worker-id=${workerId}`,
48
+ `--log-path=${logPath}`,
49
+ ];
32
50
  if (options.mode === "persist") args.push("--persist");
33
51
  if (options.taskId) args.push(`--task-id=${options.taskId}`);
34
52
 
@@ -44,5 +62,5 @@ export async function spawnWorker(
44
62
  );
45
63
  logger.dim(` Log: ${logPath}`);
46
64
 
47
- return { pid: proc.pid ?? 0 };
65
+ return { pid: proc.pid ?? 0, workerId, logPath };
48
66
  }