library: billion-context's compression markers can be switched off (@JamesYu32 on X)

@JamesYu32 asked for a switch that turns off the markers billion-context
adds after it folds: compress.visibilityMarkers. In bili 0.1.213
(CONFIGURATION.md, dist/index.js) it is a boolean, true by default; true
appends the 📦/❌ line after a compress, decompress, search_context or
acp_status call and re-injects it into the rebuilt history, false drops
both, and the tool calls still run. Some models imitate the markers.

The billion-context tab's Advanced fold gets "Show compression markers",
on unless the file says false. Off writes compress.visibilityMarkers:
false through edit.PatchJSON (comments and every other key kept); on
takes the key out, back to bili's default, rather than leaving a value
magpie chose. A provider's or model's own compress.visibilityMarkers is
the user's and is left as it is; a non-boolean value (which bili
rejects) is not read as off. The running bili is asked to reload, as
for the other settings. Under Advanced because it is rarely changed.

Run (mote, at this tree on origin/main df2b819c6):
- go test -count=1 ./internal/library/ ./internal/gui/: ok (117s, 136s)
- go vet ./internal/library/ ./internal/gui/; GOOS=linux go vet -tags
  nogui and GOOS=windows go vet of both: clean. gofmt -l: nothing.
- node --test of every library*.test.cjs and i18n*.test.cjs (81 files,
  Chromium and WebKit, every language, 1100 and 420 wide): 1753 of
  1754 pass. library-bili-settings now switches the markers off under
  Advanced and checks the post is {markers:false}. The one red is
  i18n-keys "a plugin's words are its own": third_party/yaml.v3/yamlh.go
  (0caa09b3d) says the usage plugin's "Error type"; red on origin/main
  without this change, fixed in the next commit.
- Real bili 0.1.213 (npm, sandbox HOME/XDG on mote): started with
  {"compress":{"visibilityMarkers":false}}, GET /__bili/config showed
  "compress": {"visibilityMarkers": false}; with the key taken out,
  POST /__bili/config/reload answered 200 and the config had no
  visibilityMarkers (default on).

Broken by hand: on writing true instead of taking the key out,
TestBiliMarkersSwitch fails ("turning markers back on left the key in").

