oira666_pi-subagent 0.2.12 → 0.2.13
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/package.json +1 -1
- package/runner.ts +45 -23
package/package.json
CHANGED
package/runner.ts
CHANGED
|
@@ -311,6 +311,20 @@ function hasMessage(result: SingleResult, message: Message): boolean {
|
|
|
311
311
|
return result.messages.some((existing) => messageDedupKey(existing) === key);
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
+
function resultHasStarted(result: SingleResult | undefined): boolean {
|
|
315
|
+
if (!result) return false;
|
|
316
|
+
return result.messages.length > 0 || result.completedTurns > 0 || result.liveLog.length > 0 || Object.keys(result.toolCalls).length > 0;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function sessionDirExists(dir: string | undefined): boolean {
|
|
320
|
+
if (!dir) return false;
|
|
321
|
+
try {
|
|
322
|
+
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
|
|
323
|
+
} catch {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
314
328
|
export function processJsonLine(line: string, result: SingleResult): boolean {
|
|
315
329
|
if (!line.trim()) return false;
|
|
316
330
|
|
|
@@ -536,25 +550,29 @@ export async function runAgentSubprocess(opts: RunAgentOptions): Promise<SingleR
|
|
|
536
550
|
};
|
|
537
551
|
}
|
|
538
552
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
553
|
+
let shouldContinueSession = resumeSession;
|
|
554
|
+
if (resumeSession && sessionDir && !sessionDirExists(sessionDir)) {
|
|
555
|
+
if (resultHasStarted(initialResult)) {
|
|
556
|
+
const errorMessage = `Cannot resume subagent session: session directory does not exist: ${sessionDir}`;
|
|
557
|
+
return {
|
|
558
|
+
agent: agentName,
|
|
559
|
+
agentSource: agent.source,
|
|
560
|
+
task,
|
|
561
|
+
exitCode: 1,
|
|
562
|
+
messages: initialResult?.messages ? [...initialResult.messages] : [],
|
|
563
|
+
stderr: errorMessage,
|
|
564
|
+
usage: initialResult?.usage ? { ...initialResult.usage } : emptyUsage(),
|
|
565
|
+
toolCalls: initialResult?.toolCalls ? { ...initialResult.toolCalls } : {},
|
|
566
|
+
model: initialResult?.model ?? agent.model,
|
|
567
|
+
stopReason: "error",
|
|
568
|
+
errorMessage,
|
|
569
|
+
completedTurns: initialResult?.completedTurns ?? 0,
|
|
570
|
+
turnInProgress: false,
|
|
571
|
+
liveLog: initialResult?.liveLog ? [...initialResult.liveLog] : [],
|
|
572
|
+
sessionDir,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
shouldContinueSession = false;
|
|
558
576
|
}
|
|
559
577
|
|
|
560
578
|
const result: SingleResult = {
|
|
@@ -603,7 +621,7 @@ export async function runAgentSubprocess(opts: RunAgentOptions): Promise<SingleR
|
|
|
603
621
|
promptTmpPath,
|
|
604
622
|
task,
|
|
605
623
|
sessionDir,
|
|
606
|
-
|
|
624
|
+
shouldContinueSession,
|
|
607
625
|
fallbackModel,
|
|
608
626
|
);
|
|
609
627
|
let wasAborted = false;
|
|
@@ -883,7 +901,6 @@ export async function executeParallelSubprocess(
|
|
|
883
901
|
completedTurns: 0,
|
|
884
902
|
turnInProgress: false,
|
|
885
903
|
liveLog: [],
|
|
886
|
-
sessionDir: getSessionDir?.(index, t),
|
|
887
904
|
}));
|
|
888
905
|
|
|
889
906
|
const emitProgress = () => {
|
|
@@ -918,7 +935,12 @@ export async function executeParallelSubprocess(
|
|
|
918
935
|
emitProgress();
|
|
919
936
|
return previousResult;
|
|
920
937
|
}
|
|
921
|
-
const
|
|
938
|
+
const savedSessionDir = previousResult?.sessionDir;
|
|
939
|
+
const savedSessionDirExists = sessionDirExists(savedSessionDir);
|
|
940
|
+
const shouldResumeThisSession = resumeExistingSessions && (!previousResult || !savedSessionDir || savedSessionDirExists);
|
|
941
|
+
const sessionDir = shouldResumeThisSession && savedSessionDirExists
|
|
942
|
+
? savedSessionDir
|
|
943
|
+
: getSessionDir?.(index, t);
|
|
922
944
|
const result = await runAgentSubprocess({
|
|
923
945
|
cwd: defaultCwd,
|
|
924
946
|
agents,
|
|
@@ -932,7 +954,7 @@ export async function executeParallelSubprocess(
|
|
|
932
954
|
signal,
|
|
933
955
|
sessionDir,
|
|
934
956
|
sessionRoot,
|
|
935
|
-
resumeSession:
|
|
957
|
+
resumeSession: shouldResumeThisSession && !!sessionDir,
|
|
936
958
|
initialResult: previousResult,
|
|
937
959
|
fallbackModel,
|
|
938
960
|
onUpdate: (partial) => {
|