mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 06:17:23 +01:00
feat(onboarding): one-command public installer for the local daemon
Closes the second half of the connect-step gap. Last week's422873amade `curl|node - init --token X` reachable for new customers (the agent CLI was served via /api/agent/install).15727a7added an honesty disclaimer that the daemon scripts still required a Cockpit repo clone. This commit removes the disclaimer by shipping the scripts the same way. • New /api/agent/daemon route spawns `tar -czf - -C scripts/ …` with the 4 daemon files (~1500 lines bash: cockpit-daemon.sh, _brand.sh, agent-hook-lib.sh, agent-hook-bridge.sh) and returns the gzipped tarball (~20 KB). • next.config.ts outputFileTracingIncludes pins those 4 source files to the route so Vercel ships them in the bundle (the route reads them via spawn at runtime — they'd otherwise be tree-shaken). • src/proxy.ts matcher exception adds api/agent/daemon so the download works pre-auth. • packages/agent/bin/cockpit-agent.js gets a new downloadDaemon() step inside `init`: after writeEnvFile, fetch the tarball, pipe into `tar -xz -C ~/.local/share/cockpit`, chmod +x the two executables. Soft-fail with a warning if it errors — the token write still lands and the user can retry by re-running init. • ConnectMachineStep step 3 drops the "requires repo clone, public installer coming soon" caveat in favor of the actual path (~/.local/share/cockpit/cockpit-daemon.sh). After this, a brand-new customer's path is: 1. Sign up + onboarding (username + project + connect) 2. Generate token → copy one curl command → paste into terminal 3. ONE command installs both the env file AND the daemon scripts 4. Run ~/.local/share/cockpit/cockpit-daemon.sh and they're live No repo clone. No npm publish dependency. Customer-#2-ready.
This commit is contained in:
5 files changed
+136
-9
No files matched your search
@@ -10,6 +10,15 @@ const nextConfig: NextConfig = {
|
||||
// isn't published to npm yet and the repo is private). Without explicit
|
||||
// tracing, Vercel would tree-shake the file out of the deployment bundle.
|
||||
"/api/agent/install": ["./packages/agent/bin/**"],
|
||||
// Serves the bash daemon bundle (4 scripts ~1500 lines) so a new
|
||||
// customer can install the local execution surface without cloning
|
||||
// the repo. Same tree-shaking concern as /install above.
|
||||
"/api/agent/daemon": [
|
||||
"./scripts/cockpit-daemon.sh",
|
||||
"./scripts/_brand.sh",
|
||||
"./scripts/agent-hook-lib.sh",
|
||||
"./scripts/agent-hook-bridge.sh",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ const readline = require("readline");
|
||||
const DEFAULT_BASE_URL = "https://cockpitapp.vercel.app";
|
||||
const CONFIG_DIR = path.join(os.homedir(), ".config", "cockpit");
|
||||
const ENV_FILE = path.join(CONFIG_DIR, "daemon.env");
|
||||
const DAEMON_DIR = path.join(os.homedir(), ".local", "share", "cockpit");
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = { command: argv[2], token: "", baseUrl: DEFAULT_BASE_URL, install: false };
|
||||
@@ -66,6 +67,40 @@ function writeEnvFile(token, baseUrl) {
|
||||
fs.writeFileSync(ENV_FILE, content, { mode: 0o600 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the daemon scripts tarball from the cloud and extract into
|
||||
* ~/.local/share/cockpit/. Uses the system `tar` binary (universal on
|
||||
* Linux/macOS; on Windows requires WSL/git-bash). Idempotent — overwrites
|
||||
* existing files on re-run. Returns the install dir on success, or null
|
||||
* on soft failure so init can still complete with just the env file.
|
||||
*/
|
||||
async function downloadDaemon(baseUrl) {
|
||||
console.log(`Downloading daemon scripts from ${baseUrl}/api/agent/daemon…`);
|
||||
const res = await fetch(`${baseUrl}/api/agent/daemon`);
|
||||
if (!res.ok) throw new Error(`Daemon download failed (HTTP ${res.status})`);
|
||||
const tarball = Buffer.from(await res.arrayBuffer());
|
||||
|
||||
fs.mkdirSync(DAEMON_DIR, { recursive: true });
|
||||
|
||||
const { spawn } = require("child_process");
|
||||
await new Promise((resolve, reject) => {
|
||||
const child = spawn("tar", ["-xz", "-C", DAEMON_DIR], {
|
||||
stdio: ["pipe", "inherit", "inherit"],
|
||||
});
|
||||
child.on("error", reject);
|
||||
child.on("close", (code) => code === 0 ? resolve() : reject(new Error(`tar exited ${code}`)));
|
||||
child.stdin.end(tarball);
|
||||
});
|
||||
|
||||
// chmod +x the executables so the user can run them directly without
|
||||
// having to remember `bash ...`.
|
||||
for (const name of ["cockpit-daemon.sh", "agent-hook-bridge.sh"]) {
|
||||
try { fs.chmodSync(path.join(DAEMON_DIR, name), 0o755); } catch {}
|
||||
}
|
||||
|
||||
return DAEMON_DIR;
|
||||
}
|
||||
|
||||
function printHelp() {
|
||||
console.log(`@cockpit/agent — connect your machine to Cockpit
|
||||
|
||||
@@ -116,15 +151,28 @@ async function main() {
|
||||
const profile = await verifyToken(args.baseUrl, token);
|
||||
writeEnvFile(token, args.baseUrl);
|
||||
|
||||
let daemonInstalledAt = null;
|
||||
try {
|
||||
daemonInstalledAt = await downloadDaemon(args.baseUrl);
|
||||
} catch (err) {
|
||||
console.warn(`\n⚠️ Daemon install failed: ${err.message}`);
|
||||
console.warn(` Token is saved (${ENV_FILE}). Re-run this command to retry the daemon download.`);
|
||||
}
|
||||
|
||||
console.log(`\n✓ Connected as ${profile.user?.name ?? profile.user?.email ?? profile.user?.id}`);
|
||||
console.log(`✓ Config saved to ${ENV_FILE}`);
|
||||
if (daemonInstalledAt) {
|
||||
console.log(`✓ Daemon scripts installed to ${daemonInstalledAt}`);
|
||||
}
|
||||
console.log("\nNext steps:");
|
||||
console.log(" 1. Install Zellij + at least one agent CLI (claude, codex, gemini, or openclaw)");
|
||||
console.log(" 2. Register projects in Cockpit with local directory paths");
|
||||
console.log(` 3. Start the daemon — currently requires a Cockpit repo clone`);
|
||||
console.log(` (one-line public installer is coming; for now, from a clone:)`);
|
||||
console.log(` set -a && source ${ENV_FILE} && ./scripts/cockpit-daemon.sh`);
|
||||
console.log(` # optional: bash scripts/install-daemon.sh (systemd user service)`);
|
||||
if (daemonInstalledAt) {
|
||||
console.log(` 3. Start the daemon:`);
|
||||
console.log(` set -a && source ${ENV_FILE} && ${daemonInstalledAt}/cockpit-daemon.sh`);
|
||||
} else {
|
||||
console.log(` 3. Re-run \`npx @cockpit/agent init\` once you're online to install the daemon scripts.`);
|
||||
}
|
||||
|
||||
if (args.install) {
|
||||
const { spawnSync } = require("child_process");
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { spawn } from "node:child_process";
|
||||
import path from "node:path";
|
||||
|
||||
/**
|
||||
* Serves a gzipped tarball of the 4 daemon scripts so a new customer can
|
||||
* install the agent fleet without cloning the cockpit repo:
|
||||
*
|
||||
* scripts/cockpit-daemon.sh — main polling loop (~780 lines)
|
||||
* scripts/_brand.sh — brand SSOT (APP_NAME / APP_SLUG / APP_DOMAIN)
|
||||
* scripts/agent-hook-lib.sh — zellij inject_prompt + shared helpers
|
||||
* scripts/agent-hook-bridge.sh — agent CLI bridge (~660 lines)
|
||||
*
|
||||
* Together: ~1500 lines of bash. Together they are the local execution surface.
|
||||
*
|
||||
* Tarred with `-C scripts/` so the files extract at the destination root with
|
||||
* no `scripts/` prefix — the agent CLI then writes them straight into
|
||||
* ~/.local/share/cockpit/ and references them by basename.
|
||||
*
|
||||
* Public (no auth) — matches the matcher exception in src/proxy.ts.
|
||||
* Designed to be piped: curl -fsSL ${APP_URL}/api/agent/daemon | tar -xzC ~/.local/share/cockpit
|
||||
*
|
||||
* next.config.ts includes the 4 source files in this route's
|
||||
* outputFileTracingIncludes so they land in the Vercel deployment bundle.
|
||||
*/
|
||||
export async function GET() {
|
||||
const scriptsDir = path.join(process.cwd(), "scripts");
|
||||
const files = ["cockpit-daemon.sh", "_brand.sh", "agent-hook-lib.sh", "agent-hook-bridge.sh"];
|
||||
|
||||
try {
|
||||
const tarball = await tarGzip(scriptsDir, files);
|
||||
return new NextResponse(new Uint8Array(tarball), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "application/gzip",
|
||||
"Cache-Control": "public, max-age=300, s-maxage=300",
|
||||
"Content-Disposition": 'attachment; filename="cockpit-daemon.tar.gz"',
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("[agent/daemon] tar failed:", (e as Error)?.message);
|
||||
return NextResponse.json(
|
||||
{ error: "Daemon bundle unavailable" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn `tar -czf - -C <cwd> <file...>` and collect stdout into a buffer.
|
||||
* Rejects on non-zero exit or stderr. The tarball is small (~60KB raw,
|
||||
* smaller compressed) so collecting in memory is fine — no need to stream.
|
||||
*/
|
||||
function tarGzip(cwd: string, files: string[]): Promise<Buffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn("tar", ["-czf", "-", "-C", cwd, ...files], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
const chunks: Buffer[] = [];
|
||||
let stderr = "";
|
||||
child.stdout.on("data", (c: Buffer) => chunks.push(c));
|
||||
child.stderr.on("data", (c: Buffer) => { stderr += c.toString(); });
|
||||
child.on("error", reject);
|
||||
child.on("close", (code) => {
|
||||
if (code === 0) resolve(Buffer.concat(chunks));
|
||||
else reject(new Error(`tar exited ${code}: ${stderr.trim()}`));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -85,11 +85,10 @@ export function ConnectMachineStep({ saving, onComplete, onSkip }: Props) {
|
||||
</a>{" "}
|
||||
and at least one agent CLI (Claude, Cursor, Codex, …).
|
||||
</li>
|
||||
<li>Generate a token and run the init command below.</li>
|
||||
<li>Generate a token and run the init command below. It saves the token and installs the daemon scripts to <code className="ui-auth-inline-code">~/.local/share/cockpit/</code>.</li>
|
||||
<li>
|
||||
Start the daemon — currently requires a {APP_NAME} repo clone
|
||||
(one-line public installer coming soon). Skip below to explore
|
||||
the cloud surface without it.
|
||||
Start the daemon:{" "}
|
||||
<code className="ui-auth-inline-code">~/.local/share/cockpit/cockpit-daemon.sh</code>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
|
||||
+3
-1
@@ -32,12 +32,14 @@ export const config = {
|
||||
* api/auth – NextAuth internal endpoints
|
||||
* api/agent/install – serves the @cockpit/agent CLI for curl|node install
|
||||
* (public so new customers can run it before they sign in)
|
||||
* api/agent/daemon – serves the gzipped daemon-scripts tarball for the
|
||||
* CLI's install step (same pre-auth rationale as /install)
|
||||
* api/health, api/setup – infrastructure endpoints (pre-auth)
|
||||
* api/crons, api/system – GET excluded for daemon/monitoring; write methods enforce auth in-handler
|
||||
* api/invitations/ – token-scoped invitation routes (GET validate, POST accept);
|
||||
* trailing slash keeps GET /api/invitations (list) protected
|
||||
* api/stripe/webhook – Stripe webhook; verifies its own Stripe-Signature header
|
||||
*/
|
||||
"/((?!_next/static|_next/image|favicon\\.ico|icon\\.svg|manifest\\.json|opengraph-image|twitter-image|robots\\.txt|sitemap\\.xml|sign-in|sign-up|forgot-password|reset-password|verify-email|setup|invite|whitepaper|thoughts|u/|beacon|api/auth|api/agent/install|api/health|api/setup|api/crons|api/system|api/beacon|api/invitations/|api/stripe/webhook).+)",
|
||||
"/((?!_next/static|_next/image|favicon\\.ico|icon\\.svg|manifest\\.json|opengraph-image|twitter-image|robots\\.txt|sitemap\\.xml|sign-in|sign-up|forgot-password|reset-password|verify-email|setup|invite|whitepaper|thoughts|u/|beacon|api/auth|api/agent/install|api/agent/daemon|api/health|api/setup|api/crons|api/system|api/beacon|api/invitations/|api/stripe/webhook).+)",
|
||||
],
|
||||
};
|
||||
Reference in new issue
Block a user