@leejungkiin/awkit 1.0.0

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 (139) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +146 -0
  3. package/VERSION +1 -0
  4. package/bin/awf.js +549 -0
  5. package/bin/awk.js +1759 -0
  6. package/core/AGENTS.md +39 -0
  7. package/core/GEMINI.md +202 -0
  8. package/core/GEMINI.md.bak +244 -0
  9. package/core/orchestrator.md +58 -0
  10. package/package.json +46 -0
  11. package/schemas/brain.schema.json +342 -0
  12. package/schemas/preferences.schema.json +95 -0
  13. package/schemas/session.schema.json +112 -0
  14. package/skill-packs/neural-memory/README.md +111 -0
  15. package/skill-packs/neural-memory/pack.json +35 -0
  16. package/skill-packs/neural-memory/schemas/brain-snapshot.json +167 -0
  17. package/skill-packs/neural-memory/skills/nm-memory-audit/SKILL.md +157 -0
  18. package/skill-packs/neural-memory/skills/nm-memory-evolution/SKILL.md +202 -0
  19. package/skill-packs/neural-memory/skills/nm-memory-intake/SKILL.md +135 -0
  20. package/skill-packs/neural-memory/skills/nm-memory-sync/SKILL.md +184 -0
  21. package/skill-packs/neural-memory/workflows/nm-import.md +73 -0
  22. package/skill-packs/neural-memory/workflows/nm-recall.md +67 -0
  23. package/skill-packs/neural-memory/workflows/nm-snapshot.md +69 -0
  24. package/skills/adaptive-language/SKILL.md +189 -0
  25. package/skills/ambient-brain/SKILL.md +314 -0
  26. package/skills/ambient-brain/brain-router.md +185 -0
  27. package/skills/ambient-brain/brain-templates.md +201 -0
  28. package/skills/auto-save/SKILL.md +223 -0
  29. package/skills/awf-adaptive-language/SKILL.md +189 -0
  30. package/skills/awf-context-help/SKILL.md +180 -0
  31. package/skills/awf-error-translator/SKILL.md +153 -0
  32. package/skills/awf-session-restore/SKILL.md +270 -0
  33. package/skills/awf-version-tracker/SKILL.md +32 -0
  34. package/skills/awf-version-tracker/scripts/snapshot.sh +22 -0
  35. package/skills/beads-manager/SKILL.md +323 -0
  36. package/skills/brainstorm-agent/SKILL.md +295 -0
  37. package/skills/context-help/SKILL.md +180 -0
  38. package/skills/error-translator/SKILL.md +153 -0
  39. package/skills/ios-engineer/SKILL.md +101 -0
  40. package/skills/memory-sync/SKILL.md +378 -0
  41. package/skills/memory-sync/memory-router.md +185 -0
  42. package/skills/memory-sync/memory-templates.md +201 -0
  43. package/skills/orchestrator/SKILL.md +193 -0
  44. package/skills/session-restore/SKILL.md +240 -0
  45. package/templates/CODEBASE.md +80 -0
  46. package/templates/brain.example.json +321 -0
  47. package/templates/preferences.example.json +21 -0
  48. package/templates/project-identity/android.json +28 -0
  49. package/templates/project-identity/backend-nestjs.json +24 -0
  50. package/templates/project-identity/expo.json +27 -0
  51. package/templates/project-identity/ios.json +27 -0
  52. package/templates/project-identity/web-nextjs.json +24 -0
  53. package/templates/session.example.json +53 -0
  54. package/templates/specs/design-template.md +166 -0
  55. package/templates/specs/requirements-template.md +65 -0
  56. package/templates/specs/tasks-template.md +132 -0
  57. package/templates/structures/android.txt +10 -0
  58. package/templates/structures/backend-nestjs.txt +6 -0
  59. package/templates/structures/expo.txt +9 -0
  60. package/templates/structures/ios.txt +9 -0
  61. package/templates/structures/web-nextjs.txt +6 -0
  62. package/templates/workflow_dual_mode_template.md +87 -0
  63. package/workflows/_uncategorized/README.md +339 -0
  64. package/workflows/_uncategorized/ads-creative.md +357 -0
  65. package/workflows/_uncategorized/ads-full-optimization.md +308 -0
  66. package/workflows/_uncategorized/ads-plan.md +247 -0
  67. package/workflows/_uncategorized/ads-user-analysis.md +337 -0
  68. package/workflows/_uncategorized/skill-health.md +35 -0
  69. package/workflows/_uncategorized/skill-rollback.md +35 -0
  70. package/workflows/ads/admob.md +62 -0
  71. package/workflows/ads/ads-analyst.md +201 -0
  72. package/workflows/ads/ads-audit.md +106 -0
  73. package/workflows/ads/ads-optimize.md +97 -0
  74. package/workflows/ads/ads-targeting.md +241 -0
  75. package/workflows/ads/adsExpert.md +160 -0
  76. package/workflows/ads/smali-ads-config.md +400 -0
  77. package/workflows/ads/smali-ads-flow.md +331 -0
  78. package/workflows/ads/smali-ads-interstitial.md +377 -0
  79. package/workflows/ads/smali-ads-native.md +382 -0
  80. package/workflows/context/auto-execution-workflow.md +291 -0
  81. package/workflows/context/auto-implement.md +211 -0
  82. package/workflows/context/codebase-sync.md +163 -0
  83. package/workflows/context/logic-reasoning-workflow.md +260 -0
  84. package/workflows/context/next.md +195 -0
  85. package/workflows/context/recap.md +212 -0
  86. package/workflows/context/save-brain.md +285 -0
  87. package/workflows/context/user-intent-analysis-workflow.md +206 -0
  88. package/workflows/expert/codeExpert.md +126 -0
  89. package/workflows/expert/debugExpert.md +136 -0
  90. package/workflows/expert/planExpert.md +112 -0
  91. package/workflows/git/cloudflare-tunnel.md +135 -0
  92. package/workflows/git/git-commit-workflow.md +75 -0
  93. package/workflows/git/hotfix.md +357 -0
  94. package/workflows/git/release-notes.md +160 -0
  95. package/workflows/git/rollback.md +52 -0
  96. package/workflows/git/smart-git-ops.md +103 -0
  97. package/workflows/lifecycle/brainstorm.md +377 -0
  98. package/workflows/lifecycle/code.md +663 -0
  99. package/workflows/lifecycle/debug.md +116 -0
  100. package/workflows/lifecycle/deploy.md +95 -0
  101. package/workflows/lifecycle/init.md +152 -0
  102. package/workflows/lifecycle/master-code-workflow.md +300 -0
  103. package/workflows/lifecycle/migration.md +196 -0
  104. package/workflows/lifecycle/plan.md +91 -0
  105. package/workflows/lifecycle/refactor.md +165 -0
  106. package/workflows/lifecycle/run.md +52 -0
  107. package/workflows/lifecycle/test.md +91 -0
  108. package/workflows/meta/customize.md +346 -0
  109. package/workflows/meta/file-protection-rules.md +129 -0
  110. package/workflows/meta/help.html +350 -0
  111. package/workflows/meta/project-identity-enforcement.md +180 -0
  112. package/workflows/mobile/app-analysis.md +64 -0
  113. package/workflows/mobile/maestro-qa-workflow.md +470 -0
  114. package/workflows/mobile/maestro-test-workflow.md +84 -0
  115. package/workflows/mobile/structure-clean-architect.md +271 -0
  116. package/workflows/mobile/turbo-mobile-build.md +190 -0
  117. package/workflows/quality/accessibility-audit.md +311 -0
  118. package/workflows/quality/audit.md +217 -0
  119. package/workflows/quality/bug-hunter.md +243 -0
  120. package/workflows/quality/code-janitor.md +209 -0
  121. package/workflows/quality/code-quality-rules.md +132 -0
  122. package/workflows/quality/performance-audit.md +343 -0
  123. package/workflows/quality/project-audit.md +61 -0
  124. package/workflows/quality/self-healing-test.md +192 -0
  125. package/workflows/quality/ui-review.md +130 -0
  126. package/workflows/quality/ux-audit.md +213 -0
  127. package/workflows/quality/visual-debug.md +34 -0
  128. package/workflows/roles/oracle.md +267 -0
  129. package/workflows/roles/product-manager-workflow.md +52 -0
  130. package/workflows/roles/qa-engineer-workflow.md +41 -0
  131. package/workflows/roles/tech-lead-workflow.md +45 -0
  132. package/workflows/roles/ui-ux-designer-workflow.md +42 -0
  133. package/workflows/roles/vibe-coding-master-workflow.md +52 -0
  134. package/workflows/ui/app-screen-analyzer.md +152 -0
  135. package/workflows/ui/create-feature.md +332 -0
  136. package/workflows/ui/create-spec-architect.md +184 -0
  137. package/workflows/ui/design-to-ui.md +308 -0
  138. package/workflows/ui/ui-first-methodology.md +279 -0
  139. package/workflows/ui/visualize.md +298 -0
