hob-bot 0.0.0-stage → 1.0.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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -2
  3. package/README.zh-CN.md +112 -0
  4. package/bin/hob.mjs +7 -0
  5. package/dist/web/assets/index-D88l35PH.css +1 -0
  6. package/dist/web/assets/index-DUs8nN3E.js +218 -0
  7. package/dist/web/favicon.ico +0 -0
  8. package/dist/web/fonts/inter-latin.woff2 +0 -0
  9. package/dist/web/fonts/jetbrains-mono-latin.woff2 +0 -0
  10. package/dist/web/icons/apple-touch-icon-180.png +0 -0
  11. package/dist/web/icons/favicon-32.png +0 -0
  12. package/dist/web/icons/icon-192.png +0 -0
  13. package/dist/web/icons/icon-512.png +0 -0
  14. package/dist/web/icons/icon-maskable-512.png +0 -0
  15. package/dist/web/index.html +32 -0
  16. package/dist/web/manifest.webmanifest +16 -0
  17. package/dist/web/sw.js +131 -0
  18. package/package.json +62 -4
  19. package/server/src/actions.ts +230 -0
  20. package/server/src/boot.ts +85 -0
  21. package/server/src/bus.ts +21 -0
  22. package/server/src/config.ts +123 -0
  23. package/server/src/cron-text.ts +49 -0
  24. package/server/src/delegations.ts +113 -0
  25. package/server/src/files.ts +142 -0
  26. package/server/src/http.ts +802 -0
  27. package/server/src/ids.ts +19 -0
  28. package/server/src/image.ts +218 -0
  29. package/server/src/imports.ts +302 -0
  30. package/server/src/jobs.ts +730 -0
  31. package/server/src/main.ts +69 -0
  32. package/server/src/memory.ts +272 -0
  33. package/server/src/models.ts +358 -0
  34. package/server/src/overview.ts +116 -0
  35. package/server/src/pages.ts +54 -0
  36. package/server/src/password.ts +23 -0
  37. package/server/src/pi.ts +273 -0
  38. package/server/src/prompt.ts +227 -0
  39. package/server/src/providers.ts +532 -0
  40. package/server/src/push.ts +285 -0
  41. package/server/src/router-tools.ts +549 -0
  42. package/server/src/router.ts +841 -0
  43. package/server/src/routines.ts +129 -0
  44. package/server/src/runtime.ts +104 -0
  45. package/server/src/search.ts +91 -0
  46. package/server/src/secrets.ts +46 -0
  47. package/server/src/settings.ts +452 -0
  48. package/server/src/skills.ts +150 -0
  49. package/server/src/store.ts +324 -0
  50. package/server/src/text.ts +14 -0
  51. package/server/src/time.ts +42 -0
  52. package/server/src/transcript.ts +272 -0
  53. package/server/src/worker-tools.ts +129 -0
  54. package/shared/command.ts +42 -0
  55. package/shared/files.ts +141 -0
  56. package/shared/media.ts +17 -0
  57. package/shared/model-note.ts +32 -0
  58. package/shared/page-shell.ts +108 -0
  59. package/shared/search.ts +19 -0
  60. package/shared/skills.ts +37 -0
  61. package/shared/sprites.ts +422 -0
  62. package/shared/thinking.ts +118 -0
  63. package/shared/types.ts +631 -0
  64. package/vendor/lore-pi-extension/README.md +28 -0
  65. package/vendor/lore-pi-extension/api.ts +140 -0
  66. package/vendor/lore-pi-extension/formatters.ts +204 -0
  67. package/vendor/lore-pi-extension/hooks.ts +195 -0
  68. package/vendor/lore-pi-extension/index.ts +25 -0
  69. package/vendor/lore-pi-extension/package.json +23 -0
  70. package/vendor/lore-pi-extension/skills.ts +447 -0
  71. package/vendor/lore-pi-extension/tools.ts +344 -0
  72. package/vendor/lore-pi-extension/uri.ts +67 -0
  73. package/vendor/lore-pi-extension/vendor/skill-workcopy/index.d.mts +266 -0
  74. package/vendor/lore-pi-extension/vendor/skill-workcopy/index.mjs +1328 -0
  75. package/vendor/lore-pi-extension/vendor/skill-workcopy/skills-sync.d.mts +33 -0
  76. package/vendor/lore-pi-extension/vendor/skill-workcopy/skills-sync.mjs +202 -0
