Skip to main content

Module command_root

Module command_root 

Source
Expand description

The project a command-line invocation acts for, and the read boundary a command-line read enforces against it.

The root comes from --root/--project-root, then LEAN_CTX_PROJECT_ROOT (reconciled with the working directory, AP04-G10), then project_root_of the working directory. Shared by the CLI commands, the daemon client and the shell-hook rewriters, so every entry point names the same project; the MCP server derives its startup root with the same project_root_of (#1315).

Functions§

cli_read_is_refused
Whether lean-ctx read <raw> from this process would be refused (#1903). Shell-hook rewriters keep such reads on the native command instead of turning a working cat into an access-denied error.
detect_project_root
The project this process acts for, from args and the working directory.
detect_project_root_in
detect_project_root for an explicit working directory.
jail_cli_read_path
#1903: lean-ctx read enforces the same boundary as MCP ctx_read — the PathJail (project root + allow_paths/extra_roots/read_only_roots + the lean-ctx state dir) and the secret-path policy — with the same error text. A relative path is resolved against the process CWD (a shell user’s intent), never re-anchored at the project root. A broad root (home, /, agent config dir) is refused like lean-ctx call does, unless the jail is disabled (path_jail = false), because jailing to ~ would admit every file the user owns.
project_root_of
#1315: the project path belongs to, for the CLI and the MCP server alike — the nearest git root at or above it, else the outermost directory with a project marker (Cargo.toml, package.json, …; #1437: a monorepo sub-package is not its own project). A broad root (~ as a dotfiles repository, /, an agent directory) never counts, and the walk continues past it. The result is canonical, so every entry point keys the project-scoped stores (local tasks, agent registry) on the same directory. None when no directory above path is a project.
promote_to_git_root
require_project_root
The project a command that writes project-scoped state acts for; Err instead of ~, / or an agent directory (AP04-G10).