Skip to repository content110 lines · 4.1 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T03:30:37.411Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
worktree_settings.rs
1use std::path::Path;
2
3use anyhow::Context as _;
4use settings::{RegisterSetting, ScanSymlinksSetting, Settings};
5use util::{
6 ResultExt,
7 paths::{PathMatcher, PathStyle},
8 rel_path::RelPath,
9};
10
11#[derive(Clone, PartialEq, Eq, RegisterSetting)]
12pub struct WorktreeSettings {
13 /// Whether to prevent this project from being shared in public channels.
14 pub prevent_sharing_in_public_channels: bool,
15 pub file_scan_exclusions: PathMatcher,
16 pub file_scan_inclusions: PathMatcher,
17 /// This field contains all ancestors of the `file_scan_inclusions`. It's used to
18 /// determine whether to terminate worktree scanning for a given dir.
19 pub parent_dir_scan_inclusions: PathMatcher,
20 pub scan_symlinks: ScanSymlinksSetting,
21 pub private_files: PathMatcher,
22 pub hidden_files: PathMatcher,
23 pub read_only_files: PathMatcher,
24}
25
26impl WorktreeSettings {
27 pub fn is_path_private(&self, path: &RelPath) -> bool {
28 path.ancestors()
29 .any(|ancestor| self.private_files.is_match(ancestor))
30 }
31
32 pub fn is_path_excluded(&self, path: &RelPath) -> bool {
33 path.ancestors()
34 .any(|ancestor| self.file_scan_exclusions.is_match(ancestor))
35 }
36
37 pub fn is_path_always_included(&self, path: &RelPath, is_dir: bool) -> bool {
38 if is_dir {
39 self.parent_dir_scan_inclusions.is_match(path)
40 } else {
41 self.file_scan_inclusions.is_match(path)
42 }
43 }
44
45 pub fn is_path_hidden(&self, path: &RelPath) -> bool {
46 path.ancestors()
47 .any(|ancestor| self.hidden_files.is_match(ancestor))
48 }
49
50 pub fn is_path_read_only(&self, path: &RelPath) -> bool {
51 self.read_only_files.is_match(path)
52 }
53
54 pub fn is_std_path_read_only(&self, path: &Path) -> bool {
55 self.read_only_files.is_match_std_path(path)
56 }
57}
58
59impl Settings for WorktreeSettings {
60 fn from_settings(content: &settings::SettingsContent) -> Self {
61 let worktree = content.project.worktree.clone();
62 let file_scan_exclusions = worktree.file_scan_exclusions.unwrap();
63 let file_scan_inclusions = worktree.file_scan_inclusions.unwrap();
64 let private_files = worktree.private_files.unwrap().0;
65 let hidden_files = worktree.hidden_files.unwrap();
66 let read_only_files = worktree.read_only_files.unwrap_or_default();
67 let scan_symlinks = worktree.scan_symlinks.unwrap();
68 let parsed_file_scan_inclusions: Vec<String> = file_scan_inclusions
69 .iter()
70 .flat_map(|glob| {
71 Path::new(glob)
72 .ancestors()
73 .skip(1)
74 .map(|a| a.to_string_lossy().into())
75 })
76 .filter(|p: &String| !p.is_empty())
77 .collect();
78
79 Self {
80 prevent_sharing_in_public_channels: worktree.prevent_sharing_in_public_channels,
81 file_scan_exclusions: path_matchers(file_scan_exclusions, "file_scan_exclusions")
82 .log_err()
83 .unwrap_or_default(),
84 parent_dir_scan_inclusions: path_matchers(
85 parsed_file_scan_inclusions,
86 "file_scan_inclusions",
87 )
88 .unwrap(),
89 file_scan_inclusions: path_matchers(file_scan_inclusions, "file_scan_inclusions")
90 .unwrap(),
91 private_files: path_matchers(private_files, "private_files")
92 .log_err()
93 .unwrap_or_default(),
94 hidden_files: path_matchers(hidden_files, "hidden_files")
95 .log_err()
96 .unwrap_or_default(),
97 read_only_files: path_matchers(read_only_files, "read_only_files")
98 .log_err()
99 .unwrap_or_default(),
100 scan_symlinks,
101 }
102 }
103}
104
105fn path_matchers(mut values: Vec<String>, context: &'static str) -> anyhow::Result<PathMatcher> {
106 values.sort();
107 PathMatcher::new(values, PathStyle::local())
108 .with_context(|| format!("Failed to parse globs from {}", context))
109}
110