heraspec 0.1.12 → 0.1.14

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 (129) hide show
  1. package/LICENSE +22 -22
  2. package/README.md +188 -103
  3. package/bin/heraspec.js +4805 -1122
  4. package/bin/heraspec.js.map +4 -4
  5. package/dist/core/templates/skills/CHANGELOG.md +117 -117
  6. package/dist/core/templates/skills/README-template.md +58 -58
  7. package/dist/core/templates/skills/README.md +38 -38
  8. package/dist/core/templates/skills/content-optimization-skill.md +104 -104
  9. package/dist/core/templates/skills/data/design-systems.csv +54 -0
  10. package/dist/core/templates/skills/data/pages-proposed.csv +21 -21
  11. package/dist/core/templates/skills/data/pages.csv +9 -9
  12. package/dist/core/templates/skills/data/typography.csv +57 -57
  13. package/dist/core/templates/skills/deploy-documentation-skill.md +408 -0
  14. package/dist/core/templates/skills/design-system-skill.md +176 -0
  15. package/dist/core/templates/skills/documents/templates/documentation-landing-page.html +63 -63
  16. package/dist/core/templates/skills/documents/templates/documentation.html +49 -49
  17. package/dist/core/templates/skills/documents/templates/landing-script.js +38 -38
  18. package/dist/core/templates/skills/documents/templates/landing-style.css +158 -158
  19. package/dist/core/templates/skills/documents/templates/script.js +56 -56
  20. package/dist/core/templates/skills/documents/templates/style.css +155 -155
  21. package/dist/core/templates/skills/documents/templates/technical-doc-template.md +16 -16
  22. package/dist/core/templates/skills/documents/templates/user-guide-template.md +16 -16
  23. package/dist/core/templates/skills/documents-skill.md +104 -104
  24. package/dist/core/templates/skills/e2e-test-skill.md +119 -119
  25. package/dist/core/templates/skills/git-embed-skill.md +57 -0
  26. package/dist/core/templates/skills/integration-test-skill.md +118 -118
  27. package/dist/core/templates/skills/knowledge/README.md +63 -0
  28. package/dist/core/templates/skills/knowledge/design-systems/airbnb/DESIGN.md +246 -0
  29. package/dist/core/templates/skills/knowledge/design-systems/airtable/DESIGN.md +89 -0
  30. package/dist/core/templates/skills/knowledge/design-systems/apple/DESIGN.md +313 -0
  31. package/dist/core/templates/skills/knowledge/design-systems/bmw/DESIGN.md +180 -0
  32. package/dist/core/templates/skills/knowledge/design-systems/cal/DESIGN.md +259 -0
  33. package/dist/core/templates/skills/knowledge/design-systems/claude/DESIGN.md +312 -0
  34. package/dist/core/templates/skills/knowledge/design-systems/clay/DESIGN.md +304 -0
  35. package/dist/core/templates/skills/knowledge/design-systems/clickhouse/DESIGN.md +281 -0
  36. package/dist/core/templates/skills/knowledge/design-systems/cohere/DESIGN.md +266 -0
  37. package/dist/core/templates/skills/knowledge/design-systems/coinbase/DESIGN.md +129 -0
  38. package/dist/core/templates/skills/knowledge/design-systems/composio/DESIGN.md +307 -0
  39. package/dist/core/templates/skills/knowledge/design-systems/cursor/DESIGN.md +309 -0
  40. package/dist/core/templates/skills/knowledge/design-systems/elevenlabs/DESIGN.md +265 -0
  41. package/dist/core/templates/skills/knowledge/design-systems/expo/DESIGN.md +281 -0
  42. package/dist/core/templates/skills/knowledge/design-systems/figma/DESIGN.md +220 -0
  43. package/dist/core/templates/skills/knowledge/design-systems/framer/DESIGN.md +246 -0
  44. package/dist/core/templates/skills/knowledge/design-systems/hashicorp/DESIGN.md +278 -0
  45. package/dist/core/templates/skills/knowledge/design-systems/ibm/DESIGN.md +332 -0
  46. package/dist/core/templates/skills/knowledge/design-systems/index.json +72 -0
  47. package/dist/core/templates/skills/knowledge/design-systems/intercom/DESIGN.md +146 -0
  48. package/dist/core/templates/skills/knowledge/design-systems/kraken/DESIGN.md +125 -0
  49. package/dist/core/templates/skills/knowledge/design-systems/linear.app/DESIGN.md +367 -0
  50. package/dist/core/templates/skills/knowledge/design-systems/lovable/DESIGN.md +298 -0
  51. package/dist/core/templates/skills/knowledge/design-systems/minimax/DESIGN.md +257 -0
  52. package/dist/core/templates/skills/knowledge/design-systems/mintlify/DESIGN.md +326 -0
  53. package/dist/core/templates/skills/knowledge/design-systems/miro/DESIGN.md +108 -0
  54. package/dist/core/templates/skills/knowledge/design-systems/mistral.ai/DESIGN.md +261 -0
  55. package/dist/core/templates/skills/knowledge/design-systems/mongodb/DESIGN.md +266 -0
  56. package/dist/core/templates/skills/knowledge/design-systems/notion/DESIGN.md +309 -0
  57. package/dist/core/templates/skills/knowledge/design-systems/nvidia/DESIGN.md +293 -0
  58. package/dist/core/templates/skills/knowledge/design-systems/ollama/DESIGN.md +267 -0
  59. package/dist/core/templates/skills/knowledge/design-systems/opencode.ai/DESIGN.md +281 -0
  60. package/dist/core/templates/skills/knowledge/design-systems/pinterest/DESIGN.md +230 -0
  61. package/dist/core/templates/skills/knowledge/design-systems/posthog/DESIGN.md +256 -0
  62. package/dist/core/templates/skills/knowledge/design-systems/raycast/DESIGN.md +268 -0
  63. package/dist/core/templates/skills/knowledge/design-systems/replicate/DESIGN.md +261 -0
  64. package/dist/core/templates/skills/knowledge/design-systems/resend/DESIGN.md +303 -0
  65. package/dist/core/templates/skills/knowledge/design-systems/revolut/DESIGN.md +185 -0
  66. package/dist/core/templates/skills/knowledge/design-systems/runwayml/DESIGN.md +244 -0
  67. package/dist/core/templates/skills/knowledge/design-systems/sanity/DESIGN.md +357 -0
  68. package/dist/core/templates/skills/knowledge/design-systems/sentry/DESIGN.md +262 -0
  69. package/dist/core/templates/skills/knowledge/design-systems/spacex/DESIGN.md +194 -0
  70. package/dist/core/templates/skills/knowledge/design-systems/spotify/DESIGN.md +246 -0
  71. package/dist/core/templates/skills/knowledge/design-systems/stripe/DESIGN.md +322 -0
  72. package/dist/core/templates/skills/knowledge/design-systems/supabase/DESIGN.md +255 -0
  73. package/dist/core/templates/skills/knowledge/design-systems/superhuman/DESIGN.md +252 -0
  74. package/dist/core/templates/skills/knowledge/design-systems/together.ai/DESIGN.md +263 -0
  75. package/dist/core/templates/skills/knowledge/design-systems/uber/DESIGN.md +295 -0
  76. package/dist/core/templates/skills/knowledge/design-systems/vercel/DESIGN.md +310 -0
  77. package/dist/core/templates/skills/knowledge/design-systems/voltagent/DESIGN.md +323 -0
  78. package/dist/core/templates/skills/knowledge/design-systems/warp/DESIGN.md +253 -0
  79. package/dist/core/templates/skills/knowledge/design-systems/webflow/DESIGN.md +92 -0
  80. package/dist/core/templates/skills/knowledge/design-systems/wise/DESIGN.md +173 -0
  81. package/dist/core/templates/skills/knowledge/design-systems/x.ai/DESIGN.md +257 -0
  82. package/dist/core/templates/skills/knowledge/design-systems/zapier/DESIGN.md +328 -0
  83. package/dist/core/templates/skills/knowledge/frameworks/php/codeigniter/rise-cms/profile.json +27 -0
  84. package/dist/core/templates/skills/knowledge/frameworks/php/codeigniter/rise-cms/structure.md +137 -0
  85. package/dist/core/templates/skills/knowledge/frameworks/php/laravel/botble/profile.json +39 -0
  86. package/dist/core/templates/skills/knowledge/frameworks/php/laravel/botble/structure.md +208 -0
  87. package/dist/core/templates/skills/knowledge/frameworks/php/wordpress/core/profile.json +51 -0
  88. package/dist/core/templates/skills/knowledge/frameworks/php/wordpress/core/structure.md +369 -0
  89. package/dist/core/templates/skills/knowledge/index.json +65 -0
  90. package/dist/core/templates/skills/module-codebase-skill.md +110 -110
  91. package/dist/core/templates/skills/plugin-directory-skill.md +396 -396
  92. package/dist/core/templates/skills/project-memory-skill.md +222 -0
  93. package/dist/core/templates/skills/project-memory-skill.vi.md +223 -0
  94. package/dist/core/templates/skills/scripts/CODE_EXPLANATION.md +394 -394
  95. package/dist/core/templates/skills/scripts/SEARCH_ALGORITHMS_COMPARISON.md +421 -421
  96. package/dist/core/templates/skills/scripts/SEARCH_MODES_GUIDE.md +238 -238
  97. package/dist/core/templates/skills/scripts/__pycache__/core.cpython-311.pyc +0 -0
  98. package/dist/core/templates/skills/scripts/core.py +391 -385
  99. package/dist/core/templates/skills/scripts/search.py +1 -1
  100. package/dist/core/templates/skills/smart-explore-skill.md +141 -0
  101. package/dist/core/templates/skills/sourcecode-analyzer-skill.md +210 -0
  102. package/dist/core/templates/skills/sourcecode-analyzer-skill.vi.md +210 -0
  103. package/dist/core/templates/skills/suggestion-skill.md +118 -118
  104. package/dist/core/templates/skills/templates/accessibility-checklist.md +40 -40
  105. package/dist/core/templates/skills/templates/example-prompt-full-theme.md +333 -333
  106. package/dist/core/templates/skills/templates/page-types-guide.md +338 -338
  107. package/dist/core/templates/skills/templates/pages-proposed-summary.md +273 -273
  108. package/dist/core/templates/skills/templates/pre-delivery-checklist.md +42 -42
  109. package/dist/core/templates/skills/templates/prompt-template-full-theme.md +313 -313
  110. package/dist/core/templates/skills/templates/responsive-design.md +40 -40
  111. package/dist/core/templates/skills/ui-ux-skill.md +595 -584
  112. package/dist/core/templates/skills/unit-test-skill.md +111 -111
  113. package/dist/core/templates/skills/ux-element/templates/Controller.php +50 -50
  114. package/dist/core/templates/skills/ux-element/templates/Shortcode.php +23 -23
  115. package/dist/core/templates/skills/ux-element/templates/Template.html +20 -20
  116. package/dist/core/templates/skills/ux-element/templates/Thumbnail.svg +8 -8
  117. package/dist/core/templates/skills/ux-element/templates/View.php +21 -21
  118. package/dist/core/templates/skills/ux-element-skill.md +83 -83
  119. package/dist/core/templates/skills/wordpress-plugin-check-skill.md +151 -76
  120. package/dist/core/templates/skills/wordpress-plugin-standard/templates/admin-dashboard.php +47 -47
  121. package/dist/core/templates/skills/wordpress-plugin-standard/templates/admin-settings.php +60 -60
  122. package/dist/core/templates/skills/wordpress-plugin-standard/templates/assets/admin-css.css +22 -22
  123. package/dist/core/templates/skills/wordpress-plugin-standard/templates/assets/admin-js.js +15 -15
  124. package/dist/core/templates/skills/wordpress-plugin-standard/templates/plugin-main.php +169 -169
  125. package/dist/core/templates/skills/wordpress-plugin-standard/templates/readme.txt +41 -41
  126. package/dist/core/templates/skills/wordpress-plugin-standard/templates/uninstall.php +21 -21
  127. package/dist/core/templates/skills/wordpress-plugin-standard-skill.md +100 -100
  128. package/dist/index.js +4068 -278
  129. package/package.json +75 -72
