@cyfsh/discovery 0.1.1 → 0.3.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/dist/index.d.ts +29 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +319 -49
- package/dist/index.js.map +1 -1
- package/dist/sanitizer.d.ts.map +1 -1
- package/dist/sanitizer.js +9 -4
- package/dist/sanitizer.js.map +1 -1
- package/dist/scanners/claude.d.ts +4 -1
- package/dist/scanners/claude.d.ts.map +1 -1
- package/dist/scanners/claude.js +90 -44
- package/dist/scanners/claude.js.map +1 -1
- package/dist/scanners/codebuddy.d.ts +4 -1
- package/dist/scanners/codebuddy.d.ts.map +1 -1
- package/dist/scanners/codebuddy.js +194 -52
- package/dist/scanners/codebuddy.js.map +1 -1
- package/dist/scanners/codex.d.ts +4 -1
- package/dist/scanners/codex.d.ts.map +1 -1
- package/dist/scanners/codex.js +112 -44
- package/dist/scanners/codex.js.map +1 -1
- package/dist/scanners/common.d.ts +79 -0
- package/dist/scanners/common.d.ts.map +1 -1
- package/dist/scanners/common.js +447 -20
- package/dist/scanners/common.js.map +1 -1
- package/dist/scanners/dsh.d.ts +5 -1
- package/dist/scanners/dsh.d.ts.map +1 -1
- package/dist/scanners/dsh.js +209 -85
- package/dist/scanners/dsh.js.map +1 -1
- package/dist/scanners/opencode.d.ts +10 -1
- package/dist/scanners/opencode.d.ts.map +1 -1
- package/dist/scanners/opencode.js +612 -293
- package/dist/scanners/opencode.js.map +1 -1
- package/package.json +2 -2
package/dist/scanners/claude.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as fsp from "node:fs/promises";
|
|
2
1
|
import * as os from "node:os";
|
|
3
2
|
import * as path from "node:path";
|
|
4
|
-
import { asNonEmptyString, decodeEncodedCwd, finalizeDiscoveredSession, isDirectory, isJsonRecord,
|
|
3
|
+
import { asNonEmptyString, decodeEncodedCwd, finalizeDiscoveredSession, finalizeSessionSummary, isDirectory, isJsonRecord, parseTimestampToIso, readJsonlDetailBounded, runWithConcurrency, sampleJsonlFileSummary, summarizeThinking, summarizeToolCall, walkFiles, } from "./common.js";
|
|
5
4
|
export function resolveClaudeStorageRoot(customRoot) {
|
|
6
5
|
if (customRoot && customRoot.trim().length > 0) {
|
|
7
6
|
return path.resolve(customRoot);
|
|
@@ -12,7 +11,7 @@ export function resolveClaudeStorageRoot(customRoot) {
|
|
|
12
11
|
}
|
|
13
12
|
return path.join(os.homedir(), ".claude", "projects");
|
|
14
13
|
}
|
|
15
|
-
function extractClaudeBlocks(content) {
|
|
14
|
+
function extractClaudeBlocks(content, includeDetails) {
|
|
16
15
|
const textParts = [];
|
|
17
16
|
const thinkingParts = [];
|
|
18
17
|
const toolCalls = [];
|
|
@@ -38,14 +37,16 @@ function extractClaudeBlocks(content) {
|
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
else if (blockType === "thinking" || blockType === "redacted_thinking") {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (includeDetails) {
|
|
41
|
+
const thought = asNonEmptyString(item.thinking) ?? asNonEmptyString(item.text);
|
|
42
|
+
if (thought) {
|
|
43
|
+
thinkingParts.push(thought);
|
|
44
|
+
}
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
else if (blockType === "tool_use") {
|
|
47
48
|
const name = asNonEmptyString(item.name) ?? "tool";
|
|
48
|
-
toolCalls.push(summarizeToolCall(name, item.input));
|
|
49
|
+
toolCalls.push(includeDetails ? summarizeToolCall(name, item.input) : { name, summary: name });
|
|
49
50
|
}
|
|
50
51
|
else if (blockType === "tool_result") {
|
|
51
52
|
toolResultCount += 1;
|
|
@@ -54,7 +55,7 @@ function extractClaudeBlocks(content) {
|
|
|
54
55
|
const hasOnlyToolResult = toolResultCount > 0 && textParts.length === 0 && toolCalls.length === 0;
|
|
55
56
|
return { textParts, thinkingParts, toolCalls, hasOnlyToolResult };
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
+
function extractClaudeSessionCore(records, filePath, fallbackCreatedAt, fallbackUpdatedAt, includeDetails) {
|
|
58
59
|
const fileSessionId = path.basename(filePath, ".jsonl");
|
|
59
60
|
const parentDirName = path.basename(path.dirname(filePath));
|
|
60
61
|
let rawSessionId = fileSessionId;
|
|
@@ -88,15 +89,17 @@ function parseClaudeSessionRecords(records, filePath, fallbackCreatedAt, fallbac
|
|
|
88
89
|
}
|
|
89
90
|
continue;
|
|
90
91
|
}
|
|
91
|
-
if (rec.isMeta === true
|
|
92
|
+
if (rec.isMeta === true ||
|
|
93
|
+
rec.isSidechain === true ||
|
|
94
|
+
rec.isCompactSummary === true) {
|
|
92
95
|
continue;
|
|
93
96
|
}
|
|
94
97
|
const nestedMsg = isJsonRecord(rec.message) ? rec.message : undefined;
|
|
95
98
|
const roleRaw = asNonEmptyString(nestedMsg?.role) ??
|
|
96
|
-
(recordType === "user" || recordType === "assistant"
|
|
99
|
+
(recordType === "user" || recordType === "assistant"
|
|
97
100
|
? recordType
|
|
98
101
|
: asNonEmptyString(rec.role));
|
|
99
|
-
if (roleRaw !== "user" && roleRaw !== "assistant"
|
|
102
|
+
if (roleRaw !== "user" && roleRaw !== "assistant") {
|
|
100
103
|
continue;
|
|
101
104
|
}
|
|
102
105
|
const msgModel = asNonEmptyString(nestedMsg?.model) ?? asNonEmptyString(rec.model);
|
|
@@ -104,19 +107,23 @@ function parseClaudeSessionRecords(records, filePath, fallbackCreatedAt, fallbac
|
|
|
104
107
|
model = msgModel;
|
|
105
108
|
}
|
|
106
109
|
const rawContent = nestedMsg ? nestedMsg.content : rec.content;
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
if (roleRaw === "user" &&
|
|
111
|
+
Array.isArray(rawContent) &&
|
|
112
|
+
rawContent.some((item) => isJsonRecord(item) && item.type === "tool_result")) {
|
|
109
113
|
continue;
|
|
110
114
|
}
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
|
|
115
|
+
const { textParts, thinkingParts, toolCalls, hasOnlyToolResult } = extractClaudeBlocks(rawContent, includeDetails);
|
|
116
|
+
if (hasOnlyToolResult) {
|
|
117
|
+
continue;
|
|
114
118
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
119
|
+
if (includeDetails) {
|
|
120
|
+
const directThinking = asNonEmptyString(rec.thinking) ?? asNonEmptyString(nestedMsg?.thinking);
|
|
121
|
+
if (directThinking) {
|
|
122
|
+
thinkingParts.push(directThinking);
|
|
123
|
+
}
|
|
118
124
|
}
|
|
119
|
-
|
|
125
|
+
const contentText = textParts.join("\n").trim();
|
|
126
|
+
if (!contentText && thinkingParts.length === 0 && toolCalls.length === 0) {
|
|
120
127
|
continue;
|
|
121
128
|
}
|
|
122
129
|
const timestamp = parseTimestampToIso(rec.timestamp ?? rec.createdAt ?? nestedMsg?.timestamp, fallbackUpdatedAt);
|
|
@@ -124,21 +131,23 @@ function parseClaudeSessionRecords(records, filePath, fallbackCreatedAt, fallbac
|
|
|
124
131
|
asNonEmptyString(nestedMsg?.id) ??
|
|
125
132
|
asNonEmptyString(rec.id) ??
|
|
126
133
|
`${rawSessionId}-msg-${idx + 1}`;
|
|
127
|
-
const thinkingSummary =
|
|
134
|
+
const thinkingSummary = includeDetails
|
|
135
|
+
? summarizeThinking(thinkingParts.join("\n"))
|
|
136
|
+
: undefined;
|
|
128
137
|
messages.push({
|
|
129
138
|
id: msgId,
|
|
130
139
|
role: roleRaw,
|
|
131
140
|
content: contentText,
|
|
132
141
|
timestamp,
|
|
133
142
|
...(thinkingSummary ? { thinkingSummary } : {}),
|
|
134
|
-
...(toolCalls.length > 0 ? { toolCalls } : {}),
|
|
143
|
+
...(includeDetails && toolCalls.length > 0 ? { toolCalls } : {}),
|
|
135
144
|
});
|
|
136
145
|
}
|
|
137
146
|
const workspacePath = explicitCwd ??
|
|
138
147
|
(parentDirName && parentDirName !== "projects"
|
|
139
148
|
? decodeEncodedCwd(parentDirName)
|
|
140
149
|
: "/unknown-workspace");
|
|
141
|
-
return
|
|
150
|
+
return {
|
|
142
151
|
engine: "claude-code",
|
|
143
152
|
rawSessionId,
|
|
144
153
|
explicitTitle,
|
|
@@ -149,9 +158,16 @@ function parseClaudeSessionRecords(records, filePath, fallbackCreatedAt, fallbac
|
|
|
149
158
|
fallbackUpdatedAt,
|
|
150
159
|
gitBranch,
|
|
151
160
|
model,
|
|
152
|
-
}
|
|
161
|
+
};
|
|
153
162
|
}
|
|
154
|
-
export async function
|
|
163
|
+
export async function readClaudeSessionDetail(filePath) {
|
|
164
|
+
const bounded = await readJsonlDetailBounded(filePath);
|
|
165
|
+
if (!bounded || bounded.records.length === 0) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return finalizeDiscoveredSession(extractClaudeSessionCore(bounded.records, filePath, bounded.createdAt, bounded.updatedAt, true));
|
|
169
|
+
}
|
|
170
|
+
export async function prepareClaudeScan(customRoot, cache) {
|
|
155
171
|
const storageRoot = resolveClaudeStorageRoot(customRoot);
|
|
156
172
|
const nestedProjectsDir = path.join(storageRoot, "projects");
|
|
157
173
|
const effectiveDir = (await isDirectory(nestedProjectsDir))
|
|
@@ -163,33 +179,63 @@ export async function scanClaudeSessions(customRoot) {
|
|
|
163
179
|
engine: "claude-code",
|
|
164
180
|
storageRoot,
|
|
165
181
|
storageDetected: false,
|
|
166
|
-
|
|
182
|
+
totalItems: 0,
|
|
183
|
+
runScan: async () => ({ summaries: [], cacheHits: 0 }),
|
|
167
184
|
};
|
|
168
185
|
}
|
|
169
186
|
const jsonlFiles = await walkFiles(effectiveDir, (_full, name) => name.endsWith(".jsonl") && !name.startsWith("agent-"), 4);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
187
|
+
return {
|
|
188
|
+
engine: "claude-code",
|
|
189
|
+
storageRoot,
|
|
190
|
+
storageDetected: true,
|
|
191
|
+
totalItems: jsonlFiles.length,
|
|
192
|
+
runScan: async (onItemDone) => {
|
|
193
|
+
const summaries = [];
|
|
194
|
+
let cacheHits = 0;
|
|
195
|
+
await runWithConcurrency(jsonlFiles, 16, async (filePath) => {
|
|
196
|
+
const { summary, fromCache } = await sampleJsonlFileSummary({
|
|
197
|
+
filePath,
|
|
198
|
+
cache,
|
|
199
|
+
parseSummaryFromRecords: (records, fp, createdAt, updatedAt) => finalizeSessionSummary(extractClaudeSessionCore(records, fp, createdAt, updatedAt, false)),
|
|
200
|
+
});
|
|
201
|
+
if (fromCache) {
|
|
202
|
+
cacheHits += 1;
|
|
203
|
+
}
|
|
204
|
+
if (summary) {
|
|
205
|
+
summaries.push(summary);
|
|
206
|
+
onItemDone(1);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
onItemDone(0);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return { summaries, cacheHits };
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export async function scanClaudeSessions(customRoot) {
|
|
217
|
+
const prepared = await prepareClaudeScan(customRoot, new Map());
|
|
218
|
+
if (!prepared.storageDetected) {
|
|
219
|
+
return {
|
|
220
|
+
engine: "claude-code",
|
|
221
|
+
storageRoot: prepared.storageRoot,
|
|
222
|
+
storageDetected: false,
|
|
223
|
+
sessions: [],
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const { summaries } = await prepared.runScan(() => undefined);
|
|
227
|
+
const details = [];
|
|
228
|
+
for (const s of summaries) {
|
|
229
|
+
const detail = await readClaudeSessionDetail(s.sourcePath);
|
|
230
|
+
if (detail) {
|
|
231
|
+
details.push(detail);
|
|
186
232
|
}
|
|
187
233
|
}
|
|
188
234
|
return {
|
|
189
235
|
engine: "claude-code",
|
|
190
|
-
storageRoot,
|
|
236
|
+
storageRoot: prepared.storageRoot,
|
|
191
237
|
storageDetected: true,
|
|
192
|
-
sessions,
|
|
238
|
+
sessions: details,
|
|
193
239
|
};
|
|
194
240
|
}
|
|
195
241
|
//# sourceMappingURL=claude.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/scanners/claude.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/scanners/claude.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAOlC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAIhB,yBAAyB,EACzB,sBAAsB,EACtB,WAAW,EACX,YAAY,EAEZ,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,GACV,MAAM,aAAa,CAAC;AAErB,MAAM,UAAU,wBAAwB,CAAC,UAAmB;IAC1D,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IACD,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAClE,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,mBAAmB,CAC1B,OAAgB,EAChB,cAAuB;IAOvB,MAAM,SAAS,GAAa,EAAE,CAAC;IAC/B,MAAM,aAAa,GAAa,EAAE,CAA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;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,UAAmB;IAC1D,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IAChE,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;QAC9B,OAAO;YACL,MAAM,EAAE,aAAa;YACrB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,eAAe,EAAE,KAAK;YACtB,QAAQ,EAAE,EAAE;SACb,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC9D,MAAM,OAAO,GAA8B,EAAE,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,MAAM,uBAAuB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO;QACL,MAAM,EAAE,aAAa;QACrB,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,eAAe,EAAE,IAAI;QACrB,QAAQ,EAAE,OAAO;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DiscoveredSessionDetail } from "@cyfsh/protocol";
|
|
2
|
+
import { type EnginePreparedScan, type EngineScanResult, type FileSummaryCache } from "./common.js";
|
|
2
3
|
export declare function resolveCodeBuddyStorageRoot(customRoot?: string): string;
|
|
4
|
+
export declare function readCodeBuddySessionDetail(filePath: string): Promise<DiscoveredSessionDetail | null>;
|
|
5
|
+
export declare function prepareCodeBuddyScan(customRoot: string | undefined, cache: FileSummaryCache): Promise<EnginePreparedScan>;
|
|
3
6
|
export declare function scanCodeBuddySessions(customRoot?: string): Promise<EngineScanResult>;
|
|
4
7
|
//# sourceMappingURL=codebuddy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codebuddy.d.ts","sourceRoot":"","sources":["../../src/scanners/codebuddy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codebuddy.d.ts","sourceRoot":"","sources":["../../src/scanners/codebuddy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,uBAAuB,EAExB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAatB,MAAM,aAAa,CAAC;AAErB,wBAAgB,2BAA2B,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CASvE;AAmUD,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAczC;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,kBAAkB,CAAC,CAyE7B;AAED,wBAAsB,qBAAqB,CACzC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAwB3B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as fsp from "node:fs/promises";
|
|
2
1
|
import * as os from "node:os";
|
|
3
2
|
import * as path from "node:path";
|
|
4
|
-
import { asNonEmptyString, decodeEncodedCwd, finalizeDiscoveredSession, isDirectory, isJsonRecord,
|
|
3
|
+
import { asNonEmptyString, decodeEncodedCwd, finalizeDiscoveredSession, finalizeSessionSummary, isDirectory, isJsonRecord, parseTimestampToIso, readJsonlDetailBounded, runWithConcurrency, sampleJsonlFileSummary, summarizeThinking, summarizeToolCall, walkFiles, } from "./common.js";
|
|
5
4
|
export function resolveCodeBuddyStorageRoot(customRoot) {
|
|
6
5
|
if (customRoot && customRoot.trim().length > 0) {
|
|
7
6
|
return path.resolve(customRoot);
|
|
@@ -12,14 +11,35 @@ export function resolveCodeBuddyStorageRoot(customRoot) {
|
|
|
12
11
|
}
|
|
13
12
|
return path.join(os.homedir(), ".codebuddy", "projects");
|
|
14
13
|
}
|
|
15
|
-
function
|
|
14
|
+
function extractReasoningRecordText(rec) {
|
|
15
|
+
const parts = [];
|
|
16
|
+
for (const key of ["rawContent", "summary", "content"]) {
|
|
17
|
+
const arr = rec[key];
|
|
18
|
+
if (Array.isArray(arr)) {
|
|
19
|
+
for (const item of arr) {
|
|
20
|
+
if (!isJsonRecord(item))
|
|
21
|
+
continue;
|
|
22
|
+
const t = asNonEmptyString(item.text) ?? asNonEmptyString(item.thinking);
|
|
23
|
+
if (t)
|
|
24
|
+
parts.push(t);
|
|
25
|
+
}
|
|
26
|
+
if (parts.length > 0) {
|
|
27
|
+
return parts.join("\n").trim();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return asNonEmptyString(rec.text) ?? "";
|
|
32
|
+
}
|
|
33
|
+
function extractCodeBuddyContent(rawContent, container, includeDetails) {
|
|
16
34
|
const textParts = [];
|
|
17
35
|
const thinkingParts = [];
|
|
18
36
|
const toolCalls = [];
|
|
19
|
-
|
|
20
|
-
asNonEmptyString(container.
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
if (includeDetails) {
|
|
38
|
+
const directThinking = asNonEmptyString(container.reasoning_content) ??
|
|
39
|
+
asNonEmptyString(container.thinking);
|
|
40
|
+
if (directThinking) {
|
|
41
|
+
thinkingParts.push(directThinking);
|
|
42
|
+
}
|
|
23
43
|
}
|
|
24
44
|
let toolResultCount = 0;
|
|
25
45
|
if (typeof rawContent === "string") {
|
|
@@ -33,21 +53,34 @@ function extractCodeBuddyContent(rawContent, container) {
|
|
|
33
53
|
continue;
|
|
34
54
|
}
|
|
35
55
|
const bType = asNonEmptyString(block.type);
|
|
36
|
-
if (bType === "text" ||
|
|
56
|
+
if (bType === "text" ||
|
|
57
|
+
bType === "input_text" ||
|
|
58
|
+
bType === "output_text" ||
|
|
59
|
+
!bType) {
|
|
37
60
|
const txt = asNonEmptyString(block.text) ?? asNonEmptyString(block.content);
|
|
38
61
|
if (txt) {
|
|
62
|
+
// Skip CodeBuddy auto-injected <system-reminder data-role="memory"> blocks
|
|
63
|
+
if (txt.trimStart().startsWith("<system-reminder") && txt.trimEnd().endsWith("</system-reminder>")) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
39
66
|
textParts.push(txt);
|
|
40
67
|
}
|
|
41
68
|
}
|
|
42
|
-
else if (bType === "thinking" ||
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
else if (bType === "thinking" ||
|
|
70
|
+
bType === "reasoning" ||
|
|
71
|
+
bType === "reasoning_text") {
|
|
72
|
+
if (includeDetails) {
|
|
73
|
+
const th = asNonEmptyString(block.thinking) ?? asNonEmptyString(block.text);
|
|
74
|
+
if (th) {
|
|
75
|
+
thinkingParts.push(th);
|
|
76
|
+
}
|
|
46
77
|
}
|
|
47
78
|
}
|
|
48
79
|
else if (bType === "tool_use" || bType === "tool_call") {
|
|
49
80
|
const name = asNonEmptyString(block.name) ?? "tool";
|
|
50
|
-
toolCalls.push(
|
|
81
|
+
toolCalls.push(includeDetails
|
|
82
|
+
? summarizeToolCall(name, block.input ?? block.arguments)
|
|
83
|
+
: { name, summary: name });
|
|
51
84
|
}
|
|
52
85
|
else if (bType === "tool_result") {
|
|
53
86
|
toolResultCount += 1;
|
|
@@ -63,11 +96,15 @@ function extractCodeBuddyContent(rawContent, container) {
|
|
|
63
96
|
}
|
|
64
97
|
if (isJsonRecord(item.function)) {
|
|
65
98
|
const fnName = asNonEmptyString(item.function.name) ?? "tool";
|
|
66
|
-
toolCalls.push(
|
|
99
|
+
toolCalls.push(includeDetails
|
|
100
|
+
? summarizeToolCall(fnName, item.function.arguments)
|
|
101
|
+
: { name: fnName, summary: fnName });
|
|
67
102
|
}
|
|
68
103
|
else {
|
|
69
104
|
const name = asNonEmptyString(item.name) ?? "tool";
|
|
70
|
-
toolCalls.push(
|
|
105
|
+
toolCalls.push(includeDetails
|
|
106
|
+
? summarizeToolCall(name, item.input ?? item.arguments ?? item.args)
|
|
107
|
+
: { name, summary: name });
|
|
71
108
|
}
|
|
72
109
|
}
|
|
73
110
|
}
|
|
@@ -79,7 +116,7 @@ function extractCodeBuddyContent(rawContent, container) {
|
|
|
79
116
|
isOnlyToolResult,
|
|
80
117
|
};
|
|
81
118
|
}
|
|
82
|
-
function
|
|
119
|
+
function extractCodeBuddySessionCore(records, filePath, fallbackCreatedAt, fallbackUpdatedAt, includeDetails) {
|
|
83
120
|
const fileSessionId = path.basename(filePath, ".jsonl");
|
|
84
121
|
const parentDirName = path.basename(path.dirname(filePath));
|
|
85
122
|
let rawSessionId = fileSessionId;
|
|
@@ -93,6 +130,9 @@ function parseCodeBuddySessionRecords(records, filePath, fallbackCreatedAt, fall
|
|
|
93
130
|
if (!rec) {
|
|
94
131
|
continue;
|
|
95
132
|
}
|
|
133
|
+
if (rec.isSidechain === true) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
96
136
|
const sId = asNonEmptyString(rec.sessionId) ??
|
|
97
137
|
asNonEmptyString(rec.session_id);
|
|
98
138
|
if (sId) {
|
|
@@ -112,6 +152,16 @@ function parseCodeBuddySessionRecords(records, filePath, fallbackCreatedAt, fall
|
|
|
112
152
|
gitBranch = lineBranch;
|
|
113
153
|
}
|
|
114
154
|
const recType = asNonEmptyString(rec.type);
|
|
155
|
+
if (recType === "custom-title" ||
|
|
156
|
+
recType === "session-title" ||
|
|
157
|
+
recType === "ai-title") {
|
|
158
|
+
explicitTitle =
|
|
159
|
+
asNonEmptyString(rec.customTitle) ??
|
|
160
|
+
asNonEmptyString(rec.aiTitle) ??
|
|
161
|
+
asNonEmptyString(rec.title) ??
|
|
162
|
+
explicitTitle;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
115
165
|
if (recType === "summary" || recType === "session_meta" || recType === "meta") {
|
|
116
166
|
explicitTitle =
|
|
117
167
|
asNonEmptyString(rec.summary) ??
|
|
@@ -127,6 +177,43 @@ function parseCodeBuddySessionRecords(records, filePath, fallbackCreatedAt, fall
|
|
|
127
177
|
}
|
|
128
178
|
continue;
|
|
129
179
|
}
|
|
180
|
+
const provData = isJsonRecord(rec.providerData) ? rec.providerData : undefined;
|
|
181
|
+
const provModel = provData ? asNonEmptyString(provData.model) : undefined;
|
|
182
|
+
if (provModel) {
|
|
183
|
+
model = provModel;
|
|
184
|
+
}
|
|
185
|
+
if (recType === "reasoning") {
|
|
186
|
+
if (includeDetails) {
|
|
187
|
+
const rText = extractReasoningRecordText(rec);
|
|
188
|
+
const thinkingSummary = summarizeThinking(rText);
|
|
189
|
+
if (thinkingSummary) {
|
|
190
|
+
const timestamp = parseTimestampToIso(rec.timestamp, fallbackUpdatedAt);
|
|
191
|
+
messages.push({
|
|
192
|
+
id: asNonEmptyString(rec.id) ?? `${rawSessionId}-cb-rsn-${idx + 1}`,
|
|
193
|
+
role: "assistant",
|
|
194
|
+
content: "",
|
|
195
|
+
timestamp,
|
|
196
|
+
thinkingSummary,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (recType === "function_call" || recType === "tool_use") {
|
|
203
|
+
if (includeDetails) {
|
|
204
|
+
const fnName = asNonEmptyString(rec.name) ?? "tool";
|
|
205
|
+
const tc = summarizeToolCall(fnName, rec.arguments ?? rec.input);
|
|
206
|
+
const timestamp = parseTimestampToIso(rec.timestamp, fallbackUpdatedAt);
|
|
207
|
+
messages.push({
|
|
208
|
+
id: asNonEmptyString(rec.id) ?? `${rawSessionId}-cb-fn-${idx + 1}`,
|
|
209
|
+
role: "assistant",
|
|
210
|
+
content: "",
|
|
211
|
+
timestamp,
|
|
212
|
+
toolCalls: [tc],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
130
217
|
const nestedMsg = isJsonRecord(rec.message) ? rec.message : undefined;
|
|
131
218
|
const container = nestedMsg ?? rec;
|
|
132
219
|
const role = asNonEmptyString(container.role) ??
|
|
@@ -140,19 +227,16 @@ function parseCodeBuddySessionRecords(records, filePath, fallbackCreatedAt, fall
|
|
|
140
227
|
if (msgModel) {
|
|
141
228
|
model = msgModel;
|
|
142
229
|
}
|
|
143
|
-
const { text, thinking, toolCalls, isOnlyToolResult } = extractCodeBuddyContent(container.content ?? rec.content, container);
|
|
230
|
+
const { text, thinking, toolCalls, isOnlyToolResult } = extractCodeBuddyContent(container.content ?? rec.content, container, includeDetails);
|
|
144
231
|
if (isOnlyToolResult) {
|
|
145
232
|
continue;
|
|
146
233
|
}
|
|
147
|
-
|
|
148
|
-
if (!finalContent && toolCalls.length
|
|
149
|
-
finalContent = `[调用工具: ${toolCalls.map((t) => t.name).join(", ")}]`;
|
|
150
|
-
}
|
|
151
|
-
if (!finalContent) {
|
|
234
|
+
const finalContent = text;
|
|
235
|
+
if (!finalContent && !thinking && toolCalls.length === 0) {
|
|
152
236
|
continue;
|
|
153
237
|
}
|
|
154
238
|
const timestamp = parseTimestampToIso(rec.timestamp ?? rec.createdAt ?? container.timestamp, fallbackUpdatedAt);
|
|
155
|
-
const thinkingSummary = summarizeThinking(thinking);
|
|
239
|
+
const thinkingSummary = includeDetails ? summarizeThinking(thinking) : undefined;
|
|
156
240
|
const msgId = asNonEmptyString(rec.uuid) ??
|
|
157
241
|
asNonEmptyString(container.id) ??
|
|
158
242
|
asNonEmptyString(rec.id) ??
|
|
@@ -163,14 +247,14 @@ function parseCodeBuddySessionRecords(records, filePath, fallbackCreatedAt, fall
|
|
|
163
247
|
content: finalContent,
|
|
164
248
|
timestamp,
|
|
165
249
|
...(thinkingSummary ? { thinkingSummary } : {}),
|
|
166
|
-
...(toolCalls.length > 0 ? { toolCalls } : {}),
|
|
250
|
+
...(includeDetails && toolCalls.length > 0 ? { toolCalls } : {}),
|
|
167
251
|
});
|
|
168
252
|
}
|
|
169
253
|
const workspacePath = explicitCwd ??
|
|
170
254
|
(parentDirName && parentDirName !== "projects"
|
|
171
255
|
? decodeEncodedCwd(parentDirName)
|
|
172
256
|
: "/unknown-workspace");
|
|
173
|
-
return
|
|
257
|
+
return {
|
|
174
258
|
engine: "codebuddy",
|
|
175
259
|
rawSessionId,
|
|
176
260
|
explicitTitle,
|
|
@@ -181,47 +265,105 @@ function parseCodeBuddySessionRecords(records, filePath, fallbackCreatedAt, fall
|
|
|
181
265
|
fallbackUpdatedAt,
|
|
182
266
|
gitBranch,
|
|
183
267
|
model,
|
|
184
|
-
}
|
|
268
|
+
};
|
|
185
269
|
}
|
|
186
|
-
export async function
|
|
270
|
+
export async function readCodeBuddySessionDetail(filePath) {
|
|
271
|
+
const bounded = await readJsonlDetailBounded(filePath);
|
|
272
|
+
if (!bounded || bounded.records.length === 0) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
return finalizeDiscoveredSession(extractCodeBuddySessionCore(bounded.records, filePath, bounded.createdAt, bounded.updatedAt, true));
|
|
276
|
+
}
|
|
277
|
+
export async function prepareCodeBuddyScan(customRoot, cache) {
|
|
187
278
|
const storageRoot = resolveCodeBuddyStorageRoot(customRoot);
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
279
|
+
const candidateDirs = [];
|
|
280
|
+
if (customRoot && customRoot.trim().length > 0) {
|
|
281
|
+
const nestedProjectsDir = path.join(storageRoot, "projects");
|
|
282
|
+
const effectiveDir = (await isDirectory(nestedProjectsDir))
|
|
283
|
+
? nestedProjectsDir
|
|
284
|
+
: storageRoot;
|
|
285
|
+
if (await isDirectory(effectiveDir)) {
|
|
286
|
+
candidateDirs.push(effectiveDir);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
// CodeBuddy CLI & WorkBuddy Desktop share the exact same kernel & transcript format
|
|
291
|
+
const workbuddyRoot = path.join(os.homedir(), ".workbuddy", "projects");
|
|
292
|
+
for (const dir of [storageRoot, workbuddyRoot]) {
|
|
293
|
+
if (await isDirectory(dir)) {
|
|
294
|
+
candidateDirs.push(dir);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (candidateDirs.length === 0) {
|
|
194
299
|
return {
|
|
195
300
|
engine: "codebuddy",
|
|
196
301
|
storageRoot,
|
|
197
302
|
storageDetected: false,
|
|
303
|
+
totalItems: 0,
|
|
304
|
+
runScan: async () => ({ summaries: [], cacheHits: 0 }),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
const allJsonlFiles = [];
|
|
308
|
+
for (const dir of candidateDirs) {
|
|
309
|
+
const found = await walkFiles(dir, (_full, name) => name.endsWith(".jsonl"), 4);
|
|
310
|
+
allJsonlFiles.push(...found);
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
engine: "codebuddy",
|
|
314
|
+
storageRoot,
|
|
315
|
+
storageDetected: true,
|
|
316
|
+
totalItems: allJsonlFiles.length,
|
|
317
|
+
runScan: async (onItemDone) => {
|
|
318
|
+
const byId = new Map();
|
|
319
|
+
let cacheHits = 0;
|
|
320
|
+
await runWithConcurrency(allJsonlFiles, 16, async (filePath) => {
|
|
321
|
+
const { summary, fromCache } = await sampleJsonlFileSummary({
|
|
322
|
+
filePath,
|
|
323
|
+
cache,
|
|
324
|
+
parseSummaryFromRecords: (records, fp, createdAt, updatedAt) => finalizeSessionSummary(extractCodeBuddySessionCore(records, fp, createdAt, updatedAt, false)),
|
|
325
|
+
});
|
|
326
|
+
if (fromCache) {
|
|
327
|
+
cacheHits += 1;
|
|
328
|
+
}
|
|
329
|
+
if (summary) {
|
|
330
|
+
const existing = byId.get(summary.id);
|
|
331
|
+
if (!existing || Date.parse(summary.updatedAt) > Date.parse(existing.updatedAt)) {
|
|
332
|
+
byId.set(summary.id, summary);
|
|
333
|
+
}
|
|
334
|
+
onItemDone(1);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
onItemDone(0);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return { summaries: Array.from(byId.values()), cacheHits };
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
export async function scanCodeBuddySessions(customRoot) {
|
|
345
|
+
const prepared = await prepareCodeBuddyScan(customRoot, new Map());
|
|
346
|
+
if (!prepared.storageDetected) {
|
|
347
|
+
return {
|
|
348
|
+
engine: "codebuddy",
|
|
349
|
+
storageRoot: prepared.storageRoot,
|
|
350
|
+
storageDetected: false,
|
|
198
351
|
sessions: [],
|
|
199
352
|
};
|
|
200
353
|
}
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
for (const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (records.length === 0) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
const { createdAt, updatedAt } = await safeStatDates(filePath);
|
|
211
|
-
const parsed = parseCodeBuddySessionRecords(records, filePath, createdAt, updatedAt);
|
|
212
|
-
if (parsed) {
|
|
213
|
-
sessions.push(parsed);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
// Skip unreadable CodeBuddy session files gracefully
|
|
354
|
+
const { summaries } = await prepared.runScan(() => undefined);
|
|
355
|
+
const details = [];
|
|
356
|
+
for (const s of summaries) {
|
|
357
|
+
const detail = await readCodeBuddySessionDetail(s.sourcePath);
|
|
358
|
+
if (detail) {
|
|
359
|
+
details.push(detail);
|
|
218
360
|
}
|
|
219
361
|
}
|
|
220
362
|
return {
|
|
221
363
|
engine: "codebuddy",
|
|
222
|
-
storageRoot,
|
|
364
|
+
storageRoot: prepared.storageRoot,
|
|
223
365
|
storageDetected: true,
|
|
224
|
-
sessions,
|
|
366
|
+
sessions: details,
|
|
225
367
|
};
|
|
226
368
|
}
|
|
227
369
|
//# sourceMappingURL=codebuddy.js.map
|