@featq/cli 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/LICENSE +21 -0
- package/README.md +49 -2
- package/bin/featq.js +12 -0
- package/lib/api.js +88 -0
- package/lib/cli.js +276 -0
- package/lib/clients.js +54 -0
- package/lib/config.js +173 -0
- package/lib/constants.js +46 -0
- package/lib/key.js +6 -0
- package/lib/prompt.js +40 -0
- package/package.json +41 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FeatQ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# featq
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official CLI for [FeatQ](https://featq.com), a feature request board for software teams. It connects your coding agent to your board over MCP in one step.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx @featq/cli init
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It asks for your board key, checks it with featq.com, and adds the FeatQ MCP server to your client. Your board key is on your board admin page, under "Connect your coding agent".
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx @featq/cli init [--client claude|cursor|codex|gemini] [--key fq_...] [--global] [--yes] [--no-verify]
|
|
15
|
+
npx @featq/cli doctor
|
|
16
|
+
npx @featq/cli --version
|
|
17
|
+
npx @featq/cli --help
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**init** adds the server for one client (Claude Code by default):
|
|
21
|
+
|
|
22
|
+
| Client | What init does |
|
|
23
|
+
|---|---|
|
|
24
|
+
| `claude` | Writes `.mcp.json` in this folder. With `--global`, prints the `claude mcp add --scope user` command. |
|
|
25
|
+
| `cursor` | Writes `.cursor/mcp.json` in this folder, or `~/.cursor/mcp.json` with `--global`. |
|
|
26
|
+
| `codex` | Prints the `codex mcp add` command to run. |
|
|
27
|
+
| `gemini` | Prints the `gemini extensions install` command to run. |
|
|
28
|
+
|
|
29
|
+
- The key comes from `--key`, then the `FEATQ_BOARD_KEY` environment variable, then a hidden prompt in a terminal.
|
|
30
|
+
- Config files never hold the key. They hold a reference to `FEATQ_BOARD_KEY`. When you typed or passed the key, init prints the line that sets it (`export` on macOS and Linux, `$env:` and `setx` on Windows). A key already in `FEATQ_BOARD_KEY` is never printed.
|
|
31
|
+
- Other keys and servers in an existing config file are kept, and so is the file's permission mode (new files are readable only by you). A symlinked config (or `.cursor` folder) is updated through the link, and init names the real file. If the link leads outside the current folder, init stops unless you pass `--yes`. A different `featq` entry is only replaced with `--yes`. A file that is not valid JSON is left as it is.
|
|
32
|
+
- `--no-verify` skips the key check.
|
|
33
|
+
|
|
34
|
+
**doctor** checks the key in `FEATQ_BOARD_KEY` and shows the board it opens.
|
|
35
|
+
|
|
36
|
+
Exit codes: 0 ok, 1 failed, 2 usage error.
|
|
37
|
+
|
|
38
|
+
## Network and privacy
|
|
39
|
+
|
|
40
|
+
The only host this CLI contacts is featq.com, with one `GET /api/v1/me` call to check your key. Set `FEATQ_URL` to use another FeatQ server, for example when testing: it must be https (http only for localhost), and the CLI says when it is in use. Redirects are never followed. There is no telemetry and no install script, and it reads no file except the config file it updates.
|
|
41
|
+
|
|
42
|
+
## Official clients
|
|
43
|
+
|
|
44
|
+
The npm package `@featq/cli` and the [featq-mcp repo](https://github.com/max-reid-repos/featq-mcp) are made by FeatQ. Other packages that forward to the FeatQ server are not.
|
|
45
|
+
|
|
46
|
+
Needs Node.js 18 or newer. Docs: https://featq.com/docs/mcp
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
package/bin/featq.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { run } from '../lib/cli.js';
|
|
3
|
+
|
|
4
|
+
run({ argv: process.argv.slice(2) }).then(
|
|
5
|
+
(code) => {
|
|
6
|
+
process.exitCode = code;
|
|
7
|
+
},
|
|
8
|
+
(err) => {
|
|
9
|
+
process.stderr.write(`featq: ${err?.message || err}\n`);
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
}
|
|
12
|
+
);
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { baseUrl, KEY_HELP } from './constants.js';
|
|
2
|
+
|
|
3
|
+
const TIMEOUT_MS = 15000;
|
|
4
|
+
|
|
5
|
+
/** Strip control characters so board text from the server cannot drive the terminal. */
|
|
6
|
+
export function clean(value) {
|
|
7
|
+
return String(value ?? '').replace(/[\u0000-\u001f\u007f-\u009f]/g, '').trim();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** One-line human message for a failed /api/v1/me call. */
|
|
11
|
+
export function messageForStatus(status, retryAfter) {
|
|
12
|
+
if (status === 401) {
|
|
13
|
+
return `That board key was not accepted. Copy it again. ${KEY_HELP}`;
|
|
14
|
+
}
|
|
15
|
+
if (status === 403) {
|
|
16
|
+
return 'This FeatQ board is inactive. Reactivate it from the board admin page, then try again.';
|
|
17
|
+
}
|
|
18
|
+
if (status === 429) {
|
|
19
|
+
const secs = Number.parseInt(retryAfter ?? '', 10);
|
|
20
|
+
const wait = Number.isFinite(secs) && secs > 0 ? `${secs} seconds` : 'a few minutes';
|
|
21
|
+
return `Too many tries with this key or from this network. Wait ${wait} and try again.`;
|
|
22
|
+
}
|
|
23
|
+
return `FeatQ answered with HTTP ${status}. Try again in a few minutes.`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* GET /api/v1/me with the board key.
|
|
28
|
+
* Resolves { ok: true, board: { name, slug, url } } or { ok: false, message }.
|
|
29
|
+
* Never throws and never puts the key in a message.
|
|
30
|
+
*/
|
|
31
|
+
export async function fetchBoard(key, { env = process.env, fetch = globalThis.fetch } = {}) {
|
|
32
|
+
let base;
|
|
33
|
+
try {
|
|
34
|
+
base = baseUrl(env);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return { ok: false, message: err.message };
|
|
37
|
+
}
|
|
38
|
+
const host = safeHost(base);
|
|
39
|
+
let res;
|
|
40
|
+
try {
|
|
41
|
+
res = await fetch(`${base}/api/v1/me`, {
|
|
42
|
+
method: 'GET',
|
|
43
|
+
headers: { Authorization: `Bearer ${key}`, Accept: 'application/json' },
|
|
44
|
+
// Never follow a redirect: the key must only go to the host named above.
|
|
45
|
+
redirect: 'manual',
|
|
46
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
const code = err?.cause?.code || err?.code || err?.name || 'network error';
|
|
50
|
+
return {
|
|
51
|
+
ok: false,
|
|
52
|
+
message: `Could not reach ${host} (${clean(code)}). Check your connection and try again.`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (res.type === 'opaqueredirect' || (res.status >= 300 && res.status < 400)) {
|
|
57
|
+
return { ok: false, message: `${host} sent a redirect. Not following it with your key.` };
|
|
58
|
+
}
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
return { ok: false, message: messageForStatus(res.status, res.headers?.get?.('retry-after')) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let body;
|
|
64
|
+
try {
|
|
65
|
+
body = await res.json();
|
|
66
|
+
} catch {
|
|
67
|
+
return { ok: false, message: `${host} sent an answer this tool could not read. Try again later.` };
|
|
68
|
+
}
|
|
69
|
+
if (!body || typeof body !== 'object' || !body.board_slug) {
|
|
70
|
+
return { ok: false, message: `${host} sent an answer this tool could not read. Try again later.` };
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
ok: true,
|
|
74
|
+
board: {
|
|
75
|
+
name: clean(body.board_name),
|
|
76
|
+
slug: clean(body.board_slug),
|
|
77
|
+
url: clean(body.board_url),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function safeHost(base) {
|
|
83
|
+
try {
|
|
84
|
+
return new URL(base).host;
|
|
85
|
+
} catch {
|
|
86
|
+
return base;
|
|
87
|
+
}
|
|
88
|
+
}
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { relative } from 'node:path';
|
|
3
|
+
import { fetchBoard } from './api.js';
|
|
4
|
+
import { CLIENT_NAMES, getClient } from './clients.js';
|
|
5
|
+
import { ConfigError, writeServerEntry } from './config.js';
|
|
6
|
+
import { ENV_KEY, ENV_URL, KEY_HELP, VERSION, checkBaseUrl, mcpUrl } from './constants.js';
|
|
7
|
+
import { isValidKey } from './key.js';
|
|
8
|
+
import { promptHidden } from './prompt.js';
|
|
9
|
+
|
|
10
|
+
export const EXIT_OK = 0;
|
|
11
|
+
export const EXIT_FAIL = 1;
|
|
12
|
+
export const EXIT_USAGE = 2;
|
|
13
|
+
|
|
14
|
+
class UsageError extends Error {}
|
|
15
|
+
|
|
16
|
+
const HELP = `featq ${VERSION}: connect your coding agent to your FeatQ board.
|
|
17
|
+
|
|
18
|
+
Usage:
|
|
19
|
+
featq init [--client claude|cursor|codex|gemini] [--key fq_...] [--global] [--yes] [--no-verify]
|
|
20
|
+
featq doctor
|
|
21
|
+
featq --version
|
|
22
|
+
featq --help
|
|
23
|
+
|
|
24
|
+
init Check your board key and add the FeatQ MCP server to your client.
|
|
25
|
+
Claude Code: writes .mcp.json in this folder.
|
|
26
|
+
Cursor: writes .cursor/mcp.json here, or ~/.cursor/mcp.json with --global.
|
|
27
|
+
Codex and Gemini CLI: prints the command to run.
|
|
28
|
+
The key comes from --key, then ${ENV_KEY}, then a hidden prompt.
|
|
29
|
+
Config files get a reference to ${ENV_KEY}, never the key itself.
|
|
30
|
+
doctor Check the key in ${ENV_KEY} and show which board it opens.
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--client <name> claude (default), cursor, codex or gemini
|
|
34
|
+
--key <fq_...> your board key
|
|
35
|
+
--global user-wide config instead of this project
|
|
36
|
+
--yes, -y replace an existing, different "featq" entry, or write
|
|
37
|
+
through a link that leads outside this folder
|
|
38
|
+
--no-verify skip the key check against featq.com
|
|
39
|
+
|
|
40
|
+
${KEY_HELP}
|
|
41
|
+
Set ${ENV_URL} to point at another FeatQ server (for testing).
|
|
42
|
+
Exit codes: 0 ok, 1 failed, 2 usage error.
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Commands by name. Each takes (flags, io) and resolves an exit code.
|
|
47
|
+
* New commands plug in here; parseArgs and run need no change.
|
|
48
|
+
*/
|
|
49
|
+
export const commands = {
|
|
50
|
+
init: { flags: ['client', 'key', 'global', 'yes', 'no-verify'], run: runInit },
|
|
51
|
+
doctor: { flags: [], run: runDoctor },
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const VALUE_FLAGS = new Set(['client', 'key']);
|
|
55
|
+
const SHORT = { y: 'yes', h: 'help', v: 'version' };
|
|
56
|
+
|
|
57
|
+
export function parseArgs(argv) {
|
|
58
|
+
const flags = {};
|
|
59
|
+
const positionals = [];
|
|
60
|
+
for (let i = 0; i < argv.length; i++) {
|
|
61
|
+
const arg = argv[i];
|
|
62
|
+
if (arg === '--') {
|
|
63
|
+
positionals.push(...argv.slice(i + 1));
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (arg.startsWith('--')) {
|
|
67
|
+
const eq = arg.indexOf('=');
|
|
68
|
+
const name = eq === -1 ? arg.slice(2) : arg.slice(2, eq);
|
|
69
|
+
if (VALUE_FLAGS.has(name)) {
|
|
70
|
+
const value = eq === -1 ? argv[++i] : arg.slice(eq + 1);
|
|
71
|
+
if (value === undefined || value === '' || (eq === -1 && value.startsWith('-'))) {
|
|
72
|
+
throw new UsageError(`--${name} needs a value.`);
|
|
73
|
+
}
|
|
74
|
+
flags[name] = value;
|
|
75
|
+
} else {
|
|
76
|
+
if (eq !== -1) throw new UsageError(`--${name} does not take a value.`);
|
|
77
|
+
flags[name] = true;
|
|
78
|
+
}
|
|
79
|
+
} else if (arg.startsWith('-') && arg.length > 1) {
|
|
80
|
+
const name = SHORT[arg.slice(1)];
|
|
81
|
+
if (!name) throw new UsageError(`Unknown option ${arg}.`);
|
|
82
|
+
flags[name] = true;
|
|
83
|
+
} else {
|
|
84
|
+
positionals.push(arg);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { flags, positionals };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Entry point. io: { argv, env, fetch, stdout, stderr, stdin, cwd, home }.
|
|
92
|
+
* Resolves the exit code; never calls process.exit itself.
|
|
93
|
+
*/
|
|
94
|
+
export async function run(io) {
|
|
95
|
+
const ctx = {
|
|
96
|
+
env: process.env,
|
|
97
|
+
fetch: globalThis.fetch,
|
|
98
|
+
stdout: process.stdout,
|
|
99
|
+
stderr: process.stderr,
|
|
100
|
+
stdin: process.stdin,
|
|
101
|
+
cwd: process.cwd(),
|
|
102
|
+
home: homedir(),
|
|
103
|
+
prompt: promptHidden,
|
|
104
|
+
platform: process.platform,
|
|
105
|
+
...io,
|
|
106
|
+
};
|
|
107
|
+
const out = (line = '') => ctx.stdout.write(line + '\n');
|
|
108
|
+
const err = (line) => ctx.stderr.write(line + '\n');
|
|
109
|
+
ctx.out = out;
|
|
110
|
+
ctx.err = err;
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
const { flags, positionals } = parseArgs(ctx.argv ?? []);
|
|
114
|
+
if (flags.version) {
|
|
115
|
+
out(VERSION);
|
|
116
|
+
return EXIT_OK;
|
|
117
|
+
}
|
|
118
|
+
if (flags.help || positionals.length === 0) {
|
|
119
|
+
out(HELP);
|
|
120
|
+
return positionals.length === 0 && !flags.help ? EXIT_USAGE : EXIT_OK;
|
|
121
|
+
}
|
|
122
|
+
const [name, ...rest] = positionals;
|
|
123
|
+
const command = Object.hasOwn(commands, name) ? commands[name] : null;
|
|
124
|
+
if (!command) throw new UsageError(`Unknown command "${name}". Run featq --help.`);
|
|
125
|
+
if (rest.length) throw new UsageError(`Unexpected argument "${rest[0]}".`);
|
|
126
|
+
for (const flag of Object.keys(flags)) {
|
|
127
|
+
if (!command.flags.includes(flag)) throw new UsageError(`${name} does not take --${flag}.`);
|
|
128
|
+
}
|
|
129
|
+
const base = checkBaseUrl(ctx.env);
|
|
130
|
+
if (!base.ok) throw new UsageError(base.message);
|
|
131
|
+
if (base.custom) err(`Using ${ENV_URL}: ${base.host}`);
|
|
132
|
+
return await command.run(flags, ctx);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
if (e instanceof UsageError) {
|
|
135
|
+
err(`featq: ${e.message}`);
|
|
136
|
+
return EXIT_USAGE;
|
|
137
|
+
}
|
|
138
|
+
if (e instanceof ConfigError) {
|
|
139
|
+
err(`featq: ${e.message}`);
|
|
140
|
+
return EXIT_FAIL;
|
|
141
|
+
}
|
|
142
|
+
err(`featq: ${e?.message || e}`);
|
|
143
|
+
return EXIT_FAIL;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function getKey(flags, ctx) {
|
|
148
|
+
if (flags.key !== undefined) return { key: flags.key, source: 'flag' };
|
|
149
|
+
const fromEnv = ctx.env[ENV_KEY];
|
|
150
|
+
if (fromEnv) return { key: fromEnv.trim(), source: 'env' };
|
|
151
|
+
if (!ctx.stdin.isTTY) {
|
|
152
|
+
throw new UsageError(`No board key. Pass --key fq_... or set ${ENV_KEY}. ${KEY_HELP}`);
|
|
153
|
+
}
|
|
154
|
+
ctx.err(KEY_HELP);
|
|
155
|
+
let key;
|
|
156
|
+
try {
|
|
157
|
+
key = await ctx.prompt('Paste your board key (fq_...): ', { input: ctx.stdin, output: ctx.stderr });
|
|
158
|
+
} catch {
|
|
159
|
+
throw new UsageError('Cancelled.');
|
|
160
|
+
}
|
|
161
|
+
return { key, source: 'prompt' };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function runInit(flags, ctx) {
|
|
165
|
+
const clientName = flags.client ?? 'claude';
|
|
166
|
+
if (!CLIENT_NAMES.includes(clientName)) {
|
|
167
|
+
throw new UsageError(`Unknown client "${clientName}". Use one of: ${CLIENT_NAMES.join(', ')}.`);
|
|
168
|
+
}
|
|
169
|
+
const client = getClient(clientName, { env: ctx.env, cwd: ctx.cwd, home: ctx.home, platform: ctx.platform });
|
|
170
|
+
|
|
171
|
+
const { key, source } = await getKey(flags, ctx);
|
|
172
|
+
if (!isValidKey(key)) {
|
|
173
|
+
const where = source === 'env' ? ENV_KEY : 'The key';
|
|
174
|
+
throw new UsageError(`${where} does not look like a board key (fq_ followed by 32 characters). ${KEY_HELP}`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (flags['no-verify']) {
|
|
178
|
+
ctx.out('Skipped the key check (--no-verify).');
|
|
179
|
+
} else {
|
|
180
|
+
const result = await fetchBoard(key, { env: ctx.env, fetch: ctx.fetch });
|
|
181
|
+
if (!result.ok) {
|
|
182
|
+
ctx.err(`featq: ${result.message}`);
|
|
183
|
+
return EXIT_FAIL;
|
|
184
|
+
}
|
|
185
|
+
ctx.out(`Key works: board "${result.board.name}" (${result.board.slug}).`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const command = flags.global && client.globalCommand ? client.globalCommand : client.command;
|
|
189
|
+
if (command) {
|
|
190
|
+
// The key must be in the environment before the command runs, so it comes first.
|
|
191
|
+
printKeyLines(client, key, source, ctx);
|
|
192
|
+
ctx.out('');
|
|
193
|
+
ctx.out(
|
|
194
|
+
source === 'env'
|
|
195
|
+
? `Run this to add FeatQ to ${client.label}:`
|
|
196
|
+
: `Then run this to add FeatQ to ${client.label} (run it after the line above):`
|
|
197
|
+
);
|
|
198
|
+
ctx.out(` ${command}`);
|
|
199
|
+
} else {
|
|
200
|
+
const path = flags.global && client.globalFile ? client.globalFile : client.file;
|
|
201
|
+
const label = displayPath(path, ctx);
|
|
202
|
+
const isGlobal = !!(flags.global && client.globalFile);
|
|
203
|
+
const result = await writeServerEntry(path, client.entry, {
|
|
204
|
+
overwrite: !!flags.yes,
|
|
205
|
+
fileLabel: label,
|
|
206
|
+
base: isGlobal ? ctx.home : ctx.cwd,
|
|
207
|
+
// Project configs must stay inside this folder unless --yes.
|
|
208
|
+
insideOf: isGlobal ? null : ctx.cwd,
|
|
209
|
+
allowOutside: !!flags.yes,
|
|
210
|
+
});
|
|
211
|
+
const where = result.linked ? `${result.target} (through the link ${label})` : label;
|
|
212
|
+
const verb = {
|
|
213
|
+
created: `Created ${where} with the FeatQ server.`,
|
|
214
|
+
added: `Added the FeatQ server to ${where}.`,
|
|
215
|
+
replaced: `Replaced the FeatQ server in ${where}.`,
|
|
216
|
+
unchanged: `${where} already has the FeatQ server. Nothing to change.`,
|
|
217
|
+
}[result.status];
|
|
218
|
+
ctx.out(verb);
|
|
219
|
+
printKeyLines(client, key, source, ctx);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
ctx.out('');
|
|
223
|
+
ctx.out(`${command ? 'Once it is added, restart' : 'Then restart'} ${client.label} and ask: "Pull my top-voted feature request and implement it."`);
|
|
224
|
+
return EXIT_OK;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Tell the user how to set FEATQ_BOARD_KEY. The full key is printed only when
|
|
229
|
+
* it came from --key or the prompt; a key from the environment is never echoed.
|
|
230
|
+
*/
|
|
231
|
+
function printKeyLines(client, key, source, ctx) {
|
|
232
|
+
ctx.out('');
|
|
233
|
+
if (source === 'env') {
|
|
234
|
+
ctx.out(`${ENV_KEY} is already set in this shell. Make sure your shell profile sets it too, so ${client.label} sees it after a restart.`);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (ctx.platform === 'win32') {
|
|
238
|
+
ctx.out(`${client.label} reads the key from ${ENV_KEY}. In PowerShell, set it for this window:`);
|
|
239
|
+
ctx.out(` $env:${ENV_KEY} = '${key}'`);
|
|
240
|
+
ctx.out('and keep it for new windows:');
|
|
241
|
+
ctx.out(` setx ${ENV_KEY} "${key}"`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
ctx.out(`${client.label} reads the key from ${ENV_KEY}. Run this line, and add it to your shell profile (~/.zshrc or ~/.bashrc):`);
|
|
245
|
+
ctx.out(` export ${ENV_KEY}=${key}`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function runDoctor(_flags, ctx) {
|
|
249
|
+
const key = (ctx.env[ENV_KEY] ?? '').trim();
|
|
250
|
+
if (!key) {
|
|
251
|
+
const setLine = ctx.platform === 'win32' ? `$env:${ENV_KEY} = 'fq_...'` : `export ${ENV_KEY}=fq_...`;
|
|
252
|
+
throw new UsageError(`${ENV_KEY} is not set. Run: ${setLine} ${KEY_HELP}`);
|
|
253
|
+
}
|
|
254
|
+
if (!isValidKey(key)) {
|
|
255
|
+
ctx.err(`featq: ${ENV_KEY} does not look like a board key (fq_ followed by 32 characters). ${KEY_HELP}`);
|
|
256
|
+
return EXIT_FAIL;
|
|
257
|
+
}
|
|
258
|
+
const result = await fetchBoard(key, { env: ctx.env, fetch: ctx.fetch });
|
|
259
|
+
if (!result.ok) {
|
|
260
|
+
ctx.err(`featq: ${result.message}`);
|
|
261
|
+
return EXIT_FAIL;
|
|
262
|
+
}
|
|
263
|
+
ctx.out(`Board: ${result.board.name}`);
|
|
264
|
+
ctx.out(`Slug: ${result.board.slug}`);
|
|
265
|
+
if (result.board.url) ctx.out(`Page: ${result.board.url}`);
|
|
266
|
+
ctx.out(`MCP server: ${mcpUrl(ctx.env)}`);
|
|
267
|
+
ctx.out('The key works.');
|
|
268
|
+
return EXIT_OK;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function displayPath(path, ctx) {
|
|
272
|
+
const rel = relative(ctx.cwd, path);
|
|
273
|
+
if (rel && !rel.startsWith('..')) return rel;
|
|
274
|
+
if (ctx.home && path.startsWith(ctx.home)) return '~' + path.slice(ctx.home.length);
|
|
275
|
+
return path;
|
|
276
|
+
}
|
package/lib/clients.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { ENV_KEY, mcpUrl } from './constants.js';
|
|
3
|
+
|
|
4
|
+
// Each client either gets a config file entry (claude, cursor) or a command to
|
|
5
|
+
// run (codex, gemini). Shapes match the repo README and .mcp.json exactly.
|
|
6
|
+
// The key itself is never written: configs hold an env reference.
|
|
7
|
+
|
|
8
|
+
export const CLIENT_NAMES = ['claude', 'cursor', 'codex', 'gemini'];
|
|
9
|
+
|
|
10
|
+
export function getClient(name, { env = process.env, cwd = process.cwd(), home = '', platform = process.platform } = {}) {
|
|
11
|
+
const url = mcpUrl(env);
|
|
12
|
+
// How the shell expands the key variable in a printed command.
|
|
13
|
+
const keyRef = platform === 'win32' ? `$env:${ENV_KEY}` : `$${ENV_KEY}`;
|
|
14
|
+
switch (name) {
|
|
15
|
+
case 'claude':
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
label: 'Claude Code',
|
|
19
|
+
file: join(cwd, '.mcp.json'),
|
|
20
|
+
entry: {
|
|
21
|
+
type: 'http',
|
|
22
|
+
url,
|
|
23
|
+
headers: { Authorization: `Bearer \${${ENV_KEY}}` },
|
|
24
|
+
},
|
|
25
|
+
// Claude Code keeps user-wide servers in its own store; its CLI writes them.
|
|
26
|
+
globalCommand: `claude mcp add --scope user --transport http featq ${url} --header "Authorization: Bearer ${keyRef}"`,
|
|
27
|
+
};
|
|
28
|
+
case 'cursor':
|
|
29
|
+
return {
|
|
30
|
+
name,
|
|
31
|
+
label: 'Cursor',
|
|
32
|
+
file: join(cwd, '.cursor', 'mcp.json'),
|
|
33
|
+
globalFile: home ? join(home, '.cursor', 'mcp.json') : null,
|
|
34
|
+
entry: {
|
|
35
|
+
url,
|
|
36
|
+
headers: { Authorization: `Bearer \${env:${ENV_KEY}}` },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
case 'codex':
|
|
40
|
+
return {
|
|
41
|
+
name,
|
|
42
|
+
label: 'Codex',
|
|
43
|
+
command: `codex mcp add featq --url ${url} --bearer-token-env-var ${ENV_KEY}`,
|
|
44
|
+
};
|
|
45
|
+
case 'gemini':
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
label: 'Gemini CLI',
|
|
49
|
+
command: 'gemini extensions install https://github.com/max-reid-repos/featq-mcp',
|
|
50
|
+
};
|
|
51
|
+
default:
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, open, readFile, realpath, rename, rm, stat } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative } from 'node:path';
|
|
4
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
5
|
+
|
|
6
|
+
export class ConfigError extends Error {}
|
|
7
|
+
|
|
8
|
+
/** Mode for a config file this tool creates: owner read/write only. */
|
|
9
|
+
export const NEW_FILE_MODE = 0o600;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Merge the "featq" server into an MCP config file's text.
|
|
13
|
+
* text: current file contents, or null when the file does not exist.
|
|
14
|
+
* Returns { status: 'created' | 'added' | 'unchanged' | 'replaced', text }.
|
|
15
|
+
* Throws ConfigError on invalid JSON, a wrong shape, or a different existing
|
|
16
|
+
* "featq" entry without overwrite. Every other key is kept as it was.
|
|
17
|
+
*/
|
|
18
|
+
export function mergeConfig(text, entry, { overwrite = false, fileLabel = 'the config file' } = {}) {
|
|
19
|
+
if (text === null || text.trim() === '') {
|
|
20
|
+
return {
|
|
21
|
+
status: 'created',
|
|
22
|
+
text: serialize({ mcpServers: { featq: entry } }),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let data;
|
|
27
|
+
try {
|
|
28
|
+
data = JSON.parse(text.replace(/^\uFEFF/, ''));
|
|
29
|
+
} catch {
|
|
30
|
+
// No parser message here: it can quote file content.
|
|
31
|
+
throw new ConfigError(`${fileLabel} is not valid JSON. Fix it and run this again. Nothing was changed.`);
|
|
32
|
+
}
|
|
33
|
+
if (!isPlainObject(data)) {
|
|
34
|
+
throw new ConfigError(`${fileLabel} does not hold a JSON object. Nothing was changed.`);
|
|
35
|
+
}
|
|
36
|
+
if (data.mcpServers !== undefined && !isPlainObject(data.mcpServers)) {
|
|
37
|
+
throw new ConfigError(`"mcpServers" in ${fileLabel} is not an object. Nothing was changed.`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const servers = data.mcpServers ?? {};
|
|
41
|
+
const existing = servers.featq;
|
|
42
|
+
if (existing !== undefined) {
|
|
43
|
+
if (isDeepStrictEqual(existing, entry)) return { status: 'unchanged', text };
|
|
44
|
+
if (!overwrite) {
|
|
45
|
+
throw new ConfigError(
|
|
46
|
+
`${fileLabel} already has a different "featq" server. Run again with --yes to replace it. Nothing was changed.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const next = { ...data, mcpServers: { ...servers, featq: entry } };
|
|
52
|
+
return { status: existing === undefined ? 'added' : 'replaced', text: serialize(next) };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The real path the config lives at, with every link resolved: the file
|
|
57
|
+
* itself, or (when it does not exist yet) its nearest existing folder plus the
|
|
58
|
+
* missing part. A link to something that does not exist is refused.
|
|
59
|
+
*/
|
|
60
|
+
export async function realTargetOf(path, fileLabel = path) {
|
|
61
|
+
let probe = path;
|
|
62
|
+
const missing = [];
|
|
63
|
+
for (;;) {
|
|
64
|
+
try {
|
|
65
|
+
await lstat(probe);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (err.code !== 'ENOENT') throw new ConfigError(`Could not read ${fileLabel} (${err.code}). Nothing was changed.`);
|
|
68
|
+
const parent = dirname(probe);
|
|
69
|
+
if (parent === probe) return path;
|
|
70
|
+
missing.unshift(basename(probe));
|
|
71
|
+
probe = parent;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return join(await realpath(probe), ...missing);
|
|
76
|
+
} catch {
|
|
77
|
+
throw new ConfigError(`${fileLabel} goes through a link to a file or folder that does not exist. Nothing was changed.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** True when the path, or a folder on the way down from base, is a symlink. */
|
|
83
|
+
async function goesThroughLink(path, base) {
|
|
84
|
+
const rel = relative(base, path);
|
|
85
|
+
if (!rel || rel.startsWith('..') || isAbsolute(rel)) return false;
|
|
86
|
+
let probe = path;
|
|
87
|
+
while (probe !== base && probe !== dirname(probe)) {
|
|
88
|
+
try {
|
|
89
|
+
if ((await lstat(probe)).isSymbolicLink()) return true;
|
|
90
|
+
} catch {
|
|
91
|
+
// does not exist yet
|
|
92
|
+
}
|
|
93
|
+
probe = dirname(probe);
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isInside(child, parent) {
|
|
99
|
+
const rel = relative(parent, child);
|
|
100
|
+
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Read, merge and write one config file. Writes a new temp file next to the
|
|
105
|
+
* target (random name, exclusive create, so it never follows a planted link),
|
|
106
|
+
* keeps the original file mode (new files get 0600), then renames it over.
|
|
107
|
+
*
|
|
108
|
+
* Links are followed: the link stays and the real file is updated.
|
|
109
|
+
* base: the folder the path is shown relative to (cwd, or home for a global
|
|
110
|
+
* config); a link between base and the file is reported as `via`.
|
|
111
|
+
* insideOf: for a project config, the cwd; a real path outside its real path
|
|
112
|
+
* is refused unless allowOutside.
|
|
113
|
+
* Returns { status, text, target, linked }.
|
|
114
|
+
*/
|
|
115
|
+
export async function writeServerEntry(
|
|
116
|
+
path,
|
|
117
|
+
entry,
|
|
118
|
+
{ overwrite = false, fileLabel = path, base = dirname(path), insideOf = null, allowOutside = false } = {}
|
|
119
|
+
) {
|
|
120
|
+
const target = await realTargetOf(path, fileLabel);
|
|
121
|
+
const linked = await goesThroughLink(path, base);
|
|
122
|
+
if (insideOf && !allowOutside) {
|
|
123
|
+
const realRoot = await realpath(insideOf).catch(() => insideOf);
|
|
124
|
+
if (!isInside(target, realRoot)) {
|
|
125
|
+
throw new ConfigError(
|
|
126
|
+
`${fileLabel} points to ${target}, outside this folder. Run again with --yes to write there. Nothing was changed.`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let text = null;
|
|
132
|
+
let mode = NEW_FILE_MODE;
|
|
133
|
+
try {
|
|
134
|
+
text = await readFile(target, 'utf8');
|
|
135
|
+
mode = (await stat(target)).mode & 0o7777;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (err.code !== 'ENOENT') throw new ConfigError(`Could not read ${fileLabel} (${err.code}). Nothing was changed.`);
|
|
138
|
+
text = null;
|
|
139
|
+
mode = NEW_FILE_MODE;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const result = mergeConfig(text, entry, { overwrite, fileLabel });
|
|
143
|
+
if (result.status === 'unchanged') return { ...result, target, linked };
|
|
144
|
+
|
|
145
|
+
const dir = dirname(target);
|
|
146
|
+
await mkdir(dir, { recursive: true });
|
|
147
|
+
const tmp = join(dir, `.${basename(target)}.featq-${randomBytes(8).toString('hex')}.tmp`);
|
|
148
|
+
let handle;
|
|
149
|
+
let created = false;
|
|
150
|
+
try {
|
|
151
|
+
handle = await open(tmp, 'wx', NEW_FILE_MODE);
|
|
152
|
+
created = true;
|
|
153
|
+
await handle.writeFile(result.text, 'utf8');
|
|
154
|
+
await handle.chmod(mode); // exact mode, whatever the umask
|
|
155
|
+
await handle.close();
|
|
156
|
+
handle = null;
|
|
157
|
+
await rename(tmp, target);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
if (handle) await handle.close().catch(() => {});
|
|
160
|
+
// Only remove a temp file this run created, never one that was already there.
|
|
161
|
+
if (created) await rm(tmp, { force: true }).catch(() => {});
|
|
162
|
+
throw new ConfigError(`Could not write ${fileLabel} (${err.code || err.message}).`);
|
|
163
|
+
}
|
|
164
|
+
return { ...result, target, linked };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function serialize(obj) {
|
|
168
|
+
return JSON.stringify(obj, null, 2) + '\n';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isPlainObject(value) {
|
|
172
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
173
|
+
}
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Kept in step with package.json "version" (a test checks it), so the CLI
|
|
2
|
+
// never has to read a file to print its version.
|
|
3
|
+
export const VERSION = '0.1.0';
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_BASE_URL = 'https://featq.com';
|
|
6
|
+
export const MCP_PATH = '/api/mcp';
|
|
7
|
+
export const ENV_KEY = 'FEATQ_BOARD_KEY';
|
|
8
|
+
export const ENV_URL = 'FEATQ_URL';
|
|
9
|
+
export const KEY_HELP =
|
|
10
|
+
'Your board key is on your FeatQ board admin page, under "Connect your coding agent".';
|
|
11
|
+
|
|
12
|
+
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Check FEATQ_URL. Returns { ok: true, custom: false } when unset,
|
|
16
|
+
* { ok: true, custom: true, host } when it is usable, or { ok: false, message }.
|
|
17
|
+
* Only https is allowed, except http on localhost / 127.0.0.1 / [::1].
|
|
18
|
+
*/
|
|
19
|
+
export function checkBaseUrl(env) {
|
|
20
|
+
const raw = env && env[ENV_URL];
|
|
21
|
+
if (!raw) return { ok: true, custom: false };
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(raw);
|
|
25
|
+
} catch {
|
|
26
|
+
return { ok: false, message: `${ENV_URL} is not a valid URL.` };
|
|
27
|
+
}
|
|
28
|
+
const local = LOCAL_HOSTS.has(url.hostname);
|
|
29
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && local)) {
|
|
30
|
+
return { ok: false, message: `${ENV_URL} must use https (http is allowed only for localhost).` };
|
|
31
|
+
}
|
|
32
|
+
return { ok: true, custom: true, host: url.host };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Base URL for every request: featq.com, or FEATQ_URL when set and valid. */
|
|
36
|
+
export function baseUrl(env) {
|
|
37
|
+
const check = checkBaseUrl(env);
|
|
38
|
+
if (!check.ok) throw new Error(check.message);
|
|
39
|
+
const raw = check.custom ? env[ENV_URL] : DEFAULT_BASE_URL;
|
|
40
|
+
return raw.replace(/\/+$/, '');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The MCP endpoint written into configs. Always featq.com unless FEATQ_URL is set. */
|
|
44
|
+
export function mcpUrl(env) {
|
|
45
|
+
return baseUrl(env) + MCP_PATH;
|
|
46
|
+
}
|
package/lib/key.js
ADDED
package/lib/prompt.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { Writable } from 'node:stream';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ask for a secret on a terminal without echoing what is typed.
|
|
6
|
+
* The prompt goes to `output` (stderr by default) so stdout stays clean.
|
|
7
|
+
* Rejects with Error('cancelled') on Ctrl-C, Ctrl-D or a closed stream.
|
|
8
|
+
*/
|
|
9
|
+
export function promptHidden(question, { input = process.stdin, output = process.stderr } = {}) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
let muted = false;
|
|
12
|
+
let settled = false;
|
|
13
|
+
const sink = new Writable({
|
|
14
|
+
write(chunk, encoding, done) {
|
|
15
|
+
if (!muted) output.write(chunk, encoding);
|
|
16
|
+
done();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const rl = createInterface({ input, output: sink, terminal: true });
|
|
20
|
+
const cancel = () => {
|
|
21
|
+
if (settled) return;
|
|
22
|
+
settled = true;
|
|
23
|
+
output.write('\n');
|
|
24
|
+
reject(new Error('cancelled'));
|
|
25
|
+
};
|
|
26
|
+
rl.on('SIGINT', () => {
|
|
27
|
+
cancel();
|
|
28
|
+
rl.close();
|
|
29
|
+
});
|
|
30
|
+
rl.on('close', cancel);
|
|
31
|
+
rl.question(question, (answer) => {
|
|
32
|
+
if (settled) return;
|
|
33
|
+
settled = true;
|
|
34
|
+
output.write('\n');
|
|
35
|
+
resolve(answer.trim());
|
|
36
|
+
rl.close();
|
|
37
|
+
});
|
|
38
|
+
muted = true;
|
|
39
|
+
});
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@featq/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": { "access": "public" },
|
|
5
|
+
"description": "Official FeatQ CLI: connect your coding agent (Claude Code, Cursor, Codex, Gemini CLI) to your FeatQ feature request board over MCP.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"featq": "bin/featq.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin/",
|
|
13
|
+
"lib/",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test test/*.test.js"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/max-reid-repos/featq-mcp.git",
|
|
26
|
+
"directory": "npm"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://featq.com/docs/mcp",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/max-reid-repos/featq-mcp/issues"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"featq",
|
|
34
|
+
"mcp",
|
|
35
|
+
"model-context-protocol",
|
|
36
|
+
"feature-requests",
|
|
37
|
+
"claude-code",
|
|
38
|
+
"cursor",
|
|
39
|
+
"codex",
|
|
40
|
+
"gemini-cli",
|
|
41
|
+
"cli"
|
|
42
|
+
]
|
|
43
|
+
}
|