@siftd/connect-agent 0.2.30 → 0.2.32

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.
@@ -0,0 +1,408 @@
1
+ /**
2
+ * Preview Worker - Fast-path local preview generation
3
+ *
4
+ * Watches ~/Lia-Hub/shared/outputs/ and generates:
5
+ * - Thumbnails (for images)
6
+ * - Metadata extraction (dimensions, page count, text snippets)
7
+ * - Preview JSON for instant gallery display
8
+ *
9
+ * NO LLM involvement - pure local, deterministic processing.
10
+ * Targets sub-second response for most assets.
11
+ *
12
+ * Uses chokidar for reliable cross-platform file watching with:
13
+ * - awaitWriteFinish to handle half-written files
14
+ * - Ignore patterns to avoid loops (*.asset.json, thumbs, etc.)
15
+ */
16
+ import chokidar from 'chokidar';
17
+ import { readFileSync, existsSync, mkdirSync } from 'fs';
18
+ import { join, basename } from 'path';
19
+ import { execSync } from 'child_process';
20
+ import { createAssetManifest, writeAssetManifest, readAssetManifest, getPreviewCacheDir, getPreviewCacheKey, getPreviewFromCache, savePreviewToCache, } from './assets.js';
21
+ import { getSharedOutputPath } from './hub.js';
22
+ // Files to ignore when watching (prevents watcher loops)
23
+ const IGNORE_PATTERNS = [
24
+ '**/*.asset.json',
25
+ '**/*.preview.json',
26
+ '**/.thumbs/**',
27
+ '**/thumbs/**',
28
+ '**/*.tmp',
29
+ '**/.DS_Store',
30
+ '**/node_modules/**',
31
+ '**/.git/**',
32
+ ];
33
+ export class PreviewWorker {
34
+ watcher = null;
35
+ queue = [];
36
+ processing = new Set();
37
+ debounceTimers = new Map();
38
+ concurrency;
39
+ options;
40
+ running = false;
41
+ rootDir;
42
+ constructor(options = {}) {
43
+ this.options = options;
44
+ this.concurrency = options.concurrency || 4;
45
+ this.rootDir = getSharedOutputPath();
46
+ }
47
+ /**
48
+ * Start watching directories
49
+ */
50
+ start() {
51
+ if (this.running)
52
+ return;
53
+ this.running = true;
54
+ const dirs = this.options.watchDirs || [this.rootDir];
55
+ for (const dir of dirs) {
56
+ if (!existsSync(dir)) {
57
+ mkdirSync(dir, { recursive: true });
58
+ }
59
+ }
60
+ this.log(`Watching: ${dirs.join(', ')}`);
61
+ // Use chokidar for reliable watching with:
62
+ // - awaitWriteFinish: wait until file size is stable (handles half-written files)
63
+ // - ignored: prevent watcher loops
64
+ this.watcher = chokidar.watch(dirs, {
65
+ ignoreInitial: false, // Process existing files on startup
66
+ persistent: true,
67
+ awaitWriteFinish: {
68
+ stabilityThreshold: 400, // Wait 400ms for file size to stabilize
69
+ pollInterval: 100,
70
+ },
71
+ ignored: IGNORE_PATTERNS,
72
+ depth: 10,
73
+ });
74
+ this.watcher.on('add', (filePath) => this.handleFile(filePath));
75
+ this.watcher.on('change', (filePath) => this.handleFile(filePath));
76
+ this.watcher.on('error', (error) => this.log(`Watcher error: ${error}`));
77
+ }
78
+ /**
79
+ * Handle file add/change with debouncing
80
+ */
81
+ handleFile(filePath) {
82
+ // Clear existing debounce timer for this file
83
+ const existingTimer = this.debounceTimers.get(filePath);
84
+ if (existingTimer) {
85
+ clearTimeout(existingTimer);
86
+ }
87
+ // Debounce: wait 100ms before processing to batch rapid changes
88
+ const timer = setTimeout(() => {
89
+ this.debounceTimers.delete(filePath);
90
+ this.enqueue(filePath);
91
+ }, 100);
92
+ this.debounceTimers.set(filePath, timer);
93
+ }
94
+ /**
95
+ * Stop watching
96
+ */
97
+ stop() {
98
+ this.running = false;
99
+ // Clear all debounce timers
100
+ for (const timer of this.debounceTimers.values()) {
101
+ clearTimeout(timer);
102
+ }
103
+ this.debounceTimers.clear();
104
+ if (this.watcher) {
105
+ this.watcher.close();
106
+ this.watcher = null;
107
+ }
108
+ }
109
+ /**
110
+ * Add file to processing queue
111
+ */
112
+ enqueue(filePath) {
113
+ if (this.queue.includes(filePath) || this.processing.has(filePath)) {
114
+ return;
115
+ }
116
+ this.queue.push(filePath);
117
+ this.processQueue();
118
+ }
119
+ /**
120
+ * Process queue with concurrency limit
121
+ */
122
+ async processQueue() {
123
+ while (this.running && this.queue.length > 0 && this.processing.size < this.concurrency) {
124
+ const filePath = this.queue.shift();
125
+ if (!filePath)
126
+ continue;
127
+ this.processing.add(filePath);
128
+ this.processFile(filePath)
129
+ .catch(err => this.log(`Error processing ${filePath}: ${err}`))
130
+ .finally(() => {
131
+ this.processing.delete(filePath);
132
+ this.processQueue();
133
+ });
134
+ }
135
+ }
136
+ /**
137
+ * Process a single file - generate manifest and preview
138
+ */
139
+ async processFile(filePath) {
140
+ // Skip if file no longer exists
141
+ if (!existsSync(filePath))
142
+ return;
143
+ const startTime = Date.now();
144
+ // Check for existing manifest
145
+ let manifest = readAssetManifest(filePath);
146
+ if (!manifest) {
147
+ // Create new manifest with rootDir for stable IDs
148
+ manifest = createAssetManifest(filePath, {
149
+ groupId: this.extractGroupId(filePath),
150
+ rootDir: this.rootDir,
151
+ });
152
+ writeAssetManifest(manifest);
153
+ this.log(`Created manifest: ${manifest.name} (${manifest.id})`);
154
+ this.options.onAsset?.(manifest);
155
+ }
156
+ // Check preview cache
157
+ const cacheKey = getPreviewCacheKey(manifest.sha256);
158
+ let preview = getPreviewFromCache(cacheKey);
159
+ if (!preview) {
160
+ // Generate preview
161
+ preview = await this.generatePreview(manifest, cacheKey);
162
+ savePreviewToCache(preview);
163
+ const elapsed = Date.now() - startTime;
164
+ this.log(`Generated preview: ${manifest.name} (${elapsed}ms)`);
165
+ }
166
+ this.options.onPreview?.(preview);
167
+ }
168
+ /**
169
+ * Generate preview for an asset
170
+ */
171
+ async generatePreview(manifest, cacheKey) {
172
+ const preview = {
173
+ assetId: manifest.id,
174
+ generatedAt: Date.now(),
175
+ cacheKey,
176
+ };
177
+ const mime = manifest.mime;
178
+ // Image preview
179
+ if (mime.startsWith('image/')) {
180
+ const imageInfo = this.getImageInfo(manifest.path);
181
+ if (imageInfo) {
182
+ preview.dimensions = imageInfo.dimensions;
183
+ preview.thumbnailData = this.generateImageThumbnail(manifest.path);
184
+ }
185
+ }
186
+ // PDF preview
187
+ else if (mime === 'application/pdf') {
188
+ const pdfInfo = this.getPdfInfo(manifest.path);
189
+ if (pdfInfo) {
190
+ preview.pageCount = pdfInfo.pageCount;
191
+ preview.textSnippet = pdfInfo.textSnippet;
192
+ }
193
+ }
194
+ // Text/code preview
195
+ else if (mime.startsWith('text/') || mime === 'application/json') {
196
+ preview.textSnippet = this.getTextSnippet(manifest.path);
197
+ }
198
+ return preview;
199
+ }
200
+ /**
201
+ * Get image dimensions using sips (macOS) or file command
202
+ */
203
+ getImageInfo(filePath) {
204
+ try {
205
+ // Try sips on macOS
206
+ if (process.platform === 'darwin') {
207
+ const output = execSync(`sips -g pixelWidth -g pixelHeight "${filePath}" 2>/dev/null`, { encoding: 'utf-8', timeout: 5000 });
208
+ const widthMatch = output.match(/pixelWidth:\s*(\d+)/);
209
+ const heightMatch = output.match(/pixelHeight:\s*(\d+)/);
210
+ if (widthMatch && heightMatch) {
211
+ return {
212
+ dimensions: {
213
+ width: parseInt(widthMatch[1], 10),
214
+ height: parseInt(heightMatch[1], 10),
215
+ },
216
+ };
217
+ }
218
+ }
219
+ // Try file command (cross-platform)
220
+ const output = execSync(`file "${filePath}"`, { encoding: 'utf-8', timeout: 5000 });
221
+ const match = output.match(/(\d+)\s*x\s*(\d+)/);
222
+ if (match) {
223
+ return {
224
+ dimensions: {
225
+ width: parseInt(match[1], 10),
226
+ height: parseInt(match[2], 10),
227
+ },
228
+ };
229
+ }
230
+ }
231
+ catch {
232
+ // Ignore errors
233
+ }
234
+ return null;
235
+ }
236
+ /**
237
+ * Generate thumbnail as base64 data URL
238
+ * Uses sips on macOS for fast resizing
239
+ */
240
+ generateImageThumbnail(filePath, maxSize = 200) {
241
+ try {
242
+ if (process.platform !== 'darwin')
243
+ return undefined;
244
+ const cacheDir = getPreviewCacheDir();
245
+ const thumbName = `thumb_${basename(filePath)}.jpg`;
246
+ const thumbPath = join(cacheDir, thumbName);
247
+ // Use sips to resize
248
+ execSync(`sips -Z ${maxSize} -s format jpeg "${filePath}" --out "${thumbPath}" 2>/dev/null`, { timeout: 10000 });
249
+ // Read as base64
250
+ const data = readFileSync(thumbPath);
251
+ return `data:image/jpeg;base64,${data.toString('base64')}`;
252
+ }
253
+ catch {
254
+ return undefined;
255
+ }
256
+ }
257
+ /**
258
+ * Get PDF info using pdfinfo or mdls
259
+ */
260
+ getPdfInfo(filePath) {
261
+ try {
262
+ let pageCount;
263
+ // Try pdfinfo
264
+ try {
265
+ const output = execSync(`pdfinfo "${filePath}" 2>/dev/null`, {
266
+ encoding: 'utf-8',
267
+ timeout: 5000,
268
+ });
269
+ const match = output.match(/Pages:\s*(\d+)/);
270
+ if (match) {
271
+ pageCount = parseInt(match[1], 10);
272
+ }
273
+ }
274
+ catch {
275
+ // Try mdls on macOS
276
+ if (process.platform === 'darwin') {
277
+ const output = execSync(`mdls -name kMDItemNumberOfPages "${filePath}" 2>/dev/null`, {
278
+ encoding: 'utf-8',
279
+ timeout: 5000,
280
+ });
281
+ const match = output.match(/kMDItemNumberOfPages\s*=\s*(\d+)/);
282
+ if (match) {
283
+ pageCount = parseInt(match[1], 10);
284
+ }
285
+ }
286
+ }
287
+ // Try to extract text snippet
288
+ let textSnippet;
289
+ try {
290
+ const output = execSync(`pdftotext -l 1 -q "${filePath}" - 2>/dev/null | head -c 500`, {
291
+ encoding: 'utf-8',
292
+ timeout: 10000,
293
+ });
294
+ if (output.trim()) {
295
+ textSnippet = output.trim().substring(0, 500);
296
+ }
297
+ }
298
+ catch {
299
+ // pdftotext not available
300
+ }
301
+ return { pageCount, textSnippet };
302
+ }
303
+ catch {
304
+ return null;
305
+ }
306
+ }
307
+ /**
308
+ * Get text snippet from file
309
+ */
310
+ getTextSnippet(filePath, maxChars = 500) {
311
+ try {
312
+ const content = readFileSync(filePath, 'utf-8');
313
+ return content.substring(0, maxChars);
314
+ }
315
+ catch {
316
+ return undefined;
317
+ }
318
+ }
319
+ /**
320
+ * Extract group ID from file path
321
+ * e.g., ~/Lia-Hub/shared/outputs/run_abc123/file.png -> run_abc123
322
+ */
323
+ extractGroupId(filePath) {
324
+ const outputPath = getSharedOutputPath();
325
+ if (filePath.startsWith(outputPath)) {
326
+ const relative = filePath.substring(outputPath.length + 1);
327
+ const parts = relative.split('/');
328
+ if (parts.length > 1) {
329
+ return parts[0]; // First directory is the group
330
+ }
331
+ }
332
+ return undefined;
333
+ }
334
+ log(message) {
335
+ if (this.options.verbose) {
336
+ console.log(`[PREVIEW] ${message}`);
337
+ }
338
+ }
339
+ }
340
+ let registry = null;
341
+ export function getAssetRegistry() {
342
+ if (!registry) {
343
+ registry = {
344
+ assets: new Map(),
345
+ previews: new Map(),
346
+ byGroup: new Map(),
347
+ };
348
+ }
349
+ return registry;
350
+ }
351
+ export function registerAsset(manifest) {
352
+ const reg = getAssetRegistry();
353
+ reg.assets.set(manifest.id, manifest);
354
+ if (manifest.groupId) {
355
+ if (!reg.byGroup.has(manifest.groupId)) {
356
+ reg.byGroup.set(manifest.groupId, new Set());
357
+ }
358
+ reg.byGroup.get(manifest.groupId).add(manifest.id);
359
+ }
360
+ }
361
+ export function registerPreview(preview) {
362
+ const reg = getAssetRegistry();
363
+ reg.previews.set(preview.assetId, preview);
364
+ }
365
+ export function getAsset(assetId) {
366
+ return getAssetRegistry().assets.get(assetId);
367
+ }
368
+ export function getPreview(assetId) {
369
+ return getAssetRegistry().previews.get(assetId);
370
+ }
371
+ export function getAssetsByGroup(groupId) {
372
+ const reg = getAssetRegistry();
373
+ const ids = reg.byGroup.get(groupId);
374
+ if (!ids)
375
+ return [];
376
+ return Array.from(ids).map(id => reg.assets.get(id)).filter(Boolean);
377
+ }
378
+ export function getAllAssets() {
379
+ return Array.from(getAssetRegistry().assets.values());
380
+ }
381
+ // ============================================================================
382
+ // SINGLETON WORKER
383
+ // ============================================================================
384
+ let previewWorker = null;
385
+ export function startPreviewWorker(options = {}) {
386
+ if (previewWorker) {
387
+ return previewWorker;
388
+ }
389
+ previewWorker = new PreviewWorker({
390
+ ...options,
391
+ onAsset: (manifest) => {
392
+ registerAsset(manifest);
393
+ options.onAsset?.(manifest);
394
+ },
395
+ onPreview: (preview) => {
396
+ registerPreview(preview);
397
+ options.onPreview?.(preview);
398
+ },
399
+ });
400
+ previewWorker.start();
401
+ return previewWorker;
402
+ }
403
+ export function stopPreviewWorker() {
404
+ if (previewWorker) {
405
+ previewWorker.stop();
406
+ previewWorker = null;
407
+ }
408
+ }
@@ -51,10 +51,10 @@
51
51
  "notes": "Always check memory before asking user for paths"
