qwen-memory-agent 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. qwen_memory_agent-0.1.0/.env.example +7 -0
  2. qwen_memory_agent-0.1.0/.github/workflows/publish.yml +19 -0
  3. qwen_memory_agent-0.1.0/.gitignore +29 -0
  4. qwen_memory_agent-0.1.0/CLAUDE.md +17 -0
  5. qwen_memory_agent-0.1.0/CONTEXT.md +156 -0
  6. qwen_memory_agent-0.1.0/LICENSE +21 -0
  7. qwen_memory_agent-0.1.0/PKG-INFO +206 -0
  8. qwen_memory_agent-0.1.0/README.md +163 -0
  9. qwen_memory_agent-0.1.0/demo/run_demo.py +61 -0
  10. qwen_memory_agent-0.1.0/docs/adr/0001-host-agnostic-hook-memory.md +34 -0
  11. qwen_memory_agent-0.1.0/docs/agents/domain.md +37 -0
  12. qwen_memory_agent-0.1.0/docs/agents/issue-tracker.md +34 -0
  13. qwen_memory_agent-0.1.0/docs/agents/triage-labels.md +15 -0
  14. qwen_memory_agent-0.1.0/install.sh +11 -0
  15. qwen_memory_agent-0.1.0/installer/install_claude_code.py +6 -0
  16. qwen_memory_agent-0.1.0/pyproject.toml +47 -0
  17. qwen_memory_agent-0.1.0/qmem/__init__.py +0 -0
  18. qwen_memory_agent-0.1.0/qmem/__main__.py +16 -0
  19. qwen_memory_agent-0.1.0/qmem/adapters/__init__.py +0 -0
  20. qwen_memory_agent-0.1.0/qmem/adapters/claude_code.py +89 -0
  21. qwen_memory_agent-0.1.0/qmem/cli.py +44 -0
  22. qwen_memory_agent-0.1.0/qmem/config.py +49 -0
  23. qwen_memory_agent-0.1.0/qmem/daemon/__init__.py +0 -0
  24. qwen_memory_agent-0.1.0/qmem/daemon/app.py +95 -0
  25. qwen_memory_agent-0.1.0/qmem/daemon/harvest.py +58 -0
  26. qwen_memory_agent-0.1.0/qmem/daemon/inject.py +30 -0
  27. qwen_memory_agent-0.1.0/qmem/daemon/manifest.py +34 -0
  28. qwen_memory_agent-0.1.0/qmem/daemon/reflect.py +15 -0
  29. qwen_memory_agent-0.1.0/qmem/demo/__init__.py +0 -0
  30. qwen_memory_agent-0.1.0/qmem/demo/scenario.py +28 -0
  31. qwen_memory_agent-0.1.0/qmem/demo/viz.py +23 -0
  32. qwen_memory_agent-0.1.0/qmem/llm/__init__.py +0 -0
  33. qwen_memory_agent-0.1.0/qmem/llm/provider.py +139 -0
  34. qwen_memory_agent-0.1.0/qmem/setup_hooks.py +147 -0
  35. qwen_memory_agent-0.1.0/qmem/store/__init__.py +0 -0
  36. qwen_memory_agent-0.1.0/qmem/store/memory.py +161 -0
  37. qwen_memory_agent-0.1.0/qmem/store/scoring.py +35 -0
  38. qwen_memory_agent-0.1.0/qmem/verify/__init__.py +0 -0
  39. qwen_memory_agent-0.1.0/qmem/verify/package_reader.py +41 -0
  40. qwen_memory_agent-0.1.0/qmem/verify/verifier.py +64 -0
  41. qwen_memory_agent-0.1.0/tests/conftest.py +25 -0
  42. qwen_memory_agent-0.1.0/tests/test_adapter.py +90 -0
  43. qwen_memory_agent-0.1.0/tests/test_demo.py +61 -0
  44. qwen_memory_agent-0.1.0/tests/test_harvest.py +64 -0
  45. qwen_memory_agent-0.1.0/tests/test_provider.py +40 -0
  46. qwen_memory_agent-0.1.0/tests/test_recall.py +45 -0
  47. qwen_memory_agent-0.1.0/tests/test_reflect.py +45 -0
  48. qwen_memory_agent-0.1.0/tests/test_session_start.py +52 -0
  49. qwen_memory_agent-0.1.0/tests/test_store_crud.py +60 -0
  50. qwen_memory_agent-0.1.0/tests/test_user_prompt.py +42 -0
  51. qwen_memory_agent-0.1.0/tests/test_verify_a.py +83 -0
  52. qwen_memory_agent-0.1.0/tests/test_verify_b.py +42 -0
  53. qwen_memory_agent-0.1.0/uninstall.sh +21 -0
  54. qwen_memory_agent-0.1.0/uv.lock +480 -0
