Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# EditorConfig (https://editorconfig.org)
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space

[*.ps1]
indent_size = 4

[*.{toml,sh}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
29 changes: 29 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The full check on all three systems runcoder supports. GitHub-hosted runners: this repository
# is public, and the Mac and Windows runs are the point. No secrets, no deploy, no publish.
name: check
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
check:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# no cache, so nothing a PR names is restored or saved
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 22
package-manager-cache: false
- run: npm install --global pnpm@12.25.1
- run: pnpm install --frozen-lockfile
- run: pnpm check
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
*.log
node_modules/
tests/tmp/
48 changes: 48 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# AGENTS.md

Operating contract for anyone (human or coding agent) working in this repository.
`runcoder` is a Node.js command-line tool, published to npm as `@setkernel/runcoder`, that runs a
coding model on a Cloud Run GPU in the user's own Google Cloud project and deletes it afterwards.
It runs on other people's machines (macOS, Linux, Windows) against their billing accounts.
Licence: PolyForm Shield 1.0.0 (source-available, `LICENSE.md`).

## Working agreement

- Keep going on steps that don't need the owner; put status notes alongside the next action.
- Stop and ask before publishing to npm, pushing to `main`, or running runcoder against a real
Google Cloud project (that deploys a GPU and bills).
- Done means `pnpm check` passes; CI runs it on all three systems. A behaviour change that the
fakes cannot show (a real deploy, a real terminal window on Linux or Windows) also needs a run
on that system; say so when it has not happened.
- End a run with three headings: **Blocked on owner**, **Changed**, **Found**.

## Commands

```sh
pnpm install
pnpm check # node --check on every module, then the tests (about 5 minutes, one at a time)
pnpm test # the tests only
```

## Layout

- `bin/runcoder.mjs`: commands and signal handling; every exit path ends in `cleanup()`.
- `src/session.mjs`: the session (lock, deploy, keep-alive loop, cleanup that deletes the service).
- `src/cloud.mjs`: every gcloud call. `src/tunnel.mjs`: the proxy, model download and warm-up.
- `src/cost.mjs`: billed time from Cloud Monitoring and prices from the Cloud Billing catalog.
- `src/qwen.mjs`, `src/qwen-window.mjs`: Qwen Code's settings and its terminal window.
- `src/setup.mjs`, `src/config.mjs`, `src/ui.mjs`, `src/proc.mjs`.
- `tests/`: runcoder run as a child process against `tests/fake/` (a Node gcloud with sh and
`.cmd` shims, fake Google APIs, a fake Ollama).

## Rules

- Nothing that bills may outlive the session: every new exit path must reach `cleanup()`, and a
change to start-up or shutdown needs a test that shows the fake service deleted (`noService`).
- Sign-in stays gcloud's own. No keys, tokens or account names in the repository, the config
file or the logs.
- The config file is data: never `eval`, `source` or `import` it.
- Run external programs through `src/proc.mjs` (cross-spawn), never a shell string, so Windows
`.cmd` files and paths with spaces work. Any call only one system has needs the others' branch.
- Costs come from Google's billed time and price list, never from a local estimate.
- Tests never reach Google and never notify the desktop: keep them on the fakes.
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CLAUDE.md

Agent instructions for this repository live in [AGENTS.md](AGENTS.md), the
tool-neutral standard. Edit that file, not this one.

@AGENTS.md
91 changes: 91 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Required Notice: Copyright 2026 SetKernel Digital Inc.

# PolyForm Shield License 1.0.0

<https://polyformproject.org/licenses/shield/1.0.0>

## Acceptance

In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.

## Copyright License

The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).

## Distribution License

The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).

## Notices

You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:

> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)

## Changes and New Works License

The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.

## Patent License

The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.

## Noncompete

Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.

## Competition

Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.

## New Products

If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.

## Discontinued Products

You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:

> Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)

## Sales of Business

If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.

## Fair Use

You may have "fair use" rights for the software under the law. These terms do not limit them.

## No Other Rights

These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.

## Patent Defense

If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.

## Violations

The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.

## No Liability

***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***

## Definitions

The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.

A **product** can be a good or service, or a combination of them.

**You** refers to the individual or entity agreeing to these terms.

**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.

**Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.

**Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.

**Your licenses** are all the licenses granted to you for the software under these terms.

**Use** means anything you do with the software requiring one of your licenses.
172 changes: 172 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# runcoder

