feat: 大规模清理 claude 的类型问题及依赖

This commit is contained in:
claude-code-best
2026-03-31 22:21:35 +08:00
parent 2c759fe6fa
commit 4c0a655a1c
38 changed files with 1154 additions and 718 deletions

View File

@@ -5,7 +5,7 @@ import React, { useCallback, useMemo, useRef } from 'react';
import { Box, Text } from '../ink.js';
import { useKeybindings } from '../keybindings/useKeybinding.js';
import { logEvent } from '../services/analytics/index.js';
import type { NormalizedUserMessage, RenderableMessage } from '../types/message.js';
import type { ContentItem, NormalizedUserMessage, RenderableMessage } from '../types/message.js';
import { isEmptyMessageText, SYNTHETIC_MESSAGES } from '../utils/messages.js';
const NAVIGABLE_TYPES = ['user', 'assistant', 'grouped_tool_use', 'collapsed_read_search', 'system', 'attachment'] as const;
export type NavigableType = (typeof NAVIGABLE_TYPES)[number];
@@ -19,7 +19,7 @@ export function isNavigableMessage(msg: NavigableMessage): boolean {
switch (msg.type) {
case 'assistant':
{
const b = msg.message.content[0];
const b = msg.message.content[0] as ContentItem | undefined;
// Text responses (minus AssistantTextMessage's return-null cases — tier-1
// misses unmeasured virtual items), or tool calls with extractable input.
return b?.type === 'text' && !isEmptyMessageText(b.text) && !SYNTHETIC_MESSAGES.has(b.text) || b?.type === 'tool_use' && b.name in PRIMARY_INPUT;
@@ -27,7 +27,7 @@ export function isNavigableMessage(msg: NavigableMessage): boolean {
case 'user':
{
if (msg.isMeta || msg.isCompactSummary) return false;
const b = msg.message.content[0];
const b = msg.message.content[0] as ContentItem | undefined;
if (b?.type !== 'text') return false;
// Interrupt etc. — synthetic, not user-authored.
if (SYNTHETIC_MESSAGES.has(b.text)) return false;
@@ -124,14 +124,14 @@ export function toolCallOf(msg: NavigableMessage): {
input: Record<string, unknown>;
} | undefined {
if (msg.type === 'assistant') {
const b = msg.message.content[0];
const b = msg.message.content[0] as ContentItem | undefined;
if (b?.type === 'tool_use') return {
name: b.name,
input: b.input as Record<string, unknown>
};
}
if (msg.type === 'grouped_tool_use') {
const b = msg.messages[0]?.message.content[0];
const b = msg.messages[0]?.message.content[0] as ContentItem | undefined;
if (b?.type === 'tool_use') return {
name: msg.toolName,
input: b.input as Record<string, unknown>
@@ -410,12 +410,12 @@ export function copyTextOf(msg: NavigableMessage): string {
switch (msg.type) {
case 'user':
{
const b = msg.message.content[0];
const b = msg.message.content[0] as ContentItem | undefined;
return b?.type === 'text' ? stripSystemReminders(b.text) : '';
}
case 'assistant':
{
const b = msg.message.content[0];
const b = msg.message.content[0] as ContentItem | undefined;
if (b?.type === 'text') return b.text;
const tc = toolCallOf(msg);
return tc ? PRIMARY_INPUT[tc.name]?.extract(tc.input) ?? '' : '';
@@ -425,14 +425,14 @@ export function copyTextOf(msg: NavigableMessage): string {
case 'collapsed_read_search':
return msg.messages.flatMap(m => m.type === 'user' ? [toolResultText(m)] : m.type === 'grouped_tool_use' ? m.results.map(toolResultText) : []).filter(Boolean).join('\n\n');
case 'system':
if ('content' in msg) return msg.content;
if ('content' in msg) return msg.content as string;
if ('error' in msg) return String(msg.error);
return msg.subtype;
return msg.subtype as string;
case 'attachment':
{
const a = msg.attachment;
if (a.type === 'queued_command') {
const p = a.prompt;
const p = a.prompt as string | ContentItem[];
return typeof p === 'string' ? p : p.flatMap(b => b.type === 'text' ? [b.text] : []).join('\n');
}
return `[${a.type}]`;
@@ -440,7 +440,7 @@ export function copyTextOf(msg: NavigableMessage): string {
}
}
function toolResultText(r: NormalizedUserMessage): string {
const b = r.message.content[0];
const b = r.message.content[0] as ContentItem | undefined;
if (b?.type !== 'tool_result') return '';
const c = b.content;
if (typeof c === 'string') return c;