@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,214 @@
1
+ /**
2
+ * Session Types
3
+ * Unified session and message types used across TUI and headless modes
4
+ */
5
+
6
+ import type { ProviderId } from '../config/ai-config.js';
7
+ import type { Todo } from './todo.types.js';
8
+
9
+ /**
10
+ * Message Part - unified type for all content parts
11
+ *
12
+ * ALL parts have status field to track their lifecycle state:
13
+ * - 'active': Being generated/processed
14
+ * - 'completed': Successfully finished
15
+ * - 'error': Failed with error
16
+ * - 'abort': User cancelled
17
+ *
18
+ * Design: No separate "StreamingPart" type needed
19
+ * - Streaming parts ARE message parts
20
+ * - Status field tracks state during and after streaming
21
+ * - No conversion required between streaming/stored formats
22
+ *
23
+ * Multiple parts can be active simultaneously (parallel tool calls).
24
+ */
25
+ export type MessagePart =
26
+ | {
27
+ type: 'text';
28
+ content: string;
29
+ status: 'active' | 'completed' | 'error' | 'abort';
30
+ }
31
+ | {
32
+ type: 'reasoning';
33
+ content: string;
34
+ status: 'active' | 'completed' | 'error' | 'abort';
35
+ duration?: number;
36
+ startTime?: number;
37
+ }
38
+ | {
39
+ type: 'tool';
40
+ toolId: string;
41
+ name: string;
42
+ status: 'active' | 'completed' | 'error' | 'abort';
43
+ args?: unknown;
44
+ result?: unknown;
45
+ error?: string;
46
+ duration?: number;
47
+ startTime?: number;
48
+ }
49
+ | {
50
+ type: 'error';
51
+ error: string;
52
+ status: 'completed'; // Errors are immediately completed
53
+ };
54
+
55
+ /**
56
+ * Legacy type alias for backwards compatibility
57
+ * @deprecated Use MessagePart directly
58
+ */
59
+ export type StreamingPart = MessagePart;
60
+
61
+ /**
62
+ * File attachment
63
+ */
64
+ export interface FileAttachment {
65
+ path: string;
66
+ relativePath: string;
67
+ size?: number;
68
+ }
69
+
70
+ /**
71
+ * Token usage statistics
72
+ */
73
+ export interface TokenUsage {
74
+ promptTokens: number;
75
+ completionTokens: number;
76
+ totalTokens: number;
77
+ }
78
+
79
+ /**
80
+ * Message metadata - system information at message creation time
81
+ *
82
+ * IMPORTANT: This metadata is captured ONCE when the message is created and NEVER changes.
83
+ * This is critical for prompt cache effectiveness - historical messages must remain immutable.
84
+ *
85
+ * Design decisions:
86
+ * 1. Stored separately from content - not shown in UI, only sent to LLM
87
+ * 2. Captured at creation time - never updated to preserve prompt cache
88
+ * 3. Used to build system status context when constructing ModelMessage for LLM
89
+ *
90
+ * What goes in metadata vs top-level fields:
91
+ * - metadata: Info for LLM but NOT shown in UI (cpu, memory, future: sessionId, requestId)
92
+ * - usage/finishReason: Info for UI/monitoring but NOT sent to LLM
93
+ * - timestamp: Shown in UI AND used to construct metadata for LLM
94
+ * - content: Shown in UI AND sent to LLM
95
+ */
96
+ export interface MessageMetadata {
97
+ cpu?: string; // CPU usage at creation time (e.g., "45.3% (8 cores)")
98
+ memory?: string; // Memory usage at creation time (e.g., "4.2GB/16.0GB")
99
+ // Future: add more fields as needed (sessionId, requestId, modelVersion, etc.)
100
+ }
101
+
102
+ /**
103
+ * Session message - Unified message type for both UI display and LLM consumption
104
+ *
105
+ * Design: Separation of UI display vs LLM context
106
+ * ================================================
107
+ *
108
+ * UI Display (what user sees):
109
+ * - content: MessagePart[] - Text, tool calls, reasoning, errors
110
+ * - timestamp: Display time
111
+ * - usage: Token counts for monitoring
112
+ * - attachments: Show file paths
113
+ *
114
+ * LLM Context (what AI sees):
115
+ * - content: Converted to ModelMessage format
116
+ * - metadata: Injected as system status (cpu, memory) - NOT shown in UI
117
+ * - timestamp: Used to construct system status time
118
+ * - attachments: File contents read and injected
119
+ * - todoSnapshot: Todo state at message creation, injected as context
120
+ *
121
+ * Why content doesn't include system status:
122
+ * - System status is contextual info, not part of user's actual message
123
+ * - Including it in content would display "<system_status>..." in chat UI
124
+ * - metadata allows us to store it separately and inject only when building ModelMessage
125
+ *
126
+ * Why usage/finishReason are NOT in metadata:
127
+ * - They're for monitoring/debugging, not for LLM consumption
128
+ * - finishReason controls multi-step flow (stop vs tool-calls vs length)
129
+ * - usage helps track API costs and quota
130
+ *
131
+ * Why todoSnapshot at top-level (not in metadata):
132
+ * - Structured data (Todo[]), not string context like cpu/memory
133
+ * - Enables rewind feature - can restore todo state at any point in conversation
134
+ * - May be used by UI for historical view
135
+ * - Clearer separation: metadata = simple context, todoSnapshot = structured state
136
+ */
137
+ export interface SessionMessage {
138
+ role: 'user' | 'assistant';
139
+ content: MessagePart[]; // UI display (without system status)
140
+ timestamp: number;
141
+ status?: 'active' | 'completed' | 'error' | 'abort'; // Message lifecycle state (default: 'completed')
142
+ metadata?: MessageMetadata; // System info for LLM context (not shown in UI)
143
+ todoSnapshot?: Todo[]; // Full todo state at message creation time (for rewind + LLM context)
144
+ attachments?: FileAttachment[];
145
+ usage?: TokenUsage; // For UI/monitoring, not sent to LLM
146
+ finishReason?: string; // For flow control (stop/tool-calls/length/error), not sent to LLM
147
+ }
148
+
149
+ /**
150
+ * Chat session
151
+ *
152
+ * Design: Per-session todo lists
153
+ * ================================
154
+ *
155
+ * Why todos are scoped to sessions (not global):
156
+ * 1. Context isolation - Each conversation has its own task context
157
+ * 2. Prevents cross-contamination - New session won't see old todos
158
+ * 3. LLM clarity - AI only sees tasks relevant to current conversation
159
+ *
160
+ * Before (global todos):
161
+ * - Session A creates todos ["Build feature X", "Test feature X"]
162
+ * - Session B starts, user says "hi"
163
+ * - LLM sees Session A's todos and tries to complete them ❌
164
+ *
165
+ * After (per-session todos):
166
+ * - Session A has its own todos
167
+ * - Session B starts with empty todos ✅
168
+ * - Each session manages independent task lists
169
+ *
170
+ * Implementation notes:
171
+ * - nextTodoId is also per-session to avoid ID conflicts
172
+ * - Todos are persisted with session to disk
173
+ * - updateTodos tool requires sessionId parameter
174
+ *
175
+ * Design: Message status-based state
176
+ * ===================================
177
+ *
178
+ * Streaming state is derived from message status, not stored separately:
179
+ * - message.status: 'active' | 'completed' | 'error' | 'abort'
180
+ * - part.status: 'active' | 'completed' | 'error' | 'abort'
181
+ *
182
+ * Session recovery:
183
+ * 1. Find messages with status === 'active'
184
+ * 2. Display their parts directly
185
+ * 3. No separate streaming state needed
186
+ *
187
+ * Streaming lifecycle:
188
+ * 1. User sends message → Create message with status='active'
189
+ * 2. Parts arrive → Add/update parts in message
190
+ * 3. User switches session → Message stays in DB with status='active'
191
+ * 4. Streaming completes → Update message status='completed'
192
+ * 5. User aborts (ESC) → Update message status='abort'
193
+ *
194
+ * Benefits:
195
+ * - Single source of truth (message data)
196
+ * - No conversion between streaming/persistent formats
197
+ * - Recovery is just "display active messages"
198
+ * - Archives naturally (status='archived')
199
+ */
200
+ export interface Session {
201
+ id: string;
202
+ title?: string; // Auto-generated from first user message
203
+ provider: ProviderId;
204
+ model: string;
205
+ messages: SessionMessage[];
206
+ todos: Todo[]; // Per-session todo list (not global!)
207
+ nextTodoId: number; // Next todo ID for this session (starts at 1)
208
+
209
+ // Note: Streaming state derived from message.status, not stored here
210
+ // To check if streaming: messages.some(m => m.status === 'active')
211
+
212
+ created: number;
213
+ updated: number;
214
+ }
@@ -0,0 +1,295 @@
1
+ import { z } from 'zod';
2
+
3
+ // ============================================================================
4
+ // TARGET CONFIGURATION INTERFACES
5
+ // ============================================================================
6
+
7
+ /**
8
+ * Generic metadata structure for agents and configurations
9
+ */
10
+ export interface AgentMetadata {
11
+ /** Agent name or identifier */
12
+ name?: string;
13
+ /** Agent description */
14
+ description?: string;
15
+ /** Agent version */
16
+ version?: string;
17
+ /** Agent author */
18
+ author?: string;
19
+ /** Tags for categorization */
20
+ tags?: string[];
21
+ /** Agent category or type */
22
+ category?: string;
23
+ /** Whether the agent is enabled */
24
+ enabled?: boolean;
25
+ /** Custom properties */
26
+ properties?: Record<string, unknown>;
27
+ /** Creation timestamp */
28
+ createdAt?: string;
29
+ /** Last updated timestamp */
30
+ updatedAt?: string;
31
+ /** Source file path */
32
+ sourcePath?: string;
33
+ }
34
+
35
+ /**
36
+ * Target-specific configuration data structure
37
+ */
38
+ export interface TargetConfigurationData {
39
+ /** Core configuration settings */
40
+ settings: Record<string, unknown>;
41
+ /** MCP server configurations */
42
+ mcpServers?: Record<string, unknown>;
43
+ /** Agent-specific configurations */
44
+ agents?: Record<string, AgentMetadata>;
45
+ /** Extension-specific settings */
46
+ extensions?: Record<string, unknown>;
47
+ /** Custom user preferences */
48
+ preferences?: Record<string, unknown>;
49
+ }
50
+
51
+ /**
52
+ * Front matter metadata for markdown files
53
+ */
54
+ export interface FrontMatterMetadata {
55
+ /** Title of the document */
56
+ title?: string;
57
+ /** Description of the document */
58
+ description?: string;
59
+ /** Tags for categorization */
60
+ tags?: string[];
61
+ /** Author information */
62
+ author?: string;
63
+ /** Creation date */
64
+ date?: string;
65
+ /** Last modified date */
66
+ modified?: string;
67
+ /** Document status (draft, published, etc.) */
68
+ status?: 'draft' | 'published' | 'archived';
69
+ /** Document category */
70
+ category?: string;
71
+ /** Custom metadata fields */
72
+ [key: string]: unknown;
73
+ }
74
+
75
+ /**
76
+ * OpenCode specific metadata structure
77
+ */
78
+ export interface OpenCodeMetadata {
79
+ /** Project name */
80
+ name?: string;
81
+ /** Project description */
82
+ description?: string;
83
+ /** Project version */
84
+ version?: string;
85
+ /** Author information */
86
+ author?: string;
87
+ /** Repository URL */
88
+ repository?: string;
89
+ /** License information */
90
+ license?: string;
91
+ /** Main entry point */
92
+ main?: string;
93
+ /** Scripts configuration */
94
+ scripts?: Record<string, string>;
95
+ /** Dependencies */
96
+ dependencies?: Record<string, string>;
97
+ /** Development dependencies */
98
+ devDependencies?: Record<string, string>;
99
+ /** Project keywords */
100
+ keywords?: string[];
101
+ /** Custom configuration */
102
+ config?: Record<string, unknown>;
103
+ }
104
+
105
+ /**
106
+ * Claude Code specific metadata structure
107
+ */
108
+ export interface ClaudeCodeMetadata {
109
+ /** Agent name */
110
+ name?: string;
111
+ /** Agent description */
112
+ description?: string;
113
+ /** Agent instructions */
114
+ instructions?: string;
115
+ /** Agent capabilities */
116
+ capabilities?: string[];
117
+ /** Agent tools */
118
+ tools?: string[];
119
+ /** Agent model configuration */
120
+ model?: {
121
+ name?: string;
122
+ temperature?: number;
123
+ maxTokens?: number;
124
+ };
125
+ /** Agent constraints */
126
+ constraints?: string[];
127
+ /** Custom metadata */
128
+ metadata?: Record<string, unknown>;
129
+ }
130
+
131
+ // ============================================================================
132
+ // ZOD SCHEMAS FOR RUNTIME VALIDATION
133
+ // ============================================================================
134
+
135
+ /**
136
+ * Zod schema for AgentMetadata
137
+ */
138
+ export const AgentMetadataSchema = z.object({
139
+ name: z.string().optional(),
140
+ description: z.string().optional(),
141
+ version: z.string().optional(),
142
+ author: z.string().optional(),
143
+ tags: z.array(z.string()).optional(),
144
+ category: z.string().optional(),
145
+ enabled: z.boolean().optional(),
146
+ properties: z.record(z.unknown()).optional(),
147
+ createdAt: z.string().optional(),
148
+ updatedAt: z.string().optional(),
149
+ sourcePath: z.string().optional(),
150
+ });
151
+
152
+ /**
153
+ * Zod schema for TargetConfigurationData
154
+ */
155
+ export const TargetConfigurationDataSchema = z.object({
156
+ settings: z.record(z.unknown()),
157
+ mcpServers: z.record(z.unknown()).optional(),
158
+ agents: z.record(AgentMetadataSchema).optional(),
159
+ extensions: z.record(z.unknown()).optional(),
160
+ preferences: z.record(z.unknown()).optional(),
161
+ });
162
+
163
+ /**
164
+ * Zod schema for FrontMatterMetadata
165
+ */
166
+ export const FrontMatterMetadataSchema = z
167
+ .object({
168
+ title: z.string().optional(),
169
+ description: z.string().optional(),
170
+ tags: z.array(z.string()).optional(),
171
+ author: z.string().optional(),
172
+ date: z.string().optional(),
173
+ modified: z.string().optional(),
174
+ status: z.enum(['draft', 'published', 'archived']).optional(),
175
+ category: z.string().optional(),
176
+ })
177
+ .catchall(z.unknown());
178
+
179
+ /**
180
+ * Zod schema for OpenCodeMetadata
181
+ */
182
+ export const OpenCodeMetadataSchema = z.object({
183
+ name: z.string().optional(),
184
+ description: z.string().optional(),
185
+ version: z.string().optional(),
186
+ author: z.string().optional(),
187
+ repository: z.string().optional(),
188
+ license: z.string().optional(),
189
+ main: z.string().optional(),
190
+ scripts: z.record(z.string()).optional(),
191
+ dependencies: z.record(z.string()).optional(),
192
+ devDependencies: z.record(z.string()).optional(),
193
+ keywords: z.array(z.string()).optional(),
194
+ config: z.record(z.unknown()).optional(),
195
+ });
196
+
197
+ /**
198
+ * Zod schema for ClaudeCodeMetadata
199
+ */
200
+ export const ClaudeCodeMetadataSchema = z.object({
201
+ name: z.string().optional(),
202
+ description: z.string().optional(),
203
+ instructions: z.string().optional(),
204
+ capabilities: z.array(z.string()).optional(),
205
+ tools: z.array(z.string()).optional(),
206
+ model: z
207
+ .object({
208
+ name: z.string().optional(),
209
+ temperature: z.number().optional(),
210
+ maxTokens: z.number().optional(),
211
+ })
212
+ .optional(),
213
+ constraints: z.array(z.string()).optional(),
214
+ metadata: z.record(z.unknown()).optional(),
215
+ });
216
+
217
+ // ============================================================================
218
+ // TYPE GUARDS FOR RUNTIME TYPE CHECKING
219
+ // ============================================================================
220
+
221
+ /**
222
+ * Type guard to check if value is AgentMetadata
223
+ */
224
+ export function isAgentMetadata(value: unknown): value is AgentMetadata {
225
+ return AgentMetadataSchema.safeParse(value).success;
226
+ }
227
+
228
+ /**
229
+ * Type guard to check if value is TargetConfigurationData
230
+ */
231
+ export function isTargetConfigurationData(value: unknown): value is TargetConfigurationData {
232
+ return TargetConfigurationDataSchema.safeParse(value).success;
233
+ }
234
+
235
+ /**
236
+ * Type guard to check if value is FrontMatterMetadata
237
+ */
238
+ export function isFrontMatterMetadata(value: unknown): value is FrontMatterMetadata {
239
+ return FrontMatterMetadataSchema.safeParse(value).success;
240
+ }
241
+
242
+ /**
243
+ * Type guard to check if value is OpenCodeMetadata
244
+ */
245
+ export function isOpenCodeMetadata(value: unknown): value is OpenCodeMetadata {
246
+ return OpenCodeMetadataSchema.safeParse(value).success;
247
+ }
248
+
249
+ /**
250
+ * Type guard to check if value is ClaudeCodeMetadata
251
+ */
252
+ export function isClaudeCodeMetadata(value: unknown): value is ClaudeCodeMetadata {
253
+ return ClaudeCodeMetadataSchema.safeParse(value).success;
254
+ }
255
+
256
+ // ============================================================================
257
+ // UTILITY TYPES
258
+ // ============================================================================
259
+
260
+ /**
261
+ * Generic configuration object with dynamic properties
262
+ */
263
+ export type DynamicConfig<T = Record<string, unknown>> = T & {
264
+ [key: string]: unknown;
265
+ };
266
+
267
+ /**
268
+ * Generic transformation result
269
+ */
270
+ export interface TransformationResult<T = unknown> {
271
+ success: boolean;
272
+ data?: T;
273
+ error?: string;
274
+ warnings?: string[];
275
+ }
276
+
277
+ /**
278
+ * Generic validation result
279
+ */
280
+ export interface ValidationResult<T = unknown> {
281
+ isValid: boolean;
282
+ data?: T;
283
+ errors: string[];
284
+ }
285
+
286
+ /**
287
+ * Generic operation result with metadata
288
+ */
289
+ export interface OperationResult<T = unknown, M = Record<string, unknown>> {
290
+ success: boolean;
291
+ data?: T;
292
+ metadata?: M;
293
+ error?: string;
294
+ timestamp: string;
295
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Target system type definitions
3
+ * Types for target platforms (Claude Code, OpenCode, etc.)
4
+ */
5
+
6
+ import type { CommonOptions, SetupResult } from './common.types.js';
7
+ import type { MCPServerConfigFlags, MCPServerConfigUnion } from './mcp.types.js';
8
+
9
+ /**
10
+ * Target-specific configuration
11
+ * Defines how agents, configs, and other artifacts are structured for each target
12
+ */
13
+ export interface TargetConfig {
14
+ /** Directory where agents are installed */
15
+ agentDir: string;
16
+ /** File extension for agent files */
17
+ agentExtension: string;
18
+ /** Format of agent files */
19
+ agentFormat: 'yaml-frontmatter' | 'json' | 'yaml' | 'markdown';
20
+ /** Whether to strip YAML front matter from content */
21
+ stripYaml: boolean;
22
+ /** Whether to flatten directory structure */
23
+ flatten: boolean;
24
+ /** Configuration file name */
25
+ configFile: string;
26
+ /** Configuration file schema URL (optional) */
27
+ configSchema: string | null;
28
+ /** Path to MCP configuration in config file */
29
+ mcpConfigPath: string;
30
+ /** Rules file path (optional, relative to project root) */
31
+ rulesFile?: string;
32
+ /** Output styles directory (optional, relative to project root) */
33
+ outputStylesDir?: string;
34
+ /** Slash commands directory (optional, relative to project root) */
35
+ slashCommandsDir?: string;
36
+ /** Installation-specific configuration */
37
+ installation: {
38
+ /** Whether to create the agent directory */
39
+ createAgentDir: boolean;
40
+ /** Whether to create the config file */
41
+ createConfigFile: boolean;
42
+ /** Whether to use secret file references for sensitive environment variables */
43
+ useSecretFiles?: boolean;
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Target interface - composition-based design
49
+ * Targets are implemented as plain objects with functions, not classes
50
+ *
51
+ * Each target represents a platform that can host AI agents and MCP servers
52
+ * (e.g., Claude Code CLI, OpenCode, VS Code with Continue, etc.)
53
+ */
54
+ export interface Target {
55
+ // Metadata
56
+ /** Internal identifier used in CLI commands */
57
+ readonly id: string;
58
+ /** Display name for the target */
59
+ readonly name: string;
60
+ /** Human-readable description */
61
+ readonly description: string;
62
+ /** Target category for grouping */
63
+ readonly category: 'ide' | 'editor' | 'cli';
64
+ /** Whether this target is the default when no target is specified */
65
+ readonly isDefault?: boolean;
66
+ /** Whether this target is fully implemented */
67
+ readonly isImplemented: boolean;
68
+
69
+ // Configuration
70
+ /** Target-specific configuration */
71
+ readonly config: TargetConfig;
72
+ /** MCP server configuration for this target */
73
+ readonly mcpServerConfig?: MCPServerConfigFlags;
74
+
75
+ // Required transformation methods
76
+ /** Transform agent content for the target */
77
+ transformAgentContent(
78
+ content: string,
79
+ metadata?: Record<string, unknown>,
80
+ sourcePath?: string
81
+ ): Promise<string>;
82
+
83
+ /** Transform MCP server configuration for the target */
84
+ transformMCPConfig(config: MCPServerConfigUnion, serverId?: string): Record<string, unknown>;
85
+
86
+ // Required configuration methods
87
+ /** Get the configuration file path for the target */
88
+ getConfigPath(cwd: string): Promise<string>;
89
+
90
+ /** Read the target's configuration file */
91
+ readConfig(cwd: string): Promise<Record<string, unknown>>;
92
+
93
+ /** Write the target's configuration file */
94
+ writeConfig(cwd: string, config: Record<string, unknown>): Promise<void>;
95
+
96
+ /** Validate target-specific requirements */
97
+ validateRequirements(cwd: string): Promise<void>;
98
+
99
+ /** Get target-specific help text */
100
+ getHelpText(): string;
101
+
102
+ // Optional methods
103
+ /** Execute command with the target (optional - not all targets need to support execution) */
104
+ executeCommand?(
105
+ systemPrompt: string,
106
+ userPrompt: string,
107
+ options: Record<string, unknown>
108
+ ): Promise<void>;
109
+
110
+ /** Detect if this target is being used in the current environment (optional) */
111
+ detectFromEnvironment?(): boolean;
112
+
113
+ /** Approve MCP servers in target-specific configuration (optional - only for targets that need approval) */
114
+ approveMCPServers?(cwd: string, serverNames: string[]): Promise<void>;
115
+
116
+ /** Transform rules content for the target (optional - defaults to no transformation) */
117
+ transformRulesContent?(content: string): Promise<string>;
118
+
119
+ /** Setup target-specific configuration (optional - for targets that need additional setup) */
120
+ setup?(cwd: string, options?: Record<string, unknown>): Promise<void>;
121
+
122
+ // Setup methods for different components
123
+ /** Setup agents for this target (optional - implement if target needs agents) */
124
+ setupAgents?(cwd: string, options: CommonOptions): Promise<SetupResult>;
125
+
126
+ /** Setup rules for this target (optional - implement if target needs rules) */
127
+ setupRules?(cwd: string, options: CommonOptions): Promise<SetupResult>;
128
+
129
+ /** Setup output styles for this target (optional - implement if target supports output styles) */
130
+ setupOutputStyles?(cwd: string, options: CommonOptions): Promise<SetupResult>;
131
+
132
+ /** Setup MCP servers for this target (optional - implement if target supports MCP) */
133
+ setupMCP?(cwd: string, options: CommonOptions): Promise<SetupResult>;
134
+
135
+ /** Setup hooks for this target (optional - implement if target needs hooks like Claude Code) */
136
+ setupHooks?(cwd: string, options: CommonOptions): Promise<SetupResult>;
137
+
138
+ /** Setup slash commands for this target (optional - implement if target supports slash commands) */
139
+ setupSlashCommands?(cwd: string, options: CommonOptions): Promise<SetupResult>;
140
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Todo Types
3
+ * Task tracking for LLM work progress
4
+ */
5
+
6
+ export type TodoStatus = 'pending' | 'in_progress' | 'completed' | 'removed';
7
+
8
+ export interface Todo {
9
+ id: number;
10
+ content: string;
11
+ status: TodoStatus;
12
+ activeForm: string; // Present continuous form (e.g., "Building feature X")
13
+ ordering: number; // For custom ordering (higher = earlier in list)
14
+ }
15
+
16
+ export interface TodoUpdate {
17
+ id?: number;
18
+ content?: string;
19
+ activeForm?: string;
20
+ status?: TodoStatus;
21
+ reorder?: {
22
+ type: 'before' | 'after' | 'top' | 'last';
23
+ id?: number; // Required when type is 'before' or 'after'
24
+ };
25
+ }