A private open coding model on a Google Cloud Run GPU, from start to delete in one command.

`runcoder` starts a GPU server in your own Google Cloud project, downloads an open model
([Qwen 3.8 27B](https://ollama.com/library/qwen3.8) by default) onto it, opens
[Qwen Code](https://github.com/QwenLM/qwen-code) in your project folder, and deletes the server
when you are done. You pay Google only for the minutes the server exists, and runcoder shows what
each session cost from Google's own billing data.

It works on macOS, Linux and Windows. Sign-in is gcloud's own: runcoder has no account, no key
and no server of its own.

## What you need

- [Node.js](https://nodejs.org) 22 or later.
- The [Google Cloud CLI](https://cloud.google.com/sdk/docs/install) (`gcloud`), logged in with
`gcloud auth login`.
- A Google Cloud project with billing turned on. Google AI Pro and Ultra plans include a monthly
Google Cloud credit that covers a few hours a month (see [Cost](#cost)).

## Install and set up

```sh
npm install --global @setkernel/runcoder
runcoder setup
```

(`pnpm add --global @setkernel/runcoder` works the same.) npm and pnpm may say they skipped an
install script for `@qwen-code/audio-capture`, Qwen Code's voice input; runcoder does not use it.

`runcoder setup` checks Node.js and gcloud, offers `gcloud auth login` if you are not logged in,
lists your projects to pick one, checks that billing is on and reads its currency, and asks
before turning on the two APIs it uses (Cloud Run and Cloud Monitoring; turning them on costs
nothing). It then asks for your monthly credit, if you have one, and prints the hourly rate.
Without a keyboard: `runcoder setup --project my-project --credit 14.25 --yes`.

## Use

```sh
runcoder ~/code/my-project
```

1. It deploys the server (Cloud Run, one GPU, `us-central1`, then `europe-west4` if that region
has no GPU free) and opens a private tunnel to it on `localhost:11435`.
2. It downloads the model to the server (about 10 minutes for 30 GB), loads it onto the GPU and
times a test answer.
3. It opens Qwen Code in a new terminal window, in your folder, pointed at the server.
4. The first window stays as the control panel: every 10 minutes it prints the time and cost so
far. **Press q there (or Ctrl+C, or close the window) and it deletes the server**, then prints
what the session cost.

If the folder has earlier Qwen Code sessions, runcoder asks whether to continue the latest
(c), pick one (r), or start fresh. `-c`, `-p` and `-n` answer that in advance.

Other commands:

| Command | What it does |
| --- | --- |
| `runcoder status` | Whether a runcoder server exists (so whether anything can bill), and the credit left. |
| `runcoder credit` | This billing month's sessions with Google's billed minutes and cost. |
| `runcoder down` | Delete the server without starting anything. Use it if a run was killed. |
| `runcoder help` | All commands and options. |

## Safety

Something that bills by the second must never be left running. runcoder deletes the server when:

- you press q, press Ctrl+C, or close its window;
- Qwen Code has been closed for 15 minutes (`RUNCODER_QWEN_IDLE_MINUTES`);
- the session reaches 150 minutes (`RUNCODER_MAX_MINUTES`);
- the model is lost and does not come back after three tries;
- anything goes wrong during start-up.

The delete is retried five times. If it still cannot confirm the server is gone, it says so in
capitals and tells you to run `runcoder down`. The server has `--max-instances=1` and
`--min-instances=0`, so even a server that was somehow left behind scales to zero (and stops
billing) once nothing has used it for about 15 minutes. Only one runcoder session runs at a time
per computer, and your computer is kept awake while it runs.

## Cost

runcoder reads two things from Google, so its numbers match your bill rather than a guess:

- **billed time**: Cloud Monitoring's `billable_instance_time` for the service, per session;
- **prices**: the Cloud Billing price list, in your billing account's currency.

The default server (an NVIDIA RTX PRO 6000 GPU with 20 vCPU and 80 GiB) is billed for the GPU,
the CPU and the memory. Cloud Run's free tier (240,000 vCPU-seconds and 450,000 GiB-seconds a
month, per billing account) pays for the CPU and memory of roughly the first 2.8 hours each
month, so the rate goes up once it is used. In December 2026 in Canadian dollars that was
**CA$1.87 an hour, then CA$4.54**; `runcoder setup` prints yours.

A monthly credit of CA$14.25 (Google AI Pro, in Canada) therefore buys about 4¾ billed hours a
month, about 4 hours of coding once the download is counted. Google publishes no API for credit
balances, so runcoder tracks the credit from the amount you give it and its own billed sessions;
other spending on the same billing account uses the credit too. When the credit looks used up,
runcoder asks before starting (and refuses without a keyboard unless `RUNCODER_ALLOW_PAID=1`).
Set `RUNCODER_FREE_TIER=0` if other Cloud Run services on the billing account use the free tier.

For a smaller, slower and cheaper server: `RUNCODER_GPU=nvidia-l4 RUNCODER_CPU=8
RUNCODER_MEMORY=32Gi RUNCODER_MODEL=<a model that fits 24 GB>`.

## Privacy

Your code and prompts go from Qwen Code through the tunnel (`gcloud run services proxy`, which
signs each request with your gcloud login) to the model on your own Cloud Run service. The
service refuses requests without your login (`--no-allow-unauthenticated`). Cloud Run's request
log records each request's time, path and size, not its contents. Nothing goes to setkernel or
any other third party, and the server, the downloaded model and its memory are deleted at the end
of each session. Qwen Code's own usage statistics are off.

## Settings

`runcoder setup` writes the config file. Any of these can go there as `KEY=value`, or be set in
the environment for one run (`RUNCODER_MAX_MINUTES=60 runcoder .`).

| Setting | Default | |
| --- | --- | --- |
| `RUNCODER_PROJECT` | (setup asks) | Google Cloud project |
| `RUNCODER_MONTHLY_CREDIT` | `0` | Monthly credit to track; 0 turns tracking off |
| `RUNCODER_CURRENCY` | (setup reads it) | The billing account's currency |
| `RUNCODER_REGIONS` | `us-central1 europe-west4` | Regions to try, in order |
| `RUNCODER_MODEL` | `qwen3.8:27b-q8_0` | Any [Ollama](https://ollama.com/library) model that fits the GPU |
| `RUNCODER_CONTEXT` | `131072` | Context window, in tokens |
| `RUNCODER_GPU` | `nvidia-rtx-pro-6000` | Cloud Run GPU type (`nvidia-l4` is the other) |
| `RUNCODER_CPU`, `RUNCODER_MEMORY` | `20`, `80Gi` | Must suit the GPU (Cloud Run's rules) |
| `RUNCODER_MAX_MINUTES` | `150` | Hard limit for one session |
| `RUNCODER_QWEN_IDLE_MINUTES` | `15` | Shut down this long after Qwen Code closes |
| `RUNCODER_PORT` | `11435` | Local end of the tunnel |
| `RUNCODER_OPEN` | `auto` | `none` prints the Qwen Code command instead of opening a window |
| `RUNCODER_FREE_TIER` | `1` | `0` if the Cloud Run free tier is used elsewhere |
| `RUNCODER_ALLOW_PAID` | `0` | `1` lets a run without a keyboard go past the credit |
| `RUNCODER_SERVICE` | `runcoder` | Cloud Run service name |
| `RUNCODER_IMAGE` | `ollama/ollama:0.40.19` | Server image |

Where things are:

| | macOS and Linux | Windows |
| --- | --- | --- |
| Config | `~/.config/runcoder/config` | `%APPDATA%\runcoder\config` |
| Logs, lock, price cache | `~/.local/state/runcoder` | `%LOCALAPPDATA%\runcoder\state` |
| Qwen Code settings and sessions | `~/.local/share/runcoder/qwen-home` | `%LOCALAPPDATA%\runcoder\data\qwen-home` |

The `XDG_*` variables move them on any system. Each run writes a full log, kept 60 days; the
path is printed on any error.

## Uninstall

```sh
runcoder down
npm uninstall --global @setkernel/runcoder
```

Then delete the three folders above, and turn off the Cloud Run and Cloud Monitoring APIs in your
project if nothing else uses them.

## Development

```sh
pnpm install
pnpm check # syntax pass, then the tests
```

The tests run runcoder for real against a fake `gcloud`, fake Google APIs and a fake model server,
so nothing reaches Google and nothing bills; one test starts the installed Qwen Code. CI runs them
on Linux, macOS and Windows.

## Licence

[PolyForm Shield 1.0.0](LICENSE.md): free to use, change and share, except to build a product
that competes with it.
Loading
Loading