mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 22:05:50 +00:00
* 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>
83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
import { APIUserAbortError } from '@anthropic-ai/sdk'
|
|
import { getEmptyToolPermissionContext } from '../Tool.js'
|
|
import type { Message } from '../types/message.js'
|
|
import { logForDebugging } from '../utils/debug.js'
|
|
import {
|
|
createUserMessage,
|
|
getAssistantMessageText,
|
|
} from '../utils/messages.js'
|
|
import { getSmallFastModel } from '../utils/model/model.js'
|
|
import { asSystemPrompt } from '../utils/systemPromptType.js'
|
|
import { getResolvedLanguage } from '../utils/language.js'
|
|
import { queryModelWithoutStreaming } from './api/claude.js'
|
|
import { getSessionMemoryContent } from './SessionMemory/sessionMemoryUtils.js'
|
|
|
|
// Recap only needs recent context — truncate to avoid "prompt too long" on
|
|
// large sessions. 30 messages ≈ ~15 exchanges, plenty for "where we left off."
|
|
const RECENT_MESSAGE_WINDOW = 30
|
|
|
|
const PROMPT_EN =
|
|
'The user stepped away and is coming back. Write exactly 1-3 short sentences. Start by stating the high-level task — what they are building or debugging, not implementation details. Next: the concrete next step. Skip status reports and commit recaps.'
|
|
|
|
const PROMPT_ZH =
|
|
'用户离开后回来了。用中文写 1-3 句话。先说明用户在做什么(高层目标,不是实现细节),然后说明下一步具体操作。不要写状态报告或提交总结。'
|
|
|
|
function buildAwaySummaryPrompt(memory: string | null): string {
|
|
const memoryBlock = memory
|
|
? `Session memory (broader context):\n${memory}\n\n`
|
|
: ''
|
|
const prompt = getResolvedLanguage() === 'zh' ? PROMPT_ZH : PROMPT_EN
|
|
return `${memoryBlock}${prompt}`
|
|
}
|
|
|
|
/**
|
|
* Generates a short session recap for the "while you were away" card.
|
|
* Returns null on abort, empty transcript, or error.
|
|
*/
|
|
export async function generateAwaySummary(
|
|
messages: readonly Message[],
|
|
signal: AbortSignal,
|
|
): Promise<string | null> {
|
|
if (messages.length === 0) {
|
|
return null
|
|
}
|
|
|
|
try {
|
|
const memory = await getSessionMemoryContent()
|
|
const recent = messages.slice(-RECENT_MESSAGE_WINDOW)
|
|
recent.push(createUserMessage({ content: buildAwaySummaryPrompt(memory) }))
|
|
const response = await queryModelWithoutStreaming({
|
|
messages: recent,
|
|
systemPrompt: asSystemPrompt([]),
|
|
thinkingConfig: { type: 'disabled' },
|
|
tools: [],
|
|
signal,
|
|
options: {
|
|
getToolPermissionContext: async () => getEmptyToolPermissionContext(),
|
|
model: getSmallFastModel(),
|
|
toolChoice: undefined,
|
|
isNonInteractiveSession: false,
|
|
hasAppendSystemPrompt: false,
|
|
agents: [],
|
|
querySource: 'away_summary',
|
|
mcpTools: [],
|
|
skipCacheWrite: true,
|
|
},
|
|
})
|
|
|
|
if (response.isApiErrorMessage) {
|
|
logForDebugging(
|
|
`[awaySummary] API error: ${getAssistantMessageText(response)}`,
|
|
)
|
|
return null
|
|
}
|
|
return getAssistantMessageText(response)
|
|
} catch (err) {
|
|
if (err instanceof APIUserAbortError || signal.aborted) {
|
|
return null
|
|
}
|
|
logForDebugging(`[awaySummary] generation failed: ${err}`)
|
|
return null
|
|
}
|
|
}
|