@hasna/terminal 0.5.0 → 0.5.1
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 +1 -1
- package/dist/sessions-db.js +6 -3
- package/package.json +1 -3
- package/src/cli.tsx +1 -1
- package/src/sessions-db.ts +8 -5
package/dist/cli.js
CHANGED
package/dist/sessions-db.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SQLite session database — tracks every terminal interaction
|
|
2
|
-
|
|
2
|
+
// @ts-ignore — bun:sqlite is a bun built-in
|
|
3
|
+
import { Database } from "bun:sqlite";
|
|
3
4
|
import { existsSync, mkdirSync } from "fs";
|
|
4
5
|
import { homedir } from "os";
|
|
5
6
|
import { join } from "path";
|
|
@@ -13,7 +14,7 @@ function getDb() {
|
|
|
13
14
|
if (!existsSync(DIR))
|
|
14
15
|
mkdirSync(DIR, { recursive: true });
|
|
15
16
|
db = new Database(DB_PATH);
|
|
16
|
-
db.
|
|
17
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
17
18
|
db.exec(`
|
|
18
19
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
19
20
|
id TEXT PRIMARY KEY,
|
|
@@ -62,7 +63,9 @@ export function getSession(id) {
|
|
|
62
63
|
export function logInteraction(sessionId, data) {
|
|
63
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)
|
|
64
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());
|
|
65
|
-
|
|
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;
|
|
66
69
|
}
|
|
67
70
|
export function updateInteraction(id, data) {
|
|
68
71
|
const sets = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/terminal",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Smart terminal wrapper for AI agents and humans — structured output, token compression, MCP server, natural language",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
18
18
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
19
19
|
"@typescript/vfs": "^1.6.4",
|
|
20
|
-
"better-sqlite3": "^12.8.0",
|
|
21
20
|
"ink": "^5.0.1",
|
|
22
21
|
"react": "^18.2.0",
|
|
23
22
|
"zod": "^4.3.6"
|
|
@@ -31,7 +30,6 @@
|
|
|
31
30
|
"url": "git+https://github.com/hasna/terminal.git"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
35
33
|
"@types/node": "^20.0.0",
|
|
36
34
|
"@types/react": "^18.2.0",
|
|
37
35
|
"tsx": "^4.0.0",
|
package/src/cli.tsx
CHANGED
package/src/sessions-db.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SQLite session database — tracks every terminal interaction
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// @ts-ignore — bun:sqlite is a bun built-in
|
|
4
|
+
import { Database } from "bun:sqlite";
|
|
4
5
|
import { existsSync, mkdirSync } from "fs";
|
|
5
6
|
import { homedir } from "os";
|
|
6
7
|
import { join } from "path";
|
|
@@ -9,13 +10,13 @@ import { randomUUID } from "crypto";
|
|
|
9
10
|
const DIR = join(homedir(), ".terminal");
|
|
10
11
|
const DB_PATH = join(DIR, "sessions.db");
|
|
11
12
|
|
|
12
|
-
let db: Database
|
|
13
|
+
let db: Database | null = null;
|
|
13
14
|
|
|
14
|
-
function getDb(): Database
|
|
15
|
+
function getDb(): Database {
|
|
15
16
|
if (db) return db;
|
|
16
17
|
if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true });
|
|
17
18
|
db = new Database(DB_PATH);
|
|
18
|
-
db.
|
|
19
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
19
20
|
|
|
20
21
|
db.exec(`
|
|
21
22
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
@@ -126,7 +127,9 @@ export function logInteraction(sessionId: string, data: {
|
|
|
126
127
|
data.cached ? 1 : 0,
|
|
127
128
|
Date.now()
|
|
128
129
|
);
|
|
129
|
-
|
|
130
|
+
// bun:sqlite — lastInsertRowid is a property on the statement after run()
|
|
131
|
+
const lastId = getDb().prepare("SELECT last_insert_rowid() as id").get() as any;
|
|
132
|
+
return lastId?.id ?? 0;
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
export function updateInteraction(id: number, data: {
|