fix(FN-2145): enforce absolute .fusion roots in core storage

- Default AgentStore rootDir to resolve(".fusion") so agent data paths are absolute by default
- Default ReflectionStore rootDir to resolve(".fusion") for consistent absolute root resolution
- Validate Database kbDir is absolute and throw a descriptive error when a relative path is provided
This commit is contained in:
Fusion
2026-04-19 09:25:22 -07:00
committed by gsxdsm
parent e6889a4b32
commit f40f87fca4
3 changed files with 9 additions and 5 deletions

View File

@@ -8,7 +8,7 @@
*/ */
import { mkdir, readFile, writeFile, readdir, unlink, rename } from "node:fs/promises"; import { mkdir, readFile, writeFile, readdir, unlink, rename } from "node:fs/promises";
import { basename, join } from "node:path"; import { basename, join, resolve } from "node:path";
import { randomUUID, randomBytes, createHash } from "node:crypto"; import { randomUUID, randomBytes, createHash } from "node:crypto";
import { EventEmitter } from "node:events"; import { EventEmitter } from "node:events";
import type { import type {
@@ -134,7 +134,7 @@ export class AgentStore extends EventEmitter {
constructor(options: AgentStoreOptions = {}) { constructor(options: AgentStoreOptions = {}) {
super(); super();
this.rootDir = options.rootDir ?? ".fusion"; this.rootDir = options.rootDir ?? resolve(".fusion");
this.agentsDir = join(this.rootDir, "agents"); this.agentsDir = join(this.rootDir, "agents");
this.taskStore = options.taskStore; this.taskStore = options.taskStore;
} }

View File

@@ -9,7 +9,7 @@
*/ */
import { DatabaseSync } from "node:sqlite"; import { DatabaseSync } from "node:sqlite";
import { join } from "node:path"; import { isAbsolute, join } from "node:path";
import { mkdirSync, existsSync } from "node:fs"; import { mkdirSync, existsSync } from "node:fs";
import { DEFAULT_PROJECT_SETTINGS } from "./types.js"; import { DEFAULT_PROJECT_SETTINGS } from "./types.js";
import type { SteeringComment, TaskComment } from "./types.js"; import type { SteeringComment, TaskComment } from "./types.js";
@@ -578,6 +578,10 @@ export class Database {
constructor(kbDir: string) { constructor(kbDir: string) {
this.dbPath = join(kbDir, "fusion.db"); this.dbPath = join(kbDir, "fusion.db");
if (!isAbsolute(kbDir)) {
throw new Error(`[fusion] Database constructor requires an absolute kbDir path, got: ${kbDir}`);
}
// Ensure .fusion directory exists // Ensure .fusion directory exists
if (!existsSync(kbDir)) { if (!existsSync(kbDir)) {
mkdirSync(kbDir, { recursive: true }); mkdirSync(kbDir, { recursive: true });

View File

@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
import { EventEmitter } from "node:events"; import { EventEmitter } from "node:events";
import { existsSync } from "node:fs"; import { existsSync } from "node:fs";
import { mkdir, readFile, unlink, writeFile } from "node:fs/promises"; import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
import { join } from "node:path"; import { join, resolve } from "node:path";
import type { import type {
AgentPerformanceSummary, AgentPerformanceSummary,
AgentReflection, AgentReflection,
@@ -63,7 +63,7 @@ export class ReflectionStore extends EventEmitter {
constructor(options: ReflectionStoreOptions = {}) { constructor(options: ReflectionStoreOptions = {}) {
super(); super();
this.rootDir = options.rootDir ?? ".fusion"; this.rootDir = options.rootDir ?? resolve(".fusion");
this.agentsDir = join(this.rootDir, "agents"); this.agentsDir = join(this.rootDir, "agents");
} }