ข้ามไปเนื้อหาหลัก

● กำลังพัฒนา

Second Brain CLI

เครื่องมือ command-line สำหรับจัดการ notes และ knowledge base ในแบบ Zettelkasten ช่วยเชื่อมโยงความคิดและดึงข้อมูลกลับมาได้รวดเร็ว

· อ่านประมาณ 1 นาที

สารบัญ

ปัญหาที่แก้

บันทึกจำนวนมากกระจายอยู่ใน Notion, Apple Notes, และ sticky notes กระดาษ — ไม่มีระบบที่ช่วยเชื่อมโยงความคิดหรือค้นหาสิ่งที่เคยเรียนรู้ได้จริง

แนวคิด Zettelkasten แก้ปัญหานี้ด้วยหลักการ: one idea per note, link notes together แต่เครื่องมือส่วนใหญ่ต้องใช้ผ่าน UI — สิ่งที่ต้องการคือทำงานได้จาก terminal โดยตรง

การใช้งาน

# สร้าง note ใหม่พร้อม tag
brain add "ค้นพบว่า Astro 6 ย้าย content config ไปที่ src/content.config.ts" --tags astro,config

# ค้นหาตาม keyword
brain search "content config"

# ดูความสัมพันธ์ระหว่าง notes
brain graph --tag astro

# เชื่อม note สองอัน
brain link 20240310-001 20240312-004

# ทบทวน note เก่าแบบ spaced repetition
brain review

โครงสร้างไฟล์

~/.brain/
  notes/
    20240310-001.md   # eid = timestamp + sequence
    20240312-004.md
  index.db            # SQLite: search index + links

Database Schema

CREATE TABLE notes (
  id TEXT PRIMARY KEY,       -- "20240310-001"
  content TEXT,
  created_at TEXT,
  updated_at TEXT
);

CREATE TABLE links (
  from_id TEXT,
  to_id TEXT,
  PRIMARY KEY (from_id, to_id),
  FOREIGN KEY (from_id) REFERENCES notes(id),
  FOREIGN KEY (to_id) REFERENCES notes(id)
);

CREATE VIRTUAL TABLE notes_fts USING fts5(id, content);

SQLite FTS5 ทำให้ full-text search เร็วมากแม้มี notes หลายพัน

ฟีเจอร์ที่วางแผน

  • Atomic notes — บันทึกสั้น แต่ละ note มี id เฉพาะจาก timestamp
  • Bi-directional links — เชื่อม note ถึงกันและดู backlinks
  • Full-text search — ค้นหาเร็วด้วย SQLite FTS5
  • Daily review — สุ่มเสนอ note เก่าให้ทบทวน (spaced repetition)
  • Export to Markdown — นำออกเพื่อเผยแพร่บนเว็บได้

เทคโนโลยี

  • TypeScript + Node.js
  • Commander.js สำหรับ CLI interface
  • SQLite (better-sqlite3) เก็บ index และ links
  • Markdown เป็น source of truth ของเนื้อหา

สิ่งที่เรียนรู้

  • better-sqlite3 vs node-sqlite3 — synchronous API ของ better-sqlite3 เหมาะกับ CLI มากกว่า เพราะไม่ต้องจัดการ async/await ในทุกคำสั่ง
  • SQLite FTS5 — virtual table ที่ทรงพลังมาก tokenize และ index ข้อความไทยได้แม้จะไม่ perfect
  • Commander.js subcommands — pattern program.command('add').argument('<text>').option(...) อ่านง่ายและ document ตัวเองได้จาก --help