Skip to content

Commit b562a51

Browse files
authored
Merge pull request #48 from FSoft-AI4Code/feat/reformat-component-id
re-format component id
2 parents 086969a + f3fe1c6 commit b562a51

File tree

15 files changed

+117
-76
lines changed

15 files changed

+117
-76
lines changed

codewiki/src/be/agent_tools/generate_sub_module_documentations.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pydantic_ai import RunContext, Tool, Agent
2+
from typing import Dict, List
23

34
from codewiki.src.be.agent_tools.deps import CodeWikiDeps
45
from codewiki.src.be.agent_tools.read_code_components import read_code_components_tool
@@ -15,12 +16,14 @@
1516

1617
async def generate_sub_module_documentation(
1718
ctx: RunContext[CodeWikiDeps],
18-
sub_module_specs: dict[str, list[str]]
19+
sub_module_specs: Dict[str, List[str]]
1920
) -> str:
20-
"""Generate detailed description of a given sub-module specs to the sub-agents
21+
"""Delegate documentation generation of sub-modules to sub-agents. Each sub-module will be documented separately.
2122
2223
Args:
23-
sub_module_specs: The specs of the sub-modules to generate documentation for. E.g. {"sub_module_1": ["core_component_1.1", "core_component_1.2"], "sub_module_2": ["core_component_2.1", "core_component_2.2"], ...}
24+
sub_module_specs: A dictionary mapping sub-module names to their core component IDs.
25+
Example: {"authentication": ["auth_handler.py::AuthHandler", "auth_middleware.py::verify_token"], "database": ["db_client.py::DBClient", "models.py::UserModel"]}
26+
Each key is a descriptive sub-module name, and the value is a list of component IDs from the current module's core components that belong to that sub-module.
2427
"""
2528

2629
deps = ctx.deps
@@ -89,4 +92,8 @@ async def generate_sub_module_documentation(
8992
return f"Generate successfully. Documentations: {', '.join([key + '.md' for key in sub_module_specs.keys()])} are saved in the working directory."
9093

9194

92-
generate_sub_module_documentation_tool = Tool(function=generate_sub_module_documentation, name="generate_sub_module_documentation", description="Generate detailed description of a given sub-module specs to the sub-agents", takes_ctx=True)
95+
generate_sub_module_documentation_tool = Tool(
96+
function=generate_sub_module_documentation,
97+
name="generate_sub_module_documentation",
98+
takes_ctx=True
99+
)

codewiki/src/be/agent_tools/read_code_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ async def read_code_components(ctx: RunContext[CodeWikiDeps], component_ids: lis
66
"""Read the code of a given component id
77
88
Args:
9-
component_ids: The ids of the components to read, e.g. ["sweagent.types.AgentRunResult", "sweagent.types.AgentRunResult"] where sweagent.types part is the path to the component and AgentRunResult is the name of the component
9+
component_ids: The ids of the components to read, e.g. ["sweagent/types.py::AgentRunResult", "auth/middleware.py::verify_token"] where the part before :: is the file path and the part after :: is the component name
1010
"""
1111

1212
results = []

codewiki/src/be/dependency_analyzer/analysis/call_graph_analyzer.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ def _resolve_call_relationships(self):
412412
func_lookup[func_info.name] = func_id
413413
if func_info.component_id:
414414
func_lookup[func_info.component_id] = func_id
415-
method_name = func_info.component_id.split(".")[-1]
415+
# Extract short name: handle both new (path::Name) and legacy (path.Name) formats
416+
if "::" in func_info.component_id:
417+
method_name = func_info.component_id.split("::")[-1]
418+
else:
419+
method_name = func_info.component_id.split(".")[-1]
416420
if method_name not in func_lookup:
417421
func_lookup[method_name] = func_id
418422

@@ -424,13 +428,16 @@ def _resolve_call_relationships(self):
424428
relationship.callee = func_lookup[callee_name]
425429
relationship.is_resolved = True
426430
resolved_count += 1
427-
elif "." in callee_name:
431+
elif "::" in callee_name or "." in callee_name:
428432
if callee_name in func_lookup:
429433
relationship.callee = func_lookup[callee_name]
430434
relationship.is_resolved = True
431435
resolved_count += 1
432436
else:
433-
method_name = callee_name.split(".")[-1]
437+
if "::" in callee_name:
438+
method_name = callee_name.split("::")[-1]
439+
else:
440+
method_name = callee_name.split(".")[-1]
434441
if method_name in func_lookup:
435442
relationship.callee = func_lookup[method_name]
436443
relationship.is_resolved = True

codewiki/src/be/dependency_analyzer/analyzers/c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def _get_relative_path(self) -> str:
4444
return str(self.file_path)
4545

4646
def _get_component_id(self, name: str) -> str:
47-
module_path = self._get_module_path()
48-
return f"{module_path}.{name}" if module_path else name
47+
rel_path = self._get_relative_path()
48+
return f"{rel_path}::{name}"
4949

5050
def _analyze(self):
5151
language_capsule = tree_sitter_c.language()

codewiki/src/be/dependency_analyzer/analyzers/cpp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def _get_relative_path(self) -> str:
4444
return str(self.file_path)
4545

4646
def _get_component_id(self, name: str, parent_class: str = None) -> str:
47-
module_path = self._get_module_path()
47+
rel_path = self._get_relative_path()
4848
if parent_class:
49-
return f"{module_path}.{parent_class}.{name}" if module_path else f"{parent_class}.{name}"
50-
return f"{module_path}.{name}" if module_path else name
49+
return f"{rel_path}::{parent_class}.{name}"
50+
return f"{rel_path}::{name}"
5151

5252
def _analyze(self):
5353
language_capsule = tree_sitter_cpp.language()

codewiki/src/be/dependency_analyzer/analyzers/csharp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def _get_relative_path(self) -> str:
4444
return str(self.file_path)
4545

4646
def _get_component_id(self, name: str) -> str:
47-
module_path = self._get_module_path()
48-
return f"{module_path}.{name}" if module_path else name
47+
rel_path = self._get_relative_path()
48+
return f"{rel_path}::{name}"
4949

5050
def _analyze(self):
5151
language_capsule = tree_sitter_c_sharp.language()

codewiki/src/be/dependency_analyzer/analyzers/java.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def _get_relative_path(self) -> str:
4545
return str(self.file_path)
4646

4747
def _get_component_id(self, name: str, parent_class: str = None) -> str:
48-
module_path = self._get_module_path()
48+
rel_path = self._get_relative_path()
4949
if parent_class:
50-
return f"{module_path}.{parent_class}.{name}"
50+
return f"{rel_path}::{parent_class}.{name}"
5151
else:
52-
return f"{module_path}.{name}"
52+
return f"{rel_path}::{name}"
5353

5454
def _analyze(self):
5555
language_capsule = tree_sitter_java.language()

codewiki/src/be/dependency_analyzer/analyzers/javascript.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ def _get_relative_path(self) -> str:
9494
return str(self.file_path)
9595

9696
def _get_component_id(self, name: str, class_name: str = None, is_method: bool = False) -> str:
97-
module_path = self._get_module_path()
98-
97+
relative_path = self._get_relative_path()
98+
9999
if is_method and class_name:
100-
return f"{module_path}.{class_name}.{name}"
101-
elif class_name and not is_method:
102-
return f"{module_path}.{name}"
103-
else:
104-
return f"{module_path}.{name}"
100+
return f"{relative_path}::{class_name}.{name}"
101+
elif class_name and not is_method:
102+
return f"{relative_path}::{name}"
103+
else:
104+
return f"{relative_path}::{name}"
105105

106106
def _find_containing_class(self, node) -> Optional[str]:
107107
parent = node.parent
@@ -167,15 +167,15 @@ def _extract_methods_from_class(self, class_node, class_name: str) -> None:
167167
if child.type == "method_definition":
168168
method_name = self._get_method_name(child)
169169
if method_name:
170-
method_key = f"{self._get_module_path()}.{class_name}.{method_name}"
170+
method_key = f"{self._get_relative_path()}::{class_name}.{method_name}"
171171
method_node = self._create_method_node(child, method_name, class_name)
172172
if method_node:
173173
self.top_level_nodes[method_key] = method_node
174174
elif child.type == "field_definition":
175175
# Handle arrow function properties
176176
field_name = self._get_field_name(child)
177177
if field_name and self._is_arrow_function_field(child):
178-
method_key = f"{self._get_module_path()}.{class_name}.{field_name}"
178+
method_key = f"{self._get_relative_path()}::{class_name}.{field_name}"
179179
method_node = self._create_method_node(child, field_name, class_name)
180180
if method_node:
181181
self.top_level_nodes[method_key] = method_node
@@ -435,7 +435,7 @@ def _traverse_for_calls(self, node, current_top_level) -> None:
435435
if child.type in ["identifier", "type_identifier"]:
436436
base_class = self._get_node_text(child)
437437
caller_id = self._get_component_id(current_top_level)
438-
callee_id = f"{self._get_module_path()}.{base_class}"
438+
callee_id = f"{self._get_relative_path()}::{base_class}"
439439
inheritance_rel = CallRelationship(
440440
caller=caller_id,
441441
callee=callee_id,
@@ -476,8 +476,8 @@ def _traverse_for_calls(self, node, current_top_level) -> None:
476476
callee_name = self._extract_callee_name(node)
477477
if callee_name:
478478
call_info = CallRelationship(
479-
caller=f"{self._get_module_path()}.{current_top_level}",
480-
callee=f"{self._get_module_path()}.{callee_name}",
479+
caller=f"{self._get_relative_path()}::{current_top_level}",
480+
callee=f"{self._get_relative_path()}::{callee_name}",
481481
call_line=node.start_point[0] + 1,
482482
is_resolved=False
483483
)
@@ -498,8 +498,8 @@ def _extract_call_from_node(self, node, caller_name: str) -> Optional[CallRelati
498498
call_text = self._get_node_text(node)
499499
is_method_call = "this." in call_text or "super." in call_text
500500

501-
caller_id = f"{self._get_module_path()}.{caller_name}"
502-
501+
caller_id = f"{self._get_relative_path()}::{caller_name}"
502+
503503
if is_method_call:
504504
current_class = None
505505
for node_key, node_obj in self.top_level_nodes.items():
@@ -508,11 +508,11 @@ def _extract_call_from_node(self, node, caller_name: str) -> Optional[CallRelati
508508
break
509509

510510
if current_class:
511-
method_key = f"{self._get_module_path()}.{current_class}.{callee_name}"
511+
method_key = f"{self._get_relative_path()}::{current_class}.{callee_name}"
512512
if method_key in self.top_level_nodes:
513513
return None
514514

515-
callee_id = f"{self._get_module_path()}.{callee_name}"
515+
callee_id = f"{self._get_relative_path()}::{callee_name}"
516516
if callee_name in self.top_level_nodes:
517517
return CallRelationship(
518518
caller=caller_id,
@@ -570,8 +570,8 @@ def _parse_jsdoc_types(self, comment_text: str, caller_name: str, line_number: i
570570

571571
for base_type in base_types:
572572
if base_type and not self._is_builtin_type_js(base_type):
573-
caller_id = f"{self._get_module_path()}.{caller_name}"
574-
callee_id = f"{self._get_module_path()}.{base_type}"
573+
caller_id = f"{self._get_relative_path()}::{caller_name}"
574+
callee_id = f"{self._get_relative_path()}::{base_type}"
575575

576576
type_rel = CallRelationship(
577577
caller=caller_id,

codewiki/src/be/dependency_analyzer/analyzers/kotlin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def _get_relative_path(self) -> str:
4545
return str(self.file_path)
4646

4747
def _get_component_id(self, name: str, parent_class: Optional[str] = None) -> str:
48-
module_path = self._get_module_path()
48+
rel_path = self._get_relative_path()
4949
if parent_class:
50-
return f"{module_path}.{parent_class}.{name}"
50+
return f"{rel_path}::{parent_class}.{name}"
5151
else:
52-
return f"{module_path}.{name}"
52+
return f"{rel_path}::{name}"
5353

5454
def _analyze(self):
5555
try:

codewiki/src/be/dependency_analyzer/analyzers/php.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,10 @@ def _get_relative_path(self) -> str:
148148

149149
def _get_component_id(self, name: str, parent_class: str = None) -> str:
150150
"""Generate component ID for a node."""
151-
# Use namespace if available
152-
if self.namespace_resolver.current_namespace:
153-
ns_prefix = self.namespace_resolver.current_namespace.replace("\\", ".")
154-
if parent_class:
155-
return f"{ns_prefix}.{parent_class}.{name}"
156-
return f"{ns_prefix}.{name}"
157-
158-
module_path = self._get_module_path()
151+
rel_path = self._get_relative_path()
159152
if parent_class:
160-
return f"{module_path}.{parent_class}.{name}"
161-
return f"{module_path}.{name}"
153+
return f"{rel_path}::{parent_class}.{name}"
154+
return f"{rel_path}::{name}"
162155

163156
def _analyze(self):
164157
"""Parse and analyze the PHP file."""
@@ -442,7 +435,7 @@ def _add_use_relationships(self, node):
442435
if name_node:
443436
fqn = name_node.text.decode().replace("\\", ".")
444437
# Add relationship from file to imported class
445-
file_id = self._get_module_path()
438+
file_id = self._get_relative_path()
446439
self.call_relationships.append(CallRelationship(
447440
caller=file_id,
448441
callee=fqn,
@@ -458,7 +451,7 @@ def _add_use_relationships(self, node):
458451
name_node = self._find_child_by_type(group_child, "namespace_name")
459452
if name_node:
460453
fqn = f"{prefix}\\{name_node.text.decode()}" if prefix else name_node.text.decode()
461-
file_id = self._get_module_path()
454+
file_id = self._get_relative_path()
462455
self.call_relationships.append(CallRelationship(
463456
caller=file_id,
464457
callee=fqn.replace("\\", "."),

0 commit comments

Comments
 (0)