[Bug]: ckg never indexes a named JavaScript or TypeScript function, so search_function reports it as absent
What happened?
The ckg tool cannot find any named function in a .js or .ts file. For a codebase containing sum.js:
function topSum(a, b) {
return a + b;
}search_function with identifier=topSum returns:
No functions named topSum found.while search_class on a class Calc in the same file works. The index is built, the file is parsed, and the function is simply never inserted.
Root cause: tree-sitter's JavaScript and TypeScript grammars give a named declaration the node type function_declaration (measured with the repo's own parsers, tree-sitter 0.21.3 / tree-sitter-languages 1.10.2):
=== javascript ===
program
function_declaration name=topSum
class_declaration name=Calc
export_statement
function_declaration name=exportedSum
=== typescript ===
program
export_statement
function_declaration name=tsNamed
function_declaration name=tsLocal_recursive_visit_javascript (trae_agent/tools/ckg/ckg_database.py:479) and _recursive_visit_typescript (:425) match only two node types each — class_declaration and method_definition — so function_declaration falls through the if/elif and the recursion carries on without inserting it. The two visitors are otherwise byte-identical apart from the name in their recursive call.
Every other language visitor in this file indexes its named function node: function_definition for Python (:213), C (:407) and C++ (:379), method_declaration for Java (:316) and C++ (:304). JavaScript and TypeScript are the only ones whose top-level function is dropped.
What did you expect to happen?
search_function should return
Found 1 functions named topSum:
1. /…/sum.js:1-3
function topSum(a, b) {
return a + b;
}the same way a Python module-level def is found today, with parent_class unset so the result is not offered as a class method.
Traceback
No exception — that is what makes this hard to notice. The tool answers "not found" with a full ToolExecResult.output and error_code=0, so nothing distinguishes "this symbol is not in the codebase" from "this language's functions are never indexed."
What is your system, Python, dependency version?
- OS: Windows 11 (10.0.26200)
- Python: 3.12.13 (uv-managed)
- tree-sitter: 0.21.3, tree-sitter-languages: 1.10.2 (as pinned by the repo)
Reproduced on main at e839e55 with a temp codebase, no git history and no network.
Additional information that you believe is relevant to this bug
The module docstring at trae_agent/tools/ckg/ckg_database.py:23-28 lists known issue 3 as:
For JavaScript and TypeScript, the AST is not complete: anonymous functions, arrow functions, etc., are not parsed.
A named function foo() {} is neither anonymous nor an arrow function, so this looks like a plain omission rather than one of the documented limitations. I am not proposing to change that docstring here: arrow and anonymous functions stay unparsed, and I'd keep it that way in a first fix so the diff stays reviewable — I'll pin the arrow-function case in the test to make the boundary explicit instead of quietly claiming full JavaScript coverage.
I plan to work on this.
Source: bytedance/trae-agent