@@ -0,0 +1,7 @@
1
+ # Qwen Cloud (OpenAI-compatible)
2
+ QWEN_API_KEY=sk-ws-xxxxxxxx
3
+ QWEN_BASE_URL=https://dashscope-intl.aliyuncs.com/compatible-mode/v1
4
+
5
+ # Model roles
6
+ QWEN_MODEL_INLINE=qwen-plus
7
+ QWEN_MODEL_REVIEW=qwen-turbo
@@ -0,0 +1,19 @@
1
+ name: Publish to PyPI
2
+
3
+ # v* 태그를 푸시하면 빌드 후 PyPI에 발행 (Trusted Publishing / OIDC, 토큰 불필요)
4
+ on:
5
+ push:
6
+ tags: ["v*"]
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ id-token: write # OIDC trusted publishing
14
+ contents: read # private repo checkout (permissions 블록 선언 시 명시 필요)
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: astral-sh/setup-uv@v5
18
+ - run: uv build
19
+ - run: uv publish # OIDC 신뢰 발행 — API 토큰 없이 업로드
@@ -0,0 +1,29 @@
1
+ # Secrets
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+ *.key
6
+
7
+ # Python
8
+ __pycache__/
9
+ *.py[cod]
10
+ .venv/
11
+ venv/
12
+ *.egg-info/
13
+ .pytest_cache/
14
+
15
+ # Memory store / local data
16
+ *.db
17
+ *.sqlite
18
+ *.sqlite3
19
+ data/
20
+ memory_store/
21
+
22
+ # OS / editor
23
+ .DS_Store
24
+ .idea/
25
+ .vscode/
26
+
27
+ # build artifacts
28
+ dist/
29
+ build/
@@ -0,0 +1,17 @@
1
+ # Qwen MemoryAgent
2
+
3
+ 쓸수록 정확해지는(self-improving) 영속 메모리 에이전트. Qwen Cloud 기반. 자세한 설계는 `README.md` 참고.
4
+
5
+ ## Agent skills
6
+
7
+ ### Issue tracker
8
+
9
+ Issues are tracked as GitHub issues via the `gh` CLI (repo: `Mrbaeksang/qwen-memory-agent`). External PRs are **not** a triage surface. See `docs/agents/issue-tracker.md`.
10
+
11
+ ### Triage labels
12
+
13
+ Five canonical triage roles, each mapped to its identically-named label (`needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-human`, `wontfix`). See `docs/agents/triage-labels.md`.
14
+
15
+ ### Domain docs
16
+
17
+ Single-context layout — one `CONTEXT.md` + `docs/adr/` at the repo root. See `docs/agents/domain.md`.
@@ -0,0 +1,156 @@
1
+ # CONTEXT — Qwen MemoryAgent
2
+
3
+ 이 문서는 아키텍처 정본(source of truth)이자 도메인 용어집(ubiquitous language)이다.
4
+ 설계 결정의 배경은 `docs/adr/` 참고.
5
+
6
+ ---
7
+
8
+ ## 한 줄 정의
9
+
10
+ 코딩 에이전트의 **낡은 학습지식 + 웹서치 미동봉**으로 생기는 라이브러리/API 실수를,
11
+ **compact 시점에 수확 → 디스크의 실제 설치버전으로 검증 → 루트 메모리에 저장 →
12
+ 다음 어떤 플랫폼의 어떤 세션이든 세션당 1회 자동 주입**하고,
13
+ 결과로 **스스로 점수를 교정(자가 발전)**하는 host-agnostic 로컬 메모리 데몬.
14
+
15
+ 효용: *"네 코딩 에이전트는 웹서치를 안 해서 낡은 API로 틀린다. 이 메모리는 그 실수를
16
+ 한 번 잡아 정답을 확인해두고, 모든 미래 세션에 자동 주입한다. 틀리면 스스로 도태시킨다."*
17
+
18
+ ---
19
+
20
+ ## 도메인 용어 (ubiquitous language)
21
+
22
+ | 용어 | 정의 |
23
+ |---|---|
24
+ | **Lesson** | 검증된 교정 1건. `{trigger, wrong, right, snippet, source, scope, confidence, use/success/fail, stale}` |
25
+ | **Trigger** | lesson 매칭 키 = `패키지@버전 + 작업유형` (예: `sqlalchemy==2.0.31 \| async test`) |
26
+ | **Harvest** | PreCompact 시 transcript+에러로그를 스캔해 "사용법 실수 후보"를 뽑는 단계 |
27
+ | **Verify** | 후보의 정답을 확정하는 단계. A=설치패키지 뜯기(우선), B=웹서치(폴백) |
28
+ | **Inject** | 미래 세션에 lesson을 컨텍스트로 끼워넣음. 호스트 LLM의 도구호출 없이(무개입) |
29
+ | **Reflect** | 주입 결과(성공/실패) 신호로 confidence/score를 갱신, 틀린 lesson 도태 |
30
+ | **Root memory** | 크로스세션·크로스플랫폼 공용 저장소(`~/.qmem/mem.db`) |
31
+ | **Adapter** | 플랫폼별 얇은 훅 스크립트. 이벤트를 데몬에 POST, 주입 컨텍스트를 stdout |
32
+ | **Daemon** | 항상 실행되는 두뇌. 저장/회상/수확/검증/reflect 담당 |
33
+ | **Tier** | 플랫폼의 통합 가능 등급. 1=훅(풀루프) / 2=MCP / 3=룰파일 |
34
+ | **Provider** | LLM 백엔드. OpenAI 호환 추상화, Qwen이 기본값 |
35
+
36
+ 회상 점수: `score = confidence × recency_decay(last_used) × success/(success+fail+1)`
37
+
38
+ ---
39
+
40
+ ## 시스템 토폴로지
41
+
42
+ ```
43
+ HOSTS (결정은 얘들이, 메모리에 무개입)
44
+ Claude Code[레퍼런스] · Codex · Gemini CLI · Cursor · ...
45
+ │ 라이프사이클 훅 (stdin: event+transcript_path / stdout: 주입ctx)
46
+ ┌────▼──────────────────────────────────────┐
47
+ │ ADAPTER LAYER 플랫폼별 얇은 훅 스크립트 │
48
+ └────────────────┬───────────────────────────┘
49
+ │ HTTP localhost fire-and-forget
50
+ ┌────────────────▼───────────────────────────────────────────┐
51
+ │ LOCAL DAEMON │
52
+ │ Ingress · Recall(inject) · Harvest(compact) · Reflect │
53
+ │ ┌───────────────────────────────────────────────────────┐ │
54
+ │ │ MEMORY STORE SQLite+FTS5 ~/.qmem/mem.db │ │
55
+ │ │ L1 Curated(항상주입,~2k) · L2 Episodic(원문,FTS5) · │ │
56
+ │ │ L3 Scored(lesson 본체, rerank top-K 주입) │ │
57
+ │ └───────────────────────────────────────────────────────┘ │
58
+ │ Verifier(A:패키지뜯 / B:웹서치) · LLM Provider(Qwen기본) │
59
+ └──────┬───────────────────────────────┬─────────────────────┘
60
+ │ DISK │ LLM ENDPOINT (OpenAI 호환)
61
+ node_modules/ site-packages/ qwen-turbo(추출) · qwen-plus(검증/합성,+search)
62
+ (실제 설치버전 = 정답 출처) · qwen3-rerank(회상) | 교체: OpenAI/로컬
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 5단계 파이프라인 (lesson의 생애)
68
+
69
+ ```
70
+ ①HARVEST PreCompact 훅 → transcript + 세션중 에러로그
71
+ → qwen-turbo가 "사용법 실수 후보" 추출 (에러신호로 후보 좁힘) [async]
72
+ ②VERIFY A. 설치패키지 뜯기(버전·타입·README) ◄우선
73
+ B. 없으면 웹서치(qwen-plus enable_search) 폴백
74
+ → qwen-plus가 "버전-정확 권장법"=lesson 합성 [async]
75
+ ③STORE lesson 레코드 + FTS5 인덱싱 + 모순체크(충돌→옛것 stale)
76
+ ④INJECT SessionStart: 매니페스트(package.json/requirements.txt) 읽어 프리로드
77
+ UserPromptSubmit: 기술언급 감지→주입
78
+ 세션당 보증: injected={session_id: set(lesson_id)} 로 (세션,lesson) 1회
79
+ → additionalContext stdout → 호스트가 모델 컨텍스트에 삽입 (LLM 무개입)
80
+ ⑤REFLECT 결과신호(테스트통과/에러0=success / 또터짐·유저교정=fail)
81
+ → score 갱신 → 낮으면 archive(도태), 높으면 우선주입 ↺①
82
+ ```
83
+
84
+ 약한 고리: **결과 귀속(outcome attribution)** 은 상관에 근사 — 인과 보장 X.
85
+ 양이 쌓이면 통계적으로 수렴. 데모는 "테스트 통과/실패 → confidence 막대"로 증명.
86
+
87
+ ---
88
+
89
+ ## 멀티플랫폼 통합 — 3등급
90
+
91
+ 감지는 쉬움(설정경로 `exists` 루프). 변수는 통합 가능 등급:
92
+
93
+ ```
94
+ TIER 1 훅 → 풀루프(자동주입+compact수확) ★타겟
95
+ Claude Code · Gemini CLI · Cursor · Copilot CLI · Kiro · (Qwen Code)
96
+ TIER 2 MCP → recall을 MCP 툴 노출(호스트가 호출, 반쪽)
97
+ VS Code Copilot · Zed · OpenCode · Kilo · Kimi · JetBrains · Antigravity
98
+ TIER 3 룰 → AGENTS.md 정적 포인터만(동적주입 X, 최소)
99
+ Aider · Cline · Goose · Warp · Windsurf
100
+ ```
101
+
102
+ 감지 레지스트리(데이터로 분리, 새 플랫폼=표 한 줄):
103
+
104
+ | 플랫폼 | 감지 경로 | tier |
105
+ |---|---|---|
106
+ | Claude Code | `~/.claude/settings.json` | hooks |
107
+ | Qwen Code | `~/.qwen/settings.json` | hooks |
108
+ | Gemini CLI | `~/.gemini/settings.json` | hooks |
109
+ | Codex | `~/.codex/config.toml` | mcp(훅 신규) |
110
+ | Cursor | `~/.cursor/hooks.json`, `~/.cursor/mcp.json` | hooks |
111
+ | Copilot CLI | `~/.copilot/hooks/` | hooks(precompact X) |
112
+ | Zed | `~/.config/zed/settings.json` | mcp |
113
+ | Aider | `AGENTS.md` | rules |
114
+
115
+ ---
116
+
117
+ ## 설치기 (코어 이후 단계)
118
+
119
+ ```
120
+ $ uvx qwen-memory init
121
+ STEP1 SCAN 레지스트리 감지경로 exists 루프 → detected
122
+ STEP2 PRESENT 감지된 것만 체크박스(기본 전체ON), tier 표기(거짓약속 금지)
123
+ STEP3 WIRE 선택 플랫폼에 등급별 와이어링
124
+ tier1→settings/hooks.json에 훅 등록
125
+ tier2→mcp.json에 qmem MCP 등록
126
+ tier3→AGENTS.md에 참조 블록 append
127
+ STEP4 DAEMON ~/.qmem 생성, mem.db 초기화, 데몬 등록/기동
128
+ ```
129
+
130
+ ---
131
+
132
+ ## 차별점 (vs prior art)
133
+
134
+ claude-mem · agentmemory · context-mode 는 "대화를 압축 저장/주입"까지만 한다.
135
+ 본 프로젝트의 wedge:
136
+ 1. **설치된 패키지를 직접 뜯어 버전-정확하게 검증** (낡음·환각 0, 오프라인)
137
+ 2. **점수형 Reflect로 자가 교정** (틀린 lesson 자동 도태 = "increasingly accurate")
138
+
139
+ 플러밍(훅·자동감지·멀티플랫폼)은 prior art 패턴을 그대로 차용하고,
140
+ 시간은 위 두 wedge에 집중한다.
141
+
142
+ ---
143
+
144
+ ## 기술 스택 (권장)
145
+
146
+ ```
147
+ 언어 Python 3.12 데몬 FastAPI + uvicorn (async)
148
+ 저장 sqlite3 + FTS5 LLM openai SDK (base_url 교체)
149
+ 기본모델 qwen-turbo/plus/qwen3-rerank (dashscope-intl)
150
+ 검증 importlib.metadata / node_modules 파서 · enable_search(폴백)
151
+ 설치기 uvx qwen-memory init (npx 래퍼 가능)
152
+ ```
153
+ ```
154
+
155
+ scoring: score = confidence × recency_decay × success/(success+fail+1)
156
+ ```
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mrbaeksang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.4
2
+ Name: qwen-memory-agent
3
+ Version: 0.1.0
4
+ Summary: Host-agnostic, self-correcting library/API memory daemon for coding agents (Qwen MemoryAgent)
5
+ Project-URL: Homepage, https://github.com/Mrbaeksang/qwen-memory-agent
6
+ Project-URL: Repository, https://github.com/Mrbaeksang/qwen-memory-agent
7
+ Project-URL: Issues, https://github.com/Mrbaeksang/qwen-memory-agent/issues
8
+ Author-email: Mrbaeksang <qortkdgus95@gmail.com>
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 Mrbaeksang
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: agent,claude,claude-code,hooks,llm,mcp,memory,qwen
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Topic :: Software Development :: Libraries
37
+ Requires-Python: >=3.12
38
+ Requires-Dist: fastapi>=0.115
39
+ Requires-Dist: httpx>=0.27
40
+ Requires-Dist: openai>=1.40
41
+ Requires-Dist: uvicorn>=0.30
42
+ Description-Content-Type: text/markdown
43
+
44
+ # Qwen MemoryAgent
45
+
46
+ > **Global AI Hackathon Series with Qwen Cloud — Track 1: MemoryAgent**
47
+ > 낡은 학습지식 때문에 라이브러리 실수를 반복하는 코딩 에이전트를, **쓸수록 정확해지게** 만드는
48
+ > host-agnostic 자가교정 메모리. Qwen Cloud 기반.
49
+
50
+ ---
51
+
52
+ ## 문제
53
+
54
+ AI 코딩 에이전트는 **학습된(낡은) 지식**으로 라이브러리/의존성을 다루다 실수한다. 웹서치를
55
+ 기본 동봉하지 않으니 최신 API를 모른다. 결정적으로 — **한 세션에서 그 실수를 교정해도
56
+ 다음/다른 세션은 그걸 모른다.** 같은 함정에 매번 다시 빠진다.
57
+
58
+ ## 효용
59
+
60
+ > 네 코딩 에이전트는 웹서치를 안 해서 낡은 API로 틀린다. 이 메모리는 그 실수를 **compact
61
+ > 순간에 잡아 — 디스크에 깔린 실제 버전을 뜯어 정답을 확인해두고 — 모든 플랫폼의 모든 미래
62
+ > 세션에 세션당 1회 자동 주입한다. 틀리면 스스로 도태시킨다.**
63
+
64
+ 핵심은 단순 저장이 아니라 **(1) 실수 수확 · (2) 버전-정확 검증 · (3) 무개입 주입 · (4) 자가 교정**.
65
+
66
+ ---
67
+
68
+ ## 아키텍처 (요약 — 정본은 [`CONTEXT.md`](./CONTEXT.md))
69
+
70
+ ```
71
+ HOSTS (결정은 얘들이, 메모리에 무개입)
72
+ Claude Code · Codex · Gemini CLI · Cursor · ...
73
+ │ 라이프사이클 훅
74
+ ADAPTER LAYER (플랫폼별 얇은 훅 스크립트)
75
+ │ HTTP localhost
76
+ LOCAL DAEMON ── Ingress · Recall · Harvest · Reflect
77
+ ├─ MEMORY STORE SQLite+FTS5 (~/.qmem/mem.db)
78
+ │ L1 Curated(항상주입) · L2 Episodic(원문/FTS5) · L3 Scored(lesson/rerank)
79
+ ├─ Verifier A:설치패키지 뜯기(우선) / B:웹서치(폴백)
80
+ └─ LLM Provider Qwen 기본 (qwen-turbo/plus/qwen3-rerank) · 교체 가능
81
+ ```
82
+
83
+ ### 5단계 파이프라인
84
+
85
+ ```
86
+ ①HARVEST PreCompact 훅 → transcript+에러로그 → qwen-turbo가 실수후보 추출 [async]
87
+ ②VERIFY 설치패키지 뜯기(A,우선) → 없으면 웹서치(B) → qwen-plus가 정답=lesson 합성 [async]
88
+ ③STORE lesson + FTS5 인덱싱 + 모순체크(충돌→stale)
89
+ ④INJECT SessionStart/UserPromptSubmit 훅 → 세션당 1회 자동 주입 (LLM 무개입)
90
+ ⑤REFLECT 결과신호(테스트통과/실패) → score 갱신 → 도태/우선주입 ↺①
91
+ ```
92
+
93
+ `score = confidence × recency_decay(last_used) × success/(success+fail+1)`
94
+
95
+ ---
96
+
97
+ ## 차별점 (vs claude-mem · agentmemory · context-mode)
98
+
99
+ 기존 툴은 "대화를 압축 저장/주입"까지만 한다. 본 프로젝트의 wedge:
100
+
101
+ | | 본 프로젝트 | 기존 툴 |
102
+ |---|---|---|
103
+ | 검증 | **설치 패키지를 직접 뜯어 버전-정확** (환각 0) | 대화 요약 저장 |
104
+ | 학습 | **점수형 Reflect 자가교정** (틀린 lesson 도태) | 없음 |
105
+
106
+ 플러밍(훅·자동감지·멀티플랫폼)은 prior art 패턴을 차용하고, 시간은 위 둘에 집중.
107
+
108
+ ---
109
+
110
+ ## 멀티플랫폼 — 자동감지 + 등급별 통합
111
+
112
+ 설치기 `uvx qwen-memory init`이 설정경로를 스캔해 깔린 플랫폼을 감지하고, 대화형으로 적용 대상을
113
+ 고른 뒤 등급별로 와이어링한다. 등급:
114
+
115
+ ```
116
+ TIER 1 훅 풀루프(자동주입+수확) ← Claude Code · Gemini CLI · Cursor · Copilot CLI · Kiro
117
+ TIER 2 MCP recall을 MCP 툴 노출 ← Zed · OpenCode · VS Code Copilot · JetBrains ...
118
+ TIER 3 룰 AGENTS.md 정적 포인터 ← Aider · Cline · Goose · Warp ...
119
+ ```
120
+
121
+ 해커톤 데모는 **Claude Code(Tier1)** 레퍼런스로 풀루프를 완성형으로 시연.
122
+
123
+ ---
124
+
125
+ ## Qwen 모델 배분 (비종속, Qwen 기본 권장)
126
+
127
+ | 용도 | 모델 |
128
+ |---|---|
129
+ | 실수 후보 추출 (대량) | `qwen-turbo` |
130
+ | 검증/lesson 합성 (+웹서치) | `qwen-plus` (`enable_search`) |
131
+ | 회상 재정렬 | `qwen3-rerank` |
132
+ | L2 키워드 검색 | LLM 미사용 (FTS5) |
133
+
134
+ **Qwen 쓰면 풀스택, 타 프로바이더는 코어(rerank/웹서치 차등).**
135
+ **API**: OpenAI 호환 — `base_url=https://dashscope-intl.aliyuncs.com/compatible-mode/v1`
136
+
137
+ ---
138
+
139
+ ## 심사 기준 매핑
140
+
141
+ | 심사 기준 | 구현 |
142
+ |---|---|
143
+ | ① 효율 저장/검색 | L2 FTS5(임베딩 0) + L3 점수 랭킹 + qwen3-rerank |
144
+ | ② 적시 망각 | 모순 stale + 점수 감쇠 archive + 용량 통합 |
145
+ | ③ 제한 컨텍스트 회상 | L1 토큰캡 + rerank top-K + 세션당 1회 주입 |
146
+ | **increasingly accurate** | 패키지-검증 + Reflect success/fail 점수 교정 |
147
+
148
+ ---
149
+
150
+ ## 빌드 단계
151
+
152
+ - [x] **P1** — SQLite+FTS5 스키마, lesson CRUD/검색 (L2/L3) — #2 #3
153
+ - [x] **P2** — Claude Code 어댑터: SessionStart/UserPromptSubmit 주입 (세션당 1회) — #5 #6 #7
154
+ - [x] **P3** — PreCompact 수확 → Verifier(패키지 뜯기 A) → lesson 합성 — #8 #9
155
+ - [x] **P4** — Reflect 점수 루프 + 웹서치 폴백(B) *(차별화 핵심)* — #4 #10 #11
156
+ - [x] **P5** — 데모 시나리오 + confidence 시각화 — #12
157
+ - [~] **P6** — 설치기: Claude Code(Tier1) 훅 와이어링 + launchd 데몬 완료 / 멀티플랫폼 자동감지·대화형은 다음
158
+
159
+ > 코어(P1~P5) 구현 완료 — `uv run pytest` 51 passed, `uv run python demo/run_demo.py`로 크로스세션 학습 데모 실행.
160
+
161
+ ---
162
+
163
+ ## 실사용 설치 (Claude Code)
164
+
165
+ **PyPI (권장)** — 레포 클론 없이:
166
+ ```bash
167
+ uv tool install qwen-memory-agent # 또는 pipx install qwen-memory-agent
168
+ qmem install # 훅 와이어링 + 데몬 기동
169
+ # ~/.qmem/.env 에 QWEN_API_KEY 입력 후: qmem install 재실행(또는 데몬 재기동)
170
+ ```
171
+ 명령: `qmem install` / `qmem uninstall` / `qmem status` / `qmem daemon` / `qmem hook`
172
+
173
+ **레포에서(개발)** — 원스크립트:
174
+ ```bash
175
+ git clone https://github.com/Mrbaeksang/qwen-memory-agent && cd qwen-memory-agent
176
+ cp .env.example .env # QWEN_API_KEY 입력
177
+ ./install.sh # uv sync + qmem install (idempotent)
178
+ ```
179
+
180
+ 제거: `qmem uninstall` (또는 `./uninstall.sh`). 메모리 완전삭제는 `rm -rf ~/.qmem`.
181
+
182
+ 데몬은 `127.0.0.1:8787`, 루트 메모리는 `~/.qmem/mem.db`. 이후 모든 Claude Code 세션에서
183
+ SessionStart/UserPromptSubmit 시 관련 교정이 자동 주입되고, PreCompact 시 실수가 수확·검증된다.
184
+ LLM 키는 프로젝트 `.env`(`QWEN_API_KEY`)에서 로드한다. (현재 macOS/launchd 기준)
185
+
186
+ ---
187
+
188
+ ## 데모 시나리오
189
+
190
+ 1. **세션 1 (Claude Code)**: AI가 SQLAlchemy 2.0 async에서 sync Session 사용 → asyncpg
191
+ `another operation in progress` 에러 → compact가 수확 → 설치된 `sqlalchemy==2.x`를 뜯어
192
+ 정답(AsyncSession+savepoint) 검증 → **lesson 저장**
193
+ 2. **재시작(크로스세션) → 세션 2**: 같은 작업 → SessionStart가 lesson 자동 주입 →
194
+ AI가 처음부터 올바르게 → **에러 0**
195
+ 3. 옛 lesson이 틀린 것으로 판명(또 터짐) → fail++ → confidence 하락 → **stale 도태**
196
+ 4. confidence 막대 시각화 → "학습 중" 증명
197
+
198
+ ---
199
+
200
+ ## 참고
201
+
202
+ - omp 메모리 설계: https://github.com/can1357/oh-my-pi/blob/main/docs/memory.md
203
+ - Hermes Agent: https://yuv.ai/blog/hermes-agent
204
+ - prior art: [claude-mem](https://github.com/thedotmack/claude-mem) · [agentmemory](https://github.com/rohitg00/agentmemory) · [context-mode](https://github.com/mksglu/context-mode) · [ruler](https://github.com/intellectronica/ruler)
205
+ - "Hindsight is 20/20" (arxiv 2512.12818): https://arxiv.org/abs/2512.12818
206
+ - Qwen Cloud Hackathon: https://qwencloud-hackathon.devpost.com/
@@ -0,0 +1,163 @@
1
+ # Qwen MemoryAgent
2
+
3
+ > **Global AI Hackathon Series with Qwen Cloud — Track 1: MemoryAgent**
4
+ > 낡은 학습지식 때문에 라이브러리 실수를 반복하는 코딩 에이전트를, **쓸수록 정확해지게** 만드는
5
+ > host-agnostic 자가교정 메모리. Qwen Cloud 기반.
6
+
7
+ ---
8
+
9
+ ## 문제
10
+
11
+ AI 코딩 에이전트는 **학습된(낡은) 지식**으로 라이브러리/의존성을 다루다 실수한다. 웹서치를
12
+ 기본 동봉하지 않으니 최신 API를 모른다. 결정적으로 — **한 세션에서 그 실수를 교정해도
13
+ 다음/다른 세션은 그걸 모른다.** 같은 함정에 매번 다시 빠진다.
14
+
15
+ ## 효용
16
+
17
+ > 네 코딩 에이전트는 웹서치를 안 해서 낡은 API로 틀린다. 이 메모리는 그 실수를 **compact
18
+ > 순간에 잡아 — 디스크에 깔린 실제 버전을 뜯어 정답을 확인해두고 — 모든 플랫폼의 모든 미래
19
+ > 세션에 세션당 1회 자동 주입한다. 틀리면 스스로 도태시킨다.**
20
+
21
+ 핵심은 단순 저장이 아니라 **(1) 실수 수확 · (2) 버전-정확 검증 · (3) 무개입 주입 · (4) 자가 교정**.
22
+
23
+ ---
24
+
25
+ ## 아키텍처 (요약 — 정본은 [`CONTEXT.md`](./CONTEXT.md))
26
+
27
+ ```
28
+ HOSTS (결정은 얘들이, 메모리에 무개입)
29
+ Claude Code · Codex · Gemini CLI · Cursor · ...
30
+ │ 라이프사이클 훅
31
+ ADAPTER LAYER (플랫폼별 얇은 훅 스크립트)
32
+ │ HTTP localhost
33
+ LOCAL DAEMON ── Ingress · Recall · Harvest · Reflect
34
+ ├─ MEMORY STORE SQLite+FTS5 (~/.qmem/mem.db)
35
+ │ L1 Curated(항상주입) · L2 Episodic(원문/FTS5) · L3 Scored(lesson/rerank)
36
+ ├─ Verifier A:설치패키지 뜯기(우선) / B:웹서치(폴백)
37
+ └─ LLM Provider Qwen 기본 (qwen-turbo/plus/qwen3-rerank) · 교체 가능
38
+ ```
39
+
40
+ ### 5단계 파이프라인
41
+
42
+ ```
43
+ ①HARVEST PreCompact 훅 → transcript+에러로그 → qwen-turbo가 실수후보 추출 [async]
44
+ ②VERIFY 설치패키지 뜯기(A,우선) → 없으면 웹서치(B) → qwen-plus가 정답=lesson 합성 [async]
45
+ ③STORE lesson + FTS5 인덱싱 + 모순체크(충돌→stale)
46
+ ④INJECT SessionStart/UserPromptSubmit 훅 → 세션당 1회 자동 주입 (LLM 무개입)
47
+ ⑤REFLECT 결과신호(테스트통과/실패) → score 갱신 → 도태/우선주입 ↺①
48
+ ```
49
+
50
+ `score = confidence × recency_decay(last_used) × success/(success+fail+1)`
51
+
52
+ ---
53
+
54
+ ## 차별점 (vs claude-mem · agentmemory · context-mode)
55
+
56
+ 기존 툴은 "대화를 압축 저장/주입"까지만 한다. 본 프로젝트의 wedge:
57
+
58
+ | | 본 프로젝트 | 기존 툴 |
59
+ |---|---|---|
60
+ | 검증 | **설치 패키지를 직접 뜯어 버전-정확** (환각 0) | 대화 요약 저장 |
61
+ | 학습 | **점수형 Reflect 자가교정** (틀린 lesson 도태) | 없음 |
62
+
63
+ 플러밍(훅·자동감지·멀티플랫폼)은 prior art 패턴을 차용하고, 시간은 위 둘에 집중.
64
+
65
+ ---
66
+
67
+ ## 멀티플랫폼 — 자동감지 + 등급별 통합
68
+
69
+ 설치기 `uvx qwen-memory init`이 설정경로를 스캔해 깔린 플랫폼을 감지하고, 대화형으로 적용 대상을
70
+ 고른 뒤 등급별로 와이어링한다. 등급:
71
+
72
+ ```
73
+ TIER 1 훅 풀루프(자동주입+수확) ← Claude Code · Gemini CLI · Cursor · Copilot CLI · Kiro
74
+ TIER 2 MCP recall을 MCP 툴 노출 ← Zed · OpenCode · VS Code Copilot · JetBrains ...
75
+ TIER 3 룰 AGENTS.md 정적 포인터 ← Aider · Cline · Goose · Warp ...
76
+ ```
77
+
78
+ 해커톤 데모는 **Claude Code(Tier1)** 레퍼런스로 풀루프를 완성형으로 시연.
79
+
80
+ ---
81
+
82
+ ## Qwen 모델 배분 (비종속, Qwen 기본 권장)
83
+
84
+ | 용도 | 모델 |
85
+ |---|---|
86
+ | 실수 후보 추출 (대량) | `qwen-turbo` |
87
+ | 검증/lesson 합성 (+웹서치) | `qwen-plus` (`enable_search`) |
88
+ | 회상 재정렬 | `qwen3-rerank` |
89
+ | L2 키워드 검색 | LLM 미사용 (FTS5) |
90
+
91
+ **Qwen 쓰면 풀스택, 타 프로바이더는 코어(rerank/웹서치 차등).**
92
+ **API**: OpenAI 호환 — `base_url=https://dashscope-intl.aliyuncs.com/compatible-mode/v1`
93
+
94
+ ---
95
+
96
+ ## 심사 기준 매핑
97
+
98
+ | 심사 기준 | 구현 |
99
+ |---|---|
100
+ | ① 효율 저장/검색 | L2 FTS5(임베딩 0) + L3 점수 랭킹 + qwen3-rerank |
101
+ | ② 적시 망각 | 모순 stale + 점수 감쇠 archive + 용량 통합 |
102
+ | ③ 제한 컨텍스트 회상 | L1 토큰캡 + rerank top-K + 세션당 1회 주입 |
103
+ | **increasingly accurate** | 패키지-검증 + Reflect success/fail 점수 교정 |
104
+
105
+ ---
106
+
107
+ ## 빌드 단계
108
+
109
+ - [x] **P1** — SQLite+FTS5 스키마, lesson CRUD/검색 (L2/L3) — #2 #3
110
+ - [x] **P2** — Claude Code 어댑터: SessionStart/UserPromptSubmit 주입 (세션당 1회) — #5 #6 #7
111
+ - [x] **P3** — PreCompact 수확 → Verifier(패키지 뜯기 A) → lesson 합성 — #8 #9
112
+ - [x] **P4** — Reflect 점수 루프 + 웹서치 폴백(B) *(차별화 핵심)* — #4 #10 #11
113
+ - [x] **P5** — 데모 시나리오 + confidence 시각화 — #12
114
+ - [~] **P6** — 설치기: Claude Code(Tier1) 훅 와이어링 + launchd 데몬 완료 / 멀티플랫폼 자동감지·대화형은 다음
115
+
116
+ > 코어(P1~P5) 구현 완료 — `uv run pytest` 51 passed, `uv run python demo/run_demo.py`로 크로스세션 학습 데모 실행.
117
+
118
+ ---
119
+
120
+ ## 실사용 설치 (Claude Code)
121
+
122
+ **PyPI (권장)** — 레포 클론 없이:
123
+ ```bash
124
+ uv tool install qwen-memory-agent # 또는 pipx install qwen-memory-agent
125
+ qmem install # 훅 와이어링 + 데몬 기동
126
+ # ~/.qmem/.env 에 QWEN_API_KEY 입력 후: qmem install 재실행(또는 데몬 재기동)
127
+ ```
128
+ 명령: `qmem install` / `qmem uninstall` / `qmem status` / `qmem daemon` / `qmem hook`
129
+
130
+ **레포에서(개발)** — 원스크립트:
131
+ ```bash
132
+ git clone https://github.com/Mrbaeksang/qwen-memory-agent && cd qwen-memory-agent
133
+ cp .env.example .env # QWEN_API_KEY 입력
134
+ ./install.sh # uv sync + qmem install (idempotent)
135
+ ```
136
+
137
+ 제거: `qmem uninstall` (또는 `./uninstall.sh`). 메모리 완전삭제는 `rm -rf ~/.qmem`.
138
+
139
+ 데몬은 `127.0.0.1:8787`, 루트 메모리는 `~/.qmem/mem.db`. 이후 모든 Claude Code 세션에서
140
+ SessionStart/UserPromptSubmit 시 관련 교정이 자동 주입되고, PreCompact 시 실수가 수확·검증된다.
141
+ LLM 키는 프로젝트 `.env`(`QWEN_API_KEY`)에서 로드한다. (현재 macOS/launchd 기준)
142
+
143
+ ---
144
+
145
+ ## 데모 시나리오
146
+
147
+ 1. **세션 1 (Claude Code)**: AI가 SQLAlchemy 2.0 async에서 sync Session 사용 → asyncpg
148
+ `another operation in progress` 에러 → compact가 수확 → 설치된 `sqlalchemy==2.x`를 뜯어
149
+ 정답(AsyncSession+savepoint) 검증 → **lesson 저장**
150
+ 2. **재시작(크로스세션) → 세션 2**: 같은 작업 → SessionStart가 lesson 자동 주입 →
151
+ AI가 처음부터 올바르게 → **에러 0**
152
+ 3. 옛 lesson이 틀린 것으로 판명(또 터짐) → fail++ → confidence 하락 → **stale 도태**
153
+ 4. confidence 막대 시각화 → "학습 중" 증명
154
+
155
+ ---
156
+
157
+ ## 참고
158
+
159
+ - omp 메모리 설계: https://github.com/can1357/oh-my-pi/blob/main/docs/memory.md
160
+ - Hermes Agent: https://yuv.ai/blog/hermes-agent
161
+ - prior art: [claude-mem](https://github.com/thedotmack/claude-mem) · [agentmemory](https://github.com/rohitg00/agentmemory) · [context-mode](https://github.com/mksglu/context-mode) · [ruler](https://github.com/intellectronica/ruler)
162
+ - "Hindsight is 20/20" (arxiv 2512.12818): https://arxiv.org/abs/2512.12818
163
+ - Qwen Cloud Hackathon: https://qwencloud-hackathon.devpost.com/