Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

refactor(shared): extract DATA_DIR constant to shared/paths.ts

yushen36e9acb35f7c
diff --git a/src/agent/profile-cli.ts b/src/agent/profile-cli.ts
index e708e2ce52..d3055734c1 100644
--- a/src/agent/profile-cli.ts
+++ b/src/agent/profile-cli.ts
@@ -10,7 +10,6 @@
*/
import { existsSync, readdirSync } from "node:fs";
-import { homedir } from "node:os";
import { join } from "node:path";
import {
createAgentProfile,
@@ -18,8 +17,9 @@ import {
getProfileDir,
profileExists,
} from "./profile/index.js";
+import { DATA_DIR } from "../shared/index.js";
-const DEFAULT_BASE_DIR = join(homedir(), ".super-multica", "agent-profiles");
+const DEFAULT_BASE_DIR = join(DATA_DIR, "agent-profiles");
type Command = "new" | "list" | "show" | "edit" | "help";
diff --git a/src/agent/profile/storage.ts b/src/agent/profile/storage.ts
index fc281bf383..fa8493fe6e 100644
--- a/src/agent/profile/storage.ts
+++ b/src/agent/profile/storage.ts
@@ -3,11 +3,11 @@
*/
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
-import { homedir } from "node:os";
import { join } from "node:path";
import { PROFILE_FILES, type AgentProfile } from "./types.js";
+import { DATA_DIR } from "../../shared/index.js";
-const DEFAULT_BASE_DIR = join(homedir(), ".super-multica", "agent-profiles");
+const DEFAULT_BASE_DIR = join(DATA_DIR, "agent-profiles");
export interface StorageOptions {
baseDir?: string | undefined;
diff --git a/src/agent/session/storage.ts b/src/agent/session/storage.ts
index fbffa76a15..b219fd95ef 100644
--- a/src/agent/session/storage.ts
+++ b/src/agent/session/storage.ts
@@ -1,15 +1,15 @@
-import { homedir } from "os";
import { join } from "path";
import { existsSync, mkdirSync, readFileSync } from "fs";
import { appendFile, writeFile } from "fs/promises";
import type { SessionEntry } from "./types.js";
+import { DATA_DIR } from "../../shared/index.js";
export type SessionStorageOptions = {
baseDir?: string | undefined;
};
export function resolveBaseDir(options?: SessionStorageOptions) {
- return options?.baseDir ?? join(homedir(), ".super-multica", "sessions");
+ return options?.baseDir ?? join(DATA_DIR, "sessions");
}
export function resolveSessionDir(sessionId: string, options?: SessionStorageOptions) {
diff --git a/src/agent/skills/loader.ts b/src/agent/skills/loader.ts
index a6f11c6607..875ad4f7d9 100644
--- a/src/agent/skills/loader.ts
+++ b/src/agent/skills/loader.ts
@@ -5,17 +5,17 @@
*/
import { existsSync, readdirSync, statSync } from "node:fs";
-import { homedir } from "node:os";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import type { Skill, SkillSource, SkillManagerOptions } from "./types.js";
import { SKILL_FILE, SKILL_SOURCE_PRECEDENCE } from "./types.js";
import { parseSkillFile } from "./parser.js";
+import { DATA_DIR } from "../../shared/index.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
/** Default profile base directory */
-const DEFAULT_PROFILE_BASE_DIR = join(homedir(), ".super-multica", "agent-profiles");
+const DEFAULT_PROFILE_BASE_DIR = join(DATA_DIR, "agent-profiles");
/** Bundled skills directory (relative to package) */
const BUNDLED_DIR = join(__dirname, "../../../skills");
diff --git a/src/hub/device.ts b/src/hub/device.ts
index 1b375b1bba..4e637b6259 100644
--- a/src/hub/device.ts
+++ b/src/hub/device.ts
@@ -1,10 +1,9 @@
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
-import { homedir } from "node:os";
import { join } from "node:path";
import { v7 as uuidv7 } from "uuid";
+import { DATA_DIR } from "../shared/index.js";
-const MULTICA_DIR = join(homedir(), ".multica");
-const DEVICE_ID_FILE = join(MULTICA_DIR, "device-id");
+const DEVICE_ID_FILE = join(DATA_DIR, "device-id");
/**
* 获取当前设备的 ID。
@@ -16,7 +15,7 @@ export function getDeviceId(): string {
return readFileSync(DEVICE_ID_FILE, "utf-8").trim();
} catch {
const id = uuidv7();
- mkdirSync(MULTICA_DIR, { recursive: true });
+ mkdirSync(DATA_DIR, { recursive: true });
writeFileSync(DEVICE_ID_FILE, id, "utf-8");
return id;
}
diff --git a/src/shared/index.ts b/src/shared/index.ts
index 214db21fbd..36af41c8ed 100644
--- a/src/shared/index.ts
+++ b/src/shared/index.ts
@@ -1,2 +1,3 @@
export * from "./types.js";
+export * from "./paths.js";
export * from "./gateway-sdk/index.js";
diff --git a/src/shared/paths.ts b/src/shared/paths.ts
new file mode 100644
index 0000000000..3d2e006b7d
--- /dev/null
+++ b/src/shared/paths.ts
@@ -0,0 +1,5 @@
+import { join } from "node:path";
+import { homedir } from "node:os";
+
+/** Root data directory: ~/.super-multica */
+export const DATA_DIR = join(homedir(), ".super-multica");