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 () => {
await withTempHome(async (home) => {
vi.mocked(runEmbeddedPiAgent).mockReset();
const storePath = path.join(home, "sessions.json");
const res = await getReplyFromConfig(
{
@@ -834,13 +835,21 @@ describe("directive behavior", () => {
},
},
whatsapp: { allowFrom: ["+1222"] },
session: { store: path.join(home, "sessions.json") },
session: { store: storePath },
},
);
const text = Array.isArray(res) ? res[0]?.text : res?.text;
expect(text).toContain("Elevated mode disabled.");
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();
});
});

View File

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

View File

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