- Replaced SettingsManager class with new Settings singleton providing synchronous get/set API and background persistence.
- Introduced settings-schema.ts as single source of truth for all configuration definitions with 100+ settings organized into logical groups.
- Migrated from method-based settings access (getTheme(), setTheme()) to path-based access using dot notation (settings.get('theme'), settings.set('theme', value)).
- Removed 2035-line settings-manager.ts file and replaced with modular settings.ts (693 lines) and settings-schema.ts (836 lines) for improved maintainability.
- Unified settings schema into single source of truth eliminating duplicate definitions across settings-defs.ts and settings-manager.ts.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { resolvePlanUrlToPath } from "../internal-urls";
|
|
import type { ToolSession } from ".";
|
|
import { resolveToCwd } from "./path-utils";
|
|
import { ToolError } from "./tool-errors";
|
|
|
|
const PLAN_URL_PREFIX = "plan://";
|
|
|
|
export function resolvePlanPath(session: ToolSession, targetPath: string): string {
|
|
if (!targetPath.startsWith(PLAN_URL_PREFIX)) {
|
|
return resolveToCwd(targetPath, session.cwd);
|
|
}
|
|
|
|
return resolvePlanUrlToPath(targetPath, {
|
|
getPlansDirectory: () => session.settings.getPlansDirectory(),
|
|
cwd: session.cwd,
|
|
});
|
|
}
|
|
|
|
export function enforcePlanModeWrite(
|
|
session: ToolSession,
|
|
targetPath: string,
|
|
options?: { rename?: string; op?: "create" | "update" | "delete" },
|
|
): void {
|
|
const state = session.getPlanModeState?.();
|
|
if (!state?.enabled) return;
|
|
|
|
const resolvedTarget = resolvePlanPath(session, targetPath);
|
|
const resolvedPlan = resolvePlanPath(session, state.planFilePath);
|
|
|
|
if (options?.rename) {
|
|
throw new ToolError("Plan mode: renaming files is not allowed.");
|
|
}
|
|
|
|
if (options?.op === "delete") {
|
|
throw new ToolError("Plan mode: deleting files is not allowed.");
|
|
}
|
|
|
|
if (resolvedTarget !== resolvedPlan) {
|
|
throw new ToolError(`Plan mode: only the plan file may be modified (${state.planFilePath}).`);
|
|
}
|
|
}
|