Skip to main content

agentshield/analysis/composite_flow/
types.rs

1use std::path::{Path, PathBuf};
2
3use crate::ir::SourceLocation;
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub struct ScopeId {
7    pub relative_file: PathBuf,
8    pub lexical_owner: String,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub struct ByteSpan {
13    pub start: usize,
14    pub end: usize,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
18pub struct DefinitionId {
19    pub scope: ScopeId,
20    pub definition_span: ByteSpan,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
24pub struct ValueId {
25    pub definition: DefinitionId,
26    pub version: u32,
27}
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
30pub enum FlowEdgeKind {
31    ControlsFilePath,
32    ProducesFileContent,
33    Propagates,
34    EntersNetworkPayload,
35}
36
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct FlowEdge {
39    pub kind: FlowEdgeKind,
40    pub input: ValueId,
41    pub output: ValueId,
42    pub location: SourceLocation,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub struct SemanticAnchor {
47    pub relative_file: PathBuf,
48    pub lexical_owner: String,
49    pub operation_kind: &'static str,
50    pub resolved_api: &'static str,
51    pub normalized_subtree_hash: String,
52    pub identical_ordinal: usize,
53}
54
55#[derive(Debug, Clone, PartialEq, Eq)]
56pub struct CompositeFlowCandidate {
57    pub tool_name: String,
58    pub source_location: SourceLocation,
59    pub sink_location: SourceLocation,
60    pub source_anchor: SemanticAnchor,
61    pub sink_anchor: SemanticAnchor,
62    pub edges: Vec<FlowEdge>,
63    pub observation_complete: bool,
64}
65
66#[derive(Debug, Clone, Copy)]
67pub struct SourceUnit<'a> {
68    pub path: &'a Path,
69    pub content: &'a str,
70}
71
72#[derive(Debug, Clone)]
73pub struct ToolFlowInput {
74    pub tool_name: String,
75    pub handler: SourceLocation,
76}