sanook-cli 0.5.1 → 0.5.2

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 (144) hide show
  1. package/.env.example +161 -3
  2. package/CHANGELOG.md +57 -8
  3. package/README.md +240 -23
  4. package/README.th.md +87 -6
  5. package/dist/approval.js +6 -0
  6. package/dist/bin.js +3026 -196
  7. package/dist/brain-context.js +223 -0
  8. package/dist/brain-doctor.js +318 -0
  9. package/dist/brain-eval.js +186 -0
  10. package/dist/brain-final.js +371 -0
  11. package/dist/brain-review.js +382 -0
  12. package/dist/brain.js +12 -1
  13. package/dist/brand.js +1 -1
  14. package/dist/cli-args.js +152 -0
  15. package/dist/cli-option-values.js +16 -0
  16. package/dist/commands.js +172 -13
  17. package/dist/compaction.js +96 -11
  18. package/dist/config.js +118 -28
  19. package/dist/context-compression.js +191 -0
  20. package/dist/cost.js +49 -15
  21. package/dist/first-run.js +21 -0
  22. package/dist/gateway/auth.js +37 -8
  23. package/dist/gateway/bluebubbles.js +205 -0
  24. package/dist/gateway/config.js +929 -0
  25. package/dist/gateway/deliver.js +357 -0
  26. package/dist/gateway/discord.js +124 -0
  27. package/dist/gateway/email.js +472 -0
  28. package/dist/gateway/googlechat.js +207 -0
  29. package/dist/gateway/homeassistant.js +256 -0
  30. package/dist/gateway/ledger.js +18 -0
  31. package/dist/gateway/line.js +171 -0
  32. package/dist/gateway/lock.js +3 -1
  33. package/dist/gateway/matrix.js +366 -0
  34. package/dist/gateway/mattermost.js +322 -0
  35. package/dist/gateway/ntfy.js +218 -0
  36. package/dist/gateway/schedule.js +31 -4
  37. package/dist/gateway/serve.js +267 -7
  38. package/dist/gateway/server.js +253 -19
  39. package/dist/gateway/service.js +224 -0
  40. package/dist/gateway/session.js +343 -0
  41. package/dist/gateway/signal.js +351 -0
  42. package/dist/gateway/slack.js +124 -0
  43. package/dist/gateway/sms.js +169 -0
  44. package/dist/gateway/targets.js +576 -0
  45. package/dist/gateway/teams.js +106 -0
  46. package/dist/gateway/telegram.js +38 -15
  47. package/dist/gateway/webhooks.js +220 -0
  48. package/dist/gateway/whatsapp.js +230 -0
  49. package/dist/hooks.js +13 -2
  50. package/dist/insights-args.js +35 -0
  51. package/dist/insights.js +86 -0
  52. package/dist/loop.js +123 -24
  53. package/dist/lsp/index.js +23 -5
  54. package/dist/mcp-registry.js +350 -0
  55. package/dist/mcp-server.js +1 -1
  56. package/dist/mcp.js +44 -6
  57. package/dist/memory.js +100 -33
  58. package/dist/orchestrate.js +49 -19
  59. package/dist/personality.js +58 -0
  60. package/dist/providers/codex.js +70 -36
  61. package/dist/providers/keys.js +1 -1
  62. package/dist/providers/models.js +1 -1
  63. package/dist/providers/registry.js +14 -47
  64. package/dist/search/chunk.js +7 -8
  65. package/dist/search/cli.js +75 -0
  66. package/dist/search/embed-store.js +3 -0
  67. package/dist/search/indexer.js +44 -1
  68. package/dist/search/store.js +23 -1
  69. package/dist/session.js +93 -7
  70. package/dist/skill-install.js +29 -12
  71. package/dist/support-dump.js +175 -0
  72. package/dist/tools/edit.js +45 -15
  73. package/dist/tools/git.js +10 -5
  74. package/dist/tools/homeassistant.js +106 -0
  75. package/dist/tools/index.js +5 -0
  76. package/dist/tools/list.js +19 -6
  77. package/dist/tools/permission.js +923 -9
  78. package/dist/tools/read.js +16 -4
  79. package/dist/tools/schedule.js +19 -3
  80. package/dist/tools/search.js +217 -13
  81. package/dist/tools/task.js +18 -7
  82. package/dist/tools/timeout.js +21 -3
  83. package/dist/trust.js +11 -1
  84. package/dist/ui/app.js +48 -8
  85. package/dist/ui/history.js +37 -5
  86. package/dist/ui/mentions.js +3 -2
  87. package/dist/ui/setup.js +17 -4
  88. package/dist/update.js +24 -11
  89. package/dist/worktree.js +175 -4
  90. package/package.json +4 -4
  91. package/second-brain/AGENTS.md +6 -4
  92. package/second-brain/CLAUDE.md +7 -1
  93. package/second-brain/Evals/_Index.md +10 -2
  94. package/second-brain/Evals/quality-ledger.md +9 -1
  95. package/second-brain/Evals/second-brain-benchmarks.md +62 -0
  96. package/second-brain/GEMINI.md +5 -4
  97. package/second-brain/Home.md +1 -1
  98. package/second-brain/Projects/_Index.md +3 -1
  99. package/second-brain/Projects/sanook-cli/_Index.md +26 -0
  100. package/second-brain/Projects/sanook-cli/second-brain-feature-roadmap.md +156 -0
  101. package/second-brain/README.md +1 -1
  102. package/second-brain/Research/2026-06-17-ai-second-brain-method-experiment.md +108 -0
  103. package/second-brain/Research/2026-06-18-ai-token-reduction-frameworks.md +55 -0
  104. package/second-brain/Research/2026-06-18-hermes-cli-second-brain-expansion-research.md +160 -0
  105. package/second-brain/Research/2026-06-18-sanook-mcp-ecosystem-and-ux-roadmap.md +181 -0
  106. package/second-brain/Research/_Index.md +6 -1
  107. package/second-brain/Reviews/2026-06-18-auto-improve-maintenance.md +54 -0
  108. package/second-brain/Reviews/_Index.md +1 -1
  109. package/second-brain/Runbooks/_Index.md +6 -1
  110. package/second-brain/Runbooks/ai-second-brain-operating-sequence.md +108 -0
  111. package/second-brain/SANOOK.md +45 -0
  112. package/second-brain/Sessions/2026-06-17-ai-framework-additional-zones.md +68 -0
  113. package/second-brain/Sessions/2026-06-17-ai-second-brain-sequence-experiment.md +63 -0
  114. package/second-brain/Sessions/2026-06-18-cli-args-release-readiness.md +59 -0
  115. package/second-brain/Sessions/2026-06-18-final-gate-template-final.md +192 -0
  116. package/second-brain/Sessions/2026-06-18-final-gate-template.md +71 -0
  117. package/second-brain/Sessions/2026-06-18-framework-dogfood-permission-and-memory.md +58 -0
  118. package/second-brain/Sessions/2026-06-18-hermes-second-brain-expansion-research.md +52 -0
  119. package/second-brain/Sessions/2026-06-18-mcp-ecosystem-and-sanook-ux-scan.md +81 -0
  120. package/second-brain/Sessions/2026-06-18-sanook-brain-cli-p0-implementation.md +86 -0
  121. package/second-brain/Sessions/2026-06-18-sanook-brain-final-cli-final.md +246 -0
  122. package/second-brain/Sessions/2026-06-18-sanook-brain-final-cli.md +78 -0
  123. package/second-brain/Sessions/2026-06-18-sanook-cli-second-brain-roadmap-correction.md +54 -0
  124. package/second-brain/Sessions/2026-06-18-token-reduction-framework-integration.md +69 -0
  125. package/second-brain/Sessions/_Index.md +15 -1
  126. package/second-brain/Shared/AI-Context-Index.md +22 -0
  127. package/second-brain/Shared/Context-Packs/_Index.md +9 -1
  128. package/second-brain/Shared/Context-Packs/coding-release.md +51 -0
  129. package/second-brain/Shared/Context-Packs/research-to-framework.md +51 -0
  130. package/second-brain/Shared/Context-Packs/second-brain-maintenance.md +41 -0
  131. package/second-brain/Shared/Operating-State/current-state.md +22 -3
  132. package/second-brain/Shared/Scripts/_Index.md +3 -1
  133. package/second-brain/Shared/Scripts/ai-second-brain-method-eval.mjs +198 -0
  134. package/second-brain/Shared/Tech-Standards/_Index.md +4 -1
  135. package/second-brain/Shared/Tech-Standards/mcp-integration-roadmap.md +86 -0
  136. package/second-brain/Shared/Tech-Standards/verification-standard.md +24 -0
  137. package/second-brain/Shared/User-Memory/_Index.md +4 -1
  138. package/second-brain/Shared/User-Memory/response-examples.md +98 -0
  139. package/second-brain/Shared/User-Memory/user-preferences.md +1 -0
  140. package/second-brain/Templates/_Index.md +9 -0
  141. package/second-brain/Templates/final-lite.md +111 -0
  142. package/second-brain/Templates/final.md +231 -0
  143. package/second-brain/Vault Structure Map.md +2 -1
  144. package/skills/structured-output-llm/SKILL.md +1 -1
