refactor(extension): split extension.ts into 3 modules - http-bridge, html-patcher, command-handler (#398)
This commit is contained in:
@@ -49,10 +49,16 @@ gravity_control/
|
||||
│
|
||||
├── ── Extension 측 (TypeScript) ──
|
||||
├── extension/src/
|
||||
│ ├── extension.ts # 메인: SDK init, activate, HTTP bridge (1,290줄)
|
||||
│ ├── step-probe.ts # 폴링 + 응답 처리 + 승인 전략 (1,435줄)
|
||||
│ ├── extension.ts # 메인: SDK init, activate, 오케스트레이션 (650줄)
|
||||
│ ├── step-probe.ts # 폴링 + 응답 처리 + 승인 전략 (1,479줄)
|
||||
│ │ # setupMonitor(), processResponseFile(),
|
||||
│ │ # writePendingApproval(), tryApprovalStrategies()
|
||||
│ ├── http-bridge.ts # HTTP 서버 (Renderer↔Extension Host 통신) (280줄)
|
||||
│ │ # startHttpBridge(), getDeterministicPort()
|
||||
│ ├── html-patcher.ts # AG HTML 패치 + product.json 체크섬 (280줄)
|
||||
│ │ # setupApprovalObserver(), updateProductChecksums()
|
||||
│ ├── command-handler.ts # Discord→AG 명령어 처리 (175줄)
|
||||
│ │ # watchCommandsDir(), handleWSCommand()
|
||||
│ ├── observer-script.ts # DOM Observer 스크립트 생성 (698줄)
|
||||
│ │ # generateApprovalObserverScript()
|
||||
│ ├── ws-client.ts # WSBridgeClient: Hub 연결, 재연결, 큐 (505줄)
|
||||
@@ -122,17 +128,49 @@ gravity_control/
|
||||
| Hub 연동 | on_hub_pending, on_hub_chat, on_hub_register 핸들러 |
|
||||
| IDLE 알림 | AI step 종료 시 Discord 알림 |
|
||||
|
||||
### 3.4 Extension (extension.ts) — VS Code 확장
|
||||
### 3.4 Extension (extension.ts) — VS Code 확장 (오케스트레이터)
|
||||
|
||||
| 기능 | 설명 |
|
||||
|------|------|
|
||||
| AG SDK 연동 | getCascadeStatus, getAllTrajectories RPC |
|
||||
| 세션 감지 | activeSessionId 자동 추적 |
|
||||
| 프로젝트 자동 감지 | git remote URL 기반 |
|
||||
| HTTP bridge | 파일 기반 pending/response 읽기쓰기 (레거시) |
|
||||
| 모듈 초기화 | HTTP bridge, observer, command handler 시작 |
|
||||
| WS bridge | WSBridgeClient 통한 Hub 연결 (우선) |
|
||||
| Status bar | SDK 상태 + 연결 상태 표시 |
|
||||
|
||||
### 3.4a HTTP Bridge (http-bridge.ts)
|
||||
|
||||
`HttpBridgeContext` 인터페이스로 extension.ts의 공유 상태 참조:
|
||||
|
||||
| 기능 | 설명 |
|
||||
|------|------|
|
||||
| POST /pending | Renderer가 발견한 승인 버튼 보고 |
|
||||
| GET /response/:rid | Renderer가 Discord 응답 폴링 |
|
||||
| GET /trigger-click | Extension→Renderer 클릭 트리거 |
|
||||
| GET/POST /deep-inspect* | DOM 심층 검사 |
|
||||
| getDeterministicPort | 프로젝트명 기반 결정적 포트 |
|
||||
|
||||
### 3.4b HTML Patcher (html-patcher.ts)
|
||||
|
||||
| 기능 | 설명 |
|
||||
|------|------|
|
||||
| setupApprovalObserver | AG Workbench HTML 파일에 observer 스크립트 인라인 삽입 |
|
||||
| updateProductChecksums | product.json SHA256 체크섬 업데이트 (vscode-file:// 프로토콜용) |
|
||||
| CSP 패치 | script-src에 'unsafe-inline' 추가 |
|
||||
| .orig 백업 | 최초 패치 전 원본 백업, 손상 시 자동 복구 |
|
||||
|
||||
### 3.4c Command Handler (command-handler.ts)
|
||||
|
||||
`CommandHandlerContext` 인터페이스로 extension.ts 상태 참조:
|
||||
|
||||
| 기능 | 설명 |
|
||||
|------|------|
|
||||
| watchCommandsDir | commands/ 디렉토리 fs.watch + 3s 폴링 |
|
||||
| handleWSCommand | WS Hub 경유 명령어 처리 |
|
||||
| !stop, !auto | AG 에이전트 제어 명령어 |
|
||||
| 텍스트 전달 | Discord → AG `sendPromptToAgentPanel` |
|
||||
|
||||
### 3.5 Step Probe (step-probe.ts) — 상태 폴링
|
||||
|
||||
`BridgeContext` 인터페이스로 extension.ts와 상태 공유:
|
||||
@@ -146,7 +184,7 @@ gravity_control/
|
||||
| setupResponseWatcher | response/ 디렉토리 파일 감시 |
|
||||
|
||||
**BridgeContext 필드** (14개):
|
||||
`bridgePath`, `projectName`, `sdk`, `wsBridge`, `logToFile`, `autoApproveEnabled`, `activeSessionId`, `sentPendingIds`, `deterministicPort`, `recentDiscordSentTexts`, `writeChatSnapshot`, `writeChatSnapshotWithFiles`, `workspaceUri`, `diffReviewMetadata`
|
||||
`bridgePath`, `projectName`, `sdk`, `wsBridge`, `logToFile`, `autoApproveEnabled`, `activeSessionId`, `setClickTrigger`, `recentDiscordSentTexts`, `writeChatSnapshot`, `writeChatSnapshotWithFiles`, `workspaceUri`, `diffReviewMetadata`, `sessionStalled`, `lastPendingStepIndex`, `stallProbed`, `sawRunningAfterPending`
|
||||
|
||||
### 3.6 WS Client (ws-client.ts) — Hub 클라이언트
|
||||
|
||||
|
||||
Reference in New Issue
Block a user