claude-brain 0.3.0

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 (200) hide show
  1. package/README.md +157 -0
  2. package/VERSION +1 -0
  3. package/assets/CLAUDE.md +307 -0
  4. package/bunfig.toml +8 -0
  5. package/package.json +74 -0
  6. package/src/automation/auto-context.ts +240 -0
  7. package/src/automation/decision-detector.ts +452 -0
  8. package/src/automation/index.ts +11 -0
  9. package/src/automation/proactive-recall.ts +373 -0
  10. package/src/automation/project-detector.ts +297 -0
  11. package/src/cli/auto-setup.ts +74 -0
  12. package/src/cli/bin.ts +110 -0
  13. package/src/cli/commands/install-mcp.ts +50 -0
  14. package/src/cli/commands/serve.ts +129 -0
  15. package/src/cli/diagnose.ts +4 -0
  16. package/src/cli/health-check.ts +4 -0
  17. package/src/cli/migrate-chroma.ts +106 -0
  18. package/src/cli/setup.ts +4 -0
  19. package/src/config/defaults.ts +47 -0
  20. package/src/config/home.ts +55 -0
  21. package/src/config/index.ts +7 -0
  22. package/src/config/loader.ts +166 -0
  23. package/src/config/migration.ts +76 -0
  24. package/src/config/schema.ts +257 -0
  25. package/src/config/validator.ts +184 -0
  26. package/src/config/watcher.ts +86 -0
  27. package/src/context/assembler.ts +398 -0
  28. package/src/context/cache-manager.ts +101 -0
  29. package/src/context/formatter.ts +84 -0
  30. package/src/context/hierarchy.ts +85 -0
  31. package/src/context/index.ts +83 -0
  32. package/src/context/progress-tracker.ts +174 -0
  33. package/src/context/standards-manager.ts +267 -0
  34. package/src/context/types.ts +252 -0
  35. package/src/context/validator.ts +58 -0
  36. package/src/cross-project/affinity.ts +162 -0
  37. package/src/cross-project/generalizer.ts +283 -0
  38. package/src/cross-project/index.ts +13 -0
  39. package/src/cross-project/transfer.ts +201 -0
  40. package/src/diagnostics/index.ts +123 -0
  41. package/src/health/index.ts +229 -0
  42. package/src/index.ts +7 -0
  43. package/src/knowledge/entity-extractor.ts +416 -0
  44. package/src/knowledge/graph/builder.ts +159 -0
  45. package/src/knowledge/graph/linker.ts +201 -0
  46. package/src/knowledge/graph/memory-graph.ts +359 -0
  47. package/src/knowledge/graph/schema.ts +99 -0
  48. package/src/knowledge/graph/search.ts +168 -0
  49. package/src/knowledge/relationship-extractor.ts +108 -0
  50. package/src/memory/chroma/client.ts +169 -0
  51. package/src/memory/chroma/collection-manager.ts +94 -0
  52. package/src/memory/chroma/config.ts +46 -0
  53. package/src/memory/chroma/embeddings.ts +153 -0
  54. package/src/memory/chroma/index.ts +82 -0
  55. package/src/memory/chroma/migration.ts +270 -0
  56. package/src/memory/chroma/schemas.ts +69 -0
  57. package/src/memory/chroma/search.ts +315 -0
  58. package/src/memory/chroma/store.ts +694 -0
  59. package/src/memory/consolidation/archiver.ts +164 -0
  60. package/src/memory/consolidation/merger.ts +186 -0
  61. package/src/memory/consolidation/scorer.ts +138 -0
  62. package/src/memory/context-builder.ts +236 -0
  63. package/src/memory/database.ts +169 -0
  64. package/src/memory/embedding-utils.ts +156 -0
  65. package/src/memory/embeddings.ts +226 -0
  66. package/src/memory/episodic/detector.ts +108 -0
  67. package/src/memory/episodic/manager.ts +334 -0
  68. package/src/memory/episodic/summarizer.ts +179 -0
  69. package/src/memory/episodic/types.ts +52 -0
  70. package/src/memory/index.ts +395 -0
  71. package/src/memory/knowledge-extractor.ts +455 -0
  72. package/src/memory/learning.ts +378 -0
  73. package/src/memory/patterns.ts +396 -0
  74. package/src/memory/schema.ts +56 -0
  75. package/src/memory/search.ts +309 -0
  76. package/src/memory/store.ts +344 -0
  77. package/src/memory/types.ts +121 -0
  78. package/src/optimization/index.ts +10 -0
  79. package/src/optimization/precompute.ts +202 -0
  80. package/src/optimization/semantic-cache.ts +207 -0
  81. package/src/orchestrator/coordinator.ts +272 -0
  82. package/src/orchestrator/decision-logger.ts +228 -0
  83. package/src/orchestrator/event-emitter.ts +198 -0
  84. package/src/orchestrator/event-queue.ts +184 -0
  85. package/src/orchestrator/handlers/base-handler.ts +70 -0
  86. package/src/orchestrator/handlers/context-handler.ts +73 -0
  87. package/src/orchestrator/handlers/decision-handler.ts +204 -0
  88. package/src/orchestrator/handlers/index.ts +10 -0
  89. package/src/orchestrator/handlers/status-handler.ts +131 -0
  90. package/src/orchestrator/handlers/task-handler.ts +171 -0
  91. package/src/orchestrator/index.ts +275 -0
  92. package/src/orchestrator/task-parser.ts +284 -0
  93. package/src/orchestrator/types.ts +98 -0
  94. package/src/phase12/index.ts +456 -0
  95. package/src/prediction/context-anticipator.ts +198 -0
  96. package/src/prediction/decision-predictor.ts +184 -0
  97. package/src/prediction/index.ts +13 -0
  98. package/src/prediction/recommender.ts +268 -0
  99. package/src/reasoning/chain-retrieval.ts +247 -0
  100. package/src/reasoning/counterfactual.ts +248 -0
  101. package/src/reasoning/index.ts +13 -0
  102. package/src/reasoning/synthesizer.ts +169 -0
  103. package/src/retrieval/bm25/index.ts +300 -0
  104. package/src/retrieval/bm25/tokenizer.ts +184 -0
  105. package/src/retrieval/feedback/adaptive.ts +223 -0
  106. package/src/retrieval/feedback/index.ts +16 -0
  107. package/src/retrieval/feedback/metrics.ts +223 -0
  108. package/src/retrieval/feedback/store.ts +283 -0
  109. package/src/retrieval/fusion/index.ts +194 -0
  110. package/src/retrieval/fusion/rrf.ts +163 -0
  111. package/src/retrieval/index.ts +12 -0
  112. package/src/retrieval/pipeline.ts +375 -0
  113. package/src/retrieval/query/expander.ts +198 -0
  114. package/src/retrieval/query/index.ts +27 -0
  115. package/src/retrieval/query/intent-classifier.ts +236 -0
  116. package/src/retrieval/query/temporal-parser.ts +295 -0
  117. package/src/retrieval/reranker/index.ts +188 -0
  118. package/src/retrieval/reranker/model.ts +95 -0
  119. package/src/retrieval/service.ts +125 -0
  120. package/src/retrieval/types.ts +162 -0
  121. package/src/scripts/health-check.ts +118 -0
  122. package/src/scripts/setup.ts +122 -0
  123. package/src/server/handlers/call-tool.ts +194 -0
  124. package/src/server/handlers/index.ts +9 -0
  125. package/src/server/handlers/list-tools.ts +18 -0
  126. package/src/server/handlers/tools/analyze-decision-evolution.ts +71 -0
  127. package/src/server/handlers/tools/auto-remember.ts +200 -0
  128. package/src/server/handlers/tools/create-project.ts +135 -0
  129. package/src/server/handlers/tools/detect-trends.ts +80 -0
  130. package/src/server/handlers/tools/find-cross-project-patterns.ts +73 -0
  131. package/src/server/handlers/tools/get-activity-log.ts +194 -0
  132. package/src/server/handlers/tools/get-code-standards.ts +124 -0
  133. package/src/server/handlers/tools/get-corrections.ts +154 -0
  134. package/src/server/handlers/tools/get-decision-timeline.ts +86 -0
  135. package/src/server/handlers/tools/get-episode.ts +93 -0
  136. package/src/server/handlers/tools/get-patterns.ts +158 -0
  137. package/src/server/handlers/tools/get-phase12-status.ts +63 -0
  138. package/src/server/handlers/tools/get-project-context.ts +75 -0
  139. package/src/server/handlers/tools/get-recommendations.ts +65 -0
  140. package/src/server/handlers/tools/index.ts +33 -0
  141. package/src/server/handlers/tools/init-project.ts +710 -0
  142. package/src/server/handlers/tools/list-episodes.ts +80 -0
  143. package/src/server/handlers/tools/list-projects.ts +125 -0
  144. package/src/server/handlers/tools/rate-memory.ts +95 -0
  145. package/src/server/handlers/tools/recall-similar.ts +87 -0
  146. package/src/server/handlers/tools/recognize-pattern.ts +126 -0
  147. package/src/server/handlers/tools/record-correction.ts +125 -0
  148. package/src/server/handlers/tools/remember-decision.ts +153 -0
  149. package/src/server/handlers/tools/schemas.ts +241 -0
  150. package/src/server/handlers/tools/search-knowledge-graph.ts +89 -0
  151. package/src/server/handlers/tools/smart-context.ts +124 -0
  152. package/src/server/handlers/tools/update-progress.ts +114 -0
  153. package/src/server/handlers/tools/what-if-analysis.ts +73 -0
  154. package/src/server/http-api.ts +474 -0
  155. package/src/server/index.ts +40 -0
  156. package/src/server/mcp-server.ts +283 -0
  157. package/src/server/providers/index.ts +7 -0
  158. package/src/server/providers/prompts.ts +327 -0
  159. package/src/server/providers/resources.ts +427 -0
  160. package/src/server/services.ts +388 -0
  161. package/src/server/types.ts +39 -0
  162. package/src/server/utils/error-handler.ts +155 -0
  163. package/src/server/utils/index.ts +13 -0
  164. package/src/server/utils/memory-indicator.ts +83 -0
  165. package/src/server/utils/request-context.ts +122 -0
  166. package/src/server/utils/response-formatter.ts +124 -0
  167. package/src/server/utils/validators.ts +210 -0
  168. package/src/setup/index.ts +22 -0
  169. package/src/setup/wizard.ts +321 -0
  170. package/src/temporal/evolution.ts +197 -0
  171. package/src/temporal/index.ts +16 -0
  172. package/src/temporal/query-processor.ts +190 -0
  173. package/src/temporal/timeline.ts +259 -0
  174. package/src/temporal/trends.ts +263 -0
  175. package/src/tools/index.ts +24 -0
  176. package/src/tools/registry.ts +106 -0
  177. package/src/tools/schemas.test.ts +30 -0
  178. package/src/tools/schemas.ts +907 -0
  179. package/src/tools/types.ts +412 -0
  180. package/src/utils/circuit-breaker.ts +130 -0
  181. package/src/utils/cleanup.ts +34 -0
  182. package/src/utils/error-handler.ts +132 -0
  183. package/src/utils/error-messages.ts +60 -0
  184. package/src/utils/fallback.ts +45 -0
  185. package/src/utils/index.ts +54 -0
  186. package/src/utils/logger-utils.ts +80 -0
  187. package/src/utils/logger.ts +88 -0
  188. package/src/utils/phase12-helper.ts +56 -0
  189. package/src/utils/retry.ts +94 -0
  190. package/src/utils/transaction.ts +63 -0
  191. package/src/vault/frontmatter.ts +264 -0
  192. package/src/vault/index.ts +318 -0
  193. package/src/vault/paths.ts +106 -0
  194. package/src/vault/query.ts +422 -0
  195. package/src/vault/reader.ts +264 -0
  196. package/src/vault/templates.ts +186 -0
  197. package/src/vault/types.ts +73 -0
  198. package/src/vault/watcher.ts +277 -0
  199. package/src/vault/writer.ts +393 -0
  200. package/tsconfig.json +30 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Request Context
