mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 08:15:53 +00:00
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 from637c908dropped 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 from637c908dropped 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>
This commit is contained in:
102
src/jobs/state.ts
Normal file
102
src/jobs/state.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { getClaudeConfigHomeDir } from '../utils/envUtils.js'
|
||||
|
||||
export interface JobState {
|
||||
jobId: string
|
||||
templateName: string
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
status: 'created' | 'running' | 'completed' | 'failed'
|
||||
args: string[]
|
||||
}
|
||||
|
||||
function getJobsDir(): string {
|
||||
return join(getClaudeConfigHomeDir(), 'jobs')
|
||||
}
|
||||
|
||||
export function getJobDir(jobId: string): string {
|
||||
return join(getJobsDir(), jobId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new job directory with initial state.
|
||||
*/
|
||||
export function createJob(
|
||||
jobId: string,
|
||||
templateName: string,
|
||||
templateContent: string,
|
||||
inputText: string,
|
||||
args: string[],
|
||||
): string {
|
||||
const dir = getJobDir(jobId)
|
||||
mkdirSync(dir, { recursive: true })
|
||||
|
||||
const now = new Date().toISOString()
|
||||
const state: JobState = {
|
||||
jobId,
|
||||
templateName,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
status: 'created',
|
||||
args,
|
||||
}
|
||||
|
||||
writeFileSync(
|
||||
join(dir, 'state.json'),
|
||||
JSON.stringify(state, null, 2),
|
||||
'utf-8',
|
||||
)
|
||||
writeFileSync(join(dir, 'template.md'), templateContent, 'utf-8')
|
||||
writeFileSync(join(dir, 'input.txt'), inputText, 'utf-8')
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
/**
|
||||
* Read job state from disk.
|
||||
*/
|
||||
export function readJobState(jobId: string): JobState | null {
|
||||
try {
|
||||
const raw = readFileSync(join(getJobDir(jobId), 'state.json'), 'utf-8')
|
||||
const parsed: unknown = JSON.parse(raw)
|
||||
if (typeof parsed !== 'object' || parsed === null) return null
|
||||
const obj = parsed as Record<string, unknown>
|
||||
if (typeof obj.jobId !== 'string' || typeof obj.status !== 'string') {
|
||||
return null
|
||||
}
|
||||
return obj as unknown as JobState
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a reply to a job.
|
||||
*/
|
||||
export function appendJobReply(jobId: string, text: string): boolean {
|
||||
const dir = getJobDir(jobId)
|
||||
const state = readJobState(jobId)
|
||||
if (!state) return false
|
||||
|
||||
const repliesPath = join(dir, 'replies.jsonl')
|
||||
const entry = JSON.stringify({
|
||||
text,
|
||||
timestamp: new Date().toISOString(),
|
||||
})
|
||||
|
||||
try {
|
||||
appendFileSync(repliesPath, entry + '\n', 'utf-8')
|
||||
} catch {
|
||||
writeFileSync(repliesPath, entry + '\n', 'utf-8')
|
||||
}
|
||||
|
||||
const updated = { ...state, updatedAt: new Date().toISOString() }
|
||||
writeFileSync(
|
||||
join(dir, 'state.json'),
|
||||
JSON.stringify(updated, null, 2),
|
||||
'utf-8',
|
||||
)
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user