oira666_pi-subagent 0.2.17 → 0.2.18

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/resume.ts +59 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oira666_pi-subagent",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Subagent extension for Pi coding agent. Delegate tasks to specialized agents.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/resume.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as path from "node:path";
2
2
  import type { ExtensionContext } from "@mariozechner/pi-coding-agent";
3
- import { parseBoolean } from "./shared.js";
3
+ import { parseBoolean, RESUME_PROVIDER } from "./shared.js";
4
4
  import { isResultError, isSubagentDetails, type SingleResult, type SubagentDetails } from "./types.js";
5
5
 
6
6
  export const SUBAGENT_RESUME_PROMPT_ENV = "PI_SUBAGENT_RESUME_PROMPT";
@@ -82,11 +82,17 @@ function hasUnfinishedResults(details: SubagentDetails | undefined, expectedTask
82
82
  return details.results.slice(0, expectedTaskCount).some((result) => result.exitCode === -1 || isResultError(result));
83
83
  }
84
84
 
85
- function messageHasNonEmptyText(message: any): boolean {
85
+ function getMessageText(message: any): string {
86
86
  const content = message?.content;
87
- if (typeof content === "string") return content.trim().length > 0;
88
- if (!Array.isArray(content)) return false;
89
- return content.some((part) => part?.type === "text" && typeof part.text === "string" && part.text.trim().length > 0);
87
+ if (typeof content === "string") return content;
88
+ if (!Array.isArray(content)) return "";
89
+ return content
90
+ .map((part) => (part?.type === "text" && typeof part.text === "string" ? part.text : ""))
91
+ .join("");
92
+ }
93
+
94
+ function messageHasNonEmptyText(message: any): boolean {
95
+ return getMessageText(message).trim().length > 0;
90
96
  }
91
97
 
92
98
  function messageHasToolCall(message: any): boolean {
@@ -114,9 +120,55 @@ function isIgnorableTrailingAbortMessage(entry: any): boolean {
114
120
  return false;
115
121
  }
116
122
 
123
+ function isResumePromptEntry(entry: any): boolean {
124
+ if (entry?.type !== "message") return false;
125
+ const message = entry.message;
126
+ if (message?.role !== "user") return false;
127
+ return /^Resuming \d+ subagents\.\.\.$/.test(getMessageText(message).trim());
128
+ }
129
+
130
+ function isSyntheticResumeModelChange(entry: any): boolean {
131
+ return entry?.type === "model_change" && entry.provider === RESUME_PROVIDER;
132
+ }
133
+
134
+ function isFailedResumeAttemptTail(entries: SessionEntry[], start: number): boolean {
135
+ if (start >= entries.length) return true;
136
+
137
+ let sawSyntheticModel = false;
138
+ let sawResumePrompt = false;
139
+ let sawFailure = false;
140
+
141
+ for (let i = start; i < entries.length; i++) {
142
+ const entry: any = entries[i];
143
+
144
+ if (isSyntheticResumeModelChange(entry)) {
145
+ sawSyntheticModel = true;
146
+ continue;
147
+ }
148
+
149
+ if (entry?.type === "thinking_level_change") continue;
150
+
151
+ if (isResumePromptEntry(entry)) {
152
+ if (!sawSyntheticModel) return false;
153
+ sawResumePrompt = true;
154
+ continue;
155
+ }
156
+
157
+ if (isIgnorableTrailingAbortMessage(entry)) {
158
+ if (entry?.type === "message" && sawResumePrompt) sawFailure = true;
159
+ continue;
160
+ }
161
+
162
+ return false;
163
+ }
164
+
165
+ return sawSyntheticModel && sawResumePrompt && sawFailure;
166
+ }
167
+
117
168
  function hasOnlyIgnorableTrailingEntries(entries: SessionEntry[], activityOrder: number): boolean {
118
- for (let i = activityOrder + 1; i < entries.length; i++) {
119
- if (!isIgnorableTrailingAbortMessage(entries[i])) return false;
169
+ const start = activityOrder + 1;
170
+ for (let i = start; i < entries.length; i++) {
171
+ if (!isIgnorableTrailingAbortMessage(entries[i])) return isFailedResumeAttemptTail(entries, start);
120
172
  }
121
173
  return true;
122
174
  }