refactor(cleanup): v0.5.0 Collector 제거 + dead code 정리 + HttpBridgeContext 버그 수정
- DELETE collector.py (523줄) - main.py: BOT_MODE=remote 분기 제거 - gateway.py: Collector REST 6개 endpoint 제거 (311→168줄) - bridge.py: RemoteTransport 제거 (480→270줄) - config.py: REMOTE_BRIDGE_URL 제거 - extension.ts: dead code 4개 + stale module vars 제거 - step-probe.ts: getStepProbeContext() 추가, autoApproveEnabled 제거 - FIX: HttpBridgeContext stale primitive (getter 패턴으로 수정) - ADD: extension.log rotation (10MB→2MB tail) - docs: architecture.md, tech-stack.md, known-issues.md 업데이트
This commit is contained in:
@@ -67,6 +67,15 @@ function logToFile(msg) {
|
||||
if (!bridgePath)
|
||||
return;
|
||||
const logFile = path.join(bridgePath, 'extension.log');
|
||||
// Log rotation: truncate when >10MB, keep last 2MB
|
||||
try {
|
||||
const stat = fs.statSync(logFile);
|
||||
if (stat.size > 10 * 1024 * 1024) {
|
||||
const content = fs.readFileSync(logFile, 'utf-8');
|
||||
fs.writeFileSync(logFile, content.slice(-2 * 1024 * 1024), 'utf-8');
|
||||
}
|
||||
}
|
||||
catch { /* file doesn't exist yet */ }
|
||||
fs.appendFileSync(logFile, line + '\n', 'utf-8');
|
||||
}
|
||||
catch (e) {
|
||||
@@ -84,15 +93,6 @@ let isActive = false;
|
||||
let autoApproveEnabled = false; // toggled via !auto from Discord
|
||||
let watcher = null;
|
||||
let wsBridge = null; // WebSocket Hub connection
|
||||
const sentPendingIds = new Set();
|
||||
// Memory-based dedup: tracks recently created pending step_indexes to prevent
|
||||
// regeneration after pending file deletion (by Collector/Bot response cycle).
|
||||
// Map<string, number> = `${conversationId}:${stepIndex}` → creation timestamp
|
||||
const recentPendingSteps = new Map();
|
||||
const PENDING_MEMORY_TTL_MS = 60_000; // 60 seconds memory retention
|
||||
// In-memory cache for diff_review metadata (survives pending file deletion by Collector).
|
||||
// Map<request_id, { edit_step_indices, modified_files }>
|
||||
const diffReviewMetadata = new Map();
|
||||
// ─── Project Detection ───
|
||||
function detectProjectName() {
|
||||
const config = vscode.workspace.getConfiguration('gravityBridge');
|
||||
@@ -374,11 +374,6 @@ async function fixLSConnection() {
|
||||
}
|
||||
// ─── Approval Observer + Product.json Checksums extracted to ./html-patcher.ts ───
|
||||
// ─── HTTP Bridge Server extracted to ./http-bridge.ts ───
|
||||
// Shared state for HTTP bridge context (module-level, referenced by BridgeContext too)
|
||||
let sessionStalled = false;
|
||||
let lastPendingStepIndex = -1;
|
||||
let stallProbed = false;
|
||||
let sawRunningAfterPending = true;
|
||||
// ─── Step Probe, Response Watcher, Approval Strategies → extracted to ./step-probe.ts ───
|
||||
async function activate(context) {
|
||||
console.log('Gravity Bridge: activating...');
|
||||
@@ -503,12 +498,11 @@ async function activate(context) {
|
||||
projectName,
|
||||
sdk,
|
||||
wsBridge,
|
||||
autoApproveEnabled,
|
||||
activeSessionId,
|
||||
sessionStalled,
|
||||
lastPendingStepIndex,
|
||||
stallProbed,
|
||||
sawRunningAfterPending,
|
||||
sessionStalled: false,
|
||||
lastPendingStepIndex: -1,
|
||||
stallProbed: false,
|
||||
sawRunningAfterPending: true,
|
||||
setClickTrigger: (action) => {
|
||||
const { setClickTrigger: setTrigger } = require('./http-bridge');
|
||||
setTrigger(action);
|
||||
@@ -520,10 +514,12 @@ async function activate(context) {
|
||||
writeChatSnapshot,
|
||||
writeChatSnapshotWithFiles,
|
||||
});
|
||||
// Start HTTP bridge, then setup observer
|
||||
// Start HTTP bridge with live step-probe state (prevents stale primitive bug)
|
||||
const httpBridgeCtx = {
|
||||
bridgePath, projectName, activeSessionId, wsBridge,
|
||||
sessionStalled, lastPendingStepIndex, logToFile,
|
||||
bridgePath, projectName, wsBridge, logToFile,
|
||||
get activeSessionId() { return (0, step_probe_1.getStepProbeContext)().activeSessionId; },
|
||||
get sessionStalled() { return (0, step_probe_1.getStepProbeContext)().sessionStalled; },
|
||||
get lastPendingStepIndex() { return (0, step_probe_1.getStepProbeContext)().lastPendingStepIndex; },
|
||||
};
|
||||
const bridgePort = await (0, http_bridge_1.startHttpBridge)(httpBridgeCtx, sdk);
|
||||
if (bridgePort) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
||||
"name": "gravity-bridge",
|
||||
"displayName": "Gravity Bridge",
|
||||
"description": "Antigravity ↔ Discord 브리지 연동 확장",
|
||||
"version": "0.4.6",
|
||||
"version": "0.5.0",
|
||||
"publisher": "variet",
|
||||
"engines": {
|
||||
"vscode": "^1.100.0"
|
||||
|
||||
@@ -16,7 +16,7 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as cp from 'child_process';
|
||||
import { WSBridgeClient, WSResponseData, WSCommandData } from './ws-client';
|
||||
import { initStepProbe, BridgeContext, writePendingApproval, tryApprovalStrategies, writeRegistration, getApprovalContext, resetPendingState, handleDiffReviewResponse, getActiveSessionId as getStepProbeSessionId } from './step-probe';
|
||||
import { initStepProbe, BridgeContext, writePendingApproval, tryApprovalStrategies, writeRegistration, getApprovalContext, resetPendingState, handleDiffReviewResponse, getActiveSessionId as getStepProbeSessionId, getStepProbeContext } from './step-probe';
|
||||
import { startHttpBridge, getDeterministicPort, HttpBridgeContext } from './http-bridge';
|
||||
import { setupApprovalObserver } from './html-patcher';
|
||||
import { watchCommandsDir, handleWSCommand, disposeCommandsWatcher, CommandHandlerContext } from './command-handler';
|
||||
@@ -31,6 +31,14 @@ function logToFile(msg: string) {
|
||||
try {
|
||||
if (!bridgePath) return;
|
||||
const logFile = path.join(bridgePath, 'extension.log');
|
||||
// Log rotation: truncate when >10MB, keep last 2MB
|
||||
try {
|
||||
const stat = fs.statSync(logFile);
|
||||
if (stat.size > 10 * 1024 * 1024) {
|
||||
const content = fs.readFileSync(logFile, 'utf-8');
|
||||
fs.writeFileSync(logFile, content.slice(-2 * 1024 * 1024), 'utf-8');
|
||||
}
|
||||
} catch { /* file doesn't exist yet */ }
|
||||
fs.appendFileSync(logFile, line + '\n', 'utf-8');
|
||||
} catch (e: any) {
|
||||
console.error(`Gravity Bridge LOG WRITE FAIL: ${e.message}`);
|
||||
@@ -50,15 +58,6 @@ let autoApproveEnabled = false; // toggled via !auto from Discord
|
||||
let watcher: fs.FSWatcher | null = null;
|
||||
let wsBridge: WSBridgeClient | null = null; // WebSocket Hub connection
|
||||
|
||||
const sentPendingIds = new Set<string>();
|
||||
// Memory-based dedup: tracks recently created pending step_indexes to prevent
|
||||
// regeneration after pending file deletion (by Collector/Bot response cycle).
|
||||
// Map<string, number> = `${conversationId}:${stepIndex}` → creation timestamp
|
||||
const recentPendingSteps = new Map<string, number>();
|
||||
const PENDING_MEMORY_TTL_MS = 60_000; // 60 seconds memory retention
|
||||
// In-memory cache for diff_review metadata (survives pending file deletion by Collector).
|
||||
// Map<request_id, { edit_step_indices, modified_files }>
|
||||
const diffReviewMetadata = new Map<string, { edit_step_indices: number[]; modified_files: string[] }>();
|
||||
|
||||
// ─── Project Detection ───
|
||||
|
||||
@@ -357,12 +356,6 @@ async function fixLSConnection(): Promise<void> {
|
||||
|
||||
// ─── HTTP Bridge Server extracted to ./http-bridge.ts ───
|
||||
|
||||
// Shared state for HTTP bridge context (module-level, referenced by BridgeContext too)
|
||||
let sessionStalled = false;
|
||||
let lastPendingStepIndex = -1;
|
||||
let stallProbed = false;
|
||||
let sawRunningAfterPending = true;
|
||||
|
||||
// ─── Step Probe, Response Watcher, Approval Strategies → extracted to ./step-probe.ts ───
|
||||
|
||||
|
||||
@@ -500,12 +493,11 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
projectName,
|
||||
sdk,
|
||||
wsBridge,
|
||||
autoApproveEnabled,
|
||||
activeSessionId,
|
||||
sessionStalled,
|
||||
lastPendingStepIndex,
|
||||
stallProbed,
|
||||
sawRunningAfterPending,
|
||||
sessionStalled: false,
|
||||
lastPendingStepIndex: -1,
|
||||
stallProbed: false,
|
||||
sawRunningAfterPending: true,
|
||||
setClickTrigger: (action: 'approve' | 'reject') => {
|
||||
const { setClickTrigger: setTrigger } = require('./http-bridge');
|
||||
setTrigger(action);
|
||||
@@ -517,10 +509,12 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
writeChatSnapshot,
|
||||
writeChatSnapshotWithFiles,
|
||||
} as BridgeContext);
|
||||
// Start HTTP bridge, then setup observer
|
||||
// Start HTTP bridge with live step-probe state (prevents stale primitive bug)
|
||||
const httpBridgeCtx: HttpBridgeContext = {
|
||||
bridgePath, projectName, activeSessionId, wsBridge,
|
||||
sessionStalled, lastPendingStepIndex, logToFile,
|
||||
bridgePath, projectName, wsBridge, logToFile,
|
||||
get activeSessionId() { return getStepProbeContext().activeSessionId; },
|
||||
get sessionStalled() { return getStepProbeContext().sessionStalled; },
|
||||
get lastPendingStepIndex() { return getStepProbeContext().lastPendingStepIndex; },
|
||||
};
|
||||
const bridgePort = await startHttpBridge(httpBridgeCtx, sdk);
|
||||
if (bridgePort) {
|
||||
|
||||
@@ -14,7 +14,6 @@ export interface BridgeContext {
|
||||
projectName: string;
|
||||
sdk: any;
|
||||
wsBridge: WSBridgeClient | null;
|
||||
autoApproveEnabled: boolean;
|
||||
activeSessionId: string;
|
||||
sessionStalled: boolean;
|
||||
lastPendingStepIndex: number;
|
||||
@@ -64,6 +63,18 @@ export function getActiveSessionId(): string {
|
||||
return ctx?.activeSessionId || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get step-probe context values for http-bridge.
|
||||
* Prevents stale primitive copies by reading live ctx values.
|
||||
*/
|
||||
export function getStepProbeContext(): { activeSessionId: string; sessionStalled: boolean; lastPendingStepIndex: number } {
|
||||
return {
|
||||
activeSessionId: ctx?.activeSessionId || '',
|
||||
sessionStalled: ctx?.sessionStalled ?? false,
|
||||
lastPendingStepIndex: ctx?.lastPendingStepIndex ?? -1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset pending state after successful approval.
|
||||
* Called after WS response triggers approval in extension.ts.
|
||||
|
||||
Reference in New Issue
Block a user