@maniumek/suwgate 0.15.0 → 0.17.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.shared.md +13 -2
- package/README.md +95 -9
- package/dist/cli.js +208 -12
- package/dist/eslint/index.d.ts +1 -0
- package/dist/eslint/index.js +20 -1
- package/dist/gate/breakdown.d.ts +38 -0
- package/dist/gate/breakdown.js +107 -0
- package/dist/gate/check.d.ts +3 -0
- package/dist/gate/check.js +37 -1
- package/dist/gate/config.d.ts +5 -1
- package/dist/gate/config.js +56 -2
- package/dist/gate/context.d.ts +15 -0
- package/dist/gate/context.js +97 -0
- package/dist/gate/contract.d.ts +7 -0
- package/dist/gate/contract.js +1 -0
- package/dist/gate/dashboard.d.ts +107 -0
- package/dist/gate/dashboard.js +126 -0
- package/dist/gate/dashboardFile.d.ts +31 -0
- package/dist/gate/dashboardFile.js +154 -0
- package/dist/gate/dashboardJson.d.ts +2 -0
- package/dist/gate/dashboardJson.js +25 -0
- package/dist/gate/dashboardPage.d.ts +3 -0
- package/dist/gate/dashboardPage.js +294 -0
- package/dist/gate/dashboardServer.d.ts +11 -0
- package/dist/gate/dashboardServer.js +70 -0
- package/dist/gate/dashboardTesting.d.ts +12 -0
- package/dist/gate/dashboardTesting.js +98 -0
- package/dist/gate/guardsStep.d.ts +6 -0
- package/dist/gate/guardsStep.js +8 -1
- package/dist/gate/history.d.ts +28 -0
- package/dist/gate/history.js +72 -0
- package/dist/gate/plan.d.ts +3 -1
- package/dist/gate/plan.js +6 -3
- package/dist/gate/repository.d.ts +1 -0
- package/dist/gate/repository.js +1 -1
- package/dist/gate/runner.d.ts +3 -0
- package/dist/gate/runner.js +4 -1
- package/dist/gate/stats.d.ts +27 -0
- package/dist/gate/stats.js +84 -0
- package/dist/guards/comments/eslint.js +1 -0
- package/dist/guards/comments/scan.js +1 -0
- package/dist/guards/comments/switches.js +1 -0
- package/dist/guards/database/connectionHost.js +1 -0
- package/dist/guards/dotnet/appsettingsBound.js +1 -0
- package/dist/guards/dotnet/bannedNugetPackages.js +1 -0
- package/dist/guards/dotnet/openApiVersions.js +1 -0
- package/dist/guards/dotnet/suwbackkitWiring.js +1 -0
- package/dist/guards/dotnet/unusedNugetVersions.js +1 -0
- package/dist/guards/repository/bannedNpmPackages.js +1 -0
- package/dist/guards/repository/composePorts.js +1 -0
- package/dist/guards/repository/dependencyDirection.js +1 -0
- package/dist/guards/repository/forbiddenNames.js +1 -0
- package/dist/guards/repository/humanDocs.js +1 -0
- package/dist/guards/repository/imagePins.js +1 -0
- package/dist/guards/repository/justModules.js +1 -0
- package/dist/guards/repository/noRawColors.js +1 -0
- package/dist/guards/repository/repositoryLayout.js +1 -0
- package/dist/guards/repository/scriptsCalled.js +1 -0
- package/dist/guards/repository/scriptsHelp.js +1 -0
- package/dist/guards/repository/suwfrontkitWiring.js +1 -0
- package/dist/guards/repository/vsCodeSettings.js +1 -0
- package/dist/profiles/holdout.d.ts +2 -0
- package/dist/profiles/holdout.js +38 -0
- package/dist/profiles/index.d.ts +1 -0
- package/dist/profiles/index.js +1 -0
- package/dist/profiles/node.d.ts +1 -0
- package/dist/profiles/node.js +12 -4
- package/dist/profiles/reports.d.ts +6 -0
- package/dist/profiles/reports.js +14 -0
- package/dist/profiles/verdict.js +45 -3
- package/dist/session/doctor.d.ts +26 -0
- package/dist/session/doctor.js +265 -0
- package/dist/session/gardenRecord.d.ts +12 -0
- package/dist/session/gardenRecord.js +58 -0
- package/dist/session/guardPr.js +2 -2
- package/dist/session/prePush.js +1 -1
- package/dist/session/suwagentInfo.d.ts +28 -0
- package/dist/session/suwagentInfo.js +103 -0
- package/package.json +3 -1
- package/schema/suwgate.schema.json +26 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { appendFileSync, readFileSync } from "node:fs";
|
|
2
|
+
const KIND = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
3
|
+
const COUNT = /^\d{1,9}$/;
|
|
4
|
+
export function parseFound(args) {
|
|
5
|
+
if (args.length === 0) {
|
|
6
|
+
return { problem: "suwgate garden-ran takes <kind>=<count> pairs, e.g. suwgate garden-ran docs=3 guards=2" };
|
|
7
|
+
}
|
|
8
|
+
const found = {};
|
|
9
|
+
for (const arg of args) {
|
|
10
|
+
const [kind = "", count = "", ...extra] = arg.split("=");
|
|
11
|
+
if (!KIND.test(kind) || !COUNT.test(count) || extra.length > 0) {
|
|
12
|
+
return {
|
|
13
|
+
problem: `suwgate garden-ran: '${arg}' is not <kind>=<count>: a kind is a kebab-case word (docs, gate-config) and a count a whole number from 0, e.g. docs=3`,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (kind in found)
|
|
17
|
+
return { problem: `suwgate garden-ran: the kind '${kind}' is given twice: give each kind once` };
|
|
18
|
+
found[kind] = Number(count);
|
|
19
|
+
}
|
|
20
|
+
return { found };
|
|
21
|
+
}
|
|
22
|
+
export function recordGarden(file, trace) {
|
|
23
|
+
appendFileSync(file, `${JSON.stringify(trace)}\n`);
|
|
24
|
+
}
|
|
25
|
+
function asTrace(value) {
|
|
26
|
+
if (typeof value !== "object" || value === null)
|
|
27
|
+
return null;
|
|
28
|
+
const { at, branch, found } = value;
|
|
29
|
+
if (typeof at !== "string" || Number.isNaN(Date.parse(at)) || typeof branch !== "string")
|
|
30
|
+
return null;
|
|
31
|
+
if (typeof found !== "object" || found === null || Array.isArray(found))
|
|
32
|
+
return null;
|
|
33
|
+
const counts = Object.entries(found);
|
|
34
|
+
if (!counts.every(([kind, count]) => KIND.test(kind) && Number.isInteger(count) && count >= 0))
|
|
35
|
+
return null;
|
|
36
|
+
return { at, branch, found: Object.fromEntries(counts) };
|
|
37
|
+
}
|
|
38
|
+
export function lastGarden(file) {
|
|
39
|
+
if (file === null)
|
|
40
|
+
return null;
|
|
41
|
+
let text;
|
|
42
|
+
try {
|
|
43
|
+
text = readFileSync(file, "utf8");
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const traces = text.split("\n").flatMap((line) => {
|
|
49
|
+
try {
|
|
50
|
+
const trace = asTrace(JSON.parse(line));
|
|
51
|
+
return trace === null ? [] : [trace];
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return traces.at(-1) ?? null;
|
|
58
|
+
}
|
package/dist/session/guardPr.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { hasShipRecord, treeOf } from "./shipRecord.js";
|
|
4
4
|
const BUILT_IN = ["gh pr create"];
|
|
5
5
|
const SKIPPED_HOOKS = /(?<![\w-])git\s+(?:\S+\s+)*?(?:push|commit)\b[^;&|]*\s--no-verify(?![\w-])/;
|
|
6
|
-
const NO_RECORD = "No ship record for this commit: run /
|
|
6
|
+
const NO_RECORD = "No ship record for this commit: run /suwgate:ship first; it simplifies, checks the changed tests, then pushes and opens the pull request.";
|
|
7
7
|
function callOf(input, root) {
|
|
8
8
|
try {
|
|
9
9
|
const parsed = JSON.parse(input);
|
|
@@ -29,7 +29,7 @@ function pattern(words) {
|
|
|
29
29
|
.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
30
30
|
return new RegExp(`(?<![\\w-])${escaped.join("\\s+")}(?![\\w-])`);
|
|
31
31
|
}
|
|
32
|
-
const SKIPPING = "An agent never skips git hooks: drop --no-verify. A push needs a ship record: run /
|
|
32
|
+
const SKIPPING = "An agent never skips git hooks: drop --no-verify. A push needs a ship record: run /suwgate:ship, which pushes for you.";
|
|
33
33
|
export function guardPr(input, root, prCommands) {
|
|
34
34
|
const call = callOf(input, root);
|
|
35
35
|
if (SKIPPED_HOOKS.test(call.command))
|
package/dist/session/prePush.js
CHANGED
|
@@ -7,7 +7,7 @@ export function prePush(input, root) {
|
|
|
7
7
|
if (localRef === undefined || localSha === undefined || !localRef.startsWith("refs/heads/") || NO_COMMIT.test(localSha))
|
|
8
8
|
continue;
|
|
9
9
|
if (!hasShipRecord(root, treeOf(root, localSha))) {
|
|
10
|
-
refused.push(`pre-push: ${localRef} has no ship record for its tree: run /
|
|
10
|
+
refused.push(`pre-push: ${localRef} has no ship record for its tree: run /suwgate:ship (an agent) or \`suwgate ship\`, then push again; push refused`);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
return { exitCode: refused.length === 0 ? 0 : 1, message: refused.join("\n") };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface SuwagentSkill {
|
|
2
|
+
name: string;
|
|
3
|
+
summary: string;
|
|
4
|
+
onlyWhenAsked: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface SuwagentHook {
|
|
7
|
+
event: string;
|
|
8
|
+
matcher: string;
|
|
9
|
+
script: string;
|
|
10
|
+
}
|
|
11
|
+
interface SuwagentAgent {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
tools: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SuwagentInfo {
|
|
17
|
+
version: string;
|
|
18
|
+
skills: SuwagentSkill[];
|
|
19
|
+
hookDescription: string;
|
|
20
|
+
hooks: SuwagentHook[];
|
|
21
|
+
agents: SuwagentAgent[];
|
|
22
|
+
}
|
|
23
|
+
export interface PluginFiles {
|
|
24
|
+
read: (file: string) => string | null;
|
|
25
|
+
list: (folder: string) => string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function findSuwagent(configDir: string, root: string, files: PluginFiles): SuwagentInfo | null;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
const PLUGIN_PREFIX = "suwagent@";
|
|
3
|
+
const ONLY_ON_REQUEST = /only when the user (?:explicitly )?asks|never on your own initiative/i;
|
|
4
|
+
function record(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
6
|
+
}
|
|
7
|
+
function text(value) {
|
|
8
|
+
return typeof value === "string" ? value : "";
|
|
9
|
+
}
|
|
10
|
+
function parseJson(source) {
|
|
11
|
+
if (source === null)
|
|
12
|
+
return null;
|
|
13
|
+
try {
|
|
14
|
+
return record(JSON.parse(source));
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function frontmatter(source) {
|
|
21
|
+
const block = /^---\r?\n([\s\S]*?)\r?\n---/.exec(source ?? "")?.[1];
|
|
22
|
+
if (block === undefined)
|
|
23
|
+
return {};
|
|
24
|
+
const fields = {};
|
|
25
|
+
let key = "";
|
|
26
|
+
for (const line of block.split(/\r?\n/)) {
|
|
27
|
+
const start = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
|
|
28
|
+
if (start !== null) {
|
|
29
|
+
key = start[1] ?? "";
|
|
30
|
+
fields[key] = (start[2] ?? "").replace(/^(["'])(.*)\1$/, "$2");
|
|
31
|
+
}
|
|
32
|
+
else if (key !== "" && /^\s+\S/.test(line)) {
|
|
33
|
+
fields[key] = `${fields[key] ?? ""} ${line.trim()}`.trim();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return fields;
|
|
37
|
+
}
|
|
38
|
+
function firstSentence(description) {
|
|
39
|
+
return /^(.+?[.!?])(?:\s|$)/s.exec(description)?.[1] ?? description;
|
|
40
|
+
}
|
|
41
|
+
function installedEntry(configDir, root, files) {
|
|
42
|
+
const plugins = record(parseJson(files.read(path.join(configDir, "plugins", "installed_plugins.json")))?.["plugins"]);
|
|
43
|
+
if (plugins === null)
|
|
44
|
+
return null;
|
|
45
|
+
const entries = Object.entries(plugins)
|
|
46
|
+
.filter(([key]) => key.startsWith(PLUGIN_PREFIX))
|
|
47
|
+
.flatMap(([, list]) => (Array.isArray(list) ? list : []))
|
|
48
|
+
.flatMap((entry) => {
|
|
49
|
+
const own = record(entry);
|
|
50
|
+
return own === null ? [] : [own];
|
|
51
|
+
});
|
|
52
|
+
const here = entries.find((entry) => text(entry["projectPath"]) !== "" && path.resolve(text(entry["projectPath"])) === path.resolve(root));
|
|
53
|
+
const chosen = here ?? entries.find((entry) => entry["scope"] === "user");
|
|
54
|
+
if (chosen === undefined || text(chosen["installPath"]) === "")
|
|
55
|
+
return null;
|
|
56
|
+
return { installPath: text(chosen["installPath"]), version: text(chosen["version"]) || "unknown" };
|
|
57
|
+
}
|
|
58
|
+
function hooksOf(source) {
|
|
59
|
+
return Object.entries(record(source?.["hooks"]) ?? {}).flatMap(([event, groups]) => (Array.isArray(groups) ? groups : []).flatMap((group) => {
|
|
60
|
+
const own = record(group);
|
|
61
|
+
return (Array.isArray(own?.["hooks"]) ? own["hooks"] : []).flatMap((hook) => {
|
|
62
|
+
const command = record(hook);
|
|
63
|
+
if (command === null)
|
|
64
|
+
return [];
|
|
65
|
+
const args = Array.isArray(command["args"]) ? command["args"].map(text) : [];
|
|
66
|
+
const script = path.basename(args.at(-1) ?? text(command["command"]));
|
|
67
|
+
return [{ event, matcher: text(own?.["matcher"]) || "any", script }];
|
|
68
|
+
});
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
export function findSuwagent(configDir, root, files) {
|
|
72
|
+
const entry = installedEntry(configDir, root, files);
|
|
73
|
+
if (entry === null)
|
|
74
|
+
return null;
|
|
75
|
+
const inside = (...parts) => path.join(entry.installPath, ...parts);
|
|
76
|
+
const skills = files
|
|
77
|
+
.list(inside("skills"))
|
|
78
|
+
.toSorted()
|
|
79
|
+
.flatMap((folder) => {
|
|
80
|
+
const source = files.read(inside("skills", folder, "SKILL.md"));
|
|
81
|
+
if (source === null)
|
|
82
|
+
return [];
|
|
83
|
+
const fields = frontmatter(source);
|
|
84
|
+
const description = fields["description"] ?? "";
|
|
85
|
+
return [
|
|
86
|
+
{ name: fields["name"] ?? folder, summary: firstSentence(description), onlyWhenAsked: ONLY_ON_REQUEST.test(description) },
|
|
87
|
+
];
|
|
88
|
+
});
|
|
89
|
+
const agents = files
|
|
90
|
+
.list(inside("agents"))
|
|
91
|
+
.filter((file) => file.endsWith(".md"))
|
|
92
|
+
.toSorted()
|
|
93
|
+
.map((file) => {
|
|
94
|
+
const fields = frontmatter(files.read(inside("agents", file)));
|
|
95
|
+
return {
|
|
96
|
+
name: fields["name"] ?? file.replace(/\.md$/, ""),
|
|
97
|
+
description: fields["description"] ?? "",
|
|
98
|
+
tools: fields["tools"] ?? "",
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
const hookFile = parseJson(files.read(inside("hooks", "hooks.json")));
|
|
102
|
+
return { version: entry.version, skills, hookDescription: text(hookFile?.["description"]), hooks: hooksOf(hookFile), agents };
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maniumek/suwgate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "One quality gate for every repository: suwgate check runs the steps of the repository's profiles and its guards, configured in suwgate.yml",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Manomenu",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"ajv": "8.20.0",
|
|
51
|
+
"eslint-plugin-better-tailwindcss": "4.11.0",
|
|
51
52
|
"yaml": "2.9.1"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
@@ -85,6 +86,7 @@
|
|
|
85
86
|
"knip": "^6.46.1",
|
|
86
87
|
"prettier": "^3.10.1",
|
|
87
88
|
"publint": "0.3.25",
|
|
89
|
+
"tailwindcss": "^4.3.5",
|
|
88
90
|
"typescript": "6.0.3",
|
|
89
91
|
"typescript-eslint": "^8.73.0",
|
|
90
92
|
"vitest": "5.1.1"
|
|
@@ -23,6 +23,32 @@
|
|
|
23
23
|
"^": { "$ref": "#/$defs/relativePath" }
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"guardSets": {
|
|
27
|
+
"description": "The sets of guards this repository takes; the guards of no set always run. Absent: every set. []: only the guards of no set. Known sets: stack (the owner's stack rules: libraries, naming, layout, style, the kits).",
|
|
28
|
+
"type": "array",
|
|
29
|
+
"uniqueItems": true,
|
|
30
|
+
"items": { "$ref": "#/$defs/id" }
|
|
31
|
+
},
|
|
32
|
+
"holdout": {
|
|
33
|
+
"description": "Holdout scenarios: end-to-end tests kept outside this repository, run only in CI (the step holdout, never in the quick gate or ship). CI checks them out and names the directory in SUWGATE_HOLDOUT; without it the step is skipped, which fails in CI. The command runs there with $SUWGATE_HOLDOUT and must write a JUnit XML report to $SUWGATE_HOLDOUT_REPORT. The gate shows only the names of the failed scenarios, never the command's output.",
|
|
34
|
+
"type": "object",
|
|
35
|
+
"additionalProperties": false,
|
|
36
|
+
"required": ["run"],
|
|
37
|
+
"properties": {
|
|
38
|
+
"run": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"minLength": 1,
|
|
41
|
+
"description": "A bash command, run in the repository root, that runs the scenarios in $SUWGATE_HOLDOUT and writes a JUnit XML report to $SUWGATE_HOLDOUT_REPORT."
|
|
42
|
+
},
|
|
43
|
+
"after": {
|
|
44
|
+
"type": "array",
|
|
45
|
+
"uniqueItems": true,
|
|
46
|
+
"items": { "$ref": "#/$defs/id" },
|
|
47
|
+
"description": "Steps that must finish first (e.g. the build the scenarios run against)."
|
|
48
|
+
},
|
|
49
|
+
"limitSeconds": { "type": "integer", "minimum": 1, "description": "The step is killed above this (default 600)." }
|
|
50
|
+
}
|
|
51
|
+
},
|
|
26
52
|
"quick": {
|
|
27
53
|
"description": "The quick gate (suwgate check --quick).",
|
|
28
54
|
"type": "object",
|