1use std::io::Write;
2use std::path::PathBuf;
3
4use nils_common::env as shared_env;
5use nils_common::provider_runtime;
6
7use crate::provider_profile::CODEX_PROVIDER_PROFILE;
8
9pub use nils_common::provider_runtime::ExecOptions;
10pub use nils_common::provider_runtime::{
11 CoreError, CoreErrorCategory, ProviderCategoryHint, auth, json, jwt,
12};
13
14pub fn config_snapshot() -> provider_runtime::config::RuntimeConfig {
15 provider_runtime::config::snapshot(&CODEX_PROVIDER_PROFILE)
16}
17
18pub fn resolve_secret_dir() -> Option<PathBuf> {
19 provider_runtime::paths::resolve_secret_dir(&CODEX_PROVIDER_PROFILE)
20}
21
22pub fn resolve_auth_file() -> Option<PathBuf> {
23 provider_runtime::paths::resolve_auth_file(&CODEX_PROVIDER_PROFILE)
24}
25
26pub fn resolve_secret_cache_dir() -> Option<PathBuf> {
27 provider_runtime::paths::resolve_secret_cache_dir(&CODEX_PROVIDER_PROFILE)
28}
29
30pub fn resolve_feature_dir() -> Option<PathBuf> {
31 provider_runtime::paths::resolve_feature_dir(&CODEX_PROVIDER_PROFILE)
32}
33
34pub fn resolve_script_dir() -> Option<PathBuf> {
35 provider_runtime::paths::resolve_script_dir()
36}
37
38pub fn resolve_zdotdir() -> Option<PathBuf> {
39 provider_runtime::paths::resolve_zdotdir()
40}
41
42pub fn require_allow_dangerous(caller: Option<&str>, stderr: &mut impl Write) -> bool {
43 provider_runtime::exec::require_allow_dangerous(&CODEX_PROVIDER_PROFILE, caller, stderr)
44}
45
46pub fn allow_dangerous_status(caller: Option<&str>) -> (bool, Option<String>) {
47 provider_runtime::exec::allow_dangerous_status(&CODEX_PROVIDER_PROFILE, caller)
48}
49
50pub fn check_allow_dangerous(caller: Option<&str>) -> Result<(), CoreError> {
51 provider_runtime::exec::check_allow_dangerous(&CODEX_PROVIDER_PROFILE, caller)
52}
53
54pub fn exec_dangerous(prompt: &str, caller: &str, stderr: &mut impl Write) -> i32 {
55 exec_dangerous_with_options(prompt, caller, stderr, ExecOptions::default())
56}
57
58pub fn exec_dangerous_with_options(
59 prompt: &str,
60 caller: &str,
61 stderr: &mut impl Write,
62 options: ExecOptions,
63) -> i32 {
64 let effective_options = ExecOptions {
65 ephemeral: options.ephemeral || shared_env::env_truthy("CODEX_CLI_EPHEMERAL_ENABLED"),
66 };
67 provider_runtime::exec::exec_dangerous_with_options(
68 &CODEX_PROVIDER_PROFILE,
69 prompt,
70 caller,
71 stderr,
72 effective_options,
73 )
74}