完成:aide/022 - 开始任务准备: 调整 aide 体系的 finish 清理、提交信息和 decide 界面
This commit is contained in:
@@ -65,10 +65,39 @@ class DecideHandlers:
|
||||
if pending is None:
|
||||
return self._server_error("无法读取待定项数据", "文件不存在或格式错误")
|
||||
|
||||
body = json.dumps(pending.to_dict(include_meta=False), ensure_ascii=False).encode("utf-8")
|
||||
# 转换为字典并为每个 item 添加 source_content
|
||||
data = pending.to_dict(include_meta=False)
|
||||
for item in data.get("items", []):
|
||||
location = item.get("location")
|
||||
if location and location.get("file"):
|
||||
source_content = self._read_source_lines(
|
||||
location["file"],
|
||||
location.get("start", 1),
|
||||
location.get("end", 1)
|
||||
)
|
||||
if source_content:
|
||||
item["source_content"] = source_content
|
||||
|
||||
body = json.dumps(data, ensure_ascii=False).encode("utf-8")
|
||||
headers = self._cors_headers({"Content-Type": "application/json; charset=utf-8"})
|
||||
return 200, headers, body
|
||||
|
||||
def _read_source_lines(self, file_path: str, start: int, end: int) -> str | None:
|
||||
"""读取源文件指定行范围的内容"""
|
||||
try:
|
||||
# 相对路径基于项目根目录
|
||||
full_path = Path(self.storage.root) / file_path
|
||||
if not full_path.exists():
|
||||
return None
|
||||
lines = full_path.read_text(encoding="utf-8").splitlines()
|
||||
# 转换为 0-indexed
|
||||
start_idx = max(0, start - 1)
|
||||
end_idx = min(len(lines), end)
|
||||
selected = lines[start_idx:end_idx]
|
||||
return "\n".join(selected)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def handle_submit(self, body: bytes) -> Response:
|
||||
try:
|
||||
pending = self.storage.load_pending()
|
||||
|
||||
@@ -88,10 +88,22 @@ function renderItemCard(item) {
|
||||
}
|
||||
|
||||
if (item.location && item.location.file) {
|
||||
const location = document.createElement("div");
|
||||
location.className = "item-location";
|
||||
location.textContent = `位置: ${item.location.file}:${item.location.start}-${item.location.end}`;
|
||||
card.appendChild(location);
|
||||
const locationWrap = document.createElement("div");
|
||||
locationWrap.className = "item-location";
|
||||
|
||||
const locationLabel = document.createElement("div");
|
||||
locationLabel.className = "location-label";
|
||||
locationLabel.textContent = `来源: ${item.location.file} (行 ${item.location.start}-${item.location.end})`;
|
||||
locationWrap.appendChild(locationLabel);
|
||||
|
||||
if (item.source_content) {
|
||||
const sourceContent = document.createElement("pre");
|
||||
sourceContent.className = "source-content";
|
||||
sourceContent.textContent = item.source_content;
|
||||
locationWrap.appendChild(sourceContent);
|
||||
}
|
||||
|
||||
card.appendChild(locationWrap);
|
||||
}
|
||||
|
||||
const options = renderOptions(item);
|
||||
|
||||
@@ -130,6 +130,26 @@ body {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.location-label {
|
||||
font-size: var(--font-size-sm);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.source-content {
|
||||
background: var(--color-background);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: var(--spacing-sm);
|
||||
margin: var(--spacing-xs) 0 0 0;
|
||||
font-family: "SF Mono", Monaco, Consolas, monospace;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.options-list {
|
||||
margin-top: var(--spacing-md);
|
||||
display: grid;
|
||||
|
||||
Reference in New Issue
Block a user