@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.
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 +86 -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 +98 -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,79 @@
1
+ import { changedIn, filesIn, has, read, withChanged } from "./shell.js";
2
+ const CODE = /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts)$/;
3
+ const TSCONFIG = /^tsconfig(\..+)?\.json$/;
4
+ const VITEST_CONFIG = /^vitest\.config\.(ts|mts|js|mjs)$/;
5
+ const UNIT_PROJECT = /\bname:\s*["'`]unit["'`]|\bunitTests\(/;
6
+ export const PNPM_INSTALL = "pnpm-install";
7
+ function install(context) {
8
+ return has(context, "node_modules") ? null : "pnpm install --frozen-lockfile --silent";
9
+ }
10
+ export function typecheck(context) {
11
+ const configs = filesIn(context, TSCONFIG).filter((file) => file !== "tsconfig.build.json");
12
+ const ordered = [...configs.filter((file) => file === "tsconfig.json"), ...configs.filter((file) => file !== "tsconfig.json")];
13
+ return (ordered.length === 0 ? ["tsconfig.json"] : ordered).map((file) => `pnpm exec tsc --noEmit -p ${file}`).join(" && ");
14
+ }
15
+ export function unitTests(context) {
16
+ const named = filesIn(context, VITEST_CONFIG).some((file) => UNIT_PROJECT.test(read(context, file) ?? ""));
17
+ return named ? "pnpm exec vitest run --project unit" : "pnpm exec vitest run";
18
+ }
19
+ export function nodeSteps(profile) {
20
+ const after = [PNPM_INSTALL];
21
+ return [
22
+ {
23
+ id: PNPM_INSTALL,
24
+ title: "packages from the lockfile when node_modules is missing (pnpm install --frozen-lockfile)",
25
+ profile,
26
+ needs: ["pnpm"],
27
+ run: install,
28
+ quick: install,
29
+ limitSeconds: 300,
30
+ },
31
+ {
32
+ id: "typecheck",
33
+ title: "typecheck (tsc, every tsconfig*.json but the build one)",
34
+ profile,
35
+ needs: ["pnpm"],
36
+ after,
37
+ run: typecheck,
38
+ quick: (context) => (changedIn(context, CODE).length === 0 ? null : typecheck(context)),
39
+ limitSeconds: 180,
40
+ },
41
+ {
42
+ id: "lint",
43
+ title: "lint (eslint)",
44
+ profile,
45
+ needs: ["pnpm"],
46
+ after,
47
+ run: "pnpm exec eslint . --max-warnings 0",
48
+ quick: (context) => withChanged(context, CODE, "pnpm exec eslint --no-warn-ignored --max-warnings 0"),
49
+ limitSeconds: 300,
50
+ },
51
+ {
52
+ id: "unit-tests",
53
+ title: "unit tests (vitest, the project unit when the config has several)",
54
+ profile,
55
+ needs: ["pnpm"],
56
+ after,
57
+ run: unitTests,
58
+ limitSeconds: 300,
59
+ },
60
+ {
61
+ id: "format",
62
+ title: "format (prettier --check)",
63
+ profile,
64
+ needs: ["pnpm"],
65
+ after,
66
+ run: "pnpm exec prettier --check --log-level warn .",
67
+ limitSeconds: 180,
68
+ },
69
+ {
70
+ id: "knip",
71
+ title: "dead code and unused dependencies (knip)",
72
+ profile,
73
+ needs: ["pnpm"],
74
+ after,
75
+ run: "pnpm exec knip",
76
+ limitSeconds: 180,
77
+ },
78
+ ];
79
+ }
@@ -0,0 +1,11 @@
1
+ export interface KnipConfig {
2
+ ignore?: string[];
3
+ ignoreDependencies?: string[];
4
+ playwright?: {
5
+ config?: string[];
6
+ };
7
+ [key: string]: unknown;
8
+ }
9
+ export declare function knip(config?: KnipConfig, directory?: string): KnipConfig;
10
+ declare const _default: KnipConfig;
11
+ export default _default;
@@ -0,0 +1,29 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ const STEP_TOOLS = ["publint", "@arethetypeswrong/cli", "openapi-typescript"];
4
+ const GENERATED = ["src/api/openapi.d.ts"];
5
+ const PLAYWRIGHT_CONFIGS = ["e2e/playwright.config.ts", "visual/playwright.config.ts", "gate/consumer/playwright.config.ts"];
6
+ function dependencies(directory) {
7
+ try {
8
+ const manifest = JSON.parse(readFileSync(path.join(directory, "package.json"), "utf8"));
9
+ return ["dependencies", "devDependencies"].flatMap((field) => {
10
+ const listed = manifest[field];
11
+ return listed !== null && typeof listed === "object" ? Object.keys(listed) : [];
12
+ });
13
+ }
14
+ catch {
15
+ return [];
16
+ }
17
+ }
18
+ export function knip(config = {}, directory = process.cwd()) {
19
+ const present = (file) => existsSync(path.join(directory, file));
20
+ const installed = dependencies(directory);
21
+ const playwrightConfigs = [...PLAYWRIGHT_CONFIGS.filter(present), ...(config.playwright?.config ?? [])];
22
+ return {
23
+ ...config,
24
+ ignore: [...GENERATED.filter(present), ...(config.ignore ?? [])],
25
+ ignoreDependencies: [...STEP_TOOLS.filter((tool) => installed.includes(tool)), ...(config.ignoreDependencies ?? [])],
26
+ ...(playwrightConfigs.length === 0 ? {} : { playwright: { ...config.playwright, config: playwrightConfigs } }),
27
+ };
28
+ }
29
+ export default knip();
@@ -0,0 +1,68 @@
1
+ interface Use {
2
+ baseURL?: string;
3
+ [key: string]: unknown;
4
+ }
5
+ interface PlaywrightConfig {
6
+ use?: Use;
7
+ [key: string]: unknown;
8
+ }
9
+ export declare function e2eTests<Config extends PlaywrightConfig>(config: Config): {
10
+ testDir: string;
11
+ testMatch: string;
12
+ workers: number;
13
+ retries: number;
14
+ failOnFlakyTests: boolean;
15
+ reporter: "list";
16
+ timeout: number;
17
+ projects: {
18
+ name: string;
19
+ use: {
20
+ browserName: "chromium";
21
+ viewport: {
22
+ width: number;
23
+ height: number;
24
+ };
25
+ };
26
+ }[];
27
+ } & Config & {
28
+ use: {
29
+ baseURL?: string;
30
+ locale: string;
31
+ trace: "retain-on-failure";
32
+ screenshot: "only-on-failure";
33
+ };
34
+ };
35
+ export declare function visualTests({ port }?: {
36
+ port?: number;
37
+ }): {
38
+ testDir: string;
39
+ testMatch: string;
40
+ outputDir: string;
41
+ snapshotPathTemplate: string;
42
+ reporter: "line";
43
+ fullyParallel: boolean;
44
+ expect: {
45
+ toHaveScreenshot: {
46
+ maxDiffPixelRatio: number;
47
+ };
48
+ };
49
+ use: {
50
+ baseURL: string;
51
+ };
52
+ projects: {
53
+ name: string;
54
+ use: {
55
+ viewport: {
56
+ width: number;
57
+ height: number;
58
+ };
59
+ };
60
+ }[];
61
+ webServer: {
62
+ command: string;
63
+ url: string;
64
+ cwd: string;
65
+ reuseExistingServer: boolean;
66
+ };
67
+ };
68
+ export {};
@@ -0,0 +1,37 @@
1
+ const ci = () => Boolean(process.env["CI"]);
2
+ export function e2eTests(config) {
3
+ return {
4
+ testDir: "../src",
5
+ testMatch: "**/*.e2e.ts",
6
+ workers: 1,
7
+ retries: ci() ? 1 : 0,
8
+ failOnFlakyTests: ci(),
9
+ reporter: "list",
10
+ timeout: 60_000,
11
+ projects: [{ name: "chromium", use: { browserName: "chromium", viewport: { width: 1440, height: 900 } } }],
12
+ ...config,
13
+ use: { locale: "en-US", trace: "retain-on-failure", screenshot: "only-on-failure", ...config.use },
14
+ };
15
+ }
16
+ export function visualTests({ port = 6007 } = {}) {
17
+ return {
18
+ testDir: ".",
19
+ testMatch: "*.visual.ts",
20
+ outputDir: "results",
21
+ snapshotPathTemplate: "{testDir}/snapshots/{projectName}/{arg}{ext}",
22
+ reporter: "line",
23
+ fullyParallel: true,
24
+ expect: { toHaveScreenshot: { maxDiffPixelRatio: 0.001 } },
25
+ use: { baseURL: `http://127.0.0.1:${port}` },
26
+ projects: [
27
+ { name: "1920x1080", use: { viewport: { width: 1920, height: 1080 } } },
28
+ { name: "3440x1440", use: { viewport: { width: 3440, height: 1440 } } },
29
+ ],
30
+ webServer: {
31
+ command: `node_modules/.bin/vite preview --outDir storybook-static --host 127.0.0.1 --port ${port} --strictPort`,
32
+ url: `http://127.0.0.1:${port}/iframe.html`,
33
+ cwd: "..",
34
+ reuseExistingServer: false,
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,12 @@
1
+ declare const prettier: {
2
+ readonly printWidth: 140;
3
+ readonly tabWidth: 4;
4
+ readonly trailingComma: "all";
5
+ readonly overrides: readonly [{
6
+ readonly files: readonly ["*.yaml", "*.yml"];
7
+ readonly options: {
8
+ readonly tabWidth: 2;
9
+ };
10
+ }];
11
+ };
12
+ export default prettier;
@@ -0,0 +1,7 @@
1
+ const prettier = {
2
+ printWidth: 140,
3
+ tabWidth: 4,
4
+ trailingComma: "all",
5
+ overrides: [{ files: ["*.yaml", "*.yml"], options: { tabWidth: 2 } }],
6
+ };
7
+ export default prettier;
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./strict.json",
3
+ "compilerOptions": {
4
+ "target": "ES2022",
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "moduleResolution": "bundler",
8
+ "jsx": "react-jsx",
9
+ "types": ["vite/client"]
10
+ }
11
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./browser.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2022", "DOM"],
5
+ "types": ["node"],
6
+ "allowImportingTsExtensions": true
7
+ }
8
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "noUnusedLocals": true,
5
+ "noUnusedParameters": true,
6
+ "noUncheckedIndexedAccess": true,
7
+ "exactOptionalPropertyTypes": true,
8
+ "noImplicitOverride": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "noPropertyAccessFromIndexSignature": true,
12
+ "verbatimModuleSyntax": true,
13
+ "skipLibCheck": true,
14
+ "noEmit": true,
15
+ "isolatedModules": true
16
+ }
17
+ }
@@ -0,0 +1,36 @@
1
+ interface UnitOptions {
2
+ extends?: string;
3
+ environment?: string;
4
+ globals?: boolean;
5
+ include?: string[];
6
+ }
7
+ interface StoryOptions<Plugin, Provider> {
8
+ extends?: string;
9
+ plugin: Plugin;
10
+ provider: Provider;
11
+ }
12
+ export declare function unitTests({ extends: base, ...test }?: UnitOptions): {
13
+ test: {
14
+ environment?: string;
15
+ globals?: boolean;
16
+ include: string[];
17
+ name: string;
18
+ };
19
+ extends?: string;
20
+ };
21
+ export declare function storyTests<Plugin, Provider>({ extends: base, plugin, provider }: StoryOptions<Plugin, Provider>): {
22
+ plugins: Plugin[];
23
+ test: {
24
+ name: string;
25
+ browser: {
26
+ enabled: boolean;
27
+ provider: Provider;
28
+ headless: boolean;
29
+ instances: {
30
+ browser: "chromium";
31
+ }[];
32
+ };
33
+ };
34
+ extends?: string;
35
+ };
36
+ export {};
@@ -0,0 +1,16 @@
1
+ export function unitTests({ extends: base, ...test } = {}) {
2
+ return {
3
+ ...(base === undefined ? {} : { extends: base }),
4
+ test: { name: "unit", include: ["src/**/*.test.{ts,tsx}"], ...test },
5
+ };
6
+ }
7
+ export function storyTests({ extends: base, plugin, provider }) {
8
+ return {
9
+ ...(base === undefined ? {} : { extends: base }),
10
+ plugins: [plugin],
11
+ test: {
12
+ name: "stories",
13
+ browser: { enabled: true, provider, headless: true, instances: [{ browser: "chromium" }] },
14
+ },
15
+ };
16
+ }
@@ -0,0 +1,10 @@
1
+ import type { StepContext } from "../gate/contract.ts";
2
+ export declare function quoted(argument: string): string;
3
+ export declare function changedIn(context: StepContext, pattern: RegExp): string[];
4
+ export declare function withChanged(context: StepContext, pattern: RegExp, command: string): string | null;
5
+ export declare function has(context: StepContext, file: string): boolean;
6
+ export declare function filesIn(context: StepContext, pattern: RegExp): string[];
7
+ export declare function read(context: StepContext, file: string): string | null;
8
+ export declare function tracked(context: StepContext, pathspecs: readonly string[]): string[];
9
+ export declare function script(lines: readonly string[]): string;
10
+ export declare function onPath(tool: string): boolean;
@@ -0,0 +1,62 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { accessSync, constants, existsSync, readdirSync, readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ export function quoted(argument) {
5
+ return `'${argument.replaceAll("'", `'"'"'`)}'`;
6
+ }
7
+ export function changedIn(context, pattern) {
8
+ const prefix = path.relative(context.root, context.cwd);
9
+ return context
10
+ .changed()
11
+ .filter((file) => prefix === "" || file.startsWith(`${prefix}/`))
12
+ .map((file) => (prefix === "" ? file : file.slice(prefix.length + 1)))
13
+ .filter((file) => pattern.test(file));
14
+ }
15
+ export function withChanged(context, pattern, command) {
16
+ const files = changedIn(context, pattern);
17
+ return files.length === 0 ? null : `${command} ${files.map(quoted).join(" ")}`;
18
+ }
19
+ export function has(context, file) {
20
+ return existsSync(path.join(context.cwd, file));
21
+ }
22
+ export function filesIn(context, pattern) {
23
+ return readdirSync(context.cwd)
24
+ .filter((file) => pattern.test(file))
25
+ .sort();
26
+ }
27
+ export function read(context, file) {
28
+ try {
29
+ return readFileSync(path.join(context.cwd, file), "utf8");
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ export function tracked(context, pathspecs) {
36
+ try {
37
+ return execFileSync("git", ["ls-files", "--cached", "--others", "--exclude-standard", "-z", "--", ...pathspecs], {
38
+ cwd: context.cwd,
39
+ encoding: "utf8",
40
+ stdio: ["ignore", "pipe", "ignore"],
41
+ })
42
+ .split("\0")
43
+ .filter((file) => file !== "" && existsSync(path.join(context.cwd, file)));
44
+ }
45
+ catch {
46
+ return [];
47
+ }
48
+ }
49
+ export function script(lines) {
50
+ return lines.join("\n");
51
+ }
52
+ export function onPath(tool) {
53
+ return (process.env["PATH"] ?? "").split(path.delimiter).some((folder) => {
54
+ try {
55
+ accessSync(path.join(folder, tool), constants.X_OK);
56
+ return true;
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ });
62
+ }
@@ -0,0 +1,2 @@
1
+ import type { Step } from "../gate/contract.ts";
2
+ export declare const webSteps: readonly Step[];
@@ -0,0 +1,17 @@
1
+ import { API_CONTRACT } from "./contract.js";
2
+ import { DATABASE_UP } from "./database.js";
3
+ import { DOTNET_BUILD, DOTNET_TEST } from "./dotnet.js";
4
+ import { PNPM_INSTALL } from "./node.js";
5
+ import { has } from "./shell.js";
6
+ const E2E_CONFIG = "e2e/playwright.config.ts";
7
+ export const webSteps = [
8
+ {
9
+ id: "e2e",
10
+ title: `browser tests against the real server and database (playwright, ${E2E_CONFIG})`,
11
+ profile: "web",
12
+ needs: ["pnpm"],
13
+ after: [PNPM_INSTALL, DOTNET_BUILD, DATABASE_UP, DOTNET_TEST, API_CONTRACT],
14
+ run: (context) => (has(context, E2E_CONFIG) ? `pnpm exec playwright test -c ${E2E_CONFIG}` : null),
15
+ limitSeconds: 600,
16
+ },
17
+ ];
@@ -0,0 +1,19 @@
1
+ export interface EditHookSettings {
2
+ protected?: string[];
3
+ generated?: {
4
+ path: string;
5
+ command: string;
6
+ }[];
7
+ recordings?: string[];
8
+ migrations?: string[];
9
+ }
10
+ export interface EditHookProject {
11
+ root: string;
12
+ profiles: readonly string[];
13
+ settings: EditHookSettings;
14
+ }
15
+ export interface Verdict {
16
+ exitCode: 0 | 2;
17
+ message: string;
18
+ }
19
+ export declare function guardEdit(input: string, project: EditHookProject, allowGateEdit: boolean): Verdict;
@@ -0,0 +1,98 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ const NODE_GATE = [
5
+ "**/eslint.config.{js,mjs,ts}",
6
+ "**/eslint.config.test.js",
7
+ "**/tsconfig*.json",
8
+ "**/vitest.config.ts",
9
+ "**/playwright.config.ts",
10
+ "**/knip.json",
11
+ "**/knip.config.{ts,js}",
12
+ "**/.prettierrc.json",
13
+ "**/prettier.config.{js,mjs,ts}",
14
+ ];
15
+ const LISTS = {
16
+ every: {
17
+ gate: ["suwgate.yml", "criteria.json", ".claude/settings.json", ".github/workflows/**", ".githooks/**", "**/.editorconfig"],
18
+ generated: { "**/pnpm-lock.yaml": "a generated lockfile: change package.json and run pnpm install" },
19
+ },
20
+ web: {
21
+ gate: NODE_GATE,
22
+ generated: {
23
+ "**/openapi.d.ts": "generated from the server's API contract: regenerate it with the command that generates the API types",
24
+ },
25
+ },
26
+ library: { gate: [...NODE_GATE, ".changeset/config.json", "**/.storybook/**"] },
27
+ dotnet: {
28
+ gate: ["**/Directory.Build.props", "**/Directory.Build.targets", "**/BannedSymbols.txt", "**/layers.json"],
29
+ generated: {
30
+ "**/packages.lock.json": "a generated lockfile: change Directory.Packages.props and run dotnet restore",
31
+ "**/contract/openapi.json": "generated from the server's endpoints: regenerate it with the command that generates the API contract",
32
+ },
33
+ recordings: ["**/Characterization/**"],
34
+ },
35
+ database: { migrations: ["**/Database/Migrations/up/**"] },
36
+ };
37
+ const allowed = { exitCode: 0, message: "" };
38
+ const ASK_THE_OWNER = "Do not work around it: ask the user to start a session with ALLOW_GATE_EDIT=1 claude and give them the exact change to make there (the file, what to change, why).";
39
+ function editedPath(input) {
40
+ try {
41
+ const parsed = JSON.parse(input);
42
+ const file = parsed.tool_input?.file_path ?? parsed.tool_input?.notebook_path;
43
+ return typeof file === "string" && file.length > 0 ? path.posix.normalize(file.replaceAll("\\", "/")) : null;
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ function listsOf(project) {
50
+ const parts = ["every", ...project.profiles].map((name) => LISTS[name] ?? {});
51
+ const { settings } = project;
52
+ return {
53
+ gate: [...parts.flatMap((part) => part.gate ?? []), ...(settings.protected ?? [])],
54
+ generated: Object.assign({}, ...parts.map((part) => part.generated ?? {}), ...(settings.generated ?? []).map((entry) => ({
55
+ [entry.path]: `generated: regenerate it with ${entry.command} instead of editing it`,
56
+ }))),
57
+ recordings: [...parts.flatMap((part) => part.recordings ?? []), ...(settings.recordings ?? [])],
58
+ migrations: [...parts.flatMap((part) => part.migrations ?? []), ...(settings.migrations ?? [])],
59
+ };
60
+ }
61
+ function matches(relative, globs) {
62
+ return globs.some((glob) => path.posix.matchesGlob(relative, glob));
63
+ }
64
+ function isTracked(root, relative) {
65
+ try {
66
+ execFileSync("git", ["ls-files", "--error-unmatch", "--", relative], { cwd: root, stdio: "ignore" });
67
+ return true;
68
+ }
69
+ catch {
70
+ return false;
71
+ }
72
+ }
73
+ function blocked(...lines) {
74
+ return { exitCode: 2, message: lines.join("\n") };
75
+ }
76
+ export function guardEdit(input, project, allowGateEdit) {
77
+ const file = editedPath(input);
78
+ const root = path.posix.normalize(project.root.replaceAll("\\", "/")).replace(/\/+$/, "");
79
+ if (!file?.startsWith(`${root}/`))
80
+ return allowed;
81
+ const relative = file.slice(root.length + 1);
82
+ const lists = listsOf(project);
83
+ if (matches(relative, lists.migrations) && existsSync(file)) {
84
+ return blocked(`Blocked: ${relative} is a migration that already exists; the migrator refuses to start when a script changes after it ran.`, "Add a new script with the next free number instead (NNNN_what_it_does.sql).");
85
+ }
86
+ const generated = Object.entries(lists.generated).find(([glob]) => path.posix.matchesGlob(relative, glob));
87
+ if (generated !== undefined)
88
+ return blocked(`Blocked: ${relative} is ${generated[1]}.`);
89
+ if (allowGateEdit)
90
+ return allowed;
91
+ if (matches(relative, lists.gate)) {
92
+ return blocked(`Blocked: ${relative} is part of the gate (suwgate.yml, a hook, a lint, type or build config), which an agent does not change on its own.`, ASK_THE_OWNER);
93
+ }
94
+ if (matches(relative, lists.recordings) && isTracked(root, relative)) {
95
+ return blocked(`Blocked: ${relative} records behaviour as it is today (a characterization test); an agent changes the code until the recording passes again, not the recording.`, ASK_THE_OWNER);
96
+ }
97
+ return allowed;
98
+ }
@@ -0,0 +1,16 @@
1
+ export interface ToolResult {
2
+ missing: boolean;
3
+ exitCode: number;
4
+ text: string;
5
+ }
6
+ export type RunTool = (command: string, args: readonly string[], cwd: string) => Promise<ToolResult>;
7
+ export interface PreCommitVerdict {
8
+ exitCode: 0 | 1;
9
+ message: string;
10
+ }
11
+ export declare const GITLEAKS_ARGS: readonly ["git", "--pre-commit", "--staged", "--no-banner", "--redact", "--log-level", "warn"];
12
+ export declare const runTool: RunTool;
13
+ export declare function preCommit(root: string, run: RunTool, quickCheck: () => Promise<{
14
+ exitCode: number;
15
+ text: string;
16
+ }>): Promise<PreCommitVerdict>;
@@ -0,0 +1,33 @@
1
+ import { spawn } from "node:child_process";
2
+ export const GITLEAKS_ARGS = ["git", "--pre-commit", "--staged", "--no-banner", "--redact", "--log-level", "warn"];
3
+ export const runTool = (command, args, cwd) => new Promise((resolve) => {
4
+ const child = spawn(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
5
+ let text = "";
6
+ child.stdout.on("data", (chunk) => (text += chunk.toString("utf8")));
7
+ child.stderr.on("data", (chunk) => (text += chunk.toString("utf8")));
8
+ child.on("error", (error) => resolve({ missing: error.code === "ENOENT", exitCode: 1, text: error.message }));
9
+ child.on("close", (code) => resolve({ missing: false, exitCode: code ?? 1, text }));
10
+ });
11
+ export async function preCommit(root, run, quickCheck) {
12
+ const leaks = await run("gitleaks", GITLEAKS_ARGS, root);
13
+ if (leaks.missing) {
14
+ return {
15
+ exitCode: 1,
16
+ message: "pre-commit: gitleaks not found, so the staged changes cannot be checked for secrets: install it (https://github.com/gitleaks/gitleaks); commit refused",
17
+ };
18
+ }
19
+ if (leaks.exitCode !== 0) {
20
+ return {
21
+ exitCode: 1,
22
+ message: `${leaks.text.trimEnd()}\npre-commit: possible secret in the staged changes (above): remove it, and rotate it if it is real; commit refused`,
23
+ };
24
+ }
25
+ const quick = await quickCheck();
26
+ if (quick.exitCode !== 0) {
27
+ return {
28
+ exitCode: 1,
29
+ message: `${quick.text.trimEnd()}\npre-commit: the quick gate is red (above): fix it before committing; commit refused`,
30
+ };
31
+ }
32
+ return { exitCode: 0, message: "" };
33
+ }
@@ -0,0 +1,8 @@
1
+ export interface StopVerdict {
2
+ exitCode: 0 | 2;
3
+ message: string;
4
+ }
5
+ export declare function stop(input: string, root: string, quickCheck: () => Promise<{
6
+ exitCode: number;
7
+ text: string;
8
+ }>): Promise<StopVerdict>;
@@ -0,0 +1,39 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
+ import path from "node:path";
5
+ const SHOWN_LINES = 60;
6
+ function git(root, args) {
7
+ try {
8
+ return execFileSync("git", args, { cwd: root, stdio: ["ignore", "pipe", "ignore"], maxBuffer: 1 << 30 });
9
+ }
10
+ catch {
11
+ return Buffer.alloc(0);
12
+ }
13
+ }
14
+ function fingerprint(root) {
15
+ const hash = createHash("sha256");
16
+ hash.update(git(root, ["rev-parse", "HEAD"]));
17
+ hash.update(git(root, ["diff", "HEAD", "--binary"]));
18
+ for (const file of git(root, ["ls-files", "--others", "--exclude-standard", "-z"]).toString("utf8").split("\0")) {
19
+ const full = path.join(root, file);
20
+ if (file !== "" && existsSync(full))
21
+ hash.update(file).update(readFileSync(full));
22
+ }
23
+ return hash.digest("hex");
24
+ }
25
+ export async function stop(input, root, quickCheck) {
26
+ if (/"stop_hook_active"\s*:\s*true/.test(input))
27
+ return { exitCode: 0, message: "" };
28
+ const marker = path.resolve(root, git(root, ["rev-parse", "--git-path", "suwgate-quick-green"]).toString("utf8").trim());
29
+ const now = fingerprint(root);
30
+ if (existsSync(marker) && readFileSync(marker, "utf8").trim() === now)
31
+ return { exitCode: 0, message: "" };
32
+ const result = await quickCheck();
33
+ if (result.exitCode === 0) {
34
+ writeFileSync(marker, `${now}\n`);
35
+ return { exitCode: 0, message: "" };
36
+ }
37
+ const shown = result.text.split("\n").slice(-SHOWN_LINES).join("\n");
38
+ return { exitCode: 2, message: `The quick gate (suwgate check --quick) is red. Fix it before finishing:\n${shown}` };
39
+ }