/**
 * Directory Management
 *
 * Manages the .codegraph/ directory structure for CodeGraph data.
 */
/** The default per-project data directory name. */
export declare const DEFAULT_CODEGRAPH_DIR = ".codegraph";
/**
 * The data directory name WSL gives a fresh project on a Windows drive, so it
 * never shares one index with CodeGraph on Windows (issue #995). Indexing and
 * watching skip every `.codegraph-*` sibling on both sides (#636).
 */
export declare const WSL_CODEGRAPH_DIR = ".codegraph-wsl";
/**
 * Resolve the per-project data directory name, honoring the `CODEGRAPH_DIR`
 * environment override (default `.codegraph`). The override is a single path
 * segment that lives in the project root.
 *
 * Why this exists: two environments that share one working tree must NOT share
 * one `.codegraph/` — most concretely Windows-native and WSL (issue #636). The
 * daemon lockfile (`.codegraph/daemon.pid`) records a platform-specific pid and
 * socket path (a Windows named pipe vs a WSL Unix socket), and SQLite file
 * locking across the WSL2 ↔ Windows filesystem boundary is unreliable, so two
 * daemons sharing one index risks corruption. Setting `CODEGRAPH_DIR=.codegraph-win`
 * on one side gives each environment its own index in the same tree.
 *
 * Read live (not captured at load) so it is both process-accurate and testable.
 * An override that isn't a plain directory name — empty, containing a path
 * separator, `.`, `..`/traversal, or absolute — is ignored (we keep the
 * default) rather than risk writing the index outside the project or into the
 * project root itself; we warn once to stderr so the misconfiguration is seen.
 */
export declare function codeGraphDirName(): string;
/**
 * CodeGraph directory name — a load-time snapshot of {@link codeGraphDirName}.
 * A running process's environment is fixed, so this equals the live value;
 * it's kept as a stable string export for backward compatibility. Internal code
 * resolves the name through {@link codeGraphDirName} / {@link getCodeGraphDir}
 * so the `CODEGRAPH_DIR` override always applies.
 */
export declare const CODEGRAPH_DIR: string;
/**
 * Is `name` (a single path segment) a CodeGraph data directory? Matches the
 * default `.codegraph`, the active `CODEGRAPH_DIR` override, and any
 * `.codegraph-*` sibling. File-watching and the indexer skip ALL of these, so
 * when two environments share one working tree (Windows + WSL, issue #636)
 * neither indexes or watches the other's index directory.
 */
export declare function isCodeGraphDataDir(name: string): boolean;
/**
 * The data directory name for one project: {@link codeGraphDirName}, except
 * for a project on a Windows drive under WSL (`/mnt/c/...`) with no
 * `CODEGRAPH_DIR` set. Windows-native CodeGraph opens `.codegraph` in that
 * same tree, and SQLite's locking doesn't hold across the 9p/DrvFs bridge, so
 * the two sharing one index fails with "disk I/O error" (issue #995). There:
 *
 *   1. `.codegraph-wsl/` exists → it. Once WSL has its own index it keeps it,
 *      even after Windows builds a `.codegraph` beside it.
 *   2. `.codegraph/codegraph.db` exists → `.codegraph`. An index built before
 *      this default is kept rather than silently rebuilt somewhere else.
 *   3. neither → `.codegraph-wsl`, so a fresh WSL index never shares.
 *
 * Every other host keeps the plain name without a stat: the WSL check is
 * cached per process.
 */
export declare function codeGraphDirNameFor(projectRoot: string): string;
/**
 * Get the .codegraph directory path for a project
 */
export declare function getCodeGraphDir(projectRoot: string): string;
/**
 * Check if a project has been initialized with CodeGraph.
 *
 * Requires `.codegraph/codegraph.db` to exist AND to carry the codegraph
 * schema. A file that merely exists — empty, or a SQLite database with no
 * tables, as an interrupted `init` or a stray `touch` leaves behind — used to
 * count as initialized, so one such file in an ANCESTOR directory (worst
 * case: `$HOME`) captured the upward resolution of every project beneath it
 * and made their real indexes unreachable (#1895).
 *
 * The probe is cheap and gated so hot callers (the prompt hook, MCP root
 * resolution on every call) pay one `stat`: file size, then a read-only
 * SQLite open with a single `sqlite_master` lookup — memoized per path +
 * mtime + size so an unchanged db is never reopened. A database that cannot
 * be inspected counts as initialized (see probeSchema) — only a proven-absent
 * schema, or a file SQLite refuses as not a database, says no.
 */
