Compare commits

...
Author SHA1 Message Date
Richard Zink a9a98a25e7 Release v202611-00049 2026-11-16 12:44:35 +01:00
Richard ZinkandClaude Sonnet 5.5 cb1e31b6e9 Factory: versions and tags, releases, retry settings, pull of the default branch
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 12:44:35 +01:00
Richard Zink 06c1b8df1b Release v202611-00048 2026-11-16 11:42:11 +01:00
Richard ZinkandClaude Sonnet 5.5 af89b91e01 Fix blank factory page: hooks above early returns
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 11:42:11 +01:00
Richard Zink 5ebdfee1a8 Release v202611-00047 2026-11-16 11:31:37 +01:00
Richard ZinkandClaude Sonnet 5.5 56c20d92f8 Factory: show and merge pull requests, issue chats (plan features, cut milestones)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 11:31:36 +01:00
Richard Zink a0a4082383 Release v202611-00046 2026-11-16 10:57:04 +01:00
Richard ZinkandClaude Sonnet 5.5 e0c550f14d Factory: acceptance opens the pull request, out_of_scope results, factory icon and chat folder
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 10:57:03 +01:00
Richard Zink 4612643081 Release v202611-00045 2026-11-16 09:26:12 +01:00
Richard ZinkandClaude Sonnet 5.5 78c4eeaa28 Factory: acceptance judges only listed scenarios, issue scope, setup.json fallback
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 09:26:11 +01:00
Richard Zink ef60b68a32 Release v202611-00044 2026-11-16 09:03:46 +01:00
Richard ZinkandClaude Sonnet 5.5 962d37e485 Factory: spec chat writes setup.json, filed as .factory/setup.json
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 09:03:46 +01:00
Richard Zink 1897dd1e0a Release v202611-00043 2026-11-16 08:51:49 +01:00
Richard ZinkandClaude Sonnet 5.5 e09e295f60 Factory acceptance phase and issue restart
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 08:51:48 +01:00
Richard Zink 3f39f4bd65 Release v202611-00042 2026-11-16 08:29:23 +01:00
Richard ZinkandClaude Sonnet 5.5 1772c8cd07 Factory build phase: worktree per issue, server-side commit/push/PR
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 08:29:23 +01:00
Richard Zink c551171c18 Release v202611-00041 2026-11-15 22:19:56 +01:00
Richard ZinkandClaude Sonnet 5.5 4000084560 Software factory (review phase): per-user Gitea/GitHub/GitLab connections, spec chat, project creation, factory page
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 22:19:45 +01:00
Richard Zink b5e2ef146c Release v202611-00040 2026-11-15 15:09:13 +01:00
Richard ZinkandClaude Sonnet 5.5 a2b9528e0b Fix uploaded images reaching Claude Code empty
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 15:09:11 +01:00
Richard Zink 81d9df4e6e Release v202611-00039 2026-11-15 14:59:12 +01:00
Richard ZinkandClaude Sonnet 5.5 ead75e78e0 Neutral chat background for colour tags; answer Claude Code's AskUserQuestion with the question card
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 14:59:10 +01:00
Richard Zink 77f9d4b0e0 Release v202611-00038 2026-11-15 14:37:31 +01:00
Richard ZinkandClaude Sonnet 5.5 103132a359 Sidebar chat menu: add Delete, remove colour and icon pickers
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 14:37:29 +01:00
Richard Zink 5d5c0f8124 Release v202611-00037 2026-11-15 13:53:13 +01:00
Richard ZinkandClaude Sonnet 5.5 f77b101847 Ask about the chat's own folder when deleting a chat
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 13:53:10 +01:00
Richard Zink 12a3198e77 Release v202611-00036 2026-11-15 13:04:03 +01:00
Richard ZinkandClaude Sonnet 5.5 4e6f74d477 Offer all CodeCraft tools to the Claude Code CLI over an MCP bridge
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 13:04:00 +01:00
Richard Zink 658148ada7 Release v202611-00035 2026-11-15 12:33:26 +01:00
Richard ZinkandClaude Sonnet 5.5 b6e4500233 Fix SSH key creation as a uid without passwd entry (ssh-keygen, ssh-keyscan, ssh-add wrappers)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 12:33:24 +01:00
Richard Zink 126c7719b9 Release v202611-00034 2026-11-15 12:15:04 +01:00
Richard ZinkandClaude Sonnet 5.5 fccaee4b94 Fix ssh/scp/sftp for containers running as a uid without passwd entry
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 12:15:02 +01:00
Richard Zink d58b23d35f Release v202611-00033 2026-11-15 11:47:34 +01:00
Richard ZinkandClaude Sonnet 5.5 6e8e739906 SSH keys in account settings; wrappers for agents, terminal and git
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 11:47:31 +01:00
37 changed files with 6294 additions and 43 deletions

No files matched your search

