Files
oh-my-pi/packages/coding-agent/src/utils/edit-mode.ts
T
can1357 ea2f4b2557 feat(coding-agent): removed vim edit mode and migrated configs to hashline
- Removed vim edit mode and automatically map existing vim configurations to hashline mode.
- Deleted VimTool class, VimEngine implementation, and all vim-specific editing logic (2409 lines).
- Removed vim mode from EditMode union type, edit tool strategies, and configuration schemas.
- Deleted vim parser, command handler, buffer manager, and renderer modules.
- Updated documentation and tests to remove vim mode references and add deprecation mapping.
2026-05-26 13:16:59 +02:00

42 lines
1.3 KiB
TypeScript

import { $env } from "@oh-my-pi/pi-utils";
export type EditMode = "replace" | "patch" | "hashline" | "apply_patch";
export const DEFAULT_EDIT_MODE: EditMode = "hashline";
const EDIT_MODE_IDS = {
apply_patch: "apply_patch",
hashline: "hashline",
patch: "patch",
replace: "replace",
} as const satisfies Record<string, EditMode>;
export const EDIT_MODES = Object.keys(EDIT_MODE_IDS) as EditMode[];
export function normalizeEditMode(mode?: string | null): EditMode | undefined {
if (!mode) return undefined;
return EDIT_MODE_IDS[mode as keyof typeof EDIT_MODE_IDS];
}
export interface EditModeSettingsLike {
get(key: "edit.mode"): unknown;
getEditVariantForModel?(model: string | undefined): EditMode | null;
}
export interface EditModeSessionLike {
settings: EditModeSettingsLike;
getActiveModelString?: () => string | undefined;
}
export function resolveEditMode(session: EditModeSessionLike): EditMode {
const activeModel = session.getActiveModelString?.();
const modelVariant = session.settings.getEditVariantForModel?.(activeModel);
if (modelVariant) return modelVariant;
const envMode = normalizeEditMode($env.PI_EDIT_VARIANT);
if (envMode) return envMode;
const settingsMode = normalizeEditMode(String(session.settings.get("edit.mode") ?? ""));
return settingsMode ?? DEFAULT_EDIT_MODE;
}