mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-24 09:05:50 +00:00
更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121)
* style(B1-1): 格式化 ink/buddy/cli/context/screens/tasks/services/keybindings/state (43 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 修复了 Box.tsx 和 ScrollBox.tsx 中无效的 global.d.ts import。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-2): 格式化 commands (79 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-3): 格式化 components/messages,permissions,mcp,sandbox,shell (104 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-4): 格式化 components/PromptInput,FeedbackSurvey,tasks,agents,skills,design-system,wizard (73 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-5): 格式化 components其余 + hooks + tools (232 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-6): 格式化 main/entrypoints/utils/moreright (21 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: 更新 README,新增 Run.ps1/TODO.md,删除 V6.md - README.md: 大幅重写,更详细版本历史和配置示例 - Run.ps1: 新增 Windows 启动脚本 - TODO.md: 新增包完成清单 - V6.md: 删除(架构重构规划已不适用) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复以前的问题 * fix: 修复 login 面板的问题 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,212 +1,283 @@
|
||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { isFeedbackSurveyDisabled } from 'src/services/analytics/config.js';
|
||||
import { getFeatureValue_CACHED_MAY_BE_STALE } from 'src/services/analytics/growthbook.js';
|
||||
import { type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, logEvent } from 'src/services/analytics/index.js';
|
||||
import { isAutoMemoryEnabled } from '../../memdir/paths.js';
|
||||
import { isPolicyAllowed } from '../../services/policyLimits/index.js';
|
||||
import { FILE_READ_TOOL_NAME } from '../../tools/FileReadTool/prompt.js';
|
||||
import type { Message } from '../../types/message.js';
|
||||
import { getGlobalConfig, saveGlobalConfig } from '../../utils/config.js';
|
||||
import { isEnvTruthy } from '../../utils/envUtils.js';
|
||||
import { isAutoManagedMemoryFile } from '../../utils/memoryFileDetection.js';
|
||||
import { extractTextContent, getLastAssistantMessage } from '../../utils/messages.js';
|
||||
import { logOTelEvent } from '../../utils/telemetry/events.js';
|
||||
import { submitTranscriptShare } from './submitTranscriptShare.js';
|
||||
import type { TranscriptShareResponse } from './TranscriptSharePrompt.js';
|
||||
import { useSurveyState } from './useSurveyState.js';
|
||||
import type { FeedbackSurveyResponse } from './utils.js';
|
||||
const HIDE_THANKS_AFTER_MS = 3000;
|
||||
const MEMORY_SURVEY_GATE = 'tengu_dunwich_bell';
|
||||
const MEMORY_SURVEY_EVENT = 'tengu_memory_survey_event';
|
||||
const SURVEY_PROBABILITY = 0.2;
|
||||
const TRANSCRIPT_SHARE_TRIGGER = 'memory_survey';
|
||||
const MEMORY_WORD_RE = /\bmemor(?:y|ies)\b/i;
|
||||
import { useCallback, useEffect, useMemo, useRef } from 'react'
|
||||
import { isFeedbackSurveyDisabled } from 'src/services/analytics/config.js'
|
||||
import { getFeatureValue_CACHED_MAY_BE_STALE } from 'src/services/analytics/growthbook.js'
|
||||
import {
|
||||
type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
logEvent,
|
||||
} from 'src/services/analytics/index.js'
|
||||
import { isAutoMemoryEnabled } from '../../memdir/paths.js'
|
||||
import { isPolicyAllowed } from '../../services/policyLimits/index.js'
|
||||
import { FILE_READ_TOOL_NAME } from '../../tools/FileReadTool/prompt.js'
|
||||
import type { Message } from '../../types/message.js'
|
||||
import { getGlobalConfig, saveGlobalConfig } from '../../utils/config.js'
|
||||
import { isEnvTruthy } from '../../utils/envUtils.js'
|
||||
import { isAutoManagedMemoryFile } from '../../utils/memoryFileDetection.js'
|
||||
import {
|
||||
extractTextContent,
|
||||
getLastAssistantMessage,
|
||||
} from '../../utils/messages.js'
|
||||
import { logOTelEvent } from '../../utils/telemetry/events.js'
|
||||
import { submitTranscriptShare } from './submitTranscriptShare.js'
|
||||
import type { TranscriptShareResponse } from './TranscriptSharePrompt.js'
|
||||
import { useSurveyState } from './useSurveyState.js'
|
||||
import type { FeedbackSurveyResponse } from './utils.js'
|
||||
|
||||
const HIDE_THANKS_AFTER_MS = 3000
|
||||
const MEMORY_SURVEY_GATE = 'tengu_dunwich_bell'
|
||||
const MEMORY_SURVEY_EVENT = 'tengu_memory_survey_event'
|
||||
const SURVEY_PROBABILITY = 0.2
|
||||
const TRANSCRIPT_SHARE_TRIGGER = 'memory_survey'
|
||||
|
||||
const MEMORY_WORD_RE = /\bmemor(?:y|ies)\b/i
|
||||
|
||||
function hasMemoryFileRead(messages: Message[]): boolean {
|
||||
for (const message of messages) {
|
||||
if (message.type !== 'assistant') {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
const content = message.message.content;
|
||||
const content = message.message.content
|
||||
if (!Array.isArray(content)) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
for (const block of content) {
|
||||
if (block.type !== 'tool_use' || block.name !== FILE_READ_TOOL_NAME) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
const input = block.input as {
|
||||
file_path?: unknown;
|
||||
};
|
||||
if (typeof input.file_path === 'string' && isAutoManagedMemoryFile(input.file_path)) {
|
||||
return true;
|
||||
const input = block.input as { file_path?: unknown }
|
||||
if (
|
||||
typeof input.file_path === 'string' &&
|
||||
isAutoManagedMemoryFile(input.file_path)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
export function useMemorySurvey(messages: Message[], isLoading: boolean, hasActivePrompt = false, {
|
||||
enabled = true
|
||||
}: {
|
||||
enabled?: boolean;
|
||||
} = {}): {
|
||||
state: 'closed' | 'open' | 'thanks' | 'transcript_prompt' | 'submitting' | 'submitted';
|
||||
lastResponse: FeedbackSurveyResponse | null;
|
||||
handleSelect: (selected: FeedbackSurveyResponse) => void;
|
||||
handleTranscriptSelect: (selected: TranscriptShareResponse) => void;
|
||||
|
||||
export function useMemorySurvey(
|
||||
messages: Message[],
|
||||
isLoading: boolean,
|
||||
hasActivePrompt = false,
|
||||
{ enabled = true }: { enabled?: boolean } = {},
|
||||
): {
|
||||
state:
|
||||
| 'closed'
|
||||
| 'open'
|
||||
| 'thanks'
|
||||
| 'transcript_prompt'
|
||||
| 'submitting'
|
||||
| 'submitted'
|
||||
lastResponse: FeedbackSurveyResponse | null
|
||||
handleSelect: (selected: FeedbackSurveyResponse) => void
|
||||
handleTranscriptSelect: (selected: TranscriptShareResponse) => void
|
||||
} {
|
||||
// Track assistant message UUIDs that were already evaluated so we don't
|
||||
// re-roll probability on re-renders or re-scan messages for the same turn.
|
||||
const seenAssistantUuids = useRef<Set<string>>(new Set());
|
||||
const seenAssistantUuids = useRef<Set<string>>(new Set())
|
||||
// Once a memory file read is observed it stays true for the session —
|
||||
// skip the O(n) scan on subsequent turns.
|
||||
const memoryReadSeen = useRef(false);
|
||||
const messagesRef = useRef(messages);
|
||||
messagesRef.current = messages;
|
||||
const memoryReadSeen = useRef(false)
|
||||
const messagesRef = useRef(messages)
|
||||
messagesRef.current = messages
|
||||
|
||||
const onOpen = useCallback((appearanceId: string) => {
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type: 'appeared' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id: appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
||||
});
|
||||
event_type:
|
||||
'appeared' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id:
|
||||
appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
})
|
||||
void logOTelEvent('feedback_survey', {
|
||||
event_type: 'appeared',
|
||||
appearance_id: appearanceId,
|
||||
survey_type: 'memory'
|
||||
});
|
||||
}, []);
|
||||
const onSelect = useCallback((appearanceId_0: string, selected: FeedbackSurveyResponse) => {
|
||||
survey_type: 'memory',
|
||||
})
|
||||
}, [])
|
||||
|
||||
const onSelect = useCallback(
|
||||
(appearanceId: string, selected: FeedbackSurveyResponse) => {
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type:
|
||||
'responded' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id:
|
||||
appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
response:
|
||||
selected as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
})
|
||||
void logOTelEvent('feedback_survey', {
|
||||
event_type: 'responded',
|
||||
appearance_id: appearanceId,
|
||||
response: selected,
|
||||
survey_type: 'memory',
|
||||
})
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
const shouldShowTranscriptPrompt = useCallback(
|
||||
(selected: FeedbackSurveyResponse) => {
|
||||
if (process.env.USER_TYPE !== 'ant') {
|
||||
return false
|
||||
}
|
||||
if (selected !== 'bad' && selected !== 'good') {
|
||||
return false
|
||||
}
|
||||
if (getGlobalConfig().transcriptShareDismissed) {
|
||||
return false
|
||||
}
|
||||
if (!isPolicyAllowed('allow_product_feedback')) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
const onTranscriptPromptShown = useCallback((appearanceId: string) => {
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type: 'responded' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id: appearanceId_0 as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
response: selected as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
||||
});
|
||||
void logOTelEvent('feedback_survey', {
|
||||
event_type: 'responded',
|
||||
appearance_id: appearanceId_0,
|
||||
response: selected,
|
||||
survey_type: 'memory'
|
||||
});
|
||||
}, []);
|
||||
const shouldShowTranscriptPrompt = useCallback((selected_0: FeedbackSurveyResponse) => {
|
||||
if ((process.env.USER_TYPE) !== 'ant') {
|
||||
return false;
|
||||
}
|
||||
if (selected_0 !== 'bad' && selected_0 !== 'good') {
|
||||
return false;
|
||||
}
|
||||
if (getGlobalConfig().transcriptShareDismissed) {
|
||||
return false;
|
||||
}
|
||||
if (!isPolicyAllowed('allow_product_feedback')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, []);
|
||||
const onTranscriptPromptShown = useCallback((appearanceId_1: string) => {
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type: 'transcript_prompt_appeared' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id: appearanceId_1 as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
trigger: TRANSCRIPT_SHARE_TRIGGER as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
||||
});
|
||||
event_type:
|
||||
'transcript_prompt_appeared' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id:
|
||||
appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
trigger:
|
||||
TRANSCRIPT_SHARE_TRIGGER as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
})
|
||||
void logOTelEvent('feedback_survey', {
|
||||
event_type: 'transcript_prompt_appeared',
|
||||
appearance_id: appearanceId_1,
|
||||
survey_type: 'memory'
|
||||
});
|
||||
}, []);
|
||||
const onTranscriptSelect = useCallback(async (appearanceId_2: string, selected_1: TranscriptShareResponse): Promise<boolean> => {
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type: `transcript_share_${selected_1}` as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id: appearanceId_2 as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
trigger: TRANSCRIPT_SHARE_TRIGGER as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
||||
});
|
||||
if (selected_1 === 'dont_ask_again') {
|
||||
saveGlobalConfig(current => ({
|
||||
...current,
|
||||
transcriptShareDismissed: true
|
||||
}));
|
||||
}
|
||||
if (selected_1 === 'yes') {
|
||||
const result = await submitTranscriptShare(messagesRef.current, TRANSCRIPT_SHARE_TRIGGER, appearanceId_2);
|
||||
appearance_id: appearanceId,
|
||||
survey_type: 'memory',
|
||||
})
|
||||
}, [])
|
||||
|
||||
const onTranscriptSelect = useCallback(
|
||||
async (
|
||||
appearanceId: string,
|
||||
selected: TranscriptShareResponse,
|
||||
): Promise<boolean> => {
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type: (result.success ? 'transcript_share_submitted' : 'transcript_share_failed') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id: appearanceId_2 as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
trigger: TRANSCRIPT_SHARE_TRIGGER as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
|
||||
});
|
||||
return result.success;
|
||||
}
|
||||
return false;
|
||||
}, []);
|
||||
const {
|
||||
state,
|
||||
lastResponse,
|
||||
open,
|
||||
handleSelect,
|
||||
handleTranscriptSelect
|
||||
} = useSurveyState({
|
||||
hideThanksAfterMs: HIDE_THANKS_AFTER_MS,
|
||||
onOpen,
|
||||
onSelect,
|
||||
shouldShowTranscriptPrompt,
|
||||
onTranscriptPromptShown,
|
||||
onTranscriptSelect
|
||||
});
|
||||
const lastAssistant = useMemo(() => getLastAssistantMessage(messages), [messages]);
|
||||
event_type:
|
||||
`transcript_share_${selected}` as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id:
|
||||
appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
trigger:
|
||||
TRANSCRIPT_SHARE_TRIGGER as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
})
|
||||
|
||||
if (selected === 'dont_ask_again') {
|
||||
saveGlobalConfig(current => ({
|
||||
...current,
|
||||
transcriptShareDismissed: true,
|
||||
}))
|
||||
}
|
||||
|
||||
if (selected === 'yes') {
|
||||
const result = await submitTranscriptShare(
|
||||
messagesRef.current,
|
||||
TRANSCRIPT_SHARE_TRIGGER,
|
||||
appearanceId,
|
||||
)
|
||||
logEvent(MEMORY_SURVEY_EVENT, {
|
||||
event_type: (result.success
|
||||
? 'transcript_share_submitted'
|
||||
: 'transcript_share_failed') as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
appearance_id:
|
||||
appearanceId as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
trigger:
|
||||
TRANSCRIPT_SHARE_TRIGGER as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
|
||||
})
|
||||
return result.success
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
const { state, lastResponse, open, handleSelect, handleTranscriptSelect } =
|
||||
useSurveyState({
|
||||
hideThanksAfterMs: HIDE_THANKS_AFTER_MS,
|
||||
onOpen,
|
||||
onSelect,
|
||||
shouldShowTranscriptPrompt,
|
||||
onTranscriptPromptShown,
|
||||
onTranscriptSelect,
|
||||
})
|
||||
|
||||
const lastAssistant = useMemo(
|
||||
() => getLastAssistantMessage(messages),
|
||||
[messages],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
if (!enabled) return
|
||||
|
||||
// /clear resets messages but REPL stays mounted — reset refs so a memory
|
||||
// read from the previous conversation doesn't leak into the new one.
|
||||
if (messages.length === 0) {
|
||||
memoryReadSeen.current = false;
|
||||
seenAssistantUuids.current.clear();
|
||||
return;
|
||||
memoryReadSeen.current = false
|
||||
seenAssistantUuids.current.clear()
|
||||
return
|
||||
}
|
||||
|
||||
if (state !== 'closed' || isLoading || hasActivePrompt) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
// 3P default: survey off (no GrowthBook on Bedrock/Vertex/Foundry).
|
||||
if (!getFeatureValue_CACHED_MAY_BE_STALE(MEMORY_SURVEY_GATE, false)) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (!isAutoMemoryEnabled()) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (isFeedbackSurveyDisabled()) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (!isPolicyAllowed('allow_product_feedback')) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (isEnvTruthy(process.env.CLAUDE_CODE_DISABLE_FEEDBACK_SURVEY)) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (!lastAssistant || seenAssistantUuids.current.has(lastAssistant.uuid)) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
const text = extractTextContent(Array.isArray(lastAssistant.message.content) ? lastAssistant.message.content : [], ' ');
|
||||
|
||||
const text = extractTextContent(lastAssistant.message.content, ' ')
|
||||
if (!MEMORY_WORD_RE.test(text)) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
// Mark as evaluated before the memory-read scan so a turn that mentions
|
||||
// "memory" but has no memory read doesn't trigger repeated O(n) scans
|
||||
// on subsequent renders with the same last assistant message.
|
||||
seenAssistantUuids.current.add(lastAssistant.uuid);
|
||||
seenAssistantUuids.current.add(lastAssistant.uuid)
|
||||
|
||||
if (!memoryReadSeen.current) {
|
||||
memoryReadSeen.current = hasMemoryFileRead(messages);
|
||||
memoryReadSeen.current = hasMemoryFileRead(messages)
|
||||
}
|
||||
if (!memoryReadSeen.current) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
if (Math.random() < SURVEY_PROBABILITY) {
|
||||
open();
|
||||
open()
|
||||
}
|
||||
}, [enabled, state, isLoading, hasActivePrompt, lastAssistant, messages, open]);
|
||||
return {
|
||||
}, [
|
||||
enabled,
|
||||
state,
|
||||
lastResponse,
|
||||
handleSelect,
|
||||
handleTranscriptSelect
|
||||
};
|
||||
isLoading,
|
||||
hasActivePrompt,
|
||||
lastAssistant,
|
||||
messages,
|
||||
open,
|
||||
])
|
||||
|
||||
return { state, lastResponse, handleSelect, handleTranscriptSelect }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user