sanook-cli 0.5.0 → 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 (146) hide show
  1. package/.env.example +161 -3
  2. package/CHANGELOG.md +83 -5
  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 +3045 -210
  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 +86 -38
  61. package/dist/providers/keys.js +1 -1
  62. package/dist/providers/models.js +22 -6
  63. package/dist/providers/registry.js +38 -49
  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 +57 -11
  85. package/dist/ui/brain-wizard.js +2 -2
  86. package/dist/ui/history.js +37 -5
  87. package/dist/ui/mentions.js +3 -2
  88. package/dist/ui/render.js +55 -15
  89. package/dist/ui/setup.js +107 -10
  90. package/dist/update.js +24 -11
  91. package/dist/worktree.js +175 -4
  92. package/package.json +4 -4
  93. package/second-brain/AGENTS.md +6 -4
  94. package/second-brain/CLAUDE.md +7 -1
  95. package/second-brain/Evals/_Index.md +10 -2
  96. package/second-brain/Evals/quality-ledger.md +9 -1
  97. package/second-brain/Evals/second-brain-benchmarks.md +62 -0
  98. package/second-brain/GEMINI.md +5 -4
  99. package/second-brain/Home.md +1 -1
  100. package/second-brain/Projects/_Index.md +3 -1
  101. package/second-brain/Projects/sanook-cli/_Index.md +26 -0
  102. package/second-brain/Projects/sanook-cli/second-brain-feature-roadmap.md +156 -0
  103. package/second-brain/README.md +1 -1
  104. package/second-brain/Research/2026-06-17-ai-second-brain-method-experiment.md +108 -0
  105. package/second-brain/Research/2026-06-18-ai-token-reduction-frameworks.md +55 -0
  106. package/second-brain/Research/2026-06-18-hermes-cli-second-brain-expansion-research.md +160 -0
  107. package/second-brain/Research/2026-06-18-sanook-mcp-ecosystem-and-ux-roadmap.md +181 -0
  108. package/second-brain/Research/_Index.md +6 -1
  109. package/second-brain/Reviews/2026-06-18-auto-improve-maintenance.md +54 -0
  110. package/second-brain/Reviews/_Index.md +1 -1
  111. package/second-brain/Runbooks/_Index.md +6 -1
  112. package/second-brain/Runbooks/ai-second-brain-operating-sequence.md +108 -0
  113. package/second-brain/SANOOK.md +45 -0
  114. package/second-brain/Sessions/2026-06-17-ai-framework-additional-zones.md +68 -0
  115. package/second-brain/Sessions/2026-06-17-ai-second-brain-sequence-experiment.md +63 -0
  116. package/second-brain/Sessions/2026-06-18-cli-args-release-readiness.md +59 -0
  117. package/second-brain/Sessions/2026-06-18-final-gate-template-final.md +192 -0
  118. package/second-brain/Sessions/2026-06-18-final-gate-template.md +71 -0
  119. package/second-brain/Sessions/2026-06-18-framework-dogfood-permission-and-memory.md +58 -0
  120. package/second-brain/Sessions/2026-06-18-hermes-second-brain-expansion-research.md +52 -0
  121. package/second-brain/Sessions/2026-06-18-mcp-ecosystem-and-sanook-ux-scan.md +81 -0
  122. package/second-brain/Sessions/2026-06-18-sanook-brain-cli-p0-implementation.md +86 -0
  123. package/second-brain/Sessions/2026-06-18-sanook-brain-final-cli-final.md +246 -0
  124. package/second-brain/Sessions/2026-06-18-sanook-brain-final-cli.md +78 -0
  125. package/second-brain/Sessions/2026-06-18-sanook-cli-second-brain-roadmap-correction.md +54 -0
  126. package/second-brain/Sessions/2026-06-18-token-reduction-framework-integration.md +69 -0
  127. package/second-brain/Sessions/_Index.md +15 -1
  128. package/second-brain/Shared/AI-Context-Index.md +22 -0
  129. package/second-brain/Shared/Context-Packs/_Index.md +9 -1
  130. package/second-brain/Shared/Context-Packs/coding-release.md +51 -0
  131. package/second-brain/Shared/Context-Packs/research-to-framework.md +51 -0
  132. package/second-brain/Shared/Context-Packs/second-brain-maintenance.md +41 -0
  133. package/second-brain/Shared/Operating-State/current-state.md +22 -3
  134. package/second-brain/Shared/Scripts/_Index.md +3 -1
  135. package/second-brain/Shared/Scripts/ai-second-brain-method-eval.mjs +198 -0
  136. package/second-brain/Shared/Tech-Standards/_Index.md +4 -1
  137. package/second-brain/Shared/Tech-Standards/mcp-integration-roadmap.md +86 -0
  138. package/second-brain/Shared/Tech-Standards/verification-standard.md +24 -0
  139. package/second-brain/Shared/User-Memory/_Index.md +4 -1
  140. package/second-brain/Shared/User-Memory/response-examples.md +98 -0
  141. package/second-brain/Shared/User-Memory/user-preferences.md +1 -0
  142. package/second-brain/Templates/_Index.md +9 -0
  143. package/second-brain/Templates/final-lite.md +111 -0
  144. package/second-brain/Templates/final.md +231 -0
  145. package/second-brain/Vault Structure Map.md +2 -1
  146. package/skills/structured-output-llm/SKILL.md +1 -1
