@artyfacts/claude 1.3.8 → 1.3.9

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/cli.js CHANGED
@@ -990,14 +990,21 @@ async function checkAndClaimTasks(baseUrl, apiKey, agentId, activeTasks, executo
990
990
  priority: task.priority
991
991
  });
992
992
  if (result.success) {
993
- await completeTask({
994
- baseUrl,
995
- apiKey,
996
- taskId: taskUuid,
997
- // Use UUID instead of section_id
998
- output: result.output,
999
- summary: result.summary
1000
- });
993
+ try {
994
+ await completeTask({
995
+ baseUrl,
996
+ apiKey,
997
+ taskId: taskUuid,
998
+ // Use UUID instead of section_id
999
+ output: result.output,
1000
+ summary: result.summary
1001
+ });
1002
+ } catch (err) {
1003
+ const errMsg = err instanceof Error ? err.message : String(err);
1004
+ if (!errMsg.includes("already complete")) {
1005
+ throw err;
1006
+ }
1007
+ }
1001
1008
  console.log(` \u2192 \u2705 Completed! ${result.summary}`);
1002
1009
  } else {
1003
1010
  console.log(` \u2192 \u274C Failed: ${result.error}`);
@@ -1110,13 +1117,20 @@ async function runAgent(options) {
1110
1117
  };
1111
1118
  const result = await executor.execute(taskContext);
1112
1119
  if (result.success) {
1113
- await completeTask({
1114
- baseUrl: options.baseUrl,
1115
- apiKey: credentials.apiKey,
1116
- taskId: task.taskId,
1117
- output: result.output,
1118
- summary: result.summary
1119
- });
1120
+ try {
1121
+ await completeTask({
1122
+ baseUrl: options.baseUrl,
1123
+ apiKey: credentials.apiKey,
1124
+ taskId: task.taskId,
1125
+ output: result.output,
1126
+ summary: result.summary
1127
+ });
1128
+ } catch (err) {
1129
+ const errMsg = err instanceof Error ? err.message : String(err);
1130
+ if (!errMsg.includes("already complete")) {
1131
+ throw err;
1132
+ }
1133
+ }
1120
1134
  console.log(` \u2192 \u2705 Completed! ${result.summary}`);
1121
1135
  } else {
1122
1136
  console.log(` \u2192 \u274C Failed: ${result.error}`);
@@ -1134,8 +1148,15 @@ async function runAgent(options) {
1134
1148
  }
1135
1149
  });
1136
1150
  listener.connect();
1151
+ const POLL_INTERVAL_MS = 3e4;
1152
+ const pollInterval = setInterval(() => {
1153
+ if (!options.dryRun) {
1154
+ checkAndClaimTasks(options.baseUrl, credentials.apiKey, credentials.agentId, activeTasks, executor, options.dryRun);
1155
+ }
1156
+ }, POLL_INTERVAL_MS);
1137
1157
  const shutdown = () => {
1138
1158
  console.log("\n\u{1F44B} Disconnecting...");
1159
+ clearInterval(pollInterval);
1139
1160
  listener.disconnect();
1140
1161
  process.exit(0);
1141
1162
  };
package/dist/cli.mjs CHANGED
@@ -180,14 +180,21 @@ async function checkAndClaimTasks(baseUrl, apiKey, agentId, activeTasks, executo
180
180
  priority: task.priority
181
181
  });
182
182
  if (result.success) {
183
- await completeTask({
184
- baseUrl,
185
- apiKey,
186
- taskId: taskUuid,
187
- // Use UUID instead of section_id
188
- output: result.output,
189
- summary: result.summary
190
- });
183
+ try {
184
+ await completeTask({
185
+ baseUrl,
186
+ apiKey,
187
+ taskId: taskUuid,
188
+ // Use UUID instead of section_id
189
+ output: result.output,
190
+ summary: result.summary
191
+ });
192
+ } catch (err) {
193
+ const errMsg = err instanceof Error ? err.message : String(err);
194
+ if (!errMsg.includes("already complete")) {
195
+ throw err;
196
+ }
197
+ }
191
198
  console.log(` \u2192 \u2705 Completed! ${result.summary}`);
192
199
  } else {
193
200
  console.log(` \u2192 \u274C Failed: ${result.error}`);
@@ -300,13 +307,20 @@ async function runAgent(options) {
300
307
  };
301
308
  const result = await executor.execute(taskContext);
302
309
  if (result.success) {
303
- await completeTask({
304
- baseUrl: options.baseUrl,
305
- apiKey: credentials.apiKey,
306
- taskId: task.taskId,
307
- output: result.output,
308
- summary: result.summary
309
- });
310
+ try {
311
+ await completeTask({
312
+ baseUrl: options.baseUrl,
313
+ apiKey: credentials.apiKey,
314
+ taskId: task.taskId,
315
+ output: result.output,
316
+ summary: result.summary
317
+ });
318
+ } catch (err) {
319
+ const errMsg = err instanceof Error ? err.message : String(err);
320
+ if (!errMsg.includes("already complete")) {
321
+ throw err;
322
+ }
323
+ }
310
324
  console.log(` \u2192 \u2705 Completed! ${result.summary}`);
311
325
  } else {
312
326
  console.log(` \u2192 \u274C Failed: ${result.error}`);
@@ -324,8 +338,15 @@ async function runAgent(options) {
324
338
  }
325
339
  });
