Skip to main content

perspt_sdk/search/
context.rs

1//! Search context and the re-homed deterministic repository map
2//! (PSP-10 Compatibility: `ProjectMap` moves here from the removed
3//! `exploration` module as the seed of `SearchContext`; the read-only
4//! explorer capability moves with it).
5
6use serde::{Deserialize, Serialize};
7
8use crate::capability::{ActorId, Capability, EffectKind};
9
10/// A structured map of the repository (PSP-8 System 3; re-homed by PSP-10).
11#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
12pub struct ProjectMap {
13    pub languages: Vec<String>,
14    pub package_roots: Vec<String>,
15    pub build_systems: Vec<String>,
16    pub entry_points: Vec<String>,
17    pub risk_hotspots: Vec<String>,
18}
19
20/// Build a read-only exploration capability for an actor. Exploration SHALL
21/// NOT write files, mutate dependencies, change graph policy, or apply
22/// patches.
23pub fn exploration_capability(actor: ActorId) -> Capability {
24    Capability::new(
25        actor,
26        vec![
27            EffectKind::ReadFile,
28            EffectKind::Search,
29            EffectKind::List,
30            EffectKind::LspQuery,
31            EffectKind::GitRead,
32        ],
33    )
34    .with_paths(vec!["*"])
35}
36
37/// Whether a capability is strictly read-only (the exploration invariant).
38pub fn is_read_only_capability(cap: &Capability) -> bool {
39    cap.effects.iter().all(|e| e.is_read_only())
40}