agentfootprint 9.55.0 → 9.57.0
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/AGENTS.md +1 -1
- package/CLAUDE.md +8 -1
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/dist/cache/CacheDecisionSubflow.js +2 -1
- package/dist/cache/CacheDecisionSubflow.js.map +1 -1
- package/dist/conventions.js +16 -0
- package/dist/conventions.js.map +1 -1
- package/dist/core/Agent.js +43 -1
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/agent/buildAgentChart.js +12 -0
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +17 -0
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/stages/callLLM.js +20 -2
- package/dist/core/agent/stages/callLLM.js.map +1 -1
- package/dist/core/agent/stages/prepareFinal.js +15 -0
- package/dist/core/agent/stages/prepareFinal.js.map +1 -1
- package/dist/core/agent/stages/route.js +168 -27
- package/dist/core/agent/stages/route.js.map +1 -1
- package/dist/core/agent/stages/window.js +75 -3
- package/dist/core/agent/stages/window.js.map +1 -1
- package/dist/core/agent/stages/wrapUp.js +101 -0
- package/dist/core/agent/stages/wrapUp.js.map +1 -0
- package/dist/core/agent/window/index.js.map +1 -1
- package/dist/core/agent/window/lastToolResult.js +123 -0
- package/dist/core/agent/window/lastToolResult.js.map +1 -0
- package/dist/core/agent/window/notice.js +58 -6
- package/dist/core/agent/window/notice.js.map +1 -1
- package/dist/core/agent/window/options.js +31 -1
- package/dist/core/agent/window/options.js.map +1 -1
- package/dist/core/agent/window/strategies/drop.js +73 -17
- package/dist/core/agent/window/strategies/drop.js.map +1 -1
- package/dist/core/agent/window/toolNames.js +81 -0
- package/dist/core/agent/window/toolNames.js.map +1 -0
- package/dist/core/agent/window/turns.js +50 -2
- package/dist/core/agent/window/turns.js.map +1 -1
- package/dist/esm/cache/CacheDecisionSubflow.js +2 -1
- package/dist/esm/cache/CacheDecisionSubflow.js.map +1 -1
- package/dist/esm/conventions.d.ts +8 -0
- package/dist/esm/conventions.js +16 -0
- package/dist/esm/conventions.js.map +1 -1
- package/dist/esm/core/Agent.d.ts +6 -0
- package/dist/esm/core/Agent.js +43 -1
- package/dist/esm/core/Agent.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.d.ts +14 -0
- package/dist/esm/core/agent/buildAgentChart.js +12 -0
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +17 -0
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/stages/callLLM.js +20 -2
- package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
- package/dist/esm/core/agent/stages/prepareFinal.js +15 -0
- package/dist/esm/core/agent/stages/prepareFinal.js.map +1 -1
- package/dist/esm/core/agent/stages/route.d.ts +8 -2
- package/dist/esm/core/agent/stages/route.js +168 -26
- package/dist/esm/core/agent/stages/route.js.map +1 -1
- package/dist/esm/core/agent/stages/window.d.ts +10 -0
- package/dist/esm/core/agent/stages/window.js +75 -3
- package/dist/esm/core/agent/stages/window.js.map +1 -1
- package/dist/esm/core/agent/stages/wrapUp.d.ts +64 -0
- package/dist/esm/core/agent/stages/wrapUp.js +97 -0
- package/dist/esm/core/agent/stages/wrapUp.js.map +1 -0
- package/dist/esm/core/agent/types.d.ts +116 -0
- package/dist/esm/core/agent/window/index.d.ts +1 -1
- package/dist/esm/core/agent/window/index.js.map +1 -1
- package/dist/esm/core/agent/window/lastToolResult.d.ts +96 -0
- package/dist/esm/core/agent/window/lastToolResult.js +119 -0
- package/dist/esm/core/agent/window/lastToolResult.js.map +1 -0
- package/dist/esm/core/agent/window/notice.d.ts +14 -4
- package/dist/esm/core/agent/window/notice.js +58 -6
- package/dist/esm/core/agent/window/notice.js.map +1 -1
- package/dist/esm/core/agent/window/options.d.ts +21 -0
- package/dist/esm/core/agent/window/options.js +29 -0
- package/dist/esm/core/agent/window/options.js.map +1 -1
- package/dist/esm/core/agent/window/strategies/drop.d.ts +20 -0
- package/dist/esm/core/agent/window/strategies/drop.js +73 -17
- package/dist/esm/core/agent/window/strategies/drop.js.map +1 -1
- package/dist/esm/core/agent/window/toolNames.d.ts +53 -0
- package/dist/esm/core/agent/window/toolNames.js +76 -0
- package/dist/esm/core/agent/window/toolNames.js.map +1 -0
- package/dist/esm/core/agent/window/turns.d.ts +23 -1
- package/dist/esm/core/agent/window/turns.js +50 -2
- package/dist/esm/core/agent/window/turns.js.map +1 -1
- package/dist/esm/core/agent/window/types.d.ts +84 -0
- package/dist/esm/events/payloads.d.ts +67 -3
- package/dist/esm/events/registry.d.ts +3 -1
- package/dist/esm/events/registry.js +2 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js +12 -1
- package/dist/esm/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/esm/lib/injection-engine/evaluator.js +31 -6
- package/dist/esm/lib/injection-engine/evaluator.js.map +1 -1
- package/dist/esm/lib/injection-engine/factories/defineInstruction.d.ts +45 -3
- package/dist/esm/lib/injection-engine/factories/defineInstruction.js +38 -4
- package/dist/esm/lib/injection-engine/factories/defineInstruction.js.map +1 -1
- package/dist/esm/lib/injection-engine/promptTemplate.d.ts +76 -0
- package/dist/esm/lib/injection-engine/promptTemplate.js +124 -0
- package/dist/esm/lib/injection-engine/promptTemplate.js.map +1 -0
- package/dist/esm/lib/injection-engine/types.d.ts +60 -3
- package/dist/esm/lib/injection-engine/types.js +25 -3
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/iterationBudget.d.ts +28 -0
- package/dist/esm/lib/iterationBudget.js +31 -0
- package/dist/esm/lib/iterationBudget.js.map +1 -0
- package/dist/events/registry.js +2 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js +12 -1
- package/dist/lib/injection-engine/buildInjectionEngineSubflow.js.map +1 -1
- package/dist/lib/injection-engine/evaluator.js +31 -6
- package/dist/lib/injection-engine/evaluator.js.map +1 -1
- package/dist/lib/injection-engine/factories/defineInstruction.js +38 -4
- package/dist/lib/injection-engine/factories/defineInstruction.js.map +1 -1
- package/dist/lib/injection-engine/promptTemplate.js +132 -0
- package/dist/lib/injection-engine/promptTemplate.js.map +1 -0
- package/dist/lib/injection-engine/types.js +25 -3
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/lib/iterationBudget.js +35 -0
- package/dist/lib/iterationBudget.js.map +1 -0
- package/dist/types/cache/CacheDecisionSubflow.d.ts.map +1 -1
- package/dist/types/conventions.d.ts +8 -0
- package/dist/types/conventions.d.ts.map +1 -1
- package/dist/types/core/Agent.d.ts +6 -0
- package/dist/types/core/Agent.d.ts.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts +14 -0
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
- package/dist/types/core/agent/stages/prepareFinal.d.ts.map +1 -1
- package/dist/types/core/agent/stages/route.d.ts +8 -2
- package/dist/types/core/agent/stages/route.d.ts.map +1 -1
- package/dist/types/core/agent/stages/window.d.ts +10 -0
- package/dist/types/core/agent/stages/window.d.ts.map +1 -1
- package/dist/types/core/agent/stages/wrapUp.d.ts +65 -0
- package/dist/types/core/agent/stages/wrapUp.d.ts.map +1 -0
- package/dist/types/core/agent/types.d.ts +116 -0
- package/dist/types/core/agent/types.d.ts.map +1 -1
- package/dist/types/core/agent/window/index.d.ts +1 -1
- package/dist/types/core/agent/window/index.d.ts.map +1 -1
- package/dist/types/core/agent/window/lastToolResult.d.ts +97 -0
- package/dist/types/core/agent/window/lastToolResult.d.ts.map +1 -0
- package/dist/types/core/agent/window/notice.d.ts +14 -4
- package/dist/types/core/agent/window/notice.d.ts.map +1 -1
- package/dist/types/core/agent/window/options.d.ts +21 -0
- package/dist/types/core/agent/window/options.d.ts.map +1 -1
- package/dist/types/core/agent/window/strategies/drop.d.ts +20 -0
- package/dist/types/core/agent/window/strategies/drop.d.ts.map +1 -1
- package/dist/types/core/agent/window/toolNames.d.ts +54 -0
- package/dist/types/core/agent/window/toolNames.d.ts.map +1 -0
- package/dist/types/core/agent/window/turns.d.ts +23 -1
- package/dist/types/core/agent/window/turns.d.ts.map +1 -1
- package/dist/types/core/agent/window/types.d.ts +84 -0
- package/dist/types/core/agent/window/types.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +67 -3
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +3 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/buildInjectionEngineSubflow.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/evaluator.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/factories/defineInstruction.d.ts +45 -3
- package/dist/types/lib/injection-engine/factories/defineInstruction.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/promptTemplate.d.ts +77 -0
- package/dist/types/lib/injection-engine/promptTemplate.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/types.d.ts +60 -3
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/lib/iterationBudget.d.ts +29 -0
- package/dist/types/lib/iterationBudget.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/agent/window/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,yCAA0D;AAAjD,wHAAA,2BAA2B,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/agent/window/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,yCAA0D;AAAjD,wHAAA,2BAA2B,OAAA;AAgBpC,yCAAqF;AAA5E,2GAAA,cAAc,OAAA;AAAE,0GAAA,aAAa,OAAA;AAStC,+CAA4E;AAAnE,sHAAA,sBAAsB,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AACnD,yCAA+D;AAAtD,+GAAA,kBAAkB,OAAA;AAAE,yGAAA,YAAY,OAAA;AACzC,sEAAkE;AAAzD,qHAAA,eAAe,OAAA;AACxB,kEAA8D;AAArD,iHAAA,aAAa,OAAA;AACtB,8DAA0D;AAAjD,6GAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* window/lastToolResult — the last thing each tool said, and why the window
|
|
4
|
+
* keeps it.
|
|
5
|
+
*
|
|
6
|
+
* Pattern: One pure function over the window (no scope, no I/O, no clock).
|
|
7
|
+
* Role: core/ layer. Feeds the refusal engine, which is what actually
|
|
8
|
+
* keeps these turns in the window (see turns.ts,
|
|
9
|
+
* `'last-tool-result'`). Sibling of currentRequest.ts, and kept
|
|
10
|
+
* apart from it for the same reason: "what did the person ask for"
|
|
11
|
+
* and "what has the agent just seen" are different questions.
|
|
12
|
+
* Emits: N/A.
|
|
13
|
+
*
|
|
14
|
+
* ## Why this exists
|
|
15
|
+
*
|
|
16
|
+
* Measured, in a context-gap audit over real recorded runs. An agent drove a
|
|
17
|
+
* screen through tools. A `whats_here` result — about 5,800 characters —
|
|
18
|
+
* carried the list of valid ids it had to act on. Under
|
|
19
|
+
* `slidingWindow({ keepRecentTurns: 2 })` that result survived roughly two
|
|
20
|
+
* iterations, because segmentation makes each assistant/tool_result PAIR one
|
|
21
|
+
* turn. The 9.55.0 anchor kept the REQUEST undroppable, so the model still
|
|
22
|
+
* knew what it had been asked to do — and no longer had the evidence to do
|
|
23
|
+
* it. It assembled a plausible id out of an entity name it remembered plus
|
|
24
|
+
* the shape of an id it had used earlier, and was refused. In one archived
|
|
25
|
+
* run the final answer to the person named a host that appears in no tool
|
|
26
|
+
* result at all.
|
|
27
|
+
*
|
|
28
|
+
* The framework evicted the evidence and kept the task. This is the other
|
|
29
|
+
* half of 9.55.0: **for each tool the agent is using, keep that tool's most
|
|
30
|
+
* recent result** — until the agent calls that tool again, or the person asks
|
|
31
|
+
* something new.
|
|
32
|
+
*
|
|
33
|
+
* ## What is pinned, exactly, and why it cannot grow
|
|
34
|
+
*
|
|
35
|
+
* One pin per tool NAME, always the LATEST result, superseded the moment that
|
|
36
|
+
* tool answers again. So the candidate space is the TOOL ROSTER, not the
|
|
37
|
+
* transcript: a loop that calls three tools forty times has three candidates,
|
|
38
|
+
* not forty. Three further bounds compose on top:
|
|
39
|
+
*
|
|
40
|
+
* • **deduped by turn** — a parallel batch answered in one assistant turn is
|
|
41
|
+
* ONE turn, so it costs one slot however many tools were in it;
|
|
42
|
+
* • **capped** — `keepLastToolResults` (default 2) is the ceiling, applied
|
|
43
|
+
* in `planRemoval` where the keep window is known, so a pin that is
|
|
44
|
+
* already inside `keepRecentTurns` costs nothing at all;
|
|
45
|
+
* • **anchored** — nothing at or before the CURRENT REQUEST is pinnable, so
|
|
46
|
+
* a new user turn releases the whole previous loop for free.
|
|
47
|
+
*
|
|
48
|
+
* Incompressible floor: 1 request + N pins + `keepRecentTurns` turns,
|
|
49
|
+
* independent of tool count, iteration count and run length.
|
|
50
|
+
*
|
|
51
|
+
* ## What it deliberately gets wrong
|
|
52
|
+
*
|
|
53
|
+
* The pin is CONTENT-BLIND. It keeps a tool's LAST result, which may be a
|
|
54
|
+
* one-word acknowledgement while the load-bearing screen dump was the call
|
|
55
|
+
* before. Two slots absorb the common case; nothing eliminates it. That is
|
|
56
|
+
* the honest price of a bound that is a fact about the tool roster rather
|
|
57
|
+
* than a guess about content — and a guess about content is what this library
|
|
58
|
+
* refuses to make everywhere else.
|
|
59
|
+
*
|
|
60
|
+
* Nor does the framework truly know "the tool the model is driving". This
|
|
61
|
+
* approximates it with "every tool that has spoken since the request, latest
|
|
62
|
+
* result each, newest first under a cap". A heuristic that PINS bills its
|
|
63
|
+
* error every iteration, which is why the cap is small and the record names
|
|
64
|
+
* what it kept.
|
|
65
|
+
*/
|
|
66
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
+
exports.toolResultPinsOf = void 0;
|
|
68
|
+
const toolNames_js_1 = require("./toolNames.js");
|
|
69
|
+
/** Content characters of one turn. Exact; not tokens. */
|
|
70
|
+
function turnChars(turn) {
|
|
71
|
+
let total = 0;
|
|
72
|
+
for (const msg of turn.messages)
|
|
73
|
+
total += msg.content.length;
|
|
74
|
+
return total;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The turns holding each tool's most recent result, NEWEST FIRST.
|
|
78
|
+
*
|
|
79
|
+
* Newest first because that is the order the ceiling is spent in: when more
|
|
80
|
+
* tools have spoken than there are slots, the ones the agent used most
|
|
81
|
+
* recently keep theirs.
|
|
82
|
+
*
|
|
83
|
+
* @param turns the window's turn segmentation
|
|
84
|
+
* @param history the window itself, for recovering a name from the assistant
|
|
85
|
+
* call when a result does not carry one
|
|
86
|
+
* @param after index of the CURRENT REQUEST, or `-1` when the window holds
|
|
87
|
+
* none. Nothing at or before it is pinnable: results gathered for an
|
|
88
|
+
* earlier request are ordinary history, and this is what makes a new user
|
|
89
|
+
* turn release the whole previous loop without a line of code
|
|
90
|
+
*/
|
|
91
|
+
function toolResultPinsOf(turns, history, after = -1) {
|
|
92
|
+
const pins = [];
|
|
93
|
+
const namedTools = new Set();
|
|
94
|
+
const pinnedTurns = new Set();
|
|
95
|
+
for (let t = turns.length - 1; t >= 0; t--) {
|
|
96
|
+
const turn = turns[t];
|
|
97
|
+
for (let m = turn.messages.length - 1; m >= 0; m--) {
|
|
98
|
+
const index = turn.start + m;
|
|
99
|
+
if (index <= after)
|
|
100
|
+
continue;
|
|
101
|
+
const name = (0, toolNames_js_1.toolNameOfMessage)(turn.messages[m], history);
|
|
102
|
+
// A result that cannot be named is not pinned. Pinning it under a made-
|
|
103
|
+
// up name would keep a turn nothing can ever supersede.
|
|
104
|
+
if (name === undefined || namedTools.has(name))
|
|
105
|
+
continue;
|
|
106
|
+
namedTools.add(name);
|
|
107
|
+
// One pin per TURN: a parallel batch is one turn, and pinning it three
|
|
108
|
+
// times would spend three slots to keep one thing.
|
|
109
|
+
if (pinnedTurns.has(t))
|
|
110
|
+
continue;
|
|
111
|
+
pinnedTurns.add(t);
|
|
112
|
+
pins.push({
|
|
113
|
+
toolName: name,
|
|
114
|
+
turnIndex: t,
|
|
115
|
+
messageIndex: turn.start,
|
|
116
|
+
chars: turnChars(turn),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return pins;
|
|
121
|
+
}
|
|
122
|
+
exports.toolResultPinsOf = toolResultPinsOf;
|
|
123
|
+
//# sourceMappingURL=lastToolResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lastToolResult.js","sourceRoot":"","sources":["../../../../src/core/agent/window/lastToolResult.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;;;AAGH,iDAAmD;AAkBnD,yDAAyD;AACzD,SAAS,SAAS,CAAC,IAAU;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ;QAAE,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,gBAAgB,CAC9B,KAAsB,EACtB,OAA8B,EAC9B,KAAK,GAAG,CAAC,CAAC;IAEV,MAAM,IAAI,GAAoB,EAAE,CAA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, it should say what
|
|
18
18
|
* happened rather than be filler. So it does: how many messages left, at
|
|
19
|
-
* which iteration, by which strategy,
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* which iteration, by which strategy, where they still are — and, since
|
|
20
|
+
* 9.57.0, WHICH TOOLS' RESULTS were among them. Unlike the compaction frame
|
|
21
|
+
* there is no model output involved at ALL — every character below is written
|
|
22
|
+
* by this library, and the only caller data that reaches it is a tool NAME,
|
|
23
|
+
* shape-filtered to a plain identifier and dropped outright when it is not
|
|
24
|
+
* one. So a drop still has no prompt-injection surface to speak of.
|
|
25
|
+
*
|
|
26
|
+
* That last sentence is the one this file exists for now. A drop the model is
|
|
27
|
+
* not told about is how a model came to invent an id: its `whats_here` result
|
|
28
|
+
* left the window, nothing said so, and it assembled a plausible-looking id
|
|
29
|
+
* out of an entity name it remembered. "Tool results are among them
|
|
30
|
+
* (whats_here) — call the tool again" is the difference between a re-fetch
|
|
31
|
+
* and a fabrication.
|
|
23
32
|
*
|
|
24
33
|
* It appears ONLY when the removal reaches the front of what may leave. That
|
|
25
34
|
* is the window's head in the ordinary case; since 9.55.0 it is the position
|
|
@@ -37,6 +46,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
46
|
exports.isDropNotice = exports.buildDropNotice = exports.DROP_NOTICE_PREFIX = void 0;
|
|
38
47
|
/** Opening of the authored notice. Stable — tests and readers match on it. */
|
|
39
48
|
exports.DROP_NOTICE_PREFIX = '[dropped history';
|
|
49
|
+
/**
|
|
50
|
+
* How many tool names the notice will print before it stops and says `…`.
|
|
51
|
+
*
|
|
52
|
+
* Four is enough to name what a turn was actually driving and small enough
|
|
53
|
+
* that the notice stays a sentence rather than a list. The record is not
|
|
54
|
+
* capped — see `WindowRecord.droppedObservations`.
|
|
55
|
+
*/
|
|
56
|
+
const MAX_NAMED_TOOLS = 4;
|
|
57
|
+
/**
|
|
58
|
+
* The only shape a tool name may take to reach the wire.
|
|
59
|
+
*
|
|
60
|
+
* A tool name is CALLER DATA — it comes from a `defineTool`, an MCP server, or
|
|
61
|
+
* a restored conversation somebody else wrote — and this notice is the one
|
|
62
|
+
* message in the drop path with no untrusted payload in it. A name that is not
|
|
63
|
+
* a plain identifier is DROPPED rather than truncated: truncating turns
|
|
64
|
+
* `ignore previous instructions and…` into `ignore previous instruction`,
|
|
65
|
+
* which is still an instruction. The record keeps the real name; the wire
|
|
66
|
+
* simply says less.
|
|
67
|
+
*/
|
|
68
|
+
const SAFE_TOOL_NAME = /^[A-Za-z0-9_.:-]{1,48}$/;
|
|
69
|
+
/**
|
|
70
|
+
* The tool names as the notice may print them: shape-filtered, deduplicated
|
|
71
|
+
* by the caller, capped, and `…` when the cap bit. Empty when nothing
|
|
72
|
+
* survived — and then the sentence is omitted entirely rather than printed
|
|
73
|
+
* with an empty list.
|
|
74
|
+
*/
|
|
75
|
+
function namesForWire(toolNames) {
|
|
76
|
+
const safe = toolNames.filter((n) => SAFE_TOOL_NAME.test(n));
|
|
77
|
+
if (safe.length === 0)
|
|
78
|
+
return '';
|
|
79
|
+
const shown = safe.slice(0, MAX_NAMED_TOOLS);
|
|
80
|
+
return safe.length > shown.length ? `${shown.join(', ')}, …` : shown.join(', ');
|
|
81
|
+
}
|
|
40
82
|
/**
|
|
41
83
|
* Build the message that takes the head position after a drop.
|
|
42
84
|
*
|
|
@@ -58,12 +100,22 @@ function buildDropNotice(facts) {
|
|
|
58
100
|
? `Your current request is kept — it is still in this window, above this line, and no ` +
|
|
59
101
|
`window strategy may drop it. `
|
|
60
102
|
: '';
|
|
103
|
+
// 9.57.0. The measured failure: a model whose tool result had been dropped
|
|
104
|
+
// assembled a plausible id out of an entity name it remembered and a shape
|
|
105
|
+
// it had seen, got refused, and in one archived run named a host that
|
|
106
|
+
// appears in no tool result at all. It was never told the evidence had
|
|
107
|
+
// gone. Now it is, by name, with the one instruction that recovers it.
|
|
108
|
+
const wireNames = facts.toolNames === undefined ? '' : namesForWire(facts.toolNames);
|
|
109
|
+
const observations = wireNames.length > 0
|
|
110
|
+
? `Tool results are among them (${wireNames}) — call the tool again if you need its ` +
|
|
111
|
+
`output; do not reconstruct ids or values from memory. `
|
|
112
|
+
: '';
|
|
61
113
|
return {
|
|
62
114
|
role: 'user',
|
|
63
115
|
content: `${exports.DROP_NOTICE_PREFIX} — ${facts.droppedMessageCount} earlier message(s) were dropped ` +
|
|
64
116
|
`from this window at iteration ${facts.iteration} by the '${facts.strategy}' window ` +
|
|
65
|
-
`strategy. ${kept}Nothing was summarized: those turns are simply not
|
|
66
|
-
`They are retained verbatim in this run's commit log.]`,
|
|
117
|
+
`strategy. ${kept}${observations}Nothing was summarized: those turns are simply not ` +
|
|
118
|
+
`being re-sent. They are retained verbatim in this run's commit log.]`,
|
|
67
119
|
};
|
|
68
120
|
}
|
|
69
121
|
exports.buildDropNotice = buildDropNotice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notice.js","sourceRoot":"","sources":["../../../../src/core/agent/window/notice.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"notice.js","sourceRoot":"","sources":["../../../../src/core/agent/window/notice.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;;;AAIH,8EAA8E;AACjE,QAAA,kBAAkB,GAAG,kBAAkB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD;;;;;GAKG;AACH,SAAS,YAAY,CAAC,SAA4B;IAChD,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,C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C"}
|
|
@@ -15,9 +15,39 @@
|
|
|
15
15
|
* money to discover.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.resolveTokenBudgetOptions = exports.resolveSlidingWindowOptions = exports.resolveCompactionOptions = exports.DEFAULT_RETENTION = exports.DEFAULT_KEEP_RECENT_TURNS = void 0;
|
|
18
|
+
exports.resolveTokenBudgetOptions = exports.resolveSlidingWindowOptions = exports.resolveCompactionOptions = exports.DEFAULT_RETENTION = exports.requireKeepLastToolResults = exports.DEFAULT_KEEP_LAST_TOOL_RESULTS = exports.DEFAULT_KEEP_RECENT_TURNS = void 0;
|
|
19
19
|
/** Default depth of the "never touch this" recent window. */
|
|
20
20
|
exports.DEFAULT_KEEP_RECENT_TURNS = 6;
|
|
21
|
+
/**
|
|
22
|
+
* How many tools' most recent results the window holds beyond
|
|
23
|
+
* `keepRecentTurns` when nobody said (9.57.0). ON by default, at 2.
|
|
24
|
+
*
|
|
25
|
+
* On by default for the same reason 9.55.0's anchor is: the counterfactual to
|
|
26
|
+
* a pinned 5,800-character tool result is not 5,800 bytes saved, it is a
|
|
27
|
+
* fabricated id, a refusal, a wasted action out of a small budget, and the
|
|
28
|
+
* same 5,800 bytes fetched again. That is a correctness failure the framework
|
|
29
|
+
* caused, and those are fixed on by default.
|
|
30
|
+
*
|
|
31
|
+
* TWO rather than one because the ceiling is spent newest-first among STALE
|
|
32
|
+
* candidates: a one-word acknowledgement from an actuator the model has
|
|
33
|
+
* stopped using can occupy a slot ahead of an older load-bearing observation.
|
|
34
|
+
* Two slots absorb that. `false` or `0` switches the pin off entirely.
|
|
35
|
+
*/
|
|
36
|
+
exports.DEFAULT_KEEP_LAST_TOOL_RESULTS = 2;
|
|
37
|
+
/**
|
|
38
|
+
* Validate the `keepLastToolResults` dial. Refused at construction, never
|
|
39
|
+
* mid-run — the house rule for every window option.
|
|
40
|
+
*/
|
|
41
|
+
function requireKeepLastToolResults(value, label) {
|
|
42
|
+
if (value === false)
|
|
43
|
+
return;
|
|
44
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
45
|
+
throw new Error(`${label}: keepLastToolResults must be a whole number >= 0, or false, got ` +
|
|
46
|
+
`${String(value)}. It is how many tools' most recent results stay in the window ` +
|
|
47
|
+
`beyond keepRecentTurns; 0 and false both switch the pin off.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.requireKeepLastToolResults = requireKeepLastToolResults;
|
|
21
51
|
/**
|
|
22
52
|
* What happens to folded messages when nobody said. The originals ride with
|
|
23
53
|
* the conversation: losing them has to be a choice somebody typed, not a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../../src/core/agent/window/options.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAUH,6DAA6D;AAChD,QAAA,yBAAyB,GAAG,CAAC,CAAC;AAE3C;;;;GAIG;AACU,QAAA,iBAAiB,GAAwB,cAAc,CAAC;AAErE,MAAM,UAAU,GAAmC,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAE/E,SAAS,aAAa,CAAC,OAAgB,EAAE,KAAa,EAAE,KAAa;IACnE,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,iCAAiC,KAAK,UAAU,OAAO,OAAO,GAAG,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,eAAwB,EAAE,KAAa;IAC/D,IACE,OAAO,eAAe,KAAK,QAAQ;QACnC,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;QACjC,eAAe,IAAI,CAAC,EACpB,CAAC;QACD,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,6DAA6D;YACnE,GAAG,MAAM,CAAC,eAAe,CAAC,0DAA0D;YACpF,sFAAsF;YACtF,eAAe,CAClB,CAA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2B,EAC3B,KAAa;IAEb,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,uCAAuC,CAAC,CAAC;IACvE,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACrD,gBAAgB,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACzC,IAAI,eAAe,KAAK,SAAS;QAAE,sBAAsB,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IAClF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,IAAI,iCAAyB,EAAE,CAAC;AAC5F,CAAC;AATD,8DASC"}
|
|
@@ -22,12 +22,55 @@
|
|
|
22
22
|
* slot just after the kept request when the request was the head;
|
|
23
23
|
* • when it does not, nothing is inserted: the original opening turn is
|
|
24
24
|
* still there, so there is no wire problem to solve.
|
|
25
|
+
*
|
|
26
|
+
* ## The notice is owed to the WIRE, not to politeness (9.57.0)
|
|
27
|
+
*
|
|
28
|
+
* That distinction used to be missing here, and it produced a livelock. The
|
|
29
|
+
* notice was authored whenever the removal reached the front of what may
|
|
30
|
+
* leave, and the whole removal was abandoned when the notice was not smaller
|
|
31
|
+
* than the span — but the obligation being guarded is narrower: **the window
|
|
32
|
+
* must open on a user turn.** When the message that would BECOME the head is
|
|
33
|
+
* already a user turn (the kept request, or an older user turn from a restored
|
|
34
|
+
* conversation), no notice is owed at all, and its 245–358 characters had no
|
|
35
|
+
* business vetoing a legitimate drop.
|
|
36
|
+
*
|
|
37
|
+
* Because the span is the longest CONTIGUOUS removable run, a blocker one turn
|
|
38
|
+
* along caps it at the same small span at every boundary — so the same verdict
|
|
39
|
+
* came back for ever and the window grew without bound. Two locally-correct
|
|
40
|
+
* rules composing into non-progress.
|
|
41
|
+
*
|
|
42
|
+
* So the decision is a LADDER: the rich notice, else the plain one, else no
|
|
43
|
+
* notice at all — and `'replacement-not-smaller'` only when the wire genuinely
|
|
44
|
+
* needs a message in that position and none of them is smaller than the span.
|
|
25
45
|
*/
|
|
26
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
47
|
exports.dropOldestSpan = void 0;
|
|
28
48
|
const notice_js_1 = require("../notice.js");
|
|
49
|
+
const toolNames_js_1 = require("../toolNames.js");
|
|
29
50
|
const removal_js_1 = require("../removal.js");
|
|
30
51
|
const turns_js_1 = require("../turns.js");
|
|
52
|
+
/**
|
|
53
|
+
* The first rung of the ladder that is SMALLER than the span it would replace,
|
|
54
|
+
* or `undefined` when none is.
|
|
55
|
+
*
|
|
56
|
+
* "Smaller", not "no larger": a notice exactly the size of the span buys
|
|
57
|
+
* nothing and costs the turns it replaced.
|
|
58
|
+
*/
|
|
59
|
+
function fittingNotice(spanChars, facts, keptRequestAtHead, toolNames) {
|
|
60
|
+
// The kept-request sentence is not a courtesy and is never traded away for
|
|
61
|
+
// size: a model that reads "3 earlier messages were dropped" and then finds
|
|
62
|
+
// a request above it has to be told which of the two facts to trust. The
|
|
63
|
+
// TOOL NAMES are the rung that can be traded — losing them costs the model
|
|
64
|
+
// a hint, while losing the drop costs it the whole window.
|
|
65
|
+
const base = { ...facts, ...(keptRequestAtHead && { currentRequestKept: true }) };
|
|
66
|
+
if (toolNames.length > 0) {
|
|
67
|
+
const rich = (0, notice_js_1.buildDropNotice)({ ...base, toolNames });
|
|
68
|
+
if (rich.content.length < spanChars)
|
|
69
|
+
return rich;
|
|
70
|
+
}
|
|
71
|
+
const plain = (0, notice_js_1.buildDropNotice)(base);
|
|
72
|
+
return plain.content.length < spanChars ? plain : undefined;
|
|
73
|
+
}
|
|
31
74
|
/**
|
|
32
75
|
* Drop the oldest contiguous removable span, if there is one.
|
|
33
76
|
*
|
|
@@ -74,18 +117,31 @@ function dropOldestSpan(input, keepRecentTurns, strategyName) {
|
|
|
74
117
|
const keptRequestAtHead = plan.from === 1 &&
|
|
75
118
|
plan.refusals.some((r) => r.reason === 'current-request' && r.turnIndex === 0);
|
|
76
119
|
if (spanStart === 0 || keptRequestAtHead) {
|
|
77
|
-
// The front of the droppable window is leaving
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
120
|
+
// The front of the droppable window is leaving. Ask the two questions
|
|
121
|
+
// separately, because they have different answers:
|
|
122
|
+
//
|
|
123
|
+
// 1. does the WIRE need a message in the head position? Only when the
|
|
124
|
+
// message that would become the head is not a user turn already.
|
|
125
|
+
// `head[0]` is the kept request on the 9.55.0 path (a user turn by
|
|
126
|
+
// definition); on the ordinary path `head` is empty and the new head
|
|
127
|
+
// is the first survivor. An empty result (reachable only from a
|
|
128
|
+
// strategy that keeps zero recent turns) counts as needing one.
|
|
129
|
+
// 2. does a notice FIT — is it smaller than what it replaces? Dropping
|
|
130
|
+
// two tiny turns to insert a longer notice is pure loss.
|
|
131
|
+
const newHead = head[0] ?? tail[0];
|
|
132
|
+
const wireNeedsNotice = newHead === undefined || newHead.role !== 'user';
|
|
133
|
+
const spanChars = (0, turns_js_1.windowChars)(span);
|
|
134
|
+
// The ladder. The rich notice is the one that names the tools whose
|
|
135
|
+
// results left; the plain one drops that sentence and keeps the rest.
|
|
136
|
+
const notice = fittingNotice(spanChars, { droppedMessageCount: span.length, iteration, strategy: strategyName }, keptRequestAtHead, (0, toolNames_js_1.droppedToolNames)(span, history));
|
|
137
|
+
if (notice !== undefined) {
|
|
138
|
+
// `head` is empty on the ordinary path, so this is byte-for-byte the
|
|
139
|
+
// `[notice, ...tail]` this function has always produced; when the
|
|
140
|
+
// request was kept it is `[request, notice, ...tail]`.
|
|
141
|
+
window = [...head, notice, ...tail];
|
|
142
|
+
insertedAtMs = droppedAtMs;
|
|
143
|
+
}
|
|
144
|
+
else if (wireNeedsNotice) {
|
|
89
145
|
// `'replacement-not-smaller'` since 8.14.0. A drop writes no summary —
|
|
90
146
|
// it never calls a summarizer at all — and the reason's old spelling
|
|
91
147
|
// (`'summary-not-smaller'`) named one that does not exist on this path.
|
|
@@ -94,11 +150,11 @@ function dropOldestSpan(input, keepRecentTurns, strategyName) {
|
|
|
94
150
|
...plan.refusals,
|
|
95
151
|
]);
|
|
96
152
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
153
|
+
else {
|
|
154
|
+
// Nothing is owed and nothing fits: drop silently. The record still
|
|
155
|
+
// names what left, which is where a reader looks anyway.
|
|
156
|
+
window = [...head, ...tail];
|
|
157
|
+
}
|
|
102
158
|
}
|
|
103
159
|
else {
|
|
104
160
|
window = [...head, ...tail];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drop.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/strategies/drop.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"drop.js","sourceRoot":"","sources":["../../../../../src/core/agent/window/strategies/drop.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;;;AAGH,4CAA+C;AAC/C,kDAAmD;AACnD,8CAA2C;AAE3C,0CAAwD;AAwBxD;;;;;;GAMG;AACH,SAAS,aAAa,CACpB,SAAiB,EACjB,KAIC,EACD,iBAA0B,EAC1B,SAA4B;IAE5B,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,2EAA2E;IAC3E,2DAA2D;IAC3D,MAAM,IAAI,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,CAAC,iBAAiB,IAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAClF,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAA,2BAAe,EAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,SAAS;YAAE,OAAO,IAAI,CAAC;IACnD,CAAC;IAC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,CAAC,MAAM;QACzB,UAAU,EAAE,IAAA,uBAAY,EAAC,MAAM,CAAC,CAAC,MAAM;KACxC,CAAC;AACJ,CAAC;AA7GD,wCA6GC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* window/toolNames — which tools spoke in a stretch of the window.
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Pure functions over messages (no scope, no I/O, no clock).
|
|
6
|
+
* Role: core/ layer. One implementation of "what is this tool result's
|
|
7
|
+
* tool called", used by the two places that need the answer for
|
|
8
|
+
* different reasons:
|
|
9
|
+
*
|
|
10
|
+
* • the drop notice, which tells the MODEL whose results left, so
|
|
11
|
+
* it calls the tool again instead of reconstructing an id from
|
|
12
|
+
* memory (9.57.0);
|
|
13
|
+
* • `WindowRecord.droppedObservations`, which tells the READER the
|
|
14
|
+
* same thing, uncapped and unsanitized.
|
|
15
|
+
* Emits: N/A.
|
|
16
|
+
*
|
|
17
|
+
* ## Why the name is not simply `msg.toolName`
|
|
18
|
+
*
|
|
19
|
+
* It usually is: every path in `stages/toolCalls.ts` that appends a result
|
|
20
|
+
* stamps `toolName` beside `toolCallId`. But `LLMMessage.toolName` is
|
|
21
|
+
* OPTIONAL on the adapter type, so a window seeded from outside this run — a
|
|
22
|
+
* restored conversation written by an older release, a hand-built fixture, a
|
|
23
|
+
* host that speaks the wire shape and nothing more — can carry a result whose
|
|
24
|
+
* only identity is the `toolCallId` it answers. The assistant turn that asked
|
|
25
|
+
* for it names the tool, so the name is recoverable; that recovery is here,
|
|
26
|
+
* once, rather than guessed twice.
|
|
27
|
+
*
|
|
28
|
+
* A result whose name cannot be recovered either way contributes NOTHING. It
|
|
29
|
+
* is not called `'unknown'` and it is not counted: a notice that says a tool
|
|
30
|
+
* called `unknown` lost its result teaches the model a tool name that does
|
|
31
|
+
* not exist, which is the exact failure this file exists to prevent.
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.droppedToolNames = exports.toolNameOfMessage = void 0;
|
|
35
|
+
/**
|
|
36
|
+
* The tool a `role: 'tool'` message came from, or `undefined`.
|
|
37
|
+
*
|
|
38
|
+
* @param msg the message to name
|
|
39
|
+
* @param context where to look for the assistant turn that asked, when the
|
|
40
|
+
* message does not name the tool itself. Usually the whole window.
|
|
41
|
+
*/
|
|
42
|
+
function toolNameOfMessage(msg, context) {
|
|
43
|
+
if (msg.role !== 'tool')
|
|
44
|
+
return undefined;
|
|
45
|
+
if (msg.toolName !== undefined && msg.toolName.length > 0)
|
|
46
|
+
return msg.toolName;
|
|
47
|
+
const id = msg.toolCallId;
|
|
48
|
+
if (id === undefined || id.length === 0)
|
|
49
|
+
return undefined;
|
|
50
|
+
for (const other of context) {
|
|
51
|
+
for (const call of other.toolCalls ?? []) {
|
|
52
|
+
if (call.id === id && call.name.length > 0)
|
|
53
|
+
return call.name;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
exports.toolNameOfMessage = toolNameOfMessage;
|
|
59
|
+
/**
|
|
60
|
+
* The tools whose results are in `span`, in FIRST-APPEARANCE order, each named
|
|
61
|
+
* once.
|
|
62
|
+
*
|
|
63
|
+
* First appearance rather than sorted or newest-first because the notice reads
|
|
64
|
+
* as a sentence about what happened, and what happened has an order.
|
|
65
|
+
*
|
|
66
|
+
* @param span the messages that are leaving
|
|
67
|
+
* @param context where to recover a missing `toolName` from; defaults to the
|
|
68
|
+
* span itself, which is enough whenever the pair left together (it always
|
|
69
|
+
* does — a turn is the removal unit, and the pair is one turn)
|
|
70
|
+
*/
|
|
71
|
+
function droppedToolNames(span, context = span) {
|
|
72
|
+
const names = [];
|
|
73
|
+
for (const msg of span) {
|
|
74
|
+
const name = toolNameOfMessage(msg, context);
|
|
75
|
+
if (name !== undefined && !names.includes(name))
|
|
76
|
+
names.push(name);
|
|
77
|
+
}
|
|
78
|
+
return names;
|
|
79
|
+
}
|
|
80
|
+
exports.droppedToolNames = droppedToolNames;
|
|
81
|
+
//# sourceMappingURL=toolNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolNames.js","sourceRoot":"","sources":["../../../../src/core/agent/window/toolNames.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;AAIH;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,GAAe,EACf,OAA8B;IAE9B,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,QAAQ,CAAC;IAC/E,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC;IAC1B,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,SAAS,IAAI,EAAE,EAAE,CAAC;YACzC,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC,IAAI,CAAC;QAC/D,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAdD,8CAcC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAC9B,IAA2B,EAC3B,UAAiC,IAAI;IAErC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAVD,4CAUC"}
|
|
@@ -98,9 +98,46 @@ function refusalFor(turn, guards) {
|
|
|
98
98
|
return 'unresolved-tool-call';
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
// LAST, because every reason above is a fact about the WIRE or about a
|
|
102
|
+
// human, and this one is a policy. A pinned turn that also holds an
|
|
103
|
+
// unanswered call reports the unanswered call: that is the reason a reader
|
|
104
|
+
// needs, and it is the one that would still be true with the pin switched
|
|
105
|
+
// off.
|
|
106
|
+
if (guards.pinnedTurnIndexes?.has(turn.index) === true)
|
|
107
|
+
return 'last-tool-result';
|
|
101
108
|
return undefined;
|
|
102
109
|
}
|
|
103
110
|
exports.refusalFor = refusalFor;
|
|
111
|
+
/**
|
|
112
|
+
* Spend the pin's ceiling, and only on turns that would otherwise leave.
|
|
113
|
+
*
|
|
114
|
+
* A pin inside `keepRecentTurns` is already safe — `planRemoval` never even
|
|
115
|
+
* asks about those turns — so it is filtered out here and costs nothing. The
|
|
116
|
+
* rest are admitted newest first, up to the ceiling; the remainder is counted
|
|
117
|
+
* as `yielded` so the record can say the pin wanted more than it was given.
|
|
118
|
+
*/
|
|
119
|
+
function admitPins(guards, candidateCount) {
|
|
120
|
+
const limit = guards.keepLastToolResults ?? 0;
|
|
121
|
+
const pins = guards.toolResultPins ?? [];
|
|
122
|
+
if (limit <= 0 || pins.length === 0)
|
|
123
|
+
return { guards };
|
|
124
|
+
const contested = pins.filter((p) => p.turnIndex < candidateCount);
|
|
125
|
+
const admitted = contested.slice(0, limit);
|
|
126
|
+
if (admitted.length === 0)
|
|
127
|
+
return { guards };
|
|
128
|
+
return {
|
|
129
|
+
guards: { ...guards, pinnedTurnIndexes: new Set(admitted.map((p) => p.turnIndex)) },
|
|
130
|
+
observations: {
|
|
131
|
+
pinned: admitted.map((p) => ({
|
|
132
|
+
toolName: p.toolName,
|
|
133
|
+
turnIndex: p.turnIndex,
|
|
134
|
+
chars: p.chars,
|
|
135
|
+
})),
|
|
136
|
+
yielded: contested.length - admitted.length,
|
|
137
|
+
limit,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
104
141
|
/**
|
|
105
142
|
* Choose the removal span: the LONGEST CONTIGUOUS run of removable candidate
|
|
106
143
|
* turns, starting at the oldest removable one.
|
|
@@ -135,12 +172,17 @@ function planRemoval(turns, keepRecent, guards, isExistingSummary) {
|
|
|
135
172
|
}
|
|
136
173
|
if (candidateCount === 0)
|
|
137
174
|
return { from: -1, to: -1, refusals };
|
|
175
|
+
// Spend the pin ceiling before asking anything, so `refusalFor` is answering
|
|
176
|
+
// one settled question per turn.
|
|
177
|
+
const admission = admitPins(guards, candidateCount);
|
|
178
|
+
const effective = admission.guards;
|
|
179
|
+
const observed = admission.observations;
|
|
138
180
|
const before = [];
|
|
139
181
|
let from = -1;
|
|
140
182
|
let to = -1;
|
|
141
183
|
for (let i = 0; i < candidateCount; i++) {
|
|
142
184
|
const turn = turns[i];
|
|
143
|
-
const reason = refusalFor(turn,
|
|
185
|
+
const reason = refusalFor(turn, effective);
|
|
144
186
|
if (reason === undefined) {
|
|
145
187
|
if (from === -1)
|
|
146
188
|
from = i;
|
|
@@ -167,9 +209,15 @@ function planRemoval(turns, keepRecent, guards, isExistingSummary) {
|
|
|
167
209
|
{ reason: 'only-existing-summary', turnIndex: from, messageIndex: turns[from].start },
|
|
168
210
|
...refusals,
|
|
169
211
|
],
|
|
212
|
+
...(observed !== undefined && { observations: observed }),
|
|
170
213
|
};
|
|
171
214
|
}
|
|
172
|
-
return {
|
|
215
|
+
return {
|
|
216
|
+
from,
|
|
217
|
+
to,
|
|
218
|
+
refusals: [...before, ...refusals],
|
|
219
|
+
...(observed !== undefined && { observations: observed }),
|
|
220
|
+
};
|
|
173
221
|
}
|
|
174
222
|
exports.planRemoval = planRemoval;
|
|
175
223
|
/** Total characters of message content in a window. Exact; not tokens. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turns.js","sourceRoot":"","sources":["../../../../src/core/agent/window/turns.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;
|
|
1
|
+
{"version":3,"file":"turns.js","sourceRoot":"","sources":["../../../../src/core/agent/window/turns.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAqBH;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,OAA8B;IACzD,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,IAAI,OAAO,GAAiB,EAAE,CAAC;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,MAAM,KAAK,GAAG,GAAS,EAAE;QACvB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACjC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACtF,OAAO,GAAG,EAAE,CAAC;IACf,CAAC,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QACxB,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChD,KAAK,EAAE,CAAC;YACR,KAAK,GAAG,CAAC,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IACD,KAAK,EAAE,CAAC;IACR,OAAO,KAAK,CAAC;AACf,CAAC;AArBD,oCAqBC;AA2CD,qEAA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