-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Harden shared agent instruction review #4220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shellz-n-stuff
wants to merge
8
commits into
block:main
Choose a base branch
from
shellz-n-stuff:codex/harden-shared-agent-instructions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e447783
fix(desktop): harden shared agent instructions
shellz-n-stuff fd739b4
test(desktop): cover shared agent instruction safety
shellz-n-stuff 1cbc460
fix(desktop): validate managed-agent sync definitions
shellz-n-stuff 238570f
fix(desktop): harden shared agent catalog
shellz-n-stuff 0140086
test(desktop): scope catalog signing identity
shellz-n-stuff 8c7db2f
test(desktop): sign catalog publication fixtures
shellz-n-stuff 683c340
fix(desktop): validate standalone agent definitions
shellz-n-stuff e19bf1e
refactor(desktop): split agent definition validation
shellz-n-stuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
desktop/src-tauri/src/commands/managed_agent_definition.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| //! Managed-agent definition validation at local mutation boundaries. | ||
|
|
||
| use crate::managed_agents::{CreateManagedAgentRequest, ManagedAgentRecord}; | ||
|
|
||
| pub(super) fn validate_create_definition( | ||
| name: &str, | ||
| persona_id: Option<&str>, | ||
| input: &CreateManagedAgentRequest, | ||
| ) -> Result<(), String> { | ||
| validate_definition_fields(name, persona_id, input.system_prompt.as_deref()) | ||
| } | ||
|
|
||
| fn validate_definition_fields( | ||
| name: &str, | ||
| persona_id: Option<&str>, | ||
| system_prompt: Option<&str>, | ||
| ) -> Result<(), String> { | ||
| crate::managed_agents::validate_managed_agent_definition_text(name, persona_id, system_prompt) | ||
| .map_err(|error| format!("Managed agent definition is unsafe: {error}")) | ||
| } | ||
|
|
||
| /// Apply definition-owned update fields, then validate the complete | ||
| /// prospective definition before the caller can persist it. | ||
| pub(super) fn apply_model_provider_prompt_update( | ||
| record: &mut ManagedAgentRecord, | ||
| model: Option<Option<String>>, | ||
| provider: Option<Option<String>>, | ||
| system_prompt: Option<Option<String>>, | ||
| ) -> Result<(), String> { | ||
| if record.persona_id.is_none() { | ||
| if let Some(model_update) = model { | ||
| record.model = model_update; | ||
| } | ||
| if let Some(provider_update) = provider { | ||
| record.provider = provider_update; | ||
| } | ||
| if let Some(prompt_update) = system_prompt { | ||
| record.system_prompt = prompt_update; | ||
| } | ||
| } | ||
|
|
||
| validate_definition_fields( | ||
| &record.name, | ||
| record.persona_id.as_deref(), | ||
| record.system_prompt.as_deref(), | ||
| ) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn standalone_record() -> ManagedAgentRecord { | ||
| serde_json::from_value(serde_json::json!({ | ||
| "pubkey": "standalone1", | ||
| "name": "standalone-agent", | ||
| "private_key_nsec": "nsec1fake", | ||
| "relay_url": "wss://localhost:3000", | ||
| "acp_command": "buzz-acp", | ||
| "agent_command": "goose", | ||
| "agent_args": [], | ||
| "mcp_command": "", | ||
| "turn_timeout_seconds": 320, | ||
| "system_prompt": "safe prompt", | ||
| "model": null, | ||
| "provider": null, | ||
| "env_vars": {}, | ||
| "created_at": "2026-01-01T00:00:00Z", | ||
| "updated_at": "2026-01-01T00:00:00Z", | ||
| "last_started_at": null, | ||
| "last_stopped_at": null, | ||
| "last_exit_code": null, | ||
| "last_error": null | ||
| })) | ||
| .expect("standalone agent record") | ||
| } | ||
|
|
||
| fn create_request(system_prompt: &str) -> CreateManagedAgentRequest { | ||
| serde_json::from_value(serde_json::json!({ | ||
| "name": "Reviewer", | ||
| "systemPrompt": system_prompt | ||
| })) | ||
| .expect("create request") | ||
| } | ||
|
|
||
| #[test] | ||
| fn create_rejects_invisible_definition_less_name_or_prompt() { | ||
| for (name, prompt, code) in [ | ||
| ("Review\u{200B}er", "Review code.", "U+200B"), | ||
| ("Reviewer", "Review\u{202E} code.", "U+202E"), | ||
| ] { | ||
| let input = create_request(prompt); | ||
| let error = validate_create_definition(name, None, &input) | ||
| .expect_err("create must reject unsafe definition text"); | ||
| assert!(error.contains(code), "unexpected error: {error}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn create_accepts_visible_multiline_definition_less_prompt() { | ||
| let input = create_request("Review changes.\n\tCall out security risks."); | ||
| validate_create_definition("Reviewer 🐝", None, &input) | ||
| .expect("visible multiline instructions should remain valid"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn update_rejects_invisible_definition_less_name_or_prompt() { | ||
| let mut unsafe_prompt = standalone_record(); | ||
| let error = apply_model_provider_prompt_update( | ||
| &mut unsafe_prompt, | ||
| None, | ||
| None, | ||
| Some(Some("Review\u{200B} code.".to_string())), | ||
| ) | ||
| .expect_err("definition-less prompt update must reject invisible text"); | ||
| assert!(error.contains("U+200B"), "unexpected error: {error}"); | ||
|
|
||
| let mut unsafe_name = standalone_record(); | ||
| unsafe_name.name = "Review\u{202E}er".to_string(); | ||
| let error = apply_model_provider_prompt_update(&mut unsafe_name, None, None, None) | ||
| .expect_err("definition-less name update must reject formatting controls"); | ||
| assert!(error.contains("U+202E"), "unexpected error: {error}"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.