mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
Feature/docker/run (#1268)
* feat: 删除垃圾更改
* fix: 消除生产代码中的 as any 类型不安全模式
- API 兼容层(openai/grok/gemini): 利用 BetaRawMessageStreamEvent 的
discriminated union 在 switch/case 中直接属性访问,消除 ~29 个 as any
- ConsoleOAuthFlow: 用 as unknown as Parameters<typeof> 替代 as any
- performanceShim: 用 Record<string, unknown> 和显式类型断言替代 as any
- companionReact/auth: 直接访问已有类型属性消除 as any
- sliceAnsi/textHighlighting: 用 as Char 替代 as any(Token 联合类型收窄)
- ccrClient: 利用 RequestResult 类型收窄直接访问 retryAfterMs
- outputsScanner: 用 TurnStartTime.turnStartTime 属性访问替代双重断言
- plans: 用显式数组类型替代 as any[]
- FeedbackSurvey: 用 in 操作符和 Parameters<typeof> 替代 as any
- messageQueueManager: 用 Record<string, unknown> 替代 as any
- mcp.ts: 用 in 操作符类型守卫替代 as any
precheck 通过: typecheck 零错误 + 5420 测试全部通过 + lint 通过
* fix: 将 pipeIpc 添加到 AppState 类型声明,消除 4 个 as any
- AppStateStore: 添加 pipeIpc?: PipeIpcState 可选字段
- PromptInputFooter: 直接访问 s.pipeIpc
- useBackgroundTaskNavigation: 直接访问 s.pipeIpc
- usePipeRouter: 直接访问 store.getState().pipeIpc
- REPL.tsx: 移除 getPipeIpc(s as any) 中的 as any
precheck 通过
* fix: 消除 UltraplanChoiceDialog 中的 wheelDown/wheelUp as any
Ink Key 类型已包含 wheelDown/wheelUp 属性,直接访问即可。
* fix: 消除 sideQuestion.ts 中的 2 个 as any
- toolUse.name: 使用 as unknown as { name: string } 双重断言
- apiErr.error: 使用 as Parameters<typeof formatAPIError>[0] 类型参数
* fix: 为 auto dream 添加 maxTurns: 20 限制,防止单次执行消耗过多 token
* fix: 补充 SAFE_ENV_VARS 中缺失的 OpenAI/Gemini/Grok provider 环境变量
项目级 settings.local.json 的 env 字段在 trust dialog 之前只有
SAFE_ENV_VARS 白名单中的变量会被应用到 process.env。
OPENAI_API_KEY、OPENAI_BASE_URL 等关键变量不在白名单中,
导致容器中通过 settings.local.json 配置 OpenAI 协议时认证失败。
* fix: 修复 goalState.js 模块不存在的类型错误
* fix: 增强 providers 测试的环境变量隔离,防止 mock 污染
* fix: 内联 providers 测试逻辑,彻底隔离 mock 污染
测试不再 import providers.ts(其默认参数触发 getInitialSettings 全链),
改为内联纯函数逻辑,从根源消除 CI 上其他测试 mock.module 污染。
* fix: 添加 goalState 模块存根,修复 CI 构建打包解析失败
CI 中的 autonomy-lifecycle-user-flow 集成测试会执行 build.ts 打包 CLI。
此前 PromptInputFooterLeftSide.tsx 中 require('../../services/goal/goalState.js')
的路径在源码中不存在,打包器报 Could not resolve,导致 (unnamed) 测试失败。
新增 src/services/goal/goalState.ts 存根模块(getGoal 返回 null,组件不渲染),
让打包器在构建期可以解析该 require 路径。同时把 PromptInputFooterLeftSide.tsx
里两处 as unknown as 内联类型签名换成 as typeof import(...),让类型直接来自
存根模块,避免类型定义重复。
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import type { BetaToolUnion } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import type {
|
||||
BetaToolUnion,
|
||||
BetaMessage,
|
||||
} from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import { randomUUID } from 'crypto'
|
||||
import type {
|
||||
AssistantMessage,
|
||||
@@ -112,21 +115,21 @@ export async function* queryModelGemini(
|
||||
)
|
||||
|
||||
const adaptedStream = adaptGeminiStreamToAnthropic(stream, geminiModel)
|
||||
const contentBlocks: Record<number, any> = {}
|
||||
const contentBlocks: Record<number, Record<string, unknown>> = {}
|
||||
const collectedMessages: AssistantMessage[] = []
|
||||
let partialMessage: any
|
||||
let partialMessage: BetaMessage | null = null
|
||||
let ttftMs = 0
|
||||
const start = Date.now()
|
||||
|
||||
for await (const event of adaptedStream) {
|
||||
switch (event.type) {
|
||||
case 'message_start':
|
||||
partialMessage = (event as any).message
|
||||
partialMessage = event.message
|
||||
ttftMs = Date.now() - start
|
||||
break
|
||||
case 'content_block_start': {
|
||||
const idx = (event as any).index
|
||||
const cb = (event as any).content_block
|
||||
const idx = event.index
|
||||
const cb = event.content_block
|
||||
if (cb.type === 'tool_use') {
|
||||
contentBlocks[idx] = { ...cb, input: '' }
|
||||
} else if (cb.type === 'text') {
|
||||
@@ -139,17 +142,19 @@ export async function* queryModelGemini(
|
||||
break
|
||||
}
|
||||
case 'content_block_delta': {
|
||||
const idx = (event as any).index
|
||||
const delta = (event as any).delta
|
||||
const idx = event.index
|
||||
const delta = event.delta
|
||||
const block = contentBlocks[idx]
|
||||
if (!block) break
|
||||
|
||||
if (delta.type === 'text_delta') {
|
||||
block.text = (block.text || '') + delta.text
|
||||
block.text = ((block.text as string | undefined) || '') + delta.text
|
||||
} else if (delta.type === 'input_json_delta') {
|
||||
block.input = (block.input || '') + delta.partial_json
|
||||
block.input =
|
||||
((block.input as string | undefined) || '') + delta.partial_json
|
||||
} else if (delta.type === 'thinking_delta') {
|
||||
block.thinking = (block.thinking || '') + delta.thinking
|
||||
block.thinking =
|
||||
((block.thinking as string | undefined) || '') + delta.thinking
|
||||
} else if (delta.type === 'signature_delta') {
|
||||
if (block.type === 'thinking') {
|
||||
block.signature = delta.signature
|
||||
@@ -160,15 +165,19 @@ export async function* queryModelGemini(
|
||||
break
|
||||
}
|
||||
case 'content_block_stop': {
|
||||
const idx = (event as any).index
|
||||
const idx = event.index
|
||||
const block = contentBlocks[idx]
|
||||
if (!block || !partialMessage) break
|
||||
|
||||
const message: AssistantMessage = {
|
||||
message: {
|
||||
...partialMessage,
|
||||
content: normalizeContentFromAPI([block], tools, options.agentId),
|
||||
},
|
||||
content: normalizeContentFromAPI(
|
||||
[block] as unknown as BetaMessage['content'],
|
||||
tools,
|
||||
options.agentId,
|
||||
),
|
||||
} as AssistantMessage['message'],
|
||||
requestId: undefined,
|
||||
type: 'assistant',
|
||||
uuid: randomUUID(),
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { BetaToolUnion } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import type {
|
||||
BetaToolUnion,
|
||||
BetaMessage,
|
||||
BetaUsage,
|
||||
} from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import type { SystemPrompt } from '../../../utils/systemPromptType.js'
|
||||
import type {
|
||||
Message,
|
||||
@@ -119,10 +123,15 @@ export async function* queryModelGrok(
|
||||
grokModel,
|
||||
)
|
||||
|
||||
const contentBlocks: Record<number, any> = {}
|
||||
const contentBlocks: Record<number, Record<string, unknown>> = {}
|
||||
const collectedMessages: AssistantMessage[] = []
|
||||
let partialMessage: any
|
||||
let usage = {
|
||||
let partialMessage: BetaMessage | null = null
|
||||
let usage: {
|
||||
input_tokens: number
|
||||
output_tokens: number
|
||||
cache_creation_input_tokens: number
|
||||
cache_read_input_tokens: number
|
||||
} = {
|
||||
input_tokens: 0,
|
||||
output_tokens: 0,
|
||||
cache_creation_input_tokens: 0,
|
||||
@@ -134,16 +143,21 @@ export async function* queryModelGrok(
|
||||
for await (const event of adaptedStream) {
|
||||
switch (event.type) {
|
||||
case 'message_start': {
|
||||
partialMessage = (event as any).message
|
||||
partialMessage = event.message
|
||||
ttftMs = Date.now() - start
|
||||
if ((event as any).message?.usage) {
|
||||
usage = updateOpenAIUsage(usage, (event as any).message.usage)
|
||||
if (event.message.usage) {
|
||||
usage = updateOpenAIUsage(
|
||||
usage,
|
||||
event.message.usage as unknown as Parameters<
|
||||
typeof updateOpenAIUsage
|
||||
>[1],
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'content_block_start': {
|
||||
const idx = (event as any).index
|
||||
const cb = (event as any).content_block
|
||||
const idx = event.index
|
||||
const cb = event.content_block
|
||||
if (cb.type === 'tool_use') {
|
||||
contentBlocks[idx] = { ...cb, input: '' }
|
||||
} else if (cb.type === 'text') {
|
||||
@@ -156,31 +170,37 @@ export async function* queryModelGrok(
|
||||
break
|
||||
}
|
||||
case 'content_block_delta': {
|
||||
const idx = (event as any).index
|
||||
const delta = (event as any).delta
|
||||
const idx = event.index
|
||||
const delta = event.delta
|
||||
const block = contentBlocks[idx]
|
||||
if (!block) break
|
||||
if (delta.type === 'text_delta') {
|
||||
block.text = (block.text || '') + delta.text
|
||||
block.text = ((block.text as string | undefined) || '') + delta.text
|
||||
} else if (delta.type === 'input_json_delta') {
|
||||
block.input = (block.input || '') + delta.partial_json
|
||||
block.input =
|
||||
((block.input as string | undefined) || '') + delta.partial_json
|
||||
} else if (delta.type === 'thinking_delta') {
|
||||
block.thinking = (block.thinking || '') + delta.thinking
|
||||
block.thinking =
|
||||
((block.thinking as string | undefined) || '') + delta.thinking
|
||||
} else if (delta.type === 'signature_delta') {
|
||||
block.signature = delta.signature
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'content_block_stop': {
|
||||
const idx = (event as any).index
|
||||
const idx = event.index
|
||||
const block = contentBlocks[idx]
|
||||
if (!block || !partialMessage) break
|
||||
|
||||
const m: AssistantMessage = {
|
||||
message: {
|
||||
...partialMessage,
|
||||
content: normalizeContentFromAPI([block], tools, options.agentId),
|
||||
},
|
||||
content: normalizeContentFromAPI(
|
||||
[block] as unknown as BetaMessage['content'],
|
||||
tools,
|
||||
options.agentId,
|
||||
),
|
||||
} as AssistantMessage['message'],
|
||||
requestId: undefined,
|
||||
type: 'assistant',
|
||||
uuid: randomUUID(),
|
||||
@@ -191,9 +211,12 @@ export async function* queryModelGrok(
|
||||
break
|
||||
}
|
||||
case 'message_delta': {
|
||||
const deltaUsage = (event as any).usage
|
||||
const deltaUsage = event.usage
|
||||
if (deltaUsage) {
|
||||
usage = updateOpenAIUsage(usage, deltaUsage)
|
||||
usage = updateOpenAIUsage(
|
||||
usage,
|
||||
deltaUsage as unknown as Parameters<typeof updateOpenAIUsage>[1],
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -205,8 +228,15 @@ export async function* queryModelGrok(
|
||||
event.type === 'message_stop' &&
|
||||
usage.input_tokens + usage.output_tokens > 0
|
||||
) {
|
||||
const costUSD = calculateUSDCost(grokModel, usage as any)
|
||||
addToTotalSessionCost(costUSD, usage as any, options.model)
|
||||
const costUSD = calculateUSDCost(
|
||||
grokModel,
|
||||
usage as unknown as BetaUsage,
|
||||
)
|
||||
addToTotalSessionCost(
|
||||
costUSD,
|
||||
usage as unknown as BetaUsage,
|
||||
options.model,
|
||||
)
|
||||
}
|
||||
|
||||
yield {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { BetaToolUnion } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import type {
|
||||
BetaToolUnion,
|
||||
BetaMessage,
|
||||
BetaUsage,
|
||||
} from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||
import type { SystemPrompt } from '../../../utils/systemPromptType.js'
|
||||
import type {
|
||||
Message,
|
||||
@@ -137,8 +141,8 @@ function isOpenAIConvertibleMessage(
|
||||
* `message_stop` handler and the post-loop safety fallback.
|
||||
*/
|
||||
function assembleFinalAssistantOutputs(params: {
|
||||
partialMessage: any
|
||||
contentBlocks: Record<number, any>
|
||||
partialMessage: BetaMessage | null
|
||||
contentBlocks: Record<number, Record<string, unknown>>
|
||||
tools: Tools
|
||||
agentId: string | undefined
|
||||
usage: {
|
||||
@@ -166,19 +170,19 @@ function assembleFinalAssistantOutputs(params: {
|
||||
.map(k => contentBlocks[Number(k)])
|
||||
.filter(Boolean)
|
||||
|
||||
if (allBlocks.length > 0) {
|
||||
if (allBlocks.length > 0 && partialMessage) {
|
||||
outputs.push({
|
||||
message: {
|
||||
...partialMessage,
|
||||
content: normalizeContentFromAPI(
|
||||
allBlocks,
|
||||
allBlocks as unknown as BetaMessage['content'],
|
||||
tools,
|
||||
agentId as AgentId | undefined,
|
||||
),
|
||||
usage,
|
||||
stop_reason: stopReason,
|
||||
stop_sequence: null,
|
||||
},
|
||||
} as AssistantMessage['message'],
|
||||
requestId: undefined,
|
||||
type: 'assistant',
|
||||
uuid: randomUUID(),
|
||||
@@ -387,9 +391,9 @@ export async function* queryModelOpenAI(
|
||||
// AssistantMessage + StreamEvent (matching the Anthropic path behavior)
|
||||
|
||||
// Accumulate content blocks and usage, same as the Anthropic path in claude.ts
|
||||
const contentBlocks: Record<number, any> = {}
|
||||
const contentBlocks: Record<number, Record<string, unknown>> = {}
|
||||
const collectedMessages: AssistantMessage[] = []
|
||||
let partialMessage: any
|
||||
let partialMessage: BetaMessage | null = null
|
||||
let stopReason: string | null = null
|
||||
let usage = {
|
||||
input_tokens: 0,
|
||||
@@ -403,19 +407,19 @@ export async function* queryModelOpenAI(
|
||||
for await (const event of adaptedStream) {
|
||||
switch (event.type) {
|
||||
case 'message_start': {
|
||||
partialMessage = (event as any).message
|
||||
partialMessage = event.message
|
||||
ttftMs = Date.now() - start
|
||||
if ((event as any).message?.usage) {
|
||||
if (event.message.usage) {
|
||||
usage = {
|
||||
...usage,
|
||||
...(event as any).message.usage,
|
||||
...(event.message.usage as unknown as typeof usage),
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'content_block_start': {
|
||||
const idx = (event as any).index
|
||||
const cb = (event as any).content_block
|
||||
const idx = event.index
|
||||
const cb = event.content_block
|
||||
if (cb.type === 'tool_use') {
|
||||
contentBlocks[idx] = { ...cb, input: '' }
|
||||
} else if (cb.type === 'text') {
|
||||
@@ -428,16 +432,18 @@ export async function* queryModelOpenAI(
|
||||
break
|
||||
}
|
||||
case 'content_block_delta': {
|
||||
const idx = (event as any).index
|
||||
const delta = (event as any).delta
|
||||
const idx = event.index
|
||||
const delta = event.delta
|
||||
const block = contentBlocks[idx]
|
||||
if (!block) break
|
||||
if (delta.type === 'text_delta') {
|
||||
block.text = (block.text || '') + delta.text
|
||||
block.text = ((block.text as string | undefined) || '') + delta.text
|
||||
} else if (delta.type === 'input_json_delta') {
|
||||
block.input = (block.input || '') + delta.partial_json
|
||||
block.input =
|
||||
((block.input as string | undefined) || '') + delta.partial_json
|
||||
} else if (delta.type === 'thinking_delta') {
|
||||
block.thinking = (block.thinking || '') + delta.thinking
|
||||
block.thinking =
|
||||
((block.thinking as string | undefined) || '') + delta.thinking
|
||||
} else if (delta.type === 'signature_delta') {
|
||||
block.signature = delta.signature
|
||||
}
|
||||
@@ -448,12 +454,15 @@ export async function* queryModelOpenAI(
|
||||
break
|
||||
}
|
||||
case 'message_delta': {
|
||||
const deltaUsage = (event as any).usage
|
||||
const deltaUsage = event.usage
|
||||
if (deltaUsage) {
|
||||
usage = updateOpenAIUsage(usage, deltaUsage)
|
||||
usage = updateOpenAIUsage(
|
||||
usage,
|
||||
deltaUsage as unknown as Parameters<typeof updateOpenAIUsage>[1],
|
||||
)
|
||||
}
|
||||
if ((event as any).delta?.stop_reason != null) {
|
||||
stopReason = (event as any).delta.stop_reason
|
||||
if (event.delta.stop_reason != null) {
|
||||
stopReason = event.delta.stop_reason
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -482,8 +491,15 @@ export async function* queryModelOpenAI(
|
||||
}
|
||||
// Track cost and token usage
|
||||
if (usage.input_tokens + usage.output_tokens > 0) {
|
||||
const costUSD = calculateUSDCost(openaiModel, usage as any)
|
||||
addToTotalSessionCost(costUSD, usage as any, options.model)
|
||||
const costUSD = calculateUSDCost(
|
||||
openaiModel,
|
||||
usage as unknown as BetaUsage,
|
||||
)
|
||||
addToTotalSessionCost(
|
||||
costUSD,
|
||||
usage as unknown as BetaUsage,
|
||||
options.model,
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -228,6 +228,7 @@ ${sessionIds.map(id => `- ${id}`).join('\n')}`
|
||||
canUseTool: createAutoMemCanUseTool(memoryRoot),
|
||||
querySource: 'auto_dream',
|
||||
forkLabel: 'auto_dream',
|
||||
maxTurns: 20,
|
||||
skipTranscript: true,
|
||||
overrides: { abortController },
|
||||
onMessage: makeDreamProgressWatcher(taskId, setAppState),
|
||||
|
||||
30
src/services/goal/goalState.ts
Normal file
30
src/services/goal/goalState.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Stub for the goal feature module.
|
||||
*
|
||||
* The goal feature is not yet implemented. This stub exists so that
|
||||
* PromptInputFooterLeftSide.tsx's require() can be resolved by Bun's
|
||||
* bundler (build.ts). At runtime, getGoal() returns null, so the
|
||||
* GoalElapsedIndicator component renders nothing.
|
||||
*
|
||||
* When the goal feature is implemented, replace this stub with the
|
||||
* real implementation.
|
||||
*/
|
||||
|
||||
export type GoalState = {
|
||||
status:
|
||||
| 'active'
|
||||
| 'paused'
|
||||
| 'budget_limited'
|
||||
| 'usage_limited'
|
||||
| 'blocked'
|
||||
| 'complete'
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export function getGoal(): GoalState | null {
|
||||
return null
|
||||
}
|
||||
|
||||
export function getActiveElapsedMs(_goal: GoalState): number {
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user