返回 CodeWhale
schema.rs
根目录 / crates / engine / src / tools / github / schema.rs
1 //! The input contract the model sees: the canonical union schema.
2
3 use serde_json::{Value, json};
4
5 /// The union schema for the canonical `github` tool: `action` plus every
6 /// field any allowed action reads. `read_only` drops the write fields so the
7 /// Plan-mode surface cannot even describe a mutation.
8 pub(super) fn canonical_schema(allowed_actions: &[&str], read_only: bool) -> Value {
9 let actions: Vec<&str> = allowed_actions.to_vec();
10 let mut properties = serde_json::Map::new();
11 properties.insert(
12 "action".to_string(),
13 json!({
14 "type": "string",
15 "enum": actions,
16 "description": "Action to perform."
17 }),
18 );
19 properties.insert(
20 "number".to_string(),
21 json!({ "type": "integer", "minimum": 1, "description": "Issue/PR number (all actions)." }),
22 );
23 properties.insert(
24 "include_comments".to_string(),
25 json!({ "type": "boolean", "default": true, "description": "(action=issue_context)" }),
26 );
27 properties.insert("report_id".to_string(), json!({"type": "string", "maxLength": 73, "description": "(report_read) Opaque current-session draft ID returned by report_draft."}));
28 properties.insert(
29 "include_diff".to_string(),
30 json!({ "type": "boolean", "default": false, "description": "(action=pr_context)" }),
31 );
32 if !read_only {
33 properties.insert("revises".to_string(), json!({"type": "string", "maxLength": 73, "description": "(report_draft) Existing current-session draft to revise. Old bytes are preserved."}));
34 properties.insert("report".to_string(), report_schema());
35 properties.insert(
36 "target".to_string(),
37 json!({ "type": "string", "enum": ["issue", "pr"], "description": "(action=comment)" }),
38 );
39 properties.insert(
40 "body".to_string(),
41 json!({ "type": "string", "description": "Comment body (action=comment)." }),
42 );
43 properties.insert(
44 "evidence".to_string(),
45 json!({
46 "type": "object",
47 "description": "Evidence object (action=comment/close_*). Close actions require files_changed, tests_run, final_status.",
48 "properties": {
49 "files_changed": { "type": "array", "items": { "type": "string" } },
50 "tests_run": { "type": "array", "items": { "type": "string" } },
51 "commits": { "type": "array", "items": { "type": "string" } },
52 "final_status": { "type": "string" }
53 }
54 }),
55 );
56 properties.insert(
57 "acceptance_criteria".to_string(),
58 json!({ "type": "array", "items": { "type": "string" }, "minItems": 1, "description": "(action=close_issue/close_pr)" }),
59 );
60 properties.insert(
61 "comment".to_string(),
62 json!({ "type": "string", "description": "Optional closing comment (action=close_issue/close_pr)." }),
63 );
64 properties.insert(
65 "allow_dirty".to_string(),
66 json!({ "type": "boolean", "default": false, "description": "(action=close_issue/close_pr) Close is rejected when the worktree is dirty unless this is true." }),
67 );
68 properties.insert(
69 "dry_run".to_string(),
70 json!({ "type": "boolean", "default": false, "description": "(action=comment/close_issue/close_pr)" }),
71 );
72 }
73 json!({
74 "type": "object",
75 "properties": properties,
76 "additionalProperties": false
77 })
78 }
79
80 fn report_schema() -> Value {
81 let narrative = json!({"type": "string", "minLength": 1, "maxLength": 1600});
82 let items = json!({"type": "array", "minItems": 1, "maxItems": 8, "items": {"type": "string", "minLength": 1, "maxLength": 800}});
83 let context = json!({"type": "string", "minLength": 1, "maxLength": 100});
84 json!({"type": "object", "additionalProperties": false,
85 "description": "(report_draft) Bounded narrative about a likely Codewhale defect, written by the active agent from observed evidence. No logs, code blocks, attachments, paths or private URLs. Only a local draft; publication unavailable.",
86 "properties": {
87 "title": {"type": "string", "minLength": 1, "maxLength": 160},
88 "expected": narrative, "actual": narrative, "impact": narrative,
89 "steps": items, "observed": items,
90 "inferred": {"type": "array", "maxItems": 4, "items": {"type": "string", "minLength": 1, "maxLength": 800}},
91 "reported_provider": context, "reported_tool": context, "reported_terminal": context,
92 "related_issues": {"type": "array", "maxItems": 5, "items": {"type": "integer", "minimum": 1, "maximum": u32::MAX}, "description": "Already-known Codewhale issue numbers; displayed as agent-supplied, unverified references. No search is performed."}
93 }, "required": ["title", "expected", "actual", "impact", "steps", "observed"]
94 })
95 }
96
96 lines RUST