@teevee98/synapse-hub 3.8.4 → 3.9.0
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/.agents/rules/author-integrity-guard.md +13 -10
- package/.agents/rules/skill-precedence.md +6 -4
- package/.agents/skills/agent-orchestration-multi-agent-optimize/SKILL.md +1 -1
- package/.agents/skills/agentless-qa-repair/SKILL.md +1 -1
- package/.agents/skills/auth-session-and-cookie-manager/SKILL.md +22 -2
- package/.agents/skills/qa-memory-os/SKILL.md +21 -4
- package/.agents/skills/security-dast-sentinel/SKILL.md +1 -1
- package/.agents/skills/token-and-context-optimizer/SKILL.md +1 -1
- package/.agents/skills/verification-before-completion/SKILL.md +1 -1
- package/AGENTS.md +3 -2
- package/CLAUDE.md +3 -3
- package/NOTICE +48 -0
- package/README.en.md +9 -9
- package/README.md +9 -9
- package/agentskills.json +1 -1
- package/bin/agent-qa.js +1 -1
- package/docs/ARCHITECTURE.en.md +7 -3
- package/docs/ARCHITECTURE.md +6 -2
- package/docs/CI_CD_INTEGRATION.en.md +6 -6
- package/docs/CI_CD_INTEGRATION.md +6 -6
- package/docs/CLI_REFERENCE.md +1 -1
- package/docs/PERFORMANCE_AUDIT_REPORT.md +1 -1
- package/docs/QUALITY_GATES.en.md +1 -1
- package/docs/QUALITY_GATES.md +1 -1
- package/docs/adopted-ecosystem-tools.md +37 -0
- package/docs/diagrams/clean_pom.svg +48 -0
- package/docs/diagrams/fsm_flow.svg +78 -0
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/skills_manifest.json +103 -54
- package/synapse.config.json +1 -1
- package/templates/PROJECT_AI_GUIDE_TEMPLATE.md +3 -3
- package/templates/ai_bridges/CLAUDE.md +3 -3
- package/templates/ci/github-actions-synapse.yml +2 -2
- package/templates/ci/gitlab-ci-synapse.yml +1 -1
- package/templates/ui/index.html +2 -2
- package/templates/welcome.html.tmpl +26 -26
- package/tools/TOOLS_RUNBOOK.md +8 -8
- package/tools/__init__.py +1 -1
- package/tools/analyze_project.py +2 -2
- package/tools/browser_helpers.js +2 -2
- package/tools/build_consolidated_report.py +1640 -0
- package/tools/bump_version.py +5 -15
- package/tools/cli.py +3 -3
- package/tools/count_tokens.py +29 -5
- package/tools/dashboard_generator.py +10 -10
- package/tools/diagram_architect.py +220 -0
- package/tools/distill_log.py +33 -8
- package/tools/git_worktree_manager.py +185 -0
- package/tools/hub_publisher.py +38 -0
- package/tools/humanize_linter.py +4 -0
- package/tools/interview_story.py +25 -2
- package/tools/mcp_docx_server.py +1 -1
- package/tools/mcp_excel_server.py +1 -1
- package/tools/mcp_server.py +1 -1
- package/tools/mechanical_ui_gate.py +242 -0
- package/tools/pairwise_generator.py +175 -0
- package/tools/repo_map.py +308 -106
- package/tools/runaway_stopper.py +178 -0
- package/tools/setup_project.py +3 -3
- package/tools/sync_agent_rules.py +3 -3
- package/tools/ui_server.py +1 -1
- package/tools/update_sentinel.py +6 -6
- package/tools/verify_all.py +15 -0
- package/tools/welcome_page.py +2 -2
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
tools/pairwise_generator.py — Pairwise (2-Way) Combinatorial Test Case Generator
|
|
5
|
+
Inspired by Composio / pypict combinatorial testing patterns.
|
|
6
|
+
Generates minimal test execution matrices covering 100% of 2-way parameter pairs,
|
|
7
|
+
reducing test case bloat by 80-90% while guaranteeing pairwise boundary coverage.
|
|
8
|
+
100% UTF-8 No BOM.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import sys
|
|
12
|
+
import json
|
|
13
|
+
import argparse
|
|
14
|
+
import itertools
|
|
15
|
+
from typing import Dict, List, Any, Set, Tuple
|
|
16
|
+
|
|
17
|
+
# Enforce UTF-8 stdout encoding
|
|
18
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
19
|
+
try:
|
|
20
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
21
|
+
sys.stderr.reconfigure(encoding="utf-8")
|
|
22
|
+
except Exception:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
def generate_all_pairs(parameters: Dict[str, List[Any]]) -> Set[Tuple[Tuple[str, Any], Tuple[str, Any]]]:
|
|
26
|
+
"""Generates all 2-way parameter value pairs."""
|
|
27
|
+
param_keys = sorted(parameters.keys())
|
|
28
|
+
all_pairs: Set[Tuple[Tuple[str, Any], Tuple[str, Any]]] = set()
|
|
29
|
+
|
|
30
|
+
for i in range(len(param_keys)):
|
|
31
|
+
for j in range(i + 1, len(param_keys)):
|
|
32
|
+
p1 = param_keys[i]
|
|
33
|
+
p2 = param_keys[j]
|
|
34
|
+
for v1 in parameters[p1]:
|
|
35
|
+
for v2 in parameters[p2]:
|
|
36
|
+
# Canonical ordered pair
|
|
37
|
+
pair = ((p1, v1), (p2, v2))
|
|
38
|
+
all_pairs.add(pair)
|
|
39
|
+
return all_pairs
|
|
40
|
+
|
|
41
|
+
def score_candidate(candidate: Dict[str, Any], uncovered_pairs: Set[Tuple[Tuple[str, Any], Tuple[str, Any]]]) -> int:
|
|
42
|
+
"""Calculates how many uncovered pairs a complete candidate test case satisfies."""
|
|
43
|
+
keys = sorted(candidate.keys())
|
|
44
|
+
count = 0
|
|
45
|
+
for i in range(len(keys)):
|
|
46
|
+
for j in range(i + 1, len(keys)):
|
|
47
|
+
p1, p2 = keys[i], keys[j]
|
|
48
|
+
pair = ((p1, candidate[p1]), (p2, candidate[p2]))
|
|
49
|
+
if pair in uncovered_pairs:
|
|
50
|
+
count += 1
|
|
51
|
+
return count
|
|
52
|
+
|
|
53
|
+
def generate_pairwise(parameters: Dict[str, List[Any]]) -> List[Dict[str, Any]]:
|
|
54
|
+
"""
|
|
55
|
+
Greedy Pairwise (IPOG-inspired) test suite generation.
|
|
56
|
+
Guarantees 100% pairwise coverage of parameter combinations.
|
|
57
|
+
"""
|
|
58
|
+
if not parameters or any(len(v) == 0 for v in parameters.values()):
|
|
59
|
+
return []
|
|
60
|
+
|
|
61
|
+
param_keys = sorted(parameters.keys())
|
|
62
|
+
if len(param_keys) == 1:
|
|
63
|
+
# Single parameter: return each value
|
|
64
|
+
p = param_keys[0]
|
|
65
|
+
return [{p: v} for v in parameters[p]]
|
|
66
|
+
|
|
67
|
+
uncovered_pairs = generate_all_pairs(parameters)
|
|
68
|
+
total_pairs = len(uncovered_pairs)
|
|
69
|
+
test_cases: List[Dict[str, Any]] = []
|
|
70
|
+
|
|
71
|
+
# Sort parameters by domain size descending for faster coverage
|
|
72
|
+
sorted_keys = sorted(param_keys, key=lambda k: len(parameters[k]), reverse=True)
|
|
73
|
+
|
|
74
|
+
while uncovered_pairs:
|
|
75
|
+
# Pick the pair with highest priority
|
|
76
|
+
target_pair = next(iter(uncovered_pairs))
|
|
77
|
+
p1, v1 = target_pair[0]
|
|
78
|
+
p2, v2 = target_pair[1]
|
|
79
|
+
|
|
80
|
+
# Initialize candidate with this pair
|
|
81
|
+
candidate: Dict[str, Any] = {p1: v1, p2: v2}
|
|
82
|
+
|
|
83
|
+
# Greedily assign remaining parameters to maximize pair coverage
|
|
84
|
+
for key in sorted_keys:
|
|
85
|
+
if key in candidate:
|
|
86
|
+
continue
|
|
87
|
+
|
|
88
|
+
best_val = parameters[key][0]
|
|
89
|
+
best_score = -1
|
|
90
|
+
|
|
91
|
+
for val in parameters[key]:
|
|
92
|
+
temp_cand = dict(candidate)
|
|
93
|
+
temp_cand[key] = val
|
|
94
|
+
# Count pairs this assignment would cover with already-fixed params
|
|
95
|
+
score = 0
|
|
96
|
+
for fixed_key, fixed_val in candidate.items():
|
|
97
|
+
p_a, v_a = (key, val) if key < fixed_key else (fixed_key, fixed_val)
|
|
98
|
+
p_b, v_b = (fixed_key, fixed_val) if key < fixed_key else (key, val)
|
|
99
|
+
if ((p_a, v_a), (p_b, v_b)) in uncovered_pairs:
|
|
100
|
+
score += 1
|
|
101
|
+
if score > best_score:
|
|
102
|
+
best_score = score
|
|
103
|
+
best_val = val
|
|
104
|
+
|
|
105
|
+
candidate[key] = best_val
|
|
106
|
+
|
|
107
|
+
# Ensure all keys are populated
|
|
108
|
+
for key in param_keys:
|
|
109
|
+
if key not in candidate:
|
|
110
|
+
candidate[key] = parameters[key][0]
|
|
111
|
+
|
|
112
|
+
# Remove covered pairs from uncovered set
|
|
113
|
+
for i in range(len(param_keys)):
|
|
114
|
+
for j in range(i + 1, len(param_keys)):
|
|
115
|
+
k1, k2 = param_keys[i], param_keys[j]
|
|
116
|
+
pair = ((k1, candidate[k1]), (k2, candidate[k2]))
|
|
117
|
+
uncovered_pairs.discard(pair)
|
|
118
|
+
|
|
119
|
+
test_cases.append(candidate)
|
|
120
|
+
|
|
121
|
+
return test_cases
|
|
122
|
+
|
|
123
|
+
def main():
|
|
124
|
+
parser = argparse.ArgumentParser(description="Generate pairwise (2-way) combinatorial test suites.")
|
|
125
|
+
parser.add_argument("--params", "-p", help="JSON string or file path containing parameter domains.")
|
|
126
|
+
parser.add_argument("--json", action="store_true", help="Output JSON format.")
|
|
127
|
+
args = parser.parse_args()
|
|
128
|
+
|
|
129
|
+
if not args.params:
|
|
130
|
+
# Default sample parameters
|
|
131
|
+
sample_params = {
|
|
132
|
+
"browser": ["chromium", "firefox", "webkit"],
|
|
133
|
+
"viewport": ["desktop_1920x1080", "mobile_390x844"],
|
|
134
|
+
"user_role": ["admin", "editor", "viewer"],
|
|
135
|
+
"auth_state": ["logged_in", "anonymous"]
|
|
136
|
+
}
|
|
137
|
+
params = sample_params
|
|
138
|
+
else:
|
|
139
|
+
try:
|
|
140
|
+
if args.params.startswith("{"):
|
|
141
|
+
params = json.loads(args.params)
|
|
142
|
+
else:
|
|
143
|
+
with open(args.params, "r", encoding="utf-8") as f:
|
|
144
|
+
params = json.load(f)
|
|
145
|
+
except Exception as e:
|
|
146
|
+
print(f"Error parsing parameters: {e}", file=sys.stderr)
|
|
147
|
+
sys.exit(1)
|
|
148
|
+
|
|
149
|
+
all_pairs = generate_all_pairs(params)
|
|
150
|
+
cases = generate_pairwise(params)
|
|
151
|
+
full_combinations = 1 if params else 0
|
|
152
|
+
for k, v in params.items():
|
|
153
|
+
full_combinations *= len(v)
|
|
154
|
+
|
|
155
|
+
reduction = round((1.0 - len(cases) / full_combinations) * 100, 1) if full_combinations > 0 else 0.0
|
|
156
|
+
|
|
157
|
+
if args.json:
|
|
158
|
+
print(json.dumps({
|
|
159
|
+
"total_full_permutations": full_combinations,
|
|
160
|
+
"pairwise_test_count": len(cases),
|
|
161
|
+
"total_2way_pairs": len(all_pairs),
|
|
162
|
+
"reduction_pct": reduction,
|
|
163
|
+
"test_cases": cases
|
|
164
|
+
}, indent=2))
|
|
165
|
+
else:
|
|
166
|
+
print(f"[PAIRWISE GENERATOR] Parameters: {len(params)} | Total Permutations: {full_combinations}")
|
|
167
|
+
print(f" Optimized Pairwise Cases: {len(cases)} (Covering {len(all_pairs)} 2-way interactions)")
|
|
168
|
+
print(f" Reduction: {reduction}% test case reduction!")
|
|
169
|
+
print("\nGenerated Test Matrix:")
|
|
170
|
+
for idx, tc in enumerate(cases, 1):
|
|
171
|
+
formatted = ", ".join(f"{k}={v}" for k, v in tc.items())
|
|
172
|
+
print(f" TC-{idx:02d}: {formatted}")
|
|
173
|
+
|
|
174
|
+
if __name__ == "__main__":
|
|
175
|
+
main()
|
package/tools/repo_map.py
CHANGED
|
@@ -14,6 +14,8 @@ import sys
|
|
|
14
14
|
import re
|
|
15
15
|
import json
|
|
16
16
|
import argparse
|
|
17
|
+
import ast
|
|
18
|
+
import copy
|
|
17
19
|
from datetime import datetime
|
|
18
20
|
|
|
19
21
|
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -21,14 +23,12 @@ HUB_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, ".."))
|
|
|
21
23
|
OUTPUT_TXT = os.path.join(SCRIPT_DIR, "repo_map.txt")
|
|
22
24
|
OUTPUT_JSON = os.path.join(SCRIPT_DIR, "repo_map.json")
|
|
23
25
|
|
|
24
|
-
# Regex patterns for Groovy/Java classes and methods
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
METHOD_PATTERN = re.compile(
|
|
28
|
-
r'^\s*(?:@\w+\s+)*(?:public\s+|protected\s+|private\s+)?(?:static\s+)?(?:async\s+)?(?:def\s+|void\s+|[\w<>\[\],]+\s+)?(\w+)\s*\(([^)]*)\)\s*(?:throws\s+[\w,\s]+)?\s*\{',
|
|
26
|
+
# Regex patterns for Groovy/Java/TS/JS classes and methods
|
|
27
|
+
CLASS_DECL_PATTERN = re.compile(
|
|
28
|
+
r'(?:^|\s)(?:export\s+|public\s+|default\s+|abstract\s+|final\s+)*class\s+([A-Za-z0-9_]+)(?:\s*<[^>]*>)?(?:\s+extends\s+([A-Za-z0-9_]+)(?:<[^>]*>)?)?',
|
|
29
29
|
re.MULTILINE
|
|
30
30
|
)
|
|
31
|
-
|
|
31
|
+
CONTROL_KEYWORDS = {"if", "for", "while", "switch", "catch", "synchronized", "constructor"}
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
def resolve_target_repo(cli_target=None, cli_repo=None):
|
|
@@ -59,8 +59,282 @@ def resolve_target_repo(cli_target=None, cli_repo=None):
|
|
|
59
59
|
return HUB_ROOT
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
def strip_comments_and_strings(source_code: str) -> str:
|
|
63
|
+
"""Strips comments, string literals, and template strings preserving line numbers and string length."""
|
|
64
|
+
pattern = re.compile(
|
|
65
|
+
r'(?P<BLOCK_COMMENT>/\*[\s\S]*?\*/)|'
|
|
66
|
+
r'(?P<LINE_COMMENT>//[^\r\n]*)|'
|
|
67
|
+
r'(?P<TRIPLE_DOUBLE>"""[\s\S]*?""")|'
|
|
68
|
+
r'(?P<TRIPLE_SINGLE>\'\'\'[\s\S]*?\'\'\')|'
|
|
69
|
+
r'(?P<DOLLAR_SLASHY>\$/[\s\S]*?/\$)|'
|
|
70
|
+
r'(?P<DOUBLE_STRING>"(?:\\.|[^"\\])*")|'
|
|
71
|
+
r'(?P<SINGLE_STRING>\'(?:\\.|[^\'\\])*\')|'
|
|
72
|
+
r'(?P<BACKTICK_STRING>`(?:\\.|[^`\\])*`)',
|
|
73
|
+
re.DOTALL
|
|
74
|
+
)
|
|
75
|
+
return pattern.sub(lambda m: re.sub(r'[^\r\n]', ' ', m.group(0)), source_code)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def clean_param_sig(p: str) -> str:
|
|
79
|
+
"""Simplifies parameter list for compact, token-budgeted method signatures."""
|
|
80
|
+
if not p:
|
|
81
|
+
return ""
|
|
82
|
+
params = []
|
|
83
|
+
current = []
|
|
84
|
+
bracket_depth = 0
|
|
85
|
+
for char in p:
|
|
86
|
+
if char in "([<":
|
|
87
|
+
bracket_depth += 1
|
|
88
|
+
current.append(char)
|
|
89
|
+
elif char in ")]>":
|
|
90
|
+
bracket_depth = max(0, bracket_depth - 1)
|
|
91
|
+
current.append(char)
|
|
92
|
+
elif char == "," and bracket_depth == 0:
|
|
93
|
+
params.append("".join(current).strip())
|
|
94
|
+
current = []
|
|
95
|
+
else:
|
|
96
|
+
current.append(char)
|
|
97
|
+
if current:
|
|
98
|
+
params.append("".join(current).strip())
|
|
99
|
+
|
|
100
|
+
res = []
|
|
101
|
+
for item in params:
|
|
102
|
+
if not item:
|
|
103
|
+
continue
|
|
104
|
+
if "=" in item:
|
|
105
|
+
item = item.split("=")[0].strip()
|
|
106
|
+
if ":" in item:
|
|
107
|
+
item = item.split(":")[0].strip()
|
|
108
|
+
parts = item.split()
|
|
109
|
+
if len(parts) > 1:
|
|
110
|
+
item = parts[-1]
|
|
111
|
+
res.append(item)
|
|
112
|
+
return ", ".join(res)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _extract_classes_py(content: str, rel_path: str, raw_size_bytes: int, line_count: int) -> list:
|
|
116
|
+
"""Uses Python built-in AST to extract class definitions and direct methods, ignoring nested local functions."""
|
|
117
|
+
try:
|
|
118
|
+
tree = ast.parse(content)
|
|
119
|
+
except Exception:
|
|
120
|
+
return []
|
|
121
|
+
|
|
122
|
+
classes = []
|
|
123
|
+
for node in tree.body:
|
|
124
|
+
if isinstance(node, ast.ClassDef):
|
|
125
|
+
class_name = node.name
|
|
126
|
+
extends_name = ""
|
|
127
|
+
if node.bases:
|
|
128
|
+
base = node.bases[0]
|
|
129
|
+
if isinstance(base, ast.Name):
|
|
130
|
+
extends_name = base.id
|
|
131
|
+
elif isinstance(base, ast.Attribute):
|
|
132
|
+
extends_name = base.attr
|
|
133
|
+
elif hasattr(ast, "unparse"):
|
|
134
|
+
extends_name = ast.unparse(base)
|
|
135
|
+
|
|
136
|
+
methods = []
|
|
137
|
+
for item in node.body:
|
|
138
|
+
if isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
139
|
+
name = item.name
|
|
140
|
+
if name.startswith("__") or name in CONTROL_KEYWORDS:
|
|
141
|
+
continue
|
|
142
|
+
args_copy = copy.deepcopy(item.args)
|
|
143
|
+
if getattr(args_copy, "posonlyargs", None) and args_copy.posonlyargs and args_copy.posonlyargs[0].arg in ("self", "cls"):
|
|
144
|
+
args_copy.posonlyargs.pop(0)
|
|
145
|
+
elif args_copy.args and args_copy.args[0].arg in ("self", "cls"):
|
|
146
|
+
args_copy.args.pop(0)
|
|
147
|
+
raw_params = ast.unparse(args_copy) if hasattr(ast, "unparse") else ""
|
|
148
|
+
doc = ast.get_docstring(item) or ""
|
|
149
|
+
first_doc = doc.strip().splitlines()[0] if doc.strip() else ""
|
|
150
|
+
methods.append({
|
|
151
|
+
"name": name,
|
|
152
|
+
"params": clean_param_sig(re.sub(r'\s+', ' ', raw_params)),
|
|
153
|
+
"comment": first_doc
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
seen = set()
|
|
157
|
+
unique_methods = []
|
|
158
|
+
for meth in methods:
|
|
159
|
+
sig = f"{meth['name']}({meth['params']})"
|
|
160
|
+
if sig not in seen:
|
|
161
|
+
seen.add(sig)
|
|
162
|
+
unique_methods.append(meth)
|
|
163
|
+
|
|
164
|
+
classes.append({
|
|
165
|
+
"rel_path": rel_path,
|
|
166
|
+
"class_name": class_name,
|
|
167
|
+
"extends": extends_name,
|
|
168
|
+
"raw_size_bytes": raw_size_bytes,
|
|
169
|
+
"line_count": line_count,
|
|
170
|
+
"methods": unique_methods
|
|
171
|
+
})
|
|
172
|
+
return classes
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _extract_classes_brace(content: str, rel_path: str, raw_size_bytes: int, line_count: int) -> list:
|
|
176
|
+
"""
|
|
177
|
+
Parses TS, JS, Groovy, Java tracking brace depth to only capture methods at direct class body level (depth 1).
|
|
178
|
+
Eliminates false-positive method calls inside function bodies.
|
|
179
|
+
Supports multiple classes per file, multiline method declarations, and multiline class headers.
|
|
180
|
+
"""
|
|
181
|
+
clean = strip_comments_and_strings(content)
|
|
182
|
+
orig_lines = content.splitlines()
|
|
183
|
+
clean_lines = clean.splitlines()
|
|
184
|
+
classes = []
|
|
185
|
+
|
|
186
|
+
current_class = None
|
|
187
|
+
pending_class = None
|
|
188
|
+
class_depth = 0
|
|
189
|
+
depth = 0
|
|
190
|
+
pending_method = None
|
|
191
|
+
in_multiline_annotation = False
|
|
192
|
+
|
|
193
|
+
for idx, (orig_line, clean_line) in enumerate(zip(orig_lines, clean_lines)):
|
|
194
|
+
clean_strip = clean_line.strip()
|
|
195
|
+
|
|
196
|
+
# Check for class declaration when not in class
|
|
197
|
+
if current_class is None and pending_class is None:
|
|
198
|
+
m = CLASS_DECL_PATTERN.search(clean_line)
|
|
199
|
+
if m:
|
|
200
|
+
eq_pos = clean_line.find("=")
|
|
201
|
+
cls_pos = m.start()
|
|
202
|
+
if eq_pos == -1 or cls_pos < eq_pos:
|
|
203
|
+
pending_class = {
|
|
204
|
+
"rel_path": rel_path,
|
|
205
|
+
"class_name": m.group(1),
|
|
206
|
+
"extends": m.group(2) or "",
|
|
207
|
+
"raw_size_bytes": raw_size_bytes,
|
|
208
|
+
"line_count": line_count,
|
|
209
|
+
"methods": [],
|
|
210
|
+
"decl_depth": depth
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if pending_class is not None and current_class is None:
|
|
214
|
+
if not pending_class["extends"]:
|
|
215
|
+
ext_m = re.search(r'\bextends\s+([A-Za-z0-9_]+)', clean_line)
|
|
216
|
+
if ext_m:
|
|
217
|
+
pending_class["extends"] = ext_m.group(1)
|
|
218
|
+
if "{" in clean_line:
|
|
219
|
+
current_class = pending_class
|
|
220
|
+
pending_class = None
|
|
221
|
+
class_depth = current_class["decl_depth"] + 1
|
|
222
|
+
|
|
223
|
+
if current_class is not None:
|
|
224
|
+
# Handle multiline annotations
|
|
225
|
+
if in_multiline_annotation:
|
|
226
|
+
if ")" in clean_strip:
|
|
227
|
+
in_multiline_annotation = False
|
|
228
|
+
clean_strip = clean_strip[clean_strip.find(")") + 1:].strip()
|
|
229
|
+
else:
|
|
230
|
+
clean_strip = ""
|
|
231
|
+
|
|
232
|
+
# Check and strip annotations (e.g. @Keyword(...), @Step(...))
|
|
233
|
+
if clean_strip.startswith("@"):
|
|
234
|
+
open_p = clean_strip.count("(")
|
|
235
|
+
close_p = clean_strip.count(")")
|
|
236
|
+
if open_p > close_p:
|
|
237
|
+
in_multiline_annotation = True
|
|
238
|
+
clean_strip = ""
|
|
239
|
+
else:
|
|
240
|
+
clean_strip = re.sub(r'^\s*@\w+(?:\([^)]*\))?\s*', '', clean_strip).strip()
|
|
241
|
+
|
|
242
|
+
if pending_method is not None:
|
|
243
|
+
# Accumulate multiline parameters
|
|
244
|
+
for char in clean_line:
|
|
245
|
+
if char == "(":
|
|
246
|
+
pending_method["paren_depth"] += 1
|
|
247
|
+
pending_method["param_parts"].append(char)
|
|
248
|
+
elif char == ")":
|
|
249
|
+
pending_method["paren_depth"] -= 1
|
|
250
|
+
if pending_method["paren_depth"] == 0:
|
|
251
|
+
raw_params = "".join(pending_method["param_parts"]).strip()
|
|
252
|
+
current_class["methods"].append({
|
|
253
|
+
"name": pending_method["name"],
|
|
254
|
+
"params": clean_param_sig(re.sub(r'\s+', ' ', raw_params)),
|
|
255
|
+
"comment": pending_method["comment"]
|
|
256
|
+
})
|
|
257
|
+
pending_method = None
|
|
258
|
+
break
|
|
259
|
+
else:
|
|
260
|
+
pending_method["param_parts"].append(char)
|
|
261
|
+
else:
|
|
262
|
+
pending_method["param_parts"].append(char)
|
|
263
|
+
|
|
264
|
+
elif depth == class_depth and clean_strip:
|
|
265
|
+
eq_pos = clean_strip.find("=")
|
|
266
|
+
paren_pos = clean_strip.find("(")
|
|
267
|
+
if paren_pos != -1 and (eq_pos == -1 or paren_pos < eq_pos):
|
|
268
|
+
meth_start_m = re.search(
|
|
269
|
+
r'(?:public\s+|protected\s+|private\s+|static\s+|async\s+|def\s+|void\s+|[\w<>\[\],]+\s+)*([a-zA-Z_]\w*)\s*\(',
|
|
270
|
+
clean_strip
|
|
271
|
+
)
|
|
272
|
+
if meth_start_m:
|
|
273
|
+
name = meth_start_m.group(1)
|
|
274
|
+
if name not in CONTROL_KEYWORDS and name != current_class["class_name"]:
|
|
275
|
+
start_p = meth_start_m.end() - 1
|
|
276
|
+
paren_depth = 0
|
|
277
|
+
param_parts = []
|
|
278
|
+
finished = False
|
|
279
|
+
for char in clean_strip[start_p:]:
|
|
280
|
+
if char == "(":
|
|
281
|
+
paren_depth += 1
|
|
282
|
+
if paren_depth > 1:
|
|
283
|
+
param_parts.append(char)
|
|
284
|
+
elif char == ")":
|
|
285
|
+
paren_depth -= 1
|
|
286
|
+
if paren_depth == 0:
|
|
287
|
+
finished = True
|
|
288
|
+
break
|
|
289
|
+
else:
|
|
290
|
+
param_parts.append(char)
|
|
291
|
+
else:
|
|
292
|
+
param_parts.append(char)
|
|
293
|
+
|
|
294
|
+
comment = ""
|
|
295
|
+
if idx > 0 and orig_lines[idx - 1].strip().startswith("//"):
|
|
296
|
+
comment = orig_lines[idx - 1].strip().lstrip("/ ").strip()
|
|
297
|
+
|
|
298
|
+
if finished:
|
|
299
|
+
raw_params = "".join(param_parts).strip()
|
|
300
|
+
current_class["methods"].append({
|
|
301
|
+
"name": name,
|
|
302
|
+
"params": clean_param_sig(re.sub(r'\s+', ' ', raw_params)),
|
|
303
|
+
"comment": comment
|
|
304
|
+
})
|
|
305
|
+
else:
|
|
306
|
+
pending_method = {
|
|
307
|
+
"name": name,
|
|
308
|
+
"comment": comment,
|
|
309
|
+
"paren_depth": paren_depth,
|
|
310
|
+
"param_parts": param_parts
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
open_braces = clean_line.count("{")
|
|
314
|
+
close_braces = clean_line.count("}")
|
|
315
|
+
depth += (open_braces - close_braces)
|
|
316
|
+
|
|
317
|
+
if depth < class_depth:
|
|
318
|
+
seen = set()
|
|
319
|
+
unique_methods = []
|
|
320
|
+
for meth in current_class["methods"]:
|
|
321
|
+
sig = f"{meth['name']}({meth['params']})"
|
|
322
|
+
if sig not in seen:
|
|
323
|
+
seen.add(sig)
|
|
324
|
+
unique_methods.append(meth)
|
|
325
|
+
current_class["methods"] = unique_methods
|
|
326
|
+
if "decl_depth" in current_class:
|
|
327
|
+
del current_class["decl_depth"]
|
|
328
|
+
classes.append(current_class)
|
|
329
|
+
current_class = None
|
|
330
|
+
class_depth = 0
|
|
331
|
+
pending_method = None
|
|
332
|
+
|
|
333
|
+
return classes
|
|
334
|
+
|
|
335
|
+
|
|
62
336
|
def extract_class_info(file_path, repo_root=None):
|
|
63
|
-
"""Parses a Groovy, TypeScript, JavaScript, or Python file and extracts class
|
|
337
|
+
"""Parses a Groovy, TypeScript, JavaScript, or Python file and extracts class names and direct methods."""
|
|
64
338
|
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
65
339
|
content = f.read()
|
|
66
340
|
|
|
@@ -71,90 +345,15 @@ def extract_class_info(file_path, repo_root=None):
|
|
|
71
345
|
rel_path = os.path.abspath(file_path)
|
|
72
346
|
|
|
73
347
|
ext = os.path.splitext(file_path)[1].lower()
|
|
74
|
-
|
|
75
|
-
|
|
348
|
+
raw_size_bytes = len(content.encode("utf-8"))
|
|
349
|
+
lines = content.splitlines()
|
|
350
|
+
line_count = len(lines)
|
|
76
351
|
|
|
77
352
|
if ext in (".groovy", ".java", ".ts", ".js"):
|
|
78
|
-
|
|
79
|
-
if not class_match:
|
|
80
|
-
return None
|
|
81
|
-
class_name = class_match.group(1)
|
|
82
|
-
extends_name = class_match.group(2) or ""
|
|
83
|
-
|
|
84
|
-
lines = content.splitlines()
|
|
85
|
-
for idx, line in enumerate(lines):
|
|
86
|
-
line_clean = line.strip()
|
|
87
|
-
if not line_clean or line_clean.startswith(("//", "/*", "*")):
|
|
88
|
-
continue
|
|
89
|
-
|
|
90
|
-
if "=" in line_clean:
|
|
91
|
-
eq_pos = line_clean.find("=")
|
|
92
|
-
paren_pos = line_clean.find("(")
|
|
93
|
-
if paren_pos != -1 and eq_pos < paren_pos:
|
|
94
|
-
continue
|
|
95
|
-
|
|
96
|
-
if "(" in line_clean and ")" in line_clean:
|
|
97
|
-
has_brace = "{" in line_clean or (idx + 1 < len(lines) and lines[idx + 1].strip().startswith("{"))
|
|
98
|
-
if has_brace:
|
|
99
|
-
m = re.search(r'(?:public\s+|protected\s+|private\s+|static\s+|async\s+|def\s+|void\s+|[\w<>\[\],]+\s+)*([a-zA-Z_]\w*)\s*\(([^)]*)\)', line_clean)
|
|
100
|
-
if m:
|
|
101
|
-
name = m.group(1)
|
|
102
|
-
params = m.group(2).strip()
|
|
103
|
-
if name not in control_keywords and name != class_name:
|
|
104
|
-
comment = ""
|
|
105
|
-
if idx > 0 and lines[idx - 1].strip().startswith("//"):
|
|
106
|
-
comment = lines[idx - 1].strip().lstrip("/ ").strip()
|
|
107
|
-
methods.append({
|
|
108
|
-
"name": name,
|
|
109
|
-
"params": re.sub(r'\s+', ' ', params),
|
|
110
|
-
"comment": comment
|
|
111
|
-
})
|
|
112
|
-
|
|
353
|
+
return _extract_classes_brace(content, rel_path, raw_size_bytes, line_count)
|
|
113
354
|
elif ext == ".py":
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return None
|
|
117
|
-
class_name = class_match.group(1)
|
|
118
|
-
extends_name = class_match.group(2) or ""
|
|
119
|
-
|
|
120
|
-
lines = content.splitlines()
|
|
121
|
-
for idx, line in enumerate(lines):
|
|
122
|
-
line_clean = line.strip()
|
|
123
|
-
if line_clean.startswith("def "):
|
|
124
|
-
m = re.search(r'def\s+([a-zA-Z_]\w*)\s*\(([^)]*)\):', line_clean)
|
|
125
|
-
if m:
|
|
126
|
-
name = m.group(1)
|
|
127
|
-
params = m.group(2).replace("self,", "").replace("self", "").strip()
|
|
128
|
-
if not name.startswith("__") and name not in control_keywords:
|
|
129
|
-
comment = ""
|
|
130
|
-
if idx + 1 < len(lines) and '"""' in lines[idx + 1]:
|
|
131
|
-
comment = lines[idx + 1].replace('"""', '').strip()
|
|
132
|
-
methods.append({
|
|
133
|
-
"name": name,
|
|
134
|
-
"params": re.sub(r'\s+', ' ', params),
|
|
135
|
-
"comment": comment
|
|
136
|
-
})
|
|
137
|
-
else:
|
|
138
|
-
return None
|
|
139
|
-
|
|
140
|
-
# Deduplicate methods preserving order
|
|
141
|
-
seen = set()
|
|
142
|
-
unique_methods = []
|
|
143
|
-
for meth in methods:
|
|
144
|
-
sig = f"{meth['name']}({meth['params']})"
|
|
145
|
-
if sig not in seen:
|
|
146
|
-
seen.add(sig)
|
|
147
|
-
unique_methods.append(meth)
|
|
148
|
-
|
|
149
|
-
lines = content.splitlines()
|
|
150
|
-
return {
|
|
151
|
-
"rel_path": rel_path,
|
|
152
|
-
"class_name": class_name,
|
|
153
|
-
"extends": extends_name,
|
|
154
|
-
"raw_size_bytes": len(content.encode("utf-8")),
|
|
155
|
-
"line_count": len(lines),
|
|
156
|
-
"methods": unique_methods
|
|
157
|
-
}
|
|
355
|
+
return _extract_classes_py(content, rel_path, raw_size_bytes, line_count)
|
|
356
|
+
return []
|
|
158
357
|
|
|
159
358
|
|
|
160
359
|
def build_repo_map(target_repo=None, output_txt=None, output_json=None):
|
|
@@ -198,36 +397,39 @@ def build_repo_map(target_repo=None, output_txt=None, output_json=None):
|
|
|
198
397
|
full_path = os.path.join(root, fname)
|
|
199
398
|
if full_path not in scanned_files:
|
|
200
399
|
scanned_files.add(full_path)
|
|
201
|
-
|
|
202
|
-
if
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
400
|
+
file_classes = extract_class_info(full_path, repo_root=repo)
|
|
401
|
+
if isinstance(file_classes, dict):
|
|
402
|
+
file_classes = [file_classes]
|
|
403
|
+
file_counted = False
|
|
404
|
+
for info in (file_classes or []):
|
|
405
|
+
if info and info.get("methods"):
|
|
406
|
+
classes.append(info)
|
|
407
|
+
if not file_counted:
|
|
408
|
+
total_raw_bytes += info["raw_size_bytes"]
|
|
409
|
+
total_raw_lines += info["line_count"]
|
|
410
|
+
file_counted = True
|
|
206
411
|
|
|
207
412
|
# Sort classes: BasePage first, then alphabetical
|
|
208
413
|
classes.sort(key=lambda c: (0 if c["class_name"] == "BasePage" else 1, c["class_name"]))
|
|
209
414
|
|
|
210
|
-
# Render text map
|
|
415
|
+
# Render text map (< 500 tokens budget)
|
|
211
416
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
417
|
+
target_name = os.path.basename(repo) or repo
|
|
212
418
|
out_lines = [
|
|
213
|
-
"#
|
|
214
|
-
"# ENTERPRISE AUTOMATION REPOSITORY MAP (Aider-Style AST Compression)",
|
|
215
|
-
f"# Generated : {timestamp}",
|
|
216
|
-
f"# Target : {repo}",
|
|
217
|
-
f"# Scope : {len(classes)} Classes ({total_raw_lines} source lines, {total_raw_bytes / 1024:.1f} KB)",
|
|
218
|
-
"# Purpose : Token-budgeted index (< 600 tokens) for instant method lookup",
|
|
219
|
-
"# ==============================================================================\n"
|
|
419
|
+
f"# AST REPO MAP | Target: {target_name} | < 500 tokens\n"
|
|
220
420
|
]
|
|
221
421
|
|
|
222
422
|
total_methods = 0
|
|
223
423
|
for cls in classes:
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
424
|
+
display_path = cls["rel_path"].replace("\\", "/")
|
|
425
|
+
if display_path.startswith("examples/"):
|
|
426
|
+
display_path = display_path[len("examples/"):]
|
|
427
|
+
ext_str = f" extends {cls['extends']}" if (cls["extends"] and cls["extends"] != "BasePage") else ""
|
|
428
|
+
out_lines.append(f"{display_path} ({cls['line_count']} lines)")
|
|
429
|
+
out_lines.append(f"class {cls['class_name']}{ext_str}:")
|
|
227
430
|
for m in cls["methods"]:
|
|
228
431
|
total_methods += 1
|
|
229
|
-
|
|
230
|
-
out_lines.append(f" def {m['name']}({m['params']}){cmt}")
|
|
432
|
+
out_lines.append(f" {m['name']}({m['params']})")
|
|
231
433
|
out_lines.append("")
|
|
232
434
|
|
|
233
435
|
rendered_text = "\n".join(out_lines)
|