fix: slim down token usage

This commit is contained in:
eric
2026-04-04 12:37:50 +02:00
parent 97f329c825
commit 1240ab946b
55 changed files with 6799 additions and 2333 deletions

161
src/model/schema.rs Normal file
View File

@@ -0,0 +1,161 @@
use serde_json::{json, Value};
pub fn verification_check_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": ["label", "commands"],
"properties": {
"label": { "type": "string" },
"commands": {
"type": "array",
"items": { "type": "string" }
}
}
})
}
pub fn cleanup_rule_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": ["label", "description"],
"properties": {
"label": { "type": "string" },
"description": { "type": "string" }
}
})
}
pub fn plan_step_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": [
"id",
"title",
"purpose",
"notes",
"inputs",
"outputs",
"dependencies",
"verification",
"cleanup_requirements",
"status",
"attempts"
],
"properties": {
"id": { "type": "string" },
"title": { "type": "string" },
"purpose": { "type": "string" },
"notes": { "type": "string" },
"inputs": { "type": "array", "items": { "type": "string" } },
"outputs": { "type": "array", "items": { "type": "string" } },
"dependencies": { "type": "array", "items": { "type": "string" } },
"verification": {
"type": "array",
"items": verification_check_schema()
},
"cleanup_requirements": {
"type": "array",
"items": cleanup_rule_schema()
},
"status": {
"type": "string",
"enum": ["todo", "active", "done", "blocked"]
},
"attempts": { "type": "integer" }
}
})
}
pub fn plan_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": ["version", "goal_summary", "steps"],
"properties": {
"version": { "type": "integer" },
"goal_summary": { "type": "string" },
"steps": {
"type": "array",
"items": plan_step_schema()
}
}
})
}
pub fn plan_delta_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": ["goal_summary", "step_updates", "remove_step_ids", "pending_step_order"],
"properties": {
"goal_summary": { "type": ["string", "null"] },
"step_updates": {
"type": "array",
"items": plan_step_schema()
},
"remove_step_ids": {
"type": "array",
"items": { "type": "string" }
},
"pending_step_order": {
"type": "array",
"items": { "type": "string" }
}
}
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn plan_schema_locks_down_nested_objects() {
let schema = plan_schema();
assert_eq!(schema["additionalProperties"], false);
assert_eq!(
schema["properties"]["steps"]["items"]["additionalProperties"],
false
);
assert_eq!(
schema["properties"]["steps"]["items"]["properties"]["verification"]["items"]
["additionalProperties"],
false
);
assert_eq!(
schema["properties"]["steps"]["items"]["properties"]["cleanup_requirements"]["items"]
["additionalProperties"],
false
);
assert_eq!(
schema["properties"]["steps"]["items"]["properties"]["notes"]["type"],
"string"
);
}
#[test]
fn plan_delta_schema_allows_partial_replans() {
let schema = plan_delta_schema();
assert_eq!(schema["additionalProperties"], false);
assert_eq!(
schema["required"],
json!([
"goal_summary",
"step_updates",
"remove_step_ids",
"pending_step_order"
])
);
assert_eq!(
schema["properties"]["goal_summary"]["type"],
json!(["string", "null"])
);
assert_eq!(
schema["properties"]["step_updates"]["items"]["additionalProperties"],
false
);
}
}