3
+ * Utilities for tracking request context and timing
4
+ */
5
+
6
+ import { randomUUID } from 'crypto'
7
+
8
+ /**
9
+ * RequestContext tracks information about a single request
10
+ */
11
+ export class RequestContext {
12
+ /** Unique identifier for this request */
13
+ readonly id: string
14
+
15
+ /** Timestamp when request started */
16
+ readonly startTime: number
17
+
18
+ /** Name of the tool being called (if applicable) */
19
+ readonly toolName?: string
20
+
21
+ /** Additional metadata for this request */
22
+ readonly metadata: Record<string, unknown>
23
+
24
+ /**
25
+ * Create a new RequestContext
26
+ * @param toolName - Optional tool name for this request
27
+ * @param metadata - Optional additional metadata
28
+ */
29
+ constructor(toolName?: string, metadata: Record<string, unknown> = {}) {
30
+ this.id = randomUUID()
31
+ this.startTime = Date.now()
32
+ this.toolName = toolName
33
+ this.metadata = metadata
34
+ }
35
+
36
+ /**
37
+ * Get the duration since request started
38
+ * @returns Duration in milliseconds
39
+ */
40
+ getDuration(): number {
41
+ return Date.now() - this.startTime
42
+ }
43
+
44
+ /**
45
+ * Get context information suitable for logging
46
+ * @returns Object with request context for logs
47
+ */
48
+ toLogContext(): Record<string, unknown> {
49
+ return {
50
+ requestId: this.id,
51
+ toolName: this.toolName,
52
+ durationMs: this.getDuration(),
53
+ ...this.metadata
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Create a child context with additional metadata
59
+ * @param additionalMetadata - Additional metadata to include
60
+ * @returns New context object for logging
61
+ */
62
+ withMetadata(additionalMetadata: Record<string, unknown>): Record<string, unknown> {
63
+ return {
64
+ ...this.toLogContext(),
65
+ ...additionalMetadata
66
+ }
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Timer for measuring operation duration
72
+ */
73
+ export class Timer {
74
+ private readonly startTime: number
75
+ private endTime?: number
76
+
77
+ constructor() {
78
+ this.startTime = performance.now()
79
+ }
80
+
81
+ /**
82
+ * Stop the timer
83
+ * @returns Duration in milliseconds
84
+ */
85
+ stop(): number {
86
+ this.endTime = performance.now()
87
+ return this.getDuration()
88
+ }
89
+
90
+ /**
91
+ * Get current duration (without stopping)
92
+ * @returns Duration in milliseconds
93
+ */
94
+ getDuration(): number {
95
+ const end = this.endTime ?? performance.now()
96
+ return Math.round(end - this.startTime)
97
+ }
98
+
99
+ /**
100
+ * Check if timer has been stopped
101
+ * @returns true if stopped
102
+ */
103
+ isStopped(): boolean {
104
+ return this.endTime !== undefined
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Create a new timer
110
+ * @returns Timer instance
111
+ */
112
+ export function createTimer(): Timer {
113
+ return new Timer()
114
+ }
115
+
116
+ /**
117
+ * Generate a short request ID
118
+ * @returns Short unique ID string
119
+ */
120
+ export function generateShortId(): string {
121
+ return `${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 9)}`
122
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Response Formatter
3
+ * Utilities for formatting MCP tool responses
4
+ */
5
+
6
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'
7
+ import type { ToolResponse } from '@/tools/types'
8
+
9
+ /**
10
+ * ResponseFormatter provides methods for creating properly formatted MCP responses
11
+ */
12
+ export class ResponseFormatter {
13
+ /**
14
+ * Format text content for MCP response
15
+ * @param content - Text content to include in response
16
+ * @returns Properly formatted ToolResponse
17
+ */
18
+ static text(content: string): ToolResponse {
19
+ return {
20
+ content: [{
21
+ type: 'text',
22
+ text: content
23
+ }]
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Format multiple text blocks for MCP response
29
+ * @param contents - Array of text content
30
+ * @returns Properly formatted ToolResponse with multiple content blocks
31
+ */
32
+ static multiText(contents: string[]): ToolResponse {
33
+ return {
34
+ content: contents.map(text => ({
35
+ type: 'text' as const,
36
+ text
37
+ }))
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Format error as MCP error (throws)
43
+ * @param message - Error message
44
+ * @param code - MCP error code
45
+ * @throws McpError
46
+ */
47
+ static error(message: string, code: ErrorCode = ErrorCode.InternalError): never {
48
+ throw new McpError(code, message)
49
+ }
50
+
51
+ /**
52
+ * Format error response (returns response with isError flag)
53
+ * @param message - Error message
54
+ * @returns ToolResponse with error flag
55
+ */
56
+ static errorResponse(message: string): ToolResponse {
57
+ return {
58
+ content: [{
59
+ type: 'text',
60
+ text: `Error: ${message}`
61
+ }],
62
+ isError: true
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Format structured data as formatted text
68
+ * @param data - Object to format
69
+ * @returns Properly formatted ToolResponse
70
+ */
71
+ static structured(data: Record<string, unknown>): ToolResponse {
72
+ const formatted = Object.entries(data)
73
+ .map(([key, value]) => {
74
+ const formattedValue = typeof value === 'object'
75
+ ? JSON.stringify(value, null, 2)
76
+ : String(value)
77
+ return `${key}: ${formattedValue}`
78
+ })
79
+ .join('\n\n')
80
+
81
+ return this.text(formatted)
82
+ }
83
+
84
+ /**
85
+ * Format JSON data as pretty-printed text
86
+ * @param data - Data to serialize as JSON
87
+ * @param label - Optional label to prefix the JSON
88
+ * @returns Properly formatted ToolResponse
89
+ */
90
+ static json(data: unknown, label?: string): ToolResponse {
91
+ const jsonStr = JSON.stringify(data, null, 2)
92
+ const content = label ? `${label}:\n${jsonStr}` : jsonStr
93
+ return this.text(content)
94
+ }
95
+
96
+ /**
97
+ * Format a list of items
98
+ * @param items - Array of items to format
99
+ * @param title - Optional title for the list
100
+ * @returns Properly formatted ToolResponse
101
+ */
102
+ static list(items: string[], title?: string): ToolResponse {
103
+ const listContent = items.map((item, i) => `${i + 1}. ${item}`).join('\n')
104
+ const content = title ? `${title}:\n${listContent}` : listContent
105
+ return this.text(content)
106
+ }
107
+
108
+ /**
109
+ * Format a success message
110
+ * @param message - Success message
111
+ * @param details - Optional additional details
112
+ * @returns Properly formatted ToolResponse
113
+ */
114
+ static success(message: string, details?: Record<string, unknown>): ToolResponse {
115
+ let content = `✓ ${message}`
116
+ if (details) {
117
+ const detailsStr = Object.entries(details)
118
+ .map(([k, v]) => ` ${k}: ${v}`)
119
+ .join('\n')
120
+ content += `\n\nDetails:\n${detailsStr}`
121
+ }
122
+ return this.text(content)
123
+ }
124
+ }
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Tool Validators
3
+ * Utilities for validating tool arguments
4
+ */
5
+
6
+ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'
7
+ import { z } from 'zod'
8
+
9
+ /**
10
+ * ToolValidator provides methods for validating tool inputs
11
+ */
12
+ export class ToolValidator {
13
+ /**
14
+ * Validate tool arguments against a Zod schema
15
+ * @param args - Arguments to validate
16
+ * @param schema - Zod schema to validate against
17
+ * @returns Parsed and validated arguments
18
+ * @throws McpError if validation fails
19
+ */
20
+ static validate<T>(args: unknown, schema: z.ZodSchema<T>): T {
21
+ try {
22
+ return schema.parse(args)
23
+ } catch (error) {
24
+ if (error instanceof z.ZodError) {
25
+ const issues = error.issues
26
+ .map(issue => `${issue.path.join('.')}: ${issue.message}`)
27
+ .join(', ')
28
+ throw new McpError(
29
+ ErrorCode.InvalidParams,
30
+ `Invalid parameters: ${issues}`
31
+ )
32
+ }
33
+ throw error
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Validate and return a required string parameter
39
+ * @param value - Value to validate
40
+ * @param name - Parameter name for error messages
41
+ * @returns Validated string
42
+ * @throws McpError if validation fails
43
+ */
44
+ static requireString(value: unknown, name: string): string {
45
+ if (typeof value !== 'string') {
46
+ throw new McpError(
47
+ ErrorCode.InvalidParams,
48
+ `${name} is required and must be a string`
49
+ )
50
+ }
51
+ if (value.trim() === '') {
52
+ throw new McpError(
53
+ ErrorCode.InvalidParams,
54
+ `${name} cannot be empty`
55
+ )
56
+ }
57
+ return value
58
+ }
59
+
60
+ /**
61
+ * Get an optional string parameter with default
62
+ * @param value - Value to check
63
+ * @param defaultValue - Default value if not provided
64
+ * @returns String value or default
65
+ * @throws McpError if value is present but not a string
66
+ */
67
+ static optionalString(value: unknown, defaultValue: string = ''): string {
68
+ if (value === undefined || value === null) {
69
+ return defaultValue
70
+ }
71
+ if (typeof value !== 'string') {
72
+ throw new McpError(
73
+ ErrorCode.InvalidParams,
74
+ 'Parameter must be a string'
75
+ )
76
+ }
77
+ return value
78
+ }
79
+
80
+ /**
81
+ * Validate and return a required number parameter
82
+ * @param value - Value to validate
83
+ * @param name - Parameter name for error messages
84
+ * @returns Validated number
85
+ * @throws McpError if validation fails
86
+ */
87
+ static requireNumber(value: unknown, name: string): number {
88
+ if (typeof value !== 'number' || isNaN(value)) {
89
+ throw new McpError(
90
+ ErrorCode.InvalidParams,
91
+ `${name} is required and must be a number`
92
+ )
93
+ }
94
+ return value
95
+ }
96
+
97
+ /**
98
+ * Get an optional number parameter with default
99
+ * @param value - Value to check
100
+ * @param defaultValue - Default value if not provided
101
+ * @returns Number value or default
102
+ * @throws McpError if value is present but not a number
103
+ */
104
+ static optionalNumber(value: unknown, defaultValue: number): number {
105
+ if (value === undefined || value === null) {
106
+ return defaultValue
107
+ }
108
+ if (typeof value !== 'number' || isNaN(value)) {
109
+ throw new McpError(
110
+ ErrorCode.InvalidParams,
111
+ 'Parameter must be a number'
112
+ )
113
+ }
114
+ return value
115
+ }
116
+
117
+ /**
118
+ * Validate and return a required boolean parameter
119
+ * @param value - Value to validate
120
+ * @param name - Parameter name for error messages
121
+ * @returns Validated boolean
122
+ * @throws McpError if validation fails
123
+ */
124
+ static requireBoolean(value: unknown, name: string): boolean {
125
+ if (typeof value !== 'boolean') {
126
+ throw new McpError(
127
+ ErrorCode.InvalidParams,
128
+ `${name} is required and must be a boolean`
129
+ )
130
+ }
131
+ return value
132
+ }
133
+
134
+ /**
135
+ * Get an optional boolean parameter with default
136
+ * @param value - Value to check
137
+ * @param defaultValue - Default value if not provided
138
+ * @returns Boolean value or default
139
+ */
140
+ static optionalBoolean(value: unknown, defaultValue: boolean): boolean {
141
+ if (value === undefined || value === null) {
142
+ return defaultValue
143
+ }
144
+ if (typeof value !== 'boolean') {
145
+ throw new McpError(
146
+ ErrorCode.InvalidParams,
147
+ 'Parameter must be a boolean'
148
+ )
149
+ }
150
+ return value
151
+ }
152
+
153
+ /**
154
+ * Validate and return a required array parameter
155
+ * @param value - Value to validate
156
+ * @param name - Parameter name for error messages
157
+ * @returns Validated array
158
+ * @throws McpError if validation fails
159
+ */
160
+ static requireArray<T>(value: unknown, name: string): T[] {
161
+ if (!Array.isArray(value)) {
162
+ throw new McpError(
163
+ ErrorCode.InvalidParams,
164
+ `${name} is required and must be an array`
165
+ )
166
+ }
167
+ return value as T[]
168
+ }
169
+
170
+ /**
171
+ * Get an optional array parameter with default
172
+ * @param value - Value to check
173
+ * @param defaultValue - Default value if not provided
174
+ * @returns Array value or default
175
+ */
176
+ static optionalArray<T>(value: unknown, defaultValue: T[] = []): T[] {
177
+ if (value === undefined || value === null) {
178
+ return defaultValue
179
+ }
180
+ if (!Array.isArray(value)) {
181
+ throw new McpError(
182
+ ErrorCode.InvalidParams,
183
+ 'Parameter must be an array'
184
+ )
185
+ }
186
+ return value as T[]
187
+ }
188
+
189
+ /**
190
+ * Validate value is one of allowed enum values
191
+ * @param value - Value to validate
192
+ * @param allowed - Array of allowed values
193
+ * @param name - Parameter name for error messages
194
+ * @returns Validated value
195
+ * @throws McpError if validation fails
196
+ */
197
+ static requireEnum<T extends string>(
198
+ value: unknown,
199
+ allowed: readonly T[],
200
+ name: string
201
+ ): T {
202
+ if (typeof value !== 'string' || !allowed.includes(value as T)) {
203
+ throw new McpError(
204
+ ErrorCode.InvalidParams,
205
+ `${name} must be one of: ${allowed.join(', ')}`
206
+ )
207
+ }
208
+ return value as T
209
+ }
210
+ }
@@ -0,0 +1,22 @@
1
+ import { createLogger } from '@/utils/logger'
2
+ import { resolveHomePath } from '@/config/home'
3
+ import { ensureHomeDirectory } from '@/cli/auto-setup'
4
+ import { SetupWizard } from './wizard'
5
+
6
+ export * from './wizard'
7
+
8
+ export async function runSetup() {
9
+ ensureHomeDirectory()
10
+
11
+ const logger = createLogger('info', resolveHomePath('./logs/setup.log'))
12
+
13
+ try {
14
+ const wizard = new SetupWizard(logger)
15
+ const answers = await wizard.run()
16
+ await wizard.applyConfiguration(answers)
17
+
18
+ } catch (error) {
19
+ console.error('\nSetup failed:', error)
20
+ process.exit(1)
21
+ }
22
+ }