@caupulican/pi-ai 0.85.0 → 0.85.3

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.
@@ -11,35 +11,89 @@ export declare function getToolRepairRegistryEntry(name: ToolRepairModeName): To
11
11
  export declare function formatToolRepairNote(name: ToolRepairModeName, path: string): string;
12
12
  export declare function formatToolRepairStandingRule(name: ToolRepairModeName): string;
13
13
  export type ToolExecutionAttemptMemory = "retain" | "discard";
14
+ export type ToolFailurePhase = "validation" | "policy" | "preflight" | "execution" | "timeout" | "cancelled" | "provisioning";
14
15
  export declare const TOOL_EXECUTION_ERROR_CATALOGUE: readonly [{
16
+ readonly name: "provisioningFailed";
17
+ readonly phase: "provisioning";
18
+ readonly failureCode: "provisioning_failed";
19
+ readonly retainDiagnostic: true;
20
+ readonly guidance: "Provisioning failed; use the exact diagnostic, repair that cause, and retry only after the environment changes.";
21
+ readonly matches: (message: string) => boolean;
22
+ }, {
15
23
  readonly name: "commandNotFound";
24
+ readonly phase: "provisioning";
16
25
  readonly guidance: "Command was not found; check the command name or available tools before retrying.";
17
26
  readonly matches: (message: string) => boolean;
18
27
  }, {
19
28
  readonly name: "encodingCorruption";
29
+ readonly phase: "execution";
20
30
  readonly failureCode: "encoding_corruption";
21
31
  readonly attemptMemory: "discard";
22
32
  readonly guidance: "Change approach: exact UTF-8 text replacement is unsafe for this file. Use an encoding-aware or byte-safe tool/workflow instead; do not replay the text edit.";
23
33
  readonly matches: (message: string) => boolean;
24
34
  }, {
25
35
  readonly name: "fileNotFound";
36
+ readonly phase: "execution";
26
37
  readonly guidance: "Path was not found; list the parent directory or re-read the path before retrying.";
27
38
  readonly matches: (message: string) => boolean;
28
39
  }, {
29
40
  readonly name: "editOldTextNotFound";
41
+ readonly phase: "execution";
30
42
  readonly guidance: "Re-read the target file and use the exact current text before retrying.";
31
43
  readonly matches: (message: string) => boolean;
32
44
  }, {
33
45
  readonly name: "pathOutsideCwd";
46
+ readonly phase: "policy";
34
47
  readonly guidance: "Choose a path inside the current working directory, or ask before changing scope.";
35
48
  readonly matches: (message: string) => boolean;
49
+ }, {
50
+ readonly name: "permissionDenied";
51
+ readonly phase: "policy";
52
+ readonly failureCode: "permission_denied";
53
+ readonly retainDiagnostic: true;
54
+ readonly guidance: "Access was denied; verify the target path and current authority, then request or change permissions before retrying.";
55
+ readonly matches: (message: string) => boolean;
56
+ }, {
57
+ readonly name: "invalidOption";
58
+ readonly phase: "execution";
59
+ readonly failureCode: "invalid_option";
60
+ readonly retainDiagnostic: true;
61
+ readonly guidance: "Option rejected; re-read command help and remove or replace it before retrying.";
62
+ readonly matches: (message: string) => boolean;
63
+ }, {
64
+ readonly name: "invalidPattern";
65
+ readonly phase: "execution";
66
+ readonly failureCode: "invalid_pattern";
67
+ readonly retainDiagnostic: true;
68
+ readonly guidance: "The search pattern was invalid; simplify it or correct its regex/glob escaping before retrying.";
69
+ readonly matches: (message: string) => boolean;
70
+ }, {
71
+ readonly name: "outputLimit";
72
+ readonly phase: "execution";
73
+ readonly failureCode: "output_limit";
74
+ readonly guidance: "Output exceeded its bound; narrow the scope, page the request, or use the retained artifact before retrying.";
75
+ readonly matches: (message: string) => boolean;
76
+ }, {
77
+ readonly name: "timedOut";
78
+ readonly phase: "timeout";
79
+ readonly failureCode: "timeout";
80
+ readonly guidance: "The operation timed out; narrow or split the work, then retry once only when repeating it is safe and still required.";
81
+ readonly matches: (message: string) => boolean;
82
+ }, {
83
+ readonly name: "cancelled";
84
+ readonly phase: "cancelled";
85
+ readonly failureCode: "cancelled";
86
+ readonly guidance: "The operation was cancelled; retry only if it is still required and the cancellation condition has cleared.";
87
+ readonly matches: (message: string) => boolean;
36
88
  }];