@@ -0,0 +1,69 @@
1
+ ---
2
+ tags: [session, token-reduction, sanook-cli, ai-agent]
3
+ note_type: session-log
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Sessions/_Index]]"
7
+ ai_surface: history
8
+ ---
9
+
10
+ # 2026-06-18 - Token Reduction Framework Integration
11
+
12
+ > Session log for researching GitHub token-reduction frameworks and integrating a safe default into Sanook CLI.
13
+
14
+ ## Summary
15
+
16
+ - Compared GitHub frameworks/patterns: Microsoft LLMLingua, Selective Context, and Headroom.
17
+ - Chose a Sanook-native selective context compressor as the default because it works without Python, model downloads, proxy services, or extra keys.
18
+ - Added `contextCompression: selective | headroom | off` with `SANOOK_CONTEXT_COMPRESSION`.
19
+ - Integrated the actual `headroom-ai` Vercel AI SDK adapter as an optional framework mode.
20
+ - Improved local selective mode with query-aware scoring and adaptive budgets for older stale tool outputs.
21
+ - Wired selective compression into the Vercel AI SDK `prepareStep` path, targeting stale huge tool outputs only.
22
+
23
+ ## What Was Tried
24
+
25
+ - Inspected Sanook's existing token controls: prompt cache, auto-compaction, summarize-compaction, subagents, read ranges, output truncation.
26
+ - Checked `headroom-ai` npm package and Vercel AI adapter.
27
+ - Decided not to require Headroom by default because direct compression requires a proxy/cloud key, but added opt-in support.
28
+
29
+ ## Errors
30
+
31
+ - A first patch to `selectivelyCompressStaleToolResults()` returned too early and left unreachable code; fixed by returning the mapped output only when a change occurred.
32
+ - A broad test patch missed exact context; re-applied as focused patches.
33
+
34
+ ## Solutions
35
+
36
+ - Added `src/context-compression.ts` with `selectiveCompressText()`.
37
+ - Added `selectivelyCompressStaleToolResults()` in `src/compaction.ts`.
38
+ - Updated `src/loop.ts` to apply selective compression before `autoCompact()`.
39
+ - The compressor now uses the latest user message to boost relevant lines and spends fewer chars on older stale tool results.
40
+ - Updated config schema, env parsing, CLI validation, README, changelog, and tests.
41
+ - Added `headroom-ai` as a dependency for optional framework-backed compression.
42
+
43
+ ## Key Decisions
44
+
45
+ - Preserve recent tool results fully.
46
+ - Compress only stale large tool output, not user intent or recent evidence.
47
+ - Keep this zero-LLM by default; use Headroom only when the user opts into a proxy/cloud setup.
48
+
49
+ ## Files Changed
50
+
51
+ - `src/context-compression.ts`
52
+ - `src/context-compression.test.ts`
53
+ - `src/compaction.ts`
54
+ - `src/compaction.test.ts`
55
+ - `src/config.ts`
56
+ - `src/config.test.ts`
57
+ - `src/loop.ts`
58
+ - `src/bin.ts`
59
+ - `README.md`
60
+ - `CHANGELOG.md`
61
+ - `second-brain/Research/2026-06-18-ai-token-reduction-frameworks.md`
62
+
63
+ ## Next Steps
64
+
65
+ - Run typecheck and tests.
66
+ - Benchmark local selective mode with real multi-step traces.
67
+ - Smoke test Headroom mode against a real proxy/cloud setup when credentials are available.
68
+
69
+ up:: [[Sessions/_Index]]
@@ -25,6 +25,20 @@ code/config · subfolder (Sessions = flat เสมอ)
25
25
 
26
26
  > รายละเอียดทุกโฟลเดอร์ + decision rules → [[Vault Structure Map]]
27
27
 
28
- _(ยังว่าง — โน้ตในโฟลเดอร์นี้จะถูกลิงก์ที่นี่)_
28
+ ## Sessions
29
+
30
+ - [[Sessions/2026-06-17-ai-second-brain-sequence-experiment]] — ทดลองและปรับ AI operating sequence ของ second-brain
31
+ - [[Sessions/2026-06-17-ai-framework-additional-zones]] — เพิ่ม benchmark, response examples, และ context packs เข้า framework
32
+ - [[Sessions/2026-06-18-framework-dogfood-permission-and-memory]] — ใช้ context packs ใหม่กับ permission/tools + memory update + benchmark dogfood
33
+ - [[Sessions/2026-06-18-cli-args-release-readiness]] — ตรวจ cli-args serve port UX + release readiness gates
34
+ - [[Sessions/2026-06-18-hermes-second-brain-expansion-research]] — วิจัยว่า second-brain ควรเพิ่มอะไรเพื่อรองรับ Hermes CLI ให้ดีขึ้น
35
+ - [[Sessions/2026-06-18-sanook-cli-second-brain-roadmap-correction]] — correction: เป้าจริงคือทำ second-brain feature ใน Sanook CLI
36
+ - [[Sessions/2026-06-18-sanook-brain-cli-p0-implementation]] — implement `brain doctor`, `brain context`, `brain eval`, and `brain review`
37
+ - [[Sessions/2026-06-18-final-gate-template]] — add evidence-backed [[Templates/final]] final gate
38
+ - [[Sessions/2026-06-18-final-gate-template-final]] — evidence-backed closeout for the final gate template work
39
+ - [[Sessions/2026-06-18-sanook-brain-final-cli]] — implement `sanook brain final`, final-lite, review validation, and eval coverage
40
+ - [[Sessions/2026-06-18-sanook-brain-final-cli-final]] — evidence-backed closeout for the Sanook brain final CLI work
41
+ - [[Sessions/2026-06-18-mcp-ecosystem-and-sanook-ux-scan]] — scan Sanook MCP support and registry-based integration opportunities
42
+ - [[Sessions/2026-06-18-token-reduction-framework-integration]] — integrate selective context compression after GitHub framework scan
29
43
 
