@howaboua/pi-codex-conversion 1.0.14 → 1.0.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-codex-conversion",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Codex-oriented tool and prompt adapter for pi coding agent",
5
5
  "type": "module",
6
6
  "repository": {
@@ -30,6 +30,12 @@ interface ApplyPatchPartialFailureDetails {
30
30
  result: ExecutePatchResult;
31
31
  error: string;
32
32
  failedTarget?: string;
33
+ appliedFiles: string[];
34
+ failedFiles: string[];
35
+ recoveryInstructions: {
36
+ mustReadFiles: string[];
37
+ mustNotReadFiles: string[];
38
+ };
33
39
  }
34
40
 
35
41
  type ApplyPatchToolDetails = ApplyPatchSuccessDetails | ApplyPatchPartialFailureDetails;
@@ -177,6 +183,25 @@ function summarizePatchCounts(result: ExecutePatchResult): string {
177
183
  ].join(", ");
178
184
  }
179
185
 
186
+ function uniqueStrings(values: Array<string | undefined>): string[] {
187
+ return Array.from(new Set(values.filter((value): value is string => typeof value === "string" && value.length > 0)));
188
+ }
189
+
190
+ function buildPartialFailureMessage(message: string, failedTarget: string | undefined, result: ExecutePatchResult): string {
191
+ const failedFiles = uniqueStrings([failedTarget]);
192
+ const appliedFiles = result.changedFiles.filter((path) => !failedFiles.includes(path));
193
+ const lines = [message];
194
+ if (failedFiles.length > 0) {
195
+ lines.push(`Failed file: ${failedFiles.join(", ")}`);
196
+ lines.push(`Recovery: MUST read ${failedFiles.join(", ")} before retrying.`);
197
+ }
198
+ if (appliedFiles.length > 0) {
199
+ lines.push(`Applied files: ${appliedFiles.join(", ")}`);
200
+ lines.push(`Recovery: MUST NOT reread ${appliedFiles.join(", ")} unless a specific dependency requires it.`);
201
+ }
202
+ return lines.join("\n");
203
+ }
204
+
180
205
  function describeFailedAction(error: ExecutePatchError, cwd: string): string | undefined {
181
206
  if (!error.failedAction) {
182
207
  return undefined;
@@ -253,14 +278,23 @@ export function registerApplyPatchTool(pi: ExtensionAPI): void {
253
278
  : "apply_patch failed";
254
279
  const message = failedTarget ? `${prefix} while patching ${failedTarget}: ${error.message}` : `${prefix}: ${error.message}`;
255
280
  if (partial) {
281
+ const failedFiles = uniqueStrings([failedTarget]);
282
+ const appliedFiles = error.result.changedFiles.filter((path) => !failedFiles.includes(path));
283
+ const recoveryMessage = buildPartialFailureMessage(message, failedTarget, error.result);
256
284
  markApplyPatchPartialFailure(toolCallId, failedTarget);
257
285
  return {
258
- content: [{ type: "text", text: message }],
286
+ content: [{ type: "text", text: recoveryMessage }],
259
287
  details: {
260
288
  status: "partial_failure",
261
289
  result: error.result,
262
- error: message,
290
+ error: recoveryMessage,
263
291
  failedTarget,
292
+ appliedFiles,
293
+ failedFiles,
294
+ recoveryInstructions: {
295
+ mustReadFiles: failedFiles,
296
+ mustNotReadFiles: appliedFiles,
297
+ },
264
298
  } satisfies ApplyPatchPartialFailureDetails,
265
299
  };
266
300
  }