@c3-oss/prosa 0.3.0 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -38,6 +38,11 @@ declare function initBundle(rootPath: string): Promise<Bundle>;
38
38
  * than the current code expects.
39
39
  */
40
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>;
41
46
  declare function closeBundle(bundle: Bundle): void;
42
47
 
43
48
  declare function runMigrations(db: Db): {
@@ -84,7 +89,8 @@ declare function getText(bundle: Bundle, objectId: ObjectId): Promise<string>;
84
89
  declare function getJson<T = unknown>(bundle: Bundle, objectId: ObjectId): Promise<T>;
85
90
  declare function getObjectMeta(bundle: Bundle, objectId: ObjectId): ObjectMeta | null;
86
91
 
87
- type SourceTool = 'cursor' | 'codex' | 'claude' | 'gemini';
92
+ declare const SOURCE_TOOLS: readonly ["cursor", "codex", "claude", "gemini"];
93
+ type SourceTool = (typeof SOURCE_TOOLS)[number];
88
94
  type Confidence = 'high' | 'medium' | 'low';
89
95
  type MessageRole = 'system_prompt' | 'developer' | 'user' | 'assistant' | 'tool' | 'operational';
90
96
  type CanonicalToolType = 'shell' | 'read_file' | 'write_file' | 'edit_file' | 'search_file' | 'web_search' | 'mcp' | 'subagent' | 'patch' | 'other';
@@ -384,4 +390,4 @@ interface CompileResult {
384
390
  }
385
391
  declare function compileCursor(bundle: Bundle, root: string, options?: CompileOptions): Promise<CompileResult>;
386
392
 
387
- export { 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 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, markIndexesAfterImport, openBundle, putBytes, putJson, putText, queryDuckDbParquet, rebuildFts5Index, rebuildTantivyIndex, recordError, registerSourceFile, resolveCompilePath, runCompileImports, runMigrations, searchFullText, startBatch };
393
+ export { 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 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, markIndexesAfterImport, openBundle, openOrInitBundle, putBytes, putJson, putText, queryDuckDbParquet, rebuildFts5Index, rebuildTantivyIndex, recordError, registerSourceFile, resolveCompilePath, runCompileImports, runMigrations, searchFullText, startBatch };
package/dist/index.js CHANGED
@@ -534,6 +534,18 @@ async function openBundle(rootPath) {
534
534
  }
535
535
  return { path: resolved, db, manifest, paths };
536
536
  }
537
+ async function openOrInitBundle(rootPath) {
538
+ const resolved = path.resolve(rootPath);
539
+ const paths = bundlePaths(resolved);
540
+ const dirStat = await stat(resolved).catch(() => null);
541
+ if (dirStat && !dirStat.isDirectory()) {
542
+ throw new Error(`bundle path not found or not a directory: ${resolved}`);
543
+ }
544
+ if (!dirStat || !await exists(paths.manifest)) {
545
+ return await initBundle(resolved);
546
+ }
547
+ return await openBundle(resolved);
548
+ }
537
549
  function closeBundle(bundle) {
538
550
  closeDb(bundle.db);
539
551
  }
@@ -1006,6 +1018,11 @@ async function fileExists(filePath) {
1006
1018
  }
1007
1019
  }
1008
1020
 
1021
+ // src/core/limits.ts
1022
+ function clampLimit(value, opts) {
1023
+ return Math.max(opts.min ?? 1, Math.min(opts.max, value ?? opts.fallback));
1024
+ }
1025
+
1009
1026
  // src/services/sessions.ts