30
44
  up:: [[Home]]
@@ -28,6 +28,23 @@ ai_surface: hot
28
28
  4. [[Shared/Decision-Memory/decision-log]] — ตัดสินใจอะไรไปแล้ว
29
29
  5. งาน project → [[Projects/_Index]] → overview → context → current-state
30
30
 
31
+ ## Best AI Operating Sequence
32
+
33
+ > default สำหรับงานไม่ trivial: [[Runbooks/ai-second-brain-operating-sequence]]
34
+
35
+ **Frame → Retrieve → Role → JIT Rules → Act → Write → Eval → Consolidate**
36
+
37
+ - เริ่มด้วย hot path ด้านบนเสมอ
38
+ - เลือกบทบาท AI ก่อนลงมือ: Scientist / Cartographer / Librarian / Operator / Editor / Archivist
39
+ - ถ้ามี pack ตรงงาน ให้ใช้ [[Shared/Context-Packs/_Index]] แทนการประกอบ context ใหม่จากศูนย์
40
+ - โหลด rule/runbook เฉพาะ task นั้นแบบ JIT; อย่าโหลดทั้ง vault
41
+ - งาน framework/หลาย session/แก้ durable memory ให้ eval และบันทึก evidence
42
+
43
+ ## Taste & Benchmarks
44
+
45
+ - owner-facing tone/examples → [[Shared/User-Memory/response-examples]]
46
+ - framework quality checks → [[Evals/second-brain-benchmarks]]
47
+
31
48
  ## Default Write Path (ก่อนสร้าง/แก้โน้ต)
32
49
 
33
50
  1. Classify artifact: project work, session log, decision, preference, source, reusable skill, runbook, or temporary scratch
@@ -50,11 +67,16 @@ ai_surface: hot
50
67
  | scratch ระหว่างงานเดียว | `Shared/Working-Memory/<topic>.md` |
51
68
  | expected output fixture | [[Acceptance/golden-case-template]] |
52
69
  | pre/postflight gate | [[Checklists/preflight-postflight-template]] |
70
+ | final phase / evidence-backed closeout | [[Templates/final]] หรือ [[Templates/final-lite]]; CLI: `sanook brain final --task "..." [--from-diff] [--lite]` |
53
71
  | entity/person/org page | `Entities/<name>.md` |
54
72
  | อื่นๆ / ไม่แน่ใจว่าโฟลเดอร์ไหน | [[Vault Structure Map]] |
55
73
 
56
74
  ## Framework Rules (โหลดตาม task — ดู CLAUDE.md §19)
57
75
 
76
+ - **งานไม่ trivial ทุกงาน** → [[Runbooks/ai-second-brain-operating-sequence]] (Scientific Loop Sequence + roles)
77
+ - **งานซ้ำ/task family ชัดเจน** → [[Shared/Context-Packs/_Index]] (ใช้ context pack แทน assemble ใหม่)
78
+ - **ก่อน/หลังแก้ framework** → [[Evals/second-brain-benchmarks]] (วัดว่าดีขึ้นจริงไหม)
79
+ - **ก่อนตอบว่าเสร็จแล้วในงานไม่ trivial** → `sanook brain final --task "..." [--from-diff]` หรือ [[Templates/final]] / [[Templates/final-lite]] + [[Shared/Tech-Standards/verification-standard]]
58
80
  - **ก่อนประกอบ context เสมอ** → [[Shared/Rules/context-assembly-policy]] (head/tail + budget, กัน context-rot)
59
81
  - ingest ของนอก → [[Runbooks/ingest-quarantine]] · fact → [[Shared/Rules/frontmatter-standard]] (bi-temporal + `source::`)
60
82
  - script ทำซ้ำ → [[Shared/Rules/skills-admission]] (Skills/) · consolidate → [[Runbooks/sleep-time-consolidation]]
@@ -25,6 +25,14 @@ pack รวม context พร้อมโหลด
25
25
 
26
26
  > รายละเอียดทุกโฟลเดอร์ + decision rules → [[Vault Structure Map]]
27
27
 
