fix(ext): WS response → tryApprovalStrategies 직접 호출 (파일 경유 제거)
This commit is contained in:
@@ -1059,20 +1059,18 @@ async function activate(context) {
|
|||||||
if (hubUrl) {
|
if (hubUrl) {
|
||||||
wsBridge = new ws_client_1.WSBridgeClient(hubUrl, regCode, projectName, pcName, {
|
wsBridge = new ws_client_1.WSBridgeClient(hubUrl, regCode, projectName, pcName, {
|
||||||
onResponse: (data) => {
|
onResponse: (data) => {
|
||||||
logToFile(`[WS-RESPONSE] ${data.request_id?.substring(0, 12)} approved=${data.approved}`);
|
logToFile(`[WS-RESPONSE] ${data.request_id?.substring(0, 12)} approved=${data.approved} step_type=${data.step_type || '(none)'}`);
|
||||||
// Route to processResponseFile logic — write temp response file for compatibility
|
// Direct approval — WS path has no pending file, so call tryApprovalStrategies directly
|
||||||
try {
|
const approved = data.approved ?? true;
|
||||||
const responseDir = path.join(bridgePath, 'response');
|
const stepType = data.step_type || '';
|
||||||
if (!fs.existsSync(responseDir)) {
|
const approvalCtx = (0, step_probe_1.getApprovalContext)();
|
||||||
fs.mkdirSync(responseDir, { recursive: true });
|
logToFile(`[WS-RESPONSE] Triggering approval: approved=${approved} session=${approvalCtx.sessionId.substring(0, 8)} stepType=${stepType} stepIndex=${approvalCtx.stepIndex}`);
|
||||||
}
|
(0, step_probe_1.tryApprovalStrategies)(approved, approvalCtx.sessionId, stepType, approvalCtx.stepIndex)
|
||||||
const responseFile = path.join(responseDir, `${data.request_id}.json`);
|
.then(result => {
|
||||||
fs.writeFileSync(responseFile, JSON.stringify(data, null, 2), 'utf-8');
|
logToFile(`[WS-RESPONSE] Approval result: ${result}`);
|
||||||
logToFile(`[WS-RESPONSE] Written response file for processing`);
|
(0, step_probe_1.resetPendingState)();
|
||||||
}
|
})
|
||||||
catch (e) {
|
.catch(err => logToFile(`[WS-RESPONSE] Approval error: ${err.message}`));
|
||||||
logToFile(`[WS-RESPONSE] Write error: ${e.message}`);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onCommand: (data) => {
|
onCommand: (data) => {
|
||||||
logToFile(`[WS-CMD] ${data.text?.substring(0, 50)}`);
|
logToFile(`[WS-CMD] ${data.text?.substring(0, 50)}`);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -18,7 +18,7 @@ import * as cp from 'child_process';
|
|||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { WSBridgeClient, WSResponseData, WSCommandData } from './ws-client';
|
import { WSBridgeClient, WSResponseData, WSCommandData } from './ws-client';
|
||||||
import { generateApprovalObserverScript } from './observer-script';
|
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) ───
|
// ─── File-based logging (AI can read directly) ───
|
||||||
function logToFile(msg: string) {
|
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 regCode = process.env.GRAVITY_REGISTRATION_CODE || config.get<string>('registrationCode') || '';
|
||||||
const pcName = os.hostname();
|
const pcName = os.hostname();
|
||||||
if (hubUrl) {
|
if (hubUrl) {
|
||||||
wsBridge = new WSBridgeClient(hubUrl, regCode, projectName, pcName, {
|
wsBridge = new WSBridgeClient(hubUrl, regCode, projectName, pcName, {
|
||||||
onResponse: (data: WSResponseData) => {
|
onResponse: (data: WSResponseData) => {
|
||||||
logToFile(`[WS-RESPONSE] ${data.request_id?.substring(0, 12)} approved=${data.approved}`);
|
logToFile(`[WS-RESPONSE] ${data.request_id?.substring(0, 12)} approved=${data.approved} step_type=${data.step_type || '(none)'}`);
|
||||||
// Route to processResponseFile logic — write temp response file for compatibility
|
// Direct approval — WS path has no pending file, so call tryApprovalStrategies directly
|
||||||
try {
|
const approved = data.approved ?? true;
|
||||||
const responseDir = path.join(bridgePath, 'response');
|
const stepType = data.step_type || '';
|
||||||
if (!fs.existsSync(responseDir)) { fs.mkdirSync(responseDir, { recursive: true }); }
|
const approvalCtx = getApprovalContext();
|
||||||
const responseFile = path.join(responseDir, `${data.request_id}.json`);
|
logToFile(`[WS-RESPONSE] Triggering approval: approved=${approved} session=${approvalCtx.sessionId.substring(0, 8)} stepType=${stepType} stepIndex=${approvalCtx.stepIndex}`);
|
||||||
fs.writeFileSync(responseFile, JSON.stringify(data, null, 2), 'utf-8');
|
tryApprovalStrategies(approved, approvalCtx.sessionId, stepType, approvalCtx.stepIndex)
|
||||||
logToFile(`[WS-RESPONSE] Written response file for processing`);
|
.then(result => {
|
||||||
} catch (e: any) {
|
logToFile(`[WS-RESPONSE] Approval result: ${result}`);
|
||||||
|
resetPendingState();
|
||||||
})
|
})
|
||||||
.catch(err => logToFile(`[WS-RESPONSE] Approval error: ${err.message}`));
|
.catch(err => logToFile(`[WS-RESPONSE] Approval error: ${err.message}`));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -41,6 +41,26 @@ const lastSeenStep = new Map<string, number>();
|
|||||||
const lastSnapshotText = new Map<string, string>();
|
const lastSnapshotText = new Map<string, string>();
|
||||||
const registeredSessions = new Set<string>(); // track which sessions have been registered
|
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.
|
* Write a registration file for the Bot to discover session → project mapping.
|
||||||
* Called automatically on first step event per session.
|
* Called automatically on first step event per session.
|
||||||
|
|||||||
Reference in New Issue
Block a user