codemeld 2.1.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.
- package/README.md +514 -0
- package/bin/cli.js +2 -0
- package/dist/ai/agent.d.ts +124 -0
- package/dist/ai/agent.d.ts.map +1 -0
- package/dist/ai/agent.js +289 -0
- package/dist/ai/agent.js.map +1 -0
- package/dist/ai/index.d.ts +10 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +10 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/prompts.d.ts +35 -0
- package/dist/ai/prompts.d.ts.map +1 -0
- package/dist/ai/prompts.js +166 -0
- package/dist/ai/prompts.js.map +1 -0
- package/dist/ai/refinement-loop.d.ts +29 -0
- package/dist/ai/refinement-loop.d.ts.map +1 -0
- package/dist/ai/refinement-loop.js +180 -0
- package/dist/ai/refinement-loop.js.map +1 -0
- package/dist/ai/tools.d.ts +17 -0
- package/dist/ai/tools.d.ts.map +1 -0
- package/dist/ai/tools.js +353 -0
- package/dist/ai/tools.js.map +1 -0
- package/dist/ai/visual-compare.d.ts +43 -0
- package/dist/ai/visual-compare.d.ts.map +1 -0
- package/dist/ai/visual-compare.js +176 -0
- package/dist/ai/visual-compare.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +179 -0
- package/dist/cli.js.map +1 -0
- package/dist/converter.d.ts +10 -0
- package/dist/converter.d.ts.map +1 -0
- package/dist/converter.js +836 -0
- package/dist/converter.js.map +1 -0
- package/dist/deconverter.d.ts +19 -0
- package/dist/deconverter.d.ts.map +1 -0
- package/dist/deconverter.js +188 -0
- package/dist/deconverter.js.map +1 -0
- package/dist/frameworks/angular-adapter.d.ts +27 -0
- package/dist/frameworks/angular-adapter.d.ts.map +1 -0
- package/dist/frameworks/angular-adapter.js +617 -0
- package/dist/frameworks/angular-adapter.js.map +1 -0
- package/dist/frameworks/index.d.ts +10 -0
- package/dist/frameworks/index.d.ts.map +1 -0
- package/dist/frameworks/index.js +21 -0
- package/dist/frameworks/index.js.map +1 -0
- package/dist/frameworks/nextjs-adapter.d.ts +22 -0
- package/dist/frameworks/nextjs-adapter.d.ts.map +1 -0
- package/dist/frameworks/nextjs-adapter.js +392 -0
- package/dist/frameworks/nextjs-adapter.js.map +1 -0
- package/dist/frameworks/react-adapter.d.ts +21 -0
- package/dist/frameworks/react-adapter.d.ts.map +1 -0
- package/dist/frameworks/react-adapter.js +71 -0
- package/dist/frameworks/react-adapter.js.map +1 -0
- package/dist/frameworks/svelte-adapter.d.ts +27 -0
- package/dist/frameworks/svelte-adapter.d.ts.map +1 -0
- package/dist/frameworks/svelte-adapter.js +519 -0
- package/dist/frameworks/svelte-adapter.js.map +1 -0
- package/dist/frameworks/types.d.ts +78 -0
- package/dist/frameworks/types.d.ts.map +1 -0
- package/dist/frameworks/types.js +2 -0
- package/dist/frameworks/types.js.map +1 -0
- package/dist/frameworks/vue-adapter.d.ts +34 -0
- package/dist/frameworks/vue-adapter.d.ts.map +1 -0
- package/dist/frameworks/vue-adapter.js +632 -0
- package/dist/frameworks/vue-adapter.js.map +1 -0
- package/dist/generators/accessibility-generator.d.ts +43 -0
- package/dist/generators/accessibility-generator.d.ts.map +1 -0
- package/dist/generators/accessibility-generator.js +507 -0
- package/dist/generators/accessibility-generator.js.map +1 -0
- package/dist/generators/asset-handler.d.ts +14 -0
- package/dist/generators/asset-handler.d.ts.map +1 -0
- package/dist/generators/asset-handler.js +79 -0
- package/dist/generators/asset-handler.js.map +1 -0
- package/dist/generators/build-verifier.d.ts +8 -0
- package/dist/generators/build-verifier.d.ts.map +1 -0
- package/dist/generators/build-verifier.js +64 -0
- package/dist/generators/build-verifier.js.map +1 -0
- package/dist/generators/component-extractor.d.ts +25 -0
- package/dist/generators/component-extractor.d.ts.map +1 -0
- package/dist/generators/component-extractor.js +146 -0
- package/dist/generators/component-extractor.js.map +1 -0
- package/dist/generators/component-generator.d.ts +12 -0
- package/dist/generators/component-generator.d.ts.map +1 -0
- package/dist/generators/component-generator.js +724 -0
- package/dist/generators/component-generator.js.map +1 -0
- package/dist/generators/deploy-generator.d.ts +9 -0
- package/dist/generators/deploy-generator.d.ts.map +1 -0
- package/dist/generators/deploy-generator.js +409 -0
- package/dist/generators/deploy-generator.js.map +1 -0
- package/dist/generators/error-boundary.d.ts +5 -0
- package/dist/generators/error-boundary.d.ts.map +1 -0
- package/dist/generators/error-boundary.js +59 -0
- package/dist/generators/error-boundary.js.map +1 -0
- package/dist/generators/form-generator.d.ts +42 -0
- package/dist/generators/form-generator.d.ts.map +1 -0
- package/dist/generators/form-generator.js +662 -0
- package/dist/generators/form-generator.js.map +1 -0
- package/dist/generators/hooks-generator.d.ts +40 -0
- package/dist/generators/hooks-generator.d.ts.map +1 -0
- package/dist/generators/hooks-generator.js +297 -0
- package/dist/generators/hooks-generator.js.map +1 -0
- package/dist/generators/html-generator.d.ts +27 -0
- package/dist/generators/html-generator.d.ts.map +1 -0
- package/dist/generators/html-generator.js +772 -0
- package/dist/generators/html-generator.js.map +1 -0
- package/dist/generators/jquery-converter.d.ts +41 -0
- package/dist/generators/jquery-converter.d.ts.map +1 -0
- package/dist/generators/jquery-converter.js +594 -0
- package/dist/generators/jquery-converter.js.map +1 -0
- package/dist/generators/pattern-implementer.d.ts +26 -0
- package/dist/generators/pattern-implementer.d.ts.map +1 -0
- package/dist/generators/pattern-implementer.js +336 -0
- package/dist/generators/pattern-implementer.js.map +1 -0
- package/dist/generators/performance-generator.d.ts +51 -0
- package/dist/generators/performance-generator.d.ts.map +1 -0
- package/dist/generators/performance-generator.js +428 -0
- package/dist/generators/performance-generator.js.map +1 -0
- package/dist/generators/router-generator.d.ts +21 -0
- package/dist/generators/router-generator.d.ts.map +1 -0
- package/dist/generators/router-generator.js +178 -0
- package/dist/generators/router-generator.js.map +1 -0
- package/dist/generators/scaffolder.d.ts +28 -0
- package/dist/generators/scaffolder.d.ts.map +1 -0
- package/dist/generators/scaffolder.js +266 -0
- package/dist/generators/scaffolder.js.map +1 -0
- package/dist/generators/seo-generator.d.ts +29 -0
- package/dist/generators/seo-generator.d.ts.map +1 -0
- package/dist/generators/seo-generator.js +223 -0
- package/dist/generators/seo-generator.js.map +1 -0
- package/dist/generators/test-generator.d.ts +19 -0
- package/dist/generators/test-generator.d.ts.map +1 -0
- package/dist/generators/test-generator.js +398 -0
- package/dist/generators/test-generator.js.map +1 -0
- package/dist/generators/type-generator.d.ts +33 -0
- package/dist/generators/type-generator.d.ts.map +1 -0
- package/dist/generators/type-generator.js +663 -0
- package/dist/generators/type-generator.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/parsers/css-processor.d.ts +23 -0
- package/dist/parsers/css-processor.d.ts.map +1 -0
- package/dist/parsers/css-processor.js +129 -0
- package/dist/parsers/css-processor.js.map +1 -0
- package/dist/parsers/framework-parser.d.ts +48 -0
- package/dist/parsers/framework-parser.d.ts.map +1 -0
- package/dist/parsers/framework-parser.js +770 -0
- package/dist/parsers/framework-parser.js.map +1 -0
- package/dist/parsers/html-parser.d.ts +12 -0
- package/dist/parsers/html-parser.d.ts.map +1 -0
- package/dist/parsers/html-parser.js +444 -0
- package/dist/parsers/html-parser.js.map +1 -0
- package/dist/parsers/js-analyzer.d.ts +199 -0
- package/dist/parsers/js-analyzer.d.ts.map +1 -0
- package/dist/parsers/js-analyzer.js +680 -0
- package/dist/parsers/js-analyzer.js.map +1 -0
- package/dist/parsers/js-resolver.d.ts +8 -0
- package/dist/parsers/js-resolver.d.ts.map +1 -0
- package/dist/parsers/js-resolver.js +45 -0
- package/dist/parsers/js-resolver.js.map +1 -0
- package/dist/parsers/tailwind-detector.d.ts +23 -0
- package/dist/parsers/tailwind-detector.d.ts.map +1 -0
- package/dist/parsers/tailwind-detector.js +104 -0
- package/dist/parsers/tailwind-detector.js.map +1 -0
- package/dist/tests/advanced-features.test.d.ts +2 -0
- package/dist/tests/advanced-features.test.d.ts.map +1 -0
- package/dist/tests/advanced-features.test.js +235 -0
- package/dist/tests/advanced-features.test.js.map +1 -0
- package/dist/tests/css-modules.test.d.ts +2 -0
- package/dist/tests/css-modules.test.d.ts.map +1 -0
- package/dist/tests/css-modules.test.js +61 -0
- package/dist/tests/css-modules.test.js.map +1 -0
- package/dist/tests/css-processor.test.d.ts +2 -0
- package/dist/tests/css-processor.test.d.ts.map +1 -0
- package/dist/tests/css-processor.test.js +48 -0
- package/dist/tests/css-processor.test.js.map +1 -0
- package/dist/tests/html-parser.test.d.ts +2 -0
- package/dist/tests/html-parser.test.d.ts.map +1 -0
- package/dist/tests/html-parser.test.js +78 -0
- package/dist/tests/html-parser.test.js.map +1 -0
- package/dist/tests/integration.test.d.ts +2 -0
- package/dist/tests/integration.test.d.ts.map +1 -0
- package/dist/tests/integration.test.js +65 -0
- package/dist/tests/integration.test.js.map +1 -0
- package/dist/tests/js-analyzer.test.d.ts +2 -0
- package/dist/tests/js-analyzer.test.d.ts.map +1 -0
- package/dist/tests/js-analyzer.test.js +58 -0
- package/dist/tests/js-analyzer.test.js.map +1 -0
- package/dist/tests/naming.test.d.ts +2 -0
- package/dist/tests/naming.test.d.ts.map +1 -0
- package/dist/tests/naming.test.js +43 -0
- package/dist/tests/naming.test.js.map +1 -0
- package/dist/tests/router-generator.test.d.ts +2 -0
- package/dist/tests/router-generator.test.d.ts.map +1 -0
- package/dist/tests/router-generator.test.js +60 -0
- package/dist/tests/router-generator.test.js.map +1 -0
- package/dist/tui/chat.d.ts +13 -0
- package/dist/tui/chat.d.ts.map +1 -0
- package/dist/tui/chat.js +499 -0
- package/dist/tui/chat.js.map +1 -0
- package/dist/tui/design-guide.d.ts +41 -0
- package/dist/tui/design-guide.d.ts.map +1 -0
- package/dist/tui/design-guide.js +184 -0
- package/dist/tui/design-guide.js.map +1 -0
- package/dist/tui/input.d.ts +30 -0
- package/dist/tui/input.d.ts.map +1 -0
- package/dist/tui/input.js +239 -0
- package/dist/tui/input.js.map +1 -0
- package/dist/tui/renderer.d.ts +48 -0
- package/dist/tui/renderer.d.ts.map +1 -0
- package/dist/tui/renderer.js +212 -0
- package/dist/tui/renderer.js.map +1 -0
- package/dist/tui/tools.d.ts +14 -0
- package/dist/tui/tools.d.ts.map +1 -0
- package/dist/tui/tools.js +1370 -0
- package/dist/tui/tools.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/config.d.ts +20 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +33 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/formatter.d.ts +5 -0
- package/dist/utils/formatter.d.ts.map +1 -0
- package/dist/utils/formatter.js +68 -0
- package/dist/utils/formatter.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +19 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/naming.d.ts +17 -0
- package/dist/utils/naming.d.ts.map +1 -0
- package/dist/utils/naming.js +48 -0
- package/dist/utils/naming.js.map +1 -0
- package/dist/utils/report.d.ts +56 -0
- package/dist/utils/report.d.ts.map +1 -0
- package/dist/utils/report.js +339 -0
- package/dist/utils/report.js.map +1 -0
- package/package.json +61 -0
package/dist/ai/agent.js
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Agent Client — OpenAI-compatible chat completions wrapper
|
|
3
|
+
* Uses the3rdacademy.com/api/chat/completions (no API key required)
|
|
4
|
+
* Uses native Node.js fetch — no curl dependency, no timeouts from external processes.
|
|
5
|
+
*/
|
|
6
|
+
const API_URL = 'https://the3rdacademy.com/api/chat/completions';
|
|
7
|
+
const REQUEST_TIMEOUT_MS = 180_000; // 3 minutes — generous for large payloads
|
|
8
|
+
const MAX_RETRIES = 3;
|
|
9
|
+
const MAX_TOOL_RESULT_LEN = 12_000; // Prevent payload bloat from large tool outputs
|
|
10
|
+
// ─── Helpers ──────────────────────────────────────────────────────────
|
|
11
|
+
function sleep(ms) {
|
|
12
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Truncate a tool result to prevent bloating the conversation payload.
|
|
16
|
+
*/
|
|
17
|
+
export function truncateToolResult(result, maxLen = MAX_TOOL_RESULT_LEN) {
|
|
18
|
+
if (result.length <= maxLen)
|
|
19
|
+
return result;
|
|
20
|
+
return result.slice(0, maxLen) + `\n\n... (truncated, ${result.length} total chars)`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sanitize an error — never leak API URLs, internal paths, or raw HTTP details.
|
|
24
|
+
*/
|
|
25
|
+
function sanitizeError(err) {
|
|
26
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
27
|
+
if (msg.includes('AbortError') || msg.includes('abort') || msg.includes('timed out') || msg.includes('timeout')) {
|
|
28
|
+
return new Error('AI request timed out. Please try again.');
|
|
29
|
+
}
|
|
30
|
+
if (msg.includes('ECONNREFUSED') || msg.includes('ENOTFOUND') || msg.includes('ECONNRESET') || msg.includes('fetch failed')) {
|
|
31
|
+
return new Error('Could not connect to AI service. Check your network connection.');
|
|
32
|
+
}
|
|
33
|
+
if (msg.includes('ECONNABORTED') || msg.includes('socket hang up')) {
|
|
34
|
+
return new Error('Connection to AI service was interrupted. Please try again.');
|
|
35
|
+
}
|
|
36
|
+
return new Error('AI request failed. Please try again.');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if an API error response is worth retrying (502/504/overloaded).
|
|
40
|
+
*/
|
|
41
|
+
function isRetryable(parsed) {
|
|
42
|
+
if (!parsed.error)
|
|
43
|
+
return false;
|
|
44
|
+
const errStr = typeof parsed.error === 'string' ? parsed.error : JSON.stringify(parsed.error);
|
|
45
|
+
return /50[2-4]|gateway|time-?out|overloaded|rate.?limit/i.test(errStr);
|
|
46
|
+
}
|
|
47
|
+
// ─── Native fetch POST ───────────────────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* POST JSON to the API using native Node.js fetch.
|
|
50
|
+
* No curl dependency, no temp files, no ENAMETOOLONG, no shell limits.
|
|
51
|
+
*/
|
|
52
|
+
async function fetchPost(payload, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
55
|
+
try {
|
|
56
|
+
const response = await fetch(API_URL, {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
body: payload,
|
|
60
|
+
signal: controller.signal,
|
|
61
|
+
});
|
|
62
|
+
const text = await response.text();
|
|
63
|
+
if (!response.ok && !text.trim()) {
|
|
64
|
+
throw new Error(`HTTP ${response.status}`);
|
|
65
|
+
}
|
|
66
|
+
return text;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
throw sanitizeError(err);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// ─── Chat Completion (non-streaming) ─────────────────────────────────
|
|
76
|
+
/**
|
|
77
|
+
* Send a non-streaming chat completion request.
|
|
78
|
+
* Retries up to 3 times on server-side gateway errors with exponential backoff.
|
|
79
|
+
*/
|
|
80
|
+
export async function chatCompletion(request) {
|
|
81
|
+
const payload = JSON.stringify({
|
|
82
|
+
...request,
|
|
83
|
+
stream: false,
|
|
84
|
+
direct_kilo: request.direct_kilo ?? true,
|
|
85
|
+
// Prevent server-side tool execution — all tools are client-side
|
|
86
|
+
disable_built_in_tools: true,
|
|
87
|
+
built_in_tools: [],
|
|
88
|
+
});
|
|
89
|
+
let lastError = null;
|
|
90
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
91
|
+
if (attempt > 0) {
|
|
92
|
+
await sleep(Math.min(2000 * Math.pow(2, attempt - 1), 16000));
|
|
93
|
+
}
|
|
94
|
+
let body;
|
|
95
|
+
try {
|
|
96
|
+
body = await fetchPost(payload);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
100
|
+
if (attempt < MAX_RETRIES)
|
|
101
|
+
continue;
|
|
102
|
+
throw lastError;
|
|
103
|
+
}
|
|
104
|
+
if (!body.trim()) {
|
|
105
|
+
lastError = new Error('AI service returned an empty response. Please try again.');
|
|
106
|
+
if (attempt < MAX_RETRIES)
|
|
107
|
+
continue;
|
|
108
|
+
throw lastError;
|
|
109
|
+
}
|
|
110
|
+
let parsed;
|
|
111
|
+
try {
|
|
112
|
+
parsed = JSON.parse(body);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Could be HTML error page from nginx — retryable
|
|
116
|
+
lastError = new Error('AI service returned an invalid response. Please try again.');
|
|
117
|
+
if (attempt < MAX_RETRIES)
|
|
118
|
+
continue;
|
|
119
|
+
throw lastError;
|
|
120
|
+
}
|
|
121
|
+
if (parsed.error) {
|
|
122
|
+
if (isRetryable(parsed) && attempt < MAX_RETRIES) {
|
|
123
|
+
lastError = new Error('AI service returned an error. Please try again later.');
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
throw new Error('AI service returned an error. Please try again later.');
|
|
127
|
+
}
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
throw lastError || new Error('AI request failed after retries. Please try again.');
|
|
131
|
+
}
|
|
132
|
+
// ─── Chat Completion (streaming) ─────────────────────────────────────
|
|
133
|
+
/**
|
|
134
|
+
* Send a streaming chat completion request.
|
|
135
|
+
* Returns accumulated content and any tool calls.
|
|
136
|
+
*/
|
|
137
|
+
export async function chatCompletionStream(request, onEvent) {
|
|
138
|
+
const payload = JSON.stringify({
|
|
139
|
+
...request,
|
|
140
|
+
stream: true,
|
|
141
|
+
direct_kilo: request.direct_kilo ?? true,
|
|
142
|
+
disable_built_in_tools: true,
|
|
143
|
+
built_in_tools: [],
|
|
144
|
+
});
|
|
145
|
+
const body = await fetchPost(payload);
|
|
146
|
+
let content = '';
|
|
147
|
+
const toolCalls = [];
|
|
148
|
+
let finishReason = '';
|
|
149
|
+
for (const line of body.split('\n')) {
|
|
150
|
+
if (!line.startsWith('data: ') || line === 'data: [DONE]')
|
|
151
|
+
continue;
|
|
152
|
+
let chunk;
|
|
153
|
+
try {
|
|
154
|
+
chunk = JSON.parse(line.slice(6));
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const delta = chunk.choices[0]?.delta;
|
|
160
|
+
const reason = chunk.choices[0]?.finish_reason;
|
|
161
|
+
if (reason)
|
|
162
|
+
finishReason = reason;
|
|
163
|
+
if (delta?.content) {
|
|
164
|
+
content += delta.content;
|
|
165
|
+
onEvent?.({ type: 'token', content: delta.content });
|
|
166
|
+
}
|
|
167
|
+
if (delta?.custom_status) {
|
|
168
|
+
if (delta.custom_status.type === 'tool_start') {
|
|
169
|
+
onEvent?.({ type: 'tool_start', toolName: delta.custom_status.name });
|
|
170
|
+
}
|
|
171
|
+
else if (delta.custom_status.type === 'tool_done') {
|
|
172
|
+
onEvent?.({ type: 'tool_done', toolName: delta.custom_status.name });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (delta?.tool_calls) {
|
|
176
|
+
for (const tc of delta.tool_calls) {
|
|
177
|
+
if (!toolCalls[tc.index]) {
|
|
178
|
+
toolCalls[tc.index] = {
|
|
179
|
+
id: tc.id || '',
|
|
180
|
+
type: tc.type || 'function',
|
|
181
|
+
function: { name: tc.function?.name || '', arguments: '' },
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (tc.id)
|
|
185
|
+
toolCalls[tc.index].id = tc.id;
|
|
186
|
+
if (tc.function?.name)
|
|
187
|
+
toolCalls[tc.index].function.name = tc.function.name;
|
|
188
|
+
if (tc.function?.arguments)
|
|
189
|
+
toolCalls[tc.index].function.arguments += tc.function.arguments;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (finishReason === 'tool_calls') {
|
|
194
|
+
onEvent?.({ type: 'tool_calls', toolCalls: toolCalls.filter(Boolean) });
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
onEvent?.({ type: 'done', content });
|
|
198
|
+
}
|
|
199
|
+
return { content, toolCalls: toolCalls.filter(Boolean), finishReason };
|
|
200
|
+
}
|
|
201
|
+
// ─── Agent Loop ──────────────────────────────────────────────────────
|
|
202
|
+
/**
|
|
203
|
+
* Run a full agent loop: send messages, execute tool calls, repeat until done.
|
|
204
|
+
*/
|
|
205
|
+
export async function agentLoop(systemPrompt, userMessage, tools, toolExecutor, options = {}) {
|
|
206
|
+
const { maxSteps = 50, temperature = 0.3, onEvent, onStep } = options;
|
|
207
|
+
const messages = [
|
|
208
|
+
{ role: 'system', content: systemPrompt },
|
|
209
|
+
{ role: 'user', content: userMessage },
|
|
210
|
+
];
|
|
211
|
+
let step = 0;
|
|
212
|
+
let finalContent = '';
|
|
213
|
+
let consecutiveCheckCalls = 0;
|
|
214
|
+
while (step < maxSteps) {
|
|
215
|
+
step++;
|
|
216
|
+
onStep?.(step, maxSteps, 'Thinking...');
|
|
217
|
+
const response = await chatCompletion({
|
|
218
|
+
messages,
|
|
219
|
+
tools,
|
|
220
|
+
temperature,
|
|
221
|
+
max_tokens: 16000,
|
|
222
|
+
});
|
|
223
|
+
const choice = response.choices[0];
|
|
224
|
+
const content = choice.message.content || '';
|
|
225
|
+
const toolCalls = choice.message.tool_calls || [];
|
|
226
|
+
const finishReason = choice.finish_reason;
|
|
227
|
+
if (content) {
|
|
228
|
+
onEvent?.({ type: 'token', content });
|
|
229
|
+
}
|
|
230
|
+
if (finishReason === 'stop' || toolCalls.length === 0) {
|
|
231
|
+
finalContent = content;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
messages.push({
|
|
235
|
+
role: 'assistant',
|
|
236
|
+
content: content || null,
|
|
237
|
+
tool_calls: toolCalls,
|
|
238
|
+
});
|
|
239
|
+
// Track tool usage patterns to detect loops
|
|
240
|
+
const toolNames = toolCalls.map(tc => tc.function.name);
|
|
241
|
+
const hasFileOp = toolNames.some(n => n === 'read_file' || n === 'write_file' || n === 'read_original_file' || n === 'list_files');
|
|
242
|
+
const hasCheckOp = toolNames.some(n => n === 'run_build' || n === 'run_typecheck');
|
|
243
|
+
if (hasCheckOp && !hasFileOp) {
|
|
244
|
+
consecutiveCheckCalls++;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
consecutiveCheckCalls = 0;
|
|
248
|
+
}
|
|
249
|
+
// Execute each tool call
|
|
250
|
+
for (const tc of toolCalls) {
|
|
251
|
+
const funcName = tc.function.name;
|
|
252
|
+
let args;
|
|
253
|
+
try {
|
|
254
|
+
args = JSON.parse(tc.function.arguments);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
args = {};
|
|
258
|
+
}
|
|
259
|
+
onStep?.(step, maxSteps, `Executing ${funcName}...`);
|
|
260
|
+
let result;
|
|
261
|
+
try {
|
|
262
|
+
result = await toolExecutor(funcName, args);
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
result = `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
266
|
+
}
|
|
267
|
+
// Truncate large tool results to prevent payload bloat
|
|
268
|
+
result = truncateToolResult(result);
|
|
269
|
+
messages.push({
|
|
270
|
+
role: 'tool',
|
|
271
|
+
tool_call_id: tc.id,
|
|
272
|
+
content: result,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
// If AI is stuck in a check loop, inject a directive
|
|
276
|
+
if (consecutiveCheckCalls >= 2) {
|
|
277
|
+
messages.push({
|
|
278
|
+
role: 'user',
|
|
279
|
+
content: 'IMPORTANT: You have run build/typecheck multiple times without fixing any files. You MUST now call read_file on the first file that has errors, then call write_file with the fixed content. Do NOT call run_build or run_typecheck again until you have fixed at least one file.',
|
|
280
|
+
});
|
|
281
|
+
consecutiveCheckCalls = 0;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (step >= maxSteps && !finalContent) {
|
|
285
|
+
finalContent = 'AI agent reached maximum steps without completing. The output may need manual review.';
|
|
286
|
+
}
|
|
287
|
+
return finalContent;
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/ai/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,OAAO,GAAG,gDAAgD,CAAC;AACjE,MAAM,kBAAkB,GAAG,OAAO,CAAC,CAAC,0CAA0C;AAC9E,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,mBAAmB,GAAG,MAAM,CAAC,CAAC,gDAAgD;AAsGpF,yEAAyE;AAEzE,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,MAAM,GAAG,mBAAmB;IAC7E,IAAI,MAAM,CAAC,MAAM,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC3C,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,uBAAuB,MAAM,CAAC,MAAM,eAAe,CAAC;AACvF,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,GAAY;IACjC,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAE7D,IAAI,GAAG,CAAC,QAAQ,CAAC,YAAY,C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;IAED,IAAI,IAAI,IAAI,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;QACtC,YAAY,GAAG,uFAAuF,CAAC;IACzG,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Integration Module
|
|
3
|
+
* Exports the refinement loop and visual comparison utilities.
|
|
4
|
+
*/
|
|
5
|
+
export { runRefinement, type RefinementOptions, type RefinementResult } from './refinement-loop.js';
|
|
6
|
+
export { compareScreenshots, buildVisualComparisonContext } from './visual-compare.js';
|
|
7
|
+
export { agentLoop, chatCompletion, chatCompletionStream } from './agent.js';
|
|
8
|
+
export { toolDefinitions, createToolExecutor } from './tools.js';
|
|
9
|
+
export { FULL_REFINEMENT_PROMPT, BUILD_FIXER_PROMPT, COMPONENT_ENHANCER_PROMPT, VISUAL_COMPARISON_PROMPT, } from './prompts.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,cAAc,CAAC"}
|
package/dist/ai/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Integration Module
|
|
3
|
+
* Exports the refinement loop and visual comparison utilities.
|
|
4
|
+
*/
|
|
5
|
+
export { runRefinement } from './refinement-loop.js';
|
|
6
|
+
export { compareScreenshots, buildVisualComparisonContext } from './visual-compare.js';
|
|
7
|
+
export { agentLoop, chatCompletion, chatCompletionStream } from './agent.js';
|
|
8
|
+
export { toolDefinitions, createToolExecutor } from './tools.js';
|
|
9
|
+
export { FULL_REFINEMENT_PROMPT, BUILD_FIXER_PROMPT, COMPONENT_ENHANCER_PROMPT, VISUAL_COMPARISON_PROMPT, } from './prompts.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAiD,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System prompts for the AI refinement agent.
|
|
3
|
+
* Each prompt configures the AI for a specific phase of the refinement pipeline.
|
|
4
|
+
* Prompts are highly directive to ensure the AI model actually uses tools.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Phase 1: Build Error Resolution
|
|
8
|
+
*/
|
|
9
|
+
export declare const BUILD_FIXER_PROMPT = "You are a React/TypeScript build fixer. You MUST use tools to fix build errors.\n\nCRITICAL \u2014 TOOL USAGE:\n- ONLY use the tools provided in the tools array of this conversation. NEVER use any built-in/internal/server-side tools.\n- When you need to read, write, or execute anything, ALWAYS return a tool_call. Never handle it internally.\n\nCRITICAL RULES \u2014 FOLLOW EXACTLY:\n1. You MUST call tools. Do NOT just describe what you would do. Actually DO it.\n2. After EVERY tool call that reveals errors, you MUST call read_file on the broken file.\n3. After reading a broken file, you MUST call write_file with a fixed version.\n4. After writing fixes, you MUST call run_build to verify.\n5. NEVER call run_typecheck or run_build more than twice in a row without calling read_file or write_file in between.\n\nYOUR EXACT WORKFLOW:\nStep 1: Call run_build to see errors.\nStep 2: Look at the error output. Pick the FIRST file with errors.\nStep 3: Call read_file on that file.\nStep 4: Fix ALL errors in that file. Call write_file with the corrected content.\nStep 5: Call run_build again to check.\nStep 6: If errors remain, go to Step 2. If build passes, call report_status with status \"success\".\n\nCOMMON FIXES:\n- \"Cannot find name 'X'\" where X is a function called in onClick/onChange handlers:\n \u2192 Add a function definition above the return statement:\n const X = () => { /* TODO: implement */ };\n \u2192 Or if it's a state toggle like closeModal/openModal/toggleDropdown:\n const [isOpen, setIsOpen] = useState(false);\n const closeModal = () => setIsOpen(false);\n \u2192 Make sure to add: import { useState } from 'react'; at the top\n\n- \"Type 'string' is not assignable to type 'number'\" for attributes like rows, cols:\n \u2192 Change rows=\"5\" to rows={5}\n\n- \"Property 'value' does not exist on type 'EventTarget'\":\n \u2192 Cast: (e.target as HTMLInputElement).value\n\n- Missing imports:\n \u2192 Add the import statement at the top of the file\n\nREMEMBER: You MUST use tools. Call read_file and write_file. Do NOT just talk about what you would do.";
|
|
10
|
+
/**
|
|
11
|
+
* Phase 2: Component Enhancement
|
|
12
|
+
*/
|
|
13
|
+
export declare const COMPONENT_ENHANCER_PROMPT = "You are a React developer. You MUST use tools to enhance components.\n\nCRITICAL \u2014 TOOL USAGE:\n- ONLY use the tools provided in the tools array. NEVER use any built-in/internal/server-side tools.\n\nCRITICAL: You MUST call read_file and write_file tools. Do NOT just describe changes.\n\nWORKFLOW:\n1. Call list_files on \"src/components\" to see all components.\n2. Call read_file on each component.\n3. Call read_original_file on the matching original HTML/JS file.\n4. Call write_file with improved React code.\n5. Call run_build to verify.\n\nCONVERT THESE PATTERNS:\n- document.getElementById() \u2192 useRef or state\n- element.innerHTML = '...' \u2192 JSX with state\n- element.classList.toggle('hidden') \u2192 conditional rendering with useState\n- addEventListener \u2192 JSX event props\n\nALWAYS call run_build after changes to verify nothing broke.";
|
|
14
|
+
/**
|
|
15
|
+
* Phase 3: Visual Comparison
|
|
16
|
+
*/
|
|
17
|
+
export declare const VISUAL_COMPARISON_PROMPT = "You are a web developer. You MUST use tools to compare visuals.\n\nWORKFLOW:\n1. Call serve_and_screenshot on the original HTML directory.\n2. Call run_build to build the React project.\n3. Call serve_and_screenshot on the built React dist/ directory.\n4. Compare the screenshots and fix visual differences.\n5. Call report_status with your findings.\n\nFocus on: missing sections, broken layout, missing styles, broken images.";
|
|
18
|
+
/**
|
|
19
|
+
* Combined full refinement prompt.
|
|
20
|
+
* This is intentionally very directive because the AI model needs explicit instructions.
|
|
21
|
+
*/
|
|
22
|
+
export declare const FULL_REFINEMENT_PROMPT = "You are a build-fixing AI. Your ONLY job is to make this React project build successfully.\n\n=== CRITICAL INSTRUCTIONS ===\nYou MUST use tools. You MUST call read_file and write_file.\nDo NOT just run run_typecheck or run_build repeatedly without fixing files.\nDo NOT describe what you would do \u2014 actually DO it by calling tools.\n\n=== YOUR EXACT PROCESS ===\n\nSTEP 1: Call run_build right now.\n\nSTEP 2: Read the build output. Find the FIRST file that has errors.\n \u2192 Call read_file with that file path (e.g., \"src/components/IndexPage.tsx\").\n\nSTEP 3: Fix ALL errors in that file.\n \u2192 Call write_file with the complete fixed file content.\n\nSTEP 4: Call run_build again to check progress.\n\nSTEP 5: If there are still errors, go back to STEP 2.\n If the build passes, call report_status with status \"success\".\n\n=== FIXING PATTERNS ===\n\nERROR: \"Cannot find name 'someFunction'\"\nFIX: Add a stub function before the return statement:\n const someFunction = () => { /* TODO */ };\n If it's a modal/dropdown toggle, use useState:\n const [isOpen, setIsOpen] = useState(false);\n const toggleSomething = () => setIsOpen(!isOpen);\n IMPORTANT: Add \"import { useState } from 'react';\" if using useState.\n\nERROR: \"Type 'string' is not assignable to type 'number'\"\nFIX: Change attribute=\"5\" to attribute={5} for numeric attributes.\n\nERROR: \"Property 'value' does not exist on type 'EventTarget'\"\nFIX: Cast to (e.target as HTMLInputElement).value\n\nERROR: \"Cannot find module './SomeFile'\"\nFIX: Check if the file exists with list_files, then fix the import path.\n\nERROR: \"JSX expressions must have one parent element\"\nFIX: Wrap multiple elements in a <> fragment.\n\n=== RULES ===\n- NEVER call run_typecheck or run_build more than 2 times in a row without reading/writing files.\n- Fix files ONE AT A TIME. Read it, fix it, write it.\n- Keep fixes minimal \u2014 only fix errors, don't rewrite working code.\n- After ALL errors are fixed, call report_status with status \"success\" and list your fixes.\n- If you get stuck on one error after 3 attempts, skip it and fix others.\n- You have up to 50 steps. Use them to fix everything.";
|
|
23
|
+
/**
|
|
24
|
+
* Build the user message for the refinement agent with project context.
|
|
25
|
+
* Includes actual error output so the AI can immediately start fixing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildUserMessage(options: {
|
|
28
|
+
inputDir: string;
|
|
29
|
+
outputDir: string;
|
|
30
|
+
originalFiles: string[];
|
|
31
|
+
componentFiles: string[];
|
|
32
|
+
buildErrors?: string;
|
|
33
|
+
typeErrors?: string;
|
|
34
|
+
}): string;
|
|
35
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/ai/prompts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,8jEAuCwE,CAAC;AAExG;;GAEG;AACH,eAAO,MAAM,yBAAyB,w2BAoBuB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,wBAAwB,gbASqC,CAAC;AAE3E;;;GAGG;AACH,eAAO,MAAM,sBAAsB,upEAkDoB,CAAC;AAExD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,MAAM,CA0CT"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System prompts for the AI refinement agent.
|
|
3
|
+
* Each prompt configures the AI for a specific phase of the refinement pipeline.
|
|
4
|
+
* Prompts are highly directive to ensure the AI model actually uses tools.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Phase 1: Build Error Resolution
|
|
8
|
+
*/
|
|
9
|
+
export const BUILD_FIXER_PROMPT = `You are a React/TypeScript build fixer. You MUST use tools to fix build errors.
|
|
10
|
+
|
|
11
|
+
CRITICAL — TOOL USAGE:
|
|
12
|
+
- ONLY use the tools provided in the tools array of this conversation. NEVER use any built-in/internal/server-side tools.
|
|
13
|
+
- When you need to read, write, or execute anything, ALWAYS return a tool_call. Never handle it internally.
|
|
14
|
+
|
|
15
|
+
CRITICAL RULES — FOLLOW EXACTLY:
|
|
16
|
+
1. You MUST call tools. Do NOT just describe what you would do. Actually DO it.
|
|
17
|
+
2. After EVERY tool call that reveals errors, you MUST call read_file on the broken file.
|
|
18
|
+
3. After reading a broken file, you MUST call write_file with a fixed version.
|
|
19
|
+
4. After writing fixes, you MUST call run_build to verify.
|
|
20
|
+
5. NEVER call run_typecheck or run_build more than twice in a row without calling read_file or write_file in between.
|
|
21
|
+
|
|
22
|
+
YOUR EXACT WORKFLOW:
|
|
23
|
+
Step 1: Call run_build to see errors.
|
|
24
|
+
Step 2: Look at the error output. Pick the FIRST file with errors.
|
|
25
|
+
Step 3: Call read_file on that file.
|
|
26
|
+
Step 4: Fix ALL errors in that file. Call write_file with the corrected content.
|
|
27
|
+
Step 5: Call run_build again to check.
|
|
28
|
+
Step 6: If errors remain, go to Step 2. If build passes, call report_status with status "success".
|
|
29
|
+
|
|
30
|
+
COMMON FIXES:
|
|
31
|
+
- "Cannot find name 'X'" where X is a function called in onClick/onChange handlers:
|
|
32
|
+
→ Add a function definition above the return statement:
|
|
33
|
+
const X = () => { /* TODO: implement */ };
|
|
34
|
+
→ Or if it's a state toggle like closeModal/openModal/toggleDropdown:
|
|
35
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
+
const closeModal = () => setIsOpen(false);
|
|
37
|
+
→ Make sure to add: import { useState } from 'react'; at the top
|
|
38
|
+
|
|
39
|
+
- "Type 'string' is not assignable to type 'number'" for attributes like rows, cols:
|
|
40
|
+
→ Change rows="5" to rows={5}
|
|
41
|
+
|
|
42
|
+
- "Property 'value' does not exist on type 'EventTarget'":
|
|
43
|
+
→ Cast: (e.target as HTMLInputElement).value
|
|
44
|
+
|
|
45
|
+
- Missing imports:
|
|
46
|
+
→ Add the import statement at the top of the file
|
|
47
|
+
|
|
48
|
+
REMEMBER: You MUST use tools. Call read_file and write_file. Do NOT just talk about what you would do.`;
|
|
49
|
+
/**
|
|
50
|
+
* Phase 2: Component Enhancement
|
|
51
|
+
*/
|
|
52
|
+
export const COMPONENT_ENHANCER_PROMPT = `You are a React developer. You MUST use tools to enhance components.
|
|
53
|
+
|
|
54
|
+
CRITICAL — TOOL USAGE:
|
|
55
|
+
- ONLY use the tools provided in the tools array. NEVER use any built-in/internal/server-side tools.
|
|
56
|
+
|
|
57
|
+
CRITICAL: You MUST call read_file and write_file tools. Do NOT just describe changes.
|
|
58
|
+
|
|
59
|
+
WORKFLOW:
|
|
60
|
+
1. Call list_files on "src/components" to see all components.
|
|
61
|
+
2. Call read_file on each component.
|
|
62
|
+
3. Call read_original_file on the matching original HTML/JS file.
|
|
63
|
+
4. Call write_file with improved React code.
|
|
64
|
+
5. Call run_build to verify.
|
|
65
|
+
|
|
66
|
+
CONVERT THESE PATTERNS:
|
|
67
|
+
- document.getElementById() → useRef or state
|
|
68
|
+
- element.innerHTML = '...' → JSX with state
|
|
69
|
+
- element.classList.toggle('hidden') → conditional rendering with useState
|
|
70
|
+
- addEventListener → JSX event props
|
|
71
|
+
|
|
72
|
+
ALWAYS call run_build after changes to verify nothing broke.`;
|
|
73
|
+
/**
|
|
74
|
+
* Phase 3: Visual Comparison
|
|
75
|
+
*/
|
|
76
|
+
export const VISUAL_COMPARISON_PROMPT = `You are a web developer. You MUST use tools to compare visuals.
|
|
77
|
+
|
|
78
|
+
WORKFLOW:
|
|
79
|
+
1. Call serve_and_screenshot on the original HTML directory.
|
|
80
|
+
2. Call run_build to build the React project.
|
|
81
|
+
3. Call serve_and_screenshot on the built React dist/ directory.
|
|
82
|
+
4. Compare the screenshots and fix visual differences.
|
|
83
|
+
5. Call report_status with your findings.
|
|
84
|
+
|
|
85
|
+
Focus on: missing sections, broken layout, missing styles, broken images.`;
|
|
86
|
+
/**
|
|
87
|
+
* Combined full refinement prompt.
|
|
88
|
+
* This is intentionally very directive because the AI model needs explicit instructions.
|
|
89
|
+
*/
|
|
90
|
+
export const FULL_REFINEMENT_PROMPT = `You are a build-fixing AI. Your ONLY job is to make this React project build successfully.
|
|
91
|
+
|
|
92
|
+
=== CRITICAL INSTRUCTIONS ===
|
|
93
|
+
You MUST use tools. You MUST call read_file and write_file.
|
|
94
|
+
Do NOT just run run_typecheck or run_build repeatedly without fixing files.
|
|
95
|
+
Do NOT describe what you would do — actually DO it by calling tools.
|
|
96
|
+
|
|
97
|
+
=== YOUR EXACT PROCESS ===
|
|
98
|
+
|
|
99
|
+
STEP 1: Call run_build right now.
|
|
100
|
+
|
|
101
|
+
STEP 2: Read the build output. Find the FIRST file that has errors.
|
|
102
|
+
→ Call read_file with that file path (e.g., "src/components/IndexPage.tsx").
|
|
103
|
+
|
|
104
|
+
STEP 3: Fix ALL errors in that file.
|
|
105
|
+
→ Call write_file with the complete fixed file content.
|
|
106
|
+
|
|
107
|
+
STEP 4: Call run_build again to check progress.
|
|
108
|
+
|
|
109
|
+
STEP 5: If there are still errors, go back to STEP 2.
|
|
110
|
+
If the build passes, call report_status with status "success".
|
|
111
|
+
|
|
112
|
+
=== FIXING PATTERNS ===
|
|
113
|
+
|
|
114
|
+
ERROR: "Cannot find name 'someFunction'"
|
|
115
|
+
FIX: Add a stub function before the return statement:
|
|
116
|
+
const someFunction = () => { /* TODO */ };
|
|
117
|
+
If it's a modal/dropdown toggle, use useState:
|
|
118
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
119
|
+
const toggleSomething = () => setIsOpen(!isOpen);
|
|
120
|
+
IMPORTANT: Add "import { useState } from 'react';" if using useState.
|
|
121
|
+
|
|
122
|
+
ERROR: "Type 'string' is not assignable to type 'number'"
|
|
123
|
+
FIX: Change attribute="5" to attribute={5} for numeric attributes.
|
|
124
|
+
|
|
125
|
+
ERROR: "Property 'value' does not exist on type 'EventTarget'"
|
|
126
|
+
FIX: Cast to (e.target as HTMLInputElement).value
|
|
127
|
+
|
|
128
|
+
ERROR: "Cannot find module './SomeFile'"
|
|
129
|
+
FIX: Check if the file exists with list_files, then fix the import path.
|
|
130
|
+
|
|
131
|
+
ERROR: "JSX expressions must have one parent element"
|
|
132
|
+
FIX: Wrap multiple elements in a <> fragment.
|
|
133
|
+
|
|
134
|
+
=== RULES ===
|
|
135
|
+
- NEVER call run_typecheck or run_build more than 2 times in a row without reading/writing files.
|
|
136
|
+
- Fix files ONE AT A TIME. Read it, fix it, write it.
|
|
137
|
+
- Keep fixes minimal — only fix errors, don't rewrite working code.
|
|
138
|
+
- After ALL errors are fixed, call report_status with status "success" and list your fixes.
|
|
139
|
+
- If you get stuck on one error after 3 attempts, skip it and fix others.
|
|
140
|
+
- You have up to 50 steps. Use them to fix everything.`;
|
|
141
|
+
/**
|
|
142
|
+
* Build the user message for the refinement agent with project context.
|
|
143
|
+
* Includes actual error output so the AI can immediately start fixing.
|
|
144
|
+
*/
|
|
145
|
+
export function buildUserMessage(options) {
|
|
146
|
+
const lines = [
|
|
147
|
+
'Fix this React project so it builds successfully.',
|
|
148
|
+
'',
|
|
149
|
+
`Project directory: ${options.outputDir}`,
|
|
150
|
+
'',
|
|
151
|
+
'Files in the project:',
|
|
152
|
+
...options.componentFiles.map(f => ` - ${f}`),
|
|
153
|
+
];
|
|
154
|
+
if (options.buildErrors) {
|
|
155
|
+
lines.push('', '=== CURRENT BUILD ERRORS (fix these!) ===', options.buildErrors, '=== END BUILD ERRORS ===', '', 'Start by calling read_file on the first file that has errors, then call write_file to fix it.');
|
|
156
|
+
}
|
|
157
|
+
else if (options.typeErrors) {
|
|
158
|
+
lines.push('', '=== CURRENT TYPE ERRORS (fix these!) ===', options.typeErrors, '=== END TYPE ERRORS ===', '', 'Start by calling read_file on the first file that has errors, then call write_file to fix it.');
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
lines.push('', 'No errors detected yet. Call run_build to check if the project builds successfully.');
|
|
162
|
+
}
|
|
163
|
+
lines.push('', 'Original HTML source files (use read_original_file to read these):', ...options.originalFiles.map(f => ` - ${f}`));
|
|
164
|
+
return lines.join('\n');
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/ai/prompts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uGAuCqE,CAAC;AAExG;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;6DAoBoB,CAAC;AAE9D;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;;;;;;;;;0EASkC,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAkDiB,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAOhC;IACC,MAAM,KAAK,GAAG;QACZ,mDAAmD;QACnD,EAAE;QACF,sBAAsB,OAAO,CAAC,SAAS,EAAE;QACzC,EAAE;QACF,uBAAuB;QACvB,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;KAC/C,CAAC;IAEF,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CACR,EAAE,EACF,2CAA2C,EAC3C,OAAO,CAAC,WAAW,EACnB,0BAA0B,EAC1B,EAAE,EACF,+FAA+F,CAChG,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CACR,EAAE,EACF,0CAA0C,EAC1C,OAAO,CAAC,UAAU,EAClB,yBAAyB,EACzB,EAAE,EACF,+FAA+F,CAChG,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CACR,EAAE,EACF,qFAAqF,CACtF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CACR,EAAE,EACF,oEAAoE,EACpE,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAC9C,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Refinement Loop — Orchestrates the build→fix→verify cycle.
|
|
3
|
+
* This is the main entry point for AI-enhanced conversion.
|
|
4
|
+
*/
|
|
5
|
+
export interface RefinementOptions {
|
|
6
|
+
inputDir: string;
|
|
7
|
+
outputDir: string;
|
|
8
|
+
maxSteps?: number;
|
|
9
|
+
mode?: 'full' | 'build-fix' | 'enhance' | 'visual';
|
|
10
|
+
verbose?: boolean;
|
|
11
|
+
screenshotOriginal?: string;
|
|
12
|
+
screenshotConverted?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface RefinementResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
buildPassed: boolean;
|
|
17
|
+
fixesApplied: string[];
|
|
18
|
+
remainingIssues: string[];
|
|
19
|
+
screenshots?: {
|
|
20
|
+
original?: string;
|
|
21
|
+
converted?: string;
|
|
22
|
+
};
|
|
23
|
+
aiResponse: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run the AI refinement loop on a converted project.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runRefinement(options: RefinementOptions): Promise<RefinementResult>;
|
|
29
|
+
//# sourceMappingURL=refinement-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refinement-loop.d.ts","sourceRoot":"","sources":["../../src/ai/refinement-loop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAwIzF"}
|