From 1d91c49b1510a6e962079d07d5cf058d42cc69f8 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 10 Feb 2026 08:19:07 -0700 Subject: [PATCH] Step 227: Open-source model tool definitions --- PROGRESS.md | 1 + editor/CMakeLists.txt | 2 + editor/tests/step227_test.cpp | 41 ++++++++++++ sprint7_plan.md | 2 +- tools/generic/adapter.json | 36 +++++++++++ tools/generic/system_prompt.txt | 22 +++++++ tools/generic/tools.json | 106 ++++++++++++++++++++++++++++++++ 7 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 editor/tests/step227_test.cpp create mode 100644 tools/generic/adapter.json create mode 100644 tools/generic/system_prompt.txt create mode 100644 tools/generic/tools.json diff --git a/PROGRESS.md b/PROGRESS.md index f61248d..947195b 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -746,3 +746,4 @@ vcpkg's imgui 1.91.9 removed the `sdl2-binding` feature (only `sdl3-binding` exi | 2026-02-10 | Claude Opus 4.6 | Sprint 7 Phase 7a (Steps 202–206): API docs (AGENT_API.md, 23 methods), JSON schemas (20 files), exposed ContextAPI/BatchMutationAPI/Pipeline via RPC, permission policy updates. 51/51 tests pass. | | 2026-02-10 | Claude Opus 4.6 | Sprint 7 Phase 7b (Steps 207–213): MCPServer.h (10 tools, 5 resources, 4 prompts, JSON-RPC 2.0 initialize handshake), MCPBridge.h (stdio transport). 90/90 tests pass. | | 2026-02-10 | Claude Opus 4.6 | Sprint 7 Phase 7c (Steps 214–219): TraceGenerator.h (6 scenario templates, 9-sample code corpus, batch engine), TraceExporter.h (Anthropic/OpenAI/JSONL/Markdown export, filtering, statistics). 294/294 tests pass. | +| 2026-02-10 | Codex | Step 227: Open-source model tool definitions (ReAct-style prompt, XML tool call format, simplified schemas, adapter rules). 1/1 tests pass. | diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index b0198f3..98f1677 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -1164,6 +1164,8 @@ target_include_directories(step225_test PRIVATE src) add_executable(step226_test tests/step226_test.cpp) target_include_directories(step226_test PRIVATE src) +add_executable(step227_test tests/step227_test.cpp) +target_include_directories(step227_test PRIVATE src) add_executable(step213_test tests/step213_test.cpp) target_include_directories(step213_test PRIVATE src) target_link_libraries(step213_test PRIVATE nlohmann_json::nlohmann_json) diff --git a/editor/tests/step227_test.cpp b/editor/tests/step227_test.cpp new file mode 100644 index 0000000..c969bf3 --- /dev/null +++ b/editor/tests/step227_test.cpp @@ -0,0 +1,41 @@ +// Step 227: Open-source model tool definitions. + +#include +#include +#include + +static std::string readFile(const std::string& path) { + std::ifstream f(path); + if (!f.is_open()) return {}; + return std::string((std::istreambuf_iterator(f)), + std::istreambuf_iterator()); +} + +static void assertContains(const std::string& text, const std::string& needle) { + assert(text.find(needle) != std::string::npos); +} + +int main() { + const std::string tools = readFile("../tools/generic/tools.json"); + const std::string prompt = readFile("../tools/generic/system_prompt.txt"); + const std::string adapter = readFile("../tools/generic/adapter.json"); + + assertContains(tools, "whetstone_get_ast"); + assertContains(tools, "whetstone_mutate"); + assertContains(tools, "whetstone_batch_mutate"); + assertContains(tools, "whetstone_get_scope"); + assertContains(tools, "whetstone_get_call_hierarchy"); + assertContains(tools, "whetstone_suggest_annotations"); + assertContains(tools, "whetstone_apply_annotation"); + assertContains(tools, "whetstone_generate_code"); + assertContains(tools, "whetstone_run_pipeline"); + assertContains(tools, "whetstone_project_language"); + + assertContains(prompt, "ReAct"); + assertContains(prompt, "{JSON_ARGS} + +Rules: +- Use exactly one tool call per Action. +- Emit valid JSON inside the tool call tag. +- If no tool is needed, respond with a direct answer. + +Available tools: +- whetstone_get_ast: Return the current AST. +- whetstone_mutate: Apply a single AST mutation. +- whetstone_batch_mutate: Apply multiple mutations atomically. +- whetstone_get_scope: List symbols in scope. +- whetstone_get_call_hierarchy: Get call hierarchy for a function. +- whetstone_suggest_annotations: Suggest memory annotations. +- whetstone_apply_annotation: Apply memory annotations. +- whetstone_generate_code: Generate code from a spec. +- whetstone_run_pipeline: Run the full pipeline (source -> target). +- whetstone_project_language: Project AST to a target language. diff --git a/tools/generic/tools.json b/tools/generic/tools.json new file mode 100644 index 0000000..0d41275 --- /dev/null +++ b/tools/generic/tools.json @@ -0,0 +1,106 @@ +{ + "version": "1.0", + "provider": "generic", + "call_format": { + "type": "xml", + "tag": "tool_call", + "name_attribute": "name", + "payload": "json", + "example": "{}" + }, + "tools": [ + { + "name": "whetstone_get_ast", + "description": "Return the current AST for the active buffer. Use before mutations.", + "args": [], + "defaults": {} + }, + { + "name": "whetstone_mutate", + "description": "Apply a single AST mutation. Use setProperty, updateNode, deleteNode, or insertNode.", + "args": [ + { "name": "type", "type": "string", "required": true, "enum": ["setProperty", "updateNode", "deleteNode", "insertNode"] }, + { "name": "nodeId", "type": "string", "required": false, "notes": "Required for setProperty, updateNode, deleteNode." }, + { "name": "property", "type": "string", "required": false }, + { "name": "value", "type": "string", "required": false }, + { "name": "parentId", "type": "string", "required": false }, + { "name": "role", "type": "string", "required": false }, + { "name": "node", "type": "object", "required": false } + ], + "defaults": {} + }, + { + "name": "whetstone_batch_mutate", + "description": "Apply multiple mutations atomically.", + "args": [ + { "name": "mutations", "type": "array", "required": true } + ], + "defaults": {} + }, + { + "name": "whetstone_get_scope", + "description": "List symbols in scope for a node.", + "args": [ + { "name": "nodeId", "type": "string", "required": true } + ], + "defaults": {} + }, + { + "name": "whetstone_get_call_hierarchy", + "description": "Get call hierarchy for a function.", + "args": [ + { "name": "functionId", "type": "string", "required": true } + ], + "defaults": {} + }, + { + "name": "whetstone_suggest_annotations", + "description": "Suggest memory annotations for a node or line/col location.", + "args": [ + { "name": "nodeId", "type": "string", "required": false }, + { "name": "line", "type": "integer", "required": false }, + { "name": "col", "type": "integer", "required": false } + ], + "defaults": {} + }, + { + "name": "whetstone_apply_annotation", + "description": "Apply a memory annotation suggestion.", + "args": [ + { "name": "nodeId", "type": "string", "required": true }, + { "name": "annotationType", "type": "string", "required": true }, + { "name": "strategy", "type": "string", "required": true }, + { "name": "reason", "type": "string", "required": false }, + { "name": "confidence", "type": "number", "required": false } + ], + "defaults": {} + }, + { + "name": "whetstone_generate_code", + "description": "Generate code from a natural language spec.", + "args": [ + { "name": "spec", "type": "string", "required": true }, + { "name": "preferImports", "type": "boolean", "required": false } + ], + "defaults": { "preferImports": true } + }, + { + "name": "whetstone_run_pipeline", + "description": "Run the full pipeline from source to target language.", + "args": [ + { "name": "source", "type": "string", "required": true }, + { "name": "sourceLanguage", "type": "string", "required": true }, + { "name": "targetLanguage", "type": "string", "required": true } + ], + "defaults": {} + }, + { + "name": "whetstone_project_language", + "description": "Project the current AST to a target language.", + "args": [ + { "name": "targetLanguage", "type": "string", "required": true } + ], + "defaults": {} + } + ] +}