@sandbaseai/cli 0.1.2 → 0.1.4
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.
- package/assets/skills/sandbase/SKILL.md +10 -0
- package/dist/adapters/index.js +4 -2
- package/dist/auth/api.d.ts +2 -2
- package/dist/auth/flow.d.ts +2 -2
- package/dist/cli.js +9 -16
- package/dist/clients.d.ts +3 -0
- package/dist/clients.js +7 -0
- package/dist/commands.d.ts +15 -12
- package/dist/commands.js +115 -21
- package/dist/skills.d.ts +16 -0
- package/dist/skills.js +89 -0
- package/dist/types.d.ts +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sandbase
|
|
3
|
+
description: Use the already configured SandBase MCP tools for relevant requests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SandBase
|
|
7
|
+
|
|
8
|
+
<!-- sandbase-cli-managed: sandbase -->
|
|
9
|
+
|
|
10
|
+
Use the already configured SandBase MCP tools when they are relevant to the user's request. First inspect the available SandBase tools, then choose the smallest suitable tool call. Keep the user informed of meaningful failures and do not change unrelated local settings.
|
package/dist/adapters/index.js
CHANGED
|
@@ -2,14 +2,16 @@ 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";
|
|
8
9
|
import { clientProfiles } from "../clients.js";
|
|
9
10
|
import { configPath, sandbaseHome } from "../paths.js";
|
|
10
11
|
const defaultIO = { backup, write: atomicWrite, restore };
|
|
11
|
-
export function detectClient(client) { const profile = clientProfiles[client]; if (
|
|
12
|
-
return { installed: true, detail: "manual setup" };
|
|
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 }; }
|
|
13
15
|
const start = "# >>> sandbase managed >>>", end = "# <<< sandbase managed <<<";
|
|
14
16
|
function block(client, bridge) {
|
|
15
17
|
if (client === "codex")
|
package/dist/auth/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
20
|
+
create(client: ConnectClient, s: Secrets): Promise<Grant>;
|
|
21
21
|
status(id: string, secret: string): Promise<{
|
|
22
22
|
status: string;
|
|
23
23
|
interval: number;
|
package/dist/auth/flow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
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:
|
|
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,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { connect, doctor, unregister } from "./commands.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { clients, isClient } from "./types.js";
|
|
3
|
+
import { clientList } from "./clients.js";
|
|
4
|
+
import { isClient } from "./types.js";
|
|
6
5
|
if (Number(process.versions.node.split(".")[0]) < 20) {
|
|
7
6
|
console.error("SandBase CLI requires Node.js 20 or newer. Upgrade Node.js and retry.");
|
|
8
7
|
process.exit(1);
|
|
@@ -10,15 +9,9 @@ if (Number(process.versions.node.split(".")[0]) < 20) {
|
|
|
10
9
|
const [command, ...args] = process.argv.slice(2);
|
|
11
10
|
const at = args.indexOf("--client");
|
|
12
11
|
const value = at >= 0 ? args[at + 1] : undefined;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return profile.mode === "auto" && !!profile.executable && detectClient(client).installed;
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
const resolved = value === "auto" || (!value && command === "connect") ? autoClient() : value && isClient(value) ? value : undefined;
|
|
20
|
-
if (!command || !resolved || (command !== "connect" && !value) || !["connect", "doctor", "unregister"].includes(command)) {
|
|
21
|
-
console.error(`Usage: sandbase <connect|doctor|unregister> --client <${clientList()}|auto>`);
|
|
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>]`);
|
|
22
15
|
process.exit(2);
|
|
23
16
|
}
|
|
24
17
|
const controller = new AbortController();
|
|
@@ -26,19 +19,19 @@ for (const signal of ["SIGINT", "SIGTERM"])
|
|
|
26
19
|
process.once(signal, () => controller.abort());
|
|
27
20
|
try {
|
|
28
21
|
if (command === "connect")
|
|
29
|
-
await connect(
|
|
22
|
+
await connect(client, { signal: controller.signal });
|
|
30
23
|
else if (command === "doctor") {
|
|
31
|
-
if (!(await doctor(
|
|
24
|
+
if (!(await doctor(client)))
|
|
32
25
|
process.exitCode = 1;
|
|
33
26
|
}
|
|
34
27
|
else
|
|
35
|
-
await unregister(
|
|
28
|
+
await unregister(client);
|
|
36
29
|
}
|
|
37
30
|
catch (e) {
|
|
38
31
|
const message = e instanceof Error ? e.message : "Unknown failure";
|
|
39
32
|
if (message.includes("fetch failed"))
|
|
40
33
|
console.error("Authorization response may have been lost. Check SandBase Dashboard for a newly created CLI credential, revoke it if present, then retry.");
|
|
41
34
|
else
|
|
42
|
-
console.error(message.replace(/sk-[A-Za-z0-9_-]+/g, "[REDACTED]"));
|
|
35
|
+
console.error(message.replace(/(?:sk|cln)-[A-Za-z0-9_-]+/g, "[REDACTED]"));
|
|
43
36
|
process.exitCode = 1;
|
|
44
37
|
}
|
package/dist/clients.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Client } from "./types.js";
|
|
2
2
|
export type InstallMode = "auto" | "manual" | "skill";
|
|
3
|
+
export type SkillTier = "s1_slash" | "s2_skill" | "s3_fallback" | "s4_none";
|
|
3
4
|
export interface ClientProfile {
|
|
4
5
|
id: Client;
|
|
5
6
|
label: string;
|
|
@@ -8,4 +9,6 @@ export interface ClientProfile {
|
|
|
8
9
|
adapter?: "codex" | "json" | "yaml";
|
|
9
10
|
}
|
|
10
11
|
export declare const clientProfiles: Record<Client, ClientProfile>;
|
|
12
|
+
export declare const skillTiers: Record<Client, SkillTier>;
|
|
11
13
|
export declare function clientList(): string;
|
|
14
|
+
export declare function autoClients(): Client[];
|
package/dist/clients.js
CHANGED
|
@@ -24,6 +24,13 @@ export const clientProfiles = {
|
|
|
24
24
|
cowork: { id: "cowork", label: "Cowork", mode: "manual" },
|
|
25
25
|
pi: { id: "pi", label: "Pi", mode: "skill" },
|
|
26
26
|
};
|
|
27
|
+
export const skillTiers = {
|
|
28
|
+
codex: "s2_skill", "claude-code": "s1_slash", cursor: "s3_fallback", hermes: "s3_fallback",
|
|
29
|
+
windsurf: "s4_none", "gemini-cli": "s4_none", opencode: "s4_none", chatgpt: "s4_none", openclaw: "s4_none", antigravity: "s4_none", "claude-desktop": "s4_none", "cursor-cli": "s4_none", warp: "s4_none", trae: "s4_none", "kimi-cli": "s4_none", "qwen-code": "s4_none", "kiro-cli": "s4_none", amp: "s4_none", crush: "s4_none", "iflow-cli": "s4_none", qoder: "s4_none", workbuddy: "s4_none", cowork: "s4_none", pi: "s4_none",
|
|
30
|
+
};
|
|
27
31
|
export function clientList() {
|
|
28
32
|
return Object.keys(clientProfiles).join("|");
|
|
29
33
|
}
|
|
34
|
+
export function autoClients() {
|
|
35
|
+
return Object.values(clientProfiles).filter(profile => profile.mode === "auto" && !!profile.adapter).map(profile => profile.id);
|
|
36
|
+
}
|
package/dist/commands.d.ts
CHANGED
|
@@ -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 {
|
|
4
|
-
|
|
5
|
-
|
|
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?:
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function
|
|
17
|
-
export
|
|
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,9 +2,10 @@ 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 { clientProfiles } from "./clients.js";
|
|
5
|
+
import { autoClients, clientProfiles } from "./clients.js";
|
|
6
6
|
import { FileCredentialStore } from "./credentials/store.js";
|
|
7
7
|
import { configure, detectClient, installBridge, isConfigured, rollback, rollbackBridge, unregister as removeAdapter } from "./adapters/index.js";
|
|
8
|
+
import { inspectSkill, installSkill, removeSkill, skillFallback, skillInvocation } from "./skills.js";
|
|
8
9
|
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 }); });
|
|
9
10
|
async function compensate(api, authorizationId, token) { for (const delay of [0, 250, 750]) {
|
|
10
11
|
if (delay)
|
|
@@ -16,42 +17,56 @@ async function compensate(api, authorizationId, token) { for (const delay of [0,
|
|
|
16
17
|
catch { /* bounded retry inside the five-minute capability window */ }
|
|
17
18
|
} return false; }
|
|
18
19
|
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(); }
|
|
19
|
-
function mcpServerSnippet(client, bridgePath) {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
function nextStepPrompts(label) {
|
|
23
|
-
return [`2. In ${label}, try asking:`, ` - List the available SandBase MCP tools.`, ` - Use SandBase to fetch Elon Musk's latest 10 posts on Twitter.`];
|
|
24
|
-
}
|
|
20
|
+
function mcpServerSnippet(client, bridgePath) { return JSON.stringify({ mcpServers: { sandbase: { command: "node", args: [bridgePath, "--client", client] } } }, null, 2); }
|
|
21
|
+
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."]; }
|
|
25
22
|
function successMessage(client, record, bridgePath, configuredPath) {
|
|
26
23
|
const profile = clientProfiles[client];
|
|
27
24
|
const label = profile.label;
|
|
28
|
-
const common = [
|
|
25
|
+
const common = ["", "SandBase MCP is connected.", "", `Client: ${label} (${client})`, `MCP URL: ${record.mcpUrl}`, `Credential: ${record.keyPrefix}... (${record.scope.join(",")})`, `Bridge: ${bridgePath}`];
|
|
29
26
|
if (profile.mode === "auto")
|
|
30
|
-
return [...common, `Config: ${configuredPath || "updated"}`,
|
|
27
|
+
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");
|
|
31
28
|
if (profile.mode === "skill")
|
|
32
|
-
return [...common,
|
|
33
|
-
return [...common,
|
|
29
|
+
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");
|
|
30
|
+
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");
|
|
31
|
+
}
|
|
32
|
+
function plannedAutoClients(detect) { return autoClients().filter(client => detect(client).installed); }
|
|
33
|
+
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 }; }
|
|
34
|
+
async function restoreCredential(store, client, previous) { if (previous)
|
|
35
|
+
await store.save(previous);
|
|
36
|
+
else
|
|
37
|
+
await store.remove(client); }
|
|
38
|
+
async function configureSkill(client, log) {
|
|
39
|
+
try {
|
|
40
|
+
const result = await installSkill(client);
|
|
41
|
+
log(`Native Skill for ${client}: ${result.state}. ${result.message}`);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const message = error instanceof Error ? error.message : "Unknown native Skill failure";
|
|
45
|
+
log(`Native Skill for ${client}: failed. ${message}`);
|
|
46
|
+
}
|
|
34
47
|
}
|
|
35
|
-
|
|
48
|
+
async function connectOne(client, deps) {
|
|
36
49
|
const api = deps.api || new AuthorizationApi((process.env.SANDBASE_API_URL || "https://sandbase.ai").replace(/\/$/, ""));
|
|
37
50
|
const store = deps.store || new FileCredentialStore();
|
|
38
51
|
const log = deps.log || console.log;
|
|
52
|
+
const detect = deps.detect || detectClient;
|
|
39
53
|
const profile = clientProfiles[client];
|
|
40
|
-
const detected =
|
|
54
|
+
const detected = detect(client);
|
|
41
55
|
if (!detected.installed)
|
|
42
|
-
throw new Error(`${profile.label} is not installed or is incompatible
|
|
56
|
+
throw new Error(`${profile.label} is not installed or is incompatible. Install a supported version, then retry.`);
|
|
43
57
|
const previous = await store.get(client);
|
|
44
58
|
const { authorizationId, exchange } = await authorize(api, client, { open: deps.open || openBrowser, sleep, log, ...(deps.signal ? { signal: deps.signal } : {}) });
|
|
45
59
|
let configured;
|
|
46
60
|
let bridgeResult;
|
|
47
61
|
try {
|
|
48
|
-
const record =
|
|
62
|
+
const record = recordFor(client, exchange);
|
|
49
63
|
await store.save(record);
|
|
50
64
|
bridgeResult = await installBridge();
|
|
51
65
|
configured = await configure(client, bridgeResult.path);
|
|
52
66
|
if (profile.mode === "auto" && !(await isConfigured(client)))
|
|
53
67
|
throw new Error("Client configuration verification failed");
|
|
54
68
|
log(successMessage(client, record, bridgeResult.path, configured.path));
|
|
69
|
+
await configureSkill(client, log);
|
|
55
70
|
exchange.cleanup_token = "";
|
|
56
71
|
}
|
|
57
72
|
catch (e) {
|
|
@@ -59,15 +74,94 @@ export async function connect(client, deps = {}) {
|
|
|
59
74
|
await rollback(configured).catch(() => undefined);
|
|
60
75
|
if (bridgeResult)
|
|
61
76
|
await rollbackBridge(bridgeResult).catch(() => undefined);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
await restoreCredential(store, client, previous).catch(() => undefined);
|
|
78
|
+
if (!(await compensate(api, authorizationId, exchange.cleanup_token)))
|
|
79
|
+
console.error("WARNING: automatic credential cleanup failed. Revoke the new CLI credential in SandBase Dashboard immediately.");
|
|
80
|
+
exchange.cleanup_token = "";
|
|
81
|
+
throw e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function connectAuto(deps) {
|
|
85
|
+
const api = deps.api || new AuthorizationApi((process.env.SANDBASE_API_URL || "https://sandbase.ai").replace(/\/$/, ""));
|
|
86
|
+
const store = deps.store || new FileCredentialStore();
|
|
87
|
+
const log = deps.log || console.log;
|
|
88
|
+
const detect = deps.detect || detectClient;
|
|
89
|
+
const targets = plannedAutoClients(detect);
|
|
90
|
+
if (!targets.length) {
|
|
91
|
+
log("No installed compatible clients support automatic configuration. Use --client <client> for manual or skill setup guidance.");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const { authorizationId, exchange } = await authorize(api, "auto", { open: deps.open || openBrowser, sleep, log, ...(deps.signal ? { signal: deps.signal } : {}) });
|
|
95
|
+
let bridgeResult;
|
|
96
|
+
const succeeded = [], failed = [];
|
|
97
|
+
try {
|
|
98
|
+
bridgeResult = await installBridge();
|
|
99
|
+
for (const client of targets) {
|
|
100
|
+
const previous = await store.get(client);
|
|
101
|
+
let configured;
|
|
102
|
+
try {
|
|
103
|
+
const record = recordFor(client, exchange);
|
|
104
|
+
await store.save(record);
|
|
105
|
+
configured = await configure(client, bridgeResult.path);
|
|
106
|
+
if (!(await isConfigured(client)))
|
|
107
|
+
throw new Error("Client configuration verification failed");
|
|
108
|
+
await configureSkill(client, log);
|
|
109
|
+
succeeded.push(client);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
if (configured)
|
|
113
|
+
await rollback(configured).catch(() => undefined);
|
|
114
|
+
await restoreCredential(store, client, previous).catch(() => undefined);
|
|
115
|
+
failed.push(client);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!succeeded.length)
|
|
119
|
+
throw new Error("No clients were configured successfully.");
|
|
120
|
+
log(`Configured clients: ${succeeded.join(", ")}.`);
|
|
121
|
+
if (failed.length)
|
|
122
|
+
log(`Partial success: failed clients were rolled back: ${failed.join(", ")}.`);
|
|
123
|
+
exchange.cleanup_token = "";
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
if (bridgeResult)
|
|
127
|
+
await rollbackBridge(bridgeResult).catch(() => undefined);
|
|
66
128
|
if (!(await compensate(api, authorizationId, exchange.cleanup_token)))
|
|
67
129
|
console.error("WARNING: automatic credential cleanup failed. Revoke the new CLI credential in SandBase Dashboard immediately.");
|
|
68
130
|
exchange.cleanup_token = "";
|
|
69
131
|
throw e;
|
|
70
132
|
}
|
|
71
133
|
}
|
|
72
|
-
export async function
|
|
73
|
-
|
|
134
|
+
export async function connect(client = "auto", deps = {}) { if (client === "auto")
|
|
135
|
+
return connectAuto(deps); return connectOne(client, deps); }
|
|
136
|
+
export async function doctor(client = "auto", store = new FileCredentialStore(), detect = detectClient) {
|
|
137
|
+
const targets = client === "auto" ? plannedAutoClients(detect) : [client];
|
|
138
|
+
if (!targets.length) {
|
|
139
|
+
console.log("No installed compatible clients support automatic configuration.");
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
let healthy = true;
|
|
143
|
+
for (const target of targets) {
|
|
144
|
+
const credential = await store.get(target);
|
|
145
|
+
const profile = clientProfiles[target];
|
|
146
|
+
const configured = profile.mode === "auto" ? await isConfigured(target) : !!credential;
|
|
147
|
+
const detected = detect(target);
|
|
148
|
+
const skill = await inspectSkill(target);
|
|
149
|
+
const skillDetail = skill === "installed" ? skillInvocation(target) : skill === "fallback" ? skillFallback(target) : skill === "unsupported" ? "No native SandBase Skill is available for this client." : skill === "modified" ? "Managed native Skill is missing or modified; it was left untouched." : "Native SandBase Skill is not installed.";
|
|
150
|
+
console.log(`${target}: mode=${profile.mode}, installed=${detected.installed ? "yes" : "no"}, config=${configured ? profile.mode === "auto" ? "ok" : "manual" : "missing"}, skill=${skill}, credential=${credential ? credential.keyPrefix + "…" : "missing"}, url=${credential?.mcpUrl || "unknown"}, scope=${credential?.scope.join(",") || "unknown"}. ${skillDetail}`);
|
|
151
|
+
healthy = healthy && detected.installed && !!credential && configured && !["missing", "modified"].includes(skill);
|
|
152
|
+
}
|
|
153
|
+
return healthy;
|
|
154
|
+
}
|
|
155
|
+
export async function unregister(client = "auto", store = new FileCredentialStore(), detect = detectClient) {
|
|
156
|
+
const targets = client === "auto" ? plannedAutoClients(detect) : [client];
|
|
157
|
+
if (!targets.length) {
|
|
158
|
+
console.log("No installed compatible clients support automatic configuration.");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
for (const target of targets) {
|
|
162
|
+
const removed = await removeAdapter(target);
|
|
163
|
+
const removedSkill = await removeSkill(target);
|
|
164
|
+
await store.remove(target);
|
|
165
|
+
console.log(`Removed local SandBase registration for ${target}.${removed || removedSkill ? "" : " No managed client configuration or Skill was changed."} Revoke the server credential in SandBase Dashboard if it is no longer needed.`);
|
|
166
|
+
}
|
|
167
|
+
}
|
package/dist/skills.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Client } from "./types.js";
|
|
2
|
+
export type SkillState = "installed" | "missing" | "modified" | "fallback" | "unsupported";
|
|
3
|
+
export interface SkillInstallResult {
|
|
4
|
+
state: "configured" | "already_configured" | "fallback" | "skipped";
|
|
5
|
+
message: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
backup?: string;
|
|
8
|
+
changed: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function skillPath(client: Client, env?: NodeJS.ProcessEnv): string | undefined;
|
|
11
|
+
export declare function skillFallback(client: Client): string;
|
|
12
|
+
export declare function skillInvocation(client: Client): string;
|
|
13
|
+
export declare function inspectSkill(client: Client, env?: NodeJS.ProcessEnv): Promise<SkillState>;
|
|
14
|
+
export declare function installSkill(client: Client, env?: NodeJS.ProcessEnv): Promise<SkillInstallResult>;
|
|
15
|
+
export declare function rollbackSkill(result: SkillInstallResult): Promise<void>;
|
|
16
|
+
export declare function removeSkill(client: Client, env?: NodeJS.ProcessEnv): Promise<boolean>;
|
package/dist/skills.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { atomicWrite, backup, readOptional, restore } from "./fs-safe.js";
|
|
5
|
+
import { clientProfiles, skillTiers } from "./clients.js";
|
|
6
|
+
import { sandbaseHome } from "./paths.js";
|
|
7
|
+
const ownershipMarker = "<!-- sandbase-cli-managed: sandbase -->";
|
|
8
|
+
export function skillPath(client, env = process.env) {
|
|
9
|
+
const home = env.HOME || sandbaseHome(env);
|
|
10
|
+
if (client === "claude-code")
|
|
11
|
+
return join(home, ".claude", "skills", "sandbase", "SKILL.md");
|
|
12
|
+
if (client === "codex")
|
|
13
|
+
return join(env.CODEX_HOME || join(home, ".codex"), "skills", "sandbase", "SKILL.md");
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
export function skillFallback(client) {
|
|
17
|
+
if (client === "cursor" || client === "hermes")
|
|
18
|
+
return `${clientProfiles[client].label} native SandBase Skill is not available yet. Use the configured SandBase MCP tools directly in chat.`;
|
|
19
|
+
return "No native SandBase Skill is available for this client. Use the configured SandBase MCP tools directly.";
|
|
20
|
+
}
|
|
21
|
+
export function skillInvocation(client) { return client === "claude-code" ? "Type / and select /sandbase to get SandBase MCP tool guidance." : "Open Codex's Skill picker and select SandBase, or reference $sandbase where that native affordance is available."; }
|
|
22
|
+
function nativeTier(client) { const tier = skillTiers[client]; return tier === "s1_slash" || tier === "s2_skill"; }
|
|
23
|
+
function isOwned(content) { return content.includes(ownershipMarker) && /^name:\s*sandbase\s*$/m.test(content); }
|
|
24
|
+
async function asset() {
|
|
25
|
+
const bundled = fileURLToPath(new URL("../assets/skills/sandbase/SKILL.md", import.meta.url));
|
|
26
|
+
try {
|
|
27
|
+
return await readFile(bundled, "utf8");
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code !== "ENOENT")
|
|
31
|
+
throw error;
|
|
32
|
+
return readFile(join(process.cwd(), "assets", "skills", "sandbase", "SKILL.md"), "utf8");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function inspectSkill(client, env = process.env) {
|
|
36
|
+
const tier = skillTiers[client];
|
|
37
|
+
if (tier === "s3_fallback")
|
|
38
|
+
return "fallback";
|
|
39
|
+
if (tier === "s4_none")
|
|
40
|
+
return "unsupported";
|
|
41
|
+
const current = await readOptional(skillPath(client, env));
|
|
42
|
+
return !current ? "missing" : isOwned(current) ? "installed" : "modified";
|
|
43
|
+
}
|
|
44
|
+
export async function installSkill(client, env = process.env) {
|
|
45
|
+
if (!nativeTier(client)) {
|
|
46
|
+
const fallback = skillTiers[client] === "s3_fallback";
|
|
47
|
+
return { state: fallback ? "fallback" : "skipped", message: fallback ? skillFallback(client) : "No native SandBase Skill is available for this client.", changed: false };
|
|
48
|
+
}
|
|
49
|
+
const path = skillPath(client, env);
|
|
50
|
+
const desired = await asset();
|
|
51
|
+
const current = await readOptional(path);
|
|
52
|
+
if (current && !isOwned(current))
|
|
53
|
+
throw new Error(`Refusing to overwrite an unmanaged ${clientProfiles[client].label} SandBase Skill artifact. Resolve it manually, then retry.`);
|
|
54
|
+
if (current === desired)
|
|
55
|
+
return { state: "already_configured", message: skillInvocation(client), path, changed: false };
|
|
56
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
57
|
+
const backupPath = await backup(path);
|
|
58
|
+
try {
|
|
59
|
+
await atomicWrite(path, desired, 0o600);
|
|
60
|
+
if ((await readOptional(path)) !== desired || !isOwned(desired))
|
|
61
|
+
throw new Error("Native Skill verification failed");
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
await restore(path, backupPath);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
return backupPath ? { state: "configured", message: skillInvocation(client), path, backup: backupPath, changed: true } : { state: "configured", message: skillInvocation(client), path, changed: true };
|
|
68
|
+
}
|
|
69
|
+
export async function rollbackSkill(result) { if (result.changed && result.path)
|
|
70
|
+
await restore(result.path, result.backup); }
|
|
71
|
+
export async function removeSkill(client, env = process.env) {
|
|
72
|
+
if (!nativeTier(client))
|
|
73
|
+
return false;
|
|
74
|
+
const path = skillPath(client, env);
|
|
75
|
+
const current = await readOptional(path);
|
|
76
|
+
if (!current)
|
|
77
|
+
return false;
|
|
78
|
+
if (!isOwned(current))
|
|
79
|
+
throw new Error(`Refusing to remove an unmanaged ${clientProfiles[client].label} SandBase Skill artifact. Remove it manually if intended.`);
|
|
80
|
+
const backupPath = await backup(path);
|
|
81
|
+
try {
|
|
82
|
+
await rm(path);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
await restore(path, backupPath);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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:
|
|
25
|
+
client: ConnectClient;
|
|
25
26
|
scope: string[];
|
|
26
27
|
mcp_url: string;
|
|
27
28
|
created_at: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sandbaseai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Secure SandBase MCP onboarding CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
14
|
-
"assets
|
|
14
|
+
"assets",
|
|
15
15
|
"README.md",
|
|
16
16
|
"LICENSE"
|
|
17
17
|
],
|