remove seed directory, clean up provisioning and sync modules

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 00:07:50 +00:00
co-authored by Claude Opus 4.6
parent 9578110e8b
commit 56f8da8907
86 changed files with 182 additions and 12061 deletions
+30 -14
View File
@@ -1,10 +1,7 @@
import { join } from 'node:path';
import { mkdirSync, existsSync } from 'node:fs';
import { mkdirSync, existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
const DATA_PATH = process.env.DATA_PATH ?? join(process.cwd(), 'data');
const STATE_DIR = join(DATA_PATH, 'sidecar');
const STATE_FILE = join(STATE_DIR, 'claude-state.json');
const LOCK_FILE = join(STATE_DIR, 'claude.lock');
export type PersistedState = {
proxySecret: string;
@@ -16,23 +13,42 @@ const DEFAULT_STATE: PersistedState = {
claudeSessions: {},
};
let stateDir: string;
let stateFile: string;
let lockFile: string;
let currentState: PersistedState = { ...DEFAULT_STATE };
let saveTimer: Timer | null = null;
/** Call once at startup to configure paths. For proxy: no email. For per-user: pass email. */
export function initPaths(email?: string): void {
if (email) {
stateDir = join(DATA_PATH, email, 'sidecar');
stateFile = join(stateDir, 'claude-state.json');
lockFile = join(stateDir, 'claude.lock');
} else {
stateDir = join(DATA_PATH, 'sidecar');
stateFile = join(stateDir, 'claude-state.json');
lockFile = join(stateDir, 'claude.lock');
}
}
// Default to proxy paths
initPaths();
function ensureDir() {
if (!existsSync(STATE_DIR)) {
mkdirSync(STATE_DIR, { recursive: true });
if (!existsSync(stateDir)) {
mkdirSync(stateDir, { recursive: true });
}
}
export function loadState(): PersistedState {
ensureDir();
try {
if (!existsSync(STATE_FILE)) {
if (!existsSync(stateFile)) {
currentState = { ...DEFAULT_STATE };
return currentState;
}
const text = require('node:fs').readFileSync(STATE_FILE, 'utf-8');
const text = readFileSync(stateFile, 'utf-8');
currentState = { ...DEFAULT_STATE, ...JSON.parse(text) };
return currentState;
} catch {
@@ -43,7 +59,7 @@ export function loadState(): PersistedState {
export async function saveState(): Promise<void> {
ensureDir();
await Bun.write(STATE_FILE, JSON.stringify(currentState, null, 2));
await Bun.write(stateFile, JSON.stringify(currentState, null, 2));
}
export function getState(): PersistedState {
@@ -90,14 +106,14 @@ export async function flushAndSave(): Promise<void> {
export function acquireLock(): boolean {
ensureDir();
try {
if (existsSync(LOCK_FILE)) {
const pidStr = require('node:fs').readFileSync(LOCK_FILE, 'utf-8').trim();
if (existsSync(lockFile)) {
const pidStr = readFileSync(lockFile, 'utf-8').trim();
const pid = Number(pidStr);
if (pid && isProcessAlive(pid)) {
return false;
}
}
require('node:fs').writeFileSync(LOCK_FILE, String(process.pid));
writeFileSync(lockFile, String(process.pid));
return true;
} catch {
return false;
@@ -106,8 +122,8 @@ export function acquireLock(): boolean {
export function releaseLock(): void {
try {
if (existsSync(LOCK_FILE)) {
require('node:fs').unlinkSync(LOCK_FILE);
if (existsSync(lockFile)) {
unlinkSync(lockFile);
}
} catch {
// best effort