oira666_pi-subagent 0.2.12 → 0.2.14

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/package.json +1 -1
  2. package/runner.ts +18 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oira666_pi-subagent",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "description": "Subagent extension for Pi coding agent. Delegate tasks to specialized agents.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/runner.ts CHANGED
@@ -311,6 +311,15 @@ function hasMessage(result: SingleResult, message: Message): boolean {
311
311
  return result.messages.some((existing) => messageDedupKey(existing) === key);
312
312
  }
313
313
 
314
+ function sessionDirExists(dir: string | undefined): boolean {
315
+ if (!dir) return false;
316
+ try {
317
+ return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
318
+ } catch {
319
+ return false;
320
+ }
321
+ }
322
+
314
323
  export function processJsonLine(line: string, result: SingleResult): boolean {
315
324
  if (!line.trim()) return false;
316
325
 
@@ -536,26 +545,7 @@ export async function runAgentSubprocess(opts: RunAgentOptions): Promise<SingleR
536
545
  };
537
546
  }
538
547
 
539
- if (resumeSession && sessionDir && (!fs.existsSync(sessionDir) || !fs.statSync(sessionDir).isDirectory())) {
540
- const errorMessage = `Cannot resume subagent session: session directory does not exist: ${sessionDir}`;
541
- return {
542
- agent: agentName,
543
- agentSource: agent.source,
544
- task,
545
- exitCode: 1,
546
- messages: initialResult?.messages ? [...initialResult.messages] : [],
547
- stderr: errorMessage,
548
- usage: initialResult?.usage ? { ...initialResult.usage } : emptyUsage(),
549
- toolCalls: initialResult?.toolCalls ? { ...initialResult.toolCalls } : {},
550
- model: initialResult?.model ?? agent.model,
551
- stopReason: "error",
552
- errorMessage,
553
- completedTurns: initialResult?.completedTurns ?? 0,
554
- turnInProgress: false,
555
- liveLog: initialResult?.liveLog ? [...initialResult.liveLog] : [],
556
- sessionDir,
557
- };
558
- }
548
+ const shouldContinueSession = resumeSession && (!sessionDir || sessionDirExists(sessionDir));
559
549
 
560
550
  const result: SingleResult = {
561
551
  agent: agentName,
@@ -603,7 +593,7 @@ export async function runAgentSubprocess(opts: RunAgentOptions): Promise<SingleR
603
593
  promptTmpPath,
604
594
  task,
605
595
  sessionDir,
606
- resumeSession,
596
+ shouldContinueSession,
607
597
  fallbackModel,
608
598
  );
609
599
  let wasAborted = false;
@@ -883,7 +873,6 @@ export async function executeParallelSubprocess(
883
873
  completedTurns: 0,
884
874
  turnInProgress: false,
885
875
  liveLog: [],
886
- sessionDir: getSessionDir?.(index, t),
887
876
  }));
888
877
 
889
878
  const emitProgress = () => {
@@ -918,7 +907,12 @@ export async function executeParallelSubprocess(
918
907
  emitProgress();
919
908
  return previousResult;
920
909
  }
921
- const sessionDir = previousResult?.sessionDir ?? getSessionDir?.(index, t);
910
+ const savedSessionDir = previousResult?.sessionDir;
911
+ const savedSessionDirExists = sessionDirExists(savedSessionDir);
912
+ const shouldResumeThisSession = resumeExistingSessions && (!previousResult || !savedSessionDir || savedSessionDirExists);
913
+ const sessionDir = shouldResumeThisSession && savedSessionDirExists
914
+ ? savedSessionDir
915
+ : getSessionDir?.(index, t);
922
916
  const result = await runAgentSubprocess({
923
917
  cwd: defaultCwd,
924
918
  agents,
@@ -932,7 +926,7 @@ export async function executeParallelSubprocess(
932
926
  signal,
933
927
  sessionDir,
934
928
  sessionRoot,
935
- resumeSession: resumeExistingSessions && !!sessionDir,
929
+ resumeSession: shouldResumeThisSession && !!sessionDir,
936
930
  initialResult: previousResult,
937
931
  fallbackModel,
938
932
  onUpdate: (partial) => {