feat: Add terminal command history tracking and autocomplete

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>
This commit is contained in:
ZacharyZcR
2025-11-09 20:18:52 +08:00
parent c4c5be34f2
commit 49094bbadc
10 changed files with 1305 additions and 0 deletions

View File

@@ -239,3 +239,17 @@ export const recentActivity = sqliteTable("recent_activity", {
.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`),
});