stets.app 0.0.0-stage → 0.1.0
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/README.md +69 -2
- package/package.json +26 -4
- package/stets.mjs +1124 -0
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# stets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connects your AI agents to [Stets](https://stets.app), the website builder you talk to.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx stets.app agent setup # once published; until then: node cli/stets.mjs agent setup
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Stet, the builder, waves and finds the agents on your computer. Inside a git project he first asks where Stets
|
|
10
|
+
should go. Then you pick the agents in a menu (space toggles, enter goes). Each agent signs in to Stets itself,
|
|
11
|
+
and if your browser is already signed in at stets.app, that's one click: Allow.
|
|
12
|
+
|
|
13
|
+
Once that's done, ask your agent: "Make me a website for my bakery."
|
|
14
|
+
|
|
15
|
+
| Command | What it does |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `stets agent setup` | Add Stets to your agents and sign them in |
|
|
18
|
+
| `stets agent status` | Show where Stets is set up |
|
|
19
|
+
| `stets agent remove` | Take Stets out again (signing the agent out first). Without `--agents` it lists what goes and asks |
|
|
20
|
+
|
|
21
|
+
## Where
|
|
22
|
+
|
|
23
|
+
| `--scope` | Means | Claude Code | Codex | Gemini, Qwen | Cursor, VS Code, Kiro, OpenCode | Devin |
|
|
24
|
+
|---|---|---|---|---|---|---|
|
|
25
|
+
| `global` (default) | all your projects | user | `~/.codex` | user | global file | user |
|
|
26
|
+
| `project` | this project, shared through git | `.mcp.json` | `.codex/config.toml` | `.gemini`, `.qwen` | `.cursor/`, `.vscode/`, `.kiro/`, `opencode.json` | `.devin/` |
|
|
27
|
+
| `local` | this project, just for you | local | none | none | none | `.devin/…local.json` |
|
|
28
|
+
|
|
29
|
+
The chat apps (the Claude app and ChatGPT) are always account-wide. A Stets connector added in the Claude app also
|
|
30
|
+
shows up in Claude Code.
|
|
31
|
+
|
|
32
|
+
## The agents
|
|
33
|
+
|
|
34
|
+
| Agent | How Stets gets in | Sign-in | Checked |
|
|
35
|
+
|---|---|---|---|
|
|
36
|
+
| Claude Code | `claude mcp add` | `claude mcp login` | fully |
|
|
37
|
+
| Codex CLI | `codex mcp add` (project: its file) | during the add, or `codex mcp login` | sign-in |
|
|
38
|
+
| Cursor | `~/.cursor/mcp.json` or `.cursor/mcp.json` | in the app; terminal: `cursor-agent mcp login` | sign-in (terminal) |
|
|
39
|
+
| VS Code | its `mcp.json` (profile or `.vscode/`) | in the app (Authenticate) | adding |
|
|
40
|
+
| Antigravity | `agy mcp add` | in the app | adding |
|
|
41
|
+
| Mistral Vibe | `vibe mcp add` | during the add, or `/mcp login` | adding |
|
|
42
|
+
| Gemini CLI, Qwen Code | `gemini` / `qwen mcp add` | on first connect, or `/mcp auth` | docs |
|
|
43
|
+
| OpenCode | `opencode mcp add` | `opencode mcp auth` | docs |
|
|
44
|
+
| GitHub Copilot CLI | `copilot mcp add` | `/mcp auth` in Copilot | docs |
|
|
45
|
+
| Factory Droid | `droid mcp add` | `droid mcp auth` | docs |
|
|
46
|
+
| Kiro, Devin (Windsurf) | their file or `mcp add` | in the app | docs |
|
|
47
|
+
| Zed | shows what to add (its settings file is yours) | in the app | docs |
|
|
48
|
+
| Claude app, ChatGPT | opens the connector page (the Claude one comes filled in) | in the app | guide |
|
|
49
|
+
|
|
50
|
+
Anything not fully checked shows "beta" in the menu.
|
|
51
|
+
|
|
52
|
+
## Options
|
|
53
|
+
|
|
54
|
+
- `--agents claude,cursor,…` and `--yes` skip the menu. `--yes` picks every coding agent that still needs Stets,
|
|
55
|
+
except the ones checked only from their docs, and never the chat apps.
|
|
56
|
+
- `--scope global|project|local` skips the "where" question.
|
|
57
|
+
- `--url` points at another Stets, and `--name` sets the server's name in the agent.
|
|
58
|
+
- `--no-login` only adds Stets. Codex and Vibe still sign in during their own add.
|
|
59
|
+
- `--no-browser` is for sign-in over SSH. Add `--ascii` or `--no-color` (or set `NO_COLOR`) for plain output.
|
|
60
|
+
|
|
61
|
+
## Safe by default
|
|
62
|
+
|
|
63
|
+
- **No tokens:** the CLI holds none. Where an agent has a command for it, the CLI runs that command and shows it.
|
|
64
|
+
- **Config files:** where an agent only has a file, the CLI writes just the Stets entry. A copy of the old file goes
|
|
65
|
+
to `~/.stets/backups` first (never into the project, where git could pick it up).
|
|
66
|
+
- **Files it won't touch:** a file with comments, or Zed's settings, stays as it is. You get the lines to add, or
|
|
67
|
+
an install link.
|
|
68
|
+
- **Other addresses:** a `stets` entry pointing at another address is left alone. Use `--name` for a second one.
|
|
69
|
+
|
|
70
|
+
Needs Node 18 or newer. One file, no dependencies.
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stets.app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Connect your AI agents (Claude Code, Codex, Gemini CLI, Cursor, VS Code and more) to Stets, with Stet.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"stets",
|
|
7
|
+
"mcp",
|
|
8
|
+
"website",
|
|
9
|
+
"claude-code",
|
|
10
|
+
"codex",
|
|
11
|
+
"gemini-cli",
|
|
12
|
+
"cursor",
|
|
13
|
+
"agent"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://stets.app",
|
|
16
|
+
"license": "UNLICENSED",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"bin": {
|
|
19
|
+
"stets": "stets.mjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"stets.mjs",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/stets.mjs
ADDED
|
@@ -0,0 +1,1124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// stets: puts Stets into your agents (Claude Code, Codex CLI, Gemini CLI, editors, the chat apps) and signs them in.
|
|
3
|
+
// One file, no dependencies, Node 18+.
|
|
4
|
+
// Each agent keeps its own Stets sign-in (OAuth, refreshed by the agent itself), so this CLI holds no tokens.
|
|
5
|
+
// Where an agent has a command for it (`mcp add`, `mcp login`), the CLI runs that and shows it; where an agent
|
|
6
|
+
// only has a config file, it edits just the Stets entry, after a backup, and leaves files with comments alone.
|
|
7
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
const VERSION = '0.1.0';
|
|
13
|
+
const DEFAULT_URL = 'https://stets.app/mcp';
|
|
14
|
+
const env = process.env;
|
|
15
|
+
const out = process.stdout;
|
|
16
|
+
|
|
17
|
+
let cursorHidden = false;
|
|
18
|
+
function showCursor() { if (cursorHidden) { out.write('\x1b[?25h'); cursorHidden = false; } }
|
|
19
|
+
function fail(msg) {
|
|
20
|
+
showCursor();
|
|
21
|
+
process.stderr.write(`stets: ${msg}\n`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
// `stets help | head` closes the pipe early: that's fine, not a crash.
|
|
25
|
+
out.on('error', (e) => { if (e.code === 'EPIPE') process.exit(0); throw e; });
|
|
26
|
+
|
|
27
|
+
// ---------- arguments ----------
|
|
28
|
+
|
|
29
|
+
const VALUED = new Set(['url', 'name', 'agents', 'scope']);
|
|
30
|
+
const KNOWN = new Set([...VALUED, 'yes', 'no-login', 'no-browser', 'ascii', 'no-color', 'help', 'version']);
|
|
31
|
+
|
|
32
|
+
function parseArgs(argv) {
|
|
33
|
+
const a = { _: [], flags: {} };
|
|
34
|
+
for (let i = 0; i < argv.length; i++) {
|
|
35
|
+
const s = argv[i];
|
|
36
|
+
if (s === '--') { a._.push(...argv.slice(i + 1)); break; }
|
|
37
|
+
if (s.startsWith('--')) {
|
|
38
|
+
const eq = s.indexOf('=');
|
|
39
|
+
const k = eq > 0 ? s.slice(2, eq) : s.slice(2);
|
|
40
|
+
if (eq > 0) a.flags[k] = s.slice(eq + 1);
|
|
41
|
+
else if (VALUED.has(k)) {
|
|
42
|
+
if (i + 1 >= argv.length) fail(`--${k} needs a value.`);
|
|
43
|
+
a.flags[k] = argv[++i];
|
|
44
|
+
} else a.flags[k] = true;
|
|
45
|
+
} else if (s === '-h') a.flags.help = true;
|
|
46
|
+
else if (s === '-y') a.flags.yes = true;
|
|
47
|
+
else if (s === '-v') a.flags.version = true;
|
|
48
|
+
else a._.push(s);
|
|
49
|
+
}
|
|
50
|
+
for (const k of Object.keys(a.flags)) if (!KNOWN.has(k)) fail(`Unknown option --${k}. See: stets help`);
|
|
51
|
+
return a;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ---------- terminal ----------
|
|
55
|
+
|
|
56
|
+
const args = parseArgs(process.argv.slice(2));
|
|
57
|
+
const TTY = !!(out.isTTY && process.stdin.isTTY);
|
|
58
|
+
const COLOR = !args.flags['no-color'] && (env.FORCE_COLOR ? env.FORCE_COLOR !== '0' : !!out.isTTY && !env.NO_COLOR && env.TERM !== 'dumb');
|
|
59
|
+
const ASCII = !!args.flags.ascii || !!env.STETS_ASCII || env.TERM === 'dumb' || env.TERM === 'linux';
|
|
60
|
+
const ANIM = TTY && COLOR && !env.CI && !env.STETS_NO_ANIM;
|
|
61
|
+
|
|
62
|
+
const sgr = (code) => (s) => (COLOR ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
63
|
+
const bold = sgr('1'), dim = sgr('2'), green = sgr('32'), yellow = sgr('33');
|
|
64
|
+
const red = /truecolor|24bit/i.test(env.COLORTERM || '') ? sgr('38;2;225;6;0') : sgr('31'); // Stets red, #e10600
|
|
65
|
+
|
|
66
|
+
// Every glyph is one column wide; --ascii (or a plain console) swaps the few non-ASCII ones.
|
|
67
|
+
const G = ASCII
|
|
68
|
+
? { ok: '+', no: 'x', warn: '!', ptr: '>', on: 'x', off: ' ', sep: '-', h: '-', v: '|', tl: '+', tr: '+', bl: '+', br: '+', smile: '_', dots: '...', spin: ['-', '\\', '|', '/'] }
|
|
69
|
+
: { ok: '✓', no: '✗', warn: '!', ptr: '▶', on: '✓', off: '·', sep: '·', h: '─', v: '│', tl: '┌', tr: '┐', bl: '└', br: '┘', smile: '‿', dots: '…', spin: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] };
|
|
70
|
+
|
|
71
|
+
const visible = (s) => String(s).replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '').length;
|
|
72
|
+
const padTo = (s, w) => s + ' '.repeat(Math.max(0, w - visible(s)));
|
|
73
|
+
const say = (s = '') => out.write(s + '\n');
|
|
74
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
75
|
+
|
|
76
|
+
const hideCursor = () => { if (TTY) { out.write('\x1b[?25l'); cursorHidden = true; } };
|
|
77
|
+
process.on('exit', showCursor);
|
|
78
|
+
process.on('SIGINT', () => { showCursor(); say(); process.exit(130); });
|
|
79
|
+
|
|
80
|
+
// ---------- Stet ----------
|
|
81
|
+
|
|
82
|
+
/** Stet, the builder from stets.app, in text: folded paper hat, round head, a roller on a pole.
|
|
83
|
+
* Poses: stand, wave (arm up), cheer (arm up, happy eyes). Seven rows, the art fits in 22 columns. */
|
|
84
|
+
function stet(pose = 'stand', blink = false) {
|
|
85
|
+
const eyes = blink ? '- -' : pose === 'cheer' ? '^ ^' : 'o o';
|
|
86
|
+
const up = pose === 'wave' || pose === 'cheer';
|
|
87
|
+
return [
|
|
88
|
+
' /\\',
|
|
89
|
+
` /--\\ [${red('####')}]`,
|
|
90
|
+
`${up ? ' \\ ' : ' '}(${eyes}) /`,
|
|
91
|
+
`${up ? ' \\ ' : ' '}\\${G.smile}/ /`,
|
|
92
|
+
`${up ? ' `-' : ' --'}|--------'`,
|
|
93
|
+
' |',
|
|
94
|
+
' / \\',
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
const ART_W = 24;
|
|
98
|
+
/** Stet with lines of text beside him, from his second row down. */
|
|
99
|
+
const scene = (pose, side = [], blink = false) => stet(pose, blink).map((row, i) => (side[i - 1] ? padTo(row, ART_W) + side[i - 1] : row));
|
|
100
|
+
|
|
101
|
+
function draw(lines, previous) {
|
|
102
|
+
if (previous) out.write(`\x1b[${previous}A\r`);
|
|
103
|
+
for (const l of lines) out.write(l + (previous ? '\x1b[K' : '') + '\n');
|
|
104
|
+
return lines.length;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Stet waves while his line types out; static without a colour terminal. */
|
|
108
|
+
async function greet(side) {
|
|
109
|
+
if (!ANIM) { say(); draw(scene('wave', side)); say(); return; }
|
|
110
|
+
hideCursor();
|
|
111
|
+
say();
|
|
112
|
+
// the first k characters of his lines, the rest still to come
|
|
113
|
+
const frame = (pose, k, blink) => {
|
|
114
|
+
let left = k;
|
|
115
|
+
const shown = side.map((l) => {
|
|
116
|
+
const w = visible(l), take = Math.max(0, Math.min(w, left));
|
|
117
|
+
left -= w;
|
|
118
|
+
return take === w ? l : l.replace(/\x1b\[[0-9;]*m/g, '').slice(0, take);
|
|
119
|
+
});
|
|
120
|
+
return scene(pose, shown, blink);
|
|
121
|
+
};
|
|
122
|
+
const total = side.reduce((n, l) => n + visible(l), 0);
|
|
123
|
+
let rows = draw(frame('wave', 0), 0);
|
|
124
|
+
for (let k = 0, f = 0; k <= total; k += 2, f++) {
|
|
125
|
+
rows = draw(frame(Math.floor(f / 5) % 2 ? 'stand' : 'wave', k), rows);
|
|
126
|
+
await sleep(18);
|
|
127
|
+
}
|
|
128
|
+
rows = draw(frame('wave', total, true), rows);
|
|
129
|
+
await sleep(120);
|
|
130
|
+
draw(frame('wave', total), rows);
|
|
131
|
+
showCursor();
|
|
132
|
+
say();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ---------- running the agents' own commands ----------
|
|
136
|
+
|
|
137
|
+
const WIN = process.platform === 'win32';
|
|
138
|
+
const q = (argv) => (WIN ? argv.map((x) => (/[\s"]/.test(x) ? `"${x.replace(/"/g, '\\"')}"` : x)) : argv);
|
|
139
|
+
|
|
140
|
+
function run(bin, argv, { timeout = 60_000, cwd, env: e } = {}) {
|
|
141
|
+
const r = spawnSync(bin, q(argv), { encoding: 'utf8', timeout, shell: WIN, env: e || env, cwd });
|
|
142
|
+
return { ok: r.status === 0, out: `${r.stdout || ''}${r.stderr || ''}`, missing: !!r.error && r.error.code === 'ENOENT' };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function runAsync(bin, argv, { timeout = 60_000, cwd, env: e } = {}) {
|
|
146
|
+
return new Promise((resolve) => {
|
|
147
|
+
let text = '';
|
|
148
|
+
let child;
|
|
149
|
+
try { child = spawn(bin, q(argv), { shell: WIN, env: e || env, cwd, stdio: ['ignore', 'pipe', 'pipe'] }); }
|
|
150
|
+
catch { return resolve({ ok: false, out: '', missing: true }); }
|
|
151
|
+
const timer = setTimeout(() => child.kill(), timeout);
|
|
152
|
+
child.stdout.on('data', (d) => { text += d; });
|
|
153
|
+
child.stderr.on('data', (d) => { text += d; });
|
|
154
|
+
child.on('error', (e) => { clearTimeout(timer); resolve({ ok: false, out: text, missing: e.code === 'ENOENT' }); });
|
|
155
|
+
child.on('close', (code) => { clearTimeout(timer); resolve({ ok: code === 0, out: text, missing: false }); });
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Runs a command where the person sees it and can answer it (sign-in prompts, browser links). */
|
|
160
|
+
function runShown(bin, argv, { cwd, env: e } = {}) {
|
|
161
|
+
say(dim(` $ ${[bin, ...argv].map((a) => (/\s/.test(a) ? JSON.stringify(a) : a)).join(' ')}`));
|
|
162
|
+
const r = spawnSync(bin, q(argv), { stdio: 'inherit', shell: WIN, env: e || env, cwd });
|
|
163
|
+
return { ok: r.status === 0 };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const sameUrl = (a, b) => !!a && !!b && a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
|
|
167
|
+
const exists = (f) => { try { fs.accessSync(f); return true; } catch { return false; } };
|
|
168
|
+
const home = os.homedir();
|
|
169
|
+
const tilde = (f) => (f.startsWith(home + path.sep) ? '~' + f.slice(home.length) : f);
|
|
170
|
+
|
|
171
|
+
// ---------- config files, for agents without a command ----------
|
|
172
|
+
|
|
173
|
+
/** Before the first change to a file in a run, a copy goes to ~/.stets/backups (not next to it: in a project,
|
|
174
|
+
* a copy there could end up in git). */
|
|
175
|
+
const backedUp = new Map();
|
|
176
|
+
function backup(file) {
|
|
177
|
+
if (backedUp.has(file) || !exists(file)) return;
|
|
178
|
+
const dir = env.STETS_BACKUP_DIR || path.join(home, '.stets', 'backups');
|
|
179
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
180
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
|
|
181
|
+
const copyTo = path.join(dir, `${stamp}_${file.replace(/[\\/:]+/g, '_').replace(/^_+/, '')}`);
|
|
182
|
+
fs.copyFileSync(file, copyTo);
|
|
183
|
+
backedUp.set(file, copyTo);
|
|
184
|
+
}
|
|
185
|
+
const backupNote = (file) => (backedUp.has(file) ? dim(` (copy of the old file: ${tilde(backedUp.get(file))})`) : '');
|
|
186
|
+
|
|
187
|
+
/** Comments and trailing commas out of JSONC, for reading only (outside strings, because URLs hold "//"). */
|
|
188
|
+
function stripJsonc(text) {
|
|
189
|
+
let o = '';
|
|
190
|
+
for (let i = 0, str = false; i < text.length; i++) {
|
|
191
|
+
const c = text[i], n = text[i + 1];
|
|
192
|
+
if (str) { o += c; if (c === '\\') o += text[++i] ?? ''; else if (c === '"') str = false; continue; }
|
|
193
|
+
if (c === '"') { str = true; o += c; }
|
|
194
|
+
else if (c === '/' && n === '/') { while (i < text.length && text[i] !== '\n') i++; o += '\n'; }
|
|
195
|
+
else if (c === '/' && n === '*') { i += 2; while (i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i++; i++; }
|
|
196
|
+
else o += c;
|
|
197
|
+
}
|
|
198
|
+
return o.replace(/,(\s*[}\]])/g, '$1');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A JSON config, read even with comments; `comments` says a rewrite would lose them, so then we don't write. */
|
|
202
|
+
function readJson(file) {
|
|
203
|
+
if (!exists(file)) return { obj: {} };
|
|
204
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
205
|
+
if (!text.trim()) return { obj: {} };
|
|
206
|
+
let obj, comments = false;
|
|
207
|
+
try { obj = JSON.parse(text); } catch {
|
|
208
|
+
try { obj = JSON.parse(stripJsonc(text)); comments = true; } catch { return { error: 'is not valid JSON' }; }
|
|
209
|
+
}
|
|
210
|
+
return obj && typeof obj === 'object' && !Array.isArray(obj) ? { obj, comments } : { error: 'is not a JSON object' };
|
|
211
|
+
}
|
|
212
|
+
function writeJson(file, obj) {
|
|
213
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
214
|
+
backup(file);
|
|
215
|
+
fs.writeFileSync(file, `${JSON.stringify(obj, null, 2)}\n`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* An agent whose MCP servers live in a JSON file at obj[key][name]. spec: { file(scope, dir), key, entry(url),
|
|
220
|
+
* link?(name, url) (an install link to offer instead), manual? (only show what to add) }. Whether the agent is
|
|
221
|
+
* signed in can't be seen from outside: that happens inside the app, on first use.
|
|
222
|
+
*/
|
|
223
|
+
function jsonFile(spec) {
|
|
224
|
+
const urlOf = (e) => e.url || e.serverUrl || e.httpUrl;
|
|
225
|
+
return {
|
|
226
|
+
async state(name, url, ctx) {
|
|
227
|
+
const file = spec.file(ctx.scope, ctx.dir);
|
|
228
|
+
const { obj, error } = readJson(file);
|
|
229
|
+
if (error) return { present: false, fileError: `${tilde(file)} ${error}` };
|
|
230
|
+
const e = obj[spec.key] && obj[spec.key][name];
|
|
231
|
+
return e ? { present: true, where: ctx.scope, url: urlOf(e), ready: true, inApp: true } : { present: false };
|
|
232
|
+
},
|
|
233
|
+
add(name, url, ctx) {
|
|
234
|
+
const file = spec.file(ctx.scope, ctx.dir);
|
|
235
|
+
const { obj, error, comments } = readJson(file);
|
|
236
|
+
if (error || comments || spec.manual) {
|
|
237
|
+
const why = error || (comments ? 'has comments' : 'holds all your settings');
|
|
238
|
+
say(yellow(` ${G.warn} ${tilde(file)} ${why}, so I didn't change it. Add this under "${spec.key}":`));
|
|
239
|
+
say(` "${name}": ${JSON.stringify(spec.entry(url))}`);
|
|
240
|
+
if (spec.link) say(` Or open this link to add it: ${spec.link(name, url)}`);
|
|
241
|
+
return { ok: false, manual: true };
|
|
242
|
+
}
|
|
243
|
+
obj[spec.key] = obj[spec.key] && typeof obj[spec.key] === 'object' ? obj[spec.key] : {};
|
|
244
|
+
obj[spec.key][name] = spec.entry(url);
|
|
245
|
+
writeJson(file, obj);
|
|
246
|
+
say(dim(` wrote "${name}" into ${tilde(file)}`) + backupNote(file));
|
|
247
|
+
return { ok: true };
|
|
248
|
+
},
|
|
249
|
+
remove(name, ctx) {
|
|
250
|
+
const file = spec.file(ctx.scope, ctx.dir);
|
|
251
|
+
const { obj, error, comments } = readJson(file);
|
|
252
|
+
if (error || !obj[spec.key] || !obj[spec.key][name]) return { ok: false, out: error ? `${tilde(file)} ${error}` : 'not there' };
|
|
253
|
+
if (comments || spec.manual) return { ok: false, out: `remove "${name}" from ${tilde(file)} yourself (it ${comments ? 'has comments' : 'holds all your settings'})` };
|
|
254
|
+
delete obj[spec.key][name];
|
|
255
|
+
writeJson(file, obj);
|
|
256
|
+
say(dim(` removed "${name}" from ${tilde(file)}`));
|
|
257
|
+
return { ok: true };
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Is a program on the PATH (without running it)? And is an app installed (macOS)? */
|
|
263
|
+
function has(bin) {
|
|
264
|
+
const exts = WIN ? (env.PATHEXT || '.EXE;.CMD;.BAT').split(';') : [''];
|
|
265
|
+
for (const dir of (env.PATH || '').split(path.delimiter)) {
|
|
266
|
+
for (const e of exts) { try { fs.accessSync(path.join(dir, bin + e), fs.constants.X_OK); return true; } catch { /* next */ } }
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
const hasApp = (n) => process.platform === 'darwin' && (exists(`/Applications/${n}.app`) || exists(path.join(home, 'Applications', `${n}.app`)));
|
|
271
|
+
const configHome = () => (WIN ? env.APPDATA || path.join(home, 'AppData', 'Roaming') : env.XDG_CONFIG_HOME || path.join(home, '.config'));
|
|
272
|
+
|
|
273
|
+
/** Shows a command, runs it out of view, and prints its output only when it fails. */
|
|
274
|
+
function runListed(bin, argv, { cwd } = {}) {
|
|
275
|
+
say(dim(` $ ${[bin, ...argv].join(' ')}`));
|
|
276
|
+
const r = run(bin, argv, { cwd });
|
|
277
|
+
if (!r.ok) say(r.out.trim().split('\n').map((l) => ` ${l}`).join('\n'));
|
|
278
|
+
return r;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** An agent with its own `mcp add` and `mcp remove`; its state is read from its config file. */
|
|
282
|
+
function cliAgent(spec) {
|
|
283
|
+
const f = jsonFile(spec);
|
|
284
|
+
return {
|
|
285
|
+
found: () => has(spec.bin),
|
|
286
|
+
state: f.state,
|
|
287
|
+
add: (name, url, ctx) => (spec.signsInOnAdd ? runShown : runListed)(spec.bin, spec.addArgs(name, url, ctx.scope), { cwd: ctx.dir }),
|
|
288
|
+
// without a remove command (OpenCode), the entry comes out of the file
|
|
289
|
+
remove: spec.removeArgs ? (name, ctx) => runListed(spec.bin, spec.removeArgs(name, ctx.scope), { cwd: ctx.dir }) : f.remove,
|
|
290
|
+
...spec,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// TOML (Codex's project file): only the [mcp_servers.<name>] table is read or written; the rest stays as it is.
|
|
295
|
+
const tomlHeader = (name) => new RegExp(`^\\[mcp_servers\\.(?:"${name}"|${name})\\][ \\t]*(?:#.*)?$`, 'm');
|
|
296
|
+
function tomlServer(file, name) {
|
|
297
|
+
if (!exists(file)) return null;
|
|
298
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
299
|
+
const m = tomlHeader(name).exec(text);
|
|
300
|
+
if (!m) return null;
|
|
301
|
+
const body = text.slice(m.index + m[0].length).split(/^\s*\[/m)[0];
|
|
302
|
+
return { url: /^\s*url\s*=\s*"([^"]*)"/m.exec(body)?.[1] };
|
|
303
|
+
}
|
|
304
|
+
function tomlAdd(file, name, url) {
|
|
305
|
+
const text = exists(file) ? fs.readFileSync(file, 'utf8') : '';
|
|
306
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
307
|
+
backup(file);
|
|
308
|
+
const gap = !text || text.endsWith('\n\n') ? '' : text.endsWith('\n') ? '\n' : '\n\n';
|
|
309
|
+
fs.writeFileSync(file, `${text}${gap}[mcp_servers.${name}]\nurl = ${JSON.stringify(url)}\n`);
|
|
310
|
+
}
|
|
311
|
+
function tomlRemove(file, name) {
|
|
312
|
+
if (!exists(file)) return false;
|
|
313
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
314
|
+
const m = tomlHeader(name).exec(text);
|
|
315
|
+
if (!m) return false;
|
|
316
|
+
const start = m.index + m[0].length;
|
|
317
|
+
const next = text.slice(start).search(/^\s*\[/m);
|
|
318
|
+
backup(file);
|
|
319
|
+
fs.writeFileSync(file, (text.slice(0, m.index) + (next < 0 ? '' : text.slice(start + next))).replace(/\n{3,}/g, '\n\n'));
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ---------- the browser and the clipboard (for the chat apps) ----------
|
|
324
|
+
|
|
325
|
+
const NO_OPEN = () => !!args.flags['no-browser'] || !!env.STETS_NO_OPEN;
|
|
326
|
+
function openUrl(u) {
|
|
327
|
+
if (NO_OPEN()) return false;
|
|
328
|
+
const [cmd, a] = process.platform === 'darwin' ? ['open', [u]] : WIN ? ['cmd', ['/c', 'start', '""', u]] : ['xdg-open', [u]];
|
|
329
|
+
return spawnSync(cmd, a, { stdio: 'ignore' }).status === 0;
|
|
330
|
+
}
|
|
331
|
+
function copy(text) {
|
|
332
|
+
if (NO_OPEN()) return false;
|
|
333
|
+
const tries = process.platform === 'darwin' ? [['pbcopy', []]] : WIN ? [['clip', []]]
|
|
334
|
+
: [['wl-copy', []], ['xclip', ['-selection', 'clipboard']], ['xsel', ['--clipboard', '--input']]];
|
|
335
|
+
for (const [c, a] of tries) if (spawnSync(c, a, { input: text, stdio: ['pipe', 'ignore', 'ignore'] }).status === 0) return true;
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ---------- where ----------
|
|
340
|
+
|
|
341
|
+
const WHERE = {
|
|
342
|
+
global: 'In all your projects',
|
|
343
|
+
project: 'Only in this project, shared through git',
|
|
344
|
+
local: 'Only in this project, just for you',
|
|
345
|
+
};
|
|
346
|
+
function projectDir() {
|
|
347
|
+
const r = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
348
|
+
return r.status === 0 && r.stdout.trim() ? r.stdout.trim() : null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ---------- the agents ----------
|
|
352
|
+
|
|
353
|
+
// Gemini CLI and OpenCode (checked 2026-11-23 against Gemini 0.70.0 and OpenCode 1.19.6: add, state, a full
|
|
354
|
+
// sign-in ending in Connected, remove).
|
|
355
|
+
const noAnsi = (s) => s.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '');
|
|
356
|
+
/** One fixed, empty folder to run an agent in for global scope: it then sees only your own servers, starts no
|
|
357
|
+
* project's commands, and the agent records just this one folder (Gemini notes every cwd in ~/.gemini). */
|
|
358
|
+
function neutralDir() {
|
|
359
|
+
const d = path.join(os.tmpdir(), 'stets-agent-check');
|
|
360
|
+
fs.mkdirSync(d, { recursive: true });
|
|
361
|
+
return d;
|
|
362
|
+
}
|
|
363
|
+
const trusted = () => ({ ...env, GEMINI_CLI_TRUST_WORKSPACE: 'true' });
|
|
364
|
+
const geminiFile = (ctx) => (ctx.scope === 'project'
|
|
365
|
+
? path.join(ctx.dir, '.gemini', 'settings.json')
|
|
366
|
+
: path.join(env.GEMINI_CLI_HOME || home, '.gemini', 'settings.json'));
|
|
367
|
+
|
|
368
|
+
/** `gemini mcp list` -> { listed, url, status, token stored, folder untrusted } for one name. */
|
|
369
|
+
function parseGeminiList(out, name) {
|
|
370
|
+
const t = noAnsi(out);
|
|
371
|
+
const m = new RegExp(`^\\S+\\s+${name}: (\\S+) \\((\\w+)\\) - (\\w+)`, 'm').exec(t);
|
|
372
|
+
return {
|
|
373
|
+
listed: !!m, url: m?.[1], status: m?.[3] || '',
|
|
374
|
+
token: t.includes(`Found stored OAuth token for server '${name}'`),
|
|
375
|
+
untrusted: /folder is untrusted/.test(t),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const ocDir = () => path.join(env.XDG_CONFIG_HOME || path.join(home, '.config'), 'opencode');
|
|
380
|
+
/** OpenCode's config files for a scope, in the order `opencode mcp add` picks (it writes the first that exists,
|
|
381
|
+
* else opencode.json). Global also loads the older config.json. */
|
|
382
|
+
function ocFiles(ctx) {
|
|
383
|
+
if (ctx.scope !== 'project') return ['opencode.json', 'opencode.jsonc', 'config.json'].map((f) => path.join(ocDir(), f));
|
|
384
|
+
const d = ctx.dir;
|
|
385
|
+
return [path.join(d, 'opencode.json'), path.join(d, 'opencode.jsonc'), path.join(d, '.opencode', 'opencode.json'), path.join(d, '.opencode', 'opencode.jsonc')];
|
|
386
|
+
}
|
|
387
|
+
/** The file that holds `name` (or where a new one goes), and its parsed JSON or the reason it can't be read. */
|
|
388
|
+
function ocFind(ctx, name) {
|
|
389
|
+
const files = ocFiles(ctx).filter(exists);
|
|
390
|
+
for (const file of files) {
|
|
391
|
+
const { obj, error, comments } = readJson(file);
|
|
392
|
+
if (error || comments) return { file, error: error || 'has comments' }; // left alone (the CLI's rule)
|
|
393
|
+
if (obj.mcp && obj.mcp[name]) return { file, obj };
|
|
394
|
+
}
|
|
395
|
+
const file = files[0] || ocFiles(ctx)[0];
|
|
396
|
+
const r = readJson(file);
|
|
397
|
+
return r.comments ? { file, error: 'has comments' } : { file, ...r };
|
|
398
|
+
}
|
|
399
|
+
/** `opencode mcp list` (clack output, ANSI even when piped) -> the status words for one name. */
|
|
400
|
+
function parseOpencodeList(out, name) {
|
|
401
|
+
const m = new RegExp(`(?:^|\\s)${name} (connected|needs authentication|needs client registration|failed|disabled|not initialized)\\b`, 'm').exec(noAnsi(out));
|
|
402
|
+
return m ? m[1] : '';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Each agent: detect via state() (null = not on this computer), add, an optional login, remove.
|
|
408
|
+
* state() answers: is a server with this name there (in this scope), at which URL, and can the agent use it.
|
|
409
|
+
* `checked`: how far its flow was checked on 2026-11-23 (docs/proposals/cli.md); not fully checked shows "beta".
|
|
410
|
+
*/
|
|
411
|
+
const AGENTS = [
|
|
412
|
+
{
|
|
413
|
+
id: 'claude', name: 'Claude Code', scopes: ['global', 'project', 'local'], checked: 'full', found: () => has('claude'),
|
|
414
|
+
async state(name, url, ctx) {
|
|
415
|
+
const r = await runAsync('claude', ['mcp', 'get', name], { cwd: ctx.dir });
|
|
416
|
+
if (r.missing) return null;
|
|
417
|
+
if (!r.ok) {
|
|
418
|
+
// A Stets connector added on claude.ai also shows up in Claude Code (signed in with claude.ai).
|
|
419
|
+
const c = await runAsync('claude', ['mcp', 'get', 'claude.ai Stets']);
|
|
420
|
+
return { present: false, viaClaudeAi: c.ok && sameUrl(url, DEFAULT_URL) && /connected/i.test(c.out) };
|
|
421
|
+
}
|
|
422
|
+
const status = /^\s*Status:\s*(.+)$/m.exec(r.out)?.[1] ?? '';
|
|
423
|
+
const scope = /^\s*Scope:\s*(.+)$/m.exec(r.out)?.[1] ?? '';
|
|
424
|
+
return {
|
|
425
|
+
present: true,
|
|
426
|
+
// "User config (available in all your projects)", "Project config (shared via .mcp.json)", "Local config (…)"
|
|
427
|
+
where: /^local/i.test(scope) ? 'local' : /^project/i.test(scope) ? 'project' : 'global',
|
|
428
|
+
url: /^\s*URL:\s*(\S+)/m.exec(r.out)?.[1],
|
|
429
|
+
ready: /connected/i.test(status) && !/fail|not/i.test(status),
|
|
430
|
+
pending: /pending|approv/i.test(status),
|
|
431
|
+
needsLogin: /auth/i.test(status),
|
|
432
|
+
failed: /fail/i.test(status),
|
|
433
|
+
status: status.replace(/^[^A-Za-z]+/, ''),
|
|
434
|
+
};
|
|
435
|
+
},
|
|
436
|
+
add(name, url, ctx) {
|
|
437
|
+
const argv = ['mcp', 'add', '--transport', 'http', '--scope', { global: 'user', project: 'project', local: 'local' }[ctx.scope], name, url];
|
|
438
|
+
say(dim(` $ claude ${argv.join(' ')}`));
|
|
439
|
+
const r = run('claude', argv, { cwd: ctx.dir });
|
|
440
|
+
if (!r.ok) say(r.out.trim().split('\n').map((l) => ` ${l}`).join('\n'));
|
|
441
|
+
return r;
|
|
442
|
+
},
|
|
443
|
+
login: (name, ctx) => runShown('claude', ['mcp', 'login', name, ...(args.flags['no-browser'] ? ['--no-browser'] : [])], { cwd: ctx.dir }),
|
|
444
|
+
later: (name) => `claude mcp login ${name}`,
|
|
445
|
+
check: (name) => `claude mcp get ${name}`,
|
|
446
|
+
remove(name, ctx) {
|
|
447
|
+
run('claude', ['mcp', 'logout', name], { cwd: ctx.dir }); // the stored token, if any
|
|
448
|
+
const s = { global: 'user', project: 'project', local: 'local' }[ctx.scope];
|
|
449
|
+
say(dim(` $ claude mcp remove ${name} --scope ${s}`));
|
|
450
|
+
return run('claude', ['mcp', 'remove', name, '--scope', s], { cwd: ctx.dir });
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
id: 'codex', name: 'Codex CLI', scopes: ['global', 'project'], checked: 'signin', found: () => has('codex'),
|
|
455
|
+
async state(name, url, ctx) {
|
|
456
|
+
const r = await runAsync('codex', ['mcp', 'list', '--json'], { cwd: ctx.dir });
|
|
457
|
+
if (r.missing) return null;
|
|
458
|
+
let list = [];
|
|
459
|
+
try { list = JSON.parse(r.out.slice(r.out.indexOf('['))); } catch { /* an old Codex: treat as not set up */ }
|
|
460
|
+
const s = list.find((x) => x && x.name === name);
|
|
461
|
+
if (ctx.scope === 'global' && !tomlServer(path.join(env.CODEX_HOME || path.join(home, '.codex'), 'config.toml'), name)) {
|
|
462
|
+
return { present: false }; // the list also shows a project's servers: only the global file counts here
|
|
463
|
+
}
|
|
464
|
+
if (ctx.scope === 'project') {
|
|
465
|
+
const t = tomlServer(path.join(ctx.dir, '.codex', 'config.toml'), name);
|
|
466
|
+
if (!t) return { present: false };
|
|
467
|
+
// Codex reads a project's .codex/config.toml only in folders you trust.
|
|
468
|
+
if (!s) return { present: true, where: 'project', url: t.url, untrusted: true, status: 'folder not trusted in Codex yet' };
|
|
469
|
+
} else if (!s) return { present: false };
|
|
470
|
+
const auth = s.auth_status || '';
|
|
471
|
+
return {
|
|
472
|
+
present: true,
|
|
473
|
+
where: ctx.scope,
|
|
474
|
+
url: s.transport && s.transport.url,
|
|
475
|
+
// o_auth: signed in; unsupported: the server needs no sign-in (a local Stets)
|
|
476
|
+
ready: s.enabled !== false && ['o_auth', 'bearer_token', 'unsupported'].includes(auth),
|
|
477
|
+
needsLogin: auth === 'not_logged_in',
|
|
478
|
+
status: s.enabled === false ? 'turned off in Codex' : auth.replace(/_/g, ' '),
|
|
479
|
+
};
|
|
480
|
+
},
|
|
481
|
+
// Codex starts the sign-in by itself when it sees the server supports it, so this one runs in view.
|
|
482
|
+
signsInOnAdd: (ctx) => ctx.scope === 'global',
|
|
483
|
+
add(name, url, ctx) {
|
|
484
|
+
if (ctx.scope === 'global') return runShown('codex', ['mcp', 'add', name, '--url', url]);
|
|
485
|
+
const file = path.join(ctx.dir, '.codex', 'config.toml');
|
|
486
|
+
tomlAdd(file, name, url);
|
|
487
|
+
say(dim(` wrote [mcp_servers.${name}] into ${tilde(file)}`) + backupNote(file));
|
|
488
|
+
return { ok: true };
|
|
489
|
+
},
|
|
490
|
+
login: (name, ctx) => runShown('codex', ['mcp', 'login', name, ...(args.flags['no-browser'] ? ['--no-browser'] : [])], { cwd: ctx.dir }),
|
|
491
|
+
later: (name) => `codex mcp login ${name}`,
|
|
492
|
+
check: (name) => `codex mcp get ${name}`,
|
|
493
|
+
trustHint: 'Codex reads this file once you trust the folder: start codex here, trust it, then run',
|
|
494
|
+
remove(name, ctx) {
|
|
495
|
+
run('codex', ['mcp', 'logout', name], { cwd: ctx.dir });
|
|
496
|
+
if (ctx.scope === 'project') {
|
|
497
|
+
const file = path.join(ctx.dir, '.codex', 'config.toml');
|
|
498
|
+
const ok = tomlRemove(file, name);
|
|
499
|
+
if (ok) say(dim(` removed [mcp_servers.${name}] from ${tilde(file)}`));
|
|
500
|
+
return { ok, out: ok ? '' : 'not there' };
|
|
501
|
+
}
|
|
502
|
+
say(dim(` $ codex mcp remove ${name}`));
|
|
503
|
+
return run('codex', ['mcp', 'remove', name]);
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
id: 'gemini', name: 'Gemini CLI', scopes: ['global', 'project'], checked: 'signin', found: () => has('gemini'),
|
|
508
|
+
async state(name, url, ctx) {
|
|
509
|
+
const project = ctx.scope === 'project';
|
|
510
|
+
const file = geminiFile(ctx);
|
|
511
|
+
const { obj, error } = readJson(file);
|
|
512
|
+
if (error) return { present: false, fileError: `${tilde(file)} ${error}` };
|
|
513
|
+
const e = obj.mcpServers && obj.mcpServers[name];
|
|
514
|
+
if (!e) return { present: false };
|
|
515
|
+
// global: the neutral folder, trusted for this one command (in an untrusted folder Gemini lists even your
|
|
516
|
+
// own servers as "Disabled"). project: as Gemini sees it there, without overriding its trust.
|
|
517
|
+
const r = await runAsync('gemini', ['mcp', 'list'], project ? { cwd: ctx.dir } : { cwd: neutralDir(), env: trusted() });
|
|
518
|
+
if (r.missing) return null;
|
|
519
|
+
const l = parseGeminiList(r.out, name);
|
|
520
|
+
if (project && l.untrusted) return { present: true, where: 'project', url: e.httpUrl || e.url, untrusted: true, status: 'folder not trusted in Gemini yet' };
|
|
521
|
+
return {
|
|
522
|
+
present: true, where: ctx.scope, url: e.httpUrl || e.url,
|
|
523
|
+
ready: l.status === 'Connected',
|
|
524
|
+
// "Disconnected" = not signed in, sign-in refused, or server down (setup() checks reachability first)
|
|
525
|
+
needsLogin: l.status === 'Disconnected',
|
|
526
|
+
status: l.status === 'Disconnected' && l.token ? 'stored sign-in not accepted' : l.status.toLowerCase(),
|
|
527
|
+
};
|
|
528
|
+
},
|
|
529
|
+
add(name, url, ctx) {
|
|
530
|
+
const argv = ['mcp', 'add', '--scope', ctx.scope === 'project' ? 'project' : 'user', '--transport', 'http', name, url];
|
|
531
|
+
say(dim(` $ gemini ${argv.join(' ')}`));
|
|
532
|
+
// project: Gemini refuses to write settings in a folder not trusted in Gemini; the person asked for it here.
|
|
533
|
+
// It writes <cwd>/.gemini/settings.json, so cwd must be the project root.
|
|
534
|
+
const r = run('gemini', argv, ctx.scope === 'project' ? { cwd: ctx.dir, env: trusted() } : {});
|
|
535
|
+
if (!r.ok) say(r.out.trim().split('\n').map((l) => ` ${l}`).join('\n'));
|
|
536
|
+
return r;
|
|
537
|
+
},
|
|
538
|
+
// No `gemini mcp login`. The headless run of the /mcp auth command signs in and then exits 42, also on
|
|
539
|
+
// success (setup() re-checks state anyway). It asks "[Y/n]" on the terminal, opens the browser itself
|
|
540
|
+
// (ignores BROWSER, NO_BROWSER), and needs Gemini's own sign-in set up (else exit 41). Without a terminal,
|
|
541
|
+
// Gemini would prepend stdin to the -p text, so: terminal only.
|
|
542
|
+
login(name, ctx) {
|
|
543
|
+
if (!TTY || args.flags['no-browser']) { say(dim(' Gemini CLI signs in only with a browser on this computer, from a terminal.')); return { ok: false }; }
|
|
544
|
+
return ctx.scope === 'project'
|
|
545
|
+
? runShown('gemini', ['-p', `/mcp auth ${name}`], { cwd: ctx.dir })
|
|
546
|
+
: runShown('gemini', ['--skip-trust', '-p', `/mcp auth ${name}`], { cwd: neutralDir() });
|
|
547
|
+
},
|
|
548
|
+
later: (name) => `gemini, then /mcp auth ${name}`,
|
|
549
|
+
check: () => 'gemini mcp list',
|
|
550
|
+
trustHint: 'Gemini reads this project\'s settings once you trust the folder: start gemini here, trust it, and sign in',
|
|
551
|
+
remove(name, ctx) {
|
|
552
|
+
const s = ctx.scope === 'project' ? 'project' : 'user';
|
|
553
|
+
say(dim(` $ gemini mcp remove --scope ${s} ${name}`));
|
|
554
|
+
const r = run('gemini', ['mcp', 'remove', '--scope', s, name], s === 'project' ? { cwd: ctx.dir, env: trusted() } : {});
|
|
555
|
+
// Exit 0 also for "not found". No sign-out command: the token stays in ~/.gemini/mcp-oauth-tokens.json
|
|
556
|
+
// (keyed by name only). Removing that array element (with a backup) is the caller's decision.
|
|
557
|
+
const tokens = path.join(env.GEMINI_CLI_HOME || home, '.gemini', 'mcp-oauth-tokens.json');
|
|
558
|
+
if (r.ok && exists(tokens) && fs.readFileSync(tokens, 'utf8').includes(`"${name}"`)) {
|
|
559
|
+
say(dim(` Gemini has no sign-out: its Stets sign-in stays in ${tilde(tokens)} (under "${name}").`));
|
|
560
|
+
}
|
|
561
|
+
return { ok: r.ok && /removed from/.test(r.out), out: r.out };
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
id: 'opencode', name: 'OpenCode', scopes: ['global', 'project'], checked: 'signin', found: () => has('opencode'),
|
|
566
|
+
async state(name, url, ctx) {
|
|
567
|
+
const cwd = ctx.scope === 'project' ? ctx.dir : neutralDir();
|
|
568
|
+
let e;
|
|
569
|
+
if (ctx.scope === 'project') {
|
|
570
|
+
const f = ocFind(ctx, name);
|
|
571
|
+
if (f.error) return { present: false, fileError: `${tilde(f.file)} ${f.error}` };
|
|
572
|
+
e = f.obj.mcp && f.obj.mcp[name];
|
|
573
|
+
} else {
|
|
574
|
+
// the resolved config as JSON (reads JSONC too); outside a project it's the global one only
|
|
575
|
+
const c = await runAsync('opencode', ['debug', 'config'], { cwd });
|
|
576
|
+
try { e = JSON.parse(c.out.slice(c.out.indexOf('{'))).mcp?.[name]; } catch { e = undefined; }
|
|
577
|
+
}
|
|
578
|
+
if (!e) return { present: false };
|
|
579
|
+
// `mcp list` connects to every server (and registers OAuth clients), so only once Stets is there
|
|
580
|
+
const r = await runAsync('opencode', ['mcp', 'list'], { cwd });
|
|
581
|
+
const s = parseOpencodeList(r.out, name);
|
|
582
|
+
return {
|
|
583
|
+
present: true, where: ctx.scope, url: e.url,
|
|
584
|
+
ready: s === 'connected',
|
|
585
|
+
needsLogin: s === 'needs authentication',
|
|
586
|
+
failed: s === 'failed' || s === 'needs client registration',
|
|
587
|
+
status: s || (e.enabled === false ? 'disabled' : 'unknown'),
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
add(name, url, ctx) {
|
|
591
|
+
if (ctx.scope === 'global') {
|
|
592
|
+
const argv = ['mcp', 'add', name, '--url', url];
|
|
593
|
+
say(dim(` $ opencode ${argv.join(' ')}`));
|
|
594
|
+
const r = run('opencode', argv);
|
|
595
|
+
if (!r.ok) say(r.out.trim().split('\n').map((l) => ` ${l}`).join('\n'));
|
|
596
|
+
return r;
|
|
597
|
+
}
|
|
598
|
+
// No flag for project scope (only the interactive `opencode mcp add`), so write the file it would write.
|
|
599
|
+
const { file, obj, error } = ocFind(ctx, name);
|
|
600
|
+
if (error) { say(` ${tilde(file)} ${error}: add "${name}": {"type":"remote","url":"${url}"} under "mcp" yourself.`); return { ok: false }; }
|
|
601
|
+
obj.mcp = obj.mcp && typeof obj.mcp === 'object' ? obj.mcp : {};
|
|
602
|
+
obj.mcp[name] = { type: 'remote', url };
|
|
603
|
+
writeJson(file, obj);
|
|
604
|
+
say(dim(` wrote "${name}" into ${tilde(file)}`) + backupNote(file));
|
|
605
|
+
return { ok: true };
|
|
606
|
+
},
|
|
607
|
+
// Opens the browser itself (no --no-browser; BROWSER ignored on macOS), listens on 127.0.0.1:19876 (fixed),
|
|
608
|
+
// works without a terminal. Call it only when not ready: when signed in already, it asks "Re-authenticate?".
|
|
609
|
+
login(name, ctx) {
|
|
610
|
+
if (args.flags['no-browser']) { say(dim(' OpenCode signs in only with a browser on this computer (it listens on port 19876).')); return { ok: false }; }
|
|
611
|
+
return runShown('opencode', ['mcp', 'auth', name], { cwd: ctx.dir });
|
|
612
|
+
},
|
|
613
|
+
later: (name) => `opencode mcp auth ${name}`,
|
|
614
|
+
check: () => 'opencode mcp list',
|
|
615
|
+
remove(name, ctx) {
|
|
616
|
+
run('opencode', ['mcp', 'logout', name], { cwd: ctx.dir }); // tokens + client registration; exit 0 if none
|
|
617
|
+
// 1.19.6 has no `opencode mcp remove`: take the entry out of the file.
|
|
618
|
+
const { file, obj, error } = ocFind(ctx, name);
|
|
619
|
+
if (error || !obj.mcp || !obj.mcp[name]) return { ok: false, out: error ? `${tilde(file)} ${error}: remove "${name}" under "mcp" yourself` : 'not there' };
|
|
620
|
+
delete obj.mcp[name];
|
|
621
|
+
writeJson(file, obj);
|
|
622
|
+
say(dim(` removed "${name}" from ${tilde(file)}`));
|
|
623
|
+
return { ok: true };
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
cliAgent({
|
|
627
|
+
id: 'copilot', name: 'GitHub Copilot CLI', bin: 'copilot', scopes: ['global'], checked: 'docs', key: 'mcpServers',
|
|
628
|
+
file: () => path.join(env.COPILOT_HOME || path.join(home, '.copilot'), 'mcp-config.json'),
|
|
629
|
+
addArgs: (n, u) => ['mcp', 'add', '--transport', 'http', n, u],
|
|
630
|
+
removeArgs: (n) => ['mcp', 'remove', n],
|
|
631
|
+
hint: 'In Copilot, type /mcp auth stets to sign in.',
|
|
632
|
+
}),
|
|
633
|
+
{
|
|
634
|
+
...jsonFile({
|
|
635
|
+
key: 'mcpServers', entry: (u) => ({ url: u }),
|
|
636
|
+
file: (scope, dir) => path.join(scope === 'project' ? dir : home, '.cursor', 'mcp.json'),
|
|
637
|
+
link: (n, u) => `cursor://anysphere.cursor-deeplink/mcp/install?name=${n}&config=${Buffer.from(JSON.stringify({ url: u })).toString('base64')}`,
|
|
638
|
+
}),
|
|
639
|
+
id: 'cursor', name: 'Cursor', scopes: ['global', 'project'], checked: 'signin',
|
|
640
|
+
found: () => hasApp('Cursor') || has('cursor') || has('cursor-agent'),
|
|
641
|
+
hint: 'Cursor asks you to sign in to Stets the first time (Settings, MCP). Its terminal agent: cursor-agent mcp login stets',
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
...jsonFile({
|
|
645
|
+
key: 'servers', entry: (u) => ({ type: 'http', url: u }),
|
|
646
|
+
file: (scope, dir) => (scope === 'project' ? path.join(dir, '.vscode', 'mcp.json')
|
|
647
|
+
: path.join(process.platform === 'darwin' ? path.join(home, 'Library', 'Application Support') : configHome(), 'Code', 'User', 'mcp.json')),
|
|
648
|
+
link: (n, u) => `vscode:mcp/install?${encodeURIComponent(JSON.stringify({ name: n, type: 'http', url: u }))}`,
|
|
649
|
+
}),
|
|
650
|
+
id: 'vscode', name: 'VS Code', scopes: ['global', 'project'], checked: 'add',
|
|
651
|
+
found: () => has('code') || hasApp('Visual Studio Code'),
|
|
652
|
+
hint: 'VS Code asks you to sign in to Stets when it starts the server (MCP servers, stets, Authenticate).',
|
|
653
|
+
},
|
|
654
|
+
cliAgent({
|
|
655
|
+
id: 'antigravity', name: 'Antigravity', bin: 'agy', scopes: ['global'], checked: 'add', key: 'mcpServers',
|
|
656
|
+
file: () => path.join(home, '.gemini', 'config', 'mcp_config.json'),
|
|
657
|
+
addArgs: (n, u) => ['mcp', 'add', n, u],
|
|
658
|
+
removeArgs: (n) => ['mcp', 'remove', n],
|
|
659
|
+
hint: 'Antigravity asks you to sign in to Stets the first time it uses it.',
|
|
660
|
+
}),
|
|
661
|
+
{
|
|
662
|
+
id: 'vibe', name: 'Mistral Vibe', scopes: ['global'], checked: 'add', found: () => has('vibe'),
|
|
663
|
+
async state(name) {
|
|
664
|
+
const file = path.join(env.VIBE_HOME || path.join(home, '.vibe'), 'config.toml');
|
|
665
|
+
if (!exists(file)) return { present: false };
|
|
666
|
+
const block = fs.readFileSync(file, 'utf8').split(/^\[\[mcp_servers\]\]/m).slice(1).find((b) => new RegExp(`^\\s*name\\s*=\\s*"${name}"`, 'm').test(b));
|
|
667
|
+
return block ? { present: true, where: 'global', url: /^\s*url\s*=\s*"([^"]*)"/m.exec(block)?.[1], ready: true, inApp: true } : { present: false };
|
|
668
|
+
},
|
|
669
|
+
// Vibe signs in during its add when the server offers it, like Codex.
|
|
670
|
+
signsInOnAdd: () => !args.flags['no-login'],
|
|
671
|
+
add: (n, u) => runShown('vibe', ['mcp', 'add', n, '--url', u, ...(args.flags['no-login'] ? ['--no-login'] : [])]),
|
|
672
|
+
remove: (n) => runListed('vibe', ['mcp', 'remove', n]),
|
|
673
|
+
hint: 'If Vibe asks, type /mcp login stets in it.',
|
|
674
|
+
},
|
|
675
|
+
cliAgent({
|
|
676
|
+
id: 'droid', name: 'Factory Droid', bin: 'droid', scopes: ['global'], checked: 'docs', key: 'mcpServers',
|
|
677
|
+
file: () => path.join(home, '.factory', 'mcp.json'),
|
|
678
|
+
addArgs: (n, u) => ['mcp', 'add', n, u, '--type', 'http'],
|
|
679
|
+
removeArgs: (n) => ['mcp', 'remove', n],
|
|
680
|
+
hint: 'Sign in from a terminal: droid mcp auth',
|
|
681
|
+
}),
|
|
682
|
+
{
|
|
683
|
+
...jsonFile({
|
|
684
|
+
key: 'mcpServers', entry: (u) => ({ url: u }),
|
|
685
|
+
file: (scope, dir) => path.join(scope === 'project' ? dir : env.KIRO_HOME || path.join(home, '.kiro'), ...(scope === 'project' ? ['.kiro'] : []), 'settings', 'mcp.json'),
|
|
686
|
+
link: (n, u) => `https://kiro.dev/launch/mcp/add?name=${n}&config=${encodeURIComponent(JSON.stringify({ url: u }))}`,
|
|
687
|
+
}),
|
|
688
|
+
id: 'kiro', name: 'Kiro', scopes: ['global', 'project'], checked: 'docs',
|
|
689
|
+
found: () => has('kiro-cli') || hasApp('Kiro'),
|
|
690
|
+
hint: 'Kiro asks you to sign in to Stets when it connects (turn on MCP support in its settings).',
|
|
691
|
+
},
|
|
692
|
+
cliAgent({
|
|
693
|
+
id: 'devin', name: 'Devin (Windsurf)', bin: 'devin', scopes: ['global', 'project', 'local'], checked: 'docs', key: 'mcpServers',
|
|
694
|
+
file: (scope, dir) => (scope === 'global' ? path.join(configHome(), 'devin', 'mcp_config.json')
|
|
695
|
+
: path.join(dir, '.devin', scope === 'local' ? 'mcp_config.local.json' : 'mcp_config.json')),
|
|
696
|
+
addArgs: (n, u, scope) => ['mcp', 'add', '-s', { global: 'user', project: 'project', local: 'local' }[scope], n, u],
|
|
697
|
+
removeArgs: (n, scope) => ['mcp', 'remove', '-s', { global: 'user', project: 'project', local: 'local' }[scope], n],
|
|
698
|
+
hint: 'Devin asks you to sign in to Stets on first use (or: devin mcp login stets).',
|
|
699
|
+
}),
|
|
700
|
+
cliAgent({
|
|
701
|
+
id: 'qwen', name: 'Qwen Code', bin: 'qwen', scopes: ['global', 'project'], checked: 'docs', key: 'mcpServers',
|
|
702
|
+
file: (scope, dir) => path.join(scope === 'project' ? dir : home, '.qwen', 'settings.json'),
|
|
703
|
+
addArgs: (n, u, scope) => ['mcp', 'add', '--transport', 'http', '-s', scope === 'project' ? 'project' : 'user', n, u],
|
|
704
|
+
removeArgs: (n, scope) => ['mcp', 'remove', '-s', scope === 'project' ? 'project' : 'user', n],
|
|
705
|
+
hint: 'In Qwen Code, type /mcp to sign in to Stets.',
|
|
706
|
+
}),
|
|
707
|
+
{
|
|
708
|
+
...jsonFile({ key: 'context_servers', entry: (u) => ({ url: u }), manual: true, file: () => path.join(configHome(), 'zed', 'settings.json') }),
|
|
709
|
+
id: 'zed', name: 'Zed', scopes: ['global'], checked: 'docs',
|
|
710
|
+
found: () => has('zed') || hasApp('Zed'),
|
|
711
|
+
hint: 'Zed asks you to sign in to Stets when it starts the server.',
|
|
712
|
+
},
|
|
713
|
+
];
|
|
714
|
+
|
|
715
|
+
/** The chat apps: a connector there is account-wide (and a Claude one shows up in Claude Code too). They need
|
|
716
|
+
* a few clicks in the app, so the CLI opens the right page and says what to click. Only for stets.app itself:
|
|
717
|
+
* the apps reach public addresses only. */
|
|
718
|
+
const APPS = [
|
|
719
|
+
{
|
|
720
|
+
id: 'claude-app', name: 'Claude app', sub: 'desktop, web, phone', scopes: ['global'], app: true, checked: 'guide',
|
|
721
|
+
// Anthropic's documented install link: it opens the Add dialog with the name and address filled in.
|
|
722
|
+
page: (url) => `https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=Stets&connectorUrl=${encodeURIComponent(url)}`,
|
|
723
|
+
manage: 'https://claude.ai/customize/connectors',
|
|
724
|
+
guide: 'https://stets.app/start/claude',
|
|
725
|
+
steps: ['Check the name (Stets) and the address, and click Add.', 'Click Connect, and sign in to Stets.'],
|
|
726
|
+
note: 'Any plan; on Team and Enterprise an Owner adds it for everyone.',
|
|
727
|
+
async state(name, url) {
|
|
728
|
+
if (!sameUrl(url, DEFAULT_URL)) return null;
|
|
729
|
+
if (!has('claude')) return { present: false, unknown: true };
|
|
730
|
+
const c = await runAsync('claude', ['mcp', 'get', 'claude.ai Stets']);
|
|
731
|
+
return c.ok && /connected/i.test(c.out) ? { present: true, where: 'global', url, ready: true } : { present: false };
|
|
732
|
+
},
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
id: 'chatgpt', name: 'ChatGPT', sub: 'web', scopes: ['global'], app: true, checked: 'guide',
|
|
736
|
+
page: () => 'https://chatgpt.com/plugins',
|
|
737
|
+
manage: 'https://chatgpt.com/plugins',
|
|
738
|
+
guide: 'https://stets.app/start/chatgpt',
|
|
739
|
+
copyUrl: true,
|
|
740
|
+
steps: ['Click +, then "Add custom MCP server".', 'Name: Stets. URL: paste it. Keep OAuth, tick the box, and create it.', 'Click Connect, and sign in to Stets.'],
|
|
741
|
+
note: 'Custom MCP servers depend on your ChatGPT plan (Business, Enterprise and Edu have them).',
|
|
742
|
+
async state(name, url) { return sameUrl(url, DEFAULT_URL) ? { present: false, unknown: true } : null; },
|
|
743
|
+
},
|
|
744
|
+
];
|
|
745
|
+
for (const a of APPS) {
|
|
746
|
+
a.add = (name, url) => {
|
|
747
|
+
const copied = a.copyUrl && copy(url);
|
|
748
|
+
const page = a.page(url);
|
|
749
|
+
const opened = openUrl(page);
|
|
750
|
+
say(` ${opened ? 'Your browser opened' : 'Open'} ${bold(page)}`);
|
|
751
|
+
if (a.copyUrl) say(` ${copied ? 'Copied to your clipboard' : 'The address to paste'}: ${bold(url)}`);
|
|
752
|
+
a.steps.forEach((st, i) => say(` ${i + 1}. ${st}`));
|
|
753
|
+
say(dim(` ${a.note} With pictures: ${a.guide}`));
|
|
754
|
+
return { ok: true, guided: true };
|
|
755
|
+
};
|
|
756
|
+
a.remove = () => ({ ok: false, out: `remove it in ${a.name}: ${a.manage}` });
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/** Waits for Enter (true) or q / s / Esc (false); without a terminal, false at once. */
|
|
760
|
+
function waitKey(prompt) {
|
|
761
|
+
if (!TTY) return Promise.resolve(false);
|
|
762
|
+
out.write(` ${prompt} `);
|
|
763
|
+
return new Promise((resolve) => {
|
|
764
|
+
const stdin = process.stdin;
|
|
765
|
+
const onKey = (buf) => {
|
|
766
|
+
const k = buf.toString();
|
|
767
|
+
if (k === '\x03') { say(); process.exit(130); }
|
|
768
|
+
if (!['\r', '\n', 'q', 's', 'Q', 'S', '\x1b'].includes(k)) return;
|
|
769
|
+
stdin.off('data', onKey); stdin.setRawMode(false); stdin.pause();
|
|
770
|
+
say();
|
|
771
|
+
resolve(k === '\r' || k === '\n');
|
|
772
|
+
};
|
|
773
|
+
stdin.setRawMode(true); stdin.resume(); stdin.on('data', onKey);
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
async function withSpinner(text, work) {
|
|
778
|
+
if (!ANIM) { say(dim(` ${text}`)); return work; }
|
|
779
|
+
hideCursor();
|
|
780
|
+
let i = 0;
|
|
781
|
+
const timer = setInterval(() => out.write(`\r ${dim(G.spin[i++ % G.spin.length])} ${dim(text)}\x1b[K`), 80);
|
|
782
|
+
try { return await work; } finally { clearInterval(timer); out.write('\r\x1b[K'); showCursor(); }
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
async function lookAround(name, url, ctx, { apps = true } = {}) {
|
|
786
|
+
const all = apps ? [...AGENTS, ...APPS] : AGENTS;
|
|
787
|
+
const states = await withSpinner(`Looking for your agents${G.dots}`, Promise.all(all.map((a) => ((a.found && !a.found()) ? null : a.state(name, url, ctx).catch(() => null)))));
|
|
788
|
+
return all.map((a, i) => ({ a, st: states[i] })).filter((x) => x.st);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
function describe(a, st, name, url, scope, statusOnly = false) {
|
|
792
|
+
const d = describeState(a, st, name, url, scope, statusOnly);
|
|
793
|
+
// agents checked from their docs only are never picked for you (nor by --yes): you tick them yourself
|
|
794
|
+
if (a.checked === 'docs' && d.on) d.on = false;
|
|
795
|
+
return d;
|
|
796
|
+
}
|
|
797
|
+
function describeState(a, st, name, url, scope, statusOnly) {
|
|
798
|
+
if (!a.scopes.includes(scope)) return { note: scope === 'local' ? 'has no just-for-you setting' : 'has no setting per project', on: false, locked: true };
|
|
799
|
+
if (st.fileError) return { note: `can't read its settings`, on: false, locked: true };
|
|
800
|
+
if (a.app) {
|
|
801
|
+
if (st.present) return { note: 'connected', on: false };
|
|
802
|
+
if (statusOnly) return { note: st.unknown ? "can't be checked from here" : 'not connected', on: false };
|
|
803
|
+
return { note: 'opens the page; you click Add', on: false };
|
|
804
|
+
}
|
|
805
|
+
if (!st.present) return st.viaClaudeAi ? { note: 'connected through claude.ai', on: false } : { note: 'not set up yet', on: true };
|
|
806
|
+
if (st.where && st.where !== scope) {
|
|
807
|
+
if (st.where === 'global') return { note: 'already in all your projects', on: false };
|
|
808
|
+
if (scope !== 'global') return { note: st.where === 'project' ? 'already in this project (shared)' : 'already in this project, just for you', on: false };
|
|
809
|
+
return { note: 'set up for this project only', on: true };
|
|
810
|
+
}
|
|
811
|
+
if (!sameUrl(st.url, url)) return { note: `has a "${name}" for ${st.url}`, on: false, locked: true };
|
|
812
|
+
if (st.untrusted) return { note: 'added; trust this folder in Codex', on: false };
|
|
813
|
+
if (st.pending) return { note: 'added; approve it when Claude Code asks', on: false };
|
|
814
|
+
if (st.ready) return { note: st.inApp ? 'added; you sign in inside it' : 'connected', on: false };
|
|
815
|
+
if (st.failed) return { note: "added, but it can't connect", on: true };
|
|
816
|
+
return { note: 'added, not signed in yet', on: true };
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// ---------- menus ----------
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* A Stripe-style menu. Checkboxes by default (resolves to the chosen rows); with single, one choice (resolves
|
|
823
|
+
* to that row). Rows with `section` get a divider above the first of them. Resolves to null when the person quits.
|
|
824
|
+
*/
|
|
825
|
+
function picker(title, rows, { single = false } = {}) {
|
|
826
|
+
return new Promise((resolve) => {
|
|
827
|
+
const stdin = process.stdin;
|
|
828
|
+
let at = rows.findIndex((r) => r.on && !r.locked);
|
|
829
|
+
if (at < 0) at = Math.max(0, rows.findIndex((r) => !r.locked));
|
|
830
|
+
let shown = 0;
|
|
831
|
+
const labelW = Math.max(...rows.map((r) => visible(r.label))) + 3;
|
|
832
|
+
const room = Math.max(10, (out.columns || 80) - labelW - 14);
|
|
833
|
+
for (const r of rows) if (r.note && r.note.length > room) r.note = r.note.slice(0, room - 1) + (ASCII ? '~' : '…');
|
|
834
|
+
const render = () => {
|
|
835
|
+
const body = ['', ` ${bold(title)}`, ''];
|
|
836
|
+
let section = null;
|
|
837
|
+
rows.forEach((r, i) => {
|
|
838
|
+
if (r.section && r.section !== section) {
|
|
839
|
+
body.push('', dim(` ${G.h.repeat(10)} ${r.section} ${G.h.repeat(10)}`), '');
|
|
840
|
+
}
|
|
841
|
+
section = r.section || section;
|
|
842
|
+
const mark = single ? (i === at ? '(*)' : '( )') : r.locked ? dim(`[${G.off}]`) : `[${r.on ? green(G.on) : dim(G.off)}]`;
|
|
843
|
+
const label = r.locked ? dim(padTo(r.label, labelW)) : padTo(r.label, labelW);
|
|
844
|
+
body.push(`${i === at ? G.ptr : ' '} ${mark} ${label}${dim(r.note || '')}`);
|
|
845
|
+
});
|
|
846
|
+
body.push('', dim(single ? ` arrows choose ${G.sep} enter go ${G.sep} q quit` : ` space toggle ${G.sep} a all ${G.sep} enter go ${G.sep} q quit`), '');
|
|
847
|
+
const w = Math.max(...body.map(visible)) + 2;
|
|
848
|
+
const lines = [G.tl + G.h.repeat(w + 2) + G.tr, ...body.map((l) => `${G.v} ${padTo(l, w)} ${G.v}`), G.bl + G.h.repeat(w + 2) + G.br];
|
|
849
|
+
shown = draw(lines.map((l) => ` ${l}`), shown);
|
|
850
|
+
};
|
|
851
|
+
const done = (value) => {
|
|
852
|
+
stdin.off('data', onKey);
|
|
853
|
+
if (stdin.isTTY) stdin.setRawMode(false);
|
|
854
|
+
stdin.pause();
|
|
855
|
+
showCursor();
|
|
856
|
+
resolve(value);
|
|
857
|
+
};
|
|
858
|
+
const move = (d) => {
|
|
859
|
+
for (let k = 0; k < rows.length; k++) { at = (at + d + rows.length) % rows.length; if (!rows[at].locked) break; }
|
|
860
|
+
};
|
|
861
|
+
const onKey = (buf) => {
|
|
862
|
+
const k = buf.toString();
|
|
863
|
+
if (k === '\x03') { done(null); say(); process.exit(130); }
|
|
864
|
+
else if (k === 'q' || k === 'Q' || k === '\x1b') return done(null);
|
|
865
|
+
else if (k === '\r' || k === '\n') return done(single ? rows[at] : rows.filter((r) => r.on && !r.locked));
|
|
866
|
+
else if (k === ' ' && !single) { if (!rows[at].locked) rows[at].on = !rows[at].on; }
|
|
867
|
+
else if ((k === 'a' || k === 'A') && !single) { const open = rows.filter((r) => !r.locked); const all = open.every((r) => r.on); open.forEach((r) => { r.on = !all; }); }
|
|
868
|
+
else if (k === '\x1b[A' || k === '\x1bOA' || k === 'k') move(-1);
|
|
869
|
+
else if (k === '\x1b[B' || k === '\x1bOB' || k === 'j' || k === '\t') move(1);
|
|
870
|
+
render();
|
|
871
|
+
};
|
|
872
|
+
hideCursor();
|
|
873
|
+
render();
|
|
874
|
+
stdin.setRawMode(true);
|
|
875
|
+
stdin.resume();
|
|
876
|
+
stdin.on('data', onKey);
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// ---------- commands ----------
|
|
881
|
+
|
|
882
|
+
function target() {
|
|
883
|
+
const url = String(args.flags.url || env.STETS_URL || DEFAULT_URL);
|
|
884
|
+
let u;
|
|
885
|
+
try { u = new URL(url); } catch { fail(`--url must be an address like ${DEFAULT_URL}`); }
|
|
886
|
+
const local = ['localhost', '127.0.0.1', '[::1]'].includes(u.hostname);
|
|
887
|
+
if (u.protocol !== 'https:' && !(u.protocol === 'http:' && local)) fail('--url must be https (or http on localhost).');
|
|
888
|
+
const name = String(args.flags.name || 'stets');
|
|
889
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]{0,40}$/.test(name)) fail('--name may hold letters, digits, - and _ only.');
|
|
890
|
+
const scope = args.flags.scope ? String(args.flags.scope) : null;
|
|
891
|
+
if (scope && !WHERE[scope]) fail('--scope is global (all your projects), project (this project, shared through git) or local (this project, just for you).');
|
|
892
|
+
return { url: u.href.replace(/\/$/, u.pathname === '/' ? '/' : ''), name, host: u.host, scope };
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/** Any HTTP answer means a server is there (Stets answers /mcp with 401 or 405 to a plain GET). */
|
|
896
|
+
async function reachable(url) {
|
|
897
|
+
try {
|
|
898
|
+
await fetch(url, { method: 'GET', redirect: 'manual', signal: AbortSignal.timeout(10_000) });
|
|
899
|
+
return true;
|
|
900
|
+
} catch { return false; }
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/** The project folder and scope: asked in a menu only inside a git project, else all your projects. */
|
|
904
|
+
async function where(scopeFlag) {
|
|
905
|
+
const dir = projectDir();
|
|
906
|
+
if (scopeFlag) {
|
|
907
|
+
if (scopeFlag !== 'global' && !dir) say(dim(` Not in a git project, so "this project" is this folder: ${tilde(process.cwd())}`));
|
|
908
|
+
return { scope: scopeFlag, dir: dir || process.cwd() };
|
|
909
|
+
}
|
|
910
|
+
if (!dir || !TTY || args.flags.yes || args.flags.agents) return { scope: 'global', dir: dir || process.cwd() };
|
|
911
|
+
const rows = Object.entries(WHERE).map(([id, label]) => ({ id, label, note: id === 'global' ? '' : path.basename(dir) }));
|
|
912
|
+
const pick = await picker('Where should your agents have Stets?', rows, { single: true });
|
|
913
|
+
if (!pick) { say(dim(' Nothing changed.')); process.exit(0); }
|
|
914
|
+
say();
|
|
915
|
+
return { scope: pick.id, dir };
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
async function setup() {
|
|
919
|
+
const { url, name, host, scope: scopeFlag } = target();
|
|
920
|
+
await greet([bold('Stets') + dim(` ${VERSION}`), 'Hi, I\'m Stet. Let\'s get your agent', `building websites with ${host}.`]);
|
|
921
|
+
if (!(await withSpinner(`Knocking on ${host}${G.dots}`, reachable(url)))) {
|
|
922
|
+
fail(`Can't reach ${url}. Check the address${['localhost', '127.0.0.1'].some((h) => host.startsWith(h)) ? ', and that Stets is running there' : ' and your internet connection'}. Nothing was changed.`);
|
|
923
|
+
}
|
|
924
|
+
const ctx = await where(scopeFlag);
|
|
925
|
+
const found = await lookAround(name, url, ctx, { apps: ctx.scope === 'global' });
|
|
926
|
+
if (!found.some((f) => !f.a.app)) {
|
|
927
|
+
say(` I can't find a coding agent on this computer (${AGENTS.map((a) => a.name).join(', ')}).`);
|
|
928
|
+
if (!found.length) {
|
|
929
|
+
say(` Use Stets in the Claude or ChatGPT app instead: ${bold('https://stets.app/start')}`);
|
|
930
|
+
process.exitCode = 1;
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
const rows = found.map(({ a, st }) => ({
|
|
935
|
+
a, st, section: a.app ? 'OR, in a chat app' : undefined,
|
|
936
|
+
label: `${a.name}${a.sub ? dim(` (${a.sub})`) : ''}${a.checked === 'full' || a.app ? '' : dim(' beta')}`,
|
|
937
|
+
...describe(a, st, name, url, ctx.scope),
|
|
938
|
+
}));
|
|
939
|
+
|
|
940
|
+
let chosen;
|
|
941
|
+
if (args.flags.agents) {
|
|
942
|
+
const ids = String(args.flags.agents).split(',').map((s) => s.trim()).filter(Boolean);
|
|
943
|
+
const known = [...AGENTS, ...APPS];
|
|
944
|
+
for (const id of ids) if (!known.some((a) => a.id === id)) fail(`Unknown agent "${id}". Known: ${known.map((a) => a.id).join(', ')}`);
|
|
945
|
+
chosen = rows.filter((r) => ids.includes(r.a.id));
|
|
946
|
+
for (const id of ids) if (!chosen.some((r) => r.a.id === id)) say(yellow(` ${G.warn} ${known.find((a) => a.id === id).name} is not on this computer.`));
|
|
947
|
+
} else if (args.flags.yes) {
|
|
948
|
+
chosen = rows.filter((r) => r.on && !r.a.app);
|
|
949
|
+
} else if (rows.every((r) => r.locked)) {
|
|
950
|
+
chosen = rows; // nothing to pick: say why below
|
|
951
|
+
} else if (TTY) {
|
|
952
|
+
chosen = await picker(`Pick where to add Stets (${WHERE[ctx.scope].toLowerCase()}):`, rows);
|
|
953
|
+
if (!chosen) { say(dim(' Nothing changed.')); return; }
|
|
954
|
+
say();
|
|
955
|
+
} else {
|
|
956
|
+
fail('Not a terminal, so no menu: add --agents claude,codex or --yes.');
|
|
957
|
+
}
|
|
958
|
+
for (const r of chosen.filter((r) => r.locked)) say(yellow(` ${G.warn} ${r.a.name} ${r.note}: left as it is.${r.note.startsWith('has a') ? ' Use --name to add a second one.' : ''}`));
|
|
959
|
+
chosen = chosen.filter((r) => !r.locked);
|
|
960
|
+
if (!chosen.length) { say(dim(' Nothing to do.')); return; }
|
|
961
|
+
|
|
962
|
+
say(bold(`Setting up Stets ${WHERE[ctx.scope].toLowerCase()}:`));
|
|
963
|
+
let told = false;
|
|
964
|
+
const beforeSignIn = () => {
|
|
965
|
+
if (told) return;
|
|
966
|
+
told = true;
|
|
967
|
+
say(dim(args.flags['no-browser']
|
|
968
|
+
? ` Open the address below in a browser and sign in to ${host}, then paste the address you land on.`
|
|
969
|
+
: ` When your browser opens, sign in to ${host}. Signed in there already? Then it's one click: Allow.`));
|
|
970
|
+
};
|
|
971
|
+
let added = 0, connected = 0, inApp = 0, errors = 0;
|
|
972
|
+
const touched = []; // the agents this run added Stets to: the undo line names only these
|
|
973
|
+
// The chat apps first: a Claude connector also covers Claude Code, which then needs nothing more.
|
|
974
|
+
chosen.sort((x, y) => (y.a.app ? 1 : 0) - (x.a.app ? 1 : 0));
|
|
975
|
+
for (const r of chosen) {
|
|
976
|
+
const a = r.a;
|
|
977
|
+
say();
|
|
978
|
+
say(` ${bold(a.name)}`);
|
|
979
|
+
if (a.app) {
|
|
980
|
+
a.add(name, url, ctx);
|
|
981
|
+
if (a.id === 'claude-app' && has('claude') && await waitKey(dim('Press Enter once it says Connected (s to skip):'))) {
|
|
982
|
+
const st = await a.state(name, url, ctx);
|
|
983
|
+
if (st && st.present) { connected++; say(` ${green(G.ok)} connected`); continue; }
|
|
984
|
+
say(dim(` Not connected yet. You can finish it later: ${a.manage}`));
|
|
985
|
+
}
|
|
986
|
+
inApp++;
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
let st = r.st;
|
|
990
|
+
if (a.id === 'claude' && ctx.scope === 'global' && !st.present && chosen.some((c) => c.a.id === 'claude-app')) {
|
|
991
|
+
const again = (await a.state(name, url, ctx)) || st;
|
|
992
|
+
if (again.viaClaudeAi) { connected++; say(` ${green(G.ok)} has Stets through the Claude app now: nothing more to add`); continue; }
|
|
993
|
+
}
|
|
994
|
+
if (!st.present || st.where !== ctx.scope) {
|
|
995
|
+
if (a.signsInOnAdd && a.signsInOnAdd(ctx)) beforeSignIn();
|
|
996
|
+
const res = a.add(name, url, ctx);
|
|
997
|
+
if (res.ok) touched.push(a.id);
|
|
998
|
+
if (res.manual) { inApp++; if (a.hint) say(dim(` ${a.hint}`)); continue; }
|
|
999
|
+
// Codex signs in during its add; if that sign-in is broken off, it may exit non-zero with Stets added.
|
|
1000
|
+
st = (await a.state(name, url, ctx)) || st;
|
|
1001
|
+
if (!st.present && res.ok) { inApp++; say(` ${green(G.ok)} added (the agent says so; I can't see it in its settings from here)`); if (a.hint) say(dim(` ${a.hint}`)); continue; }
|
|
1002
|
+
if (!st.present) { errors++; say(` ${red(G.no)} could not add Stets`); continue; }
|
|
1003
|
+
if (!res.ok) say(dim(' (the agent reported a problem, but Stets is added)'));
|
|
1004
|
+
added++;
|
|
1005
|
+
say(` ${green(G.ok)} added`);
|
|
1006
|
+
}
|
|
1007
|
+
if (st.inApp) { inApp++; say(dim(` ${a.hint || `${a.name} asks you to sign in to ${host} the first time it uses Stets.`}`)); continue; }
|
|
1008
|
+
if (st.pending) { inApp++; say(dim(` Claude Code asks you to approve "${name}" the next time you start it in this project, then: ${a.later(name)}`)); continue; }
|
|
1009
|
+
if (st.untrusted) { inApp++; say(dim(` ${a.trustHint}: ${a.later(name)}`)); continue; }
|
|
1010
|
+
if (st.ready) { connected++; say(` ${green(G.ok)} connected`); continue; }
|
|
1011
|
+
if (st.failed) { errors++; say(` ${red(G.no)} ${a.name} can't connect to ${host}. Check with: ${a.check(name)}`); continue; }
|
|
1012
|
+
if (args.flags['no-login'] || !a.login) { say(dim(` sign in later: ${a.later(name)}`)); continue; }
|
|
1013
|
+
beforeSignIn();
|
|
1014
|
+
a.login(name, ctx);
|
|
1015
|
+
st = (await a.state(name, url, ctx)) || st;
|
|
1016
|
+
if (st.ready) { connected++; say(` ${green(G.ok)} signed in`); }
|
|
1017
|
+
else { errors++; say(` ${yellow(G.warn)} not signed in yet (${st.status || 'unknown'}). Try again: ${a.later(name)}`); }
|
|
1018
|
+
}
|
|
1019
|
+
say();
|
|
1020
|
+
say(`${added} added, ${connected} connected, ${inApp ? `${inApp} to finish in the ${inApp === 1 ? 'agent' : 'agents'}, ` : ''}${errors} ${errors === 1 ? 'problem' : 'problems'}`);
|
|
1021
|
+
if (errors) process.exitCode = 1;
|
|
1022
|
+
if (!errors && (connected || inApp)) {
|
|
1023
|
+
say();
|
|
1024
|
+
const first = (chosen.find((c) => !c.a.app) || chosen[0]).a.name;
|
|
1025
|
+
const head = connected ? `${bold('Done!')} Now open ${first} and say:` : `${bold('Nearly there.')} Finish the steps above, then tell ${first}:`;
|
|
1026
|
+
const app = chosen.find((c) => c.a.app);
|
|
1027
|
+
const undo = touched.length ? `Undo: stets agent remove --agents ${touched.join(',')}${sameFlags(ctx.scope)}` : app ? `Undo: in ${app.a.name}, ${app.a.manage}` : '';
|
|
1028
|
+
draw(scene(connected ? 'cheer' : 'wave', [head, '"Make me a website for my bakery."', dim(undo)]));
|
|
1029
|
+
say();
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** The --url, --name and --scope this run used, so a printed command does the same. */
|
|
1034
|
+
function sameFlags(scope) {
|
|
1035
|
+
const { url, name } = target();
|
|
1036
|
+
return `${sameUrl(url, DEFAULT_URL) ? '' : ` --url ${url}`}${name === 'stets' ? '' : ` --name ${name}`}${scope && scope !== 'global' ? ` --scope ${scope}` : ''}`;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
async function status() {
|
|
1040
|
+
const { url, name, scope } = target();
|
|
1041
|
+
const ctx = { scope: scope || 'global', dir: projectDir() || process.cwd() };
|
|
1042
|
+
const found = await lookAround(name, url, ctx);
|
|
1043
|
+
if (!found.length) { say(' No agents found on this computer.'); return; }
|
|
1044
|
+
say(dim(` ${WHERE[ctx.scope]}${ctx.scope === 'global' ? '' : ` (${tilde(ctx.dir)})`}:`));
|
|
1045
|
+
const w = Math.max(...found.map((f) => f.a.name.length)) + 4;
|
|
1046
|
+
for (const { a, st } of found) {
|
|
1047
|
+
const d = describe(a, st, name, url, ctx.scope, true);
|
|
1048
|
+
const good = /^connected|added \(signs in|already in all/.test(d.note);
|
|
1049
|
+
const mark = good ? green(G.ok) : d.locked ? yellow(G.warn) : dim(G.off);
|
|
1050
|
+
say(` ${mark} ${padTo(a.name, w)}${d.note}`);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
async function remove() {
|
|
1055
|
+
const { url, name, scope } = target();
|
|
1056
|
+
const ctx = { scope: scope || 'global', dir: projectDir() || process.cwd() };
|
|
1057
|
+
const ids = args.flags.agents ? String(args.flags.agents).split(',').map((x) => x.trim()).filter(Boolean) : null;
|
|
1058
|
+
const found = (await lookAround(name, url, ctx)).filter(({ a }) => !ids || ids.includes(a.id));
|
|
1059
|
+
const targets = [];
|
|
1060
|
+
for (const { a, st } of found) {
|
|
1061
|
+
if (a.app) { if (st.present) say(dim(` ${a.name} has Stets as a connector: remove it there (${a.manage}).`)); continue; }
|
|
1062
|
+
if (!a.scopes.includes(ctx.scope) || !st.present || st.where !== ctx.scope) continue;
|
|
1063
|
+
if (!sameUrl(st.url, url)) { say(dim(` ${a.name}: "${name}" points at ${st.url}, left as it is (to remove that one: stets agent remove --url ${st.url}${name === 'stets' ? '' : ` --name ${name}`}).`)); continue; }
|
|
1064
|
+
targets.push({ a, st });
|
|
1065
|
+
}
|
|
1066
|
+
if (!targets.length) {
|
|
1067
|
+
say(dim(` No agent here has Stets ${WHERE[ctx.scope].replace(/^In all/, 'in all').replace(/^Only/, 'only')}.`));
|
|
1068
|
+
} else if (!ids && !args.flags.yes) {
|
|
1069
|
+
// Without --agents this would take Stets out of every agent, also ones set up some other way: ask first.
|
|
1070
|
+
say(` Stets will be taken out of: ${bold(targets.map((t) => t.a.name).join(', '))}`);
|
|
1071
|
+
if (!TTY) fail('Not a terminal, so no question: add --agents <ids> (or --yes for all of them).');
|
|
1072
|
+
if (!(await waitKey(dim('Press Enter to go on, q to keep them:')))) { say(dim(' Nothing changed.')); return; }
|
|
1073
|
+
}
|
|
1074
|
+
for (const { a } of targets) {
|
|
1075
|
+
const r = a.remove(name, ctx);
|
|
1076
|
+
if (r.ok) say(` ${green(G.ok)} ${a.name}: Stets removed`);
|
|
1077
|
+
else say(` ${red(G.no)} ${a.name}: ${String(r.out || '').trim().split('\n')[0]}`);
|
|
1078
|
+
}
|
|
1079
|
+
for (const { a, st } of found) if (st.viaClaudeAi) say(dim(` ${a.name} also has Stets through claude.ai: remove it there (Settings, Connectors).`));
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function help() {
|
|
1083
|
+
const lines = [
|
|
1084
|
+
`${bold('stets')} ${VERSION}: connects your agents to Stets, the website builder you talk to.`,
|
|
1085
|
+
'',
|
|
1086
|
+
bold('Usage'),
|
|
1087
|
+
' stets agent setup Add Stets to your agents and sign them in',
|
|
1088
|
+
' stets agent status Show where Stets is set up',
|
|
1089
|
+
' stets agent remove Take Stets out again',
|
|
1090
|
+
'',
|
|
1091
|
+
bold('Options'),
|
|
1092
|
+
` --agents <ids> Pick without the menu: ${[...AGENTS, ...APPS].map((a) => a.id).join(',')}`,
|
|
1093
|
+
' -y, --yes Without the menu: every coding agent that needs it (not docs-only ones)',
|
|
1094
|
+
' --scope <where> global: all your projects (default)',
|
|
1095
|
+
' project: this project, shared through git',
|
|
1096
|
+
' local: this project, just for you (Claude Code)',
|
|
1097
|
+
` --url <url> Another Stets (default ${DEFAULT_URL}; or STETS_URL)`,
|
|
1098
|
+
' --name <name> The server\'s name in the agent (default stets)',
|
|
1099
|
+
' --no-login Only add Stets; sign in later from the agent',
|
|
1100
|
+
' --no-browser Don\'t open a browser (sign-in over SSH)',
|
|
1101
|
+
' --ascii, --no-color Plain output (NO_COLOR works too)',
|
|
1102
|
+
];
|
|
1103
|
+
say();
|
|
1104
|
+
draw(scene('stand', [bold('Stets') + dim(` ${VERSION}`), 'Websites your agent builds.']));
|
|
1105
|
+
say();
|
|
1106
|
+
for (const l of lines) say(l ? ` ${l}` : '');
|
|
1107
|
+
say();
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
async function main() {
|
|
1111
|
+
if (args.flags.version) return say(VERSION);
|
|
1112
|
+
const [cmd, sub] = args._;
|
|
1113
|
+
if (args.flags.help || !cmd || cmd === 'help') return help();
|
|
1114
|
+
if (cmd === 'login') {
|
|
1115
|
+
say(` No separate sign-in: each agent signs in to Stets itself, during ${bold('stets agent setup')}.`);
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
if (cmd === 'setup' || (cmd === 'agent' && sub === 'setup')) return setup();
|
|
1119
|
+
if (cmd === 'status' || (cmd === 'agent' && (sub === 'status' || !sub))) return status();
|
|
1120
|
+
if (cmd === 'remove' || (cmd === 'agent' && sub === 'remove')) return remove();
|
|
1121
|
+
fail(`Unknown command "${args._.join(' ')}". See: stets help`);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
main().catch((e) => fail(e && e.stack ? e.stack : String(e)));
|