@c3-oss/prosa 0.1.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/README.md +566 -0
- package/dist/cli/main.d.ts +4 -0
- package/dist/cli/main.js +6479 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/index.d.ts +330 -0
- package/dist/index.js +5082 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { Database } from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
type Db = Database;
|
|
4
|
+
|
|
5
|
+
interface BundleManifest {
|
|
6
|
+
version: 1;
|
|
7
|
+
parser_version: string;
|
|
8
|
+
schema_version: number;
|
|
9
|
+
created_at: string;
|
|
10
|
+
hash_alg: 'blake3';
|
|
11
|
+
default_compression: 'zstd';
|
|
12
|
+
}
|
|
13
|
+
interface Bundle {
|
|
14
|
+
path: string;
|
|
15
|
+
db: Db;
|
|
16
|
+
manifest: BundleManifest;
|
|
17
|
+
paths: {
|
|
18
|
+
db: string;
|
|
19
|
+
manifest: string;
|
|
20
|
+
objects: string;
|
|
21
|
+
rawSources: string;
|
|
22
|
+
search: string;
|
|
23
|
+
tantivy: string;
|
|
24
|
+
exports: string;
|
|
25
|
+
parquet: string;
|
|
26
|
+
lock: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
declare function defaultBundlePath(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Create a fresh bundle at `rootPath`. Fails if the directory already contains
|
|
32
|
+
* a manifest (use openBundle for that case).
|
|
33
|
+
*/
|
|
34
|
+
declare function initBundle(rootPath: string): Promise<Bundle>;
|
|
35
|
+
/**
|
|
36
|
+
* Open an existing bundle. Applies pending migrations if the schema is older
|
|
37
|
+
* than the current code expects.
|
|
38
|
+
*/
|
|
39
|
+
declare function openBundle(rootPath: string): Promise<Bundle>;
|
|
40
|
+
declare function closeBundle(bundle: Bundle): void;
|
|
41
|
+
|
|
42
|
+
declare function runMigrations(db: Db): {
|
|
43
|
+
applied: number[];
|
|
44
|
+
};
|
|
45
|
+
declare function currentSchemaVersion(db: Db): number;
|
|
46
|
+
|
|
47
|
+
declare const PROSA_PARSER_VERSION = "0.1.0";
|
|
48
|
+
declare const PROSA_SCHEMA_VERSION = 2;
|
|
49
|
+
|
|
50
|
+
type Compression = 'zstd' | 'none';
|
|
51
|
+
|
|
52
|
+
type ObjectId = string;
|
|
53
|
+
interface ObjectMeta {
|
|
54
|
+
object_id: ObjectId;
|
|
55
|
+
hash_alg: 'blake3';
|
|
56
|
+
hash: string;
|
|
57
|
+
size_bytes: number;
|
|
58
|
+
compressed_size_bytes: number | null;
|
|
59
|
+
compression: Compression;
|
|
60
|
+
mime_type: string | null;
|
|
61
|
+
encoding: string | null;
|
|
62
|
+
storage_path: string;
|
|
63
|
+
created_at: string;
|
|
64
|
+
}
|
|
65
|
+
interface PutOptions {
|
|
66
|
+
mimeType?: string;
|
|
67
|
+
encoding?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Store raw bytes in the CAS. Returns the object_id. Idempotent: if the same
|
|
71
|
+
* content already exists, returns the existing object_id without rewriting.
|
|
72
|
+
*
|
|
73
|
+
* Bytes are compressed with zstd when worth it (see compress.ts threshold).
|
|
74
|
+
* The on-disk path is `<bundle>/objects/blake3/ab/cd/<hash>.zst`.
|
|
75
|
+
*/
|
|
76
|
+
declare function putBytes(bundle: Bundle, bytes: Uint8Array, options?: PutOptions): Promise<ObjectId>;
|
|
77
|
+
declare function putText(bundle: Bundle, text: string, options?: {
|
|
78
|
+
mimeType?: string;
|
|
79
|
+
}): Promise<ObjectId>;
|
|
80
|
+
declare function putJson(bundle: Bundle, value: unknown): Promise<ObjectId>;
|
|
81
|
+
declare function getBytes(bundle: Bundle, objectId: ObjectId): Promise<Buffer>;
|
|
82
|
+
declare function getText(bundle: Bundle, objectId: ObjectId): Promise<string>;
|
|
83
|
+
declare function getJson<T = unknown>(bundle: Bundle, objectId: ObjectId): Promise<T>;
|
|
84
|
+
declare function getObjectMeta(bundle: Bundle, objectId: ObjectId): ObjectMeta | null;
|
|
85
|
+
|
|
86
|
+
type SourceTool = 'cursor' | 'codex' | 'claude' | 'gemini';
|
|
87
|
+
type Confidence = 'high' | 'medium' | 'low';
|
|
88
|
+
type MessageRole = 'system_prompt' | 'developer' | 'user' | 'assistant' | 'tool' | 'operational';
|
|
89
|
+
type CanonicalToolType = 'shell' | 'read_file' | 'write_file' | 'edit_file' | 'search_file' | 'web_search' | 'mcp' | 'subagent' | 'patch' | 'other';
|
|
90
|
+
type EdgeType = 'parent_of' | 'calls' | 'returns' | 'spawned' | 'contains' | 'produced' | 'consumed' | 'derived_from' | 'summarizes' | 'compacts' | 'same_as' | 'refers_to';
|
|
91
|
+
type ToolCallStatus = 'started' | 'success' | 'error' | 'cancelled' | 'unknown';
|
|
92
|
+
interface SessionRowFull {
|
|
93
|
+
session_id: string;
|
|
94
|
+
source_tool: SourceTool;
|
|
95
|
+
source_session_id: string;
|
|
96
|
+
project_id: string | null;
|
|
97
|
+
parent_session_id: string | null;
|
|
98
|
+
is_subagent: 0 | 1;
|
|
99
|
+
agent_role: string | null;
|
|
100
|
+
agent_nickname: string | null;
|
|
101
|
+
title: string | null;
|
|
102
|
+
summary: string | null;
|
|
103
|
+
start_ts: string | null;
|
|
104
|
+
end_ts: string | null;
|
|
105
|
+
cwd_initial: string | null;
|
|
106
|
+
git_branch_initial: string | null;
|
|
107
|
+
model_first: string | null;
|
|
108
|
+
model_last: string | null;
|
|
109
|
+
status: string | null;
|
|
110
|
+
timeline_confidence: Confidence;
|
|
111
|
+
raw_record_id: string | null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface ImportBatch {
|
|
115
|
+
batch_id: string;
|
|
116
|
+
source_tool: SourceTool | null;
|
|
117
|
+
parser_version: string;
|
|
118
|
+
paths: string[];
|
|
119
|
+
started_at: string;
|
|
120
|
+
finished_at?: string;
|
|
121
|
+
}
|
|
122
|
+
interface ImportCounts {
|
|
123
|
+
source_files_seen: number;
|
|
124
|
+
source_files_imported: number;
|
|
125
|
+
source_files_skipped: number;
|
|
126
|
+
raw_records: number;
|
|
127
|
+
sessions: number;
|
|
128
|
+
turns: number;
|
|
129
|
+
events: number;
|
|
130
|
+
messages: number;
|
|
131
|
+
content_blocks: number;
|
|
132
|
+
tool_calls: number;
|
|
133
|
+
tool_results: number;
|
|
134
|
+
artifacts: number;
|
|
135
|
+
edges: number;
|
|
136
|
+
errors: number;
|
|
137
|
+
}
|
|
138
|
+
declare function emptyCounts(): ImportCounts;
|
|
139
|
+
declare function startBatch(bundle: Bundle, sourceTool: SourceTool | null, paths: string[]): ImportBatch;
|
|
140
|
+
declare function finishBatch(bundle: Bundle, batch: ImportBatch, counts: ImportCounts, status: 'completed' | 'failed'): void;
|
|
141
|
+
declare function recordError(bundle: Bundle, batchId: string, args: {
|
|
142
|
+
sourceFileId?: string | null;
|
|
143
|
+
rawRecordId?: string | null;
|
|
144
|
+
kind: string;
|
|
145
|
+
message: string;
|
|
146
|
+
payload?: unknown;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
|
|
149
|
+
interface SourceFileRow {
|
|
150
|
+
source_file_id: string;
|
|
151
|
+
source_tool: SourceTool;
|
|
152
|
+
path: string;
|
|
153
|
+
file_kind: string;
|
|
154
|
+
size_bytes: number;
|
|
155
|
+
mtime: string | null;
|
|
156
|
+
content_hash: string;
|
|
157
|
+
object_id: string | null;
|
|
158
|
+
discovered_at: string;
|
|
159
|
+
workspace_hint: string | null;
|
|
160
|
+
}
|
|
161
|
+
interface RegisterResult {
|
|
162
|
+
row: SourceFileRow;
|
|
163
|
+
alreadyKnown: boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Idempotent registration of a source file. The natural key is
|
|
167
|
+
* (source_tool, path, size, mtime, content_hash). If a row with the same
|
|
168
|
+
* tuple already exists we return it untouched and the caller can skip
|
|
169
|
+
* re-importing. Otherwise we insert a new row.
|
|
170
|
+
*
|
|
171
|
+
* This is the cheapest form of idempotency: re-running `prosa compile` over
|
|
172
|
+
* the same Codex tree is a no-op (no rehash unless the file changed).
|
|
173
|
+
*/
|
|
174
|
+
declare function registerSourceFile(bundle: Bundle, args: {
|
|
175
|
+
sourceTool: SourceTool;
|
|
176
|
+
absolutePath: string;
|
|
177
|
+
fileKind: string;
|
|
178
|
+
workspaceHint?: string | null;
|
|
179
|
+
}): Promise<RegisterResult>;
|
|
180
|
+
|
|
181
|
+
interface SessionListFilters {
|
|
182
|
+
sourceTool?: SourceTool;
|
|
183
|
+
sinceIso?: string;
|
|
184
|
+
untilIso?: string;
|
|
185
|
+
limit?: number;
|
|
186
|
+
}
|
|
187
|
+
interface SessionRow {
|
|
188
|
+
session_id: string;
|
|
189
|
+
source_tool: SourceTool;
|
|
190
|
+
source_session_id: string;
|
|
191
|
+
parent_session_id: string | null;
|
|
192
|
+
is_subagent: 0 | 1;
|
|
193
|
+
title: string | null;
|
|
194
|
+
start_ts: string | null;
|
|
195
|
+
end_ts: string | null;
|
|
196
|
+
cwd_initial: string | null;
|
|
197
|
+
git_branch_initial: string | null;
|
|
198
|
+
model_first: string | null;
|
|
199
|
+
model_last: string | null;
|
|
200
|
+
status: string | null;
|
|
201
|
+
timeline_confidence: Confidence;
|
|
202
|
+
message_count: number;
|
|
203
|
+
tool_call_count: number;
|
|
204
|
+
}
|
|
205
|
+
declare function listSessions(bundle: Bundle, filters?: SessionListFilters): SessionRow[];
|
|
206
|
+
declare function countSessions(bundle: Bundle, filters?: SessionListFilters): number;
|
|
207
|
+
interface SessionDetailEvent {
|
|
208
|
+
ordinal: number;
|
|
209
|
+
timestamp: string | null;
|
|
210
|
+
event_type: string;
|
|
211
|
+
source_type: string | null;
|
|
212
|
+
subtype: string | null;
|
|
213
|
+
actor: string | null;
|
|
214
|
+
message_id: string | null;
|
|
215
|
+
role: string | null;
|
|
216
|
+
tool_name: string | null;
|
|
217
|
+
is_error: 0 | 1 | null;
|
|
218
|
+
preview: string | null;
|
|
219
|
+
}
|
|
220
|
+
interface SessionDetail {
|
|
221
|
+
session: SessionRow;
|
|
222
|
+
events: SessionDetailEvent[];
|
|
223
|
+
}
|
|
224
|
+
declare function getSession(bundle: Bundle, sessionId: string): SessionDetail | null;
|
|
225
|
+
|
|
226
|
+
type SearchEngine = 'fts5' | 'tantivy';
|
|
227
|
+
interface SearchIndexStatus {
|
|
228
|
+
engine: SearchEngine;
|
|
229
|
+
status: 'missing' | 'ready' | 'stale' | 'building' | 'failed';
|
|
230
|
+
source_doc_count: number;
|
|
231
|
+
indexed_doc_count: number;
|
|
232
|
+
updated_at: string;
|
|
233
|
+
error_message: string | null;
|
|
234
|
+
}
|
|
235
|
+
declare function enableFts5Triggers(bundle: Bundle): void;
|
|
236
|
+
declare function disableFts5Triggers(bundle: Bundle): void;
|
|
237
|
+
declare function getSearchIndexStatuses(bundle: Bundle): SearchIndexStatus[];
|
|
238
|
+
declare function getSearchIndexStatus(bundle: Bundle, engine: SearchEngine): SearchIndexStatus | null;
|
|
239
|
+
declare function markIndexesAfterImport(bundle: Bundle, options: {
|
|
240
|
+
changed: boolean;
|
|
241
|
+
fts5Deferred: boolean;
|
|
242
|
+
}): void;
|
|
243
|
+
declare function rebuildFts5Index(bundle: Bundle): SearchIndexStatus;
|
|
244
|
+
declare function rebuildTantivyIndex(bundle: Bundle): Promise<SearchIndexStatus>;
|
|
245
|
+
|
|
246
|
+
interface SearchHit {
|
|
247
|
+
doc_id: string;
|
|
248
|
+
entity_type: string;
|
|
249
|
+
entity_id: string;
|
|
250
|
+
session_id: string | null;
|
|
251
|
+
timestamp: string | null;
|
|
252
|
+
role: string | null;
|
|
253
|
+
tool_name: string | null;
|
|
254
|
+
field_kind: string;
|
|
255
|
+
snippet: string;
|
|
256
|
+
}
|
|
257
|
+
interface SearchOptions {
|
|
258
|
+
query: string;
|
|
259
|
+
limit?: number;
|
|
260
|
+
engine?: SearchEngine;
|
|
261
|
+
/**
|
|
262
|
+
* When true, pass `query` straight to FTS5 (MATCH expression). When false
|
|
263
|
+
* (default), each whitespace-delimited token is wrapped in double quotes so
|
|
264
|
+
* punctuation like `package.json` doesn't trip the FTS5 parser. Set true if
|
|
265
|
+
* you want to use FTS5 operators like `OR`, `NEAR`, prefixes, etc.
|
|
266
|
+
*/
|
|
267
|
+
raw?: boolean;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* FTS5 search over messages, tool calls and tool outputs. Caller passes a
|
|
271
|
+
* raw FTS5 MATCH query. We project a snippet around the hit and join with
|
|
272
|
+
* search_docs to recover entity metadata.
|
|
273
|
+
*/
|
|
274
|
+
declare function searchFullText(bundle: Bundle, options: SearchOptions): SearchHit[];
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Render a session into Markdown. Big tool outputs aren't dumped inline:
|
|
278
|
+
* we show a preview line plus a `[object: blake3:…]` reference, leaving the
|
|
279
|
+
* raw bytes in the CAS for downstream tools.
|
|
280
|
+
*/
|
|
281
|
+
declare function exportSessionMarkdown(bundle: Bundle, sessionId: string): Promise<string>;
|
|
282
|
+
|
|
283
|
+
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"];
|
|
284
|
+
type ParquetTable = (typeof PARQUET_TABLES)[number];
|
|
285
|
+
interface ParquetExportOptions {
|
|
286
|
+
bundlePath: string;
|
|
287
|
+
outDir?: string;
|
|
288
|
+
}
|
|
289
|
+
interface ParquetExportResult {
|
|
290
|
+
outDir: string;
|
|
291
|
+
manifestPath: string;
|
|
292
|
+
files: Record<ParquetTable, string>;
|
|
293
|
+
counts: Record<ParquetTable, number>;
|
|
294
|
+
}
|
|
295
|
+
interface DuckDbQueryOptions {
|
|
296
|
+
parquetDir: string;
|
|
297
|
+
sql: string;
|
|
298
|
+
}
|
|
299
|
+
interface DuckDbQueryResult {
|
|
300
|
+
columns: string[];
|
|
301
|
+
rows: Record<string, unknown>[];
|
|
302
|
+
}
|
|
303
|
+
declare function exportBundleParquet(options: ParquetExportOptions): Promise<ParquetExportResult>;
|
|
304
|
+
declare function queryDuckDbParquet(options: DuckDbQueryOptions): Promise<DuckDbQueryResult>;
|
|
305
|
+
|
|
306
|
+
interface CompileResult$3 {
|
|
307
|
+
batch: ImportBatch;
|
|
308
|
+
counts: ImportCounts;
|
|
309
|
+
}
|
|
310
|
+
declare function compileCodex(bundle: Bundle, root: string): Promise<CompileResult$3>;
|
|
311
|
+
|
|
312
|
+
interface CompileResult$2 {
|
|
313
|
+
batch: ImportBatch;
|
|
314
|
+
counts: ImportCounts;
|
|
315
|
+
}
|
|
316
|
+
declare function compileClaude(bundle: Bundle, root: string): Promise<CompileResult$2>;
|
|
317
|
+
|
|
318
|
+
interface CompileResult$1 {
|
|
319
|
+
batch: ImportBatch;
|
|
320
|
+
counts: ImportCounts;
|
|
321
|
+
}
|
|
322
|
+
declare function compileGemini(bundle: Bundle, root: string): Promise<CompileResult$1>;
|
|
323
|
+
|
|
324
|
+
interface CompileResult {
|
|
325
|
+
batch: ImportBatch;
|
|
326
|
+
counts: ImportCounts;
|
|
327
|
+
}
|
|
328
|
+
declare function compileCursor(bundle: Bundle, root: string): Promise<CompileResult>;
|
|
329
|
+
|
|
330
|
+
export { type Bundle, type BundleManifest, type CanonicalToolType, type CompileResult$2 as ClaudeCompileResult, type CompileResult$3 as CodexCompileResult, 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 ParquetExportOptions, type ParquetExportResult, type ParquetTable, 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 ToolCallStatus, closeBundle, compileClaude, compileCodex, compileCursor, compileGemini, countSessions, currentSchemaVersion, defaultBundlePath, disableFts5Triggers, emptyCounts, enableFts5Triggers, exportBundleParquet, exportSessionMarkdown, finishBatch, getBytes, getJson, getObjectMeta, getSearchIndexStatus, getSearchIndexStatuses, getSession, getText, initBundle, listSessions, markIndexesAfterImport, openBundle, putBytes, putJson, putText, queryDuckDbParquet, rebuildFts5Index, rebuildTantivyIndex, recordError, registerSourceFile, runMigrations, searchFullText, startBatch };
|