feat: 3-button file permission UX (Allow Once / Allow This Conversation / Deny)

This commit is contained in:
2026-03-10 12:45:12 +09:00
parent c9b4fd4722
commit 14d2acf6c4
3 changed files with 51 additions and 16 deletions

View File

@@ -496,6 +496,17 @@ function startObserverHttpBridge() {
auto_detected: true, auto_detected: true,
source: 'dom_observer', source: 'dom_observer',
}; };
// File permission: inject multi-choice buttons
const cmdLower = (data.command || '').toLowerCase();
if (cmdLower.includes('allow') && !pending.buttons) {
pending.buttons = [
{ text: 'Allow Once', index: 0 },
{ text: 'Allow This Conversation', index: 1 },
{ text: 'Deny', index: 2 },
];
pending.step_type = 'file_permission';
pending.command = `파일 접근 권한: ${data.description || data.command}`;
}
fs.writeFileSync(path.join(pendingDir, `${rid}.json`), JSON.stringify(pending, null, 2)); fs.writeFileSync(path.join(pendingDir, `${rid}.json`), JSON.stringify(pending, null, 2));
logToFile(`[HTTP] pending created: ${rid} cmd="${data.command}" btns=${(data.buttons || []).length} ctx="${(data.description || '').substring(0, 50)}"`); logToFile(`[HTTP] pending created: ${rid} cmd="${data.command}" btns=${(data.buttons || []).length} ctx="${(data.description || '').substring(0, 50)}"`);
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });
@@ -1989,16 +2000,22 @@ async function processResponseFile(filePath) {
pendingStepIndex = pending.step_index ?? lastPendingStepIndex; pendingStepIndex = pending.step_index ?? lastPendingStepIndex;
if (!pendingStepType && pending.command) { if (!pendingStepType && pending.command) {
const cmd = (pending.command || '').toLowerCase(); const cmd = (pending.command || '').toLowerCase();
if (cmd.includes('allow this conversation')) { if (cmd.includes('allow') || cmd.includes('파일 접근') || pending.step_type === 'file_permission') {
// Map button_index → scope: 0=Once, 1=Conversation, 2=Deny
const btnIdx = resp.button_index ?? -1;
if (btnIdx === 1) {
pendingStepType = 'file_permission_conversation'; pendingStepType = 'file_permission_conversation';
} }
else if (cmd.includes('allow once')) { else {
pendingStepType = 'file_permission_once'; pendingStepType = 'file_permission_once';
} }
else if (cmd.includes('allow')) {
pendingStepType = 'file_permission_once'; // default to once
} }
} }
// Also handle when step_type was explicitly set
if (pendingStepType === 'file_permission') {
const btnIdx = resp.button_index ?? -1;
pendingStepType = btnIdx === 1 ? 'file_permission_conversation' : 'file_permission_once';
}
} }
catch { } catch { }
} }

File diff suppressed because one or more lines are too long

View File

@@ -465,7 +465,7 @@ function startObserverHttpBridge(): Promise<number> {
// Write pending file for Discord bot // Write pending file for Discord bot
const pendingDir = path.join(bridgePath, 'pending'); const pendingDir = path.join(bridgePath, 'pending');
if (!fs.existsSync(pendingDir)) fs.mkdirSync(pendingDir, { recursive: true }); if (!fs.existsSync(pendingDir)) fs.mkdirSync(pendingDir, { recursive: true });
const pending = { const pending: Record<string, any> = {
...data, ...data,
request_id: rid, request_id: rid,
conversation_id: activeSessionId || '', conversation_id: activeSessionId || '',
@@ -475,6 +475,17 @@ function startObserverHttpBridge(): Promise<number> {
auto_detected: true, auto_detected: true,
source: 'dom_observer', source: 'dom_observer',
}; };
// File permission: inject multi-choice buttons
const cmdLower = (data.command || '').toLowerCase();
if (cmdLower.includes('allow') && !pending.buttons) {
pending.buttons = [
{ text: 'Allow Once', index: 0 },
{ text: 'Allow This Conversation', index: 1 },
{ text: 'Deny', index: 2 },
];
pending.step_type = 'file_permission';
pending.command = `파일 접근 권한: ${data.description || data.command}`;
}
fs.writeFileSync(path.join(pendingDir, `${rid}.json`), JSON.stringify(pending, null, 2)); fs.writeFileSync(path.join(pendingDir, `${rid}.json`), JSON.stringify(pending, null, 2));
logToFile(`[HTTP] pending created: ${rid} cmd="${data.command}" btns=${(data.buttons || []).length} ctx="${(data.description || '').substring(0, 50)}"`); logToFile(`[HTTP] pending created: ${rid} cmd="${data.command}" btns=${(data.buttons || []).length} ctx="${(data.description || '').substring(0, 50)}"`);
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });
@@ -1945,14 +1956,21 @@ async function processResponseFile(filePath: string) {
pendingStepIndex = pending.step_index ?? lastPendingStepIndex; pendingStepIndex = pending.step_index ?? lastPendingStepIndex;
if (!pendingStepType && pending.command) { if (!pendingStepType && pending.command) {
const cmd = (pending.command || '').toLowerCase(); const cmd = (pending.command || '').toLowerCase();
if (cmd.includes('allow this conversation')) { if (cmd.includes('allow') || cmd.includes('파일 접근') || pending.step_type === 'file_permission') {
// Map button_index → scope: 0=Once, 1=Conversation, 2=Deny
const btnIdx = resp.button_index ?? -1;
if (btnIdx === 1) {
pendingStepType = 'file_permission_conversation'; pendingStepType = 'file_permission_conversation';
} else if (cmd.includes('allow once')) { } else {
pendingStepType = 'file_permission_once'; pendingStepType = 'file_permission_once';
} else if (cmd.includes('allow')) {
pendingStepType = 'file_permission_once'; // default to once
} }
} }
}
// Also handle when step_type was explicitly set
if (pendingStepType === 'file_permission') {
const btnIdx = resp.button_index ?? -1;
pendingStepType = btnIdx === 1 ? 'file_permission_conversation' : 'file_permission_once';
}
} catch { } } catch { }
} }