claude-code-best/src/services/rawDump/spawn.ts
林凯90331 28d4f1f4e5 feat(rawDump): add session data raw-dump reporting module
Introduce a framework-decoupled raw-dump module that uploads conversation, summary, and commits data to the CoStrict server in a non-blocking detached worker process.

- Add src/services/rawDump/ with index, types, state, spawn, git, worker, and README

- Implement reportTurn and reportSession entry points with in-memory dedup and env-based disable switch (CSC_DISABLE_RAW_DUMP / COSTRICT_DISABLE_RAW_DUMP)

- Replace sessionDataUploader stub with uploadSessionTurn that delegates to reportTurn

Signed-off-by: 林凯90331 <90331@sangfor.com>

Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
2026-05-07 17:27:56 +08:00

44 lines
1.1 KiB
TypeScript

/**
* Raw Dump Worker 进程启动器
* 使用 detached 子进程,确保不阻塞主业务流程
*/
import { spawn } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { RAW_DUMP_EVENT_ENV_KEY, type RawDumpEventPayload } from './types.js'
export function getRawDumpEventEnvKey(): string {
return RAW_DUMP_EVENT_ENV_KEY
}
export function spawnRawDumpWorker(payload: RawDumpEventPayload): void {
const entry = process.execPath
const isDev = path.basename(entry).toLowerCase().startsWith('bun')
// 计算 worker.ts 的绝对路径
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const workerPath = path.resolve(__dirname, 'worker.ts')
const args = isDev
? ['run', workerPath]
: [workerPath]
const child = spawn(entry, args, {
detached: true,
windowsHide: true,
stdio: 'ignore',
env: {
...process.env,
[RAW_DUMP_EVENT_ENV_KEY]: JSON.stringify(payload),
},
})
child.on('error', (err) => {
// 静默处理,不影响主进程
console.error('[raw-dump] spawn error:', err.message)
})
child.unref()
}