Factory: spec chat writes setup.json, filed as .factory/setup.json

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Sonnet 5.5 committed 2026-11-16 09:03:46 +01:00
1 parent 1897dd1e0a
commit 962d37e485
7 files changed
+49 -6

No files matched your search

+8
View File
@@ -3,6 +3,14 @@
All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/);
until 1.0, minor versions may contain breaking changes.
## [Unreleased]
### Added
- The factory spec chat now also writes `setup.json` (how to install and start the app). Creating the
project files it as `.factory/setup.json` in the repository, where the acceptance phase reads it; the
create dialog warns when it is missing.
## [v202611-00043] – 2026-11-16
### Added
+4 -2
View File
@@ -2735,7 +2735,8 @@ async fn factory_draft(Extension(user): Extension<User>, State(app): State<AppSt
let spec = std::fs::read_to_string(dir.join("spec.md")).unwrap_or_default();
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let conns: Vec<Value> = s.connections.iter().map(|c| json!({"id": c.id, "name": c.name, "kind": c.kind, "owner": c.owner})).collect();
Ok(Json(json!({"spec": spec, "proposal": crate::factory::proposal(&app, &id), "connections": conns})))
let setup = std::fs::read_to_string(dir.join("setup.json")).ok().filter(|t| crate::factory::valid_setup(t));
Ok(Json(json!({"spec": spec, "setup": setup, "proposal": crate::factory::proposal(&app, &id), "connections": conns})))
}
#[derive(Deserialize)]
@@ -2754,7 +2755,8 @@ async fn factory_create_project(Extension(user): Extension<User>, State(app): St
let (_, dir) = draft_session(&app, &user, &id)?;
let spec = std::fs::read_to_string(dir.join("spec.md")).unwrap_or_default();
let mut s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let res = crate::factory::create_project(&app, &user, &mut s, &spec, &b.connection, &b.name, &b.slug, &b.description, &b.owner).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
let setup = std::fs::read_to_string(dir.join("setup.json")).unwrap_or_default();
let res = crate::factory::create_project(&app, &user, &mut s, &spec, &setup, &b.connection, &b.name, &b.slug, &b.description, &b.owner).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
app.store.set_user_setting(&user.id, "factory", &s)?;
app.audit(Some(&user), "factory.project.create", res["repo"].as_str().unwrap_or(""), &crate::auth::client_ip(&headers));
Ok(Json(res))
+29 -4
View File
@@ -1188,7 +1188,10 @@ How to work:
2. Keep the spec in the file `spec.md` in your working directory and update it as the conversation moves on. Structure: Goal · Users · Features (numbered, each with acceptance criteria that can be checked by looking at the running app) · Non-functional requirements · Tech stack · Out of scope · Open questions.
3. Be concrete: exact texts, limits, behaviour on errors. Point out contradictions and gaps instead of guessing.
4. Do not build the software and do not touch other files. Do not create repositories yourself.
5. When the user says the spec is done, propose a short project name and a repository slug (lowercase, digits and dashes) and end your message with exactly one fenced json block and nothing after it:
5. Also keep the file `setup.json` in your working directory: it tells the acceptance stage how to start the finished app, so the app can be checked by looking at it. Once the tech stack is settled write it, and update it when the stack changes. Format (one JSON object, all values strings, no comments):
`{"install": "optional one-off setup command, e.g. npm ci", "start": "command that runs the app in the foreground", "url": "where it listens, e.g. http://localhost:8080"}`
Ask the user for the port and commands if the spec leaves them open. A static site may use e.g. `"start": "python3 -m http.server 8080"`. Without a start command acceptance has to guess, so do not skip this file for anything that runs.
6. When the user says the spec is done, propose a short project name and a repository slug (lowercase, digits and dashes) and end your message with exactly one fenced json block and nothing after it:
```json
{"decision": "ready", "name": "Project name", "slug": "project-name", "description": "one sentence"}
```
@@ -1269,9 +1272,14 @@ pub fn slugify(s: &str) -> String {
out.trim_end_matches('-').chars().take(60).collect::<String>().trim_end_matches('-').to_string()
}
/// Is this a usable `.factory/setup.json`: a JSON object with a non-empty `start` command?
pub fn valid_setup(text: &str) -> bool {
serde_json::from_str::<Value>(text).ok().is_some_and(|v| v["start"].as_str().is_some_and(|s| !s.trim().is_empty()))
}
/// Create the repository, file README and spec, register the repository and open the issue
/// that starts the workflow. Safe to repeat after a failure: an empty repository is reused.
pub async fn create_project(app: &Arc<App>, user: &User, settings: &mut FactorySettings, spec: &str, connection: &str, name: &str, slug: &str, description: &str, owner: &str) -> Result<Value> {
pub async fn create_project(app: &Arc<App>, user: &User, settings: &mut FactorySettings, spec: &str, setup: &str, connection: &str, name: &str, slug: &str, description: &str, owner: &str) -> Result<Value> {
let slug = slugify(slug);
if slug.len() < 2 {
bail!("the repository name is too short");
@@ -1308,7 +1316,14 @@ pub async fn create_project(app: &Arc<App>, user: &User, settings: &mut FactoryS
let id: crate::gitcreds::GitSettings = app.store.user_setting(&user.id, "git").unwrap_or_default();
let (who, mail) = (Some(id.name.trim()).filter(|n| !n.is_empty()).unwrap_or("CodeCraft Factory").to_string(), Some(id.email.trim()).filter(|n| !n.is_empty()).unwrap_or("factory@codecraft.local").to_string());
git(&resolved, &dir, &["checkout", "-B", "main"]).await?;
git(&resolved, &dir, &["add", "README.md", "docs"]).await?;
let mut add = vec!["add", "README.md", "docs"];
let setup_filed = valid_setup(setup);
if setup_filed {
std::fs::create_dir_all(dir.join(".factory"))?;
std::fs::write(dir.join(".factory/setup.json"), setup)?;
add.push(".factory");
}
git(&resolved, &dir, &add).await?;
git(&resolved, &dir, &["-c", &format!("user.name={who}"), "-c", &format!("user.email={mail}"), "commit", "-m", &format!("Add specification for {name}")]).await?;
git(&resolved, &dir, &["push", "-u", "origin", "main"]).await?;
@@ -1318,7 +1333,7 @@ pub async fn create_project(app: &Arc<App>, user: &User, settings: &mut FactoryS
let issue = g.create_issue(name, &format!("{}\n\nSpec: {spec_path}", description.trim()), &[cfg.label.clone()]).await?;
let n = issue_no(&issue);
app.store.factory_issue_add(&cfg.url, n, &user.id, name, &login)?;
Ok(json!({"url": cfg.url, "repo": created["full_name"], "issue": n, "issue_url": issue["html_url"], "spec": spec_path}))
Ok(json!({"url": cfg.url, "repo": created["full_name"], "issue": n, "issue_url": issue["html_url"], "spec": spec_path, "setup": setup_filed}))
}
#[cfg(test)]
@@ -1447,6 +1462,16 @@ mod tests {
assert!(SPEC_INSTRUCTIONS.contains("\"decision\": \"ready\""));
}
#[test]
fn setup_json_needs_a_start_command() {
assert!(valid_setup(r#"{"start": "npm start", "url": "http://localhost:3000"}"#));
assert!(!valid_setup(r#"{"start": " "}"#));
assert!(!valid_setup(r#"{"url": "x"}"#));
assert!(!valid_setup("not json"));
assert!(!valid_setup(""));
assert!(SPEC_INSTRUCTIONS.contains("setup.json"));
}
#[test]
fn encodes_labels() {
assert_eq!(urlenc("factory:qa"), "factory%3Aqa");
+2
View File
@@ -8,6 +8,7 @@ import { Spinner } from "./Activity";
interface Draft {
spec: string;
setup?: string | null;
proposal: { name?: string; slug?: string; description?: string } | null;
connections: { id: string; name: string; kind: string; owner: string }[];
}
@@ -112,6 +113,7 @@ function CreateProjectDialog({ sessionId, onClose }: { sessionId: string; onClos
) : (
<>
{!draft.spec.trim() && <div className="notice err">{t("draft.noSpec")}</div>}
{draft.spec.trim() && !draft.setup && <div className="notice">{t("draft.noSetup")}</div>}
<div className="factory-form">
<label>
<span>{t("draft.name")}</span>
+1
View File
@@ -1271,6 +1271,7 @@ export const de: Messages = {
"draft.owner": "Besitzer",
"draft.ownerPlaceholder": "leer = dein eigenes Konto",
"draft.private": "Das Repository wird privat angelegt. Die Spec wird als docs/specs/<name>.md committet und ein Issue startet den Workflow.",
"draft.noSetup": "Noch keine setup.json – bitte das Modell sie schreiben lassen, sonst muss die Abnahme raten, wie die App startet.",
"draft.specPreview": "Spec anzeigen",
"draft.noSpec": "In diesem Chat gibt es noch keine spec.md – lass sie zuerst vom Modell schreiben.",
"draft.noConnection": "Richte zuerst eine Verbindung (Gitea, GitHub oder GitLab) ein:",
+1
View File
@@ -1270,6 +1270,7 @@ export const en = {
"draft.owner": "Owner",
"draft.ownerPlaceholder": "empty = your own account",
"draft.private": "The repository is created private. The spec is committed as docs/specs/<name>.md and an issue starts the workflow.",
"draft.noSetup": "No setup.json yet – ask the model to write it, otherwise the acceptance has to guess how to start the app.",
"draft.specPreview": "Show spec",
"draft.noSpec": "There is no spec.md in this chat yet – let the model write it first.",
"draft.noConnection": "Set up a connection (Gitea, GitHub or GitLab) first:",
+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: the spec chat writes setup.json so the acceptance knows how to start the app"],
de: ["Factory: der Spec-Chat schreibt setup.json, damit die Abnahme weiß, wie die App startet"],
},
"202611-00043": {
en: ["Factory: approved issues are built automatically on their own branch and end as a pull request", "Factory acceptance: another model starts the app and checks the scenarios, with up to 2 rework rounds", "Factory: restart a failed or rejected issue at review, build or acceptance"],
de: ["Factory: freigegebene Issues werden automatisch auf einem eigenen Branch gebaut und enden als Pull Request", "Factory-Abnahme: ein anderes Modell startet die App und prüft die Szenarien, bis zu 2 Nachbesserungsrunden", "Factory: fehlgeschlagene oder abgelehnte Issues bei Review, Build oder Abnahme neu starten"],