@bryti/agent 0.1.2 → 0.2.1
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/README.md +9 -22
- package/dist/cli.js +84 -334
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -3
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -15
- package/dist/index.js.map +1 -1
- package/dist/memory/embeddings.d.ts +15 -9
- package/dist/memory/embeddings.d.ts.map +1 -1
- package/dist/memory/embeddings.js +37 -13
- package/dist/memory/embeddings.js.map +1 -1
- package/dist/memory/search.d.ts +1 -1
- package/dist/memory/search.d.ts.map +1 -1
- package/dist/memory/search.js +6 -5
- package/dist/memory/search.js.map +1 -1
- package/dist/memory/store.d.ts +3 -2
- package/dist/memory/store.d.ts.map +1 -1
- package/dist/memory/store.js +5 -3
- package/dist/memory/store.js.map +1 -1
- package/dist/model-infra.d.ts.map +1 -1
- package/dist/model-infra.js +1 -0
- package/dist/model-infra.js.map +1 -1
- package/dist/projection/store.d.ts +1 -1
- package/dist/projection/store.d.ts.map +1 -1
- package/dist/projection/store.js +6 -0
- package/dist/projection/store.js.map +1 -1
- package/dist/setup.d.ts +9 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +240 -0
- package/dist/setup.js.map +1 -0
- package/dist/tools/archival-memory-tool.d.ts +1 -1
- package/dist/tools/archival-memory-tool.d.ts.map +1 -1
- package/dist/tools/archival-memory-tool.js.map +1 -1
- package/dist/update-check.d.ts +16 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +94 -0
- package/dist/update-check.js.map +1 -0
- package/package.json +10 -6
- package/run.sh +15 -5
package/README.md
CHANGED
|
@@ -47,18 +47,6 @@ Bryti is a personal AI agent that lives in Telegram and WhatsApp. It remembers w
|
|
|
47
47
|
|
|
48
48
|
### Quick start
|
|
49
49
|
|
|
50
|
-
**From npm:**
|
|
51
|
-
```bash
|
|
52
|
-
npm install -g @bryti/agent
|
|
53
|
-
|
|
54
|
-
# Configure
|
|
55
|
-
cp "$(npm root -g)/@bryti/agent/config.example.yml" data/config.yml
|
|
56
|
-
cp "$(npm root -g)/@bryti/agent/.env.example" .env
|
|
57
|
-
# Edit data/config.yml and .env, then:
|
|
58
|
-
bryti-start
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
**From source:**
|
|
62
50
|
```bash
|
|
63
51
|
git clone git@github.com:larsderidder/bryti.git
|
|
64
52
|
cd bryti
|
|
@@ -69,7 +57,7 @@ cp .env.example .env # add your Telegram bot token
|
|
|
69
57
|
cp config.example.yml data/config.yml # edit to taste
|
|
70
58
|
|
|
71
59
|
# Run
|
|
72
|
-
./run.sh
|
|
60
|
+
bryti # or: npm start, or: ./run.sh (auto-restart on crash)
|
|
73
61
|
```
|
|
74
62
|
|
|
75
63
|
The embedding model downloads on first run (~300 MB). After that, startups take a few seconds.
|
|
@@ -250,17 +238,16 @@ Environment variables are supported via `${VAR}` syntax. The `.env` file loads a
|
|
|
250
238
|
|
|
251
239
|
## CLI
|
|
252
240
|
|
|
253
|
-
Operator tools for managing Bryti without going through chat
|
|
241
|
+
Operator tools for managing Bryti without going through chat. Safe to run while the server is running.
|
|
254
242
|
|
|
255
243
|
```bash
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
npm run cli -- fill-context --turns 20 # inject synthetic conversation for testing
|
|
244
|
+
bryti help # all commands
|
|
245
|
+
bryti memory # inspect all memory tiers
|
|
246
|
+
bryti memory projections --all # all projections (including resolved)
|
|
247
|
+
bryti memory archival --query "energy" # search archival memory
|
|
248
|
+
bryti reflect # run reflection pass now
|
|
249
|
+
bryti archive-fact "dentist confirmed" # insert fact, trigger matching projections
|
|
250
|
+
bryti version # show version
|
|
264
251
|
```
|
|
265
252
|
|
|
266
253
|
## Contributing
|
package/dist/cli.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Load .env
|
|
2
|
+
// Load .env from cwd or data dir (whichever exists)
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
3
4
|
try {
|
|
4
|
-
|
|
5
|
+
if (existsSync(".env")) {
|
|
6
|
+
process.loadEnvFile(".env");
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
// Defer full resolution until after imports, but try common locations
|
|
10
|
+
const xdg = process.env.XDG_CONFIG_HOME || (process.env.HOME + "/.config");
|
|
11
|
+
const dataEnv = process.env.BRYTI_DATA_DIR
|
|
12
|
+
? process.env.BRYTI_DATA_DIR + "/.env"
|
|
13
|
+
: xdg + "/bryti/.env";
|
|
14
|
+
if (existsSync(dataEnv)) {
|
|
15
|
+
process.loadEnvFile(dataEnv);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
5
18
|
}
|
|
6
19
|
catch { /* not present, fine */ }
|
|
7
20
|
/**
|
|
8
|
-
* Bryti
|
|
9
|
-
* Run via: bryti <command> [options]
|
|
21
|
+
* Bryti CLI. Starts the server or runs management commands.
|
|
10
22
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
23
|
+
* `bryti` (no args) or `bryti serve` starts the server.
|
|
24
|
+
* `bryti <command>` runs a management command. Management commands bypass
|
|
25
|
+
* the running application and read/write SQLite directly (safe to run
|
|
26
|
+
* while the server is running, thanks to WAL mode).
|
|
14
27
|
*
|
|
15
|
-
* See `
|
|
28
|
+
* See `bryti help` for full command listing.
|
|
16
29
|
*/
|
|
17
30
|
import fs from "node:fs";
|
|
18
31
|
import path from "node:path";
|
|
19
|
-
import crypto from "node:crypto";
|
|
20
32
|
import Database from "better-sqlite3";
|
|
21
|
-
import { loadConfig } from "./config.js";
|
|
33
|
+
import { loadConfig, resolveDataDir as defaultDataDir } from "./config.js";
|
|
22
34
|
import { runReflection } from "./projection/index.js";
|
|
23
35
|
// ---------------------------------------------------------------------------
|
|
36
|
+
// Version
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
const VERSION = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")).version;
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
24
40
|
// Arg parsing helpers
|
|
25
41
|
// ---------------------------------------------------------------------------
|
|
26
42
|
const argv = process.argv.slice(2);
|
|
@@ -32,7 +48,6 @@ function opt(name, fallback) {
|
|
|
32
48
|
return idx !== -1 ? argv[idx + 1] : fallback;
|
|
33
49
|
}
|
|
34
50
|
function positional(afterFlags) {
|
|
35
|
-
// Return the Nth non-flag argument
|
|
36
51
|
const nonFlags = argv.filter((a) => !a.startsWith("--"));
|
|
37
52
|
return nonFlags[afterFlags];
|
|
38
53
|
}
|
|
@@ -40,22 +55,21 @@ function positional(afterFlags) {
|
|
|
40
55
|
// Config / environment
|
|
41
56
|
// ---------------------------------------------------------------------------
|
|
42
57
|
function resolveDataDir() {
|
|
43
|
-
return opt("--data-dir") ??
|
|
58
|
+
return opt("--data-dir") ?? defaultDataDir();
|
|
44
59
|
}
|
|
45
|
-
function resolveUserId(
|
|
60
|
+
function resolveUserId(_dataDir) {
|
|
46
61
|
if (opt("--user-id"))
|
|
47
62
|
return opt("--user-id");
|
|
48
63
|
if (process.env.BRYTI_USER_ID)
|
|
49
64
|
return process.env.BRYTI_USER_ID;
|
|
50
|
-
// Try to read from config
|
|
51
65
|
try {
|
|
52
|
-
const config = loadConfig(
|
|
66
|
+
const config = loadConfig();
|
|
53
67
|
const first = config.telegram.allowed_users[0];
|
|
54
68
|
if (first)
|
|
55
69
|
return String(first);
|
|
56
70
|
}
|
|
57
71
|
catch {
|
|
58
|
-
// Config may not exist
|
|
72
|
+
// Config may not exist yet
|
|
59
73
|
}
|
|
60
74
|
return "default-user";
|
|
61
75
|
}
|
|
@@ -184,7 +198,6 @@ async function cmdReflect(dataDir, userId, windowMinutes) {
|
|
|
184
198
|
console.error(`Failed to load config: ${err.message}`);
|
|
185
199
|
process.exit(1);
|
|
186
200
|
}
|
|
187
|
-
// Override data_dir in case --data-dir was passed
|
|
188
201
|
config.data_dir = dataDir;
|
|
189
202
|
const result = await runReflection(config, userId, windowMinutes);
|
|
190
203
|
if (result.skipped) {
|
|
@@ -201,264 +214,11 @@ async function cmdReflect(dataDir, userId, windowMinutes) {
|
|
|
201
214
|
}
|
|
202
215
|
}
|
|
203
216
|
// ---------------------------------------------------------------------------
|
|
204
|
-
// Command: timeskip
|
|
205
|
-
// ---------------------------------------------------------------------------
|
|
206
|
-
function cmdTimeskipList(dataDir, userId) {
|
|
207
|
-
const dbPath = path.join(dataDir, "users", userId, "memory.db");
|
|
208
|
-
if (!fs.existsSync(dbPath)) {
|
|
209
|
-
console.error(`No memory.db found at ${dbPath}`);
|
|
210
|
-
process.exit(1);
|
|
211
|
-
}
|
|
212
|
-
const db = new Database(dbPath, { readonly: true });
|
|
213
|
-
const rows = db.prepare(`SELECT id, summary, resolved_when, resolution, status
|
|
214
|
-
FROM projections ORDER BY
|
|
215
|
-
CASE status WHEN 'pending' THEN 0 ELSE 1 END,
|
|
216
|
-
resolved_when ASC`).all();
|
|
217
|
-
db.close();
|
|
218
|
-
if (rows.length === 0) {
|
|
219
|
-
console.log("No projections found.");
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const statusIcon = { pending: "⏳", done: "✅", cancelled: "❌", passed: "🔕" };
|
|
223
|
-
console.log("Projections:\n");
|
|
224
|
-
for (const row of rows) {
|
|
225
|
-
const icon = statusIcon[row.status] ?? "?";
|
|
226
|
-
console.log(`${icon} [${row.resolution}] ${row.summary}`);
|
|
227
|
-
console.log(` id: ${row.id}`);
|
|
228
|
-
console.log(` when: ${row.resolved_when ?? "(someday)"}`);
|
|
229
|
-
console.log("");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
function cmdTimeskip(dataDir, userId, summaryOrId, minutes) {
|
|
233
|
-
const dbPath = path.join(dataDir, "users", userId, "memory.db");
|
|
234
|
-
if (!fs.existsSync(dbPath)) {
|
|
235
|
-
console.error(`No memory.db found at ${dbPath}`);
|
|
236
|
-
process.exit(1);
|
|
237
|
-
}
|
|
238
|
-
const db = new Database(dbPath);
|
|
239
|
-
// Users may reference projections by summary substring (human-friendly) or
|
|
240
|
-
// by full UUID (copy-pasted from 'timeskip --list'). The regex distinguishes
|
|
241
|
-
// them: UUIDs match the standard 8-4-4-4-12 hex pattern, everything else is
|
|
242
|
-
// treated as a summary substring.
|
|
243
|
-
const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(summaryOrId);
|
|
244
|
-
const row = isUuid
|
|
245
|
-
? db.prepare("SELECT * FROM projections WHERE id = ?").get(summaryOrId)
|
|
246
|
-
: db.prepare("SELECT * FROM projections WHERE summary LIKE ? AND status = 'pending' LIMIT 1")
|
|
247
|
-
.get(`%${summaryOrId}%`);
|
|
248
|
-
if (!row) {
|
|
249
|
-
console.error(`No pending projection found matching: ${summaryOrId}`);
|
|
250
|
-
db.close();
|
|
251
|
-
process.exit(1);
|
|
252
|
-
}
|
|
253
|
-
const newTime = new Date(Date.now() + minutes * 60 * 1000);
|
|
254
|
-
const newTimeStr = newTime.toISOString().slice(0, 16).replace("T", " ");
|
|
255
|
-
db.prepare("UPDATE projections SET resolved_when = ?, resolution = 'exact' WHERE id = ?").run(newTimeStr, row.id);
|
|
256
|
-
db.close();
|
|
257
|
-
console.log(`Timeskipped projection:`);
|
|
258
|
-
console.log(` Summary: ${row.summary}`);
|
|
259
|
-
console.log(` Old when: ${row.resolved_when ?? "(none)"}`);
|
|
260
|
-
console.log(` New when: ${newTimeStr} UTC (fires in ~${minutes} min)`);
|
|
261
|
-
console.log(`\nThe scheduler will pick it up on the next 5-minute tick.`);
|
|
262
|
-
}
|
|
263
|
-
// ---------------------------------------------------------------------------
|
|
264
|
-
// Command: import-openclaw
|
|
265
|
-
// ---------------------------------------------------------------------------
|
|
266
|
-
// One-time migration tool for importing Lars's OpenClaw memory files into
|
|
267
|
-
// bryti's archival memory. Specific to Lars's local setup (/home/lars/clawd).
|
|
268
|
-
// Not a general-purpose import command.
|
|
269
|
-
function cmdImportOpenclaw(dataDir, userId, dryRun) {
|
|
270
|
-
const clawdDir = "/home/lars/clawd";
|
|
271
|
-
console.log(`Importing OpenClaw memory into bryti`);
|
|
272
|
-
console.log(` User ID: ${userId}`);
|
|
273
|
-
console.log(` Data dir: ${dataDir}`);
|
|
274
|
-
console.log(` Dry run: ${dryRun}`);
|
|
275
|
-
console.log("");
|
|
276
|
-
// Core memory
|
|
277
|
-
const userMd = path.join(clawdDir, "USER.md");
|
|
278
|
-
if (!fs.existsSync(userMd)) {
|
|
279
|
-
console.log("[core] USER.md not found, skipping");
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
const corePath = path.join(dataDir, "core-memory.md");
|
|
283
|
-
const existing = fs.existsSync(corePath) ? fs.readFileSync(corePath, "utf-8") : "";
|
|
284
|
-
if (existing.includes("## About Lars")) {
|
|
285
|
-
console.log("[core] Already contains Lars profile, skipping");
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
const userContent = fs.readFileSync(userMd, "utf-8");
|
|
289
|
-
const sectionText = "\n\n## About Lars\n" + userContent.replace(/^# USER\.md.*\n/, "").trim();
|
|
290
|
-
if (dryRun) {
|
|
291
|
-
console.log("[core] DRY RUN — would append to core-memory.md:");
|
|
292
|
-
console.log(sectionText.slice(0, 300) + "...");
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
fs.appendFileSync(corePath, sectionText, "utf-8");
|
|
296
|
-
console.log(`[core] Appended USER.md to core-memory.md (${sectionText.length} chars)`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
// Archival memory
|
|
301
|
-
const memoryDir = path.join(clawdDir, "memory");
|
|
302
|
-
if (!fs.existsSync(memoryDir)) {
|
|
303
|
-
console.log("[archival] memory/ directory not found, skipping");
|
|
304
|
-
console.log("\nDone.");
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
const files = fs.readdirSync(memoryDir).filter((f) => f.endsWith(".md")).sort();
|
|
308
|
-
console.log(`[archival] Found ${files.length} memory files`);
|
|
309
|
-
if (dryRun) {
|
|
310
|
-
for (const file of files) {
|
|
311
|
-
const content = fs.readFileSync(path.join(memoryDir, file), "utf-8");
|
|
312
|
-
const sections = splitIntoSections(content, file);
|
|
313
|
-
console.log(`[archival] DRY RUN — ${file}: ${sections.length} section(s)`);
|
|
314
|
-
}
|
|
315
|
-
console.log("\nDone (dry run).");
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
const userDir = path.join(dataDir, "users", userId);
|
|
319
|
-
fs.mkdirSync(userDir, { recursive: true });
|
|
320
|
-
const db = new Database(path.join(userDir, "memory.db"));
|
|
321
|
-
db.pragma("journal_mode = WAL");
|
|
322
|
-
db.exec(`
|
|
323
|
-
CREATE TABLE IF NOT EXISTS facts (
|
|
324
|
-
id TEXT PRIMARY KEY, content TEXT NOT NULL, source TEXT NOT NULL,
|
|
325
|
-
timestamp INTEGER NOT NULL, hash TEXT NOT NULL
|
|
326
|
-
);
|
|
327
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS facts_fts USING fts5(content, content='facts', content_rowid='rowid');
|
|
328
|
-
CREATE TRIGGER IF NOT EXISTS facts_ai AFTER INSERT ON facts BEGIN
|
|
329
|
-
INSERT INTO facts_fts(rowid, content) VALUES (NEW.rowid, NEW.content);
|
|
330
|
-
END;
|
|
331
|
-
`);
|
|
332
|
-
const insertStmt = db.prepare("INSERT OR IGNORE INTO facts (id, content, source, timestamp, hash) VALUES (?, ?, ?, ?, ?)");
|
|
333
|
-
const existsStmt = db.prepare("SELECT hash FROM facts WHERE hash = ?");
|
|
334
|
-
let inserted = 0;
|
|
335
|
-
let skipped = 0;
|
|
336
|
-
for (const file of files) {
|
|
337
|
-
const filePath = path.join(memoryDir, file);
|
|
338
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
339
|
-
const sections = splitIntoSections(content, file);
|
|
340
|
-
const timestamp = fs.statSync(filePath).mtimeMs;
|
|
341
|
-
for (const sec of sections) {
|
|
342
|
-
const hash = crypto.createHash("sha256").update(sec).digest("hex").slice(0, 16);
|
|
343
|
-
if (existsStmt.get(hash)) {
|
|
344
|
-
skipped++;
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
insertStmt.run(crypto.randomUUID(), sec, `openclaw:memory/${file}`, timestamp, hash);
|
|
348
|
-
inserted++;
|
|
349
|
-
}
|
|
350
|
-
console.log(`[archival] ${file}: ${sections.length} section(s)`);
|
|
351
|
-
}
|
|
352
|
-
db.close();
|
|
353
|
-
console.log(`[archival] Done: ${inserted} inserted, ${skipped} skipped`);
|
|
354
|
-
console.log("\nDone. Restart bryti for core memory changes to take effect.");
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Split a markdown document into granular facts by ## headings.
|
|
358
|
-
*
|
|
359
|
-
* Each ## section is stored as a separate archival fact so that semantic
|
|
360
|
-
* search can retrieve the relevant section rather than returning the entire
|
|
361
|
-
* document. The date prefix (derived from the filename) is prepended to each
|
|
362
|
-
* section so temporal context is preserved after the split.
|
|
363
|
-
*/
|
|
364
|
-
function splitIntoSections(content, filename) {
|
|
365
|
-
const date = path.basename(filename, ".md");
|
|
366
|
-
const parts = content.split(/^## /m);
|
|
367
|
-
const sections = [];
|
|
368
|
-
for (const part of parts) {
|
|
369
|
-
const trimmed = part.trim();
|
|
370
|
-
if (!trimmed || trimmed.length < 50)
|
|
371
|
-
continue;
|
|
372
|
-
sections.push(`[${date}] ## ${trimmed}`);
|
|
373
|
-
}
|
|
374
|
-
if (sections.length === 0 && content.trim().length > 50) {
|
|
375
|
-
sections.push(`[${date}] ${content.trim()}`);
|
|
376
|
-
}
|
|
377
|
-
return sections;
|
|
378
|
-
}
|
|
379
|
-
// ---------------------------------------------------------------------------
|
|
380
|
-
// Command: fill-context
|
|
381
|
-
// ---------------------------------------------------------------------------
|
|
382
|
-
const DEFAULT_DATASET = path.join("/home/lars/xithing/contextpatterns-content/synthetic-agent-conversations", "dataset/memory-context.jsonl");
|
|
383
|
-
/**
|
|
384
|
-
* Inject synthetic conversations into history for compaction testing.
|
|
385
|
-
* Back-dates entries so they look like real history. Prioritises
|
|
386
|
-
* context-window-pressure subcategory conversations.
|
|
387
|
-
*
|
|
388
|
-
* This is a testing/development tool only. It writes synthetic entries with
|
|
389
|
-
* _synthetic: true markers but those entries are otherwise indistinguishable
|
|
390
|
-
* from real history as far as the compaction and reflection passes are
|
|
391
|
-
* concerned. Do not run in production.
|
|
392
|
-
*/
|
|
393
|
-
function cmdFillContext(dataDir, count, datasetPath, dryRun) {
|
|
394
|
-
if (!fs.existsSync(datasetPath)) {
|
|
395
|
-
console.error(`Dataset not found: ${datasetPath}`);
|
|
396
|
-
process.exit(1);
|
|
397
|
-
}
|
|
398
|
-
const lines = fs.readFileSync(datasetPath, "utf-8").split("\n").filter(Boolean);
|
|
399
|
-
const all = lines.map((l) => JSON.parse(l));
|
|
400
|
-
// Prefer context-window-pressure, then fall back to all
|
|
401
|
-
const pressure = all.filter((c) => c.subcategory === "context-window-pressure");
|
|
402
|
-
const pool = pressure.length >= count ? pressure : all;
|
|
403
|
-
const selected = pool.slice(0, count);
|
|
404
|
-
// Count total turns we'll inject
|
|
405
|
-
const totalTurns = selected.reduce((n, c) => n + c.turns.filter((t) => t.role === "user" || t.role === "assistant").length, 0);
|
|
406
|
-
console.log(`Injecting ${selected.length} conversation(s), ${totalTurns} turns total`);
|
|
407
|
-
if (dryRun)
|
|
408
|
-
console.log("(dry run — nothing will be written)\n");
|
|
409
|
-
// Back-date entries starting from 2 hours ago, spreading turns across time
|
|
410
|
-
const now = Date.now();
|
|
411
|
-
const startMs = now - 2 * 60 * 60 * 1000;
|
|
412
|
-
const stepMs = Math.floor((2 * 60 * 60 * 1000) / Math.max(totalTurns, 1));
|
|
413
|
-
const historyDir = path.join(dataDir, "history");
|
|
414
|
-
if (!dryRun)
|
|
415
|
-
fs.mkdirSync(historyDir, { recursive: true });
|
|
416
|
-
let turnIdx = 0;
|
|
417
|
-
const byDay = new Map();
|
|
418
|
-
for (const conv of selected) {
|
|
419
|
-
console.log(` [${conv.id}] ${conv.description}`);
|
|
420
|
-
for (const turn of conv.turns) {
|
|
421
|
-
if (turn.role !== "user" && turn.role !== "assistant")
|
|
422
|
-
continue;
|
|
423
|
-
const ts = new Date(startMs + turnIdx * stepMs);
|
|
424
|
-
const day = ts.toISOString().slice(0, 10);
|
|
425
|
-
const entry = JSON.stringify({
|
|
426
|
-
role: turn.role,
|
|
427
|
-
content: turn.content,
|
|
428
|
-
timestamp: ts.toISOString(),
|
|
429
|
-
_synthetic: true,
|
|
430
|
-
});
|
|
431
|
-
if (!byDay.has(day))
|
|
432
|
-
byDay.set(day, []);
|
|
433
|
-
byDay.get(day).push(entry);
|
|
434
|
-
turnIdx++;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
if (!dryRun) {
|
|
438
|
-
for (const [day, entries] of byDay) {
|
|
439
|
-
const filePath = path.join(historyDir, `${day}.jsonl`);
|
|
440
|
-
fs.appendFileSync(filePath, entries.join("\n") + "\n", "utf-8");
|
|
441
|
-
console.log(` Written ${entries.length} entries to history/${day}.jsonl`);
|
|
442
|
-
}
|
|
443
|
-
console.log(`\nDone. Restart bryti to pick up the new history in context.`);
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
for (const [day, entries] of byDay) {
|
|
447
|
-
console.log(` Would write ${entries.length} entries to history/${day}.jsonl`);
|
|
448
|
-
}
|
|
449
|
-
console.log("\nDone (dry run).");
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
// ---------------------------------------------------------------------------
|
|
453
217
|
// Command: archive-fact
|
|
454
218
|
// ---------------------------------------------------------------------------
|
|
455
219
|
async function cmdArchiveFact(dataDir, userId, content) {
|
|
456
220
|
console.log(`Archiving fact for user ${userId}...`);
|
|
457
221
|
console.log(`Content: "${content}"\n`);
|
|
458
|
-
// Lazy-import the embedding model and memory store. The embedding model is
|
|
459
|
-
// 300MB+ and takes several seconds to load. Importing at the top of the file
|
|
460
|
-
// would add that startup cost to every CLI command, including fast read-only
|
|
461
|
-
// ones like 'memory' and 'reflect'. Deferring to here keeps the CLI snappy.
|
|
462
222
|
const { embed } = await import("./memory/embeddings.js");
|
|
463
223
|
const { createMemoryStore } = await import("./memory/store.js");
|
|
464
224
|
const { createProjectionStore } = await import("./projection/index.js");
|
|
@@ -466,11 +226,9 @@ async function cmdArchiveFact(dataDir, userId, content) {
|
|
|
466
226
|
const memoryStore = createMemoryStore(userId, dataDir);
|
|
467
227
|
const projStore = createProjectionStore(userId, dataDir);
|
|
468
228
|
try {
|
|
469
|
-
// Embed and store the fact.
|
|
470
229
|
const embedding = await embed(content, modelsDir);
|
|
471
230
|
memoryStore.addFact(content, "cli", embedding);
|
|
472
231
|
console.log("Fact archived.");
|
|
473
|
-
// Check triggers (keyword + embedding fallback).
|
|
474
232
|
const triggered = await projStore.checkTriggers(content, (text) => embed(text, modelsDir));
|
|
475
233
|
if (triggered.length > 0) {
|
|
476
234
|
console.log(`\nTriggered ${triggered.length} projection(s):`);
|
|
@@ -493,72 +251,88 @@ async function cmdArchiveFact(dataDir, userId, content) {
|
|
|
493
251
|
// Help
|
|
494
252
|
// ---------------------------------------------------------------------------
|
|
495
253
|
function showHelp() {
|
|
254
|
+
const dataDir = resolveDataDir();
|
|
496
255
|
console.log(`
|
|
497
|
-
bryti
|
|
256
|
+
bryti ${VERSION} — AI colleague in your messaging apps
|
|
498
257
|
|
|
499
258
|
Usage:
|
|
500
|
-
|
|
259
|
+
bryti Start the server (Telegram/WhatsApp bridges, scheduler)
|
|
260
|
+
bryti serve Same as above (explicit)
|
|
261
|
+
bryti <command> Run a management command (safe while server is running)
|
|
501
262
|
|
|
502
263
|
Commands:
|
|
503
|
-
|
|
504
|
-
|
|
264
|
+
hail [<path>]
|
|
265
|
+
First-run setup. Walks you through creating a config.
|
|
266
|
+
Alias: init
|
|
505
267
|
|
|
506
|
-
|
|
507
|
-
|
|
268
|
+
serve
|
|
269
|
+
Start the bryti server.
|
|
508
270
|
|
|
509
|
-
memory core
|
|
510
|
-
|
|
271
|
+
memory [core|projections|archival|all]
|
|
272
|
+
Inspect memory tiers. No subcommand shows all tiers.
|
|
511
273
|
|
|
512
274
|
memory projections [--all]
|
|
513
|
-
Show pending projections.
|
|
275
|
+
Show pending projections. --all includes resolved ones.
|
|
514
276
|
|
|
515
277
|
memory archival [--query <text>] [--limit <n>]
|
|
516
|
-
Show recent archival facts, or search by keyword.
|
|
517
|
-
Default limit: 20.
|
|
278
|
+
Show recent archival facts, or search by keyword. Default limit: 20.
|
|
518
279
|
|
|
519
280
|
reflect [--window <minutes>]
|
|
520
|
-
Run the reflection pass on demand.
|
|
521
|
-
for future references the agent may have missed.
|
|
522
|
-
Default window: 30 minutes.
|
|
523
|
-
|
|
524
|
-
timeskip <summary|id> [--minutes <n>]
|
|
525
|
-
Move a projection's resolved_when to now + N minutes so the
|
|
526
|
-
exact-time scheduler fires it on the next 5-minute tick.
|
|
527
|
-
Matches by summary substring or exact UUID.
|
|
528
|
-
Default: 2 minutes.
|
|
281
|
+
Run the reflection pass on demand. Default window: 30 minutes.
|
|
529
282
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
import-openclaw [--dry-run]
|
|
534
|
-
Import /home/lars/clawd/USER.md into core memory and
|
|
535
|
-
/home/lars/clawd/memory/*.md into archival memory.
|
|
283
|
+
archive-fact "<content>"
|
|
284
|
+
Insert a fact into archival memory and check trigger-based projections.
|
|
536
285
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
Used to test compaction and archival memory retrieval under context pressure.
|
|
540
|
-
Prioritises context-window-pressure conversations from the dataset.
|
|
541
|
-
Default count: 10. Default dataset: synthetic-agent-conversations/dataset/memory-context.jsonl
|
|
286
|
+
version
|
|
287
|
+
Show version number.
|
|
542
288
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
projections fire. Uses keyword matching + embedding similarity fallback.
|
|
546
|
-
Useful for testing trigger_on_fact without going through the agent.
|
|
289
|
+
help
|
|
290
|
+
Show this help text.
|
|
547
291
|
|
|
548
292
|
Global options:
|
|
549
293
|
--user-id <id> User ID (default: first entry in telegram.allowed_users)
|
|
550
|
-
--data-dir <path> Data directory (default:
|
|
294
|
+
--data-dir <path> Data directory (default: ${dataDir})
|
|
551
295
|
`);
|
|
552
296
|
}
|
|
553
297
|
// ---------------------------------------------------------------------------
|
|
554
298
|
// Main dispatcher
|
|
555
299
|
// ---------------------------------------------------------------------------
|
|
556
300
|
async function main() {
|
|
301
|
+
// Flags that work without a command
|
|
302
|
+
if (flag("--version") || flag("-v")) {
|
|
303
|
+
console.log(VERSION);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (flag("--help") || flag("-h")) {
|
|
307
|
+
showHelp();
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
557
310
|
const command = positional(0);
|
|
558
|
-
|
|
311
|
+
// No args or "serve": start the server (or suggest hail if no config)
|
|
312
|
+
if (!command || command === "serve") {
|
|
313
|
+
const configPath = path.join(resolveDataDir(), "config.yml");
|
|
314
|
+
if (!fs.existsSync(configPath)) {
|
|
315
|
+
console.log(`\n No config found at ${configPath}`);
|
|
316
|
+
console.log(` Run 'bryti hail' to set up your steward.\n`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const { startServer } = await import("./index.js");
|
|
320
|
+
await startServer();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (command === "version") {
|
|
324
|
+
console.log(VERSION);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (command === "help") {
|
|
559
328
|
showHelp();
|
|
560
329
|
return;
|
|
561
330
|
}
|
|
331
|
+
if (command === "hail" || command === "init") {
|
|
332
|
+
const { runSetup } = await import("./setup.js");
|
|
333
|
+
await runSetup(positional(1));
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
562
336
|
const dataDir = resolveDataDir();
|
|
563
337
|
const userId = resolveUserId(dataDir);
|
|
564
338
|
switch (command) {
|
|
@@ -593,30 +367,6 @@ async function main() {
|
|
|
593
367
|
await cmdReflect(dataDir, userId, window);
|
|
594
368
|
break;
|
|
595
369
|
}
|
|
596
|
-
case "timeskip": {
|
|
597
|
-
if (flag("--list")) {
|
|
598
|
-
cmdTimeskipList(dataDir, userId);
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
const summaryOrId = positional(1);
|
|
602
|
-
if (!summaryOrId) {
|
|
603
|
-
console.error("Usage: timeskip <summary|id> [--minutes <n>] | timeskip --list");
|
|
604
|
-
process.exit(1);
|
|
605
|
-
}
|
|
606
|
-
const minutes = Number(opt("--minutes", "2"));
|
|
607
|
-
cmdTimeskip(dataDir, userId, summaryOrId, minutes);
|
|
608
|
-
break;
|
|
609
|
-
}
|
|
610
|
-
case "import-openclaw": {
|
|
611
|
-
cmdImportOpenclaw(dataDir, userId, flag("--dry-run"));
|
|
612
|
-
break;
|
|
613
|
-
}
|
|
614
|
-
case "fill-context": {
|
|
615
|
-
const count = Number(opt("--count", "10"));
|
|
616
|
-
const dataset = opt("--dataset", DEFAULT_DATASET);
|
|
617
|
-
cmdFillContext(dataDir, count, dataset, flag("--dry-run"));
|
|
618
|
-
break;
|
|
619
|
-
}
|
|
620
370
|
case "archive-fact": {
|
|
621
371
|
const content = positional(1);
|
|
622
372
|
if (!content) {
|
|
@@ -628,7 +378,7 @@ async function main() {
|
|
|
628
378
|
}
|
|
629
379
|
default:
|
|
630
380
|
console.error(`Unknown command: ${command}`);
|
|
631
|
-
console.error("Run '
|
|
381
|
+
console.error("Run 'bryti help' for usage.");
|
|
632
382
|
process.exit(1);
|
|
633
383
|
}
|
|
634
384
|
console.log("");
|