surjection_core/adapters/
omp.rs1use crate::adapters::caps::{
15 Caps, CommandRef, CompatSource, DisableMech, EnvRefSyntax, FieldSet, ProjectDisable,
16 ProjectSemantics, Source, TimeUnit, TimeoutField, TransportSet,
17};
18use crate::adapters::detect::Probe;
19use crate::adapters::location::Location;
20use crate::adapters::mapper::McpServersJson;
21use crate::adapters::spec::{AdapterSpec, ContainerPath, McpSpec, Profiles, Tier, exact_names};
22use crate::env::Os;
23use crate::formats::Format;
24use crate::model::clients::passthrough_of;
25
26pub const ID: &str = "omp";
27
28pub const DEFAULT_PROFILE: &str = "default";
30
31const ROOT: Location = Location::HomeNamedDir {
33 var: "PI_CONFIG_DIR",
34 default: ".omp",
35 rel: "",
36};
37
38const USER_FILE: Location = Location::EnvDir {
43 var: "PI_CODING_AGENT_DIR",
44 fallback: &Location::HomeNamedDir {
45 var: "PI_CONFIG_DIR",
46 default: ".omp",
47 rel: "agent",
48 },
49 rel: "mcp.json",
50 tilde: false,
51};
52
53const SKELETON: &str = "{\n \"$schema\": \"https://raw.githubusercontent.com/can1357/oh-my-pi/main/packages/coding-agent/src/config/mcp-schema.json\"\n}\n";
55
56const CAPS: Caps = Caps {
57 transports: TransportSet::ALL,
58 env_ref: Some(EnvRefSyntax::DollarBrace {
59 default: true,
60 bare: false,
61 }),
62 env_ref_fields: FieldSet::COMMAND
63 .union(FieldSet::ARGS)
64 .union(FieldSet::ENV)
65 .union(FieldSet::CWD)
66 .union(FieldSet::URL)
67 .union(FieldSet::HEADERS),
68 command_ref: Some(CommandRef::Bang),
69 native_disable: Some(DisableMech::EnabledFalse),
70 project_disable: Some(ProjectDisable::EnabledFalse { partial: false }),
74 project_semantics: ProjectSemantics::Replace,
75 precedence: &[Source::Project, Source::User],
76 compat_reads: &[
77 CompatSource::below("claude-code", Source::User),
78 CompatSource::below("claude-code", Source::Project),
79 CompatSource::below("codex", Source::User),
80 CompatSource::below("codex", Source::Project),
81 CompatSource::below("gemini", Source::User),
82 CompatSource::below("gemini", Source::Project),
83 CompatSource::below("opencode", Source::User),
84 CompatSource::below("opencode", Source::Project),
85 CompatSource::below("cursor", Source::User),
86 CompatSource::below("cursor", Source::Project),
87 CompatSource::below("windsurf", Source::User),
88 CompatSource::below("windsurf", Source::Project),
89 CompatSource::below("vscode-legacy", Source::Project),
90 ],
91 trust_gate: None,
92 rewrites_file_at_runtime: false,
93 restart_required: false,
94 tool_filter: None,
95 windows_shell_shim: false,
97 timeouts: &[TimeoutField {
98 key: "timeout",
99 unit: TimeUnit::Milliseconds,
100 }],
101 passthrough_allowlist: passthrough_of(ID),
102};
103
104static MAPPER: McpServersJson = McpServersJson {
105 caps: &CAPS,
106 type_field: true,
107 remote_type: true,
108 cwd: true,
109 http_aliases: &[],
110 url_implies_http: true,
111 valid_name,
112};
113
114pub static SPEC: AdapterSpec = AdapterSpec {
115 id: ID,
116 display_name: "oh-my-pi",
117 tier: Tier::A,
118 detect: &[Probe::Path(ROOT), Probe::Executable("omp")],
119 mcp: Some(McpSpec {
120 oses: &[Os::Windows, Os::Linux, Os::MacOs],
121 read_only: false,
122 user: &[USER_FILE],
123 user_files: None,
124 user_mirrors: &[],
125 profiles: Some(Profiles {
126 default: DEFAULT_PROFILE,
127 dir: Location::HomeNamedDir {
128 var: "PI_CONFIG_DIR",
129 default: ".omp",
130 rel: "profiles",
131 },
132 rel: "agent/mcp.json",
133 valid_name: valid_profile,
134 }),
135 project: &[Location::Project(".omp/mcp.json")],
136 project_local: &[],
137 format: Format::Json,
138 skeleton: SKELETON,
139 container: ContainerPath(&["mcpServers"]),
140 project_local_container: ContainerPath(&["mcpServers"]),
141 legacy_containers: &[],
142 same_name: exact_names,
143 replaced_by: &[],
144 mapper: &MAPPER,
145 caps: CAPS,
146 sign_in: crate::adapters::sign_in::SignIn::UNKNOWN,
147 }),
148};
149
150fn valid_name(name: &str) -> bool {
153 name.chars().count() <= 100
154 && !name.is_empty()
155 && name.split(' ').all(|segment| {
156 !segment.is_empty()
157 && segment
158 .chars()
159 .all(|c| c.is_alphanumeric() || matches!(c, '_' | '-' | '.' | ':'))
160 })
161}
162
163fn valid_profile(name: &str) -> bool {
166 let bytes = name.as_bytes();
167 let pattern = matches!(bytes.first(), Some(b'a'..=b'z' | b'0'..=b'9'))
168 && bytes.len() <= 64
169 && bytes
170 .iter()
171 .all(|b| matches!(b, b'a'..=b'z' | b'0'..=b'9' | b'.' | b'_' | b'-'));
172 let base = name.split('.').next().unwrap_or(name).to_ascii_uppercase();
173 let reserved = matches!(base.as_str(), "CON" | "PRN" | "AUX" | "NUL")
174 || (base.len() == 4
175 && (base.starts_with("COM") || base.starts_with("LPT"))
176 && base.as_bytes()[3].is_ascii_digit());
177 pattern && !name.ends_with('.') && !reserved
178}