export declare function isInitialized(projectRoot: string): boolean;
/**
 * `codegraph.db` exists at `projectRoot` but does not carry the schema, and
 * `init` can add it in place: an empty file, or a SQLite database without the
 * codegraph tables (#1895). A file that is not SQLite at all is NOT this case —
 * see {@link hasForeignDbFile}.
 */
export declare function hasSchemalessDb(projectRoot: string): boolean;
/**
 * `codegraph.db` exists at `projectRoot` and is not a SQLite database (no
 * header magic): SQLite refuses to open it, so `init` cannot rebuild it in
 * place. The caller must say so rather than promise a repair; nothing here
 * deletes the file.
 */
export declare function hasForeignDbFile(projectRoot: string): boolean;
/**
 * Find the nearest parent directory containing .codegraph/
 *
 * Walks up from the given path to find a CodeGraph-initialized project,
 * similar to how git finds .git/ directories.
 *
 * @param startPath - Directory to start searching from
 * @returns The project root containing .codegraph/, or null if not found
 */
/**
 * Reason a directory is unsafe to use as an index ROOT, or null when it's fine.
 *
 * Indexing your home directory or a filesystem root drags in caches, `Library`,
 * every other project, etc. — a multi-GB index, constant file-watcher churn, and
 * (pre-1.0 on macOS) a file-descriptor blowup that exhausted `kern.maxfiles` and
 * took unrelated apps / the whole machine down (#845). The classic trigger:
 * running the installer or `codegraph init` from `$HOME`, which auto-indexes the
 * current directory. These are never intended project roots, so the installer
 * and `init`/`index` refuse them (overridable with `--force`).
 *
 * Pure-ish (reads only `os.homedir()` + realpath) so it's easy to unit-test.
 * The returned string is a human phrase that slots into "… looks like {reason}".
 */
export declare function unsafeIndexRootReason(projectRoot: string): string | null;
/**
 * `dev:ino` for a path, or null if it can't be stat'd or the platform doesn't
 * report a usable inode. Read as bigints: WSL DrvFs (`/mnt/c`) reports inodes
 * above 2^53, where a plain number rounds nearby inodes onto one value. Windows
 * st_ino is unreliable across handle reopens, so we deliberately return null
 * there — the deleted-but-open-inode hazard this guards (#925) is a POSIX
 * file-semantics issue that doesn't arise on Windows (an open file can't be
 * unlinked).
 */
export declare function statInode(p: string): string | null;
/**
 * Canonicalize a project root for IDENTITY: hashing it into a rendezvous key
 * (the daemon's named pipe / tmpdir socket, a registry record). Not for display
 * — the caller-visible root keeps its own spelling.
 *
 * The contract is that two spellings of ONE directory yield ONE string, because
 * a client that derives a different key silently fails to meet the daemon that
 * is already running: it probes a socket nobody bound, spawns a redundant
 * daemon, and that daemon dies on the lock the first one holds, so the session
 * degrades to a single-process engine. `path.resolve` alone does NOT satisfy
 * that contract — NTFS is case-insensitive, so `d:\work\codegraph` and
 * `D:\work\codegraph` name one directory but two strings, and non-native
 * `fs.realpathSync` keeps whichever casing the caller passed (only `.native`
 * asks the filesystem for the on-disk name — the same reason
 * {@link isSameIndexRoot} uses it). Both spellings really do occur: a
 * cwd-derived root is the on-disk case, while a client-supplied
 * `rootUri`/`workspaceFolders` path arrives as `file:///d%3A/…`.
 *
 * The Windows lowercase is belt-and-braces on top of the native realpath — NTFS
 * can't hold two directories differing only by case, and it also absorbs a
 * `\\?\`-prefixed native result diverging from a plain one.
 */
export declare function canonicalProjectRoot(projectRoot: string): string;
/**
 * Whether two resolved index roots are one index spelled two ways — a symlinked
 * checkout, or a case-variant on a case-insensitive mount (macOS, NTFS, WSL
 * DrvFs `/mnt/c`), where `realpathSync` keeps the caller's casing (#1057).
 * Compares the identity of both data directories as they are NOW, so an inode
 * reused after a delete can't match: the deleted root no longer stats. Windows
 * has no usable inode, so it compares the on-disk-cased native realpaths.
 */