28
- _(ยังว่าง โน้ตในโฟลเดอร์นี้จะถูกลิงก์ที่นี่)_
28
+ ## Context Packs
29
+
30
+ - [[Shared/Context-Packs/second-brain-maintenance]] — แก้ vault structure, routing, memory policy, indexes, runbooks, agent adapters
31
+ - [[Shared/Context-Packs/coding-release]] — แก้ code/tests/build/release/CLI scripts
32
+ - [[Shared/Context-Packs/research-to-framework]] — research/experiment → framework update
33
+
34
+ ## Use Rule
35
+
36
+ โหลด pack เมื่อ task ตรงกับ pack ชัดเจน; ถ้าไม่ตรงให้ใช้ [[Shared/AI-Context-Index]] + JIT rules ปกติ
29
37
 
30
38
  up:: [[Shared/_Index]]
@@ -0,0 +1,51 @@
1
+ ---
2
+ tags: [context-pack, coding, release, verification]
3
+ note_type: context-pack
4
+ created: 2026-06-17
5
+ updated: 2026-06-17
6
+ parent: "[[Shared/Context-Packs/_Index]]"
7
+ ---
8
+
9
+ # Context Pack: Coding & Release Work
10
+
11
+ > Use when changing source code, tests, build/release behavior, CLI commands, or scripts that affect runtime behavior.
12
+
13
+ ## Load Order
14
+
15
+ 1. [[Shared/AI-Context-Index]]
16
+ 2. [[Runbooks/ai-second-brain-operating-sequence]]
17
+ 3. [[Shared/Tech-Standards/verification-standard]]
18
+ 4. Relevant project/source files
19
+ 5. Relevant tests
20
+ 6. [[Evals/second-brain-benchmarks]] only if the change affects AI/vault framework
21
+
22
+ ## Required Role
23
+
24
+ - Primary: Operator
25
+ - Secondary: Scientist
26
+
27
+ ## Verification Menu
28
+
29
+ Pick the narrowest set that proves the change:
30
+
31
+ - targeted test
32
+ - full test suite
33
+ - typecheck
34
+ - build
35
+ - smoke command
36
+ - diff/scan gate
37
+
38
+ ## Output Artifacts
39
+
40
+ - Code/test/docs changes
41
+ - Short owner-facing summary with verification
42
+ - Session log if the work is non-trivial or changes durable framework behavior
43
+
44
+ ## Done Criteria
45
+
46
+ - Source read before editing
47
+ - Tests or explicit unable-to-run note
48
+ - No destructive command without owner approval
49
+ - Residual risk stated if verification is partial
50
+
51
+ up:: [[Shared/Context-Packs/_Index]]
@@ -0,0 +1,51 @@
1
+ ---
2
+ tags: [context-pack, research, framework, ai]
3
+ note_type: context-pack
4
+ created: 2026-06-17
5
+ updated: 2026-06-17
6
+ parent: "[[Shared/Context-Packs/_Index]]"
7
+ ---
8
+
9
+ # Context Pack: Research To Framework
10
+
11
+ > Use when the owner asks for best method, comparison, experiment, or turning research into framework changes.
12
+
13
+ ## Load Order
14
+
15
+ 1. [[Shared/AI-Context-Index]]
16
+ 2. [[Runbooks/ai-second-brain-operating-sequence]]
17
+ 3. [[Shared/Rules/context-assembly-policy]]
18
+ 4. [[Evals/second-brain-benchmarks]]
19
+ 5. Relevant prior research notes
20
+ 6. Target framework files or destination `_Index.md`
21
+
22
+ ## Required Role
23
+
24
+ - Primary: Scientist
25
+ - Secondary: Librarian
26
+
27
+ ## Method
28
+
29
+ 1. State hypothesis.
30
+ 2. Define candidates.
31
+ 3. Define metrics before judging.
32
+ 4. Run a small reproducible check when possible.
33
+ 5. Record result in `Research/` if it is evidence-bearing.
34
+ 6. Promote the winner into `Runbooks/`, `Rules/`, `Context-Packs/`, or `Playbooks/` only after evidence.
35
+ 7. Wire the result into indexes/hot path.
36
+
37
+ ## Output Artifacts
38
+
39
+ - Research note with method/results
40
+ - Framework/runbook/rule update
41
+ - Quality-ledger entry for non-trivial changes
42
+ - Session log when files are changed
43
+
44
+ ## Done Criteria
45
+
46
+ - Recommendation is evidence-backed
47
+ - Tradeoffs are explicit
48
+ - Framework is actually changed, not only summarized
49
+ - Owner-facing final answer names files and verification
50
+
51
+ up:: [[Shared/Context-Packs/_Index]]
@@ -0,0 +1,41 @@
1
+ ---
2
+ tags: [context-pack, second-brain, maintenance]
3
+ note_type: context-pack
4
+ created: 2026-06-17
5
+ updated: 2026-06-17
6
+ parent: "[[Shared/Context-Packs/_Index]]"
7
+ ---
8
+
9
+ # Context Pack: Second-Brain Maintenance
10
+
11
+ > Use when editing vault structure, routing rules, memory policy, indexes, runbooks, or agent adapters.
12
+
13
+ ## Load Order
14
+
15
+ 1. [[Shared/AI-Context-Index]]
16
+ 2. [[Runbooks/ai-second-brain-operating-sequence]]
17
+ 3. [[Vault Structure Map]]
18
+ 4. [[Shared/Rules/context-assembly-policy]]
19
+ 5. Destination `_Index.md`
20
+ 6. [[Shared/Rules/memory-write-protocol]] if changing memory/facts
21
+ 7. [[Evals/second-brain-benchmarks]] before and after framework edits
22
+
23
+ ## Required Role
24
+
25
+ - Primary: Librarian
26
+ - Secondary: Scientist
27
+
28
+ ## Output Artifacts
29
+
30
+ - Updated target note/index
31
+ - Quality/evidence note when non-trivial: [[Evals/quality-ledger]] or [[Sessions/_Index]]
32
+ - No new root folder unless [[Vault Structure Map]] is updated and drift tests are considered
33
+
34
+ ## Done Criteria
35
+
36
+ - New/changed notes have `parent` and `up::`
37
+ - Index links make the artifact discoverable
38
+ - Benchmark or explicit verification is recorded
39
+ - Context bloat is checked; do not preload every rule
40
+
41
+ up:: [[Shared/Context-Packs/_Index]]
@@ -13,11 +13,24 @@ ai_surface: starter
13
13
 
