fix(ext): WS response → tryApprovalStrategies 직접 호출 (파일 경유 제거)

This commit is contained in:
Variet Worker
2026-03-17 17:43:45 +09:00
parent adbed69237
commit 2eea5fa638
4 changed files with 46 additions and 27 deletions

View File

@@ -18,7 +18,7 @@ import * as cp from 'child_process';
import * as crypto from 'crypto';
import { WSBridgeClient, WSResponseData, WSCommandData } from './ws-client';
import { generateApprovalObserverScript } from './observer-script';
import { initStepProbe, BridgeContext, writePendingApproval, tryApprovalStrategies, writeRegistration } from './step-probe';
import { initStepProbe, BridgeContext, writePendingApproval, tryApprovalStrategies, writeRegistration, getApprovalContext, resetPendingState } from './step-probe';
// ─── File-based logging (AI can read directly) ───
function logToFile(msg: string) {
@@ -1053,17 +1053,18 @@ export async function activate(context: vscode.ExtensionContext) {
const regCode = process.env.GRAVITY_REGISTRATION_CODE || config.get<string>('registrationCode') || '';
const pcName = os.hostname();
if (hubUrl) {
wsBridge = new WSBridgeClient(hubUrl, regCode, projectName, pcName, {
onResponse: (data: WSResponseData) => {
logToFile(`[WS-RESPONSE] ${data.request_id?.substring(0, 12)} approved=${data.approved}`);
// Route to processResponseFile logic — write temp response file for compatibility
try {
const responseDir = path.join(bridgePath, 'response');
if (!fs.existsSync(responseDir)) { fs.mkdirSync(responseDir, { recursive: true }); }
const responseFile = path.join(responseDir, `${data.request_id}.json`);
fs.writeFileSync(responseFile, JSON.stringify(data, null, 2), 'utf-8');
logToFile(`[WS-RESPONSE] Written response file for processing`);
} catch (e: any) {
wsBridge = new WSBridgeClient(hubUrl, regCode, projectName, pcName, {
onResponse: (data: WSResponseData) => {
logToFile(`[WS-RESPONSE] ${data.request_id?.substring(0, 12)} approved=${data.approved} step_type=${data.step_type || '(none)'}`);
// Direct approval — WS path has no pending file, so call tryApprovalStrategies directly
const approved = data.approved ?? true;
const stepType = data.step_type || '';
const approvalCtx = getApprovalContext();
logToFile(`[WS-RESPONSE] Triggering approval: approved=${approved} session=${approvalCtx.sessionId.substring(0, 8)} stepType=${stepType} stepIndex=${approvalCtx.stepIndex}`);
tryApprovalStrategies(approved, approvalCtx.sessionId, stepType, approvalCtx.stepIndex)
.then(result => {
logToFile(`[WS-RESPONSE] Approval result: ${result}`);
resetPendingState();
})
.catch(err => logToFile(`[WS-RESPONSE] Approval error: ${err.message}`));
},

View File

@@ -41,6 +41,26 @@ const lastSeenStep = new Map<string, number>();
const lastSnapshotText = new Map<string, string>();
const registeredSessions = new Set<string>(); // track which sessions have been registered
/**
* Get current approval context for WS response routing.
* Used by extension.ts onResponse handler to call tryApprovalStrategies.
*/
export function getApprovalContext(): { sessionId: string; stepIndex: number } {
return {
sessionId: ctx.activeSessionId || '',
stepIndex: ctx.lastPendingStepIndex ?? -1,
};
}
/**
* Reset pending state after successful approval.
* Called after WS response triggers approval in extension.ts.
*/
export function resetPendingState(): void {
ctx.stallProbed = false;
ctx.sawRunningAfterPending = false;
}
/**
* Write a registration file for the Bot to discover session → project mapping.
* Called automatically on first step event per session.