UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

22 lines • 1.3 kB
import { homedir } from "os"; import { join } from "path"; import { CONFIG_DIR_NAME, ENV_AGENT_DIR, isBunBinary } from "./config.js"; const SOURCE_MODULE_PATTERN = /\.(ts|mts|cts|tsx)$/; export function isFromSourceRun(moduleUrl = import.meta.url, bunBinary = isBunBinary) { return !bunBinary && SOURCE_MODULE_PATTERN.test(moduleUrl); } export function targetsRealUserAgentDir(agentDir, envAgentDir = process.env[ENV_AGENT_DIR], homeDir = homedir()) { return !envAgentDir && agentDir === join(homeDir, CONFIG_DIR_NAME, "agent"); } /** * A run from TypeScript sources (dev/QA) that resolves to the real user agent * dir is the exact setup that has leaked writes into real user config before. * Returns the warning to print, or undefined when the run is safe. */ export function getFromSourceRealConfigWarning(agentDir, moduleUrl = import.meta.url, envAgentDir = process.env[ENV_AGENT_DIR], homeDir = homedir(), bunBinary = isBunBinary) { if (!isFromSourceRun(moduleUrl, bunBinary) || !targetsRealUserAgentDir(agentDir, envAgentDir, homeDir)) { return undefined; } return `Warning: running from source against the real user config (${agentDir}). Set ${ENV_AGENT_DIR} to an isolated directory for dev and QA runs.`; } //# sourceMappingURL=from-source-config-guard.js.map