@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,36 @@
1
+ import { baseName } from "./text.js";
2
+ const MOD_LINE = /^mod\??\s+([\w-]+)\s*$/gm;
3
+ function moduleName(file) {
4
+ return file.endsWith("/mod.just") ? (file.split("/")[0] ?? "") : baseName(file).replace(/\.just$/, "");
5
+ }
6
+ export const justModules = {
7
+ id: "just-modules",
8
+ description: "Every just module is <name>.just beside the justfile or <folder>/mod.just, and the justfile names each one with mod <name>",
9
+ profiles: "every",
10
+ check(context) {
11
+ const modules = context.files.filter((file) => file.endsWith(".just"));
12
+ const named = context.files.includes("justfile")
13
+ ? [...context.read("justfile").matchAll(MOD_LINE)].map((match) => match[1] ?? "")
14
+ : [];
15
+ const misplaced = modules
16
+ .filter((file) => file.includes("/") && (baseName(file) !== "mod.just" || file.split("/").length !== 2))
17
+ .map((file) => ({
18
+ target: file,
19
+ message: "just finds a module only as <name>.just beside the justfile or as <folder>/mod.just: move it there",
20
+ }));
21
+ const missing = named
22
+ .filter((name) => !modules.includes(`${name}.just`) && !modules.includes(`${name}/mod.just`))
23
+ .map((name) => ({
24
+ target: "justfile",
25
+ message: `mod ${name} has no ${name}.just or ${name}/mod.just: add the module, or delete the mod line`,
26
+ }));
27
+ const orphans = modules
28
+ .filter((file) => !named.includes(moduleName(file)))
29
+ .filter((file) => !misplaced.some((finding) => finding.target === file))
30
+ .map((file) => ({
31
+ target: file,
32
+ message: `the justfile does not load it: add mod ${moduleName(file)} to the justfile, or delete the module`,
33
+ }));
34
+ return [...misplaced, ...missing, ...orphans];
35
+ },
36
+ };
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const noRawColors: Guard;
@@ -0,0 +1,29 @@
1
+ import { inProfileDirectory, numberedLines, stringList } from "./text.js";
2
+ const RAW_COLOR = /#[0-9a-fA-F]{3,8}\b|\b(rgb|rgba|hsl|hsla|oklch|oklab)\(|\[#/;
3
+ const CODE_FILE = /\.(ts|tsx|js|jsx)$/;
4
+ export const noRawColors = {
5
+ id: "no-raw-colors",
6
+ description: "Components use the theme's tokens, never a colour value of their own; it reads the src/ folder of a web app, and the folders settings name",
7
+ profiles: ["web", "library"],
8
+ settingsSchema: {
9
+ type: "object",
10
+ additionalProperties: false,
11
+ properties: {
12
+ folders: { ...stringList, description: "The folders of components, relative to the root (default: src/ of the web app)." },
13
+ },
14
+ },
15
+ check(context) {
16
+ const settings = (context.settings ?? {});
17
+ const defaults = context.profiles.includes("web") ? [inProfileDirectory(context.directories, "web", "src/")] : [];
18
+ const folders = (settings.folders ?? defaults).map((folder) => `${folder.replace(/\/+$/, "")}/`);
19
+ return context.files
20
+ .filter((file) => CODE_FILE.test(file) && folders.some((folder) => file.startsWith(folder)))
21
+ .flatMap((file) => numberedLines(context.read(file))
22
+ .filter(({ text }) => RAW_COLOR.test(text))
23
+ .map(({ line }) => ({
24
+ target: file,
25
+ line,
26
+ message: "a colour value of its own drifts from the theme and breaks dark mode: use a token class (bg-primary, text-muted-foreground) or var(--token), and add a new colour to the theme's tokens",
27
+ })));
28
+ },
29
+ };
@@ -0,0 +1,13 @@
1
+ import type { GuardContext } from "../../gate/contract.ts";
2
+ export declare const RUNTIME_GROUPS: readonly ["dependencies", "peerDependencies", "optionalDependencies"];
3
+ declare const ALL_GROUPS: readonly ["dependencies", "peerDependencies", "optionalDependencies", "devDependencies"];
4
+ export interface Dependency {
5
+ manifest: string;
6
+ name: string;
7
+ version: string;
8
+ group: (typeof ALL_GROUPS)[number];
9
+ line: number;
10
+ privateManifest: boolean;
11
+ }
12
+ export declare function npmDependencies(context: GuardContext): Dependency[];
13
+ export {};
@@ -0,0 +1,26 @@
1
+ import { baseName, isRecord, lineAt, parseJson } from "./text.js";
2
+ export const RUNTIME_GROUPS = ["dependencies", "peerDependencies", "optionalDependencies"];
3
+ const ALL_GROUPS = [...RUNTIME_GROUPS, "devDependencies"];
4
+ export function npmDependencies(context) {
5
+ return context.files
6
+ .filter((file) => baseName(file) === "package.json")
7
+ .flatMap((manifest) => {
8
+ const text = context.read(manifest);
9
+ const parsed = parseJson(text);
10
+ if (!isRecord(parsed))
11
+ return [];
12
+ return ALL_GROUPS.flatMap((group) => {
13
+ const dependencies = parsed[group];
14
+ if (!isRecord(dependencies))
15
+ return [];
16
+ return Object.entries(dependencies).map(([name, version]) => ({
17
+ manifest,
18
+ name,
19
+ version: typeof version === "string" ? version : "",
20
+ group,
21
+ line: lineAt(text, Math.max(0, text.indexOf(`"${name}"`))),
22
+ privateManifest: parsed["private"] === true,
23
+ }));
24
+ });
25
+ });
26
+ }
@@ -0,0 +1,3 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const MAX_MAP_LINE_LENGTH = 300;
3
+ export declare const repositoryLayout: Guard;
@@ -0,0 +1,75 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { numberedLines } from "./text.js";
5
+ const MAP = "docs/architecture.md";
6
+ export const MAX_MAP_LINE_LENGTH = 300;
7
+ const MAP_ENTRY = /^- `([^`]+)`/;
8
+ function mapFindings(context) {
9
+ const entries = numberedLines(context.read(MAP)).filter(({ text }) => MAP_ENTRY.test(text));
10
+ const folders = new Set(context.files.filter((file) => file.includes("/")).map((file) => file.split("/")[0] ?? ""));
11
+ const described = new Map(entries.map(({ line, text }) => [(MAP_ENTRY.exec(text)?.[1] ?? "").split("/")[0] ?? "", line]));
12
+ const missing = [...folders]
13
+ .filter((folder) => !described.has(folder))
14
+ .sort()
15
+ .map((folder) => ({
16
+ target: `${folder}/`,
17
+ message: `add a line for it to the map in ${MAP}: - \`${folder}/\` — what it holds and why it is a folder of its own`,
18
+ }));
19
+ const stale = [...described]
20
+ .filter(([entry]) => !folders.has(entry) && !context.files.includes(entry) && !existsSync(path.join(context.root, entry)))
21
+ .map(([entry, line]) => ({ target: MAP, line, message: `the map names ${entry}, which does not exist: delete its line` }));
22
+ const tooLong = entries
23
+ .filter(({ text }) => text.length > MAX_MAP_LINE_LENGTH)
24
+ .map(({ line, text }) => ({
25
+ target: MAP,
26
+ line,
27
+ message: `${text.length} characters, the limit is ${MAX_MAP_LINE_LENGTH}: shorten the line, the map says what a folder holds, not how it works`,
28
+ }));
29
+ return [...missing, ...stale, ...tooLong];
30
+ }
31
+ function caseClashes(files) {
32
+ const seen = new Map();
33
+ const findings = [];
34
+ for (const file of files) {
35
+ const other = seen.get(file.toLowerCase());
36
+ if (other !== undefined) {
37
+ findings.push({
38
+ target: file,
39
+ message: `differs from ${other} only in letter case, which Windows and macOS ignore: rename one of them`,
40
+ });
41
+ }
42
+ seen.set(file.toLowerCase(), file);
43
+ }
44
+ return findings;
45
+ }
46
+ function notExecutable(root) {
47
+ let staged;
48
+ try {
49
+ staged = execFileSync("git", ["ls-files", "--stage", "-z", "--", "*.sh", ".githooks/*"], {
50
+ cwd: root,
51
+ encoding: "utf8",
52
+ stdio: ["ignore", "pipe", "ignore"],
53
+ });
54
+ }
55
+ catch {
56
+ return [];
57
+ }
58
+ return staged
59
+ .split("\0")
60
+ .filter((entry) => entry.length > 0 && !entry.startsWith("100755"))
61
+ .map((entry) => entry.split("\t")[1] ?? entry)
62
+ .map((file) => ({ target: file, message: `not executable in git: run git update-index --chmod=+x ${file}` }));
63
+ }
64
+ export const repositoryLayout = {
65
+ id: "repository-layout",
66
+ description: "Every top-level folder has a short line in the map of docs/architecture.md, no two files differ only in letter case, and every shell script is executable in git",
67
+ profiles: "every",
68
+ check(context) {
69
+ return [
70
+ ...(context.files.includes(MAP) ? mapFindings(context) : []),
71
+ ...caseClashes(context.files),
72
+ ...notExecutable(context.root),
73
+ ];
74
+ },
75
+ };
@@ -0,0 +1,6 @@
1
+ import { type Guard, type Profile } from "../../gate/contract.ts";
2
+ type Purposes = Readonly<Record<string, string>>;
3
+ export declare const EVERY_REPOSITORY: Purposes;
4
+ export declare const REQUIRED_BY_PROFILE: Readonly<Record<Profile, Purposes>>;
5
+ export declare const requiredFiles: Guard;
6
+ export {};
@@ -0,0 +1,78 @@
1
+ import { PROFILES } from "../../gate/contract.js";
2
+ import { inProfileDirectory, stringList } from "./text.js";
3
+ export const EVERY_REPOSITORY = {
4
+ "suwgate.yml": "the repository's gate: its profiles, the steps it adds or skips, and the exceptions with their reasons",
5
+ "README.md": "what the project is and how to use it, for people",
6
+ "AGENTS.md": "the rules every agent and person reads before changing the repository",
7
+ "CLAUDE.md": "it points Claude Code to the rules with exactly @AGENTS.md",
8
+ ".editorconfig": "the whitespace and line endings every editor follows",
9
+ ".gitattributes": "the line endings and binary files git keeps the same on every machine",
10
+ ".gitignore": "it keeps build output, secrets and local settings out of git, and so out of every guard's file list",
11
+ ".claude/settings.json": "it wires the Claude Code hooks suwgate hook stop and suwgate hook guard-edit",
12
+ ".githooks/pre-commit": "the git hook that runs suwgate hook pre-commit (gitleaks on the staged changes, then the quick gate)",
13
+ justfile: "the recipes people run, which just lists",
14
+ "docs/architecture.md": "the map of the top-level folders, which repository-layout reads, and the contracts of the code",
15
+ "docs/development.md": "how to set up the repository and work on it",
16
+ ".vscode/settings.json": "the editor's glue: the formatter per language and yaml.schemas for suwgate.yml",
17
+ ".vscode/extensions.json": "the editor extensions the repository expects",
18
+ };
19
+ export const REQUIRED_BY_PROFILE = {
20
+ web: {
21
+ "package.json": "the web app's packages and scripts",
22
+ "pnpm-lock.yaml": "the exact versions pnpm installs, the same on every machine and in CI",
23
+ "pnpm-workspace.yaml": "pnpm's settings, such as the minimum age of a new release",
24
+ "tsconfig.json": "the strict TypeScript options the typecheck step uses",
25
+ "eslint.config.js": "the lint rules, including no comments and the feature boundaries",
26
+ ".prettierrc.json": "the formatting the format step checks",
27
+ "knip.config.ts": "knip's config, one line that extends @maniumek/suwgate/knip, so dead code is found",
28
+ },
29
+ library: {
30
+ LICENSE: "the terms under which the published package may be used",
31
+ "package.json": "the published package: its name, entry points and dependencies",
32
+ "pnpm-lock.yaml": "the exact versions pnpm installs, the same on every machine and in CI",
33
+ ".changeset/config.json": "the changesets that describe each change of the package for its next release",
34
+ },
35
+ dotnet: {
36
+ "global.json": "the .NET SDK every machine and CI builds with",
37
+ "nuget.config": "the package sources, so a restore never reaches an unexpected feed",
38
+ "Directory.Build.props": "the build settings of every project (warnings as errors, analyzers, nullable, lock files)",
39
+ "Directory.Packages.props": "the one place that pins the version of every NuGet package",
40
+ ".config/dotnet-tools.json": "the .NET tools at pinned versions, such as CSharpier for the format step",
41
+ "layers.json": "the layers of the server and which project may reference which, read by Suwgate.Architecture",
42
+ },
43
+ database: {
44
+ "compose.yaml": "the local PostgreSQL the server and its tests run against",
45
+ },
46
+ };
47
+ function required(context, settings) {
48
+ const files = new Map();
49
+ for (const [file, purpose] of Object.entries(EVERY_REPOSITORY))
50
+ files.set(file, `${purpose}. Every repository needs it: add it`);
51
+ for (const profile of PROFILES.filter((candidate) => context.profiles.includes(candidate))) {
52
+ for (const [file, purpose] of Object.entries(REQUIRED_BY_PROFILE[profile])) {
53
+ const placed = inProfileDirectory(context.directories, profile, file);
54
+ if (!files.has(placed))
55
+ files.set(placed, `${purpose}. The ${profile} profile needs it: add it`);
56
+ }
57
+ }
58
+ for (const file of settings.files ?? []) {
59
+ if (!files.has(file))
60
+ files.set(file, "settings.required-files.files in suwgate.yml asks for it: add it");
61
+ }
62
+ return files;
63
+ }
64
+ export const requiredFiles = {
65
+ id: "required-files",
66
+ description: "Every file a repository of these profiles needs is there (the gate, the agent rules, the editor and git settings, the hooks, each profile's tool configs)",
67
+ profiles: "every",
68
+ settingsSchema: { type: "object", additionalProperties: false, properties: { files: stringList } },
69
+ check(context) {
70
+ const present = new Set(context.files);
71
+ return [...required(context, (context.settings ?? {}))]
72
+ .filter(([file]) => !present.has(file))
73
+ .map(([file, purpose]) => ({
74
+ target: file,
75
+ message: `missing: ${purpose}, or add an exception with the reason it does not apply`,
76
+ }));
77
+ },
78
+ };
@@ -0,0 +1,3 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare function isScript(file: string): boolean;
3
+ export declare const scriptsCalled: Guard;
@@ -0,0 +1,39 @@
1
+ import { baseName } from "./text.js";
2
+ const CALLER_FILES = new Set([
3
+ "justfile",
4
+ "package.json",
5
+ "suwgate.yml",
6
+ ".claude/settings.json",
7
+ ".vscode/tasks.json",
8
+ ".template.config/template.json",
9
+ ]);
10
+ export function isScript(file) {
11
+ return file.endsWith(".sh") || /(^|\/)scripts\/(.+\/)?[^/]+\.(ts|js|mjs|py|ps1)$/.test(file);
12
+ }
13
+ function isCaller(file) {
14
+ const name = baseName(file);
15
+ return (CALLER_FILES.has(file) ||
16
+ name === "package.json" ||
17
+ name === "justfile" ||
18
+ /\.(sh|just|csproj|proj|props|targets)$/.test(name) ||
19
+ /^Dockerfile|\.Dockerfile$/.test(name) ||
20
+ /^(docker-)?compose(\.[\w-]+)?\.ya?ml$/.test(name) ||
21
+ file.startsWith(".githooks/") ||
22
+ file.startsWith(".github/workflows/") ||
23
+ file.startsWith(".github/actions/"));
24
+ }
25
+ export const scriptsCalled = {
26
+ id: "scripts-called",
27
+ description: "Every script (*.sh, and the files of a scripts/ folder) is called by a recipe, another script, a hook, the workflow or suwgate.yml",
28
+ profiles: "every",
29
+ check(context) {
30
+ const callers = context.files.filter(isCaller).map((file) => ({ file, text: context.read(file) }));
31
+ return context.files
32
+ .filter(isScript)
33
+ .filter((script) => !callers.some((caller) => caller.file !== script && caller.text.includes(baseName(script))))
34
+ .map((script) => ({
35
+ target: script,
36
+ message: "nothing calls it: delete it, or call it from the recipe, script, hook or workflow that needs it",
37
+ }));
38
+ },
39
+ };
@@ -0,0 +1,2 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare const scriptsHelp: Guard;
@@ -0,0 +1,37 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { baseName } from "./text.js";
3
+ const TIMEOUT_MS = 30_000;
4
+ function helpFinding(root, script, text) {
5
+ if (!text.includes("--help") && !text.includes("usage:")) {
6
+ return {
7
+ target: script,
8
+ message: "it does not handle --help, so it would run for real when an agent asks it what it does: print a usage text on --help and exit",
9
+ };
10
+ }
11
+ const run = spawnSync("bash", [script, "--help"], {
12
+ cwd: root,
13
+ encoding: "utf8",
14
+ timeout: TIMEOUT_MS,
15
+ stdio: ["ignore", "pipe", "pipe"],
16
+ });
17
+ if (run.error !== undefined || run.signal !== null) {
18
+ return {
19
+ target: script,
20
+ message: `--help did not finish within ${TIMEOUT_MS / 1000} s: print the usage text and exit before doing any work`,
21
+ };
22
+ }
23
+ return run.stdout.length + run.stderr.length > 0
24
+ ? null
25
+ : { target: script, message: "--help printed nothing: print what the script does and how to call it" };
26
+ }
27
+ export const scriptsHelp = {
28
+ id: "scripts-help",
29
+ description: "Every shell script but the hooks answers --help with a usage text, so an agent asks it instead of reading it",
30
+ profiles: "every",
31
+ quick: false,
32
+ check(context) {
33
+ return context.files
34
+ .filter((file) => file.endsWith(".sh") && !baseName(file).startsWith("hook-"))
35
+ .flatMap((script) => helpFinding(context.root, script, context.read(script)) ?? []);
36
+ },
37
+ };
@@ -0,0 +1,4 @@
1
+ import type { Finding, Guard, GuardContext } from "../../gate/contract.ts";
2
+ export declare function findingsOf(guard: Guard, files: Readonly<Record<string, string>>, extra?: Partial<GuardContext>): Promise<readonly Finding[]>;
3
+ export declare function shown(findings: readonly Finding[]): string[];
4
+ export declare function gitRepository(files: Readonly<Record<string, string>>, executable?: readonly string[]): string;
@@ -0,0 +1,39 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ function contextOf(files, extra = {}) {
6
+ return {
7
+ root: "/repository",
8
+ files: Object.keys(files),
9
+ profiles: ["library"],
10
+ directories: {},
11
+ exceptions: [],
12
+ settings: undefined,
13
+ read: (file) => {
14
+ const text = files[file];
15
+ if (text === undefined)
16
+ throw new Error(`${file} is not in the test repository`);
17
+ return text;
18
+ },
19
+ ...extra,
20
+ };
21
+ }
22
+ export async function findingsOf(guard, files, extra = {}) {
23
+ return guard.check(contextOf(files, extra));
24
+ }
25
+ export function shown(findings) {
26
+ return findings.map((finding) => `${finding.target}${finding.line === undefined ? "" : `:${finding.line}`}`);
27
+ }
28
+ export function gitRepository(files, executable = []) {
29
+ const root = mkdtempSync(path.join(tmpdir(), "suwgate-repository-"));
30
+ for (const [file, text] of Object.entries(files)) {
31
+ mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
32
+ writeFileSync(path.join(root, file), text);
33
+ if (executable.includes(file))
34
+ chmodSync(path.join(root, file), 0o755);
35
+ }
36
+ execFileSync("git", ["init", "-q"], { cwd: root });
37
+ execFileSync("git", ["add", "-A"], { cwd: root });
38
+ return root;
39
+ }
@@ -0,0 +1,20 @@
1
+ import type { Profile } from "../../gate/contract.ts";
2
+ export declare function baseName(file: string): string;
3
+ export declare function lineAt(text: string, index: number): number;
4
+ export declare function numberedLines(text: string): {
5
+ line: number;
6
+ text: string;
7
+ }[];
8
+ export declare function wildcard(pattern: string): RegExp;
9
+ export declare function matchesAny(file: string, globs: readonly string[]): boolean;
10
+ export declare function inProfileDirectory(directories: Readonly<Partial<Record<Profile, string>>>, profile: Profile, file: string): string;
11
+ export declare function parseJson(text: string): unknown;
12
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
13
+ export declare const stringList: {
14
+ readonly type: "array";
15
+ readonly uniqueItems: true;
16
+ readonly items: {
17
+ readonly type: "string";
18
+ readonly minLength: 1;
19
+ };
20
+ };
@@ -0,0 +1,33 @@
1
+ import path from "node:path";
2
+ export function baseName(file) {
3
+ return path.posix.basename(file);
4
+ }
5
+ export function lineAt(text, index) {
6
+ return text.slice(0, index).split("\n").length;
7
+ }
8
+ export function numberedLines(text) {
9
+ return text.split("\n").map((line, index) => ({ line: index + 1, text: line.replace(/\r$/, "") }));
10
+ }
11
+ export function wildcard(pattern) {
12
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replaceAll("*", ".*");
13
+ return new RegExp(`^${escaped}$`);
14
+ }
15
+ export function matchesAny(file, globs) {
16
+ return globs.some((glob) => path.posix.matchesGlob(file, glob));
17
+ }
18
+ export function inProfileDirectory(directories, profile, file) {
19
+ const directory = directories[profile];
20
+ return directory === undefined ? file : `${directory.replace(/\/+$/, "")}/${file}`;
21
+ }
22
+ export function parseJson(text) {
23
+ try {
24
+ return JSON.parse(text);
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ export function isRecord(value) {
31
+ return typeof value === "object" && value !== null && !Array.isArray(value);
32
+ }
33
+ export const stringList = { type: "array", uniqueItems: true, items: { type: "string", minLength: 1 } };
@@ -0,0 +1,3 @@
1
+ import type { Guard } from "../../gate/contract.ts";
2
+ export declare function isStyleKey(key: string): boolean;
3
+ export declare const vsCodeSettings: Guard;
@@ -0,0 +1,49 @@
1
+ import { isRecord, parseJson } from "./text.js";
2
+ const TOOL_PATHS = new Set(["prettier.prettierPath", "prettier.configPath", "prettier.ignorePath", "prettier.requireConfig"]);
3
+ const STYLE_KEY = /^(editor\.(tabSize|insertSpaces|detectIndentation|rulers|wordWrap|wordWrapColumn|trimAutoWhitespace|renderWhitespace)|files\.(eol|insertFinalNewline|trimFinalNewlines|trimTrailingWhitespace|encoding|autoGuessEncoding)|csharpier\..*|prettier\..*)$/;
4
+ const EXTENSION_ID = /^[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*$/;
5
+ const SETTINGS = ".vscode/settings.json";
6
+ const EXTENSIONS = ".vscode/extensions.json";
7
+ export function isStyleKey(key) {
8
+ return STYLE_KEY.test(key) && !TOOL_PATHS.has(key);
9
+ }
10
+ function keys(value) {
11
+ return Object.entries(value).flatMap(([key, inner]) => (key.startsWith("[") && isRecord(inner) ? [key, ...keys(inner)] : [key]));
12
+ }
13
+ function notJson(file) {
14
+ return { target: file, message: "not valid JSON (comments and trailing commas included): fix the file so every tool can read it" };
15
+ }
16
+ function settingsFindings(text) {
17
+ const settings = parseJson(text);
18
+ if (!isRecord(settings))
19
+ return [notJson(SETTINGS)];
20
+ return keys(settings)
21
+ .filter(isStyleKey)
22
+ .map((key) => ({
23
+ target: SETTINGS,
24
+ message: `${key} is a style rule only VS Code reads: move it to .editorconfig, .prettierrc.json or .csharpierrc.json so every editor and the gate use it`,
25
+ }));
26
+ }
27
+ function extensionFindings(text) {
28
+ const parsed = parseJson(text);
29
+ const ids = isRecord(parsed) && Array.isArray(parsed["recommendations"]) ? parsed["recommendations"] : null;
30
+ if (ids === null)
31
+ return [notJson(EXTENSIONS)];
32
+ return ids
33
+ .filter((id, index) => typeof id !== "string" || !EXTENSION_ID.test(id) || ids.indexOf(id) !== index)
34
+ .map((id) => ({
35
+ target: EXTENSIONS,
36
+ message: `${JSON.stringify(id)}: write each id once, as publisher.name in lower case (the Marketplace id from the extension's page)`,
37
+ }));
38
+ }
39
+ export const vsCodeSettings = {
40
+ id: "vscode-settings",
41
+ description: "The VS Code settings hold glue and no style rules, and every recommended extension id is well formed and listed once",
42
+ profiles: "every",
43
+ check(context) {
44
+ return [
45
+ ...(context.files.includes(SETTINGS) ? settingsFindings(context.read(SETTINGS)) : []),
46
+ ...(context.files.includes(EXTENSIONS) ? extensionFindings(context.read(EXTENSIONS)) : []),
47
+ ];
48
+ },
49
+ };
@@ -0,0 +1,5 @@
1
+ import type { Step, StepContext } from "../gate/contract.ts";
2
+ export declare const API_CONTRACT = "api-contract";
3
+ export declare function apiContract(context: StepContext): string | null;
4
+ export declare function contractPins(context: StepContext): string | null;
5
+ export declare const contractSteps: readonly Step[];