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.
- package/COLD_START.md +31 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/data/migrations/001_initial_schema.sql +43 -0
- package/data/migrations/002_seed_categories.sql +18 -0
- package/data/migrations/003_add_rating.sql +4 -0
- package/data/migrations/004_timer_sessions.sql +21 -0
- package/data/migrations/005_profile_settings.sql +5 -0
- package/data/migrations/006_add_timeblock_status.sql +1 -0
- package/data/migrations/007_reminders.sql +17 -0
- package/data/migrations/008_timer_target_ms.sql +5 -0
- package/data/migrations/009_tasks.sql +22 -0
- package/data/migrations/010_timer_task_id.sql +4 -0
- package/data/migrations/011_profile_default_confirmed.sql +4 -0
- package/data/migrations/012_identity_tables.sql +68 -0
- package/data/migrations/013_identity_managed_by.sql +3 -0
- package/data/migrations/014_task_difficulty_priority.sql +6 -0
- package/data/migrations/015_timeblock_asked_at.sql +5 -0
- package/data/migrations/016_intent_columns.sql +8 -0
- package/data/migrations/017_ap_wallet.sql +25 -0
- package/data/migrations/018_ap_rewards.sql +21 -0
- package/data/migrations/019_ap_bounty.sql +10 -0
- package/data/migrations/020_chat_turns.sql +10 -0
- package/data/migrations/021_portrait.sql +4 -0
- package/data/migrations/022_family_emoji_single.sql +3 -0
- package/data/migrations/023_ap_balance_view_log.sql +9 -0
- package/data/schema.sql +75 -0
- package/dist/data/db.js +83 -0
- package/dist/data/migrations/001_initial_schema.sql +43 -0
- package/dist/data/migrations/002_seed_categories.sql +18 -0
- package/dist/data/migrations/003_add_rating.sql +4 -0
- package/dist/data/migrations/004_timer_sessions.sql +21 -0
- package/dist/data/migrations/005_profile_settings.sql +5 -0
- package/dist/data/migrations/006_add_timeblock_status.sql +1 -0
- package/dist/data/migrations/007_reminders.sql +17 -0
- package/dist/data/migrations/008_timer_target_ms.sql +5 -0
- package/dist/data/migrations/009_tasks.sql +22 -0
- package/dist/data/migrations/010_timer_task_id.sql +4 -0
- package/dist/data/migrations/011_profile_default_confirmed.sql +4 -0
- package/dist/data/migrations/012_identity_tables.sql +68 -0
- package/dist/data/migrations/013_identity_managed_by.sql +3 -0
- package/dist/data/migrations/014_task_difficulty_priority.sql +6 -0
- package/dist/data/migrations/015_timeblock_asked_at.sql +5 -0
- package/dist/data/migrations/016_intent_columns.sql +8 -0
- package/dist/data/migrations/017_ap_wallet.sql +25 -0
- package/dist/data/migrations/018_ap_rewards.sql +21 -0
- package/dist/data/migrations/019_ap_bounty.sql +10 -0
- package/dist/data/migrations/020_chat_turns.sql +10 -0
- package/dist/data/migrations/021_portrait.sql +4 -0
- package/dist/data/migrations/022_family_emoji_single.sql +3 -0
- package/dist/data/migrations/023_ap_balance_view_log.sql +9 -0
- package/dist/data/schema.sql +75 -0
- package/dist/knowledge/_registry/dimensions.yaml +10 -0
- package/dist/knowledge/_registry/personas.yaml +7 -0
- package/dist/knowledge/_schema/analysis-model.schema.js +32 -0
- package/dist/knowledge/_schema/entry.schema.js +45 -0
- package/dist/knowledge/_schema/persona.schema.js +23 -0
- package/dist/knowledge/_schema/scenario-pack.schema.js +29 -0
- package/dist/knowledge/analysis-models/review-default.yaml +16 -0
- package/dist/knowledge/analysis-models/review-summer-plan.yaml +15 -0
- package/dist/knowledge/brain-science/brain-deep-warmup.yaml +22 -0
- package/dist/knowledge/brain-science/brain-emotion-granularity.yaml +22 -0
- package/dist/knowledge/brain-science/brain-env-engineering.yaml +22 -0
- package/dist/knowledge/brain-science/brain-extended-mind.yaml +22 -0
- package/dist/knowledge/brain-science/brain-friction-barrier.yaml +22 -0
- package/dist/knowledge/brain-science/brain-peak-end.yaml +29 -0
- package/dist/knowledge/brain-science/brain-pomodoro.yaml +31 -0
- package/dist/knowledge/brain-science/brain-revenge-bedtime.yaml +22 -0
- package/dist/knowledge/brain-science/brain-single-variable.yaml +15 -0
- package/dist/knowledge/brain-science/brain-tiny-habits.yaml +22 -0
- package/dist/knowledge/energy/energy-active-recovery.yaml +22 -0
- package/dist/knowledge/energy/energy-deliberate-rest.yaml +22 -0
- package/dist/knowledge/energy/energy-exercise-embedded.yaml +22 -0
- package/dist/knowledge/energy/energy-fixed-wake-time.yaml +22 -0
- package/dist/knowledge/energy/energy-four-energy-radar.yaml +22 -0
- package/dist/knowledge/energy/energy-intensity-recovery.yaml +22 -0
- package/dist/knowledge/scenario-packs/pack-summer-kid.yaml +12 -0
- package/dist/knowledge/src/repo/fs-yaml.js +252 -0
- package/dist/knowledge/src/repo/types.js +1 -0
- package/dist/knowledge/time/time-batch-windows.yaml +22 -0
- package/dist/knowledge/time/time-conscious-abandon.yaml +22 -0
- package/dist/knowledge/time/time-deep-work-block.yaml +22 -0
- package/dist/knowledge/time/time-finite-commitment.yaml +22 -0
- package/dist/knowledge/time/time-forced-whitespace.yaml +22 -0
- package/dist/knowledge/time/time-gtd-next-action.yaml +22 -0
- package/dist/knowledge/time/time-three-tier-list.yaml +22 -0
- package/dist/mcp/cold-start.js +43 -0
- package/dist/mcp/contract/v1/rest.js +56 -0
- package/dist/mcp/rest-server.js +52 -0
- package/dist/mcp/server-core.js +1334 -0
- package/dist/mcp/server.js +34 -0
- package/dist/mcp/src/ap/index.js +14 -0
- package/dist/mcp/src/ap/rewards.js +44 -0
- package/dist/mcp/src/categories/index.js +12 -0
- package/dist/mcp/src/chat/from-env.js +111 -0
- package/dist/mcp/src/chat/history.js +35 -0
- package/dist/mcp/src/chat/loop.js +131 -0
- package/dist/mcp/src/chat/portrait.js +133 -0
- package/dist/mcp/src/chat/system-prompt.js +23 -0
- package/dist/mcp/src/chat/tool-names.js +27 -0
- package/dist/mcp/src/chat/tool-schema.js +20 -0
- package/dist/mcp/src/chat/types.js +1 -0
- package/dist/mcp/src/clock/index.js +78 -0
- package/dist/mcp/src/coachmod/index.js +135 -0
- package/dist/mcp/src/host-adapters/hermes-cron.js +185 -0
- package/dist/mcp/src/host-adapters/index.js +61 -0
- package/dist/mcp/src/host-adapters/types.js +7 -0
- package/dist/mcp/src/identity/equivalent-ids.js +41 -0
- package/dist/mcp/src/identity/in-memory.js +100 -0
- package/dist/mcp/src/identity/resolve.js +60 -0
- package/dist/mcp/src/identity/types.js +4 -0
- package/dist/mcp/src/matrix/index.js +15 -0
- package/dist/mcp/src/profile/confirm-default.js +48 -0
- package/dist/mcp/src/profile/index.js +298 -0
- package/dist/mcp/src/profile-confirm.js +28 -0
- package/dist/mcp/src/profile-helpers.js +109 -0
- package/dist/mcp/src/reminder/hermes-channel.js +40 -0
- package/dist/mcp/src/reminder/index.js +70 -0
- package/dist/mcp/src/reminder/push-channel.js +10 -0
- package/dist/mcp/src/repo/factory.js +34 -0
- package/dist/mcp/src/repo/in-memory.js +469 -0
- package/dist/mcp/src/repo/sqlite-ap.js +188 -0
- package/dist/mcp/src/repo/sqlite-helpers.js +39 -0
- package/dist/mcp/src/repo/sqlite-identity.js +129 -0
- package/dist/mcp/src/repo/sqlite.js +754 -0
- package/dist/mcp/src/repo/types.js +4 -0
- package/dist/mcp/src/rest/app.js +121 -0
- package/dist/mcp/src/rest/invoke-tool.js +98 -0
- package/dist/mcp/src/rest/short-token.js +38 -0
- package/dist/mcp/src/rest/tokens.js +55 -0
- package/dist/mcp/src/scheduler/index.js +319 -0
- package/dist/mcp/src/stats/index.js +29 -0
- package/dist/mcp/src/stickiness/report.js +174 -0
- package/dist/mcp/src/stickiness/types.js +1 -0
- package/dist/mcp/src/task/index.js +412 -0
- package/dist/mcp/src/timeblock/index.js +206 -0
- package/dist/mcp/src/timeline/index.js +705 -0
- package/dist/mcp/src/timer/index.js +234 -0
- package/dist/mcp/src/user-id-resolver.js +30 -0
- package/dist/mcp/src/weixin/app.js +97 -0
- package/dist/mcp/src/weixin/custom-send.js +82 -0
- package/dist/mcp/src/weixin/handle-text.js +49 -0
- package/dist/mcp/src/weixin/reminder-loop.js +39 -0
- package/dist/mcp/src/weixin/signature.js +13 -0
- package/dist/mcp/src/weixin/tencent-asr.js +101 -0
- package/dist/mcp/src/weixin/xml.js +37 -0
- package/dist/mcp/weixin-server.js +158 -0
- package/knowledge/_registry/dimensions.yaml +10 -0
- package/knowledge/_registry/personas.yaml +7 -0
- package/knowledge/_schema/analysis-model.schema.ts +36 -0
- package/knowledge/_schema/entry.schema.ts +50 -0
- package/knowledge/_schema/persona.schema.ts +30 -0
- package/knowledge/_schema/scenario-pack.schema.ts +33 -0
- package/knowledge/analysis-models/review-default.yaml +16 -0
- package/knowledge/analysis-models/review-summer-plan.yaml +15 -0
- package/knowledge/brain-science/brain-deep-warmup.yaml +22 -0
- package/knowledge/brain-science/brain-emotion-granularity.yaml +22 -0
- package/knowledge/brain-science/brain-env-engineering.yaml +22 -0
- package/knowledge/brain-science/brain-extended-mind.yaml +22 -0
- package/knowledge/brain-science/brain-friction-barrier.yaml +22 -0
- package/knowledge/brain-science/brain-peak-end.yaml +29 -0
- package/knowledge/brain-science/brain-pomodoro.yaml +31 -0
- package/knowledge/brain-science/brain-revenge-bedtime.yaml +22 -0
- package/knowledge/brain-science/brain-single-variable.yaml +15 -0
- package/knowledge/brain-science/brain-tiny-habits.yaml +22 -0
- package/knowledge/energy/energy-active-recovery.yaml +22 -0
- package/knowledge/energy/energy-deliberate-rest.yaml +22 -0
- package/knowledge/energy/energy-exercise-embedded.yaml +22 -0
- package/knowledge/energy/energy-fixed-wake-time.yaml +22 -0
- package/knowledge/energy/energy-four-energy-radar.yaml +22 -0
- package/knowledge/energy/energy-intensity-recovery.yaml +22 -0
- package/knowledge/scenario-packs/pack-summer-kid.yaml +12 -0
- package/knowledge/src/repo/fs-yaml.ts +282 -0
- package/knowledge/src/repo/types.ts +24 -0
- package/knowledge/tests/fixtures/base/_registry/dimensions.yaml +4 -0
- package/knowledge/tests/fixtures/base/time/valid-entry.yaml +24 -0
- package/knowledge/tests/fixtures/dup/_registry/dimensions.yaml +4 -0
- package/knowledge/tests/fixtures/dup/time/entry-a.yaml +13 -0
- package/knowledge/tests/fixtures/dup/time/entry-b.yaml +13 -0
- package/knowledge/tests/fixtures/unregistered/_registry/dimensions.yaml +7 -0
- package/knowledge/tests/fixtures/unregistered/time/anxiety-entry.yaml +13 -0
- package/knowledge/tests/repo/fs-yaml-knowledge-repo.test.ts +333 -0
- package/knowledge/time/time-batch-windows.yaml +22 -0
- package/knowledge/time/time-conscious-abandon.yaml +22 -0
- package/knowledge/time/time-deep-work-block.yaml +22 -0
- package/knowledge/time/time-finite-commitment.yaml +22 -0
- package/knowledge/time/time-forced-whitespace.yaml +22 -0
- package/knowledge/time/time-gtd-next-action.yaml +22 -0
- package/knowledge/time/time-three-tier-list.yaml +22 -0
- package/knowledge/validate.ts +50 -0
- package/package.json +76 -0
- package/scripts/postinstall-cold-start.js +45 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SqliteIdentityRepo — persists S40 identity layer to user_identity + user_platform_alias.
|
|
3
|
+
*
|
|
4
|
+
* §4.5 静默折叠声明:
|
|
5
|
+
* - FK / PK violation 抛错(依赖 sqlite 的 PRAGMA foreign_keys = ON 或应用层校验)
|
|
6
|
+
* - 应用层显式 if-exist check + throw,不靠 sqlite 静默拒绝
|
|
7
|
+
*/
|
|
8
|
+
export class SqliteIdentityRepo {
|
|
9
|
+
db;
|
|
10
|
+
constructor(db) {
|
|
11
|
+
this.db = db;
|
|
12
|
+
}
|
|
13
|
+
async createIdentity(input) {
|
|
14
|
+
const existing = this.db
|
|
15
|
+
.prepare("SELECT 1 FROM user_identity WHERE libero_user_id = ?")
|
|
16
|
+
.get(input.libero_user_id);
|
|
17
|
+
if (existing) {
|
|
18
|
+
throw new Error(`identity already exists: libero_user_id=${input.libero_user_id}`);
|
|
19
|
+
}
|
|
20
|
+
const now = new Date().toISOString().replace("T", " ").replace("Z", "");
|
|
21
|
+
this.db
|
|
22
|
+
.prepare(`INSERT INTO user_identity (libero_user_id, display_name, created_at, updated_at)
|
|
23
|
+
VALUES (?, ?, ?, ?)`)
|
|
24
|
+
.run(input.libero_user_id, input.display_name ?? null, now, now);
|
|
25
|
+
return input.libero_user_id;
|
|
26
|
+
}
|
|
27
|
+
async getIdentity(libero_user_id) {
|
|
28
|
+
const row = this.db
|
|
29
|
+
.prepare("SELECT libero_user_id, display_name, created_at, updated_at FROM user_identity WHERE libero_user_id = ?")
|
|
30
|
+
.get(libero_user_id);
|
|
31
|
+
if (!row)
|
|
32
|
+
return null;
|
|
33
|
+
return {
|
|
34
|
+
libero_user_id: row.libero_user_id,
|
|
35
|
+
display_name: row.display_name,
|
|
36
|
+
created_at: row.created_at,
|
|
37
|
+
updated_at: row.updated_at,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async bindAlias(input) {
|
|
41
|
+
// FK check
|
|
42
|
+
const owner = this.db
|
|
43
|
+
.prepare("SELECT 1 FROM user_identity WHERE libero_user_id = ?")
|
|
44
|
+
.get(input.libero_user_id);
|
|
45
|
+
if (!owner) {
|
|
46
|
+
throw new Error(`bindAlias FK violation: libero_user_id not found: ${input.libero_user_id}`);
|
|
47
|
+
}
|
|
48
|
+
// PK check
|
|
49
|
+
const existing = this.db
|
|
50
|
+
.prepare("SELECT 1 FROM user_platform_alias WHERE platform = ? AND platform_user_id = ?")
|
|
51
|
+
.get(input.platform, input.platform_user_id);
|
|
52
|
+
if (existing) {
|
|
53
|
+
throw new Error(`alias already bound: platform=${input.platform} platform_user_id=${input.platform_user_id}`);
|
|
54
|
+
}
|
|
55
|
+
const now = new Date().toISOString().replace("T", " ").replace("Z", "");
|
|
56
|
+
this.db
|
|
57
|
+
.prepare(`INSERT INTO user_platform_alias (libero_user_id, platform, platform_user_id, chat_id, bound_at)
|
|
58
|
+
VALUES (?, ?, ?, ?, ?)`)
|
|
59
|
+
.run(input.libero_user_id, input.platform, input.platform_user_id, input.chat_id ?? input.platform_user_id, now);
|
|
60
|
+
}
|
|
61
|
+
async listAliases(libero_user_id) {
|
|
62
|
+
const rows = this.db
|
|
63
|
+
.prepare(`SELECT libero_user_id, platform, platform_user_id, chat_id, bound_at
|
|
64
|
+
FROM user_platform_alias
|
|
65
|
+
WHERE libero_user_id = ?
|
|
66
|
+
ORDER BY bound_at ASC`)
|
|
67
|
+
.all(libero_user_id);
|
|
68
|
+
return rows.map((r) => ({ ...r }));
|
|
69
|
+
}
|
|
70
|
+
async findAliasByPlatformUserId(platform_user_id) {
|
|
71
|
+
const row = this.db
|
|
72
|
+
.prepare(`SELECT libero_user_id, platform, platform_user_id, chat_id, bound_at
|
|
73
|
+
FROM user_platform_alias
|
|
74
|
+
WHERE platform_user_id = ?
|
|
75
|
+
LIMIT 1`)
|
|
76
|
+
.get(platform_user_id);
|
|
77
|
+
return row ? { ...row } : null;
|
|
78
|
+
}
|
|
79
|
+
async listAllIdentities() {
|
|
80
|
+
const rows = this.db
|
|
81
|
+
.prepare(`SELECT libero_user_id, display_name, managed_by, created_at, updated_at
|
|
82
|
+
FROM user_identity
|
|
83
|
+
ORDER BY created_at ASC`)
|
|
84
|
+
.all();
|
|
85
|
+
return rows.map((r) => ({ ...r }));
|
|
86
|
+
}
|
|
87
|
+
async getManager(libero_user_id) {
|
|
88
|
+
const row = this.db
|
|
89
|
+
.prepare(`SELECT ui.libero_user_id, ui.managed_by, mgr.display_name as manager_display_name
|
|
90
|
+
FROM user_identity ui
|
|
91
|
+
LEFT JOIN user_identity mgr ON mgr.libero_user_id = ui.managed_by
|
|
92
|
+
WHERE ui.libero_user_id = ?`)
|
|
93
|
+
.get(libero_user_id);
|
|
94
|
+
if (!row) {
|
|
95
|
+
throw new Error(`getManager: libero_user_id not found: ${libero_user_id}`);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
libero_user_id: row.libero_user_id,
|
|
99
|
+
managed_by: row.managed_by,
|
|
100
|
+
manager_display_name: row.manager_display_name,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async setManager(input) {
|
|
104
|
+
// User existence check
|
|
105
|
+
const user = this.db
|
|
106
|
+
.prepare("SELECT 1 FROM user_identity WHERE libero_user_id = ?")
|
|
107
|
+
.get(input.libero_user_id);
|
|
108
|
+
if (!user) {
|
|
109
|
+
throw new Error(`setManager: libero_user_id not found: ${input.libero_user_id}`);
|
|
110
|
+
}
|
|
111
|
+
// Manager FK check (if non-null)
|
|
112
|
+
if (input.managed_by !== null) {
|
|
113
|
+
const mgr = this.db
|
|
114
|
+
.prepare("SELECT 1 FROM user_identity WHERE libero_user_id = ?")
|
|
115
|
+
.get(input.managed_by);
|
|
116
|
+
if (!mgr) {
|
|
117
|
+
throw new Error(`setManager: manager libero_user_id not found: ${input.managed_by}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const now = new Date().toISOString().replace("T", " ").replace("Z", "");
|
|
121
|
+
this.db
|
|
122
|
+
.prepare("UPDATE user_identity SET managed_by = ?, updated_at = ? WHERE libero_user_id = ?")
|
|
123
|
+
.run(input.managed_by, now, input.libero_user_id);
|
|
124
|
+
return {
|
|
125
|
+
libero_user_id: input.libero_user_id,
|
|
126
|
+
managed_by: input.managed_by,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|