326
340
  listener.connect();
341
+ const POLL_INTERVAL_MS = 3e4;
342
+ const pollInterval = setInterval(() => {
343
+ if (!options.dryRun) {
344
+ checkAndClaimTasks(options.baseUrl, credentials.apiKey, credentials.agentId, activeTasks, executor, options.dryRun);
345
+ }
346
+ }, POLL_INTERVAL_MS);
327
347
  const shutdown = () => {
328
348
  console.log("\n\u{1F44B} Disconnecting...");
349
+ clearInterval(pollInterval);
329
350
  listener.disconnect();
330
351
  process.exit(0);
331
352
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artyfacts/claude",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "Claude adapter for Artyfacts - Execute tasks using Claude Code CLI",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/src/cli.ts CHANGED
@@ -305,13 +305,21 @@ async function checkAndClaimTasks(
305
305
  });
306
306
 
307
307
  if (result.success) {
308
- await completeTask({
309
- baseUrl,
310
- apiKey,
311
- taskId: taskUuid, // Use UUID instead of section_id
312
- output: result.output,
313
- summary: result.summary,
314
- });
308
+ try {
309
+ await completeTask({
310
+ baseUrl,
311
+ apiKey,
312
+ taskId: taskUuid, // Use UUID instead of section_id
313
+ output: result.output,
314
+ summary: result.summary,
315
+ });
316
+ } catch (err) {
317
+ // Ignore "already complete" - means Claude completed it via MCP
318
+ const errMsg = err instanceof Error ? err.message : String(err);
319
+ if (!errMsg.includes('already complete')) {
320
+ throw err;
321
+ }
322
+ }
315
323
  console.log(` → ✅ Completed! ${result.summary}`);
316
324
  } else {
317
325
  console.log(` → ❌ Failed: ${result.error}`);
@@ -460,14 +468,22 @@ async function runAgent(options: {
460
468
  const result = await executor!.execute(taskContext);
461
469
 
462
470
  if (result.success) {
463
- // Complete task via API
464
- await completeTask({
465
- baseUrl: options.baseUrl,
466
- apiKey: credentials.apiKey,
467
- taskId: task.taskId,
468
- output: result.output,
469
- summary: result.summary,
470
- });
471
+ // Complete task via API (Claude may have already done this via MCP tool)
472
+ try {
473
+ await completeTask({
474
+ baseUrl: options.baseUrl,
475
+ apiKey: credentials.apiKey,
476
+ taskId: task.taskId,
477
+ output: result.output,
478
+ summary: result.summary,
479
+ });
480
+ } catch (err) {
481
+ // Ignore "already complete" - means Claude completed it via MCP
482
+ const errMsg = err instanceof Error ? err.message : String(err);
483
+ if (!errMsg.includes('already complete')) {
484
+ throw err;
485
+ }
486
+ }
471
487
 
472
488
  console.log(` → ✅ Completed! ${result.summary}`);
473
489
  } else {
@@ -491,9 +507,19 @@ async function runAgent(options: {
491
507
  // Start listening
492
508
  listener.connect();
493
509
 
510
+ // Poll for tasks periodically (every 30 seconds) as a backup to SSE
511
+ // This catches tasks that were created before we connected or if SSE events are missed
512
+ const POLL_INTERVAL_MS = 30_000;
513
+ const pollInterval = setInterval(() => {
514
+ if (!options.dryRun) {
515
+ checkAndClaimTasks(options.baseUrl, credentials.apiKey, credentials.agentId, activeTasks, executor!, options.dryRun);
516
+ }
517
+ }, POLL_INTERVAL_MS);
518
+
494
519
  // Handle shutdown
495
520
  const shutdown = () => {
496
521
  console.log('\n👋 Disconnecting...');
522
+ clearInterval(pollInterval);
497
523
  listener.disconnect();
498
524
  process.exit(0);
499
525
  };