Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
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>
This commit is contained in:
218
akode-rs/ext/guardian-reviewer/src/review_result.rs
Normal file
218
akode-rs/ext/guardian-reviewer/src/review_result.rs
Normal file
@@ -0,0 +1,218 @@
|
||||
//! Review result details used for local decisions and local-only metrics.
|
||||
//! Nothing here is sent anywhere: aKode has no usage-data reporting.
|
||||
|
||||
use akode_protocol::approvals::NetworkApprovalProtocol;
|
||||
use akode_protocol::models::AdditionalPermissionProfile;
|
||||
use akode_protocol::models::SandboxPermissions;
|
||||
use akode_protocol::protocol::GuardianAssessmentOutcome;
|
||||
use akode_protocol::protocol::GuardianCommandSource;
|
||||
use akode_protocol::protocol::GuardianRiskLevel;
|
||||
use akode_protocol::protocol::GuardianUserAuthorization;
|
||||
use akode_protocol::protocol::TokenUsage;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianReviewDecision {
|
||||
Approved,
|
||||
Denied,
|
||||
Aborted,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianReviewTerminalStatus {
|
||||
Approved,
|
||||
Denied,
|
||||
Aborted,
|
||||
TimedOut,
|
||||
FailedClosed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianReviewFailureReason {
|
||||
StaleAuthorization,
|
||||
Timeout,
|
||||
Cancelled,
|
||||
PromptBuildError,
|
||||
SessionError,
|
||||
ParseError,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianReviewSessionKind {
|
||||
TrunkNew,
|
||||
TrunkReused,
|
||||
EphemeralForked,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianApprovalRequestSource {
|
||||
/// Approval requested directly by the main Codex turn.
|
||||
MainTurn,
|
||||
/// Approval requested by a delegated subagent and routed through the parent
|
||||
/// session for guardian review.
|
||||
DelegatedSubagent,
|
||||
}
|
||||
|
||||
/// Path-free permission metadata for a Guardian reviewed action.
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct GuardianAdditionalPermissions {
|
||||
network: Option<GuardianNetworkPermissions>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
struct GuardianNetworkPermissions {
|
||||
enabled: Option<bool>,
|
||||
}
|
||||
|
||||
impl From<&AdditionalPermissionProfile> for GuardianAdditionalPermissions {
|
||||
fn from(permissions: &AdditionalPermissionProfile) -> Self {
|
||||
Self {
|
||||
network: permissions
|
||||
.network
|
||||
.as_ref()
|
||||
.map(|network| GuardianNetworkPermissions {
|
||||
enabled: network.enabled,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum GuardianReviewedAction {
|
||||
NativeToolCall {},
|
||||
Shell {
|
||||
sandbox_permissions: SandboxPermissions,
|
||||
additional_permissions: Option<GuardianAdditionalPermissions>,
|
||||
},
|
||||
UnifiedExec {
|
||||
sandbox_permissions: SandboxPermissions,
|
||||
additional_permissions: Option<GuardianAdditionalPermissions>,
|
||||
tty: bool,
|
||||
},
|
||||
WriteStdin {
|
||||
tty: bool,
|
||||
},
|
||||
Execve {
|
||||
source: GuardianCommandSource,
|
||||
additional_permissions: Option<GuardianAdditionalPermissions>,
|
||||
},
|
||||
ApplyPatch {},
|
||||
NetworkAccess {
|
||||
protocol: NetworkApprovalProtocol,
|
||||
port: u16,
|
||||
},
|
||||
McpToolCall {
|
||||
server: String,
|
||||
tool_name: String,
|
||||
connector_id: Option<String>,
|
||||
connector_name: Option<String>,
|
||||
tool_title: Option<String>,
|
||||
},
|
||||
RequestPermissions {},
|
||||
}
|
||||
|
||||
/// Details of one completed review, used for local decisions and local metrics.
|
||||
#[derive(Debug)]
|
||||
pub struct GuardianReviewDetails {
|
||||
pub guardian_context_mode: Option<&'static str>,
|
||||
pub decision: GuardianReviewDecision,
|
||||
pub terminal_status: GuardianReviewTerminalStatus,
|
||||
pub failure_reason: Option<GuardianReviewFailureReason>,
|
||||
pub attempt_count: i64,
|
||||
/// An allow was validated against changed parent/root authorization or review context.
|
||||
/// Retained across attempts; this does not identify the cause of a later cancellation.
|
||||
pub context_changed: bool,
|
||||
pub risk_level: Option<GuardianRiskLevel>,
|
||||
pub user_authorization: Option<GuardianUserAuthorization>,
|
||||
pub outcome: Option<GuardianAssessmentOutcome>,
|
||||
pub guardian_thread_id: Option<String>,
|
||||
pub guardian_session_kind: Option<GuardianReviewSessionKind>,
|
||||
pub guardian_model: Option<String>,
|
||||
pub guardian_reasoning_effort: Option<String>,
|
||||
pub guardian_default_review_model_id: Option<String>,
|
||||
pub guardian_catalog_contains_auto_review: Option<bool>,
|
||||
pub guardian_review_model_overridden: Option<bool>,
|
||||
pub guardian_review_model_override: Option<String>,
|
||||
pub guardian_model_provider_id: Option<String>,
|
||||
pub had_prior_review_context: Option<bool>,
|
||||
pub reviewed_action_truncated: bool,
|
||||
pub token_usage: Option<TokenUsage>,
|
||||
pub time_to_first_token_ms: Option<u64>,
|
||||
}
|
||||
|
||||
impl GuardianReviewDetails {
|
||||
pub fn without_session() -> Self {
|
||||
Self {
|
||||
guardian_context_mode: None,
|
||||
decision: GuardianReviewDecision::Denied,
|
||||
terminal_status: GuardianReviewTerminalStatus::FailedClosed,
|
||||
failure_reason: None,
|
||||
attempt_count: 1,
|
||||
context_changed: false,
|
||||
risk_level: None,
|
||||
user_authorization: None,
|
||||
outcome: None,
|
||||
guardian_thread_id: None,
|
||||
guardian_session_kind: None,
|
||||
guardian_model: None,
|
||||
guardian_reasoning_effort: None,
|
||||
guardian_default_review_model_id: None,
|
||||
guardian_catalog_contains_auto_review: None,
|
||||
guardian_review_model_overridden: None,
|
||||
guardian_review_model_override: None,
|
||||
guardian_model_provider_id: None,
|
||||
had_prior_review_context: None,
|
||||
reviewed_action_truncated: false,
|
||||
token_usage: None,
|
||||
time_to_first_token_ms: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_session(params: GuardianReviewSessionDetails) -> Self {
|
||||
Self {
|
||||
guardian_thread_id: Some(params.guardian_thread_id),
|
||||
guardian_session_kind: Some(params.guardian_session_kind),
|
||||
guardian_model: Some(params.guardian_model),
|
||||
guardian_reasoning_effort: params.guardian_reasoning_effort,
|
||||
guardian_default_review_model_id: Some(params.guardian_default_review_model_id),
|
||||
guardian_catalog_contains_auto_review: Some(
|
||||
params.guardian_catalog_contains_auto_review,
|
||||
),
|
||||
guardian_review_model_overridden: Some(params.guardian_review_model_overridden),
|
||||
guardian_review_model_override: params.guardian_review_model_override,
|
||||
guardian_model_provider_id: Some(params.guardian_model_provider_id),
|
||||
had_prior_review_context: Some(params.had_prior_review_context),
|
||||
..Self::without_session()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GuardianReviewSessionDetails {
|
||||
pub guardian_thread_id: String,
|
||||
pub guardian_session_kind: GuardianReviewSessionKind,
|
||||
pub guardian_model: String,
|
||||
pub guardian_reasoning_effort: Option<String>,
|
||||
pub guardian_default_review_model_id: String,
|
||||
pub guardian_catalog_contains_auto_review: bool,
|
||||
pub guardian_review_model_overridden: bool,
|
||||
pub guardian_review_model_override: Option<String>,
|
||||
pub guardian_model_provider_id: String,
|
||||
pub had_prior_review_context: bool,
|
||||
}
|
||||
|
||||
/// Milliseconds since the Unix epoch.
|
||||
pub fn now_unix_millis() -> u64 {
|
||||
u64::try_from(
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis(),
|
||||
)
|
||||
.unwrap_or(u64::MAX)
|
||||
}
|
||||
Reference in New Issue
Block a user