@nanocollective/nanocoder
Version:
A local-first CLI coding agent that brings the power of agentic coding tools like Claude Code and Gemini CLI to local models or controlled APIs like OpenRouter
68 lines • 2.23 kB
JavaScript
import { randomUUID } from 'node:crypto';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
const SCHEDULES_DIR = '.nanocoder';
const SCHEDULES_FILE = 'schedules.json';
const SCHEDULE_RUNS_FILE = 'schedule-runs.json';
const MAX_RUNS = 100;
function getSchedulesPath() {
return join(process.cwd(), SCHEDULES_DIR, SCHEDULES_FILE);
}
function getScheduleRunsPath() {
return join(process.cwd(), SCHEDULES_DIR, SCHEDULE_RUNS_FILE);
}
export function generateScheduleId() {
return randomUUID().slice(0, 8);
}
export async function loadSchedules() {
try {
const path = getSchedulesPath();
const content = await readFile(path, 'utf-8');
const data = JSON.parse(content);
return data.schedules ?? [];
}
catch {
return [];
}
}
export async function saveSchedules(schedules) {
const dirPath = join(process.cwd(), SCHEDULES_DIR);
await mkdir(dirPath, { recursive: true });
const path = getSchedulesPath();
const data = { schedules };
await writeFile(path, JSON.stringify(data, null, 2), 'utf-8');
}
export async function loadScheduleRuns() {
try {
const path = getScheduleRunsPath();
const content = await readFile(path, 'utf-8');
const data = JSON.parse(content);
return data.runs ?? [];
}
catch {
return [];
}
}
export async function saveScheduleRuns(runs) {
const dirPath = join(process.cwd(), SCHEDULES_DIR);
await mkdir(dirPath, { recursive: true });
const path = getScheduleRunsPath();
// Cap at MAX_RUNS entries
const cappedRuns = runs.slice(-MAX_RUNS);
const data = { runs: cappedRuns };
await writeFile(path, JSON.stringify(data, null, 2), 'utf-8');
}
export async function addScheduleRun(run) {
const runs = await loadScheduleRuns();
runs.push(run);
await saveScheduleRuns(runs);
}
export async function updateScheduleRun(runId, updates) {
const runs = await loadScheduleRuns();
const index = runs.findIndex(r => r.id === runId);
if (index !== -1) {
runs[index] = { ...runs[index], ...updates };
await saveScheduleRuns(runs);
}
}
//# sourceMappingURL=storage.js.map