export declare function isSameIndexRoot(a: string, b: string): boolean;
export declare function findNearestCodeGraphRoot(startPath: string): string | null;
/**
 * Indexed sub-project roots beneath `root` (bounded breadth-first scan). For
 * the monorepo case behind #964: the index lives in a CHILD
 * (`packages/x/.codegraph/`), not at the workspace root the agent's cwd points
 * at. Descent stops at the first indexed directory on a branch (a project's
 * own sub-dirs aren't separate projects) and is bounded by depth + count so it
 * never turns into a full-tree crawl on a large repo.
 */
export declare function findIndexedSubprojectRoots(root: string, opts?: {
    maxDepth?: number;
    max?: number;
}): string[];
/** Result of {@link resolveServerRoot}. */
export interface ServerRootResolution {
    /** The project root to serve as the default, or null when none resolved. */
    root: string | null;
    /** True when `root` was adopted from the down-scan rather than the up-walk. */
    viaSubScan: boolean;
    /**
     * Indexed sub-projects the down-scan saw when it ran but could NOT adopt
     * (zero or several candidates). Empty when the up-walk resolved or the scan
     * was skipped. Callers surface these so "no default project" errors can say
     * what IS reachable (#1607).
     */
    candidates: string[];
}
/**
 * Resolve the project root an MCP server should serve as its DEFAULT project
 * (#1606). Up-walk first (`findNearestCodeGraphRoot` — the common case, and
 * cheap). When nothing is indexed at or above `searchFrom`, run the bounded
 * sub-project down-scan `planFrontload` already uses, behind the workspace
 * gate above: EXACTLY ONE indexed sub-project is unambiguous and is adopted
 * as the root; zero or several yield no root, with the candidates carried so
 * the caller can name them instead of failing silently (#1607).
 *
 * `opts.subprojectScan: false` skips the down-scan entirely (the per-tool-call
 * retry path throttles it; the up-walk always runs).
 */
export declare function resolveServerRoot(searchFrom: string, opts?: {
    subprojectScan?: boolean;
}): ServerRootResolution;
/**
 * Does `prompt` contain an explicit structural keyword? A keyword is a strong,
 * self-contained signal, so the front-load hook fires on it directly — no graph
 * check needed. (A *code-token* match, by contrast, is only a candidate the
 * hook verifies against the graph first; see {@link extractCodeTokens}.)
 * Coverage is multilingual (#994, #1126): the ~29 languages with the largest
 * developer populations, across Latin, Cyrillic, Greek, CJK, Hangul, Arabic,
 * Hebrew, Thai, and Devanagari scripts. Languages beyond the keyword table
 * still fire through the language-agnostic code-token path.
 */
export declare function hasStructuralKeyword(prompt: string): boolean;
/**
 * Identifier-shaped tokens in `prompt` — camelCase / PascalCase-with-inner-cap,
 * snake_case, a `name(` call, or the two sides of an `a.b` member access. Naming
 * a symbol is a code question whatever the surrounding human language, and these
 * shapes almost never occur in ordinary prose, so they catch the common
 * "<symbol> 的调用链?" / "where is <symbol> 定義" prompts no keyword list would.
 *
 * These are *candidates*, not a verdict: a tech brand like `JavaScript` or
 * `GitHub` is identifier-shaped too, so the front-load hook checks each token
 * against the actual index ({@link getNodesByName}) and only fires when one is a
 * real symbol here — otherwise a brand-name prompt would inject ~16KB of
 * low-relevance context (issue #994 follow-up). A doc/data filename ("README.md")
 * is excluded from the member-access form since it's a file reference, not a symbol.
 */
export declare function extractCodeTokens(prompt: string): string[];
/**
 * Cheap, graph-free candidate gate for the front-load hook: could `prompt` be a
 * structural / flow / impact / "where-how" question worth front-loading context
 * for? True on an explicit keyword in any covered language (#994, #1126) OR an
 * identifier-shaped token. A keyword is sufficient to fire on its own; a
 * token-only match is only a candidate the hook then verifies against the graph
 * (a brand name like `JavaScript` is token-shaped but isn't a symbol). Every
 * non-candidate prompt ("fix this typo", in any language) stays a zero-cost no-op.
 */