+3
View File
@@ -9,6 +9,9 @@ CODECRAFT_ADMIN_PASSWORD=
# Directory with your projects, mounted as /workspace.
WORKSPACE=/path/to/your/projects
# Directory of the software factory (clones it works in), mounted as /factory.
FACTORY_DIR=./factory
# Host port and address (127.0.0.1 = only reachable through a local reverse proxy).
PORT=8787
BIND_ADDR=127.0.0.1
+206
View File
@@ -3,6 +3,212 @@
All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/);
until 1.0, minor versions may contain breaking changes.
## [v202611-00049] – 2026-11-16
### Added
- **Factory versions and tags.** Every merged factory issue (merged through the factory or on the forge)
gets a version: the patch number goes up with each issue (0.1.0 → 0.1.1); the issue that completes a
milestone (the last open `M1.x` issue) raises the minor number and restarts the patch (0.0.7 → 0.1.0).
The factory commits a `VERSION` file on the default branch, tags the commit `vX.Y.Z`, closes the issue
and notes the version in it. The version shows on the repository tile. Versioning starts with the next
merged issue; issues that were done before are not counted.
- **Factory release (0.x → 1.0.0 and on).** The new "Release" button makes a release you choose the
version of: `VERSION`, tag, the Docker image for amd64 and arm64 (buildx, pushed to the registry of the
image name), the source zip and further files, and the release on the forge (Gitea and GitHub attach the
files; GitLab gets the release without attachments). How to build is described in
`.factory/release.json` in the repository (`image`, `platforms`, `dockerfile`, `context`,
`build_args`, `commands`, `files`, `name`); without it only tag, release and source zip are made. The
dialog shows the recipe first, because its commands run on the server outside the sandbox.
- The image now contains the buildx plugin.
- **The factory's checkout of the default branch is pulled** (fast-forward) after every fetch, and right after
a merge is detected and the version commit is pushed – before, the review read the files of the first clone.
Local changes or a diverged branch are left alone with a warning.
- **Settings for repetitions** per repository: *Rework rounds* (how often a failed acceptance sends the
issue back to the build, default 2, 0 = never) and *Tries* per phase (how often a phase is repeated after
a technical failure such as a timeout, default 2).
## [v202611-00048] – 2026-11-16
### Fixed
- The factory page showed a blank page since v202611-00047 (the new pull request panel declared its state
after an early return, which breaks React's hook order). The hooks now sit above the early returns.
## [v202611-00047] – 2026-11-16
### Added
- **Factory: show and approve pull requests.** Selecting an issue shows its open pull request (state,
conflicts, files, +/− lines, link) with "Approve and merge" (merge commit, squash or rebase). Merging only
happens on your click after a confirmation; the factory itself still never merges.
- **Factory: plan with a model and file the issues.** "Plan a feature" starts a chat that works out a new
feature with you; "Cut a milestone" lets a model cut a milestone of the spec into numbered deliverables
("M2.1 – …"). The chat reads the repository and ends with an issue list; a dialog lets you tick and edit
the issues, which are then created on the forge with `Spec:` and `Scope:` lines and the prerequisites.
They get the factory label only if you ask for it, so you can start them one after the other.
### Fixed
- An accepted rework build now gets a new pull request when the earlier one was merged or closed already;
before, the commits of the rework rounds stayed on the branch without any pull request.
## [v202611-00046] – 2026-11-16
### Changed
- **Factory: the pull request is opened by the acceptance**, not by the build. A build only pushes its
branch `factory/issue-<n>`; once the acceptance passes, the pull request is created with the build
report and the result table (an existing one is kept).
- The factory has its own icon (a factory instead of a toolbox).
- All factory chats (spec chats, review, build, acceptance) are collected in one sidebar folder
"Factory"; existing ones are moved there on start.
### Fixed
- Factory acceptance: scenarios outside the scope of the issue (stored scenarios that cover a whole
multi-milestone spec) get the result `out_of_scope` and no longer fail the issue. The acceptance
receives the build report to tell what the build claims to cover, and an acceptance in which no
scenario of the scope could be observed working does not pass.
## [v202611-00045] – 2026-11-16
### Fixed
- Factory acceptance: when the built branch has no `.factory/setup.json` (it was added to the default
branch later), the one from the default branch is used.
- Factory acceptance judged things outside the issue (e.g. later milestones of a large spec) and failed
the issue for them. Now only the listed scenarios count: the verdict follows the scenario results
(one failed scenario fails, unverified or out-of-scope gaps do not), and the prompts of review, build
and acceptance restrict the work to the issue's scope. An issue can name it with a `Scope: <name>`
line (e.g. `Scope: M1`); without one the review picks the first milestone that is not built yet.
## [v202611-00044] – 2026-11-16
### 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
- **Factory acceptance phase**: a finished build is checked by a different model. It starts the built
branch (as `.factory/setup.json` describes: `install`, `start`, `url`), goes through the acceptance
scenarios from the review – kept away from the builder – and uses the browser tool where it can.
Every scenario ends as pass, fail or *unverified*; unverified ones are reported openly and never
count as passed. One failed scenario sends the issue back to the build with the findings (at most
2 rework rounds, then `failed`); otherwise the issue is `done` and the pull request waits for you
to merge – the factory never merges.
- **Restart an issue** in the factory page (select an issue → "Restart at": review, build or
acceptance). Works for failed, rejected, done and waiting issues; restarting at review forgets the
stored scenarios, and restarts reset the retry counters.
### Fixed
- Factory runs interrupted by a server restart continue where they were (builds in a rework round
resume as rework).
## [v202611-00042] – 2026-11-16
### Added
- **Factory build phase**: approved issues are built automatically. The build agent works in its own git
worktree on branch `factory/issue-<n>` (inside the factory area, never in the workspace), with the
model chosen for the build phase. The server – not the agent – commits, pushes and opens the pull
request; the spec file is restored if the agent touched it. A build that makes no changes, times out or
returns no result is retried once, then marked `failed`; a `blocked` answer is reported on the issue.
Finished builds move to `factory:qa` (acceptance follows in a later version).
## [v202611-00041] – 2026-11-15
### Added
- **Software factory** (sidebar → Factory): specs arrive as issues (label `factory`) on Gitea, GitHub or
GitLab and are worked off by agents in phases, each phase with its own model, agent, permission mode
and time limit. This version contains the **review phase**: an agent reads the spec and the code and
decides *approved*, *questions* (posted as an issue comment; your answer restarts the review) or
*rejected*, and writes acceptance scenarios that stay in the database, away from the builder. Build and
acceptance follow.
- **Connections per user**: every user sets up their own accounts (Gitea, GitHub, GitLab) with their own
token; repositories use the token of their connection or one of their own. Models are free per user,
project and phase.
- **New project with a model**: *Factory → New project* opens a spec chat. When the spec is done, the
*Create project* bar picks name, connection and owner, creates the repository (private), commits the
spec as `docs/specs/<name>.md` and opens the issue that starts the workflow.
- **Overview**: board with all issues by state, a tile per project, and per run the model, status,
duration, tokens and cost, with a link into the chat of that run.
- **Separate factory area**: repositories are cloned into their own mount `/factory` (`FACTORY_DIR` in
`.env`), not into the workspace. The API token is handed to git only as a header and never reaches
agents.
## [v202611-00040] – 2026-11-15
### Fixed
- **Images you upload reach Claude Code**: its chats read the history without the image bytes, so the
files it was pointed to were empty. Images without data are no longer written as empty files.
## [v202611-00039] – 2026-11-15
### Changed
- A chat's colour no longer tints the chat background (pane, message field, agent bubbles, top bar
fill); it still marks the top bar line, the list entry, the badge and your own bubbles.
### Fixed
- **Claude Code can ask questions again**: its `AskUserQuestion` was always rejected; now the question
appears as a question card in the chat (single and multiple choice) and the answers go back to it.
## [v202611-00038] – 2026-11-15
### Changed
- The chat menu in the sidebar has a **Delete** entry (with the question about the chat's own folder);
colour and icon selection moved out of it – they remain in the ⋯ menu inside the chat.
## [v202611-00037] – 2026-11-15
### Added
- **Deleting a chat asks about its folder**: if the chat has a folder of its own (inside your folders,
not shared with any other chat, no project folder), you can delete it with the chat – with the
number of files, size and a warning for git repositories. The server checks again before deleting.
## [v202611-00036] – 2026-11-15
### Added
- **Claude Code gets all CodeCraft tools** (image generation, 3D, OpenSCAD, browser, scheduling,
diagnostics, reverse engineering, skills, ask_user, the server's MCP tools …) over an MCP bridge,
as `mcp__codecraft__<name>`. Tools the CLI has itself (read, write, edit, bash, grep …) are not
offered twice. Calls go through the usual approval cards and rules.
## [v202611-00035] – 2026-11-15
### Fixed
- Creating an SSH key failed with "No user exists for uid 99": `ssh-keygen`, `ssh-keyscan` and
`ssh-add` get the same passwd workaround as `ssh`.
## [v202611-00034] – 2026-11-15
### Fixed
- `ssh`, `scp` and `sftp` failed with "No user exists for uid 99" because the container runs as a uid
without passwd entry; the image now wraps them with nss_wrapper (also used by the key wrappers).
## [v202611-00033] – 2026-11-15
### Added
- **SSH keys** (Settings → Account): generate (ed25519) or import keys; agents, the terminal and the
git panel use them automatically for `ssh`, `scp`, `sftp`, `rsync` and git over ssh. Hosts are
trusted on first contact; the public key can be copied for the server's `authorized_keys`.
## [v202611-00032] – 2026-11-15
### Fixed
+13 -1
View File
@@ -74,6 +74,10 @@ ARG DOCKER_VERSION=29.9.3
RUN case "$TARGETARCH" in amd64) arch=x86_64 ;; arm64) arch=aarch64 ;; *) echo "unsupported $TARGETARCH" >&2; exit 1 ;; esac \
&& curl -fsSL "https://download.docker.com/linux/static/stable/$arch/docker-$DOCKER_VERSION.tgz" | tar -xz -C /tmp docker/docker \
&& install -m 0755 /tmp/docker/docker /docker
# buildx plugin: the factory builds multi-arch release images with it (own builder on the host daemon).
ARG BUILDX_VERSION=v0.19.3
RUN curl -fsSL -o /docker-buildx "https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-${TARGETARCH}" \
&& chmod 0755 /docker-buildx
# --- runtime ------------------------------------------------------------------
# Node is included so agents can work on JS projects and run npx-based MCP servers.
@@ -85,7 +89,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential pkg-config libssl-dev cmake zlib1g-dev binutils-multiarch \
chromium fonts-dejavu-core fonts-noto-color-emoji poppler-utils openmpt123 \
openscad xvfb xauth \
openssh-client rsync mc \
openssh-client libnss-wrapper rsync mc \
&& rm -rf /var/lib/apt/lists/*
# Language servers for diagnostics after edits (rust-analyzer/gopls/clangd can be
# installed by agents: rustup component add rust-analyzer, go install …).
@@ -95,9 +99,17 @@ COPY --from=web /web/dist /app/web
COPY --from=cli /out /app/cli
# Used with a mounted /var/run/docker.sock (see docs/MOVING.md, --docker-sock).
COPY --from=dockercli /docker /usr/local/bin/docker
COPY --from=dockercli /docker-buildx /usr/local/lib/docker/cli-plugins/docker-buildx
COPY server/ghidra /app/ghidra
# git for agent shells: commits get the co-author trailer of the model (server.commit_trailer).
COPY --chmod=755 docker/git-coauthor /usr/local/lib/codecraft/bin/git
# ssh, scp, sftp and the ssh-* tools (the server creates keys with ssh-keygen) also work when the container runs as a uid without passwd entry.
COPY --chmod=755 docker/ssh-nss /usr/local/bin/ssh
COPY --chmod=755 docker/ssh-nss /usr/local/bin/scp
COPY --chmod=755 docker/ssh-nss /usr/local/bin/sftp
COPY --chmod=755 docker/ssh-nss /usr/local/bin/ssh-keygen
COPY --chmod=755 docker/ssh-nss /usr/local/bin/ssh-keyscan
COPY --chmod=755 docker/ssh-nss /usr/local/bin/ssh-add
COPY server/resources /app/resources
# The agent's home lives on the data volume: tools it installs in user space
# (pip --user, pipx, rustup, npm -g, downloaded binaries) survive rebuilds.
+1 -1
View File
@@ -11,7 +11,7 @@
</p>
<p align="center">
<img alt="Version v202611-00032" src="https://img.shields.io/badge/version-v202611--00032-d69e2e?style=flat-square">
<img alt="Version v202611-00049" src="https://img.shields.io/badge/version-v202611--00049-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">
+2
View File
@@ -34,6 +34,8 @@ services:
- codecraft-data:/data
# The projects the agents may work on.
- ${WORKSPACE:-./workspace}:/workspace
# Separate area for the software factory (clones of the watched repositories).
- ${FACTORY_DIR:-./factory}:/factory
# Reach self-hosted models (Ollama, vLLM, ...) on the host.
extra_hosts:
- "host.docker.internal:host-gateway"
+2
View File
@@ -30,6 +30,8 @@ services:
- codecraft-data:/data
# The projects the agents may work on.
- ${WORKSPACE:-./workspace}:/workspace
# Separate area for the software factory (clones of the watched repositories).
- ${FACTORY_DIR:-./factory}:/factory
# Reach self-hosted models (Ollama, vLLM, ...) on the host.
extra_hosts:
- "host.docker.internal:host-gateway"
Executable
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
# ssh, scp and sftp for containers that run as an arbitrary uid (docker-compose `user:`):
# OpenSSH refuses to start without a passwd entry for the uid ("No user exists for uid N").
# Without an entry, nss_wrapper provides one for this process; otherwise nothing changes.
if ! getent passwd "$(id -u)" >/dev/null 2>&1; then
d=${TMPDIR:-/tmp}/codecraft-nss-$(id -u)
mkdir -p "$d" 2>/dev/null
printf 'codecraft:x:%s:%s:CodeCraft:%s:/bin/sh\n' "$(id -u)" "$(id -g)" "${HOME:-/}" > "$d/passwd"
printf 'codecraft:x:%s:\n' "$(id -g)" > "$d/group"
export NSS_WRAPPER_PASSWD="$d/passwd" NSS_WRAPPER_GROUP="$d/group"
export LD_PRELOAD="libnss_wrapper.so${LD_PRELOAD:+:$LD_PRELOAD}"
fi
exec "/usr/bin/$(basename "$0")" "$@"
+480 -3
View File
@@ -86,6 +86,7 @@ pub fn router(app: AppState) -> Router {
.route("/sessions/{id}/search", get(search_in_session))
.route("/sessions/{id}/media", get(session_media))
.route("/sessions/{id}", get(get_session).patch(update_session).delete(delete_session))
.route("/sessions/{id}/folder", get(session_folder))
.route("/sessions/{id}/prompt", post(prompt))
.route("/sessions/{id}/abort", post(abort))
.route("/sessions/{id}/compact", post(compact))
@@ -103,6 +104,7 @@ pub fn router(app: AppState) -> Router {
.route("/sessions/{id}/links", get(list_links).post(create_link))
.route("/sessions/{id}/links/{token}", delete(delete_link))
.route("/public/chat/{token}", get(public_chat))
.route("/mcp-bridge/{token}", post(crate::mcp_bridge::handle))
.route("/sessions/{id}/shares", get(get_shares).put(put_shares))
.route("/sessions/{id}/queue", get(get_queue))
.route("/sessions/{id}/queue/flush", post(flush_queue))
@@ -157,6 +159,24 @@ pub fn router(app: AppState) -> Router {
.route("/images/{id}", delete(delete_image))
.route("/images/{id}/file", get(image_file))
.route("/account/git", get(get_git_settings).put(put_git_settings))
.route("/account/factory", get(get_factory).put(put_factory))
.route("/account/factory/test", post(test_factory))
.route("/factory/overview", get(factory_overview))
.route("/factory/poll", post(factory_poll))
.route("/factory/issues/restart", post(factory_restart))
.route("/factory/issue-chats", post(factory_new_issue_chat))
.route("/factory/issue-chats/{id}", get(factory_issue_chat))
.route("/factory/issue-chats/{id}/create", post(factory_create_issues))
.route("/factory/release/preview", get(factory_release_preview))
.route("/factory/release", post(factory_release))
.route("/factory/issues/pr", get(factory_pr))
.route("/factory/issues/pr/merge", post(factory_pr_merge))
.route("/account/factory/connection/test", post(test_factory_connection))
.route("/factory/drafts", post(factory_new_draft))
.route("/factory/drafts/{id}", get(factory_draft))
.route("/factory/drafts/{id}/create", post(factory_create_project))
.route("/account/ssh", get(get_ssh_keys).post(add_ssh_key))
.route("/account/ssh/{id}", delete(delete_ssh_key))
.route("/account/snippets", get(crate::cli_api::get_snippets).put(crate::cli_api::put_snippets))
.route("/account/prefs", get(crate::cli_api::get_prefs).put(crate::cli_api::put_prefs))
.route("/account/sidebar", get(crate::cli_api::get_sidebar).put(crate::cli_api::put_sidebar))
@@ -1053,8 +1073,83 @@ async fn put_file_tabs(Extension(user): Extension<User>, State(app): State<AppSt
Ok(Json(json!({"ok": true})))
}
async fn delete_session(Extension(user): Extension<User>, State(app): State<AppState>, Path(id): Path<String>) -> ApiResult {
writable(&app, &user, &id)?;
/// The folder a chat owns: inside the owner's folders (never one of them), not a link, and no
/// other chat works in it, below it or above it (then it belongs to a project, not to this chat).
/// Returns the folder and the titles of chats that prevent it.
fn own_folder(app: &App, session: &Session) -> (Option<PathBuf>, Vec<String>) {
let Ok(dir) = std::fs::canonicalize(&session.cwd) else { return (None, vec![]) };
if std::fs::symlink_metadata(&session.cwd).map(|m| m.file_type().is_symlink()).unwrap_or(true) || !dir.is_dir() {
return (None, vec![]);
}
let roots: Vec<PathBuf> = app.user_roots(session.owner_id.as_deref()).iter().filter_map(|r| std::fs::canonicalize(r).ok()).collect();
if !roots.iter().any(|r| dir.starts_with(r) && dir != *r) {
return (None, vec![]);
}
let mut blockers = Vec::new();
for (title, cwd) in app.store.other_session_cwds(&session.id).unwrap_or_default() {
let Ok(other) = std::fs::canonicalize(&cwd) else { continue };
if other.starts_with(&dir) || dir.starts_with(&other) {
blockers.push(if title.is_empty() { "(untitled)".to_string() } else { title });
}
}
if blockers.is_empty() { (Some(dir), blockers) } else { (None, blockers) }
}
/// Facts for the delete dialog: does the chat have a folder of its own, and what is in it?
async fn session_folder(Extension(user): Extension<User>, State(app): State<AppState>, Path(id): Path<String>) -> ApiResult {
let session = writable(&app, &user, &id)?;
let (dir, blockers) = own_folder(&app, &session);
let Some(dir) = dir else { return Ok(Json(json!({"own": false, "shared_with": blockers}))) };
let (files, bytes, git, truncated) = tokio::task::spawn_blocking({
let dir = dir.clone();
move || {
let (mut files, mut bytes, mut seen) = (0u64, 0u64, 0u64);
let mut stack = vec![dir.clone()];
let mut truncated = false;
while let Some(d) = stack.pop() {
let Ok(rd) = std::fs::read_dir(&d) else { continue };
for e in rd.flatten() {
// Git's own files are not "the chat's files".
if e.file_name() == ".git" {
continue;
}
seen += 1;
if seen > 50_000 {
truncated = true;
stack.clear();
break;
}
let Ok(m) = e.metadata() else { continue };
if m.is_dir() && !e.file_type().map(|t| t.is_symlink()).unwrap_or(true) {
stack.push(e.path());
} else if m.is_file() {
files += 1;
bytes += m.len();
}
}
}
(files, bytes, dir.join(".git").exists(), truncated)
}
})
.await
.unwrap_or((0, 0, false, false));
Ok(Json(json!({"own": true, "path": dir, "files": files, "bytes": bytes, "git": git, "truncated": truncated})))
}
#[derive(Deserialize)]
struct DeleteQ {
/// Also delete the chat's own folder (only if it really is one – checked again here).
#[serde(default)]
delete_folder: bool,
}
async fn delete_session(Extension(user): Extension<User>, State(app): State<AppState>, Path(id): Path<String>, Query(q): Query<DeleteQ>) -> ApiResult {
let session = writable(&app, &user, &id)?;
// Decide about the folder while the chat and all the others still exist.
let folder = if q.delete_folder { own_folder(&app, &session).0 } else { None };
if q.delete_folder && folder.is_none() {
return Err(ApiError(StatusCode::CONFLICT, "this chat has no folder of its own (other chats use it, or it is a project folder)".into()));
}
// Notify before deleting: visibility is checked against the stored session.
app.emit(Event::SessionDeleted { session_id: id.clone() });
runner::abort(&app, &id);
@@ -1068,7 +1163,20 @@ async fn delete_session(Extension(user): Extension<User>, State(app): State<AppS
tracing::warn!("image cleanup: {e:#}");
}
});
Ok(Json(json!({"ok": true})))
let mut folder_error = None;
let mut folder_deleted = false;
if let Some(dir) = folder {
let shown = dir.display().to_string();
match tokio::task::spawn_blocking(move || std::fs::remove_dir_all(&dir)).await {
Ok(Ok(())) => {
folder_deleted = true;
app.audit(Some(&user), "session.delete_folder", &shown, "");
}
Ok(Err(e)) => folder_error = Some(format!("the chat was deleted, but not its folder: {e}")),
Err(e) => folder_error = Some(format!("the chat was deleted, but not its folder: {e}")),
}
}
Ok(Json(json!({"ok": true, "folder_deleted": folder_deleted, "folder_error": folder_error})))
}
/// An image of a chat message (see blobs.rs). Addressed by the SHA-256 of its bytes,
@@ -2426,6 +2534,57 @@ async fn run_job(Extension(user): Extension<User>, State(app): State<AppState>,
// --- git credentials ---------------------------------------------------------------
// --- SSH keys -----------------------------------------------------------------
async fn get_ssh_keys(Extension(user): Extension<User>, State(app): State<AppState>) -> ApiResult {
let s: crate::sshkeys::SshSettings = app.store.user_setting(&user.id, "ssh")?;
Ok(Json(json!(crate::sshkeys::masked(&s))))
}
#[derive(Deserialize)]
struct NewSshKey {
name: String,
/// An existing private key to import; a new key is generated when missing.
private: Option<String>,
}
async fn add_ssh_key(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<NewSshKey>) -> ApiResult {
let name = b.name.trim().to_string();
if name.is_empty() || name.chars().count() > 60 {
return Err(ApiError(StatusCode::BAD_REQUEST, "give the key a name (up to 60 characters)".into()));
}
let mut s: crate::sshkeys::SshSettings = app.store.user_setting(&user.id, "ssh")?;
if s.keys.len() >= 10 {
return Err(ApiError(StatusCode::BAD_REQUEST, "at most 10 keys".into()));
}
let key = match b.private.as_deref().filter(|p| !p.trim().is_empty()) {
Some(p) => crate::sshkeys::import(&name, p).await,
None => crate::sshkeys::generate(&name).await,
}
.map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
if s.keys.iter().any(|k| k.fingerprint == key.fingerprint && !key.fingerprint.is_empty()) {
return Err(ApiError(StatusCode::CONFLICT, "this key is already stored".into()));
}
s.keys.push(key);
crate::sshkeys::write_files(&app, &user, &s).map_err(|e| ApiError(StatusCode::INTERNAL_SERVER_ERROR, format!("{e:#}")))?;
app.store.set_user_setting(&user.id, "ssh", &s)?;
app.audit(Some(&user), "ssh.key.add", &name, "");
Ok(Json(json!(crate::sshkeys::masked(&s))))
}
async fn delete_ssh_key(Extension(user): Extension<User>, State(app): State<AppState>, Path(id): Path<String>) -> ApiResult {
let mut s: crate::sshkeys::SshSettings = app.store.user_setting(&user.id, "ssh")?;
let before = s.keys.len();
s.keys.retain(|k| k.id != id);
if s.keys.len() == before {
return Err(not_found("key"));
}
crate::sshkeys::write_files(&app, &user, &s).map_err(|e| ApiError(StatusCode::INTERNAL_SERVER_ERROR, format!("{e:#}")))?;
app.store.set_user_setting(&user.id, "ssh", &s)?;
app.audit(Some(&user), "ssh.key.delete", &id, "");
Ok(Json(json!(crate::sshkeys::masked(&s))))
}
async fn get_git_settings(Extension(user): Extension<User>, State(app): State<AppState>) -> ApiResult {
let s: crate::gitcreds::GitSettings = app.store.user_setting(&user.id, "git")?;
Ok(Json(json!(crate::gitcreds::masked(&s))))
@@ -2441,6 +2600,324 @@ async fn put_git_settings(Extension(user): Extension<User>, State(app): State<Ap
Ok(Json(json!(crate::gitcreds::masked(&new))))
}
// --- software factory ---------------------------------------------------------------
async fn get_factory(Extension(user): Extension<User>, State(app): State<AppState>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
Ok(Json(json!(crate::factory::masked(&s))))
}
async fn put_factory(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Json(b): Json<crate::factory::FactorySettings>) -> ApiResult {
let old: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let mut new = crate::factory::merge(&old, b);
for r in &mut new.repos {
r.validate().map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{}: {e:#}", r.url)))?;
}
app.store.set_user_setting(&user.id, "factory", &new)?;
let urls: Vec<&str> = new.repos.iter().map(|r| r.url.as_str()).collect();
app.audit(Some(&user), "factory.settings", urls.join(", "), &crate::auth::client_ip(&headers));
Ok(Json(json!(crate::factory::masked(&new))))
}
#[derive(Deserialize)]
struct FactoryTest {
url: String,
}
/// Check token and repository and create the missing status labels.
async fn test_factory(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<FactoryTest>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let cfg = s.repos.iter().find(|r| r.url == b.url.trim()).map(|r| s.resolve(r)).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "save the repository first".into()))?;
let cfg = &cfg;
let g = crate::factory::Forge::new(cfg).map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
let info = g.check().await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
let created = g.ensure_labels().await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
let dir = crate::factory::checkout(&app, &user, cfg).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
Ok(Json(json!({"ok": true, "info": info, "labels_created": created, "folder": dir.display().to_string()})))
}
/// Everything the factory page shows: repositories, issues with state, runs with tokens/cost.
async fn factory_overview(Extension(user): Extension<User>, State(app): State<AppState>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let repos: Vec<Value> = s.repos.iter().map(|r| json!({"url": r.url, "enabled": r.enabled, "label": r.label, "max_parallel": r.max_parallel, "kind": s.resolve(r).kind, "has_token": !s.resolve(r).token.is_empty(), "models": {"review": r.review.model, "build": r.build.model, "qa": r.qa.model}, "running": app.store.factory_running(&r.url).unwrap_or(0), "version": app.store.factory_version(&r.url).ok().flatten()})).collect();
Ok(Json(json!({
"area": app.factory_dir().is_some(),
"repos": repos,
"issues": app.store.factory_issues(&user.id)?,
"runs": app.store.factory_runs(&user.id, None, None, 300)?,
"releases": app.store.factory_releases(&user.id, 10)?,
})))
}
/// 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")?;
let mut errors = Vec::new();
for cfg in s.repos.iter().filter(|r| r.enabled).map(|r| s.resolve(r)).filter(|r| !r.token.is_empty()) {
if let Err(e) = crate::factory::poll_repo(&app, &user, &cfg).await {
errors.push(format!("{}: {e:#}", cfg.url));
}
}
Ok(Json(json!({"errors": errors})))
}
#[derive(Deserialize)]
struct ReleaseQuery {
repo: String,
}
/// Current version, suggested next major version and the release recipe (.factory/release.json).
async fn factory_release_preview(Extension(user): Extension<User>, State(app): State<AppState>, Query(q): Query<ReleaseQuery>) -> ApiResult {
let cfg = factory_repo_cfg(&app, &user, &q.repo)?;
let v = crate::factory_version::preview(&app, &user, &cfg).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
Ok(Json(v))
}
#[derive(Deserialize)]
struct StartRelease {
repo: String,
version: String,
}
/// Start a release: tag, Docker image, downloads and the release on the forge (runs in the background).
async fn factory_release(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Json(b): Json<StartRelease>) -> ApiResult {
let cfg = factory_repo_cfg(&app, &user, &b.repo)?;
let id = crate::factory_version::start_release(&app, &user, &cfg, b.version.trim()).await.map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
app.audit(Some(&user), "factory.release.start", &format!("{} {}", b.repo, b.version.trim()), &crate::auth::client_ip(&headers));
Ok(Json(json!({"id": id})))
}
#[derive(Deserialize)]
struct NewIssueChat {
repo: String,
/// "feature" or "slice"
mode: String,
#[serde(default)]
topic: String,
#[serde(default)]
model: Option<String>,
}
fn factory_repo_cfg(app: &AppState, user: &User, repo: &str) -> Result<crate::factory::RepoCfg, ApiError> {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
s.repos.iter().find(|r| r.url == repo).map(|r| s.resolve(r)).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "the repository is not configured".into()))
}
/// Start a chat that works out a feature or cuts a milestone into issues.
async fn factory_new_issue_chat(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<NewIssueChat>) -> ApiResult {
if !["feature", "slice"].contains(&b.mode.as_str()) {
return Err(ApiError(StatusCode::BAD_REQUEST, "unknown mode".into()));
}
let cfg = factory_repo_cfg(&app, &user, &b.repo)?;
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let model = b.model.filter(|m| !m.is_empty()).unwrap_or(s.defaults.spec_model.clone());
let session = crate::factory::start_issue_chat(&app, &user, &cfg, &model, &b.mode, &b.topic).await.map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
Ok(Json(json!(session)))
}
fn issue_chat_session(app: &AppState, user: &User, id: &str) -> Result<(String, std::path::PathBuf), ApiError> {
let session = app.session(id).map_err(|_| ApiError(StatusCode::NOT_FOUND, "unknown chat".into()))?;
let dir = crate::factory::issue_chat_of(app, user, &session).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "not an issue chat".into()))?;
let repo = std::fs::read_to_string(dir.join("repo.txt")).unwrap_or_default().trim().to_string();
Ok((repo, dir))
}
/// The issue list the model proposed in its last message.
async fn factory_issue_chat(Extension(user): Extension<User>, State(app): State<AppState>, Path(id): Path<String>) -> ApiResult {
let (repo, _) = issue_chat_session(&app, &user, &id)?;
Ok(Json(json!({"repo": repo, "proposal": crate::factory::issue_proposal(&app, &id)})))
}
#[derive(Deserialize)]
struct CreateIssues {
spec: String,
issues: Vec<Value>,
/// Give the issues the factory label so the workflow starts right away.
#[serde(default)]
start: bool,
}
/// Create the (possibly edited) issues of a proposal on the forge.
async fn factory_create_issues(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Path(id): Path<String>, Json(b): Json<CreateIssues>) -> ApiResult {
let (repo, _) = issue_chat_session(&app, &user, &id)?;
let cfg = factory_repo_cfg(&app, &user, &repo)?;
if b.issues.is_empty() || b.issues.len() > 100 {
return Err(ApiError(StatusCode::BAD_REQUEST, "choose between 1 and 100 issues".into()));
}
let created = crate::factory::create_issues(&cfg, &b.spec, &b.issues, b.start).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
app.audit(Some(&user), "factory.issues.create", &format!("{repo} ({} issues)", created.len()), &crate::auth::client_ip(&headers));
if b.start {
let _ = crate::factory::poll_repo(&app, &user, &cfg).await;
}
Ok(Json(json!({"created": created})))
}
#[derive(Deserialize)]
struct PrQuery {
repo: String,
number: i64,
}
/// The issue's forge client and row; the issue must belong to the user.
fn factory_issue_forge(app: &AppState, user: &User, repo: &str, number: i64) -> Result<(crate::factory::Forge, Value), ApiError> {
let row = app.store.factory_issue(repo, number)?.filter(|r| r["owner_id"].as_str() == Some(user.id.as_str())).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "unknown issue".into()))?;
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let cfg = s.repos.iter().find(|r| r.url == repo).map(|r| s.resolve(r)).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "the repository is not configured".into()))?;
let g = crate::factory::Forge::new(&cfg).map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
Ok((g, row))
}
/// The pull request of an issue: the open one from its branch, else the one on record.
async fn factory_pr(Extension(user): Extension<User>, State(app): State<AppState>, Query(q): Query<PrQuery>) -> ApiResult {
let (g, row) = factory_issue_forge(&app, &user, &q.repo, q.number)?;
let bad = |e: anyhow::Error| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}"));
let branch = row["branch"].as_str().unwrap_or("");
let mut pr = if branch.is_empty() { None } else { g.find_pr(branch).await.map_err(bad)? };
if pr.is_none() {
let n: u64 = row["pr_url"].as_str().unwrap_or("").trim_end_matches('/').rsplit('/').next().and_then(|n| n.parse().ok()).unwrap_or(0);
if n > 0 {
pr = g.pr(n).await.ok();
}
}
Ok(Json(json!({"pr": pr})))
}
#[derive(Deserialize)]
struct MergePr {
repo: String,
number: i64,
pr: u64,
#[serde(default)]
method: String,
}
/// 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)?;
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()));
}
let pr = g.pr(b.pr).await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
// Only the pull request of this issue's own branch may be merged from here.
if pr["head"].as_str() != row["branch"].as_str() || pr["state"].as_str() != Some("open") {
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.audit(Some(&user), "factory.pr.merge", &format!("{}#{}", b.repo, b.number), &crate::auth::client_ip(&headers));
Ok(Json(json!({"ok": true})))
}
#[derive(Deserialize)]
struct RestartIssue {
repo: String,
number: i64,
/// Where to re-enter the flow: new (review again), approved (build again) or qa (acceptance again).
to: String,
}
/// Put a finished, failed or rejected issue back into the flow at the chosen stage.
async fn factory_restart(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<RestartIssue>) -> ApiResult {
let bad = |m: &str| ApiError(StatusCode::BAD_REQUEST, m.to_string());
let row = app.store.factory_issue(&b.repo, b.number)?.filter(|r| r["owner_id"].as_str() == Some(user.id.as_str())).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "unknown issue".into()))?;
let state = row["state"].as_str().unwrap_or("");
if ["review", "building", "testing"].contains(&state) {
return Err(bad("a phase is running for this issue – wait until it ends"));
}
if !["new", "approved", "qa"].contains(&b.to.as_str()) {
return Err(bad("unknown target stage"));
}
if b.to == "qa" && row["branch"].as_str().unwrap_or("").is_empty() {
return Err(bad("nothing was built yet – restart at review or build"));
}
let mut fields: Vec<(&str, Value)> = vec![("state", json!(b.to)), ("attempts", json!(0)), ("note", json!(""))];
if b.to != "qa" {
fields.push(("rounds", json!(0)));
}
if b.to == "new" {
fields.push(("scenarios", json!("")));
// Answers given before count as read; the new review starts from the issue as it is now.
}
app.store.factory_issue_set(&b.repo, b.number, &fields)?;
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
if let Some(cfg) = s.repos.iter().find(|r| r.url == b.repo).map(|r| s.resolve(r)) {
if let Ok(g) = crate::factory::Forge::new(&cfg) {
let labels = if b.to == "new" { vec![cfg.label.clone()] } else { vec![cfg.label.clone(), format!("factory:{}", b.to)] };
let _ = g.set_labels(b.number as u64, &labels).await;
}
}
Ok(Json(json!({"ok": true})))
}
#[derive(Deserialize)]
struct ConnTest {
id: String,
}
/// Test a connection: who the token belongs to and which organisations/groups it can use.
async fn test_factory_connection(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<ConnTest>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let conn = s.connection(&b.id).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "save the connection first".into()))?;
let g = crate::factory::Forge::for_conn(conn).map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
let login = g.login().await.map_err(|e| ApiError(StatusCode::BAD_GATEWAY, format!("{e:#}")))?;
let orgs = g.orgs().await.unwrap_or_default();
Ok(Json(json!({"login": login, "orgs": orgs})))
}
#[derive(Deserialize)]
struct NewDraft {
#[serde(default)]
model: Option<String>,
}
/// Start a chat in which the user writes a spec with a model.
async fn factory_new_draft(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<NewDraft>) -> ApiResult {
let s: crate::factory::FactorySettings = app.store.user_setting(&user.id, "factory")?;
let model = b.model.filter(|m| !m.is_empty()).unwrap_or(s.defaults.spec_model.clone());
let session = crate::factory::start_spec_chat(&app, &user, &model).map_err(|e| ApiError(StatusCode::BAD_REQUEST, format!("{e:#}")))?;
Ok(Json(json!(session)))
}
fn draft_session(app: &AppState, user: &User, id: &str) -> Result<(crate::types::Session, std::path::PathBuf), ApiError> {
let session = app.session(id).map_err(|_| ApiError(StatusCode::NOT_FOUND, "unknown chat".into()))?;
let dir = crate::factory::draft_of(app, user, &session).ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "not a spec chat".into()))?;
Ok((session, dir))
}
/// The state of a spec chat: spec text, the model's name proposal, connections to choose from.
async fn factory_draft(Extension(user): Extension<User>, State(app): State<AppState>, Path(id): Path<String>) -> ApiResult {
let (_, dir) = draft_session(&app, &user, &id)?;
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();
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)]
struct CreateProject {
connection: String,
name: String,
slug: String,
#[serde(default)]
description: String,
#[serde(default)]
owner: String,
}
/// Create the repository, file the spec and open the issue that starts the workflow.
async fn factory_create_project(Extension(user): Extension<User>, State(app): State<AppState>, headers: axum::http::HeaderMap, Path(id): Path<String>, Json(b): Json<CreateProject>) -> ApiResult {
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 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))
}
// --- web terminal ------------------------------------------------------------------
#[derive(Deserialize)]
+18 -1
View File
@@ -189,6 +189,20 @@ impl App {
std::fs::canonicalize(&ws).unwrap_or(ws)
}
/// Separate area of the software factory (mounted outside the workspace); None when absent.
pub fn factory_dir(&self) -> Option<PathBuf> {
let p = std::env::var("CODECRAFT_FACTORY_DIR").ok().filter(|p| !p.is_empty()).unwrap_or_else(|| "/factory".into());
let p = PathBuf::from(p);
p.is_dir().then(|| std::fs::canonicalize(&p).unwrap_or(p))
}
/// The user's own folder in the factory area (created on demand).
pub fn factory_home(&self, user: &crate::store::User) -> Option<PathBuf> {
let dir = self.factory_dir()?.join(&user.username);
std::fs::create_dir_all(&dir).ok()?;
Some(dir)
}
/// Directories a session owner may work in: admins (and legacy sessions
/// without owner) the whole workspace, users their own folder plus shared folders.
pub fn user_roots(&self, owner_id: Option<&str>) -> Vec<PathBuf> {
@@ -196,12 +210,15 @@ impl App {
let Some(user) = owner_id.and_then(|id| self.store.user(id).ok().flatten()) else {
return vec![ws];
};
// The user's factory folder (if the area is mounted) is an additional root.
let factory = self.factory_dir().map(|d| d.join(&user.username)).filter(|d| d.is_dir());
if user.is_admin() {
return vec![ws];
return std::iter::once(ws).chain(factory).collect();
}
let own = ws.join(&user.username);
let _ = std::fs::create_dir_all(&own);
let mut roots = vec![own];
roots.extend(factory);
for p in self.store.folders_for_user(&user.id).unwrap_or_default() {
let p = PathBuf::from(p);
if p.starts_with(&ws) && p.is_dir() {
+3
View File
@@ -189,6 +189,9 @@ fn is_public(path: &str) -> bool {
// Read-only chat links (the token is the credential).
|| path.starts_with("/public/chat/")
|| path.starts_with("/api/public/chat/")
// MCP bridge for the Claude Code CLI (per-run token).
|| path.starts_with("/mcp-bridge/")
|| path.starts_with("/api/mcp-bridge/")
}
pub async fn require_user(State(app): State<Arc<App>>, mut req: Request, next: Next) -> Response {
+130 -8
View File
@@ -104,6 +104,7 @@ fn command(app: &App, owner: Option<&str>, cwd: &Path, args: &[String]) -> Resul
c.env("GIT_CONFIG_GLOBAL", cfg);
}
c.envs(crate::gitcreds::identity_env(app, &user.id));
c.envs(crate::sshkeys::env(app, &user));
}
Ok(c)
}
@@ -111,7 +112,51 @@ fn command(app: &App, owner: Option<&str>, cwd: &Path, args: &[String]) -> Resul
// --- tool mapping -----------------------------------------------------------------------
/// Claude Code tool → (our tool name, input with our key names), so the chat renders it like ours.
/// Claude Code's `AskUserQuestion` input → our questions (it writes `multiSelect`).
fn cc_questions(input: &Value) -> Vec<crate::types::Question> {
input["questions"]
.as_array()
.into_iter()
.flatten()
.filter_map(|q| {
let question = q["question"].as_str()?.to_string();
let options = q["options"]
.as_array()
.into_iter()
.flatten()
.filter_map(|o| Some(crate::types::QuestionOption { label: o["label"].as_str()?.to_string(), description: o["description"].as_str().unwrap_or("").to_string() }))
.collect();
Some(crate::types::Question { question, header: q["header"].as_str().unwrap_or("").to_string(), options, multi_select: q["multiSelect"].as_bool().or(q["multi_select"].as_bool()).unwrap_or(false) })
})
.collect()
}
/// Our answers (question → text or list) as the CLI expects them: question → text, lists joined by ", ".
fn cc_answers(answers: &serde_json::Map<String, Value>) -> Value {
Value::Object(
answers
.iter()
.map(|(q, a)| {
let text = match a {
Value::String(s) => s.clone(),
Value::Array(l) => l.iter().filter_map(|x| x.as_str()).collect::<Vec<_>>().join(", "),
other => other.to_string(),
};
(q.clone(), Value::String(text))
})
.collect(),
)
}
fn map_tool(name: &str, input: &Value) -> (String, Value) {
// Questions to the user show up as our question card / ask_user call.
if name == "AskUserQuestion" {
return ("ask_user".to_string(), json!({"questions": cc_questions(input)}));
}
// Our own tools reach the CLI over MCP: shown and judged under their usual names.
if let Some(ours) = name.strip_prefix(crate::mcp_bridge::PREFIX) {
return (ours.to_string(), input.clone());
}
let mut v = input.clone();
let rename = |v: &mut Value, from: &str, to: &str| {
if let Some(x) = v.get(from).cloned() {
@@ -148,6 +193,8 @@ impl ToolInfo for CcTool {
}
fn read_only(&self) -> bool {
matches!(self.name.as_str(), "read" | "glob" | "grep" | "web_fetch" | "web_search" | "task" | "todowrite" | "list")
// One of our tools (MCP bridge): as it declares itself.
|| crate::tools::builtin_tools().iter().any(|t| t.name() == self.name && t.read_only())
}
fn is_edit(&self) -> bool {
matches!(self.name.as_str(), "write" | "edit")
@@ -177,16 +224,16 @@ fn title_of(name: &str, input: &Value, claude_input: &Value) -> String {
match name {
"bash" => input["description"].as_str().filter(|d| !d.is_empty()).map(String::from).unwrap_or_else(|| input["command"].as_str().unwrap_or("").chars().take(120).collect()),
"write" | "edit" | "read" => input["path"].as_str().unwrap_or("").to_string(),
_ => claude_input["description"].as_str().map(String::from).unwrap_or_else(|| name.to_string()),
_ => match crate::tools::builtin_tools().iter().find(|t| t.name() == name) {
Some(t) => t.title(input),
None => claude_input["description"].as_str().map(String::from).unwrap_or_else(|| name.to_string()),
},
}
}
/// Ask our permission system whether a tool call of Claude Code may run: (allow, message for a rejection).
async fn decide(app: &Arc<App>, session: &Session, claude_name: &str, claude_input: &Value, cancel: &CancellationToken) -> (bool, Option<String>) {
let (name, input) = map_tool(claude_name, claude_input);
if claude_name == "AskUserQuestion" {
return (false, Some("Questions to the user are not available in this mode – decide yourself or state your assumption.".into()));
}
let info = CcTool { name: name.clone() };
let cfg = app.config();
let root = app.root_session_id(&session.id);
@@ -314,7 +361,12 @@ fn save_images(cwd: &str, parts: &[Part]) -> Vec<String> {
let mut out = Vec::new();
for (i, p) in parts.iter().enumerate() {
let Part::Image { image } = p else { continue };
// An image without bytes (an unresolved reference) would become an empty file.
let Ok(bytes) = base64::engine::general_purpose::STANDARD.decode(&image.data) else { continue };
if bytes.is_empty() {
tracing::warn!("claude code: image {i} of the message has no data – not saved");
continue;
}
let ext = image.media_type.split('/').nth(1).unwrap_or("png").split('+').next().unwrap_or("png");
let path = dir.join(format!("chat-{}-{i}.{ext}", now_ms()));
if std::fs::create_dir_all(&dir).is_ok() {
@@ -332,7 +384,8 @@ pub async fn run(app: Arc<App>, session_id: &str, cancel: CancellationToken) ->
let session = app.session(session_id)?;
let owner = session.owner_id.clone();
let model_id = session.model.strip_prefix("claude-code/").unwrap_or("default").to_string();
let history = crate::runner::active_history(app.store.messages(session_id)?);
// With the bytes of the images filled in (they are stored as references).
let history = crate::runner::active_history(app.store.messages_for_model(session_id)?);
let Some(last_user) = history.iter().rposition(|m| m.role == Role::User && m.parts.iter().any(|p| matches!(p, Part::Text { .. } | Part::Image { .. }))) else {
bail!("nothing to do: no user message");
};
@@ -364,9 +417,15 @@ pub async fn run(app: Arc<App>, session_id: &str, cancel: CancellationToken) ->
if let Some(r) = &resume {
args.extend(["--resume".into(), r.clone()]);
}
// CodeCraft's own tools for the CLI (MCP, per-run token).
let bridge = crate::mcp_bridge::register(session_id);
args.extend(["--mcp-config".into(), crate::mcp_bridge::config_json(&app, &bridge.token)]);
let mut appended = session.instructions.trim().to_string();
if let Some(git) = owner.as_deref().and_then(|u| crate::gitcreds::prompt_section(&app, u)) {
appended = format!("{appended}\n{git}").trim().to_string();
if let Some(note) = crate::mcp_bridge::prompt_section(&crate::mcp_bridge::tools_for(&app, &session)) {
appended = format!("{appended}\n{note}").trim().to_string();
}
for extra in owner.as_deref().into_iter().flat_map(|u| [crate::gitcreds::prompt_section(&app, u), crate::sshkeys::prompt_section(&app, u)]).flatten() {
appended = format!("{appended}\n{extra}").trim().to_string();
}
if !appended.is_empty() {
args.extend(["--append-system-prompt".into(), appended]);
@@ -401,6 +460,8 @@ pub async fn run(app: Arc<App>, session_id: &str, cancel: CancellationToken) ->
let mut cur: Option<Cur> = None;
let mut calls: HashMap<String, String> = HashMap::new();
let mut diffs: HashMap<String, String> = HashMap::new();
// Answers to AskUserQuestion calls, kept as the result's data for the question card.
let mut asked: HashMap<String, Value> = HashMap::new();
let mut final_text = String::new();
let mut got_result = false;
let mut failure: Option<String> = None;
@@ -482,7 +543,7 @@ pub async fn run(app: Arc<App>, session_id: &str, cancel: CancellationToken) ->
}
let id = b["tool_use_id"].as_str().unwrap_or("").to_string();
let is_error = b["is_error"].as_bool().unwrap_or(false);
let meta = if is_error { None } else { diffs.remove(&id).map(|d| json!({"diff": d})) };
let meta = if is_error { None } else { diffs.remove(&id).map(|d| json!({"diff": d})).or_else(|| asked.remove(&id).map(|a| json!({"answers": a}))) };
parts.push(Part::ToolResult { name: calls.get(&id).cloned().unwrap_or_default(), call_id: id, content: result_text(&b["content"]), images: result_images(&b["content"]), is_error, meta });
}
if !parts.is_empty() {
@@ -495,6 +556,30 @@ pub async fn run(app: Arc<App>, session_id: &str, cancel: CancellationToken) ->
"control_request" if ev["request"]["subtype"] == "can_use_tool" => {
finalize(&app, session_id, &mut cur, &model_id);
let req = &ev["request"];
// A question for the user: shown as a question card; the answers go back to the CLI.
if req["tool_name"] == "AskUserQuestion" {
let questions = cc_questions(&req["input"]);
let response = if questions.is_empty() {
json!({"behavior": "deny", "message": "No usable question was given."})
} else {
match app.ask_user(session_id, "agent", questions, cancel.clone()).await {
Ok(Some(answers)) => {
let mut input = req["input"].clone();
input["answers"] = cc_answers(&answers);
if let Some(id) = req["tool_use_id"].as_str() {
asked.insert(id.to_string(), Value::Object(answers));
}
json!({"behavior": "allow", "updatedInput": input})
}
_ => json!({"behavior": "deny", "message": "The user dismissed the questions without answering."}),
}
};
let reply = json!({"type": "control_response", "response": {"subtype": "success", "request_id": ev["request_id"], "response": response}});
if stdin.write_all(format!("{reply}\n").as_bytes()).await.is_err() {
break;
}
continue;
}
let (allow, message) = decide(&app, &session, req["tool_name"].as_str().unwrap_or(""), &req["input"], &cancel).await;
if allow {
let (name, input) = map_tool(req["tool_name"].as_str().unwrap_or(""), &req["input"]);
@@ -877,6 +962,43 @@ pub async fn update() -> Result<String> {
#[cfg(test)]
mod tests {
#[test]
fn uploaded_images_are_saved_with_their_bytes_only() {
let dir = std::env::temp_dir().join(format!("cc-uploads-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let parts = vec![
Part::Image { image: ImageData { media_type: "image/png".into(), data: "QUJD".into(), blob: None, size: None } },
// A reference whose bytes were not filled in: must not become an empty file.
Part::Image { image: ImageData { media_type: "image/png".into(), data: String::new(), blob: Some("x".into()), size: None } },
];
let saved = save_images(&dir.display().to_string(), &parts);
assert_eq!(saved.len(), 1);
assert_eq!(std::fs::read(&saved[0]).unwrap(), b"ABC");
std::fs::remove_dir_all(&dir).unwrap();
}
#[test]
fn questions_roundtrip_with_the_cli_format() {
let input = json!({"questions": [
{"question": "Which database?", "header": "DB", "multiSelect": false, "options": [{"label": "SQLite", "description": "file"}, {"label": "Postgres"}]},
{"question": "Which extras?", "header": "Extras", "multiSelect": true, "options": [{"label": "Auth"}, {"label": "Docs"}]},
{"nonsense": true}
]});
let qs = cc_questions(&input);
assert_eq!(qs.len(), 2);
assert_eq!((qs[0].question.as_str(), qs[0].options.len(), qs[0].multi_select), ("Which database?", 2, false));
assert!(qs[1].multi_select);
// The tool card shows it as our ask_user.
let (name, shown) = map_tool("AskUserQuestion", &input);
assert_eq!(name, "ask_user");
assert_eq!(shown["questions"][1]["multi_select"], true);
// Answers: text stays, a multiple choice is joined.
let answers = json!({"Which database?": "SQLite", "Which extras?": ["Auth", "Docs"]});
let out = cc_answers(answers.as_object().unwrap());
assert_eq!(out["Which database?"], "SQLite");
assert_eq!(out["Which extras?"], "Auth, Docs");
}
#[test]
fn tool_result_images_are_kept() {
let content = json!([{"type": "text", "text": "ok"}, {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": "QUJD"}}]);
File diff suppressed because it is too large. Load diff
+609
View File
@@ -0,0 +1,609 @@
//! Versions, tags and releases of factory repositories.
//!
//! Every merged factory issue gets a version (`MAJOR.MINOR.PATCH`): the patch number goes up with each
//! issue, the minor number when the issue completes a milestone (`M1.3` was the last open `M1.x`
//! issue); the patch restarts at 0. A version is a commit with a `VERSION` file on the default branch
//! plus the tag `vX.Y.Z` on it. Major versions are only made by a manual release, which also builds
//! the Docker image and the downloads described in `.factory/release.json`.
use crate::app::App;
use crate::factory::{Forge, RepoCfg, bot_comment, checkout, git, issue_no, notify};
use crate::store::User;
use anyhow::{Context, Result, bail};
use serde::Deserialize;
use serde_json::{Value, json};
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, OnceLock};
use std::time::Duration;
pub type Ver = (u64, u64, u64);
pub fn parse_version(s: &str) -> Option<Ver> {
let mut it = s.trim().trim_start_matches('v').split('.');
let v = (it.next()?.parse().ok()?, it.next()?.parse().ok()?, it.next()?.parse().ok()?);
it.next().is_none().then_some(v)
}
pub fn fmt(v: Ver) -> String {
format!("{}.{}.{}", v.0, v.1, v.2)
}
/// Milestone of an issue title: `M1.3 – x` → (1, Some(3)), `M1 – x` → (1, None).
pub fn milestone_of(title: &str) -> Option<(u64, Option<u64>)> {
let t = title.trim();
let rest = t.strip_prefix('M').or_else(|| t.strip_prefix('m'))?;
let digits: String = rest.chars().take_while(|c| c.is_ascii_digit()).collect();
let k: u64 = digits.parse().ok()?;
let after = &rest[digits.len()..];
if let Some(a) = after.strip_prefix('.') {
let d: String = a.chars().take_while(|c| c.is_ascii_digit()).collect();
if !d.is_empty() {
return Some((k, Some(d.parse().ok()?)));
}
}
match after.chars().next() {
None | Some(' ') | Some('–') | Some('-') | Some(':') => Some((k, None)),
_ => None,
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Bump {
Patch,
Minor,
}
/// How an issue raises the version, given the titles of the *other* open issues of the repository.
pub fn bump_for(title: &str, other_open: &[String]) -> Bump {
match milestone_of(title) {
Some((_, None)) => Bump::Minor,
Some((k, Some(_))) => {
if other_open.iter().any(|t| matches!(milestone_of(t), Some((k2, Some(_))) if k2 == k)) {
Bump::Patch
} else {
Bump::Minor
}
}
None => Bump::Patch,
}
}
pub fn next_version(cur: Ver, b: Bump) -> Ver {
match b {
Bump::Patch => (cur.0, cur.1, cur.2 + 1),
Bump::Minor => (cur.0, cur.1 + 1, 0),
}
}
// --- git helpers ---------------------------------------------------------------------------
/// Highest `vX.Y.Z` tag of the remote (0.0.0 when there is none).
async fn tags_version(cfg: &RepoCfg, dir: &Path) -> Ver {
let _ = git(cfg, dir, &["fetch", "--tags", "--force", "origin"]).await;
git(cfg, dir, &["tag", "-l", "v[0-9]*"]).await.unwrap_or_default().lines().filter_map(parse_version).max().unwrap_or((0, 0, 0))
}
/// `git pull --ff-only` of the default branch in the main checkout, so everything that was merged
/// (also by others) is on disk for the reviews. Does nothing harmful: with local changes or a
/// diverged branch it reports an error and leaves the checkout alone.
pub async fn sync_default(cfg: &RepoCfg, dir: &Path) -> Result<()> {
let base = base_branch(cfg, dir).await;
let current = git(cfg, dir, &["rev-parse", "--abbrev-ref", "HEAD"]).await.unwrap_or_default();
if current != base {
if !git(cfg, dir, &["status", "--porcelain"]).await.unwrap_or_default().is_empty() {
bail!("the checkout has local changes and is on '{current}', not on {base}");
}
git(cfg, dir, &["checkout", "-q", &base]).await?;
}
git(cfg, dir, &["merge", "--ff-only", "-q", &format!("origin/{base}")]).await?;
Ok(())
}
async fn base_branch(cfg: &RepoCfg, repo: &Path) -> String {
git(cfg, repo, &["symbolic-ref", "--short", "refs/remotes/origin/HEAD"]).await.ok().and_then(|s| s.strip_prefix("origin/").map(String::from)).unwrap_or_else(|| "main".to_string())
}
/// A throw-away detached worktree of the default branch below `<owner>/<sub>/<name>`.
async fn fresh_worktree(cfg: &RepoCfg, repo: &Path, sub: &str, name: &str, base: &str) -> Result<PathBuf> {
let work = repo.parent().context("no parent folder")?.join(sub).join(name);
std::fs::create_dir_all(work.parent().unwrap())?;
if work.exists() {
let _ = git(cfg, repo, &["worktree", "remove", "--force", &work.display().to_string()]).await;
let _ = std::fs::remove_dir_all(&work);
}
let _ = git(cfg, repo, &["worktree", "prune"]).await;
git(cfg, repo, &["worktree", "add", "--detach", &work.display().to_string(), &format!("origin/{base}")]).await?;
Ok(work)
}
async fn drop_worktree(cfg: &RepoCfg, repo: &Path, work: &Path) {
let _ = git(cfg, repo, &["worktree", "remove", "--force", &work.display().to_string()]).await;
let _ = std::fs::remove_dir_all(work);
}
const IDENT: [&str; 4] = ["-c", "user.name=CodeCraft Factory", "-c", "user.email=factory@codecraft.invalid"];
/// Write `VERSION` and commit it locally (nothing is pushed yet).
async fn commit_version(cfg: &RepoCfg, work: &Path, ver: &str, msg: &str) -> Result<()> {
std::fs::write(work.join("VERSION"), format!("{ver}\n"))?;
git(cfg, work, &["add", "VERSION"]).await?;
if !git(cfg, work, &["diff", "--cached", "--name-only"]).await?.is_empty() {
let mut args = IDENT.to_vec();
args.extend(["commit", "-m", msg]);
git(cfg, work, &args).await?;
}
Ok(())
}
/// Tag the commit and push default branch and tag. Returns a warning when the branch could not be
/// pushed (e.g. protected): then the tag goes onto the commit already on the branch.
async fn publish_version(cfg: &RepoCfg, work: &Path, base: &str, ver: &str, msg: &str) -> Result<String> {
let mut warn = String::new();
let target = format!("HEAD:refs/heads/{base}");
let mut pushed = git(cfg, work, &["push", "origin", &target]).await;
if pushed.is_err() {
// The branch moved meanwhile: put the version commit on top and try once more.
let _ = git(cfg, work, &["fetch", "origin"]).await;
let upstream = format!("origin/{base}");
let mut args = IDENT.to_vec();
args.extend(["rebase", &upstream]);
if git(cfg, work, &args).await.is_ok() {
pushed = git(cfg, work, &["push", "origin", &target]).await;
} else {
let _ = git(cfg, work, &["rebase", "--abort"]).await;
}
}
if let Err(e) = pushed {
warn = format!("the VERSION commit could not be pushed to {base} ({e:#}); the tag points to the branch head instead");
git(cfg, work, &["reset", "--hard", &format!("origin/{base}")]).await?;
}
let tag = format!("v{ver}");
let mut args = IDENT.to_vec();
args.extend(["tag", "-a", "-f", &tag, "-m", msg]);
git(cfg, work, &args).await?;
git(cfg, work, &["push", "origin", &format!("refs/tags/{tag}")]).await?;
Ok(warn)
}
// --- version of merged issues -----------------------------------------------------------------
static BUSY: OnceLock<Mutex<HashSet<String>>> = OnceLock::new();
/// Keeps two passes (poller and manual poll) from versioning the same repository at once.
struct Busy(String);
fn busy(repo: &str) -> Option<Busy> {
let set = BUSY.get_or_init(Default::default);
set.lock().unwrap().insert(repo.to_string()).then(|| Busy(repo.to_string()))
}
impl Drop for Busy {
fn drop(&mut self) {
if let Some(set) = BUSY.get() {
set.lock().unwrap().remove(&self.0);
}
}
}
fn pr_number(url: &str) -> u64 {
url.trim_end_matches('/').rsplit('/').next().and_then(|n| n.parse().ok()).unwrap_or(0)
}
/// Give every merged, accepted issue its version. The first pass over a repository only
/// sets the baseline: issues that were done before are not versioned.
pub async fn version_pass(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<()> {
let Some(_guard) = busy(&cfg.url) else { return Ok(()) };
let rows: Vec<Value> = app.store.factory_issues(&user.id)?.into_iter().filter(|r| r["repo"].as_str() == Some(cfg.url.as_str())).collect();
let pending = |r: &&Value| r["state"].as_str() == Some("done") && r["version"].as_str() == Some("");
if app.store.factory_version(&cfg.url)?.is_none() {
let dir = checkout(app, user, cfg).await?;
let cur = tags_version(cfg, &dir).await;
for r in rows.iter().filter(pending) {
app.store.factory_issue_set(&cfg.url, issue_no(r), &[("version", json!("-"))])?;
}
app.store.factory_version_set(&cfg.url, &fmt(cur))?;
return Ok(());
}
let mut todo: Vec<&Value> = rows.iter().filter(pending).collect();
if todo.is_empty() {
return Ok(());
}
todo.sort_by_key(|r| issue_no(r));
let g = Forge::new(cfg)?;
for r in todo {
let n = issue_no(r);
let pr_n = pr_number(r["pr_url"].as_str().unwrap_or(""));
if pr_n == 0 {
continue;
}
let pr = match g.pr(pr_n).await {
Ok(p) => p,
Err(e) => {
tracing::warn!("factory {}#{n}: pull request: {e:#}", cfg.url);
continue;
}
};
if pr["state"].as_str() != Some("merged") {
continue;
}
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?;
let cur = tags_version(cfg, &dir).await;
let bump = bump_for(&title, &others);
let new = fmt(next_version(cur, bump));
let base = base_branch(cfg, &dir).await;
let (_, _, name) = cfg.parts()?;
let work = fresh_worktree(cfg, &dir, "_release", &format!("{name}-version"), &base).await?;
let msg = format!("Release v{new}: {title} (#{n})");
let published = async {
commit_version(cfg, &work, &new, &msg).await?;
publish_version(cfg, &work, &base, &new, &msg).await
}
.await;
drop_worktree(cfg, &dir, &work).await;
let warn = match published {
Ok(w) => w,
Err(e) => {
tracing::warn!("factory {}#{n}: version {new}: {e:#}", cfg.url);
continue;
}
};
let _ = checkout(app, user, cfg).await; // pulls the merge and the VERSION commit
app.store.factory_issue_set(&cfg.url, n, &[("version", json!(new.clone()))])?;
app.store.factory_version_set(&cfg.url, &new)?;
let _ = g.close_issue(n as u64).await;
let why = if bump == Bump::Minor && milestone_of(&title).is_some() { " – the milestone is complete" } else { "" };
let extra = if warn.is_empty() { String::new() } else { format!("\n\nNote: {warn}.") };
bot_comment(&g, n as u64, &format!("**Version v{new}**{why}. The change is merged; tag `v{new}` and `VERSION` are on the default branch.{extra}")).await;
notify(app, user, &format!("Factory #{n}"), &format!("v{new}{why}"), n).await;
}
Ok(())
}
// --- manual release ----------------------------------------------------------------------------
/// `.factory/release.json`: how to build the downloads of a release.
#[derive(Debug, Default, Deserialize)]
pub struct ReleaseSpec {
/// Docker image name without tag, e.g. registry.example.org/team/app (empty = no image).
#[serde(default)]
pub image: String,
#[serde(default = "default_platforms")]
pub platforms: String,
#[serde(default = "default_dockerfile")]
pub dockerfile: String,
#[serde(default = "default_context")]
pub context: String,
#[serde(default)]
pub build_args: HashMap<String, String>,
/// Shell commands run in the release checkout before the image is built (e.g. to make zips).
#[serde(default)]
pub commands: Vec<String>,
/// Files (globs relative to the checkout) attached to the release; the source zip is always attached.
#[serde(default)]
pub files: Vec<String>,
/// Name used for the source zip (default: the repository name).
#[serde(default)]
pub name: String,
}
fn default_platforms() -> String {
"linux/amd64,linux/arm64".into()
}
fn default_dockerfile() -> String {
"Dockerfile".into()
}
fn default_context() -> String {
".".into()
}
/// Run a command with a timeout; returns the last lines of its output.
async fn run(cmd: &mut tokio::process::Command, timeout: Duration, stdin: Option<&str>) -> Result<String> {
use tokio::io::AsyncWriteExt;
cmd.stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::piped()).stdin(if stdin.is_some() { std::process::Stdio::piped() } else { std::process::Stdio::null() }).kill_on_drop(true);
let mut child = cmd.spawn().context("could not start the command")?;
if let (Some(text), Some(mut si)) = (stdin, child.stdin.take()) {
si.write_all(text.as_bytes()).await?;
}
let out = tokio::time::timeout(timeout, child.wait_with_output()).await.map_err(|_| anyhow::anyhow!("timed out after {} min", timeout.as_secs() / 60))??;
let text = format!("{}{}", String::from_utf8_lossy(&out.stdout), String::from_utf8_lossy(&out.stderr));
let tail: Vec<&str> = text.lines().rev().take(25).collect::<Vec<_>>().into_iter().rev().collect();
let tail = tail.join("\n");
if !out.status.success() {
bail!("{}", tail);
}
Ok(tail)
}
fn clean_env(cmd: &mut tokio::process::Command, extra: &[(&str, &str)]) {
cmd.env_clear().env("PATH", std::env::var("PATH").unwrap_or_default()).env("HOME", "/tmp");
for (k, v) in extra {
cmd.env(k, v);
}
}
/// Current version, suggested next major version and the release recipe of the default branch.
pub async fn preview(app: &Arc<App>, user: &User, cfg: &RepoCfg) -> Result<Value> {
let dir = checkout(app, user, cfg).await?;
let cur = tags_version(cfg, &dir).await;
let base = base_branch(cfg, &dir).await;
let spec = git(cfg, &dir, &["show", &format!("origin/{base}:.factory/release.json")]).await.ok();
Ok(json!({"current": fmt(cur), "suggested": fmt((cur.0 + 1, 0, 0)), "spec": spec, "running": app.store.factory_release_running(&cfg.url)?}))
}
/// Validate and start a release in the background; returns the release id.
pub async fn start_release(app: &Arc<App>, user: &User, cfg: &RepoCfg, version: &str) -> Result<String> {
let Some(new) = parse_version(version) else { bail!("the version must look like 1.0.0") };
if app.store.factory_release_running(&cfg.url)? {
bail!("a release of this repository is already running");
}
let dir = checkout(app, user, cfg).await?;
let cur = tags_version(cfg, &dir).await;
if new <= cur {
bail!("v{} is not newer than the current version v{}", fmt(new), fmt(cur));
}
let id = crate::types::new_id();
app.store.factory_release_add(&id, &user.id, &cfg.url, &fmt(new))?;
let (app, user, cfg, rid) = (app.clone(), user.clone(), cfg.clone(), id.clone());
tokio::spawn(async move {
let log = |m: &str| {
let _ = app.store.factory_release_log(&rid, m);
};
match run_release(&app, &user, &cfg, new, &rid, &log).await {
Ok(url) => {
let _ = app.store.factory_release_end(&rid, "done", &url);
notify(&app, &user, "Factory release", &format!("v{} released", fmt(new)), 0).await;
}
Err(e) => {
log(&format!("FAILED: {e:#}"));
let _ = app.store.factory_release_end(&rid, "failed", "");
notify(&app, &user, "Factory release", &format!("v{} failed", fmt(new)), 0).await;
}
}
});
Ok(id)
}
async fn run_release(app: &Arc<App>, user: &User, cfg: &RepoCfg, new: Ver, rid: &str, log: &(dyn Fn(&str) + Sync)) -> Result<String> {
let ver = fmt(new);
let tag = format!("v{ver}");
let dir = checkout(app, user, cfg).await?;
let base = base_branch(cfg, &dir).await;
let (_, _, name) = cfg.parts()?;
let g = Forge::new(cfg)?;
log(&format!("release {tag} from {base}"));
let work = fresh_worktree(cfg, &dir, "_release", &format!("{name}-release"), &base).await?;
let tmp = std::env::temp_dir().join(format!("factory-release-{rid}"));
std::fs::create_dir_all(&tmp)?;
let result = release_steps(cfg, &g, &work, &tmp, &base, &name, &ver, &tag, rid, log).await;
drop_worktree(cfg, &dir, &work).await;
let _ = std::fs::remove_dir_all(&tmp);
result
}
#[allow(clippy::too_many_arguments)]
async fn release_steps(cfg: &RepoCfg, g: &Forge, work: &Path, tmp: &Path, base: &str, name: &str, ver: &str, tag: &str, rid: &str, log: &(dyn Fn(&str) + Sync)) -> Result<String> {
let msg = format!("Release {tag}");
commit_version(cfg, work, ver, &msg).await?;
let spec: ReleaseSpec = match std::fs::read_to_string(work.join(".factory/release.json")) {
Ok(t) => serde_json::from_str(&t).context(".factory/release.json is not valid")?,
Err(_) => {
log("no .factory/release.json – only the tag, the release and the source zip are made");
ReleaseSpec::default()
}
};
let hour = Duration::from_secs(3600);
for cmd in &spec.commands {
log(&format!("$ {cmd}"));
let mut c = tokio::process::Command::new("bash");
c.arg("-c").arg(cmd).current_dir(work);
clean_env(&mut c, &[("VERSION", ver), ("CI", "1")]);
log(&run(&mut c, hour, None).await?);
}
if !spec.image.trim().is_empty() {
build_image(cfg, g, &spec, work, tmp, ver, rid, log).await?;
}
// Publish: branch + tag, then the release with its files.
let warn = publish_version(cfg, work, base, ver, &msg).await?;
if !warn.is_empty() {
log(&format!("note: {warn}"));
}
log(&format!("tag {tag} pushed"));
let prev = git(cfg, work, &["tag", "-l", "v[0-9]*"]).await.unwrap_or_default().lines().filter_map(|t| parse_version(t).map(|v| (v, t.to_string()))).filter(|(v, _)| fmt(*v) != ver && *v < parse_version(ver).unwrap_or((0, 0, 0))).max().map(|(_, t)| t);
let range = prev.as_ref().map(|p| format!("{p}..{tag}")).unwrap_or_else(|| tag.to_string());
let changes = git(cfg, work, &["log", "--pretty=format:- %s", "--max-count=200", &range]).await.unwrap_or_default();
let mut notes = format!("Release {tag}\n\n");
if !spec.image.trim().is_empty() {
notes.push_str(&format!("Docker image: `{}:{ver}` ({})\n\n", spec.image.trim(), spec.platforms));
}
notes.push_str(&format!("## Changes\n\n{changes}\n"));
let rel = g.create_release(tag, &format!("{name} {tag}"), &notes).await?;
let url = rel["html_url"].as_str().unwrap_or("").to_string();
log(&format!("release created {url}"));
// Downloads: the source zip and the configured files.
let zip_name = format!("{}-{ver}-source.zip", Some(spec.name.trim()).filter(|n| !n.is_empty()).unwrap_or(name));
let zip = tmp.join(&zip_name);
git(cfg, work, &["archive", "--format=zip", &format!("--prefix={name}-{ver}/"), "-o", &zip.display().to_string(), "HEAD"]).await?;
let mut files: Vec<(String, PathBuf)> = vec![(zip_name, zip)];
if !spec.files.is_empty() {
let mut builder = globset::GlobSetBuilder::new();
for f in &spec.files {
builder.add(globset::Glob::new(f).with_context(|| format!("bad file pattern {f}"))?);
}
let set = builder.build()?;
let mut stack = vec![work.to_path_buf()];
while let Some(d) = stack.pop() {
for e in std::fs::read_dir(&d)?.flatten() {
let p = e.path();
let rel_path = p.strip_prefix(work).unwrap_or(&p).to_path_buf();
if rel_path.starts_with(".git") || rel_path.starts_with("node_modules") || rel_path.starts_with("target") && !set.is_match(&rel_path) {
continue;
}
if p.is_dir() {
stack.push(p);
} else if set.is_match(&rel_path) && files.len() < 60 {
files.push((e.file_name().to_string_lossy().to_string(), p));
}
}
}
}
for (fname, path) in &files {
match g.upload_asset(&rel["id"], fname, path).await {
Ok(()) => log(&format!("attached {fname}")),
Err(e) => log(&format!("not attached: {e:#}")),
}
}
Ok(url)
}
/// Build and push the multi-arch Docker image with buildx (own builder, own login, both removed afterwards).
#[allow(clippy::too_many_arguments)]
async fn build_image(cfg: &RepoCfg, g: &Forge, spec: &ReleaseSpec, work: &Path, tmp: &Path, ver: &str, rid: &str, log: &(dyn Fn(&str) + Sync)) -> Result<()> {
let image = spec.image.trim();
let first = image.split('/').next().unwrap_or("");
let host = if image.contains('/') && (first.contains('.') || first.contains(':')) { first } else { "docker.io" };
let conf = tmp.join("docker");
std::fs::create_dir_all(&conf)?;
let conf_s = conf.display().to_string();
let builder = format!("factory-{}", &rid[..8.min(rid.len())]);
let minute = Duration::from_secs(120);
let env = [("DOCKER_CONFIG", conf_s.as_str())];
let mut c = tokio::process::Command::new("docker");
c.args(["buildx", "version"]);
clean_env(&mut c, &env);
run(&mut c, minute, None).await.context("docker buildx is not available in this installation")?;
let login = g.login().await?;
log(&format!("docker login {host}"));
let mut c = tokio::process::Command::new("docker");
c.args(["login", host, "-u", &login, "--password-stdin"]);
clean_env(&mut c, &env);
run(&mut c, minute, Some(&cfg.token)).await.context("docker login failed")?;
let mut c = tokio::process::Command::new("docker");
c.args(["buildx", "create", "--name", &builder, "--driver", "docker-container"]);
clean_env(&mut c, &env);
run(&mut c, minute, None).await.context("could not create the buildx builder")?;
let mut args: Vec<String> = ["buildx", "build", "--builder", &builder, "--platform", &spec.platforms, "-f", &spec.dockerfile, "-t", &format!("{image}:{ver}"), "-t", &format!("{image}:latest"), "--build-arg", &format!("VERSION={ver}")].iter().map(|s| s.to_string()).collect();
for (k, v) in &spec.build_args {
args.extend(["--build-arg".to_string(), format!("{k}={v}")]);
}
args.extend(["--push".to_string(), spec.context.clone()]);
log(&format!("docker buildx build {} → {image}:{ver}", spec.platforms));
let mut c = tokio::process::Command::new("docker");
c.args(&args).current_dir(work);
clean_env(&mut c, &env);
let built = run(&mut c, Duration::from_secs(3 * 3600), None).await;
let mut c = tokio::process::Command::new("docker");
c.args(["buildx", "rm", "--force", &builder]);
clean_env(&mut c, &env);
let _ = run(&mut c, minute, None).await;
log(&built.context("the image build failed")?);
log("image pushed");
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_and_formats_versions() {
assert_eq!(parse_version("v1.2.3"), Some((1, 2, 3)));
assert_eq!(parse_version("0.0.0"), Some((0, 0, 0)));
assert_eq!(parse_version("1.2"), None);
assert_eq!(parse_version("1.2.3.4"), None);
assert_eq!(parse_version("vx.1.2"), None);
assert_eq!(fmt((0, 1, 10)), "0.1.10");
assert!(parse_version("0.10.0") > parse_version("0.9.9"));
}
#[test]
fn reads_milestones_from_titles() {
assert_eq!(milestone_of("M1.3 – Import"), Some((1, Some(3))));
assert_eq!(milestone_of("M12.10 - x"), Some((12, Some(10))));
assert_eq!(milestone_of("M1 – Foundation"), Some((1, None)));
assert_eq!(milestone_of("M0"), Some((0, None)));
assert_eq!(milestone_of("Make it faster"), None);
assert_eq!(milestone_of("M1abc"), None);
assert_eq!(milestone_of("Fix login"), None);
}
#[test]
fn issues_raise_patch_and_the_last_one_of_a_milestone_the_minor() {
let open = |v: &[&str]| v.iter().map(|s| s.to_string()).collect::<Vec<_>>();
// other M1 issues still open: patch
assert_eq!(bump_for("M1.3 – Import", &open(&["M1.4 – Debayering", "M2.1 – Mail"])), Bump::Patch);
// the last open M1 issue: minor (other milestones do not matter)
assert_eq!(bump_for("M1.11 – Log", &open(&["M2.1 – Mail", "Fix typo"])), Bump::Minor);
assert_eq!(bump_for("Fix login bug", &open(&["M1.1 – x"])), Bump::Patch);
assert_eq!(bump_for("M3 – Mosaics", &open(&[])), Bump::Minor);
assert_eq!(next_version((0, 0, 7), Bump::Patch), (0, 0, 8));
assert_eq!(next_version((0, 0, 10), Bump::Minor), (0, 1, 0));
assert_eq!(next_version((0, 1, 4), Bump::Minor), (0, 2, 0));
}
#[test]
fn release_spec_has_defaults() {
let s: ReleaseSpec = serde_json::from_str(r#"{"image": "r.example/app"}"#).unwrap();
assert_eq!((s.platforms.as_str(), s.dockerfile.as_str(), s.context.as_str()), ("linux/amd64,linux/arm64", "Dockerfile", "."));
assert!(s.commands.is_empty() && s.files.is_empty());
}
#[tokio::test]
async fn sync_default_pulls_what_was_merged() {
let run = |dir: &Path, args: &[&str]| {
let o = std::process::Command::new("git").args(["-c", "user.name=t", "-c", "user.email=t@t", "-c", "init.defaultBranch=main"]).args(args).current_dir(dir).output().unwrap();
assert!(o.status.success(), "git {args:?}: {}", String::from_utf8_lossy(&o.stderr));
};
let root = std::env::temp_dir().join(format!("factory-sync-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(&root).unwrap();
run(&root, &["init", "-q", "--bare", "origin.git"]);
run(&root, &["clone", "-q", "origin.git", "a"]);
std::fs::write(root.join("a/one.txt"), "1").unwrap();
run(&root.join("a"), &["add", "."]);
run(&root.join("a"), &["commit", "-qm", "one"]);
run(&root.join("a"), &["push", "-q", "origin", "HEAD:main"]);
run(&root, &["--git-dir=origin.git", "symbolic-ref", "HEAD", "refs/heads/main"]);
run(&root, &["clone", "-q", "origin.git", "checkout"]);
// somebody merges a second change on the remote
std::fs::write(root.join("a/two.txt"), "2").unwrap();
run(&root.join("a"), &["add", "."]);
run(&root.join("a"), &["commit", "-qm", "two"]);
run(&root.join("a"), &["push", "-q", "origin", "HEAD:main"]);
let cfg: RepoCfg = serde_json::from_value(json!({"url": "https://g.example/o/r.git", "token": "t"})).unwrap();
let dir = root.join("checkout");
git(&cfg, &dir, &["fetch", "origin"]).await.unwrap();
assert!(!dir.join("two.txt").exists(), "a fetch alone does not update the files");
sync_default(&cfg, &dir).await.unwrap();
assert!(dir.join("two.txt").exists());
// local changes block switching, nothing is damaged
std::fs::write(dir.join("one.txt"), "edited").unwrap();
sync_default(&cfg, &dir).await.unwrap();
assert_eq!(std::fs::read_to_string(dir.join("one.txt")).unwrap(), "edited");
let _ = std::fs::remove_dir_all(&root);
}
#[test]
fn pr_numbers_come_from_urls() {
assert_eq!(pr_number("https://g.example/o/r/pulls/72"), 72);
assert_eq!(pr_number("https://g.example/o/r/-/merge_requests/5/"), 5);
assert_eq!(pr_number(""), 0);
}
#[test]
fn busy_guard_blocks_a_second_pass() {
let a = busy("https://g.example/o/busy-test");
assert!(a.is_some());
assert!(busy("https://g.example/o/busy-test").is_none());
drop(a);
assert!(busy("https://g.example/o/busy-test").is_some());
}
}
+4 -2
View File
@@ -174,7 +174,8 @@ fn parse_status(raw: &str) -> Value {
pub async fn handle(Extension(user): Extension<User>, State(app): State<AppState>, Json(b): Json<GitBody>) -> ApiResult {
let spec = crate::sandbox::spec_for(&app, Some(&user.id));
let cfg = crate::gitcreds::global_config(&app, &user);
let env = crate::gitcreds::identity_env(&app, &user.id);
let mut env = crate::gitcreds::identity_env(&app, &user.id);
env.extend(crate::sshkeys::env(&app, &user));
SANDBOX.scope(spec, GITCONFIG.scope(cfg, GITENV.scope(env, handle_inner(user, app, b)))).await
}
@@ -401,7 +402,8 @@ fn wt_str<'a>(wt: &'a Value, key: &str) -> &'a str {
pub async fn worktree(app: &std::sync::Arc<App>, user: &User, session: &mut crate::types::Session, action: &str) -> Result<Value, ApiError> {
let spec = crate::sandbox::spec_for(app, Some(&user.id));
let cfg = crate::gitcreds::global_config(app, user);
let env = crate::gitcreds::identity_env(app, &user.id);
let mut env = crate::gitcreds::identity_env(app, &user.id);
env.extend(crate::sshkeys::env(app, user));
let s = session.clone();
let res = SANDBOX.scope(spec, GITCONFIG.scope(cfg, GITENV.scope(env, worktree_inner(s, action)))).await?;
if let Some(cwd) = res.get("cwd").and_then(|v| v.as_str()) {
+5
View File
@@ -13,6 +13,8 @@ mod config;
mod digest;
mod docs;
mod export;
mod factory;
mod factory_version;
mod files;
mod git;
mod health;
@@ -24,6 +26,7 @@ mod lsp;
mod mentions;
mod metrics;
mod mcp;
mod mcp_bridge;
mod media;
mod mesh3d;
mod permission;
@@ -34,6 +37,7 @@ mod reverse;
mod runner;
mod sandbox;
mod shells;
mod sshkeys;
mod stats_export;
mod store;
mod telegram;
@@ -76,6 +80,7 @@ async fn main() -> Result<()> {
push::spawn_listener(app.clone());
terminal::spawn_reaper(app.clone());
jobs::spawn_scheduler(app.clone());
factory::spawn(app.clone());
update::spawn_checker(app.clone());
health::spawn_checker(app.clone());
digest::spawn(app.clone());
+252
View File
@@ -0,0 +1,252 @@
//! CodeCraft's tools for the Claude Code CLI, as an MCP server (streamable HTTP, JSON answers).
//!
//! The CLI only knows its own tools. For every run the server registers a secret token and
//! passes `--mcp-config` with `http://127.0.0.1:<port>/api/mcp-bridge/<token>`; the CLI then
//! lists and calls the tools like any MCP tool (`mcp__codecraft__<name>`). The token is the
//! credential (the route is public) and binds the calls to the chat that started the run.
//! Permissions are asked by the CLI through the usual `can_use_tool` request, so the approval
//! cards, rules and project approvals work as for the CLI's own tools.
use crate::app::App;
use crate::tools::{Tool, ToolCtx, ToolOutput};
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use axum::Json;
use serde_json::{Value, json};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, LazyLock, Mutex};
use tokio_util::sync::CancellationToken;
pub const SERVER: &str = "codecraft";
/// Prefix the CLI gives our tools.
pub const PREFIX: &str = "mcp__codecraft__";
/// Our tools the CLI brings itself (same job): not offered twice.
const CLI_HAS: &[&str] = &["read", "write", "edit", "list", "glob", "grep", "bash", "bash_output", "kill_shell", "web_fetch", "web_search", "todo_write", "task", "change_directory"];
static TOKENS: LazyLock<Mutex<HashMap<String, String>>> = LazyLock::new(Default::default);
/// A registered run; the token stops working when this is dropped.
pub struct Registration {
pub token: String,
}
impl Drop for Registration {
fn drop(&mut self) {
TOKENS.lock().unwrap().remove(&self.token);
}
}
pub fn register(session_id: &str) -> Registration {
let token = format!("{}{}", crate::types::new_id(), crate::types::new_id());
TOKENS.lock().unwrap().insert(token.clone(), session_id.to_string());
Registration { token }
}
/// `--mcp-config` value for a run.
pub fn config_json(app: &App, token: &str) -> String {
let port = app.config().server.bind.rsplit(':').next().and_then(|p| p.parse::<u16>().ok()).unwrap_or(8787);
json!({"mcpServers": {SERVER: {"type": "http", "url": format!("http://127.0.0.1:{port}/api/mcp-bridge/{token}")}}}).to_string()
}
/// The tools the CLI gets for a chat: what the chat's own agent would have (mode, images,
/// the server's MCP tools …) without the ones the CLI has itself.
pub fn tools_for(app: &Arc<App>, session: &crate::types::Session) -> Vec<Arc<dyn Tool>> {
let cwd = PathBuf::from(&session.cwd);
let root = app.root_for(session.owner_id.as_deref(), &cwd);
let agent = crate::prompts::find_agent_for(app, &root, &cwd, &session.agent, session.owner_id.as_deref());
let owner = session.owner_id.as_deref().and_then(|id| app.store.user(id).ok().flatten());
crate::runner::available_tools(app, &agent, owner.as_ref()).into_iter().filter(|t| !CLI_HAS.contains(&t.name())).collect()
}
/// Short note for the system prompt: what the extra tools are called.
pub fn prompt_section(tools: &[Arc<dyn Tool>]) -> Option<String> {
if tools.is_empty() {
return None;
}
let names: Vec<String> = tools.iter().map(|t| format!("{PREFIX}{}", t.name())).collect();
Some(format!(
"\n# CodeCraft tools\nBesides your own tools you have the tools of the CodeCraft server (MCP server `{SERVER}`): {}. \
Use them for what they do – e.g. image generation (generate_image), 3D models, OpenSCAD, scheduling automations, diagnostics, the browser. \
If one is not in your tool list, load it with ToolSearch (query `select:<name>`).\n",
names.join(", ")
))
}
// --- protocol ----------------------------------------------------------------------------
fn tools_list(tools: &[Arc<dyn Tool>]) -> Value {
json!({"tools": tools.iter().map(|t| json!({"name": t.name(), "description": t.description(), "inputSchema": t.schema()})).collect::<Vec<_>>()})
}
fn call_result(res: anyhow::Result<ToolOutput>) -> Value {
match res {
Ok(out) => {
let mut content = vec![json!({"type": "text", "text": out.content})];
for img in out.images.iter().filter(|i| !i.data.is_empty()) {
content.push(json!({"type": "image", "data": img.data, "mimeType": img.media_type}));
}
json!({"content": content, "isError": out.is_error})
}
Err(e) => json!({"content": [{"type": "text", "text": format!("Error: {e:#}")}], "isError": true}),
}
}
fn answer(id: &Value, result: Value) -> Response {
Json(json!({"jsonrpc": "2.0", "id": id, "result": result})).into_response()
}
fn failure(id: &Value, code: i64, message: &str) -> Response {
Json(json!({"jsonrpc": "2.0", "id": id, "error": {"code": code, "message": message}})).into_response()
}
pub async fn handle(State(app): State<Arc<App>>, Path(token): Path<String>, Json(req): Json<Value>) -> Response {
let Some(session_id) = TOKENS.lock().unwrap().get(&token).cloned() else {
return (StatusCode::NOT_FOUND, "unknown or finished run").into_response();
};
let id = req["id"].clone();
let method = req["method"].as_str().unwrap_or("");
// Notifications have no answer.
if req.get("id").is_none() || method.starts_with("notifications/") {
return StatusCode::ACCEPTED.into_response();
}
match method {
"initialize" => answer(
&id,
json!({
"protocolVersion": req["params"]["protocolVersion"].as_str().unwrap_or("2025-03-26"),
"capabilities": {"tools": {"listChanged": false}},
"serverInfo": {"name": "codecraft", "version": env!("CARGO_PKG_VERSION")},
}),
),
"ping" => answer(&id, json!({})),
"tools/list" | "tools/call" => {
let Ok(session) = app.session(&session_id) else { return failure(&id, -32000, "the chat is gone") };
let tools = tools_for(&app, &session);
if method == "tools/list" {
return answer(&id, tools_list(&tools));
}
let name = req["params"]["name"].as_str().unwrap_or("");
let Some(tool) = tools.iter().find(|t| t.name() == name).cloned() else {
return failure(&id, -32602, &format!("unknown tool '{name}'"));
};
let cwd = PathBuf::from(&session.cwd);
let agent = crate::prompts::find_agent_for(&app, &app.root_for(session.owner_id.as_deref(), &cwd), &cwd, &session.agent, session.owner_id.as_deref());
let ctx = ToolCtx {
app: app.clone(),
session_id: session_id.clone(),
call_id: crate::types::new_id(),
cwd,
cancel: CancellationToken::new(),
agent: agent.name.clone(),
roots: app.user_roots(session.owner_id.as_deref()),
sandbox: crate::sandbox::spec_for(&app, session.owner_id.as_deref()),
clean_room: session.clean_room(app.config().craft.clean_room) && agent.name == "craft",
owner_id: None,
};
let input = req["params"]["arguments"].clone();
let input = if input.is_null() { json!({}) } else { input };
answer(&id, call_result(tool.run(input, &ctx).await))
}
_ => failure(&id, -32601, "method not found"),
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::ImageData;
#[test]
fn registration_lives_as_long_as_the_run() {
let r = register("s1");
assert_eq!(TOKENS.lock().unwrap().get(&r.token).map(String::as_str), Some("s1"));
let t = r.token.clone();
drop(r);
assert!(!TOKENS.lock().unwrap().contains_key(&t));
}
#[test]
fn tool_results_carry_text_and_images() {
let out = ToolOutput {
content: "saved".into(),
images: vec![ImageData { media_type: "image/png".into(), data: "QUJD".into(), blob: None, size: None }, ImageData { media_type: "image/png".into(), data: String::new(), blob: Some("x".into()), size: None }],
..Default::default()
};
let v = call_result(Ok(out));
assert_eq!(v["isError"], false);
let c = v["content"].as_array().unwrap();
assert_eq!(c.len(), 2); // the image without data is left out
assert_eq!((c[1]["type"].as_str(), c[1]["mimeType"].as_str()), (Some("image"), Some("image/png")));
assert_eq!(call_result(Err(anyhow::anyhow!("boom")))["isError"], true);
}
#[test]
fn cli_builtins_are_not_offered_twice() {
let all = crate::tools::builtin_tools();
let ours: Vec<&str> = all.iter().map(|t| t.name()).filter(|n| !CLI_HAS.contains(n)).collect();
for n in ["generate_image", "generate_3d", "openscad", "browser", "schedule", "remember", "diagnostics", "ask_user", "skill"] {
assert!(ours.contains(&n), "{n} missing");
}
assert!(!ours.contains(&"read") && !ours.contains(&"bash"));
let list = tools_list(&all.into_iter().filter(|t| t.name() == "remember").collect::<Vec<_>>());
assert!(list["tools"][0]["inputSchema"].is_object());
}
/// The whole protocol against a real App: initialize, list, call, unknown token.
#[tokio::test]
async fn protocol_roundtrip_with_a_real_app() {
let dir = std::env::temp_dir().join(format!("cc-bridge-{}", std::process::id()));
std::fs::create_dir_all(dir.join("ws")).unwrap();
let toml = crate::config::EXAMPLE_CONFIG.lines().map(|l| {
if l.starts_with("workspace = ") { format!("workspace = \"{}\"", dir.join("ws").display()) }
else if l.starts_with("data_dir = ") { format!("data_dir = \"{}\"", dir.join("data").display()) }
else { l.to_string() }
}).collect::<Vec<_>>().join("\n");
let cfg = crate::config::Config::parse(&toml).unwrap();
let app = App::new(dir.join("config.toml"), cfg).await.unwrap();
let now = crate::types::now_ms();
let session = crate::types::Session {
id: crate::types::new_id(), title: String::new(), cwd: dir.join("ws").display().to_string(), model: "x/y".into(), agent: "build".into(), permission_mode: "bypass".into(),
parent_id: None, owner_id: None, created_at: now, updated_at: now, todos: Value::Null, last_usage: None, clean_room: None, phase: None, worktree: None,
pinned: false, archived: false, folder: None, instructions: String::new(), telegram_quiet: true, summary: String::new(), color: None, icon: None,
};
let session = app.save_session(session).unwrap();
let reg = register(&session.id);
let rpc = |req: Value| {
let app = app.clone();
let token = reg.token.clone();
async move {
let resp = handle(State(app), Path(token), Json(req)).await;
let status = resp.status();
let bytes = axum::body::to_bytes(resp.into_body(), 1 << 20).await.unwrap();
(status, serde_json::from_slice::<Value>(&bytes).unwrap_or(Value::Null))
}
};
let (st, init) = rpc(json!({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18"}})).await;
assert_eq!(st, StatusCode::OK);
assert_eq!(init["result"]["protocolVersion"], "2025-06-18");
assert!(init["result"]["capabilities"]["tools"].is_object());
let (st, _) = rpc(json!({"jsonrpc": "2.0", "method": "notifications/initialized"})).await;
assert_eq!(st, StatusCode::ACCEPTED);
let (_, list) = rpc(json!({"jsonrpc": "2.0", "id": 2, "method": "tools/list"})).await;
let names: Vec<&str> = list["result"]["tools"].as_array().unwrap().iter().map(|t| t["name"].as_str().unwrap()).collect();
assert!(names.contains(&"remember") && names.contains(&"openscad") && names.contains(&"browser"), "{names:?}");
assert!(!names.contains(&"read") && !names.contains(&"bash"), "{names:?}");
// A real tool call: `remember` writes the project memory.
let (_, call) = rpc(json!({"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "remember", "arguments": {"note": "bridge works"}}})).await;
assert_eq!(call["result"]["isError"], false, "{call}");
let mem = std::fs::read_to_string(dir.join("ws/.codecraft/memory.md")).unwrap_or_default();
assert!(mem.contains("bridge works"), "{mem}");
let (_, bad) = rpc(json!({"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "bash", "arguments": {"command": "id"}}})).await;
assert!(bad["error"].is_object());
// A finished run's token is dead.
let token = reg.token.clone();
drop(reg);
let resp = handle(State(app.clone()), Path(token), Json(json!({"jsonrpc": "2.0", "id": 5, "method": "ping"}))).await;
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
let _ = std::fs::remove_dir_all(&dir);
}
}
+3
View File
@@ -301,6 +301,9 @@ pub fn system_prompt(app: &App, agent: &Agent, root: &Path, cwd: &Path, model: &
if let Some(git) = owner.and_then(|u| crate::gitcreds::prompt_section(app, &u.id)) {
s.push_str(&git);
}
if let Some(ssh) = owner.and_then(|u| crate::sshkeys::prompt_section(app, &u.id)) {
s.push_str(&ssh);
}
match std::fs::read_to_string(cwd.join(".codecraft").join("memory.md")) {
Ok(mem) => s.push_str(&format!("\n# Project memory\nFacts learned earlier in this project (keep it current with the remember tool):\n{}\n", mem.chars().take(20_000).collect::<String>())),
Err(_) if !agent.read_only => s.push_str("\n# Project memory\nWhen you learn something lasting about this project (how to build/test, conventions, pitfalls), save it with the remember tool.\n"),
+8 -1
View File
@@ -132,7 +132,10 @@ pub fn bwrap_args(spec: &SandboxSpec, cwd: &Path, extra_ro: &[&Path], new_sessio
if new_session {
push(&[&"--new-session"]);
}
let path = format!("{home}/.local/bin:{home}/.cargo/bin:{home}/.npm-global/bin:/usr/local/bin:/usr/bin:/bin");
// SSH wrappers (user's keys); only when keys are set up.
let ssh_wrapper = spec.home.join(crate::sshkeys::SANDBOX_BIN).join("ssh");
let ssh_bin = format!("{home}/{}", crate::sshkeys::SANDBOX_BIN);
let path = format!("{}{home}/.local/bin:{home}/.cargo/bin:{home}/.npm-global/bin:/usr/local/bin:/usr/bin:/bin", if ssh_wrapper.exists() { format!("{ssh_bin}:") } else { String::new() });
let npm = format!("{home}/.npm-global");
let pipx = format!("{home}/.local/pipx");
let pipx_bin = format!("{home}/.local/bin");
@@ -152,6 +155,10 @@ pub fn bwrap_args(spec: &SandboxSpec, cwd: &Path, extra_ro: &[&Path], new_sessio
] {
push(&[&"--setenv", &k, &v]);
}
if ssh_wrapper.exists() {
let cmd = format!("{ssh_bin}/ssh");
push(&[&"--setenv", &"GIT_SSH_COMMAND", &cmd]);
}
for (k, v) in &spec.env {
push(&[&"--setenv", k, v]);
}
+299
View File
@@ -0,0 +1,299 @@
//! Per-user SSH keys for agents, terminals and the git panel.
//!
//! The keys live in the database and are rendered into the user's home (`.ssh/`), like the git
//! credentials. OpenSSH takes `~` from the passwd entry, not from `$HOME`, so plain `ssh` would
//! not look into the sandbox home. A small `ssh`/`scp`/`sftp` wrapper directory goes first in PATH
//! and applies the managed config with `-F`; `GIT_SSH_COMMAND` points at the wrapper. Two
//! variants: one for the sandbox (paths through `${HOME}`) and one for unsandboxed runs (admins;
//! absolute host paths).
use crate::app::App;
use crate::store::User;
use anyhow::{Context, Result, anyhow, bail};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use tokio::process::Command;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SshKey {
pub id: String,
pub name: String,
pub public: String,
pub fingerprint: String,
/// OpenSSH private key (never sent to the UI).
#[serde(default)]
pub private: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SshSettings {
#[serde(default)]
pub keys: Vec<SshKey>,
}
/// Keys without the private part, for the UI.
pub fn masked(s: &SshSettings) -> Vec<SshKey> {
s.keys.iter().map(|k| SshKey { private: String::new(), ..k.clone() }).collect()
}
fn ssh_dir(home: &Path) -> PathBuf {
home.join(".ssh")
}
/// Wrappers for unsandboxed runs.
fn bin_dir(home: &Path) -> PathBuf {
home.join(".codecraft-bin")
}
/// Wrappers inside the sandbox (see `sandbox::bwrap_args`).
pub const SANDBOX_BIN: &str = ".codecraft-sbin";
fn key_file(id: &str) -> String {
format!("codecraft_{id}")
}
/// SSH client config. `sandbox`: paths through `${HOME}` (the home is mounted at a different
/// place there); otherwise absolute paths below `home` (wrapper for unsandboxed runs).
pub fn render_config(keys: &[SshKey], home: &Path, sandbox: bool) -> String {
let mut c = String::from("# Managed by CodeCraft (Settings → Account → SSH keys). Do not edit.\nHost *\n");
for k in keys {
if sandbox {
c.push_str(&format!("\tIdentityFile ${{HOME}}/.ssh/{}\n", key_file(&k.id)));
} else {
c.push_str(&format!("\tIdentityFile {}\n", ssh_dir(home).join(key_file(&k.id)).display()));
}
}
// Trust a host on first contact and refuse changed keys afterwards.
c.push_str("\tStrictHostKeyChecking accept-new\n\tServerAliveInterval 30\n");
if sandbox {
c.push_str("\tUserKnownHostsFile ${HOME}/.ssh/known_hosts\n");
} else {
c.push_str(&format!("\tUserKnownHostsFile {}\n", ssh_dir(home).join("known_hosts").display()));
}
c
}
#[cfg(unix)]
fn chmod(p: &Path, mode: u32) -> Result<()> {
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(p, std::fs::Permissions::from_mode(mode))?;
Ok(())
}
#[cfg(not(unix))]
fn chmod(_: &Path, _: u32) -> Result<()> {
Ok(())
}
/// Write keys, config and wrappers into the user's home (removes files of deleted keys).
pub fn write_files(app: &App, user: &User, s: &SshSettings) -> Result<()> {
let home = crate::gitcreds::home_of(app, user);
let dir = ssh_dir(&home);
std::fs::create_dir_all(&dir)?;
chmod(&dir, 0o700)?;
// Old key files.
for e in std::fs::read_dir(&dir)?.flatten() {
let n = e.file_name().to_string_lossy().into_owned();
if n.starts_with("codecraft_") && !s.keys.iter().any(|k| n == key_file(&k.id) || n == format!("{}.pub", key_file(&k.id))) {
let _ = std::fs::remove_file(e.path());
}
}
if s.keys.is_empty() {
// No keys: no wrappers either, ssh behaves as usual.
let _ = std::fs::remove_dir_all(bin_dir(&home));
let _ = std::fs::remove_dir_all(home.join(SANDBOX_BIN));
for f in ["config-sandbox", "config-host"] {
let _ = std::fs::remove_file(dir.join(f));
}
return Ok(());
}
for k in &s.keys {
let p = dir.join(key_file(&k.id));
// The file is replaced, not appended: remove it first so the mode applies.
let _ = std::fs::remove_file(&p);
std::fs::write(&p, &k.private)?;
chmod(&p, 0o600)?;
let pubp = dir.join(format!("{}.pub", key_file(&k.id)));
std::fs::write(&pubp, format!("{}\n", k.public.trim()))?;
chmod(&pubp, 0o644)?;
}
// The user's own ~/.ssh/config (if any) is included after the managed part.
let own = dir.join("config");
let sandbox_cfg = dir.join("config-sandbox");
std::fs::write(&sandbox_cfg, format!("{}\nInclude /home/{}/.ssh/config\n", render_config(&s.keys, &home, true), user.username))?;
chmod(&sandbox_cfg, 0o600)?;
let host_cfg = dir.join("config-host");
std::fs::write(&host_cfg, format!("{}\nInclude {}\n", render_config(&s.keys, &home, false), own.display()))?;
chmod(&host_cfg, 0o600)?;
for (bin, config) in [(bin_dir(&home), format!("'{}'", host_cfg.display())), (home.join(SANDBOX_BIN), "\"$HOME/.ssh/config-sandbox\"".to_string())] {
std::fs::create_dir_all(&bin)?;
for name in ["ssh", "scp", "sftp"] {
// The image's /usr/local/bin wrappers cope with a uid without passwd entry.
let local = format!("/usr/local/bin/{name}");
let real = if Path::new(&local).exists() { local } else { format!("/usr/bin/{name}") };
let p = bin.join(name);
std::fs::write(&p, format!("#!/bin/sh\nexec {real} -F {config} \"$@\"\n"))?;
chmod(&p, 0o755)?;
}
}
Ok(())
}
/// Environment for processes that run without the sandbox: the wrappers first in PATH, git over
/// SSH through the wrapper. Empty when the user has no keys.
pub fn env(app: &App, user: &User) -> Vec<(String, String)> {
let s: SshSettings = app.store.user_setting(&user.id, "ssh").unwrap_or_default();
if s.keys.is_empty() {
return Vec::new();
}
let bin = bin_dir(&crate::gitcreds::home_of(app, user));
if !bin.join("ssh").exists() {
return Vec::new();
}
let path = format!("{}:{}", bin.display(), std::env::var("PATH").unwrap_or_else(|_| "/usr/local/bin:/usr/bin:/bin".into()));
vec![("PATH".into(), path), ("GIT_SSH_COMMAND".into(), bin.join("ssh").display().to_string())]
}
/// What an agent needs to know (public keys only). None without keys.
pub fn prompt_section(app: &App, user_id: &str) -> Option<String> {
render_prompt(&app.store.user_setting(user_id, "ssh").unwrap_or_default())
}
fn render_prompt(s: &SshSettings) -> Option<String> {
if s.keys.is_empty() {
return None;
}
let names: Vec<&str> = s.keys.iter().map(|k| k.name.as_str()).collect();
Some(format!(
"\n# SSH access\nThe user has SSH keys set up ({}). `ssh`, `scp`, `sftp`, `rsync -e ssh` and `git` over ssh:// or git@host use them automatically – \
no password, no `ssh-add`, no agent. A host is trusted on first contact. Do NOT generate new keys or search for keys or passwords; \
if a server refuses the connection, tell the user that their public key must be added to the server's authorized_keys. \
Commands run without a terminal, so password or passphrase prompts fail.\n",
names.join(", ")
))
}
// --- creating keys ---------------------------------------------------------------------
async fn keygen(args: &[&str], stdin: Option<&str>) -> Result<String> {
let mut cmd = Command::new("ssh-keygen");
cmd.args(args).env_clear().env("PATH", std::env::var("PATH").unwrap_or_default()).stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::piped());
let mut child = cmd.spawn().context("ssh-keygen is not installed on the server")?;
if let Some(mut si) = child.stdin.take() {
use tokio::io::AsyncWriteExt;
if let Some(t) = stdin {
let _ = si.write_all(t.as_bytes()).await;
}
}
let out = tokio::time::timeout(std::time::Duration::from_secs(20), child.wait_with_output()).await.map_err(|_| anyhow!("ssh-keygen timed out"))??;
if !out.status.success() {
bail!("{}", String::from_utf8_lossy(&out.stderr).trim());
}
Ok(String::from_utf8_lossy(&out.stdout).into_owned())
}
fn temp_dir() -> Result<PathBuf> {
let d = std::env::temp_dir().join(format!("cc-ssh-{}", crate::types::new_id()));
std::fs::create_dir_all(&d)?;
chmod(&d, 0o700)?;
Ok(d)
}
/// A new ed25519 key without passphrase.
pub async fn generate(name: &str) -> Result<SshKey> {
let d = temp_dir()?;
let f = d.join("key");
let comment = format!("codecraft-{}", name.replace(char::is_whitespace, "-"));
let res = async {
keygen(&["-q", "-t", "ed25519", "-N", "", "-C", &comment, "-f", &f.to_string_lossy()], None).await?;
let private = std::fs::read_to_string(&f)?;
let public = std::fs::read_to_string(d.join("key.pub"))?;
finish(name, private, public.trim().to_string()).await
}
.await;
let _ = std::fs::remove_dir_all(&d);
res
}
/// An existing private key (OpenSSH or PEM, without passphrase).
pub async fn import(name: &str, private: &str) -> Result<SshKey> {
let mut text = private.trim().replace("\r\n", "\n");
if !text.starts_with("-----BEGIN ") || !text.contains("PRIVATE KEY-----") {
bail!("that does not look like a private key (-----BEGIN … PRIVATE KEY-----)");
}
text.push('\n');
let d = temp_dir()?;
let f = d.join("key");
let res = async {
std::fs::write(&f, &text)?;
chmod(&f, 0o600)?;
let public = keygen(&["-y", "-P", "", "-f", &f.to_string_lossy()], None).await.map_err(|e| anyhow!("cannot read the key (keys with a passphrase are not supported): {e}"))?;
finish(name, text.clone(), public.trim().to_string()).await
}
.await;
let _ = std::fs::remove_dir_all(&d);
res
}
async fn finish(name: &str, private: String, public: String) -> Result<SshKey> {
let fp = keygen(&["-l", "-f", "-"], Some(&format!("{public}\n"))).await.unwrap_or_default();
let fingerprint = fp.split_whitespace().nth(1).unwrap_or("").to_string();
Ok(SshKey { id: crate::types::new_id().chars().take(10).collect(), name: name.to_string(), public, fingerprint, private })
}
#[cfg(test)]
mod tests {
use super::*;
fn key(id: &str) -> SshKey {
SshKey { id: id.into(), name: "laptop".into(), public: "ssh-ed25519 AAAA x".into(), fingerprint: "SHA256:x".into(), private: "SECRET".into() }
}
#[test]
fn config_has_both_path_styles() {
let home = Path::new("/data/users/ann/home");
let t = render_config(&[key("k1")], home, true);
assert!(t.contains("IdentityFile ${HOME}/.ssh/codecraft_k1") && t.contains("UserKnownHostsFile ${HOME}/.ssh/known_hosts"));
assert!(t.contains("StrictHostKeyChecking accept-new"));
let a = render_config(&[key("k1")], home, false);
assert!(a.contains("IdentityFile /data/users/ann/home/.ssh/codecraft_k1"));
assert!(a.contains("UserKnownHostsFile /data/users/ann/home/.ssh/known_hosts"));
}
#[test]
fn sandbox_config_resolves_through_home() {
if std::process::Command::new("ssh").arg("-V").output().is_err() {
return;
}
let d = std::env::temp_dir().join(format!("cc-sshcfg-{}", std::process::id()));
std::fs::create_dir_all(&d).unwrap();
let cfg = d.join("cfg");
std::fs::write(&cfg, render_config(&[key("k1")], Path::new("/unused"), true)).unwrap();
let out = std::process::Command::new("ssh").arg("-F").arg(&cfg).args(["-G", "example.org"]).env("HOME", "/sandbox/home").output().unwrap();
let text = String::from_utf8_lossy(&out.stdout).to_lowercase();
// `-G` shows identity files unexpanded (expanded when used, ssh_config(5)).
assert!(text.contains("identityfile ${home}/.ssh/codecraft_k1"), "{text}");
assert!(text.contains("userknownhostsfile /sandbox/home/.ssh/known_hosts"), "{text}");
std::fs::remove_dir_all(&d).unwrap();
}
#[test]
fn prompt_and_ui_view_never_contain_the_private_key() {
let s = SshSettings { keys: vec![key("k1")] };
assert!(masked(&s).iter().all(|k| k.private.is_empty()));
let p = render_prompt(&s).unwrap();
assert!(p.contains("laptop") && !p.contains("SECRET"));
assert!(render_prompt(&SshSettings::default()).is_none());
}
#[tokio::test]
async fn generated_and_imported_keys_match() {
if std::process::Command::new("ssh-keygen").arg("-?").output().is_err() {
return; // not installed here
}
let k = generate("test key").await.unwrap();
assert!(k.public.starts_with("ssh-ed25519 ") && k.fingerprint.starts_with("SHA256:") && k.private.contains("PRIVATE KEY"));
let again = import("copy", &k.private).await.unwrap();
assert_eq!(again.fingerprint, k.fingerprint);
assert!(import("bad", "hello").await.is_err());
}
}
+205
View File
@@ -171,6 +171,55 @@ impl Store {
expires_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS share_links_session ON share_links(session_id);
CREATE TABLE IF NOT EXISTS factory_issues (
repo_url TEXT NOT NULL,
number INTEGER NOT NULL,
owner_id TEXT NOT NULL,
title TEXT NOT NULL DEFAULT '',
author TEXT NOT NULL DEFAULT '',
state TEXT NOT NULL DEFAULT 'new',
attempts INTEGER NOT NULL DEFAULT 0,
rounds INTEGER NOT NULL DEFAULT 0,
last_comment INTEGER NOT NULL DEFAULT 0,
scenarios TEXT NOT NULL DEFAULT '',
branch TEXT NOT NULL DEFAULT '',
pr_url TEXT NOT NULL DEFAULT '',
note TEXT NOT NULL DEFAULT '',
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
PRIMARY KEY (repo_url, number)
);
CREATE TABLE IF NOT EXISTS factory_runs (
id TEXT PRIMARY KEY,
owner_id TEXT NOT NULL,
repo_url TEXT NOT NULL,
issue INTEGER NOT NULL,
phase TEXT NOT NULL,
round INTEGER NOT NULL DEFAULT 0,
session_id TEXT NOT NULL,
model TEXT NOT NULL DEFAULT '',
started_at INTEGER NOT NULL,
ended_at INTEGER,
status TEXT NOT NULL DEFAULT 'running',
result TEXT NOT NULL DEFAULT ''
);
CREATE INDEX IF NOT EXISTS factory_runs_issue ON factory_runs(repo_url, issue);
CREATE TABLE IF NOT EXISTS factory_versions (
repo_url TEXT PRIMARY KEY,
current TEXT NOT NULL DEFAULT '0.0.0',
since INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS factory_releases (
id TEXT PRIMARY KEY,
owner_id TEXT NOT NULL,
repo_url TEXT NOT NULL,
version TEXT NOT NULL,
state TEXT NOT NULL DEFAULT 'running',
log TEXT NOT NULL DEFAULT '',
url TEXT NOT NULL DEFAULT '',
started_at INTEGER NOT NULL,
ended_at INTEGER
);
CREATE TABLE IF NOT EXISTS project_defaults (
cwd TEXT PRIMARY KEY,
data TEXT NOT NULL
@@ -205,6 +254,7 @@ impl Store {
("jobs", "settings", "ALTER TABLE jobs ADD COLUMN settings TEXT"),
("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 ''"),
] {
let exists: bool = conn
.prepare(&format!("SELECT 1 FROM pragma_table_info('{table}') WHERE name = ?1"))?
@@ -409,6 +459,16 @@ impl Store {
Ok(())
}
/// (title, cwd) of all other chats (subagent sessions of this chat excluded).
pub fn other_session_cwds(&self, id: &str) -> Result<Vec<(String, String)>> {
let conn = self.conn.lock().unwrap();
let mut stmt = conn.prepare(
"SELECT COALESCE(json_extract(data, '$.title'), ''), COALESCE(json_extract(data, '$.cwd'), '') FROM sessions WHERE id != ?1 AND COALESCE(parent_id, '') != ?1",
)?;
let rows = stmt.query_map([id], |r| Ok((r.get(0)?, r.get(1)?)))?;
Ok(rows.collect::<std::result::Result<_, _>>()?)
}
pub fn add_message(&self, session_id: &str, m: &Message) -> Result<()> {
// Images go to the blob table (encoded before taking the lock).
let mut m = m.clone();
@@ -1417,6 +1477,151 @@ impl Store {
Ok(())
}
// --- software factory ---------------------------------------------------------
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)?}))
})
.optional()?)
}
pub fn factory_issue_add(&self, repo: &str, number: i64, owner: &str, title: &str, author: &str) -> Result<()> {
let now = crate::types::now_ms();
self.conn.lock().unwrap().execute(
"INSERT OR IGNORE INTO factory_issues (repo_url, number, owner_id, title, author, created_at, updated_at) VALUES (?1,?2,?3,?4,?5,?6,?6)",
params![repo, number, owner, title, author, now],
)?;
Ok(())
}
/// 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"];
let conn = self.conn.lock().unwrap();
for (k, v) in fields {
if !COLS.contains(k) {
anyhow::bail!("unknown column {k}");
}
let sql = format!("UPDATE factory_issues SET {k} = ?3, updated_at = ?4 WHERE repo_url = ?1 AND number = ?2");
let now = crate::types::now_ms();
match v {
Value::Number(n) => conn.execute(&sql, params![repo, number, n.as_i64().unwrap_or(0), now])?,
other => conn.execute(&sql, params![repo, number, other.as_str().unwrap_or(""), now])?,
};
}
Ok(())
}
/// Version of a repository, None while versioning has not been started for it.
pub fn factory_version(&self, repo: &str) -> Result<Option<String>> {
Ok(self.conn.lock().unwrap().query_row("SELECT current FROM factory_versions WHERE repo_url = ?1", [repo], |r| r.get(0)).optional()?)
}
pub fn factory_version_set(&self, repo: &str, current: &str) -> Result<()> {
self.conn.lock().unwrap().execute(
"INSERT INTO factory_versions (repo_url, current, since) VALUES (?1, ?2, ?3) ON CONFLICT(repo_url) DO UPDATE SET current = ?2",
params![repo, current, crate::types::now_ms()],
)?;
Ok(())
}
pub fn factory_release_add(&self, id: &str, owner: &str, repo: &str, version: &str) -> Result<()> {
self.conn.lock().unwrap().execute(
"INSERT INTO factory_releases (id, owner_id, repo_url, version, started_at) VALUES (?1,?2,?3,?4,?5)",
params![id, owner, repo, version, crate::types::now_ms()],
)?;
Ok(())
}
/// Append a line to the log of a release (the log is capped).
pub fn factory_release_log(&self, id: &str, line: &str) -> Result<()> {
self.conn.lock().unwrap().execute(
"UPDATE factory_releases SET log = substr(log || ?2 || char(10), -30000) WHERE id = ?1",
params![id, line],
)?;
Ok(())
}
pub fn factory_release_end(&self, id: &str, state: &str, url: &str) -> Result<()> {
self.conn.lock().unwrap().execute("UPDATE factory_releases SET state = ?2, url = ?3, ended_at = ?4 WHERE id = ?1", params![id, state, url, crate::types::now_ms()])?;
Ok(())
}
pub fn factory_release_running(&self, repo: &str) -> Result<bool> {
Ok(self.conn.lock().unwrap().query_row("SELECT COUNT(*) FROM factory_releases WHERE repo_url = ?1 AND state = 'running'", [repo], |r| r.get::<_, i64>(0))? > 0)
}
pub fn factory_releases(&self, owner: &str, limit: i64) -> Result<Vec<Value>> {
let conn = self.conn.lock().unwrap();
let mut st = conn.prepare("SELECT id, repo_url, version, state, log, url, started_at, ended_at FROM factory_releases WHERE owner_id = ?1 ORDER BY started_at DESC LIMIT ?2")?;
let rows = st.query_map(params![owner, limit], |r| {
Ok(json!({"id": r.get::<_, String>(0)?, "repo": r.get::<_, String>(1)?, "version": r.get::<_, String>(2)?, "state": r.get::<_, String>(3)?, "log": r.get::<_, String>(4)?, "url": r.get::<_, String>(5)?, "started_at": r.get::<_, i64>(6)?, "ended_at": r.get::<_, Option<i64>>(7)?}))
})?;
Ok(rows.filter_map(|r| r.ok()).collect())
}
pub fn factory_issues(&self, owner: &str) -> Result<Vec<Value>> {
let nums: Vec<(String, i64)> = {
let conn = self.conn.lock().unwrap();
let mut st = conn.prepare("SELECT repo_url, number FROM factory_issues WHERE owner_id = ?1 ORDER BY updated_at DESC")?;
st.query_map([owner], |r| Ok((r.get(0)?, r.get(1)?)))?.filter_map(|r| r.ok()).collect()
};
Ok(nums.into_iter().filter_map(|(r, n)| self.factory_issue(&r, n).ok().flatten()).collect())
}
pub fn factory_run_add(&self, id: &str, owner: &str, repo: &str, issue: i64, phase: &str, round: i64, session: &str, model: &str) -> Result<()> {
self.conn.lock().unwrap().execute(
"INSERT INTO factory_runs (id, owner_id, repo_url, issue, phase, round, session_id, model, started_at) VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9)",
params![id, owner, repo, issue, phase, round, session, model, crate::types::now_ms()],
)?;
Ok(())
}
pub fn factory_run_end(&self, id: &str, status: &str, result: &str) -> Result<()> {
self.conn.lock().unwrap().execute("UPDATE factory_runs SET ended_at = ?2, status = ?3, result = ?4 WHERE id = ?1", params![id, crate::types::now_ms(), status, result])?;
Ok(())
}
pub fn factory_running(&self, repo: &str) -> Result<i64> {
Ok(self.conn.lock().unwrap().query_row("SELECT COUNT(*) FROM factory_runs WHERE repo_url = ?1 AND status = 'running'", [repo], |r| r.get(0))?)
}
/// Runs with token and cost totals (joined from the usage table).
pub fn factory_runs(&self, owner: &str, repo: Option<&str>, issue: Option<i64>, limit: i64) -> Result<Vec<Value>> {
let conn = self.conn.lock().unwrap();
let mut st = conn.prepare(
"SELECT f.id, f.repo_url, f.issue, f.phase, f.round, f.session_id, f.model, f.started_at, f.ended_at, f.status, f.result,
COALESCE((SELECT SUM(input_tokens + cache_read_tokens + cache_write_tokens) FROM usage WHERE session_id = f.session_id),0),
COALESCE((SELECT SUM(output_tokens) FROM usage WHERE session_id = f.session_id),0),
COALESCE((SELECT SUM(cost) FROM usage WHERE session_id = f.session_id),0.0)
FROM factory_runs f WHERE f.owner_id = ?1 AND (?2 IS NULL OR f.repo_url = ?2) AND (?3 IS NULL OR f.issue = ?3)
ORDER BY f.started_at DESC LIMIT ?4",
)?;
let rows = st.query_map(params![owner, repo, issue, limit], |r| {
Ok(json!({"id": r.get::<_, String>(0)?, "repo": r.get::<_, String>(1)?, "issue": r.get::<_, i64>(2)?, "phase": r.get::<_, String>(3)?, "round": r.get::<_, i64>(4)?, "session_id": r.get::<_, String>(5)?, "model": r.get::<_, String>(6)?, "started_at": r.get::<_, i64>(7)?, "ended_at": r.get::<_, Option<i64>>(8)?, "status": r.get::<_, String>(9)?, "result": r.get::<_, String>(10)?, "input_tokens": r.get::<_, i64>(11)?, "output_tokens": r.get::<_, i64>(12)?, "cost": r.get::<_, f64>(13)?}))
})?;
Ok(rows.filter_map(|r| r.ok()).collect())
}
/// After a restart: runs that were still going are over; their issues go back one step.
pub fn factory_recover(&self) -> Result<usize> {
let conn = self.conn.lock().unwrap();
let n = conn.execute("UPDATE factory_runs SET status = 'interrupted', ended_at = ?1 WHERE status = 'running'", [crate::types::now_ms()])?;
conn.execute("UPDATE factory_issues SET state = 'new' WHERE state = 'review'", [])?;
conn.execute("UPDATE factory_issues SET state = CASE WHEN rounds > 0 THEN 'rework' ELSE 'approved' END WHERE state = 'building'", [])?;
conn.execute("UPDATE factory_issues SET state = 'qa' WHERE state = 'testing'", [])?;
conn.execute("UPDATE factory_releases SET state = 'failed', ended_at = ?1, log = log || char(10) || 'interrupted by a restart' WHERE state = 'running'", [crate::types::now_ms()])?;
// All factory chats live in one sidebar folder (older ones are moved there once).
conn.execute(
"UPDATE sessions SET data = json_set(data, '$.folder', 'Factory') WHERE (json_extract(data, '$.folder') IS NULL OR json_extract(data, '$.folder') = '') AND (id IN (SELECT session_id FROM factory_runs) OR json_extract(data, '$.cwd') LIKE '%/_drafts/%')",
[],
)?;
Ok(n)
}
pub fn job_touch(&self, id: &str, ts: i64) -> Result<()> {
self.conn.lock().unwrap().execute("UPDATE jobs SET last_run = ?2 WHERE id = ?1", rusqlite::params![id, ts])?;
Ok(())
+2 -1
View File
@@ -162,7 +162,8 @@ pub fn spawn(app: &Arc<App>, user: &User, cwd: &Path, session_id: Option<String>
.current_dir(cwd)
.env("TERM", "xterm-256color")
.env("CODECRAFT", "1")
.envs(crate::gitcreds::identity_env(app, &user.id));
.envs(crate::gitcreds::identity_env(app, &user.id))
.envs(crate::sshkeys::env(app, user));
match crate::gitcreds::global_config(app, user) {
Some(cfg) => c.env("GIT_CONFIG_GLOBAL", cfg),
None => c,
+1
View File
@@ -155,6 +155,7 @@ pub fn shell_command(ctx: &ToolCtx, command: &str) -> std::result::Result<Comman
c.env("GIT_CONFIG_GLOBAL", cfg);
}
c.envs(crate::gitcreds::identity_env(&ctx.app, &u.id));
c.envs(crate::sshkeys::env(&ctx.app, &u));
}
c
}
+2
View File
@@ -13,6 +13,7 @@ import { NewSession } from "./components/NewSession";
import { Settings } from "./components/Settings";
import { Stats } from "./components/Stats";
import { Images } from "./components/Images";
import { Factory } from "./components/Factory";
import { Jobs } from "./components/Jobs";
import { JobEditor } from "./components/JobEditor";
import { Spinner, useTitleActivity } from "./components/Activity";
@@ -110,6 +111,7 @@ export function App() {
);
else if (section === "settings") content = <Settings tab={arg} onMenu={() => setMenuOpen(true)} />;
else if (section === "p" && arg) content = <ProjectPage key={arg} cwd={decodeURIComponent(arg)} onMenu={() => setMenuOpen(true)} />;
else if (section === "factory") content = <Factory onMenu={() => setMenuOpen(true)} />;
else if (section === "stats") content = <Stats onMenu={() => setMenuOpen(true)} />;
else if (section === "images") content = <Images onMenu={() => setMenuOpen(true)} />;
else if (section === "jobs" && arg) content = <JobEditor key={arg} id={arg} onMenu={() => setMenuOpen(true)} />;
+46
View File
@@ -0,0 +1,46 @@
import { del, get } from "./api";
import { choiceDialog, confirmDialog, toast } from "./dialogs";
import { t } from "./i18n";
import { formatSize } from "./components/FileFigure";
interface FolderInfo {
own: boolean;
path?: string;
files?: number;
bytes?: number;
git?: boolean;
truncated?: boolean;
}
/**
* Delete a chat after asking. A chat with a folder of its own (not shared with other chats, not a
* project) gets the question whether the folder goes with it. Resolves to true when it was deleted.
*/
export async function deleteChat(session: { id: string; parent_id?: string | null }): Promise<boolean> {
const folder = session.parent_id ? undefined : await get<FolderInfo>(`/sessions/${session.id}/folder`).catch(() => undefined);
let withFolder = false;
if (folder?.own) {
const size = `${folder.truncated ? "> " : ""}${t("chat.folderFiles", { n: folder.files ?? 0 })}, ${formatSize(folder.bytes ?? 0)}`;
const choice = await choiceDialog({
title: t("chat.deleteTitle"),
message: `${t("chat.deleteWithFolder", { path: folder.path ?? "", size })}${folder.git ? `\n\n${t("chat.folderHasGit")}` : ""}`,
choices: [
{ value: "chat", label: t("chat.deleteOnlyChat") },
{ value: "both", label: t("chat.deleteChatAndFolder"), danger: true },
],
});
if (!choice) return false;
withFolder = choice === "both";
} else if (!(await confirmDialog({ message: t("chat.deleteConfirm"), danger: true, confirmLabel: t("common.delete") }))) {
return false;
}
try {
const r = await del<{ folder_deleted?: boolean; folder_error?: string }>(`/sessions/${session.id}${withFolder ? "?delete_folder=true" : ""}`);
if (r?.folder_error) toast(r.folder_error);
else if (r?.folder_deleted) toast(t("chat.folderDeleted"), "success");
return true;
} catch (e: any) {
toast(e.message);
return false;
}
}
+6 -4
View File
@@ -1,3 +1,4 @@
import { DraftBar, IssueBar, isDraftChat, isIssueChat } from "./FactoryDraft";
import { takePrefill } from "../share";
import { Icon } from "./Icon";
import { FileChip, FileFigure, fileType, imageSize, imageSrc } from "./FileFigure";
@@ -24,7 +25,8 @@ import { UsageOverlay } from "./UsageOverlay";
import { RewindDialog } from "./RewindDialog";
import { ShellsChip } from "./ShellsPanel";
import { TodoList, ToolCard } from "./ToolCard";
import { confirmDialog, promptDialog, toast } from "../dialogs";
import { promptDialog, toast } from "../dialogs";
import { deleteChat } from "../chatActions";
import { ChatTabBar, ChatTabPanes, useChatTabs } from "./ChatTabs";
import { ColorSwatches, IconPicker } from "./ColorSwatches";
import { ProjectPermissions } from "./ProjectPermissions";
@@ -757,9 +759,7 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
};
const remove = async () => {
if (!(await confirmDialog({ message: t("chat.deleteConfirm"), danger: true, confirmLabel: t("common.delete") }))) return;
await del(`/sessions/${sessionId}`);
navigate(session.parent_id ? `/s/${session.parent_id}` : "/new");
if (await deleteChat(session)) navigate(session.parent_id ? `/s/${session.parent_id}` : "/new");
};
// Context usage of the last request relative to the model's window.
@@ -1090,6 +1090,8 @@ export function ChatView({ sessionId, onMenu, onClosePane }: { sessionId: string
{editingTitle && <RenameDialog sessionId={sessionId} title={session.title} onClose={() => setEditingTitle(false)} />}
{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 ? (
+850
View File
@@ -0,0 +1,850 @@
import { useEffect, useMemo, useState } from "react";
import { get, post, put } from "../api";
import { fmtCompact, fmtCost, fmtRelative, useT } from "../i18n";
import { navigate } from "../router";
import { choiceDialog, confirmDialog, promptDialog, toast } from "../dialogs";
import { Icon } from "./Icon";
import { Spinner } from "./Activity";
import { ModelSelect } from "./ModelSelect";
import { ReleaseDialog, ReleasesPanel, type ReleaseRow } from "./FactoryRelease";
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"];
interface PhaseCfg {
model: string;
agent: string;
permission_mode: string;
timeout_minutes: number;
max_attempts: number;
extra_prompt: string;
}
interface RepoCfg {
url: string;
kind: string;
connection: string;
token: string;
label: string;
max_parallel: number;
max_rework: number;
allowed_users: string[];
enabled: boolean;
review: PhaseCfg;
build: PhaseCfg;
qa: PhaseCfg;
}
interface Connection {
id: string;
name: string;
kind: "gitea" | "github" | "gitlab";
url: string;
token: string;
owner: string;
}
interface Defaults {
spec_model: string;
review: PhaseCfg;
build: PhaseCfg;
qa: PhaseCfg;
}
interface Settings {
connections: Connection[];
defaults: Defaults;
repos: RepoCfg[];
}
interface Issue {
repo: string;
number: number;
title: string;
author: string;
state: string;
note: string;
pr_url: string;
branch: string;
rounds: number;
created_at: number;
updated_at: number;
}
interface Run {
id: string;
repo: string;
issue: number;
phase: Phase;
round: number;
session_id: string;
model: string;
started_at: number;
ended_at: number | null;
status: string;
input_tokens: number;
output_tokens: number;
cost: number;
}
interface RepoInfo {
url: string;
kind: string;
enabled: boolean;
label: string;
max_parallel: number;
has_token: boolean;
models: Record<Phase, string>;
running: number;
version?: string | null;
}
interface Overview {
area: boolean;
repos: RepoInfo[];
issues: Issue[];
runs: Run[];
releases: ReleaseRow[];
}
/** Board columns: a column collects one or more issue states. */
const COLUMNS: { id: string; states: string[] }[] = [
{ id: "review", states: ["new", "review"] },
{ id: "question", states: ["question"] },
{ id: "approved", states: ["approved"] },
{ id: "build", states: ["building", "rework"] },
{ id: "qa", states: ["qa", "testing"] },
{ id: "done", states: ["done"] },
{ id: "failed", states: ["failed", "rejected"] },
];
const KIND_NAME: Record<string, string> = { gitea: "Gitea", github: "GitHub", gitlab: "GitLab" };
const repoName = (url: string) => url.replace(/\.git$/, "").split("/").slice(-2).join("/");
const issueUrl = (repo: string, n: number) => `${repo.replace(/\.git$/, "")}/issues/${n}`;
function fmtDuration(ms: number) {
const s = Math.max(0, Math.round(ms / 1000));
if (s < 60) return `${s} s`;
const m = Math.floor(s / 60);
return m < 60 ? `${m} min ${s % 60} s` : `${Math.floor(m / 60)} h ${m % 60} min`;
}
const runMs = (r: Run, now: number) => (r.ended_at ?? now) - r.started_at;
/** Software factory: spec issues in Gitea are reviewed, built and accepted by agents with a model per phase. */
export function Factory({ onMenu }: { onMenu: () => void }) {
const t = useT();
const [tab, setTab] = useState<"overview" | "settings">("overview");
return (
<>
<div className="topbar">
<button className="ghost menu-btn" onClick={onMenu} aria-label={t("nav.menu")}>
<Icon name="menu" />
</button>
<div className="grow">
<h1>{t("factory.title")}</h1>
</div>
<div className="segmented">
{(["overview", "settings"] as const).map((x) => (
<button key={x} className={tab === x ? "active" : ""} onClick={() => setTab(x)}>
{t(`factory.tab.${x}` as any)}
</button>
))}
</div>
</div>
<div className="page">
<div className="page-inner" style={{ maxWidth: 1280 }}>
{tab === "overview" ? <FactoryOverview onSettings={() => setTab("settings")} /> : <FactorySettings />}
</div>
</div>
</>
);
}
function FactoryOverview({ onSettings }: { onSettings: () => void }) {
const t = useT();
const [data, setData] = useState<Overview>();
const [repo, setRepo] = useState<string>("");
const [sel, setSel] = useState<string>("");
const [now, setNow] = useState(Date.now());
const [busy, setBusy] = useState(false);
const reload = () =>
get<Overview>("/factory/overview")
.then(setData)
.catch((e) => toast(e.message));
useEffect(() => {
void reload();
const h = setInterval(() => {
void reload();
setNow(Date.now());
}, 5000);
return () => clearInterval(h);
}, []);
const newProject = async () => {
setBusy(true);
try {
const s = await post<{ id: string }>("/factory/drafts", {});
navigate(`/s/${s.id}`);
} catch (e: any) {
toast(e.message);
setBusy(false);
}
};
const [releaseRepo, setReleaseRepo] = useState("");
const startRelease = async () => {
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;
}
}
setReleaseRepo(target);
};
/** 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]);
const selected = issues.find((i) => `${i.repo}#${i.number}` === sel);
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]);
if (!data) return <div className="empty"><Spinner /></div>;
if (data.repos.length === 0)
return (
<div className="empty">
<p>{t("factory.empty")}</p>
<div className="row" style={{ gap: 8, justifyContent: "center" }}>
<button className="primary" onClick={newProject} disabled={busy}>
<Icon name="plus" /> {t("factory.newProject")}
</button>
<button onClick={onSettings}>{t("factory.tab.settings")}</button>
</div>
</div>
);
const sum = (f: (r: Run) => number) => runs.reduce((a, r) => a + f(r), 0);
const finished = runs.filter((r) => r.ended_at);
const running = runs.filter((r) => !r.ended_at);
const done = issues.filter((i) => i.state === "done").length;
const failed = issues.filter((i) => ["failed", "rejected"].includes(i.state)).length;
const runsOf = (i: Issue) => data.runs.filter((r) => r.repo === i.repo && r.issue === i.number);
const shown = selected ? runsOf(selected) : runs.slice(0, 12);
const poll = async () => {
setBusy(true);
try {
const r = await post<{ errors: string[] }>("/factory/poll", {});
if (r.errors.length) toast(r.errors.join("\n"));
await reload();
} catch (e: any) {
toast(e.message);
} finally {
setBusy(false);
}
};
const restart = async (to: "new" | "approved" | "qa") => {
if (!selected) return;
setBusy(true);
try {
await post("/factory/issues/restart", { repo: selected.repo, number: selected.number, to });
toast(t("factory.restarted"));
await reload();
} catch (e: any) {
toast(e.message);
} finally {
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;
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 (
<>
{!data.area && <div className="notice err">{t("factory.noArea")}</div>}
<div className="kpis">
<div className="kpi">
<div className="k-label">{t("factory.kpi.running")}</div>
<div className="k-value">{running.length}</div>
<div className="k-sub">{t("factory.kpi.issues", { n: issues.length })}</div>
</div>
<div className="kpi">
<div className="k-label">{t("factory.kpi.done")}</div>
<div className="k-value">{done}</div>
<div className="k-sub">{t("factory.kpi.failed", { n: failed })}</div>
</div>
<div className="kpi">
<div className="k-label">{t("factory.kpi.tokens")}</div>
<div className="k-value">{fmtCompact(sum((r) => r.input_tokens + r.output_tokens))}</div>
<div className="k-sub">
{fmtCompact(sum((r) => r.input_tokens))} {t("factory.in")} · {fmtCompact(sum((r) => r.output_tokens))} {t("factory.out")}
</div>
</div>
<div className="kpi">
<div className="k-label">{t("factory.kpi.cost")}</div>
<div className="k-value">{fmtCost(sum((r) => r.cost), "USD")}</div>
<div className="k-sub">{t("factory.kpi.runs", { n: runs.length })}</div>
</div>
<div className="kpi">
<div className="k-label">{t("factory.kpi.time")}</div>
<div className="k-value">{finished.length ? fmtDuration(sum((r) => runMs(r, now)) / finished.length) : "–"}</div>
<div className="k-sub">{t("factory.kpi.perRun")}</div>
</div>
</div>
<div className="factory-repos">
<button className={`factory-repo ${repo === "" ? "active" : ""}`} onClick={() => setRepo("")}>
<b>{t("factory.allRepos")}</b>
<span className="hint">{t("factory.kpi.issues", { n: data.issues.length })}</span>
</button>
{data.repos.map((r) => {
const mine = data.issues.filter((i) => i.repo === r.url);
return (
<button key={r.url} className={`factory-repo ${repo === r.url ? "active" : ""} ${r.enabled ? "" : "off"}`} onClick={() => setRepo(r.url)}>
<b>{repoName(r.url)}</b>
<span className="chip">{KIND_NAME[r.kind] ?? r.kind}</span>
{r.version && <span className="chip ok mono">v{r.version}</span>}
<span className="hint">
{r.running > 0 && <span className="factory-pulse" />}
{t("factory.repoLine", { n: mine.length, run: r.running })}
</span>
<span className="hint mono">{PHASES.map((p) => r.models[p] || "·").map((m) => m.split("/").pop()).join(" → ")}</span>
{!r.has_token && <span className="chip warn">{t("factory.noToken")}</span>}
</button>
);
})}
<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={startRelease} disabled={busy} title={t("release.hint")}>
<Icon name="download" /> {t("release.button")}
</button>
<button className="small" onClick={poll} disabled={busy} title={t("factory.pollNow")}>
<Icon name="refresh" /> {t("factory.pollNow")}
</button>
</div>
<div className="factory-board">
{COLUMNS.map((c) => {
const cards = issues.filter((i) => c.states.includes(i.state));
return (
<div key={c.id} className="factory-col">
<h4>
{t(`factory.col.${c.id}` as any)} <span className="chip">{cards.length}</span>
</h4>
{cards.map((i) => {
const rs = runsOf(i);
const active = rs.find((r) => !r.ended_at);
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}`)}>
<span className="hint">
{repoName(i.repo)} #{i.number}
</span>
<b>{i.title || `#${i.number}`}</b>
{latest && (
<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>}
</button>
);
})}
</div>
);
})}
</div>
<ReleasesPanel releases={(data.releases ?? []).filter((r) => !repo || r.repo === repo)} />
{releaseRepo && <ReleaseDialog repo={releaseRepo} onClose={() => setReleaseRepo("")} onStarted={() => void reload()} />}
<div className="panel" style={{ marginTop: 16 }}>
<div className="row">
<h3 style={{ margin: 0 }}>{selected ? `${repoName(selected.repo)} #${selected.number} – ${selected.title}` : t("factory.latestRuns")}</h3>
<span className="spacer" />
{selected && !phaseRunning && (
<>
<span className="hint">{t("factory.restartAt")}</span>
<button className="small" onClick={() => restart("new")} disabled={busy}>
{t("factory.col.review")}
</button>
<button className="small" onClick={() => restart("approved")} disabled={busy}>
{t("factory.col.build")}
</button>
<button className="small" onClick={() => restart("qa")} disabled={busy || !selected.branch}>
{t("factory.col.qa")}
</button>
</>
)}
{selected && (
<>
<a className="small ghost button-link" href={issueUrl(selected.repo, selected.number)} target="_blank" rel="noreferrer">
<Icon name="external" /> Gitea
</a>
{selected.pr_url && (
<a className="small ghost button-link" href={selected.pr_url} target="_blank" rel="noreferrer">
<Icon name="external" /> {t("factory.pr")}
</a>
)}
</>
)}
</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">
<table className="grid factory-runs">
<thead>
<tr>
{!selected && <th>{t("factory.issue")}</th>}
<th>{t("factory.phase")}</th>
<th>{t("factory.model")}</th>
<th>{t("factory.status")}</th>
<th>{t("factory.started")}</th>
<th>{t("factory.duration")}</th>
<th>{t("factory.tokens")}</th>
<th>{t("factory.cost")}</th>
<th />
</tr>
</thead>
<tbody>
{shown.map((r) => (
<tr key={r.id}>
{!selected && (
<td>
{repoName(r.repo)} #{r.issue}
</td>
)}
<td>
{t(`factory.phase.${r.phase}` as any)}
{r.round > 0 && <span className="hint"> · {t("factory.round", { n: r.round })}</span>}
</td>
<td className="mono">{r.model}</td>
<td>
<span className={`chip ${r.status === "done" ? "ok" : r.status === "running" ? "" : "warn"}`}>
{r.status === "running" && <span className="factory-pulse" />}
{t(`factory.runStatus.${r.status}` as any) || r.status}
</span>
</td>
<td>{fmtRelative(r.started_at)}</td>
<td>{fmtDuration(runMs(r, now))}</td>
<td title={`${r.input_tokens} / ${r.output_tokens}`}>
{fmtCompact(r.input_tokens)} / {fmtCompact(r.output_tokens)}
</td>
<td>{fmtCost(r.cost, "USD")}</td>
<td>
<button className="small" onClick={() => navigate(`/s/${r.session_id}`)}>
<Icon name="eye" /> {t("factory.openChat")}
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</>
);
}
const blankPhase = (): PhaseCfg => ({ model: "", agent: "codecraft", permission_mode: "auto", timeout_minutes: 60, max_attempts: 2, extra_prompt: "" });
const blankRepo = (connection = "", kind = "gitea"): RepoCfg => ({ url: "", kind, connection, token: "", label: "factory", max_parallel: 1, max_rework: 2, allowed_users: [], enabled: true, review: blankPhase(), build: blankPhase(), qa: blankPhase() });
const blankConn = (): Connection => ({ id: "", name: "", kind: "gitea", url: "", token: "", owner: "" });
const MODES = ["default", "auto", "accept_edits", "bypass"];
function PhaseForm({ phase, value, onChange }: { phase: Phase; value: PhaseCfg; onChange: (patch: Partial<PhaseCfg>) => void }) {
const t = useT();
return (
<div className="factory-phase">
<h4>{t(`factory.phase.${phase}` as any)}</h4>
<label>
<span>{t("factory.model")}</span>
<ModelSelect value={value.model} onChange={(model) => onChange({ model })} emptyLabel={t("jobEditor.defaultModel")} />
</label>
<label>
<span>{t("factory.agent")}</span>
<select value={value.agent} onChange={(e) => onChange({ agent: e.target.value })}>
<option value="codecraft">CodeCraft</option>
<option value="claude-code">Claude Code</option>
</select>
</label>
<label>
<span>{t("factory.mode")}</span>
<select value={value.permission_mode} onChange={(e) => onChange({ permission_mode: e.target.value })}>
{MODES.map((m) => (
<option key={m} value={m}>
{t(`permissionMode.${m}` as any)}
</option>
))}
</select>
</label>
<label>
<span>{t("factory.timeout")}</span>
<input type="number" min={1} value={value.timeout_minutes} onChange={(e) => onChange({ timeout_minutes: Number(e.target.value) || 60 })} />
</label>
<label>
<span>{t("factory.attempts")}</span>
<input type="number" min={1} max={10} value={value.max_attempts} title={t("factory.attemptsHint")} onChange={(e) => onChange({ max_attempts: Math.max(1, Number(e.target.value) || 1) })} />
</label>
<label>
<span>{t("factory.extraPrompt")}</span>
<textarea rows={3} value={value.extra_prompt} onChange={(e) => onChange({ extra_prompt: e.target.value })} />
</label>
</div>
);
}
const URL_PLACEHOLDER: Record<string, string> = { gitea: "https://git.example.org", github: "https://github.com", gitlab: "https://gitlab.com" };
function FactorySettings() {
const t = useT();
const [st, setSt] = useState<Settings>();
const [busy, setBusy] = useState<string>();
const [orgs, setOrgs] = useState<Record<string, string[]>>({});
useEffect(() => {
get<Settings>("/account/factory")
.then(setSt)
.catch((e) => toast(e.message));
}, []);
if (!st) return <div className="empty"><Spinner /></div>;
const { connections: conns, repos } = st;
const setConns = (connections: Connection[]) => setSt({ ...st, connections });
const setRepos = (r: RepoCfg[]) => setSt({ ...st, repos: r });
const upConn = (i: number, patch: Partial<Connection>) => setConns(conns.map((c, k) => (k === i ? { ...c, ...patch } : c)));
const up = (i: number, patch: Partial<RepoCfg>) => setRepos(repos.map((r, k) => (k === i ? { ...r, ...patch } : r)));
const upPhase = (i: number, p: Phase, patch: Partial<PhaseCfg>) => up(i, { [p]: { ...repos[i][p], ...patch } } as any);
const upDefault = (p: Phase, patch: Partial<PhaseCfg>) => setSt({ ...st, defaults: { ...st.defaults, [p]: { ...st.defaults[p], ...patch } } });
const save = async () => {
const s = await put<Settings>("/account/factory", st);
setSt(s);
return s;
};
const act = async (key: string, f: () => Promise<void>) => {
setBusy(key);
try {
await f();
} catch (e: any) {
toast(e.message);
} finally {
setBusy(undefined);
}
};
return (
<>
<div className="notice">{t("factory.settingsHint")}</div>
<h3 className="factory-h">{t("factory.connections")}</h3>
<div className="hint" style={{ marginBottom: 8 }}>{t("factory.connectionsHint")}</div>
{conns.map((c, i) => (
<div key={i} className="panel">
<div className="row" style={{ gap: 8, flexWrap: "wrap" }}>
<h3 style={{ margin: 0 }}>{c.name || KIND_NAME[c.kind]}</h3>
<span className="spacer" />
<button
className="small"
disabled={busy !== undefined}
onClick={() =>
act(`c${i}`, async () => {
const saved = await save();
const id = saved.connections[i]?.id;
const r = await post<{ login: string; orgs: string[] }>("/account/factory/connection/test", { id });
setOrgs({ ...orgs, [id]: r.orgs });
toast(t("factory.connOk", { login: r.login, n: r.orgs.length }), "success");
})
}
>
{busy === `c${i}` ? <Spinner small /> : <Icon name="plug" />} {t("factory.testConn")}
</button>
<button
className="small"
title={t("common.delete")}
aria-label={t("common.delete")}
onClick={async () => {
if (await confirmDialog({ message: t("factory.connDeleteConfirm", { name: c.name || KIND_NAME[c.kind] }), danger: true })) setConns(conns.filter((_, k) => k !== i));
}}
>
<Icon name="trash" />
</button>
</div>
<div className="factory-form">
<label>
<span>{t("factory.connName")}</span>
<input value={c.name} onChange={(e) => upConn(i, { name: e.target.value })} />
</label>
<label>
<span>{t("factory.kind")}</span>
<select value={c.kind} onChange={(e) => upConn(i, { kind: e.target.value as Connection["kind"] })}>
{Object.entries(KIND_NAME).map(([k, n]) => (
<option key={k} value={k}>
{n}
</option>
))}
</select>
</label>
<label>
<span>{t("factory.serviceUrl")}</span>
<input value={c.url} placeholder={URL_PLACEHOLDER[c.kind]} onChange={(e) => upConn(i, { url: e.target.value })} />
</label>
<label>
<span>{t("factory.token")}</span>
<input type="password" autoComplete="new-password" value={c.token} placeholder={t("factory.tokenPlaceholder")} onChange={(e) => upConn(i, { token: e.target.value })} onFocus={(e) => c.token.startsWith("•") && e.currentTarget.select()} />
<span className="hint">{c.token.startsWith("•") ? t("factory.tokenSet") : t(`factory.tokenHint.${c.kind}` as any)}</span>
</label>
<label>
<span>{t("factory.defaultOwner")}</span>
<input list={`orgs-${c.id}`} value={c.owner} placeholder={t("draft.ownerPlaceholder")} onChange={(e) => upConn(i, { owner: e.target.value })} />
<datalist id={`orgs-${c.id}`}>
{(orgs[c.id] ?? []).map((o) => (
<option key={o} value={o} />
))}
</datalist>
</label>
</div>
</div>
))}
<button onClick={() => setConns([...conns, blankConn()])}>
<Icon name="plus" /> {t("factory.addConn")}
</button>
<h3 className="factory-h">{t("factory.defaults")}</h3>
<div className="hint" style={{ marginBottom: 8 }}>{t("factory.defaultsHint")}</div>
<div className="panel">
<label className="factory-form" style={{ margin: 0 }}>
<span style={{ fontSize: 12 }}>{t("factory.specModel")}</span>
<ModelSelect value={st.defaults.spec_model} onChange={(spec_model) => setSt({ ...st, defaults: { ...st.defaults, spec_model } })} emptyLabel={t("jobEditor.defaultModel")} />
</label>
<div className="factory-phases" style={{ marginTop: 10 }}>
{PHASES.map((p) => (
<PhaseForm key={p} phase={p} value={st.defaults[p]} onChange={(patch) => upDefault(p, patch)} />
))}
</div>
</div>
<h3 className="factory-h">{t("factory.repos")}</h3>
{repos.map((r, i) => (
<div key={i} className="panel">
<div className="row" style={{ flexWrap: "wrap", gap: 8 }}>
<h3 style={{ margin: 0 }}>{r.url ? repoName(r.url) : t("factory.newRepo")}</h3>
<span className="chip">{KIND_NAME[conns.find((c) => c.id === r.connection)?.kind ?? r.kind] ?? r.kind}</span>
<span className="spacer" />
<label className="switch">
<input type="checkbox" checked={r.enabled} onChange={(e) => up(i, { enabled: e.target.checked })} />
<span>{t(r.enabled ? "jobs.on" : "jobs.off")}</span>
</label>
<button
className="small"
disabled={busy !== undefined}
onClick={() =>
act(`t${i}`, async () => {
await save();
const res = await post<{ info: { login: string; repo: string; can_push: boolean }; labels_created: string[]; folder: string }>("/account/factory/test", { url: r.url });
toast(t("factory.testOk", { login: res.info.login, repo: res.info.repo, n: res.labels_created.length }), "success");
})
}
>
{busy === `t${i}` ? <Spinner small /> : <Icon name="plug" />} {t("factory.test")}
</button>
<button
className="small"
title={t("common.delete")}
aria-label={t("common.delete")}
onClick={async () => {
if (await confirmDialog({ message: t("factory.deleteConfirm", { name: repoName(r.url) || "?" }), danger: true })) setRepos(repos.filter((_, k) => k !== i));
}}
>
<Icon name="trash" />
</button>
</div>
<div className="factory-form">
<label>
<span>{t("factory.connection")}</span>
<select
value={r.connection}
onChange={(e) => up(i, { connection: e.target.value, kind: conns.find((c) => c.id === e.target.value)?.kind ?? r.kind })}
>
<option value="">{t("factory.noConnection")}</option>
{conns
.filter((c) => c.id)
.map((c) => (
<option key={c.id} value={c.id}>
{c.name || KIND_NAME[c.kind]}
</option>
))}
</select>
</label>
{!r.connection && (
<label>
<span>{t("factory.kind")}</span>
<select value={r.kind} onChange={(e) => up(i, { kind: e.target.value })}>
{Object.entries(KIND_NAME).map(([k, n]) => (
<option key={k} value={k}>
{n}
</option>
))}
</select>
</label>
)}
<label>
<span>{t("factory.url")}</span>
<input value={r.url} placeholder="https://host/owner/repo.git" onChange={(e) => up(i, { url: e.target.value })} />
</label>
<label>
<span>{t("factory.repoToken")}</span>
<input type="password" autoComplete="new-password" value={r.token} placeholder={t("factory.repoTokenPlaceholder")} onChange={(e) => up(i, { token: e.target.value })} onFocus={(e) => r.token.startsWith("•") && e.currentTarget.select()} />
<span className="hint">{r.token.startsWith("•") ? t("factory.tokenSet") : t("factory.repoTokenHint")}</span>
</label>
<label>
<span>{t("factory.label")}</span>
<input value={r.label} onChange={(e) => up(i, { label: e.target.value })} />
</label>
<label>
<span>{t("factory.parallel")}</span>
<input type="number" min={1} max={4} value={r.max_parallel} onChange={(e) => up(i, { max_parallel: Number(e.target.value) || 1 })} />
</label>
<label>
<span>{t("factory.rework")}</span>
<input type="number" min={0} max={10} value={r.max_rework} title={t("factory.reworkHint")} onChange={(e) => up(i, { max_rework: Math.max(0, Number(e.target.value) || 0) })} />
</label>
<label>
<span>{t("factory.allowed")}</span>
<input value={r.allowed_users.join(", ")} placeholder={t("factory.allowedPlaceholder")} onChange={(e) => up(i, { allowed_users: e.target.value.split(",").map((u) => u.trim()).filter(Boolean) })} />
</label>
</div>
<div className="factory-phases">
{PHASES.map((p) => (
<PhaseForm key={p} phase={p} value={r[p]} onChange={(patch) => upPhase(i, p, patch)} />
))}
</div>
</div>
))}
<div className="row" style={{ gap: 8, marginTop: 12 }}>
<button onClick={() => setRepos([...repos, blankRepo(conns.find((c) => c.id)?.id ?? "", conns.find((c) => c.id)?.kind ?? "gitea")])}>
<Icon name="plus" /> {t("factory.addRepo")}
</button>
<button
className="primary"
disabled={busy !== undefined}
onClick={() =>
act("save", async () => {
await save();
toast(t("factory.saved"), "success");
})
}
>
{busy === "save" ? <Spinner small /> : <Icon name="check" />} {t("common.save")}
</button>
</div>
</>
);
}
+314
View File
@@ -0,0 +1,314 @@
import { useEffect, useState } from "react";
import { get, post } from "../api";
import { useT } from "../i18n";
import { navigate } from "../router";
import { toast } from "../dialogs";
import { Icon } from "./Icon";
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 }[];
}
export const isDraftChat = (cwd: string) => /\/_drafts\/[^/]+$/.test(cwd);
const slugify = (s: string) =>
s
.toLowerCase()
.replace(/ä/g, "ae")
.replace(/ö/g, "oe")
.replace(/ü/g, "ue")
.replace(/ß/g, "ss")
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "")
.slice(0, 60);
/** Bar above the composer of a spec chat: file the spec as a new repository and start the workflow. */
export function DraftBar({ sessionId }: { sessionId: string }) {
const t = useT();
const [open, setOpen] = useState(false);
return (
<>
<div className="draft-bar">
<Icon name="scroll" />
<span>{t("draft.hint")}</span>
<span className="spacer" />
<button className="small primary" onClick={() => setOpen(true)}>
<Icon name="check" /> {t("draft.create")}
</button>
</div>
{open && <CreateProjectDialog sessionId={sessionId} onClose={() => setOpen(false)} />}
</>
);
}
function CreateProjectDialog({ sessionId, onClose }: { sessionId: string; onClose: () => void }) {
const t = useT();
const [draft, setDraft] = useState<Draft>();
const [name, setName] = useState("");
const [slug, setSlug] = useState("");
const [slugTouched, setSlugTouched] = useState(false);
const [description, setDescription] = useState("");
const [connection, setConnection] = useState("");
const [owner, setOwner] = useState("");
const [busy, setBusy] = useState(false);
useEffect(() => {
get<Draft>(`/factory/drafts/${sessionId}`)
.then((d) => {
setDraft(d);
setName(d.proposal?.name ?? "");
setSlug(d.proposal?.slug ? slugify(d.proposal.slug) : "");
setSlugTouched(!!d.proposal?.slug);
setDescription(d.proposal?.description ?? "");
setConnection(d.connections[0]?.id ?? "");
setOwner(d.connections[0]?.owner ?? "");
})
.catch((e) => {
toast(e.message);
onClose();
});
}, [sessionId]);
if (!draft)
return (
<div className="modal-backdrop">
<div className="modal">
<Spinner />
</div>
</div>
);
const conn = draft.connections.find((c) => c.id === connection);
const ready = draft.spec.trim() && name.trim() && slug.length >= 2 && connection;
const create = async () => {
setBusy(true);
try {
const r = await post<{ repo: string; issue: number }>(`/factory/drafts/${sessionId}/create`, { connection, name, slug, description, owner });
await post("/factory/poll", {}).catch(() => undefined);
toast(t("draft.created", { repo: r.repo, n: r.issue }), "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("draft.create")} onClick={(e) => e.stopPropagation()}>
<h3>{t("draft.create")}</h3>
{draft.connections.length === 0 ? (
<div className="notice err">
{t("draft.noConnection")}{" "}
<button className="link-btn" onClick={() => navigate("/factory")}>
{t("factory.tab.settings")}
</button>
</div>
) : (
<>
{!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>
<input
autoFocus
value={name}
onChange={(e) => {
setName(e.target.value);
if (!slugTouched) setSlug(slugify(e.target.value));
}}
/>
</label>
<label>
<span>{t("draft.slug")}</span>
<input
value={slug}
className="mono"
onChange={(e) => {
setSlug(slugify(e.target.value));
setSlugTouched(true);
}}
/>
</label>
<label style={{ gridColumn: "1 / -1" }}>
<span>{t("draft.description")}</span>
<input value={description} onChange={(e) => setDescription(e.target.value)} />
</label>
<label>
<span>{t("draft.connection")}</span>
<select
value={connection}
onChange={(e) => {
setConnection(e.target.value);
setOwner(draft.connections.find((c) => c.id === e.target.value)?.owner ?? "");
}}
>
{draft.connections.map((c) => (
<option key={c.id} value={c.id}>
{c.name || c.kind} ({c.kind})
</option>
))}
</select>
</label>
<label>
<span>{t("draft.owner")}</span>
<input value={owner} placeholder={t("draft.ownerPlaceholder")} onChange={(e) => setOwner(e.target.value)} />
</label>
</div>
<div className="hint" style={{ margin: "6px 0" }}>
{t("draft.private", { conn: conn?.name || "" })}
</div>
<details>
<summary>{t("draft.specPreview")}</summary>
<pre className="draft-spec">{draft.spec || "–"}</pre>
</details>
</>
)}
<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={!ready || busy}>
{busy ? <Spinner small /> : <Icon name="check" />} {t("draft.createGo")}
</button>
</div>
</div>
</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>
);
}
+136
View File
@@ -0,0 +1,136 @@
import { useEffect, useState } from "react";
import { get, post } from "../api";
import { fmtRelative, useT } from "../i18n";
import { toast } from "../dialogs";
import { Icon } from "./Icon";
import { Spinner } from "./Activity";
export interface ReleaseRow {
id: string;
repo: string;
version: string;
state: "running" | "done" | "failed";
log: string;
url: string;
started_at: number;
ended_at: number | null;
}
interface Preview {
current: string;
suggested: string;
spec: string | null;
running: boolean;
}
const repoName = (url: string) => url.replace(/\.git$/, "").split("/").slice(-2).join("/");
/** Confirm and start a release: version, the recipe that will run, then tag + image + downloads. */
export function ReleaseDialog({ repo, onClose, onStarted }: { repo: string; onClose: () => void; onStarted: () => void }) {
const t = useT();
const [pv, setPv] = useState<Preview>();
const [version, setVersion] = useState("");
const [busy, setBusy] = useState(false);
useEffect(() => {
get<Preview>(`/factory/release/preview?repo=${encodeURIComponent(repo)}`)
.then((p) => {
setPv(p);
setVersion(p.suggested);
})
.catch((e) => {
toast(e.message);
onClose();
});
}, [repo]);
if (!pv)
return (
<div className="modal-backdrop">
<div className="modal">
<Spinner />
</div>
</div>
);
const start = async () => {
setBusy(true);
try {
await post("/factory/release", { repo, version });
toast(t("release.started", { v: version }), "success");
onStarted();
onClose();
} 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("release.title")} onClick={(e) => e.stopPropagation()}>
<h3>
{t("release.title")} – {repoName(repo)}
</h3>
<div className="hint">{t("release.current", { v: pv.current })}</div>
<label className="factory-form" style={{ display: "block", margin: "8px 0" }}>
<span>{t("release.version")}</span>
<input className="mono" value={version} onChange={(e) => setVersion(e.target.value.trim().replace(/^v/, ""))} />
</label>
<div className="notice">{t("release.what")}</div>
{pv.spec ? (
<details open>
<summary>{t("release.recipe")}</summary>
<pre className="draft-spec">{pv.spec}</pre>
<div className="notice err">{t("release.trust")}</div>
</details>
) : (
<div className="hint">{t("release.noRecipe")}</div>
)}
{pv.running && <div className="notice err">{t("release.running")}</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={start} disabled={busy || pv.running || !/^\d+\.\d+\.\d+$/.test(version)}>
{busy ? <Spinner small /> : <Icon name="check" />} {t("release.go", { v: version })}
</button>
</div>
</div>
</div>
);
}
/** The latest releases with their log. */
export function ReleasesPanel({ releases }: { releases: ReleaseRow[] }) {
const t = useT();
if (releases.length === 0) return null;
return (
<div className="panel" style={{ marginTop: 16 }}>
<h3 style={{ margin: "0 0 8px" }}>{t("release.list")}</h3>
{releases.map((r) => (
<details key={r.id} className="release-row" open={r.state === "running"}>
<summary>
<b>
{repoName(r.repo)} v{r.version}
</b>{" "}
<span className={`chip ${r.state === "done" ? "ok" : r.state === "running" ? "" : "warn"}`}>
{r.state === "running" && <span className="factory-pulse" />}
{t(`release.state.${r.state}` as any)}
</span>{" "}
<span className="hint">{fmtRelative(r.started_at)}</span>
{r.url && (
<>
{" "}
<a href={r.url} target="_blank" rel="noreferrer" onClick={(e) => e.stopPropagation()}>
<Icon name="external" />
</a>
</>
)}
</summary>
<pre className="draft-spec">{r.log || "–"}</pre>
</details>
))}
</div>
);
}
+6
View File
@@ -260,6 +260,12 @@ const P: Record<string, ReactNode> = {
<path d="M4.5 20.5a7.5 7.5 0 0 1 15 0" />
</>
),
factory: (
<>
<path d="M3 20V9.5l5 3V9.5l5 3V9.5l5 3V4h3v16Z" />
<path d="M7 16h2M12 16h2M17 16h2" />
</>
),
toolbox: (
<>
<rect x="3" y="8" width="18" height="11" rx="2" />
+17 -3
View File
@@ -1,4 +1,4 @@
import { ColorSwatches, IconPicker } from "./ColorSwatches";
import { deleteChat } from "../chatActions";
import { Icon } from "./Icon";
import { StatusLeds } from "./StatusLeds";
import { cycleThemeMode, getThemeMode, onThemeChange } from "../theme";
@@ -98,11 +98,21 @@ function SessionRow({ s, active, attention, busy, folders }: { s: Session; activ
<Icon name="folder-up" /> {t("sidebar.removeFromFolder")}
</button>
)}
<ColorSwatches value={s.color} onChange={(color) => (setMenu(false), organise(s.id, { color }))} />
<IconPicker value={s.icon} color={s.color} onChange={(icon) => (setMenu(false), organise(s.id, { icon }))} />
<button role="menuitem" onClick={() => (setMenu(false), organise(s.id, { archived: !s.archived }))}>
<Icon name="archive" /> {t(s.archived ? "sidebar.unarchive" : "sidebar.archiveOne")}
</button>
{!s.shared && (
<button
role="menuitem"
className="danger"
onClick={async () => {
setMenu(false);
if ((await deleteChat(s)) && active) navigate("/new");
}}
>
<Icon name="trash" /> {t("chat.delete")}
</button>
)}
</div>
)}
</div>
@@ -481,6 +491,10 @@ export function Sidebar({ open, activeIds, section }: { open: boolean; activeIds
<Icon name="clock" className="nav-icon" />
{t("nav.jobs")}
</button>
<button className={`ghost ${section === "factory" ? "active" : ""}`} onClick={() => navigate("/factory")}>
<Icon name="factory" className="nav-icon" />
{t("nav.factory")}
</button>
<button className={`ghost ${section === "stats" ? "active" : ""}`} onClick={() => navigate("/stats")}>
<Icon name="chart" className="nav-icon" />
{t("nav.stats")}
+2
View File
@@ -3,6 +3,7 @@ import { post } from "../../api";
import { useT } from "../../i18n";
import { useStore } from "../../store";
import { GitAccount } from "./GitAccount";
import { SshKeys } from "./SshKeys";
import { ApiTokens } from "./ApiTokens";
import { CliInstall } from "./CliInstall";
import { Memory } from "./Memory";
@@ -54,6 +55,7 @@ export function Account() {
<Memory />
<Snippets />
<GitAccount />
<SshKeys />
<CliInstall />
<ClaudeCode />
<Telegram />
+98
View File
@@ -0,0 +1,98 @@
import { useEffect, useState } from "react";
import { del, get, post } from "../../api";
import { useT } from "../../i18n";
import { confirmDialog, toast } from "../../dialogs";
import { Icon } from "../Icon";
interface Key {
id: string;
name: string;
public: string;
fingerprint: string;
}
/** SSH keys of the user: used by agents, the terminal and the git panel to reach other servers. */
export function SshKeys() {
const t = useT();
const [keys, setKeys] = useState<Key[]>();
const [name, setName] = useState("");
const [priv, setPriv] = useState("");
const [importing, setImporting] = useState(false);
const [busy, setBusy] = useState(false);
useEffect(() => {
get<Key[]>("/account/ssh")
.then(setKeys)
.catch((e) => toast(e.message));
}, []);
if (!keys) return null;
const add = async () => {
setBusy(true);
try {
setKeys(await post<Key[]>("/account/ssh", { name, private: importing ? priv : undefined }));
setName("");
setPriv("");
toast(t("ssh.added"), "success");
} catch (e: any) {
toast(e.message);
} finally {
setBusy(false);
}
};
const copy = (text: string) => navigator.clipboard?.writeText(text).then(() => toast(t("ssh.copied"), "success"), () => toast(t("ssh.copyFailed")));
return (
<div className="panel">
<h3>
<Icon name="lock" /> {t("ssh.title")}
</h3>
<div className="hint" style={{ marginBottom: 10 }}>
{t("ssh.hint")}
</div>
{keys.length === 0 && <div className="hint">{t("ssh.none")}</div>}
{keys.map((k) => (
<div key={k.id} className="ssh-key">
<div className="row">
<b>{k.name}</b>
<span className="hint mono">{k.fingerprint}</span>
<span className="spacer" />
<button className="small" onClick={() => copy(k.public)}>
<Icon name="copy" /> {t("ssh.copyPublic")}
</button>
<button
className="small"
title={t("common.delete")}
aria-label={t("common.delete")}
onClick={async () => {
if (await confirmDialog({ message: t("ssh.deleteConfirm", { name: k.name }), danger: true })) {
del<Key[]>(`/account/ssh/${k.id}`).then(setKeys).catch((e) => toast(e.message));
}
}}
>
<Icon name="trash" />
</button>
</div>
<input readOnly value={k.public} onFocus={(e) => e.currentTarget.select()} aria-label={t("ssh.public")} className="mono" />
</div>
))}
<div className="row" style={{ marginTop: 10, flexWrap: "wrap" }}>
<input value={name} onChange={(e) => setName(e.target.value)} placeholder={t("ssh.name")} maxLength={60} aria-label={t("ssh.name")} style={{ flex: "1 1 160px" }} />
<button className="primary" disabled={busy || !name.trim() || (importing && !priv.trim())} onClick={add}>
{importing ? t("ssh.import") : t("ssh.generate")}
</button>
<label className="row" style={{ gap: 6 }}>
<input type="checkbox" checked={importing} onChange={(e) => setImporting(e.target.checked)} />
{t("ssh.importExisting")}
</label>
</div>
{importing && (
<>
<textarea rows={5} className="mono" value={priv} onChange={(e) => setPriv(e.target.value)} placeholder="-----BEGIN OPENSSH PRIVATE KEY-----" aria-label={t("ssh.private")} style={{ width: "100%", marginTop: 8 }} spellCheck={false} autoComplete="off" />
<div className="hint">{t("ssh.importHint")}</div>
</>
)}
</div>
);
}
+36 -8
View File
@@ -20,8 +20,15 @@ interface PromptOpts {
confirmLabel?: string;
}
interface ChoiceOpts {
title?: string;
message: string;
choices: { value: string; label: string; danger?: boolean }[];
}
type Dialog =
| ({ kind: "confirm"; id: number; resolve: (v: boolean) => void } & ConfirmOpts)
| ({ kind: "choice"; id: number; resolve: (v: string | null) => void } & ChoiceOpts)
| ({ kind: "prompt"; id: number; resolve: (v: string | null) => void } & PromptOpts);
interface Toast {
@@ -45,6 +52,14 @@ export function confirmDialog(opts: ConfirmOpts | string): Promise<boolean> {
});
}
/** Several actions to choose from (plus Cancel): resolves to the chosen value, or null. */
export function choiceDialog(opts: ChoiceOpts): Promise<string | null> {
return new Promise((resolve) => {
dialogs = [...dialogs, { kind: "choice", id: ++seq, resolve, ...opts }];
emit();
});
}
export function promptDialog(opts: PromptOpts | string): Promise<string | null> {
const o = typeof opts === "string" ? { message: opts } : opts;
return new Promise((resolve) => {
@@ -108,14 +123,27 @@ function DialogView({ d }: { d: Dialog }) {
style={{ width: "100%" }}
/>
)}
<div className="row dialog-actions">
<button type="button" onClick={() => close(d, cancelValue)}>
{t("common.cancel")}
</button>
<button ref={ok} type="submit" className={d.kind === "confirm" && d.danger ? "danger-solid" : "primary"}>
{d.confirmLabel ?? t("common.ok")}
</button>
</div>
{d.kind === "choice" ? (
<div className="row dialog-actions dialog-choices">
<button type="button" onClick={() => close(d, null)}>
{t("common.cancel")}
</button>
{d.choices.map((c, i) => (
<button key={c.value} ref={i === d.choices.length - 1 ? ok : undefined} type="button" className={c.danger ? "danger-solid" : i === d.choices.length - 1 ? "primary" : undefined} onClick={() => close(d, c.value)}>
{c.label}
</button>
))}
</div>
) : (
<div className="row dialog-actions">
<button type="button" onClick={() => close(d, cancelValue)}>
{t("common.cancel")}
</button>
<button ref={ok} type="submit" className={d.kind === "confirm" && d.danger ? "danger-solid" : "primary"}>
{d.confirmLabel ?? t("common.ok")}
</button>
</div>
)}
</form>
</div>
);
+179
View File
@@ -1146,4 +1146,183 @@ export const de: Messages = {
"stats.table.session": "teuerste Chats",
"command.clear": "Bisheriges Gespräch vergessen (der Chat bleibt sichtbar)",
"chat.cleared": "Kontext geleert – das Modell sieht die Nachrichten darüber nicht mehr",
"ssh.title": "SSH-Schlüssel",
"ssh.hint": "Schlüssel, mit denen Agenten, Terminal und Git-Panel andere Server erreichen (ssh, scp, rsync, Git über ssh). Sie werden automatisch genutzt; Hosts werden beim ersten Kontakt akzeptiert. Den öffentlichen Schlüssel trägst du in die authorized_keys des Servers ein.",
"ssh.none": "Noch keine Schlüssel.",
"ssh.name": "Name (z. B. Laptop, Build-Server)",
"ssh.generate": "Neuen Schlüssel erzeugen",
"ssh.import": "Schlüssel importieren",
"ssh.importExisting": "Vorhandenen Schlüssel importieren",
"ssh.importHint": "Nur private Schlüssel ohne Passphrase. Der Schlüssel wird für dein Konto auf dem Server gespeichert.",
"ssh.private": "Privater Schlüssel",
"ssh.public": "Öffentlicher Schlüssel",
"ssh.copyPublic": "Öffentlichen Schlüssel kopieren",
"ssh.copied": "Öffentlicher Schlüssel kopiert",
"ssh.copyFailed": "Kopieren nicht möglich – Text von Hand markieren",
"ssh.added": "Schlüssel hinzugefügt",
"ssh.deleteConfirm": "Schlüssel \"{name}\" löschen? Server, die ihm vertrauen, akzeptieren dich von hier aus nicht mehr.",
"chat.deleteTitle": "Chat löschen",
"chat.deleteWithFolder": "Dieser Chat hat einen eigenen Ordner:\n{path}\n({size})\n\nSoll der Ordner mit dem Chat gelöscht werden?",
"chat.deleteOnlyChat": "Nur Chat löschen",
"chat.deleteChatAndFolder": "Chat und Ordner löschen",
"chat.folderFiles": "{n} Dateien",
"chat.folderHasGit": "Der Ordner enthält ein Git-Repository – nicht gepushte Commits und Branches gehen verloren.",
"chat.folderDeleted": "Chat und Ordner gelöscht",
"nav.factory": "Factory",
"factory.title": "Software-Factory",
"factory.tab.overview": "Übersicht",
"factory.tab.settings": "Einstellungen",
"factory.empty": "Noch kein Repository verbunden. Füge in den Einstellungen eines hinzu: Issues mit dem Factory-Label werden dann von Agenten geprüft, gebaut und abgenommen.",
"factory.addRepo": "Repository hinzufügen",
"factory.newRepo": "Neues Repository",
"factory.noArea": "Der Factory-Bereich ist nicht eingebunden (FACTORY_DIR → /factory). Repositories können nicht geklont werden.",
"factory.kpi.running": "Läuft gerade",
"factory.kpi.issues": "{n} Issues",
"factory.kpi.done": "Fertig",
"factory.kpi.failed": "{n} fehlgeschlagen oder abgelehnt",
"factory.kpi.tokens": "Tokens",
"factory.kpi.cost": "Kosten",
"factory.kpi.runs": "{n} Läufe",
"factory.kpi.time": "Ø Laufzeit",
"factory.kpi.perRun": "pro beendetem Lauf",
"factory.in": "ein",
"factory.out": "aus",
"factory.allRepos": "Alle Projekte",
"factory.repoLine": "{n} Issues · {run} laufen",
"factory.noToken": "kein Token",
"factory.pollNow": "Jetzt prüfen",
"factory.col.review": "Prüfung",
"factory.col.question": "Rückfragen",
"factory.col.approved": "Freigegeben",
"factory.col.build": "Bau",
"factory.col.qa": "Abnahme",
"factory.col.done": "Fertig",
"factory.col.failed": "Fehlgeschlagen / abgelehnt",
"factory.phase": "Phase",
"factory.phase.review": "Prüfung",
"factory.phase.build": "Bau",
"factory.phase.qa": "Abnahme",
"factory.latestRuns": "Letzte Läufe",
"factory.noRuns": "Noch keine Läufe.",
"factory.issue": "Issue",
"factory.model": "Modell",
"factory.status": "Status",
"factory.started": "Gestartet",
"factory.duration": "Dauer",
"factory.tokens": "Tokens",
"factory.cost": "Kosten",
"factory.restartAt": "Neu starten bei:",
"factory.restarted": "Issue ist wieder im Ablauf",
"factory.mergeBtn": "Freigeben und mergen",
"factory.mergeConfirm": "Pull Request #{n} mergen ({method})? Die Factory merged nie selbst – das ist deine Freigabe.",
"factory.merged": "Pull Request gemergt",
"factory.merge.merge": "Merge-Commit",
"factory.merge.squash": "Squash",
"factory.merge.rebase": "Rebase",
"factory.pr.open": "offen",
"factory.pr.merged": "gemergt",
"factory.pr.closed": "geschlossen",
"factory.pr.conflict": "Konflikt mit dem Zielbranch",
"factory.pr.files": "{n} Dateien",
"issues.hint": "Wenn der Plan steht, die Issues im Repository anlegen.",
"issues.create": "Issues anlegen",
"issues.createGo": "{n} Issues anlegen",
"issues.created": "{n} Issues angelegt",
"issues.noProposal": "Das Modell hat noch keine Issue-Liste vorgeschlagen. Sag ihm, dass der Plan fertig ist; es schließt dann mit der Liste ab.",
"issues.spec": "Spec-Datei im Repository",
"issues.depends": "Voraussetzung: {d}",
"issues.description": "Beschreibung",
"issues.start": "Sofort starten (Label factory setzen)",
"issues.startHint": "Standardmäßig aus: die Issues werden nur angelegt, das Label setzt du selbst nacheinander – spätere bauen auf den gemergten früheren auf.",
"issues.pickRepo": "Für welches Repository?",
"issues.sliceWhich": "Welcher Meilenstein soll in Deliverables zerlegt werden?",
"issues.sliceGo": "Starten",
"issues.feature": "Feature planen",
"issues.featureHint": "Ein neues Feature mit einem Modell ausarbeiten und daraus Issues anlegen",
"issues.slice": "Meilenstein zerlegen",
"issues.sliceHint": "Ein Modell zerlegt einen Meilenstein in nummerierte Deliverables und legt die Issues an",
"factory.attempts": "Versuche",
"factory.attemptsHint": "Wie oft diese Phase bei technischem Scheitern (Zeitüberschreitung, kein Ergebnis, keine Änderungen) versucht wird, bevor das Issue als fehlgeschlagen gilt",
"factory.rework": "Nachbesserungsrunden",
"factory.reworkHint": "Wie oft eine durchgefallene Abnahme das Issue zurück an den Build schickt (0 = nie, das Issue scheitert sofort)",
"release.button": "Release",
"release.hint": "Release erstellen: Tag, Docker-Image und Downloads",
"release.title": "Release",
"release.current": "Aktuelle Version: v{v}",
"release.version": "Neue Version",
"release.what": "Die Factory schreibt VERSION, baut, was das Rezept beschreibt, pusht den Tag und erstellt das Release auf der Forge mit Quell-ZIP und den Dateien des Rezepts. Das Docker-Image geht in die Registry des Image-Namens.",
"release.recipe": "Release-Rezept (.factory/release.json)",
"release.trust": "Die Befehle in diesem Rezept laufen auf dem Server mit Docker-Zugriff außerhalb der Sandbox. Starte das Release nur, wenn du sie gelesen hast und ihnen vertraust.",
"release.noRecipe": "Keine .factory/release.json auf dem Default-Branch: es werden nur Tag, Release und Quell-ZIP erstellt, kein Docker-Image.",
"release.running": "Für dieses Repository läuft bereits ein Release.",
"release.go": "Release v{v}",
"release.started": "Release v{v} gestartet",
"release.list": "Releases",
"release.state.running": "läuft",
"release.state.done": "fertig",
"release.state.failed": "fehlgeschlagen",
"factory.pr": "Pull Request",
"factory.round": "Runde {n}",
"factory.openChat": "Chat öffnen",
"factory.runStatus.running": "läuft",
"factory.runStatus.done": "fertig",
"factory.runStatus.timeout": "Zeitlimit",
"factory.runStatus.error": "Fehler",
"factory.runStatus.no-result": "kein Ergebnis",
"factory.runStatus.interrupted": "unterbrochen",
"factory.settingsHint": "Specs kommen als Gitea-Issues mit dem Factory-Label (\"Spec: <Pfad>\" im Text). Jede Phase läuft als eigener Chat in der Sandbox mit eigenem Modell. Repositories werden in den separaten Factory-Bereich geklont, nicht in den Workspace; die Agenten sehen den API-Token nie.",
"factory.url": "Repository-URL",
"factory.token": "Gitea-API-Token",
"factory.tokenPlaceholder": "Token mit Rechten für Issues und Pull Requests",
"factory.tokenSet": "Ein Token ist gespeichert. Gib einen neuen ein, um ihn zu ersetzen.",
"factory.label": "Issue-Label",
"factory.parallel": "Parallele Läufe",
"factory.allowed": "Erlaubte Issue-Autoren",
"factory.allowedPlaceholder": "leer = nur der Token-Besitzer",
"factory.agent": "Agent",
"factory.mode": "Berechtigungsmodus",
"factory.timeout": "Zeitlimit (Minuten)",
"factory.extraPrompt": "Zusätzliche Anweisungen",
"factory.test": "Verbindung testen",
"factory.testOk": "Verbunden als {login} mit {repo}; {n} Labels angelegt, Repository geklont.",
"factory.deleteConfirm": "{name} aus der Factory entfernen? Issues und Chats bleiben.",
"factory.newProject": "Neues Projekt",
"factory.connections": "Verbindungen",
"factory.connectionsHint": "Deine Konten bei Gitea, GitHub oder GitLab. Jeder Nutzer richtet seine eigenen ein; Repositories nutzen den Token ihrer Verbindung, sofern sie keinen eigenen haben.",
"factory.connName": "Name",
"factory.kind": "Dienst",
"factory.serviceUrl": "Adresse des Dienstes",
"factory.defaultOwner": "Standard-Besitzer für neue Repositories",
"factory.addConn": "Verbindung hinzufügen",
"factory.testConn": "Testen",
"factory.connOk": "Angemeldet als {login}; {n} Organisationen oder Gruppen gefunden.",
"factory.connDeleteConfirm": "Verbindung {name} entfernen? Repositories funktionieren danach nur mit eigenem Token.",
"factory.tokenHint.gitea": "Scopes: write:repository, write:issue, read:user – zum Anlegen von Repositories zusätzlich write:user (oder write:organization).",
"factory.tokenHint.github": "Classic-Token mit Scope \"repo\" oder fein abgestufter Token mit Contents, Issues und Pull requests (Lesen/Schreiben).",
"factory.tokenHint.gitlab": "Persönlicher oder Projekt-Zugriffstoken mit Scope \"api\".",
"factory.defaults": "Standard für neue Projekte",
"factory.defaultsHint": "Modelle und Grenzen, mit denen ein Projekt startet; du kannst sie danach pro Projekt ändern.",
"factory.specModel": "Modell des Spec-Chats",
"factory.repos": "Repositories",
"factory.connection": "Verbindung",
"factory.noConnection": "– keine (eigener Token) –",
"factory.repoToken": "Eigener Token (optional)",
"factory.repoTokenPlaceholder": "leer = Token der Verbindung",
"factory.repoTokenHint": "Nur nötig, wenn dieses Repository einen anderen Token nutzen soll.",
"draft.hint": "Spec-Chat: Wenn die Spec fertig ist, lege sie als neues Repository ab.",
"draft.create": "Projekt anlegen",
"draft.createGo": "Repository anlegen und starten",
"draft.name": "Projektname",
"draft.slug": "Repository-Name",
"draft.description": "Kurzbeschreibung",
"draft.connection": "Verbindung",
"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:",
"draft.created": "{repo} angelegt, Issue #{n} eröffnet – die Prüfung startet gleich.",
"factory.saved": "Gespeichert",
};
+179
View File
@@ -1145,6 +1145,185 @@ export const en = {
"stats.table.session": "top chats",
"command.clear": "Forget the conversation so far (the chat stays visible)",
"chat.cleared": "Context cleared – the model no longer sees the messages above",
"ssh.title": "SSH keys",
"ssh.hint": "Keys that agents, the terminal and the git panel use to reach other servers (ssh, scp, rsync, git over ssh). They are used automatically; hosts are trusted on first contact. Add the public key to the server's authorized_keys.",
"ssh.none": "No keys yet.",
"ssh.name": "Name (e.g. laptop, build server)",
"ssh.generate": "Generate new key",
"ssh.import": "Import key",
"ssh.importExisting": "Import an existing key",
"ssh.importHint": "Private keys without a passphrase only. The key is stored on the server for your account.",
"ssh.private": "Private key",
"ssh.public": "Public key",
"ssh.copyPublic": "Copy public key",
"ssh.copied": "Public key copied",
"ssh.copyFailed": "Could not copy – select the text manually",
"ssh.added": "Key added",
"ssh.deleteConfirm": "Delete the key \"{name}\"? Servers that trust it will no longer accept you from here.",
"chat.deleteTitle": "Delete chat",
"chat.deleteWithFolder": "This chat has a folder of its own:\n{path}\n({size})\n\nDelete the folder with the chat?",
"chat.deleteOnlyChat": "Delete chat only",
"chat.deleteChatAndFolder": "Delete chat and folder",
"chat.folderFiles": "{n} files",
"chat.folderHasGit": "The folder contains a git repository – commits and branches that were not pushed are lost.",
"chat.folderDeleted": "Chat and folder deleted",
"nav.factory": "Factory",
"factory.title": "Software factory",
"factory.tab.overview": "Overview",
"factory.tab.settings": "Settings",
"factory.empty": "No repository connected yet. Add one in the settings: issues with the factory label are then reviewed, built and checked by agents.",
"factory.addRepo": "Add repository",
"factory.newRepo": "New repository",
"factory.noArea": "The factory area is not mounted (FACTORY_DIR → /factory). Repositories cannot be cloned.",
"factory.kpi.running": "Running now",
"factory.kpi.issues": "{n} issues",
"factory.kpi.done": "Done",
"factory.kpi.failed": "{n} failed or rejected",
"factory.kpi.tokens": "Tokens",
"factory.kpi.cost": "Cost",
"factory.kpi.runs": "{n} runs",
"factory.kpi.time": "Avg. run time",
"factory.kpi.perRun": "per finished run",
"factory.in": "in",
"factory.out": "out",
"factory.allRepos": "All projects",
"factory.repoLine": "{n} issues · {run} running",
"factory.noToken": "no token",
"factory.pollNow": "Check now",
"factory.col.review": "Review",
"factory.col.question": "Questions",
"factory.col.approved": "Approved",
"factory.col.build": "Build",
"factory.col.qa": "Acceptance",
"factory.col.done": "Done",
"factory.col.failed": "Failed / rejected",
"factory.phase": "Phase",
"factory.phase.review": "Review",
"factory.phase.build": "Build",
"factory.phase.qa": "Acceptance",
"factory.latestRuns": "Latest runs",
"factory.noRuns": "No runs yet.",
"factory.issue": "Issue",
"factory.model": "Model",
"factory.status": "Status",
"factory.started": "Started",
"factory.duration": "Duration",
"factory.tokens": "Tokens",
"factory.cost": "Cost",
"factory.restartAt": "Restart at:",
"factory.restarted": "Issue is back in the flow",
"factory.mergeBtn": "Approve and merge",
"factory.mergeConfirm": "Merge pull request #{n} ({method})? The factory itself never merges – this is your approval.",
"factory.merged": "Pull request merged",
"factory.merge.merge": "Merge commit",
"factory.merge.squash": "Squash",
"factory.merge.rebase": "Rebase",
"factory.pr.open": "open",
"factory.pr.merged": "merged",
"factory.pr.closed": "closed",
"factory.pr.conflict": "conflicts with the target branch",
"factory.pr.files": "{n} files",
"issues.hint": "When the plan is done, file the issues on the forge.",
"issues.create": "Create issues",
"issues.createGo": "Create {n} issues",
"issues.created": "{n} issues created",
"issues.noProposal": "The model has not proposed an issue list yet. Tell it that the plan is done; it ends with the list.",
"issues.spec": "Spec file in the repository",
"issues.depends": "Needs first: {d}",
"issues.description": "Description",
"issues.start": "Start right away (set the factory label)",
"issues.startHint": "Off by default: the issues are only created and you set the label yourself, one after the other – later ones build on the merged earlier ones.",
"issues.pickRepo": "For which repository?",
"issues.sliceWhich": "Which milestone should be cut into deliverables?",
"issues.sliceGo": "Start",
"issues.feature": "Plan a feature",
"issues.featureHint": "Work out a new feature with a model and create issues from it",
"issues.slice": "Cut a milestone",
"issues.sliceHint": "Let a model cut a milestone into numbered deliverables and create the issues",
"factory.attempts": "Tries",
"factory.attemptsHint": "How often this phase is tried when it fails technically (timeout, no result, no changes) before the issue is marked failed",
"factory.rework": "Rework rounds",
"factory.reworkHint": "How often a failed acceptance sends the issue back to the build (0 = never, the issue fails right away)",
"release.button": "Release",
"release.hint": "Make a release: tag, Docker image and downloads",
"release.title": "Release",
"release.current": "Current version: v{v}",
"release.version": "New version",
"release.what": "The factory writes VERSION, builds what the recipe describes, pushes the tag and creates the release on the forge with the source zip and the files of the recipe. The Docker image goes to the registry of the image name.",
"release.recipe": "Release recipe (.factory/release.json)",
"release.trust": "The commands in this recipe run on the server with Docker access, outside the sandbox. Only start the release if you have read and trust them.",
"release.noRecipe": "No .factory/release.json on the default branch: only the tag, the release and the source zip are made, no Docker image.",
"release.running": "A release of this repository is already running.",
"release.go": "Release v{v}",
"release.started": "Release v{v} started",
"release.list": "Releases",
"release.state.running": "running",
"release.state.done": "done",
"release.state.failed": "failed",
"factory.pr": "Pull request",
"factory.round": "round {n}",
"factory.openChat": "Open chat",
"factory.runStatus.running": "running",
"factory.runStatus.done": "done",
"factory.runStatus.timeout": "timeout",
"factory.runStatus.error": "error",
"factory.runStatus.no-result": "no result",
"factory.runStatus.interrupted": "interrupted",
"factory.settingsHint": "Specs arrive as Gitea issues with the factory label (\"Spec: <path>\" in the text). Each phase runs as its own chat in the sandbox with its own model. Repositories are cloned into the separate factory area, not into the workspace; agents never see the API token.",
"factory.url": "Repository URL",
"factory.token": "Gitea API token",
"factory.tokenPlaceholder": "Token with rights for issues and pull requests",
"factory.tokenSet": "A token is stored. Type a new one to replace it.",
"factory.label": "Issue label",
"factory.parallel": "Parallel runs",
"factory.allowed": "Allowed issue authors",
"factory.allowedPlaceholder": "empty = only the token's owner",
"factory.agent": "Agent",
"factory.mode": "Permission mode",
"factory.timeout": "Timeout (minutes)",
"factory.extraPrompt": "Extra instructions",
"factory.test": "Test connection",
"factory.testOk": "Connected as {login} to {repo}; {n} labels created, repository cloned.",
"factory.deleteConfirm": "Remove {name} from the factory? Issues and chats stay.",
"factory.newProject": "New project",
"factory.connections": "Connections",
"factory.connectionsHint": "Your accounts at Gitea, GitHub or GitLab. Each user sets up their own; repositories use the token of their connection unless they have a token of their own.",
"factory.connName": "Name",
"factory.kind": "Service",
"factory.serviceUrl": "Address of the service",
"factory.defaultOwner": "Default owner for new repositories",
"factory.addConn": "Add connection",
"factory.testConn": "Test",
"factory.connOk": "Signed in as {login}; {n} organisations or groups found.",
"factory.connDeleteConfirm": "Remove the connection {name}? Repositories keep working only with a token of their own.",
"factory.tokenHint.gitea": "Scopes: write:repository, write:issue, read:user – plus write:user (or write:organization) to create repositories.",
"factory.tokenHint.github": "Classic token with scope \"repo\", or a fine-grained token with Contents, Issues and Pull requests (read/write).",
"factory.tokenHint.gitlab": "Personal or project access token with scope \"api\".",
"factory.defaults": "Defaults for new projects",
"factory.defaultsHint": "Models and limits a project starts with; you can change them per project afterwards.",
"factory.specModel": "Model of the spec chat",
"factory.repos": "Repositories",
"factory.connection": "Connection",
"factory.noConnection": "– none (own token) –",
"factory.repoToken": "Own token (optional)",
"factory.repoTokenPlaceholder": "empty = token of the connection",
"factory.repoTokenHint": "Only needed when this repository should use a different token.",
"draft.hint": "Spec chat: when the spec is done, file it as a new repository.",
"draft.create": "Create project",
"draft.createGo": "Create repository and start",
"draft.name": "Project name",
"draft.slug": "Repository name",
"draft.description": "Short description",
"draft.connection": "Connection",
"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:",
"draft.created": "{repo} created, issue #{n} opened – the review starts shortly.",
"factory.saved": "Saved",
};
export type Messages = Record<keyof typeof en, string>;
+188 -10
View File
@@ -600,9 +600,6 @@ button.session-group:hover {
background: color-mix(in srgb, var(--tag) 38%, var(--bg1));
border-color: color-mix(in srgb, var(--tag) 70%, transparent);
}
.chat-pane[data-color] .msg.bubble.agent {
background: color-mix(in srgb, var(--tag) 7%, var(--bg1));
}
@media (max-width: 700px) {
.msg.user-msg {
max-width: 94%;
@@ -4758,15 +4755,10 @@ span.chat-tab > button {
}
}
.chat-pane[data-color] {
background: color-mix(in srgb, var(--tag) 16%, var(--bg0));
}
.chat-pane[data-color] .composer-wrap {
background: color-mix(in srgb, var(--tag) 16%, var(--bg0));
}
/* The chat's colour marks the top bar (line), the list entry, the badge and your own bubbles –
* the chat background itself stays neutral. */
.topbar[data-color] {
border-bottom: 3px solid var(--tag);
background: color-mix(in srgb, var(--tag) 28%, var(--bg0));
}
.session-item[data-color] {
box-shadow: inset 4px 0 0 var(--tag);
@@ -5022,3 +5014,189 @@ td.fold-indent {
.share-link input { flex: 1 1 200px; min-width: 0; }
.offline-bar { background: color-mix(in srgb, var(--warn, #d79921) 25%, var(--bg0, transparent)); color: var(--fg, inherit); padding: 6px 12px; font-size: 0.85rem; text-align: center; }
.ssh-key { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.ssh-key .row { align-items: center; flex-wrap: wrap; }
.ssh-key input.mono { width: 100%; font-size: 12px; }
.dialog-message { overflow-wrap: anywhere; }
.dialog-choices { flex-wrap: wrap; }
/* --- software factory ------------------------------------------------------ */
.button-link {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 8px;
border-radius: 6px;
text-decoration: none;
color: var(--fg1);
}
.table-wrap {
overflow-x: auto;
}
.factory-repos {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 14px;
align-items: stretch;
}
.factory-repo {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
text-align: left;
background: var(--bg1);
border: 1px solid var(--bg2);
border-radius: var(--radius);
padding: 8px 12px;
min-width: 150px;
}
.factory-repo.active {
border-color: var(--accent);
}
.factory-repo.off {
opacity: 0.6;
}
.factory-board {
display: grid;
grid-auto-flow: column;
grid-auto-columns: minmax(200px, 1fr);
gap: 10px;
overflow-x: auto;
padding-bottom: 6px;
}
.factory-col {
background: var(--bg1);
border-radius: var(--radius);
padding: 8px;
min-height: 120px;
display: flex;
flex-direction: column;
gap: 6px;
}
.factory-col h4 {
margin: 0 0 2px;
font-size: 13px;
display: flex;
justify-content: space-between;
align-items: center;
}
.factory-card {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
text-align: left;
background: var(--bg0);
border: 1px solid var(--bg2);
border-radius: 8px;
padding: 8px 10px;
}
.factory-card.active {
border-color: var(--accent);
}
.factory-card.running {
border-left: 3px solid var(--accent);
}
.factory-pulse {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
margin-right: 5px;
animation: factory-pulse 1.4s ease-in-out infinite;
}
@keyframes factory-pulse {
50% {
opacity: 0.25;
}
}
.factory-form {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 10px;
margin: 12px 0;
}
.factory-form label,
.factory-phase label {
display: flex;
flex-direction: column;
gap: 3px;
font-size: 12px;
color: var(--fg3);
}
.factory-phases {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 10px;
}
.factory-phase {
background: var(--bg1);
border-radius: var(--radius);
padding: 10px;
display: flex;
flex-direction: column;
gap: 8px;
}
.factory-phase h4 {
margin: 0;
}
.factory-h {
margin: 22px 0 6px;
}
.draft-bar {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 12px;
background: var(--bg1);
border-top: 1px solid var(--bg2);
font-size: 13px;
color: var(--fg2);
}
.draft-modal {
width: min(640px, calc(100vw - 32px));
}
.draft-spec {
max-height: 260px;
overflow: auto;
white-space: pre-wrap;
background: var(--bg1);
border-radius: 6px;
padding: 8px;
font-size: 12px;
}
.factory-pr {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
padding: 8px 0 12px;
}
.issue-list {
display: flex;
flex-direction: column;
gap: 8px;
max-height: 46vh;
overflow: auto;
margin-top: 8px;
}
.issue-item {
border: 1px solid var(--border);
border-radius: 8px;
padding: 8px;
}
.issue-item textarea {
width: 100%;
}
.release-row {
border-top: 1px solid var(--border);
padding: 6px 0;
}
+60
View File
@@ -3,6 +3,66 @@
* under "unreleased"; scripts/release.sh renames the key to the release version.
*/
export const WHATS_NEW: Record<string, { en: string[]; de: string[] }> = {
"202611-00049": {
en: ["Factory: every merged issue gets a version and a git tag (patch per issue, minor per finished milestone)", "Factory: start a release with Docker image (amd64 + arm64), downloads and a release on the forge", "Factory: set the number of rework rounds and tries per phase"],
de: ["Factory: jedes gemergte Issue bekommt eine Version und einen Git-Tag (Patch je Issue, Minor je abgeschlossenem Meilenstein)", "Factory: Release mit Docker-Image (amd64 + arm64), Downloads und Release auf der Forge anstoßen", "Factory: Anzahl der Nachbesserungsrunden und Versuche je Phase einstellbar"],
},
"202611-00048": {
en: ["Fixed: the factory page was blank"],
de: ["Behoben: die Factory-Seite blieb leer"],
},
"202611-00047": {
en: ["Factory: see an issue's pull request and approve/merge it right in the factory page", "Factory: plan a feature with a model or cut a milestone into numbered deliverables – the issues are created for you"],
de: ["Factory: Pull Request eines Issues ansehen und direkt in der Factory freigeben/mergen", "Factory: Feature mit einem Modell planen oder einen Meilenstein in nummerierte Deliverables zerlegen – die Issues werden für dich angelegt"],
},
"202611-00044": {
en: ["Factory: the pull request is now opened by the acceptance, after it passed", "Factory has its own icon and all its chats sit in one sidebar folder", "Factory acceptance only judges the scenarios in the issue's scope"],
de: ["Factory: den Pull Request erstellt jetzt die Abnahme, nachdem sie bestanden ist", "Die Factory hat ein eigenes Icon, alle ihre Chats liegen in einem Ordner in der Seitenleiste", "Die Factory-Abnahme beurteilt nur die Szenarien im Umfang des Issues"],
},
"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"],
},
"202611-00042": {
en: ["Factory: approved issues are now built automatically on their own branch, with a pull request at the end"],
de: ["Factory: freigegebene Issues werden jetzt automatisch auf einem eigenen Branch gebaut, am Ende steht ein Pull Request"],
},
"202611-00041": {
en: ["New: software factory – write a spec with a model, create the repository (Gitea, GitHub or GitLab) and let agents review it, a model per phase", "Factory overview with board, tokens, run time and links into the runs"],
de: ["Neu: Software-Factory – Spec mit einem Modell schreiben, Repository anlegen (Gitea, GitHub oder GitLab) und von Agenten prüfen lassen, ein Modell pro Phase", "Factory-Übersicht mit Board, Tokens, Laufzeit und Links in die Läufe"],
},
"202611-00040": {
en: ["Images you upload are now visible to Claude Code (they arrived empty before)"],
de: ["Hochgeladene Bilder sind für Claude Code jetzt sichtbar (sie kamen vorher leer an)"],
},
"202611-00039": {
en: ["The chat colour no longer tints the chat background", "Claude Code can ask you questions again (question card in the chat)"],
de: ["Die Chat-Farbe färbt den Hintergrund des Chats nicht mehr ein", "Claude Code kann dir wieder Fragen stellen (Fragenkarte im Chat)"],
},
"202611-00038": {
en: ["Sidebar chat menu: Delete added; colour and icon are now chosen in the chat's own menu"],
de: ["Chat-Menü in der Sidebar: Löschen hinzugefügt; Farbe und Icon wählst du jetzt im Menü des Chats"],
},
"202611-00037": {
en: ["Deleting a chat now asks whether to delete its own folder too"],
de: ["Beim Löschen eines Chats wirst du gefragt, ob sein eigener Ordner mitgelöscht werden soll"],
},
"202611-00036": {
en: ["Claude Code can now use all CodeCraft tools (image generation, 3D, browser, scheduling …)"],
de: ["Claude Code kann jetzt alle CodeCraft-Tools nutzen (Bildgenerierung, 3D, Browser, Zeitpläne …)"],
},
"202611-00035": {
en: ["Creating SSH keys works in the container now (fixes \"No user exists for uid\")"],
de: ["SSH-Schlüssel lassen sich im Container jetzt erzeugen (behebt \"No user exists for uid\")"],
},
"202611-00034": {
en: ["ssh/scp/sftp now work in the container (fixes \"No user exists for uid\")"],
de: ["ssh/scp/sftp funktionieren jetzt im Container (behebt \"No user exists for uid\")"],
},
"202611-00033": {
en: ["SSH keys in Settings → Account: agents, terminal and git use them to reach other servers"],
de: ["SSH-Schlüssel unter Einstellungen → Account: Agenten, Terminal und Git nutzen sie für den Zugriff auf andere Server"],
},
"202611-00032": {
en: ["Agents now use your stored git credentials instead of searching for them (also Claude Code)"],
de: ["Agenten nutzen deine hinterlegten Git-Zugangsdaten, statt danach zu suchen (auch Claude Code)"],