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
2 changes: 1 addition & 1 deletion .ci/release-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mkdir -p "$output"
rm -rf "$output/Tokamak.app"
ditto target/release/bundle/macos/Tokamak.app "$output/Tokamak.app"
ditto -c -k --sequesterRsrc --keepParent "$output/Tokamak.app" "$output/Tokamak-macos-arm64.zip"
tar -czf "$output/server-macos-arm64.tar.gz" -C target/release tokamak
tar -czf "$output/server-macos-arm64.tar.gz" -C target/release tokamak-server
(
cd "$output"
shasum -a 256 Tokamak-macos-arm64.zip server-macos-arm64.tar.gz > SHA256SUMS.txt
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- name: Smoke check server build identity
shell: bash
run: |
id=$(./target/release/tokamak --build-id)
id=$(./target/release/tokamak-server --build-id)
if [[ ! "$id" =~ ^[0-9a-f]{64}$ ]]; then
printf '%s\n' 'Server did not print a 64-character build identity' >&2
exit 1
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
- name: Smoke check server build identity
shell: pwsh
run: |
$id = & ./target/release/tokamak.exe --build-id
$id = & ./target/release/tokamak-server.exe --build-id
if ($LASTEXITCODE -ne 0 -or $id -cnotmatch '^[0-9a-f]{64}$') {
throw 'Server did not print a 64-character build identity'
}
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
- run: |
moon run workspace:build-release
mkdir -p .ci-results
tar -czf .ci-results/server-linux-${{ matrix.arch }}.tar.gz -C target/release tokamak
tar -czf .ci-results/server-linux-${{ matrix.arch }}.tar.gz -C target/release tokamak-server
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: server-linux-${{ matrix.arch }}
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ COPY . .
RUN proto run bun -- install --frozen-lockfile --network-concurrency=16 --verbose
RUN proto run bun -- run --cwd app build \
&& proto run bun -- packages/build/src/build.ts plugins/chat
RUN proto run rust -- build --locked --release -p server --bin tokamak
RUN proto run rust -- build --locked --release -p server --bin tokamak-server

FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --uid 10001 --create-home tokamak \
&& mkdir /data && chown tokamak:tokamak /data
COPY --from=build /src/target/release/tokamak /usr/local/bin/tokamak
COPY --from=build /src/target/release/tokamak-server /usr/local/bin/tokamak-server
COPY --from=build /src/app/dist /opt/tokamak/web
COPY --from=build /src/plugins/chat/dist /opt/tokamak/plugins/chat
ENV PORT=3000 TOKAMAK_WEB_DIR=/opt/tokamak/web
USER tokamak
EXPOSE ${PORT}
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD curl --fail --silent "http://127.0.0.1:${PORT}/health" || exit 1
ENTRYPOINT ["tokamak", "--plugins", "/opt/tokamak/plugins", "--data", "/data/store"]
ENTRYPOINT ["tokamak-server", "--plugins", "/opt/tokamak/plugins", "--data", "/data/store"]
2 changes: 1 addition & 1 deletion app/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tasks:
server-build:
script: >-
proto run bun -- ../packages/build/src/build.ts ../plugins/chat &&
cargo build --locked -p server --bin tokamak
cargo build --locked -p server --bin tokamak-server
options:
cache: false
mutex: "cargo"
Expand Down
10 changes: 7 additions & 3 deletions app/scripts/integration-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ for (const plugin of [
await cp(resolve(root, plugin, "dist"), `${directory}/${id}/dist`, { recursive: true });
}
if (process.argv.includes("--reload")) {
const result = spawnSync(`${root}/target/debug/tokamak`, ["plugin", "reload", "integration-fixture"], {
stdio: "inherit",
});
const result = spawnSync(
`${root}/target/debug/tokamak-server`,
["plugin", "reload", "integration-fixture"],
{
stdio: "inherit",
},
);
if (result.error) throw result.error;
process.exitCode = result.status ?? 1;
}
Expand Down
14 changes: 11 additions & 3 deletions app/scripts/prepare-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ function run(command: string, args: string[]) {
// The dev server loads the whole plugins folder, so every plugin in it must be built.
for (const plugin of ["chat", "acp"])
run("proto", ["run", "bun", "--", "packages/build/src/build.ts", `plugins/${plugin}`]);
run("cargo", ["build", "--locked", "-p", "server", "--bin", "tokamak", ...(release ? ["--release"] : [])]);
run("cargo", [
"build",
"--locked",
"-p",
"server",
"--bin",
"tokamak-server",
...(release ? ["--release"] : []),
]);
{
const info = spawnSync("rustc", ["-vV"], { encoding: "utf8" });
if (info.status !== 0) throw new Error("Cannot determine Rust target");
Expand All @@ -22,8 +30,8 @@ run("cargo", ["build", "--locked", "-p", "server", "--bin", "tokamak", ...(relea
await mkdir(directory, { recursive: true });
const suffix = process.platform === "win32" ? ".exe" : "";
await cp(
`${root}target/${release ? "release" : "debug"}/tokamak${suffix}`,
`${directory}/tokamak-${target}${suffix}`,
`${root}target/${release ? "release" : "debug"}/tokamak-server${suffix}`,
`${directory}/tokamak-server-${target}${suffix}`,
);
await rm(`${directory}/plugins`, { recursive: true, force: true });
for (const plugin of await readdir(`${root}plugins`, { withFileTypes: true })) {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ try {
await mkdir(`${directory}/plugins/chat`, { recursive: true });
await cp(`${root}plugins/chat/dist`, `${directory}/plugins/chat/dist`, { recursive: true });
const child = spawn(
`${root}target/debug/tokamak`,
`${root}target/debug/tokamak-server`,
[
// --local-dir resets the listener, so the explicit port must follow it.
...(process.env.TOKAMAK_SERVER_DIR ? ["--local-dir", process.env.TOKAMAK_SERVER_DIR] : []),
Expand Down
5 changes: 4 additions & 1 deletion app/src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
fn main() {
println!("cargo:rerun-if-changed=dist");
let target = std::env::var("TARGET").expect("Cargo target");
let sidecar = format!("dist/tokamak-{target}{}", std::env::consts::EXE_SUFFIX);
let sidecar = format!(
"dist/tokamak-server-{target}{}",
std::env::consts::EXE_SUFFIX
);
if !std::path::Path::new(&sidecar).is_file() {
// Cargo checks need no packaged artifacts; the Tauri hooks prepare them before bundling.
let mut config: serde_json::Value =
Expand Down
6 changes: 3 additions & 3 deletions app/src-tauri/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ fn binary() -> Result<PathBuf> {
for profile in ["debug", "release"] {
let path = root
.join(profile)
.join(format!("tokamak{}", std::env::consts::EXE_SUFFIX));
.join(format!("tokamak-server{}", std::env::consts::EXE_SUFFIX));
if path.is_file() {
return Ok(path);
}
}
}
let path =
std::env::current_exe()?.with_file_name(format!("tokamak{}", std::env::consts::EXE_SUFFIX));
let path = std::env::current_exe()?
.with_file_name(format!("tokamak-server{}", std::env::consts::EXE_SUFFIX));
if !path.is_file() {
return Err("Tokamak server binary is missing; run the app preparation script".into());
}
Expand Down
2 changes: 1 addition & 1 deletion app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"active": true,
"targets": ["app"],
"icon": [],
"externalBin": ["dist/tokamak"],
"externalBin": ["dist/tokamak-server"],
"resources": {
"dist/plugins/": "plugins/"
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ try {
recursive: true,
filter: (source) => !source.split("/").includes("dist"),
});
run("cargo", ["build", "--locked", "-p", "server", "--bin", "tokamak", "--jobs", "2"]);
run("cargo", ["build", "--locked", "-p", "server", "--bin", "tokamak-server", "--jobs", "2"]);
run("proto", ["run", "bun", "--", "app/scripts/integration-fixture.ts"]);
// Adds ACP and a scripted agent; the server then never sees this machine's real agent CLIs.
const sandbox = await prepareChatSandbox(directory);
Expand Down
2 changes: 1 addition & 1 deletion e2e/chat-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if (import.meta.main) {
await writeFile(`${directory}/local/server.token`, token, { mode: 0o600 });
await writeFile(`${root}/app/.dev/chat-sandbox.env`, `VITE_TOKAMAK_TOKEN=${token}\n`, { mode: 0o600 });
const child = spawn(
`${root}/target/debug/tokamak`,
`${root}/target/debug/tokamak-server`,
[
"--local-dir",
`${directory}/local`,
Expand Down
4 changes: 2 additions & 2 deletions e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function headless(
options: { args?: string[]; env?: NodeJS.ProcessEnv; timeout?: number; killed?: boolean } = {},
) {
const child = spawn(
resolve("target/debug/tokamak"),
resolve("target/debug/tokamak-server"),
[...(options.args ?? ["--bundle", bundle]), "--data", data, "--listen", "127.0.0.1:0", "--workers", "1"],
{ cwd: repository, env: { ...env, ...sandbox.env, ...options.env }, stdio: ["pipe", "pipe", "pipe"] },
);
Expand Down Expand Up @@ -174,7 +174,7 @@ const sandbox = await prepareAgentEnvironment(root);
let feature: string | undefined;
try {
command([process.execPath, "check", "--no-script", "--project", "e2e/tsconfig.json"]);
command(["cargo", "build", "--locked", "--package", "server", "--bin", "tokamak", "--jobs", "2"]);
command(["cargo", "build", "--locked", "--package", "server", "--bin", "tokamak-server", "--jobs", "2"]);
feature = await buildFeature({
source: resolve("packages/server/tests/fixtures/record/src/server"),
parent: root,
Expand Down
2 changes: 1 addition & 1 deletion e2e/serve-hosted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
await mkdir(`${directory}/plugins`);
await cp(`${process.env.TOKAMAK_PLUGIN_DIR}/chat`, `${directory}/plugins/chat`, { recursive: true });
const child = spawn(
`${root}/target/debug/tokamak`,
`${root}/target/debug/tokamak-server`,
[
"--web",
process.env.TOKAMAK_E2E_WEB_ROOT!,
Expand Down
2 changes: 1 addition & 1 deletion e2e/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const root = resolve(import.meta.dirname, "..");
const directory = await mkdtemp(`${root}/app/.dev/serve-`);
try {
const child = spawn(
`${root}/target/debug/tokamak`,
`${root}/target/debug/tokamak-server`,
[
"--local-dir",
process.env.TOKAMAK_SERVER_DIR!,
Expand Down
6 changes: 3 additions & 3 deletions moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tasks:
cache: false
mutex: "cargo"
build-release:
command: "cargo build --locked --release --package server --bin tokamak --target-dir target"
command: "cargo build --locked --release --package server --bin tokamak-server --target-dir target"
# The server depends on engine, not the UI/app/plugin bundles. Keep an
# unrelated frontend change from forcing another release link.
inputs:
Expand All @@ -91,7 +91,7 @@ tasks:
- "!/.moon/cache/**"
- "$RUSTFLAGS"
- "$CARGO_ENCODED_RUSTFLAGS"
outputs: ["target/release/tokamak"]
outputs: ["target/release/tokamak-server"]
options:
cache: true
mutex: "cargo"
Expand All @@ -106,7 +106,7 @@ tasks:
- "-e"
- >-
import { stat } from "node:fs/promises";
for (const binary of ["tokamak"]) {
for (const binary of ["tokamak-server"]) {
const path = "target/release/" + binary + (process.platform === "win32" ? ".exe" : "");
const { size } = await stat(path);
console.log(path + ": " + size + " bytes");
Expand Down
2 changes: 1 addition & 1 deletion packages/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ header authorization in desktop mode.
Run the focused build tests from this directory with `sh tests/run.sh`.
The browser fixture lives in `tests/fixtures/browser`; its optional cross-plugin
module need not be installed to build or serve it.
After building `target/debug/tokamak`, run the real curl/WebSocket checks from the
After building `target/debug/tokamak-server`, run the real curl/WebSocket checks from the
repository root with `proto run bun -- packages/build/tests/browser-assets.mjs`.
They cover loopback, desktop token authentication and a configured origin list.

Expand Down
2 changes: 1 addition & 1 deletion packages/build/tests/browser-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const workspace = resolve(import.meta.dir, "../../..");
const directory = await mkdtemp(resolve(tmpdir(), "tokamak-browser-assets-"));
const sandbox = await prepareAgentEnvironment(directory);
const fixture = resolve(workspace, "packages/build/tests/fixtures/browser");
const binary = resolve(workspace, "target/debug/tokamak");
const binary = resolve(workspace, "target/debug/tokamak-server");
const built = spawnSync("proto", ["run", "bun", "--", "packages/build/src/build.ts", fixture], {
cwd: workspace,
stdio: "inherit",
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ and reload/invalidation. The app's `WebPluginHost` fetches modules and rewrites
cross-plugin and relative imports to revision-owned blobs. Host SDK/Solid
contexts are shared through one import map; no eval is needed. Reload revokes
blobs, removes stylesheets and disposes view/query owners, including affected
importers. Publish complete builds before requesting `tokamak plugin reload <id>`;
importers. Publish complete builds before requesting `tokamak-server plugin reload <id>`;
there is no automatic file watcher. Retired revisions reject stale assets.

`createPluginShell` and `PluginViews` in `app/src/plugins/views.tsx` expose a
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks:
options:
mergeArgs: "replace"
test:
command: "proto run bun -- --conditions=browser test tests/plugins.test.mjs"
command: "proto run bun -- --conditions=browser test tests/plugins.test.mjs tests/server-binary.test.ts"
options:
cache: false
mergeArgs: "replace"
19 changes: 19 additions & 0 deletions packages/runtime/tests/server-binary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect, test } from "bun:test";
import { serverBinaryCandidates } from "../tools/server-binary";

test("start only accepts the renamed build of the requested profile", () => {
expect(serverBinaryCandidates("start", "debug", "")).toEqual(["target/debug/tokamak-server"]);
});

test("stop and status still find a build made before the rename", () => {
for (const command of ["stop", "status"]) {
const candidates = serverBinaryCandidates(command, "debug", ".exe");
expect(candidates[0]).toBe("target/debug/tokamak-server.exe");
expect(candidates).toContain("target/debug/tokamak.exe");
expect(candidates).toContain("target/release/tokamak.exe");
// The renamed builds are preferred over the old name in either profile.
expect(candidates.indexOf("target/release/tokamak-server.exe")).toBeLessThan(
candidates.indexOf("target/debug/tokamak.exe"),
);
}
});
7 changes: 3 additions & 4 deletions packages/runtime/tools/run-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { fileURLToPath } from "node:url";
import { resolve } from "node:path";
import { existsSync } from "node:fs";
import { ensure, localDirectory, status, stop } from "./local-server";
import { serverBinaryCandidates } from "./server-binary";

const [command = "status", profile = "debug"] = process.argv.slice(2);
if (!["start", "stop", "status"].includes(command) || !["debug", "release"].includes(profile)) {
throw new Error("Expected start, stop or status, optionally followed by debug or release");
}
const root = fileURLToPath(new URL("../../../", import.meta.url));
const suffix = process.platform === "win32" ? ".exe" : "";
let binary = resolve(root, `target/${profile}/tokamak${suffix}`);
if (!existsSync(binary) && ["stop", "status"].includes(command)) {
binary = resolve(root, `target/${profile === "debug" ? "release" : "debug"}/tokamak${suffix}`);
}
const candidates = serverBinaryCandidates(command, profile, suffix).map((path) => resolve(root, path));
const binary = candidates.find((path) => existsSync(path)) ?? candidates[0]!;
const directory = localDirectory(binary, root);
if (command === "stop") {
await stop(directory);
Expand Down
25 changes: 25 additions & 0 deletions packages/runtime/tools/server-binary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Where `server:start`, `server:stop` and `server:status` look for the server
* executable, in order of preference.
*
* `start` only accepts the build of the requested profile. `stop` and `status`
* need the executable just to locate a running local server, so they also
* accept the other profile's build.
*
* The executable was named `tokamak` before it was renamed `tokamak-server`.
* A checkout that pulled the rename but has not rebuilt yet still has only the
* old file on disk, and may have an old server running. `stop` and `status`
* fall back to the old name so that server can still be found and stopped.
* Remove the old name once nobody can have a pre-rename build left.
*/
export function serverBinaryCandidates(command: string, profile: string, suffix: string): string[] {
const other = profile === "debug" ? "release" : "debug";
const current = `target/${profile}/tokamak-server${suffix}`;
if (command === "start") return [current];
return [
current,
`target/${other}/tokamak-server${suffix}`,
`target/${profile}/tokamak${suffix}`,
`target/${other}/tokamak${suffix}`,
];
}
2 changes: 1 addition & 1 deletion packages/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
publish.workspace = true

[[bin]]
name = "tokamak"
name = "tokamak-server"
path = "src/main.rs"

[[bin]]
Expand Down
2 changes: 1 addition & 1 deletion packages/server/HOW_IT_WORKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ It's the same idea as Convex: Convex is "their database + a V8 runtime + live sy
└───────────────────────────────┬───────────────────────────────────────┘
│ WebSocket (local, token-protected)
┌───────────────────────────────▼───────────────────────────────────────┐
│ server (tokamak, ~40 MB) ← the owner of everything below │
│ server (tokamak-server, ~40 MB) ← the owner of everything below │
│ │
│ websocket.rs receives requests, sends responses + live updates │
│ service.rs the Coordinator: runs queries/mutations ONE AT A │
Expand Down
8 changes: 4 additions & 4 deletions packages/server/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ and typed API references. Do not author the artifact manifest by hand.

```sh
proto run bun -- packages/build/src/build.ts path/to/plugins/notes
cargo build --locked -p server --bin tokamak --jobs 2
target/debug/tokamak --plugins path/to/plugins --local-dir path/to/private-server
cargo build --locked -p server --bin tokamak-server --jobs 2
target/debug/tokamak-server --plugins path/to/plugins --local-dir path/to/private-server
```

The local directory requires the same private `server.token` as the desktop
launcher. Never pass the token in arguments. The launcher now uses the workspace `plugins/` installation, including Chat.
`--plugins` and legacy `--bundle` are mutually exclusive.

```sh
TOKAMAK_SERVER_DIR=path/to/private-server target/debug/tokamak plugin list
TOKAMAK_SERVER_DIR=path/to/private-server target/debug/tokamak plugin reload acme.notes
TOKAMAK_SERVER_DIR=path/to/private-server target/debug/tokamak-server plugin list
TOKAMAK_SERVER_DIR=path/to/private-server target/debug/tokamak-server plugin reload acme.notes
```

The control CLI validates loopback discovery, uses bearer authentication, disables
Expand Down
Loading
Loading