Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
113 lines
4.2 KiB
Rust
113 lines
4.2 KiB
Rust
pub use akode_apply_patch::AKODE_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR;
|
|
use akode_protocol::SessionId;
|
|
use akode_protocol::ThreadId;
|
|
#[cfg(test)]
|
|
use akode_protocol::config_types::EnvironmentVariablePattern;
|
|
use akode_protocol::config_types::ShellEnvironmentPolicy;
|
|
use akode_protocol::models::ActivePermissionProfile;
|
|
use akode_protocol::shell_environment;
|
|
use std::collections::HashMap;
|
|
|
|
pub use akode_protocol::shell_environment::AKODE_SESSION_ID_ENV_VAR;
|
|
pub use akode_protocol::shell_environment::AKODE_THREAD_ID_ENV_VAR;
|
|
pub use akode_protocol::shell_environment::AKODE_TOOL_CALL_ID_ENV_VAR;
|
|
pub(crate) use akode_protocol::shell_environment::set_tool_call_id_env_var;
|
|
|
|
pub(crate) const AKODE_VERSION_ENV_VAR: &str = "AKODE_VERSION";
|
|
|
|
/// Informational name of the active permission profile. Child processes can
|
|
/// overwrite this value, so it must not be treated as proof of enforcement.
|
|
pub const AKODE_PERMISSION_PROFILE_ENV_VAR: &str = "AKODE_PERMISSION_PROFILE";
|
|
|
|
/// Construct an environment map based on the rules in the specified policy. The
|
|
/// resulting map can be passed directly to `Command::envs()` after calling
|
|
/// `env_clear()` to ensure no unintended variables are leaked to the spawned
|
|
/// process.
|
|
///
|
|
/// The derivation follows the algorithm documented in the struct-level comment
|
|
/// for [`ShellEnvironmentPolicy`].
|
|
///
|
|
/// `AKODE_THREAD_ID` is injected when a thread id is provided, even when
|
|
/// `include_only` is set.
|
|
pub fn create_env(
|
|
policy: &ShellEnvironmentPolicy,
|
|
thread_id: Option<ThreadId>,
|
|
) -> HashMap<String, String> {
|
|
let thread_id = thread_id.map(|thread_id| thread_id.to_string());
|
|
shell_environment::create_env(policy, thread_id.as_deref())
|
|
}
|
|
|
|
/// Exposes the shared root-session identity and harness version to shell commands.
|
|
pub(crate) fn inject_session_env(env: &mut HashMap<String, String>, session_id: SessionId) {
|
|
env.insert(AKODE_SESSION_ID_ENV_VAR.to_string(), session_id.to_string());
|
|
if cfg!(windows) {
|
|
env.retain(|key, _| !key.eq_ignore_ascii_case(AKODE_VERSION_ENV_VAR));
|
|
}
|
|
env.insert(
|
|
AKODE_VERSION_ENV_VAR.to_string(),
|
|
env!("CARGO_PKG_VERSION").to_string(),
|
|
);
|
|
}
|
|
|
|
/// Injects the selected named permission profile into a shell tool's environment.
|
|
///
|
|
/// This is applied after the shell environment policy so the runtime-selected
|
|
/// profile wins over inherited or configured values.
|
|
pub(crate) fn inject_permission_profile_env(
|
|
env: &mut HashMap<String, String>,
|
|
active_permission_profile: Option<&ActivePermissionProfile>,
|
|
) {
|
|
if cfg!(windows) {
|
|
env.retain(|key, _| !key.eq_ignore_ascii_case(AKODE_PERMISSION_PROFILE_ENV_VAR));
|
|
} else {
|
|
env.remove(AKODE_PERMISSION_PROFILE_ENV_VAR);
|
|
}
|
|
if let Some(active_permission_profile) = active_permission_profile {
|
|
env.insert(
|
|
AKODE_PERMISSION_PROFILE_ENV_VAR.to_string(),
|
|
active_permission_profile.id.clone(),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Enables line-ending preservation for older standalone patch executables,
|
|
/// including those provided by remote executors. Override inherited values so
|
|
/// they cannot restore the legacy normalization behavior.
|
|
pub fn inject_apply_patch_env(env: &mut HashMap<String, String>) {
|
|
env.retain(|key, _| !key.eq_ignore_ascii_case(AKODE_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR));
|
|
env.insert(
|
|
AKODE_APPLY_PATCH_PRESERVE_LINE_ENDINGS_ENV_VAR.to_string(),
|
|
"1".to_string(),
|
|
);
|
|
}
|
|
|
|
#[cfg(all(test, target_os = "windows"))]
|
|
fn create_env_from_vars<I>(
|
|
vars: I,
|
|
policy: &ShellEnvironmentPolicy,
|
|
thread_id: Option<ThreadId>,
|
|
) -> HashMap<String, String>
|
|
where
|
|
I: IntoIterator<Item = (String, String)>,
|
|
{
|
|
let thread_id = thread_id.map(|thread_id| thread_id.to_string());
|
|
shell_environment::create_env_from_vars(vars, policy, thread_id.as_deref())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
fn populate_env<I>(
|
|
vars: I,
|
|
policy: &ShellEnvironmentPolicy,
|
|
thread_id: Option<ThreadId>,
|
|
) -> HashMap<String, String>
|
|
where
|
|
I: IntoIterator<Item = (String, String)>,
|
|
{
|
|
let thread_id = thread_id.map(|thread_id| thread_id.to_string());
|
|
shell_environment::populate_env(vars, policy, thread_id.as_deref())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "exec_env_tests.rs"]
|
|
mod tests;
|