aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 11:06:46 +01:00
parent df99318392
commit 86e7c72e5f
10383 changed files with 749164 additions and 749170 deletions

View File

@@ -0,0 +1,103 @@
//! Shared formatting for user-facing `akode resume` command hints.
use akode_protocol::ThreadId;
use akode_shell_command::parse_command::shlex_join;
pub fn resume_command(thread_name: Option<&str>, thread_id: Option<ThreadId>) -> Option<String> {
let resume_target = thread_name
.filter(|name| !name.is_empty())
.map(str::to_string)
.or_else(|| thread_id.map(|thread_id| thread_id.to_string()));
resume_target.map(|target| {
let needs_double_dash = target.starts_with('-');
let escaped = shlex_join(&[target]);
if needs_double_dash {
format!("codex resume -- {escaped}")
} else {
format!("codex resume {escaped}")
}
})
}
pub fn resume_hint(thread_name: Option<&str>, thread_id: Option<ThreadId>) -> Option<String> {
let thread_id = thread_id?;
match thread_name.filter(|name| !name.is_empty()) {
Some(thread_name) => Some(format!(
"codex resume, then select {thread_name} ({thread_id})"
)),
None => resume_command(/*thread_name*/ None, Some(thread_id)),
}
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn prefers_name_over_id() {
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
let command = resume_command(Some("my-thread"), Some(thread_id));
assert_eq!(command, Some("codex resume my-thread".to_string()));
}
#[test]
fn formats_thread_id_when_name_is_missing() {
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
let command = resume_command(/*thread_name*/ None, Some(thread_id));
assert_eq!(
command,
Some("codex resume 123e4567-e89b-12d3-a456-426614174000".to_string())
);
}
#[test]
fn returns_none_without_a_resume_target() {
let command = resume_command(/*thread_name*/ None, /*thread_id*/ None);
assert_eq!(command, None);
}
#[test]
fn quotes_thread_names_when_needed() {
let command = resume_command(Some("-starts-with-dash"), /*thread_id*/ None);
assert_eq!(
command,
Some("codex resume -- -starts-with-dash".to_string())
);
let command = resume_command(Some("two words"), /*thread_id*/ None);
assert_eq!(command, Some("codex resume 'two words'".to_string()));
let command = resume_command(Some("quote'case"), /*thread_id*/ None);
assert_eq!(command, Some("codex resume \"quote'case\"".to_string()));
}
#[test]
fn resume_hint_names_picker_item_with_id() {
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
let hint = resume_hint(Some("my-thread"), Some(thread_id));
assert_eq!(
hint,
Some(
"codex resume, then select my-thread (123e4567-e89b-12d3-a456-426614174000)"
.to_string()
)
);
}
#[test]
fn resume_hint_uses_direct_id_command_without_name() {
let thread_id = ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").unwrap();
let hint = resume_hint(/*thread_name*/ None, Some(thread_id));
assert_eq!(
hint,
Some("codex resume 123e4567-e89b-12d3-a456-426614174000".to_string())
);
}
#[test]
fn resume_hint_requires_thread_id() {
let hint = resume_hint(Some("my-thread"), /*thread_id*/ None);
assert_eq!(hint, None);
}
}