vibeman 0.0.0 → 0.0.1

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 (220) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +116 -0
  3. package/dist/runtime/api/.tsbuildinfo +1 -0
  4. package/dist/runtime/api/agent/agent-service.d.ts +226 -0
  5. package/dist/runtime/api/agent/agent-service.js +901 -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 +373 -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 +281 -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 +180 -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 +88 -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 +15 -0
  19. package/dist/runtime/api/agent/parsers.js +241 -0
  20. package/dist/runtime/api/agent/prompt-service.d.ts +17 -0
  21. package/dist/runtime/api/agent/prompt-service.js +340 -0
  22. package/dist/runtime/api/agent/routing-policy.d.ts +188 -0
  23. package/dist/runtime/api/agent/routing-policy.js +246 -0
  24. package/dist/runtime/api/api/router-helpers.d.ts +32 -0
  25. package/dist/runtime/api/api/router-helpers.js +31 -0
  26. package/dist/runtime/api/api/routers/ai.d.ts +188 -0
  27. package/dist/runtime/api/api/routers/ai.js +410 -0
  28. package/dist/runtime/api/api/routers/executions.d.ts +98 -0
  29. package/dist/runtime/api/api/routers/executions.js +103 -0
  30. package/dist/runtime/api/api/routers/git.d.ts +45 -0
  31. package/dist/runtime/api/api/routers/git.js +35 -0
  32. package/dist/runtime/api/api/routers/settings.d.ts +139 -0
  33. package/dist/runtime/api/api/routers/settings.js +113 -0
  34. package/dist/runtime/api/api/routers/tasks.d.ts +141 -0
  35. package/dist/runtime/api/api/routers/tasks.js +238 -0
  36. package/dist/runtime/api/api/routers/workflows.d.ts +268 -0
  37. package/dist/runtime/api/api/routers/workflows.js +308 -0
  38. package/dist/runtime/api/api/routers/worktrees.d.ts +102 -0
  39. package/dist/runtime/api/api/routers/worktrees.js +80 -0
  40. package/dist/runtime/api/api/trpc.d.ts +118 -0
  41. package/dist/runtime/api/api/trpc.js +34 -0
  42. package/dist/runtime/api/index.d.ts +9 -0
  43. package/dist/runtime/api/index.js +125 -0
  44. package/dist/runtime/api/lib/id-generator.d.ts +70 -0
  45. package/dist/runtime/api/lib/id-generator.js +123 -0
  46. package/dist/runtime/api/lib/image-paste-drop-extension.d.ts +26 -0
  47. package/dist/runtime/api/lib/image-paste-drop-extension.js +125 -0
  48. package/dist/runtime/api/lib/logger.d.ts +11 -0
  49. package/dist/runtime/api/lib/logger.js +188 -0
  50. package/dist/runtime/api/lib/markdown-utils.d.ts +8 -0
  51. package/dist/runtime/api/lib/markdown-utils.js +282 -0
  52. package/dist/runtime/api/lib/markdown-utils.test.d.ts +1 -0
  53. package/dist/runtime/api/lib/markdown-utils.test.js +348 -0
  54. package/dist/runtime/api/lib/server/agent-service-singleton.d.ts +6 -0
  55. package/dist/runtime/api/lib/server/agent-service-singleton.js +27 -0
  56. package/dist/runtime/api/lib/server/git-service-singleton.d.ts +6 -0
  57. package/dist/runtime/api/lib/server/git-service-singleton.js +47 -0
  58. package/dist/runtime/api/lib/server/project-root.d.ts +2 -0
  59. package/dist/runtime/api/lib/server/project-root.js +38 -0
  60. package/dist/runtime/api/lib/server/task-service-singleton.d.ts +7 -0
  61. package/dist/runtime/api/lib/server/task-service-singleton.js +58 -0
  62. package/dist/runtime/api/lib/server/vibing-orchestrator-singleton.d.ts +7 -0
  63. package/dist/runtime/api/lib/server/vibing-orchestrator-singleton.js +57 -0
  64. package/dist/runtime/api/lib/tiptap-utils.clamp-selection.test.d.ts +1 -0
  65. package/dist/runtime/api/lib/tiptap-utils.clamp-selection.test.js +27 -0
  66. package/dist/runtime/api/lib/tiptap-utils.d.ts +130 -0
  67. package/dist/runtime/api/lib/tiptap-utils.js +327 -0
  68. package/dist/runtime/api/lib/trpc/client.d.ts +1 -0
  69. package/dist/runtime/api/lib/trpc/client.js +5 -0
  70. package/dist/runtime/api/lib/trpc/server.d.ts +822 -0
  71. package/dist/runtime/api/lib/trpc/server.js +11 -0
  72. package/dist/runtime/api/lib/trpc/ws-server.d.ts +8 -0
  73. package/dist/runtime/api/lib/trpc/ws-server.js +33 -0
  74. package/dist/runtime/api/persistence/database-service.d.ts +14 -0
  75. package/dist/runtime/api/persistence/database-service.js +74 -0
  76. package/dist/runtime/api/persistence/execution-log-persistence.d.ts +90 -0
  77. package/dist/runtime/api/persistence/execution-log-persistence.js +410 -0
  78. package/dist/runtime/api/persistence/execution-log-persistence.test.d.ts +1 -0
  79. package/dist/runtime/api/persistence/execution-log-persistence.test.js +170 -0
  80. package/dist/runtime/api/router.d.ts +825 -0
  81. package/dist/runtime/api/router.js +56 -0
  82. package/dist/runtime/api/settings-service.d.ts +110 -0
  83. package/dist/runtime/api/settings-service.js +611 -0
  84. package/dist/runtime/api/tasks/file-watcher.d.ts +23 -0
  85. package/dist/runtime/api/tasks/file-watcher.js +88 -0
  86. package/dist/runtime/api/tasks/task-file-parser.d.ts +13 -0
  87. package/dist/runtime/api/tasks/task-file-parser.js +161 -0
  88. package/dist/runtime/api/tasks/task-service.d.ts +36 -0
  89. package/dist/runtime/api/tasks/task-service.js +173 -0
  90. package/dist/runtime/api/types/index.d.ts +179 -0
  91. package/dist/runtime/api/types/index.js +1 -0
  92. package/dist/runtime/api/types/settings.d.ts +81 -0
  93. package/dist/runtime/api/types/settings.js +2 -0
  94. package/dist/runtime/api/types.d.ts +2 -0
  95. package/dist/runtime/api/types.js +1 -0
  96. package/dist/runtime/api/utils/env.d.ts +6 -0
  97. package/dist/runtime/api/utils/env.js +12 -0
  98. package/dist/runtime/api/utils/stripNextEnv.d.ts +7 -0
  99. package/dist/runtime/api/utils/stripNextEnv.js +22 -0
  100. package/dist/runtime/api/utils/title-slug.d.ts +6 -0
  101. package/dist/runtime/api/utils/title-slug.js +77 -0
  102. package/dist/runtime/api/utils/url.d.ts +2 -0
  103. package/dist/runtime/api/utils/url.js +19 -0
  104. package/dist/runtime/api/vcs/git-history-service.d.ts +57 -0
  105. package/dist/runtime/api/vcs/git-history-service.js +228 -0
  106. package/dist/runtime/api/vcs/git-service.d.ts +127 -0
  107. package/dist/runtime/api/vcs/git-service.js +284 -0
  108. package/dist/runtime/api/vcs/worktree-service.d.ts +93 -0
  109. package/dist/runtime/api/vcs/worktree-service.js +506 -0
  110. package/dist/runtime/api/vcs/worktree-service.test.d.ts +1 -0
  111. package/dist/runtime/api/vcs/worktree-service.test.js +20 -0
  112. package/dist/runtime/api/workflows/quality-pipeline.d.ts +58 -0
  113. package/dist/runtime/api/workflows/quality-pipeline.js +400 -0
  114. package/dist/runtime/api/workflows/vibing-orchestrator.d.ts +313 -0
  115. package/dist/runtime/api/workflows/vibing-orchestrator.js +1861 -0
  116. package/dist/runtime/web/.next/BUILD_ID +1 -0
  117. package/dist/runtime/web/.next/app-build-manifest.json +59 -0
  118. package/dist/runtime/web/.next/app-path-routes-manifest.json +7 -0
  119. package/dist/runtime/web/.next/build-manifest.json +33 -0
  120. package/dist/runtime/web/.next/package.json +1 -0
  121. package/dist/runtime/web/.next/prerender-manifest.json +61 -0
  122. package/dist/runtime/web/.next/react-loadable-manifest.json +39 -0
  123. package/dist/runtime/web/.next/required-server-files.json +334 -0
  124. package/dist/runtime/web/.next/routes-manifest.json +62 -0
  125. package/dist/runtime/web/.next/server/app/_not-found/page.js +2 -0
  126. package/dist/runtime/web/.next/server/app/_not-found/page.js.nft.json +1 -0
  127. package/dist/runtime/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
  128. package/dist/runtime/web/.next/server/app/_not-found.html +7 -0
  129. package/dist/runtime/web/.next/server/app/_not-found.meta +8 -0
  130. package/dist/runtime/web/.next/server/app/_not-found.rsc +22 -0
  131. package/dist/runtime/web/.next/server/app/api/health/route.js +1 -0
  132. package/dist/runtime/web/.next/server/app/api/health/route.js.nft.json +1 -0
  133. package/dist/runtime/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -0
  134. package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js +1 -0
  135. package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js.nft.json +1 -0
  136. package/dist/runtime/web/.next/server/app/api/images/[...path]/route_client-reference-manifest.js +1 -0
  137. package/dist/runtime/web/.next/server/app/api/upload/route.js +1 -0
  138. package/dist/runtime/web/.next/server/app/api/upload/route.js.nft.json +1 -0
  139. package/dist/runtime/web/.next/server/app/api/upload/route_client-reference-manifest.js +1 -0
  140. package/dist/runtime/web/.next/server/app/index.html +7 -0
  141. package/dist/runtime/web/.next/server/app/index.meta +7 -0
  142. package/dist/runtime/web/.next/server/app/index.rsc +27 -0
  143. package/dist/runtime/web/.next/server/app/page.js +147 -0
  144. package/dist/runtime/web/.next/server/app/page.js.nft.json +1 -0
  145. package/dist/runtime/web/.next/server/app/page_client-reference-manifest.js +1 -0
  146. package/dist/runtime/web/.next/server/app-paths-manifest.json +7 -0
  147. package/dist/runtime/web/.next/server/chunks/217.js +1 -0
  148. package/dist/runtime/web/.next/server/chunks/383.js +6 -0
  149. package/dist/runtime/web/.next/server/chunks/458.js +1 -0
  150. package/dist/runtime/web/.next/server/chunks/576.js +18 -0
  151. package/dist/runtime/web/.next/server/chunks/635.js +22 -0
  152. package/dist/runtime/web/.next/server/chunks/761.js +1 -0
  153. package/dist/runtime/web/.next/server/chunks/777.js +3 -0
  154. package/dist/runtime/web/.next/server/chunks/825.js +1 -0
  155. package/dist/runtime/web/.next/server/chunks/838.js +1 -0
  156. package/dist/runtime/web/.next/server/chunks/973.js +15 -0
  157. package/dist/runtime/web/.next/server/functions-config-manifest.json +4 -0
  158. package/dist/runtime/web/.next/server/middleware-build-manifest.js +1 -0
  159. package/dist/runtime/web/.next/server/middleware-manifest.json +6 -0
  160. package/dist/runtime/web/.next/server/middleware-react-loadable-manifest.js +1 -0
  161. package/dist/runtime/web/.next/server/next-font-manifest.js +1 -0
  162. package/dist/runtime/web/.next/server/next-font-manifest.json +1 -0
  163. package/dist/runtime/web/.next/server/pages/404.html +7 -0
  164. package/dist/runtime/web/.next/server/pages/500.html +1 -0
  165. package/dist/runtime/web/.next/server/pages/_app.js +1 -0
  166. package/dist/runtime/web/.next/server/pages/_app.js.nft.json +1 -0
  167. package/dist/runtime/web/.next/server/pages/_document.js +1 -0
  168. package/dist/runtime/web/.next/server/pages/_document.js.nft.json +1 -0
  169. package/dist/runtime/web/.next/server/pages/_error.js +19 -0
  170. package/dist/runtime/web/.next/server/pages/_error.js.nft.json +1 -0
  171. package/dist/runtime/web/.next/server/pages-manifest.json +6 -0
  172. package/dist/runtime/web/.next/server/server-reference-manifest.js +1 -0
  173. package/dist/runtime/web/.next/server/server-reference-manifest.json +1 -0
  174. package/dist/runtime/web/.next/server/webpack-runtime.js +1 -0
  175. package/dist/runtime/web/.next/static/1HR8N0rJkCvFRtbTPJMyH/_buildManifest.js +1 -0
  176. package/dist/runtime/web/.next/static/1HR8N0rJkCvFRtbTPJMyH/_ssgManifest.js +1 -0
  177. package/dist/runtime/web/.next/static/chunks/18-15c10d3288afef2e.js +1 -0
  178. package/dist/runtime/web/.next/static/chunks/1c0ca389.537bbe362e3ffbd9.js +3 -0
  179. package/dist/runtime/web/.next/static/chunks/22747d63-ad5da0c19f4cfe41.js +71 -0
  180. package/dist/runtime/web/.next/static/chunks/277-0142a939f08738c3.js +63 -0
  181. package/dist/runtime/web/.next/static/chunks/355.056c2645878a799a.js +1 -0
  182. package/dist/runtime/web/.next/static/chunks/420.a5ccf151c9e2b2f1.js +1 -0
  183. package/dist/runtime/web/.next/static/chunks/439.1be0c6242fd248d5.js +15 -0
  184. package/dist/runtime/web/.next/static/chunks/440.c52e7c0f797e22b2.js +1 -0
  185. package/dist/runtime/web/.next/static/chunks/575-e2478287c27da87b.js +1 -0
  186. package/dist/runtime/web/.next/static/chunks/691.920d88c115087314.js +1 -0
  187. package/dist/runtime/web/.next/static/chunks/765-e838910065b50c3d.js +1 -0
  188. package/dist/runtime/web/.next/static/chunks/87c73c54-09e1ba5c70e60a51.js +1 -0
  189. package/dist/runtime/web/.next/static/chunks/891cff7f.0f71fc028f87e683.js +1 -0
  190. package/dist/runtime/web/.next/static/chunks/8bb4d8db-3e2aa02b0a2384b9.js +1 -0
  191. package/dist/runtime/web/.next/static/chunks/9af238c7-271a911d4e99ab18.js +1 -0
  192. package/dist/runtime/web/.next/static/chunks/app/_not-found/page-1cb74d1cba27d0ab.js +1 -0
  193. package/dist/runtime/web/.next/static/chunks/app/api/health/route-105a61ae865ba536.js +1 -0
  194. package/dist/runtime/web/.next/static/chunks/app/api/images/[...path]/route-105a61ae865ba536.js +1 -0
  195. package/dist/runtime/web/.next/static/chunks/app/api/upload/route-105a61ae865ba536.js +1 -0
  196. package/dist/runtime/web/.next/static/chunks/app/layout-dc0cfd29075b2160.js +1 -0
  197. package/dist/runtime/web/.next/static/chunks/app/page-f34a8b196b18850b.js +1 -0
  198. package/dist/runtime/web/.next/static/chunks/cac567b0-5b77dd12911823cd.js +1 -0
  199. package/dist/runtime/web/.next/static/chunks/framework-2518f1345b5b2806.js +1 -0
  200. package/dist/runtime/web/.next/static/chunks/main-17665e5e39de9a8a.js +1 -0
  201. package/dist/runtime/web/.next/static/chunks/main-app-c0b0f5ba4f7f9d75.js +1 -0
  202. package/dist/runtime/web/.next/static/chunks/pages/_app-d6f6b3bbc3d81ee1.js +1 -0
  203. package/dist/runtime/web/.next/static/chunks/pages/_error-75a96cf1997cc3b9.js +1 -0
  204. package/dist/runtime/web/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  205. package/dist/runtime/web/.next/static/chunks/webpack-c8de37305b4635cf.js +1 -0
  206. package/dist/runtime/web/.next/static/css/08c950681f1a9a92.css +1 -0
  207. package/dist/runtime/web/.next/static/css/2728291c68f99cb1.css +3 -0
  208. package/dist/runtime/web/.next/static/css/521bd69cc298cd1a.css +1 -0
  209. package/dist/runtime/web/.next/static/css/537e22821e101b87.css +1 -0
  210. package/dist/runtime/web/.next/static/media/19cfc7226ec3afaa-s.woff2 +0 -0
  211. package/dist/runtime/web/.next/static/media/21350d82a1f187e9-s.woff2 +0 -0
  212. package/dist/runtime/web/.next/static/media/8e9860b6e62d6359-s.woff2 +0 -0
  213. package/dist/runtime/web/.next/static/media/ba9851c3c22cd980-s.woff2 +0 -0
  214. package/dist/runtime/web/.next/static/media/c5fe6dc8356a8c31-s.woff2 +0 -0
  215. package/dist/runtime/web/.next/static/media/df0a9ae256c0569c-s.woff2 +0 -0
  216. package/dist/runtime/web/.next/static/media/e4af272ccee01ff0-s.p.woff2 +0 -0
  217. package/dist/runtime/web/package.json +65 -0
  218. package/dist/runtime/web/server.js +44 -0
  219. package/dist/tsconfig.tsbuildinfo +1 -0
  220. package/package.json +80 -7
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Claude Code Adapter
3
+ * Implements AIProvider interface for Claude Code SDK
4
+ */
5
+ import { AIProvider, ExecutionOptions, ExecutionMessage, ExecutionResult, ModelInfo, ProviderStatus, ProviderCapabilities } from './types.js';
6
+ /**
7
+ * Configuration for Claude Code Adapter
8
+ */
9
+ export interface ClaudeCodeConfig {
10
+ /**
11
+ * Path to Claude CLI executable
12
+ * If not provided, will use default resolution
13
+ */
14
+ claudeBinPath?: string;
15
+ /**
16
+ * Default working directory
17
+ */
18
+ defaultWorkingDirectory?: string;
19
+ /**
20
+ * Default model to use
21
+ */
22
+ defaultModel?: string;
23
+ }
24
+ /**
25
+ * Claude Code Adapter
26
+ * Wraps the Claude Code SDK to implement the AIProvider interface
27
+ */
28
+ export declare class ClaudeCodeAdapter implements AIProvider {
29
+ readonly name = "claude-code";
30
+ readonly displayName = "Claude Code";
31
+ private config;
32
+ constructor(config?: ClaudeCodeConfig);
33
+ /**
34
+ * Execute a prompt using Claude Code SDK
35
+ */
36
+ execute(prompt: string, options?: ExecutionOptions): AsyncIterableIterator<ExecutionMessage>;
37
+ /**
38
+ * Execute synchronously and return the final result
39
+ */
40
+ executeSync(prompt: string, options?: ExecutionOptions): Promise<ExecutionResult>;
41
+ /**
42
+ * Detect available Claude models
43
+ */
44
+ detectAvailableModels(): Promise<ModelInfo[]>;
45
+ /**
46
+ * Validate Claude Code setup
47
+ */
48
+ validateSetup(): Promise<ProviderStatus>;
49
+ /**
50
+ * Get provider capabilities
51
+ */
52
+ getCapabilities(): ProviderCapabilities;
53
+ /**
54
+ * Map ExecutionOptions to Claude Code Options
55
+ */
56
+ private mapToClaudeOptions;
57
+ /**
58
+ * Resolve Claude CLI executable path
59
+ */
60
+ private getClaudeExecutablePath;
61
+ }
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Claude Code Adapter
3
+ * Implements AIProvider interface for Claude Code SDK
4
+ */
5
+ import { query } from '@anthropic-ai/claude-code';
6
+ import path from 'path';
7
+ import os from 'os';
8
+ import { generateId } from '../../lib/id-generator.js';
9
+ import { getSettingsService } from '../../settings-service.js';
10
+ /**
11
+ * Claude Code Adapter
12
+ * Wraps the Claude Code SDK to implement the AIProvider interface
13
+ */
14
+ export class ClaudeCodeAdapter {
15
+ constructor(config = {}) {
16
+ this.name = 'claude-code';
17
+ this.displayName = 'Claude Code';
18
+ this.config = config;
19
+ }
20
+ /**
21
+ * Execute a prompt using Claude Code SDK
22
+ */
23
+ async *execute(prompt, options) {
24
+ const claudeOptions = this.mapToClaudeOptions(options);
25
+ const co = claudeOptions;
26
+ const startTime = Date.now();
27
+ let sessionId;
28
+ // let totalCost = 0;
29
+ let promptTokens = 0;
30
+ let completionTokens = 0;
31
+ try {
32
+ // Emit a synthetic system message with the effective prompt we send to the provider
33
+ const sysParts = [];
34
+ if (co.systemPrompt) {
35
+ sysParts.push('--- System Prompt ---');
36
+ sysParts.push(String(co.systemPrompt));
37
+ sysParts.push('--- End System Prompt ---');
38
+ }
39
+ if (co.appendSystemPrompt) {
40
+ sysParts.push('--- Append System Prompt ---');
41
+ sysParts.push(String(co.appendSystemPrompt));
42
+ sysParts.push('--- End Append System Prompt ---');
43
+ }
44
+ sysParts.push('--- User Prompt ---');
45
+ sysParts.push(String(prompt));
46
+ sysParts.push('--- End User Prompt ---');
47
+ yield {
48
+ type: 'system',
49
+ timestamp: new Date().toISOString(),
50
+ content: `Effective prompt sent to ${this.displayName} (model: ${co.model || this.config.defaultModel || 'claude-sonnet-4-20250514'}):\n${sysParts.join('\n')}`,
51
+ metadata: {
52
+ provider: this.name,
53
+ model: co.model || this.config.defaultModel || 'claude-sonnet-4-20250514',
54
+ workingDirectory: co?.cwd || this.config.defaultWorkingDirectory || process.cwd(),
55
+ tools: co?.allowedTools,
56
+ },
57
+ };
58
+ for await (const message of query({ prompt, options: claudeOptions })) {
59
+ // Handle init message
60
+ if (message.type === 'system' && message.subtype === 'init') {
61
+ sessionId = message.session_id;
62
+ const initMsg = {
63
+ type: 'init',
64
+ timestamp: new Date().toISOString(),
65
+ sessionId,
66
+ model: claudeOptions.model ||
67
+ this.config.defaultModel ||
68
+ 'claude-sonnet-4-20250514',
69
+ provider: this.name,
70
+ };
71
+ yield initMsg;
72
+ }
73
+ // Handle assistant messages
74
+ else if (message.type === 'assistant') {
75
+ const content = message.message.content;
76
+ if (typeof content === 'string') {
77
+ const assistantMsg = {
78
+ type: 'assistant',
79
+ timestamp: new Date().toISOString(),
80
+ content,
81
+ metadata: { sessionId },
82
+ };
83
+ yield assistantMsg;
84
+ }
85
+ else if (Array.isArray(content)) {
86
+ for (const block of content) {
87
+ if (block.type === 'text') {
88
+ const assistantMsg = {
89
+ type: 'assistant',
90
+ timestamp: new Date().toISOString(),
91
+ content: block.text,
92
+ metadata: { sessionId },
93
+ };
94
+ yield assistantMsg;
95
+ }
96
+ else if (block.type === 'tool_use') {
97
+ const toolMsg = {
98
+ type: 'tool_use',
99
+ timestamp: new Date().toISOString(),
100
+ tool: block.name,
101
+ input: block.input,
102
+ metadata: { sessionId, toolId: block.id },
103
+ };
104
+ yield toolMsg;
105
+ }
106
+ }
107
+ }
108
+ }
109
+ // Handle result message
110
+ else if (message.type === 'result') {
111
+ const resultMsg = {
112
+ type: 'result',
113
+ timestamp: new Date().toISOString(),
114
+ success: message.subtype === 'success',
115
+ result: message.subtype === 'success' ? message.result : undefined,
116
+ error: message.subtype !== 'success' ? message.subtype : undefined,
117
+ usage: {
118
+ promptTokens: message.usage?.input_tokens || promptTokens,
119
+ completionTokens: message.usage?.output_tokens || completionTokens,
120
+ totalTokens: (message.usage?.input_tokens || 0) + (message.usage?.output_tokens || 0),
121
+ cost: message.total_cost_usd,
122
+ },
123
+ duration: Date.now() - startTime,
124
+ metadata: { sessionId },
125
+ };
126
+ yield resultMsg;
127
+ // Track metrics
128
+ // if (message.total_cost_usd) totalCost = message.total_cost_usd;
129
+ if (message.usage?.input_tokens)
130
+ promptTokens = message.usage.input_tokens;
131
+ if (message.usage?.output_tokens)
132
+ completionTokens = message.usage.output_tokens;
133
+ }
134
+ // Handle other message types (errors, etc.)
135
+ else {
136
+ // Check if this is an error message
137
+ const msgType = message.type;
138
+ if (msgType === 'error') {
139
+ const errorMsg = {
140
+ type: 'error',
141
+ timestamp: new Date().toISOString(),
142
+ content: message.message || 'Unknown error',
143
+ metadata: { sessionId, errorType: message.subtype },
144
+ };
145
+ yield errorMsg;
146
+ }
147
+ }
148
+ }
149
+ }
150
+ catch (error) {
151
+ // Yield error message
152
+ yield {
153
+ type: 'error',
154
+ timestamp: new Date().toISOString(),
155
+ content: error instanceof Error ? error.message : String(error),
156
+ metadata: { sessionId },
157
+ };
158
+ throw error;
159
+ }
160
+ }
161
+ /**
162
+ * Execute synchronously and return the final result
163
+ */
164
+ async executeSync(prompt, options) {
165
+ const executionId = generateId('claude');
166
+ const result = {
167
+ id: executionId,
168
+ provider: this.name,
169
+ model: options?.model || this.config.defaultModel || 'claude-sonnet-4-20250514',
170
+ content: '',
171
+ usage: {
172
+ promptTokens: 0,
173
+ completionTokens: 0,
174
+ totalTokens: 0,
175
+ cost: 0,
176
+ },
177
+ duration: 0,
178
+ };
179
+ const startTime = Date.now();
180
+ const messages = [];
181
+ try {
182
+ for await (const message of this.execute(prompt, options)) {
183
+ if (message.type === 'assistant') {
184
+ const assistantMsg = message;
185
+ messages.push(assistantMsg.content);
186
+ }
187
+ else if (message.type === 'result') {
188
+ const resultMsg = message;
189
+ if (resultMsg.success) {
190
+ result.content = resultMsg.result || messages.join('\n');
191
+ result.usage = resultMsg.usage || result.usage;
192
+ result.duration = Date.now() - startTime;
193
+ }
194
+ else {
195
+ result.error = resultMsg.error;
196
+ throw new Error(resultMsg.error || 'Execution failed');
197
+ }
198
+ }
199
+ }
200
+ }
201
+ catch (error) {
202
+ result.error = error instanceof Error ? error.message : String(error);
203
+ result.duration = Date.now() - startTime;
204
+ throw error;
205
+ }
206
+ return result;
207
+ }
208
+ /**
209
+ * Detect available Claude models
210
+ */
211
+ async detectAvailableModels() {
212
+ // For now, return known Claude models
213
+ // In the future, could query the API for available models
214
+ return [
215
+ {
216
+ id: 'claude-sonnet-4-20250514',
217
+ name: 'claude-sonnet-4-20250514',
218
+ displayName: 'Claude Sonnet 4',
219
+ provider: this.name,
220
+ contextWindow: 200000,
221
+ maxOutputTokens: 64000,
222
+ capabilities: ['code', 'analysis', 'tools', 'vision', 'extended-thinking'],
223
+ },
224
+ {
225
+ id: 'claude-opus-4-1-20250805',
226
+ name: 'claude-opus-4-1-20250805',
227
+ displayName: 'Claude Opus 4.1',
228
+ provider: this.name,
229
+ contextWindow: 200000,
230
+ maxOutputTokens: 32000,
231
+ capabilities: [
232
+ 'code',
233
+ 'analysis',
234
+ 'tools',
235
+ 'deep-reasoning',
236
+ 'vision',
237
+ 'extended-thinking',
238
+ ],
239
+ },
240
+ {
241
+ id: 'claude-3-5-haiku-20241022',
242
+ name: 'claude-3-5-haiku-20241022',
243
+ displayName: 'Claude 3.5 Haiku',
244
+ provider: this.name,
245
+ contextWindow: 200000,
246
+ maxOutputTokens: 8000,
247
+ capabilities: ['code', 'analysis', 'tools', 'vision'],
248
+ },
249
+ ];
250
+ }
251
+ /**
252
+ * Validate Claude Code setup
253
+ */
254
+ async validateSetup() {
255
+ try {
256
+ const claudePath = this.getClaudeExecutablePath();
257
+ const fs = await import('fs/promises');
258
+ // Check if Claude executable exists
259
+ try {
260
+ await fs.access(claudePath);
261
+ }
262
+ catch {
263
+ // Try to execute claude directly (might be in PATH)
264
+ const { execSync } = await import('child_process');
265
+ try {
266
+ execSync('claude --version', { stdio: 'ignore' });
267
+ }
268
+ catch {
269
+ return {
270
+ available: false,
271
+ error: 'Claude CLI not found. Please install Claude Code CLI.',
272
+ models: [],
273
+ capabilities: this.getCapabilities(),
274
+ };
275
+ }
276
+ }
277
+ const models = await this.detectAvailableModels();
278
+ return {
279
+ available: true,
280
+ models,
281
+ capabilities: this.getCapabilities(),
282
+ };
283
+ }
284
+ catch (error) {
285
+ return {
286
+ available: false,
287
+ error: error instanceof Error ? error.message : String(error),
288
+ models: [],
289
+ capabilities: this.getCapabilities(),
290
+ };
291
+ }
292
+ }
293
+ /**
294
+ * Get provider capabilities
295
+ */
296
+ getCapabilities() {
297
+ return {
298
+ streaming: true,
299
+ tools: true,
300
+ functionCalling: false, // Claude Code uses tool format
301
+ vision: true,
302
+ codeExecution: true,
303
+ maxContextWindow: 200000,
304
+ maxOutputTokens: 8192,
305
+ };
306
+ }
307
+ /**
308
+ * Map ExecutionOptions to Claude Code Options
309
+ */
310
+ mapToClaudeOptions(options) {
311
+ const claudeOptions = {
312
+ cwd: options?.workingDirectory || this.config.defaultWorkingDirectory || process.cwd(),
313
+ model: options?.model || this.config.defaultModel,
314
+ pathToClaudeCodeExecutable: this.getClaudeExecutablePath(),
315
+ };
316
+ // Map temperature
317
+ if (options?.temperature !== undefined) {
318
+ claudeOptions.temperature = options.temperature;
319
+ }
320
+ // Map max tokens
321
+ if (options?.maxTokens !== undefined) {
322
+ claudeOptions.maxTokens = options.maxTokens;
323
+ }
324
+ // Map abort signal
325
+ if (options?.abortSignal) {
326
+ claudeOptions.abortController = new AbortController();
327
+ options.abortSignal.addEventListener('abort', () => {
328
+ claudeOptions.abortController?.abort();
329
+ });
330
+ }
331
+ // Map system prompt
332
+ if (options?.systemPrompt) {
333
+ claudeOptions.systemPrompt = options.systemPrompt;
334
+ }
335
+ if (options?.appendSystemPrompt) {
336
+ claudeOptions.appendSystemPrompt = options.appendSystemPrompt;
337
+ }
338
+ // Map tools
339
+ if (options?.tools) {
340
+ claudeOptions.allowedTools = options.tools;
341
+ }
342
+ return claudeOptions;
343
+ }
344
+ /**
345
+ * Resolve Claude CLI executable path
346
+ */
347
+ getClaudeExecutablePath() {
348
+ // Highest precedence: explicit env var (documented in README)
349
+ const envPath = process.env.VIBEMAN_CLAUDE_BIN;
350
+ if (envPath && envPath.trim()) {
351
+ return envPath.trim();
352
+ }
353
+ if (this.config.claudeBinPath) {
354
+ return this.config.claudeBinPath;
355
+ }
356
+ // Check settings first
357
+ const settingsBinPath = (() => {
358
+ try {
359
+ const svc = getSettingsService();
360
+ const s = svc.getSettings();
361
+ return s?.agents?.providers?.claudeCode?.binPath;
362
+ }
363
+ catch {
364
+ return undefined;
365
+ }
366
+ })();
367
+ if (settingsBinPath?.trim()) {
368
+ return settingsBinPath.trim();
369
+ }
370
+ // Default to local installation
371
+ return path.join(os.homedir(), '.claude', 'local', 'claude');
372
+ }
373
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Codex CLI Provider
3
+ * Headless wrapper around the Codex CLI `codex exec` command.
4
+ */
5
+ import { AIProvider, ExecutionMessage, ExecutionOptions, ModelInfo, ProviderCapabilities, ProviderStatus } from './types.js';
6
+ export interface CodexCliConfig {
7
+ codexBinPath?: string;
8
+ defaultWorkingDirectory?: string;
9
+ defaultModel?: string;
10
+ defaultTimeoutMs?: number;
11
+ }
12
+ export declare class CodexCliProvider implements AIProvider {
13
+ private config;
14
+ readonly name = "codex";
15
+ readonly displayName = "Codex CLI";
16
+ constructor(config?: CodexCliConfig);
17
+ private resolveExecutable;
18
+ execute(prompt: string, options?: ExecutionOptions): AsyncIterableIterator<ExecutionMessage>;
19
+ executeSync(prompt: string, options?: ExecutionOptions): Promise<{
20
+ id: string;
21
+ provider: string;
22
+ model: string;
23
+ content: string;
24
+ usage: {
25
+ promptTokens: number;
26
+ completionTokens: number;
27
+ totalTokens: number;
28
+ };
29
+ duration: number;
30
+ }>;
31
+ detectAvailableModels(): Promise<ModelInfo[]>;
32
+ validateSetup(): Promise<ProviderStatus>;
33
+ getCapabilities(): ProviderCapabilities;
34
+ }