Compare commits

..
9 Commits
Author SHA1 Message Date
tben 1a68dd7e19 Merge pull request 'docs: rewrite README for clarity and conversion' (#1) from docs/readme-rewrite into main
CI / check (push) Waiting to run
Reviewed-on: #1
2026-11-23 09:06:01 +01:00
tben 63512b75ce Correct four README claims and move the demo shot list
CI / check (pull_request) Waiting to run
The coordinator does run tasks on computers, so it never "does the work
itself" was wrong. Bot files are found by name or path, not searched by
meaning. Data leaves the box wherever the user points a bot, not only to
the model provider. A hand-over leaves the same browser and files, so say
that instead of "it carries on".

The seven-beat GIF shot list moves out of a 32-line comment in the
README into docs/readme/DEMO.md, and the Gitea link keeps its canonical
capitalisation.
2026-11-23 09:01:28 +01:00
tben 0fd348f158 docs: rewrite README for clarity and conversion
CI / check (pull_request) Canceled after 0s
- Hero states the product in one line
- Install command above the fold
- New comparison section
- Star CTA added
- Contributing section expanded
- Demo GIF placeholder added, commented out
2026-11-23 07:45:47 +00:00
tben aef7169173 Release 0.27.10
Release image / image (release) Waiting to run
Release image / computer-image (release) Waiting to run
CI / check (push) Canceled after 0s
2026-11-23 07:33:39 +01:00
tben 712145582e Test that an active plan marks a reply due 2026-11-23 07:32:23 +01:00
tben 1b26c5b42f Stand the thinking row at once when a plan is approved 2026-11-23 07:26:44 +01:00
tben 3e13d02341 Adopt only the account a sign-in here made, so a provider leftover cannot double a card
CI / check (push) Canceled after 0s
Release image / image (release) Canceled after 0s
Release image / computer-image (release) Canceled after 0s
A fresh app adopted the first connected account its provider listed, even
when no request here started it. A leftover at the provider (a sign-in made
there, or an earlier attempt's) took that card, and the user's own sign-in
was then claimed beside it, so every connect in production made two cards
for one mailbox.

A row is now made only for a connected account a pending request names, an
unfinished sign-in stores nothing, and the insert refuses a second row for
the same provider account when a poll and the cron reach it at once.

Release 0.27.9.
2026-11-23 05:57:53 +01:00
tben a5dbde1da7 Release 0.27.8
CI / check (push) Canceled after 0s
Release image / image (release) Canceled after 0s
Release image / computer-image (release) Canceled after 0s
2026-11-22 18:04:53 +01:00
tben 51747c069f Let a connector given to a workspace reach every account connected for it
A workspace's connector gave every member its tools but no account, so a
member with no sign-in of their own was told nothing was connected while
the super admin's account sat unused. Account reach now follows the
workspace grant, whoever connected the account, and the run names them.

The Composio listing also filtered on `user_id`, which it ignores, so one
person's sync adopted the whole project's accounts: it takes `user_ids`.
2026-11-22 18:04:48 +01:00
22 changed files with 573 additions and 321 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+211 -165
View File
@@ -5,69 +5,104 @@
<img src="docs/readme/lockup-dark.svg#gh-dark-mode-only" alt="Cobble" height="56">
</h1>
A crew of small AI worker bots you host yourself (alpha).
### A crew of small AI worker bots you host yourself
![Cobble: a crew of small AI worker bots you host yourself](docs/readme/hero-light.png#gh-light-mode-only)
![Cobble: a crew of small AI worker bots you host yourself](docs/readme/hero-dark.png#gh-dark-mode-only)
Not a chat box with a system prompt. A coordinator, a team of workers, and real
Docker computers with a browser and a shell that they actually operate.
[![CI](https://github.com/Moduletrace/cobble/actions/workflows/ci.yml/badge.svg)](https://github.com/Moduletrace/cobble/actions/workflows/ci.yml)
[![GitHub stars](https://img.shields.io/github/stars/Moduletrace/cobble?style=flat&color=0e1116)](https://github.com/Moduletrace/cobble/stargazers)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Website](https://img.shields.io/badge/website-cobble.moduletrace.org-0e1116)](https://cobble.moduletrace.org)
[![Bun](https://img.shields.io/badge/runs%20on-Bun-14151a?logo=bun&logoColor=white)](https://bun.sh)
[![Runs on Bun](https://img.shields.io/badge/runs%20on-Bun-14151a?logo=bun&logoColor=white)](https://bun.sh)
```bash
curl -fsSL https://url.moduletrace.com/cobble | sudo bash
```
One command. One SQLite file. Your machine. No account, no per-seat pricing.
<br>
<!-- Demo GIF: shot list in docs/readme/DEMO.md. -->
<!-- ![Cobble in action: delegating to a crew, a bot driving a real browser, a handoff to the human, a finished pull request](docs/readme/demo.gif) -->
![Cobble: a self-hosted crew of small AI worker bots](docs/readme/hero-light.png#gh-light-mode-only)
![Cobble: a self-hosted crew of small AI worker bots](docs/readme/hero-dark.png#gh-dark-mode-only)
[Website](https://cobble.moduletrace.org) · [Install](#install) · [Features](#features) · [Development](#development) · [Architecture](AGENTS.md)
</div>
> **Alpha.** Cobble is still in alpha: interfaces, database schema and
> settings change between releases, and things break. Install it to try it
> out and to tell us what is wrong, but keep your own backups (Settings >
> Backups) and do not put it in front of work you cannot lose. Every release
> is a real release: the installer updates an existing install in place and
> keeps its data.
---
Cobble is a self-hosted crew of small AI worker bots. You get a coordinator
and a set of workers, each with its own job, models, memory and workspace.
They talk to you in one chat, share workspaces, run routines on a schedule,
and drive their own computers: lean Docker sandboxes with a real Chrome and
a shell, which a bot can use and hand back to you when it needs help.
> **Alpha.** Cobble is still in alpha. Interfaces, database schema and settings
> change between releases, and things break. Install it to try it out and to
> tell us what is wrong, but keep your own backups (Settings > Backups) and do
> not put it in front of work you cannot lose. Every release is a real release:
> the installer updates an existing install in place and keeps its data.
It is an install, not a SaaS. One SQLite database, one Docker container, and
your data on your own machine.
## The problem with one big assistant
**Why small workers instead of one big assistant**
You give an agent a task. It works for forty turns. Somewhere in the middle it
loses the thread, forgets what it already tried, or quietly stops and says it is
done. You cannot see what it is doing, you cannot stop it cleanly, and the whole
thing lives in someone else's cloud with your files in it.
- **A crew, not a chat.** Each worker has one job and only loads the context
for it. A five-bot crew does five things in parallel, and each one stays
cheap and focused.
Cobble splits that agent into a crew and gives the crew a machine:
- **A crew, not a chat.** Each worker has one job and only loads the context for
it. A five-bot crew does five things in parallel, and each one stays cheap
and focused. The coordinator plans and delegates; the workers do the work.
- **Bots you can see through.** The face on each stone is the status: idle,
working, done, asleep, needs you. You read the whole crew at a glance
instead of asking each one what it is doing.
- **Real computers.** Workers run on your own sandboxed machines, with
browser, terminal, files and desktop, not just a tool loop.
working, done, asleep, needs you. You read the whole crew at a glance instead
of asking each one what it is doing.
- **Real computers.** Workers run on your own sandboxed Docker machines, with a
real headful Chrome on a virtual screen, a shell, files and a desktop. Not
just a tool loop that can call `curl`.
- **A human in the loop that works.** When a bot hits a login wall or a captcha,
it hands the live browser back to you mid-task. You act, you hand it back, and
it continues from the same browser and the same files. No restart, no lost
state.
- **Yours.** Self-hosted, MIT, one SQLite file to back up, no account and no
per-seat billing.
per-seat billing. Your keys stay on your machine.
## Where Cobble fits
| | One big chat assistant | A hosted agent platform | Cobble |
|---|---|---|---|
| Runs on your hardware | No | No | Yes, one container plus one per computer |
| Parallel work | Manually, one thread | Often | Yes, one worker per job |
| Real browser and shell | No | Sometimes, headless | Yes, headful Chrome plus a shell, visible live |
| Human takes over mid-task | Copy and paste | Rarely | Yes, live, same session |
| Your data leaves the box | Yes | Yes | Only where you point it: your provider, the tools you give a bot |
| Cost model | Per seat | Per seat plus usage | Your hardware, your API keys |
| Licence | Proprietary | Proprietary | MIT |
If you want a single assistant that writes emails, a chat app is cheaper. If you
want a team that ships work on machines you control, that is this.
## Features
| Area | What you get |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Crew | One coordinator and as many workers as you need, each with a name, a role, a hue and its own core instructions |
| Rail | The coordinator, your recent workers and their latest sessions, then your workspaces, each row carrying its status line |
| Chat | Markdown with @-mentions for bots and #-mentions for workspaces, replies and quotes, reactions, attachments, older messages on scroll, drafts kept locally |
| Stop | Stop a bot from the thinking row or the header menu: its queued and running work stops at once, everywhere you chat with it, and it goes idle |
| Header | The bot's model, provider and computer at a glance, one click from either, and its picture, instructions and settings on the avatar |
| Workspaces | A shared home for a group of bots: shared context, per-workspace instructions and memory, a default computer, and a dashboard |
| Memory | Each bot keeps core memory, memory about you, and workspace memory, and rewrites it as it works |
| Routines | Cron schedules per bot, written in chat, that queue a task on its own |
| Computers | Docker sandboxes with a real headful Chrome and a shell, shown live in the chat and handed back to you mid-task |
| Files | Bots keep files on your data volume, search them by meaning, and attach the ones they make to a reply |
| Models | OpenRouter, OpenAI, Anthropic, Gemini, DeepSeek, Groq, Mistral, xAI, Ollama or any OpenAI-compatible server, per bot and per harness |
| Voice | Dictate into the composer, play any bot reply, with speech-to-text and text-to-speech models of your choice |
| Tools | Install your own MCP servers and custom HTTP, script or prompt tools, and give them to bots or workspaces |
| Skills | Write runbooks your bots follow. Each bot sees what a skill is for and reads the whole thing only when it needs it |
| Knowledge | Knowledgebases of documents and notes, given to bots or workspaces: every reply starts from the passages that fit, searched by one embedding model |
| App | Installable PWA with Web Push, dark mode, and a rail built for a phone |
| Area | What you get |
| --- | --- |
| Crew | One coordinator and as many workers as you need, each with a name, a role, a hue and its own core instructions |
| Rail | The coordinator, your recent workers and their latest sessions, then your workspaces, each row carrying its status line |
| Chat | Markdown with @-mentions for bots and #-mentions for workspaces, replies and quotes, reactions, attachments, older messages on scroll, drafts kept locally |
| Stop | Stop a bot from the thinking row or the header menu: its queued and running work stops at once, everywhere you chat with it, and it goes idle |
| Header | The bot's model, provider and computer at a glance, one click from either, and its picture, instructions and settings on the avatar |
| Workspaces | A shared home for a group of bots: shared context, per-workspace instructions and memory, a default computer, and a dashboard |
| Memory | Each bot keeps core memory, memory about you, and workspace memory, and rewrites it as it works |
| Routines | Cron schedules per bot, written in chat, that queue a task on its own |
| Computers | Docker sandboxes with a real headful Chrome and a shell, shown live in the chat and handed back to you mid-task |
| Files | Bots keep files on your data volume, find them by name or path, and attach the ones they make to a reply |
| Models | OpenRouter, OpenAI, Anthropic, Gemini, DeepSeek, Groq, Mistral, xAI, Ollama or any OpenAI-compatible server, per bot and per harness |
| Voice | Dictate into the composer, play any bot reply, with speech-to-text and text-to-speech models of your choice |
| Tools | Install your own MCP servers and custom HTTP, script or prompt tools, and give them to bots or workspaces |
| Skills | Write runbooks your bots follow. Each bot sees what a skill is for and reads the whole thing only when it needs it |
| Knowledge | Knowledgebases of documents and notes, given to bots or workspaces: every reply starts from the passages that fit, searched by one embedding model |
| App | Installable PWA with Web Push, dark mode, and a rail built for a phone |
## Screenshots
@@ -77,44 +112,72 @@ their instructions there, and its computers.
![A workspace dashboard in Cobble](docs/readme/workspace-light.png#gh-light-mode-only)
![A workspace dashboard in Cobble, dark mode](docs/readme/workspace-dark.png#gh-dark-mode-only)
## How it fits together
```
You ── chat ── Coordinator ── delegates ── Workers
│ │
├── Workspaces ──────────┤
│ context, memory, bots │
├── Routines ────────────┤
│ cron schedules │
└── Computers ───────────┘
docker sandboxes:
real Chrome, shell
```
- **Coordinator** is yours alone. It plans, delegates to workers, and keeps the
crew in order. It is the only bot that reaches every worker.
- **Workers** are the crew. Each has a job, its own instructions and memory, and
its own models if you want to tune cost per bot.
- **Workspaces** group bots around a subject. Models, instructions, memory and
the default computer resolve per workspace before per bot.
- **Routines** are cron schedules that queue a task without you asking.
- **Computers** are per-install Docker containers of Cobble's own image
(`computer/`: Debian 13, Google Chrome on a virtual screen, Playwright MCP and
a shell). Bots drive the browser and the shell, and you can watch the same
browser live in the chat and take over.
Each conversation is split into sessions, so a long-running bot does not grow
one endless thread: the bot names a session, summarizes it, and carries the
summary into the next one.
## Install
On a Linux machine with Docker (the installer adds Docker when it is
missing):
On a Linux machine with Docker (the installer adds Docker when it is missing):
```bash
curl -fsSL https://url.moduletrace.com/cobble | sudo bash
```
The app serves plain HTTP on the port it prints, usually
`http://<your-ip>:7227`. Put a reverse proxy or tunnel in front of it for
HTTPS (see [HTTPS](#https)), then open the proxy's address and create the
super admin account. The first signup also creates the coordinator and the
main computer, which pulls the computer image in the background. Give it a
few minutes.
`http://<your-ip>:7227`. Put a reverse proxy or tunnel in front of it for HTTPS
(see [HTTPS](#https)), then open the proxy's address and create the super admin
account. The first signup also creates the coordinator and the main computer,
which pulls the computer image in the background. Give it a few minutes.
Then open **Settings > Models**, add an OpenRouter key (or another provider)
and wait for the model list to sync. This is what the bots think with.
Then open **Settings > Models**, add an OpenRouter key (or another provider) and
wait for the model list to sync. This is what the bots think with.
### Requirements
- Linux amd64 or arm64, with Docker. The installer installs Docker from
get.docker.com when it is missing.
- 2 CPU cores, 4 GB RAM and 20 GB free disk for the app plus one computer.
Each computer is its own container with its own memory limit.
- Docker Desktop on macOS works for development and small installs, but
Linux is the supported host.
- 2 CPU cores, 4 GB RAM and 20 GB free disk for the app plus one computer. Each
computer is its own container with its own memory limit.
- Docker Desktop on macOS works for development and small installs, but Linux is
the supported host.
- Port 7227, or another port with `--port`.
- A reverse proxy or tunnel in front for HTTPS. The app itself serves plain
HTTP and never handles certificates.
- A reverse proxy or tunnel in front for HTTPS. The app itself serves plain HTTP
and never handles certificates.
The installer binds to `0.0.0.0` so the app is reachable from your phone on
the same network. Use `--bind 127.0.0.1` when a reverse proxy is the only
thing that should reach it.
The installer binds to `0.0.0.0` so the app is reachable from your phone on the
same network. Use `--bind 127.0.0.1` when a reverse proxy is the only thing that
should reach it.
The app container itself is limited to 1 CPU and 2 GB of memory, since the
heavy work happens in the computers' own containers. Change that with
`--cpus` and `--memory`; each computer keeps its own limits.
The app container itself is limited to 1 CPU and 2 GB of memory, since the heavy
work happens in the computers' own containers. Change that with `--cpus` and
`--memory`; each computer keeps its own limits.
## HTTPS
@@ -127,21 +190,21 @@ point that at `http://<this machine>:7227`:
`proxy_set_header X-Forwarded-Proto $scheme;`.
- Pass `/ws` through as well as ordinary requests, including the upgrade.
- Keep the address the browser used in `Host` (or send it as
`X-Forwarded-Host`). Live updates and the computers' terminals only accept
a websocket from the app's own address; Caddy and Cloudflare Tunnel keep
it, and nginx needs `proxy_set_header Host $host;`.
- Give the proxy a real certificate. Browsers treat plain HTTP as unsafe, so
the installable app, offline support, Web Push notifications and voice
recording stay off until the address is HTTPS.
`X-Forwarded-Host`). Live updates and the computers' terminals only accept a
websocket from the app's own address; Caddy and Cloudflare Tunnel keep it, and
nginx needs `proxy_set_header Host $host;`.
- Give the proxy a real certificate. Browsers treat plain HTTP as unsafe, so the
installable app, offline support, Web Push notifications and voice recording
stay off until the address is HTTPS.
Nothing on the machine needs a certificate installed: the browser only ever
talks to the proxy. See the Help page in the app for the common proxy fixes.
## Update and uninstall
The same script is the updater. It keeps the database, media, computers'
home directories and generated secrets, backs up the database before
replacing the container, and does nothing when the image has not changed.
The same script is the updater. It keeps the database, media, computers' home
directories and generated secrets, backs up the database before replacing the
container, and does nothing when the image has not changed.
```bash
curl -fsSL https://url.moduletrace.com/cobble | sudo bash
@@ -157,54 +220,24 @@ curl -fsSL https://url.moduletrace.com/cobble | sudo bash -s -- --uninstall --pu
### Options
| Option | Meaning |
| --------------------- | ---------------------------------------------------------- |
| `--home DIR` | Install directory, default `/opt/cobble` |
| `--data-dir DIR` | Data directory mounted at `/data`, default `HOME/data` |
| `--port PORT` | Host port, default `7227` |
| `--bind ADDRESS` | Host address to publish on, default `0.0.0.0` |
| `--cpus N` | CPU cores for the app container, default `1` |
| `--memory MB` | Memory for the app container in MB, default `2048` |
| `--image IMAGE` | Container image, default `ghcr.io/moduletrace/cobble` |
| `--version TAG` | Image tag, default `latest` |
| Option | Meaning |
| --- | --- |
| `--home DIR` | Install directory, default `/opt/cobble` |
| `--data-dir DIR` | Data directory mounted at `/data`, default `HOME/data` |
| `--port PORT` | Host port, default `7227` |
| `--bind ADDRESS` | Host address to publish on, default `0.0.0.0` |
| `--cpus N` | CPU cores for the app container, default `1` |
| `--memory MB` | Memory for the app container in MB, default `2048` |
| `--image IMAGE` | Container image, default `ghcr.io/moduletrace/cobble` |
| `--version TAG` | Image tag, default `latest` |
| `--extra-network NET` | Join another Docker network, for a tunnel or reverse proxy |
| `--force` | Recreate the container even when it is current |
| `--no-pull` | Use an image that is already on the machine |
| `--skip-backup` | Update without a database backup |
| `--no-docker-install` | Fail instead of installing Docker |
| `--yes`, `-y` | Accept the defaults without asking |
| `--uninstall` | Stop and remove the app container |
| `--purge` | With `--uninstall`, also delete the data directory |
## How it fits together
```
You ── chat ── Coordinator ── delegates ── Workers
│ │
├── Workspaces ────────────┤
│ context, memory, bots │
├── Routines ──────────────┤
│ cron schedules │
└── Computers ─────────────┘
docker sandboxes:
real Chrome, shell
```
- **Coordinator** is yours alone. It plans, delegates to workers, and keeps
the crew in order. It is the only bot that reaches every worker.
- **Workers** are the crew. Each has a job, its own instructions and memory,
and its own models if you want to tune cost per bot.
- **Workspaces** group bots around a subject. Models, instructions, memory
and the default computer resolve per workspace before per bot.
- **Routines** are cron schedules that queue a task without you asking.
- **Computers** are per-install Docker containers of Cobble's own image
(`computer/`: Debian 13, Google Chrome on a virtual screen, Playwright MCP
and a shell). Bots drive the browser and the shell, and you can watch the
same browser live in the chat and take over.
Each conversation is split into sessions, so a long-running bot does not grow
one endless thread: the bot names a session, summarizes it, and carries the
summary into the next one.
| `--force` | Recreate the container even when it is current |
| `--no-pull` | Use an image that is already on the machine |
| `--skip-backup` | Update without a database backup |
| `--no-docker-install` | Fail instead of installing Docker |
| `--yes`, `-y` | Accept the defaults without asking |
| `--uninstall` | Stop and remove the app container |
| `--purge` | With `--uninstall`, also delete the data directory |
## Data and settings
@@ -227,38 +260,37 @@ Everything that must survive an update lives under the install directory:
`.env` holds the port and the encryption keys. The keys encrypt sessions and
settings, so keep a copy and do not rotate them without re-entering provider
keys and other secrets. Provider keys, MCP servers, tools and app settings
are managed in the app, not in `.env`.
keys and other secrets. Provider keys, MCP servers, tools and app settings are
managed in the app, not in `.env`.
Edit `.env` and run `docker restart cobble` to apply changes. The installer
only appends missing values and keeps what is already there, apart from the
port it manages.
Edit `.env` and run `docker restart cobble` to apply changes. The installer only
appends missing values and keeps what is already there, apart from the port it
manages.
Settings > Backups makes two kinds of copy. Database snapshots (bun-sqlite's
`backup` command) stay in `data/db/.backups` and can be restored from the
app. Whole-data archives are a `tar.gz` of the entire `data/` directory,
written to `backups-archives/` (mounted at `/backups-archives`, the
`BACKUP_ARCHIVE_DIR` setting); every entry sits under one folder named after
the archive, so extracting one by hand drops a single folder. Each group
can create a copy, restore from one (a listed row, or a file uploaded from
the button beside Create), download it and delete it; the newest five
archives are kept.
`backup` command) stay in `data/db/.backups` and can be restored from the app.
Whole-data archives are a `tar.gz` of the entire `data/` directory, written to
`backups-archives/` (mounted at `/backups-archives`, the `BACKUP_ARCHIVE_DIR`
setting); every entry sits under one folder named after the archive, so
extracting one by hand drops a single folder. Each group can create a copy,
restore from one (a listed row, or a file uploaded from the button beside
Create), download it and delete it; the newest five archives are kept.
The app container is started with the Docker socket mounted and
`MAIN_SERVER=1`, so it can create computer containers and run cron, the
queue and Web Push.
`MAIN_SERVER=1`, so it can create computer containers and run cron, the queue
and Web Push.
## Images
Every release publishes a multi-arch image to
`ghcr.io/moduletrace/cobble`, which is what the installer pulls. Tags are
`latest`, the release version, `major.minor` and the commit sha.
Every release publishes a multi-arch image to `ghcr.io/moduletrace/cobble`,
which is what the installer pulls. Tags are `latest`, the release version,
`major.minor` and the commit sha.
The same image is copied into `git.tben.me/moduletrace/cobble` by
`bun run mirror:gitea`, which runs after the build over the VPN (the Gitea
registry is not on the public internet, so GitHub Actions cannot reach it).
Install from Gitea with `--image git.tben.me/moduletrace/cobble`, or build
from source with `docker build -t cobble:local .` and
Install from Gitea with `--image git.tben.me/moduletrace/cobble`, or build from
source with `docker build -t cobble:local .` and
`--image cobble --version local --no-pull`.
A release is published from a clean `main` with the two scripts, which tag the
@@ -291,32 +323,31 @@ Open `http://localhost:7227`. With no users, every page goes to
SEED_SUPER_ADMIN_PASSWORD=... bun run seed
```
The development server serves plain HTTP, the same as the container. To try
the app from a phone, run a proxy or tunnel in front of it (see
[HTTPS](#https)); the installed app, Web Push and voice need that secure
context.
The development server serves plain HTTP, the same as the container. To try the
app from a phone, run a proxy or tunnel in front of it (see [HTTPS](#https)); the
installed app, Web Push and voice need that secure context.
| Command | Purpose |
| ---------------------- | ----------------------------------- |
| `bun run dev` | Development server |
| `bun run start` | Production server on the host |
| `bun run typecheck` | Type-check |
| `bun run test` | Run the test suite |
| `bun run check:bundle` | Bundle budget after a build |
| `bun run seed` | Create the super admin from the CLI |
| `bun run seed:bots` | Add a sample crew |
| `bun run db:schema` | Sync the schema and types |
| `bun run gen:favicon` | Regenerate favicons and PWA assets |
| Command | Purpose |
| --- | --- |
| `bun run dev` | Development server |
| `bun run start` | Production server on the host |
| `bun run typecheck` | Type-check |
| `bun run test` | Run the test suite |
| `bun run check:bundle` | Bundle budget after a build |
| `bun run seed` | Create the super admin from the CLI |
| `bun run seed:bots` | Add a sample crew |
| `bun run db:schema` | Sync the schema and types |
| `bun run gen:favicon` | Regenerate favicons and PWA assets |
Plain Node does not work: the app runs on Bun. The stack is Bun,
[`@moduletrace/bunext`](https://github.com/Moduletrace/bunext) for
filesystem routing, SQLite via
[`@moduletrace/bun-sqlite`](https://github.com/Moduletrace/bun-sqlite),
Tailwind CSS and the `@moduletrace/twui` component library. The model layer is
one adapter over OpenAI-compatible APIs, so any compatible provider works.
[`@moduletrace/bunext`](https://github.com/Moduletrace/bunext) for filesystem
routing, SQLite via
[`@moduletrace/bun-sqlite`](https://github.com/Moduletrace/bun-sqlite), Tailwind
CSS and the `@moduletrace/twui` component library. The model layer is one
adapter over OpenAI-compatible APIs, so any compatible provider works.
See [AGENTS.md](AGENTS.md) for the full architecture, routes, queue, harness
and data model. CI runs type-check and tests on every push and pull request;
See [AGENTS.md](AGENTS.md) for the full architecture, routes, queue, harness and
data model. CI runs type-check and tests on every push and pull request;
releases are built by GitHub Actions and pushed to both registries. See
[RELEASING.md](RELEASING.md) for the release and launch checklist.
@@ -325,9 +356,24 @@ releases are built by GitHub Actions and pushed to both registries. See
Issues and pull requests are welcome, in English, on either
[GitHub](https://github.com/Moduletrace/cobble) or
[Gitea](https://git.tben.me/Moduletrace/cobble). Run `bun run typecheck` and
`bun run test` before opening a pull request, and read
[AGENTS.md](AGENTS.md) first: it documents the conventions the code follows.
`bun run test` before opening a pull request, and read [AGENTS.md](AGENTS.md)
first: it documents the conventions the code follows.
Good first contributions right now: a worker role that ships as a one-click
template, an MCP server integration that other people would install, a missing
proxy recipe for the Help page, or a test around a bug you hit while installing.
## License
MIT. See [LICENSE](LICENSE).
---
<div align="center">
**If Cobble saves you from stitching three tools together, star the repo.**
It is the fastest way to help other people find it.
[![Star Cobble](https://img.shields.io/github/stars/Moduletrace/cobble?style=social)](https://github.com/Moduletrace/cobble/stargazers)
</div>
+35
View File
@@ -0,0 +1,35 @@
# Demo GIF
The demo recording is a placeholder. `README.md` carries the image line commented
out, pointing at `docs/readme/demo.gif`, which does not exist yet.
## To go live
1. Record the loop below and save it as `docs/readme/demo.gif`, under 8 MB
(GitHub renders anything bigger badly, and the point is that it plays
instantly on the repo page).
2. Uncomment the image line near the top of `README.md`.
## Shot list
Target 12 to 18 seconds, 960px wide, loop, no audio.
1. **0.0s** The rail. Coordinator at top, four workers below with different
faces. Mouse hovers one, its status line reads "working".
2. **2.5s** Cut to the chat. You type: "Check whether the staging site still
returns 200 and open a PR if the footer link is broken." Send.
3. **4.5s** The coordinator delegates. Two worker faces go to "working" in the
rail at the same time.
4. **6.5s** Cut to the live computer view. Chrome is open, the bot is scrolling
the staging site. The cursor moves on its own. Terminal panel beside it shows
curl output.
5. **10.0s** The bot hits a login wall. Face flips to "needs you". Card appears
asking to take over. You click, type the password, hand it back.
6. **12.5s** The bot finishes. PR link appears in chat. Worker faces go to
"done".
7. **15.0s** Pull back to the rail. Whole crew idle, everything green, one line
of summary text.
That sequence is the entire product in one loop: delegate, parallel work, a real
browser, a human handoff, a shipped artifact. Do not replace it with a
screenshot carousel.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cobble",
"version": "0.27.7",
"version": "0.27.10",
"module": "index.ts",
"type": "module",
"private": true,
@@ -2,6 +2,7 @@ import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_CONNECTOR_ACCOUNTS, BUN_SQLITE_COBBLE_CONNECTORS } from "@/db/types/db";
import type { BotConnectorEntry, ConnectorAccountRecord, ConnectorRecord } from "@/src/types";
import botConnectorsSql from "@/src/utils/bot-connectors-sql";
import connectorAccountReachSql from "@/src/utils/connector-account-reach-sql";
import attachConnectorAccountScopes from "./attach-connector-account-scopes";
import parseConnectorAccountRow from "./parse-connector-account-row";
import parseConnectorRow from "./parse-connector-row";
@@ -18,10 +19,11 @@ type ConnectorRow = BUN_SQLITE_COBBLE_CONNECTORS & { connection_name?: string };
/**
* The connectors a conversation's bot can use for this user, with the
* accounts that reach there: this user's own (whatever their status, so a
* pending sign-in still shows), and any connected account given to this
* bot, this workspace or every bot, named with its owner. Each app says
* where it comes from: the install, this workspace, this user's own
* attachment, or an account given here.
* pending sign-in still shows), every connected account of a connector given
* to this workspace, and any connected account given to this bot, this
* workspace or every bot, named with its owner. Each app says where it comes
* from: the install, this workspace, this user's own attachment, or an
* account given here.
*/
export default async function grabBotConnectors({
user_id,
@@ -44,6 +46,7 @@ export default async function grabBotConnectors({
const connection_names = new Map(found.map((row) => [Number(row.id), row.connection_name || ""]));
const ids = connectors.map((connector) => connector.id);
const placeholders = ids.map(() => "?").join(", ");
const workspace_reach = connectorAccountReachSql({ workspace_id });
const [account_res, workspace_res, bot_res] = await Promise.all([
BunSQLite.sql<AccountRow>({
@@ -57,13 +60,18 @@ export default async function grabBotConnectors({
a.all_bots = 1
OR EXISTS (SELECT 1 FROM connector_account_bots ab WHERE ab.account_id = a.id AND ab.bot_id = ?)
${workspace_id ? `OR EXISTS (SELECT 1 FROM connector_account_workspaces aw WHERE aw.account_id = a.id AND aw.workspace_id = ?)` : ""}
${workspace_reach.sql}
)
)
)
ORDER BY a.id ASC`,
values: workspace_id
? [...ids, Number(user_id), Number(bot_id), Number(workspace_id)]
: [...ids, Number(user_id), Number(bot_id)],
values: [
...ids,
Number(user_id),
Number(bot_id),
...(workspace_id ? [Number(workspace_id)] : []),
...workspace_reach.values,
],
}),
BunSQLite.sql<{ connector_id: number }>({
sql: `SELECT connector_id FROM workspace_connectors WHERE connector_id IN (${placeholders})`,
@@ -2,6 +2,7 @@ import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_CONNECTOR_ACCOUNTS, BUN_SQLITE_COBBLE_CONNECTORS } from "@/db/types/db";
import type { ConnectorAccountRecord, ConnectorRecord } from "@/src/types";
import botConnectorsSql from "@/src/utils/bot-connectors-sql";
import connectorAccountReachSql from "@/src/utils/connector-account-reach-sql";
import attachConnectorAccountScopes from "./attach-connector-account-scopes";
import parseConnectorAccountRow from "./parse-connector-account-row";
import parseConnectorRow from "./parse-connector-row";
@@ -19,9 +20,10 @@ type Params = {
export type RunConnector = {
connector: ConnectorRecord;
/**
* The accounts the run may use for it: the user's own, and every one
* given to this bot, this workspace or every bot. Empty means nothing
* to call with: the card asks them to connect one.
* The accounts the run may use for it: the user's own, every connected
* account of a connector given to this workspace, and every one given to
* this bot, this workspace or every bot. Empty means nothing to call
* with: the card asks them to connect one.
*/
accounts: ConnectorAccountRecord[];
};
@@ -31,9 +33,9 @@ type AccountRow = BUN_SQLITE_COBBLE_CONNECTOR_ACCOUNTS & { owner_name?: string }
/**
* The connectors one run reaches (`botConnectorsSql`) with the accounts it
* may act through: its own user's, never another person's unless that
* account was given to this bot, this workspace or every bot. A connector
* reaches a run without any account; it only becomes callable once there is
* one.
* account was given to this bot, this workspace or every bot, or its app was
* given to this workspace. A connector reaches a run without any account; it
* only becomes callable once there is one.
*/
export default async function grabRunConnectors({ user_id, bot_id, workspace_id }: Params): Promise<RunConnector[]> {
const found =
@@ -47,6 +49,7 @@ export default async function grabRunConnectors({ user_id, bot_id, workspace_id
const connectors = found.map((row) => parseConnectorRow({ row }));
const ids = connectors.map((connector) => connector.id);
const workspace_reach = connectorAccountReachSql({ workspace_id });
const rows =
(
await BunSQLite.sql<AccountRow>({
@@ -60,9 +63,10 @@ export default async function grabRunConnectors({ user_id, bot_id, workspace_id
OR a.all_bots = 1
OR EXISTS (SELECT 1 FROM connector_account_bots b WHERE b.account_id = a.id AND b.bot_id = ?)
OR EXISTS (SELECT 1 FROM connector_account_workspaces w WHERE w.account_id = a.id AND w.workspace_id = ?)
${workspace_reach.sql}
)
ORDER BY a.id ASC`,
values: [...ids, Number(user_id), Number(bot_id), Number(workspace_id || 0)],
values: [...ids, Number(user_id), Number(bot_id), Number(workspace_id || 0), ...workspace_reach.values],
})
).payload || [];
@@ -0,0 +1,85 @@
import { Database } from "bun:sqlite";
import { describe, expect, test } from "bun:test";
import insertConnectorAccountSql from "@/src/functions/backend/db/connectors/insert-connector-account-sql";
function scratch() {
const db = new Database(":memory:");
db.run(`CREATE TABLE connector_accounts (
id INTEGER PRIMARY KEY,
created_at INTEGER,
updated_at INTEGER,
connector_id INTEGER,
user_id INTEGER,
label TEXT,
slug TEXT,
provider_account_id TEXT,
status TEXT,
is_default INTEGER,
connected_at INTEGER,
last_checked_at INTEGER,
last_error TEXT
)`);
return db;
}
function insert(db: Database, { label, slug }: { label: string; slug: string }) {
const statement = insertConnectorAccountSql({
now: 1000,
connector_id: 1,
user_id: 1,
label,
slug,
provider_account_id: "ca_one",
status: "connected",
});
db.query(statement.sql).run(...statement.values);
}
describe("insertConnectorAccountSql", () => {
test("inserts the sign-in once", () => {
const db = scratch();
insert(db, { label: "Ben", slug: "ben" });
const rows = db.query(`SELECT label, slug, status, is_default, last_error FROM connector_accounts`).all();
expect(rows).toEqual([{ label: "Ben", slug: "ben", status: "connected", is_default: 0, last_error: "" }]);
});
test("keeps the row a second sync already wrote for the same account", () => {
const db = scratch();
insert(db, { label: "Ben", slug: "ben" });
insert(db, { label: "Ben again", slug: "ben-2" });
const rows = db.query(`SELECT label, slug FROM connector_accounts`).all();
expect(rows).toEqual([{ label: "Ben", slug: "ben" }]);
});
test("adds a different account of the same app", () => {
const db = scratch();
insert(db, { label: "Ben", slug: "ben" });
const statement = insertConnectorAccountSql({
now: 1000,
connector_id: 1,
user_id: 1,
label: "Ben work",
slug: "ben-work",
provider_account_id: "ca_two",
status: "connected",
});
db.query(statement.sql).run(...statement.values);
expect(db.query(`SELECT provider_account_id FROM connector_accounts ORDER BY id`).all()).toEqual([
{ provider_account_id: "ca_one" },
{ provider_account_id: "ca_two" },
]);
});
});
@@ -0,0 +1,50 @@
import type { ProviderAccountStatus } from "@/src/harness/connectors/connector-provider";
type Params = {
now: number;
connector_id: number;
user_id: number;
label: string;
slug: string;
provider_account_id: string;
status: ProviderAccountStatus;
};
/**
* One row per provider account, even when two syncs (a poll beside the cron)
* reach it at once: the statement itself refuses a second row, so neither can
* insert the same sign-in twice.
*/
export default function insertConnectorAccountSql({
now,
connector_id,
user_id,
label,
slug,
provider_account_id,
status,
}: Params) {
return {
sql: `INSERT INTO connector_accounts
(created_at, updated_at, connector_id, user_id, label, slug, provider_account_id, status, is_default, connected_at, last_checked_at, last_error)
SELECT ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ''
WHERE NOT EXISTS (
SELECT 1 FROM connector_accounts WHERE connector_id = ? AND user_id = ? AND provider_account_id = ?
)`,
values: [
now,
now,
connector_id,
user_id,
label,
slug,
provider_account_id,
status,
status == "connected" ? now : null,
now,
connector_id,
user_id,
provider_account_id,
],
};
}
@@ -2,63 +2,18 @@ import { describe, expect, test } from "bun:test";
import shouldAdoptConnectorAccount from "@/src/functions/backend/db/connectors/should-adopt-connector-account";
describe("shouldAdoptConnectorAccount", () => {
test("adopts a connected account into the app's free card", () => {
expect(shouldAdoptConnectorAccount({ status: "connected", reconnect: false, claimed: false, free_slot: true })).toBe(
true,
);
test("adopts a connected account its own sign-in made", () => {
expect(shouldAdoptConnectorAccount({ status: "connected", reconnect: true, claimed: false })).toBe(true);
expect(shouldAdoptConnectorAccount({ status: "connected", reconnect: false, claimed: true })).toBe(true);
});
test("leaves a second connected account at the provider once the card is taken", () => {
expect(shouldAdoptConnectorAccount({ status: "connected", reconnect: false, claimed: false, free_slot: false })).toBe(
false,
);
test("leaves a connected account nothing here asked for at the provider", () => {
expect(shouldAdoptConnectorAccount({ status: "connected", reconnect: false, claimed: false })).toBe(false);
});
test("adopts a connected account a request here started, even with no free card", () => {
expect(shouldAdoptConnectorAccount({ status: "connected", reconnect: false, claimed: true, free_slot: false })).toBe(
true,
);
});
test("adopts a pending account a request here started", () => {
expect(shouldAdoptConnectorAccount({ status: "pending", reconnect: false, claimed: true, free_slot: false })).toBe(
true,
);
});
test("adopts a pending account that reconnects a row", () => {
expect(shouldAdoptConnectorAccount({ status: "pending", reconnect: true, claimed: false, free_slot: false })).toBe(
true,
);
});
test("skips a pending account nothing here started", () => {
expect(shouldAdoptConnectorAccount({ status: "pending", reconnect: false, claimed: false, free_slot: true })).toBe(
false,
);
expect(shouldAdoptConnectorAccount({ status: "expired", reconnect: false, claimed: false, free_slot: true })).toBe(
false,
);
});
test("skips a stranger once the provider lists none of the app's accounts", () => {
expect(
shouldAdoptConnectorAccount({
status: "connected",
reconnect: false,
claimed: false,
free_slot: true,
wiped: true,
}),
).toBe(false);
expect(
shouldAdoptConnectorAccount({
status: "connected",
reconnect: false,
claimed: true,
free_slot: true,
wiped: true,
}),
).toBe(true);
test("leaves an unfinished sign-in alone until it connects", () => {
expect(shouldAdoptConnectorAccount({ status: "pending", reconnect: true, claimed: false })).toBe(false);
expect(shouldAdoptConnectorAccount({ status: "pending", reconnect: false, claimed: true })).toBe(false);
expect(shouldAdoptConnectorAccount({ status: "expired", reconnect: false, claimed: false })).toBe(false);
});
});
@@ -6,36 +6,17 @@ type Params = {
reconnect: boolean;
/** A pending request here started this sign-in. */
claimed: boolean;
/**
* Whether the app has no live account here yet: one card per app is
* filled by the provider's account, and any other account arrives through
* its own sign-in (claimed).
*/
free_slot: boolean;
/**
* The provider lists none of the accounts the app knows: they were
* replaced there, so no stranger takes their place (the cards offer
* Reconnect instead).
*/
wiped?: boolean;
};
/**
* Whether a provider account becomes a local row. One a request here started
* (or is reconnecting) always does. A connected one the app doesn't know
* gets the app's one free card, so leftovers from earlier sign-ins at the
* provider can't pile up as four rows of the same mailbox; a second account
* appears by signing in again, which claims its own row.
* Whether a provider account becomes a local row: only one a request here
* started or is reconnecting, and only once it is connected. One card per
* sign-in, so an account the provider already held (a leftover from an earlier
* attempt, or a sign-in made at the provider itself) never arrives as a second
* card of the same mailbox. A sign-in that hasn't finished has no card either:
* a link that connects under another id would leave a dead row beside the real
* one.
*/
export default function shouldAdoptConnectorAccount({
status,
reconnect,
claimed,
free_slot,
wiped = false,
}: Params) {
if (reconnect || claimed) return true;
if (wiped) return false;
return status == "connected" && free_slot;
export default function shouldAdoptConnectorAccount({ status, reconnect, claimed }: Params) {
return status == "connected" && (reconnect || claimed);
}
@@ -7,6 +7,7 @@ import connectorSlug from "@/src/utils/connector-slug";
import grabConnector from "./grab-connector";
import parseConnectorAccountRow from "./parse-connector-account-row";
import shouldAdoptConnectorAccount from "./should-adopt-connector-account";
import insertConnectorAccountSql from "./insert-connector-account-sql";
type Params = {
user_id: number | string;
@@ -20,15 +21,15 @@ type Params = {
/**
* Reads the user's accounts for a connector at its provider and brings the
* local rows in line: new sign-ins are added (the first connected one is the
* default), ones the provider reports expired say so, and ones it no longer
* lists are marked revoked without losing their label. Pending connect
* requests are closed as soon as the account they made is connected.
* local rows in line: the account a sign-in here made is added (the first
* connected one is the default), ones the provider reports expired say so, and
* ones it no longer lists are marked revoked without losing their label.
* Pending connect requests are closed as soon as the account they made is
* connected.
*
* One card per app unless the user signed in again: an account the provider
* holds but no request here made fills the app's free card once and is left
* at the provider after that, so a pile of earlier sign-ins cannot arrive as
* four rows of the same mailbox.
* One card per sign-in: an account no request here made is left at the
* provider, so a leftover from an earlier attempt there cannot arrive as a
* second card of the same mailbox beside the one its own sign-in made.
*/
export default async function syncConnectorAccounts({ user_id, connector_id, label }: Params) {
const connector = await grabConnector({ connector_id });
@@ -51,34 +52,29 @@ export default async function syncConnectorAccounts({ user_id, connector_id, lab
const reconnect_for = new Map(
requests
.filter((row) => Number(row.account_id) != 0 && row.provider_account_id)
// A row disconnected since is no target: that sign-in arrives as a new one.
.filter((request) => local.some((account) => Number(account.id) == Number(request.account_id)))
.map((row) => [String(row.provider_account_id), Number(row.account_id)]),
);
let reconnect_row = pendingReconnectRow(requests);
// A row disconnected since is no target: that sign-in arrives as a new one.
if (reconnect_row && !local.some((row) => Number(row.id) == reconnect_row)) reconnect_row = null;
/**
* A sign-in only becomes a row once it is connected, or while the request
* that started it is still open. A pending account nothing here asked for
* is an abandoned or replaced sign-in at the provider (Composio keeps one
* A sign-in only becomes a row once it is connected, and only the account
* its own request names. A pending account nothing here asked for is an
* abandoned or replaced sign-in at the provider (Composio keeps one
* `INITIALIZING` per abandoned link), and adopting it would put a second,
* never connected account beside the one a reconnect replaced.
*/
const claimed = new Set(requests.map((row) => String(row.provider_account_id || "")).filter(Boolean));
/**
* A new sign-in the provider named no account for: the first connected
* account it didn't already have is that sign-in, once.
*/
let unclaimed_sign_in = requests.some((row) => Number(row.account_id) == 0 && !row.provider_account_id);
const seen = new Set(accounts.map((account) => account.provider_account_id));
const now = Date.now();
/**
* The provider lists none of the accounts the app knows: they were
* replaced there (a sign-in made outside the app), so its leftover takes
* no card and the known ones offer Reconnect.
*/
const wiped = local.length > 0 && !local.some((row) => seen.has(String(row.provider_account_id || "")));
/**
* The app's one free card: a live row still listed by the provider holds
* it. An account arriving without a sign-in here (an older attempt at
* the provider) may fill it once, never pile up beside it.
*/
let free_slot = !local.some((row) => row.status == "connected" && seen.has(String(row.provider_account_id || "")));
/**
* A listing that names no account is the provider unable to answer, not
@@ -96,7 +92,7 @@ export default async function syncConnectorAccounts({ user_id, connector_id, lab
}
}
let firstConnected: number | null = free_slot ? 0 : null;
let firstConnected: number | null = local.some((row) => row.status == "connected") ? null : 0;
for (const account of accounts) {
const provider_account_id = String(account.provider_account_id);
@@ -105,10 +101,11 @@ export default async function syncConnectorAccounts({ user_id, connector_id, lab
if (
!shouldAdoptConnectorAccount({
status: account.status,
reconnect: Boolean(reconnect_id) || (account.status == "connected" && Boolean(reconnect_row)),
claimed: claimed.has(provider_account_id),
free_slot,
wiped,
reconnect: Boolean(reconnect_id) || Boolean(reconnect_row),
claimed:
claimed.has(provider_account_id) ||
(unclaimed_sign_in &&
!local.some((row) => String(row.provider_account_id || "") == provider_account_id)),
})
)
continue;
@@ -119,14 +116,11 @@ export default async function syncConnectorAccounts({ user_id, connector_id, lab
account,
fallback_label: label,
reconnect_id,
reconnect_row: account.status == "connected" ? reconnect_row : null,
reconnect_row,
});
if (account.status == "connected" && reconnect_row) reconnect_row = null;
if (account.status != "connected") continue;
if (free_slot) free_slot = false;
reconnect_row = null;
unclaimed_sign_in = false;
if (firstConnected === 0) {
const created = (
@@ -273,23 +267,17 @@ async function upsertAccount({ connector_id, user_id, account, fallback_label, r
slug = `${connectorSlug({ name: display_name, max: 8, fallback: "account" })}-${index}`;
}
await BunSQLite.sql({
sql: `INSERT INTO connector_accounts
(created_at, updated_at, connector_id, user_id, label, slug, provider_account_id, status, is_default, connected_at, last_checked_at, last_error)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, '')`,
values: [
now,
now,
connector_id,
user_id,
display_name,
slug,
account.provider_account_id,
account.status,
account.status == "connected" ? now : null,
now,
],
const { sql, values } = insertConnectorAccountSql({
now,
connector_id,
user_id,
label: display_name,
slug,
provider_account_id: account.provider_account_id,
status: account.status,
});
await BunSQLite.sql({ sql, values });
}
type SettleParams = {
@@ -271,6 +271,8 @@ describe("composioConnectorProvider", () => {
{ provider_account_id: "ca_2", status: "expired", label: undefined },
]);
expect(calls[0]!.url.searchParams.get("toolkit_slugs")).toBe("gmail");
expect(calls[0]!.url.searchParams.get("user_ids")).toBe("cobble-user-4");
expect(calls[0]!.url.searchParams.get("user_id")).toBeNull();
});
test("executes one tool with the account named in the call", async () => {
+5 -3
View File
@@ -330,9 +330,11 @@ export default function composioConnectorProvider({ key, base_url, fetchImpl }:
async accounts({ app, user_id }) {
const items = await listAllPages<any>({
path: "/connected_accounts",
// The listing filters on the plural name only: `toolkit_slug`
// is ignored and answers with the whole project's accounts.
query: { user_id: `cobble-user-${user_id}`, toolkit_slugs: app },
// The listing filters on the plural names only: `toolkit_slug`
// and `user_id` are ignored and answer with the whole
// project's accounts, which is how one user's sync took over
// another's account.
query: { user_ids: `cobble-user-${user_id}`, toolkit_slugs: app },
what: `the ${app} accounts`,
});
@@ -1,6 +1,7 @@
import isCrewMessage from "@/src/utils/is-crew-message";
import { lazy, Suspense, useContext, useEffect, useMemo, useRef, useState } from "react";
import awaitsReply from "../(utils)/awaits-reply";
import planMarksReplyDue from "../(utils)/plan-marks-reply-due";
import Stack from "@moduletrace/twui/layout/Stack";
import type { BotMessageReactionEmoji } from "@/src/dict/bot-dict";
import type {
@@ -336,7 +337,19 @@ export default function Conversation() {
on_open_jobs: () => setOpenReplyJobs(1),
});
useSessionPlan({ session_id, on_change: setSessionPlan });
/**
* An active plan has a step reply on its way, queued by the app with no
* user message before it: mark it due here so the thinking row stands at
* once instead of waiting for the run's first step push.
*/
useSessionPlan({
session_id,
on_change: (plan) => {
setSessionPlan(plan);
if (planMarksReplyDue({ plan })) setOpenReplyJobs(1);
},
});
/**
* The thread's pull-to-reload: the page's crew read again (the layout
@@ -0,0 +1,26 @@
import { describe, expect, test } from "bun:test";
import type { BotPlanView } from "@/src/types";
import planMarksReplyDue from "./plan-marks-reply-due";
const plan = (status: BotPlanView["status"]) => ({ id: 7, status }) as BotPlanView;
describe("planMarksReplyDue", () => {
test("a plan that started has a step reply on its way", () => {
expect(planMarksReplyDue({ plan: plan("active") })).toBe(true);
});
test("approving is what starts it: one waiting for the user does not", () => {
expect(planMarksReplyDue({ plan: plan("planned") })).toBe(false);
});
test("a plan stopped between steps has nothing on its way", () => {
expect(planMarksReplyDue({ plan: plan("paused") })).toBe(false);
expect(planMarksReplyDue({ plan: plan("done") })).toBe(false);
expect(planMarksReplyDue({ plan: plan("cancelled") })).toBe(false);
});
test("no plan in the conversation at all is no reply", () => {
expect(planMarksReplyDue({ plan: null })).toBe(false);
expect(planMarksReplyDue({})).toBe(false);
});
});
@@ -0,0 +1,16 @@
import type { BotPlanView } from "@/src/types";
type Params = {
plan?: BotPlanView | null;
};
/**
* Whether this plan change means a reply is on its way in its conversation.
* An active plan is one the app advances by itself: approving it, picking it
* back up or finishing a step queues the next step with no user message
* before it, so the thread must show the thinking row at once instead of
* waiting for the run's first step push.
*/
export default function planMarksReplyDue({ plan }: Params) {
return plan?.status == "active";
}
@@ -107,7 +107,7 @@ export default function ConnectorAccessModal({
setOpen={(next) => !next && onCancel()}
title={`Who gets ${connector.name}`}
description={
"A bot picked here is yours: it reaches the connector only in your runs there. A workspace reaches everyone working in it; every bot reaches the whole install."
"A bot picked here is yours: it reaches the connector only in your runs there, with your own accounts. A workspace reaches everyone working in it, with every account connected for this connector. Every bot reaches the whole install, each user with their own accounts."
}
>
<Form
@@ -80,7 +80,7 @@ export default function ConnectorConnectionModal({ connection, onSaved, onCancel
description={
connection
? "Renaming keeps its apps. A new key lists them again."
: "Each connection is one provider account with its own key, so a work account and a personal one live side by side. Once saved, every app that key holds is listed here: give one to every bot, a workspace or your own runs, and each person signs in to their own account for it."
: "Each connection is one provider account with its own key, so a work account and a personal one live side by side. Once saved, every app that key holds is listed here: give one to every bot, a workspace or your own runs, and a workspace's apps use every account connected for them, whoever connected them."
}
>
<Form className="w-full gap-4! items-stretch pt-4" onSubmit={submit}>
@@ -75,7 +75,7 @@ export default function ConnectorAppsSection() {
return (
<SettingsShell
title={connection.name}
description={`The apps ${connection.name} offers. Give one to every bot, to a workspace, or to your own runs on a bot; each person then signs in to their own account for it.`}
description={`The apps ${connection.name} offers. Give one to every bot, to a workspace, or to your own runs on a bot; a workspace uses every account connected for that app, whoever connected it.`}
>
<Row className="w-full items-center gap-2!">
<Link href="/admin/settings/connectors" className="text-sm">
@@ -46,7 +46,7 @@ export default function ConnectorsSettingsSection() {
return (
<SettingsGroup
title="Connectors"
description="Connect a paradigm once and every app it offers is listed under it. Open a connection to search its apps and give one to every bot, to a workspace, or to your own runs on a bot; each person then signs in to their own account for it."
description="Connect a paradigm once and every app it offers is listed under it. Open a connection to search its apps and give one to every bot, to a workspace, or to your own runs on a bot; a workspace uses every account connected for that app, whoever connected it."
>
<SettingsList is_empty={!connections.length} empty="No connectors yet">
{connections.map((connection) => (
@@ -0,0 +1,23 @@
import { describe, expect, test } from "bun:test";
import connectorAccountReachSql from "./connector-account-reach-sql";
describe("connectorAccountReachSql", () => {
test("a connector given to a workspace hands every connected account of it to that workspace", () => {
const { sql, values } = connectorAccountReachSql({ workspace_id: 4 });
expect(sql).toContain("SELECT 1 FROM workspace_connectors wc");
expect(sql).toContain("wc.connector_id = a.connector_id");
expect(sql).toContain("wc.workspace_id = ?");
expect(values).toEqual([4]);
});
test("the global scope brings no accounts, only the workspace grant does", () => {
expect(connectorAccountReachSql({ workspace_id: 4 }).sql).not.toContain("all_bots");
});
test("a run outside a workspace gets no clause", () => {
expect(connectorAccountReachSql({})).toEqual({ sql: "", values: [] });
expect(connectorAccountReachSql({ workspace_id: null })).toEqual({ sql: "", values: [] });
expect(connectorAccountReachSql({ workspace_id: 0 })).toEqual({ sql: "", values: [] });
});
});
+18
View File
@@ -0,0 +1,18 @@
type Params = {
workspace_id?: number | string | null;
};
/**
* The extra account clause a workspace brings: a connector given to a
* workspace reaches everyone working in it, so every connected account of
* that connector does too, whoever connected it. Empty outside a workspace,
* and the global scope brings no accounts (only the workspace grant does).
*/
export default function connectorAccountReachSql({ workspace_id }: Params): { sql: string; values: number[] } {
if (!workspace_id) return { sql: "", values: [] };
return {
sql: `OR EXISTS (SELECT 1 FROM workspace_connectors wc WHERE wc.connector_id = a.connector_id AND wc.workspace_id = ?)`,
values: [Number(workspace_id)],
};
}