@narumitw/pi-retry 0.1.1

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/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # pi-retry
2
+
3
+ A public [pi](https://pi.dev) extension package that treats provider responses containing `Unknown error (no error details in response)` as retryable.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@narumitw/pi-retry
9
+ ```
10
+
11
+ Try without installing:
12
+
13
+ ```bash
14
+ pi -e npm:@narumitw/pi-retry
15
+ ```
16
+
17
+ Try this working tree locally:
18
+
19
+ ```bash
20
+ pi -e .
21
+ ```
22
+
23
+ ## What it does
24
+
25
+ When an assistant message ends with `stopReason: "error"` and the error message matches `Unknown error (no error details in response)`, the extension appends pi's retryable-provider-error hint so pi's built-in retry path can continue the turn.
package/biome.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "formatter": {
3
+ "indentStyle": "space",
4
+ "indentWidth": 2
5
+ }
6
+ }
@@ -0,0 +1,53 @@
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+
3
+ const UNKNOWN_NO_DETAILS_RE = /Unknown error \(no error details in response\)/i;
4
+ const RETRYABLE_HINT = "provider returned error";
5
+ const EXTENSION_TAG = "[unknown-error-retry]";
6
+
7
+ export default function unknownErrorRetry(pi: ExtensionAPI) {
8
+ pi.on("session_start", (_event, ctx) => {
9
+ ctx.ui.setStatus("unknown-error-retry", "unknown-error retry: on");
10
+ });
11
+
12
+ pi.on("session_shutdown", (_event, ctx) => {
13
+ ctx.ui.setStatus("unknown-error-retry", undefined);
14
+ });
15
+
16
+ pi.on("message_end", (event, ctx) => {
17
+ const message = event.message as unknown as {
18
+ role?: string;
19
+ stopReason?: string;
20
+ errorMessage?: unknown;
21
+ [key: string]: unknown;
22
+ };
23
+
24
+ if (message.role !== "assistant") return;
25
+ if (message.stopReason !== "error") return;
26
+ if (typeof message.errorMessage !== "string") return;
27
+ if (!UNKNOWN_NO_DETAILS_RE.test(message.errorMessage)) return;
28
+
29
+ // Avoid appending the hint repeatedly if a resumed/replayed message already has it.
30
+ if (message.errorMessage.includes(EXTENSION_TAG)) return;
31
+
32
+ // pi already has agent-level auto-retry for transient provider errors, but its
33
+ // matcher does not classify this empty-detail "Unknown error" message as retryable.
34
+ // Adding this hint before the message is finalized makes pi's built-in auto-retry
35
+ // path pick it up, remove the failed assistant message from live agent state, and
36
+ // call agent.continue() with the normal retry settings/backoff.
37
+ const errorMessage = `${message.errorMessage}\n\n${EXTENSION_TAG} ${RETRYABLE_HINT}; treating empty-detail provider failure as retryable.`;
38
+
39
+ if (ctx.hasUI) {
40
+ ctx.ui.notify(
41
+ "Matched provider 'Unknown error (no error details in response)'; letting pi auto-retry this turn.",
42
+ "warning",
43
+ );
44
+ }
45
+
46
+ return {
47
+ message: {
48
+ ...message,
49
+ errorMessage,
50
+ } as typeof event.message,
51
+ };
52
+ });
53
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@narumitw/pi-retry",
3
+ "version": "0.1.1",
4
+ "description": "Public pi extension that retries empty-detail provider unknown errors.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "keywords": [
9
+ "pi-package",
10
+ "pi-extension",
11
+ "pi",
12
+ "retry"
13
+ ],
14
+ "files": [
15
+ "extensions",
16
+ "README.md",
17
+ "biome.json"
18
+ ],
19
+ "pi": {
20
+ "extensions": [
21
+ "./extensions"
22
+ ]
23
+ },
24
+ "scripts": {
25
+ "check": "biome check . && npm run typecheck",
26
+ "format": "biome check --write .",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "peerDependencies": {
30
+ "@mariozechner/pi-coding-agent": "*"
31
+ },
32
+ "devDependencies": {
33
+ "@biomejs/biome": "2.4.14",
34
+ "@mariozechner/pi-coding-agent": "0.73.0",
35
+ "typescript": "6.0.3"
36
+ }
37
+ }