@hasna/terminal 2.0.5 → 2.3.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/cli.js +52 -21
- package/package.json +1 -1
- package/src/ai.ts +77 -130
- package/src/cli.tsx +51 -21
- package/src/command-validator.ts +11 -0
- package/src/context-hints.ts +291 -0
- package/src/discover.ts +238 -0
- package/src/economy.ts +53 -0
- package/src/output-processor.ts +7 -18
- package/src/output-store.ts +65 -0
- package/src/providers/base.ts +3 -1
- package/src/providers/groq.ts +108 -0
- package/src/providers/index.ts +26 -2
- package/src/providers/providers.test.ts +4 -2
- package/src/providers/xai.ts +108 -0
- package/src/sessions-db.ts +81 -0
- package/temp/rtk/.claude/agents/code-reviewer.md +221 -0
- package/temp/rtk/.claude/agents/debugger.md +519 -0
- package/temp/rtk/.claude/agents/rtk-testing-specialist.md +461 -0
- package/temp/rtk/.claude/agents/rust-rtk.md +511 -0
- package/temp/rtk/.claude/agents/technical-writer.md +355 -0
- package/temp/rtk/.claude/commands/diagnose.md +352 -0
- package/temp/rtk/.claude/commands/test-routing.md +362 -0
- package/temp/rtk/.claude/hooks/bash/pre-commit-format.sh +16 -0
- package/temp/rtk/.claude/hooks/rtk-rewrite.sh +70 -0
- package/temp/rtk/.claude/hooks/rtk-suggest.sh +152 -0
- package/temp/rtk/.claude/rules/cli-testing.md +526 -0
- package/temp/rtk/.claude/skills/issue-triage/SKILL.md +348 -0
- package/temp/rtk/.claude/skills/issue-triage/templates/issue-comment.md +134 -0
- package/temp/rtk/.claude/skills/performance.md +435 -0
- package/temp/rtk/.claude/skills/pr-triage/SKILL.md +315 -0
- package/temp/rtk/.claude/skills/pr-triage/templates/review-comment.md +71 -0
- package/temp/rtk/.claude/skills/repo-recap.md +206 -0
- package/temp/rtk/.claude/skills/rtk-tdd/SKILL.md +78 -0
- package/temp/rtk/.claude/skills/rtk-tdd/references/testing-patterns.md +124 -0
- package/temp/rtk/.claude/skills/security-guardian.md +503 -0
- package/temp/rtk/.claude/skills/ship.md +404 -0
- package/temp/rtk/.github/workflows/benchmark.yml +34 -0
- package/temp/rtk/.github/workflows/dco-check.yaml +12 -0
- package/temp/rtk/.github/workflows/release-please.yml +51 -0
- package/temp/rtk/.github/workflows/release.yml +343 -0
- package/temp/rtk/.github/workflows/security-check.yml +135 -0
- package/temp/rtk/.github/workflows/validate-docs.yml +78 -0
- package/temp/rtk/.release-please-manifest.json +3 -0
- package/temp/rtk/ARCHITECTURE.md +1491 -0
- package/temp/rtk/CHANGELOG.md +640 -0
- package/temp/rtk/CLAUDE.md +605 -0
- package/temp/rtk/CONTRIBUTING.md +199 -0
- package/temp/rtk/Cargo.lock +1668 -0
- package/temp/rtk/Cargo.toml +64 -0
- package/temp/rtk/Formula/rtk.rb +43 -0
- package/temp/rtk/INSTALL.md +390 -0
- package/temp/rtk/LICENSE +21 -0
- package/temp/rtk/README.md +386 -0
- package/temp/rtk/README_es.md +159 -0
- package/temp/rtk/README_fr.md +197 -0
- package/temp/rtk/README_ja.md +159 -0
- package/temp/rtk/README_ko.md +159 -0
- package/temp/rtk/README_zh.md +167 -0
- package/temp/rtk/ROADMAP.md +15 -0
- package/temp/rtk/SECURITY.md +217 -0
- package/temp/rtk/TEST_EXEC_TIME.md +102 -0
- package/temp/rtk/build.rs +57 -0
- package/temp/rtk/docs/AUDIT_GUIDE.md +432 -0
- package/temp/rtk/docs/FEATURES.md +1410 -0
- package/temp/rtk/docs/TROUBLESHOOTING.md +309 -0
- package/temp/rtk/docs/filter-workflow.md +102 -0
- package/temp/rtk/docs/images/gain-dashboard.jpg +0 -0
- package/temp/rtk/docs/tracking.md +583 -0
- package/temp/rtk/hooks/opencode-rtk.ts +39 -0
- package/temp/rtk/hooks/rtk-awareness.md +29 -0
- package/temp/rtk/hooks/rtk-rewrite.sh +61 -0
- package/temp/rtk/hooks/test-rtk-rewrite.sh +442 -0
- package/temp/rtk/install.sh +124 -0
- package/temp/rtk/release-please-config.json +10 -0
- package/temp/rtk/scripts/benchmark.sh +592 -0
- package/temp/rtk/scripts/check-installation.sh +162 -0
- package/temp/rtk/scripts/install-local.sh +37 -0
- package/temp/rtk/scripts/rtk-economics.sh +137 -0
- package/temp/rtk/scripts/test-all.sh +561 -0
- package/temp/rtk/scripts/test-aristote.sh +227 -0
- package/temp/rtk/scripts/test-tracking.sh +79 -0
- package/temp/rtk/scripts/update-readme-metrics.sh +32 -0
- package/temp/rtk/scripts/validate-docs.sh +73 -0
- package/temp/rtk/src/aws_cmd.rs +880 -0
- package/temp/rtk/src/binlog.rs +1645 -0
- package/temp/rtk/src/cargo_cmd.rs +1727 -0
- package/temp/rtk/src/cc_economics.rs +1157 -0
- package/temp/rtk/src/ccusage.rs +340 -0
- package/temp/rtk/src/config.rs +187 -0
- package/temp/rtk/src/container.rs +855 -0
- package/temp/rtk/src/curl_cmd.rs +134 -0
- package/temp/rtk/src/deps.rs +268 -0
- package/temp/rtk/src/diff_cmd.rs +367 -0
- package/temp/rtk/src/discover/mod.rs +274 -0
- package/temp/rtk/src/discover/provider.rs +388 -0
- package/temp/rtk/src/discover/registry.rs +2022 -0
- package/temp/rtk/src/discover/report.rs +202 -0
- package/temp/rtk/src/discover/rules.rs +667 -0
- package/temp/rtk/src/display_helpers.rs +402 -0
- package/temp/rtk/src/dotnet_cmd.rs +1771 -0
- package/temp/rtk/src/dotnet_format_report.rs +133 -0
- package/temp/rtk/src/dotnet_trx.rs +593 -0
- package/temp/rtk/src/env_cmd.rs +204 -0
- package/temp/rtk/src/filter.rs +462 -0
- package/temp/rtk/src/filters/README.md +52 -0
- package/temp/rtk/src/filters/ansible-playbook.toml +34 -0
- package/temp/rtk/src/filters/basedpyright.toml +47 -0
- package/temp/rtk/src/filters/biome.toml +45 -0
- package/temp/rtk/src/filters/brew-install.toml +37 -0
- package/temp/rtk/src/filters/composer-install.toml +40 -0
- package/temp/rtk/src/filters/df.toml +16 -0
- package/temp/rtk/src/filters/dotnet-build.toml +64 -0
- package/temp/rtk/src/filters/du.toml +16 -0
- package/temp/rtk/src/filters/fail2ban-client.toml +15 -0
- package/temp/rtk/src/filters/gcc.toml +49 -0
- package/temp/rtk/src/filters/gcloud.toml +22 -0
- package/temp/rtk/src/filters/hadolint.toml +24 -0
- package/temp/rtk/src/filters/helm.toml +29 -0
- package/temp/rtk/src/filters/iptables.toml +27 -0
- package/temp/rtk/src/filters/jj.toml +28 -0
- package/temp/rtk/src/filters/jq.toml +24 -0
- package/temp/rtk/src/filters/make.toml +41 -0
- package/temp/rtk/src/filters/markdownlint.toml +24 -0
- package/temp/rtk/src/filters/mix-compile.toml +27 -0
- package/temp/rtk/src/filters/mix-format.toml +15 -0
- package/temp/rtk/src/filters/mvn-build.toml +44 -0
- package/temp/rtk/src/filters/oxlint.toml +43 -0
- package/temp/rtk/src/filters/ping.toml +63 -0
- package/temp/rtk/src/filters/pio-run.toml +40 -0
- package/temp/rtk/src/filters/poetry-install.toml +50 -0
- package/temp/rtk/src/filters/pre-commit.toml +35 -0
- package/temp/rtk/src/filters/ps.toml +16 -0
- package/temp/rtk/src/filters/quarto-render.toml +41 -0
- package/temp/rtk/src/filters/rsync.toml +48 -0
- package/temp/rtk/src/filters/shellcheck.toml +27 -0
- package/temp/rtk/src/filters/shopify-theme.toml +29 -0
- package/temp/rtk/src/filters/skopeo.toml +45 -0
- package/temp/rtk/src/filters/sops.toml +16 -0
- package/temp/rtk/src/filters/ssh.toml +44 -0
- package/temp/rtk/src/filters/stat.toml +34 -0
- package/temp/rtk/src/filters/swift-build.toml +41 -0
- package/temp/rtk/src/filters/systemctl-status.toml +33 -0
- package/temp/rtk/src/filters/terraform-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-fmt.toml +16 -0
- package/temp/rtk/src/filters/tofu-init.toml +38 -0
- package/temp/rtk/src/filters/tofu-plan.toml +35 -0
- package/temp/rtk/src/filters/tofu-validate.toml +17 -0
- package/temp/rtk/src/filters/trunk-build.toml +39 -0
- package/temp/rtk/src/filters/ty.toml +50 -0
- package/temp/rtk/src/filters/uv-sync.toml +37 -0
- package/temp/rtk/src/filters/xcodebuild.toml +99 -0
- package/temp/rtk/src/filters/yamllint.toml +25 -0
- package/temp/rtk/src/find_cmd.rs +598 -0
- package/temp/rtk/src/format_cmd.rs +386 -0
- package/temp/rtk/src/gain.rs +723 -0
- package/temp/rtk/src/gh_cmd.rs +1651 -0
- package/temp/rtk/src/git.rs +2012 -0
- package/temp/rtk/src/go_cmd.rs +592 -0
- package/temp/rtk/src/golangci_cmd.rs +254 -0
- package/temp/rtk/src/grep_cmd.rs +288 -0
- package/temp/rtk/src/gt_cmd.rs +810 -0
- package/temp/rtk/src/hook_audit_cmd.rs +283 -0
- package/temp/rtk/src/hook_check.rs +171 -0
- package/temp/rtk/src/init.rs +1859 -0
- package/temp/rtk/src/integrity.rs +537 -0
- package/temp/rtk/src/json_cmd.rs +231 -0
- package/temp/rtk/src/learn/detector.rs +628 -0
- package/temp/rtk/src/learn/mod.rs +119 -0
- package/temp/rtk/src/learn/report.rs +184 -0
- package/temp/rtk/src/lint_cmd.rs +694 -0
- package/temp/rtk/src/local_llm.rs +316 -0
- package/temp/rtk/src/log_cmd.rs +248 -0
- package/temp/rtk/src/ls.rs +324 -0
- package/temp/rtk/src/main.rs +2482 -0
- package/temp/rtk/src/mypy_cmd.rs +389 -0
- package/temp/rtk/src/next_cmd.rs +241 -0
- package/temp/rtk/src/npm_cmd.rs +236 -0
- package/temp/rtk/src/parser/README.md +267 -0
- package/temp/rtk/src/parser/error.rs +46 -0
- package/temp/rtk/src/parser/formatter.rs +336 -0
- package/temp/rtk/src/parser/mod.rs +311 -0
- package/temp/rtk/src/parser/types.rs +119 -0
- package/temp/rtk/src/pip_cmd.rs +302 -0
- package/temp/rtk/src/playwright_cmd.rs +479 -0
- package/temp/rtk/src/pnpm_cmd.rs +573 -0
- package/temp/rtk/src/prettier_cmd.rs +221 -0
- package/temp/rtk/src/prisma_cmd.rs +482 -0
- package/temp/rtk/src/psql_cmd.rs +382 -0
- package/temp/rtk/src/pytest_cmd.rs +384 -0
- package/temp/rtk/src/read.rs +217 -0
- package/temp/rtk/src/rewrite_cmd.rs +50 -0
- package/temp/rtk/src/ruff_cmd.rs +402 -0
- package/temp/rtk/src/runner.rs +271 -0
- package/temp/rtk/src/summary.rs +297 -0
- package/temp/rtk/src/tee.rs +405 -0
- package/temp/rtk/src/telemetry.rs +248 -0
- package/temp/rtk/src/toml_filter.rs +1655 -0
- package/temp/rtk/src/tracking.rs +1416 -0
- package/temp/rtk/src/tree.rs +209 -0
- package/temp/rtk/src/tsc_cmd.rs +259 -0
- package/temp/rtk/src/utils.rs +432 -0
- package/temp/rtk/src/verify_cmd.rs +47 -0
- package/temp/rtk/src/vitest_cmd.rs +385 -0
- package/temp/rtk/src/wc_cmd.rs +401 -0
- package/temp/rtk/src/wget_cmd.rs +260 -0
- package/temp/rtk/tests/fixtures/dotnet/build_failed.txt +11 -0
- package/temp/rtk/tests/fixtures/dotnet/format_changes.json +31 -0
- package/temp/rtk/tests/fixtures/dotnet/format_empty.json +1 -0
- package/temp/rtk/tests/fixtures/dotnet/format_success.json +12 -0
- package/temp/rtk/tests/fixtures/dotnet/test_failed.txt +18 -0
- package/dist/App.js +0 -404
- package/dist/Browse.js +0 -79
- package/dist/FuzzyPicker.js +0 -47
- package/dist/Onboarding.js +0 -51
- package/dist/Spinner.js +0 -12
- package/dist/StatusBar.js +0 -49
- package/dist/ai.js +0 -368
- package/dist/cache.js +0 -41
- package/dist/command-rewriter.js +0 -64
- package/dist/command-validator.js +0 -77
- package/dist/compression.js +0 -107
- package/dist/diff-cache.js +0 -107
- package/dist/economy.js +0 -79
- package/dist/expand-store.js +0 -38
- package/dist/file-cache.js +0 -72
- package/dist/file-index.js +0 -62
- package/dist/history.js +0 -62
- package/dist/lazy-executor.js +0 -54
- package/dist/line-dedup.js +0 -59
- package/dist/loop-detector.js +0 -75
- package/dist/mcp/install.js +0 -98
- package/dist/mcp/server.js +0 -569
- package/dist/noise-filter.js +0 -86
- package/dist/output-processor.js +0 -136
- package/dist/output-router.js +0 -41
- package/dist/parsers/base.js +0 -2
- package/dist/parsers/build.js +0 -64
- package/dist/parsers/errors.js +0 -101
- package/dist/parsers/files.js +0 -78
- package/dist/parsers/git.js +0 -99
- package/dist/parsers/index.js +0 -48
- package/dist/parsers/tests.js +0 -89
- package/dist/providers/anthropic.js +0 -39
- package/dist/providers/base.js +0 -4
- package/dist/providers/cerebras.js +0 -95
- package/dist/providers/index.js +0 -49
- package/dist/recipes/model.js +0 -20
- package/dist/recipes/storage.js +0 -136
- package/dist/search/content-search.js +0 -68
- package/dist/search/file-search.js +0 -61
- package/dist/search/filters.js +0 -34
- package/dist/search/index.js +0 -5
- package/dist/search/semantic.js +0 -320
- package/dist/session-boot.js +0 -59
- package/dist/session-context.js +0 -55
- package/dist/sessions-db.js +0 -120
- package/dist/smart-display.js +0 -286
- package/dist/snapshots.js +0 -51
- package/dist/supervisor.js +0 -112
- package/dist/test-watchlist.js +0 -131
- package/dist/tree.js +0 -94
- package/dist/usage-cache.js +0 -65
package/dist/search/semantic.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
// Semantic code search — AST-powered search that understands code structure
|
|
2
|
-
// Instead of raw grep, searches by meaning: "find auth functions" → login(), verifyToken()
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
|
-
import { readFileSync, existsSync } from "fs";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
function exec(command, cwd) {
|
|
7
|
-
return new Promise((resolve) => {
|
|
8
|
-
const proc = spawn("/bin/zsh", ["-c", command], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
9
|
-
let out = "";
|
|
10
|
-
proc.stdout?.on("data", (d) => { out += d.toString(); });
|
|
11
|
-
proc.stderr?.on("data", (d) => { });
|
|
12
|
-
proc.on("close", () => resolve(out));
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
/** Extract code symbols from a TypeScript/JavaScript file using regex-based parsing */
|
|
16
|
-
export function extractSymbolsFromFile(filePath) {
|
|
17
|
-
return extractSymbols(filePath);
|
|
18
|
-
}
|
|
19
|
-
/** Extract the complete code block for a symbol by name */
|
|
20
|
-
export function extractBlock(filePath, symbolName) {
|
|
21
|
-
if (!existsSync(filePath))
|
|
22
|
-
return null;
|
|
23
|
-
const content = readFileSync(filePath, "utf8");
|
|
24
|
-
const lines = content.split("\n");
|
|
25
|
-
const symbols = extractSymbols(filePath);
|
|
26
|
-
const symbol = symbols.find(s => s.name === symbolName && s.kind !== "import");
|
|
27
|
-
if (!symbol)
|
|
28
|
-
return null;
|
|
29
|
-
const startLine = symbol.line - 1; // 0-indexed
|
|
30
|
-
let braceDepth = 0;
|
|
31
|
-
let foundOpen = false;
|
|
32
|
-
let endLine = startLine;
|
|
33
|
-
for (let i = startLine; i < lines.length; i++) {
|
|
34
|
-
const line = lines[i];
|
|
35
|
-
for (const ch of line) {
|
|
36
|
-
if (ch === "{") {
|
|
37
|
-
braceDepth++;
|
|
38
|
-
foundOpen = true;
|
|
39
|
-
}
|
|
40
|
-
if (ch === "}") {
|
|
41
|
-
braceDepth--;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
endLine = i;
|
|
45
|
-
if (foundOpen && braceDepth <= 0)
|
|
46
|
-
break;
|
|
47
|
-
// For single-line arrow functions without braces
|
|
48
|
-
if (i === startLine && !line.includes("{") && line.includes("=>"))
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
code: lines.slice(startLine, endLine + 1).join("\n"),
|
|
53
|
-
startLine: startLine + 1, // 1-indexed
|
|
54
|
-
endLine: endLine + 1,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function extractSymbols(filePath) {
|
|
58
|
-
if (!existsSync(filePath))
|
|
59
|
-
return [];
|
|
60
|
-
const content = readFileSync(filePath, "utf8");
|
|
61
|
-
const lines = content.split("\n");
|
|
62
|
-
const symbols = [];
|
|
63
|
-
const file = filePath;
|
|
64
|
-
const ext = filePath.match(/\.(\w+)$/)?.[1] ?? "";
|
|
65
|
-
// Python support
|
|
66
|
-
if (ext === "py") {
|
|
67
|
-
for (let i = 0; i < lines.length; i++) {
|
|
68
|
-
const line = lines[i];
|
|
69
|
-
const defMatch = line.match(/^(\s*)(?:async\s+)?def\s+(\w+)\s*\(/);
|
|
70
|
-
if (defMatch) {
|
|
71
|
-
symbols.push({ name: defMatch[2], kind: "function", file, line: i + 1, signature: line.trim(), exported: !defMatch[2].startsWith("_") });
|
|
72
|
-
}
|
|
73
|
-
const classMatch = line.match(/^class\s+(\w+)/);
|
|
74
|
-
if (classMatch) {
|
|
75
|
-
symbols.push({ name: classMatch[1], kind: "class", file, line: i + 1, signature: line.trim(), exported: true });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return symbols;
|
|
79
|
-
}
|
|
80
|
-
// Go support
|
|
81
|
-
if (ext === "go") {
|
|
82
|
-
for (let i = 0; i < lines.length; i++) {
|
|
83
|
-
const line = lines[i];
|
|
84
|
-
const funcMatch = line.match(/^func\s+(?:\(\w+\s+\*?\w+\)\s+)?(\w+)\s*\(/);
|
|
85
|
-
if (funcMatch) {
|
|
86
|
-
symbols.push({ name: funcMatch[1], kind: "function", file, line: i + 1, signature: line.trim(), exported: /^[A-Z]/.test(funcMatch[1]) });
|
|
87
|
-
}
|
|
88
|
-
const typeMatch = line.match(/^type\s+(\w+)\s+(struct|interface)/);
|
|
89
|
-
if (typeMatch) {
|
|
90
|
-
symbols.push({ name: typeMatch[1], kind: typeMatch[2] === "interface" ? "interface" : "class", file, line: i + 1, signature: line.trim(), exported: /^[A-Z]/.test(typeMatch[1]) });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return symbols;
|
|
94
|
-
}
|
|
95
|
-
// Rust support
|
|
96
|
-
if (ext === "rs") {
|
|
97
|
-
for (let i = 0; i < lines.length; i++) {
|
|
98
|
-
const line = lines[i];
|
|
99
|
-
const fnMatch = line.match(/^\s*(?:pub\s+)?(?:async\s+)?fn\s+(\w+)/);
|
|
100
|
-
if (fnMatch) {
|
|
101
|
-
symbols.push({ name: fnMatch[1], kind: "function", file, line: i + 1, signature: line.trim(), exported: line.includes("pub") });
|
|
102
|
-
}
|
|
103
|
-
const structMatch = line.match(/^\s*(?:pub\s+)?struct\s+(\w+)/);
|
|
104
|
-
if (structMatch) {
|
|
105
|
-
symbols.push({ name: structMatch[1], kind: "class", file, line: i + 1, signature: line.trim(), exported: line.includes("pub") });
|
|
106
|
-
}
|
|
107
|
-
const enumMatch = line.match(/^\s*(?:pub\s+)?enum\s+(\w+)/);
|
|
108
|
-
if (enumMatch) {
|
|
109
|
-
symbols.push({ name: enumMatch[1], kind: "type", file, line: i + 1, signature: line.trim(), exported: line.includes("pub") });
|
|
110
|
-
}
|
|
111
|
-
const traitMatch = line.match(/^\s*(?:pub\s+)?trait\s+(\w+)/);
|
|
112
|
-
if (traitMatch) {
|
|
113
|
-
symbols.push({ name: traitMatch[1], kind: "interface", file, line: i + 1, signature: line.trim(), exported: line.includes("pub") });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return symbols;
|
|
117
|
-
}
|
|
118
|
-
// TypeScript/JavaScript (default)
|
|
119
|
-
for (let i = 0; i < lines.length; i++) {
|
|
120
|
-
const line = lines[i];
|
|
121
|
-
const lineNum = i + 1;
|
|
122
|
-
const isExported = line.trimStart().startsWith("export");
|
|
123
|
-
// Functions: export function X(...) or export const X = (...) =>
|
|
124
|
-
const funcMatch = line.match(/(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/);
|
|
125
|
-
if (funcMatch) {
|
|
126
|
-
const prevLine = i > 0 ? lines[i - 1] : "";
|
|
127
|
-
const doc = prevLine.trim().startsWith("/**") || prevLine.trim().startsWith("//")
|
|
128
|
-
? prevLine.trim().replace(/^\/\*\*\s*|\s*\*\/$/g, "").replace(/^\/\/\s*/, "")
|
|
129
|
-
: undefined;
|
|
130
|
-
symbols.push({
|
|
131
|
-
name: funcMatch[1], kind: "function", file, line: lineNum,
|
|
132
|
-
signature: line.trim().replace(/\{.*$/, "").trim(),
|
|
133
|
-
exported: isExported, doc,
|
|
134
|
-
});
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
// Arrow functions: export const X = (...) =>
|
|
138
|
-
const arrowMatch = line.match(/(?:export\s+)?(?:const|let)\s+(\w+)\s*=\s*(?:async\s+)?\(([^)]*)\)\s*(?::\s*\w[^=]*)?\s*=>/);
|
|
139
|
-
if (arrowMatch) {
|
|
140
|
-
// Detect React hooks
|
|
141
|
-
const isHook = arrowMatch[1].startsWith("use");
|
|
142
|
-
const isComponent = /^[A-Z]/.test(arrowMatch[1]);
|
|
143
|
-
symbols.push({
|
|
144
|
-
name: arrowMatch[1],
|
|
145
|
-
kind: isHook ? "hook" : isComponent ? "component" : "function",
|
|
146
|
-
file, line: lineNum,
|
|
147
|
-
signature: line.trim().replace(/\{.*$/, "").replace(/=>.*$/, "=>").trim(),
|
|
148
|
-
exported: isExported,
|
|
149
|
-
});
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
// Classes
|
|
153
|
-
const classMatch = line.match(/(?:export\s+)?class\s+(\w+)(?:\s+extends\s+(\w+))?/);
|
|
154
|
-
if (classMatch) {
|
|
155
|
-
symbols.push({
|
|
156
|
-
name: classMatch[1], kind: "class", file, line: lineNum,
|
|
157
|
-
signature: line.trim().replace(/\{.*$/, "").trim(),
|
|
158
|
-
exported: isExported,
|
|
159
|
-
});
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
// Interfaces
|
|
163
|
-
const ifaceMatch = line.match(/(?:export\s+)?interface\s+(\w+)/);
|
|
164
|
-
if (ifaceMatch) {
|
|
165
|
-
symbols.push({
|
|
166
|
-
name: ifaceMatch[1], kind: "interface", file, line: lineNum,
|
|
167
|
-
signature: line.trim().replace(/\{.*$/, "").trim(),
|
|
168
|
-
exported: isExported,
|
|
169
|
-
});
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
// Type aliases
|
|
173
|
-
const typeMatch = line.match(/(?:export\s+)?type\s+(\w+)\s*=/);
|
|
174
|
-
if (typeMatch) {
|
|
175
|
-
symbols.push({
|
|
176
|
-
name: typeMatch[1], kind: "type", file, line: lineNum,
|
|
177
|
-
signature: line.trim(),
|
|
178
|
-
exported: isExported,
|
|
179
|
-
});
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
// Imports (for dependency tracking)
|
|
183
|
-
const importMatch = line.match(/import\s+(?:\{([^}]+)\}|(\w+))\s+from\s+['"]([^'"]+)['"]/);
|
|
184
|
-
if (importMatch) {
|
|
185
|
-
const names = importMatch[1]
|
|
186
|
-
? importMatch[1].split(",").map(s => s.trim().split(" as ")[0].trim())
|
|
187
|
-
: [importMatch[2]];
|
|
188
|
-
for (const name of names) {
|
|
189
|
-
if (name) {
|
|
190
|
-
symbols.push({
|
|
191
|
-
name, kind: "import", file, line: lineNum,
|
|
192
|
-
signature: `from '${importMatch[3]}'`,
|
|
193
|
-
exported: false,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
// Exported constants/variables
|
|
200
|
-
const constMatch = line.match(/export\s+const\s+(\w+)\s*[=:]/);
|
|
201
|
-
if (constMatch && !arrowMatch) {
|
|
202
|
-
symbols.push({
|
|
203
|
-
name: constMatch[1], kind: "variable", file, line: lineNum,
|
|
204
|
-
signature: line.trim().slice(0, 80),
|
|
205
|
-
exported: true,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return symbols;
|
|
210
|
-
}
|
|
211
|
-
/** Find all source files in a directory */
|
|
212
|
-
async function findSourceFiles(cwd, maxFiles = 200) {
|
|
213
|
-
const excludes = ["node_modules", ".git", "dist", "build", ".next", "coverage", "__pycache__"];
|
|
214
|
-
const excludeArgs = excludes.map(d => `-not -path '*/${d}/*'`).join(" ");
|
|
215
|
-
const extensions = "\\( -name '*.ts' -o -name '*.tsx' -o -name '*.js' -o -name '*.jsx' \\)";
|
|
216
|
-
const cmd = `find . ${extensions} ${excludeArgs} -type f 2>/dev/null | head -${maxFiles}`;
|
|
217
|
-
const output = await exec(cmd, cwd);
|
|
218
|
-
return output.split("\n").filter(l => l.trim()).map(l => join(cwd, l.trim()));
|
|
219
|
-
}
|
|
220
|
-
/** Semantic search: find symbols matching a natural language query */
|
|
221
|
-
export async function semanticSearch(query, cwd, options = {}) {
|
|
222
|
-
const { kinds, exportedOnly = false, maxResults = 30 } = options;
|
|
223
|
-
// Find all source files
|
|
224
|
-
const files = await findSourceFiles(cwd);
|
|
225
|
-
// Extract symbols from all files
|
|
226
|
-
let allSymbols = [];
|
|
227
|
-
for (const file of files) {
|
|
228
|
-
try {
|
|
229
|
-
allSymbols.push(...extractSymbols(file));
|
|
230
|
-
}
|
|
231
|
-
catch { /* skip unreadable files */ }
|
|
232
|
-
}
|
|
233
|
-
// Filter by kind
|
|
234
|
-
if (kinds) {
|
|
235
|
-
allSymbols = allSymbols.filter(s => kinds.includes(s.kind));
|
|
236
|
-
}
|
|
237
|
-
// Filter by exported
|
|
238
|
-
if (exportedOnly) {
|
|
239
|
-
allSymbols = allSymbols.filter(s => s.exported);
|
|
240
|
-
}
|
|
241
|
-
// Score each symbol against the query
|
|
242
|
-
const queryLower = query.toLowerCase();
|
|
243
|
-
const queryWords = queryLower.split(/\s+/).filter(w => w.length > 2);
|
|
244
|
-
const scored = allSymbols.map(symbol => {
|
|
245
|
-
let score = 0;
|
|
246
|
-
const nameLower = symbol.name.toLowerCase();
|
|
247
|
-
const sigLower = (symbol.signature ?? "").toLowerCase();
|
|
248
|
-
const fileLower = symbol.file.toLowerCase();
|
|
249
|
-
// Exact name match
|
|
250
|
-
if (queryWords.some(w => nameLower === w))
|
|
251
|
-
score += 10;
|
|
252
|
-
// Name contains query word
|
|
253
|
-
if (queryWords.some(w => nameLower.includes(w)))
|
|
254
|
-
score += 5;
|
|
255
|
-
// Signature contains query word
|
|
256
|
-
if (queryWords.some(w => sigLower.includes(w)))
|
|
257
|
-
score += 3;
|
|
258
|
-
// File path contains query word
|
|
259
|
-
if (queryWords.some(w => fileLower.includes(w)))
|
|
260
|
-
score += 2;
|
|
261
|
-
// Doc contains query word
|
|
262
|
-
if (symbol.doc && queryWords.some(w => symbol.doc.toLowerCase().includes(w)))
|
|
263
|
-
score += 4;
|
|
264
|
-
// Boost exported symbols
|
|
265
|
-
if (symbol.exported)
|
|
266
|
-
score += 1;
|
|
267
|
-
// Boost functions/classes over imports
|
|
268
|
-
if (symbol.kind === "function" || symbol.kind === "class")
|
|
269
|
-
score += 1;
|
|
270
|
-
// Semantic matching for common patterns
|
|
271
|
-
if (queryLower.includes("component") && symbol.kind === "component")
|
|
272
|
-
score += 5;
|
|
273
|
-
if (queryLower.includes("hook") && symbol.kind === "hook")
|
|
274
|
-
score += 5;
|
|
275
|
-
if (queryLower.includes("type") && (symbol.kind === "type" || symbol.kind === "interface"))
|
|
276
|
-
score += 5;
|
|
277
|
-
if (queryLower.includes("import") && symbol.kind === "import")
|
|
278
|
-
score += 5;
|
|
279
|
-
if (queryLower.includes("class") && symbol.kind === "class")
|
|
280
|
-
score += 5;
|
|
281
|
-
return { symbol, score };
|
|
282
|
-
});
|
|
283
|
-
// Sort by score, filter zero scores
|
|
284
|
-
const results = scored
|
|
285
|
-
.filter(s => s.score > 0)
|
|
286
|
-
.sort((a, b) => b.score - a.score)
|
|
287
|
-
.slice(0, maxResults)
|
|
288
|
-
.map(s => s.symbol);
|
|
289
|
-
// Make file paths relative
|
|
290
|
-
for (const r of results) {
|
|
291
|
-
if (r.file.startsWith(cwd)) {
|
|
292
|
-
r.file = "." + r.file.slice(cwd.length);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
// Estimate token savings
|
|
296
|
-
const rawGrep = await exec(`grep -rn '${queryWords[0] ?? query}' . --include='*.ts' --include='*.tsx' 2>/dev/null | head -100`, cwd);
|
|
297
|
-
const rawTokens = Math.ceil(rawGrep.length / 4);
|
|
298
|
-
const resultTokens = Math.ceil(JSON.stringify(results).length / 4);
|
|
299
|
-
return {
|
|
300
|
-
query,
|
|
301
|
-
symbols: results,
|
|
302
|
-
totalFiles: files.length,
|
|
303
|
-
tokensSaved: Math.max(0, rawTokens - resultTokens),
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
/** Quick helper: find all exported functions */
|
|
307
|
-
export async function findExports(cwd) {
|
|
308
|
-
const result = await semanticSearch("export", cwd, { exportedOnly: true, maxResults: 100 });
|
|
309
|
-
return result.symbols;
|
|
310
|
-
}
|
|
311
|
-
/** Quick helper: find all React components */
|
|
312
|
-
export async function findComponents(cwd) {
|
|
313
|
-
const result = await semanticSearch("component", cwd, { kinds: ["component"], maxResults: 50 });
|
|
314
|
-
return result.symbols;
|
|
315
|
-
}
|
|
316
|
-
/** Quick helper: find all hooks */
|
|
317
|
-
export async function findHooks(cwd) {
|
|
318
|
-
const result = await semanticSearch("hook", cwd, { kinds: ["hook"], maxResults: 50 });
|
|
319
|
-
return result.symbols;
|
|
320
|
-
}
|
package/dist/session-boot.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Session boot cache — precompute common data on first MCP call
|
|
2
|
-
// Agents always start with git status + file tree + package.json — do it once
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
|
-
import { existsSync, readFileSync } from "fs";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
let bootCache = null;
|
|
7
|
-
let bootCwd = "";
|
|
8
|
-
function exec(command, cwd) {
|
|
9
|
-
return new Promise((resolve) => {
|
|
10
|
-
const proc = spawn("/bin/zsh", ["-c", command], { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
11
|
-
let out = "";
|
|
12
|
-
proc.stdout?.on("data", (d) => { out += d.toString(); });
|
|
13
|
-
proc.on("close", () => resolve(out.trim()));
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/** Get or build session boot context */
|
|
17
|
-
export async function getBootContext(cwd) {
|
|
18
|
-
if (bootCache && bootCwd === cwd)
|
|
19
|
-
return bootCache;
|
|
20
|
-
const [branch, status, log, srcLs] = await Promise.all([
|
|
21
|
-
exec("git branch --show-current 2>/dev/null", cwd),
|
|
22
|
-
exec("git status --porcelain 2>/dev/null", cwd),
|
|
23
|
-
exec("git log --oneline -8 2>/dev/null", cwd),
|
|
24
|
-
exec("ls -1 src/ 2>/dev/null || ls -1 lib/ 2>/dev/null || echo ''", cwd),
|
|
25
|
-
]);
|
|
26
|
-
let pkg = null;
|
|
27
|
-
const pkgPath = join(cwd, "package.json");
|
|
28
|
-
if (existsSync(pkgPath)) {
|
|
29
|
-
try {
|
|
30
|
-
pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
31
|
-
}
|
|
32
|
-
catch { }
|
|
33
|
-
}
|
|
34
|
-
bootCache = {
|
|
35
|
-
cwd,
|
|
36
|
-
git: {
|
|
37
|
-
branch: branch || null,
|
|
38
|
-
dirty: status.length > 0,
|
|
39
|
-
changedFiles: status.split("\n").filter(l => l.trim()).length,
|
|
40
|
-
recentCommits: log.split("\n").filter(l => l.trim()).slice(0, 5).map(l => {
|
|
41
|
-
const m = l.match(/^([a-f0-9]+)\s+(.+)$/);
|
|
42
|
-
return m ? { hash: m[1], message: m[2] } : null;
|
|
43
|
-
}).filter(Boolean),
|
|
44
|
-
},
|
|
45
|
-
project: pkg ? {
|
|
46
|
-
name: pkg.name,
|
|
47
|
-
version: pkg.version,
|
|
48
|
-
scripts: pkg.scripts ? Object.keys(pkg.scripts) : [],
|
|
49
|
-
deps: pkg.dependencies ? Object.keys(pkg.dependencies).length : 0,
|
|
50
|
-
} : null,
|
|
51
|
-
sourceFiles: srcLs.split("\n").filter(l => l.trim()),
|
|
52
|
-
};
|
|
53
|
-
bootCwd = cwd;
|
|
54
|
-
return bootCache;
|
|
55
|
-
}
|
|
56
|
-
/** Invalidate boot cache (call after git operations or file changes) */
|
|
57
|
-
export function invalidateBootCache() {
|
|
58
|
-
bootCache = null;
|
|
59
|
-
}
|
package/dist/session-context.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// Session context — stores last N command+output pairs for follow-up queries
|
|
2
|
-
// Enables: terminal "show auth code" → terminal "explain that function"
|
|
3
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
4
|
-
import { homedir } from "os";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
const DIR = join(homedir(), ".terminal");
|
|
7
|
-
const CTX_FILE = join(DIR, "session-context.json");
|
|
8
|
-
const MAX_ENTRIES = 5;
|
|
9
|
-
function ensureDir() {
|
|
10
|
-
if (!existsSync(DIR))
|
|
11
|
-
mkdirSync(DIR, { recursive: true });
|
|
12
|
-
}
|
|
13
|
-
/** Load session context */
|
|
14
|
-
export function loadContext() {
|
|
15
|
-
ensureDir();
|
|
16
|
-
if (!existsSync(CTX_FILE))
|
|
17
|
-
return [];
|
|
18
|
-
try {
|
|
19
|
-
const entries = JSON.parse(readFileSync(CTX_FILE, "utf8"));
|
|
20
|
-
// Only return entries from last 30 minutes (session freshness)
|
|
21
|
-
const cutoff = Date.now() - 30 * 60 * 1000;
|
|
22
|
-
return entries.filter(e => e.timestamp > cutoff).slice(-MAX_ENTRIES);
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/** Save a command to session context */
|
|
29
|
-
export function saveContext(prompt, command, output) {
|
|
30
|
-
ensureDir();
|
|
31
|
-
const entries = loadContext();
|
|
32
|
-
entries.push({
|
|
33
|
-
prompt,
|
|
34
|
-
command,
|
|
35
|
-
output: output.slice(0, 500),
|
|
36
|
-
timestamp: Date.now(),
|
|
37
|
-
});
|
|
38
|
-
// Keep only last N
|
|
39
|
-
const trimmed = entries.slice(-MAX_ENTRIES);
|
|
40
|
-
writeFileSync(CTX_FILE, JSON.stringify(trimmed, null, 2));
|
|
41
|
-
}
|
|
42
|
-
/** Format context for AI prompt injection */
|
|
43
|
-
export function formatContext() {
|
|
44
|
-
const entries = loadContext();
|
|
45
|
-
if (entries.length === 0)
|
|
46
|
-
return "";
|
|
47
|
-
const lines = ["\nRECENT SESSION CONTEXT (for follow-up references like 'that', 'it', 'the same'):"];
|
|
48
|
-
for (const e of entries.slice(-3)) {
|
|
49
|
-
lines.push(`> ${e.prompt}`);
|
|
50
|
-
lines.push(`$ ${e.command}`);
|
|
51
|
-
if (e.output)
|
|
52
|
-
lines.push(e.output.slice(0, 200));
|
|
53
|
-
}
|
|
54
|
-
return lines.join("\n");
|
|
55
|
-
}
|
package/dist/sessions-db.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// SQLite session database — tracks every terminal interaction
|
|
2
|
-
// @ts-ignore — bun:sqlite is a bun built-in
|
|
3
|
-
import { Database } from "bun:sqlite";
|
|
4
|
-
import { existsSync, mkdirSync } from "fs";
|
|
5
|
-
import { homedir } from "os";
|
|
6
|
-
import { join } from "path";
|
|
7
|
-
import { randomUUID } from "crypto";
|
|
8
|
-
const DIR = join(homedir(), ".terminal");
|
|
9
|
-
const DB_PATH = join(DIR, "sessions.db");
|
|
10
|
-
let db = null;
|
|
11
|
-
function getDb() {
|
|
12
|
-
if (db)
|
|
13
|
-
return db;
|
|
14
|
-
if (!existsSync(DIR))
|
|
15
|
-
mkdirSync(DIR, { recursive: true });
|
|
16
|
-
db = new Database(DB_PATH);
|
|
17
|
-
db.exec("PRAGMA journal_mode = WAL");
|
|
18
|
-
db.exec(`
|
|
19
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
20
|
-
id TEXT PRIMARY KEY,
|
|
21
|
-
started_at INTEGER NOT NULL,
|
|
22
|
-
ended_at INTEGER,
|
|
23
|
-
cwd TEXT NOT NULL,
|
|
24
|
-
provider TEXT,
|
|
25
|
-
model TEXT
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
CREATE TABLE IF NOT EXISTS interactions (
|
|
29
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
30
|
-
session_id TEXT NOT NULL REFERENCES sessions(id),
|
|
31
|
-
nl TEXT NOT NULL,
|
|
32
|
-
command TEXT,
|
|
33
|
-
output TEXT,
|
|
34
|
-
exit_code INTEGER,
|
|
35
|
-
tokens_used INTEGER DEFAULT 0,
|
|
36
|
-
tokens_saved INTEGER DEFAULT 0,
|
|
37
|
-
duration_ms INTEGER,
|
|
38
|
-
model TEXT,
|
|
39
|
-
cached INTEGER DEFAULT 0,
|
|
40
|
-
created_at INTEGER NOT NULL
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
CREATE INDEX IF NOT EXISTS idx_interactions_session ON interactions(session_id);
|
|
44
|
-
CREATE INDEX IF NOT EXISTS idx_sessions_started ON sessions(started_at);
|
|
45
|
-
`);
|
|
46
|
-
return db;
|
|
47
|
-
}
|
|
48
|
-
// ── Sessions ─────────────────────────────────────────────────────────────────
|
|
49
|
-
export function createSession(cwd, provider, model) {
|
|
50
|
-
const id = randomUUID();
|
|
51
|
-
getDb().prepare("INSERT INTO sessions (id, started_at, cwd, provider, model) VALUES (?, ?, ?, ?, ?)").run(id, Date.now(), cwd, provider ?? null, model ?? null);
|
|
52
|
-
return id;
|
|
53
|
-
}
|
|
54
|
-
export function endSession(sessionId) {
|
|
55
|
-
getDb().prepare("UPDATE sessions SET ended_at = ? WHERE id = ?").run(Date.now(), sessionId);
|
|
56
|
-
}
|
|
57
|
-
export function listSessions(limit = 20) {
|
|
58
|
-
return getDb().prepare("SELECT * FROM sessions ORDER BY started_at DESC LIMIT ?").all(limit);
|
|
59
|
-
}
|
|
60
|
-
export function getSession(id) {
|
|
61
|
-
return getDb().prepare("SELECT * FROM sessions WHERE id = ?").get(id);
|
|
62
|
-
}
|
|
63
|
-
export function logInteraction(sessionId, data) {
|
|
64
|
-
const result = getDb().prepare(`INSERT INTO interactions (session_id, nl, command, output, exit_code, tokens_used, tokens_saved, duration_ms, model, cached, created_at)
|
|
65
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(sessionId, data.nl, data.command ?? null, data.output ? data.output.slice(0, 500) : null, data.exitCode ?? null, data.tokensUsed ?? 0, data.tokensSaved ?? 0, data.durationMs ?? null, data.model ?? null, data.cached ? 1 : 0, Date.now());
|
|
66
|
-
// bun:sqlite — lastInsertRowid is a property on the statement after run()
|
|
67
|
-
const lastId = getDb().prepare("SELECT last_insert_rowid() as id").get();
|
|
68
|
-
return lastId?.id ?? 0;
|
|
69
|
-
}
|
|
70
|
-
export function updateInteraction(id, data) {
|
|
71
|
-
const sets = [];
|
|
72
|
-
const vals = [];
|
|
73
|
-
if (data.command !== undefined) {
|
|
74
|
-
sets.push("command = ?");
|
|
75
|
-
vals.push(data.command);
|
|
76
|
-
}
|
|
77
|
-
if (data.output !== undefined) {
|
|
78
|
-
sets.push("output = ?");
|
|
79
|
-
vals.push(data.output.slice(0, 500));
|
|
80
|
-
}
|
|
81
|
-
if (data.exitCode !== undefined) {
|
|
82
|
-
sets.push("exit_code = ?");
|
|
83
|
-
vals.push(data.exitCode);
|
|
84
|
-
}
|
|
85
|
-
if (data.tokensSaved !== undefined) {
|
|
86
|
-
sets.push("tokens_saved = ?");
|
|
87
|
-
vals.push(data.tokensSaved);
|
|
88
|
-
}
|
|
89
|
-
if (sets.length === 0)
|
|
90
|
-
return;
|
|
91
|
-
vals.push(id);
|
|
92
|
-
getDb().prepare(`UPDATE interactions SET ${sets.join(", ")} WHERE id = ?`).run(...vals);
|
|
93
|
-
}
|
|
94
|
-
export function getSessionInteractions(sessionId) {
|
|
95
|
-
return getDb().prepare("SELECT * FROM interactions WHERE session_id = ? ORDER BY created_at ASC").all(sessionId);
|
|
96
|
-
}
|
|
97
|
-
export function getSessionStats() {
|
|
98
|
-
const d = getDb();
|
|
99
|
-
const sessions = d.prepare("SELECT COUNT(*) as c FROM sessions").get();
|
|
100
|
-
const interactions = d.prepare("SELECT COUNT(*) as c, SUM(tokens_saved) as saved, SUM(tokens_used) as used FROM interactions").get();
|
|
101
|
-
const cached = d.prepare("SELECT COUNT(*) as c FROM interactions WHERE cached = 1").get();
|
|
102
|
-
const errors = d.prepare("SELECT COUNT(*) as c FROM interactions WHERE exit_code IS NOT NULL AND exit_code != 0").get();
|
|
103
|
-
const totalInteractions = interactions.c ?? 0;
|
|
104
|
-
return {
|
|
105
|
-
totalSessions: sessions.c ?? 0,
|
|
106
|
-
totalInteractions,
|
|
107
|
-
totalTokensSaved: interactions.saved ?? 0,
|
|
108
|
-
totalTokensUsed: interactions.used ?? 0,
|
|
109
|
-
cacheHitRate: totalInteractions > 0 ? (cached.c ?? 0) / totalInteractions : 0,
|
|
110
|
-
avgInteractionsPerSession: sessions.c > 0 ? totalInteractions / sessions.c : 0,
|
|
111
|
-
errorRate: totalInteractions > 0 ? (errors.c ?? 0) / totalInteractions : 0,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
/** Close the database connection */
|
|
115
|
-
export function closeDb() {
|
|
116
|
-
if (db) {
|
|
117
|
-
db.close();
|
|
118
|
-
db = null;
|
|
119
|
-
}
|
|
120
|
-
}
|