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>
38 lines
982 B
TypeScript
38 lines
982 B
TypeScript
/**
|
|
* Raw Dump 磁盘状态管理
|
|
* 用于 conversation 和 commits 的去重
|
|
*/
|
|
|
|
import { promises as fs } from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import type { RawDumpState } from './types.js'
|
|
|
|
const STATE_DIR = path.join(os.homedir(), '.claude')
|
|
const STATE_FILE = path.join(STATE_DIR, 'csc-raw-dump-state.json')
|
|
|
|
function createEmptyState(): RawDumpState {
|
|
return {
|
|
conversation: {},
|
|
commits: {},
|
|
}
|
|
}
|
|
|
|
export async function readState(): Promise<RawDumpState> {
|
|
try {
|
|
const text = await fs.readFile(STATE_FILE, 'utf-8')
|
|
const parsed = JSON.parse(text) as Partial<RawDumpState>
|
|
return {
|
|
conversation: parsed.conversation ?? {},
|
|
commits: parsed.commits ?? {},
|
|
}
|
|
} catch {
|
|
return createEmptyState()
|
|
}
|
|
}
|
|
|
|
export async function writeState(state: RawDumpState): Promise<void> {
|
|
await fs.mkdir(STATE_DIR, { recursive: true })
|
|
await fs.writeFile(STATE_FILE, JSON.stringify(state, null, 2), 'utf-8')
|
|
}
|