qatools-cli 1.2.40 → 1.2.41
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/own-login.js +78 -0
- package/package.json +2 -1
- package/qatools.js +75 -1
package/own-login.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// cli.claude-own-login: Claude works in qa-tools as Claude, with the project's own key — never on the person's login.
|
|
2
|
+
// `qatools init --claude-login` (run once by the person, signed in as themselves) stores the project's Claude key in a
|
|
3
|
+
// project-own login folder outside the repo, marks the repo with its project (.claude/qatools-project.json, no secret)
|
|
4
|
+
// and points Claude Code's qatools MCP server for the repo at that folder. When Claude runs qatools in a marked repo
|
|
5
|
+
// (Claude Code sets CLAUDECODE=1 for its commands), the CLI uses that login — and refuses rather than fall back to
|
|
6
|
+
// the person's. A person running qatools in a terminal keeps their own login.
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
|
|
11
|
+
const MARKER = path.join(".claude", "qatools-project.json");
|
|
12
|
+
|
|
13
|
+
// The project-own login folder: its .qatools holds only Claude's key for that project
|
|
14
|
+
const projectHome = (projectId, home = os.homedir()) => path.join(home, ".qatools-projects", String(projectId).replace(/[^A-Za-z0-9_-]/g, ""));
|
|
15
|
+
|
|
16
|
+
// The nearest repo marker from cwd upwards → { projectId, projectName, dir } or null
|
|
17
|
+
function findProjectMarker(cwd = process.cwd()) {
|
|
18
|
+
let dir = path.resolve(cwd);
|
|
19
|
+
for (;;) {
|
|
20
|
+
const f = path.join(dir, MARKER);
|
|
21
|
+
try {
|
|
22
|
+
const m = JSON.parse(fs.readFileSync(f, "utf8"));
|
|
23
|
+
if (m && typeof m.projectId === "string" && m.projectId) return { projectId: m.projectId, projectName: m.projectName || "", dir };
|
|
24
|
+
} catch {}
|
|
25
|
+
const up = path.dirname(dir);
|
|
26
|
+
if (up === dir) return null;
|
|
27
|
+
dir = up;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function readProjectLogin(projectId, home = os.homedir()) {
|
|
32
|
+
try {
|
|
33
|
+
const c = JSON.parse(fs.readFileSync(path.join(projectHome(projectId, home), ".qatools"), "utf8"));
|
|
34
|
+
return c && typeof c.apiKey === "string" && c.apiKey ? c : null;
|
|
35
|
+
} catch { return null; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Which login a qatools process should use:
|
|
39
|
+
// { use: "own" } — the person's own (~/.qatools) as before
|
|
40
|
+
// { use: "project", creds } — Claude, in a marked repo, with the project's own login
|
|
41
|
+
// { use: "refuse", message } — Claude in a marked repo without its own login: never the person's
|
|
42
|
+
// An explicit QATOOLS_API_KEY always wins (scheduled runs, CI).
|
|
43
|
+
function chooseLogin({ env = process.env, cwd = process.cwd(), home = os.homedir() } = {}) {
|
|
44
|
+
if (env.QATOOLS_API_KEY) return { use: "own" };
|
|
45
|
+
if (env.CLAUDECODE !== "1") return { use: "own" };
|
|
46
|
+
const marker = findProjectMarker(cwd);
|
|
47
|
+
if (!marker) return { use: "own" };
|
|
48
|
+
const creds = readProjectLogin(marker.projectId, home);
|
|
49
|
+
if (creds) return { use: "project", creds, marker };
|
|
50
|
+
return {
|
|
51
|
+
use: "refuse",
|
|
52
|
+
message: `This repo belongs to the qa-tools project ${marker.projectName || marker.projectId}, and Claude works there with the project's own login — not the person's. ` +
|
|
53
|
+
`Ask the person to run, in their own terminal in this repo: qatools init --claude-login`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function writeProjectLogin({ projectId, projectName, apiKey }, home = os.homedir()) {
|
|
58
|
+
const dir = projectHome(projectId, home);
|
|
59
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
60
|
+
const file = path.join(dir, ".qatools");
|
|
61
|
+
fs.writeFileSync(file, JSON.stringify({ apiKey, projectId, projectName: projectName || "" }, null, 2), { mode: 0o600 });
|
|
62
|
+
return dir;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function writeMarker(repoRoot, { projectId, projectName }) {
|
|
66
|
+
const f = path.join(repoRoot, MARKER);
|
|
67
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
68
|
+
fs.writeFileSync(f, JSON.stringify({ projectId, projectName: projectName || "", note: "qa-tools project of this repo (no secret). Claude's login is in ~/.qatools-projects/<projectId>, outside the repo." }, null, 2) + "\n");
|
|
69
|
+
return f;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// The MCP server entry for Claude Code: the same qatools, with HOME pointing at the project-own login folder
|
|
73
|
+
function mcpServerConfig(projectId, { node = process.execPath, cli = path.join(__dirname, "qatools.js"), home = os.homedir() } = {}) {
|
|
74
|
+
const dir = projectHome(projectId, home);
|
|
75
|
+
return { type: "stdio", command: node, args: [cli, "mcp"], env: { HOME: dir, USERPROFILE: dir, QATOOLS_NO_UPDATE_CHECK: "1" } };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = { MARKER, projectHome, findProjectMarker, readProjectLogin, chooseLogin, writeProjectLogin, writeMarker, mcpServerConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qatools-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.41",
|
|
4
4
|
"description": "CLI for QA Tools — requirements, epics, sprints, sessions, App Context sync, project agenda. The companion to qa-tools.com.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"release": "npm version patch --no-git-tag-version && npm publish",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"files": [
|
|
14
14
|
"qatools.js",
|
|
15
15
|
"mcp-core.js",
|
|
16
|
+
"own-login.js",
|
|
16
17
|
"impact.js",
|
|
17
18
|
"context-sync.js",
|
|
18
19
|
"hooks.js",
|
package/qatools.js
CHANGED
|
@@ -61,7 +61,7 @@ they would have built themselves if they had infinite time.
|
|
|
61
61
|
|
|
62
62
|
You work in qa-tools as Claude, with this project's own Claude key — never on the person's login. On their login everything you do is recorded as them (your claims would count as their independent verification), and you reach all their projects with their rights.
|
|
63
63
|
|
|
64
|
-
When \`qatools\` says "No credentials", or \`qatools brief\` shows a person's email or another project, stop and guide the person, in their language, one step at a time:
|
|
64
|
+
When \`qatools\` says "No credentials" or that the repo needs Claude's own login, or \`qatools brief\` shows a person's email or another project, stop and guide the person, in their language. The simple way: the project's owner opens their own terminal (not Claude Code — there it would count as you) in this repo and runs \`qatools init --claude-login\` (Claude must be switched on for the project in qa-tools). Then they restart Claude Code. For a scheduled run that needs the key in a file, one step at a time:
|
|
65
65
|
|
|
66
66
|
1. In qa-tools: the project → Members → **Claude AI Integration** → **New key** (or **Generate key**) → **Copy**. A project has one Claude key and a new one replaces the old: if another session or scheduled run on this computer uses it, say so first.
|
|
67
67
|
2. Save it from the clipboard, so the key is never typed or shown — Windows PowerShell: \`(Get-Clipboard).Trim() | Set-Content -NoNewline -Encoding ascii C:/qatools-loop/<project>-key.txt\`; macOS: \`mkdir -p ~/.qatools-keys && pbpaste > ~/.qatools-keys/<project>\`.
|
|
@@ -685,7 +685,12 @@ const functions = getFunctions(app);
|
|
|
685
685
|
let envKeyProject = null;
|
|
686
686
|
|
|
687
687
|
// Load credentials from ~/.qatools or env vars
|
|
688
|
+
// cli.claude-own-login: Claude (CLAUDECODE=1) in a repo marked with its project uses that project's own login,
|
|
689
|
+
// and refuses rather than fall back to the person's
|
|
688
690
|
function getCredentials() {
|
|
691
|
+
const chosen = require("./own-login").chooseLogin();
|
|
692
|
+
if (chosen.use === "refuse") { console.error(chosen.message); process.exit(1); }
|
|
693
|
+
if (chosen.use === "project") return envKeyProject ? { ...chosen.creds, ...envKeyProject } : chosen.creds;
|
|
689
694
|
const configPath = path.join(process.env.HOME || process.env.USERPROFILE, ".qatools");
|
|
690
695
|
let creds = null;
|
|
691
696
|
if (fs.existsSync(configPath)) {
|
|
@@ -3384,14 +3389,83 @@ program
|
|
|
3384
3389
|
process.exit(0);
|
|
3385
3390
|
});
|
|
3386
3391
|
|
|
3392
|
+
// cli.claude-own-login: the owner gives Claude its own login for the repo's project — the key is never shown
|
|
3393
|
+
async function setupClaudeLogin(options) {
|
|
3394
|
+
const own = require("./own-login");
|
|
3395
|
+
if (process.env.CLAUDECODE === "1") {
|
|
3396
|
+
console.error("Run this yourself, in your own terminal: qatools init --claude-login. Claude does not create its own key.");
|
|
3397
|
+
process.exit(1);
|
|
3398
|
+
}
|
|
3399
|
+
if (process.env.QATOOLS_API_KEY) { console.error("QATOOLS_API_KEY is set — this needs your own login. Open a terminal without it."); process.exit(1); }
|
|
3400
|
+
let repoRoot = process.cwd();
|
|
3401
|
+
try { repoRoot = String(require("child_process").execFileSync("git", ["rev-parse", "--show-toplevel"], { stdio: ["ignore", "pipe", "ignore"] })).trim() || repoRoot; } catch {}
|
|
3402
|
+
repoRoot = path.resolve(repoRoot);
|
|
3403
|
+
await authenticate(options, { asMember: true }); // the person's own login
|
|
3404
|
+
const { projects } = (await httpsCallable(functions, "listProjects")({})).data;
|
|
3405
|
+
const marker = own.findProjectMarker(repoRoot);
|
|
3406
|
+
const projectId = options.project || marker?.projectId || getCredentials()?.projectId;
|
|
3407
|
+
const project = projects.find(p => p.id === projectId);
|
|
3408
|
+
if (!project) {
|
|
3409
|
+
console.error(`Which project? Pass --project <id>. Yours: ${projects.map(p => `${p.name} (${p.id})`).join(", ")}`);
|
|
3410
|
+
process.exit(1);
|
|
3411
|
+
}
|
|
3412
|
+
// A key only works while Claude is switched on for the project — that is the owner's decision, in the web app
|
|
3413
|
+
if (!project.claudeEnabled) {
|
|
3414
|
+
console.error(`Claude is not switched on for "${project.name}". In qa-tools: ${project.name} → Members → Claude AI Integration → switch it on. Then run this again.`);
|
|
3415
|
+
process.exit(1);
|
|
3416
|
+
}
|
|
3417
|
+
// A working login already there is reused — no new key
|
|
3418
|
+
let reused = false;
|
|
3419
|
+
const existing = own.readProjectLogin(project.id);
|
|
3420
|
+
if (existing) {
|
|
3421
|
+
try {
|
|
3422
|
+
const r = await (await fetch("https://us-central1-qatools-app.cloudfunctions.net/authenticateWithApiKey", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ data: { apiKey: existing.apiKey } }) })).json();
|
|
3423
|
+
reused = r.result?.projectId === project.id;
|
|
3424
|
+
} catch {}
|
|
3425
|
+
}
|
|
3426
|
+
if (!reused) {
|
|
3427
|
+
if (!options.yes) {
|
|
3428
|
+
const rl = require("readline").createInterface({ input: process.stdin, output: process.stdout });
|
|
3429
|
+
const answer = await new Promise(r => rl.question(`Create Claude's own key for "${project.name}"? A project has one Claude key: anything still using the current one (another computer, a scheduled run, a key file) stops working. [y/N] `, r));
|
|
3430
|
+
rl.close();
|
|
3431
|
+
if (!/^(y|yes|j|ja)$/i.test(String(answer).trim())) { console.log("Nothing changed."); process.exit(0); }
|
|
3432
|
+
}
|
|
3433
|
+
let key;
|
|
3434
|
+
try { key = (await httpsCallable(functions, "generateClaudeApiKey")({ projectId: project.id, scope: "full" })).data.key; }
|
|
3435
|
+
catch (e) {
|
|
3436
|
+
console.error(/owner/i.test(e.message) ? `Only the project's owner creates Claude's key. Ask them to run qatools init --claude-login in this repo.` : `Could not create the key: ${e.message}`);
|
|
3437
|
+
process.exit(1);
|
|
3438
|
+
}
|
|
3439
|
+
own.writeProjectLogin({ projectId: project.id, projectName: project.name, apiKey: key });
|
|
3440
|
+
}
|
|
3441
|
+
const markerFile = own.writeMarker(repoRoot, { projectId: project.id, projectName: project.name });
|
|
3442
|
+
// Claude Code's qatools MCP server for this repo (local scope: Claude Code's own settings, not the repo)
|
|
3443
|
+
const cfg = own.mcpServerConfig(project.id);
|
|
3444
|
+
const q = (s) => (/[\s"&|<>^]/.test(s) ? `"${s}"` : s);
|
|
3445
|
+
const envArgs = Object.entries(cfg.env).flatMap(([k, v]) => ["-e", `${k}=${v}`]);
|
|
3446
|
+
const sh = (args) => require("child_process").spawnSync("claude", args.map(q), { cwd: repoRoot, shell: true, encoding: "utf8" });
|
|
3447
|
+
sh(["mcp", "remove", "qatools", "--scope", "local"]);
|
|
3448
|
+
// the name first: -e takes several values and would swallow it
|
|
3449
|
+
const added = sh(["mcp", "add", "qatools", "--scope", "local", ...envArgs, "--", cfg.command, ...cfg.args]);
|
|
3450
|
+
console.log(reused ? `Claude's own login for ${project.name} was already set up — kept it.` : `Claude's own key for ${project.name} is created and kept in ${own.projectHome(project.id)} (outside the repo, never shown).`);
|
|
3451
|
+
console.log(`This repo is marked as ${project.name}: ${path.relative(repoRoot, markerFile)} — commit it (no secret in it).`);
|
|
3452
|
+
if (added.status === 0) console.log("Claude Code's qatools server for this repo now uses Claude's own login. Restart Claude Code (or reload the window).");
|
|
3453
|
+
else console.log(`Could not register the MCP server with Claude Code (${(added.stderr || added.error?.message || "claude not found").trim().split("\n")[0]}). Run in this repo:\n claude mcp add qatools --scope local ${envArgs.map(q).join(" ")} --${q(cfg.command)} ${cfg.args.map(q).join(" ")}`);
|
|
3454
|
+
console.log("From now on, when Claude runs qatools here it works as Claude for this project; when you do, it is you.");
|
|
3455
|
+
}
|
|
3456
|
+
|
|
3387
3457
|
program
|
|
3388
3458
|
.command("init")
|
|
3389
3459
|
.description("One command to set up everything: login + skills + sync + agenda. Just run: qatools init --api-key <key>")
|
|
3390
3460
|
.option("-k, --api-key <key>", "Claude API key (from QA-Tools → Members → Claude AI Integration)")
|
|
3461
|
+
.option("--claude-login", "Give Claude its own login for this repo's project (the owner runs it once, signed in as themselves): creates the project's Claude key, keeps it outside the repo and never shows it")
|
|
3462
|
+
.option("--project <id>", "With --claude-login: the project (default: the repo's marker, else your default project)")
|
|
3463
|
+
.option("-y, --yes", "With --claude-login: do not ask before replacing the project's Claude key")
|
|
3391
3464
|
.option("-e, --email <email>", "Login email")
|
|
3392
3465
|
.option("-p, --password <password>", "Login password")
|
|
3393
3466
|
.action(async (options) => {
|
|
3394
3467
|
const cwd = process.cwd();
|
|
3468
|
+
if (options.claudeLogin) { await setupClaudeLogin(options); process.exit(0); }
|
|
3395
3469
|
|
|
3396
3470
|
// Step 0: Login if api-key provided and not already logged in
|
|
3397
3471
|
const existingCreds = getCredentials();
|