@maniumek/suwgate 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +149 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +97 -0
- package/dist/dev/checkoutEnv.d.ts +20 -0
- package/dist/dev/checkoutEnv.js +101 -0
- package/dist/dev/db.d.ts +25 -0
- package/dist/dev/db.js +103 -0
- package/dist/dev/index.d.ts +16 -0
- package/dist/dev/index.js +108 -0
- package/dist/dev/logs.d.ts +15 -0
- package/dist/dev/logs.js +127 -0
- package/dist/dev/process.d.ts +24 -0
- package/dist/dev/process.js +34 -0
- package/dist/dev/server.d.ts +8 -0
- package/dist/dev/server.js +61 -0
- package/dist/dev/settings.d.ts +46 -0
- package/dist/dev/settings.js +160 -0
- package/dist/dev/smoke.d.ts +15 -0
- package/dist/dev/smoke.js +50 -0
- package/dist/dev/testing.d.ts +19 -0
- package/dist/dev/testing.js +18 -0
- package/dist/dev/tmux.d.ts +24 -0
- package/dist/dev/tmux.js +121 -0
- package/dist/eslint/index.d.ts +17 -0
- package/dist/eslint/index.js +91 -0
- package/dist/eslint/noComments.d.ts +2 -0
- package/dist/eslint/noComments.js +27 -0
- package/dist/gate/check.d.ts +13 -0
- package/dist/gate/check.js +49 -0
- package/dist/gate/config.d.ts +34 -0
- package/dist/gate/config.js +170 -0
- package/dist/gate/contract.d.ts +51 -0
- package/dist/gate/contract.js +1 -0
- package/dist/gate/guardsStep.d.ts +14 -0
- package/dist/gate/guardsStep.js +53 -0
- package/dist/gate/plan.d.ts +29 -0
- package/dist/gate/plan.js +86 -0
- package/dist/gate/report.d.ts +15 -0
- package/dist/gate/report.js +65 -0
- package/dist/gate/repository.d.ts +3 -0
- package/dist/gate/repository.js +37 -0
- package/dist/gate/runner.d.ts +10 -0
- package/dist/gate/runner.js +75 -0
- package/dist/guards/comments/csharp.d.ts +3 -0
- package/dist/guards/comments/csharp.js +163 -0
- package/dist/guards/comments/css.d.ts +3 -0
- package/dist/guards/comments/css.js +11 -0
- package/dist/guards/comments/eslint.d.ts +2 -0
- package/dist/guards/comments/eslint.js +81 -0
- package/dist/guards/comments/hash.d.ts +3 -0
- package/dist/guards/comments/hash.js +72 -0
- package/dist/guards/comments/index.d.ts +2 -0
- package/dist/guards/comments/index.js +18 -0
- package/dist/guards/comments/json.d.ts +3 -0
- package/dist/guards/comments/json.js +13 -0
- package/dist/guards/comments/markup.d.ts +3 -0
- package/dist/guards/comments/markup.js +14 -0
- package/dist/guards/comments/scan.d.ts +19 -0
- package/dist/guards/comments/scan.js +84 -0
- package/dist/guards/comments/sql.d.ts +3 -0
- package/dist/guards/comments/sql.js +11 -0
- package/dist/guards/comments/switches.d.ts +3 -0
- package/dist/guards/comments/switches.js +30 -0
- package/dist/guards/criteria/criteriaKinds.d.ts +2 -0
- package/dist/guards/criteria/criteriaKinds.js +45 -0
- package/dist/guards/criteria/index.d.ts +2 -0
- package/dist/guards/criteria/index.js +2 -0
- package/dist/guards/database/connectionHost.d.ts +2 -0
- package/dist/guards/database/connectionHost.js +30 -0
- package/dist/guards/database/index.d.ts +2 -0
- package/dist/guards/database/index.js +3 -0
- package/dist/guards/database/migrationsUnchanged.d.ts +2 -0
- package/dist/guards/database/migrationsUnchanged.js +56 -0
- package/dist/guards/dotnet/appsettingsBound.d.ts +2 -0
- package/dist/guards/dotnet/appsettingsBound.js +43 -0
- package/dist/guards/dotnet/bannedNugetPackages.d.ts +2 -0
- package/dist/guards/dotnet/bannedNugetPackages.js +51 -0
- package/dist/guards/dotnet/index.d.ts +2 -0
- package/dist/guards/dotnet/index.js +4 -0
- package/dist/guards/dotnet/msbuild.d.ts +5 -0
- package/dist/guards/dotnet/msbuild.js +17 -0
- package/dist/guards/dotnet/testContext.d.ts +2 -0
- package/dist/guards/dotnet/testContext.js +12 -0
- package/dist/guards/dotnet/unusedNugetVersions.d.ts +2 -0
- package/dist/guards/dotnet/unusedNugetVersions.js +21 -0
- package/dist/guards/index.d.ts +2 -0
- package/dist/guards/index.js +6 -0
- package/dist/guards/repository/agentsFile.d.ts +3 -0
- package/dist/guards/repository/agentsFile.js +56 -0
- package/dist/guards/repository/bannedNpmPackages.d.ts +2 -0
- package/dist/guards/repository/bannedNpmPackages.js +43 -0
- package/dist/guards/repository/composePorts.d.ts +6 -0
- package/dist/guards/repository/composePorts.js +57 -0
- package/dist/guards/repository/dependencyDirection.d.ts +2 -0
- package/dist/guards/repository/dependencyDirection.js +87 -0
- package/dist/guards/repository/docsPaths.d.ts +2 -0
- package/dist/guards/repository/docsPaths.js +54 -0
- package/dist/guards/repository/forbiddenNames.d.ts +4 -0
- package/dist/guards/repository/forbiddenNames.js +69 -0
- package/dist/guards/repository/hooks.d.ts +3 -0
- package/dist/guards/repository/hooks.js +86 -0
- package/dist/guards/repository/imagePins.d.ts +3 -0
- package/dist/guards/repository/imagePins.js +68 -0
- package/dist/guards/repository/index.d.ts +2 -0
- package/dist/guards/repository/index.js +32 -0
- package/dist/guards/repository/justModules.d.ts +2 -0
- package/dist/guards/repository/justModules.js +36 -0
- package/dist/guards/repository/noRawColors.d.ts +2 -0
- package/dist/guards/repository/noRawColors.js +29 -0
- package/dist/guards/repository/packageManifests.d.ts +13 -0
- package/dist/guards/repository/packageManifests.js +26 -0
- package/dist/guards/repository/repositoryLayout.d.ts +3 -0
- package/dist/guards/repository/repositoryLayout.js +75 -0
- package/dist/guards/repository/requiredFiles.d.ts +6 -0
- package/dist/guards/repository/requiredFiles.js +86 -0
- package/dist/guards/repository/scriptsCalled.d.ts +3 -0
- package/dist/guards/repository/scriptsCalled.js +39 -0
- package/dist/guards/repository/scriptsHelp.d.ts +2 -0
- package/dist/guards/repository/scriptsHelp.js +37 -0
- package/dist/guards/repository/testRepository.d.ts +4 -0
- package/dist/guards/repository/testRepository.js +39 -0
- package/dist/guards/repository/text.d.ts +20 -0
- package/dist/guards/repository/text.js +33 -0
- package/dist/guards/repository/vsCodeSettings.d.ts +3 -0
- package/dist/guards/repository/vsCodeSettings.js +49 -0
- package/dist/profiles/contract.d.ts +5 -0
- package/dist/profiles/contract.js +124 -0
- package/dist/profiles/criteria.d.ts +25 -0
- package/dist/profiles/criteria.js +162 -0
- package/dist/profiles/database.d.ts +4 -0
- package/dist/profiles/database.js +23 -0
- package/dist/profiles/dotnet.d.ts +5 -0
- package/dist/profiles/dotnet.js +56 -0
- package/dist/profiles/everyRepository.d.ts +2 -0
- package/dist/profiles/everyRepository.js +32 -0
- package/dist/profiles/index.d.ts +2 -0
- package/dist/profiles/index.js +21 -0
- package/dist/profiles/library.d.ts +7 -0
- package/dist/profiles/library.js +132 -0
- package/dist/profiles/node.d.ts +5 -0
- package/dist/profiles/node.js +79 -0
- package/dist/profiles/presets/knip.d.ts +11 -0
- package/dist/profiles/presets/knip.js +29 -0
- package/dist/profiles/presets/playwright.d.ts +68 -0
- package/dist/profiles/presets/playwright.js +37 -0
- package/dist/profiles/presets/prettier.d.ts +12 -0
- package/dist/profiles/presets/prettier.js +7 -0
- package/dist/profiles/presets/tsconfig/browser.json +11 -0
- package/dist/profiles/presets/tsconfig/node.json +8 -0
- package/dist/profiles/presets/tsconfig/strict.json +17 -0
- package/dist/profiles/presets/vitest.d.ts +36 -0
- package/dist/profiles/presets/vitest.js +16 -0
- package/dist/profiles/shell.d.ts +10 -0
- package/dist/profiles/shell.js +62 -0
- package/dist/profiles/web.d.ts +2 -0
- package/dist/profiles/web.js +17 -0
- package/dist/session/guardEdit.d.ts +19 -0
- package/dist/session/guardEdit.js +98 -0
- package/dist/session/preCommit.d.ts +16 -0
- package/dist/session/preCommit.js +33 -0
- package/dist/session/stop.d.ts +8 -0
- package/dist/session/stop.js +39 -0
- package/package.json +97 -3
- 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,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,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,86 @@
|
|
|
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 (prettier.config.js instead, when a plugin needs the preset spread)",
|
|
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
|
+
const ALTERNATIVES = {
|
|
48
|
+
".prettierrc.json": ["prettier.config.js"],
|
|
49
|
+
};
|
|
50
|
+
function isPresent(file, present) {
|
|
51
|
+
const directory = file.slice(0, file.lastIndexOf("/") + 1);
|
|
52
|
+
const name = file.slice(directory.length);
|
|
53
|
+
return [name, ...(ALTERNATIVES[name] ?? [])].some((candidate) => present.has(directory + candidate));
|
|
54
|
+
}
|
|
55
|
+
function required(context, settings) {
|
|
56
|
+
const files = new Map();
|
|
57
|
+
for (const [file, purpose] of Object.entries(EVERY_REPOSITORY))
|
|
58
|
+
files.set(file, `${purpose}. Every repository needs it: add it`);
|
|
59
|
+
for (const profile of PROFILES.filter((candidate) => context.profiles.includes(candidate))) {
|
|
60
|
+
for (const [file, purpose] of Object.entries(REQUIRED_BY_PROFILE[profile])) {
|
|
61
|
+
const placed = inProfileDirectory(context.directories, profile, file);
|
|
62
|
+
if (!files.has(placed))
|
|
63
|
+
files.set(placed, `${purpose}. The ${profile} profile needs it: add it`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const file of settings.files ?? []) {
|
|
67
|
+
if (!files.has(file))
|
|
68
|
+
files.set(file, "settings.required-files.files in suwgate.yml asks for it: add it");
|
|
69
|
+
}
|
|
70
|
+
return files;
|
|
71
|
+
}
|
|
72
|
+
export const requiredFiles = {
|
|
73
|
+
id: "required-files",
|
|
74
|
+
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)",
|
|
75
|
+
profiles: "every",
|
|
76
|
+
settingsSchema: { type: "object", additionalProperties: false, properties: { files: stringList } },
|
|
77
|
+
check(context) {
|
|
78
|
+
const present = new Set(context.files);
|
|
79
|
+
return [...required(context, (context.settings ?? {}))]
|
|
80
|
+
.filter(([file]) => !isPresent(file, present))
|
|
81
|
+
.map(([file, purpose]) => ({
|
|
82
|
+
target: file,
|
|
83
|
+
message: `missing: ${purpose}, or add an exception with the reason it does not apply`,
|
|
84
|
+
}));
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -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,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,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[];
|