Compare commits

..
Author SHA1 Message Date
Richard Zink 836377ac38 Release v202611-00074 2026-11-20 13:23:56 +01:00
Richard ZinkandClaude Sonnet 5.5 391db43949 Factory: merge and close buttons on the issue card, enforced order
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 13:23:52 +01:00
Richard Zink 0e54714436 Release v202611-00073 2026-11-20 13:15:10 +01:00
Richard ZinkandClaude Sonnet 5.5 b9df00422a Test runner: per-project cache (tool caches, shared dirs, seeds)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 13:15:07 +01:00
Richard Zink a083798d7f Release v202611-00072 2026-11-20 12:46:01 +01:00
Richard ZinkandClaude Sonnet 5.5 724405b245 Factory: blinking blue lamp while a phase is being prepared
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 12:45:59 +01:00
12 changed files with 375 additions and 22 deletions

No files matched your search

+18
View File
@@ -3,6 +3,24 @@
All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/);
until 1.0, minor versions may contain breaking changes.
## [v202611-00074] – 2026-11-20
### Changed
- **Factory: merge and close on the issue card.** A finished issue shows a *Merge* button on its card once the acceptance has passed (the pull request is open); after the merge the card shows *Close*. Before that neither button is shown. The server enforces the order: a pull request is merged only when the acceptance passed, an issue is closed only when its pull request is merged (a merge done on the forge itself counts). The issue also gets its version and tag right after a merge instead of at the next poll.
## [v202611-00073] – 2026-11-20
### Added
- **Test runner: cache between acceptance runs.** Every project gets a cache volume (`cc-cache-<project>`) in the runner. Tool caches are shared automatically: npm and Yarn, pip, Go modules and build cache, the Cargo registry and the Cargo target directory (so the second build of a Rust project is incremental). `.factory/setup.json` can add `"cache": {"dirs": [...]}` for directories that persist (downloads – inputs only) and `"cache": {"seed": {"paths": [...], "key": [...]}}` for expensive *results* of `install`, such as a built disk image: the seed is stored after a successful install under a key made from the image, the install command, the seed paths and the contents of the `key` files, and copied into fresh containers only while the key matches – a run never sees changes of an earlier run, and a change of the listed sources builds it anew (the three newest seeds are kept). `"cache": false` turns everything off; `DELETE /v1/cache/<project>` on the runner forgets a project's cache.
## [v202611-00072] – 2026-11-20
### Added
- **Factory: "preparing" lamp.** An issue card whose phase has been started but whose chat does not exist yet – checkout and, for acceptance, installing and starting the app in its throw-away container – shows a blinking blue lamp with the elapsed time instead of staying silent. (Active chats keep their accent-coloured lamp.)
## [v202611-00071] – 2026-11-20
### Added
+20 -2
View File
@@ -11,7 +11,7 @@
</p>
<p align="center">
<img alt="Version v202611-00071" src="https://img.shields.io/badge/version-v202611--00071-d69e2e?style=flat-square">
<img alt="Version v202611-00074" src="https://img.shields.io/badge/version-v202611--00074-d69e2e?style=flat-square">
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-689d6a?style=flat-square">
<img alt="Rust backend" src="https://img.shields.io/badge/backend-Rust-b7410e?style=flat-square&logo=rust">
<img alt="React PWA" src="https://img.shields.io/badge/frontend-React%20PWA-2d81ff?style=flat-square&logo=react">
@@ -292,7 +292,8 @@ the server.
On *pass* the factory opens the pull request (if none is open) and comments a result table
in the issue. On *fail* the issue goes back to the build with the findings (*rework*).
4. **Done, merge, version.** You review the pull request in the factory (diff, description) and
merge it there. The factory then pulls the merge, gives the issue its version, commits
merge it there – on the page or with the *Merge* button of the issue card, which appears once
the acceptance has passed (closing an issue by hand is possible only after its merge). The factory then pulls the merge, gives the issue its version, commits
`VERSION`, pushes an annotated tag, comments on the issue and closes it.
Issue text is treated as data, never as instructions for the factory itself.
@@ -373,6 +374,23 @@ helper services and network are removed (leftovers are swept at startup and afte
}
```
Between runs of one project the runner keeps a cache volume: npm/Yarn, pip, Go and Cargo caches
(including the Cargo target directory) are shared automatically. For more, add to `setup.json`:
```json
"cache": {
"dirs": ["build/downloads"],
"seed": { "paths": ["data/ubuntu.ext4"], "key": ["guest", "lib", "scripts", "package-lock.json"] }
}
```
`dirs` persist and are shared by all runs (use them for downloads, not for results). A `seed`
holds expensive *results* of `install`: it is stored after a successful install under a key made
from the image, the install command, the seed paths and the contents of the `key` files or
directories, and copied into a fresh container only while that key matches – so a run never
inherits changes from an earlier one, and editing a listed source rebuilds it. `"cache": false`
disables caching; `DELETE /v1/cache/<project>` on the runner clears one project.
`image` defaults to `RUNNER_DEFAULT_IMAGE`; `"dockerfile": "path"` builds the image from the
repository instead; helper services are reachable by their name. Containers run without extra
capabilities, with memory/CPU/process limits (`RUNNER_MEMORY`, `RUNNER_CPUS`), and cannot see the
+21 -1
View File
@@ -3011,6 +3011,15 @@ async fn factory_close_issue(Extension(user): Extension<User>, State(app): State
return Err(ApiError(StatusCode::BAD_REQUEST, "only finished issues can be closed here".into()));
}
let bad = |e: anyhow::Error| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}"));
// Closing comes after the merge. A merge done on the forge itself counts too: ask the forge when we do not know yet.
if row["merged"].as_bool() != Some(true) {
let pr_n: u64 = row["pr_url"].as_str().unwrap_or("").trim_end_matches('/').rsplit('/').next().and_then(|n| n.parse().ok()).unwrap_or(0);
let merged = pr_n > 0 && g.pr(pr_n).await.map(|p| p["state"].as_str() == Some("merged")).unwrap_or(false);
if !merged {
return Err(ApiError(StatusCode::BAD_REQUEST, "merge the pull request first".into()));
}
app.store.factory_issue_set(&b.repo, b.number, &[("merged", json!(1))])?;
}
let text = if b.comment.trim().is_empty() { "Closed.".to_string() } else { b.comment.trim().to_string() };
g.comment(b.number as u64, &format!("{}\n**Closed** by {}: {text}", crate::factory::BOT, user.username)).await.map_err(bad)?;
g.close_issue(b.number as u64).await.map_err(bad)?;
@@ -3072,6 +3081,10 @@ struct MergePr {
/// Merge the pull request of an issue – only on the user's own click in the factory page.
async fn factory_pr_merge(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Json(b): Json<MergePr>) -> ApiResult {
let (g, row) = factory_issue_forge(&app, &user, &b.repo, b.number)?;
// Merging comes after a positive acceptance (the issue is "done").
if row["state"].as_str() != Some("done") {
return Err(ApiError(StatusCode::BAD_REQUEST, "the pull request can be merged once the acceptance has passed".into()));
}
let method = if b.method.is_empty() { "merge" } else { b.method.as_str() };
if !["merge", "squash", "rebase"].contains(&method) {
return Err(ApiError(StatusCode::BAD_REQUEST, "unknown merge method".into()));
@@ -3082,8 +3095,15 @@ async fn factory_pr_merge(Extension(user): Extension<User>, State(app): State<Ap
return Err(ApiError(StatusCode::BAD_REQUEST, "this is not the open pull request of the issue".into()));
}
g.merge_pr(b.pr, method).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
app.store.factory_issue_set(&b.repo, b.number, &[("pr_url", json!(pr["html_url"].as_str().unwrap_or("")))])?;
app.store.factory_issue_set(&b.repo, b.number, &[("pr_url", json!(pr["html_url"].as_str().unwrap_or(""))), ("merged", json!(1))])?;
app.audit(Some(&user), "factory.pr.merge", &format!("{}#{}", b.repo, b.number), &crate::auth::client_ip(&headers));
// Give the issue its version and tag right away instead of at the next poll.
if let Ok(cfg) = factory_repo_cfg(&app, &user, &b.repo) {
let (app2, user2) = (app.clone(), user.clone());
tokio::spawn(async move {
let _ = crate::factory::poll_repo(&app2, &user2, &cfg).await;
});
}
Ok(Json(json!({"ok": true})))
}
+4 -2
View File
@@ -1240,11 +1240,13 @@ impl TestEnv {
/// Start the app of `work` in a throw-away container when a test runner is configured
/// (`CODECRAFT_RUNNER_URL`) and `.factory/setup.json` says how. `Ok(None)` = run it the old way.
async fn start_test_env(work: &std::path::Path) -> Result<Option<TestEnv>> {
async fn start_test_env(work: &std::path::Path, repo_url: &str) -> Result<Option<TestEnv>> {
use crate::testrunner as tr;
let Some(client) = tr::Client::from_env() else { return Ok(None) };
let Some(mut req) = std::fs::read_to_string(work.join(".factory/setup.json")).ok().and_then(|t| tr::parse_setup(&t)) else { return Ok(None) };
req.work = work.display().to_string();
// One cache per project: tool caches, download directories and seeds survive between acceptance runs.
req.cache_id = slugify(repo_url.trim_end_matches(".git").rsplit("://").next().unwrap_or(repo_url)).chars().take(80).collect();
let started = client.start(&req).await?;
let (local, forward) = match tr::forward_local(req.port, client.host(), started.port).await {
Ok(x) => x,
@@ -1342,7 +1344,7 @@ async fn qa(app: Arc<App>, user: User, cfg: RepoCfg, issue: Value) {
}
}
// With a test runner the app starts in a throw-away container; without one the agent starts it itself.
let env = match start_test_env(&work).await {
let env = match start_test_env(&work, &cfg.url).await {
Ok(e) => e,
Err(e) => {
cleanup_worktree(&app, &user, &cfg, &work).await;
+2
View File
@@ -235,6 +235,8 @@ pub async fn version_pass(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<
if pr["state"].as_str() != Some("merged") {
continue;
}
// Remember it at once: if the version step below fails, the issue can still be closed by hand.
let _ = app.store.factory_issue_set(&cfg.url, n, &[("merged", json!(1))]);
let title = r["title"].as_str().unwrap_or("").to_string();
let others: Vec<String> = g.open_issue_titles().await?.into_iter().filter(|(num, _)| *num != n).map(|(_, t)| t).collect();
let dir = checkout(app, user, cfg).await?;
+4 -3
View File
@@ -262,6 +262,7 @@ impl Store {
("images", "blob", "ALTER TABLE images ADD COLUMN blob TEXT"),
("usage", "allowance", "ALTER TABLE usage ADD COLUMN allowance REAL"),
("factory_issues", "version", "ALTER TABLE factory_issues ADD COLUMN version TEXT NOT NULL DEFAULT ''"),
("factory_issues", "merged", "ALTER TABLE factory_issues ADD COLUMN merged INTEGER NOT NULL DEFAULT 0"),
] {
let exists: bool = conn
.prepare(&format!("SELECT 1 FROM pragma_table_info('{table}') WHERE name = ?1"))?
@@ -1489,8 +1490,8 @@ impl Store {
pub fn factory_issue(&self, repo: &str, number: i64) -> Result<Option<Value>> {
let conn = self.conn.lock().unwrap();
Ok(conn
.query_row("SELECT title, author, state, attempts, rounds, last_comment, scenarios, branch, pr_url, note, created_at, updated_at, owner_id, version FROM factory_issues WHERE repo_url = ?1 AND number = ?2", params![repo, number], |r| {
Ok(json!({"repo": repo, "number": number, "title": r.get::<_, String>(0)?, "author": r.get::<_, String>(1)?, "state": r.get::<_, String>(2)?, "attempts": r.get::<_, i64>(3)?, "rounds": r.get::<_, i64>(4)?, "last_comment": r.get::<_, i64>(5)?, "scenarios": r.get::<_, String>(6)?, "branch": r.get::<_, String>(7)?, "pr_url": r.get::<_, String>(8)?, "note": r.get::<_, String>(9)?, "created_at": r.get::<_, i64>(10)?, "updated_at": r.get::<_, i64>(11)?, "owner_id": r.get::<_, String>(12)?, "version": r.get::<_, String>(13)?}))
.query_row("SELECT title, author, state, attempts, rounds, last_comment, scenarios, branch, pr_url, note, created_at, updated_at, owner_id, version, merged FROM factory_issues WHERE repo_url = ?1 AND number = ?2", params![repo, number], |r| {
Ok(json!({"repo": repo, "number": number, "title": r.get::<_, String>(0)?, "author": r.get::<_, String>(1)?, "state": r.get::<_, String>(2)?, "attempts": r.get::<_, i64>(3)?, "rounds": r.get::<_, i64>(4)?, "last_comment": r.get::<_, i64>(5)?, "scenarios": r.get::<_, String>(6)?, "branch": r.get::<_, String>(7)?, "pr_url": r.get::<_, String>(8)?, "note": r.get::<_, String>(9)?, "created_at": r.get::<_, i64>(10)?, "updated_at": r.get::<_, i64>(11)?, "owner_id": r.get::<_, String>(12)?, "version": r.get::<_, String>(13)?, "merged": r.get::<_, i64>(14)? != 0}))
})
.optional()?)
}
@@ -1512,7 +1513,7 @@ impl Store {
/// Update the given columns (whitelisted) of an issue.
pub fn factory_issue_set(&self, repo: &str, number: i64, fields: &[(&str, Value)]) -> Result<()> {
const COLS: [&str; 11] = ["title", "state", "attempts", "rounds", "last_comment", "scenarios", "branch", "pr_url", "note", "author", "version"];
const COLS: [&str; 12] = ["title", "state", "attempts", "rounds", "last_comment", "scenarios", "branch", "pr_url", "note", "author", "version", "merged"];
let conn = self.conn.lock().unwrap();
for (k, v) in fields {
if !COLS.contains(k) {
+189 -1
View File
@@ -30,6 +30,24 @@ use tokio::process::Command;
use tokio::task::JoinHandle;
const LABEL: &str = "codecraft.testrunner=1";
const CACHE_LABEL: &str = "codecraft.testrunner.cache=1";
/// What every environment container runs: link the shared directories, restore a matching seed, run
/// `install`, store a new seed (only after a successful install, so it is pristine), start the app.
const ENTRY_SCRIPT: &str = r#"cd /app
if [ -d /cache ]; then
for d in $CC_CACHE_DIRS; do mkdir -p "/cache/dirs/$d" "$(dirname "$d")" && rm -rf "$d" && ln -s "/cache/dirs/$d" "$d"; done
if [ -d /usr/local/cargo ]; then for d in registry git; do mkdir -p "/cache/cargo/$d"; rm -rf "/usr/local/cargo/$d"; ln -s "/cache/cargo/$d" "/usr/local/cargo/$d"; done; fi
if [ -n "$CC_SEED_KEY" ]; then for p in $CC_SEED_PATHS; do if [ -e "/cache/seed/$CC_SEED_KEY/$p" ]; then mkdir -p "$(dirname "$p")" && cp -a "/cache/seed/$CC_SEED_KEY/$p" "$p" && echo "[runner] restored $p from the cache"; fi; done; fi
fi
if [ -n "$CC_INSTALL" ]; then sh -c "$CC_INSTALL" || exit 1; fi
if [ -d /cache ] && [ -n "$CC_SEED_KEY" ] && [ ! -d "/cache/seed/$CC_SEED_KEY" ]; then
t="/cache/seed/.tmp-$$"; rm -rf "$t"; mkdir -p "$t"; ok=1
for p in $CC_SEED_PATHS; do if [ -e "$p" ]; then mkdir -p "$t/$(dirname "$p")" && cp -a "$p" "$t/$p" || ok=0; fi; done
if [ "$ok" = 1 ]; then mv "$t" "/cache/seed/$CC_SEED_KEY" && echo "[runner] stored the seed $CC_SEED_KEY"; else rm -rf "$t"; fi
ls -1t /cache/seed 2>/dev/null | grep -v '^\.tmp' | tail -n +4 | while read -r o; do rm -rf "/cache/seed/$o"; done
fi
exec sh -c "$CC_START""#;
// --- what a repository asks for (.factory/setup.json) ------------------------------------
@@ -41,6 +59,29 @@ pub struct Service {
pub env: BTreeMap<String, String>,
}
/// What stays between runs of one project (kept in a Docker volume of the runner).
///
/// * `dirs`: directories of the sources that persist and are shared by all runs (downloads, caches –
/// inputs only: whatever lands there is visible to the next run).
/// * `seed`: expensive *results* of `install` (e.g. a built disk image). They are stored after a successful
/// `install` under a key made from the image, the install command, the seed paths and the contents of the
/// `key` files/directories, and copied into fresh containers whenever that key matches – so a run never
/// sees changes of an earlier run, and a change of the listed sources builds the seed anew.
///
/// Tool caches (npm, yarn, pip, Go, Cargo registry and target directory) are always shared per project
/// unless `"cache": false`.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct CacheCfg {
#[serde(default)]
pub disabled: bool,
#[serde(default)]
pub dirs: Vec<String>,
#[serde(default)]
pub seed_paths: Vec<String>,
#[serde(default)]
pub seed_key: Vec<String>,
}
/// The request to start an environment.
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct StartReq {
@@ -63,6 +104,11 @@ pub struct StartReq {
/// How long to wait until the port answers (seconds, default 300).
#[serde(default)]
pub ready_secs: u64,
/// Stable name of the project: its cache lives in the volume `cc-cache-<cache_id>`. Empty = no cache.
#[serde(default)]
pub cache_id: String,
#[serde(default)]
pub cache: CacheCfg,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -110,9 +156,19 @@ pub fn parse_setup(text: &str) -> Option<StartReq> {
env: strs("env"),
services,
ready_secs: v["ready_seconds"].as_u64().unwrap_or(0),
cache_id: String::new(),
cache: parse_cache(&v["cache"]),
})
}
fn parse_cache(v: &Value) -> CacheCfg {
let list = |x: &Value| -> Vec<String> { x.as_array().map(|a| a.iter().filter_map(|s| s.as_str().map(|s| s.trim().trim_end_matches('/').to_string())).filter(|s| !s.is_empty()).collect()).unwrap_or_default() };
if v.as_bool() == Some(false) {
return CacheCfg { disabled: true, ..Default::default() };
}
CacheCfg { disabled: false, dirs: list(&v["dirs"]), seed_paths: list(&v["seed"]["paths"]), seed_key: list(&v["seed"]["key"]) }
}
/// Port of `http://host:1234/path` (80/443 by scheme when missing).
pub fn port_of(url: &str) -> Option<u16> {
let (scheme, rest) = url.trim().split_once("://")?;
@@ -132,6 +188,61 @@ fn image_ok(s: &str) -> bool {
ident_ok(s, "._/:@-") && !s.starts_with('-')
}
/// A path inside the sources: relative, no `..`, only plain characters (it ends up in a shell loop).
fn rel_ok(p: &str) -> bool {
ident_ok(p, "._/-") && !p.starts_with('/') && !p.starts_with('-') && !p.split('/').any(|c| c.is_empty() || c == "..") && !p.split('/').any(|c| c == ".git")
}
/// Key of a seed: image, install command, seed paths and the contents of the key files (directories: recursively).
pub fn seed_key(work: &Path, image: &str, req: &StartReq) -> Option<String> {
use sha2::{Digest, Sha256};
let c = &req.cache;
if c.disabled || c.seed_paths.is_empty() {
return None;
}
fn walk(base: &Path, rel: &Path, out: &mut Vec<std::path::PathBuf>) {
let full = base.join(rel);
if full.is_dir() {
let mut kids: Vec<_> = std::fs::read_dir(&full).map(|d| d.filter_map(|e| e.ok()).map(|e| e.file_name()).collect()).unwrap_or_default();
kids.sort();
for k in kids {
if k == ".git" || k == "node_modules" {
continue;
}
walk(base, &rel.join(k), out);
}
} else if full.is_file() {
out.push(rel.to_path_buf());
}
}
let mut h = Sha256::new();
for part in [image, &req.install, &c.seed_paths.join("\n"), &req.dockerfile] {
h.update(part.as_bytes());
h.update([0]);
}
let mut files = Vec::new();
let mut keys = c.seed_key.clone();
keys.sort();
for k in &keys {
h.update(k.as_bytes());
h.update([1]);
walk(work, Path::new(k), &mut files);
}
let mut total = 0u64;
for f in files {
let data = std::fs::read(work.join(&f)).ok()?;
total += data.len() as u64;
if total > 200 << 20 {
return None;
}
h.update(f.to_string_lossy().as_bytes());
h.update([2]);
h.update(&data);
}
let d = h.finalize();
Some(d.iter().take(10).map(|b| format!("{b:02x}")).collect())
}
fn env_ok(m: &BTreeMap<String, String>) -> bool {
m.len() <= 64 && m.iter().all(|(k, v)| k.chars().next().is_some_and(|c| c.is_ascii_alphabetic() || c == '_') && ident_ok(k, "_") && v.len() <= 4096 && !v.contains('\0'))
}
@@ -158,6 +269,16 @@ fn validate(req: &StartReq, factory_dir: &Path) -> Result<PathBuf> {
if !env_ok(&req.env) {
bail!("invalid environment variable");
}
if !req.cache_id.is_empty() && !ident_ok(&req.cache_id, "-_.") {
bail!("invalid cache id");
}
let c = &req.cache;
if c.dirs.len() > 16 || c.seed_paths.len() > 8 || c.seed_key.len() > 32 || !c.dirs.iter().chain(&c.seed_paths).chain(&c.seed_key).all(|p| rel_ok(p)) {
bail!("invalid cache path (relative, letters, digits and ._-/ only)");
}
if !c.seed_paths.is_empty() && c.seed_key.is_empty() {
bail!("cache.seed needs a key (the sources the seed depends on)");
}
let root = factory_dir.canonicalize().with_context(|| format!("factory area {} is not mounted", factory_dir.display()))?;
let work = Path::new(&req.work).canonicalize().context("source directory not found")?;
if !work.starts_with(&root) || !work.is_dir() {
@@ -254,6 +375,7 @@ pub async fn serve() -> Result<()> {
.route("/v1/envs", post(start_env))
.route("/v1/envs/{id}", delete(stop_env))
.route("/v1/envs/{id}/log", get(log_env))
.route("/v1/cache/{id}", delete(clear_cache))
.with_state(runner);
let bind = std::env::var("RUNNER_BIND").unwrap_or_else(|_| "0.0.0.0:8788".into());
let l = TcpListener::bind(&bind).await?;
@@ -350,12 +472,42 @@ async fn create(r: &Arc<Runner>, id: &str, req: &StartReq, work: &Path) -> Resul
a.push("-e".into());
a.push(format!("{k}={v}"));
}
// Per-project cache volume: tool caches, shared download directories and seeds (see CacheCfg).
let cached = !req.cache_id.is_empty() && !req.cache.disabled;
if cached {
let vol = format!("cc-cache-{}", req.cache_id);
docker(&["volume", "create", "--label", CACHE_LABEL, &vol]).await.context("cache volume")?;
a.push("-v".into());
a.push(format!("{vol}:/cache"));
for (k, v) in [
("npm_config_cache", "/cache/npm"),
("YARN_CACHE_FOLDER", "/cache/yarn"),
("PIP_CACHE_DIR", "/cache/pip"),
("GOMODCACHE", "/cache/go/mod"),
("GOCACHE", "/cache/go/build"),
("CARGO_TARGET_DIR", "/cache/target"),
("XDG_CACHE_HOME", "/cache/xdg"),
] {
if !req.env.contains_key(k) {
a.push("-e".into());
a.push(format!("{k}={v}"));
}
}
a.push("-e".into());
a.push(format!("CC_CACHE_DIRS={}", req.cache.dirs.join(" ")));
if let Some(key) = seed_key(work, &image, req) {
a.push("-e".into());
a.push(format!("CC_SEED_KEY={key}"));
a.push("-e".into());
a.push(format!("CC_SEED_PATHS={}", req.cache.seed_paths.join(" ")));
}
}
a.push("-e".into());
a.push(format!("CC_INSTALL={}", req.install));
a.push("-e".into());
a.push(format!("CC_START={}", req.start));
a.push(image);
a.extend(["sh", "-c", r#"if [ -n "$CC_INSTALL" ]; then sh -c "$CC_INSTALL" || exit 1; fi; exec sh -c "$CC_START""#].map(String::from));
a.extend(["sh", "-c", ENTRY_SCRIPT].map(String::from));
let refs: Vec<&str> = a.iter().map(String::as_str).collect();
docker(&refs).await.context("docker create")?;
// Copy the sources in (without .git); the container never sees the host directory.
@@ -443,6 +595,16 @@ async fn stop_env(State(r): State<Arc<Runner>>, h: HeaderMap, AxPath(id): AxPath
Ok(Json(json!({"ok": true})))
}
/// Forget the cache of a project (fails while an environment of it is running).
async fn clear_cache(State(r): State<Arc<Runner>>, h: HeaderMap, AxPath(id): AxPath<String>) -> Resp<Json<Value>> {
authed(&r, &h)?;
if !ident_ok(&id, "-_.") {
return Err((StatusCode::BAD_REQUEST, "invalid cache id".into()));
}
docker(&["volume", "rm", &format!("cc-cache-{id}")]).await.map_err(|e| (StatusCode::CONFLICT, format!("{e:#}")))?;
Ok(Json(json!({"ok": true})))
}
#[derive(Deserialize)]
struct LogQ {
tail: Option<usize>,
@@ -574,6 +736,32 @@ mod tests {
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn cache_config_and_seed_key() {
let r = parse_setup(r#"{"start":"x","port":1,"cache":{"dirs":["build/downloads/"],"seed":{"paths":["data/ubuntu.ext4"],"key":["guest","package-lock.json"]}}}"#).unwrap();
assert_eq!(r.cache.dirs, vec!["build/downloads"]);
assert_eq!(r.cache.seed_key, vec!["guest", "package-lock.json"]);
assert!(parse_setup(r#"{"start":"x","port":1,"cache":false}"#).unwrap().cache.disabled);
assert!(!parse_setup(r#"{"start":"x","port":1}"#).unwrap().cache.disabled);
assert!(rel_ok("build/downloads") && !rel_ok("../x") && !rel_ok("/etc") && !rel_ok("a b") && !rel_ok("a/.git/b") && !rel_ok("a//b"));
// The key follows the contents of the key files, not of anything else.
let dir = std::env::temp_dir().join(format!("ccs-{}", std::process::id()));
std::fs::create_dir_all(dir.join("guest")).unwrap();
std::fs::write(dir.join("guest/a.c"), "one").unwrap();
std::fs::write(dir.join("other.txt"), "x").unwrap();
let mut req = r.clone();
req.install = "npm ci".into();
let k1 = seed_key(&dir, "node:24", &req).unwrap();
std::fs::write(dir.join("other.txt"), "changed").unwrap();
assert_eq!(seed_key(&dir, "node:24", &req).unwrap(), k1);
std::fs::write(dir.join("guest/a.c"), "two").unwrap();
assert_ne!(seed_key(&dir, "node:24", &req).unwrap(), k1);
assert_ne!(seed_key(&dir, "node:22", &req).unwrap(), seed_key(&dir, "node:24", &req).unwrap());
req.cache.seed_paths.clear();
assert!(seed_key(&dir, "node:24", &req).is_none());
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn tokens_compare() {
assert!(eq_const("abc", "abc"));
+56 -13
View File
@@ -78,6 +78,8 @@ interface Issue {
branch: string;
rounds: number;
/** Newest phase chat that still exists. */
/** The pull request is merged (merging comes after a positive acceptance, closing after the merge). */
merged?: boolean;
chat_session?: string;
chat_phase?: Phase;
created_at: number;
@@ -188,6 +190,20 @@ export function Factory({ onMenu, overlayId }: { onMenu: () => void; overlayId?:
);
}
/** A button inside an issue card (the card itself is a button, so this is a span with the button role). */
function CardAction({ children, onClick, title, primary, disabled }: { children: React.ReactNode; onClick: () => void; title?: string; primary?: boolean; disabled?: boolean }) {
const run = (e: React.SyntheticEvent) => {
e.stopPropagation();
e.preventDefault();
if (!disabled) onClick();
};
return (
<span role="button" tabIndex={disabled ? -1 : 0} aria-disabled={disabled} className={`factory-card-action ${primary ? "primary" : ""} ${disabled ? "disabled" : ""}`} title={title} onClick={run} onKeyDown={(e) => (e.key === "Enter" || e.key === " ") && run(e)}>
{children}
</span>
);
}
/** The factory's main switch, coloured by state: green = running, yellow = stopping, red = stopped. */
function PowerSwitch({ power, onToggle }: { power: Power; onToggle: (on: boolean) => void }) {
const t = useT();
@@ -402,20 +418,24 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
setBusy(false);
}
};
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;
const prNo = (i: Issue) => Number(i.pr_url.replace(/\/$/, "").split("/").pop()) || 0;
/** Merge the pull request of an issue; only offered once the acceptance has passed. */
const mergeIssue = async (i: Issue, n = prNo(i)) => {
if (!n || i.state !== "done") return;
if (!(await confirmDialog({ message: t("factory.mergeConfirm", { n, 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 });
await post("/factory/issues/pr/merge", { repo: i.repo, number: i.number, pr: n, method: prMethod });
toast(t("factory.merged"));
await loadPr();
await reload();
} catch (e: any) {
toast(e.message);
} finally {
setBusy(false);
}
};
const mergePr = () => (selected && pr ? mergeIssue(selected, pr.number) : Promise.resolve());
const removeIssue = async () => {
if (!selected) return;
if (!(await confirmDialog({ message: t("factory.removeConfirm", { n: selected.number }), confirmLabel: t("factory.remove"), danger: true }))) return;
@@ -430,15 +450,16 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
setBusy(false);
}
};
const closeIssue = async () => {
if (!selected) return;
const comment = await promptDialog({ title: t("factory.closeTitle"), message: t("factory.closeMsg", { n: selected.number }), defaultValue: t("factory.closeDefault"), confirmLabel: t("factory.close") });
/** Close an issue; only offered once its pull request is merged. */
const closeIssueOf = async (i: Issue) => {
if (i.state !== "done" || !i.merged) return;
const comment = await promptDialog({ title: t("factory.closeTitle"), message: t("factory.closeMsg", { n: i.number }), defaultValue: t("factory.closeDefault"), confirmLabel: t("factory.close") });
if (comment === null) return;
setBusy(true);
try {
await post("/factory/issues/close", { repo: selected.repo, number: selected.number, comment });
await post("/factory/issues/close", { repo: i.repo, number: i.number, comment });
toast(t("factory.closed"), "success");
setSel("");
if (selected && selected.number === i.number && selected.repo === i.repo) setSel("");
await reload();
} catch (e: any) {
toast(e.message);
@@ -446,6 +467,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
setBusy(false);
}
};
const closeIssue = () => (selected ? closeIssueOf(selected) : Promise.resolve());
const phaseRunning = !!selected && ["review", "building", "testing"].includes(selected.state);
/** Master switch: a soft stop – no new agent starts, running ones finish their phase. */
const setPower = async (on: boolean) => {
@@ -577,9 +599,11 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
const rs = runsOf(i);
const active = rs.find((r) => !r.ended_at);
const latest = active ?? rs[0];
// Claimed by a phase but no chat yet: checkout, and – for acceptance – installing and starting the app in its throw-away container.
const preparing = !active && ["review", "building", "testing"].includes(i.state);
const tokens = rs.reduce((a, r) => a + r.input_tokens + r.output_tokens, 0);
return (
<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}`)}>
<button key={`${i.repo}#${i.number}`} data-state={i.state} className={`factory-card ${sel === `${i.repo}#${i.number}` ? "active" : ""} ${active ? "running" : ""} ${preparing ? "preparing" : ""}`} onClick={() => setSel(sel === `${i.repo}#${i.number}` ? "" : `${i.repo}#${i.number}`)}>
<span className="factory-card-head">
<span className="hint">
{repoName(i.repo)} #{i.number}
@@ -608,13 +632,32 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
)}
</span>
<b>{i.title || `#${i.number}`}</b>
{latest && (
{preparing && (
<span className="hint" title={t("factory.preparing.hint")}>
<span className="factory-pulse prep" />
{i.state === "testing" ? t("factory.preparing.env") : t("factory.preparing.start")} · {fmtDuration(now - i.updated_at)}
</span>
)}
{latest && !preparing && (
<span className="hint">
{active && <span className="factory-pulse" />}
{t(`factory.phase.${latest.phase}` as any)} · {(latest.model || "").split("/").pop()} · {fmtDuration(runMs(latest, now))}
</span>
)}
{tokens > 0 && <span className="hint">{fmtCompact(tokens)} {t("factory.tokens")}</span>}
{i.state === "done" && (i.merged || prNo(i) > 0) && (
<span className="factory-card-actions">
{!i.merged ? (
<CardAction primary disabled={busy} title={t("factory.mergeHint")} onClick={() => void mergeIssue(i)}>
<Icon name="fork" /> {t("factory.mergeBtn")}
</CardAction>
) : (
<CardAction disabled={busy} title={t("factory.closeHint")} onClick={() => void closeIssueOf(i)}>
<Icon name="check" /> {t("factory.close")}
</CardAction>
)}
</span>
)}
</button>
);
})}
@@ -650,7 +693,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
<Icon name="trash" /> {t("factory.remove")}
</button>
)}
{selected && selected.state === "done" && (
{selected && selected.state === "done" && selected.merged && (
<button className="small" onClick={closeIssue} disabled={busy}>
<Icon name="check" /> {t("factory.close")}
</button>
@@ -683,7 +726,7 @@ function FactoryOverview({ onSettings }: { onSettings: () => void }) {
</span>
)}
<span className="spacer" />
{pr.state === "open" && (
{pr.state === "open" && selected?.state === "done" && (
<>
<select value={prMethod} onChange={(e) => setPrMethod(e.target.value)} disabled={busy}>
{["merge", "squash", "rebase"].map((m) => (
+5
View File
@@ -1243,6 +1243,11 @@ export const de: Messages = {
"factory.power.stopped": "Factory gestoppt",
"factory.power.stopHint": "Klicken zum Stoppen: keine neuen Agenten, laufende werden fertig",
"factory.power.startHint": "Klicken, um die Factory zu starten",
"factory.preparing.env": "Testumgebung wird vorbereitet",
"factory.preparing.start": "Lauf wird vorbereitet",
"factory.preparing.hint": "Der Agent-Chat startet, sobald der Checkout fertig ist und – bei der Abnahme – die App in ihrem Wegwerf-Container installiert ist und läuft",
"factory.mergeHint": "Pull Request mergen – die Abnahme war erfolgreich",
"factory.closeHint": "Issue schließen – der Pull Request ist gemerged",
"factory.col.review": "Prüfung",
"factory.col.question": "Rückfragen",
"factory.col.approved": "Freigegeben",
+5
View File
@@ -1242,6 +1242,11 @@ export const en = {
"factory.power.stopped": "Factory stopped",
"factory.power.stopHint": "Click to stop: no new agents start, running ones finish",
"factory.power.startHint": "Click to start the factory",
"factory.preparing.env": "Preparing the test environment",
"factory.preparing.start": "Preparing the run",
"factory.preparing.hint": "The agent chat starts when the checkout is done and – for acceptance – the app is installed and running in its throw-away container",
"factory.mergeHint": "Merge the pull request – the acceptance has passed",
"factory.closeHint": "Close the issue – the pull request is merged",
"factory.col.review": "Review",
"factory.col.question": "Questions",
"factory.col.approved": "Approved",
+39
View File
@@ -5278,6 +5278,38 @@ td.fold-indent {
border: 0;
}
}
.factory-card-actions {
display: flex;
gap: 6px;
margin-top: 4px;
}
.factory-card-action {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 3px 9px;
font-size: 12.5px;
border-radius: 6px;
border: 1px solid var(--bg3);
background: var(--bg1);
color: var(--fg0);
cursor: pointer;
}
.factory-card-action:hover {
background: var(--bg2);
}
.factory-card-action.primary {
background: var(--accent);
border-color: var(--accent);
color: var(--on-accent, var(--bg0));
}
.factory-card-action.primary:hover {
filter: brightness(1.08);
}
.factory-card-action.disabled {
opacity: 0.5;
cursor: default;
}
.factory-card-head {
display: flex;
align-items: center;
@@ -5319,6 +5351,13 @@ td.fold-indent {
margin-right: 5px;
animation: factory-pulse 1.4s ease-in-out infinite;
}
/* Preparing (checkout, test environment): same lamp, other colour than an active chat. */
.factory-pulse.prep {
background: var(--blue, var(--accent2));
}
.factory-card.preparing {
border-left: 3px solid var(--blue, var(--accent2));
}
@keyframes factory-pulse {
50% {
opacity: 0.25;
+12
View File
@@ -3,6 +3,18 @@
* under "unreleased"; scripts/release.sh renames the key to the release version.
*/
export const WHATS_NEW: Record<string, { en: string[]; de: string[] }> = {
"202611-00074": {
en: ["Factory: Merge and Close buttons on the issue card – merge after a positive acceptance, close after the merge"],
de: ["Factory: Merge- und Schließen-Knopf auf der Issue-Karte – Merge nach erfolgreicher Abnahme, Schließen nach dem Merge"],
},
"202611-00073": {
en: ["Factory test runner: caches between acceptance runs (npm, Cargo, pip, Go and optional seeds of the install step) – the test environment starts much faster"],
de: ["Factory-Test-Runner: Caches zwischen Abnahmeläufen (npm, Cargo, pip, Go und optionale Seeds des Install-Schritts) – die Testumgebung startet deutlich schneller"],
},
"202611-00072": {
en: ["Factory: a blinking blue lamp shows that a phase is being prepared (checkout, test environment) before its chat starts"],
de: ["Factory: eine blinkende blaue Lampe zeigt, dass eine Phase vorbereitet wird (Checkout, Testumgebung), bevor der Chat startet"],
},
"202611-00071": {
en: ["Unsent messages are saved per chat and can be continued on another device (web and terminal client)", "Factory: main switch (green running, yellow stopping, red stopped) with a soft stop – running agents finish", "Factory: chats open in an overlay on the desktop; every issue card has an open-chat button; the overview uses the full width"],
de: ["Ungesendete Nachrichten werden pro Chat gespeichert und lassen sich auf einem anderen Gerät fortsetzen (Web und Terminal-Client)", "Factory: Hauptschalter (grün läuft, gelb stoppt, rot gestoppt) mit sanftem Stopp – laufende Agenten werden fertig", "Factory: Chats öffnen auf dem Desktop in einem Overlay; jede Issue-Karte hat einen Chat-Knopf; die Übersicht nutzt die volle Breite"],