@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
39 lines • 1.21 kB
JavaScript
import { closeSync, openSync, readFileSync, writeSync } from "node:fs";
export function seedKeybindingsFile(configPath, keybindings) {
let fd;
try {
// Exclusive create: fails with EEXIST if the file already exists, so a
// concurrently created config is never overwritten (no check-then-create window).
fd = openSync(configPath, "wx");
}
catch (error) {
if (error.code === "EEXIST")
return false;
throw error;
}
try {
writeSync(fd, `${JSON.stringify(keybindings.getEffectiveConfig(), null, 2)}\n`);
}
finally {
closeSync(fd);
}
return true;
}
export function applyKeybindingsFileEdit(configPath, keybindings) {
let raw;
try {
raw = readFileSync(configPath, "utf-8");
}
catch (error) {
return { status: "invalid", message: error instanceof Error ? error.message : String(error) };
}
try {
JSON.parse(raw);
}
catch (error) {
return { status: "invalid", message: error instanceof Error ? error.message : String(error) };
}
keybindings.reload();
return { status: "reloaded" };
}
//# sourceMappingURL=keybindings-command.js.map