ccshare
Version:
Share Claude Code prompts and results easily
75 lines • 3.35 kB
JavaScript
// capture.ts의 개선된 findRealUserPrompt 함수
function findRealUserPrompt(entryUuid, entriesByUuid) {
let current = entriesByUuid.get(entryUuid);
const visited = new Set();
while (current && !visited.has(current.uuid)) {
visited.add(current.uuid);
// user 타입인지 확인
if (current.type === 'user' && current.message) {
// tool_result 타입인지 확인
const isToolResult = current.message.content?.[0]?.type === 'tool_result';
if (!isToolResult) {
// 실제 사용자 입력인지 확인
let content = '';
if (typeof current.message.content === 'string') {
content = current.message.content;
}
else if (Array.isArray(current.message.content)) {
const textItem = current.message.content.find((item) => item.type === 'text');
if (textItem && textItem.text) {
content = textItem.text;
}
}
// 시스템 메시지나 자동 생성된 메시지가 아닌지 확인
if (content &&
!content.includes('<function_calls>') &&
!content.includes('Todos have been modified') &&
!content.includes('<system-reminder>') &&
!content.includes('Tool ran without output') &&
!content.includes('⏺ Update(') && // 파일 변경 출력 메시지 제외
!content.includes('⏺ Read(')) { // 파일 읽기 출력 메시지 제외
return current.uuid;
}
}
}
// 부모로 계속 이동
if (current.parentUuid) {
current = entriesByUuid.get(current.parentUuid);
}
else {
break;
}
}
return null;
}
// capture.ts의 수정된 부분을 적용
export function improvedParentChainTraversal(entry, entriesByUuid) {
// New format (MultiEdit/Edit)
if (entry.toolUseResult?.filePath && entry.toolUseResult?.edits && Array.isArray(entry.toolUseResult.edits)) {
for (const edit of entry.toolUseResult.edits) {
const fileChange = {
type: 'edit',
path: entry.toolUseResult.filePath,
content: edit.new_string,
oldContent: edit.old_string,
timestamp: entry.timestamp || new Date().toISOString()
};
// Generate diff
if (edit.old_string && edit.new_string) {
const diff = generateSimpleDiff(edit.old_string, edit.new_string, entry.toolUseResult.filePath);
fileChange.diff = diff;
}
// Find the real user prompt
const userPromptUuid = findRealUserPrompt(entry.uuid, entriesByUuid);
if (userPromptUuid) {
// Associate with the real user prompt
if (!fileChangesByPrompt.has(userPromptUuid)) {
fileChangesByPrompt.set(userPromptUuid, []);
}
fileChangesByPrompt.get(userPromptUuid).push(fileChange);
}
sessionData.changes.push(fileChange);
}
}
}
//# sourceMappingURL=capture-improved.js.map