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:
117
akode-rs/message-board/src/local/setup.rs
Normal file
117
akode-rs/message-board/src/local/setup.rs
Normal file
@@ -0,0 +1,117 @@
|
||||
//! Loads initial channels into an empty local board and pins their source template.
|
||||
|
||||
use super::insert_channel;
|
||||
use super::invalid;
|
||||
use super::options::LocalBoardOptions;
|
||||
use super::storage_error;
|
||||
use super::validate_channel;
|
||||
use crate::ChannelDescription;
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use akode_protocol::AgentPath;
|
||||
use akode_protocol::SessionId;
|
||||
use akode_protocol::error::Result;
|
||||
use akode_state::SqliteConfig;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Channel {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
description: Option<ChannelDescription>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Template {
|
||||
version: u32,
|
||||
#[serde(default)]
|
||||
channels: BTreeMap<String, Channel>,
|
||||
}
|
||||
|
||||
/// Operator input for loading an empty board. This is not an agent tool.
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct LocalBoardSetup {
|
||||
#[serde(default)]
|
||||
timestamp: Option<DateTime<Utc>>,
|
||||
template: Template,
|
||||
}
|
||||
|
||||
/// Saves the template and its initial channels atomically. The same template is
|
||||
/// safe to retry; replacing it or initializing an already-used board is rejected.
|
||||
pub async fn configure_local_board(
|
||||
sqlite: &SqliteConfig,
|
||||
options: &LocalBoardOptions,
|
||||
board: SessionId,
|
||||
setup: LocalBoardSetup,
|
||||
) -> Result<()> {
|
||||
let template = setup.template;
|
||||
let encoded = serde_json::to_string(&template).map_err(storage_error)?;
|
||||
if template.version != 1 || encoded.len() > 64 * 1024 || template.channels.len() > 64 {
|
||||
return Err(invalid(
|
||||
"board templates require version 1 and at most 64 KiB / 64 channels",
|
||||
));
|
||||
}
|
||||
for name in template.channels.keys() {
|
||||
validate_channel(name)?;
|
||||
}
|
||||
let pool = super::pool::open(sqlite, options).await?;
|
||||
let mut tx = pool
|
||||
.begin_with("BEGIN IMMEDIATE")
|
||||
.await
|
||||
.map_err(storage_error)?;
|
||||
let board_key = board.to_string();
|
||||
let deleted: bool =
|
||||
sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM deleted_boards WHERE board=?)")
|
||||
.bind(&board_key)
|
||||
.fetch_one(&mut *tx)
|
||||
.await
|
||||
.map_err(storage_error)?;
|
||||
if deleted {
|
||||
return Err(invalid("the board has been permanently deleted"));
|
||||
}
|
||||
let pinned: Option<String> =
|
||||
sqlx::query_scalar("SELECT template FROM board_templates WHERE board=?")
|
||||
.bind(&board_key)
|
||||
.fetch_optional(&mut *tx)
|
||||
.await
|
||||
.map_err(storage_error)?;
|
||||
if let Some(pinned) = pinned {
|
||||
if pinned != encoded {
|
||||
return Err(invalid("the board template is already pinned"));
|
||||
}
|
||||
} else {
|
||||
let used: bool = sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM channels WHERE board=?)")
|
||||
.bind(&board_key)
|
||||
.fetch_one(&mut *tx)
|
||||
.await
|
||||
.map_err(storage_error)?;
|
||||
if used {
|
||||
return Err(invalid(
|
||||
"pin the template before creating channels or posts",
|
||||
));
|
||||
}
|
||||
sqlx::query("INSERT INTO board_templates(board,template) VALUES(?,?)")
|
||||
.bind(&board_key)
|
||||
.bind(encoded)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_err(storage_error)?;
|
||||
let now = setup.timestamp.unwrap_or_else(Utc::now);
|
||||
for (name, channel) in &template.channels {
|
||||
insert_channel(
|
||||
&mut tx,
|
||||
board,
|
||||
name,
|
||||
channel.description.as_ref(),
|
||||
&AgentPath::root(),
|
||||
now,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
tx.commit().await.map_err(storage_error)
|
||||
}
|
||||
Reference in New Issue
Block a user