winx_code_agent/utils/
orchestration.rs1use std::fmt::Write as _;
2
3const DEFAULT_INSTRUCTIONS: &str = "Initialize Winx once for the intended workspace and preserve the returned thread_id. Treat structuredContent.status as the authoritative tool state. Never repeat a failed tool call unchanged: execute next_action and every required_read first. Use CodeMap to locate code, then batch ReadFiles calls. Read every target file and required range before editing. Use MultiFileEdit for atomic cross-file changes. Compose related finite fail-fast checks in one BashCommand with &&. When an edit tool exposes verify_command, use it for a quick finite post-edit check in the same round trip; the edit remains applied if verification fails. BashCommand defaults to wait_policy=adaptive; use until_complete for finite long commands and return_early when prompt control matters. Call status_check only when status is running. Do not automatically approve interactive prompts that change permissions, data, or system state.";
4
5const DISALLOW_INSTRUCTION: &str = "As soon as you encounter \"The user has chosen to disallow the tool call.\", immediately stop doing everything and ask the user for the reason.";
6
7pub fn server_instructions() -> String {
11 let mut instructions = format!("{DEFAULT_INSTRUCTIONS}\n\n{DISALLOW_INSTRUCTION}");
12 if let Some(extra) = crate::config::env_text("WINX_SERVER_INSTRUCTIONS") {
13 let _ = write!(instructions, "\n\nOperator instructions:\n{extra}");
14 }
15 instructions
16}
17
18pub fn append_initialize_instructions(response: &mut String) {
21 let _ = write!(response, "\n# Winx orchestration contract\n{}\n", server_instructions());
22}
23
24#[cfg(test)]
25mod tests {
26 use super::server_instructions;
27
28 #[test]
29 fn default_contract_names_structured_recovery_before_optional_operator_text() {
30 let instructions = server_instructions();
31 let prefix = instructions.chars().take(512).collect::<String>();
32 assert!(prefix.contains("structuredContent.status"));
33 assert!(prefix.contains("Never repeat a failed tool call unchanged"));
34 assert!(prefix.contains("required_read"));
35 }
36}