@mindfoldhq/trellis 0.6.0-beta.3 → 0.6.0-beta.5
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/dist/commands/mem.d.ts +2 -2
- package/dist/commands/mem.d.ts.map +1 -1
- package/dist/commands/mem.js +28 -258
- package/dist/commands/mem.js.map +1 -1
- package/dist/migrations/manifests/0.5.10.json +9 -0
- package/dist/migrations/manifests/0.6.0-beta.4.json +9 -0
- package/dist/migrations/manifests/0.6.0-beta.5.json +9 -0
- package/dist/templates/common/commands/start.md +2 -0
- package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +39 -0
- package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +289 -43
- package/dist/templates/pi/extensions/trellis/index.ts.txt +179 -4
- package/dist/templates/pi/settings.json +9 -0
- package/dist/templates/trellis/index.d.ts +1 -0
- package/dist/templates/trellis/index.d.ts.map +1 -1
- package/dist/templates/trellis/index.js +2 -0
- package/dist/templates/trellis/index.js.map +1 -1
- package/dist/templates/trellis/scripts/add_session.py +44 -24
- package/dist/templates/trellis/scripts/common/safe_commit.py +229 -0
- package/dist/templates/trellis/scripts/common/session_context.py +170 -0
- package/dist/templates/trellis/scripts/common/task_store.py +34 -5
- package/dist/utils/uninstall-scrubbers.d.ts +1 -0
- package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
- package/dist/utils/uninstall-scrubbers.js +21 -0
- package/dist/utils/uninstall-scrubbers.js.map +1 -1
- package/package.json +1 -3
package/dist/commands/mem.d.ts
CHANGED
|
@@ -225,8 +225,8 @@ export declare function collectCodexTurnsAndEvents(s: SessionInfo): {
|
|
|
225
225
|
turns: DialogueTurn[];
|
|
226
226
|
events: TaskPyEvent[];
|
|
227
227
|
};
|
|
228
|
-
export declare function opencodeListSessions(
|
|
229
|
-
export declare function opencodeExtractDialogue(
|
|
228
|
+
export declare function opencodeListSessions(_f: Filter): SessionInfo[];
|
|
229
|
+
export declare function opencodeExtractDialogue(_s: SessionInfo): DialogueTurn[];
|
|
230
230
|
export declare function shortDate(iso?: string): string;
|
|
231
231
|
export declare function shortPath(p?: string): string;
|
|
232
232
|
export declare function runMem(args: readonly string[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mem.d.ts","sourceRoot":"","sources":["../../src/commands/mem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"mem.d.ts","sourceRoot":"","sources":["../../src/commands/mem.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;iBASrB,CAAC;AACH,KAAK,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAErD,QAAA,MAAM,kBAAkB;;;EAAgC,CAAC;AACzD,KAAK,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEvD,UAAU,YAAY;IACpB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAMD,QAAA,MAAM,eAAe;;;;;;;;;;;;iBAMnB,CAAC;AACH,KAAK,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEjD;;;;;2BAK2B;AAC3B,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAGnD;AAED,QAAA,MAAM,YAAY;;;;;;;;;;iBAMhB,CAAC;AACH,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAE3C,QAAA,MAAM,UAAU;;;;iBAId,CAAC;AACH,KAAK,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAmFvC,wBAAgB,SAAS,CAAC,IAAI,EAAE,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,CAyC1D;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,WAAW,GAAG,YAAY,EAAE,CAuDnE;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAEjE;AAED;;;;;;0CAM0C;AAC1C,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,WAAW,GAAG;IAC1D,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAkGA;AA2BD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,EAAE,CAG9D;AAED,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,WAAW,GAAG,YAAY,EAAE,CAGvE;AAgGD,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED,wBAAgB,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5C;AAmjBD,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAwBpD"}
|
package/dist/commands/mem.js
CHANGED
|
@@ -13,13 +13,7 @@
|
|
|
13
13
|
import * as fs from "node:fs";
|
|
14
14
|
import * as path from "node:path";
|
|
15
15
|
import * as os from "node:os";
|
|
16
|
-
import { createRequire } from "node:module";
|
|
17
16
|
import { z } from "zod";
|
|
18
|
-
// ESM bundle (`"type": "module"` + `module: NodeNext`) needs an explicit
|
|
19
|
-
// `require()` for the optional native `better-sqlite3` load (see
|
|
20
|
-
// loadBetterSqlite3 below). `import.meta.url` resolves to this module's URL,
|
|
21
|
-
// which lets createRequire resolve siblings the same way a CJS file would.
|
|
22
|
-
const ocRequire = createRequire(import.meta.url);
|
|
23
17
|
// ---------- schemas: domain types ----------
|
|
24
18
|
const PlatformSchema = z.enum(["claude", "codex", "opencode"]);
|
|
25
19
|
const SessionInfoSchema = z.object({
|
|
@@ -135,41 +129,6 @@ const CodexEventSchema = z
|
|
|
135
129
|
payload: CodexPayloadSchema.optional(),
|
|
136
130
|
})
|
|
137
131
|
.loose();
|
|
138
|
-
// OpenCode SQLite-row schemas (1.2+).
|
|
139
|
-
// OpenCode 1.2 migrated from JSON tree under ~/.local/share/opencode/storage/
|
|
140
|
-
// to a single SQLite database at ~/.local/share/opencode/opencode.db. Schema
|
|
141
|
-
// (drizzle, observed on opencode 1.14.30):
|
|
142
|
-
//
|
|
143
|
-
// CREATE TABLE session (
|
|
144
|
-
// id text PRIMARY KEY, project_id text NOT NULL, parent_id text,
|
|
145
|
-
// slug text NOT NULL, directory text NOT NULL, title text NOT NULL,
|
|
146
|
-
// version text NOT NULL, share_url text, summary_* ..., revert text,
|
|
147
|
-
// permission text, time_created integer NOT NULL, time_updated integer NOT NULL,
|
|
148
|
-
// time_compacting integer, time_archived integer, workspace_id text, path text
|
|
149
|
-
// );
|
|
150
|
-
// CREATE TABLE message (
|
|
151
|
-
// id text PRIMARY KEY, session_id text NOT NULL,
|
|
152
|
-
// time_created integer NOT NULL, time_updated integer NOT NULL,
|
|
153
|
-
// data text NOT NULL -- JSON: { role, time: { created }, agent, ... }
|
|
154
|
-
// );
|
|
155
|
-
// CREATE TABLE part (
|
|
156
|
-
// id text PRIMARY KEY, message_id text NOT NULL, session_id text NOT NULL,
|
|
157
|
-
// time_created integer NOT NULL, time_updated integer NOT NULL,
|
|
158
|
-
// data text NOT NULL -- JSON: { type: text|tool|reasoning|step-*|patch, text, ... }
|
|
159
|
-
// );
|
|
160
|
-
const OpenCodeMessageDataSchema = z
|
|
161
|
-
.object({
|
|
162
|
-
role: z.string().optional(),
|
|
163
|
-
time: z.object({ created: z.number().optional() }).loose().optional(),
|
|
164
|
-
})
|
|
165
|
-
.loose();
|
|
166
|
-
const OpenCodePartDataSchema = z
|
|
167
|
-
.object({
|
|
168
|
-
type: z.string().optional(),
|
|
169
|
-
text: z.string().optional(),
|
|
170
|
-
synthetic: z.boolean().optional(),
|
|
171
|
-
})
|
|
172
|
-
.loose();
|
|
173
132
|
// ---------- argv ----------
|
|
174
133
|
export function parseArgv(argv) {
|
|
175
134
|
const cmd = argv[0] ?? "list";
|
|
@@ -1296,228 +1255,39 @@ export function collectCodexTurnsAndEvents(s) {
|
|
|
1296
1255
|
});
|
|
1297
1256
|
return { turns, events };
|
|
1298
1257
|
}
|
|
1299
|
-
// ---------- opencode adapter (
|
|
1258
|
+
// ---------- opencode adapter (temporarily unavailable) ----------
|
|
1300
1259
|
//
|
|
1301
|
-
// OpenCode 1.2+
|
|
1302
|
-
//
|
|
1303
|
-
//
|
|
1304
|
-
//
|
|
1305
|
-
//
|
|
1260
|
+
// OpenCode 1.2+ migrated to a SQLite database at
|
|
1261
|
+
// ~/.local/share/opencode/opencode.db. The previous SQLite reader required
|
|
1262
|
+
// `better-sqlite3` (a native dep). In 0.6.0-beta.4 we reverted that dep
|
|
1263
|
+
// because its prebuilt-tarball download from GitHub Releases was unreliable
|
|
1264
|
+
// in some networks (notably Windows + China), and the source-build fallback
|
|
1265
|
+
// requires a C compiler that most users don't have — `npm install` was
|
|
1266
|
+
// failing for the entire CLI, not just the OpenCode reader.
|
|
1306
1267
|
//
|
|
1307
|
-
//
|
|
1308
|
-
//
|
|
1309
|
-
//
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
// on it.
|
|
1319
|
-
const OC_DB_PATH = path.join(HOME, ".local", "share", "opencode", "opencode.db");
|
|
1320
|
-
let bsqliteCtor;
|
|
1321
|
-
let bsqliteWarned = false;
|
|
1322
|
-
let bsqliteResolved = false;
|
|
1323
|
-
function loadBetterSqlite3() {
|
|
1324
|
-
if (bsqliteResolved)
|
|
1325
|
-
return bsqliteCtor;
|
|
1326
|
-
bsqliteResolved = true;
|
|
1327
|
-
try {
|
|
1328
|
-
const mod = ocRequire("better-sqlite3");
|
|
1329
|
-
bsqliteCtor =
|
|
1330
|
-
typeof mod === "function"
|
|
1331
|
-
? mod
|
|
1332
|
-
: (mod.default ?? undefined);
|
|
1333
|
-
return bsqliteCtor;
|
|
1334
|
-
}
|
|
1335
|
-
catch {
|
|
1336
|
-
if (!bsqliteWarned) {
|
|
1337
|
-
bsqliteWarned = true;
|
|
1338
|
-
process.stderr.write("tl mem: better-sqlite3 failed to load; OpenCode platform skipped.\n" +
|
|
1339
|
-
" To enable: reinstall trellis (or `npm rebuild better-sqlite3`).\n");
|
|
1340
|
-
}
|
|
1341
|
-
return undefined;
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
function discoverColumns(db, table) {
|
|
1345
|
-
try {
|
|
1346
|
-
// PRAGMA table_info(<name>); table is a literal identifier — not a user
|
|
1347
|
-
// input — so embedding it is safe. better-sqlite3 doesn't bind identifiers.
|
|
1348
|
-
const rows = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
1349
|
-
return new Set(rows.map((r) => r.name).filter((n) => !!n));
|
|
1350
|
-
}
|
|
1351
|
-
catch {
|
|
1352
|
-
return new Set();
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
let ocSchemaWarned = false;
|
|
1356
|
-
function probeSchema(db) {
|
|
1357
|
-
const sessionCols = discoverColumns(db, "session");
|
|
1358
|
-
const messageCols = discoverColumns(db, "message");
|
|
1359
|
-
const partCols = discoverColumns(db, "part");
|
|
1360
|
-
const need = [
|
|
1361
|
-
[sessionCols, ["id", "directory", "time_created", "time_updated"]],
|
|
1362
|
-
[messageCols, ["id", "session_id", "data"]],
|
|
1363
|
-
[partCols, ["message_id", "data"]],
|
|
1364
|
-
];
|
|
1365
|
-
const missing = [];
|
|
1366
|
-
for (const [cols, required] of need) {
|
|
1367
|
-
for (const c of required) {
|
|
1368
|
-
if (!cols.has(c))
|
|
1369
|
-
missing.push(c);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
const ok = missing.length === 0;
|
|
1373
|
-
if (!ok && !ocSchemaWarned) {
|
|
1374
|
-
ocSchemaWarned = true;
|
|
1375
|
-
process.stderr.write(`tl mem: OpenCode SQLite schema missing required columns (${missing.join(", ")}); platform skipped.\n`);
|
|
1376
|
-
}
|
|
1377
|
-
return { sessionCols, messageCols, partCols, ok };
|
|
1378
|
-
}
|
|
1379
|
-
function openOcDb() {
|
|
1380
|
-
if (!fs.existsSync(OC_DB_PATH))
|
|
1381
|
-
return undefined;
|
|
1382
|
-
const Ctor = loadBetterSqlite3();
|
|
1383
|
-
if (!Ctor)
|
|
1384
|
-
return undefined;
|
|
1385
|
-
let db;
|
|
1386
|
-
try {
|
|
1387
|
-
db = new Ctor(OC_DB_PATH, { readonly: true, fileMustExist: true });
|
|
1388
|
-
}
|
|
1389
|
-
catch {
|
|
1390
|
-
return undefined;
|
|
1391
|
-
}
|
|
1392
|
-
const schema = probeSchema(db);
|
|
1393
|
-
if (!schema.ok) {
|
|
1394
|
-
db.close();
|
|
1395
|
-
return undefined;
|
|
1396
|
-
}
|
|
1397
|
-
return { db, schema };
|
|
1268
|
+
// The three exported adapter functions are kept (callers in dispatch /
|
|
1269
|
+
// slicePhase rely on them) but degraded to no-ops with a one-shot stderr
|
|
1270
|
+
// warning. Re-enabled in a future release once a non-native fallback ships.
|
|
1271
|
+
let opencodeWarned = false;
|
|
1272
|
+
function warnOpencodeUnavailable() {
|
|
1273
|
+
if (opencodeWarned)
|
|
1274
|
+
return;
|
|
1275
|
+
opencodeWarned = true;
|
|
1276
|
+
process.stderr.write("⚠️ tl mem: OpenCode platform reader is temporarily unavailable in this build.\n" +
|
|
1277
|
+
" OpenCode 1.2+ moved to SQLite; the native dependency was reverted in\n" +
|
|
1278
|
+
" 0.6.0-beta.4 due to install failures. Re-enabled in a future release.\n");
|
|
1398
1279
|
}
|
|
1399
|
-
export function opencodeListSessions(
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
return [];
|
|
1403
|
-
try {
|
|
1404
|
-
const cols = ctx.schema.sessionCols;
|
|
1405
|
-
const select = [
|
|
1406
|
-
"id",
|
|
1407
|
-
cols.has("directory") ? "directory" : "NULL AS directory",
|
|
1408
|
-
cols.has("title") ? "title" : "NULL AS title",
|
|
1409
|
-
cols.has("parent_id") ? "parent_id" : "NULL AS parent_id",
|
|
1410
|
-
"time_created",
|
|
1411
|
-
"time_updated",
|
|
1412
|
-
].join(", ");
|
|
1413
|
-
const rows = ctx.db
|
|
1414
|
-
.prepare(`SELECT ${select} FROM session ORDER BY time_updated DESC`)
|
|
1415
|
-
.all();
|
|
1416
|
-
const out = [];
|
|
1417
|
-
for (const r of rows) {
|
|
1418
|
-
const created = r.time_created
|
|
1419
|
-
? new Date(r.time_created).toISOString()
|
|
1420
|
-
: undefined;
|
|
1421
|
-
const updated = r.time_updated
|
|
1422
|
-
? new Date(r.time_updated).toISOString()
|
|
1423
|
-
: undefined;
|
|
1424
|
-
const cwd = r.directory ?? undefined;
|
|
1425
|
-
if (f.cwd && !sameProject(cwd, f.cwd))
|
|
1426
|
-
continue;
|
|
1427
|
-
if (!inRangeOverlap(created, updated, f))
|
|
1428
|
-
continue;
|
|
1429
|
-
out.push(SessionInfoSchema.parse({
|
|
1430
|
-
platform: "opencode",
|
|
1431
|
-
id: r.id,
|
|
1432
|
-
title: r.title ?? undefined,
|
|
1433
|
-
cwd,
|
|
1434
|
-
created,
|
|
1435
|
-
updated,
|
|
1436
|
-
filePath: OC_DB_PATH,
|
|
1437
|
-
parent_id: r.parent_id ?? undefined,
|
|
1438
|
-
}));
|
|
1439
|
-
}
|
|
1440
|
-
return out;
|
|
1441
|
-
}
|
|
1442
|
-
finally {
|
|
1443
|
-
ctx.db.close();
|
|
1444
|
-
}
|
|
1280
|
+
export function opencodeListSessions(_f) {
|
|
1281
|
+
warnOpencodeUnavailable();
|
|
1282
|
+
return [];
|
|
1445
1283
|
}
|
|
1446
|
-
export function opencodeExtractDialogue(
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
return [];
|
|
1450
|
-
try {
|
|
1451
|
-
const messages = ctx.db
|
|
1452
|
-
.prepare("SELECT id, data, time_created FROM message WHERE session_id = ? ORDER BY time_created ASC, id ASC")
|
|
1453
|
-
.all(s.id);
|
|
1454
|
-
if (messages.length === 0)
|
|
1455
|
-
return [];
|
|
1456
|
-
const parts = ctx.db
|
|
1457
|
-
.prepare("SELECT message_id, data FROM part WHERE session_id = ? ORDER BY message_id ASC, id ASC")
|
|
1458
|
-
.all(s.id);
|
|
1459
|
-
// Group parts by message_id, preserving SQL order (id ASC).
|
|
1460
|
-
const partsByMsg = new Map();
|
|
1461
|
-
for (const p of parts) {
|
|
1462
|
-
const list = partsByMsg.get(p.message_id);
|
|
1463
|
-
if (list)
|
|
1464
|
-
list.push(p);
|
|
1465
|
-
else
|
|
1466
|
-
partsByMsg.set(p.message_id, [p]);
|
|
1467
|
-
}
|
|
1468
|
-
const turns = [];
|
|
1469
|
-
for (const m of messages) {
|
|
1470
|
-
const mdata = safeJsonParse(m.data, OpenCodeMessageDataSchema);
|
|
1471
|
-
if (!mdata)
|
|
1472
|
-
continue;
|
|
1473
|
-
const roleParsed = DialogueRoleSchema.safeParse(mdata.role);
|
|
1474
|
-
if (!roleParsed.success)
|
|
1475
|
-
continue;
|
|
1476
|
-
const msgParts = partsByMsg.get(m.id) ?? [];
|
|
1477
|
-
const collected = [];
|
|
1478
|
-
let totalRaw = 0;
|
|
1479
|
-
for (const p of msgParts) {
|
|
1480
|
-
const pdata = safeJsonParse(p.data, OpenCodePartDataSchema);
|
|
1481
|
-
if (!pdata)
|
|
1482
|
-
continue;
|
|
1483
|
-
if (pdata.type !== "text" || pdata.synthetic)
|
|
1484
|
-
continue;
|
|
1485
|
-
if (typeof pdata.text !== "string")
|
|
1486
|
-
continue;
|
|
1487
|
-
totalRaw += pdata.text.length;
|
|
1488
|
-
const cleaned = stripInjectionTags(pdata.text);
|
|
1489
|
-
if (cleaned)
|
|
1490
|
-
collected.push(cleaned);
|
|
1491
|
-
}
|
|
1492
|
-
if (!collected.length)
|
|
1493
|
-
continue;
|
|
1494
|
-
const merged = collected.join("\n\n");
|
|
1495
|
-
if (isBootstrapTurn(merged, totalRaw))
|
|
1496
|
-
continue;
|
|
1497
|
-
turns.push({ role: roleParsed.data, text: merged });
|
|
1498
|
-
}
|
|
1499
|
-
return turns;
|
|
1500
|
-
}
|
|
1501
|
-
finally {
|
|
1502
|
-
ctx.db.close();
|
|
1503
|
-
}
|
|
1284
|
+
export function opencodeExtractDialogue(_s) {
|
|
1285
|
+
warnOpencodeUnavailable();
|
|
1286
|
+
return [];
|
|
1504
1287
|
}
|
|
1505
|
-
function opencodeSearch(
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
turns.unshift({ role: "user", text: s.title });
|
|
1509
|
-
return searchInDialogue(turns, kw);
|
|
1510
|
-
}
|
|
1511
|
-
function safeJsonParse(raw, schema) {
|
|
1512
|
-
let parsed;
|
|
1513
|
-
try {
|
|
1514
|
-
parsed = JSON.parse(raw);
|
|
1515
|
-
}
|
|
1516
|
-
catch {
|
|
1517
|
-
return undefined;
|
|
1518
|
-
}
|
|
1519
|
-
const r = schema.safeParse(parsed);
|
|
1520
|
-
return r.success ? r.data : undefined;
|
|
1288
|
+
function opencodeSearch(_s, kw) {
|
|
1289
|
+
warnOpencodeUnavailable();
|
|
1290
|
+
return searchInDialogue([], kw);
|
|
1521
1291
|
}
|
|
1522
1292
|
// ---------- dispatch ----------
|
|
1523
1293
|
function listAll(f) {
|