Initial import of streamline

This commit is contained in:
2026-11-16 17:26:44 -08:00
commit 8e4aec1855
1221 changed files with 274256 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
// 「接力」:把本地 coding agent 的调研总结交给 Streamline 从头修。服务端的说明见 control-server/src/agent_handoff.ts。
//
// 总结是一份按固定小节写的 Markdown(模板在 skill/SKILL.md)。这里把它拆成三块:
// 现象 → description(提交人看到了什么);复现步骤 → reproSteps;其余小节 → notes(线索,服务端加说明后进 remark)。
import { execFileSync } from "node:child_process";
import { CliError } from "./http.js";
const SECTION_ALIASES = {
symptom: ["现象", "问题现象", "symptom", "symptoms"],
repro: ["复现步骤", "复现", "repro", "repro steps", "steps to reproduce"],
facts: ["已确认的事实", "事实", "已确认事实", "facts", "confirmed facts"],
suspects: ["怀疑点", "疑点", "可能原因", "suspects", "hypotheses"],
ruledOut: ["已排除", "排除", "ruled out"],
fix: ["建议修法", "修复建议", "suggested fix"],
};
function kindOf(heading) {
const h = heading.replace(/[((][^))]*[))]/g, "").trim().toLowerCase();
for (const [kind, names] of Object.entries(SECTION_ALIASES)) if (names.includes(h)) return kind;
return "other";
}
export function parseHandoff(markdown) {
const sections = [];
let current = null;
for (const line of markdown.split(/\r?\n/)) {
const m = line.match(/^##\s+(.+?)\s*$/);
if (m) {
current = { heading: m[1], kind: kindOf(m[1]), body: [] };
sections.push(current);
} else if (current) {
current.body.push(line);
}
}
const text = (s) => s.body.join("\n").trim();
const pick = (kind) => sections.filter((s) => s.kind === kind).map(text).filter(Boolean).join("\n\n");
const description = pick("symptom");
const reproSteps = pick("repro");
if (!description) throw new CliError("总结里缺少「## 现象」小节", "按 Skill 里的模板写:现象、复现步骤、已确认的事实、怀疑点、已排除");
const rest = sections.filter((s) => s.kind !== "symptom" && s.kind !== "repro" && text(s));
if (!rest.some((s) => s.kind === "facts" || s.kind === "suspects"))
throw new CliError("总结里至少要有「## 已确认的事实」或「## 怀疑点」之一", "没有调研结论的话直接用 streamline task create");
const notes = rest.map((s) => `## ${s.heading}\n\n${text(s)}`).join("\n\n");
return { description, reproSteps: reproSteps || null, notes };
}
function git(args, cwd) {
try {
return execFileSync("git", args, { cwd, encoding: "utf8", timeout: 2000, stdio: ["ignore", "pipe", "ignore"] }).trim() || null;
} catch { return null; }
}
/** 调研时的代码版本:仓库、分支、提交。远端地址里的用户名口令一律去掉。不在 git 仓库里就全空。 */
export function gitContext(cwd = process.cwd()) {
const remote = git(["remote", "get-url", "origin"], cwd);
return {
repo: remote ? remote.replace(/\/\/[^@/]+@/, "//") : null,
branch: git(["rev-parse", "--abbrev-ref", "HEAD"], cwd),
commit: git(["rev-parse", "HEAD"], cwd),
};
}