rivet-design 0.5.4 → 0.5.7
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 +18 -18
- package/README.npm.md +18 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -14
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +2 -67
- package/dist/mcp/server.js.map +1 -1
- package/dist/services/TelemetryService.d.ts.map +1 -1
- package/dist/services/TelemetryService.js +5 -0
- package/dist/services/TelemetryService.js.map +1 -1
- package/package.json +3 -3
- package/src/ui/dist/assets/main-DAIpACRO.js +491 -0
- package/src/ui/dist/index.html +1 -1
- package/dist/routes/agent.d.ts +0 -8
- package/dist/routes/agent.d.ts.map +0 -1
- package/dist/routes/agent.js +0 -79
- package/dist/routes/agent.js.map +0 -1
- package/dist/routes/comments.d.ts +0 -2
- package/dist/routes/comments.d.ts.map +0 -1
- package/dist/routes/comments.js +0 -92
- package/dist/routes/comments.js.map +0 -1
- package/dist/routes/onboarding.d.ts +0 -6
- package/dist/routes/onboarding.d.ts.map +0 -1
- package/dist/routes/onboarding.js +0 -206
- package/dist/routes/onboarding.js.map +0 -1
- package/dist/routes/selection.d.ts +0 -2
- package/dist/routes/selection.d.ts.map +0 -1
- package/dist/routes/selection.js +0 -38
- package/dist/routes/selection.js.map +0 -1
- package/dist/scripts/react-instrumentation.js +0 -300
- package/dist/services/AgentBridgeService.d.ts +0 -89
- package/dist/services/AgentBridgeService.d.ts.map +0 -1
- package/dist/services/AgentBridgeService.js +0 -413
- package/dist/services/AgentBridgeService.js.map +0 -1
- package/dist/services/AgentModService.d.ts +0 -76
- package/dist/services/AgentModService.d.ts.map +0 -1
- package/dist/services/AgentModService.js +0 -494
- package/dist/services/AgentModService.js.map +0 -1
- package/dist/services/CommentSessionManager.d.ts +0 -94
- package/dist/services/CommentSessionManager.d.ts.map +0 -1
- package/dist/services/CommentSessionManager.js +0 -260
- package/dist/services/CommentSessionManager.js.map +0 -1
- package/dist/services/ImportResolverService.d.ts +0 -30
- package/dist/services/ImportResolverService.d.ts.map +0 -1
- package/dist/services/ImportResolverService.js +0 -136
- package/dist/services/ImportResolverService.js.map +0 -1
- package/dist/services/ReactComponentPlugin.d.ts +0 -44
- package/dist/services/ReactComponentPlugin.d.ts.map +0 -1
- package/dist/services/ReactComponentPlugin.js +0 -100
- package/dist/services/ReactComponentPlugin.js.map +0 -1
- package/dist/types/agent-protocol.d.ts +0 -55
- package/dist/types/agent-protocol.d.ts.map +0 -1
- package/dist/types/agent-protocol.js +0 -6
- package/dist/types/agent-protocol.js.map +0 -1
- package/dist/types/agent-tools.d.ts +0 -78
- package/dist/types/agent-tools.d.ts.map +0 -1
- package/dist/types/agent-tools.js +0 -7
- package/dist/types/agent-tools.js.map +0 -1
- package/dist/types/types.d.ts +0 -15
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js +0 -3
- package/dist/types/types.js.map +0 -1
- package/src/ui/dist/assets/main-BXXN24hn.js +0 -505
|
@@ -1,494 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.AgentModService = void 0;
|
|
40
|
-
const path_1 = __importDefault(require("path"));
|
|
41
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
42
|
-
const logger_1 = require("../utils/logger");
|
|
43
|
-
const crypto = __importStar(require("crypto"));
|
|
44
|
-
const proxy_1 = require("../config/proxy");
|
|
45
|
-
const ConfigManager_1 = require("./ConfigManager");
|
|
46
|
-
const log = (0, logger_1.createLogger)('AgentModService');
|
|
47
|
-
/**
|
|
48
|
-
* Check if running as a direct Node process (vs embedded in Electron/etc.)
|
|
49
|
-
*/
|
|
50
|
-
const isDirectNodeProcess = () => {
|
|
51
|
-
return (process.execPath.endsWith('node') || process.execPath.endsWith('node.exe'));
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Service for agentic code modifications using Claude Agent SDK.
|
|
55
|
-
* Agent autonomously searches for files, reads context, and makes modifications.
|
|
56
|
-
*/
|
|
57
|
-
class AgentModService {
|
|
58
|
-
projectPath;
|
|
59
|
-
sessionService;
|
|
60
|
-
configManager = (0, ConfigManager_1.getConfigManager)();
|
|
61
|
-
gatewayUrl;
|
|
62
|
-
proxyUrl;
|
|
63
|
-
constructor(projectPath, sessionService, gatewayUrl) {
|
|
64
|
-
this.projectPath = projectPath;
|
|
65
|
-
this.sessionService = sessionService;
|
|
66
|
-
this.gatewayUrl = gatewayUrl || proxy_1.GATEWAY_URL;
|
|
67
|
-
this.proxyUrl = proxy_1.PROXY_URL;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Refresh access token using refresh token
|
|
71
|
-
*/
|
|
72
|
-
async refreshAccessToken() {
|
|
73
|
-
const refreshToken = this.configManager.getRefreshToken();
|
|
74
|
-
if (!refreshToken) {
|
|
75
|
-
log.error('No refresh token available');
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
log.info('Refreshing access token...');
|
|
80
|
-
const response = await fetch(`${this.proxyUrl}/api/auth/refresh`, {
|
|
81
|
-
method: 'POST',
|
|
82
|
-
headers: {
|
|
83
|
-
'Content-Type': 'application/json',
|
|
84
|
-
},
|
|
85
|
-
body: JSON.stringify({ refreshToken }),
|
|
86
|
-
});
|
|
87
|
-
if (!response.ok) {
|
|
88
|
-
log.error('Token refresh failed');
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
const result = await response.json();
|
|
92
|
-
if (result.success && result.token) {
|
|
93
|
-
// Update stored tokens
|
|
94
|
-
const email = this.configManager.getEmail() || '';
|
|
95
|
-
this.configManager.setAuth(result.token, email, result.refreshToken);
|
|
96
|
-
log.info('Access token refreshed successfully');
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
log.error('Error refreshing token:', error);
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Decode JWT and check if it expires within the next hour
|
|
108
|
-
*/
|
|
109
|
-
isTokenExpiringSoon(token) {
|
|
110
|
-
try {
|
|
111
|
-
// JWT format: header.payload.signature
|
|
112
|
-
const payload = token.split('.')[1];
|
|
113
|
-
if (!payload)
|
|
114
|
-
return true;
|
|
115
|
-
const decoded = JSON.parse(Buffer.from(payload, 'base64').toString());
|
|
116
|
-
const expiry = decoded.exp; // Unix timestamp
|
|
117
|
-
if (!expiry)
|
|
118
|
-
return true;
|
|
119
|
-
// Check if expires within next hour (3600 seconds)
|
|
120
|
-
const now = Math.floor(Date.now() / 1000);
|
|
121
|
-
const timeUntilExpiry = expiry - now;
|
|
122
|
-
log.debug(`Token expires in ${timeUntilExpiry} seconds`);
|
|
123
|
-
return timeUntilExpiry < 3600; // Less than 1 hour
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
log.warn('Could not decode JWT, assuming it needs refresh:', error);
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Execute an agentic modification workflow.
|
|
132
|
-
* The agent autonomously uses Grep/Glob/Read to find files and Edit to modify them.
|
|
133
|
-
*
|
|
134
|
-
* @effect Streams progress events via onProgress callback
|
|
135
|
-
* @param instruction User's modification instruction
|
|
136
|
-
* @param initialElements Selected elements from UI with candidate file paths
|
|
137
|
-
* @param onProgress Callback for streaming progress updates
|
|
138
|
-
* @param designTokens Optional design system tokens
|
|
139
|
-
* @param image Optional reference image
|
|
140
|
-
*/
|
|
141
|
-
async executeAgenticModification(instruction, initialElements, onProgress, designTokens, image, retryCount = 0) {
|
|
142
|
-
log.info(`Starting agentic modification: "${instruction}"`);
|
|
143
|
-
log.info(`Initial elements: ${initialElements.length}`);
|
|
144
|
-
// Get Supabase JWT from config
|
|
145
|
-
let authToken = this.configManager.getAuthToken();
|
|
146
|
-
if (!authToken) {
|
|
147
|
-
const errorMsg = 'Not authenticated. Please run `rivet login` to authenticate.';
|
|
148
|
-
log.error(errorMsg);
|
|
149
|
-
throw new Error(errorMsg);
|
|
150
|
-
}
|
|
151
|
-
// Pre-emptively refresh if token expires within 1 hour
|
|
152
|
-
// (Agent can run for a while, so we want a fresh token)
|
|
153
|
-
if (this.isTokenExpiringSoon(authToken)) {
|
|
154
|
-
log.info('Token expires soon, refreshing before starting agent...');
|
|
155
|
-
const refreshed = await this.refreshAccessToken();
|
|
156
|
-
if (refreshed) {
|
|
157
|
-
authToken = this.configManager.getAuthToken() || authToken;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
log.warn('Token refresh failed, continuing with existing token');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
// Dynamically import the ESM SDK (works in CommonJS bundle)
|
|
165
|
-
// TODO: HACK, handle this import natively
|
|
166
|
-
// Use eval to prevent TypeScript from transforming to require()
|
|
167
|
-
const { query } = await eval("import('@anthropic-ai/claude-agent-sdk')");
|
|
168
|
-
// Build initial context from selected elements and read candidate files
|
|
169
|
-
const initialContext = await this.buildInitialContext(initialElements, designTokens, image);
|
|
170
|
-
// Track state throughout agent execution
|
|
171
|
-
const filesModified = new Set();
|
|
172
|
-
const reasoning = [];
|
|
173
|
-
const steps = [];
|
|
174
|
-
// Log the base URL we're using for debugging
|
|
175
|
-
// Note: Anthropic SDK appends /v1/messages to the base URL
|
|
176
|
-
log.info(`Agent will use ANTHROPIC_BASE_URL: ${this.gatewayUrl}`);
|
|
177
|
-
log.info(`SDK will construct full endpoint: ${this.gatewayUrl}/v1/messages`);
|
|
178
|
-
log.info(`Auth token (first 20 chars): ${authToken.substring(0, 20)}...`);
|
|
179
|
-
// Build environment for agent subprocess
|
|
180
|
-
const agentEnv = {
|
|
181
|
-
...process.env,
|
|
182
|
-
// Point claude-agent-sdk to Rivet Gateway instead of Anthropic directly
|
|
183
|
-
ANTHROPIC_BASE_URL: this.gatewayUrl,
|
|
184
|
-
// Use Supabase JWT as the API key
|
|
185
|
-
ANTHROPIC_API_KEY: authToken,
|
|
186
|
-
};
|
|
187
|
-
// In embedded runtimes (Electron), use execPath with ELECTRON_RUN_AS_NODE
|
|
188
|
-
if (!isDirectNodeProcess()) {
|
|
189
|
-
agentEnv.ELECTRON_RUN_AS_NODE = '1';
|
|
190
|
-
log.debug('Running in embedded runtime, setting ELECTRON_RUN_AS_NODE=1');
|
|
191
|
-
}
|
|
192
|
-
// Execute agent query with streaming
|
|
193
|
-
const agentQuery = query({
|
|
194
|
-
prompt: this.buildAgentPrompt(instruction, initialContext),
|
|
195
|
-
options: {
|
|
196
|
-
model: 'claude-opus-4-5-20251101',
|
|
197
|
-
cwd: this.projectPath,
|
|
198
|
-
systemPrompt: this.buildSystemPrompt(),
|
|
199
|
-
executable: process.execPath,
|
|
200
|
-
executableArgs: [],
|
|
201
|
-
env: agentEnv,
|
|
202
|
-
// Agent can use built-in file manipulation tools
|
|
203
|
-
allowedTools: [
|
|
204
|
-
'Glob', // Find files by pattern (e.g., "**/*.tsx")
|
|
205
|
-
'Grep', // Search file contents by regex
|
|
206
|
-
'Read', // Read file contents
|
|
207
|
-
'Edit', // Make precise search/replace edits
|
|
208
|
-
'Bash', // Run commands if needed
|
|
209
|
-
],
|
|
210
|
-
// Accept edits automatically in this flow
|
|
211
|
-
permissionMode: 'acceptEdits',
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
// Stream agent responses
|
|
215
|
-
for await (const message of agentQuery) {
|
|
216
|
-
if (message.type === 'assistant') {
|
|
217
|
-
// Extract reasoning and tool calls from content blocks
|
|
218
|
-
const content = message.message.content;
|
|
219
|
-
for (const block of content) {
|
|
220
|
-
if (block.type === 'text') {
|
|
221
|
-
reasoning.push(block.text);
|
|
222
|
-
const step = {
|
|
223
|
-
type: 'reasoning',
|
|
224
|
-
timestamp: Date.now(),
|
|
225
|
-
data: { text: block.text },
|
|
226
|
-
};
|
|
227
|
-
steps.push(step);
|
|
228
|
-
onProgress({ type: 'step', step });
|
|
229
|
-
log.debug('Agent reasoning:', block.text.slice(0, 100) + '...');
|
|
230
|
-
}
|
|
231
|
-
else if (block.type === 'tool_use') {
|
|
232
|
-
// Track tool calls
|
|
233
|
-
const step = {
|
|
234
|
-
type: 'tool_call',
|
|
235
|
-
timestamp: Date.now(),
|
|
236
|
-
data: {
|
|
237
|
-
name: block.name,
|
|
238
|
-
input: block.input,
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
steps.push(step);
|
|
242
|
-
onProgress({ type: 'step', step });
|
|
243
|
-
log.debug(`Agent calling tool: ${block.name}`);
|
|
244
|
-
// Track file modifications
|
|
245
|
-
if (block.name === 'Edit' || block.name === 'Write') {
|
|
246
|
-
const input = block.input;
|
|
247
|
-
const filePath = input.file_path;
|
|
248
|
-
if (filePath) {
|
|
249
|
-
filesModified.add(filePath);
|
|
250
|
-
log.info(`Agent modified file: ${filePath}`);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
log.info(`Agent completed. Modified ${filesModified.size} files`);
|
|
258
|
-
// Commit changes if git tracking is enabled
|
|
259
|
-
if (this.sessionService && filesModified.size > 0) {
|
|
260
|
-
log.info('Committing changes to git...');
|
|
261
|
-
const changeRecord = await this.createChangeRecord(Array.from(filesModified), instruction, reasoning.join('\n\n'), initialElements);
|
|
262
|
-
await this.sessionService.commitModification(changeRecord);
|
|
263
|
-
}
|
|
264
|
-
const result = {
|
|
265
|
-
success: true,
|
|
266
|
-
filesModified: Array.from(filesModified),
|
|
267
|
-
reasoning,
|
|
268
|
-
changes: this.summarizeChanges(Array.from(filesModified), reasoning),
|
|
269
|
-
};
|
|
270
|
-
onProgress({ type: 'complete', result });
|
|
271
|
-
return result;
|
|
272
|
-
}
|
|
273
|
-
catch (error) {
|
|
274
|
-
log.error('Agentic modification failed:', error);
|
|
275
|
-
// Log full error details for debugging
|
|
276
|
-
if (error instanceof Error) {
|
|
277
|
-
log.error('Error name:', error.name);
|
|
278
|
-
log.error('Error message:', error.message);
|
|
279
|
-
log.error('Error stack:', error.stack);
|
|
280
|
-
}
|
|
281
|
-
// Extract and parse error message with better credit/billing detection
|
|
282
|
-
let errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
283
|
-
// Parse common error patterns to provide better user-facing messages
|
|
284
|
-
if (errorMessage.includes('429') || errorMessage.includes('rate limit')) {
|
|
285
|
-
errorMessage =
|
|
286
|
-
'Usage limit exceeded. Please check your account at https://rivet.design/account or contact support.';
|
|
287
|
-
}
|
|
288
|
-
else if (errorMessage.includes('402') ||
|
|
289
|
-
errorMessage.includes('payment') ||
|
|
290
|
-
errorMessage.includes('credit')) {
|
|
291
|
-
errorMessage =
|
|
292
|
-
'Insufficient credits. Please add credits at https://rivet.design/account to continue.';
|
|
293
|
-
}
|
|
294
|
-
else if (errorMessage.includes('401') ||
|
|
295
|
-
errorMessage.includes('unauthorized')) {
|
|
296
|
-
errorMessage =
|
|
297
|
-
'Authentication expired. Please run `rivet logout` and `rivet login` to re-authenticate.';
|
|
298
|
-
}
|
|
299
|
-
else if (errorMessage.includes('403') ||
|
|
300
|
-
errorMessage.includes('forbidden')) {
|
|
301
|
-
errorMessage =
|
|
302
|
-
'Access denied. Please check your account permissions at https://rivet.design/account.';
|
|
303
|
-
}
|
|
304
|
-
// Check if this is an auth error and we haven't retried yet
|
|
305
|
-
const isAuthError = errorMessage.includes('401') ||
|
|
306
|
-
errorMessage.includes('Authentication') ||
|
|
307
|
-
errorMessage.includes('Invalid or expired token');
|
|
308
|
-
if (isAuthError && retryCount === 0) {
|
|
309
|
-
log.warn('Agent failed with auth error, attempting to refresh token...');
|
|
310
|
-
const refreshed = await this.refreshAccessToken();
|
|
311
|
-
if (refreshed) {
|
|
312
|
-
log.info('Token refreshed, retrying agent execution...');
|
|
313
|
-
// Retry the entire agent execution with fresh token
|
|
314
|
-
return this.executeAgenticModification(instruction, initialElements, onProgress, designTokens, image, retryCount + 1);
|
|
315
|
-
}
|
|
316
|
-
log.error('Token refresh failed, cannot retry');
|
|
317
|
-
}
|
|
318
|
-
onProgress({
|
|
319
|
-
type: 'error',
|
|
320
|
-
error: errorMessage,
|
|
321
|
-
});
|
|
322
|
-
return {
|
|
323
|
-
success: false,
|
|
324
|
-
filesModified: [],
|
|
325
|
-
reasoning: [],
|
|
326
|
-
changes: `Error: ${errorMessage}`,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Build system prompt for the agent
|
|
332
|
-
*/
|
|
333
|
-
buildSystemPrompt() {
|
|
334
|
-
return `You are an expert software engineer modifying a web application's code.
|
|
335
|
-
|
|
336
|
-
TASK: Analyze the user's instruction and make all necessary code changes across multiple files.
|
|
337
|
-
|
|
338
|
-
TOOLS AVAILABLE:
|
|
339
|
-
- Glob: Find files by glob pattern (e.g., "**/*.tsx", "src/components/**/*.jsx")
|
|
340
|
-
- Grep: Search file contents using regex patterns (e.g., find all files containing "className='button'")
|
|
341
|
-
- Read: Read the full contents of any file
|
|
342
|
-
- Edit: Make precise search/replace edits to files (PREFERRED for modifications)
|
|
343
|
-
- Bash: Run terminal commands if absolutely needed (use sparingly)
|
|
344
|
-
|
|
345
|
-
WORKFLOW:
|
|
346
|
-
1. Review the initial context (I'll provide candidate files and selected elements)
|
|
347
|
-
2. Read the candidate files to understand the current code
|
|
348
|
-
3. If you need to find additional files:
|
|
349
|
-
- Use Grep to search for classNames, IDs, imports, function names, etc.
|
|
350
|
-
- Use Glob to find files by path patterns (e.g., all TypeScript files in a directory)
|
|
351
|
-
- Use Read to examine any file you find
|
|
352
|
-
4. Make modifications using the Edit tool:
|
|
353
|
-
- Each Edit requires a unique search string and replacement
|
|
354
|
-
- Search strings must appear EXACTLY ONCE in the file
|
|
355
|
-
- Include 2-3 lines of context to ensure uniqueness
|
|
356
|
-
- Match exact whitespace and indentation
|
|
357
|
-
5. Consider side effects:
|
|
358
|
-
- If changing a component's props, search for all files that import and use it
|
|
359
|
-
- If modifying shared utilities or types, check all usage sites
|
|
360
|
-
- If changing CSS classes, find all components that use those classes
|
|
361
|
-
|
|
362
|
-
RULES FOR EDIT TOOL:
|
|
363
|
-
- Search strings must be UNIQUE within the target file (appear exactly once)
|
|
364
|
-
- Include 2-3 lines of surrounding context in search strings
|
|
365
|
-
- Match exact whitespace, indentation, and line breaks from the source file
|
|
366
|
-
- The search string must exist exactly as written in the file
|
|
367
|
-
- Use Read first to see the exact formatting before using Edit
|
|
368
|
-
|
|
369
|
-
BEST PRACTICES:
|
|
370
|
-
- Make MINIMAL changes to achieve the user's goal
|
|
371
|
-
- Preserve existing code style and formatting
|
|
372
|
-
- Prefer using existing design tokens/variables over hardcoded values
|
|
373
|
-
- Think step-by-step and explain your reasoning before each action
|
|
374
|
-
- Start with the candidate files provided, then search for related files as needed
|
|
375
|
-
|
|
376
|
-
Your goal is to make clean, precise modifications that accomplish the user's intent while maintaining code quality.`;
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Build the initial agent prompt with context
|
|
380
|
-
*/
|
|
381
|
-
buildAgentPrompt(instruction, initialContext) {
|
|
382
|
-
return `USER INSTRUCTION:
|
|
383
|
-
${instruction}
|
|
384
|
-
|
|
385
|
-
${initialContext}
|
|
386
|
-
|
|
387
|
-
Please analyze this request and make all necessary code modifications. Start by reading the candidate files I've provided, then use Grep/Glob to find any additional files you need.`;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Build initial context string from selected elements and read candidate files
|
|
391
|
-
*
|
|
392
|
-
* @effect Reads candidate files from disk
|
|
393
|
-
*/
|
|
394
|
-
async buildInitialContext(elements, designTokens, image) {
|
|
395
|
-
let context = '';
|
|
396
|
-
// Add design tokens if available
|
|
397
|
-
if (designTokens) {
|
|
398
|
-
context += 'DESIGN TOKENS AVAILABLE:\n';
|
|
399
|
-
context +=
|
|
400
|
-
'The project has design tokens defined. Prefer using these tokens over hardcoded values.\n';
|
|
401
|
-
context += JSON.stringify(designTokens, null, 2);
|
|
402
|
-
context += '\n\n';
|
|
403
|
-
}
|
|
404
|
-
// Add reference image info if available
|
|
405
|
-
if (image) {
|
|
406
|
-
context += 'REFERENCE IMAGE:\n';
|
|
407
|
-
context +=
|
|
408
|
-
'A reference image has been provided showing the desired visual outcome.\n\n';
|
|
409
|
-
}
|
|
410
|
-
// Add selected elements with their candidate files
|
|
411
|
-
context += 'SELECTED ELEMENTS AND CANDIDATE FILES:\n\n';
|
|
412
|
-
for (let i = 0; i < elements.length; i++) {
|
|
413
|
-
const element = elements[i];
|
|
414
|
-
context += `━━━ Element ${i + 1}: <${element.tagName}> ━━━\n`;
|
|
415
|
-
if (element.className) {
|
|
416
|
-
context += `Classes: ${element.className}\n`;
|
|
417
|
-
}
|
|
418
|
-
if (element.id) {
|
|
419
|
-
context += `ID: ${element.id}\n`;
|
|
420
|
-
}
|
|
421
|
-
if (element.textContent && element.textContent.trim()) {
|
|
422
|
-
const preview = element.textContent.slice(0, 100);
|
|
423
|
-
context += `Text: ${preview}${element.textContent.length > 100 ? '...' : ''}\n`;
|
|
424
|
-
}
|
|
425
|
-
// Add candidate files with code preview
|
|
426
|
-
if (element.filePaths && element.filePaths.length > 0) {
|
|
427
|
-
context += '\nCANDIDATE FILES (ordered by relevance):\n';
|
|
428
|
-
for (const file of element.filePaths.slice(0, 3)) {
|
|
429
|
-
// Top 3 candidates
|
|
430
|
-
const relativePath = path_1.default.relative(this.projectPath, file.filePath);
|
|
431
|
-
context += `\n━━━ ${relativePath} ━━━\n`;
|
|
432
|
-
try {
|
|
433
|
-
const content = await promises_1.default.readFile(file.filePath, 'utf-8');
|
|
434
|
-
// Show first 50 lines as preview
|
|
435
|
-
const lines = content.split('\n').slice(0, 50);
|
|
436
|
-
context += lines.join('\n');
|
|
437
|
-
if (content.split('\n').length > 50) {
|
|
438
|
-
context += '\n... (file continues)\n';
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
catch (error) {
|
|
442
|
-
context += `(Error reading file: ${error instanceof Error ? error.message : 'Unknown error'})\n`;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
context += '\n';
|
|
447
|
-
}
|
|
448
|
-
return context;
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Create a ChangeRecord for git tracking
|
|
452
|
-
*
|
|
453
|
-
* @effect Reads modified files from disk
|
|
454
|
-
*/
|
|
455
|
-
async createChangeRecord(filesModified, instruction, reasoning, elements) {
|
|
456
|
-
const files = [];
|
|
457
|
-
for (const filePath of filesModified) {
|
|
458
|
-
try {
|
|
459
|
-
const content = await promises_1.default.readFile(filePath, 'utf-8');
|
|
460
|
-
files.push({
|
|
461
|
-
filePath,
|
|
462
|
-
originalContent: '', // Git will track the original
|
|
463
|
-
modifiedContent: content,
|
|
464
|
-
diff: '', // Git will generate the diff
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
catch (error) {
|
|
468
|
-
log.warn(`Could not read modified file ${filePath}:`, error);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return {
|
|
472
|
-
id: crypto.randomBytes(8).toString('hex'),
|
|
473
|
-
timestamp: new Date(),
|
|
474
|
-
type: 'llm',
|
|
475
|
-
description: `${instruction}\n\nAgent reasoning:\n${reasoning.slice(0, 500)}`,
|
|
476
|
-
elements,
|
|
477
|
-
files,
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Summarize changes for user display
|
|
482
|
-
*/
|
|
483
|
-
summarizeChanges(filesModified, reasoning) {
|
|
484
|
-
const fileList = filesModified
|
|
485
|
-
.map((f) => `- ${path_1.default.basename(f)}`)
|
|
486
|
-
.join('\n');
|
|
487
|
-
const summary = reasoning.length > 0
|
|
488
|
-
? reasoning[reasoning.length - 1].slice(0, 200)
|
|
489
|
-
: 'Completed modifications';
|
|
490
|
-
return `Modified ${filesModified.length} file(s):\n${fileList}\n\n${summary}`;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
exports.AgentModService = AgentModService;
|
|
494
|
-
//# sourceMappingURL=AgentModService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentModService.js","sourceRoot":"","sources":["../../src/services/AgentModService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,2DAA6B;AAC7B,4CAA+C;AAG/C,+CAAiC;AACjC,2CAAyD;AACzD,mDAAmD;AAEnD,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,iBAAiB,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,mBAAmB,GAAG,GAAY,EAAE;IACxC,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAC3E,CAAC;AACJ,CAAC,CAAC;AAsBF;;;GAGG;AACH,MAAa,eAAe;IAClB,WAAW,CAAS;IACpB,cAAc,CAAkB;IAChC,aAAa,GAAG,IAAA,gCAAgB,GAAE,CAAC;IACnC,UAAU,CAAS;IACnB,QAAQ,CAAS;IAEzB,YACE,WAAmB,EACnB,cAA+B,EAC/B,UAAmB;QAEnB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,mBAAW,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,iBAAS,CAAC;IAC5B,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,kBAAkB;QAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;QAC1D,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,GAAG,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;YACxC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC;YAC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,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;YACzC,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,IAAI,EAAE,KAAK;YACX,WAAW,EAAE,GAAG,WAAW,yBAAyB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;YAC7E,QAAQ;YACR,KAAK;SACN,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,gBAAgB,CACtB,aAAuB,EACvB,SAAmB;QAEnB,MAAM,QAAQ,GAAG,aAAa;aAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,cAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;aACnC,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,MAAM,OAAO,GACX,SAAS,CAAC,MAAM,GAAG,CAAC;YAClB,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;YAC/C,CAAC,CAAC,yBAAyB,CAAC;QAEhC,OAAO,YAAY,aAAa,CAAC,MAAM,cAAc,QAAQ,OAAO,OAAO,EAAE,CAAC;IAChF,CAAC;CACF;AA3hBD,0CA2hBC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { AgentProgressEvent } from './agent/AgentCore';
|
|
3
|
-
import { ElementContext } from '@rivet/core';
|
|
4
|
-
export type CommentSessionStatus = 'running' | 'complete' | 'error';
|
|
5
|
-
export type CommentSession = {
|
|
6
|
-
commentId: string;
|
|
7
|
-
instruction: string;
|
|
8
|
-
elementContext: ElementContext;
|
|
9
|
-
status: CommentSessionStatus;
|
|
10
|
-
abortController: AbortController;
|
|
11
|
-
sessionId: string | null;
|
|
12
|
-
messages: AgentProgressEvent[];
|
|
13
|
-
};
|
|
14
|
-
export type CommentSSEEvent = {
|
|
15
|
-
type: 'comment:status';
|
|
16
|
-
commentId: string;
|
|
17
|
-
status: CommentSessionStatus;
|
|
18
|
-
} | {
|
|
19
|
-
type: 'comment:step';
|
|
20
|
-
commentId: string;
|
|
21
|
-
step: AgentProgressEvent;
|
|
22
|
-
} | {
|
|
23
|
-
type: 'comment:message';
|
|
24
|
-
commentId: string;
|
|
25
|
-
content: string;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Manages concurrent agent sessions spawned by element comments.
|
|
29
|
-
* Each comment gets its own AgentCore subprocess.
|
|
30
|
-
* Emits SSE events for frontend consumption via a multiplexed stream.
|
|
31
|
-
*/
|
|
32
|
-
export declare class CommentSessionManager extends EventEmitter {
|
|
33
|
-
private sessions;
|
|
34
|
-
private core;
|
|
35
|
-
private projectPath;
|
|
36
|
-
private orphanCleanupTimer;
|
|
37
|
-
private connectedClients;
|
|
38
|
-
constructor(projectPath: string);
|
|
39
|
-
/**
|
|
40
|
-
* Start an agent session for a comment.
|
|
41
|
-
* Spawns a new AgentCore subprocess and streams progress events.
|
|
42
|
-
*
|
|
43
|
-
* @effect Spawns a child process, emits SSE events
|
|
44
|
-
*/
|
|
45
|
-
startSession(commentId: string, instruction: string, elementContext: ElementContext): void;
|
|
46
|
-
/**
|
|
47
|
-
* Abort and remove a single session
|
|
48
|
-
*/
|
|
49
|
-
abortSession(commentId: string): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Abort all running sessions and clear the map
|
|
52
|
-
*/
|
|
53
|
-
abortAll(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Check if a session exists
|
|
56
|
-
*/
|
|
57
|
-
hasSession(commentId: string): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Get current session count
|
|
60
|
-
*/
|
|
61
|
-
getSessionCount(): number;
|
|
62
|
-
/**
|
|
63
|
-
* Track SSE client connections for orphan cleanup
|
|
64
|
-
*/
|
|
65
|
-
clientConnected(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Track SSE client disconnections.
|
|
68
|
-
* Starts orphan cleanup timer if no clients remain.
|
|
69
|
-
*/
|
|
70
|
-
clientDisconnected(): void;
|
|
71
|
-
/**
|
|
72
|
-
* Execute the agent for a comment session and emit progress events.
|
|
73
|
-
*
|
|
74
|
-
* @effect Streams AgentProgressEvents via SSE, updates session status
|
|
75
|
-
*/
|
|
76
|
-
private runAgent;
|
|
77
|
-
/**
|
|
78
|
-
* Emit an SSE event to all connected clients
|
|
79
|
-
*/
|
|
80
|
-
private emitSSE;
|
|
81
|
-
/**
|
|
82
|
-
* Build system prompt for the comment agent
|
|
83
|
-
*/
|
|
84
|
-
private buildSystemPrompt;
|
|
85
|
-
/**
|
|
86
|
-
* Build the user prompt for the comment agent
|
|
87
|
-
*/
|
|
88
|
-
private buildUserPrompt;
|
|
89
|
-
/**
|
|
90
|
-
* Register process shutdown handlers to abort all sessions
|
|
91
|
-
*/
|
|
92
|
-
private registerShutdownHandlers;
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=CommentSessionManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommentSessionManager.d.ts","sourceRoot":"","sources":["../../src/services/CommentSessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAa,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpE,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,kBAAkB,EAAE,CAA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