Step 248: compact AST response format (subtree, diff, version tracking)

Adds token-efficient AST queries: compact mode (<30% of full size),
subtree extraction by nodeId, version-tracked AST diff after mutations,
and tokenEstimate on all responses. 12/12 tests pass, 17 tools total.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Bill
2026-02-11 06:29:17 +00:00
parent 1131fdf73d
commit fbff0cedd0
8 changed files with 599 additions and 13 deletions

View File

@@ -309,12 +309,15 @@ private:
void registerASTTools() {
// whetstone_get_ast
tools_.push_back({"whetstone_get_ast",
"Get the current AST (Abstract Syntax Tree) of the active buffer as JSON. "
"Returns the full tree structure with all nodes, annotations, and metadata.",
{{"type", "object"}, {"properties", json::object()}}
"Get the current AST of the active buffer. Set compact=true for "
"a token-efficient flat list of {id, type, name, line, children}. "
"Full mode returns complete tree with properties and spans.",
{{"type", "object"}, {"properties", {
{"compact", {{"type", "boolean"}, {"description", "Compact mode: flat list with minimal fields (default false)"}}}
}}}
});
toolHandlers_["whetstone_get_ast"] = [this](const json&) {
return callWhetstone("getAST");
toolHandlers_["whetstone_get_ast"] = [this](const json& args) {
return callWhetstone("getAST", args);
};
// whetstone_mutate
@@ -370,6 +373,30 @@ private:
toolHandlers_["whetstone_get_call_hierarchy"] = [this](const json& args) {
return callWhetstone("getCallHierarchy", args);
};
// whetstone_get_ast_subtree
tools_.push_back({"whetstone_get_ast_subtree",
"Get only the subtree rooted at a specific node ID. Returns full "
"node detail for just that subtree, saving tokens vs full AST.",
{{"type", "object"}, {"properties", {
{"nodeId", {{"type", "string"}, {"description", "Root node ID for the subtree"}}}
}}, {"required", {"nodeId"}}}
});
toolHandlers_["whetstone_get_ast_subtree"] = [this](const json& args) {
return callWhetstone("getASTSubtree", args);
};
// whetstone_get_ast_diff
tools_.push_back({"whetstone_get_ast_diff",
"Get only the AST nodes that changed since a given version. "
"Use the version number from a previous getAST or mutation response.",
{{"type", "object"}, {"properties", {
{"sinceVersion", {{"type", "integer"}, {"description", "Version number to diff against (from previous response)"}}}
}}, {"required", {"sinceVersion"}}}
});
toolHandlers_["whetstone_get_ast_diff"] = [this](const json& args) {
return callWhetstone("getASTDiff", args);
};
}
// ---------------------------------------------------------------