Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions packages/pi-fff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,30 @@ export default function fffExtension(pi: ExtensionAPI) {
pi.on("session_start", async (_event, ctx) => {
try {
activeCwd = ctx.cwd;

// Restore persisted mode from session entries. This handles session
// resume after process restart where env vars are lost, and ensures
// the env var is set for the next /reload in the same session.
const entries = ctx.sessionManager?.getEntries();
if (entries) {
const modeEntry = [...entries]
.reverse()
.find(
(e: { type: string; customType?: string }) =>
e.type === "custom" && e.customType === "fff-mode",
);
if (
modeEntry &&
typeof (modeEntry as any).data?.mode === "string" &&
VALID_MODES.includes((modeEntry as any).data.mode as FffMode)
) {
const restored = (modeEntry as any).data.mode as FffMode;
if (restored !== currentMode) {
currentMode = restored;
}
}
}

registerAutocompleteProvider(ctx);
await ensureFinder(activeCwd);
} catch (e: unknown) {
Expand Down Expand Up @@ -920,8 +944,10 @@ export default function fffExtension(pi: ExtensionAPI) {
if (!arg) {
const mode = getMode();
const flag = pi.getFlag("fff-mode") ?? "unset";
const env = process.env.PI_FFF_MODE ?? "unset";
ctx.ui.notify(`Current mode: '${mode}'\nFlag: ${flag}, Env: ${env}`, "info");
ctx.ui.notify(
`Current mode: '${mode}' (flag: ${flag})`,
"info",
);
return;
}

Expand All @@ -935,9 +961,11 @@ export default function fffExtension(pi: ExtensionAPI) {
const oldMode = getMode();
setMode(newMode);

pi.appendEntry("fff-mode", { mode: newMode });

const note =
(oldMode === "override") !== (newMode === "override")
? " (tool name change requires restart)"
? " (tool name change requires /reload)"
: "";
ctx.ui.notify(`Mode changed: '${oldMode}' → '${newMode}'${note}`, "info");
},
Expand Down
1 change: 1 addition & 0 deletions packages/pi-fff/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function createPi(mode?: string) {
}),
registerFlag: mock(() => undefined),
registerTool: mock(() => undefined),
appendEntry: mock(() => undefined),
};

return { pi, events, commands };
Expand Down
Loading