libero3 0.3.0

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 (192) hide show
  1. package/COLD_START.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +43 -0
  4. package/data/migrations/001_initial_schema.sql +43 -0
  5. package/data/migrations/002_seed_categories.sql +18 -0
  6. package/data/migrations/003_add_rating.sql +4 -0
  7. package/data/migrations/004_timer_sessions.sql +21 -0
  8. package/data/migrations/005_profile_settings.sql +5 -0
  9. package/data/migrations/006_add_timeblock_status.sql +1 -0
  10. package/data/migrations/007_reminders.sql +17 -0
  11. package/data/migrations/008_timer_target_ms.sql +5 -0
  12. package/data/migrations/009_tasks.sql +22 -0
  13. package/data/migrations/010_timer_task_id.sql +4 -0
  14. package/data/migrations/011_profile_default_confirmed.sql +4 -0
  15. package/data/migrations/012_identity_tables.sql +68 -0
  16. package/data/migrations/013_identity_managed_by.sql +3 -0
  17. package/data/migrations/014_task_difficulty_priority.sql +6 -0
  18. package/data/migrations/015_timeblock_asked_at.sql +5 -0
  19. package/data/migrations/016_intent_columns.sql +8 -0
  20. package/data/migrations/017_ap_wallet.sql +25 -0
  21. package/data/migrations/018_ap_rewards.sql +21 -0
  22. package/data/migrations/019_ap_bounty.sql +10 -0
  23. package/data/migrations/020_chat_turns.sql +10 -0
  24. package/data/migrations/021_portrait.sql +4 -0
  25. package/data/migrations/022_family_emoji_single.sql +3 -0
  26. package/data/migrations/023_ap_balance_view_log.sql +9 -0
  27. package/data/schema.sql +75 -0
  28. package/dist/data/db.js +83 -0
  29. package/dist/data/migrations/001_initial_schema.sql +43 -0
  30. package/dist/data/migrations/002_seed_categories.sql +18 -0
  31. package/dist/data/migrations/003_add_rating.sql +4 -0
  32. package/dist/data/migrations/004_timer_sessions.sql +21 -0
  33. package/dist/data/migrations/005_profile_settings.sql +5 -0
  34. package/dist/data/migrations/006_add_timeblock_status.sql +1 -0
  35. package/dist/data/migrations/007_reminders.sql +17 -0
  36. package/dist/data/migrations/008_timer_target_ms.sql +5 -0
  37. package/dist/data/migrations/009_tasks.sql +22 -0
  38. package/dist/data/migrations/010_timer_task_id.sql +4 -0
  39. package/dist/data/migrations/011_profile_default_confirmed.sql +4 -0
  40. package/dist/data/migrations/012_identity_tables.sql +68 -0
  41. package/dist/data/migrations/013_identity_managed_by.sql +3 -0
  42. package/dist/data/migrations/014_task_difficulty_priority.sql +6 -0
  43. package/dist/data/migrations/015_timeblock_asked_at.sql +5 -0
  44. package/dist/data/migrations/016_intent_columns.sql +8 -0
  45. package/dist/data/migrations/017_ap_wallet.sql +25 -0
  46. package/dist/data/migrations/018_ap_rewards.sql +21 -0
  47. package/dist/data/migrations/019_ap_bounty.sql +10 -0
  48. package/dist/data/migrations/020_chat_turns.sql +10 -0
  49. package/dist/data/migrations/021_portrait.sql +4 -0
  50. package/dist/data/migrations/022_family_emoji_single.sql +3 -0
  51. package/dist/data/migrations/023_ap_balance_view_log.sql +9 -0
  52. package/dist/data/schema.sql +75 -0
  53. package/dist/knowledge/_registry/dimensions.yaml +10 -0
  54. package/dist/knowledge/_registry/personas.yaml +7 -0
  55. package/dist/knowledge/_schema/analysis-model.schema.js +32 -0
  56. package/dist/knowledge/_schema/entry.schema.js +45 -0
  57. package/dist/knowledge/_schema/persona.schema.js +23 -0
  58. package/dist/knowledge/_schema/scenario-pack.schema.js +29 -0
  59. package/dist/knowledge/analysis-models/review-default.yaml +16 -0
  60. package/dist/knowledge/analysis-models/review-summer-plan.yaml +15 -0
  61. package/dist/knowledge/brain-science/brain-deep-warmup.yaml +22 -0
  62. package/dist/knowledge/brain-science/brain-emotion-granularity.yaml +22 -0
  63. package/dist/knowledge/brain-science/brain-env-engineering.yaml +22 -0
  64. package/dist/knowledge/brain-science/brain-extended-mind.yaml +22 -0
  65. package/dist/knowledge/brain-science/brain-friction-barrier.yaml +22 -0
  66. package/dist/knowledge/brain-science/brain-peak-end.yaml +29 -0
  67. package/dist/knowledge/brain-science/brain-pomodoro.yaml +31 -0
  68. package/dist/knowledge/brain-science/brain-revenge-bedtime.yaml +22 -0
  69. package/dist/knowledge/brain-science/brain-single-variable.yaml +15 -0
  70. package/dist/knowledge/brain-science/brain-tiny-habits.yaml +22 -0
  71. package/dist/knowledge/energy/energy-active-recovery.yaml +22 -0
  72. package/dist/knowledge/energy/energy-deliberate-rest.yaml +22 -0
  73. package/dist/knowledge/energy/energy-exercise-embedded.yaml +22 -0
  74. package/dist/knowledge/energy/energy-fixed-wake-time.yaml +22 -0
  75. package/dist/knowledge/energy/energy-four-energy-radar.yaml +22 -0
  76. package/dist/knowledge/energy/energy-intensity-recovery.yaml +22 -0
  77. package/dist/knowledge/scenario-packs/pack-summer-kid.yaml +12 -0
  78. package/dist/knowledge/src/repo/fs-yaml.js +252 -0
  79. package/dist/knowledge/src/repo/types.js +1 -0
  80. package/dist/knowledge/time/time-batch-windows.yaml +22 -0
  81. package/dist/knowledge/time/time-conscious-abandon.yaml +22 -0
  82. package/dist/knowledge/time/time-deep-work-block.yaml +22 -0
  83. package/dist/knowledge/time/time-finite-commitment.yaml +22 -0
  84. package/dist/knowledge/time/time-forced-whitespace.yaml +22 -0
  85. package/dist/knowledge/time/time-gtd-next-action.yaml +22 -0
  86. package/dist/knowledge/time/time-three-tier-list.yaml +22 -0
  87. package/dist/mcp/cold-start.js +43 -0
  88. package/dist/mcp/contract/v1/rest.js +56 -0
  89. package/dist/mcp/rest-server.js +52 -0
  90. package/dist/mcp/server-core.js +1334 -0
  91. package/dist/mcp/server.js +34 -0
  92. package/dist/mcp/src/ap/index.js +14 -0
  93. package/dist/mcp/src/ap/rewards.js +44 -0
  94. package/dist/mcp/src/categories/index.js +12 -0
  95. package/dist/mcp/src/chat/from-env.js +111 -0
  96. package/dist/mcp/src/chat/history.js +35 -0
  97. package/dist/mcp/src/chat/loop.js +131 -0
  98. package/dist/mcp/src/chat/portrait.js +133 -0
  99. package/dist/mcp/src/chat/system-prompt.js +23 -0
  100. package/dist/mcp/src/chat/tool-names.js +27 -0
  101. package/dist/mcp/src/chat/tool-schema.js +20 -0
  102. package/dist/mcp/src/chat/types.js +1 -0
  103. package/dist/mcp/src/clock/index.js +78 -0
  104. package/dist/mcp/src/coachmod/index.js +135 -0
  105. package/dist/mcp/src/host-adapters/hermes-cron.js +185 -0
  106. package/dist/mcp/src/host-adapters/index.js +61 -0
  107. package/dist/mcp/src/host-adapters/types.js +7 -0
  108. package/dist/mcp/src/identity/equivalent-ids.js +41 -0
  109. package/dist/mcp/src/identity/in-memory.js +100 -0
  110. package/dist/mcp/src/identity/resolve.js +60 -0
  111. package/dist/mcp/src/identity/types.js +4 -0
  112. package/dist/mcp/src/matrix/index.js +15 -0
  113. package/dist/mcp/src/profile/confirm-default.js +48 -0
  114. package/dist/mcp/src/profile/index.js +298 -0
  115. package/dist/mcp/src/profile-confirm.js +28 -0
  116. package/dist/mcp/src/profile-helpers.js +109 -0
  117. package/dist/mcp/src/reminder/hermes-channel.js +40 -0
  118. package/dist/mcp/src/reminder/index.js +70 -0
  119. package/dist/mcp/src/reminder/push-channel.js +10 -0
  120. package/dist/mcp/src/repo/factory.js +34 -0
  121. package/dist/mcp/src/repo/in-memory.js +469 -0
  122. package/dist/mcp/src/repo/sqlite-ap.js +188 -0
  123. package/dist/mcp/src/repo/sqlite-helpers.js +39 -0
  124. package/dist/mcp/src/repo/sqlite-identity.js +129 -0
  125. package/dist/mcp/src/repo/sqlite.js +754 -0
  126. package/dist/mcp/src/repo/types.js +4 -0
  127. package/dist/mcp/src/rest/app.js +121 -0
  128. package/dist/mcp/src/rest/invoke-tool.js +98 -0
  129. package/dist/mcp/src/rest/short-token.js +38 -0
  130. package/dist/mcp/src/rest/tokens.js +55 -0
  131. package/dist/mcp/src/scheduler/index.js +319 -0
  132. package/dist/mcp/src/stats/index.js +29 -0
  133. package/dist/mcp/src/stickiness/report.js +174 -0
  134. package/dist/mcp/src/stickiness/types.js +1 -0
  135. package/dist/mcp/src/task/index.js +412 -0
  136. package/dist/mcp/src/timeblock/index.js +206 -0
  137. package/dist/mcp/src/timeline/index.js +705 -0
  138. package/dist/mcp/src/timer/index.js +234 -0
  139. package/dist/mcp/src/user-id-resolver.js +30 -0
  140. package/dist/mcp/src/weixin/app.js +97 -0
  141. package/dist/mcp/src/weixin/custom-send.js +82 -0
  142. package/dist/mcp/src/weixin/handle-text.js +49 -0
  143. package/dist/mcp/src/weixin/reminder-loop.js +39 -0
  144. package/dist/mcp/src/weixin/signature.js +13 -0
  145. package/dist/mcp/src/weixin/tencent-asr.js +101 -0
  146. package/dist/mcp/src/weixin/xml.js +37 -0
  147. package/dist/mcp/weixin-server.js +158 -0
  148. package/knowledge/_registry/dimensions.yaml +10 -0
  149. package/knowledge/_registry/personas.yaml +7 -0
  150. package/knowledge/_schema/analysis-model.schema.ts +36 -0
  151. package/knowledge/_schema/entry.schema.ts +50 -0
  152. package/knowledge/_schema/persona.schema.ts +30 -0
  153. package/knowledge/_schema/scenario-pack.schema.ts +33 -0
  154. package/knowledge/analysis-models/review-default.yaml +16 -0
  155. package/knowledge/analysis-models/review-summer-plan.yaml +15 -0
  156. package/knowledge/brain-science/brain-deep-warmup.yaml +22 -0
  157. package/knowledge/brain-science/brain-emotion-granularity.yaml +22 -0
  158. package/knowledge/brain-science/brain-env-engineering.yaml +22 -0
  159. package/knowledge/brain-science/brain-extended-mind.yaml +22 -0
  160. package/knowledge/brain-science/brain-friction-barrier.yaml +22 -0
  161. package/knowledge/brain-science/brain-peak-end.yaml +29 -0
  162. package/knowledge/brain-science/brain-pomodoro.yaml +31 -0
  163. package/knowledge/brain-science/brain-revenge-bedtime.yaml +22 -0
  164. package/knowledge/brain-science/brain-single-variable.yaml +15 -0
  165. package/knowledge/brain-science/brain-tiny-habits.yaml +22 -0
  166. package/knowledge/energy/energy-active-recovery.yaml +22 -0
  167. package/knowledge/energy/energy-deliberate-rest.yaml +22 -0
  168. package/knowledge/energy/energy-exercise-embedded.yaml +22 -0
  169. package/knowledge/energy/energy-fixed-wake-time.yaml +22 -0
  170. package/knowledge/energy/energy-four-energy-radar.yaml +22 -0
  171. package/knowledge/energy/energy-intensity-recovery.yaml +22 -0
  172. package/knowledge/scenario-packs/pack-summer-kid.yaml +12 -0
  173. package/knowledge/src/repo/fs-yaml.ts +282 -0
  174. package/knowledge/src/repo/types.ts +24 -0
  175. package/knowledge/tests/fixtures/base/_registry/dimensions.yaml +4 -0
  176. package/knowledge/tests/fixtures/base/time/valid-entry.yaml +24 -0
  177. package/knowledge/tests/fixtures/dup/_registry/dimensions.yaml +4 -0
  178. package/knowledge/tests/fixtures/dup/time/entry-a.yaml +13 -0
  179. package/knowledge/tests/fixtures/dup/time/entry-b.yaml +13 -0
  180. package/knowledge/tests/fixtures/unregistered/_registry/dimensions.yaml +7 -0
  181. package/knowledge/tests/fixtures/unregistered/time/anxiety-entry.yaml +13 -0
  182. package/knowledge/tests/repo/fs-yaml-knowledge-repo.test.ts +333 -0
  183. package/knowledge/time/time-batch-windows.yaml +22 -0
  184. package/knowledge/time/time-conscious-abandon.yaml +22 -0
  185. package/knowledge/time/time-deep-work-block.yaml +22 -0
  186. package/knowledge/time/time-finite-commitment.yaml +22 -0
  187. package/knowledge/time/time-forced-whitespace.yaml +22 -0
  188. package/knowledge/time/time-gtd-next-action.yaml +22 -0
  189. package/knowledge/time/time-three-tier-list.yaml +22 -0
  190. package/knowledge/validate.ts +50 -0
  191. package/package.json +76 -0
  192. package/scripts/postinstall-cold-start.js +45 -0
