@sylphx/flow 1.0.1 → 1.0.3

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 (229) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +10 -9
  3. package/src/commands/codebase-command.ts +168 -0
  4. package/src/commands/flow-command.ts +1137 -0
  5. package/src/commands/flow-orchestrator.ts +296 -0
  6. package/src/commands/hook-command.ts +444 -0
  7. package/src/commands/init-command.ts +92 -0
  8. package/src/commands/init-core.ts +322 -0
  9. package/src/commands/knowledge-command.ts +161 -0
  10. package/src/commands/run-command.ts +120 -0
  11. package/src/components/benchmark-monitor.tsx +331 -0
  12. package/src/components/reindex-progress.tsx +261 -0
  13. package/src/composables/functional/index.ts +14 -0
  14. package/src/composables/functional/useEnvironment.ts +171 -0
  15. package/src/composables/functional/useFileSystem.ts +139 -0
  16. package/src/composables/index.ts +5 -0
  17. package/src/composables/useEnv.ts +13 -0
  18. package/src/composables/useRuntimeConfig.ts +27 -0
  19. package/src/composables/useTargetConfig.ts +45 -0
  20. package/src/config/ai-config.ts +376 -0
  21. package/src/config/constants.ts +35 -0
  22. package/src/config/index.ts +27 -0
  23. package/src/config/rules.ts +43 -0
  24. package/src/config/servers.ts +371 -0
  25. package/src/config/targets.ts +126 -0
  26. package/src/core/agent-loader.ts +141 -0
  27. package/src/core/agent-manager.ts +174 -0
  28. package/src/core/ai-sdk.ts +603 -0
  29. package/src/core/app-factory.ts +381 -0
  30. package/src/core/builtin-agents.ts +9 -0
  31. package/src/core/command-system.ts +550 -0
  32. package/src/core/config-system.ts +550 -0
  33. package/src/core/connection-pool.ts +390 -0
  34. package/src/core/di-container.ts +155 -0
  35. package/src/core/error-handling.ts +519 -0
  36. package/src/core/formatting/bytes.test.ts +115 -0
  37. package/src/core/formatting/bytes.ts +64 -0
  38. package/src/core/functional/async.ts +313 -0
  39. package/src/core/functional/either.ts +109 -0
  40. package/src/core/functional/error-handler.ts +135 -0
  41. package/src/core/functional/error-types.ts +311 -0
  42. package/src/core/functional/index.ts +19 -0
  43. package/src/core/functional/option.ts +142 -0
  44. package/src/core/functional/pipe.ts +189 -0
  45. package/src/core/functional/result.ts +204 -0
  46. package/src/core/functional/validation.ts +138 -0
  47. package/src/core/headless-display.ts +96 -0
  48. package/src/core/index.ts +6 -0
  49. package/src/core/installers/file-installer.ts +303 -0
  50. package/src/core/installers/mcp-installer.ts +213 -0
  51. package/src/core/interfaces/index.ts +22 -0
  52. package/src/core/interfaces/repository.interface.ts +91 -0
  53. package/src/core/interfaces/service.interface.ts +133 -0
  54. package/src/core/interfaces.ts +129 -0
  55. package/src/core/loop-controller.ts +200 -0
  56. package/src/core/result.ts +351 -0
  57. package/src/core/rule-loader.ts +147 -0
  58. package/src/core/rule-manager.ts +240 -0
  59. package/src/core/service-config.ts +252 -0
  60. package/src/core/session-service.ts +121 -0
  61. package/src/core/state-detector.ts +389 -0
  62. package/src/core/storage-factory.ts +115 -0
  63. package/src/core/stream-handler.ts +288 -0
  64. package/src/core/target-manager.ts +161 -0
  65. package/src/core/type-utils.ts +427 -0
  66. package/src/core/unified-storage.ts +456 -0
  67. package/src/core/upgrade-manager.ts +300 -0
  68. package/src/core/validation/limit.test.ts +155 -0
  69. package/src/core/validation/limit.ts +46 -0
  70. package/src/core/validation/query.test.ts +44 -0
  71. package/src/core/validation/query.ts +20 -0
  72. package/src/db/auto-migrate.ts +322 -0
  73. package/src/db/base-database-client.ts +144 -0
  74. package/src/db/cache-db.ts +218 -0
  75. package/src/db/cache-schema.ts +75 -0
  76. package/src/db/database.ts +70 -0
  77. package/src/db/index.ts +252 -0
  78. package/src/db/memory-db.ts +153 -0
  79. package/src/db/memory-schema.ts +29 -0
  80. package/src/db/schema.ts +289 -0
  81. package/src/db/session-repository.ts +733 -0
  82. package/src/domains/codebase/index.ts +5 -0
  83. package/src/domains/codebase/tools.ts +139 -0
  84. package/src/domains/index.ts +8 -0
  85. package/src/domains/knowledge/index.ts +10 -0
  86. package/src/domains/knowledge/resources.ts +537 -0
  87. package/src/domains/knowledge/tools.ts +174 -0
  88. package/src/domains/utilities/index.ts +6 -0
  89. package/src/domains/utilities/time/index.ts +5 -0
  90. package/src/domains/utilities/time/tools.ts +291 -0
  91. package/src/index.ts +211 -0
  92. package/src/services/agent-service.ts +273 -0
  93. package/src/services/claude-config-service.ts +252 -0
  94. package/src/services/config-service.ts +258 -0
  95. package/src/services/evaluation-service.ts +271 -0
  96. package/src/services/functional/evaluation-logic.ts +296 -0
  97. package/src/services/functional/file-processor.ts +273 -0
  98. package/src/services/functional/index.ts +12 -0
  99. package/src/services/index.ts +13 -0
  100. package/src/services/mcp-service.ts +432 -0
  101. package/src/services/memory.service.ts +476 -0
  102. package/src/services/search/base-indexer.ts +156 -0
  103. package/src/services/search/codebase-indexer-types.ts +38 -0
  104. package/src/services/search/codebase-indexer.ts +647 -0
  105. package/src/services/search/embeddings-provider.ts +455 -0
  106. package/src/services/search/embeddings.ts +316 -0
  107. package/src/services/search/functional-indexer.ts +323 -0
  108. package/src/services/search/index.ts +27 -0
  109. package/src/services/search/indexer.ts +380 -0
  110. package/src/services/search/knowledge-indexer.ts +422 -0
  111. package/src/services/search/semantic-search.ts +244 -0
  112. package/src/services/search/tfidf.ts +559 -0
  113. package/src/services/search/unified-search-service.ts +888 -0
  114. package/src/services/smart-config-service.ts +385 -0
  115. package/src/services/storage/cache-storage.ts +487 -0
  116. package/src/services/storage/drizzle-storage.ts +581 -0
  117. package/src/services/storage/index.ts +15 -0
  118. package/src/services/storage/lancedb-vector-storage.ts +494 -0
  119. package/src/services/storage/memory-storage.ts +268 -0
  120. package/src/services/storage/separated-storage.ts +467 -0
  121. package/src/services/storage/vector-storage.ts +13 -0
  122. package/src/shared/agents/index.ts +63 -0
  123. package/src/shared/files/index.ts +99 -0
  124. package/src/shared/index.ts +32 -0
  125. package/src/shared/logging/index.ts +24 -0
  126. package/src/shared/processing/index.ts +153 -0
  127. package/src/shared/types/index.ts +25 -0
  128. package/src/targets/claude-code.ts +574 -0
  129. package/src/targets/functional/claude-code-logic.ts +185 -0
  130. package/src/targets/functional/index.ts +6 -0
  131. package/src/targets/opencode.ts +529 -0
  132. package/src/types/agent.types.ts +32 -0
  133. package/src/types/api/batch.ts +108 -0
  134. package/src/types/api/errors.ts +118 -0
  135. package/src/types/api/index.ts +55 -0
  136. package/src/types/api/requests.ts +76 -0
  137. package/src/types/api/responses.ts +180 -0
  138. package/src/types/api/websockets.ts +85 -0
  139. package/src/types/api.types.ts +9 -0
  140. package/src/types/benchmark.ts +49 -0
  141. package/src/types/cli.types.ts +87 -0
  142. package/src/types/common.types.ts +35 -0
  143. package/src/types/database.types.ts +510 -0
  144. package/src/types/mcp-config.types.ts +448 -0
  145. package/src/types/mcp.types.ts +69 -0
  146. package/src/types/memory-types.ts +63 -0
  147. package/src/types/provider.types.ts +28 -0
  148. package/src/types/rule.types.ts +24 -0
  149. package/src/types/session.types.ts +214 -0
  150. package/src/types/target-config.types.ts +295 -0
  151. package/src/types/target.types.ts +140 -0
  152. package/src/types/todo.types.ts +25 -0
  153. package/src/types.ts +40 -0
  154. package/src/utils/advanced-tokenizer.ts +191 -0
  155. package/src/utils/agent-enhancer.ts +114 -0
  156. package/src/utils/ai-model-fetcher.ts +19 -0
  157. package/src/utils/async-file-operations.ts +516 -0
  158. package/src/utils/audio-player.ts +345 -0
  159. package/src/utils/cli-output.ts +266 -0
  160. package/src/utils/codebase-helpers.ts +211 -0
  161. package/src/utils/console-ui.ts +79 -0
  162. package/src/utils/database-errors.ts +140 -0
  163. package/src/utils/debug-logger.ts +49 -0
  164. package/src/utils/error-handler.ts +53 -0
  165. package/src/utils/file-operations.ts +310 -0
  166. package/src/utils/file-scanner.ts +259 -0
  167. package/src/utils/functional/array.ts +355 -0
  168. package/src/utils/functional/index.ts +15 -0
  169. package/src/utils/functional/object.ts +279 -0
  170. package/src/utils/functional/string.ts +281 -0
  171. package/src/utils/functional.ts +543 -0
  172. package/src/utils/help.ts +20 -0
  173. package/src/utils/immutable-cache.ts +106 -0
  174. package/src/utils/index.ts +78 -0
  175. package/src/utils/jsonc.ts +158 -0
  176. package/src/utils/logger.ts +396 -0
  177. package/src/utils/mcp-config.ts +249 -0
  178. package/src/utils/memory-tui.ts +414 -0
  179. package/src/utils/models-dev.ts +91 -0
  180. package/src/utils/notifications.ts +169 -0
  181. package/src/utils/object-utils.ts +51 -0
  182. package/src/utils/parallel-operations.ts +487 -0
  183. package/src/utils/paths.ts +143 -0
  184. package/src/utils/process-manager.ts +155 -0
  185. package/src/utils/prompts.ts +120 -0
  186. package/src/utils/search-tool-builder.ts +214 -0
  187. package/src/utils/secret-utils.ts +179 -0
  188. package/src/utils/security.ts +537 -0
  189. package/src/utils/session-manager.ts +168 -0
  190. package/src/utils/session-title.ts +87 -0
  191. package/src/utils/settings.ts +182 -0
  192. package/src/utils/simplified-errors.ts +410 -0
  193. package/src/utils/sync-utils.ts +159 -0
  194. package/src/utils/target-config.ts +570 -0
  195. package/src/utils/target-utils.ts +394 -0
  196. package/src/utils/template-engine.ts +94 -0
  197. package/src/utils/test-audio.ts +71 -0
  198. package/src/utils/todo-context.ts +46 -0
  199. package/src/utils/token-counter.ts +288 -0
  200. package/dist/index.d.ts +0 -10
  201. package/dist/index.js +0 -59554
  202. package/dist/lancedb.linux-x64-gnu-b7f0jgsz.node +0 -0
  203. package/dist/lancedb.linux-x64-musl-tgcv22rx.node +0 -0
  204. package/dist/shared/chunk-25dwp0dp.js +0 -89
  205. package/dist/shared/chunk-3pjb6063.js +0 -208
  206. package/dist/shared/chunk-4d6ydpw7.js +0 -2854
  207. package/dist/shared/chunk-4wjcadjk.js +0 -225
  208. package/dist/shared/chunk-5j4w74t6.js +0 -30
  209. package/dist/shared/chunk-5j8m3dh3.js +0 -58
  210. package/dist/shared/chunk-5thh3qem.js +0 -91
  211. package/dist/shared/chunk-6g9xy73m.js +0 -252
  212. package/dist/shared/chunk-7eq34c42.js +0 -23
  213. package/dist/shared/chunk-c2gwgx3r.js +0 -115
  214. package/dist/shared/chunk-cjd3mk4c.js +0 -1320
  215. package/dist/shared/chunk-g5cv6703.js +0 -368
  216. package/dist/shared/chunk-hpkhykhq.js +0 -574
  217. package/dist/shared/chunk-m2322pdk.js +0 -122
  218. package/dist/shared/chunk-nd5fdvaq.js +0 -26
  219. package/dist/shared/chunk-pgd3m6zf.js +0 -108
  220. package/dist/shared/chunk-qk8n91hw.js +0 -494
  221. package/dist/shared/chunk-rkkn8szp.js +0 -16855
  222. package/dist/shared/chunk-t16rfxh0.js +0 -61
  223. package/dist/shared/chunk-t4fbfa5v.js +0 -19
  224. package/dist/shared/chunk-t77h86w6.js +0 -276
  225. package/dist/shared/chunk-v0ez4aef.js +0 -71
  226. package/dist/shared/chunk-v29j2r3s.js +0 -32051
  227. package/dist/shared/chunk-vfbc6ew5.js +0 -765
  228. package/dist/shared/chunk-vmeqwm1c.js +0 -204
  229. package/dist/shared/chunk-x66eh37x.js +0 -137
