fs-inspect is a high-integrity, agent-facing CLI tool designed for filesystem exploration and inspection. It is built following the CLI Doctrine (see SKILL.md), which mandates a contract-first approach, strict separation between domain core and adapters, and machine-safe output standards.
- Core Purpose: Provide a reliable, machine-readable interface for agents to perform filesystem operations like
statandfind. - Architecture:
- Contract (
src/contract/): Defines the JSON schema for requests and responses. All input/output is governed by versioned schemas (e.g.,fscli.v1). - Core (
src/core/): Contains the domain logic and command definitions, independent of the filesystem backend or serialization. - Adapters (
src/fs/): Concrete implementations for filesystem access, including security policies (e.g.,RootPolicy). - CLI (
src/main.rs): A thin wrapper usingclapto route requests to the core and format results as JSON envelopes.
- Contract (
The project is written in Rust (Edition 2024).
- Build:
cargo build - Test:
cargo test(includes unit tests and integration tests intests/) - Run (Stat):
cargo run -- stat --request '{"root": "/abs/path", "path": "relative/path"}' - Run (Find):
cargo run -- find --request '{"root": "/abs/path", "include": ["*.rs"]}' - Read from Stdin: Use
--request @-to pipe JSON into the command.
schema: (Optional) Enables JSON schema generation usingschemars.
- Contract-First: Never modify the implementation before updating the contract in
src/contract/. - Machine-Safe Output:
stdoutis reserved for valid JSON envelopes. All logs, warnings (unless part of the contract), and diagnostic info must go tostderr. - Error Modeling: Errors are categorized by
ErrorCodeand mapped to specific exit codes (e.g.,InvalidRequest= 2,RootNotFound= 3). - Root Policy: All filesystem operations must be bounded by a "Root" path. Path traversal (
..) is strictly prohibited. - No Dependencies in Core: Keep the
coremodule free of IO and external crates where possible.
SKILL.md: The "CLI Doctrine" - the foundational rules for the project.src/contract/schema.rs: The source of truth for the JSON API.src/fs/root_policy.rs: Logic for enforcing security boundaries.references/: Detailed documentation for specific modules and implementation lessons.assets/templates/: Blueprints for expanding the tool with new capabilities.
When interacting with this tool, always:
- Expect a JSON object with a
statusfield (complete,partial_failure,truncated, orerror). - Use the
--request @-pattern for complex queries. - Check the
exit codeto differentiate between system failures and contract-level errors.