@sandbaseai/cli 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,18 +2,21 @@ import { mkdir, readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { spawnSync } from "node:child_process";
5
+ import { existsSync } from "node:fs";
5
6
  import { parse as parseToml } from "smol-toml";
6
7
  import { parseDocument } from "yaml";
7
8
  import { atomicWrite, backup, readOptional, restore } from "../fs-safe.js";
9
+ import { clientProfiles } from "../clients.js";
8
10
  import { configPath, sandbaseHome } from "../paths.js";
9
11
  const defaultIO = { backup, write: atomicWrite, restore };
10
- const executables = { codex: "codex", "claude-code": "claude", cursor: "cursor", hermes: "hermes" };
11
- export function detectClient(client) { const result = spawnSync(executables[client], ["--version"], { encoding: "utf8", timeout: 5000 }); const detail = (result.stdout || result.stderr || "").trim().split("\n")[0] || "not found"; return { installed: result.status === 0, detail }; }
12
+ export function detectClient(client) { const profile = clientProfiles[client]; if (profile.mode !== "auto")
13
+ return { installed: true, detail: "manual setup" }; if (!profile.executable)
14
+ return existsSync(configPath(client)) ? { installed: true, detail: "existing configuration" } : { installed: false, detail: "configuration not found" }; const result = spawnSync(profile.executable, ["--version"], { encoding: "utf8", timeout: 5000 }); const detail = (result.stdout || result.stderr || "").trim().split("\n")[0] || "not found"; return { installed: result.status === 0, detail }; }
12
15
  const start = "# >>> sandbase managed >>>", end = "# <<< sandbase managed <<<";
13
16
  function block(client, bridge) {
14
17
  if (client === "codex")
15
18
  return `${start}\n[mcp_servers.sandbase]\ncommand = "node"\nargs = ["${bridge.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}", "--client", "codex"]\n${end}`;
16
- return ` ${start}\n sandbase:\n command: node\n args:\n - ${JSON.stringify(bridge)}\n - --client\n - hermes\n ${end}`;
19
+ return ` ${start}\n sandbase:\n command: node\n args:\n - ${JSON.stringify(bridge)}\n - --client\n - ${client}\n ${end}`;
17
20
  }
18
21
  function managedText(raw, value) { const re = new RegExp(`${start.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${end.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "m"); return re.test(raw) ? raw.replace(re, value) : raw.replace(/\s*$/, "") + (raw.trim() ? "\n\n" : "") + value + "\n"; }
19
22
  function removeManaged(raw) { return raw.replace(new RegExp(`\\n?[ \\t]*${start.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?[ \\t]*${end.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\n?`, "m"), "\n"); }
@@ -27,7 +30,7 @@ function removeHermesEntry(raw) { const lines = raw.split("\n"); const at = line
27
30
  break;
28
31
  end++;
29
32
  } lines.splice(at, end - at); return lines.join("\n"); }
30
- function hermesUpdate(raw, bridge) { const own = block("hermes", bridge); const cleaned = removeHermesEntry(removeManaged(raw)).replace(/^(mcp_servers:[ \t]*)\n+/m, "$1\n"); if (/^mcp_servers:[ \t]*$/m.test(cleaned))
33
+ function hermesUpdate(raw, bridge, client) { const own = block(client, bridge); const cleaned = removeHermesEntry(removeManaged(raw)).replace(/^(mcp_servers:[ \t]*)\n+/m, "$1\n"); if (/^mcp_servers:[ \t]*$/m.test(cleaned))
31
34
  return cleaned.replace(/^mcp_servers:[ \t]*$/m, match => `${match}\n${own}`); return cleaned.replace(/\s*$/, "") + (cleaned.trim() ? "\n" : "") + `mcp_servers:\n${own}\n`; }
32
35
  function jsonUpdate(raw, client, bridge, remove = false) { const obj = raw ? JSON.parse(raw) : {}; if (!obj || Array.isArray(obj))
33
36
  throw new Error("Client configuration root must be an object"); const servers = obj.mcpServers === undefined ? {} : obj.mcpServers; if (!servers || typeof servers !== "object" || Array.isArray(servers))
@@ -36,12 +39,12 @@ function jsonUpdate(raw, client, bridge, remove = false) { const obj = raw ? JSO
36
39
  else
37
40
  map.sandbase = { command: "node", args: [bridge, "--client", client] }; obj.mcpServers = map; return JSON.stringify(obj, null, 2) + "\n"; }
38
41
  function validateText(client, text) { if (!text.trim())
39
- return; if (client === "codex") {
42
+ return; const adapter = clientProfiles[client].adapter; if (adapter === "codex") {
40
43
  const value = parseToml(text);
41
44
  if (!value || typeof value !== "object" || Array.isArray(value))
42
45
  throw new Error("TOML root must be a table");
43
46
  return;
44
- } if (client === "hermes") {
47
+ } if (adapter === "yaml") {
45
48
  const doc = parseDocument(text, { prettyErrors: false, uniqueKeys: true });
46
49
  if (doc.errors.length)
47
50
  throw doc.errors[0];
@@ -58,10 +61,11 @@ catch (e) {
58
61
  throw e;
59
62
  } return backupPath ? { path: target, backup: backupPath, changed: true } : { path: target, changed: true }; }
60
63
  export async function rollbackBridge(result) { await rollback(result); }
61
- export async function configure(client, bridge, env = process.env, io = defaultIO) { const path = configPath(client, env); const raw = await readOptional(path); let next; try {
64
+ export async function configure(client, bridge, env = process.env, io = defaultIO) { const profile = clientProfiles[client]; if (profile.mode !== "auto" || !profile.adapter)
65
+ return { path: configPath(client, env), changed: false }; const path = configPath(client, env); const raw = await readOptional(path); let next; try {
62
66
  const text = raw || "";
63
67
  validateText(client, text);
64
- next = client === "claude-code" || client === "cursor" ? jsonUpdate(raw, client, bridge) : client === "hermes" ? hermesUpdate(text, bridge) : managedText(text.includes(start) ? text : removeCodexEntry(text), block(client, bridge));
68
+ next = profile.adapter === "json" ? jsonUpdate(raw, client, bridge) : profile.adapter === "yaml" ? hermesUpdate(text, bridge, client) : managedText(text.includes(start) ? text : removeCodexEntry(text), block(client, bridge));
65
69
  validateText(client, next);
66
70
  }
67
71
  catch {
@@ -76,10 +80,11 @@ catch (e) {
76
80
  } return backupPath ? { path, backup: backupPath, changed: true } : { path, changed: true }; }
77
81
  export async function rollback(result) { if (result.changed)
78
82
  await restore(result.path, result.backup); }
79
- export async function unregister(client, env = process.env) { const path = configPath(client, env); const raw = await readOptional(path); if (!raw)
83
+ export async function unregister(client, env = process.env) { const profile = clientProfiles[client]; if (profile.mode !== "auto" || !profile.adapter)
84
+ return false; const path = configPath(client, env); const raw = await readOptional(path); if (!raw)
80
85
  return false; let next; try {
81
86
  validateText(client, raw);
82
- next = client === "claude-code" || client === "cursor" ? jsonUpdate(raw, client, "", true) : client === "codex" ? removeCodexEntry(removeManaged(raw)) : removeHermesEntry(removeManaged(raw));
87
+ next = profile.adapter === "json" ? jsonUpdate(raw, client, "", true) : profile.adapter === "codex" ? removeCodexEntry(removeManaged(raw)) : removeHermesEntry(removeManaged(raw));
83
88
  validateText(client, next);
84
89
  }
85
90
  catch {
@@ -92,8 +97,9 @@ catch (e) {
92
97
  await restore(path, backupPath);
93
98
  throw e;
94
99
  } return true; }
95
- export async function isConfigured(client, env = process.env) { const raw = await readOptional(configPath(client, env)); if (!raw)
96
- return false; if (client === "claude-code" || client === "cursor") {
100
+ export async function isConfigured(client, env = process.env) { const profile = clientProfiles[client]; if (profile.mode !== "auto" || !profile.adapter)
101
+ return false; const raw = await readOptional(configPath(client, env)); if (!raw)
102
+ return false; if (profile.adapter === "json") {
97
103
  try {
98
104
  const o = JSON.parse(raw);
99
105
  return !!o.mcpServers?.sandbase;
@@ -1,4 +1,4 @@
1
- import type { Client, Exchange, Grant } from "../types.js";
1
+ import type { ConnectClient, Exchange, Grant } from "../types.js";
2
2
  export interface Secrets {
3
3
  requestId: string;
4
4
  deviceSecret: string;
@@ -17,7 +17,7 @@ export declare class AuthorizationApi {
17
17
  private readonly fetcher;
18
18
  constructor(baseUrl: string, fetcher?: typeof fetch);
19
19
  private request;
20
- create(client: Client, s: Secrets): Promise<Grant>;
20
+ create(client: ConnectClient, s: Secrets): Promise<Grant>;
21
21
  status(id: string, secret: string): Promise<{
22
22
  status: string;
23
23
  interval: number;
@@ -1,4 +1,4 @@
1
- import type { Client, Exchange } from "../types.js";
1
+ import type { ConnectClient, Exchange } from "../types.js";
2
2
  import { AuthorizationApi } from "./api.js";
3
3
  export interface FlowOptions {
4
4
  signal?: AbortSignal;
@@ -6,7 +6,7 @@ export interface FlowOptions {
6
6
  sleep(ms: number, signal?: AbortSignal): Promise<void>;
7
7
  log(message: string): void;
8
8
  }
9
- export declare function authorize(api: AuthorizationApi, client: Client, options: FlowOptions): Promise<{
9
+ export declare function authorize(api: AuthorizationApi, client: ConnectClient, options: FlowOptions): Promise<{
10
10
  authorizationId: string;
11
11
  exchange: Exchange;
12
12
  }>;
package/dist/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { connect, doctor, unregister } from "./commands.js";
3
+ import { clientList } from "./clients.js";
3
4
  import { isClient } from "./types.js";
4
5
  if (Number(process.versions.node.split(".")[0]) < 20) {
5
6
  console.error("SandBase CLI requires Node.js 20 or newer. Upgrade Node.js and retry.");
@@ -8,8 +9,9 @@ if (Number(process.versions.node.split(".")[0]) < 20) {
8
9
  const [command, ...args] = process.argv.slice(2);
9
10
  const at = args.indexOf("--client");
10
11
  const value = at >= 0 ? args[at + 1] : undefined;
11
- if (!command || !value || !isClient(value) || !["connect", "doctor", "unregister"].includes(command)) {
12
- console.error("Usage: sandbase <connect|doctor|unregister> --client <codex|claude-code|cursor|hermes>");
12
+ const client = value === undefined || value === "auto" ? "auto" : isClient(value) ? value : undefined;
13
+ if (!command || !client || !["connect", "doctor", "unregister"].includes(command) || (at >= 0 && !value)) {
14
+ console.error(`Usage: sandbase <connect|doctor|unregister> [--client <${clientList()}|auto>]`);
13
15
  process.exit(2);
14
16
  }
15
17
  const controller = new AbortController();
@@ -17,19 +19,19 @@ for (const signal of ["SIGINT", "SIGTERM"])
17
19
  process.once(signal, () => controller.abort());
18
20
  try {
19
21
  if (command === "connect")
20
- await connect(value, { signal: controller.signal });
22
+ await connect(client, { signal: controller.signal });
21
23
  else if (command === "doctor") {
22
- if (!(await doctor(value)))
24
+ if (!(await doctor(client)))
23
25
  process.exitCode = 1;
24
26
  }
25
27
  else
26
- await unregister(value);
28
+ await unregister(client);
27
29
  }
28
30
  catch (e) {
29
31
  const message = e instanceof Error ? e.message : "Unknown failure";
30
32
  if (message.includes("fetch failed"))
31
33
  console.error("Authorization response may have been lost. Check SandBase Dashboard for a newly created CLI credential, revoke it if present, then retry.");
32
34
  else
33
- console.error(message.replace(/sk-[A-Za-z0-9_-]+/g, "[REDACTED]"));
35
+ console.error(message.replace(/(?:sk|cln)-[A-Za-z0-9_-]+/g, "[REDACTED]"));
34
36
  process.exitCode = 1;
35
37
  }
@@ -0,0 +1,12 @@
1
+ import type { Client } from "./types.js";
2
+ export type InstallMode = "auto" | "manual" | "skill";
3
+ export interface ClientProfile {
4
+ id: Client;
5
+ label: string;
6
+ mode: InstallMode;
7
+ executable?: string;
8
+ adapter?: "codex" | "json" | "yaml";
9
+ }
10
+ export declare const clientProfiles: Record<Client, ClientProfile>;
11
+ export declare function clientList(): string;
12
+ export declare function autoClients(): Client[];
@@ -0,0 +1,32 @@
1
+ export const clientProfiles = {
2
+ codex: { id: "codex", label: "Codex", mode: "auto", executable: "codex", adapter: "codex" },
3
+ "claude-code": { id: "claude-code", label: "Claude Code", mode: "auto", executable: "claude", adapter: "json" },
4
+ cursor: { id: "cursor", label: "Cursor", mode: "auto", executable: "cursor", adapter: "json" },
5
+ windsurf: { id: "windsurf", label: "Windsurf", mode: "manual" },
6
+ "gemini-cli": { id: "gemini-cli", label: "Gemini CLI", mode: "auto", executable: "gemini", adapter: "json" },
7
+ opencode: { id: "opencode", label: "OpenCode", mode: "manual", executable: "opencode" },
8
+ chatgpt: { id: "chatgpt", label: "ChatGPT", mode: "manual" },
9
+ hermes: { id: "hermes", label: "Hermes", mode: "auto", executable: "hermes", adapter: "yaml" },
10
+ openclaw: { id: "openclaw", label: "OpenClaw", mode: "skill" },
11
+ antigravity: { id: "antigravity", label: "Antigravity", mode: "skill" },
12
+ "claude-desktop": { id: "claude-desktop", label: "Claude Desktop", mode: "auto", adapter: "json" },
13
+ "cursor-cli": { id: "cursor-cli", label: "Cursor CLI", mode: "auto", executable: "cursor-agent", adapter: "json" },
14
+ warp: { id: "warp", label: "Warp", mode: "manual" },
15
+ trae: { id: "trae", label: "Trae", mode: "skill" },
16
+ "kimi-cli": { id: "kimi-cli", label: "Kimi CLI", mode: "manual", executable: "kimi" },
17
+ "qwen-code": { id: "qwen-code", label: "Qwen Code", mode: "auto", executable: "qwen", adapter: "json" },
18
+ "kiro-cli": { id: "kiro-cli", label: "Kiro CLI", mode: "manual", executable: "kiro" },
19
+ amp: { id: "amp", label: "Amp", mode: "manual", executable: "amp" },
20
+ crush: { id: "crush", label: "Crush", mode: "manual", executable: "crush" },
21
+ "iflow-cli": { id: "iflow-cli", label: "iFlow CLI", mode: "manual", executable: "iflow" },
22
+ qoder: { id: "qoder", label: "Qoder", mode: "skill" },
23
+ workbuddy: { id: "workbuddy", label: "WorkBuddy", mode: "skill" },
24
+ cowork: { id: "cowork", label: "Cowork", mode: "manual" },
25
+ pi: { id: "pi", label: "Pi", mode: "skill" },
26
+ };
27
+ export function clientList() {
28
+ return Object.keys(clientProfiles).join("|");
29
+ }
30
+ export function autoClients() {
31
+ return Object.values(clientProfiles).filter(profile => profile.mode === "auto" && !!profile.adapter).map(profile => profile.id);
32
+ }
@@ -1,17 +1,20 @@
1
- import type { Client } from "./types.js";
1
+ import type { Client, ConnectClient } from "./types.js";
2
2
  import { AuthorizationApi } from "./auth/api.js";
3
- import { FileCredentialStore } from "./credentials/store.js";
4
- export declare function openBrowser(url: string): Promise<void>;
5
- export declare function connect(client: Client, deps?: {
3
+ import { type CredentialStore } from "./credentials/store.js";
4
+ type Detection = {
5
+ installed: boolean;
6
+ detail: string;
7
+ };
8
+ export interface CommandDependencies {
6
9
  api?: AuthorizationApi;
7
- store?: FileCredentialStore;
10
+ store?: CredentialStore;
8
11
  open?: (url: string) => Promise<void>;
9
12
  signal?: AbortSignal;
10
13
  log?: (s: string) => void;
11
- detect?: (client: Client) => {
12
- installed: boolean;
13
- detail: string;
14
- };
15
- }): Promise<void>;
16
- export declare function doctor(client: Client, store?: FileCredentialStore): Promise<boolean>;
17
- export declare function unregister(client: Client, store?: FileCredentialStore): Promise<void>;
14
+ detect?: (client: Client) => Detection;
15
+ }
16
+ export declare function openBrowser(url: string): Promise<void>;
17
+ export declare function connect(client?: ConnectClient, deps?: CommandDependencies): Promise<void>;
18
+ export declare function doctor(client?: ConnectClient, store?: CredentialStore, detect?: (client: Client) => Detection): Promise<boolean>;
19
+ export declare function unregister(client?: ConnectClient, store?: CredentialStore, detect?: (client: Client) => Detection): Promise<void>;
20
+ export {};
package/dist/commands.js CHANGED
@@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
2
2
  import { platform } from "node:os";
3
3
  import { AuthorizationApi } from "./auth/api.js";
4
4
  import { authorize } from "./auth/flow.js";
5
+ import { autoClients, clientProfiles } from "./clients.js";
5
6
  import { FileCredentialStore } from "./credentials/store.js";
6
7
  import { configure, detectClient, installBridge, isConfigured, rollback, rollbackBridge, unregister as removeAdapter } from "./adapters/index.js";
7
8
  const sleep = (ms, signal) => new Promise((resolve, reject) => { const t = setTimeout(resolve, ms); signal?.addEventListener("abort", () => { clearTimeout(t); reject(new Error("Authorization cancelled")); }, { once: true }); });
@@ -15,25 +16,45 @@ async function compensate(api, authorizationId, token) { for (const delay of [0,
15
16
  catch { /* bounded retry inside the five-minute capability window */ }
16
17
  } return false; }
17
18
  export async function openBrowser(url) { const cmd = platform() === "darwin" ? "open" : platform() === "win32" ? "cmd" : "xdg-open"; const args = platform() === "win32" ? ["/c", "start", "", url] : [url]; const child = spawn(cmd, args, { detached: true, stdio: "ignore" }); child.unref(); }
18
- export async function connect(client, deps = {}) {
19
+ function mcpServerSnippet(client, bridgePath) { return JSON.stringify({ mcpServers: { sandbase: { command: "node", args: [bridgePath, "--client", client] } } }, null, 2); }
20
+ function nextStepPrompts(label) { return [`2. In ${label}, try asking:`, " - List the available SandBase MCP tools.", " - Use SandBase to fetch Elon Musk's latest 10 posts on Twitter."]; }
21
+ function successMessage(client, record, bridgePath, configuredPath) {
22
+ const profile = clientProfiles[client];
23
+ const label = profile.label;
24
+ const common = ["", "SandBase MCP is connected.", "", `Client: ${label} (${client})`, `MCP URL: ${record.mcpUrl}`, `Credential: ${record.keyPrefix}... (${record.scope.join(",")})`, `Bridge: ${bridgePath}`];
25
+ if (profile.mode === "auto")
26
+ return [...common, `Config: ${configuredPath || "updated"}`, "", "Next steps:", `1. Restart or reload ${label} so it picks up the new MCP configuration.`, ...nextStepPrompts(label), "", 'Manage access: revoke the "CLI Login" key in SandBase Dashboard when you no longer need it.'].join("\n");
27
+ if (profile.mode === "skill")
28
+ return [...common, "", "Skill/prompt setup required.", `Copy the following instruction into ${label}:`, "", `Install the SandBase MCP bridge for ${label}. Use this local MCP server configuration and keep the scope limited to SandBase:`, mcpServerSnippet(client, bridgePath), `After setup, reload ${label} if needed.`, "", "Next steps:", "1. Finish the skill/prompt setup in ${label}.", ...nextStepPrompts(label), "", 'Manage access: revoke the "CLI Login" key in SandBase Dashboard when you no longer need it.'].join("\n");
29
+ return [...common, "", "Manual MCP configuration required.", `Add this MCP server configuration to ${label}:`, "", mcpServerSnippet(client, bridgePath), "", "Next steps:", `1. Save the configuration and restart or reload ${label}.`, ...nextStepPrompts(label), "", 'Manage access: revoke the "CLI Login" key in SandBase Dashboard when you no longer need it.'].join("\n");
30
+ }
31
+ function plannedAutoClients(detect) { return autoClients().filter(client => detect(client).installed); }
32
+ function recordFor(client, exchange) { return { credential: exchange.credential, credentialId: exchange.credential_id, keyPrefix: exchange.key_prefix, client, scope: exchange.scope, mcpUrl: exchange.mcp_url, createdAt: exchange.created_at }; }
33
+ async function restoreCredential(store, client, previous) { if (previous)
34
+ await store.save(previous);
35
+ else
36
+ await store.remove(client); }
37
+ async function connectOne(client, deps) {
19
38
  const api = deps.api || new AuthorizationApi((process.env.SANDBASE_API_URL || "https://sandbase.ai").replace(/\/$/, ""));
20
39
  const store = deps.store || new FileCredentialStore();
21
40
  const log = deps.log || console.log;
22
- const detected = (deps.detect || detectClient)(client);
41
+ const detect = deps.detect || detectClient;
42
+ const profile = clientProfiles[client];
43
+ const detected = detect(client);
23
44
  if (!detected.installed)
24
- throw new Error(`${client} is not installed or is incompatible (${detected.detail}). Install a supported version, then retry.`);
45
+ throw new Error(`${profile.label} is not installed or is incompatible. Install a supported version, then retry.`);
25
46
  const previous = await store.get(client);
26
47
  const { authorizationId, exchange } = await authorize(api, client, { open: deps.open || openBrowser, sleep, log, ...(deps.signal ? { signal: deps.signal } : {}) });
27
48
  let configured;
28
49
  let bridgeResult;
29
50
  try {
30
- const record = { credential: exchange.credential, credentialId: exchange.credential_id, keyPrefix: exchange.key_prefix, client, scope: exchange.scope, mcpUrl: exchange.mcp_url, createdAt: exchange.created_at };
51
+ const record = recordFor(client, exchange);
31
52
  await store.save(record);
32
53
  bridgeResult = await installBridge();
33
54
  configured = await configure(client, bridgeResult.path);
34
- if (!(await isConfigured(client)))
55
+ if (profile.mode === "auto" && !(await isConfigured(client)))
35
56
  throw new Error("Client configuration verification failed");
36
- log(`Connected ${client} to ${record.mcpUrl} with ${record.keyPrefix}… (${record.scope.join(",")})`);
57
+ log(successMessage(client, record, bridgeResult.path, configured.path));
37
58
  exchange.cleanup_token = "";
38
59
  }
39
60
  catch (e) {
@@ -41,15 +62,90 @@ export async function connect(client, deps = {}) {
41
62
  await rollback(configured).catch(() => undefined);
42
63
  if (bridgeResult)
43
64
  await rollbackBridge(bridgeResult).catch(() => undefined);
44
- if (previous)
45
- await store.save(previous).catch(() => undefined);
46
- else
47
- await store.remove(client).catch(() => undefined);
65
+ await restoreCredential(store, client, previous).catch(() => undefined);
48
66
  if (!(await compensate(api, authorizationId, exchange.cleanup_token)))
49
67
  console.error("WARNING: automatic credential cleanup failed. Revoke the new CLI credential in SandBase Dashboard immediately.");
50
68
  exchange.cleanup_token = "";
51
69
  throw e;
52
70
  }
53
71
  }
54
- export async function doctor(client, store = new FileCredentialStore()) { const credential = await store.get(client); const configured = await isConfigured(client); const detected = detectClient(client); console.log(`${client}: installed=${detected.installed ? "yes" : "no"}, config=${configured ? "ok" : "missing"}, credential=${credential ? credential.keyPrefix + "…" : "missing"}, url=${credential?.mcpUrl || "unknown"}, scope=${credential?.scope.join(",") || "unknown"}`); return detected.installed && !!credential && configured; }
55
- export async function unregister(client, store = new FileCredentialStore()) { await removeAdapter(client); await store.remove(client); console.log(`Removed local SandBase registration for ${client}. Revoke the server credential in SandBase Dashboard if it is no longer needed.`); }
72
+ async function connectAuto(deps) {
73
+ const api = deps.api || new AuthorizationApi((process.env.SANDBASE_API_URL || "https://sandbase.ai").replace(/\/$/, ""));
74
+ const store = deps.store || new FileCredentialStore();
75
+ const log = deps.log || console.log;
76
+ const detect = deps.detect || detectClient;
77
+ const targets = plannedAutoClients(detect);
78
+ if (!targets.length) {
79
+ log("No installed compatible clients support automatic configuration. Use --client <client> for manual or skill setup guidance.");
80
+ return;
81
+ }
82
+ const { authorizationId, exchange } = await authorize(api, "auto", { open: deps.open || openBrowser, sleep, log, ...(deps.signal ? { signal: deps.signal } : {}) });
83
+ let bridgeResult;
84
+ const succeeded = [], failed = [];
85
+ try {
86
+ bridgeResult = await installBridge();
87
+ for (const client of targets) {
88
+ const previous = await store.get(client);
89
+ let configured;
90
+ try {
91
+ const record = recordFor(client, exchange);
92
+ await store.save(record);
93
+ configured = await configure(client, bridgeResult.path);
94
+ if (!(await isConfigured(client)))
95
+ throw new Error("Client configuration verification failed");
96
+ succeeded.push(client);
97
+ }
98
+ catch {
99
+ if (configured)
100
+ await rollback(configured).catch(() => undefined);
101
+ await restoreCredential(store, client, previous).catch(() => undefined);
102
+ failed.push(client);
103
+ }
104
+ }
105
+ if (!succeeded.length)
106
+ throw new Error("No clients were configured successfully.");
107
+ log(`Configured clients: ${succeeded.join(", ")}.`);
108
+ if (failed.length)
109
+ log(`Partial success: failed clients were rolled back: ${failed.join(", ")}.`);
110
+ exchange.cleanup_token = "";
111
+ }
112
+ catch (e) {
113
+ if (bridgeResult)
114
+ await rollbackBridge(bridgeResult).catch(() => undefined);
115
+ if (!(await compensate(api, authorizationId, exchange.cleanup_token)))
116
+ console.error("WARNING: automatic credential cleanup failed. Revoke the new CLI credential in SandBase Dashboard immediately.");
117
+ exchange.cleanup_token = "";
118
+ throw e;
119
+ }
120
+ }
121
+ export async function connect(client = "auto", deps = {}) { if (client === "auto")
122
+ return connectAuto(deps); return connectOne(client, deps); }
123
+ export async function doctor(client = "auto", store = new FileCredentialStore(), detect = detectClient) {
124
+ const targets = client === "auto" ? plannedAutoClients(detect) : [client];
125
+ if (!targets.length) {
126
+ console.log("No installed compatible clients support automatic configuration.");
127
+ return false;
128
+ }
129
+ let healthy = true;
130
+ for (const target of targets) {
131
+ const credential = await store.get(target);
132
+ const profile = clientProfiles[target];
133
+ const configured = profile.mode === "auto" ? await isConfigured(target) : !!credential;
134
+ const detected = detect(target);
135
+ console.log(`${target}: mode=${profile.mode}, installed=${detected.installed ? "yes" : "no"}, config=${configured ? profile.mode === "auto" ? "ok" : "manual" : "missing"}, credential=${credential ? credential.keyPrefix + "…" : "missing"}, url=${credential?.mcpUrl || "unknown"}, scope=${credential?.scope.join(",") || "unknown"}`);
136
+ healthy = healthy && detected.installed && !!credential && configured;
137
+ }
138
+ return healthy;
139
+ }
140
+ export async function unregister(client = "auto", store = new FileCredentialStore(), detect = detectClient) {
141
+ const targets = client === "auto" ? plannedAutoClients(detect) : [client];
142
+ if (!targets.length) {
143
+ console.log("No installed compatible clients support automatic configuration.");
144
+ return;
145
+ }
146
+ for (const target of targets) {
147
+ const removed = await removeAdapter(target);
148
+ await store.remove(target);
149
+ console.log(`Removed local SandBase registration for ${target}.${removed ? "" : " No managed client configuration was changed."} Revoke the server credential in SandBase Dashboard if it is no longer needed.`);
150
+ }
151
+ }
package/dist/paths.js CHANGED
@@ -9,5 +9,15 @@ export function configPath(client, env = process.env) {
9
9
  return join(home, ".claude.json");
10
10
  if (client === "cursor")
11
11
  return join(home, ".cursor", "mcp.json");
12
- return env.HERMES_HOME ? join(env.HERMES_HOME, "config.yaml") : join(home, ".hermes", "config.yaml");
12
+ if (client === "hermes")
13
+ return env.HERMES_HOME ? join(env.HERMES_HOME, "config.yaml") : join(home, ".hermes", "config.yaml");
14
+ if (client === "claude-desktop")
15
+ return env.CLAUDE_DESKTOP_CONFIG || join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
16
+ if (client === "gemini-cli")
17
+ return join(home, ".gemini", "settings.json");
18
+ if (client === "qwen-code")
19
+ return join(home, ".qwen", "settings.json");
20
+ if (client === "cursor-cli")
21
+ return join(home, ".cursor", "mcp.json");
22
+ return join(sandbaseHome(env), "manual", `${client}.json`);
13
23
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export declare const clients: readonly ["codex", "claude-code", "cursor", "hermes"];
1
+ export declare const clients: readonly ["codex", "claude-code", "cursor", "windsurf", "gemini-cli", "opencode", "chatgpt", "hermes", "openclaw", "antigravity", "claude-desktop", "cursor-cli", "warp", "trae", "kimi-cli", "qwen-code", "kiro-cli", "amp", "crush", "iflow-cli", "qoder", "workbuddy", "cowork", "pi"];
2
2
  export type Client = typeof clients[number];
3
+ export type ConnectClient = Client | "auto";
3
4
  export declare function isClient(value: string): value is Client;
4
5
  export interface CredentialRecord {
5
6
  credential: string;
@@ -21,7 +22,7 @@ export interface Exchange {
21
22
  credential: string;
22
23
  credential_id: string;
23
24
  key_prefix: string;
24
- client: Client;
25
+ client: ConnectClient;
25
26
  scope: string[];
26
27
  mcp_url: string;
27
28
  created_at: string;
package/dist/types.js CHANGED
@@ -1,2 +1,2 @@
1
- export const clients = ["codex", "claude-code", "cursor", "hermes"];
1
+ export const clients = ["codex", "claude-code", "cursor", "windsurf", "gemini-cli", "opencode", "chatgpt", "hermes", "openclaw", "antigravity", "claude-desktop", "cursor-cli", "warp", "trae", "kimi-cli", "qwen-code", "kiro-cli", "amp", "crush", "iflow-cli", "qoder", "workbuddy", "cowork", "pi"];
2
2
  export function isClient(value) { return clients.includes(value); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandbaseai/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Secure SandBase MCP onboarding CLI",
5
5
  "type": "module",
6
6
  "bin": {