Implement comprehensive command history system for SSH terminals: - Stage 1: Automatic command tracking with character-level input monitoring - Stage 2: Ctrl+R history search dialog with real-time filtering and keyboard navigation - Stage 3: Tab-based autocomplete with multi-match selection UI Key features: - Per-host command history stored in SQLite database - Smart positioning for autocomplete menu (auto-adjusts based on screen space) - Delete individual commands from history - Keyboard shortcuts: Ctrl+R (search), Tab (autocomplete), ↑↓ (navigate), Enter (select), Esc (close) Bug fixes: - Prevent double input by filtering keyup events (only handle keydown) - Use refs to avoid closure traps in event handlers - Real-time history updates without requiring terminal restart 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
256 lines
7.8 KiB
TypeScript
256 lines
7.8 KiB
TypeScript
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
|
import { sql } from "drizzle-orm";
|
|
|
|
export const users = sqliteTable("users", {
|
|
id: text("id").primaryKey(),
|
|
username: text("username").notNull(),
|
|
password_hash: text("password_hash").notNull(),
|
|
is_admin: integer("is_admin", { mode: "boolean" }).notNull().default(false),
|
|
|
|
is_oidc: integer("is_oidc", { mode: "boolean" }).notNull().default(false),
|
|
oidc_identifier: text("oidc_identifier"),
|
|
client_id: text("client_id"),
|
|
client_secret: text("client_secret"),
|
|
issuer_url: text("issuer_url"),
|
|
authorization_url: text("authorization_url"),
|
|
token_url: text("token_url"),
|
|
identifier_path: text("identifier_path"),
|
|
name_path: text("name_path"),
|
|
scopes: text().default("openid email profile"),
|
|
|
|
totp_secret: text("totp_secret"),
|
|
totp_enabled: integer("totp_enabled", { mode: "boolean" })
|
|
.notNull()
|
|
.default(false),
|
|
totp_backup_codes: text("totp_backup_codes"),
|
|
});
|
|
|
|
export const settings = sqliteTable("settings", {
|
|
key: text("key").primaryKey(),
|
|
value: text("value").notNull(),
|
|
});
|
|
|
|
export const sessions = sqliteTable("sessions", {
|
|
id: text("id").primaryKey(),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
jwtToken: text("jwt_token").notNull(),
|
|
deviceType: text("device_type").notNull(),
|
|
deviceInfo: text("device_info").notNull(),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
expiresAt: text("expires_at").notNull(),
|
|
lastActiveAt: text("last_active_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const sshData = sqliteTable("ssh_data", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
name: text("name"),
|
|
ip: text("ip").notNull(),
|
|
port: integer("port").notNull(),
|
|
username: text("username").notNull(),
|
|
folder: text("folder"),
|
|
tags: text("tags"),
|
|
pin: integer("pin", { mode: "boolean" }).notNull().default(false),
|
|
authType: text("auth_type").notNull(),
|
|
forceKeyboardInteractive: text("force_keyboard_interactive"),
|
|
|
|
password: text("password"),
|
|
key: text("key", { length: 8192 }),
|
|
key_password: text("key_password"),
|
|
keyType: text("key_type"),
|
|
|
|
autostartPassword: text("autostart_password"),
|
|
autostartKey: text("autostart_key", { length: 8192 }),
|
|
autostartKeyPassword: text("autostart_key_password"),
|
|
|
|
credentialId: integer("credential_id").references(() => sshCredentials.id),
|
|
enableTerminal: integer("enable_terminal", { mode: "boolean" })
|
|
.notNull()
|
|
.default(true),
|
|
enableTunnel: integer("enable_tunnel", { mode: "boolean" })
|
|
.notNull()
|
|
.default(true),
|
|
tunnelConnections: text("tunnel_connections"),
|
|
enableFileManager: integer("enable_file_manager", { mode: "boolean" })
|
|
.notNull()
|
|
.default(true),
|
|
defaultPath: text("default_path"),
|
|
statsConfig: text("stats_config"),
|
|
terminalConfig: text("terminal_config"),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
updatedAt: text("updated_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const fileManagerRecent = sqliteTable("file_manager_recent", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
hostId: integer("host_id")
|
|
.notNull()
|
|
.references(() => sshData.id),
|
|
name: text("name").notNull(),
|
|
path: text("path").notNull(),
|
|
lastOpened: text("last_opened")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const fileManagerPinned = sqliteTable("file_manager_pinned", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
hostId: integer("host_id")
|
|
.notNull()
|
|
.references(() => sshData.id),
|
|
name: text("name").notNull(),
|
|
path: text("path").notNull(),
|
|
pinnedAt: text("pinned_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const fileManagerShortcuts = sqliteTable("file_manager_shortcuts", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
hostId: integer("host_id")
|
|
.notNull()
|
|
.references(() => sshData.id),
|
|
name: text("name").notNull(),
|
|
path: text("path").notNull(),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const dismissedAlerts = sqliteTable("dismissed_alerts", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
alertId: text("alert_id").notNull(),
|
|
dismissedAt: text("dismissed_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const sshCredentials = sqliteTable("ssh_credentials", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
name: text("name").notNull(),
|
|
description: text("description"),
|
|
folder: text("folder"),
|
|
tags: text("tags"),
|
|
authType: text("auth_type").notNull(),
|
|
username: text("username").notNull(),
|
|
password: text("password"),
|
|
key: text("key", { length: 16384 }),
|
|
private_key: text("private_key", { length: 16384 }),
|
|
public_key: text("public_key", { length: 4096 }),
|
|
key_password: text("key_password"),
|
|
keyType: text("key_type"),
|
|
detectedKeyType: text("detected_key_type"),
|
|
usageCount: integer("usage_count").notNull().default(0),
|
|
lastUsed: text("last_used"),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
updatedAt: text("updated_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const sshCredentialUsage = sqliteTable("ssh_credential_usage", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
credentialId: integer("credential_id")
|
|
.notNull()
|
|
.references(() => sshCredentials.id),
|
|
hostId: integer("host_id")
|
|
.notNull()
|
|
.references(() => sshData.id),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
usedAt: text("used_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const snippets = sqliteTable("snippets", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
name: text("name").notNull(),
|
|
content: text("content").notNull(),
|
|
description: text("description"),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
updatedAt: text("updated_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const sshFolders = sqliteTable("ssh_folders", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
name: text("name").notNull(),
|
|
color: text("color"),
|
|
icon: text("icon"),
|
|
createdAt: text("created_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
updatedAt: text("updated_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const recentActivity = sqliteTable("recent_activity", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
type: text("type").notNull(),
|
|
hostId: integer("host_id")
|
|
.notNull()
|
|
.references(() => sshData.id),
|
|
hostName: text("host_name").notNull(),
|
|
timestamp: text("timestamp")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|
|
|
|
export const commandHistory = sqliteTable("command_history", {
|
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
userId: text("user_id")
|
|
.notNull()
|
|
.references(() => users.id),
|
|
hostId: integer("host_id")
|
|
.notNull()
|
|
.references(() => sshData.id),
|
|
command: text("command").notNull(),
|
|
executedAt: text("executed_at")
|
|
.notNull()
|
|
.default(sql`CURRENT_TIMESTAMP`),
|
|
});
|