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:
Variet Worker
2026-03-18 11:08:59 +09:00
parent 4a5521dcc3
commit e7631177f8
15 changed files with 65 additions and 989 deletions

View File

@@ -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) {