qatools-cli 1.2.17 → 1.2.18
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/context-sync.js +68 -0
- package/package.json +3 -2
- package/qatools.js +42 -16
package/context-sync.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// context.sync-what-is-built: the part of the synced CLAUDE.md block that says what is already built,
|
|
2
|
+
// so a new session knows it from the start. Pure functions, unit-tested in test/context-sync.test.js.
|
|
3
|
+
|
|
4
|
+
const BEGIN_MARKER = "<!-- BEGIN qatools-context (auto-synced from qa-tools, do not edit by hand) -->";
|
|
5
|
+
const END_MARKER = "<!-- END qatools-context -->";
|
|
6
|
+
|
|
7
|
+
// One line per requirement: key, title, status. No descriptions or criteria, to keep CLAUDE.md short.
|
|
8
|
+
const clean = (s) => String(s || "").replace(/\s+/g, " ").replace(/-->/g, "--\\>").trim();
|
|
9
|
+
|
|
10
|
+
function renderBuiltSection(requirements, epics = []) {
|
|
11
|
+
const epicTitle = new Map(epics.map(e => [e.key, e.title || e.name || e.key]));
|
|
12
|
+
const built = requirements.filter(r => r.status === "implemented" || r.status === "tested");
|
|
13
|
+
const inProgress = requirements.filter(r => r.status === "in_progress");
|
|
14
|
+
const byKey = (a, b) => String(a.key || "").localeCompare(String(b.key || ""));
|
|
15
|
+
const lines = [];
|
|
16
|
+
|
|
17
|
+
lines.push("### What is already built");
|
|
18
|
+
lines.push("> Every implemented or tested requirement in qa-tools, grouped by epic. Before you build something or say it is missing, check this list and `qatools requirements` — work may exist on another branch or from before you. Synced from requirement statuses, which need evidence.");
|
|
19
|
+
lines.push("");
|
|
20
|
+
if (!built.length) {
|
|
21
|
+
lines.push("_No requirements are implemented or tested yet._");
|
|
22
|
+
lines.push("");
|
|
23
|
+
} else {
|
|
24
|
+
const groups = new Map();
|
|
25
|
+
for (const r of built) {
|
|
26
|
+
const g = r.epicKey || "";
|
|
27
|
+
if (!groups.has(g)) groups.set(g, []);
|
|
28
|
+
groups.get(g).push(r);
|
|
29
|
+
}
|
|
30
|
+
// Epics in the project's epic order, then any unknown epic keys, then requirements without an epic
|
|
31
|
+
const order = [...epics.map(e => e.key).filter(k => groups.has(k)),
|
|
32
|
+
...[...groups.keys()].filter(k => k && !epicTitle.has(k)).sort()];
|
|
33
|
+
if (groups.has("")) order.push("");
|
|
34
|
+
for (const g of order) {
|
|
35
|
+
lines.push(g ? `#### ${clean(epicTitle.get(g) || g)} (${g})` : "#### No epic");
|
|
36
|
+
for (const r of groups.get(g).sort(byKey)) lines.push(`- \`${clean(r.key)}\` ${clean(r.title)} (${r.status})`);
|
|
37
|
+
lines.push("");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
lines.push("### Being built now");
|
|
42
|
+
if (!inProgress.length) lines.push("_Nothing is in progress._");
|
|
43
|
+
// A Claude API-key account (claude@<projectid>.qatools) reads as "Claude"
|
|
44
|
+
const who = (email) => /^claude@[^@]+\.qatools$/i.test(String(email)) ? "Claude" : clean(email);
|
|
45
|
+
for (const r of inProgress.sort(byKey)) {
|
|
46
|
+
lines.push(`- \`${clean(r.key)}\` ${clean(r.title)}${r.assignedTo ? ` — ${who(r.assignedTo)}` : ""}`);
|
|
47
|
+
}
|
|
48
|
+
lines.push("");
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Replace the synced block in a file's text, or append it. Text outside the block is kept as is.
|
|
53
|
+
function spliceBlock(existing, md) {
|
|
54
|
+
const block = `${BEGIN_MARKER}\n${md}\n${END_MARKER}`;
|
|
55
|
+
const beginIdx = existing.indexOf(BEGIN_MARKER);
|
|
56
|
+
const endIdx = existing.indexOf(END_MARKER);
|
|
57
|
+
if (beginIdx >= 0 && endIdx > beginIdx) {
|
|
58
|
+
return existing.slice(0, beginIdx) + block + existing.slice(endIdx + END_MARKER.length);
|
|
59
|
+
}
|
|
60
|
+
const sep = existing && !existing.endsWith("\n") ? "\n\n" : (existing ? "\n" : "");
|
|
61
|
+
return existing + sep + block + "\n";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The sync time changes on every run; it must not make --check report a change on its own.
|
|
65
|
+
const withoutSyncTime = (text) => String(text).replace(/<!-- Last synced: [^>]*-->/g, "<!-- Last synced -->").replace(/\r\n/g, "\n");
|
|
66
|
+
const sameContent = (a, b) => withoutSyncTime(a) === withoutSyncTime(b);
|
|
67
|
+
|
|
68
|
+
module.exports = { BEGIN_MARKER, END_MARKER, renderBuiltSection, spliceBlock, sameContent };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qatools-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.18",
|
|
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",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"qatools.js",
|
|
15
|
-
"impact.js"
|
|
15
|
+
"impact.js",
|
|
16
|
+
"context-sync.js"
|
|
16
17
|
],
|
|
17
18
|
"keywords": [
|
|
18
19
|
"qa",
|
package/qatools.js
CHANGED
|
@@ -1254,27 +1254,24 @@ program
|
|
|
1254
1254
|
process.exit(1);
|
|
1255
1255
|
}
|
|
1256
1256
|
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1257
|
+
const { BEGIN_MARKER: beginMarker, END_MARKER: endMarker, spliceBlock, sameContent } = require("./context-sync");
|
|
1258
|
+
let md;
|
|
1259
|
+
try {
|
|
1260
|
+
md = await renderSyncedContext(ctx, projectId, systemAiRules);
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
console.error("Failed to fetch requirements:", e.message);
|
|
1263
|
+
process.exit(1);
|
|
1264
|
+
}
|
|
1260
1265
|
const block = `${beginMarker}\n${md}\n${endMarker}`;
|
|
1261
1266
|
|
|
1262
1267
|
const filePath = path.resolve(options.output);
|
|
1263
1268
|
let existing = "";
|
|
1264
1269
|
if (fs.existsSync(filePath)) existing = fs.readFileSync(filePath, "utf8");
|
|
1265
1270
|
|
|
1266
|
-
|
|
1267
|
-
const beginIdx = existing.indexOf(beginMarker);
|
|
1268
|
-
const endIdx = existing.indexOf(endMarker);
|
|
1269
|
-
if (beginIdx >= 0 && endIdx > beginIdx) {
|
|
1270
|
-
updated = existing.slice(0, beginIdx) + block + existing.slice(endIdx + endMarker.length);
|
|
1271
|
-
} else {
|
|
1272
|
-
const sep = existing && !existing.endsWith("\n") ? "\n\n" : (existing ? "\n" : "");
|
|
1273
|
-
updated = existing + sep + block + "\n";
|
|
1274
|
-
}
|
|
1271
|
+
const updated = spliceBlock(existing, md);
|
|
1275
1272
|
|
|
1276
1273
|
if (options.check) {
|
|
1277
|
-
if (existing
|
|
1274
|
+
if (sameContent(existing, updated)) {
|
|
1278
1275
|
console.log(`✓ ${options.output} is in sync with project ${projectId}`);
|
|
1279
1276
|
process.exit(0);
|
|
1280
1277
|
} else {
|
|
@@ -1284,7 +1281,7 @@ program
|
|
|
1284
1281
|
}
|
|
1285
1282
|
|
|
1286
1283
|
if (options.dryRun) {
|
|
1287
|
-
if (existing
|
|
1284
|
+
if (sameContent(existing, updated)) {
|
|
1288
1285
|
console.log(`✓ ${options.output} already in sync — nothing would change.`);
|
|
1289
1286
|
process.exit(0);
|
|
1290
1287
|
}
|
|
@@ -1326,7 +1323,7 @@ program
|
|
|
1326
1323
|
process.exit(0);
|
|
1327
1324
|
}
|
|
1328
1325
|
|
|
1329
|
-
if (existing
|
|
1326
|
+
if (sameContent(existing, updated)) {
|
|
1330
1327
|
console.log(`✓ ${options.output} already in sync (no changes)`);
|
|
1331
1328
|
} else {
|
|
1332
1329
|
fs.writeFileSync(filePath, updated);
|
|
@@ -1335,6 +1332,16 @@ program
|
|
|
1335
1332
|
process.exit(0);
|
|
1336
1333
|
});
|
|
1337
1334
|
|
|
1335
|
+
// context.sync-what-is-built: App Context plus what is already built, as one synced block
|
|
1336
|
+
async function renderSyncedContext(ctx, projectId, systemAiRules) {
|
|
1337
|
+
const { renderBuiltSection } = require("./context-sync");
|
|
1338
|
+
const [reqRes, epicRes] = await Promise.all([
|
|
1339
|
+
httpsCallable(functions, "listRequirements")({ projectId, status: null }),
|
|
1340
|
+
httpsCallable(functions, "listEpics")({ projectId }),
|
|
1341
|
+
]);
|
|
1342
|
+
return renderAppContextMarkdown(ctx, projectId, systemAiRules) + "\n" + renderBuiltSection(reqRes.data.requirements || [], epicRes.data.epics || []);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1338
1345
|
function renderAppContextMarkdown(ctx, projectId, systemAiRules) {
|
|
1339
1346
|
const lines = [];
|
|
1340
1347
|
const ts = new Date().toISOString();
|
|
@@ -3058,7 +3065,7 @@ See \`.claude/skills/\` for role-specific instructions. Start with \`qa-purpose.
|
|
|
3058
3065
|
const systemRules = syncResult.data.systemAiRules || [];
|
|
3059
3066
|
if (syncCtx) {
|
|
3060
3067
|
// Use the same sync logic as qatools sync
|
|
3061
|
-
const syncMd =
|
|
3068
|
+
const syncMd = await renderSyncedContext(syncCtx, creds.projectId, systemRules);
|
|
3062
3069
|
const beginMarker = "<!-- BEGIN qatools-context (auto-synced from qa-tools, do not edit by hand) -->";
|
|
3063
3070
|
const endMarker = "<!-- END qatools-context -->";
|
|
3064
3071
|
const block = `${beginMarker}\n${syncMd}\n${endMarker}`;
|
|
@@ -4484,6 +4491,25 @@ program
|
|
|
4484
4491
|
process.exit(0);
|
|
4485
4492
|
});
|
|
4486
4493
|
|
|
4494
|
+
program
|
|
4495
|
+
.command("audit")
|
|
4496
|
+
.description("The project's security log (owner or superadmin; log in with Google, not with an API key)")
|
|
4497
|
+
.option("--limit <n>", "Number of entries", "50")
|
|
4498
|
+
.option("--json", "Output as JSON")
|
|
4499
|
+
.option("--project <id>", "Target project ID")
|
|
4500
|
+
.action(async (options) => {
|
|
4501
|
+
await authenticate(options);
|
|
4502
|
+
const projectId = options.project || getCredentials()?.projectId;
|
|
4503
|
+
if (!projectId) { console.error("No project configured. Run: qatools setup, or pass --project <id>"); process.exit(1); }
|
|
4504
|
+
try {
|
|
4505
|
+
const { entries } = (await httpsCallable(functions, "listAuditLog")({ projectId, limit: Number(options.limit) || 50 })).data;
|
|
4506
|
+
if (options.json) { console.log(JSON.stringify(entries, null, 2)); process.exit(0); }
|
|
4507
|
+
for (const x of entries) console.log(` ${x.at.slice(0, 16).replace("T", " ")} ${x.actor.padEnd(32)} ${x.action.padEnd(30)} ${Object.entries(x.details || {}).map(([k, v]) => `${k}=${v}`).join(" ")}${x.ip ? " ip=" + x.ip : ""}`);
|
|
4508
|
+
if (!entries.length) console.log("No security events yet.");
|
|
4509
|
+
} catch (e) { console.error("Failed:", e.message); process.exit(1); }
|
|
4510
|
+
process.exit(0);
|
|
4511
|
+
});
|
|
4512
|
+
|
|
4487
4513
|
program.hook("preAction", async (_root, cmd) => {
|
|
4488
4514
|
if (cmd.name() === "mcp") return; // the MCP server reports through instructions and get_agenda
|
|
4489
4515
|
for (const w of await staleWarnings({ skipSkills: cmd.name() === "init" })) console.error(`⚠ ${w}`);
|