feat(observer): v11 — enhanced context extraction + 5-level sibling search + command enrichment (v0.5.42) #task-619

- extractContextFromNearby: span/div/p text fallback when pre/code not found (depth 0-8)
- collectSiblingButtons: extended to 5 parent levels, stop only when both action+reject found
- http-bridge: command enrichment — swap generic button text with actual command from description
- Fixes: cmd='Always run' now shows actual command text, Cancel button detection improved
This commit is contained in:
Variet Worker
2026-04-15 06:20:47 +09:00
parent 02d9799f20
commit ed63f65975
3 changed files with 58 additions and 25 deletions

View File

@@ -314,6 +314,23 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
const rawDesc = (data.description || data.command || '').replace(/Deny|Allow Once|Allow This Conversation/gi, '').trim();
pending.command = `파일 접근 권한${rawDesc ? ': ' + rawDesc : ''}`;
}
// v11: Command enrichment — if command is just button text but description has actual content,
// swap them so Discord shows what's actually being executed
const descText = (pending.description || data.description || '').trim();
const cmdText = (pending.command || data.command || '').trim();
const GENERIC_BTN_RE = /^(?:Always\s*)?(?:Run|Allow|Accept|Approve)$/i;
if (GENERIC_BTN_RE.test(cmdText) && descText.length > 10 && descText !== cmdText) {
// Extract the actual command from description (often includes terminal prompt)
// Pattern: "…\project_name > actual_command"
let enrichedCmd = descText;
const promptMatch = descText.match(/[>»]\s*(.+)/);
if (promptMatch && promptMatch[1].trim().length > 3) {
enrichedCmd = promptMatch[1].trim();
}
pending.command = enrichedCmd.substring(0, 200);
pending.description = `[${cmdText}] ${descText}`;
ctx.logToFile(`[HTTP] command enriched: "${cmdText}" → "${enrichedCmd.substring(0, 60)}"`);
}
// WS dispatch
if (ctx.wsBridge && ctx.wsBridge.isConnected()) {
ctx.wsBridge.sendPending({
@@ -327,7 +344,8 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
});
ctx.logToFile(`[HTTP-WS] pending sent via WS: ${rid}`);
}
ctx.logToFile(`[HTTP] pending created: ${rid} cmd="${data.command}" btns=${(data.buttons || []).length} ctx="${(data.description || '').substring(0, 50)}"`);
ctx.logToFile(`[HTTP] pending created: ${rid} cmd="${pending.command || data.command}" btns=${(pending.buttons || data.buttons || []).length} ctx="${(pending.description || data.description || '').substring(0, 80)}"`);
if (data._debug_trail) {
ctx.logToFile(`[HTTP-DIAG] trail: ${data._debug_trail.substring(0, 500)}`);
}