52
52
  },
53
53
  {
54
- "scenario": "Preview HTML/web project",
55
- "approach": "start_local_server + open_browser",
56
- "example": "start_local_server('/path/to/project', 8080) then open_browser('http://localhost:8080')",
57
- "notes": "Serve files and open in browser for preview"
54
+ "scenario": "Preview worker outputs (images, code, files)",
55
+ "approach": "Workers write files, gallery shows them automatically",
56
+ "example": "spawn_worker('Create the image and save to ~/Lia-Hub/shared/outputs/') - gallery displays result",
57
+ "notes": "NEVER use localhost servers for previews. The Connect web UI gallery handles all asset display in-app."
58
58
  },
59
59
  {
60
60
  "scenario": "Debug failing workers",
@@ -83,6 +83,11 @@
83
83
  "wrong": "Guessing file paths",
84
84
  "right": "Use search_memory or ask user",
85
85
  "reason": "Memory stores indexed filesystem, use it"
86
+ },
87
+ {
88
+ "wrong": "Using start_local_server + open_browser for previews",
89
+ "right": "Workers write to ~/Lia-Hub/shared/outputs/, gallery displays automatically",
90
+ "reason": "Connect's web UI has a built-in gallery. localhost servers open random tabs and break UX."
86
91
  }
87
92
  ]
