libero-mcp 0.2.0 → 0.2.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.
package/COLD_START.md ADDED
@@ -0,0 +1,31 @@
1
+ # libero 冷启动(装机后、reload 前)
2
+
3
+ > 给 Hermes / OpenClaw 等 host agent 读。装完包后**先把下面欢迎发给用户**,再 `/reload-mcp`。
4
+
5
+ ## 装机顺序
6
+
7
+ 1. `npm i -g libero-mcp@latest`
8
+ 2. 配置 `mcp_servers.libero.command: libero-mcp`(如需)
9
+ 3. **先介绍**:把「欢迎原文」原样发给用户(不要列工具名、不要问 user_id)
10
+ 4. **再刷新**:`/reload-mcp`(或等价)挂上工具
11
+
12
+ ## 欢迎原文(原样发给用户)
13
+
14
+ ```
15
+ 你好,我是 libero,帮你管时间和精力。
16
+
17
+ 常用这几件事,直接说就行:
18
+ • 计时:「开始计时写代码」/「开个 25 分钟番茄钟」
19
+ • 日程:「明天 9 点到 11 点写报告」
20
+ • 拆任务:「这个太大了,帮我拆一下」
21
+ • 看数据:「这周时间都花哪儿了」
22
+ • 复盘:「帮我复盘一下这周」
23
+
24
+ 想先试哪一句?
25
+ ```
26
+
27
+ ## 硬规矩
28
+
29
+ - **禁止问 user_id**(从会话上下文静默取;取不到用 `local:default`)
30
+ - 不要提 MCP / 工具表 / DB / YAML
31
+ - 用户选了例句 → 直接执行,不要重复整段介绍
package/README.md CHANGED
@@ -1,21 +1,64 @@
1
- # libero 2.0
1
+ # libero
2
2
 
3
- AI 辅助人类精力管理:观察实绩 → 发现问题 → 对齐方案 → AI 辅助达成,PDCA 闭环。
3
+ AI 辅助的精力管理教练:观察实绩 → 发现问题 → 对齐方案 → AI 辅助达成。
4
4
 
5
- 2.0 = 一组 Skills(脑)+ 一层 MCP 工具(手)+ 一个数据后端(记忆),骑 Openclaw,本地优先。
5
+ > 2.0 = 一组 Skills(脑)+ 一层 MCP 工具(手)+ 一个数据后端(记忆),骑 Hermes / OpenClaw,本地优先。
6
6
 
7
7
  ## 快速开始
8
8
 
9
- > MV-0 排雷中,runbook 待补充。
9
+ ```bash
10
+ npm i -g libero-mcp@latest
11
+ ```
10
12
 
11
- ## 仓库结构
13
+ ### 给 host agent(Hermes / OpenClaw)的装机顺序
12
14
 
13
- - `skills/` 脑(prompt + markdown)
14
- - `mcp/` 手(确定性 MCP 工具)
15
- - `data/` — 本地 DB schema + migrations
16
- - `eval/` — Skill 评估与压力测试
17
- - `docs/` — spec / plan / 决策记录
15
+ 1. 装包并写好 MCP 配置
16
+ 2. **先介绍**:把 [`COLD_START.md`](COLD_START.md) 里的欢迎原文发给用户(不要列工具、不要问 user_id)
17
+ 3. **再刷新**:`/reload-mcp`(或等价)挂上工具
18
18
 
19
- ## 协作宪法
19
+ 用户装完后应直接看到欢迎与试用例句,而不是配置问卷。
20
20
 
21
- [AGENTS.md](AGENTS.md)
21
+ ### 用户怎么试
22
+
23
+ 装完后直接说:
24
+
25
+ > 开始计时写代码
26
+
27
+ 或:
28
+
29
+ > 这周时间都花哪儿了?帮我复盘一下
30
+
31
+ ## 能说什么
32
+
33
+ | 想做的事 | 这样说 |
34
+ |---|---|
35
+ | 开始一段专注 | "开始计时写代码" / "开个 25 分钟番茄钟读书" |
36
+ | 停下来 | "停一下" / "看看今天计了多久" |
37
+ | 安排日程 | "明天 9 点到 11 点写报告" / "下周二下午开会" |
38
+ | 看时间分布 | "这周时间都花哪儿了" / "看看今天的四象限" |
39
+ | 复盘 | "复盘一下这周" / "帮我分析最近的时间使用" |
40
+ | 拆任务 | "这个任务太大,帮我拆一下" |
41
+ | 安排提醒 | "明天 8 点提醒我打卡" |
42
+
43
+ ## 数据存在哪
44
+
45
+ 默认在 `~/.libero/libero.db`(SQLite)。想换位置:
46
+
47
+ ```bash
48
+ DB_PATH=/your/path.db libero-mcp
49
+ ```
50
+
51
+ ## 升级
52
+
53
+ ```bash
54
+ npm update -g libero-mcp
55
+ ```
56
+
57
+ DB schema 升级在启动时自动跑,不用手工干预。
58
+
59
+ ## 给开发者
60
+
61
+ - 冷启动文案:[COLD_START.md](COLD_START.md)(与 MCP `instructions` 同源)
62
+ - 协作宪法:[AGENTS.md](AGENTS.md)
63
+ - 部署细节:[docs/operations/deploy-to-hermes.md](docs/operations/deploy-to-hermes.md)
64
+ - Skills:`skills/`(libero-coach / libero-record / libero-onboarding / libero-decompose)
package/dist/data/db.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import Database from "better-sqlite3";
2
- import { readFileSync, readdirSync } from "node:fs";
3
- import { join } from "node:path";
2
+ import { mkdirSync, readFileSync, readdirSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join } from "node:path";
4
5
  import { fileURLToPath } from "node:url";
