@maniumek/suwgate 0.16.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.
Files changed (76) hide show
  1. package/AGENTS.shared.md +13 -2
  2. package/README.md +95 -9
  3. package/dist/cli.js +208 -12
  4. package/dist/gate/breakdown.d.ts +38 -0
  5. package/dist/gate/breakdown.js +107 -0
  6. package/dist/gate/check.d.ts +3 -0
  7. package/dist/gate/check.js +37 -1
  8. package/dist/gate/config.d.ts +5 -1
  9. package/dist/gate/config.js +56 -2
  10. package/dist/gate/context.d.ts +15 -0
  11. package/dist/gate/context.js +97 -0
  12. package/dist/gate/contract.d.ts +7 -0
  13. package/dist/gate/contract.js +1 -0
  14. package/dist/gate/dashboard.d.ts +107 -0
  15. package/dist/gate/dashboard.js +126 -0
  16. package/dist/gate/dashboardFile.d.ts +31 -0
  17. package/dist/gate/dashboardFile.js +154 -0
  18. package/dist/gate/dashboardJson.d.ts +2 -0
  19. package/dist/gate/dashboardJson.js +25 -0
  20. package/dist/gate/dashboardPage.d.ts +3 -0
  21. package/dist/gate/dashboardPage.js +294 -0
  22. package/dist/gate/dashboardServer.d.ts +11 -0
  23. package/dist/gate/dashboardServer.js +70 -0
  24. package/dist/gate/dashboardTesting.d.ts +12 -0
  25. package/dist/gate/dashboardTesting.js +98 -0
  26. package/dist/gate/guardsStep.d.ts +6 -0
  27. package/dist/gate/guardsStep.js +8 -1
  28. package/dist/gate/history.d.ts +28 -0
  29. package/dist/gate/history.js +72 -0
  30. package/dist/gate/plan.d.ts +3 -1
  31. package/dist/gate/plan.js +6 -3
  32. package/dist/gate/repository.d.ts +1 -0
  33. package/dist/gate/repository.js +1 -1
  34. package/dist/gate/runner.d.ts +3 -0
  35. package/dist/gate/runner.js +4 -1
  36. package/dist/gate/stats.d.ts +27 -0
  37. package/dist/gate/stats.js +84 -0
  38. package/dist/guards/comments/eslint.js +1 -0
  39. package/dist/guards/comments/scan.js +1 -0
  40. package/dist/guards/comments/switches.js +1 -0
  41. package/dist/guards/database/connectionHost.js +1 -0
  42. package/dist/guards/dotnet/appsettingsBound.js +1 -0
  43. package/dist/guards/dotnet/bannedNugetPackages.js +1 -0
  44. package/dist/guards/dotnet/openApiVersions.js +1 -0
  45. package/dist/guards/dotnet/suwbackkitWiring.js +1 -0
  46. package/dist/guards/dotnet/unusedNugetVersions.js +1 -0
  47. package/dist/guards/repository/bannedNpmPackages.js +1 -0
  48. package/dist/guards/repository/composePorts.js +1 -0
  49. package/dist/guards/repository/dependencyDirection.js +1 -0
  50. package/dist/guards/repository/forbiddenNames.js +1 -0
  51. package/dist/guards/repository/humanDocs.js +1 -0
  52. package/dist/guards/repository/imagePins.js +1 -0
  53. package/dist/guards/repository/justModules.js +1 -0
  54. package/dist/guards/repository/noRawColors.js +1 -0
  55. package/dist/guards/repository/repositoryLayout.js +1 -0
  56. package/dist/guards/repository/scriptsCalled.js +1 -0
  57. package/dist/guards/repository/scriptsHelp.js +1 -0
  58. package/dist/guards/repository/suwfrontkitWiring.js +1 -0
  59. package/dist/guards/repository/vsCodeSettings.js +1 -0
  60. package/dist/profiles/holdout.d.ts +2 -0
  61. package/dist/profiles/holdout.js +38 -0
  62. package/dist/profiles/index.d.ts +1 -0
  63. package/dist/profiles/index.js +1 -0
  64. package/dist/profiles/reports.d.ts +6 -0
  65. package/dist/profiles/reports.js +14 -0
  66. package/dist/profiles/verdict.js +41 -2
  67. package/dist/session/doctor.d.ts +26 -0
  68. package/dist/session/doctor.js +265 -0
  69. package/dist/session/gardenRecord.d.ts +12 -0
  70. package/dist/session/gardenRecord.js +58 -0
  71. package/dist/session/guardPr.js +2 -2
  72. package/dist/session/prePush.js +1 -1
  73. package/dist/session/suwagentInfo.d.ts +28 -0
  74. package/dist/session/suwagentInfo.js +103 -0
  75. package/package.json +1 -1
  76. package/schema/suwgate.schema.json +26 -0
@@ -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.16.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",
@@ -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",