"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.expandWorkspacesRoot = expandWorkspacesRoot; exports.loadEnv = loadEnv; exports.loadDisclawConfig = loadDisclawConfig; const fs = __importStar(require("fs")); const os = __importStar(require("os")); const path = __importStar(require("path")); const dotenv = __importStar(require("dotenv")); const YAML = __importStar(require("yaml")); /** * Expands a leading `~` in a path to the user's home directory and resolves * the result to an absolute, normalised path. No shell expansion is used. * * Exported as a pure function so it can be unit-tested independently. */ function expandWorkspacesRoot(raw, repoRoot) { let expanded = raw; if (expanded.startsWith("~")) { expanded = os.homedir() + expanded.slice(1); } const resolved = path.resolve(repoRoot, expanded); const rel = path.relative(repoRoot, resolved); const isInsideRepo = !rel.startsWith("..") && !path.isAbsolute(rel); if (isInsideRepo) { console.warn("[DisClaw] WARNING: workspaces_root lies inside the DisClaw repository (" + resolved + "). " + "Claude Code walks parent directories and concatenates every CLAUDE.md it finds. " + "A workspace under the repo root will inherit the project CLAUDE.md, " + "leaking DisClaw system instructions into every agent context. " + "Set workspaces_root to a path outside the repository (e.g. ~/.disclaw/workspaces)."); } return resolved; } function loadEnv(rootDir) { dotenv.config({ path: path.join(rootDir, ".env") }); const token = process.env.DISCORD_BOT_TOKEN; if (!token) { throw new Error("DISCORD_BOT_TOKEN is not set in .env"); } return { DISCORD_BOT_TOKEN: token, DISCORD_GUILD_ID: process.env.DISCORD_GUILD_ID, CLAUDE_PATH: process.env.CLAUDE_PATH, }; } function loadDisclawConfig(rootDir) { const configPath = path.join(rootDir, "disclaw.yaml"); if (!fs.existsSync(configPath)) { throw new Error(`disclaw.yaml not found at ${configPath}`); } const raw = fs.readFileSync(configPath, "utf-8"); const parsed = YAML.parse(raw); // Apply defaults const rawWorkspacesRoot = parsed.workspaces_root ?? "~/.disclaw/workspaces"; const config = { workspaces_root: expandWorkspacesRoot(rawWorkspacesRoot, rootDir), management_channel: parsed.management_channel ?? "disclaw", claude_command: parsed.claude_command ?? "claude", claude_timeout_seconds: parsed.claude_timeout_seconds ?? 120, env_blocklist: parsed.env_blocklist ?? [], }; return config; } //# sourceMappingURL=loader.js.map