@threadbase-sh/scanner 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,269 @@
1
+ import { LoggerOptions, Logger } from 'pino';
2
+ export { Logger, LoggerOptions } from 'pino';
3
+
4
+ type MessageSender = "user" | "assistant";
5
+ type Include = "all" | "conversations" | "subagents" | "teammates";
6
+ type View = "flat" | "tree" | "grouped";
7
+ type SortOrder = "recent" | "oldest" | "messages-desc" | "messages-asc" | "alpha";
8
+ declare const VALID_SORT_ORDERS: SortOrder[];
9
+ interface Profile {
10
+ id: string;
11
+ label: string;
12
+ configDir: string;
13
+ enabled: boolean;
14
+ emoji?: string;
15
+ scanHistory?: boolean;
16
+ }
17
+ interface ContentTier {
18
+ name: string;
19
+ previewMax: number;
20
+ snippetMax: number;
21
+ }
22
+ interface MessageSnapshot {
23
+ text: string;
24
+ timestamp: string;
25
+ }
26
+ interface ConversationMeta {
27
+ id: string;
28
+ filePath: string;
29
+ sessionId: string;
30
+ sessionName: string;
31
+ projectPath: string;
32
+ projectName: string;
33
+ account: string;
34
+ timestamp: string;
35
+ messageCount: number;
36
+ lastMessageSender: MessageSender;
37
+ preview: string;
38
+ contentSnippet: string;
39
+ gitBranch: string | null;
40
+ model: string | null;
41
+ isSubagent: boolean;
42
+ parentSessionId: string | null;
43
+ isTeammate: boolean;
44
+ teamName: string | null;
45
+ toolNames: string[];
46
+ firstMessage: MessageSnapshot | null;
47
+ lastMessage: MessageSnapshot | null;
48
+ lastPrompt?: string;
49
+ }
50
+ interface TreeConversation extends ConversationMeta {
51
+ subagents: ConversationMeta[];
52
+ }
53
+ interface GroupedConversations {
54
+ [groupKey: string]: ConversationMeta[];
55
+ }
56
+ interface FileStatEntry {
57
+ mtimeMs: number;
58
+ size: number;
59
+ }
60
+ interface ScanOptions {
61
+ profiles?: Profile[];
62
+ tier?: string;
63
+ tiers?: Record<string, ContentTier>;
64
+ include?: Include;
65
+ view?: View;
66
+ sort?: SortOrder;
67
+ since?: string;
68
+ project?: string;
69
+ account?: string;
70
+ limit?: number;
71
+ offset?: number;
72
+ onProgress?: (scanned: number, total: number) => void;
73
+ onBatch?: (metas: ConversationMeta[]) => void;
74
+ /** Known file stats from a previous scan. Files whose (mtimeMs, size) match
75
+ * are skipped — the cached ConversationMeta is reused instead. */
76
+ statCache?: Map<string, {
77
+ stat: FileStatEntry;
78
+ meta: ConversationMeta;
79
+ }>;
80
+ }
81
+ interface ScanResult {
82
+ conversations: ConversationMeta[] | TreeConversation[] | GroupedConversations;
83
+ total: number;
84
+ scanned: number;
85
+ }
86
+ interface SearchOptions extends ScanOptions {
87
+ fields?: string[];
88
+ }
89
+ interface SearchMatch {
90
+ field: string;
91
+ snippet: string;
92
+ }
93
+ interface SearchResult {
94
+ meta: ConversationMeta;
95
+ score: number;
96
+ matches: SearchMatch[];
97
+ }
98
+ interface GetConversationOptions {
99
+ profiles?: Profile[];
100
+ }
101
+ interface GetConversationPageOptions {
102
+ beforeIndex?: number;
103
+ limit: number;
104
+ }
105
+ interface ConversationPage {
106
+ messages: ConversationMessage[];
107
+ total: number;
108
+ fromIndex: number;
109
+ }
110
+ interface SingleFilePage extends ConversationPage {
111
+ conversation: Conversation;
112
+ }
113
+ interface TurnDuration {
114
+ durationMs: number;
115
+ messageCount: number;
116
+ uuid?: string;
117
+ }
118
+ interface DeferredToolsDeltaAttachment {
119
+ type: "deferred_tools_delta";
120
+ addedNames: string[];
121
+ addedLines: unknown[];
122
+ removedNames: string[];
123
+ }
124
+ type AttachmentSidecar = DeferredToolsDeltaAttachment | {
125
+ type: string;
126
+ [key: string]: unknown;
127
+ };
128
+ interface ToolUseBlock {
129
+ id: string;
130
+ name: string;
131
+ input: Record<string, unknown>;
132
+ }
133
+ interface ToolResultBlock {
134
+ toolUseId: string;
135
+ type: "edit" | "write" | "read" | "bash" | "grep" | "glob" | "taskAgent" | "taskCreate" | "taskUpdate" | "generic";
136
+ content: Record<string, unknown>;
137
+ isError?: boolean;
138
+ }
139
+ interface TeamInfo {
140
+ teammateId: string;
141
+ summary?: string;
142
+ color?: string;
143
+ }
144
+ interface MessageMetadata {
145
+ model?: string;
146
+ stopReason?: string | null;
147
+ inputTokens?: number;
148
+ outputTokens?: number;
149
+ cacheReadTokens?: number;
150
+ cacheCreationTokens?: number;
151
+ gitBranch?: string;
152
+ version?: string;
153
+ toolUses?: string[];
154
+ toolUseBlocks?: ToolUseBlock[];
155
+ toolResults?: ToolResultBlock[];
156
+ teamName?: string;
157
+ teamInfo?: TeamInfo;
158
+ }
159
+ interface ConversationMessage {
160
+ role: MessageSender;
161
+ text: string;
162
+ timestamp: string;
163
+ uuid?: string;
164
+ metadata?: MessageMetadata;
165
+ isToolResult?: boolean;
166
+ isThinking?: boolean;
167
+ thinkingContent?: string;
168
+ thinkingSignature?: string;
169
+ parentUuid?: string | null;
170
+ requestId?: string;
171
+ promptId?: string;
172
+ isSidechain?: boolean;
173
+ permissionMode?: string;
174
+ hasImages?: boolean;
175
+ attachment?: AttachmentSidecar;
176
+ }
177
+ interface Conversation {
178
+ id: string;
179
+ filePath: string;
180
+ projectPath: string;
181
+ projectName: string;
182
+ sessionId: string;
183
+ sessionName: string;
184
+ messages: ConversationMessage[];
185
+ fullText: string;
186
+ timestamp: string;
187
+ messageCount: number;
188
+ account: string;
189
+ turnDurations?: TurnDuration[];
190
+ lastPrompt?: string;
191
+ }
192
+
193
+ declare function applySort(metas: ConversationMeta[], order: SortOrder): ConversationMeta[];
194
+ declare function applySinceFilter(metas: ConversationMeta[], since: string): ConversationMeta[];
195
+ declare function applyIncludeFilter(metas: ConversationMeta[], include: Include): ConversationMeta[];
196
+ declare function applyProjectFilter(metas: ConversationMeta[], project: string): ConversationMeta[];
197
+ declare function applyAccountFilter(metas: ConversationMeta[], account: string): ConversationMeta[];
198
+ declare function applyPagination<T>(items: T[], limit: number, offset: number): {
199
+ items: T[];
200
+ total: number;
201
+ };
202
+
203
+ declare function readGitBranch(projectPath: string): string | null;
204
+
205
+ declare class SearchIndexer {
206
+ private index;
207
+ private documents;
208
+ constructor();
209
+ private createIndex;
210
+ addDocument(meta: ConversationMeta): void;
211
+ buildIndex(metas: ConversationMeta[]): void;
212
+ search(query: string, options?: {
213
+ fields?: string[];
214
+ limit?: number;
215
+ }): SearchResult[];
216
+ private getRecent;
217
+ private generateMatches;
218
+ getDocumentCount(): number;
219
+ updateDocument(meta: ConversationMeta): void;
220
+ removeDocument(id: string): void;
221
+ clear(): void;
222
+ }
223
+
224
+ declare function createLogger(options?: LoggerOptions | Logger): Logger;
225
+ declare function setLogger(logger: Logger): void;
226
+ declare function getLogger(): Logger;
227
+
228
+ declare function resolveConfigDir(configDir: string): string;
229
+ declare function getProjectsDir(profile: Profile): string;
230
+ declare function detectDefaultProfile(): Promise<Profile>;
231
+ declare function loadProfiles(configPath: string): Promise<Profile[]>;
232
+ declare function saveProfiles(profiles: Profile[], configPath: string): Promise<void>;
233
+
234
+ declare class ConversationScanner {
235
+ private metadataCache;
236
+ private conversationLRU;
237
+ private sessionIdIndex;
238
+ private projects;
239
+ private indexer;
240
+ private lastTier;
241
+ constructor(options?: {
242
+ metadataCacheSize?: number;
243
+ conversationCacheSize?: number;
244
+ });
245
+ scan(options?: ScanOptions): Promise<ScanResult>;
246
+ search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
247
+ getConversation(id: string, _options?: GetConversationOptions): Promise<Conversation | null>;
248
+ getConversationPage(id: string, options: GetConversationPageOptions): Promise<ConversationPage | null>;
249
+ parseSingleFilePage(filePath: string, account: string | undefined, options: GetConversationPageOptions): Promise<SingleFilePage | null>;
250
+ refreshFile(filePath: string, account?: string): Promise<ConversationMeta | null>;
251
+ getMetadataCache(): Map<string, ConversationMeta>;
252
+ getProjects(): string[];
253
+ private resolveProfiles;
254
+ private transformView;
255
+ private toTree;
256
+ private toGrouped;
257
+ }
258
+
259
+ declare function cleanSystemTags(text: string): string;
260
+
261
+ declare const DEFAULT_TIERS: Record<string, ContentTier>;
262
+ declare function resolveTier(tierName: string, customTiers?: Record<string, ContentTier>): ContentTier;
263
+
264
+ declare function resetDefaultScanner(): void;
265
+ declare function scan(options?: ScanOptions, scanner?: ConversationScanner): Promise<ScanResult>;
266
+ declare function search(query: string, options?: SearchOptions, scanner?: ConversationScanner): Promise<SearchResult[]>;
267
+ declare function getConversation(id: string, options?: GetConversationOptions, scanner?: ConversationScanner): Promise<Conversation | null>;
268
+
269
+ export { type AttachmentSidecar, type ContentTier, type Conversation, type ConversationMessage, type ConversationMeta, type ConversationPage, ConversationScanner, DEFAULT_TIERS, type DeferredToolsDeltaAttachment, type FileStatEntry, type GetConversationOptions, type GetConversationPageOptions, type GroupedConversations, type Include, type MessageMetadata, type MessageSender, type MessageSnapshot, type Profile, type ScanOptions, type ScanResult, SearchIndexer, type SearchMatch, type SearchOptions, type SearchResult, type SingleFilePage, type SortOrder, type TeamInfo, type ToolResultBlock, type ToolUseBlock, type TreeConversation, type TurnDuration, VALID_SORT_ORDERS, type View, applyAccountFilter, applyIncludeFilter, applyPagination, applyProjectFilter, applySinceFilter, applySort, cleanSystemTags, createLogger, detectDefaultProfile, getConversation, getLogger, getProjectsDir, loadProfiles, readGitBranch, resetDefaultScanner, resolveConfigDir, resolveTier, saveProfiles, scan, search, setLogger };