@@ -25,6 +25,8 @@ deliverable + overview/context/current-state ของ project
25
25
 
26
26
  > รายละเอียดทุกโฟลเดอร์ + decision rules → [[Vault Structure Map]]
27
27
 
28
- _(ยังว่าง — โน้ตในโฟลเดอร์นี้จะถูกลิงก์ที่นี่)_
28
+ ## Projects
29
+
30
+ - [[Projects/sanook-cli/_Index]] — project workspace สำหรับ Sanook CLI
29
31
 
30
32
  up:: [[Home]]
@@ -0,0 +1,26 @@
1
+ ---
2
+ tags: [index, moc, project, sanook-cli]
3
+ note_type: moc
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Projects/_Index]]"
7
+ ---
8
+
9
+ # Sanook CLI
10
+
11
+ > Project workspace for Sanook CLI product decisions, implementation plans, and current project-specific state. Use this for deliverables about the CLI itself, not generic second-brain theory.
12
+
13
+ ## Notes
14
+
15
+ - [[Projects/sanook-cli/second-brain-feature-roadmap]] — roadmap for making second-brain features native to Sanook CLI
16
+
17
+ ## AI Routing Contract
18
+
19
+ - ก่อนเขียน: ใช้โฟลเดอร์นี้เฉพาะงานที่เกี่ยวกับ Sanook CLI product/codebase โดยตรง
20
+ - ก่อนสร้างไฟล์ใหม่: ค้นหา note เดิมใน `Projects/sanook-cli/` ก่อน เพื่อ merge/update แทน append ซ้ำ
21
+ - เมื่อสร้างโน้ตในโฟลเดอร์นี้: ตั้ง `parent: "[[Projects/sanook-cli/_Index]]"` และท้ายไฟล์ `up:: [[Projects/sanook-cli/_Index]]`
22
+ - หลังเขียน: เชื่อม link ไป session/source/code path ที่เกี่ยวข้อง และอัปเดต index นี้ถ้าโน้ตควรถูกค้นเจอในอนาคต
23
+
24
+ > รายละเอียดทุกโฟลเดอร์ + decision rules → [[Vault Structure Map]]
25
+
26
+ up:: [[Projects/_Index]]
@@ -0,0 +1,156 @@
1
+ ---
2
+ tags: [project, sanook-cli, second-brain, roadmap]
3
+ note_type: project-overview
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Projects/sanook-cli/_Index]]"
7
+ source::
8
+ - src/bin.ts
9
+ - src/brain.ts
10
+ - src/memory.ts
11
+ - src/knowledge.ts
12
+ - src/mcp-server.ts
13
+ - src/search/indexer.ts
14
+ - second-brain/SANOOK.md
15
+ related:: [[Research/2026-06-18-hermes-cli-second-brain-expansion-research]]
16
+ ---
17
+
18
+ # Sanook CLI Second-Brain Feature Roadmap
19
+
20
+ > Implementation roadmap for doing the second-brain work inside Sanook CLI itself. This supersedes Hermes-specific next actions unless the task is explicitly about Hermes compatibility.
21
+
22
+ ## Current Sanook Capabilities
23
+
24
+ - `sanook brain init [path]` scaffolds the vault, writes `SANOOK.md`, and stores `brainPath`.
25
+ - `wireBrainMcp()` adds a filesystem MCP server for the vault under `~/.sanook/mcp.json`.
26
+ - `buildBrainContext()` injects `Shared/AI-Context-Index.md`, `current-state.md`, and Memory-Inbox candidates into agent context.
27
+ - `remember` writes to Sanook memory store and routes facts into vault Memory-Inbox.
28
+ - Headless sessions append a daily worklog into `Sessions/`.
29
+ - `sanook index` incrementally indexes vault + memory + sessions + skills.
30
+ - `sanook search` gives BM25 plus optional semantic/hybrid search over the unified index.
31
+ - `sanook mcp serve` exposes `sanook_search`, `sanook_recall`, `sanook_remember`, `sanook_index`, and `sanook_stats`.
32
+
33
+ ## Correct Direction
34
+
35
+ Do not make the next step `HERMES.md`. For Sanook CLI, the better work is:
36
+
37
+ 1. Make Sanook able to inspect and repair its own second-brain.
38
+ 2. Make Sanook able to assemble task-focused context from the vault.
39
+ 3. Make Sanook able to run lightweight evals against the vault.
40
+ 4. Keep the scaffold taxonomy stable until a command proves a new folder is necessary.
41
+
42
+ ## P0 Features
43
+
44
+ ### `sanook brain doctor`
45
+
46
+ Status: implemented.
47
+
48
+ Check the vault itself, not just installation:
49
+
50
+ - `brainPath` configured and exists.
51
+ - Hot files exist: `SANOOK.md`, `Shared/AI-Context-Index.md`, `Vault Structure Map.md`, `Shared/Operating-State/current-state.md`.
52
+ - Every markdown seed has purpose blockquote, `parent`, and `up::` where expected.
53
+ - `Vault Structure Map.md` mentions every `FOLDERS[]` entry.
54
+ - Search index exists and is fresh enough compared with vault mtimes.
55
+ - MCP wiring points to the configured vault.
56
+
57
+ ### `sanook brain context [--task "..."]`
58
+
59
+ Status: implemented.
60
+
61
+ Show the exact context Sanook would inject or retrieve:
62
+
63
+ - Hot context sources and character counts.
64
+ - Optional task query that runs search and prints top vault/session/skill hits.
65
+ - Clear warning when context is stale, too large, or missing expected files.
66
+
67
+ ### `sanook brain eval`
68
+
69
+ Status: implemented.
70
+
71
+ Turn `Evals/second-brain-benchmarks.md` into a runnable sanity check:
72
+
73
+ - Static cases: required files, routing links, memory policy, index presence.
74
+ - Retrieval cases: search for known benchmark phrases and verify expected files appear.
75
+ - Output pass/partial/fail with file evidence.
76
+
77
+ ## P1 Features
78
+
79
+ ### `sanook brain review`
80
+
81
+ Status: implemented.
82
+
83
+ Curator-style health review for the vault:
84
+
85
+ - Stale context packs.
86
+ - Duplicate or contradictory memory candidates.
87
+ - Sessions without index entries.
88
+ - Evals that have not been updated after framework changes.
89
+ - Markdown routing hygiene: purpose blockquote, `parent`, and `up::`.
90
+
91
+ ### `sanook brain pack list|show`
92
+
93
+ Make `Shared/Context-Packs/` first-class:
94
+
95
+ - List available packs with descriptions.
96
+ - Show pack sources and expected use cases.
97
+ - Eventually let the agent choose a pack before loading broader context.
98
+
99
+ ### `sanook brain new <type>`
100
+
101
+ Template-backed note creation:
102
+
103
+ - `session`, `bug`, `handoff`, `project`, `golden-case`, `checklist`.
104
+ - Reads destination `_Index.md`, fills frontmatter, and prevents wrong-folder drift.
105
+
106
+ ## P2 Features
107
+
108
+ - `sanook brain export --for claude|gemini|codex|hermes` for adapter files only when explicitly needed.
109
+ - `sanook brain metrics` for counts, stale notes, index freshness, and retrieval coverage.
110
+ - `sanook brain repair` for safe one-line fixes after `doctor` reports them.
111
+
112
+ ## Folder Policy
113
+
114
+ No new root folder is needed yet.
115
+
116
+ Add folders only when a Sanook command needs stable output:
117
+
118
+ - `Evals/Benchmarks/` when `sanook brain eval` wants per-case files.
119
+ - `Acceptance/Golden-Cases/` when golden fixtures multiply.
120
+ - `Reviews/Vault-Health/` when `sanook brain review` starts writing scheduled reports. The current command is read-only, so no new folder is needed yet.
121
+
122
+ Avoid broad folders:
123
+
124
+ - No `Resources/`
125
+ - No `Notes/`
126
+ - No root `AI/`
127
+ - No root `Experiments/`
128
+
129
+ ## First Implementation Slice
130
+
131
+ Completed on 2026-06-18:
132
+
133
+ 1. Added `src/brain-doctor.ts` with pure check functions and CLI wiring.
134
+ 2. Added `src/brain-context.ts` so Sanook can inspect the exact prompt context and task retrieval hits.
135
+ 3. Added `src/brain-eval.ts` as a runnable benchmark sanity checker over `Evals/second-brain-benchmarks.md`.
136
+ 4. Updated shell/REPL help and changelog.
137
+ 5. Verified with targeted second-brain tests and typecheck.
138
+
139
+ ## Second Implementation Slice
140
+
141
+ Completed on 2026-06-18:
142
+
143
+ 1. Added `src/brain-review.ts` for curator-style vault review.
144
+ 2. Wired `sanook brain review [--no-hygiene]` into CLI and help.
145
+ 3. Updated generated `Shared/Context-Packs/_Index.md` to link bundled context packs.
146
+ 4. Verified with review/scaffold/memory tests and typecheck.
147
+
148
+ ## Next Implementation Slice
149
+
150
+ Best next code slice:
151
+
152
+ 1. Add `sanook brain pack list|show` for `Shared/Context-Packs/`.
153
+ 2. Add `sanook brain new <type>` once note creation templates need a CLI surface.
154
+ 3. Add `sanook brain repair` for safe one-line fixes after `doctor`/`review` reports them.
155
+
156
+ up:: [[Projects/sanook-cli/_Index]]
@@ -23,7 +23,7 @@
23
23
  1. เปิดโฟลเดอร์นี้ใน **Obsidian** (Open folder as vault)
