Skip to content

Commit 819131e

Browse files
committed
feat: 完成阶段八 Agent 入口集成(review_agent + dry_run + config)
1 parent 108bf55 commit 819131e

3 files changed

Lines changed: 796 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
2+
#
3+
# Copyright (C) 2026 Tencent. All rights reserved.
4+
#
5+
# tRPC-Agent-Python is licensed under Apache-2.0.
6+
"""Configuration management for the code review agent.
7+
8+
Provides a centralized configuration object that can be loaded from
9+
CLI arguments, environment variables, or a config file.
10+
"""
11+
12+
from __future__ import annotations
13+
14+
import os
15+
from dataclasses import dataclass, field
16+
from typing import Optional
17+
18+
19+
@dataclass
20+
class ReviewAgentConfig:
21+
"""Central configuration for the code review agent.
22+
23+
Attributes:
24+
input_source: One of "diff_file", "repo_path", "fixture".
25+
input_value: The value for the input source (path or name).
26+
output_dir: Directory for output reports.
27+
db_path: Path to SQLite database file.
28+
sandbox_type: "local", "container", or "cube".
29+
sandbox_timeout: Sandbox execution timeout in seconds.
30+
sandbox_max_output: Max output size in bytes.
31+
sandbox_image: Docker image for container sandbox.
32+
dry_run: If True, skip sandbox execution and LLM calls.
33+
fake_model: If True, use simulated LLM results.
34+
disable_filters: If True, skip all filter checks.
35+
model_name: LLM model name (for future use).
36+
api_key: API key (for future use, falls back to env var).
37+
base_url: API base URL (for future use, falls back to env var).
38+
block_all_network: If True, deny all network access in sandbox.
39+
max_executions: Maximum script executions per review.
40+
max_total_time_ms: Maximum total sandbox time in ms.
41+
list_fixtures: If True, list available fixtures and exit.
42+
fixtures_dir: Path to fixtures directory.
43+
"""
44+
45+
# Input
46+
input_source: str = ""
47+
input_value: str = ""
48+
49+
# Output
50+
output_dir: str = "."
51+
output_json: Optional[str] = None
52+
output_md: Optional[str] = None
53+
54+
# Database
55+
db_path: str = "review.db"
56+
57+
# Sandbox
58+
sandbox_type: str = "local"
59+
sandbox_timeout: int = 30
60+
sandbox_max_output: int = 1_048_576
61+
sandbox_image: str = "python:3.12-slim"
62+
63+
# Execution mode
64+
dry_run: bool = False
65+
fake_model: bool = False
66+
67+
# Filter
68+
disable_filters: bool = False
69+
block_all_network: bool = True
70+
max_executions: int = 10
71+
max_total_time_ms: float = 60_000.0
72+
73+
# Model (for future LLM mode)
74+
model_name: Optional[str] = None
75+
api_key: Optional[str] = None
76+
base_url: Optional[str] = None
77+
78+
# Fixtures
79+
list_fixtures: bool = False
80+
fixtures_dir: Optional[str] = None
81+
82+
@classmethod
83+
def from_args(cls, args) -> ReviewAgentConfig:
84+
"""Build config from parsed CLI arguments."""
85+
# Determine input source
86+
if args.diff_file:
87+
input_source = "diff_file"
88+
input_value = args.diff_file
89+
elif args.repo_path:
90+
input_source = "repo_path"
91+
input_value = args.repo_path
92+
elif args.fixture:
93+
input_source = "fixture"
94+
input_value = args.fixture
95+
else:
96+
input_source = ""
97+
input_value = ""
98+
99+
# Resolve API key from env if not provided
100+
api_key = args.api_key or os.getenv("TRPC_AGENT_API_KEY", "")
101+
base_url = args.base_url or os.getenv("TRPC_AGENT_BASE_URL", "")
102+
103+
return cls(
104+
input_source=input_source,
105+
input_value=input_value,
106+
output_dir=args.output_dir,
107+
output_json=args.output_json,
108+
output_md=args.output_md,
109+
db_path=args.db_path,
110+
sandbox_type=args.sandbox,
111+
sandbox_timeout=args.sandbox_timeout,
112+
dry_run=args.dry_run,
113+
fake_model=args.fake_model,
114+
disable_filters=args.disable_filters,
115+
model_name=args.model,
116+
api_key=api_key or None,
117+
base_url=base_url or None,
118+
list_fixtures=args.list_fixtures,
119+
)
120+
121+
@property
122+
def is_fake_mode(self) -> bool:
123+
"""True if running in dry-run or fake-model mode."""
124+
return self.dry_run or self.fake_model

0 commit comments

Comments
 (0)