forge-codebase
Codebase intelligence primitives for the Forge SDK — repo understanding, dependency graphs, file relevance, and change impact analysis
Codebase intelligence primitives for the Forge SDK — repo understanding, dependency graphs, file relevance, and change impact analysis
Package contract
| Field | Value |
|---|---|
| Language | rust |
| Source version | 0.2.0 |
| Manifest | forge-rs/crates/forge-codebase/Cargo.toml |
| Source files | 5 |
| Evidence | Source reference; registry publication and runtime conformance are separate checks |
Import boundary
use forge_codebase;Use a source checkout or your verified private registry. Manifest coordinates identify the package; they do not establish that a public registry release exists.
Crate boundary
The following entries are taken from src/lib.rs. Feature conditions in the exact source still apply.
pub mod error;
pub mod structure;
pub mod tools;
pub mod types;
pub mod prelude;
pub use crate::error::{CodebaseError, CodebaseResult};
pub use crate::structure::{classify_file, detect_language, FileClassification, Language};
pub use crate::tools::{register_codebase_tools, CODEBASE_TOOL_NAMES};
pub use crate::types::{
CrateContext, DependencyEntry, DependencyGraph, FileEntry, ImpactReport, RankedFile,
RepoStructure,
};Source reference
Download package reference JSON. Each original source file and generated declaration artifact has its own SHA-256 digest. Function bodies and constant values are omitted from downloads. These are source declaration inventories, not compiler-resolved rustdoc, TypeDoc, DocC, or Dokka output. Private modules can contain public declarations that are not reachable through the package boundary; consult the entry point before importing.
error.rs
Read declaration text · 2 declaration entries
#[derive(Debug, Error)]
pub enum CodebaseError {
/// The repository path does not exist or is not a directory.
#[error(
"repository path '{path}' does not exist or is not a directory; \
provide an absolute path to a valid repository root"
)]
InvalidRepoPath {
/// The path that was provided.
path: String,
},
/// A file could not be read.
#[error("failed to read file '{path}': {reason}")]
FileReadFailed {
/// The file path.
path: String,
/// Why the read failed.
reason: String,
},
/// Dependency manifest parsing failed.
#[error("failed to parse dependency manifest '{path}': {reason}")]
ManifestParseFailed {
/// The manifest file path.
path: String,
/// The parse error.
reason: String,
},
/// The task description for file ranking was empty.
#[error("task description must not be empty for file relevance ranking")]
EmptyTaskDescription,
/// The file path for impact prediction was empty or invalid.
#[error("changed file path must not be empty for impact prediction")]
EmptyChangedFile,
/// The crate/package name for context assembly was not found.
#[error(
"crate or package '{name}' not found in repository at '{repo_path}'; \
verify the name matches a Cargo.toml [package] name or package.json name"
)]
CrateNotFound {
/// The crate/package name.
name: String,
/// The repository path.
repo_path: String,
},
/// An I/O error occurred.
#[error("I/O error during codebase analysis: {reason}")]
IoError {
/// What went wrong.
reason: String,
},
}
pub type CodebaseResult<T> = Result<T, CodebaseError>;lib.rs
Read declaration text · 9 declaration entries
pub mod error;
pub mod structure;
pub mod tools;
pub mod types;
pub mod prelude;
pub use crate::error::{CodebaseError, CodebaseResult};
pub use crate::structure::{classify_file, detect_language, FileClassification, Language};
pub use crate::tools::{register_codebase_tools, CODEBASE_TOOL_NAMES};
pub use crate::types::{
CrateContext, DependencyEntry, DependencyGraph, FileEntry, ImpactReport, RankedFile,
RepoStructure,
};structure.rs
Read declaration text · 6 declaration entries
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FileClassification {
/// Source code files (.rs, .ts, .go, .py, etc.)
Source,
/// Test files (files in test directories or with test suffixes)
Test,
/// Configuration files (Cargo.toml, package.json, .env, etc.)
Config,
/// Documentation files (.md, .txt, .rst, etc.)
Documentation,
/// Build artifacts and generated files
Generated,
/// CI/CD configuration (.github/workflows, .gitlab-ci.yml, etc.)
Ci,
/// Data files (.json, .yaml, .csv, .sql, etc.)
Data,
/// Media files (images, fonts, etc.)
Media,
/// Lock files (Cargo.lock, package-lock.json, etc.)
Lock,
/// Schema files (.json schema, .proto, .graphql, etc.)
Schema,
/// Unknown file type
Unknown,
}
pub fn as_str(&self) -> &'static str;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Language {
/// Rust (.rs)
Rust,
/// TypeScript (.ts, .tsx)
TypeScript,
/// JavaScript (.js, .jsx, .mjs, .cjs)
JavaScript,
/// Go (.go)
Go,
/// Python (.py)
Python,
/// Swift (.swift)
Swift,
/// Kotlin (.kt, .kts)
Kotlin,
/// Java (.java)
Java,
/// C (.c, .h)
C,
/// C++ (.cpp, .cc, .cxx, .hpp, .hh)
Cpp,
/// Shell (.sh, .bash, .zsh)
Shell,
/// SQL (.sql)
Sql,
/// HTML (.html, .htm)
Html,
/// CSS (.css, .scss, .sass, .less)
Css,
/// TOML (.toml)
Toml,
/// YAML (.yaml, .yml)
Yaml,
/// JSON (.json)
Json,
/// Markdown (.md)
Markdown,
/// Protocol Buffers (.proto)
Protobuf,
/// GraphQL (.graphql, .gql)
GraphQL,
/// Zig (.zig)
Zig,
}
pub fn as_str(&self) -> &'static str;
pub fn classify_file(path: &str) -> FileClassification;
pub fn detect_language(path: &str) -> Option<Language>;tools.rs
Read declaration text · 3 declaration entries
pub const CODEBASE_TOOL_NAMES: &[&str];
pub fn codebase_tool_definitions() -> Vec<ToolDefinition>;
pub fn register_codebase_tools(registry: &mut ToolRegistry) -> Result<(), ForgeToolError>;types.rs
Read declaration text · 7 declaration entries
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileEntry {
/// Relative path from the repository root.
pub path: String,
/// Classification of the file's role.
pub classification: FileClassification,
/// Programming language, if detected.
pub language: Option<Language>,
/// File size in bytes.
pub size_bytes: u64
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RepoStructure {
/// Absolute path to the repository root.
pub root_path: String,
/// All files in the repository.
pub files: Vec<FileEntry>,
/// Total number of files.
pub total_files: usize,
/// Total size of all files in bytes.
pub total_size_bytes: u64,
/// Count of files per detected language.
pub language_counts: std::collections::BTreeMap<String, usize>,
/// Count of files per classification.
pub classification_counts: std::collections::BTreeMap<String, usize>,
/// Top-level directories.
pub directories: Vec<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DependencyEntry {
/// The dependency name.
pub name: String,
/// The version requirement or resolved version.
pub version: Option<String>,
/// The source (e.g., "crates.io", "npm", "path", "git").
pub source: String,
/// Whether this is a dev-only dependency.
pub is_dev: bool,
/// Whether this comes from a workspace declaration.
pub is_workspace: bool,
/// Path dependency location, if applicable.
pub path: Option<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DependencyGraph {
/// Path to the manifest file.
pub manifest_path: String,
/// Type of manifest ("cargo", "npm", "go", "python").
pub manifest_type: String,
/// The package/crate name from the manifest.
pub package_name: Option<String>,
/// All declared dependencies.
pub dependencies: Vec<DependencyEntry>,
/// Workspace members (for Cargo workspaces or npm workspaces).
pub workspace_members: Vec<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RankedFile {
/// The file path relative to the repository root.
pub path: String,
/// Relevance score (0.0 to 1.0, higher = more relevant).
pub relevance_score: f64,
/// Human-readable reasons for the ranking.
pub reasons: Vec<String>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImpactReport {
/// The file that was changed.
pub changed_file: String,
/// Files that directly import/use the changed file.
pub directly_affected: Vec<String>,
/// Files that are transitively affected.
pub transitively_affected: Vec<String>,
/// Test files that should be re-run.
pub affected_tests: Vec<String>,
/// Risk level: "low", "medium", "high", "critical".
pub risk_level: String,
/// Human-readable summary of the impact.
pub summary: String
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CrateContext {
/// The crate/package name.
pub name: String,
/// Path to the crate root directory.
pub root_path: String,
/// Path to the manifest file (Cargo.toml, package.json, etc.).
pub manifest_path: String,
/// Source code files in this crate.
pub source_files: Vec<String>,
/// Test files for this crate.
pub test_files: Vec<String>,
/// Documentation files for this crate.
pub doc_files: Vec<String>,
/// Dependencies of this crate.
pub dependencies: Vec<DependencyEntry>,
/// Other crates/packages that depend on this one.
pub dependents: Vec<String>,
/// Approximate total lines of source code.
pub total_lines: u64
}Continue
forge-code-safety
Runtime safety primitives for coding agents — worktree isolation, write scoping, delete prevention, approval gates, and audit logging
forge-coder
Production-grade coding agent runtime — repo understanding, code search, dependency awareness, plan/implement/review cycles, and test verification loops