@sandagent/runner-cli 0.2.18 → 0.2.20

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.
Files changed (2) hide show
  1. package/dist/bundle.mjs +47 -13
  2. package/package.json +2 -2
package/dist/bundle.mjs CHANGED
@@ -227,6 +227,8 @@ var AISDKStreamConverter = class {
227
227
  systemMessage;
228
228
  hasEmittedStart = false;
229
229
  sessionId;
230
+ /** True after we emitted an error from a result message (e.g. API 400). Avoids emitting a second generic "exited with code 1" that would hide the real error. */
231
+ errorEmitted = false;
230
232
  partIdMap = /* @__PURE__ */ new Map();
231
233
  /**
232
234
  * Get the current session ID from the stream
@@ -368,6 +370,7 @@ var AISDKStreamConverter = class {
368
370
  if (message.type === "result") {
369
371
  const resultMsg = message;
370
372
  if (resultMsg.is_error) {
373
+ this.errorEmitted = true;
371
374
  const errorText = resultMsg.result || "Unknown error";
372
375
  yield this.emit({
373
376
  type: "error",
@@ -385,21 +388,53 @@ var AISDKStreamConverter = class {
385
388
  }
386
389
  }
387
390
  } catch (error) {
388
- trace({ error: String(error) });
391
+ if (process.env.DEBUG === "true") {
392
+ const errPayload = {
393
+ error: error instanceof Error ? error.message : String(error)
394
+ };
395
+ if (error instanceof Error) {
396
+ if (error.stack)
397
+ errPayload.stack = error.stack;
398
+ if (error.cause !== void 0) {
399
+ errPayload.cause = error.cause instanceof Error ? {
400
+ message: error.cause.message,
401
+ stack: error.cause.stack
402
+ } : String(error.cause);
403
+ }
404
+ }
405
+ trace(errPayload);
406
+ } else {
407
+ trace({ error: String(error) });
408
+ }
389
409
  if (isAbortError(error)) {
390
410
  console.error("[AISDKStream] Operation aborted");
391
411
  } else {
392
412
  const errorMessage = error instanceof Error ? error.message : "Unknown error";
393
413
  console.error("[AISDKStream] Error:", errorMessage);
394
- yield this.emit({ type: "error", errorText: errorMessage });
395
- yield this.emit({
396
- type: "finish",
397
- finishReason: mapFinishReason("error_during_execution", true),
398
- messageMetadata: {
399
- usage: convertUsageToAISDK({}),
400
- sessionId: this.sessionId
414
+ if (process.env.DEBUG === "true") {
415
+ if (error instanceof Error && error.stack) {
416
+ console.error("[AISDKStream] Stack:", error.stack);
417
+ }
418
+ if (error instanceof Error && error.cause) {
419
+ console.error("[AISDKStream] Cause:", error.cause);
401
420
  }
402
- });
421
+ }
422
+ if ((errorMessage.includes("exited with code") || errorMessage.includes("process exited")) && this.errorEmitted) {
423
+ console.error("[AISDKStream] (Skipping duplicate error \u2014 already sent API/result error above. Check the first error in the stream.)");
424
+ } else if (errorMessage.includes("exited with code") || errorMessage.includes("process exited")) {
425
+ console.error("[AISDKStream] Hint: Verify ANTHROPIC_API_KEY, --model (proxy must support it), and network.");
426
+ }
427
+ if (!this.errorEmitted) {
428
+ yield this.emit({ type: "error", errorText: errorMessage });
429
+ yield this.emit({
430
+ type: "finish",
431
+ finishReason: mapFinishReason("error_during_execution", true),
432
+ messageMetadata: {
433
+ usage: convertUsageToAISDK({}),
434
+ sessionId: this.sessionId
435
+ }
436
+ });
437
+ }
403
438
  }
404
439
  } finally {
405
440
  yield `data: [DONE]
@@ -544,6 +579,7 @@ async function* runWithClaudeAgentSDK(sdk, options, userInput) {
544
579
  }
545
580
  }
546
581
  function createSDKOptions(options) {
582
+ const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
547
583
  return {
548
584
  model: options.model,
549
585
  systemPrompt: options.systemPrompt,
@@ -559,10 +595,8 @@ function createSDKOptions(options) {
559
595
  resume: options.resume,
560
596
  settingSources: ["project", "user"],
561
597
  canUseTool: createCanUseToolCallback(options),
562
- // Bypass all permission checks for automated execution
563
- permissionMode: "bypassPermissions",
564
- allowDangerouslySkipPermissions: true,
565
- // Enable partial messages for streaming
598
+ permissionMode: isRoot ? "default" : "bypassPermissions",
599
+ allowDangerouslySkipPermissions: !isRoot,
566
600
  includePartialMessages: options.includePartialMessages
567
601
  };
568
602
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandagent/runner-cli",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "SandAgent Runner CLI - Like gemini-cli or claude-code, runs in your local terminal with AI SDK UI streaming",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,7 +41,7 @@
41
41
  "anthropic"
42
42
  ],
43
43
  "dependencies": {
44
- "@anthropic-ai/claude-agent-sdk": ">=0.1.70"
44
+ "@anthropic-ai/claude-agent-sdk": "0.2.69"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^20.10.0",