limai
理脈 limai
理華與理月的共享神經系統——從角色中按第一性原理提取的獨立器官。
第一性原理推導
角色裡的樣子 | 本質 | 模組 | MCP 工具 |
心跳輪詢+錯誤退避(on_idle.mjs) | 節律 | heartbeat.mjs | heartbeat_now・vitals_latest・vitals_history |
截圖/視窗/剪貼簿(screenshot.mjs) | 視覺 | vision.mjs | screen_capture(回圖片)・list_windows・read_clipboard |
todo-tasks.json+權重融合心跳 | 意圖 | todo.mjs | todo_add・todo_list・todo_update |
長期記憶(名×關鍵字×內容) | 記憶 | memory.mjs | memory_add・memory_search・memory_list・memory_forget |
o-pi 六文件工具 | 檔案行動 | filesys.mjs | fs_ls/read/write/edit/find/grep |
o-pi websearch/webfetch | 網路行動 | web.mjs | web_search・web_fetch |
捨棄的:角色的 LLM 任務提示詞(人格不搬)、記憶的 JS eval 觸發器(安全)。 保留的精髓:加權隨機排程思想→心跳退避;STALE_READ 守衛;SSRF 防護;有界讀取。
Related MCP server: qwen-mcp
啟動
npm install
npm run start # ① stdio → Claude Desktop / Cursor 等本地客戶端
npm run serve:http # ② HTTP MCP → GPT 客戶端 / 區網 / 遠端
npm run tick # ③ 手動跑一次心跳(驗證感知層)CLI 為 AI agent 而設計
limai shot # → {"file":...,"width":1920,"height":1080,"bytes":...}
limai win # → {"foreground":...,"windows":[{process,title},…]}
limai clip [--json] # 剪貼簿原文走 stdout(利於管線)
limai tick # 心跳一次,生命徵象 JSON
limai web search <q> # → [{title,url,snippet},…]
limai web fetch <url> # 正文走 stdout、中繼 stderr;--json 得全包裝
limai fs ls|read|write|edit|find|grep …
limai mem … / limai todo … # 同前Agent 契約:
輸出預設 JSON、錯誤碼前綴進 stderr 訊息(
STALE_READ: …)、退出碼非零表失敗fs edit嚴格契約與 MCP 相同:須先fs read;觀測狀態持久化於fs-state.json, 「read 行程 → edit 行程」跨呼叫依然成立,外部變更必被攔截(--force 可越過)成功的
fs write亦建立觀測,可接 edit(同 o-pi「緊接成功 write」規則)
架構上 MCP 只是核心模組之上的其中一種介面:同一套 vision/web/filesys/memory/todo/heartbeat 同時供 CLI 子命令與 MCP 工具呼叫,兩種介面共用同一份資料與同一套安全契約。`
首次執行自動建立 ~/.limai/(config.json・memory.json・todo.json・vitals.*・screenshots/)並印出 token。
客戶端接入
本地(stdio)
// claude_desktop_config.json
{ "mcpServers": { "limai": { "command": "node", "args": ["F:\\fount開發項目\\理脈\\src\\cli.mjs", "serve", "--stdio"] } } }區網/同機 GPT 客戶端(Cherry Studio、LobeChat、OpenWebUI…)
node src/cli.mjs serve --http # 預設 127.0.0.1:8931
# 對區網開放:--host 0.0.0.0 --token <強密碼>{ "type": "http", "url": "http://192.168.x.x:8931/mcp",
"headers": { "Authorization": "Bearer <token>" } }雲端 ChatGPT(Connectors/開發者模式)
ChatGPT 摸不到你的 localhost,需要公網 HTTPS——一行隧道:
cloudflared tunnel --url http://127.0.0.1:8931
# → https://xxxx.trycloudflare.com連接器 URL 填 https://xxxx.trycloudflare.com/mcp?token=<token>(GPT 類客戶端多不能自訂 header,故支援 query 傳 token)。
長期方案:Tailscale Funnel(免開埠)或 Caddy 反代自有網域。
安全邊界
檔案:鎖在
config.json的allowedRoots;.git永久阻擋;fs_edit必須先fs_read(STALE_READ 版本守衛);old 文本必須唯一網路:拒 localhost/私網/link-local(SSRF)、重定向逐跳複檢、2MB 上限、30 秒逾時
認證:HTTP 全程 Bearer/query-token;預設只綁 127.0.0.1
隱私:心跳只記視窗標題+剪貼簿雜湊(變化時存前 60 字元預覽);像素截圖僅限明確呼叫 screen_capture
心跳語義(沿襲理華)
15 分鐘一跳(可調 heartbeat.intervalMin)。每跳收集:前景視窗・視窗清單(top8)・閒置秒數・剪貼簿變化・開放待辦數。失敗時間隔 ×2(上限 8×),成功復位。日誌滾動於 vitals.ndjson。
上游同步(o-pi)
2026-08-23 檢查:上游當日大量提交為內部重構(file-tools/web-tools/filesystem/lsp 簡化),六工具+兩網頁工具的行為契約不變;
duckduckgo-html-provider仍為零-key 備援路徑——理脈提取依然忠實。新能力
read支援 PDF 頁面圖像(d762209):理脈已對齊實作——fs_read加pages參數(N / N-M / N-),回傳頁面 PNG 的 MCP 圖像內容塊;CLI 用fs read <pdf> --pages "1-5"。主路線 PDF.js(pdfjs-dist legacy)+@napi-rs/canvas 跨平臺渲染;Windows 上依賴無法載入時自動降級內建 WinRTWindows.Data.Pdf。預設單次上限 20 頁,含總頁數與續讀位置。skill URI/bash 工具/approval gate 屬 Pi 宿主專屬,不在提取範圍。
同日二檢(d795f92 new approval UI):僅動
src/approval/*與 TUI,file-tools/web-tools 零變更。據此完成 grep 契約對齊:非法正則降級為精確字面量——有命中→回literal_fallback警告;零命中→INVALID_REGEX不偽裝空結果。已測試通過。
授權與來源(License & Attribution)
本專案以 GNU Affero General Public License v3.0 或更新版本(AGPL-3.0-or-later)發佈,完整條款見 LICENSE。
代碼來源聲明:
檔案工具(
src/core/filesys.mjs:ls/read/write/edit/find/grep)與網頁工具(src/core/web.mjs:web_search/web_fetch)的行為契約與設計,衍生自 Orion-zhen/o-pi(Pi Agent 的 file-tools 與 web-tools 設計文檔,AGPL-3.0 授權)。理脈為其精髓的獨立 Node.js 零重依賴實作,非代碼複製,依 AGPL 同條款回饋開源。心跳/todo/記憶/視覺等能力原語的提取藍本,來自 steve02081504/fount 生態中「理華」角色的能力設計(MIT 授權)。僅參考其架構思想(閒置輪詢退避、加權任務、名稱×關鍵字×內容記憶),未複製其程式碼。
MCP 協議實作基於官方 @modelcontextprotocol/sdk。
PDF 渲染依賴 pdf.js(Apache-2.0)與 @napi-rs/canvas(MIT)。
Available Tools
21 toolsfs_edit精確編輯A
對既有檔案做精確替換。須先 fs_read;old 必須唯一(多處命中需 replace_all 或更多上下文)。
Inputs: file (required), edits (required), force.
fs_find找路徑A
glob 路徑模糊搜尋(跳過 .git/node_modules;不搜尋內容)。
Inputs: glob, root, limit.
fs_grep搜內容A
正則逐行搜尋檔案內容(跳過 .git/node_modules 與 >1MB 檔)。非法正則時降級為精確字面量:有命中回 literal_fallback 警告,零命中才報 INVALID_REGEX。
Inputs: query (required), root, limit.
fs_ls列目錄B
列出目錄直屬成員(不遞迴、不讀內容)。
Inputs: dir.
fs_read讀檔案A
讀取檔案。文字檔用行範圍;PDF 用 pages 參數(如 "1-5"、"3"),回傳頁面 PNG 圖像內容(預設單次上限 20 頁,含總頁數與續讀位置);fs_edit 前必讀以建立觀測狀態。
Inputs: file (required), pages, maxLines, offsetLine.
fs_write寫檔案A
建立新檔或完整覆蓋(自動建父目錄)。不做局部合併。
Inputs: file (required), content (required).
heartbeat_now立即心跳A
立即執行一次心跳:收集前景視窗/閒置秒數/剪貼簿變化/todo 數量,寫入 vitals。
Inputs: no named parameters.
list_windows視窗清單A
列出前景視窗與所有有標題的視窗(行程名+標題)。輕量了解使用者正在做什麼。
Inputs: no named parameters.
memory_add記憶寫入B
新增或更新長期記憶。名稱唯一;keywords 供日後檢索觸發。內容應簡潔、去修辭、客觀(角色記憶規範)。
Inputs: name (required), content (required), keywords.
memory_forget遺忘C
依名稱刪除一條記憶。
Inputs: name (required).
memory_list記憶清單B
列出全部長期記憶。
Inputs: no named parameters.
memory_search記憶搜尋C
依關鍵字/名稱/內容搜尋記憶。
Inputs: query (required).
read_clipboard讀剪貼簿A
讀取目前剪貼簿文字(上限 2 萬字元)。
Inputs: no named parameters.
screen_capture螢幕截圖A
擷取本機全螢幕畫面。回傳 PNG 圖片(多模態客戶端可直接看見畫面內容)。僅在明確需要時呼叫。
Inputs: no named parameters.
todo_add新增待辦C
新增待辦任務(open 狀態;同名 open 任務會拒絕重複)。
Inputs: name (required), weight, content.
todo_list待辦清單A
列待辦;status 可選 open/done,省略則全部。
Inputs: status.
todo_update更新待辦C
標記完成(done)/重開(reopen)/刪除(remove)。id 接受 id 或 name。
Inputs: id (required), action (required).
vitals_history徵象歷史C
最近 N 筆心跳歷史。
Inputs: n.
vitals_latest最新徵象B
最近一次心跳快照。
Inputs: no named parameters.
web_fetch抓取網頁A
讀取公開 HTTP(S) URL。readable=抽正文、source=原文;offset/limit 有界分頁;拒絕本機與私網位址。
Inputs: url (required), mode, limit, offset.
web_search網頁搜尋A
DuckDuckGo 公開網頁搜尋,回傳標題/URL/摘要。不執行 JS、不讀結果頁正文。
Inputs: query (required), limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 21 tools
Each tool targets a distinct resource and action—monitoring (screen, windows, clipboard, heartbeat), memory (add/search/list/forget), todo (add/list/update), web (search/fetch), and filesystem (ls/read/write/edit/find/grep). There is no meaningful overlap; even fs_write vs fs_edit are clearly separated by create/overwrite vs precise replacement.
All tool names follow a consistent 'domain_action' pattern with snake_case (e.g., memory_add, web_fetch, fs_grep). The verb is consistently after the domain, and every name is lowercase, making the API predictable and easy to navigate.
With 21 tools, the server is slightly above the ideal range but each tool serves a clear purpose across multiple domains (system monitoring, memory, todos, web, filesystem). The count is justified given the broad scope, though a few tools could potentially be consolidated without losing clarity.
The server covers most core operations for its domains—memory and todo have full CRUD-ish coverage, web has search and fetch, and filesystem has read/write/edit/find/grep. However, the absence of a file deletion tool (e.g., fs_delete) leaves the filesystem incomplete, and there is no explicit tool for renaming or moving files. This gap could cause agent failures when cleanup is required.
Maintenance
Related MCP Connectors
Private-by-default, local-first memory/context/task orchestrator for MCP apps and agents.
Persistent memory, knowledge graph, task management and more for AI agents via MCP.
Shared memory for your AI tools: tasks, notes and context every tool can read and write over MCP.
Tasks, notes, habits, finance, watchlists and focus for your AI assistant, over MCP.
Related MCP Servers
- FlicenseAqualityDmaintenanceProvides persistent memory for MCP-compatible agents (like Copilot CLI) to save and recall knowledge across sessions, plus long-running monitoring tools.9-
- AlicenseBqualityDmaintenanceAn all-in-one MCP server that enables AI agents with local system capabilities like filesystem navigation, command execution, desktop automation, and a continuity memory suite for persistent cross-session project context.37MIT
- AlicenseNot gradedqualityCmaintenanceLocal-first memory MCP server that captures macOS screen and app context into persistent Markdown, enabling any tool-capable LLM agent to query its working history.MIT
- AlicenseNot gradedqualityBmaintenanceExposes MCP tools that give desktop agents durable two-tier memory with recall and graph traversal, project code intelligence (symbol lookup, impact walking, notes search), and web search with page-to-Markdown conversion. It also runs a local model gateway that routes Anthropic- and OpenAI-shaped traffic across providers with usage accounting.MIT