pi-subagentura 1.0.9 → 1.0.12

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/helpers.ts +79 -2
  2. package/package.json +1 -1
package/helpers.ts CHANGED
@@ -433,6 +433,11 @@ export async function startSubagentJob(
433
433
  }
434
434
 
435
435
  // Create session
436
+ debugLog("info", "session_creating", {
437
+ jobId,
438
+ model: modelLabel ?? "default",
439
+ cwd,
440
+ });
436
441
  const session = (
437
442
  await createAgentSession({
438
443
  sessionManager: SessionManager.inMemory(),
@@ -442,10 +447,15 @@ export async function startSubagentJob(
442
447
  cwd,
443
448
  })
444
449
  ).session;
450
+ debugLog("info", "session_created", {
451
+ jobId,
452
+ sessionModel: session.model ? `${session.model.provider}/${session.model.id}` : null,
453
+ });
445
454
 
446
455
  // Wire abort signal
447
456
  if (signal) {
448
457
  handleAbort = () => {
458
+ debugLog("warn", "job_abort", { jobId });
449
459
  session.abort().catch(() => {});
450
460
  };
451
461
  if (signal.aborted) {
@@ -462,10 +472,16 @@ export async function startSubagentJob(
462
472
  liveStatus.turn++;
463
473
  liveStatus.usage.turns = liveStatus.turn;
464
474
  liveStatus.output = "";
475
+ debugLog("info", "turn_start", { jobId, turn: liveStatus.turn });
465
476
  onUpdate?.(buildLiveUpdate(liveStatus, modelLabel));
466
477
  break;
467
478
  }
468
479
  case "tool_execution_start": {
480
+ debugLog("info", "tool_start", {
481
+ jobId,
482
+ toolName: event.toolName,
483
+ args: event.args as Record<string, unknown>,
484
+ });
469
485
  setActiveToolDebounced({
470
486
  name: event.toolName,
471
487
  args: event.args as Record<string, unknown>,
@@ -473,10 +489,17 @@ export async function startSubagentJob(
473
489
  break;
474
490
  }
475
491
  case "tool_execution_end": {
492
+ debugLog("info", "tool_end", { jobId, toolName: liveStatus.activeTool?.name });
476
493
  setActiveToolDebounced(undefined);
477
494
  break;
478
495
  }
479
496
  case "turn_end": {
497
+ debugLog("info", "turn_end", {
498
+ jobId,
499
+ turn: liveStatus.turn,
500
+ outputLength: liveStatus.output.length,
501
+ activeTool: liveStatus.activeTool?.name ?? null,
502
+ });
480
503
  if (activeToolTimer) {
481
504
  clearTimeout(activeToolTimer);
482
505
  activeToolTimer = undefined;
@@ -486,8 +509,20 @@ export async function startSubagentJob(
486
509
  break;
487
510
  }
488
511
  case "message_update": {
489
- if (event.assistantMessageEvent.type === "text_delta") {
490
- liveStatus.output += event.assistantMessageEvent.delta;
512
+ const evt = event.assistantMessageEvent;
513
+ debugLog("info", "message_update", {
514
+ jobId,
515
+ updateType: evt.type,
516
+ ...(evt.type === "text_delta" && {
517
+ delta: evt.delta.slice(0, 200),
518
+ outputLength: liveStatus.output.length,
519
+ }),
520
+ ...(evt.type === "thinking_delta" && { delta: evt.delta.slice(0, 200) }),
521
+ ...(evt.type === "toolcall_delta" && { partial: String(evt.partial).slice(0, 200) }),
522
+ ...(evt.type === "toolcall_end" && { toolCallId: evt.toolCall?.id }),
523
+ });
524
+ if (evt.type === "text_delta") {
525
+ liveStatus.output += evt.delta;
491
526
  onUpdate?.(buildLiveUpdate(liveStatus, modelLabel));
492
527
  }
493
528
  break;
@@ -501,18 +536,44 @@ export async function startSubagentJob(
501
536
  ? `${personaPrefix}You are a SEPARATE background sub-agent. Your ONLY job is the task below.\nThe conversation history above is CONTEXT ONLY — do NOT comment on it, do NOT role-play as the main assistant, do NOT describe the spawning process. Execute ONLY the task and return ONLY the result.\n\n## Conversation History (context only — do not respond to this)\n${contextText}\n\n## Your Task (respond ONLY to this)\n${task}`
502
537
  : `${personaPrefix}Task: ${task}`;
503
538
 
539
+ debugLog("info", "prompt_built", {
540
+ jobId,
541
+ hasContext: !!contextText,
542
+ contextLength: contextText?.length ?? 0,
543
+ taskLength: task.length,
544
+ persona: persona ?? null,
545
+ promptPreview: finalPrompt.slice(0, 500),
546
+ });
547
+
504
548
  // Launch the prompt in a promise chain (NOT awaited — returns immediately).
505
549
  // The jobPromise represents the full lifecycle: prompt → extraction → cleanup.
506
550
  const jobPromise = (async (): Promise<SubagentResult> => {
507
551
  let result: SubagentResult;
508
552
  try {
553
+ debugLog("info", "prompt_start", { jobId });
509
554
  await session.prompt(finalPrompt);
555
+ debugLog("info", "prompt_complete", { jobId });
510
556
 
511
557
  // Extract final assistant output
512
558
  const messages = session.agent.state.messages;
559
+ debugLog("info", "messages_extracted", {
560
+ jobId,
561
+ messageCount: messages.length,
562
+ messageRoles: messages.map((m) => m.role),
563
+ lastMessageContentType: typeof (messages[messages.length - 1] as any)?.content,
564
+ lastMessageContentIsArray: Array.isArray((messages[messages.length - 1] as any)?.content),
565
+ });
566
+
513
567
  let finalOutput = liveStatus.output;
514
568
  for (let i = messages.length - 1; i >= 0; i--) {
515
569
  const msg = messages[i];
570
+ debugLog("info", "message_check", {
571
+ jobId,
572
+ index: i,
573
+ role: msg.role,
574
+ contentType: typeof (msg as any).content,
575
+ contentIsArray: Array.isArray((msg as any).content),
576
+ });
516
577
  if (msg.role === "assistant") {
517
578
  const textParts = extractTextFromContent(msg.content);
518
579
  if (textParts) {
@@ -552,6 +613,13 @@ export async function startSubagentJob(
552
613
  };
553
614
  } catch (err) {
554
615
  const msg = err instanceof Error ? err.message : String(err);
616
+ const stack = err instanceof Error ? err.stack : undefined;
617
+ debugLog("error", "subagent_error", {
618
+ jobId,
619
+ error: msg,
620
+ stack: stack ?? null,
621
+ errorName: err instanceof Error ? err.name : typeof err,
622
+ });
555
623
  result = {
556
624
  output: `Sub-agent crashed: ${msg}`,
557
625
  usage: {
@@ -567,6 +635,14 @@ export async function startSubagentJob(
567
635
  errorMessage: msg,
568
636
  };
569
637
  } finally {
638
+ debugLog("info", "job_complete", {
639
+ jobId,
640
+ outputLength: result.output.length,
641
+ output: result.output.slice(0, 200),
642
+ isError: result.isError,
643
+ errorMessage: result.errorMessage ?? null,
644
+ usage: result.usage,
645
+ });
570
646
  if (activeToolTimer) {
571
647
  clearTimeout(activeToolTimer);
572
648
  activeToolTimer = undefined;
@@ -575,6 +651,7 @@ export async function startSubagentJob(
575
651
  signal.removeEventListener("abort", handleAbort);
576
652
  if (unsubscribe) unsubscribe();
577
653
  session?.dispose();
654
+ debugLog("info", "session_disposed", { jobId });
578
655
  }
579
656
  return result;
580
657
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-subagentura",
3
- "version": "1.0.9",
3
+ "version": "1.0.12",
4
4
  "description": "Public Pi package that adds in-process sub-agents via the SDK",
5
5
  "main": "subagent.ts",
6
6
  "type": "module",