billion-context-pi 0.1.63-pr.352.146 → 0.1.63
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/config.d.ts +0 -10
- package/dist/index.js +0 -185
- package/dist/index.js.map +1 -1
- package/dist/user-config.d.ts +1 -4
- package/package.json +1 -1
- package/dist/degeneration.d.ts +0 -98
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type Config, type Prompts } from "acp-kernel";
|
|
2
2
|
import type { CompressReasoningConfig } from "./reasoning-drop.js";
|
|
3
|
-
import type { DegenerationGuardConfig } from "./degeneration.js";
|
|
4
3
|
import type { ThrottleRetryConfig } from "./throttle-retry.js";
|
|
5
4
|
/** Per-role delegate defaults. Lets long-lived automation pin a cheaper or
|
|
6
5
|
* more capable model and a thinking level per delegate role, so the main
|
|
@@ -223,15 +222,6 @@ export interface AdapterConfig {
|
|
|
223
222
|
* warn=3, abort=5. Stops greedy small models looping on byte-identical
|
|
224
223
|
* tool calls (issue #308). */
|
|
225
224
|
repetitionGuard?: boolean | RepetitionGuardConfig;
|
|
226
|
-
/** Character-level degenerate-repeat guard (see DegenerationGuardConfig).
|
|
227
|
-
* Collapses long single-codepoint runs (e.g. 4655×「【」) in assistant
|
|
228
|
-
* text/thinking of the outgoing view and injects a one-shot recovery notice
|
|
229
|
-
* after a degenerated turn — breaking the abort loop where pi replays the
|
|
230
|
-
* degenerated thinking back to the provider on every request (issue #351).
|
|
231
|
-
* Distinct from `repetitionGuard`, which is tool-call level. Accepts a
|
|
232
|
-
* boolean shorthand (`false` disables) or an object. Default: enabled,
|
|
233
|
-
* minRun=200. */
|
|
234
|
-
degenerationGuard?: boolean | DegenerationGuardConfig;
|
|
235
225
|
/** Legacy flat alias for `delegate.displayUsage`. Kept for backward
|
|
236
226
|
* compatibility with existing acp.json files. Prefer `delegate.displayUsage`. */
|
|
237
227
|
displayUsage?: "merged" | "separate";
|
package/dist/index.js
CHANGED
|
@@ -4739,8 +4739,6 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
4739
4739
|
"displayUsage",
|
|
4740
4740
|
"throttleRetry",
|
|
4741
4741
|
"outputHeadroomMaxPct",
|
|
4742
|
-
"repetitionGuard",
|
|
4743
|
-
"degenerationGuard",
|
|
4744
4742
|
"prompts",
|
|
4745
4743
|
"acknowledgePromptsRisk"
|
|
4746
4744
|
]);
|
|
@@ -16859,170 +16857,6 @@ async function statusReport(runtime, ctx) {
|
|
|
16859
16857
|
return text;
|
|
16860
16858
|
}
|
|
16861
16859
|
|
|
16862
|
-
// src/degeneration.ts
|
|
16863
|
-
var DEFAULT_DEGENERATION_GUARD = { enabled: true, minRun: 200 };
|
|
16864
|
-
var MIN_VALID_MIN_RUN = 8;
|
|
16865
|
-
function resolveDegenerationGuard(cfg) {
|
|
16866
|
-
if (cfg === false) return { enabled: false, minRun: DEFAULT_DEGENERATION_GUARD.minRun };
|
|
16867
|
-
const c = typeof cfg === "object" && cfg !== null ? cfg : {};
|
|
16868
|
-
let minRun = DEFAULT_DEGENERATION_GUARD.minRun;
|
|
16869
|
-
if (c.minRun !== void 0) {
|
|
16870
|
-
const n = c.minRun;
|
|
16871
|
-
if (typeof n === "number" && Number.isFinite(n) && n >= 2) {
|
|
16872
|
-
minRun = Math.max(MIN_VALID_MIN_RUN, Math.floor(n));
|
|
16873
|
-
} else {
|
|
16874
|
-
logWarn("config", { event: "degeneration-guard-invalid", field: "minRun", value: n, fallback: DEFAULT_DEGENERATION_GUARD.minRun });
|
|
16875
|
-
}
|
|
16876
|
-
}
|
|
16877
|
-
return { enabled: c.enabled !== false, minRun };
|
|
16878
|
-
}
|
|
16879
|
-
var preScreenMinRun = Number.NaN;
|
|
16880
|
-
var preScreenRe = null;
|
|
16881
|
-
function hasLongRun(text, minRun) {
|
|
16882
|
-
const n = Math.floor(minRun);
|
|
16883
|
-
if (preScreenRe === null || preScreenMinRun !== n) {
|
|
16884
|
-
preScreenMinRun = n;
|
|
16885
|
-
preScreenRe = new RegExp(`(.)\\1{${Math.max(n - 1, 0)},}`, "su");
|
|
16886
|
-
}
|
|
16887
|
-
return preScreenRe.test(text);
|
|
16888
|
-
}
|
|
16889
|
-
function findDegenerateRuns(text, minRun) {
|
|
16890
|
-
const runs2 = [];
|
|
16891
|
-
if (!text || !Number.isFinite(minRun) || minRun < 2) return runs2;
|
|
16892
|
-
if (!hasLongRun(text, minRun)) return runs2;
|
|
16893
|
-
const chars = Array.from(text);
|
|
16894
|
-
let utf16 = 0;
|
|
16895
|
-
let k = 0;
|
|
16896
|
-
while (k < chars.length) {
|
|
16897
|
-
const ch = chars[k];
|
|
16898
|
-
let m2 = k + 1;
|
|
16899
|
-
while (m2 < chars.length && chars[m2] === ch) m2++;
|
|
16900
|
-
const count = m2 - k;
|
|
16901
|
-
if (count >= minRun) runs2.push({ char: ch, count, index: utf16 });
|
|
16902
|
-
utf16 += count * ch.length;
|
|
16903
|
-
k = m2;
|
|
16904
|
-
}
|
|
16905
|
-
return runs2;
|
|
16906
|
-
}
|
|
16907
|
-
function describeChar(ch) {
|
|
16908
|
-
if (ch === " ") return "space";
|
|
16909
|
-
if (ch === "\n") return "newline";
|
|
16910
|
-
if (ch === " ") return "tab";
|
|
16911
|
-
if (ch === "\r") return "carriage-return";
|
|
16912
|
-
const cp = ch.codePointAt(0) ?? 0;
|
|
16913
|
-
if (cp < 32 || cp === 127) return `U+${cp.toString(16).toUpperCase().padStart(4, "0")}`;
|
|
16914
|
-
return JSON.stringify(ch);
|
|
16915
|
-
}
|
|
16916
|
-
function applyRuns(text, runs2, minRun) {
|
|
16917
|
-
const keep = Math.max(1, Math.min(3, minRun - 1));
|
|
16918
|
-
let out = "";
|
|
16919
|
-
let last = 0;
|
|
16920
|
-
for (const r of runs2) {
|
|
16921
|
-
out += text.slice(last, r.index);
|
|
16922
|
-
out += `${r.char.repeat(keep)}\u2026 [${r.count}\xD7 identical chars cut \u2014 degenerate repeat]`;
|
|
16923
|
-
last = r.index + r.count * r.char.length;
|
|
16924
|
-
}
|
|
16925
|
-
out += text.slice(last);
|
|
16926
|
-
return out;
|
|
16927
|
-
}
|
|
16928
|
-
function collapseAssistantDegeneration(messages, cfg) {
|
|
16929
|
-
const { enabled, minRun } = resolveDegenerationGuard(cfg);
|
|
16930
|
-
if (!enabled || messages.length === 0) return { messages, evidence: [] };
|
|
16931
|
-
try {
|
|
16932
|
-
const evidence = [];
|
|
16933
|
-
let changed = false;
|
|
16934
|
-
const out = messages.slice();
|
|
16935
|
-
for (let i = 0; i < messages.length; i++) {
|
|
16936
|
-
const msg = messages[i];
|
|
16937
|
-
if (msg.role !== "assistant") continue;
|
|
16938
|
-
const c = msg.content;
|
|
16939
|
-
if (typeof c === "string") {
|
|
16940
|
-
const runs3 = findDegenerateRuns(c, minRun);
|
|
16941
|
-
if (runs3.length > 0) {
|
|
16942
|
-
out[i] = { ...msg, content: applyRuns(c, runs3, minRun) };
|
|
16943
|
-
evidence.push({ msgIndex: i, blocks: ["content"], runs: runs3 });
|
|
16944
|
-
changed = true;
|
|
16945
|
-
}
|
|
16946
|
-
continue;
|
|
16947
|
-
}
|
|
16948
|
-
if (!Array.isArray(c)) continue;
|
|
16949
|
-
const blocks = [];
|
|
16950
|
-
const runs2 = [];
|
|
16951
|
-
let blockChanged = false;
|
|
16952
|
-
const nc = c.map((p) => {
|
|
16953
|
-
const b2 = p;
|
|
16954
|
-
if (b2?.type === "text" && typeof b2.text === "string") {
|
|
16955
|
-
const r = findDegenerateRuns(b2.text, minRun);
|
|
16956
|
-
if (r.length > 0) {
|
|
16957
|
-
blockChanged = true;
|
|
16958
|
-
blocks.push("text");
|
|
16959
|
-
runs2.push(...r);
|
|
16960
|
-
return { ...b2, text: applyRuns(b2.text, r, minRun) };
|
|
16961
|
-
}
|
|
16962
|
-
return p;
|
|
16963
|
-
}
|
|
16964
|
-
if (b2?.type === "thinking" && typeof b2.thinking === "string") {
|
|
16965
|
-
const r = findDegenerateRuns(b2.thinking, minRun);
|
|
16966
|
-
if (r.length > 0) {
|
|
16967
|
-
blockChanged = true;
|
|
16968
|
-
blocks.push("thinking");
|
|
16969
|
-
runs2.push(...r);
|
|
16970
|
-
return { ...b2, thinking: applyRuns(b2.thinking, r, minRun) };
|
|
16971
|
-
}
|
|
16972
|
-
return p;
|
|
16973
|
-
}
|
|
16974
|
-
return p;
|
|
16975
|
-
});
|
|
16976
|
-
if (blockChanged) {
|
|
16977
|
-
out[i] = { ...msg, content: nc };
|
|
16978
|
-
evidence.push({ msgIndex: i, blocks, runs: runs2 });
|
|
16979
|
-
changed = true;
|
|
16980
|
-
}
|
|
16981
|
-
}
|
|
16982
|
-
return { messages: changed ? out : messages, evidence };
|
|
16983
|
-
} catch {
|
|
16984
|
-
return { messages, evidence: [] };
|
|
16985
|
-
}
|
|
16986
|
-
}
|
|
16987
|
-
function lastAssistantRuns(messages, minRun) {
|
|
16988
|
-
try {
|
|
16989
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
16990
|
-
const msg = messages[i];
|
|
16991
|
-
if (msg.role !== "assistant") continue;
|
|
16992
|
-
const runs2 = [];
|
|
16993
|
-
const c = msg.content;
|
|
16994
|
-
if (typeof c === "string") {
|
|
16995
|
-
runs2.push(...findDegenerateRuns(c, minRun));
|
|
16996
|
-
} else if (Array.isArray(c)) {
|
|
16997
|
-
for (const p of c) {
|
|
16998
|
-
const b2 = p;
|
|
16999
|
-
if (b2?.type === "text" && typeof b2.text === "string") runs2.push(...findDegenerateRuns(b2.text, minRun));
|
|
17000
|
-
else if (b2?.type === "thinking" && typeof b2.thinking === "string") runs2.push(...findDegenerateRuns(b2.thinking, minRun));
|
|
17001
|
-
}
|
|
17002
|
-
}
|
|
17003
|
-
return runs2.length > 0 ? runs2 : null;
|
|
17004
|
-
}
|
|
17005
|
-
return null;
|
|
17006
|
-
} catch {
|
|
17007
|
-
return null;
|
|
17008
|
-
}
|
|
17009
|
-
}
|
|
17010
|
-
function degenerationNotice(runs2) {
|
|
17011
|
-
const sorted = [...runs2].sort((a, b2) => b2.count - a.count);
|
|
17012
|
-
const top = sorted[0];
|
|
17013
|
-
const extra = sorted.length > 1 ? ` and ${sorted.length - 1} other repeated segment(s)` : "";
|
|
17014
|
-
return {
|
|
17015
|
-
role: "user",
|
|
17016
|
-
content: [
|
|
17017
|
-
{
|
|
17018
|
-
type: "text",
|
|
17019
|
-
text: `[ACP recovery notice] Your previous turn ended in degenerate generation: its output contained ${top.count} consecutive repetitions of ${describeChar(top.char)}${extra}. That repeated segment carries no information and has been truncated in the context above. Do not reproduce it or continue the pattern. Resume your task from your last valid step.`
|
|
17020
|
-
}
|
|
17021
|
-
],
|
|
17022
|
-
timestamp: Date.now()
|
|
17023
|
-
};
|
|
17024
|
-
}
|
|
17025
|
-
|
|
17026
16860
|
// src/system-prompt.ts
|
|
17027
16861
|
function buildAcpSystemPrompt(prompts) {
|
|
17028
16862
|
return `
|
|
@@ -17850,7 +17684,6 @@ function wireSessionLifecycle(pi, runtime, standDownIfProxied) {
|
|
|
17850
17684
|
closeLogStream();
|
|
17851
17685
|
});
|
|
17852
17686
|
}
|
|
17853
|
-
var lastDegNoticeKey = null;
|
|
17854
17687
|
function wireContextTransform(pi, runtime, standDownIfProxied) {
|
|
17855
17688
|
pi.on("context", async (event, ctx) => {
|
|
17856
17689
|
if (runtime.refused) return;
|
|
@@ -17963,24 +17796,6 @@ function wireContextTransform(pi, runtime, standDownIfProxied) {
|
|
|
17963
17796
|
debug.event("reasoning-drop", { sid, droppedChars, drop: reasoningDrop.drop, threshold: reasoningDrop.threshold });
|
|
17964
17797
|
}
|
|
17965
17798
|
rebuilt = droppedThinking;
|
|
17966
|
-
const degCfg = resolveDegenerationGuard(runtime.adapter.degenerationGuard);
|
|
17967
|
-
const tailRuns = degCfg.enabled ? lastAssistantRuns([...originalById.values()], degCfg.minRun) : null;
|
|
17968
|
-
const deg = collapseAssistantDegeneration(rebuilt, degCfg);
|
|
17969
|
-
if (deg.messages !== rebuilt) {
|
|
17970
|
-
rebuilt = deg.messages;
|
|
17971
|
-
const maxRun = deg.evidence.reduce((m2, e) => e.runs.reduce((x2, r) => Math.max(x2, r.count), m2), 0);
|
|
17972
|
-
logWarn("degeneration", { sid, event: "runs-collapsed", msgs: deg.evidence.length, maxRun, minRun: degCfg.minRun });
|
|
17973
|
-
debug.event("degeneration-collapsed", { sid, msgs: deg.evidence.length, maxRun });
|
|
17974
|
-
}
|
|
17975
|
-
if (tailRuns) {
|
|
17976
|
-
rebuilt.push(degenerationNotice(tailRuns));
|
|
17977
|
-
const top = [...tailRuns].sort((a, b2) => b2.count - a.count)[0];
|
|
17978
|
-
logInfo("degeneration", { sid, event: "recovery-notice", maxRun: top.count });
|
|
17979
|
-
if (ctx.hasUI && lastDegNoticeKey !== `${sid}:${top.count}:${top.char.codePointAt(0)}`) {
|
|
17980
|
-
lastDegNoticeKey = `${sid}:${top.count}:${top.char.codePointAt(0)}`;
|
|
17981
|
-
ctx.ui.notify(`[ACP] previous turn ended in degenerate generation (${top.count}\xD7 repeat) \u2014 the repeated segment was truncated above and a recovery notice injected.`);
|
|
17982
|
-
}
|
|
17983
|
-
}
|
|
17984
17799
|
const debugOn2 = debug.enabled;
|
|
17985
17800
|
const turnKey = lastUserMessageId(entries) ?? sid;
|
|
17986
17801
|
const compressOutcomes = collectCompressOutcomes(entries, turnStartIndex(entries));
|