@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.
- package/CHANGELOG.md +12 -0
- package/package.json +10 -9
- package/src/commands/codebase-command.ts +168 -0
- package/src/commands/flow-command.ts +1137 -0
- package/src/commands/flow-orchestrator.ts +296 -0
- package/src/commands/hook-command.ts +444 -0
- package/src/commands/init-command.ts +92 -0
- package/src/commands/init-core.ts +322 -0
- package/src/commands/knowledge-command.ts +161 -0
- package/src/commands/run-command.ts +120 -0
- package/src/components/benchmark-monitor.tsx +331 -0
- package/src/components/reindex-progress.tsx +261 -0
- package/src/composables/functional/index.ts +14 -0
- package/src/composables/functional/useEnvironment.ts +171 -0
- package/src/composables/functional/useFileSystem.ts +139 -0
- package/src/composables/index.ts +5 -0
- package/src/composables/useEnv.ts +13 -0
- package/src/composables/useRuntimeConfig.ts +27 -0
- package/src/composables/useTargetConfig.ts +45 -0
- package/src/config/ai-config.ts +376 -0
- package/src/config/constants.ts +35 -0
- package/src/config/index.ts +27 -0
- package/src/config/rules.ts +43 -0
- package/src/config/servers.ts +371 -0
- package/src/config/targets.ts +126 -0
- package/src/core/agent-loader.ts +141 -0
- package/src/core/agent-manager.ts +174 -0
- package/src/core/ai-sdk.ts +603 -0
- package/src/core/app-factory.ts +381 -0
- package/src/core/builtin-agents.ts +9 -0
- package/src/core/command-system.ts +550 -0
- package/src/core/config-system.ts +550 -0
- package/src/core/connection-pool.ts +390 -0
- package/src/core/di-container.ts +155 -0
- package/src/core/error-handling.ts +519 -0
- package/src/core/formatting/bytes.test.ts +115 -0
- package/src/core/formatting/bytes.ts +64 -0
- package/src/core/functional/async.ts +313 -0
- package/src/core/functional/either.ts +109 -0
- package/src/core/functional/error-handler.ts +135 -0
- package/src/core/functional/error-types.ts +311 -0
- package/src/core/functional/index.ts +19 -0
- package/src/core/functional/option.ts +142 -0
- package/src/core/functional/pipe.ts +189 -0
- package/src/core/functional/result.ts +204 -0
- package/src/core/functional/validation.ts +138 -0
- package/src/core/headless-display.ts +96 -0
- package/src/core/index.ts +6 -0
- package/src/core/installers/file-installer.ts +303 -0
- package/src/core/installers/mcp-installer.ts +213 -0
- package/src/core/interfaces/index.ts +22 -0
- package/src/core/interfaces/repository.interface.ts +91 -0
- package/src/core/interfaces/service.interface.ts +133 -0
- package/src/core/interfaces.ts +129 -0
- package/src/core/loop-controller.ts +200 -0
- package/src/core/result.ts +351 -0
- package/src/core/rule-loader.ts +147 -0
- package/src/core/rule-manager.ts +240 -0
- package/src/core/service-config.ts +252 -0
- package/src/core/session-service.ts +121 -0
- package/src/core/state-detector.ts +389 -0
- package/src/core/storage-factory.ts +115 -0
- package/src/core/stream-handler.ts +288 -0
- package/src/core/target-manager.ts +161 -0
- package/src/core/type-utils.ts +427 -0
- package/src/core/unified-storage.ts +456 -0
- package/src/core/upgrade-manager.ts +300 -0
- package/src/core/validation/limit.test.ts +155 -0
- package/src/core/validation/limit.ts +46 -0
- package/src/core/validation/query.test.ts +44 -0
- package/src/core/validation/query.ts +20 -0
- package/src/db/auto-migrate.ts +322 -0
- package/src/db/base-database-client.ts +144 -0
- package/src/db/cache-db.ts +218 -0
- package/src/db/cache-schema.ts +75 -0
- package/src/db/database.ts +70 -0
- package/src/db/index.ts +252 -0
- package/src/db/memory-db.ts +153 -0
- package/src/db/memory-schema.ts +29 -0
- package/src/db/schema.ts +289 -0
- package/src/db/session-repository.ts +733 -0
- package/src/domains/codebase/index.ts +5 -0
- package/src/domains/codebase/tools.ts +139 -0
- package/src/domains/index.ts +8 -0
- package/src/domains/knowledge/index.ts +10 -0
- package/src/domains/knowledge/resources.ts +537 -0
- package/src/domains/knowledge/tools.ts +174 -0
- package/src/domains/utilities/index.ts +6 -0
- package/src/domains/utilities/time/index.ts +5 -0
- package/src/domains/utilities/time/tools.ts +291 -0
- package/src/index.ts +211 -0
- package/src/services/agent-service.ts +273 -0
- package/src/services/claude-config-service.ts +252 -0
- package/src/services/config-service.ts +258 -0
- package/src/services/evaluation-service.ts +271 -0
- package/src/services/functional/evaluation-logic.ts +296 -0
- package/src/services/functional/file-processor.ts +273 -0
- package/src/services/functional/index.ts +12 -0
- package/src/services/index.ts +13 -0
- package/src/services/mcp-service.ts +432 -0
- package/src/services/memory.service.ts +476 -0
- package/src/services/search/base-indexer.ts +156 -0
- package/src/services/search/codebase-indexer-types.ts +38 -0
- package/src/services/search/codebase-indexer.ts +647 -0
- package/src/services/search/embeddings-provider.ts +455 -0
- package/src/services/search/embeddings.ts +316 -0
- package/src/services/search/functional-indexer.ts +323 -0
- package/src/services/search/index.ts +27 -0
- package/src/services/search/indexer.ts +380 -0
- package/src/services/search/knowledge-indexer.ts +422 -0
- package/src/services/search/semantic-search.ts +244 -0
- package/src/services/search/tfidf.ts +559 -0
- package/src/services/search/unified-search-service.ts +888 -0
- package/src/services/smart-config-service.ts +385 -0
- package/src/services/storage/cache-storage.ts +487 -0
- package/src/services/storage/drizzle-storage.ts +581 -0
- package/src/services/storage/index.ts +15 -0
- package/src/services/storage/lancedb-vector-storage.ts +494 -0
- package/src/services/storage/memory-storage.ts +268 -0
- package/src/services/storage/separated-storage.ts +467 -0
- package/src/services/storage/vector-storage.ts +13 -0
- package/src/shared/agents/index.ts +63 -0
- package/src/shared/files/index.ts +99 -0
- package/src/shared/index.ts +32 -0
- package/src/shared/logging/index.ts +24 -0
- package/src/shared/processing/index.ts +153 -0
- package/src/shared/types/index.ts +25 -0
- package/src/targets/claude-code.ts +574 -0
- package/src/targets/functional/claude-code-logic.ts +185 -0
- package/src/targets/functional/index.ts +6 -0
- package/src/targets/opencode.ts +529 -0
- package/src/types/agent.types.ts +32 -0
- package/src/types/api/batch.ts +108 -0
- package/src/types/api/errors.ts +118 -0
- package/src/types/api/index.ts +55 -0
- package/src/types/api/requests.ts +76 -0
- package/src/types/api/responses.ts +180 -0
- package/src/types/api/websockets.ts +85 -0
- package/src/types/api.types.ts +9 -0
- package/src/types/benchmark.ts +49 -0
- package/src/types/cli.types.ts +87 -0
- package/src/types/common.types.ts +35 -0
- package/src/types/database.types.ts +510 -0
- package/src/types/mcp-config.types.ts +448 -0
- package/src/types/mcp.types.ts +69 -0
- package/src/types/memory-types.ts +63 -0
- package/src/types/provider.types.ts +28 -0
- package/src/types/rule.types.ts +24 -0
- package/src/types/session.types.ts +214 -0
- package/src/types/target-config.types.ts +295 -0
- package/src/types/target.types.ts +140 -0
- package/src/types/todo.types.ts +25 -0
- package/src/types.ts +40 -0
- package/src/utils/advanced-tokenizer.ts +191 -0
- package/src/utils/agent-enhancer.ts +114 -0
- package/src/utils/ai-model-fetcher.ts +19 -0
- package/src/utils/async-file-operations.ts +516 -0
- package/src/utils/audio-player.ts +345 -0
- package/src/utils/cli-output.ts +266 -0
- package/src/utils/codebase-helpers.ts +211 -0
- package/src/utils/console-ui.ts +79 -0
- package/src/utils/database-errors.ts +140 -0
- package/src/utils/debug-logger.ts +49 -0
- package/src/utils/error-handler.ts +53 -0
- package/src/utils/file-operations.ts +310 -0
- package/src/utils/file-scanner.ts +259 -0
- package/src/utils/functional/array.ts +355 -0
- package/src/utils/functional/index.ts +15 -0
- package/src/utils/functional/object.ts +279 -0
- package/src/utils/functional/string.ts +281 -0
- package/src/utils/functional.ts +543 -0
- package/src/utils/help.ts +20 -0
- package/src/utils/immutable-cache.ts +106 -0
- package/src/utils/index.ts +78 -0
- package/src/utils/jsonc.ts +158 -0
- package/src/utils/logger.ts +396 -0
- package/src/utils/mcp-config.ts +249 -0
- package/src/utils/memory-tui.ts +414 -0
- package/src/utils/models-dev.ts +91 -0
- package/src/utils/notifications.ts +169 -0
- package/src/utils/object-utils.ts +51 -0
- package/src/utils/parallel-operations.ts +487 -0
- package/src/utils/paths.ts +143 -0
- package/src/utils/process-manager.ts +155 -0
- package/src/utils/prompts.ts +120 -0
- package/src/utils/search-tool-builder.ts +214 -0
- package/src/utils/secret-utils.ts +179 -0
- package/src/utils/security.ts +537 -0
- package/src/utils/session-manager.ts +168 -0
- package/src/utils/session-title.ts +87 -0
- package/src/utils/settings.ts +182 -0
- package/src/utils/simplified-errors.ts +410 -0
- package/src/utils/sync-utils.ts +159 -0
- package/src/utils/target-config.ts +570 -0
- package/src/utils/target-utils.ts +394 -0
- package/src/utils/template-engine.ts +94 -0
- package/src/utils/test-audio.ts +71 -0
- package/src/utils/todo-context.ts +46 -0
- package/src/utils/token-counter.ts +288 -0
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -59554
- package/dist/lancedb.linux-x64-gnu-b7f0jgsz.node +0 -0
- package/dist/lancedb.linux-x64-musl-tgcv22rx.node +0 -0
- package/dist/shared/chunk-25dwp0dp.js +0 -89
- package/dist/shared/chunk-3pjb6063.js +0 -208
- package/dist/shared/chunk-4d6ydpw7.js +0 -2854
- package/dist/shared/chunk-4wjcadjk.js +0 -225
- package/dist/shared/chunk-5j4w74t6.js +0 -30
- package/dist/shared/chunk-5j8m3dh3.js +0 -58
- package/dist/shared/chunk-5thh3qem.js +0 -91
- package/dist/shared/chunk-6g9xy73m.js +0 -252
- package/dist/shared/chunk-7eq34c42.js +0 -23
- package/dist/shared/chunk-c2gwgx3r.js +0 -115
- package/dist/shared/chunk-cjd3mk4c.js +0 -1320
- package/dist/shared/chunk-g5cv6703.js +0 -368
- package/dist/shared/chunk-hpkhykhq.js +0 -574
- package/dist/shared/chunk-m2322pdk.js +0 -122
- package/dist/shared/chunk-nd5fdvaq.js +0 -26
- package/dist/shared/chunk-pgd3m6zf.js +0 -108
- package/dist/shared/chunk-qk8n91hw.js +0 -494
- package/dist/shared/chunk-rkkn8szp.js +0 -16855
- package/dist/shared/chunk-t16rfxh0.js +0 -61
- package/dist/shared/chunk-t4fbfa5v.js +0 -19
- package/dist/shared/chunk-t77h86w6.js +0 -276
- package/dist/shared/chunk-v0ez4aef.js +0 -71
- package/dist/shared/chunk-v29j2r3s.js +0 -32051
- package/dist/shared/chunk-vfbc6ew5.js +0 -765
- package/dist/shared/chunk-vmeqwm1c.js +0 -204
- package/dist/shared/chunk-x66eh37x.js +0 -137
package/src/types.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized type exports
|
|
3
|
+
* This file re-exports types from domain-specific modules for backward compatibility
|
|
4
|
+
*
|
|
5
|
+
* MIGRATION GUIDE:
|
|
6
|
+
* Instead of importing from this file, prefer importing from specific type modules:
|
|
7
|
+
* - './types/cli.types.js' for CLI-related types
|
|
8
|
+
* - './types/mcp.types.js' for MCP configuration types
|
|
9
|
+
* - './types/target.types.js' for Target system types
|
|
10
|
+
* - './types/common.types.js' for shared types
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Re-export all types for backward compatibility
|
|
14
|
+
export type {
|
|
15
|
+
CommandHandler,
|
|
16
|
+
CommandOptions,
|
|
17
|
+
CommandConfig,
|
|
18
|
+
RunCommandOptions,
|
|
19
|
+
} from './types/cli.types.js';
|
|
20
|
+
export type {
|
|
21
|
+
CommonOptions,
|
|
22
|
+
Resolvable,
|
|
23
|
+
SetupResult,
|
|
24
|
+
} from './types/common.types.js';
|
|
25
|
+
export type {
|
|
26
|
+
MCPServerConfig,
|
|
27
|
+
MCPServerConfigFlags,
|
|
28
|
+
MCPServerConfigHTTP,
|
|
29
|
+
MCPServerConfigUnion,
|
|
30
|
+
OpenCodeConfig,
|
|
31
|
+
} from './types/mcp.types.js';
|
|
32
|
+
export {
|
|
33
|
+
isCLICommandConfig,
|
|
34
|
+
isHttpConfig,
|
|
35
|
+
isStdioConfig,
|
|
36
|
+
} from './types/mcp.types.js';
|
|
37
|
+
export type {
|
|
38
|
+
Target,
|
|
39
|
+
TargetConfig,
|
|
40
|
+
} from './types/target.types.js';
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced Code Tokenizer - 純粹 StarCoder2,無任何多餘處理
|
|
3
|
+
* 完全信任 StarCoder2 嘅世界級 tokenization 能力
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AutoTokenizer } from '@huggingface/transformers';
|
|
7
|
+
|
|
8
|
+
export interface AdvancedToken {
|
|
9
|
+
text: string;
|
|
10
|
+
id: number;
|
|
11
|
+
score: number;
|
|
12
|
+
confidence: number;
|
|
13
|
+
relevance: 'high' | 'medium' | 'low';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AdvancedTokenizerResult {
|
|
17
|
+
tokens: AdvancedToken[];
|
|
18
|
+
metadata: {
|
|
19
|
+
totalTokens: number;
|
|
20
|
+
vocabSize: number;
|
|
21
|
+
processingTime: number;
|
|
22
|
+
averageConfidence: number;
|
|
23
|
+
};
|
|
24
|
+
raw: {
|
|
25
|
+
inputIds: number[];
|
|
26
|
+
decodedText: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Advanced Code Tokenizer - 純粹 StarCoder2
|
|
32
|
+
*/
|
|
33
|
+
export class AdvancedCodeTokenizer {
|
|
34
|
+
private tokenizer: any;
|
|
35
|
+
private initialized = false;
|
|
36
|
+
private modelPath: string;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
options: {
|
|
40
|
+
modelPath?: string;
|
|
41
|
+
} = {}
|
|
42
|
+
) {
|
|
43
|
+
this.modelPath = options.modelPath || './models/starcoder2';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 初始化 tokenizer
|
|
48
|
+
*/
|
|
49
|
+
async initialize(): Promise<void> {
|
|
50
|
+
if (this.initialized) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
this.tokenizer = await AutoTokenizer.from_pretrained(this.modelPath);
|
|
56
|
+
this.initialized = true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
throw new Error(`Tokenizer initialization failed: ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 純粹 StarCoder2 tokenization - 無任何安全限制或多餘分析
|
|
64
|
+
*/
|
|
65
|
+
async tokenize(content: string): Promise<AdvancedTokenizerResult> {
|
|
66
|
+
if (!this.initialized) {
|
|
67
|
+
await this.initialize();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const startTime = Date.now();
|
|
71
|
+
|
|
72
|
+
// Handle empty content
|
|
73
|
+
if (!content || content.trim().length === 0) {
|
|
74
|
+
return {
|
|
75
|
+
tokens: [],
|
|
76
|
+
metadata: {
|
|
77
|
+
totalTokens: 0,
|
|
78
|
+
vocabSize: 49152,
|
|
79
|
+
processingTime: Date.now() - startTime,
|
|
80
|
+
averageConfidence: 0,
|
|
81
|
+
},
|
|
82
|
+
raw: {
|
|
83
|
+
inputIds: [],
|
|
84
|
+
decodedText: '',
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
// 完全信任 StarCoder2,直接處理所有內容
|
|
91
|
+
const encoded = await this.tokenizer(content);
|
|
92
|
+
const inputIds = encoded.input_ids.tolist()[0];
|
|
93
|
+
|
|
94
|
+
// 解碼獲得原文
|
|
95
|
+
const decodedText = await this.tokenizer.decode(inputIds);
|
|
96
|
+
|
|
97
|
+
// 直接用 StarCoder2 嘅輸出,唔做多餘分析
|
|
98
|
+
const tokens = await this.createDirectTokens(decodedText, inputIds);
|
|
99
|
+
|
|
100
|
+
const processingTime = Date.now() - startTime;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
tokens,
|
|
104
|
+
metadata: {
|
|
105
|
+
totalTokens: tokens.length,
|
|
106
|
+
vocabSize: 49152,
|
|
107
|
+
processingTime,
|
|
108
|
+
averageConfidence: 0.95, // StarCoder2 本身就係高質量
|
|
109
|
+
},
|
|
110
|
+
raw: {
|
|
111
|
+
inputIds,
|
|
112
|
+
decodedText,
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new Error(`Tokenization failed: ${error.message}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 純粹 StarCoder2 tokenization - 完全信任,無任何額外處理
|
|
122
|
+
* 直接使用 StarCoder2 嘅 token IDs,逐個解碼成文字
|
|
123
|
+
*/
|
|
124
|
+
private async createDirectTokens(
|
|
125
|
+
_decodedText: string,
|
|
126
|
+
inputIds: number[]
|
|
127
|
+
): Promise<AdvancedToken[]> {
|
|
128
|
+
const tokens: AdvancedToken[] = [];
|
|
129
|
+
|
|
130
|
+
// 完全信任 StarCoder2,直接使用佢嘅 tokenization
|
|
131
|
+
// 逐個 token ID 解碼,得到 StarCoder2 認為嘅最佳分割
|
|
132
|
+
for (let i = 0; i < inputIds.length; i++) {
|
|
133
|
+
const tokenId = inputIds[i];
|
|
134
|
+
try {
|
|
135
|
+
// 直接使用 StarCoder2 嘅解碼結果
|
|
136
|
+
const tokenText = await this.tokenizer.decode([tokenId], { skip_special_tokens: true });
|
|
137
|
+
const cleaned = tokenText.trim().toLowerCase();
|
|
138
|
+
|
|
139
|
+
// 只過濾空白 token,其他全部保留(完全信任 StarCoder2)
|
|
140
|
+
if (cleaned.length > 0) {
|
|
141
|
+
tokens.push({
|
|
142
|
+
text: cleaned,
|
|
143
|
+
id: tokenId,
|
|
144
|
+
score: 1.0, // StarCoder2 嘅所有 token 都係高質量
|
|
145
|
+
confidence: 1.0, // 完全信任 StarCoder2
|
|
146
|
+
relevance: 'high' as const,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
} catch (_error) {}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return tokens;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 便利方法:只返回高質量 tokens
|
|
157
|
+
*/
|
|
158
|
+
async getTopTokens(content: string, limit = 20): Promise<AdvancedToken[]> {
|
|
159
|
+
const result = await this.tokenize(content);
|
|
160
|
+
return result.tokens.slice(0, limit);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 便利方法:返回所有 tokens (StarCoder2 嘅輸出全部都係高質量)
|
|
165
|
+
*/
|
|
166
|
+
async getTechnicalTokens(content: string): Promise<AdvancedToken[]> {
|
|
167
|
+
const result = await this.tokenize(content);
|
|
168
|
+
return result.tokens; // StarCoder2 嘅所有輸出都係技術相關
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 解碼 token IDs 回文本
|
|
173
|
+
*/
|
|
174
|
+
async decode(tokenIds: number[]): Promise<string> {
|
|
175
|
+
if (!this.initialized) {
|
|
176
|
+
throw new Error('Tokenizer not initialized. Call initialize() first.');
|
|
177
|
+
}
|
|
178
|
+
return await this.tokenizer.decode(tokenIds);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 編碼文本為 token IDs
|
|
183
|
+
*/
|
|
184
|
+
async encode(text: string): Promise<number[]> {
|
|
185
|
+
if (!this.initialized) {
|
|
186
|
+
throw new Error('Tokenizer not initialized. Call initialize() first.');
|
|
187
|
+
}
|
|
188
|
+
const result = await this.tokenizer(text);
|
|
189
|
+
return result.input_ids.tolist()[0];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Enhancer - Append rules and output styles to agent content
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities to enhance agent files with:
|
|
5
|
+
* - Rules (from assets/rules/core.md)
|
|
6
|
+
* - Output Styles (from assets/output-styles/*.md)
|
|
7
|
+
*
|
|
8
|
+
* These are appended to agent content to ensure every agent has
|
|
9
|
+
* access to the same rules and output styles without duplicating
|
|
10
|
+
* them in CLAUDE.md or other system prompts.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { getOutputStylesDir, getRulesDir } from './paths.js';
|
|
16
|
+
import { yamlUtils } from './target-utils.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Load and combine rules and output styles
|
|
20
|
+
*/
|
|
21
|
+
export async function loadRulesAndStyles(ruleNames?: string[]): Promise<string> {
|
|
22
|
+
const sections: string[] = [];
|
|
23
|
+
|
|
24
|
+
// Load rules (either specified rules or default to 'core')
|
|
25
|
+
const rulesContent = await loadRules(ruleNames);
|
|
26
|
+
if (rulesContent) {
|
|
27
|
+
sections.push(rulesContent);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Load output styles
|
|
31
|
+
const stylesContent = await loadOutputStyles();
|
|
32
|
+
if (stylesContent) {
|
|
33
|
+
sections.push(stylesContent);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return sections.join('\n\n---\n\n');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Load rules from assets/rules/*.md
|
|
41
|
+
* @param ruleNames - Array of rule file names (without .md extension). Defaults to ['core']
|
|
42
|
+
*/
|
|
43
|
+
async function loadRules(ruleNames?: string[]): Promise<string> {
|
|
44
|
+
try {
|
|
45
|
+
const rulesDir = getRulesDir();
|
|
46
|
+
const rulesToLoad = ruleNames && ruleNames.length > 0 ? ruleNames : ['core'];
|
|
47
|
+
const sections: string[] = [];
|
|
48
|
+
|
|
49
|
+
for (const ruleName of rulesToLoad) {
|
|
50
|
+
const rulePath = path.join(rulesDir, `${ruleName}.md`);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const content = await fs.readFile(rulePath, 'utf8');
|
|
54
|
+
// Strip YAML front matter
|
|
55
|
+
const stripped = await yamlUtils.stripFrontMatter(content);
|
|
56
|
+
sections.push(stripped);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// Log warning if rule file not found, but continue with other rules
|
|
59
|
+
console.warn(`Warning: Rule file not found: ${ruleName}.md`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return sections.join('\n\n---\n\n');
|
|
64
|
+
} catch (_error) {
|
|
65
|
+
// If rules directory doesn't exist, return empty string
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Load output styles from assets/output-styles/
|
|
72
|
+
*/
|
|
73
|
+
async function loadOutputStyles(): Promise<string> {
|
|
74
|
+
try {
|
|
75
|
+
const outputStylesDir = getOutputStylesDir();
|
|
76
|
+
const files = await fs.readdir(outputStylesDir);
|
|
77
|
+
const mdFiles = files.filter((f) => f.endsWith('.md'));
|
|
78
|
+
|
|
79
|
+
if (mdFiles.length === 0) {
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const sections: string[] = [];
|
|
84
|
+
|
|
85
|
+
for (const file of mdFiles) {
|
|
86
|
+
const filePath = path.join(outputStylesDir, file);
|
|
87
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
88
|
+
|
|
89
|
+
// Strip YAML front matter
|
|
90
|
+
const stripped = await yamlUtils.stripFrontMatter(content);
|
|
91
|
+
sections.push(stripped);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return sections.join('\n\n');
|
|
95
|
+
} catch (_error) {
|
|
96
|
+
// If output styles directory doesn't exist, return empty string
|
|
97
|
+
return '';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Enhance agent content by appending rules and output styles
|
|
103
|
+
* @param agentContent - The agent markdown content
|
|
104
|
+
* @param ruleNames - Optional array of rule file names to include (defaults to ['core'])
|
|
105
|
+
*/
|
|
106
|
+
export async function enhanceAgentContent(agentContent: string, ruleNames?: string[]): Promise<string> {
|
|
107
|
+
const rulesAndStyles = await loadRulesAndStyles(ruleNames);
|
|
108
|
+
|
|
109
|
+
if (!rulesAndStyles) {
|
|
110
|
+
return agentContent;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return `${agentContent}\n\n---\n\n# Rules and Output Styles\n\n${rulesAndStyles}`;
|
|
114
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Model Fetcher
|
|
3
|
+
* Dynamically fetch available models from providers using provider registry
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ProviderId } from '../types/provider.types.js';
|
|
7
|
+
import type { ProviderConfig, ModelInfo } from '../providers/base-provider.js';
|
|
8
|
+
import { getProvider } from '../providers/index.js';
|
|
9
|
+
|
|
10
|
+
// Re-export ModelInfo for backward compatibility
|
|
11
|
+
export type { ModelInfo } from '../providers/base-provider.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetch models for a provider using provider registry
|
|
15
|
+
*/
|
|
16
|
+
export async function fetchModels(provider: ProviderId, config: ProviderConfig = {}): Promise<ModelInfo[]> {
|
|
17
|
+
const providerInstance = getProvider(provider);
|
|
18
|
+
return providerInstance.fetchModels(config);
|
|
19
|
+
}
|