codegraphcontext-rust 0.9.24__cp314-cp314-win_amd64.whl
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.
- codegraphcontext/__init__.py +2 -0
- codegraphcontext/__main__.py +5 -0
- codegraphcontext/_cgc_rust.cp314-win_amd64.pyd +4 -0
- codegraphcontext/cli/__init__.py +1 -0
- codegraphcontext/cli/cli_helpers.py +774 -0
- codegraphcontext/cli/config_manager.py +1051 -0
- codegraphcontext/cli/entry.py +21 -0
- codegraphcontext/cli/main.py +2386 -0
- codegraphcontext/cli/registry_commands.py +404 -0
- codegraphcontext/cli/setup_macos.py +93 -0
- codegraphcontext/cli/setup_wizard.py +991 -0
- codegraphcontext/cli/visualizer.py +50 -0
- codegraphcontext/core/__init__.py +165 -0
- codegraphcontext/core/bundle_registry.py +181 -0
- codegraphcontext/core/cgc_bundle.py +858 -0
- codegraphcontext/core/cgcignore.py +118 -0
- codegraphcontext/core/database.py +273 -0
- codegraphcontext/core/database_falkordb.py +480 -0
- codegraphcontext/core/database_falkordb_remote.py +199 -0
- codegraphcontext/core/database_kuzu.py +636 -0
- codegraphcontext/core/falkor_worker.py +132 -0
- codegraphcontext/core/jobs.py +132 -0
- codegraphcontext/core/watcher.py +260 -0
- codegraphcontext/prompts.py +125 -0
- codegraphcontext/server.py +471 -0
- codegraphcontext/tool_definitions.py +220 -0
- codegraphcontext/tools/__init__.py +0 -0
- codegraphcontext/tools/advanced_language_query_tool.py +103 -0
- codegraphcontext/tools/code_finder.py +1160 -0
- codegraphcontext/tools/graph_builder.py +337 -0
- codegraphcontext/tools/handlers/analysis_handlers.py +114 -0
- codegraphcontext/tools/handlers/indexing_handlers.py +116 -0
- codegraphcontext/tools/handlers/management_handlers.py +339 -0
- codegraphcontext/tools/handlers/query_handlers.py +83 -0
- codegraphcontext/tools/handlers/watcher_handlers.py +83 -0
- codegraphcontext/tools/indexing/__init__.py +1 -0
- codegraphcontext/tools/indexing/angular_routes.py +396 -0
- codegraphcontext/tools/indexing/cgc_wiki_cli.py +1334 -0
- codegraphcontext/tools/indexing/constants.py +70 -0
- codegraphcontext/tools/indexing/context_generator.py +461 -0
- codegraphcontext/tools/indexing/discovery.py +64 -0
- codegraphcontext/tools/indexing/engine.py +114 -0
- codegraphcontext/tools/indexing/execution_flows.py +355 -0
- codegraphcontext/tools/indexing/module_grouping.py +551 -0
- codegraphcontext/tools/indexing/noise_filter.py +131 -0
- codegraphcontext/tools/indexing/op_param_extraction.py +287 -0
- codegraphcontext/tools/indexing/persistence/__init__.py +3 -0
- codegraphcontext/tools/indexing/persistence/duckdb_writer.py +1116 -0
- codegraphcontext/tools/indexing/persistence/parquet_loader.py +643 -0
- codegraphcontext/tools/indexing/persistence/writer.py +1562 -0
- codegraphcontext/tools/indexing/pipeline.py +171 -0
- codegraphcontext/tools/indexing/pre_scan.py +105 -0
- codegraphcontext/tools/indexing/rationale_extraction.py +154 -0
- codegraphcontext/tools/indexing/resolution/__init__.py +8 -0
- codegraphcontext/tools/indexing/resolution/calls.py +253 -0
- codegraphcontext/tools/indexing/resolution/inheritance.py +91 -0
- codegraphcontext/tools/indexing/route_extraction.py +659 -0
- codegraphcontext/tools/indexing/sanitize.py +41 -0
- codegraphcontext/tools/indexing/schema.py +79 -0
- codegraphcontext/tools/indexing/schema_contract.py +44 -0
- codegraphcontext/tools/indexing/scip_pipeline.py +140 -0
- codegraphcontext/tools/languages/c.py +563 -0
- codegraphcontext/tools/languages/cpp.py +616 -0
- codegraphcontext/tools/languages/csharp.py +551 -0
- codegraphcontext/tools/languages/dart.py +378 -0
- codegraphcontext/tools/languages/elixir.py +460 -0
- codegraphcontext/tools/languages/go.py +499 -0
- codegraphcontext/tools/languages/haskell.py +426 -0
- codegraphcontext/tools/languages/java.py +500 -0
- codegraphcontext/tools/languages/javascript.py +589 -0
- codegraphcontext/tools/languages/kotlin.py +640 -0
- codegraphcontext/tools/languages/perl.py +260 -0
- codegraphcontext/tools/languages/php.py +519 -0
- codegraphcontext/tools/languages/python.py +578 -0
- codegraphcontext/tools/languages/ruby.py +537 -0
- codegraphcontext/tools/languages/rust.py +295 -0
- codegraphcontext/tools/languages/scala.py +519 -0
- codegraphcontext/tools/languages/swift.py +491 -0
- codegraphcontext/tools/languages/typescript.py +606 -0
- codegraphcontext/tools/languages/typescriptjsx.py +151 -0
- codegraphcontext/tools/package_resolver.py +472 -0
- codegraphcontext/tools/query_tool_languages/c_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/cpp_toolkit.py +87 -0
- codegraphcontext/tools/query_tool_languages/csharp_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/dart_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/go_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/haskell_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/java_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/javascript_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/perl_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/python_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/ruby_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/rust_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/scala_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/swift_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/typescript_toolkit.py +5 -0
- codegraphcontext/tools/scip_indexer.py +467 -0
- codegraphcontext/tools/scip_pb2.py +2455 -0
- codegraphcontext/tools/system.py +133 -0
- codegraphcontext/tools/tree_sitter_parser.py +103 -0
- codegraphcontext/utils/debug_log.py +90 -0
- codegraphcontext/utils/path_ignore.py +55 -0
- codegraphcontext/utils/repo_path.py +27 -0
- codegraphcontext/utils/tree_sitter_manager.py +285 -0
- codegraphcontext/utils/visualize_graph.py +0 -0
- codegraphcontext/viz/server.py +282 -0
- codegraphcontext_rust-0.9.24.dist-info/METADATA +543 -0
- codegraphcontext_rust-0.9.24.dist-info/RECORD +112 -0
- codegraphcontext_rust-0.9.24.dist-info/WHEEL +4 -0
- codegraphcontext_rust-0.9.24.dist-info/entry_points.txt +4 -0
- codegraphcontext_rust-0.9.24.dist-info/licenses/LICENSE +21 -0
- codegraphcontext_rust-0.9.24.dist-info/sboms/cgc-python.cyclonedx.json +2302 -0
|
@@ -0,0 +1,1334 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""cgc-wiki: Index codebase → generate wiki-ready graph data.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python cgc-wiki.py index /path/to/repo
|
|
6
|
+
python cgc-wiki.py index /path/to/repo --output ./cgc-index
|
|
7
|
+
python cgc-wiki.py report /path/to/repo
|
|
8
|
+
python cgc-wiki.py query /path/to/repo "search term"
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import time
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
# Add CGC to path
|
|
19
|
+
CGC_SRC = str(Path(__file__).parent.parent / "src")
|
|
20
|
+
if CGC_SRC not in sys.path:
|
|
21
|
+
sys.path.insert(0, CGC_SRC)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
EXT_LANG = {
|
|
25
|
+
".py": "python", ".js": "javascript", ".jsx": "javascript",
|
|
26
|
+
".ts": "typescript", ".tsx": "tsx",
|
|
27
|
+
".java": "java", ".go": "go", ".rs": "rust",
|
|
28
|
+
".rb": "ruby", ".cs": "c_sharp", ".php": "php",
|
|
29
|
+
".kt": "kotlin", ".scala": "scala", ".swift": "swift",
|
|
30
|
+
".c": "c", ".cpp": "cpp", ".h": "c", ".hpp": "cpp",
|
|
31
|
+
".dart": "dart", ".ex": "elixir", ".hs": "haskell",
|
|
32
|
+
".pl": "perl",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
from codegraphcontext.tools.indexing.constants import DEFAULT_IGNORE_PATTERNS
|
|
36
|
+
|
|
37
|
+
import pathspec
|
|
38
|
+
_IGNORE_SPEC = pathspec.PathSpec.from_lines("gitwildmatch", DEFAULT_IGNORE_PATTERNS)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def discover_files(repo_path: str) -> list:
|
|
42
|
+
root = Path(repo_path).resolve()
|
|
43
|
+
files = []
|
|
44
|
+
for ext, lang in EXT_LANG.items():
|
|
45
|
+
for f in root.rglob(f"*{ext}"):
|
|
46
|
+
rel = f.relative_to(root).as_posix()
|
|
47
|
+
if not _IGNORE_SPEC.match_file(rel):
|
|
48
|
+
files.append((str(f), lang))
|
|
49
|
+
# rglob order depends on the OS and the Python version (3.14 changed the
|
|
50
|
+
# directory walk), and the resolver breaks ties by input order — sort so
|
|
51
|
+
# the same repo gives the same graph everywhere.
|
|
52
|
+
return sorted(files)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def cmd_index(args):
|
|
56
|
+
"""Index a codebase into DuckDB graph."""
|
|
57
|
+
repo_path = str(Path(args.path).resolve())
|
|
58
|
+
output_dir = args.output or os.path.join(repo_path, "wiki", "raw")
|
|
59
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
60
|
+
|
|
61
|
+
print(f"CGC Wiki Indexer v0.7.0")
|
|
62
|
+
print(f"Repository: {repo_path}")
|
|
63
|
+
print()
|
|
64
|
+
|
|
65
|
+
# Discover files
|
|
66
|
+
files = discover_files(repo_path)
|
|
67
|
+
print(f"Files discovered: {len(files)}")
|
|
68
|
+
|
|
69
|
+
from collections import Counter
|
|
70
|
+
lang_counts = Counter(l for _, l in files)
|
|
71
|
+
for lang, cnt in lang_counts.most_common():
|
|
72
|
+
print(f" {lang}: {cnt}")
|
|
73
|
+
|
|
74
|
+
# Parse + resolve
|
|
75
|
+
from codegraphcontext._cgc_rust import parse_and_prescan, resolve_call_groups, resolve_inheritance
|
|
76
|
+
|
|
77
|
+
t0 = time.time()
|
|
78
|
+
specs = [(f, l, False) for f, l in files]
|
|
79
|
+
results, imports_map = parse_and_prescan(specs)
|
|
80
|
+
valid = [r for r in results if "error" not in r]
|
|
81
|
+
call_groups, unresolved = resolve_call_groups(valid, imports_map, False, True)
|
|
82
|
+
inheritance, _ = resolve_inheritance(valid, imports_map)
|
|
83
|
+
t_parse = time.time() - t0
|
|
84
|
+
print(f"\nParse + resolve: {t_parse:.1f}s")
|
|
85
|
+
|
|
86
|
+
# Write to DuckDB (detects flows/routes/rationales/op_params internally)
|
|
87
|
+
from codegraphcontext.tools.indexing.persistence.duckdb_writer import DuckDBGraphWriter
|
|
88
|
+
|
|
89
|
+
db_path = os.path.join(output_dir, "graph.duckdb")
|
|
90
|
+
t0 = time.time()
|
|
91
|
+
writer = DuckDBGraphWriter(db_path)
|
|
92
|
+
counts = writer.write_all(valid, repo_path, call_groups, inheritance, unresolved=unresolved)
|
|
93
|
+
t_write = time.time() - t0
|
|
94
|
+
|
|
95
|
+
# Read back from DB (no duplicate extraction)
|
|
96
|
+
flows = writer.get_execution_flows()
|
|
97
|
+
routes = writer.get_routes()
|
|
98
|
+
rationales = writer.get_rationales()
|
|
99
|
+
op_params = writer.get_operational_params()
|
|
100
|
+
writer.close()
|
|
101
|
+
|
|
102
|
+
# Summary
|
|
103
|
+
funcs = counts.get("functions", 0)
|
|
104
|
+
classes = counts.get("classes", 0)
|
|
105
|
+
calls = counts.get("calls", 0)
|
|
106
|
+
n_flows = counts.get("execution_flows", 0)
|
|
107
|
+
n_routes = counts.get("routes", 0)
|
|
108
|
+
n_rationale = counts.get("rationales", 0)
|
|
109
|
+
n_op_params = counts.get("operational_params", 0)
|
|
110
|
+
|
|
111
|
+
print(f"DB write: {t_write:.1f}s")
|
|
112
|
+
print(f"\n{'='*50}")
|
|
113
|
+
print(f"INDEX COMPLETE")
|
|
114
|
+
print(f"{'='*50}")
|
|
115
|
+
print(f" Functions: {funcs}")
|
|
116
|
+
print(f" Classes: {classes}")
|
|
117
|
+
print(f" CALLS edges: {calls}")
|
|
118
|
+
print(f" Execution flows: {n_flows}")
|
|
119
|
+
print(f" API routes: {n_routes}")
|
|
120
|
+
print(f" Rationale notes: {n_rationale}")
|
|
121
|
+
print(f" Op params: {n_op_params}")
|
|
122
|
+
print(f" Output: {db_path}")
|
|
123
|
+
print(f" Total time: {t_parse + t_write:.1f}s")
|
|
124
|
+
|
|
125
|
+
# Generate report
|
|
126
|
+
report_path = os.path.join(output_dir, "GRAPH_REPORT.md")
|
|
127
|
+
_generate_report(writer, db_path, repo_path, report_path, counts, flows, routes, rationales, op_params)
|
|
128
|
+
print(f" Report: {report_path}")
|
|
129
|
+
|
|
130
|
+
# Generate module contexts for AI IDE wiki generation
|
|
131
|
+
from codegraphcontext.tools.indexing.module_grouping import auto_group_modules, group_parents
|
|
132
|
+
from codegraphcontext.tools.indexing.context_generator import generate_module_contexts
|
|
133
|
+
|
|
134
|
+
modules = auto_group_modules(valid, repo_path)
|
|
135
|
+
parent_groups = group_parents(modules)
|
|
136
|
+
ctx_dir = os.path.join(output_dir, "module_contexts")
|
|
137
|
+
n_ctx = generate_module_contexts(
|
|
138
|
+
modules, valid, repo_path, ctx_dir,
|
|
139
|
+
call_groups=call_groups, routes=routes, flows=flows,
|
|
140
|
+
rationales=rationales, op_params=op_params,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# Save modules.json with parent hierarchy
|
|
144
|
+
import json as _json
|
|
145
|
+
modules_json_path = os.path.join(output_dir, "modules.json")
|
|
146
|
+
with open(modules_json_path, "w") as fh:
|
|
147
|
+
_json.dump({"modules": modules, "parent_groups": parent_groups}, fh, indent=2)
|
|
148
|
+
|
|
149
|
+
print(f" Modules: {len(modules)} ({n_ctx} context files)")
|
|
150
|
+
if parent_groups:
|
|
151
|
+
print(f" Parent groups: {len(parent_groups)}")
|
|
152
|
+
print(f" Context dir: {ctx_dir}")
|
|
153
|
+
print(f"\n → AI IDE: read module_contexts/ + type /wiki to generate docs")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _generate_report(writer, db_path, repo_path, report_path, counts, flows, routes, rationales, op_params=None):
|
|
157
|
+
"""Generate GRAPH_REPORT.md (like Graphify)."""
|
|
158
|
+
from codegraphcontext.tools.indexing.persistence.duckdb_writer import DuckDBGraphWriter
|
|
159
|
+
from codegraphcontext.tools.indexing.noise_filter import is_noise_node
|
|
160
|
+
|
|
161
|
+
w = DuckDBGraphWriter(db_path)
|
|
162
|
+
raw_top = w.get_top_connected(limit=50)
|
|
163
|
+
top = [t for t in raw_top
|
|
164
|
+
if not is_noise_node(t.get("name", ""), t.get("call_count", 0))][:10]
|
|
165
|
+
stats = w.get_stats()
|
|
166
|
+
w.close()
|
|
167
|
+
|
|
168
|
+
repo_name = Path(repo_path).name
|
|
169
|
+
lines = [
|
|
170
|
+
f"# Graph Report — {repo_name}",
|
|
171
|
+
"",
|
|
172
|
+
f"## Summary",
|
|
173
|
+
f"- **{counts.get('files', 0)}** files · **{counts.get('functions', 0)}** functions · **{counts.get('classes', 0)}** classes",
|
|
174
|
+
f"- **{counts.get('calls', 0)}** call edges · **{counts.get('execution_flows', 0)}** execution flows",
|
|
175
|
+
f"- **{counts.get('routes', 0)}** API routes · **{counts.get('rationales', 0)}** design rationale comments",
|
|
176
|
+
"",
|
|
177
|
+
f"## Top Connected (God Nodes)",
|
|
178
|
+
"",
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
for i, fn in enumerate(top[:10], 1):
|
|
182
|
+
lines.append(f"{i}. **{fn.get('name', '?')}** ({fn.get('path', '?')}) — {fn.get('call_count', 0)} connections")
|
|
183
|
+
|
|
184
|
+
if routes:
|
|
185
|
+
lines.extend(["", "## API Routes", ""])
|
|
186
|
+
lines.append("| Method | Path | Handler | Framework |")
|
|
187
|
+
lines.append("|--------|------|---------|-----------|")
|
|
188
|
+
for r in routes[:30]:
|
|
189
|
+
lines.append(f"| {r['method']} | `{r['path']}` | {r['handler']} | {r['framework']} |")
|
|
190
|
+
if len(routes) > 30:
|
|
191
|
+
lines.append(f"| ... | ... | {len(routes) - 30} more | ... |")
|
|
192
|
+
|
|
193
|
+
if flows:
|
|
194
|
+
lines.extend(["", "## Key Execution Flows", ""])
|
|
195
|
+
for f in flows[:10]:
|
|
196
|
+
steps = " → ".join(s["name"] for s in f["steps"][:6])
|
|
197
|
+
if len(f["steps"]) > 6:
|
|
198
|
+
steps += " → ..."
|
|
199
|
+
lines.append(f"- **{f['name']}** ({f['step_count']} steps): {steps}")
|
|
200
|
+
|
|
201
|
+
if rationales:
|
|
202
|
+
lines.extend(["", "## Design Rationale (from source comments)", ""])
|
|
203
|
+
for r in rationales:
|
|
204
|
+
ctx = f" in `{r['context']}`" if r["context"] else ""
|
|
205
|
+
lines.append(f"- **[{r['tag']}]**{ctx}: {r['text']}")
|
|
206
|
+
lines.append(f" — `{r['file']}:{r['line']}`")
|
|
207
|
+
|
|
208
|
+
if op_params:
|
|
209
|
+
lines.extend(["", "## Operational Parameters", ""])
|
|
210
|
+
lines.append("| Name | Value | Category | File | Line |")
|
|
211
|
+
lines.append("|------|-------|----------|------|------|")
|
|
212
|
+
for p in (op_params or [])[:30]:
|
|
213
|
+
lines.append(
|
|
214
|
+
f"| `{p['name']}` | `{p['value']}` | {p['category']} "
|
|
215
|
+
f"| `{p['path']}` | {p['line_number']} |"
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
lines.extend([
|
|
219
|
+
"",
|
|
220
|
+
"---",
|
|
221
|
+
f"*Generated by CGC v0.9.6 · {time.strftime('%Y-%m-%d %H:%M')}*",
|
|
222
|
+
])
|
|
223
|
+
|
|
224
|
+
with open(report_path, "w") as fh:
|
|
225
|
+
fh.write("\n".join(lines))
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def cmd_search_index(args):
|
|
229
|
+
"""Build search index from wiki/outputs/code/ for AI navigation."""
|
|
230
|
+
repo_path = str(Path(args.path).resolve())
|
|
231
|
+
wiki_dir = os.path.join(repo_path, "wiki", "outputs", "code")
|
|
232
|
+
if not os.path.exists(wiki_dir):
|
|
233
|
+
print(f"No wiki/outputs/code/ found. Generate wiki first: /wiki in AI IDE")
|
|
234
|
+
return
|
|
235
|
+
|
|
236
|
+
cgc_dir = os.path.join(repo_path, "wiki", "raw")
|
|
237
|
+
index_path = os.path.join(cgc_dir, "WIKI_INDEX.md")
|
|
238
|
+
|
|
239
|
+
lines = [
|
|
240
|
+
"# Wiki Search Index",
|
|
241
|
+
"",
|
|
242
|
+
"Use this index to find the right wiki document for any question.",
|
|
243
|
+
"",
|
|
244
|
+
"| Document | Topics | Key Functions | Routes |",
|
|
245
|
+
"|----------|--------|---------------|--------|",
|
|
246
|
+
]
|
|
247
|
+
|
|
248
|
+
for md_file in sorted(Path(wiki_dir).glob("*.md")):
|
|
249
|
+
name = md_file.stem
|
|
250
|
+
content = md_file.read_text(encoding="utf-8", errors="replace")
|
|
251
|
+
|
|
252
|
+
# Extract topics from headings
|
|
253
|
+
headings = [line.lstrip("#").strip() for line in content.split("\n")
|
|
254
|
+
if line.startswith("#") and len(line) < 80][:5]
|
|
255
|
+
topics = ", ".join(headings[:3])
|
|
256
|
+
|
|
257
|
+
# Extract function names (backtick-wrapped)
|
|
258
|
+
import re
|
|
259
|
+
funcs = re.findall(r"`(\w+)\(\)`", content)
|
|
260
|
+
funcs_str = ", ".join(sorted(set(funcs))[:5])
|
|
261
|
+
|
|
262
|
+
# Extract routes
|
|
263
|
+
routes = re.findall(r"(GET|POST|PUT|DELETE|PATCH)\s+`?(/[^\s`|]+)", content)
|
|
264
|
+
routes_str = ", ".join(f"{m} {p}" for m, p in routes[:3])
|
|
265
|
+
|
|
266
|
+
lines.append(f"| [{name}](wiki/outputs/code/{name}.md) | {topics} | {funcs_str} | {routes_str} |")
|
|
267
|
+
|
|
268
|
+
lines.extend([
|
|
269
|
+
"",
|
|
270
|
+
"## How to use",
|
|
271
|
+
"",
|
|
272
|
+
"When answering a question about this codebase:",
|
|
273
|
+
"1. Search this table for matching topics/functions/routes",
|
|
274
|
+
"2. Read the matching wiki document(s)",
|
|
275
|
+
"3. Answer using the wiki content (don't grep raw source)",
|
|
276
|
+
])
|
|
277
|
+
|
|
278
|
+
os.makedirs(cgc_dir, exist_ok=True)
|
|
279
|
+
with open(index_path, "w") as fh:
|
|
280
|
+
fh.write("\n".join(lines))
|
|
281
|
+
print(f"Search index: {index_path}")
|
|
282
|
+
print(f"Documents indexed: {len(list(Path(wiki_dir).glob('*.md')))}")
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def cmd_report(args):
|
|
286
|
+
"""Show graph report."""
|
|
287
|
+
repo_path = str(Path(args.path).resolve())
|
|
288
|
+
report_path = os.path.join(repo_path, "wiki", "raw", "GRAPH_REPORT.md")
|
|
289
|
+
if os.path.exists(report_path):
|
|
290
|
+
print(open(report_path).read())
|
|
291
|
+
else:
|
|
292
|
+
print(f"No report found. Run: python cgc-wiki.py index {args.path}")
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def cmd_query(args):
|
|
296
|
+
"""Search symbols in the graph."""
|
|
297
|
+
repo_path = str(Path(args.path).resolve())
|
|
298
|
+
db_path = os.path.join(repo_path, "wiki", "raw", "graph.duckdb")
|
|
299
|
+
if not os.path.exists(db_path):
|
|
300
|
+
print(f"No index found. Run: python cgc-wiki.py index {args.path}")
|
|
301
|
+
return
|
|
302
|
+
|
|
303
|
+
from codegraphcontext.tools.indexing.persistence.duckdb_writer import DuckDBGraphWriter
|
|
304
|
+
w = DuckDBGraphWriter(db_path)
|
|
305
|
+
results = w.search_symbols(args.query, limit=20)
|
|
306
|
+
w.close()
|
|
307
|
+
|
|
308
|
+
print(f"Results for '{args.query}':")
|
|
309
|
+
for r in results:
|
|
310
|
+
print(f" [{r['type']}] {r['name']} ({r['path']}:{r['line_number']})")
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def cmd_install(args):
|
|
314
|
+
"""Install CGC-Wiki skill + hooks for AI coding assistants."""
|
|
315
|
+
platform = args.platform or _detect_platform()
|
|
316
|
+
home = Path.home()
|
|
317
|
+
skill_src = Path(__file__).parent.parent / ".claude" / "skills" / "wiki-gen" / "SKILL.md"
|
|
318
|
+
|
|
319
|
+
print(f"Installing CGC-Wiki for: {platform}")
|
|
320
|
+
|
|
321
|
+
if platform == "claude":
|
|
322
|
+
# 1. Copy skill
|
|
323
|
+
skill_dir = home / ".claude" / "skills" / "wiki"
|
|
324
|
+
skill_dir.mkdir(parents=True, exist_ok=True)
|
|
325
|
+
if skill_src.exists():
|
|
326
|
+
(skill_dir / "SKILL.md").write_text(skill_src.read_text())
|
|
327
|
+
print(f" Skill → {skill_dir / 'SKILL.md'}")
|
|
328
|
+
|
|
329
|
+
# 2. Add to CLAUDE.md
|
|
330
|
+
claude_md = Path(".") / "CLAUDE.md"
|
|
331
|
+
section = _claude_md_section()
|
|
332
|
+
if claude_md.exists():
|
|
333
|
+
content = claude_md.read_text()
|
|
334
|
+
if "cgc-wiki" not in content:
|
|
335
|
+
claude_md.write_text(content + "\n\n" + section)
|
|
336
|
+
print(f" CLAUDE.md updated")
|
|
337
|
+
else:
|
|
338
|
+
print(f" CLAUDE.md already has cgc-wiki section")
|
|
339
|
+
else:
|
|
340
|
+
claude_md.write_text(section)
|
|
341
|
+
print(f" CLAUDE.md created")
|
|
342
|
+
|
|
343
|
+
# 3. Install PreToolUse hook
|
|
344
|
+
settings_path = home / ".claude" / "settings.json"
|
|
345
|
+
_install_pretool_hook(settings_path)
|
|
346
|
+
print(f" PreToolUse hook → {settings_path}")
|
|
347
|
+
|
|
348
|
+
elif platform == "antigravity":
|
|
349
|
+
# 1. Skill
|
|
350
|
+
skill_dir = Path(".") / ".agents" / "skills" / "wiki"
|
|
351
|
+
skill_dir.mkdir(parents=True, exist_ok=True)
|
|
352
|
+
(skill_dir / "SKILL.md").write_text(_antigravity_skill())
|
|
353
|
+
print(f" Skill → {skill_dir / 'SKILL.md'}")
|
|
354
|
+
|
|
355
|
+
# 2. Rule
|
|
356
|
+
rules_dir = Path(".") / ".agents" / "rules"
|
|
357
|
+
rules_dir.mkdir(parents=True, exist_ok=True)
|
|
358
|
+
(rules_dir / "cgc-wiki.md").write_text(_antigravity_rule())
|
|
359
|
+
print(f" Rule → {rules_dir / 'cgc-wiki.md'}")
|
|
360
|
+
|
|
361
|
+
# 3. AGENTS.md (cross-tool)
|
|
362
|
+
agents_md = Path(".") / "AGENTS.md"
|
|
363
|
+
section = _agents_md_section()
|
|
364
|
+
if agents_md.exists():
|
|
365
|
+
content = agents_md.read_text()
|
|
366
|
+
if "cgc-wiki" not in content:
|
|
367
|
+
agents_md.write_text(content + "\n\n" + section)
|
|
368
|
+
print(f" AGENTS.md updated")
|
|
369
|
+
else:
|
|
370
|
+
agents_md.write_text(section)
|
|
371
|
+
print(f" AGENTS.md created")
|
|
372
|
+
|
|
373
|
+
elif platform == "cursor":
|
|
374
|
+
rules_dir = Path(".") / ".cursor" / "rules"
|
|
375
|
+
rules_dir.mkdir(parents=True, exist_ok=True)
|
|
376
|
+
rule_file = rules_dir / "cgc-wiki.mdc"
|
|
377
|
+
rule_file.write_text(_cursor_rule())
|
|
378
|
+
print(f" Rule → {rule_file}")
|
|
379
|
+
|
|
380
|
+
elif platform == "codex":
|
|
381
|
+
agents_md = Path(".") / "AGENTS.md"
|
|
382
|
+
section = _agents_md_section()
|
|
383
|
+
if agents_md.exists():
|
|
384
|
+
content = agents_md.read_text()
|
|
385
|
+
if "cgc-wiki" not in content:
|
|
386
|
+
agents_md.write_text(content + "\n\n" + section)
|
|
387
|
+
else:
|
|
388
|
+
agents_md.write_text(section)
|
|
389
|
+
print(f" AGENTS.md updated")
|
|
390
|
+
|
|
391
|
+
else:
|
|
392
|
+
# Generic: write AGENTS.md
|
|
393
|
+
agents_md = Path(".") / "AGENTS.md"
|
|
394
|
+
section = _agents_md_section()
|
|
395
|
+
if agents_md.exists():
|
|
396
|
+
content = agents_md.read_text()
|
|
397
|
+
if "cgc-wiki" not in content:
|
|
398
|
+
agents_md.write_text(content + "\n\n" + section)
|
|
399
|
+
else:
|
|
400
|
+
agents_md.write_text(section)
|
|
401
|
+
print(f" AGENTS.md updated")
|
|
402
|
+
|
|
403
|
+
print(f"\nDone! Now run: cgc-wiki index .")
|
|
404
|
+
print(f"Then type /wiki in your AI assistant to generate docs.")
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def cmd_hook(args):
|
|
408
|
+
"""Install/uninstall git hooks for auto-rebuild."""
|
|
409
|
+
repo_path = Path(args.path or ".").resolve()
|
|
410
|
+
git_dir = repo_path / ".git"
|
|
411
|
+
if not git_dir.exists():
|
|
412
|
+
print(f"Not a git repo: {repo_path}")
|
|
413
|
+
return
|
|
414
|
+
|
|
415
|
+
hooks_dir = git_dir / "hooks"
|
|
416
|
+
hooks_dir.mkdir(exist_ok=True)
|
|
417
|
+
hook_file = hooks_dir / "post-commit"
|
|
418
|
+
|
|
419
|
+
if args.action == "install":
|
|
420
|
+
script = f"""#!/bin/sh
|
|
421
|
+
# CGC-Wiki: auto-rebuild index after commit (AST only, no LLM cost)
|
|
422
|
+
if [ -d "wiki/raw" ]; then
|
|
423
|
+
echo "[cgc-wiki] Rebuilding index..."
|
|
424
|
+
python {Path(__file__).resolve()} index . 2>/dev/null &
|
|
425
|
+
fi
|
|
426
|
+
"""
|
|
427
|
+
hook_file.write_text(script)
|
|
428
|
+
hook_file.chmod(0o755)
|
|
429
|
+
print(f"Post-commit hook installed: {hook_file}")
|
|
430
|
+
print("Index will auto-rebuild after each commit (background, no LLM cost)")
|
|
431
|
+
|
|
432
|
+
elif args.action == "uninstall":
|
|
433
|
+
if hook_file.exists():
|
|
434
|
+
content = hook_file.read_text()
|
|
435
|
+
if "cgc-wiki" in content:
|
|
436
|
+
hook_file.unlink()
|
|
437
|
+
print(f"Hook removed: {hook_file}")
|
|
438
|
+
else:
|
|
439
|
+
print("Hook exists but not from cgc-wiki — skipping")
|
|
440
|
+
else:
|
|
441
|
+
print("No hook found")
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def _detect_platform() -> str:
|
|
445
|
+
"""Auto-detect which AI coding platform is installed."""
|
|
446
|
+
home = Path.home()
|
|
447
|
+
if (home / ".claude").exists():
|
|
448
|
+
return "claude"
|
|
449
|
+
if (home / ".antigravity").exists() or Path(".agents").exists():
|
|
450
|
+
return "antigravity"
|
|
451
|
+
if (home / ".cursor").exists() or Path(".cursor").exists():
|
|
452
|
+
return "cursor"
|
|
453
|
+
if (home / ".codex").exists():
|
|
454
|
+
return "codex"
|
|
455
|
+
return "generic"
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _claude_md_section() -> str:
|
|
459
|
+
return """## cgc-wiki
|
|
460
|
+
This project has a CGC knowledge graph at `wiki/raw/`.
|
|
461
|
+
|
|
462
|
+
### When answering questions about this codebase:
|
|
463
|
+
1. First check if `wiki/outputs/code/` exists — if yes, read `wiki/outputs/code/overview.md` then search relevant docs
|
|
464
|
+
2. If no wiki, read `wiki/raw/GRAPH_REPORT.md` for god nodes, routes, flows
|
|
465
|
+
3. Use graph data instead of grepping raw files
|
|
466
|
+
|
|
467
|
+
### Commands:
|
|
468
|
+
- `/wiki` — generate wiki documentation (reads module_contexts/, writes wiki/outputs/code/)
|
|
469
|
+
- `wiki-forge init` — rebuild index after code changes
|
|
470
|
+
"""
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _agents_md_section() -> str:
|
|
474
|
+
return """## cgc-wiki
|
|
475
|
+
This project has a CGC knowledge graph at `wiki/raw/`.
|
|
476
|
+
Rules:
|
|
477
|
+
- Before answering architecture questions, read `wiki/raw/GRAPH_REPORT.md`
|
|
478
|
+
- The report contains: god nodes, API routes, execution flows, design rationale
|
|
479
|
+
- After modifying code, run `wiki-forge init` to rebuild
|
|
480
|
+
"""
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def _cursor_rule() -> str:
|
|
484
|
+
return """---
|
|
485
|
+
description: CGC-Wiki code intelligence
|
|
486
|
+
alwaysApply: true
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
This project has a CGC knowledge graph at `wiki/raw/`.
|
|
490
|
+
|
|
491
|
+
Before answering architecture or codebase questions:
|
|
492
|
+
1. Read `wiki/raw/GRAPH_REPORT.md` for god nodes, routes, flows
|
|
493
|
+
2. Use the graph structure instead of grepping raw files
|
|
494
|
+
3. Type `/wiki` to generate wiki documentation
|
|
495
|
+
"""
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _antigravity_skill() -> str:
|
|
499
|
+
return """---
|
|
500
|
+
name: wiki
|
|
501
|
+
description: Generate code documentation wiki from CGC knowledge graph
|
|
502
|
+
trigger: user asks to generate wiki, document codebase, create docs, or types /wiki
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
# /wiki — Generate Code Documentation Wiki
|
|
506
|
+
|
|
507
|
+
Generate comprehensive wiki documentation using pre-computed module contexts.
|
|
508
|
+
**Zero LLM API cost** — uses your IDE's built-in AI.
|
|
509
|
+
|
|
510
|
+
## CRITICAL RULES
|
|
511
|
+
|
|
512
|
+
- **DO NOT write shell scripts, Python scripts, or call external CLIs.** YOU and your subagents must read context files and write docs using AI reasoning.
|
|
513
|
+
- **DO NOT write scripts. Read each context file and write each doc with AI reasoning.**
|
|
514
|
+
- Each doc must have real architectural analysis with Mermaid diagrams.
|
|
515
|
+
- Keep each doc **50-150 lines** max.
|
|
516
|
+
|
|
517
|
+
### Writing Style — MANDATORY
|
|
518
|
+
|
|
519
|
+
**WRITE LIKE AN ENGINEER, NOT A MARKETER.**
|
|
520
|
+
|
|
521
|
+
Every sentence must contain a concrete fact: a function name, a file path, a config value, a data flow, or a constraint. If a sentence could apply to any random project, delete it.
|
|
522
|
+
|
|
523
|
+
**BANNED patterns** (your output will be rejected if these appear):
|
|
524
|
+
- Adverb stuffing: "natively", "securely", "dynamically", "accurately", "cleanly", "perfectly", "effectively", "flawlessly", "structurally", "organically", "robustly"
|
|
525
|
+
- Vague verbs: "manages", "handles", "orchestrates", "facilitates", "leverages" without saying WHAT or HOW
|
|
526
|
+
- Meaningless modifiers: "complex", "massive", "enormous", "heavy", "deep", "strict", "explicit" when not quantified
|
|
527
|
+
- Redundant clauses: "ensuring X while maintaining Y avoiding Z" chains
|
|
528
|
+
|
|
529
|
+
**GOOD example:**
|
|
530
|
+
> `WorkflowService.cancel(id, reason)` marks the workflow as cancelled in `workflows` table, sends cancellation emails to pending signers via `NotificationService`, and logs `WORKFLOW_CANCELLED` audit event.
|
|
531
|
+
|
|
532
|
+
**BAD example (DO NOT WRITE LIKE THIS):**
|
|
533
|
+
> The workflow module operates as the central REST nerve center orchestrating complex lifecycle management dynamically handling massive operations securely ensuring clean mappings natively.
|
|
534
|
+
|
|
535
|
+
### Language Rule
|
|
536
|
+
|
|
537
|
+
**Write in English by default.** If the user requests Vietnamese (or another language):
|
|
538
|
+
- Section headings: translate (e.g., "Mục đích", "Kiến trúc", "Luồng thực thi")
|
|
539
|
+
- Explanatory text: translate naturally
|
|
540
|
+
- **NEVER translate**: function names, file paths, config values, class names, variable names, CLI commands, error messages, HTTP methods/paths, library names
|
|
541
|
+
- **NEVER invent technical jargon in the target language.** Use the original English term with translated context. Example: "Hàm `getAuth()` khởi tạo Better Auth instance" — NOT "Hàm Truy Xuất Lõi Mạch Định Danh Bảo Vệ"
|
|
542
|
+
- If unsure how to translate a term, keep it in English
|
|
543
|
+
|
|
544
|
+
### Data Extraction — MANDATORY
|
|
545
|
+
|
|
546
|
+
You MUST extract and include these from the module context file. Do NOT summarize them away:
|
|
547
|
+
|
|
548
|
+
1. **Operational Parameters** — if the context has an "Operational Parameters" section, include ALL of them as a table
|
|
549
|
+
2. **Key Functions** — list the top 10 most important functions with file:line references
|
|
550
|
+
3. **Route Table** — if the module has API routes, list EVERY route as `Method | Path | Handler`
|
|
551
|
+
4. **Design Rationale** — copy ALL `[IMPORTANT]`, `[WARNING]`, `[NOTE]` items verbatim from source
|
|
552
|
+
5. **Call Graph Summary** — state total internal calls count and list top 5 outgoing dependencies
|
|
553
|
+
|
|
554
|
+
## Prerequisites
|
|
555
|
+
|
|
556
|
+
If `wiki/raw/module_contexts/` doesn't exist:
|
|
557
|
+
```bash
|
|
558
|
+
wiki-forge init
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
## Step 1: Read the index + plan chunks
|
|
562
|
+
|
|
563
|
+
1. Read `wiki/raw/module_contexts/index.md`
|
|
564
|
+
2. Count total modules
|
|
565
|
+
3. Create `wiki/outputs/code/` directory
|
|
566
|
+
4. If **≤ 10 modules**: process all yourself (go to Step 2A)
|
|
567
|
+
5. If **> 10 modules**: split into chunks of 8-10 modules each, grouped by related slugs (go to Step 2B)
|
|
568
|
+
|
|
569
|
+
## Step 2A: Sequential generation (≤ 10 modules)
|
|
570
|
+
|
|
571
|
+
For each module in index.md:
|
|
572
|
+
1. Read `wiki/raw/module_contexts/{slug}.md`
|
|
573
|
+
2. Write `wiki/outputs/code/{slug}.md` with sections below
|
|
574
|
+
3. Move to next module
|
|
575
|
+
|
|
576
|
+
## Step 2B: Parallel subagent dispatch (> 10 modules)
|
|
577
|
+
|
|
578
|
+
**Split into chunks of 8-10 modules. Dispatch ALL subagents in a SINGLE message.**
|
|
579
|
+
|
|
580
|
+
This is critical — if you make one Agent call, wait, then make another, they run sequentially. All Agent tool calls must be in ONE response for true parallelism.
|
|
581
|
+
|
|
582
|
+
Example for 30 modules → 3 chunks:
|
|
583
|
+
```
|
|
584
|
+
[Agent tool call 1: modules 1-10, subagent_type="general-purpose"]
|
|
585
|
+
[Agent tool call 2: modules 11-20, subagent_type="general-purpose"]
|
|
586
|
+
[Agent tool call 3: modules 21-30, subagent_type="general-purpose"]
|
|
587
|
+
```
|
|
588
|
+
All three in ONE message. NOT three separate messages.
|
|
589
|
+
|
|
590
|
+
**IMPORTANT:** Use `subagent_type="general-purpose"` — NOT `Explore` (read-only, cannot write files).
|
|
591
|
+
|
|
592
|
+
Each subagent receives this prompt (substitute MODULE_LIST and CHUNK_NUM):
|
|
593
|
+
|
|
594
|
+
```
|
|
595
|
+
You are a wiki documentation subagent (chunk CHUNK_NUM).
|
|
596
|
+
|
|
597
|
+
Read these module context files from `wiki/raw/module_contexts/` and generate wiki docs in `wiki/outputs/code/`:
|
|
598
|
+
MODULE_LIST
|
|
599
|
+
|
|
600
|
+
For EACH module:
|
|
601
|
+
1. Read `wiki/raw/module_contexts/{slug}.md` — contains all context needed
|
|
602
|
+
2. Follow "Instructions for AI Wiki Generator" at the bottom of the context file
|
|
603
|
+
3. Write `wiki/outputs/code/{slug}.md` with the required sections listed below
|
|
604
|
+
|
|
605
|
+
## Required sections per doc:
|
|
606
|
+
|
|
607
|
+
### 1. Purpose (2-3 sentences)
|
|
608
|
+
What this module does. State file count, function count, and class count from the Stats line.
|
|
609
|
+
|
|
610
|
+
### 2. Architecture (Mermaid diagram)
|
|
611
|
+
Copy and enhance the Mermaid diagram from the context. Add the key classes/services as nodes.
|
|
612
|
+
|
|
613
|
+
### 3. API Endpoints (table — skip if 0 routes)
|
|
614
|
+
Extract EVERY route from the context file. Format:
|
|
615
|
+
|
|
616
|
+
| Method | Path | Handler | Description |
|
|
617
|
+
|--------|------|---------|-------------|
|
|
618
|
+
|
|
619
|
+
### 4. Key Functions (table — top 10)
|
|
620
|
+
Pick the 10 most important functions from the "Key Functions" section:
|
|
621
|
+
|
|
622
|
+
| Function | File:Line | Purpose |
|
|
623
|
+
|----------|-----------|---------|
|
|
624
|
+
|
|
625
|
+
### 5. Execution Flows (top 2-3)
|
|
626
|
+
From the "Execution Flows" section, describe what happens step-by-step. Include the step count and depth.
|
|
627
|
+
|
|
628
|
+
### 6. Design Rationale
|
|
629
|
+
Copy ALL [IMPORTANT], [WARNING], [NOTE], [CONTEXT] items from "Design Rationale" section.
|
|
630
|
+
Format as a bullet list with the tag, quote, and file:line reference. Do NOT paraphrase — keep the original wording.
|
|
631
|
+
|
|
632
|
+
### 7. Operational Parameters (table — skip if none)
|
|
633
|
+
If the context has "Operational Parameters", include ALL as:
|
|
634
|
+
|
|
635
|
+
| Name | Value | Category | File |
|
|
636
|
+
|------|-------|----------|------|
|
|
637
|
+
|
|
638
|
+
### 8. Call Graph Summary
|
|
639
|
+
- State: "N internal calls, M outgoing, K incoming" using actual numbers from context
|
|
640
|
+
- List top 5 outgoing calls with target file paths
|
|
641
|
+
|
|
642
|
+
### 9. Dependencies
|
|
643
|
+
- **Outgoing (Depends on)**: List with [[module-slug]] wikilinks
|
|
644
|
+
- **Incoming (Depended on by)**: List with [[module-slug]] wikilinks
|
|
645
|
+
|
|
646
|
+
## Writing rules — STRICTLY ENFORCED:
|
|
647
|
+
|
|
648
|
+
- 50-150 lines per doc. Be concise but data-rich.
|
|
649
|
+
- Every sentence must contain a concrete fact (function name, file path, config value, or data flow).
|
|
650
|
+
- BANNED words: "natively", "securely", "dynamically", "accurately", "cleanly", "perfectly", "effectively", "flawlessly", "structurally", "robustly", "orchestrates", "facilitates", "leverages"
|
|
651
|
+
- DO NOT write filler. If you don't know something, skip it. Short + correct > long + vague.
|
|
652
|
+
- Use confidence tags: EXTRACTED = certain (same file, explicit import or enclosing class), INFERRED = resolved via the receiver's type or inheritance. AMBIGUOUS edges are omitted.
|
|
653
|
+
- When mentioning another module, use: [[module-slug]]
|
|
654
|
+
- Language: Write in English by default. If the user requested another language, translate headings and explanatory text but NEVER translate function names, file paths, config values, class names, HTTP paths. NEVER invent technical jargon.
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
**Step 2B-verify: Check results**
|
|
658
|
+
|
|
659
|
+
After all subagents complete:
|
|
660
|
+
- List `wiki/outputs/code/` directory
|
|
661
|
+
- Count generated files vs expected
|
|
662
|
+
- If any are missing, generate them yourself
|
|
663
|
+
- If any file is suspiciously short (< 20 lines), regenerate it
|
|
664
|
+
- **Quality spot-check**: Read 2-3 random files. If they contain banned adverbs or lack function/file references, regenerate them.
|
|
665
|
+
|
|
666
|
+
## Step 3: Generate overview
|
|
667
|
+
|
|
668
|
+
After ALL module docs exist, generate `wiki/outputs/code/overview.md`:
|
|
669
|
+
1. Read `wiki/raw/GRAPH_REPORT.md` for god nodes + summary stats
|
|
670
|
+
2. Read `wiki/raw/module_contexts/index.md` for the full module list with stats
|
|
671
|
+
|
|
672
|
+
Write overview with these REQUIRED sections:
|
|
673
|
+
|
|
674
|
+
### 3a. Project Summary (3-5 sentences)
|
|
675
|
+
What the project does, tech stack, total file/function/class counts.
|
|
676
|
+
|
|
677
|
+
### 3b. Architecture Diagram
|
|
678
|
+
Mermaid diagram showing the top-level layers (max 10 nodes). Label edges with what flows between them.
|
|
679
|
+
|
|
680
|
+
### 3c. Module Index Table
|
|
681
|
+
MUST be a markdown table with data from index.md:
|
|
682
|
+
|
|
683
|
+
| Module | Files | Functions | Classes | Key Feature |
|
|
684
|
+
|--------|-------|-----------|---------|-------------|
|
|
685
|
+
|
|
686
|
+
Link each module: `[Module Name](slug.md)`
|
|
687
|
+
|
|
688
|
+
### 3d. God Nodes
|
|
689
|
+
From GRAPH_REPORT.md, list the most-connected functions/classes (highest in-degree). These are the architectural hotspots.
|
|
690
|
+
|
|
691
|
+
### 3e. API Surface Summary
|
|
692
|
+
Group all routes by area (auth, workflows, admin, etc.) with total count per area.
|
|
693
|
+
|
|
694
|
+
### 3f. Design Decisions Summary
|
|
695
|
+
Collect the most critical [IMPORTANT] and [WARNING] items across all modules (top 5-10).
|
|
696
|
+
"""
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
def _antigravity_classify_skill() -> str:
|
|
700
|
+
return '''---
|
|
701
|
+
name: wiki-classify
|
|
702
|
+
description: Classify wiki/outputs/code into entities, concepts, and sources for full vault structure
|
|
703
|
+
trigger: user asks to classify wiki, organize wiki, or types /wiki-classify
|
|
704
|
+
---
|
|
705
|
+
|
|
706
|
+
# /wiki-classify — Classify Wiki into Vault Structure
|
|
707
|
+
|
|
708
|
+
Read `wiki/outputs/code/` flat files and organize into `wiki/` vault structure with entities, concepts, and sources.
|
|
709
|
+
**Zero LLM API cost** — uses your IDE's built-in AI.
|
|
710
|
+
|
|
711
|
+
## ABSOLUTE PROHIBITION
|
|
712
|
+
|
|
713
|
+
**YOU MUST NOT write or execute ANY scripts.** No Python, no Bash, no Node.js, no `cat << EOF`, no `shutil.copy`. This skill is about YOU (the AI) reading files, understanding their content, and writing new markdown files using your reasoning.
|
|
714
|
+
|
|
715
|
+
If you write a script, the output will be garbage templates like "Initializes components mapping contexts" — which is useless. You MUST read the actual wiki/outputs/code content and extract real information.
|
|
716
|
+
|
|
717
|
+
**Violation examples (DO NOT DO THESE):**
|
|
718
|
+
- `cat << 'EOF' > scripts/wiki-classify.py`
|
|
719
|
+
- `python3 scripts/classify.py`
|
|
720
|
+
- `bash -c "for f in wiki/outputs/code/*.md; do cp ..."`
|
|
721
|
+
- Writing ANY .py, .sh, or .js file
|
|
722
|
+
|
|
723
|
+
**What you MUST do instead:**
|
|
724
|
+
- Read wiki/outputs/code/services.md with the Read tool
|
|
725
|
+
- Understand: "services uses Drizzle ORM for DB, pdf-lib for signing, Resend for email"
|
|
726
|
+
- Write wiki/entities/drizzle-orm.md with the Write tool, including real details you just read
|
|
727
|
+
|
|
728
|
+
## When to use
|
|
729
|
+
|
|
730
|
+
Run AFTER `/wiki` has generated `wiki/outputs/code/`. Creates the full vault structure that `wiki-forge serve` expects.
|
|
731
|
+
|
|
732
|
+
## Step 1: Read wiki/outputs/code
|
|
733
|
+
|
|
734
|
+
1. List all `.md` files in `wiki/outputs/code/`
|
|
735
|
+
2. Read `wiki/outputs/code/overview.md` to understand the project
|
|
736
|
+
|
|
737
|
+
## Step 2: Ensure wiki/ directories exist
|
|
738
|
+
|
|
739
|
+
Create: `wiki/sources/`, `wiki/entities/`, `wiki/concepts/`, `wiki/syntheses/`
|
|
740
|
+
|
|
741
|
+
## Step 3: Classify and distribute
|
|
742
|
+
|
|
743
|
+
### Sources (wiki/sources/)
|
|
744
|
+
Copy ALL wiki/outputs/code/*.md files to wiki/sources/ — these are code-to-doc modules.
|
|
745
|
+
|
|
746
|
+
### Entities (wiki/entities/)
|
|
747
|
+
Extract **external** technologies, libraries, services, and tools. NOT internal classes.
|
|
748
|
+
|
|
749
|
+
**What IS an entity:** Something you could Google independently — PostgreSQL, Next.js, EasyCA, VNeID, Zod.
|
|
750
|
+
**What is NOT an entity:** Internal service classes (WorkflowService, EmailService), generic terms (theme, middleware), or architectural patterns (those are concepts).
|
|
751
|
+
|
|
752
|
+
**Entity page format — every field must contain REAL data from wiki/outputs/code:**
|
|
753
|
+
|
|
754
|
+
```
|
|
755
|
+
---
|
|
756
|
+
title: {Entity Name}
|
|
757
|
+
type: entity
|
|
758
|
+
tags: [technology|library|service|database|tool]
|
|
759
|
+
sources: [[{originating-module}]]
|
|
760
|
+
---
|
|
761
|
+
|
|
762
|
+
# {Entity Name}
|
|
763
|
+
|
|
764
|
+
## What it is
|
|
765
|
+
{2-3 sentences: what this technology does in general.}
|
|
766
|
+
|
|
767
|
+
## How this project uses it
|
|
768
|
+
{3-5 sentences with concrete details FROM wiki/outputs/code modules you just read.}
|
|
769
|
+
|
|
770
|
+
**Key configuration:**
|
|
771
|
+
- {env var or config}: `{value}` — {purpose}
|
|
772
|
+
|
|
773
|
+
## Referenced in
|
|
774
|
+
- [[module-a]] — {specific role FROM the module doc you read}
|
|
775
|
+
- [[module-b]] — {specific role FROM the module doc you read}
|
|
776
|
+
|
|
777
|
+
## Related
|
|
778
|
+
- [[concept-x]] — {how they connect}
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
**Target: 15-30 entities.** Only EXTERNAL technologies in 2+ modules.
|
|
782
|
+
|
|
783
|
+
### Concepts (wiki/concepts/)
|
|
784
|
+
Extract architectural patterns, workflows, design principles. Include REAL implementation details.
|
|
785
|
+
|
|
786
|
+
**Concept page format — every field must contain REAL data from wiki/outputs/code:**
|
|
787
|
+
|
|
788
|
+
```
|
|
789
|
+
---
|
|
790
|
+
title: {Concept Name}
|
|
791
|
+
type: concept
|
|
792
|
+
tags: [pattern|workflow|architecture|security|process]
|
|
793
|
+
sources: [[{originating-module}]]
|
|
794
|
+
---
|
|
795
|
+
|
|
796
|
+
# {Concept Name}
|
|
797
|
+
|
|
798
|
+
## What it is
|
|
799
|
+
{2-3 sentences: general definition.}
|
|
800
|
+
|
|
801
|
+
## How this project implements it
|
|
802
|
+
{5-10 bullet points with REAL details from wiki/outputs/code:}
|
|
803
|
+
- {Which files/services implement it — from module docs you read}
|
|
804
|
+
- {Key functions with file:line — from Key Functions tables}
|
|
805
|
+
- {Config values, thresholds — from Operational Parameters}
|
|
806
|
+
- {[IMPORTANT]/[WARNING] notes — from Design Rationale sections}
|
|
807
|
+
|
|
808
|
+
## Flow
|
|
809
|
+
{Step by step with REAL function names from the wiki/outputs/code execution flows.}
|
|
810
|
+
|
|
811
|
+
## Related
|
|
812
|
+
- [[entity-a]], [[concept-b]]
|
|
813
|
+
- Modules: [[module-x]], [[module-y]]
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
**Priority concepts** (create if found):
|
|
817
|
+
- Multi-tenancy, Provider/DI pattern, Incremental PDF signing
|
|
818
|
+
- Impersonation, Audit logging, Magic link auth, Workflow state machine
|
|
819
|
+
|
|
820
|
+
**Target: 15-25 concepts.**
|
|
821
|
+
|
|
822
|
+
## Step 4: Generate wiki/overview.md and wiki/index.md
|
|
823
|
+
|
|
824
|
+
## Step 5: Report
|
|
825
|
+
|
|
826
|
+
## Rules
|
|
827
|
+
- **ABSOLUTELY NO SCRIPTS** — no Python, no Bash, no cat heredoc. Use Read/Write tools only.
|
|
828
|
+
- **DO NOT delete or modify wiki/outputs/code/**
|
|
829
|
+
- **DO NOT invent information** — only extract from wiki/outputs/code/ content
|
|
830
|
+
- **DO NOT use template phrases** — BANNED: "Initializes components mapping contexts", "Evaluates specific bounds", "Translates executions updating database layers", "Serves as an architectural backbone", "Contextually binds this principle", "Inherits standard operational routing constraints"
|
|
831
|
+
- Entity = external technology only (NOT internal classes)
|
|
832
|
+
- Concept = architectural pattern with REAL implementation details
|
|
833
|
+
- Use [[wikilinks]] to cross-reference
|
|
834
|
+
'''
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
def _antigravity_docs_index_skill() -> str:
|
|
838
|
+
return """---
|
|
839
|
+
name: docs-index
|
|
840
|
+
description: Index docs/ folder into compact summaries that /wiki can reference
|
|
841
|
+
trigger: user asks to index docs, or types /docs-index
|
|
842
|
+
---
|
|
843
|
+
|
|
844
|
+
# /docs-index — Index Documentation for Wiki
|
|
845
|
+
|
|
846
|
+
Scan `docs/` folder, create compact summaries in `wiki/raw/docs-context/` so `/wiki` can merge hand-written docs into generated wiki.
|
|
847
|
+
**Zero LLM API cost** — uses your IDE's built-in AI.
|
|
848
|
+
|
|
849
|
+
## When to use
|
|
850
|
+
|
|
851
|
+
Run BEFORE `/wiki` if the project has a `docs/` folder with hand-written documentation (architecture, API references, guides, etc.).
|
|
852
|
+
|
|
853
|
+
Only needs to run once, or when docs/ content changes.
|
|
854
|
+
|
|
855
|
+
## Step 1: Discover docs
|
|
856
|
+
|
|
857
|
+
1. Check if `docs/` exists. If not, check `documentation/`, `doc/`. If none found, stop.
|
|
858
|
+
2. List all `.md` files in docs/ with file sizes
|
|
859
|
+
3. Create `wiki/raw/docs-context/` directory
|
|
860
|
+
|
|
861
|
+
## Step 2: Read module index
|
|
862
|
+
|
|
863
|
+
Read `wiki/raw/module_contexts/index.md` to get the list of code modules. This is needed to map docs → modules.
|
|
864
|
+
|
|
865
|
+
## Step 3: Process each doc
|
|
866
|
+
|
|
867
|
+
For each markdown file in `docs/`:
|
|
868
|
+
|
|
869
|
+
1. Read the full file
|
|
870
|
+
2. Write a compact summary to `wiki/raw/docs-context/{filename}` with this format:
|
|
871
|
+
|
|
872
|
+
```markdown
|
|
873
|
+
# {Document Title}
|
|
874
|
+
|
|
875
|
+
**Source:** `docs/{filename}` ({size} bytes)
|
|
876
|
+
**Related modules:** [[module-a]], [[module-b]], ...
|
|
877
|
+
|
|
878
|
+
## Key Information
|
|
879
|
+
|
|
880
|
+
- {Bullet point 1: concrete fact, number, or decision}
|
|
881
|
+
- {Bullet point 2}
|
|
882
|
+
- ...
|
|
883
|
+
- {Bullet point N}
|
|
884
|
+
|
|
885
|
+
## Data Tables (preserve verbatim)
|
|
886
|
+
|
|
887
|
+
{Copy any tables from the source doc — API endpoints, config values,
|
|
888
|
+
schema definitions, environment variables. These are high-value structured
|
|
889
|
+
data that must not be summarized away.}
|
|
890
|
+
|
|
891
|
+
## Constraints & Decisions
|
|
892
|
+
|
|
893
|
+
- {Any architectural decisions, limitations, or requirements mentioned}
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
### Rules for summarization:
|
|
897
|
+
|
|
898
|
+
- **Target: 30-80 lines per summary** (source may be 200-500 lines)
|
|
899
|
+
- **KEEP verbatim:** tables, code blocks, config values, API specs, env vars, schema definitions
|
|
900
|
+
- **KEEP verbatim:** anything marked IMPORTANT, WARNING, NOTE, TODO
|
|
901
|
+
- **Summarize:** narrative explanations, step-by-step guides, background context
|
|
902
|
+
- **Map to modules:** identify which `module_contexts/` modules this doc relates to using [[module-slug]] wikilinks
|
|
903
|
+
- **Skip:** table of contents, navigation links, badges, images
|
|
904
|
+
|
|
905
|
+
### For non-markdown files (PDF, DOCX):
|
|
906
|
+
|
|
907
|
+
- Note their existence in the index but do not attempt to read them
|
|
908
|
+
- Write: `**Format:** PDF (not indexed — use wiki-forge ingest for PDF/DOCX processing)`
|
|
909
|
+
|
|
910
|
+
## Step 4: Generate index
|
|
911
|
+
|
|
912
|
+
Write `wiki/raw/docs-context/index.md`:
|
|
913
|
+
|
|
914
|
+
```markdown
|
|
915
|
+
# Documentation Context Index
|
|
916
|
+
|
|
917
|
+
Summaries of hand-written docs for wiki generation.
|
|
918
|
+
|
|
919
|
+
| Document | Size | Related Modules | Key Topic |
|
|
920
|
+
|----------|------|-----------------|-----------|
|
|
921
|
+
| [system-architecture](system-architecture.md) | 32KB | [[services]], [[schema]], [[auth]] | System layers, data flows |
|
|
922
|
+
| [database-schema](database-schema.md) | 15KB | [[schema]], [[db]] | Table definitions, relations |
|
|
923
|
+
| ... | | | |
|
|
924
|
+
|
|
925
|
+
## Usage
|
|
926
|
+
|
|
927
|
+
These summaries are consumed by `/wiki` during wiki/outputs/code generation.
|
|
928
|
+
To regenerate: `/docs-index`
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
## Step 5: Report
|
|
932
|
+
|
|
933
|
+
```
|
|
934
|
+
Docs Index Summary
|
|
935
|
+
──────────────────
|
|
936
|
+
Source: docs/ ({N} files, {total_size})
|
|
937
|
+
Output: wiki/raw/docs-context/ ({N} summaries)
|
|
938
|
+
Skipped: {N} non-markdown files
|
|
939
|
+
|
|
940
|
+
Next step: run /wiki to generate wiki with docs context merged
|
|
941
|
+
```
|
|
942
|
+
"""
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
def _antigravity_review_skill() -> str:
|
|
946
|
+
return """---
|
|
947
|
+
name: wiki-review
|
|
948
|
+
description: Review and fix wiki/outputs/code quality by comparing against CGC module contexts
|
|
949
|
+
trigger: user asks to review wiki, fix wiki quality, or types /wiki-review
|
|
950
|
+
---
|
|
951
|
+
|
|
952
|
+
# /wiki-review — Wiki Quality Review & Fix
|
|
953
|
+
|
|
954
|
+
Review `wiki/outputs/code/` docs against `wiki/raw/module_contexts/` source data. Fix quality issues in-place.
|
|
955
|
+
**Zero LLM API cost** — uses your IDE's built-in AI.
|
|
956
|
+
|
|
957
|
+
## When to use
|
|
958
|
+
|
|
959
|
+
Run AFTER `/wiki` has generated `wiki/outputs/code/`. This is a quality gate before committing or publishing.
|
|
960
|
+
|
|
961
|
+
## Step 1: Build checklist
|
|
962
|
+
|
|
963
|
+
Read `wiki/outputs/code/overview.md` and list all module doc files. For each file, you will check quality.
|
|
964
|
+
|
|
965
|
+
If there are more than 15 files, split into chunks of ~10 and dispatch subagents in parallel (same pattern as `/wiki`).
|
|
966
|
+
|
|
967
|
+
## Step 2: Review each doc
|
|
968
|
+
|
|
969
|
+
For each `wiki/outputs/code/{slug}.md`:
|
|
970
|
+
|
|
971
|
+
1. Read `wiki/outputs/code/{slug}.md` (the generated doc)
|
|
972
|
+
2. Read `wiki/raw/module_contexts/{slug}.md` (the source context)
|
|
973
|
+
3. Check against this checklist:
|
|
974
|
+
|
|
975
|
+
### Quality Checklist
|
|
976
|
+
|
|
977
|
+
| # | Check | How to verify |
|
|
978
|
+
|---|-------|---------------|
|
|
979
|
+
| 1 | **No filler adverbs** | Search for: "natively", "securely", "dynamically", "accurately", "cleanly", "perfectly", "effectively", "flawlessly", "structurally", "robustly". If found → rewrite the sentence with a concrete fact. |
|
|
980
|
+
| 2 | **No invented jargon** | If doc is in Vietnamese/other language: check that function names, file paths, class names, config values are in English. If translated → fix. |
|
|
981
|
+
| 3 | **Operational params preserved** | Compare "Operational Parameters" section in context vs doc. If context has params but doc doesn't → add them. |
|
|
982
|
+
| 4 | **Design rationale complete** | Count `[IMPORTANT]`, `[WARNING]`, `[NOTE]` items in context's "Design Rationale" section. Compare with doc. If any missing → add verbatim with file:line. |
|
|
983
|
+
| 5 | **Route table complete** | If context lists routes, check doc has ALL routes (not just "5 representative"). If truncated → expand to full list. |
|
|
984
|
+
| 6 | **Key functions listed** | Doc should have top 10 functions with file:line refs. If missing → add from context "Key Functions" section. |
|
|
985
|
+
| 7 | **Mermaid diagram present** | Every doc must have at least 1 Mermaid diagram. If missing → add based on context "Architecture" section. |
|
|
986
|
+
| 8 | **Line count 50-150** | If < 50 → too thin, add missing data. If > 150 → trim redundant text. |
|
|
987
|
+
| 9 | **Every sentence has a fact** | Each sentence should contain a function name, file path, config value, or data flow. Sentences like "This module handles various operations" → rewrite or delete. |
|
|
988
|
+
|
|
989
|
+
### Fix process
|
|
990
|
+
|
|
991
|
+
- If a file fails 1-2 checks: edit in-place (use Edit tool)
|
|
992
|
+
- If a file fails 3+ checks: rewrite entirely from the module context
|
|
993
|
+
- Track fixes in a summary
|
|
994
|
+
|
|
995
|
+
## Step 3: Review overview.md
|
|
996
|
+
|
|
997
|
+
Check `wiki/outputs/code/overview.md` specifically for:
|
|
998
|
+
1. Module index TABLE exists (not just bullet list)
|
|
999
|
+
2. God nodes section exists
|
|
1000
|
+
3. API surface summary with route counts exists
|
|
1001
|
+
4. Architecture Mermaid diagram has labeled edges
|
|
1002
|
+
5. No filler text
|
|
1003
|
+
|
|
1004
|
+
Fix any issues.
|
|
1005
|
+
|
|
1006
|
+
## Step 4: Report
|
|
1007
|
+
|
|
1008
|
+
After all reviews, output a summary:
|
|
1009
|
+
|
|
1010
|
+
```
|
|
1011
|
+
Wiki Review Summary
|
|
1012
|
+
───────────────────
|
|
1013
|
+
Files reviewed: N
|
|
1014
|
+
Files passed: N
|
|
1015
|
+
Files fixed: N
|
|
1016
|
+
Files rewritten: N
|
|
1017
|
+
|
|
1018
|
+
Fixes applied:
|
|
1019
|
+
- {slug}.md: added 3 missing operational params
|
|
1020
|
+
- {slug}.md: removed filler adverbs (5 instances)
|
|
1021
|
+
- {slug}.md: expanded route table from 5 to 27 routes
|
|
1022
|
+
- overview.md: added module index table
|
|
1023
|
+
```
|
|
1024
|
+
"""
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
def _antigravity_rule() -> str:
|
|
1028
|
+
return """---
|
|
1029
|
+
description: Use CGC wiki before searching raw files
|
|
1030
|
+
alwaysApply: true
|
|
1031
|
+
---
|
|
1032
|
+
|
|
1033
|
+
This project has a CGC knowledge graph at `wiki/raw/`.
|
|
1034
|
+
|
|
1035
|
+
Before answering architecture or codebase questions:
|
|
1036
|
+
1. First check if `wiki/outputs/code/` exists — if yes, read `wiki/outputs/code/overview.md` then search relevant docs
|
|
1037
|
+
2. If no wiki, read `wiki/raw/GRAPH_REPORT.md` for god nodes, routes, flows
|
|
1038
|
+
3. Use graph data instead of grepping raw files
|
|
1039
|
+
|
|
1040
|
+
Commands:
|
|
1041
|
+
- `/wiki` — generate wiki documentation (reads module_contexts/, writes wiki/outputs/code/)
|
|
1042
|
+
- `wiki-forge init` — rebuild index after code changes
|
|
1043
|
+
"""
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
def _antigravity_wiki_docs_skill() -> str:
|
|
1047
|
+
return """---
|
|
1048
|
+
name: wiki-docs
|
|
1049
|
+
description: Transform raw docs repo (.md files) into structured wiki pages with Summary, Key Claims, Connections
|
|
1050
|
+
user_invocable: true
|
|
1051
|
+
trigger: user asks to generate wiki from docs, process documentation repo, or types /wiki-docs
|
|
1052
|
+
---
|
|
1053
|
+
|
|
1054
|
+
# /wiki-docs — Generate Wiki from Docs Repository
|
|
1055
|
+
|
|
1056
|
+
Transform raw markdown docs (Confluence exports, BA docs, design docs) into structured wiki pages.
|
|
1057
|
+
**Zero LLM API cost** — uses your IDE's built-in AI.
|
|
1058
|
+
|
|
1059
|
+
## ⚠️ TOKEN EFFICIENCY RULES — READ FIRST
|
|
1060
|
+
|
|
1061
|
+
- **NEVER spawn subagents or parallel agents.** Process everything sequentially in this single session.
|
|
1062
|
+
- **NEVER dispatch Agent tool.** All work happens in this one context window.
|
|
1063
|
+
- **Read 5 files at once, write 5 outputs at once** — batch reads to minimize tool calls.
|
|
1064
|
+
- With 1M context window, you can hold many files simultaneously. Use it.
|
|
1065
|
+
|
|
1066
|
+
## CONTENT RULES
|
|
1067
|
+
|
|
1068
|
+
- **DO NOT write shell scripts or Python scripts.** Use Read/Write tools only.
|
|
1069
|
+
- **DO NOT copy-paste raw content.** Every output must be a structured synthesis.
|
|
1070
|
+
- **DO NOT hallucinate.** Every claim must come from the source file.
|
|
1071
|
+
- **SKIP empty files** — under 200 bytes or only a Confluence metadata header.
|
|
1072
|
+
|
|
1073
|
+
### Writing Style — MANDATORY
|
|
1074
|
+
|
|
1075
|
+
Every sentence must contain a concrete fact from the source document.
|
|
1076
|
+
|
|
1077
|
+
**BANNED:** "comprehensively", "effectively", "seamlessly", "robustly", "This document discusses various aspects of..."
|
|
1078
|
+
|
|
1079
|
+
**GOOD:** `The authentication flow has 3 layers: Traefik → authorization-service (token check) → Keycloak (token verify).`
|
|
1080
|
+
|
|
1081
|
+
### Language Rule
|
|
1082
|
+
|
|
1083
|
+
Write in the same language as the source document. Never translate system/product names.
|
|
1084
|
+
|
|
1085
|
+
## Prerequisites
|
|
1086
|
+
|
|
1087
|
+
`wiki/sources/` must exist (run `wiki-forge init-docs .` first).
|
|
1088
|
+
|
|
1089
|
+
## Step 1: Scan and filter
|
|
1090
|
+
|
|
1091
|
+
List all `.md` files under `wiki/sources/` recursively.
|
|
1092
|
+
|
|
1093
|
+
**Skip a file if:**
|
|
1094
|
+
- Size < 200 bytes
|
|
1095
|
+
- Content is only: `# title` + `> Migrated from Confluence: ...` with no body
|
|
1096
|
+
|
|
1097
|
+
Count: total files, skippable files, files to process.
|
|
1098
|
+
|
|
1099
|
+
Print summary:
|
|
1100
|
+
```
|
|
1101
|
+
Total: 1613 files
|
|
1102
|
+
Skip (empty): 490
|
|
1103
|
+
To process: 1123
|
|
1104
|
+
```
|
|
1105
|
+
|
|
1106
|
+
**STOP if files to process > 500.** Tell the user: "Too many files. Run /wiki-docs with --folder confluence/architecture to process one folder at a time."
|
|
1107
|
+
|
|
1108
|
+
## Step 2: Batch process — 5 files per read cycle
|
|
1109
|
+
|
|
1110
|
+
For each batch of 5 files:
|
|
1111
|
+
|
|
1112
|
+
1. Read all 5 files in parallel (MultiRead)
|
|
1113
|
+
2. For EACH file, generate structured output:
|
|
1114
|
+
|
|
1115
|
+
```markdown
|
|
1116
|
+
---
|
|
1117
|
+
title: "{Document Title}"
|
|
1118
|
+
type: source
|
|
1119
|
+
source_file: {relative path}
|
|
1120
|
+
---
|
|
1121
|
+
|
|
1122
|
+
## Summary
|
|
1123
|
+
|
|
1124
|
+
{2-4 sentences. Concrete facts only.}
|
|
1125
|
+
|
|
1126
|
+
## Key Claims
|
|
1127
|
+
|
|
1128
|
+
- **{heading}**: {specific fact from document}
|
|
1129
|
+
- ... (3-8 bullets, only stated facts)
|
|
1130
|
+
|
|
1131
|
+
## Connections
|
|
1132
|
+
|
|
1133
|
+
* [[{System/Entity}]] — {1-line role}
|
|
1134
|
+
```
|
|
1135
|
+
|
|
1136
|
+
3. Write all 5 outputs (overwrite source files)
|
|
1137
|
+
4. Print: `✓ Batch N/M — 5 files processed`
|
|
1138
|
+
|
|
1139
|
+
**Do NOT spawn agents. Process all batches yourself sequentially.**
|
|
1140
|
+
|
|
1141
|
+
## Step 3: Update overview.md
|
|
1142
|
+
|
|
1143
|
+
After all files processed, write `wiki/overview.md`:
|
|
1144
|
+
|
|
1145
|
+
```markdown
|
|
1146
|
+
# {Project Name} — Documentation Overview
|
|
1147
|
+
|
|
1148
|
+
| Folder | Processed | Skipped |
|
|
1149
|
+
|--------|-----------|---------|
|
|
1150
|
+
| confluence/architecture/ | 32 | 13 |
|
|
1151
|
+
| ...
|
|
1152
|
+
| **Total** | **N** | **N** |
|
|
1153
|
+
```
|
|
1154
|
+
|
|
1155
|
+
## Step 4: Final report
|
|
1156
|
+
|
|
1157
|
+
```
|
|
1158
|
+
Wiki Docs Complete
|
|
1159
|
+
──────────────────
|
|
1160
|
+
Processed: N files
|
|
1161
|
+
Skipped: N files (empty)
|
|
1162
|
+
Duration: ~N min
|
|
1163
|
+
|
|
1164
|
+
Next: wiki-forge pack --vault .
|
|
1165
|
+
```
|
|
1166
|
+
"""
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
def _antigravity_wiki_docs_review_skill() -> str:
|
|
1170
|
+
return """---
|
|
1171
|
+
name: wiki-docs-review
|
|
1172
|
+
description: Review and fix wiki/sources/ quality for docs repos — check accuracy, remove hallucinations, fix empty pages
|
|
1173
|
+
user_invocable: true
|
|
1174
|
+
trigger: user asks to review docs wiki, check wiki-docs quality, or types /wiki-docs-review
|
|
1175
|
+
---
|
|
1176
|
+
|
|
1177
|
+
# /wiki-docs-review — Docs Wiki Quality Review
|
|
1178
|
+
|
|
1179
|
+
Review `wiki/sources/` pages generated by `/wiki-docs`. Fix accuracy issues and quality problems.
|
|
1180
|
+
**Zero LLM API cost** — uses your IDE's built-in AI.
|
|
1181
|
+
|
|
1182
|
+
## When to use
|
|
1183
|
+
|
|
1184
|
+
Run AFTER `/wiki-docs` has processed `wiki/sources/`. This is a quality gate before `wiki-forge pack`.
|
|
1185
|
+
|
|
1186
|
+
## Step 1: Build review checklist
|
|
1187
|
+
|
|
1188
|
+
List all `.md` files in `wiki/sources/` (recursively). Group by folder.
|
|
1189
|
+
Total files to review. If > 30 files, dispatch subagents per folder in parallel.
|
|
1190
|
+
|
|
1191
|
+
## Step 2: Review each file
|
|
1192
|
+
|
|
1193
|
+
For each processed file in `wiki/sources/`:
|
|
1194
|
+
|
|
1195
|
+
1. Read the structured output file
|
|
1196
|
+
2. Read the original source (check if raw content was in the same file before processing, or skip if already overwritten)
|
|
1197
|
+
|
|
1198
|
+
### Quality Checklist
|
|
1199
|
+
|
|
1200
|
+
| # | Check | How to verify |
|
|
1201
|
+
|---|-------|---------------|
|
|
1202
|
+
| 1 | **Has Summary section** | Must have `## Summary` with 2+ sentences. If missing → generate from content. |
|
|
1203
|
+
| 2 | **Has Key Claims** | Must have `## Key Claims` with 3+ bullet points. If empty → extract from content. |
|
|
1204
|
+
| 3 | **No filler language** | Search for: "comprehensively", "effectively", "seamlessly", "robustly", "various aspects". If found → rewrite with concrete facts. |
|
|
1205
|
+
| 4 | **No hallucinated claims** | Each Key Claim must be traceable to content in the file. If a claim seems invented → remove it. |
|
|
1206
|
+
| 5 | **Connections are real** | Each `[[Entity]]` in Connections must be mentioned in the file content. If not → remove. |
|
|
1207
|
+
| 6 | **Not a copy-paste dump** | If Summary is just the first paragraph of the source verbatim → rewrite as synthesis. |
|
|
1208
|
+
| 7 | **Line count 15-60** | If < 15 → too thin (likely empty source), flag for deletion. If > 60 → trim redundant content. |
|
|
1209
|
+
| 8 | **Concrete facts present** | At least 3 Key Claims must have specific names, numbers, or decisions — not generic descriptions. |
|
|
1210
|
+
|
|
1211
|
+
### Fix process
|
|
1212
|
+
|
|
1213
|
+
- Fail 1-2 checks → edit in-place
|
|
1214
|
+
- Fail 3+ checks → rewrite from scratch using file content
|
|
1215
|
+
- File < 15 lines AND source was empty → delete the file, log as removed
|
|
1216
|
+
|
|
1217
|
+
## Step 3: Check overview.md
|
|
1218
|
+
|
|
1219
|
+
Verify `wiki/overview.md`:
|
|
1220
|
+
1. Has folder table with file counts
|
|
1221
|
+
2. Total count matches actual files
|
|
1222
|
+
3. No filler intro text
|
|
1223
|
+
|
|
1224
|
+
## Step 4: Report
|
|
1225
|
+
|
|
1226
|
+
```
|
|
1227
|
+
Wiki Docs Review Summary
|
|
1228
|
+
─────────────────────────
|
|
1229
|
+
Files reviewed: N
|
|
1230
|
+
Files passed: N
|
|
1231
|
+
Files fixed: N
|
|
1232
|
+
Files deleted: N (empty sources)
|
|
1233
|
+
|
|
1234
|
+
Issues fixed:
|
|
1235
|
+
- confluence/architecture/admin-service.md: deleted (empty source)
|
|
1236
|
+
- confluence/pmo/sprint-planning.md: rewrote Key Claims (had filler)
|
|
1237
|
+
- context/product-modules.md: removed 2 hallucinated Connections
|
|
1238
|
+
|
|
1239
|
+
Next: wiki-forge pack --vault .
|
|
1240
|
+
```
|
|
1241
|
+
"""
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
def _install_pretool_hook(settings_path: Path):
|
|
1245
|
+
"""Add PreToolUse hook to Claude Code settings."""
|
|
1246
|
+
settings_path.parent.mkdir(parents=True, exist_ok=True)
|
|
1247
|
+
|
|
1248
|
+
settings = {}
|
|
1249
|
+
if settings_path.exists():
|
|
1250
|
+
try:
|
|
1251
|
+
settings = json.loads(settings_path.read_text())
|
|
1252
|
+
except (json.JSONDecodeError, OSError):
|
|
1253
|
+
pass
|
|
1254
|
+
|
|
1255
|
+
hooks = settings.setdefault("hooks", {})
|
|
1256
|
+
pre_tool = hooks.setdefault("PreToolUse", [])
|
|
1257
|
+
|
|
1258
|
+
# Remove any existing cgc-wiki hooks (old or new format)
|
|
1259
|
+
pre_tool[:] = [
|
|
1260
|
+
hook for hook in pre_tool
|
|
1261
|
+
if "cgc-wiki" not in str(hook.get("command", ""))
|
|
1262
|
+
and "cgc-wiki" not in str(hook.get("hooks", []))
|
|
1263
|
+
]
|
|
1264
|
+
|
|
1265
|
+
# Add with correct format
|
|
1266
|
+
pre_tool.append({
|
|
1267
|
+
"matcher": "Glob|Grep|Read",
|
|
1268
|
+
"hooks": [
|
|
1269
|
+
{
|
|
1270
|
+
"type": "command",
|
|
1271
|
+
"command": 'test -f wiki/raw/GRAPH_REPORT.md && echo "cgc-wiki: Knowledge graph exists at wiki/raw/. Read GRAPH_REPORT.md for god nodes, API routes, and execution flows before searching raw files." || true',
|
|
1272
|
+
}
|
|
1273
|
+
],
|
|
1274
|
+
})
|
|
1275
|
+
|
|
1276
|
+
settings_path.write_text(json.dumps(settings, indent=2))
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
parser = argparse.ArgumentParser(
|
|
1280
|
+
description="CGC Wiki — Index codebase + generate docs",
|
|
1281
|
+
epilog="Examples:\n"
|
|
1282
|
+
" cgc-wiki index . Index current directory\n"
|
|
1283
|
+
" cgc-wiki install Install AI skill + hooks\n"
|
|
1284
|
+
" cgc-wiki hook install Auto-rebuild on git commit\n"
|
|
1285
|
+
" cgc-wiki report . Show graph report\n"
|
|
1286
|
+
" cgc-wiki query . 'login' Search symbols\n",
|
|
1287
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
1288
|
+
)
|
|
1289
|
+
sub = parser.add_subparsers(dest="command")
|
|
1290
|
+
|
|
1291
|
+
p_index = sub.add_parser("index", help="Index a codebase")
|
|
1292
|
+
p_index.add_argument("path", help="Repository path")
|
|
1293
|
+
p_index.add_argument("--output", help="Output directory (default: <repo>/wiki/raw)")
|
|
1294
|
+
|
|
1295
|
+
p_install = sub.add_parser("install", help="Install AI skill + hooks")
|
|
1296
|
+
p_install.add_argument("--platform", choices=["claude", "cursor", "codex", "generic"],
|
|
1297
|
+
help="Target platform (auto-detected if omitted)")
|
|
1298
|
+
|
|
1299
|
+
p_hook = sub.add_parser("hook", help="Install/uninstall git hooks")
|
|
1300
|
+
p_hook.add_argument("action", choices=["install", "uninstall"])
|
|
1301
|
+
p_hook.add_argument("path", nargs="?", default=".", help="Repository path")
|
|
1302
|
+
|
|
1303
|
+
p_report = sub.add_parser("report", help="Show graph report")
|
|
1304
|
+
p_report.add_argument("path", help="Repository path")
|
|
1305
|
+
|
|
1306
|
+
p_query = sub.add_parser("query", help="Search symbols")
|
|
1307
|
+
p_query.add_argument("path", help="Repository path")
|
|
1308
|
+
p_query.add_argument("query", help="Search term")
|
|
1309
|
+
|
|
1310
|
+
p_search = sub.add_parser("search-index", help="Build search index from wiki/outputs/code/")
|
|
1311
|
+
p_search.add_argument("path", nargs="?", default=".", help="Repository path")
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
def main():
|
|
1315
|
+
"""Entry point for cgc-wiki CLI."""
|
|
1316
|
+
args = parser.parse_args()
|
|
1317
|
+
if args.command == "index":
|
|
1318
|
+
cmd_index(args)
|
|
1319
|
+
elif args.command == "install":
|
|
1320
|
+
cmd_install(args)
|
|
1321
|
+
elif args.command == "hook":
|
|
1322
|
+
cmd_hook(args)
|
|
1323
|
+
elif args.command == "report":
|
|
1324
|
+
cmd_report(args)
|
|
1325
|
+
elif args.command == "query":
|
|
1326
|
+
cmd_query(args)
|
|
1327
|
+
elif args.command == "search-index":
|
|
1328
|
+
cmd_search_index(args)
|
|
1329
|
+
else:
|
|
1330
|
+
parser.print_help()
|
|
1331
|
+
|
|
1332
|
+
|
|
1333
|
+
if __name__ == "__main__":
|
|
1334
|
+
main()
|