Files
claude-code/docs/task/task-001-daemon-status-stop.md
claude-code-best c8d08d235b Feat/integrate lint preview (#285)
* feat: 适配 zed acp 协议

* docs: 完善 acp 文档

* feat: integrate feature branches + daemon/job 命令层级化 + 跨平台后台引擎

Cherry-picked from origin/lint/preview (637c908), excluding lint-only changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: correct detectMimeFromBase64 to decode raw bytes from base64

Cherry-picked from origin/lint/preview (ee36954).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: daemon 子进程 spawn 跨平台修复 + CliLaunchSpec 集中化重构

Cherry-picked from origin/lint/preview (c5f52cd), excluding lint-only formatting changes.

- 新建 src/utils/cliLaunch.ts: 集中化 CLI 子进程启动层
- 修复 --daemon-worker=kind 等号格式解析
- 修复 daemon/bg fast path 缺少 setShellIfWindows()
- 修复 checkPathExists 用 existsSync 替代 execSync('dir')
- 7 个 spawn 站点迁移到 CliLaunchSpec

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: merge tsconfig.base.json into tsconfig.json with full compiler options

The cherry-pick from 637c908 dropped jsx/strict/etc settings when removing
tsconfig.base.json. This commit restores them in a single tsconfig.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: merge tsconfig.base.json into tsconfig.json with full compiler options

The cherry-pick from 637c908 dropped jsx/strict/etc settings when removing
tsconfig.base.json. This commit restores them in a single tsconfig.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 20:59:29 +08:00

2.0 KiB
Raw Blame History

Task 001: daemon status / stop

来源: stub-recovery-design-1-4.md 第 1 项 优先级: P0 (首选实现项) 工作量: 小 状态: DONE

目标

claude daemon statusclaude daemon stop 在任意 CLI 进程中都能正确工作,不依赖 TUI 内存态。

背景

  • start 路径已有完整 supervisor + worker 生命周期 (src/daemon/main.ts, src/daemon/workerRegistry.ts)
  • status / stop 目前只是占位输出 (src/daemon/main.ts:49)
  • /remote-control-server 有自己的命令内 UI 状态,但只维护当前进程内的 daemonProcess,不适合跨进程管理

实现方案

新增文件

文件 说明
src/daemon/state.ts daemon 状态文件读写模块

修改文件

文件 改动
src/daemon/main.ts start 写入状态文件;status/stop 调用 state 模块
src/commands/remoteControlServer/remoteControlServer.tsx 读取同一份状态文件(轻量改动)

状态文件

路径: ~/.claude/daemon/remote-control.json

{
  "pid": 12345,
  "cwd": "/path/to/project",
  "startedAt": "2026-04-12T10:00:00Z",
  "workerKinds": ["bridge", "rcs"],
  "lastStatus": "running"
}

status 逻辑

  1. 读取状态文件
  2. 用进程探测验证 pid 是否存活
  3. 输出 running / stopped / stale
  4. stale 时自动清理状态文件

stop 逻辑

  1. 读取 pid
  2. 发送 SIGTERM
  3. 等待退出(超时兜底)
  4. 超时后 SIGKILL
  5. 清理状态文件

验证步骤

  • claude daemon start 正常启动并写入状态文件
  • 新开终端执行 claude daemon status,显示 running
  • 执行 claude daemon stopdaemon 正常退出
  • 再次执行 claude daemon status,返回 stoppedstale cleaned
  • Windows 下 stop 超时兜底正常工作

风险

  • Windows 信号模型和 Unix 不同,stop 需要超时兜底
  • 当前设计默认单 supervisor不处理多实例并发

依赖

无外部依赖,可独立实施。