refactor: unify hook notification system, remove duplicate broadcasts
- Replace forward-hook.ps1 with notify.ps1 (now accepts optional agent param) - Remove ejecutor settings.local.json (redundant status hooks, deriveStatus covers it) - Remove legacy claude-permission system (route, store methods, terminal broadcast) - Remove redundant deriveStatus + /claude-status POST from claude-hook.ts (broadcastClaudeHook → processHookEvent already handles status derivation) - Clean up HookNotifications.vue permission buttons (dead code)
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -84,7 +84,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 ejecutor",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 ejecutor",
|
||||||
"timeout": 10000
|
"timeout": 10000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
{
|
|
||||||
"hooks": {
|
|
||||||
"UserPromptSubmit": [
|
|
||||||
{
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "powershell -NoProfile -Command \"try { Invoke-RestMethod -Uri 'http://localhost:4101/api/claude-status' -Method POST -Body '{\\\"status\\\":\\\"thinking\\\",\\\"agent\\\":\\\"ejecutor\\\"}' -ContentType 'application/json' -TimeoutSec 2 | Out-Null } catch {}\"",
|
|
||||||
"timeout": 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"PreToolUse": [
|
|
||||||
{
|
|
||||||
"matcher": ".*",
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "powershell -NoProfile -Command \"try { Invoke-RestMethod -Uri 'http://localhost:4101/api/claude-status' -Method POST -Body '{\\\"status\\\":\\\"toolUse\\\",\\\"tool\\\":\\\"$CLAUDE_TOOL_NAME\\\",\\\"agent\\\":\\\"ejecutor\\\"}' -ContentType 'application/json' -TimeoutSec 2 | Out-Null } catch {}\"",
|
|
||||||
"timeout": 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"PostToolUse": [
|
|
||||||
{
|
|
||||||
"matcher": ".*",
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "powershell -NoProfile -Command \"try { Invoke-RestMethod -Uri 'http://localhost:4101/api/claude-status' -Method POST -Body '{\\\"status\\\":\\\"thinking\\\",\\\"tool\\\":\\\"$CLAUDE_TOOL_NAME\\\",\\\"agent\\\":\\\"ejecutor\\\"}' -ContentType 'application/json' -TimeoutSec 2 | Out-Null } catch {}\"",
|
|
||||||
"timeout": 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"PostToolUseFailure": [
|
|
||||||
{
|
|
||||||
"matcher": ".*",
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "powershell -NoProfile -Command \"try { Invoke-RestMethod -Uri 'http://localhost:4101/api/claude-status' -Method POST -Body '{\\\"status\\\":\\\"error\\\",\\\"tool\\\":\\\"$CLAUDE_TOOL_NAME\\\",\\\"agent\\\":\\\"ejecutor\\\"}' -ContentType 'application/json' -TimeoutSec 2 | Out-Null } catch {}\"",
|
|
||||||
"timeout": 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"SessionEnd": [
|
|
||||||
{
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "powershell -NoProfile -Command \"try { Invoke-RestMethod -Uri 'http://localhost:4101/api/claude-status' -Method POST -Body '{\\\"status\\\":\\\"sessionEnd\\\",\\\"agent\\\":\\\"ejecutor\\\"}' -ContentType 'application/json' -TimeoutSec 2 | Out-Null } catch {}\"",
|
|
||||||
"timeout": 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Stop": [
|
|
||||||
{
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "powershell -NoProfile -Command \"try { Invoke-RestMethod -Uri 'http://localhost:4101/api/claude-status' -Method POST -Body '{\\\"status\\\":\\\"idle\\\",\\\"agent\\\":\\\"ejecutor\\\"}' -ContentType 'application/json' -TimeoutSec 2 | Out-Null } catch {}\"",
|
|
||||||
"timeout": 5000
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -94,7 +94,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 5000
|
"timeout": 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -115,7 +115,7 @@
|
|||||||
"hooks": [
|
"hooks": [
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "powershell -NoProfile -File hooks/forward-hook.ps1 nucleo000",
|
"command": "powershell -NoProfile -File hooks/notify.ps1 nucleo000",
|
||||||
"timeout": 10000
|
"timeout": 10000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -83,14 +83,8 @@ function typeClass(n: HookNotification) {
|
|||||||
<span v-if="n.detail" class="toast-detail">{{ n.detail }}</span>
|
<span v-if="n.detail" class="toast-detail">{{ n.detail }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Permission buttons -->
|
|
||||||
<div v-if="n.event === 'PermissionRequest' && n.requestId" class="toast-actions">
|
|
||||||
<button class="toast-btn toast-btn--allow" @click="store.respondPermission(n.id, n.requestId!, 'allow')">Allow</button>
|
|
||||||
<button class="toast-btn toast-btn--deny" @click="store.respondPermission(n.id, n.requestId!, 'deny')">Deny</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Dismiss -->
|
<!-- Dismiss -->
|
||||||
<button v-else class="toast-close" @click="store.remove(n.id)">×</button>
|
<button class="toast-close" @click="store.remove(n.id)">×</button>
|
||||||
</div>
|
</div>
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { apiFetch } from '@/lib/tauri'
|
|
||||||
|
|
||||||
export interface HookNotification {
|
export interface HookNotification {
|
||||||
id: string
|
id: string
|
||||||
@@ -11,10 +10,6 @@ export interface HookNotification {
|
|||||||
type: 'info' | 'success' | 'warning' | 'error'
|
type: 'info' | 'success' | 'warning' | 'error'
|
||||||
timestamp: number
|
timestamp: number
|
||||||
persistent?: boolean
|
persistent?: boolean
|
||||||
// Permission-specific
|
|
||||||
requestId?: string
|
|
||||||
toolName?: string
|
|
||||||
toolInput?: unknown
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useClaudeHooksStore = defineStore('claude-hooks', () => {
|
export const useClaudeHooksStore = defineStore('claude-hooks', () => {
|
||||||
@@ -144,47 +139,7 @@ export const useClaudeHooksStore = defineStore('claude-hooks', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process a claude-permission WS message
|
return { notifications, visible, add, remove, clear, processHook }
|
||||||
function processPermission(data: Record<string, any>) {
|
|
||||||
const id = `perm_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`
|
|
||||||
const toolName = data.tool_name || 'Unknown'
|
|
||||||
const input = data.tool_input || {}
|
|
||||||
let detail = ''
|
|
||||||
if (toolName === 'Bash') {
|
|
||||||
const cmd = input.command || ''
|
|
||||||
detail = cmd.length > 120 ? cmd.slice(0, 120) + '...' : cmd
|
|
||||||
} else if (toolName === 'Edit' || toolName === 'Write') {
|
|
||||||
detail = input.file_path ? shortPath(input.file_path) : ''
|
|
||||||
} else {
|
|
||||||
detail = JSON.stringify(input).slice(0, 100)
|
|
||||||
}
|
|
||||||
|
|
||||||
add({
|
|
||||||
id, event: 'PermissionRequest', type: 'error',
|
|
||||||
icon: '', title: `Permission: ${toolName}`,
|
|
||||||
detail,
|
|
||||||
timestamp: Date.now(),
|
|
||||||
persistent: true,
|
|
||||||
requestId: data.requestId,
|
|
||||||
toolName,
|
|
||||||
toolInput: input
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function respondPermission(notifId: string, requestId: string, decision: 'allow' | 'deny') {
|
|
||||||
try {
|
|
||||||
await apiFetch('/api/claude-permission-respond', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ requestId, decision })
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[Hooks] Failed to respond permission:', e)
|
|
||||||
}
|
|
||||||
remove(notifId)
|
|
||||||
}
|
|
||||||
|
|
||||||
return { notifications, visible, add, remove, clear, processHook, processPermission, respondPermission }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function shortPath(p: string): string {
|
function shortPath(p: string): string {
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
# Forward hook stdin to agent-ui backend (fire-and-forget)
|
|
||||||
# Usage: powershell -NoProfile -File hooks/forward-hook.ps1 <agent>
|
|
||||||
param([string]$agent = "ejecutor")
|
|
||||||
$b = [Console]::In.ReadToEnd()
|
|
||||||
try {
|
|
||||||
Invoke-RestMethod -Uri "http://localhost:4101/api/claude-hook?agent=$agent" -Method POST -Body $b -ContentType 'application/json' -TimeoutSec 3 | Out-Null
|
|
||||||
} catch {}
|
|
||||||
@@ -2,7 +2,7 @@ import { jsonResponse, errorResponse } from '../utils/cors'
|
|||||||
import { PORT_TERMINAL } from '../config'
|
import { PORT_TERMINAL } from '../config'
|
||||||
import { existsSync, readFileSync } from 'fs'
|
import { existsSync, readFileSync } from 'fs'
|
||||||
import { setActiveSession, getIncrementalMessages } from '../services/transcript-engine'
|
import { setActiveSession, getIncrementalMessages } from '../services/transcript-engine'
|
||||||
import { deriveStatus, sessionState, type HookPayload } from '../services/session-state'
|
import { sessionState, type HookPayload } from '../services/session-state'
|
||||||
|
|
||||||
export async function handleClaudeHook(req: Request): Promise<Response | null> {
|
export async function handleClaudeHook(req: Request): Promise<Response | null> {
|
||||||
if (req.method !== 'POST') return null
|
if (req.method !== 'POST') return null
|
||||||
@@ -68,34 +68,7 @@ export async function handleClaudeHook(req: Request): Promise<Response | null> {
|
|||||||
console.error('[claude-hook] Failed to forward hook to terminal server:', e)
|
console.error('[claude-hook] Failed to forward hook to terminal server:', e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Forward PermissionRequest to /claude-permission for hooks approval system
|
// 2. Incremental transcript reading for real-time chat
|
||||||
if (body.hook_event_name === 'PermissionRequest') {
|
|
||||||
try {
|
|
||||||
await fetch(`http://localhost:${PORT_TERMINAL}/claude-permission`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify(hookData)
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[claude-hook] Failed to forward permission to terminal server:', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Derive status and broadcast via WebSocket
|
|
||||||
const derived = deriveStatus(body)
|
|
||||||
if (derived) {
|
|
||||||
try {
|
|
||||||
await fetch(`http://localhost:${PORT_TERMINAL}/claude-status`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ status: derived.status, tool: derived.tool, agent })
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[claude-hook] Failed to forward status to terminal server:', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Incremental transcript reading for real-time chat
|
|
||||||
if (body.session_id && body.transcript_path) {
|
if (body.session_id && body.transcript_path) {
|
||||||
setActiveSession(agent, body.session_id, body.transcript_path as string)
|
setActiveSession(agent, body.session_id, body.transcript_path as string)
|
||||||
|
|
||||||
|
|||||||
@@ -1,111 +0,0 @@
|
|||||||
import { jsonResponse, errorResponse } from '../utils/cors'
|
|
||||||
import { PORT_TERMINAL } from '../config'
|
|
||||||
|
|
||||||
interface PermissionPayload {
|
|
||||||
hook_event_name?: string
|
|
||||||
session_id?: string
|
|
||||||
tool_name?: string
|
|
||||||
tool_input?: unknown
|
|
||||||
cwd?: string
|
|
||||||
[key: string]: unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PendingPermission {
|
|
||||||
resolve: (decision: string) => void
|
|
||||||
timer: ReturnType<typeof setTimeout>
|
|
||||||
payload: PermissionPayload
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map of requestId -> pending permission promise resolver
|
|
||||||
const pendingPermissions = new Map<string, PendingPermission>()
|
|
||||||
|
|
||||||
const PERMISSION_TIMEOUT_MS = 60_000
|
|
||||||
|
|
||||||
export async function handleClaudePermission(req: Request): Promise<Response | null> {
|
|
||||||
if (req.method !== 'POST') return null
|
|
||||||
|
|
||||||
try {
|
|
||||||
const body = await req.json() as PermissionPayload
|
|
||||||
const requestId = `perm_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`
|
|
||||||
|
|
||||||
// Broadcast permission request to UI via WebSocket
|
|
||||||
try {
|
|
||||||
await fetch(`http://localhost:${PORT_TERMINAL}/claude-permission`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ requestId, ...body })
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[claude-permission] Failed to broadcast to terminal server:', e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also broadcast claude-status for backward compat (animations)
|
|
||||||
try {
|
|
||||||
await fetch(`http://localhost:${PORT_TERMINAL}/claude-status`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ status: 'permissionRequest', tool: body.tool_name })
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
console.error('[claude-permission] Failed to forward status:', e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for UI decision (or timeout)
|
|
||||||
const decision = await new Promise<string>((resolve) => {
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
pendingPermissions.delete(requestId)
|
|
||||||
resolve('ask')
|
|
||||||
}, PERMISSION_TIMEOUT_MS)
|
|
||||||
|
|
||||||
pendingPermissions.set(requestId, { resolve, timer, payload: body })
|
|
||||||
})
|
|
||||||
|
|
||||||
return jsonResponse({ decision, requestId })
|
|
||||||
} catch (e) {
|
|
||||||
return errorResponse('Invalid JSON body', 400)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function handleClaudePermissionRespond(req: Request): Promise<Response | null> {
|
|
||||||
if (req.method !== 'POST') return null
|
|
||||||
|
|
||||||
try {
|
|
||||||
const body = await req.json() as { requestId: string, decision: 'allow' | 'deny' }
|
|
||||||
|
|
||||||
if (!body.requestId || !body.decision) {
|
|
||||||
return errorResponse('Missing requestId or decision', 400)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!['allow', 'deny'].includes(body.decision)) {
|
|
||||||
return errorResponse('Decision must be "allow" or "deny"', 400)
|
|
||||||
}
|
|
||||||
|
|
||||||
const pending = pendingPermissions.get(body.requestId)
|
|
||||||
if (!pending) {
|
|
||||||
return errorResponse('Permission request not found or already expired', 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve the pending promise
|
|
||||||
clearTimeout(pending.timer)
|
|
||||||
pendingPermissions.delete(body.requestId)
|
|
||||||
pending.resolve(body.decision)
|
|
||||||
|
|
||||||
return jsonResponse({ success: true, requestId: body.requestId, decision: body.decision })
|
|
||||||
} catch (e) {
|
|
||||||
return errorResponse('Invalid JSON body', 400)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// List pending permissions (useful for UI to recover state)
|
|
||||||
export async function handleClaudePermissionList(req: Request): Promise<Response | null> {
|
|
||||||
if (req.method !== 'GET') return null
|
|
||||||
|
|
||||||
const pending = Array.from(pendingPermissions.entries()).map(([id, p]) => ({
|
|
||||||
requestId: id,
|
|
||||||
tool_name: p.payload.tool_name,
|
|
||||||
tool_input: p.payload.tool_input,
|
|
||||||
session_id: p.payload.session_id
|
|
||||||
}))
|
|
||||||
|
|
||||||
return jsonResponse({ pending })
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@ import { handleWhisperRoutes } from './whisper'
|
|||||||
import { handleRecordingsRoutes } from './recordings'
|
import { handleRecordingsRoutes } from './recordings'
|
||||||
import { handleClaudeStatus } from './claude-status'
|
import { handleClaudeStatus } from './claude-status'
|
||||||
import { handleClaudeHook } from './claude-hook'
|
import { handleClaudeHook } from './claude-hook'
|
||||||
import { handleClaudePermission, handleClaudePermissionRespond, handleClaudePermissionList } from './claude-permission'
|
|
||||||
import { handleSnapshots, handleSnapshotById } from './snapshots'
|
import { handleSnapshots, handleSnapshotById } from './snapshots'
|
||||||
import { handleGitStatus, handleGitDiff, handleGitLog, handleGitLogCommit, handleGitCompare, handleGitBranches, handleGitCurrentBranch, handleGitTree, handleGitFile } from './git'
|
import { handleGitStatus, handleGitDiff, handleGitLog, handleGitLogCommit, handleGitCompare, handleGitBranches, handleGitCurrentBranch, handleGitTree, handleGitFile } from './git'
|
||||||
import {
|
import {
|
||||||
@@ -81,22 +80,6 @@ export async function handleRequest(req: Request): Promise<Response> {
|
|||||||
if (res) return res
|
if (res) return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claude Code permission request/respond
|
|
||||||
if (path === '/api/claude-permission') {
|
|
||||||
if (req.method === 'GET') {
|
|
||||||
const res = await handleClaudePermissionList(req)
|
|
||||||
if (res) return res
|
|
||||||
} else {
|
|
||||||
const res = await handleClaudePermission(req)
|
|
||||||
if (res) return res
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path === '/api/claude-permission-respond') {
|
|
||||||
const res = await handleClaudePermissionRespond(req)
|
|
||||||
if (res) return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
if (path === '/api/components') {
|
if (path === '/api/components') {
|
||||||
const res = await handleComponents(req)
|
const res = await handleComponents(req)
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ export async function startAgentInSession(agentId: string, force = false): Promi
|
|||||||
|
|
||||||
export function startTerminalServer() {
|
export function startTerminalServer() {
|
||||||
const server = Bun.serve({
|
const server = Bun.serve({
|
||||||
|
hostname: '0.0.0.0',
|
||||||
port: PORT_TERMINAL,
|
port: PORT_TERMINAL,
|
||||||
async fetch(req, server) {
|
async fetch(req, server) {
|
||||||
const url = new URL(req.url)
|
const url = new URL(req.url)
|
||||||
@@ -316,17 +317,6 @@ export function startTerminalServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claude permission request broadcast endpoint
|
|
||||||
if (url.pathname === '/claude-permission' && req.method === 'POST') {
|
|
||||||
try {
|
|
||||||
const body = await req.json()
|
|
||||||
broadcastPermissionRequest(body)
|
|
||||||
return Response.json({ success: true }, { headers: corsHeaders })
|
|
||||||
} catch {
|
|
||||||
return Response.json({ error: 'Invalid JSON' }, { status: 400, headers: corsHeaders })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Agent sessions info
|
// Agent sessions info
|
||||||
if (url.pathname === '/agent-sessions' && req.method === 'GET') {
|
if (url.pathname === '/agent-sessions' && req.method === 'GET') {
|
||||||
const result: Record<string, any> = {}
|
const result: Record<string, any> = {}
|
||||||
@@ -762,8 +752,6 @@ export function broadcastClaudeStatus(status: ClaudeStatus, tool?: string, agent
|
|||||||
console.log(`[Terminal] Claude status broadcast: ${status}${tool ? ` (${tool})` : ''} → ${clientCount} clients`)
|
console.log(`[Terminal] Claude status broadcast: ${status}${tool ? ` (${tool})` : ''} → ${clientCount} clients`)
|
||||||
|
|
||||||
// Note: session state is updated via broadcastClaudeHook which has full payload context.
|
// Note: session state is updated via broadcastClaudeHook which has full payload context.
|
||||||
// Direct /claude-status POSTs (from ejecutor's settings.local.json) are lightweight
|
|
||||||
// and don't carry enough context to update full session state.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast full Claude hook data to ALL clients
|
// Broadcast full Claude hook data to ALL clients
|
||||||
@@ -783,18 +771,6 @@ export function broadcastClaudeHook(data: Record<string, unknown>) {
|
|||||||
console.log(`[Terminal] Claude hook broadcast: ${data.hook_event_name || 'unknown'}${data.tool_name ? ` (${data.tool_name})` : ''} → ${clientCount} clients`)
|
console.log(`[Terminal] Claude hook broadcast: ${data.hook_event_name || 'unknown'}${data.tool_name ? ` (${data.tool_name})` : ''} → ${clientCount} clients`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast permission request to ALL clients
|
|
||||||
export function broadcastPermissionRequest(data: Record<string, unknown>) {
|
|
||||||
const message = JSON.stringify({
|
|
||||||
type: 'claude-permission',
|
|
||||||
...data,
|
|
||||||
timestamp: Date.now()
|
|
||||||
})
|
|
||||||
|
|
||||||
const clientCount = broadcastToAll(message)
|
|
||||||
console.log(`[Terminal] Permission request broadcast: ${data.tool_name || 'unknown'} (${data.requestId}) → ${clientCount} clients`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Broadcast transcript updates to ALL clients
|
// Broadcast transcript updates to ALL clients
|
||||||
export function broadcastTranscriptUpdate(data: Record<string, unknown>) {
|
export function broadcastTranscriptUpdate(data: Record<string, unknown>) {
|
||||||
const message = JSON.stringify({
|
const message = JSON.stringify({
|
||||||
|
|||||||
Reference in New Issue
Block a user