fix: dedup file_permission pendings (10s window) + clean description text

This commit is contained in:
2026-03-10 13:21:18 +09:00
parent bec38f9a6a
commit e107b70510
3 changed files with 43 additions and 3 deletions

View File

@@ -481,13 +481,33 @@ function startObserverHttpBridge(): Promise<number> {
// File permission: inject multi-choice buttons
const cmdLower = (data.command || '').toLowerCase();
if (cmdLower.includes('allow') && !pending.buttons) {
// Dedup: skip if another file_permission pending was created within 10s
const nowMs = Date.now();
try {
const existingFiles = fs.readdirSync(pendingDir).filter((f: string) => f.endsWith('.json'));
for (const ef of existingFiles) {
const existing = JSON.parse(fs.readFileSync(path.join(pendingDir, ef), 'utf-8'));
if (existing.step_type === 'file_permission' && existing.status === 'pending') {
const age = nowMs - (existing.timestamp * 1000);
if (age < 10_000 && age >= 0) {
logToFile(`[HTTP] filtered duplicate file_permission (${age}ms old): ${ef}`);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: false, filtered: true, reason: 'dedup_file_permission' }));
return;
}
}
}
} catch { }
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}`;
// Clean description: remove button labels from text
const rawDesc = (data.description || data.command || '').replace(/Deny|Allow Once|Allow This Conversation/gi, '').trim();
pending.command = `파일 접근 권한${rawDesc ? ': ' + rawDesc : ''}`;
}
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)}"`);