@@ -0,0 +1,222 @@
1
+ ---
2
+ name: project-memory
3
+ description: Complementary project memory system for AI agents. Records observations, decisions, and session summaries to maintain context across development sessions. Prevents duplicate work, tracks architectural decisions, and enables token-efficient context retrieval.
4
+ projectType: all
5
+ ---
6
+
7
+ # Project Memory Skill
8
+
9
+ ## Purpose
10
+
11
+ Enable AI agents to maintain **persistent project context** across sessions using a complementary (non-intrusive) approach. The memory system records what was done, what was learned, and what decisions were made — so future sessions start with relevant context instead of re-reading the entire codebase.
12
+
13
+ ## When to Use
14
+
15
+ - **Before implementing a new feature**: Search memory to check if similar work was done before
16
+ - **After completing a significant task**: Log an observation to record what was done
17
+ - **At the end of a session**: Summarize the session for future reference
18
+ - **When starting a complex session**: Read context to understand project history
19
+
20
+ ## Complementary Approach
21
+
22
+ > **This skill is COMPLEMENTARY, not mandatory.** The AI agent uses memory WHEN USEFUL, not at every step.
23
+ >
24
+ > - Simple tasks (fix typo, format code): Skip memory entirely → 0 token overhead
25
+ > - Complex tasks (new feature, architecture change): Use memory → save 10-30x tokens vs re-reading code
26
+
27
+ ## Available Commands
28
+
29
+ ### 1. Log an Observation (Post-Task)
30
+ Record what was done after completing a significant task:
31
+
32
+ ```bash
33
+ heraspec memory log \
34
+ --type <decision|bugfix|feature|refactor|discovery|change> \
35
+ --title "Short descriptive title" \
36
+ --narrative "Detailed description of what was done and why" \
37
+ --concepts "tag1,tag2,tag3" \
38
+ --files-modified "src/file1.ts,src/file2.ts"
39
+ ```
40
+
41
+ **Observation types:**
42
+ | Type | Icon | When to Use |
43
+ |------|------|------------|
44
+ | `decision` | ⚖️ | Architecture or design decisions with rationale |
45
+ | `bugfix` | 🔴 | Bug fixes with root cause |
46
+ | `feature` | 🟢 | New feature implementations |
47
+ | `refactor` | 🔄 | Code restructuring or optimization |
48
+ | `discovery` | 🔵 | Important findings about codebase or behavior |
49
+ | `change` | ✅ | General code changes |
50
+
51
+ ### 2. Search Memory (Pre-Implementation)
52
+ Check if related work exists before implementing something new:
53
+
54
+ ```bash
55
+ heraspec memory search "authentication middleware"
56
+ heraspec memory search --type feature --concepts "auth,login"
57
+ heraspec memory search --id 42 # Get full details of observation #42
58
+ ```
59
+
60
+ ### 3. Generate Context (Session Start)
61
+ Get a summary of recent project activity:
62
+
63
+ ```bash
64
+ heraspec memory context # Print to stdout
65
+ heraspec memory context --output file # Write to heraspec/memory/context.md
66
+ ```
67
+
68
+ ### 4. Summarize Session (Session End)
69
+ Record what was accomplished in this session:
70
+
71
+ ```bash
72
+ heraspec memory summarize \
73
+ --request "What the user asked for" \
74
+ --completed "What was done" \
75
+ --learned "Key insights discovered" \
76
+ --next-steps "What remains to be done" \
77
+ --files-edited "src/file1.ts,src/file2.ts"
78
+ ```
79
+
80
+ ### 5. View Status
81
+ Check memory statistics:
82
+
83
+ ```bash
84
+ heraspec memory status # Observation count, top concepts, top files
85
+ heraspec memory timeline # Chronological view of activity
86
+ ```
87
+
88
+ ### 6. Token Analytics Report
89
+ View detailed token usage vs savings comparison per project:
90
+
91
+ ```bash
92
+ heraspec memory analytics # Table + chart of token economics
93
+ heraspec memory analytics --history # Includes 13 latest database size changes
94
+ ```
95
+
96
+ Output includes:
97
+ - **Table**: Project name, Operations count, Tokens With Memory, Tokens Without Memory, Savings %, **DB Size**
98
+ - **Bar Chart**: Visual comparison of tokens avoided per project
99
+ - **Totals**: Aggregated savings across all projects
100
+ - **History (Optional)**: A chronological delta chart of how the `.db` file size has changed over time.
101
+
102
+ ### 7. Maintenance
103
+ ```bash
104
+ heraspec memory prune 90 # Delete observations older than 90 days
105
+ ```
106
+
107
+ ## Workflow for AI Agents
108
+
109
+ ### When to Use Memory (Decision Tree)
110
+
111
+ ```
112
+ Receive task from user
113
+ ├── Is it a simple/trivial task? → Skip memory, just do it
114
+ ├── Is it a new feature or significant change?
115
+ │ ├── Search memory: "heraspec memory search <relevant keywords>"
116
+ │ ├── Results found? → Read relevant observations, avoid duplicating work
117
+ │ └── No results? → Proceed normally
118
+ ├── After completing the task:
119
+ │ ├── Was it significant? → Log observation
120
+ │ └── Was it trivial? → Skip logging
121
+ └── End of session?
122
+ └── Multiple tasks completed? → Create session summary
123
+ ```
124
+
125
+ ### Key Principles
126
+
127
+ 1. **Don't force it**: Only use memory when it genuinely saves time or prevents mistakes
128
+ 2. **Quality over quantity**: One detailed observation is better than ten shallow ones
129
+ 3. **Concepts are crucial**: Good concept tags (`auth`, `database`, `api`, `ui`) make search effective
130
+ 4. **Files matter**: Recording which files were modified helps future agents navigate
131
+
132
+ ## Configuration
133
+
134
+ Memory configuration is stored in `heraspec/memory/config.json`:
135
+
136
+ ```json
137
+ {
138
+ "totalObservationCount": 50,
139
+ "fullObservationCount": 5,
140
+ "sessionCount": 5,
141
+ "maxTokens": 6000,
142
+ "showLastSummary": true
143
+ }
144
+ ```
145
+
146
+ ## Token Economics
147
+
148
+ | Action | Token Cost | Token Savings |
149
+ |--------|-----------|---------------|
150
+ | Read context | ~2,000-4,000 | vs ~50,000-120,000 re-reading codebase |
151
+ | Search memory | ~500-1,000 | vs ~5,000-15,000 duplicate implementation |
152
+ | Log observation | ~200-500 | Investment for future sessions |
153
+ | Smart explore (outline) | ~1,000-2,000 | vs ~12,000+ full file read |
154
+
155
+ To view a live analytics dashboard of token savings, run:
156
+ ```bash
157
+ heraspec memory analytics
158
+ ```
159
+
160
+ ## Bootstrapping Existing Projects
161
+
162
+ If you are adding the `project-memory` skill to an older project that already has historical specs and changes (in `heraspec/specs/` and `heraspec/archives/`), you can bootstrap the memory system without writing any code.
163
+
164
+ Simply provide this prompt to the AI agent **once**:
165
+
166
+ ```text
167
+ Use the project-memory skill.
168
+ Please bootstrap the project memory from all our existing specs and archives.
169
+ Open the folders: heraspec/specs/ and heraspec/archives/
170
+ For EVERY sub-folder/file inside, read it to understand the context, then run:
171
+
172
+ heraspec memory log \
173
+ --type feature \
174
+ --title "[Extract spec/change title]" \
175
+ --narrative "[Short summary of what was implemented]" \
176
+ --concepts "[Extract key tags/technologies]" \
177
+ --files-modified "[Extract affected files]"
178
+
179
+ Repeat this until all old specs are migrated into the memory system.
180
+ ```
181
+
182
+ Alternatively, use the built-in **CLI command** (faster, no AI tokens spent):
183
+ ```bash
184
+ heraspec memory bootstrap # Interactive — prompts for confirmation
185
+ heraspec memory bootstrap --yes # Non-interactive — auto-confirm
186
+ ```
187
+
188
+ This command will automatically scan `heraspec/specs/`, `heraspec/archives/`, and `heraspec/changes/`, extract title/narrative/files from each markdown spec, and insert them into the memory database.
189
+
190
+ > **Note:** Duplicate titles are automatically skipped, so running the command multiple times is safe.
191
+
192
+ ## Agent-Triggered Reporting
193
+
194
+ When the user asks the AI agent to view memory reports, analytics, or token savings — the agent should run the CLI command and return the output:
195
+
196
+ ```text
197
+ User: "Show me the memory analytics report"
198
+ User: "How many tokens has the memory system saved?"
199
+ User: "Give me a token usage report"
200
+ ```
201
+
202
+ **Agent action:** Execute the following command and display the output to the user:
203
+ ```bash
204
+ heraspec memory analytics
205
+ ```
206
+
207
+ For a quick status check:
208
+ ```bash
209
+ heraspec memory status
210
+ ```
211
+
212
+ For a timeline view:
213
+ ```bash
214
+ heraspec memory timeline
215
+ ```
216
+
217
+ ## Limitations
218
+
219
+ - Memory is project-local (stored in `heraspec/memory/`)
220
+ - Requires `better-sqlite3` npm package
221
+ - FTS5 search is keyword-based, not semantic
222
+ - Agent must decide when to use memory (complementary approach)
@@ -0,0 +1,223 @@
1
+ ---
2
+ name: project-memory
3
+ description: Hệ thống bộ nhớ dự án bổ trợ cho AI agent. Ghi lại các quan sát, quyết định và tóm tắt phiên làm việc để duy trì ngữ cảnh giữa các phiên phát triển. Ngăn ngừa việc làm trùng lặp, theo dõi các quyết định kiến trúc và cho phép truy xuất ngữ cảnh tối ưu token.
4
+ projectType: all
5
+ ---
6
+
7
+ # Project Memory Skill
8
+
9
+ ## Mục đích
10
+
11
+ Cho phép AI agent duy trì **ngữ cảnh dự án bền vững** qua các phiên làm việc bằng cách tiếp cận bổ trợ (không can thiệp). Hệ thống bộ nhớ ghi lại những gì đã làm, đã học được và những quyết định đã đưa ra — để các phiên trong tương lai bắt đầu với ngữ cảnh có liên quan thay vì phải đọc lại toàn bộ mã nguồn (codebase).
12
+
13
+ ## Khi nào nên dùng
14
+
15
+ - **Trước khi triển khai tính năng mới**: Tìm kiếm bộ nhớ xem có công việc tương tự nào đã làm trước đó không.
16
+ - **Sau khi hoàn thành một nhiệm vụ quan trọng**: Ghi lại quan sát (observation) để lưu lại những gì đã thực hiện.
17
+ - **Vào cuối một phiên làm việc (session)**: Tóm tắt phiên làm việc để tham khảo sau này.
18
+ - **Khi bắt đầu một phiên làm việc phức tạp**: Đọc ngữ cảnh để hiểu lịch sử của dự án.
19
+
20
+ ## Cách tiếp cận bổ trợ (Complementary Approach)
21
+
22
+ > **Skill này mang tính BỔ TRỢ, không bắt buộc.** AI agent sử dụng bộ nhớ KHI HỮU ÍCH, không phải ở mọi bước.
23
+ >
24
+ > - Nhiệm vụ đơn giản (sửa lỗi chính tả, format code): Bỏ qua bộ nhớ hoàn toàn → tốn 0 token.
25
+ > - Nhiệm vụ phức tạp (tính năng mới, thay đổi kiến trúc): Dùng bộ nhớ → tiết kiệm 10-30x token so với việc đọc lại codebase.
26
+
27
+ ## Các Lệnh Có Sẵn
28
+
29
+ ### 1. Ghi lại quan sát (Log an Observation - Post-Task)
30
+ Ghi lại những gì đã làm sau khi hoàn thành một nhiệm vụ quan trọng:
31
+
32
+ ```bash
33
+ heraspec memory log \
34
+ --type <decision|bugfix|feature|refactor|discovery|change> \
35
+ --title "Tiêu đề mô tả ngắn gọn" \
36
+ --narrative "Mô tả chi tiết về những gì đã làm và lý do" \
37
+ --concepts "tag1,tag2,tag3" \
38
+ --files-modified "src/file1.ts,src/file2.ts"
39
+ ```
40
+
41
+ **Các loại quan sát (Observation types):**
42
+ | Loại (Type) | Icon | Khi nào dùng |
43
+ |------|------|------------|
44
+ | `decision` | ⚖️ | Quyết định về kiến trúc hoặc thiết kế kèm theo lý do |
45
+ | `bugfix` | 🔴 | Sửa lỗi kèm theo nguyên nhân gốc rễ |
46
+ | `feature` | 🟢 | Triển khai tính năng mới |
47
+ | `refactor` | 🔄 | Tái cấu trúc hoặc tối ưu hóa mã nguồn |
48
+ | `discovery` | 🔵 | Những phát hiện quan trọng về codebase hoặc hành vi |
49
+ | `change` | ✅ | Các thay đổi code chung chung |
50
+
51
+ ### 2. Tìm kiếm trong bộ nhớ (Search Memory - Pre-Implementation)
52
+ Kiểm tra xem các công việc liên quan có tồn tại không trước khi triển khai tính năng mới:
53
+
54
+ ```bash
55
+ heraspec memory search "authentication middleware"
56
+ heraspec memory search --type feature --concepts "auth,login"
57
+ heraspec memory search --id 42 # Lấy chi tiết đầy đủ của observation #42
58
+ ```
59
+
60
+ ### 3. Tạo ngữ cảnh (Generate Context - Session Start)
61
+ Nhận bản tóm tắt các hoạt động gần đây của dự án:
62
+
63
+ ```bash
64
+ heraspec memory context # In ra stdout
65
+ heraspec memory context --output file # Ghi vào file heraspec/memory/context.md
66
+ ```
67
+
68
+ ### 4. Tóm tắt phiên làm việc (Summarize Session - Session End)
69
+ Ghi lại những thành quả đạt được trong phiên làm việc này:
70
+
71
+ ```bash
72
+ heraspec memory summarize \
73
+ --request "Người dùng đã yêu cầu gì?" \
74
+ --completed "Những gì đã được thực hiện?" \
75
+ --learned "Những hiểu biết (insights) quan trọng đã phát hiện" \
76
+ --next-steps "Những việc còn lại cần làm" \
77
+ --files-edited "src/file1.ts,src/file2.ts"
78
+ ```
79
+
80
+ ### 5. Xem trạng thái (View Status)
81
+ Kiểm tra số liệu thống kê bộ nhớ:
82
+
83
+ ```bash
84
+ heraspec memory status # Số lượng observation, top concepts, top files
85
+ heraspec memory timeline # Xem hoạt động theo thứ tự thời gian
86
+ ```
87
+
88
+ ### 6. Báo cáo Phân tích Token (Token Analytics Report)
89
+ Xem bảng so sánh chi tiết token đã dùng và tiết kiệm theo từng dự án:
90
+
91
+ ```bash
92
+ heraspec memory analytics # Bảng + biểu đồ về hiệu quả token
93
+ heraspec memory analytics --history # Đính kèm thêm 13 mốc thời gian file DB thay đổi kích thước
94
+ ```
95
+
96
+ Kết quả bao gồm:
97
+ - **Bảng (Table)**: Tên dự án, Số thao tác, Token khi dùng Memory, Token khi không dùng Memory, % Tiết kiệm, **Kích thước DB**
98
+ - **Biểu đồ thanh (Bar Chart)**: So sánh trực quan số token đã tránh được cho mỗi dự án
99
+ - **Tổng cộng (Totals)**: Tổng hợp tiết kiệm trên tất cả dự án
100
+ - **Lịch sử (History - Tùy chọn)**: Bảng thời gian (Chronological delta chart) cho thấy file `.db` đã thay đổi kích thước ra sao qua các lần cập nhật.
101
+
102
+ ### 7. Bảo trì (Maintenance)
103
+ ```bash
104
+ heraspec memory prune 90 # Xóa các observation cũ hơn 90 ngày
105
+ ```
106
+
107
+ ## Quy trình làm việc cho AI Agent
108
+
109
+ ### Khi nào nên dùng Memory (Cây Quyết Định)
110
+
111
+ ```
112
+ Nhận nhiệm vụ từ user
113
+ ├── Nhiệm vụ đơn giản/nhỏ lẻ? → Bỏ qua bộ nhớ, làm luôn
114
+ ├── Tính năng mới hay thay đổi lớn?
115
+ │ ├── Tìm kiếm bộ nhớ: "heraspec memory search <từ khóa>"
116
+ │ ├── Tìm thấy kết quả? → Đọc observation liên quan, tránh làm lại từ đầu
117
+ │ └── Không có kết quả? → Tiến hành bình thường
118
+ ├── Sau khi hoàn thành nhiệm vụ:
119
+ │ ├── Quan trọng/Lớn? → Ghi lại observation
120
+ │ └── Nhỏ lẻ? → Bỏ qua ghi log
121
+ └── Kết thúc phiên làm việc?
122
+ └── Đã hoàn thành nhiều nhiệm vụ? → Tạo tóm tắt phiên (session summary)
123
+ ```
124
+
125
+ ### Các Nguyên Tắc Chính
126
+
127
+ 1. **Đừng gượng ép**: Chỉ sử dụng bộ nhớ khi nó thực sự giúp tiết kiệm thời gian hoặc tránh sai sót.
128
+ 2. **Chất lượng hơn số lượng**: Một observation chi tiết còn hơn mười cái hời hợt.
129
+ 3. **Concept là cốt lõi**: Việc gắn thẻ concept chuẩn (`auth`, `database`, `api`, `ui`) giúp tìm kiếm hiệu quả.
130
+ 4. **File cũng rất quan trọng**: Ghi lại file nào đã sửa giúp cho AI lần sau điều hướng dễ dàng hơn.
131
+
132
+ ## Cấu hình
133
+
134
+ Cấu hình bộ nhớ được lưu trữ tại `heraspec/memory/config.json`:
135
+
136
+ ```json
137
+ {
138
+ "totalObservationCount": 50,
139
+ "fullObservationCount": 5,
140
+ "sessionCount": 5,
141
+ "maxTokens": 6000,
142
+ "showLastSummary": true
143
+ }
144
+ ```
145
+
146
+ ## Tối ưu (Token Economics)
147
+
148
+ | Hành động | Chi phí Token | Token Tiết kiệm được |
149
+ |--------|-----------|---------------|
150
+ | Đọc ngữ cảnh (context) | ~2,000-4,000 | so với ~50,000-120,000 khi đọc lại codebase |
151
+ | Tìm kiếm bộ nhớ (search)| ~500-1,000 | so với ~5,000-15,000 nếu phải làm lại mã nguồn |
152
+ | Ghi lại observation | ~200-500 | Đầu tư dài hạn cho các phiên sau |
153
+ | Smart explore (outline) | ~1,000-2,000 | so với ~12,000+ nếu đọc toàn bộ file |
154
+
155
+ Để xem bảng phân tích trực tiếp về số token đã tiết kiệm, chạy:
156
+ ```bash
157
+ heraspec memory analytics
158
+ ```
159
+
160
+ ## Tích hợp dữ liệu cũ (Bootstrapping Existing Projects)
161
+
162
+ Nếu bạn vừa thêm skill `project-memory` vào một **dự án cũ** đã và đang làm việc theo quy trình HeraSpec (đã có thư mục `heraspec/specs/` và `heraspec/archives/`), bạn có thể "tích hợp" dữ liệu về bộ nhớ rất dễ dàng mà không cần lập trình thêm.
163
+
164
+ Chỉ cần gửi duy nhất một prompt sau cho AI Agent (MỘT LẦN VÀ DUY NHẤT):
165
+
166
+ ```text
167
+ Sử dụng skill project-memory.
168
+ Bạn hãy khởi tạo memory cho dự án này từ các specs và archives đã có.
169
+ Mở thư mục: heraspec/specs/ và heraspec/archives/
170
+ Với MỖI sub-folder/file có trong đó, hãy đọc lướt để hiểu nội dung, sau đó chạy lệnh:
171
+
172
+ heraspec memory log \
173
+ --type feature \
174
+ --title "[Trích xuất tên spec/change]" \
175
+ --narrative "[Tóm tắt ngắn gọn những gì đã được triển khai trong spec này]" \
176
+ --concepts "[Trích xuất các thẻ/công nghệ chính]" \
177
+ --files-modified "[Trích xuất hoặc suy thoái các file bị ảnh hưởng]"
178
+
179
+ Lặp lại việc này cho đến khi di chuyển (migrate) hoàn tất tất cả spec cũ vào hệ thống memory.
180
+ ```
181
+
182
+ Ngoài ra, có thể sử dụng **lệnh CLI có sẵn** (nhanh hơn, không tốn AI token):
183
+ ```bash
184
+ heraspec memory bootstrap # Tương tác — hỏi xác nhận trước khi chạy
185
+ heraspec memory bootstrap --yes # Không tương tác — tự động xác nhận
186
+ ```
187
+
188
+ Lệnh này sẽ tự động quét `heraspec/specs/`, `heraspec/archives/` và `heraspec/changes/`, trích xuất tiêu đề/nội dung/file từ mỗi markdown spec, rồi chèn vào cơ sở dữ liệu memory.
189
+
190
+ > **Lưu ý:** Các tiêu đề trùng lặp sẽ tự động bị bỏ qua, nên chạy lệnh nhiều lần vẫn an toàn.
191
+
192
+ ## Báo cáo do Agent kích hoạt (Agent-Triggered Reporting)
193
+
194
+ Khi user yêu cầu AI agent xem báo cáo bộ nhớ, phân tích token hoặc thống kê tiết kiệm — agent nên chạy lệnh CLI và hiển thị kết quả cho user:
195
+
196
+ ```text
197
+ User: "Cho tôi xem báo cáo phân tích memory"
198
+ User: "Hệ thống memory đã tiết kiệm bao nhiêu token?"
199
+ User: "Xem báo cáo token usage"
200
+ User: "Show me the memory analytics report"
201
+ ```
202
+
203
+ **Hành động của Agent:** Chạy lệnh sau và hiển thị kết quả cho user:
204
+ ```bash
205
+ heraspec memory analytics
206
+ ```
207
+
208
+ Để xem trạng thái nhanh:
209
+ ```bash
210
+ heraspec memory status
211
+ ```
212
+
213
+ Để xem dòng thời gian:
214
+ ```bash
215
+ heraspec memory timeline
216
+ ```
217
+
218
+ ## Hạn chế (Limitations)
219
+
220
+ - Bộ nhớ chỉ mang tính cục bộ (local) của dự án (lưu trong `heraspec/memory/`).
221
+ - Yêu cầu gói npm `better-sqlite3`.
222
+ - Tìm kiếm FTS5 là tìm kiếm dựa trên từ khóa (keyword-based), không phải theo ngữ nghĩa (semantic).
223
+ - Agent phải tự quyết định thời điểm thích hợp để sử dụng bộ nhớ (cách tiếp cận bổ trợ).