@caupulican/pi-agent-core 0.93.5 → 0.93.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +22 -4
- package/dist/agent-loop.js.map +1 -1
- package/dist/tool-failure-memory.d.ts +13 -3
- package/dist/tool-failure-memory.d.ts.map +1 -1
- package/dist/tool-failure-memory.js +58 -18
- package/dist/tool-failure-memory.js.map +1 -1
- package/dist/tool-failure-recovery-gate.d.ts.map +1 -1
- package/dist/tool-failure-recovery-gate.js +22 -2
- package/dist/tool-failure-recovery-gate.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -18,12 +18,22 @@ export interface ToolFailureMemoryRecord {
|
|
|
18
18
|
state: ToolFailureState;
|
|
19
19
|
phase: ToolFailurePhase;
|
|
20
20
|
failureCode: string;
|
|
21
|
+
/** Tool-owned full-output digest, or a fallback result-text digest; used only to distinguish recovery episodes. */
|
|
22
|
+
outputSignature?: string;
|
|
21
23
|
diagnostic?: string;
|
|
24
|
+
/** Bounded result-scoped harness notice (replay block, circuit state); never displaces the retained diagnostic. */
|
|
25
|
+
note?: string;
|
|
22
26
|
/** Bounded tool-owned source evidence needed to construct a changed operation. */
|
|
23
27
|
evidence?: string;
|
|
24
28
|
correction: string;
|
|
25
29
|
attemptMemory?: "discard";
|
|
26
30
|
}
|
|
31
|
+
export interface ToolFailureOutputIdentity {
|
|
32
|
+
/** Complete tool output when available, otherwise the complete bounded result returned to the agent. */
|
|
33
|
+
output: string;
|
|
34
|
+
/** Optional tool-owned digest of output that was not retained in the bounded result. */
|
|
35
|
+
outputSignature?: string;
|
|
36
|
+
}
|
|
27
37
|
export interface ToolFailureMemoryDetails {
|
|
28
38
|
piToolFailureMemory: ToolFailureMemoryRecord;
|
|
29
39
|
}
|
|
@@ -84,12 +94,12 @@ export interface ToolFailureTelemetry {
|
|
|
84
94
|
/** Read only bounded failure identity and guidance; operation arguments never cross this telemetry boundary. */
|
|
85
95
|
export declare function readToolFailureTelemetry(details: unknown): ToolFailureTelemetry | undefined;
|
|
86
96
|
export declare function createToolFailureMemoryTracker(messages: AgentMessage[]): ToolFailureMemoryTracker;
|
|
87
|
-
export declare function rememberToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown, state: ToolFailureState, failureCode: string, correction: string, diagnostic?: string, phase?: ToolFailurePhase, evidence?: string): ToolFailureMemoryRecord;
|
|
97
|
+
export declare function rememberToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown, state: ToolFailureState, failureCode: string, correction: string, diagnostic?: string, phase?: ToolFailurePhase, evidence?: string, outputIdentity?: ToolFailureOutputIdentity): ToolFailureMemoryRecord;
|
|
88
98
|
export declare function clearToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): void;
|
|
89
99
|
export declare function createToolFailureResult(record: ToolFailureMemoryRecord, terminate?: boolean): AgentToolResult<ToolFailureResultDetails>;
|
|
90
100
|
export declare function createRepeatedToolFailureResult(record: ToolFailureMemoryRecord): AgentToolResult<ToolFailureMemoryDetails>;
|
|
91
|
-
export declare function createToolFailureRecoveryExhaustedResult(record: ToolFailureMemoryRecord,
|
|
92
|
-
export declare function createToolFailureOperationExhaustedResult(record: ToolFailureMemoryRecord,
|
|
101
|
+
export declare function createToolFailureRecoveryExhaustedResult(record: ToolFailureMemoryRecord, note: string): AgentToolResult<ToolFailureMemoryDetails>;
|
|
102
|
+
export declare function createToolFailureOperationExhaustedResult(record: ToolFailureMemoryRecord, note: string): AgentToolResult<ToolFailureMemoryDetails>;
|
|
93
103
|
export declare function sanitizeToolFailureContext(messages: AgentMessage[], systemPrompt: string): {
|
|
94
104
|
messages: AgentMessage[];
|
|
95
105
|
systemPrompt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-failure-memory.d.ts","sourceRoot":"","sources":["../src/tool-failure-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,gBAAgB,EACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAKnF,OAAO,KAAK,EAAE,YAAY,EAAiB,eAAe,EAAE,MAAM,YAAY,CAAC;AAG/E,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,QAAA,MAAM,8BAA8B,IAAI,CAAC;AACzC,QAAA,MAAM,0BAA0B,eAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-failure-memory.d.ts","sourceRoot":"","sources":["../src/tool-failure-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,gBAAgB,EACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAKnF,OAAO,KAAK,EAAE,YAAY,EAAiB,eAAe,EAAE,MAAM,YAAY,CAAC;AAG/E,QAAA,MAAM,2BAA2B,IAAI,CAAC;AACtC,QAAA,MAAM,8BAA8B,IAAI,CAAC;AACzC,QAAA,MAAM,0BAA0B,eAAoC,CAAC;AAsBrE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAErD,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,OAAO,2BAA2B,CAAC;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,qFAAqF;IACrF,QAAQ,CAAC,CAAC,0BAA0B,CAAC,CAAC,EAAE,MAAM,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,WAAW,EA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D,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"}
|
|
@@ -12,12 +12,15 @@ const MAX_TOOL_FAILURE_EVIDENCE_CHARS = 1_600;
|
|
|
12
12
|
const MAX_ACTIVE_FAILURE_EVIDENCE_CHARS = 2_400;
|
|
13
13
|
const MAX_TOOL_NAME_CHARS = 64;
|
|
14
14
|
const TOOL_SIGNATURE_HEX_CHARS = 32;
|
|
15
|
+
const TOOL_FALLBACK_OUTPUT_SIGNATURE_BASE62_CHARS = 22;
|
|
16
|
+
const TOOL_OUTPUT_SIGNATURE_BASE64URL_CHARS = 43;
|
|
17
|
+
const LEGACY_TOOL_OUTPUT_SIGNATURE_HEX_CHARS = 64;
|
|
15
18
|
const MAX_ACTIVE_FAILURES = 8;
|
|
16
19
|
const MAX_TRACKED_FAILURES = 64;
|
|
17
20
|
const REPAIRABLE_REJECTION_CODES = new Set(["invalid_arguments", "malformed_call", "unknown_tool"]);
|
|
18
21
|
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 = "
|
|
22
|
+
const BLOCKED_REPLAY_CAVEMAN_CORRECTION = "Blocked: this exact operation will not run again this session — change the operation or continue other work.";
|
|
23
|
+
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
24
|
function truncate(value, maxChars) {
|
|
22
25
|
if (value.length <= maxChars)
|
|
23
26
|
return value;
|
|
@@ -165,10 +168,29 @@ function renderSignatureHash(hash) {
|
|
|
165
168
|
.map((part) => (part >>> 0).toString(16).padStart(8, "0"))
|
|
166
169
|
.join("");
|
|
167
170
|
}
|
|
168
|
-
|
|
171
|
+
const COMPACT_SIGNATURE_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
172
|
+
function renderCompactSignatureHash(hash) {
|
|
173
|
+
let remaining = (BigInt(hash.first >>> 0) << 96n) |
|
|
174
|
+
(BigInt(hash.second >>> 0) << 64n) |
|
|
175
|
+
(BigInt(hash.third >>> 0) << 32n) |
|
|
176
|
+
BigInt(hash.fourth >>> 0);
|
|
177
|
+
let output = "";
|
|
178
|
+
for (let index = 0; index < TOOL_FALLBACK_OUTPUT_SIGNATURE_BASE62_CHARS; index++) {
|
|
179
|
+
output = COMPACT_SIGNATURE_ALPHABET[Number(remaining % 62n)] + output;
|
|
180
|
+
remaining /= 62n;
|
|
181
|
+
}
|
|
182
|
+
return output;
|
|
183
|
+
}
|
|
184
|
+
function calculateStructuredHash(value, normalizeVolatile) {
|
|
169
185
|
const hash = createSignatureHash();
|
|
170
186
|
updateStructuredHash(hash, value, new Set(), 0, normalizeVolatile ? updateNormalizedHashString : updateExactHashString);
|
|
171
|
-
return
|
|
187
|
+
return hash;
|
|
188
|
+
}
|
|
189
|
+
function structuredHash(value, normalizeVolatile) {
|
|
190
|
+
return renderSignatureHash(calculateStructuredHash(value, normalizeVolatile));
|
|
191
|
+
}
|
|
192
|
+
function structuredOutputSignature(output) {
|
|
193
|
+
return renderCompactSignatureHash(calculateStructuredHash(output, false));
|
|
172
194
|
}
|
|
173
195
|
function boundedJsonPreview(value, maxChars) {
|
|
174
196
|
let output = "";
|
|
@@ -619,6 +641,16 @@ export function assessToolFailure(message, state, errorClass) {
|
|
|
619
641
|
function isRecord(value) {
|
|
620
642
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
621
643
|
}
|
|
644
|
+
function isOutputSignature(value) {
|
|
645
|
+
if (typeof value !== "string")
|
|
646
|
+
return false;
|
|
647
|
+
if (value.length === TOOL_FALLBACK_OUTPUT_SIGNATURE_BASE62_CHARS)
|
|
648
|
+
return /^[0-9A-Za-z]+$/.test(value);
|
|
649
|
+
if (value.length === TOOL_OUTPUT_SIGNATURE_BASE64URL_CHARS)
|
|
650
|
+
return /^[A-Za-z0-9_-]+$/.test(value);
|
|
651
|
+
return ((value.length === TOOL_SIGNATURE_HEX_CHARS || value.length === LEGACY_TOOL_OUTPUT_SIGNATURE_HEX_CHARS) &&
|
|
652
|
+
/^[0-9a-f]+$/.test(value));
|
|
653
|
+
}
|
|
622
654
|
function readFailureRecord(details) {
|
|
623
655
|
if (!isRecord(details) || !isRecord(details.piToolFailureMemory))
|
|
624
656
|
return undefined;
|
|
@@ -635,6 +667,8 @@ function readFailureRecord(details) {
|
|
|
635
667
|
return undefined;
|
|
636
668
|
}
|
|
637
669
|
const diagnostic = typeof candidate.diagnostic === "string" ? truncate(candidate.diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined;
|
|
670
|
+
const outputSignature = isOutputSignature(candidate.outputSignature) ? candidate.outputSignature : undefined;
|
|
671
|
+
const note = typeof candidate.note === "string" ? truncate(candidate.note, MAX_DIAGNOSTIC_CHARS) : undefined;
|
|
638
672
|
const evidence = sanitizeToolFailureEvidence(candidate.evidence);
|
|
639
673
|
const retainedCorrection = typeof candidate.correction === "string" ? truncate(candidate.correction, MAX_CORRECTION_CHARS) : undefined;
|
|
640
674
|
const correction = candidate.state === "failed" && retainedCorrection === LEGACY_GENERIC_EXECUTION_CORRECTION
|
|
@@ -658,7 +692,9 @@ function readFailureRecord(details) {
|
|
|
658
692
|
state: candidate.state,
|
|
659
693
|
phase,
|
|
660
694
|
failureCode: boundedFailureCode(candidate.failureCode),
|
|
695
|
+
outputSignature,
|
|
661
696
|
diagnostic,
|
|
697
|
+
note,
|
|
662
698
|
evidence,
|
|
663
699
|
correction,
|
|
664
700
|
};
|
|
@@ -803,6 +839,7 @@ function analyzeToolFailureContext(messages) {
|
|
|
803
839
|
state,
|
|
804
840
|
phase: retained?.phase ?? assessment?.phase ?? inferToolFailurePhase(state, "tool_error"),
|
|
805
841
|
failureCode: retained?.failureCode ?? assessment?.failureCode ?? "tool_error",
|
|
842
|
+
outputSignature: retained ? retained.outputSignature : structuredOutputSignature(textPayload),
|
|
806
843
|
diagnostic: retained?.diagnostic ?? assessment?.diagnostic,
|
|
807
844
|
evidence: retained?.evidence,
|
|
808
845
|
correction: retained?.correction ??
|
|
@@ -895,7 +932,7 @@ function analyzeToolFailureContext(messages) {
|
|
|
895
932
|
export function createToolFailureMemoryTracker(messages) {
|
|
896
933
|
return new Map(analyzeToolFailureContext(messages).activeRecords.map((record) => [record.failureKey, record]));
|
|
897
934
|
}
|
|
898
|
-
export function rememberToolFailure(tracker, tool, args, state, failureCode, correction, diagnostic, phase = inferToolFailurePhase(state, failureCode), evidence) {
|
|
935
|
+
export function rememberToolFailure(tracker, tool, args, state, failureCode, correction, diagnostic, phase = inferToolFailurePhase(state, failureCode), evidence, outputIdentity) {
|
|
899
936
|
let kindCount = 1;
|
|
900
937
|
for (const previous of tracker.values()) {
|
|
901
938
|
if (previous.tool === tool) {
|
|
@@ -923,6 +960,9 @@ export function rememberToolFailure(tracker, tool, args, state, failureCode, cor
|
|
|
923
960
|
state,
|
|
924
961
|
phase,
|
|
925
962
|
failureCode: boundedFailureCode(failureCode),
|
|
963
|
+
outputSignature: isOutputSignature(outputIdentity?.outputSignature)
|
|
964
|
+
? outputIdentity.outputSignature
|
|
965
|
+
: structuredOutputSignature(outputIdentity?.output ?? ""),
|
|
926
966
|
diagnostic: diagnostic ? truncate(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,
|
|
927
967
|
evidence: sanitizeToolFailureEvidence(evidence),
|
|
928
968
|
correction: truncate(correction, MAX_CORRECTION_CHARS),
|
|
@@ -968,6 +1008,7 @@ function formatRecordJson(record, includeOperation = false, evidence = record.ev
|
|
|
968
1008
|
...(includeOperation ? { operation: record.operation } : {}),
|
|
969
1009
|
failure_code: record.failureCode,
|
|
970
1010
|
...(record.diagnostic ? { diagnostic: record.diagnostic } : {}),
|
|
1011
|
+
...(record.note ? { note: record.note } : {}),
|
|
971
1012
|
...(evidence ? { evidence } : {}),
|
|
972
1013
|
...guidance,
|
|
973
1014
|
...(record.attemptMemory === "discard" ? { attempt_memory: "discarded" } : {}),
|
|
@@ -998,32 +1039,31 @@ export function createToolFailureResult(record, terminate) {
|
|
|
998
1039
|
};
|
|
999
1040
|
}
|
|
1000
1041
|
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);
|
|
1042
|
+
const retainedRecord = retainBlockedToolFailure(record);
|
|
1043
|
+
const replayNotice = truncateMiddle(`The unchanged operation was not executed. Unchanged replay blocked after ${record.failureCode}`, MAX_DIAGNOSTIC_CHARS);
|
|
1006
1044
|
const blockedResult = createToolFailureResult({
|
|
1007
1045
|
...retainedRecord,
|
|
1008
1046
|
state: "rejected",
|
|
1009
1047
|
failureCode: "repeated_failed_operation",
|
|
1010
|
-
diagnostic
|
|
1011
|
-
|
|
1048
|
+
...(retainedRecord.diagnostic
|
|
1049
|
+
? { note: replayNotice }
|
|
1050
|
+
: { diagnostic: replayNotice, correction: BLOCKED_REPLAY_CAVEMAN_CORRECTION }),
|
|
1012
1051
|
});
|
|
1013
1052
|
return {
|
|
1014
1053
|
...blockedResult,
|
|
1015
|
-
// The visible result
|
|
1016
|
-
// authoritative cause so later blocks do not
|
|
1054
|
+
// The visible result leads with the retained root cause and carries the replay notice as a
|
|
1055
|
+
// note, while retained memory keeps the authoritative cause so later blocks do not
|
|
1056
|
+
// recursively wrap synthetic failures.
|
|
1017
1057
|
details: { piToolFailureMemory: retainedRecord },
|
|
1018
1058
|
};
|
|
1019
1059
|
}
|
|
1020
|
-
export function createToolFailureRecoveryExhaustedResult(record,
|
|
1060
|
+
export function createToolFailureRecoveryExhaustedResult(record, note) {
|
|
1021
1061
|
const retainedRecord = retainBlockedToolFailure(record);
|
|
1022
1062
|
const exhaustedResult = createToolFailureResult({
|
|
1023
1063
|
...retainedRecord,
|
|
1024
1064
|
state: "rejected",
|
|
1025
1065
|
failureCode: "recovery_exhausted",
|
|
1026
|
-
|
|
1066
|
+
note: truncateMiddle(note, MAX_DIAGNOSTIC_CHARS),
|
|
1027
1067
|
correction: "Stop retrying tools in this run. Report the unresolved failure and the user or environment action required to continue.",
|
|
1028
1068
|
}, true);
|
|
1029
1069
|
return {
|
|
@@ -1031,7 +1071,7 @@ export function createToolFailureRecoveryExhaustedResult(record, diagnostic) {
|
|
|
1031
1071
|
details: { piToolFailureMemory: retainedRecord },
|
|
1032
1072
|
};
|
|
1033
1073
|
}
|
|
1034
|
-
export function createToolFailureOperationExhaustedResult(record,
|
|
1074
|
+
export function createToolFailureOperationExhaustedResult(record, note) {
|
|
1035
1075
|
const retainedRecord = {
|
|
1036
1076
|
...retainBlockedToolFailure(record),
|
|
1037
1077
|
correction: CLOSED_OPERATION_CAVEMAN_CORRECTION,
|
|
@@ -1040,7 +1080,7 @@ export function createToolFailureOperationExhaustedResult(record, diagnostic) {
|
|
|
1040
1080
|
...retainedRecord,
|
|
1041
1081
|
state: "rejected",
|
|
1042
1082
|
failureCode: "operation_recovery_exhausted",
|
|
1043
|
-
|
|
1083
|
+
note: truncateMiddle(note, MAX_DIAGNOSTIC_CHARS),
|
|
1044
1084
|
}, false);
|
|
1045
1085
|
return {
|
|
1046
1086
|
...exhaustedResult,
|