@c3-oss/prosa 0.6.1 → 0.8.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 CHANGED
@@ -1,469 +1 @@
1
- import { Database } from 'better-sqlite3';
2
- import { Logger } from 'pino';
3
-
4
- type Db = Database;
5
-
6
- interface BundleManifest {
7
- version: 1;
8
- parser_version: string;
9
- schema_version: number;
10
- created_at: string;
11
- hash_alg: 'blake3';
12
- default_compression: 'zstd';
13
- }
14
- interface Bundle {
15
- path: string;
16
- db: Db;
17
- manifest: BundleManifest;
18
- paths: {
19
- db: string;
20
- manifest: string;
21
- objects: string;
22
- rawSources: string;
23
- search: string;
24
- tantivy: string;
25
- exports: string;
26
- parquet: string;
27
- lock: string;
28
- };
29
- }
30
- declare function defaultBundlePath(): string;
31
- /**
32
- * Create a fresh bundle at `rootPath`. Fails if the directory already contains
33
- * a manifest (use openBundle for that case).
34
- */
35
- declare function initBundle(rootPath: string): Promise<Bundle>;
36
- /**
37
- * Open an existing bundle. Applies pending migrations if the schema is older
38
- * than the current code expects.
39
- */
40
- declare function openBundle(rootPath: string): Promise<Bundle>;
41
- /**
42
- * Open an existing bundle or transparently initialize one if the store path is
43
- * missing or has not been initialized yet.
44
- */
45
- declare function openOrInitBundle(rootPath: string): Promise<Bundle>;
46
- declare function closeBundle(bundle: Bundle): void;
47
-
48
- declare function runMigrations(db: Db): {
49
- applied: number[];
50
- };
51
- declare function currentSchemaVersion(db: Db): number;
52
-
53
- declare const PROSA_PARSER_VERSION = "0.1.0";
54
- declare const PROSA_SCHEMA_VERSION = 4;
55
-
56
- type Compression = 'zstd' | 'none';
57
-
58
- type ObjectId = string;
59
- interface ObjectMeta {
60
- object_id: ObjectId;
61
- hash_alg: 'blake3';
62
- hash: string;
63
- size_bytes: number;
64
- compressed_size_bytes: number | null;
65
- compression: Compression;
66
- mime_type: string | null;
67
- encoding: string | null;
68
- storage_path: string;
69
- created_at: string;
70
- }
71
- interface PutOptions {
72
- mimeType?: string;
73
- encoding?: string;
74
- }
75
- /**
76
- * Store raw bytes in the CAS. Returns the object_id. Idempotent: if the same
77
- * content already exists, returns the existing object_id without rewriting.
78
- *
79
- * Bytes are compressed with zstd when worth it (see compress.ts threshold).
80
- * The on-disk path is `<bundle>/objects/blake3/ab/cd/<hash>.zst`.
81
- */
82
- declare function putBytes(bundle: Bundle, bytes: Uint8Array, options?: PutOptions): Promise<ObjectId>;
83
- declare function putText(bundle: Bundle, text: string, options?: {
84
- mimeType?: string;
85
- }): Promise<ObjectId>;
86
- declare function putJson(bundle: Bundle, value: unknown): Promise<ObjectId>;
87
- declare function getBytes(bundle: Bundle, objectId: ObjectId): Promise<Buffer>;
88
- declare function getText(bundle: Bundle, objectId: ObjectId): Promise<string>;
89
- declare function getJson<T = unknown>(bundle: Bundle, objectId: ObjectId): Promise<T>;
90
- declare function getObjectMeta(bundle: Bundle, objectId: ObjectId): ObjectMeta | null;
91
-
92
- declare const SOURCE_TOOLS: readonly ["cursor", "codex", "claude", "gemini"];
93
- type SourceTool = (typeof SOURCE_TOOLS)[number];
94
- type Confidence = 'high' | 'medium' | 'low';
95
- type MessageRole = 'system_prompt' | 'developer' | 'user' | 'assistant' | 'tool' | 'operational';
96
- type CanonicalToolType = 'shell' | 'read_file' | 'write_file' | 'edit_file' | 'search_file' | 'web_search' | 'mcp' | 'subagent' | 'patch' | 'other';
97
- type EdgeType = 'parent_of' | 'calls' | 'returns' | 'spawned' | 'contains' | 'produced' | 'consumed' | 'derived_from' | 'summarizes' | 'compacts' | 'same_as' | 'refers_to';
98
- type ToolCallStatus = 'started' | 'success' | 'error' | 'cancelled' | 'unknown';
99
- interface SessionRowFull {
100
- session_id: string;
101
- source_tool: SourceTool;
102
- source_session_id: string;
103
- project_id: string | null;
104
- parent_session_id: string | null;
105
- is_subagent: 0 | 1;
106
- agent_role: string | null;
107
- agent_nickname: string | null;
108
- title: string | null;
109
- summary: string | null;
110
- start_ts: string | null;
111
- end_ts: string | null;
112
- cwd_initial: string | null;
113
- git_branch_initial: string | null;
114
- model_first: string | null;
115
- model_last: string | null;
116
- status: string | null;
117
- timeline_confidence: Confidence;
118
- raw_record_id: string | null;
119
- }
120
-
121
- interface ImportBatch {
122
- batch_id: string;
123
- source_tool: SourceTool | null;
124
- parser_version: string;
125
- paths: string[];
126
- started_at: string;
127
- finished_at?: string;
128
- }
129
- interface ImportCounts {
130
- source_files_seen: number;
131
- source_files_imported: number;
132
- source_files_skipped: number;
133
- raw_records: number;
134
- sessions: number;
135
- turns: number;
136
- events: number;
137
- messages: number;
138
- content_blocks: number;
139
- tool_calls: number;
140
- tool_results: number;
141
- artifacts: number;
142
- edges: number;
143
- errors: number;
144
- }
145
- declare function emptyCounts(): ImportCounts;
146
- declare function startBatch(bundle: Bundle, sourceTool: SourceTool | null, paths: string[]): ImportBatch;
147
- declare function finishBatch(bundle: Bundle, batch: ImportBatch, counts: ImportCounts, status: 'completed' | 'failed'): void;
148
- declare function recordError(bundle: Bundle, batchId: string, args: {
149
- sourceFileId?: string | null;
150
- rawRecordId?: string | null;
151
- kind: string;
152
- message: string;
153
- payload?: unknown;
154
- }): Promise<void>;
155
-
156
- interface SourceFileRow {
157
- source_file_id: string;
158
- source_tool: SourceTool;
159
- path: string;
160
- file_kind: string;
161
- size_bytes: number;
162
- mtime: string | null;
163
- content_hash: string;
164
- object_id: string | null;
165
- discovered_at: string;
166
- workspace_hint: string | null;
167
- }
168
- interface RegisterResult {
169
- row: SourceFileRow;
170
- alreadyKnown: boolean;
171
- }
172
- /**
173
- * Idempotent registration of a source file. The natural key is
174
- * (source_tool, path, size, mtime, content_hash). If a row with the same
175
- * tuple already exists we return it untouched and the caller can skip
176
- * re-importing. Otherwise we insert a new row.
177
- *
178
- * This is the cheapest form of idempotency: re-running `prosa compile` over
179
- * the same Codex tree is a no-op (no rehash unless the file changed).
180
- */
181
- declare function registerSourceFile(bundle: Bundle, args: {
182
- sourceTool: SourceTool;
183
- absolutePath: string;
184
- fileKind: string;
185
- workspaceHint?: string | null;
186
- }): Promise<RegisterResult>;
187
-
188
- interface SessionListFilters {
189
- sourceTool?: SourceTool;
190
- sinceIso?: string;
191
- untilIso?: string;
192
- limit?: number;
193
- }
194
- interface SessionRow {
195
- session_id: string;
196
- source_tool: SourceTool;
197
- source_session_id: string;
198
- parent_session_id: string | null;
199
- is_subagent: 0 | 1;
200
- title: string | null;
201
- start_ts: string | null;
202
- end_ts: string | null;
203
- cwd_initial: string | null;
204
- git_branch_initial: string | null;
205
- model_first: string | null;
206
- model_last: string | null;
207
- status: string | null;
208
- timeline_confidence: Confidence;
209
- message_count: number;
210
- tool_call_count: number;
211
- }
212
- declare function listSessions(bundle: Bundle, filters?: SessionListFilters): SessionRow[];
213
- declare function countSessions(bundle: Bundle, filters?: SessionListFilters): number;
214
- interface SessionDetailEvent {
215
- ordinal: number;
216
- timestamp: string | null;
217
- event_type: string;
218
- source_type: string | null;
219
- subtype: string | null;
220
- actor: string | null;
221
- message_id: string | null;
222
- role: string | null;
223
- tool_name: string | null;
224
- is_error: 0 | 1 | null;
225
- preview: string | null;
226
- }
227
- interface SessionDetail {
228
- session: SessionRow;
229
- events: SessionDetailEvent[];
230
- }
231
- declare function getSession(bundle: Bundle, sessionId: string): SessionDetail | null;
232
-
233
- type SearchEngine = 'fts5' | 'tantivy';
234
- interface SearchIndexStatus {
235
- engine: SearchEngine;
236
- status: 'missing' | 'ready' | 'stale' | 'building' | 'failed';
237
- source_doc_count: number;
238
- indexed_doc_count: number;
239
- updated_at: string;
240
- error_message: string | null;
241
- last_indexed_rowid: number | null;
242
- schema_fingerprint: string | null;
243
- }
244
- declare function enableFts5Triggers(bundle: Bundle): void;
245
- declare function disableFts5Triggers(bundle: Bundle): void;
246
- declare function getSearchIndexStatuses(bundle: Bundle): SearchIndexStatus[];
247
- declare function getSearchIndexStatus(bundle: Bundle, engine: SearchEngine): SearchIndexStatus | null;
248
- declare function markIndexesAfterImport(bundle: Bundle, options: {
249
- changed: boolean;
250
- }): void;
251
- declare function rebuildFts5Index(bundle: Bundle): SearchIndexStatus;
252
- interface RebuildTantivyOptions {
253
- /**
254
- * Force a full re-index even when an incremental run would be valid.
255
- * Surfaced by the `--overwrite` flag on `prosa index tantivy` and on
256
- * `prosa compile`.
257
- */
258
- overwrite?: boolean;
259
- }
260
- declare function rebuildTantivyIndex(bundle: Bundle, options?: RebuildTantivyOptions): Promise<SearchIndexStatus>;
261
-
262
- interface SearchHit {
263
- doc_id: string;
264
- entity_type: string;
265
- entity_id: string;
266
- session_id: string | null;
267
- timestamp: string | null;
268
- role: string | null;
269
- tool_name: string | null;
270
- field_kind: string;
271
- snippet: string;
272
- }
273
- interface SearchOptions {
274
- query: string;
275
- limit?: number;
276
- engine?: SearchEngine;
277
- /**
278
- * When true, pass `query` straight to FTS5 (MATCH expression). When false
279
- * (default), each whitespace-delimited token is wrapped in double quotes so
280
- * punctuation like `package.json` doesn't trip the FTS5 parser. Set true if
281
- * you want to use FTS5 operators like `OR`, `NEAR`, prefixes, etc.
282
- */
283
- raw?: boolean;
284
- }
285
- /**
286
- * FTS5 search over messages, tool calls and tool outputs. Caller passes a
287
- * raw FTS5 MATCH query. We project a snippet around the hit and join with
288
- * search_docs to recover entity metadata.
289
- */
290
- declare function searchFullText(bundle: Bundle, options: SearchOptions): SearchHit[];
291
-
292
- type CompileLogger = Pick<Logger, 'child' | 'debug' | 'error' | 'info' | 'warn'>;
293
- interface CompileOptions {
294
- logger?: CompileLogger;
295
- }
296
-
297
- interface CompileResult$4 {
298
- batch: ImportBatch;
299
- counts: ImportCounts;
300
- }
301
- interface CompileProviderConfig {
302
- name: SourceTool;
303
- description: string;
304
- pathHelp: string;
305
- defaultSessionsPath: () => string;
306
- compile: (bundle: Bundle, root: string, options?: CompileOptions) => Promise<CompileResult$4>;
307
- }
308
- interface ProviderCompileSummary {
309
- source: SourceTool;
310
- sourcePath: string;
311
- batchId: string;
312
- batch: ImportBatch;
313
- counts: ImportCounts;
314
- }
315
- interface TantivyCompileSummary {
316
- indexedDocCount: number;
317
- }
318
- interface CompileImportSummary {
319
- providers: ProviderCompileSummary[];
320
- importedAny: boolean;
321
- tantivy: TantivyCompileSummary | null;
322
- tantivyError: string | null;
323
- fts5Error: string | null;
324
- }
325
- interface ParquetCompileSummary {
326
- outDir: string;
327
- manifestPath: string;
328
- tableCount: number;
329
- files: Record<string, string>;
330
- counts: Record<string, number>;
331
- }
332
- declare const COMPILE_PROVIDERS: CompileProviderConfig[];
333
- declare function getCompileProvider(source: SourceTool): CompileProviderConfig;
334
- declare function resolveCompilePath(p: string): string;
335
- declare function runCompileImports(options: {
336
- bundle: Bundle;
337
- providers: CompileProviderConfig[];
338
- sessionsPath?: string;
339
- /**
340
- * Force a full rebuild of derived indexes after import. Tantivy is the
341
- * only sidecar with an incremental path today, so this currently flips
342
- * Tantivy to a from-scratch rebuild; FTS5 and Parquet are always
343
- * full-rewrite. Surfaced by `prosa compile … --overwrite`.
344
- */
345
- overwrite?: boolean;
346
- logger?: CompileLogger;
347
- onProviderComplete?: (summary: ProviderCompileSummary) => void;
348
- onTantivyComplete?: (summary: TantivyCompileSummary) => void;
349
- }): Promise<CompileImportSummary>;
350
- declare function exportCompileParquet(options: {
351
- storePath: string;
352
- logger?: CompileLogger;
353
- }): Promise<ParquetCompileSummary>;
354
-
355
- declare const PARQUET_TABLES: readonly ["objects", "source_files", "import_batches", "raw_records", "import_errors", "uncertainties", "projects", "sessions", "turns", "events", "messages", "content_blocks", "tool_calls", "tool_results", "artifacts", "edges", "search_docs"];
356
- declare const ANALYTICS_VIEWS: readonly ["session_facts", "tool_usage_facts", "error_facts", "model_usage", "project_activity"];
357
- type ParquetTable = (typeof PARQUET_TABLES)[number];
358
- type AnalyticsView = (typeof ANALYTICS_VIEWS)[number];
359
- interface ParquetExportOptions {
360
- bundlePath: string;
361
- outDir?: string;
362
- }
363
- interface ParquetExportResult {
364
- outDir: string;
365
- manifestPath: string;
366
- files: Record<ParquetTable, string>;
367
- counts: Record<ParquetTable, number>;
368
- }
369
- interface DuckDbQueryOptions {
370
- parquetDir: string;
371
- sql: string;
372
- }
373
- interface DuckDbQueryResult {
374
- columns: string[];
375
- rows: Record<string, unknown>[];
376
- }
377
- declare function exportBundleParquet(options: ParquetExportOptions): Promise<ParquetExportResult>;
378
- declare function queryDuckDbParquet(options: DuckDbQueryOptions): Promise<DuckDbQueryResult>;
379
-
380
- declare const ANALYTICS_REPORTS: readonly ["sessions", "tools", "errors", "models", "projects"];
381
- type AnalyticsReport = (typeof ANALYTICS_REPORTS)[number];
382
- type AnalyticsDialect = 'sqlite' | 'duckdb';
383
- interface AnalyticsReportFilters {
384
- source?: string;
385
- since?: string;
386
- until?: string;
387
- limit?: number;
388
- toolName?: string;
389
- canonicalType?: string;
390
- errorsOnly?: boolean;
391
- category?: string;
392
- model?: string;
393
- project?: string;
394
- sessionId?: string;
395
- sourcePathSubstring?: string;
396
- }
397
- interface AnalyticsReportOptions {
398
- parquetDir: string;
399
- report: AnalyticsReport;
400
- filters?: AnalyticsReportFilters;
401
- }
402
- interface AnalyticsBundleReportOptions {
403
- bundle: Bundle;
404
- report: AnalyticsReport;
405
- filters?: AnalyticsReportFilters;
406
- }
407
- declare function runAnalyticsReport(options: AnalyticsReportOptions): Promise<DuckDbQueryResult>;
408
- declare function runAnalyticsReportFromBundle(options: AnalyticsBundleReportOptions): DuckDbQueryResult;
409
-
410
- type ToolCallEntity = 'tool_call' | 'artifact';
411
- interface ToolCallEvidence {
412
- entity_type: ToolCallEntity;
413
- session_id: string | null;
414
- tool_call_id: string | null;
415
- artifact_id: string | null;
416
- tool_name: string | null;
417
- canonical_tool_type: string | null;
418
- command: string | null;
419
- path: string | null;
420
- status: string | null;
421
- timestamp_start: string | null;
422
- is_error: 0 | 1 | null;
423
- exit_code: number | null;
424
- preview: string | null;
425
- }
426
- interface ToolCallFilters {
427
- sessionId?: string;
428
- toolName?: string;
429
- canonicalType?: string;
430
- pathSubstring?: string;
431
- errorsOnly?: boolean;
432
- sinceIso?: string;
433
- untilIso?: string;
434
- limit?: number;
435
- }
436
- declare function listToolCalls(bundle: Bundle, filters?: ToolCallFilters): ToolCallEvidence[];
437
-
438
- /**
439
- * Render a session into Markdown. Big tool outputs aren't dumped inline:
440
- * we show a preview line plus a `[object: blake3:…]` reference, leaving the
441
- * raw bytes in the CAS for downstream tools.
442
- */
443
- declare function exportSessionMarkdown(bundle: Bundle, sessionId: string): Promise<string>;
444
-
445
- interface CompileResult$3 {
446
- batch: ImportBatch;
447
- counts: ImportCounts;
448
- }
449
- declare function compileCodex(bundle: Bundle, root: string, options?: CompileOptions): Promise<CompileResult$3>;
450
-
451
- interface CompileResult$2 {
452
- batch: ImportBatch;
453
- counts: ImportCounts;
454
- }
455
- declare function compileClaude(bundle: Bundle, root: string, options?: CompileOptions): Promise<CompileResult$2>;
456
-
457
- interface CompileResult$1 {
458
- batch: ImportBatch;
459
- counts: ImportCounts;
460
- }
461
- declare function compileGemini(bundle: Bundle, root: string, options?: CompileOptions): Promise<CompileResult$1>;
462
-
463
- interface CompileResult {
464
- batch: ImportBatch;
465
- counts: ImportCounts;
466
- }
467
- declare function compileCursor(bundle: Bundle, root: string, options?: CompileOptions): Promise<CompileResult>;
468
-
469
- export { ANALYTICS_REPORTS, ANALYTICS_VIEWS, type AnalyticsBundleReportOptions, type AnalyticsDialect, type AnalyticsReport, type AnalyticsReportFilters, type AnalyticsReportOptions, type AnalyticsView, type Bundle, type BundleManifest, COMPILE_PROVIDERS, type CanonicalToolType, type CompileResult$2 as ClaudeCompileResult, type CompileResult$3 as CodexCompileResult, type CompileImportSummary, type CompileLogger, type CompileOptions, type CompileProviderConfig, type Confidence, type CompileResult as CursorCompileResult, type DuckDbQueryOptions, type DuckDbQueryResult, type EdgeType, type CompileResult$1 as GeminiCompileResult, type ImportBatch, type ImportCounts, type MessageRole, type ObjectId, type ObjectMeta, PARQUET_TABLES, PROSA_PARSER_VERSION, PROSA_SCHEMA_VERSION, type ParquetCompileSummary, type ParquetExportOptions, type ParquetExportResult, type ParquetTable, type ProviderCompileSummary, type RegisterResult, type SearchEngine, type SearchHit, type SearchIndexStatus, type SearchOptions, type SessionDetail, type SessionDetailEvent, type SessionListFilters, type SessionRow, type SessionRowFull, type SourceFileRow, type SourceTool, type TantivyCompileSummary, type ToolCallEntity, type ToolCallEvidence, type ToolCallFilters, type ToolCallStatus, closeBundle, compileClaude, compileCodex, compileCursor, compileGemini, countSessions, currentSchemaVersion, defaultBundlePath, disableFts5Triggers, emptyCounts, enableFts5Triggers, exportBundleParquet, exportCompileParquet, exportSessionMarkdown, finishBatch, getBytes, getCompileProvider, getJson, getObjectMeta, getSearchIndexStatus, getSearchIndexStatuses, getSession, getText, initBundle, listSessions, listToolCalls, markIndexesAfterImport, openBundle, openOrInitBundle, putBytes, putJson, putText, queryDuckDbParquet, rebuildFts5Index, rebuildTantivyIndex, recordError, registerSourceFile, resolveCompilePath, runAnalyticsReport, runAnalyticsReportFromBundle, runCompileImports, runMigrations, searchFullText, startBatch };
1
+ export * from '@c3-oss/prosa-core';