@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,140 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import {
3
+ ConnectedSocket,
4
+ MessageBody,
5
+ OnGatewayConnection,
6
+ OnGatewayDisconnect,
7
+ OnGatewayInit,
8
+ SubscribeMessage,
9
+ WebSocketGateway,
10
+ WebSocketServer,
11
+ } from '@nestjs/websockets';
12
+ import { Server, Socket } from 'socket.io';
13
+
14
+ import { TaskExecutionService } from './task-execution.service';
15
+ import type {
16
+ AgentDoneEvent,
17
+ AgentErrorEvent,
18
+ AgentOutputEvent,
19
+ AgentToolEvent,
20
+ TaskStatusEvent,
21
+ } from './task-execution.service';
22
+
23
+ /**
24
+ * WebSocket 프로토콜 (/tasks 네임스페이스)
25
+ *
26
+ * Client → Server
27
+ * task:subscribe { taskId } 특정 태스크 룸 구독 (에이전트 출력 수신)
28
+ * task:unsubscribe { taskId } 특정 태스크 룸 구독 해제
29
+ * task:get-logs { taskId } 버퍼된 로그 요청 (늦은 구독자)
30
+ * task:watch-all 전역 알림 룸 구독 (모든 task:status 수신)
31
+ * task:unwatch-all 전역 알림 룸 구독 해제
32
+ *
33
+ * Server → Client
34
+ * agent:output { taskId, agentId, text }
35
+ * agent:tool { taskId, agentId, tool, input }
36
+ * agent:done { taskId, agentId, result, isError, durationMs, costUsd }
37
+ * agent:error { taskId, agentId, message }
38
+ * task:status { taskId, status, title? } — 특정 룸 + 전역 알림 룸
39
+ * task:buffered-logs { taskId, logs }
40
+ */
41
+
42
+ const NOTIFICATIONS_ROOM = 'task:notifications';
43
+
44
+ @WebSocketGateway({ namespace: '/tasks', cors: { origin: '*' } })
45
+ export class TaskGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
46
+ @WebSocketServer()
47
+ private readonly server!: Server;
48
+
49
+ private readonly logger = new Logger(TaskGateway.name);
50
+
51
+ constructor(private readonly executionService: TaskExecutionService) {}
52
+
53
+ afterInit(): void {
54
+ this.executionService.on('agent:output', (e: AgentOutputEvent) => {
55
+ this.server.to(`task:${e.taskId}`).emit('agent:output', e);
56
+ });
57
+
58
+ this.executionService.on('agent:tool', (e: AgentToolEvent) => {
59
+ this.server.to(`task:${e.taskId}`).emit('agent:tool', e);
60
+ });
61
+
62
+ this.executionService.on('agent:done', (e: AgentDoneEvent) => {
63
+ this.server.to(`task:${e.taskId}`).emit('agent:done', e);
64
+ });
65
+
66
+ this.executionService.on('agent:error', (e: AgentErrorEvent) => {
67
+ this.server.to(`task:${e.taskId}`).emit('agent:error', e);
68
+ });
69
+
70
+ this.executionService.on('task:status', (e: TaskStatusEvent) => {
71
+ // 1. 특정 태스크 룸 (에이전트 출력 패널용)
72
+ this.server.to(`task:${e.taskId}`).emit('task:status', e);
73
+ // 2. 전역 알림 룸 (useTaskNotification 구독자 전체)
74
+ this.server.to(NOTIFICATIONS_ROOM).emit('task:status', e);
75
+ });
76
+
77
+ this.logger.log('TaskGateway initialised — namespace: /tasks');
78
+ }
79
+
80
+ handleConnection(client: Socket): void {
81
+ this.logger.debug(`Client connected: ${client.id}`);
82
+ }
83
+
84
+ handleDisconnect(client: Socket): void {
85
+ this.logger.debug(`Client disconnected: ${client.id}`);
86
+ }
87
+
88
+ // ─── 특정 태스크 구독 ─────────────────────────────────────────────────────
89
+
90
+ @SubscribeMessage('task:subscribe')
91
+ handleSubscribe(
92
+ @ConnectedSocket() client: Socket,
93
+ @MessageBody('taskId') taskId: string,
94
+ ): void {
95
+ void client.join(`task:${taskId}`);
96
+ this.logger.debug(`${client.id} subscribed to task:${taskId}`);
97
+ }
98
+
99
+ @SubscribeMessage('task:unsubscribe')
100
+ handleUnsubscribe(
101
+ @ConnectedSocket() client: Socket,
102
+ @MessageBody('taskId') taskId: string,
103
+ ): void {
104
+ void client.leave(`task:${taskId}`);
105
+ }
106
+
107
+ /** 늦은 구독자용 — 버퍼 우선, 없으면 DB에서 복원 */
108
+ @SubscribeMessage('task:get-logs')
109
+ handleGetLogs(
110
+ @ConnectedSocket() client: Socket,
111
+ @MessageBody('taskId') taskId: string,
112
+ ): void {
113
+ const buffered = this.executionService.getBufferedLogs(taskId);
114
+
115
+ if (buffered.length > 0) {
116
+ client.emit('task:buffered-logs', { taskId, logs: buffered });
117
+ return;
118
+ }
119
+
120
+ // 서버 재시작 후 버퍼 소실 — DB에서 복원
121
+ void this.executionService.getLogsFromDb(taskId).then((logs) => {
122
+ client.emit('task:buffered-logs', { taskId, logs });
123
+ });
124
+ }
125
+
126
+ // ─── 전역 알림 룸 ─────────────────────────────────────────────────────────
127
+
128
+ /** 모든 task:status 이벤트를 받는 전역 알림 룸 가입 */
129
+ @SubscribeMessage('task:watch-all')
130
+ handleWatchAll(@ConnectedSocket() client: Socket): void {
131
+ void client.join(NOTIFICATIONS_ROOM);
132
+ this.logger.debug(`${client.id} joined notifications room`);
133
+ }
134
+
135
+ /** 전역 알림 룸 탈퇴 */
136
+ @SubscribeMessage('task:unwatch-all')
137
+ handleUnwatchAll(@ConnectedSocket() client: Socket): void {
138
+ void client.leave(NOTIFICATIONS_ROOM);
139
+ }
140
+ }
@@ -0,0 +1,210 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+
3
+ import { TasksController } from './tasks.controller';
4
+ import { TasksService } from './tasks.service';
5
+ import type { TaskEntity } from '../../database/entities/task.entity';
6
+ import type { TaskRunEntity } from '../../database/entities/task-run.entity';
7
+
8
+ const mockTask: TaskEntity = {
9
+ id: 'task-1',
10
+ title: 'Test Task',
11
+ status: 'pending',
12
+ workingDir: '/tmp/project',
13
+ claudeSessionId: null,
14
+ archived: false,
15
+ createdAt: new Date('2024-01-01'),
16
+ updatedAt: new Date('2024-01-01'),
17
+ requirements: [],
18
+ agents: [],
19
+ };
20
+
21
+ describe('TasksController', () => {
22
+ let controller: TasksController;
23
+ let service: jest.Mocked<TasksService>;
24
+
25
+ beforeEach(async () => {
26
+ const module: TestingModule = await Test.createTestingModule({
27
+ controllers: [TasksController],
28
+ providers: [
29
+ {
30
+ provide: TasksService,
31
+ useValue: {
32
+ create: jest.fn(),
33
+ findAll: jest.fn(),
34
+ findOne: jest.fn(),
35
+ update: jest.fn(),
36
+ execute: jest.fn(),
37
+ stop: jest.fn(),
38
+ rerun: jest.fn(),
39
+ rerunAgent: jest.fn(),
40
+ getRuns: jest.fn(),
41
+ archive: jest.fn(),
42
+ mergeAgentAll: jest.fn(),
43
+ mergeAgentFile: jest.fn(),
44
+ remove: jest.fn(),
45
+ },
46
+ },
47
+ ],
48
+ }).compile();
49
+
50
+ controller = module.get(TasksController);
51
+ service = module.get(TasksService) as jest.Mocked<TasksService>;
52
+ });
53
+
54
+ afterEach(() => jest.clearAllMocks());
55
+
56
+ describe('create', () => {
57
+ it('service.create를 호출하고 결과를 반환한다', async () => {
58
+ service.create.mockResolvedValue(mockTask);
59
+
60
+ const result = await controller.create({ title: 'Test Task' });
61
+
62
+ expect(service.create).toHaveBeenCalledWith({ title: 'Test Task' });
63
+ expect(result).toBe(mockTask);
64
+ });
65
+ });
66
+
67
+ describe('findAll', () => {
68
+ it('service.findAll를 호출하고 task 목록을 반환한다', async () => {
69
+ service.findAll.mockResolvedValue([mockTask]);
70
+
71
+ const result = await controller.findAll();
72
+
73
+ expect(service.findAll).toHaveBeenCalled();
74
+ expect(result).toEqual([mockTask]);
75
+ });
76
+ });
77
+
78
+ describe('findOne', () => {
79
+ it('service.findOne를 id와 함께 호출한다', async () => {
80
+ service.findOne.mockResolvedValue(mockTask);
81
+
82
+ const result = await controller.findOne('task-1');
83
+
84
+ expect(service.findOne).toHaveBeenCalledWith('task-1');
85
+ expect(result).toBe(mockTask);
86
+ });
87
+ });
88
+
89
+ describe('update', () => {
90
+ it('service.update를 id와 dto와 함께 호출한다', async () => {
91
+ const updated = { ...mockTask, title: 'Updated' };
92
+ service.update.mockResolvedValue(updated);
93
+
94
+ const result = await controller.update('task-1', { title: 'Updated' });
95
+
96
+ expect(service.update).toHaveBeenCalledWith('task-1', { title: 'Updated' });
97
+ expect(result).toBe(updated);
98
+ });
99
+ });
100
+
101
+ describe('execute', () => {
102
+ it('service.execute를 호출한다', async () => {
103
+ const running = { ...mockTask, status: 'running' };
104
+ service.execute.mockResolvedValue(running);
105
+
106
+ const result = await controller.execute('task-1', { agentTestCodePreferences: [{ agentId: 1, writeTestCode: true }] });
107
+
108
+ expect(service.execute).toHaveBeenCalledWith('task-1', [{ agentId: 1, writeTestCode: true }]);
109
+ expect(result).toBe(running);
110
+ });
111
+ });
112
+
113
+ describe('stop', () => {
114
+ it('service.stop를 호출한다', async () => {
115
+ const stopped = { ...mockTask, status: 'stopped' };
116
+ service.stop.mockResolvedValue(stopped);
117
+
118
+ const result = await controller.stop('task-1');
119
+
120
+ expect(service.stop).toHaveBeenCalledWith('task-1');
121
+ expect(result).toBe(stopped);
122
+ });
123
+ });
124
+
125
+ describe('rerun', () => {
126
+ it('service.rerun을 supplementNote와 함께 호출한다', async () => {
127
+ service.rerun.mockResolvedValue(mockTask);
128
+
129
+ const result = await controller.rerun('task-1', { supplementNote: '보완 작업' });
130
+
131
+ expect(service.rerun).toHaveBeenCalledWith('task-1', '보완 작업', undefined);
132
+ expect(result).toBe(mockTask);
133
+ });
134
+
135
+ it('supplementNote 없이 호출할 수 있다', async () => {
136
+ service.rerun.mockResolvedValue(mockTask);
137
+
138
+ await controller.rerun('task-1', {});
139
+
140
+ expect(service.rerun).toHaveBeenCalledWith('task-1', undefined, undefined);
141
+ });
142
+ });
143
+
144
+ describe('rerunAgent', () => {
145
+ it('service.rerunAgent를 agentId와 supplementNote로 호출한다', async () => {
146
+ service.rerunAgent.mockResolvedValue(mockTask);
147
+
148
+ const result = await controller.rerunAgent('task-1', '2', { supplementNote: 'agent only', writeTestCode: true });
149
+
150
+ expect(service.rerunAgent).toHaveBeenCalledWith('task-1', 2, 'agent only', true);
151
+ expect(result).toBe(mockTask);
152
+ });
153
+ });
154
+
155
+ describe('getRuns', () => {
156
+ it('service.getRuns를 호출하고 실행 이력을 반환한다', async () => {
157
+ const runs: TaskRunEntity[] = [
158
+ { id: 1, taskId: 'task-1', version: 1, supplementNote: null, status: 'completed', startedAt: new Date(), completedAt: null, task: mockTask, agentRuns: [] },
159
+ ];
160
+ service.getRuns.mockResolvedValue(runs);
161
+
162
+ const result = await controller.getRuns('task-1');
163
+
164
+ expect(service.getRuns).toHaveBeenCalledWith('task-1');
165
+ expect(result).toBe(runs);
166
+ });
167
+ });
168
+
169
+ describe('archive', () => {
170
+ it('service.archive를 호출한다', async () => {
171
+ service.archive.mockResolvedValue(undefined);
172
+
173
+ await controller.archive('task-1');
174
+
175
+ expect(service.archive).toHaveBeenCalledWith('task-1');
176
+ });
177
+ });
178
+
179
+ describe('mergeAgentAll', () => {
180
+ it('service.mergeAgentAll을 id와 agentId로 호출한다', async () => {
181
+ service.mergeAgentAll.mockResolvedValue({ success: true, message: '완료' });
182
+
183
+ const result = await controller.mergeAgentAll('task-1', '2');
184
+
185
+ expect(service.mergeAgentAll).toHaveBeenCalledWith('task-1', 2);
186
+ expect(result).toEqual({ success: true, message: '완료' });
187
+ });
188
+ });
189
+
190
+ describe('mergeAgentFile', () => {
191
+ it('service.mergeAgentFile을 filePath와 함께 호출한다', async () => {
192
+ service.mergeAgentFile.mockResolvedValue({ success: true, message: '완료' });
193
+
194
+ const result = await controller.mergeAgentFile('task-1', '2', { filePath: 'src/app.ts' });
195
+
196
+ expect(service.mergeAgentFile).toHaveBeenCalledWith('task-1', 2, 'src/app.ts');
197
+ expect(result).toEqual({ success: true, message: '완료' });
198
+ });
199
+ });
200
+
201
+ describe('remove', () => {
202
+ it('service.remove를 호출한다', async () => {
203
+ service.remove.mockResolvedValue(undefined);
204
+
205
+ await controller.remove('task-1');
206
+
207
+ expect(service.remove).toHaveBeenCalledWith('task-1');
208
+ });
209
+ });
210
+ });
@@ -0,0 +1,139 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ HttpCode,
7
+ HttpStatus,
8
+ Param,
9
+ Patch,
10
+ Post,
11
+ UsePipes,
12
+ ValidationPipe,
13
+ } from '@nestjs/common';
14
+ import { ApiNoContentResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
15
+
16
+ import { CreateTaskDto } from './dto/create-task.dto';
17
+ import { ExecuteTaskDto } from './dto/execute-task.dto';
18
+ import { MergeFileDto } from './dto/merge-file.dto';
19
+ import { RerunTaskDto } from './dto/rerun-task.dto';
20
+ import { UpdateTaskDto } from './dto/update-task.dto';
21
+ import { TasksService } from './tasks.service';
22
+
23
+ @ApiTags('tasks')
24
+ @UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
25
+ @Controller('tasks')
26
+ export class TasksController {
27
+ constructor(private readonly tasksService: TasksService) {}
28
+
29
+ @ApiOperation({ summary: '작업 생성' })
30
+ @ApiOkResponse({ description: '생성된 작업 정보' })
31
+ @Post()
32
+ create(@Body() dto: CreateTaskDto) {
33
+ return this.tasksService.create(dto);
34
+ }
35
+
36
+ @ApiOperation({ summary: '전체 작업 목록 조회' })
37
+ @ApiOkResponse({ description: '작업 목록 (에이전트 로그 포함)' })
38
+ @Get()
39
+ findAll() {
40
+ return this.tasksService.findAll();
41
+ }
42
+
43
+ @ApiOperation({ summary: '특정 작업 조회' })
44
+ @ApiOkResponse({ description: '작업 상세 정보' })
45
+ @Get(':id')
46
+ findOne(@Param('id') id: string) {
47
+ return this.tasksService.findOne(id);
48
+ }
49
+
50
+ @ApiOperation({ summary: '작업 수정 (제목·디렉토리·요구사항·에이전트)' })
51
+ @ApiOkResponse({ description: '수정된 작업 정보' })
52
+ @Patch(':id')
53
+ update(@Param('id') id: string, @Body() dto: UpdateTaskDto) {
54
+ return this.tasksService.update(id, dto);
55
+ }
56
+
57
+ @ApiOperation({
58
+ summary: '작업 실행',
59
+ description: '실시간 출력은 WebSocket `/tasks` 네임스페이스의 `agent:output` / `task:status` 이벤트로 수신',
60
+ })
61
+ @ApiOkResponse({ description: '실행 시작 확인' })
62
+ @Post(':id/execute')
63
+ @HttpCode(HttpStatus.OK)
64
+ execute(@Param('id') id: string, @Body() dto: ExecuteTaskDto = {}) {
65
+ return this.tasksService.execute(id, dto.agentTestCodePreferences);
66
+ }
67
+
68
+ @ApiOperation({ summary: '실행 중인 작업 중지' })
69
+ @ApiOkResponse({ description: '중지 확인' })
70
+ @Post(':id/stop')
71
+ @HttpCode(HttpStatus.OK)
72
+ stop(@Param('id') id: string) {
73
+ return this.tasksService.stop(id);
74
+ }
75
+
76
+ @ApiOperation({ summary: '작업 재실행', description: '보완 메모를 추가하여 동일 작업을 다시 실행' })
77
+ @ApiOkResponse({ description: '재실행 시작 확인' })
78
+ @Post(':id/rerun')
79
+ @HttpCode(HttpStatus.OK)
80
+ rerun(@Param('id') id: string, @Body() dto: RerunTaskDto) {
81
+ return this.tasksService.rerun(id, dto.supplementNote, dto.writeTestCode);
82
+ }
83
+
84
+ @ApiOperation({ summary: '에이전트 단위 작업 재실행', description: '보완 메모를 추가하여 특정 에이전트만 다시 실행' })
85
+ @ApiOkResponse({ description: '에이전트 재실행 시작 확인' })
86
+ @Post(':id/agents/:agentId/rerun')
87
+ @HttpCode(HttpStatus.OK)
88
+ rerunAgent(
89
+ @Param('id') id: string,
90
+ @Param('agentId') agentId: string,
91
+ @Body() dto: RerunTaskDto,
92
+ ) {
93
+ return this.tasksService.rerunAgent(id, Number(agentId), dto.supplementNote, dto.writeTestCode);
94
+ }
95
+
96
+ @ApiOperation({ summary: '실행 버전 이력 조회' })
97
+ @ApiOkResponse({ description: '버전별 실행 기록 (supplementNote, 상태, 에이전트 결과 포함)' })
98
+ @Get(':id/runs')
99
+ getRuns(@Param('id') id: string) {
100
+ return this.tasksService.getRuns(id);
101
+ }
102
+
103
+ @ApiOperation({ summary: '작업 보관' })
104
+ @ApiNoContentResponse({ description: '보관 완료 (응답 본문 없음)' })
105
+ @Post(':id/archive')
106
+ @HttpCode(HttpStatus.NO_CONTENT)
107
+ archive(@Param('id') id: string) {
108
+ return this.tasksService.archive(id);
109
+ }
110
+
111
+ @ApiOperation({ summary: '에이전트 전체 변경사항 병합' })
112
+ @ApiOkResponse({ description: '병합 결과' })
113
+ @Post(':id/agents/:agentId/merge')
114
+ mergeAgentAll(
115
+ @Param('id') id: string,
116
+ @Param('agentId') agentId: string,
117
+ ) {
118
+ return this.tasksService.mergeAgentAll(id, Number(agentId));
119
+ }
120
+
121
+ @ApiOperation({ summary: '에이전트 단일 파일 병합' })
122
+ @ApiOkResponse({ description: '병합 결과' })
123
+ @Post(':id/agents/:agentId/merge-file')
124
+ mergeAgentFile(
125
+ @Param('id') id: string,
126
+ @Param('agentId') agentId: string,
127
+ @Body() dto: MergeFileDto,
128
+ ) {
129
+ return this.tasksService.mergeAgentFile(id, Number(agentId), dto.filePath);
130
+ }
131
+
132
+ @ApiOperation({ summary: '작업 삭제' })
133
+ @ApiNoContentResponse({ description: '삭제 완료 (응답 본문 없음)' })
134
+ @Delete(':id')
135
+ @HttpCode(HttpStatus.NO_CONTENT)
136
+ remove(@Param('id') id: string) {
137
+ return this.tasksService.remove(id);
138
+ }
139
+ }
@@ -0,0 +1,30 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { TypeOrmModule } from '@nestjs/typeorm';
3
+
4
+ import { TaskAgentEntity } from '../../database/entities/task-agent.entity';
5
+ import { TaskAgentRunEntity } from '../../database/entities/task-agent-run.entity';
6
+ import { TaskRequirementEntity } from '../../database/entities/task-requirement.entity';
7
+ import { TaskEntity } from '../../database/entities/task.entity';
8
+ import { TaskRunEntity } from '../../database/entities/task-run.entity';
9
+ import { GeminiModule } from '../agents/gemini/gemini.module';
10
+ import { ConversationModule } from '../conversations/conversation.module';
11
+ import { ChangelogModule } from '../changelog/changelog.module';
12
+ import { HarnessModule } from '../harness/harness.module';
13
+ import { TaskExecutionService } from './task-execution.service';
14
+ import { TaskGateway } from './task.gateway';
15
+ import { TasksController } from './tasks.controller';
16
+ import { TasksService } from './tasks.service';
17
+
18
+ @Module({
19
+ imports: [
20
+ TypeOrmModule.forFeature([TaskEntity, TaskRequirementEntity, TaskAgentEntity, TaskRunEntity, TaskAgentRunEntity]),
21
+ GeminiModule,
22
+ ConversationModule,
23
+ ChangelogModule,
24
+ HarnessModule,
25
+ ],
26
+ controllers: [TasksController],
27
+ providers: [TasksService, TaskExecutionService, TaskGateway],
28
+ exports: [TasksService],
29
+ })
30
+ export class TasksModule {}