完成:aide/022 - 开始任务准备: 调整 aide 体系的 finish 清理、提交信息和 decide 界面

This commit is contained in:
2025-12-19 04:50:05 +08:00
parent af40327146
commit 3313dc1fb8
11 changed files with 252 additions and 36 deletions

View File

@@ -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()

View File

@@ -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);

View File

@@ -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;

View File

@@ -620,11 +620,10 @@ class BranchManager:
# 8. 创建收尾提交
self.git.add_all()
short_hash = start_commit[:7] if start_commit else "unknown"
if is_force_clean:
commit_msg = f"{short_hash}的强制清理"
commit_msg = f"任务中断,清理:{task_branch} - {branch_info.task_summary}"
else:
commit_msg = f"{short_hash}的任务收尾"
commit_msg = f"完成:{task_branch} - {branch_info.task_summary}"
self.git.commit(commit_msg)
return True, f"任务分支已合并到 {source_branch}"