Repository navigation
feat: rank Memory cards by how often and how recently the operator said them - #1780
Merged
Merged
Conversation
…rmation A card's sessions are the sessions that first said its words, picked by session start, then time said, then session name, so the order is the same whatever the ids or the analysis order. The last time said is the newest source in an origin session, so confirming again in the same session makes the card recent and a fork's copy never does. Pi and Grok sessions start when their header or summary says, not at the records a fork copied.
The catalog read the session start from the file's first line, which in omp is the title slot, so an omp fork fell back to the copied records' times. It now reads the header the way every other reader of it does.
…adline and a source limit A retrieval now reads the cards and the operator's sources behind them in one read transaction, so a correction between the two reads is not half seen. The source read looks at the caller's expiry as it reads and tallies, and a card keeps at most 1,000 operator sources: a write past it keeps none of the batch's further sources and reports the card, which the analysis logs.
yansfil
added a commit
that referenced
this pull request
Oct 28, 2026
…eep Memory tidy (#1816) Related: PRD `agents/prd/memory-self-improve/prd.md` (로컬 계약; 아래 Summary와 Evidence가 검토할 내용입니다) · 선행 #1779, #1780 ## Summary - 운영자가 세션마다 같은 부탁을 다시 하고, 같은 취향이 기억 여러 장으로 흩어지고, 준 기억이 먹혔는지 아무도 몰랐습니다. - 이제 Hide pane의 모든 새 세션이 Hide 전역 지시(`~/.hide/state/global-instruction.md`, 4 KiB)를 운영자가 승인한 지시로 받습니다. - 제안 탭이 되풀이한 요청과 줬는데도 안 먹힌 기억을 찾아, 전역 지시에 넣을 줄을 근거와 함께 보여 줍니다. 누르면 Hide가 넣고, 되돌리기는 그 줄만 뺍니다. - Memory는 같은 뜻의 기억을 합치고(되돌리기 가능), 60일 안 쓴 기억은 보관하고, 운영자 말인지 다시 확인할 수 있습니다. - 에이전트가 전역 지시 파일을 쓰는 도구 호출은 hook이 막습니다(운영자 선택 A: best-effort 가드).  제안 탭: 되풀이한 요청에서 나온 전역 지시 줄과 운영자 말 근거, 넣은 뒤 되돌리기와 다시 말함  Memory 탭: 합치기와 다시 확인이 남긴 변경 기록과 되돌리기, 60일 안 쓴 기억의 보관과 되살리기 ## Review - **판단해 주세요**: 운영자 선택 A로 전역 지시 쓰기 가드는 best-effort입니다. 따옴표로 쪼갠 이름, glob, 계산한 이름, PowerShell 표기는 못 봅니다(아래 수용한 위험). - **판단해 주세요**: 수용한 위험이자 후속 B: 파일 지문을 두고, 바뀌었으면 제안 탭에서 한 번 확인받는 방식입니다. 이슈는 운영자가 직접 엽니다. - **판단해 주세요**: 전역 지시를 흔한 이름의 파일(`AGENTS.md` 등)에 링크하면, 그 이름을 담은 셸 호출은 읽기여도 막힙니다. 셸 호출은 읽기와 쓰기를 구분할 수 없기 때문입니다. - **조심해서 볼 파일**: `hide-memory/src/store.rs`, `store/upkeep.rs` - 운영자 Memory 저장소 스키마 21→22 마이그레이션(21 백업을 남김), failure path. - **조심해서 볼 파일**: `herdr-core/src/global_instruction.rs` - 모든 세션에 들어가는 파일 쓰기. 미리 보인 줄의 token이 맞을 때만 쓰고, 그사이 손으로 고친 저장은 덮지 않으며, 링크는 이미 있는 `.md`/`.txt`로만 따라갑니다. - **조심해서 볼 파일**: `hide-agent-hooks/src/global_guard.rs`, OpenCode·Pi·omp 스크립트 - 모든 pre-tool 호출의 고빈도 경로. 이름이 없는 payload는 바이트 검색과 상태 폴더마다 링크 읽기 한 번으로 끝납니다. - **조심해서 볼 파일**: `herdr-core/src/node_migration/copy.rs` - 코어 이동이 링크된 전역 지시를 코어의 상한 읽기(4 KiB, UTF-8, 링크 재추적 없음)로 옮깁니다. 못 읽으면 남기고 진단만 씁니다. - **조심해서 볼 파일**: `herdr-core/src/runtime/suggestion_evidence.rs` - 근거 발췌 읽기는 lock 밖 worker에서 (workspace, row)별로 한 번에 하나만 돌고, panic은 읽지 못한 발췌로 떨어집니다. - **비용 검토**: 분석, 합치기, 보관, 다시 확인은 기존 Memory 분석 worker 위에서 돕니다. 다시 확인 대기는 프로젝트당 20장, 변경 기록은 상한까지 잘리고, 근거 읽기는 single-flight입니다. ## Evidence - **확인한 것**: `sasu implement verify`가 최종 head에서 PASS: workspace nextest 전체와 clippy `-D warnings`. - **확인한 것**: 같은 변경의 앞선 head에서 hooks·memory 590개, core·hided 4048개, web 2220개, desktop 289개 통과. design contract와 workstation identity 검사 통과. - **확인한 것**: 마지막 수정 뒤 hide-agent-hooks 395개 통과. 링크 대상에 쓰는 Claude Write를 컴파일된 hook으로 보내 거절되고, 로그에 명령이나 경로가 남지 않음을 확인했습니다. - **확인한 것**: policy lane(scripts 테스트 713개와 구조 검사)을 로컬에서 통과. 외부 lane의 `remote_core` Memory 여정을 pinned Herdr로 로컬에서 통과. - **확인한 것**: 제안 탭, Memory 탭 화면(ko, en)과 전역 지시가 너무 큰 상태를 gallery에서 캡처했습니다. - **확인하지 못한 것**: 격리한 후보 앱의 native QA는 돌리지 않았습니다. 화면은 gallery 캡처뿐입니다. - **확인하지 못한 것**: 실제 Claude Code, Codex, OpenCode 세션이 전역 지시를 받는지, 쓰기가 거절되는지 실측하지 않았습니다(B30). Windows와 Linux는 CI lane에만 맡깁니다. - **확인하지 못한 것**: `core_move` lane은 로컬 디스크가 모자라 CI에만 맡깁니다. - **확인하지 못한 것**: Claude Code 컨텍스트 10,000자 상한 안에서 전역 지시와 Memory가 함께 들어가는지 재지 않았습니다. <details><summary>후속 개선 (Follow-up improvements)</summary> - 후속 B: 전역 지시 파일 지문을 두고, 바뀌었으면 제안 탭에서 한 번 확인받습니다(운영자가 이슈를 엽니다). - 가드가 못 보는 표기: 따옴표로 쪼갠 이름, glob, `python -c`로 계산한 이름, `cd ~/.hide && cd state`, 256 KiB 이후에만 이름이 있는 payload, Claude Code PowerShell 도구 matcher. - 가드 비용과 범위: 링크 대상 이름이 흔하면 파싱이 넓어집니다. 거절 로그에 rate limit이 없습니다. 링크는 한 단계만 따라갑니다. `.hide-new` 임시 파일 이름은 예측할 수 있습니다. - 테스트: B15 전달 배지 흐름, B12 에스컬레이션, 근거 읽기 panic, `from_card` 같은 세션 경우, 경로를 넣은 JS route decode, OpenCode 2·Pi 링크 경우. - 동작: B11은 세션 시작 시각으로 "받은 세션"을 근사합니다. B13은 켠 날의 소급 계산이 없습니다. stale `writing` 표시가 남는 crash 구간이 있고, 손으로 넣은 줄을 채택할 때 되돌리기 힌트가 없습니다. - 그 밖: `is_invisible` 목록 확장, 줄의 `>` 거절, `trim_changes` 다시 확인 행, 두 클라이언트의 근거 슬롯 공유, 다시 확인 읽기의 순차 처리, 같은 batch 합치기 undo id, alias 재시도, receipt 상한. </details> <details><summary>Verification record</summary> - PRD: `agents/prd/memory-self-improve/prd.md` (sha256 1ec0f473831342cddec15936561f70fbadf390d53016db2786a103bb212ae9c8) - Base e86a1f4 → head 8bd8a5c, verified 2026-10-28T19:09:34.724Z: PASS - Verification report: `agents/runs/memory-self-improve/verification-report.json` and `agents/runs/memory-self-improve/verification-report.md`; source fingerprint f5e066833570caae5a5621e62f7a1a93336d9ff0a96b58e8fb8fc072392b0bc4 - Suites: - S1: GREEN `bash scripts/verify-cargo.sh test` (exit 0) - S2: GREEN `bash scripts/verify-cargo.sh lint` (exit 0) - Reviews (advisory, native subagents): - Fidelity: 28f6903 Fix now 2개(D-37 새 카드의 정정 억제, AI 꺼짐 다시 확인 core 테스트와 오류 문구) -> 52113f680에서 고침; 52113f6, 6cb74d2 Fix now 없음. Follow-up: `from_card` 해석 테스트, 링크 한 단계, B15/B12 테스트, B11 근사, B13 소급. - Code: 28f6903 Fix now 3개 -> f56aca3, 52113f680에서 고침; 52113f6 Fix now 1개(server.js export, Low) -> 6cb74d2; d99d074 Fix now 1개(링크된 전역 지시면 코어 이동 거절, Medium) -> b730419, c1403906f에서 고침; 3237405 fixture 수정 확인; 마지막 리뷰 c140390, 3237405 Fix now 없음. Follow-up: 흔한 링크 이름의 파싱 비용, `may_name` 중복 검색, JS route decode 테스트, 링크를 평평하게 옮긴 기록(`link_copied`). - Security: 28f6903 Fix now 4개 -> 52113f6(256 KiB 이후 이름은 수용한 한계); 52113f6 Fix now 1개(링크 대상이 hook 사전 검사를 못 지남, Medium) -> 6cb74d2; b730419 Follow-up(이동 복사에 상한 없음, 검사-복사 경합)을 c1403906f에서 상한 읽기로 닫음; c140390 Fix now 없음. Follow-up: 흔한 이름 링크 시 셸 읽기 거절, 거절 로그 rate limit, `.hide-new` 예측 가능 이름, PowerShell matcher. - 8bd8a5c87은 c140390 이후 테스트 두 파일만 바꿨습니다(remote_core fixture 시각, SessionStart receipt 기대). - Evidence: 5 registered (5 screenshot); paths are local to the run directory - agents/runs/memory-self-improve/evidence/global_unusable-ko.png - agents/runs/memory-self-improve/evidence/upkeep-ko.png - agents/runs/memory-self-improve/evidence/upkeep-en.png - agents/runs/memory-self-improve/evidence/global-ko.png - agents/runs/memory-self-improve/evidence/global-en.png - Changed paths: 96 (see Files changed) - Delivery: mode pr, branch `feat/memory-self-improve`, base `main` </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
운영자가 여러 세션에서 거듭 말한 카드와 한 번 말한 카드가 같은 순위였습니다.
세션 시작 목록은 카드를 만들 때 모델이 매긴 중요도(salience)로만 정렬돼, 끝난 지 오래된 m4 "hcoord를 hided에 단계적으로 흡수" 같은 카드가 계속 위에 있었습니다.
이제 두 순서 모두 "운영자가 몇 개의 서로 다른 세션에서 말했는가"와 "마지막으로 말한 지 얼마나 됐는가"를 함께 봅니다. 모델 호출은 없고, hook은 여전히 읽기만 합니다.
(1 + ln(1 + 세션 수)) / (1 + 지난 일수 / 30). 세션이 늘수록 덜 늘어나고, 30일이면 절반, 0이 되지는 않음.중요도 × 가중치순 상위 20개.점수 × √가중치로 다시 정렬합니다. 제곱근을 써서 관련성이 계속 주된 기준입니다.스크린샷 없음: 화면 변경 없음 (hide-memory 순서, 분석 출처, 문서)
Review
hide-session/src/catalog.rs,grok.rs- Pi/omp 세션의 시작 시각을 첫 기록 대신 headertimestamp로(omp는 첫 줄 title slot 다음 header를, 다른 header 판독과 같은native_file::header_from_reader로 읽음), Grok는summary.json의created_at으로 읽습니다. fork가 복사한 기록의 옛 시각이 시작 시각이 되지 않게 하려는 것입니다. 둘 다 없으면 예전처럼 첫 기록 시각입니다.hide-memory/src/store.rs마이그레이션 v20 → v21 -memory_sources.words열을 추가하고 v20 백업을 남깁니다(Project 삭제 시 백업도 정리됨). 이전 빌드는 v21 store를 거부합니다.hide-memory/src/store/reinforcement.rs- hook 경로(100 ms 검색 마감)의 쿼리 1개와 Rust 집계입니다. 출처는memory_sources기본 키, 글 비교는memory_revisions의(item_id,revision), 세션 시작은session_sources기본 키로 찾습니다.herdr-core/src/runtime/memory_analysis.rsvalidate_candidates- 분석이 보낸 이벤트 글로 digest를 채웁니다. hook은 쓰지 않습니다.hide-memory/src/store.rsretrieve_with_expiry- 카드 목록과 강화 근거를 한 읽기 트랜잭션(WAL 스냅샷)에서 읽습니다. 쓰기는 없고 끝나면 rollback됩니다.CARD_SOURCE_LIMIT, 실제 최대 13). 넘는 batch는 그 카드에 새 출처를 더하지 않고ApplySummary::sources_full로 알리며, 분석이card.sources_full진단으로 남깁니다. 상한에 닿은 카드는 최근성이 더 오르지 않습니다. 쓰기로는 생길 수 없는 상한 초과 카드는 읽기를 실패시킵니다(부분 집계 대신).Evidence
a_correction_counts_only_its_own_words_and_its_undo_brings_back_the_old_ones- 호출자가 받는 index를 비교합니다.m2@1,m1@1, 정정 후m2@1,m1@2, Undo 후m2@1,m1@1.m1@2,m2@1로 실패합니다.a_forked_session_counts_only_what_the_operator_said_after_the_fork- reader → 분석(scripted provider) → index 전 과정입니다. Claude 세션 파일 두 개를 쓰고, fork 쪽 복사 줄은 Codex처럼 fork 시각으로 바꿨습니다.[3, 2].[2, 3].[2, 3]이 되어 실패합니다.confirming_a_card_again_in_the_same_session_makes_it_recent- 같은 세션에서 다시 확인한 카드가 최근이 되어 index에서 먼저 나옵니다[1, 2]. last-said를 원래 출처 시각으로 되돌리면 실패합니다.a_fork_counts_as_another_session_only_for_what_the_operator_said_in_it- fork가 시각을 유지(Grok·Pi)/다시 씀(Codex) × fork에서 다시 말함/부모만 계속 말함 × 세션 id 사전순 뒤집기 × 분석 순서 뒤집기, 16가지 모두 반환 카드 순서로 확인합니다. fork에서 다시 말하면[1, 2], 아니면[2, 1]. 시작 시각 비교를 빼면 시각을 유지한 fork에서 실패합니다.a_pi_fork_starts_when_its_header_says_not_at_the_records_it_copied,a_grok_fork_starts_when_its_summary_says_not_at_the_records_it_copied.an_omp_fork_starts_when_its_header_past_the_title_slot_says(실제 omp-18.7.0 fixture, catalog 시작 시각)와an_omp_fork_that_kept_its_parents_times_does_not_take_the_parents_words(같은 fixture로 부모·fork omp 파일 → 분석 → index). 옛 첫 줄 판독으로 되돌리면 각각 시작 시각이 복사된 기록 시각이 되고 index가[3, 2]로 실패합니다(고친 뒤[2, 3]).a_correction_between_the_card_read_and_the_support_read_is_not_half_seen- 두 읽기 사이(expiry 콜백)에서 다른 연결이 카드를 정정하고 새 세션 2개에서 다시 말하게 합니다. 결과[(2,1),(1,1)]. 트랜잭션을 빼면[(1,1),(2,1)]로 실패합니다.a_card_keeps_operator_sources_up_to_its_limit_and_reports_a_batch_past_it- 1,000개에서 멈추고 넘는 batch마다sources_full == [1], 상한 초과 카드는memory_card_sources_over_limit로 읽기 실패.-p hide-memory -p herdr-core -p hide-session --all-targets)와 fmt도 깨끗합니다.usage::usage_opencode_2_rows_past_the_read_total_are_read_by_the_next_read가 부하 중 1번 실패했고 단독으로 3번 통과했습니다.세션 시작 목록 상위 20: main → 이 PR
sN= 현재 글을 받치는 서로 다른 세션 수. 전체 462장 중 순위: m4 4 → 190, m31(6세션) 91 → 8, m49 63 → 5, m34 9 → 15.실제 프롬프트에 주입된 카드 before → after (현재 head `32b5affe6` release 빌드)
Verification record
4a6fea3e3(origin/main), head0fce6361d(4차 리뷰 수정6cf8d3bc5,0fce6361d; 이전32b5affe6,26b8432b9, 첫 커밋41cfd6914)cargo nextest run -p hide-memory -p hide-session: 527 passedcargo nextest run -p herdr-core -E 'test(memory) | test(reown) | test(catalog) | test(session) | test(omp)': 737 passed (전체 lib 3358은26b8432b9에서)cargo clippy -p hide-memory -p herdr-core -p hide-session --all-targets -- -D warnings: clean;cargo fmt --all: no changepython3 -m unittest discover -s scripts/tests -p 'test_*.py': 689 OK (21 skipped)scripts/check-no-workstation-identity.sh: pass