fix: persist elevated off override

This commit is contained in:
Peter Steinberger
2026-01-10 05:23:29 +01:00
parent e4abd06094
commit 66db6c749d
3 changed files with 17 additions and 10 deletions

View File

@@ -811,6 +811,7 @@ describe("directive behavior", () => {
it("returns status alongside directive-only acks", async () => { it("returns status alongside directive-only acks", async () => {
await withTempHome(async (home) => { await withTempHome(async (home) => {
vi.mocked(runEmbeddedPiAgent).mockReset(); vi.mocked(runEmbeddedPiAgent).mockReset();
const storePath = path.join(home, "sessions.json");
const res = await getReplyFromConfig( const res = await getReplyFromConfig(
{ {
@@ -834,13 +835,21 @@ describe("directive behavior", () => {
}, },
}, },
whatsapp: { allowFrom: ["+1222"] }, whatsapp: { allowFrom: ["+1222"] },
session: { store: path.join(home, "sessions.json") }, session: { store: storePath },
}, },
); );
const text = Array.isArray(res) ? res[0]?.text : res?.text; const text = Array.isArray(res) ? res[0]?.text : res?.text;
expect(text).toContain("Elevated mode disabled."); expect(text).toContain("Elevated mode disabled.");
expect(text).toContain("Session: agent:main:main"); expect(text).toContain("Session: agent:main:main");
const optionsLine = text
?.split("\n")
.find((line) => line.trim().startsWith("⚙️"));
expect(optionsLine).toBeTruthy();
expect(optionsLine).not.toContain("elevated");
const store = loadSessionStore(storePath);
expect(store["agent:main:main"]?.elevatedLevel).toBe("off");
expect(runEmbeddedPiAgent).not.toHaveBeenCalled(); expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
}); });
}); });

View File

@@ -866,8 +866,9 @@ export async function handleDirectiveOnly(params: {
else sessionEntry.reasoningLevel = directives.reasoningLevel; else sessionEntry.reasoningLevel = directives.reasoningLevel;
} }
if (directives.hasElevatedDirective && directives.elevatedLevel) { if (directives.hasElevatedDirective && directives.elevatedLevel) {
if (directives.elevatedLevel === "off") delete sessionEntry.elevatedLevel; // Unlike other toggles, elevated defaults can be "on".
else sessionEntry.elevatedLevel = directives.elevatedLevel; // Persist "off" explicitly so `/elevated off` actually overrides defaults.
sessionEntry.elevatedLevel = directives.elevatedLevel;
} }
if (modelSelection) { if (modelSelection) {
if (modelSelection.isDefault) { if (modelSelection.isDefault) {
@@ -1049,11 +1050,8 @@ export async function persistInlineDirectives(params: {
elevatedEnabled && elevatedEnabled &&
elevatedAllowed elevatedAllowed
) { ) {
if (directives.elevatedLevel === "off") { // Persist "off" explicitly so inline `/elevated off` overrides defaults.
delete sessionEntry.elevatedLevel; sessionEntry.elevatedLevel = directives.elevatedLevel;
} else {
sessionEntry.elevatedLevel = directives.elevatedLevel;
}
updated = true; updated = true;
} }
const modelDirective = const modelDirective =

View File

@@ -144,8 +144,8 @@ export async function applySessionsPatchToStore(params: {
} else if (raw !== undefined) { } else if (raw !== undefined) {
const normalized = normalizeElevatedLevel(String(raw)); const normalized = normalizeElevatedLevel(String(raw));
if (!normalized) return invalid('invalid elevatedLevel (use "on"|"off")'); if (!normalized) return invalid('invalid elevatedLevel (use "on"|"off")');
if (normalized === "off") delete next.elevatedLevel; // Persist "off" explicitly so patches can override defaults.
else next.elevatedLevel = normalized; next.elevatedLevel = normalized;
} }
} }