Skip to content

feat(chat): show an inline memory receipt with undo under each turn - #53

Merged
zereight merged 1 commit into
mainfrom
feat/turn-memory-receipt
Nov 22, 2026
Merged

zereight merged 1 commit into
mainfrom
feat/turn-memory-receipt

Conversation

@zereight

Copy link
Copy Markdown
Owner

요약

턴이 메모리를 바꾸면, 답장 아래에 메모리 영수증(파일 이름, +N/-N, 되돌리기 버튼)을 바로 보여 줍니다. 도구 호출 숨김(기본값) 상태에서도 보입니다. 함께 **되돌리기 해시 검사(409)**를 넣어, 오래된 턴을 되돌릴 때 그 뒤의 더 최근 메모리까지 지워지는 문제를 막았습니다.

이유

  • Orca Bots 벤치마킹: Orca는 턴마다 "Memory updated"를 항상 보여 주고, 사실 단위로 되돌릴 수 있습니다. OpenMyBot은 메모리 변경을 digest 칩에만 memory N개로 표시했고, 그 칩도 showToolCalls(기본 꺼짐)가 켜져 있을 때만 보였습니다. 그래서 사용자는 봇이 무엇을 기억했는지 채팅에서 볼 수 없었습니다.
  • 기존 revertMemoryChange는 파일 전체를 before 스냅샷으로 덮어씁니다. 되돌리기 버튼을 채팅의 모든 턴 아래에 두면 오래된 턴의 Undo를 누르기 쉬워지고, 누르는 순간 그 뒤의 변경이 조용히 사라집니다. 그래서 영수증보다 이 검사를 먼저 넣었습니다.

변경

  • packages/phone-protocol/src/digest.ts: DigestMemory(journalId, added, removed, via, canRevert) 타입 추가
  • server/digest.ts: buildTurnDigest가 저널 행에서 위 필드를 채움
  • server/memory-journal.ts: revertMemoryChange에서 현재 파일 해시가 entry.afterHash와 다르면 409를 돌려줌
  • src/lib/memory.ts: 409를 memory.revertConflict 번역 문구로 바꿈. 채팅 영수증, 설정의 메모리 화면, 메모리 정리 카드 세 곳이 함께 씀
  • src/components/DigestChip.tsx: MemoryReceipt 추가. DigestChip도 이 컴포넌트를 씀. via === "deletion-guard"(feat(memory): restore unauthorized MEMORY.md dated entry deletions at turn end #45)이면 "복원됨" 배지를 보여 줌
  • src/components/ChatView.tsx, src/components/GroupView.tsx, src/components/chat-bubble.ts: 도구 호출을 숨겨도 메모리 변경이 있는 digest는 영수증으로 그림(quietRow)
  • src/locales/{en,ko,pt-br}.json: chat.memoryReceipt.{restored,reverted,revertFailed}, memory.revertConflict
  • 테스트: server/memory-journal.test.ts(409 케이스, MEMORY.md 생성 픽스처가 디스크에 실제로 쓰도록 수정), server/digest.test.ts, src/components/DigestChip.test.ts

Before / After 증적

  • Before (서버): 수정 전 코드에서 새 409 테스트가 실패했습니다. 더 최근 변경이 있는 상태에서 오래된 변경을 되돌리자 ok: true가 나왔고 최근에 추가된 third 줄이 지워졌습니다.
  • Before (UI): 도구 호출 숨김(기본값) 상태에서 digest 행이 null이어서 채팅에 메모리 변경이 전혀 보이지 않았습니다.
  • After (실제 HTTP, 임시 서버): 최근 변경이 있을 때 오래된 변경 되돌리기 → 409, 파일 유지. 최신 변경 되돌리기 → 200. 그 뒤 오래된 변경 되돌리기 → 200.
  • After (실제 화면, 임시 서버 + Vite, 내장 브라우저):
    1. 도구 호출을 숨긴 상태에서 답장 아래에 MEMORY.md +1 Undo 영수증 2개가 보이고, digest-chip은 보이지 않음
    2. 오래된 영수증 Undo → 409, 빨간 경고 문구(role=alert), 디스크의 MEMORY.md는 fact A/B/C 그대로
    3. 최신 영수증 Undo → "Undone", 파일은 A/B
    4. 이어서 오래된 영수증 Undo → "Undone", 파일은 A
    5. 한국어(omb-language=ko)로 바꾼 뒤 409 → "이 변경 뒤에 파일이 또 바뀌었어요. 지금 되돌리면 더 최근 변경까지 지워지니, 최근 변경부터 되돌려 주세요."
  • 테스트: vitest run ChatView·GroupView·DigestChip·OptionsCardRow·Select.guard·bot-panel·bot-settings·room-activity·lib/memory·locales·memory-journal·memory-upkeep·digest·file-size-ratchet → 108개 파일 중 106개 통과(737건 통과). 실패한 2건(ChatView.automation "lets Advanced mode hide routine updates…", BotApiCard.dom "on Starter…")은 stash로 되돌린 기준 커밋 09d8bda05에서도 똑같이 실패하는 포크의 기존 문제입니다.
  • pnpm run typecheck exit 0, pnpm run build exit 0, pre-push(14개 파일) 통과

한계

  • 되돌린 상태는 화면 안에만 남아, 새로고침하면 Undo가 다시 보입니다. 저널에 "되돌림" 표시가 없어서이고, 설정의 메모리 화면도 같습니다. 해시 검사가 덮어쓰기는 막지만, 파일이 우연히 같은 내용으로 돌아오면 다시 되돌려질 수 있습니다.
  • 되돌리기는 여전히 파일 단위입니다. Orca 같은 사실(줄) 단위 되돌리기는 이번 범위에 넣지 않았습니다.
  • 새 문구는 en/ko/pt-br에만 넣었고, 다른 언어는 영어로 보입니다.

Each turn digest now carries the journal id, added/removed counts, origin and revertability of every memory change, and the chat shows them as a small receipt even while tool calls are hidden. Undo refuses (409) when the file changed after that edit, so undoing an older turn can no longer wipe newer memory.
@zereight
zereight merged commit 6ae18f1 into main Nov 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant