mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
Squashed merge of: 1. fix/mcp-tsc-errors — 修复上游 MCP 重构后的 tsc 错误和测试失败 2. feat/pipe-mute-disconnect — Pipe IPC 逻辑断开、/lang 命令、mute 状态机 3. feat/stub-recovery-all — 实现全部 stub 恢复 (task 001-012) 4. feat/kairos-activation — KAIROS 激活解除阻塞 + 工具实现 5. codex/openclaw-autonomy-pr — 自治权限系统、运行记录、managed flows Additional: 6. daemon/job 命令层级化重构 (subcommand 架构) 7. 跨平台后台引擎抽象 (detached/tmux engines) 8. 修复 src/ 中 43 个预存在的 TypeScript 类型错误 9. 修复 langfuse isolated test mock 完整性 10. 修复 CodeRabbit 审查的 Critical/Major/Minor 问题 11. remote-control-server logger 抽象 (测试 stderr 静默化) 12. /simplify 审查修复 (代码复用、质量、效率)
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { spawn } from 'child_process'
|
|
import { openSync, closeSync, mkdirSync } from 'fs'
|
|
import { dirname } from 'path'
|
|
import type { BgEngine, BgStartOptions, BgStartResult, SessionEntry } from '../engine.js'
|
|
import { tailLog } from '../tail.js'
|
|
|
|
export class DetachedEngine implements BgEngine {
|
|
readonly name = 'detached' as const
|
|
|
|
async available(): Promise<boolean> {
|
|
return true
|
|
}
|
|
|
|
async start(opts: BgStartOptions): Promise<BgStartResult> {
|
|
mkdirSync(dirname(opts.logPath), { recursive: true })
|
|
|
|
const logFd = openSync(opts.logPath, 'a')
|
|
const entrypoint = process.argv[1]!
|
|
|
|
const child = spawn(process.execPath, [entrypoint, ...opts.args], {
|
|
detached: true,
|
|
stdio: ['ignore', logFd, logFd],
|
|
env: {
|
|
...opts.env,
|
|
CLAUDE_CODE_SESSION_KIND: 'bg',
|
|
CLAUDE_CODE_SESSION_NAME: opts.sessionName,
|
|
CLAUDE_CODE_SESSION_LOG: opts.logPath,
|
|
} as Record<string, string>,
|
|
cwd: opts.cwd,
|
|
})
|
|
|
|
child.unref()
|
|
closeSync(logFd)
|
|
|
|
const pid = child.pid ?? 0
|
|
|
|
return {
|
|
pid,
|
|
sessionName: opts.sessionName,
|
|
logPath: opts.logPath,
|
|
engineUsed: 'detached',
|
|
}
|
|
}
|
|
|
|
async attach(session: SessionEntry): Promise<void> {
|
|
if (!session.logPath) {
|
|
throw new Error(`Session ${session.sessionId} has no log path.`)
|
|
}
|
|
await tailLog(session.logPath)
|
|
}
|
|
}
|