refactor: remove dead notification systems and legacy broadcasts
- Delete claude-hooks.ts store (processHook never called, always empty) - Delete HookNotifications.vue and NotificationLog.vue (orphan components) - Delete claude-status.ts route and broadcastClaudeStatus (no consumers) - Delete agent-bar.md legacy doc - Remove legacy WS 'claude-hook' broadcast (frontend ignores it) - Move isAgentRunning tracking into broadcastClaudeHook
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
import { jsonResponse, errorResponse } from '../utils/cors'
|
||||
import { PORT_TERMINAL } from '../config'
|
||||
|
||||
type ClaudeStatus =
|
||||
| 'idle'
|
||||
| 'thinking' // UserPromptSubmit / PostToolUse - Claude is thinking
|
||||
| 'toolUse' // PreToolUse - Using a tool (generic)
|
||||
| 'reading' // PreToolUse(Read/Glob/Grep) - Reading files
|
||||
| 'writing' // PreToolUse(Edit/Write) - Writing files
|
||||
| 'sessionStart' // SessionStart - Session just started
|
||||
| 'sessionEnd' // SessionEnd - Session ended
|
||||
| 'permissionRequest' // PermissionRequest - Waiting for user permission
|
||||
| 'interrupted' // PostToolUseFailure with is_interrupt
|
||||
| 'error' // PostToolUseFailure without is_interrupt
|
||||
|
||||
interface ClaudeStatusPayload {
|
||||
status: ClaudeStatus
|
||||
tool?: string
|
||||
agent?: string
|
||||
}
|
||||
|
||||
export async function handleClaudeStatus(req: Request): Promise<Response | null> {
|
||||
if (req.method !== 'POST') return null
|
||||
|
||||
try {
|
||||
const body = await req.json() as ClaudeStatusPayload
|
||||
|
||||
const validStatuses: ClaudeStatus[] = [
|
||||
'idle', 'thinking', 'toolUse', 'reading', 'writing',
|
||||
'sessionStart', 'sessionEnd', 'permissionRequest',
|
||||
'interrupted', 'error'
|
||||
]
|
||||
if (!body.status || !validStatuses.includes(body.status)) {
|
||||
return errorResponse(`Invalid status. Must be one of: ${validStatuses.join(', ')}`, 400)
|
||||
}
|
||||
|
||||
// Forward to terminal server for WebSocket broadcast
|
||||
try {
|
||||
await fetch(`http://localhost:${PORT_TERMINAL}/claude-status`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('[claude-status] Failed to forward to terminal server:', e)
|
||||
}
|
||||
|
||||
return jsonResponse({ success: true, status: body.status })
|
||||
} catch (e) {
|
||||
return errorResponse('Invalid JSON body', 400)
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import { handleGiteaRepo, handleGiteaTree, handleGiteaFile } from './gitea'
|
||||
import { handleTables, handleStats, handleTableSchema, handleTableData, handleQuery } from './database'
|
||||
import { handleWhisperRoutes } from './whisper'
|
||||
import { handleRecordingsRoutes } from './recordings'
|
||||
import { handleClaudeStatus } from './claude-status'
|
||||
import { handleClaudeHook } from './claude-hook'
|
||||
import { handleSnapshots, handleSnapshotById } from './snapshots'
|
||||
import { handleGitStatus, handleGitDiff, handleGitLog, handleGitLogCommit, handleGitCompare, handleGitBranches, handleGitCurrentBranch, handleGitTree, handleGitFile } from './git'
|
||||
@@ -68,12 +67,6 @@ export async function handleRequest(req: Request): Promise<Response> {
|
||||
if (res) return res
|
||||
}
|
||||
|
||||
// Claude Code status (thinking/idle)
|
||||
if (path === '/api/claude-status') {
|
||||
const res = await handleClaudeStatus(req)
|
||||
if (res) return res
|
||||
}
|
||||
|
||||
// Claude Code hook (rich stdin data forwarding)
|
||||
if (path === '/api/claude-hook') {
|
||||
const res = await handleClaudeHook(req)
|
||||
|
||||
@@ -295,17 +295,6 @@ export function startTerminalServer() {
|
||||
return Response.json({ sessions: list })
|
||||
}
|
||||
|
||||
// Claude status broadcast endpoint
|
||||
if (url.pathname === '/claude-status' && req.method === 'POST') {
|
||||
try {
|
||||
const body = await req.json() as { status: ClaudeStatus, tool?: string, agent?: string }
|
||||
broadcastClaudeStatus(body.status, body.tool, body.agent)
|
||||
return Response.json({ success: true }, { headers: corsHeaders })
|
||||
} catch {
|
||||
return Response.json({ error: 'Invalid JSON' }, { status: 400, headers: corsHeaders })
|
||||
}
|
||||
}
|
||||
|
||||
// Claude hook broadcast endpoint (rich data from stdin)
|
||||
if (url.pathname === '/claude-hook' && req.method === 'POST') {
|
||||
try {
|
||||
@@ -718,57 +707,20 @@ export function startTerminalServer() {
|
||||
return server
|
||||
}
|
||||
|
||||
// Claude status types
|
||||
type ClaudeStatus = 'idle' | 'thinking' | 'toolUse' | 'reading' | 'writing' | 'sessionStart' | 'sessionEnd' | 'permissionRequest' | 'interrupted' | 'error'
|
||||
|
||||
// Broadcast Claude status to ALL clients across ALL sessions
|
||||
export function broadcastClaudeStatus(status: ClaudeStatus, tool?: string, agent?: string) {
|
||||
const agentName = agent || 'claude'
|
||||
|
||||
// Track agent running state
|
||||
if (status === 'sessionStart') {
|
||||
const state = agentSessions.get(agentName)
|
||||
if (state) {
|
||||
state.isAgentRunning = true
|
||||
console.log(`[Terminal] Agent ${agentName} marked as running (sessionStart)`)
|
||||
}
|
||||
} else if (status === 'sessionEnd') {
|
||||
const state = agentSessions.get(agentName)
|
||||
if (state) {
|
||||
state.isAgentRunning = false
|
||||
console.log(`[Terminal] Agent ${agentName} marked as stopped (sessionEnd)`)
|
||||
}
|
||||
}
|
||||
|
||||
const message = JSON.stringify({
|
||||
type: 'claude-status',
|
||||
status,
|
||||
tool,
|
||||
agent: agentName,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
|
||||
const clientCount = broadcastToAll(message)
|
||||
console.log(`[Terminal] Claude status broadcast: ${status}${tool ? ` (${tool})` : ''} → ${clientCount} clients`)
|
||||
|
||||
// Note: session state is updated via broadcastClaudeHook which has full payload context.
|
||||
}
|
||||
|
||||
// Broadcast full Claude hook data to ALL clients
|
||||
// Process hook event and broadcast session state patch to ALL clients
|
||||
export function broadcastClaudeHook(data: Record<string, unknown>) {
|
||||
// ── Update centralized session state and broadcast patch ──
|
||||
const statePatch = sessionState.processHookEvent(data as any)
|
||||
broadcastSessionStatePatch(statePatch)
|
||||
|
||||
// ── Legacy raw broadcast (dual temporal — kept for backward compatibility) ──
|
||||
const message = JSON.stringify({
|
||||
type: 'claude-hook',
|
||||
...data,
|
||||
timestamp: Date.now()
|
||||
})
|
||||
|
||||
const clientCount = broadcastToAll(message)
|
||||
console.log(`[Terminal] Claude hook broadcast: ${data.hook_event_name || 'unknown'}${data.tool_name ? ` (${data.tool_name})` : ''} → ${clientCount} clients`)
|
||||
// Track agent running state in terminal sessions
|
||||
const agentName = (data.agent_name as string) || 'claude'
|
||||
const event = data.hook_event_name as string
|
||||
if (event === 'SessionStart' || event === 'SessionEnd') {
|
||||
const state = agentSessions.get(agentName)
|
||||
if (state) {
|
||||
state.isAgentRunning = event === 'SessionStart'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Broadcast transcript updates to ALL clients
|
||||
|
||||
Reference in New Issue
Block a user