Not tried: a real agent session through bili to watch the markers
disappear from the model's view; only the config bili loads was checked.
This commit is contained in:
yetone
2026-11-14 15:33:24 +08:00
parent df2b819c67
commit 01c3efc4f7
7 changed files with 87 additions and 6 deletions
File diff suppressed because one or more lines are too long
@@ -2013,6 +2013,17 @@ magpie.plugin("library", (ctx) => {
const more = el("details", "lib-more lib-bili-more");
more.append(el("summary", "", t("Advanced")));
// compress.visibilityMarkers: the 📦/❌ lines after a fold, which
// some models imitate (@JamesYu32 on X)
const marks = el("div", "list lib-list lib-bili-marks");
const mk = toggle(s.markers !== false, t("Show compression markers"), (v) => biliChange({ markers: v }));
mk.disabled = biliSetBusy;
const mr = el("div", "row lib-row");
const mw = el("div", "who");
mw.append(el("div", "name", t("Show compression markers")));
mr.append(mw, el("span", "grow"), mk);
marks.append(mr);
more.append(marks);
const ph = el("div", "lib-bili-phil");
ph.append(el("div", "name", t("Compression philosophy")));
const ta = el("textarea", "lib-text small");
@@ -997,6 +997,7 @@ magpie.strings({
"Fold only when nudged": "仅在提示后折叠",
"Nudge every": "提示间隔",
"Compression philosophy": "压缩理念",
"Show compression markers": "显示压缩标记",
"billion-context's own": "billion-context 自带的",
"Replaces billion-context's guidance on what a fold keeps. Setting it also tells billion-context you accept the risk of changing its prompts.": "替换 billion-context 关于折叠时保留什么的指引。设置后也会告诉 billion-context 你接受修改其提示词的风险。",
"billion-context.json can't be read, so magpie leaves it alone. Fix it or take it out to change these here.": "billion-context.json 无法读取,magpie 不会改动它。修好或删掉它后才能在这里修改。",
@@ -2035,6 +2036,7 @@ magpie.strings({
"Fold only when nudged": "僅在提示後折疊",
"Nudge every": "提示間隔",
"Compression philosophy": "壓縮理念",
"Show compression markers": "顯示壓縮標記",
"billion-context's own": "billion-context 內建的",
"Replaces billion-context's guidance on what a fold keeps. Setting it also tells billion-context you accept the risk of changing its prompts.": "取代 billion-context 關於折疊時保留什麼的指引。設定後也會告訴 billion-context 你接受修改其提示詞的風險。",
"billion-context.json can't be read, so magpie leaves it alone. Fix it or take it out to change these here.": "billion-context.json 無法讀取,magpie 不會改動它。修好或刪除它後才能在這裡修改。",
@@ -3073,6 +3075,7 @@ magpie.strings({
"Fold only when nudged": "ナッジ後にのみ折りたたむ",
"Nudge every": "ナッジ間隔",
"Compression philosophy": "圧縮の方針",
"Show compression markers": "圧縮マーカーを表示",
"billion-context's own": "billion-context の既定",
"Replaces billion-context's guidance on what a fold keeps. Setting it also tells billion-context you accept the risk of changing its prompts.": "折りたたみで何を残すかについての billion-context の指針を置き換えます。設定すると、プロンプト変更のリスクを受け入れることも billion-context に伝えます。",
"billion-context.json can't be read, so magpie leaves it alone. Fix it or take it out to change these here.": "billion-context.json を読み込めないため、magpie は変更しません。ここで変更するには、修正するか削除してください。",
@@ -4111,6 +4114,7 @@ magpie.strings({
"Fold only when nudged": "Nur nach einem Anstoß falten",
"Nudge every": "Anstoß alle",
"Compression philosophy": "Komprimierungsleitlinie",
"Show compression markers": "Komprimierungsmarker anzeigen",
"billion-context's own": "Die von billion-context",
"Replaces billion-context's guidance on what a fold keeps. Setting it also tells billion-context you accept the risk of changing its prompts.": "Ersetzt die Leitlinie von billion-context dazu, was eine Faltung behält. Damit sagst du billion-context auch, dass du das Risiko geänderter Prompts in Kauf nimmst.",
"billion-context.json can't be read, so magpie leaves it alone. Fix it or take it out to change these here.": "billion-context.json lässt sich nicht lesen, daher lässt magpie sie unverändert. Repariere oder entferne sie, um das hier zu ändern.",
@@ -950,6 +950,7 @@ input.lib-memq:focus, input.lib-memtags:focus, input.lib-memwhy:focus { border-c
.lib-bili-more > summary:hover { color: var(--fg); }
.lib-bili-more > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .lib-bili-more > summary, .lib-bili-more > summary::before { transition: none; } }
.lib-bili-more > .lib-bili-marks { margin: 8px 0 0 15px; }
.lib-bili-phil { display: grid; gap: 6px; padding: 8px 0 0 15px; }
.lib-bili-phil > .name { font-size: 12.5px; color: var(--fg-2); }
.lib-bili-phil .lib-acts { justify-content: flex-end; }
@@ -2,7 +2,8 @@
// billion-context.json's settings in the Library's billion-context tab
// (@Luxzinw on X): below the agents, the summary model with its switch,
// fold only when nudged, and the nudge step in front; the compression
// philosophy under Advanced, folded until opened. Each change posts only
// philosophy and the compression markers' switch (@JamesYu32 on X:
// compress.visibilityMarkers) under Advanced, folded until opened. Each change posts only
// what changed to /api/library/bili/settings, and the status says whether
// the running billion-context reloaded it. The model is picked from the
// app's menu (never a <select>): magpie's models and the file's own
@@ -35,7 +36,7 @@ const MODELS = [
const settings = (st) => st.bad
? { path: `${HOME}/.config/billion-context/billion-context.json`, bad: "billion-context.json isn't JSON billion-context can read", targets: [], recipes: [], models: MODELS }
: { path: `${HOME}/.config/billion-context/billion-context.json`, growth: st.growth, nudge: st.nudge, summary: st.summary, targets: st.targets,
recipes: ["claude/claude-haiku"], philosophy: st.philosophy, risk: !!st.philosophy, reloaded: st.reloaded, running: 1, models: MODELS };
recipes: ["claude/claude-haiku"], philosophy: st.philosophy, risk: !!st.philosophy, markers: st.markers, reloaded: st.reloaded, running: 1, models: MODELS };
function server(lang, st) {
return async (route) => {
@@ -56,6 +57,7 @@ function server(lang, st) {
if ("target" in c) st.targets = [c.target, ...st.targets.filter((x) => x !== c.target)];
if ("summary" in c) st.summary = c.summary;
if ("philosophy" in c) st.philosophy = c.philosophy;
if ("markers" in c) st.markers = c.markers;
st.reloaded = 1;
return route.fulfill({ json: settings(st) });
}
@@ -99,7 +101,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
for (const lang of LANGS) for (const width of [1100, 420]) {
await t.test(`${lang} ${width}`, async () => {
const st = { growth: 0, nudge: false, summary: false, targets: [], philosophy: "", posts: [], reloaded: 0 };
const st = { growth: 0, nudge: false, summary: false, targets: [], philosophy: "", markers: true, posts: [], reloaded: 0 };
const ctx = await browser.newContext({ viewport: { width, height: 900 } });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
@@ -157,7 +159,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForFunction(() => document.querySelector("#view-library .lib-bili-phil textarea")?.value === "Keep every file path verbatim." && !document.querySelector("#view-library .lib-bili-phil textarea").disabled);
assert.deepEqual(st.posts.at(-1), { philosophy: "Keep every file path verbatim." });
assert.equal(await more.evaluate((d) => d.open), true, "Advanced closed again on its own");
assert.equal(st.posts.length, 4);
// Advanced: the compression markers, on by default, switched off
const mk = v.locator(".lib-bili-marks .lib-switch");
assert.equal(await mk.getAttribute("aria-checked"), "true");
const mname = (await v.locator(".lib-bili-marks .name").textContent()).trim();
if (lang !== "en") assert.notEqual(mname, "Show compression markers");
await mk.click();
await page.waitForFunction(() => document.querySelector("#view-library .lib-bili-marks .lib-switch")?.getAttribute("aria-checked") === "false");
assert.deepEqual(st.posts.at(-1), { markers: false });
assert.equal(await more.evaluate((d) => d.open), true, "Advanced closed again on its own");
assert.equal(st.posts.length, 5);
const sideways = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
assert(sideways <= 0, `the page scrolls sideways by ${sideways}px`);
+17 -1
View File
@@ -344,6 +344,10 @@ type BiliSettings struct {
// only with compress.acknowledgePromptsRisk (Risk)
Philosophy string `json:"philosophy"`
Risk bool `json:"risk"`
// Markers is compress.visibilityMarkers: the 📦/❌ lines bili adds
// after a compress, decompress or search_context call runs, on unless
// the file turns them off
Markers bool `json:"markers"`
// Reloaded of Running are the bilis that read a change again, of the
// ones running here
Reloaded int `json:"reloaded,omitempty"`
@@ -364,7 +368,7 @@ func ReadBiliSettings() (*BiliSettings, error) {
}
func biliSettingsOf(p, text string) *BiliSettings {
s := &BiliSettings{Path: p, Targets: []string{}, Recipes: []string{}}
s := &BiliSettings{Path: p, Targets: []string{}, Recipes: []string{}, Markers: true}
r, ok := biliParse(text)
if !ok {
s.Bad = "billion-context.json isn't JSON billion-context can read"
@@ -382,6 +386,8 @@ func biliSettingsOf(p, text string) *BiliSettings {
}
s.Philosophy = c.Get("prompts.compressPhilosophy").String()
s.Risk = c.Get("acknowledgePromptsRisk").Bool()
// bili takes only a boolean here; anything else isn't false to it
s.Markers = c.Get("visibilityMarkers").Type != gjson.False
r.Get("providers").ForEach(func(k, v gjson.Result) bool {
name := k.String()
if name == biliRecipe && biliOurs(r) || !v.IsObject() || !v.Get("baseUrl").Exists() && !v.Get("api").Exists() {
@@ -415,6 +421,9 @@ type BiliChange struct {
// Philosophy "" takes it out; one set turns acknowledgePromptsRisk on,
// which bili needs to use it
Philosophy *string `json:"philosophy"`
// Markers false turns compress.visibilityMarkers off; true takes the
// setting out, back to bili's default, which shows them
Markers *bool `json:"markers"`
}
// SetBiliSettings changes billion-context.json and has the bilis running
@@ -516,6 +525,13 @@ func setBiliSettings(p string, c BiliChange) (string, error) {
edit.KV{Path: "compress.acknowledgePromptsRisk", Value: true})
}
}
if c.Markers != nil {
if *c.Markers {
del = append(del, "compress.visibilityMarkers")
} else {
set = append(set, edit.KV{Path: "compress.visibilityMarkers", Value: false})
}
}
// a key taken out of nothing changes nothing; PatchJSON would refuse it
del = slices.DeleteFunc(del, func(k string) bool { return !r.Get(k).Exists() })
if len(set) == 0 && len(del) == 0 {
+37
View File
@@ -293,6 +293,43 @@ func TestBiliSettingsChanged(t *testing.T) {
}
}
// TestBiliMarkersSwitch (@JamesYu32 on X: a switch for visibilityMarkers):
// compress.visibilityMarkers reads as on until the file says false, the
// switch writes false where bili reads it (CONFIGURATION.md, 0.1.213),
// keeps the rest of the file, and turning it back on takes the key out to
// bili's default rather than leaving a value magpie chose. A provider's or
// model's own setting is the user's and stays as it is.
func TestBiliMarkersSwitch(t *testing.T) {
h, _ := biliSandbox(t, "4567")
write(t, biliCfgPath(h), biliFileFixture)
if s := biliMust[*BiliSettings](t)(ReadBiliSettings()); !s.Markers {
t.Fatal("markers read as off with nothing set")
}
off, on := false, true
s := biliMust[*BiliSettings](t)(SetBiliSettings(BiliChange{Markers: &off}))
r := biliJSON(t, biliCfgPath(h))
if v := r.Get("compress.visibilityMarkers"); v.Type != gjson.False || s.Markers {
t.Fatalf("not turned off: %s (read back %v)", r.Get("compress").Raw, s.Markers)
}
if !strings.Contains(read(t, biliCfgPath(h)), "// my summary models") || !r.Get("retained").Bool() {
t.Error("the rest of the file wasn't kept")
}
s = biliMust[*BiliSettings](t)(SetBiliSettings(BiliChange{Markers: &on}))
if biliJSON(t, biliCfgPath(h)).Get("compress.visibilityMarkers").Exists() || !s.Markers {
t.Error("turning markers back on left the key in")
}
// a provider's own setting is left alone, and a non-boolean bili
// rejects is not read as off
write(t, biliCfgPath(h), `{"compress":{"visibilityMarkers":"no"},"providers":{"x":{"compress":{"visibilityMarkers":false}}}}`)
if s := biliMust[*BiliSettings](t)(ReadBiliSettings()); !s.Markers {
t.Error(`"no" read as off`)
}
biliMust[*BiliSettings](t)(SetBiliSettings(BiliChange{Markers: &off}))
if r := biliJSON(t, biliCfgPath(h)); r.Get("providers.x.compress.visibilityMarkers").Type != gjson.False || r.Get("compress.visibilityMarkers").Type != gjson.False {
t.Errorf("got %s", r.Raw)
}
}
// TestBiliSettingsRefused: what bili would refuse, and so turn its whole
// compress section off over, is never written: an out-of-range step, a
// summary switched on with no model, a recipe of the user's named magpie,