qatools-cli 1.3.0 → 1.3.2
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/package.json +2 -1
- package/qatools.js +12 -5
- package/skills-layout.js +109 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qatools-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"own-login.js",
|
|
18
18
|
"impact.js",
|
|
19
19
|
"context-sync.js",
|
|
20
|
+
"skills-layout.js",
|
|
20
21
|
"hooks.js",
|
|
21
22
|
"brief.js",
|
|
22
23
|
"secrets.js",
|
package/qatools.js
CHANGED
|
@@ -724,11 +724,18 @@ async function latestPublishedVersion() {
|
|
|
724
724
|
if (c.latest && Date.now() - c.checkedAt < 3600 * 1000) return c.latest; // cli.self-upgrade: a new version is noticed within the hour
|
|
725
725
|
} catch {}
|
|
726
726
|
try {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
const
|
|
727
|
+
// Not fetch: its keep-alive socket can still be closing when a command calls process.exit, and on Windows libuv
|
|
728
|
+
// then aborts ("Assertion failed: !(handle->flags & UV_HANDLE_CLOSING)", exit 0xC0000409). agent:false closes
|
|
729
|
+
// the connection with the response.
|
|
730
|
+
const url = new URL(process.env.QATOOLS_UPDATE_URL || "https://registry.npmjs.org/qatools-cli/latest");
|
|
731
|
+
const body = await new Promise((resolve, reject) => {
|
|
732
|
+
const req = require(url.protocol === "http:" ? "http" : "https").get(url, { agent: false, headers: { accept: "application/json" } }, (res) => {
|
|
733
|
+
let s = ""; res.setEncoding("utf8"); res.on("data", d => s += d); res.on("end", () => resolve(s)); res.on("error", reject);
|
|
734
|
+
});
|
|
735
|
+
req.setTimeout(2000, () => req.destroy(new Error("timeout")));
|
|
736
|
+
req.on("error", reject);
|
|
737
|
+
});
|
|
738
|
+
const latest = JSON.parse(body).version;
|
|
732
739
|
if (latest) try { fs.writeFileSync(file, JSON.stringify({ checkedAt: Date.now(), latest })); } catch {}
|
|
733
740
|
return latest || null;
|
|
734
741
|
} catch { return null; }
|
package/skills-layout.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// cli.skills-claude-code-format (DEF-74): Claude Code only loads a skill from .claude/skills/<name>/SKILL.md, with
|
|
2
|
+
// name and description in the frontmatter. Earlier CLIs wrote flat .claude/skills/<name>.md files, which Claude Code
|
|
3
|
+
// never loads. These helpers write the folder layout and move flat files qa-tools wrote. Pure fs, unit-tested in
|
|
4
|
+
// test/skills-layout.test.js.
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
// Files in .claude/skills that are not skills and are never moved or warned about
|
|
9
|
+
const NOT_SKILLS = new Set(["readme.md"]);
|
|
10
|
+
|
|
11
|
+
// A skill's folder name: what Claude Code shows as /<name>. Lowercase letters, digits and hyphens.
|
|
12
|
+
function skillName(filename) {
|
|
13
|
+
return String(filename).replace(/\.md$/i, "").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "skill";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// YAML double-quoted scalar: JSON's string syntax is a subset of it, so colons, quotes and dashes are safe
|
|
17
|
+
const yamlString = (s) => JSON.stringify(String(s).replace(/\s+/g, " ").trim());
|
|
18
|
+
|
|
19
|
+
// Split a leading --- frontmatter --- block off a Markdown text: { fields, other, body }. fields holds name and
|
|
20
|
+
// description as plain strings (a folded "description: >" block is joined); other keeps every other line as written.
|
|
21
|
+
function splitFrontmatter(text) {
|
|
22
|
+
const s = String(text || "").replace(/^/, "").replace(/\r\n/g, "\n");
|
|
23
|
+
const m = s.match(/^---\n([\s\S]*?)\n---\n?/);
|
|
24
|
+
if (!m) return { fields: {}, other: [], body: s };
|
|
25
|
+
const fields = {}, other = [];
|
|
26
|
+
const lines = m[1].split("\n");
|
|
27
|
+
for (let i = 0; i < lines.length; i++) {
|
|
28
|
+
const f = lines[i].match(/^(name|description):\s*(.*)$/);
|
|
29
|
+
if (!f) { other.push(lines[i]); continue; }
|
|
30
|
+
let v = f[2].trim();
|
|
31
|
+
if (/^[>|][-+]?$/.test(v)) { // block scalar: the indented lines that follow
|
|
32
|
+
const block = [];
|
|
33
|
+
while (i + 1 < lines.length && /^\s+\S|^\s*$/.test(lines[i + 1])) block.push(lines[++i].trim());
|
|
34
|
+
v = block.filter(Boolean).join(" ");
|
|
35
|
+
} else if (/^".*"$/.test(v)) { try { v = JSON.parse(v); } catch {} }
|
|
36
|
+
else if (/^'.*'$/.test(v)) v = v.slice(1, -1).replace(/''/g, "'");
|
|
37
|
+
fields[f[1]] = v;
|
|
38
|
+
}
|
|
39
|
+
return { fields, other: other.filter(l => l.trim()), body: s.slice(m[0].length) };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The SKILL.md text: name and description first in the frontmatter (other lines kept as written), then the body.
|
|
43
|
+
// Without a description, the first non-empty line of the body is used — as Claude Code itself does.
|
|
44
|
+
function toSkillMd(name, text) {
|
|
45
|
+
const { fields, other, body } = splitFrontmatter(text);
|
|
46
|
+
const description = fields.description || (body.split("\n").find(l => l.trim()) || name).replace(/^#+\s*/, "");
|
|
47
|
+
const front = [`name: ${name}`, `description: ${yamlString(description)}`, ...other];
|
|
48
|
+
return `---\n${front.join("\n")}\n---\n\n${body.replace(/^\n+/, "")}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const skillFile = (skillsDir, name) => path.join(skillsDir, name, "SKILL.md");
|
|
52
|
+
|
|
53
|
+
// Write one skill as <name>/SKILL.md and remove the flat <name>.md an earlier CLI wrote. Returns the name.
|
|
54
|
+
function writeSkill(skillsDir, filename, text) {
|
|
55
|
+
const name = skillName(filename);
|
|
56
|
+
fs.mkdirSync(path.join(skillsDir, name), { recursive: true });
|
|
57
|
+
fs.writeFileSync(skillFile(skillsDir, name), toSkillMd(name, text));
|
|
58
|
+
const flat = path.join(skillsDir, `${name}.md`);
|
|
59
|
+
try { if (fs.statSync(flat).isFile()) fs.unlinkSync(flat); } catch {}
|
|
60
|
+
return name;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Flat .md files directly in .claude/skills — Claude Code does not load them
|
|
64
|
+
function flatSkillFiles(skillsDir) {
|
|
65
|
+
try {
|
|
66
|
+
return fs.readdirSync(skillsDir, { withFileTypes: true })
|
|
67
|
+
.filter(d => d.isFile() && /\.md$/i.test(d.name) && !NOT_SKILLS.has(d.name.toLowerCase()))
|
|
68
|
+
.map(d => d.name).sort();
|
|
69
|
+
} catch { return []; }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Move the flat files qa-tools wrote (their names are in `owned`) to <name>/SKILL.md, keeping their text.
|
|
73
|
+
// Returns { moved: [names], foreign: [file names left as they are] }.
|
|
74
|
+
function migrateFlatSkills(skillsDir, owned) {
|
|
75
|
+
const ownedNames = new Set([...owned].map(skillName));
|
|
76
|
+
const moved = [], foreign = [];
|
|
77
|
+
for (const f of flatSkillFiles(skillsDir)) {
|
|
78
|
+
if (!ownedNames.has(skillName(f))) { foreign.push(f); continue; }
|
|
79
|
+
const text = fs.readFileSync(path.join(skillsDir, f), "utf8");
|
|
80
|
+
// A folder written by a newer run wins over the flat leftover; the flat file just goes
|
|
81
|
+
if (!fs.existsSync(skillFile(skillsDir, skillName(f)))) writeSkill(skillsDir, f, text);
|
|
82
|
+
else fs.unlinkSync(path.join(skillsDir, f));
|
|
83
|
+
moved.push(skillName(f));
|
|
84
|
+
}
|
|
85
|
+
return { moved, foreign };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Does this .claude/skills hold qa-tools skills, in either layout?
|
|
89
|
+
function hasQaSkills(skillsDir) {
|
|
90
|
+
try {
|
|
91
|
+
return fs.readdirSync(skillsDir, { withFileTypes: true }).some(d =>
|
|
92
|
+
(d.isFile() && /^qa-.*\.md$/.test(d.name)) || (d.isDirectory() && /^qa-/.test(d.name) && fs.existsSync(path.join(skillsDir, d.name, "SKILL.md"))));
|
|
93
|
+
} catch { return false; }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// CLAUDE.md text that earlier `qatools init` wrote points at the flat qa-purpose.md; point it at the folder.
|
|
97
|
+
function repointClaudeMd(text) {
|
|
98
|
+
return String(text)
|
|
99
|
+
.split(".claude/skills/qa-purpose.md").join(".claude/skills/qa-purpose/SKILL.md")
|
|
100
|
+
.split("Start with `qa-purpose.md`.").join("Start with the `qa-purpose` skill.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function foreignWarning(files) {
|
|
104
|
+
if (!files.length) return null;
|
|
105
|
+
return `⚠ Claude Code does not load flat skill files: ${files.map(f => ".claude/skills/" + f).join(", ")}. ` +
|
|
106
|
+
`Move each to .claude/skills/<name>/SKILL.md with name and description in its frontmatter (qatools left ${files.length > 1 ? "them" : "it"} as ${files.length > 1 ? "they are" : "it is"}).`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
module.exports = { skillName, splitFrontmatter, toSkillMd, writeSkill, flatSkillFiles, migrateFlatSkills, hasQaSkills, repointClaudeMd, foreignWarning, skillFile };
|