Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(connectors): finish a phone's sign-in here; restart from Settings ▸ Connectors

bubu-dudub5e5bc2f1ed5
diff --git a/cli/scripts/connector-assets.mjs b/cli/scripts/connector-assets.mjs
index 1cd94420a..bd2d7288f 100644
--- a/cli/scripts/connector-assets.mjs
+++ b/cli/scripts/connector-assets.mjs
@@ -44,9 +44,37 @@ export function renderDesktop() {
}
}
+/**
+ * The phone app's copy. It draws no SVG (it carries no SVG package), so a service whose icon is an SVG
+ * takes its PNG rendering from assets/mobile-icons: 64 px, transparent, made once from the SVG beside it
+ * (headless Chrome, or `rsvg-convert -w 64 -h 64 --keep-aspect-ratio`) when that icon changes.
+ */
+const mobile = fileURLToPath(new URL('../../mobile/', import.meta.url))
+export function renderMobile() {
+ const icons = {}
+ for (const name of readdirSync(join(assets, 'web/icons')).sort()) {
+ const code = basename(name, extname(name))
+ if (extname(name) === '.png') icons[`${code}.png`] = readFileSync(join(assets, 'web/icons', name))
+ else if (extname(name) === '.svg') icons[`${code}.png`] = readFileSync(join(assets, 'mobile-icons', `${code}.png`))
+ }
+ const map = Object.keys(icons).sort().map(name => ` '${basename(name, '.png')}': 'assets/connector-icons/${name}',`).join('\n')
+ return {
+ icons,
+ dart: `// Generated by cli/scripts/connector-assets.mjs from cli/src/lib/connectors/assets. Do not edit.\n\n/// Each connected service's icon, bundled with the app, by its code. PNG only: this app draws no SVG.\nconst connectorIcons = <String, String>{\n${map}\n};\n`,
+ }
+}
+
+const NOTICE = [
+ 'OpenHarness: service icons for Settings ▸ Connectors', '',
+ 'Copied by cli/scripts/connector-assets.mjs from cli/src/lib/connectors/assets/web/icons; do not edit here.', '',
+ "Sources: Autonomous's connector icons (cdn.autonomous.ai), Simple Icons (CC0) and the services' own",
+ 'favicons, resized to 64 px PNG or coloured SVG. Names and marks identify the services; they do not imply',
+ 'sponsorship or endorsement.', ''].join('\n')
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const files = render()
const app = renderDesktop()
+ const phone = renderMobile()
if (process.argv.includes('--check')) {
const stale = Object.entries(files).filter(([name, body]) => {
try { return readFileSync(join(out, name), 'utf8') !== body } catch { return true }
@@ -58,13 +86,13 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
rmSync(join(desktop, 'assets/connector-icons'), { recursive: true, force: true })
mkdirSync(join(desktop, 'assets/connector-icons'), { recursive: true })
for (const [name, data] of Object.entries(app.icons)) writeFileSync(join(desktop, 'assets/connector-icons', name), data)
- writeFileSync(join(desktop, 'assets/connector-icons/NOTICE.txt'), [
- 'OpenHarness: service icons for Settings ▸ Connectors', '',
- 'Copied by cli/scripts/connector-assets.mjs from cli/src/lib/connectors/assets/web/icons; do not edit here.', '',
- "Sources: Autonomous's connector icons (cdn.autonomous.ai), Simple Icons (CC0) and the services' own",
- 'favicons, resized to 64 px PNG or coloured SVG. Names and marks identify the services; they do not imply',
- 'sponsorship or endorsement.', ''].join('\n'))
+ writeFileSync(join(desktop, 'assets/connector-icons/NOTICE.txt'), NOTICE)
mkdirSync(join(desktop, 'lib/connectors'), { recursive: true })
writeFileSync(join(desktop, 'lib/connectors/connector_icons.dart'), app.dart)
+ rmSync(join(mobile, 'assets/connector-icons'), { recursive: true, force: true })
+ mkdirSync(join(mobile, 'assets/connector-icons'), { recursive: true })
+ for (const [name, data] of Object.entries(phone.icons)) writeFileSync(join(mobile, 'assets/connector-icons', name), data)
+ writeFileSync(join(mobile, 'assets/connector-icons/NOTICE.txt'), NOTICE)
+ writeFileSync(join(mobile, 'lib/phone/connector_icons.dart'), phone.dart)
}
}
diff --git a/cli/src/lib/connectors/assets/mobile-icons/airtable.png b/cli/src/lib/connectors/assets/mobile-icons/airtable.png
new file mode 100644
index 000000000..f9e9cb83f
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/airtable.png differ
diff --git a/cli/src/lib/connectors/assets/mobile-icons/figma-api-app.png b/cli/src/lib/connectors/assets/mobile-icons/figma-api-app.png
new file mode 100644
index 000000000..2fc7c59f7
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/figma-api-app.png differ
diff --git a/cli/src/lib/connectors/assets/mobile-icons/gitlab.png b/cli/src/lib/connectors/assets/mobile-icons/gitlab.png
new file mode 100644
index 000000000..05da4382c
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/gitlab.png differ
diff --git a/cli/src/lib/connectors/assets/mobile-icons/sentry.png b/cli/src/lib/connectors/assets/mobile-icons/sentry.png
new file mode 100644
index 000000000..1d2aa51c6
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/sentry.png differ
diff --git a/cli/src/lib/connectors/assets/mobile-icons/stripe.png b/cli/src/lib/connectors/assets/mobile-icons/stripe.png
new file mode 100644
index 000000000..102295bf7
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/stripe.png differ
diff --git a/cli/src/lib/connectors/assets/mobile-icons/supabase.png b/cli/src/lib/connectors/assets/mobile-icons/supabase.png
new file mode 100644
index 000000000..56b35a9b9
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/supabase.png differ
diff --git a/cli/src/lib/connectors/assets/mobile-icons/vercel.png b/cli/src/lib/connectors/assets/mobile-icons/vercel.png
new file mode 100644
index 000000000..07c2b9431
Binary files /dev/null and b/cli/src/lib/connectors/assets/mobile-icons/vercel.png differ
diff --git a/cli/src/lib/connectors/assets/web/index.html b/cli/src/lib/connectors/assets/web/index.html
index 1b9ae36d7..4a507d797 100644
--- a/cli/src/lib/connectors/assets/web/index.html
+++ b/cli/src/lib/connectors/assets/web/index.html
@@ -23,7 +23,7 @@
<p id="signed-out" class="hint-line" hidden>GitHub, Slack, Google and a few more sign in through your Harness account. Run <code>harness login</code>, then refresh to connect them.</p>
<p id="notice" role="status" aria-live="polite"></p>
<div id="sections"><p class="empty">Loading connectors…</p></div>
- <footer>Accounts stay on this computer and are shared by every agent you run here. Disconnecting stops Harness from using an account; revoke it in the service's settings to remove it everywhere.</footer>
+ <footer>Accounts are shared by every agent you run, on every computer signed in to your Harness account. Disconnecting stops Harness from using an account; revoke it in the service's settings to remove it at the service too.</footer>
</main>
<dialog id="custom-dialog">
<form id="custom-form">
diff --git a/cli/src/lib/connectors/assets/web/page.js b/cli/src/lib/connectors/assets/web/page.js
index 435d6575b..178236888 100644
--- a/cli/src/lib/connectors/assets/web/page.js
+++ b/cli/src/lib/connectors/assets/web/page.js
@@ -9,6 +9,13 @@ const search = $("#search");
let items = [];
let view = "browse";
const pending = new Map(); // connector -> flow id
+let noticeTimer = 0;
+// A notice goes away on its own, so a disconnect from earlier does not stand there for good.
+function say(text) {
+ notice.textContent = text;
+ clearTimeout(noticeTimer);
+ if (text) noticeTimer = setTimeout(() => {notice.textContent = "";}, 20000);
+}
async function request(path, body) {
const response = await fetch(path, {
@@ -106,12 +113,12 @@ async function follow(item, flow) {
for (;;) {
await new Promise((done) => setTimeout(done, 1000));
const status = await request("/api/flows/" + flow);
- if (status.state === "connected") {notice.textContent = item.name + " connected. Your agents can use it now."; break;}
- if (status.state === "failed") {notice.textContent = item.name + ": " + status.error; break;}
+ if (status.state === "connected") {say(item.name + " connected. Your agents can use it now."); break;}
+ if (status.state === "failed") {say(item.name + ": " + status.error); break;}
}
- } catch (e) {notice.textContent = e.message;}
+ } catch (e) {say(e.message);}
pending.delete(item.connector);
- await refresh().catch((e) => {notice.textContent = e.message;});
+ await refresh().catch((e) => {say(e.message);});
}
function blankTab() {
const tab = window.open("about:blank", "_blank");
@@ -120,18 +127,18 @@ function blankTab() {
return tab;
}
async function connect(item) {
- notice.textContent = "";
+ say("");
// Open the tab inside the click, so the browser allows it; the address follows.
const tab = blankTab();
try {
const result = await request("/api/connect", {connector: item.connector});
if (result.authorize_url && tab) tab.location.href = result.authorize_url;
else if (tab) tab.close();
- if (result.authorize_url && !tab) notice.textContent = "Allow pop-ups for this page to sign in to " + item.name + ".";
+ if (result.authorize_url && !tab) say("Allow pop-ups for this page to sign in to " + item.name + ".");
await follow(item, result.flow);
} catch (e) {
if (tab) tab.close();
- notice.textContent = item.name + ": " + e.message;
+ say(item.name + ": " + e.message);
}
}
let disconnecting = null;
@@ -147,9 +154,9 @@ $("#confirm-form").addEventListener("submit", async (event) => {
const item = disconnecting;
try {
await request("/api/disconnect", {connector: item.connector});
- notice.textContent = item.name + " disconnected on this computer.";
+ say(item.name + " disconnected.");
await refresh();
- } catch (e) {notice.textContent = e.message;}
+ } catch (e) {say(e.message);}
});
function headers(text) {
const result = {};
@@ -184,7 +191,7 @@ $("#custom-form").addEventListener("submit", async (event) => {
await follow({connector: "custom:" + name, name}, result.flow);
} else {
if (tab) tab.close();
- notice.textContent = name + " added. Your agents can use it now.";
+ say(name + " added. Your agents can use it now.");
await refresh();
}
} catch (e) {
@@ -202,7 +209,7 @@ function show(next) {
}
$("#browse").addEventListener("click", () => show("browse"));
$("#connected").addEventListener("click", () => show("connected"));
-$("#reload").addEventListener("click", () => refresh().catch((e) => {notice.textContent = e.message;}));
+$("#reload").addEventListener("click", () => refresh().catch((e) => {say(e.message);}));
search.addEventListener("input", render);
-if (!key) notice.textContent = "Open “harness connections” from the terminal to manage your accounts.";
-else refresh().catch((e) => {notice.textContent = e.message;});
+if (!key) say("Open “harness connections” from the terminal to manage your accounts.");
+else refresh().catch((e) => {say(e.message);});
diff --git a/cli/src/lib/connectors/connect.ts b/cli/src/lib/connectors/connect.ts
index 3b4bcc87f..4c5f6a690 100644
--- a/cli/src/lib/connectors/connect.ts
+++ b/cli/src/lib/connectors/connect.ts
@@ -35,7 +35,7 @@ export function customCode(name: string, taken: Set<string>): string {
return validateCode(code)
}
-interface Flow { connector: string, state: 'pending' | 'connected' | 'failed', error: string, cancel: boolean }
+interface Flow { connector: string, state: 'pending' | 'connected' | 'failed', error: string, cancel: boolean, signIn: SignIn }
/** Browser sign-ins in progress, each finishing on its own. */
export class Flows {
@@ -45,7 +45,7 @@ export class Flows {
async start(code: string, signIn: SignIn, label?: string): Promise<{ flow: string, authorize_url: string | null }> {
const authorize = await signIn.prepare()
const flow = randomBytes(12).toString('base64url')
- const record: Flow = { connector: code, state: 'pending', error: '', cancel: false }
+ const record: Flow = { connector: code, state: 'pending', error: '', cancel: false, signIn }
// One sign-in per service: a newer one replaces a forgotten tab.
for (const other of this.items.values()) if (other.connector === code && other.state === 'pending') other.cancel = true
this.items.set(flow, record)
@@ -65,6 +65,15 @@ export class Flows {
return { connector: record.connector, state: record.state, error: record.error }
}
+ /** A browser redirect caught on another device (the phone), for this computer's own sign-in. */
+ deliver(flow: string, url: string): { connector: string, state: string } {
+ const record = this.items.get(flow)
+ if (!record || record.state !== 'pending' || record.cancel) throw new ConnectorError('This sign-in has ended. Try again.')
+ if (!record.signIn.deliver) throw new ConnectorError('This service finishes its sign-in on its own.')
+ try { record.signIn.deliver(url) } catch { throw new ConnectorError('This is not the sign-in address. Try again.') }
+ return { connector: record.connector, state: record.state }
+ }
+
get pending(): boolean { return [...this.items.values()].some(flow => flow.state === 'pending') }
}
diff --git a/cli/src/lib/connectors/connectors.spec.ts b/cli/src/lib/connectors/connectors.spec.ts
index 8062071da..e95ae1d74 100644
--- a/cli/src/lib/connectors/connectors.spec.ts
+++ b/cli/src/lib/connectors/connectors.spec.ts
@@ -2,7 +2,7 @@
* Connected services, against fake services (testing/connectorServers.ts) in a throwaway home: never a
* real provider, ~/.claude or ~/.codex.
*/
-import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, symlinkSync, writeFileSync, chmodSync } from 'node:fs'
import { createServer, request as httpRequest } from 'node:http'
import { tmpdir } from 'node:os'
@@ -69,6 +69,22 @@ describe('signing in from this computer (MCP OAuth)', () => {
await expect(signIn(fake, true)).rejects.toThrow('could not be confirmed')
expect(vault.tokens()).toEqual({})
})
+
+ it('finishes with the redirect a phone caught in its own browser, and only that address', async () => {
+ const fake = await service()
+ const flows = new Flows(vault, env)
+ const { flow, authorize_url } = await flows.start('linear', new LocalSignIn(vault, fake.base + '/mcp'))
+ // The phone's browser follows the service to this computer's 127.0.0.1 address, which it cannot reach.
+ const caught = (await fetch(authorize_url!, { redirect: 'manual' })).headers.get('location')!
+ const port = Number(new URL(caught).port)
+ expect(() => flows.deliver(flow, caught.replace(`:${port}/`, `:${port + 1}/`))).toThrow('not the sign-in address')
+ expect(() => flows.deliver(flow, caught.replace('/callback', '/elsewhere'))).toThrow('not the sign-in address')
+ expect(() => flows.deliver('gone', caught)).toThrow('ended')
+ expect(flows.deliver(flow, caught)).toEqual({ connector: 'linear', state: 'pending' })
+ await vi.waitFor(() => expect(flows.get(flow).state).toBe('connected'))
+ expect(vault.token('linear')).toMatchObject({ source: 'dcr', mcp_entry: { headers: { Authorization: 'Bearer access-1' } } })
+ expect(() => flows.deliver(flow, caught)).toThrow('ended')
+ })
})
describe('the bridge', () => {
@@ -204,6 +220,13 @@ describe('the connector gateway', () => {
expect(vault.token('github')).toBeUndefined()
}, 15_000)
+ it('takes no caught redirect for a gateway sign-in, which the gateway finishes', async () => {
+ await signedIn()
+ const flows = new Flows(vault, env)
+ const { flow } = await flows.start('github', signInFor(vault, 'github', services(await gateway.available())))
+ expect(() => flows.deliver(flow, 'http://127.0.0.1:51789/callback?code=x&state=y')).toThrow('on its own')
+ })
+
it('a grant the gateway no longer holds asks for connecting again; a lapsed Harness sign-in says so', async () => {
const fake = await signedIn()
const due = { access_token: 'gho-old', refresh: true, source: 'gateway' as const, expires_at: Math.floor(Date.now() / 1000) + 60 }
diff --git a/cli/src/lib/connectors/generated/page.ts b/cli/src/lib/connectors/generated/page.ts
index f1d47060a..6eaf61aaa 100644
--- a/cli/src/lib/connectors/generated/page.ts
+++ b/cli/src/lib/connectors/generated/page.ts
@@ -1,7 +1,7 @@
// Generated by scripts/connector-assets.mjs from src/lib/connectors/assets. Do not edit.
/** The Connectors page's files, served by page.ts. */
export const PAGE_FILES: Record<string, string> = {
- "index.html": "<!doctype html>\n<html lang=\"en\">\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Connectors · Harness</title>\n<link rel=\"stylesheet\" href=\"/style.css\">\n<script src=\"/page.js\" defer></script>\n<body>\n<main>\n <header>\n <h1>Connectors</h1>\n <p class=\"intro\">Connect your agents to tools outside this computer: a tracker, a design tool, a web service.</p>\n </header>\n <div class=\"toolbar\">\n <input id=\"search\" type=\"search\" placeholder=\"Search connectors\" autocomplete=\"off\" spellcheck=\"false\" aria-label=\"Search connectors\">\n <button id=\"reload\" class=\"icon\" type=\"button\" title=\"Refresh\" aria-label=\"Refresh\">↻</button>\n <button id=\"add\" class=\"primary\" type=\"button\">+ Add custom</button>\n </div>\n <div class=\"pills\" role=\"tablist\">\n <button id=\"browse\" class=\"pill selected\" type=\"button\" role=\"tab\" aria-selected=\"true\">Browse</button>\n <button id=\"connected\" class=\"pill\" type=\"button\" role=\"tab\" aria-selected=\"false\">Connected</button>\n </div>\n <p id=\"signed-out\" class=\"hint-line\" hidden>GitHub, Slack, Google and a few more sign in through your Harness account. Run <code>harness login</code>, then refresh to connect them.</p>\n <p id=\"notice\" role=\"status\" aria-live=\"polite\"></p>\n <div id=\"sections\"><p class=\"empty\">Loading connectors…</p></div>\n <footer>Accounts stay on this computer and are shared by every agent you run here. Disconnecting stops Harness from using an account; revoke it in the service's settings to remove it everywhere.</footer>\n</main>\n<dialog id=\"custom-dialog\">\n <form id=\"custom-form\">\n <h2>Add custom</h2>\n <p>A remote MCP server. If it asks you to sign in, Harness opens the service's sign-in page.</p>\n <label for=\"custom-name\">Name</label>\n <input id=\"custom-name\" required maxlength=\"64\" autocomplete=\"off\" spellcheck=\"false\">\n <label for=\"custom-url\">Remote MCP server URL</label>\n <input id=\"custom-url\" type=\"url\" required maxlength=\"2048\" placeholder=\"https://example.com/mcp\" autocomplete=\"off\" spellcheck=\"false\">\n <details>\n <summary>Advanced</summary>\n <label for=\"custom-headers\">Headers (Name: value, one per line)</label>\n <textarea id=\"custom-headers\" rows=\"3\" placeholder=\"Authorization: Bearer …\" spellcheck=\"false\"></textarea>\n </details>\n <p id=\"custom-error\" class=\"error\" role=\"status\" aria-live=\"polite\"></p>\n <div class=\"actions\"><button type=\"button\" id=\"custom-cancel\">Cancel</button><button class=\"primary\" id=\"custom-save\" type=\"submit\">Continue</button></div>\n </form>\n</dialog>\n<dialog id=\"confirm-dialog\">\n <form id=\"confirm-form\">\n <h2 id=\"confirm-title\">Disconnect</h2>\n <p>Agents on this computer stop using this account. To revoke it everywhere, use the service's settings.</p>\n <div class=\"actions\"><button type=\"button\" id=\"confirm-cancel\">Cancel</button><button class=\"danger\" type=\"submit\">Disconnect</button></div>\n </form>\n</dialog>\n</body>\n</html>\n",
- "page.js": "\"use strict\";\nlet key = location.hash.slice(1) || sessionStorage.getItem(\"harness-connections\") || \"\";\nif (key) sessionStorage.setItem(\"harness-connections\", key);\nhistory.replaceState(null, \"\", location.pathname);\nconst $ = (selector) => document.querySelector(selector);\nconst sections = $(\"#sections\");\nconst notice = $(\"#notice\");\nconst search = $(\"#search\");\nlet items = [];\nlet view = \"browse\";\nconst pending = new Map(); // connector -> flow id\n\nasync function request(path, body) {\n const response = await fetch(path, {\n method: body ? \"POST\" : \"GET\",\n headers: {\"X-Harness-Connections\": key, ...(body ? {\"Content-Type\": \"application/json\"} : {})},\n ...(body ? {body: JSON.stringify(body)} : {})\n });\n const result = await response.json();\n if (!response.ok) throw new Error(result.error || \"Could not update this connection.\");\n return result;\n}\nfunction node(tag, text, className) {\n const element = document.createElement(tag);\n if (text) element.textContent = text;\n if (className) element.className = className;\n return element;\n}\nfunction mark(item) {\n if (item.icon) {\n const image = node(\"img\", \"\", \"mark logo\");\n image.src = item.icon;\n image.alt = \"\";\n return image;\n }\n const tile = node(\"span\", (item.name || \"?\").trim().charAt(0).toUpperCase(), \"mark\");\n tile.style.background = item.color || \"#59634b\";\n return tile;\n}\nfunction card(item) {\n const connected = item.state === \"connected\";\n const box = node(\"article\", \"\", \"card\" + (connected ? \" on\" : \"\"));\n const head = node(\"div\", \"\", \"card-head\");\n head.append(mark(item), node(\"h3\", item.name));\n if (connected) head.append(node(\"span\", item.account || \"Signed in\", \"badge\"));\n if (item.state === \"reconnect\") head.append(node(\"span\", \"Reconnect\", \"badge warn\"));\n const actions = node(\"div\", \"\", \"card-actions\");\n const waiting = pending.has(item.connector);\n if (waiting) {\n actions.append(node(\"span\", \"Waiting for sign-in…\", \"hint\"));\n } else if (item.state !== \"not_connected\") {\n if (item.state === \"reconnect\" && !item.custom) actions.append(button(\"Reconnect\", () => connect(item)));\n actions.append(button(\"×\", () => confirmDisconnect(item), \"icon\", \"Disconnect \" + item.name));\n } else if (item.reason) {\n // Signs in through the Harness account: shown, but not yet connectable.\n actions.append(node(\"span\", item.reason, \"hint\"));\n const add = button(\"+\", () => {}, \"icon plus\", item.reason);\n add.disabled = true;\n actions.append(add);\n } else {\n actions.append(button(\"+\", () => connect(item), \"icon plus\", \"Connect \" + item.name));\n }\n head.append(actions);\n box.append(head);\n const about = connected && !item.tools ? item.description + \" Agents use it with harness connections call.\" : item.description;\n box.append(node(\"p\", about, \"about\"));\n return box;\n}\nfunction button(text, action, className, label) {\n const element = node(\"button\", text, className);\n element.type = \"button\";\n if (label) {element.title = label; element.setAttribute(\"aria-label\", label);}\n element.addEventListener(\"click\", action);\n return element;\n}\nfunction render() {\n const query = search.value.trim().toLowerCase();\n const match = (item) => !query || (item.name + \" \" + item.description).toLowerCase().includes(query);\n const on = items.filter((item) => item.state !== \"not_connected\" && match(item));\n const off = items.filter((item) => item.state === \"not_connected\" && match(item));\n sections.replaceChildren();\n const group = (title, list, empty) => {\n const section = node(\"section\", \"\", \"group\");\n const heading = node(\"h2\", title + \" \");\n heading.append(node(\"span\", String(list.length), \"count\"));\n section.append(heading);\n const grid = node(\"div\", \"\", \"grid\");\n for (const item of list) grid.append(card(item));\n if (!list.length) grid.append(node(\"p\", empty, \"empty\"));\n section.append(grid);\n sections.append(section);\n };\n group(\"Connected\", on, query ? \"No connected service matches.\" : \"Nothing connected yet. Choose a service below.\");\n if (view === \"browse\") group(\"Available\", off, \"No service matches.\");\n}\nasync function refresh() {\n const result = await request(\"/api/connections\");\n items = result.connections.sort((a, b) => a.name.localeCompare(b.name));\n $(\"#signed-out\").hidden = result.signed_in;\n render();\n}\nasync function follow(item, flow) {\n pending.set(item.connector, flow);\n render();\n try {\n for (;;) {\n await new Promise((done) => setTimeout(done, 1000));\n const status = await request(\"/api/flows/\" + flow);\n if (status.state === \"connected\") {notice.textContent = item.name + \" connected. Your agents can use it now.\"; break;}\n if (status.state === \"failed\") {notice.textContent = item.name + \": \" + status.error; break;}\n }\n } catch (e) {notice.textContent = e.message;}\n pending.delete(item.connector);\n await refresh().catch((e) => {notice.textContent = e.message;});\n}\nfunction blankTab() {\n const tab = window.open(\"about:blank\", \"_blank\");\n // The service's page must not be able to reach back into this one.\n if (tab) tab.opener = null;\n return tab;\n}\nasync function connect(item) {\n notice.textContent = \"\";\n // Open the tab inside the click, so the browser allows it; the address follows.\n const tab = blankTab();\n try {\n const result = await request(\"/api/connect\", {connector: item.connector});\n if (result.authorize_url && tab) tab.location.href = result.authorize_url;\n else if (tab) tab.close();\n if (result.authorize_url && !tab) notice.textContent = \"Allow pop-ups for this page to sign in to \" + item.name + \".\";\n await follow(item, result.flow);\n } catch (e) {\n if (tab) tab.close();\n notice.textContent = item.name + \": \" + e.message;\n }\n}\nlet disconnecting = null;\nfunction confirmDisconnect(item) {\n disconnecting = item;\n $(\"#confirm-title\").textContent = \"Disconnect \" + item.name + \"?\";\n $(\"#confirm-dialog\").showModal();\n}\n$(\"#confirm-cancel\").addEventListener(\"click\", () => $(\"#confirm-dialog\").close());\n$(\"#confirm-form\").addEventListener(\"submit\", async (event) => {\n event.preventDefault();\n $(\"#confirm-dialog\").close();\n const item = disconnecting;\n try {\n await request(\"/api/disconnect\", {connector: item.connector});\n notice.textContent = item.name + \" disconnected on this computer.\";\n await refresh();\n } catch (e) {notice.textContent = e.message;}\n});\nfunction headers(text) {\n const result = {};\n for (const line of text.split(\"\\n\").map((l) => l.trim()).filter(Boolean)) {\n const at = line.indexOf(\":\");\n if (at < 1) throw new Error(\"Write each header as Name: value.\");\n result[line.slice(0, at).trim()] = line.slice(at + 1).trim();\n }\n return result;\n}\n$(\"#add\").addEventListener(\"click\", () => {\n $(\"#custom-form\").reset();\n $(\"#custom-error\").textContent = \"\";\n $(\"#custom-dialog\").showModal();\n $(\"#custom-name\").focus();\n});\n$(\"#custom-cancel\").addEventListener(\"click\", () => $(\"#custom-dialog\").close());\n$(\"#custom-form\").addEventListener(\"submit\", async (event) => {\n event.preventDefault();\n const save = $(\"#custom-save\");\n const name = $(\"#custom-name\").value.trim();\n let extra;\n try {extra = headers($(\"#custom-headers\").value);} catch (e) {$(\"#custom-error\").textContent = e.message; return;}\n const tab = Object.keys(extra).length ? null : blankTab();\n save.disabled = true;\n try {\n const result = await request(\"/api/custom\", {name, url: $(\"#custom-url\").value.trim(), headers: extra});\n $(\"#custom-dialog\").close();\n if (result.flow) {\n if (result.authorize_url && tab) tab.location.href = result.authorize_url;\n else if (tab) tab.close();\n await follow({connector: \"custom:\" + name, name}, result.flow);\n } else {\n if (tab) tab.close();\n notice.textContent = name + \" added. Your agents can use it now.\";\n await refresh();\n }\n } catch (e) {\n if (tab) tab.close();\n $(\"#custom-error\").textContent = e.message;\n } finally {save.disabled = false;}\n});\nfunction show(next) {\n view = next;\n for (const id of [\"browse\", \"connected\"]) {\n $(\"#\" + id).classList.toggle(\"selected\", id === next);\n $(\"#\" + id).setAttribute(\"aria-selected\", String(id === next));\n }\n render();\n}\n$(\"#browse\").addEventListener(\"click\", () => show(\"browse\"));\n$(\"#connected\").addEventListener(\"click\", () => show(\"connected\"));\n$(\"#reload\").addEventListener(\"click\", () => refresh().catch((e) => {notice.textContent = e.message;}));\nsearch.addEventListener(\"input\", render);\nif (!key) notice.textContent = \"Open “harness connections” from the terminal to manage your accounts.\";\nelse refresh().catch((e) => {notice.textContent = e.message;});\n",
+ "index.html": "<!doctype html>\n<html lang=\"en\">\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Connectors · Harness</title>\n<link rel=\"stylesheet\" href=\"/style.css\">\n<script src=\"/page.js\" defer></script>\n<body>\n<main>\n <header>\n <h1>Connectors</h1>\n <p class=\"intro\">Connect your agents to tools outside this computer: a tracker, a design tool, a web service.</p>\n </header>\n <div class=\"toolbar\">\n <input id=\"search\" type=\"search\" placeholder=\"Search connectors\" autocomplete=\"off\" spellcheck=\"false\" aria-label=\"Search connectors\">\n <button id=\"reload\" class=\"icon\" type=\"button\" title=\"Refresh\" aria-label=\"Refresh\">↻</button>\n <button id=\"add\" class=\"primary\" type=\"button\">+ Add custom</button>\n </div>\n <div class=\"pills\" role=\"tablist\">\n <button id=\"browse\" class=\"pill selected\" type=\"button\" role=\"tab\" aria-selected=\"true\">Browse</button>\n <button id=\"connected\" class=\"pill\" type=\"button\" role=\"tab\" aria-selected=\"false\">Connected</button>\n </div>\n <p id=\"signed-out\" class=\"hint-line\" hidden>GitHub, Slack, Google and a few more sign in through your Harness account. Run <code>harness login</code>, then refresh to connect them.</p>\n <p id=\"notice\" role=\"status\" aria-live=\"polite\"></p>\n <div id=\"sections\"><p class=\"empty\">Loading connectors…</p></div>\n <footer>Accounts are shared by every agent you run, on every computer signed in to your Harness account. Disconnecting stops Harness from using an account; revoke it in the service's settings to remove it at the service too.</footer>\n</main>\n<dialog id=\"custom-dialog\">\n <form id=\"custom-form\">\n <h2>Add custom</h2>\n <p>A remote MCP server. If it asks you to sign in, Harness opens the service's sign-in page.</p>\n <label for=\"custom-name\">Name</label>\n <input id=\"custom-name\" required maxlength=\"64\" autocomplete=\"off\" spellcheck=\"false\">\n <label for=\"custom-url\">Remote MCP server URL</label>\n <input id=\"custom-url\" type=\"url\" required maxlength=\"2048\" placeholder=\"https://example.com/mcp\" autocomplete=\"off\" spellcheck=\"false\">\n <details>\n <summary>Advanced</summary>\n <label for=\"custom-headers\">Headers (Name: value, one per line)</label>\n <textarea id=\"custom-headers\" rows=\"3\" placeholder=\"Authorization: Bearer …\" spellcheck=\"false\"></textarea>\n </details>\n <p id=\"custom-error\" class=\"error\" role=\"status\" aria-live=\"polite\"></p>\n <div class=\"actions\"><button type=\"button\" id=\"custom-cancel\">Cancel</button><button class=\"primary\" id=\"custom-save\" type=\"submit\">Continue</button></div>\n </form>\n</dialog>\n<dialog id=\"confirm-dialog\">\n <form id=\"confirm-form\">\n <h2 id=\"confirm-title\">Disconnect</h2>\n <p>Agents on this computer stop using this account. To revoke it everywhere, use the service's settings.</p>\n <div class=\"actions\"><button type=\"button\" id=\"confirm-cancel\">Cancel</button><button class=\"danger\" type=\"submit\">Disconnect</button></div>\n </form>\n</dialog>\n</body>\n</html>\n",
+ "page.js": "\"use strict\";\nlet key = location.hash.slice(1) || sessionStorage.getItem(\"harness-connections\") || \"\";\nif (key) sessionStorage.setItem(\"harness-connections\", key);\nhistory.replaceState(null, \"\", location.pathname);\nconst $ = (selector) => document.querySelector(selector);\nconst sections = $(\"#sections\");\nconst notice = $(\"#notice\");\nconst search = $(\"#search\");\nlet items = [];\nlet view = \"browse\";\nconst pending = new Map(); // connector -> flow id\nlet noticeTimer = 0;\n// A notice goes away on its own, so a disconnect from earlier does not stand there for good.\nfunction say(text) {\n notice.textContent = text;\n clearTimeout(noticeTimer);\n if (text) noticeTimer = setTimeout(() => {notice.textContent = \"\";}, 20000);\n}\n\nasync function request(path, body) {\n const response = await fetch(path, {\n method: body ? \"POST\" : \"GET\",\n headers: {\"X-Harness-Connections\": key, ...(body ? {\"Content-Type\": \"application/json\"} : {})},\n ...(body ? {body: JSON.stringify(body)} : {})\n });\n const result = await response.json();\n if (!response.ok) throw new Error(result.error || \"Could not update this connection.\");\n return result;\n}\nfunction node(tag, text, className) {\n const element = document.createElement(tag);\n if (text) element.textContent = text;\n if (className) element.className = className;\n return element;\n}\nfunction mark(item) {\n if (item.icon) {\n const image = node(\"img\", \"\", \"mark logo\");\n image.src = item.icon;\n image.alt = \"\";\n return image;\n }\n const tile = node(\"span\", (item.name || \"?\").trim().charAt(0).toUpperCase(), \"mark\");\n tile.style.background = item.color || \"#59634b\";\n return tile;\n}\nfunction card(item) {\n const connected = item.state === \"connected\";\n const box = node(\"article\", \"\", \"card\" + (connected ? \" on\" : \"\"));\n const head = node(\"div\", \"\", \"card-head\");\n head.append(mark(item), node(\"h3\", item.name));\n if (connected) head.append(node(\"span\", item.account || \"Signed in\", \"badge\"));\n if (item.state === \"reconnect\") head.append(node(\"span\", \"Reconnect\", \"badge warn\"));\n const actions = node(\"div\", \"\", \"card-actions\");\n const waiting = pending.has(item.connector);\n if (waiting) {\n actions.append(node(\"span\", \"Waiting for sign-in…\", \"hint\"));\n } else if (item.state !== \"not_connected\") {\n if (item.state === \"reconnect\" && !item.custom) actions.append(button(\"Reconnect\", () => connect(item)));\n actions.append(button(\"×\", () => confirmDisconnect(item), \"icon\", \"Disconnect \" + item.name));\n } else if (item.reason) {\n // Signs in through the Harness account: shown, but not yet connectable.\n actions.append(node(\"span\", item.reason, \"hint\"));\n const add = button(\"+\", () => {}, \"icon plus\", item.reason);\n add.disabled = true;\n actions.append(add);\n } else {\n actions.append(button(\"+\", () => connect(item), \"icon plus\", \"Connect \" + item.name));\n }\n head.append(actions);\n box.append(head);\n const about = connected && !item.tools ? item.description + \" Agents use it with harness connections call.\" : item.description;\n box.append(node(\"p\", about, \"about\"));\n return box;\n}\nfunction button(text, action, className, label) {\n const element = node(\"button\", text, className);\n element.type = \"button\";\n if (label) {element.title = label; element.setAttribute(\"aria-label\", label);}\n element.addEventListener(\"click\", action);\n return element;\n}\nfunction render() {\n const query = search.value.trim().toLowerCase();\n const match = (item) => !query || (item.name + \" \" + item.description).toLowerCase().includes(query);\n const on = items.filter((item) => item.state !== \"not_connected\" && match(item));\n const off = items.filter((item) => item.state === \"not_connected\" && match(item));\n sections.replaceChildren();\n const group = (title, list, empty) => {\n const section = node(\"section\", \"\", \"group\");\n const heading = node(\"h2\", title + \" \");\n heading.append(node(\"span\", String(list.length), \"count\"));\n section.append(heading);\n const grid = node(\"div\", \"\", \"grid\");\n for (const item of list) grid.append(card(item));\n if (!list.length) grid.append(node(\"p\", empty, \"empty\"));\n section.append(grid);\n sections.append(section);\n };\n group(\"Connected\", on, query ? \"No connected service matches.\" : \"Nothing connected yet. Choose a service below.\");\n if (view === \"browse\") group(\"Available\", off, \"No service matches.\");\n}\nasync function refresh() {\n const result = await request(\"/api/connections\");\n items = result.connections.sort((a, b) => a.name.localeCompare(b.name));\n $(\"#signed-out\").hidden = result.signed_in;\n render();\n}\nasync function follow(item, flow) {\n pending.set(item.connector, flow);\n render();\n try {\n for (;;) {\n await new Promise((done) => setTimeout(done, 1000));\n const status = await request(\"/api/flows/\" + flow);\n if (status.state === \"connected\") {say(item.name + \" connected. Your agents can use it now.\"); break;}\n if (status.state === \"failed\") {say(item.name + \": \" + status.error); break;}\n }\n } catch (e) {say(e.message);}\n pending.delete(item.connector);\n await refresh().catch((e) => {say(e.message);});\n}\nfunction blankTab() {\n const tab = window.open(\"about:blank\", \"_blank\");\n // The service's page must not be able to reach back into this one.\n if (tab) tab.opener = null;\n return tab;\n}\nasync function connect(item) {\n say(\"\");\n // Open the tab inside the click, so the browser allows it; the address follows.\n const tab = blankTab();\n try {\n const result = await request(\"/api/connect\", {connector: item.connector});\n if (result.authorize_url && tab) tab.location.href = result.authorize_url;\n else if (tab) tab.close();\n if (result.authorize_url && !tab) say(\"Allow pop-ups for this page to sign in to \" + item.name + \".\");\n await follow(item, result.flow);\n } catch (e) {\n if (tab) tab.close();\n say(item.name + \": \" + e.message);\n }\n}\nlet disconnecting = null;\nfunction confirmDisconnect(item) {\n disconnecting = item;\n $(\"#confirm-title\").textContent = \"Disconnect \" + item.name + \"?\";\n $(\"#confirm-dialog\").showModal();\n}\n$(\"#confirm-cancel\").addEventListener(\"click\", () => $(\"#confirm-dialog\").close());\n$(\"#confirm-form\").addEventListener(\"submit\", async (event) => {\n event.preventDefault();\n $(\"#confirm-dialog\").close();\n const item = disconnecting;\n try {\n await request(\"/api/disconnect\", {connector: item.connector});\n say(item.name + \" disconnected.\");\n await refresh();\n } catch (e) {say(e.message);}\n});\nfunction headers(text) {\n const result = {};\n for (const line of text.split(\"\\n\").map((l) => l.trim()).filter(Boolean)) {\n const at = line.indexOf(\":\");\n if (at < 1) throw new Error(\"Write each header as Name: value.\");\n result[line.slice(0, at).trim()] = line.slice(at + 1).trim();\n }\n return result;\n}\n$(\"#add\").addEventListener(\"click\", () => {\n $(\"#custom-form\").reset();\n $(\"#custom-error\").textContent = \"\";\n $(\"#custom-dialog\").showModal();\n $(\"#custom-name\").focus();\n});\n$(\"#custom-cancel\").addEventListener(\"click\", () => $(\"#custom-dialog\").close());\n$(\"#custom-form\").addEventListener(\"submit\", async (event) => {\n event.preventDefault();\n const save = $(\"#custom-save\");\n const name = $(\"#custom-name\").value.trim();\n let extra;\n try {extra = headers($(\"#custom-headers\").value);} catch (e) {$(\"#custom-error\").textContent = e.message; return;}\n const tab = Object.keys(extra).length ? null : blankTab();\n save.disabled = true;\n try {\n const result = await request(\"/api/custom\", {name, url: $(\"#custom-url\").value.trim(), headers: extra});\n $(\"#custom-dialog\").close();\n if (result.flow) {\n if (result.authorize_url && tab) tab.location.href = result.authorize_url;\n else if (tab) tab.close();\n await follow({connector: \"custom:\" + name, name}, result.flow);\n } else {\n if (tab) tab.close();\n say(name + \" added. Your agents can use it now.\");\n await refresh();\n }\n } catch (e) {\n if (tab) tab.close();\n $(\"#custom-error\").textContent = e.message;\n } finally {save.disabled = false;}\n});\nfunction show(next) {\n view = next;\n for (const id of [\"browse\", \"connected\"]) {\n $(\"#\" + id).classList.toggle(\"selected\", id === next);\n $(\"#\" + id).setAttribute(\"aria-selected\", String(id === next));\n }\n render();\n}\n$(\"#browse\").addEventListener(\"click\", () => show(\"browse\"));\n$(\"#connected\").addEventListener(\"click\", () => show(\"connected\"));\n$(\"#reload\").addEventListener(\"click\", () => refresh().catch((e) => {say(e.message);}));\nsearch.addEventListener(\"input\", render);\nif (!key) say(\"Open “harness connections” from the terminal to manage your accounts.\");\nelse refresh().catch((e) => {say(e.message);});\n",
"style.css": ":root{color-scheme:dark;font:15px/1.5 ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",sans-serif;color:#e8e8e8;background:#141414}\n*{box-sizing:border-box}\nbody{margin:0}\nmain{max-width:1240px;margin:auto;padding:28px 24px 48px}\nheader{border-bottom:1px solid #2a2a2a;padding-bottom:14px;margin-bottom:18px}\nh1{font-size:26px;font-weight:700;margin:0 0 4px}.intro{margin:0;color:#a3a3a3}\n.toolbar{display:flex;gap:10px;align-items:center}\n#search{flex:1;min-width:0;height:38px;padding:0 14px;background:#1f1f1f;border:1px solid #2a2a2a;border-radius:8px;color:inherit;font:inherit}\nbutton,input,textarea{font:inherit}\nbutton{min-height:36px;border-radius:8px;border:1px solid #333;background:#1f1f1f;color:inherit;padding:6px 14px;cursor:pointer;white-space:nowrap}\nbutton:hover{border-color:#5b6bff}button:disabled{opacity:.5;cursor:wait}\n.plus:disabled{opacity:.35;cursor:not-allowed;border-color:#1d2450}\nbutton:focus-visible,input:focus-visible,textarea:focus-visible,summary:focus-visible{outline:2px solid #6b7bff;outline-offset:2px}\n.primary{background:#2f45d8;border-color:#3d55ff;color:#fff;font-weight:600}.primary:hover{background:#3a51ea}\n.danger{background:#5c1f1f;border-color:#8a2c2c;color:#fff}\n.icon{min-width:36px;padding:4px 10px}\n.pills{display:flex;gap:8px;margin:16px 0 4px}\n.pill{border-radius:8px;background:#1f1f1f;border-color:#1f1f1f;color:#bdbdbd;font-weight:600}\n.pill.selected{background:#2f45d8;border-color:#3d55ff;color:#fff}\n#notice{min-height:22px;color:#9fe0a8;margin:10px 0}\n.hint-line{margin:14px 0 0;color:#a3a3a3;font-size:14px}.hint-line code{color:#e8e8e8}\n.group h2{font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:#a3a3a3;margin:18px 0 10px}\n.count{color:#6f6f6f;margin-left:4px}\n.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:12px}\n.card{background:#1f1f1f;border:1px solid #262626;border-radius:12px;padding:16px;min-height:118px}\n.card.on{border-color:#2d3a2d}\n.card-head{display:flex;align-items:center;gap:10px}\n.card-head h3{font-size:16px;margin:0;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.mark{flex:none;width:26px;height:26px;border-radius:6px;display:grid;place-items:center;color:#fff;font-weight:800;font-size:14px}\n.logo{object-fit:contain;background:#2a2a2a;padding:2px}\n.badge{font-size:12px;color:#9fb0ff;background:#1d2450;border-radius:6px;padding:1px 8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:160px}\n.badge.warn{color:#ffd28a;background:#4a3511}\n.card-actions{margin-left:auto;display:flex;gap:6px;align-items:center}\n.plus{color:#8fa0ff;background:#1d2450;border-color:#1d2450;font-size:18px;line-height:1}\n.hint{font-size:12px;color:#8a8a8a;text-align:right}\n.about{margin:12px 0 0;color:#bdbdbd;font-size:14px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}\n.empty{color:#8a8a8a;margin:0}\nfooter{color:#7a7a7a;font-size:13px;border-top:1px solid #2a2a2a;margin-top:28px;padding-top:16px}\ndialog{width:min(520px,calc(100% - 32px));border:1px solid #333;border-radius:12px;background:#1b1b1b;color:inherit;padding:24px}\ndialog::backdrop{background:#000b}dialog h2{margin:0 0 6px;font-size:20px}dialog p{font-size:14px;color:#a3a3a3;margin:0}\nlabel{display:block;margin:16px 0 6px;font-size:14px}\ndialog input,textarea{width:100%;padding:10px 12px;background:#141414;color:inherit;border:1px solid #333;border-radius:8px}\ndetails{margin-top:14px}summary{cursor:pointer;color:#a3a3a3;font-size:14px}\n.actions{display:flex;justify-content:flex-end;gap:10px;margin-top:20px}.error{color:#f1ac95;min-height:22px;margin-top:10px}\n@media(max-width:560px){main{padding:20px 16px}.toolbar{flex-wrap:wrap}#search{flex-basis:100%}.grid{grid-template-columns:1fr}}\n"
}
diff --git a/cli/src/lib/connectors/oauth.ts b/cli/src/lib/connectors/oauth.ts
index 61ba99e45..0192cebee 100644
--- a/cli/src/lib/connectors/oauth.ts
+++ b/cli/src/lib/connectors/oauth.ts
@@ -119,6 +119,15 @@ class Callback {
})
}
get redirectUri(): string { return `http://127.0.0.1:${this.port}/callback` }
+ /** The same redirect, read by another device whose browser was sent to it (a phone, over the relay). */
+ deliver(address: string): void {
+ let url: URL
+ try { url = new URL(address) } catch { throw new SignInError('This is not the sign-in address.') }
+ if (url.origin + url.pathname !== this.redirectUri) throw new SignInError('This is not the sign-in address.')
+ if (this.result) return
+ this.result = Object.fromEntries(url.searchParams)
+ this.done()
+ }
close(): void { this.server.close(); this.server.closeAllConnections?.() }
}
@@ -197,6 +206,8 @@ export interface SignIn {
/** The address to open in a browser, or null when the server needs no sign-in. */
prepare(): Promise<string | null>
wait(cancelled?: () => boolean): Promise<Token>
+ /** The browser's redirect, when it reached another device instead of this computer. */
+ deliver?(url: string): void
}
/** One browser sign-in to an MCP server: prepare() gives the address to open, wait() the token. */
@@ -225,6 +236,16 @@ export class LocalSignIn implements SignIn {
return endpoint + (endpoint.includes('?') ? '&' : '?') + query.toString()
}
+ /**
+ * A phone that opened the sign-in in its own browser caught the redirect to this computer's
+ * 127.0.0.1 address and sent it here. Only that exact address counts; wait() then checks state
+ * and exchanges the code with the PKCE verifier, which never leaves this computer.
+ */
+ deliver(url: string): void {
+ if (!this.callback) throw new SignInError('This sign-in needs no address.')
+ this.callback.deliver(url)
+ }
+
async wait(cancelled: () => boolean = () => false): Promise<Token> {
if (!this.callback || this.meta?.kind !== 'oauth') {
return { mcp_entry: { url: this.mcpUrl, headers: {} }, source: 'dcr', obtained_at: Math.floor(Date.now() / 1000) }
diff --git a/cli/src/services/connectors.spec.ts b/cli/src/services/connectors.spec.ts
index 485990126..154044dae 100644
--- a/cli/src/services/connectors.spec.ts
+++ b/cli/src/services/connectors.spec.ts
@@ -29,7 +29,10 @@ describe('the connectors service', () => {
expect(Object.keys(requests)).toEqual([...CONNECTORS_REQUESTS])
expect(await requests.connectors!({ action: 'list' }, { local: false, owner: false })).toEqual({ error: 'OWNER_REQUIRED' })
// Signed out, the gateway's list is empty and nothing reaches the network.
- expect(await requests.connectors!({ action: 'list' }, OWNER)).toMatchObject({ signed_in: false })
+ // The core is signed in to the account, so a connection made here is shared with its computers.
+ expect(await requests.connectors!({ action: 'list' }, OWNER)).toMatchObject({ signed_in: false, shared: true })
+ expect(await startConnectors(fakeCore(), { env, vaultPort: null }).connectors!({ action: 'list' }, OWNER))
+ .toMatchObject({ shared: false })
})
it('keeps the connections the account\'s when signed in: reads them now and again at each notice that may change them', async () => {
@@ -76,6 +79,10 @@ describe('the connectors service', () => {
expect(await requests.connectors!({ action: 'connect', connector: 'github' }, OWNER)).toMatchObject({ error: 'CONNECTORS_FAILED', detail: expect.stringContaining('harness login') })
expect(await requests.connectors!({ action: 'flow', flow: 'gone' }, OWNER)).toMatchObject({ error: 'CONNECTORS_FAILED', detail: expect.stringContaining('ended') })
expect(await requests.connectors!({ action: 'flow' }, OWNER)).toMatchObject({ error: 'CONNECTORS_FAILED' })
+ // A phone's caught redirect for a sign-in this computer no longer holds is refused, never followed.
+ expect(await requests.connectors!({ action: 'callback', flow: 'gone', url: 'http://127.0.0.1:51789/callback?code=x' }, OWNER))
+ .toMatchObject({ error: 'CONNECTORS_FAILED', detail: expect.stringContaining('ended') })
+ expect(await requests.connectors!({ action: 'callback' }, OWNER)).toMatchObject({ error: 'CONNECTORS_FAILED' })
expect(await requests.connectors!({ action: 'nope' }, OWNER)).toEqual({ error: 'CONNECTORS_FAILED', detail: 'Unknown action.' })
expect(await requests.connectors!({ action: 'custom', name: 'Mine', url: 'https://mine.example/mcp', headers: { Authorization: 'Bearer pat' } }, OWNER))
.toEqual({ connector: 'mine', state: 'connected' })
diff --git a/cli/src/services/connectors.ts b/cli/src/services/connectors.ts
index c86351aac..343410b74 100644
--- a/cli/src/services/connectors.ts
+++ b/cli/src/services/connectors.ts
@@ -4,8 +4,11 @@
* again as it starts, so an agent installed since a service was connected gets it too.
*
* `connectors` takes `{action}`: `list`, `connect` {connector}, `flow` {flow}, `disconnect` {connector},
- * `custom` {name, url, headers}. The app opens a returned `authorize_url` in the browser and follows the
- * flow. Never a token in a reply. Owner only, and end-to-end encrypted like `api_connections`.
+ * `custom` {name, url, headers}, `callback` {flow, url}. The app opens a returned `authorize_url` in the
+ * browser and follows the flow. A phone signing in for this computer opens it in its own browser and,
+ * for a service this computer signs in to itself, sends back the redirect to 127.0.0.1 it caught as
+ * `callback`: the code alone is useless without the PKCE verifier kept here. Never a token in a reply.
+ * Owner only, and end-to-end encrypted like `api_connections`.
*
* The connections are the account's: kept the same on every computer through the backend, sealed for the
* account's machines (lib/connectors/vaultSync.ts).
@@ -79,7 +82,9 @@ export function startConnectors(core: CoreApi, overrides: Partial<ConnectorsDeps
const answer = async (payload: Record<string, unknown>): Promise<Record<string, unknown>> => {
switch (payload.action) {
- case 'list': return { ...cards(vault, await gatewayOffers()) }
+ // `shared`: a connection made here reaches the account's other computers. The phone signs in
+ // through one that says so before one that keeps it to itself (an older CLI says nothing).
+ case 'list': return { ...cards(vault, await gatewayOffers()), shared: deps.vaultPort !== null }
case 'connect': {
const code = validateCode(payload.connector)
return { ...(await flows.start(code, signInFor(vault, code, services(await gatewayOffers())))) }
@@ -96,6 +101,7 @@ export function startConnectors(core: CoreApi, overrides: Partial<ConnectorsDeps
return { connector: code, state: 'not_connected' }
}
case 'custom': return addCustom(vault, flows, payload, env)
+ case 'callback': return { ...flows.deliver(String(payload.flow ?? ''), String(payload.url ?? '')) }
default: return { error: 'CONNECTORS_FAILED', detail: 'Unknown action.' }
}
}
diff --git a/desktop/lib/connectors/connectors_controller.dart b/desktop/lib/connectors/connectors_controller.dart
index cc417f46a..bbfc0ee20 100644
--- a/desktop/lib/connectors/connectors_controller.dart
+++ b/desktop/lib/connectors/connectors_controller.dart
@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
+import '../core/models.dart' show Agent;
import '../core/open_in_browser.dart';
import '../state/app_state.dart';
@@ -74,10 +75,50 @@ class ConnectorsController extends ChangeNotifier {
bool signedIn = true;
bool loading = false;
String? error;
- String notice = '';
final Set<String> pending = {};
bool _disposed = false;
+ /// Whether a connection made here reaches the account's other computers (`list` `shared`).
+ bool shared = false;
+
+ /// What the last action came to. It goes away on its own: Settings keeps this page alive, and a
+ /// "disconnected" from days ago was still standing there.
+ String get notice => _notice;
+ set notice(String text) {
+ _notice = text;
+ _noticeTimer?.cancel();
+ if (text.isEmpty) return;
+ _noticeTimer = Timer(noticeFor, () {
+ _notice = '';
+ _changed();
+ });
+ }
+
+ String _notice = '';
+ Timer? _noticeTimer;
+ @visibleForTesting
+ static Duration noticeFor = const Duration(seconds: 20);
+
+ /// The engines Harness gives connections to as MCP servers (cli/src/lib/connectors/agents.ts).
+ static const mcpEngines = {'claude', 'codex', 'opencode'};
+
+ /// The harness in the focused pane, when it is running on an engine that reads its tools at start
+ /// and is this account's to restart (a shared machine's is view-only).
+ ({String machineId, Agent agent})? get focusedRestartable {
+ final pane = app.focusedPane;
+ final agentId = pane?.agentId;
+ if (pane == null || agentId == null) return null;
+ final machine = app.stateOf(pane.machineId);
+ if (machine == null || machine.machine.isShared != false) return null;
+ final agent = machine.agents.where((a) => a.id == agentId).firstOrNull;
+ if (agent == null ||
+ agent.isStopped ||
+ !mcpEngines.contains(agent.engine)) {
+ return null;
+ }
+ return (machineId: pane.machineId, agent: agent);
+ }
+
String? get _target => machineId ?? app.localMachineState?.machine.machineId;
Future<Map<String, dynamic>> _ask(Map<String, dynamic> payload) async {
@@ -110,6 +151,7 @@ class ConnectorsController extends ChangeNotifier {
if (row is Map) ConnectorCard.fromJson(row.cast<String, dynamic>()),
]..sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
signedIn = answer['signed_in'] != false;
+ shared = answer['shared'] == true;
error = null;
} catch (e) {
error = _message(e);
@@ -179,7 +221,9 @@ class ConnectorsController extends ChangeNotifier {
Future<void> disconnect(ConnectorCard card) async {
try {
await _ask({'action': 'disconnect', 'connector': card.code});
- notice = '${card.name} disconnected on this computer.';
+ notice = shared
+ ? '${card.name} disconnected on all your computers.'
+ : '${card.name} disconnected on this computer.';
} catch (e) {
notice = _message(e);
}
@@ -226,6 +270,7 @@ class ConnectorsController extends ChangeNotifier {
@override
void dispose() {
_disposed = true;
+ _noticeTimer?.cancel();
super.dispose();
}
}
diff --git a/desktop/lib/settings/sections/connectors_section.dart b/desktop/lib/settings/sections/connectors_section.dart
index 832efe3b0..6d3214f95 100644
--- a/desktop/lib/settings/sections/connectors_section.dart
+++ b/desktop/lib/settings/sections/connectors_section.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@@ -10,6 +12,7 @@ import '../../shared/widgets/app_icon_button.dart';
import '../../shared/widgets/section_scaffold.dart';
import '../../shared/widgets/toolbar_pill.dart';
import '../../state/app_state.dart';
+import '../../widgets/restart_agent_action.dart';
/// Settings ▸ Connectors: connect a service once on this computer, and every
/// local agent (Claude Code, Codex, OpenCode) gets it. The same list and
@@ -132,6 +135,42 @@ class _ConnectorsSectionState extends State<ConnectorsSection> {
),
),
],
+ // Agents read their tools when they start: one already running gets a connection made since
+ // only on a restart. Always here, for the focused pane's harness: Settings closes onto that
+ // pane, and the restart runs there, where it can be watched.
+ if (_controller.focusedRestartable case final target?) ...[
+ const SizedBox(height: 12),
+ Row(
+ children: [
+ Expanded(
+ child: Text(
+ 'Restart "${target.agent.displayName}" to use the new tools from your connectors.',
+ style: theme.textTheme.bodySmall?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant,
+ ),
+ ),
+ ),
+ const SizedBox(width: 12),
+ OutlinedButton.icon(
+ key: const ValueKey('connectors-restart'),
+ icon: const Icon(Icons.restart_alt, size: 16),
+ label: const Text('Restart'),
+ onPressed: () {
+ final navigator = Navigator.of(context);
+ navigator.pop();
+ unawaited(
+ restartHarness(
+ navigator.context,
+ widget.notifier,
+ target.machineId,
+ target.agent.id,
+ ),
+ );
+ },
+ ),
+ ],
+ ),
+ ],
const SizedBox(height: 8),
Expanded(
child: _controller.cards.isEmpty && _controller.loading