5
6
  let instance = null;
6
7
  function runMigrations(db) {
@@ -33,6 +34,9 @@ export function initDb(dbPath) {
33
34
  instance.close();
34
35
  instance = null;
35
36
  }
37
+ // 父目录不存在时自动创建(recursive),避免 SQLITE_CANTOPEN
38
+ // 2026-07-17:hermes 装机后默认 cwd 无 ./data/ → 用户看到"缺少数据库目录"
39
+ mkdirSync(dirname(dbPath), { recursive: true });
36
40
  const db = new Database(dbPath);
37
41
  db.pragma("journal_mode = WAL");
38
42
  db.pragma("foreign_keys = ON");
@@ -54,7 +58,8 @@ export function closeDb() {
54
58
  }
55
59
  const entry = process.argv[1];
56
60
  if (entry && fileURLToPath(import.meta.url) === entry) {
57
- const dbPath = process.env.DB_PATH ?? join(import.meta.dirname, "libero.db");
61
+ // CLI 模式:默认 ~/.libero/libero.db(与 server.ts 保持一致)
62
+ const dbPath = process.env.DB_PATH ?? join(homedir(), ".libero", "libero.db");
58
63
  initDb(dbPath);
59
64
  console.log(`DB initialized at ${dbPath}`);
60
65
  closeDb();
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Cold-start copy for host agents (Hermes / OpenClaw) and MCP server instructions.
3
+ *
4
+ * Timing (user perspective):
5
+ * 1. After npm install / config written
6
+ * 2. FIRST show COLD_START_WELCOME to the user (before tools are live)
7
+ * 3. THEN /reload-mcp (or equivalent) to attach tools
8
+ *
9
+ * MCP cannot push a chat message by itself — hosts must speak this text in the
10
+ * install turn. Server `instructions` reinforce the same rules after connect.
11
+ */
12
+ /** Short welcome users should see (natural language only). */
13
+ export const COLD_START_WELCOME = `你好,我是 libero,帮你管时间和精力。
14
+
15
+ 常用这几件事,直接说就行:
16
+ • 计时:「开始计时写代码」/「开个 25 分钟番茄钟」
17
+ • 日程:「明天 9 点到 11 点写报告」
18
+ • 拆任务:「这个太大了,帮我拆一下」
19
+ • 看数据:「这周时间都花哪儿了」
20
+ • 复盘:「帮我复盘一下这周」
21
+
22
+ 想先试哪一句?`;
23
+ /**
24
+ * MCP initialize `instructions` — injected into host model context after connect.
25
+ * Also documents the install sequence for hosts that read package docs.
26
+ */
27
+ export function buildServerInstructions() {
28
+ return [
29
+ "# libero — 时间与精力管理助手",
30
+ "",
31
+ "## 装机顺序(硬规矩)",
32
+ "1. npm i -g libero-mcp@latest 配置好 mcp_servers 后:",
33
+ "2. **先介绍**:把下面「冷启动欢迎」原样发给用户(不要列工具名 / 不要问配置)",
34
+ "3. **再 reload**:用户看完介绍后,再执行 /reload-mcp(或等价刷新)挂上工具",
35
+ "4. 禁止在介绍或首次对话里索取 user_id / DB_PATH / YAML",
36
+ "",
37
+ "## 冷启动欢迎(原样发给用户)",
38
+ COLD_START_WELCOME,
39
+ "",
40
+ "## user_id(硬纪律)",
41
+ "- 调用任何需要 user_id 的工具时:从当前会话上下文静默取(平台用户 ID / 会话稳定 ID)",
42
+ "- 取不到时用稳定占位 local:default",
43
+ "- **禁止问用户起 user_id**;禁止输出 wechat_你的ID / test_1 这类工程师问卷",
44
+ "- 可选问称呼(display_name),一句即可,可跳过",
45
+ "",
46
+ "## 对用户说话",
47
+ "- 只说自然语言能做什么;不要提 MCP / 工具表 / schema / 数据库",
48
+ "- 用户选了试用例句 → 直接执行对应能力,不要重复整段介绍",
49
+ ].join("\n");
50
+ }
@@ -11,6 +11,7 @@ import { createReminderTools } from "./src/reminder/index.js";
11
11
  import { createSchedulerTools } from "./src/scheduler/index.js";
12
12
  import { createTaskTools } from "./src/task/index.js";
13
13
  import { nowLocal, formatTime, parseTime } from "./src/clock/index.js";
14
+ import { buildServerInstructions } from "./cold-start.js";
14
15
  /** Wrap any tool result as MCP text content (JSON). Void results become {ok:true}. */
15
16
  function asContent(result) {
16
17
  return {
@@ -45,7 +46,8 @@ export function buildServer(db) {
45
46
  const reminder = createReminderTools(reminderRepo);
46
47
  const scheduler = createSchedulerTools(timeblockRepo, reminderRepo, categoryRepo);
47
48
  const task = createTaskTools(db);
48
- const server = new McpServer({ name: "libero-mcp", version: "0.1.0" });
49
+ // instructions 必须放在第 2 ServerOptions(不是 serverInfo)—— SDK 只从 options 读
50
+ const server = new McpServer({ name: "libero-mcp", version: "0.2.2" }, { instructions: buildServerInstructions() });
49
51
  // ============================================================
50
52
  // categories (2 tools)
51
53
  // ============================================================
@@ -200,9 +202,9 @@ export function buildServer(db) {
200
202
  inputSchema: { user_id: z.string().min(1) },
201
203
  }, async ({ user_id }) => asContent(await profile.get(user_id)));
202
204
  server.registerTool("profile.upsert", {
203
- description: "创建或更新用户 profile(结构化约定存入 settings JSON 列)",
205
+ description: "创建或更新用户 profile。user_id 从会话上下文静默取,禁止向用户索取。",
204
206
  inputSchema: {
205
- user_id: z.string().min(1),
207
+ user_id: z.string().min(1).describe("从会话上下文静默取;禁止问用户"),
206
208
  display_name: z.string().optional(),
207
209
  expectations: z.string().optional(),
208
210
  settings: z
@@ -3,14 +3,18 @@
3
3
  * libero MCP server — stdio transport entry point (S10 §3.3).
4
4
  *
5
5
  * Usage:
6
- * DB_PATH=/path/to/libero.db node mcp/server.ts
7
- * DB_PATH=/path/to/libero.db npx tsx mcp/server.ts
8
- * libero-mcp (if package.json bin + tsx is configured)
6
+ * libero-mcp # 默认 DB 在 ~/.libero/libero.db
7
+ * DB_PATH=/path/to/libero.db libero-mcp # 自定义 DB 路径
9
8
  */
10
9
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
10
+ import { homedir } from "node:os";
11
+ import { join } from "node:path";
11
12
  import { initDb, closeDb } from "../data/db.js";
12
13
  import { buildServer } from "./server-core.js";
13
- const DB_PATH = process.env.DB_PATH ?? "./data/libero.db";
14
+ // 默认 DB 在用户家目录的 ~/.libero/libero.db(跨平台、不污染 cwd、符合 XDG-ish 约定)
15
+ // 2026-07-17:原默认 "./data/libero.db" 是相对路径,hermes 启动 libero-mcp 时 cwd 无 ./data/
16
+ // → better-sqlite3 抛 SQLITE_CANTOPEN → 用户看到"缺少数据库目录"。改绝对路径根治。
17
+ const DB_PATH = process.env.DB_PATH ?? join(homedir(), ".libero", "libero.db");
14
18
  if (!DB_PATH) {
15
19
  console.error("FATAL: DB_PATH environment variable not set.");
16
20
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libero-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "AI 时间管理教练 MCP 工具集——时间块记录、统计、矩阵诊断、计时、分类、profile",
5
5
  "license": "MIT",
6
6
  "author": "amosyuan",
@@ -39,7 +39,8 @@
39
39
  "files": [
40
40
  "dist",
41
41
  "data/migrations",
42
- "data/schema.sql"
42
+ "data/schema.sql",
43
+ "COLD_START.md"
43
44
  ],
44
45
  "dependencies": {
45
46
  "@modelcontextprotocol/sdk": "^1.29.0",