37
89
  export type ToolExecutionErrorClass = (typeof TOOL_EXECUTION_ERROR_CATALOGUE)[number]["name"];
38
90
  export interface ToolExecutionErrorPolicy {
39
91
  name: ToolExecutionErrorClass;
92
+ phase: ToolFailurePhase;
40
93
  guidance: string;
41
94
  failureCode?: string;
42
95
  attemptMemory: ToolExecutionAttemptMemory;
96
+ retainDiagnostic: boolean;
43
97
  }
44
98
  export declare function getToolExecutionErrorPolicy(errorMessage: string): ToolExecutionErrorPolicy | undefined;
45
99
  export declare function getToolExecutionAttemptMemory(failureCode: string): ToolExecutionAttemptMemory;
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/utils/tool-repair/registry.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,YAClC,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,mBAAmB,CACV,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzE,MAAM,MAAM,yBAAyB,GAAG,kBAAkB,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,kBAAkB,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,oBAAoB,EAAE,SAAS,uBAAuB,EAgFzD,CAAC;AAIX,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,kBAAkB,GAAG,uBAAuB,CAI5F;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnF;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAE7E;AAED,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,SAAS,CAAC;AAU9D,eAAO,MAAM,8BAA8B;mBAEnC,iBAAiB;uBACb,mFAAmF;gCAC5E,MAAM,KAAG,OAAO;;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AAgB;;uBAEnB,iFAAiF;gCAC1E,MAAM,KAAG,OAAO;;mBAK3B,gBAAgB;oBACf,WAAW;0BACL,iBAAiB;;uBAEpB,iGAAiG;gCAC1F,MAAM,KAAG,OAAO;;mBAQ3B,aAAa;oBACZ,WAAW;0BACL,cAAc;uBAE1B,8GAA8G;gCAC9F,MAAM,KAAG,OAAO;;mBAK3B,UAAU;oBACT,SAAS;0BACH,SAAS;uBAErB,uHAAuH;gCACvG,MAAM,KAAG,OAAO;;mBAQ3B,WAAW;oBACV,WAAW;0BACL,WAAW;uBAEvB,6GAA6G;gCAC7F,MAAM,KAAG,OAAO;EAO6B,CAAC;AAEjE,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAG9F,MAAM,WAAW,wBAAwB;IACxC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,0BAA0B,CAAC;IAC1C,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAWtG;AAED,wBAAgB,6BAA6B,CAAC,WAAW,EAAE,MAAM,GAAG,0BAA0B,CAG7F;AAED,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtF"}
@@ -106,8 +106,19 @@ export function formatToolRepairStandingRule(name) {
106
106
  return getToolRepairRegistryEntry(name).standingRule;
107
107
  }
