pi-subagentura 1.0.11 → 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 +65 -4
  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) {
@@ -484,7 +494,12 @@ export async function startSubagentJob(
484
494
  break;
485
495
  }
486
496
  case "turn_end": {
487
- debugLog("info", "turn_end", { jobId, turn: liveStatus.turn });
497
+ debugLog("info", "turn_end", {
498
+ jobId,
499
+ turn: liveStatus.turn,
500
+ outputLength: liveStatus.output.length,
501
+ activeTool: liveStatus.activeTool?.name ?? null,
502
+ });
488
503
  if (activeToolTimer) {
489
504
  clearTimeout(activeToolTimer);
490
505
  activeToolTimer = undefined;
@@ -494,8 +509,20 @@ export async function startSubagentJob(
494
509
  break;
495
510
  }
496
511
  case "message_update": {
497
- if (event.assistantMessageEvent.type === "text_delta") {
498
- 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;
499
526
  onUpdate?.(buildLiveUpdate(liveStatus, modelLabel));
500
527
  }
501
528
  break;
@@ -509,18 +536,44 @@ export async function startSubagentJob(
509
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}`
510
537
  : `${personaPrefix}Task: ${task}`;
511
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
+
512
548
  // Launch the prompt in a promise chain (NOT awaited — returns immediately).
513
549
  // The jobPromise represents the full lifecycle: prompt → extraction → cleanup.
514
550
  const jobPromise = (async (): Promise<SubagentResult> => {
515
551
  let result: SubagentResult;
516
552
  try {
553
+ debugLog("info", "prompt_start", { jobId });
517
554
  await session.prompt(finalPrompt);
555
+ debugLog("info", "prompt_complete", { jobId });
518
556
 
519
557
  // Extract final assistant output
520
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
+
521
567
  let finalOutput = liveStatus.output;
522
568
  for (let i = messages.length - 1; i >= 0; i--) {
523
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
+ });
524
577
  if (msg.role === "assistant") {
525
578
  const textParts = extractTextFromContent(msg.content);
526
579
  if (textParts) {
@@ -560,7 +613,13 @@ export async function startSubagentJob(
560
613
  };
561
614
  } catch (err) {
562
615
  const msg = err instanceof Error ? err.message : String(err);
563
- debugLog("error", "subagent_error", { jobId, error: msg });
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
+ });
564
623
  result = {
565
624
  output: `Sub-agent crashed: ${msg}`,
566
625
  usage: {
@@ -579,6 +638,7 @@ export async function startSubagentJob(
579
638
  debugLog("info", "job_complete", {
580
639
  jobId,
581
640
  outputLength: result.output.length,
641
+ output: result.output.slice(0, 200),
582
642
  isError: result.isError,
583
643
  errorMessage: result.errorMessage ?? null,
584
644
  usage: result.usage,
@@ -591,6 +651,7 @@ export async function startSubagentJob(
591
651
  signal.removeEventListener("abort", handleAbort);
592
652
  if (unsubscribe) unsubscribe();
593
653
  session?.dispose();
654
+ debugLog("info", "session_disposed", { jobId });
594
655
  }
595
656
  return result;
596
657
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-subagentura",
3
- "version": "1.0.11",
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",