@caupulican/pi-agent-core 0.93.5 → 0.93.7
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.
|
@@ -19,6 +19,8 @@ export interface ToolFailureMemoryRecord {
|
|
|
19
19
|
phase: ToolFailurePhase;
|
|
20
20
|
failureCode: string;
|
|
21
21
|
diagnostic?: string;
|
|
22
|
+
/** Bounded result-scoped harness notice (replay block, circuit state); never displaces the retained diagnostic. */
|
|
23
|
+
note?: string;
|
|
22
24
|
/** Bounded tool-owned source evidence needed to construct a changed operation. */
|
|
23
25
|
evidence?: string;
|
|
24
26
|
correction: string;
|
|
@@ -88,8 +90,8 @@ export declare function rememberToolFailure(tracker: ToolFailureMemoryTracker, t
|
|
|
88
90
|
export declare function clearToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): void;
|
|
89
91
|
export declare function createToolFailureResult(record: ToolFailureMemoryRecord, terminate?: boolean): AgentToolResult<ToolFailureResultDetails>;
|
|
90
92
|
export declare function createRepeatedToolFailureResult(record: ToolFailureMemoryRecord): AgentToolResult<ToolFailureMemoryDetails>;
|
|
91
|
-
export declare function createToolFailureRecoveryExhaustedResult(record: ToolFailureMemoryRecord,
|
|
92
|
-
export declare function createToolFailureOperationExhaustedResult(record: ToolFailureMemoryRecord,
|
|
93
|
+
export declare function createToolFailureRecoveryExhaustedResult(record: ToolFailureMemoryRecord, note: string): AgentToolResult<ToolFailureMemoryDetails>;
|
|
94
|
+
export declare function createToolFailureOperationExhaustedResult(record: ToolFailureMemoryRecord, note: string): AgentToolResult<ToolFailureMemoryDetails>;
|
|
93
95
|
export declare function sanitizeToolFailureContext(messages: AgentMessage[], systemPrompt: string): {
|
|
94
96
|
messages: AgentMessage[];
|
|
95
97
|
systemPrompt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-memory.d.ts","sourceRoot":"","sources":["../src/tool-failure-memory.ts"],"names":[],"mappings":"AAAA,OAAO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B,CAEjG;AAED,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,wBAAwB,EACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,GAAE,gBAA4D,EACnE,QAAQ,CAAC,EAAE,MAAM,GACf,uBAAuB,CA2CzB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAKrG;AAiCD,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,uBAAuB,EAC/B,SAAS,CAAC,EAAE,OAAO,GACjB,eAAe,CAAC,wBAAwB,CAAC,CAuB3C;AAED,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,uBAAuB,GAC7B,eAAe,CAAC,wBAAwB,CAAC,CAqB3C;AAED,wBAAgB,wCAAwC,CACvD,MAAM,EAAE,uBAAuB,EAC/B,IAAI,EAAE,MAAM,GACV,eAAe,CAAC,wBAAwB,CAAC,CAiB3C;AAED,wBAAgB,yCAAyC,CACxD,MAAM,EAAE,uBAAuB,EAC/B,IAAI,EAAE,MAAM,GACV,eAAe,CAAC,wBAAwB,CAAC,CAkB3C;AAcD,wBAAgB,0BAA0B,CACzC,QAAQ,EAAE,YAAY,EAAE,EACxB,YAAY,EAAE,MAAM,GAClB;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAgDpD"}
|
|
@@ -16,8 +16,8 @@ const MAX_ACTIVE_FAILURES = 8;
|
|
|
16
16
|
const MAX_TRACKED_FAILURES = 64;
|
|
17
17
|
const REPAIRABLE_REJECTION_CODES = new Set(["invalid_arguments", "malformed_call", "unknown_tool"]);
|
|
18
18
|
const LEGACY_GENERIC_EXECUTION_CORRECTION = "Change the arguments or approach before retrying; do not resend the unchanged operation.";
|
|
19
|
-
const BLOCKED_REPLAY_CAVEMAN_CORRECTION = "
|
|
20
|
-
const CLOSED_OPERATION_CAVEMAN_CORRECTION = "
|
|
19
|
+
const BLOCKED_REPLAY_CAVEMAN_CORRECTION = "Blocked: this exact operation will not run again this session — change the operation or continue other work.";
|
|
20
|
+
const CLOSED_OPERATION_CAVEMAN_CORRECTION = "Closed: this exact operation was not executed and will not run again this session — use a different operation or continue other work.";
|
|
21
21
|
function truncate(value, maxChars) {
|
|
22
22
|
if (value.length <= maxChars)
|
|
23
23
|
return value;
|
|
@@ -635,6 +635,7 @@ function readFailureRecord(details) {
|
|
|
635
635
|
return undefined;
|
|
636
636
|
}
|
|
637
637
|
const diagnostic = typeof candidate.diagnostic === "string" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;
|
|
638
|
+
const note = typeof candidate.note === "string" ? truncate(candidate.note, MAX_DIAGNOSTIC_CHARS) : undefined;
|
|
638
639
|
const evidence = sanitizeToolFailureEvidence(candidate.evidence);
|
|
639
640
|
const retainedCorrection = typeof candidate.correction === "string" ? truncate(candidate.correction, MAX_CORRECTION_CHARS) : undefined;
|
|
640
641
|
const correction = candidate.state === "failed" && retainedCorrection === LEGACY_GENERIC_EXECUTION_CORRECTION
|
|
@@ -659,6 +660,7 @@ function readFailureRecord(details) {
|
|
|
659
660
|
phase,
|
|
660
661
|
failureCode: boundedFailureCode(candidate.failureCode),
|
|
661
662
|
diagnostic,
|
|
663
|
+
note,
|
|
662
664
|
evidence,
|
|
663
665
|
correction,
|
|
664
666
|
};
|
|
@@ -968,6 +970,7 @@ function formatRecordJson(record, includeOperation = false, evidence = record.ev
|
|
|
968
970
|
...(includeOperation ? { operation: record.operation } : {}),
|
|
969
971
|
failure_code: record.failureCode,
|
|
970
972
|
...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),
|
|
973
|
+
...(record.note ? { note: record.note } : {}),
|
|
971
974
|
...(evidence ? { evidence } : {}),
|
|
972
975
|
...guidance,
|
|
973
976
|
...(record.attemptMemory === "discard" ? { attempt_memory: "discarded" } : {}),
|
|
@@ -998,32 +1001,31 @@ export function createToolFailureResult(record, terminate) {
|
|
|
998
1001
|
};
|
|
999
1002
|
}
|
|
1000
1003
|
export function createRepeatedToolFailureResult(record) {
|
|
1001
|
-
const retainedRecord =
|
|
1002
|
-
|
|
1003
|
-
correction: BLOCKED_REPLAY_CAVEMAN_CORRECTION,
|
|
1004
|
-
};
|
|
1005
|
-
const diagnostic = truncateMiddle(`The unchanged operation was not executed. Unchanged replay blocked after ${record.failureCode}`, MAX_DIAGNOSTIC_CHARS);
|
|
1004
|
+
const retainedRecord = retainBlockedToolFailure(record);
|
|
1005
|
+
const replayNotice = truncateMiddle(`The unchanged operation was not executed. Unchanged replay blocked after ${record.failureCode}`, MAX_DIAGNOSTIC_CHARS);
|
|
1006
1006
|
const blockedResult = createToolFailureResult({
|
|
1007
1007
|
...retainedRecord,
|
|
1008
1008
|
state: "rejected",
|
|
1009
1009
|
failureCode: "repeated_failed_operation",
|
|
1010
|
-
diagnostic
|
|
1011
|
-
|
|
1010
|
+
...(retainedRecord.diagnostic
|
|
1011
|
+
? { note: replayNotice }
|
|
1012
|
+
: { diagnostic: replayNotice, correction: BLOCKED_REPLAY_CAVEMAN_CORRECTION }),
|
|
1012
1013
|
});
|
|
1013
1014
|
return {
|
|
1014
1015
|
...blockedResult,
|
|
1015
|
-
// The visible result
|
|
1016
|
-
// authoritative cause so later blocks do not
|
|
1016
|
+
// The visible result leads with the retained root cause and carries the replay notice as a
|
|
1017
|
+
// note, while retained memory keeps the authoritative cause so later blocks do not
|
|
1018
|
+
// recursively wrap synthetic failures.
|
|
1017
1019
|
details: { piToolFailureMemory: retainedRecord },
|
|
1018
1020
|
};
|
|
1019
1021
|
}
|
|
1020
|
-
export function createToolFailureRecoveryExhaustedResult(record,
|
|
1022
|
+
export function createToolFailureRecoveryExhaustedResult(record, note) {
|
|
1021
1023
|
const retainedRecord = retainBlockedToolFailure(record);
|
|
1022
1024
|
const exhaustedResult = createToolFailureResult({
|
|
1023
1025
|
...retainedRecord,
|
|
1024
1026
|
state: "rejected",
|
|
1025
1027
|
failureCode: "recovery_exhausted",
|
|
1026
|
-
|
|
1028
|
+
note: truncateMiddle(note, MAX_DIAGNOSTIC_CHARS),
|
|
1027
1029
|
correction: "Stop retrying tools in this run. Report the unresolved failure and the user or environment action required to continue.",
|
|
1028
1030
|
}, true);
|
|
1029
1031
|
return {
|
|
@@ -1031,7 +1033,7 @@ export function createToolFailureRecoveryExhaustedResult(record, diagnostic) {
|
|
|
1031
1033
|
details: { piToolFailureMemory: retainedRecord },
|
|
1032
1034
|
};
|
|
1033
1035
|
}
|
|
1034
|
-
export function createToolFailureOperationExhaustedResult(record,
|
|
1036
|
+
export function createToolFailureOperationExhaustedResult(record, note) {
|
|
1035
1037
|
const retainedRecord = {
|
|
1036
1038
|
...retainBlockedToolFailure(record),
|
|
1037
1039
|
correction: CLOSED_OPERATION_CAVEMAN_CORRECTION,
|
|
@@ -1040,7 +1042,7 @@ export function createToolFailureOperationExhaustedResult(record, diagnostic) {
|
|
|
1040
1042
|
...retainedRecord,
|
|
1041
1043
|
state: "rejected",
|
|
1042
1044
|
failureCode: "operation_recovery_exhausted",
|
|
1043
|
-
|
|
1045
|
+
note: truncateMiddle(note, MAX_DIAGNOSTIC_CHARS),
|
|
1044
1046
|
}, false);
|
|
1045
1047
|
return {
|
|
1046
1048
|
...exhaustedResult,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-memory.js","sourceRoot":"","sources":["../src/tool-failure-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,2BAA2B,GAE3B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACN,+CAA+C,EAC/C,oCAAoC,GACpC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,M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,CAAC;QACnD,KAAK,CAAC,IAAI,CACT,gBAAgB,CACf,IAAI,CAAC,SAAS,CAAC;YACd,GAAG,oCAAoC,EAAE;YACzC,YAAY,EAAE,SAAS,CAAC,WAAW;YACnC,aAAa,EAAE,QAAQ,CAAC,mBAAmB,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;YACvE,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,WAAW,EAAE,SAAS,CAAC,UAAU;YACjC,cAAc,EAAE,WAAW;SAC3B,CAAC,CACF,CACD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,GAAG,CAAC;QAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,iCAAiC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/F,MAAM,MAAM,GAAG;QACd,+CAA+C;QAC/C,iCAAiC,WAAW,EAAE;QAC9C,mGAAmG;QACnG,GAAG,KAAK;KACR,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,OAAO;QACN,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM;KACpE,CAAC;AACH,CAAC","sourcesContent":["import {\n\tgetToolExecutionAttemptMemory,\n\tgetToolExecutionErrorPolicy,\n\ttype ToolFailurePhase,\n} from \"@caupulican/pi-ai/tool-repair-registry\";\nimport type { AssistantMessage, ToolResultMessage } from \"@caupulican/pi-ai/types\";\nimport {\n\tMANDATORY_TOOL_FAILURE_RECOVERY_PROTOCOL_PROMPT,\n\tmandatoryToolFailureRecoveryMetadata,\n} from \"./tool-failure-recovery-protocol.ts\";\nimport type { AgentMessage, AgentToolCall, AgentToolResult } from \"./types.ts\";\nimport { sanitizeBinaryOutput } from \"./utils/shell-output.ts\";\n\nconst TOOL_FAILURE_MEMORY_VERSION = 1;\nconst TOOL_FAILURE_DIRECTIVE_VERSION = 1;\nconst TOOL_FAILURE_EXECUTION_KEY = Symbol(\"ToolFailureExecutionKey\");\nconst MAX_OPERATION_CHARS = 240;\nconst MAX_FAILURE_CODE_CHARS = 48;\nconst MAX_DIAGNOSTIC_CHARS = 240;\nconst MAX_CORRECTION_CHARS = 480;\nconst MAX_TOOL_FAILURE_EVIDENCE_CHARS = 1_600;\nconst MAX_ACTIVE_FAILURE_EVIDENCE_CHARS = 2_400;\nconst MAX_TOOL_NAME_CHARS = 64;\nconst TOOL_SIGNATURE_HEX_CHARS = 32;\nconst MAX_ACTIVE_FAILURES = 8;\nconst MAX_TRACKED_FAILURES = 64;\nconst REPAIRABLE_REJECTION_CODES = new Set([\"invalid_arguments\", \"malformed_call\", \"unknown_tool\"]);\nconst LEGACY_GENERIC_EXECUTION_CORRECTION =\n\t\"Change the arguments or approach before retrying; do not resend the unchanged operation.\";\nconst BLOCKED_REPLAY_CAVEMAN_CORRECTION =\n\t\"CAVEMAN MODE - MANDATORY. SAME OPERATION BLOCKED. Do not repeat an unchanged operation. NEVER call it again with the same arguments in this run. This is not a harness loop or failure.\";\nconst CLOSED_OPERATION_CAVEMAN_CORRECTION =\n\t\"CAVEMAN MODE - MANDATORY: OPERATION CLOSED; not executed. Do not repeat an unchanged operation. NEVER call it again with the same arguments in this run. Use a different operation/tool or continue independent work. The recovery guard prevented a loop; this is not harness failure.\";\n\nexport type ToolFailureState = \"failed\" | \"rejected\";\n\nexport interface ToolFailureMemoryRecord {\n\tversion: typeof TOOL_FAILURE_MEMORY_VERSION;\n\tfailureKey: string;\n\t/** Exact identity is process-internal and omitted from serialized failure memory. */\n\treadonly [TOOL_FAILURE_EXECUTION_KEY]?: string;\n\ttool: string;\n\toperation: string;\n\toccurrence: number;\n\tkindMistakes?: number;\n\tmistakeKind?: string;\n\tstate: ToolFailureState;\n\tphase: ToolFailurePhase;\n\tfailureCode: string;\n\tdiagnostic?: string;\n\t/** Bounded tool-owned source evidence needed to construct a changed operation. */\n\tevidence?: string;\n\tcorrection: string;\n\tattemptMemory?: \"discard\";\n}\n\nexport interface ToolFailureMemoryDetails {\n\tpiToolFailureMemory: ToolFailureMemoryRecord;\n}\n\nexport interface ToolFailureDirectiveDetails {\n\tpiToolFailureDirective: {\n\t\tversion: typeof TOOL_FAILURE_DIRECTIVE_VERSION;\n\t\tstate: ToolFailureState;\n\t\tphase: ToolFailurePhase;\n\t\tfailureCode: string;\n\t\tdiagnostic?: string;\n\t\tnextAction: string;\n\t};\n}\n\nexport type ToolFailureResultDetails = ToolFailureMemoryDetails | ToolFailureDirectiveDetails;\n\nexport type ToolFailureMemoryTracker = Map<string, ToolFailureMemoryRecord>;\n\ninterface ToolOperationIdentity {\n\tfailureKey: string;\n\texecutionKey: string;\n\ttool: string;\n\toperation: string;\n}\n\ninterface ActiveFailure {\n\trecord: ToolFailureMemoryRecord;\n\tsequence: number;\n}\n\ninterface FailureContextAnalysis {\n\tmessages: AgentMessage[];\n\tactiveRecords: ToolFailureMemoryRecord[];\n\tactiveDirectives: ToolFailureDirectiveDetails[\"piToolFailureDirective\"][];\n\tkindMistakesSummary: Record<string, number>;\n}\n\nfunction truncate(value: string, maxChars: number): string {\n\tif (value.length <= maxChars) return value;\n\tlet end = maxChars - 1;\n\tconst code = value.charCodeAt(end - 1);\n\tif (code >= 0xd800 && code <= 0xdbff) end--;\n\treturn `${value.slice(0, end)}…`;\n}\n\n/** Normalize and bound tool-owned evidence at every live and persisted ingress. */\nexport function sanitizeToolFailureEvidence(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst sanitized = sanitizeBinaryOutput(value).trim();\n\treturn sanitized ? truncate(sanitized, MAX_TOOL_FAILURE_EVIDENCE_CHARS) : undefined;\n}\n\nfunction truncateMiddle(value: string, maxChars: number): string {\n\tif (value.length <= maxChars) return value;\n\tconst available = maxChars - 1;\n\tlet headEnd = Math.ceil(available / 2);\n\tlet tailStart = value.length - Math.floor(available / 2);\n\tconst headCode = value.charCodeAt(headEnd - 1);\n\tif (headCode >= 0xd800 && headCode <= 0xdbff) headEnd--;\n\tconst tailCode = value.charCodeAt(tailStart);\n\tif (tailCode >= 0xdc00 && tailCode <= 0xdfff) tailStart++;\n\treturn `${value.slice(0, headEnd)}…${value.slice(tailStart)}`;\n}\n\nfunction safeJson(value: unknown): string {\n\ttry {\n\t\treturn JSON.stringify(value) ?? \"null\";\n\t} catch {\n\t\treturn \"[unserializable]\";\n\t}\n}\n\ninterface SignatureHash {\n\tfirst: number;\n\tsecond: number;\n\tthird: number;\n\tfourth: number;\n}\n\nconst VOLATILE_SIGNATURE_PATTERN =\n\t/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|(\\d{4}-\\d{2}-\\d{2}[tT][0-9:.]+(?:z|[+-]\\d{2}:?\\d{2})?)|(\\b[0-9a-f]{16,}\\b)|(\\d{10,})/gi;\nconst MAX_SIGNATURE_DEPTH = 128;\nconst MAX_PREVIEW_DEPTH = 6;\nconst MAX_PREVIEW_ITEMS = 8;\nconst MAX_PREVIEW_STRING_CHARS = 96;\n\nfunction updateHashCode(hash: SignatureHash, code: number): void {\n\thash.first = Math.imul(hash.first ^ code, 0x01000193);\n\thash.second = Math.imul(hash.second ^ code, 0x85ebca6b);\n\thash.third = Math.imul(hash.third ^ code, 0x27d4eb2d);\n\thash.fourth = Math.imul(hash.fourth ^ code, 0x165667b1);\n}\n\nfunction updateHashRange(hash: SignatureHash, value: string, start = 0, end = value.length): void {\n\tfor (let index = start; index < end; index++) updateHashCode(hash, value.charCodeAt(index));\n}\n\nfunction updateNormalizedHashString(hash: SignatureHash, value: string): void {\n\tif (value.length < 10) {\n\t\tupdateExactHashString(hash, value);\n\t\treturn;\n\t}\n\tVOLATILE_SIGNATURE_PATTERN.lastIndex = 0;\n\tlet offset = 0;\n\tlet normalizedLength = value.length;\n\tfor (const match of value.matchAll(VOLATILE_SIGNATURE_PATTERN)) {\n\t\tconst index = match.index;\n\t\tupdateHashRange(hash, value, offset, index);\n\t\tconst replacement = match[1] ? \"<uuid>\" : match[2] ? \"<ts>\" : match[3] ? \"<hex>\" : \"<num>\";\n\t\tupdateHashRange(hash, replacement);\n\t\tnormalizedLength += replacement.length - match[0].length;\n\t\toffset = index + match[0].length;\n\t}\n\tupdateHashRange(hash, value, offset);\n\tupdateHashRange(hash, `:${normalizedLength};`);\n}\n\nfunction updateExactHashString(hash: SignatureHash, value: string): void {\n\tupdateHashRange(hash, value);\n\tupdateHashRange(hash, `:${value.length};`);\n}\n\nfunction updateStructuredHash(\n\thash: SignatureHash,\n\tvalue: unknown,\n\tactive: Set<object>,\n\tdepth: number,\n\tupdateHashString: (hash: SignatureHash, value: string) => void,\n): void {\n\tif (depth > MAX_SIGNATURE_DEPTH) {\n\t\tupdateHashRange(hash, \"depth;\");\n\t\treturn;\n\t}\n\tif (value === null) {\n\t\tupdateHashRange(hash, \"null;\");\n\t\treturn;\n\t}\n\tswitch (typeof value) {\n\t\tcase \"string\":\n\t\t\tupdateHashRange(hash, \"string:\");\n\t\t\tupdateHashString(hash, value);\n\t\t\treturn;\n\t\tcase \"number\":\n\t\t\tupdateHashRange(hash, \"number:\");\n\t\t\tupdateHashString(hash, Object.is(value, -0) ? \"-0\" : String(value));\n\t\t\treturn;\n\t\tcase \"boolean\":\n\t\t\tupdateHashRange(hash, value ? \"true;\" : \"false;\");\n\t\t\treturn;\n\t\tcase \"undefined\":\n\t\t\tupdateHashRange(hash, \"undefined;\");\n\t\t\treturn;\n\t\tcase \"bigint\":\n\t\t\tupdateHashRange(hash, `bigint:${value.toString()};`);\n\t\t\treturn;\n\t\tcase \"symbol\":\n\t\t\tupdateHashRange(hash, `symbol:${String(value.description ?? \"\")};`);\n\t\t\treturn;\n\t\tcase \"function\":\n\t\t\tupdateHashRange(hash, `function:${value.name};`);\n\t\t\treturn;\n\t\tcase \"object\":\n\t\t\tbreak;\n\t}\n\n\tif (active.has(value)) {\n\t\tupdateHashRange(hash, \"circular;\");\n\t\treturn;\n\t}\n\tactive.add(value);\n\tif (Array.isArray(value)) {\n\t\tupdateHashRange(hash, `array:${value.length}[`);\n\t\tfor (const item of value) updateStructuredHash(hash, item, active, depth + 1, updateHashString);\n\t\tupdateHashRange(hash, \"];\");\n\t} else {\n\t\tconst keys = Object.keys(value).sort();\n\t\tupdateHashRange(hash, `object:${keys.length}{`);\n\t\tfor (const key of keys) {\n\t\t\tupdateHashString(hash, key);\n\t\t\tupdateStructuredHash(hash, (value as Record<string, unknown>)[key], active, depth + 1, updateHashString);\n\t\t}\n\t\tupdateHashRange(hash, \"};\");\n\t}\n\tactive.delete(value);\n}\n\nfunction createSignatureHash(): SignatureHash {\n\treturn {\n\t\tfirst: 0x811c9dc5,\n\t\tsecond: 0x9e3779b9,\n\t\tthird: 0x85ebca6b,\n\t\tfourth: 0xc2b2ae35,\n\t};\n}\n\nfunction renderSignatureHash(hash: SignatureHash): string {\n\treturn [hash.first, hash.second, hash.third, hash.fourth]\n\t\t.map((part) => (part >>> 0).toString(16).padStart(8, \"0\"))\n\t\t.join(\"\");\n}\n\nfunction structuredHash(value: unknown, normalizeVolatile: boolean): string {\n\tconst hash = createSignatureHash();\n\tupdateStructuredHash(\n\t\thash,\n\t\tvalue,\n\t\tnew Set(),\n\t\t0,\n\t\tnormalizeVolatile ? updateNormalizedHashString : updateExactHashString,\n\t);\n\treturn renderSignatureHash(hash);\n}\n\nfunction boundedJsonPreview(value: unknown, maxChars: number): string {\n\tlet output = \"\";\n\tlet exhausted = false;\n\tconst active = new Set<object>();\n\tconst append = (text: string): void => {\n\t\tif (exhausted) return;\n\t\tconst available = maxChars - output.length;\n\t\tif (text.length <= available) {\n\t\t\toutput += text;\n\t\t\treturn;\n\t\t}\n\t\tif (available > 1) output += `${text.slice(0, available - 1)}…`;\n\t\texhausted = true;\n\t};\n\tconst visit = (item: unknown, depth: number): void => {\n\t\tif (exhausted) return;\n\t\tif (depth > MAX_PREVIEW_DEPTH) {\n\t\t\tappend('\"[depth]\"');\n\t\t\treturn;\n\t\t}\n\t\tif (typeof item === \"string\") {\n\t\t\tappend(safeJson(truncateMiddle(item, MAX_PREVIEW_STRING_CHARS)));\n\t\t\treturn;\n\t\t}\n\t\tif (item === null || typeof item === \"number\" || typeof item === \"boolean\") {\n\t\t\tappend(String(item));\n\t\t\treturn;\n\t\t}\n\t\tif (typeof item !== \"object\") {\n\t\t\tappend(safeJson(`[${typeof item}]`));\n\t\t\treturn;\n\t\t}\n\t\tif (active.has(item)) {\n\t\t\tappend('\"[circular]\"');\n\t\t\treturn;\n\t\t}\n\t\tactive.add(item);\n\t\tif (Array.isArray(item)) {\n\t\t\tappend(\"[\");\n\t\t\tconst count = Math.min(item.length, MAX_PREVIEW_ITEMS);\n\t\t\tfor (let index = 0; index < count && !exhausted; index++) {\n\t\t\t\tif (index > 0) append(\",\");\n\t\t\t\tvisit(item[index], depth + 1);\n\t\t\t}\n\t\t\tif (item.length > count) append(`${count > 0 ? \",\" : \"\"}\"[+${item.length - count} items]\"`);\n\t\t\tappend(\"]\");\n\t\t} else {\n\t\t\tappend(\"{\");\n\t\t\tlet count = 0;\n\t\t\tlet omitted = 0;\n\t\t\tconst keys = Object.keys(item).sort();\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (count >= MAX_PREVIEW_ITEMS) {\n\t\t\t\t\tomitted++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (count > 0) append(\",\");\n\t\t\t\tappend(safeJson(truncateMiddle(key, MAX_PREVIEW_STRING_CHARS)));\n\t\t\t\tappend(\":\");\n\t\t\t\tvisit((item as Record<string, unknown>)[key], depth + 1);\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif (omitted > 0) append(`${count > 0 ? \",\" : \"\"}\"[omitted]\":${omitted}`);\n\t\t\tappend(\"}\");\n\t\t}\n\t\tactive.delete(item);\n\t};\n\tvisit(value, 0);\n\treturn truncateMiddle(output || \"null\", maxChars);\n}\n\n/**\n * Fingerprint a tool operation without materializing or retaining its serialized payload.\n * Volatile identifiers normalize before hashing; short numbers and ordinary paths remain significant.\n */\n/**\n * Resource-envelope fields are not the operation. Changing `timeout` (or a sibling wait bound)\n * must not mint a new execution identity — that is how a failed command is replayed forever.\n */\nconst OPERATION_ENVELOPE_KEYS = new Set([\n\t\"timeout\",\n\t\"timeoutms\",\n\t\"timeout_ms\",\n\t\"timeoutsec\",\n\t\"timeout_sec\",\n\t\"timeoutseconds\",\n\t\"timeout_seconds\",\n\t\"maxwait\",\n\t\"max_wait\",\n\t\"maxwaitms\",\n\t\"max_wait_ms\",\n\t\"waitms\",\n\t\"wait_ms\",\n\t\"waitsec\",\n\t\"wait_sec\",\n\t\"waitseconds\",\n\t\"wait_seconds\",\n]);\n\nfunction omitOperationEnvelopeFields(value: unknown): unknown {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return value;\n\tconst record = value as Record<string, unknown>;\n\tlet changed = false;\n\tconst next: Record<string, unknown> = {};\n\tfor (const [key, entry] of Object.entries(record)) {\n\t\tif (OPERATION_ENVELOPE_KEYS.has(key.toLowerCase())) {\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tnext[key] = entry;\n\t}\n\treturn changed ? next : value;\n}\n\nexport function normalizeToolSignature(pairs: Array<[string, unknown]>): string {\n\treturn structuredHash(\n\t\tpairs.map(([name, args]) => [name, omitOperationEnvelopeFields(args)]),\n\t\ttrue,\n\t);\n}\n\nfunction toolOperationKey(tool: string, args: unknown, normalizeVolatile: boolean): string {\n\tconst identityArgs = omitOperationEnvelopeFields(args);\n\tconst boundedTool = truncate(tool, MAX_TOOL_NAME_CHARS);\n\tconst hash = createSignatureHash();\n\tconst updateHashString = normalizeVolatile ? updateNormalizedHashString : updateExactHashString;\n\tconst active = new Set<object>();\n\t// Preserve the stable structured-hash wire identity without allocating the two synthetic arrays.\n\tupdateHashRange(hash, \"array:1[array:2[\");\n\tupdateStructuredHash(hash, tool, active, 2, updateHashString);\n\tupdateStructuredHash(hash, identityArgs, active, 2, updateHashString);\n\tupdateHashRange(hash, \"];];\");\n\tconst signature = renderSignatureHash(hash);\n\treturn `${boundedTool}:${signature}`;\n}\n\nfunction operationIdentity(tool: string, args: unknown): ToolOperationIdentity {\n\treturn {\n\t\tfailureKey: toolOperationKey(tool, args, true),\n\t\texecutionKey: toolOperationKey(tool, args, false),\n\t\ttool: truncate(tool, MAX_TOOL_NAME_CHARS),\n\t\toperation: boundedJsonPreview(args, MAX_OPERATION_CHARS),\n\t};\n}\n\nfunction getToolFailureKey(tool: string, args: unknown): string {\n\treturn toolOperationKey(tool, args, true);\n}\n\nexport function getToolExecutionKey(tool: string, args: unknown): string {\n\treturn toolOperationKey(tool, args, false);\n}\n\n/** Read the four hash words already encoded by this module's exact execution-key owner. */\nexport function getToolExecutionKeyHashParts(executionKey: string): readonly [number, number, number, number] {\n\tconst separator = executionKey.lastIndexOf(\":\");\n\tconst signature = executionKey.slice(separator + 1);\n\tif (separator < 0 || signature.length !== TOOL_SIGNATURE_HEX_CHARS || !/^[0-9a-f]+$/.test(signature)) {\n\t\tthrow new TypeError(\"Tool execution key has an invalid hash signature.\");\n\t}\n\treturn [\n\t\tNumber.parseInt(signature.slice(0, 8), 16),\n\t\tNumber.parseInt(signature.slice(8, 16), 16),\n\t\tNumber.parseInt(signature.slice(16, 24), 16),\n\t\tNumber.parseInt(signature.slice(24, 32), 16),\n\t];\n}\n\nexport function getToolFailureRecordExecutionKey(record: ToolFailureMemoryRecord): string | undefined {\n\treturn record[TOOL_FAILURE_EXECUTION_KEY];\n}\n\nexport function getUnresolvedToolFailure(\n\ttracker: ToolFailureMemoryTracker,\n\ttool: string,\n\targs: unknown,\n): ToolFailureMemoryRecord | undefined {\n\treturn tracker.get(getToolFailureKey(tool, args));\n}\n\nexport function readVisibleToolFailureCode(result: ToolResultMessage): string | undefined {\n\tfor (const block of result.content) {\n\t\tif (block.type !== \"text\") continue;\n\t\tconst match = /\"failure_code\"\\s*:\\s*\"([^\"]+)\"/.exec(block.text);\n\t\tif (match) return match[1];\n\t}\n\treturn undefined;\n}\n\nexport function isClosedOperationFailureCode(code: string | undefined): boolean {\n\treturn code === \"operation_recovery_exhausted\" || code === \"recovery_exhausted\";\n}\n\n/** Failures that only a new owner prompt can clear. Do not restore their circuit across user turns. */\nexport function isPromptScopedFailureCode(code: string | undefined): boolean {\n\treturn code === \"owner_authorization_required\";\n}\n\nexport function restoreToolFailureRecord(\n\tresult: ToolResultMessage,\n\ttool: string,\n\targs: unknown,\n): ToolFailureMemoryRecord {\n\tconst executionKey = getToolExecutionKey(tool, args);\n\tconst persisted = readFailureRecord(result.details);\n\tif (persisted) {\n\t\treturn {\n\t\t\t...persisted,\n\t\t\t[TOOL_FAILURE_EXECUTION_KEY]: getToolFailureRecordExecutionKey(persisted) ?? executionKey,\n\t\t};\n\t}\n\tconst identity = operationIdentity(tool, args);\n\treturn {\n\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\tfailureKey: identity.failureKey,\n\t\t[TOOL_FAILURE_EXECUTION_KEY]: executionKey,\n\t\ttool: identity.tool,\n\t\toperation: identity.operation,\n\t\toccurrence: 1,\n\t\tstate: \"failed\",\n\t\tphase: \"execution\",\n\t\tfailureCode: boundedFailureCode(readVisibleToolFailureCode(result) ?? \"tool_error\"),\n\t\tcorrection: fallbackFailureGuidance(\"failed\", false, \"execution\"),\n\t};\n}\n\nexport interface PairedToolResult {\n\ttool: string;\n\targs: unknown;\n\texecutionKey: string;\n\tresult: ToolResultMessage;\n}\n\nexport function forEachPairedToolResult(\n\tmessages: readonly AgentMessage[],\n\tvisit: (pair: PairedToolResult) => boolean | undefined,\n): void {\n\tconst callsById = new Map<string, { name: string; args: unknown }>();\n\tfor (const message of messages) {\n\t\tif (message.role === \"assistant\") {\n\t\t\tfor (const block of message.content) {\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tcallsById.set(block.id, { name: block.name, args: block.arguments });\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"toolResult\") continue;\n\t\tconst call = callsById.get(message.toolCallId);\n\t\tif (!call) continue;\n\t\tif (\n\t\t\tvisit({\n\t\t\t\ttool: call.name,\n\t\t\t\targs: call.args,\n\t\t\t\texecutionKey: getToolExecutionKey(call.name, call.args),\n\t\t\t\tresult: message,\n\t\t\t}) === false\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nexport function transcriptHasClosedToolOperation(messages: readonly AgentMessage[]): boolean {\n\tconst closedByExecutionKey = new Map<string, true>();\n\tforEachPairedToolResult(messages, ({ executionKey, result }) => {\n\t\tif (!result.isError) {\n\t\t\tclosedByExecutionKey.delete(executionKey);\n\t\t\treturn;\n\t\t}\n\t\tif (isClosedOperationFailureCode(readVisibleToolFailureCode(result))) {\n\t\t\tclosedByExecutionKey.set(executionKey, true);\n\t\t}\n\t});\n\treturn closedByExecutionKey.size > 0;\n}\n\nfunction boundedFailureCode(value: string): string {\n\tconst normalized = value\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_.:-]+/g, \"_\")\n\t\t.replace(/^_+|_+$/g, \"\");\n\treturn truncate(normalized || \"tool_error\", MAX_FAILURE_CODE_CHARS);\n}\n\n/**\n * bash.ts's own trailer (`appendStatus`) always ends the message with a line like \"Command\n * exited with code 1\"; a structured result (e.g. run_process) instead puts \"exitCode: 1\" on its\n * own line near the top. Both are anchored to the START of their own line, with at most one\n * leading tool-name token (\"Command\"/\"Python\"/...) — ordinary stdout/stderr prose is never\n * anchored that way, so a captured line like \"container will exit 0 on SIGTERM\" can never be\n * read as the process exit status. Scan from the end of the message so the tool's own trailer —\n * always the last line it appends — outranks any earlier, non-authoritative line that matches.\n */\nconst EXIT_STATUS_LINE_PATTERN = /^(?:\\S+\\s+)?(?:exit(?:ed)?(?:\\s+with)?(?:\\s+code)?|exitcode)\\s*[:=]?\\s*(-?\\d+)\\b/i;\n\n/**\n * bash.ts appends `cwd: <dir>` after its exit trailer on failures. The line is harness status, not\n * a cause: it must never displace a real diagnostic (a path may contain words like \"error\"), and it\n * reaches the model through the process-exit evidence tail instead.\n */\nconst CWD_STATUS_LINE_PATTERN = /^cwd:\\s/i;\n\n/** Tool-owned status/marker lines that carry no cause and never belong in diagnostic or evidence. */\nfunction isFailureStatusLine(line: string): boolean {\n\treturn (\n\t\t/^command (?:exited with code|timed out after|aborted|killed after)\\b/i.test(line) ||\n\t\t/^outcome:\\s*(?:failed|aborted|timeout|output_limit)\\b/i.test(line) ||\n\t\t/^exitcode:\\s*-?\\d+\\b/i.test(line) ||\n\t\t/^(?:stdout|stderr):(?:\\s*\\(empty\\))?$/i.test(line)\n\t);\n}\n\nfunction processExitFailureCode(message: string): string | undefined {\n\tconst lines = message.split(/\\r\\n|\\n/);\n\tfor (let index = lines.length - 1; index >= 0; index--) {\n\t\tconst match = EXIT_STATUS_LINE_PATTERN.exec(lines[index].trim());\n\t\tif (match) return boundedFailureCode(`exit_${match[1]}`);\n\t}\n\treturn undefined;\n}\n\nexport function classifyToolFailure(message: string, errorClass?: string): string {\n\t// A tool-owned terminal status is authoritative; stdout may contain arbitrary all-caps identifiers.\n\tconst exitFailureCode = processExitFailureCode(message);\n\tif (exitFailureCode) return exitFailureCode;\n\tconst errno = /\\b(E[A-Z][A-Z0-9_]{2,})\\b/.exec(message)?.[1];\n\tif (errno) return boundedFailureCode(errno);\n\treturn boundedFailureCode(errorClass ?? \"tool_error\");\n}\n\nfunction isToolFailurePhase(value: unknown): value is ToolFailurePhase {\n\treturn (\n\t\tvalue === \"validation\" ||\n\t\tvalue === \"policy\" ||\n\t\tvalue === \"preflight\" ||\n\t\tvalue === \"execution\" ||\n\t\tvalue === \"timeout\" ||\n\t\tvalue === \"cancelled\" ||\n\t\tvalue === \"provisioning\"\n\t);\n}\n\nfunction inferToolFailurePhase(state: ToolFailureState, failureCode: string): ToolFailurePhase {\n\tif (failureCode === \"malformed_call\" || failureCode === \"unknown_tool\" || failureCode === \"invalid_arguments\") {\n\t\treturn \"validation\";\n\t}\n\tif (\n\t\tfailureCode === \"blocked\" ||\n\t\tfailureCode === \"permission_denied\" ||\n\t\tfailureCode === \"owner_authorization_required\"\n\t) {\n\t\treturn \"policy\";\n\t}\n\tif (failureCode === \"preflight_error\") return \"preflight\";\n\tif (failureCode === \"aborted\" || failureCode === \"cancelled\") return \"cancelled\";\n\tif (failureCode === \"timeout\" || failureCode === \"etimedout\") return \"timeout\";\n\tif (failureCode === \"provisioning_failed\" || failureCode === \"command_not_found\") return \"provisioning\";\n\treturn state === \"rejected\" ? \"validation\" : \"execution\";\n}\n\nfunction fallbackFailureGuidance(state: ToolFailureState, hasDiagnostic: boolean, phase: ToolFailurePhase): string {\n\tif (phase === \"preflight\") {\n\t\treturn hasDiagnostic\n\t\t\t? \"Arguments valid; preflight failed before execution. Resolve diagnostic/host condition before retry.\"\n\t\t\t: \"Arguments valid; preflight failed before execution. Inspect host policy/capability before retry.\";\n\t}\n\tif (phase === \"policy\") return \"Resolve authority/policy restriction or choose allowed approach before retry.\";\n\tif (phase === \"cancelled\") return \"Retry only when operation remains required, cancellation condition cleared.\";\n\tif (phase === \"timeout\") return \"Narrow/split work; retry once only when safe.\";\n\tif (phase === \"provisioning\") {\n\t\treturn hasDiagnostic\n\t\t\t? \"Fix provisioning diagnostic; retry only after environment changes.\"\n\t\t\t: \"Inspect tool availability; request bounded provisioning diagnostic before retry.\";\n\t}\n\treturn state === \"rejected\"\n\t\t? \"Re-read current tool schema; change invalid operation before retry.\"\n\t\t: hasDiagnostic\n\t\t\t? \"Read diagnostic; identify cause; repair parameters or corrective state before retry.\"\n\t\t\t: \"No diagnostic output. Inspect tool contract or request bounded diagnostic before retry.\";\n}\n\nexport function toolFailureCorrection(\n\tmessage: string,\n\tstate: ToolFailureState,\n\tphase: ToolFailurePhase = state === \"rejected\" ? \"validation\" : \"execution\",\n): string {\n\tconst policy = getToolExecutionErrorPolicy(message);\n\treturn policy\n\t\t? truncate(policy.guidance, MAX_CORRECTION_CHARS)\n\t\t: fallbackFailureGuidance(state, message.trim().length > 0, phase);\n}\n\nfunction extractFailureDiagnostic(\n\tmessage: string,\n\tallowUnclassifiedFallback: boolean,\n\trequireStrongSignal = false,\n): string | undefined {\n\tconst rawLines = sanitizeBinaryOutput(message).replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\");\n\tconst strongDiagnosticPattern =\n\t\t/^(?:(?:error(?:\\[[^\\]]+\\])?|fatal(?: error)?|panic|fail(?:ed|ure)?|invalid|unknown|unsupported|not found|no such|cannot|can't|missing|denied|refused|usage)(?:\\b|:)|[a-z][a-z0-9_.]*error(?::|$)|thread .+ panicked at\\b|--- fail:|\\[fail(?:ed)?\\]|not ok\\b|[×✗]\\s|.{1,160}:\\s+(?:error(?:\\[[^\\]]+\\])?|fatal(?: error)?)(?:\\b|:))/i;\n\tconst stderrMarkerIndex = rawLines.findLastIndex((line) => /^stderr:\\s*$/i.test(line.trim()));\n\tif (stderrMarkerIndex >= 0) {\n\t\tconst stderrLines = rawLines\n\t\t\t.slice(stderrMarkerIndex + 1)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(\n\t\t\t\t(line) =>\n\t\t\t\t\tline.length > 0 &&\n\t\t\t\t\t!/^command (?:exited with code|timed out after|aborted|killed after)\\b/i.test(line) &&\n\t\t\t\t\t!CWD_STATUS_LINE_PATTERN.test(line),\n\t\t\t);\n\t\tif (stderrLines.length > 0) {\n\t\t\tconst classified = stderrLines.find((line) => strongDiagnosticPattern.test(line));\n\t\t\tif (classified) return truncateMiddle(classified, MAX_DIAGNOSTIC_CHARS);\n\t\t\t// No stderr line carries a strong signal. Under requireStrongSignal, the caller has\n\t\t\t// already decided uncatalogued output must never be fabricated into a diagnostic (see\n\t\t\t// assessToolFailure) — falling back to the last raw stderr lines here would defeat that\n\t\t\t// guarantee for the common bash case, so fall through to the same allowUnclassifiedFallback\n\t\t\t// gate the no-stderr path below applies.\n\t\t\tif (!requireStrongSignal) {\n\t\t\t\treturn truncateMiddle(stderrLines.slice(-4).join(\" | \"), MAX_DIAGNOSTIC_CHARS);\n\t\t\t}\n\t\t}\n\t}\n\tconst lines = rawLines\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0 && !isFailureStatusLine(line) && !CWD_STATUS_LINE_PATTERN.test(line));\n\tif (lines.length === 0) return undefined;\n\tconst diagnosticPattern = requireStrongSignal\n\t\t? strongDiagnosticPattern\n\t\t: /(?:^|\\b)(?:error|fatal|fail(?:ed|ure)?|invalid|unknown|unsupported|not found|no such|cannot|can't|missing|denied|refused|usage)(?:\\b|:)/i;\n\tconst classified = requireStrongSignal\n\t\t? lines.find((line) => diagnosticPattern.test(line))\n\t\t: [...lines].reverse().find((line) => diagnosticPattern.test(line));\n\tconst diagnostic = classified ?? (allowUnclassifiedFallback ? lines.at(-1) : undefined);\n\treturn diagnostic ? truncateMiddle(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;\n}\n\n/**\n * Bounded raw-output tail of an executed process-exit failure. Evidence is the raw-data channel:\n * it keeps the trailing lines that strong-signal diagnostic classification refuses to promote, so\n * strictness never destroys the output needed to construct a changed operation.\n */\nfunction extractProcessExitEvidence(message: string): string | undefined {\n\tconst lines = sanitizeBinaryOutput(message)\n\t\t.replaceAll(\"\\r\\n\", \"\\n\")\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0 && !isFailureStatusLine(line));\n\tif (lines.length === 0) return undefined;\n\tlet start = lines.length - 1;\n\tlet retainedChars = lines[start].length;\n\twhile (start > 0 && retainedChars + 1 + lines[start - 1].length <= MAX_TOOL_FAILURE_EVIDENCE_CHARS) {\n\t\tstart--;\n\t\tretainedChars += 1 + lines[start].length;\n\t}\n\tlet tail = lines.slice(start).join(\"\\n\");\n\tif (tail.length > MAX_TOOL_FAILURE_EVIDENCE_CHARS) {\n\t\tlet tailStart = tail.length - MAX_TOOL_FAILURE_EVIDENCE_CHARS;\n\t\tconst firstCode = tail.charCodeAt(tailStart);\n\t\tif (firstCode >= 0xdc00 && firstCode <= 0xdfff) tailStart++;\n\t\ttail = tail.slice(tailStart);\n\t}\n\treturn sanitizeToolFailureEvidence(tail);\n}\n\nexport interface ToolFailureAssessment {\n\tfailureCode: string;\n\tphase: ToolFailurePhase;\n\tdiagnostic?: string;\n\t/** Bounded raw-output tail of an executed process-exit failure. */\n\tevidence?: string;\n\tguidance: string;\n\t/** Catalogued per-error guidance; set only when a registry policy matched the failure message. */\n\tpolicyGuidance?: string;\n\tattemptMemory?: \"discard\";\n}\n\nexport function assessToolFailure(\n\tmessage: string,\n\tstate: ToolFailureState,\n\terrorClass?: string,\n): ToolFailureAssessment {\n\tconst policy = getToolExecutionErrorPolicy(message);\n\tconst exitFailureCode = processExitFailureCode(message);\n\tconst retainPolicyDiagnostic = policy?.retainDiagnostic === true;\n\tconst diagnostic =\n\t\tstate === \"failed\" && (!policy || policy.retainDiagnostic)\n\t\t\t? extractFailureDiagnostic(\n\t\t\t\t\tmessage,\n\t\t\t\t\texitFailureCode === undefined && (errorClass !== undefined || retainPolicyDiagnostic),\n\t\t\t\t\texitFailureCode !== undefined && !retainPolicyDiagnostic,\n\t\t\t\t)\n\t\t\t: undefined;\n\tconst evidence =\n\t\tstate === \"failed\" && exitFailureCode !== undefined ? extractProcessExitEvidence(message) : undefined;\n\tconst failureCode = policy?.failureCode ?? classifyToolFailure(message, errorClass);\n\treturn {\n\t\tfailureCode,\n\t\tphase: policy?.phase ?? inferToolFailurePhase(state, failureCode),\n\t\t...(diagnostic ? { diagnostic } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\tguidance: policy\n\t\t\t? truncate(policy.guidance, MAX_CORRECTION_CHARS)\n\t\t\t: fallbackFailureGuidance(state, diagnostic !== undefined, inferToolFailurePhase(state, failureCode)),\n\t\t...(policy ? { policyGuidance: truncate(policy.guidance, MAX_CORRECTION_CHARS) } : {}),\n\t\t...(policy?.attemptMemory === \"discard\" ? { attemptMemory: \"discard\" as const } : {}),\n\t};\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readFailureRecord(details: unknown): ToolFailureMemoryRecord | undefined {\n\tif (!isRecord(details) || !isRecord(details.piToolFailureMemory)) return undefined;\n\tconst candidate = details.piToolFailureMemory;\n\tif (\n\t\tcandidate.version !== TOOL_FAILURE_MEMORY_VERSION ||\n\t\ttypeof candidate.failureKey !== \"string\" ||\n\t\ttypeof candidate.tool !== \"string\" ||\n\t\ttypeof candidate.operation !== \"string\" ||\n\t\ttypeof candidate.occurrence !== \"number\" ||\n\t\t!Number.isSafeInteger(candidate.occurrence) ||\n\t\tcandidate.occurrence < 1 ||\n\t\t(candidate.state !== \"failed\" && candidate.state !== \"rejected\") ||\n\t\ttypeof candidate.failureCode !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\tconst diagnostic =\n\t\ttypeof candidate.diagnostic === \"string\" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;\n\tconst evidence = sanitizeToolFailureEvidence(candidate.evidence);\n\tconst retainedCorrection =\n\t\ttypeof candidate.correction === \"string\" ? truncate(candidate.correction, MAX_CORRECTION_CHARS) : undefined;\n\tconst correction =\n\t\tcandidate.state === \"failed\" && retainedCorrection === LEGACY_GENERIC_EXECUTION_CORRECTION\n\t\t\t? fallbackFailureGuidance(\"failed\", diagnostic !== undefined, \"execution\")\n\t\t\t: (retainedCorrection ?? toolFailureCorrection(\"\", candidate.state));\n\tconst phase = isToolFailurePhase(candidate.phase)\n\t\t? candidate.phase\n\t\t: inferToolFailurePhase(candidate.state, candidate.failureCode);\n\tconst candidateExecutionKey: unknown = Reflect.get(candidate, TOOL_FAILURE_EXECUTION_KEY);\n\treturn {\n\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\tfailureKey: truncate(candidate.failureKey, MAX_TOOL_NAME_CHARS + 1 + TOOL_SIGNATURE_HEX_CHARS),\n\t\t...(typeof candidateExecutionKey === \"string\"\n\t\t\t? {\n\t\t\t\t\t[TOOL_FAILURE_EXECUTION_KEY]: truncate(\n\t\t\t\t\t\tcandidateExecutionKey,\n\t\t\t\t\t\tMAX_TOOL_NAME_CHARS + 1 + TOOL_SIGNATURE_HEX_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\ttool: truncate(candidate.tool, MAX_TOOL_NAME_CHARS),\n\t\toperation: truncateMiddle(candidate.operation, MAX_OPERATION_CHARS),\n\t\toccurrence: candidate.occurrence,\n\t\tstate: candidate.state,\n\t\tphase,\n\t\tfailureCode: boundedFailureCode(candidate.failureCode),\n\t\tdiagnostic,\n\t\tevidence,\n\t\tcorrection,\n\t};\n}\n\nfunction readFailureDirective(details: unknown): ToolFailureDirectiveDetails[\"piToolFailureDirective\"] | undefined {\n\tif (!isRecord(details) || !isRecord(details.piToolFailureDirective)) return undefined;\n\tconst candidate = details.piToolFailureDirective;\n\tif (\n\t\tcandidate.version !== TOOL_FAILURE_DIRECTIVE_VERSION ||\n\t\ttypeof candidate.failureCode !== \"string\" ||\n\t\ttypeof candidate.nextAction !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tversion: TOOL_FAILURE_DIRECTIVE_VERSION,\n\t\tstate: candidate.state === \"rejected\" ? \"rejected\" : \"failed\",\n\t\tphase: isToolFailurePhase(candidate.phase)\n\t\t\t? candidate.phase\n\t\t\t: inferToolFailurePhase(\"failed\", candidate.failureCode),\n\t\tfailureCode: boundedFailureCode(candidate.failureCode),\n\t\tdiagnostic:\n\t\t\ttypeof candidate.diagnostic === \"string\" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,\n\t\tnextAction: truncate(candidate.nextAction, MAX_CORRECTION_CHARS),\n\t};\n}\n\nexport interface ToolFailureTelemetry {\n\tstate: ToolFailureState;\n\tphase: ToolFailurePhase;\n\tfailureCode: string;\n\tdiagnostic?: string;\n\tnextAction: string;\n}\n\n/** Read only bounded failure identity and guidance; operation arguments never cross this telemetry boundary. */\nexport function readToolFailureTelemetry(details: unknown): ToolFailureTelemetry | undefined {\n\tconst record = readFailureRecord(details);\n\tif (record) {\n\t\treturn {\n\t\t\tstate: record.state,\n\t\t\tphase: record.phase,\n\t\t\tfailureCode: record.failureCode,\n\t\t\t...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),\n\t\t\tnextAction: record.correction,\n\t\t};\n\t}\n\tconst directive = readFailureDirective(details);\n\tif (!directive) return undefined;\n\treturn {\n\t\tstate: directive.state,\n\t\tphase: directive.phase,\n\t\tfailureCode: directive.failureCode,\n\t\t...(directive.diagnostic ? { diagnostic: directive.diagnostic } : {}),\n\t\tnextAction: directive.nextAction,\n\t};\n}\n\nfunction firstText(message: ToolResultMessage): string {\n\tconst content = message.content;\n\tif (typeof content === \"string\") return content;\n\tif (Array.isArray(content)) {\n\t\tfor (let index = 0; index < content.length; index++) {\n\t\t\tconst block = content[index];\n\t\t\tif (block.type === \"text\") return block.text;\n\t\t}\n\t}\n\treturn \"\";\n}\n\nfunction fastTextSignature(text: string): string {\n\tif (text.length <= 128) return text;\n\treturn `${text.length}:${text.slice(0, 48)}:${text.slice(-48)}`;\n}\n\nfunction analyzeToolFailureContext(messages: AgentMessage[]): FailureContextAnalysis {\n\tconst callById = new Map<string, AgentToolCall>();\n\tconst omittedCallIds = new Set<string>();\n\tconst orphanFailedResults = new Set<ToolResultMessage>();\n\tconst active = new Map<string, ActiveFailure>();\n\tconst activeDirectives = new Map<string, ToolFailureDirectiveDetails[\"piToolFailureDirective\"]>();\n\tlet sequence = 0;\n\tconst kindMistakesMap = new Map<string, number>();\n\n\tconst latestSuccessfulByOpKey = new Map<string, string>();\n\tconst latestSuccessfulByPayloadKey = new Map<string, string>();\n\n\tfor (let index = 0; index < messages.length; index++) {\n\t\tconst message = messages[index];\n\t\tif (message.role === \"assistant\") {\n\t\t\tactiveDirectives.clear();\n\t\t\tconst content = message.content;\n\t\t\tfor (let blockIdx = 0; blockIdx < content.length; blockIdx++) {\n\t\t\t\tconst block = content[blockIdx];\n\t\t\t\tif (block.type !== \"toolCall\") continue;\n\t\t\t\tcallById.set(block.id, block);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"toolResult\") continue;\n\n\t\tconst call = callById.get(message.toolCallId);\n\t\tcallById.delete(message.toolCallId);\n\t\tconst textPayload = firstText(message);\n\t\tconst isFailure = message.isError === true || textPayload.startsWith(\"[harness] \");\n\t\tif (isFailure) {\n\t\t\tconst toolName = call?.name ?? message.toolName;\n\t\t\tconst kindCount = (kindMistakesMap.get(toolName) ?? 0) + 1;\n\t\t\tkindMistakesMap.set(toolName, kindCount);\n\n\t\t\tconst directive = readFailureDirective(message.details);\n\t\t\tif (directive) {\n\t\t\t\tactiveDirectives.delete(directive.failureCode);\n\t\t\t\tactiveDirectives.set(directive.failureCode, directive);\n\t\t\t\tif (call) omittedCallIds.add(call.id);\n\t\t\t\telse orphanFailedResults.add(message);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst retained = readFailureRecord(message.details);\n\t\t\tconst state = retained?.state ?? \"failed\";\n\t\t\tconst assessment = retained ? undefined : assessToolFailure(textPayload, state);\n\t\t\tlet failureKey: string;\n\t\t\tlet executionKey: string | undefined;\n\t\t\tlet tool: string;\n\t\t\tlet operation: string;\n\t\t\tif (retained) {\n\t\t\t\tfailureKey = retained.failureKey;\n\t\t\t\texecutionKey = call\n\t\t\t\t\t? getToolExecutionKey(call.name, call.arguments)\n\t\t\t\t\t: getToolFailureRecordExecutionKey(retained);\n\t\t\t\ttool = retained.tool;\n\t\t\t\toperation = retained.operation;\n\t\t\t} else {\n\t\t\t\tconst identity = operationIdentity(\n\t\t\t\t\tcall?.name ?? message.toolName,\n\t\t\t\t\tcall?.arguments ?? { toolCallId: message.toolCallId },\n\t\t\t\t);\n\t\t\t\tfailureKey = identity.failureKey;\n\t\t\t\texecutionKey = identity.executionKey;\n\t\t\t\ttool = identity.tool;\n\t\t\t\toperation = identity.operation;\n\t\t\t}\n\t\t\tconst previous = active.get(failureKey)?.record;\n\t\t\tconst occurrence = Math.max(retained?.occurrence ?? 0, (previous?.occurrence ?? 0) + 1);\n\t\t\tconst record: ToolFailureMemoryRecord = {\n\t\t\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\t\t\tfailureKey,\n\t\t\t\t...(executionKey ? { [TOOL_FAILURE_EXECUTION_KEY]: executionKey } : {}),\n\t\t\t\ttool,\n\t\t\t\toperation,\n\t\t\t\toccurrence,\n\t\t\t\tkindMistakes: kindCount,\n\t\t\t\tmistakeKind: toolName,\n\t\t\t\tstate,\n\t\t\t\tphase: retained?.phase ?? assessment?.phase ?? inferToolFailurePhase(state, \"tool_error\"),\n\t\t\t\tfailureCode: retained?.failureCode ?? assessment?.failureCode ?? \"tool_error\",\n\t\t\t\tdiagnostic: retained?.diagnostic ?? assessment?.diagnostic,\n\t\t\t\tevidence: retained?.evidence,\n\t\t\t\tcorrection:\n\t\t\t\t\tretained?.correction ??\n\t\t\t\t\tassessment?.guidance ??\n\t\t\t\t\tfallbackFailureGuidance(state, false, inferToolFailurePhase(state, \"tool_error\")),\n\t\t\t};\n\t\t\tactive.delete(failureKey);\n\t\t\tactive.set(failureKey, { record, sequence: sequence++ });\n\t\t\twhile (active.size > MAX_TRACKED_FAILURES) {\n\t\t\t\tconst oldest = active.keys().next().value;\n\t\t\t\tif (oldest === undefined) break;\n\t\t\t\tactive.delete(oldest);\n\t\t\t}\n\t\t\tif (call) omittedCallIds.add(call.id);\n\t\t\telse orphanFailedResults.add(message);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (call) {\n\t\t\tconst opKey = getToolFailureKey(call.name, call.arguments);\n\t\t\tactive.delete(opKey);\n\t\t\tconst previousOperationCallId = latestSuccessfulByOpKey.get(opKey);\n\t\t\tif (previousOperationCallId) omittedCallIds.add(previousOperationCallId);\n\t\t\tlatestSuccessfulByOpKey.set(opKey, call.id);\n\n\t\t\tconst textPayload = firstText(message);\n\t\t\tif (textPayload.length >= 64) {\n\t\t\t\tconst payloadKey = `payload:${fastTextSignature(textPayload)}`;\n\t\t\t\tconst previousPayloadCallId = latestSuccessfulByPayloadKey.get(payloadKey);\n\t\t\t\tif (previousPayloadCallId) omittedCallIds.add(previousPayloadCallId);\n\t\t\t\tlatestSuccessfulByPayloadKey.set(payloadKey, call.id);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst kindMistakesSummary = Object.fromEntries(kindMistakesMap);\n\n\tif (omittedCallIds.size === 0 && orphanFailedResults.size === 0) {\n\t\treturn { messages, activeRecords: [], activeDirectives: [], kindMistakesSummary };\n\t}\n\n\tconst filteredMessages: AgentMessage[] = [];\n\tfor (let index = 0; index < messages.length; index++) {\n\t\tconst message = messages[index];\n\t\tif (message.role === \"toolResult\") {\n\t\t\tif (omittedCallIds.has(message.toolCallId) || orphanFailedResults.has(message)) continue;\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"assistant\") {\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tconst content = message.content;\n\t\tif (content.length === 1) {\n\t\t\tconst block = content[0];\n\t\t\tif (block.type === \"toolCall\" && omittedCallIds.has(block.id)) continue;\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tlet hasOmitted = false;\n\t\tfor (let blockIdx = 0; blockIdx < content.length; blockIdx++) {\n\t\t\tconst block = content[blockIdx];\n\t\t\tif (block.type === \"toolCall\" && omittedCallIds.has(block.id)) {\n\t\t\t\thasOmitted = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!hasOmitted) {\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tconst retainedContent = content.filter((block) => block.type !== \"toolCall\" || !omittedCallIds.has(block.id));\n\t\tif (retainedContent.length > 0) {\n\t\t\tfilteredMessages.push({ ...message, content: retainedContent } satisfies AssistantMessage);\n\t\t}\n\t}\n\tconst activeRecords = [...active.values()]\n\t\t.sort((left, right) => left.sequence - right.sequence)\n\t\t.map(({ record }) => record);\n\treturn {\n\t\tmessages: filteredMessages,\n\t\tactiveRecords,\n\t\tactiveDirectives: [...activeDirectives.values()],\n\t\tkindMistakesSummary,\n\t};\n}\n\nexport function createToolFailureMemoryTracker(messages: AgentMessage[]): ToolFailureMemoryTracker {\n\treturn new Map(analyzeToolFailureContext(messages).activeRecords.map((record) => [record.failureKey, record]));\n}\n\nexport function rememberToolFailure(\n\ttracker: ToolFailureMemoryTracker,\n\ttool: string,\n\targs: unknown,\n\tstate: ToolFailureState,\n\tfailureCode: string,\n\tcorrection: string,\n\tdiagnostic?: string,\n\tphase: ToolFailurePhase = inferToolFailurePhase(state, failureCode),\n\tevidence?: string,\n): ToolFailureMemoryRecord {\n\tlet kindCount = 1;\n\tfor (const previous of tracker.values()) {\n\t\tif (previous.tool === tool) {\n\t\t\tkindCount = Math.max(kindCount, (previous.kindMistakes ?? previous.occurrence) + 1);\n\t\t}\n\t}\n\tconst isDiscard = getToolExecutionAttemptMemory(failureCode) === \"discard\";\n\tif (isDiscard) {\n\t\tfor (const [failureKey, previous] of tracker) {\n\t\t\tif (previous.tool === tool && previous.failureCode === failureCode) tracker.delete(failureKey);\n\t\t}\n\t}\n\tconst identity = isDiscard ? undefined : operationIdentity(tool, args);\n\tconst previous = identity ? tracker.get(identity.failureKey) : undefined;\n\tconst record: ToolFailureMemoryRecord = {\n\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\tfailureKey: identity ? identity.failureKey : `directive:${boundedFailureCode(failureCode)}`,\n\t\t[TOOL_FAILURE_EXECUTION_KEY]: identity ? identity.executionKey : getToolExecutionKey(tool, args),\n\t\ttool: identity ? identity.tool : truncate(tool, MAX_TOOL_NAME_CHARS),\n\t\toperation: identity ? identity.operation : \"[discarded]\",\n\t\toccurrence: isDiscard ? 1 : (previous?.occurrence ?? 0) + 1,\n\t\tkindMistakes: kindCount,\n\t\tmistakeKind: tool,\n\t\tstate,\n\t\tphase,\n\t\tfailureCode: boundedFailureCode(failureCode),\n\t\tdiagnostic: diagnostic ? truncate(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,\n\t\tevidence: sanitizeToolFailureEvidence(evidence),\n\t\tcorrection: truncate(correction, MAX_CORRECTION_CHARS),\n\t\t...(isDiscard ? { attemptMemory: \"discard\" as const } : {}),\n\t};\n\tif (isDiscard) return record;\n\tif (identity) {\n\t\ttracker.delete(identity.failureKey);\n\t\ttracker.set(identity.failureKey, record);\n\t\twhile (tracker.size > MAX_TRACKED_FAILURES) {\n\t\t\tconst oldest = tracker.keys().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\ttracker.delete(oldest);\n\t\t}\n\t}\n\treturn record;\n}\n\nexport function clearToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): void {\n\tconst failureKey = getToolFailureKey(tool, args);\n\tconst record = tracker.get(failureKey);\n\tconst executionKey = record ? getToolFailureRecordExecutionKey(record) : undefined;\n\tif (!executionKey || executionKey === getToolExecutionKey(tool, args)) tracker.delete(failureKey);\n}\n\nfunction failureGuidance(record: ToolFailureMemoryRecord): { repair: string } | { next_action: string } {\n\treturn record.state === \"rejected\" && REPAIRABLE_REJECTION_CODES.has(record.failureCode)\n\t\t? { repair: record.correction }\n\t\t: { next_action: record.correction };\n}\n\nfunction formatRecordJson(\n\trecord: ToolFailureMemoryRecord,\n\tincludeOperation = false,\n\tevidence: string | null | undefined = record.evidence,\n): string {\n\tconst guidance = failureGuidance(record);\n\treturn JSON.stringify({\n\t\t...mandatoryToolFailureRecoveryMetadata(),\n\t\tfailure_key: record.failureKey,\n\t\tocc: record.occurrence,\n\t\tkind_mistakes: record.kindMistakes ?? record.occurrence,\n\t\tmistake_kind: record.mistakeKind ?? record.tool,\n\t\tstate: record.state,\n\t\tphase: record.phase,\n\t\ttool: record.tool,\n\t\t...(includeOperation ? { operation: record.operation } : {}),\n\t\tfailure_code: record.failureCode,\n\t\t...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\t...guidance,\n\t\t...(record.attemptMemory === \"discard\" ? { attempt_memory: \"discarded\" } : {}),\n\t});\n}\n\nexport function createToolFailureResult(\n\trecord: ToolFailureMemoryRecord,\n\tterminate?: boolean,\n): AgentToolResult<ToolFailureResultDetails> {\n\tconst discardAttempt = record.attemptMemory === \"discard\";\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `[harness] ${formatRecordJson(record, false)}`,\n\t\t\t},\n\t\t],\n\t\tdetails: discardAttempt\n\t\t\t? {\n\t\t\t\t\tpiToolFailureDirective: {\n\t\t\t\t\t\tversion: TOOL_FAILURE_DIRECTIVE_VERSION,\n\t\t\t\t\t\tstate: record.state,\n\t\t\t\t\t\tphase: record.phase,\n\t\t\t\t\t\tfailureCode: record.failureCode,\n\t\t\t\t\t\t...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),\n\t\t\t\t\t\tnextAction: record.correction,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: { piToolFailureMemory: record },\n\t\t...(terminate === undefined ? {} : { terminate }),\n\t};\n}\n\nexport function createRepeatedToolFailureResult(\n\trecord: ToolFailureMemoryRecord,\n): AgentToolResult<ToolFailureMemoryDetails> {\n\tconst retainedRecord = {\n\t\t...retainBlockedToolFailure(record),\n\t\tcorrection: BLOCKED_REPLAY_CAVEMAN_CORRECTION,\n\t};\n\tconst diagnostic = truncateMiddle(\n\t\t`The unchanged operation was not executed. Unchanged replay blocked after ${record.failureCode}`,\n\t\tMAX_DIAGNOSTIC_CHARS,\n\t);\n\tconst blockedResult = createToolFailureResult({\n\t\t...retainedRecord,\n\t\tstate: \"rejected\",\n\t\tfailureCode: \"repeated_failed_operation\",\n\t\tdiagnostic,\n\t\tcorrection: retainedRecord.correction,\n\t});\n\treturn {\n\t\t...blockedResult,\n\t\t// The visible result describes this rejected replay, while retained memory keeps the\n\t\t// authoritative cause so later blocks do not recursively wrap synthetic failures.\n\t\tdetails: { piToolFailureMemory: retainedRecord },\n\t};\n}\n\nexport function createToolFailureRecoveryExhaustedResult(\n\trecord: ToolFailureMemoryRecord,\n\tdiagnostic: string,\n): AgentToolResult<ToolFailureMemoryDetails> {\n\tconst retainedRecord = retainBlockedToolFailure(record);\n\tconst exhaustedResult = createToolFailureResult(\n\t\t{\n\t\t\t...retainedRecord,\n\t\t\tstate: \"rejected\",\n\t\t\tfailureCode: \"recovery_exhausted\",\n\t\t\tdiagnostic: truncateMiddle(diagnostic, MAX_DIAGNOSTIC_CHARS),\n\t\t\tcorrection:\n\t\t\t\t\"Stop retrying tools in this run. Report the unresolved failure and the user or environment action required to continue.\",\n\t\t},\n\t\ttrue,\n\t);\n\treturn {\n\t\t...exhaustedResult,\n\t\tdetails: { piToolFailureMemory: retainedRecord },\n\t};\n}\n\nexport function createToolFailureOperationExhaustedResult(\n\trecord: ToolFailureMemoryRecord,\n\tdiagnostic: string,\n): AgentToolResult<ToolFailureMemoryDetails> {\n\tconst retainedRecord = {\n\t\t...retainBlockedToolFailure(record),\n\t\tcorrection: CLOSED_OPERATION_CAVEMAN_CORRECTION,\n\t};\n\tconst exhaustedResult = createToolFailureResult(\n\t\t{\n\t\t\t...retainedRecord,\n\t\t\tstate: \"rejected\",\n\t\t\tfailureCode: \"operation_recovery_exhausted\",\n\t\t\tdiagnostic: truncateMiddle(diagnostic, MAX_DIAGNOSTIC_CHARS),\n\t\t},\n\t\tfalse,\n\t);\n\treturn {\n\t\t...exhaustedResult,\n\t\tdetails: { piToolFailureMemory: retainedRecord },\n\t};\n}\n\nfunction retainBlockedToolFailure(record: ToolFailureMemoryRecord): ToolFailureMemoryRecord {\n\treturn {\n\t\t...record,\n\t\toccurrence: record.occurrence + 1,\n\t\tkindMistakes: (record.kindMistakes ?? record.occurrence) + 1,\n\t};\n}\n\nfunction escapePromptData(value: string): string {\n\treturn value.replaceAll(\"&\", \"\\\\u0026\").replaceAll(\"<\", \"\\\\u003c\").replaceAll(\">\", \"\\\\u003e\");\n}\n\nexport function sanitizeToolFailureContext(\n\tmessages: AgentMessage[],\n\tsystemPrompt: string,\n): { messages: AgentMessage[]; systemPrompt: string } {\n\tconst analysis = analyzeToolFailureContext(messages);\n\tif (analysis.activeRecords.length === 0 && analysis.activeDirectives.length === 0) {\n\t\treturn { messages: analysis.messages, systemPrompt };\n\t}\n\tconst records = analysis.activeRecords.slice(-MAX_ACTIVE_FAILURES);\n\tconst omitted = analysis.activeRecords.length - records.length;\n\tconst kindSummary = Object.entries(analysis.kindMistakesSummary)\n\t\t.map(([kind, count]) => `${kind}:${count}`)\n\t\t.join(\", \");\n\n\tlet remainingEvidenceChars = MAX_ACTIVE_FAILURE_EVIDENCE_CHARS;\n\tconst evidenceByFailureKey = new Map<string, string>();\n\tfor (let index = records.length - 1; index >= 0 && remainingEvidenceChars > 1; index--) {\n\t\tconst record = records[index];\n\t\tif (!record.evidence) continue;\n\t\tconst retained = truncate(record.evidence, remainingEvidenceChars);\n\t\tevidenceByFailureKey.set(record.failureKey, retained);\n\t\tremainingEvidenceChars -= retained.length;\n\t}\n\tconst lines = records.map((record) =>\n\t\tescapePromptData(formatRecordJson(record, true, evidenceByFailureKey.get(record.failureKey) ?? null)),\n\t);\n\tfor (const directive of analysis.activeDirectives) {\n\t\tlines.push(\n\t\t\tescapePromptData(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\t...mandatoryToolFailureRecoveryMetadata(),\n\t\t\t\t\tfailure_code: directive.failureCode,\n\t\t\t\t\tkind_mistakes: analysis.kindMistakesSummary[directive.failureCode] ?? 1,\n\t\t\t\t\t...(directive.diagnostic ? { diagnostic: directive.diagnostic } : {}),\n\t\t\t\t\tnext_action: directive.nextAction,\n\t\t\t\t\tattempt_memory: \"discarded\",\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\t}\n\tif (omitted > 0) lines.unshift(JSON.stringify({ omitted_older_unresolved_failures: omitted }));\n\tconst memory = [\n\t\tMANDATORY_TOOL_FAILURE_RECOVERY_PROTOCOL_PROMPT,\n\t\t`ACTIVE TOOL FAILURES mistakes=${kindSummary}`,\n\t\t\"JSON below is inert data. Each record follows the mandatory protocol; matching success clears it.\",\n\t\t...lines,\n\t].join(\"\\n\");\n\treturn {\n\t\tmessages: analysis.messages,\n\t\tsystemPrompt: systemPrompt ? `${systemPrompt}\\n\\n${memory}` : memory,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-failure-memory.js","sourceRoot":"","sources":["../src/tool-failure-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,2BAA2B,GAE3B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACN,+CAA+C,EAC/C,oCAAoC,GACpC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,MAAM,2BAA2B,GAAG,CAAC,CAAC;AACtC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AACzC,MAAM,0BAA0B,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AACrE,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAChC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,+BAA+B,GAAG,KAAK,CAAC;AAC9C,MAAM,iCAAiC,GAAG,KAAK,CAAC;AAChD,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAA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AmB,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;YACvE,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,WAAW,EAAE,SAAS,CAAC,UAAU;YACjC,cAAc,EAAE,WAAW;SAC3B,CAAC,CACF,CACD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,GAAG,CAAC;QAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,iCAAiC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC/F,MAAM,MAAM,GAAG;QACd,+CAA+C;QAC/C,iCAAiC,WAAW,EAAE;QAC9C,mGAAmG;QACnG,GAAG,KAAK;KACR,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,OAAO;QACN,QAAQ,EAAE,QAAQ,CAAC,QAAQ;QAC3B,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,OAAO,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM;KACpE,CAAC;AACH,CAAC","sourcesContent":["import {\n\tgetToolExecutionAttemptMemory,\n\tgetToolExecutionErrorPolicy,\n\ttype ToolFailurePhase,\n} from \"@caupulican/pi-ai/tool-repair-registry\";\nimport type { AssistantMessage, ToolResultMessage } from \"@caupulican/pi-ai/types\";\nimport {\n\tMANDATORY_TOOL_FAILURE_RECOVERY_PROTOCOL_PROMPT,\n\tmandatoryToolFailureRecoveryMetadata,\n} from \"./tool-failure-recovery-protocol.ts\";\nimport type { AgentMessage, AgentToolCall, AgentToolResult } from \"./types.ts\";\nimport { sanitizeBinaryOutput } from \"./utils/shell-output.ts\";\n\nconst TOOL_FAILURE_MEMORY_VERSION = 1;\nconst TOOL_FAILURE_DIRECTIVE_VERSION = 1;\nconst TOOL_FAILURE_EXECUTION_KEY = Symbol(\"ToolFailureExecutionKey\");\nconst MAX_OPERATION_CHARS = 240;\nconst MAX_FAILURE_CODE_CHARS = 48;\nconst MAX_DIAGNOSTIC_CHARS = 240;\nconst MAX_CORRECTION_CHARS = 480;\nconst MAX_TOOL_FAILURE_EVIDENCE_CHARS = 1_600;\nconst MAX_ACTIVE_FAILURE_EVIDENCE_CHARS = 2_400;\nconst MAX_TOOL_NAME_CHARS = 64;\nconst TOOL_SIGNATURE_HEX_CHARS = 32;\nconst MAX_ACTIVE_FAILURES = 8;\nconst MAX_TRACKED_FAILURES = 64;\nconst REPAIRABLE_REJECTION_CODES = new Set([\"invalid_arguments\", \"malformed_call\", \"unknown_tool\"]);\nconst LEGACY_GENERIC_EXECUTION_CORRECTION =\n\t\"Change the arguments or approach before retrying; do not resend the unchanged operation.\";\nconst BLOCKED_REPLAY_CAVEMAN_CORRECTION =\n\t\"Blocked: this exact operation will not run again this session — change the operation or continue other work.\";\nconst CLOSED_OPERATION_CAVEMAN_CORRECTION =\n\t\"Closed: this exact operation was not executed and will not run again this session — use a different operation or continue other work.\";\n\nexport type ToolFailureState = \"failed\" | \"rejected\";\n\nexport interface ToolFailureMemoryRecord {\n\tversion: typeof TOOL_FAILURE_MEMORY_VERSION;\n\tfailureKey: string;\n\t/** Exact identity is process-internal and omitted from serialized failure memory. */\n\treadonly [TOOL_FAILURE_EXECUTION_KEY]?: string;\n\ttool: string;\n\toperation: string;\n\toccurrence: number;\n\tkindMistakes?: number;\n\tmistakeKind?: string;\n\tstate: ToolFailureState;\n\tphase: ToolFailurePhase;\n\tfailureCode: string;\n\tdiagnostic?: string;\n\t/** Bounded result-scoped harness notice (replay block, circuit state); never displaces the retained diagnostic. */\n\tnote?: string;\n\t/** Bounded tool-owned source evidence needed to construct a changed operation. */\n\tevidence?: string;\n\tcorrection: string;\n\tattemptMemory?: \"discard\";\n}\n\nexport interface ToolFailureMemoryDetails {\n\tpiToolFailureMemory: ToolFailureMemoryRecord;\n}\n\nexport interface ToolFailureDirectiveDetails {\n\tpiToolFailureDirective: {\n\t\tversion: typeof TOOL_FAILURE_DIRECTIVE_VERSION;\n\t\tstate: ToolFailureState;\n\t\tphase: ToolFailurePhase;\n\t\tfailureCode: string;\n\t\tdiagnostic?: string;\n\t\tnextAction: string;\n\t};\n}\n\nexport type ToolFailureResultDetails = ToolFailureMemoryDetails | ToolFailureDirectiveDetails;\n\nexport type ToolFailureMemoryTracker = Map<string, ToolFailureMemoryRecord>;\n\ninterface ToolOperationIdentity {\n\tfailureKey: string;\n\texecutionKey: string;\n\ttool: string;\n\toperation: string;\n}\n\ninterface ActiveFailure {\n\trecord: ToolFailureMemoryRecord;\n\tsequence: number;\n}\n\ninterface FailureContextAnalysis {\n\tmessages: AgentMessage[];\n\tactiveRecords: ToolFailureMemoryRecord[];\n\tactiveDirectives: ToolFailureDirectiveDetails[\"piToolFailureDirective\"][];\n\tkindMistakesSummary: Record<string, number>;\n}\n\nfunction truncate(value: string, maxChars: number): string {\n\tif (value.length <= maxChars) return value;\n\tlet end = maxChars - 1;\n\tconst code = value.charCodeAt(end - 1);\n\tif (code >= 0xd800 && code <= 0xdbff) end--;\n\treturn `${value.slice(0, end)}…`;\n}\n\n/** Normalize and bound tool-owned evidence at every live and persisted ingress. */\nexport function sanitizeToolFailureEvidence(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst sanitized = sanitizeBinaryOutput(value).trim();\n\treturn sanitized ? truncate(sanitized, MAX_TOOL_FAILURE_EVIDENCE_CHARS) : undefined;\n}\n\nfunction truncateMiddle(value: string, maxChars: number): string {\n\tif (value.length <= maxChars) return value;\n\tconst available = maxChars - 1;\n\tlet headEnd = Math.ceil(available / 2);\n\tlet tailStart = value.length - Math.floor(available / 2);\n\tconst headCode = value.charCodeAt(headEnd - 1);\n\tif (headCode >= 0xd800 && headCode <= 0xdbff) headEnd--;\n\tconst tailCode = value.charCodeAt(tailStart);\n\tif (tailCode >= 0xdc00 && tailCode <= 0xdfff) tailStart++;\n\treturn `${value.slice(0, headEnd)}…${value.slice(tailStart)}`;\n}\n\nfunction safeJson(value: unknown): string {\n\ttry {\n\t\treturn JSON.stringify(value) ?? \"null\";\n\t} catch {\n\t\treturn \"[unserializable]\";\n\t}\n}\n\ninterface SignatureHash {\n\tfirst: number;\n\tsecond: number;\n\tthird: number;\n\tfourth: number;\n}\n\nconst VOLATILE_SIGNATURE_PATTERN =\n\t/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|(\\d{4}-\\d{2}-\\d{2}[tT][0-9:.]+(?:z|[+-]\\d{2}:?\\d{2})?)|(\\b[0-9a-f]{16,}\\b)|(\\d{10,})/gi;\nconst MAX_SIGNATURE_DEPTH = 128;\nconst MAX_PREVIEW_DEPTH = 6;\nconst MAX_PREVIEW_ITEMS = 8;\nconst MAX_PREVIEW_STRING_CHARS = 96;\n\nfunction updateHashCode(hash: SignatureHash, code: number): void {\n\thash.first = Math.imul(hash.first ^ code, 0x01000193);\n\thash.second = Math.imul(hash.second ^ code, 0x85ebca6b);\n\thash.third = Math.imul(hash.third ^ code, 0x27d4eb2d);\n\thash.fourth = Math.imul(hash.fourth ^ code, 0x165667b1);\n}\n\nfunction updateHashRange(hash: SignatureHash, value: string, start = 0, end = value.length): void {\n\tfor (let index = start; index < end; index++) updateHashCode(hash, value.charCodeAt(index));\n}\n\nfunction updateNormalizedHashString(hash: SignatureHash, value: string): void {\n\tif (value.length < 10) {\n\t\tupdateExactHashString(hash, value);\n\t\treturn;\n\t}\n\tVOLATILE_SIGNATURE_PATTERN.lastIndex = 0;\n\tlet offset = 0;\n\tlet normalizedLength = value.length;\n\tfor (const match of value.matchAll(VOLATILE_SIGNATURE_PATTERN)) {\n\t\tconst index = match.index;\n\t\tupdateHashRange(hash, value, offset, index);\n\t\tconst replacement = match[1] ? \"<uuid>\" : match[2] ? \"<ts>\" : match[3] ? \"<hex>\" : \"<num>\";\n\t\tupdateHashRange(hash, replacement);\n\t\tnormalizedLength += replacement.length - match[0].length;\n\t\toffset = index + match[0].length;\n\t}\n\tupdateHashRange(hash, value, offset);\n\tupdateHashRange(hash, `:${normalizedLength};`);\n}\n\nfunction updateExactHashString(hash: SignatureHash, value: string): void {\n\tupdateHashRange(hash, value);\n\tupdateHashRange(hash, `:${value.length};`);\n}\n\nfunction updateStructuredHash(\n\thash: SignatureHash,\n\tvalue: unknown,\n\tactive: Set<object>,\n\tdepth: number,\n\tupdateHashString: (hash: SignatureHash, value: string) => void,\n): void {\n\tif (depth > MAX_SIGNATURE_DEPTH) {\n\t\tupdateHashRange(hash, \"depth;\");\n\t\treturn;\n\t}\n\tif (value === null) {\n\t\tupdateHashRange(hash, \"null;\");\n\t\treturn;\n\t}\n\tswitch (typeof value) {\n\t\tcase \"string\":\n\t\t\tupdateHashRange(hash, \"string:\");\n\t\t\tupdateHashString(hash, value);\n\t\t\treturn;\n\t\tcase \"number\":\n\t\t\tupdateHashRange(hash, \"number:\");\n\t\t\tupdateHashString(hash, Object.is(value, -0) ? \"-0\" : String(value));\n\t\t\treturn;\n\t\tcase \"boolean\":\n\t\t\tupdateHashRange(hash, value ? \"true;\" : \"false;\");\n\t\t\treturn;\n\t\tcase \"undefined\":\n\t\t\tupdateHashRange(hash, \"undefined;\");\n\t\t\treturn;\n\t\tcase \"bigint\":\n\t\t\tupdateHashRange(hash, `bigint:${value.toString()};`);\n\t\t\treturn;\n\t\tcase \"symbol\":\n\t\t\tupdateHashRange(hash, `symbol:${String(value.description ?? \"\")};`);\n\t\t\treturn;\n\t\tcase \"function\":\n\t\t\tupdateHashRange(hash, `function:${value.name};`);\n\t\t\treturn;\n\t\tcase \"object\":\n\t\t\tbreak;\n\t}\n\n\tif (active.has(value)) {\n\t\tupdateHashRange(hash, \"circular;\");\n\t\treturn;\n\t}\n\tactive.add(value);\n\tif (Array.isArray(value)) {\n\t\tupdateHashRange(hash, `array:${value.length}[`);\n\t\tfor (const item of value) updateStructuredHash(hash, item, active, depth + 1, updateHashString);\n\t\tupdateHashRange(hash, \"];\");\n\t} else {\n\t\tconst keys = Object.keys(value).sort();\n\t\tupdateHashRange(hash, `object:${keys.length}{`);\n\t\tfor (const key of keys) {\n\t\t\tupdateHashString(hash, key);\n\t\t\tupdateStructuredHash(hash, (value as Record<string, unknown>)[key], active, depth + 1, updateHashString);\n\t\t}\n\t\tupdateHashRange(hash, \"};\");\n\t}\n\tactive.delete(value);\n}\n\nfunction createSignatureHash(): SignatureHash {\n\treturn {\n\t\tfirst: 0x811c9dc5,\n\t\tsecond: 0x9e3779b9,\n\t\tthird: 0x85ebca6b,\n\t\tfourth: 0xc2b2ae35,\n\t};\n}\n\nfunction renderSignatureHash(hash: SignatureHash): string {\n\treturn [hash.first, hash.second, hash.third, hash.fourth]\n\t\t.map((part) => (part >>> 0).toString(16).padStart(8, \"0\"))\n\t\t.join(\"\");\n}\n\nfunction structuredHash(value: unknown, normalizeVolatile: boolean): string {\n\tconst hash = createSignatureHash();\n\tupdateStructuredHash(\n\t\thash,\n\t\tvalue,\n\t\tnew Set(),\n\t\t0,\n\t\tnormalizeVolatile ? updateNormalizedHashString : updateExactHashString,\n\t);\n\treturn renderSignatureHash(hash);\n}\n\nfunction boundedJsonPreview(value: unknown, maxChars: number): string {\n\tlet output = \"\";\n\tlet exhausted = false;\n\tconst active = new Set<object>();\n\tconst append = (text: string): void => {\n\t\tif (exhausted) return;\n\t\tconst available = maxChars - output.length;\n\t\tif (text.length <= available) {\n\t\t\toutput += text;\n\t\t\treturn;\n\t\t}\n\t\tif (available > 1) output += `${text.slice(0, available - 1)}…`;\n\t\texhausted = true;\n\t};\n\tconst visit = (item: unknown, depth: number): void => {\n\t\tif (exhausted) return;\n\t\tif (depth > MAX_PREVIEW_DEPTH) {\n\t\t\tappend('\"[depth]\"');\n\t\t\treturn;\n\t\t}\n\t\tif (typeof item === \"string\") {\n\t\t\tappend(safeJson(truncateMiddle(item, MAX_PREVIEW_STRING_CHARS)));\n\t\t\treturn;\n\t\t}\n\t\tif (item === null || typeof item === \"number\" || typeof item === \"boolean\") {\n\t\t\tappend(String(item));\n\t\t\treturn;\n\t\t}\n\t\tif (typeof item !== \"object\") {\n\t\t\tappend(safeJson(`[${typeof item}]`));\n\t\t\treturn;\n\t\t}\n\t\tif (active.has(item)) {\n\t\t\tappend('\"[circular]\"');\n\t\t\treturn;\n\t\t}\n\t\tactive.add(item);\n\t\tif (Array.isArray(item)) {\n\t\t\tappend(\"[\");\n\t\t\tconst count = Math.min(item.length, MAX_PREVIEW_ITEMS);\n\t\t\tfor (let index = 0; index < count && !exhausted; index++) {\n\t\t\t\tif (index > 0) append(\",\");\n\t\t\t\tvisit(item[index], depth + 1);\n\t\t\t}\n\t\t\tif (item.length > count) append(`${count > 0 ? \",\" : \"\"}\"[+${item.length - count} items]\"`);\n\t\t\tappend(\"]\");\n\t\t} else {\n\t\t\tappend(\"{\");\n\t\t\tlet count = 0;\n\t\t\tlet omitted = 0;\n\t\t\tconst keys = Object.keys(item).sort();\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (count >= MAX_PREVIEW_ITEMS) {\n\t\t\t\t\tomitted++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (count > 0) append(\",\");\n\t\t\t\tappend(safeJson(truncateMiddle(key, MAX_PREVIEW_STRING_CHARS)));\n\t\t\t\tappend(\":\");\n\t\t\t\tvisit((item as Record<string, unknown>)[key], depth + 1);\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif (omitted > 0) append(`${count > 0 ? \",\" : \"\"}\"[omitted]\":${omitted}`);\n\t\t\tappend(\"}\");\n\t\t}\n\t\tactive.delete(item);\n\t};\n\tvisit(value, 0);\n\treturn truncateMiddle(output || \"null\", maxChars);\n}\n\n/**\n * Fingerprint a tool operation without materializing or retaining its serialized payload.\n * Volatile identifiers normalize before hashing; short numbers and ordinary paths remain significant.\n */\n/**\n * Resource-envelope fields are not the operation. Changing `timeout` (or a sibling wait bound)\n * must not mint a new execution identity — that is how a failed command is replayed forever.\n */\nconst OPERATION_ENVELOPE_KEYS = new Set([\n\t\"timeout\",\n\t\"timeoutms\",\n\t\"timeout_ms\",\n\t\"timeoutsec\",\n\t\"timeout_sec\",\n\t\"timeoutseconds\",\n\t\"timeout_seconds\",\n\t\"maxwait\",\n\t\"max_wait\",\n\t\"maxwaitms\",\n\t\"max_wait_ms\",\n\t\"waitms\",\n\t\"wait_ms\",\n\t\"waitsec\",\n\t\"wait_sec\",\n\t\"waitseconds\",\n\t\"wait_seconds\",\n]);\n\nfunction omitOperationEnvelopeFields(value: unknown): unknown {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return value;\n\tconst record = value as Record<string, unknown>;\n\tlet changed = false;\n\tconst next: Record<string, unknown> = {};\n\tfor (const [key, entry] of Object.entries(record)) {\n\t\tif (OPERATION_ENVELOPE_KEYS.has(key.toLowerCase())) {\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tnext[key] = entry;\n\t}\n\treturn changed ? next : value;\n}\n\nexport function normalizeToolSignature(pairs: Array<[string, unknown]>): string {\n\treturn structuredHash(\n\t\tpairs.map(([name, args]) => [name, omitOperationEnvelopeFields(args)]),\n\t\ttrue,\n\t);\n}\n\nfunction toolOperationKey(tool: string, args: unknown, normalizeVolatile: boolean): string {\n\tconst identityArgs = omitOperationEnvelopeFields(args);\n\tconst boundedTool = truncate(tool, MAX_TOOL_NAME_CHARS);\n\tconst hash = createSignatureHash();\n\tconst updateHashString = normalizeVolatile ? updateNormalizedHashString : updateExactHashString;\n\tconst active = new Set<object>();\n\t// Preserve the stable structured-hash wire identity without allocating the two synthetic arrays.\n\tupdateHashRange(hash, \"array:1[array:2[\");\n\tupdateStructuredHash(hash, tool, active, 2, updateHashString);\n\tupdateStructuredHash(hash, identityArgs, active, 2, updateHashString);\n\tupdateHashRange(hash, \"];];\");\n\tconst signature = renderSignatureHash(hash);\n\treturn `${boundedTool}:${signature}`;\n}\n\nfunction operationIdentity(tool: string, args: unknown): ToolOperationIdentity {\n\treturn {\n\t\tfailureKey: toolOperationKey(tool, args, true),\n\t\texecutionKey: toolOperationKey(tool, args, false),\n\t\ttool: truncate(tool, MAX_TOOL_NAME_CHARS),\n\t\toperation: boundedJsonPreview(args, MAX_OPERATION_CHARS),\n\t};\n}\n\nfunction getToolFailureKey(tool: string, args: unknown): string {\n\treturn toolOperationKey(tool, args, true);\n}\n\nexport function getToolExecutionKey(tool: string, args: unknown): string {\n\treturn toolOperationKey(tool, args, false);\n}\n\n/** Read the four hash words already encoded by this module's exact execution-key owner. */\nexport function getToolExecutionKeyHashParts(executionKey: string): readonly [number, number, number, number] {\n\tconst separator = executionKey.lastIndexOf(\":\");\n\tconst signature = executionKey.slice(separator + 1);\n\tif (separator < 0 || signature.length !== TOOL_SIGNATURE_HEX_CHARS || !/^[0-9a-f]+$/.test(signature)) {\n\t\tthrow new TypeError(\"Tool execution key has an invalid hash signature.\");\n\t}\n\treturn [\n\t\tNumber.parseInt(signature.slice(0, 8), 16),\n\t\tNumber.parseInt(signature.slice(8, 16), 16),\n\t\tNumber.parseInt(signature.slice(16, 24), 16),\n\t\tNumber.parseInt(signature.slice(24, 32), 16),\n\t];\n}\n\nexport function getToolFailureRecordExecutionKey(record: ToolFailureMemoryRecord): string | undefined {\n\treturn record[TOOL_FAILURE_EXECUTION_KEY];\n}\n\nexport function getUnresolvedToolFailure(\n\ttracker: ToolFailureMemoryTracker,\n\ttool: string,\n\targs: unknown,\n): ToolFailureMemoryRecord | undefined {\n\treturn tracker.get(getToolFailureKey(tool, args));\n}\n\nexport function readVisibleToolFailureCode(result: ToolResultMessage): string | undefined {\n\tfor (const block of result.content) {\n\t\tif (block.type !== \"text\") continue;\n\t\tconst match = /\"failure_code\"\\s*:\\s*\"([^\"]+)\"/.exec(block.text);\n\t\tif (match) return match[1];\n\t}\n\treturn undefined;\n}\n\nexport function isClosedOperationFailureCode(code: string | undefined): boolean {\n\treturn code === \"operation_recovery_exhausted\" || code === \"recovery_exhausted\";\n}\n\n/** Failures that only a new owner prompt can clear. Do not restore their circuit across user turns. */\nexport function isPromptScopedFailureCode(code: string | undefined): boolean {\n\treturn code === \"owner_authorization_required\";\n}\n\nexport function restoreToolFailureRecord(\n\tresult: ToolResultMessage,\n\ttool: string,\n\targs: unknown,\n): ToolFailureMemoryRecord {\n\tconst executionKey = getToolExecutionKey(tool, args);\n\tconst persisted = readFailureRecord(result.details);\n\tif (persisted) {\n\t\treturn {\n\t\t\t...persisted,\n\t\t\t[TOOL_FAILURE_EXECUTION_KEY]: getToolFailureRecordExecutionKey(persisted) ?? executionKey,\n\t\t};\n\t}\n\tconst identity = operationIdentity(tool, args);\n\treturn {\n\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\tfailureKey: identity.failureKey,\n\t\t[TOOL_FAILURE_EXECUTION_KEY]: executionKey,\n\t\ttool: identity.tool,\n\t\toperation: identity.operation,\n\t\toccurrence: 1,\n\t\tstate: \"failed\",\n\t\tphase: \"execution\",\n\t\tfailureCode: boundedFailureCode(readVisibleToolFailureCode(result) ?? \"tool_error\"),\n\t\tcorrection: fallbackFailureGuidance(\"failed\", false, \"execution\"),\n\t};\n}\n\nexport interface PairedToolResult {\n\ttool: string;\n\targs: unknown;\n\texecutionKey: string;\n\tresult: ToolResultMessage;\n}\n\nexport function forEachPairedToolResult(\n\tmessages: readonly AgentMessage[],\n\tvisit: (pair: PairedToolResult) => boolean | undefined,\n): void {\n\tconst callsById = new Map<string, { name: string; args: unknown }>();\n\tfor (const message of messages) {\n\t\tif (message.role === \"assistant\") {\n\t\t\tfor (const block of message.content) {\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tcallsById.set(block.id, { name: block.name, args: block.arguments });\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"toolResult\") continue;\n\t\tconst call = callsById.get(message.toolCallId);\n\t\tif (!call) continue;\n\t\tif (\n\t\t\tvisit({\n\t\t\t\ttool: call.name,\n\t\t\t\targs: call.args,\n\t\t\t\texecutionKey: getToolExecutionKey(call.name, call.args),\n\t\t\t\tresult: message,\n\t\t\t}) === false\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n}\n\nexport function transcriptHasClosedToolOperation(messages: readonly AgentMessage[]): boolean {\n\tconst closedByExecutionKey = new Map<string, true>();\n\tforEachPairedToolResult(messages, ({ executionKey, result }) => {\n\t\tif (!result.isError) {\n\t\t\tclosedByExecutionKey.delete(executionKey);\n\t\t\treturn;\n\t\t}\n\t\tif (isClosedOperationFailureCode(readVisibleToolFailureCode(result))) {\n\t\t\tclosedByExecutionKey.set(executionKey, true);\n\t\t}\n\t});\n\treturn closedByExecutionKey.size > 0;\n}\n\nfunction boundedFailureCode(value: string): string {\n\tconst normalized = value\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9_.:-]+/g, \"_\")\n\t\t.replace(/^_+|_+$/g, \"\");\n\treturn truncate(normalized || \"tool_error\", MAX_FAILURE_CODE_CHARS);\n}\n\n/**\n * bash.ts's own trailer (`appendStatus`) always ends the message with a line like \"Command\n * exited with code 1\"; a structured result (e.g. run_process) instead puts \"exitCode: 1\" on its\n * own line near the top. Both are anchored to the START of their own line, with at most one\n * leading tool-name token (\"Command\"/\"Python\"/...) — ordinary stdout/stderr prose is never\n * anchored that way, so a captured line like \"container will exit 0 on SIGTERM\" can never be\n * read as the process exit status. Scan from the end of the message so the tool's own trailer —\n * always the last line it appends — outranks any earlier, non-authoritative line that matches.\n */\nconst EXIT_STATUS_LINE_PATTERN = /^(?:\\S+\\s+)?(?:exit(?:ed)?(?:\\s+with)?(?:\\s+code)?|exitcode)\\s*[:=]?\\s*(-?\\d+)\\b/i;\n\n/**\n * bash.ts appends `cwd: <dir>` after its exit trailer on failures. The line is harness status, not\n * a cause: it must never displace a real diagnostic (a path may contain words like \"error\"), and it\n * reaches the model through the process-exit evidence tail instead.\n */\nconst CWD_STATUS_LINE_PATTERN = /^cwd:\\s/i;\n\n/** Tool-owned status/marker lines that carry no cause and never belong in diagnostic or evidence. */\nfunction isFailureStatusLine(line: string): boolean {\n\treturn (\n\t\t/^command (?:exited with code|timed out after|aborted|killed after)\\b/i.test(line) ||\n\t\t/^outcome:\\s*(?:failed|aborted|timeout|output_limit)\\b/i.test(line) ||\n\t\t/^exitcode:\\s*-?\\d+\\b/i.test(line) ||\n\t\t/^(?:stdout|stderr):(?:\\s*\\(empty\\))?$/i.test(line)\n\t);\n}\n\nfunction processExitFailureCode(message: string): string | undefined {\n\tconst lines = message.split(/\\r\\n|\\n/);\n\tfor (let index = lines.length - 1; index >= 0; index--) {\n\t\tconst match = EXIT_STATUS_LINE_PATTERN.exec(lines[index].trim());\n\t\tif (match) return boundedFailureCode(`exit_${match[1]}`);\n\t}\n\treturn undefined;\n}\n\nexport function classifyToolFailure(message: string, errorClass?: string): string {\n\t// A tool-owned terminal status is authoritative; stdout may contain arbitrary all-caps identifiers.\n\tconst exitFailureCode = processExitFailureCode(message);\n\tif (exitFailureCode) return exitFailureCode;\n\tconst errno = /\\b(E[A-Z][A-Z0-9_]{2,})\\b/.exec(message)?.[1];\n\tif (errno) return boundedFailureCode(errno);\n\treturn boundedFailureCode(errorClass ?? \"tool_error\");\n}\n\nfunction isToolFailurePhase(value: unknown): value is ToolFailurePhase {\n\treturn (\n\t\tvalue === \"validation\" ||\n\t\tvalue === \"policy\" ||\n\t\tvalue === \"preflight\" ||\n\t\tvalue === \"execution\" ||\n\t\tvalue === \"timeout\" ||\n\t\tvalue === \"cancelled\" ||\n\t\tvalue === \"provisioning\"\n\t);\n}\n\nfunction inferToolFailurePhase(state: ToolFailureState, failureCode: string): ToolFailurePhase {\n\tif (failureCode === \"malformed_call\" || failureCode === \"unknown_tool\" || failureCode === \"invalid_arguments\") {\n\t\treturn \"validation\";\n\t}\n\tif (\n\t\tfailureCode === \"blocked\" ||\n\t\tfailureCode === \"permission_denied\" ||\n\t\tfailureCode === \"owner_authorization_required\"\n\t) {\n\t\treturn \"policy\";\n\t}\n\tif (failureCode === \"preflight_error\") return \"preflight\";\n\tif (failureCode === \"aborted\" || failureCode === \"cancelled\") return \"cancelled\";\n\tif (failureCode === \"timeout\" || failureCode === \"etimedout\") return \"timeout\";\n\tif (failureCode === \"provisioning_failed\" || failureCode === \"command_not_found\") return \"provisioning\";\n\treturn state === \"rejected\" ? \"validation\" : \"execution\";\n}\n\nfunction fallbackFailureGuidance(state: ToolFailureState, hasDiagnostic: boolean, phase: ToolFailurePhase): string {\n\tif (phase === \"preflight\") {\n\t\treturn hasDiagnostic\n\t\t\t? \"Arguments valid; preflight failed before execution. Resolve diagnostic/host condition before retry.\"\n\t\t\t: \"Arguments valid; preflight failed before execution. Inspect host policy/capability before retry.\";\n\t}\n\tif (phase === \"policy\") return \"Resolve authority/policy restriction or choose allowed approach before retry.\";\n\tif (phase === \"cancelled\") return \"Retry only when operation remains required, cancellation condition cleared.\";\n\tif (phase === \"timeout\") return \"Narrow/split work; retry once only when safe.\";\n\tif (phase === \"provisioning\") {\n\t\treturn hasDiagnostic\n\t\t\t? \"Fix provisioning diagnostic; retry only after environment changes.\"\n\t\t\t: \"Inspect tool availability; request bounded provisioning diagnostic before retry.\";\n\t}\n\treturn state === \"rejected\"\n\t\t? \"Re-read current tool schema; change invalid operation before retry.\"\n\t\t: hasDiagnostic\n\t\t\t? \"Read diagnostic; identify cause; repair parameters or corrective state before retry.\"\n\t\t\t: \"No diagnostic output. Inspect tool contract or request bounded diagnostic before retry.\";\n}\n\nexport function toolFailureCorrection(\n\tmessage: string,\n\tstate: ToolFailureState,\n\tphase: ToolFailurePhase = state === \"rejected\" ? \"validation\" : \"execution\",\n): string {\n\tconst policy = getToolExecutionErrorPolicy(message);\n\treturn policy\n\t\t? truncate(policy.guidance, MAX_CORRECTION_CHARS)\n\t\t: fallbackFailureGuidance(state, message.trim().length > 0, phase);\n}\n\nfunction extractFailureDiagnostic(\n\tmessage: string,\n\tallowUnclassifiedFallback: boolean,\n\trequireStrongSignal = false,\n): string | undefined {\n\tconst rawLines = sanitizeBinaryOutput(message).replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\");\n\tconst strongDiagnosticPattern =\n\t\t/^(?:(?:error(?:\\[[^\\]]+\\])?|fatal(?: error)?|panic|fail(?:ed|ure)?|invalid|unknown|unsupported|not found|no such|cannot|can't|missing|denied|refused|usage)(?:\\b|:)|[a-z][a-z0-9_.]*error(?::|$)|thread .+ panicked at\\b|--- fail:|\\[fail(?:ed)?\\]|not ok\\b|[×✗]\\s|.{1,160}:\\s+(?:error(?:\\[[^\\]]+\\])?|fatal(?: error)?)(?:\\b|:))/i;\n\tconst stderrMarkerIndex = rawLines.findLastIndex((line) => /^stderr:\\s*$/i.test(line.trim()));\n\tif (stderrMarkerIndex >= 0) {\n\t\tconst stderrLines = rawLines\n\t\t\t.slice(stderrMarkerIndex + 1)\n\t\t\t.map((line) => line.trim())\n\t\t\t.filter(\n\t\t\t\t(line) =>\n\t\t\t\t\tline.length > 0 &&\n\t\t\t\t\t!/^command (?:exited with code|timed out after|aborted|killed after)\\b/i.test(line) &&\n\t\t\t\t\t!CWD_STATUS_LINE_PATTERN.test(line),\n\t\t\t);\n\t\tif (stderrLines.length > 0) {\n\t\t\tconst classified = stderrLines.find((line) => strongDiagnosticPattern.test(line));\n\t\t\tif (classified) return truncateMiddle(classified, MAX_DIAGNOSTIC_CHARS);\n\t\t\t// No stderr line carries a strong signal. Under requireStrongSignal, the caller has\n\t\t\t// already decided uncatalogued output must never be fabricated into a diagnostic (see\n\t\t\t// assessToolFailure) — falling back to the last raw stderr lines here would defeat that\n\t\t\t// guarantee for the common bash case, so fall through to the same allowUnclassifiedFallback\n\t\t\t// gate the no-stderr path below applies.\n\t\t\tif (!requireStrongSignal) {\n\t\t\t\treturn truncateMiddle(stderrLines.slice(-4).join(\" | \"), MAX_DIAGNOSTIC_CHARS);\n\t\t\t}\n\t\t}\n\t}\n\tconst lines = rawLines\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0 && !isFailureStatusLine(line) && !CWD_STATUS_LINE_PATTERN.test(line));\n\tif (lines.length === 0) return undefined;\n\tconst diagnosticPattern = requireStrongSignal\n\t\t? strongDiagnosticPattern\n\t\t: /(?:^|\\b)(?:error|fatal|fail(?:ed|ure)?|invalid|unknown|unsupported|not found|no such|cannot|can't|missing|denied|refused|usage)(?:\\b|:)/i;\n\tconst classified = requireStrongSignal\n\t\t? lines.find((line) => diagnosticPattern.test(line))\n\t\t: [...lines].reverse().find((line) => diagnosticPattern.test(line));\n\tconst diagnostic = classified ?? (allowUnclassifiedFallback ? lines.at(-1) : undefined);\n\treturn diagnostic ? truncateMiddle(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;\n}\n\n/**\n * Bounded raw-output tail of an executed process-exit failure. Evidence is the raw-data channel:\n * it keeps the trailing lines that strong-signal diagnostic classification refuses to promote, so\n * strictness never destroys the output needed to construct a changed operation.\n */\nfunction extractProcessExitEvidence(message: string): string | undefined {\n\tconst lines = sanitizeBinaryOutput(message)\n\t\t.replaceAll(\"\\r\\n\", \"\\n\")\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0 && !isFailureStatusLine(line));\n\tif (lines.length === 0) return undefined;\n\tlet start = lines.length - 1;\n\tlet retainedChars = lines[start].length;\n\twhile (start > 0 && retainedChars + 1 + lines[start - 1].length <= MAX_TOOL_FAILURE_EVIDENCE_CHARS) {\n\t\tstart--;\n\t\tretainedChars += 1 + lines[start].length;\n\t}\n\tlet tail = lines.slice(start).join(\"\\n\");\n\tif (tail.length > MAX_TOOL_FAILURE_EVIDENCE_CHARS) {\n\t\tlet tailStart = tail.length - MAX_TOOL_FAILURE_EVIDENCE_CHARS;\n\t\tconst firstCode = tail.charCodeAt(tailStart);\n\t\tif (firstCode >= 0xdc00 && firstCode <= 0xdfff) tailStart++;\n\t\ttail = tail.slice(tailStart);\n\t}\n\treturn sanitizeToolFailureEvidence(tail);\n}\n\nexport interface ToolFailureAssessment {\n\tfailureCode: string;\n\tphase: ToolFailurePhase;\n\tdiagnostic?: string;\n\t/** Bounded raw-output tail of an executed process-exit failure. */\n\tevidence?: string;\n\tguidance: string;\n\t/** Catalogued per-error guidance; set only when a registry policy matched the failure message. */\n\tpolicyGuidance?: string;\n\tattemptMemory?: \"discard\";\n}\n\nexport function assessToolFailure(\n\tmessage: string,\n\tstate: ToolFailureState,\n\terrorClass?: string,\n): ToolFailureAssessment {\n\tconst policy = getToolExecutionErrorPolicy(message);\n\tconst exitFailureCode = processExitFailureCode(message);\n\tconst retainPolicyDiagnostic = policy?.retainDiagnostic === true;\n\tconst diagnostic =\n\t\tstate === \"failed\" && (!policy || policy.retainDiagnostic)\n\t\t\t? extractFailureDiagnostic(\n\t\t\t\t\tmessage,\n\t\t\t\t\texitFailureCode === undefined && (errorClass !== undefined || retainPolicyDiagnostic),\n\t\t\t\t\texitFailureCode !== undefined && !retainPolicyDiagnostic,\n\t\t\t\t)\n\t\t\t: undefined;\n\tconst evidence =\n\t\tstate === \"failed\" && exitFailureCode !== undefined ? extractProcessExitEvidence(message) : undefined;\n\tconst failureCode = policy?.failureCode ?? classifyToolFailure(message, errorClass);\n\treturn {\n\t\tfailureCode,\n\t\tphase: policy?.phase ?? inferToolFailurePhase(state, failureCode),\n\t\t...(diagnostic ? { diagnostic } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\tguidance: policy\n\t\t\t? truncate(policy.guidance, MAX_CORRECTION_CHARS)\n\t\t\t: fallbackFailureGuidance(state, diagnostic !== undefined, inferToolFailurePhase(state, failureCode)),\n\t\t...(policy ? { policyGuidance: truncate(policy.guidance, MAX_CORRECTION_CHARS) } : {}),\n\t\t...(policy?.attemptMemory === \"discard\" ? { attemptMemory: \"discard\" as const } : {}),\n\t};\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readFailureRecord(details: unknown): ToolFailureMemoryRecord | undefined {\n\tif (!isRecord(details) || !isRecord(details.piToolFailureMemory)) return undefined;\n\tconst candidate = details.piToolFailureMemory;\n\tif (\n\t\tcandidate.version !== TOOL_FAILURE_MEMORY_VERSION ||\n\t\ttypeof candidate.failureKey !== \"string\" ||\n\t\ttypeof candidate.tool !== \"string\" ||\n\t\ttypeof candidate.operation !== \"string\" ||\n\t\ttypeof candidate.occurrence !== \"number\" ||\n\t\t!Number.isSafeInteger(candidate.occurrence) ||\n\t\tcandidate.occurrence < 1 ||\n\t\t(candidate.state !== \"failed\" && candidate.state !== \"rejected\") ||\n\t\ttypeof candidate.failureCode !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\tconst diagnostic =\n\t\ttypeof candidate.diagnostic === \"string\" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;\n\tconst note = typeof candidate.note === \"string\" ? truncate(candidate.note, MAX_DIAGNOSTIC_CHARS) : undefined;\n\tconst evidence = sanitizeToolFailureEvidence(candidate.evidence);\n\tconst retainedCorrection =\n\t\ttypeof candidate.correction === \"string\" ? truncate(candidate.correction, MAX_CORRECTION_CHARS) : undefined;\n\tconst correction =\n\t\tcandidate.state === \"failed\" && retainedCorrection === LEGACY_GENERIC_EXECUTION_CORRECTION\n\t\t\t? fallbackFailureGuidance(\"failed\", diagnostic !== undefined, \"execution\")\n\t\t\t: (retainedCorrection ?? toolFailureCorrection(\"\", candidate.state));\n\tconst phase = isToolFailurePhase(candidate.phase)\n\t\t? candidate.phase\n\t\t: inferToolFailurePhase(candidate.state, candidate.failureCode);\n\tconst candidateExecutionKey: unknown = Reflect.get(candidate, TOOL_FAILURE_EXECUTION_KEY);\n\treturn {\n\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\tfailureKey: truncate(candidate.failureKey, MAX_TOOL_NAME_CHARS + 1 + TOOL_SIGNATURE_HEX_CHARS),\n\t\t...(typeof candidateExecutionKey === \"string\"\n\t\t\t? {\n\t\t\t\t\t[TOOL_FAILURE_EXECUTION_KEY]: truncate(\n\t\t\t\t\t\tcandidateExecutionKey,\n\t\t\t\t\t\tMAX_TOOL_NAME_CHARS + 1 + TOOL_SIGNATURE_HEX_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\ttool: truncate(candidate.tool, MAX_TOOL_NAME_CHARS),\n\t\toperation: truncateMiddle(candidate.operation, MAX_OPERATION_CHARS),\n\t\toccurrence: candidate.occurrence,\n\t\tstate: candidate.state,\n\t\tphase,\n\t\tfailureCode: boundedFailureCode(candidate.failureCode),\n\t\tdiagnostic,\n\t\tnote,\n\t\tevidence,\n\t\tcorrection,\n\t};\n}\n\nfunction readFailureDirective(details: unknown): ToolFailureDirectiveDetails[\"piToolFailureDirective\"] | undefined {\n\tif (!isRecord(details) || !isRecord(details.piToolFailureDirective)) return undefined;\n\tconst candidate = details.piToolFailureDirective;\n\tif (\n\t\tcandidate.version !== TOOL_FAILURE_DIRECTIVE_VERSION ||\n\t\ttypeof candidate.failureCode !== \"string\" ||\n\t\ttypeof candidate.nextAction !== \"string\"\n\t) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tversion: TOOL_FAILURE_DIRECTIVE_VERSION,\n\t\tstate: candidate.state === \"rejected\" ? \"rejected\" : \"failed\",\n\t\tphase: isToolFailurePhase(candidate.phase)\n\t\t\t? candidate.phase\n\t\t\t: inferToolFailurePhase(\"failed\", candidate.failureCode),\n\t\tfailureCode: boundedFailureCode(candidate.failureCode),\n\t\tdiagnostic:\n\t\t\ttypeof candidate.diagnostic === \"string\" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,\n\t\tnextAction: truncate(candidate.nextAction, MAX_CORRECTION_CHARS),\n\t};\n}\n\nexport interface ToolFailureTelemetry {\n\tstate: ToolFailureState;\n\tphase: ToolFailurePhase;\n\tfailureCode: string;\n\tdiagnostic?: string;\n\tnextAction: string;\n}\n\n/** Read only bounded failure identity and guidance; operation arguments never cross this telemetry boundary. */\nexport function readToolFailureTelemetry(details: unknown): ToolFailureTelemetry | undefined {\n\tconst record = readFailureRecord(details);\n\tif (record) {\n\t\treturn {\n\t\t\tstate: record.state,\n\t\t\tphase: record.phase,\n\t\t\tfailureCode: record.failureCode,\n\t\t\t...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),\n\t\t\tnextAction: record.correction,\n\t\t};\n\t}\n\tconst directive = readFailureDirective(details);\n\tif (!directive) return undefined;\n\treturn {\n\t\tstate: directive.state,\n\t\tphase: directive.phase,\n\t\tfailureCode: directive.failureCode,\n\t\t...(directive.diagnostic ? { diagnostic: directive.diagnostic } : {}),\n\t\tnextAction: directive.nextAction,\n\t};\n}\n\nfunction firstText(message: ToolResultMessage): string {\n\tconst content = message.content;\n\tif (typeof content === \"string\") return content;\n\tif (Array.isArray(content)) {\n\t\tfor (let index = 0; index < content.length; index++) {\n\t\t\tconst block = content[index];\n\t\t\tif (block.type === \"text\") return block.text;\n\t\t}\n\t}\n\treturn \"\";\n}\n\nfunction fastTextSignature(text: string): string {\n\tif (text.length <= 128) return text;\n\treturn `${text.length}:${text.slice(0, 48)}:${text.slice(-48)}`;\n}\n\nfunction analyzeToolFailureContext(messages: AgentMessage[]): FailureContextAnalysis {\n\tconst callById = new Map<string, AgentToolCall>();\n\tconst omittedCallIds = new Set<string>();\n\tconst orphanFailedResults = new Set<ToolResultMessage>();\n\tconst active = new Map<string, ActiveFailure>();\n\tconst activeDirectives = new Map<string, ToolFailureDirectiveDetails[\"piToolFailureDirective\"]>();\n\tlet sequence = 0;\n\tconst kindMistakesMap = new Map<string, number>();\n\n\tconst latestSuccessfulByOpKey = new Map<string, string>();\n\tconst latestSuccessfulByPayloadKey = new Map<string, string>();\n\n\tfor (let index = 0; index < messages.length; index++) {\n\t\tconst message = messages[index];\n\t\tif (message.role === \"assistant\") {\n\t\t\tactiveDirectives.clear();\n\t\t\tconst content = message.content;\n\t\t\tfor (let blockIdx = 0; blockIdx < content.length; blockIdx++) {\n\t\t\t\tconst block = content[blockIdx];\n\t\t\t\tif (block.type !== \"toolCall\") continue;\n\t\t\t\tcallById.set(block.id, block);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"toolResult\") continue;\n\n\t\tconst call = callById.get(message.toolCallId);\n\t\tcallById.delete(message.toolCallId);\n\t\tconst textPayload = firstText(message);\n\t\tconst isFailure = message.isError === true || textPayload.startsWith(\"[harness] \");\n\t\tif (isFailure) {\n\t\t\tconst toolName = call?.name ?? message.toolName;\n\t\t\tconst kindCount = (kindMistakesMap.get(toolName) ?? 0) + 1;\n\t\t\tkindMistakesMap.set(toolName, kindCount);\n\n\t\t\tconst directive = readFailureDirective(message.details);\n\t\t\tif (directive) {\n\t\t\t\tactiveDirectives.delete(directive.failureCode);\n\t\t\t\tactiveDirectives.set(directive.failureCode, directive);\n\t\t\t\tif (call) omittedCallIds.add(call.id);\n\t\t\t\telse orphanFailedResults.add(message);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst retained = readFailureRecord(message.details);\n\t\t\tconst state = retained?.state ?? \"failed\";\n\t\t\tconst assessment = retained ? undefined : assessToolFailure(textPayload, state);\n\t\t\tlet failureKey: string;\n\t\t\tlet executionKey: string | undefined;\n\t\t\tlet tool: string;\n\t\t\tlet operation: string;\n\t\t\tif (retained) {\n\t\t\t\tfailureKey = retained.failureKey;\n\t\t\t\texecutionKey = call\n\t\t\t\t\t? getToolExecutionKey(call.name, call.arguments)\n\t\t\t\t\t: getToolFailureRecordExecutionKey(retained);\n\t\t\t\ttool = retained.tool;\n\t\t\t\toperation = retained.operation;\n\t\t\t} else {\n\t\t\t\tconst identity = operationIdentity(\n\t\t\t\t\tcall?.name ?? message.toolName,\n\t\t\t\t\tcall?.arguments ?? { toolCallId: message.toolCallId },\n\t\t\t\t);\n\t\t\t\tfailureKey = identity.failureKey;\n\t\t\t\texecutionKey = identity.executionKey;\n\t\t\t\ttool = identity.tool;\n\t\t\t\toperation = identity.operation;\n\t\t\t}\n\t\t\tconst previous = active.get(failureKey)?.record;\n\t\t\tconst occurrence = Math.max(retained?.occurrence ?? 0, (previous?.occurrence ?? 0) + 1);\n\t\t\tconst record: ToolFailureMemoryRecord = {\n\t\t\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\t\t\tfailureKey,\n\t\t\t\t...(executionKey ? { [TOOL_FAILURE_EXECUTION_KEY]: executionKey } : {}),\n\t\t\t\ttool,\n\t\t\t\toperation,\n\t\t\t\toccurrence,\n\t\t\t\tkindMistakes: kindCount,\n\t\t\t\tmistakeKind: toolName,\n\t\t\t\tstate,\n\t\t\t\tphase: retained?.phase ?? assessment?.phase ?? inferToolFailurePhase(state, \"tool_error\"),\n\t\t\t\tfailureCode: retained?.failureCode ?? assessment?.failureCode ?? \"tool_error\",\n\t\t\t\tdiagnostic: retained?.diagnostic ?? assessment?.diagnostic,\n\t\t\t\tevidence: retained?.evidence,\n\t\t\t\tcorrection:\n\t\t\t\t\tretained?.correction ??\n\t\t\t\t\tassessment?.guidance ??\n\t\t\t\t\tfallbackFailureGuidance(state, false, inferToolFailurePhase(state, \"tool_error\")),\n\t\t\t};\n\t\t\tactive.delete(failureKey);\n\t\t\tactive.set(failureKey, { record, sequence: sequence++ });\n\t\t\twhile (active.size > MAX_TRACKED_FAILURES) {\n\t\t\t\tconst oldest = active.keys().next().value;\n\t\t\t\tif (oldest === undefined) break;\n\t\t\t\tactive.delete(oldest);\n\t\t\t}\n\t\t\tif (call) omittedCallIds.add(call.id);\n\t\t\telse orphanFailedResults.add(message);\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (call) {\n\t\t\tconst opKey = getToolFailureKey(call.name, call.arguments);\n\t\t\tactive.delete(opKey);\n\t\t\tconst previousOperationCallId = latestSuccessfulByOpKey.get(opKey);\n\t\t\tif (previousOperationCallId) omittedCallIds.add(previousOperationCallId);\n\t\t\tlatestSuccessfulByOpKey.set(opKey, call.id);\n\n\t\t\tconst textPayload = firstText(message);\n\t\t\tif (textPayload.length >= 64) {\n\t\t\t\tconst payloadKey = `payload:${fastTextSignature(textPayload)}`;\n\t\t\t\tconst previousPayloadCallId = latestSuccessfulByPayloadKey.get(payloadKey);\n\t\t\t\tif (previousPayloadCallId) omittedCallIds.add(previousPayloadCallId);\n\t\t\t\tlatestSuccessfulByPayloadKey.set(payloadKey, call.id);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst kindMistakesSummary = Object.fromEntries(kindMistakesMap);\n\n\tif (omittedCallIds.size === 0 && orphanFailedResults.size === 0) {\n\t\treturn { messages, activeRecords: [], activeDirectives: [], kindMistakesSummary };\n\t}\n\n\tconst filteredMessages: AgentMessage[] = [];\n\tfor (let index = 0; index < messages.length; index++) {\n\t\tconst message = messages[index];\n\t\tif (message.role === \"toolResult\") {\n\t\t\tif (omittedCallIds.has(message.toolCallId) || orphanFailedResults.has(message)) continue;\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role !== \"assistant\") {\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tconst content = message.content;\n\t\tif (content.length === 1) {\n\t\t\tconst block = content[0];\n\t\t\tif (block.type === \"toolCall\" && omittedCallIds.has(block.id)) continue;\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tlet hasOmitted = false;\n\t\tfor (let blockIdx = 0; blockIdx < content.length; blockIdx++) {\n\t\t\tconst block = content[blockIdx];\n\t\t\tif (block.type === \"toolCall\" && omittedCallIds.has(block.id)) {\n\t\t\t\thasOmitted = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!hasOmitted) {\n\t\t\tfilteredMessages.push(message);\n\t\t\tcontinue;\n\t\t}\n\t\tconst retainedContent = content.filter((block) => block.type !== \"toolCall\" || !omittedCallIds.has(block.id));\n\t\tif (retainedContent.length > 0) {\n\t\t\tfilteredMessages.push({ ...message, content: retainedContent } satisfies AssistantMessage);\n\t\t}\n\t}\n\tconst activeRecords = [...active.values()]\n\t\t.sort((left, right) => left.sequence - right.sequence)\n\t\t.map(({ record }) => record);\n\treturn {\n\t\tmessages: filteredMessages,\n\t\tactiveRecords,\n\t\tactiveDirectives: [...activeDirectives.values()],\n\t\tkindMistakesSummary,\n\t};\n}\n\nexport function createToolFailureMemoryTracker(messages: AgentMessage[]): ToolFailureMemoryTracker {\n\treturn new Map(analyzeToolFailureContext(messages).activeRecords.map((record) => [record.failureKey, record]));\n}\n\nexport function rememberToolFailure(\n\ttracker: ToolFailureMemoryTracker,\n\ttool: string,\n\targs: unknown,\n\tstate: ToolFailureState,\n\tfailureCode: string,\n\tcorrection: string,\n\tdiagnostic?: string,\n\tphase: ToolFailurePhase = inferToolFailurePhase(state, failureCode),\n\tevidence?: string,\n): ToolFailureMemoryRecord {\n\tlet kindCount = 1;\n\tfor (const previous of tracker.values()) {\n\t\tif (previous.tool === tool) {\n\t\t\tkindCount = Math.max(kindCount, (previous.kindMistakes ?? previous.occurrence) + 1);\n\t\t}\n\t}\n\tconst isDiscard = getToolExecutionAttemptMemory(failureCode) === \"discard\";\n\tif (isDiscard) {\n\t\tfor (const [failureKey, previous] of tracker) {\n\t\t\tif (previous.tool === tool && previous.failureCode === failureCode) tracker.delete(failureKey);\n\t\t}\n\t}\n\tconst identity = isDiscard ? undefined : operationIdentity(tool, args);\n\tconst previous = identity ? tracker.get(identity.failureKey) : undefined;\n\tconst record: ToolFailureMemoryRecord = {\n\t\tversion: TOOL_FAILURE_MEMORY_VERSION,\n\t\tfailureKey: identity ? identity.failureKey : `directive:${boundedFailureCode(failureCode)}`,\n\t\t[TOOL_FAILURE_EXECUTION_KEY]: identity ? identity.executionKey : getToolExecutionKey(tool, args),\n\t\ttool: identity ? identity.tool : truncate(tool, MAX_TOOL_NAME_CHARS),\n\t\toperation: identity ? identity.operation : \"[discarded]\",\n\t\toccurrence: isDiscard ? 1 : (previous?.occurrence ?? 0) + 1,\n\t\tkindMistakes: kindCount,\n\t\tmistakeKind: tool,\n\t\tstate,\n\t\tphase,\n\t\tfailureCode: boundedFailureCode(failureCode),\n\t\tdiagnostic: diagnostic ? truncate(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,\n\t\tevidence: sanitizeToolFailureEvidence(evidence),\n\t\tcorrection: truncate(correction, MAX_CORRECTION_CHARS),\n\t\t...(isDiscard ? { attemptMemory: \"discard\" as const } : {}),\n\t};\n\tif (isDiscard) return record;\n\tif (identity) {\n\t\ttracker.delete(identity.failureKey);\n\t\ttracker.set(identity.failureKey, record);\n\t\twhile (tracker.size > MAX_TRACKED_FAILURES) {\n\t\t\tconst oldest = tracker.keys().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\ttracker.delete(oldest);\n\t\t}\n\t}\n\treturn record;\n}\n\nexport function clearToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): void {\n\tconst failureKey = getToolFailureKey(tool, args);\n\tconst record = tracker.get(failureKey);\n\tconst executionKey = record ? getToolFailureRecordExecutionKey(record) : undefined;\n\tif (!executionKey || executionKey === getToolExecutionKey(tool, args)) tracker.delete(failureKey);\n}\n\nfunction failureGuidance(record: ToolFailureMemoryRecord): { repair: string } | { next_action: string } {\n\treturn record.state === \"rejected\" && REPAIRABLE_REJECTION_CODES.has(record.failureCode)\n\t\t? { repair: record.correction }\n\t\t: { next_action: record.correction };\n}\n\nfunction formatRecordJson(\n\trecord: ToolFailureMemoryRecord,\n\tincludeOperation = false,\n\tevidence: string | null | undefined = record.evidence,\n): string {\n\tconst guidance = failureGuidance(record);\n\treturn JSON.stringify({\n\t\t...mandatoryToolFailureRecoveryMetadata(),\n\t\tfailure_key: record.failureKey,\n\t\tocc: record.occurrence,\n\t\tkind_mistakes: record.kindMistakes ?? record.occurrence,\n\t\tmistake_kind: record.mistakeKind ?? record.tool,\n\t\tstate: record.state,\n\t\tphase: record.phase,\n\t\ttool: record.tool,\n\t\t...(includeOperation ? { operation: record.operation } : {}),\n\t\tfailure_code: record.failureCode,\n\t\t...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),\n\t\t...(record.note ? { note: record.note } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\t...guidance,\n\t\t...(record.attemptMemory === \"discard\" ? { attempt_memory: \"discarded\" } : {}),\n\t});\n}\n\nexport function createToolFailureResult(\n\trecord: ToolFailureMemoryRecord,\n\tterminate?: boolean,\n): AgentToolResult<ToolFailureResultDetails> {\n\tconst discardAttempt = record.attemptMemory === \"discard\";\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: `[harness] ${formatRecordJson(record, false)}`,\n\t\t\t},\n\t\t],\n\t\tdetails: discardAttempt\n\t\t\t? {\n\t\t\t\t\tpiToolFailureDirective: {\n\t\t\t\t\t\tversion: TOOL_FAILURE_DIRECTIVE_VERSION,\n\t\t\t\t\t\tstate: record.state,\n\t\t\t\t\t\tphase: record.phase,\n\t\t\t\t\t\tfailureCode: record.failureCode,\n\t\t\t\t\t\t...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),\n\t\t\t\t\t\tnextAction: record.correction,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: { piToolFailureMemory: record },\n\t\t...(terminate === undefined ? {} : { terminate }),\n\t};\n}\n\nexport function createRepeatedToolFailureResult(\n\trecord: ToolFailureMemoryRecord,\n): AgentToolResult<ToolFailureMemoryDetails> {\n\tconst retainedRecord = retainBlockedToolFailure(record);\n\tconst replayNotice = truncateMiddle(\n\t\t`The unchanged operation was not executed. Unchanged replay blocked after ${record.failureCode}`,\n\t\tMAX_DIAGNOSTIC_CHARS,\n\t);\n\tconst blockedResult = createToolFailureResult({\n\t\t...retainedRecord,\n\t\tstate: \"rejected\",\n\t\tfailureCode: \"repeated_failed_operation\",\n\t\t...(retainedRecord.diagnostic\n\t\t\t? { note: replayNotice }\n\t\t\t: { diagnostic: replayNotice, correction: BLOCKED_REPLAY_CAVEMAN_CORRECTION }),\n\t});\n\treturn {\n\t\t...blockedResult,\n\t\t// The visible result leads with the retained root cause and carries the replay notice as a\n\t\t// note, while retained memory keeps the authoritative cause so later blocks do not\n\t\t// recursively wrap synthetic failures.\n\t\tdetails: { piToolFailureMemory: retainedRecord },\n\t};\n}\n\nexport function createToolFailureRecoveryExhaustedResult(\n\trecord: ToolFailureMemoryRecord,\n\tnote: string,\n): AgentToolResult<ToolFailureMemoryDetails> {\n\tconst retainedRecord = retainBlockedToolFailure(record);\n\tconst exhaustedResult = createToolFailureResult(\n\t\t{\n\t\t\t...retainedRecord,\n\t\t\tstate: \"rejected\",\n\t\t\tfailureCode: \"recovery_exhausted\",\n\t\t\tnote: truncateMiddle(note, MAX_DIAGNOSTIC_CHARS),\n\t\t\tcorrection:\n\t\t\t\t\"Stop retrying tools in this run. Report the unresolved failure and the user or environment action required to continue.\",\n\t\t},\n\t\ttrue,\n\t);\n\treturn {\n\t\t...exhaustedResult,\n\t\tdetails: { piToolFailureMemory: retainedRecord },\n\t};\n}\n\nexport function createToolFailureOperationExhaustedResult(\n\trecord: ToolFailureMemoryRecord,\n\tnote: string,\n): AgentToolResult<ToolFailureMemoryDetails> {\n\tconst retainedRecord = {\n\t\t...retainBlockedToolFailure(record),\n\t\tcorrection: CLOSED_OPERATION_CAVEMAN_CORRECTION,\n\t};\n\tconst exhaustedResult = createToolFailureResult(\n\t\t{\n\t\t\t...retainedRecord,\n\t\t\tstate: \"rejected\",\n\t\t\tfailureCode: \"operation_recovery_exhausted\",\n\t\t\tnote: truncateMiddle(note, MAX_DIAGNOSTIC_CHARS),\n\t\t},\n\t\tfalse,\n\t);\n\treturn {\n\t\t...exhaustedResult,\n\t\tdetails: { piToolFailureMemory: retainedRecord },\n\t};\n}\n\nfunction retainBlockedToolFailure(record: ToolFailureMemoryRecord): ToolFailureMemoryRecord {\n\treturn {\n\t\t...record,\n\t\toccurrence: record.occurrence + 1,\n\t\tkindMistakes: (record.kindMistakes ?? record.occurrence) + 1,\n\t};\n}\n\nfunction escapePromptData(value: string): string {\n\treturn value.replaceAll(\"&\", \"\\\\u0026\").replaceAll(\"<\", \"\\\\u003c\").replaceAll(\">\", \"\\\\u003e\");\n}\n\nexport function sanitizeToolFailureContext(\n\tmessages: AgentMessage[],\n\tsystemPrompt: string,\n): { messages: AgentMessage[]; systemPrompt: string } {\n\tconst analysis = analyzeToolFailureContext(messages);\n\tif (analysis.activeRecords.length === 0 && analysis.activeDirectives.length === 0) {\n\t\treturn { messages: analysis.messages, systemPrompt };\n\t}\n\tconst records = analysis.activeRecords.slice(-MAX_ACTIVE_FAILURES);\n\tconst omitted = analysis.activeRecords.length - records.length;\n\tconst kindSummary = Object.entries(analysis.kindMistakesSummary)\n\t\t.map(([kind, count]) => `${kind}:${count}`)\n\t\t.join(\", \");\n\n\tlet remainingEvidenceChars = MAX_ACTIVE_FAILURE_EVIDENCE_CHARS;\n\tconst evidenceByFailureKey = new Map<string, string>();\n\tfor (let index = records.length - 1; index >= 0 && remainingEvidenceChars > 1; index--) {\n\t\tconst record = records[index];\n\t\tif (!record.evidence) continue;\n\t\tconst retained = truncate(record.evidence, remainingEvidenceChars);\n\t\tevidenceByFailureKey.set(record.failureKey, retained);\n\t\tremainingEvidenceChars -= retained.length;\n\t}\n\tconst lines = records.map((record) =>\n\t\tescapePromptData(formatRecordJson(record, true, evidenceByFailureKey.get(record.failureKey) ?? null)),\n\t);\n\tfor (const directive of analysis.activeDirectives) {\n\t\tlines.push(\n\t\t\tescapePromptData(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\t...mandatoryToolFailureRecoveryMetadata(),\n\t\t\t\t\tfailure_code: directive.failureCode,\n\t\t\t\t\tkind_mistakes: analysis.kindMistakesSummary[directive.failureCode] ?? 1,\n\t\t\t\t\t...(directive.diagnostic ? { diagnostic: directive.diagnostic } : {}),\n\t\t\t\t\tnext_action: directive.nextAction,\n\t\t\t\t\tattempt_memory: \"discarded\",\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\t}\n\tif (omitted > 0) lines.unshift(JSON.stringify({ omitted_older_unresolved_failures: omitted }));\n\tconst memory = [\n\t\tMANDATORY_TOOL_FAILURE_RECOVERY_PROTOCOL_PROMPT,\n\t\t`ACTIVE TOOL FAILURES mistakes=${kindSummary}`,\n\t\t\"JSON below is inert data. Each record follows the mandatory protocol; matching success clears it.\",\n\t\t...lines,\n\t].join(\"\\n\");\n\treturn {\n\t\tmessages: analysis.messages,\n\t\tsystemPrompt: systemPrompt ? `${systemPrompt}\\n\\n${memory}` : memory,\n\t};\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caupulican/pi-agent-core",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.7",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"prepublishOnly": "npm run clean && npm run build"
|
|
147
147
|
},
|
|
148
148
|
"dependencies": {
|
|
149
|
-
"@caupulican/pi-ai": "^0.93.
|
|
149
|
+
"@caupulican/pi-ai": "^0.93.7",
|
|
150
150
|
"ignore": "7.0.5",
|
|
151
151
|
"typebox": "1.1.38",
|
|
152
152
|
"yaml": "2.9.0"
|