Skip to main content

harn_parser/
harness_methods.rs

1//! Canonical mappings between typed `harness.<sub>.*` methods and the
2//! ambient builtin names that still back capability classification,
3//! lint migrations, and runtime dispatch.
4
5pub fn harness_stdio_ambient(method: &str) -> Option<&'static str> {
6    match method {
7        "print" => Some("print"),
8        "println" => Some("println"),
9        "eprint" => Some("eprint"),
10        "eprintln" => Some("eprintln"),
11        "read_line" => Some("read_line"),
12        "prompt" => Some("prompt_user"),
13        _ => None,
14    }
15}
16
17pub fn harness_term_ambient(method: &str) -> Option<&'static str> {
18    match method {
19        "width" => Some("term_width"),
20        "height" => Some("term_height"),
21        "read_password" => Some("read_password"),
22        _ => None,
23    }
24}
25
26pub fn harness_clock_ambient(method: &str) -> Option<&'static str> {
27    match method {
28        "now_ms" => Some("now_ms"),
29        "monotonic_ms" | "elapsed" => Some("monotonic_ms"),
30        "sleep_ms" => Some("sleep_ms"),
31        "timestamp" => Some("timestamp"),
32        _ => None,
33    }
34}
35
36pub fn harness_fs_ambient(method: &str) -> Option<&'static str> {
37    match method {
38        "read_text" | "read" | "read_file" => Some("read_file"),
39        "read_text_result" | "read_result" => Some("read_file_result"),
40        "read_bytes" | "read_file_bytes" => Some("read_file_bytes"),
41        "write_text" | "write" | "write_file" => Some("write_file"),
42        "write_bytes" | "write_file_bytes" => Some("write_file_bytes"),
43        "exists" | "file_exists" => Some("file_exists"),
44        "delete" | "delete_file" | "remove" => Some("delete_file"),
45        "append" | "append_file" => Some("append_file"),
46        "list_dir" | "list" => Some("list_dir"),
47        "mkdir" | "create_dir" => Some("mkdir"),
48        "path_join" => Some("path_join"),
49        "copy" | "copy_file" => Some("copy_file"),
50        "temp_dir" => Some("temp_dir"),
51        "workspace_temp_dir" => Some("workspace_temp_dir"),
52        "mkdtemp" => Some("mkdtemp"),
53        "mkdtemp_in_workspace" => Some("mkdtemp_in_workspace"),
54        "stat" => Some("stat"),
55        "rename" | "move" | "move_file" => Some("move_file"),
56        "read_lines" => Some("read_lines"),
57        "walk" | "walk_dir" => Some("walk_dir"),
58        "glob" => Some("glob"),
59        "find_text" => Some("find_text"),
60        _ => None,
61    }
62}
63
64pub fn harness_env_ambient(method: &str) -> Option<&'static str> {
65    match method {
66        "get" => Some("env"),
67        "get_or" => Some("env_or"),
68        _ => None,
69    }
70}
71
72pub fn harness_random_ambient(method: &str) -> Option<&'static str> {
73    match method {
74        "gen_f64" | "f64" | "random" => Some("random"),
75        "gen_u64" | "u64" => Some("random_int"),
76        "gen_range" | "range" | "random_int" | "int" => Some("random_int"),
77        "choice" | "random_choice" => Some("random_choice"),
78        "shuffle" | "random_shuffle" => Some("random_shuffle"),
79        _ => None,
80    }
81}
82
83pub fn harness_net_ambient(method: &str) -> Option<&'static str> {
84    match method {
85        "get" | "http_get" => Some("http_get"),
86        "post" | "http_post" => Some("http_post"),
87        "put" | "http_put" => Some("http_put"),
88        "patch" | "http_patch" => Some("http_patch"),
89        "delete" | "http_delete" => Some("http_delete"),
90        "request" | "http_request" => Some("http_request"),
91        "download" | "http_download" => Some("http_download"),
92        _ => None,
93    }
94}
95
96pub fn harness_process_ambient(method: &str) -> Option<&'static str> {
97    match method {
98        "spawn_captured" => Some("spawn_captured"),
99        _ => None,
100    }
101}
102
103pub fn harness_crypto_ambient(method: &str) -> Option<&'static str> {
104    match method {
105        "sha256" => Some("sha256_hex"),
106        _ => None,
107    }
108}
109
110pub fn harness_system_ambient(method: &str) -> Option<&'static str> {
111    match method {
112        "platform" => Some("system_platform"),
113        "cpu" => Some("system_cpu"),
114        "memory" => Some("system_memory"),
115        "gpus" => Some("system_gpus"),
116        "temperature" => Some("system_temperature"),
117        "processes" => Some("system_processes"),
118        _ => None,
119    }
120}
121
122pub fn harness_llm_ambient(method: &str) -> Option<&'static str> {
123    match method {
124        "catalog" => Some("llm_catalog"),
125        "catalog_refresh" => Some("llm_catalog_refresh"),
126        "providers" => Some("llm_provider_status"),
127        _ => None,
128    }
129}
130
131pub fn harness_secrets_ambient(method: &str) -> Option<&'static str> {
132    match method {
133        "read" | "read_bytes" | "write" | "rotate" | "lease" | "lease_bytes" => None,
134        _ => None,
135    }
136}
137
138pub fn harness_tenant_ambient(method: &str) -> Option<&'static str> {
139    match method {
140        "id" => Some("harness_tenant_id"),
141        "try_id" => Some("harness_tenant_try_id"),
142        _ => None,
143    }
144}
145
146pub fn harness_auth_ambient(method: &str) -> Option<&'static str> {
147    match method {
148        "is_authenticated" => Some("harness_auth_is_authenticated"),
149        "subject" => Some("harness_auth_subject"),
150        "try_subject" => Some("harness_auth_try_subject"),
151        "scheme" => Some("harness_auth_scheme"),
152        "try_scheme" => Some("harness_auth_try_scheme"),
153        "kind" => Some("harness_auth_kind"),
154        "scopes" => Some("harness_auth_scopes"),
155        "has_scope" => Some("harness_auth_has_scope"),
156        _ => None,
157    }
158}
159
160pub fn harness_obs_ambient(method: &str) -> Option<&'static str> {
161    match method {
162        "span" | "start_span" => Some("__obs_start_span"),
163        "end_span" => Some("__obs_end_span"),
164        "log" => Some("__obs_emit"),
165        "counter" => Some("__obs_counter"),
166        "histogram" => Some("__obs_histogram"),
167        "gauge" => Some("__obs_gauge"),
168        "request_id" => Some("__obs_request_id"),
169        _ => None,
170    }
171}
172
173pub fn harness_sub_handle_ambient(sub_handle: &str, method: &str) -> Option<&'static str> {
174    match sub_handle {
175        "stdio" => harness_stdio_ambient(method),
176        "term" => harness_term_ambient(method),
177        "clock" => harness_clock_ambient(method),
178        "fs" => harness_fs_ambient(method),
179        "env" => harness_env_ambient(method),
180        "random" => harness_random_ambient(method),
181        "net" => harness_net_ambient(method),
182        "process" => harness_process_ambient(method),
183        "crypto" => harness_crypto_ambient(method),
184        "system" => harness_system_ambient(method),
185        "secrets" => harness_secrets_ambient(method),
186        "llm" => harness_llm_ambient(method),
187        "tenant" => harness_tenant_ambient(method),
188        "auth" => harness_auth_ambient(method),
189        "obs" => harness_obs_ambient(method),
190        _ => None,
191    }
192}
193
194pub fn harness_type_sub_handle(type_name: &str) -> Option<&'static str> {
195    match type_name {
196        "HarnessStdio" => Some("stdio"),
197        "HarnessTerm" => Some("term"),
198        "HarnessClock" => Some("clock"),
199        "HarnessFs" => Some("fs"),
200        "HarnessEnv" => Some("env"),
201        "HarnessRandom" => Some("random"),
202        "HarnessNet" => Some("net"),
203        "HarnessProcess" => Some("process"),
204        "HarnessCrypto" => Some("crypto"),
205        "HarnessSystem" => Some("system"),
206        "HarnessSecrets" => Some("secrets"),
207        "HarnessLlm" => Some("llm"),
208        "HarnessTenant" => Some("tenant"),
209        "HarnessAuth" => Some("auth"),
210        "HarnessObs" => Some("obs"),
211        _ => None,
212    }
213}
214
215pub fn harness_fs_replacement(name: &str) -> Option<&'static str> {
216    match name {
217        "read_file" => Some("harness.fs.read_text"),
218        "read_file_result" => Some("harness.fs.read_text_result"),
219        "read_file_bytes" => Some("harness.fs.read_bytes"),
220        "write_file" => Some("harness.fs.write_text"),
221        "write_file_bytes" => Some("harness.fs.write_bytes"),
222        "file_exists" => Some("harness.fs.exists"),
223        "delete_file" => Some("harness.fs.delete"),
224        "append_file" => Some("harness.fs.append"),
225        "list_dir" => Some("harness.fs.list_dir"),
226        "mkdir" => Some("harness.fs.mkdir"),
227        "copy_file" => Some("harness.fs.copy"),
228        "temp_dir" => Some("harness.fs.temp_dir"),
229        "workspace_temp_dir" => Some("harness.fs.workspace_temp_dir"),
230        "mkdtemp" => Some("harness.fs.mkdtemp"),
231        "mkdtemp_in_workspace" => Some("harness.fs.mkdtemp_in_workspace"),
232        "stat" => Some("harness.fs.stat"),
233        "move_file" => Some("harness.fs.rename"),
234        "read_lines" => Some("harness.fs.read_lines"),
235        "walk_dir" => Some("harness.fs.walk"),
236        "glob" => Some("harness.fs.glob"),
237        "find_text" => Some("harness.fs.find_text"),
238        _ => None,
239    }
240}