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,33 @@
1
+ /**
2
+ * Host-shared Lore skills sync (see skills-sync.mjs). Reconciles a host-native
3
+ * skills directory with the server catalog and records the outcome in
4
+ * <root>/.lore-sync-status.json. Never throws: failures land in errors.
5
+ */
6
+
7
+ export interface SkillsSyncStatus {
8
+ finished_at: string;
9
+ project_id: string;
10
+ catalog_revision: string;
11
+ created: string[];
12
+ updated: string[];
13
+ unchanged: string[];
14
+ removed: string[];
15
+ conflicts: string[];
16
+ errors: Array<{ name: string; message: string }>;
17
+ }
18
+
19
+ export function runSkillsSync(opts: {
20
+ clientType: string;
21
+ /** Host-native skills directory to reconcile. */
22
+ root?: string;
23
+ /**
24
+ * Resolves the skills directory from the project_id returned by the catalog,
25
+ * for hosts keyed by server project identity (~/.lore/skills/<project_id>).
26
+ * Used when root is omitted.
27
+ */
28
+ rootForProject?: (projectId: string) => string;
29
+ loreHome?: string;
30
+ baseUrl?: string;
31
+ apiToken?: string;
32
+ timeoutMs?: number;
33
+ }): Promise<SkillsSyncStatus>;
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Host-shared Lore skills sync: fetch the server catalog and reconcile a
4
+ * host-native skills directory via syncSkillsToDir, then record the outcome in
5
+ * <root>/.lore-sync-status.json (atomic tmp + rename).
6
+ *
7
+ * This is the single implementation shared by every host:
8
+ * - Hook-based hosts (Claude Code, Codex) spawn it detached as a CLI:
9
+ * node skills-sync.mjs --client-type <type> --root <dir> [--lore-home <dir>]
10
+ * The CLI installer runs the same command for the first sync after install.
11
+ * - In-process hosts (Pi, OpenClaw, dsh) import runSkillsSync directly.
12
+ *
13
+ * Connection resolution matches the other Lore scripts: <loreHome>/config.json
14
+ * (base_url, api_token) with LORE_BASE_URL / LORE_API_TOKEN / API_TOKEN env
15
+ * fallbacks; explicit options win. One AbortSignal.timeout (default 10 min)
16
+ * covers the catalog request and every skill detail request. Network and
17
+ * other failures never throw: they are recorded in status.errors, and the
18
+ * explicit process.exit in the CLI keeps lingering keep-alive sockets from
19
+ * holding a finished run open.
20
+ */
21
+
22
+ import * as fs from 'node:fs';
23
+ import * as path from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+
26
+ import { resolveLoreHome, syncSkillsToDir } from './index.mjs';
27
+
28
+ const DEFAULT_BASE_URL = 'http://127.0.0.1:18901';
29
+ const DEFAULT_TIMEOUT_MS = 600000;
30
+ const STATUS_FILE = '.lore-sync-status.json';
31
+ const OPENAI_YAML_PATH = 'agents/openai.yaml';
32
+ // Codex has no disable-model-invocation frontmatter support; the equivalent is
33
+ // an agents/openai.yaml policy file shipped inside the skill package.
34
+ const OPENAI_POLICY_YAML = 'policy:\n allow_implicit_invocation: false\n';
35
+ // Codex bundles a static lore-memory skill without a Lore marker: an expected
36
+ // conflict, kept out of the recorded conflicts to avoid noisy status files.
37
+ const CODEX_BUNDLED_SKILLS = ['lore-memory'];
38
+
39
+ function pickString(value) {
40
+ return typeof value === 'string' && value.trim() ? value.trim() : '';
41
+ }
42
+
43
+ function loadConnection({ loreHome, baseUrl, apiToken, env = process.env }) {
44
+ let config = {};
45
+ try {
46
+ config = JSON.parse(fs.readFileSync(path.join(loreHome, 'config.json'), 'utf-8'));
47
+ } catch { /* best-effort */ }
48
+ return {
49
+ baseUrl: (pickString(baseUrl)
50
+ || pickString(config.base_url)
51
+ || pickString(env.LORE_BASE_URL)
52
+ || DEFAULT_BASE_URL).replace(/\/+$/, ''),
53
+ apiToken: pickString(apiToken)
54
+ || pickString(config.api_token)
55
+ || pickString(env.LORE_API_TOKEN)
56
+ || pickString(env.API_TOKEN),
57
+ };
58
+ }
59
+
60
+ function adaptCodexSkill(detail) {
61
+ if (!detail || !detail.disable_model_invocation) return detail;
62
+ const files = Array.isArray(detail.files) ? detail.files : [];
63
+ if (files.some((file) => file && file.path === OPENAI_YAML_PATH)) return detail;
64
+ return {
65
+ ...detail,
66
+ files: [...files, { path: OPENAI_YAML_PATH, content: OPENAI_POLICY_YAML }],
67
+ };
68
+ }
69
+
70
+ /** Per-host packaging tweaks applied before a work copy is materialized. */
71
+ function hostAdapter(clientType) {
72
+ if (clientType === 'codex') {
73
+ return {
74
+ adapt: adaptCodexSkill,
75
+ filterConflicts: (conflicts) => conflicts.filter((name) => !CODEX_BUNDLED_SKILLS.includes(name)),
76
+ };
77
+ }
78
+ return {};
79
+ }
80
+
81
+ async function fetchSkillsJson(baseUrl, apiToken, clientType, skillPath, signal) {
82
+ const url = new URL(`/api/skills${skillPath}`, `${baseUrl}/`);
83
+ url.searchParams.set('client_type', clientType);
84
+ const headers = {};
85
+ if (apiToken) headers.authorization = `Bearer ${apiToken}`;
86
+ const response = await fetch(url, { headers, signal });
87
+ if (!response.ok) throw new Error(`skills request failed: ${response.status}`);
88
+ return JSON.parse(await response.text());
89
+ }
90
+
91
+ function writeStatusFile(root, status) {
92
+ fs.mkdirSync(root, { recursive: true });
93
+ const tmp = path.join(root, `${STATUS_FILE}.tmp-${process.pid}`);
94
+ fs.writeFileSync(tmp, `${JSON.stringify(status, null, 2)}\n`, 'utf-8');
95
+ fs.renameSync(tmp, path.join(root, STATUS_FILE));
96
+ }
97
+
98
+ /**
99
+ * Sync the server skill catalog into a host-native skills directory and record
100
+ * the outcome in <root>/.lore-sync-status.json. Never throws: failures land in
101
+ * status.errors. Returns the recorded status object.
102
+ */
103
+ export async function runSkillsSync(opts) {
104
+ const clientType = pickString(opts?.clientType);
105
+ const root = pickString(opts?.root);
106
+ const rootForProject = typeof opts?.rootForProject === 'function' ? opts.rootForProject : null;
107
+ const loreHome = pickString(opts?.loreHome) ? path.resolve(pickString(opts?.loreHome)) : resolveLoreHome();
108
+ const timeoutMs = Number.isFinite(opts?.timeoutMs) ? Number(opts.timeoutMs) : DEFAULT_TIMEOUT_MS;
109
+
110
+ const status = {
111
+ finished_at: '',
112
+ project_id: '',
113
+ catalog_revision: '',
114
+ created: [],
115
+ updated: [],
116
+ unchanged: [],
117
+ removed: [],
118
+ conflicts: [],
119
+ errors: [],
120
+ };
121
+ let syncRoot = root;
122
+ try {
123
+ if (!clientType) throw new Error('runSkillsSync requires clientType');
124
+ if (!root && !rootForProject) throw new Error('runSkillsSync requires root');
125
+ const { baseUrl, apiToken } = loadConnection({
126
+ loreHome,
127
+ baseUrl: opts?.baseUrl,
128
+ apiToken: opts?.apiToken,
129
+ });
130
+ // One deadline covers the whole run: catalog + every skill detail.
131
+ const signal = AbortSignal.timeout(timeoutMs);
132
+ const catalog = await fetchSkillsJson(baseUrl, apiToken, clientType, '', signal);
133
+ status.project_id = pickString(catalog?.project_id);
134
+ if (!syncRoot) {
135
+ // Hosts whose skills root is keyed by the server project identity (Pi,
136
+ // Hermes, dsh: ~/.lore/skills/<project_id>) resolve it after the catalog.
137
+ syncRoot = pickString(rootForProject(status.project_id));
138
+ if (!syncRoot) throw new Error('runSkillsSync requires root');
139
+ }
140
+ status.catalog_revision = catalog?.catalog_revision === undefined || catalog?.catalog_revision === null
141
+ ? ''
142
+ : String(catalog.catalog_revision);
143
+ const { adapt, filterConflicts } = hostAdapter(clientType);
144
+ const result = await syncSkillsToDir({
145
+ root: syncRoot,
146
+ projectId: status.project_id,
147
+ skills: Array.isArray(catalog?.skills) ? catalog.skills : [],
148
+ loadSkill: (skillId) => fetchSkillsJson(baseUrl, apiToken, clientType, `/${encodeURIComponent(skillId)}`, signal),
149
+ adapt,
150
+ });
151
+ status.created = result.created;
152
+ status.updated = result.updated;
153
+ status.unchanged = result.unchanged;
154
+ status.removed = result.removed;
155
+ status.conflicts = filterConflicts ? filterConflicts(result.conflicts) : result.conflicts;
156
+ status.errors = result.errors;
157
+ } catch (error) {
158
+ status.errors.push({ name: '', message: error instanceof Error ? error.message : String(error) });
159
+ }
160
+ status.finished_at = new Date().toISOString();
161
+ if (syncRoot) {
162
+ try {
163
+ writeStatusFile(syncRoot, status);
164
+ } catch { /* silent: background best-effort */ }
165
+ }
166
+ return status;
167
+ }
168
+
169
+ // ---- CLI entry (spawned detached by hooks; run directly by the installer) ----
170
+
171
+ function usage() {
172
+ console.error('usage: skills-sync.mjs --client-type <type> --root <dir> [--lore-home <dir>]');
173
+ }
174
+
175
+ function parseArgs(argv) {
176
+ const out = {};
177
+ const flags = { '--client-type': 'clientType', '--root': 'root', '--lore-home': 'loreHome' };
178
+ for (let i = 0; i < argv.length; i += 2) {
179
+ const key = argv[i];
180
+ const value = argv[i + 1];
181
+ if (!Object.hasOwn(flags, key) || value === undefined) {
182
+ usage();
183
+ process.exit(2);
184
+ }
185
+ out[flags[key]] = value;
186
+ }
187
+ return out;
188
+ }
189
+
190
+ const invokedAsScript = process.argv[1]
191
+ && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
192
+
193
+ if (invokedAsScript) {
194
+ const args = parseArgs(process.argv.slice(2));
195
+ if (!args.clientType || !args.root) {
196
+ usage();
197
+ process.exit(2);
198
+ }
199
+ runSkillsSync(args)
200
+ .catch(() => { /* recorded in the status file when possible */ })
201
+ .finally(() => process.exit(0));
202
+ }