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:
49
akode-rs/core/src/plugins/injection.rs
Normal file
49
akode-rs/core/src/plugins/injection.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use akode_features::Features;
|
||||
use akode_protocol::models::ResponseItem;
|
||||
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::context::PluginInstructions;
|
||||
use crate::plugins::PluginCapabilitySummary;
|
||||
use crate::plugins::render_explicit_plugin_instructions;
|
||||
use akode_mcp::ToolInfo;
|
||||
|
||||
pub(crate) fn build_plugin_injections(
|
||||
mentioned_plugins: &[PluginCapabilitySummary],
|
||||
mcp_tools: &[ToolInfo],
|
||||
features: &Features,
|
||||
model_messages: akode_prompts::ResolvedModelMessages<'_>,
|
||||
) -> Vec<ResponseItem> {
|
||||
if mentioned_plugins.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let messages = model_messages.selected_plugin();
|
||||
// Turn each explicit plugin mention with available capabilities into a developer hint.
|
||||
mentioned_plugins
|
||||
.iter()
|
||||
.filter_map(|plugin| {
|
||||
let available_mcp_servers = mcp_tools
|
||||
.iter()
|
||||
.filter(|tool| {
|
||||
tool.plugin_display_names
|
||||
.iter()
|
||||
.any(|plugin_name| plugin_name == &plugin.display_name)
|
||||
})
|
||||
.map(|tool| tool.server_name.clone())
|
||||
.collect::<BTreeSet<String>>()
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
render_explicit_plugin_instructions(
|
||||
plugin,
|
||||
&available_mcp_servers,
|
||||
/*available_apps*/ &[],
|
||||
features,
|
||||
&messages,
|
||||
)
|
||||
.map(PluginInstructions::new)
|
||||
.map(ContextualUserFragment::into)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
82
akode-rs/core/src/plugins/mentions.rs
Normal file
82
akode-rs/core/src/plugins/mentions.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use akode_protocol::user_input::UserInput;
|
||||
use akode_skills::ToolMentionKind;
|
||||
use akode_skills::extract_tool_mentions_with_sigil;
|
||||
use akode_skills::plugin_config_name_from_path;
|
||||
use akode_skills::tool_kind_for_path;
|
||||
|
||||
use crate::mention_syntax::PLUGIN_TEXT_MENTION_SIGIL;
|
||||
use crate::mention_syntax::TOOL_MENTION_SIGIL;
|
||||
|
||||
use super::PluginCapabilitySummary;
|
||||
|
||||
pub(crate) struct CollectedToolMentions {
|
||||
pub(crate) paths: HashSet<String>,
|
||||
}
|
||||
|
||||
pub(crate) fn collect_tool_mentions_from_messages(messages: &[String]) -> CollectedToolMentions {
|
||||
collect_tool_mentions_from_messages_with_sigil(messages, TOOL_MENTION_SIGIL)
|
||||
}
|
||||
|
||||
fn collect_tool_mentions_from_messages_with_sigil(
|
||||
messages: &[String],
|
||||
sigil: char,
|
||||
) -> CollectedToolMentions {
|
||||
let mut paths = HashSet::new();
|
||||
for message in messages {
|
||||
let mentions = extract_tool_mentions_with_sigil(message, sigil);
|
||||
paths.extend(mentions.paths().map(str::to_string));
|
||||
}
|
||||
CollectedToolMentions { paths }
|
||||
}
|
||||
|
||||
/// Collect explicit structured or linked `plugin://...` mentions.
|
||||
pub(crate) fn collect_explicit_plugin_mentions(
|
||||
input: &[UserInput],
|
||||
plugins: &[PluginCapabilitySummary],
|
||||
) -> Vec<PluginCapabilitySummary> {
|
||||
if plugins.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
// `config_name` stores the full plugin ID, not its display or mention name.
|
||||
let mentioned_plugin_ids = collect_explicit_plugin_ids(input);
|
||||
plugins
|
||||
.iter()
|
||||
.filter(|plugin| mentioned_plugin_ids.contains(plugin.config_name.as_str()))
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Collect exact IDs from explicit `plugin://` references, independently of display names.
|
||||
///
|
||||
/// Host plugins use `<plugin>@<marketplace>` IDs; selected roots may supply opaque IDs.
|
||||
pub(crate) fn collect_explicit_plugin_ids(input: &[UserInput]) -> HashSet<String> {
|
||||
let messages = input
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
UserInput::Text { text, .. } => Some(text.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
input
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
UserInput::Mention { path, .. } => Some(path.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.chain(
|
||||
// Plugin plaintext links use `@`, not the default `$` tool sigil.
|
||||
collect_tool_mentions_from_messages_with_sigil(&messages, PLUGIN_TEXT_MENTION_SIGIL)
|
||||
.paths,
|
||||
)
|
||||
.filter(|path| tool_kind_for_path(path.as_str()) == ToolMentionKind::Plugin)
|
||||
.filter_map(|path| plugin_config_name_from_path(path.as_str()).map(str::to_string))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "mentions_tests.rs"]
|
||||
mod tests;
|
||||
126
akode-rs/core/src/plugins/mentions_tests.rs
Normal file
126
akode-rs/core/src/plugins/mentions_tests.rs
Normal file
@@ -0,0 +1,126 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use akode_protocol::user_input::UserInput;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::collect_explicit_plugin_ids;
|
||||
use super::collect_explicit_plugin_mentions;
|
||||
use crate::plugins::PluginCapabilitySummary;
|
||||
|
||||
fn text_input(text: &str) -> UserInput {
|
||||
UserInput::Text {
|
||||
text: text.to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin(config_name: &str, display_name: &str) -> PluginCapabilitySummary {
|
||||
PluginCapabilitySummary {
|
||||
config_name: config_name.to_string(),
|
||||
display_name: display_name.to_string(),
|
||||
plugin_namespace: None,
|
||||
description: None,
|
||||
has_skills: true,
|
||||
mcp_server_names: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_plugin_mentions_from_structured_paths() {
|
||||
let expected = plugin("sample@test", "Sample");
|
||||
let plugins = vec![
|
||||
expected.clone(),
|
||||
plugin("sample@other-marketplace", "Sample"),
|
||||
plugin("other@test", "alias"),
|
||||
];
|
||||
|
||||
let mentioned = collect_explicit_plugin_mentions(
|
||||
&[UserInput::Mention {
|
||||
name: "alias".to_string(),
|
||||
path: "plugin://sample@test".to_string(),
|
||||
}],
|
||||
&plugins,
|
||||
);
|
||||
|
||||
assert_eq!(mentioned, vec![expected]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_plugin_mentions_from_linked_text_mentions() {
|
||||
let expected = plugin("sample@test", "Sample");
|
||||
let plugins = vec![
|
||||
expected.clone(),
|
||||
plugin("sample@other-marketplace", "Sample"),
|
||||
plugin("other@test", "alias"),
|
||||
];
|
||||
|
||||
let mentioned = collect_explicit_plugin_mentions(
|
||||
&[text_input("use [@alias](plugin://sample@test)")],
|
||||
&plugins,
|
||||
);
|
||||
|
||||
assert_eq!(mentioned, vec![expected]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_plugin_mentions_dedupes_structured_and_linked_mentions() {
|
||||
let plugins = vec![
|
||||
plugin("sample@test", "sample"),
|
||||
plugin("other@test", "other"),
|
||||
];
|
||||
|
||||
let mentioned = collect_explicit_plugin_mentions(
|
||||
&[
|
||||
text_input("use [@sample](plugin://sample@test)"),
|
||||
UserInput::Mention {
|
||||
name: "sample".to_string(),
|
||||
path: "plugin://sample@test".to_string(),
|
||||
},
|
||||
],
|
||||
&plugins,
|
||||
);
|
||||
|
||||
assert_eq!(mentioned, vec![plugin("sample@test", "sample")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_plugin_mentions_ignores_non_plugin_paths() {
|
||||
let plugins = vec![plugin("sample@test", "sample")];
|
||||
|
||||
let mentioned = collect_explicit_plugin_mentions(
|
||||
&[text_input(
|
||||
"use [$app](app://calendar) and [$skill](skill://team/skill) and [$file](/tmp/file.txt)",
|
||||
)],
|
||||
&plugins,
|
||||
);
|
||||
|
||||
assert_eq!(mentioned, Vec::<PluginCapabilitySummary>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_plugin_mentions_ignores_dollar_linked_plugin_mentions() {
|
||||
let plugins = vec![plugin("sample@test", "sample")];
|
||||
|
||||
let mentioned = collect_explicit_plugin_mentions(
|
||||
&[text_input("use [$sample](plugin://sample@test)")],
|
||||
&plugins,
|
||||
);
|
||||
|
||||
assert_eq!(mentioned, Vec::<PluginCapabilitySummary>::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_explicit_plugin_ids_preserves_opaque_ids() {
|
||||
let input = [
|
||||
text_input("use [@same](plugin://selected-one)"),
|
||||
UserInput::Mention {
|
||||
name: "same".to_string(),
|
||||
path: "plugin://selected-two".to_string(),
|
||||
},
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
collect_explicit_plugin_ids(&input),
|
||||
HashSet::from(["selected-one".to_string(), "selected-two".to_string()]),
|
||||
);
|
||||
}
|
||||
41
akode-rs/core/src/plugins/mod.rs
Normal file
41
akode-rs/core/src/plugins/mod.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
mod injection;
|
||||
mod mentions;
|
||||
mod render;
|
||||
#[cfg(test)]
|
||||
#[path = "skill_snapshot_tests.rs"]
|
||||
mod skill_snapshot_tests;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test_support;
|
||||
|
||||
use crate::config::Config;
|
||||
use akode_core_plugins::PluginsManager;
|
||||
use akode_login::AuthManager;
|
||||
use akode_skills_extension::HostSkillsService;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) use akode_plugin::PluginCapabilitySummary;
|
||||
|
||||
pub(crate) use injection::build_plugin_injections;
|
||||
pub(crate) use render::render_explicit_plugin_instructions;
|
||||
|
||||
pub(crate) use mentions::collect_explicit_plugin_ids;
|
||||
pub(crate) use mentions::collect_explicit_plugin_mentions;
|
||||
pub(crate) use mentions::collect_tool_mentions_from_messages;
|
||||
|
||||
/// Constructs a standalone plugin manager with extension-owned plugin skill loading.
|
||||
///
|
||||
/// Callers that already own a host skills service should inject that existing service instead.
|
||||
pub fn plugins_manager_for_config(
|
||||
config: &Config,
|
||||
auth_manager: Arc<AuthManager>,
|
||||
) -> PluginsManager {
|
||||
let skill_root_loader = Arc::new(HostSkillsService::new(
|
||||
config.codex_home.clone(),
|
||||
/*bundled_skills_enabled*/ false,
|
||||
));
|
||||
PluginsManager::new(
|
||||
config.codex_home.to_path_buf(),
|
||||
auth_manager,
|
||||
skill_root_loader,
|
||||
)
|
||||
}
|
||||
124
akode-rs/core/src/plugins/render.rs
Normal file
124
akode-rs/core/src/plugins/render.rs
Normal file
@@ -0,0 +1,124 @@
|
||||
#[cfg(test)]
|
||||
use crate::context::AvailablePluginsInstructions;
|
||||
#[cfg(test)]
|
||||
use crate::context::ContextualUserFragment;
|
||||
use crate::plugins::PluginCapabilitySummary;
|
||||
use akode_features::Feature;
|
||||
use akode_features::Features;
|
||||
use akode_prompts::ResolvedSelectedPluginMessages;
|
||||
#[cfg(test)]
|
||||
use akode_protocol_test_support::ContentItemTestExt;
|
||||
use akode_utils_string::take_bytes_at_char_boundary;
|
||||
|
||||
const MAX_EXPLICIT_PLUGIN_INSTRUCTIONS_BYTES: usize = 4 * 1024;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn render_plugins_section(plugins: &[PluginCapabilitySummary]) -> Option<String> {
|
||||
(!plugins.is_empty()).then(|| {
|
||||
AvailablePluginsInstructions::default()
|
||||
.render()
|
||||
.expect_text()
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn render_explicit_plugin_instructions(
|
||||
plugin: &PluginCapabilitySummary,
|
||||
available_mcp_servers: &[String],
|
||||
available_apps: &[String],
|
||||
features: &Features,
|
||||
messages: &ResolvedSelectedPluginMessages,
|
||||
) -> Option<String> {
|
||||
if features.enabled(Feature::SimplifiedSelectionHints) {
|
||||
return (plugin.has_skills || !available_apps.is_empty() || !available_mcp_servers.is_empty())
|
||||
.then(|| {
|
||||
bound_explicit_plugin_instructions(
|
||||
format!(
|
||||
"The user selected the `{}` plugin. Use its available skills and tools to complete this request.",
|
||||
plugin.display_name
|
||||
),
|
||||
"\n[Plugin selection truncated to fit the context limit.]",
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
let mut lines = vec![
|
||||
messages
|
||||
.intro
|
||||
.replace("{{ plugin_name }}", &plugin.display_name),
|
||||
];
|
||||
|
||||
if !available_apps.is_empty() {
|
||||
lines.push(messages.search_tools.clone());
|
||||
}
|
||||
|
||||
if plugin.has_skills {
|
||||
let skill_namespace = plugin
|
||||
.plugin_namespace
|
||||
.as_deref()
|
||||
.unwrap_or(plugin.display_name.as_str());
|
||||
lines.push(
|
||||
messages
|
||||
.skill_namespace
|
||||
.replace("{{ skill_namespace }}", skill_namespace),
|
||||
);
|
||||
}
|
||||
|
||||
if !available_apps.is_empty() {
|
||||
lines.push(
|
||||
messages.apps.replace(
|
||||
"{{ apps }}",
|
||||
&available_apps
|
||||
.iter()
|
||||
.map(|app| format!("`{app}`"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if !available_mcp_servers.is_empty() {
|
||||
lines.push(
|
||||
messages.mcp_servers.replace(
|
||||
"{{ mcp_servers }}",
|
||||
&available_mcp_servers
|
||||
.iter()
|
||||
.map(|server| format!("`{server}`"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if lines.len() == 1 {
|
||||
return None;
|
||||
}
|
||||
|
||||
lines.push(messages.closing.clone());
|
||||
|
||||
// The separator belongs to the harness; preserve the catalog's exact bytes after it.
|
||||
let omitted = if messages.omitted.starts_with('\n') || messages.omitted.starts_with("\r\n") {
|
||||
messages.omitted.clone()
|
||||
} else {
|
||||
format!("\n{}", messages.omitted)
|
||||
};
|
||||
|
||||
Some(bound_explicit_plugin_instructions(
|
||||
lines.join("\n"),
|
||||
&omitted,
|
||||
))
|
||||
}
|
||||
|
||||
fn bound_explicit_plugin_instructions(rendered: String, truncation_suffix: &str) -> String {
|
||||
if rendered.len() <= MAX_EXPLICIT_PLUGIN_INSTRUCTIONS_BYTES {
|
||||
return rendered;
|
||||
}
|
||||
|
||||
let max_prefix_bytes =
|
||||
MAX_EXPLICIT_PLUGIN_INSTRUCTIONS_BYTES.saturating_sub(truncation_suffix.len());
|
||||
let prefix = take_bytes_at_char_boundary(&rendered, max_prefix_bytes);
|
||||
format!("{prefix}{truncation_suffix}")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "render_tests.rs"]
|
||||
mod tests;
|
||||
157
akode-rs/core/src/plugins/render_tests.rs
Normal file
157
akode-rs/core/src/plugins/render_tests.rs
Normal file
@@ -0,0 +1,157 @@
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn render_plugins_section_returns_none_for_empty_plugins() {
|
||||
assert_eq!(render_plugins_section(&[]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_plugins_section_keeps_plugin_usage_guidance_without_listing_plugins() {
|
||||
let rendered = render_plugins_section(&[PluginCapabilitySummary {
|
||||
config_name: "sample@test".to_string(),
|
||||
display_name: "sample".to_string(),
|
||||
plugin_namespace: None,
|
||||
description: Some("inspect sample data".to_string()),
|
||||
has_skills: true,
|
||||
..PluginCapabilitySummary::default()
|
||||
}])
|
||||
.expect("plugin section should render");
|
||||
|
||||
let expected = "<plugins_instructions>\n## Plugins\nA plugin is a local bundle of skills, MCP servers, and apps.\n### How to use plugins\n- Skill naming: If a plugin contributes skills, those skill entries are prefixed with `plugin_name:` in the Skills list.\n- MCP naming: Plugin-provided MCP tools keep standard MCP identifiers such as `mcp__server__tool`; use tool provenance to tell which plugin they come from.\n- Trigger rules: If the user explicitly names a plugin, prefer capabilities associated with that plugin for that turn.\n- Relationship to capabilities: Plugins are not invoked directly. Use their underlying skills, MCP tools, and app tools to help solve the task.\n- Relevance: Determine what a plugin can help with from explicit user mention or from the plugin-associated skills, MCP tools, and apps exposed elsewhere in this turn.\n- Missing/blocked: If the user requests a plugin that does not have relevant callable capabilities for the task, say so briefly and continue with the best fallback.\n</plugins_instructions>";
|
||||
|
||||
assert_eq!(rendered, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_plugin_instructions_use_manifest_namespace_for_skills() {
|
||||
let rendered = render_explicit_plugin_instructions(
|
||||
&PluginCapabilitySummary {
|
||||
config_name: "acme.tools@test".to_string(),
|
||||
display_name: "Acme Developer Tools".to_string(),
|
||||
plugin_namespace: Some("acme.tools".to_string()),
|
||||
has_skills: true,
|
||||
..PluginCapabilitySummary::default()
|
||||
},
|
||||
&[],
|
||||
&[],
|
||||
&Features::default(),
|
||||
&akode_prompts::ResolvedModelMessages::bundled().selected_plugin(),
|
||||
)
|
||||
.expect("skill capability should render");
|
||||
|
||||
assert!(rendered.contains("`acme.tools:`"));
|
||||
assert!(!rendered.contains("`Acme Developer Tools:`"));
|
||||
assert!(!rendered.contains("tool_search"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_plugin_instructions_search_available_apps_before_fallback() {
|
||||
let rendered = render_explicit_plugin_instructions(
|
||||
&PluginCapabilitySummary {
|
||||
config_name: "app-adobe@openai-curated".to_string(),
|
||||
display_name: "Adobe".to_string(),
|
||||
..PluginCapabilitySummary::default()
|
||||
},
|
||||
&[],
|
||||
&["Adobe".to_string()],
|
||||
&Features::default(),
|
||||
&akode_prompts::ResolvedModelMessages::bundled().selected_plugin(),
|
||||
)
|
||||
.expect("app capability should render");
|
||||
|
||||
assert_eq!(
|
||||
rendered,
|
||||
"Capabilities from the `Adobe` plugin:\n\
|
||||
- For the user request that explicitly selected this plugin, and only for that request, \
|
||||
if `tool_search` is available and an app from this plugin may help, search for its \
|
||||
tools before falling back to unrelated or built-in tools.\n\
|
||||
- Apps from this plugin available in this session: `Adobe`.\n\
|
||||
Use these plugin-associated capabilities to help solve the task."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_plugin_instructions_are_bounded() {
|
||||
let servers = (0..1_024)
|
||||
.map(|index| format!("server-{index}"))
|
||||
.collect::<Vec<_>>();
|
||||
let apps = (0..1_024)
|
||||
.map(|index| format!("app-{index}"))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let rendered = render_explicit_plugin_instructions(
|
||||
&PluginCapabilitySummary {
|
||||
config_name: "sample@test".to_string(),
|
||||
display_name: "sample".to_string(),
|
||||
has_skills: true,
|
||||
..PluginCapabilitySummary::default()
|
||||
},
|
||||
&servers,
|
||||
&apps,
|
||||
&Features::default(),
|
||||
&akode_prompts::ResolvedModelMessages::bundled().selected_plugin(),
|
||||
)
|
||||
.expect("MCP capability should render");
|
||||
|
||||
assert!(rendered.len() <= MAX_EXPLICIT_PLUGIN_INSTRUCTIONS_BYTES);
|
||||
assert!(rendered.contains("only for that request"));
|
||||
assert!(rendered.contains("if `tool_search` is available"));
|
||||
assert!(rendered.contains("Skills from this plugin"));
|
||||
assert!(rendered.contains("`app-0`"));
|
||||
assert!(
|
||||
rendered.ends_with(
|
||||
&akode_prompts::ResolvedModelMessages::bundled()
|
||||
.selected_plugin()
|
||||
.omitted
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_plugin_templates_insert_runtime_facts_once() {
|
||||
let mut messages = akode_prompts::ResolvedModelMessages::bundled().selected_plugin();
|
||||
messages.intro = "Selected {{ plugin_name }}.".into();
|
||||
messages.search_tools = "Search wording {{literal}}.\r\n".into();
|
||||
messages.skill_namespace = "Skills {{ skill_namespace }}.".into();
|
||||
messages.apps = "Apps {{ apps }}.".into();
|
||||
messages.mcp_servers = "Servers {{ mcp_servers }}.".into();
|
||||
messages.closing = "Closing {{literal}}.".into();
|
||||
let rendered = render_explicit_plugin_instructions(
|
||||
&PluginCapabilitySummary {
|
||||
display_name: "Name {{ apps }}".into(),
|
||||
plugin_namespace: Some("namespace{{ plugin_name }}".into()),
|
||||
has_skills: true,
|
||||
..PluginCapabilitySummary::default()
|
||||
},
|
||||
&["server{{ apps }}".into()],
|
||||
&["app{{ mcp_servers }}".into()],
|
||||
&Features::default(),
|
||||
&messages,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
rendered,
|
||||
"Selected Name {{ apps }}.\nSearch wording {{literal}}.\r\n\nSkills namespace{{ plugin_name }}.\nApps `app{{ mcp_servers }}`.\nServers `server{{ apps }}`.\nClosing {{literal}}."
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_plugin_omission_keeps_utf8_and_the_final_item_bound() {
|
||||
let mut messages = akode_prompts::ResolvedModelMessages::bundled().selected_plugin();
|
||||
messages.omitted = "é".repeat(250);
|
||||
let rendered = render_explicit_plugin_instructions(
|
||||
&PluginCapabilitySummary {
|
||||
display_name: "plugin".into(),
|
||||
..Default::default()
|
||||
},
|
||||
&[],
|
||||
&["🦀".repeat(2_000)],
|
||||
&Features::default(),
|
||||
&messages,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(rendered.len() <= MAX_EXPLICIT_PLUGIN_INSTRUCTIONS_BYTES);
|
||||
assert!(rendered.ends_with(&format!("\n{}", messages.omitted)));
|
||||
assert!(rendered.contains("🦀"));
|
||||
}
|
||||
89
akode-rs/core/src/plugins/skill_snapshot_tests.rs
Normal file
89
akode-rs/core/src/plugins/skill_snapshot_tests.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use akode_core_plugins::PluginsManager;
|
||||
use akode_login::AuthManager;
|
||||
use akode_login::CodexAuth;
|
||||
use akode_protocol::protocol::Product;
|
||||
use akode_skills_extension::HostSkillsLoadInput;
|
||||
use akode_skills_extension::HostSkillsService;
|
||||
use akode_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::test_support::load_plugins_config;
|
||||
use super::test_support::write_file;
|
||||
|
||||
// Remote curated catalogs need ChatGPT auth; the local API-key curated catalog exercises
|
||||
// the same snapshot reuse.
|
||||
const PLUGIN_CONFIG_NAME: &str = "sample@openai-api-curated";
|
||||
|
||||
#[tokio::test]
|
||||
async fn host_skills_service_reuses_plugin_manager_skill_snapshot() {
|
||||
let codex_home = tempfile::tempdir().expect("create codex home");
|
||||
let plugin_root = codex_home
|
||||
.path()
|
||||
.join("plugins/cache/openai-api-curated/sample/local");
|
||||
write_file(
|
||||
&plugin_root.join(".codex-plugin/plugin.json"),
|
||||
r#"{"name":"sample","description":"sample plugin"}"#,
|
||||
);
|
||||
let skill_path = plugin_root.join("skills/SKILL.md");
|
||||
write_file(&skill_path, "---\nname: search\ndescription: first\n---\n");
|
||||
write_file(
|
||||
&codex_home.path().join("config.toml"),
|
||||
&format!(
|
||||
r#"[features]
|
||||
plugins = true
|
||||
remote_plugin = false
|
||||
|
||||
[plugins."{PLUGIN_CONFIG_NAME}"]
|
||||
enabled = true
|
||||
|
||||
[skills.bundled]
|
||||
enabled = false
|
||||
"#,
|
||||
),
|
||||
);
|
||||
let config = load_plugins_config(codex_home.path()).await;
|
||||
let plugins_input = config.plugins_config_input();
|
||||
let skills_service = Arc::new(HostSkillsService::new(
|
||||
config.codex_home.clone(),
|
||||
/*bundled_skills_enabled*/ false,
|
||||
));
|
||||
let plugins_manager = PluginsManager::new_with_options(
|
||||
codex_home.path().to_path_buf(),
|
||||
Some(Product::Codex),
|
||||
AuthManager::from_auth_for_testing(CodexAuth::from_api_key("Test API Key")),
|
||||
skills_service.clone(),
|
||||
);
|
||||
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
|
||||
|
||||
write_file(&skill_path, "---\nname: search\ndescription: second\n---\n");
|
||||
|
||||
let other_cwd = codex_home.path().join("other-workspace");
|
||||
std::fs::create_dir_all(&other_cwd).expect("create second workspace");
|
||||
let other_cwd = AbsolutePathBuf::from_absolute_path(other_cwd).expect("absolute workspace");
|
||||
|
||||
for cwd in [config.cwd.clone(), other_cwd] {
|
||||
let skills_input = HostSkillsLoadInput::new(
|
||||
cwd,
|
||||
plugin_outcome.effective_plugin_skill_roots(),
|
||||
config.config_layer_stack.clone(),
|
||||
)
|
||||
.with_plugin_skill_snapshots(
|
||||
plugins_manager.plugin_skill_snapshots_for_config(&plugins_input),
|
||||
);
|
||||
let snapshot = skills_service
|
||||
.snapshot_for_config(&skills_input, /*repository*/ None)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
snapshot
|
||||
.outcome()
|
||||
.skills
|
||||
.iter()
|
||||
.filter(|skill| skill.plugin_id.as_deref() == Some(PLUGIN_CONFIG_NAME))
|
||||
.map(|skill| (skill.description.as_str(), skill.plugin_id.as_deref()))
|
||||
.collect::<Vec<_>>(),
|
||||
vec![("first", Some(PLUGIN_CONFIG_NAME))]
|
||||
);
|
||||
}
|
||||
}
|
||||
17
akode-rs/core/src/plugins/test_support.rs
Normal file
17
akode-rs/core/src/plugins/test_support.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::config::ConfigBuilder;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
pub(crate) fn write_file(path: &Path, contents: &str) {
|
||||
fs::create_dir_all(path.parent().expect("file should have a parent")).unwrap();
|
||||
fs::write(path, contents).unwrap();
|
||||
}
|
||||
|
||||
pub(crate) async fn load_plugins_config(codex_home: &Path) -> crate::config::Config {
|
||||
ConfigBuilder::default()
|
||||
.codex_home(codex_home.to_path_buf())
|
||||
.fallback_cwd(Some(codex_home.to_path_buf()))
|
||||
.build()
|
||||
.await
|
||||
.expect("config should load")
|
||||
}
|
||||
Reference in New Issue
Block a user