qualiloop 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/README.md +258 -3
- package/dist/api.js +165 -0
- package/dist/auth.js +73 -0
- package/dist/catalog.js +24 -0
- package/dist/catalog.json +7943 -0
- package/dist/cli.js +2777 -0
- package/dist/config.js +76 -0
- package/dist/connect.js +357 -0
- package/dist/export.js +114 -0
- package/dist/mcp/install.js +142 -0
- package/dist/mcp/server.js +523 -0
- package/dist/output.js +43 -0
- package/dist/workflows.js +147 -0
- package/package.json +47 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { DEFAULT_URL } from '../config.js';
|
|
7
|
+
export const CLIENTS = ['claude-code', 'cursor', 'vscode', 'windsurf', 'claude-desktop', 'codex'];
|
|
8
|
+
export const DEFAULT_CLIENTS = ['claude-desktop'];
|
|
9
|
+
export const serverCommand = (url) => {
|
|
10
|
+
const cli = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'cli.js');
|
|
11
|
+
const command = { command: process.execPath, args: [cli, 'mcp'] };
|
|
12
|
+
if (url !== DEFAULT_URL)
|
|
13
|
+
command.env = { QUALILOOP_URL: url };
|
|
14
|
+
return command;
|
|
15
|
+
};
|
|
16
|
+
const home = os.homedir();
|
|
17
|
+
const appData = process.env.APPDATA || path.join(home, 'AppData', 'Roaming');
|
|
18
|
+
export const configFile = (client, scope, cwd) => {
|
|
19
|
+
switch (client) {
|
|
20
|
+
case 'claude-code':
|
|
21
|
+
return scope === 'project' ? path.join(cwd, '.mcp.json') : null;
|
|
22
|
+
case 'cursor':
|
|
23
|
+
return scope === 'project' ? path.join(cwd, '.cursor', 'mcp.json') : path.join(home, '.cursor', 'mcp.json');
|
|
24
|
+
case 'vscode':
|
|
25
|
+
return path.join(cwd, '.vscode', 'mcp.json');
|
|
26
|
+
case 'windsurf':
|
|
27
|
+
return path.join(home, '.codeium', 'windsurf', 'mcp_config.json');
|
|
28
|
+
case 'claude-desktop':
|
|
29
|
+
return process.platform === 'win32'
|
|
30
|
+
? path.join(appData, 'Claude', 'claude_desktop_config.json')
|
|
31
|
+
: process.platform === 'darwin'
|
|
32
|
+
? path.join(home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json')
|
|
33
|
+
: path.join(home, '.config', 'Claude', 'claude_desktop_config.json');
|
|
34
|
+
case 'codex':
|
|
35
|
+
return path.join(home, '.codex', 'config.toml');
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const readJsonFile = (file) => {
|
|
39
|
+
if (!existsSync(file))
|
|
40
|
+
return {};
|
|
41
|
+
const raw = readFileSync(file, 'utf8').trim();
|
|
42
|
+
if (!raw)
|
|
43
|
+
return {};
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(raw);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new Error(`${file} is not valid JSON; fix it or add the server by hand (qualiloop mcp install --print).`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export const entryFor = (client, command) => client === 'vscode' ? { type: 'stdio', ...command } : { ...command };
|
|
52
|
+
const writeJsonConfig = (client, file, command) => {
|
|
53
|
+
const config = readJsonFile(file);
|
|
54
|
+
const key = client === 'vscode' ? 'servers' : 'mcpServers';
|
|
55
|
+
const servers = config[key] ?? {};
|
|
56
|
+
servers.qualiloop = entryFor(client, command);
|
|
57
|
+
config[key] = servers;
|
|
58
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
59
|
+
writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`);
|
|
60
|
+
};
|
|
61
|
+
const tomlString = (value) => JSON.stringify(value);
|
|
62
|
+
export const codexSection = (command) => {
|
|
63
|
+
const lines = [
|
|
64
|
+
'[mcp_servers.qualiloop]',
|
|
65
|
+
`command = ${tomlString(command.command)}`,
|
|
66
|
+
`args = [${command.args.map(tomlString).join(', ')}]`,
|
|
67
|
+
];
|
|
68
|
+
if (command.env) {
|
|
69
|
+
lines.push(`env = { ${Object.entries(command.env)
|
|
70
|
+
.map(([key, value]) => `${key} = ${tomlString(value)}`)
|
|
71
|
+
.join(', ')} }`);
|
|
72
|
+
}
|
|
73
|
+
return lines.join('\n');
|
|
74
|
+
};
|
|
75
|
+
const writeCodex = (file, command) => {
|
|
76
|
+
const existing = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
77
|
+
const without = existing.replace(/\n?\[mcp_servers\.qualiloop\][\s\S]*?(?=\n\[|$)/, '').trimEnd();
|
|
78
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
79
|
+
writeFileSync(file, `${without ? `${without}\n\n` : ''}${codexSection(command)}\n`);
|
|
80
|
+
};
|
|
81
|
+
export const install = (clients, options) => {
|
|
82
|
+
const cwd = options.cwd ?? process.cwd();
|
|
83
|
+
const command = serverCommand(options.url);
|
|
84
|
+
return clients.map((client) => {
|
|
85
|
+
if (client === 'claude-code' && options.scope === 'user') {
|
|
86
|
+
const args = claudeAddArgs(command);
|
|
87
|
+
const ran = spawnSync('claude', args, { stdio: 'pipe', shell: process.platform === 'win32' });
|
|
88
|
+
if (ran.status === 0)
|
|
89
|
+
return { client, done: true, where: 'claude mcp add --scope user' };
|
|
90
|
+
const byHand = `Run: claude ${args.map((arg) => (/\s/.test(arg) ? JSON.stringify(arg) : arg)).join(' ')}`;
|
|
91
|
+
const output = `${ran.stderr ?? ''}`.trim() || `${ran.stdout ?? ''}`.trim();
|
|
92
|
+
const missing = Boolean(ran.error) || ran.status === 127 || /not recognized|not found/i.test(output);
|
|
93
|
+
return {
|
|
94
|
+
client,
|
|
95
|
+
done: false,
|
|
96
|
+
where: missing
|
|
97
|
+
? `Claude Code CLI not found. ${byHand}`
|
|
98
|
+
: `claude mcp add failed: ${output || `exit code ${ran.status}`}. ${byHand}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const file = configFile(client, options.scope, cwd);
|
|
102
|
+
if (!file)
|
|
103
|
+
return { client, done: false, where: 'not supported' };
|
|
104
|
+
if (client === 'codex')
|
|
105
|
+
writeCodex(file, command);
|
|
106
|
+
else
|
|
107
|
+
writeJsonConfig(client, file, command);
|
|
108
|
+
return { client, done: true, where: file };
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
export const claudeAddArgs = (command) => {
|
|
112
|
+
const args = ['mcp', 'add', '--scope', 'user'];
|
|
113
|
+
for (const [key, value] of Object.entries(command.env ?? {}))
|
|
114
|
+
args.push('-e', `${key}=${value}`);
|
|
115
|
+
args.push('qualiloop', '--', command.command, ...command.args);
|
|
116
|
+
return args;
|
|
117
|
+
};
|
|
118
|
+
const LABELS = {
|
|
119
|
+
'claude-code': 'Claude Code',
|
|
120
|
+
cursor: 'Cursor (~/.cursor/mcp.json)',
|
|
121
|
+
windsurf: 'Windsurf (~/.codeium/windsurf/mcp_config.json)',
|
|
122
|
+
'claude-desktop': 'Claude Desktop (claude_desktop_config.json)',
|
|
123
|
+
vscode: 'VS Code (.vscode/mcp.json)',
|
|
124
|
+
codex: 'Codex (~/.codex/config.toml)',
|
|
125
|
+
};
|
|
126
|
+
export const snippets = (url, clients = CLIENTS) => {
|
|
127
|
+
const command = serverCommand(url);
|
|
128
|
+
const quote = (part) => (/^[\w./:=@-]+$/.test(part) ? part : JSON.stringify(part));
|
|
129
|
+
const one = (client) => {
|
|
130
|
+
switch (client) {
|
|
131
|
+
case 'claude-code':
|
|
132
|
+
return ` claude ${claudeAddArgs(command).map(quote).join(' ')}`;
|
|
133
|
+
case 'vscode':
|
|
134
|
+
return JSON.stringify({ servers: { qualiloop: entryFor('vscode', command) } }, null, 2);
|
|
135
|
+
case 'codex':
|
|
136
|
+
return codexSection(command);
|
|
137
|
+
default:
|
|
138
|
+
return JSON.stringify({ mcpServers: { qualiloop: entryFor(client, command) } }, null, 2);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return clients.map((client) => `${LABELS[client]}:\n${one(client)}`).join('\n\n');
|
|
142
|
+
};
|