/** * Strategy-root resolver (mmnto-ai/totem#1710). * * Single source of truth for "where is the strategy repo on disk." Replaces * the hardcoded `.strategy/` submodule path with a configurable resolver that * checks four precedence layers: * * 1. **env** — `TOTEM_STRATEGY_ROOT` (canonical) or `STRATEGY_ROOT` (alias). * 2. **config** — `TotemConfig.strategyRoot`. * 3. **sibling** — `/../totem-strategy`. * 4. **submodule** — `/.strategy`. * * Each layer must resolve to a real directory (`fs.statSync(...).isDirectory()`) * before it counts; a value that points at a file or a missing path falls * through to the next layer. Returns a `StrategyRootStatus` discriminated * union so callers can pattern-match on `resolved` without a TS-side type * assertion. * * Anchors relative env / config values at `gitRoot`, not at the literal cwd — * a deep cwd like `packages/mcp/src/` with `STRATEGY_ROOT=../totem-strategy` * would otherwise resolve to `packages/mcp/totem-strategy`, which is wrong. * * Pure utility. No caching, no side effects, no logging. Each call walks the * precedence chain from scratch so a process that mutates `process.env` mid-run * sees the new value on the next call. */ /** * Discriminated union. The `resolved: true` branch carries an absolute `path` * and a `source` tag so callers can route per-layer (e.g., the `submodule` * source is the legacy path that the gitlink-removal follow-up will retire). * The `resolved: false` branch carries a `reason` string suitable for * surfacing to agents and for the `totem doctor` advisory. */ export type StrategyRootStatus = { resolved: true; path: string; source: 'env' | 'config' | 'sibling' | 'submodule'; } | { resolved: false; reason: string; }; /** * Minimal config shape consumed by the resolver. Avoids importing the full * `TotemConfig` type to keep the resolver dependency-light and to let * callers pass partial config objects (e.g., during init or in tests). */ export interface StrategyResolverConfig { strategyRoot?: string; } export interface StrategyResolverOptions { /** Test seam — production callers omit and the resolver invokes `resolveGitRoot(cwd)` itself. */ gitRoot?: string | null; /** Test seam — production callers omit and the resolver reads `process.env`. */ env?: Record; /** Loaded `totem.config.ts` shape (only `strategyRoot` is read). */ config?: StrategyResolverConfig; } /** * Walk the four-layer precedence chain. Returns a `StrategyRootStatus` * discriminated union. * * The git-root probe is lazy. `resolveGitRoot` can throw `TotemGitError` on * permission errors or a corrupted index; an eager probe would short-circuit * an absolute env / config override that doesn't need git context at all. * `getAnchor` defers the probe and swallows throws, so absolute overrides * always get their precedence-1 / precedence-2 chance. */ export declare function resolveStrategyRoot(cwd: string, options?: StrategyResolverOptions): StrategyRootStatus; //# sourceMappingURL=strategy-resolver.d.ts.map