88
93
  }
@@ -122,6 +122,15 @@ You have a personal hub at ~/Lia-Hub/ for organizing your work:
122
122
  - **~/Lia-Hub/notebook-a/WORKER-LOG.md** - Track all workers you spawn
123
123
  - **~/Lia-Hub/shared/outputs/** - Where workers save their outputs
124
124
 
125
+ ASSET PREVIEWS & GALLERY:
126
+ The Connect web UI has a built-in gallery that shows worker outputs automatically.
127
+ ⛔ NEVER use start_local_server or open_browser for previews
128
+ ⛔ NEVER ask workers to start servers on localhost
129
+ ⛔ NEVER open localhost URLs - they won't work for remote users
130
+ ✅ Workers write files to ~/Lia-Hub/shared/outputs/
131
+ ✅ Gallery displays assets in-app as workers complete
132
+ ✅ Use open_browser ONLY for external websites (not localhost)
133
+
125
134
  BEFORE STARTING COMPLEX WORK:
126
135
  1. Check CLAUDE.md for user instructions
127
136
  2. Read LANDMARKS.md for current context
@@ -844,13 +853,13 @@ Be specific about what you want done.`,
844
853
  },
845
854
  {
846
855
  name: 'open_browser',
847
- description: 'Open a URL or file in the user\'s default browser. Use for opening localhost servers, web pages, or local HTML files.',
856
+ description: 'Open a URL in the user\'s default browser. ⚠️ ONLY for external websites (https://). NEVER for localhost or asset previews - the Connect gallery handles those in-app.',
848
857
  input_schema: {
849
858
  type: 'object',
850
859
  properties: {
851
860
  url: {
852
861
  type: 'string',
853
- description: 'URL to open (e.g., http://localhost:8080, https://example.com, or file path)'
862
+ description: 'URL to open (https://example.com). NEVER use localhost URLs.'
854
863
  }
855
864
  },
856
865
  required: ['url']
@@ -858,7 +867,7 @@ Be specific about what you want done.`,
858
867
  },
859
868
  {
860
869
  name: 'start_local_server',
861
- description: 'Start a persistent HTTP server to serve a web project. Server runs in background and survives after this call. Use before open_browser for local web projects.',
870
+ description: '⚠️ DEPRECATED for previews. The Connect gallery shows worker outputs in-app. Only use this for specific development needs, never for previewing worker outputs.',
862
871
  input_schema: {
863
872
  type: 'object',
864
873
  properties: {
@@ -1287,6 +1296,14 @@ Be specific about what you want done.`,
1287
1296
  */
