Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/loopover-miner/lib/governor-ledger.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { chmodSync, mkdirSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { DatabaseSync } from "node:sqlite";
import { join } from "node:path";
import { normalizeGovernorLedgerEvent } from "@loopover/engine";
import { openLocalStoreDb } from "./local-store.js";
import { applySchemaMigrations } from "./schema-version.js";
import {
GOVERNOR_LEDGER_PURGE_SPEC,
Expand Down Expand Up @@ -96,10 +95,7 @@ function rowToDecision(row) {
*/
export function initGovernorLedger(dbPath = resolveGovernorLedgerDbPath()) {
const resolvedPath = normalizeDbPath(dbPath);
mkdirSync(dirname(resolvedPath), { recursive: true, mode: 0o700 });
const db = new DatabaseSync(resolvedPath);
chmodSync(resolvedPath, 0o600);
db.exec("PRAGMA busy_timeout = 5000");
const db = openLocalStoreDb(resolvedPath);
db.exec(`
CREATE TABLE IF NOT EXISTS governor_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand Down
15 changes: 5 additions & 10 deletions packages/loopover-miner/lib/plan-store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { chmodSync, mkdirSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { DatabaseSync } from "node:sqlite";
import { join } from "node:path";
import { openLocalStoreDb } from "./local-store.js";
import { applySchemaMigrations } from "./schema-version.js";

// Local SQLite persistence for the stateless MCP plan DAG (#2318). `loopover_build_plan`/`plan_status`/
Expand Down Expand Up @@ -150,13 +149,9 @@ function rowToRecord(row) {
*/
export function openPlanStore(dbPath = resolvePlanStoreDbPath()) {
const resolvedPath = normalizeDbPath(dbPath);
// The store is a persistent local file; the special in-memory path (':memory:') has no file to create or chmod.
if (resolvedPath !== ":memory:") {
mkdirSync(dirname(resolvedPath), { recursive: true, mode: 0o700 });
}
const db = new DatabaseSync(resolvedPath);
if (resolvedPath !== ":memory:") chmodSync(resolvedPath, 0o600);
db.exec("PRAGMA busy_timeout = 5000");
// openLocalStoreDb centralizes the mkdir(0o700)/chmod(0o600)/busy_timeout + crash-safe cleanup registration and
// treats ':memory:' as a no-file special case, so this store no longer hand-rolls that boilerplate (#4826).
const db = openLocalStoreDb(resolvedPath);
db.exec(`
CREATE TABLE IF NOT EXISTS miner_plans (
plan_id TEXT PRIMARY KEY,
Expand Down
10 changes: 3 additions & 7 deletions packages/loopover-miner/lib/prediction-ledger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { chmodSync, mkdirSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join } from "node:path";
import { DatabaseSync } from "node:sqlite";
import { join } from "node:path";
import { openLocalStoreDb } from "./local-store.js";
import {
PREDICTION_LEDGER_PURGE_SPEC,
PREDICTION_LEDGER_RETENTION_SPEC,
Expand Down Expand Up @@ -135,10 +134,7 @@ function rowToEntry(row) {
*/
export function initPredictionLedger(dbPath = resolvePredictionLedgerDbPath()) {
const resolvedPath = normalizeDbPath(dbPath);
mkdirSync(dirname(resolvedPath), { recursive: true, mode: 0o700 });
const db = new DatabaseSync(resolvedPath);
chmodSync(resolvedPath, 0o600);
db.exec("PRAGMA busy_timeout = 5000");
const db = openLocalStoreDb(resolvedPath);
db.exec(`
CREATE TABLE IF NOT EXISTS predictions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand Down