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,613 @@
1
+ /**
2
+ * Settings Service - Centralized configuration management
3
+ *
4
+ * Provides persistent storage and validation for application settings
5
+ * with atomic write operations and schema validation using Zod.
6
+ */
7
+ import { EventEmitter } from 'events';
8
+ import fs from 'fs/promises';
9
+ import path from 'path';
10
+ import { z } from 'zod';
11
+ import { log } from './lib/logger.js';
12
+ import { getProjectRoot } from './lib/server/project-root.js';
13
+ // Zod schema for validation
14
+ const CLAUDE_ALLOWED_MODELS = [
15
+ 'claude-sonnet-4-20250514',
16
+ 'claude-opus-4-1-20250805',
17
+ 'claude-3-5-haiku-20241022',
18
+ ];
19
+ const MODEL_ENUM = [...CLAUDE_ALLOWED_MODELS, 'gpt-5'];
20
+ const VibemanSettingsSchema = z.object({
21
+ agents: z.object({
22
+ defaultProvider: z.enum(['claude-code', 'codex']),
23
+ codingAgent: z.object({
24
+ provider: z.enum(['claude-code', 'codex']),
25
+ model: z.enum(MODEL_ENUM),
26
+ maxTokens: z.number().min(256).max(10000000000000).optional(),
27
+ }),
28
+ judgeAgent: z.object({
29
+ provider: z.enum(['claude-code', 'codex']),
30
+ model: z.enum(MODEL_ENUM),
31
+ maxTokens: z.number().min(256).max(10000000000000).optional(),
32
+ reviewThresholdScore: z.number().min(0).max(100),
33
+ }),
34
+ defaultPrompts: z.object({
35
+ systemPrompt: z.string().min(10),
36
+ taskPrompt: z.string().min(10),
37
+ }),
38
+ // Note: Provider binary paths are now stored in local config (.vibeman/.local/)
39
+ // This field is kept for backwards compatibility but deprecated
40
+ providers: z
41
+ .object({
42
+ claudeCode: z.object({ binPath: z.string().min(1).optional() }).optional(),
43
+ codex: z.object({ binPath: z.string().min(1).optional() }).optional(),
44
+ })
45
+ .optional(),
46
+ }),
47
+ defaultWorkflow: z.object({
48
+ autoQualityChecks: z.boolean(),
49
+ requireHumanApproval: z.boolean(),
50
+ aiCodeReview: z.boolean(),
51
+ maxImplementationAttempts: z.number().min(1).max(10),
52
+ autoCommit: z.boolean(),
53
+ }),
54
+ quality: z
55
+ .object({
56
+ checks: z.array(z.object({
57
+ name: z.string().min(1),
58
+ command: z.string().min(1),
59
+ args: z.array(z.string()).optional(),
60
+ timeout: z
61
+ .number()
62
+ .min(1000)
63
+ .max(10 * 60 * 1000)
64
+ .optional(),
65
+ enabled: z.boolean().optional(),
66
+ })),
67
+ })
68
+ .optional(),
69
+ development: z.object({
70
+ vibeDir: z.string().min(1).optional(),
71
+ git: z.object({
72
+ defaultBranch: z.string().min(1),
73
+ worktreePath: z.string().min(1).optional(),
74
+ }),
75
+ editor: z
76
+ .object({
77
+ type: z.enum(['vscode', 'cursor', 'vim', 'custom']).optional(),
78
+ command: z.string().min(1).optional(),
79
+ args: z.array(z.string()).optional(),
80
+ name: z.string().min(1).optional(),
81
+ openFileCommand: z.array(z.string()).optional(),
82
+ openFolderCommand: z.array(z.string()).optional(),
83
+ })
84
+ .optional(),
85
+ terminal: z
86
+ .object({
87
+ type: z.enum(['system', 'iterm2', 'warp', 'custom']).optional(),
88
+ command: z.string().min(1).optional(),
89
+ args: z.array(z.string()).optional(),
90
+ name: z.string().min(1).optional(),
91
+ openCommand: z.array(z.string()).optional(),
92
+ })
93
+ .optional(),
94
+ }),
95
+ server: z.object({
96
+ port: z.number().min(3000).max(65535),
97
+ host: z.string().min(1),
98
+ autoOpenBrowser: z.boolean(),
99
+ }),
100
+ });
101
+ // Default settings
102
+ const DEFAULT_SETTINGS = {
103
+ agents: {
104
+ defaultProvider: 'claude-code',
105
+ codingAgent: {
106
+ provider: 'claude-code',
107
+ model: 'claude-sonnet-4-20250514',
108
+ },
109
+ judgeAgent: {
110
+ provider: 'claude-code',
111
+ model: 'claude-sonnet-4-20250514',
112
+ reviewThresholdScore: 70,
113
+ },
114
+ defaultPrompts: {
115
+ systemPrompt: 'You are a senior software engineer assistant. Follow best practices and write clean, maintainable code.',
116
+ taskPrompt: 'Please implement the following task with attention to quality and testing.',
117
+ },
118
+ providers: {},
119
+ },
120
+ defaultWorkflow: {
121
+ autoQualityChecks: true,
122
+ requireHumanApproval: true,
123
+ aiCodeReview: true,
124
+ maxImplementationAttempts: 3,
125
+ autoCommit: false,
126
+ },
127
+ quality: {
128
+ checks: [],
129
+ },
130
+ development: {
131
+ git: {
132
+ defaultBranch: 'main',
133
+ },
134
+ editor: {
135
+ type: 'vscode',
136
+ command: 'code',
137
+ args: [],
138
+ name: 'Visual Studio Code',
139
+ openFileCommand: ['code', '${file}'],
140
+ openFolderCommand: ['code', '${folder}'],
141
+ },
142
+ terminal: {
143
+ type: 'system',
144
+ command: process.platform === 'darwin'
145
+ ? 'open'
146
+ : process.platform === 'win32'
147
+ ? 'cmd'
148
+ : 'gnome-terminal',
149
+ args: process.platform === 'darwin' ? ['-a', 'Terminal'] : [],
150
+ name: process.platform === 'darwin'
151
+ ? 'Terminal'
152
+ : process.platform === 'win32'
153
+ ? 'Command Prompt'
154
+ : 'Terminal',
155
+ openCommand: process.platform === 'darwin'
156
+ ? ['open', '-a', 'Terminal', '${cwd}']
157
+ : process.platform === 'win32'
158
+ ? ['cmd', '/c', 'start', 'cmd', '/k', 'cd', '/d', '${cwd}']
159
+ : ['gnome-terminal', '--working-directory=${cwd}'],
160
+ },
161
+ },
162
+ server: {
163
+ port: 6969,
164
+ host: 'localhost',
165
+ autoOpenBrowser: true,
166
+ },
167
+ };
168
+ export class SettingsService extends EventEmitter {
169
+ constructor(config = {}) {
170
+ super();
171
+ this.settings = { ...DEFAULT_SETTINGS };
172
+ this.initialized = false;
173
+ const settingsDir = config.settingsDir ?? '.vibeman';
174
+ const settingsFileName = config.settingsFileName ?? 'settings.json';
175
+ // Resolve settings path relative to the repo project root (not package CWD)
176
+ const projectRoot = getProjectRoot();
177
+ this.settingsPath = path.join(projectRoot, settingsDir, settingsFileName);
178
+ }
179
+ /**
180
+ * Initialize the settings service
181
+ */
182
+ async initialize() {
183
+ if (this.initialized)
184
+ return;
185
+ try {
186
+ await this.ensureSettingsDirectory();
187
+ await this.loadSettings();
188
+ this.initialized = true;
189
+ log.info('Settings service initialized', { settingsPath: this.settingsPath }, 'settings-service');
190
+ }
191
+ catch (error) {
192
+ log.error('Failed to initialize settings service', error, 'settings-service');
193
+ throw error;
194
+ }
195
+ }
196
+ /**
197
+ * Get all current settings
198
+ */
199
+ getSettings() {
200
+ return { ...this.settings };
201
+ }
202
+ /**
203
+ * Get a specific setting by path
204
+ */
205
+ getSetting(path) {
206
+ let current = this.settings;
207
+ for (const key of path) {
208
+ if (current && typeof current === 'object' && key in current) {
209
+ current = current[key];
210
+ }
211
+ else {
212
+ return undefined;
213
+ }
214
+ }
215
+ return current;
216
+ }
217
+ /**
218
+ * Update settings with validation
219
+ */
220
+ async updateSettings(updates) {
221
+ // Create a copy to test updates
222
+ const testSettings = JSON.parse(JSON.stringify(this.settings));
223
+ const errors = [];
224
+ // Apply all updates to test copy
225
+ for (const update of updates) {
226
+ try {
227
+ this.applySingleUpdate(testSettings, update.path, update.value);
228
+ }
229
+ catch (error) {
230
+ errors.push({
231
+ path: update.path,
232
+ message: error instanceof Error ? error.message : 'Invalid update',
233
+ });
234
+ }
235
+ }
236
+ // Validate the entire updated settings object
237
+ try {
238
+ const validated = VibemanSettingsSchema.parse(testSettings);
239
+ if (errors.length === 0) {
240
+ // Apply updates to actual settings
241
+ this.settings = validated;
242
+ await this.saveSettings();
243
+ // Emit change events
244
+ for (const update of updates) {
245
+ this.emit('settingChanged', {
246
+ path: update.path,
247
+ oldValue: this.getSetting(update.path),
248
+ newValue: update.value,
249
+ });
250
+ }
251
+ this.emit('settingsUpdated', this.settings);
252
+ return { success: true, errors: [] };
253
+ }
254
+ }
255
+ catch (validationError) {
256
+ if (validationError instanceof z.ZodError) {
257
+ for (const issue of validationError.issues) {
258
+ errors.push({
259
+ path: issue.path.map(String),
260
+ message: issue.message,
261
+ expected: 'Valid value according to schema',
262
+ });
263
+ }
264
+ }
265
+ else {
266
+ errors.push({
267
+ path: [],
268
+ message: validationError instanceof Error ? validationError.message : 'Validation failed',
269
+ });
270
+ }
271
+ }
272
+ return { success: false, errors };
273
+ }
274
+ /**
275
+ * Reset settings to defaults
276
+ */
277
+ async resetToDefaults() {
278
+ this.settings = { ...DEFAULT_SETTINGS };
279
+ await this.saveSettings();
280
+ this.emit('settingsReset', this.settings);
281
+ log.info('Settings reset to defaults', undefined, 'settings-service');
282
+ }
283
+ /**
284
+ * Validate settings schema
285
+ */
286
+ validateSettings(settings) {
287
+ try {
288
+ VibemanSettingsSchema.parse(settings);
289
+ return { valid: true, errors: [] };
290
+ }
291
+ catch (error) {
292
+ const errors = [];
293
+ if (error instanceof z.ZodError) {
294
+ for (const issue of error.issues) {
295
+ errors.push({
296
+ path: issue.path.map(String),
297
+ message: issue.message,
298
+ expected: 'Valid value according to schema',
299
+ });
300
+ }
301
+ }
302
+ else {
303
+ errors.push({
304
+ path: [],
305
+ message: error instanceof Error ? error.message : 'Validation failed',
306
+ });
307
+ }
308
+ return { valid: false, errors };
309
+ }
310
+ }
311
+ /**
312
+ * Get settings file information
313
+ */
314
+ async getSettingsInfo() {
315
+ return {
316
+ path: this.settingsPath,
317
+ exists: await this.fileExists(this.settingsPath),
318
+ };
319
+ }
320
+ /**
321
+ * Get predefined editor configurations
322
+ */
323
+ getEditorPresets() {
324
+ return {
325
+ vscode: {
326
+ type: 'vscode',
327
+ command: 'code',
328
+ name: 'Visual Studio Code',
329
+ openFileCommand: ['code', '${file}'],
330
+ openFolderCommand: ['code', '${folder}'],
331
+ },
332
+ cursor: {
333
+ type: 'cursor',
334
+ command: 'cursor',
335
+ name: 'Cursor',
336
+ openFileCommand: ['cursor', '${file}'],
337
+ openFolderCommand: ['cursor', '${folder}'],
338
+ },
339
+ vim: {
340
+ type: 'vim',
341
+ command: 'vim',
342
+ name: 'Vim',
343
+ openFileCommand: ['vim', '${file}'],
344
+ openFolderCommand: ['vim', '${folder}'],
345
+ },
346
+ };
347
+ }
348
+ /**
349
+ * Get predefined terminal configurations
350
+ */
351
+ getTerminalPresets() {
352
+ const platform = process.platform;
353
+ return {
354
+ system: {
355
+ type: 'system',
356
+ command: platform === 'darwin' ? 'open' : platform === 'win32' ? 'cmd' : 'gnome-terminal',
357
+ args: platform === 'darwin' ? ['-a', 'Terminal'] : [],
358
+ name: platform === 'darwin' ? 'Terminal' : platform === 'win32' ? 'Command Prompt' : 'Terminal',
359
+ openCommand: platform === 'darwin'
360
+ ? ['open', '-a', 'Terminal', '${cwd}']
361
+ : platform === 'win32'
362
+ ? ['cmd', '/c', 'start', 'cmd', '/k', 'cd', '/d', '${cwd}']
363
+ : ['gnome-terminal', '--working-directory=${cwd}'],
364
+ },
365
+ iterm2: {
366
+ type: 'iterm2',
367
+ command: 'open',
368
+ args: ['-a', 'iTerm'],
369
+ name: 'iTerm2',
370
+ openCommand: ['open', '-a', 'iTerm', '${cwd}'],
371
+ },
372
+ warp: {
373
+ type: 'warp',
374
+ command: 'open',
375
+ args: ['-a', 'Warp'],
376
+ name: 'Warp',
377
+ openCommand: ['open', '-a', 'Warp', '${cwd}'],
378
+ },
379
+ };
380
+ }
381
+ /**
382
+ * Apply editor preset configuration
383
+ */
384
+ async applyEditorPreset(presetName) {
385
+ const presets = this.getEditorPresets();
386
+ const preset = presets[presetName];
387
+ if (!preset) {
388
+ return {
389
+ success: false,
390
+ errors: [
391
+ { path: ['development', 'editor'], message: `Unknown editor preset: ${presetName}` },
392
+ ],
393
+ };
394
+ }
395
+ return this.updateSettings([
396
+ {
397
+ path: ['development', 'editor'],
398
+ value: preset,
399
+ },
400
+ ]);
401
+ }
402
+ /**
403
+ * Apply terminal preset configuration
404
+ */
405
+ async applyTerminalPreset(presetName) {
406
+ const presets = this.getTerminalPresets();
407
+ const preset = presets[presetName];
408
+ if (!preset) {
409
+ return {
410
+ success: false,
411
+ errors: [
412
+ { path: ['development', 'terminal'], message: `Unknown terminal preset: ${presetName}` },
413
+ ],
414
+ };
415
+ }
416
+ return this.updateSettings([
417
+ {
418
+ path: ['development', 'terminal'],
419
+ value: preset,
420
+ },
421
+ ]);
422
+ }
423
+ /**
424
+ * Generate command to open a file with the configured editor
425
+ */
426
+ getOpenFileCommand(filePath) {
427
+ const editor = this.settings.development?.editor;
428
+ if (!editor?.openFileCommand)
429
+ return null;
430
+ return editor.openFileCommand.map((arg) => arg.replace('${file}', filePath));
431
+ }
432
+ /**
433
+ * Generate command to open a folder with the configured editor
434
+ */
435
+ getOpenFolderCommand(folderPath) {
436
+ const editor = this.settings.development?.editor;
437
+ if (!editor?.openFolderCommand)
438
+ return null;
439
+ return editor.openFolderCommand.map((arg) => arg.replace('${folder}', folderPath));
440
+ }
441
+ /**
442
+ * Generate command to open terminal in specific directory
443
+ */
444
+ getOpenTerminalCommand(cwd) {
445
+ const terminal = this.settings.development?.terminal;
446
+ if (!terminal?.openCommand)
447
+ return null;
448
+ return terminal.openCommand.map((arg) => arg.replace('${cwd}', cwd));
449
+ }
450
+ /**
451
+ * Validate if editor is available on system
452
+ */
453
+ async validateEditorAvailability() {
454
+ const editor = this.settings.development?.editor;
455
+ if (!editor?.command) {
456
+ return { available: false, error: 'No editor command configured' };
457
+ }
458
+ try {
459
+ const { exec } = await import('child_process');
460
+ const { promisify } = await import('util');
461
+ const execAsync = promisify(exec);
462
+ // Try to get version or check if command exists
463
+ await execAsync(`which ${editor.command}`, { timeout: 5000 });
464
+ return { available: true };
465
+ }
466
+ catch {
467
+ return {
468
+ available: false,
469
+ error: `Editor command '${editor.command}' not found in PATH`,
470
+ };
471
+ }
472
+ }
473
+ /**
474
+ * Validate if terminal is available on system
475
+ */
476
+ async validateTerminalAvailability() {
477
+ const terminal = this.settings.development?.terminal;
478
+ if (!terminal?.command) {
479
+ return { available: false, error: 'No terminal command configured' };
480
+ }
481
+ try {
482
+ const { exec } = await import('child_process');
483
+ const { promisify } = await import('util');
484
+ const execAsync = promisify(exec);
485
+ // Try to check if command exists
486
+ await execAsync(`which ${terminal.command}`, { timeout: 5000 });
487
+ return { available: true };
488
+ }
489
+ catch {
490
+ return {
491
+ available: false,
492
+ error: `Terminal command '${terminal.command}' not found in PATH`,
493
+ };
494
+ }
495
+ }
496
+ // Private methods
497
+ async ensureSettingsDirectory() {
498
+ const settingsDir = path.dirname(this.settingsPath);
499
+ try {
500
+ await fs.access(settingsDir);
501
+ }
502
+ catch {
503
+ await fs.mkdir(settingsDir, { recursive: true });
504
+ log.info('Created settings directory', { settingsDir }, 'settings-service');
505
+ }
506
+ }
507
+ async loadSettings() {
508
+ try {
509
+ await fs.access(this.settingsPath);
510
+ const data = await fs.readFile(this.settingsPath, 'utf-8');
511
+ const parsed = JSON.parse(data);
512
+ // Validate and merge with defaults
513
+ const validated = VibemanSettingsSchema.parse(parsed);
514
+ this.settings = this.mergeWithDefaults(validated);
515
+ log.info('Settings loaded from file', { settingsPath: this.settingsPath }, 'settings-service');
516
+ }
517
+ catch (error) {
518
+ log.info('Settings file not found or invalid, using defaults', { error: String(error) }, 'settings-service');
519
+ this.settings = { ...DEFAULT_SETTINGS };
520
+ await this.saveSettings();
521
+ }
522
+ }
523
+ async saveSettings() {
524
+ const data = JSON.stringify(this.settings, null, 2);
525
+ await fs.writeFile(this.settingsPath, data, 'utf-8');
526
+ log.debug('Settings saved to file', { settingsPath: this.settingsPath }, 'settings-service');
527
+ }
528
+ async fileExists(filePath) {
529
+ try {
530
+ await fs.access(filePath);
531
+ return true;
532
+ }
533
+ catch {
534
+ return false;
535
+ }
536
+ }
537
+ mergeWithDefaults(settings) {
538
+ // Deep merge settings with defaults to handle missing properties
539
+ return {
540
+ ...DEFAULT_SETTINGS,
541
+ ...settings,
542
+ agents: {
543
+ ...DEFAULT_SETTINGS.agents,
544
+ ...settings.agents,
545
+ codingAgent: {
546
+ ...DEFAULT_SETTINGS.agents.codingAgent,
547
+ ...settings.agents?.codingAgent,
548
+ },
549
+ judgeAgent: {
550
+ ...DEFAULT_SETTINGS.agents.judgeAgent,
551
+ ...settings.agents?.judgeAgent,
552
+ },
553
+ providers: {
554
+ ...(DEFAULT_SETTINGS.agents.providers ?? {}),
555
+ ...(settings.agents?.providers ?? {}),
556
+ },
557
+ defaultPrompts: {
558
+ ...DEFAULT_SETTINGS.agents.defaultPrompts,
559
+ ...settings.agents?.defaultPrompts,
560
+ },
561
+ },
562
+ defaultWorkflow: {
563
+ ...DEFAULT_SETTINGS.defaultWorkflow,
564
+ ...settings.defaultWorkflow,
565
+ },
566
+ quality: {
567
+ ...DEFAULT_SETTINGS.quality,
568
+ ...settings.quality,
569
+ checks: (settings.quality?.checks ?? DEFAULT_SETTINGS.quality?.checks),
570
+ },
571
+ development: {
572
+ ...DEFAULT_SETTINGS.development,
573
+ ...settings.development,
574
+ git: {
575
+ ...DEFAULT_SETTINGS.development.git,
576
+ ...settings.development?.git,
577
+ },
578
+ editor: {
579
+ ...DEFAULT_SETTINGS.development.editor,
580
+ ...settings.development?.editor,
581
+ },
582
+ terminal: {
583
+ ...DEFAULT_SETTINGS.development.terminal,
584
+ ...settings.development?.terminal,
585
+ },
586
+ },
587
+ server: {
588
+ ...DEFAULT_SETTINGS.server,
589
+ ...settings.server,
590
+ },
591
+ };
592
+ }
593
+ applySingleUpdate(target, path, value) {
594
+ if (path.length === 0) {
595
+ throw new Error('Empty path not allowed');
596
+ }
597
+ if (path.length === 1) {
598
+ target[path[0]] = value;
599
+ return;
600
+ }
601
+ const [head, ...tail] = path;
602
+ if (!target[head] || typeof target[head] !== 'object') {
603
+ target[head] = {};
604
+ }
605
+ this.applySingleUpdate(target[head], tail, value);
606
+ }
607
+ }
608
+ // Singleton instance
609
+ let settingsService = null;
610
+ export function getSettingsService(config) {
611
+ settingsService ?? (settingsService = new SettingsService(config));
612
+ return settingsService;
613
+ }
@@ -0,0 +1,23 @@
1
+ import { EventEmitter } from 'events';
2
+ export interface FileWatcherOptions {
3
+ recursive?: boolean;
4
+ debounceMs?: number;
5
+ fileFilter?: (filename: string) => boolean;
6
+ }
7
+ export interface FileChangeEvent {
8
+ type: 'created' | 'updated' | 'deleted';
9
+ filename: string;
10
+ fullPath: string;
11
+ }
12
+ export declare class FileWatcher extends EventEmitter {
13
+ private watcher;
14
+ private watchDir;
15
+ private options;
16
+ private pendingChanges;
17
+ constructor(watchDir: string, options?: FileWatcherOptions);
18
+ start(): void;
19
+ stop(): void;
20
+ private debounceFileChange;
21
+ private handleFileChange;
22
+ private fileExists;
23
+ }