aiexecode 1.0.94 → 1.0.96
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.
Potentially problematic release.
This version of aiexecode might be problematic. Click here for more details.
- package/README.md +210 -87
- package/index.js +33 -1
- package/package.json +3 -3
- package/payload_viewer/out/404/index.html +1 -1
- package/payload_viewer/out/404.html +1 -1
- package/payload_viewer/out/_next/static/chunks/{37d0cd2587a38f79.js → b6c0459f3789d25c.js} +1 -1
- package/payload_viewer/out/_next/static/chunks/b75131b58f8ca46a.css +3 -0
- package/payload_viewer/out/index.html +1 -1
- package/payload_viewer/out/index.txt +3 -3
- package/payload_viewer/web_server.js +361 -0
- package/src/LLMClient/client.js +392 -16
- package/src/LLMClient/converters/responses-to-claude.js +67 -18
- package/src/LLMClient/converters/responses-to-zai.js +608 -0
- package/src/LLMClient/errors.js +18 -4
- package/src/LLMClient/index.js +5 -0
- package/src/ai_based/completion_judge.js +35 -4
- package/src/ai_based/orchestrator.js +146 -35
- package/src/commands/agents.js +70 -0
- package/src/commands/commands.js +51 -0
- package/src/commands/debug.js +52 -0
- package/src/commands/help.js +11 -1
- package/src/commands/model.js +43 -7
- package/src/commands/skills.js +46 -0
- package/src/config/ai_models.js +96 -5
- package/src/config/constants.js +71 -0
- package/src/frontend/components/HelpView.js +106 -2
- package/src/frontend/components/SetupWizard.js +53 -8
- package/src/frontend/utils/toolUIFormatter.js +261 -0
- package/src/system/agents_loader.js +289 -0
- package/src/system/ai_request.js +147 -9
- package/src/system/command_parser.js +33 -3
- package/src/system/conversation_state.js +265 -0
- package/src/system/custom_command_loader.js +386 -0
- package/src/system/session.js +59 -35
- package/src/system/skill_loader.js +318 -0
- package/src/system/tool_approval.js +10 -0
- package/src/tools/file_reader.js +49 -9
- package/src/tools/glob.js +0 -3
- package/src/tools/ripgrep.js +5 -7
- package/src/tools/skill_tool.js +122 -0
- package/src/tools/web_downloader.js +0 -3
- package/src/util/clone.js +174 -0
- package/src/util/config.js +38 -2
- package/src/util/config_migration.js +174 -0
- package/src/util/path_validator.js +178 -0
- package/src/util/prompt_loader.js +68 -1
- package/src/util/safe_fs.js +43 -3
- package/payload_viewer/out/_next/static/chunks/ecd2072ebf41611f.css +0 -3
- /package/payload_viewer/out/_next/static/{wkEKh6i9XPSyP6rjDRvHn → lHmNygVpv4N1VR0LdnwkJ}/_buildManifest.js +0 -0
- /package/payload_viewer/out/_next/static/{wkEKh6i9XPSyP6rjDRvHn → lHmNygVpv4N1VR0LdnwkJ}/_clientMiddlewareManifest.json +0 -0
- /package/payload_viewer/out/_next/static/{wkEKh6i9XPSyP6rjDRvHn → lHmNygVpv4N1VR0LdnwkJ}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool UI Formatter
|
|
3
|
+
* 도구 스키마에서 UI 포맷팅 로직을 분리하여 tools → frontend 의존성을 제거합니다.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { theme } from '../design/themeColors.js';
|
|
7
|
+
import { toDisplayPath } from '../../util/path_helper.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 도구별 UI 포맷터 정의
|
|
11
|
+
* 각 도구의 ui_display 설정을 중앙에서 관리합니다.
|
|
12
|
+
*/
|
|
13
|
+
export const toolUIFormatters = {
|
|
14
|
+
// ============================================
|
|
15
|
+
// File Reader
|
|
16
|
+
// ============================================
|
|
17
|
+
read_file: {
|
|
18
|
+
show_tool_call: true,
|
|
19
|
+
show_tool_result: true,
|
|
20
|
+
display_name: 'Read',
|
|
21
|
+
format_tool_call: (args) => {
|
|
22
|
+
return `(${toDisplayPath(args.filePath)})`;
|
|
23
|
+
},
|
|
24
|
+
format_tool_result: (result) => {
|
|
25
|
+
if (result.operation_successful) {
|
|
26
|
+
const lines = result.total_line_count || 0;
|
|
27
|
+
return {
|
|
28
|
+
type: 'formatted',
|
|
29
|
+
parts: [
|
|
30
|
+
{ text: 'Read ', style: {} },
|
|
31
|
+
{ text: String(lines), style: { color: theme.brand.light, bold: true } },
|
|
32
|
+
{ text: ` line${lines !== 1 ? 's' : ''}`, style: {} }
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return result.error_message || 'Error reading file';
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
read_file_range: {
|
|
41
|
+
show_tool_call: true,
|
|
42
|
+
show_tool_result: true,
|
|
43
|
+
display_name: 'Read',
|
|
44
|
+
format_tool_call: (args) => {
|
|
45
|
+
return `(${toDisplayPath(args.filePath)}, lines ${args.startLine}-${args.endLine})`;
|
|
46
|
+
},
|
|
47
|
+
format_tool_result: (result) => {
|
|
48
|
+
if (result.operation_successful) {
|
|
49
|
+
const lineCount = result.file_content ? result.file_content.split('\n').length : 0;
|
|
50
|
+
return {
|
|
51
|
+
type: 'formatted',
|
|
52
|
+
parts: [
|
|
53
|
+
{ text: 'Read ', style: {} },
|
|
54
|
+
{ text: String(lineCount), style: { color: theme.brand.light, bold: true } },
|
|
55
|
+
{ text: ` line${lineCount !== 1 ? 's' : ''}`, style: {} }
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return result.error_message || 'Error reading file';
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
// ============================================
|
|
64
|
+
// Code Editor
|
|
65
|
+
// ============================================
|
|
66
|
+
write_file: {
|
|
67
|
+
show_tool_call: true,
|
|
68
|
+
show_tool_result: true,
|
|
69
|
+
display_name: 'Write',
|
|
70
|
+
format_tool_call: (args) => {
|
|
71
|
+
return `(${toDisplayPath(args.file_path)})`;
|
|
72
|
+
},
|
|
73
|
+
format_tool_result: (result) => {
|
|
74
|
+
if (result.operation_successful) {
|
|
75
|
+
const lines = result.total_line_count || 0;
|
|
76
|
+
const action = result.file_existed ? 'Overwrote' : 'Created';
|
|
77
|
+
return {
|
|
78
|
+
type: 'formatted',
|
|
79
|
+
parts: [
|
|
80
|
+
{ text: `${action} `, style: {} },
|
|
81
|
+
{ text: String(lines), style: { color: theme.brand.light, bold: true } },
|
|
82
|
+
{ text: ` line${lines !== 1 ? 's' : ''}`, style: {} }
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return result.error_message || 'Error writing file';
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
edit_file_replace: {
|
|
91
|
+
show_tool_call: true,
|
|
92
|
+
show_tool_result: true,
|
|
93
|
+
display_name: 'Replace',
|
|
94
|
+
format_tool_call: (args) => {
|
|
95
|
+
return `(${toDisplayPath(args.file_path)})`;
|
|
96
|
+
},
|
|
97
|
+
format_tool_result: (result) => {
|
|
98
|
+
if (result.operation_successful) {
|
|
99
|
+
const count = result.replacement_count || 0;
|
|
100
|
+
return {
|
|
101
|
+
type: 'formatted',
|
|
102
|
+
parts: [
|
|
103
|
+
{ text: 'Replaced ', style: {} },
|
|
104
|
+
{ text: String(count), style: { color: theme.brand.light, bold: true } },
|
|
105
|
+
{ text: ` occurrence${count !== 1 ? 's' : ''}`, style: {} }
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return result.error_message || 'Error replacing string';
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
edit_file_range: {
|
|
114
|
+
show_tool_call: true,
|
|
115
|
+
show_tool_result: true,
|
|
116
|
+
display_name: 'Edit',
|
|
117
|
+
format_tool_call: (args) => {
|
|
118
|
+
return `(${toDisplayPath(args.file_path)}, lines ${args.start_line}-${args.end_line})`;
|
|
119
|
+
},
|
|
120
|
+
format_tool_result: (result) => {
|
|
121
|
+
if (result.operation_successful) {
|
|
122
|
+
const op = result.operation_type;
|
|
123
|
+
if (op === 'delete') {
|
|
124
|
+
return `Deleted lines`;
|
|
125
|
+
} else if (op === 'insert') {
|
|
126
|
+
return `Inserted lines`;
|
|
127
|
+
} else {
|
|
128
|
+
return `Replaced lines`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result.error_message || 'Error editing file';
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// ============================================
|
|
136
|
+
// Search Tools
|
|
137
|
+
// ============================================
|
|
138
|
+
glob_search: {
|
|
139
|
+
show_tool_call: true,
|
|
140
|
+
show_tool_result: true,
|
|
141
|
+
display_name: 'Search',
|
|
142
|
+
format_tool_call: (args) => {
|
|
143
|
+
const pattern = args.pattern || '';
|
|
144
|
+
return `(${pattern})`;
|
|
145
|
+
},
|
|
146
|
+
format_tool_result: (result) => {
|
|
147
|
+
if (result.operation_successful) {
|
|
148
|
+
const matches = result.total_matches || 0;
|
|
149
|
+
return {
|
|
150
|
+
type: 'formatted',
|
|
151
|
+
parts: [
|
|
152
|
+
{ text: 'Found ', style: {} },
|
|
153
|
+
{ text: String(matches), style: { color: theme.brand.light, bold: true } },
|
|
154
|
+
{ text: ` match${matches !== 1 ? 'es' : ''}`, style: {} }
|
|
155
|
+
]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return result.error_message || 'Search failed';
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
ripgrep: {
|
|
163
|
+
show_tool_call: true,
|
|
164
|
+
show_tool_result: true,
|
|
165
|
+
display_name: 'Grep',
|
|
166
|
+
format_tool_call: (args) => {
|
|
167
|
+
const pattern = args.pattern || '';
|
|
168
|
+
const shortened = pattern.length > 30 ? pattern.substring(0, 27) + '...' : pattern;
|
|
169
|
+
return `(${shortened})`;
|
|
170
|
+
},
|
|
171
|
+
format_tool_result: (result) => {
|
|
172
|
+
if (result.operation_successful) {
|
|
173
|
+
const matches = result.totalMatches || 0;
|
|
174
|
+
return {
|
|
175
|
+
type: 'formatted',
|
|
176
|
+
parts: [
|
|
177
|
+
{ text: 'Found ', style: {} },
|
|
178
|
+
{ text: String(matches), style: { color: theme.brand.light, bold: true } },
|
|
179
|
+
{ text: ` match${matches !== 1 ? 'es' : ''}`, style: {} }
|
|
180
|
+
]
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return result.error_message || 'Search failed';
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
// ============================================
|
|
188
|
+
// Web Downloader
|
|
189
|
+
// ============================================
|
|
190
|
+
fetch_web_page: {
|
|
191
|
+
show_tool_call: true,
|
|
192
|
+
show_tool_result: true,
|
|
193
|
+
display_name: 'Fetch',
|
|
194
|
+
format_tool_call: (args) => {
|
|
195
|
+
const url = args.url || '';
|
|
196
|
+
const shortened = url.length > 50 ? url.substring(0, 47) + '...' : url;
|
|
197
|
+
return `(${shortened})`;
|
|
198
|
+
},
|
|
199
|
+
format_tool_result: (result) => {
|
|
200
|
+
if (result.operation_successful) {
|
|
201
|
+
const contentLength = result.content?.length || 0;
|
|
202
|
+
return {
|
|
203
|
+
type: 'formatted',
|
|
204
|
+
parts: [
|
|
205
|
+
{ text: 'Fetched ', style: {} },
|
|
206
|
+
{ text: String(contentLength), style: { color: theme.brand.light, bold: true } },
|
|
207
|
+
{ text: ' characters', style: {} }
|
|
208
|
+
]
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return result.error_message || 'Fetch failed';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 도구 이름으로 UI 포맷터를 가져옵니다.
|
|
218
|
+
* @param {string} toolName - 도구 이름
|
|
219
|
+
* @returns {Object|null} UI 포맷터 또는 null
|
|
220
|
+
*/
|
|
221
|
+
export function getToolUIFormatter(toolName) {
|
|
222
|
+
return toolUIFormatters[toolName] || null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 도구 호출을 포맷팅합니다.
|
|
227
|
+
* @param {string} toolName - 도구 이름
|
|
228
|
+
* @param {Object} args - 도구 인자
|
|
229
|
+
* @returns {string} 포맷팅된 문자열
|
|
230
|
+
*/
|
|
231
|
+
export function formatToolCall(toolName, args) {
|
|
232
|
+
const formatter = getToolUIFormatter(toolName);
|
|
233
|
+
if (formatter && formatter.format_tool_call) {
|
|
234
|
+
return formatter.format_tool_call(args);
|
|
235
|
+
}
|
|
236
|
+
return `(${JSON.stringify(args)})`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 도구 결과를 포맷팅합니다.
|
|
241
|
+
* @param {string} toolName - 도구 이름
|
|
242
|
+
* @param {Object} result - 도구 실행 결과
|
|
243
|
+
* @returns {string|Object} 포맷팅된 결과
|
|
244
|
+
*/
|
|
245
|
+
export function formatToolResult(toolName, result) {
|
|
246
|
+
const formatter = getToolUIFormatter(toolName);
|
|
247
|
+
if (formatter && formatter.format_tool_result) {
|
|
248
|
+
return formatter.format_tool_result(result);
|
|
249
|
+
}
|
|
250
|
+
return result.operation_successful ? 'Success' : (result.error_message || 'Error');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 도구의 표시 이름을 가져옵니다.
|
|
255
|
+
* @param {string} toolName - 도구 이름
|
|
256
|
+
* @returns {string} 표시 이름
|
|
257
|
+
*/
|
|
258
|
+
export function getToolDisplayName(toolName) {
|
|
259
|
+
const formatter = getToolUIFormatter(toolName);
|
|
260
|
+
return formatter?.display_name || toolName;
|
|
261
|
+
}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AGENTS.md Loader
|
|
3
|
+
*
|
|
4
|
+
* AGENTS.md는 AI 코딩 에이전트를 위한 오픈 표준 포맷입니다.
|
|
5
|
+
* README.md가 인간을 위한 것이라면, AGENTS.md는 AI 에이전트를 위한 것입니다.
|
|
6
|
+
*
|
|
7
|
+
* 파일 위치 및 우선순위 (높은 순):
|
|
8
|
+
* 1. CWD/AGENTS.md - 현재 작업 디렉토리
|
|
9
|
+
* 2. CWD/.aiexe/AGENTS.md - 프로젝트별 설정
|
|
10
|
+
* 3. ~/.aiexe/AGENTS.md - 글로벌 설정
|
|
11
|
+
*
|
|
12
|
+
* 하위 디렉토리 지원:
|
|
13
|
+
* - 하위 디렉토리에 AGENTS.md가 있으면 해당 디렉토리 작업 시 추가로 로드
|
|
14
|
+
* - 가장 가까운 AGENTS.md가 우선순위를 가짐
|
|
15
|
+
*
|
|
16
|
+
* 참조: https://agents.md/
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { join, dirname, resolve } from 'path';
|
|
20
|
+
import { safeReadFile, safeAccess, safeStat } from '../util/safe_fs.js';
|
|
21
|
+
import { CONFIG_DIR } from '../util/config.js';
|
|
22
|
+
import { createDebugLogger } from '../util/debug_log.js';
|
|
23
|
+
|
|
24
|
+
const debugLog = createDebugLogger('agents_loader.log', 'agents_loader');
|
|
25
|
+
|
|
26
|
+
// AGENTS.md 파일명 (대소문자 구분)
|
|
27
|
+
const AGENTS_MD_FILENAME = 'AGENTS.md';
|
|
28
|
+
|
|
29
|
+
// 권장 최대 줄 수 (GitHub 분석 기반)
|
|
30
|
+
const RECOMMENDED_MAX_LINES = 150;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 파일이 존재하는지 확인합니다.
|
|
34
|
+
* @param {string} filePath - 확인할 파일 경로
|
|
35
|
+
* @returns {Promise<boolean>}
|
|
36
|
+
*/
|
|
37
|
+
async function fileExists(filePath) {
|
|
38
|
+
try {
|
|
39
|
+
await safeAccess(filePath);
|
|
40
|
+
const stat = await safeStat(filePath);
|
|
41
|
+
return stat.isFile();
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* AGENTS.md 파일을 로드합니다.
|
|
49
|
+
* @param {string} filePath - AGENTS.md 파일 경로
|
|
50
|
+
* @returns {Promise<{path: string, content: string}|null>}
|
|
51
|
+
*/
|
|
52
|
+
async function loadAgentsMd(filePath) {
|
|
53
|
+
try {
|
|
54
|
+
if (!await fileExists(filePath)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const content = await safeReadFile(filePath, 'utf8');
|
|
58
|
+
const trimmedContent = content.trim();
|
|
59
|
+
const lineCount = trimmedContent.split('\n').length;
|
|
60
|
+
|
|
61
|
+
debugLog(`[loadAgentsMd] Loaded: ${filePath} (${trimmedContent.length} chars, ${lineCount} lines)`);
|
|
62
|
+
|
|
63
|
+
// 권장 크기 초과 시 경고
|
|
64
|
+
if (lineCount > RECOMMENDED_MAX_LINES) {
|
|
65
|
+
debugLog(`[loadAgentsMd] WARNING: ${filePath} has ${lineCount} lines (recommended: <=${RECOMMENDED_MAX_LINES})`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
path: filePath,
|
|
70
|
+
content: trimmedContent,
|
|
71
|
+
lineCount
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
debugLog(`[loadAgentsMd] Error loading ${filePath}: ${error.message}`);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 디렉토리에서 상위로 올라가며 AGENTS.md를 찾습니다.
|
|
81
|
+
* @param {string} startDir - 시작 디렉토리
|
|
82
|
+
* @param {string} [stopAt] - 여기까지만 탐색 (기본: 루트)
|
|
83
|
+
* @returns {Promise<{path: string, content: string}|null>}
|
|
84
|
+
*/
|
|
85
|
+
async function findAgentsMdUpward(startDir, stopAt = '/') {
|
|
86
|
+
let currentDir = resolve(startDir);
|
|
87
|
+
const stopDir = resolve(stopAt);
|
|
88
|
+
|
|
89
|
+
while (currentDir && currentDir !== stopDir) {
|
|
90
|
+
const agentsMdPath = join(currentDir, AGENTS_MD_FILENAME);
|
|
91
|
+
|
|
92
|
+
const result = await loadAgentsMd(agentsMdPath);
|
|
93
|
+
if (result) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const parentDir = dirname(currentDir);
|
|
98
|
+
if (parentDir === currentDir) {
|
|
99
|
+
break; // 루트에 도달
|
|
100
|
+
}
|
|
101
|
+
currentDir = parentDir;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 모든 관련 AGENTS.md 파일을 수집합니다.
|
|
109
|
+
* 우선순위 순서로 반환 (높은 우선순위가 먼저)
|
|
110
|
+
*
|
|
111
|
+
* @param {string} [cwd] - 현재 작업 디렉토리 (기본: process.cwd())
|
|
112
|
+
* @returns {Promise<Array<{path: string, content: string, source: string}>>}
|
|
113
|
+
*/
|
|
114
|
+
export async function discoverAllAgentsMd(cwd = process.cwd()) {
|
|
115
|
+
debugLog(`[discoverAllAgentsMd] Starting discovery from: ${cwd}`);
|
|
116
|
+
|
|
117
|
+
const results = [];
|
|
118
|
+
|
|
119
|
+
// 1. CWD/AGENTS.md (최고 우선순위)
|
|
120
|
+
const cwdAgentsMd = await loadAgentsMd(join(cwd, AGENTS_MD_FILENAME));
|
|
121
|
+
if (cwdAgentsMd) {
|
|
122
|
+
results.push({
|
|
123
|
+
...cwdAgentsMd,
|
|
124
|
+
source: 'project'
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 2. CWD/.aiexe/AGENTS.md (프로젝트별 설정)
|
|
129
|
+
const projectAgentsMd = await loadAgentsMd(join(cwd, '.aiexe', AGENTS_MD_FILENAME));
|
|
130
|
+
if (projectAgentsMd) {
|
|
131
|
+
results.push({
|
|
132
|
+
...projectAgentsMd,
|
|
133
|
+
source: 'project-config'
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 3. 상위 디렉토리 탐색 (CWD가 아닌 상위에서)
|
|
138
|
+
const parentAgentsMd = await findAgentsMdUpward(dirname(cwd));
|
|
139
|
+
if (parentAgentsMd && !results.some(r => r.path === parentAgentsMd.path)) {
|
|
140
|
+
results.push({
|
|
141
|
+
...parentAgentsMd,
|
|
142
|
+
source: 'parent'
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 4. ~/.aiexe/AGENTS.md (글로벌 설정 - 가장 낮은 우선순위)
|
|
147
|
+
const globalAgentsMd = await loadAgentsMd(join(CONFIG_DIR, AGENTS_MD_FILENAME));
|
|
148
|
+
if (globalAgentsMd && !results.some(r => r.path === globalAgentsMd.path)) {
|
|
149
|
+
results.push({
|
|
150
|
+
...globalAgentsMd,
|
|
151
|
+
source: 'global'
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
debugLog(`[discoverAllAgentsMd] Found ${results.length} AGENTS.md files`);
|
|
156
|
+
return results;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 특정 파일/디렉토리에 가장 가까운 AGENTS.md를 찾습니다.
|
|
161
|
+
* 하위 디렉토리 작업 시 해당 디렉토리의 AGENTS.md를 우선 사용
|
|
162
|
+
*
|
|
163
|
+
* @param {string} targetPath - 대상 파일 또는 디렉토리 경로
|
|
164
|
+
* @returns {Promise<{path: string, content: string}|null>}
|
|
165
|
+
*/
|
|
166
|
+
export async function findNearestAgentsMd(targetPath) {
|
|
167
|
+
const resolvedPath = resolve(targetPath);
|
|
168
|
+
|
|
169
|
+
// 파일인지 디렉토리인지 확인
|
|
170
|
+
let startDir;
|
|
171
|
+
try {
|
|
172
|
+
const stat = await safeStat(resolvedPath);
|
|
173
|
+
startDir = stat.isDirectory() ? resolvedPath : dirname(resolvedPath);
|
|
174
|
+
} catch {
|
|
175
|
+
startDir = dirname(resolvedPath);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
debugLog(`[findNearestAgentsMd] Searching from: ${startDir}`);
|
|
179
|
+
return await findAgentsMdUpward(startDir);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* AGENTS.md 내용을 시스템 프롬프트용 텍스트로 포맷팅합니다.
|
|
184
|
+
* @param {Array<{path: string, content: string, source: string}>} agentsMdFiles
|
|
185
|
+
* @returns {string}
|
|
186
|
+
*/
|
|
187
|
+
export function formatAgentsMdForPrompt(agentsMdFiles) {
|
|
188
|
+
if (!agentsMdFiles || agentsMdFiles.length === 0) {
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const sections = [];
|
|
193
|
+
|
|
194
|
+
for (const file of agentsMdFiles) {
|
|
195
|
+
const sourceLabel = {
|
|
196
|
+
'project': 'Project Root',
|
|
197
|
+
'project-config': 'Project Config (.aiexe/)',
|
|
198
|
+
'parent': 'Parent Directory',
|
|
199
|
+
'global': 'Global (~/.aiexe/)'
|
|
200
|
+
}[file.source] || file.source;
|
|
201
|
+
|
|
202
|
+
sections.push(`## AGENTS.md (${sourceLabel})\n**Path:** ${file.path}\n\n${file.content}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return `\n\n# Agent Instructions (AGENTS.md)\n\n` +
|
|
206
|
+
`The following instructions are from AGENTS.md files in the project.\n` +
|
|
207
|
+
`These provide project-specific guidance for AI coding agents.\n\n` +
|
|
208
|
+
sections.join('\n\n---\n\n') +
|
|
209
|
+
'\n';
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 현재 프로젝트의 AGENTS.md를 로드하고 포맷팅합니다.
|
|
214
|
+
* 시스템 프롬프트에 추가할 때 사용
|
|
215
|
+
*
|
|
216
|
+
* @param {string} [cwd] - 현재 작업 디렉토리
|
|
217
|
+
* @returns {Promise<string>} 포맷팅된 AGENTS.md 내용 (없으면 빈 문자열)
|
|
218
|
+
*/
|
|
219
|
+
export async function loadAgentsMdForPrompt(cwd = process.cwd()) {
|
|
220
|
+
const agentsMdFiles = await discoverAllAgentsMd(cwd);
|
|
221
|
+
return formatAgentsMdForPrompt(agentsMdFiles);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* AGENTS.md 정보를 요약하여 반환합니다.
|
|
226
|
+
* /agents 명령어용
|
|
227
|
+
*
|
|
228
|
+
* @param {string} [cwd] - 현재 작업 디렉토리
|
|
229
|
+
* @returns {Promise<string>}
|
|
230
|
+
*/
|
|
231
|
+
export async function formatAgentsMdSummary(cwd = process.cwd()) {
|
|
232
|
+
const agentsMdFiles = await discoverAllAgentsMd(cwd);
|
|
233
|
+
|
|
234
|
+
if (agentsMdFiles.length === 0) {
|
|
235
|
+
return [
|
|
236
|
+
'No AGENTS.md files found.',
|
|
237
|
+
'',
|
|
238
|
+
'AGENTS.md is an open standard for guiding AI coding agents.',
|
|
239
|
+
'',
|
|
240
|
+
'File locations (in priority order):',
|
|
241
|
+
' 1. CWD/AGENTS.md - Project root',
|
|
242
|
+
' 2. CWD/.aiexe/AGENTS.md - Project config',
|
|
243
|
+
' 3. ~/.aiexe/AGENTS.md - Global config',
|
|
244
|
+
'',
|
|
245
|
+
'Create an AGENTS.md file to provide project-specific instructions.',
|
|
246
|
+
'',
|
|
247
|
+
'Recommended sections:',
|
|
248
|
+
' - Commands (build, test)',
|
|
249
|
+
' - Testing guidelines',
|
|
250
|
+
' - Project structure',
|
|
251
|
+
' - Code style',
|
|
252
|
+
' - Git workflow',
|
|
253
|
+
' - Boundaries (what not to touch)',
|
|
254
|
+
'',
|
|
255
|
+
'Learn more: https://agents.md/'
|
|
256
|
+
].join('\n');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const lines = ['AGENTS.md Files:', ''];
|
|
260
|
+
|
|
261
|
+
for (const file of agentsMdFiles) {
|
|
262
|
+
const sourceLabel = {
|
|
263
|
+
'project': 'Project Root',
|
|
264
|
+
'project-config': 'Project Config',
|
|
265
|
+
'parent': 'Parent Directory',
|
|
266
|
+
'global': 'Global'
|
|
267
|
+
}[file.source] || file.source;
|
|
268
|
+
|
|
269
|
+
const lineCount = file.lineCount || file.content.split('\n').length;
|
|
270
|
+
const charCount = file.content.length;
|
|
271
|
+
const sizeWarning = lineCount > RECOMMENDED_MAX_LINES
|
|
272
|
+
? ` (exceeds recommended ${RECOMMENDED_MAX_LINES} lines)`
|
|
273
|
+
: '';
|
|
274
|
+
|
|
275
|
+
lines.push(`${sourceLabel}:`);
|
|
276
|
+
lines.push(` Path: ${file.path}`);
|
|
277
|
+
lines.push(` Size: ${lineCount} lines, ${charCount} chars${sizeWarning}`);
|
|
278
|
+
|
|
279
|
+
// 첫 3줄 미리보기
|
|
280
|
+
const preview = file.content.split('\n').slice(0, 3).join('\n');
|
|
281
|
+
lines.push(` Preview:`);
|
|
282
|
+
lines.push(` ${preview.replace(/\n/g, '\n ')}`);
|
|
283
|
+
lines.push('');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
lines.push('Use /agents <path> to view full content of a specific file.');
|
|
287
|
+
|
|
288
|
+
return lines.join('\n');
|
|
289
|
+
}
|