1288
1297
  async executeOpenBrowser(url) {
1289
1298
  try {
1299
+ // Block localhost URLs - gallery handles asset previews in-app
1300
+ if (url.includes('localhost') || url.includes('127.0.0.1') || url.match(/:80[0-9]{2}/)) {
1301
+ console.log(`[ORCHESTRATOR] Blocked localhost URL: ${url}`);
1302
+ return {
1303
+ success: false,
1304
+ output: `⛔ BLOCKED: Cannot open localhost URLs. The Connect gallery displays worker outputs in-app automatically. Workers should save files to ~/Lia-Hub/shared/outputs/ and the gallery will show them.`
1305
+ };
1306
+ }
1290
1307
  // Use 'open' on macOS, 'xdg-open' on Linux, 'start' on Windows
1291
1308
  const platform = process.platform;
1292
1309
  let command;
@@ -1312,6 +1329,8 @@ Be specific about what you want done.`,
1312
1329
  * Start a persistent HTTP server
1313
1330
  */
1314
1331
  async executeStartServer(directory, port = 8080) {
1332
+ // Warn that this shouldn't be used for previews
1333
+ console.log(`[ORCHESTRATOR] ⚠️ start_local_server called - consider using gallery for previews instead`);
1315
1334
  try {
1316
1335
  // First, check if something is already running on this port
1317
1336
  try {
@@ -1319,7 +1338,7 @@ Be specific about what you want done.`,
1319
1338
  if (existing) {
1320
1339
  return {
1321
1340
  success: true,
1322
- output: `Server already running on port ${port}. URL: http://localhost:${port}`
1341
+ output: `⚠️ Note: For previewing worker outputs, the Connect gallery shows them in-app automatically. Server already running on port ${port}.`
1323
1342
  };
1324
1343
  }
1325
1344
  }
@@ -1341,7 +1360,7 @@ Be specific about what you want done.`,
1341
1360
  console.log(`[ORCHESTRATOR] Started server on port ${port} for ${directory}`);
1342
1361
  return {
1343
1362
  success: true,
1344
- output: `Started HTTP server on http://localhost:${port} serving ${directory}`
1363
+ output: `Started HTTP server on port ${port}. ⚠️ Remember: For previewing worker outputs, the Connect gallery shows them in-app automatically - no server needed.`
1345
1364
  };
