profile: remove lua profile resolver

This commit is contained in:
2026-07-11 04:44:32 +09:00
parent 156f8ad044
commit 254360f1ab
24 changed files with 473 additions and 980 deletions
+1 -1
View File
@@ -1227,7 +1227,7 @@ workflow = "ticket-review-workflow"
temp.path(),
r#"
[roles.coder]
profile = "./coder.lua"
profile = "./coder.toml"
"#,
);
let context = TicketRoleLaunchContext::new(temp.path(), TicketRole::Coder);
-1
View File
@@ -7,7 +7,6 @@ license.workspace = true
[dependencies]
arc-swap = "1"
llm-engine = { workspace = true }
mlua = { version = "0.11.4", features = ["lua54", "vendored", "serialize"] }
protocol = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
+3 -3
View File
@@ -1193,9 +1193,9 @@ model_id = "claude-sonnet-4-20250514"
let toml = MINIMAL_REQUIRED.replace(
"[engine]\n",
"[engine]\n\
[worker.tool_output]\n\
[engine.tool_output]\n\
default_max_bytes = 8192\n\n\
[worker.tool_output.per_tool]\n\
[engine.tool_output.per_tool]\n\
Read = 32768\n\
Grep = 4096\n\n\
[engine.file_upload]\n\
@@ -1215,7 +1215,7 @@ model_id = "claude-sonnet-4-20250514"
let toml = MINIMAL_REQUIRED.replace(
"[engine]\n",
"[engine]\n\
[worker.tool_output]\n",
[engine.tool_output]\n",
);
let manifest = WorkerManifest::from_toml(&toml).unwrap();
let limits = &manifest.engine.tool_output;
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -497,7 +497,7 @@ mod tests {
);
metadata.resolved_manifest_snapshot = Some(serde_json::json!({
"worker": { "name": "profile-worker" },
"profile": { "source": { "kind": "path", "path": "/profiles/coder.lua" } }
"profile": { "source": { "kind": "path", "path": "/profiles/coder.toml" } }
}));
let json = serde_json::to_string(&metadata).unwrap();
+4 -2
View File
@@ -526,7 +526,9 @@ impl ProfileSelectorRef {
if value.starts_with("path:")
|| value.starts_with('.')
|| value.contains('/')
|| value.ends_with(".lua")
|| value.ends_with(".dcdl")
|| value.ends_with(".json")
|| value.ends_with(".toml")
|| value.ends_with(".nix")
{
return Err("profile selector must be `inherit`, `default`, a source-qualified registry selector, or an unqualified registry selector; path selectors are not supported".to_string());
@@ -1347,7 +1349,7 @@ profile = "legacy.nix"
temp.path(),
r#"
[roles.coder]
profile = "./coder.lua"
profile = "./coder.toml"
"#,
);
+1 -1
View File
@@ -34,7 +34,7 @@
//! let fs = ScopedFs::new(scope, PathBuf::from("/workspace")); // worker lifetime
//! let tracker = Tracker::new(); // session lifetime
//! let bash_outputs = PathBuf::from("/run/yoi/bash-output");
//! let defs = core_builtin_tools(fs, tracker, bash_outputs, None);
//! let defs = core_builtin_tools(fs, tracker, bash_outputs);
//! ```
use std::collections::{HashMap, VecDeque};
+52 -54
View File
@@ -8,7 +8,7 @@ use toml::Value;
use toml::map::Map;
const GENERATED_PROFILE_NAME: &str = "default";
const GENERATED_PROFILE_PATH: &str = "profiles/default.lua";
const GENERATED_PROFILE_PATH: &str = "profiles/default.toml";
const GENERATED_PROFILE_DESCRIPTION: &str = "Generated by yoi setup-model";
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -149,7 +149,7 @@ pub fn write_default_profile_config(
std::fs::create_dir_all(&profiles_dir)?;
let profile_path = config_dir.join(GENERATED_PROFILE_PATH);
std::fs::write(&profile_path, generated_profile_lua(model_ref))?;
std::fs::write(&profile_path, generated_profile_toml(model_ref))?;
let registry_path = config_dir.join("profiles.toml");
let mut document = read_registry_document(&registry_path)?;
@@ -203,65 +203,63 @@ fn set_default_profile_entry(document: &mut Value) -> Result<(), Box<dyn std::er
Ok(())
}
fn generated_profile_lua(model_ref: &str) -> String {
fn generated_profile_toml(model_ref: &str) -> String {
format!(
r#"local profile = require("yoi.profile")
local scope = require("yoi.scope")
local compact = require("yoi.compact")
r#"slug = "default"
description = "Generated by yoi setup-model"
scope = "workspace_write"
return profile {{
slug = "default",
description = "Generated by yoi setup-model",
[model]
ref = "{}"
scope = scope.workspace_write(),
[session]
record_event_trace = true
session = {{
record_event_trace = true,
}},
[engine]
reasoning = "high"
worker = {{
reasoning = "high",
}},
[compaction]
kind = "tokens"
threshold = 240000
request_threshold = 270000
worker_context_max_tokens = 100000
model = {{
ref = "{}",
}},
[feature.task]
enabled = true
compaction = compact.tokens {{
threshold = 240000,
request_threshold = 270000,
worker_context_max_tokens = 100000,
}},
[feature.memory]
enabled = true
feature = {{
task = {{ enabled = true }},
memory = {{ enabled = true }},
web = {{ enabled = true }},
workers = {{ enabled = false }},
ticket = {{ enabled = false, access = "lifecycle" }},
ticket_orchestration = {{ enabled = false }},
}},
[feature.web]
enabled = true
memory = {{
extract_threshold = 50000,
consolidation_threshold_files = 5,
consolidation_threshold_bytes = 50000,
}},
[feature.workers]
enabled = false
web = {{
enabled = true,
search = {{
provider = "brave",
api_key_secret = "web/brave/default",
}},
}},
}}
[feature.ticket]
enabled = false
access = "lifecycle"
[feature.ticket_orchestration]
enabled = false
[memory]
extract_threshold = 50000
consolidation_threshold_files = 5
consolidation_threshold_bytes = 50000
[web]
enabled = true
[web.search]
provider = "brave"
api_key_secret = "web/brave/default"
"#,
escape_lua_string(model_ref)
escape_toml_string(model_ref)
)
}
fn escape_lua_string(value: &str) -> String {
fn escape_toml_string(value: &str) -> String {
value
.chars()
.flat_map(|c| match c {
@@ -288,18 +286,18 @@ mod tests {
assert_eq!(written.registry_path, dir.path().join("profiles.toml"));
assert_eq!(
written.profile_path,
dir.path().join("profiles/default.lua")
dir.path().join("profiles/default.toml")
);
let registry = std::fs::read_to_string(&written.registry_path).unwrap();
assert!(registry.contains("default = \"user:default\""));
assert!(registry.contains("[profile.default]"));
assert!(registry.contains("path = \"profiles/default.lua\""));
assert!(registry.contains("path = \"profiles/default.toml\""));
let profile = std::fs::read_to_string(&written.profile_path).unwrap();
assert!(profile.contains("slug = \"default\""));
assert!(profile.contains("ref = \"codex-oauth/gpt-5.5\""));
assert!(profile.contains("scope = scope.workspace_write()"));
assert!(profile.contains("scope = \"workspace_write\""));
}
#[test]
@@ -308,7 +306,7 @@ mod tests {
std::fs::write(
dir.path().join("profiles.toml"),
r#"[profile.other]
path = "profiles/other.lua"
path = "profiles/other.toml"
description = "keep me"
"#,
)
@@ -318,13 +316,13 @@ description = "keep me"
let registry = std::fs::read_to_string(dir.path().join("profiles.toml")).unwrap();
assert!(registry.contains("[profile.other]"));
assert!(registry.contains("path = \"profiles/other.lua\""));
assert!(registry.contains("path = \"profiles/other.toml\""));
assert!(registry.contains("[profile.default]"));
assert!(registry.contains("default = \"user:default\""));
}
#[test]
fn escape_lua_string_escapes_quotes_and_slashes() {
assert_eq!(escape_lua_string("a\\b\"c"), "a\\\\b\\\"c");
fn escape_toml_string_escapes_quotes_and_slashes() {
assert_eq!(escape_toml_string("a\\b\"c"), "a\\\\b\\\"c");
}
}
+2 -2
View File
@@ -664,7 +664,7 @@ mod tests {
r#"
default = "coder"
[profile]
coder = "profiles/coder.lua"
coder = "profiles/coder.toml"
"#,
)
.unwrap();
@@ -692,7 +692,7 @@ coder = "profiles/coder.lua"
r#"
default = "coder"
[profile.coder]
path = "profiles/coder.lua"
path = "profiles/coder.toml"
description = "Project coder"
"#,
)
+18 -12
View File
@@ -845,15 +845,15 @@ recursive = true
external.display()
),
);
let profile = tmp.path().join("profile.lua");
let profile = tmp.path().join("profile.toml");
write(
&profile,
r#"
local yoi = require("yoi")
return yoi.profile {
slug = "override-scope",
model = { scheme = "anthropic", model_id = "test-model" },
}
slug = "override-scope"
[model]
scheme = "anthropic"
model_id = "test-model"
"#,
);
let cli = Cli::try_parse_from([
@@ -889,7 +889,7 @@ return yoi.profile {
#[test]
fn profile_uses_selected_profile() {
let tmp = TempDir::new().unwrap();
let profile = tmp.path().join("profile.lua");
let profile = tmp.path().join("profile.toml");
let cli = Cli::try_parse_from([
"yoi worker",
"--profile",
@@ -1223,8 +1223,14 @@ permission = "write"
fn profile_conflicts_with_manifest_and_restore_modes() {
let segment_id = session_store::new_segment_id().to_string();
for args in [
vec!["yoi worker", "--profile", "p.lua", "--manifest", "m.toml"],
vec!["yoi worker", "--profile", "p.lua", "--session", &segment_id],
vec!["yoi worker", "--profile", "p.toml", "--manifest", "m.toml"],
vec![
"yoi worker",
"--profile",
"p.toml",
"--session",
&segment_id,
],
] {
let err = Cli::try_parse_from(args).unwrap_err();
assert_eq!(err.kind(), clap::error::ErrorKind::ArgumentConflict);
@@ -1233,9 +1239,9 @@ permission = "write"
#[test]
fn profile_and_worker_are_independent_startup_inputs() {
let cli =
Cli::try_parse_from(["yoi worker", "--profile", "p.lua", "--worker", "agent"]).unwrap();
assert_eq!(cli.profile.as_deref(), Some("p.lua"));
let cli = Cli::try_parse_from(["yoi worker", "--profile", "p.toml", "--worker", "agent"])
.unwrap();
assert_eq!(cli.profile.as_deref(), Some("p.toml"));
assert_eq!(cli.worker.as_deref(), Some("agent"));
}
+1 -1
View File
@@ -243,7 +243,7 @@ impl ProtocolProviderContribution {
#[serde(rename_all = "snake_case")]
pub enum FeatureRuntimeKind {
Builtin,
LuaProfile,
Profile,
ExternalPlugin,
ProtocolProvider,
}
+37 -29
View File
@@ -183,7 +183,9 @@ fn parse_spawn_profile_selector(raw: Option<&str>) -> Result<SpawnProfileSelecto
|| raw.starts_with("./")
|| raw.starts_with("../")
|| raw.contains('/')
|| raw.ends_with(".lua")
|| raw.ends_with(".dcdl")
|| raw.ends_with(".json")
|| raw.ends_with(".toml")
|| raw.ends_with(".nix")
{
return Err(format!(
@@ -1181,25 +1183,31 @@ mod tests {
}
const CODER_PROFILE: &str = r#"
local profile = require("yoi.profile")
local scope = require("yoi.scope")
return profile {
slug = "coder",
model = { scheme = "anthropic", model_id = "coder-model" },
engine = { instruction = "$yoi/coder", language = "Coderish", max_tokens = 2222 },
scope = scope.workspace_write(),
}
slug = "coder"
scope = "workspace_write"
[model]
scheme = "anthropic"
model_id = "coder-model"
[engine]
instruction = "$yoi/coder"
language = "Coderish"
max_tokens = 2222
"#;
const REVIEWER_PROFILE: &str = r#"
local profile = require("yoi.profile")
local scope = require("yoi.scope")
return profile {
slug = "reviewer",
model = { scheme = "anthropic", model_id = "reviewer-model" },
engine = { instruction = "$yoi/reviewer", language = "Reviewerish", max_tokens = 3333 },
scope = scope.workspace_write(),
}
slug = "reviewer"
scope = "workspace_write"
[model]
scheme = "anthropic"
model_id = "reviewer-model"
[engine]
instruction = "$yoi/reviewer"
language = "Reviewerish"
max_tokens = 3333
"#;
#[test]
@@ -1297,8 +1305,8 @@ return profile {
&project,
Some("reviewer"),
&[
("coder", "coder.lua", CODER_PROFILE),
("reviewer", "reviewer.lua", REVIEWER_PROFILE),
("coder", "coder.toml", CODER_PROFILE),
("reviewer", "reviewer.toml", REVIEWER_PROFILE),
],
);
let parent = parent_manifest(&project, None);
@@ -1333,8 +1341,8 @@ return profile {
&project,
Some("coder"),
&[
("coder", "coder.lua", CODER_PROFILE),
("reviewer", "reviewer.lua", REVIEWER_PROFILE),
("coder", "coder.toml", CODER_PROFILE),
("reviewer", "reviewer.toml", REVIEWER_PROFILE),
],
);
let parent = parent_manifest(&project, None);
@@ -1414,7 +1422,7 @@ return profile {
let available = write_project_profile_registry(
&project,
Some("reviewer"),
&[("reviewer", "reviewer.lua", REVIEWER_PROFILE)],
&[("reviewer", "reviewer.toml", REVIEWER_PROFILE)],
);
let parent = parent_manifest(&project, None);
let scope = vec![abs_rule(&delegated, Permission::Write)];
@@ -1451,7 +1459,7 @@ return profile {
let available = write_project_profile_registry(
&project,
Some("reviewer"),
&[("reviewer", "reviewer.lua", REVIEWER_PROFILE)],
&[("reviewer", "reviewer.toml", REVIEWER_PROFILE)],
);
let parent = parent_manifest(&parent_root, Some(&parent_root.join("deny")));
let scope = vec![abs_rule(&delegated, Permission::Read)];
@@ -1497,12 +1505,12 @@ return profile {
let available = write_project_profile_registry(
&project,
None,
&[("coder", "coder.lua", CODER_PROFILE)],
&[("coder", "coder.toml", CODER_PROFILE)],
);
let parent = parent_manifest(&project, None);
let scope = vec![abs_rule(&project, Permission::Read)];
let invalid = parse_spawn_profile_selector(Some("./reviewer.lua"))
let invalid = parse_spawn_profile_selector(Some("./reviewer.toml"))
.map_err(|msg| format!("{msg}{}", available.error_suffix()))
.unwrap_err();
assert!(invalid.contains("Use `default`, `inherit`"));
@@ -1521,7 +1529,7 @@ return profile {
assert!(default_config.contains("\"name\":\"child\""));
let user_config = tmp.path().join("user-profiles.toml");
std::fs::write(&user_config, "[profile]\ncoder = \"user-coder.lua\"\n").unwrap();
std::fs::write(&user_config, "[profile]\ncoder = \"user-coder.toml\"\n").unwrap();
let project_config = project.join(".yoi/profiles.toml");
let ambiguous = AvailableProfiles {
registry: Some(
@@ -1550,9 +1558,9 @@ return profile {
#[test]
fn spawn_profile_selector_rejects_path_like_values() {
for raw in [
"./reviewer.lua",
"path:./reviewer.lua",
"/tmp/reviewer.lua",
"./reviewer.toml",
"path:./reviewer.toml",
"/tmp/reviewer.toml",
"legacy.nix",
] {
let err = parse_spawn_profile_selector(Some(raw)).unwrap_err();
+2 -2
View File
@@ -1528,7 +1528,7 @@ mod tests {
(
vec![
"--profile".to_string(),
"p.lua".to_string(),
"p.toml".to_string(),
"--session".to_string(),
segment_id,
],
@@ -1537,7 +1537,7 @@ mod tests {
(
vec![
"--profile".to_string(),
"p.lua".to_string(),
"p.toml".to_string(),
"--socket".to_string(),
"/tmp/yoi/sock".to_string(),
],
+44 -39
View File
@@ -1076,34 +1076,37 @@ mod tests {
let tmp = TempDir::new().unwrap();
let workspace = tmp.path().join("workspace");
std::fs::create_dir(&workspace).unwrap();
let profile = write_profile(tmp.path(), "mcp.lua", body);
let profile = write_profile(tmp.path(), "mcp.toml", body);
(tmp, workspace, profile)
}
fn mcp_profile() -> String {
r#"
local profile = require("yoi.profile")
return profile {
slug = "mcp-test",
model = { scheme = "anthropic", model_id = "claude-sonnet-4-20250514" },
mcp = {
stdio_server = {
{
name = "filesystem",
command = "definitely-not-spawned-during-cli-inspection",
args = { "--root", ".", "--token", "ARG_SECRET_DO_NOT_PRINT" },
env = {
inherit = { "PATH" },
set = {
SAFE_MODE = { kind = "literal", value = "SUPER_SECRET_LITERAL_DO_NOT_PRINT" },
API_TOKEN = { kind = "secret_ref", ref = "providers/mcp-token" },
FROM_ENV = { kind = "env_ref", name = "SECRET_ENV_NAME_DO_NOT_PRINT" },
},
},
},
},
},
}
slug = "mcp-test"
[model]
scheme = "anthropic"
model_id = "claude-sonnet-4-20250514"
[[mcp.stdio_server]]
name = "filesystem"
command = "definitely-not-spawned-during-cli-inspection"
args = ["--root", ".", "--token", "ARG_SECRET_DO_NOT_PRINT"]
[mcp.stdio_server.env]
inherit = ["PATH"]
[mcp.stdio_server.env.set.SAFE_MODE]
kind = "literal"
value = "SUPER_SECRET_LITERAL_DO_NOT_PRINT"
[mcp.stdio_server.env.set.API_TOKEN]
kind = "secret_ref"
ref = "providers/mcp-token"
[mcp.stdio_server.env.set.FROM_ENV]
kind = "env_ref"
name = "SECRET_ENV_NAME_DO_NOT_PRINT"
"#
.to_string()
}
@@ -1194,17 +1197,19 @@ return profile {
#[test]
fn invalid_config_is_reported_as_invalid_not_silently_empty() {
let body = r#"
local profile = require("yoi.profile")
return profile {
slug = "bad-mcp",
model = { scheme = "anthropic", model_id = "claude-sonnet-4-20250514" },
mcp = {
stdio_server = {
{ name = "dup", command = "one" },
{ name = "dup", command = "two" },
},
},
}
slug = "bad-mcp"
[model]
scheme = "anthropic"
model_id = "claude-sonnet-4-20250514"
[[mcp.stdio_server]]
name = "dup"
command = "one"
[[mcp.stdio_server]]
name = "dup"
command = "two"
"#;
let (_tmp, workspace, profile) = workspace_and_profile(body);
let output = render_list(&args(&workspace, &profile, true)).unwrap();
@@ -1218,11 +1223,11 @@ return profile {
#[test]
fn human_output_distinguishes_empty_and_unavailable() {
let body = r#"
local profile = require("yoi.profile")
return profile {
slug = "empty-mcp",
model = { scheme = "anthropic", model_id = "claude-sonnet-4-20250514" },
}
slug = "empty-mcp"
[model]
scheme = "anthropic"
model_id = "claude-sonnet-4-20250514"
"#;
let (_tmp, workspace, profile) = workspace_and_profile(body);
let output = render_list(&args(&workspace, &profile, false)).unwrap();