@@ -0,0 +1,631 @@
1
+ // Hob 前后端共用的契约。改这里 = 两边一起改。说明见 docs/architecture.md。
2
+ import type { SearchSettings } from "./search.ts";
3
+
4
+ export type Iso = string; // ISO 8601 时间
5
+
6
+ /** 思考档,和 pi 的 ThinkingLevel 一致。 */
7
+ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
8
+
9
+ /**
10
+ * 一个模型的自定义思考档:档位 → 发给服务商的字符。
11
+ * 字符串 = 用户指定的字符;空串 = 这一档开着,但按服务商协议的默认(不写给引擎);null = 这一档不要。
12
+ * 没写的键按默认规则算(见 shared/thinking.ts)。
13
+ */
14
+ export type ThinkingLevelMapSetting = Partial<Record<ThinkingLevel, string | null>>;
15
+
16
+ /** 一个能被 Hob 用的模型:来自引擎的模型注册表(有凭据的聊天模型)。 */
17
+ export interface ModelInfo {
18
+ ref: string; // "provider/id"
19
+ provider: string;
20
+ id: string;
21
+ name: string; // 显示名,注册表里没有名字时等于 id
22
+ reasoning: boolean; // 会推理(有思考档)
23
+ thinkingLevels: ThinkingLevel[]; // 这个模型能用的思考档(Hob 按设置里的自定义档位 / 默认规则算出来的)
24
+ input: ("text" | "image")[]; // 能吃什么;含 image 才能看图
25
+ contextWindow: number; // 上下文窗口(token)
26
+ maxTokens: number; // 单次最多输出
27
+ cost: { input: number; output: number }; // 每百万 token 的价格,货币由服务商决定
28
+ }
29
+
30
+ /** 模型 + 思考档。 */
31
+ export interface ModelPick {
32
+ ref: string; // "provider/id"
33
+ thinking: ThinkingLevel;
34
+ }
35
+
36
+ export interface ModelScores { smart: number; cost: number; speed: number }
37
+
38
+ /** 设置 → 模型:名单里的一项。 */
39
+ export interface RosterEntry {
40
+ ref: string;
41
+ note: string; // 可选的补充说明
42
+ scores?: ModelScores; // 旧数据没有分数时按模型信息推测
43
+ scoresConfirmed?: boolean; // 推测的分数是否已确认
44
+ thinking?: ThinkingLevel; // 这个模型的默认思考档
45
+ }
46
+
47
+ /** 设置 → 模型。 */
48
+ export interface ModelSettings {
49
+ roster: RosterEntry[]; // Hob 能用的模型
50
+ conversation: ModelPick; // 对话(助手本身)
51
+ work: ModelPick; // 任务执行(分派任务不指定就用它)
52
+ thinkingChoice?: "auto" | "fixed"; // 缺省 auto:助手按任务选择;fixed:使用模型默认档
53
+ /** 每个模型的自定义思考档,键是模型 ref("服务商/模型");没存就用 Hob 的默认规则 */
54
+ thinking?: Record<string, ThinkingLevelMapSetting>;
55
+ }
56
+
57
+ /** 设置 → 生图:关闭 / OpenAI 兼容接口。 */
58
+ export type ImageSettings = { source: "off" } | { source: "openai"; baseUrl: string; model: string; size?: string };
59
+
60
+ /** GET /api/image:生图接口的 Key 配没配(Key 永不回显)。 */
61
+ export interface ImageKeyView {
62
+ keyConfigured: boolean;
63
+ }
64
+
65
+ /** PUT /api/image:保存生图配置,返回整份设置和 Key 状态。 */
66
+ export interface ImageSettingsSaved {
67
+ settings: SettingsFile;
68
+ keyConfigured: boolean;
69
+ }
70
+
71
+ /** POST /api/image/test:生成测试图片。失败也是 200,原因在这里。 */
72
+ export type ImageTestResult = { ok: true; path: string } | { ok: false; error: string };
73
+
74
+ /** GET /api/models:可用模型 + 名单里的模型当前是否还可用。 */
75
+ export interface ModelsView {
76
+ models: ModelInfo[]; // 现在有凭据可用的聊天模型
77
+ roster: (RosterEntry & { unavailable?: boolean })[]; // 名单(unavailable 表示服务商删了或者没有 Key)
78
+ }
79
+
80
+ /** 兼容接口的协议。 */
81
+ export type ProviderApi = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai";
82
+
83
+ /** 兼容接口里的一个模型;extra 原样透传给引擎的模型配置(compat、thinkingLevelMap 之类)。 */
84
+ export interface ProviderModelSetting {
85
+ id: string;
86
+ name?: string;
87
+ input?: ("text" | "image")[];
88
+ reasoning?: boolean;
89
+ contextWindow?: number;
90
+ maxTokens?: number;
91
+ extra?: Record<string, unknown>;
92
+ }
93
+
94
+ /** 设置 → 服务商:引擎自带的服务商,只填 Key。 */
95
+ export interface BuiltinProviderSettings {
96
+ kind: "builtin";
97
+ id: string; // 引擎里的服务商 id,如 anthropic
98
+ }
99
+
100
+ /** 设置 → 服务商:兼容接口(地址 + 协议 + Key + 模型列表)。 */
101
+ export interface CustomProviderSettings {
102
+ kind: "custom";
103
+ id: string; // slug;模型 ref 是 "<id>/<模型 id>"
104
+ name: string;
105
+ api: ProviderApi;
106
+ baseUrl: string;
107
+ models: ProviderModelSetting[];
108
+ /** 服务商级字段(compat、headers、authHeader 等)原样透传给引擎,界面不编辑 */
109
+ extra?: Record<string, unknown>;
110
+ }
111
+
112
+ export type ProviderSettings = BuiltinProviderSettings | CustomProviderSettings;
113
+
114
+ /** 已配的服务商(Key 只报配没配,永不回显)。 */
115
+ export type ProviderView = ProviderSettings & { keyConfigured: boolean };
116
+
117
+ /** 一个模型现在的思考档:档位 + 发给服务商的字符(自定义或默认,Hob 算出来的)。 */
118
+ export interface ModelThinkingView {
119
+ ref: string; // "服务商/模型"
120
+ id: string;
121
+ name: string; // 显示名
122
+ reasoning: boolean; // 会推理才有思考档
123
+ input?: ("text" | "image")[];
124
+ contextWindow?: number;
125
+ levels: { level: ThinkingLevel; text: string }[]; // 从低到高;text 空串 = 没改过,按服务商协议的默认
126
+ custom: boolean; // 存过自定义档位(可以恢复默认)
127
+ }
128
+
129
+ /** GET /api/providers:已配的服务商、引擎自带的服务商目录、跟着一起回的整份设置(前端要新 revision)。 */
130
+ export interface ProvidersView {
131
+ providers: ProviderView[];
132
+ builtin: { id: string; name: string }[];
133
+ settings: SettingsFile;
134
+ /** 每个已配置服务商的模型和思考档,键是服务商 id;服务商详情里列模型、编辑思考档 */
135
+ models: Record<string, ModelThinkingView[]>;
136
+ }
137
+
138
+ /** PUT /api/models/thinking:存一个模型的自定义思考档。 */
139
+ export interface ModelThinkingPatch {
140
+ ref: string; // "服务商/模型"
141
+ /** 完整的档位表;null = 恢复默认(只用 Hob 的默认规则) */
142
+ levels: ThinkingLevelMapSetting | null;
143
+ }
144
+
145
+ /** PUT /api/models/thinking:存完的整份设置(新 revision)+ 这个模型现在的思考档。 */
146
+ export interface ModelThinkingSaved {
147
+ settings: SettingsFile;
148
+ thinking: ModelThinkingView;
149
+ }
150
+
151
+ /** POST /api/providers/discover:从兼容接口拉到的模型列表。 */
152
+ export interface DiscoveredModels {
153
+ models: { id: string; name?: string }[];
154
+ }
155
+
156
+ /** 导入时 Key 怎么来:字面值 / 环境变量 / 命令(不执行)/ 没有。 */
157
+ export type ProviderImportKey = "literal" | "env" | "command" | "none";
158
+
159
+ /** GET /api/providers/import:本机配置里能导入的一个服务商(不带 Key 明文)。 */
160
+ export interface ProviderImportItem {
161
+ id: string;
162
+ kind: "custom" | "builtin";
163
+ api?: ProviderApi;
164
+ baseUrl?: string;
165
+ models: number;
166
+ key: ProviderImportKey;
167
+ exists: boolean; // 已经配置过,导入会覆盖
168
+ selectable: boolean; // 不可选时 note 写原因
169
+ note?: string;
170
+ }
171
+
172
+ /** GET /api/providers/import:本机能导入的服务商 + 来源目录(界面显示用)。 */
173
+ export interface ProviderImportView {
174
+ source: string;
175
+ items: ProviderImportItem[];
176
+ }
177
+
178
+ /** GET /api/memory/lore/import:本机的 Lore 连接(不带 Token 明文)。 */
179
+ export interface LoreImportView {
180
+ source: string;
181
+ found: boolean;
182
+ baseUrl?: string;
183
+ tokenPresent: boolean;
184
+ }
185
+
186
+ /** 头像:「道具」或「道具:颜色」,如 "server"、"wifi:green";自画的记成 "custom" 或 "custom:颜色"(shared/sprites.ts) */
187
+ export type SpriteId = string;
188
+
189
+ /** AI 画的自定义道具:画法格式和 PROPS 里的一项相同,从第 0 行起逐行盖在火苗上,`.` 不动,其它字符查 pal。 */
190
+ export interface CustomProp {
191
+ art: string[]; // 最多 16 行、每行 16 字符;字符只能是 `.`、`k`(描边色,固定)或 pal 里的键
192
+ pal: Record<string, string>; // 单个小写字母 → #rrggbb;不能用火苗自己的 o y e 和描边 k,最多 6 种
193
+ dx: 0 | 1 | 2; // 火苗在 16×16 里的横向位置(2 = 居中)
194
+ }
195
+
196
+ export interface Assistant {
197
+ id: string; // 主助手固定 "hob";其余为 slug(小写字母数字连字符)
198
+ name: string; // 显示名,如 "写作"
199
+ duty: string; // 一句话职责,左栏大头像下的小字,如 "周报和文章";主助手为 "主助手"
200
+ dutyLong?: string; // 详细职责
201
+ sprite: SpriteId;
202
+ /** sprite 是 custom / custom:* 时的画法;换成内置道具后保留,随时能换回来 */
203
+ prop?: CustomProp;
204
+ primary: boolean; // 只有 hob 为 true
205
+ pinned: boolean; // 左栏顶部大头像
206
+ hidden: boolean; // 收起的助手
207
+ notify: boolean; // 需要确认时通知我
208
+ instructions: string; // 补充说明:用户可直接编辑的自定义指令,这个助手特有的做法写这里
209
+ /** 这个助手用哪些模型;缺省全部跟随设置 → 模型 */
210
+ models?: {
211
+ conversation?: ModelPick; // 不填 = 跟随全局的对话模型
212
+ work?: ModelPick; // 不填 = 跟随全局的任务模型
213
+ allowed?: string[]; // 可分派的模型 ref;缺省 = 名单全部
214
+ };
215
+ /** 派出去的活能用的能力;缺省全开(读总是有) */
216
+ abilities?: { exec: boolean; write: boolean; image: boolean };
217
+ createdAt: Iso;
218
+ splitFrom?: { from: string; at: Iso; conversations: number };
219
+ }
220
+
221
+ export interface AssistantSummary extends Assistant {
222
+ last?: { text: string; at: Iso }; // 对话最后一条(列表第二行)
223
+ unread: number; // 未读条数(>0 时大头像右上角橙点)
224
+ busy: boolean; // Router 正在回复(在跑的任务不算,任务状态看任务卡)
225
+ }
226
+
227
+ export interface Rule {
228
+ id: string;
229
+ text: string; // 规则内容,如 "发布公众号"
230
+ mode: "ask" | "allow"; // ask=执行前确认;allow=直接执行
231
+ changedAt: Iso; // 24 小时内变过 → 设置页显示 "最近修改"
232
+ }
233
+
234
+
235
+ export interface WorklogEntry {
236
+ at: Iso;
237
+ text: string; // 如 "每日简报:今天 6 条" / "完成任务:查页面卡顿"
238
+ jobId?: string;
239
+ }
240
+
241
+ export interface RoutineRun {
242
+ jobId: string;
243
+ at: Iso;
244
+ status: JobStatus;
245
+ }
246
+
247
+ export interface Routine {
248
+ id: string;
249
+ assistantId: string;
250
+ name: string; // 如 "每日简报"
251
+ instruction: string; // 要做什么
252
+ schedules: string[]; // cron 表达式,如 "0 9 * * *";可多个("再加一个")
253
+ active: boolean;
254
+ createdAt: Iso;
255
+ runs: RoutineRun[]; // 最近 20 次,新的在前
256
+ }
257
+
258
+ export interface Delegation {
259
+ id: string;
260
+ from: "hob";
261
+ to: string;
262
+ text: string;
263
+ createdAt: Iso;
264
+ status: "running" | "waiting" | "done" | "stuck" | "interrupted" | "returned";
265
+ jobIds: string[];
266
+ reply?: string;
267
+ returnedText?: string; // 退回时补充的用户要求
268
+ endedAt?: Iso;
269
+ approvalIds?: string[];
270
+ turnFinished?: boolean;
271
+ turnFailed?: boolean;
272
+ reportedAt?: Iso;
273
+ }
274
+
275
+ export type JobStatus =
276
+ | "queued"
277
+ | "running"
278
+ | "waiting" // 待确认(Worker 的 ask_user 未答)
279
+ | "done" // 已完成
280
+ | "stuck" // 受阻
281
+ | "failed"
282
+ | "stopped";
283
+
284
+ export interface ActivityLine {
285
+ at: Iso;
286
+ verb: "$" | "读" | "跑" | "改" | "写" | "搜" | "说";
287
+ text: string;
288
+ }
289
+
290
+ /** 任务的 token 和花费(pi 消息里有的就汇总)。 */
291
+ export interface JobUsage {
292
+ input: number;
293
+ output: number;
294
+ cost: number; // 美元
295
+ }
296
+
297
+ /**
298
+ * 任务过程的一步:说明文字、模型思考摘要、一次工具调用。
299
+ * 同 id 替换(工具输出流式更新用它),顺序就是时间顺序。
300
+ */
301
+ export interface JobStep {
302
+ id: string; // 工具调用用 toolCallId,文字用消息时间戳 + 序号
303
+ kind: "text" | "thinking" | "tool";
304
+ at: Iso;
305
+ /** 文字是谁说的:助手回复 / 你补的那句 */
306
+ from?: "assistant" | "user";
307
+ /** text / thinking 的正文 */
308
+ text?: string;
309
+ /** tool:工具名(bash / read / edit / write / grep / find / ls / report / ask_user) */
310
+ name?: string;
311
+ /** tool:一行中文,如 跑 `npm test` / 改 server/src/jobs.ts */
312
+ title?: string;
313
+ /** tool:参数(bash 的 command、read 的 path 和行范围、edit 的 path 和 edits) */
314
+ args?: Record<string, unknown>;
315
+ /** tool:结果文本(transcript 最多 20KB,实时事件最多 4KB) */
316
+ output?: string;
317
+ /** tool:结果太长被截断,全文在这个文件里 */
318
+ outputPath?: string;
319
+ isError?: boolean;
320
+ durationMs?: number;
321
+ /** tool:还在跑 */
322
+ running?: boolean;
323
+ }
324
+
325
+ /** GET /api/jobs/:id/transcript */
326
+ export interface JobTranscript {
327
+ job: Job;
328
+ steps: JobStep[];
329
+ }
330
+
331
+ /** GET /api/jobs?assistantId&status&before&limit(工作记录) */
332
+ export interface JobsPage {
333
+ jobs: Job[]; // 新的在前
334
+ hasMore: boolean;
335
+ }
336
+
337
+ export interface Job {
338
+ id: string; // "t-" + 4 位以上
339
+ assistantId: string;
340
+ assistantName?: string; // 建任务时的助手名:助手并回 Hob 后,任务详情里照样显示
341
+ title: string; // 如 "查页面卡顿"
342
+ instruction: string;
343
+ status: JobStatus;
344
+ statusReason?: string; // stuck/failed 的原因
345
+ createdAt: Iso;
346
+ startedAt?: Iso;
347
+ endedAt?: Iso;
348
+ usage?: JobUsage; // 输入/输出 token 和花费
349
+ durationMs?: number; // 用时(结束时间 − 开始时间)
350
+ stats: { reads: number; commands: number; edits: number };
351
+ summary?: string; // report 的摘要(≤600 字)
352
+ reportPath?: string; // 完整报告
353
+ files?: string[]; // 产出文件(绝对路径)
354
+ cwd?: string; // 工作目录(缺省为 HOB_HOME/jobs/<id>/work)
355
+ model?: string; // 这个任务用的模型("provider/id")
356
+ thinking?: ThinkingLevel; // 这个任务的思考档
357
+ modelReason?: string; // 换了模型的原因,如「需要看图,换成了 X」
358
+ inputs?: string[]; // 交给任务的附件(绝对路径)
359
+ routineId?: string; // 由定时触发
360
+ delegationId?: string; // 转交回合创建的任务
361
+ activity: ActivityLine[]; // 最近 200 行
362
+ }
363
+
364
+ export interface ApprovalOption {
365
+ key: "A" | "B" | "C";
366
+ label: string; // 如 "以后同类内容直接发布,无需确认"
367
+ always?: boolean; // 选中后写一条 allow 规则
368
+ }
369
+
370
+ export interface Approval {
371
+ id: string;
372
+ assistantId: string; // 提问的助手
373
+ title: string; // 如 "发到公众号吗?"
374
+ detail?: string; // 如 "发出去就撤不回了。你选之前我不会发。"
375
+ options: ApprovalOption[];
376
+ status: "pending" | "answered" | "expired";
377
+ chosen?: ApprovalOption["key"];
378
+ /** 用户没选选项、而是自己写的那句(走 chosen 时没有这个字段) */
379
+ answerText?: string;
380
+ source: "router" | "job";
381
+ jobId?: string;
382
+ ruleText?: string; // always 选项要写进规则的文字,如 "发布公众号"
383
+ createdAt: Iso;
384
+ answeredAt?: Iso;
385
+ }
386
+
387
+ export interface Draft {
388
+ id: string;
389
+ assistantId: string; // 提议者(hob)
390
+ status: "pending" | "created" | "dismissed";
391
+ name: string;
392
+ sprite: SpriteId;
393
+ /** sprite 是 custom 时的画法(propose_assistant 的 prop_art) */
394
+ prop?: CustomProp;
395
+ duty: string; // 一句话职责
396
+ dutyLong: string; // 草稿卡 "职责" 行
397
+ routines: { name: string; instruction: string; schedule: string }[]; // 草稿卡 "定时任务" 行
398
+ routinesText: string; // 草稿卡 "定时任务" 行的展示文字
399
+ askFirst: string[]; // 执行前确认的事项
400
+ instructions: string[]; // 补充说明(建好后写进新助手的 instructions)
401
+ carry: { conversations: number }; // 迁移几段对话(记忆是所有助手共用的一份,不用迁移)
402
+ createdAssistantId?: string;
403
+ createdAt: Iso;
404
+ }
405
+
406
+ export type NoteIcon = "memory" | "rule" | "routine" | "split" | "info";
407
+
408
+ export type Item = (
409
+ | { kind: "user"; id: string; at: Iso; text: string; quote?: { itemId: string; text: string }; files?: string[]; from?: { assistantId: string; name: string; delegationId: string } }
410
+ | { kind: "assistant"; id: string; at: Iso; text: string; streaming?: boolean; routine?: { id: string; name: string } }
411
+ | { kind: "note"; id: string; at: Iso; icon: NoteIcon; text: string; handbackId?: string } // 居中灰色一行,如 "记忆已更新 · 不看融资新闻"
412
+ | { kind: "question"; id: string; at: Iso; approvalId: string }
413
+ | { kind: "job"; id: string; at: Iso; jobId: string }
414
+ | { kind: "delegation"; id: string; at: Iso; delegationId: string }
415
+ | { kind: "draft"; id: string; at: Iso; draftId: string }
416
+ | { kind: "file"; id: string; at: Iso; path: string; name: string; meta?: string } // meta 如 "3200 字 · 4 张图"
417
+ ) & {
418
+ /** 这条开启新的一组,前端在它上面拉开间距:事件触发的新一轮回复,或任务直接发进对话的图片、提问卡 */
419
+ lead?: true;
420
+ };
421
+
422
+ export interface PageLive {
423
+ assistantId: string;
424
+ callId: string;
425
+ title?: string;
426
+ summary?: string;
427
+ html: string;
428
+ state: "writing" | "done" | "failed";
429
+ path?: string;
430
+ error?: string;
431
+ }
432
+
433
+ export interface ItemsPage {
434
+ pageLive?: PageLive[];
435
+ items: Item[]; // 旧 → 新
436
+ approvals: Approval[];
437
+ jobs: Job[];
438
+ drafts: Draft[];
439
+ delegations?: Delegation[];
440
+ hasMore: boolean;
441
+ }
442
+
443
+ export interface Profile {
444
+ assistant: AssistantSummary;
445
+ rules: Rule[];
446
+ routines: Routine[];
447
+ worklog: WorklogEntry[]; // 最近 30 条,新的在前
448
+ }
449
+
450
+ export type MemoryProvider = "local" | "lore" | "off";
451
+
452
+ /** Lore 连接信息(永远不带 Token,只有 "配没配")。 */
453
+ export interface LoreConnectionInfo {
454
+ configured: boolean; // 地址和 Token 都有
455
+ baseUrl: string | null;
456
+ source: "config" | "none"; // 地址从哪来:Hob 自己的 lore/config.json / 没有
457
+ tokenConfigured: boolean;
458
+ }
459
+
460
+ /** GET /api/memory:记忆提供者 + Lore 连接状态。 */
461
+ export interface MemoryConfig {
462
+ revision: number;
463
+ provider: MemoryProvider;
464
+ providerExplicit: boolean; // 用户在设置里明确选过(没选过就是按有没有配好 Lore 推出的)
465
+ lore: LoreConnectionInfo;
466
+ }
467
+
468
+ /** POST /api/memory/lore-test:测试失败也是 200,原因在这里。 */
469
+ export type LoreTestResult =
470
+ | { ok: true; baseUrl: string }
471
+ | { ok: false; reason: "invalid_url" | "insecure_http" | "missing_token" | "unauthorized" | "unreachable" };
472
+
473
+ export type Theme = "system" | "light" | "dark";
474
+
475
+ /** 设置 → 通用。 */
476
+ export interface GeneralSettings {
477
+ /** 是否允许助手生成展示页面;旧设置缺省为开启。 */
478
+ showPage?: boolean;
479
+ theme: Theme;
480
+ timezone: string; // IANA 时区名,默认系统时区
481
+ aboutYou: { name: string; language: string; notes: string }; // 空字符串 = 没填,提示词里就不出这一节
482
+ }
483
+
484
+ /** 设置 → 工作。 */
485
+ export interface WorkSettings {
486
+ maxJobs: number; // 最大并行任务数,1–8
487
+ jobStallMinutes: number; // 任务多久无响应视为受阻
488
+ routerStallMinutes: number; // 助手回复多久无响应视为受阻
489
+ }
490
+
491
+ /** 设置 → 通知。 */
492
+ export interface PushSettings {
493
+ /** VAPID subject 用的邮箱;空就用 mailto:hob@localhost */
494
+ email: string;
495
+ }
496
+
497
+ export interface Settings {
498
+ general: GeneralSettings;
499
+ /** 服务商(Key 在 secrets.json,这里只放不敏感的) */
500
+ providers: ProviderSettings[];
501
+ models: ModelSettings;
502
+ image: ImageSettings;
503
+ search: SearchSettings;
504
+ /** 停用的技能,键为来源和技能名。 */
505
+ skills?: { disabled: string[] };
506
+ work: WorkSettings;
507
+ push: PushSettings;
508
+ }
509
+
510
+ /** HOB_HOME/settings.json:界面可改的设置,写入走 revision 比对(CAS)。 */
511
+ export interface SettingsFile {
512
+ revision: number;
513
+ settings: Settings;
514
+ }
515
+
516
+ /** PUT /api/settings:按节合并,没给的项保持原样。 */
517
+ export interface SettingsPatch {
518
+ general?: Omit<Partial<GeneralSettings>, "aboutYou"> & { aboutYou?: Partial<GeneralSettings["aboutYou"]> };
519
+ models?: Partial<ModelSettings>;
520
+ skills?: { disabled: string[] };
521
+ work?: Partial<WorkSettings>;
522
+ push?: Partial<PushSettings>;
523
+ }
524
+
525
+ /** 一台订阅了推送的设备(密钥只存服务端,不回给页面)。 */
526
+ export interface PushDevice {
527
+ endpoint: string;
528
+ label: string; // 设备名,如 "iPhone" / "Chrome"
529
+ createdAt: Iso;
530
+ }
531
+
532
+ /** GET /api/push:浏览器订阅要的 publicKey + 已订阅设备。 */
533
+ export interface PushView {
534
+ publicKey: string; // VAPID 公钥(base64url)
535
+ email: string; // subject 用的邮箱(设置 → 通知)
536
+ devices: PushDevice[]; // 新的在前
537
+ }
538
+
539
+ /** 浏览器 PushSubscription.toJSON() 的形状(POST /api/push/subscribe 回传)。 */
540
+ export interface PushSubscriptionJson {
541
+ endpoint: string;
542
+ keys: { p256dh: string; auth: string };
543
+ }
544
+
545
+ /** GET /api/about:设置 → 关于 里显示的那几项。 */
546
+ export interface AboutInfo {
547
+ version: string; // Hob 的版本(package.json)
548
+ home: string; // 数据目录
549
+ }
550
+
551
+ /** 文件预览的种类(按扩展名判定,见 shared/files.ts);不认识的扩展名服务端嗅探内容后归成 code/text/other。 */
552
+ export type FileKind =
553
+ | "image"
554
+ | "svg"
555
+ | "pdf"
556
+ | "audio"
557
+ | "video"
558
+ | "markdown"
559
+ | "json"
560
+ | "csv"
561
+ | "html"
562
+ | "xml"
563
+ | "code"
564
+ | "text"
565
+ | "other";
566
+
567
+ /** GET /api/files/meta:预览面板要的文件信息(文件必须在这个任务的目录范围内)。 */
568
+ export interface FileMeta {
569
+ path: string; // 真实路径(符号链接已解开)
570
+ name: string;
571
+ size: number; // 字节
572
+ modifiedAt: Iso;
573
+ mime: string;
574
+ kind: FileKind;
575
+ text: boolean; // 按文本预览(二进制 false)
576
+ page?: boolean; // 展示页面目录中的渲染产物
577
+ }
578
+
579
+ /** GET /api/jobs/:id/files:任务工作目录里的一个文件。 */
580
+ export interface JobFileEntry {
581
+ path: string; // 绝对路径
582
+ rel: string; // 相对任务工作目录,如 "src/index.ts"
583
+ name: string;
584
+ size: number;
585
+ modifiedAt: Iso;
586
+ kind: FileKind;
587
+ }
588
+
589
+ /** GET /api/jobs/:id/files:任务工作目录(HOB_HOME/jobs/<id>/work)里的文件,最多 200 个。 */
590
+ export interface JobFilesView {
591
+ files: JobFileEntry[]; // 修改时间倒序
592
+ hasMore: boolean;
593
+ }
594
+
595
+ export interface Bootstrap {
596
+ assistants: AssistantSummary[];
597
+ jobs: Job[]; // 在跑的 + 最近 24 小时结束的
598
+ routines: Routine[];
599
+ approvals: Approval[]; // pending
600
+ settings: SettingsFile;
601
+ delegations?: Delegation[];
602
+ }
603
+
604
+ export type HobEvent =
605
+ | ({ type: "page-live" } & PageLive)
606
+ | { type: "assistant"; assistant: AssistantSummary } // 新建或变化
607
+ | { type: "assistant_removed"; id: string }
608
+ | { type: "item"; assistantId: string; item: Item } // 新条目,或按 id 替换
609
+ | { type: "delta"; assistantId: string; itemId: string; text: string } // 流式追加到 assistant 条目
610
+ | { type: "job"; job: Job }
611
+ | { type: "delegation"; delegation: Delegation }
612
+ | { type: "job_step"; jobId: string; step: JobStep } // 新的一步,或按 id 替换(输出流式更新、跑完补结果)
613
+ | { type: "activity"; jobId: string; line: ActivityLine; stats: Job["stats"] }
614
+ | { type: "approval"; approval: Approval }
615
+ | { type: "draft"; draft: Draft }
616
+ | { type: "routine"; routine: Routine }
617
+ | { type: "routine_removed"; id: string }
618
+ | { type: "profile"; assistantId: string }; // rules/memories/worklog 变了,前端重拉 profile
619
+
620
+ /** POST /api/assistants/:id/messages 的请求体 */
621
+ export interface SendMessageBody {
622
+ text: string;
623
+ quote?: { itemId: string; text: string };
624
+ files?: string[]; // /api/uploads 返回的路径
625
+ }
626
+
627
+ /** POST /api/approvals/:id 的请求体:选一个选项(key),或者用户自己写的一段(text)。 */
628
+ export interface AnswerApprovalBody {
629
+ key?: ApprovalOption["key"];
630
+ text?: string;
631
+ }
@@ -0,0 +1,28 @@
1
+ # Lore Pi Extension
2
+
3
+ This extension connects Pi agent to Lore long-term memory.
4
+
5
+ ## Capabilities
6
+
7
+ - Registers Lore tools with `pi.registerTool`.
8
+ - Adds `client_type=pi` to Lore API requests.
9
+ - Injects Lore boot guidance through `before_agent_start`.
10
+ - Injects per-prompt recall context as a hidden custom message.
11
+ - Tracks session reads for `lore_get_node`.
12
+ - Registers server-side Skill management tools (list/search/create/update/delete/import) without prescribing when the agent should use them; changes sync to the local skills directory at the start of the next session.
13
+ - When Skills are enabled, session start (`resources_discover`) registers Lore's work-copy directory `~/.lore/skills/<project-id>/` (or `LORE_HOME`) as a native Pi skill directory — no separate copy — and reconciles it with the server catalog in a background sync. Skills appear as regular Pi skills: users invoke them with `/skill:name`, and `disable-model-invocation: true` is honored by Pi natively. The previous sync's skills are visible in the current session; newly synced skills become available in the next session or after `/reload`. The last sync outcome is recorded in `~/.lore/skills/<project-id>/.lore-sync-status.json`.
14
+ - Managed package files are read-only (0444 POSIX) while the skill directory itself stays writable (0755), so agents create local outputs/cache directly inside the same copy. Extra local files never trigger tamper and survive syncs and version upgrades.
15
+ - Same-version local outputs are preserved across syncs and upgrades; a version mismatch updates only the server-managed package files.
16
+ - Transport validation covers safe paths, required `SKILL.md`, per-file hashes/sizes, and optional manifest hashes. Unmanaged local directories are never overwritten.
17
+
18
+ ## Local Install
19
+
20
+ ```bash
21
+ ./pi-extension/scripts/install-local.sh
22
+ ```
23
+
24
+ Then run `/reload` inside Pi or restart Pi.
25
+
26
+ Pi discovers extensions from `~/.pi/agent/extensions/*/index.ts`.
27
+
28
+ Skill work copies keep the server-managed package files read-only while the directory stays writable for local outputs; the background sync refreshes managed package files on a version change.