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:
102
akode-rs/core/src/environment_selection/attachment.rs
Normal file
102
akode-rs/core/src/environment_selection/attachment.rs
Normal file
@@ -0,0 +1,102 @@
|
||||
//! The lifetime of one continuous selection of an executor.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_channel::Receiver;
|
||||
use async_channel::Sender;
|
||||
use akode_exec_server::Environment;
|
||||
use akode_exec_server::EnvironmentConnectionState;
|
||||
use akode_protocol::protocol::EnvironmentConnectionEvent;
|
||||
use akode_protocol::protocol::Event;
|
||||
use akode_protocol::protocol::EventMsg;
|
||||
use tokio::sync::watch;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tokio_util::sync::DropGuard;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
|
||||
/// Tracks one executor's membership in a thread's active or configured environment list.
|
||||
/// Turn snapshots share the attachment to access the executor and observe when it leaves that list.
|
||||
///
|
||||
/// Removing the executor drops the selection's guard and cancels `detached`, even while
|
||||
/// an older snapshot holds the attachment. Selecting the same executor again creates a new attachment.
|
||||
pub(crate) struct EnvironmentAttachment {
|
||||
pub(crate) environment: Arc<Environment>,
|
||||
pub(crate) detached: CancellationToken,
|
||||
_connection_events_task: Option<AbortOnDropHandle<()>>,
|
||||
}
|
||||
|
||||
impl EnvironmentAttachment {
|
||||
/// Returns the attachment, its detach guard, and a receiver for remote connection events.
|
||||
/// Snapshots share the attachment while the selection owns the guard, so dropping the guard
|
||||
/// signals detach immediately. The receiver starts at construction and can be dropped by
|
||||
/// callers that do not publish events. Local executors have no connection stream.
|
||||
pub(crate) fn new(
|
||||
environment_id: &str,
|
||||
environment: Arc<Environment>,
|
||||
) -> (Arc<Self>, DropGuard, Option<Receiver<Event>>) {
|
||||
let detached = CancellationToken::new();
|
||||
let (connection_events_task, events) = environment
|
||||
.subscribe_connection_state()
|
||||
.map(|connection_state| {
|
||||
let (tx_event, events) = async_channel::unbounded();
|
||||
let task = tokio::spawn(forward_connection_events(
|
||||
connection_state,
|
||||
environment_id.to_owned(),
|
||||
tx_event,
|
||||
detached.clone(),
|
||||
));
|
||||
(AbortOnDropHandle::new(task), events)
|
||||
})
|
||||
.unzip();
|
||||
let attachment = Arc::new(Self {
|
||||
environment,
|
||||
detached,
|
||||
_connection_events_task: connection_events_task,
|
||||
});
|
||||
let detach_on_drop = attachment.detached.clone().drop_guard();
|
||||
(attachment, detach_on_drop, events)
|
||||
}
|
||||
}
|
||||
|
||||
async fn forward_connection_events(
|
||||
mut connection_state: watch::Receiver<EnvironmentConnectionState>,
|
||||
environment_id: String,
|
||||
tx_event: Sender<Event>,
|
||||
detached: CancellationToken,
|
||||
) {
|
||||
loop {
|
||||
let state = tokio::select! {
|
||||
biased;
|
||||
_ = detached.cancelled() => return,
|
||||
_ = tx_event.closed() => return,
|
||||
changed = connection_state.changed() => {
|
||||
if changed.is_err() {
|
||||
return;
|
||||
}
|
||||
*connection_state.borrow_and_update()
|
||||
}
|
||||
};
|
||||
let msg = match state {
|
||||
EnvironmentConnectionState::Recovering => continue,
|
||||
EnvironmentConnectionState::Connected => {
|
||||
EventMsg::EnvironmentConnected(EnvironmentConnectionEvent {
|
||||
environment_id: environment_id.clone(),
|
||||
})
|
||||
}
|
||||
EnvironmentConnectionState::Disconnected => {
|
||||
EventMsg::EnvironmentDisconnected(EnvironmentConnectionEvent {
|
||||
environment_id: environment_id.clone(),
|
||||
})
|
||||
}
|
||||
};
|
||||
if tx_event
|
||||
.try_send(Event {
|
||||
id: String::new(),
|
||||
msg,
|
||||
})
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user