Replace per-turn detached workers with a file-backed queue consumed by
a single long-running batch worker (30s interval, 0-10s jitter).
- queue.ts, batchWorker.ts: file queue with pid-based lock for worker
singleton; tasks deduped by sessionID:messageID before processing
- worker.ts: retry with backoff (5s, 10s) for 429 and network errors;
update commit state per upload so partial failures resume cleanly;
export auth, loadSessionMessages, getSessionDirectory and upload*
helpers for batchWorker reuse
- git.ts: cap commit log at 50 entries within last 7 days; pause 500ms
every 10 commits to spread load
- worker.ts: resolve session jsonl via ~/.claude/projects/{normalized}
with fallbacks, scanning for the file containing the target session
- logger.ts: file + stderr logger gated by CSC_RAW_DUMP_DEBUG, default
silent
- sessionDataUploader.ts: implement createSessionTurnUploader to pick
the last assistant message; query.ts fires uploadSessionTurn after
query_api_streaming_end (non-blocking)
Signed-off-by: 林凯90331 <90331@sangfor.com>
Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
/**
|
||
* Raw Dump 主入口
|
||
* 队列模式:主进程只 enqueue,单 batch worker 顺序消费
|
||
*/
|
||
|
||
import { enqueue } from './queue.js'
|
||
import { spawnBatchWorker } from './spawn.js'
|
||
|
||
let batchWorkerSpawned = false
|
||
|
||
function isEnabled(): boolean {
|
||
if (process.env.CSC_DISABLE_RAW_DUMP === '1' || process.env.CSC_DISABLE_RAW_DUMP === 'true') return false
|
||
if (process.env.COSTRICT_DISABLE_RAW_DUMP === '1' || process.env.COSTRICT_DISABLE_RAW_DUMP === 'true') return false
|
||
return true
|
||
}
|
||
|
||
function ensureBatchWorker() {
|
||
if (batchWorkerSpawned) return
|
||
batchWorkerSpawned = true
|
||
spawnBatchWorker()
|
||
}
|
||
|
||
/**
|
||
* 上报一轮对话
|
||
* 只写入队列,由 batch worker 顺序消费
|
||
*/
|
||
export function reportTurn(sessionID: string, messageID: string, directory: string): void {
|
||
if (!isEnabled()) return
|
||
enqueue({ sessionID, messageID, directory })
|
||
ensureBatchWorker()
|
||
}
|
||
|
||
export function reportSession(sessionID: string, directory: string): void {
|
||
if (!isEnabled()) return
|
||
enqueue({ sessionID, messageID: '__summary__', directory })
|
||
ensureBatchWorker()
|
||
}
|