Handle git WebSocket messages and persist to database

This commit is contained in:
Jared Miller 2026-01-28 14:56:53 -05:00
parent 3b5e636730
commit 599f911964
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 24 additions and 1 deletions

View file

@ -147,7 +147,8 @@ export function initDb(path = "claude-remote.db"): Database {
updateSessionStatsStmt = db.prepare(` updateSessionStatsStmt = db.prepare(`
UPDATE sessions UPDATE sessions
SET state = ?, prompts = ?, completions = ?, tools = ?, compressions = ?, SET state = ?, prompts = ?, completions = ?, tools = ?, compressions = ?,
thinking_seconds = ?, work_seconds = ?, mode = ?, model = ?, idle_since = ? thinking_seconds = ?, work_seconds = ?, mode = ?, model = ?, idle_since = ?,
git_branch = ?, git_files_json = ?
WHERE id = ? WHERE id = ?
`); `);
@ -286,6 +287,8 @@ export function updateSessionStats(
mode: string; mode: string;
model: string | null; model: string | null;
idle_since: number | null; idle_since: number | null;
git_branch: string | null;
git_files_json: string | null;
}, },
): void { ): void {
updateSessionStatsStmt.run( updateSessionStatsStmt.run(
@ -299,6 +302,8 @@ export function updateSessionStats(
state.mode, state.mode,
state.model, state.model,
state.idle_since, state.idle_since,
state.git_branch,
state.git_files_json,
sessionId, sessionId,
); );
} }

View file

@ -509,6 +509,24 @@ const server = Bun.serve<SessionData>({
return; return;
} }
// Handle git message
if (msg.type === "git") {
const sessionState = sessionStates.get(ws.data.sessionId);
if (sessionState) {
sessionState.git_branch = msg.branch;
sessionState.git_files_json = JSON.stringify(msg.files);
sessionState.dirty = true;
// Broadcast SSE git event
broadcastSSE({
type: "git",
session_id: ws.data.sessionId,
branch: msg.branch,
files_json: JSON.stringify(msg.files),
});
}
return;
}
// Handle resize message // Handle resize message
if (msg.type === "resize") { if (msg.type === "resize") {
// Store resize info if needed (not yet implemented) // Store resize info if needed (not yet implemented)