@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,106 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+
3
+ import { ConversationEntity } from '../../database/entities/conversation.entity';
4
+ import { ConversationController } from './conversation.controller';
5
+ import { ConversationService } from './conversation.service';
6
+ import { AgentModel, ConversationType } from './enums/conversation.enum';
7
+
8
+ const baseConversation: ConversationEntity = {
9
+ id: 'conv-uuid-1',
10
+ sessionId: 'session-1',
11
+ promptId: 'prompt-1',
12
+ agentId: null,
13
+ runId: null,
14
+ content: '코드 분석해줘',
15
+ agentModel: AgentModel.CLAUDE,
16
+ type: ConversationType.USER_MESSAGE,
17
+ createdAt: new Date('2024-01-01'),
18
+ };
19
+
20
+ describe('ConversationController', () => {
21
+ let controller: ConversationController;
22
+ let service: jest.Mocked<ConversationService>;
23
+
24
+ beforeEach(async () => {
25
+ const module: TestingModule = await Test.createTestingModule({
26
+ controllers: [ConversationController],
27
+ providers: [
28
+ {
29
+ provide: ConversationService,
30
+ useValue: {
31
+ create: jest.fn(),
32
+ findBySession: jest.fn(),
33
+ findOne: jest.fn(),
34
+ remove: jest.fn(),
35
+ removeBySession: jest.fn(),
36
+ },
37
+ },
38
+ ],
39
+ }).compile();
40
+
41
+ controller = module.get(ConversationController);
42
+ service = module.get(ConversationService) as jest.Mocked<ConversationService>;
43
+ });
44
+
45
+ afterEach(() => jest.clearAllMocks());
46
+
47
+ describe('create', () => {
48
+ it('service.create를 호출하고 결과를 반환한다', async () => {
49
+ service.create.mockResolvedValue(baseConversation);
50
+
51
+ const dto = {
52
+ sessionId: 'session-1',
53
+ promptId: 'prompt-1',
54
+ content: '코드 분석해줘',
55
+ agentModel: AgentModel.CLAUDE,
56
+ type: ConversationType.USER_MESSAGE,
57
+ };
58
+ const result = await controller.create(dto);
59
+
60
+ expect(service.create).toHaveBeenCalledWith(dto);
61
+ expect(result).toBe(baseConversation);
62
+ });
63
+ });
64
+
65
+ describe('findBySession', () => {
66
+ it('service.findBySession을 sessionId로 호출한다', async () => {
67
+ service.findBySession.mockResolvedValue([baseConversation]);
68
+
69
+ const result = await controller.findBySession('session-1');
70
+
71
+ expect(service.findBySession).toHaveBeenCalledWith('session-1');
72
+ expect(result).toEqual([baseConversation]);
73
+ });
74
+ });
75
+
76
+ describe('findOne', () => {
77
+ it('service.findOne을 id로 호출한다', async () => {
78
+ service.findOne.mockResolvedValue(baseConversation);
79
+
80
+ const result = await controller.findOne('conv-uuid-1');
81
+
82
+ expect(service.findOne).toHaveBeenCalledWith('conv-uuid-1');
83
+ expect(result).toBe(baseConversation);
84
+ });
85
+ });
86
+
87
+ describe('remove', () => {
88
+ it('service.remove를 id로 호출한다', async () => {
89
+ service.remove.mockResolvedValue(undefined);
90
+
91
+ await controller.remove('conv-uuid-1');
92
+
93
+ expect(service.remove).toHaveBeenCalledWith('conv-uuid-1');
94
+ });
95
+ });
96
+
97
+ describe('removeBySession', () => {
98
+ it('service.removeBySession을 sessionId로 호출한다', async () => {
99
+ service.removeBySession.mockResolvedValue(undefined);
100
+
101
+ await controller.removeBySession('session-1');
102
+
103
+ expect(service.removeBySession).toHaveBeenCalledWith('session-1');
104
+ });
105
+ });
106
+ });
@@ -0,0 +1,60 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ HttpCode,
7
+ HttpStatus,
8
+ Param,
9
+ Post,
10
+ UsePipes,
11
+ ValidationPipe,
12
+ } from '@nestjs/common';
13
+ import { ApiNoContentResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
14
+
15
+ import { ConversationService } from './conversation.service';
16
+ import { CreateConversationDto } from './dto/create-conversation.dto';
17
+
18
+ @ApiTags('conversations')
19
+ @UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
20
+ @Controller('conversations')
21
+ export class ConversationController {
22
+ constructor(private readonly conversationService: ConversationService) {}
23
+
24
+ @ApiOperation({ summary: '대화 메시지 저장' })
25
+ @ApiOkResponse({ description: '저장된 대화 레코드' })
26
+ @Post()
27
+ create(@Body() dto: CreateConversationDto) {
28
+ return this.conversationService.create(dto);
29
+ }
30
+
31
+ @ApiOperation({ summary: '세션의 전체 대화 조회' })
32
+ @ApiOkResponse({ description: '대화 목록 (시간순)' })
33
+ @Get('session/:sessionId')
34
+ findBySession(@Param('sessionId') sessionId: string) {
35
+ return this.conversationService.findBySession(sessionId);
36
+ }
37
+
38
+ @ApiOperation({ summary: '대화 단건 조회' })
39
+ @ApiOkResponse({ description: '대화 레코드' })
40
+ @Get(':id')
41
+ findOne(@Param('id') id: string) {
42
+ return this.conversationService.findOne(id);
43
+ }
44
+
45
+ @ApiOperation({ summary: '대화 단건 삭제' })
46
+ @ApiNoContentResponse({ description: '삭제 완료 (응답 본문 없음)' })
47
+ @Delete(':id')
48
+ @HttpCode(HttpStatus.NO_CONTENT)
49
+ remove(@Param('id') id: string) {
50
+ return this.conversationService.remove(id);
51
+ }
52
+
53
+ @ApiOperation({ summary: '세션 전체 대화 삭제' })
54
+ @ApiNoContentResponse({ description: '삭제 완료 (응답 본문 없음)' })
55
+ @Delete('session/:sessionId')
56
+ @HttpCode(HttpStatus.NO_CONTENT)
57
+ removeBySession(@Param('sessionId') sessionId: string) {
58
+ return this.conversationService.removeBySession(sessionId);
59
+ }
60
+ }
@@ -0,0 +1,14 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { TypeOrmModule } from '@nestjs/typeorm';
3
+
4
+ import { ConversationEntity } from '../../database/entities/conversation.entity';
5
+ import { ConversationController } from './conversation.controller';
6
+ import { ConversationService } from './conversation.service';
7
+
8
+ @Module({
9
+ imports: [TypeOrmModule.forFeature([ConversationEntity])],
10
+ controllers: [ConversationController],
11
+ providers: [ConversationService],
12
+ exports: [ConversationService],
13
+ })
14
+ export class ConversationModule {}
@@ -0,0 +1,176 @@
1
+ import { NotFoundException } from '@nestjs/common';
2
+ import { Test, TestingModule } from '@nestjs/testing';
3
+ import { getRepositoryToken } from '@nestjs/typeorm';
4
+
5
+ import { ConversationEntity } from '../../database/entities/conversation.entity';
6
+ import { AgentModel, ConversationType } from './enums/conversation.enum';
7
+ import { ConversationService } from './conversation.service';
8
+
9
+ const mockRepo = () => ({
10
+ create: jest.fn((dto: any) => ({ ...dto })),
11
+ save: jest.fn((e: any) => Promise.resolve(e)),
12
+ findOne: jest.fn(),
13
+ find: jest.fn(),
14
+ remove: jest.fn().mockResolvedValue({}),
15
+ delete: jest.fn().mockResolvedValue({}),
16
+ });
17
+
18
+ describe('ConversationService', () => {
19
+ let service: ConversationService;
20
+ let repo: ReturnType<typeof mockRepo>;
21
+
22
+ const baseConversation: ConversationEntity = {
23
+ id: 'conv-uuid-1',
24
+ sessionId: 'session-1',
25
+ promptId: 'prompt-1',
26
+ agentId: null,
27
+ runId: null,
28
+ content: '코드 분석해줘',
29
+ agentModel: AgentModel.CLAUDE,
30
+ type: ConversationType.USER_MESSAGE,
31
+ createdAt: new Date('2024-01-01'),
32
+ };
33
+
34
+ beforeEach(async () => {
35
+ const module: TestingModule = await Test.createTestingModule({
36
+ providers: [
37
+ ConversationService,
38
+ { provide: getRepositoryToken(ConversationEntity), useFactory: mockRepo },
39
+ ],
40
+ }).compile();
41
+
42
+ service = module.get(ConversationService);
43
+ repo = module.get(getRepositoryToken(ConversationEntity));
44
+ });
45
+
46
+ afterEach(() => jest.clearAllMocks());
47
+
48
+ // ─── create ──────────────────────────────────────────────────────────────
49
+
50
+ describe('create', () => {
51
+ it('대화 메시지를 생성하고 저장한다', async () => {
52
+ repo.save.mockResolvedValue(baseConversation);
53
+
54
+ const dto = {
55
+ sessionId: 'session-1',
56
+ promptId: 'prompt-1',
57
+ content: '코드 분석해줘',
58
+ agentModel: AgentModel.CLAUDE,
59
+ type: ConversationType.USER_MESSAGE,
60
+ };
61
+ const result = await service.create(dto);
62
+
63
+ expect(repo.create).toHaveBeenCalledWith(dto);
64
+ expect(repo.save).toHaveBeenCalled();
65
+ expect(result).toBe(baseConversation);
66
+ });
67
+
68
+ it('agentId와 runId를 포함한 메시지를 생성한다', async () => {
69
+ const withIds = { ...baseConversation, agentId: 5, runId: 2 };
70
+ repo.save.mockResolvedValue(withIds);
71
+
72
+ const dto = {
73
+ sessionId: 'session-1',
74
+ promptId: 'prompt-1',
75
+ content: 'agent response',
76
+ agentModel: AgentModel.CLAUDE,
77
+ type: ConversationType.AGENT_MESSAGE,
78
+ agentId: 5,
79
+ runId: 2,
80
+ };
81
+ const result = await service.create(dto);
82
+
83
+ expect(result.agentId).toBe(5);
84
+ expect(result.runId).toBe(2);
85
+ });
86
+ });
87
+
88
+ // ─── findBySession ───────────────────────────────────────────────────────
89
+
90
+ describe('findBySession', () => {
91
+ it('세션의 전체 대화를 생성 시간 오름차순으로 반환한다', async () => {
92
+ repo.find.mockResolvedValue([baseConversation]);
93
+
94
+ const result = await service.findBySession('session-1');
95
+
96
+ expect(result).toEqual([baseConversation]);
97
+ expect(repo.find).toHaveBeenCalledWith({
98
+ where: { sessionId: 'session-1' },
99
+ order: { createdAt: 'ASC' },
100
+ });
101
+ });
102
+
103
+ it('대화가 없으면 빈 배열을 반환한다', async () => {
104
+ repo.find.mockResolvedValue([]);
105
+
106
+ const result = await service.findBySession('empty-session');
107
+
108
+ expect(result).toEqual([]);
109
+ });
110
+ });
111
+
112
+ // ─── findByRun ───────────────────────────────────────────────────────────
113
+
114
+ describe('findByRun', () => {
115
+ it('run의 대화를 생성 시간 오름차순으로 반환한다', async () => {
116
+ const runConv = { ...baseConversation, runId: 3 };
117
+ repo.find.mockResolvedValue([runConv]);
118
+
119
+ const result = await service.findByRun(3);
120
+
121
+ expect(result).toEqual([runConv]);
122
+ expect(repo.find).toHaveBeenCalledWith({
123
+ where: { runId: 3 },
124
+ order: { createdAt: 'ASC' },
125
+ });
126
+ });
127
+ });
128
+
129
+ // ─── findOne ─────────────────────────────────────────────────────────────
130
+
131
+ describe('findOne', () => {
132
+ it('ID로 대화를 조회한다', async () => {
133
+ repo.findOne.mockResolvedValue(baseConversation);
134
+
135
+ const result = await service.findOne('conv-uuid-1');
136
+
137
+ expect(result).toBe(baseConversation);
138
+ expect(repo.findOne).toHaveBeenCalledWith({ where: { id: 'conv-uuid-1' } });
139
+ });
140
+
141
+ it('존재하지 않는 ID는 NotFoundException을 던진다', async () => {
142
+ repo.findOne.mockResolvedValue(null);
143
+
144
+ await expect(service.findOne('not-exist')).rejects.toThrow(NotFoundException);
145
+ });
146
+ });
147
+
148
+ // ─── remove ──────────────────────────────────────────────────────────────
149
+
150
+ describe('remove', () => {
151
+ it('대화를 조회 후 삭제한다', async () => {
152
+ repo.findOne.mockResolvedValue(baseConversation);
153
+
154
+ await service.remove('conv-uuid-1');
155
+
156
+ expect(repo.findOne).toHaveBeenCalled();
157
+ expect(repo.remove).toHaveBeenCalledWith(baseConversation);
158
+ });
159
+
160
+ it('존재하지 않는 ID는 NotFoundException을 던진다', async () => {
161
+ repo.findOne.mockResolvedValue(null);
162
+
163
+ await expect(service.remove('not-exist')).rejects.toThrow(NotFoundException);
164
+ });
165
+ });
166
+
167
+ // ─── removeBySession ─────────────────────────────────────────────────────
168
+
169
+ describe('removeBySession', () => {
170
+ it('세션의 전체 대화를 삭제한다', async () => {
171
+ await service.removeBySession('session-1');
172
+
173
+ expect(repo.delete).toHaveBeenCalledWith({ sessionId: 'session-1' });
174
+ });
175
+ });
176
+ });
@@ -0,0 +1,54 @@
1
+ import { Injectable, NotFoundException } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { Repository } from 'typeorm';
4
+
5
+ import { ConversationEntity } from '../../database/entities/conversation.entity';
6
+ import { CreateConversationDto } from './dto/create-conversation.dto';
7
+
8
+ @Injectable()
9
+ export class ConversationService {
10
+ constructor(
11
+ @InjectRepository(ConversationEntity)
12
+ private readonly repo: Repository<ConversationEntity>,
13
+ ) {}
14
+
15
+ /** 대화 메시지 저장 */
16
+ create(dto: CreateConversationDto): Promise<ConversationEntity> {
17
+ const entity = this.repo.create(dto);
18
+ return this.repo.save(entity);
19
+ }
20
+
21
+ /** 특정 세션의 전체 대화 조회 (생성 순) */
22
+ findBySession(sessionId: string): Promise<ConversationEntity[]> {
23
+ return this.repo.find({
24
+ where: { sessionId },
25
+ order: { createdAt: 'ASC' },
26
+ });
27
+ }
28
+
29
+ /** 특정 run의 대화 조회 (생성 순) */
30
+ findByRun(runId: number): Promise<ConversationEntity[]> {
31
+ return this.repo.find({
32
+ where: { runId },
33
+ order: { createdAt: 'ASC' },
34
+ });
35
+ }
36
+
37
+ /** 단건 조회 */
38
+ async findOne(id: string): Promise<ConversationEntity> {
39
+ const entity = await this.repo.findOne({ where: { id } });
40
+ if (!entity) throw new NotFoundException(`Conversation ${id} not found`);
41
+ return entity;
42
+ }
43
+
44
+ /** 단건 삭제 */
45
+ async remove(id: string): Promise<void> {
46
+ const entity = await this.findOne(id);
47
+ await this.repo.remove(entity);
48
+ }
49
+
50
+ /** 세션 전체 삭제 */
51
+ async removeBySession(sessionId: string): Promise<void> {
52
+ await this.repo.delete({ sessionId });
53
+ }
54
+ }
@@ -0,0 +1,37 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsEnum, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator';
3
+
4
+ import { AgentModel, ConversationType } from '../enums/conversation.enum';
5
+
6
+ export class CreateConversationDto {
7
+ @ApiProperty({ example: 'uuid-session-id', description: '세션 ID' })
8
+ @IsString()
9
+ @IsNotEmpty()
10
+ sessionId!: string;
11
+
12
+ @ApiProperty({ example: 'uuid-prompt-id', description: '프롬프트 ID' })
13
+ @IsString()
14
+ @IsNotEmpty()
15
+ promptId!: string;
16
+
17
+ @ApiProperty({ example: '코드 분석해줘', description: '메시지 내용' })
18
+ @IsString()
19
+ @IsNotEmpty()
20
+ content!: string;
21
+
22
+ @ApiProperty({ enum: AgentModel, example: AgentModel.CLAUDE, description: '에이전트 모델' })
23
+ @IsEnum(AgentModel)
24
+ agentModel!: AgentModel;
25
+
26
+ @ApiProperty({ enum: ConversationType, example: ConversationType.USER_MESSAGE, description: '메시지 유형' })
27
+ @IsEnum(ConversationType)
28
+ type!: ConversationType;
29
+
30
+ @IsInt()
31
+ @IsOptional()
32
+ agentId?: number | null;
33
+
34
+ @IsInt()
35
+ @IsOptional()
36
+ runId?: number | null;
37
+ }
@@ -0,0 +1,13 @@
1
+ export enum AgentModel {
2
+ CLAUDE = 'claude',
3
+ CHATGPT = 'chatgpt',
4
+ GEMINI = 'gemini',
5
+ OPENCODE = 'opencode',
6
+ GROK = 'grok',
7
+ CODEX = 'codex',
8
+ }
9
+
10
+ export enum ConversationType {
11
+ USER_MESSAGE = 'user_message',
12
+ AGENT_MESSAGE = 'agent_message',
13
+ }
@@ -0,0 +1,29 @@
1
+ import { Controller, Get, Query } from '@nestjs/common';
2
+ import { ApiOperation, ApiTags } from '@nestjs/swagger';
3
+ import * as fs from 'fs';
4
+ import * as os from 'os';
5
+ import * as path from 'path';
6
+
7
+ @ApiTags('fs')
8
+ @Controller('fs')
9
+ export class FsController {
10
+ @ApiOperation({ summary: '하위 디렉토리 목록 조회' })
11
+ @Get('dirs')
12
+ listDirs(@Query('path') inputPath?: string) {
13
+ const target = inputPath
14
+ ? path.resolve(inputPath.replace(/^~(?=\/|$)/, os.homedir()))
15
+ : os.homedir();
16
+
17
+ try {
18
+ const entries = fs.readdirSync(target, { withFileTypes: true });
19
+ const dirs = entries
20
+ .filter((e) => e.isDirectory() && !e.name.startsWith('.'))
21
+ .map((e) => e.name)
22
+ .sort((a, b) => a.localeCompare(b));
23
+
24
+ return { path: target, dirs };
25
+ } catch {
26
+ return { path: target, dirs: [] };
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,8 @@
1
+ import { Module } from '@nestjs/common';
2
+
3
+ import { FsController } from './fs.controller';
4
+
5
+ @Module({
6
+ controllers: [FsController],
7
+ })
8
+ export class FsModule {}
@@ -0,0 +1,9 @@
1
+ import { IsEnum, IsString } from 'class-validator';
2
+
3
+ export class SaveHarnessDto {
4
+ @IsString()
5
+ content!: string;
6
+
7
+ @IsEnum(['md', 'tsx'])
8
+ ext!: 'md' | 'tsx';
9
+ }
@@ -0,0 +1,95 @@
1
+ import { Test, TestingModule } from '@nestjs/testing';
2
+
3
+ import { HarnessController } from './harness.controller';
4
+ import { HarnessService } from './harness.service';
5
+ import type { Harness } from './harness.service';
6
+
7
+ describe('HarnessController', () => {
8
+ let controller: HarnessController;
9
+ let service: jest.Mocked<HarnessService>;
10
+
11
+ const commonHarness: Harness = { role: 'common', ext: 'md', content: '# Common Template' };
12
+ const frontendHarness: Harness = { role: 'frontend', ext: 'tsx', content: 'export default () => null;' };
13
+
14
+ beforeEach(async () => {
15
+ const module: TestingModule = await Test.createTestingModule({
16
+ controllers: [HarnessController],
17
+ providers: [
18
+ {
19
+ provide: HarnessService,
20
+ useValue: {
21
+ findAll: jest.fn(),
22
+ findOne: jest.fn(),
23
+ save: jest.fn(),
24
+ remove: jest.fn(),
25
+ },
26
+ },
27
+ ],
28
+ }).compile();
29
+
30
+ controller = module.get(HarnessController);
31
+ service = module.get(HarnessService) as jest.Mocked<HarnessService>;
32
+ });
33
+
34
+ afterEach(() => jest.clearAllMocks());
35
+
36
+ describe('findAll', () => {
37
+ it('service.findAll을 호출하고 모든 harness를 반환한다', () => {
38
+ service.findAll.mockReturnValue([commonHarness, frontendHarness]);
39
+
40
+ const result = controller.findAll();
41
+
42
+ expect(service.findAll).toHaveBeenCalled();
43
+ expect(result).toEqual([commonHarness, frontendHarness]);
44
+ });
45
+ });
46
+
47
+ describe('findOne', () => {
48
+ it('harness가 존재하면 반환한다', () => {
49
+ service.findOne.mockReturnValue(commonHarness);
50
+
51
+ const result = controller.findOne('common');
52
+
53
+ expect(service.findOne).toHaveBeenCalledWith('common');
54
+ expect(result).toBe(commonHarness);
55
+ });
56
+
57
+ it('harness가 없으면 기본값을 반환한다', () => {
58
+ service.findOne.mockReturnValue(null);
59
+
60
+ const result = controller.findOne('other');
61
+
62
+ expect(result).toEqual({ role: 'other', ext: 'md', content: '' });
63
+ });
64
+ });
65
+
66
+ describe('save', () => {
67
+ it('service.save를 role, content, ext와 함께 호출한다', () => {
68
+ service.save.mockReturnValue(commonHarness);
69
+
70
+ const result = controller.save('common', { content: '# Common Template', ext: 'md' });
71
+
72
+ expect(service.save).toHaveBeenCalledWith('common', '# Common Template', 'md');
73
+ expect(result).toBe(commonHarness);
74
+ });
75
+
76
+ it('tsx 확장자로 저장할 수 있다', () => {
77
+ service.save.mockReturnValue(frontendHarness);
78
+
79
+ const result = controller.save('frontend', { content: 'export default () => null;', ext: 'tsx' });
80
+
81
+ expect(service.save).toHaveBeenCalledWith('frontend', 'export default () => null;', 'tsx');
82
+ expect(result).toBe(frontendHarness);
83
+ });
84
+ });
85
+
86
+ describe('remove', () => {
87
+ it('service.remove를 role과 함께 호출한다', () => {
88
+ service.remove.mockReturnValue(undefined);
89
+
90
+ controller.remove('common');
91
+
92
+ expect(service.remove).toHaveBeenCalledWith('common');
93
+ });
94
+ });
95
+ });
@@ -0,0 +1,35 @@
1
+ import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Put, UsePipes, ValidationPipe } from '@nestjs/common';
2
+
3
+ import { HarnessService } from './harness.service';
4
+ import { SaveHarnessDto } from './dto/save-harness.dto';
5
+
6
+ @UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
7
+ @Controller('harness')
8
+ export class HarnessController {
9
+ constructor(private readonly harnessService: HarnessService) {}
10
+
11
+ /** GET /harness */
12
+ @Get()
13
+ findAll() {
14
+ return this.harnessService.findAll();
15
+ }
16
+
17
+ /** GET /harness/:role */
18
+ @Get(':role')
19
+ findOne(@Param('role') role: string) {
20
+ return this.harnessService.findOne(role) ?? { role, ext: 'md', content: '' };
21
+ }
22
+
23
+ /** PUT /harness/:role */
24
+ @Put(':role')
25
+ save(@Param('role') role: string, @Body() dto: SaveHarnessDto) {
26
+ return this.harnessService.save(role, dto.content, dto.ext);
27
+ }
28
+
29
+ /** DELETE /harness/:role */
30
+ @Delete(':role')
31
+ @HttpCode(HttpStatus.NO_CONTENT)
32
+ remove(@Param('role') role: string) {
33
+ this.harnessService.remove(role);
34
+ }
35
+ }
@@ -0,0 +1,11 @@
1
+ import { Module } from '@nestjs/common';
2
+
3
+ import { HarnessController } from './harness.controller';
4
+ import { HarnessService } from './harness.service';
5
+
6
+ @Module({
7
+ controllers: [HarnessController],
8
+ providers: [HarnessService],
9
+ exports: [HarnessService],
10
+ })
11
+ export class HarnessModule {}