chattercatcher 0.1.7 → 0.1.8
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/package.json
CHANGED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# Gateway Background Start Implementation Plan
|
|
2
|
-
|
|
3
|
-
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
-
|
|
5
|
-
**Goal:** Make `chattercatcher gateway start` launch Gateway/Web UI in the background by default while preserving `--foreground` for the current blocking behavior.
|
|
6
|
-
|
|
7
|
-
**Architecture:** Keep the existing Gateway runtime as the foreground implementation, and add a thin detached launcher around it. The default `gateway start` process only checks state, opens the log file, spawns the same CLI with `gateway start --foreground`, prints PID/log instructions, and exits; the child process owns Gateway/Web UI startup and PID cleanup.
|
|
8
|
-
|
|
9
|
-
**Tech Stack:** Node.js 20+, TypeScript ESM, Commander, `child_process.spawn`, existing ChatterCatcher config/runtime/log helpers, Vitest.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## File Structure
|
|
14
|
-
|
|
15
|
-
- Modify `src/gateway/runtime.ts`: extend PID records with optional `logFile`, add `getGatewayLogPath()`, keep old PID files readable.
|
|
16
|
-
- Create `src/gateway/detached.ts`: background-launch helper that builds child command, opens log streams, spawns, and returns a launch result.
|
|
17
|
-
- Modify `src/gateway/index.ts`: surface `logFile` in Gateway status.
|
|
18
|
-
- Modify `src/cli.ts`: add default detached start and `--foreground` option.
|
|
19
|
-
- Modify `tests/gateway/runtime.test.ts`: cover `logFile` read/write, compatibility, and status.
|
|
20
|
-
- Create `tests/gateway/detached.test.ts`: cover command construction, running-PID guard, and launch result.
|
|
21
|
-
- Modify `package.json` and `package-lock.json`: bump patch after verification.
|
|
22
|
-
|
|
23
|
-
Do not create commits unless the user explicitly asks for commits.
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
### Task 1: Extend Gateway runtime state with log file support
|
|
28
|
-
|
|
29
|
-
**Files:** `src/gateway/runtime.ts`, `tests/gateway/runtime.test.ts`
|
|
30
|
-
|
|
31
|
-
1. Add runtime tests for PID `logFile` read/write and backward compatibility with old PID files.
|
|
32
|
-
2. Run `npm test -- tests/gateway/runtime.test.ts` and verify failure before implementation.
|
|
33
|
-
3. In `src/gateway/runtime.ts`, add `import { getLogsDirectory } from "../logs/reader.js";`, extend `GatewayPidRecord` with `logFile?: string`, add `getGatewayLogPath(): string` returning `path.join(getLogsDirectory(), "gateway.log")`, and preserve `parsed.logFile` only when it is a string.
|
|
34
|
-
4. Run `npm test -- tests/gateway/runtime.test.ts` and verify pass.
|
|
35
|
-
|
|
36
|
-
### Task 2: Add detached Gateway launcher helper
|
|
37
|
-
|
|
38
|
-
**Files:** `src/gateway/detached.ts`, `tests/gateway/detached.test.ts`
|
|
39
|
-
|
|
40
|
-
1. Create tests that mock `node:child_process.spawn` and cover:
|
|
41
|
-
- `buildGatewayForegroundSpawnCommand(["/usr/local/bin/node", "/repo/dist/cli.js"])` returns command `/usr/local/bin/node` and args `["/repo/dist/cli.js", "gateway", "start", "--foreground"]`.
|
|
42
|
-
- `startDetachedGateway()` creates logs dir, spawns detached child with stdout/stderr to log, returns `started: true`, `pid`, and log path.
|
|
43
|
-
- A running PID record prevents spawning and returns `started: false` with a message containing `正在运行`.
|
|
44
|
-
2. Run `npm test -- tests/gateway/detached.test.ts` and verify failure before implementation.
|
|
45
|
-
3. Create `src/gateway/detached.ts` with `GatewayForegroundSpawnCommand`, `DetachedGatewayStartInput`, `DetachedGatewayStartResult`, `buildGatewayForegroundSpawnCommand()`, and `startDetachedGateway()`.
|
|
46
|
-
4. `startDetachedGateway()` must call `getGatewayStatus()`, use `getGatewayLogPath()`, guard `running`, open append log fds, call `spawn(command, args, { detached: true, stdio: ["ignore", out, err], windowsHide: true })`, call `child.unref()`, and close fds on spawn throw.
|
|
47
|
-
5. Run `npm test -- tests/gateway/runtime.test.ts tests/gateway/detached.test.ts`.
|
|
48
|
-
|
|
49
|
-
### Task 3: Surface log file in Gateway status
|
|
50
|
-
|
|
51
|
-
**Files:** `src/gateway/index.ts`, `tests/gateway/runtime.test.ts`
|
|
52
|
-
|
|
53
|
-
1. Update existing status test so the PID record includes `logFile` and expected status includes `logFile`.
|
|
54
|
-
2. Run `npm test -- tests/gateway/runtime.test.ts` and verify failure before implementation.
|
|
55
|
-
3. Add optional `logFile?: string` to `GatewayStatus`.
|
|
56
|
-
4. Return `logFile: runtime.record.logFile` in running and stale branches.
|
|
57
|
-
5. Run `npm test -- tests/gateway/runtime.test.ts` and `npm test -- tests/gateway/detached.test.ts`.
|
|
58
|
-
|
|
59
|
-
### Task 4: Wire CLI foreground/background behavior
|
|
60
|
-
|
|
61
|
-
**Files:** `src/cli.ts`
|
|
62
|
-
|
|
63
|
-
1. Import `startDetachedGateway` from `./gateway/detached.js` and `getGatewayLogPath` from `./gateway/runtime.js` by merging with the existing runtime import.
|
|
64
|
-
2. Rename existing `startGatewayCommand()` to `startGatewayForegroundCommand()`.
|
|
65
|
-
3. Change foreground PID write to pass a record with `pid`, `startedAt`, `command`, and `logFile: getGatewayLogPath()`.
|
|
66
|
-
4. Add `startGatewayCommand(options: { foreground?: boolean } = {})` that routes foreground to `startGatewayForegroundCommand()`, otherwise loads config/secrets, calls `startDetachedGateway({ config, secrets })`, and prints message, optional PID, log path, logs follow command, and stop command.
|
|
67
|
-
5. Change `gateway start` Commander setup to add `.option("--foreground", "在当前终端以前台模式运行")` and `.action(startGatewayCommand)`.
|
|
68
|
-
6. Keep `gateway restart` calling `await startGatewayCommand()` so it restarts in background.
|
|
69
|
-
7. Run `npm run lint` and fix changed-file TypeScript errors only.
|
|
70
|
-
|
|
71
|
-
### Task 5: Verify tests and build
|
|
72
|
-
|
|
73
|
-
1. Run `npm test -- tests/gateway/runtime.test.ts tests/gateway/detached.test.ts`.
|
|
74
|
-
2. Run `npm test`.
|
|
75
|
-
3. Run `npm run lint`.
|
|
76
|
-
4. Run `npm run build`.
|
|
77
|
-
5. If verification fails, diagnose and fix the smallest relevant issue.
|
|
78
|
-
|
|
79
|
-
### Task 6: Bump npm patch version
|
|
80
|
-
|
|
81
|
-
**Files:** `package.json`, `package-lock.json`
|
|
82
|
-
|
|
83
|
-
1. Run `npm version patch --no-git-tag-version`.
|
|
84
|
-
2. Verify `package.json` and `package-lock.json` root package version moved from current value to the next patch.
|
|
85
|
-
3. Run `git diff -- package.json package-lock.json` and confirm only version metadata changed.
|
|
86
|
-
4. Run `npm run lint`.
|