@@ -0,0 +1,22 @@
1
+ id: time-forced-whitespace
2
+ kind: prescription
3
+ dimension: time
4
+ title: 强制留白
5
+ triggers:
6
+ signals:
7
+ - daily_total_minutes: ">600"
8
+ symptoms:
9
+ - 某天经常过载
10
+ - 日程太满
11
+ prescription:
12
+ one_liner: 日程只排 60-70%,把留白当作系统必需而非懒惰
13
+ steps:
14
+ - 计算你一天的实际可用时间
15
+ - 只排 60-70% 的任务
16
+ - 留出 30-40% 应对意外和恢复
17
+ micro_experiment: 明天日程只排 60%,留白 40%
18
+ verify: 一周后看过载天数是否减少
19
+ source:
20
+ ref: Make Time (Jake Knapp & John Zeratsky)
21
+ evidence_level: book
22
+ tags: [留白, 日程]
@@ -0,0 +1,22 @@
1
+ id: time-gtd-next-action
2
+ kind: prescription
3
+ dimension: time
4
+ title: GTD 下一步物理动作
5
+ triggers:
6
+ signals:
7
+ - quadrant: 能耗黑洞
8
+ symptoms:
9
+ - 任务反复推迟
10
+ - 不知道从哪开始
11
+ prescription:
12
+ one_liner: 把模糊目标拆为"打开文档 + 写 3 个小标题"级粒度
13
+ steps:
14
+ - 写下模糊目标
15
+ - 问自己"下一步物理动作是什么"
16
+ - 拆到 ≤5 分钟的粒度
17
+ micro_experiment: 选一个反复推迟的任务,拆成 3 个 ≤5 分钟的物理动作
18
+ verify: 拆解后 24 小时内是否启动了
19
+ source:
20
+ ref: GTD (Getting Things Done, David Allen)
21
+ evidence_level: framework
22
+ tags: [GTD, 任务拆解]
@@ -0,0 +1,22 @@
1
+ id: time-three-tier-list
2
+ kind: prescription
3
+ dimension: time
4
+ title: 三层专注清单
5
+ triggers:
6
+ signals:
7
+ - quadrant: 能耗黑洞
8
+ symptoms:
9
+ - 待办过载焦虑
10
+ - 事情太多
11
+ prescription:
12
+ one_liner: 第一层今日重点 / 第二层本周推进 / 第三层随时杂事
13
+ steps:
14
+ - 列出所有待办
15
+ - 分三层:今日重点 ≤3 项 / 本周推进 / 随时杂事
16
+ - 每天先做第一层
17
+ micro_experiment: 明天只设 3 个今日重点,其他待办归入第二、三层
18
+ verify: 当天完成率是否提升
19
+ source:
20
+ ref: Esor 时间管理方法论
21
+ evidence_level: folk
22
+ tags: [优先级, 清单]
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Cold-start copy for host agents (Hermes / OpenClaw) and MCP server instructions.
3
+ *
4
+ * User perspective: one line `npm i -g` or "帮我装 libero" → welcome appears.
5
+ * Host perspective: postinstall prints LIBERO_HOST_ACTION; host relays welcome,
6
+ * then /reload-mcp. Never ask the human to coach the agent.
7
+ */
8
+ /** Short welcome users should see (natural language only). */
9
+ export const COLD_START_WELCOME = `你好,我是 libero,帮你管时间和精力。
10
+
11
+ 常用这几件事,直接说就行:
12
+ • 计时:「开始计时写代码」/「开个 25 分钟番茄钟」
13
+ • 日程:「明天 9 点到 11 点写报告」
14
+ • 拆任务:「这个太大了,帮我拆一下」
15
+ • 看数据:「这周时间都花哪儿了」
16
+ • 复盘:「帮我复盘一下这周」
17
+
18
+ 想先试哪一句?`;
19
+ /**
20
+ * MCP initialize `instructions` — injected into host model context after connect.
21
+ * Also documents the install sequence for hosts that read package docs.
22
+ */
23
+ export function buildServerInstructions() {
24
+ return [
25
+ "# libero — 时间与精力管理助手",
26
+ "",
27
+ "## 装机(对 host agent,不是对用户)",
28
+ "用户只说「帮我装 libero」或跑 npm i -g。**禁止**让用户再提醒你读 md / 执行命令。",
29
+ "npm postinstall 会打印 LIBERO_HOST_ACTION + 欢迎原文:你的**下一条对用户回复**必须是该欢迎,然后再 /reload-mcp。",
30
+ "禁止问 user_id;禁止列工具表。",
31
+ "",
32
+ "## 冷启动欢迎(原样发给用户)",
33
+ COLD_START_WELCOME,
34
+ "",
35
+ "## user_id(硬纪律)",
36
+ "- 从当前会话上下文静默取;取不到用 local:default",
37
+ "- **禁止问用户起 user_id**;禁止 wechat_你的ID / test_1 问卷",
38
+ "",
39
+ "## 对用户说话",
40
+ "- 只说自然语言能做什么;不要提 MCP / 工具表 / schema / 数据库",
41
+ "- 用户选了试用例句 → 直接执行,不要重复整段介绍",
42
+ ].join("\n");
43
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * MC-0b REST contract v1 — single source of truth (api-contract-first).
3
+ *
4
+ * REST adapter and tests bind these schemas. Do not invent parallel field names.
5
+ */
6
+ import { z } from "zod";
7
+ export const restErrorCodeSchema = z.enum([
8
+ "unauthorized",
9
+ "forbidden",
10
+ "not_found",
11
+ "invalid_input",
12
+ "tool_error",
13
+ "internal",
14
+ "unavailable",
15
+ "llm_error",
16
+ ]);
17
+ export const restErrorBodySchema = z.object({
18
+ ok: z.literal(false),
19
+ error: z.object({
20
+ code: restErrorCodeSchema,
21
+ message: z.string().min(1),
22
+ }),
23
+ });
24
+ export const restSuccessBodySchema = z.object({
25
+ ok: z.literal(true),
26
+ data: z.unknown(),
27
+ });
28
+ export const restHealthBodySchema = z.object({
29
+ ok: z.literal(true),
30
+ });
31
+ export const chatRequestBodySchema = z.object({
32
+ message: z.string().min(1),
33
+ });
34
+ export const chatSuccessBodySchema = z.object({
35
+ ok: z.literal(true),
36
+ reply: z.string().min(1),
37
+ tools_called: z.array(z.string()),
38
+ });
39
+ /** INT-AP-tools — request/response data (fields bind to libero-homm spec). */
40
+ export const apCreditDataSchema = z.object({
41
+ balance: z.number().int().nonnegative(),
42
+ credited: z.number().int().positive(),
43
+ source: z.string().min(1),
44
+ });
45
+ export const apBalanceDataSchema = z.object({
46
+ balance: z.number().int().nonnegative(),
47
+ });
48
+ export const apSpendDataSchema = z.object({
49
+ balance: z.number().int().nonnegative(),
50
+ spent: z.number().int().positive(),
51
+ });
52
+ export const REST_V1 = {
53
+ health: { method: "GET", path: "/api/v1/health" },
54
+ invokeTool: { method: "POST", path: "/api/v1/tools/:toolName" },
55
+ chat: { method: "POST", path: "/api/v1/chat" },
56
+ };
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * libero REST server — HTTP adapter over the same tool registry (MC-0b).
4
+ *
5
+ * Usage:
6
+ * LIBERO_REST_TOKENS='{"<token>":"<libero_user_id>"}' libero-rest
7
+ * DB_PATH=/path/to/libero.db LIBERO_REST_PORT=8787 libero-rest
8
+ *
9
+ * Default bind 127.0.0.1 (local trial). Same DB_PATH as MCP → same ledger.
10
+ */
11
+ import { serve } from "@hono/node-server";
12
+ import { homedir } from "node:os";
13
+ import { join } from "node:path";
14
+ import { initDb, closeDb } from "../data/db.js";
15
+ import { createToolRuntime } from "./server-core.js";
16
+ import { createRestApp } from "./src/rest/app.js";
17
+ import { parseRestTokens } from "./src/rest/tokens.js";
18
+ import { chatLlmFromEnv } from "./src/chat/from-env.js";
19
+ const DB_PATH = process.env.DB_PATH ?? join(homedir(), ".libero", "libero.db");
20
+ const PORT = Number(process.env.LIBERO_REST_PORT ?? "8787");
21
+ const HOST = process.env.LIBERO_REST_HOST ?? "127.0.0.1";
22
+ let tokenMap;
23
+ try {
24
+ tokenMap = parseRestTokens(process.env);
25
+ }
26
+ catch (e) {
27
+ console.error(`[libero-rest] FATAL: ${e.message}`);
28
+ process.exit(1);
29
+ }
30
+ const db = initDb(DB_PATH);
31
+ console.error(`[libero-rest] DB initialized at ${DB_PATH}`);
32
+ const { registry } = createToolRuntime(db);
33
+ const chatLlm = chatLlmFromEnv(process.env);
34
+ if (!chatLlm) {
35
+ console.error("[libero-rest] chat disabled: set LIBERO_CHAT_BASE_URL, LIBERO_CHAT_API_KEY, LIBERO_CHAT_MODEL");
36
+ }
37
+ const linkSecret = process.env.LIBERO_LINK_TOKEN_SECRET?.trim() || undefined;
38
+ const linkBaseUrl = process.env.LIBERO_HOMM_LINK_BASE?.trim() || undefined;
39
+ const ttlSec = process.env.LIBERO_LINK_TOKEN_TTL_SEC ? Number(process.env.LIBERO_LINK_TOKEN_TTL_SEC) : undefined;
40
+ if (!linkSecret)
41
+ console.warn("[libero-rest] LIBERO_LINK_TOKEN_SECRET 未配置:homm 链接回退 tk_main(无逐用户短 token)");
42
+ const app = createRestApp({ registry, tokenMap, chatLlm: chatLlm ?? undefined, linkSecret, linkBaseUrl, ttlSec });
43
+ serve({ fetch: app.fetch, port: PORT, hostname: HOST }, (info) => {
44
+ console.error(`[libero-rest] listening on http://${info.address}:${info.port}`);
45
+ });
46
+ function shutdown() {
47
+ console.error("[libero-rest] Shutting down…");
48
+ closeDb();
49
+ process.exit(0);
50
+ }
51
+ process.on("SIGINT", shutdown);
52
+ process.on("SIGTERM", shutdown);