@@ -0,0 +1,448 @@
1
+ import { z } from 'zod';
2
+
3
+ // ============================================================================
4
+ // MCP SERVER CONFIGURATION INTERFACES
5
+ // ============================================================================
6
+
7
+ /**
8
+ * Base MCP server configuration with common fields
9
+ */
10
+ export interface BaseMCPServerConfig {
11
+ /** Server identifier */
12
+ id?: string;
13
+ /** Server name */
14
+ name?: string;
15
+ /** Server description */
16
+ description?: string;
17
+ /** Whether the server is enabled */
18
+ enabled?: boolean;
19
+ /** Server tags for categorization */
20
+ tags?: string[];
21
+ /** Custom server properties */
22
+ properties?: Record<string, unknown>;
23
+ }
24
+
25
+ /**
26
+ * Enhanced MCP server configuration for stdio type
27
+ */
28
+ export interface EnhancedMCPServerConfig extends BaseMCPServerConfig {
29
+ type: 'stdio';
30
+ /** Command to execute */
31
+ command: string;
32
+ /** Command arguments */
33
+ args?: string[];
34
+ /** Environment variables */
35
+ env?: Record<string, string>;
36
+ /** Working directory */
37
+ cwd?: string;
38
+ /** Timeout in milliseconds */
39
+ timeout?: number;
40
+ /** Retry configuration */
41
+ retry?: {
42
+ attempts?: number;
43
+ delay?: number;
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Enhanced MCP server configuration for HTTP type
49
+ */
50
+ export interface EnhancedMCPServerConfigHTTP extends BaseMCPServerConfig {
51
+ type: 'http';
52
+ /** Server URL */
53
+ url: string;
54
+ /** HTTP headers */
55
+ headers?: Record<string, string>;
56
+ /** Authentication configuration */
57
+ auth?: {
58
+ type: 'bearer' | 'basic' | 'api-key';
59
+ token?: string;
60
+ username?: string;
61
+ password?: string;
62
+ apiKey?: string;
63
+ };
64
+ /** Request timeout */
65
+ timeout?: number;
66
+ /** SSL configuration */
67
+ ssl?: {
68
+ rejectUnauthorized?: boolean;
69
+ cert?: string;
70
+ key?: string;
71
+ ca?: string;
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Enhanced MCP server configuration for legacy local type
77
+ */
78
+ export interface EnhancedMCPServerConfigLegacy extends BaseMCPServerConfig {
79
+ type: 'local';
80
+ /** Command and arguments as array */
81
+ command: string[];
82
+ /** Environment variables */
83
+ environment?: Record<string, string>;
84
+ /** Working directory */
85
+ cwd?: string;
86
+ /** Shell configuration */
87
+ shell?: boolean | string;
88
+ }
89
+
90
+ /**
91
+ * Enhanced MCP server configuration for legacy remote type
92
+ */
93
+ export interface EnhancedMCPServerConfigHTTPLegacy extends BaseMCPServerConfig {
94
+ type: 'remote';
95
+ /** Server URL */
96
+ url: string;
97
+ /** HTTP headers */
98
+ headers?: Record<string, string>;
99
+ /** Authentication information */
100
+ auth?: Record<string, string>;
101
+ /** Request timeout */
102
+ timeout?: number;
103
+ }
104
+
105
+ /**
106
+ * Union type for all enhanced MCP server configurations
107
+ */
108
+ export type EnhancedMCPServerConfigUnion =
109
+ | EnhancedMCPServerConfig
110
+ | EnhancedMCPServerConfigHTTP
111
+ | EnhancedMCPServerConfigLegacy
112
+ | EnhancedMCPServerConfigHTTPLegacy;
113
+
114
+ /**
115
+ * MCP server registry configuration
116
+ */
117
+ export interface MCPServerRegistryConfig {
118
+ /** Registry name */
119
+ name: string;
120
+ /** Registry URL */
121
+ url: string;
122
+ /** Authentication configuration */
123
+ auth?: {
124
+ type: 'bearer' | 'basic';
125
+ token?: string;
126
+ username?: string;
127
+ password?: string;
128
+ };
129
+ /** Cache configuration */
130
+ cache?: {
131
+ enabled?: boolean;
132
+ ttl?: number;
133
+ maxSize?: number;
134
+ };
135
+ /** Registry metadata */
136
+ metadata?: Record<string, unknown>;
137
+ }
138
+
139
+ /**
140
+ * MCP server transformation options
141
+ */
142
+ export interface MCPTransformationOptions {
143
+ /** Target server ID */
144
+ serverId?: string;
145
+ /** Target environment */
146
+ environment?: 'development' | 'production' | 'testing';
147
+ /** Whether to validate configuration */
148
+ validate?: boolean;
149
+ /** Whether to normalize configuration */
150
+ normalize?: boolean;
151
+ /** Custom transformation rules */
152
+ rules?: TransformationRule[];
153
+ }
154
+
155
+ /**
156
+ * Transformation rule for MCP configurations
157
+ */
158
+ export interface TransformationRule {
159
+ /** Rule name */
160
+ name: string;
161
+ /** Rule type */
162
+ type: 'map' | 'filter' | 'validate' | 'transform';
163
+ /** Rule condition */
164
+ condition?: (config: EnhancedMCPServerConfigUnion) => boolean;
165
+ /** Rule transformation function */
166
+ transform: (config: EnhancedMCPServerConfigUnion) => EnhancedMCPServerConfigUnion;
167
+ /** Rule priority */
168
+ priority?: number;
169
+ }
170
+
171
+ /**
172
+ * MCP server validation result
173
+ */
174
+ export interface MCPServerValidationResult {
175
+ /** Whether validation passed */
176
+ isValid: boolean;
177
+ /** Validated configuration */
178
+ config?: EnhancedMCPServerConfigUnion;
179
+ /** Validation errors */
180
+ errors: string[];
181
+ /** Validation warnings */
182
+ warnings: string[];
183
+ /** Validation metadata */
184
+ metadata?: {
185
+ validatedAt: string;
186
+ validatorVersion: string;
187
+ };
188
+ }
189
+
190
+ // ============================================================================
191
+ // ZOD SCHEMAS FOR RUNTIME VALIDATION
192
+ // ============================================================================
193
+
194
+ /**
195
+ * Base schema for MCP server configurations
196
+ */
197
+ const BaseMCPServerConfigSchema = z.object({
198
+ id: z.string().optional(),
199
+ name: z.string().optional(),
200
+ description: z.string().optional(),
201
+ enabled: z.boolean().optional(),
202
+ tags: z.array(z.string()).optional(),
203
+ properties: z.record(z.unknown()).optional(),
204
+ });
205
+
206
+ /**
207
+ * Zod schema for EnhancedMCPServerConfig
208
+ */
209
+ export const EnhancedMCPServerConfigSchema = BaseMCPServerConfigSchema.extend({
210
+ type: z.literal('stdio'),
211
+ command: z.string(),
212
+ args: z.array(z.string()).optional(),
213
+ env: z.record(z.string()).optional(),
214
+ cwd: z.string().optional(),
215
+ timeout: z.number().optional(),
216
+ retry: z
217
+ .object({
218
+ attempts: z.number().optional(),
219
+ delay: z.number().optional(),
220
+ })
221
+ .optional(),
222
+ });
223
+
224
+ /**
225
+ * Zod schema for EnhancedMCPServerConfigHTTP
226
+ */
227
+ export const EnhancedMCPServerConfigHTTPSchema = BaseMCPServerConfigSchema.extend({
228
+ type: z.literal('http'),
229
+ url: z.string().url(),
230
+ headers: z.record(z.string()).optional(),
231
+ auth: z
232
+ .object({
233
+ type: z.enum(['bearer', 'basic', 'api-key']),
234
+ token: z.string().optional(),
235
+ username: z.string().optional(),
236
+ password: z.string().optional(),
237
+ apiKey: z.string().optional(),
238
+ })
239
+ .optional(),
240
+ timeout: z.number().optional(),
241
+ ssl: z
242
+ .object({
243
+ rejectUnauthorized: z.boolean().optional(),
244
+ cert: z.string().optional(),
245
+ key: z.string().optional(),
246
+ ca: z.string().optional(),
247
+ })
248
+ .optional(),
249
+ });
250
+
251
+ /**
252
+ * Zod schema for EnhancedMCPServerConfigLegacy
253
+ */
254
+ export const EnhancedMCPServerConfigLegacySchema = BaseMCPServerConfigSchema.extend({
255
+ type: z.literal('local'),
256
+ command: z.array(z.string()),
257
+ environment: z.record(z.string()).optional(),
258
+ cwd: z.string().optional(),
259
+ shell: z.union([z.boolean(), z.string()]).optional(),
260
+ });
261
+
262
+ /**
263
+ * Zod schema for EnhancedMCPServerConfigHTTPLegacy
264
+ */
265
+ export const EnhancedMCPServerConfigHTTPLegacySchema = BaseMCPServerConfigSchema.extend({
266
+ type: z.literal('remote'),
267
+ url: z.string().url(),
268
+ headers: z.record(z.string()).optional(),
269
+ auth: z.record(z.string()).optional(),
270
+ timeout: z.number().optional(),
271
+ });
272
+
273
+ /**
274
+ * Zod schema for EnhancedMCPServerConfigUnion
275
+ */
276
+ export const EnhancedMCPServerConfigUnionSchema = z.discriminatedUnion('type', [
277
+ EnhancedMCPServerConfigSchema,
278
+ EnhancedMCPServerConfigHTTPSchema,
279
+ EnhancedMCPServerConfigLegacySchema,
280
+ EnhancedMCPServerConfigHTTPLegacySchema,
281
+ ]);
282
+
283
+ /**
284
+ * Zod schema for MCPServerRegistryConfig
285
+ */
286
+ export const MCPServerRegistryConfigSchema = z.object({
287
+ name: z.string(),
288
+ url: z.string().url(),
289
+ auth: z
290
+ .object({
291
+ type: z.enum(['bearer', 'basic']),
292
+ token: z.string().optional(),
293
+ username: z.string().optional(),
294
+ password: z.string().optional(),
295
+ })
296
+ .optional(),
297
+ cache: z
298
+ .object({
299
+ enabled: z.boolean().optional(),
300
+ ttl: z.number().optional(),
301
+ maxSize: z.number().optional(),
302
+ })
303
+ .optional(),
304
+ metadata: z.record(z.unknown()).optional(),
305
+ });
306
+
307
+ /**
308
+ * Zod schema for MCPTransformationOptions
309
+ */
310
+ export const MCPTransformationOptionsSchema = z.object({
311
+ serverId: z.string().optional(),
312
+ environment: z.enum(['development', 'production', 'testing']).optional(),
313
+ validate: z.boolean().optional(),
314
+ normalize: z.boolean().optional(),
315
+ rules: z
316
+ .array(
317
+ z.object({
318
+ name: z.string(),
319
+ type: z.enum(['map', 'filter', 'validate', 'transform']),
320
+ condition: z.function().optional(),
321
+ transform: z.function(),
322
+ priority: z.number().optional(),
323
+ })
324
+ )
325
+ .optional(),
326
+ });
327
+
328
+ /**
329
+ * Zod schema for MCPServerValidationResult
330
+ */
331
+ export const MCPServerValidationResultSchema = z.object({
332
+ isValid: z.boolean(),
333
+ config: EnhancedMCPServerConfigUnionSchema.optional(),
334
+ errors: z.array(z.string()),
335
+ warnings: z.array(z.string()),
336
+ metadata: z
337
+ .object({
338
+ validatedAt: z.string(),
339
+ validatorVersion: z.string(),
340
+ })
341
+ .optional(),
342
+ });
343
+
344
+ // ============================================================================
345
+ // TYPE GUARDS FOR RUNTIME TYPE CHECKING
346
+ // ============================================================================
347
+
348
+ /**
349
+ * Type guard to check if value is EnhancedMCPServerConfig
350
+ */
351
+ export function isEnhancedMCPServerConfig(value: unknown): value is EnhancedMCPServerConfig {
352
+ return EnhancedMCPServerConfigSchema.safeParse(value).success;
353
+ }
354
+
355
+ /**
356
+ * Type guard to check if value is EnhancedMCPServerConfigHTTP
357
+ */
358
+ export function isEnhancedMCPServerConfigHTTP(
359
+ value: unknown
360
+ ): value is EnhancedMCPServerConfigHTTP {
361
+ return EnhancedMCPServerConfigHTTPSchema.safeParse(value).success;
362
+ }
363
+
364
+ /**
365
+ * Type guard to check if value is EnhancedMCPServerConfigLegacy
366
+ */
367
+ export function isEnhancedMCPServerConfigLegacy(
368
+ value: unknown
369
+ ): value is EnhancedMCPServerConfigLegacy {
370
+ return EnhancedMCPServerConfigLegacySchema.safeParse(value).success;
371
+ }
372
+
373
+ /**
374
+ * Type guard to check if value is EnhancedMCPServerConfigHTTPLegacy
375
+ */
376
+ export function isEnhancedMCPServerConfigHTTPLegacy(
377
+ value: unknown
378
+ ): value is EnhancedMCPServerConfigHTTPLegacy {
379
+ return EnhancedMCPServerConfigHTTPLegacySchema.safeParse(value).success;
380
+ }
381
+
382
+ /**
383
+ * Type guard to check if value is EnhancedMCPServerConfigUnion
384
+ */
385
+ export function isEnhancedMCPServerConfigUnion(
386
+ value: unknown
387
+ ): value is EnhancedMCPServerConfigUnion {
388
+ return EnhancedMCPServerConfigUnionSchema.safeParse(value).success;
389
+ }
390
+
391
+ /**
392
+ * Type guard to check if value is MCPServerRegistryConfig
393
+ */
394
+ export function isMCPServerRegistryConfig(value: unknown): value is MCPServerRegistryConfig {
395
+ return MCPServerRegistryConfigSchema.safeParse(value).success;
396
+ }
397
+
398
+ /**
399
+ * Type guard to check if value is MCPServerValidationResult
400
+ */
401
+ export function isMCPServerValidationResult(value: unknown): value is MCPServerValidationResult {
402
+ return MCPServerValidationResultSchema.safeParse(value).success;
403
+ }
404
+
405
+ // ============================================================================
406
+ // UTILITY FUNCTIONS
407
+ // ============================================================================
408
+
409
+ /**
410
+ * Validate MCP server configuration
411
+ */
412
+ export function validateMCPServerConfig(config: unknown): MCPServerValidationResult {
413
+ const result = EnhancedMCPServerConfigUnionSchema.safeParse(config);
414
+
415
+ if (result.success) {
416
+ return {
417
+ isValid: true,
418
+ config: result.data,
419
+ errors: [],
420
+ warnings: [],
421
+ metadata: {
422
+ validatedAt: new Date().toISOString(),
423
+ validatorVersion: '1.0.0',
424
+ },
425
+ };
426
+ }
427
+ return {
428
+ isValid: false,
429
+ errors: result.error.errors.map((e) => `${e.path.join('.')}: ${e.message}`),
430
+ warnings: [],
431
+ metadata: {
432
+ validatedAt: new Date().toISOString(),
433
+ validatorVersion: '1.0.0',
434
+ },
435
+ };
436
+ }
437
+
438
+ /**
439
+ * Transform legacy MCP config to enhanced config
440
+ */
441
+ export function transformLegacyToEnhanced(
442
+ legacyConfig: unknown
443
+ ): EnhancedMCPServerConfigUnion | null {
444
+ // This would contain the transformation logic
445
+ // For now, just validate and return if valid
446
+ const result = EnhancedMCPServerConfigUnionSchema.safeParse(legacyConfig);
447
+ return result.success ? result.data : null;
448
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * MCP (Model Context Protocol) configuration types
3
+ * Types for configuring and managing MCP servers
4
+ */
5
+
6
+ import type { Resolvable } from './common.types.js';
7
+
8
+ /**
9
+ * MCP server configuration for stdio-based servers
10
+ * Communicates via standard input/output
11
+ */
12
+ export interface MCPServerConfig {
13
+ type: 'stdio';
14
+ command: Resolvable<string>;
15
+ args?: Resolvable<string[]>;
16
+ env?: Record<string, string>;
17
+ }
18
+
19
+ /**
20
+ * MCP server configuration for HTTP-based servers
21
+ * Communicates via HTTP requests
22
+ */
23
+ export interface MCPServerConfigHTTP {
24
+ type: 'http';
25
+ url: Resolvable<string>;
26
+ headers?: Record<string, string>;
27
+ }
28
+
29
+ /**
30
+ * Union of all possible MCP server configurations
31
+ */
32
+ export type MCPServerConfigUnion = MCPServerConfig | MCPServerConfigHTTP;
33
+
34
+ /**
35
+ * MCP server configuration flags
36
+ * Used to disable specific server features per target
37
+ */
38
+ export type MCPServerConfigFlags = {
39
+ disableTime?: boolean;
40
+ disableKnowledge?: boolean;
41
+ disableCodebase?: boolean;
42
+ };
43
+
44
+ /**
45
+ * OpenCode-specific configuration format
46
+ */
47
+ export interface OpenCodeConfig {
48
+ $schema?: string;
49
+ mcp?: Record<string, MCPServerConfigUnion>;
50
+ }
51
+
52
+ /**
53
+ * Type guard: Check if config is stdio-based
54
+ */
55
+ export const isStdioConfig = (config: MCPServerConfigUnion): config is MCPServerConfig =>
56
+ config.type === 'stdio';
57
+
58
+ /**
59
+ * Type guard: Check if config is HTTP-based
60
+ */
61
+ export const isHttpConfig = (config: MCPServerConfigUnion): config is MCPServerConfigHTTP =>
62
+ config.type === 'http';
63
+
64
+ /**
65
+ * Type guard: Check if config is CLI command-based (stdio)
66
+ * Alias for isStdioConfig for backward compatibility
67
+ */
68
+ export const isCLICommandConfig = (config: MCPServerConfigUnion): config is MCPServerConfig =>
69
+ isStdioConfig(config);
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Memory Service Types
3
+ * Value types for functional memory operations
4
+ */
5
+
6
+ /**
7
+ * Metadata for memory entries
8
+ */
9
+ export interface MemoryMetadata {
10
+ readonly namespace: string;
11
+ readonly timestamp: number;
12
+ readonly size: number;
13
+ }
14
+
15
+ /**
16
+ * Memory value with metadata
17
+ * Used as success value in Result<MemoryValue, E>
18
+ */
19
+ export interface MemoryValue {
20
+ readonly value: string;
21
+ readonly metadata: MemoryMetadata;
22
+ }
23
+
24
+ /**
25
+ * Result of listing memory entries
26
+ */
27
+ export interface MemoryListResult {
28
+ readonly entries: ReadonlyArray<{
29
+ readonly key: string;
30
+ readonly value: string;
31
+ readonly namespace: string;
32
+ readonly timestamp: number;
33
+ }>;
34
+ readonly metadata: {
35
+ readonly namespace: string;
36
+ readonly count: number;
37
+ readonly totalSize: number;
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Result of memory statistics
43
+ */
44
+ export interface MemoryStatsResult {
45
+ readonly totalEntries: number;
46
+ readonly totalSize: number;
47
+ readonly namespaces: ReadonlyArray<{
48
+ readonly name: string;
49
+ readonly count: number;
50
+ readonly oldestTimestamp?: number;
51
+ readonly newestTimestamp?: number;
52
+ }>;
53
+ }
54
+
55
+ /**
56
+ * Memory entry for cache storage
57
+ */
58
+ export interface CachedMemoryEntry {
59
+ readonly key: string;
60
+ readonly value: string;
61
+ readonly namespace: string;
62
+ readonly timestamp: number;
63
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Provider Type Definitions
3
+ * Shared types to prevent circular dependencies
4
+ *
5
+ * This file contains only type definitions with no imports,
6
+ * allowing it to be safely imported from anywhere.
7
+ */
8
+
9
+ /**
10
+ * Provider IDs
11
+ * All supported AI providers
12
+ */
13
+ export type ProviderId =
14
+ | 'anthropic'
15
+ | 'openai'
16
+ | 'google'
17
+ | 'openrouter'
18
+ | 'claude-code'
19
+ | 'zai';
20
+
21
+ /**
22
+ * Provider configuration value
23
+ * Generic provider config interface
24
+ */
25
+ export interface ProviderConfigValue {
26
+ defaultModel?: string;
27
+ [key: string]: string | number | boolean | undefined;
28
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Rule Types
3
+ * Defines shared system prompt rules that apply to all agents
4
+ */
5
+
6
+ /**
7
+ * Rule metadata from front matter
8
+ */
9
+ export interface RuleMetadata {
10
+ name: string;
11
+ description: string;
12
+ enabled?: boolean; // Default enabled state
13
+ }
14
+
15
+ /**
16
+ * Rule definition
17
+ */
18
+ export interface Rule {
19
+ id: string; // File path relative to rules directory (e.g., 'coding/typescript')
20
+ metadata: RuleMetadata;
21
+ content: string; // Rule content to add to system prompt
22
+ isBuiltin: boolean; // Whether this is a system-provided rule
23
+ filePath?: string; // Path to the rule file
24
+ }