pi-prompt-template-model 0.6.7 → 0.6.8
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/CHANGELOG.md +5 -0
- package/index.ts +51 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.8] - 2026-03-28
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Delegated prompt results are now injected back into the parent conversation as a user message, triggering an agent turn so the parent agent can process and respond to the delegation outcome. Applies to single delegated runs, delegated loops, and delegated chain steps.
|
|
7
|
+
|
|
3
8
|
## [0.6.7] - 2026-03-28
|
|
4
9
|
|
|
5
10
|
### Changed
|
package/index.ts
CHANGED
|
@@ -45,6 +45,7 @@ interface ExecutionErrorState {
|
|
|
45
45
|
|
|
46
46
|
interface PromptStepResult {
|
|
47
47
|
changed: boolean;
|
|
48
|
+
text?: string;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export default function promptModelExtension(pi: ExtensionAPI) {
|
|
@@ -218,7 +219,7 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
218
219
|
notify(ctx, `Prompt \`${prompt.name}\` is not configured for delegated execution.`, "error");
|
|
219
220
|
return "aborted";
|
|
220
221
|
}
|
|
221
|
-
return { changed: delegated.changed };
|
|
222
|
+
return { changed: delegated.changed, text: delegated.text };
|
|
222
223
|
} catch (error) {
|
|
223
224
|
notify(ctx, error instanceof Error ? error.message : String(error), "error");
|
|
224
225
|
return { changed: false };
|
|
@@ -421,6 +422,8 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
421
422
|
let completedIterations = 0;
|
|
422
423
|
let converged = false;
|
|
423
424
|
let loopErrorState: ExecutionErrorState = { hasError: false, error: undefined };
|
|
425
|
+
let lastDelegatedText: string | undefined;
|
|
426
|
+
let loopAborted = false;
|
|
424
427
|
|
|
425
428
|
try {
|
|
426
429
|
for (let i = 0; i < effectiveMax; i++) {
|
|
@@ -431,6 +434,7 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
431
434
|
const prompt = prompts.get(name);
|
|
432
435
|
if (!prompt) {
|
|
433
436
|
notify(ctx, `Prompt "${name}" no longer exists`, "error");
|
|
437
|
+
loopAborted = true;
|
|
434
438
|
break;
|
|
435
439
|
}
|
|
436
440
|
const effectivePrompt = { ...prompt, ...(cwdOverride ? { cwd: cwdOverride } : {}), ...promptOverrides };
|
|
@@ -468,13 +472,20 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
468
472
|
undefined,
|
|
469
473
|
loopContext,
|
|
470
474
|
);
|
|
471
|
-
if (stepResult === "aborted")
|
|
475
|
+
if (stepResult === "aborted") {
|
|
476
|
+
loopAborted = true;
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
const delegatedStep = shouldDelegatePrompt(iterationPrompt, subagentOverride);
|
|
480
|
+
if (delegatedStep) {
|
|
481
|
+
lastDelegatedText = stepResult.text;
|
|
482
|
+
}
|
|
472
483
|
|
|
473
484
|
currentModel = getCurrentModel(ctx);
|
|
474
485
|
currentThinking = pi.getThinkingLevel();
|
|
475
486
|
completedIterations++;
|
|
476
487
|
|
|
477
|
-
const iterationChanged =
|
|
488
|
+
const iterationChanged = delegatedStep
|
|
478
489
|
? stepResult.changed
|
|
479
490
|
: didIterationMakeChanges(getIterationEntries(ctx, iterationStartId));
|
|
480
491
|
if (useConverge && (isUnlimited || effectiveMax > 1) && !iterationChanged) {
|
|
@@ -487,6 +498,7 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
487
498
|
const result = await ctx.navigateTree(anchorId, { summarize: true });
|
|
488
499
|
freshCollapse = null;
|
|
489
500
|
if (result.cancelled) {
|
|
501
|
+
loopAborted = true;
|
|
490
502
|
notify(ctx, "Loop cancelled", "warning");
|
|
491
503
|
break;
|
|
492
504
|
}
|
|
@@ -517,6 +529,15 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
517
529
|
}
|
|
518
530
|
}
|
|
519
531
|
|
|
532
|
+
if (lastDelegatedText && !loopErrorState.hasError && !loopAborted) {
|
|
533
|
+
const label = converged
|
|
534
|
+
? `Delegated loop converged after ${completedIterations} iteration(s): ${name}`
|
|
535
|
+
: `Delegated loop completed ${completedIterations} iteration(s): ${name}`;
|
|
536
|
+
pi.sendUserMessage(`[${label}]\n\n${lastDelegatedText}`);
|
|
537
|
+
await waitForTurnStart(ctx);
|
|
538
|
+
await ctx.waitForIdle();
|
|
539
|
+
}
|
|
540
|
+
|
|
520
541
|
if (loopErrorState.hasError) {
|
|
521
542
|
throw loopErrorState.error;
|
|
522
543
|
}
|
|
@@ -610,6 +631,8 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
610
631
|
let completedIterations = 0;
|
|
611
632
|
let converged = false;
|
|
612
633
|
let chainErrorState: ExecutionErrorState = { hasError: false, error: undefined };
|
|
634
|
+
let lastDelegatedText: string | undefined;
|
|
635
|
+
let chainAborted = false;
|
|
613
636
|
if (effectiveMax > 1) {
|
|
614
637
|
loopState = { currentIteration: 1, totalIterations };
|
|
615
638
|
accumulatedSummaries = [];
|
|
@@ -622,7 +645,10 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
622
645
|
loopState!.currentIteration = iteration + 1;
|
|
623
646
|
updateLoopStatus(ctx);
|
|
624
647
|
refreshPrompts(ctx.cwd, ctx);
|
|
625
|
-
if (!validateChainSteps())
|
|
648
|
+
if (!validateChainSteps()) {
|
|
649
|
+
chainAborted = true;
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
626
652
|
}
|
|
627
653
|
|
|
628
654
|
const templates = steps.map((step) =>
|
|
@@ -700,6 +726,7 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
700
726
|
aborted = true;
|
|
701
727
|
break;
|
|
702
728
|
}
|
|
729
|
+
lastDelegatedText = delegated.text;
|
|
703
730
|
|
|
704
731
|
currentModel = getCurrentModel(ctx);
|
|
705
732
|
currentThinking = pi.getThinkingLevel();
|
|
@@ -764,9 +791,13 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
764
791
|
stepLoopContext,
|
|
765
792
|
);
|
|
766
793
|
if (stepResult === "aborted") {
|
|
794
|
+
chainAborted = true;
|
|
767
795
|
aborted = true;
|
|
768
796
|
break;
|
|
769
797
|
}
|
|
798
|
+
if (shouldDelegatePrompt(singleStep.prompt, subagentOverride)) {
|
|
799
|
+
lastDelegatedText = stepResult.text;
|
|
800
|
+
}
|
|
770
801
|
|
|
771
802
|
currentModel = getCurrentModel(ctx);
|
|
772
803
|
currentThinking = pi.getThinkingLevel();
|
|
@@ -790,7 +821,10 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
790
821
|
chainStepSummaries.push(generateChainStepSummary(stepEntries, singleStep.prompt.name, stepNumber));
|
|
791
822
|
}
|
|
792
823
|
|
|
793
|
-
if (aborted)
|
|
824
|
+
if (aborted) {
|
|
825
|
+
chainAborted = true;
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
794
828
|
completedIterations++;
|
|
795
829
|
|
|
796
830
|
if (useConverge && (isUnlimited || effectiveMax > 1) && !iterationChanged) {
|
|
@@ -803,6 +837,7 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
803
837
|
const result = await ctx.navigateTree(anchorId, { summarize: true });
|
|
804
838
|
freshCollapse = null;
|
|
805
839
|
if (result.cancelled) {
|
|
840
|
+
chainAborted = true;
|
|
806
841
|
notify(ctx, "Loop cancelled", "warning");
|
|
807
842
|
break;
|
|
808
843
|
}
|
|
@@ -838,6 +873,12 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
838
873
|
}
|
|
839
874
|
}
|
|
840
875
|
|
|
876
|
+
if (lastDelegatedText && !chainErrorState.hasError && !chainAborted) {
|
|
877
|
+
pi.sendUserMessage(`[Delegated chain complete: ${chainStepNames}]\n\n${lastDelegatedText}`);
|
|
878
|
+
await waitForTurnStart(ctx);
|
|
879
|
+
await ctx.waitForIdle();
|
|
880
|
+
}
|
|
881
|
+
|
|
841
882
|
if (chainErrorState.hasError) {
|
|
842
883
|
throw chainErrorState.error;
|
|
843
884
|
}
|
|
@@ -937,6 +978,11 @@ export default function promptModelExtension(pi: ExtensionAPI) {
|
|
|
937
978
|
subagent.override,
|
|
938
979
|
);
|
|
939
980
|
if (stepResult === "aborted") return;
|
|
981
|
+
if (shouldDelegatePrompt(effectivePrompt, subagent.override) && stepResult.text) {
|
|
982
|
+
pi.sendUserMessage(`[Delegated result: ${name}]\n\n${stepResult.text}`);
|
|
983
|
+
await waitForTurnStart(ctx);
|
|
984
|
+
await ctx.waitForIdle();
|
|
985
|
+
}
|
|
940
986
|
|
|
941
987
|
if (!shouldDelegatePrompt(effectivePrompt, subagent.override) && prompt.restore) {
|
|
942
988
|
const currentModel = getCurrentModel(ctx);
|