Factory: backlog column with queue buttons, status-tinted issue cards

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Sonnet 5.5 committed 2026-11-20 10:55:59 +01:00
1 parent 51a60ee75e
commit 25e4167f56
9 files changed
+318 -4

No files matched your search

+7
View File
@@ -3,6 +3,13 @@
All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/);
until 1.0, minor versions may contain breaking changes.
## [Unreleased]
### Added
- **Factory: backlog column.** All open issues of the configured repositories that are not in the factory yet appear in a new column on the far left. Each card has a *Queue* button (and the column *Queue all*, with a confirmation): the issue gets the factory label on the forge and the factory takes it up straight away. Issues whose author may not file factory issues are shown but cannot be queued. The list is read from the forge (cached for a minute) and follows the project dropdown.
- **Factory: cards are tinted by status** – a faint background and border colour per state (review, question, approved, build, acceptance, failed, done), taken from the theme's own colours.
## [v202611-00068] – 2026-11-20
### Added
+6
View File
@@ -332,6 +332,12 @@ phase the model, agent (CodeCraft or Claude Code), permission mode, timeout, tri
technical failures, the skills that are switched on for it, plus the number of rework rounds (default 2). Failed or rejected issues
can be restarted from the board, finished ones are closed with a comment.
**Backlog.** The first column of the board lists every open issue of the configured
repositories that is not in the factory yet. *Queue* gives an issue the factory label on the
forge (so it enters the review at once); *Queue all* does it for the whole list. Issues of authors
who are not allowed to file factory issues are shown but cannot be queued. Cards are tinted by
status.
**Files in the repository** (all optional, kept in `.factory/`):
| File | Purpose |
+88
View File
@@ -168,6 +168,8 @@ pub fn router(app: AppState) -> Router {
.route("/account/factory", get(get_factory).put(put_factory))
.route("/account/factory/test", post(test_factory))
.route("/factory/overview", get(factory_overview))
.route("/factory/backlog", get(factory_backlog))
.route("/factory/backlog/enqueue", post(factory_enqueue))
.route("/factory/poll", post(factory_poll))
.route("/factory/issues/restart", post(factory_restart))
.route("/factory/issue-chats", post(factory_new_issue_chat))
@@ -2754,6 +2756,92 @@ async fn factory_overview(Extension(user): Extension<User>, State(app): State<Ap
})))
}
/// Open issues per repository as the forge lists them; cached for a minute so that the board can ask often.
static BACKLOG_CACHE: std::sync::OnceLock<std::sync::Mutex<std::collections::HashMap<String, (std::time::Instant, Vec<Value>)>>> = std::sync::OnceLock::new();
#[derive(Deserialize)]
struct BacklogQuery {
#[serde(default)]
refresh: bool,
}
/// The backlog: open issues of the configured repositories that are not in the factory yet.
async fn factory_backlog(Extension(user): Extension<User>, State(app): State<AppState>, Query(q): Query<BacklogQuery>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let cache = BACKLOG_CACHE.get_or_init(Default::default);
let tracked_all = app.store.factory_issues(&user.id)?;
let (mut issues, mut errors) = (Vec::new(), Vec::new());
for cfg in s.repos.iter().filter(|r| r.enabled).map(|r| s.resolve(r)).filter(|r| !r.token.is_empty()) {
let key = format!("{}|{}", user.id, cfg.url);
let cached = cache.lock().unwrap().get(&key).filter(|(t, _)| !q.refresh && t.elapsed().as_secs() < 60).map(|(_, v)| v.clone());
let result = async {
let g = crate::factory::Forge::new(&cfg)?;
let open = match cached {
Some(v) => v,
None => {
let v = g.open_issues().await?;
cache.lock().unwrap().insert(key.clone(), (std::time::Instant::now(), v.clone()));
v
}
};
let allowed = crate::factory::allowed_authors(&g, &cfg).await?;
let tracked: Vec<i64> = tracked_all.iter().filter(|r| r["repo"].as_str() == Some(cfg.url.as_str())).map(|r| r["number"].as_i64().unwrap_or(0)).collect();
anyhow::Ok(crate::factory::backlog_of(&cfg, &open, &tracked, &allowed))
}
.await;
match result {
Ok(v) => issues.extend(v),
Err(e) => errors.push(format!("{}: {e:#}", cfg.url)),
}
}
Ok(Json(json!({"issues": issues, "errors": errors})))
}
#[derive(Deserialize)]
struct Enqueue {
repo: String,
numbers: Vec<i64>,
}
/// Put backlog issues into the process: give them the factory label, the next poll picks them up.
async fn factory_enqueue(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Json(b): Json<Enqueue>) -> ApiResult {
let cfg = factory_repo_cfg(&app, &user, &b.repo)?;
if b.numbers.is_empty() || b.numbers.len() > 100 {
return Err(ApiError(StatusCode::BAD_REQUEST, "1 to 100 issues".into()));
}
let bad = |e: anyhow::Error| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}"));
let g = crate::factory::Forge::new(&cfg).map_err(bad)?;
let allowed = crate::factory::allowed_authors(&g, &cfg).await.map_err(bad)?;
let open = g.open_issues().await.map_err(bad)?;
g.ensure_labels().await.map_err(bad)?;
let (mut queued, mut errors) = (Vec::new(), Vec::new());
for n in b.numbers {
let Some(issue) = open.iter().find(|i| crate::factory::issue_no(i) == n) else {
errors.push(json!({"number": n, "error": "not an open issue of this repository"}));
continue;
};
let author = issue["user"]["login"].as_str().unwrap_or("");
if !allowed.iter().any(|a| a.eq_ignore_ascii_case(author)) {
errors.push(json!({"number": n, "error": format!("the author {author} is not allowed to file factory issues (see the repository settings)")}));
continue;
}
match g.add_label(n as u64, &cfg.label).await {
Ok(()) => queued.push(n),
Err(e) => errors.push(json!({"number": n, "error": format!("{e:#}")})),
}
}
BACKLOG_CACHE.get_or_init(Default::default).lock().unwrap().remove(&format!("{}|{}", user.id, cfg.url));
app.audit(Some(&user), "factory.backlog.enqueue", &format!("{} {:?}", b.repo, queued), &crate::auth::client_ip(&headers));
// Take the issues up right away instead of waiting for the next poll.
if !queued.is_empty() {
let (app2, user2) = (app.clone(), user.clone());
tokio::spawn(async move {
let _ = crate::factory::poll_repo(&app2, &user2, &cfg).await;
});
}
Ok(Json(json!({"queued": queued, "errors": errors})))
}
/// Look for new issues right now instead of waiting for the next poll.
async fn factory_poll(Extension(user): Extension<User>, State(app): State<AppState>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
+89 -1
View File
@@ -556,6 +556,49 @@ impl Forge {
Ok(out)
}
/// All open issues (pull requests excluded), up to 200, in the shape of `issues()`.
pub async fn open_issues(&self) -> Result<Vec<Value>> {
let mut out = Vec::new();
for page in 1..=4 {
let url = match self.kind {
Kind::Gitea => self.rp(&format!("/issues?state=open&type=issues&limit=50&page={page}")),
Kind::Github => self.rp(&format!("/issues?state=open&per_page=50&page={page}")),
Kind::Gitlab => self.rp(&format!("/issues?state=opened&per_page=50&page={page}")),
};
let v = self.call(reqwest::Method::GET, url, None).await?;
let a = v.as_array().cloned().unwrap_or_default();
let n = a.len();
for i in a {
if !i.get("pull_request").map_or(true, |p| p.is_null()) {
continue;
}
out.push(if self.kind == Kind::Gitlab { norm_gitlab_issue(&i) } else { i });
}
if n < 50 {
break;
}
}
Ok(out)
}
/// Add one label to an issue without touching its other labels.
pub async fn add_label(&self, issue: u64, name: &str) -> Result<()> {
match self.kind {
Kind::Gitea => {
let all = self.label_names().await?;
let id = all.iter().find(|l| l["name"].as_str() == Some(name)).map(|l| l["id"].clone()).with_context(|| format!("label {name} does not exist"))?;
self.call(reqwest::Method::POST, self.rp(&format!("/issues/{issue}/labels")), Some(json!({"labels": [id]}))).await?;
}
Kind::Github => {
self.call(reqwest::Method::POST, self.rp(&format!("/issues/{issue}/labels")), Some(json!({"labels": [name]}))).await?;
}
Kind::Gitlab => {
self.call(reqwest::Method::PUT, self.rp(&format!("/issues/{issue}")), Some(json!({"add_labels": name}))).await?;
}
}
Ok(())
}
/// Is the issue still open on the forge?
pub async fn issue_is_open(&self, number: u64) -> Result<bool> {
let v = self.call(reqwest::Method::GET, self.rp(&format!("/issues/{number}")), None).await?;
@@ -738,7 +781,12 @@ impl Forge {
/// GitLab issue → {number, title, body, user.login, html_url}.
fn norm_gitlab_issue(i: &Value) -> Value {
json!({"number": i["iid"], "title": i["title"], "body": i["description"], "user": {"login": i["author"]["username"]}, "html_url": i["web_url"]})
json!({"number": i["iid"], "title": i["title"], "body": i["description"], "user": {"login": i["author"]["username"]}, "html_url": i["web_url"], "labels": i["labels"]})
}
/// Label names of an issue (Gitea/GitHub: objects with a name, GitLab: plain strings).
pub fn issue_labels(i: &Value) -> Vec<String> {
i["labels"].as_array().map(|a| a.iter().filter_map(|l| l["name"].as_str().or_else(|| l.as_str()).map(String::from)).collect()).unwrap_or_default()
}
fn urlenc(s: &str) -> String {
@@ -1396,6 +1444,33 @@ pub(crate) async fn alert(app: &App, repo: &str, n: i64, what: &str, detail: &st
}
/// One pass over a repository: take up new issues, restart reviews after answers.
/// Who may file issues for the factory: the configured users, by default the token's owner.
pub async fn allowed_authors(g: &Forge, cfg: &RepoCfg) -> Result<Vec<String>> {
let mut allowed = cfg.allowed_users.clone();
if allowed.is_empty() {
allowed.push(g.login().await?);
}
Ok(allowed)
}
/// Open issues of the forge that are not in the factory (yet): the backlog.
/// `open` is the forge's list of open issues, `tracked` the issue numbers the factory already knows.
pub fn backlog_of(cfg: &RepoCfg, open: &[Value], tracked: &[i64], allowed: &[String]) -> Vec<Value> {
open.iter()
.filter_map(|i| {
let n = issue_no(i);
let author = i["user"]["login"].as_str().unwrap_or("");
let ok = allowed.iter().any(|a| a.eq_ignore_ascii_case(author));
let labelled = issue_labels(i).iter().any(|l| l == &cfg.label);
// Labelled issues of allowed authors are taken up by the next poll anyway.
if n == 0 || tracked.contains(&n) || (labelled && ok) {
return None;
}
Some(json!({"repo": cfg.url, "number": n, "title": i["title"], "author": author, "url": i["html_url"], "allowed": ok, "labels": issue_labels(i)}))
})
.collect()
}
pub async fn poll_repo(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()> {
let g = Forge::new(cfg)?;
let mut allowed = cfg.allowed_users.clone();
@@ -1832,6 +1907,19 @@ pub async fn create_project(app: &Arc<App>, user: &User, settings: &mut FactoryS
mod tests {
use super::*;
#[test]
fn backlog_skips_tracked_and_queued_issues() {
let cfg = repo("https://git.example.org/o/r.git");
let issue = |n: i64, author: &str, labels: &[&str]| json!({"number": n, "title": format!("t{n}"), "user": {"login": author}, "html_url": "u", "labels": labels.iter().map(|l| json!({"name": l})).collect::<Vec<_>>()});
let open = vec![issue(1, "me", &[]), issue(2, "me", &[&cfg.label]), issue(3, "me", &["bug"]), issue(4, "stranger", &[&cfg.label]), issue(5, "me", &[])];
let b = backlog_of(&cfg, &open, &[5], &["ME".to_string()]);
let nums: Vec<i64> = b.iter().map(|i| i["number"].as_i64().unwrap()).collect();
// 2 is labelled by an allowed author (the poll takes it), 5 is tracked; 4 stays visible but not allowed.
assert_eq!(nums, vec![1, 3, 4]);
assert_eq!(b[2]["allowed"], false);
assert_eq!(issue_labels(&json!({"labels": ["a", {"name": "b"}]})), vec!["a", "b"]);
}
fn repo(url: &str) -> RepoCfg {
serde_json::from_value(json!({"url": url, "token": "tok"})).unwrap()
}
+66 -3
View File
@@ -79,6 +79,15 @@ interface Issue {
created_at: number;
updated_at: number;
}
interface BacklogIssue {
repo: string;
number: number;
title: string;
author: string;
url: string;
allowed: boolean;
labels: string[];
}
interface Run {
id: string;
repo: string;
@@ -188,10 +197,21 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
const [busy, setBusy] = useState(false);
const [recreate, setRecreate] = useState(false);
const reload = () =>
get<Overview>("/factory/overview")
const [backlog, setBacklog] = useState<BacklogIssue[]>([]);
const [backlogErrors, setBacklogErrors] = useState<string[]>([]);
const loadBacklog = (refresh = false) =>
get<{ issues: BacklogIssue[]; errors: string[] }>(`/factory/backlog${refresh ? "?refresh=1" : ""}`)
.then((r) => {
setBacklog(r.issues);
setBacklogErrors(r.errors);
})
.catch(() => {});
const reload = () => {
void loadBacklog();
return get<Overview>("/factory/overview")
.then(setData)
.catch((e) => toast(e.message));
};
useEffect(() => {
void reload();
const h = setInterval(() => {
@@ -263,6 +283,24 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
};
const issues = useMemo(() => (data?.issues ?? []).filter((i) => !repo || i.repo === repo), [data, repo]);
const backlogShown = useMemo(() => backlog.filter((i) => !repo || i.repo === repo), [backlog, repo]);
/** Put backlog issues into the process (they get the factory label on the forge). */
const enqueue = async (items: BacklogIssue[]) => {
if (items.length === 0) return;
if (items.length > 1 && !(await confirmDialog({ message: t("factory.backlog.allConfirm", { n: items.length }), confirmLabel: t("factory.backlog.queueAll") }))) return;
setBusy(true);
try {
for (const r of [...new Set(items.map((i) => i.repo))]) {
const res = await post<{ queued: number[]; errors: { number: number; error: string }[] }>("/factory/backlog/enqueue", { repo: r, numbers: items.filter((i) => i.repo === r).map((i) => i.number) });
for (const e of res.errors) toast(`#${e.number}: ${e.error}`);
}
} catch (e: any) {
toast(e.message);
}
setBusy(false);
await loadBacklog(true);
await reload();
};
const runs = useMemo(() => (data?.runs ?? []).filter((r) => !repo || r.repo === repo), [data, repo]);
const selected = issues.find((i) => `${i.repo}#${i.number}` === sel);
const [pr, setPr] = useState<PrInfo | null>(null);
@@ -462,6 +500,31 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
</div>
<div className="factory-board">
<div className="factory-col backlog">
<h4>
{t("factory.col.backlog")} <span className="chip">{backlogShown.length}</span>
</h4>
{backlogShown.length > 1 && (
<button className="small" onClick={() => void enqueue(backlogShown.filter((i) => i.allowed))} disabled={busy || !backlogShown.some((i) => i.allowed)} title={t("factory.backlog.queueAllHint")}>
<Icon name="plus" /> {t("factory.backlog.queueAll")}
</button>
)}
{backlogShown.map((i) => (
<div key={`${i.repo}#${i.number}`} className="factory-card backlog">
<span className="hint">
{repoName(i.repo)} #{i.number} · {i.author}
</span>
<a href={i.url || issueUrl(i.repo, i.number)} target="_blank" rel="noreferrer">
<b>{i.title || `#${i.number}`}</b>
</a>
<button className="small" onClick={() => void enqueue([i])} disabled={busy || !i.allowed} title={i.allowed ? t("factory.backlog.queueHint") : t("factory.backlog.notAllowed", { user: i.author })}>
<Icon name="plus" /> {t("factory.backlog.queue")}
</button>
</div>
))}
{backlogShown.length === 0 && <span className="hint">{t("factory.backlog.empty")}</span>}
{backlogErrors.length > 0 && <span className="hint" title={backlogErrors.join("\n")}>{t("factory.backlog.error")}</span>}
</div>
{COLUMNS.map((c) => {
const cards = issues.filter((i) => c.states.includes(i.state));
return (
@@ -475,7 +538,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
const latest = active ?? rs[0];
const tokens = rs.reduce((a, r) => a + r.input_tokens + r.output_tokens, 0);
return (
<button key={`${i.repo}#${i.number}`} className={`factory-card ${sel === `${i.repo}#${i.number}` ? "active" : ""} ${active ? "running" : ""}`} onClick={() => setSel(sel === `${i.repo}#${i.number}` ? "" : `${i.repo}#${i.number}`)}>
<button key={`${i.repo}#${i.number}`} data-state={i.state} className={`factory-card ${sel === `${i.repo}#${i.number}` ? "active" : ""} ${active ? "running" : ""}`} onClick={() => setSel(sel === `${i.repo}#${i.number}` ? "" : `${i.repo}#${i.number}`)}>
<span className="hint">
{repoName(i.repo)} #{i.number}
</span>
+9
View File
@@ -1226,6 +1226,15 @@ export const de: Messages = {
"factory.repoLine": "{n} Issues · {run} laufen",
"factory.noToken": "kein Token",
"factory.pollNow": "Jetzt prüfen",
"factory.backlog.queue": "Einreihen",
"factory.backlog.queueAll": "Alle einreihen",
"factory.backlog.queueHint": "Dem Issue das Factory-Label geben, damit es in den Prozess kommt",
"factory.backlog.queueAllHint": "Alle Issues dieser Liste einreihen",
"factory.backlog.allConfirm": "{n} Issues einreihen? Sie bekommen das Factory-Label im Forge und werden nacheinander geprüft.",
"factory.backlog.notAllowed": "{user} darf keine Factory-Issues anlegen (Repository-Einstellungen → erlaubte Nutzer)",
"factory.backlog.empty": "Keine offenen Issues außerhalb der Factory",
"factory.backlog.error": "Der Forge konnte für einige Projekte nicht gelesen werden",
"factory.col.backlog": "Backlog",
"factory.col.review": "Prüfung",
"factory.col.question": "Rückfragen",
"factory.col.approved": "Freigegeben",
+9
View File
@@ -1225,6 +1225,15 @@ export const en = {
"factory.repoLine": "{n} issues · {run} running",
"factory.noToken": "no token",
"factory.pollNow": "Check now",
"factory.backlog.queue": "Queue",
"factory.backlog.queueAll": "Queue all",
"factory.backlog.queueHint": "Give the issue the factory label so that it enters the process",
"factory.backlog.queueAllHint": "Queue all issues of this list",
"factory.backlog.allConfirm": "Queue {n} issues? They get the factory label on the forge and are reviewed one after another.",
"factory.backlog.notAllowed": "{user} is not allowed to file factory issues (repository settings → allowed users)",
"factory.backlog.empty": "No open issues outside the factory",
"factory.backlog.error": "The forge could not be read for some projects",
"factory.col.backlog": "Backlog",
"factory.col.review": "Review",
"factory.col.question": "Questions",
"factory.col.approved": "Approved",
+40
View File
@@ -5107,6 +5107,46 @@ td.fold-indent {
border-radius: 8px;
padding: 8px 10px;
}
/* A faint tint by status, also on the border; --tone is set per state. */
.factory-card[data-state] {
--tone: var(--muted);
border-color: color-mix(in srgb, var(--tone) 50%, var(--bg2));
background: color-mix(in srgb, var(--tone) 7%, var(--bg0));
}
.factory-card[data-state="new"],
.factory-card[data-state="review"] {
--tone: var(--aqua);
}
.factory-card[data-state="question"] {
--tone: var(--accent);
}
.factory-card[data-state="approved"] {
--tone: var(--blue);
}
.factory-card[data-state="building"],
.factory-card[data-state="rework"] {
--tone: var(--purple);
}
.factory-card[data-state="qa"],
.factory-card[data-state="testing"] {
--tone: var(--accent2);
}
.factory-card[data-state="failed"],
.factory-card[data-state="rejected"] {
--tone: var(--red);
}
.factory-card[data-state="done"] {
--tone: var(--green);
}
.factory-card.backlog {
gap: 4px;
border-style: dashed;
color: inherit;
}
.factory-card.backlog a {
color: inherit;
text-decoration: none;
}
.factory-card.active {
border-color: var(--accent);
}
+4
View File
@@ -3,6 +3,10 @@
* under "unreleased"; scripts/release.sh renames the key to the release version.
*/
export const WHATS_NEW: Record<string, { en: string[]; de: string[] }> = {
unreleased: {
en: ["Factory: backlog column with all open issues of the forge – queue them into the process with one click", "Factory: issue cards are faintly tinted by status, including the border"],
de: ["Factory: Backlog-Spalte mit allen offenen Issues des Forges – mit einem Klick in den Prozess einreihen", "Factory: Issue-Karten sind dezent nach Status eingefärbt, auch der Rahmen"],
},
"202611-00068": {
en: ["Test runner: \"isolated\": false in .factory/setup.json for apps that cannot run in a container"],
de: ["Test-Runner: \"isolated\": false in .factory/setup.json für Apps, die nicht im Container laufen können"],