1010
1027
  function sessionFilterWhere(filters) {
1011
1028
  const conds = [];
@@ -1029,7 +1046,7 @@ function sessionFilterWhere(filters) {
1029
1046
  }
1030
1047
  function listSessions(bundle, filters = {}) {
1031
1048
  const { where, params } = sessionFilterWhere(filters);
1032
- const limit = Math.max(1, Math.min(1e3, filters.limit ?? 50));
1049
+ const limit = clampLimit(filters.limit, { max: 1e3, fallback: 50 });
1033
1050
  const sql = `
1034
1051
  SELECT s.session_id,
1035
1052
  s.source_tool,
@@ -1105,6 +1122,9 @@ function getSession(bundle, sessionId2) {
1105
1122
  import { existsSync } from "fs";
1106
1123
  import { createRequire } from "module";
1107
1124
 
1125
+ // src/core/errors.ts
1126
+ var getErrorMessage = (err) => err instanceof Error ? err.message : String(err);
1127
+
1108
1128
  // src/services/indexing.ts
1109
1129
  import { mkdir as mkdir3, rm, writeFile as writeFile4 } from "fs/promises";
1110
1130
  import path4 from "path";
@@ -1203,7 +1223,7 @@ function rebuildFts5Index(bundle) {
1203
1223
  status: "failed",
1204
1224
  sourceDocCount: countSearchDocs(bundle),
1205
1225
  indexedDocCount: countFts5Docs(bundle),
1206
- errorMessage: error instanceof Error ? error.message : String(error)
1226
+ errorMessage: getErrorMessage(error)
1207
1227
  });
1208
1228
  throw error;
1209
1229
  }
@@ -1276,7 +1296,7 @@ async function rebuildTantivyIndex(bundle) {
1276
1296
  status: "failed",
1277
1297
  sourceDocCount: countSearchDocs(bundle),
1278
1298
  indexedDocCount: 0,
1279
- errorMessage: error instanceof Error ? error.message : String(error)
1299
+ errorMessage: getErrorMessage(error)
1280
1300
  });
1281
1301
  throw error;
1282
1302
  }
@@ -1329,7 +1349,7 @@ function searchFullText(bundle, options) {
1329
1349
  if (options.engine === "tantivy") {
1330
1350
  return searchTantivy(bundle, options);
1331
1351
  }
1332
- const limit = Math.max(1, Math.min(500, options.limit ?? 50));
1352
+ const limit = clampLimit(options.limit, { max: 500, fallback: 50 });
1333
1353
  const sql = `
1334
1354
  SELECT d.doc_id,
1335
1355
  d.entity_type,
@@ -1360,7 +1380,7 @@ function searchTantivy(bundle, options) {
1360
1380
  `tantivy index is ${status?.status ?? "missing"}; run \`prosa index tantivy\` first`
1361
1381
  );
1362
1382
  }
1363
- const limit = Math.max(1, Math.min(500, options.limit ?? 50));
1383
+ const limit = clampLimit(options.limit, { max: 500, fallback: 50 });
1364
1384
  const queryText = options.query.trim();
1365
1385
  if (!queryText) return [];
1366
1386
  const tantivy = requireTantivy();
@@ -1394,9 +1414,7 @@ function requireTantivy() {
1394
1414
  try {
1395
1415
  return require2("@oxdev03/node-tantivy-binding");
1396
1416
  } catch (error) {
1397
- throw new Error(
1398
- `tantivy engine is unavailable: ${error instanceof Error ? error.message : String(error)}`
1399
- );
1417
+ throw new Error(`tantivy engine is unavailable: ${getErrorMessage(error)}`);
1400
1418
  }
1401
1419
  }
1402
1420
  function getStoredText(doc, field) {
@@ -1518,7 +1536,7 @@ async function compileClaude(bundle, root, options = {}) {
1518
1536
  );
1519
1537
  await recordError(bundle, batch.batch_id, {
1520
1538
  kind: "claude_file_failed",
1521
- message: error instanceof Error ? error.message : String(error),
1539
+ message: getErrorMessage(error),
1522
1540
  payload: { path: file.filePath }
1523
1541
  });
1524
1542
  }
@@ -2480,7 +2498,7 @@ async function compileCodex(bundle, root, options = {}) {
2480
2498
  );
2481
2499
  await recordError(bundle, batch.batch_id, {
2482
2500
  kind: "codex_file_failed",
2483
- message: error instanceof Error ? error.message : String(error),
2501
+ message: getErrorMessage(error),
2484
2502
  payload: { path: filePath }
2485
2503
  });
2486
2504
  }
@@ -3633,7 +3651,7 @@ async function compileCursor(bundle, root, options = {}) {
3633
3651
  );
3634
3652
  await recordError(bundle, batch.batch_id, {
3635
3653
  kind: "cursor_store_failed",
3636
- message: error instanceof Error ? error.message : String(error),
3654
+ message: getErrorMessage(error),
3637
3655
  payload: { path: store.filePath }
3638
3656
  });
3639
3657
  }
@@ -4356,7 +4374,7 @@ async function compileGemini(bundle, root, options = {}) {
4356
4374
  );
4357
4375
  await recordError(bundle, batch.batch_id, {
4358
4376
  kind: "gemini_file_failed",
4359
- message: error instanceof Error ? error.message : String(error),
4377
+ message: getErrorMessage(error),
4360
4378
  payload: { path: file.filePath }
4361
4379
  });
4362
4380
  }
@@ -5139,7 +5157,7 @@ async function attachSqlite(connection, dbPath) {
5139
5157
  await connection.run(`ATTACH ${sqlString(dbPath)} AS prosa (TYPE sqlite)`);
5140
5158
  } catch (error) {
5141
5159
  throw new Error(
5142
- `DuckDB could not attach prosa.sqlite via the sqlite extension: ${error instanceof Error ? error.message : String(error)}`
5160
+ `DuckDB could not attach prosa.sqlite via the sqlite extension: ${getErrorMessage(error)}`
5143
5161
  );
5144
5162
  }
5145
5163
  }
@@ -5170,7 +5188,7 @@ function sqlString(value) {
5170
5188
  return `'${value.replace(/'/g, "''")}'`;
5171
5189
  }
5172
5190
  function isMissingParquetError(error) {
5173
- const message = error instanceof Error ? error.message : String(error);
5191
+ const message = getErrorMessage(error);
5174
5192
  return /No files found|does not exist|not found/i.test(message) && /\.parquet/i.test(message);
5175
5193
  }
5176
5194
 
@@ -5266,7 +5284,7 @@ async function runCompileImports(options) {
5266
5284
  tantivy = { indexedDocCount: status.indexed_doc_count };
5267
5285
  options.onTantivyComplete?.(tantivy);
5268
5286
  } catch (error) {
5269
- tantivyError = error instanceof Error ? error.message : String(error);
5287
+ tantivyError = getErrorMessage(error);
5270
5288
  logger?.error({ err: error }, "tantivy rebuild failed; SQLite data is intact");
5271
5289
  }
5272
5290
  }
@@ -5437,6 +5455,7 @@ export {
5437
5455
  listSessions,
5438
5456
  markIndexesAfterImport,
5439
5457
  openBundle,
5458
+ openOrInitBundle,
5440
5459
  putBytes,
5441
5460
  putJson,
5442
5461
  putText,