agent.libx.js 0.94.6 → 0.94.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/README.md +2 -1
- package/dist/{Agent-uWtu_WFY.d.ts → Agent-COa80xYy.d.ts} +4 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +175 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/dist/mcp.client.d.ts +2 -0
- package/dist/mcp.client.js +1 -1
- package/dist/mcp.client.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as AgentOptions, H as Hooks, h as RunResult, A as Agent } from './Agent-
|
|
2
|
-
export { C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-
|
|
1
|
+
import { a as AgentOptions, H as Hooks, h as RunResult, A as Agent } from './Agent-COa80xYy.js';
|
|
2
|
+
export { C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-COa80xYy.js';
|
|
3
3
|
import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
|
|
4
4
|
export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
|
|
5
5
|
import { BodDB } from '@bod.ee/db';
|
package/dist/index.js
CHANGED
|
@@ -2765,6 +2765,8 @@ var Agent = class _Agent {
|
|
|
2765
2765
|
transcript = [];
|
|
2766
2766
|
ctx;
|
|
2767
2767
|
// built in the ctor when `fs` is provided, else lazily in ensureFs()
|
|
2768
|
+
lastTrimNotified = 0;
|
|
2769
|
+
// last auto-trim drop count surfaced via host.notify (dedup)
|
|
2768
2770
|
activeTools = [];
|
|
2769
2771
|
activeHooks;
|
|
2770
2772
|
// composed: user hooks + plan-mode + permissions
|
|
@@ -2928,13 +2930,15 @@ var Agent = class _Agent {
|
|
|
2928
2930
|
* Fold the conversation in place (manual `/compact`): keep the system message + the
|
|
2929
2931
|
* most-recent window, summarizing the dropped middle (deterministic, no LLM call).
|
|
2930
2932
|
* No-op when the transcript already fits. Returns the number of messages removed.
|
|
2933
|
+
* `focus` (e.g. from `/compact keep the API details`) preserves matching lines from the
|
|
2934
|
+
* dropped span verbatim in the summary, instead of losing them to the generic recap.
|
|
2931
2935
|
*/
|
|
2932
|
-
compactNow(maxMessages = 12) {
|
|
2936
|
+
compactNow(maxMessages = 12, focus) {
|
|
2933
2937
|
const max = Math.max(2, maxMessages);
|
|
2934
2938
|
if (this.transcript.length <= max) return 0;
|
|
2935
2939
|
void this.activeHooks?.onPreCompact?.(this.transcript);
|
|
2936
2940
|
const before = this.transcript.length;
|
|
2937
|
-
this.transcript = compact(this.transcript, max);
|
|
2941
|
+
this.transcript = compact(this.transcript, max, focus);
|
|
2938
2942
|
return before - this.transcript.length;
|
|
2939
2943
|
}
|
|
2940
2944
|
async runLoop() {
|
|
@@ -3164,7 +3168,15 @@ ${out}`;
|
|
|
3164
3168
|
if (o.compaction?.maxMessages && m.length > o.compaction.maxMessages) out = compact(m, o.compaction.maxMessages);
|
|
3165
3169
|
else if (o.maxContextMessages && m.length > o.maxContextMessages) out = dropOldest(m, o.maxContextMessages);
|
|
3166
3170
|
if (o.keepToolOutputs) out = stubOldToolResults(out ?? m, o.keepToolOutputs);
|
|
3167
|
-
if (o.maxContextTokens)
|
|
3171
|
+
if (o.maxContextTokens) {
|
|
3172
|
+
const pre = (out ?? m).length;
|
|
3173
|
+
out = fitTokenBudget(out ?? m, o.maxContextTokens);
|
|
3174
|
+
const dropped = pre - out.length;
|
|
3175
|
+
if (dropped > 0 && dropped !== this.lastTrimNotified) {
|
|
3176
|
+
this.lastTrimNotified = dropped;
|
|
3177
|
+
o.host?.notify?.({ kind: "compaction", message: `context full \u2014 auto-trimmed ${dropped} oldest message(s) to fit ~${Math.round(o.maxContextTokens / 1e3)}k tokens` });
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3168
3180
|
return dropOrphanToolResults(out ?? m);
|
|
3169
3181
|
}
|
|
3170
3182
|
};
|
|
@@ -3224,16 +3236,16 @@ function fitTokenBudget(messages, maxTokens) {
|
|
|
3224
3236
|
log3.warn(`context ~${estimateTokens([...head, ...body])} tok still over maxContextTokens=${maxTokens} after trimming (system head can't be dropped)`);
|
|
3225
3237
|
return [...head, ...body];
|
|
3226
3238
|
}
|
|
3227
|
-
function compact(m, max) {
|
|
3239
|
+
function compact(m, max, focus) {
|
|
3228
3240
|
const hasSystem = m[0]?.role === "system";
|
|
3229
3241
|
const head = hasSystem ? [m[0]] : [];
|
|
3230
3242
|
const tailCount = Math.max(1, max - head.length - 1);
|
|
3231
3243
|
const tail = m.slice(head.length).slice(-tailCount);
|
|
3232
3244
|
const dropped = m.slice(head.length, m.length - tail.length);
|
|
3233
3245
|
if (dropped.length === 0) return [...head, ...tail];
|
|
3234
|
-
return [...head, { role: "system", content: summarize(dropped) }, ...tail];
|
|
3246
|
+
return [...head, { role: "system", content: summarize(dropped, focus) }, ...tail];
|
|
3235
3247
|
}
|
|
3236
|
-
function summarize(messages) {
|
|
3248
|
+
function summarize(messages, focus) {
|
|
3237
3249
|
const tools = /* @__PURE__ */ new Set();
|
|
3238
3250
|
const files = /* @__PURE__ */ new Set();
|
|
3239
3251
|
let lastAssistant = "";
|
|
@@ -3252,6 +3264,21 @@ function summarize(messages) {
|
|
|
3252
3264
|
if (tools.size) lines.push(`tools used: ${[...tools].join(", ")}`);
|
|
3253
3265
|
if (files.size) lines.push(`files touched: ${[...files].join(", ")}`);
|
|
3254
3266
|
if (lastAssistant) lines.push(`last assistant: ${lastAssistant}`);
|
|
3267
|
+
if (focus?.trim()) {
|
|
3268
|
+
const words = focus.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
3269
|
+
const kept = [];
|
|
3270
|
+
outer: for (const msg of messages) {
|
|
3271
|
+
if (msg.role === "tool") continue;
|
|
3272
|
+
for (const line of contentText(msg.content).split("\n")) {
|
|
3273
|
+
const l = line.toLowerCase();
|
|
3274
|
+
if (line.trim() && words.some((w) => l.includes(w))) {
|
|
3275
|
+
kept.push(line.trim().slice(0, 200));
|
|
3276
|
+
if (kept.length >= 12) break outer;
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
if (kept.length) lines.push(`preserved (re: ${focus.trim()}):`, ...kept.map((l) => ` ${l}`));
|
|
3281
|
+
}
|
|
3255
3282
|
return lines.join("\n");
|
|
3256
3283
|
}
|
|
3257
3284
|
function lastAssistantText(messages) {
|