Drafts in every chat, factory chat overlay, factory main switch

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Sonnet 5.5 committed 2026-11-20 12:14:04 +01:00
1 parent 58475ce65e
commit 171b87b766
48 files changed
+754 -10

No files matched your search

+35 -3
View File
@@ -17,6 +17,28 @@ pub const FACTORY_FOLDER: &str = "Factory";
pub const PHASES: [&str; 3] = ["review", "build", "qa"];
/// The master switch of a user's factory. Switched off, no new agent starts (a soft stop: agents that
/// are running finish their phase); the poller still keeps the board up to date.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Power {
pub on: bool,
}
impl Default for Power {
fn default() -> Self {
Self { on: true }
}
}
/// "running" (on), "stopping" (off, agents still working) or "stopped" (off, nobody working).
pub fn power_state(on: bool, active: i64) -> &'static str {
match (on, active) {
(true, _) => "running",
(false, 0) => "stopped",
(false, _) => "stopping",
}
}
/// Status labels of an issue, in the order of the workflow.
pub const STATUS_LABELS: [(&str, &str); 9] = [
("factory", "0e8a16"),
@@ -1478,6 +1500,7 @@ pub async fn poll_repo(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()>
allowed.push(g.login().await?);
}
let issues = g.issues(&cfg.label).await?;
let power_on = app.store.user_setting::<Power>(&user.id, "factory_power").unwrap_or_default().on;
for issue in issues {
let n = issue_no(&issue);
let author = issue["user"]["login"].as_str().unwrap_or("");
@@ -1498,7 +1521,7 @@ pub async fn poll_repo(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()>
}
"approved" | "rework" => {
let feedback = if state == "rework" { row["note"].as_str().unwrap_or("").to_string() } else { String::new() };
if app.store.factory_running(&cfg.url)? < cfg.max_parallel as i64 {
if power_on && app.store.factory_running(&cfg.url)? < cfg.max_parallel as i64 {
let comments = g.comments(n as u64).await.unwrap_or_default();
app.store.factory_issue_set(&cfg.url, n, &[("title", json!(title)), ("state", json!("building"))])?;
tokio::spawn(build(app.clone(), user.clone(), cfg.clone(), issue, comments, feedback));
@@ -1506,7 +1529,7 @@ pub async fn poll_repo(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()>
continue;
}
"qa" => {
if app.store.factory_running(&cfg.url)? < cfg.max_parallel as i64 {
if power_on && app.store.factory_running(&cfg.url)? < cfg.max_parallel as i64 {
app.store.factory_issue_set(&cfg.url, n, &[("title", json!(title))])?;
// Mark the run before it starts so the next poll does not take it up again.
app.store.factory_issue_set(&cfg.url, n, &[("state", json!("testing"))])?;
@@ -1516,7 +1539,7 @@ pub async fn poll_repo(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()>
}
_ => false,
};
if !start || app.store.factory_running(&cfg.url)? >= cfg.max_parallel as i64 {
if !start || !power_on || app.store.factory_running(&cfg.url)? >= cfg.max_parallel as i64 {
continue;
}
if comments.is_empty() {
@@ -1907,6 +1930,15 @@ pub async fn create_project(app: &Arc<App>, user: &User, settings: &mut FactoryS
mod tests {
use super::*;
#[test]
fn power_states() {
assert_eq!(power_state(true, 0), "running");
assert_eq!(power_state(true, 3), "running");
assert_eq!(power_state(false, 2), "stopping");
assert_eq!(power_state(false, 0), "stopped");
assert!(Power::default().on);
}
#[test]
fn backlog_skips_tracked_and_queued_issues() {
let cfg = repo("https://git.example.org/o/r.git");