14
14
  ## Now
15
15
 
16
- _(งาน/โฟกัสหลักตอนนี้ ยังว่าง)_
16
+ - 2026-06-17: ปรับ second-brain ให้ใช้ [[Runbooks/ai-second-brain-operating-sequence]] เป็น default AI operating sequence หลังทดลองเทียบ methods แล้ว
17
+ - 2026-06-17: เพิ่ม [[Evals/second-brain-benchmarks]], [[Shared/User-Memory/response-examples]], และ context packs ใน [[Shared/Context-Packs/_Index]]
18
+ - 2026-06-18: dogfood context packs กับงานจริง 3 task-family แล้ว: coding-release, second-brain-maintenance, research-to-framework
19
+ - 2026-06-18: ตรวจ cli-args serve port UX change แล้ว; targeted/full tests, typecheck, build, diff check ผ่าน
20
+ - 2026-06-18: วิจัย Hermes CLI second-brain expansion ไว้เป็น reference; เจ้าของ clarify ว่าเป้าจริงคือทำใน Sanook CLI
21
+ - 2026-06-18: Sanook-native P0 implemented: `sanook brain doctor`, `sanook brain context`, `sanook brain eval`
22
+ - 2026-06-18: เพิ่ม `sanook brain review` เป็น curator review แบบ read-only สำหรับ inbox/context-packs/sessions/evals/note hygiene
23
+ - 2026-06-18: เพิ่ม [[Templates/final]] เป็น final gate / evidence matrix ก่อนปิดงาน non-trivial
24
+ - 2026-06-18: เพิ่ม `sanook brain final`, [[Templates/final-lite]], final-gate validator ใน `brain review`, และ `SB-FINAL` ใน `brain eval` แล้ว
25
+ - 2026-06-18: MCP P0 implemented ใน Sanook CLI แล้ว: registry-backed `mcp search/info/install/preset/test/doctor/list --tools`; verification ผ่าน และพบว่า GitLab remote ต้อง auth header ก่อน probe ผ่าน
26
+ - 2026-06-18: เพิ่ม [[Research/2026-06-18-ai-token-reduction-frameworks]], default query-aware selective context compression, adaptive stale-tool budgets, และ optional Headroom framework mode ใน Sanook CLI
17
27
 
18
28
  ## Active Bets
19
29
 
20
- _(สิ่งที่กำลังลงแรง/ลงทุน)_
30
+ - Scientific Loop Sequence: single retrieval path + JIT task rules + explicit write routing + eval/consolidation loop
31
+ - AI จะเก่งขึ้นแบบวัดได้เมื่อมี benchmark + taste examples + reusable context packs
32
+ - Final gate ที่มี evidence และ CLI scaffold จะลดการ claim done เกินจริงตอนปิดงาน
33
+ - Token/cost จะลดได้อย่างปลอดภัยที่สุดจาก stale tool-output compression ก่อน ไม่ใช่บีบ user intent หรือ recent evidence
21
34
 
22
35
  ## Blockers
23
36
 
@@ -25,6 +38,12 @@ _(ติดอะไรอยู่)_
25
38
 
26
39
  ## Next Actions
27
40
 
28
- - [ ] _(เริ่มจดงานแรกที่นี่)_
41
+ - [ ] Review remaining worktree diff before commit/release
42
+ - [ ] Dogfood `sanook brain final --task "..." --from-diff` ในงาน implementation ถัดไป
43
+ - [x] ทำ MCP P0: `sanook mcp search`, `sanook mcp info`, `sanook mcp install`, `sanook mcp test`
44
+ - [ ] MCP follow-up: auth hints for hosted remotes that return `401`, risk labels, and richer install preview/cache
45
+ - [ ] Token compression follow-up: benchmark real multi-step traces and smoke test Headroom mode with a real proxy/cloud setup
46
+ - [ ] ถ้าจะต่อ second-brain CLI รอบถัดไป: ทำ `sanook brain pack list|show`, `sanook brain new <type>`, หรือ `sanook brain repair`
47
+ - [ ] เพิ่ม good/bad examples ใหม่ใน [[Shared/User-Memory/response-examples]] เมื่อมี feedback จริงรอบถัดไป
29
48
 
30
49
  up:: [[Shared/Operating-State/_Index]]
