diff --git a/PROGRESS.md b/PROGRESS.md index 947195b..fa46c2b 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -747,3 +747,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 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. | +| 2026-02-10 | Codex | Step 228: Prompt engineering templates (5 prompt files with system/user templates, expected tools, success criteria). 1/1 tests pass. | diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index 98f1677..9b7d746 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -1166,6 +1166,8 @@ 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(step228_test tests/step228_test.cpp) +target_include_directories(step228_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/step228_test.cpp b/editor/tests/step228_test.cpp new file mode 100644 index 0000000..516258b --- /dev/null +++ b/editor/tests/step228_test.cpp @@ -0,0 +1,40 @@ +// Step 228: Prompt engineering templates. + +#include +#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::vector prompts = { + "../tools/prompts/annotate_module.prompt", + "../tools/prompts/cross_language.prompt", + "../tools/prompts/code_review.prompt", + "../tools/prompts/refactor.prompt", + "../tools/prompts/security.prompt" + }; + + for (const auto& path : prompts) { + const std::string content = readFile(path); + assert(!content.empty()); + assertContains(content, "system:"); + assertContains(content, "user:"); + assertContains(content, "expected_tools:"); + assertContains(content, "success_criteria:"); + assertContains(content, "{{"); + } + + printf("step228_test: all assertions passed\n"); + return 0; +} diff --git a/sprint7_plan.md b/sprint7_plan.md index 552f0b8..476f084 100644 --- a/sprint7_plan.md +++ b/sprint7_plan.md @@ -375,7 +375,7 @@ Optimized tool definitions and prompts for specific LLM families. - Adapter that parses model output into structured tool calls *New:* `tools/generic/` directory with definitions + adapter -- [ ] **Step 228: Prompt engineering templates** +- [x] **Step 228: Prompt engineering templates** Reusable prompt templates for common Whetstone tasks: - `annotate_module.prompt` — System + user messages for annotation workflow - `cross_language.prompt` — System + user for cross-language projection diff --git a/tools/prompts/annotate_module.prompt b/tools/prompts/annotate_module.prompt new file mode 100644 index 0000000..a4e936c --- /dev/null +++ b/tools/prompts/annotate_module.prompt @@ -0,0 +1,17 @@ +# annotate_module + +system: +You are a Whetstone annotation assistant. Prefer using tools to inspect ASTs and apply safe annotations. + +user: +Analyze module {{module_name}}. Suggest memory annotations for all unannotated functions. Include confidence scores and reasons. + +expected_tools: +- whetstone_get_ast +- whetstone_suggest_annotations +- whetstone_apply_annotation + +success_criteria: +- All unannotated functions receive suggestions. +- Each suggestion includes a confidence score and brief reason. +- Applied annotations are reported with node ids. diff --git a/tools/prompts/code_review.prompt b/tools/prompts/code_review.prompt new file mode 100644 index 0000000..89f4850 --- /dev/null +++ b/tools/prompts/code_review.prompt @@ -0,0 +1,16 @@ +# code_review + +system: +You are a Whetstone reviewer. Inspect AST and annotations before giving recommendations. + +user: +Review module {{module_name}} for annotation correctness. Highlight risky memory strategies and suggest safer alternatives. + +expected_tools: +- whetstone_get_ast +- whetstone_suggest_annotations + +success_criteria: +- Risks are tied to specific nodes. +- Safer alternatives are provided with rationale. +- No changes are applied unless explicitly requested. diff --git a/tools/prompts/cross_language.prompt b/tools/prompts/cross_language.prompt new file mode 100644 index 0000000..9920efb --- /dev/null +++ b/tools/prompts/cross_language.prompt @@ -0,0 +1,16 @@ +# cross_language + +system: +You are a Whetstone projection assistant. Use the pipeline tools to convert between languages while preserving annotations. + +user: +Project the current module from {{source_language}} to {{target_language}}. Keep annotation intent equivalent and report adaptation notes. + +expected_tools: +- whetstone_get_ast +- whetstone_project_language + +success_criteria: +- Target language projection produced. +- Annotation adaptation notes include any strategy changes. +- Output includes the projected AST summary. diff --git a/tools/prompts/refactor.prompt b/tools/prompts/refactor.prompt new file mode 100644 index 0000000..d79de57 --- /dev/null +++ b/tools/prompts/refactor.prompt @@ -0,0 +1,17 @@ +# refactor + +system: +You are a Whetstone refactoring assistant. Use AST mutations in small, verifiable steps. + +user: +Refactor {{module_name}} to {{goal}}. Keep behavior intact and update annotations if ownership changes. + +expected_tools: +- whetstone_get_ast +- whetstone_mutate +- whetstone_batch_mutate + +success_criteria: +- Refactor uses minimal, reversible mutations. +- Behavior preserved per description. +- Annotation updates reflect new ownership. diff --git a/tools/prompts/security.prompt b/tools/prompts/security.prompt new file mode 100644 index 0000000..536fc75 --- /dev/null +++ b/tools/prompts/security.prompt @@ -0,0 +1,16 @@ +# security + +system: +You are a Whetstone security assistant. Check dependencies and annotations for vulnerabilities before recommending changes. + +user: +Audit {{module_name}} dependencies for known vulnerabilities. Recommend safe upgrades and show impacted functions. + +expected_tools: +- whetstone_get_ast +- whetstone_get_scope + +success_criteria: +- Vulnerable dependencies are listed. +- Recommendations include safer versions or alternatives. +- Impacted nodes or functions are identified.