config: add singleton UserInstructions declarations

This commit is contained in:
Adam Perry
2026-07-06 21:21:09 +00:00
parent 32d15fae79
commit 7df31eacac
13 changed files with 288 additions and 16 deletions
@@ -408,6 +408,7 @@ fn map_hooks_requirements_to_api(hooks: ManagedHooksRequirementsToml) -> Managed
pre_compact,
post_compact,
session_start,
user_instructions,
user_prompt_submit,
subagent_start,
subagent_stop,
@@ -423,6 +424,7 @@ fn map_hooks_requirements_to_api(hooks: ManagedHooksRequirementsToml) -> Managed
pre_compact: map_hook_matcher_groups_to_api(pre_compact),
post_compact: map_hook_matcher_groups_to_api(post_compact),
session_start: map_hook_matcher_groups_to_api(session_start),
user_instructions: user_instructions.map(map_hook_handler_to_api),
user_prompt_submit: map_hook_matcher_groups_to_api(user_prompt_submit),
subagent_start: map_hook_matcher_groups_to_api(subagent_start),
subagent_stop: map_hook_matcher_groups_to_api(subagent_stop),
@@ -574,9 +576,14 @@ fn config_write_error(code: ConfigWriteErrorCode, message: impl Into<String>) ->
#[cfg(test)]
mod tests {
use super::map_requirements_toml_to_api;
use codex_app_server_protocol::ConfiguredHookHandler;
use codex_app_server_protocol::ManagedHooksRequirements;
use codex_app_server_protocol::WindowsSandboxSetupMode;
use codex_config::ComputerUseRequirementsToml;
use codex_config::ConfigRequirementsToml;
use codex_config::HookEventsToml;
use codex_config::HookHandlerConfig;
use codex_config::ManagedHooksRequirementsToml;
use codex_config::ModelsRequirementsToml;
use codex_config::NewThreadModelDefaultsToml;
use codex_config::WindowsRequirementsToml;
@@ -595,6 +602,51 @@ mod tests {
assert_eq!(mapped.hooks, None);
}
#[test]
fn requirements_api_includes_user_instructions_hooks() {
let mapped = map_requirements_toml_to_api(ConfigRequirementsToml {
hooks: Some(ManagedHooksRequirementsToml {
hooks: HookEventsToml {
user_instructions: Some(HookHandlerConfig::Command {
command: "python3 instructions.py".to_string(),
command_windows: None,
timeout_sec: Some(10),
r#async: false,
status_message: Some("loading instructions".to_string()),
}),
..HookEventsToml::default()
},
..ManagedHooksRequirementsToml::default()
}),
..ConfigRequirementsToml::default()
});
assert_eq!(
mapped.hooks,
Some(ManagedHooksRequirements {
managed_dir: None,
windows_managed_dir: None,
pre_tool_use: Vec::new(),
permission_request: Vec::new(),
post_tool_use: Vec::new(),
pre_compact: Vec::new(),
post_compact: Vec::new(),
session_start: Vec::new(),
user_instructions: Some(ConfiguredHookHandler::Command {
command: "python3 instructions.py".to_string(),
command_windows: None,
timeout_sec: Some(10),
r#async: false,
status_message: Some("loading instructions".to_string()),
}),
user_prompt_submit: Vec::new(),
subagent_start: Vec::new(),
subagent_stop: Vec::new(),
stop: Vec::new(),
})
);
}
#[test]
fn requirements_api_includes_permission_default_and_allowlist() {
let mapped = map_requirements_toml_to_api(ConfigRequirementsToml {