fix(bridge): Always run auto-approve now checks buttons array, not just rawCmd (v0.5.58) #task-634
This commit is contained in:
@@ -361,11 +361,22 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
|
||||
buttons: data.buttons,
|
||||
step_index: ctx.lastPendingStepIndex >= 0 ? ctx.lastPendingStepIndex : undefined,
|
||||
};
|
||||
// v17: "Always run" auto-approve — click button immediately without Discord roundtrip
|
||||
// rawCmd is the original button text before enrichment. "Always run" means the user
|
||||
// already trusts this command pattern, so we auto-approve at the bridge level.
|
||||
// v17+: "Always run" auto-approve — click button immediately without Discord roundtrip
|
||||
// Check rawCmd first, then fall back to scanning the buttons array
|
||||
// (Observer may detect "Run" first while "Always run" is a sibling button)
|
||||
let alwaysRunIndex = -1;
|
||||
if (/^Always\s+run$/i.test(rawCmd)) {
|
||||
ctx.logToFile(`[HTTP] AUTO-APPROVE "Always run": enriched="${enrichedCmd.substring(0, 80)}"`);
|
||||
alwaysRunIndex = 0;
|
||||
} else if (Array.isArray(data.buttons)) {
|
||||
for (let bi = 0; bi < data.buttons.length; bi++) {
|
||||
if (/^Always\s+run$/i.test((data.buttons[bi].text || '').trim())) {
|
||||
alwaysRunIndex = bi;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alwaysRunIndex >= 0) {
|
||||
ctx.logToFile(`[HTTP] AUTO-APPROVE "Always run" (btnIdx=${alwaysRunIndex}): enriched="${enrichedCmd.substring(0, 80)}"`);
|
||||
// Write response file so observer's pollResponseGroup picks it up and clicks the button
|
||||
const responseDir = path.join(ctx.bridgePath, 'response');
|
||||
if (!fs.existsSync(responseDir)) {
|
||||
@@ -374,7 +385,7 @@ function _handlePending(req: any, res: any, ctx: HttpBridgeContext) {
|
||||
const respPayload = {
|
||||
request_id: rid,
|
||||
approved: true,
|
||||
button_index: 0, // "Always run" is always the first button
|
||||
button_index: alwaysRunIndex,
|
||||
step_type: data.step_type || 'command',
|
||||
project_name: ctx.projectName,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user