@ladamczyk/skillslint 4.1.2 → 4.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/AGENTS.md +30 -2
- package/bin/cli.js +11 -1
- package/lib/index.cjs +149 -124
- package/lib/index.mjs +124 -120
- package/lib/src/cli.d.ts +2 -0
- package/lib/src/helpers/stats.d.ts +2 -0
- package/lib/src/helpers/stats.test.d.ts +1 -0
- package/lib/src/helpers/threshold.d.ts +1 -1
- package/lib/src/helpers/threshold.test.d.ts +1 -0
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/types.d.ts +1 -0
- package/package.json +14 -21
package/AGENTS.md
CHANGED
|
@@ -29,7 +29,13 @@ The package also exports a JavaScript API (ESM). The `lint` function runs the sa
|
|
|
29
29
|
```js
|
|
30
30
|
import { lint } from '@ladamczyk/skillslint';
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
// `stats` is required — see "Anonymous usage stats" below.
|
|
33
|
+
const result = await lint({
|
|
34
|
+
path: './skills',
|
|
35
|
+
threshold: 70,
|
|
36
|
+
ignored: ['wip-skill'],
|
|
37
|
+
stats: false,
|
|
38
|
+
});
|
|
33
39
|
|
|
34
40
|
result.passed; // boolean — every skill met its threshold and textlint found no errors
|
|
35
41
|
result.fixed; // boolean — whether `fix` was requested (fixes are written to disk)
|
|
@@ -37,7 +43,29 @@ result.skills; // Array<{ name, scores: { overall, structure, clarity, specifici
|
|
|
37
43
|
result.textlint; // raw textlint results for the linted markdown files
|
|
38
44
|
```
|
|
39
45
|
|
|
40
|
-
`lint(options)` accepts the same options as the CLI flags (`path`, `fix`, `ignored`, `threshold`, `overall`, `structure`, `clarity`, `specificity`, `advanced`). Additional named exports: `DEFAULT_PATH`, `DEFAULT_THRESHOLD`, `buildThreshold`, `failsThreshold`, `runTextlint`, `hasTextlintErrors`, and the TypeScript types (`ILintOptions`, `ILintResult`, `IScores`, `ISkillScore`, `IThreshold`).
|
|
46
|
+
`lint(options)` accepts the same options as the CLI flags (`path`, `fix`, `ignored`, `threshold`, `overall`, `structure`, `clarity`, `specificity`, `advanced`), all optional, plus the required `stats: boolean` (see below). Additional named exports: `DEFAULT_PATH`, `DEFAULT_THRESHOLD`, `buildThreshold`, `failsThreshold`, `runTextlint`, `hasTextlintErrors`, and the TypeScript types (`ILintOptions`, `ILintResult`, `IScores`, `ISkillScore`, `IThreshold`).
|
|
47
|
+
|
|
48
|
+
## Anonymous usage stats
|
|
49
|
+
|
|
50
|
+
Opt-in, off until a human says yes. A counted run posts one constant to `https://stats.adamczyk.ovh` and nothing else — every run, every flag combination, byte for byte the same body:
|
|
51
|
+
|
|
52
|
+
```jsonc
|
|
53
|
+
{ "tool": "skillslint", "options": [] } // `options` is always empty
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
So the only thing a send carries is that a run happened. Never sent: skills, file names, paths, scores, findings, thresholds, the flags you typed, project or package names, or anything identifying the user or machine. Sends are fire-and-forget with a 2s timeout; a failure is swallowed and never affects the exit code.
|
|
57
|
+
|
|
58
|
+
- **CLI** — asks the user, once, the first time it runs with a TTY on both stdin and stdout, and stores the answer in `$XDG_CONFIG_HOME/skillslint.json` (`~/.config/skillslint.json` by default):
|
|
59
|
+
|
|
60
|
+
| File state | Meaning | Effect |
|
|
61
|
+
| -------------------- | ----------- | --------------------------------------------- |
|
|
62
|
+
| `{ "stats": true }` | allowed | one POST per run |
|
|
63
|
+
| `{ "stats": false }` | denied | nothing sent, never asked again |
|
|
64
|
+
| no key / no file | never asked | nothing sent, asked again on the next TTY run |
|
|
65
|
+
|
|
66
|
+
Edit or delete the file to change the answer; deleting it returns to "never asked". Non-interactive runs — `CI=true`, a pipe, a subprocess — are never prompted, never counted, and write nothing, so they leave the question open rather than answering it for the user.
|
|
67
|
+
|
|
68
|
+
- **API** — never prompts, never reads that file, and has no default. `stats: boolean` is a **required** option on `lint()`: the caller holds its own user's consent, so it must pass `true` or `false` outright. `false` sends nothing.
|
|
41
69
|
|
|
42
70
|
## Skills directory structure
|
|
43
71
|
|
package/bin/cli.js
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{EExitCode as e,getPackageInfo as t,getRelativePath as n,resolveCwdRelativePath as r}from"@ladamczyk/qoq-utils";import i from"cac";import{assessQuality as a,formatScoreBar as o,getScoreColor as s}from"agent-skills-cli";import c from"picocolors";import{createLinter as l,loadFixerFormatter as u,loadLinterFormatter as d,loadTextlintrc as f}from"textlint";import{writeFile as p}from"fs/promises";import{dirname as m,join as h,resolve as g}from"path";import{mkdirSync as _,readFileSync as v,readdirSync as y,writeFileSync as b}from"fs";import{homedir as x}from"os";import{createInterface as S}from"readline/promises";const C=()=>{try{let{rootPath:e}=t(`@ladamczyk/skillslint`)??{};return e}catch{return process.cwd()}},w=e=>g(`${C()}${e}`),T=e=>n(w(e)),E=async(e,t)=>{let n=await f({configFilePath:T(`/.textlintrc.json`)}),r=l({descriptor:n});try{if(!t)return await r.lintFiles([e]);let n=await r.fixFiles([e]);return await Promise.all(n.map(e=>p(e.filePath,e.output,`utf-8`))),n}catch(e){if(e instanceof Error&&e.name===`TextlintFileSearchError`)return[];throw e}},D=e=>e.some(e=>(`remainingMessages`in e?e.remainingMessages:e.messages).some(e=>e.severity===2)),O=[`overall`,`structure`,`clarity`,`specificity`,`advanced`],k=async(e,t)=>t?(await u({formatterName:`stylish`})).format(e):(await d({formatterName:`stylish`})).format(e),A=async e=>{let t=``,n=await k(e.textlint,e.fixed);return n.trim()&&(t+=`${n}\n`),e.fixed&&D(e.textlint)&&(t+=c.red(`Can't perform automatic fix!
|
|
3
|
+
|
|
4
|
+
`)),e.skills.forEach(({name:e,scores:n})=>{t+=c.gray(`\n/${e}\n`),O.forEach(e=>{let r=`${e[0]?.toUpperCase()}${e.slice(1)}:`.padEnd(13),i=c[s(n[e])];t+=i(`${r}${o(n[e],25)}\n`)})}),e.skills.some(e=>!e.passed)&&(t+=c.red(`At least one skill doesn't meet required threshold!
|
|
5
|
+
`)),e.passed&&(t+=c.green(`
|
|
6
|
+
All good!
|
|
7
|
+
`)),t},j=`https://stats.adamczyk.ovh`,M=h(process.env.XDG_CONFIG_HOME??h(x(),`.config`),`skillslint.json`),N=e=>{try{let t=JSON.parse(v(e,`utf8`));return typeof t==`object`&&t?t:{}}catch{return{}}},P=(e,t)=>{try{_(m(e),{recursive:!0}),b(e,`${JSON.stringify({...N(e),stats:t},null,2)}\n`)}catch{}},F=async()=>{process.stdout.write([c.bold(`
|
|
8
|
+
Skillslint usage stats
|
|
9
|
+
`),`Send a count of skillslint runs to ${j}? Each run posts one thing:\n`,` • the tool name — always the literal ${c.cyan(`"skillslint"`)}\n`,c.gray(`Never sent: your skills, file names, paths, scores, findings, thresholds,
|
|
10
|
+
the flags you typed, project or package names, and nothing identifying
|
|
11
|
+
you or your machine.
|
|
12
|
+
`),c.gray(`Stored as \`stats: true|false\` in ${M} — edit it any time.\n\n`)].join(``));let e=S({input:process.stdin,output:process.stdout});try{return(await e.question(`Send anonymous usage stats? [y/N] `)).trim().toLowerCase()===`y`}finally{e.close()}},I=async(e=M)=>{let t=N(e).stats;if(typeof t==`boolean`)return t;if(process.env.CI===`true`||!process.stdin.isTTY||!process.stdout.isTTY)return;let n=await F();return P(e,n),n},L=async()=>{try{await fetch(j,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({tool:`skillslint`,options:[]}),signal:AbortSignal.timeout(2e3)})}catch{}},R=e=>{let{threshold:t,overall:n,structure:r,clarity:i,specificity:a,advanced:o}=e,s={};return n&&(s.overall=n),r&&(s.structure=r),i&&(s.clarity=i),a&&(s.specificity=a),o&&(s.advanced=o),Object.keys(s).length===0&&(s.overall=t??70),s},z=(e,t)=>e.overall<(t.overall??0)||e.structure<(t.structure??0)||e.clarity<(t.clarity??0)||e.specificity<(t.specificity??0)||e.advanced<(t.advanced??0),B=async e=>{let{fix:t=!1,path:n,ignored:i,stats:o}=e;o&&L();let s=`/${n??`./skills`}`,c=R(e),l=r(s),u=await E(r(`${s}/**/*.md`),t),d=y(l,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!(i??[]).includes(e.name)).map(({name:e})=>e),f=await Promise.all(d.map(async e=>{let{overall:t,structure:n,clarity:r,specificity:i,advanced:o}=await a(`${l}/${e}`),s={overall:t,structure:n,clarity:r,specificity:i,advanced:o};return{name:e,scores:s,passed:!z(s,c)}}));return{textlint:u,fixed:t,skills:f,passed:!D(u)&&f.every(e=>e.passed)}},V=i(`skillslint`);V.command(``,`Linter for agents skills`).option(`-p,--path <path>`,`Lint path`,{default:`./skills`}).option(`-t, --threshold <threshold>`,`Same as --overall 70, will take effect only if no other threshold options are configured`,{default:70}).option(`-f,--fix`,`Try to fix findings`).option(`-i,--ignored [ignored]`,`Ignored skills`).option(`--overall <threshold>`,`Overall required threshold`).option(`--structure <threshold>`,`Structure required threshold`).option(`--clarity <threshold>`,`Clarity required threshold`).option(`--specificity <threshold>`,`Specificity required threshold`).option(`--advanced <threshold>`,`Advanced required threshold`).action(async t=>{let n=await B({...t,stats:await I()??!1});process.stdout.write(await A(n)),process.exit(n.passed?e.OK:e.ERROR)}),V.help(),V.parse();
|
package/lib/index.cjs
CHANGED
|
@@ -1,142 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let agent_skills_cli = require("agent-skills-cli");
|
|
25
|
+
let picocolors = require("picocolors");
|
|
26
|
+
picocolors = __toESM(picocolors, 1);
|
|
27
|
+
let textlint = require("textlint");
|
|
28
|
+
let fs_promises = require("fs/promises");
|
|
29
|
+
let path = require("path");
|
|
30
|
+
let _ladamczyk_qoq_utils = require("@ladamczyk/qoq-utils");
|
|
31
|
+
let fs = require("fs");
|
|
32
|
+
let os = require("os");
|
|
33
|
+
//#region src/helpers/paths.ts
|
|
34
|
+
const PACKAGE_NAME = "@ladamczyk/skillslint";
|
|
12
35
|
const getCliPackagePath = () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return process.cwd();
|
|
20
|
-
}
|
|
36
|
+
try {
|
|
37
|
+
const { rootPath } = (0, _ladamczyk_qoq_utils.getPackageInfo)(PACKAGE_NAME) ?? {};
|
|
38
|
+
return rootPath;
|
|
39
|
+
} catch {
|
|
40
|
+
return process.cwd();
|
|
41
|
+
}
|
|
21
42
|
};
|
|
22
|
-
const resolveCliPackagePath = (path$1) => path.resolve(`${getCliPackagePath()}${path$1}`);
|
|
23
|
-
const resolveCliRelativePath = (path) =>
|
|
24
|
-
|
|
43
|
+
const resolveCliPackagePath = (path$1) => (0, path.resolve)(`${getCliPackagePath()}${path$1}`);
|
|
44
|
+
const resolveCliRelativePath = (path$2) => (0, _ladamczyk_qoq_utils.getRelativePath)(resolveCliPackagePath(path$2));
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/helpers/textlint.ts
|
|
25
47
|
const ERROR_SEVERITY = 2;
|
|
26
|
-
const NO_TARGET_FILES_ERROR =
|
|
48
|
+
const NO_TARGET_FILES_ERROR = "TextlintFileSearchError";
|
|
27
49
|
const runTextlint = async (target, fix) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return results;
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
// textlint throws when no markdown files match the glob; treat as nothing to lint.
|
|
43
|
-
if (error instanceof Error && error.name === NO_TARGET_FILES_ERROR) {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
throw error;
|
|
47
|
-
}
|
|
50
|
+
const descriptor = await (0, textlint.loadTextlintrc)({ configFilePath: resolveCliRelativePath("/.textlintrc.json") });
|
|
51
|
+
const linter = (0, textlint.createLinter)({ descriptor });
|
|
52
|
+
try {
|
|
53
|
+
if (!fix) return await linter.lintFiles([target]);
|
|
54
|
+
const results = await linter.fixFiles([target]);
|
|
55
|
+
await Promise.all(results.map((result) => (0, fs_promises.writeFile)(result.filePath, result.output, "utf-8")));
|
|
56
|
+
return results;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error instanceof Error && error.name === NO_TARGET_FILES_ERROR) return [];
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
48
61
|
};
|
|
49
|
-
const hasTextlintErrors = (results) => results.some((result) => (
|
|
50
|
-
|
|
62
|
+
const hasTextlintErrors = (results) => results.some((result) => ("remainingMessages" in result ? result.remainingMessages : result.messages).some((message) => message.severity === ERROR_SEVERITY));
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/format.ts
|
|
51
65
|
const BAR_WIDTH = 25;
|
|
52
|
-
const DIMENSIONS = [
|
|
66
|
+
const DIMENSIONS = [
|
|
67
|
+
"overall",
|
|
68
|
+
"structure",
|
|
69
|
+
"clarity",
|
|
70
|
+
"specificity",
|
|
71
|
+
"advanced"
|
|
72
|
+
];
|
|
53
73
|
const formatTextlint = async (textlint$1, fixed) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return formatter.format(textlint$1);
|
|
57
|
-
}
|
|
58
|
-
const formatter = await textlint.loadLinterFormatter({ formatterName: 'stylish' });
|
|
59
|
-
return formatter.format(textlint$1);
|
|
74
|
+
if (fixed) return (await (0, textlint.loadFixerFormatter)({ formatterName: "stylish" })).format(textlint$1);
|
|
75
|
+
return (await (0, textlint.loadLinterFormatter)({ formatterName: "stylish" })).format(textlint$1);
|
|
60
76
|
};
|
|
61
77
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
* Renders an {@link ILintResult} into a console-ready, colorized string
|
|
79
|
+
* (textlint findings, per-skill score bars and the summary verdict).
|
|
80
|
+
*/
|
|
65
81
|
const format = async (result) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
let output = "";
|
|
83
|
+
const textlint$2 = await formatTextlint(result.textlint, result.fixed);
|
|
84
|
+
if (textlint$2.trim()) output += `${textlint$2}\n`;
|
|
85
|
+
if (result.fixed && hasTextlintErrors(result.textlint)) output += picocolors.default.red("Can't perform automatic fix!\n\n");
|
|
86
|
+
result.skills.forEach(({ name, scores }) => {
|
|
87
|
+
output += picocolors.default.gray(`\n/${name}\n`);
|
|
88
|
+
DIMENSIONS.forEach((dimension) => {
|
|
89
|
+
const label = `${dimension[0]?.toUpperCase()}${dimension.slice(1)}:`.padEnd(13);
|
|
90
|
+
const color = picocolors.default[(0, agent_skills_cli.getScoreColor)(scores[dimension])];
|
|
91
|
+
output += color(`${label}${(0, agent_skills_cli.formatScoreBar)(scores[dimension], BAR_WIDTH)}\n`);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
if (result.skills.some((skill) => !skill.passed)) output += picocolors.default.red(`At least one skill doesn't meet required threshold!\n`);
|
|
95
|
+
if (result.passed) output += picocolors.default.green("\nAll good!\n");
|
|
96
|
+
return output;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/helpers/stats.ts
|
|
100
|
+
const STATS_URL = "https://stats.adamczyk.ovh";
|
|
101
|
+
const STATS_TIMEOUT_MS = 2e3;
|
|
102
|
+
(0, path.join)(process.env.XDG_CONFIG_HOME ?? (0, path.join)((0, os.homedir)(), ".config"), "skillslint.json");
|
|
103
|
+
const sendStats = async () => {
|
|
104
|
+
try {
|
|
105
|
+
await fetch(STATS_URL, {
|
|
106
|
+
method: "POST",
|
|
107
|
+
headers: { "content-type": "application/json" },
|
|
108
|
+
body: JSON.stringify({
|
|
109
|
+
tool: "skillslint",
|
|
110
|
+
options: []
|
|
111
|
+
}),
|
|
112
|
+
signal: AbortSignal.timeout(STATS_TIMEOUT_MS)
|
|
113
|
+
});
|
|
114
|
+
} catch {}
|
|
89
115
|
};
|
|
90
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/helpers/threshold.ts
|
|
91
118
|
const DEFAULT_THRESHOLD = 70;
|
|
92
119
|
const buildThreshold = (options) => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
threshold.clarity = clarity;
|
|
103
|
-
}
|
|
104
|
-
if (specificity) {
|
|
105
|
-
threshold.specificity = specificity;
|
|
106
|
-
}
|
|
107
|
-
if (advanced) {
|
|
108
|
-
threshold.advanced = advanced;
|
|
109
|
-
}
|
|
110
|
-
if (Object.keys(threshold).length === 0) {
|
|
111
|
-
threshold.overall = optionsThreshold ?? DEFAULT_THRESHOLD;
|
|
112
|
-
}
|
|
113
|
-
return threshold;
|
|
120
|
+
const { threshold: optionsThreshold, overall, structure, clarity, specificity, advanced } = options;
|
|
121
|
+
const threshold = {};
|
|
122
|
+
if (overall) threshold.overall = overall;
|
|
123
|
+
if (structure) threshold.structure = structure;
|
|
124
|
+
if (clarity) threshold.clarity = clarity;
|
|
125
|
+
if (specificity) threshold.specificity = specificity;
|
|
126
|
+
if (advanced) threshold.advanced = advanced;
|
|
127
|
+
if (Object.keys(threshold).length === 0) threshold.overall = optionsThreshold ?? 70;
|
|
128
|
+
return threshold;
|
|
114
129
|
};
|
|
115
|
-
const failsThreshold = (scores, threshold) => scores.overall < (threshold.overall ?? 0) ||
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
const failsThreshold = (scores, threshold) => scores.overall < (threshold.overall ?? 0) || scores.structure < (threshold.structure ?? 0) || scores.clarity < (threshold.clarity ?? 0) || scores.specificity < (threshold.specificity ?? 0) || scores.advanced < (threshold.advanced ?? 0);
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/lint.ts
|
|
133
|
+
const DEFAULT_PATH = "./skills";
|
|
134
|
+
const lint = async (options) => {
|
|
135
|
+
const { fix = false, path: optionsPath, ignored, stats } = options;
|
|
136
|
+
if (stats) sendStats();
|
|
137
|
+
const path = `/${optionsPath ?? "./skills"}`;
|
|
138
|
+
const threshold = buildThreshold(options);
|
|
139
|
+
const skillsPath = (0, _ladamczyk_qoq_utils.resolveCwdRelativePath)(path);
|
|
140
|
+
const textlint = await runTextlint((0, _ladamczyk_qoq_utils.resolveCwdRelativePath)(`${path}/**/*.md`), fix);
|
|
141
|
+
const skillNames = (0, fs.readdirSync)(skillsPath, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !(ignored ?? []).includes(entry.name)).map(({ name }) => name);
|
|
142
|
+
const skills = await Promise.all(skillNames.map(async (name) => {
|
|
143
|
+
const { overall, structure, clarity, specificity, advanced } = await (0, agent_skills_cli.assessQuality)(`${skillsPath}/${name}`);
|
|
144
|
+
const scores = {
|
|
145
|
+
overall,
|
|
146
|
+
structure,
|
|
147
|
+
clarity,
|
|
148
|
+
specificity,
|
|
149
|
+
advanced
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
name,
|
|
153
|
+
scores,
|
|
154
|
+
passed: !failsThreshold(scores, threshold)
|
|
155
|
+
};
|
|
156
|
+
}));
|
|
157
|
+
return {
|
|
158
|
+
textlint,
|
|
159
|
+
fixed: fix,
|
|
160
|
+
skills,
|
|
161
|
+
passed: !hasTextlintErrors(textlint) && skills.every((skill) => skill.passed)
|
|
162
|
+
};
|
|
138
163
|
};
|
|
139
|
-
|
|
164
|
+
//#endregion
|
|
140
165
|
exports.DEFAULT_PATH = DEFAULT_PATH;
|
|
141
166
|
exports.DEFAULT_THRESHOLD = DEFAULT_THRESHOLD;
|
|
142
167
|
exports.buildThreshold = buildThreshold;
|
package/lib/index.mjs
CHANGED
|
@@ -1,138 +1,142 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import c from
|
|
3
|
-
import {
|
|
4
|
-
import { writeFile } from
|
|
5
|
-
import { resolve } from
|
|
6
|
-
import {
|
|
7
|
-
import { readdirSync } from
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { assessQuality, formatScoreBar, getScoreColor } from "agent-skills-cli";
|
|
2
|
+
import c from "picocolors";
|
|
3
|
+
import { createLinter, loadFixerFormatter, loadLinterFormatter, loadTextlintrc } from "textlint";
|
|
4
|
+
import { writeFile } from "fs/promises";
|
|
5
|
+
import { join, resolve } from "path";
|
|
6
|
+
import { getPackageInfo, getRelativePath, resolveCwdRelativePath } from "@ladamczyk/qoq-utils";
|
|
7
|
+
import { readdirSync } from "fs";
|
|
8
|
+
import { homedir } from "os";
|
|
9
|
+
import "readline/promises";
|
|
10
|
+
//#region src/helpers/paths.ts
|
|
11
|
+
const PACKAGE_NAME = "@ladamczyk/skillslint";
|
|
10
12
|
const getCliPackagePath = () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return process.cwd();
|
|
18
|
-
}
|
|
13
|
+
try {
|
|
14
|
+
const { rootPath } = getPackageInfo(PACKAGE_NAME) ?? {};
|
|
15
|
+
return rootPath;
|
|
16
|
+
} catch {
|
|
17
|
+
return process.cwd();
|
|
18
|
+
}
|
|
19
19
|
};
|
|
20
20
|
const resolveCliPackagePath = (path) => resolve(`${getCliPackagePath()}${path}`);
|
|
21
21
|
const resolveCliRelativePath = (path) => getRelativePath(resolveCliPackagePath(path));
|
|
22
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/helpers/textlint.ts
|
|
23
24
|
const ERROR_SEVERITY = 2;
|
|
24
|
-
const NO_TARGET_FILES_ERROR =
|
|
25
|
+
const NO_TARGET_FILES_ERROR = "TextlintFileSearchError";
|
|
25
26
|
const runTextlint = async (target, fix) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return results;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
// textlint throws when no markdown files match the glob; treat as nothing to lint.
|
|
41
|
-
if (error instanceof Error && error.name === NO_TARGET_FILES_ERROR) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
27
|
+
const descriptor = await loadTextlintrc({ configFilePath: resolveCliRelativePath("/.textlintrc.json") });
|
|
28
|
+
const linter = createLinter({ descriptor });
|
|
29
|
+
try {
|
|
30
|
+
if (!fix) return await linter.lintFiles([target]);
|
|
31
|
+
const results = await linter.fixFiles([target]);
|
|
32
|
+
await Promise.all(results.map((result) => writeFile(result.filePath, result.output, "utf-8")));
|
|
33
|
+
return results;
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error instanceof Error && error.name === NO_TARGET_FILES_ERROR) return [];
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
46
38
|
};
|
|
47
|
-
const hasTextlintErrors = (results) => results.some((result) => (
|
|
48
|
-
|
|
39
|
+
const hasTextlintErrors = (results) => results.some((result) => ("remainingMessages" in result ? result.remainingMessages : result.messages).some((message) => message.severity === ERROR_SEVERITY));
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/format.ts
|
|
49
42
|
const BAR_WIDTH = 25;
|
|
50
|
-
const DIMENSIONS = [
|
|
43
|
+
const DIMENSIONS = [
|
|
44
|
+
"overall",
|
|
45
|
+
"structure",
|
|
46
|
+
"clarity",
|
|
47
|
+
"specificity",
|
|
48
|
+
"advanced"
|
|
49
|
+
];
|
|
51
50
|
const formatTextlint = async (textlint, fixed) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return formatter.format(textlint);
|
|
55
|
-
}
|
|
56
|
-
const formatter = await loadLinterFormatter({ formatterName: 'stylish' });
|
|
57
|
-
return formatter.format(textlint);
|
|
51
|
+
if (fixed) return (await loadFixerFormatter({ formatterName: "stylish" })).format(textlint);
|
|
52
|
+
return (await loadLinterFormatter({ formatterName: "stylish" })).format(textlint);
|
|
58
53
|
};
|
|
59
54
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
* Renders an {@link ILintResult} into a console-ready, colorized string
|
|
56
|
+
* (textlint findings, per-skill score bars and the summary verdict).
|
|
57
|
+
*/
|
|
63
58
|
const format = async (result) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
if (result.skills.some((skill) => !skill.passed)) {
|
|
81
|
-
output += c.red(`At least one skill doesn't meet required threshold!\n`);
|
|
82
|
-
}
|
|
83
|
-
if (result.passed) {
|
|
84
|
-
output += c.green('\nAll good!\n');
|
|
85
|
-
}
|
|
86
|
-
return output;
|
|
59
|
+
let output = "";
|
|
60
|
+
const textlint = await formatTextlint(result.textlint, result.fixed);
|
|
61
|
+
if (textlint.trim()) output += `${textlint}\n`;
|
|
62
|
+
if (result.fixed && hasTextlintErrors(result.textlint)) output += c.red("Can't perform automatic fix!\n\n");
|
|
63
|
+
result.skills.forEach(({ name, scores }) => {
|
|
64
|
+
output += c.gray(`\n/${name}\n`);
|
|
65
|
+
DIMENSIONS.forEach((dimension) => {
|
|
66
|
+
const label = `${dimension[0]?.toUpperCase()}${dimension.slice(1)}:`.padEnd(13);
|
|
67
|
+
const color = c[getScoreColor(scores[dimension])];
|
|
68
|
+
output += color(`${label}${formatScoreBar(scores[dimension], BAR_WIDTH)}\n`);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
if (result.skills.some((skill) => !skill.passed)) output += c.red(`At least one skill doesn't meet required threshold!\n`);
|
|
72
|
+
if (result.passed) output += c.green("\nAll good!\n");
|
|
73
|
+
return output;
|
|
87
74
|
};
|
|
88
|
-
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/helpers/stats.ts
|
|
77
|
+
const STATS_URL = "https://stats.adamczyk.ovh";
|
|
78
|
+
const STATS_TIMEOUT_MS = 2e3;
|
|
79
|
+
join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "skillslint.json");
|
|
80
|
+
const sendStats = async () => {
|
|
81
|
+
try {
|
|
82
|
+
await fetch(STATS_URL, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: { "content-type": "application/json" },
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
tool: "skillslint",
|
|
87
|
+
options: []
|
|
88
|
+
}),
|
|
89
|
+
signal: AbortSignal.timeout(STATS_TIMEOUT_MS)
|
|
90
|
+
});
|
|
91
|
+
} catch {}
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/helpers/threshold.ts
|
|
89
95
|
const DEFAULT_THRESHOLD = 70;
|
|
90
96
|
const buildThreshold = (options) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
threshold.clarity = clarity;
|
|
101
|
-
}
|
|
102
|
-
if (specificity) {
|
|
103
|
-
threshold.specificity = specificity;
|
|
104
|
-
}
|
|
105
|
-
if (advanced) {
|
|
106
|
-
threshold.advanced = advanced;
|
|
107
|
-
}
|
|
108
|
-
if (Object.keys(threshold).length === 0) {
|
|
109
|
-
threshold.overall = optionsThreshold ?? DEFAULT_THRESHOLD;
|
|
110
|
-
}
|
|
111
|
-
return threshold;
|
|
97
|
+
const { threshold: optionsThreshold, overall, structure, clarity, specificity, advanced } = options;
|
|
98
|
+
const threshold = {};
|
|
99
|
+
if (overall) threshold.overall = overall;
|
|
100
|
+
if (structure) threshold.structure = structure;
|
|
101
|
+
if (clarity) threshold.clarity = clarity;
|
|
102
|
+
if (specificity) threshold.specificity = specificity;
|
|
103
|
+
if (advanced) threshold.advanced = advanced;
|
|
104
|
+
if (Object.keys(threshold).length === 0) threshold.overall = optionsThreshold ?? 70;
|
|
105
|
+
return threshold;
|
|
112
106
|
};
|
|
113
|
-
const failsThreshold = (scores, threshold) => scores.overall < (threshold.overall ?? 0) ||
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
107
|
+
const failsThreshold = (scores, threshold) => scores.overall < (threshold.overall ?? 0) || scores.structure < (threshold.structure ?? 0) || scores.clarity < (threshold.clarity ?? 0) || scores.specificity < (threshold.specificity ?? 0) || scores.advanced < (threshold.advanced ?? 0);
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/lint.ts
|
|
110
|
+
const DEFAULT_PATH = "./skills";
|
|
111
|
+
const lint = async (options) => {
|
|
112
|
+
const { fix = false, path: optionsPath, ignored, stats } = options;
|
|
113
|
+
if (stats) sendStats();
|
|
114
|
+
const path = `/${optionsPath ?? "./skills"}`;
|
|
115
|
+
const threshold = buildThreshold(options);
|
|
116
|
+
const skillsPath = resolveCwdRelativePath(path);
|
|
117
|
+
const textlint = await runTextlint(resolveCwdRelativePath(`${path}/**/*.md`), fix);
|
|
118
|
+
const skillNames = readdirSync(skillsPath, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !(ignored ?? []).includes(entry.name)).map(({ name }) => name);
|
|
119
|
+
const skills = await Promise.all(skillNames.map(async (name) => {
|
|
120
|
+
const { overall, structure, clarity, specificity, advanced } = await assessQuality(`${skillsPath}/${name}`);
|
|
121
|
+
const scores = {
|
|
122
|
+
overall,
|
|
123
|
+
structure,
|
|
124
|
+
clarity,
|
|
125
|
+
specificity,
|
|
126
|
+
advanced
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
name,
|
|
130
|
+
scores,
|
|
131
|
+
passed: !failsThreshold(scores, threshold)
|
|
132
|
+
};
|
|
133
|
+
}));
|
|
134
|
+
return {
|
|
135
|
+
textlint,
|
|
136
|
+
fixed: fix,
|
|
137
|
+
skills,
|
|
138
|
+
passed: !hasTextlintErrors(textlint) && skills.every((skill) => skill.passed)
|
|
139
|
+
};
|
|
136
140
|
};
|
|
137
|
-
|
|
141
|
+
//#endregion
|
|
138
142
|
export { DEFAULT_PATH, DEFAULT_THRESHOLD, buildThreshold, failsThreshold, format, hasTextlintErrors, lint, runTextlint };
|
package/lib/src/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ILintOptions, IScores, IThreshold } from '../types.ts';
|
|
2
2
|
export declare const DEFAULT_THRESHOLD = 70;
|
|
3
|
-
export declare const buildThreshold: (options: ILintOptions) => IThreshold;
|
|
3
|
+
export declare const buildThreshold: (options: IThreshold & Pick<ILintOptions, "threshold">) => IThreshold;
|
|
4
4
|
export declare const failsThreshold: (scores: IScores, threshold: IThreshold) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/src/lint.d.ts
CHANGED
package/lib/src/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ladamczyk/skillslint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Linter for agents skills",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"AGENTS.md"
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
|
-
"build": "rimraf ./bin ./lib &&
|
|
42
|
+
"build": "rimraf ./bin ./lib && rolldown -c && tsc --emitDeclarationOnly && chmod +x ./bin/cli.js",
|
|
43
43
|
"dev": "npm run build && node ./bin/cli.js",
|
|
44
44
|
"husky:pre-push": "run-s qoq:check test build",
|
|
45
45
|
"prepare": "husky",
|
|
@@ -52,39 +52,32 @@
|
|
|
52
52
|
"test:coverage": "npm run test -- --coverage"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@ladamczyk/qoq-utils": "
|
|
56
|
-
"@textlint/textlint-plugin-markdown": "15.
|
|
57
|
-
"@textlint/textlint-plugin-text": "15.
|
|
55
|
+
"@ladamczyk/qoq-utils": "6.0.0",
|
|
56
|
+
"@textlint/textlint-plugin-markdown": "15.8.0",
|
|
57
|
+
"@textlint/textlint-plugin-text": "15.8.0",
|
|
58
58
|
"agent-skills-cli": "1.1.9",
|
|
59
59
|
"cac": "7.0.0",
|
|
60
60
|
"picocolors": "1.1.1",
|
|
61
|
-
"textlint": "15.
|
|
61
|
+
"textlint": "15.8.0",
|
|
62
62
|
"textlint-rule-common-misspellings": "1.0.1",
|
|
63
63
|
"textlint-rule-terminology": "5.2.16",
|
|
64
64
|
"textlint-rule-write-good": "2.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@commitlint/cli": "21.2.
|
|
68
|
-
"@commitlint/config-conventional": "21.2.
|
|
69
|
-
"@ladamczyk/qoq-cli": "
|
|
70
|
-
"@ladamczyk/qoq-eslint-v9-ts": "
|
|
71
|
-
"@ladamczyk/qoq-jscpd": "
|
|
72
|
-
"@ladamczyk/qoq-knip": "
|
|
73
|
-
"@ladamczyk/qoq-prettier-with-json-sort": "
|
|
74
|
-
"@rollup/plugin-commonjs": "29.0.3",
|
|
75
|
-
"@rollup/plugin-json": "6.1.0",
|
|
76
|
-
"@rollup/plugin-node-resolve": "16.0.3",
|
|
77
|
-
"@rollup/plugin-terser": "1.0.0",
|
|
78
|
-
"@rollup/plugin-typescript": "12.3.0",
|
|
67
|
+
"@commitlint/cli": "21.2.2",
|
|
68
|
+
"@commitlint/config-conventional": "21.2.2",
|
|
69
|
+
"@ladamczyk/qoq-cli": "6.0.0",
|
|
70
|
+
"@ladamczyk/qoq-eslint-v9-ts": "6.0.0",
|
|
71
|
+
"@ladamczyk/qoq-jscpd": "6.0.0",
|
|
72
|
+
"@ladamczyk/qoq-knip": "6.0.0",
|
|
73
|
+
"@ladamczyk/qoq-prettier-with-json-sort": "6.0.0",
|
|
79
74
|
"@types/node": "^22",
|
|
80
75
|
"@vitest/coverage-v8": "4.1.10",
|
|
81
76
|
"dotenv": "17.4.2",
|
|
82
|
-
"esbuild": "0.28.1",
|
|
83
77
|
"husky": "9.1.7",
|
|
84
78
|
"npm-run-all": "4.1.5",
|
|
85
79
|
"rimraf": "6.1.3",
|
|
86
|
-
"
|
|
87
|
-
"rollup-plugin-esbuild": "6.2.1",
|
|
80
|
+
"rolldown": "1.2.4",
|
|
88
81
|
"typescript": "6.0.3",
|
|
89
82
|
"vitest": "4.1.10"
|
|
90
83
|
},
|