export declare function isStructuralPrompt(prompt: string): boolean;
/**
 * Claude Code persists `UserPromptSubmit` hook stdout above this many
 * characters to a file and shows the model a ~2 KB preview instead (#1694).
 * Measured on Claude Code 2.1.261; documented in the hooks reference as a
 * 10,000-character cap on hook output strings.
 */
export declare const CLAUDE_CODE_INLINE_HOOK_OUTPUT_LIMIT = 10000;
/**
 * Max characters of explore text injected by `codegraph prompt-hook` before
 * truncation. Must stay under {@link CLAUDE_CODE_INLINE_HOOK_OUTPUT_LIMIT} so
 * the host delivers the payload inline. 9,000 leaves ~1k for the
 * `<codegraph_context>` wrapper and the `projectPath` nudge lines appended
 * after the cap is applied.
 */
export declare const PROMPT_HOOK_INJECTION_MAX = 9000;
/**
 * Cap explore text for the prompt-hook injection, preserving the existing
 * "call codegraph_explore for the rest" notice when truncated.
 */
export declare function capPromptHookInjection(text: string, max?: number): string;
/**
 * What the front-load hook should do for a prompt issued from a directory.
 */
export interface FrontloadPlan {
    /** Open + explore this project and inject its source as context. `null` when
     *  there's no single project to front-load (none indexed, or several indexed
     *  sub-projects with no clear match — see {@link nudgeProjects}). */
    exploreRoot: string | null;
    /** Indexed sub-projects to surface in a "pass `projectPath`" nudge: the rest
     *  of a monorepo's indexed projects alongside `exploreRoot`, or — when no one
     *  project clearly matches — the full list (with `exploreRoot` null). */
    nudgeProjects: string[];
    /** True when the plan came from scanning DOWN into sub-projects (cwd itself
     *  is not under any index) — the monorepo case, where a follow-up
     *  `codegraph_explore` needs an explicit `projectPath`. */
    viaSubScan: boolean;
}
/**
 * Decide what the front-load hook injects for a `prompt` issued from `cwd`,
 * shaped by where the `.codegraph/` index(es) actually are:
 *   1. **cwd (or an ancestor) is indexed** → front-load that project. The
 *      normal single-project / nested-file case.
 *   2. **cwd isn't indexed but looks like a workspace root** → the indexes live
 *      in sub-projects (the monorepo case behind #964). One indexed
 *      sub-project → front-load it; several → front-load the one the prompt
 *      names (by relative path like `packages/api`, or package directory name)
 *      and nudge about the rest; several with no match → nudge the full list so
 *      the agent passes `projectPath`, rather than guessing wrong.
 *   3. **nothing indexed reachable** → do nothing (the agent's own tools apply).
 */
export declare function planFrontload(cwd: string, prompt: string): FrontloadPlan;
/**
 * Create the .codegraph directory structure
 * Note: Only throws if codegraph.db already exists, not just if .codegraph/ exists.
 */
export declare function createDirectory(projectRoot: string): void;
/**
 * Remove the .codegraph directory
 */
export declare function removeDirectory(projectRoot: string): void;
/**
 * Get all files in the .codegraph directory
 */
export declare function listDirectoryContents(projectRoot: string): string[];
/**
 * Get the total size of the .codegraph directory in bytes
 */
export declare function getDirectorySize(projectRoot: string): number;
/**
 * Ensure a subdirectory exists within .codegraph
 */
export declare function ensureSubdirectory(projectRoot: string, subdirName: string): string;
/**
 * Check if the .codegraph directory has valid structure
 */
export declare function validateDirectory(projectRoot: string): {
    valid: boolean;
    errors: string[];
};
/**
 * Claude Code injects `<task-notification>…</task-notification>` blocks as
 * `user` messages when a background agent finishes, and UserPromptSubmit
 * hooks receive them exactly like typed prompts (#1832). The whole prompt
 * must be that single envelope; a user question that merely mentions the
 * marker is still a prompt.
 */
export declare function isTaskNotification(prompt: string): boolean;
/**
 * Claude Code hands a subagent's report back to the parent session as a
 * `<agent-message from="…">…</agent-message>` prompt, which UserPromptSubmit
 * hooks also receive (#2184). Same rule as {@link isTaskNotification}: only a
 * prompt that is entirely that envelope is skipped.
 */
export declare function isAgentMessage(prompt: string): boolean;
//# sourceMappingURL=directory.d.ts.map