Skip to content

Commit 1de3ef5

Browse files
Seaualclaude
andcommitted
style: apply ruff format across entire codebase
Standardize type hints (Optional[X] -> X | None, Dict -> dict), sort imports, and fix trailing newlines across 51 files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d57ba55 commit 1de3ef5

61 files changed

Lines changed: 4414 additions & 352 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ demo_papers*.json
8888

8989
# Redis dump
9090
dump.rdb
91+
.gitnexus

.mcp.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"mcpServers": {
3+
"gitnexus": {
4+
"command": "npx",
5+
"args": ["gitnexus@latest", "mcp"]
6+
}
7+
}
8+
}

AGENTS.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!-- gitnexus:start -->
2+
# GitNexus — Code Intelligence
3+
4+
This project is indexed by GitNexus as **meta-knowledge-graph-main** (1781 symbols, 5293 relationships, 149 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
5+
6+
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
7+
8+
## Always Do
9+
10+
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `gitnexus_impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
11+
- **MUST run `gitnexus_detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows.
12+
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
13+
- When exploring unfamiliar code, use `gitnexus_query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
14+
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `gitnexus_context({name: "symbolName"})`.
15+
16+
## When Debugging
17+
18+
1. `gitnexus_query({query: "<error or symptom>"})` — find execution flows related to the issue
19+
2. `gitnexus_context({name: "<suspect function>"})` — see all callers, callees, and process participation
20+
3. `READ gitnexus://repo/meta-knowledge-graph-main/process/{processName}` — trace the full execution flow step by step
21+
4. For regressions: `gitnexus_detect_changes({scope: "compare", base_ref: "main"})` — see what your branch changed
22+
23+
## When Refactoring
24+
25+
- **Renaming**: MUST use `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` first. Review the preview — graph edits are safe, text_search edits need manual review. Then run with `dry_run: false`.
26+
- **Extracting/Splitting**: MUST run `gitnexus_context({name: "target"})` to see all incoming/outgoing refs, then `gitnexus_impact({target: "target", direction: "upstream"})` to find all external callers before moving code.
27+
- After any refactor: run `gitnexus_detect_changes({scope: "all"})` to verify only expected files changed.
28+
29+
## Never Do
30+
31+
- NEVER edit a function, class, or method without first running `gitnexus_impact` on it.
32+
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
33+
- NEVER rename symbols with find-and-replace — use `gitnexus_rename` which understands the call graph.
34+
- NEVER commit changes without running `gitnexus_detect_changes()` to check affected scope.
35+
36+
## Tools Quick Reference
37+
38+
| Tool | When to use | Command |
39+
|------|-------------|---------|
40+
| `query` | Find code by concept | `gitnexus_query({query: "auth validation"})` |
41+
| `context` | 360-degree view of one symbol | `gitnexus_context({name: "validateUser"})` |
42+
| `impact` | Blast radius before editing | `gitnexus_impact({target: "X", direction: "upstream"})` |
43+
| `detect_changes` | Pre-commit scope check | `gitnexus_detect_changes({scope: "staged"})` |
44+
| `rename` | Safe multi-file rename | `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` |
45+
| `cypher` | Custom graph queries | `gitnexus_cypher({query: "MATCH ..."})` |
46+
47+
## Impact Risk Levels
48+
49+
| Depth | Meaning | Action |
50+
|-------|---------|--------|
51+
| d=1 | WILL BREAK — direct callers/importers | MUST update these |
52+
| d=2 | LIKELY AFFECTED — indirect deps | Should test |
53+
| d=3 | MAY NEED TESTING — transitive | Test if critical path |
54+
55+
## Resources
56+
57+
| Resource | Use for |
58+
|----------|---------|
59+
| `gitnexus://repo/meta-knowledge-graph-main/context` | Codebase overview, check index freshness |
60+
| `gitnexus://repo/meta-knowledge-graph-main/clusters` | All functional areas |
61+
| `gitnexus://repo/meta-knowledge-graph-main/processes` | All execution flows |
62+
| `gitnexus://repo/meta-knowledge-graph-main/process/{name}` | Step-by-step execution trace |
63+
64+
## Self-Check Before Finishing
65+
66+
Before completing any code modification task, verify:
67+
1. `gitnexus_impact` was run for all modified symbols
68+
2. No HIGH/CRITICAL risk warnings were ignored
69+
3. `gitnexus_detect_changes()` confirms changes match expected scope
70+
4. All d=1 (WILL BREAK) dependents were updated
71+
72+
## Keeping the Index Fresh
73+
74+
After committing code changes, the GitNexus index becomes stale. Re-run analyze to update it:
75+
76+
```bash
77+
npx gitnexus analyze
78+
```
79+
80+
If the index previously included embeddings, preserve them by adding `--embeddings`:
81+
82+
```bash
83+
npx gitnexus analyze --embeddings
84+
```
85+
86+
To check whether embeddings exist, inspect `.gitnexus/meta.json` — the `stats.embeddings` field shows the count (0 means no embeddings). **Running analyze without `--embeddings` will delete any previously generated embeddings.**
87+
88+
> Claude Code users: A PostToolUse hook handles this automatically after `git commit` and `git merge`.
89+
90+
## CLI
91+
92+
| Task | Read this skill file |
93+
|------|---------------------|
94+
| Understand architecture / "How does X work?" | `.claude/skills/gitnexus/gitnexus-exploring/SKILL.md` |
95+
| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md` |
96+
| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus/gitnexus-debugging/SKILL.md` |
97+
| Rename / extract / split / refactor | `.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md` |
98+
| Tools, resources, schema reference | `.claude/skills/gitnexus/gitnexus-guide/SKILL.md` |
99+
| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus/gitnexus-cli/SKILL.md` |
100+
101+
<!-- gitnexus:end -->

CLAUDE.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!-- gitnexus:start -->
2+
# GitNexus — Code Intelligence
3+
4+
This project is indexed by GitNexus as **meta-knowledge-graph-main** (1781 symbols, 5293 relationships, 149 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
5+
6+
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
7+
8+
## Always Do
9+
10+
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `gitnexus_impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
11+
- **MUST run `gitnexus_detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows.
12+
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
13+
- When exploring unfamiliar code, use `gitnexus_query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
14+
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `gitnexus_context({name: "symbolName"})`.
15+
16+
## When Debugging
17+
18+
1. `gitnexus_query({query: "<error or symptom>"})` — find execution flows related to the issue
19+
2. `gitnexus_context({name: "<suspect function>"})` — see all callers, callees, and process participation
20+
3. `READ gitnexus://repo/meta-knowledge-graph-main/process/{processName}` — trace the full execution flow step by step
21+
4. For regressions: `gitnexus_detect_changes({scope: "compare", base_ref: "main"})` — see what your branch changed
22+
23+
## When Refactoring
24+
25+
- **Renaming**: MUST use `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` first. Review the preview — graph edits are safe, text_search edits need manual review. Then run with `dry_run: false`.
26+
- **Extracting/Splitting**: MUST run `gitnexus_context({name: "target"})` to see all incoming/outgoing refs, then `gitnexus_impact({target: "target", direction: "upstream"})` to find all external callers before moving code.
27+
- After any refactor: run `gitnexus_detect_changes({scope: "all"})` to verify only expected files changed.
28+
29+
## Never Do
30+
31+
- NEVER edit a function, class, or method without first running `gitnexus_impact` on it.
32+
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
33+
- NEVER rename symbols with find-and-replace — use `gitnexus_rename` which understands the call graph.
34+
- NEVER commit changes without running `gitnexus_detect_changes()` to check affected scope.
35+
36+
## Tools Quick Reference
37+
38+
| Tool | When to use | Command |
39+
|------|-------------|---------|
40+
| `query` | Find code by concept | `gitnexus_query({query: "auth validation"})` |
41+
| `context` | 360-degree view of one symbol | `gitnexus_context({name: "validateUser"})` |
42+
| `impact` | Blast radius before editing | `gitnexus_impact({target: "X", direction: "upstream"})` |
43+
| `detect_changes` | Pre-commit scope check | `gitnexus_detect_changes({scope: "staged"})` |
44+
| `rename` | Safe multi-file rename | `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` |
45+
| `cypher` | Custom graph queries | `gitnexus_cypher({query: "MATCH ..."})` |
46+
47+
## Impact Risk Levels
48+
49+
| Depth | Meaning | Action |
50+
|-------|---------|--------|
51+
| d=1 | WILL BREAK — direct callers/importers | MUST update these |
52+
| d=2 | LIKELY AFFECTED — indirect deps | Should test |
53+
| d=3 | MAY NEED TESTING — transitive | Test if critical path |
54+
55+
## Resources
56+
57+
| Resource | Use for |
58+
|----------|---------|
59+
| `gitnexus://repo/meta-knowledge-graph-main/context` | Codebase overview, check index freshness |
60+
| `gitnexus://repo/meta-knowledge-graph-main/clusters` | All functional areas |
61+
| `gitnexus://repo/meta-knowledge-graph-main/processes` | All execution flows |
62+
| `gitnexus://repo/meta-knowledge-graph-main/process/{name}` | Step-by-step execution trace |
63+
64+
## Self-Check Before Finishing
65+
66+
Before completing any code modification task, verify:
67+
1. `gitnexus_impact` was run for all modified symbols
68+
2. No HIGH/CRITICAL risk warnings were ignored
69+
3. `gitnexus_detect_changes()` confirms changes match expected scope
70+
4. All d=1 (WILL BREAK) dependents were updated
71+
72+
## Keeping the Index Fresh
73+
74+
After committing code changes, the GitNexus index becomes stale. Re-run analyze to update it:
75+
76+
```bash
77+
npx gitnexus analyze
78+
```
79+
80+
If the index previously included embeddings, preserve them by adding `--embeddings`:
81+
82+
```bash
83+
npx gitnexus analyze --embeddings
84+
```
85+
86+
To check whether embeddings exist, inspect `.gitnexus/meta.json` — the `stats.embeddings` field shows the count (0 means no embeddings). **Running analyze without `--embeddings` will delete any previously generated embeddings.**
87+
88+
> Claude Code users: A PostToolUse hook handles this automatically after `git commit` and `git merge`.
89+
90+
## CLI
91+
92+
| Task | Read this skill file |
93+
|------|---------------------|
94+
| Understand architecture / "How does X work?" | `.claude/skills/gitnexus/gitnexus-exploring/SKILL.md` |
95+
| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md` |
96+
| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus/gitnexus-debugging/SKILL.md` |
97+
| Rename / extract / split / refactor | `.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md` |
98+
| Tools, resources, schema reference | `.claude/skills/gitnexus/gitnexus-guide/SKILL.md` |
99+
| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus/gitnexus-cli/SKILL.md` |
100+
101+
<!-- gitnexus:end -->

backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Backend package
1+
# Backend package

backend/dependencies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
from pathlib import Path
7-
from typing import Optional
87

98
# 延迟导入避免循环依赖
109
_db_instance = None
@@ -83,4 +82,4 @@ def get_dedup_service():
8382
def get_research_service():
8483
"""获取 ResearchService 实例"""
8584
from .services.research_service import ResearchService
86-
return ResearchService(get_db(), get_s2_client())
85+
return ResearchService(get_db(), get_s2_client())

backend/routes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Routes package
1+
# Routes package

backend/routes/agent.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@
22
Agent API routes
33
"""
44

5-
from fastapi import APIRouter, HTTPException
6-
from fastapi.responses import StreamingResponse
7-
from typing import Dict, Any, Optional, List, AsyncGenerator
8-
from pydantic import BaseModel
9-
import sys
105
import json
11-
import asyncio
6+
import sys
127
import threading
138
import uuid
149
from pathlib import Path
1510

16-
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
11+
from fastapi import APIRouter, HTTPException
12+
from fastapi.responses import StreamingResponse
13+
from pydantic import BaseModel
1714

18-
from backend.schemas import AgentChatRequest, AgentChatResponse, AgentMessage
19-
from backend.dependencies import get_db, get_s2_client, get_pdf_parser
20-
from mkg.llm import init_llm_from_db, reset_llm
15+
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
2116

2217
# LangGraph imports
23-
from langchain_core.messages import HumanMessage, AIMessage
18+
from langchain_core.messages import AIMessage, HumanMessage
2419

20+
from backend.dependencies import get_db, get_pdf_parser, get_s2_client
21+
from backend.schemas import AgentChatRequest, AgentChatResponse
2522
from mkg.agent.graph import get_agent_graph, reset_graph
2623
from mkg.agent.state import AgentState
27-
from mkg.agent.tools import ALL_TOOLS
24+
from mkg.llm import init_llm_from_db, reset_llm
2825

2926
router = APIRouter(prefix="/api/agent", tags=["agent"])
3027

@@ -51,14 +48,14 @@ class DeepResearchStartRequest(BaseModel):
5148
targetType: str
5249
targetName: str
5350
query: str
54-
dimensions: Optional[List[str]] = None
51+
dimensions: list[str] | None = None
5552

5653

5754
class DeepResearchStatusResponse(BaseModel):
5855
status: str
5956
progress: int
60-
dimensions: List[str]
61-
completedDimensions: List[str]
57+
dimensions: list[str]
58+
completedDimensions: list[str]
6259

6360

6461
@router.post("/chat", response_model=AgentChatResponse)
@@ -137,8 +134,8 @@ def chat(request: AgentChatRequest):
137134
@router.post("/deep-research/start")
138135
def start_deep_research(request: DeepResearchStartRequest):
139136
"""启动深入研究任务(异步,后台运行)"""
140-
from mkg.agent.tools import deep_research
141137
from mkg.agent.research_graph import get_deep_research_progress
138+
from mkg.agent.tools import deep_research
142139

143140
# 生成唯一 session_id
144141
session_id = str(uuid.uuid4())[:12]
@@ -291,4 +288,4 @@ def reset_agent():
291288
"""重置 Agent 图(用于重新加载配置)"""
292289
reset_llm()
293290
reset_graph()
294-
return {"status": "ok"}
291+
return {"status": "ok"}

backend/routes/concepts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ def get_concept_papers(
4646
):
4747
"""获取概念关联的论文"""
4848
papers = service.get_papers(concept_id, limit)
49-
return {"concept_id": concept_id, "papers": papers, "total": len(papers)}
49+
return {"concept_id": concept_id, "papers": papers, "total": len(papers)}

backend/routes/concepts_research.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
研究路由 - 研究点发现和论文推荐相关端点
44
"""
55

6+
67
from fastapi import APIRouter, Depends, HTTPException
7-
from typing import Optional
88

99
from ..dependencies import get_research_service
1010
from ..services.research_service import ResearchService
@@ -15,8 +15,8 @@
1515
@router.get("/{concept_id}/search-papers")
1616
def search_papers_by_concept(
1717
concept_id: str,
18-
year: Optional[str] = None,
19-
min_citations: Optional[int] = None,
18+
year: str | None = None,
19+
min_citations: int | None = None,
2020
limit: int = 10,
2121
service: ResearchService = Depends(get_research_service)
2222
):
@@ -36,4 +36,4 @@ def discover_research_points(
3636
result = service.discover_research_points(concept_id)
3737
if "error" in result:
3838
raise HTTPException(status_code=400, detail=result["error"])
39-
return result
39+
return result

0 commit comments

Comments
 (0)