@blulotus/trellis-core 0.7.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/LICENSE +235 -0
- package/dist/channel/api/assert.d.ts +3 -0
- package/dist/channel/api/assert.d.ts.map +1 -0
- package/dist/channel/api/assert.js +11 -0
- package/dist/channel/api/assert.js.map +1 -0
- package/dist/channel/api/context.d.ts +21 -0
- package/dist/channel/api/context.d.ts.map +1 -0
- package/dist/channel/api/context.js +99 -0
- package/dist/channel/api/context.js.map +1 -0
- package/dist/channel/api/create.d.ts +9 -0
- package/dist/channel/api/create.d.ts.map +1 -0
- package/dist/channel/api/create.js +104 -0
- package/dist/channel/api/create.js.map +1 -0
- package/dist/channel/api/inbox.d.ts +51 -0
- package/dist/channel/api/inbox.d.ts.map +1 -0
- package/dist/channel/api/inbox.js +176 -0
- package/dist/channel/api/inbox.js.map +1 -0
- package/dist/channel/api/interrupt.d.ts +31 -0
- package/dist/channel/api/interrupt.d.ts.map +1 -0
- package/dist/channel/api/interrupt.js +102 -0
- package/dist/channel/api/interrupt.js.map +1 -0
- package/dist/channel/api/post-thread.d.ts +14 -0
- package/dist/channel/api/post-thread.d.ts.map +1 -0
- package/dist/channel/api/post-thread.js +109 -0
- package/dist/channel/api/post-thread.js.map +1 -0
- package/dist/channel/api/read.d.ts +17 -0
- package/dist/channel/api/read.d.ts.map +1 -0
- package/dist/channel/api/read.js +44 -0
- package/dist/channel/api/read.js.map +1 -0
- package/dist/channel/api/resolve.d.ts +21 -0
- package/dist/channel/api/resolve.d.ts.map +1 -0
- package/dist/channel/api/resolve.js +28 -0
- package/dist/channel/api/resolve.js.map +1 -0
- package/dist/channel/api/runtime.d.ts +70 -0
- package/dist/channel/api/runtime.d.ts.map +1 -0
- package/dist/channel/api/runtime.js +11 -0
- package/dist/channel/api/runtime.js.map +1 -0
- package/dist/channel/api/send.d.ts +4 -0
- package/dist/channel/api/send.d.ts.map +1 -0
- package/dist/channel/api/send.js +52 -0
- package/dist/channel/api/send.js.map +1 -0
- package/dist/channel/api/spawn.d.ts +13 -0
- package/dist/channel/api/spawn.d.ts.map +1 -0
- package/dist/channel/api/spawn.js +54 -0
- package/dist/channel/api/spawn.js.map +1 -0
- package/dist/channel/api/title.d.ts +5 -0
- package/dist/channel/api/title.d.ts.map +1 -0
- package/dist/channel/api/title.js +40 -0
- package/dist/channel/api/title.js.map +1 -0
- package/dist/channel/api/types.d.ts +65 -0
- package/dist/channel/api/types.d.ts.map +1 -0
- package/dist/channel/api/types.js +2 -0
- package/dist/channel/api/types.js.map +1 -0
- package/dist/channel/api/watch-channels.d.ts +40 -0
- package/dist/channel/api/watch-channels.d.ts.map +1 -0
- package/dist/channel/api/watch-channels.js +143 -0
- package/dist/channel/api/watch-channels.js.map +1 -0
- package/dist/channel/api/watch.d.ts +11 -0
- package/dist/channel/api/watch.d.ts.map +1 -0
- package/dist/channel/api/watch.js +17 -0
- package/dist/channel/api/watch.js.map +1 -0
- package/dist/channel/api/workers.d.ts +69 -0
- package/dist/channel/api/workers.d.ts.map +1 -0
- package/dist/channel/api/workers.js +145 -0
- package/dist/channel/api/workers.js.map +1 -0
- package/dist/channel/index.d.ts +38 -0
- package/dist/channel/index.d.ts.map +1 -0
- package/dist/channel/index.js +23 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/channel/internal/store/channel-metadata.d.ts +23 -0
- package/dist/channel/internal/store/channel-metadata.d.ts.map +1 -0
- package/dist/channel/internal/store/channel-metadata.js +94 -0
- package/dist/channel/internal/store/channel-metadata.js.map +1 -0
- package/dist/channel/internal/store/delivery.d.ts +27 -0
- package/dist/channel/internal/store/delivery.d.ts.map +1 -0
- package/dist/channel/internal/store/delivery.js +37 -0
- package/dist/channel/internal/store/delivery.js.map +1 -0
- package/dist/channel/internal/store/events.d.ts +215 -0
- package/dist/channel/internal/store/events.d.ts.map +1 -0
- package/dist/channel/internal/store/events.js +206 -0
- package/dist/channel/internal/store/events.js.map +1 -0
- package/dist/channel/internal/store/filter.d.ts +21 -0
- package/dist/channel/internal/store/filter.d.ts.map +1 -0
- package/dist/channel/internal/store/filter.js +75 -0
- package/dist/channel/internal/store/filter.js.map +1 -0
- package/dist/channel/internal/store/inbox.d.ts +17 -0
- package/dist/channel/internal/store/inbox.d.ts.map +1 -0
- package/dist/channel/internal/store/inbox.js +30 -0
- package/dist/channel/internal/store/inbox.js.map +1 -0
- package/dist/channel/internal/store/lock.d.ts +17 -0
- package/dist/channel/internal/store/lock.d.ts.map +1 -0
- package/dist/channel/internal/store/lock.js +88 -0
- package/dist/channel/internal/store/lock.js.map +1 -0
- package/dist/channel/internal/store/paths.d.ts +57 -0
- package/dist/channel/internal/store/paths.d.ts.map +1 -0
- package/dist/channel/internal/store/paths.js +264 -0
- package/dist/channel/internal/store/paths.js.map +1 -0
- package/dist/channel/internal/store/schema.d.ts +77 -0
- package/dist/channel/internal/store/schema.d.ts.map +1 -0
- package/dist/channel/internal/store/schema.js +127 -0
- package/dist/channel/internal/store/schema.js.map +1 -0
- package/dist/channel/internal/store/seq.d.ts +12 -0
- package/dist/channel/internal/store/seq.d.ts.map +1 -0
- package/dist/channel/internal/store/seq.js +133 -0
- package/dist/channel/internal/store/seq.js.map +1 -0
- package/dist/channel/internal/store/thread-state.d.ts +37 -0
- package/dist/channel/internal/store/thread-state.d.ts.map +1 -0
- package/dist/channel/internal/store/thread-state.js +206 -0
- package/dist/channel/internal/store/thread-state.js.map +1 -0
- package/dist/channel/internal/store/watch.d.ts +10 -0
- package/dist/channel/internal/store/watch.d.ts.map +1 -0
- package/dist/channel/internal/store/watch.js +122 -0
- package/dist/channel/internal/store/watch.js.map +1 -0
- package/dist/channel/internal/store/worker-state.d.ts +56 -0
- package/dist/channel/internal/store/worker-state.d.ts.map +1 -0
- package/dist/channel/internal/store/worker-state.js +220 -0
- package/dist/channel/internal/store/worker-state.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/mem/adapters/claude.d.ts +22 -0
- package/dist/mem/adapters/claude.d.ts.map +1 -0
- package/dist/mem/adapters/claude.js +209 -0
- package/dist/mem/adapters/claude.js.map +1 -0
- package/dist/mem/adapters/codex.d.ts +55 -0
- package/dist/mem/adapters/codex.d.ts.map +1 -0
- package/dist/mem/adapters/codex.js +344 -0
- package/dist/mem/adapters/codex.js.map +1 -0
- package/dist/mem/adapters/grok.d.ts +41 -0
- package/dist/mem/adapters/grok.d.ts.map +1 -0
- package/dist/mem/adapters/grok.js +202 -0
- package/dist/mem/adapters/grok.js.map +1 -0
- package/dist/mem/adapters/opencode.d.ts +19 -0
- package/dist/mem/adapters/opencode.d.ts.map +1 -0
- package/dist/mem/adapters/opencode.js +25 -0
- package/dist/mem/adapters/opencode.js.map +1 -0
- package/dist/mem/adapters/pi.d.ts +24 -0
- package/dist/mem/adapters/pi.d.ts.map +1 -0
- package/dist/mem/adapters/pi.js +290 -0
- package/dist/mem/adapters/pi.js.map +1 -0
- package/dist/mem/adapters/zcode.d.ts +76 -0
- package/dist/mem/adapters/zcode.d.ts.map +1 -0
- package/dist/mem/adapters/zcode.js +434 -0
- package/dist/mem/adapters/zcode.js.map +1 -0
- package/dist/mem/context.d.ts +23 -0
- package/dist/mem/context.d.ts.map +1 -0
- package/dist/mem/context.js +120 -0
- package/dist/mem/context.js.map +1 -0
- package/dist/mem/dialogue.d.ts +32 -0
- package/dist/mem/dialogue.d.ts.map +1 -0
- package/dist/mem/dialogue.js +0 -0
- package/dist/mem/dialogue.js.map +1 -0
- package/dist/mem/filter.d.ts +31 -0
- package/dist/mem/filter.d.ts.map +1 -0
- package/dist/mem/filter.js +66 -0
- package/dist/mem/filter.js.map +1 -0
- package/dist/mem/index.d.ts +18 -0
- package/dist/mem/index.d.ts.map +1 -0
- package/dist/mem/index.js +17 -0
- package/dist/mem/index.js.map +1 -0
- package/dist/mem/internal/jsonl.d.ts +35 -0
- package/dist/mem/internal/jsonl.d.ts.map +1 -0
- package/dist/mem/internal/jsonl.js +125 -0
- package/dist/mem/internal/jsonl.js.map +1 -0
- package/dist/mem/internal/paths.d.ts +38 -0
- package/dist/mem/internal/paths.d.ts.map +1 -0
- package/dist/mem/internal/paths.js +126 -0
- package/dist/mem/internal/paths.js.map +1 -0
- package/dist/mem/internal/sqlite-readonly.d.ts +77 -0
- package/dist/mem/internal/sqlite-readonly.d.ts.map +1 -0
- package/dist/mem/internal/sqlite-readonly.js +797 -0
- package/dist/mem/internal/sqlite-readonly.js.map +1 -0
- package/dist/mem/phase.d.ts +45 -0
- package/dist/mem/phase.d.ts.map +1 -0
- package/dist/mem/phase.js +220 -0
- package/dist/mem/phase.js.map +1 -0
- package/dist/mem/projects.d.ts +13 -0
- package/dist/mem/projects.d.ts.map +1 -0
- package/dist/mem/projects.js +47 -0
- package/dist/mem/projects.js.map +1 -0
- package/dist/mem/search.d.ts +39 -0
- package/dist/mem/search.d.ts.map +1 -0
- package/dist/mem/search.js +133 -0
- package/dist/mem/search.js.map +1 -0
- package/dist/mem/sessions.d.ts +38 -0
- package/dist/mem/sessions.d.ts.map +1 -0
- package/dist/mem/sessions.js +313 -0
- package/dist/mem/sessions.js.map +1 -0
- package/dist/mem/types.d.ts +188 -0
- package/dist/mem/types.d.ts.map +1 -0
- package/dist/mem/types.js +10 -0
- package/dist/mem/types.js.map +1 -0
- package/dist/task/index.d.ts +9 -0
- package/dist/task/index.d.ts.map +1 -0
- package/dist/task/index.js +9 -0
- package/dist/task/index.js.map +1 -0
- package/dist/task/paths.d.ts +37 -0
- package/dist/task/paths.d.ts.map +1 -0
- package/dist/task/paths.js +49 -0
- package/dist/task/paths.js.map +1 -0
- package/dist/task/phase.d.ts +27 -0
- package/dist/task/phase.d.ts.map +1 -0
- package/dist/task/phase.js +24 -0
- package/dist/task/phase.js.map +1 -0
- package/dist/task/records.d.ts +39 -0
- package/dist/task/records.d.ts.map +1 -0
- package/dist/task/records.js +89 -0
- package/dist/task/records.js.map +1 -0
- package/dist/task/schema.d.ts +77 -0
- package/dist/task/schema.d.ts.map +1 -0
- package/dist/task/schema.js +220 -0
- package/dist/task/schema.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +4 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode session reader — currently a degraded no-op.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode 1.2+ moved to a SQLite store at
|
|
5
|
+
* `~/.local/share/opencode/opencode.db`. The previous SQLite reader required a
|
|
6
|
+
* native dependency (`better-sqlite3`) whose prebuilt-tarball + node-gyp
|
|
7
|
+
* fallback chain broke `npm install` on Windows + restricted networks, so it
|
|
8
|
+
* was reverted. These adapter functions are kept (dispatch / phase slicing
|
|
9
|
+
* rely on them) but degraded to silent no-ops.
|
|
10
|
+
*
|
|
11
|
+
* The "OpenCode reader unavailable" warning is a presentation concern owned by
|
|
12
|
+
* the CLI — core never prints. Re-enabled in a future release once a
|
|
13
|
+
* non-native backend ships.
|
|
14
|
+
*/
|
|
15
|
+
import { searchInDialogue } from "../search.js";
|
|
16
|
+
export function opencodeListSessions(_f) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
export function opencodeExtractDialogue(_s) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
export function opencodeSearch(kw) {
|
|
23
|
+
return searchInDialogue([], kw);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=opencode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode.js","sourceRoot":"","sources":["../../../src/mem/adapters/opencode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQhD,MAAM,UAAU,oBAAoB,CAAC,EAAa;IAChD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,EAAkB;IACxD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,OAAO,gBAAgB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persisted Pi Agent session reader.
|
|
3
|
+
*
|
|
4
|
+
* Layout: `~/.pi/agent/sessions/--<encoded-cwd>--/<timestamp>_<id>.jsonl`
|
|
5
|
+
* for the default store, or direct `.jsonl` files under an env/settings
|
|
6
|
+
* configured custom session directory. Entries form a tree via `id` / `parentId`;
|
|
7
|
+
* extraction follows the whole active branch (last entry leaf).
|
|
8
|
+
*
|
|
9
|
+
* Compaction: Pi writes a `compaction` entry naming the first entry it kept.
|
|
10
|
+
* That is Pi's context rule, not a record of what was said — every earlier
|
|
11
|
+
* entry is still on the active path. Extraction keeps the full path and renders
|
|
12
|
+
* the compaction entry as a boundary marker in place.
|
|
13
|
+
*/
|
|
14
|
+
import type { DialogueTurn, MemFilter, MemSessionInfo, SearchHit, TaskPyEvent } from "../types.js";
|
|
15
|
+
interface PiBuilt {
|
|
16
|
+
turns: DialogueTurn[];
|
|
17
|
+
events: TaskPyEvent[];
|
|
18
|
+
}
|
|
19
|
+
export declare function piListSessions(f: MemFilter): MemSessionInfo[];
|
|
20
|
+
export declare function piExtractDialogue(s: MemSessionInfo): DialogueTurn[];
|
|
21
|
+
export declare function piSearch(s: MemSessionInfo, kw: string): SearchHit;
|
|
22
|
+
export declare function collectPiTurnsAndEvents(s: MemSessionInfo): PiBuilt;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=pi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../../../src/mem/adapters/pi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoBH,OAAO,KAAK,EAEV,YAAY,EACZ,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACZ,MAAM,aAAa,CAAC;AAwCrB,UAAU,OAAO;IACf,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAID,wBAAgB,cAAc,CAAC,CAAC,EAAE,SAAS,GAAG,cAAc,EAAE,CAwD7D;AA2CD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,cAAc,GAAG,YAAY,EAAE,CAEnE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAEjE;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAElE"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persisted Pi Agent session reader.
|
|
3
|
+
*
|
|
4
|
+
* Layout: `~/.pi/agent/sessions/--<encoded-cwd>--/<timestamp>_<id>.jsonl`
|
|
5
|
+
* for the default store, or direct `.jsonl` files under an env/settings
|
|
6
|
+
* configured custom session directory. Entries form a tree via `id` / `parentId`;
|
|
7
|
+
* extraction follows the whole active branch (last entry leaf).
|
|
8
|
+
*
|
|
9
|
+
* Compaction: Pi writes a `compaction` entry naming the first entry it kept.
|
|
10
|
+
* That is Pi's context rule, not a record of what was said — every earlier
|
|
11
|
+
* entry is still on the active path. Extraction keeps the full path and renders
|
|
12
|
+
* the compaction entry as a boundary marker in place.
|
|
13
|
+
*/
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import { compactionBoundaryTurn, stripInjectionTags, isBootstrapTurn, } from "../dialogue.js";
|
|
17
|
+
import { inRangeOverlap, sameProject } from "../filter.js";
|
|
18
|
+
import { readJsonl, readJsonlFirst } from "../internal/jsonl.js";
|
|
19
|
+
import { PI_AGENT_DIR, piProjectDirFromCwd, piSessionRoots, walkDir, } from "../internal/paths.js";
|
|
20
|
+
import { parseTaskPyCommandsAll } from "../phase.js";
|
|
21
|
+
import { searchInDialogue } from "../search.js";
|
|
22
|
+
// ---------- list ----------
|
|
23
|
+
export function piListSessions(f) {
|
|
24
|
+
const out = [];
|
|
25
|
+
for (const filePath of candidateFiles(f)) {
|
|
26
|
+
const header = readJsonlFirst(filePath);
|
|
27
|
+
if (header?.type !== "session")
|
|
28
|
+
continue;
|
|
29
|
+
const id = typeof header.id === "string" ? header.id : idFromFile(filePath);
|
|
30
|
+
const cwd = typeof header.cwd === "string" ? header.cwd : undefined;
|
|
31
|
+
if (f.cwd && !sameProject(cwd, f.cwd))
|
|
32
|
+
continue;
|
|
33
|
+
let title;
|
|
34
|
+
let lastActivityMs;
|
|
35
|
+
readJsonl(filePath, (entry) => {
|
|
36
|
+
if (entry.type === "session_info") {
|
|
37
|
+
title =
|
|
38
|
+
typeof entry.name === "string" && entry.name.trim()
|
|
39
|
+
? entry.name.trim()
|
|
40
|
+
: undefined;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (entry.type !== "message")
|
|
44
|
+
return;
|
|
45
|
+
const role = entry.message?.role;
|
|
46
|
+
if (role !== "user" && role !== "assistant")
|
|
47
|
+
return;
|
|
48
|
+
const activityMs = timestampMs(entry.message?.timestamp) ?? timestampMs(entry.timestamp);
|
|
49
|
+
if (activityMs !== undefined)
|
|
50
|
+
lastActivityMs = Math.max(lastActivityMs ?? 0, activityMs);
|
|
51
|
+
});
|
|
52
|
+
let updated;
|
|
53
|
+
try {
|
|
54
|
+
updated =
|
|
55
|
+
lastActivityMs !== undefined
|
|
56
|
+
? new Date(lastActivityMs).toISOString()
|
|
57
|
+
: fs.statSync(filePath).mtime.toISOString();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
updated =
|
|
61
|
+
lastActivityMs !== undefined
|
|
62
|
+
? new Date(lastActivityMs).toISOString()
|
|
63
|
+
: undefined;
|
|
64
|
+
}
|
|
65
|
+
const created = typeof header.timestamp === "string" ? header.timestamp : undefined;
|
|
66
|
+
if (!inRangeOverlap(created, updated, f))
|
|
67
|
+
continue;
|
|
68
|
+
out.push({
|
|
69
|
+
platform: "pi",
|
|
70
|
+
id,
|
|
71
|
+
title,
|
|
72
|
+
cwd,
|
|
73
|
+
created,
|
|
74
|
+
updated,
|
|
75
|
+
filePath,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
function candidateFiles(f) {
|
|
81
|
+
const defaultRoot = path.join(PI_AGENT_DIR, "sessions");
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
const out = [];
|
|
84
|
+
const pushJsonlFiles = (root) => {
|
|
85
|
+
if (!fs.existsSync(root))
|
|
86
|
+
return;
|
|
87
|
+
for (const file of walkDir(root)) {
|
|
88
|
+
if (!file.endsWith(".jsonl"))
|
|
89
|
+
continue;
|
|
90
|
+
const normalized = path.resolve(file);
|
|
91
|
+
if (seen.has(normalized))
|
|
92
|
+
continue;
|
|
93
|
+
seen.add(normalized);
|
|
94
|
+
out.push(file);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
for (const root of piSessionRoots(f.cwd)) {
|
|
98
|
+
if (f.cwd && path.resolve(root) === path.resolve(defaultRoot)) {
|
|
99
|
+
pushJsonlFiles(piProjectDirFromCwd(f.cwd));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
pushJsonlFiles(root);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function idFromFile(filePath) {
|
|
108
|
+
const base = path.basename(filePath, ".jsonl");
|
|
109
|
+
const underscore = base.indexOf("_");
|
|
110
|
+
return underscore === -1 ? base : base.slice(underscore + 1);
|
|
111
|
+
}
|
|
112
|
+
function timestampMs(value) {
|
|
113
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
114
|
+
return value;
|
|
115
|
+
if (typeof value !== "string")
|
|
116
|
+
return undefined;
|
|
117
|
+
const ms = new Date(value).getTime();
|
|
118
|
+
return Number.isNaN(ms) ? undefined : ms;
|
|
119
|
+
}
|
|
120
|
+
// ---------- extract/search/phase ----------
|
|
121
|
+
export function piExtractDialogue(s) {
|
|
122
|
+
return buildPiTurnsAndEvents(s).turns;
|
|
123
|
+
}
|
|
124
|
+
export function piSearch(s, kw) {
|
|
125
|
+
return searchInDialogue(piExtractDialogue(s), kw);
|
|
126
|
+
}
|
|
127
|
+
export function collectPiTurnsAndEvents(s) {
|
|
128
|
+
return buildPiTurnsAndEvents(s);
|
|
129
|
+
}
|
|
130
|
+
function buildPiTurnsAndEvents(s) {
|
|
131
|
+
const activePath = piActivePath(s.filePath);
|
|
132
|
+
const turns = [];
|
|
133
|
+
const events = [];
|
|
134
|
+
for (const entry of activePath) {
|
|
135
|
+
collectTaskEvents(entry, turns.length, events);
|
|
136
|
+
const turn = turnFromEntry(entry);
|
|
137
|
+
if (turn)
|
|
138
|
+
turns.push(turn);
|
|
139
|
+
}
|
|
140
|
+
return { turns, events };
|
|
141
|
+
}
|
|
142
|
+
/** Walk parent links back from the last entry — the branch the session ended
|
|
143
|
+
* on, in chronological order. No compaction truncation: a `compaction` entry is
|
|
144
|
+
* Pi's context rule, and the entries it excluded are still on this path. */
|
|
145
|
+
function piActivePath(filePath) {
|
|
146
|
+
const entries = [];
|
|
147
|
+
readJsonl(filePath, (entry) => {
|
|
148
|
+
if (entry.type === "session")
|
|
149
|
+
return;
|
|
150
|
+
if (typeof entry.id !== "string")
|
|
151
|
+
return;
|
|
152
|
+
entries.push(entry);
|
|
153
|
+
});
|
|
154
|
+
if (entries.length === 0)
|
|
155
|
+
return [];
|
|
156
|
+
const byId = new Map();
|
|
157
|
+
for (const entry of entries) {
|
|
158
|
+
if (typeof entry.id === "string")
|
|
159
|
+
byId.set(entry.id, entry);
|
|
160
|
+
}
|
|
161
|
+
const leaf = entries[entries.length - 1];
|
|
162
|
+
if (!leaf)
|
|
163
|
+
return [];
|
|
164
|
+
const activePath = [];
|
|
165
|
+
let current = leaf;
|
|
166
|
+
const seen = new Set();
|
|
167
|
+
while (current) {
|
|
168
|
+
if (typeof current.id !== "string" || seen.has(current.id))
|
|
169
|
+
break;
|
|
170
|
+
seen.add(current.id);
|
|
171
|
+
activePath.unshift(current);
|
|
172
|
+
current =
|
|
173
|
+
typeof current.parentId === "string"
|
|
174
|
+
? byId.get(current.parentId)
|
|
175
|
+
: undefined;
|
|
176
|
+
}
|
|
177
|
+
return activePath;
|
|
178
|
+
}
|
|
179
|
+
function turnFromEntry(entry) {
|
|
180
|
+
if (entry.type === "compaction") {
|
|
181
|
+
return compactionBoundary(entry.summary);
|
|
182
|
+
}
|
|
183
|
+
if (entry.type === "branch_summary") {
|
|
184
|
+
return syntheticTurn("[branch summary]", entry.summary);
|
|
185
|
+
}
|
|
186
|
+
if (entry.type === "custom_message") {
|
|
187
|
+
return buildTurn("user", entry.content);
|
|
188
|
+
}
|
|
189
|
+
if (entry.type !== "message")
|
|
190
|
+
return null;
|
|
191
|
+
const msg = entry.message;
|
|
192
|
+
if (!msg)
|
|
193
|
+
return null;
|
|
194
|
+
switch (msg.role) {
|
|
195
|
+
case "user":
|
|
196
|
+
return buildTurn("user", msg.content);
|
|
197
|
+
case "assistant":
|
|
198
|
+
return buildTurn("assistant", msg.content);
|
|
199
|
+
case "custom":
|
|
200
|
+
return buildTurn("user", msg.content);
|
|
201
|
+
case "branchSummary":
|
|
202
|
+
return syntheticTurn("[branch summary]", msg.summary);
|
|
203
|
+
case "compactionSummary":
|
|
204
|
+
return compactionBoundary(msg.summary);
|
|
205
|
+
default:
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function compactionBoundary(raw) {
|
|
210
|
+
const summary = typeof raw === "string" ? stripInjectionTags(raw) : "";
|
|
211
|
+
return compactionBoundaryTurn("context compacted here; the turns above stayed on the active branch", summary);
|
|
212
|
+
}
|
|
213
|
+
function syntheticTurn(prefix, raw) {
|
|
214
|
+
if (typeof raw !== "string")
|
|
215
|
+
return null;
|
|
216
|
+
const text = stripInjectionTags(raw);
|
|
217
|
+
if (!text)
|
|
218
|
+
return null;
|
|
219
|
+
return { role: "user", text: `${prefix}\n${text}` };
|
|
220
|
+
}
|
|
221
|
+
function buildTurn(role, content) {
|
|
222
|
+
const parts = [];
|
|
223
|
+
let totalRaw = 0;
|
|
224
|
+
if (typeof content === "string") {
|
|
225
|
+
totalRaw = content.length;
|
|
226
|
+
const cleaned = stripInjectionTags(content);
|
|
227
|
+
if (cleaned)
|
|
228
|
+
parts.push(cleaned);
|
|
229
|
+
}
|
|
230
|
+
else if (Array.isArray(content)) {
|
|
231
|
+
for (const block of content) {
|
|
232
|
+
if (block.type !== "text" || typeof block.text !== "string")
|
|
233
|
+
continue;
|
|
234
|
+
totalRaw += block.text.length;
|
|
235
|
+
const cleaned = stripInjectionTags(block.text);
|
|
236
|
+
if (cleaned)
|
|
237
|
+
parts.push(cleaned);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (parts.length === 0)
|
|
241
|
+
return null;
|
|
242
|
+
const merged = parts.join("\n\n");
|
|
243
|
+
if (isBootstrapTurn(merged, totalRaw))
|
|
244
|
+
return null;
|
|
245
|
+
return { role, text: merged };
|
|
246
|
+
}
|
|
247
|
+
function collectTaskEvents(entry, turnIndex, events) {
|
|
248
|
+
if (entry.type !== "message")
|
|
249
|
+
return;
|
|
250
|
+
const msg = entry.message;
|
|
251
|
+
if (!msg)
|
|
252
|
+
return;
|
|
253
|
+
if (msg.role === "bashExecution" && typeof msg.command === "string") {
|
|
254
|
+
pushTaskEvents(msg.command, entry.timestamp, turnIndex, events);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content))
|
|
258
|
+
return;
|
|
259
|
+
for (const block of msg.content) {
|
|
260
|
+
if (block.type !== "toolCall")
|
|
261
|
+
continue;
|
|
262
|
+
if (typeof block.name !== "string")
|
|
263
|
+
continue;
|
|
264
|
+
const toolName = block.name.toLowerCase();
|
|
265
|
+
if (toolName !== "bash" && toolName !== "shell")
|
|
266
|
+
continue;
|
|
267
|
+
const args = block.arguments;
|
|
268
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
269
|
+
continue;
|
|
270
|
+
const command = args.command;
|
|
271
|
+
if (typeof command !== "string")
|
|
272
|
+
continue;
|
|
273
|
+
pushTaskEvents(command, entry.timestamp, turnIndex, events);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function pushTaskEvents(command, timestamp, turnIndex, events) {
|
|
277
|
+
const parsedAll = parseTaskPyCommandsAll(command);
|
|
278
|
+
for (const parsed of parsedAll) {
|
|
279
|
+
const ev = {
|
|
280
|
+
action: parsed.action,
|
|
281
|
+
timestamp: timestamp ?? "",
|
|
282
|
+
turnIndex,
|
|
283
|
+
...(parsed.action === "create"
|
|
284
|
+
? { slug: parsed.slug }
|
|
285
|
+
: { taskDir: parsed.taskDir }),
|
|
286
|
+
};
|
|
287
|
+
events.push(ev);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=pi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.js","sourceRoot":"","sources":["../../../src/mem/adapters/pi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,OAAO,GACR,MAAM,sBAAsB,CAAC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I,QAAQ,KAAK,OAAO;YAAE,SAAS;QAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;QAC7B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,SAAS;QACvE,MAAM,OAAO,GAAI,IAA8B,CAAC,OAAO,CAAC;QACxD,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,SAAS;QAC1C,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CACrB,OAAe,EACf,SAA6B,EAC7B,SAAiB,EACjB,MAAqB;IAErB,MAAM,SAAS,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAClD,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,CAAC;QAC/B,MAAM,EAAE,GAAgB;YACtB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,SAAS,IAAI,EAAE;YAC1B,SAAS;YACT,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ;gBAC5B,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;gBACvB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;SACjC,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZCode (Zhipu) persisted-session reader.
|
|
3
|
+
*
|
|
4
|
+
* ZCode stores sessions in a SQLite database at `~/.zcode/cli/db/db.sqlite`
|
|
5
|
+
* (WAL mode). The three tables this adapter reads are:
|
|
6
|
+
*
|
|
7
|
+
* - `session` — id / title / directory (workspace cwd) / time_created /
|
|
8
|
+
* time_updated / task_type
|
|
9
|
+
* - `message` — id / session_id / time_created / data (JSON: {role, ...})
|
|
10
|
+
* - `part` — message_id / time_created / data (JSON: {type, text|tool, ...})
|
|
11
|
+
* plus compaction markers that replace earlier dialogue with
|
|
12
|
+
* a summary message.
|
|
13
|
+
*
|
|
14
|
+
* The older `~/.zcode/v2/sessions/*.json` layout is abandoned by current ZCode,
|
|
15
|
+
* and `~/.zcode/cli/rollout/*.jsonl` is a non-persistent model-IO stream that
|
|
16
|
+
* gets cleaned up periodically — neither is read here. SQLite is the single
|
|
17
|
+
* complete source of truth (see `docs-hlaia/06-...` for the investigation).
|
|
18
|
+
*
|
|
19
|
+
* SQLite access is via the zero-dependency parser in `internal/sqlite-readonly.ts`
|
|
20
|
+
* — `better-sqlite3` was rejected because its native build chain broke npm
|
|
21
|
+
* install on Windows for the OpenCode adapter.
|
|
22
|
+
*/
|
|
23
|
+
import type { DialogueTurn, MemFilter, MemSessionInfo, MemWarning, SearchHit, TaskPyEvent } from "../types.js";
|
|
24
|
+
interface ZcodeTextPart {
|
|
25
|
+
type?: string;
|
|
26
|
+
text?: string;
|
|
27
|
+
}
|
|
28
|
+
interface ZcodeToolPart {
|
|
29
|
+
type?: string;
|
|
30
|
+
tool?: string;
|
|
31
|
+
state?: {
|
|
32
|
+
input?: {
|
|
33
|
+
command?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare function prepareZcodeSessionStore(dbPath: string, warnings: MemWarning[]): void;
|
|
38
|
+
export declare function releaseZcodeSessionStore(): void;
|
|
39
|
+
export declare function zcodeListSessions(f: MemFilter, warnings?: MemWarning[]): MemSessionInfo[];
|
|
40
|
+
/**
|
|
41
|
+
* Build cleaned dialogue turns from a session's messages + parts. Each message
|
|
42
|
+
* is one turn; its text is the concatenation of its `text`-typed parts after
|
|
43
|
+
* injection-tag stripping. Messages with no surviving text are dropped.
|
|
44
|
+
*/
|
|
45
|
+
export declare function zcodeExtractDialogue(s: MemSessionInfo, warnings?: MemWarning[]): DialogueTurn[];
|
|
46
|
+
export declare function zcodeSearch(s: MemSessionInfo, kw: string, warnings?: MemWarning[]): SearchHit;
|
|
47
|
+
/**
|
|
48
|
+
* Single pass over messages + parts. Emits both the cleaned dialogue turns and
|
|
49
|
+
* the list of `task.py create|start` invocations found in `Bash` tool parts
|
|
50
|
+
* (`{type:"tool", tool:"Bash", state:{input:{command:"..."}}}`). `turnIndex`
|
|
51
|
+
* for each event is the turn count at the time the tool ran.
|
|
52
|
+
*
|
|
53
|
+
* Compaction: ZCode writes a summary message with a `compaction` part carrying
|
|
54
|
+
* `tail_start_id` / `compactBoundary`. The summarized messages remain in the
|
|
55
|
+
* database, so they stay in the turn pool and the summary message becomes a
|
|
56
|
+
* boundary marker — `task.py` boundaries from before a compaction keep pointing
|
|
57
|
+
* at turns that are still there.
|
|
58
|
+
*
|
|
59
|
+
* turnIndex note (differs slightly from claude/codex): in ZCode a message's
|
|
60
|
+
* text parts and tool parts are siblings within one message. This loop pushes
|
|
61
|
+
* the message's text turn *before* recording its tool events, so a tool event
|
|
62
|
+
* on message M has turnIndex = (turns including M's text). claude/codex
|
|
63
|
+
* instead record the event before pushing the text, so their turnIndex is one
|
|
64
|
+
* less. Both are internally self-consistent for brainstorm-window slicing
|
|
65
|
+
* (create and start use the same convention within a platform), so phase
|
|
66
|
+
* boundaries compute correctly. The ZCode ordering reflects real time order
|
|
67
|
+
* (the assistant writes, then the tool runs). Do not "align" this without also
|
|
68
|
+
* adjusting the test expectations.
|
|
69
|
+
*/
|
|
70
|
+
export declare function collectZcodeTurnsAndEvents(s: MemSessionInfo, warnings?: MemWarning[]): {
|
|
71
|
+
turns: DialogueTurn[];
|
|
72
|
+
events: TaskPyEvent[];
|
|
73
|
+
};
|
|
74
|
+
/** Re-exported so callers needing loose shapes can import from one place. */
|
|
75
|
+
export type { ZcodeTextPart, ZcodeToolPart };
|
|
76
|
+
//# sourceMappingURL=zcode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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