1#![allow(
2 missing_docs,
3 dead_code,
4 unused_imports,
5 reason = "Intentional compatibility, platform, or test-only suppression."
6)]
7
8#![recursion_limit = "256"]
11use serde_json::{Value, json};
12
13mod collaboration;
14mod json_schema;
15#[cfg(feature = "mcp")]
16mod mcp_tool;
17mod responses_api;
18mod tool_kind;
19
20pub use collaboration::{
21 AGENT_DESCRIPTION, SUBAGENT_REASONING_EFFORT_VALUES, agent_parameters, close_agent_parameters,
22 request_user_input_description, request_user_input_parameters, resume_agent_parameters, send_input_parameters,
23 spawn_agent_parameters, spawn_background_subprocess_parameters, wait_agent_parameters,
24};
25pub use json_schema::{AdditionalProperties, JsonSchema, parse_tool_input_schema};
26#[cfg(feature = "mcp")]
27pub use mcp_tool::{ParsedMcpTool, parse_mcp_tool};
28pub use responses_api::{FreeformTool, FreeformToolFormat, ResponsesApiTool};
29pub(crate) use tool_kind::{CanonicalToolMeta, TokenBucket, ToolKind, ToolNamespace};
30
31pub const SEMANTIC_ANCHOR_GUIDANCE: &str =
32 "Prefer stable semantic @@ anchors such as function, class, method, or impl names.";
33
34pub const APPLY_PATCH_ALIAS_DESCRIPTION: &str = "Alias for 'input': same VT Code patch envelope (*** Begin Patch … *** End Patch); unified diffs (---/+++ format) are rejected.";
42pub const DEFAULT_APPLY_PATCH_INPUT_DESCRIPTION: &str = "Patch in VT Code format: *** Begin Patch, *** Update File: path, @@ hunk, -/+ lines, *** End Patch. Every patch path must be workspace-relative; absolute paths, `..`, and traversal-like forms are rejected.";
43pub const APPLY_PATCH_TOOL_DESCRIPTION: &str = "Apply a patch in VT Code format (*** Begin Patch / *** Update File: path / @@ hunks with -/+ lines / *** End Patch); standard unified diffs (---/+++ format) are rejected. *** Add File: path, *** Delete File: path, and *** Move to: path (after *** Update File) are also supported. Every patch path must be workspace-relative; absolute paths, `..`, and traversal-like forms are rejected. Changes are applied after permission checks.";
49
50pub const DEFAULT_MAX_OUTPUT_TOKENS: usize = 10_000;
52pub const MIN_MAX_OUTPUT_TOKENS: usize = 1;
54pub const MAX_MAX_OUTPUT_TOKENS: usize = 50_000;
56pub const MAX_OUTPUT_TOKENS_FIELD: &str = "max_output_tokens";
61
62#[must_use]
68pub fn with_max_output_tokens_parameter(mut schema: Value) -> Value {
69 let Some(schema_object) = schema.as_object_mut() else {
70 return schema;
71 };
72 let properties = schema_object
73 .entry("properties")
74 .or_insert_with(|| Value::Object(serde_json::Map::new()));
75 let Some(properties_object) = properties.as_object_mut() else {
76 return schema;
77 };
78 {
79 let _entry = properties_object.entry(MAX_OUTPUT_TOKENS_FIELD).or_insert_with(|| {
80 json!({
81 "type": "integer",
82 "minimum": MIN_MAX_OUTPUT_TOKENS,
83 "maximum": MAX_MAX_OUTPUT_TOKENS,
84 "default": DEFAULT_MAX_OUTPUT_TOKENS,
85 "description": "Maximum number of result tokens returned to the model. Full oversized output is spooled when available."
86 })
87 });
88 }
89 schema
90}
91
92#[must_use]
93pub fn with_semantic_anchor_guidance(base: &str) -> String {
94 let trimmed = base.trim_end();
95 if trimmed.contains(SEMANTIC_ANCHOR_GUIDANCE) {
96 trimmed.to_string()
97 } else if trimmed.ends_with('.') {
98 format!("{trimmed} {SEMANTIC_ANCHOR_GUIDANCE}")
99 } else {
100 format!("{trimmed}. {SEMANTIC_ANCHOR_GUIDANCE}")
101 }
102}
103
104#[must_use]
105pub fn apply_patch_parameter_schema(input_description: &str) -> Value {
106 json!({
107 "type": "object",
108 "properties": {
109 "input": {
110 "type": "string",
111 "description": with_semantic_anchor_guidance(input_description)
112 },
113 "patch": {
114 "type": "string",
115 "description": with_semantic_anchor_guidance(APPLY_PATCH_ALIAS_DESCRIPTION)
116 }
117 },
118 "anyOf": [
119 {"required": ["input"]},
120 {"required": ["patch"]}
121 ]
122 })
123}
124
125#[must_use]
126pub fn apply_patch_parameters() -> Value {
127 apply_patch_parameter_schema(DEFAULT_APPLY_PATCH_INPUT_DESCRIPTION)
128}
129
130#[must_use]
131pub fn cron_parameters() -> Value {
132 json!({
133 "type": "object",
134 "required": ["action"],
135 "additionalProperties": false,
136 "properties": {
137 "action": {
138 "type": "string",
139 "enum": ["create", "list", "delete"],
140 "description": "create: schedule a prompt (requires prompt and exactly one of cron, delay_minutes, or run_at). list: show scheduled prompts. delete: remove one by id."
141 },
142 "prompt": {"type": "string", "description": "create: prompt to run when the task fires."},
143 "name": {"type": "string", "description": "create: optional short label for the task."},
144 "cron": {"type": "string", "description": "create: five-field cron expression for recurring tasks."},
145 "delay_minutes": {"type": "integer", "description": "create: fixed recurring interval in minutes."},
146 "run_at": {"type": "string", "description": "create: one-shot fire time in RFC3339 or local datetime form."},
147 "id": {"type": "string", "description": "delete: session scheduled task id to delete."}
148 }
149 })
150}
151
152pub const MCP_DESCRIPTION: &str = "Discover and manage Model Context Protocol capabilities. Use action=search_tools to find tools, action=get_tool_details to fetch one schema, action=list_servers to inspect configured servers, or action=connect and action=disconnect to manage a named server. action=search_tools searches only tools exposed by configured MCP servers; the separate search_tools tool searches the whole session catalog, including deferred built-in tools. Do not disconnect a server while one of its tool calls is active.";
154
155#[must_use]
156pub fn mcp_parameters() -> Value {
157 json!({
158 "type": "object",
159 "required": ["action"],
160 "properties": {
161 "action": {
162 "type": "string",
163 "enum": ["search_tools", "get_tool_details", "list_servers", "connect", "disconnect"],
164 "description": "search_tools: find MCP tools by natural-language query. get_tool_details: fetch the full input schema for one MCP tool name. list_servers: list configured servers and their connection state. connect or disconnect: manage one configured MCP server by name."
165 },
166 "query": {"type": "string", "description": "search_tools: natural language query describing the MCP capability to find."},
167 "detail_level": {"type": "string", "enum": ["name", "name_description", "full"], "description": "search_tools: response detail level."},
168 "limit": {"type": "integer", "minimum": 1, "maximum": 25, "description": "search_tools: maximum number of results to return."},
169 "name": {"type": "string", "description": "get_tool_details: exact MCP tool name. connect or disconnect: configured MCP server name."}
170 },
171 "additionalProperties": false
172 })
173}
174
175#[must_use]
176pub fn cron_create_parameters() -> Value {
177 json!({
178 "type": "object",
179 "required": ["prompt"],
180 "additionalProperties": false,
181 "properties": {
182 "prompt": {"type": "string", "description": "Prompt to run when the task fires."},
183 "name": {"type": "string", "description": "Optional short label for the task."},
184 "cron": {"type": "string", "description": "Five-field cron expression for recurring tasks."},
185 "delay_minutes": {"type": "integer", "description": "Fixed recurring interval in minutes."},
186 "run_at": {
187 "type": "string",
188 "description": "One-shot fire time in RFC3339 or local datetime form. Use this instead of `cron` or `delay_minutes` for reminders."
189 }
190 }
191 })
192}
193
194#[must_use]
195pub fn cron_list_parameters() -> Value {
196 json!({
197 "type": "object",
198 "properties": {},
199 "additionalProperties": false
200 })
201}
202
203#[must_use]
204pub fn cron_delete_parameters() -> Value {
205 json!({
206 "type": "object",
207 "required": ["id"],
208 "properties": {
209 "id": {"type": "string", "description": "Session scheduled task id to delete."}
210 }
211 })
212}
213
214pub const EXEC_COMMAND_DESCRIPTION: &str = "Run a shell command through the active sandbox policy and permission checks. Put normal shell tools such as ls, rg, find, cat, sed, awk, build tools, and test tools in cmd. Returns output, exit status, and a reusable session id when the command is still running. For file edits, use apply_patch instead of shell redirection or in-place editors such as `sed -i`. Expanded sandbox_permissions modes trigger an approval check before the command runs; `require_escalated` and `bypass_sandbox` also need a non-empty justification.";
216
217#[must_use]
218pub fn exec_command_parameters() -> Value {
219 json!({
220 "type": "object",
221 "required": ["cmd"],
222 "properties": {
223 "cmd": {"type": "string", "description": "Shell command to execute, subject to command policy. The tool description lists covered tools."},
224 "yield_time_ms": {"type": "integer", "description": "Wait before returning output (ms). If the command is still running, the response includes a session_id for write_stdin. Values above 10000 turn this into a single-call long run: no outer timeout applies and the response returns after the yield window or command exit, whichever is first.", "default": 10000},
225 "background": {"type": "boolean", "description": "Start a retained background process and return after a bounded initial output window. At most three live background processes are allowed per VT Code runtime; use the returned session_id with write_stdin to wait, poll, write, inspect, terminate, or close.", "default": false},
226 "max_output_tokens": {"type": "integer", "minimum": 1, "maximum": 50000, "default": 10000, "description": "Output token cap. Large or truncated output can return a spool_path; an active session may set spool_complete=false for a readable partial snapshot, while an exited pending spool is withheld until a later wait."},
227 "workdir": {"type": "string", "description": "Working directory."},
228 "tty": {"type": "boolean", "description": "Run the command in PTY mode for interactive or terminal-sensitive commands.", "default": false},
229 "sandbox_permissions": {
230 "type": "string",
231 "enum": ["use_default", "with_additional_permissions", "require_escalated", "bypass_sandbox"],
232 "description": "Sandbox permission mode for this command. Omit it or use `use_default` for the normal sandbox. Non-empty `additional_permissions` is normalized to `with_additional_permissions`. `require_escalated` and `bypass_sandbox` require a non-empty `justification` and cannot be combined with `additional_permissions`.",
233 "default": "use_default"
234 },
235 "additional_permissions": {
236 "type": "object",
237 "description": "Optional extra filesystem roots to grant inside the sandbox. Non-empty `additional_permissions` implicitly requests `with_additional_permissions`; every path is normalized and must stay within allowed workspace or temp roots.",
238 "properties": {
239 "fs_read": {"type": "array", "items": {"type": "string"}},
240 "fs_write": {"type": "array", "items": {"type": "string"}}
241 },
242 "additionalProperties": false
243 },
244 "justification": {"type": "string", "description": "Short approval question for expanded sandbox scope. Required when sandbox_permissions is `require_escalated` or `bypass_sandbox`."}
245 },
246 "additionalProperties": false
247 })
248}
249
250#[must_use]
251pub fn write_stdin_parameters() -> Value {
252 json!({
253 "type": "object",
254 "required": ["session_id"],
255 "properties": {
256 "session_id": {"type": "string", "description": "Active execution session id."},
257 "action": {"type": "string", "enum": ["write", "poll", "wait"], "description": "Use wait to block until the command exits or wait_timeout_seconds expires; wait never kills the session."},
258 "chars": {"type": "string", "description": "Bytes to write to stdin. Pass an empty string to poll without sending input."},
259 "yield_time_ms": {"type": "integer", "description": "Wait before returning fresh session output (ms).", "default": 1000},
260 "wait_timeout_seconds": {"type": "integer", "minimum": 1, "description": "Explicit wait deadline in seconds. A deadline returns an in-progress session that can be waited on again."},
261 "max_output_tokens": {"type": "integer", "minimum": 1, "maximum": 50000, "default": 10000, "description": "Output token cap for the continuation response. Large or truncated output can return a spool_path; the response reports whether an active session has finished writing it."}
262 },
263 "anyOf": [
264 {"required": ["chars"]},
265 {"required": ["action"], "properties": {"action": {"const": "wait"}}}
266 ],
267 "additionalProperties": false
268 })
269}
270
271pub const SEARCH_TOOLS_DESCRIPTION: &str = "Search the session tool catalog by capability and return ranked matches. Use it to find tools whose definitions are deferred and not yet sent to you, such as code_search, web_fetch, web_search, cron, and MCP server tools. Deferred matches are listed in `expanded_for_next_segment` and become callable on the next request. It is not needed for tools already defined in the current request; call those directly.";
273
274#[must_use]
275pub fn search_tools_parameters() -> Value {
276 with_max_output_tokens_parameter(json!({
277 "type": "object",
278 "required": ["query"],
279 "properties": {
280 "query": {
281 "type": "string",
282 "minLength": 1,
283 "description": "Natural-language description of the capability to discover."
284 },
285 "limit": {
286 "type": "integer",
287 "minimum": 1,
288 "maximum": 25,
289 "default": 5,
290 "description": "Maximum number of ranked matches to return (default: 5, max: 25)."
291 },
292 "detail_level": {
293 "type": "string",
294 "enum": ["name", "name_description", "full"],
295 "default": "name_description",
296 "description": "Fields returned per match (default: name_description). name returns the tool name and score; name_description adds the description; full also adds the parameter schema."
297 }
298 },
299 "additionalProperties": false
300 }))
301}
302
303#[must_use]
304pub fn code_search_parameters() -> Value {
305 json!({
306 "type": "object",
307 "required": ["query"],
308 "additionalProperties": false,
309 "properties": {
310 "query": {
311 "type": "string",
312 "minLength": 1,
313 "pattern": "\\S",
314 "description": "Literal code or path query. Smart-case applies to content and exact symbol-name matching: a wholly lower-case query matches case-insensitively, while an upper-case character makes matching case-sensitive. Path matching remains fuzzy and case-insensitive."
315 },
316 "path": {
317 "type": "string",
318 "minLength": 1,
319 "pattern": "\\S",
320 "description": "Workspace-relative file or directory to search. Omit to search the workspace root."
321 },
322 "file_types": {
323 "type": "array",
324 "minItems": 1,
325 "items": {
326 "type": "string",
327 "minLength": 1,
328 "pattern": "\\S"
329 },
330 "description": "Language names or common file extensions, with or without one leading dot."
331 },
332 "result_types": {
333 "type": "array",
334 "minItems": 1,
335 "items": {
336 "type": "string",
337 "enum": ["definition", "usage", "text", "path"]
338 },
339 "description": "Result categories to include. Omit to include all four categories."
340 },
341 "max_results": {
342 "type": "integer",
343 "minimum": 1,
344 "maximum": 100,
345 "description": "Maximum number of merged results to return. Omit for 20."
346 }
347 }
348 })
349}
350
351#[must_use]
352pub fn list_files_parameters() -> Value {
353 json!({
354 "type": "object",
355 "properties": {
356 "path": {"type": "string", "description": "Directory or file path to inspect.", "default": "."},
357 "mode": {
358 "type": "string",
359 "enum": ["list", "recursive", "tree", "find_name", "find_content", "largest", "file", "files"],
360 "description": "Listing mode. Use page/per_page to continue paginated results.",
361 "default": "list"
362 },
363 "pattern": {"type": "string", "description": "Optional glob-style path filter."},
364 "name_pattern": {"type": "string", "description": "Optional name filter for list/find_name modes."},
365 "content_pattern": {"type": "string", "description": "Content query for find_content mode."},
366 "page": {"type": "integer", "description": "1-indexed results page.", "minimum": 1},
367 "per_page": {"type": "integer", "description": "Items per page.", "minimum": 1},
368 "max_results": {"type": "integer", "description": "Maximum total results to consider before pagination.", "minimum": 1},
369 "include_hidden": {"type": "boolean", "description": "Include dotfiles and hidden entries.", "default": false},
370 "response_format": {"type": "string", "enum": ["concise", "detailed"], "description": "Verbosity of the listing output.", "default": "concise"},
371 "case_sensitive": {"type": "boolean", "description": "Case-sensitive name matching.", "default": false}
372 }
373 })
374}
375
376#[cfg(test)]
377mod tests {
378 use serde_json::json;
379
380 use super::*;
381
382 #[test]
383 fn apply_patch_parameter_schema_keeps_alias_and_guidance_consistent() {
384 let schema = apply_patch_parameter_schema("Patch in VT Code format");
385
386 assert_eq!(
390 schema["properties"]["patch"]["description"],
391 with_semantic_anchor_guidance(APPLY_PATCH_ALIAS_DESCRIPTION)
392 );
393 let patch_description = schema["properties"]["patch"]["description"]
394 .as_str()
395 .expect("patch description");
396 assert!(patch_description.contains("*** Begin Patch"));
397 assert!(patch_description.contains("unified diff"));
398 assert!(patch_description.contains(SEMANTIC_ANCHOR_GUIDANCE));
399
400 let input_description = schema["properties"]["input"]["description"]
401 .as_str()
402 .expect("input description");
403 assert!(input_description.contains(SEMANTIC_ANCHOR_GUIDANCE));
404 }
405
406 #[test]
407 fn search_tools_schema_documents_limit_and_detail_level_defaults() {
408 let schema = search_tools_parameters();
409 let limit = &schema["properties"]["limit"];
410 assert_eq!(limit["default"], json!(5));
411 assert_eq!(limit["maximum"], json!(25));
412 let limit_description = limit["description"].as_str().expect("limit description");
413 assert!(limit_description.contains("default: 5"));
414 assert!(limit_description.contains("max: 25"));
415
416 let detail_level = &schema["properties"]["detail_level"];
417 assert_eq!(detail_level["default"], json!("name_description"));
418 let detail_description = detail_level["description"].as_str().expect("detail_level description");
419 for level in ["name", "name_description", "full"] {
420 assert!(detail_description.contains(level), "{level}");
421 }
422
423 assert!(SEARCH_TOOLS_DESCRIPTION.contains("deferred"));
424 assert!(SEARCH_TOOLS_DESCRIPTION.contains("next request"));
425 assert!(SEARCH_TOOLS_DESCRIPTION.contains("MCP"));
426 assert!(SEARCH_TOOLS_DESCRIPTION.contains("not needed"));
427 }
428
429 #[test]
430 fn apply_patch_tool_description_leads_with_format_and_stays_calm() {
431 assert!(APPLY_PATCH_TOOL_DESCRIPTION.starts_with("Apply a patch in VT Code format (*** Begin Patch"));
432 assert!(APPLY_PATCH_TOOL_DESCRIPTION.contains("unified diffs"));
433 assert!(APPLY_PATCH_TOOL_DESCRIPTION.contains("workspace-relative"));
434 assert!(APPLY_PATCH_TOOL_DESCRIPTION.contains("permission checks"));
435 for description in [
436 APPLY_PATCH_TOOL_DESCRIPTION,
437 APPLY_PATCH_ALIAS_DESCRIPTION,
438 DEFAULT_APPLY_PATCH_INPUT_DESCRIPTION,
439 ] {
440 assert!(!description.contains("IMPORTANT"), "{description}");
441 assert!(!description.contains("NOT"), "{description}");
442 assert!(!description.contains("never"), "{description}");
443 }
444 }
445
446 #[test]
447 fn common_output_limit_parameter_preserves_strict_schema() {
448 let schema = with_max_output_tokens_parameter(json!({
449 "type": "object",
450 "properties": {"query": {"type": "string"}},
451 "additionalProperties": false
452 }));
453 assert_eq!(schema["additionalProperties"], json!(false));
454 assert_eq!(schema["properties"]["max_output_tokens"]["default"], json!(DEFAULT_MAX_OUTPUT_TOKENS));
455 assert_eq!(schema["properties"]["max_output_tokens"]["minimum"], json!(MIN_MAX_OUTPUT_TOKENS));
456 assert_eq!(schema["properties"]["max_output_tokens"]["maximum"], json!(MAX_MAX_OUTPUT_TOKENS));
457 }
458
459 #[test]
460 fn codex_baseline_exec_schemas_use_public_names_shape() {
461 let exec_params = exec_command_parameters();
462 assert_eq!(exec_params["required"], json!(["cmd"]));
463 assert!(exec_params["properties"]["cmd"].is_object());
464 assert!(exec_params["properties"]["workdir"].is_object());
465 assert!(
466 exec_params["properties"]["yield_time_ms"]["description"]
467 .as_str()
468 .expect("exec yield description")
469 .contains("session_id")
470 );
471 assert!(
472 exec_params["properties"]["yield_time_ms"]["description"]
473 .as_str()
474 .expect("exec yield description")
475 .contains("single-call long run")
476 );
477 assert!(
478 exec_params["properties"]["max_output_tokens"]["description"]
479 .as_str()
480 .expect("exec max output description")
481 .contains("spool_path")
482 );
483 assert_eq!(exec_params["properties"]["tty"]["type"], "boolean");
484 assert_eq!(exec_params["properties"]["tty"]["default"], false);
485 assert_eq!(exec_params["properties"]["background"]["type"], "boolean");
486 assert_eq!(exec_params["properties"]["background"]["default"], false);
487 assert_eq!(exec_params["properties"]["yield_time_ms"]["default"], 10000);
488 assert_eq!(
489 exec_params["properties"]["sandbox_permissions"]["enum"],
490 json!([
491 "use_default",
492 "with_additional_permissions",
493 "require_escalated",
494 "bypass_sandbox"
495 ])
496 );
497 assert_eq!(exec_params["properties"]["sandbox_permissions"]["default"], "use_default");
498 assert_eq!(
499 exec_params["properties"]["additional_permissions"]["properties"]["fs_read"]["items"]["type"],
500 "string"
501 );
502 assert_eq!(
503 exec_params["properties"]["additional_permissions"]["properties"]["fs_write"]["items"]["type"],
504 "string"
505 );
506 assert_eq!(exec_params["properties"]["additional_permissions"]["additionalProperties"], false);
507 assert_eq!(exec_params["properties"]["justification"]["type"], "string");
508 assert!(
509 exec_params["properties"]["sandbox_permissions"]["description"]
510 .as_str()
511 .expect("sandbox_permissions description")
512 .contains("normalized to `with_additional_permissions`")
513 );
514 assert!(
515 exec_params["properties"]["additional_permissions"]["description"]
516 .as_str()
517 .expect("additional_permissions description")
518 .contains("allowed workspace or temp roots")
519 );
520 assert!(
521 exec_params["properties"]["justification"]["description"]
522 .as_str()
523 .expect("justification description")
524 .contains("Required when sandbox_permissions is `require_escalated` or `bypass_sandbox`")
525 );
526 assert_eq!(exec_params["additionalProperties"], false);
527 assert!(
531 exec_params["properties"]["cmd"]["description"]
532 .as_str()
533 .expect("cmd description")
534 .contains("tool description lists covered tools"),
535 "cmd description must defer the example list to the tool description"
536 );
537 for command in ["ls", "rg", "find", "cat", "sed", "awk"] {
538 assert!(
539 EXEC_COMMAND_DESCRIPTION.contains(command),
540 "{command} should be described as an exec_command example"
541 );
542 assert!(
543 exec_params["properties"].get(command).is_none(),
544 "{command} must not be modelled as a separate exec_command field"
545 );
546 }
547
548 let stdin_params = write_stdin_parameters();
549 assert_eq!(stdin_params["required"], json!(["session_id"]));
550 assert!(stdin_params["properties"]["session_id"].is_object());
551 assert_eq!(stdin_params["properties"]["chars"]["type"], "string");
552 assert_eq!(stdin_params["properties"]["action"]["enum"], json!(["write", "poll", "wait"]));
553 assert!(stdin_params["properties"]["wait_timeout_seconds"].is_object());
554 assert!(
555 stdin_params["properties"].get("timeout_seconds").is_none(),
556 "write_stdin schema advertises only wait_timeout_seconds"
557 );
558 assert_eq!(stdin_params["anyOf"][1]["required"], json!(["action"]));
559 assert_eq!(stdin_params["anyOf"][1]["properties"]["action"]["const"], "wait");
560 assert!(
561 stdin_params["properties"]["chars"]["description"]
562 .as_str()
563 .is_some_and(|description| description.contains("empty string"))
564 );
565 assert!(stdin_params["properties"]["chars"].is_object());
566 assert!(
567 stdin_params["properties"]["yield_time_ms"]["description"]
568 .as_str()
569 .expect("stdin yield description")
570 .contains("fresh session output")
571 );
572 assert!(
573 stdin_params["properties"]["max_output_tokens"]["description"]
574 .as_str()
575 .expect("stdin max output description")
576 .contains("spool_path")
577 );
578 assert_eq!(stdin_params["additionalProperties"], false);
579 }
580
581 #[test]
582 fn mcp_description_distinguishes_server_search_from_catalog_search() {
583 assert!(MCP_DESCRIPTION.starts_with("Discover and manage Model Context Protocol capabilities."));
584 assert!(MCP_DESCRIPTION.contains("action=search_tools searches only tools exposed by configured MCP servers"));
585 assert!(MCP_DESCRIPTION.contains("the separate search_tools tool searches the whole session catalog"));
586 }
587
588 #[test]
589 fn agent_description_routes_shell_processes_to_exec_command() {
590 assert!(AGENT_DESCRIPTION.starts_with("Spawn and steer delegated child agents."));
591 assert!(AGENT_DESCRIPTION.contains("spawn_subprocess runs a subagent defined with background: true"));
592 assert!(AGENT_DESCRIPTION.contains("go through exec_command, with background=true"));
593 let action = agent_parameters()["properties"]["action"]["description"]
594 .as_str()
595 .unwrap_or_default()
596 .to_string();
597 assert!(!action.contains("daemons"), "{action}");
598 }
599
600 #[test]
601 fn exec_command_description_states_edit_routing_and_escalation_rules() {
602 assert!(EXEC_COMMAND_DESCRIPTION.starts_with("Run a shell command through the active sandbox policy"));
603 assert!(EXEC_COMMAND_DESCRIPTION.contains("For file edits, use apply_patch"));
604 assert!(EXEC_COMMAND_DESCRIPTION.contains("approval check"));
605 assert!(EXEC_COMMAND_DESCRIPTION.contains("non-empty justification"));
606 for mode in ["require_escalated", "bypass_sandbox"] {
607 assert!(EXEC_COMMAND_DESCRIPTION.contains(mode), "{mode}");
608 assert!(
609 exec_command_parameters()["properties"]["sandbox_permissions"]["enum"]
610 .as_array()
611 .expect("sandbox_permissions enum")
612 .iter()
613 .any(|value| value == mode),
614 "{mode} must stay a real sandbox_permissions value"
615 );
616 }
617 }
618
619 #[test]
620 fn code_search_schema_exposes_exact_five_property_contract() {
621 let params = code_search_parameters();
622 let properties = params["properties"].as_object().expect("properties");
623 let mut property_names = properties.keys().map(String::as_str).collect::<Vec<_>>();
624 property_names.sort_unstable();
625
626 assert_eq!(params["required"], json!(["query"]));
627 assert_eq!(property_names, ["file_types", "max_results", "path", "query", "result_types"]);
628 assert_eq!(params["additionalProperties"], false);
629 assert_eq!(params["properties"]["query"]["pattern"], "\\S");
630 assert_eq!(params["properties"]["file_types"]["minItems"], 1);
631 assert_eq!(params["properties"]["result_types"]["minItems"], 1);
632 assert_eq!(
633 params["properties"]["result_types"]["items"]["enum"],
634 json!(["definition", "usage", "text", "path"])
635 );
636 assert_eq!(params["properties"]["max_results"]["minimum"], 1);
637 assert_eq!(params["properties"]["max_results"]["maximum"], 100);
638 assert!(params.get("anyOf").is_none());
639 }
640
641 #[test]
642 fn legacy_list_files_schema_exposes_pagination_fields() {
643 let list_params = list_files_parameters();
644 assert!(list_params["properties"]["page"].is_object());
645 assert!(list_params["properties"]["per_page"].is_object());
646 assert!(
647 list_params["properties"]["mode"]["enum"]
648 .as_array()
649 .expect("mode enum")
650 .iter()
651 .any(|value| value == "recursive")
652 );
653 }
654
655 #[test]
656 fn semantic_anchor_guidance_is_appended_once() {
657 let base = "Patch in VT Code format.";
658 let with_guidance = with_semantic_anchor_guidance(base);
659
660 assert!(with_guidance.contains(SEMANTIC_ANCHOR_GUIDANCE));
661 assert_eq!(with_semantic_anchor_guidance(&with_guidance), with_guidance);
662 }
663
664 #[test]
665 fn default_apply_patch_parameters_keep_expected_alias_shape() {
666 let schema = apply_patch_parameters();
667
668 assert_eq!(
669 schema["anyOf"],
670 json!([
671 {"required": ["input"]},
672 {"required": ["patch"]}
673 ])
674 );
675 }
676}