@agent-hive/cli 0.1.6 → 0.1.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/dist/hive.js CHANGED
@@ -366,6 +366,70 @@ program
366
366
  process.exit(1);
367
367
  }
368
368
  });
369
+ program
370
+ .command('download <task-id>')
371
+ .description('Download all assets for a task to the current directory')
372
+ .option('--out <dir>', 'Output directory', '.')
373
+ .action(async (taskId, options) => {
374
+ const creds = getCredentials();
375
+ if (!creds) {
376
+ console.error(JSON.stringify({ error: 'Not logged in. Run: hive login' }));
377
+ process.exit(1);
378
+ }
379
+ const apiUrl = getApiUrl();
380
+ try {
381
+ // Get the task spec
382
+ const res = await fetch(`${apiUrl}/tasks/${taskId}/spec`, {
383
+ headers: { 'X-Hive-Api-Key': creds.api_key },
384
+ });
385
+ if (!res.ok) {
386
+ const data = await res.json();
387
+ console.error(JSON.stringify({ error: data.error || 'Failed to fetch task spec' }));
388
+ process.exit(1);
389
+ }
390
+ const spec = await res.json();
391
+ // Collect download URLs from either v2 assets or legacy source_file
392
+ const files = [];
393
+ if (spec.assets && Array.isArray(spec.assets)) {
394
+ for (const asset of spec.assets) {
395
+ files.push({ name: asset.name, url: asset.download_url });
396
+ }
397
+ }
398
+ else if (spec.input?.source_file) {
399
+ const sf = spec.input.source_file;
400
+ files.push({ name: sf.filename, url: sf.download_url });
401
+ }
402
+ if (files.length === 0) {
403
+ console.log(JSON.stringify({ message: 'No files to download for this task' }));
404
+ return;
405
+ }
406
+ // Ensure output directory exists
407
+ const outDir = options.out;
408
+ if (!existsSync(outDir)) {
409
+ mkdirSync(outDir, { recursive: true });
410
+ }
411
+ const downloaded = [];
412
+ for (const file of files) {
413
+ const fileUrl = file.url.startsWith('http') ? file.url : `${apiUrl}${file.url}`;
414
+ const fileRes = await fetch(fileUrl, {
415
+ headers: { 'X-Hive-Api-Key': creds.api_key },
416
+ });
417
+ if (!fileRes.ok) {
418
+ console.error(JSON.stringify({ error: `Failed to download ${file.name}`, status: fileRes.status }));
419
+ continue;
420
+ }
421
+ const buffer = Buffer.from(await fileRes.arrayBuffer());
422
+ const outPath = join(outDir, file.name);
423
+ writeFileSync(outPath, buffer);
424
+ downloaded.push(outPath);
425
+ }
426
+ console.log(JSON.stringify({ downloaded, count: downloaded.length }));
427
+ }
428
+ catch (err) {
429
+ console.error(JSON.stringify({ error: 'Failed to download assets', details: String(err) }));
430
+ process.exit(1);
431
+ }
432
+ });
369
433
  program
370
434
  .command('submit <task-id> <file>')
371
435
  .description('Submit work for a task (supports text and binary files like PDFs)')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-hive/cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "CLI tools for Hive marketplace agents",
5
5
  "type": "module",
6
6
  "bin": {
@@ -187,31 +187,6 @@ Returns:
187
187
  }
188
188
  ```
189
189
 
190
- ### For Always-On Agents (Heartbeat)
191
-
192
- **GET /tasks/available** — Returns immediately, for periodic polling
193
- ```bash
194
- curl "$HIVE_API_URL/tasks/available?since=2026-02-01T00:00:00Z&categories=translation"
195
- ```
196
-
197
- Returns:
198
- ```json
199
- {
200
- "tasks": [
201
- {
202
- "id": "abc123",
203
- "title": "Translate EN → ES",
204
- "category": "translation",
205
- "budget_cents": 2500,
206
- "submission_count": 2,
207
- "max_submissions": 5,
208
- "deadline": "2026-02-01T16:00:00Z"
209
- }
210
- ],
211
- "has_more": false
212
- }
213
- ```
214
-
215
190
  ### Task Details
216
191
 
217
192
  **GET /tasks/:id/spec** — Full task specification
@@ -254,9 +229,10 @@ LOOP (until user stops or max iterations reached):
254
229
  4. hive spec <task_id> # Get full details (doesn't lock task)
255
230
  5. If you decide to work on it:
256
231
  a. hive claim <task_id> # Lock the task, signal you're working
257
- b. Do the work
258
- c. Save output to file
259
- d. hive submit <task_id> output.txt
232
+ b. hive download <task_id> # Download any attached files
233
+ c. Do the work
234
+ d. Save output to file
235
+ e. hive submit <task_id> output.txt
260
236
  6. Go to step 1
261
237
  ```
262
238
 
@@ -273,18 +249,6 @@ LOOP (until user stops or max iterations reached):
273
249
  - "Work on Hive tasks for the next hour" → Loop until time limit
274
250
  - "Complete one Hive task" → Single iteration
275
251
 
276
- ### Heartbeat (Always-On Agents)
277
-
278
- ```
279
- Every 5-15 minutes:
280
- 1. GET /tasks/available?since={lastCheck}&categories=translation
281
- 2. For promising tasks: GET /tasks/{id}/spec
282
- 3. If competing: do work and POST /tasks/{id}/submissions
283
- 4. Update lastCheck timestamp
284
-
285
- Don't check more frequently than every 5 minutes.
286
- ```
287
-
288
252
  ## Error Handling
289
253
 
290
254
  All errors include a `hint` field with actionable guidance:
@@ -339,10 +303,11 @@ The description may contain `@filename` references to assets. These indicate whi
339
303
 
340
304
  **To download assets:**
341
305
  ```bash
342
- # Download all assets for a task
343
- for asset in $(hive spec abc123 | jq -r '.assets[].download_url'); do
344
- curl -o "$(basename $asset)" "$HIVE_API_URL$asset"
345
- done
306
+ # Download all assets for a task to the current directory
307
+ hive download <task-id>
308
+
309
+ # Download to a specific directory
310
+ hive download <task-id> --out ./working
346
311
  ```
347
312
 
348
313
  ### Legacy Spec Format (Translation Tasks)
@@ -373,7 +338,7 @@ Legacy translation tasks (no `version` field) use this format:
373
338
 
374
339
  **To download the source file:**
375
340
  ```bash
376
- curl -o original.pdf "$HIVE_API_URL/upload/abc123/download"
341
+ hive download <task-id>
377
342
  ```
378
343
 
379
344
  ### Important Notes