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
@@ -0,0 +1,246 @@
1
+ ---
2
+ tags: [final-gate, verification, sanook-cli, second-brain]
3
+ note_type: final-gate
4
+ created: 2026-06-18
5
+ updated: 2026-06-18
6
+ parent: "[[Sessions/_Index]]"
7
+ ---
8
+
9
+ # 2026-06-18 - Sanook Brain Final CLI - Final Gate
10
+
11
+ > Evidence-backed closeout for implementing `sanook brain final`, `--from-diff`, [[Templates/final-lite]], final-gate validation, and eval coverage.
12
+
13
+ ## 0. Final Gate Rule
14
+
15
+ - [x] This final gate was created before the final owner-facing answer.
16
+ - [x] Every PASS/PARTIAL/FAIL/BLOCKED claim below has evidence or an explicit reason.
17
+ - [x] No unchecked item is silently treated as done.
18
+ - [x] If evidence is missing, status is `PARTIAL`, `FAIL`, or `BLOCKED`, not `PASS`.
19
+ - [x] If a row has no evidence, it cannot be `PASS`.
20
+
21
+ ## 1. Objective / DoD Lock
22
+
23
+ Original request:
24
+
25
+ ```text
26
+ ทำทั้งหมดมาได้เลย
27
+ ```
28
+
29
+ Expected output:
30
+
31
+ - [x] Add `sanook brain final`.
32
+ - [x] Support `--from-diff`.
33
+ - [x] Add a final-gate validator.
34
+ - [x] Add [[Templates/final-lite]].
35
+ - [x] Integrate final-gate coverage with `sanook brain eval`.
36
+
37
+ Definition of Done:
38
+
39
+ | DoD item | Status | Evidence | Notes |
40
+ |---|---|---|---|
41
+ | CLI can create a final gate note in Sessions. | PASS | `src/brain-final.ts`; temp-vault smoke with `node dist/bin.js brain final --task "smoke final gate" --from-diff` | Smoke created `Sessions/2026-06-18-smoke-final-gate-final.md`. |
42
+ | Diff prefill works. | PASS | `src/brain-final.test.ts`; smoke output `from-diff: 23 file(s)` | Prefills changed-file table from git status. |
43
+ | Lite template exists and is scaffolded. | PASS | `second-brain/Templates/final-lite.md`; `src/brain.test.ts`; temp-vault smoke with `--lite --output Sessions/smoke-lite-final.md` | Scaffold test includes full and lite templates; smoke created a lite final gate. |
44
+ | Review validates final-gate evidence. | PASS | `src/brain-review.ts`; `src/brain-review.test.ts` | Test catches TODO and PASS-without-evidence rows. |
45
+ | Eval covers final-gate contract. | PASS | `src/brain-eval.ts`; `src/brain-eval.test.ts` | `SB-FINAL` case added. |
46
+ | Work is documented and discoverable. | PASS | [[Sessions/2026-06-18-sanook-brain-final-cli]], [[Evals/quality-ledger]], [[Templates/_Index]], [[Shared/AI-Context-Index]] | Index and hot path updated. |
47
+
48
+ Out of scope / non-goals:
49
+
50
+ - No automatic filling of all final-gate evidence rows from tests; the CLI creates a scaffold and prefilled diff evidence, then the agent/owner must complete it.
51
+ - No broad `sanook brain new TYPE` template generator in this change.
52
+
53
+ ## 2. Evidence-Backed Checklist
54
+
55
+ | Gate | Status | Evidence | Notes |
56
+ |---|---|---|---|
57
+ | Relevant source/context was read before editing. | PASS | Read `src/brain.ts`, `src/brain-review.ts`, `src/brain-eval.ts`, `src/bin.ts`, existing templates, and tests | Matched local command/test style. |
58
+ | Existing canonical note/file was searched before creating a new one. | PASS | `rg final-lite|brain final|review.final-gates|SB-FINAL` | No existing CLI final generator was present. |
59
+ | Changes were made in the correct folder/module boundary. | PASS | New logic isolated in `src/brain-final.ts`; docs in second-brain templates/standards/evals | Existing `brain context/eval/review` patterns preserved. |
60
+ | No unrelated user/worktree changes were reverted or overwritten. | PASS | `git status --short` showed `src/config.ts` and `src/config.test.ts` as pre-existing modified files; they were not edited | Mention in final answer. |
61
+ | New/changed durable notes have `parent` and `up::`. | PASS | This file and session log include `parent` and `up::`; scaffold hygiene tests passed | Full tests passed. |
62
+ | Index/backlink/discoverability was updated when needed. | PASS | [[Sessions/_Index]], [[Templates/_Index]], [[Shared/AI-Context-Index]], [[Evals/quality-ledger]] | Links added. |
63
+ | Verification was run at the right scope. | PASS | Targeted tests, typecheck, full tests, build, diff check, CLI smoke | Listed in Evidence Matrix. |
64
+ | Residual risk is stated clearly. | PASS | Residual Risk section | Known limitation documented. |
65
+
66
+ ## 3. Status Matrix
67
+
68
+ | Work item / phase | Status | Evidence | Owner-visible outcome |
69
+ |---|---|---|---|
70
+ | Frame objective and DoD | PASS | Section 1 of this final gate | "ทำทั้งหมด" mapped to five concrete deliverables. |
71
+ | Retrieve required context | PASS | Files inspected list below | Implementation follows existing Sanook brain command structure. |
72
+ | Implement / write / edit | PASS | Files changed list below | New CLI workflow exists. |
73
+ | Verify behavior or artifact | PASS | Commands table below | Tests/build/smoke passed. |
74
+ | Update memory/index/session if needed | PASS | Session, final gate, current-state, quality ledger, Sessions index | Work is traceable. |
75
+ | Prepare final response | PASS | Final-answer draft below | Response can cite verified evidence. |
76
+
77
+ Blocked / partial explanation:
78
+
79
+ - `PARTIAL`: none.
80
+ - `BLOCKED`: none.
81
+
82
+ ## 4. Evidence Matrix
83
+
84
+ Commands:
85
+
86
+ | Command | Status | Important output | Scope proven |
87
+ |---|---|---|---|
88
+ | `npm test -- src/brain-final.test.ts src/brain-review.test.ts src/brain-eval.test.ts src/brain.test.ts` | PASS | 4 files, 37 tests passed | Targeted final/review/eval/scaffold behavior. |
89
+ | `npm run typecheck` | PASS | `tsc --noEmit` passed | TypeScript compile surface. |
90
+ | `npm test` | PASS | 102 files, 881 tests passed | Full current test suite. |
91
+ | `npm run build` | PASS | `tsc -p tsconfig.build.json` passed | Build output compiles. |
92
+ | `git diff --check` | PASS | No output | No whitespace/conflict-marker issues. |
93
+ | `node dist/bin.js brain init ...` then `node dist/bin.js brain final --task "smoke final gate" --from-diff` | PASS | Created temp-vault final note, linked Sessions index, `from-diff: 23 file(s)` | Real CLI path from built output. |
94
+ | `node dist/bin.js brain init ...` then `node dist/bin.js brain final --task "smoke lite final" --lite --output Sessions/smoke-lite-final.md` | PASS | Created temp-vault lite final note and linked Sessions index. | Real lite CLI path from built output. |
95
+
96
+ Files inspected:
97
+
98
+ | File/path | Why it matters | Evidence |
99
+ |---|---|---|
100
+ | `src/brain.ts` | Scaffold/copy pattern | New template covered by scaffold tests. |
101
+ | `src/brain-review.ts` | Existing curator check shape | Added final-gate check in same pattern. |
102
+ | `src/brain-eval.ts` | Existing benchmark runner shape | Added `SB-FINAL`. |
103
+ | `src/bin.ts` | CLI subcommand wiring | Added `runBrainFinal` and dispatcher entry. |
104
+ | `second-brain/Templates/final.md` | Full final gate source | Lite template mirrors section contract. |
105
+
106
+ Files changed:
107
+
108
+ | File/path | Change summary | Evidence |
109
+ |---|---|---|
110
+ | `src/brain-final.ts` | New parser, generator, diff prefill, Sessions index update, and validator helpers. | Targeted tests and typecheck passed. |
111
+ | `src/brain-final.test.ts` | Parser/generation/validator coverage. | Targeted tests passed. |
112
+ | `src/bin.ts` / `src/commands.ts` | CLI help and dispatcher wiring for `brain final`. | CLI smoke passed. |
113
+ | `src/brain-review.ts` / `src/brain-review.test.ts` | Review check for final-gate templates and session final gates. | Targeted tests passed. |
114
+ | `src/brain-eval.ts` / `src/brain-eval.test.ts` | `SB-FINAL` eval case. | Targeted tests passed. |
115
+ | `src/brain.test.ts` | Scaffold/template coverage for `final-lite`. | Targeted tests passed. |
116
+ | `second-brain/Templates/final-lite.md` | New compact evidence-backed final gate template. | Scaffold tests passed. |
117
+ | `second-brain/*` indexes/standards/evals/session files | Discoverability and quality-loop closeout. | This final gate and full tests. |
118
+ | `CHANGELOG.md` | User-facing release note. | Diff reviewed. |
119
+
120
+ Artifacts/rendered outputs:
121
+
122
+ | Artifact | Status | Evidence |
123
+ |---|---|---|
124
+ | Built CLI smoke final note in temp vault | PASS | Smoke output showed created path and Sessions index link. |
125
+
126
+ External sources, if any:
127
+
128
+ | Source | Claim supported | Link / citation |
129
+ |---|---|---|
130
+ | N/A | This task used local repo state only. | N/A |
131
+
132
+ ## 5. Residual Risk
133
+
134
+ Known risk:
135
+
136
+ | Risk | Impact | Mitigation / next check |
137
+ |---|---|---|
138
+ | `--from-diff` uses `git status --porcelain=v1` path parsing and does not deeply unescape exotic quoted paths. | Very unusual filenames may need manual adjustment in the generated evidence table. | Keep generated rows editable; add quoted-path parser later if a real case appears. |
139
+ | Generated final gate still contains TODO rows by design. | `brain review` will warn until the gate is filled. | This is intentional; users/agents must complete evidence before claiming done. |
140
+ | Worktree had unrelated config changes before this task. | Full tests cover current tree, but those files are not part of this implementation. | Final answer names them as untouched unrelated changes. |
141
+
142
+ Checks not run:
143
+
144
+ | Check | Reason not run | Consequence |
145
+ |---|---|---|
146
+ | Visual/browser QA | No frontend or visual artifact changed. | N/A |
147
+
148
+ Do not claim done if:
149
+
150
+ - [x] Required checks passed.
151
+ - [x] Changed behavior was exercised by tests and CLI smoke.
152
+ - [x] Final answer will mention residual risk and unrelated modified files.
153
+
154
+ ## 6. Change Summary Audit
155
+
156
+ What changed:
157
+
158
+ - `sanook brain final` can create full or lite final-gate notes in Sessions.
159
+ - `--from-diff` can prefill changed-file evidence rows.
160
+ - `brain review` validates session final gates.
161
+ - `brain eval` includes `SB-FINAL`.
162
+ - Second-brain docs/indexes/quality ledger/session state now point to the workflow.
163
+
164
+ What did not change:
165
+
166
+ - No broad template generator was added.
167
+ - No automatic evidence completion was added.
168
+ - Pre-existing `src/config.ts` and `src/config.test.ts` changes were not edited.
169
+
170
+ Behavior before:
171
+
172
+ - Final gate existed as a manual template only.
173
+ - Review/eval did not know whether final gates existed or were complete.
174
+
175
+ Behavior after:
176
+
177
+ - Sanook can generate final-gate notes from CLI, smoke-tested through built `dist/bin.js`.
178
+ - Review/eval can keep the final-gate workflow from drifting.
179
+
180
+ Compatibility / migration notes:
181
+
182
+ - Existing vaults without `Templates/final-lite.md` can still run the command because the generator falls back to bundled templates.
183
+
184
+ ## 7. Final Answer Draft
185
+
186
+ ```text
187
+ ทำครบแล้วครับ: เพิ่ม `sanook brain final`, `--from-diff`, `--lite`, final-gate validator ใน `brain review`, และ `SB-FINAL` ใน `brain eval` พร้อม docs/templates/session closeout.
188
+
189
+ Verified:
190
+ - npm test -- src/brain-final.test.ts src/brain-review.test.ts src/brain-eval.test.ts src/brain.test.ts: PASS
191
+ - npm run typecheck: PASS
192
+ - npm test: PASS (102 files, 881 tests)
193
+ - npm run build: PASS
194
+ - git diff --check: PASS
195
+ - built CLI smoke: PASS (`--from-diff` and `--lite`)
196
+
197
+ Note:
198
+ - `src/config.ts` และ `src/config.test.ts` เป็น modified อยู่ก่อนแล้ว ผมไม่ได้แตะสองไฟล์นี้
199
+ ```
200
+
201
+ Final-answer safety check:
202
+
203
+ - [x] Does not claim tests/build/smoke passed unless listed in Evidence Matrix.
204
+ - [x] Names files/commands accurately.
205
+ - [x] Mentions skipped checks or residual risk.
206
+ - [x] Is concise enough for the owner.
207
+
208
+ ## 8. Second-Brain Routing / Memory Closeout
209
+
210
+ Session / handoff:
211
+
212
+ - [x] Added [[Sessions/2026-06-18-sanook-brain-final-cli]].
213
+ - [x] Added this final gate note.
214
+ - [x] Updated [[Sessions/_Index]].
215
+
216
+ Durable memory:
217
+
218
+ - [x] Updated [[Shared/Operating-State/current-state]].
219
+ - [x] No new owner preference or protected fact discovered.
220
+
221
+ Indexes / discoverability:
222
+
223
+ - [x] Updated [[Templates/_Index]].
224
+ - [x] Updated [[Shared/AI-Context-Index]].
225
+ - [x] Updated [[Evals/quality-ledger]].
226
+ - [x] Updated [[Evals/second-brain-benchmarks]].
227
+
228
+ Quality loop:
229
+
230
+ - [x] Added `SB-FINAL` eval case.
231
+ - [x] Ran targeted tests, typecheck, full tests, build, diff check, and CLI smoke.
232
+
233
+ ## Final Verdict
234
+
235
+ | Verdict | Choose one | Evidence |
236
+ |---|---|---|
237
+ | Ready to close | PASS | Tests, typecheck, build, diff check, and CLI smoke passed. |
238
+ | Close with caveats | PASS | Residual risk around exotic git paths and intentionally unfilled generated gates is documented. |
239
+ | Needs more work | N/A | No required item remains open. |
240
+ | Blocked | N/A | No blocker. |
241
+
242
+ One-line final state:
243
+
244
+ > Ready to close: Sanook now has a CLI-backed final-gate workflow with diff prefill, lite template, review validation, eval coverage, and documented evidence.
245
+
246
+ up:: [[Sessions/_Index]]
@@ -0,0 +1,78 @@
1
+ ---
2
+ tags: [session, session-log, sanook-cli, second-brain]
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 - Sanook Brain Final CLI
11
+
12
+ > Session log for turning the manual final-gate template into a Sanook CLI workflow with validation and eval coverage.
13
+
14
+ ## Summary
15
+
16
+ - Added `sanook brain final [--task "..."] [--from-diff] [--lite]`.
17
+ - Added [[Templates/final-lite]] for smaller evidence-backed closeouts.
18
+ - Added final-gate validation to `sanook brain review`.
19
+ - Added `SB-FINAL` coverage to `sanook brain eval`.
20
+ - Verified with targeted tests, typecheck, full tests, build, diff check, and a temp-vault CLI smoke.
21
+
22
+ ## What Was Tried
23
+
24
+ - Read the existing `brain context/eval/review` command pattern before adding a new subcommand.
25
+ - Kept the generator pure/testable in `src/brain-final.ts`.
26
+ - Used the existing Sessions folder as the canonical home for generated closeout notes.
27
+ - Let `--from-diff` prefill changed files from `git status --porcelain=v1`.
28
+ - Kept `brain review` non-blocking: incomplete final gates warn instead of failing the whole vault.
29
+
30
+ ## Errors
31
+
32
+ - Initial typecheck failed because `CreateBrainFinalOptions` inherited required booleans from parsed CLI args even though runtime options are optional.
33
+
34
+ ## Solutions
35
+
36
+ - Made `CreateBrainFinalOptions` explicitly optional for `fromDiff`, `lite`, `force`, `task`, and `output`.
37
+ - Added tests for parser behavior, full/lite generation, overwrite protection, output path safety, and validator warnings.
38
+ - Added a CLI smoke from `dist/bin.js` using a temp HOME and temp vault.
39
+
40
+ ## Key Decisions
41
+
42
+ - Default output path is `Sessions/YYYY-MM-DD-<slug>-final.md`.
43
+ - `--output` is confined inside the configured second-brain vault.
44
+ - `--lite` uses the same eight final-gate section names so review/eval can share the same structural validator.
45
+ - `brain review` checks session final gates only, while template files are checked structurally so scaffolded vaults do not fail because templates contain TODO placeholders.
46
+
47
+ ## Files Changed
48
+
49
+ - `src/brain-final.ts`
50
+ - `src/brain-final.test.ts`
51
+ - `src/bin.ts`
52
+ - `src/commands.ts`
53
+ - `src/brain-review.ts`
54
+ - `src/brain-review.test.ts`
55
+ - `src/brain-eval.ts`
56
+ - `src/brain-eval.test.ts`
57
+ - `src/brain.test.ts`
58
+ - `second-brain/Templates/final-lite.md`
59
+ - `second-brain/Templates/_Index.md`
60
+ - `second-brain/Shared/AI-Context-Index.md`
61
+ - `second-brain/Shared/Tech-Standards/verification-standard.md`
62
+ - `second-brain/Runbooks/ai-second-brain-operating-sequence.md`
63
+ - `second-brain/Evals/second-brain-benchmarks.md`
64
+ - `second-brain/Evals/quality-ledger.md`
65
+ - `second-brain/Shared/Operating-State/current-state.md`
66
+ - `CHANGELOG.md`
67
+
68
+ Unrelated pre-existing changes left untouched:
69
+
70
+ - `src/config.ts`
71
+ - `src/config.test.ts`
72
+
73
+ ## Next Steps
74
+
75
+ - Dogfood `sanook brain final --task "..." --from-diff` in future non-trivial Sanook CLI work.
76
+ - Consider `sanook brain new TYPE` later if template instantiation becomes a broader workflow need.
77
+
78
+ up:: [[Sessions/_Index]]
@@ -0,0 +1,54 @@
1
+ ---
2
+ tags: [session, session-log, sanook-cli, second-brain, correction]
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 — Sanook CLI Second-Brain Roadmap Correction
11
+
12
+ > Correction session after owner clarified that the target is Sanook CLI, not Hermes CLI. Captures the Sanook-native direction and leaves Hermes research as reference only.
13
+
14
+ ## Summary
15
+
16
+ Reframed the previous Hermes-heavy research into a Sanook CLI roadmap. Sanook already has `brain init`, vault context injection, memory routing, index/search, and MCP serving, so the next useful work is CLI features: `brain doctor`, `brain context`, `brain eval`, and later `brain review`.
17
+
18
+ ## What Was Tried
19
+
20
+ - Read `src/brain.ts`, `src/bin.ts`, `src/commands.ts`, `src/doctor.ts`, `src/knowledge.ts`, and `second-brain/SANOOK.md`.
21
+ - Checked current command surface for `brain init`, `index`, `search`, MCP, and memory behavior.
22
+ - Created a Sanook project workspace note under `Projects/sanook-cli/`.
23
+
24
+ ## Errors
25
+
26
+ - Initial research over-weighted Hermes-specific implementation because the earlier wording mentioned Hermes CLI.
27
+
28
+ ## Solutions
29
+
30
+ - Added [[Projects/sanook-cli/second-brain-feature-roadmap]] as the corrected implementation roadmap.
31
+ - Left Hermes research as a compatibility reference, not the main next action.
32
+
33
+ ## Key Decisions
34
+
35
+ - Do not add `HERMES.md` as the next step for this objective.
36
+ - First Sanook-native slice should be `sanook brain doctor`.
37
+
38
+ ## Files Changed
39
+
40
+ - `second-brain/Projects/_Index.md`
41
+ - `second-brain/Projects/sanook-cli/_Index.md`
42
+ - `second-brain/Projects/sanook-cli/second-brain-feature-roadmap.md`
43
+ - `second-brain/Sessions/_Index.md`
44
+ - `second-brain/Sessions/2026-06-18-sanook-cli-second-brain-roadmap-correction.md`
45
+ - `second-brain/Shared/Operating-State/current-state.md`
46
+ - `second-brain/Research/2026-06-18-hermes-cli-second-brain-expansion-research.md`
47
+
48
+ ## Next Steps
49
+
50
+ - [ ] Implement `sanook brain doctor`.
51
+ - [ ] Then implement `sanook brain context [--task]`.
52
+ - [ ] Then implement `sanook brain eval`.
53
+
54
+ up:: [[Sessions/_Index]]
@@ -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]]