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,395 @@
1
+ /**
2
+ * AI Router - Multi-Model Orchestration API
3
+ * Provides tRPC endpoints for managing AI providers and routing policies
4
+ */
5
+ import { z } from 'zod';
6
+ import { publicProcedure } from '../trpc.js';
7
+ import { RoutingPolicySchema, OperationConfigSchema, } from '../../agent/routing-policy.js';
8
+ import { log } from '../../lib/logger.js';
9
+ import { getSettingsService } from '../../settings-service.js';
10
+ /**
11
+ * Input schemas for API endpoints
12
+ */
13
+ const ListModelsInputSchema = z.object({
14
+ provider: z.string().optional(),
15
+ });
16
+ const UpdateRoutingPolicyInputSchema = z.object({
17
+ policy: RoutingPolicySchema.partial(),
18
+ });
19
+ const SetDefaultProviderInputSchema = z.object({
20
+ provider: z.string(),
21
+ });
22
+ const SetOperationConfigInputSchema = z.object({
23
+ operation: z.enum(['execute_task', 'improve_task', 'ai_codereview', 'ai_merge']),
24
+ config: OperationConfigSchema,
25
+ });
26
+ const ValidateProvidersInputSchema = z.object({
27
+ force: z.boolean().optional(),
28
+ });
29
+ /**
30
+ * Build AI router with required dependencies
31
+ */
32
+ export function buildAIRoutes(options) {
33
+ const { agentService } = options;
34
+ return {
35
+ /**
36
+ * List all registered AI providers with health status
37
+ */
38
+ listProviders: publicProcedure.query(async () => {
39
+ try {
40
+ const providers = agentService.getAvailableProviders();
41
+ const providerStatuses = await agentService.validateProviders();
42
+ const result = Array.from(providers.entries()).map(([name, provider]) => {
43
+ const status = providerStatuses.get(name);
44
+ return {
45
+ name,
46
+ displayName: provider.displayName,
47
+ available: status?.available || false,
48
+ error: status?.error,
49
+ capabilities: status?.capabilities || provider.getCapabilities(),
50
+ models: status?.models || [],
51
+ };
52
+ });
53
+ log.debug('Listed AI providers', { count: result.length }, 'ai-router');
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ const msg = `Failed to list providers: ${error instanceof Error ? error.message : String(error)}`;
58
+ log.error(msg, error, 'ai-router');
59
+ throw new Error(msg);
60
+ }
61
+ }),
62
+ /**
63
+ * List available models from providers
64
+ */
65
+ listModels: publicProcedure.input(ListModelsInputSchema.optional()).query(async ({ input }) => {
66
+ try {
67
+ if (input?.provider) {
68
+ // Get models from specific provider
69
+ const provider = agentService.getAvailableProviders().get(input.provider);
70
+ if (!provider) {
71
+ throw new Error(`Provider ${input.provider} not found`);
72
+ }
73
+ const models = await provider.detectAvailableModels();
74
+ log.debug('Listed models for provider', { provider: input.provider, count: models.length }, 'ai-router');
75
+ return models;
76
+ }
77
+ else {
78
+ // Get models from all providers
79
+ const models = await agentService.getAvailableModels();
80
+ log.debug('Listed all available models', { count: models.length }, 'ai-router');
81
+ return models;
82
+ }
83
+ }
84
+ catch (error) {
85
+ const msg = `Failed to list models: ${error instanceof Error ? error.message : String(error)}`;
86
+ log.error(msg, error, 'ai-router');
87
+ throw new Error(msg);
88
+ }
89
+ }),
90
+ /**
91
+ * Get current routing policy
92
+ */
93
+ getRoutingPolicy: publicProcedure.query(async () => {
94
+ try {
95
+ const policy = await agentService.getRoutingPolicyManager()?.getPolicy();
96
+ if (!policy) {
97
+ // Return default policy if none exists
98
+ const settings = getSettingsService().getSettings();
99
+ const defaultPolicy = {
100
+ defaultProvider: settings.agents.defaultProvider || 'claude-code',
101
+ operations: {},
102
+ };
103
+ return defaultPolicy;
104
+ }
105
+ log.debug('Retrieved routing policy', { policy }, 'ai-router');
106
+ return policy;
107
+ }
108
+ catch (error) {
109
+ const msg = `Failed to get routing policy: ${error instanceof Error ? error.message : String(error)}`;
110
+ log.error(msg, error, 'ai-router');
111
+ throw new Error(msg);
112
+ }
113
+ }),
114
+ /**
115
+ * Update routing policy
116
+ */
117
+ updateRoutingPolicy: publicProcedure
118
+ .input(UpdateRoutingPolicyInputSchema)
119
+ .mutation(async ({ input }) => {
120
+ try {
121
+ const routingManager = agentService.getRoutingPolicyManager();
122
+ if (!routingManager) {
123
+ throw new Error('Routing policy manager not available');
124
+ }
125
+ await routingManager.updatePolicy(input.policy);
126
+ const updatedPolicy = await routingManager.getPolicy();
127
+ log.info('Updated routing policy', { updates: input.policy }, 'ai-router');
128
+ return { success: true, policy: updatedPolicy };
129
+ }
130
+ catch (error) {
131
+ const msg = `Failed to update routing policy: ${error instanceof Error ? error.message : String(error)}`;
132
+ log.error(msg, error, 'ai-router');
133
+ throw new Error(msg);
134
+ }
135
+ }),
136
+ /**
137
+ * Set default provider
138
+ */
139
+ setDefaultProvider: publicProcedure
140
+ .input(SetDefaultProviderInputSchema)
141
+ .mutation(async ({ input }) => {
142
+ try {
143
+ const routingManager = agentService.getRoutingPolicyManager();
144
+ if (!routingManager) {
145
+ throw new Error('Routing policy manager not available');
146
+ }
147
+ // Validate provider exists
148
+ const providers = agentService.getAvailableProviders();
149
+ if (!providers.has(input.provider)) {
150
+ throw new Error(`Provider ${input.provider} not found`);
151
+ }
152
+ await routingManager.setDefaultProvider(input.provider);
153
+ log.info('Set default provider', { provider: input.provider }, 'ai-router');
154
+ return { success: true, provider: input.provider };
155
+ }
156
+ catch (error) {
157
+ const msg = `Failed to set default provider: ${error instanceof Error ? error.message : String(error)}`;
158
+ log.error(msg, error, 'ai-router');
159
+ throw new Error(msg);
160
+ }
161
+ }),
162
+ /**
163
+ * Set operation-specific configuration
164
+ */
165
+ setOperationConfig: publicProcedure
166
+ .input(SetOperationConfigInputSchema)
167
+ .mutation(async ({ input }) => {
168
+ try {
169
+ const routingManager = agentService.getRoutingPolicyManager();
170
+ if (!routingManager) {
171
+ throw new Error('Routing policy manager not available');
172
+ }
173
+ // Validate provider exists
174
+ const providers = agentService.getAvailableProviders();
175
+ if (!providers.has(input.config.provider)) {
176
+ throw new Error(`Provider ${input.config.provider} not found`);
177
+ }
178
+ // Validate fallback providers if specified
179
+ if (input.config.fallback) {
180
+ for (const fallbackProvider of input.config.fallback) {
181
+ if (!providers.has(fallbackProvider)) {
182
+ throw new Error(`Fallback provider ${fallbackProvider} not found`);
183
+ }
184
+ }
185
+ }
186
+ await routingManager.setOperationConfig(input.operation, input.config);
187
+ log.info('Set operation config', { operation: input.operation, config: input.config }, 'ai-router');
188
+ return { success: true };
189
+ }
190
+ catch (error) {
191
+ const msg = `Failed to set operation config: ${error instanceof Error ? error.message : String(error)}`;
192
+ log.error(msg, error, 'ai-router');
193
+ throw new Error(msg);
194
+ }
195
+ }),
196
+ /**
197
+ * Validate provider setup and refresh health status
198
+ */
199
+ validateProviders: publicProcedure
200
+ .input(ValidateProvidersInputSchema.optional())
201
+ .mutation(async ({ input }) => {
202
+ try {
203
+ const results = await agentService.validateProviders();
204
+ const validation = Array.from(results.entries()).map(([name, status]) => ({
205
+ provider: name,
206
+ available: status.available,
207
+ error: status.error,
208
+ modelCount: status.models.length,
209
+ capabilities: status.capabilities,
210
+ }));
211
+ log.info('Validated providers', {
212
+ force: input?.force || false,
213
+ results: validation,
214
+ }, 'ai-router');
215
+ return {
216
+ success: true,
217
+ results: validation,
218
+ totalProviders: validation.length,
219
+ availableProviders: validation.filter((p) => p.available).length,
220
+ };
221
+ }
222
+ catch (error) {
223
+ const msg = `Failed to validate providers: ${error instanceof Error ? error.message : String(error)}`;
224
+ log.error(msg, error, 'ai-router');
225
+ throw new Error(msg);
226
+ }
227
+ }),
228
+ };
229
+ }
230
+ /**
231
+ * Test-friendly plain handlers mirroring the AI routes, without tRPC wrappers.
232
+ * Useful for unit tests that call functions directly.
233
+ */
234
+ export function buildAIRouteHandlers(options) {
235
+ const { agentService } = options;
236
+ return {
237
+ async listProviders() {
238
+ try {
239
+ const providers = agentService.getAvailableProviders();
240
+ const providerStatuses = await agentService.validateProviders();
241
+ return Array.from(providers.entries()).map(([name, provider]) => {
242
+ const status = providerStatuses.get(name);
243
+ return {
244
+ name,
245
+ displayName: provider.displayName,
246
+ available: status?.available || false,
247
+ error: status?.error,
248
+ capabilities: status?.capabilities || provider.getCapabilities?.(),
249
+ models: status?.models || [],
250
+ };
251
+ });
252
+ }
253
+ catch (error) {
254
+ throw new Error(`Failed to list providers: ${error instanceof Error ? error.message : String(error)}`);
255
+ }
256
+ },
257
+ async listModels(input) {
258
+ try {
259
+ if (input?.provider) {
260
+ const provider = agentService.getAvailableProviders().get(input.provider);
261
+ if (!provider)
262
+ throw new Error(`Provider ${input.provider} not found`);
263
+ return await provider.detectAvailableModels();
264
+ }
265
+ return await agentService.getAvailableModels();
266
+ }
267
+ catch (error) {
268
+ throw new Error(`Failed to list models: ${error instanceof Error ? error.message : String(error)}`);
269
+ }
270
+ },
271
+ async getRoutingPolicy() {
272
+ try {
273
+ const rpm = agentService.getRoutingPolicyManager?.() ||
274
+ agentService.routingPolicyManager;
275
+ const policy = await rpm?.getPolicy();
276
+ if (!policy) {
277
+ const settings = getSettingsService().getSettings();
278
+ return {
279
+ defaultProvider: settings.agents.defaultProvider || 'claude-code',
280
+ operations: {},
281
+ };
282
+ }
283
+ return policy;
284
+ }
285
+ catch (error) {
286
+ throw new Error(`Failed to get routing policy: ${error instanceof Error ? error.message : String(error)}`);
287
+ }
288
+ },
289
+ async updateRoutingPolicy(input) {
290
+ try {
291
+ const routingManager = agentService.getRoutingPolicyManager?.() ||
292
+ agentService.routingPolicyManager;
293
+ if (!routingManager)
294
+ throw new Error('Routing policy manager not available');
295
+ await routingManager.updatePolicy(input.policy);
296
+ const updatedPolicy = await routingManager.getPolicy();
297
+ return { success: true, policy: updatedPolicy };
298
+ }
299
+ catch (error) {
300
+ throw new Error(`Failed to update routing policy: ${error instanceof Error ? error.message : String(error)}`);
301
+ }
302
+ },
303
+ async setDefaultProvider(input) {
304
+ try {
305
+ const routingManager = agentService.getRoutingPolicyManager?.() ||
306
+ agentService.routingPolicyManager;
307
+ if (!routingManager)
308
+ throw new Error('Routing policy manager not available');
309
+ const providers = agentService.getAvailableProviders();
310
+ if (!providers.has(input.provider))
311
+ throw new Error(`Provider ${input.provider} not found`);
312
+ await routingManager.setDefaultProvider(input.provider);
313
+ return { success: true, provider: input.provider };
314
+ }
315
+ catch (error) {
316
+ throw new Error(`Failed to set default provider: ${error instanceof Error ? error.message : String(error)}`);
317
+ }
318
+ },
319
+ async setOperationConfig(input) {
320
+ try {
321
+ const routingManager = agentService.getRoutingPolicyManager?.() ||
322
+ agentService.routingPolicyManager;
323
+ if (!routingManager)
324
+ throw new Error('Routing policy manager not available');
325
+ const providers = agentService.getAvailableProviders();
326
+ if (!providers.has(input.config.provider)) {
327
+ throw new Error(`Provider ${input.config.provider} not found`);
328
+ }
329
+ if (input.config.fallback) {
330
+ for (const fallbackProvider of input.config.fallback) {
331
+ if (!providers.has(fallbackProvider)) {
332
+ throw new Error(`Fallback provider ${fallbackProvider} not found`);
333
+ }
334
+ }
335
+ }
336
+ await routingManager.setOperationConfig(input.operation, input.config);
337
+ return { success: true };
338
+ }
339
+ catch (error) {
340
+ throw new Error(`Failed to set operation config: ${error instanceof Error ? error.message : String(error)}`);
341
+ }
342
+ },
343
+ async validateProviders() {
344
+ try {
345
+ const results = await agentService.validateProviders();
346
+ const validation = Array.from(results.entries()).map(([name, status]) => ({
347
+ provider: name,
348
+ available: status.available,
349
+ error: status.error,
350
+ modelCount: status.models.length,
351
+ capabilities: status.capabilities,
352
+ }));
353
+ return {
354
+ success: true,
355
+ results: validation,
356
+ totalProviders: validation.length,
357
+ availableProviders: validation.filter((p) => p.available).length,
358
+ };
359
+ }
360
+ catch (error) {
361
+ throw new Error(`Failed to validate providers: ${error instanceof Error ? error.message : String(error)}`);
362
+ }
363
+ },
364
+ async getProviderHealth() {
365
+ try {
366
+ const providers = agentService.getAvailableProviders();
367
+ const statuses = await agentService.validateProviders();
368
+ const health = {
369
+ totalProviders: providers.size,
370
+ availableProviders: 0,
371
+ unavailableProviders: 0,
372
+ providers: [],
373
+ };
374
+ for (const [name] of providers) {
375
+ const status = statuses.get(name);
376
+ const isAvailable = status?.available || false;
377
+ if (isAvailable)
378
+ health.availableProviders++;
379
+ else
380
+ health.unavailableProviders++;
381
+ health.providers.push({
382
+ name,
383
+ available: isAvailable,
384
+ error: status?.error,
385
+ modelCount: status?.models.length || 0,
386
+ });
387
+ }
388
+ return health;
389
+ }
390
+ catch (error) {
391
+ throw new Error(`Failed to get provider health: ${error instanceof Error ? error.message : String(error)}`);
392
+ }
393
+ },
394
+ };
395
+ }
@@ -0,0 +1,98 @@
1
+ import type { TaskService } from '../../tasks/task-service.js';
2
+ import type { VibingOrchestrator } from '../../workflows/vibing-orchestrator.js';
3
+ type Deps = {
4
+ taskService: TaskService;
5
+ vibingOrchestrator: VibingOrchestrator;
6
+ };
7
+ export declare function buildExecutionRoutes({ taskService, vibingOrchestrator }: Deps): {
8
+ readonly executeTask: import("@trpc/server").TRPCMutationProcedure<{
9
+ input: {
10
+ taskId: string;
11
+ };
12
+ output: {
13
+ readonly executionId: string;
14
+ };
15
+ meta: object;
16
+ }>;
17
+ readonly stopTaskExecution: import("@trpc/server").TRPCMutationProcedure<{
18
+ input: {
19
+ executionId: string;
20
+ };
21
+ output: {
22
+ readonly success: true;
23
+ };
24
+ meta: object;
25
+ }>;
26
+ readonly getTaskExecutionStatus: import("@trpc/server").TRPCQueryProcedure<{
27
+ input: {
28
+ executionId: string;
29
+ };
30
+ output: import("../../types/index.js").AgentExecution | null;
31
+ meta: object;
32
+ }>;
33
+ readonly getTaskExecutionLogs: import("@trpc/server").TRPCQueryProcedure<{
34
+ input: {
35
+ executionId: string;
36
+ };
37
+ output: {
38
+ logs: any[];
39
+ };
40
+ meta: object;
41
+ }>;
42
+ readonly getTaskExecutions: import("@trpc/server").TRPCQueryProcedure<{
43
+ input: {
44
+ taskId: string;
45
+ };
46
+ output: import("../../types/index.js").AgentExecution[];
47
+ meta: object;
48
+ }>;
49
+ readonly getTaskExecutionStats: import("@trpc/server").TRPCQueryProcedure<{
50
+ input: void;
51
+ output: {
52
+ total: number;
53
+ pending: number;
54
+ running: number;
55
+ completed: number;
56
+ failed: number;
57
+ cancelled: number;
58
+ worktrees: {
59
+ active: number;
60
+ total: number;
61
+ enabled: boolean;
62
+ };
63
+ };
64
+ meta: object;
65
+ }>;
66
+ readonly improveTask: import("@trpc/server").TRPCMutationProcedure<{
67
+ input: {
68
+ title: string;
69
+ type: "feature" | "bug" | "chore" | "refactor" | "test" | "doc";
70
+ priority: "high" | "medium" | "low";
71
+ content: string;
72
+ taskId: string;
73
+ executionId?: string | undefined;
74
+ };
75
+ output: {
76
+ type: string;
77
+ priority: string;
78
+ content: string;
79
+ title?: string;
80
+ executionId: string;
81
+ selectedModel?: string;
82
+ };
83
+ meta: object;
84
+ }>;
85
+ readonly onExecutionUpdate: import("@trpc/server").TRPCSubscriptionProcedure<{
86
+ input: {
87
+ executionId: string;
88
+ };
89
+ output: AsyncIterable<{
90
+ executionId: string;
91
+ status: "pending" | "running" | "completed" | "failed" | "cancelled";
92
+ logs: string[];
93
+ error?: string;
94
+ }, void, any>;
95
+ meta: object;
96
+ }>;
97
+ };
98
+ export {};
@@ -0,0 +1,94 @@
1
+ import { z } from 'zod';
2
+ import { on, EventEmitter } from 'events';
3
+ import { publicProcedure } from '../trpc.js';
4
+ import { ExecutionIdSchema, TaskIdSchema } from '../router-helpers.js';
5
+ import { makeAssertTaskActive } from '../router-helpers.js';
6
+ import { log } from '../../lib/logger.js';
7
+ export function buildExecutionRoutes({ taskService, vibingOrchestrator }) {
8
+ const assertTaskActive = makeAssertTaskActive(taskService);
9
+ return {
10
+ executeTask: publicProcedure.input(TaskIdSchema).mutation(async ({ input }) => {
11
+ assertTaskActive(input.taskId);
12
+ const { executionId } = await vibingOrchestrator.executeTask(input.taskId);
13
+ return { executionId };
14
+ }),
15
+ stopTaskExecution: publicProcedure.input(ExecutionIdSchema).mutation(async ({ input }) => {
16
+ await vibingOrchestrator.stopExecution(input.executionId);
17
+ return { success: true };
18
+ }),
19
+ getTaskExecutionStatus: publicProcedure.input(ExecutionIdSchema).query(async ({ input }) => {
20
+ return vibingOrchestrator.getExecutionStatus(input.executionId);
21
+ }),
22
+ getTaskExecutionLogs: publicProcedure.input(ExecutionIdSchema).query(async ({ input }) => {
23
+ try {
24
+ const persistedLogs = await vibingOrchestrator.getPersistedExecutionLogs(input.executionId);
25
+ return { logs: persistedLogs.logs };
26
+ }
27
+ catch (error) {
28
+ log.error('Failed to get task execution logs', error);
29
+ const logs = vibingOrchestrator.getExecutionLogs(input.executionId);
30
+ const logEntries = logs.map((message, index) => ({
31
+ timestamp: new Date().toISOString(),
32
+ level: 'info',
33
+ message,
34
+ data: { index },
35
+ }));
36
+ return { logs: logEntries };
37
+ }
38
+ }),
39
+ getTaskExecutions: publicProcedure.input(TaskIdSchema).query(async ({ input }) => {
40
+ return vibingOrchestrator.getTaskExecutions(input.taskId);
41
+ }),
42
+ getTaskExecutionStats: publicProcedure.query(async () => {
43
+ return vibingOrchestrator.getExecutionStats();
44
+ }),
45
+ improveTask: publicProcedure
46
+ .input(z.object({
47
+ taskId: z.string(),
48
+ title: z.string(),
49
+ type: z.enum(['feature', 'bug', 'chore', 'refactor', 'test', 'doc']),
50
+ priority: z.enum(['low', 'medium', 'high']),
51
+ content: z.string(),
52
+ executionId: z.string().optional(),
53
+ }))
54
+ .mutation(async ({ input }) => {
55
+ assertTaskActive(input.taskId);
56
+ const improvement = await vibingOrchestrator.improveTaskContent(input.taskId, {
57
+ title: input.title,
58
+ type: input.type,
59
+ priority: input.priority,
60
+ content: input.content,
61
+ }, { executionId: input.executionId });
62
+ return improvement;
63
+ }),
64
+ onExecutionUpdate: publicProcedure
65
+ .input(z.object({ executionId: z.string() }))
66
+ .subscription(async function* (opts) {
67
+ const input = opts.input;
68
+ // Emit initial status if exists
69
+ const initial = vibingOrchestrator.getExecutionStatus(input.executionId);
70
+ if (initial) {
71
+ yield {
72
+ executionId: initial.id,
73
+ status: initial.status,
74
+ logs: initial.logs,
75
+ error: initial.error,
76
+ };
77
+ }
78
+ const proxy = new EventEmitter();
79
+ const handleUpdate = (update) => {
80
+ if (update.executionId === input.executionId)
81
+ proxy.emit('data', update);
82
+ };
83
+ vibingOrchestrator.on('executionUpdated', handleUpdate);
84
+ try {
85
+ for await (const [payload] of on(proxy, 'data', { signal: opts.signal })) {
86
+ yield payload;
87
+ }
88
+ }
89
+ finally {
90
+ vibingOrchestrator.off('executionUpdated', handleUpdate);
91
+ }
92
+ }),
93
+ };
94
+ }
@@ -0,0 +1,45 @@
1
+ import type { TaskService } from '../../tasks/task-service.js';
2
+ import type { GitService } from '../../vcs/git-service.js';
3
+ export declare function buildGitRoutes(taskService: TaskService, gitService: GitService): {
4
+ readonly getGitStatus: import("@trpc/server").TRPCQueryProcedure<{
5
+ input: void;
6
+ output: {
7
+ current: string;
8
+ staged: string[];
9
+ modified: string[];
10
+ untracked: string[];
11
+ ahead: number;
12
+ behind: number;
13
+ };
14
+ meta: object;
15
+ }>;
16
+ readonly createBranch: import("@trpc/server").TRPCMutationProcedure<{
17
+ input: {
18
+ taskId: string;
19
+ baseBranch?: string | undefined;
20
+ };
21
+ output: import("../../vcs/git-service.js").BranchInfo;
22
+ meta: object;
23
+ }>;
24
+ readonly commitChanges: import("@trpc/server").TRPCMutationProcedure<{
25
+ input: {
26
+ taskId: string;
27
+ message?: string | undefined;
28
+ files?: string[] | undefined;
29
+ };
30
+ output: import("../../vcs/git-service.js").CommitInfo;
31
+ meta: object;
32
+ }>;
33
+ readonly getCommitHistory: import("@trpc/server").TRPCQueryProcedure<{
34
+ input: {
35
+ maxCount?: number | undefined;
36
+ };
37
+ output: import("../../vcs/git-service.js").CommitInfo[];
38
+ meta: object;
39
+ }>;
40
+ readonly hasUncommittedChanges: import("@trpc/server").TRPCQueryProcedure<{
41
+ input: void;
42
+ output: boolean;
43
+ meta: object;
44
+ }>;
45
+ };
@@ -0,0 +1,35 @@
1
+ import { z } from 'zod';
2
+ import { publicProcedure } from '../trpc.js';
3
+ import { makeAssertTaskActive } from '../router-helpers.js';
4
+ export function buildGitRoutes(taskService, gitService) {
5
+ const assertTaskActive = makeAssertTaskActive(taskService);
6
+ return {
7
+ getGitStatus: publicProcedure.query(async () => {
8
+ return await gitService.getStatus();
9
+ }),
10
+ createBranch: publicProcedure
11
+ .input(z.object({ taskId: z.string(), baseBranch: z.string().optional() }))
12
+ .mutation(async ({ input }) => {
13
+ const task = assertTaskActive(input.taskId);
14
+ return await gitService.createBranch(task, input.baseBranch);
15
+ }),
16
+ commitChanges: publicProcedure
17
+ .input(z.object({
18
+ taskId: z.string(),
19
+ message: z.string().optional(),
20
+ files: z.array(z.string()).optional(),
21
+ }))
22
+ .mutation(async ({ input }) => {
23
+ const task = assertTaskActive(input.taskId);
24
+ return await gitService.commitChanges(task, input.message, input.files);
25
+ }),
26
+ getCommitHistory: publicProcedure
27
+ .input(z.object({ maxCount: z.number().optional() }))
28
+ .query(async ({ input }) => {
29
+ return await gitService.getCommitHistory(input.maxCount);
30
+ }),
31
+ hasUncommittedChanges: publicProcedure.query(async () => {
32
+ return await gitService.hasUncommittedChanges();
33
+ }),
34
+ };
35
+ }