@rejacky/opencode-insights 0.1.4 → 0.1.5

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,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 createCaptureStore, d as defaultDataDir, n as normalizeChatHeadersCapture, e as normalizeChatMessageCapture, f as normalizeChatParamsCapture, g as normalizeEventCapture, h as normalizeExperimentalChatMessagesTransformCapture, i as normalizeExperimentalChatSystemTransformCapture, j as normalizeToolCapture, r as resolveCapturePath } from './capture-DkASdFpu.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, n as normalizeChatHeadersCapture, f as normalizeChatMessageCapture, g as normalizeChatParamsCapture, h as normalizeEventCapture, i as normalizeExperimentalChatMessagesTransformCapture, j as normalizeExperimentalChatSystemTransformCapture, k as normalizeToolCapture, o as openDatabase, r as resolveCapturePath, l as resolveRetentionDays } from './capture-B6sM1QQA.js';
4
4
 
5
5
  type StreamSample = {
6
6
  at: number;
@@ -109,7 +109,6 @@ declare const id = "opencode-insights";
109
109
  declare const _default: {
110
110
  id: string;
111
111
  server: Plugin;
112
- tui: TuiPlugin;
113
112
  };
114
113
 
115
114
  export { type MessageTiming, type MetricsState, OpenCodeInsights, type SessionAverage, type StreamSample, type SubagentInfo, type SubagentSidebarModel, type SubagentSidebarRow, type SubagentState, type SubagentStatus, applySubagentEvent, createMetricsState, createSubagentState, _default as default, estimateStreamTokens, getSubagentItems, getSubagentSidebarModel, id, pruneStaleSubagents, recordAssistantDelta, recordAssistantMessage, recordToolActivity, renderMetricsText, renderSubagentFooter, renderSubagentSidebar, renderSubagentStatus, server, rootTui as tui };
package/dist/index.js CHANGED
@@ -26,13 +26,63 @@ import {
26
26
  normalizeExperimentalChatMessagesTransformCapture,
27
27
  normalizeExperimentalChatSystemTransformCapture,
28
28
  normalizeToolCapture,
29
- resolveCapturePath
30
- } from "./chunk-Q5ROKOOJ.js";
29
+ openDatabase,
30
+ resolveCapturePath,
31
+ resolveRetentionDays
32
+ } from "./chunk-PBX4AJCR.js";
33
+
34
+ // src/cli-shim.ts
35
+ import { existsSync } from "fs";
36
+ import { chmod, mkdir, readFile, writeFile } from "fs/promises";
37
+ import { dirname, join } from "path";
38
+ import { homedir } from "os";
39
+ import { fileURLToPath } from "url";
40
+ var SHIM_MARKER = "Generated by opencode-insights";
41
+ function resolveCliShimPath(options = {}) {
42
+ const home = options.homeDir ?? homedir();
43
+ const name = options.platform === "win32" ? "opencode-insights.cmd" : "opencode-insights";
44
+ return join(home, ".local", "bin", name);
45
+ }
46
+ function createCliShimContent(cliPath, platform = process.platform) {
47
+ if (platform === "win32") {
48
+ return [`@echo off`, `rem ${SHIM_MARKER}. Do not edit.`, `node ${JSON.stringify(cliPath)} %*`, ""].join("\r\n");
49
+ }
50
+ return [`#!/usr/bin/env sh`, `# ${SHIM_MARKER}. Do not edit.`, `exec node ${shellQuote(cliPath)} "$@"`, ""].join("\n");
51
+ }
52
+ async function ensureCliShim(options = {}) {
53
+ const platform = options.platform ?? process.platform;
54
+ const path = resolveCliShimPath({ homeDir: options.homeDir, platform });
55
+ if (options.enabled === false || process.env.OPENCODE_INSIGHTS_CLI_SHIM === "0") {
56
+ return { path, status: "skipped", reason: "disabled" };
57
+ }
58
+ const packageRoot = options.packageRoot ?? defaultPackageRoot();
59
+ const content = createCliShimContent(join(packageRoot, "dist", "cli.js"), platform);
60
+ const existed = existsSync(path);
61
+ if (existed) {
62
+ const existing = await readFile(path, "utf8");
63
+ if (existing === content) return { path, status: "unchanged" };
64
+ if (!existing.includes(SHIM_MARKER)) {
65
+ return { path, status: "skipped", reason: "existing command is not managed by opencode-insights" };
66
+ }
67
+ }
68
+ await mkdir(dirname(path), { recursive: true });
69
+ await writeFile(path, content, "utf8");
70
+ if (platform !== "win32") await chmod(path, 493);
71
+ return { path, status: existed ? "updated" : "created" };
72
+ }
73
+ function defaultPackageRoot() {
74
+ return dirname(dirname(fileURLToPath(import.meta.url)));
75
+ }
76
+ function shellQuote(value) {
77
+ return `'${value.replace(/'/g, `'\\''`)}'`;
78
+ }
31
79
 
32
80
  // src/index.ts
33
81
  var OpenCodeInsights = async (_input, options) => {
82
+ if (options?.cliShim !== false) {
83
+ void ensureCliShim().catch(() => void 0);
84
+ }
34
85
  const store = createCaptureStore(options);
35
- const experimental = options?.experimental ?? false;
36
86
  try {
37
87
  await store.initialize?.();
38
88
  } catch {
@@ -56,16 +106,14 @@ var OpenCodeInsights = async (_input, options) => {
56
106
  "chat.params": async (input, output) => {
57
107
  await capture(normalizeChatParamsCapture(input, output));
58
108
  },
59
- ...experimental && {
60
- "chat.headers": async (input, output) => {
61
- await capture(normalizeChatHeadersCapture(input, output));
62
- },
63
- "experimental.chat.messages.transform": async (input, output) => {
64
- await capture(normalizeExperimentalChatMessagesTransformCapture(input, output));
65
- },
66
- "experimental.chat.system.transform": async (input, output) => {
67
- await capture(normalizeExperimentalChatSystemTransformCapture(input, output));
68
- }
109
+ "chat.headers": async (input, output) => {
110
+ await capture(normalizeChatHeadersCapture(input, output));
111
+ },
112
+ "experimental.chat.messages.transform": async (input, output) => {
113
+ await capture(normalizeExperimentalChatMessagesTransformCapture(input, output));
114
+ },
115
+ "experimental.chat.system.transform": async (input, output) => {
116
+ await capture(normalizeExperimentalChatSystemTransformCapture(input, output));
69
117
  },
70
118
  "tool.execute.before": async (input, output) => {
71
119
  await capture(normalizeToolCapture("tool.execute.before", input, output));
@@ -81,7 +129,7 @@ var rootTui = async (...args) => {
81
129
  return mod.tui(...args);
82
130
  };
83
131
  var id = "opencode-insights";
84
- var src_default = { id, server, tui: rootTui };
132
+ var src_default = { id, server };
85
133
  export {
86
134
  JsonlCaptureStore,
87
135
  OpenCodeInsights,
@@ -103,6 +151,7 @@ export {
103
151
  normalizeExperimentalChatMessagesTransformCapture,
104
152
  normalizeExperimentalChatSystemTransformCapture,
105
153
  normalizeToolCapture,
154
+ openDatabase,
106
155
  pruneStaleSubagents,
107
156
  recordAssistantDelta,
108
157
  recordAssistantMessage,
@@ -112,6 +161,7 @@ export {
112
161
  renderSubagentSidebar,
113
162
  renderSubagentStatus,
114
163
  resolveCapturePath,
164
+ resolveRetentionDays,
115
165
  server,
116
166
  rootTui as tui
117
167
  };
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.4",
4
+ "version": "0.1.5",
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",
@@ -75,10 +75,16 @@
75
75
  "@opencode-ai/plugin": "^1.17.13",
76
76
  "@opentui/core": "^0.4.3",
77
77
  "@opentui/solid": "^0.4.3",
78
+ "@types/better-sqlite3": "^7.6.13",
78
79
  "@types/node": "^24.12.2",
80
+ "@types/sql.js": "^1.4.11",
79
81
  "solid-js": "1.9.12",
80
82
  "tsup": "^8.5.1",
81
83
  "typescript": "^6.0.3",
82
84
  "vitest": "^4.1.10"
85
+ },
86
+ "dependencies": {
87
+ "better-sqlite3": "^12.11.1",
88
+ "sql.js": "^1.14.1"
83
89
  }
84
90
  }