@rejacky/opencode-insights 0.1.6 → 0.1.8

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.
@@ -42,7 +42,7 @@ interface SqliteDb {
42
42
  sync(): void;
43
43
  close(): void;
44
44
  }
45
- declare function openDatabase(path: string): Promise<SqliteDb | undefined>;
45
+ declare function openDatabase(path: string, readonly?: boolean): Promise<SqliteDb | undefined>;
46
46
  declare function extractEventType(payload: Record<string, unknown>): string | null;
47
47
  declare class SqliteCaptureStore implements CaptureStore {
48
48
  private readonly path;
@@ -1,6 +1,6 @@
1
1
  // src/capture.ts
2
2
  import { mkdir, appendFile, readFile, writeFile } from "fs/promises";
3
- import { existsSync } from "fs";
3
+ import { existsSync, readFileSync } from "fs";
4
4
  import { dirname, join } from "path";
5
5
  import { homedir } from "os";
6
6
  var DEFAULT_RETENTION_DAYS = 1;
@@ -191,7 +191,7 @@ var JsonlCaptureStore = class {
191
191
  }
192
192
  }
193
193
  };
194
- async function openDatabase(path) {
194
+ async function openDatabase(path, readonly = false) {
195
195
  try {
196
196
  const mod = await import("bun:sqlite").catch(() => void 0);
197
197
  if (mod) {
@@ -233,6 +233,34 @@ async function openDatabase(path) {
233
233
  }
234
234
  } catch {
235
235
  }
236
+ if (readonly) {
237
+ try {
238
+ const initSqlJs = await import("sql.js").catch(() => void 0);
239
+ if (initSqlJs) {
240
+ const SQL = await initSqlJs.default();
241
+ const data = readFileSync(path);
242
+ const db = new SQL.Database(data);
243
+ return {
244
+ all(sql, ...params) {
245
+ const stmt = db.prepare(sql);
246
+ if (params.length > 0) stmt.bind(params);
247
+ const rows = [];
248
+ while (stmt.step()) rows.push(stmt.getAsObject());
249
+ stmt.free();
250
+ return rows;
251
+ },
252
+ run() {
253
+ },
254
+ sync() {
255
+ },
256
+ close() {
257
+ db.close();
258
+ }
259
+ };
260
+ }
261
+ } catch {
262
+ }
263
+ }
236
264
  return void 0;
237
265
  }
238
266
  function extractEventType(payload) {
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as CaptureRecord } from './capture-Dy799i3Z.js';
2
+ import { C as CaptureRecord } from './capture-BMWWI5GR.js';
3
3
 
4
4
  type HistoryMessage = {
5
5
  id: string;
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  openDatabase,
4
4
  resolveCapturePath
5
- } from "./chunk-XCHFXQIL.js";
5
+ } from "./chunk-FGTKNB7T.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { execFile as execFile2 } from "child_process";
@@ -62,7 +62,7 @@ async function readCaptureRecord(id, options = {}) {
62
62
  const dbPath = resolveCapturePath(options);
63
63
  if (!existsSync(dbPath)) return void 0;
64
64
  try {
65
- const db = await openDatabase(dbPath);
65
+ const db = await openDatabase(dbPath, true);
66
66
  if (db) {
67
67
  try {
68
68
  const rows = db.all("select id, kind, timestamp, session_id, message_id, provider_id, model_id, payload_json from captures where id = ?", id);
@@ -269,7 +269,7 @@ function ensureEventTypeColumn(db) {
269
269
  async function readSqliteCaptures(path, limit) {
270
270
  if (!existsSync(path)) return void 0;
271
271
  try {
272
- const db = await openDatabase(path);
272
+ const db = await openDatabase(path, true);
273
273
  if (!db) return readSqliteCapturesWithCli(path, limit);
274
274
  try {
275
275
  ensureEventTypeColumn(db);
@@ -303,7 +303,7 @@ async function readSqliteCapturesWithCli(path, limit) {
303
303
  async function readSqliteViewerCaptures(path, limit) {
304
304
  if (!existsSync(path)) return void 0;
305
305
  try {
306
- const db = await openDatabase(path);
306
+ const db = await openDatabase(path, true);
307
307
  if (!db) return readSqliteViewerCapturesWithCli(path, limit);
308
308
  try {
309
309
  ensureEventTypeColumn(db);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin } from '@opencode-ai/plugin';
2
2
  import { TuiPlugin } from '@opencode-ai/plugin/tui';
3
- export { a as CaptureKind, C as CaptureRecord, b as CaptureStore, I as InsightsOptions, J as JsonlCaptureStore, S as SqliteCaptureStore, c as SqliteDb, d as createCaptureStore, e as defaultDataDir, f as extractEventType, n as normalizeChatHeadersCapture, g as normalizeChatMessageCapture, h as normalizeChatParamsCapture, i as normalizeEventCapture, j as normalizeExperimentalChatMessagesTransformCapture, k as normalizeExperimentalChatSystemTransformCapture, l as normalizeToolCapture, o as openDatabase, r as resolveCapturePath, m as resolveRetentionDays } from './capture-Dy799i3Z.js';
3
+ export { a as CaptureKind, C as CaptureRecord, b as CaptureStore, I as InsightsOptions, J as JsonlCaptureStore, S as SqliteCaptureStore, c as SqliteDb, d as createCaptureStore, e as defaultDataDir, f as extractEventType, n as normalizeChatHeadersCapture, g as normalizeChatMessageCapture, h as normalizeChatParamsCapture, i as normalizeEventCapture, j as normalizeExperimentalChatMessagesTransformCapture, k as normalizeExperimentalChatSystemTransformCapture, l as normalizeToolCapture, o as openDatabase, r as resolveCapturePath, m as resolveRetentionDays } from './capture-BMWWI5GR.js';
4
4
 
5
5
  type StreamSample = {
6
6
  at: number;
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  openDatabase,
31
31
  resolveCapturePath,
32
32
  resolveRetentionDays
33
- } from "./chunk-XCHFXQIL.js";
33
+ } from "./chunk-FGTKNB7T.js";
34
34
 
35
35
  // src/cli-shim.ts
36
36
  import { existsSync } from "fs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@rejacky/opencode-insights",
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "description": "OpenCode plugin for local request capture, TPS metrics, and subagent status visibility.",
6
6
  "type": "module",
7
7
  "author": "opencode-insights contributors",
@@ -47,6 +47,7 @@
47
47
  "scripts": {
48
48
  "build": "tsup",
49
49
  "debug": "npm run build && node dist/cli.js debug",
50
+ "postinstall": "npm rebuild better-sqlite3",
50
51
  "test": "vitest run",
51
52
  "typecheck": "tsc --noEmit",
52
53
  "verify": "npm run typecheck && npm run test && npm run build",