@embedder/embedder 1.1.0 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/_commonjsHelpers-C1uRMj_j.js +1 -0
- package/assets/cli-DIXdkQBM.js +887 -0
- package/assets/devtools-B4JKPJyU.js +1 -0
- package/assets/index-B3hJUcJE.js +1 -0
- package/assets/index-BCdeyKtY.js +1 -0
- package/assets/index-oEV_emLn.js +1 -0
- package/cli.js +2 -0
- package/package.json +15 -96
- package/LICENSE +0 -36
- package/bundle/embedder.js +0 -618
- package/bundle/gdb-debugger-python/gdb_bridge.py +0 -392
- package/bundle/gdb-debugger-python/requirements.txt +0 -1
- package/bundle/postinstall-for-users.js +0 -515
- package/bundle/repomap-bridge.js +0 -6
- package/bundle/repomap-python/importance.py +0 -58
- package/bundle/repomap-python/queries/tree-sitter-language-pack/README.md +0 -9
- package/bundle/repomap-python/queries/tree-sitter-language-pack/arduino-tags.scm +0 -5
- package/bundle/repomap-python/queries/tree-sitter-language-pack/c-tags.scm +0 -9
- package/bundle/repomap-python/queries/tree-sitter-language-pack/chatito-tags.scm +0 -16
- package/bundle/repomap-python/queries/tree-sitter-language-pack/commonlisp-tags.scm +0 -122
- package/bundle/repomap-python/queries/tree-sitter-language-pack/cpp-tags.scm +0 -15
- package/bundle/repomap-python/queries/tree-sitter-language-pack/csharp-tags.scm +0 -26
- package/bundle/repomap-python/queries/tree-sitter-language-pack/d-tags.scm +0 -26
- package/bundle/repomap-python/queries/tree-sitter-language-pack/dart-tags.scm +0 -92
- package/bundle/repomap-python/queries/tree-sitter-language-pack/elisp-tags.scm +0 -5
- package/bundle/repomap-python/queries/tree-sitter-language-pack/elixir-tags.scm +0 -54
- package/bundle/repomap-python/queries/tree-sitter-language-pack/elm-tags.scm +0 -19
- package/bundle/repomap-python/queries/tree-sitter-language-pack/gleam-tags.scm +0 -41
- package/bundle/repomap-python/queries/tree-sitter-language-pack/go-tags.scm +0 -42
- package/bundle/repomap-python/queries/tree-sitter-language-pack/java-tags.scm +0 -20
- package/bundle/repomap-python/queries/tree-sitter-language-pack/javascript-tags.scm +0 -88
- package/bundle/repomap-python/queries/tree-sitter-language-pack/lua-tags.scm +0 -34
- package/bundle/repomap-python/queries/tree-sitter-language-pack/ocaml-tags.scm +0 -115
- package/bundle/repomap-python/queries/tree-sitter-language-pack/ocaml_interface-tags.scm +0 -98
- package/bundle/repomap-python/queries/tree-sitter-language-pack/pony-tags.scm +0 -39
- package/bundle/repomap-python/queries/tree-sitter-language-pack/properties-tags.scm +0 -5
- package/bundle/repomap-python/queries/tree-sitter-language-pack/python-tags.scm +0 -14
- package/bundle/repomap-python/queries/tree-sitter-language-pack/r-tags.scm +0 -21
- package/bundle/repomap-python/queries/tree-sitter-language-pack/racket-tags.scm +0 -12
- package/bundle/repomap-python/queries/tree-sitter-language-pack/ruby-tags.scm +0 -64
- package/bundle/repomap-python/queries/tree-sitter-language-pack/rust-tags.scm +0 -60
- package/bundle/repomap-python/queries/tree-sitter-language-pack/solidity-tags.scm +0 -43
- package/bundle/repomap-python/queries/tree-sitter-language-pack/swift-tags.scm +0 -51
- package/bundle/repomap-python/queries/tree-sitter-language-pack/udev-tags.scm +0 -20
- package/bundle/repomap-python/queries/tree-sitter-languages/README.md +0 -24
- package/bundle/repomap-python/queries/tree-sitter-languages/c-tags.scm +0 -9
- package/bundle/repomap-python/queries/tree-sitter-languages/c_sharp-tags.scm +0 -46
- package/bundle/repomap-python/queries/tree-sitter-languages/cpp-tags.scm +0 -15
- package/bundle/repomap-python/queries/tree-sitter-languages/dart-tags.scm +0 -91
- package/bundle/repomap-python/queries/tree-sitter-languages/elisp-tags.scm +0 -8
- package/bundle/repomap-python/queries/tree-sitter-languages/elixir-tags.scm +0 -54
- package/bundle/repomap-python/queries/tree-sitter-languages/elm-tags.scm +0 -19
- package/bundle/repomap-python/queries/tree-sitter-languages/go-tags.scm +0 -30
- package/bundle/repomap-python/queries/tree-sitter-languages/hcl-tags.scm +0 -77
- package/bundle/repomap-python/queries/tree-sitter-languages/java-tags.scm +0 -20
- package/bundle/repomap-python/queries/tree-sitter-languages/javascript-tags.scm +0 -88
- package/bundle/repomap-python/queries/tree-sitter-languages/kotlin-tags.scm +0 -27
- package/bundle/repomap-python/queries/tree-sitter-languages/ocaml-tags.scm +0 -115
- package/bundle/repomap-python/queries/tree-sitter-languages/ocaml_interface-tags.scm +0 -98
- package/bundle/repomap-python/queries/tree-sitter-languages/php-tags.scm +0 -26
- package/bundle/repomap-python/queries/tree-sitter-languages/python-tags.scm +0 -12
- package/bundle/repomap-python/queries/tree-sitter-languages/ql-tags.scm +0 -26
- package/bundle/repomap-python/queries/tree-sitter-languages/ruby-tags.scm +0 -64
- package/bundle/repomap-python/queries/tree-sitter-languages/rust-tags.scm +0 -60
- package/bundle/repomap-python/queries/tree-sitter-languages/scala-tags.scm +0 -65
- package/bundle/repomap-python/queries/tree-sitter-languages/typescript-tags.scm +0 -41
- package/bundle/repomap-python/repomap.py +0 -229
- package/bundle/repomap-python/repomap_bridge.py +0 -234
- package/bundle/repomap-python/repomap_class.py +0 -637
- package/bundle/repomap-python/repomap_server.py +0 -561
- package/bundle/repomap-python/requirements.txt +0 -7
- package/bundle/repomap-python/scm.py +0 -59
- package/bundle/repomap-python/utils.py +0 -58
- package/bundle/sandbox-macos-permissive-closed.sb +0 -26
- package/bundle/sandbox-macos-permissive-open.sb +0 -19
- package/bundle/sandbox-macos-permissive-proxied.sb +0 -31
- package/bundle/sandbox-macos-restrictive-closed.sb +0 -87
- package/bundle/sandbox-macos-restrictive-open.sb +0 -90
- package/bundle/sandbox-macos-restrictive-proxied.sb +0 -92
- package/postinstall.js +0 -42
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
; Method definitions
|
|
2
|
-
|
|
3
|
-
(
|
|
4
|
-
(comment)* @doc
|
|
5
|
-
.
|
|
6
|
-
[
|
|
7
|
-
(method
|
|
8
|
-
name: (_) @name.definition.method) @definition.method
|
|
9
|
-
(singleton_method
|
|
10
|
-
name: (_) @name.definition.method) @definition.method
|
|
11
|
-
]
|
|
12
|
-
(#strip! @doc "^#\\s*")
|
|
13
|
-
(#select-adjacent! @doc @definition.method)
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
(alias
|
|
17
|
-
name: (_) @name.definition.method) @definition.method
|
|
18
|
-
|
|
19
|
-
(setter
|
|
20
|
-
(identifier) @ignore)
|
|
21
|
-
|
|
22
|
-
; Class definitions
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
(comment)* @doc
|
|
26
|
-
.
|
|
27
|
-
[
|
|
28
|
-
(class
|
|
29
|
-
name: [
|
|
30
|
-
(constant) @name.definition.class
|
|
31
|
-
(scope_resolution
|
|
32
|
-
name: (_) @name.definition.class)
|
|
33
|
-
]) @definition.class
|
|
34
|
-
(singleton_class
|
|
35
|
-
value: [
|
|
36
|
-
(constant) @name.definition.class
|
|
37
|
-
(scope_resolution
|
|
38
|
-
name: (_) @name.definition.class)
|
|
39
|
-
]) @definition.class
|
|
40
|
-
]
|
|
41
|
-
(#strip! @doc "^#\\s*")
|
|
42
|
-
(#select-adjacent! @doc @definition.class)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
; Module definitions
|
|
46
|
-
|
|
47
|
-
(
|
|
48
|
-
(module
|
|
49
|
-
name: [
|
|
50
|
-
(constant) @name.definition.module
|
|
51
|
-
(scope_resolution
|
|
52
|
-
name: (_) @name.definition.module)
|
|
53
|
-
]) @definition.module
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
; Calls
|
|
57
|
-
|
|
58
|
-
(call method: (identifier) @name.reference.call) @reference.call
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
[(identifier) (constant)] @name.reference.call @reference.call
|
|
62
|
-
(#is-not? local)
|
|
63
|
-
(#not-match? @name.reference.call "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
|
|
64
|
-
)
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
; ADT definitions
|
|
2
|
-
|
|
3
|
-
(struct_item
|
|
4
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
5
|
-
|
|
6
|
-
(enum_item
|
|
7
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
8
|
-
|
|
9
|
-
(union_item
|
|
10
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
11
|
-
|
|
12
|
-
; type aliases
|
|
13
|
-
|
|
14
|
-
(type_item
|
|
15
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
16
|
-
|
|
17
|
-
; method definitions
|
|
18
|
-
|
|
19
|
-
(declaration_list
|
|
20
|
-
(function_item
|
|
21
|
-
name: (identifier) @name.definition.method)) @definition.method
|
|
22
|
-
|
|
23
|
-
; function definitions
|
|
24
|
-
|
|
25
|
-
(function_item
|
|
26
|
-
name: (identifier) @name.definition.function) @definition.function
|
|
27
|
-
|
|
28
|
-
; trait definitions
|
|
29
|
-
(trait_item
|
|
30
|
-
name: (type_identifier) @name.definition.interface) @definition.interface
|
|
31
|
-
|
|
32
|
-
; module definitions
|
|
33
|
-
(mod_item
|
|
34
|
-
name: (identifier) @name.definition.module) @definition.module
|
|
35
|
-
|
|
36
|
-
; macro definitions
|
|
37
|
-
|
|
38
|
-
(macro_definition
|
|
39
|
-
name: (identifier) @name.definition.macro) @definition.macro
|
|
40
|
-
|
|
41
|
-
; references
|
|
42
|
-
|
|
43
|
-
(call_expression
|
|
44
|
-
function: (identifier) @name.reference.call) @reference.call
|
|
45
|
-
|
|
46
|
-
(call_expression
|
|
47
|
-
function: (field_expression
|
|
48
|
-
field: (field_identifier) @name.reference.call)) @reference.call
|
|
49
|
-
|
|
50
|
-
(macro_invocation
|
|
51
|
-
macro: (identifier) @name.reference.call) @reference.call
|
|
52
|
-
|
|
53
|
-
; implementations
|
|
54
|
-
|
|
55
|
-
(impl_item
|
|
56
|
-
trait: (type_identifier) @name.reference.implementation) @reference.implementation
|
|
57
|
-
|
|
58
|
-
(impl_item
|
|
59
|
-
type: (type_identifier) @name.reference.implementation
|
|
60
|
-
!trait) @reference.implementation
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
; Definitions
|
|
2
|
-
|
|
3
|
-
(package_clause
|
|
4
|
-
name: (package_identifier) @name.definition.module) @definition.module
|
|
5
|
-
|
|
6
|
-
(trait_definition
|
|
7
|
-
name: (identifier) @name.definition.interface) @definition.interface
|
|
8
|
-
|
|
9
|
-
(enum_definition
|
|
10
|
-
name: (identifier) @name.definition.enum) @definition.enum
|
|
11
|
-
|
|
12
|
-
(simple_enum_case
|
|
13
|
-
name: (identifier) @name.definition.class) @definition.class
|
|
14
|
-
|
|
15
|
-
(full_enum_case
|
|
16
|
-
name: (identifier) @name.definition.class) @definition.class
|
|
17
|
-
|
|
18
|
-
(class_definition
|
|
19
|
-
name: (identifier) @name.definition.class) @definition.class
|
|
20
|
-
|
|
21
|
-
(object_definition
|
|
22
|
-
name: (identifier) @name.definition.object) @definition.object
|
|
23
|
-
|
|
24
|
-
(function_definition
|
|
25
|
-
name: (identifier) @name.definition.function) @definition.function
|
|
26
|
-
|
|
27
|
-
(val_definition
|
|
28
|
-
pattern: (identifier) @name.definition.variable) @definition.variable
|
|
29
|
-
|
|
30
|
-
(given_definition
|
|
31
|
-
name: (identifier) @name.definition.variable) @definition.variable
|
|
32
|
-
|
|
33
|
-
(var_definition
|
|
34
|
-
pattern: (identifier) @name.definition.variable) @definition.variable
|
|
35
|
-
|
|
36
|
-
(val_declaration
|
|
37
|
-
name: (identifier) @name.definition.variable) @definition.variable
|
|
38
|
-
|
|
39
|
-
(var_declaration
|
|
40
|
-
name: (identifier) @name.definition.variable) @definition.variable
|
|
41
|
-
|
|
42
|
-
(type_definition
|
|
43
|
-
name: (type_identifier) @name.definition.type) @definition.type
|
|
44
|
-
|
|
45
|
-
(class_parameter
|
|
46
|
-
name: (identifier) @name.definition.property) @definition.property
|
|
47
|
-
|
|
48
|
-
; References
|
|
49
|
-
|
|
50
|
-
(call_expression
|
|
51
|
-
(identifier) @name.reference.call) @reference.call
|
|
52
|
-
|
|
53
|
-
(instance_expression
|
|
54
|
-
(type_identifier) @name.reference.interface) @reference.interface
|
|
55
|
-
|
|
56
|
-
(instance_expression
|
|
57
|
-
(generic_type
|
|
58
|
-
(type_identifier) @name.reference.interface)) @reference.interface
|
|
59
|
-
|
|
60
|
-
(extends_clause
|
|
61
|
-
(type_identifier) @name.reference.class) @reference.class
|
|
62
|
-
|
|
63
|
-
(extends_clause
|
|
64
|
-
(generic_type
|
|
65
|
-
(type_identifier) @name.reference.class)) @reference.class
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
(function_signature
|
|
2
|
-
name: (identifier) @name.definition.function) @definition.function
|
|
3
|
-
|
|
4
|
-
(method_signature
|
|
5
|
-
name: (property_identifier) @name.definition.method) @definition.method
|
|
6
|
-
|
|
7
|
-
(abstract_method_signature
|
|
8
|
-
name: (property_identifier) @name.definition.method) @definition.method
|
|
9
|
-
|
|
10
|
-
(abstract_class_declaration
|
|
11
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
12
|
-
|
|
13
|
-
(module
|
|
14
|
-
name: (identifier) @name.definition.module) @definition.module
|
|
15
|
-
|
|
16
|
-
(interface_declaration
|
|
17
|
-
name: (type_identifier) @name.definition.interface) @definition.interface
|
|
18
|
-
|
|
19
|
-
(type_annotation
|
|
20
|
-
(type_identifier) @name.reference.type) @reference.type
|
|
21
|
-
|
|
22
|
-
(new_expression
|
|
23
|
-
constructor: (identifier) @name.reference.class) @reference.class
|
|
24
|
-
|
|
25
|
-
(function_declaration
|
|
26
|
-
name: (identifier) @name.definition.function) @definition.function
|
|
27
|
-
|
|
28
|
-
(method_definition
|
|
29
|
-
name: (property_identifier) @name.definition.method) @definition.method
|
|
30
|
-
|
|
31
|
-
(class_declaration
|
|
32
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
33
|
-
|
|
34
|
-
(interface_declaration
|
|
35
|
-
name: (type_identifier) @name.definition.class) @definition.class
|
|
36
|
-
|
|
37
|
-
(type_alias_declaration
|
|
38
|
-
name: (type_identifier) @name.definition.type) @definition.type
|
|
39
|
-
|
|
40
|
-
(enum_declaration
|
|
41
|
-
name: (identifier) @name.definition.enum) @definition.enum
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Standalone RepoMap Tool
|
|
4
|
-
|
|
5
|
-
A command-line tool that generates a "map" of a software repository,
|
|
6
|
-
highlighting important files and definitions based on their relevance.
|
|
7
|
-
Uses Tree-sitter for parsing and PageRank for ranking importance.
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import argparse
|
|
11
|
-
import os
|
|
12
|
-
import sys
|
|
13
|
-
from pathlib import Path
|
|
14
|
-
from typing import List
|
|
15
|
-
|
|
16
|
-
from utils import count_tokens, read_text, Tag
|
|
17
|
-
from scm import get_scm_fname
|
|
18
|
-
from importance import is_important, filter_important_files
|
|
19
|
-
from repomap_class import RepoMap
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def find_src_files(directory: str) -> List[str]:
|
|
23
|
-
"""Find source files in a directory."""
|
|
24
|
-
if not os.path.isdir(directory):
|
|
25
|
-
return [directory] if os.path.isfile(directory) else []
|
|
26
|
-
|
|
27
|
-
src_files = []
|
|
28
|
-
for root, dirs, files in os.walk(directory):
|
|
29
|
-
# Skip hidden directories and common non-source directories
|
|
30
|
-
dirs[:] = [d for d in dirs if not d.startswith('.') and d not in {'node_modules', '__pycache__', 'venv', 'env'}]
|
|
31
|
-
|
|
32
|
-
for file in files:
|
|
33
|
-
if not file.startswith('.'):
|
|
34
|
-
full_path = os.path.join(root, file)
|
|
35
|
-
src_files.append(full_path)
|
|
36
|
-
|
|
37
|
-
return src_files
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def tool_output(*messages):
|
|
41
|
-
"""Print informational messages."""
|
|
42
|
-
print(*messages, file=sys.stdout)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def tool_warning(message):
|
|
46
|
-
"""Print warning messages."""
|
|
47
|
-
print(f"Warning: {message}", file=sys.stderr)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def tool_error(message):
|
|
51
|
-
"""Print error messages."""
|
|
52
|
-
print(f"Error: {message}", file=sys.stderr)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def main():
|
|
56
|
-
"""Main CLI entry point."""
|
|
57
|
-
parser = argparse.ArgumentParser(
|
|
58
|
-
description="Generate a repository map showing important code structures.",
|
|
59
|
-
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
60
|
-
epilog="""
|
|
61
|
-
Examples:
|
|
62
|
-
%(prog)s . # Map current directory
|
|
63
|
-
%(prog)s src/ --map-tokens 2048 # Map src/ with 2048 token limit
|
|
64
|
-
%(prog)s file1.py file2.py # Map specific files
|
|
65
|
-
%(prog)s --chat-files main.py --other-files src/ # Specify chat vs other files
|
|
66
|
-
"""
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
parser.add_argument(
|
|
70
|
-
"paths",
|
|
71
|
-
nargs="*",
|
|
72
|
-
help="Files or directories to include in the map"
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
parser.add_argument(
|
|
76
|
-
"--root",
|
|
77
|
-
default=".",
|
|
78
|
-
help="Repository root directory (default: current directory)"
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
parser.add_argument(
|
|
82
|
-
"--map-tokens",
|
|
83
|
-
type=int,
|
|
84
|
-
default=8192,
|
|
85
|
-
help="Maximum tokens for the generated map (default: 8192)"
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
parser.add_argument(
|
|
89
|
-
"--chat-files",
|
|
90
|
-
nargs="*",
|
|
91
|
-
help="Files currently being edited (given higher priority)"
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
parser.add_argument(
|
|
95
|
-
"--other-files",
|
|
96
|
-
nargs="*",
|
|
97
|
-
help="Other files to consider for the map"
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
parser.add_argument(
|
|
101
|
-
"--mentioned-files",
|
|
102
|
-
nargs="*",
|
|
103
|
-
help="Files explicitly mentioned (given higher priority)"
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
parser.add_argument(
|
|
107
|
-
"--mentioned-idents",
|
|
108
|
-
nargs="*",
|
|
109
|
-
help="Identifiers explicitly mentioned (given higher priority)"
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
parser.add_argument(
|
|
113
|
-
"--verbose",
|
|
114
|
-
action="store_true",
|
|
115
|
-
help="Enable verbose output"
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
parser.add_argument(
|
|
119
|
-
"--model",
|
|
120
|
-
default="gpt-4",
|
|
121
|
-
help="Model name for token counting (default: gpt-4)"
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
parser.add_argument(
|
|
125
|
-
"--max-context-window",
|
|
126
|
-
type=int,
|
|
127
|
-
help="Maximum context window size"
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
parser.add_argument(
|
|
131
|
-
"--force-refresh",
|
|
132
|
-
action="store_true",
|
|
133
|
-
help="Force refresh of caches"
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
parser.add_argument(
|
|
137
|
-
"--exclude-unranked",
|
|
138
|
-
action="store_true",
|
|
139
|
-
help="Exclude files with Page Rank 0 from the map"
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
args = parser.parse_args()
|
|
143
|
-
|
|
144
|
-
# Set up token counter with specified model
|
|
145
|
-
def token_counter(text: str) -> int:
|
|
146
|
-
return count_tokens(text, args.model)
|
|
147
|
-
|
|
148
|
-
# Set up output handlers
|
|
149
|
-
output_handlers = {
|
|
150
|
-
'info': tool_output,
|
|
151
|
-
'warning': tool_warning,
|
|
152
|
-
'error': tool_error
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
# Process file arguments
|
|
156
|
-
chat_files_from_args = args.chat_files or [] # These are the paths as strings from the CLI
|
|
157
|
-
|
|
158
|
-
# Determine the list of unresolved path specifications that will form the 'other_files'
|
|
159
|
-
# These can be files or directories. find_src_files will expand them.
|
|
160
|
-
unresolved_paths_for_other_files_specs = []
|
|
161
|
-
if args.other_files: # If --other-files is explicitly provided, it's the source
|
|
162
|
-
unresolved_paths_for_other_files_specs.extend(args.other_files)
|
|
163
|
-
elif args.paths: # Else, if positional paths are given, they are the source
|
|
164
|
-
unresolved_paths_for_other_files_specs.extend(args.paths)
|
|
165
|
-
# If neither, unresolved_paths_for_other_files_specs remains empty.
|
|
166
|
-
|
|
167
|
-
# Now, expand all directory paths in unresolved_paths_for_other_files_specs into actual file lists
|
|
168
|
-
# and collect all file paths. find_src_files handles both files and directories.
|
|
169
|
-
effective_other_files_unresolved = []
|
|
170
|
-
for path_spec_str in unresolved_paths_for_other_files_specs:
|
|
171
|
-
effective_other_files_unresolved.extend(find_src_files(path_spec_str))
|
|
172
|
-
|
|
173
|
-
# Convert to absolute paths
|
|
174
|
-
root_path = Path(args.root).resolve()
|
|
175
|
-
# chat_files for RepoMap are from --chat-files argument, resolved.
|
|
176
|
-
chat_files = [str(Path(f).resolve()) for f in chat_files_from_args]
|
|
177
|
-
# other_files for RepoMap are the effective_other_files, resolved after expansion.
|
|
178
|
-
other_files = [str(Path(f).resolve()) for f in effective_other_files_unresolved]
|
|
179
|
-
|
|
180
|
-
print(f"Chat files: {chat_files}")
|
|
181
|
-
|
|
182
|
-
# Convert mentioned files to sets
|
|
183
|
-
mentioned_fnames = set(args.mentioned_files) if args.mentioned_files else None
|
|
184
|
-
mentioned_idents = set(args.mentioned_idents) if args.mentioned_idents else None
|
|
185
|
-
|
|
186
|
-
# Create RepoMap instance
|
|
187
|
-
repo_map = RepoMap(
|
|
188
|
-
map_tokens=args.map_tokens,
|
|
189
|
-
root=str(root_path),
|
|
190
|
-
token_counter_func=token_counter,
|
|
191
|
-
file_reader_func=read_text,
|
|
192
|
-
output_handler_funcs=output_handlers,
|
|
193
|
-
verbose=args.verbose,
|
|
194
|
-
max_context_window=args.max_context_window,
|
|
195
|
-
exclude_unranked=args.exclude_unranked
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
# Generate the map
|
|
199
|
-
try:
|
|
200
|
-
map_content = repo_map.get_repo_map(
|
|
201
|
-
chat_files=chat_files,
|
|
202
|
-
other_files=other_files,
|
|
203
|
-
mentioned_fnames=mentioned_fnames,
|
|
204
|
-
mentioned_idents=mentioned_idents,
|
|
205
|
-
force_refresh=args.force_refresh
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
if map_content:
|
|
209
|
-
if args.verbose:
|
|
210
|
-
tokens = repo_map.token_count(map_content)
|
|
211
|
-
tool_output(f"Generated map: {len(map_content)} chars, ~{tokens} tokens")
|
|
212
|
-
|
|
213
|
-
print(map_content)
|
|
214
|
-
else:
|
|
215
|
-
tool_output("No repository map generated.")
|
|
216
|
-
|
|
217
|
-
except KeyboardInterrupt:
|
|
218
|
-
tool_error("Interrupted by user")
|
|
219
|
-
sys.exit(1)
|
|
220
|
-
except Exception as e:
|
|
221
|
-
tool_error(f"Error generating repository map: {e}")
|
|
222
|
-
if args.verbose:
|
|
223
|
-
import traceback
|
|
224
|
-
traceback.print_exc()
|
|
225
|
-
sys.exit(1)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if __name__ == "__main__":
|
|
229
|
-
main()
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
RepoMapper Bridge for TypeScript communication
|
|
4
|
-
Reads JSON requests from stdin and outputs JSON responses to stdout
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import sys
|
|
8
|
-
import json
|
|
9
|
-
import os
|
|
10
|
-
import logging
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
from typing import Dict, Any, List, Optional
|
|
13
|
-
|
|
14
|
-
# Add the current directory to the path so we can import our modules
|
|
15
|
-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
16
|
-
|
|
17
|
-
from repomap_class import RepoMap
|
|
18
|
-
from utils import count_tokens, read_text
|
|
19
|
-
from scm import get_scm_fname
|
|
20
|
-
from importance import filter_important_files
|
|
21
|
-
|
|
22
|
-
# Suppress logs to stderr to avoid interfering with JSON communication
|
|
23
|
-
root_logger = logging.getLogger()
|
|
24
|
-
root_logger.setLevel(logging.ERROR)
|
|
25
|
-
|
|
26
|
-
def find_src_files(directory: str) -> List[str]:
|
|
27
|
-
"""Find source files in a directory."""
|
|
28
|
-
if not os.path.isdir(directory):
|
|
29
|
-
return [directory] if os.path.isfile(directory) else []
|
|
30
|
-
|
|
31
|
-
src_files = []
|
|
32
|
-
for root, dirs, files in os.walk(directory):
|
|
33
|
-
# Skip hidden directories and common non-source directories
|
|
34
|
-
dirs[:] = [d for d in dirs if not d.startswith('.') and d not in {'node_modules', '__pycache__', 'venv', 'env'}]
|
|
35
|
-
|
|
36
|
-
for file in files:
|
|
37
|
-
if not file.startswith('.'):
|
|
38
|
-
full_path = os.path.join(root, file)
|
|
39
|
-
src_files.append(full_path)
|
|
40
|
-
|
|
41
|
-
return src_files
|
|
42
|
-
|
|
43
|
-
def generate_repo_map(request: Dict[str, Any]) -> Dict[str, Any]:
|
|
44
|
-
"""Generate repository map from request parameters."""
|
|
45
|
-
try:
|
|
46
|
-
project_root = request.get('project_root')
|
|
47
|
-
if not project_root or not os.path.isdir(project_root):
|
|
48
|
-
return {"error": f"Project root directory not found: {project_root}"}
|
|
49
|
-
|
|
50
|
-
# Extract parameters with defaults
|
|
51
|
-
chat_files = request.get('chat_files', [])
|
|
52
|
-
mentioned_files = request.get('mentioned_files', [])
|
|
53
|
-
other_files = request.get('other_files', [])
|
|
54
|
-
mentioned_idents = request.get('mentioned_idents', [])
|
|
55
|
-
token_limit = request.get('token_limit', 8192)
|
|
56
|
-
exclude_unranked = request.get('exclude_unranked', False)
|
|
57
|
-
force_refresh = request.get('force_refresh', False)
|
|
58
|
-
verbose = request.get('verbose', False)
|
|
59
|
-
max_context_window = request.get('max_context_window')
|
|
60
|
-
|
|
61
|
-
# Convert to sets for mentioned items
|
|
62
|
-
mentioned_fnames_set = set(mentioned_files) if mentioned_files else None
|
|
63
|
-
mentioned_idents_set = set(mentioned_idents) if mentioned_idents else None
|
|
64
|
-
|
|
65
|
-
# If no other_files specified, auto-discover
|
|
66
|
-
effective_other_files = other_files if other_files else find_src_files(project_root)
|
|
67
|
-
|
|
68
|
-
# Convert to absolute paths
|
|
69
|
-
root_path = Path(project_root).resolve()
|
|
70
|
-
abs_chat_files = [str(root_path / f) for f in chat_files] if chat_files else []
|
|
71
|
-
abs_other_files = [str(root_path / f) for f in effective_other_files] if effective_other_files else []
|
|
72
|
-
|
|
73
|
-
# Remove any chat files from other_files to avoid duplication
|
|
74
|
-
abs_chat_files_set = set(abs_chat_files)
|
|
75
|
-
abs_other_files = [f for f in abs_other_files if f not in abs_chat_files_set]
|
|
76
|
-
|
|
77
|
-
# Create output handlers that suppress output
|
|
78
|
-
output_handlers = {
|
|
79
|
-
'info': lambda *args: None,
|
|
80
|
-
'warning': lambda *args: None,
|
|
81
|
-
'error': lambda *args: None
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
# Create RepoMap instance
|
|
85
|
-
repo_mapper = RepoMap(
|
|
86
|
-
map_tokens=token_limit,
|
|
87
|
-
root=str(root_path),
|
|
88
|
-
token_counter_func=lambda text: count_tokens(text, "gpt-4"),
|
|
89
|
-
file_reader_func=read_text,
|
|
90
|
-
output_handler_funcs=output_handlers,
|
|
91
|
-
verbose=verbose,
|
|
92
|
-
exclude_unranked=exclude_unranked,
|
|
93
|
-
max_context_window=max_context_window
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
# Generate the repository map
|
|
97
|
-
map_content, file_report = repo_mapper.get_repo_map(
|
|
98
|
-
chat_files=abs_chat_files,
|
|
99
|
-
other_files=abs_other_files,
|
|
100
|
-
mentioned_fnames=mentioned_fnames_set,
|
|
101
|
-
mentioned_idents=mentioned_idents_set,
|
|
102
|
-
force_refresh=force_refresh,
|
|
103
|
-
show_preview=True # Ensure we get the full map content, not just "complete"
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
# Convert FileReport to dictionary for JSON serialization
|
|
107
|
-
report_dict = {
|
|
108
|
-
"excluded": file_report.excluded,
|
|
109
|
-
"definition_matches": file_report.definition_matches,
|
|
110
|
-
"reference_matches": file_report.reference_matches,
|
|
111
|
-
"total_files_considered": file_report.total_files_considered
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
"map": map_content or "No repository map could be generated.",
|
|
116
|
-
"report": report_dict
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
except Exception as e:
|
|
120
|
-
return {"error": f"Error generating repository map: {str(e)}"}
|
|
121
|
-
|
|
122
|
-
def search_identifiers(request: Dict[str, Any]) -> Dict[str, Any]:
|
|
123
|
-
"""Search for identifiers in the codebase."""
|
|
124
|
-
try:
|
|
125
|
-
project_root = request.get('project_root')
|
|
126
|
-
if not project_root or not os.path.isdir(project_root):
|
|
127
|
-
return {"error": f"Project root directory not found: {project_root}"}
|
|
128
|
-
|
|
129
|
-
query = request.get('query', '')
|
|
130
|
-
max_results = request.get('max_results', 50)
|
|
131
|
-
context_lines = request.get('context_lines', 2)
|
|
132
|
-
include_definitions = request.get('include_definitions', True)
|
|
133
|
-
include_references = request.get('include_references', True)
|
|
134
|
-
|
|
135
|
-
# Create RepoMap instance for searching
|
|
136
|
-
repo_map = RepoMap(
|
|
137
|
-
root=project_root,
|
|
138
|
-
token_counter_func=lambda text: count_tokens(text, "gpt-4"),
|
|
139
|
-
file_reader_func=read_text,
|
|
140
|
-
output_handler_funcs={'info': lambda *args: None, 'warning': lambda *args: None, 'error': lambda *args: None},
|
|
141
|
-
verbose=False,
|
|
142
|
-
exclude_unranked=True
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
# Find all source files
|
|
146
|
-
all_files = find_src_files(project_root)
|
|
147
|
-
|
|
148
|
-
# Get all tags for all files
|
|
149
|
-
all_tags = []
|
|
150
|
-
for file_path in all_files:
|
|
151
|
-
rel_path = str(Path(file_path).relative_to(project_root))
|
|
152
|
-
tags = repo_map.get_tags(file_path, rel_path)
|
|
153
|
-
all_tags.extend(tags)
|
|
154
|
-
|
|
155
|
-
# Filter tags based on search query and options
|
|
156
|
-
matching_tags = []
|
|
157
|
-
query_lower = query.lower()
|
|
158
|
-
|
|
159
|
-
for tag in all_tags:
|
|
160
|
-
if query_lower in tag.name.lower():
|
|
161
|
-
if (tag.kind == "def" and include_definitions) or \
|
|
162
|
-
(tag.kind == "ref" and include_references):
|
|
163
|
-
matching_tags.append(tag)
|
|
164
|
-
|
|
165
|
-
# Sort by relevance (definitions first, then references)
|
|
166
|
-
matching_tags.sort(key=lambda x: (x.kind != "def", x.name.lower().find(query_lower)))
|
|
167
|
-
|
|
168
|
-
# Limit results
|
|
169
|
-
matching_tags = matching_tags[:max_results]
|
|
170
|
-
|
|
171
|
-
# Format results with context
|
|
172
|
-
results = []
|
|
173
|
-
for tag in matching_tags:
|
|
174
|
-
file_path = str(Path(project_root) / tag.rel_fname)
|
|
175
|
-
|
|
176
|
-
# Calculate context range
|
|
177
|
-
start_line = max(1, tag.line - context_lines)
|
|
178
|
-
end_line = tag.line + context_lines
|
|
179
|
-
context_range = list(range(start_line, end_line + 1))
|
|
180
|
-
|
|
181
|
-
context = repo_map.render_tree(
|
|
182
|
-
file_path,
|
|
183
|
-
tag.rel_fname,
|
|
184
|
-
context_range
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
if context:
|
|
188
|
-
results.append({
|
|
189
|
-
"file": tag.rel_fname,
|
|
190
|
-
"line": tag.line,
|
|
191
|
-
"name": tag.name,
|
|
192
|
-
"kind": tag.kind,
|
|
193
|
-
"context": context
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
return {"results": results}
|
|
197
|
-
|
|
198
|
-
except Exception as e:
|
|
199
|
-
return {"error": f"Error searching identifiers: {str(e)}"}
|
|
200
|
-
|
|
201
|
-
def main():
|
|
202
|
-
"""Main bridge entry point - reads JSON from stdin, processes request, outputs JSON to stdout."""
|
|
203
|
-
try:
|
|
204
|
-
# Read JSON request from stdin
|
|
205
|
-
input_data = sys.stdin.read().strip()
|
|
206
|
-
if not input_data:
|
|
207
|
-
result = {"error": "No input data received"}
|
|
208
|
-
else:
|
|
209
|
-
request = json.loads(input_data)
|
|
210
|
-
|
|
211
|
-
# Check for action type
|
|
212
|
-
action = request.get('action', 'repo_map')
|
|
213
|
-
|
|
214
|
-
if action == 'search_identifiers':
|
|
215
|
-
result = search_identifiers(request)
|
|
216
|
-
else:
|
|
217
|
-
# Default action is to generate repository map
|
|
218
|
-
result = generate_repo_map(request)
|
|
219
|
-
|
|
220
|
-
# Output JSON result to stdout
|
|
221
|
-
print(json.dumps(result, indent=2))
|
|
222
|
-
|
|
223
|
-
except json.JSONDecodeError as e:
|
|
224
|
-
error_result = {"error": f"Invalid JSON input: {str(e)}"}
|
|
225
|
-
print(json.dumps(error_result, indent=2))
|
|
226
|
-
sys.exit(1)
|
|
227
|
-
|
|
228
|
-
except Exception as e:
|
|
229
|
-
error_result = {"error": f"Unexpected error: {str(e)}"}
|
|
230
|
-
print(json.dumps(error_result, indent=2))
|
|
231
|
-
sys.exit(1)
|
|
232
|
-
|
|
233
|
-
if __name__ == "__main__":
|
|
234
|
-
main()
|