@@ -25,6 +25,8 @@ one-off ที่ retired (→Scripts-Archive)
25
25
 
26
26
  > รายละเอียดทุกโฟลเดอร์ + decision rules → [[Vault Structure Map]]
27
27
 
28
- _(ยังว่าง — โน้ตในโฟลเดอร์นี้จะถูกลิงก์ที่นี่)_
28
+ ## Scripts
29
+
30
+ - `Shared/Scripts/ai-second-brain-method-eval.mjs` — reproducible eval เปรียบเทียบ AI second-brain operating methods; ใช้เป็น evidence ของ [[Research/2026-06-17-ai-second-brain-method-experiment]]
29
31
 
30
32
  up:: [[Shared/_Index]]
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+
5
+ const vault = process.argv[2] ?? 'second-brain';
6
+
7
+ const files = {
8
+ aiIndex: 'Shared/AI-Context-Index.md',
9
+ user: 'USER.md',
10
+ currentState: 'Shared/Operating-State/current-state.md',
11
+ preferences: 'Shared/User-Memory/user-preferences.md',
12
+ decisions: 'Shared/Decision-Memory/decision-log.md',
13
+ structureMap: 'Vault Structure Map.md',
14
+ contextPolicy: 'Shared/Rules/context-assembly-policy.md',
15
+ noteRule: 'Shared/Rules/contextual-note-rule.md',
16
+ formatting: 'Shared/Rules/rules-formatting.md',
17
+ memoryWrite: 'Shared/Rules/memory-write-protocol.md',
18
+ frontmatter: 'Shared/Rules/frontmatter-standard.md',
19
+ ingest: 'Runbooks/ingest-quarantine.md',
20
+ sleep: 'Runbooks/sleep-time-consolidation.md',
21
+ evalLoop: 'Runbooks/eval-loop.md',
22
+ retrievalEval: 'Evals/retrieval-eval.md',
23
+ qualityLedger: 'Evals/quality-ledger.md',
24
+ verification: 'Shared/Tech-Standards/verification-standard.md',
25
+ coordinationNow: 'Shared/Coordination/NOW.md',
26
+ taskBoard: 'Shared/Coordination/task-board.md',
27
+ agentRegistry: 'Shared/Coordination/agent-registry.md',
28
+ sessionsIndex: 'Sessions/_Index.md',
29
+ runbooksIndex: 'Runbooks/_Index.md',
30
+ scriptsIndex: 'Shared/Scripts/_Index.md',
31
+ };
32
+
33
+ function fileTokens(path) {
34
+ const full = join(vault, path);
35
+ if (!existsSync(full)) return { exists: false, tokens: 0 };
36
+ return { exists: true, tokens: Math.ceil(readFileSync(full, 'utf8').length / 4) };
37
+ }
38
+
39
+ const scenarios = [
40
+ {
41
+ id: 'start-session',
42
+ label: 'เริ่มงานกับ AI โดยไม่หลุด source of truth',
43
+ required: [files.aiIndex, files.user, files.currentState, files.preferences, files.decisions],
44
+ capabilities: ['retrieval', 'state', 'preference'],
45
+ },
46
+ {
47
+ id: 'write-durable-note',
48
+ label: 'สร้าง/แก้ durable note ให้ถูกที่และค้นเจอภายหลัง',
49
+ required: [files.aiIndex, files.structureMap, files.contextPolicy, files.noteRule, files.formatting],
50
+ capabilities: ['retrieval', 'routing', 'write-contract', 'graph-linking'],
51
+ },
52
+ {
53
+ id: 'write-memory',
54
+ label: 'บันทึก preference/decision/fact โดยไม่ append ซ้ำ',
55
+ required: [files.aiIndex, files.memoryWrite, files.frontmatter, files.preferences, files.decisions],
56
+ capabilities: ['memory-op', 'dedupe', 'verification'],
57
+ },
58
+ {
59
+ id: 'ingest-source',
60
+ label: 'นำข้อมูลภายนอกเข้า vault แบบปลอด prompt injection',
61
+ required: [files.aiIndex, files.ingest, files.frontmatter, files.structureMap],
62
+ capabilities: ['ingest-safety', 'provenance', 'routing'],
63
+ },
64
+ {
65
+ id: 'consolidate',
66
+ label: 'ทำ sleep-time consolidation และปิด loop ความจำ',
67
+ required: [files.aiIndex, files.sleep, files.memoryWrite, files.retrievalEval, files.qualityLedger],
68
+ capabilities: ['consolidation', 'memory-op', 'eval'],
69
+ },
70
+ {
71
+ id: 'multi-agent',
72
+ label: 'กันหลาย agent ชนกันและส่งต่องานได้',
73
+ required: [files.aiIndex, files.coordinationNow, files.taskBoard, files.agentRegistry, files.sessionsIndex],
74
+ capabilities: ['coordination', 'handoff', 'session-log'],
75
+ },
76
+ {
77
+ id: 'technical-work',
78
+ label: 'งานเทคนิคที่ต้อง verify ก่อนสรุป',
79
+ required: [files.aiIndex, files.verification, files.evalLoop, files.sessionsIndex],
80
+ capabilities: ['verification', 'eval', 'session-log'],
81
+ },
82
+ ];
83
+
84
+ const methods = [
85
+ {
86
+ id: 'session-log-only',
87
+ label: 'Session-log only',
88
+ filesFor: () => [files.sessionsIndex],
89
+ capabilities: ['session-log'],
90
+ },
91
+ {
92
+ id: 'folder-map-only',
93
+ label: 'Folder map + destination indexes',
94
+ filesFor: (scenario) => [files.structureMap, files.sessionsIndex, ...scenario.required.filter((p) => p.endsWith('_Index.md'))],
95
+ capabilities: ['routing', 'session-log'],
96
+ },
97
+ {
98
+ id: 'single-context-index',
99
+ label: 'Single retrieval index',
100
+ filesFor: () => [files.aiIndex, files.user, files.currentState, files.preferences, files.decisions],
101
+ capabilities: ['retrieval', 'state', 'preference'],
102
+ },
103
+ {
104
+ id: 'jit-context-policy',
105
+ label: 'Index + JIT context policy',
106
+ filesFor: (scenario) => [files.aiIndex, files.contextPolicy, ...scenario.required.slice(0, 3)],
107
+ capabilities: ['retrieval', 'state', 'preference', 'routing', 'write-contract', 'graph-linking', 'verification'],
108
+ },
109
+ {
110
+ id: 'scientific-loop-sequence',
111
+ label: 'Scientific loop sequence',
112
+ filesFor: (scenario) => [files.aiIndex, files.contextPolicy, ...scenario.required],
113
+ capabilities: [
114
+ 'retrieval',
115
+ 'state',
116
+ 'preference',
117
+ 'routing',
118
+ 'write-contract',
119
+ 'graph-linking',
120
+ 'memory-op',
121
+ 'dedupe',
122
+ 'verification',
123
+ 'ingest-safety',
124
+ 'provenance',
125
+ 'consolidation',
126
+ 'eval',
127
+ 'coordination',
128
+ 'handoff',
129
+ 'session-log',
130
+ ],
131
+ },
132
+ ];
133
+
134
+ function uniq(items) {
135
+ return [...new Set(items.filter(Boolean))];
136
+ }
137
+
138
+ function scoreScenario(method, scenario) {
139
+ const contextFiles = uniq(method.filesFor(scenario));
140
+ const fileStats = contextFiles.map((path) => ({ path, ...fileTokens(path) }));
141
+ const tokens = fileStats.reduce((sum, stat) => sum + stat.tokens, 0);
142
+ const requiredHits = scenario.required.filter((path) => contextFiles.includes(path) && fileTokens(path).exists).length;
143
+ const existingRequired = scenario.required.filter((path) => fileTokens(path).exists).length;
144
+ const fileCoverage = existingRequired ? requiredHits / existingRequired : 1;
145
+ const capabilityHits = scenario.capabilities.filter((cap) => method.capabilities.includes(cap)).length;
146
+ const capabilityCoverage = scenario.capabilities.length ? capabilityHits / scenario.capabilities.length : 1;
147
+ const economy = tokens <= 2200 ? 1 : Math.max(0, 1 - (tokens - 2200) / 2200);
148
+ const score = Math.round((fileCoverage * 70 + capabilityCoverage * 20 + economy * 10) * 10) / 10;
149
+ return { score, fileCoverage, capabilityCoverage, economy, tokens, contextFiles };
150
+ }
151
+
152
+ const rows = methods.map((method) => {
153
+ const perScenario = scenarios.map((scenario) => scoreScenario(method, scenario));
154
+ const avgScore = perScenario.reduce((sum, s) => sum + s.score, 0) / perScenario.length;
155
+ const avgTokens = perScenario.reduce((sum, s) => sum + s.tokens, 0) / perScenario.length;
156
+ const avgFileCoverage = perScenario.reduce((sum, s) => sum + s.fileCoverage, 0) / perScenario.length;
157
+ const avgCapabilityCoverage = perScenario.reduce((sum, s) => sum + s.capabilityCoverage, 0) / perScenario.length;
158
+ return {
159
+ method,
160
+ avgScore: Math.round(avgScore * 10) / 10,
161
+ avgTokens: Math.round(avgTokens),
162
+ avgFileCoverage: Math.round(avgFileCoverage * 100),
163
+ avgCapabilityCoverage: Math.round(avgCapabilityCoverage * 100),
164
+ perScenario,
165
+ };
166
+ });
167
+
168
+ rows.sort((a, b) => b.avgScore - a.avgScore);
169
+
170
+ console.log('# AI Second-Brain Method Eval');
171
+ console.log('');
172
+ console.log(`vault: ${vault}`);
173
+ console.log(`scenarios: ${scenarios.length}`);
174
+ console.log('');
175
+ console.log('| rank | method | score | file coverage | capability coverage | avg tokens |');
176
+ console.log('|---:|---|---:|---:|---:|---:|');
177
+ rows.forEach((row, idx) => {
178
+ console.log(
179
+ `| ${idx + 1} | ${row.method.label} | ${row.avgScore} | ${row.avgFileCoverage}% | ${row.avgCapabilityCoverage}% | ~${row.avgTokens} |`,
180
+ );
181
+ });
182
+ console.log('');
183
+ console.log('## Scenario Detail');
184
+ console.log('');
185
+ for (const row of rows) {
186
+ console.log(`### ${row.method.label}`);
187
+ console.log('| scenario | score | tokens |');
188
+ console.log('|---|---:|---:|');
189
+ row.perScenario.forEach((result, idx) => {
190
+ console.log(`| ${scenarios[idx].label} | ${result.score} | ~${result.tokens} |`);
191
+ });
192
+ console.log('');
193
+ }
194
+
195
+ const best = rows[0];
196
+ console.log('## Winner');
197
+ console.log('');
198
+ console.log(`${best.method.label} (${best.method.id})`);
@@ -25,6 +25,9 @@ MCP/stack/DoD/verification rulebook
25
25
 