1346
1365
  }
1347
1366
  catch {
@@ -8,7 +8,7 @@
8
8
  * Core worker identity and rules
9
9
  * This is the foundation every worker receives
10
10
  */
11
- export declare const WORKER_IDENTITY = "## Worker Identity\nYou are a Claude Code CLI worker executing a delegated task.\nYou report to the Master Orchestrator.\n\n## Critical Rules\n1. Do NOT open browsers or start servers\n2. Do NOT ask questions - just do the work\n3. Output files to the shared workspace unless specified\n4. Report file paths you create at the end\n5. Be concise and efficient";
11
+ export declare const WORKER_IDENTITY = "## Worker Identity\nYou are a Claude Code CLI worker executing a delegated task.\nYou report to the Master Orchestrator.\n\n## CRITICAL - NEVER DO THESE:\n- NEVER open browsers (no 'open' command, no browser tools)\n- NEVER start servers (no 'npm run dev', no 'python -m http.server', etc.)\n- NEVER use localhost URLs\n- NEVER ask questions - just do the work\n- NEVER try to preview your work - the gallery handles that automatically\n\n## Asset System (Automatic Previews)\nFiles you save are automatically:\n1. Detected by the preview worker\n2. Thumbnailed (images) and metadata extracted\n3. Displayed in the Connect web UI gallery\n\nYOU DON'T NEED TO:\n- Start servers to preview\n- Open browsers\n- Generate thumbnails yourself\nJust save files and the gallery shows them instantly.\n\n## What You SHOULD Do:\n1. Create/edit files as needed\n2. Save outputs to the shared workspace\n3. Report file paths you create at the end\n4. Be concise and efficient";
12
12
  /**
13
13
  * Output format workers should follow
14
14
  */
@@ -13,12 +13,30 @@ export const WORKER_IDENTITY = `## Worker Identity
13
13
  You are a Claude Code CLI worker executing a delegated task.
14
14
  You report to the Master Orchestrator.
15
15
 
16
- ## Critical Rules
17
- 1. Do NOT open browsers or start servers
18
- 2. Do NOT ask questions - just do the work
19
- 3. Output files to the shared workspace unless specified
20
- 4. Report file paths you create at the end
21
- 5. Be concise and efficient`;
16
+ ## CRITICAL - NEVER DO THESE:
17
+ - NEVER open browsers (no 'open' command, no browser tools)
18
+ - NEVER start servers (no 'npm run dev', no 'python -m http.server', etc.)
19
+ - NEVER use localhost URLs
20
+ - NEVER ask questions - just do the work
21
+ - NEVER try to preview your work - the gallery handles that automatically
22
+
23
+ ## Asset System (Automatic Previews)
24
+ Files you save are automatically:
25
+ 1. Detected by the preview worker
26
+ 2. Thumbnailed (images) and metadata extracted
27
+ 3. Displayed in the Connect web UI gallery
28
+
29
+ YOU DON'T NEED TO:
30
+ - Start servers to preview
31
+ - Open browsers
32
+ - Generate thumbnails yourself
33
+ Just save files and the gallery shows them instantly.
34
+
35
+ ## What You SHOULD Do:
36
+ 1. Create/edit files as needed
37
+ 2. Save outputs to the shared workspace
38
+ 3. Report file paths you create at the end
39
+ 4. Be concise and efficient`;
22
40
  /**
23
41
  * Output format workers should follow
24
42
  */
@@ -110,10 +128,19 @@ export function buildWorkerPrompt(task, options = {}) {
110
128
  * Lighter version for quick operations
111
129
  */
112
130
  export function getQuickWorkerPrompt(task, context) {
131
+ const sharedPath = getSharedOutputPath();
113
132
  let prompt = task;
114
133
  if (context) {
115
134
  prompt = `Context: ${context}\n\nTask: ${task}`;
116
135
  }
117
- prompt += `\n\nBe concise. Output results directly. Do NOT open browsers or start servers - just create files and report paths.`;
136
+ prompt += `
137
+
138
+ Save outputs to: ${sharedPath}
139
+
140
+ CRITICAL RESTRICTIONS:
141
+ - NEVER open browsers (no 'open' command)
142
+ - NEVER start servers (no localhost)
143
+ - NEVER try to preview - gallery shows files automatically
144
+ Just create files and report paths. Be concise.`;
118
145
  return prompt;
119
146
  }
@@ -7,14 +7,19 @@
7
7
  * - Supports interruption and progress updates
8
8
  */
9
9
  import type { WorkerStatus } from './orchestrator.js';
10
+ import { AssetResponse } from './core/asset-api.js';
10
11
  export type MessageHandler = (message: WebSocketMessage) => Promise<void>;
11
12
  export type StreamHandler = (chunk: string) => void;
12
13
  export interface WebSocketMessage {
13
- type: 'message' | 'interrupt' | 'ping' | 'pong' | 'connected';
14
+ type: 'message' | 'interrupt' | 'ping' | 'pong' | 'connected' | 'asset_request';
14
15
  id?: string;
15
16
  content?: string;
16
17
  timestamp?: number;
17
18
  apiKey?: string;
19
+ requestId?: string;
20
+ assetId?: string;
21
+ groupId?: string;
22
+ viewId?: string;
18
23
  }
19
24
  export interface StreamingResponse {
20
25
  send: (chunk: string) => void;
@@ -67,7 +72,7 @@ export declare class AgentWebSocket {
67
72
  */
68
73
  sendGalleryCommand(command: 'open' | 'close' | 'focus_worker' | 'open_asset' | 'back', workerId?: string, assetIndex?: number): void;
69
74
  /**
70
- * Send gallery workers with their assets
75
+ * Send gallery workers with their assets (legacy)
71
76
  */
72
77
  sendGalleryWorkers(workers: Array<{
73
78
  id: string;
@@ -85,6 +90,14 @@ export declare class AgentWebSocket {
85
90
  }>;
86
91
  }>;
87
92
  }>): void;
93
+ /**
94
+ * Send full gallery state (new fast-path system)
95
+ */
96
+ sendGalleryState(): void;
97
+ /**
98
+ * Send asset response
99
+ */
100
+ sendAssetResponse(response: AssetResponse): void;
88
101
  /**
89
102
  * Check if connected
90
103
  */
@@ -95,6 +108,10 @@ export declare class AgentWebSocket {
95
108
  close(): void;
96
109
  private handleMessage;
97
110
  private sendToServer;
111
+ /**
112
+ * Handle asset requests (fast-path, no LLM)
113
+ */
114
+ private handleAssetRequest;
98
115
  private startPingInterval;
99
116
  private stopPingInterval;
100
117
  private attemptReconnect;