vibeman 0.0.0 → 0.0.2

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 (230) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +114 -0
  3. package/dist/runtime/api/.tsbuildinfo +1 -0
  4. package/dist/runtime/api/agent/agent-service.d.ts +224 -0
  5. package/dist/runtime/api/agent/agent-service.js +895 -0
  6. package/dist/runtime/api/agent/ai-providers/claude-code-adapter.d.ts +61 -0
  7. package/dist/runtime/api/agent/ai-providers/claude-code-adapter.js +362 -0
  8. package/dist/runtime/api/agent/ai-providers/codex-cli-provider.d.ts +34 -0
  9. package/dist/runtime/api/agent/ai-providers/codex-cli-provider.js +315 -0
  10. package/dist/runtime/api/agent/ai-providers/index.d.ts +9 -0
  11. package/dist/runtime/api/agent/ai-providers/index.js +7 -0
  12. package/dist/runtime/api/agent/ai-providers/types.d.ts +182 -0
  13. package/dist/runtime/api/agent/ai-providers/types.js +5 -0
  14. package/dist/runtime/api/agent/codex-cli-provider.test.d.ts +1 -0
  15. package/dist/runtime/api/agent/codex-cli-provider.test.js +125 -0
  16. package/dist/runtime/api/agent/core-agent-service.d.ts +119 -0
  17. package/dist/runtime/api/agent/core-agent-service.js +267 -0
  18. package/dist/runtime/api/agent/parsers.d.ts +16 -0
  19. package/dist/runtime/api/agent/parsers.js +308 -0
  20. package/dist/runtime/api/agent/prompt-service.d.ts +30 -0
  21. package/dist/runtime/api/agent/prompt-service.js +449 -0
  22. package/dist/runtime/api/agent/prompt-service.test.d.ts +1 -0
  23. package/dist/runtime/api/agent/prompt-service.test.js +230 -0
  24. package/dist/runtime/api/agent/routing-policy.d.ts +188 -0
  25. package/dist/runtime/api/agent/routing-policy.js +246 -0
  26. package/dist/runtime/api/api/router-helpers.d.ts +32 -0
  27. package/dist/runtime/api/api/router-helpers.js +31 -0
  28. package/dist/runtime/api/api/routers/ai.d.ts +188 -0
  29. package/dist/runtime/api/api/routers/ai.js +395 -0
  30. package/dist/runtime/api/api/routers/executions.d.ts +98 -0
  31. package/dist/runtime/api/api/routers/executions.js +94 -0
  32. package/dist/runtime/api/api/routers/git.d.ts +45 -0
  33. package/dist/runtime/api/api/routers/git.js +35 -0
  34. package/dist/runtime/api/api/routers/provider-config.d.ts +165 -0
  35. package/dist/runtime/api/api/routers/provider-config.js +252 -0
  36. package/dist/runtime/api/api/routers/settings.d.ts +139 -0
  37. package/dist/runtime/api/api/routers/settings.js +113 -0
  38. package/dist/runtime/api/api/routers/tasks.d.ts +141 -0
  39. package/dist/runtime/api/api/routers/tasks.js +238 -0
  40. package/dist/runtime/api/api/routers/workflows.d.ts +267 -0
  41. package/dist/runtime/api/api/routers/workflows.js +310 -0
  42. package/dist/runtime/api/api/routers/worktrees.d.ts +101 -0
  43. package/dist/runtime/api/api/routers/worktrees.js +80 -0
  44. package/dist/runtime/api/api/trpc.d.ts +118 -0
  45. package/dist/runtime/api/api/trpc.js +34 -0
  46. package/dist/runtime/api/index.d.ts +9 -0
  47. package/dist/runtime/api/index.js +117 -0
  48. package/dist/runtime/api/lib/id-generator.d.ts +70 -0
  49. package/dist/runtime/api/lib/id-generator.js +123 -0
  50. package/dist/runtime/api/lib/image-paste-drop-extension.d.ts +26 -0
  51. package/dist/runtime/api/lib/image-paste-drop-extension.js +125 -0
  52. package/dist/runtime/api/lib/local-config.d.ts +245 -0
  53. package/dist/runtime/api/lib/local-config.js +288 -0
  54. package/dist/runtime/api/lib/logger.d.ts +11 -0
  55. package/dist/runtime/api/lib/logger.js +188 -0
  56. package/dist/runtime/api/lib/markdown-utils.d.ts +8 -0
  57. package/dist/runtime/api/lib/markdown-utils.js +282 -0
  58. package/dist/runtime/api/lib/markdown-utils.test.d.ts +1 -0
  59. package/dist/runtime/api/lib/markdown-utils.test.js +348 -0
  60. package/dist/runtime/api/lib/provider-detection.d.ts +59 -0
  61. package/dist/runtime/api/lib/provider-detection.js +244 -0
  62. package/dist/runtime/api/lib/server/agent-service-singleton.d.ts +6 -0
  63. package/dist/runtime/api/lib/server/agent-service-singleton.js +27 -0
  64. package/dist/runtime/api/lib/server/bootstrap.d.ts +38 -0
  65. package/dist/runtime/api/lib/server/bootstrap.js +197 -0
  66. package/dist/runtime/api/lib/server/git-service-singleton.d.ts +6 -0
  67. package/dist/runtime/api/lib/server/git-service-singleton.js +47 -0
  68. package/dist/runtime/api/lib/server/project-root.d.ts +2 -0
  69. package/dist/runtime/api/lib/server/project-root.js +61 -0
  70. package/dist/runtime/api/lib/server/task-service-singleton.d.ts +7 -0
  71. package/dist/runtime/api/lib/server/task-service-singleton.js +58 -0
  72. package/dist/runtime/api/lib/server/vibing-orchestrator-singleton.d.ts +7 -0
  73. package/dist/runtime/api/lib/server/vibing-orchestrator-singleton.js +57 -0
  74. package/dist/runtime/api/lib/tiptap-utils.clamp-selection.test.d.ts +1 -0
  75. package/dist/runtime/api/lib/tiptap-utils.clamp-selection.test.js +27 -0
  76. package/dist/runtime/api/lib/tiptap-utils.d.ts +130 -0
  77. package/dist/runtime/api/lib/tiptap-utils.js +327 -0
  78. package/dist/runtime/api/lib/trpc/client.d.ts +1 -0
  79. package/dist/runtime/api/lib/trpc/client.js +5 -0
  80. package/dist/runtime/api/lib/trpc/server.d.ts +915 -0
  81. package/dist/runtime/api/lib/trpc/server.js +11 -0
  82. package/dist/runtime/api/lib/trpc/ws-server.d.ts +8 -0
  83. package/dist/runtime/api/lib/trpc/ws-server.js +33 -0
  84. package/dist/runtime/api/persistence/database-service.d.ts +14 -0
  85. package/dist/runtime/api/persistence/database-service.js +74 -0
  86. package/dist/runtime/api/persistence/execution-log-persistence.d.ts +90 -0
  87. package/dist/runtime/api/persistence/execution-log-persistence.js +410 -0
  88. package/dist/runtime/api/persistence/execution-log-persistence.test.d.ts +1 -0
  89. package/dist/runtime/api/persistence/execution-log-persistence.test.js +170 -0
  90. package/dist/runtime/api/router.d.ts +918 -0
  91. package/dist/runtime/api/router.js +34 -0
  92. package/dist/runtime/api/settings-service.d.ts +110 -0
  93. package/dist/runtime/api/settings-service.js +613 -0
  94. package/dist/runtime/api/tasks/file-watcher.d.ts +23 -0
  95. package/dist/runtime/api/tasks/file-watcher.js +88 -0
  96. package/dist/runtime/api/tasks/task-file-parser.d.ts +13 -0
  97. package/dist/runtime/api/tasks/task-file-parser.js +161 -0
  98. package/dist/runtime/api/tasks/task-service.d.ts +36 -0
  99. package/dist/runtime/api/tasks/task-service.js +173 -0
  100. package/dist/runtime/api/types/index.d.ts +179 -0
  101. package/dist/runtime/api/types/index.js +1 -0
  102. package/dist/runtime/api/types/settings.d.ts +81 -0
  103. package/dist/runtime/api/types/settings.js +2 -0
  104. package/dist/runtime/api/types.d.ts +2 -0
  105. package/dist/runtime/api/types.js +1 -0
  106. package/dist/runtime/api/utils/env.d.ts +6 -0
  107. package/dist/runtime/api/utils/env.js +12 -0
  108. package/dist/runtime/api/utils/stripNextEnv.d.ts +7 -0
  109. package/dist/runtime/api/utils/stripNextEnv.js +22 -0
  110. package/dist/runtime/api/utils/title-slug.d.ts +6 -0
  111. package/dist/runtime/api/utils/title-slug.js +77 -0
  112. package/dist/runtime/api/utils/url.d.ts +2 -0
  113. package/dist/runtime/api/utils/url.js +19 -0
  114. package/dist/runtime/api/vcs/git-history-service.d.ts +57 -0
  115. package/dist/runtime/api/vcs/git-history-service.js +228 -0
  116. package/dist/runtime/api/vcs/git-service.d.ts +127 -0
  117. package/dist/runtime/api/vcs/git-service.js +284 -0
  118. package/dist/runtime/api/vcs/worktree-service.d.ts +93 -0
  119. package/dist/runtime/api/vcs/worktree-service.js +506 -0
  120. package/dist/runtime/api/vcs/worktree-service.test.d.ts +1 -0
  121. package/dist/runtime/api/vcs/worktree-service.test.js +20 -0
  122. package/dist/runtime/api/workflows/quality-pipeline.d.ts +58 -0
  123. package/dist/runtime/api/workflows/quality-pipeline.js +400 -0
  124. package/dist/runtime/api/workflows/vibing-orchestrator.d.ts +318 -0
  125. package/dist/runtime/api/workflows/vibing-orchestrator.js +1860 -0
  126. package/dist/runtime/web/.next/BUILD_ID +1 -0
  127. package/dist/runtime/web/.next/app-build-manifest.json +59 -0
  128. package/dist/runtime/web/.next/app-path-routes-manifest.json +7 -0
  129. package/dist/runtime/web/.next/build-manifest.json +33 -0
  130. package/dist/runtime/web/.next/package.json +1 -0
  131. package/dist/runtime/web/.next/prerender-manifest.json +61 -0
  132. package/dist/runtime/web/.next/react-loadable-manifest.json +39 -0
  133. package/dist/runtime/web/.next/required-server-files.json +334 -0
  134. package/dist/runtime/web/.next/routes-manifest.json +62 -0
  135. package/dist/runtime/web/.next/server/app/_not-found/page.js +2 -0
  136. package/dist/runtime/web/.next/server/app/_not-found/page.js.nft.json +1 -0
  137. package/dist/runtime/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  138. package/dist/runtime/web/.next/server/app/_not-found.html +7 -0
  139. package/dist/runtime/web/.next/server/app/_not-found.meta +8 -0
  140. package/dist/runtime/web/.next/server/app/_not-found.rsc +22 -0
  141. package/dist/runtime/web/.next/server/app/api/health/route.js +1 -0
  142. package/dist/runtime/web/.next/server/app/api/health/route.js.nft.json +1 -0
  143. package/dist/runtime/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -0
  144. package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js +1 -0
  145. package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js.nft.json +1 -0
  146. package/dist/runtime/web/.next/server/app/api/images/[...path]/route_client-reference-manifest.js +1 -0
  147. package/dist/runtime/web/.next/server/app/api/upload/route.js +1 -0
  148. package/dist/runtime/web/.next/server/app/api/upload/route.js.nft.json +1 -0
  149. package/dist/runtime/web/.next/server/app/api/upload/route_client-reference-manifest.js +1 -0
  150. package/dist/runtime/web/.next/server/app/index.html +7 -0
  151. package/dist/runtime/web/.next/server/app/index.meta +7 -0
  152. package/dist/runtime/web/.next/server/app/index.rsc +27 -0
  153. package/dist/runtime/web/.next/server/app/page.js +147 -0
  154. package/dist/runtime/web/.next/server/app/page.js.nft.json +1 -0
  155. package/dist/runtime/web/.next/server/app/page_client-reference-manifest.js +1 -0
  156. package/dist/runtime/web/.next/server/app-paths-manifest.json +7 -0
  157. package/dist/runtime/web/.next/server/chunks/217.js +1 -0
  158. package/dist/runtime/web/.next/server/chunks/383.js +6 -0
  159. package/dist/runtime/web/.next/server/chunks/458.js +1 -0
  160. package/dist/runtime/web/.next/server/chunks/576.js +18 -0
  161. package/dist/runtime/web/.next/server/chunks/635.js +22 -0
  162. package/dist/runtime/web/.next/server/chunks/761.js +1 -0
  163. package/dist/runtime/web/.next/server/chunks/777.js +3 -0
  164. package/dist/runtime/web/.next/server/chunks/825.js +1 -0
  165. package/dist/runtime/web/.next/server/chunks/838.js +1 -0
  166. package/dist/runtime/web/.next/server/chunks/973.js +15 -0
  167. package/dist/runtime/web/.next/server/functions-config-manifest.json +4 -0
  168. package/dist/runtime/web/.next/server/middleware-build-manifest.js +1 -0
  169. package/dist/runtime/web/.next/server/middleware-manifest.json +6 -0
  170. package/dist/runtime/web/.next/server/middleware-react-loadable-manifest.js +1 -0
  171. package/dist/runtime/web/.next/server/next-font-manifest.js +1 -0
  172. package/dist/runtime/web/.next/server/next-font-manifest.json +1 -0
  173. package/dist/runtime/web/.next/server/pages/404.html +7 -0
  174. package/dist/runtime/web/.next/server/pages/500.html +1 -0
  175. package/dist/runtime/web/.next/server/pages/_app.js +1 -0
  176. package/dist/runtime/web/.next/server/pages/_app.js.nft.json +1 -0
  177. package/dist/runtime/web/.next/server/pages/_document.js +1 -0
  178. package/dist/runtime/web/.next/server/pages/_document.js.nft.json +1 -0
  179. package/dist/runtime/web/.next/server/pages/_error.js +19 -0
  180. package/dist/runtime/web/.next/server/pages/_error.js.nft.json +1 -0
  181. package/dist/runtime/web/.next/server/pages-manifest.json +6 -0
  182. package/dist/runtime/web/.next/server/server-reference-manifest.js +1 -0
  183. package/dist/runtime/web/.next/server/server-reference-manifest.json +1 -0
  184. package/dist/runtime/web/.next/server/webpack-runtime.js +1 -0
  185. package/dist/runtime/web/.next/static/chunks/18-15c10d3288afef2e.js +1 -0
  186. package/dist/runtime/web/.next/static/chunks/1c0ca389.537bbe362e3ffbd9.js +3 -0
  187. package/dist/runtime/web/.next/static/chunks/22747d63-ad5da0c19f4cfe41.js +71 -0
  188. package/dist/runtime/web/.next/static/chunks/277-0142a939f08738c3.js +63 -0
  189. package/dist/runtime/web/.next/static/chunks/355.056c2645878a799a.js +1 -0
  190. package/dist/runtime/web/.next/static/chunks/420.a5ccf151c9e2b2f1.js +1 -0
  191. package/dist/runtime/web/.next/static/chunks/439.1be0c6242fd248d5.js +15 -0
  192. package/dist/runtime/web/.next/static/chunks/440.c52e7c0f797e22b2.js +1 -0
  193. package/dist/runtime/web/.next/static/chunks/575-e2478287c27da87b.js +1 -0
  194. package/dist/runtime/web/.next/static/chunks/691.920d88c115087314.js +1 -0
  195. package/dist/runtime/web/.next/static/chunks/765-e838910065b50c3d.js +1 -0
  196. package/dist/runtime/web/.next/static/chunks/87c73c54-09e1ba5c70e60a51.js +1 -0
  197. package/dist/runtime/web/.next/static/chunks/891cff7f.0f71fc028f87e683.js +1 -0
  198. package/dist/runtime/web/.next/static/chunks/8bb4d8db-3e2aa02b0a2384b9.js +1 -0
  199. package/dist/runtime/web/.next/static/chunks/9af238c7-271a911d4e99ab18.js +1 -0
  200. package/dist/runtime/web/.next/static/chunks/app/_not-found/page-1cb74d1cba27d0ab.js +1 -0
  201. package/dist/runtime/web/.next/static/chunks/app/api/health/route-105a61ae865ba536.js +1 -0
  202. package/dist/runtime/web/.next/static/chunks/app/api/images/[...path]/route-105a61ae865ba536.js +1 -0
  203. package/dist/runtime/web/.next/static/chunks/app/api/upload/route-105a61ae865ba536.js +1 -0
  204. package/dist/runtime/web/.next/static/chunks/app/layout-8435322f09fd0975.js +1 -0
  205. package/dist/runtime/web/.next/static/chunks/app/page-8c3ba579efc6f918.js +1 -0
  206. package/dist/runtime/web/.next/static/chunks/cac567b0-5b77dd12911823cd.js +1 -0
  207. package/dist/runtime/web/.next/static/chunks/framework-2518f1345b5b2806.js +1 -0
  208. package/dist/runtime/web/.next/static/chunks/main-17665e5e39de9a8a.js +1 -0
  209. package/dist/runtime/web/.next/static/chunks/main-app-c0b0f5ba4f7f9d75.js +1 -0
  210. package/dist/runtime/web/.next/static/chunks/pages/_app-d6f6b3bbc3d81ee1.js +1 -0
  211. package/dist/runtime/web/.next/static/chunks/pages/_error-75a96cf1997cc3b9.js +1 -0
  212. package/dist/runtime/web/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  213. package/dist/runtime/web/.next/static/chunks/webpack-c8de37305b4635cf.js +1 -0
  214. package/dist/runtime/web/.next/static/css/08c950681f1a9a92.css +1 -0
  215. package/dist/runtime/web/.next/static/css/2728291c68f99cb1.css +3 -0
  216. package/dist/runtime/web/.next/static/css/521bd69cc298cd1a.css +1 -0
  217. package/dist/runtime/web/.next/static/css/537e22821e101b87.css +1 -0
  218. package/dist/runtime/web/.next/static/mRpNgPfbYR_0wrODzlg_4/_buildManifest.js +1 -0
  219. package/dist/runtime/web/.next/static/mRpNgPfbYR_0wrODzlg_4/_ssgManifest.js +1 -0
  220. package/dist/runtime/web/.next/static/media/19cfc7226ec3afaa-s.woff2 +0 -0
  221. package/dist/runtime/web/.next/static/media/21350d82a1f187e9-s.woff2 +0 -0
  222. package/dist/runtime/web/.next/static/media/8e9860b6e62d6359-s.woff2 +0 -0
  223. package/dist/runtime/web/.next/static/media/ba9851c3c22cd980-s.woff2 +0 -0
  224. package/dist/runtime/web/.next/static/media/c5fe6dc8356a8c31-s.woff2 +0 -0
  225. package/dist/runtime/web/.next/static/media/df0a9ae256c0569c-s.woff2 +0 -0
  226. package/dist/runtime/web/.next/static/media/e4af272ccee01ff0-s.p.woff2 +0 -0
  227. package/dist/runtime/web/package.json +65 -0
  228. package/dist/runtime/web/server.js +44 -0
  229. package/dist/tsconfig.tsbuildinfo +1 -0
  230. package/package.json +84 -7
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Codex CLI Provider
3
+ * Headless wrapper around the Codex CLI `codex exec` command.
4
+ */
5
+ import { spawn } from 'child_process';
6
+ import { getSettingsService } from '../../settings-service.js';
7
+ import { getProviderDetectionService } from '../../lib/provider-detection.js';
8
+ import { logger } from '../../lib/logger.js';
9
+ export class CodexCliProvider {
10
+ constructor(config = {}) {
11
+ this.config = config;
12
+ this.name = 'codex';
13
+ this.displayName = 'Codex CLI';
14
+ }
15
+ async resolveExecutable() {
16
+ if (this.config.codexBinPath)
17
+ return this.config.codexBinPath;
18
+ // Use enhanced detection service
19
+ const detectionService = getProviderDetectionService();
20
+ const result = await detectionService.detectProvider('codex');
21
+ if (result.found && result.path) {
22
+ return result.path;
23
+ }
24
+ // Fallback: try old settings-based approach for backwards compatibility
25
+ const settingsBinPath = (() => {
26
+ try {
27
+ const svc = getSettingsService();
28
+ const s = svc.getSettings();
29
+ return s?.agents?.providers?.codex?.binPath;
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ })();
35
+ if (settingsBinPath?.trim())
36
+ return settingsBinPath.trim();
37
+ // Default to binary name (resolve via PATH)
38
+ return 'codex';
39
+ }
40
+ async *execute(prompt, options) {
41
+ // Effective options
42
+ const cwd = options?.workingDirectory || this.config.defaultWorkingDirectory || process.cwd();
43
+ const mapModel = (m) => {
44
+ if (!m)
45
+ return m;
46
+ // Normalize reasoning-effort variants to the canonical model id
47
+ // Users reported only `gpt-5` is selectable; variants are effort levels in the TUI.
48
+ const lower = m.toLowerCase();
49
+ if (lower === 'gpt-5-minimal' ||
50
+ lower === 'gpt-5-low' ||
51
+ lower === 'gpt-5-medium' ||
52
+ lower === 'gpt-5-high') {
53
+ return 'gpt-5';
54
+ }
55
+ return m;
56
+ };
57
+ const model = mapModel(options?.model || this.config.defaultModel);
58
+ const images = (options?.images || []).filter(Boolean);
59
+ const effort = options?.effort;
60
+ const timeoutMs = options?.timeout ?? this.config.defaultTimeoutMs ?? 10 * 60 * 1000; // 10m
61
+ const systemPrompt = options?.systemPrompt?.trim();
62
+ const appendSystemPrompt = options?.appendSystemPrompt?.trim();
63
+ const promptSegments = [];
64
+ if (systemPrompt) {
65
+ promptSegments.push(systemPrompt);
66
+ }
67
+ if (appendSystemPrompt) {
68
+ promptSegments.push(appendSystemPrompt);
69
+ }
70
+ promptSegments.push(prompt);
71
+ const effectivePrompt = promptSegments.join('\n\n');
72
+ // Build argv for `codex exec` (non-interactive automation mode)
73
+ const argv = ['exec', effectivePrompt];
74
+ if (model) {
75
+ argv.push('--model', model);
76
+ }
77
+ // Prefer spawning with cwd, but also set --cd to make Codex aware of root
78
+ if (cwd) {
79
+ argv.push('--cd', cwd);
80
+ }
81
+ if (images.length) {
82
+ argv.push('--image', images.join(','));
83
+ }
84
+ if (options?.dangerouslyBypassApprovalsAndSandbox) {
85
+ argv.push('--dangerously-bypass-approvals-and-sandbox');
86
+ }
87
+ const cmd = await this.resolveExecutable();
88
+ const child = spawn(cmd, argv, {
89
+ cwd,
90
+ env: { ...process.env },
91
+ stdio: ['ignore', 'pipe', 'pipe'],
92
+ });
93
+ // Emit an init/system message with effective command
94
+ const init = {
95
+ type: 'init',
96
+ timestamp: new Date().toISOString(),
97
+ sessionId: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
98
+ model: model || 'default',
99
+ provider: this.name,
100
+ };
101
+ yield init;
102
+ yield {
103
+ type: 'system',
104
+ timestamp: new Date().toISOString(),
105
+ content: `Running: ${cmd} ${argv
106
+ .map((a) => (a.includes(' ') ? '"' + a + '"' : a))
107
+ .join(' ')} (cwd=${cwd})`,
108
+ metadata: {
109
+ provider: this.name,
110
+ images,
111
+ effort,
112
+ systemPrompt,
113
+ appendSystemPrompt,
114
+ dangerouslyBypassApprovalsAndSandbox: !!options?.dangerouslyBypassApprovalsAndSandbox,
115
+ },
116
+ };
117
+ let stdoutBuf = '';
118
+ // let stderrBuf = '';
119
+ let finished = false;
120
+ let lastFlushedIndex = 0;
121
+ let lineCarry = '';
122
+ // Helper to push incremental stdout as assistant log lines
123
+ const flushNewOutput = () => {
124
+ const newChunk = stdoutBuf.slice(lastFlushedIndex);
125
+ if (!newChunk)
126
+ return;
127
+ lastFlushedIndex = stdoutBuf.length;
128
+ // Accumulate and split by line breaks, keep trailing partial
129
+ lineCarry += newChunk;
130
+ const parts = lineCarry.split(/\r?\n/);
131
+ lineCarry = parts.pop() || '';
132
+ return parts.map((l) => l.trimEnd()).filter(Boolean);
133
+ };
134
+ // Provider stays generic: it streams lines and returns raw stdout.
135
+ // Forward parent termination via abortSignal
136
+ // const abortController = new AbortController();
137
+ const onAbort = () => {
138
+ try {
139
+ child.kill('SIGTERM');
140
+ }
141
+ catch {
142
+ /* ignore */
143
+ }
144
+ // Fallback kill after short grace
145
+ setTimeout(() => {
146
+ if (!finished) {
147
+ try {
148
+ child.kill('SIGKILL');
149
+ }
150
+ catch {
151
+ /* ignore */
152
+ }
153
+ }
154
+ }, 3000);
155
+ };
156
+ if (options?.abortSignal) {
157
+ if (options.abortSignal.aborted)
158
+ onAbort();
159
+ else
160
+ options.abortSignal.addEventListener('abort', onAbort, { once: true });
161
+ }
162
+ // Local timeout guard
163
+ const guard = setTimeout(() => {
164
+ onAbort();
165
+ }, timeoutMs);
166
+ // Capture data into buffers
167
+ child.stdout?.on('data', (data) => {
168
+ stdoutBuf += data.toString('utf8');
169
+ });
170
+ // child.stderr?.on('data', (data: Buffer) => {
171
+ // stderrBuf += data.toString('utf8');
172
+ // });
173
+ // Wait for process to finish
174
+ // Stream logs while the process runs by polling for new output
175
+ const exitPromise = new Promise((resolve) => {
176
+ child.on('exit', (code, signal) => resolve({ code, signal }));
177
+ });
178
+ // Poll for output until the process exits
179
+ let exitStatus;
180
+ while (!finished) {
181
+ const tick = new Promise((r) => setTimeout(r, 150));
182
+ const exit = await Promise.race([exitPromise, tick]);
183
+ if (exit && typeof exit.code !== 'undefined') {
184
+ // Process exited; flush any remaining output before breaking
185
+ const lines = flushNewOutput();
186
+ if (lines && lines.length) {
187
+ for (const text of lines) {
188
+ yield {
189
+ type: 'assistant',
190
+ timestamp: new Date().toISOString(),
191
+ content: text,
192
+ };
193
+ }
194
+ }
195
+ finished = true;
196
+ // Record exit info for finalization
197
+ exitStatus = exit;
198
+ break;
199
+ }
200
+ // Flush incremental lines during run
201
+ const lines = flushNewOutput();
202
+ if (lines && lines.length) {
203
+ for (const text of lines) {
204
+ yield {
205
+ type: 'assistant',
206
+ timestamp: new Date().toISOString(),
207
+ content: text,
208
+ };
209
+ }
210
+ }
211
+ }
212
+ // If loop ended without capturing exit status (unlikely), await it now
213
+ const exit = exitStatus ?? (await exitPromise);
214
+ finished = true;
215
+ clearTimeout(guard);
216
+ // Flush any final carry line as a log
217
+ if (lineCarry.trim()) {
218
+ yield {
219
+ type: 'assistant',
220
+ timestamp: new Date().toISOString(),
221
+ content: lineCarry.trimEnd(),
222
+ };
223
+ lineCarry = '';
224
+ }
225
+ // Compose final message
226
+ const success = (exit.code ?? 1) === 0 && !exit.signal;
227
+ const remainingStdout = stdoutBuf.trim();
228
+ const resultMsg = {
229
+ type: 'result',
230
+ timestamp: new Date().toISOString(),
231
+ success,
232
+ // Return raw stdout as result; higher layers decide how to parse it
233
+ result: success ? (remainingStdout || '').toString() : undefined,
234
+ error: success
235
+ ? undefined
236
+ : `codex exited ${exit.signal ? 'by ' + exit.signal : 'with code ' + exit.code}`,
237
+ usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
238
+ };
239
+ yield resultMsg;
240
+ }
241
+ async executeSync(prompt, options) {
242
+ // Convenience: collect from execute()
243
+ let content = '';
244
+ const start = Date.now();
245
+ for await (const msg of this.execute(prompt, options)) {
246
+ if (msg.type === 'assistant' && typeof msg.content === 'string') {
247
+ content += (content ? '\n' : '') + msg.content;
248
+ }
249
+ }
250
+ return {
251
+ id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
252
+ provider: this.name,
253
+ model: options?.model || this.config.defaultModel || 'default',
254
+ content,
255
+ usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
256
+ duration: Date.now() - start,
257
+ };
258
+ }
259
+ async detectAvailableModels() {
260
+ // Current public CLI exposes `--model gpt-5`; effort levels are chosen in-CLI.
261
+ return [
262
+ {
263
+ id: 'gpt-5',
264
+ name: 'gpt-5',
265
+ displayName: 'gpt‑5',
266
+ provider: this.name,
267
+ contextWindow: 256000,
268
+ maxOutputTokens: 16384,
269
+ // Capabilities per Codex docs: supports images via --image and advanced reasoning
270
+ capabilities: ['code', 'analysis', 'tools', 'vision', 'image', 'reasoning'],
271
+ },
272
+ ];
273
+ }
274
+ async validateSetup() {
275
+ try {
276
+ const detectionService = getProviderDetectionService();
277
+ const result = await detectionService.detectProvider('codex');
278
+ if (!result.found) {
279
+ return {
280
+ available: false,
281
+ error: result.error ||
282
+ 'Codex CLI not found. Install from https://github.com/openai/codex (see Getting Started: CLI usage).',
283
+ models: [],
284
+ capabilities: this.getCapabilities(),
285
+ };
286
+ }
287
+ return {
288
+ available: true,
289
+ models: await this.detectAvailableModels(),
290
+ capabilities: this.getCapabilities(),
291
+ };
292
+ }
293
+ catch (error) {
294
+ logger.error(error);
295
+ return {
296
+ available: false,
297
+ error: error instanceof Error ? error.message : String(error),
298
+ models: [],
299
+ capabilities: this.getCapabilities(),
300
+ };
301
+ }
302
+ }
303
+ // Note: persistence of detected binary paths is handled by onboarding workflow.
304
+ getCapabilities() {
305
+ return {
306
+ streaming: true,
307
+ tools: true,
308
+ functionCalling: false,
309
+ vision: true,
310
+ codeExecution: true,
311
+ maxContextWindow: 128000,
312
+ maxOutputTokens: 8192,
313
+ };
314
+ }
315
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * AI Providers Module
3
+ * Export all provider types and implementations
4
+ */
5
+ export * from './types.js';
6
+ export { ClaudeCodeAdapter } from './claude-code-adapter.js';
7
+ export type { ClaudeCodeConfig } from './claude-code-adapter.js';
8
+ export { CodexCliProvider } from './codex-cli-provider.js';
9
+ export type { CodexCliConfig } from './codex-cli-provider.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * AI Providers Module
3
+ * Export all provider types and implementations
4
+ */
5
+ export * from './types.js';
6
+ export { ClaudeCodeAdapter } from './claude-code-adapter.js';
7
+ export { CodexCliProvider } from './codex-cli-provider.js';
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Core AI Provider Abstraction
3
+ * Defines the contract for AI execution providers (Claude, OpenAI, Local LLMs, etc.)
4
+ */
5
+ /**
6
+ * Model information for available AI models
7
+ */
8
+ export interface ModelInfo {
9
+ id: string;
10
+ name: string;
11
+ displayName: string;
12
+ provider: string;
13
+ contextWindow?: number;
14
+ maxOutputTokens?: number;
15
+ costPerInputToken?: number;
16
+ costPerOutputToken?: number;
17
+ capabilities?: string[];
18
+ }
19
+ /**
20
+ * Tool permissions for AI execution
21
+ * Source: https://docs.anthropic.com/en/docs/claude-code/settings#tools-available-to-claude
22
+ */
23
+ export type ToolPermission = 'Bash' | 'Edit' | 'Glob' | 'Grep' | 'MultiEdit' | 'NotebookEdit' | 'NotebookRead' | 'Read' | 'Task' | 'TodoWrite' | 'WebSearch' | 'WebFetch' | 'Write';
24
+ /**
25
+ * Execution options for AI providers
26
+ */
27
+ export interface ExecutionOptions {
28
+ workingDirectory?: string;
29
+ model?: string;
30
+ temperature?: number;
31
+ maxTokens?: number;
32
+ tools?: ToolPermission[];
33
+ timeout?: number;
34
+ abortSignal?: AbortSignal;
35
+ systemPrompt?: string;
36
+ appendSystemPrompt?: string;
37
+ /**
38
+ * Permission mode for Claude Code SDK (provider-specific hint).
39
+ * - default: standard prompts/permissions
40
+ * - acceptEdits: auto-approve file edits and common FS ops
41
+ * - bypassPermissions: auto-approve all tool uses (dangerous; headless automation)
42
+ */
43
+ permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions';
44
+ /** Optional list of image file paths to attach (Codex CLI: --image) */
45
+ images?: string[];
46
+ /** Optional effort hint for reasoning presets (e.g., 'minimal'|'low'|'medium'|'high'); informational only */
47
+ effort?: string;
48
+ /** Enable Codex CLI sandbox bypass flag when running automation that must edit files */
49
+ dangerouslyBypassApprovalsAndSandbox?: boolean;
50
+ }
51
+ /**
52
+ * Message types for streaming execution
53
+ */
54
+ export interface ExecutionMessage {
55
+ type: 'init' | 'assistant' | 'tool_use' | 'result' | 'error' | 'system';
56
+ timestamp: string;
57
+ content?: string | any;
58
+ metadata?: Record<string, any>;
59
+ }
60
+ /**
61
+ * Initialization message
62
+ */
63
+ export interface InitMessage extends ExecutionMessage {
64
+ type: 'init';
65
+ sessionId: string;
66
+ model: string;
67
+ provider: string;
68
+ }
69
+ /**
70
+ * Assistant message (AI response)
71
+ */
72
+ export interface AssistantMessage extends ExecutionMessage {
73
+ type: 'assistant';
74
+ content: string;
75
+ toolCalls?: ToolCall[];
76
+ }
77
+ /**
78
+ * Tool call information
79
+ */
80
+ export interface ToolCall {
81
+ id: string;
82
+ name: string;
83
+ input?: any;
84
+ output?: any;
85
+ }
86
+ /**
87
+ * Tool use message
88
+ */
89
+ export interface ToolUseMessage extends ExecutionMessage {
90
+ type: 'tool_use';
91
+ tool: string;
92
+ input: any;
93
+ output?: any;
94
+ }
95
+ /**
96
+ * Result message (final output)
97
+ */
98
+ export interface ResultMessage extends ExecutionMessage {
99
+ type: 'result';
100
+ success: boolean;
101
+ result?: string;
102
+ error?: string;
103
+ usage?: {
104
+ promptTokens: number;
105
+ completionTokens: number;
106
+ totalTokens: number;
107
+ cost?: number;
108
+ };
109
+ duration?: number;
110
+ }
111
+ /**
112
+ * Execution result for synchronous execution
113
+ */
114
+ export interface ExecutionResult {
115
+ id: string;
116
+ provider: string;
117
+ model: string;
118
+ content: string;
119
+ usage: {
120
+ promptTokens: number;
121
+ completionTokens: number;
122
+ totalTokens: number;
123
+ cost?: number;
124
+ };
125
+ duration: number;
126
+ error?: string;
127
+ }
128
+ /**
129
+ * Provider capabilities
130
+ */
131
+ export interface ProviderCapabilities {
132
+ streaming: boolean;
133
+ tools: boolean;
134
+ functionCalling: boolean;
135
+ vision: boolean;
136
+ codeExecution: boolean;
137
+ maxContextWindow: number;
138
+ maxOutputTokens: number;
139
+ }
140
+ /**
141
+ * Provider status
142
+ */
143
+ export interface ProviderStatus {
144
+ available: boolean;
145
+ error?: string;
146
+ models: ModelInfo[];
147
+ capabilities: ProviderCapabilities;
148
+ }
149
+ /**
150
+ * Core AI Provider interface
151
+ * All AI providers must implement this interface
152
+ */
153
+ export interface AIProvider {
154
+ /**
155
+ * Provider identifier
156
+ */
157
+ readonly name: string;
158
+ /**
159
+ * Provider display name
160
+ */
161
+ readonly displayName: string;
162
+ /**
163
+ * Execute a prompt and return streaming messages
164
+ */
165
+ execute(prompt: string, options?: ExecutionOptions): AsyncIterableIterator<ExecutionMessage>;
166
+ /**
167
+ * Execute a prompt and return the final result (convenience method)
168
+ */
169
+ executeSync?(prompt: string, options?: ExecutionOptions): Promise<ExecutionResult>;
170
+ /**
171
+ * Detect available models for this provider
172
+ */
173
+ detectAvailableModels(): Promise<ModelInfo[]>;
174
+ /**
175
+ * Validate provider setup and configuration
176
+ */
177
+ validateSetup(): Promise<ProviderStatus>;
178
+ /**
179
+ * Get provider capabilities
180
+ */
181
+ getCapabilities(): ProviderCapabilities;
182
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Core AI Provider Abstraction
3
+ * Defines the contract for AI execution providers (Claude, OpenAI, Local LLMs, etc.)
4
+ */
5
+ export {};
@@ -0,0 +1,125 @@
1
+ import { describe, it, expect, vi, afterEach } from 'vitest';
2
+ // Toggle real CLI integration via env
3
+ const USE_REAL = process.env.VITEST_USE_REAL_CODEX === 'true';
4
+ // Note: we dynamically import the provider after (un)mocking per test block
5
+ describe('CodexCliProvider (mocked)', () => {
6
+ afterEach(() => {
7
+ vi.resetAllMocks();
8
+ });
9
+ it('streams stdout, passes images flag, and returns result', async () => {
10
+ vi.resetModules();
11
+ vi.doMock('child_process', () => {
12
+ let captured = [];
13
+ return {
14
+ __captured: () => captured,
15
+ spawn: (cmd, args, opts) => {
16
+ captured = [cmd, args, opts];
17
+ const { EventEmitter } = require('events');
18
+ const stdout = new EventEmitter();
19
+ const stderr = new EventEmitter();
20
+ const proc = new EventEmitter();
21
+ proc.stdout = stdout;
22
+ proc.stderr = stderr;
23
+ setTimeout(() => stdout.emit('data', Buffer.from('Hello from Codex\n')), 10);
24
+ setTimeout(() => proc.emit('exit', 0, null), 20);
25
+ return proc;
26
+ },
27
+ };
28
+ });
29
+ const { CodexCliProvider } = await import('./ai-providers/codex-cli-provider.js');
30
+ const provider = new CodexCliProvider({ defaultTimeoutMs: 1000 });
31
+ const messages = [];
32
+ const iter = provider.execute('What is this project about?', {
33
+ workingDirectory: process.cwd(),
34
+ images: ['a.png', 'b.jpg'],
35
+ effort: 'minimal',
36
+ model: 'gpt-5',
37
+ });
38
+ for await (const m of iter)
39
+ messages.push(m);
40
+ const resultMsg = messages.find((m) => m.type === 'result');
41
+ expect(!!resultMsg).toBe(true);
42
+ const assistantMsg = messages.find((m) => m.type === 'assistant');
43
+ if (assistantMsg && typeof assistantMsg.content === 'string') {
44
+ expect(assistantMsg.content.length).toBeGreaterThan(0);
45
+ }
46
+ else if (resultMsg && typeof resultMsg.result === 'string') {
47
+ expect(resultMsg.result.length).toBeGreaterThan(0);
48
+ }
49
+ const mockSpawn = await import('child_process');
50
+ const captured = mockSpawn.__captured();
51
+ expect(Array.isArray(captured[1])).toBe(true);
52
+ expect(captured[1]).toContain('--image');
53
+ expect(captured[1]).toContain('a.png,b.jpg');
54
+ const modelIdx = captured[1].indexOf('--model');
55
+ expect(modelIdx).toBeGreaterThan(-1);
56
+ expect(captured[1][modelIdx + 1]).toBe('gpt-5');
57
+ });
58
+ it('prepends system prompts and toggles sandbox bypass flag', async () => {
59
+ vi.resetModules();
60
+ vi.doMock('child_process', () => {
61
+ let captured = [];
62
+ return {
63
+ __captured: () => captured,
64
+ spawn: (cmd, args, opts) => {
65
+ captured = [cmd, args, opts];
66
+ const { EventEmitter } = require('events');
67
+ const stdout = new EventEmitter();
68
+ const proc = new EventEmitter();
69
+ proc.stdout = stdout;
70
+ setTimeout(() => stdout.emit('data', Buffer.from('Done\n')), 5);
71
+ setTimeout(() => proc.emit('exit', 0, null), 10);
72
+ return proc;
73
+ },
74
+ };
75
+ });
76
+ const { CodexCliProvider } = await import('./ai-providers/codex-cli-provider.js');
77
+ const provider = new CodexCliProvider();
78
+ const iter = provider.execute('Implement feature', {
79
+ workingDirectory: '/tmp/project',
80
+ systemPrompt: 'Base system prompt',
81
+ appendSystemPrompt: 'Additional guidance',
82
+ dangerouslyBypassApprovalsAndSandbox: true,
83
+ });
84
+ for await (const _ of iter) {
85
+ // drain iterator
86
+ }
87
+ const mockSpawn = await import('child_process');
88
+ const captured = mockSpawn.__captured();
89
+ expect(captured[1][1]).toContain('Base system prompt');
90
+ expect(captured[1][1]).toContain('Additional guidance');
91
+ const bypassIdx = captured[1].indexOf('--dangerously-bypass-approvals-and-sandbox');
92
+ expect(bypassIdx).toBeGreaterThan(-1);
93
+ expect(captured[1][bypassIdx + 1]).toBeUndefined();
94
+ });
95
+ });
96
+ // Real integration (opt-in)
97
+ (USE_REAL ? describe : describe.skip)('CodexCliProvider (real CLI)', () => {
98
+ it('answers a simple model question and prints output', { timeout: 120000 }, async () => {
99
+ vi.resetModules();
100
+ vi.doUnmock('child_process');
101
+ const { CodexCliProvider } = await import('./ai-providers/codex-cli-provider.js');
102
+ const provider = new CodexCliProvider({
103
+ defaultWorkingDirectory: process.cwd(),
104
+ defaultTimeoutMs: 120000,
105
+ });
106
+ const prompt = 'Just answer 1 + 1 = ? for testing.';
107
+ let assistant = '';
108
+ let sawResult = false;
109
+ for await (const m of provider.execute(prompt, {
110
+ workingDirectory: process.cwd(),
111
+ timeout: 120000,
112
+ })) {
113
+ console.log('[CODEX]', m.type, typeof m.content === 'string' ? m.content : '');
114
+ if (m.type === 'assistant' && typeof m.content === 'string') {
115
+ if (!assistant)
116
+ assistant = m.content.trim();
117
+ }
118
+ if (m.type === 'result') {
119
+ sawResult = true;
120
+ }
121
+ }
122
+ expect(sawResult).toBe(true);
123
+ expect(assistant.length).toBeGreaterThan(0);
124
+ });
125
+ });