/** * @file sessionDefaults.ts * @description The account's own starting choices for new work, picked in the * first-run setup (docs/plans/onboarding) and synced per account like every * other preference (`lib/userPrefs.ts`): the AI a new workspace starts on, and * the permission mode a new Claude session starts in. Bypass is NEVER one of * them — it stays the per-session switch (CLAUDE.md), so `bypassPermissions` * is refused on read and on write. * @author Nguyễn Ngọc Trí Vĩ */ import type { PermissionMode } from "./api"; const TOOL_KEY = "agenthub.defaultTool"; const MODE_KEY = "agenthub.permissionMode"; /** The permission modes a default may be. */ export const DEFAULT_MODES = ["auto", "acceptEdits", "default", "plan"] as const; export type DefaultMode = (typeof DEFAULT_MODES)[number]; function read(key: string): string | null { try { return localStorage.getItem(key); } catch { return null; } } function write(key: string, value: string): void { try { localStorage.setItem(key, value); } catch { /* storage blocked */ } } /** The account's own default AI tool id, or null (the install's default applies). */ export const readDefaultTool = (): string | null => read(TOOL_KEY); export const writeDefaultTool = (id: string): void => write(TOOL_KEY, id); /** The permission mode a new Claude session starts in ("auto" when none was picked). */ export function readDefaultMode(): PermissionMode { const v = read(MODE_KEY); return (DEFAULT_MODES as readonly string[]).includes(v ?? "") ? (v as DefaultMode) : "auto"; } export function writeDefaultMode(mode: DefaultMode): void { if ((DEFAULT_MODES as readonly string[]).includes(mode)) write(MODE_KEY, mode); }