@maniumek/suwgate 0.0.0-stage → 0.1.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 (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +149 -2
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +97 -0
  5. package/dist/dev/checkoutEnv.d.ts +20 -0
  6. package/dist/dev/checkoutEnv.js +101 -0
  7. package/dist/dev/db.d.ts +25 -0
  8. package/dist/dev/db.js +103 -0
  9. package/dist/dev/index.d.ts +16 -0
  10. package/dist/dev/index.js +108 -0
  11. package/dist/dev/logs.d.ts +15 -0
  12. package/dist/dev/logs.js +127 -0
  13. package/dist/dev/process.d.ts +24 -0
  14. package/dist/dev/process.js +34 -0
  15. package/dist/dev/server.d.ts +8 -0
  16. package/dist/dev/server.js +61 -0
  17. package/dist/dev/settings.d.ts +46 -0
  18. package/dist/dev/settings.js +160 -0
  19. package/dist/dev/smoke.d.ts +15 -0
  20. package/dist/dev/smoke.js +50 -0
  21. package/dist/dev/testing.d.ts +19 -0
  22. package/dist/dev/testing.js +18 -0
  23. package/dist/dev/tmux.d.ts +24 -0
  24. package/dist/dev/tmux.js +121 -0
  25. package/dist/eslint/index.d.ts +17 -0
  26. package/dist/eslint/index.js +91 -0
  27. package/dist/eslint/noComments.d.ts +2 -0
  28. package/dist/eslint/noComments.js +27 -0
  29. package/dist/gate/check.d.ts +13 -0
  30. package/dist/gate/check.js +49 -0
  31. package/dist/gate/config.d.ts +34 -0
  32. package/dist/gate/config.js +170 -0
  33. package/dist/gate/contract.d.ts +51 -0
  34. package/dist/gate/contract.js +1 -0
  35. package/dist/gate/guardsStep.d.ts +14 -0
  36. package/dist/gate/guardsStep.js +53 -0
  37. package/dist/gate/plan.d.ts +29 -0
  38. package/dist/gate/plan.js +86 -0
  39. package/dist/gate/report.d.ts +15 -0
  40. package/dist/gate/report.js +65 -0
  41. package/dist/gate/repository.d.ts +3 -0
  42. package/dist/gate/repository.js +37 -0
  43. package/dist/gate/runner.d.ts +10 -0
  44. package/dist/gate/runner.js +75 -0
  45. package/dist/guards/comments/csharp.d.ts +3 -0
  46. package/dist/guards/comments/csharp.js +163 -0
  47. package/dist/guards/comments/css.d.ts +3 -0
  48. package/dist/guards/comments/css.js +11 -0
  49. package/dist/guards/comments/eslint.d.ts +2 -0
  50. package/dist/guards/comments/eslint.js +81 -0
  51. package/dist/guards/comments/hash.d.ts +3 -0
  52. package/dist/guards/comments/hash.js +72 -0
  53. package/dist/guards/comments/index.d.ts +2 -0
  54. package/dist/guards/comments/index.js +18 -0
  55. package/dist/guards/comments/json.d.ts +3 -0
  56. package/dist/guards/comments/json.js +13 -0
  57. package/dist/guards/comments/markup.d.ts +3 -0
  58. package/dist/guards/comments/markup.js +14 -0
  59. package/dist/guards/comments/scan.d.ts +19 -0
  60. package/dist/guards/comments/scan.js +84 -0
  61. package/dist/guards/comments/sql.d.ts +3 -0
  62. package/dist/guards/comments/sql.js +11 -0
  63. package/dist/guards/comments/switches.d.ts +3 -0
  64. package/dist/guards/comments/switches.js +30 -0
  65. package/dist/guards/criteria/criteriaKinds.d.ts +2 -0
  66. package/dist/guards/criteria/criteriaKinds.js +45 -0
  67. package/dist/guards/criteria/index.d.ts +2 -0
  68. package/dist/guards/criteria/index.js +2 -0
  69. package/dist/guards/database/connectionHost.d.ts +2 -0
  70. package/dist/guards/database/connectionHost.js +30 -0
  71. package/dist/guards/database/index.d.ts +2 -0
  72. package/dist/guards/database/index.js +3 -0
  73. package/dist/guards/database/migrationsUnchanged.d.ts +2 -0
  74. package/dist/guards/database/migrationsUnchanged.js +56 -0
  75. package/dist/guards/dotnet/appsettingsBound.d.ts +2 -0
  76. package/dist/guards/dotnet/appsettingsBound.js +43 -0
  77. package/dist/guards/dotnet/bannedNugetPackages.d.ts +2 -0
  78. package/dist/guards/dotnet/bannedNugetPackages.js +51 -0
  79. package/dist/guards/dotnet/index.d.ts +2 -0
  80. package/dist/guards/dotnet/index.js +4 -0
  81. package/dist/guards/dotnet/msbuild.d.ts +5 -0
  82. package/dist/guards/dotnet/msbuild.js +17 -0
  83. package/dist/guards/dotnet/testContext.d.ts +2 -0
  84. package/dist/guards/dotnet/testContext.js +12 -0
  85. package/dist/guards/dotnet/unusedNugetVersions.d.ts +2 -0
  86. package/dist/guards/dotnet/unusedNugetVersions.js +21 -0
  87. package/dist/guards/index.d.ts +2 -0
  88. package/dist/guards/index.js +6 -0
  89. package/dist/guards/repository/agentsFile.d.ts +3 -0
  90. package/dist/guards/repository/agentsFile.js +56 -0
  91. package/dist/guards/repository/bannedNpmPackages.d.ts +2 -0
  92. package/dist/guards/repository/bannedNpmPackages.js +43 -0
  93. package/dist/guards/repository/composePorts.d.ts +6 -0
  94. package/dist/guards/repository/composePorts.js +57 -0
  95. package/dist/guards/repository/dependencyDirection.d.ts +2 -0
  96. package/dist/guards/repository/dependencyDirection.js +87 -0
  97. package/dist/guards/repository/docsPaths.d.ts +2 -0
  98. package/dist/guards/repository/docsPaths.js +54 -0
  99. package/dist/guards/repository/forbiddenNames.d.ts +4 -0
  100. package/dist/guards/repository/forbiddenNames.js +69 -0
  101. package/dist/guards/repository/hooks.d.ts +3 -0
  102. package/dist/guards/repository/hooks.js +86 -0
  103. package/dist/guards/repository/imagePins.d.ts +3 -0
  104. package/dist/guards/repository/imagePins.js +68 -0
  105. package/dist/guards/repository/index.d.ts +2 -0
  106. package/dist/guards/repository/index.js +32 -0
  107. package/dist/guards/repository/justModules.d.ts +2 -0
  108. package/dist/guards/repository/justModules.js +36 -0
  109. package/dist/guards/repository/noRawColors.d.ts +2 -0
  110. package/dist/guards/repository/noRawColors.js +29 -0
  111. package/dist/guards/repository/packageManifests.d.ts +13 -0
  112. package/dist/guards/repository/packageManifests.js +26 -0
  113. package/dist/guards/repository/repositoryLayout.d.ts +3 -0
  114. package/dist/guards/repository/repositoryLayout.js +75 -0
  115. package/dist/guards/repository/requiredFiles.d.ts +6 -0
  116. package/dist/guards/repository/requiredFiles.js +78 -0
  117. package/dist/guards/repository/scriptsCalled.d.ts +3 -0
  118. package/dist/guards/repository/scriptsCalled.js +39 -0
  119. package/dist/guards/repository/scriptsHelp.d.ts +2 -0
  120. package/dist/guards/repository/scriptsHelp.js +37 -0
  121. package/dist/guards/repository/testRepository.d.ts +4 -0
  122. package/dist/guards/repository/testRepository.js +39 -0
  123. package/dist/guards/repository/text.d.ts +20 -0
  124. package/dist/guards/repository/text.js +33 -0
  125. package/dist/guards/repository/vsCodeSettings.d.ts +3 -0
  126. package/dist/guards/repository/vsCodeSettings.js +49 -0
  127. package/dist/profiles/contract.d.ts +5 -0
  128. package/dist/profiles/contract.js +124 -0
  129. package/dist/profiles/criteria.d.ts +25 -0
  130. package/dist/profiles/criteria.js +162 -0
  131. package/dist/profiles/database.d.ts +4 -0
  132. package/dist/profiles/database.js +23 -0
  133. package/dist/profiles/dotnet.d.ts +5 -0
  134. package/dist/profiles/dotnet.js +56 -0
  135. package/dist/profiles/everyRepository.d.ts +2 -0
  136. package/dist/profiles/everyRepository.js +32 -0
  137. package/dist/profiles/index.d.ts +2 -0
  138. package/dist/profiles/index.js +21 -0
  139. package/dist/profiles/library.d.ts +7 -0
  140. package/dist/profiles/library.js +132 -0
  141. package/dist/profiles/node.d.ts +5 -0
  142. package/dist/profiles/node.js +79 -0
  143. package/dist/profiles/presets/knip.d.ts +11 -0
  144. package/dist/profiles/presets/knip.js +29 -0
  145. package/dist/profiles/presets/playwright.d.ts +68 -0
  146. package/dist/profiles/presets/playwright.js +37 -0
  147. package/dist/profiles/presets/prettier.d.ts +12 -0
  148. package/dist/profiles/presets/prettier.js +7 -0
  149. package/dist/profiles/presets/tsconfig/browser.json +11 -0
  150. package/dist/profiles/presets/tsconfig/node.json +8 -0
  151. package/dist/profiles/presets/tsconfig/strict.json +17 -0
  152. package/dist/profiles/presets/vitest.d.ts +36 -0
  153. package/dist/profiles/presets/vitest.js +16 -0
  154. package/dist/profiles/shell.d.ts +10 -0
  155. package/dist/profiles/shell.js +62 -0
  156. package/dist/profiles/web.d.ts +2 -0
  157. package/dist/profiles/web.js +17 -0
  158. package/dist/session/guardEdit.d.ts +19 -0
  159. package/dist/session/guardEdit.js +96 -0
  160. package/dist/session/preCommit.d.ts +16 -0
  161. package/dist/session/preCommit.js +33 -0
  162. package/dist/session/stop.d.ts +8 -0
  163. package/dist/session/stop.js +39 -0
  164. package/package.json +97 -3
  165. package/schema/suwgate.schema.json +196 -0
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../gate/contract.ts";
2
+ export declare const guards: readonly Guard[];
@@ -0,0 +1,6 @@
1
+ import { commentGuards } from "./comments/index.js";
2
+ import { criteriaGuards } from "./criteria/index.js";
3
+ import { databaseGuards } from "./database/index.js";
4
+ import { dotnetGuards } from "./dotnet/index.js";
5
+ import { repositoryGuards } from "./repository/index.js";
6
+ export const guards = [...repositoryGuards, ...commentGuards, ...criteriaGuards, ...dotnetGuards, ...databaseGuards];
@@ -0,0 +1,3 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const MAX_AGENTS_LINES = 100;
3
+ export declare const agentsFile: Guard;
@@ -0,0 +1,56 @@
1
+ import { numberedLines, stringList } from "./text.js";
2
+ export const MAX_AGENTS_LINES = 100;
3
+ const ACRONYMS = ["AGENTS", "CLAUDE", "CSS", "FAIL", "HTML", "HTTP", "JSON", "KISS", "PASS", "README", "SKIP", "TODO", "YAGNI", "YAML"];
4
+ const TREE = /[├└│]/;
5
+ const SHOUTING = /\b[A-Z]{4,}\b/g;
6
+ function lineCount(text) {
7
+ const lines = text.split("\n").length;
8
+ return text.endsWith("\n") ? lines - 1 : lines;
9
+ }
10
+ function agentsFindings(text, acronyms) {
11
+ const findings = [];
12
+ const lines = lineCount(text);
13
+ if (lines > MAX_AGENTS_LINES) {
14
+ findings.push({
15
+ target: "AGENTS.md",
16
+ message: `${lines} lines, the limit is ${MAX_AGENTS_LINES} (it is read in every session): move detail to docs/, or make the rule a type, lint, test, guard or hook instead`,
17
+ });
18
+ }
19
+ for (const { line, text: content } of numberedLines(text)) {
20
+ if (TREE.test(content)) {
21
+ findings.push({
22
+ target: "AGENTS.md",
23
+ line,
24
+ message: "a directory tree goes stale: delete it and keep the map of folders in docs/architecture.md, which repository-layout checks",
25
+ });
26
+ }
27
+ for (const word of new Set(content.match(SHOUTING) ?? [])) {
28
+ if (!acronyms.has(word)) {
29
+ findings.push({
30
+ target: "AGENTS.md",
31
+ line,
32
+ message: `"${word}" shouts: write it in plain case and give the reason instead, or, if it is a real acronym, add it to settings.agents-file.acronyms in suwgate.yml`,
33
+ });
34
+ }
35
+ }
36
+ }
37
+ return findings;
38
+ }
39
+ export const agentsFile = {
40
+ id: "agents-file",
41
+ description: "AGENTS.md stays short, draws no directory tree and does not shout; CLAUDE.md only points to it with @AGENTS.md",
42
+ profiles: "every",
43
+ settingsSchema: { type: "object", additionalProperties: false, properties: { acronyms: stringList } },
44
+ check(context) {
45
+ const settings = (context.settings ?? {});
46
+ const acronyms = new Set([...ACRONYMS, ...(settings.acronyms ?? [])]);
47
+ const findings = context.files.includes("AGENTS.md") ? agentsFindings(context.read("AGENTS.md"), acronyms) : [];
48
+ if (context.files.includes("CLAUDE.md") && context.read("CLAUDE.md").trim() !== "@AGENTS.md") {
49
+ findings.push({
50
+ target: "CLAUDE.md",
51
+ message: "it must contain exactly @AGENTS.md, so every agent reads the same rules: move what it says into AGENTS.md",
52
+ });
53
+ }
54
+ return findings;
55
+ },
56
+ };
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const bannedNpmPackages: Guard;
@@ -0,0 +1,43 @@
1
+ import { npmDependencies } from "./packageManifests.js";
2
+ const KIT_COMPONENTS = "build it from the components of @maniumek/suwfrontkit and Tailwind utilities";
3
+ const TOKENS = "style with Tailwind utilities and the theme's tokens";
4
+ const BANNED_NPM_PACKAGES = {
5
+ "@mantine/": KIT_COMPONENTS,
6
+ "@mui/": KIT_COMPONENTS,
7
+ "@chakra-ui/": KIT_COMPONENTS,
8
+ "@emotion/": TOKENS,
9
+ "styled-components": TOKENS,
10
+ classnames: "use cn() of @maniumek/suwfrontkit",
11
+ lodash: "use the standard library",
12
+ "lodash-es": "use the standard library",
13
+ moment: "use Intl and Date",
14
+ jquery: "use React and the DOM",
15
+ };
16
+ function bannedBy(name, banned) {
17
+ const match = Object.keys(banned).find((entry) => name === entry || (entry.endsWith("/") && name.startsWith(entry)));
18
+ return match === undefined ? undefined : banned[match];
19
+ }
20
+ export const bannedNpmPackages = {
21
+ id: "banned-npm-packages",
22
+ description: "No package.json depends on a banned package (component kits, CSS-in-JS, lodash, moment, jQuery, classnames, and what settings add)",
23
+ profiles: ["web", "library"],
24
+ settingsSchema: {
25
+ type: "object",
26
+ additionalProperties: false,
27
+ properties: {
28
+ packages: {
29
+ type: "object",
30
+ description: "More banned packages: the name (a scope ends with /) and what to use instead.",
31
+ additionalProperties: { type: "string", minLength: 1 },
32
+ },
33
+ },
34
+ },
35
+ check(context) {
36
+ const settings = (context.settings ?? {});
37
+ const banned = { ...BANNED_NPM_PACKAGES, ...(settings.packages ?? {}) };
38
+ return npmDependencies(context).flatMap(({ manifest, name, line }) => {
39
+ const instead = bannedBy(name, banned);
40
+ return instead === undefined ? [] : [{ target: name, line, message: `${manifest} depends on it: remove it and ${instead}` }];
41
+ });
42
+ },
43
+ };
@@ -0,0 +1,6 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare function openPorts(text: string): {
3
+ line?: number;
4
+ port: string;
5
+ }[];
6
+ export declare const composePorts: Guard;
@@ -0,0 +1,57 @@
1
+ import { isMap, isScalar, isSeq, LineCounter, parseDocument } from "yaml";
2
+ import { baseName } from "./text.js";
3
+ const COMPOSE_FILE = /^(docker-)?compose(\.[\w-]+)?\.ya?ml$/;
4
+ const LOOPBACK = "127.0.0.1";
5
+ function lineOf(node, lineCounter) {
6
+ const start = node.range?.[0];
7
+ return start === undefined ? undefined : lineCounter.linePos(start).line;
8
+ }
9
+ function openPort(entry) {
10
+ if (isScalar(entry)) {
11
+ const port = String(entry.value);
12
+ return port.startsWith(`${LOOPBACK}:`) ? null : port;
13
+ }
14
+ if (isMap(entry)) {
15
+ const hostIp = entry.get("host_ip");
16
+ const published = entry.get("published");
17
+ const target = entry.get("target");
18
+ const shown = (value, fallback) => typeof value === "string" || typeof value === "number" ? String(value) : fallback;
19
+ return hostIp === LOOPBACK ? null : `${shown(published, "a random port")}:${shown(target, "?")}`;
20
+ }
21
+ return null;
22
+ }
23
+ export function openPorts(text) {
24
+ const lineCounter = new LineCounter();
25
+ const document = parseDocument(text, { lineCounter });
26
+ const services = document.get("services", true);
27
+ if (!isMap(services))
28
+ return [];
29
+ return services.items.flatMap((service) => {
30
+ const ports = isMap(service.value) ? service.value.get("ports", true) : undefined;
31
+ if (!isSeq(ports))
32
+ return [];
33
+ return ports.items.flatMap((entry) => {
34
+ const port = openPort(entry);
35
+ if (port === null)
36
+ return [];
37
+ const line = isScalar(entry) || isMap(entry) ? lineOf(entry, lineCounter) : undefined;
38
+ return [line === undefined ? { port } : { line, port }];
39
+ });
40
+ });
41
+ }
42
+ export const composePorts = {
43
+ id: "compose-ports",
44
+ description: "Every compose file publishes its ports on the loopback (127.0.0.1) only, never on every network interface",
45
+ profiles: "every",
46
+ check(context) {
47
+ return context.files
48
+ .filter((file) => COMPOSE_FILE.test(baseName(file)))
49
+ .flatMap((file) => openPorts(context.read(file)).map(({ line, port }) => {
50
+ const finding = {
51
+ target: file,
52
+ message: `${port} is published on every network interface, which puts it on the network and past the host's firewall: write "127.0.0.1:<host port>:<container port>" (or host_ip: 127.0.0.1)`,
53
+ };
54
+ return line === undefined ? finding : { ...finding, line };
55
+ }));
56
+ },
57
+ };
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const dependencyDirection: Guard;
@@ -0,0 +1,87 @@
1
+ import path from "node:path";
2
+ import { npmDependencies, RUNTIME_GROUPS } from "./packageManifests.js";
3
+ import { baseName, lineAt, stringList, wildcard } from "./text.js";
4
+ const NUGET_REFERENCE = /<(PackageReference|PackageVersion|ProjectReference)\b[^>]*?\bInclude="([^"]+)"/g;
5
+ const LOCAL_PATH = /^(link|file|portal):/;
6
+ function isShippedProject(file, text) {
7
+ const project = baseName(file).replace(/\.csproj$/, "");
8
+ return !/\.Tests?$/.test(project) && !/<IsTestProject>\s*true\s*</i.test(text) && !/<IsPackable>\s*false\s*</i.test(text);
9
+ }
10
+ function nugetReferences(context) {
11
+ return context.files
12
+ .filter((file) => /\.(csproj|props|targets)$/.test(file))
13
+ .flatMap((file) => {
14
+ const text = context.read(file);
15
+ const runtime = !file.endsWith(".csproj") || isShippedProject(file, text);
16
+ return [...text.matchAll(NUGET_REFERENCE)].map((match) => {
17
+ const include = (match[2] ?? "").replaceAll("\\", "/");
18
+ const isProject = match[1] === "ProjectReference";
19
+ const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(file), include));
20
+ return {
21
+ where: file,
22
+ line: lineAt(text, match.index),
23
+ name: isProject ? baseName(include).replace(/\.\w+proj$/, "") : include,
24
+ runtime: runtime && match[1] !== "PackageVersion",
25
+ localPath: isProject && resolved.startsWith("../") ? include : null,
26
+ };
27
+ });
28
+ });
29
+ }
30
+ function npmReferences(context) {
31
+ return npmDependencies(context).map((dependency) => ({
32
+ where: dependency.manifest,
33
+ line: dependency.line,
34
+ name: dependency.name,
35
+ runtime: !dependency.privateManifest && RUNTIME_GROUPS.includes(dependency.group),
36
+ localPath: LOCAL_PATH.test(dependency.version) ? dependency.version : null,
37
+ }));
38
+ }
39
+ function findingOf(reference, settings, isLibrary) {
40
+ const { where, line, name } = reference;
41
+ const matches = (patterns) => (patterns ?? []).some((pattern) => wildcard(pattern).test(name));
42
+ if (matches(settings.forbidden)) {
43
+ return {
44
+ target: name,
45
+ line,
46
+ message: `${where} depends on it, and this repository never does (settings.dependency-direction.forbidden in suwgate.yml): remove the dependency; what both need belongs in a package below them both`,
47
+ };
48
+ }
49
+ if (!isLibrary || !reference.runtime)
50
+ return null;
51
+ if (matches(settings.applications)) {
52
+ return {
53
+ target: name,
54
+ line,
55
+ message: `${where} depends on it at runtime, and it is an application (settings.dependency-direction.applications): a library never depends on an application; move what both need into the library and let the application depend on it`,
56
+ };
57
+ }
58
+ if (reference.localPath !== null) {
59
+ return {
60
+ target: name,
61
+ line,
62
+ message: `${where} takes it from ${reference.localPath}, a path outside the published package (an application or unpublished code): depend on a published version, or move the code into this library`,
63
+ };
64
+ }
65
+ return null;
66
+ }
67
+ export const dependencyDirection = {
68
+ id: "dependency-direction",
69
+ description: "Dependencies point one way: a library never depends at runtime on an application (named in settings, or taken from a local path), and no repository depends on a package its settings forbid",
70
+ profiles: "every",
71
+ settingsSchema: {
72
+ type: "object",
73
+ additionalProperties: false,
74
+ properties: {
75
+ applications: { ...stringList, description: "npm or NuGet packages that are applications (* matches anything), e.g. Myapp.*." },
76
+ forbidden: {
77
+ ...stringList,
78
+ description: "Packages this repository never depends on, not even to build or test (* matches anything).",
79
+ },
80
+ },
81
+ },
82
+ check(context) {
83
+ const settings = (context.settings ?? {});
84
+ const isLibrary = context.profiles.includes("library");
85
+ return [...npmReferences(context), ...nugetReferences(context)].flatMap((reference) => findingOf(reference, settings, isLibrary) ?? []);
86
+ },
87
+ };
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const docsPaths: Guard;
@@ -0,0 +1,54 @@
1
+ import path from "node:path";
2
+ import { baseName, lineAt, matchesAny, stringList } from "./text.js";
3
+ const MENTION = /`([\w.\-/@]+)`|\]\(([\w.\-/]+)(?:#[\w-]*)?\)/g;
4
+ const FILE_NAME = /[\w-]\.(cs|csproj|css|json|md|props|sh|slnx|sql|ts|tsx|txt|yaml|yml)$/;
5
+ const NOT_IN_THE_REPOSITORY = ["CLAUDE.local.md", "dist/"];
6
+ const NOT_READ = ["docs/visual/**", ".changeset/**"];
7
+ function isPath(mention) {
8
+ return !/^(https?:|\/|@|~)/.test(mention) && (mention.includes("/") || FILE_NAME.test(mention));
9
+ }
10
+ function existsLoosely(mention, files) {
11
+ const name = mention.replace(/^(\.\.?\/)+/, "");
12
+ const folder = `${name.replace(/\/+$/, "")}/`;
13
+ return files.some((file) => file === name || file.startsWith(folder) || file.endsWith(`/${name}`) || file.includes(`/${folder}`));
14
+ }
15
+ function existsFrom(document, link, files) {
16
+ const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(document), link));
17
+ if (resolved.startsWith("../"))
18
+ return false;
19
+ const folder = `${resolved.replace(/\/+$/, "")}/`;
20
+ return files.some((file) => file === resolved || file.startsWith(folder)) || (!link.startsWith(".") && existsLoosely(link, files));
21
+ }
22
+ function isIgnored(mention, ignored) {
23
+ return ignored.some((name) => mention === name || (name.endsWith("/") && mention.startsWith(name)));
24
+ }
25
+ function stale(document, text, files, ignored) {
26
+ return [...text.matchAll(MENTION)].flatMap((match) => {
27
+ const mention = match[1] ?? match[2] ?? "";
28
+ const isLink = match[1] === undefined;
29
+ if (!isPath(mention) || isIgnored(mention, ignored))
30
+ return [];
31
+ if (isLink ? existsFrom(document, mention, files) : existsLoosely(mention, files))
32
+ return [];
33
+ return [
34
+ {
35
+ target: document,
36
+ line: lineAt(text, match.index),
37
+ message: `${mention} is not a path in this repository: fix the path, or say what the code does instead of where it is (a name meant to be outside the repository, or a pattern of names, goes into settings.docs-paths.ignore; a folder there ends with /)`,
38
+ },
39
+ ];
40
+ });
41
+ }
42
+ export const docsPaths = {
43
+ id: "docs-paths",
44
+ description: "Every file and folder the Markdown docs name, in backticks or as a link, exists in the repository",
45
+ profiles: "every",
46
+ settingsSchema: { type: "object", additionalProperties: false, properties: { ignore: stringList } },
47
+ check(context) {
48
+ const settings = (context.settings ?? {});
49
+ const ignored = [...NOT_IN_THE_REPOSITORY, ...(settings.ignore ?? [])];
50
+ return context.files
51
+ .filter((file) => file.endsWith(".md") && baseName(file) !== "CHANGELOG.md" && !matchesAny(file, NOT_READ))
52
+ .flatMap((document) => stale(document, context.read(document), context.files, ignored));
53
+ },
54
+ };
@@ -0,0 +1,4 @@
1
+ import { type Guard, type Profile } from "../../gate/contract.ts";
2
+ export declare const FORBIDDEN_BY_PROFILE: Readonly<Record<Profile, readonly string[]>>;
3
+ export declare function forbiddenIn(name: string, forbidden: readonly string[]): string | undefined;
4
+ export declare const forbiddenNames: Guard;
@@ -0,0 +1,69 @@
1
+ import { PROFILES } from "../../gate/contract.js";
2
+ import { matchesAny, stringList } from "./text.js";
3
+ const EVERY_REPOSITORY = [
4
+ "base",
5
+ "common",
6
+ "core",
7
+ "helper",
8
+ "helpers",
9
+ "lib",
10
+ "manager",
11
+ "misc",
12
+ "shared",
13
+ "stuff",
14
+ "util",
15
+ "utilities",
16
+ "utility",
17
+ "utils",
18
+ ];
19
+ export const FORBIDDEN_BY_PROFILE = {
20
+ web: ["components", "hooks", "ui"],
21
+ library: ["components", "hooks", "ui"],
22
+ dotnet: ["application", "controllers", "domain", "dtos", "infrastructure", "interfaces", "models", "repositories", "services"],
23
+ database: [],
24
+ };
25
+ const NOT_READ = ["docs/visual/**"];
26
+ function words(name) {
27
+ return name
28
+ .split(/[-_.\s]+|(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/)
29
+ .filter((word) => word.length > 0)
30
+ .map((word) => word.toLowerCase());
31
+ }
32
+ export function forbiddenIn(name, forbidden) {
33
+ const parts = words(name);
34
+ return forbidden.find((word) => word === name.toLowerCase() || parts.includes(word));
35
+ }
36
+ function namedPaths(files) {
37
+ const named = new Map();
38
+ for (const file of files) {
39
+ const parts = file.split("/");
40
+ parts.slice(0, -1).forEach((_, index) => named.set(parts.slice(0, index + 1).join("/"), true));
41
+ if (!named.has(file))
42
+ named.set(file, /\.\w+proj$/.test(file));
43
+ }
44
+ return [...named].sort(([a], [b]) => (a < b ? -1 : 1)).map(([path, isFolderOrProject]) => ({ named: path, isFolderOrProject }));
45
+ }
46
+ export const forbiddenNames = {
47
+ id: "forbidden-names",
48
+ description: "No folder, project or file is named by a vague word (utils, helpers, common), and no folder or project by the kind of thing it holds (services, components), instead of what it is",
49
+ profiles: "every",
50
+ settingsSchema: { type: "object", additionalProperties: false, properties: { words: stringList, ignore: stringList } },
51
+ check(context) {
52
+ const settings = (context.settings ?? {});
53
+ const vague = [...EVERY_REPOSITORY, ...(settings.words ?? []).map((word) => word.toLowerCase())];
54
+ const byKind = PROFILES.filter((profile) => context.profiles.includes(profile)).flatMap((profile) => FORBIDDEN_BY_PROFILE[profile]);
55
+ const ignored = [...NOT_READ, ...(settings.ignore ?? [])];
56
+ return namedPaths(context.files.filter((file) => !matchesAny(file, ignored))).flatMap(({ named, isFolderOrProject }) => {
57
+ const name = named.split("/").at(-1) ?? named;
58
+ const word = forbiddenIn(name, isFolderOrProject ? [...vague, ...byKind] : vague);
59
+ return word === undefined
60
+ ? []
61
+ : [
62
+ {
63
+ target: named,
64
+ message: `"${word}" names who uses it or what kind of thing it holds, not what it is: rename it after the feature or after what it is (Database, Output, appShell); one feature, one folder`,
65
+ },
66
+ ];
67
+ });
68
+ },
69
+ };
@@ -0,0 +1,3 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare function matcherCovers(matcher: string, tool: string): boolean;
3
+ export declare const hooks: Guard;
@@ -0,0 +1,86 @@
1
+ import { isRecord, parseJson, stringList } from "./text.js";
2
+ const CLAUDE_SETTINGS = ".claude/settings.json";
3
+ const PRE_COMMIT = ".githooks/pre-commit";
4
+ const EDIT_TOOLS = ["Edit", "Write"];
5
+ export function matcherCovers(matcher, tool) {
6
+ if (matcher === "" || matcher === "*")
7
+ return true;
8
+ if (/^[\w\s,|-]+$/.test(matcher))
9
+ return matcher.split(/[|,]/).some((name) => name.trim() === tool);
10
+ try {
11
+ return new RegExp(matcher).test(tool);
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ function entries(settings, event) {
18
+ const hooks = isRecord(settings) ? settings["hooks"] : undefined;
19
+ const list = isRecord(hooks) ? hooks[event] : undefined;
20
+ if (!Array.isArray(list))
21
+ return [];
22
+ return list.filter(isRecord).map((entry) => ({
23
+ matcher: typeof entry["matcher"] === "string" ? entry["matcher"] : "",
24
+ commands: (Array.isArray(entry["hooks"]) ? entry["hooks"] : [])
25
+ .filter(isRecord)
26
+ .flatMap((hook) => (typeof hook["command"] === "string" ? [hook["command"]] : [])),
27
+ }));
28
+ }
29
+ function claudeFindings(text) {
30
+ const settings = parseJson(text);
31
+ if (!isRecord(settings))
32
+ return [{ target: CLAUDE_SETTINGS, message: "not valid JSON: fix it, Claude Code ignores settings it cannot read" }];
33
+ const findings = [];
34
+ if (!entries(settings, "Stop").some((entry) => entry.commands.some((command) => command.includes("hook stop")))) {
35
+ findings.push({
36
+ target: CLAUDE_SETTINGS,
37
+ message: 'no Stop hook runs suwgate hook stop, so an agent can finish a turn with a red quick gate: add { "type": "command", "command": "<suwgate> hook stop", "timeout": 600 } under hooks.Stop',
38
+ });
39
+ }
40
+ const guarded = entries(settings, "PreToolUse").filter((entry) => entry.commands.some((command) => command.includes("hook guard-edit")));
41
+ const unguarded = EDIT_TOOLS.filter((tool) => !guarded.some((entry) => matcherCovers(entry.matcher, tool)));
42
+ if (unguarded.length > 0) {
43
+ findings.push({
44
+ target: CLAUDE_SETTINGS,
45
+ message: `no PreToolUse hook runs suwgate hook guard-edit for ${unguarded.join(", ")}, so an agent can edit the gate: add { "matcher": "Edit|Write|MultiEdit|NotebookEdit", "hooks": [{ "type": "command", "command": "<suwgate> hook guard-edit" }] } under hooks.PreToolUse`,
46
+ });
47
+ }
48
+ return findings;
49
+ }
50
+ export const hooks = {
51
+ id: "hooks",
52
+ description: "The Claude Code hooks (suwgate hook stop, suwgate hook guard-edit) and the git hook (suwgate hook pre-commit) are wired; its settings are the edit hook's lists",
53
+ profiles: "every",
54
+ settingsSchema: {
55
+ type: "object",
56
+ additionalProperties: false,
57
+ properties: {
58
+ protected: {
59
+ ...stringList,
60
+ description: "More files of this repository's gate an agent does not edit (globs, relative to the root).",
61
+ },
62
+ generated: {
63
+ type: "array",
64
+ description: "Files a command generates, which nobody edits by hand: the glob and the command that regenerates them.",
65
+ items: {
66
+ type: "object",
67
+ additionalProperties: false,
68
+ required: ["path", "command"],
69
+ properties: { path: { type: "string", minLength: 1 }, command: { type: "string", minLength: 1 } },
70
+ },
71
+ },
72
+ recordings: { ...stringList, description: "Globs of recorded tests: a file git tracks there is not edited by an agent." },
73
+ migrations: { ...stringList, description: "Globs of migration scripts: one that exists is never edited, a new one is added." },
74
+ },
75
+ },
76
+ check(context) {
77
+ const findings = context.files.includes(CLAUDE_SETTINGS) ? claudeFindings(context.read(CLAUDE_SETTINGS)) : [];
78
+ if (context.files.includes(PRE_COMMIT) && !context.read(PRE_COMMIT).includes("hook pre-commit")) {
79
+ findings.push({
80
+ target: PRE_COMMIT,
81
+ message: "it does not run suwgate hook pre-commit (gitleaks on the staged changes, then the quick gate): make its body exec <suwgate> hook pre-commit",
82
+ });
83
+ }
84
+ return findings;
85
+ },
86
+ };
@@ -0,0 +1,3 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare function isPinned(image: string): boolean;
3
+ export declare const imagePins: Guard;
@@ -0,0 +1,68 @@
1
+ import { baseName, isRecord, lineAt, parseJson } from "./text.js";
2
+ const FROM = /^[ \t]*FROM[ \t]+(?:--\S+[ \t]+)*(\S+)(?:[ \t]+AS[ \t]+(\S+))?/gim;
3
+ const YAML_IMAGE = /^[ \t]*(?:-[ \t]*)?image:[ \t]*["']?([^"'\s#]+)/gm;
4
+ const SHELL_IMAGE = /(?:^|\s)IMAGE=["']?([^"'\s]+)/gm;
5
+ const PLAYWRIGHT_IMAGE = /^mcr\.microsoft\.com\/playwright:v([\d.]+)-/;
6
+ function isDockerfile(name) {
7
+ return /^Dockerfile(\.[\w-]+)?$|\.Dockerfile$/.test(name);
8
+ }
9
+ function references(file, text) {
10
+ const found = (pattern) => [...text.matchAll(pattern)].map((match) => ({ file, line: lineAt(text, match.index), image: match[1] ?? "" }));
11
+ const name = baseName(file);
12
+ if (isDockerfile(name)) {
13
+ const stages = new Set([...text.matchAll(FROM)].flatMap((match) => (match[2] === undefined ? [] : [match[2].toLowerCase()])));
14
+ return found(FROM).filter((reference) => reference.image !== "scratch" && !stages.has(reference.image.toLowerCase()));
15
+ }
16
+ if (/\.ya?ml$/.test(name))
17
+ return name === "pnpm-lock.yaml" ? [] : found(YAML_IMAGE);
18
+ return name.endsWith(".sh") ? found(SHELL_IMAGE) : [];
19
+ }
20
+ export function isPinned(image) {
21
+ if (image.includes("@sha256:"))
22
+ return true;
23
+ const tag = image.split("/").at(-1)?.split(":")[1];
24
+ return tag !== undefined && tag !== "" && tag !== "latest";
25
+ }
26
+ function installedPlaywright(context) {
27
+ return context.files
28
+ .filter((file) => baseName(file) === "package.json")
29
+ .flatMap((file) => {
30
+ const manifest = parseJson(context.read(file));
31
+ if (!isRecord(manifest))
32
+ return [];
33
+ return ["dependencies", "devDependencies"].flatMap((group) => {
34
+ const dependencies = manifest[group];
35
+ const version = isRecord(dependencies) ? dependencies["@playwright/test"] : undefined;
36
+ return typeof version === "string" ? [version.replace(/^[\^~=]/, "")] : [];
37
+ });
38
+ });
39
+ }
40
+ export const imagePins = {
41
+ id: "image-pins",
42
+ description: "Every container image (Dockerfile FROM, image: in YAML, IMAGE= in a script) is pinned to a version, never latest, and the Playwright image matches the installed @playwright/test",
43
+ profiles: "every",
44
+ check(context) {
45
+ const found = context.files.flatMap((file) => isDockerfile(baseName(file)) || /\.(ya?ml|sh)$/.test(file) ? references(file, context.read(file)) : []);
46
+ const unpinned = found
47
+ .filter(({ image }) => !image.includes("$") && !isPinned(image))
48
+ .map(({ file, line, image }) => ({
49
+ target: file,
50
+ line,
51
+ message: `${image} moves with every release, so builds stop being reproducible: pin it to a version (name:1.2.3) or a digest`,
52
+ }));
53
+ const installed = installedPlaywright(context);
54
+ const playwright = found.flatMap(({ file, line, image }) => {
55
+ const version = PLAYWRIGHT_IMAGE.exec(image)?.[1];
56
+ if (version === undefined || installed.length === 0 || installed.includes(version))
57
+ return [];
58
+ return [
59
+ {
60
+ target: file,
61
+ line,
62
+ message: `the image has Playwright ${version}, the tests expect ${installed.join(", ")}: move it to mcr.microsoft.com/playwright:v${installed[0] ?? ""}-noble together with @playwright/test`,
63
+ },
64
+ ];
65
+ });
66
+ return [...unpinned, ...playwright];
67
+ },
68
+ };
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const repositoryGuards: readonly Guard[];
@@ -0,0 +1,32 @@
1
+ import { agentsFile } from "./agentsFile.js";
2
+ import { bannedNpmPackages } from "./bannedNpmPackages.js";
3
+ import { composePorts } from "./composePorts.js";
4
+ import { dependencyDirection } from "./dependencyDirection.js";
5
+ import { docsPaths } from "./docsPaths.js";
6
+ import { forbiddenNames } from "./forbiddenNames.js";
7
+ import { hooks } from "./hooks.js";
8
+ import { imagePins } from "./imagePins.js";
9
+ import { justModules } from "./justModules.js";
10
+ import { noRawColors } from "./noRawColors.js";
11
+ import { repositoryLayout } from "./repositoryLayout.js";
12
+ import { requiredFiles } from "./requiredFiles.js";
13
+ import { scriptsCalled } from "./scriptsCalled.js";
14
+ import { scriptsHelp } from "./scriptsHelp.js";
15
+ import { vsCodeSettings } from "./vsCodeSettings.js";
16
+ export const repositoryGuards = [
17
+ requiredFiles,
18
+ agentsFile,
19
+ docsPaths,
20
+ forbiddenNames,
21
+ repositoryLayout,
22
+ scriptsCalled,
23
+ scriptsHelp,
24
+ justModules,
25
+ imagePins,
26
+ composePorts,
27
+ vsCodeSettings,
28
+ bannedNpmPackages,
29
+ noRawColors,
30
+ dependencyDirection,
31
+ hooks,
32
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const justModules: Guard;