@jcjeon/integration-cli 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +23 -0
- package/.npmignore +21 -0
- package/.prettierignore +6 -0
- package/.prettierrc +26 -0
- package/AGENTS.md +10 -0
- package/CLAUDE.md +10 -0
- package/README.md +384 -0
- package/apps/server/README.md +294 -0
- package/apps/server/eslint.config.mjs +20 -0
- package/apps/server/nest-cli.json +8 -0
- package/apps/server/package.json +89 -0
- package/apps/server/scripts/postinstall.js +53 -0
- package/apps/server/src/__mocks__/glob.js +6 -0
- package/apps/server/src/__mocks__/uuid.js +5 -0
- package/apps/server/src/app.controller.spec.ts +24 -0
- package/apps/server/src/app.controller.ts +13 -0
- package/apps/server/src/app.module.ts +18 -0
- package/apps/server/src/app.service.ts +8 -0
- package/apps/server/src/common/ji-paths.ts +41 -0
- package/apps/server/src/database/database.module.ts +27 -0
- package/apps/server/src/database/entities/agent-changelog.entity.ts +39 -0
- package/apps/server/src/database/entities/agent-session.entity.ts +29 -0
- package/apps/server/src/database/entities/conversation.entity.ts +41 -0
- package/apps/server/src/database/entities/session.entity.ts +16 -0
- package/apps/server/src/database/entities/task-agent-run.entity.ts +40 -0
- package/apps/server/src/database/entities/task-agent.entity.ts +42 -0
- package/apps/server/src/database/entities/task-requirement.entity.ts +27 -0
- package/apps/server/src/database/entities/task-run.entity.ts +41 -0
- package/apps/server/src/database/entities/task.entity.ts +44 -0
- package/apps/server/src/main.ts +65 -0
- package/apps/server/src/modules/agents/agent-model-settings.spec.ts +80 -0
- package/apps/server/src/modules/agents/agents.module.ts +11 -0
- package/apps/server/src/modules/agents/claude/claude-auth.manager.ts +83 -0
- package/apps/server/src/modules/agents/claude/claude-pty.manager.ts +380 -0
- package/apps/server/src/modules/agents/claude/claude.controller.ts +85 -0
- package/apps/server/src/modules/agents/claude/claude.gateway.ts +158 -0
- package/apps/server/src/modules/agents/claude/claude.module.ts +18 -0
- package/apps/server/src/modules/agents/claude/claude.service.ts +67 -0
- package/apps/server/src/modules/agents/claude/dto/create-session.dto.ts +24 -0
- package/apps/server/src/modules/agents/claude/dto/resize-session.dto.ts +13 -0
- package/apps/server/src/modules/agents/claude/dto/send-input.dto.ts +9 -0
- package/apps/server/src/modules/agents/claude/interfaces/claude-session.interface.ts +26 -0
- package/apps/server/src/modules/agents/claude/interfaces/pty-event.interface.ts +10 -0
- package/apps/server/src/modules/agents/claude/interfaces/stream-event.interface.ts +61 -0
- package/apps/server/src/modules/agents/codex/codex-auth.manager.ts +107 -0
- package/apps/server/src/modules/agents/codex/codex-session.manager.ts +357 -0
- package/apps/server/src/modules/agents/codex/codex.controller.ts +64 -0
- package/apps/server/src/modules/agents/codex/codex.gateway.ts +97 -0
- package/apps/server/src/modules/agents/codex/codex.module.ts +17 -0
- package/apps/server/src/modules/agents/codex/dto/configure-auth.dto.ts +7 -0
- package/apps/server/src/modules/agents/gemini/dto/configure-auth.dto.ts +15 -0
- package/apps/server/src/modules/agents/gemini/dto/create-session.dto.ts +9 -0
- package/apps/server/src/modules/agents/gemini/dto/send-input.dto.ts +9 -0
- package/apps/server/src/modules/agents/gemini/gemini-auth.manager.ts +157 -0
- package/apps/server/src/modules/agents/gemini/gemini-session.manager.ts +287 -0
- package/apps/server/src/modules/agents/gemini/gemini.controller.ts +93 -0
- package/apps/server/src/modules/agents/gemini/gemini.gateway.ts +149 -0
- package/apps/server/src/modules/agents/gemini/gemini.module.ts +17 -0
- package/apps/server/src/modules/agents/gemini/interfaces/gemini-session.interface.ts +18 -0
- package/apps/server/src/modules/agents/gemini/interfaces/stream-event.interface.ts +14 -0
- package/apps/server/src/modules/agents/session-termination.spec.ts +103 -0
- package/apps/server/src/modules/changelog/changelog.controller.ts +20 -0
- package/apps/server/src/modules/changelog/changelog.module.ts +14 -0
- package/apps/server/src/modules/changelog/changelog.service.spec.ts +531 -0
- package/apps/server/src/modules/changelog/changelog.service.ts +690 -0
- package/apps/server/src/modules/conversations/conversation.controller.spec.ts +106 -0
- package/apps/server/src/modules/conversations/conversation.controller.ts +60 -0
- package/apps/server/src/modules/conversations/conversation.module.ts +14 -0
- package/apps/server/src/modules/conversations/conversation.service.spec.ts +176 -0
- package/apps/server/src/modules/conversations/conversation.service.ts +54 -0
- package/apps/server/src/modules/conversations/dto/create-conversation.dto.ts +37 -0
- package/apps/server/src/modules/conversations/enums/conversation.enum.ts +13 -0
- package/apps/server/src/modules/fs/fs.controller.ts +29 -0
- package/apps/server/src/modules/fs/fs.module.ts +8 -0
- package/apps/server/src/modules/harness/dto/save-harness.dto.ts +9 -0
- package/apps/server/src/modules/harness/harness.controller.spec.ts +95 -0
- package/apps/server/src/modules/harness/harness.controller.ts +35 -0
- package/apps/server/src/modules/harness/harness.module.ts +11 -0
- package/apps/server/src/modules/harness/harness.service.spec.ts +217 -0
- package/apps/server/src/modules/harness/harness.service.ts +112 -0
- package/apps/server/src/modules/sessions/session.controller.spec.ts +68 -0
- package/apps/server/src/modules/sessions/session.controller.ts +43 -0
- package/apps/server/src/modules/sessions/session.module.ts +14 -0
- package/apps/server/src/modules/sessions/session.service.spec.ts +106 -0
- package/apps/server/src/modules/sessions/session.service.ts +35 -0
- package/apps/server/src/modules/tasks/dto/create-task.dto.ts +54 -0
- package/apps/server/src/modules/tasks/dto/execute-task.dto.ts +22 -0
- package/apps/server/src/modules/tasks/dto/merge-file.dto.ts +7 -0
- package/apps/server/src/modules/tasks/dto/rerun-task.dto.ts +14 -0
- package/apps/server/src/modules/tasks/dto/update-task.dto.ts +55 -0
- package/apps/server/src/modules/tasks/task-execution.service.ts +978 -0
- package/apps/server/src/modules/tasks/task.gateway.ts +140 -0
- package/apps/server/src/modules/tasks/tasks.controller.spec.ts +210 -0
- package/apps/server/src/modules/tasks/tasks.controller.ts +139 -0
- package/apps/server/src/modules/tasks/tasks.module.ts +30 -0
- package/apps/server/src/modules/tasks/tasks.service.spec.ts +552 -0
- package/apps/server/src/modules/tasks/tasks.service.ts +333 -0
- package/apps/server/test/app.e2e-spec.ts +28 -0
- package/apps/server/test/jest-e2e.json +9 -0
- package/apps/server/tsconfig.build.json +4 -0
- package/apps/server/tsconfig.json +13 -0
- package/apps/web/AGENTS.md +7 -0
- package/apps/web/CLAUDE.md +1 -0
- package/apps/web/README.md +36 -0
- package/apps/web/eslint.config.mjs +21 -0
- package/apps/web/next-env.d.ts +6 -0
- package/apps/web/next.config.ts +7 -0
- package/apps/web/package.json +49 -0
- package/apps/web/postcss.config.mjs +7 -0
- package/apps/web/public/file.svg +1 -0
- package/apps/web/public/globe.svg +1 -0
- package/apps/web/public/next.svg +1 -0
- package/apps/web/public/vercel.svg +1 -0
- package/apps/web/public/window.svg +1 -0
- package/apps/web/src/app/claude/page.tsx +5 -0
- package/apps/web/src/app/codex/page.tsx +126 -0
- package/apps/web/src/app/favicon.ico +0 -0
- package/apps/web/src/app/gemini/page.tsx +130 -0
- package/apps/web/src/app/globals.css +149 -0
- package/apps/web/src/app/layout.tsx +40 -0
- package/apps/web/src/app/login/page.tsx +67 -0
- package/apps/web/src/app/page.tsx +497 -0
- package/apps/web/src/app/task/[id]/page.tsx +11 -0
- package/apps/web/src/app/test/page.tsx +298 -0
- package/apps/web/src/components/ui/Modal.tsx +78 -0
- package/apps/web/src/components/ui/WorkingDirPicker.tsx +195 -0
- package/apps/web/src/components/ui/__tests__/Modal.test.tsx +68 -0
- package/apps/web/src/features/auth/api/__tests__/auth.api.test.ts +83 -0
- package/apps/web/src/features/auth/api/auth.api.ts +81 -0
- package/apps/web/src/features/auth/hooks/__tests__/useClaudeAuth.test.ts +166 -0
- package/apps/web/src/features/auth/hooks/__tests__/useCodexAuth.test.ts +127 -0
- package/apps/web/src/features/auth/hooks/__tests__/useGeminiAuth.test.ts +120 -0
- package/apps/web/src/features/auth/hooks/useClaudeAuth.ts +88 -0
- package/apps/web/src/features/auth/hooks/useCodexAuth.ts +149 -0
- package/apps/web/src/features/auth/hooks/useGeminiAuth.ts +125 -0
- package/apps/web/src/features/auth/ui/CodexLoginPanel.tsx +302 -0
- package/apps/web/src/features/auth/ui/GeminiLoginPanel.tsx +316 -0
- package/apps/web/src/features/auth/ui/LoginForm.tsx +190 -0
- package/apps/web/src/features/auth/ui/LoginPanel.tsx +114 -0
- package/apps/web/src/features/auth/ui/__tests__/LoginPanel.test.tsx +105 -0
- package/apps/web/src/features/chat/api/__tests__/sessions.api.test.ts +187 -0
- package/apps/web/src/features/chat/api/sessions.api.ts +161 -0
- package/apps/web/src/features/chat/container/ClaudePageContainer.tsx +152 -0
- package/apps/web/src/features/chat/hooks/__tests__/useCodexSessions.test.ts +131 -0
- package/apps/web/src/features/chat/hooks/__tests__/useGeminiSessions.test.ts +130 -0
- package/apps/web/src/features/chat/hooks/useAgentModelSettings.ts +54 -0
- package/apps/web/src/features/chat/hooks/useClaudeSessions.ts +323 -0
- package/apps/web/src/features/chat/hooks/useCodexSessions.ts +275 -0
- package/apps/web/src/features/chat/hooks/useGeminiSessions.ts +255 -0
- package/apps/web/src/features/chat/hooks/useSessionCommand.ts +66 -0
- package/apps/web/src/features/chat/hooks/useSessionRename.ts +61 -0
- package/apps/web/src/features/chat/hooks/useSessionWorkingDirectories.ts +34 -0
- package/apps/web/src/features/chat/hooks/useUnifiedSessions.ts +156 -0
- package/apps/web/src/features/chat/lib/agentModelOptions.ts +72 -0
- package/apps/web/src/features/chat/ui/AgentModelPicker.tsx +134 -0
- package/apps/web/src/features/chat/ui/AgentSelectModal.tsx +236 -0
- package/apps/web/src/features/chat/ui/ChatInput.tsx +162 -0
- package/apps/web/src/features/chat/ui/ChatMessage.tsx +204 -0
- package/apps/web/src/features/chat/ui/ChatWorkspace.tsx +207 -0
- package/apps/web/src/features/chat/ui/CheckingSkeleton.tsx +44 -0
- package/apps/web/src/features/chat/ui/ClaudeLoginView.tsx +44 -0
- package/apps/web/src/features/chat/ui/PermissionCard.tsx +37 -0
- package/apps/web/src/features/chat/ui/SessionSidebar.tsx +280 -0
- package/apps/web/src/features/chat/ui/__tests__/AgentSelectModal.test.tsx +58 -0
- package/apps/web/src/features/chat/ui/__tests__/ChatInput.test.tsx +134 -0
- package/apps/web/src/features/chat/ui/__tests__/ChatMessage.test.tsx +106 -0
- package/apps/web/src/features/chat/ui/__tests__/ChatWorkspace.test.tsx +66 -0
- package/apps/web/src/features/diff/ui/DiffFileRow.tsx +73 -0
- package/apps/web/src/features/diff/ui/DiffHunk.tsx +61 -0
- package/apps/web/src/features/diff/ui/FileChangeBadge.tsx +23 -0
- package/apps/web/src/features/diff/ui/__tests__/DiffFileRow.test.tsx +40 -0
- package/apps/web/src/features/diff/ui/__tests__/DiffHunk.test.tsx +24 -0
- package/apps/web/src/features/diff/ui/__tests__/FileChangeBadge.test.tsx +16 -0
- package/apps/web/src/features/fs/api/fs.api.ts +14 -0
- package/apps/web/src/features/fs/hooks/useDirBrowser.ts +50 -0
- package/apps/web/src/features/harness/api/__tests__/harness.api.test.ts +73 -0
- package/apps/web/src/features/harness/api/harness.api.ts +46 -0
- package/apps/web/src/features/harness/hooks/__tests__/useHarness.test.ts +65 -0
- package/apps/web/src/features/harness/hooks/useHarness.ts +66 -0
- package/apps/web/src/features/harness/ui/HarnessModal.tsx +171 -0
- package/apps/web/src/features/harness/ui/__tests__/HarnessModal.test.tsx +46 -0
- package/apps/web/src/features/status/ui/AgentStatusModal.tsx +267 -0
- package/apps/web/src/features/status/ui/__tests__/AgentStatusModal.test.tsx +71 -0
- package/apps/web/src/features/tasks/api/__tests__/changelog.api.test.ts +89 -0
- package/apps/web/src/features/tasks/api/__tests__/tasks.api.test.ts +282 -0
- package/apps/web/src/features/tasks/api/changelog.api.ts +52 -0
- package/apps/web/src/features/tasks/api/tasks.api.ts +175 -0
- package/apps/web/src/features/tasks/container/TaskDetailPageContainer.tsx +69 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useChangelogCodeCopy.test.ts +48 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskChangelog.test.ts +48 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskCreate.test.ts +217 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskEdit.test.ts +152 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskExecution.test.ts +143 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskList.test.ts +168 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskNotification.test.ts +125 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskRuns.test.ts +51 -0
- package/apps/web/src/features/tasks/hooks/useChangelogCodeCopy.ts +52 -0
- package/apps/web/src/features/tasks/hooks/useCopyToClipboard.ts +47 -0
- package/apps/web/src/features/tasks/hooks/useTaskChangelog.ts +32 -0
- package/apps/web/src/features/tasks/hooks/useTaskCreate.ts +137 -0
- package/apps/web/src/features/tasks/hooks/useTaskDetail.ts +217 -0
- package/apps/web/src/features/tasks/hooks/useTaskEdit.ts +130 -0
- package/apps/web/src/features/tasks/hooks/useTaskExecution.ts +137 -0
- package/apps/web/src/features/tasks/hooks/useTaskList.ts +159 -0
- package/apps/web/src/features/tasks/hooks/useTaskNotification.ts +80 -0
- package/apps/web/src/features/tasks/hooks/useTaskRuns.ts +32 -0
- package/apps/web/src/features/tasks/ui/AgentOutputPanel.tsx +203 -0
- package/apps/web/src/features/tasks/ui/AgentRoleSelect.tsx +97 -0
- package/apps/web/src/features/tasks/ui/ChangelogPanel.tsx +321 -0
- package/apps/web/src/features/tasks/ui/RunHistoryPanel.tsx +193 -0
- package/apps/web/src/features/tasks/ui/TaskCreateModal.tsx +205 -0
- package/apps/web/src/features/tasks/ui/TaskDetailView.tsx +413 -0
- package/apps/web/src/features/tasks/ui/TaskEditModal.tsx +165 -0
- package/apps/web/src/features/tasks/ui/TaskListModal.tsx +591 -0
- package/apps/web/src/features/tasks/ui/__tests__/AgentRoleSelect.test.tsx +91 -0
- package/apps/web/src/features/tasks/ui/__tests__/ChangelogPanel.test.tsx +94 -0
- package/apps/web/src/features/tasks/ui/__tests__/RunHistoryPanel.test.tsx +71 -0
- package/apps/web/src/features/tasks/ui/__tests__/TaskCreateModal.test.tsx +153 -0
- package/apps/web/src/features/tasks/ui/__tests__/TaskEditModal.test.tsx +75 -0
- package/apps/web/src/features/tasks/ui/__tests__/TaskListModal.test.tsx +243 -0
- package/apps/web/src/hooks/useWorkingDir.ts +28 -0
- package/apps/web/src/lib/__tests__/ansi.test.ts +88 -0
- package/apps/web/src/lib/ansi.ts +105 -0
- package/apps/web/src/lib/constants.ts +4 -0
- package/apps/web/src/lib/quota.ts +22 -0
- package/apps/web/src/lib/theme.tsx +78 -0
- package/apps/web/src/lib/toast.tsx +175 -0
- package/apps/web/src/store/agentStatusStore.ts +38 -0
- package/apps/web/tsconfig.json +18 -0
- package/apps/web/vitest.config.ts +25 -0
- package/apps/web/vitest.setup.ts +10 -0
- package/package.json +85 -0
- package/packages/cli/dist/commands/check.d.ts +1 -0
- package/packages/cli/dist/commands/check.js +89 -0
- package/packages/cli/dist/commands/init.d.ts +5 -0
- package/packages/cli/dist/commands/init.js +183 -0
- package/packages/cli/dist/commands/start.d.ts +4 -0
- package/packages/cli/dist/commands/start.js +188 -0
- package/packages/cli/dist/index.d.ts +2 -0
- package/packages/cli/dist/index.js +71 -0
- package/packages/cli/dist/utils/agent-tools.d.ts +28 -0
- package/packages/cli/dist/utils/agent-tools.js +193 -0
- package/packages/cli/dist/utils/project-init.d.ts +12 -0
- package/packages/cli/dist/utils/project-init.js +258 -0
- package/packages/cli/dist/utils/proxy.d.ts +8 -0
- package/packages/cli/dist/utils/proxy.js +138 -0
- package/packages/cli/package.json +30 -0
- package/packages/cli/src/commands/check.ts +77 -0
- package/packages/cli/src/commands/init.ts +209 -0
- package/packages/cli/src/commands/start.ts +183 -0
- package/packages/cli/src/index.ts +91 -0
- package/packages/cli/src/utils/agent-tools.ts +201 -0
- package/packages/cli/src/utils/project-init.ts +252 -0
- package/packages/cli/src/utils/proxy.ts +123 -0
- package/packages/cli/tsconfig.json +14 -0
- package/packages/eslint-config/base.mjs +31 -0
- package/packages/eslint-config/nest.mjs +55 -0
- package/packages/eslint-config/next.mjs +23 -0
- package/packages/eslint-config/package.json +20 -0
- package/packages/typescript-config/base.json +16 -0
- package/packages/typescript-config/nestjs.json +17 -0
- package/packages/typescript-config/nextjs.json +15 -0
- package/packages/typescript-config/package.json +11 -0
- package/turbo.json +28 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BadRequestException,
|
|
3
|
+
Body,
|
|
4
|
+
Controller,
|
|
5
|
+
Delete,
|
|
6
|
+
Get,
|
|
7
|
+
HttpCode,
|
|
8
|
+
HttpStatus,
|
|
9
|
+
Param,
|
|
10
|
+
Post,
|
|
11
|
+
UsePipes,
|
|
12
|
+
ValidationPipe,
|
|
13
|
+
} from '@nestjs/common';
|
|
14
|
+
import { ApiNoContentResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
15
|
+
|
|
16
|
+
import { ConfigureAuthDto } from './dto/configure-auth.dto';
|
|
17
|
+
import { CreateSessionDto } from './dto/create-session.dto';
|
|
18
|
+
import { SendInputDto } from './dto/send-input.dto';
|
|
19
|
+
import { GeminiAuthManager } from './gemini-auth.manager';
|
|
20
|
+
import type { GeminiAuthStatus } from './gemini-auth.manager';
|
|
21
|
+
import { GeminiSessionManager } from './gemini-session.manager';
|
|
22
|
+
import type { SessionInfo } from './interfaces/gemini-session.interface';
|
|
23
|
+
|
|
24
|
+
@ApiTags('agents/gemini')
|
|
25
|
+
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
26
|
+
@Controller('agents/gemini')
|
|
27
|
+
export class GeminiController {
|
|
28
|
+
constructor(
|
|
29
|
+
private readonly authManager: GeminiAuthManager,
|
|
30
|
+
private readonly sessionManager: GeminiSessionManager,
|
|
31
|
+
) {}
|
|
32
|
+
|
|
33
|
+
@ApiOperation({ summary: 'Gemini CLI 인증 상태 조회' })
|
|
34
|
+
@ApiOkResponse({ description: '설치 여부, 인증 방식, 이메일 반환' })
|
|
35
|
+
@Get('auth/status')
|
|
36
|
+
getAuthStatus(): Promise<GeminiAuthStatus> {
|
|
37
|
+
return this.authManager.getAuthStatus();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@ApiOperation({
|
|
41
|
+
summary: 'Gemini CLI 인증 설정',
|
|
42
|
+
description: '`api-key` 방식은 apiKey 필드 필수. `gca` 방식은 WebSocket으로 진행',
|
|
43
|
+
})
|
|
44
|
+
@ApiNoContentResponse({ description: '설정 완료 (응답 본문 없음)' })
|
|
45
|
+
@Post('auth/configure')
|
|
46
|
+
@HttpCode(HttpStatus.NO_CONTENT)
|
|
47
|
+
configureAuth(@Body() dto: ConfigureAuthDto): void {
|
|
48
|
+
if (dto.authType === 'api-key') {
|
|
49
|
+
if (!dto.apiKey?.trim()) throw new BadRequestException('apiKey is required');
|
|
50
|
+
this.authManager.saveApiKey(dto.apiKey.trim());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@ApiOperation({ summary: '새 Gemini 세션 생성' })
|
|
55
|
+
@ApiOkResponse({ description: '생성된 세션 정보' })
|
|
56
|
+
@Post('sessions')
|
|
57
|
+
createSession(@Body() dto: CreateSessionDto): SessionInfo {
|
|
58
|
+
return this.sessionManager.createSession(dto.workingDirectory);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ApiOperation({ summary: '활성 Gemini 세션 목록 조회' })
|
|
62
|
+
@ApiOkResponse({ description: '세션 목록' })
|
|
63
|
+
@Get('sessions')
|
|
64
|
+
listSessions(): SessionInfo[] {
|
|
65
|
+
return this.sessionManager.listSessions();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@ApiOperation({ summary: '특정 Gemini 세션 조회' })
|
|
69
|
+
@ApiOkResponse({ description: '세션 정보' })
|
|
70
|
+
@Get('sessions/:id')
|
|
71
|
+
getSession(@Param('id') id: string): SessionInfo {
|
|
72
|
+
return this.sessionManager.getSessionInfo(id);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@ApiOperation({
|
|
76
|
+
summary: '세션에 메시지 전송',
|
|
77
|
+
description: '응답은 WebSocket `/agents/gemini` 네임스페이스의 `session:chunk` / `session:done` 이벤트로 수신',
|
|
78
|
+
})
|
|
79
|
+
@ApiNoContentResponse({ description: '전송 완료 (응답 본문 없음)' })
|
|
80
|
+
@Post('sessions/:id/message')
|
|
81
|
+
@HttpCode(HttpStatus.NO_CONTENT)
|
|
82
|
+
sendMessage(@Param('id') id: string, @Body() dto: SendInputDto): void {
|
|
83
|
+
this.sessionManager.sendMessage(id, dto.input);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@ApiOperation({ summary: '세션 종료' })
|
|
87
|
+
@ApiNoContentResponse({ description: '종료 완료 (응답 본문 없음)' })
|
|
88
|
+
@Delete('sessions/:id')
|
|
89
|
+
@HttpCode(HttpStatus.NO_CONTENT)
|
|
90
|
+
terminateSession(@Param('id') id: string): void {
|
|
91
|
+
this.sessionManager.terminateSession(id);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Logger, UsePipes, ValidationPipe } from '@nestjs/common';
|
|
2
|
+
import {
|
|
3
|
+
ConnectedSocket,
|
|
4
|
+
MessageBody,
|
|
5
|
+
OnGatewayConnection,
|
|
6
|
+
OnGatewayDisconnect,
|
|
7
|
+
OnGatewayInit,
|
|
8
|
+
SubscribeMessage,
|
|
9
|
+
WebSocketGateway,
|
|
10
|
+
WebSocketServer,
|
|
11
|
+
WsException,
|
|
12
|
+
} from '@nestjs/websockets';
|
|
13
|
+
import { Server, Socket } from 'socket.io';
|
|
14
|
+
|
|
15
|
+
import { GeminiAuthManager } from './gemini-auth.manager';
|
|
16
|
+
import { GeminiSessionManager } from './gemini-session.manager';
|
|
17
|
+
import { SendInputDto } from './dto/send-input.dto';
|
|
18
|
+
import type { CreateSessionDto } from './dto/create-session.dto';
|
|
19
|
+
import type { ResultEvent, SessionExitEvent, TextDeltaEvent } from './interfaces/stream-event.interface';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* WebSocket 이벤트 프로토콜 (/agents/gemini)
|
|
23
|
+
*
|
|
24
|
+
* Client → Server
|
|
25
|
+
* session:create { workingDirectory? }
|
|
26
|
+
* session:message { sessionId, input }
|
|
27
|
+
* session:terminate { sessionId }
|
|
28
|
+
* auth:gca:start
|
|
29
|
+
* auth:login:cancel
|
|
30
|
+
*
|
|
31
|
+
* Server → Client
|
|
32
|
+
* session:created { id, status, ... }
|
|
33
|
+
* session:text { sessionId, text }
|
|
34
|
+
* session:result { sessionId, isError }
|
|
35
|
+
* session:exit { sessionId, exitCode }
|
|
36
|
+
* error { message }
|
|
37
|
+
* auth:output { text }
|
|
38
|
+
* auth:done { success }
|
|
39
|
+
*/
|
|
40
|
+
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
|
|
41
|
+
@WebSocketGateway({ namespace: '/agents/gemini', cors: { origin: '*' } })
|
|
42
|
+
export class GeminiGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
|
|
43
|
+
@WebSocketServer()
|
|
44
|
+
private readonly server!: Server;
|
|
45
|
+
|
|
46
|
+
private readonly logger = new Logger(GeminiGateway.name);
|
|
47
|
+
|
|
48
|
+
constructor(
|
|
49
|
+
private readonly sessionManager: GeminiSessionManager,
|
|
50
|
+
private readonly authManager: GeminiAuthManager,
|
|
51
|
+
) {}
|
|
52
|
+
|
|
53
|
+
// ─── Gateway hooks ───────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
afterInit(): void {
|
|
56
|
+
this.sessionManager.on('text-delta', (event: TextDeltaEvent) => {
|
|
57
|
+
this.server.to(event.sessionId).emit('session:text', event);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
this.sessionManager.on('result', (event: ResultEvent) => {
|
|
61
|
+
this.server.to(event.sessionId).emit('session:result', event);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
this.sessionManager.on('exit', (event: SessionExitEvent) => {
|
|
65
|
+
this.server.to(event.sessionId).emit('session:exit', event);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
this.sessionManager.on('error', (event: { sessionId: string; message: string }) => {
|
|
69
|
+
this.server.to(event.sessionId).emit('error', { message: event.message });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
this.logger.log('GeminiGateway initialised — namespace: /agents/gemini');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
handleConnection(client: Socket): void {
|
|
76
|
+
this.logger.debug(`Client connected: ${client.id}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
handleDisconnect(client: Socket): void {
|
|
80
|
+
this.authManager.cancelLogin(client.id);
|
|
81
|
+
this.logger.debug(`Client disconnected: ${client.id}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ─── Session handlers ────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
@SubscribeMessage('session:create')
|
|
87
|
+
handleCreate(
|
|
88
|
+
@ConnectedSocket() client: Socket,
|
|
89
|
+
@MessageBody() dto: CreateSessionDto,
|
|
90
|
+
): void {
|
|
91
|
+
try {
|
|
92
|
+
const session = this.sessionManager.createSession(dto.workingDirectory);
|
|
93
|
+
void client.join(session.id);
|
|
94
|
+
client.emit('session:created', session);
|
|
95
|
+
} catch (err) {
|
|
96
|
+
this.emitError(client, err);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@SubscribeMessage('session:message')
|
|
101
|
+
handleMessage(
|
|
102
|
+
@ConnectedSocket() client: Socket,
|
|
103
|
+
@MessageBody() body: { sessionId: string } & SendInputDto,
|
|
104
|
+
): void {
|
|
105
|
+
try {
|
|
106
|
+
void client.join(body.sessionId);
|
|
107
|
+
this.sessionManager.sendMessage(body.sessionId, body.input);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
this.emitError(client, err);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@SubscribeMessage('session:terminate')
|
|
114
|
+
handleTerminate(
|
|
115
|
+
@ConnectedSocket() client: Socket,
|
|
116
|
+
@MessageBody('sessionId') sessionId: string,
|
|
117
|
+
): void {
|
|
118
|
+
try {
|
|
119
|
+
this.sessionManager.terminateSession(sessionId);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
this.emitError(client, err);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ─── Auth handlers ───────────────────────────────────────────────────
|
|
126
|
+
|
|
127
|
+
@SubscribeMessage('auth:gca:start')
|
|
128
|
+
handleGcaLoginStart(@ConnectedSocket() client: Socket): void {
|
|
129
|
+
this.authManager.startGcaLogin(
|
|
130
|
+
client.id,
|
|
131
|
+
(text) => client.emit('auth:output', { text }),
|
|
132
|
+
(success) => client.emit('auth:done', { success }),
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@SubscribeMessage('auth:login:cancel')
|
|
137
|
+
handleAuthLoginCancel(@ConnectedSocket() client: Socket): void {
|
|
138
|
+
this.authManager.cancelLogin(client.id);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ─── Private ─────────────────────────────────────────────────────────
|
|
142
|
+
|
|
143
|
+
private emitError(client: Socket, err: unknown): void {
|
|
144
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
145
|
+
this.logger.error(`[${client.id}] ${message}`);
|
|
146
|
+
client.emit('error', { message });
|
|
147
|
+
throw new WsException(message);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
+
|
|
4
|
+
import { AgentSessionEntity } from '../../../database/entities/agent-session.entity';
|
|
5
|
+
import { SessionEntity } from '../../../database/entities/session.entity';
|
|
6
|
+
import { GeminiAuthManager } from './gemini-auth.manager';
|
|
7
|
+
import { GeminiController } from './gemini.controller';
|
|
8
|
+
import { GeminiGateway } from './gemini.gateway';
|
|
9
|
+
import { GeminiSessionManager } from './gemini-session.manager';
|
|
10
|
+
|
|
11
|
+
@Module({
|
|
12
|
+
imports: [TypeOrmModule.forFeature([AgentSessionEntity, SessionEntity])],
|
|
13
|
+
controllers: [GeminiController],
|
|
14
|
+
providers: [GeminiAuthManager, GeminiSessionManager, GeminiGateway],
|
|
15
|
+
exports: [GeminiSessionManager, GeminiAuthManager],
|
|
16
|
+
})
|
|
17
|
+
export class GeminiModule {}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SessionStatus = 'idle' | 'processing' | 'terminated';
|
|
2
|
+
|
|
3
|
+
export interface GeminiSession {
|
|
4
|
+
id: string;
|
|
5
|
+
status: SessionStatus;
|
|
6
|
+
workingDirectory: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
lastActivity: Date;
|
|
9
|
+
persisted: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SessionInfo {
|
|
13
|
+
id: string;
|
|
14
|
+
status: SessionStatus;
|
|
15
|
+
workingDirectory: string;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
lastActivity: Date;
|
|
18
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
|
|
4
|
+
import { ClaudePtyManager } from './claude/claude-pty.manager';
|
|
5
|
+
import { CodexSessionManager } from './codex/codex-session.manager';
|
|
6
|
+
import { GeminiSessionManager } from './gemini/gemini-session.manager';
|
|
7
|
+
|
|
8
|
+
jest.mock('child_process', () => ({
|
|
9
|
+
spawn: jest.fn(),
|
|
10
|
+
execSync: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const spawnMock = spawn as jest.Mock;
|
|
14
|
+
|
|
15
|
+
function mockRepo() {
|
|
16
|
+
return {
|
|
17
|
+
save: jest.fn().mockResolvedValue({}),
|
|
18
|
+
update: jest.fn().mockResolvedValue({}),
|
|
19
|
+
findOne: jest.fn(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function mockProcess() {
|
|
24
|
+
const proc = new EventEmitter() as EventEmitter & {
|
|
25
|
+
stdout: EventEmitter;
|
|
26
|
+
stderr: EventEmitter;
|
|
27
|
+
killed: boolean;
|
|
28
|
+
kill: jest.Mock;
|
|
29
|
+
};
|
|
30
|
+
proc.stdout = new EventEmitter();
|
|
31
|
+
proc.stderr = new EventEmitter();
|
|
32
|
+
proc.killed = false;
|
|
33
|
+
proc.kill = jest.fn(() => {
|
|
34
|
+
proc.killed = true;
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
return proc;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function flushPromises() {
|
|
41
|
+
await Promise.resolve();
|
|
42
|
+
await Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('agent session termination', () => {
|
|
46
|
+
afterEach(() => jest.clearAllMocks());
|
|
47
|
+
|
|
48
|
+
it('kills a running Claude process and does not reset DB status to idle after close', async () => {
|
|
49
|
+
const proc = mockProcess();
|
|
50
|
+
spawnMock.mockReturnValueOnce(proc);
|
|
51
|
+
const agentRepo = mockRepo();
|
|
52
|
+
const sessionRepo = mockRepo();
|
|
53
|
+
const manager = new ClaudePtyManager(agentRepo as never, sessionRepo as never);
|
|
54
|
+
const session = manager.createSession('/tmp/project');
|
|
55
|
+
|
|
56
|
+
manager.sendMessage(session.id, 'hello');
|
|
57
|
+
await flushPromises();
|
|
58
|
+
manager.terminateSession(session.id);
|
|
59
|
+
proc.emit('close', 0);
|
|
60
|
+
|
|
61
|
+
expect(proc.kill).toHaveBeenCalledWith('SIGTERM');
|
|
62
|
+
expect(agentRepo.update).toHaveBeenCalledWith(session.id, { status: 'terminated' });
|
|
63
|
+
expect(agentRepo.update).not.toHaveBeenCalledWith(session.id, { status: 'idle' });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('kills a running Gemini process and does not reset DB status to idle after close', async () => {
|
|
67
|
+
const proc = mockProcess();
|
|
68
|
+
spawnMock.mockReturnValueOnce(proc);
|
|
69
|
+
const agentRepo = mockRepo();
|
|
70
|
+
const sessionRepo = mockRepo();
|
|
71
|
+
const authManager = { getEnvForGemini: jest.fn(() => ({})) };
|
|
72
|
+
const manager = new GeminiSessionManager(agentRepo as never, sessionRepo as never, authManager as never);
|
|
73
|
+
const session = manager.createSession('/tmp/project');
|
|
74
|
+
|
|
75
|
+
manager.sendMessage(session.id, 'hello');
|
|
76
|
+
await flushPromises();
|
|
77
|
+
manager.terminateSession(session.id);
|
|
78
|
+
proc.emit('close', 0);
|
|
79
|
+
|
|
80
|
+
expect(proc.kill).toHaveBeenCalledWith('SIGTERM');
|
|
81
|
+
expect(agentRepo.update).toHaveBeenCalledWith(session.id, { status: 'terminated' });
|
|
82
|
+
expect(agentRepo.update).not.toHaveBeenCalledWith(session.id, { status: 'idle' });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('kills a running Codex process and persists terminated status', async () => {
|
|
86
|
+
const proc = mockProcess();
|
|
87
|
+
spawnMock.mockReturnValueOnce(proc);
|
|
88
|
+
const agentRepo = mockRepo();
|
|
89
|
+
const sessionRepo = mockRepo();
|
|
90
|
+
const authManager = { getEnvForCodex: jest.fn(() => ({})) };
|
|
91
|
+
const manager = new CodexSessionManager(agentRepo as never, sessionRepo as never, authManager as never);
|
|
92
|
+
const session = manager.createSession('/tmp/project');
|
|
93
|
+
|
|
94
|
+
manager.sendMessage(session.id, 'hello');
|
|
95
|
+
await flushPromises();
|
|
96
|
+
manager.terminateSession(session.id);
|
|
97
|
+
proc.emit('close', 0);
|
|
98
|
+
|
|
99
|
+
expect(proc.kill).toHaveBeenCalledWith('SIGTERM');
|
|
100
|
+
expect(agentRepo.update).toHaveBeenCalledWith(session.id, { status: 'terminated' });
|
|
101
|
+
expect(agentRepo.update).not.toHaveBeenCalledWith(session.id, { status: 'idle' });
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Controller, Get, Param } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { GitChangelogService } from './changelog.service';
|
|
4
|
+
|
|
5
|
+
@Controller('tasks')
|
|
6
|
+
export class ChangelogController {
|
|
7
|
+
constructor(private readonly changelogService: GitChangelogService) {}
|
|
8
|
+
|
|
9
|
+
/** GET /tasks/:taskId/changelog */
|
|
10
|
+
@Get(':taskId/changelog')
|
|
11
|
+
getChangelog(@Param('taskId') taskId: string) {
|
|
12
|
+
return this.changelogService.getByTask(taskId);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** GET /tasks/:taskId/runs/:runId/changelog */
|
|
16
|
+
@Get(':taskId/runs/:runId/changelog')
|
|
17
|
+
getRunChangelog(@Param('taskId') taskId: string, @Param('runId') runId: string) {
|
|
18
|
+
return this.changelogService.getByTask(taskId, Number(runId));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
+
|
|
4
|
+
import { AgentChangelogEntity } from '../../database/entities/agent-changelog.entity';
|
|
5
|
+
import { ChangelogController } from './changelog.controller';
|
|
6
|
+
import { GitChangelogService } from './changelog.service';
|
|
7
|
+
|
|
8
|
+
@Module({
|
|
9
|
+
imports: [TypeOrmModule.forFeature([AgentChangelogEntity])],
|
|
10
|
+
controllers: [ChangelogController],
|
|
11
|
+
providers: [GitChangelogService],
|
|
12
|
+
exports: [GitChangelogService],
|
|
13
|
+
})
|
|
14
|
+
export class ChangelogModule {}
|