@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.
Files changed (264) hide show
  1. package/.gitignore +23 -0
  2. package/.npmignore +21 -0
  3. package/.prettierignore +6 -0
  4. package/.prettierrc +26 -0
  5. package/AGENTS.md +10 -0
  6. package/CLAUDE.md +10 -0
  7. package/README.md +384 -0
  8. package/apps/server/README.md +294 -0
  9. package/apps/server/eslint.config.mjs +20 -0
  10. package/apps/server/nest-cli.json +8 -0
  11. package/apps/server/package.json +89 -0
  12. package/apps/server/scripts/postinstall.js +53 -0
  13. package/apps/server/src/__mocks__/glob.js +6 -0
  14. package/apps/server/src/__mocks__/uuid.js +5 -0
  15. package/apps/server/src/app.controller.spec.ts +24 -0
  16. package/apps/server/src/app.controller.ts +13 -0
  17. package/apps/server/src/app.module.ts +18 -0
  18. package/apps/server/src/app.service.ts +8 -0
  19. package/apps/server/src/common/ji-paths.ts +41 -0
  20. package/apps/server/src/database/database.module.ts +27 -0
  21. package/apps/server/src/database/entities/agent-changelog.entity.ts +39 -0
  22. package/apps/server/src/database/entities/agent-session.entity.ts +29 -0
  23. package/apps/server/src/database/entities/conversation.entity.ts +41 -0
  24. package/apps/server/src/database/entities/session.entity.ts +16 -0
  25. package/apps/server/src/database/entities/task-agent-run.entity.ts +40 -0
  26. package/apps/server/src/database/entities/task-agent.entity.ts +42 -0
  27. package/apps/server/src/database/entities/task-requirement.entity.ts +27 -0
  28. package/apps/server/src/database/entities/task-run.entity.ts +41 -0
  29. package/apps/server/src/database/entities/task.entity.ts +44 -0
  30. package/apps/server/src/main.ts +65 -0
  31. package/apps/server/src/modules/agents/agent-model-settings.spec.ts +80 -0
  32. package/apps/server/src/modules/agents/agents.module.ts +11 -0
  33. package/apps/server/src/modules/agents/claude/claude-auth.manager.ts +83 -0
  34. package/apps/server/src/modules/agents/claude/claude-pty.manager.ts +380 -0
  35. package/apps/server/src/modules/agents/claude/claude.controller.ts +85 -0
  36. package/apps/server/src/modules/agents/claude/claude.gateway.ts +158 -0
  37. package/apps/server/src/modules/agents/claude/claude.module.ts +18 -0
  38. package/apps/server/src/modules/agents/claude/claude.service.ts +67 -0
  39. package/apps/server/src/modules/agents/claude/dto/create-session.dto.ts +24 -0
  40. package/apps/server/src/modules/agents/claude/dto/resize-session.dto.ts +13 -0
  41. package/apps/server/src/modules/agents/claude/dto/send-input.dto.ts +9 -0
  42. package/apps/server/src/modules/agents/claude/interfaces/claude-session.interface.ts +26 -0
  43. package/apps/server/src/modules/agents/claude/interfaces/pty-event.interface.ts +10 -0
  44. package/apps/server/src/modules/agents/claude/interfaces/stream-event.interface.ts +61 -0
  45. package/apps/server/src/modules/agents/codex/codex-auth.manager.ts +107 -0
  46. package/apps/server/src/modules/agents/codex/codex-session.manager.ts +357 -0
  47. package/apps/server/src/modules/agents/codex/codex.controller.ts +64 -0
  48. package/apps/server/src/modules/agents/codex/codex.gateway.ts +97 -0
  49. package/apps/server/src/modules/agents/codex/codex.module.ts +17 -0
  50. package/apps/server/src/modules/agents/codex/dto/configure-auth.dto.ts +7 -0
  51. package/apps/server/src/modules/agents/gemini/dto/configure-auth.dto.ts +15 -0
  52. package/apps/server/src/modules/agents/gemini/dto/create-session.dto.ts +9 -0
  53. package/apps/server/src/modules/agents/gemini/dto/send-input.dto.ts +9 -0
  54. package/apps/server/src/modules/agents/gemini/gemini-auth.manager.ts +157 -0
  55. package/apps/server/src/modules/agents/gemini/gemini-session.manager.ts +287 -0
  56. package/apps/server/src/modules/agents/gemini/gemini.controller.ts +93 -0
  57. package/apps/server/src/modules/agents/gemini/gemini.gateway.ts +149 -0
  58. package/apps/server/src/modules/agents/gemini/gemini.module.ts +17 -0
  59. package/apps/server/src/modules/agents/gemini/interfaces/gemini-session.interface.ts +18 -0
  60. package/apps/server/src/modules/agents/gemini/interfaces/stream-event.interface.ts +14 -0
  61. package/apps/server/src/modules/agents/session-termination.spec.ts +103 -0
  62. package/apps/server/src/modules/changelog/changelog.controller.ts +20 -0
  63. package/apps/server/src/modules/changelog/changelog.module.ts +14 -0
  64. package/apps/server/src/modules/changelog/changelog.service.spec.ts +531 -0
  65. package/apps/server/src/modules/changelog/changelog.service.ts +690 -0
  66. package/apps/server/src/modules/conversations/conversation.controller.spec.ts +106 -0
  67. package/apps/server/src/modules/conversations/conversation.controller.ts +60 -0
  68. package/apps/server/src/modules/conversations/conversation.module.ts +14 -0
  69. package/apps/server/src/modules/conversations/conversation.service.spec.ts +176 -0
  70. package/apps/server/src/modules/conversations/conversation.service.ts +54 -0
  71. package/apps/server/src/modules/conversations/dto/create-conversation.dto.ts +37 -0
  72. package/apps/server/src/modules/conversations/enums/conversation.enum.ts +13 -0
  73. package/apps/server/src/modules/fs/fs.controller.ts +29 -0
  74. package/apps/server/src/modules/fs/fs.module.ts +8 -0
  75. package/apps/server/src/modules/harness/dto/save-harness.dto.ts +9 -0
  76. package/apps/server/src/modules/harness/harness.controller.spec.ts +95 -0
  77. package/apps/server/src/modules/harness/harness.controller.ts +35 -0
  78. package/apps/server/src/modules/harness/harness.module.ts +11 -0
  79. package/apps/server/src/modules/harness/harness.service.spec.ts +217 -0
  80. package/apps/server/src/modules/harness/harness.service.ts +112 -0
  81. package/apps/server/src/modules/sessions/session.controller.spec.ts +68 -0
  82. package/apps/server/src/modules/sessions/session.controller.ts +43 -0
  83. package/apps/server/src/modules/sessions/session.module.ts +14 -0
  84. package/apps/server/src/modules/sessions/session.service.spec.ts +106 -0
  85. package/apps/server/src/modules/sessions/session.service.ts +35 -0
  86. package/apps/server/src/modules/tasks/dto/create-task.dto.ts +54 -0
  87. package/apps/server/src/modules/tasks/dto/execute-task.dto.ts +22 -0
  88. package/apps/server/src/modules/tasks/dto/merge-file.dto.ts +7 -0
  89. package/apps/server/src/modules/tasks/dto/rerun-task.dto.ts +14 -0
  90. package/apps/server/src/modules/tasks/dto/update-task.dto.ts +55 -0
  91. package/apps/server/src/modules/tasks/task-execution.service.ts +978 -0
  92. package/apps/server/src/modules/tasks/task.gateway.ts +140 -0
  93. package/apps/server/src/modules/tasks/tasks.controller.spec.ts +210 -0
  94. package/apps/server/src/modules/tasks/tasks.controller.ts +139 -0
  95. package/apps/server/src/modules/tasks/tasks.module.ts +30 -0
  96. package/apps/server/src/modules/tasks/tasks.service.spec.ts +552 -0
  97. package/apps/server/src/modules/tasks/tasks.service.ts +333 -0
  98. package/apps/server/test/app.e2e-spec.ts +28 -0
  99. package/apps/server/test/jest-e2e.json +9 -0
  100. package/apps/server/tsconfig.build.json +4 -0
  101. package/apps/server/tsconfig.json +13 -0
  102. package/apps/web/AGENTS.md +7 -0
  103. package/apps/web/CLAUDE.md +1 -0
  104. package/apps/web/README.md +36 -0
  105. package/apps/web/eslint.config.mjs +21 -0
  106. package/apps/web/next-env.d.ts +6 -0
  107. package/apps/web/next.config.ts +7 -0
  108. package/apps/web/package.json +49 -0
  109. package/apps/web/postcss.config.mjs +7 -0
  110. package/apps/web/public/file.svg +1 -0
  111. package/apps/web/public/globe.svg +1 -0
  112. package/apps/web/public/next.svg +1 -0
  113. package/apps/web/public/vercel.svg +1 -0
  114. package/apps/web/public/window.svg +1 -0
  115. package/apps/web/src/app/claude/page.tsx +5 -0
  116. package/apps/web/src/app/codex/page.tsx +126 -0
  117. package/apps/web/src/app/favicon.ico +0 -0
  118. package/apps/web/src/app/gemini/page.tsx +130 -0
  119. package/apps/web/src/app/globals.css +149 -0
  120. package/apps/web/src/app/layout.tsx +40 -0
  121. package/apps/web/src/app/login/page.tsx +67 -0
  122. package/apps/web/src/app/page.tsx +497 -0
  123. package/apps/web/src/app/task/[id]/page.tsx +11 -0
  124. package/apps/web/src/app/test/page.tsx +298 -0
  125. package/apps/web/src/components/ui/Modal.tsx +78 -0
  126. package/apps/web/src/components/ui/WorkingDirPicker.tsx +195 -0
  127. package/apps/web/src/components/ui/__tests__/Modal.test.tsx +68 -0
  128. package/apps/web/src/features/auth/api/__tests__/auth.api.test.ts +83 -0
  129. package/apps/web/src/features/auth/api/auth.api.ts +81 -0
  130. package/apps/web/src/features/auth/hooks/__tests__/useClaudeAuth.test.ts +166 -0
  131. package/apps/web/src/features/auth/hooks/__tests__/useCodexAuth.test.ts +127 -0
  132. package/apps/web/src/features/auth/hooks/__tests__/useGeminiAuth.test.ts +120 -0
  133. package/apps/web/src/features/auth/hooks/useClaudeAuth.ts +88 -0
  134. package/apps/web/src/features/auth/hooks/useCodexAuth.ts +149 -0
  135. package/apps/web/src/features/auth/hooks/useGeminiAuth.ts +125 -0
  136. package/apps/web/src/features/auth/ui/CodexLoginPanel.tsx +302 -0
  137. package/apps/web/src/features/auth/ui/GeminiLoginPanel.tsx +316 -0
  138. package/apps/web/src/features/auth/ui/LoginForm.tsx +190 -0
  139. package/apps/web/src/features/auth/ui/LoginPanel.tsx +114 -0
  140. package/apps/web/src/features/auth/ui/__tests__/LoginPanel.test.tsx +105 -0
  141. package/apps/web/src/features/chat/api/__tests__/sessions.api.test.ts +187 -0
  142. package/apps/web/src/features/chat/api/sessions.api.ts +161 -0
  143. package/apps/web/src/features/chat/container/ClaudePageContainer.tsx +152 -0
  144. package/apps/web/src/features/chat/hooks/__tests__/useCodexSessions.test.ts +131 -0
  145. package/apps/web/src/features/chat/hooks/__tests__/useGeminiSessions.test.ts +130 -0
  146. package/apps/web/src/features/chat/hooks/useAgentModelSettings.ts +54 -0
  147. package/apps/web/src/features/chat/hooks/useClaudeSessions.ts +323 -0
  148. package/apps/web/src/features/chat/hooks/useCodexSessions.ts +275 -0
  149. package/apps/web/src/features/chat/hooks/useGeminiSessions.ts +255 -0
  150. package/apps/web/src/features/chat/hooks/useSessionCommand.ts +66 -0
  151. package/apps/web/src/features/chat/hooks/useSessionRename.ts +61 -0
  152. package/apps/web/src/features/chat/hooks/useSessionWorkingDirectories.ts +34 -0
  153. package/apps/web/src/features/chat/hooks/useUnifiedSessions.ts +156 -0
  154. package/apps/web/src/features/chat/lib/agentModelOptions.ts +72 -0
  155. package/apps/web/src/features/chat/ui/AgentModelPicker.tsx +134 -0
  156. package/apps/web/src/features/chat/ui/AgentSelectModal.tsx +236 -0
  157. package/apps/web/src/features/chat/ui/ChatInput.tsx +162 -0
  158. package/apps/web/src/features/chat/ui/ChatMessage.tsx +204 -0
  159. package/apps/web/src/features/chat/ui/ChatWorkspace.tsx +207 -0
  160. package/apps/web/src/features/chat/ui/CheckingSkeleton.tsx +44 -0
  161. package/apps/web/src/features/chat/ui/ClaudeLoginView.tsx +44 -0
  162. package/apps/web/src/features/chat/ui/PermissionCard.tsx +37 -0
  163. package/apps/web/src/features/chat/ui/SessionSidebar.tsx +280 -0
  164. package/apps/web/src/features/chat/ui/__tests__/AgentSelectModal.test.tsx +58 -0
  165. package/apps/web/src/features/chat/ui/__tests__/ChatInput.test.tsx +134 -0
  166. package/apps/web/src/features/chat/ui/__tests__/ChatMessage.test.tsx +106 -0
  167. package/apps/web/src/features/chat/ui/__tests__/ChatWorkspace.test.tsx +66 -0
  168. package/apps/web/src/features/diff/ui/DiffFileRow.tsx +73 -0
  169. package/apps/web/src/features/diff/ui/DiffHunk.tsx +61 -0
  170. package/apps/web/src/features/diff/ui/FileChangeBadge.tsx +23 -0
  171. package/apps/web/src/features/diff/ui/__tests__/DiffFileRow.test.tsx +40 -0
  172. package/apps/web/src/features/diff/ui/__tests__/DiffHunk.test.tsx +24 -0
  173. package/apps/web/src/features/diff/ui/__tests__/FileChangeBadge.test.tsx +16 -0
  174. package/apps/web/src/features/fs/api/fs.api.ts +14 -0
  175. package/apps/web/src/features/fs/hooks/useDirBrowser.ts +50 -0
  176. package/apps/web/src/features/harness/api/__tests__/harness.api.test.ts +73 -0
  177. package/apps/web/src/features/harness/api/harness.api.ts +46 -0
  178. package/apps/web/src/features/harness/hooks/__tests__/useHarness.test.ts +65 -0
  179. package/apps/web/src/features/harness/hooks/useHarness.ts +66 -0
  180. package/apps/web/src/features/harness/ui/HarnessModal.tsx +171 -0
  181. package/apps/web/src/features/harness/ui/__tests__/HarnessModal.test.tsx +46 -0
  182. package/apps/web/src/features/status/ui/AgentStatusModal.tsx +267 -0
  183. package/apps/web/src/features/status/ui/__tests__/AgentStatusModal.test.tsx +71 -0
  184. package/apps/web/src/features/tasks/api/__tests__/changelog.api.test.ts +89 -0
  185. package/apps/web/src/features/tasks/api/__tests__/tasks.api.test.ts +282 -0
  186. package/apps/web/src/features/tasks/api/changelog.api.ts +52 -0
  187. package/apps/web/src/features/tasks/api/tasks.api.ts +175 -0
  188. package/apps/web/src/features/tasks/container/TaskDetailPageContainer.tsx +69 -0
  189. package/apps/web/src/features/tasks/hooks/__tests__/useChangelogCodeCopy.test.ts +48 -0
  190. package/apps/web/src/features/tasks/hooks/__tests__/useTaskChangelog.test.ts +48 -0
  191. package/apps/web/src/features/tasks/hooks/__tests__/useTaskCreate.test.ts +217 -0
  192. package/apps/web/src/features/tasks/hooks/__tests__/useTaskEdit.test.ts +152 -0
  193. package/apps/web/src/features/tasks/hooks/__tests__/useTaskExecution.test.ts +143 -0
  194. package/apps/web/src/features/tasks/hooks/__tests__/useTaskList.test.ts +168 -0
  195. package/apps/web/src/features/tasks/hooks/__tests__/useTaskNotification.test.ts +125 -0
  196. package/apps/web/src/features/tasks/hooks/__tests__/useTaskRuns.test.ts +51 -0
  197. package/apps/web/src/features/tasks/hooks/useChangelogCodeCopy.ts +52 -0
  198. package/apps/web/src/features/tasks/hooks/useCopyToClipboard.ts +47 -0
  199. package/apps/web/src/features/tasks/hooks/useTaskChangelog.ts +32 -0
  200. package/apps/web/src/features/tasks/hooks/useTaskCreate.ts +137 -0
  201. package/apps/web/src/features/tasks/hooks/useTaskDetail.ts +217 -0
  202. package/apps/web/src/features/tasks/hooks/useTaskEdit.ts +130 -0
  203. package/apps/web/src/features/tasks/hooks/useTaskExecution.ts +137 -0
  204. package/apps/web/src/features/tasks/hooks/useTaskList.ts +159 -0
  205. package/apps/web/src/features/tasks/hooks/useTaskNotification.ts +80 -0
  206. package/apps/web/src/features/tasks/hooks/useTaskRuns.ts +32 -0
  207. package/apps/web/src/features/tasks/ui/AgentOutputPanel.tsx +203 -0
  208. package/apps/web/src/features/tasks/ui/AgentRoleSelect.tsx +97 -0
  209. package/apps/web/src/features/tasks/ui/ChangelogPanel.tsx +321 -0
  210. package/apps/web/src/features/tasks/ui/RunHistoryPanel.tsx +193 -0
  211. package/apps/web/src/features/tasks/ui/TaskCreateModal.tsx +205 -0
  212. package/apps/web/src/features/tasks/ui/TaskDetailView.tsx +413 -0
  213. package/apps/web/src/features/tasks/ui/TaskEditModal.tsx +165 -0
  214. package/apps/web/src/features/tasks/ui/TaskListModal.tsx +591 -0
  215. package/apps/web/src/features/tasks/ui/__tests__/AgentRoleSelect.test.tsx +91 -0
  216. package/apps/web/src/features/tasks/ui/__tests__/ChangelogPanel.test.tsx +94 -0
  217. package/apps/web/src/features/tasks/ui/__tests__/RunHistoryPanel.test.tsx +71 -0
  218. package/apps/web/src/features/tasks/ui/__tests__/TaskCreateModal.test.tsx +153 -0
  219. package/apps/web/src/features/tasks/ui/__tests__/TaskEditModal.test.tsx +75 -0
  220. package/apps/web/src/features/tasks/ui/__tests__/TaskListModal.test.tsx +243 -0
  221. package/apps/web/src/hooks/useWorkingDir.ts +28 -0
  222. package/apps/web/src/lib/__tests__/ansi.test.ts +88 -0
  223. package/apps/web/src/lib/ansi.ts +105 -0
  224. package/apps/web/src/lib/constants.ts +4 -0
  225. package/apps/web/src/lib/quota.ts +22 -0
  226. package/apps/web/src/lib/theme.tsx +78 -0
  227. package/apps/web/src/lib/toast.tsx +175 -0
  228. package/apps/web/src/store/agentStatusStore.ts +38 -0
  229. package/apps/web/tsconfig.json +18 -0
  230. package/apps/web/vitest.config.ts +25 -0
  231. package/apps/web/vitest.setup.ts +10 -0
  232. package/package.json +85 -0
  233. package/packages/cli/dist/commands/check.d.ts +1 -0
  234. package/packages/cli/dist/commands/check.js +89 -0
  235. package/packages/cli/dist/commands/init.d.ts +5 -0
  236. package/packages/cli/dist/commands/init.js +183 -0
  237. package/packages/cli/dist/commands/start.d.ts +4 -0
  238. package/packages/cli/dist/commands/start.js +188 -0
  239. package/packages/cli/dist/index.d.ts +2 -0
  240. package/packages/cli/dist/index.js +71 -0
  241. package/packages/cli/dist/utils/agent-tools.d.ts +28 -0
  242. package/packages/cli/dist/utils/agent-tools.js +193 -0
  243. package/packages/cli/dist/utils/project-init.d.ts +12 -0
  244. package/packages/cli/dist/utils/project-init.js +258 -0
  245. package/packages/cli/dist/utils/proxy.d.ts +8 -0
  246. package/packages/cli/dist/utils/proxy.js +138 -0
  247. package/packages/cli/package.json +30 -0
  248. package/packages/cli/src/commands/check.ts +77 -0
  249. package/packages/cli/src/commands/init.ts +209 -0
  250. package/packages/cli/src/commands/start.ts +183 -0
  251. package/packages/cli/src/index.ts +91 -0
  252. package/packages/cli/src/utils/agent-tools.ts +201 -0
  253. package/packages/cli/src/utils/project-init.ts +252 -0
  254. package/packages/cli/src/utils/proxy.ts +123 -0
  255. package/packages/cli/tsconfig.json +14 -0
  256. package/packages/eslint-config/base.mjs +31 -0
  257. package/packages/eslint-config/nest.mjs +55 -0
  258. package/packages/eslint-config/next.mjs +23 -0
  259. package/packages/eslint-config/package.json +20 -0
  260. package/packages/typescript-config/base.json +16 -0
  261. package/packages/typescript-config/nestjs.json +17 -0
  262. package/packages/typescript-config/nextjs.json +15 -0
  263. package/packages/typescript-config/package.json +11 -0
  264. 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,14 @@
1
+ export interface TextDeltaEvent {
2
+ sessionId: string;
3
+ text: string;
4
+ }
5
+
6
+ export interface ResultEvent {
7
+ sessionId: string;
8
+ isError: boolean;
9
+ }
10
+
11
+ export interface SessionExitEvent {
12
+ sessionId: string;
13
+ exitCode: number;
14
+ }
@@ -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 {}