@@ -0,0 +1,314 @@
1
+ ---
2
+ name: ambient-brain
3
+ description: >-
4
+ Ambient Brain Sync — AI tự động đọc/ghi brain theo context mà không cần user nhớ.
5
+ Write triggers: decisions, bug fixes, architecture, task completion.
6
+ Read triggers: session start, debug, new task, errors, similar problems.
7
+ version: 1.0.0
8
+ trigger: always
9
+ priority: high
10
+ ---
11
+
12
+ # 🧠 Ambient Brain Sync
13
+
14
+ > **Philosophy:** User không nên nhớ để lưu. AI phải tự biết lúc nào cần đọc, lúc nào cần ghi.
15
+
16
+ ---
17
+
18
+ ## Core Principle: "Ambient Memory"
19
+
20
+ ```
21
+ Traditional: User làm việc → nhớ → gõ /save-brain → AI lưu (FAIL khi quên)
22
+ Ambient: User làm việc → AI tự nhận ra ký ức quan trọng → Tự lưu & tự đọc
23
+ ```
24
+
25
+ ---
26
+
27
+ ## 📖 BRAIN READ TRIGGERS (Khi nào tự động ĐỌC)
28
+
29
+ ### R1: Session Start (LUÔN LUÔN)
30
+ **Điều kiện:** Đầu mỗi conversation mới
31
+ ```
32
+ Action:
33
+ 1. Đọc brain/session.json → Working context
34
+ 2. Đọc brain/active_plans.json → Active plan
35
+ 3. Đọc brain/decisions/ → 3 decisions gần nhất
36
+ 4. Output: Hiển thị "🧠 Brain loaded: [summary]"
37
+ ```
38
+
39
+ ### R2: New Task / Feature Work
40
+ **Điều kiện:** User mention file/feature/task cụ thể, hoặc dùng /code, /debug, /plan
41
+ ```
42
+ Patterns:
43
+ - "làm feature X", "sửa file Y", "implement Z"
44
+ - /code, /codeExpert, /debug, /debugExpert, /plan, /planExpert
45
+
46
+ Action:
47
+ 1. Query brain/decisions/ với keywords từ task
48
+ 2. Query brain/solutions/ với filename/feature name
49
+ 3. Nếu tìm thấy liên quan: "💡 Nhớ ra: [relevant context]"
50
+ 4. Inject vào working context
51
+ ```
52
+
53
+ ### R3: Error / Bug Encounter
54
+ **Điều kiện:** Error message xuất hiện trong conversation
55
+ ```
56
+ Patterns (detect any of):
57
+ - "error:", "Error:", "ERROR", "failed:", "exception"
58
+ - "không chạy", "lỗi", "crash", "bug"
59
+ - Terminal output có stack trace
60
+
61
+ Action:
62
+ 1. Extract error type/keywords
63
+ 2. Query brain/solutions/ với error pattern
64
+ 3. Nếu tìm thấy: "🔍 Đã gặp lỗi này trước: [solution summary]"
65
+ 4. Trình bày solution từ brain trước khi debug mới
66
+ ```
67
+
68
+ ### R4: Architectural Decision Needed
69
+ **Điều kiện:** User hỏi về design, approach, architecture
70
+ ```
71
+ Patterns:
72
+ - "nên dùng gì", "best approach", "how to design"
73
+ - "chọn giữa X và Y", "architecture", "pattern"
74
+
75
+ Action:
76
+ 1. Query brain/decisions/ với topic
77
+ 2. Nếu tìm thấy: "📋 Quyết định cũ: [relevant decision]"
78
+ 3. Hỏi: "Vẫn dùng approach này hay muốn thay đổi?"
79
+ ```
80
+
81
+ ### R5: Recurring Similar Problem
82
+ **Điều kiện:** Task/error giống với brain entries (keyword overlap > 2)
83
+ ```
84
+ Action:
85
+ 1. Tự động load solution từ brain
86
+ 2. Hiển thị: "🔁 Pattern quen: Đã giải quyết tương tự lúc [date]"
87
+ 3. Gợi ý dùng lại solution
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 💾 BRAIN WRITE TRIGGERS (Khi nào tự động GHI)
93
+
94
+ ### W1: Decision Made (SILENT AUTO-SAVE)
95
+ **Điều kiện:** AI hoặc user đưa ra quyết định kỹ thuật
96
+ ```
97
+ Patterns detect decision:
98
+ - "quyết định dùng...", "ta sẽ dùng...", "chọn approach..."
99
+ - "best way is...", "we'll use...", "decided to..."
100
+ - User confirm sau khi AI suggest: "ok", "được", "đồng ý", "làm vậy đi"
101
+ (nhưng chỉ sau khi AI vừa đề xuất architecture/approach)
102
+
103
+ Action (SILENT - không hỏi user):
104
+ 1. Extract: what, why, alternatives_considered
105
+ 2. Save to: brain/decisions/YYYY-MM-DD-[slug].md
106
+ 3. Update: brain/session.json với decision reference
107
+ 4. Log internally (không notify user trừ khi được hỏi)
108
+
109
+ Template:
110
+ ---
111
+ date: [ISO date]
112
+ topic: [decision topic]
113
+ decision: [what was decided]
114
+ rationale: [why this approach]
115
+ alternatives: [other options considered]
116
+ context: [feature/task this belongs to]
117
+ tags: [relevant tags]
118
+ ---
119
+ ```
120
+
121
+ ### W2: Bug Fixed / Solution Found
122
+ **Điều kiện:** Sau khi fix xong bug được confirm
123
+ ```
124
+ Patterns detect resolution:
125
+ - "works now", "fixed", "chạy rồi", "ok rồi", "xong"
126
+ - User sau khi test: "ổn rồi", "pass", "ngon"
127
+ - "solved by", "the fix was"
128
+
129
+ Action (SILENT):
130
+ 1. Capture: error_pattern, root_cause, solution_steps, files_changed
131
+ 2. Save to: brain/solutions/[error-slug]-[date].md
132
+ 3. Tag với: filename, error_type, feature
133
+
134
+ Template:
135
+ ---
136
+ date: [ISO date]
137
+ error_pattern: [what the error looked like]
138
+ root_cause: [why it happened]
139
+ solution: [how it was fixed]
140
+ files: [which files were changed]
141
+ prevent: [how to avoid in future]
142
+ tags: [file, error_type, feature]
143
+ ---
144
+ ```
145
+
146
+ ### W3: Architecture / Pattern Defined
147
+ **Điều kiện:** Sau workflow /plan, /planExpert, /brainstorm hoàn thành; hoặc spec file được tạo
148
+ ```
149
+ Action (SILENT):
150
+ 1. Capture: feature_name, tech_choices, structure, reasoning
151
+ 2. Save to: brain/decisions/arch-[feature]-[date].md
152
+ 3. Link to Bead task ID nếu có
153
+ ```
154
+
155
+ ### W4: Task Milestone Completed
156
+ **Điều kiện:** `bd update --status done` hoặc user tuyên bố xong 1 giai đoạn lớn
157
+ ```
158
+ Patterns:
159
+ - "bd update ... --status done"
160
+ - "xong phase", "hoàn thành feature", "done với X"
161
+
162
+ Action (SILENT):
163
+ 1. Capture: task_name, what_was_built, key_learnings
164
+ 2. Append to: brain/session.json → completed_milestones
165
+ 3. Nếu có learnings quan trọng → Save to brain/solutions/
166
+ ```
167
+
168
+ ### W5: Explicit Save Request
169
+ **Điều kiện:** User gõ /save-brain "title" (vẫn support manual)
170
+ ```
171
+ Action (FULL SAVE - có confirm):
172
+ 1. Synthesize toàn bộ conversation context
173
+ 2. User confirm nội dung trước khi lưu
174
+ 3. Save với rich metadata
175
+ 4. Notify: "💾 Đã lưu vào brain: [title]"
176
+ ```
177
+
178
+ ---
179
+
180
+ ## 🔄 BRAIN SYNC PROTOCOL
181
+
182
+ ### Sync Frequency
183
+ ```
184
+ IMMEDIATE (real-time):
185
+ - W1 Decision made → save trong 1 turn
186
+ - W2 Bug fixed → save ngay khi detect resolution
187
+
188
+ DEFERRED (end of workflow):
189
+ - W3 Architecture → save khi workflow hoàn thành
190
+ - W4 Task completion → save khi task đóng
191
+
192
+ PERIODIC:
193
+ - Mỗi 10 turns → Check if anything worth saving missed
194
+ - End of session → Final consolidation save
195
+ ```
196
+
197
+ ### File Structure
198
+ ```
199
+ brain/
200
+ ├── session.json # Current working state (auto-updated)
201
+ ├── active_plans.json # Plans đang active (auto-updated)
202
+ ├── decisions/
203
+ │ ├── 2026-02-22-use-sqlite.md
204
+ │ ├── 2026-02-22-arch-neural-brain.md
205
+ │ └── ...
206
+ └── solutions/
207
+ ├── 2026-02-22-fts5-error-fix.md
208
+ ├── 2026-02-22-activation-algorithm.md
209
+ └── ...
210
+ ```
211
+
212
+ ---
213
+
214
+ ## 🧭 SALIENCE SCORING (Độ quan trọng)
215
+
216
+ AI tự đánh giá trước khi lưu — chỉ lưu những gì có salience ≥ 0.5:
217
+
218
+ ```
219
+ salience_map:
220
+ architectural_decision: 0.95 # Always save
221
+ bug_fix_solution: 0.85 # Always save
222
+ tech_choice: 0.80 # Always save
223
+ pattern_discovered: 0.75 # Save if novel
224
+ task_completion: 0.60 # Save key learnings
225
+ code_snippet: 0.50 # Save if reusable
226
+ conversation_detail: 0.20 # Skip
227
+ casual_chat: 0.05 # Never save
228
+ ```
229
+
230
+ **Novelty Check:** Nếu brain đã có entry tương tự → Reinforce (tăng salience) thay vì tạo mới.
231
+
232
+ ---
233
+
234
+ ## 🔔 NOTIFICATION BEHAVIOR
235
+
236
+ ```
237
+ QUIET MODE (default):
238
+ - Silent save: Không notify
239
+ - Chỉ show indicator nhỏ: "💾" ở cuối message khi có relevant brain read
240
+
241
+ VERBOSE MODE (khi user hỏi):
242
+ - Explain what was saved/loaded
243
+ - Show brain entry preview
244
+
245
+ NEVER:
246
+ - Hỏi "Bạn có muốn lưu không?" → Chỉ lưu im lặng
247
+ - Interrupt flow để confirm save
248
+ - Spam thông báo lưu
249
+ ```
250
+
251
+ ---
252
+
253
+ ## 🧩 INTEGRATION WITH EXISTING SKILLS
254
+
255
+ ```
256
+ Runs BEFORE: session-restore (cung cấp data)
257
+ Runs AFTER: auto-save (fallback nếu ambient bỏ sót)
258
+ Works WITH: beads-manager (link brain entries với Bead IDs)
259
+ Enhances: error-translator (thêm historical context)
260
+ ```
261
+
262
+ ---
263
+
264
+ ## 📝 BRAIN QUERY ALGORITHM
265
+
266
+ Khi đọc brain, AI tự tìm kiếm theo priority:
267
+
268
+ ```
269
+ 1. Exact tag match (filename, feature_name, error_type)
270
+ 2. Keyword overlap trong content (>= 2 keywords)
271
+ 3. Same time period (cùng feature đang làm)
272
+ 4. Recent entries (< 7 ngày)
273
+
274
+ Return: Top 3 most relevant entries
275
+ Format: Inline mention, không dump toàn bộ content
276
+ ```
277
+
278
+ ---
279
+
280
+ ## ⚡ ACTIVATION EXAMPLES
281
+
282
+ ### Example 1: Auto-Read on Error
283
+ ```
284
+ User: "Ứng dụng bị crash với lỗi 'TypeError: Cannot read property of undefined'"
285
+ AI internal: [BRAIN READ TRIGGER R3 detected]
286
+ AI scans: brain/solutions/ với "TypeError undefined"
287
+ AI finds: "2026-02-15-undefined-null-fix.md"
288
+ AI responds: "🔍 Nhớ ra: Lỗi này gặp lần trước do null check thiếu
289
+ trong UserService. Fix: optional chaining + default value.
290
+ Áp dụng vào đây..."
291
+ ```
292
+
293
+ ### Example 2: Auto-Write on Decision
294
+ ```
295
+ User: "Ok, ta dùng better-sqlite3 cho neural brain"
296
+ AI internal: [BRAIN WRITE TRIGGER W1 detected]
297
+ AI saves silently: brain/decisions/2026-02-22-use-better-sqlite3.md
298
+ AI responds normally (không mention save)
299
+ ```
300
+
301
+ ### Example 3: Auto-Read on New Task
302
+ ```
303
+ User: "Giờ làm phần activation.js"
304
+ AI internal: [BRAIN READ TRIGGER R2 detected - filename mention]
305
+ AI scans: brain/* với "activation"
306
+ AI finds: "arch-neural-brain-2026-02-22.md"
307
+ AI responds: "💡 Từ plan trước: activation.js dùng heap-based BFS với
308
+ sigmoid decay. Bắt đầu với SpreadingActivation class..."
309
+ ```
310
+
311
+ ---
312
+
313
+ *ambient-brain v1.0.0 — Auto Memory Sync for AWF*
314
+ *Created by Kien AI*
@@ -0,0 +1,185 @@
1
+ # Brain Router — Decision Logic
2
+
3
+ > AI sử dụng file này để quyết định: READ, WRITE, hoặc SKIP brain cho mỗi input.
4
+
5
+ ---
6
+
7
+ ## Routing Decision Tree
8
+
9
+ ```
10
+ USER_INPUT received
11
+
12
+
13
+ [1. Session Start?] ──YES──▶ READ: session.json + active_plans + recent decisions
14
+ │ NO
15
+
16
+ [2. Error detected?] ──YES──▶ READ: brain/solutions/ (error pattern match)
17
+ │ NO Then: proceed with debug, WRITE solution if fixed
18
+
19
+ [3. Command: /plan, /code, /debug?] ──YES──▶ READ: feature-relevant entries
20
+ │ NO
21
+
22
+ [4. File/Feature/Task mentioned?] ──YES──▶ READ: tag match for that file/feature
23
+ │ NO
24
+
25
+ [5. Decision signal detected?] ──YES──▶ WRITE: brain/decisions/ (silent)
26
+ │ NO
27
+
28
+ [6. Resolution signal detected?] ──YES──▶ WRITE: brain/solutions/ (silent)
29
+ │ NO
30
+
31
+ [7. Workflow end?] ──YES──▶ WRITE: architecture/milestone summary (silent)
32
+ │ NO
33
+
34
+ [8. Every 10 turns?] ──YES──▶ CONSOLIDATE: check missed saves
35
+ │ NO
36
+
37
+ SKIP (normal processing)
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Signal Detection Patterns
43
+
44
+ ### 🔴 WRITE Signals
45
+
46
+ #### Decision Signals
47
+ ```yaml
48
+ high_confidence:
49
+ - "ta sẽ dùng {X}"
50
+ - "quyết định dùng {X}"
51
+ - "chọn {X} vì {reason}"
52
+ - "best approach là {X}"
53
+ - "we'll go with {X}"
54
+ - "decided: {X}"
55
+
56
+ medium_confidence (chỉ save nếu AI vừa propose):
57
+ - "ok", "được", "đồng ý" # + context: AI vừa suggest architecture
58
+ - "làm vậy đi", "Kien Ok" # + context: AI vừa propose approach
59
+ - "alright", "sounds good" # + context: technical decision context
60
+
61
+ low_confidence (SKIP - too vague):
62
+ - "ok" alone in casual chat
63
+ - "được" in non-technical context
64
+ ```
65
+
66
+ #### Resolution Signals
67
+ ```yaml
68
+ high_confidence:
69
+ - "works now", "fixed it", "chạy rồi"
70
+ - "problem solved", "issue resolved"
71
+ - "xong rồi", "ổn rồi", "ngon"
72
+ - "tests pass", "build success"
73
+
74
+ medium_confidence:
75
+ - "ok rồi" sau debug session
76
+ - "done" sau coding task
77
+ - emoji: ✅ sau error discussion
78
+
79
+ requires_context: True # Chỉ save nếu đang trong debug/fix context
80
+ ```
81
+
82
+ ### 🔵 READ Signals
83
+
84
+ #### Auto-Read Triggers
85
+ ```yaml
86
+ session_start:
87
+ detect: First message of conversation
88
+ load: session.json, active_plans.json, decisions (last 3)
89
+
90
+ error_context:
91
+ detect: error pattern in message
92
+ patterns:
93
+ - "error:", "Error:", "failed", "exception"
94
+ - "crash", "lỗi", "không chạy", "bug"
95
+ - Stack trace format (indented lines with "at ")
96
+ query: brain/solutions/ with error keywords
97
+
98
+ task_context:
99
+ detect: Specific file/feature mentioned + action verb
100
+ patterns:
101
+ - "{verb} {filename}.{ext}"
102
+ - "feature {name}", "implement {name}"
103
+ - /code, /debug, /plan commands
104
+ query: brain/* with filename or feature name as tags
105
+
106
+ architecture_question:
107
+ detect: Design/approach question
108
+ patterns:
109
+ - "nên dùng gì", "best approach"
110
+ - "how to design", "architecture for"
111
+ - "which pattern", "chọn giữa"
112
+ query: brain/decisions/ with topic keywords
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Context Accumulator
118
+
119
+ Brain Router maintains internal context per conversation:
120
+
121
+ ```json
122
+ {
123
+ "conversation_context": {
124
+ "turn_count": 0,
125
+ "current_feature": null,
126
+ "current_files": [],
127
+ "current_task_id": null,
128
+ "recent_errors": [],
129
+ "decisions_made": [],
130
+ "solutions_found": [],
131
+ "last_brain_read": null,
132
+ "last_brain_write": null,
133
+ "brain_entries_loaded": []
134
+ }
135
+ }
136
+ ```
137
+
138
+ **Updated each turn** to maintain routing accuracy with accumulated context.
139
+
140
+ ---
141
+
142
+ ## Anti-Patterns (When NOT to read/write)
143
+
144
+ ```yaml
145
+ never_read:
146
+ - Casual greeting ("xin chào", "hi", "how are you")
147
+ - Pure question about general knowledge (not project-specific)
148
+ - Already read brain this turn (deduplicate)
149
+
150
+ never_write:
151
+ - Salience < 0.5 (see SKILL.md scoring)
152
+ - Already have identical/similar entry (within 24h)
153
+ - Casual conversation, non-technical decisions
154
+ - User says "never mind", "bỏ qua", "thôi"
155
+
156
+ rate_limits:
157
+ max_reads_per_turn: 1
158
+ max_writes_per_turn: 2
159
+ min_write_interval_seconds: 30 # Avoid duplicate rapid saves
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Output Format for Brain Reads
165
+
166
+ When brain read finds relevant content:
167
+
168
+ ```
169
+ ✅ Inline mention (default):
170
+ "💡 Nhớ ra: [1-2 sentence summary]. Áp dụng vào đây..."
171
+
172
+ ✅ Decision reminder:
173
+ "📋 Đã quyết định [X] lúc [date]. Vẫn dùng?"
174
+
175
+ ✅ Solution reference:
176
+ "🔍 Đã giải quyết lỗi tương tự: [root_cause + fix in 1 line]"
177
+
178
+ ❌ Never dump full file content
179
+ ❌ Never show raw markdown formatting
180
+ ❌ Never mention "reading from brain" explicitly
181
+ ```
182
+
183
+ ---
184
+
185
+ *brain-router v1.0.0 — Routing logic for ambient-brain skill*
@@ -0,0 +1,201 @@
1
+ # Brain Entry Templates
2
+
3
+ > Các template chuẩn để lưu vào brain/ — dùng cho cả auto-save và manual /save-brain.
4
+
5
+ ---
6
+
7
+ ## Template 1: Decision (brain/decisions/)
8
+
9
+ **Filename:** `brain/decisions/YYYY-MM-DD-[slug].md`
10
+
11
+ ```markdown
12
+ ---
13
+ date: 2026-02-22
14
+ type: decision
15
+ topic: [brief topic, e.g., "Database choice for neural-brain"]
16
+ feature: [which feature/project this belongs to]
17
+ tags: [tech, architecture, database, ...]
18
+ salience: 0.90
19
+ ---
20
+
21
+ # Decision: [Topic]
22
+
23
+ ## What was decided
24
+ [Clear statement of the decision]
25
+
26
+ ## Why this approach
27
+ [Rationale — key reasons]
28
+
29
+ ## Alternatives considered
30
+ - **[Option A]**: [Why rejected]
31
+ - **[Option B]**: [Why rejected]
32
+
33
+ ## Trade-offs
34
+ - ✅ [Pro 1]
35
+ - ✅ [Pro 2]
36
+ - ⚠️ [Con/caveat]
37
+
38
+ ## Context
39
+ [Additional context: task ID, feature, constraints]
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Template 2: Solution (brain/solutions/)
45
+
46
+ **Filename:** `brain/solutions/YYYY-MM-DD-[slug].md`
47
+
48
+ ```markdown
49
+ ---
50
+ date: 2026-02-22
51
+ type: solution
52
+ error_pattern: [e.g., "TypeError: Cannot read property of undefined"]
53
+ files_affected: [e.g., "activation.js, store.js"]
54
+ tags: [javascript, sqlite, null-check, ...]
55
+ salience: 0.85
56
+ ---
57
+
58
+ # Solution: [Error Pattern]
59
+
60
+ ## The Error
61
+ ```
62
+ [Paste exact error or describe the bug]
63
+ ```
64
+
65
+ ## Root Cause
66
+ [Why this happened — 1-2 sentences]
67
+
68
+ ## The Fix
69
+ [Step-by-step or code snippet showing the solution]
70
+
71
+ ```js
72
+ // Before (broken)
73
+ code here
74
+
75
+ // After (fixed)
76
+ code here
77
+ ```
78
+
79
+ ## How to Prevent
80
+ [Rule or pattern to avoid this in future]
81
+
82
+ ## Context
83
+ [What feature/task was being worked on when this occurred]
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Template 3: Architecture (brain/decisions/)
89
+
90
+ **Filename:** `brain/decisions/arch-[feature]-[date].md`
91
+
92
+ ```markdown
93
+ ---
94
+ date: 2026-02-22
95
+ type: architecture
96
+ feature: [feature name, e.g., "neural-brain"]
97
+ tags: [architecture, design, ...]
98
+ salience: 0.95
99
+ ---
100
+
101
+ # Architecture: [Feature Name]
102
+
103
+ ## Overview
104
+ [Brief description of what was designed]
105
+
106
+ ## Structure
107
+ ```
108
+ [directory tree or component diagram]
109
+ ```
110
+
111
+ ## Key Decisions
112
+ 1. [Decision 1 + rationale]
113
+ 2. [Decision 2 + rationale]
114
+ 3. [Decision 3 + rationale]
115
+
116
+ ## Tech Choices
117
+ | Component | Choice | Reason |
118
+ |-----------|--------|--------|
119
+ | [Layer] | [Tech] | [Why] |
120
+
121
+ ## Data Flow
122
+ [How data flows through the system]
123
+
124
+ ## Open Questions
125
+ - [ ] [Question to resolve later]
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Template 4: Session (brain/session.json)
131
+
132
+ **Auto-updated by ambient-brain skill.**
133
+
134
+ ```json
135
+ {
136
+ "last_updated": "2026-02-22T16:56:00+07:00",
137
+ "working_on": {
138
+ "project": "main-awf",
139
+ "feature": "neural-brain + ambient-brain skill",
140
+ "phase": "implementation",
141
+ "current_task_id": null,
142
+ "current_files": ["skills/ambient-brain/SKILL.md"]
143
+ },
144
+ "recent_decisions": [
145
+ {
146
+ "ref": "decisions/2026-02-22-use-better-sqlite3.md",
147
+ "summary": "Use better-sqlite3 for neural brain storage"
148
+ }
149
+ ],
150
+ "recent_solutions": [],
151
+ "active_context": {
152
+ "neural_brain_port": "Planning phase - studying Python source",
153
+ "ambient_brain": "Implementing skill files"
154
+ },
155
+ "completed_milestones": [],
156
+ "context_checkpoints": []
157
+ }
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Template 5: Active Plans (brain/active_plans.json)
163
+
164
+ ```json
165
+ {
166
+ "plans": [
167
+ {
168
+ "id": "neural-brain-nodejs-port",
169
+ "title": "Port neural-memory to Node.js for main-awf",
170
+ "status": "planning",
171
+ "phases": [
172
+ { "id": "p1", "name": "Study Python source", "status": "done" },
173
+ { "id": "p2", "name": "Build SQLite schema", "status": "next" },
174
+ { "id": "p3", "name": "Core data structures", "status": "pending" },
175
+ { "id": "p4", "name": "Spreading activation engine", "status": "pending" },
176
+ { "id": "p5", "name": "Public API integration", "status": "pending" }
177
+ ],
178
+ "created": "2026-02-22",
179
+ "last_updated": "2026-02-22"
180
+ },
181
+ {
182
+ "id": "ambient-brain-skill",
183
+ "title": "Ambient Brain Sync skill for AWF",
184
+ "status": "implementing",
185
+ "phases": [
186
+ { "id": "p1", "name": "Design & brainstorm", "status": "done" },
187
+ { "id": "p2", "name": "Create skill files", "status": "in_progress" },
188
+ { "id": "p3", "name": "Update GEMINI.md", "status": "next" },
189
+ { "id": "p4", "name": "Deploy to antigravity", "status": "pending" },
190
+ { "id": "p5", "name": "Test with real workflow", "status": "pending" }
191
+ ],
192
+ "created": "2026-02-22",
193
+ "last_updated": "2026-02-22"
194
+ }
195
+ ]
196
+ }
197
+ ```
198
+
199
+ ---
200
+
201
+ *brain-templates v1.0.0 — Standard formats for consistent brain storage*