Skip to main content

rac_engine/
index.rs

1//! Repository index — `decided index` (services/index.py, INDEX-PLAN B1).
2//!
3//! One walk, one parse per file, entries in sorted-path order. Identity-only
4//! JSON contract (id/type/title/path/aliases); the command never consumes or
5//! writes the derived cache (spec/index-contracts.json `index-command`).
6
7use crate::classify::classify;
8use crate::identity::{artifact_identifier, artifact_identifiers};
9use crate::relationships::corpus_items;
10
11/// One row in the repository manifest: structural identity only.
12pub struct IndexEntry {
13    pub id: String,
14    pub artifact_type: String,
15    pub title: Option<String>,
16    pub path: String,
17    pub aliases: Vec<String>,
18}
19
20/// Deterministic inventory of every artifact in a repository.
21pub struct RepositoryIndex {
22    pub directory: String,
23    pub recursive: bool,
24    pub artifacts: Vec<IndexEntry>,
25}
26
27pub fn build_repository_index(directory: &str, recursive: bool) -> RepositoryIndex {
28    let items = corpus_items(directory, recursive);
29    let artifacts = items
30        .iter()
31        .map(|it| IndexEntry {
32            id: artifact_identifier(&it.artifact, it.spec, &it.path),
33            artifact_type: classify(&it.artifact).artifact_type,
34            title: it.artifact.product.title.clone(),
35            path: it.path.clone(),
36            aliases: artifact_identifiers(&it.artifact, it.spec, &it.path),
37        })
38        .collect();
39    RepositoryIndex {
40        directory: directory.to_string(),
41        recursive,
42        artifacts,
43    }
44}