24
24
  2. ให้ AI agent อ่าน `Shared/AI-Context-Index.md` ก่อนทำงานเสมอ
25
25
  3. ก่อนสร้างหรือย้ายโน้ต ให้เลือกปลายทางจาก `Vault Structure Map.md` แล้วอ่าน `_Index.md` ของโฟลเดอร์นั้นเพื่อทำตาม **AI Routing Contract**
26
- 4. constitution อยู่ที่ `CLAUDE.md` / `GEMINI.md` / `AGENTS.md` — กฎปฏิบัติของ AI
26
+ 4. constitution อยู่ที่ `CLAUDE.md` / `GEMINI.md` / `AGENTS.md` / `SANOOK.md` — กฎปฏิบัติของ AI
27
27
 
28
28
  ## ปรับให้เป็นของคุณ
29
29
 
@@ -0,0 +1,108 @@
1
+ ---
2
+ tags: [research, second-brain, ai, experiment]
3
+ note_type: research-note
4
+ created: 2026-06-17
5
+ updated: 2026-06-17
6
+ parent: "[[Research/_Index]]"
7
+ source::
8
+ - "[[Shared/Scripts/ai-second-brain-method-eval.mjs]]"
9
+ - "https://arxiv.org/abs/2307.03172"
10
+ - "https://arxiv.org/abs/2310.11511"
11
+ - "https://arxiv.org/abs/2404.16130"
12
+ ---
13
+
14
+ # AI Second-Brain Method Experiment — 2026-06-17
15
+
16
+ > คำถามทดลอง: วิธีจัด second-brain แบบไหนทำให้ AI ใช้งาน vault ได้แม่นที่สุด โดยไม่โหลด context เกินจำเป็น?
17
+
18
+ ## Hypothesis
19
+
20
+ วิธีที่ดีที่สุดไม่ใช่การให้ AI โหลดทั้ง vault หรือจำจาก session log แต่คือ:
21
+
22
+ **Single Retrieval Path + JIT Task Rules + Explicit Write Routing + Eval/Consolidation Loop**
23
+
24
+ ชื่อที่ใช้ใน framework: **Scientific Loop Sequence**.
25
+
26
+ ## Method
27
+
28
+ รันสคริปต์:
29
+
30
+ ```bash
31
+ node second-brain/Shared/Scripts/ai-second-brain-method-eval.mjs second-brain
32
+ ```
33
+
34
+ สคริปต์เทียบ 5 วิธี:
35
+
36
+ | Method | แนวคิด |
37
+ |---|---|
38
+ | Session-log only | ใช้ session history เป็น memory หลัก |
39
+ | Folder map only | ใช้ `Vault Structure Map.md` และ index ปลายทาง |
40
+ | Single retrieval index | เริ่มจาก `Shared/AI-Context-Index.md` |
41
+ | Index + JIT context policy | single index + context assembly + โหลดเฉพาะไฟล์จำเป็น |
42
+ | Scientific loop sequence | single index + JIT + write protocol + eval + sleep consolidation + coordination |
43
+
44
+ Scenarios ที่ใช้วัด:
45
+
46
+ 1. เริ่มงานกับ AI โดยไม่หลุด source of truth
47
+ 2. สร้าง/แก้ durable note ให้ถูกที่และค้นเจอภายหลัง
48
+ 3. บันทึก preference/decision/fact โดยไม่ append ซ้ำ
49
+ 4. นำข้อมูลภายนอกเข้า vault แบบปลอด prompt injection
50
+ 5. ทำ sleep-time consolidation และปิด loop ความจำ
51
+ 6. กันหลาย agent ชนกันและส่งต่องานได้
52
+ 7. งานเทคนิคที่ต้อง verify ก่อนสรุป
53
+
54
+ Metric:
55
+
56
+ - **File coverage**: context มีไฟล์ที่ scenario ต้องใช้ไหม
57
+ - **Capability coverage**: วิธีนั้นมี retrieval/routing/eval/memory/coordination ครบไหม
58
+ - **Token economy**: context เฉลี่ยยังใกล้ budget หรือไม่
59
+
60
+ ## Results
61
+
62
+ | Rank | Method | Score | File Coverage | Capability Coverage | Avg Tokens |
63
+ |---:|---|---:|---:|---:|---:|
64
+ | 1 | Scientific loop sequence | 97.0 | 100% | 100% | ~2890 |
65
+ | 2 | Index + JIT context policy | 62.6 | 64% | 43% | ~2235 |
66
+ | 3 | Single retrieval index | 40.6 | 39% | 18% | ~1932 |
67
+ | 4 | Folder map + destination indexes | 20.8 | 13% | 18% | ~2598 |
68
+ | 5 | Session-log only | 16.4 | 6% | 10% | ~313 |
69
+
70
+ ## Interpretation
71
+
72
+ **Winner: Scientific Loop Sequence.**
73
+
74
+ เหตุผล:
75
+
76
+ - ครอบคลุมงาน AI กับ second-brain ได้ครบทุก scenario
77
+ - ลด hallucination เพราะเริ่มจาก single source of truth แล้วค่อย expand context
78
+ - ลด memory rot เพราะ write operation ต้องเลือก ADD/UPDATE/DELETE/NOOP
79
+ - ลด context rot เพราะใช้ `context-assembly-policy` ก่อนโหลด task rules
80
+ - มี feedback loop จริงผ่าน `eval-loop` และ `sleep-time-consolidation`
81
+
82
+ ข้อควรระวัง:
83
+
84
+ - Avg tokens ~2890 สูงกว่า target ~2k
85
+ - บาง scenario สูงเพราะต้องโหลดไฟล์ใหญ่ เช่น `Vault Structure Map.md` และ ingest rules
86
+ - ดังนั้น implementation ต้องใช้แบบ **JIT**: โหลด heading/index ก่อน, expand body เฉพาะเมื่อจำเป็น, และอย่า preload ทุก rule ทุกครั้ง
87
+
88
+ ## Literature Anchor
89
+
90
+ - Lost in the Middle สนับสนุนว่า context ยาวและตำแหน่งกลางทำให้ retrieval/usefulness ลดลง จึงควรวาง load-bearing context ไว้หัว/ท้าย
91
+ - Self-RAG สนับสนุน retrieve-then-critique/evaluate loop แทนการตอบจาก memory ล้วน
92
+ - GraphRAG สนับสนุนการจัดความรู้เป็น graph/index แทนการกองเอกสารแบบ flat
93
+
94
+ ## Decision
95
+
96
+ ใช้ **Scientific Loop Sequence** เป็น default AI operating sequence ของ vault:
97
+
98
+ 1. Frame objective/DoD
99
+ 2. Retrieve hot context via `Shared/AI-Context-Index.md`
100
+ 3. Select AI role for the current phase
101
+ 4. Load task-specific rules JIT
102
+ 5. Act and verify
103
+ 6. Write memory with explicit operation
104
+ 7. Eval if non-trivial
105
+ 8. Consolidate later via sleep-time loop
106
+
107
+ related:: [[Runbooks/ai-second-brain-operating-sequence]]
108
+ up:: [[Research/_Index]]
@@ -0,0 +1,55 @@
1
+ ---
2
+ tags: [research, token-reduction, ai-agent, sanook-cli]
3
+ note_type: research
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Research/_Index]]"
7
+ source:
8
+ - https://github.com/microsoft/LLMLingua
9
+ - https://github.com/liyucheng09/Selective_Context
10
+ - https://github.com/chopratejas/headroom
11
+ ---
12
+
13
+ # AI Token Reduction Frameworks for Sanook CLI
14
+
15
+ > Research note for choosing a token-reduction framework/pattern to integrate into Sanook CLI.
16
+
17
+ ## Candidates
18
+
19
+ - Microsoft LLMLingua: strong prompt-compression family, but Python/model-heavy for a Node CLI default.
20
+ - Selective Context: removes low-information lexical units; good fit for a zero-LLM local compressor.
21
+ - Headroom: TypeScript package with Vercel AI SDK adapter, but direct compression requires a running proxy or cloud API key.
22
+
23
+ ## Decision
24
+
25
+ Use a Sanook-native zero-dependency selective context compressor as the default, and expose Headroom as an optional framework mode.
26
+
27
+ Rationale:
28
+
29
+ - Works by default without a Python runtime, model download, proxy, or extra API key.
30
+ - Fits the current Sanook architecture because the biggest waste is stale tool output in multi-step agent loops.
31
+ - Keeps recent tool results full, preserving local correctness while reducing old transcript bloat.
32
+ - Lets users opt into the actual `headroom-ai` Vercel AI SDK adapter when they have a Headroom proxy/cloud compression layer.
33
+
34
+ ## Implementation Shape
35
+
36
+ - New `contextCompression` config: `selective` (default), `headroom`, or `off`.
37
+ - `SANOOK_CONTEXT_COMPRESSION=off` disables it.
38
+ - `SANOOK_CONTEXT_COMPRESSION=headroom` wraps the Vercel AI SDK model with `headroom-ai/vercel-ai`.
39
+ - `SANOOK_HEADROOM_BASE_URL` and `SANOOK_HEADROOM_API_KEY` can point Sanook at the user's Headroom setup.
40
+ - `selectiveCompressText()` keeps head/tail anchors and high-information lines:
41
+ - current user-query matches
42
+ - errors, warnings, failures, tracebacks
43
+ - file paths and line numbers
44
+ - diffs and code structure
45
+ - headings / JSON-like structure
46
+ - rare lexical terms
47
+ - `selectivelyCompressStaleToolResults()` applies it only to old large tool outputs before each model step.
48
+ - Older stale tool outputs get tighter budgets; the newest tail remains full.
49
+
50
+ ## Verification
51
+
52
+ - Unit tests cover preservation of query matches, errors, code/diff structure, unchanged short text, stale-tool compression, recency budgets, and recent-tail preservation.
53
+ - Full validation still needs `typecheck`, full test suite, and build after implementation.
54
+
55
+ up:: [[Research/_Index]]
@@ -0,0 +1,160 @@
1
+ ---
2
+ tags: [research, second-brain, hermes, ai-agent, context-engineering]
3
+ note_type: research-note
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Research/_Index]]"
7
+ source::
8
+ - https://github.com/NousResearch/hermes-agent
9
+ - https://hermes-agent.nousresearch.com/docs/user-guide/features/context-files
10
+ - https://hermes-agent.nousresearch.com/docs/user-guide/features/memory
11
+ - https://hermes-agent.nousresearch.com/docs/user-guide/features/skills
12
+ - https://hermes-agent.nousresearch.com/docs/user-guide/features/curator
13
+ - https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
14
+ - https://docs.langchain.com/oss/python/concepts/memory
15
+ - https://arxiv.org/abs/2304.03442
16
+ - https://arxiv.org/abs/2310.08560
17
+ - https://arxiv.org/abs/2303.11366
18
+ - https://arxiv.org/abs/2210.03629
19
+ - https://fortelabs.com/blog/para/
20
+ related:: [[Runbooks/ai-second-brain-operating-sequence]]
21
+ related:: [[Shared/AI-Context-Index]]
22
+ related:: [[Evals/second-brain-benchmarks]]
23
+ ---
24
+
25
+ # Hermes CLI Second-Brain Expansion Research
26
+
27
+ > Research note for deciding what to add to this second-brain so Hermes CLI can use it better. Created after comparing the current vault structure with Hermes Agent docs, agent memory research, context-engineering guidance, eval patterns, and PARA-style knowledge management. This note becomes stale when Hermes context/memory/skills semantics change materially.
28
+
29
+ ## Bottom Line
30
+
31
+ Scope correction on 2026-06-18: this note is reference material for Hermes compatibility only. If the objective is Sanook CLI itself, use [[Projects/sanook-cli/second-brain-feature-roadmap]] instead.
32
+
33
+ อย่าเพิ่ม root-level folder เยอะตอนนี้. โครงสร้างปัจจุบันมี knowledge pipeline, memory, context packs, evals, coordination, and runbooks ครบกว่าค่าเฉลี่ยแล้ว.
34
+
35
+ สิ่งที่ควรเพิ่มถัดไปคือชั้นที่ทำให้ Hermes ใช้ของที่มีอยู่ได้แม่นขึ้น:
36
+
37
+ 1. `HERMES.md` หรือ `.hermes.md` adapter สำหรับ Hermes CLI โดยเฉพาะ.
38
+ 2. `Shared/Hermes/` หรืออย่างน้อย `Shared/Agent-Adapters/hermes.md` สำหรับ config, memory sync, toolset, and curator policy.
39
+ 3. `Evals/Benchmarks/` สำหรับ benchmark cases แยกเป็นไฟล์เล็กๆ แทนการโตในไฟล์เดียว.
40
+ 4. `Acceptance/Golden-Cases/` สำหรับ input -> expected output ของ Hermes workflows.
41
+ 5. `Reviews/Vault-Health/` สำหรับ scheduled curator-style review ของ vault/context/skills.
42
+
43
+ ## Evidence From Hermes
44
+
45
+ Hermes context files:
46
+
47
+ - Hermes supports `.hermes.md` / `HERMES.md`, `AGENTS.md`, `CLAUDE.md`, `SOUL.md`, `.cursorrules`, and Cursor rule modules.
48
+ - Priority is first-match: `.hermes.md` -> `AGENTS.md` -> `CLAUDE.md` -> `.cursorrules`; `SOUL.md` is separate global identity.
49
+ - Hermes loads one project context type per session, then progressively discovers subdirectory context files as tools touch paths.
50
+ - Context files are security scanned, truncated, and should stay concise with headers, examples, negative constraints, key paths, and stale-context hygiene.
51
+
52
+ Implication for this vault:
53
+
54
+ - Current `AGENTS.md` works as fallback, but Hermes-only usage should prefer a dedicated `HERMES.md` / `.hermes.md` so Hermes does not inherit adapter compromises meant for other agents.
55
+ - Because Hermes progressively discovers subdirectory files, scoped context files can be more useful than one giant root instruction file.
56
+
57
+ Hermes memory:
58
+
59
+ - Built-in memory is deliberately tiny: `MEMORY.md` for agent notes and `USER.md` for user profile, both loaded once as a frozen snapshot at session start.
60
+ - Hermes explicitly separates always-on memory from on-demand session search.
61
+ - Memory writes can be gated with approval, and memory entries should be compact, specific, and non-duplicative.
62
+
63
+ Implication for this vault:
64
+
65
+ - Keep Hermes memory small and use the vault as the long-term source of truth.
66
+ - Add a Hermes memory sync policy: what goes to `~/.hermes/memories/MEMORY.md`, what stays in `Shared/User-Memory`, what is retrieved on demand from vault search/session logs.
67
+
68
+ Hermes skills:
69
+
70
+ - Skills are on-demand knowledge documents with progressive disclosure.
71
+ - `SKILL.md` supports references, templates, scripts, assets, platform restrictions, required environment variables, and verification sections.
72
+ - Hermes can scan external skill directories, but writable external dirs are not a write-protection boundary.
73
+
74
+ Implication for this vault:
75
+
76
+ - Current `.agents/skills/` can become a shared skill source, but it needs an explicit policy for which skills are read-only, owner-authored, or agent-created.
77
+ - Useful repeatable vault workflows should graduate into Hermes skills only after they have examples, pitfalls, and verification.
78
+
79
+ Hermes curator:
80
+
81
+ - The curator tracks skill usage, marks stale skills, archives long-unused skills, and can optionally run an LLM consolidation pass.
82
+ - It has status, dry-run, backup, rollback, pin, and archive commands.
83
+
84
+ Implication for this vault:
85
+
86
+ - Add curator-like vault health reviews: stale context, duplicated rules, unused context packs, benchmark drift, and skills that should be archived or pinned.
87
+
88
+ ## Evidence From Agent Research
89
+
90
+ Context engineering:
91
+
92
+ - Anthropic frames context as finite and context engineering as the task of curating all tokens available to an agent across long-running loops, not just writing better prompts.
93
+ - This supports the current Scientific Loop Sequence and argues for smaller, task-specific retrieval bundles rather than a larger global instruction file.
94
+
95
+ Memory taxonomy:
96
+
97
+ - LangGraph separates short-term thread-scoped memory from long-term memory across conversations, and uses semantic, episodic, and procedural memory categories.
98
+ - Generative Agents stores experiences, synthesizes reflections, and retrieves memories dynamically for planning.
99
+ - MemGPT argues for tiered memory and movement between fast context and slower external memory.
100
+ - Reflexion stores reflective text in episodic memory after feedback to improve future trials.
101
+ - ReAct shows the value of interleaving reasoning/action with external information retrieval.
102
+
103
+ Implication for this vault:
104
+
105
+ - Current folders already map well:
106
+ - semantic memory -> `Learning/`, `Distillations/`, `Entities/`, `Shared/Core-Facts/`
107
+ - episodic memory -> `Sessions/`, `Retrospectives/`, `Traces/`
108
+ - procedural memory -> `Runbooks/`, `Playbooks/`, `Skills/`, `.agents/skills/`
109
+ - eval/reflection memory -> `Evals/`, `Acceptance/`, `Reviews/`
110
+ - The missing piece is not another generic "Resources" folder. It is sharper eval cases, Hermes adapter policy, and scheduled consolidation.
111
+
112
+ PKM / PARA:
113
+
114
+ - PARA's Projects / Areas / Resources / Archives split supports action-oriented retrieval.
115
+ - This vault already extends PARA with AI-specific layers: Evals, Acceptance, Rules, Context-Packs, Provenance, Coordination.
116
+
117
+ Implication for this vault:
118
+
119
+ - Avoid adding broad folders like `Resources/`, `Notes/`, or `AI/`; they would overlap existing canonical homes.
120
+
121
+ ## Gap Analysis
122
+
123
+ | Gap | Current coverage | Recommended addition | Priority |
124
+ |---|---|---|---|
125
+ | Hermes-specific project context | `AGENTS.md` only | `HERMES.md` or `.hermes.md` pointing to hot path and Hermes-only rules | P0 |
126
+ | Hermes memory policy | `Shared/User-Memory`, `Shared/Memory-Inbox`, `USER.md` | `Shared/Hermes/memory-sync-policy.md` or `Shared/Agent-Adapters/hermes-memory.md` | P0 |
127
+ | Hermes skill lifecycle | `.agents/skills`, `Skills/`, `Shared/Rules/skills-admission` | `Shared/Hermes/skill-lifecycle.md` plus first Hermes skill for second-brain maintenance | P1 |
128
+ | Atomic benchmarks | `Evals/second-brain-benchmarks.md` | `Evals/Benchmarks/<case-id>.md` | P1 |
129
+ | Golden fixtures | `Acceptance/golden-case-template.md` | `Acceptance/Golden-Cases/<workflow>.md` | P1 |
130
+ | Scheduled vault health | `Reviews/`, `Runbooks/sleep-time-consolidation.md` | `Reviews/Vault-Health/YYYY-MM-DD.md` | P1 |
131
+ | Prompt-injection trust boundary | `Intake/_Quarantine`, `ingest-quarantine`, Hermes scanner | `Shared/Security/trust-boundaries.md` only if rules grow beyond current files | P2 |
132
+ | Tool inventory and MCP capabilities | `Tools/`, `Shared/mcp-servers`, `Tech-Standards` | `Shared/Hermes/toolsets.md` if Hermes profiles/toolsets become important | P2 |
133
+ | Output artifacts per project | `Projects/<proj>/` role allows deliverables | Add `Projects/<proj>/Artifacts/` only inside active projects with many generated files | P2 |
134
+
135
+ ## Recommended Next Build
136
+
137
+ Best next bundle:
138
+
139
+ 1. Add `second-brain/HERMES.md`.
140
+ 2. Add `second-brain/Shared/Hermes/_Index.md`.
141
+ 3. Add `second-brain/Shared/Hermes/memory-sync-policy.md`.
142
+ 4. Add `second-brain/Shared/Hermes/skill-lifecycle.md`.
143
+ 5. Add `second-brain/Shared/Context-Packs/hermes-cli-vault-maintenance.md`.
144
+ 6. Split 3-5 high-value cases from `Evals/second-brain-benchmarks.md` into `Evals/Benchmarks/`.
145
+
146
+ Implementation caution:
147
+
148
+ - If adding new folders, update [[Vault Structure Map]] and any folder scaffold source such as `src/brain.ts`.
149
+ - If adding only files under existing folders, keep the current taxonomy stable.
150
+ - Do not mirror Hermes `~/.hermes/` wholesale into the vault; keep local runtime state in Hermes home and store only policy, reviewed snapshots, and durable decisions here.
151
+
152
+ ## Do Not Add Yet
153
+
154
+ - `Resources/` root folder: overlaps `Research/`, `Learning/`, and `Distillations/`.
155
+ - `Notes/` root folder: becomes a junk drawer and weakens routing.
156
+ - `AI/` root folder: duplicates `Shared/AI-Context-Index`, agent adapters, rules, and context packs.
157
+ - `Archive/` root folder: `Shared/Archive/` already exists.
158
+ - `Experiments/` root folder: use `Research/`, `Evals/`, or `Sessions/` depending on artifact type.
159
+
160
+ up:: [[Research/_Index]]