feat: ClawTap v0.2.0
Interactive Prompts: - Unified InteractivePrompt type across all 3 adapters (Claude/Codex/Gemini) - InteractivePromptOverlay component with options, text input, countdown - Gemini + Codex pane monitors detect tool confirmation, ask user, plan approval - respondInteractivePrompt routing: permission → respondPermission, options → _selectOption - Claude AskUserQuestion nested questions[0] structure parsing Cross-AI Review: - Client-generated reviewId, removed pendingReview state - FloatingReviewPanel uses CSS display:none instead of unmount (keeps hooks alive) - Child review sessions default to YOLO/bypass permission mode - Send back to parent, send to existing/new review, tab switching, end review - Collapsed review cards with read-only panel for ended reviews - Full reconnect support: active + ended reviews restore correctly AskUserQuestion Tool Card UI: - Dedicated renderer replaces raw JSON display - Options shown with selected (green) / unselected (gray) indicators - Free text answers shown in quoted format with green border - Collapsed summary: question → answer - Shared parseAskQuestionInput utility (client + server) - Historical tool results attached via _result on tool_use blocks Adapter Fixes: - Session→adapter mapping persisted in SQLite (survives server restart) - SESSION_CREATED deferred for pendingRekey adapters (Codex/Gemini) - session-rekeyed handler sends complete SESSION_CREATED with adapter + cwd - Gemini: auto-accept folder trust, privacy notice, IDE nudge, YOLO * prompt - Claude: auto-accept bypass permissions confirmation (v2.1.85+) - Port fallback (EADDRINUSE → try +1), statusLine shell script wrapper Other: - Desktop Enter sends / Shift+Enter newline; Mobile Enter newline - Strip CLAWTAP_REF marker from session list - Active sessions tab shows adapter badge - Rename CLAUDE_UI_PASSWORD → CLAWTAP_PASSWORD Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import type { ReconnectState } from '../../types/adapter.js';
|
||||
import type { ActiveSessionInfo } from '../interface.js';
|
||||
import { isLargeContent } from '../interface.js';
|
||||
import { PermissionManager } from '../../permission-manager.js';
|
||||
import { findActiveSession } from '../shared/find-active-session.js';
|
||||
import { readFile } from 'fs/promises';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -149,7 +150,7 @@ export class CodexTmuxAdapter extends EventEmitter {
|
||||
|
||||
this._startMonitor(finalId, windowId);
|
||||
|
||||
return { sessionId: finalId };
|
||||
return { sessionId: finalId, pendingRekey: finalId === tempKey };
|
||||
}
|
||||
|
||||
async resumeSession(sessionId: string, cwd: string, options: QueryOptions = {}): Promise<{ sessionId: string }> {
|
||||
@@ -606,6 +607,23 @@ export class CodexTmuxAdapter extends EventEmitter {
|
||||
await tmuxManager.sendKeys(session.windowId, answer, true);
|
||||
}
|
||||
|
||||
respondInteractivePrompt(requestId: string, selectedOption?: string, textValue?: string): void {
|
||||
const pending = this._permissions.resolvePermission(requestId)
|
||||
|| this._permissions.resolveQuestion(requestId);
|
||||
const sessionId = pending?.sessionId || findActiveSession(this.sessions);
|
||||
if (!sessionId) return;
|
||||
const session = this.sessions.get(sessionId);
|
||||
if (!session) return;
|
||||
|
||||
if (selectedOption != null) {
|
||||
// Codex uses single-key shortcuts (y, a, p, d, n)
|
||||
tmuxManager.sendKeys(session.windowId, selectedOption, false).catch(() => {});
|
||||
}
|
||||
if (textValue != null) {
|
||||
tmuxManager.sendKeys(session.windowId, textValue, true).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
/** Release all pending requests for a session (e.g., when Mobile disconnects). */
|
||||
releaseAllPending(sessionId: string): void {
|
||||
this._permissions.dismissAll(sessionId);
|
||||
|
||||
@@ -87,10 +87,10 @@ export class CodexAdapter extends IAdapter {
|
||||
}
|
||||
|
||||
setup(app: Express): void {
|
||||
this.installHooks();
|
||||
this._registerHookRoutes(app);
|
||||
}
|
||||
|
||||
setHookPort(port: number | string): void { this._hookConfig.port = port; }
|
||||
installHooks(): void { this._hookConfig.install(); }
|
||||
uninstallHooks(): void { this._hookConfig.uninstall(); }
|
||||
|
||||
@@ -164,6 +164,7 @@ export class CodexAdapter extends IAdapter {
|
||||
async switchPermissionMode(sid: string, mode: string): Promise<boolean> { return this._tmux.switchPermissionMode(sid, mode); }
|
||||
respondPermission(reqId: string, behavior: PermissionBehavior): void { this._tmux.respondPermission(reqId, behavior); }
|
||||
async respondQuestion(reqId: string, answer: string): Promise<void> { return this._tmux.respondQuestion(reqId, answer); }
|
||||
respondInteractivePrompt(reqId: string, opt?: string, text?: string): void { this._tmux.respondInteractivePrompt(reqId, opt, text); }
|
||||
releaseAllPending(sid: string): void { this._tmux.releaseAllPending(sid); }
|
||||
resolveAllPendingAs(sid: string, behavior: PermissionBehavior): void { this._tmux.resolveAllPendingAs(sid, behavior); }
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { createReadStream } from 'fs';
|
||||
import { createInterface } from 'readline';
|
||||
import { stripMarker } from '../shared/content-utils.js';
|
||||
import { CodexTranscriptParser } from './transcript-parser.js';
|
||||
import type { CodexJsonlEntry } from './transcript-parser.js';
|
||||
import type { DirectoryEntry, MessagesResult } from '../interface.js';
|
||||
@@ -202,7 +203,7 @@ export async function getSessions(dir?: string, limit?: number): Promise<Session
|
||||
cwd,
|
||||
lastModified: entry.ts * 1000, // Convert to ms timestamp
|
||||
firstPrompt: entry.text
|
||||
? entry.text.replace(/^(?:\[CLAWTAP_REF:[^\]]+\]|\d+\])(?:\\n|\n)?/, '').slice(0, 200)
|
||||
? stripMarker(entry.text).slice(0, 200)
|
||||
: null,
|
||||
model,
|
||||
};
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
// that will be refined through empirical testing with the actual Codex TUI.
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { InteractivePrompt } from '../../types/messages.js';
|
||||
|
||||
function simpleHash(str: string): string {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
||||
hash |= 0;
|
||||
}
|
||||
return Math.abs(hash).toString(36);
|
||||
}
|
||||
|
||||
/** Minimal interface for the tmux manager dependency */
|
||||
interface TmuxCapture {
|
||||
@@ -42,6 +52,7 @@ export class CodexPaneMonitor {
|
||||
private interval: ReturnType<typeof setInterval> | null = null;
|
||||
private _lastContent: string = '';
|
||||
private _lastResponseText: string = '';
|
||||
private lastPromptId: string | null = null;
|
||||
|
||||
constructor(
|
||||
sessionId: string,
|
||||
@@ -84,7 +95,19 @@ export class CodexPaneMonitor {
|
||||
if (content === this._lastContent) return;
|
||||
this._lastContent = content;
|
||||
|
||||
// 1. Check for approval prompt (highest priority — blocks everything)
|
||||
// 0. Check for interactive prompt (highest priority)
|
||||
const interactivePrompt = this._detectPrompt(content);
|
||||
if (interactivePrompt) {
|
||||
if (interactivePrompt.requestId !== this.lastPromptId) {
|
||||
this.lastPromptId = interactivePrompt.requestId;
|
||||
this.emitter.emit('interactive-prompt', this.sessionId, interactivePrompt);
|
||||
}
|
||||
return; // Don't process streaming while prompt is showing
|
||||
} else if (this.lastPromptId) {
|
||||
this.lastPromptId = null;
|
||||
}
|
||||
|
||||
// 1. Check for approval prompt (legacy — kept for backwards compat)
|
||||
const approval = detectApprovalPrompt(content);
|
||||
if (approval) {
|
||||
this.emitter.emit('approval-prompt', this.sessionId, approval);
|
||||
@@ -108,6 +131,78 @@ export class CodexPaneMonitor {
|
||||
// Silently ignore — tmux window may have been killed
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect an interactive prompt in the Codex CLI pane content.
|
||||
* Returns an InteractivePrompt if one is detected, null otherwise.
|
||||
*/
|
||||
private _detectPrompt(content: string): InteractivePrompt | null {
|
||||
// Command/File/Network Approval: "(y)" with proceed/run/make patterns
|
||||
if (
|
||||
content.includes('(y)') &&
|
||||
(/proceed/i.test(content) || /Would you like to run/i.test(content) || /Would you like to make/i.test(content))
|
||||
) {
|
||||
const options = this._parseCodexOptions(content);
|
||||
const lines = content.split('\n');
|
||||
const tail = lines.slice(-20);
|
||||
const promptLine = tail.find(l => /proceed|\brun\b|\bmake\b/i.test(l)) || 'Approve action';
|
||||
const description = tail.join('\n').trim();
|
||||
return {
|
||||
requestId: `codex-perm-${simpleHash(description)}`,
|
||||
promptType: 'permission',
|
||||
title: typeof promptLine === 'string' ? promptLine.trim() : 'Approve action',
|
||||
description,
|
||||
options: options.length > 0 ? options : [
|
||||
{ value: 'y', label: 'Yes' },
|
||||
{ value: 'n', label: 'No' },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
// User Input: "enter to submit" AND "esc to cancel" (but NOT approval patterns)
|
||||
if (
|
||||
/enter to submit/i.test(content) &&
|
||||
/esc to cancel/i.test(content) &&
|
||||
!content.includes('(y)')
|
||||
) {
|
||||
const lines = content.split('\n');
|
||||
const tail = lines.slice(-20);
|
||||
const options = this._parseCodexOptions(content);
|
||||
const description = tail.join('\n').trim();
|
||||
if (options.length > 0) {
|
||||
return {
|
||||
requestId: `codex-ask-${simpleHash(description)}`,
|
||||
promptType: 'question',
|
||||
title: 'User Input',
|
||||
description,
|
||||
options,
|
||||
};
|
||||
}
|
||||
return {
|
||||
requestId: `codex-ask-${simpleHash(description)}`,
|
||||
promptType: 'question',
|
||||
title: 'User Input',
|
||||
description,
|
||||
textInput: { placeholder: 'Type your response...' },
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Codex-style options from content.
|
||||
* Matches patterns like "(y) Yes" or "(a) Always approve".
|
||||
*/
|
||||
private _parseCodexOptions(content: string): { value: string; label: string }[] {
|
||||
const results: { value: string; label: string }[] = [];
|
||||
const regex = /\(([a-z])\)\s+(.+?)(?:\n|$)/g;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = regex.exec(content)) !== null) {
|
||||
results.push({ value: match[1]!, label: match[2]!.trim() });
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user