Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(computers): setup prompt for a coding agent and a paste box that reads anything

rubenluetke10-beepfcd0fd91d4b5
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/computers/de.json b/jarvis/ui/web/frontend/src/i18n/locales/computers/de.json
index a3fefab0f5..7d0721dbe4 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/computers/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/computers/de.json
@@ -298,7 +298,7 @@
"cx_key_too_big": "Diese Datei ist zu groß für einen SSH-Schlüssel.",
"cx_own_key_hint": "Öffentlicher Schlüssel von {name} – er muss schon in authorized_keys auf dem Server stehen",
"cx_key_already_there": "Der Schlüssel von {name} ist schon auf dem Server",
- "cx_use_password": "Stattdessen mit Passwort oder Schlüssel anmelden",
+ "cx_use_password": "Stattdessen Passwort verwenden",
"cx_more": "Weitere Optionen",
"cx_keep_password": "Weiter mit Passwort statt Schlüssel anmelden",
"cx_connect": "Verbinden",
@@ -312,6 +312,15 @@
"cx_fail_timeout": "Der Server hat nicht rechtzeitig geantwortet. Prüfe Adresse und Firewall.",
"cx_fail_host_key_changed": "Die Identität des Servers hat sich seit der letzten Verbindung geändert.",
"cx_fail_protocol": "Die SSH-Verbindung ist fehlgeschlagen.",
- "cx_fail_bad_key": "Das sieht nicht nach einem gültigen privaten Schlüssel aus, oder der Passwortsatz stimmt nicht."
+ "cx_fail_bad_key": "Das sieht nicht nach einem gültigen privaten Schlüssel aus, oder der Passwortsatz stimmt nicht.",
+ "cx_setup_title": "Am einfachsten: Einrichten lassen",
+ "cx_setup_body": "Kopiere diesen Prompt in Claude Code, Codex oder einen anderen Coding-Agenten AUF dem Zielcomputer. Er schaltet SSH ein, hinterlegt den Schlüssel von {name} und endet mit einer Zeile, die du unten einfügst.",
+ "cx_setup_copy": "Setup-Prompt kopieren",
+ "cx_paste": "Server",
+ "cx_paste_hint": "Eine IP, user@IP, ein ganzer ssh-Befehl – oder füge das Ergebnis des Agenten bzw. einen Block mit deinem Schlüssel ein. {name} sucht sich heraus, was es braucht.",
+ "cx_detected": "Erkannt:",
+ "cx_key_found": "Privater Schlüssel",
+ "cx_setup_done": "Schlüssel von {name} ist eingerichtet",
+ "cx_have_key": "Ich habe einen SSH-Schlüssel"
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/computers/en.json b/jarvis/ui/web/frontend/src/i18n/locales/computers/en.json
index 6a187e0f63..1432aac6a6 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/computers/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/computers/en.json
@@ -298,7 +298,7 @@
"cx_key_too_big": "That file is too large to be an SSH key.",
"cx_own_key_hint": "{name}'s public key — it must already be in the server's authorized_keys",
"cx_key_already_there": "{name}'s key is already on the server",
- "cx_use_password": "Log in with a password or key instead",
+ "cx_use_password": "Use a password instead",
"cx_more": "More options",
"cx_keep_password": "Keep using the password instead of a key",
"cx_connect": "Connect",
@@ -312,6 +312,15 @@
"cx_fail_timeout": "The server did not answer in time. Check the address and your firewall.",
"cx_fail_host_key_changed": "The server's identity changed since the last connection.",
"cx_fail_protocol": "The SSH connection failed.",
- "cx_fail_bad_key": "This does not look like a valid private key, or the passphrase is wrong."
+ "cx_fail_bad_key": "This does not look like a valid private key, or the passphrase is wrong.",
+ "cx_setup_title": "Easiest: let an agent set it up",
+ "cx_setup_body": "Copy this prompt into Claude Code, Codex or any coding agent running ON that computer. It turns on SSH, adds {name}'s key and ends with one line to paste below.",
+ "cx_setup_copy": "Copy setup prompt",
+ "cx_paste": "Server",
+ "cx_paste_hint": "An IP, user@IP, a whole ssh command — or paste the agent's result or a block with your key. {name} picks out what it needs.",
+ "cx_detected": "Found:",
+ "cx_key_found": "Private key",
+ "cx_setup_done": "{name}'s key is set up",
+ "cx_have_key": "I have an SSH key"
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/computers/es.json b/jarvis/ui/web/frontend/src/i18n/locales/computers/es.json
index c4027390c9..75d8ff03ce 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/computers/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/computers/es.json
@@ -298,7 +298,7 @@
"cx_key_too_big": "Ese archivo es demasiado grande para ser una clave SSH.",
"cx_own_key_hint": "Clave pública de {name}: ya debe estar en authorized_keys del servidor",
"cx_key_already_there": "La clave de {name} ya está en el servidor",
- "cx_use_password": "Entrar con contraseña o clave",
+ "cx_use_password": "Usar contraseña",
"cx_more": "Más opciones",
"cx_keep_password": "Seguir entrando con contraseña en lugar de clave",
"cx_connect": "Conectar",
@@ -312,6 +312,15 @@
"cx_fail_timeout": "El servidor no respondió a tiempo. Revisa la dirección y el cortafuegos.",
"cx_fail_host_key_changed": "La identidad del servidor ha cambiado desde la última conexión.",
"cx_fail_protocol": "La conexión SSH falló.",
- "cx_fail_bad_key": "No parece una clave privada válida, o la frase de contraseña es incorrecta."
+ "cx_fail_bad_key": "No parece una clave privada válida, o la frase de contraseña es incorrecta.",
+ "cx_setup_title": "Lo más fácil: que un agente lo configure",
+ "cx_setup_body": "Copia este prompt en Claude Code, Codex u otro agente de código que se ejecute EN ese ordenador. Activa SSH, añade la clave de {name} y termina con una línea que pegas abajo.",
+ "cx_setup_copy": "Copiar prompt de configuración",
+ "cx_paste": "Servidor",
+ "cx_paste_hint": "Una IP, usuario@IP, un comando ssh completo, o pega el resultado del agente o un bloque con tu clave. {name} extrae lo que necesita.",
+ "cx_detected": "Detectado:",
+ "cx_key_found": "Clave privada",
+ "cx_setup_done": "La clave de {name} está configurada",
+ "cx_have_key": "Tengo una clave SSH"
}
}
diff --git a/jarvis/ui/web/frontend/src/views/ComputersView.test.tsx b/jarvis/ui/web/frontend/src/views/ComputersView.test.tsx
index 7c5cba5f61..c82b4fbecf 100644
--- a/jarvis/ui/web/frontend/src/views/ComputersView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/ComputersView.test.tsx
@@ -176,6 +176,41 @@ describe("ComputersView", () => {
});
});
+ it("takes a pasted agent answer with a key and needs no password", async () => {
+ let rows: Computer[] = [];
+ const calls = installFetch({
+ "GET /api/computers": () => ({ computers: rows }),
+ "GET /api/computers/providers": () => ({ providers: PROVIDERS }),
+ "GET /api/computers/identity": () => IDENTITY,
+ "POST /api/computers/test": () => ({
+ ok: true, kind: null, message: null, host_fingerprint: "SHA256:x", facts: VPS.facts, latency_ms: 9,
+ }),
+ "POST /api/computers": () => {
+ rows = [VPS];
+ return VPS;
+ },
+ });
+ renderView();
+
+ fireEvent.click(await screen.findByTestId("computers-add-first"));
+ const answer = [
+ "-----BEGIN OPENSSH PRIVATE KEY-----",
+ "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQ",
+ "-----END OPENSSH PRIVATE KEY-----",
+ "ssh -i ~/.ssh/id_ed25519_grokbot [email protected]",
+ ].join("\n");
+ fireEvent.change(await screen.findByTestId("cx-address"), { target: { value: answer } });
+
+ expect(screen.queryByTestId("cx-password")).toBeNull();
+ expect(screen.getByTestId("cx-detected").textContent).toContain("[email protected]");
+ fireEvent.click(screen.getByTestId("cx-connect"));
+
+ expect(await screen.findByTestId("computer-detail")).toBeTruthy();
+ const post = calls.find((c) => c.method === "POST" && c.url === "/api/computers");
+ expect(post?.body).toMatchObject({ host: "192.168.178.132", username: "Administrator", auth: "private_key" });
+ expect((post?.body as { private_key: string }).private_key).toContain("BEGIN OPENSSH PRIVATE KEY");
+ });
+
it("offers hosting accounts as an optional shortcut", async () => {
installFetch({
"GET /api/computers": () => ({ computers: [] }),
diff --git a/jarvis/ui/web/frontend/src/views/computers/ConnectDialog.tsx b/jarvis/ui/web/frontend/src/views/computers/ConnectDialog.tsx
index e043ce8fa3..dad87f1bc2 100644
--- a/jarvis/ui/web/frontend/src/views/computers/ConnectDialog.tsx
+++ b/jarvis/ui/web/frontend/src/views/computers/ConnectDialog.tsx
@@ -1,7 +1,11 @@
/**
* "Connect a computer" — one screen, because SSH needs only two things: where
- * the server is, and a way in (the password once, or an SSH key). Which
- * company runs the server does not matter for that.
+ * the server is, and a way in. The easiest way in is the copyable setup
+ * prompt: a coding agent on that computer installs the assistant's PUBLIC key
+ * and prints one line to paste back. The paste box also understands a bare IP,
+ * user@host, a whole ssh command or a block with a private key, so the user
+ * never has to split anything into fields. The password field appears only
+ * when nothing pasted says how to log in.
*
* Two optional doors sit below the form: connect a hosting account to pick
* from all its servers (no IP to copy), or create a virtual machine here.
@@ -11,14 +15,17 @@
* assistant's own key and is then forgotten, unless "keep" is ticked.
*/
import { useEffect, useMemo, useRef, useState } from "react";
-import { ArrowLeft, ChevronDown, KeyRound, Loader2, Lock, MonitorSmartphone, Plug, X } from "lucide-react";
+import { ArrowLeft, Check, ChevronDown, Copy, KeyRound, Loader2, MonitorSmartphone, Plug, Sparkles, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { ProviderLogo } from "@/components/providers/ProviderLogo";
import { useIdentity, useProviderCatalog, useUpsertComputer } from "@/hooks/useComputers";
import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
+import { robustCopy } from "@/lib/clipboard";
+import { useEventStore } from "@/store/events";
import { computersApi, type AddServerInput, type Computer, type ProviderInfo } from "@/lib/computersApi";
-import { CopyField, Field, inputClass } from "./parts";
+import { parseConnection, setupPrompt } from "./connection";
+import { Field, inputClass } from "./parts";
import { ApiImportStep } from "./wizard/ApiImportStep";
import { LocalVmStep } from "./wizard/LocalVmStep";
import { ErrorNote, errorText } from "./wizard/shared";
@@ -26,30 +33,6 @@ import { ErrorNote, errorText } from "./wizard/shared";
type Screen = { kind: "form" } | { kind: "account"; provider: ProviderInfo } | { kind: "vm" };
type Login = "password" | "private_key" | "key";
-/** "[email protected]:2222" → user, host, port (each optional in the input). */
-export function parseAddress(raw: string): { user: string | null; host: string; port: number | null } {
- let rest = raw.trim().replace(/^ssh\s+/i, "");
- let user: string | null = null;
- const at = rest.lastIndexOf("@");
- if (at > 0) {
- user = rest.slice(0, at);
- rest = rest.slice(at + 1);
- }
- let port: number | null = null;
- const bracket = rest.match(/^\[(.+)\](?::(\d+))?$/);
- if (bracket) {
- rest = bracket[1];
- port = bracket[2] ? Number(bracket[2]) : null;
- } else if ((rest.match(/:/g) ?? []).length === 1) {
- const [h, p] = rest.split(":");
- if (/^\d+$/.test(p)) {
- rest = h;
- port = Number(p);
- }
- }
- return { user, host: rest, port };
-}
-
export function ConnectDialog({
onClose,
onOpen,
@@ -62,8 +45,9 @@ export function ConnectDialog({
const catalog = useProviderCatalog();
const identity = useIdentity();
const [screen, setScreen] = useState<Screen>({ kind: "form" });
- const [address, setAddress] = useState("");
- const [login, setLogin] = useState<Login>("password");
+ const assistantName = useEventStore((s) => s.assistantName) || "Jarvis";
+ const [pasted, setPasted] = useState("");
+ const [manualKey, setManualKey] = useState(false);
const [password, setPassword] = useState("");
const [privateKey, setPrivateKey] = useState("");
const [passphrase, setPassphrase] = useState("");
@@ -74,6 +58,7 @@ export function ConnectDialog({
const [keepPassword, setKeepPassword] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
+ const [promptCopied, setPromptCopied] = useState(false);
const fileInput = useRef<HTMLInputElement>(null);
useEffect(() => {
@@ -85,31 +70,45 @@ export function ConnectDialog({
}, [onClose]);
const accounts = useMemo(() => (catalog.data ?? []).filter((p) => p.api), [catalog.data]);
- const parsed = parseAddress(address);
- const effectiveUser = username.trim() || parsed.user || "root";
- const effectivePort = Number(port) || parsed.port || 22;
+ // Everything the paste box understood: address, login, port, a key.
+ const detected = useMemo(() => parseConnection(pasted), [pasted]);
+ const pastedKey = detected.privateKey;
+ // The login follows what was pasted: a key block wins, then our own setup
+ // prompt's result (the assistant's key is installed), else the password.
+ const login: Login = pastedKey || manualKey ? "private_key" : detected.fromSetupPrompt ? "key" : "password";
+ const effectiveUser = username.trim() || detected.user || "root";
+ const effectivePort = Number(port) || detected.port || 22;
+ const keyText = pastedKey ?? privateKey;
const ready =
- parsed.host.length > 0 &&
- (login === "key" || (login === "password" ? password.length > 0 : privateKey.trim().length > 0));
+ Boolean(detected.host) &&
+ (login === "key" || (login === "password" ? password.length > 0 : keyText.trim().length > 0));
const finish = (computer: Computer) => {
upsert(computer);
onOpen(computer, "overview");
};
+ async function copyPrompt() {
+ if (!identity.data) return;
+ const ok = await robustCopy(setupPrompt(assistantName, identity.data.public_key));
+ if (!ok) return;
+ setPromptCopied(true);
+ window.setTimeout(() => setPromptCopied(false), 2000);
+ }
+
async function connect() {
- if (!ready || busy) return;
+ if (!ready || busy || !detected.host) return;
setBusy(true);
setError(null);
const input: AddServerInput = {
- name: name.trim() || parsed.host,
- host: parsed.host,
+ name: name.trim() || detected.host,
+ host: detected.host,
port: effectivePort,
username: effectiveUser,
auth: login,
password: login === "password" ? password : undefined,
keep_password: login === "password" ? keepPassword : undefined,
- private_key: login === "private_key" ? privateKey : undefined,
+ private_key: login === "private_key" ? keyText : undefined,
passphrase: login === "private_key" && passphrase ? passphrase : undefined,
provider: "generic",
};
@@ -136,11 +135,6 @@ export function ConnectDialog({
setPrivateKey(await file.text());
}
- const loginTabs: { id: Login; label: string; icon: typeof Lock }[] = [
- { id: "password", label: t("computers.cx_login_password"), icon: Lock },
- { id: "private_key", label: t("computers.cx_login_key"), icon: KeyRound },
- ];
-
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-scrim/50 p-4 backdrop-blur-sm">
<div
@@ -202,12 +196,34 @@ export function ConnectDialog({
void connect();
}}
>
- <Field label={t("computers.cx_address")} hint={t("computers.cx_address_hint")}>
- <input
- className={cn(inputClass, "h-10 font-mono")}
- value={address}
- onChange={(e) => setAddress(e.target.value)}
- placeholder="[email protected]"
+ <div className="rounded-lg border border-border bg-secondary/40 p-4" data-testid="cx-setup">
+ <div className="flex items-start gap-3">
+ <Sparkles className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" aria-hidden />
+ <div className="min-w-0 flex-1">
+ <div className="text-sm font-medium text-foreground-strong">{t("computers.cx_setup_title")}</div>
+ <p className="mt-0.5 text-xs text-muted-foreground">{t("computers.cx_setup_body")}</p>
+ </div>
+ <Button
+ type="button"
+ variant="outline"
+ size="sm"
+ disabled={!identity.data}
+ onClick={() => void copyPrompt()}
+ data-testid="cx-copy-prompt"
+ >
+ {promptCopied ? <Check className="text-success" /> : <Copy />}
+ {promptCopied ? t("computers.copied") : t("computers.cx_setup_copy")}
+ </Button>
+ </div>
+ </div>
+
+ <Field label={t("computers.cx_paste")} hint={t("computers.cx_paste_hint")}>
+ <textarea
+ className={cn(inputClass, "h-auto min-h-[40px] resize-none py-2 font-mono text-sm")}
+ rows={pasted.includes("\n") ? 4 : 1}
+ value={pasted}
+ onChange={(e) => setPasted(e.target.value)}
+ placeholder="203.0.113.10"
autoFocus
spellCheck={false}
autoComplete="off"
@@ -215,127 +231,113 @@ export function ConnectDialog({
/>
</Field>
- <div>
- <div role="tablist" aria-label={t("computers.cx_login")} className="flex gap-1 rounded-lg bg-secondary p-1">
- {loginTabs.map((tab) => {
- const Icon = tab.icon;
- const active = login === tab.id;
- return (
- <button
- key={tab.id}
- type="button"
- role="tab"
- aria-selected={active}
- onClick={() => setLogin(tab.id)}
- className={cn(
- "flex h-8 flex-1 items-center justify-center gap-1.5 rounded-md text-sm font-medium transition-colors",
- active ? "bg-popover text-foreground-strong shadow-sm" : "text-muted-foreground hover:text-foreground",
- )}
- >
- <Icon className="h-3.5 w-3.5" aria-hidden />
- {tab.label}
- </button>
- );
- })}
- </div>
-
- <div className="mt-4">
- {login === "password" && (
- <Field label={t("computers.cx_password")} hint={t("computers.cx_password_hint")}>
- <input
- type="password"
- className={cn(inputClass, "h-10")}
- value={password}
- onChange={(e) => setPassword(e.target.value)}
- autoComplete="new-password"
- data-testid="cx-password"
- />
- </Field>
- )}
+ {detected.host && (
+ <div className="flex flex-wrap items-center gap-1.5 text-xs" data-testid="cx-detected">
+ <span className="text-muted-foreground">{t("computers.cx_detected")}</span>
+ <span className="rounded bg-secondary px-1.5 py-0.5 font-mono text-foreground-secondary">
+ {effectiveUser}@{detected.host}
+ {effectivePort !== 22 ? `:${effectivePort}` : ""}
+ </span>
{login === "private_key" && (
- <div className="space-y-3">
- <Field label={t("computers.cx_private_key")} hint={t("computers.cx_private_key_hint")}>
- <textarea
- className={cn(inputClass, "h-24 resize-none py-2 font-mono text-xs")}
- value={privateKey}
- onChange={(e) => setPrivateKey(e.target.value)}
- placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
- spellCheck={false}
- data-testid="cx-private-key"
- />
- </Field>
- <div className="flex items-center gap-3">
- <Button type="button" variant="outline" size="sm" onClick={() => fileInput.current?.click()}>
- {t("computers.cx_key_file")}
- </Button>
- <input
- ref={fileInput}
- type="file"
- className="hidden"
- onChange={(e) => void pickKeyFile(e.target.files?.[0])}
- />
- <input
- type="password"
- className={cn(inputClass, "h-8 flex-1 text-sm")}
- value={passphrase}
- onChange={(e) => setPassphrase(e.target.value)}
- placeholder={t("computers.cx_passphrase")}
- aria-label={t("computers.cx_passphrase")}
- autoComplete="off"
- />
- </div>
- </div>
+ <span className="inline-flex items-center gap-1 rounded bg-success/15 px-1.5 py-0.5 text-success">
+ <KeyRound className="h-3 w-3" aria-hidden />
+ {t("computers.cx_key_found")}
+ </span>
)}
- {login === "key" && identity.data && (
- <CopyField
- multiline
- label={t("computers.cx_own_key_hint")}
- value={identity.data.public_key}
- copyLabel={t("computers.copy")}
- copiedLabel={t("computers.copied")}
- />
+ {login === "key" && (
+ <span className="inline-flex items-center gap-1 rounded bg-success/15 px-1.5 py-0.5 text-success">
+ <Check className="h-3 w-3" aria-hidden />
+ {t("computers.cx_setup_done")}
+ </span>
)}
+ </div>
+ )}
+
+ {login === "password" && (
+ <Field label={t("computers.cx_password")} hint={t("computers.cx_password_hint")}>
+ <input
+ type="password"
+ className={cn(inputClass, "h-10")}
+ value={password}
+ onChange={(e) => setPassword(e.target.value)}
+ autoComplete="new-password"
+ data-testid="cx-password"
+ />
+ </Field>
+ )}
+
+ {manualKey && login === "private_key" && !pastedKey && (
+ <div className="space-y-3">
+ <Field label={t("computers.cx_private_key")} hint={t("computers.cx_private_key_hint")}>
+ <textarea
+ className={cn(inputClass, "h-24 resize-none py-2 font-mono text-xs")}
+ value={privateKey}
+ onChange={(e) => setPrivateKey(e.target.value)}
+ placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
+ spellCheck={false}
+ data-testid="cx-private-key"
+ />
+ </Field>
+ <Button type="button" variant="outline" size="sm" onClick={() => fileInput.current?.click()}>
+ {t("computers.cx_key_file")}
+ </Button>
+ <input ref={fileInput} type="file" className="hidden" onChange={(e) => void pickKeyFile(e.target.files?.[0])} />
+ </div>
+ )}
+
+ {login === "private_key" && (
+ <input
+ type="password"
+ className={cn(inputClass, "h-9 text-sm")}
+ value={passphrase}
+ onChange={(e) => setPassphrase(e.target.value)}
+ placeholder={t("computers.cx_passphrase")}
+ aria-label={t("computers.cx_passphrase")}
+ autoComplete="off"
+ />
+ )}
+
+ <div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs">
+ {!pastedKey && !detected.fromSetupPrompt && (
<button
type="button"
- onClick={() => setLogin(login === "key" ? "password" : "key")}
- className="mt-2 text-xs text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
+ onClick={() => setManualKey((v) => !v)}
+ className="text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
>
- {login === "key" ? t("computers.cx_use_password") : t("computers.cx_key_already_there")}
+ {manualKey ? t("computers.cx_use_password") : t("computers.cx_have_key")}
</button>
- </div>
- </div>
-
- <div>
+ )}
<button
type="button"
onClick={() => setMore((v) => !v)}
aria-expanded={more}
- className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground"
+ className="inline-flex items-center gap-1 text-muted-foreground hover:text-foreground"
>
- <ChevronDown className={cn("h-4 w-4 transition-transform", more && "rotate-180")} aria-hidden />
+ <ChevronDown className={cn("h-3.5 w-3.5 transition-transform", more && "rotate-180")} aria-hidden />
{t("computers.cx_more")}
</button>
- {more && (
- <div className="mt-3 grid gap-3 sm:grid-cols-[minmax(0,1fr)_110px_80px]">
- <Field label={t("computers.field_name")}>
- <input className={inputClass} value={name} onChange={(e) => setName(e.target.value)} placeholder={parsed.host || t("computers.field_name_placeholder")} />
- </Field>
- <Field label={t("computers.field_username")}>
- <input className={cn(inputClass, "font-mono")} value={username} onChange={(e) => setUsername(e.target.value)} placeholder={parsed.user || "root"} spellCheck={false} />
- </Field>
- <Field label={t("computers.field_port")}>
- <input className={cn(inputClass, "font-mono")} value={port} inputMode="numeric" onChange={(e) => setPort(e.target.value.replace(/[^0-9]/g, ""))} placeholder={String(parsed.port ?? 22)} />
- </Field>
- {login === "password" && (
- <label className="col-span-full flex items-center gap-2 text-sm text-foreground-secondary">
- <input type="checkbox" checked={keepPassword} onChange={(e) => setKeepPassword(e.target.checked)} className="h-4 w-4" />
- {t("computers.cx_keep_password")}
- </label>
- )}
- </div>
- )}
</div>
+ {more && (
+ <div className="grid gap-3 sm:grid-cols-[minmax(0,1fr)_110px_80px]">
+ <Field label={t("computers.field_name")}>
+ <input className={inputClass} value={name} onChange={(e) => setName(e.target.value)} placeholder={detected.host || t("computers.field_name_placeholder")} />
+ </Field>
+ <Field label={t("computers.field_username")}>
+ <input className={cn(inputClass, "font-mono")} value={username} onChange={(e) => setUsername(e.target.value)} placeholder={detected.user || "root"} spellCheck={false} />
+ </Field>
+ <Field label={t("computers.field_port")}>
+ <input className={cn(inputClass, "font-mono")} value={port} inputMode="numeric" onChange={(e) => setPort(e.target.value.replace(/[^0-9]/g, ""))} placeholder={String(detected.port ?? 22)} />
+ </Field>
+ {login === "password" && (
+ <label className="col-span-full flex items-center gap-2 text-sm text-foreground-secondary">
+ <input type="checkbox" checked={keepPassword} onChange={(e) => setKeepPassword(e.target.checked)} className="h-4 w-4" />
+ {t("computers.cx_keep_password")}
+ </label>
+ )}
+ </div>
+ )}
+
<ErrorNote message={error} />
<Button type="submit" className="h-10 w-full" disabled={!ready || busy} data-testid="cx-connect">
diff --git a/jarvis/ui/web/frontend/src/views/computers/connection.test.ts b/jarvis/ui/web/frontend/src/views/computers/connection.test.ts
new file mode 100644
index 0000000000..c34b990640
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/computers/connection.test.ts
@@ -0,0 +1,56 @@
+import { describe, expect, it } from "vitest";
+import { CONNECT_MARKER, parseConnection, setupPrompt } from "./connection";
+
+const KEY = [
+ "-----BEGIN OPENSSH PRIVATE KEY-----",
+ "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW",
+ "QyNTUxOQAAACASIKR6ANBgoozPuWTatwu3XSwQsPNn1cR6jQWJtaWShwAAALBTqx6wU6se",
+ "-----END OPENSSH PRIVATE KEY-----",
+].join("\n");
+
+describe("parseConnection", () => {
+ it("reads a bare IP, user@host and host:port", () => {
+ expect(parseConnection("192.168.178.132")).toMatchObject({ user: null, host: "192.168.178.132", port: null });
+ expect(parseConnection("[email protected]:2222")).toMatchObject({
+ user: "admin",
+ host: "vps.example.com",
+ port: 2222,
+ });
+ });
+
+ it("reads a whole ssh command and skips the key file path", () => {
+ expect(parseConnection("ssh -i ~/.ssh/id_ed25519_grokbot -p 2200 [email protected]")).toMatchObject({
+ user: "Administrator",
+ host: "192.168.178.132",
+ port: 2200,
+ });
+ });
+
+ it("pulls address and private key out of an agent's whole answer", () => {
+ const answer = `Here is your new key.\n\n${KEY}\n\nPublic key (already in C:\\Users\\Administrator\\.ssh\\authorized_keys):\n\nssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBIgpHoA0GCijM+5ZNq3C7dd aethroc@INSTALL-79MCMN5\n\nConnection:\n\nssh -i ~/.ssh/id_ed25519_grokbot [email protected]\n`;
+ const parsed = parseConnection(answer);
+ expect(parsed).toMatchObject({ user: "Administrator", host: "192.168.178.132", port: null, fromSetupPrompt: false });
+ expect(parsed.privateKey).toContain("BEGIN OPENSSH PRIVATE KEY");
+ expect(parsed.privateKey).toContain("END OPENSSH PRIVATE KEY");
+ });
+
+ it("recognises the setup prompt's result line", () => {
+ const parsed = parseConnection(`All done.\n${CONNECT_MARKER} [email protected]:22`);
+ expect(parsed).toMatchObject({ user: "ubuntu", host: "203.0.113.10", port: 22, fromSetupPrompt: true });
+ });
+
+ it("finds nothing in text without an address", () => {
+ expect(parseConnection("hello there, no server here").host).toBeNull();
+ expect(parseConnection("").host).toBeNull();
+ });
+});
+
+describe("setupPrompt", () => {
+ it("carries only the public key and ends with the marker line", () => {
+ const prompt = setupPrompt("George", "ssh-ed25519 AAAA george@desk");
+ expect(prompt).toContain("ssh-ed25519 AAAA george@desk");
+ expect(prompt).toContain("administrators_authorized_keys");
+ expect(prompt).not.toContain("BEGIN OPENSSH PRIVATE KEY");
+ expect(prompt.trim().endsWith(`${CONNECT_MARKER} <account>@<address>:<port>`)).toBe(true);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/views/computers/connection.ts b/jarvis/ui/web/frontend/src/views/computers/connection.ts
new file mode 100644
index 0000000000..0dbbb25c2d
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/computers/connection.ts
@@ -0,0 +1,149 @@
+/**
+ * Reading "how do I reach this computer" out of whatever the user pastes, and
+ * the setup prompt that makes a coding agent on that computer produce it.
+ *
+ * People arrive with very different things in the clipboard: a bare IP, a
+ * `user@host`, a whole `ssh -i key -p 2222 user@host` line, the block another
+ * agent printed (private key + public key + command), or the one line our own
+ * setup prompt ends with. `parseConnection` pulls out what matters and ignores
+ * the rest — a public key or a key *file path* is never mistaken for a host.
+ */
+
+/** The single line the setup prompt asks the agent to finish with. */
+export const CONNECT_MARKER = "JARVIS-CONNECT";
+
+export interface ParsedConnection {
+ user: string | null;
+ host: string | null;
+ port: number | null;
+ /** A pasted private key (OpenSSH/PEM block), if the text carried one. */
+ privateKey: string | null;
+ /** The text is our setup prompt's result: the assistant's key is installed. */
+ fromSetupPrompt: boolean;
+}
+
+const PRIVATE_KEY_RE = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/;
+const MARKER_RE = new RegExp(`${CONNECT_MARKER}\\s+(\\S+)`);
+const SSH_LINE_RE = /(?:^|\s)ssh\s+([^\n]+)/;
+const IPV4 = "(?:\\d{1,3}\\.){3}\\d{1,3}";
+const HOSTNAME = "(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,}";
+const USER_AT_HOST_RE = new RegExp(`([A-Za-z0-9._-]+)@(${IPV4}|${HOSTNAME}|\\[[0-9A-Fa-f:]+\\])(?::(\\d{1,5}))?`);
+const BARE_HOST_RE = new RegExp(`(?:^|\\s)(${IPV4}|\\[[0-9A-Fa-f:]+\\])(?::(\\d{1,5}))?(?=\\s|$)`);
+
+/** "user@host:port" (each part optional) → its parts. */
+export function splitAddress(raw: string): { user: string | null; host: string | null; port: number | null } {
+ let rest = raw.trim();
+ if (!rest) return { user: null, host: null, port: null };
+ let user: string | null = null;
+ const at = rest.lastIndexOf("@");
+ if (at > 0) {
+ user = rest.slice(0, at);
+ rest = rest.slice(at + 1);
+ }
+ let port: number | null = null;
+ const bracket = rest.match(/^\[(.+)\](?::(\d+))?$/);
+ if (bracket) {
+ rest = bracket[1];
+ port = bracket[2] ? Number(bracket[2]) : null;
+ } else if ((rest.match(/:/g) ?? []).length === 1) {
+ const [h, p] = rest.split(":");
+ if (/^\d+$/.test(p)) {
+ rest = h;
+ port = Number(p);
+ }
+ }
+ return { user, host: rest || null, port };
+}
+
+/** The destination and options of one `ssh ...` command line. */
+function parseSshLine(args: string): { user: string | null; host: string | null; port: number | null } {
+ const tokens = args.trim().split(/\s+/);
+ let user: string | null = null;
+ let port: number | null = null;
+ let destination: string | null = null;
+ for (let i = 0; i < tokens.length; i += 1) {
+ const token = tokens[i];
+ if (token === "-p" && tokens[i + 1]) {
+ port = Number(tokens[i + 1]) || null;
+ i += 1;
+ } else if (token === "-l" && tokens[i + 1]) {
+ user = tokens[i + 1];
+ i += 1;
+ } else if (/^-[iFJoEbcDeLmOQRSWw]$/.test(token)) {
+ i += 1; // an option that takes a value we do not need (-i key file, ...)
+ } else if (token.startsWith("-")) {
+ continue;
+ } else if (destination === null) {
+ destination = token;
+ }
+ }
+ const parts = splitAddress(destination ?? "");
+ return { user: user ?? parts.user, host: parts.host, port: port ?? parts.port };
+}
+
+export function parseConnection(text: string): ParsedConnection {
+ const raw = text.replace(/\r/g, "");
+ const keyMatch = raw.match(PRIVATE_KEY_RE);
+ const privateKey = keyMatch ? keyMatch[0].trim() + "\n" : null;
+ // Everything else is read with the key block removed, so base64 lines can
+ // never look like a host.
+ const rest = keyMatch ? raw.replace(keyMatch[0], " ") : raw;
+ const empty: ParsedConnection = { user: null, host: null, port: null, privateKey, fromSetupPrompt: false };
+
+ const marker = rest.match(MARKER_RE);
+ if (marker) {
+ return { ...empty, ...splitAddress(marker[1]), fromSetupPrompt: true };
+ }
+ const sshLine = rest.match(SSH_LINE_RE);
+ if (sshLine) {
+ const parsed = parseSshLine(sshLine[1]);
+ if (parsed.host) return { ...empty, ...parsed };
+ }
+ const userAtHost = rest.match(USER_AT_HOST_RE);
+ if (userAtHost) {
+ return {
+ ...empty,
+ user: userAtHost[1],
+ host: userAtHost[2].replace(/^\[|\]$/g, ""),
+ port: userAtHost[3] ? Number(userAtHost[3]) : null,
+ };
+ }
+ const bare = rest.match(BARE_HOST_RE);
+ if (bare) {
+ return { ...empty, host: bare[1].replace(/^\[|\]$/g, ""), port: bare[2] ? Number(bare[2]) : null };
+ }
+ // A single short line that is none of the above: a host name the user typed.
+ const single = rest.trim();
+ if (single && !/\s/.test(single) && single.length < 254 && !single.includes("/") && !single.includes("\\")) {
+ return { ...empty, ...splitAddress(single) };
+ }
+ return empty;
+}
+
+/**
+ * The prompt a coding agent ON THE TARGET COMPUTER runs to let the assistant
+ * in. It installs only the PUBLIC key — no private key is created or moves —
+ * and ends with one line the user pastes back into the connect dialog.
+ */
+export function setupPrompt(assistantName: string, publicKey: string): string {
+ return `Set up this computer so my assistant "${assistantName}" can log in to it over SSH. Do every step yourself; only stop when something needs my approval (an admin/sudo/UAC prompt).
+
+1. Make sure an OpenSSH SERVER is installed, running, starts automatically, and is allowed through the firewall on TCP port 22.
+ - Linux: install openssh-server with the package manager, then enable and start the ssh/sshd service.
+ - macOS: turn on System Settings > General > Sharing > Remote Login.
+ - Windows: Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0, Start-Service sshd, Set-Service sshd -StartupType Automatic, and allow TCP 22 in Windows Defender Firewall.
+
+2. Authorize exactly this PUBLIC key for the account I normally use on this computer. Do not create, copy or print any private key.
+ ${publicKey}
+ - Linux/macOS: append it to ~/.ssh/authorized_keys of that account (folder mode 700, file mode 600, owned by that account).
+ - Windows: if the account is in the Administrators group, append it to C:\\ProgramData\\ssh\\administrators_authorized_keys and run: icacls C:\\ProgramData\\ssh\\administrators_authorized_keys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F". Otherwise append it to C:\\Users\\<account>\\.ssh\\authorized_keys.
+
+3. If this is Linux or macOS, also install tmux and git if they are missing (coding agents will run here later).
+
+4. Work out the address another computer can use to reach this one: the local network IP if we are on the same network, otherwise the public IP. If a router port-forward would be needed, tell me in one sentence.
+
+5. Test that the key login is accepted (for example with sshd's logs or ssh -o BatchMode=yes against localhost if possible).
+
+6. Finish with exactly this one line and nothing after it, filled in:
+${CONNECT_MARKER} <account>@<address>:<port>`;
+}