@cubicecho/agent-core 2.18.0 → 2.18.1

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.
@@ -107,21 +107,30 @@ export declare function orderTools(tools: OpenAI.ChatCompletionTool[], order?: T
107
107
  export declare const MAX_PER_LOAD = 12;
108
108
  /**
109
109
  * The most a conversation carries between turns. Bounds the tool array no matter how long the
110
- * conversation runs; least-recently-used names fall off the front.
110
+ * conversation runs; past it, the earliest-declared names this turn did not use fall off first.
111
111
  *
112
112
  * Only a multi-turn caller needs this — a run that starts from nothing each time has nothing to
113
113
  * carry. See `carryOver`, which takes another number if this one is not yours.
114
114
  */
115
115
  export declare const MAX_CARRIED = 16;
116
116
  /**
117
- * The tools to start the next turn with: recently used, newest last, capped.
118
- *
119
- * @param previous Last turn's names, oldest first.
120
- * @param used What this turn called. Moved to the end, so the oldest unused fall off.
121
- * @param max How many to carry, defaulting to `MAX_CARRIED`. At least one: a cap of zero is
122
- * read as no cap, which is what `slice` does with it and not what anybody asking for zero meant.
117
+ * The tools to start the next turn with: last turn's where they were, then what this turn used.
118
+ *
119
+ * Nothing carried moves. A template renders the tool array near the head of the prompt, and
120
+ * moving each used tool to the end — which this did until it was found in a local server's cache
121
+ * log — reordered the array between turns and re-prefilled the whole transcript from the first
122
+ * moved definition. Kept in place, the next turn's array is this one's with only the unused
123
+ * loads gone, a prefix of it when every load was used. Past `max`, dropping a name from the
124
+ * middle costs the cache from there, so it happens only when the cap forces it.
125
+ *
126
+ * @param previous Last turn's names, in the order they were declared.
127
+ * @param used What this turn called. Names not already carried are appended in the order given,
128
+ * so pass them in load order to keep them where the tool array had them.
129
+ * @param max How many to carry, defaulting to `MAX_CARRIED`. Past it, the earliest names not in
130
+ * `used` go first, then the earliest of all. At least one: a cap of zero is read as one, not as
131
+ * no cap and not as none.
123
132
  */
124
- export declare const carryOver: (previous: string[], used: Set<string>, max?: number) => string[];
133
+ export declare function carryOver(previous: readonly string[], used: ReadonlySet<string>, max?: number): string[];
125
134
  /**
126
135
  * Resolves requested names against the catalogue, expanding trailing `*` wildcards.
127
136
  *
@@ -174,21 +174,38 @@ export function orderTools(tools, order = true) {
174
174
  export const MAX_PER_LOAD = 12;
175
175
  /**
176
176
  * The most a conversation carries between turns. Bounds the tool array no matter how long the
177
- * conversation runs; least-recently-used names fall off the front.
177
+ * conversation runs; past it, the earliest-declared names this turn did not use fall off first.
178
178
  *
179
179
  * Only a multi-turn caller needs this — a run that starts from nothing each time has nothing to
180
180
  * carry. See `carryOver`, which takes another number if this one is not yours.
181
181
  */
182
182
  export const MAX_CARRIED = 16;
183
183
  /**
184
- * The tools to start the next turn with: recently used, newest last, capped.
185
- *
186
- * @param previous Last turn's names, oldest first.
187
- * @param used What this turn called. Moved to the end, so the oldest unused fall off.
188
- * @param max How many to carry, defaulting to `MAX_CARRIED`. At least one: a cap of zero is
189
- * read as no cap, which is what `slice` does with it and not what anybody asking for zero meant.
184
+ * The tools to start the next turn with: last turn's where they were, then what this turn used.
185
+ *
186
+ * Nothing carried moves. A template renders the tool array near the head of the prompt, and
187
+ * moving each used tool to the end — which this did until it was found in a local server's cache
188
+ * log — reordered the array between turns and re-prefilled the whole transcript from the first
189
+ * moved definition. Kept in place, the next turn's array is this one's with only the unused
190
+ * loads gone, a prefix of it when every load was used. Past `max`, dropping a name from the
191
+ * middle costs the cache from there, so it happens only when the cap forces it.
192
+ *
193
+ * @param previous Last turn's names, in the order they were declared.
194
+ * @param used What this turn called. Names not already carried are appended in the order given,
195
+ * so pass them in load order to keep them where the tool array had them.
196
+ * @param max How many to carry, defaulting to `MAX_CARRIED`. Past it, the earliest names not in
197
+ * `used` go first, then the earliest of all. At least one: a cap of zero is read as one, not as
198
+ * no cap and not as none.
190
199
  */
191
- export const carryOver = (previous, used, max = MAX_CARRIED) => [...previous.filter((name) => !used.has(name)), ...used].slice(-Math.max(1, max));
200
+ export function carryOver(previous, used, max = MAX_CARRIED) {
201
+ const next = [...previous, ...[...used].filter((name) => !previous.includes(name))];
202
+ const cap = Math.max(1, max);
203
+ while (next.length > cap) {
204
+ const stale = next.findIndex((name) => !used.has(name));
205
+ next.splice(stale === -1 ? 0 : stale, 1);
206
+ }
207
+ return next;
208
+ }
192
209
  /**
193
210
  * Resolves requested names against the catalogue, expanding trailing `*` wildcards.
194
211
  *
package/llms.txt CHANGED
@@ -300,7 +300,7 @@ Reading what a model meant by a tool call when it did not write one cleanly.
300
300
 
301
301
  ### tool-loading
302
302
 
303
- - `carryOver` — The tools to start the next turn with: recently used, newest last, capped.
303
+ - `carryOver` — The tools to start the next turn with: last turn's where they were, then what this turn used.
304
304
  - `catalogList` — The catalogue as a plain grouped listing of names, loaded ones marked if asked.
305
305
  - `catalogPrompt` — The catalogue block appended to the system prompt.
306
306
  - `expandNames` — Resolves requested names against the catalogue, expanding trailing `*` wildcards.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubicecho/agent-core",
3
- "version": "2.18.0",
3
+ "version": "2.18.1",
4
4
  "description": "The endpoint-agnostic half of an OpenAI-compatible agent loop: tool-schema compatibility, on-demand tool loading, one-shot side tasks, run events, and a pooled client.",
5
5
  "keywords": [
6
6
  "openai",