108
108
  export const TOOL_EXECUTION_ERROR_CATALOGUE = [
109
+ {
110
+ name: "provisioningFailed",
111
+ phase: "provisioning",
112
+ failureCode: "provisioning_failed",
113
+ retainDiagnostic: true,
114
+ guidance: "Provisioning failed; use the exact diagnostic, repair that cause, and retry only after the environment changes.",
115
+ matches(message) {
116
+ return /\bPI_TOOL_PROVISIONING_FAILED\b/i.test(message);
117
+ },
118
+ },
109
119
  {
110
120
  name: "commandNotFound",
121
+ phase: "provisioning",
111
122
  guidance: "Command was not found; check the command name or available tools before retrying.",
112
123
  matches(message) {
113
124
  return /^spawn \S+ ENOENT\b/i.test(message) || /(?:^|\n|:)\s*command not found\b/i.test(message);
@@ -115,6 +126,7 @@ export const TOOL_EXECUTION_ERROR_CATALOGUE = [
115
126
  },
116
127
  {
117
128
  name: "encodingCorruption",
129
+ phase: "execution",
118
130
  failureCode: "encoding_corruption",
119
131
  attemptMemory: "discard",
120
132
  guidance: "Change approach: exact UTF-8 text replacement is unsafe for this file. Use an encoding-aware or byte-safe tool/workflow instead; do not replay the text edit.",
@@ -124,6 +136,7 @@ export const TOOL_EXECUTION_ERROR_CATALOGUE = [
124
136
  },
125
137
  {
126
138
  name: "fileNotFound",
139
+ phase: "execution",
127
140
  guidance: "Path was not found; list the parent directory or re-read the path before retrying.",
128
141
  matches(message) {
129
142
  return /\bENOENT\b/i.test(message) || /no such file or directory/i.test(message);
@@ -131,6 +144,7 @@ export const TOOL_EXECUTION_ERROR_CATALOGUE = [
131
144
  },
132
145
  {
133
146
  name: "editOldTextNotFound",
147
+ phase: "execution",
134
148
  guidance: "Re-read the target file and use the exact current text before retrying.",
135
149
  matches(message) {
136
150
  return /(?:oldText|old text|exact text).*(?:not found|no match|failed to match|must match)/is.test(message);
@@ -138,11 +152,72 @@ export const TOOL_EXECUTION_ERROR_CATALOGUE = [
138
152
  },
139
153
  {
140
154
  name: "pathOutsideCwd",
155
+ phase: "policy",
141
156
  guidance: "Choose a path inside the current working directory, or ask before changing scope.",
142
157
  matches(message) {
143
158
  return /outside (?:the )?(?:current working directory|cwd|workspace|root)/i.test(message);
144
159
  },
145
160
  },
161
+ {
162
+ name: "permissionDenied",
163
+ phase: "policy",
164
+ failureCode: "permission_denied",
165
+ retainDiagnostic: true,
166
+ guidance: "Access was denied; verify the target path and current authority, then request or change permissions before retrying.",
167
+ matches(message) {
168
+ return /\b(?:EACCES|EPERM)\b/i.test(message) || /(?:permission|access) (?:is )?denied/i.test(message);
169
+ },
170
+ },
171
+ {
172
+ name: "invalidOption",
173
+ phase: "execution",
174
+ failureCode: "invalid_option",
175
+ retainDiagnostic: true,
176
+ guidance: "Option rejected; re-read command help and remove or replace it before retrying.",
177
+ matches(message) {
178
+ return /\b(?:invalid|unknown|unrecognized) (?:command-line )?(?:option|argument)\b/i.test(message);
179
+ },
180
+ },
181
+ {
182
+ name: "invalidPattern",
183
+ phase: "execution",
184
+ failureCode: "invalid_pattern",
185
+ retainDiagnostic: true,
186
+ guidance: "The search pattern was invalid; simplify it or correct its regex/glob escaping before retrying.",
187
+ matches(message) {
188
+ return (/(?:regex|regular expression|glob) (?:parse )?error\b/i.test(message) ||
189
+ /\bunclosed (?:group|class)\b/i.test(message));
190
+ },
191
+ },
192
+ {
193
+ name: "outputLimit",
194
+ phase: "execution",
195
+ failureCode: "output_limit",
196
+ guidance: "Output exceeded its bound; narrow the scope, page the request, or use the retained artifact before retrying.",
197
+ matches(message) {
198
+ return /\b(?:output|result|response).*(?:limit|truncat|too large)\b/i.test(message);
199
+ },
200
+ },
201
+ {
202
+ name: "timedOut",
203
+ phase: "timeout",
204
+ failureCode: "timeout",
205
+ guidance: "The operation timed out; narrow or split the work, then retry once only when repeating it is safe and still required.",
206
+ matches(message) {
207
+ return (/\b(?:command|operation|process|request|tool)\s+(?:timed out|timeout(?: after)?)\b/i.test(message) ||
208
+ /\bETIMEDOUT\b/i.test(message));
209
+ },
210
+ },
211
+ {
212
+ name: "cancelled",
213
+ phase: "cancelled",
214
+ failureCode: "cancelled",
215
+ guidance: "The operation was cancelled; retry only if it is still required and the cancellation condition has cleared.",
216
+ matches(message) {
217
+ return (/^(?:operation|request|tool) (?:was )?(?:aborted|cancelled|canceled)\b/i.test(message) ||
218
+ /\bAbortError\b/i.test(message));
219
+ },
220
+ },
146
221
  ];
147
222
  const executionErrorCatalogue = TOOL_EXECUTION_ERROR_CATALOGUE;
148
223
  export function getToolExecutionErrorPolicy(errorMessage) {
@@ -151,9 +226,11 @@ export function getToolExecutionErrorPolicy(errorMessage) {
151
226
  return undefined;
152
227
  return {
153
228
  name: entry.name,
229
+ phase: entry.phase,
154
230
  guidance: entry.guidance,
155
231
  ...(entry.failureCode ? { failureCode: entry.failureCode } : {}),
156
232
  attemptMemory: entry.attemptMemory ?? "retain",
233
+ retainDiagnostic: entry.retainDiagnostic ?? false,
157
234
  };
158
235
  }
159
236
  export function getToolExecutionAttemptMemory(failureCode) {
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/registry.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,kBAAkB;IAClB,oBAAoB;IACpB,iBAAiB;IACjB,2BAA2B;IAC3B,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,uBAAuB;IACvB,qBAAqB;IACrB,0BAA0B;IAC1B,qBAAqB;IACrB,mBAAmB;CACV,CAAC;AAWX,MAAM,CAAC,MAAM,oBAAoB,GAAuC;IACvE;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,2DAA2D;QACzE,YAAY,EAAE,+CAA+C;KAC7D;IACD;QACC,IAAI,EAAE,oBAAoB;QAC1B,YAAY,EAAE,8DAA8D;QAC5E,YAAY,EAAE,6EAA6E;KAC3F;IACD;QACC,IAAI,EAAE,iBAAiB;QACvB,YAAY,EAAE,uEAAuE;QACrF,YAAY,EACX,+GAA+G;KAChH;IACD;QACC,IAAI,EAAE,2BAA2B;QACjC,YAAY,EACX,6GAA6G;QAC9G,YAAY,EACX,uHAAuH;KACxH;IACD;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,+DAA+D;QAC7E,YAAY,EAAE,kEAAkE;KAChF;IACD;QACC,IA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CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3F,CAAC;KACD;CAC8D,CAAC;AAGjE,MAAM,uBAAuB,GAAgD,8BAA8B,CAAC;AAS5G,MAAM,UAAU,2BAA2B,CAAC,YAAoB;IAC/D,MAAM,KAAK,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3F,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,OAAO;QACN,IAAI,EAAE,KAAK,CAAC,IAA+B;QAC3C,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,aAAa,EAAE,KAAK,CAAC,aAAa,IAAI,QAAQ;KAC9C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,WAAmB;IAChE,MAAM,KAAK,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;IACjG,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,YAAoB;IACjE,OAAO,2BAA2B,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC;AAC5D,CAAC","sourcesContent":["export const TOOL_REPAIR_MODE_NAMES = [\n\t\"nullOptionalDrop\",\n\t\"nullRequiredBounce\",\n\t\"jsonStringParse\",\n\t\"jsonObjectPropertySalvage\",\n\t\"singleObjectWrap\",\n\t\"bareScalarWrap\",\n\t\"emptyObjectPlaceholder\",\n\t\"numberFromString\",\n\t\"boolFromString\",\n\t\"enumCaseNormalize\",\n\t\"propertyCaseNormalize\",\n\t\"singleElementUnwrap\",\n\t\"stringifiedNumberInArray\",\n\t\"bashCommandArgvJoin\",\n\t\"bashCommandUnwrap\",\n] as const;\n\nexport type ToolRepairModeName = (typeof TOOL_REPAIR_MODE_NAMES)[number];\nexport type ToolRepairFailureModeName = ToolRepairModeName | \"other\";\n\nexport interface ToolRepairRegistryEntry {\n\tname: ToolRepairModeName;\n\tnoteTemplate: string;\n\tstandingRule: string;\n}\n\nexport const TOOL_REPAIR_REGISTRY: readonly ToolRepairRegistryEntry[] = [\n\t{\n\t\tname: \"nullOptionalDrop\",\n\t\tnoteTemplate: \"sent null for optional `{path}` -> omit the field instead\",\n\t\tstandingRule: \"Omit optional fields instead of sending null.\",\n\t},\n\t{\n\t\tname: \"nullRequiredBounce\",\n\t\tnoteTemplate: \"`{path}` is required and cannot be null -> send a real value\",\n\t\tstandingRule: \"Send real values for required fields; never send null for a required field.\",\n\t},\n\t{\n\t\tname: \"jsonStringParse\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted JSON string -> send a raw JSON array/object\",\n\t\tstandingRule:\n\t\t\t\"Send raw JSON arrays/objects where the tool schema expects arrays/objects; do not quote them as JSON strings.\",\n\t},\n\t{\n\t\tname: \"jsonObjectPropertySalvage\",\n\t\tnoteTemplate:\n\t\t\t\"sent `{path}` as malformed JSON with recoverable declared properties -> keep the schema-declared properties\",\n\t\tstandingRule:\n\t\t\t\"When sending JSON objects, use strict JSON syntax with commas between properties and no extra text inside the object.\",\n\t},\n\t{\n\t\tname: \"singleObjectWrap\",\n\t\tnoteTemplate: \"sent one object where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single object in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"bareScalarWrap\",\n\t\tnoteTemplate: \"sent a single value where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single scalar in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"emptyObjectPlaceholder\",\n\t\tnoteTemplate: \"sent `{}` as a placeholder -> omit `{path}`; its default applies\",\n\t\tstandingRule: \"Omit defaulted object fields instead of sending `{}` placeholders.\",\n\t},\n\t{\n\t\tname: \"numberFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted number -> send a bare number\",\n\t\tstandingRule: \"Send bare numbers where the tool schema expects numbers; do not quote them.\",\n\t},\n\t{\n\t\tname: \"boolFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted boolean -> send bare true/false\",\n\t\tstandingRule: \"Send bare true/false where the tool schema expects booleans; do not quote them.\",\n\t},\n\t{\n\t\tname: \"enumCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` matched a declared enum value after case/space normalization\",\n\t\tstandingRule: \"Use enum values exactly as declared, preserving case and spacing.\",\n\t},\n\t{\n\t\tname: \"propertyCaseNormalize\",\n\t\tnoteTemplate: \"sent `{path}` with different property-key casing -> use the schema key casing\",\n\t\tstandingRule: \"Use tool argument property names exactly as declared in the schema, preserving case.\",\n\t},\n\t{\n\t\tname: \"singleElementUnwrap\",\n\t\tnoteTemplate: \"sent `{path}` as a 1-item list where a single value was expected -> send the value\",\n\t\tstandingRule:\n\t\t\t\"Send a single value directly when the tool schema expects a single value; do not wrap it in a one-item list.\",\n\t},\n\t{\n\t\tname: \"stringifiedNumberInArray\",\n\t\tnoteTemplate: \"list `{path}` holds quoted numbers -> send bare numbers\",\n\t\tstandingRule: \"Use bare numbers inside number arrays; do not quote them.\",\n\t},\n\t{\n\t\tname: \"bashCommandArgvJoin\",\n\t\tnoteTemplate: \"bash takes one command string, not an argv list -> joined the argv values\",\n\t\tstandingRule: \"For bash, send one command string rather than an argv array.\",\n\t},\n\t{\n\t\tname: \"bashCommandUnwrap\",\n\t\tnoteTemplate: \"bash `command` is a string -> unwrapped the command object\",\n\t\tstandingRule: \"For bash, send `command` as a string rather than an object wrapper.\",\n\t},\n] as const;\n\nconst registryByName = new Map(TOOL_REPAIR_REGISTRY.map((entry) => [entry.name, entry]));\n\nexport function getToolRepairRegistryEntry(name: ToolRepairModeName): ToolRepairRegistryEntry {\n\tconst entry = registryByName.get(name);\n\tif (!entry) throw new Error(`Unknown tool repair mode: ${name}`);\n\treturn entry;\n}\n\nexport function formatToolRepairNote(name: ToolRepairModeName, path: string): string {\n\treturn getToolRepairRegistryEntry(name).noteTemplate.replaceAll(\"{path}\", path);\n}\n\nexport function formatToolRepairStandingRule(name: ToolRepairModeName): string {\n\treturn getToolRepairRegistryEntry(name).standingRule;\n}\n\nexport type ToolExecutionAttemptMemory = \"retain\" | \"discard\";\n\ninterface ToolExecutionErrorCatalogueEntry {\n\tname: string;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory?: ToolExecutionAttemptMemory;\n\tmatches(message: string): boolean;\n}\n\nexport const TOOL_EXECUTION_ERROR_CATALOGUE = [\n\t{\n\t\tname: \"commandNotFound\",\n\t\tguidance: \"Command was not found; check the command name or available tools before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /^spawn \\S+ ENOENT\\b/i.test(message) || /(?:^|\\n|:)\\s*command not found\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"encodingCorruption\",\n\t\tfailureCode: \"encoding_corruption\",\n\t\tattemptMemory: \"discard\",\n\t\tguidance:\n\t\t\t\"Change approach: exact UTF-8 text replacement is unsafe for this file. Use an encoding-aware or byte-safe tool/workflow instead; do not replay the text edit.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_ENCODING_CORRUPTION\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"fileNotFound\",\n\t\tguidance: \"Path was not found; list the parent directory or re-read the path before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bENOENT\\b/i.test(message) || /no such file or directory/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"editOldTextNotFound\",\n\t\tguidance: \"Re-read the target file and use the exact current text before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /(?:oldText|old text|exact text).*(?:not found|no match|failed to match|must match)/is.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"pathOutsideCwd\",\n\t\tguidance: \"Choose a path inside the current working directory, or ask before changing scope.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /outside (?:the )?(?:current working directory|cwd|workspace|root)/i.test(message);\n\t\t},\n\t},\n] as const satisfies readonly ToolExecutionErrorCatalogueEntry[];\n\nexport type ToolExecutionErrorClass = (typeof TOOL_EXECUTION_ERROR_CATALOGUE)[number][\"name\"];\nconst executionErrorCatalogue: readonly ToolExecutionErrorCatalogueEntry[] = TOOL_EXECUTION_ERROR_CATALOGUE;\n\nexport interface ToolExecutionErrorPolicy {\n\tname: ToolExecutionErrorClass;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory: ToolExecutionAttemptMemory;\n}\n\nexport function getToolExecutionErrorPolicy(errorMessage: string): ToolExecutionErrorPolicy | undefined {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.matches(errorMessage));\n\tif (!entry) return undefined;\n\treturn {\n\t\tname: entry.name as ToolExecutionErrorClass,\n\t\tguidance: entry.guidance,\n\t\t...(entry.failureCode ? { failureCode: entry.failureCode } : {}),\n\t\tattemptMemory: entry.attemptMemory ?? \"retain\",\n\t};\n}\n\nexport function getToolExecutionAttemptMemory(failureCode: string): ToolExecutionAttemptMemory {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.failureCode === failureCode);\n\treturn entry?.attemptMemory ?? \"retain\";\n}\n\nexport function getToolExecutionErrorGuidance(errorMessage: string): string | undefined {\n\treturn getToolExecutionErrorPolicy(errorMessage)?.guidance;\n}\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/registry.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,kBAAkB;IAClB,oBAAoB;IACpB,iBAAiB;IACjB,2BAA2B;IAC3B,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,kBAAkB;IAClB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aceholder\",\n\t\"numberFromString\",\n\t\"boolFromString\",\n\t\"enumCaseNormalize\",\n\t\"propertyCaseNormalize\",\n\t\"singleElementUnwrap\",\n\t\"stringifiedNumberInArray\",\n\t\"bashCommandArgvJoin\",\n\t\"bashCommandUnwrap\",\n] as const;\n\nexport type ToolRepairModeName = (typeof TOOL_REPAIR_MODE_NAMES)[number];\nexport type ToolRepairFailureModeName = ToolRepairModeName | \"other\";\n\nexport interface ToolRepairRegistryEntry {\n\tname: ToolRepairModeName;\n\tnoteTemplate: string;\n\tstandingRule: string;\n}\n\nexport const TOOL_REPAIR_REGISTRY: readonly ToolRepairRegistryEntry[] = [\n\t{\n\t\tname: \"nullOptionalDrop\",\n\t\tnoteTemplate: \"sent null for optional `{path}` -> omit the field instead\",\n\t\tstandingRule: \"Omit optional fields instead of sending null.\",\n\t},\n\t{\n\t\tname: \"nullRequiredBounce\",\n\t\tnoteTemplate: \"`{path}` is required and cannot be null -> send a real value\",\n\t\tstandingRule: \"Send real values for required fields; never send null for a required field.\",\n\t},\n\t{\n\t\tname: \"jsonStringParse\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted JSON string -> send a raw JSON array/object\",\n\t\tstandingRule:\n\t\t\t\"Send raw JSON arrays/objects where the tool schema expects arrays/objects; do not quote them as JSON strings.\",\n\t},\n\t{\n\t\tname: \"jsonObjectPropertySalvage\",\n\t\tnoteTemplate:\n\t\t\t\"sent `{path}` as malformed JSON with recoverable declared properties -> keep the schema-declared properties\",\n\t\tstandingRule:\n\t\t\t\"When sending JSON objects, use strict JSON syntax with commas between properties and no extra text inside the object.\",\n\t},\n\t{\n\t\tname: \"singleObjectWrap\",\n\t\tnoteTemplate: \"sent one object where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single object in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"bareScalarWrap\",\n\t\tnoteTemplate: \"sent a single value where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single scalar in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"emptyObjectPlaceholder\",\n\t\tnoteTemplate: \"sent `{}` as a placeholder -> omit `{path}`; its default applies\",\n\t\tstandingRule: \"Omit defaulted object fields instead of sending `{}` placeholders.\",\n\t},\n\t{\n\t\tname: \"numberFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted number -> send a bare number\",\n\t\tstandingRule: \"Send bare numbers where the tool schema expects numbers; do not quote them.\",\n\t},\n\t{\n\t\tname: \"boolFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted boolean -> send bare true/false\",\n\t\tstandingRule: \"Send bare true/false where the tool schema expects booleans; do not quote them.\",\n\t},\n\t{\n\t\tname: \"enumCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` matched a declared enum value after case/space normalization\",\n\t\tstandingRule: \"Use enum values exactly as declared, preserving case and spacing.\",\n\t},\n\t{\n\t\tname: \"propertyCaseNormalize\",\n\t\tnoteTemplate: \"sent `{path}` with different property-key casing -> use the schema key casing\",\n\t\tstandingRule: \"Use tool argument property names exactly as declared in the schema, preserving case.\",\n\t},\n\t{\n\t\tname: \"singleElementUnwrap\",\n\t\tnoteTemplate: \"sent `{path}` as a 1-item list where a single value was expected -> send the value\",\n\t\tstandingRule:\n\t\t\t\"Send a single value directly when the tool schema expects a single value; do not wrap it in a one-item list.\",\n\t},\n\t{\n\t\tname: \"stringifiedNumberInArray\",\n\t\tnoteTemplate: \"list `{path}` holds quoted numbers -> send bare numbers\",\n\t\tstandingRule: \"Use bare numbers inside number arrays; do not quote them.\",\n\t},\n\t{\n\t\tname: \"bashCommandArgvJoin\",\n\t\tnoteTemplate: \"bash takes one command string, not an argv list -> joined the argv values\",\n\t\tstandingRule: \"For bash, send one command string rather than an argv array.\",\n\t},\n\t{\n\t\tname: \"bashCommandUnwrap\",\n\t\tnoteTemplate: \"bash `command` is a string -> unwrapped the command object\",\n\t\tstandingRule: \"For bash, send `command` as a string rather than an object wrapper.\",\n\t},\n] as const;\n\nconst registryByName = new Map(TOOL_REPAIR_REGISTRY.map((entry) => [entry.name, entry]));\n\nexport function getToolRepairRegistryEntry(name: ToolRepairModeName): ToolRepairRegistryEntry {\n\tconst entry = registryByName.get(name);\n\tif (!entry) throw new Error(`Unknown tool repair mode: ${name}`);\n\treturn entry;\n}\n\nexport function formatToolRepairNote(name: ToolRepairModeName, path: string): string {\n\treturn getToolRepairRegistryEntry(name).noteTemplate.replaceAll(\"{path}\", path);\n}\n\nexport function formatToolRepairStandingRule(name: ToolRepairModeName): string {\n\treturn getToolRepairRegistryEntry(name).standingRule;\n}\n\nexport type ToolExecutionAttemptMemory = \"retain\" | \"discard\";\nexport type ToolFailurePhase =\n\t| \"validation\"\n\t| \"policy\"\n\t| \"preflight\"\n\t| \"execution\"\n\t| \"timeout\"\n\t| \"cancelled\"\n\t| \"provisioning\";\n\ninterface ToolExecutionErrorCatalogueEntry {\n\tname: string;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory?: ToolExecutionAttemptMemory;\n\tretainDiagnostic?: boolean;\n\tmatches(message: string): boolean;\n}\n\nexport const TOOL_EXECUTION_ERROR_CATALOGUE = [\n\t{\n\t\tname: \"provisioningFailed\",\n\t\tphase: \"provisioning\",\n\t\tfailureCode: \"provisioning_failed\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Provisioning failed; use the exact diagnostic, repair that cause, and retry only after the environment changes.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_TOOL_PROVISIONING_FAILED\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"commandNotFound\",\n\t\tphase: \"provisioning\",\n\t\tguidance: \"Command was not found; check the command name or available tools before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /^spawn \\S+ ENOENT\\b/i.test(message) || /(?:^|\\n|:)\\s*command not found\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"encodingCorruption\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"encoding_corruption\",\n\t\tattemptMemory: \"discard\",\n\t\tguidance:\n\t\t\t\"Change approach: exact UTF-8 text replacement is unsafe for this file. Use an encoding-aware or byte-safe tool/workflow instead; do not replay the text edit.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_ENCODING_CORRUPTION\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"fileNotFound\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Path was not found; list the parent directory or re-read the path before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bENOENT\\b/i.test(message) || /no such file or directory/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"editOldTextNotFound\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Re-read the target file and use the exact current text before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /(?:oldText|old text|exact text).*(?:not found|no match|failed to match|must match)/is.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"pathOutsideCwd\",\n\t\tphase: \"policy\",\n\t\tguidance: \"Choose a path inside the current working directory, or ask before changing scope.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /outside (?:the )?(?:current working directory|cwd|workspace|root)/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"permissionDenied\",\n\t\tphase: \"policy\",\n\t\tfailureCode: \"permission_denied\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Access was denied; verify the target path and current authority, then request or change permissions before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:EACCES|EPERM)\\b/i.test(message) || /(?:permission|access) (?:is )?denied/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"invalidOption\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"invalid_option\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"Option rejected; re-read command help and remove or replace it before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:invalid|unknown|unrecognized) (?:command-line )?(?:option|argument)\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"invalidPattern\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"invalid_pattern\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"The search pattern was invalid; simplify it or correct its regex/glob escaping before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/(?:regex|regular expression|glob) (?:parse )?error\\b/i.test(message) ||\n\t\t\t\t/\\bunclosed (?:group|class)\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"outputLimit\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"output_limit\",\n\t\tguidance:\n\t\t\t\"Output exceeded its bound; narrow the scope, page the request, or use the retained artifact before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:output|result|response).*(?:limit|truncat|too large)\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"timedOut\",\n\t\tphase: \"timeout\",\n\t\tfailureCode: \"timeout\",\n\t\tguidance:\n\t\t\t\"The operation timed out; narrow or split the work, then retry once only when repeating it is safe and still required.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/\\b(?:command|operation|process|request|tool)\\s+(?:timed out|timeout(?: after)?)\\b/i.test(message) ||\n\t\t\t\t/\\bETIMEDOUT\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"cancelled\",\n\t\tphase: \"cancelled\",\n\t\tfailureCode: \"cancelled\",\n\t\tguidance:\n\t\t\t\"The operation was cancelled; retry only if it is still required and the cancellation condition has cleared.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/^(?:operation|request|tool) (?:was )?(?:aborted|cancelled|canceled)\\b/i.test(message) ||\n\t\t\t\t/\\bAbortError\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n] as const satisfies readonly ToolExecutionErrorCatalogueEntry[];\n\nexport type ToolExecutionErrorClass = (typeof TOOL_EXECUTION_ERROR_CATALOGUE)[number][\"name\"];\nconst executionErrorCatalogue: readonly ToolExecutionErrorCatalogueEntry[] = TOOL_EXECUTION_ERROR_CATALOGUE;\n\nexport interface ToolExecutionErrorPolicy {\n\tname: ToolExecutionErrorClass;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory: ToolExecutionAttemptMemory;\n\tretainDiagnostic: boolean;\n}\n\nexport function getToolExecutionErrorPolicy(errorMessage: string): ToolExecutionErrorPolicy | undefined {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.matches(errorMessage));\n\tif (!entry) return undefined;\n\treturn {\n\t\tname: entry.name as ToolExecutionErrorClass,\n\t\tphase: entry.phase,\n\t\tguidance: entry.guidance,\n\t\t...(entry.failureCode ? { failureCode: entry.failureCode } : {}),\n\t\tattemptMemory: entry.attemptMemory ?? \"retain\",\n\t\tretainDiagnostic: entry.retainDiagnostic ?? false,\n\t};\n}\n\nexport function getToolExecutionAttemptMemory(failureCode: string): ToolExecutionAttemptMemory {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.failureCode === failureCode);\n\treturn entry?.attemptMemory ?? \"retain\";\n}\n\nexport function getToolExecutionErrorGuidance(errorMessage: string): string | undefined {\n\treturn getToolExecutionErrorPolicy(errorMessage)?.guidance;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caupulican/pi-ai",
3
- "version": "0.85.0",
3
+ "version": "0.85.3",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",