26
26
  > รายละเอียดทุกโฟลเดอร์ + decision rules → [[Vault Structure Map]]
27
27
 
28
- _(ยังว่าง — โน้ตในโฟลเดอร์นี้จะถูกลิงก์ที่นี่)_
28
+ ## Standards
29
+
30
+ - [[Shared/Tech-Standards/verification-standard]] — verification ladder, evidence format, and final gate contract
31
+ - [[Shared/Tech-Standards/mcp-integration-roadmap]] — MCP registry/install/test UX roadmap
29
32
 
30
33
  up:: [[Shared/_Index]]
@@ -0,0 +1,86 @@
1
+ ---
2
+ tags: [standard, mcp, integration, roadmap]
3
+ note_type: standard-reference
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Shared/Tech-Standards/_Index]]"
7
+ source:
8
+ - "[[Research/2026-06-18-sanook-mcp-ecosystem-and-ux-roadmap]]"
9
+ ---
10
+
11
+ # MCP Integration Roadmap
12
+
13
+ > Technical roadmap for making MCP easier and safer to use inside Sanook CLI.
14
+
15
+ ## Current Baseline
16
+
17
+ - `src/mcp.ts` supports stdio MCP and remote Streamable HTTP.
18
+ - `src/mcp-server.ts` exposes Sanook's brain as an MCP server.
19
+ - `src/bin.ts` supports `mcp add/list/remove`, `mcp serve`, registry-backed `mcp search/info/install`, curated `mcp preset`, and `mcp test/doctor`.
20
+ - `src/mcp-registry.ts` maps official registry remotes/packages into Sanook `mcp.json`.
21
+ - Project MCP config remains behind `sanook trust`.
22
+
23
+ ## Target UX
24
+
25
+ ```text
26
+ sanook mcp search github
27
+ sanook mcp info com.gitlab/mcp
28
+ sanook mcp install com.gitlab/mcp --name gitlab
29
+ sanook mcp test gitlab
30
+ sanook mcp doctor
31
+ ```
32
+
33
+ ## P0 Requirements
34
+
35
+ 1. Registry search - implemented
36
+ - Query official registry.
37
+ - Show latest versions only by default.
38
+ - Show server name, description, version, transport, package runtime, and source URL.
39
+ 2. Server info - implemented
40
+ - Show remotes/packages.
41
+ - Show required env/header inputs.
42
+ - Mark secret inputs.
43
+ - Show install command preview.
44
+ 3. Install - implemented
45
+ - Convert selected remote/package into Sanook `mcp.json`.
46
+ - Write explicit user-requested config only.
47
+ - Preserve `0600` permissions.
48
+ - Never inherit ambient provider API keys into MCP child env.
49
+ 4. Test - implemented
50
+ - Initialize one server.
51
+ - Run `tools/list`.
52
+ - Report tool count and tool names.
53
+ - Print clear failure reason and setup hints.
54
+
55
+ ## P1 Requirements
56
+
57
+ - `sanook mcp doctor`: validate config shape, missing commands, missing env, unreachable remote, duplicate tool names.
58
+ - `sanook mcp list --tools`: grouped tools by server.
59
+ - `sanook mcp remove` should support exact server names and show config path.
60
+ - Support `--project` install only if project is trusted.
61
+ - Add auth hints when hosted remotes return `401 Unauthorized`.
62
+ - Add registry result caching and risk labels for write-capable servers.
63
+
64
+ ## Safety Policy
65
+
66
+ - Default to read-only where a server offers read-only or scoped modes.
67
+ - Show risk class before enabling:
68
+ - read-only
69
+ - file-write
70
+ - network-write
71
+ - database-write
72
+ - infra/admin
73
+ - Dangerous servers must remain subject to existing approval gates in ask mode.
74
+ - Do not run package installs implicitly during `search` or `info`.
75
+ - For package metadata with `fileSha256`, verify downloaded MCPB packages before running.
76
+
77
+ ## First Presets
78
+
79
+ | Preset | Servers to consider | Use case |
80
+ |---|---|---|
81
+ | `dev` | GitHub/GitLab, Sentry, Context7/docs | coding, PRs, releases, error debugging |
82
+ | `research` | fetch, Brave/web search, docs, Obsidian/GDrive | grounded external research |
83
+ | `pm` | Linear/Jira, Slack/Discord, Notion | task and team workflows |
84
+ | `ops` | Postgres read-only, Docker/Kubernetes, Sentry | operational debugging |
85
+
86
+ up:: [[Shared/Tech-Standards/_Index]]