@siftd/connect-agent 0.2.29 → 0.2.31

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.
@@ -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;
package/dist/websocket.js CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import WebSocket from 'ws';
10
10
  import { getServerUrl, getAgentToken } from './config.js';
11
+ import { handleAssetRequest, buildGalleryState, galleryStateToMessage } from './core/asset-api.js';
11
12
  export class AgentWebSocket {
12
13
  ws = null;
13
14
  serverUrl;
@@ -180,7 +181,7 @@ export class AgentWebSocket {
180
181
  });
181
182
  }
182
183
  /**
183
- * Send gallery workers with their assets
184
+ * Send gallery workers with their assets (legacy)
184
185
  */
185
186
  sendGalleryWorkers(workers) {
186
187
  this.sendToServer({
@@ -188,6 +189,19 @@ export class AgentWebSocket {
188
189
  workers
189
190
  });
190
191
  }
192
+ /**
193
+ * Send full gallery state (new fast-path system)
194
+ */
195
+ sendGalleryState() {
196
+ const state = buildGalleryState();
197
+ this.sendToServer(galleryStateToMessage(state));
198
+ }
199
+ /**
200
+ * Send asset response
201
+ */
202
+ sendAssetResponse(response) {
203
+ this.sendToServer(response);
204
+ }
191
205
  /**
192
206
  * Check if connected
193
207
  */
@@ -228,8 +242,18 @@ export class AgentWebSocket {
228
242
  this.messageHandler(message);
229
243
  }
230
244
  break;
245
+ case 'asset_request':
246
+ // Handle asset requests (fast-path, no LLM)
247
+ this.handleAssetRequest(message);
248
+ break;
231
249
  default:
232
- console.log('[WS] Unknown message type:', message.type);
250
+ // Check if it's an asset request type
251
+ if (message.type.startsWith('asset.') || message.type.startsWith('view.')) {
252
+ this.handleAssetRequest(message);
253
+ }
254
+ else {
255
+ console.log('[WS] Unknown message type:', message.type);
256
+ }
233
257
  }
234
258
  }
235
259
  catch (error) {
@@ -241,6 +265,20 @@ export class AgentWebSocket {
241
265
  this.ws.send(JSON.stringify(data));
242
266
  }
243
267
  }
268
+ /**
269
+ * Handle asset requests (fast-path, no LLM)
270
+ */
271
+ async handleAssetRequest(message) {
272
+ const request = {
273
+ type: message.type,
274
+ requestId: message.requestId || message.id || 'unknown',
275
+ assetId: message.assetId,
276
+ groupId: message.groupId,
277
+ viewId: message.viewId,
278
+ };
279
+ const response = await handleAssetRequest(request);
280
+ this.sendAssetResponse(response);
281
+ }
244
282
  startPingInterval() {
245
283
  this.pingInterval = setInterval(() => {
246
284
  if (this.connected()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siftd/connect-agent",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
4
4
  "description": "Master orchestrator agent - control Claude Code remotely via web",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",