feat: @agor/stores package + Electrobun hardening (WIP)

- packages/stores/: theme, notifications, health stores extracted
- Electrobun hardening: durable event sequencing, file conflict detection,
  push-based updates, backpressure guards (partial, agents still running)
This commit is contained in:
Hibryda 2026-03-22 04:40:04 +01:00
parent 5836fb7d80
commit 5e1fd62ed9
13 changed files with 855 additions and 665 deletions

View file

@ -76,6 +76,21 @@ export function createFilesHandlers() {
}
},
// Feature 2: Get file stat (mtime) for conflict detection
"files.stat": async ({ path: filePath }: { path: string }) => {
const guard = guardPath(filePath);
if (!guard.valid) {
return { mtimeMs: 0, size: 0, error: guard.error };
}
try {
const stat = fs.statSync(guard.resolved);
return { mtimeMs: stat.mtimeMs, size: stat.size };
} catch (err) {
const error = err instanceof Error ? err.message : String(err);
return { mtimeMs: 0, size: 0, error };
}
},
"files.write": async ({ path: filePath, content }: { path: string; content: string }) => {
const guard = guardPath(filePath);
if (!guard.valid) {
@ -83,7 +98,10 @@ export function createFilesHandlers() {
return { ok: false, error: guard.error };
}
try {
fs.writeFileSync(guard.resolved, content, "utf8");
// Feature 2: Atomic write via temp file + rename
const tmpPath = guard.resolved + ".agor-tmp";
fs.writeFileSync(tmpPath, content, "utf8");
fs.renameSync(tmpPath, guard.resolved);
return { ok: true };
} catch (err) {
const error = err instanceof Error ? err.message : String(err);