codegraph-engine 3.0.0__py3-none-any.whl → 3.0.1__py3-none-any.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.
- codegraph/__init__.py +1 -1
- codegraph/__main__.py +7 -0
- codegraph/agent_brain.py +81 -0
- codegraph/agent_capabilities.py +1037 -73
- codegraph/agent_rules.py +1 -0
- codegraph/architecture_rules.py +123 -0
- codegraph/changelog.py +170 -0
- codegraph/cli.py +793 -1
- codegraph/context.py +97 -13
- codegraph/dataflow_propagation.py +118 -0
- codegraph/dead_code.py +387 -0
- codegraph/epistemic.py +8 -0
- codegraph/evidence_contract.py +13 -3
- codegraph/federation.py +245 -0
- codegraph/frameworks.py +63 -6
- codegraph/graph/traversal.py +150 -7
- codegraph/graph_csr.py +218 -0
- codegraph/incremental.py +150 -0
- codegraph/indexing/classifier.py +5 -0
- codegraph/indexing/indexer.py +1 -0
- codegraph/indexing/languages/__init__.py +1 -0
- codegraph/indexing/languages/cpp.py +457 -0
- codegraph/indexing/languages/go.py +459 -0
- codegraph/indexing/languages/jvm.py +583 -0
- codegraph/indexing/languages/rust.py +507 -0
- codegraph/indexing/models.py +9 -1
- codegraph/indexing/parser.py +146 -9
- codegraph/indexing/protocols.py +220 -0
- codegraph/indexing/scanner.py +17 -0
- codegraph/interrogation.py +80 -20
- codegraph/lsp.py +318 -0
- codegraph/lsp_bridge/__init__.py +16 -0
- codegraph/lsp_bridge/bridge.py +102 -0
- codegraph/lsp_bridge/client.py +207 -0
- codegraph/lsp_bridge/models.py +71 -0
- codegraph/mcp/server.py +312 -1
- codegraph/memory/trajectory.py +282 -0
- codegraph/multi_agent/__init__.py +13 -0
- codegraph/multi_agent/coordinator.py +229 -0
- codegraph/multi_agent/models.py +76 -0
- codegraph/polymorphism.py +95 -0
- codegraph/pr_review.py +296 -0
- codegraph/process_lifecycle.py +22 -2
- codegraph/reachability.py +198 -0
- codegraph/reachability_index.py +74 -0
- codegraph/refactor/__init__.py +12 -0
- codegraph/refactor/patcher.py +348 -0
- codegraph/refactor/renamer.py +3 -3
- codegraph/refactor/transactions.py +23 -12
- codegraph/repair.py +233 -0
- codegraph/resolver.py +155 -2
- codegraph/retrieval_policy.py +16 -1
- codegraph/roblox.py +2174 -0
- codegraph/route_composer.py +7 -0
- codegraph/runtime/__init__.py +6 -0
- codegraph/runtime/db_watcher.py +2 -2
- codegraph/runtime/otel_receiver.py +208 -0
- codegraph/sandbox.py +215 -0
- codegraph/security/supply_chain.py +188 -0
- codegraph/security/taint.py +421 -0
- codegraph/test_gen.py +437 -0
- codegraph/ui/server.py +200 -39
- codegraph/watcher.py +2 -2
- {codegraph_engine-3.0.0.dist-info → codegraph_engine-3.0.1.dist-info}/METADATA +255 -69
- {codegraph_engine-3.0.0.dist-info → codegraph_engine-3.0.1.dist-info}/RECORD +69 -34
- {codegraph_engine-3.0.0.dist-info → codegraph_engine-3.0.1.dist-info}/WHEEL +1 -1
- {codegraph_engine-3.0.0.dist-info → codegraph_engine-3.0.1.dist-info}/entry_points.txt +0 -0
- {codegraph_engine-3.0.0.dist-info → codegraph_engine-3.0.1.dist-info}/licenses/LICENSE +0 -0
- {codegraph_engine-3.0.0.dist-info → codegraph_engine-3.0.1.dist-info}/top_level.txt +0 -0
codegraph/cli.py
CHANGED
|
@@ -422,6 +422,7 @@ def trace(
|
|
|
422
422
|
callees: Annotated[bool, typer.Option("--callees", help="Trace direct callees")] = False,
|
|
423
423
|
both: Annotated[bool, typer.Option("--both", help="Trace both callers and callees")] = False,
|
|
424
424
|
depth: Annotated[int, typer.Option("--depth", "-d", help="Max trace depth (clamped to max 5)")] = 2,
|
|
425
|
+
compact: Annotated[bool, typer.Option("--compact", help="Emit compact human-readable summary")] = False,
|
|
425
426
|
) -> None:
|
|
426
427
|
"""Trace a symbol definition, callers, and callees with explicit confidence labels."""
|
|
427
428
|
repo = _resolve_repo(repository=repository)
|
|
@@ -477,6 +478,33 @@ def trace(
|
|
|
477
478
|
)
|
|
478
479
|
)
|
|
479
480
|
return
|
|
481
|
+
if compact:
|
|
482
|
+
cli_echo(f"Trace for: {symbol}")
|
|
483
|
+
definitions = [x for x in res if x.get("relationship") == "DEFINES"]
|
|
484
|
+
handlers = [x for x in res if x.get("relationship") == "HANDLED_BY"]
|
|
485
|
+
caller_list = [x for x in res if x.get("relationship") == "CALLER"]
|
|
486
|
+
callee_list = [x for x in res if x.get("relationship") == "CALLEE"]
|
|
487
|
+
if definitions:
|
|
488
|
+
cli_echo(" Definitions:")
|
|
489
|
+
for d in definitions[:5]:
|
|
490
|
+
cli_echo(f" - {d.get('symbol')} ({d.get('file')}:{d.get('start_line')})")
|
|
491
|
+
if handlers:
|
|
492
|
+
cli_echo(" Handled by Routes:")
|
|
493
|
+
for h in handlers[:5]:
|
|
494
|
+
cli_echo(f" - {h.get('symbol')} ({h.get('file')}:{h.get('start_line')})")
|
|
495
|
+
if caller_list:
|
|
496
|
+
cli_echo(f" Callers ({len(caller_list)} total):")
|
|
497
|
+
for c in caller_list[:15]:
|
|
498
|
+
cli_echo(f" - {c.get('symbol')} at {c.get('file')}:{c.get('start_line')} [{c.get('confidence')}]")
|
|
499
|
+
if len(caller_list) > 15:
|
|
500
|
+
cli_echo(f" ... and {len(caller_list) - 15} more")
|
|
501
|
+
if callee_list:
|
|
502
|
+
cli_echo(f" Callees ({len(callee_list)} total):")
|
|
503
|
+
for c in callee_list[:15]:
|
|
504
|
+
cli_echo(f" - {c.get('symbol')} at {c.get('file')}:{c.get('start_line')} [{c.get('confidence')}]")
|
|
505
|
+
if len(callee_list) > 15:
|
|
506
|
+
cli_echo(f" ... and {len(callee_list) - 15} more")
|
|
507
|
+
return
|
|
480
508
|
typer.echo(json.dumps(res, indent=2))
|
|
481
509
|
|
|
482
510
|
|
|
@@ -688,6 +716,113 @@ def api_drift_alias(
|
|
|
688
716
|
api_drift_cmd(path=path, repository=repository, json_output=json_output)
|
|
689
717
|
|
|
690
718
|
|
|
719
|
+
@app.command("dead-code")
|
|
720
|
+
def dead_code_cmd(
|
|
721
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
722
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
723
|
+
max_symbols: Annotated[int, typer.Option("--max-symbols", "-m", help="Max dead symbols to display")] = 50,
|
|
724
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output raw JSON")] = False,
|
|
725
|
+
) -> None:
|
|
726
|
+
"""Detect zero-caller functions/classes, uncalled zombie HTTP routes, and orphaned database tables."""
|
|
727
|
+
from codegraph.dead_code import analyze_dead_code
|
|
728
|
+
|
|
729
|
+
repo = _resolve_repo(path, repository)
|
|
730
|
+
if not _ensure_indexed(repo):
|
|
731
|
+
return
|
|
732
|
+
|
|
733
|
+
with _indexer(repo).session() as con:
|
|
734
|
+
report = analyze_dead_code(con, repo, max_symbols=max_symbols)
|
|
735
|
+
|
|
736
|
+
if json_output:
|
|
737
|
+
typer.echo(json.dumps(report.as_dict(), indent=2))
|
|
738
|
+
return
|
|
739
|
+
|
|
740
|
+
typer.echo(f"CodeGraph Dead Code & Zombie Route Report for {repo.name}:")
|
|
741
|
+
typer.echo(f" Runtime Telemetry: {'PRESENT' if report.runtime_traces_present else 'ABSENT (Routes marked UNOBSERVED_AT_RUNTIME)'}")
|
|
742
|
+
typer.echo(f" Total Flagged: {report.total_dead_count}")
|
|
743
|
+
typer.echo(f" Dead Symbols: {len(report.dead_symbols)}")
|
|
744
|
+
typer.echo(f" Zombie Routes: {len(report.zombie_routes)}")
|
|
745
|
+
typer.echo(f" Orphaned Tables: {len(report.orphaned_tables)}\n")
|
|
746
|
+
|
|
747
|
+
if report.dead_symbols:
|
|
748
|
+
typer.echo("Dead Symbols (0 Static Callers, 0 Runtime Invocations):")
|
|
749
|
+
for s in report.dead_symbols:
|
|
750
|
+
typer.echo(f" - [{s.kind}] {s.name} ({s.file_path}:{s.line}) [{s.confidence}]")
|
|
751
|
+
typer.echo()
|
|
752
|
+
|
|
753
|
+
if report.zombie_routes:
|
|
754
|
+
typer.echo("Zombie & Unobserved HTTP Routes:")
|
|
755
|
+
for r in report.zombie_routes:
|
|
756
|
+
typer.echo(f" - [{r.http_method}] {r.route_path} -> {r.handler_name} ({r.file_path}:{r.line}) [{r.status}]")
|
|
757
|
+
typer.echo()
|
|
758
|
+
|
|
759
|
+
if report.orphaned_tables:
|
|
760
|
+
typer.echo("Orphaned Database Tables (0 Readers, 0 Writers):")
|
|
761
|
+
for t in report.orphaned_tables:
|
|
762
|
+
typer.echo(f" - {t.table_name} ({t.file_path}:{t.line}) [{t.confidence}]")
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
@app.command("otel-listen")
|
|
766
|
+
def otel_listen_cmd(
|
|
767
|
+
port: Annotated[int, typer.Option("--port", "-p", help="Listening port for OTLP HTTP receiver (default: 4318)")] = 4318,
|
|
768
|
+
host: Annotated[str, typer.Option("--host", "-h", help="Listening host (default: 127.0.0.1)")] = "127.0.0.1",
|
|
769
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
770
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
771
|
+
) -> None:
|
|
772
|
+
"""Run lightweight embedded OpenTelemetry (OTLP/HTTP) trace receiver streaming into .codegraph.sqlite3."""
|
|
773
|
+
import asyncio
|
|
774
|
+
|
|
775
|
+
from codegraph.runtime.otel_receiver import run_otel_listener
|
|
776
|
+
|
|
777
|
+
repo = _resolve_repo(path, repository)
|
|
778
|
+
if not _ensure_indexed(repo):
|
|
779
|
+
return
|
|
780
|
+
|
|
781
|
+
indexer = _indexer(repo)
|
|
782
|
+
|
|
783
|
+
def on_batch(result: dict[str, Any]) -> None:
|
|
784
|
+
events = result.get("ingested_events", 0)
|
|
785
|
+
edges = result.get("edges_created", 0)
|
|
786
|
+
typer.echo(f"[OTLP] Ingested trace batch: {events} spans -> {edges} runtime graph edges")
|
|
787
|
+
|
|
788
|
+
async def main() -> None:
|
|
789
|
+
receiver = await run_otel_listener(
|
|
790
|
+
db_path=indexer.db_path,
|
|
791
|
+
host=host,
|
|
792
|
+
port=port,
|
|
793
|
+
on_batch=on_batch,
|
|
794
|
+
)
|
|
795
|
+
typer.echo(f"CodeGraph OTLP HTTP Receiver listening on http://{host}:{port}/v1/traces")
|
|
796
|
+
typer.echo(f"Export traces using: export OTEL_EXPORTER_OTLP_ENDPOINT=http://{host}:{port}")
|
|
797
|
+
typer.echo("Press Ctrl+C to terminate.")
|
|
798
|
+
try:
|
|
799
|
+
while True:
|
|
800
|
+
await asyncio.sleep(1)
|
|
801
|
+
except (KeyboardInterrupt, asyncio.CancelledError):
|
|
802
|
+
await receiver.stop()
|
|
803
|
+
typer.echo("\nOTLP Receiver stopped.")
|
|
804
|
+
|
|
805
|
+
try:
|
|
806
|
+
asyncio.run(main())
|
|
807
|
+
except KeyboardInterrupt:
|
|
808
|
+
pass
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
@app.command("lsp")
|
|
812
|
+
def lsp_cmd(
|
|
813
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
814
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
815
|
+
) -> None:
|
|
816
|
+
"""Run Language Server Protocol (LSP) server over stdio for IDE integration (VS Code, Neovim, Helix)."""
|
|
817
|
+
from codegraph.lsp import run_stdio_lsp_server
|
|
818
|
+
|
|
819
|
+
repo = _resolve_repo(path, repository)
|
|
820
|
+
if not _ensure_indexed(repo):
|
|
821
|
+
return
|
|
822
|
+
|
|
823
|
+
run_stdio_lsp_server(repo)
|
|
824
|
+
|
|
825
|
+
|
|
691
826
|
@app.command()
|
|
692
827
|
def imports(
|
|
693
828
|
path: Annotated[str | None, typer.Argument(help="Repository-relative file path to inspect imports for (default: inspect all imports)")] = None,
|
|
@@ -1206,7 +1341,10 @@ def context(
|
|
|
1206
1341
|
mode=mode,
|
|
1207
1342
|
explain=explain,
|
|
1208
1343
|
)
|
|
1209
|
-
|
|
1344
|
+
if json_output:
|
|
1345
|
+
typer.echo(json.dumps(packet.as_dict(), indent=2))
|
|
1346
|
+
else:
|
|
1347
|
+
typer.echo(packet.format_human())
|
|
1210
1348
|
|
|
1211
1349
|
|
|
1212
1350
|
@app.command("explain-context")
|
|
@@ -1750,6 +1888,500 @@ def git_conflicts_cmd(
|
|
|
1750
1888
|
cli_echo(f" Head ({head}): {c.head_file} ({c.head_evidence})")
|
|
1751
1889
|
|
|
1752
1890
|
|
|
1891
|
+
agent_memory_app = typer.Typer(
|
|
1892
|
+
help="Long-term agent trajectory & debugging memory store.",
|
|
1893
|
+
no_args_is_help=True,
|
|
1894
|
+
)
|
|
1895
|
+
app.add_typer(agent_memory_app, name="agent-memory")
|
|
1896
|
+
|
|
1897
|
+
|
|
1898
|
+
@agent_memory_app.command("store")
|
|
1899
|
+
def memory_store_cmd(
|
|
1900
|
+
title: Annotated[str, typer.Option("--title", "-t", help="Title or summary of the debugging session/decision")],
|
|
1901
|
+
resolution: Annotated[str, typer.Option("--resolution", "-r", help="Resolution or architectural fix applied")],
|
|
1902
|
+
category: Annotated[str, typer.Option("--category", "-c", help="Category: BUG_FIX, ARCHITECTURE_DECISION, TEST_PATTERN, ROOT_CAUSE")] = "BUG_FIX",
|
|
1903
|
+
symptoms: Annotated[str, typer.Option("--symptoms", "-s", help="Observed symptoms or error traces")] = "",
|
|
1904
|
+
root_cause: Annotated[str, typer.Option("--root-cause", help="Identified root cause")] = "",
|
|
1905
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
1906
|
+
repository: Annotated[Path | None, typer.Option("--repository", "--repo", help="Repository path")] = None,
|
|
1907
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
1908
|
+
) -> None:
|
|
1909
|
+
"""Store an agent debugging trajectory or architectural decision into persistent memory."""
|
|
1910
|
+
from codegraph.memory.trajectory import get_trajectory_memory_store
|
|
1911
|
+
|
|
1912
|
+
repo = _resolve_repo(path, repository)
|
|
1913
|
+
store = get_trajectory_memory_store(repo)
|
|
1914
|
+
record = store.store(
|
|
1915
|
+
title=title,
|
|
1916
|
+
resolution=resolution,
|
|
1917
|
+
category=category,
|
|
1918
|
+
symptoms=symptoms,
|
|
1919
|
+
root_cause=root_cause,
|
|
1920
|
+
)
|
|
1921
|
+
|
|
1922
|
+
if json_output:
|
|
1923
|
+
cli_echo(json.dumps(record.as_dict(), indent=2), json_mode=True)
|
|
1924
|
+
else:
|
|
1925
|
+
cli_echo(f"Stored Agent Memory Record [{record.id}]:")
|
|
1926
|
+
cli_echo(f" Category: {record.category}")
|
|
1927
|
+
cli_echo(f" Title: {record.title}")
|
|
1928
|
+
cli_echo(f" Resolution: {record.resolution}")
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
@agent_memory_app.command("search")
|
|
1932
|
+
def memory_search_cmd(
|
|
1933
|
+
query: Annotated[str, typer.Argument(help="Search query matching symptoms, title, root cause, or resolution")],
|
|
1934
|
+
category: Annotated[str | None, typer.Option("--category", "-c", help="Filter by category")] = None,
|
|
1935
|
+
limit: Annotated[int, typer.Option("--limit", "-l", help="Max records to return")] = 5,
|
|
1936
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
1937
|
+
repository: Annotated[Path | None, typer.Option("--repository", "--repo", help="Repository path")] = None,
|
|
1938
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
1939
|
+
) -> None:
|
|
1940
|
+
"""Search past agent debugging memories and architectural decisions using FTS5 BM25 ranking."""
|
|
1941
|
+
from codegraph.memory.trajectory import get_trajectory_memory_store
|
|
1942
|
+
|
|
1943
|
+
repo = _resolve_repo(path, repository)
|
|
1944
|
+
store = get_trajectory_memory_store(repo)
|
|
1945
|
+
records = store.search(query=query, category=category, limit=limit)
|
|
1946
|
+
|
|
1947
|
+
if json_output:
|
|
1948
|
+
cli_echo(json.dumps([r.as_dict() for r in records], indent=2), json_mode=True)
|
|
1949
|
+
else:
|
|
1950
|
+
cli_echo(f"Found {len(records)} Agent Memory Record(s) for '{query}':")
|
|
1951
|
+
for r in records:
|
|
1952
|
+
cli_echo(f"\n [{r.category}] {r.title} (Relevance: {r.score})")
|
|
1953
|
+
if r.symptoms:
|
|
1954
|
+
cli_echo(f" Symptoms: {r.symptoms}")
|
|
1955
|
+
if r.root_cause:
|
|
1956
|
+
cli_echo(f" Root Cause: {r.root_cause}")
|
|
1957
|
+
cli_echo(f" Resolution: {r.resolution}")
|
|
1958
|
+
|
|
1959
|
+
|
|
1960
|
+
@agent_memory_app.command("list")
|
|
1961
|
+
def memory_list_cmd(
|
|
1962
|
+
limit: Annotated[int, typer.Option("--limit", "-l", help="Max records to return")] = 10,
|
|
1963
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
1964
|
+
repository: Annotated[Path | None, typer.Option("--repository", "--repo", help="Repository path")] = None,
|
|
1965
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
1966
|
+
) -> None:
|
|
1967
|
+
"""List recent agent memories."""
|
|
1968
|
+
from codegraph.memory.trajectory import get_trajectory_memory_store
|
|
1969
|
+
|
|
1970
|
+
repo = _resolve_repo(path, repository)
|
|
1971
|
+
store = get_trajectory_memory_store(repo)
|
|
1972
|
+
records = store.list_recent(limit=limit)
|
|
1973
|
+
|
|
1974
|
+
if json_output:
|
|
1975
|
+
cli_echo(json.dumps([r.as_dict() for r in records], indent=2), json_mode=True)
|
|
1976
|
+
else:
|
|
1977
|
+
cli_echo(f"Recent Agent Memories ({len(records)}):")
|
|
1978
|
+
for r in records:
|
|
1979
|
+
cli_echo(f" [{r.id}] ({r.category}) {r.title} - {r.created_at}")
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
@agent_memory_app.command("clear")
|
|
1983
|
+
def memory_clear_cmd(
|
|
1984
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
1985
|
+
repository: Annotated[Path | None, typer.Option("--repository", "--repo", help="Repository path")] = None,
|
|
1986
|
+
) -> None:
|
|
1987
|
+
"""Clear all agent memory records for the repository."""
|
|
1988
|
+
from codegraph.memory.trajectory import get_trajectory_memory_store
|
|
1989
|
+
|
|
1990
|
+
repo = _resolve_repo(path, repository)
|
|
1991
|
+
store = get_trajectory_memory_store(repo)
|
|
1992
|
+
store.clear()
|
|
1993
|
+
cli_echo("Agent memory cleared.")
|
|
1994
|
+
|
|
1995
|
+
|
|
1996
|
+
federate_app = typer.Typer(
|
|
1997
|
+
help="Cross-repository & microservice graph federation commands.",
|
|
1998
|
+
no_args_is_help=True,
|
|
1999
|
+
)
|
|
2000
|
+
app.add_typer(federate_app, name="federate")
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
@federate_app.command("scan")
|
|
2004
|
+
def federate_scan_cmd(
|
|
2005
|
+
workspace_root: Annotated[Path | None, typer.Argument(help="Workspace directory containing repositories (default: current directory)")] = None,
|
|
2006
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2007
|
+
) -> None:
|
|
2008
|
+
"""Discover federated repositories and index sizes in a multi-repo workspace."""
|
|
2009
|
+
from codegraph.federation import federate_workspace
|
|
2010
|
+
|
|
2011
|
+
root = workspace_root or Path.cwd()
|
|
2012
|
+
report = federate_workspace(root)
|
|
2013
|
+
|
|
2014
|
+
if json_output:
|
|
2015
|
+
cli_echo(json.dumps(report.as_dict(), indent=2), json_mode=True)
|
|
2016
|
+
else:
|
|
2017
|
+
cli_echo(f"Federated Workspace: {report.workspace_root}")
|
|
2018
|
+
cli_echo(f"Discovered Repositories ({len(report.repos)}):")
|
|
2019
|
+
for r in report.repos:
|
|
2020
|
+
cli_echo(f" - [{r.name}] {r.path}")
|
|
2021
|
+
cli_echo(f" Symbols: {r.symbol_count} | Routes: {r.route_count} | Database: {r.db_path}")
|
|
2022
|
+
|
|
2023
|
+
|
|
2024
|
+
@federate_app.command("routes")
|
|
2025
|
+
def federate_routes_cmd(
|
|
2026
|
+
workspace_root: Annotated[Path | None, typer.Argument(help="Workspace directory containing repositories (default: current directory)")] = None,
|
|
2027
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2028
|
+
) -> None:
|
|
2029
|
+
"""Resolve cross-repository HTTP and RPC service-to-service links across microservices."""
|
|
2030
|
+
from codegraph.federation import federate_workspace
|
|
2031
|
+
|
|
2032
|
+
root = workspace_root or Path.cwd()
|
|
2033
|
+
report = federate_workspace(root)
|
|
2034
|
+
|
|
2035
|
+
if json_output:
|
|
2036
|
+
cli_echo(json.dumps(report.as_dict(), indent=2), json_mode=True)
|
|
2037
|
+
else:
|
|
2038
|
+
cli_echo(f"Cross-Repository Route Links in {report.workspace_root}:")
|
|
2039
|
+
if not report.cross_repo_links:
|
|
2040
|
+
cli_echo(" No cross-repository route calls discovered.")
|
|
2041
|
+
for link in report.cross_repo_links:
|
|
2042
|
+
cli_echo(
|
|
2043
|
+
f" [{link.confidence}] {link.source_repo}:{link.source_file} ({link.source_symbol})\n"
|
|
2044
|
+
f" --[{link.http_method} {link.route_path}]-->\n"
|
|
2045
|
+
f" {link.target_repo}:{link.target_file} ({link.target_handler})"
|
|
2046
|
+
)
|
|
2047
|
+
|
|
2048
|
+
|
|
2049
|
+
@app.command("generate-tests")
|
|
2050
|
+
def generate_tests_cmd(
|
|
2051
|
+
target: Annotated[str, typer.Argument(help="Symbol name, canonical ID, or HTTP route path to generate tests for")],
|
|
2052
|
+
framework: Annotated[str | None, typer.Option("--framework", "-f", help="Target test framework (pytest, jest, testez)")] = None,
|
|
2053
|
+
output_file: Annotated[Path | None, typer.Option("--output-file", "-o", help="Write generated test suite to file")] = None,
|
|
2054
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
2055
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2056
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2057
|
+
) -> None:
|
|
2058
|
+
"""Generate production-ready test scaffolding with fixtures, dependency mocks, and boundary test cases."""
|
|
2059
|
+
from codegraph.test_gen import generate_test_scaffolding
|
|
2060
|
+
|
|
2061
|
+
repo = _resolve_repo(path, repository)
|
|
2062
|
+
indexer = _indexer(repo)
|
|
2063
|
+
|
|
2064
|
+
with indexer.session() as con:
|
|
2065
|
+
scaffold = generate_test_scaffolding(con, target=target, repository=repo, framework=framework)
|
|
2066
|
+
|
|
2067
|
+
if output_file:
|
|
2068
|
+
output_file.parent.mkdir(parents=True, exist_ok=True)
|
|
2069
|
+
output_file.write_text(scaffold.test_code, encoding="utf-8")
|
|
2070
|
+
cli_echo(f"Wrote generated test scaffold to {output_file}")
|
|
2071
|
+
|
|
2072
|
+
if json_output:
|
|
2073
|
+
cli_echo(json.dumps(scaffold.as_dict(), indent=2), json_mode=True)
|
|
2074
|
+
elif not output_file:
|
|
2075
|
+
cli_echo(f"Generated {scaffold.framework} Test Scaffold for '{scaffold.target_symbol}':")
|
|
2076
|
+
cli_echo(f"Target Source File: {scaffold.target_file}")
|
|
2077
|
+
cli_echo(f"SuggestedTest File: {scaffold.suggested_test_file}")
|
|
2078
|
+
if scaffold.mock_requirements:
|
|
2079
|
+
cli_echo("\nDetected Mock Requirements:")
|
|
2080
|
+
for m in scaffold.mock_requirements:
|
|
2081
|
+
cli_echo(f" - [{m.mock_type}] {m.target}: {m.description}")
|
|
2082
|
+
cli_echo("\n--- Generated Test Code ---")
|
|
2083
|
+
cli_echo(scaffold.test_code)
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
@app.command("pr-review")
|
|
2087
|
+
def pr_review_cmd(
|
|
2088
|
+
base: Annotated[str, typer.Argument(help="Base Git branch/commit (default: main)")] = "main",
|
|
2089
|
+
head: Annotated[str, typer.Argument(help="Head Git branch/commit (default: HEAD)")] = "HEAD",
|
|
2090
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
2091
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2092
|
+
output_file: Annotated[Path | None, typer.Option("--output-file", "-o", help="Write markdown review to file")] = None,
|
|
2093
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2094
|
+
) -> None:
|
|
2095
|
+
"""Generate comprehensive semantic PR review evaluating structural diffs, contract breaks, affected routes, and test coverage."""
|
|
2096
|
+
from codegraph.pr_review import generate_pr_review
|
|
2097
|
+
|
|
2098
|
+
repo = _resolve_repo(path, repository)
|
|
2099
|
+
indexer = _indexer(repo)
|
|
2100
|
+
|
|
2101
|
+
with indexer.session() as con:
|
|
2102
|
+
rep = generate_pr_review(repo, base_ref=base, head_ref=head, con=con)
|
|
2103
|
+
|
|
2104
|
+
if output_file:
|
|
2105
|
+
output_file.write_text(rep.markdown_report, encoding="utf-8")
|
|
2106
|
+
|
|
2107
|
+
if json_output:
|
|
2108
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2109
|
+
else:
|
|
2110
|
+
cli_echo(rep.markdown_report)
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
security_app = typer.Typer(no_args_is_help=True, help="Security SAST taint tracking and vulnerability audit.")
|
|
2114
|
+
app.add_typer(security_app, name="security")
|
|
2115
|
+
|
|
2116
|
+
|
|
2117
|
+
@security_app.command("audit")
|
|
2118
|
+
def security_audit_cmd(
|
|
2119
|
+
entrypoint: Annotated[str | None, typer.Option("--entrypoint", "-e", help="Optional entrypoint symbol or handler")] = None,
|
|
2120
|
+
cwe: Annotated[str | None, typer.Option("--cwe", help="Filter by CWE identifier (e.g. CWE-89, CWE-78, CWE-22, CWE-918, CWE-502)")] = None,
|
|
2121
|
+
max_depth: Annotated[int, typer.Option("--max-depth", help="Maximum AST traversal depth")] = 12,
|
|
2122
|
+
sarif: Annotated[bool, typer.Option("--sarif", help="Output OASIS SARIF 2.1.0 format for GitHub Code Scanning")] = False,
|
|
2123
|
+
sarif_output: Annotated[Path | None, typer.Option("--sarif-output", help="Write SARIF 2.1.0 JSON report to file")] = None,
|
|
2124
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2125
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2126
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2127
|
+
) -> None:
|
|
2128
|
+
"""Analyze source-to-sink dataflow taint paths for injection and security vulnerabilities."""
|
|
2129
|
+
from codegraph.security.taint import audit_repository_taint
|
|
2130
|
+
|
|
2131
|
+
repo = _resolve_repo(path, repository)
|
|
2132
|
+
indexer = _indexer(repo)
|
|
2133
|
+
|
|
2134
|
+
with indexer.session() as con:
|
|
2135
|
+
rep = audit_repository_taint(repo, con=con, entrypoint_symbol=entrypoint, filter_cwe=cwe, max_depth=max_depth)
|
|
2136
|
+
|
|
2137
|
+
if sarif_output:
|
|
2138
|
+
sarif_data = rep.to_sarif()
|
|
2139
|
+
sarif_output.write_text(json.dumps(sarif_data, indent=2), encoding="utf-8")
|
|
2140
|
+
if not json_output and not sarif:
|
|
2141
|
+
cli_echo(f"Exported SARIF 2.1.0 report with {rep.total_vulnerabilities} findings to {sarif_output}")
|
|
2142
|
+
|
|
2143
|
+
if sarif:
|
|
2144
|
+
cli_echo(json.dumps(rep.to_sarif(), indent=2), json_mode=True)
|
|
2145
|
+
elif json_output:
|
|
2146
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2147
|
+
else:
|
|
2148
|
+
cli_echo(f"Security SAST Taint Audit for {repo.name}:")
|
|
2149
|
+
cli_echo(f" Total Vulnerabilities: {rep.total_vulnerabilities}")
|
|
2150
|
+
cli_echo(f" Critical: {rep.critical_count} | High: {rep.high_count} | Medium: {rep.medium_count} | Low: {rep.low_count}")
|
|
2151
|
+
for v in rep.vulnerabilities:
|
|
2152
|
+
cli_echo(f"\n • [{v.severity.value}] {v.cwe_id}: {v.vulnerability_type}")
|
|
2153
|
+
cli_echo(f" Source: {v.source_expr} ({v.file_path}:{v.source_line})")
|
|
2154
|
+
cli_echo(f" Sink: {v.sink_expr} ({v.file_path}:{v.sink_line})")
|
|
2155
|
+
cli_echo(f" Remediation: {v.remediation}")
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
@app.command("repair")
|
|
2159
|
+
def repair_cmd(
|
|
2160
|
+
quick: Annotated[bool, typer.Option("--quick", help="Run quick check only without deep FTS & orphaned FK cleanup")] = False,
|
|
2161
|
+
vacuum: Annotated[bool, typer.Option("--vacuum", help="Run SQLite VACUUM to defragment index pages")] = False,
|
|
2162
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2163
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2164
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2165
|
+
) -> None:
|
|
2166
|
+
"""Perform automated self-healing, integrity check, dangling FK pruning, FTS rebuild, and WAL checkpointing."""
|
|
2167
|
+
from codegraph.repair import repair_repository_index
|
|
2168
|
+
|
|
2169
|
+
repo = _resolve_repo(path, repository)
|
|
2170
|
+
rep = repair_repository_index(repo, deep=not quick, vacuum=vacuum)
|
|
2171
|
+
|
|
2172
|
+
if json_output:
|
|
2173
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2174
|
+
else:
|
|
2175
|
+
cli_echo(f"Database Index Self-Healing for {repo.name}: Status: {rep.status}")
|
|
2176
|
+
cli_echo(f" Integrity Check: {'PASSED' if rep.integrity_check_passed else 'FAILED'}")
|
|
2177
|
+
cli_echo(f" FTS5 Rebuilt: {rep.fts_rebuilt}")
|
|
2178
|
+
cli_echo(f" WAL Checkpoint: {rep.wal_checkpointed}")
|
|
2179
|
+
cli_echo(f" Stale Locks: {rep.stale_locks_cleared}")
|
|
2180
|
+
if rep.actions_taken:
|
|
2181
|
+
cli_echo(" Actions Taken:")
|
|
2182
|
+
for act in rep.actions_taken:
|
|
2183
|
+
cli_echo(f" - {act}")
|
|
2184
|
+
if rep.issues_found:
|
|
2185
|
+
cli_echo(" Issues Found:")
|
|
2186
|
+
for issue in rep.issues_found:
|
|
2187
|
+
cli_echo(f" ! {issue}")
|
|
2188
|
+
|
|
2189
|
+
|
|
2190
|
+
lsp_bridge_app = typer.Typer(no_args_is_help=True, help="Language Server Protocol (LSP) diagnostics bridge.")
|
|
2191
|
+
app.add_typer(lsp_bridge_app, name="lsp-bridge")
|
|
2192
|
+
|
|
2193
|
+
|
|
2194
|
+
@lsp_bridge_app.command("status")
|
|
2195
|
+
def lsp_status_cmd(
|
|
2196
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2197
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2198
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2199
|
+
) -> None:
|
|
2200
|
+
"""Discover available Language Server Protocol (LSP) daemons on host system."""
|
|
2201
|
+
from codegraph.lsp_bridge.bridge import detect_lsp_servers
|
|
2202
|
+
|
|
2203
|
+
repo = _resolve_repo(path, repository)
|
|
2204
|
+
servers = detect_lsp_servers(repo)
|
|
2205
|
+
if json_output:
|
|
2206
|
+
cli_echo(json.dumps(servers, indent=2), json_mode=True)
|
|
2207
|
+
else:
|
|
2208
|
+
cli_echo(f"Discovered LSP Language Servers for {repo.name}:")
|
|
2209
|
+
if not servers:
|
|
2210
|
+
cli_echo(" No language servers found in PATH (pyright-langserver, gopls, rust-analyzer, clangd).")
|
|
2211
|
+
for lang, bin_path in servers.items():
|
|
2212
|
+
cli_echo(f" • {lang}: {bin_path}")
|
|
2213
|
+
|
|
2214
|
+
|
|
2215
|
+
@lsp_bridge_app.command("diagnostics")
|
|
2216
|
+
def lsp_diagnostics_cmd(
|
|
2217
|
+
file: Annotated[str | None, typer.Option("--file", "-f", help="Specific file to query diagnostics for")] = None,
|
|
2218
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2219
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2220
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2221
|
+
) -> None:
|
|
2222
|
+
"""Collect live compiler diagnostics and type errors from Language Server Protocol daemons."""
|
|
2223
|
+
from codegraph.lsp_bridge.bridge import collect_lsp_diagnostics
|
|
2224
|
+
|
|
2225
|
+
repo = _resolve_repo(path, repository)
|
|
2226
|
+
rep = collect_lsp_diagnostics(repo, file_path=file)
|
|
2227
|
+
|
|
2228
|
+
if json_output:
|
|
2229
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2230
|
+
else:
|
|
2231
|
+
cli_echo(f"LSP Diagnostics for {repo.name} [Status: {rep.status}]:")
|
|
2232
|
+
cli_echo(f" Total Diagnostics: {rep.total_diagnostics} (Errors: {rep.error_count}, Warnings: {rep.warning_count})")
|
|
2233
|
+
for d in rep.diagnostics:
|
|
2234
|
+
cli_echo(f" • [{d.severity.value}] {d.file_path}:{d.line}:{d.column} - {d.message} ({d.source})")
|
|
2235
|
+
|
|
2236
|
+
|
|
2237
|
+
swarm_app = typer.Typer(no_args_is_help=True, help="Multi-agent swarm coordination and file lease management.")
|
|
2238
|
+
app.add_typer(swarm_app, name="swarm")
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
@swarm_app.command("status")
|
|
2242
|
+
def swarm_status_cmd(
|
|
2243
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2244
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2245
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2246
|
+
) -> None:
|
|
2247
|
+
"""Display active AI coding agent sessions, leased files, and semantic conflicts."""
|
|
2248
|
+
from codegraph.multi_agent.coordinator import MultiAgentCoordinator
|
|
2249
|
+
|
|
2250
|
+
repo = _resolve_repo(path, repository)
|
|
2251
|
+
coord = MultiAgentCoordinator(repo)
|
|
2252
|
+
rep = coord.get_status_report()
|
|
2253
|
+
|
|
2254
|
+
if json_output:
|
|
2255
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2256
|
+
else:
|
|
2257
|
+
cli_echo(f"Multi-Agent Swarm Status for {repo.name}:")
|
|
2258
|
+
cli_echo(f" Active Agents: {rep.total_agents} | Active Leases: {rep.active_leases_count} | Conflicts: {rep.conflicts_count}")
|
|
2259
|
+
for a in rep.agents:
|
|
2260
|
+
cli_echo(f" • Agent [{a.agent_id}] '{a.name}': {a.task_description}")
|
|
2261
|
+
for lease in rep.leases:
|
|
2262
|
+
cli_echo(f" • Lease: {lease.file_path} held by {lease.agent_id} ({lease.lease_type})")
|
|
2263
|
+
for c in rep.conflicts:
|
|
2264
|
+
cli_echo(f" ! CONFLICT: {c.file_path} - {c.reason}")
|
|
2265
|
+
|
|
2266
|
+
|
|
2267
|
+
@swarm_app.command("claim")
|
|
2268
|
+
def swarm_claim_cmd(
|
|
2269
|
+
agent_id: Annotated[str, typer.Option("--agent-id", "-a", help="Agent identifier")] = "agent-1",
|
|
2270
|
+
file: Annotated[str, typer.Argument(help="File path to lease")] = "",
|
|
2271
|
+
shared: Annotated[bool, typer.Option("--shared", help="Claim shared read lease instead of exclusive write")] = False,
|
|
2272
|
+
ttl: Annotated[float, typer.Option("--ttl", help="Lease TTL in seconds")] = 60.0,
|
|
2273
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
2274
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2275
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2276
|
+
) -> None:
|
|
2277
|
+
"""Claim a lease lock on a file for an AI agent."""
|
|
2278
|
+
from codegraph.multi_agent.coordinator import MultiAgentCoordinator
|
|
2279
|
+
|
|
2280
|
+
repo = _resolve_repo(path, repository)
|
|
2281
|
+
coord = MultiAgentCoordinator(repo)
|
|
2282
|
+
lease_type = "SHARED_READ" if shared else "EXCLUSIVE_WRITE"
|
|
2283
|
+
ok, msg = coord.claim_lease(agent_id=agent_id, file_path=file, lease_type=lease_type, ttl_seconds=ttl)
|
|
2284
|
+
|
|
2285
|
+
if json_output:
|
|
2286
|
+
cli_echo(json.dumps({"success": ok, "message": msg, "file": file, "agent_id": agent_id}, indent=2), json_mode=True)
|
|
2287
|
+
else:
|
|
2288
|
+
cli_echo(f"{'SUCCESS' if ok else 'FAILED'}: {msg}")
|
|
2289
|
+
|
|
2290
|
+
|
|
2291
|
+
@app.command("lint-arch")
|
|
2292
|
+
def lint_arch_cmd(
|
|
2293
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2294
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2295
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2296
|
+
) -> None:
|
|
2297
|
+
"""Enforce declarative architectural invariants and layer boundary rules."""
|
|
2298
|
+
from codegraph.architecture_rules import evaluate_architecture_rules
|
|
2299
|
+
|
|
2300
|
+
repo = _resolve_repo(path, repository)
|
|
2301
|
+
indexer = _indexer(repo)
|
|
2302
|
+
with indexer.session() as con:
|
|
2303
|
+
rep = evaluate_architecture_rules(repo, con)
|
|
2304
|
+
|
|
2305
|
+
if json_output:
|
|
2306
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2307
|
+
else:
|
|
2308
|
+
cli_echo(f"Architecture Rule Check for {repo.name}: Status: {rep.status}")
|
|
2309
|
+
cli_echo(f" Rules Checked: {rep.total_rules_checked} | Violations: {rep.violations_count}")
|
|
2310
|
+
for v in rep.violations:
|
|
2311
|
+
cli_echo(f" • [{v.severity}] {v.source_file}:{v.line} -> {v.target_entity} ({v.rule_name})")
|
|
2312
|
+
cli_echo(f" Message: {v.message}")
|
|
2313
|
+
|
|
2314
|
+
|
|
2315
|
+
@app.command("reachability")
|
|
2316
|
+
def reachability_cmd(
|
|
2317
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2318
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2319
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2320
|
+
) -> None:
|
|
2321
|
+
"""Perform DI-aware root-to-leaf reachability analysis and dead code elimination."""
|
|
2322
|
+
from codegraph.reachability import compute_di_aware_reachability
|
|
2323
|
+
|
|
2324
|
+
repo = _resolve_repo(path, repository)
|
|
2325
|
+
indexer = _indexer(repo)
|
|
2326
|
+
with indexer.session() as con:
|
|
2327
|
+
rep = compute_di_aware_reachability(repo, con)
|
|
2328
|
+
|
|
2329
|
+
if json_output:
|
|
2330
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2331
|
+
else:
|
|
2332
|
+
cli_echo(f"DI-Aware Reachability & Dead Code for {repo.name}:")
|
|
2333
|
+
cli_echo(f" Total Symbols: {rep.total_symbols} | Reachable: {rep.reachable_count} | Unreachable: {rep.unreachable_count} ({rep.dead_code_percentage:.1f}%)")
|
|
2334
|
+
cli_echo(f" Root Entrypoints: {rep.root_entrypoints_count}")
|
|
2335
|
+
for s in rep.unreachable_symbols[:20]:
|
|
2336
|
+
cli_echo(f" • [{s.kind}] {s.name} ({s.file_path}:{s.line}) [CONFIDENCE: {s.confidence}]")
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
@app.command("changelog")
|
|
2340
|
+
def changelog_cmd(
|
|
2341
|
+
base: Annotated[str, typer.Option("--base", "-b", help="Base Git revision")] = "HEAD~1",
|
|
2342
|
+
head: Annotated[str, typer.Option("--head", "-h", help="Head Git revision")] = "HEAD",
|
|
2343
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2344
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2345
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2346
|
+
) -> None:
|
|
2347
|
+
"""Synthesize human-readable release changelog and breaking change report from AST diffs."""
|
|
2348
|
+
from codegraph.changelog import generate_semantic_changelog
|
|
2349
|
+
|
|
2350
|
+
repo = _resolve_repo(path, repository)
|
|
2351
|
+
rep = generate_semantic_changelog(repo, base_ref=base, head_ref=head)
|
|
2352
|
+
|
|
2353
|
+
if json_output:
|
|
2354
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2355
|
+
else:
|
|
2356
|
+
cli_echo(rep.markdown_changelog)
|
|
2357
|
+
|
|
2358
|
+
|
|
2359
|
+
@security_app.command("supply-chain")
|
|
2360
|
+
def security_supply_chain_cmd(
|
|
2361
|
+
package: Annotated[str | None, typer.Option("--package", "-p", help="Filter by specific package name")] = None,
|
|
2362
|
+
path: Annotated[Path | None, typer.Argument(help="Repository path (default: current directory)")] = None,
|
|
2363
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2364
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2365
|
+
) -> None:
|
|
2366
|
+
"""Inspect dependency manifests and trace internal call site reachability for packages."""
|
|
2367
|
+
from codegraph.security.supply_chain import analyze_supply_chain
|
|
2368
|
+
|
|
2369
|
+
repo = _resolve_repo(path, repository)
|
|
2370
|
+
indexer = _indexer(repo)
|
|
2371
|
+
with indexer.session() as con:
|
|
2372
|
+
rep = analyze_supply_chain(repo, con=con, target_package=package)
|
|
2373
|
+
|
|
2374
|
+
if json_output:
|
|
2375
|
+
cli_echo(json.dumps(rep.as_dict(), indent=2), json_mode=True)
|
|
2376
|
+
else:
|
|
2377
|
+
cli_echo(f"Dependency Supply Chain Reachability for {repo.name}:")
|
|
2378
|
+
cli_echo(f" Total Dependencies: {rep.total_dependencies} | Actively Imported: {rep.actively_imported_count} | Call Sites: {rep.total_call_sites}")
|
|
2379
|
+
cli_echo(f" Manifests: {', '.join(rep.manifests_found)}")
|
|
2380
|
+
for pkg in rep.packages[:25]:
|
|
2381
|
+
status_str = f"IMPORTED ({pkg.call_sites_count} call sites)" if pkg.is_actively_imported else "UNINVOKED"
|
|
2382
|
+
cli_echo(f" • {pkg.name} ({pkg.version_spec}) [{pkg.manifest_file}]: {status_str}")
|
|
2383
|
+
|
|
2384
|
+
|
|
1753
2385
|
@app.command("check-freshness")
|
|
1754
2386
|
def check_freshness_cli_cmd(
|
|
1755
2387
|
task: Annotated[str, typer.Argument(help="Task prompt to verify context freshness for")] = "",
|
|
@@ -1870,6 +2502,67 @@ def refactor_rename_cli_cmd(
|
|
|
1870
2502
|
cli_echo(f" ! {err}")
|
|
1871
2503
|
|
|
1872
2504
|
|
|
2505
|
+
@refactor_app.command("patch")
|
|
2506
|
+
def refactor_patch_cli_cmd(
|
|
2507
|
+
patch_file: Annotated[Path, typer.Argument(help="Path to JSON file containing patch specifications (or '-' for stdin)")],
|
|
2508
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
2509
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
2510
|
+
dry_run: Annotated[bool, typer.Option("--dry-run", "-d", help="Preview patch without modifying disk")] = False,
|
|
2511
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON format")] = False,
|
|
2512
|
+
) -> None:
|
|
2513
|
+
"""Atomically apply or preview a multi-file semantic patch with pre-flight syntax validation and rollback support."""
|
|
2514
|
+
import sys
|
|
2515
|
+
|
|
2516
|
+
from codegraph.refactor.models import RefactorStatus
|
|
2517
|
+
from codegraph.refactor.patcher import apply_semantic_patch, preview_semantic_patch
|
|
2518
|
+
|
|
2519
|
+
repo = _resolve_repo(path, repository)
|
|
2520
|
+
|
|
2521
|
+
if str(patch_file) == "-":
|
|
2522
|
+
raw_text = sys.stdin.read()
|
|
2523
|
+
else:
|
|
2524
|
+
if not patch_file.exists():
|
|
2525
|
+
cli_echo(f"Error: Patch file '{patch_file}' not found.", err=True)
|
|
2526
|
+
raise typer.Exit(1)
|
|
2527
|
+
raw_text = patch_file.read_text(encoding="utf-8")
|
|
2528
|
+
|
|
2529
|
+
try:
|
|
2530
|
+
data = json.loads(raw_text)
|
|
2531
|
+
patch_specs = data if isinstance(data, list) else data.get("patches", [data])
|
|
2532
|
+
except Exception as e:
|
|
2533
|
+
cli_echo(f"Error: Invalid JSON in patch file: {e}", err=True)
|
|
2534
|
+
raise typer.Exit(1) from e
|
|
2535
|
+
|
|
2536
|
+
if dry_run:
|
|
2537
|
+
result = preview_semantic_patch(repo, patch_specs)
|
|
2538
|
+
else:
|
|
2539
|
+
result = apply_semantic_patch(repo, patch_specs, dry_run=False)
|
|
2540
|
+
if result.status == RefactorStatus.APPLIED:
|
|
2541
|
+
try:
|
|
2542
|
+
indexer = _indexer(repo)
|
|
2543
|
+
indexer.index()
|
|
2544
|
+
except Exception:
|
|
2545
|
+
pass
|
|
2546
|
+
|
|
2547
|
+
if json_output:
|
|
2548
|
+
cli_echo(json.dumps(result.to_dict(), indent=2), json_mode=True)
|
|
2549
|
+
else:
|
|
2550
|
+
mode_label = "DRY-RUN PREVIEW" if dry_run else "COMMIT"
|
|
2551
|
+
cli_echo(f"Semantic Patch ({mode_label}): {result.status}")
|
|
2552
|
+
cli_echo(f"Files Changed: {result.files_changed}")
|
|
2553
|
+
if result.rollback_id:
|
|
2554
|
+
cli_echo(f"Rollback ID: {result.rollback_id}")
|
|
2555
|
+
if result.diffs:
|
|
2556
|
+
cli_echo("\nDiffs:")
|
|
2557
|
+
for p, d in result.diffs.items():
|
|
2558
|
+
cli_echo(f"--- {p} ---")
|
|
2559
|
+
cli_echo(d)
|
|
2560
|
+
if result.errors:
|
|
2561
|
+
cli_echo("\nErrors:")
|
|
2562
|
+
for err in result.errors:
|
|
2563
|
+
cli_echo(f" ! {err}")
|
|
2564
|
+
|
|
2565
|
+
|
|
1873
2566
|
@refactor_app.command("undo")
|
|
1874
2567
|
def refactor_undo_cli_cmd(
|
|
1875
2568
|
transaction_id: Annotated[str, typer.Argument(help="Transaction ID to rollback")],
|
|
@@ -2300,7 +2993,106 @@ def db_ingest_cli_cmd(
|
|
|
2300
2993
|
ingest_cli_cmd(source=source, repository=repository, format=format, json_output=json_output)
|
|
2301
2994
|
|
|
2302
2995
|
|
|
2996
|
+
roblox_app = typer.Typer(no_args_is_help=True, help="Roblox & Luau DataModel, Remote, Module, and Service intelligence.")
|
|
2997
|
+
app.add_typer(roblox_app, name="roblox")
|
|
2998
|
+
|
|
2999
|
+
|
|
3000
|
+
@roblox_app.command("remotes")
|
|
3001
|
+
def roblox_remotes_cli_cmd(
|
|
3002
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
3003
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
3004
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON result")] = False,
|
|
3005
|
+
) -> None:
|
|
3006
|
+
"""List Roblox RemoteEvents and RemoteFunctions with client dispatchers and server handlers."""
|
|
3007
|
+
from codegraph.roblox import list_roblox_remotes
|
|
3008
|
+
|
|
3009
|
+
repo = _resolve_repo(path, repository)
|
|
3010
|
+
if not _ensure_indexed(repo):
|
|
3011
|
+
raise typer.Exit(code=1)
|
|
3012
|
+
|
|
3013
|
+
indexer = _indexer(repo)
|
|
3014
|
+
with indexer.session() as con:
|
|
3015
|
+
res = list_roblox_remotes(con, repo)
|
|
3016
|
+
|
|
3017
|
+
if json_output:
|
|
3018
|
+
cli_echo(json.dumps(res, indent=2), json_mode=True)
|
|
3019
|
+
else:
|
|
3020
|
+
remotes = res.get("remotes", [])
|
|
3021
|
+
cli_echo(f"Roblox Remotes ({len(remotes)}):")
|
|
3022
|
+
for r in remotes:
|
|
3023
|
+
cli_echo(f" • {r.get('remote')} [{r.get('evidence_class')}]")
|
|
3024
|
+
for c in r.get("client_dispatchers", []):
|
|
3025
|
+
cli_echo(f" Client -> {c.get('symbol')} ({c.get('file')}:{c.get('line')})")
|
|
3026
|
+
for s in r.get("server_handlers", []):
|
|
3027
|
+
cli_echo(f" Server <- {s.get('symbol')} ({s.get('file')}:{s.get('line')})")
|
|
3028
|
+
|
|
3029
|
+
|
|
3030
|
+
@roblox_app.command("modules")
|
|
3031
|
+
def roblox_modules_cli_cmd(
|
|
3032
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
3033
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
3034
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON result")] = False,
|
|
3035
|
+
) -> None:
|
|
3036
|
+
"""List Luau / Roblox modules, Rojo DataModel paths, and require edges."""
|
|
3037
|
+
from codegraph.roblox import list_roblox_modules
|
|
3038
|
+
|
|
3039
|
+
repo = _resolve_repo(path, repository)
|
|
3040
|
+
if not _ensure_indexed(repo):
|
|
3041
|
+
raise typer.Exit(code=1)
|
|
3042
|
+
|
|
3043
|
+
indexer = _indexer(repo)
|
|
3044
|
+
with indexer.session() as con:
|
|
3045
|
+
res = list_roblox_modules(con, repo)
|
|
3046
|
+
|
|
3047
|
+
if json_output:
|
|
3048
|
+
cli_echo(json.dumps(res, indent=2), json_mode=True)
|
|
3049
|
+
else:
|
|
3050
|
+
modules = res.get("modules", [])
|
|
3051
|
+
cli_echo(f"Roblox / Luau Modules ({len(modules)}):")
|
|
3052
|
+
for m in modules:
|
|
3053
|
+
vpath = m.get("virtual_path") or "unmapped"
|
|
3054
|
+
cli_echo(f" • {m.get('file')} ({vpath}) [{m.get('evidence_class')}]")
|
|
3055
|
+
for req in m.get("requires", []):
|
|
3056
|
+
cli_echo(f" REQUIRES_MODULE -> {req.get('target')} [{req.get('evidence_class')}]")
|
|
3057
|
+
|
|
3058
|
+
|
|
3059
|
+
@roblox_app.command("routes")
|
|
3060
|
+
def roblox_routes_cli_cmd(
|
|
3061
|
+
path: Annotated[Path | None, typer.Option("--path", "-p", help="Repository path")] = None,
|
|
3062
|
+
repository: Annotated[Path | None, typer.Option("--repository", "-r", "--repo", help="Repository path")] = None,
|
|
3063
|
+
json_output: Annotated[bool, typer.Option("--json", help="Output JSON result")] = False,
|
|
3064
|
+
) -> None:
|
|
3065
|
+
"""List Roblox Client -> Remote -> Server routes, Knit services, and DataStore persistence bindings."""
|
|
3066
|
+
from codegraph.roblox import list_roblox_routes
|
|
3067
|
+
|
|
3068
|
+
repo = _resolve_repo(path, repository)
|
|
3069
|
+
if not _ensure_indexed(repo):
|
|
3070
|
+
raise typer.Exit(code=1)
|
|
3071
|
+
|
|
3072
|
+
indexer = _indexer(repo)
|
|
3073
|
+
with indexer.session() as con:
|
|
3074
|
+
res = list_roblox_routes(con, repo)
|
|
3075
|
+
|
|
3076
|
+
if json_output:
|
|
3077
|
+
cli_echo(json.dumps(res, indent=2), json_mode=True)
|
|
3078
|
+
else:
|
|
3079
|
+
routes = res.get("routes", [])
|
|
3080
|
+
services = res.get("services", [])
|
|
3081
|
+
persistence = res.get("persistence", [])
|
|
3082
|
+
cli_echo(f"Roblox Network Routes ({len(routes)}):")
|
|
3083
|
+
for rt in routes:
|
|
3084
|
+
cli_echo(f" • {rt.get('client')} -> {rt.get('remote')} -> {rt.get('server')} [{rt.get('evidence_class')}]")
|
|
3085
|
+
if services:
|
|
3086
|
+
cli_echo(f"\nKnit / Flamework Services ({len(services)}):")
|
|
3087
|
+
for sv in services:
|
|
3088
|
+
cli_echo(f" • {sv.get('provider')} ({sv.get('relationship')}) -> {sv.get('service')} [{sv.get('evidence_class')}]")
|
|
3089
|
+
if persistence:
|
|
3090
|
+
cli_echo(f"\nRoblox Persistence ({len(persistence)}):")
|
|
3091
|
+
for p in persistence:
|
|
3092
|
+
cli_echo(f" • {p.get('symbol')} ({p.get('relationship')}) -> {p.get('store')} [{p.get('evidence_class')}]")
|
|
3093
|
+
|
|
2303
3094
|
|
|
2304
3095
|
if __name__ == "__main__":
|
|
2305
3096
|
app()
|
|
2306
3097
|
|
|
3098
|
+
|