@caupulican/pi-agent-core 0.93.7 → 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 +9 -1
- package/dist/tool-failure-memory.d.ts.map +1 -1
- package/dist/tool-failure-memory.js +41 -3
- 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,6 +18,8 @@ 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;
|
|
22
24
|
/** Bounded result-scoped harness notice (replay block, circuit state); never displaces the retained diagnostic. */
|
|
23
25
|
note?: string;
|
|
@@ -26,6 +28,12 @@ export interface ToolFailureMemoryRecord {
|
|
|
26
28
|
correction: string;
|
|
27
29
|
attemptMemory?: "discard";
|
|
28
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
|
+
}
|
|
29
37
|
export interface ToolFailureMemoryDetails {
|
|
30
38
|
piToolFailureMemory: ToolFailureMemoryRecord;
|
|
31
39
|
}
|
|
@@ -86,7 +94,7 @@ export interface ToolFailureTelemetry {
|
|
|
86
94
|
/** Read only bounded failure identity and guidance; operation arguments never cross this telemetry boundary. */
|
|
87
95
|
export declare function readToolFailureTelemetry(details: unknown): ToolFailureTelemetry | undefined;
|
|
88
96
|
export declare function createToolFailureMemoryTracker(messages: AgentMessage[]): ToolFailureMemoryTracker;
|
|
89
|
-
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;
|
|
90
98
|
export declare function clearToolFailure(tracker: ToolFailureMemoryTracker, tool: string, args: unknown): void;
|
|
91
99
|
export declare function createToolFailureResult(record: ToolFailureMemoryRecord, terminate?: boolean): AgentToolResult<ToolFailureResultDetails>;
|
|
92
100
|
export declare function createRepeatedToolFailureResult(record: ToolFailureMemoryRecord): AgentToolResult<ToolFailureMemoryDetails>;
|
|
@@ -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-mem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kB3C;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,6 +12,9 @@ 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"]);
|
|
@@ -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,7 @@ 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;
|
|
638
671
|
const note = typeof candidate.note === "string" ? truncate(candidate.note, MAX_DIAGNOSTIC_CHARS) : undefined;
|
|
639
672
|
const evidence = sanitizeToolFailureEvidence(candidate.evidence);
|
|
640
673
|
const retainedCorrection = typeof candidate.correction === "string" ? truncate(candidate.correction, MAX_CORRECTION_CHARS) : undefined;
|
|
@@ -659,6 +692,7 @@ function readFailureRecord(details) {
|
|
|
659
692
|
state: candidate.state,
|
|
660
693
|
phase,
|
|
661
694
|
failureCode: boundedFailureCode(candidate.failureCode),
|
|
695
|
+
outputSignature,
|
|
662
696
|
diagnostic,
|
|
663
697
|
note,
|
|
664
698
|
evidence,
|
|
@@ -805,6 +839,7 @@ function analyzeToolFailureContext(messages) {
|
|
|
805
839
|
state,
|
|
806
840
|
phase: retained?.phase ?? assessment?.phase ?? inferToolFailurePhase(state, "tool_error"),
|
|
807
841
|
failureCode: retained?.failureCode ?? assessment?.failureCode ?? "tool_error",
|
|
842
|
+
outputSignature: retained ? retained.outputSignature : structuredOutputSignature(textPayload),
|
|
808
843
|
diagnostic: retained?.diagnostic ?? assessment?.diagnostic,
|
|
809
844
|
evidence: retained?.evidence,
|
|
810
845
|
correction: retained?.correction ??
|
|
@@ -897,7 +932,7 @@ function analyzeToolFailureContext(messages) {
|
|
|
897
932
|
export function createToolFailureMemoryTracker(messages) {
|
|
898
933
|
return new Map(analyzeToolFailureContext(messages).activeRecords.map((record) => [record.failureKey, record]));
|
|
899
934
|
}
|
|
900
|
-
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) {
|
|
901
936
|
let kindCount = 1;
|
|
902
937
|
for (const previous of tracker.values()) {
|
|
903
938
|
if (previous.tool === tool) {
|
|
@@ -925,6 +960,9 @@ export function rememberToolFailure(tracker, tool, args, state, failureCode, cor
|
|
|
925
960
|
state,
|
|
926
961
|
phase,
|
|
927
962
|
failureCode: boundedFailureCode(failureCode),
|
|
963
|
+
outputSignature: isOutputSignature(outputIdentity?.outputSignature)
|
|
964
|
+
? outputIdentity.outputSignature
|
|
965
|
+
: structuredOutputSignature(outputIdentity?.output ?? ""),
|
|
928
966
|
diagnostic: diagnostic ? truncate(diagnostic, MAX_DIAGNOSTIC_CHARS) : undefined,
|
|
929
967
|
evidence: sanitizeToolFailureEvidence(evidence),
|
|
930
968
|
correction: truncate(correction, MAX_CORRECTION_CHARS),
|