@caupulican/pi-ai 0.90.2 → 0.90.4

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.
@@ -17,7 +17,17 @@ export declare const REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE: {
17
17
  readonly diagnostic: "The identical phone tool call already succeeded and was not executed again.";
18
18
  readonly guidance: "Use prior successful result; continue. Task complete: answer user. Otherwise call different required tool. Never retry unchanged.";
19
19
  };
20
+ /** Stable marker for a tool-owned guard that rejects one operation before external execution. */
21
+ export declare const TOOL_OPERATION_REJECTED_MARKER = "PI_TOOL_OPERATION_REJECTED";
20
22
  export declare const TOOL_EXECUTION_ERROR_CATALOGUE: readonly [{
23
+ readonly name: "operationRejected";
24
+ readonly phase: "policy";
25
+ readonly failureCode: "operation_rejected";
26
+ readonly attemptMemory: "discard";
27
+ readonly retainDiagnostic: true;
28
+ readonly guidance: "Operation rejected before execution. Follow the diagnostic: correct or narrow the call, or continue independent work. The runtime remains available.";
29
+ readonly matches: (message: string) => boolean;
30
+ }, {
21
31
  readonly name: "provisioningFailed";
22
32
  readonly phase: "provisioning";
23
33
  readonly failureCode: "provisioning_failed";
@@ -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;AAEr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AAC;IACrB,aAAa,EAAE,0BAA0B,CAAC;IAC1C,gBAAgB,EAAE,OAAO,CAAC;IAC1B,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAYtG;AAED,wBAAgB,6BAA6B,CAAC,WAAW,EAAE,MAAM,GAAG,0BAA0B,CAG7F;AAED,wBAAgB,mCAAmC,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG/E;AAED,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEtF"}
@@ -110,7 +110,20 @@ export const REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE = {
110
110
  diagnostic: "The identical phone tool call already succeeded and was not executed again.",
111
111
  guidance: "Use prior successful result; continue. Task complete: answer user. Otherwise call different required tool. Never retry unchanged.",
112
112
  };
113
+ /** Stable marker for a tool-owned guard that rejects one operation before external execution. */
114
+ export const TOOL_OPERATION_REJECTED_MARKER = "PI_TOOL_OPERATION_REJECTED";
113
115
  export const TOOL_EXECUTION_ERROR_CATALOGUE = [
116
+ {
117
+ name: "operationRejected",
118
+ phase: "policy",
119
+ failureCode: "operation_rejected",
120
+ attemptMemory: "discard",
121
+ retainDiagnostic: true,
122
+ guidance: "Operation rejected before execution. Follow the diagnostic: correct or narrow the call, or continue independent work. The runtime remains available.",
123
+ matches(message) {
124
+ return message.includes(TOOL_OPERATION_REJECTED_MARKER);
125
+ },
126
+ },
114
127
  {
115
128
  name: "provisioningFailed",
116
129
  phase: "provisioning",
@@ -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;IACx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KACnD,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,mCAAmC,CAAC,WAAmB;IACtE,MAAM,KAAK,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;IACjG,OAAO,KAAK,EAAE,mBAAmB,IAAI,CAAC,CAAC;AACxC,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: \"optional `{path}` was null; omit field\",\n\t\tstandingRule: \"Optional field: omit, never null.\",\n\t},\n\t{\n\t\tname: \"nullRequiredBounce\",\n\t\tnoteTemplate: \"required `{path}` was null; send real value\",\n\t\tstandingRule: \"Required field: real value, never null.\",\n\t},\n\t{\n\t\tname: \"jsonStringParse\",\n\t\tnoteTemplate: \"`{path}` was quoted JSON; send raw array/object\",\n\t\tstandingRule: \"Schema array/object: raw JSON, never quoted JSON string.\",\n\t},\n\t{\n\t\tname: \"jsonObjectPropertySalvage\",\n\t\tnoteTemplate: \"`{path}` was malformed JSON; retained declared properties\",\n\t\tstandingRule: \"JSON object: strict syntax, commas between properties, no extra inner text.\",\n\t},\n\t{\n\t\tname: \"singleObjectWrap\",\n\t\tnoteTemplate: \"`{path}` needs list; wrap object in [ ]\",\n\t\tstandingRule: \"List schema: wrap one object in [ ].\",\n\t},\n\t{\n\t\tname: \"bareScalarWrap\",\n\t\tnoteTemplate: \"`{path}` needs list; wrap scalar in [ ]\",\n\t\tstandingRule: \"List schema: wrap one scalar in [ ].\",\n\t},\n\t{\n\t\tname: \"emptyObjectPlaceholder\",\n\t\tnoteTemplate: \"`{path}` was `{}` placeholder; omit for default\",\n\t\tstandingRule: \"Defaulted object field: omit, never `{}` placeholder.\",\n\t},\n\t{\n\t\tname: \"numberFromString\",\n\t\tnoteTemplate: \"`{path}` was quoted number; send bare number\",\n\t\tstandingRule: \"Number schema: bare number, never quoted.\",\n\t},\n\t{\n\t\tname: \"boolFromString\",\n\t\tnoteTemplate: \"`{path}` was quoted boolean; send bare true/false\",\n\t\tstandingRule: \"Boolean schema: bare true/false, never quoted.\",\n\t},\n\t{\n\t\tname: \"enumCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` normalized to declared enum case/spacing\",\n\t\tstandingRule: \"Enum value: exact declared case/spacing.\",\n\t},\n\t{\n\t\tname: \"propertyCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` used wrong key case; use schema case\",\n\t\tstandingRule: \"Argument property: exact schema name/case.\",\n\t},\n\t{\n\t\tname: \"singleElementUnwrap\",\n\t\tnoteTemplate: \"`{path}` needs scalar; unwrap 1-item list\",\n\t\tstandingRule: \"Scalar schema: direct value, never 1-item list.\",\n\t},\n\t{\n\t\tname: \"stringifiedNumberInArray\",\n\t\tnoteTemplate: \"number list `{path}` held quoted values; send bare numbers\",\n\t\tstandingRule: \"Number array: bare numbers, never quoted.\",\n\t},\n\t{\n\t\tname: \"bashCommandArgvJoin\",\n\t\tnoteTemplate: \"bash needs one command string; joined argv values\",\n\t\tstandingRule: \"bash command: one string, never argv array.\",\n\t},\n\t{\n\t\tname: \"bashCommandUnwrap\",\n\t\tnoteTemplate: \"bash `command` needs string; unwrapped object\",\n\t\tstandingRule: \"bash `command`: string, never 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\nexport const REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE = {\n\tfailureCode: \"repeated_successful_call\",\n\tdiagnostic: \"The identical phone tool call already succeeded and was not executed again.\",\n\tguidance:\n\t\t\"Use prior successful result; continue. Task complete: answer user. Otherwise call different required tool. Never retry unchanged.\",\n} as const;\n\ninterface ToolExecutionErrorCatalogueEntry {\n\tname: string;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory?: ToolExecutionAttemptMemory;\n\tretainDiagnostic?: boolean;\n\t/** Number of unchanged executions permitted after the first failure in one recovery window. */\n\tunchangedRetryLimit?: number;\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: \"Provisioning failed. Use exact diagnostic, fix cause; retry only after 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 not found. Check exact name/available tools before retry.\",\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: \"bashNoOutput\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Command failed without output. Verify syntax, exact command documentation before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn message === \"(no output)\";\n\t\t},\n\t},\n\t{\n\t\tname: \"bashPosixNotSupported\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Windows host rejects POSIX .sh scripts. Use PowerShell equivalent or invoke executable directly.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /POSIX shell scripts are not supported by the Windows shell contract router/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"bashNestedShell\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Never wrap command in powershell.exe/pwsh. Invoke .ps1 or command directly.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /Nested shell execution is not supported by the Windows shell contract router/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"bashMissingCommandWord\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Missing shell command word. Fix empty pipeline element or string quoting before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /Missing command: a pipeline\\/list element has no command word/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"bashEmptyRedirectTarget\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Empty redirect target. Supply valid file path before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /redirect target expanded to nothing/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 replacement unsafe. Use encoding-aware/byte-safe tool; never replay 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: \"repeatedSuccessfulCall\",\n\t\tphase: \"execution\",\n\t\tfailureCode: REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.failureCode,\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance: REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.guidance,\n\t\tmatches(message: string): boolean {\n\t\t\treturn message === REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.diagnostic;\n\t\t},\n\t},\n\t{\n\t\tname: \"fileMutationRetarget\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"mutation_retarget_required\",\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Harness retained mutation. Choose corrected target path, reuse exact diagnostic payloadRef; never regenerate content/edits.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_MUTATION_RETARGET\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"fileNotFound\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"file_not_found\",\n\t\tguidance: \"Path not found. List parent directory or re-read path before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/\\bENOENT\\b/i.test(message) ||\n\t\t\t\t/no such file or directory/i.test(message) ||\n\t\t\t\t/\\b(?:file|path) not found\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"editOldTextNotFound\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"edit_old_text_not_found\",\n\t\tguidance: \"Re-read target; use exact current text before retry.\",\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 path inside current working directory; ask before scope change.\",\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: \"Access denied. Verify target/current authority; obtain permissions before retry.\",\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. Read command help; remove/replace option before retry.\",\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: \"Invalid search pattern. Simplify or fix regex/glob escaping before retry.\",\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: \"Output exceeded bound. Narrow scope, page request, or use retained artifact before retry.\",\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\tunchangedRetryLimit: 1,\n\t\tguidance: \"Operation timed out. Narrow/split work; one unchanged retry only when safe, 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: \"Operation cancelled. Retry only when still required, cancellation condition 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\tunchangedRetryLimit: number;\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\tunchangedRetryLimit: entry.unchangedRetryLimit ?? 0,\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 getToolExecutionUnchangedRetryLimit(failureCode: string): number {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.failureCode === failureCode);\n\treturn entry?.unchangedRetryLimit ?? 0;\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,gBAAgB;IAChB,mBAAmB;IACnB,uBAAuB;IACvB,qBAAqB;IACrB,0BAA0B;IAC1B,qBAAqB;IACrB,mBAAmB;CACV,CAAC;AAWX,MAAM,CAAC,MAAM,oBAAoB,GAAuC;IACvE;QACC,IAA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AAa,EAAE,KAAK,CAAC,aAAa,IAAI,QAAQ;QAC9C,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,IAAI,KAAK;QACjD,mBAAmB,EAAE,KAAK,CAAC,mBAAmB,IAAI,CAAC;KACnD,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,mCAAmC,CAAC,WAAmB;IACtE,MAAM,KAAK,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;IACjG,OAAO,KAAK,EAAE,mBAAmB,IAAI,CAAC,CAAC;AACxC,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: \"optional `{path}` was null; omit field\",\n\t\tstandingRule: \"Optional field: omit, never null.\",\n\t},\n\t{\n\t\tname: \"nullRequiredBounce\",\n\t\tnoteTemplate: \"required `{path}` was null; send real value\",\n\t\tstandingRule: \"Required field: real value, never null.\",\n\t},\n\t{\n\t\tname: \"jsonStringParse\",\n\t\tnoteTemplate: \"`{path}` was quoted JSON; send raw array/object\",\n\t\tstandingRule: \"Schema array/object: raw JSON, never quoted JSON string.\",\n\t},\n\t{\n\t\tname: \"jsonObjectPropertySalvage\",\n\t\tnoteTemplate: \"`{path}` was malformed JSON; retained declared properties\",\n\t\tstandingRule: \"JSON object: strict syntax, commas between properties, no extra inner text.\",\n\t},\n\t{\n\t\tname: \"singleObjectWrap\",\n\t\tnoteTemplate: \"`{path}` needs list; wrap object in [ ]\",\n\t\tstandingRule: \"List schema: wrap one object in [ ].\",\n\t},\n\t{\n\t\tname: \"bareScalarWrap\",\n\t\tnoteTemplate: \"`{path}` needs list; wrap scalar in [ ]\",\n\t\tstandingRule: \"List schema: wrap one scalar in [ ].\",\n\t},\n\t{\n\t\tname: \"emptyObjectPlaceholder\",\n\t\tnoteTemplate: \"`{path}` was `{}` placeholder; omit for default\",\n\t\tstandingRule: \"Defaulted object field: omit, never `{}` placeholder.\",\n\t},\n\t{\n\t\tname: \"numberFromString\",\n\t\tnoteTemplate: \"`{path}` was quoted number; send bare number\",\n\t\tstandingRule: \"Number schema: bare number, never quoted.\",\n\t},\n\t{\n\t\tname: \"boolFromString\",\n\t\tnoteTemplate: \"`{path}` was quoted boolean; send bare true/false\",\n\t\tstandingRule: \"Boolean schema: bare true/false, never quoted.\",\n\t},\n\t{\n\t\tname: \"enumCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` normalized to declared enum case/spacing\",\n\t\tstandingRule: \"Enum value: exact declared case/spacing.\",\n\t},\n\t{\n\t\tname: \"propertyCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` used wrong key case; use schema case\",\n\t\tstandingRule: \"Argument property: exact schema name/case.\",\n\t},\n\t{\n\t\tname: \"singleElementUnwrap\",\n\t\tnoteTemplate: \"`{path}` needs scalar; unwrap 1-item list\",\n\t\tstandingRule: \"Scalar schema: direct value, never 1-item list.\",\n\t},\n\t{\n\t\tname: \"stringifiedNumberInArray\",\n\t\tnoteTemplate: \"number list `{path}` held quoted values; send bare numbers\",\n\t\tstandingRule: \"Number array: bare numbers, never quoted.\",\n\t},\n\t{\n\t\tname: \"bashCommandArgvJoin\",\n\t\tnoteTemplate: \"bash needs one command string; joined argv values\",\n\t\tstandingRule: \"bash command: one string, never argv array.\",\n\t},\n\t{\n\t\tname: \"bashCommandUnwrap\",\n\t\tnoteTemplate: \"bash `command` needs string; unwrapped object\",\n\t\tstandingRule: \"bash `command`: string, never 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\nexport const REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE = {\n\tfailureCode: \"repeated_successful_call\",\n\tdiagnostic: \"The identical phone tool call already succeeded and was not executed again.\",\n\tguidance:\n\t\t\"Use prior successful result; continue. Task complete: answer user. Otherwise call different required tool. Never retry unchanged.\",\n} as const;\n\n/** Stable marker for a tool-owned guard that rejects one operation before external execution. */\nexport const TOOL_OPERATION_REJECTED_MARKER = \"PI_TOOL_OPERATION_REJECTED\";\n\ninterface ToolExecutionErrorCatalogueEntry {\n\tname: string;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory?: ToolExecutionAttemptMemory;\n\tretainDiagnostic?: boolean;\n\t/** Number of unchanged executions permitted after the first failure in one recovery window. */\n\tunchangedRetryLimit?: number;\n\tmatches(message: string): boolean;\n}\n\nexport const TOOL_EXECUTION_ERROR_CATALOGUE = [\n\t{\n\t\tname: \"operationRejected\",\n\t\tphase: \"policy\",\n\t\tfailureCode: \"operation_rejected\",\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Operation rejected before execution. Follow the diagnostic: correct or narrow the call, or continue independent work. The runtime remains available.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn message.includes(TOOL_OPERATION_REJECTED_MARKER);\n\t\t},\n\t},\n\t{\n\t\tname: \"provisioningFailed\",\n\t\tphase: \"provisioning\",\n\t\tfailureCode: \"provisioning_failed\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"Provisioning failed. Use exact diagnostic, fix cause; retry only after 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 not found. Check exact name/available tools before retry.\",\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: \"bashNoOutput\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Command failed without output. Verify syntax, exact command documentation before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn message === \"(no output)\";\n\t\t},\n\t},\n\t{\n\t\tname: \"bashPosixNotSupported\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Windows host rejects POSIX .sh scripts. Use PowerShell equivalent or invoke executable directly.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /POSIX shell scripts are not supported by the Windows shell contract router/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"bashNestedShell\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Never wrap command in powershell.exe/pwsh. Invoke .ps1 or command directly.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /Nested shell execution is not supported by the Windows shell contract router/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"bashMissingCommandWord\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Missing shell command word. Fix empty pipeline element or string quoting before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /Missing command: a pipeline\\/list element has no command word/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"bashEmptyRedirectTarget\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Empty redirect target. Supply valid file path before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /redirect target expanded to nothing/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 replacement unsafe. Use encoding-aware/byte-safe tool; never replay 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: \"repeatedSuccessfulCall\",\n\t\tphase: \"execution\",\n\t\tfailureCode: REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.failureCode,\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance: REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.guidance,\n\t\tmatches(message: string): boolean {\n\t\t\treturn message === REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.diagnostic;\n\t\t},\n\t},\n\t{\n\t\tname: \"fileMutationRetarget\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"mutation_retarget_required\",\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Harness retained mutation. Choose corrected target path, reuse exact diagnostic payloadRef; never regenerate content/edits.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_MUTATION_RETARGET\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"fileNotFound\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"file_not_found\",\n\t\tguidance: \"Path not found. List parent directory or re-read path before retry.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/\\bENOENT\\b/i.test(message) ||\n\t\t\t\t/no such file or directory/i.test(message) ||\n\t\t\t\t/\\b(?:file|path) not found\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"editOldTextNotFound\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"edit_old_text_not_found\",\n\t\tguidance: \"Re-read target; use exact current text before retry.\",\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 path inside current working directory; ask before scope change.\",\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: \"Access denied. Verify target/current authority; obtain permissions before retry.\",\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. Read command help; remove/replace option before retry.\",\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: \"Invalid search pattern. Simplify or fix regex/glob escaping before retry.\",\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: \"Output exceeded bound. Narrow scope, page request, or use retained artifact before retry.\",\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\tunchangedRetryLimit: 1,\n\t\tguidance: \"Operation timed out. Narrow/split work; one unchanged retry only when safe, 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: \"Operation cancelled. Retry only when still required, cancellation condition 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\tunchangedRetryLimit: number;\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\tunchangedRetryLimit: entry.unchangedRetryLimit ?? 0,\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 getToolExecutionUnchangedRetryLimit(failureCode: string): number {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.failureCode === failureCode);\n\treturn entry?.unchangedRetryLimit ?? 0;\n}\n\nexport function getToolExecutionErrorGuidance(errorMessage: string): string | undefined {\n\treturn getToolExecutionErrorPolicy(errorMessage)?.guidance;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"validation-path.d.ts","sourceRoot":"","sources":["../../src/utils/validation-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE/D,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAW7E"}
1
+ {"version":3,"file":"validation-path.d.ts","sourceRoot":"","sources":["../../src/utils/validation-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE/D,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAiB7E"}
@@ -1,14 +1,20 @@
1
1
  /** Format a TypeBox validation location consistently across package boundaries. */
2
2
  export function formatValidationPath(error) {
3
+ const basePath = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
3
4
  if (error.keyword === "required") {
4
5
  const requiredProperties = error.params.requiredProperties;
5
6
  const requiredProperty = requiredProperties?.[0];
6
7
  if (requiredProperty) {
7
- const basePath = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
8
8
  return basePath ? `${basePath}.${requiredProperty}` : requiredProperty;
9
9
  }
10
10
  }
11
- const path = error.instancePath.replace(/^\//, "").replace(/\//g, ".");
12
- return path || "root";
11
+ if (error.keyword === "additionalProperties") {
12
+ const params = error.params;
13
+ const additionalProperty = params.additionalProperty ?? params.additionalProperties?.[0];
14
+ if (additionalProperty) {
15
+ return basePath ? `${basePath}.${additionalProperty}` : additionalProperty;
16
+ }
17
+ }
18
+ return basePath || "root";
13
19
  }
14
20
  //# sourceMappingURL=validation-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation-path.js","sourceRoot":"","sources":["../../src/utils/validation-path.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACpE,IAAI,KAAK,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,kBAAkB,GAAI,KAAK,CAAC,MAA4C,CAAC,kBAAkB,CAAC;QAClG,MAAM,gBAAgB,GAAG,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,gBAAgB,EAAE,CAAC;YACtB,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YAC3E,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,gBAAgB,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC;QACxE,CAAC;IACF,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvE,OAAO,IAAI,IAAI,MAAM,CAAC;AACvB,CAAC","sourcesContent":["import type { TLocalizedValidationError } from \"typebox/error\";\n\n/** Format a TypeBox validation location consistently across package boundaries. */\nexport function formatValidationPath(error: TLocalizedValidationError): string {\n\tif (error.keyword === \"required\") {\n\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\tconst requiredProperty = requiredProperties?.[0];\n\t\tif (requiredProperty) {\n\t\t\tconst basePath = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\t\t\treturn basePath ? `${basePath}.${requiredProperty}` : requiredProperty;\n\t\t}\n\t}\n\tconst path = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\treturn path || \"root\";\n}\n"]}
1
+ {"version":3,"file":"validation-path.js","sourceRoot":"","sources":["../../src/utils/validation-path.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACpE,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC3E,IAAI,KAAK,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,kBAAkB,GAAI,KAAK,CAAC,MAA4C,CAAC,kBAAkB,CAAC;QAClG,MAAM,gBAAgB,GAAG,kBAAkB,EAAE,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,gBAAgB,EAAE,CAAC;YACtB,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,gBAAgB,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC;QACxE,CAAC;IACF,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,KAAK,sBAAsB,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,MAA0E,CAAC;QAChG,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,IAAI,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,CAAC;QACzF,IAAI,kBAAkB,EAAE,CAAC;YACxB,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,kBAAkB,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC;QAC5E,CAAC;IACF,CAAC;IACD,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC3B,CAAC","sourcesContent":["import type { TLocalizedValidationError } from \"typebox/error\";\n\n/** Format a TypeBox validation location consistently across package boundaries. */\nexport function formatValidationPath(error: TLocalizedValidationError): string {\n\tconst basePath = error.instancePath.replace(/^\\//, \"\").replace(/\\//g, \".\");\n\tif (error.keyword === \"required\") {\n\t\tconst requiredProperties = (error.params as { requiredProperties?: string[] }).requiredProperties;\n\t\tconst requiredProperty = requiredProperties?.[0];\n\t\tif (requiredProperty) {\n\t\t\treturn basePath ? `${basePath}.${requiredProperty}` : requiredProperty;\n\t\t}\n\t}\n\tif (error.keyword === \"additionalProperties\") {\n\t\tconst params = error.params as { additionalProperty?: string; additionalProperties?: string[] };\n\t\tconst additionalProperty = params.additionalProperty ?? params.additionalProperties?.[0];\n\t\tif (additionalProperty) {\n\t\t\treturn basePath ? `${basePath}.${additionalProperty}` : additionalProperty;\n\t\t}\n\t}\n\treturn basePath || \"root\";\n}\n"]}
@@ -156,7 +156,7 @@ function formatFailureShape(errors, args, schema) {
156
156
  const value = receivedValueAtPath(args, pathSegments);
157
157
  const entry = {
158
158
  path,
159
- expectedType: expectedTypeOf(expectedSchema),
159
+ expectedType: error.keyword === "additionalProperties" ? "forbidden" : expectedTypeOf(expectedSchema),
160
160
  receivedType: receivedTypeOf(value),
161
161
  keyword: error.keyword,
162
162
  };
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EACN,oBAAoB,GAGpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,cAAc,GAAG,IAAI,OAAO,EAAsC,CAAC;AACzE,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAmCxC,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAKrD,YAAY,OAAe,EAAE,OAAoE;QAChG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CA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;KAC5C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Compile } from \"typebox/compile\";\nimport type { TLocalizedValidationError } from \"typebox/error\";\nimport type { Tool, ToolCall } from \"../types.ts\";\nimport { analyzeToolArgumentErrors } from \"./tool-repair/analyzer.ts\";\nimport {\n\tformatToolRepairNote,\n\ttype ToolRepairFailureModeName,\n\ttype ToolRepairModeName,\n} from \"./tool-repair/registry.ts\";\nimport { repairToolArguments } from \"./tool-repair/repairer.ts\";\nimport { formatValidationPath } from \"./validation-path.ts\";\n\nconst validatorCache = new WeakMap<object, ReturnType<typeof Compile>>();\nconst EXPECTED_FRAGMENT_MAX_LENGTH = 320;\nconst RECEIVED_VALUE_MAX_LENGTH = 200;\nconst MISSING_VALUE = Symbol(\"missing\");\n\nexport type ToolArgumentValidationOutcome = \"clean\" | \"repaired\" | \"bounced\";\nexport type ToolArgumentTeachState = \"none\" | \"note\" | \"rule\";\nexport type ToolArgumentExecutionOutcome = \"not_run\" | \"succeeded\" | \"failed\";\n\nexport interface ToolArgumentFailureShapeEntry {\n\tpath: string;\n\texpectedType: string;\n\treceivedType: string;\n\tkeyword?: string;\n}\n\nexport interface ToolArgumentValidationTelemetryEvent {\n\toutcome: ToolArgumentValidationOutcome;\n\tprovider?: string;\n\tmodel?: string;\n\ttool: string;\n\tsource?: ToolCall[\"source\"];\n\tfailureModes: ToolRepairFailureModeName[];\n\trepairsApplied: ToolRepairModeName[];\n\tfailureShape?: ToolArgumentFailureShapeEntry[];\n\terrorKeywords?: string[];\n\ttaught: ToolArgumentTeachState;\n\texecutionOutcome: ToolArgumentExecutionOutcome;\n}\n\nexport interface ToolArgumentValidationOptions {\n\tmodel?: string;\n\tprovider?: string;\n\ttelemetry?: (event: ToolArgumentValidationTelemetryEvent) => void;\n\t/** Internal emergency diagnostic kill; user settings do not disable deterministic repair. */\n\trepairEnabled?: boolean;\n}\n\nexport class ToolArgumentValidationError extends Error {\n\tpublic readonly toolName: string;\n\tpublic readonly signature: string;\n\tpublic readonly enrichment: string;\n\n\tconstructor(message: string, options: { toolName: string; signature: string; enrichment: string }) {\n\t\tsuper(message);\n\t\tthis.name = \"ToolArgumentValidationError\";\n\t\tthis.toolName = options.toolName;\n\t\tthis.signature = options.signature;\n\t\tthis.enrichment = options.enrichment;\n\t}\n}\n\nfunction emitToolArgumentValidationTelemetry(\n\toptions: ToolArgumentValidationOptions | undefined,\n\tevent: Omit<ToolArgumentValidationTelemetryEvent, \"model\" | \"provider\" | \"taught\" | \"executionOutcome\">,\n): void {\n\ttry {\n\t\toptions?.telemetry?.({\n\t\t\t...event,\n\t\t\tmodel: options.model,\n\t\t\tprovider: options.provider,\n\t\t\ttaught: \"none\",\n\t\t\texecutionOutcome: \"not_run\",\n\t\t});\n\t} catch {\n\t\t// Telemetry is observe-only; never fail validation because a sink failed.\n\t}\n}\n\nfunction uniqueRepairModes(modes: Iterable<ToolRepairModeName>): ToolRepairModeName[] {\n\treturn [...new Set(modes)];\n}\n\nfunction uniqueFailureModes(modes: Iterable<ToolRepairModeName>): ToolRepairFailureModeName[] {\n\tconst uniqueModes = uniqueRepairModes(modes);\n\treturn uniqueModes.length > 0 ? uniqueModes : [\"other\"];\n}\n\n/**\n * Compiles (and caches) the TypeBox validator for a tool's parameter schema.\n *\n * This is the ONE validator compile-cache for the repair layer (decision D3, tool-call-repair\n * doctrine): `repairer.ts` imports this instead of keeping a second cache over the same schema\n * objects, so a schema is compiled once and both the validate and repair paths share the result.\n */\nexport function getValidator(schema: Tool[\"parameters\"]): ReturnType<typeof Compile> {\n\tconst key = schema as object;\n\tconst cached = validatorCache.get(key);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\tconst validator = Compile(schema);\n\tvalidatorCache.set(key, validator);\n\treturn validator;\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction truncateText(text: string, maxLength: number): string {\n\tif (text.length <= maxLength) {\n\t\treturn text;\n\t}\n\treturn `${text.slice(0, maxLength)}...[truncated]`;\n}\n\nfunction formatCompactJson(value: unknown, maxLength: number): string {\n\tif (value === MISSING_VALUE) {\n\t\treturn \"<missing>\";\n\t}\n\tif (value === undefined) {\n\t\treturn \"undefined\";\n\t}\n\treturn truncateText(JSON.stringify(value), maxLength);\n}\n\nfunction validationPathSegments(error: TLocalizedValidationError): string[] {\n\tconst path = formatValidationPath(error);\n\treturn path === \"root\" ? [] : path.split(\".\");\n}\n\nfunction schemaAtPath(schema: unknown, pathSegments: readonly string[]): unknown {\n\tlet current: unknown = schema;\n\tfor (const segment of pathSegments) {\n\t\tconst record = asRecord(current);\n\t\tif (!record) {\n\t\t\treturn current;\n\t\t}\n\n\t\tconst properties = asRecord(record.properties);\n\t\tif (properties && segment in properties) {\n\t\t\tcurrent = properties[segment];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (record.items !== undefined) {\n\t\t\tcurrent = record.items;\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn current;\n\t}\n\treturn current;\n}\n\nfunction receivedValueAtPath(args: unknown, pathSegments: readonly string[]): unknown {\n\tlet current: unknown = args;\n\tfor (const segment of pathSegments) {\n\t\tconst record = asRecord(current);\n\t\tif (record) {\n\t\t\tif (!(segment in record)) {\n\t\t\t\treturn MISSING_VALUE;\n\t\t\t}\n\t\t\tcurrent = record[segment];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(current)) {\n\t\t\tconst index = Number(segment);\n\t\t\tif (!Number.isInteger(index) || index < 0 || index >= current.length) {\n\t\t\t\treturn MISSING_VALUE;\n\t\t\t}\n\t\t\tcurrent = current[index];\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn MISSING_VALUE;\n\t}\n\treturn current;\n}\n\nfunction receivedTypeOf(value: unknown): string {\n\tif (value === MISSING_VALUE) return \"missing\";\n\tif (value === null) return \"null\";\n\tif (Array.isArray(value)) return \"array\";\n\treturn typeof value;\n}\n\nfunction expectedTypeOf(schema: unknown): string {\n\tconst record = asRecord(schema);\n\tif (!record) return \"unknown\";\n\tif (Array.isArray(record.type)) return record.type.filter((type) => typeof type === \"string\").join(\"|\") || \"unknown\";\n\tif (typeof record.type === \"string\") return record.type;\n\tif (literalValues(record)) return \"enum\";\n\tif (record.properties !== undefined) return \"object\";\n\tif (record.items !== undefined) return \"array\";\n\treturn \"unknown\";\n}\n\nfunction formatFailureShape(\n\terrors: readonly TLocalizedValidationError[],\n\targs: unknown,\n\tschema: unknown,\n): ToolArgumentFailureShapeEntry[] {\n\tconst seen = new Set<string>();\n\tconst shape: ToolArgumentFailureShapeEntry[] = [];\n\tfor (const error of errors) {\n\t\tconst path = formatValidationPath(error);\n\t\tconst pathSegments = path === \"root\" ? [] : path.split(\".\");\n\t\tconst expectedSchema = schemaAtPath(schema, pathSegments);\n\t\tconst value = receivedValueAtPath(args, pathSegments);\n\t\tconst entry = {\n\t\t\tpath,\n\t\t\texpectedType: expectedTypeOf(expectedSchema),\n\t\t\treceivedType: receivedTypeOf(value),\n\t\t\tkeyword: error.keyword,\n\t\t};\n\t\tconst key = `${entry.path}\\0${entry.expectedType}\\0${entry.receivedType}\\0${entry.keyword}`;\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tshape.push(entry);\n\t}\n\treturn shape;\n}\n\nfunction errorKeywords(errors: readonly TLocalizedValidationError[]): string[] {\n\treturn [...new Set(errors.map((error) => error.keyword))].sort();\n}\n\nfunction literalValues(schema: unknown): unknown[] | undefined {\n\tconst record = asRecord(schema);\n\tif (!record) {\n\t\treturn undefined;\n\t}\n\tif (Array.isArray(record.enum)) {\n\t\treturn record.enum;\n\t}\n\tif (record.const !== undefined) {\n\t\treturn [record.const];\n\t}\n\tconst anyOf = Array.isArray(record.anyOf) ? record.anyOf : Array.isArray(record.oneOf) ? record.oneOf : undefined;\n\tif (anyOf) {\n\t\tconst values: unknown[] = [];\n\t\tfor (const option of anyOf) {\n\t\t\tconst optionRecord = asRecord(option);\n\t\t\tif (!optionRecord || optionRecord.const === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tvalues.push(optionRecord.const);\n\t\t}\n\t\treturn values;\n\t}\n\treturn undefined;\n}\n\nfunction compactSchemaFragment(schema: unknown): Record<string, unknown> {\n\tconst record = asRecord(schema);\n\tif (!record) {\n\t\treturn {};\n\t}\n\n\tconst fragment: Record<string, unknown> = {};\n\tconst values = literalValues(record);\n\tif (values) {\n\t\tfragment.enum = values;\n\t\treturn fragment;\n\t}\n\n\tfor (const key of [\"type\", \"required\", \"minimum\", \"maximum\", \"minLength\", \"maxLength\", \"format\"] as const) {\n\t\tif (record[key] !== undefined) {\n\t\t\tfragment[key] = record[key];\n\t\t}\n\t}\n\n\tconst properties = asRecord(record.properties);\n\tif (properties) {\n\t\tfragment.properties = Object.keys(properties);\n\t}\n\tif (record.items !== undefined) {\n\t\tfragment.items = compactSchemaFragment(record.items);\n\t}\n\treturn fragment;\n}\n\nfunction minimalExample(schema: unknown): unknown {\n\tconst record = asRecord(schema);\n\tif (!record) {\n\t\treturn undefined;\n\t}\n\tif (record.default !== undefined) {\n\t\treturn record.default;\n\t}\n\tconst values = literalValues(record);\n\tif (values?.length) {\n\t\treturn values[0];\n\t}\n\n\tconst type = Array.isArray(record.type) ? record.type[0] : record.type;\n\tswitch (type) {\n\t\tcase \"string\":\n\t\t\treturn \"\";\n\t\tcase \"number\":\n\t\t\treturn typeof record.minimum === \"number\" ? record.minimum : 0;\n\t\tcase \"integer\":\n\t\t\treturn typeof record.minimum === \"number\" ? Math.ceil(record.minimum) : 0;\n\t\tcase \"boolean\":\n\t\t\treturn true;\n\t\tcase \"array\":\n\t\t\treturn [];\n\t\tcase \"object\": {\n\t\t\tconst properties = asRecord(record.properties) ?? {};\n\t\t\tconst required = Array.isArray(record.required)\n\t\t\t\t? record.required.filter((key) => typeof key === \"string\")\n\t\t\t\t: [];\n\t\t\treturn Object.fromEntries(required.map((key) => [key, minimalExample(properties[key]) ?? null]));\n\t\t}\n\t\tcase \"null\":\n\t\t\treturn null;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nfunction formatValidationErrors(errors: readonly TLocalizedValidationError[], args: unknown, schema: unknown): string {\n\treturn (\n\t\terrors\n\t\t\t.map((error) => {\n\t\t\t\tconst path = formatValidationPath(error);\n\t\t\t\tconst pathSegments = validationPathSegments(error);\n\t\t\t\tconst expectedSchema = schemaAtPath(schema, pathSegments);\n\t\t\t\tconst expectedFragment = formatCompactJson(\n\t\t\t\t\tcompactSchemaFragment(expectedSchema),\n\t\t\t\t\tEXPECTED_FRAGMENT_MAX_LENGTH,\n\t\t\t\t);\n\t\t\t\tconst example = minimalExample(expectedSchema);\n\t\t\t\tconst received = formatCompactJson(receivedValueAtPath(args, pathSegments), RECEIVED_VALUE_MAX_LENGTH);\n\t\t\t\tconst exampleText =\n\t\t\t\t\texample === undefined ? \"\" : `; Example: ${formatCompactJson(example, RECEIVED_VALUE_MAX_LENGTH)}`;\n\t\t\t\treturn ` - ${path}: ${error.message}; Expected schema: ${expectedFragment}${exampleText}; Received: ${received}`;\n\t\t\t})\n\t\t\t.join(\"\\n\") || \"Unknown validation error\"\n\t);\n}\n\nfunction validationFailureSignature(errors: readonly TLocalizedValidationError[]): string {\n\treturn JSON.stringify(\n\t\terrors.map((error) => ({\n\t\t\tpath: formatValidationPath(error),\n\t\t\tkeyword: error.keyword,\n\t\t\tmessage: error.message,\n\t\t})),\n\t);\n}\n\nfunction formatValidationEnrichment(tool: Tool): string {\n\tconst example = minimalExample(tool.parameters);\n\tconst exampleText = example === undefined ? \"\" : `\\nValid example:\\n${formatCompactJson(example, 2000)}`;\n\treturn `Full tool schema:\\n${formatCompactJson(tool.parameters, 4000)}${exampleText}`;\n}\n\n/**\n * Finds a tool by name and validates the tool call arguments against its TypeBox schema\n * @param tools Array of tool definitions\n * @param toolCall The tool call from the LLM\n * @returns The validated arguments\n * @throws Error if tool is not found or validation fails\n */\nexport function validateToolCall(\n\ttools: Tool[],\n\ttoolCall: ToolCall,\n\toptions?: ToolArgumentValidationOptions,\n): Record<string, unknown> {\n\tconst tool = tools.find((t) => t.name === toolCall.name);\n\tif (!tool) {\n\t\tthrow new Error(`Tool \"${toolCall.name}\" not found`);\n\t}\n\treturn validateToolArguments(tool, toolCall, options);\n}\n\n/**\n * Validates tool call arguments against the tool's TypeBox schema.\n *\n * The hot path is validate-first and allocation-free: valid arguments return the exact\n * argument object emitted by the model. Only invalid calls enter the deterministic\n * repair layer, which applies named, guard-checked shape repairs on a clone.\n *\n * @param tool The tool definition with TypeBox schema\n * @param toolCall The tool call from the LLM\n * @returns The validated (and potentially repaired) arguments\n * @throws Error with formatted message if validation fails\n */\nexport function validateToolArguments(\n\ttool: Tool,\n\ttoolCall: ToolCall,\n\toptions?: ToolArgumentValidationOptions,\n): Record<string, unknown> {\n\tconst args = toolCall.arguments;\n\tconst validator = getValidator(tool.parameters);\n\n\tif (validator.Check(args)) {\n\t\treturn args;\n\t}\n\n\tconst validationErrors = [...validator.Errors(args)] as TLocalizedValidationError[];\n\tconst repairIssues = analyzeToolArgumentErrors(toolCall.name, tool.parameters, args, validationErrors);\n\tconst failureModes = uniqueFailureModes(repairIssues.flatMap((issue) => issue.modes));\n\tconst repaired =\n\t\toptions?.repairEnabled === false\n\t\t\t? undefined\n\t\t\t: repairToolArguments(toolCall.name, tool.parameters, args, validationErrors, (candidate) =>\n\t\t\t\t\tvalidator.Check(candidate),\n\t\t\t\t);\n\tif (repaired) {\n\t\tconst repairsApplied = uniqueRepairModes(repaired.repairsApplied);\n\t\ttoolCall.repairNotes = repaired.repairs.map(\n\t\t\t(repair) =>\n\t\t\t\t`[harness] ${repair.name}: ${formatToolRepairNote(repair.name, repair.path)}; executed with repaired arguments.`,\n\t\t);\n\t\temitToolArgumentValidationTelemetry(options, {\n\t\t\toutcome: \"repaired\",\n\t\t\ttool: toolCall.name,\n\t\t\tsource: toolCall.source,\n\t\t\tfailureModes,\n\t\t\trepairsApplied,\n\t\t});\n\t\treturn repaired.args;\n\t}\n\n\temitToolArgumentValidationTelemetry(options, {\n\t\toutcome: \"bounced\",\n\t\ttool: toolCall.name,\n\t\tsource: toolCall.source,\n\t\tfailureModes,\n\t\trepairsApplied: [],\n\t\tfailureShape: formatFailureShape(validationErrors, toolCall.arguments, tool.parameters),\n\t\terrorKeywords: errorKeywords(validationErrors),\n\t});\n\n\tconst errorMessage = `Validation failed for tool \"${toolCall.name}\":\\n${formatValidationErrors(\n\t\tvalidationErrors,\n\t\ttoolCall.arguments,\n\t\ttool.parameters,\n\t)}\\n\\nReceived arguments:\\n${truncateText(JSON.stringify(toolCall.arguments, null, 2), 2000)}`;\n\n\tthrow new ToolArgumentValidationError(errorMessage, {\n\t\ttoolName: toolCall.name,\n\t\tsignature: validationFailureSignature(validationErrors),\n\t\tenrichment: formatValidationEnrichment(tool),\n\t});\n}\n"]}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EACN,oBAAoB,GAGpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,cAAc,GAAG,IAAI,OAAO,EAAsC,CAAC;AACzE,MAAM,4BAA4B,GAAG,GAAG,CAAC;AACzC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AACtC,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAmCxC,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAKrD,YAAY,OAAe,EAAE,OAAoE;QAChG,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC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,SAAS,EAAE,0BAA0B,CAAC,gBAAgB,CAAC;QACvD,UAAU,EAAE,0BAA0B,CAAC,IAAI,CAAC;KAC5C,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Compile } from \"typebox/compile\";\nimport type { TLocalizedValidationError } from \"typebox/error\";\nimport type { Tool, ToolCall } from \"../types.ts\";\nimport { analyzeToolArgumentErrors } from \"./tool-repair/analyzer.ts\";\nimport {\n\tformatToolRepairNote,\n\ttype ToolRepairFailureModeName,\n\ttype ToolRepairModeName,\n} from \"./tool-repair/registry.ts\";\nimport { repairToolArguments } from \"./tool-repair/repairer.ts\";\nimport { formatValidationPath } from \"./validation-path.ts\";\n\nconst validatorCache = new WeakMap<object, ReturnType<typeof Compile>>();\nconst EXPECTED_FRAGMENT_MAX_LENGTH = 320;\nconst RECEIVED_VALUE_MAX_LENGTH = 200;\nconst MISSING_VALUE = Symbol(\"missing\");\n\nexport type ToolArgumentValidationOutcome = \"clean\" | \"repaired\" | \"bounced\";\nexport type ToolArgumentTeachState = \"none\" | \"note\" | \"rule\";\nexport type ToolArgumentExecutionOutcome = \"not_run\" | \"succeeded\" | \"failed\";\n\nexport interface ToolArgumentFailureShapeEntry {\n\tpath: string;\n\texpectedType: string;\n\treceivedType: string;\n\tkeyword?: string;\n}\n\nexport interface ToolArgumentValidationTelemetryEvent {\n\toutcome: ToolArgumentValidationOutcome;\n\tprovider?: string;\n\tmodel?: string;\n\ttool: string;\n\tsource?: ToolCall[\"source\"];\n\tfailureModes: ToolRepairFailureModeName[];\n\trepairsApplied: ToolRepairModeName[];\n\tfailureShape?: ToolArgumentFailureShapeEntry[];\n\terrorKeywords?: string[];\n\ttaught: ToolArgumentTeachState;\n\texecutionOutcome: ToolArgumentExecutionOutcome;\n}\n\nexport interface ToolArgumentValidationOptions {\n\tmodel?: string;\n\tprovider?: string;\n\ttelemetry?: (event: ToolArgumentValidationTelemetryEvent) => void;\n\t/** Internal emergency diagnostic kill; user settings do not disable deterministic repair. */\n\trepairEnabled?: boolean;\n}\n\nexport class ToolArgumentValidationError extends Error {\n\tpublic readonly toolName: string;\n\tpublic readonly signature: string;\n\tpublic readonly enrichment: string;\n\n\tconstructor(message: string, options: { toolName: string; signature: string; enrichment: string }) {\n\t\tsuper(message);\n\t\tthis.name = \"ToolArgumentValidationError\";\n\t\tthis.toolName = options.toolName;\n\t\tthis.signature = options.signature;\n\t\tthis.enrichment = options.enrichment;\n\t}\n}\n\nfunction emitToolArgumentValidationTelemetry(\n\toptions: ToolArgumentValidationOptions | undefined,\n\tevent: Omit<ToolArgumentValidationTelemetryEvent, \"model\" | \"provider\" | \"taught\" | \"executionOutcome\">,\n): void {\n\ttry {\n\t\toptions?.telemetry?.({\n\t\t\t...event,\n\t\t\tmodel: options.model,\n\t\t\tprovider: options.provider,\n\t\t\ttaught: \"none\",\n\t\t\texecutionOutcome: \"not_run\",\n\t\t});\n\t} catch {\n\t\t// Telemetry is observe-only; never fail validation because a sink failed.\n\t}\n}\n\nfunction uniqueRepairModes(modes: Iterable<ToolRepairModeName>): ToolRepairModeName[] {\n\treturn [...new Set(modes)];\n}\n\nfunction uniqueFailureModes(modes: Iterable<ToolRepairModeName>): ToolRepairFailureModeName[] {\n\tconst uniqueModes = uniqueRepairModes(modes);\n\treturn uniqueModes.length > 0 ? uniqueModes : [\"other\"];\n}\n\n/**\n * Compiles (and caches) the TypeBox validator for a tool's parameter schema.\n *\n * This is the ONE validator compile-cache for the repair layer (decision D3, tool-call-repair\n * doctrine): `repairer.ts` imports this instead of keeping a second cache over the same schema\n * objects, so a schema is compiled once and both the validate and repair paths share the result.\n */\nexport function getValidator(schema: Tool[\"parameters\"]): ReturnType<typeof Compile> {\n\tconst key = schema as object;\n\tconst cached = validatorCache.get(key);\n\tif (cached) {\n\t\treturn cached;\n\t}\n\tconst validator = Compile(schema);\n\tvalidatorCache.set(key, validator);\n\treturn validator;\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value)\n\t\t? (value as Record<string, unknown>)\n\t\t: undefined;\n}\n\nfunction truncateText(text: string, maxLength: number): string {\n\tif (text.length <= maxLength) {\n\t\treturn text;\n\t}\n\treturn `${text.slice(0, maxLength)}...[truncated]`;\n}\n\nfunction formatCompactJson(value: unknown, maxLength: number): string {\n\tif (value === MISSING_VALUE) {\n\t\treturn \"<missing>\";\n\t}\n\tif (value === undefined) {\n\t\treturn \"undefined\";\n\t}\n\treturn truncateText(JSON.stringify(value), maxLength);\n}\n\nfunction validationPathSegments(error: TLocalizedValidationError): string[] {\n\tconst path = formatValidationPath(error);\n\treturn path === \"root\" ? [] : path.split(\".\");\n}\n\nfunction schemaAtPath(schema: unknown, pathSegments: readonly string[]): unknown {\n\tlet current: unknown = schema;\n\tfor (const segment of pathSegments) {\n\t\tconst record = asRecord(current);\n\t\tif (!record) {\n\t\t\treturn current;\n\t\t}\n\n\t\tconst properties = asRecord(record.properties);\n\t\tif (properties && segment in properties) {\n\t\t\tcurrent = properties[segment];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (record.items !== undefined) {\n\t\t\tcurrent = record.items;\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn current;\n\t}\n\treturn current;\n}\n\nfunction receivedValueAtPath(args: unknown, pathSegments: readonly string[]): unknown {\n\tlet current: unknown = args;\n\tfor (const segment of pathSegments) {\n\t\tconst record = asRecord(current);\n\t\tif (record) {\n\t\t\tif (!(segment in record)) {\n\t\t\t\treturn MISSING_VALUE;\n\t\t\t}\n\t\t\tcurrent = record[segment];\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (Array.isArray(current)) {\n\t\t\tconst index = Number(segment);\n\t\t\tif (!Number.isInteger(index) || index < 0 || index >= current.length) {\n\t\t\t\treturn MISSING_VALUE;\n\t\t\t}\n\t\t\tcurrent = current[index];\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn MISSING_VALUE;\n\t}\n\treturn current;\n}\n\nfunction receivedTypeOf(value: unknown): string {\n\tif (value === MISSING_VALUE) return \"missing\";\n\tif (value === null) return \"null\";\n\tif (Array.isArray(value)) return \"array\";\n\treturn typeof value;\n}\n\nfunction expectedTypeOf(schema: unknown): string {\n\tconst record = asRecord(schema);\n\tif (!record) return \"unknown\";\n\tif (Array.isArray(record.type)) return record.type.filter((type) => typeof type === \"string\").join(\"|\") || \"unknown\";\n\tif (typeof record.type === \"string\") return record.type;\n\tif (literalValues(record)) return \"enum\";\n\tif (record.properties !== undefined) return \"object\";\n\tif (record.items !== undefined) return \"array\";\n\treturn \"unknown\";\n}\n\nfunction formatFailureShape(\n\terrors: readonly TLocalizedValidationError[],\n\targs: unknown,\n\tschema: unknown,\n): ToolArgumentFailureShapeEntry[] {\n\tconst seen = new Set<string>();\n\tconst shape: ToolArgumentFailureShapeEntry[] = [];\n\tfor (const error of errors) {\n\t\tconst path = formatValidationPath(error);\n\t\tconst pathSegments = path === \"root\" ? [] : path.split(\".\");\n\t\tconst expectedSchema = schemaAtPath(schema, pathSegments);\n\t\tconst value = receivedValueAtPath(args, pathSegments);\n\t\tconst entry = {\n\t\t\tpath,\n\t\t\texpectedType: error.keyword === \"additionalProperties\" ? \"forbidden\" : expectedTypeOf(expectedSchema),\n\t\t\treceivedType: receivedTypeOf(value),\n\t\t\tkeyword: error.keyword,\n\t\t};\n\t\tconst key = `${entry.path}\\0${entry.expectedType}\\0${entry.receivedType}\\0${entry.keyword}`;\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tshape.push(entry);\n\t}\n\treturn shape;\n}\n\nfunction errorKeywords(errors: readonly TLocalizedValidationError[]): string[] {\n\treturn [...new Set(errors.map((error) => error.keyword))].sort();\n}\n\nfunction literalValues(schema: unknown): unknown[] | undefined {\n\tconst record = asRecord(schema);\n\tif (!record) {\n\t\treturn undefined;\n\t}\n\tif (Array.isArray(record.enum)) {\n\t\treturn record.enum;\n\t}\n\tif (record.const !== undefined) {\n\t\treturn [record.const];\n\t}\n\tconst anyOf = Array.isArray(record.anyOf) ? record.anyOf : Array.isArray(record.oneOf) ? record.oneOf : undefined;\n\tif (anyOf) {\n\t\tconst values: unknown[] = [];\n\t\tfor (const option of anyOf) {\n\t\t\tconst optionRecord = asRecord(option);\n\t\t\tif (!optionRecord || optionRecord.const === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tvalues.push(optionRecord.const);\n\t\t}\n\t\treturn values;\n\t}\n\treturn undefined;\n}\n\nfunction compactSchemaFragment(schema: unknown): Record<string, unknown> {\n\tconst record = asRecord(schema);\n\tif (!record) {\n\t\treturn {};\n\t}\n\n\tconst fragment: Record<string, unknown> = {};\n\tconst values = literalValues(record);\n\tif (values) {\n\t\tfragment.enum = values;\n\t\treturn fragment;\n\t}\n\n\tfor (const key of [\"type\", \"required\", \"minimum\", \"maximum\", \"minLength\", \"maxLength\", \"format\"] as const) {\n\t\tif (record[key] !== undefined) {\n\t\t\tfragment[key] = record[key];\n\t\t}\n\t}\n\n\tconst properties = asRecord(record.properties);\n\tif (properties) {\n\t\tfragment.properties = Object.keys(properties);\n\t}\n\tif (record.items !== undefined) {\n\t\tfragment.items = compactSchemaFragment(record.items);\n\t}\n\treturn fragment;\n}\n\nfunction minimalExample(schema: unknown): unknown {\n\tconst record = asRecord(schema);\n\tif (!record) {\n\t\treturn undefined;\n\t}\n\tif (record.default !== undefined) {\n\t\treturn record.default;\n\t}\n\tconst values = literalValues(record);\n\tif (values?.length) {\n\t\treturn values[0];\n\t}\n\n\tconst type = Array.isArray(record.type) ? record.type[0] : record.type;\n\tswitch (type) {\n\t\tcase \"string\":\n\t\t\treturn \"\";\n\t\tcase \"number\":\n\t\t\treturn typeof record.minimum === \"number\" ? record.minimum : 0;\n\t\tcase \"integer\":\n\t\t\treturn typeof record.minimum === \"number\" ? Math.ceil(record.minimum) : 0;\n\t\tcase \"boolean\":\n\t\t\treturn true;\n\t\tcase \"array\":\n\t\t\treturn [];\n\t\tcase \"object\": {\n\t\t\tconst properties = asRecord(record.properties) ?? {};\n\t\t\tconst required = Array.isArray(record.required)\n\t\t\t\t? record.required.filter((key) => typeof key === \"string\")\n\t\t\t\t: [];\n\t\t\treturn Object.fromEntries(required.map((key) => [key, minimalExample(properties[key]) ?? null]));\n\t\t}\n\t\tcase \"null\":\n\t\t\treturn null;\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nfunction formatValidationErrors(errors: readonly TLocalizedValidationError[], args: unknown, schema: unknown): string {\n\treturn (\n\t\terrors\n\t\t\t.map((error) => {\n\t\t\t\tconst path = formatValidationPath(error);\n\t\t\t\tconst pathSegments = validationPathSegments(error);\n\t\t\t\tconst expectedSchema = schemaAtPath(schema, pathSegments);\n\t\t\t\tconst expectedFragment = formatCompactJson(\n\t\t\t\t\tcompactSchemaFragment(expectedSchema),\n\t\t\t\t\tEXPECTED_FRAGMENT_MAX_LENGTH,\n\t\t\t\t);\n\t\t\t\tconst example = minimalExample(expectedSchema);\n\t\t\t\tconst received = formatCompactJson(receivedValueAtPath(args, pathSegments), RECEIVED_VALUE_MAX_LENGTH);\n\t\t\t\tconst exampleText =\n\t\t\t\t\texample === undefined ? \"\" : `; Example: ${formatCompactJson(example, RECEIVED_VALUE_MAX_LENGTH)}`;\n\t\t\t\treturn ` - ${path}: ${error.message}; Expected schema: ${expectedFragment}${exampleText}; Received: ${received}`;\n\t\t\t})\n\t\t\t.join(\"\\n\") || \"Unknown validation error\"\n\t);\n}\n\nfunction validationFailureSignature(errors: readonly TLocalizedValidationError[]): string {\n\treturn JSON.stringify(\n\t\terrors.map((error) => ({\n\t\t\tpath: formatValidationPath(error),\n\t\t\tkeyword: error.keyword,\n\t\t\tmessage: error.message,\n\t\t})),\n\t);\n}\n\nfunction formatValidationEnrichment(tool: Tool): string {\n\tconst example = minimalExample(tool.parameters);\n\tconst exampleText = example === undefined ? \"\" : `\\nValid example:\\n${formatCompactJson(example, 2000)}`;\n\treturn `Full tool schema:\\n${formatCompactJson(tool.parameters, 4000)}${exampleText}`;\n}\n\n/**\n * Finds a tool by name and validates the tool call arguments against its TypeBox schema\n * @param tools Array of tool definitions\n * @param toolCall The tool call from the LLM\n * @returns The validated arguments\n * @throws Error if tool is not found or validation fails\n */\nexport function validateToolCall(\n\ttools: Tool[],\n\ttoolCall: ToolCall,\n\toptions?: ToolArgumentValidationOptions,\n): Record<string, unknown> {\n\tconst tool = tools.find((t) => t.name === toolCall.name);\n\tif (!tool) {\n\t\tthrow new Error(`Tool \"${toolCall.name}\" not found`);\n\t}\n\treturn validateToolArguments(tool, toolCall, options);\n}\n\n/**\n * Validates tool call arguments against the tool's TypeBox schema.\n *\n * The hot path is validate-first and allocation-free: valid arguments return the exact\n * argument object emitted by the model. Only invalid calls enter the deterministic\n * repair layer, which applies named, guard-checked shape repairs on a clone.\n *\n * @param tool The tool definition with TypeBox schema\n * @param toolCall The tool call from the LLM\n * @returns The validated (and potentially repaired) arguments\n * @throws Error with formatted message if validation fails\n */\nexport function validateToolArguments(\n\ttool: Tool,\n\ttoolCall: ToolCall,\n\toptions?: ToolArgumentValidationOptions,\n): Record<string, unknown> {\n\tconst args = toolCall.arguments;\n\tconst validator = getValidator(tool.parameters);\n\n\tif (validator.Check(args)) {\n\t\treturn args;\n\t}\n\n\tconst validationErrors = [...validator.Errors(args)] as TLocalizedValidationError[];\n\tconst repairIssues = analyzeToolArgumentErrors(toolCall.name, tool.parameters, args, validationErrors);\n\tconst failureModes = uniqueFailureModes(repairIssues.flatMap((issue) => issue.modes));\n\tconst repaired =\n\t\toptions?.repairEnabled === false\n\t\t\t? undefined\n\t\t\t: repairToolArguments(toolCall.name, tool.parameters, args, validationErrors, (candidate) =>\n\t\t\t\t\tvalidator.Check(candidate),\n\t\t\t\t);\n\tif (repaired) {\n\t\tconst repairsApplied = uniqueRepairModes(repaired.repairsApplied);\n\t\ttoolCall.repairNotes = repaired.repairs.map(\n\t\t\t(repair) =>\n\t\t\t\t`[harness] ${repair.name}: ${formatToolRepairNote(repair.name, repair.path)}; executed with repaired arguments.`,\n\t\t);\n\t\temitToolArgumentValidationTelemetry(options, {\n\t\t\toutcome: \"repaired\",\n\t\t\ttool: toolCall.name,\n\t\t\tsource: toolCall.source,\n\t\t\tfailureModes,\n\t\t\trepairsApplied,\n\t\t});\n\t\treturn repaired.args;\n\t}\n\n\temitToolArgumentValidationTelemetry(options, {\n\t\toutcome: \"bounced\",\n\t\ttool: toolCall.name,\n\t\tsource: toolCall.source,\n\t\tfailureModes,\n\t\trepairsApplied: [],\n\t\tfailureShape: formatFailureShape(validationErrors, toolCall.arguments, tool.parameters),\n\t\terrorKeywords: errorKeywords(validationErrors),\n\t});\n\n\tconst errorMessage = `Validation failed for tool \"${toolCall.name}\":\\n${formatValidationErrors(\n\t\tvalidationErrors,\n\t\ttoolCall.arguments,\n\t\ttool.parameters,\n\t)}\\n\\nReceived arguments:\\n${truncateText(JSON.stringify(toolCall.arguments, null, 2), 2000)}`;\n\n\tthrow new ToolArgumentValidationError(errorMessage, {\n\t\ttoolName: toolCall.name,\n\t\tsignature: validationFailureSignature(validationErrors),\n\t\tenrichment: formatValidationEnrichment(tool),\n\t});\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caupulican/pi-ai",
3
- "version": "0.90.2",
3
+ "version": "0.90.4",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",