Factory: show and merge pull requests, issue chats (plan features, cut milestones)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a0a4082383
commit
56c20d92f8
10 files changed
+673
-3
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { DraftBar, isDraftChat } from "./FactoryDraft";
|
||||
import { DraftBar, IssueBar, isDraftChat, isIssueChat } from "./FactoryDraft";
|
||||
import { takePrefill } from "../share";
|
||||
import { Icon } from "./Icon";
|
||||
import { FileChip, FileFigure, fileType, imageSize, imageSrc } from "./FileFigure";
|
||||
@@ -1091,6 +1091,7 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
|
||||
{sharing && <ShareDialog sessionId={sessionId} onClose={() => setSharing(false)} />}
|
||||
{rewinding && <RewindDialog sessionId={sessionId} messageId={rewinding.id} onDone={rewindDone} onClose={() => setRewinding(undefined)} />}
|
||||
{!readOnly && isDraftChat(session.cwd) && <DraftBar sessionId={sessionId} />}
|
||||
{!readOnly && isIssueChat(session.cwd) && <IssueBar sessionId={sessionId} />}
|
||||
{!readOnly && <OutboxBar sessionId={sessionId} />}
|
||||
{!readOnly && <QueueList sessionId={sessionId} busy={busy} />}
|
||||
{readOnly ? (
|
||||
|
||||
@@ -2,11 +2,23 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { get, post, put } from "../api";
|
||||
import { fmtCompact, fmtCost, fmtRelative, useT } from "../i18n";
|
||||
import { navigate } from "../router";
|
||||
import { confirmDialog, toast } from "../dialogs";
|
||||
import { choiceDialog, confirmDialog, promptDialog, toast } from "../dialogs";
|
||||
import { Icon } from "./Icon";
|
||||
import { Spinner } from "./Activity";
|
||||
import { ModelSelect } from "./ModelSelect";
|
||||
|
||||
interface PrInfo {
|
||||
number: number;
|
||||
html_url: string;
|
||||
title: string;
|
||||
state: "open" | "merged" | "closed";
|
||||
mergeable: boolean | null;
|
||||
changed_files: number | null;
|
||||
additions: number | null;
|
||||
deletions: number | null;
|
||||
head: string;
|
||||
}
|
||||
|
||||
type Phase = "review" | "build" | "qa";
|
||||
const PHASES: Phase[] = ["review", "build", "qa"];
|
||||
|
||||
@@ -180,6 +192,35 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
}
|
||||
};
|
||||
|
||||
/** Start a chat that works out a feature or cuts a milestone into issues. */
|
||||
const issueChat = async (mode: "feature" | "slice") => {
|
||||
if (!data) return;
|
||||
let target = repo;
|
||||
if (!target) {
|
||||
const repos = data.repos.filter((r) => r.enabled);
|
||||
if (repos.length === 1) target = repos[0].url;
|
||||
else {
|
||||
const pick = await choiceDialog({ message: t("issues.pickRepo"), choices: repos.map((r) => ({ value: r.url, label: repoName(r.url) })) });
|
||||
if (!pick) return;
|
||||
target = pick;
|
||||
}
|
||||
}
|
||||
let topic = "";
|
||||
if (mode === "slice") {
|
||||
const name = await promptDialog({ message: t("issues.sliceWhich"), placeholder: "M2", confirmLabel: t("issues.sliceGo") });
|
||||
if (!name?.trim()) return;
|
||||
topic = name.trim();
|
||||
}
|
||||
setBusy(true);
|
||||
try {
|
||||
const s = await post<{ id: string }>("/factory/issue-chats", { repo: target, mode, topic });
|
||||
navigate(`/s/${s.id}`);
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const issues = useMemo(() => (data?.issues ?? []).filter((i) => !repo || i.repo === repo), [data, repo]);
|
||||
const runs = useMemo(() => (data?.runs ?? []).filter((r) => !repo || r.repo === repo), [data, repo]);
|
||||
if (!data) return <div className="empty"><Spinner /></div>;
|
||||
@@ -231,6 +272,37 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const [pr, setPr] = useState<PrInfo | null>(null);
|
||||
const [prMethod, setPrMethod] = useState("merge");
|
||||
const selKey = selected ? `${selected.repo}#${selected.number}` : "";
|
||||
const loadPr = async () => {
|
||||
if (!selected || (!selected.branch && !selected.pr_url)) return setPr(null);
|
||||
try {
|
||||
const r = await get<{ pr: PrInfo | null }>(`/factory/issues/pr?repo=${encodeURIComponent(selected.repo)}&number=${selected.number}`);
|
||||
setPr(r.pr);
|
||||
} catch {
|
||||
setPr(null);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
setPr(null);
|
||||
void loadPr();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selKey, selected?.state]);
|
||||
const mergePr = async () => {
|
||||
if (!selected || !pr) return;
|
||||
if (!(await confirmDialog({ message: t("factory.mergeConfirm", { n: pr.number, method: t(`factory.merge.${prMethod}` as any) }) }))) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await post("/factory/issues/pr/merge", { repo: selected.repo, number: selected.number, pr: pr.number, method: prMethod });
|
||||
toast(t("factory.merged"));
|
||||
await loadPr();
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const phaseRunning = !!selected && ["review", "building", "testing"].includes(selected.state);
|
||||
|
||||
return (
|
||||
@@ -289,6 +361,12 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
<button className="small primary" onClick={newProject} disabled={busy}>
|
||||
<Icon name="plus" /> {t("factory.newProject")}
|
||||
</button>
|
||||
<button className="small" onClick={() => issueChat("feature")} disabled={busy} title={t("issues.featureHint")}>
|
||||
<Icon name="sparkle" /> {t("issues.feature")}
|
||||
</button>
|
||||
<button className="small" onClick={() => issueChat("slice")} disabled={busy} title={t("issues.sliceHint")}>
|
||||
<Icon name="sparkle" /> {t("issues.slice")}
|
||||
</button>
|
||||
<button className="small" onClick={poll} disabled={busy} title={t("factory.pollNow")}>
|
||||
<Icon name="refresh" /> {t("factory.pollNow")}
|
||||
</button>
|
||||
@@ -360,6 +438,36 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
|
||||
)}
|
||||
</div>
|
||||
{selected?.note && <div className="hint" style={{ margin: "6px 0" }}>{selected.note}</div>}
|
||||
{pr && (
|
||||
<div className="factory-pr">
|
||||
<a href={pr.html_url} target="_blank" rel="noreferrer">
|
||||
<Icon name="external" /> #{pr.number} {pr.title}
|
||||
</a>
|
||||
<span className={`chip ${pr.state === "merged" ? "ok" : pr.state === "open" ? "" : "warn"}`}>{t(`factory.pr.${pr.state}` as any)}</span>
|
||||
{pr.state === "open" && pr.mergeable === false && <span className="chip warn">{t("factory.pr.conflict")}</span>}
|
||||
{pr.changed_files != null && (
|
||||
<span className="hint">
|
||||
{t("factory.pr.files", { n: pr.changed_files })}
|
||||
{pr.additions != null && ` · +${pr.additions} −${pr.deletions ?? 0}`}
|
||||
</span>
|
||||
)}
|
||||
<span className="spacer" />
|
||||
{pr.state === "open" && (
|
||||
<>
|
||||
<select value={prMethod} onChange={(e) => setPrMethod(e.target.value)} disabled={busy}>
|
||||
{["merge", "squash", "rebase"].map((m) => (
|
||||
<option key={m} value={m}>
|
||||
{t(`factory.merge.${m}` as any)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button className="small primary" onClick={mergePr} disabled={busy || pr.mergeable === false}>
|
||||
{t("factory.mergeBtn")}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{shown.length === 0 && <div className="hint">{t("factory.noRuns")}</div>}
|
||||
{shown.length > 0 && (
|
||||
<div className="table-wrap">
|
||||
|
||||
@@ -183,3 +183,132 @@ function CreateProjectDialog({ sessionId, onClose }: { sessionId: string; onClos
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const isIssueChat = (cwd: string) => /\/_issues\/[^/]+$/.test(cwd);
|
||||
|
||||
interface ProposedIssue {
|
||||
title: string;
|
||||
description: string;
|
||||
scope: string;
|
||||
depends: string;
|
||||
}
|
||||
interface IssueProposal {
|
||||
repo: string;
|
||||
proposal: { spec?: string; issues: ProposedIssue[] } | null;
|
||||
}
|
||||
|
||||
/** Bar above the composer of an issue chat: file the proposed issues on the forge. */
|
||||
export function IssueBar({ sessionId }: { sessionId: string }) {
|
||||
const t = useT();
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<div className="draft-bar">
|
||||
<Icon name="scroll" />
|
||||
<span>{t("issues.hint")}</span>
|
||||
<span className="spacer" />
|
||||
<button className="small primary" onClick={() => setOpen(true)}>
|
||||
<Icon name="check" /> {t("issues.create")}
|
||||
</button>
|
||||
</div>
|
||||
{open && <CreateIssuesDialog sessionId={sessionId} onClose={() => setOpen(false)} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateIssuesDialog({ sessionId, onClose }: { sessionId: string; onClose: () => void }) {
|
||||
const t = useT();
|
||||
const [data, setData] = useState<IssueProposal>();
|
||||
const [items, setItems] = useState<(ProposedIssue & { on: boolean })[]>([]);
|
||||
const [spec, setSpec] = useState("");
|
||||
const [start, setStart] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
get<IssueProposal>(`/factory/issue-chats/${sessionId}`)
|
||||
.then((d) => {
|
||||
setData(d);
|
||||
setSpec(d.proposal?.spec ?? "");
|
||||
setItems((d.proposal?.issues ?? []).map((i) => ({ title: i.title ?? "", description: i.description ?? "", scope: i.scope ?? "", depends: i.depends ?? "", on: true })));
|
||||
})
|
||||
.catch((e) => {
|
||||
toast(e.message);
|
||||
onClose();
|
||||
});
|
||||
}, [sessionId]);
|
||||
|
||||
if (!data)
|
||||
return (
|
||||
<div className="modal-backdrop">
|
||||
<div className="modal">
|
||||
<Spinner />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const chosen = items.filter((i) => i.on && i.title.trim());
|
||||
const set = (k: number, patch: Partial<ProposedIssue & { on: boolean }>) => setItems(items.map((x, j) => (j === k ? { ...x, ...patch } : x)));
|
||||
const create = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
const r = await post<{ created: { number: number }[] }>(`/factory/issue-chats/${sessionId}/create`, {
|
||||
spec,
|
||||
start,
|
||||
issues: chosen.map(({ on, ...i }) => i),
|
||||
});
|
||||
toast(t("issues.created", { n: r.created.length }), "success");
|
||||
onClose();
|
||||
navigate("/factory");
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="modal-backdrop" onClick={busy ? undefined : onClose}>
|
||||
<div className="modal draft-modal" role="dialog" aria-label={t("issues.create")} onClick={(e) => e.stopPropagation()}>
|
||||
<h3>{t("issues.create")}</h3>
|
||||
{!data.proposal ? (
|
||||
<div className="notice err">{t("issues.noProposal")}</div>
|
||||
) : (
|
||||
<>
|
||||
<label className="factory-form" style={{ display: "block" }}>
|
||||
<span>{t("issues.spec")}</span>
|
||||
<input className="mono" value={spec} onChange={(e) => setSpec(e.target.value)} />
|
||||
</label>
|
||||
<div className="issue-list">
|
||||
{items.map((i, k) => (
|
||||
<div key={k} className="issue-item">
|
||||
<label className="row" style={{ gap: 8 }}>
|
||||
<input type="checkbox" checked={i.on} onChange={(e) => set(k, { on: e.target.checked })} />
|
||||
<input style={{ flex: 1 }} value={i.title} onChange={(e) => set(k, { title: e.target.value })} />
|
||||
</label>
|
||||
<div className="hint">{i.scope}</div>
|
||||
{i.depends && i.depends.toLowerCase() !== "none" && <div className="hint">{t("issues.depends", { d: i.depends })}</div>}
|
||||
<details>
|
||||
<summary>{t("issues.description")}</summary>
|
||||
<textarea rows={4} value={i.description} onChange={(e) => set(k, { description: e.target.value })} />
|
||||
</details>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<label className="row" style={{ gap: 8, marginTop: 8 }}>
|
||||
<input type="checkbox" checked={start} onChange={(e) => setStart(e.target.checked)} />
|
||||
<span>{t("issues.start")}</span>
|
||||
</label>
|
||||
<div className="hint">{t("issues.startHint")}</div>
|
||||
</>
|
||||
)}
|
||||
<div className="row" style={{ justifyContent: "flex-end", gap: 8, marginTop: 12 }}>
|
||||
<button onClick={onClose} disabled={busy}>
|
||||
{t("common.cancel")}
|
||||
</button>
|
||||
<button className="primary" onClick={create} disabled={!data.proposal || chosen.length === 0 || !spec.trim() || busy}>
|
||||
{busy ? <Spinner small /> : <Icon name="check" />} {t("issues.createGo", { n: chosen.length })}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user