@webpieces/rules-config 0.4.813 → 0.4.815

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/rules-config",
3
- "version": "0.4.813",
3
+ "version": "0.4.815",
4
4
  "description": "Shared webpieces.config.json loader. Single source of truth for validation rule configuration consumed by @webpieces/ai-hook-rules, @webpieces/code-rules, and @webpieces/nx-webpieces-rules.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -2,6 +2,7 @@ import { MaxMethodLinesConfig, MaxFileLinesConfig, RequireReturnTypeConfig, NoIn
2
2
  import { BranchStateGuardConfig } from './main-sync-guard-configs';
3
3
  import { NoClientCreationOutsideServerOrClientConfig } from './no-client-creation-config';
4
4
  import { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from './api-lib-spelling-configs';
5
+ import { NoUtilityTypesInApiLibConfig } from './no-utility-types-config';
5
6
  import { NoStatePathsInTemplatesConfig } from './no-state-paths-config';
6
7
  export declare class WebpiecesRulesConfig {
7
8
  'max-method-lines'?: MaxMethodLinesConfig;
@@ -29,6 +30,7 @@ export declare class WebpiecesRulesConfig {
29
30
  'ensure-we-are-secure'?: EnsureWeAreSecureConfig;
30
31
  'no-inline-import-in-api-lib'?: NoInlineImportInApiLibConfig;
31
32
  'one-enum-spelling-in-api-lib'?: OneEnumSpellingInApiLibConfig;
33
+ 'no-utility-types-in-api-lib'?: NoUtilityTypesInApiLibConfig;
32
34
  'branch-state-guard'?: BranchStateGuardConfig;
33
35
  'branch-creation-guard'?: BranchCreationGuardConfig;
34
36
  'pr-lifecycle-guard'?: PrLifecycleGuardConfig;
@@ -27,6 +27,7 @@ class WebpiecesRulesConfig {
27
27
  'ensure-we-are-secure';
28
28
  'no-inline-import-in-api-lib';
29
29
  'one-enum-spelling-in-api-lib';
30
+ 'no-utility-types-in-api-lib';
30
31
  // The THREE hookGuards keys, complete. It used to list five of the nine class-named keys — both
31
32
  // bash guards were simply missing — and nothing caught it, because this class is populated by
32
33
  // dynamic key assignment in the loader. One key per POLICY makes completeness checkable by eye.
@@ -1 +1 @@
1
- {"version":3,"file":"WebpiecesRulesConfig.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/WebpiecesRulesConfig.ts"],"names":[],"mappings":";;;AAoCA,MAAa,oBAAoB;IAC7B,kBAAkB,CAAwB;IAC1C,gBAAgB,CAAsB;IACtC,qBAAqB,CAA2B;IAChD,yBAAyB,CAA8B;IACvD,gBAAgB,CAAsB;IACtC,iBAAiB,CAAuB;IACxC,sBAAsB,CAA4B;IAClD,kBAAkB,CAAyB;IAC3C,gBAAgB,CAAuB;IACvC,yBAAyB,CAA+B;IACxD,qBAAqB,CAA2B;IAChD,sBAAsB,CAA4B;IAClD,mCAAmC,CAAsC;IACzE,qBAAqB,CAA0B;IAC/C,6CAA6C,CAA+C;IAC5F,eAAe,CAAqB;IACpC,6BAA6B,CAAiC;IAC9D,8BAA8B,CAAkC;IAChE,2BAA2B,CAAgC;IAC3D,iDAAiD,CAAmD;IACpG,eAAe,CAAsB;IACrC,UAAU,CAAiB;IAC3B,sBAAsB,CAA2B;IACjD,6BAA6B,CAAgC;IAC7D,8BAA8B,CAAiC;IAC/D,gGAAgG;IAChG,8FAA8F;IAC9F,gGAAgG;IAChG,oBAAoB,CAA0B;IAC9C,uBAAuB,CAA6B;IACpD,oBAAoB,CAA0B;IAC9C,uBAAuB,CAA4B;IACnD,sBAAsB,CAA6B;IACnD,UAAU,CAAiB;IAC3B,2BAA2B,CAAiC;IAC5D,aAAa,CAAmB;IAChC,oBAAoB,CAAyB;IAC7C,QAAQ,CAAY;CACvB;AAvCD,oDAuCC","sourcesContent":["import {\n MaxMethodLinesConfig,\n MaxFileLinesConfig,\n RequireReturnTypeConfig,\n NoInlineTypeLiteralsConfig,\n NoAnyUnknownConfig,\n NoImplicitAnyConfig,\n PrismaValidateDtosConfig,\n PrismaConverterConfig,\n NoDestructureConfig,\n NoUnmanagedExceptionsConfig,\n CatchErrorPatternConfig,\n ThrowCauseRequiredConfig,\n AngularNoDirectApiInResolverConfig,\n NoSymbolDiTokensConfig,\n NoCustomCssConfig,\n NoProcessExitOutsideMainConfig,\n NoFunctionOutsideClassConfig,\n InjectAnnotationNotNeededForConcreteClassConfig,\n FrameworkTagConfig,\n RoleTagConfig,\n EnsureWeAreSecureConfig,\n BranchCreationGuardConfig,\n PrLifecycleGuardConfig,\n NoFileImportCyclesConfig,\n RuntimeArchitectureConfig,\n DiGraphConfig,\n MissingDesignAnnotationConfig,\n NoJsFilesConfig,\n ValidateTsInSrcConfig,\n} from './rule-configs';\nimport { BranchStateGuardConfig } from './main-sync-guard-configs';\nimport { NoClientCreationOutsideServerOrClientConfig } from './no-client-creation-config';\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from './api-lib-spelling-configs';\nimport { NoStatePathsInTemplatesConfig } from './no-state-paths-config';\n\nexport class WebpiecesRulesConfig {\n 'max-method-lines'?: MaxMethodLinesConfig;\n 'max-file-lines'?: MaxFileLinesConfig;\n 'require-return-type'?: RequireReturnTypeConfig;\n 'no-inline-type-literals'?: NoInlineTypeLiteralsConfig;\n 'no-any-unknown'?: NoAnyUnknownConfig;\n 'no-implicit-any'?: NoImplicitAnyConfig;\n 'prisma-validate-dtos'?: PrismaValidateDtosConfig;\n 'prisma-converter'?: PrismaConverterConfig;\n 'no-destructure'?: NoDestructureConfig;\n 'no-unmanaged-exceptions'?: NoUnmanagedExceptionsConfig;\n 'catch-error-pattern'?: CatchErrorPatternConfig;\n 'throw-cause-required'?: ThrowCauseRequiredConfig;\n 'angular-no-direct-api-in-resolver'?: AngularNoDirectApiInResolverConfig;\n 'no-symbol-di-tokens'?: NoSymbolDiTokensConfig;\n 'no-client-creation-outside-server-or-client'?: NoClientCreationOutsideServerOrClientConfig;\n 'no-custom-css'?: NoCustomCssConfig;\n 'no-state-paths-in-templates'?: NoStatePathsInTemplatesConfig;\n 'no-process-exit-outside-main'?: NoProcessExitOutsideMainConfig;\n 'no-function-outside-class'?: NoFunctionOutsideClassConfig;\n 'inject-annotation-not-needed-for-concrete-class'?: InjectAnnotationNotNeededForConcreteClassConfig;\n 'framework-tag'?: FrameworkTagConfig;\n 'role-tag'?: RoleTagConfig;\n 'ensure-we-are-secure'?: EnsureWeAreSecureConfig;\n 'no-inline-import-in-api-lib'?: NoInlineImportInApiLibConfig;\n 'one-enum-spelling-in-api-lib'?: OneEnumSpellingInApiLibConfig;\n // The THREE hookGuards keys, complete. It used to list five of the nine class-named keys — both\n // bash guards were simply missing — and nothing caught it, because this class is populated by\n // dynamic key assignment in the loader. One key per POLICY makes completeness checkable by eye.\n 'branch-state-guard'?: BranchStateGuardConfig;\n 'branch-creation-guard'?: BranchCreationGuardConfig;\n 'pr-lifecycle-guard'?: PrLifecycleGuardConfig;\n 'no-file-import-cycles'?: NoFileImportCyclesConfig;\n 'runtime-architecture'?: RuntimeArchitectureConfig;\n 'di-graph'?: DiGraphConfig;\n 'missing-design-annotation'?: MissingDesignAnnotationConfig;\n 'no-js-files'?: NoJsFilesConfig;\n 'validate-ts-in-src'?: ValidateTsInSrcConfig;\n rulesDir?: string[];\n}\n"]}
1
+ {"version":3,"file":"WebpiecesRulesConfig.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/WebpiecesRulesConfig.ts"],"names":[],"mappings":";;;AAqCA,MAAa,oBAAoB;IAC7B,kBAAkB,CAAwB;IAC1C,gBAAgB,CAAsB;IACtC,qBAAqB,CAA2B;IAChD,yBAAyB,CAA8B;IACvD,gBAAgB,CAAsB;IACtC,iBAAiB,CAAuB;IACxC,sBAAsB,CAA4B;IAClD,kBAAkB,CAAyB;IAC3C,gBAAgB,CAAuB;IACvC,yBAAyB,CAA+B;IACxD,qBAAqB,CAA2B;IAChD,sBAAsB,CAA4B;IAClD,mCAAmC,CAAsC;IACzE,qBAAqB,CAA0B;IAC/C,6CAA6C,CAA+C;IAC5F,eAAe,CAAqB;IACpC,6BAA6B,CAAiC;IAC9D,8BAA8B,CAAkC;IAChE,2BAA2B,CAAgC;IAC3D,iDAAiD,CAAmD;IACpG,eAAe,CAAsB;IACrC,UAAU,CAAiB;IAC3B,sBAAsB,CAA2B;IACjD,6BAA6B,CAAgC;IAC7D,8BAA8B,CAAiC;IAC/D,6BAA6B,CAAgC;IAC7D,gGAAgG;IAChG,8FAA8F;IAC9F,gGAAgG;IAChG,oBAAoB,CAA0B;IAC9C,uBAAuB,CAA6B;IACpD,oBAAoB,CAA0B;IAC9C,uBAAuB,CAA4B;IACnD,sBAAsB,CAA6B;IACnD,UAAU,CAAiB;IAC3B,2BAA2B,CAAiC;IAC5D,aAAa,CAAmB;IAChC,oBAAoB,CAAyB;IAC7C,QAAQ,CAAY;CACvB;AAxCD,oDAwCC","sourcesContent":["import {\n MaxMethodLinesConfig,\n MaxFileLinesConfig,\n RequireReturnTypeConfig,\n NoInlineTypeLiteralsConfig,\n NoAnyUnknownConfig,\n NoImplicitAnyConfig,\n PrismaValidateDtosConfig,\n PrismaConverterConfig,\n NoDestructureConfig,\n NoUnmanagedExceptionsConfig,\n CatchErrorPatternConfig,\n ThrowCauseRequiredConfig,\n AngularNoDirectApiInResolverConfig,\n NoSymbolDiTokensConfig,\n NoCustomCssConfig,\n NoProcessExitOutsideMainConfig,\n NoFunctionOutsideClassConfig,\n InjectAnnotationNotNeededForConcreteClassConfig,\n FrameworkTagConfig,\n RoleTagConfig,\n EnsureWeAreSecureConfig,\n BranchCreationGuardConfig,\n PrLifecycleGuardConfig,\n NoFileImportCyclesConfig,\n RuntimeArchitectureConfig,\n DiGraphConfig,\n MissingDesignAnnotationConfig,\n NoJsFilesConfig,\n ValidateTsInSrcConfig,\n} from './rule-configs';\nimport { BranchStateGuardConfig } from './main-sync-guard-configs';\nimport { NoClientCreationOutsideServerOrClientConfig } from './no-client-creation-config';\nimport { NoInlineImportInApiLibConfig, OneEnumSpellingInApiLibConfig } from './api-lib-spelling-configs';\nimport { NoUtilityTypesInApiLibConfig } from './no-utility-types-config';\nimport { NoStatePathsInTemplatesConfig } from './no-state-paths-config';\n\nexport class WebpiecesRulesConfig {\n 'max-method-lines'?: MaxMethodLinesConfig;\n 'max-file-lines'?: MaxFileLinesConfig;\n 'require-return-type'?: RequireReturnTypeConfig;\n 'no-inline-type-literals'?: NoInlineTypeLiteralsConfig;\n 'no-any-unknown'?: NoAnyUnknownConfig;\n 'no-implicit-any'?: NoImplicitAnyConfig;\n 'prisma-validate-dtos'?: PrismaValidateDtosConfig;\n 'prisma-converter'?: PrismaConverterConfig;\n 'no-destructure'?: NoDestructureConfig;\n 'no-unmanaged-exceptions'?: NoUnmanagedExceptionsConfig;\n 'catch-error-pattern'?: CatchErrorPatternConfig;\n 'throw-cause-required'?: ThrowCauseRequiredConfig;\n 'angular-no-direct-api-in-resolver'?: AngularNoDirectApiInResolverConfig;\n 'no-symbol-di-tokens'?: NoSymbolDiTokensConfig;\n 'no-client-creation-outside-server-or-client'?: NoClientCreationOutsideServerOrClientConfig;\n 'no-custom-css'?: NoCustomCssConfig;\n 'no-state-paths-in-templates'?: NoStatePathsInTemplatesConfig;\n 'no-process-exit-outside-main'?: NoProcessExitOutsideMainConfig;\n 'no-function-outside-class'?: NoFunctionOutsideClassConfig;\n 'inject-annotation-not-needed-for-concrete-class'?: InjectAnnotationNotNeededForConcreteClassConfig;\n 'framework-tag'?: FrameworkTagConfig;\n 'role-tag'?: RoleTagConfig;\n 'ensure-we-are-secure'?: EnsureWeAreSecureConfig;\n 'no-inline-import-in-api-lib'?: NoInlineImportInApiLibConfig;\n 'one-enum-spelling-in-api-lib'?: OneEnumSpellingInApiLibConfig;\n 'no-utility-types-in-api-lib'?: NoUtilityTypesInApiLibConfig;\n // The THREE hookGuards keys, complete. It used to list five of the nine class-named keys — both\n // bash guards were simply missing — and nothing caught it, because this class is populated by\n // dynamic key assignment in the loader. One key per POLICY makes completeness checkable by eye.\n 'branch-state-guard'?: BranchStateGuardConfig;\n 'branch-creation-guard'?: BranchCreationGuardConfig;\n 'pr-lifecycle-guard'?: PrLifecycleGuardConfig;\n 'no-file-import-cycles'?: NoFileImportCyclesConfig;\n 'runtime-architecture'?: RuntimeArchitectureConfig;\n 'di-graph'?: DiGraphConfig;\n 'missing-design-annotation'?: MissingDesignAnnotationConfig;\n 'no-js-files'?: NoJsFilesConfig;\n 'validate-ts-in-src'?: ValidateTsInSrcConfig;\n rulesDir?: string[];\n}\n"]}
@@ -8,7 +8,8 @@ import { BaseRuleConfig, ModifiedCodeMode } from './rule-configs';
8
8
  *
9
9
  * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
10
10
  * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
11
- * occurrence in a changed file). `allowedPaths` exempts whole trees. The per-site escape hatch is
11
+ * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in each touched
12
+ * project / the whole repo — #1027). `allowedPaths` exempts whole trees. The per-site escape hatch is
12
13
  * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
13
14
  */
14
15
  export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
@@ -29,7 +30,7 @@ export declare class NoInlineImportInApiLibConfig extends BaseRuleConfig {
29
30
  * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's
30
31
  * mode grandfathers. This rule is what forbids NEW ones in an api library.
31
32
  *
32
- * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three
33
+ * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same five
33
34
  * values as above; `allowedPaths` and the per-site disable work the same way.
34
35
  */
35
36
  export declare class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {
@@ -11,7 +11,8 @@ const rule_configs_1 = require("./rule-configs");
11
11
  *
12
12
  * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |
13
13
  * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every
14
- * occurrence in a changed file). `allowedPaths` exempts whole trees. The per-site escape hatch is
14
+ * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in each touched
15
+ * project / the whole repo — #1027). `allowedPaths` exempts whole trees. The per-site escape hatch is
15
16
  * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.
16
17
  */
17
18
  class NoInlineImportInApiLibConfig extends rule_configs_1.BaseRuleConfig {
@@ -36,7 +37,7 @@ exports.NoInlineImportInApiLibConfig = NoInlineImportInApiLibConfig;
36
37
  * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's
37
38
  * mode grandfathers. This rule is what forbids NEW ones in an api library.
38
39
  *
39
- * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three
40
+ * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same five
40
41
  * values as above; `allowedPaths` and the per-site disable work the same way.
41
42
  */
42
43
  class OneEnumSpellingInApiLibConfig extends rule_configs_1.BaseRuleConfig {
@@ -1 +1 @@
1
- {"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,iDAAyG;AAEzG;;;;;;;;;;GAUG;AACH,MAAa,4BAA6B,SAAQ,6BAAc;IAE5D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA8C;QAChE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,kCAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,+BAAgB;KACtB,CAAC;;AARN,oEASC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,6BAA8B,SAAQ,6BAAc;IAE7D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA+C;QACjE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,kCAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,+BAAgB;KACtB,CAAC;;AARN,sEASC","sourcesContent":["import { FieldDef, SchemaShape } from './field-def';\nimport { BaseRuleConfig, BASE_RULE_SCHEMA, ModifiedCodeMode, MODIFIED_CODE_MODES } from './rule-configs';\n\n/**\n * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`\n * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`\n * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library\n * dependency from every reader of the contract and from the tools that read its imports.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |\n * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every\n * occurrence in a changed file). `allowedPaths` exempts whole trees. The per-site escape hatch is\n * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.\n */\nexport class NoInlineImportInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n\n/**\n * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string\n * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string\n * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one\n * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:\n * a string-literal union of two or more members (in a type alias, a field or a parameter),\n * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,\n * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the\n * wire).\n *\n * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's\n * mode grandfathers. This rule is what forbids NEW ones in an api library.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same three\n * values as above; `allowedPaths` and the per-site disable work the same way.\n */\nexport class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
1
+ {"version":3,"file":"api-lib-spelling-configs.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/api-lib-spelling-configs.ts"],"names":[],"mappings":";;;AAAA,2CAAoD;AACpD,iDAAyG;AAEzG;;;;;;;;;;;GAWG;AACH,MAAa,4BAA6B,SAAQ,6BAAc;IAE5D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA8C;QAChE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,kCAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,+BAAgB;KACtB,CAAC;;AARN,oEASC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,6BAA8B,SAAQ,6BAAc;IAE7D,YAAY,CAAY;IAExB,MAAM,CAAU,MAAM,GAA+C;QACjE,IAAI,EAAE,IAAI,oBAAQ,CAAC,QAAQ,EAAE,kCAAmB,CAAC;QACjD,YAAY,EAAE,oBAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3C,GAAG,+BAAgB;KACtB,CAAC;;AARN,sEASC","sourcesContent":["import { FieldDef, SchemaShape } from './field-def';\nimport { BaseRuleConfig, BASE_RULE_SCHEMA, ModifiedCodeMode, MODIFIED_CODE_MODES } from './rule-configs';\n\n/**\n * `no-inline-import-in-api-lib` (#1023) — in every `role:api-lib` project, refuse an `import('…')`\n * TYPE node (`activeAiProvider?: import('@myorg/company-core').AiProvider`) and a dynamic `import()`\n * EXPRESSION. An API imports at the top of the file, only: an inline import hides a cross-library\n * dependency from every reader of the contract and from the tools that read its imports.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`): OFF |\n * NEW_AND_MODIFIED_CODE (only changed lines — grandfathers the rest) | NEW_AND_MODIFIED_FILES (every\n * occurrence in a changed file) | MODIFIED_PROJECTS / RUN_EVERY_TIME (every occurrence in each touched\n * project / the whole repo — #1027). `allowedPaths` exempts whole trees. The per-site escape hatch is\n * `// webpieces-disable no-inline-import-in-api-lib -- <reason>` on the line or the line above.\n */\nexport class NoInlineImportInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<NoInlineImportInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n\n/**\n * `one-enum-spelling-in-api-lib` (#1023) — in every `role:api-lib` project, a fixed set of string\n * values has ONE spelling: a string `enum` whose every member is explicitly initialised with a string\n * literal (`export enum SpeakerGender { FEMALE = 'female', MALE = 'male' }`), used as the enum, one\n * member of it, or a union of its members. Refused, each with a cure that prints the enum to write:\n * a string-literal union of two or more members (in a type alias, a field or a parameter),\n * `(typeof X)[number]`, `keyof typeof X`, a single string-literal type used as a union discriminator,\n * and a numeric, heterogeneous, `const` or non-initialised enum (a numeric enum puts numbers on the\n * wire).\n *\n * The GENERATOR keeps supporting string-literal unions — for other consumers, and for code this rule's\n * mode grandfathers. This rule is what forbids NEW ones in an api library.\n *\n * `mode` is REQUIRED and has no default (`.claude/rules/no-rule-defaults.md`), with the same five\n * values as above; `allowedPaths` and the per-site disable work the same way.\n */\nexport class OneEnumSpellingInApiLibConfig extends BaseRuleConfig {\n declare mode?: ModifiedCodeMode;\n allowedPaths?: string[];\n\n static readonly SCHEMA: SchemaShape<OneEnumSpellingInApiLibConfig> = {\n mode: new FieldDef('string', MODIFIED_CODE_MODES),\n allowedPaths: FieldDef.optional('string[]'),\n ...BASE_RULE_SCHEMA,\n };\n}\n"]}
@@ -28,6 +28,7 @@ export declare const RULE_NAMES: {
28
28
  readonly API_RULES_FOR_MCP: "api-rules-for-mcp";
29
29
  readonly NO_INLINE_IMPORT_IN_API_LIB: "no-inline-import-in-api-lib";
30
30
  readonly ONE_ENUM_SPELLING_IN_API_LIB: "one-enum-spelling-in-api-lib";
31
+ readonly NO_UTILITY_TYPES_IN_API_LIB: "no-utility-types-in-api-lib";
31
32
  };
32
33
  export declare const WEBPIECES_TMP_DIR = ".webpieces";
33
34
  export declare const MERGE_INFO_DIR = "merge-info";
package/src/constants.js CHANGED
@@ -42,6 +42,7 @@ exports.RULE_NAMES = {
42
42
  API_RULES_FOR_MCP: 'api-rules-for-mcp',
43
43
  NO_INLINE_IMPORT_IN_API_LIB: 'no-inline-import-in-api-lib',
44
44
  ONE_ENUM_SPELLING_IN_API_LIB: 'one-enum-spelling-in-api-lib',
45
+ NO_UTILITY_TYPES_IN_API_LIB: 'no-utility-types-in-api-lib',
45
46
  };
46
47
  // Merge-state convention shared by the pr-gate scripts (which WRITE the marker during a
47
48
  // conflicted 3-point merge) and the ai-hook-rules merge-in-progress-guard (which READS it
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/constants.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,sEAAsE;AACtE,EAAE;AACF,yFAAyF;AACzF,qFAAqF;AACrF,kFAAkF;;;AA6GlF,gCAEC;AA7GY,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAErD,kFAAkF;AAClF,uFAAuF;AACvF,uEAAuE;AACvE,sFAAsF;AACzE,QA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,sBAAsB,GAAG,wBAAwB,CAAC;AAE/D,uFAAuF;AACvF,qGAAqG;AACrG,8FAA8F;AAC9F,2DAA2D;AAC3D,EAAE;AACF,kGAAkG;AAClG,iGAAiG;AACjG,oGAAoG;AACpG,kGAAkG;AACrF,QAAA,mBAAmB,GAAG,2BAA2B,CAAC;AAE/D,2FAA2F;AAC3F,mFAAmF;AACnF,uFAAuF;AACvF,uGAAuG;AACvG,kGAAkG;AAClG,kGAAkG;AAClG,iDAAiD;AACpC,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D;;;;;;;;;GASG;AACU,QAAA,qBAAqB,GAAG,8BAA8B,CAAC;AAEpE;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,QAAgB;IACrD,OAAO,IAAI,CAAC,QAAQ,CAAC,yBAAiB,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvE,CAAC","sourcesContent":["// Single source of truth for the disable-comment token and rule-name identifiers\n// shared across rules-config, ai-hook-rules, code-rules, and pr-gate.\n//\n// There is exactly ONE disable form: `// webpieces-disable <rule>[, <rule2>] -- reason`.\n// The legacy `ai-hook-disable` alias and the `-file`/`-next`/`-all` variants and the\n// `*`/bare (no-rule) wildcard have been removed — every disable MUST name a rule.\n\nexport const WEBPIECES_DISABLE = 'webpieces-disable';\n\n// Rule-name tokens as they appear AFTER `webpieces-disable` in a disable comment.\n// Values must match existing comments exactly — changing a value silently breaks every\n// disable that names that rule. Note MAX_LINES_MODIFIED is a prefix of\n// MAX_LINES_MODIFIED_FILES (a historical substring-match quirk preserved on purpose).\nexport const RULE_NAMES = {\n NO_ANY_UNKNOWN: 'no-any-unknown',\n NO_IMPLICIT_ANY: 'no-implicit-any',\n NO_DESTRUCTURE: 'no-destructure',\n NO_UNMANAGED_EXCEPTIONS: 'no-unmanaged-exceptions',\n CATCH_ERROR_PATTERN: 'catch-error-pattern',\n THROW_CAUSE_REQUIRED: 'throw-cause-required',\n REQUIRE_RETURN_TYPE: 'require-return-type',\n NO_SYMBOL_DI_TOKENS: 'no-symbol-di-tokens',\n NO_CLIENT_CREATION_OUTSIDE_SERVER_OR_CLIENT: 'no-client-creation-outside-server-or-client',\n NO_PROCESS_EXIT_OUTSIDE_MAIN: 'no-process-exit-outside-main',\n NO_FUNCTION_OUTSIDE_CLASS: 'no-function-outside-class',\n INJECT_ANNOTATION_NOT_NEEDED_FOR_CONCRETE_CLASS:\n 'inject-annotation-not-needed-for-concrete-class',\n FRAMEWORK_TAG: 'framework-tag',\n ROLE_TAG: 'role-tag',\n ENSURE_WE_ARE_SECURE: 'ensure-we-are-secure',\n NO_INLINE_TYPES: 'no-inline-types',\n NO_DIRECT_API_RESOLVER: 'no-direct-api-resolver',\n NO_CUSTOM_CSS: 'no-custom-css',\n NO_STATE_PATHS_IN_TEMPLATES: 'no-state-paths-in-templates',\n PRISMA_CONVERTER: 'prisma-converter',\n MAX_LINES_NEW_METHODS: 'max-lines-new-methods',\n MAX_LINES_MODIFIED_FILES: 'max-lines-modified-files',\n MAX_LINES_MODIFIED: 'max-lines-modified',\n NO_ROOT_UNION_API_TYPE: 'no-root-union-api-type',\n API_RULES_FOR_OPENAPI: 'api-rules-for-openapi',\n API_RULES_FOR_MCP: 'api-rules-for-mcp',\n NO_INLINE_IMPORT_IN_API_LIB: 'no-inline-import-in-api-lib',\n ONE_ENUM_SPELLING_IN_API_LIB: 'one-enum-spelling-in-api-lib',\n} as const;\n\n// Merge-state convention shared by the pr-gate scripts (which WRITE the marker during a\n// conflicted 3-point merge) and the ai-hook-rules merge-in-progress-guard (which READS it\n// to block commit/push/PR until the merge is validated). Kept here so neither package\n// depends on the other — they only share this vocabulary.\n//\n// `.webpieces/` is the single working dir for all webpieces tooling: ai-hook-rules\n// bootstrap/cache, the instruct-ai docs, and the workflow state. To keep the top level\n// quiet, per-feature workflow dirs are nested one level down under `merge-info/<feature>`\n// and `pr-review/<feature>` rather than scattered as top-level `merge-<feature>`/`pr-<feature>`.\n// `.webpieces/` is gitignored; only the per-feature subdirs under those two homes are subject\n// to 30-day cleanup (the homes themselves, like hooks/ and instruct-ai/, are permanent).\n// The DIRECTORY NAME only. Never join it onto a root yourself — go through `DotWebpieces.shared()`\n// (repo-wide state), `DotWebpieces.local()` (this worktree's own tooling-written state) or\n// `DotWebpieces.aiWritable()` (this worktree's state that a CODING AGENT writes) so the call site\n// declares its scope. In a linked worktree the three resolve to different places, and getting that\n// silently wrong is the bug those methods exist to prevent.\nexport const WEBPIECES_TMP_DIR = '.webpieces';\nexport const MERGE_INFO_DIR = 'merge-info';\n// The PR working home. Renamed from the legacy `pr-info` to `pr-review` for clarity (it holds the\n// AI's PR review + rendered body). Old `pr-info/` dirs are gitignored local state and self-clear via\n// cleanTmp's legacy `pr-` sweep.\nexport const PR_REVIEW_DIR = 'pr-review';\nexport const MERGE_IN_PROGRESS_FILE = 'merge-in-progress.json';\n\n// The dev-deploy resolve state file, written by `wp-push-dev --resolve` and cleared by\n// `wp-finish-push-dev` (or `--abort`). Named here for the same reason MERGE_IN_PROGRESS_FILE is: the\n// pr-gate commands WRITE it and things outside pr-gate READ it to decide whether a resolve is\n// half-finished, and neither side may depend on the other.\n//\n// It lives directly under `.webpieces/` local state (NOT under merge-info/), because a dev-deploy\n// resolve is not a 3-point merge: it never touches the feature branch, never produces merge-info\n// context, and must NOT be picked up by merge-in-progress-guard's marker scan — that guard's remedy\n// is `pnpm wp-finish-upsert-pr`, which is the wrong command here and would strand the tmp branch.\nexport const PUSH_DEV_STATE_FILE = 'push-dev-in-progress.json';\n\n// Proof-of-work the AI must produce for every conflicted file it resolves during a 3-point\n// merge: a short explanation written NEXT TO that file's 3-point context (the same\n// `updatemain-<safe_path>/` dir that holds A-forkpoint.txt / B-A.diff / C-A.diff). The\n// wp-finish-upsert-pr gate requires a non-empty file of this name per conflicted file before passing —\n// it is the only check on the part of the process the AI actually owns (resolving files). Using a\n// sidecar file (rather than an in-source comment) works for any file type, including comment-less\n// ones like JSON and files resolved by deletion.\nexport const MERGE_EXPLANATION_FILE = 'merge-explanation.md';\n\n/**\n * The command that MECHANICALLY strips every unknown key from webpieces.config.json.\n *\n * An unknown key controls nothing, so deleting it is the cure — but \"delete it\" is a judgement call made\n * while the guard denies every Bash call, which is exactly when a reader is least able to make one. This\n * command turns that judgement into one keystroke, and every message that reports an unknown key names it.\n *\n * Lives in this leaf module (no imports) so both the banner and the validators can name it without\n * importing the pruner and re-creating an import cycle.\n */\nexport const PRUNE_UNKNOWN_COMMAND = 'pnpm wp-prune-unknown-config';\n\n/**\n * The command that rewrites every webpieces-owned file a repo commits — the L0 hook shim and the generic\n * reviewer agent (`.claude/agents/webpieces-reviewer.md`). Named here, in the leaf module, so the config\n * validator that finds that agent missing can print the cure without importing ai-hook-rules.\n */\nexport const UPGRADE_SHIM_COMMAND = 'pnpm wp-upgrade-shim';\n\n/**\n * Fast predicate: does this text carry a webpieces-disable for the given rule?\n * Line-agnostic — the caller decides which line(s) or block of text to feed it.\n * This is the cheap substring form used by code-rules detection and pr-gate's\n * dashboard grep/count. (ai-hook-rules uses a richer line-mapping parser.)\n */\nexport function hasDisable(text: string, ruleName: string): boolean {\n return text.includes(WEBPIECES_DISABLE) && text.includes(ruleName);\n}\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/constants.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,sEAAsE;AACtE,EAAE;AACF,yFAAyF;AACzF,qFAAqF;AACrF,kFAAkF;;;AA8GlF,gCAEC;AA9GY,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAErD,kFAAkF;AAClF,uFAAuF;AACvF,uEAAuE;AACvE,sFAAsF;AACzE,QAAA,UAAU,GAAG;IACtB,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,uBAAuB,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F,2DAA2D;AAC3D,EAAE;AACF,kGAAkG;AAClG,iGAAiG;AACjG,oGAAoG;AACpG,kGAAkG;AACrF,QAAA,mBAAmB,GAAG,2BAA2B,CAAC;AAE/D,2FAA2F;AAC3F,mFAAmF;AACnF,uFAAuF;AACvF,uGAAuG;AACvG,kGAAkG;AAClG,kGAAkG;AAClG,iDAAiD;AACpC,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D;;;;;;;;;GASG;AACU,QAAA,qBAAqB,GAAG,8BAA8B,CAAC;AAEpE;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,QAAgB;IACrD,OAAO,IAAI,CAAC,QAAQ,CAAC,yBAAiB,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvE,CAAC","sourcesContent":["// Single source of truth for the disable-comment token and rule-name identifiers\n// shared across rules-config, ai-hook-rules, code-rules, and pr-gate.\n//\n// There is exactly ONE disable form: `// webpieces-disable <rule>[, <rule2>] -- reason`.\n// The legacy `ai-hook-disable` alias and the `-file`/`-next`/`-all` variants and the\n// `*`/bare (no-rule) wildcard have been removed — every disable MUST name a rule.\n\nexport const WEBPIECES_DISABLE = 'webpieces-disable';\n\n// Rule-name tokens as they appear AFTER `webpieces-disable` in a disable comment.\n// Values must match existing comments exactly — changing a value silently breaks every\n// disable that names that rule. Note MAX_LINES_MODIFIED is a prefix of\n// MAX_LINES_MODIFIED_FILES (a historical substring-match quirk preserved on purpose).\nexport const RULE_NAMES = {\n NO_ANY_UNKNOWN: 'no-any-unknown',\n NO_IMPLICIT_ANY: 'no-implicit-any',\n NO_DESTRUCTURE: 'no-destructure',\n NO_UNMANAGED_EXCEPTIONS: 'no-unmanaged-exceptions',\n CATCH_ERROR_PATTERN: 'catch-error-pattern',\n THROW_CAUSE_REQUIRED: 'throw-cause-required',\n REQUIRE_RETURN_TYPE: 'require-return-type',\n NO_SYMBOL_DI_TOKENS: 'no-symbol-di-tokens',\n NO_CLIENT_CREATION_OUTSIDE_SERVER_OR_CLIENT: 'no-client-creation-outside-server-or-client',\n NO_PROCESS_EXIT_OUTSIDE_MAIN: 'no-process-exit-outside-main',\n NO_FUNCTION_OUTSIDE_CLASS: 'no-function-outside-class',\n INJECT_ANNOTATION_NOT_NEEDED_FOR_CONCRETE_CLASS:\n 'inject-annotation-not-needed-for-concrete-class',\n FRAMEWORK_TAG: 'framework-tag',\n ROLE_TAG: 'role-tag',\n ENSURE_WE_ARE_SECURE: 'ensure-we-are-secure',\n NO_INLINE_TYPES: 'no-inline-types',\n NO_DIRECT_API_RESOLVER: 'no-direct-api-resolver',\n NO_CUSTOM_CSS: 'no-custom-css',\n NO_STATE_PATHS_IN_TEMPLATES: 'no-state-paths-in-templates',\n PRISMA_CONVERTER: 'prisma-converter',\n MAX_LINES_NEW_METHODS: 'max-lines-new-methods',\n MAX_LINES_MODIFIED_FILES: 'max-lines-modified-files',\n MAX_LINES_MODIFIED: 'max-lines-modified',\n NO_ROOT_UNION_API_TYPE: 'no-root-union-api-type',\n API_RULES_FOR_OPENAPI: 'api-rules-for-openapi',\n API_RULES_FOR_MCP: 'api-rules-for-mcp',\n NO_INLINE_IMPORT_IN_API_LIB: 'no-inline-import-in-api-lib',\n ONE_ENUM_SPELLING_IN_API_LIB: 'one-enum-spelling-in-api-lib',\n NO_UTILITY_TYPES_IN_API_LIB: 'no-utility-types-in-api-lib',\n} as const;\n\n// Merge-state convention shared by the pr-gate scripts (which WRITE the marker during a\n// conflicted 3-point merge) and the ai-hook-rules merge-in-progress-guard (which READS it\n// to block commit/push/PR until the merge is validated). Kept here so neither package\n// depends on the other — they only share this vocabulary.\n//\n// `.webpieces/` is the single working dir for all webpieces tooling: ai-hook-rules\n// bootstrap/cache, the instruct-ai docs, and the workflow state. To keep the top level\n// quiet, per-feature workflow dirs are nested one level down under `merge-info/<feature>`\n// and `pr-review/<feature>` rather than scattered as top-level `merge-<feature>`/`pr-<feature>`.\n// `.webpieces/` is gitignored; only the per-feature subdirs under those two homes are subject\n// to 30-day cleanup (the homes themselves, like hooks/ and instruct-ai/, are permanent).\n// The DIRECTORY NAME only. Never join it onto a root yourself — go through `DotWebpieces.shared()`\n// (repo-wide state), `DotWebpieces.local()` (this worktree's own tooling-written state) or\n// `DotWebpieces.aiWritable()` (this worktree's state that a CODING AGENT writes) so the call site\n// declares its scope. In a linked worktree the three resolve to different places, and getting that\n// silently wrong is the bug those methods exist to prevent.\nexport const WEBPIECES_TMP_DIR = '.webpieces';\nexport const MERGE_INFO_DIR = 'merge-info';\n// The PR working home. Renamed from the legacy `pr-info` to `pr-review` for clarity (it holds the\n// AI's PR review + rendered body). Old `pr-info/` dirs are gitignored local state and self-clear via\n// cleanTmp's legacy `pr-` sweep.\nexport const PR_REVIEW_DIR = 'pr-review';\nexport const MERGE_IN_PROGRESS_FILE = 'merge-in-progress.json';\n\n// The dev-deploy resolve state file, written by `wp-push-dev --resolve` and cleared by\n// `wp-finish-push-dev` (or `--abort`). Named here for the same reason MERGE_IN_PROGRESS_FILE is: the\n// pr-gate commands WRITE it and things outside pr-gate READ it to decide whether a resolve is\n// half-finished, and neither side may depend on the other.\n//\n// It lives directly under `.webpieces/` local state (NOT under merge-info/), because a dev-deploy\n// resolve is not a 3-point merge: it never touches the feature branch, never produces merge-info\n// context, and must NOT be picked up by merge-in-progress-guard's marker scan — that guard's remedy\n// is `pnpm wp-finish-upsert-pr`, which is the wrong command here and would strand the tmp branch.\nexport const PUSH_DEV_STATE_FILE = 'push-dev-in-progress.json';\n\n// Proof-of-work the AI must produce for every conflicted file it resolves during a 3-point\n// merge: a short explanation written NEXT TO that file's 3-point context (the same\n// `updatemain-<safe_path>/` dir that holds A-forkpoint.txt / B-A.diff / C-A.diff). The\n// wp-finish-upsert-pr gate requires a non-empty file of this name per conflicted file before passing —\n// it is the only check on the part of the process the AI actually owns (resolving files). Using a\n// sidecar file (rather than an in-source comment) works for any file type, including comment-less\n// ones like JSON and files resolved by deletion.\nexport const MERGE_EXPLANATION_FILE = 'merge-explanation.md';\n\n/**\n * The command that MECHANICALLY strips every unknown key from webpieces.config.json.\n *\n * An unknown key controls nothing, so deleting it is the cure — but \"delete it\" is a judgement call made\n * while the guard denies every Bash call, which is exactly when a reader is least able to make one. This\n * command turns that judgement into one keystroke, and every message that reports an unknown key names it.\n *\n * Lives in this leaf module (no imports) so both the banner and the validators can name it without\n * importing the pruner and re-creating an import cycle.\n */\nexport const PRUNE_UNKNOWN_COMMAND = 'pnpm wp-prune-unknown-config';\n\n/**\n * The command that rewrites every webpieces-owned file a repo commits — the L0 hook shim and the generic\n * reviewer agent (`.claude/agents/webpieces-reviewer.md`). Named here, in the leaf module, so the config\n * validator that finds that agent missing can print the cure without importing ai-hook-rules.\n */\nexport const UPGRADE_SHIM_COMMAND = 'pnpm wp-upgrade-shim';\n\n/**\n * Fast predicate: does this text carry a webpieces-disable for the given rule?\n * Line-agnostic — the caller decides which line(s) or block of text to feed it.\n * This is the cheap substring form used by code-rules detection and pr-gate's\n * dashboard grep/count. (ai-hook-rules uses a richer line-mapping parser.)\n */\nexport function hasDisable(text: string, ruleName: string): boolean {\n return text.includes(WEBPIECES_DISABLE) && text.includes(ruleName);\n}\n"]}
@@ -91,6 +91,9 @@ exports.defaultRules = {
91
91
  // pin bump to the release that ships them, tracked in #1024.
92
92
  'no-inline-import-in-api-lib': {},
93
93
  'one-enum-spelling-in-api-lib': {},
94
+ // #1026: REQUIRES `mode` and `paths` — no entry here may carry either. A new key the
95
+ // one-release-behind validator does not know yet, so THIS repo's config states it after publish.
96
+ 'no-utility-types-in-api-lib': {},
94
97
  'branch-creation-guard': {},
95
98
  'pr-lifecycle-guard': {},
96
99
  // NOTE: `whole-repo-build-guard` is deliberately ABSENT from this table, and from RULE_SCHEMAS and
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/default-rules.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AClC,iDAAiD,EAAE,EAAE;IACrD,eAAe,EAAE;QACb,UAAU,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC;KACjE;IACD,UAAU,EAAE;QACR,UAAU,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC;KAC5E;IACD,sBAAsB,EAAE,EAAE;IAC1B,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,EAAE;IACd,2BAA2B,EAAE,EAAE;IAC/B,oBAAoB,EAAE;QAClB,gBAAgB,EAAE,CAAC,eAAe,CAAC;QACnC,YAAY,EAAE,CAAC,GAAG,qBAAqB,CAAC;KAC3C;IACD,aAAa,EAAE,EAAE;IACjB,iCAAiC,EAAE,EAAE;IACrC,iCAAiC,EAAE,EAAE;IACrC,sBAAsB,EAAE,EAAE;IAC1B,0BAA0B,EAAE,EAAE;IAC9B,sBAAsB,EAAE,EAAE;IAC1B,wBAAwB,EAAE,EAAE;IAC5B,uBAAuB,EAAE,EAAE;IAC3B,mBAAmB,EAAE,EAAE;IACvB,mGAAmG;IACnG,iGAAiG;IACjG,6DAA6D;IAC7D,6BAA6B,EAAE,EAAE;IACjC,8BAA8B,EAAE,EAAE;IAClC,uBAAuB,EAAE,EAAE;IAC3B,oBAAoB,EAAE,EAAE;IACxB,mGAAmG;IACnG,mGAAmG;IACnG,+EAA+E;IAC/E,mGAAmG;IACnG,gGAAgG;IAChG,uCAAuC;IACvC,oBAAoB,EAAE,EAAE;CAC3B,CAAC;AAEW,QAAA,eAAe,GAAsB,EAAE,CAAC","sourcesContent":["// Default holistic exclude list for the validate-ts-in-src\n// rules. Bare names match a directory segment at any depth; globs match the\n// workspace-relative path. `**/*.d.ts` (ambient declarations) and\n// `**/jest.config.ts` legitimately live outside src/ and are exempt here.\nconst DEFAULT_EXCLUDE_PATHS: readonly string[] = [\n 'node_modules',\n 'dist',\n '.nx',\n '.git',\n '**/*.d.ts',\n '**/jest.config.ts',\n];\n\n// A RULE HAS NO DEFAULT. Not `mode`, and not any other field a schema marks REQUIRED.\n//\n// This table is TUNING ONLY: the value an OPTIONAL field takes when a consumer omits it, and the value\n// the installer seeds that field with. It may never carry `mode`, and it may never carry a\n// schema-required field — `no-rule-defaults.spec.ts` fails the build if one appears, and\n// `webpieces-config-defaults-reviewer` fails the PR.\n//\n// Why, in one paragraph. Every rule with a schema is one `webpieces.config.json` must carry an entry\n// for: validateWebpiecesConfig pushes a copy-paste snippet for every RULE_SCHEMAS key the config does\n// not name, and that error FAILS THE LOAD. A default sitting beneath that is therefore not \"the value\n// when nobody said\" — it is the value when the loader is bypassed, and its real effect is to make the\n// question look answered. The consumer ANSWERING it is the product: a repo that was never asked\n// whether merged branches may be deleted unattended is a repo where nobody decided, and an agent\n// authoring a rule is the wrong party to decide that on every downstream repo's behalf. The failing\n// load is the delivery mechanism, exactly as a compile error is for a changed surface — the upgrade\n// breaks, the agent reads \"add this entry\", finds out what it means, and the human chooses.\n//\n// The six entries #1017 measured are gone from here, and every consumer must now state each one in\n// its own config: branch-creation-guard (mode + subBranchNaming + autoReapMergedBranches),\n// pr-lifecycle-guard (mode), branch-state-guard (mode + maxCommitsBehind), no-root-union-api-type,\n// api-rules-for-openapi and api-rules-for-mcp (mode). THIS repo states only the first three today —\n// the other three are new keys the one-release-behind validator does not know yet\n// (.claude/rules/published-vs-local-source.md), so they land with the pin bump, tracked in #1015.\n// `autoReapMergedBranches` and `subBranchNaming` are schema-REQUIRED\n// because they are BEHAVIOUR — one deletes branches unattended, the other decides which branch names\n// are blocked — and behaviour is stated, never inherited. The numeric caps (maxLocalBranches,\n// maxWorktrees) stay optional knobs on purpose: they tune a refusal that PRINTS the cap it hit, so the\n// value is visible at the moment it bites rather than only in webpieces' source.\n// webpieces-disable no-any-unknown -- rule options are opaque at framework level\nexport const defaultRules: Record<string, Record<string, unknown>> = {\n 'no-any-unknown': {},\n 'no-implicit-any': {},\n 'max-file-lines': { limit: 900 },\n 'max-method-lines': { limit: 80 },\n 'require-return-type': {},\n 'no-inline-type-literals': {},\n 'no-destructure': { allowTopLevel: true },\n 'catch-error-pattern': {},\n 'no-unmanaged-exceptions': {},\n 'no-file-import-cycles': {},\n 'runtime-architecture': {},\n 'prisma-validate-dtos': {},\n 'prisma-converter': {},\n 'angular-no-direct-api-in-resolver': {},\n 'no-symbol-di-tokens': {},\n 'no-client-creation-outside-server-or-client': {},\n 'no-custom-css': { allowGlobs: [] },\n 'no-state-paths-in-templates': {},\n 'no-process-exit-outside-main': {},\n 'inject-annotation-not-needed-for-concrete-class': {},\n 'framework-tag': {\n knownTypes: ['browser', 'react', 'angular', 'node', 'express'],\n },\n 'role-tag': {\n knownTypes: ['server', 'app', 'designed-lib', 'lib', 'client', 'api-lib'],\n },\n 'ensure-we-are-secure': {},\n 'nx-wiring': {},\n 'di-graph': {},\n 'missing-design-annotation': {},\n 'validate-ts-in-src': {\n allowedRootFiles: ['jest.setup.ts'],\n excludePaths: [...DEFAULT_EXCLUDE_PATHS],\n },\n 'no-js-files': {},\n 'validate-architecture-unchanged': {},\n 'validate-no-architecture-cycles': {},\n 'validate-packagejson': {},\n 'validate-versions-locked': {},\n 'validate-eslint-sync': {},\n 'no-root-union-api-type': {},\n 'api-rules-for-openapi': {},\n 'api-rules-for-mcp': {},\n // #1023: both REQUIRE `mode` — no entry here may carry one. Like the three above they are new keys\n // the one-release-behind validator does not know yet, so THIS repo's config states them with the\n // pin bump to the release that ships them, tracked in #1024.\n 'no-inline-import-in-api-lib': {},\n 'one-enum-spelling-in-api-lib': {},\n 'branch-creation-guard': {},\n 'pr-lifecycle-guard': {},\n // NOTE: `whole-repo-build-guard` is deliberately ABSENT from this table, and from RULE_SCHEMAS and\n // HOOK_GUARD_NAMES with it. It is EXPERIMENTAL and OFF by default; the ONLY thing that turns it on\n // is `experimental.whole-repo-build-guard: true` in the optional machine-local\n // ~/.webpieces/config.json. Adding it back here would make it a rule every consumer must CONFIGURE\n // — which is fault Y, i.e. every Bash call blocked on upgrade, which is exactly what it did the\n // first time. See RETIRED_CONFIG_KEYS.\n 'branch-state-guard': {},\n};\n\nexport const defaultRulesDir: readonly string[] = [];\n"]}
1
+ {"version":3,"file":"default-rules.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/default-rules.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAC3D,4EAA4E;AAC5E,kEAAkE;AAClE,0EAA0E;AAC1E,MAAM,qBAAqB,GAAsB;IAC7C,cAAc;IACd,MAAM;IACN,KAAK;IACL,MAAM;IACN,WAAW;IACX,mBAAmB;CACtB,CAAC;AAEF,sFAAsF;AACtF,EAAE;AACF,uGAAuG;AACvG,2FAA2F;AAC3F,yFAAyF;AACzF,qDAAqD;AACrD,EAAE;AACF,qGAAqG;AACrG,sGAAsG;AACtG,sGAAsG;AACtG,sGAAsG;AACtG,gGAAgG;AAChG,iGAAiG;AACjG,oGAAoG;AACpG,oGAAoG;AACpG,4FAA4F;AAC5F,EAAE;AACF,mGAAmG;AACnG,2FAA2F;AAC3F,mGAAmG;AACnG,oGAAoG;AACpG,kFAAkF;AAClF,kGAAkG;AAClG,qEAAqE;AACrE,qGAAqG;AACrG,8FAA8F;AAC9F,uGAAuG;AACvG,iFAAiF;AACjF,iFAAiF;AACpE,QAAA,YAAY,GAA4C;IACjE,gBAAgB,EAAE,EAAE;IACpB,iBAAiB,EAAE,EAAE;IACrB,gBAAgB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE;IAChC,kBAAkB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;IACjC,qBAAqB,EAAE,EAAE;IACzB,yBAAyB,EAAE,EAAE;IAC7B,gBAAgB,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE;IACzC,qBAAqB,EAAE,EAAE;IACzB,yBAAyB,EAAE,EAAE;IAC7B,uBAAuB,EAAE,EAAE;IAC3B,sBAAsB,EAAE,EAAE;IAC1B,sBAAsB,EAAE,EAAE;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AE;CAC3B,CAAC;AAEW,QAAA,eAAe,GAAsB,EAAE,CAAC","sourcesContent":["// Default holistic exclude list for the validate-ts-in-src\n// rules. Bare names match a directory segment at any depth; globs match the\n// workspace-relative path. `**/*.d.ts` (ambient declarations) and\n// `**/jest.config.ts` legitimately live outside src/ and are exempt here.\nconst DEFAULT_EXCLUDE_PATHS: readonly string[] = [\n 'node_modules',\n 'dist',\n '.nx',\n '.git',\n '**/*.d.ts',\n '**/jest.config.ts',\n];\n\n// A RULE HAS NO DEFAULT. Not `mode`, and not any other field a schema marks REQUIRED.\n//\n// This table is TUNING ONLY: the value an OPTIONAL field takes when a consumer omits it, and the value\n// the installer seeds that field with. It may never carry `mode`, and it may never carry a\n// schema-required field — `no-rule-defaults.spec.ts` fails the build if one appears, and\n// `webpieces-config-defaults-reviewer` fails the PR.\n//\n// Why, in one paragraph. Every rule with a schema is one `webpieces.config.json` must carry an entry\n// for: validateWebpiecesConfig pushes a copy-paste snippet for every RULE_SCHEMAS key the config does\n// not name, and that error FAILS THE LOAD. A default sitting beneath that is therefore not \"the value\n// when nobody said\" — it is the value when the loader is bypassed, and its real effect is to make the\n// question look answered. The consumer ANSWERING it is the product: a repo that was never asked\n// whether merged branches may be deleted unattended is a repo where nobody decided, and an agent\n// authoring a rule is the wrong party to decide that on every downstream repo's behalf. The failing\n// load is the delivery mechanism, exactly as a compile error is for a changed surface — the upgrade\n// breaks, the agent reads \"add this entry\", finds out what it means, and the human chooses.\n//\n// The six entries #1017 measured are gone from here, and every consumer must now state each one in\n// its own config: branch-creation-guard (mode + subBranchNaming + autoReapMergedBranches),\n// pr-lifecycle-guard (mode), branch-state-guard (mode + maxCommitsBehind), no-root-union-api-type,\n// api-rules-for-openapi and api-rules-for-mcp (mode). THIS repo states only the first three today —\n// the other three are new keys the one-release-behind validator does not know yet\n// (.claude/rules/published-vs-local-source.md), so they land with the pin bump, tracked in #1015.\n// `autoReapMergedBranches` and `subBranchNaming` are schema-REQUIRED\n// because they are BEHAVIOUR — one deletes branches unattended, the other decides which branch names\n// are blocked — and behaviour is stated, never inherited. The numeric caps (maxLocalBranches,\n// maxWorktrees) stay optional knobs on purpose: they tune a refusal that PRINTS the cap it hit, so the\n// value is visible at the moment it bites rather than only in webpieces' source.\n// webpieces-disable no-any-unknown -- rule options are opaque at framework level\nexport const defaultRules: Record<string, Record<string, unknown>> = {\n 'no-any-unknown': {},\n 'no-implicit-any': {},\n 'max-file-lines': { limit: 900 },\n 'max-method-lines': { limit: 80 },\n 'require-return-type': {},\n 'no-inline-type-literals': {},\n 'no-destructure': { allowTopLevel: true },\n 'catch-error-pattern': {},\n 'no-unmanaged-exceptions': {},\n 'no-file-import-cycles': {},\n 'runtime-architecture': {},\n 'prisma-validate-dtos': {},\n 'prisma-converter': {},\n 'angular-no-direct-api-in-resolver': {},\n 'no-symbol-di-tokens': {},\n 'no-client-creation-outside-server-or-client': {},\n 'no-custom-css': { allowGlobs: [] },\n 'no-state-paths-in-templates': {},\n 'no-process-exit-outside-main': {},\n 'inject-annotation-not-needed-for-concrete-class': {},\n 'framework-tag': {\n knownTypes: ['browser', 'react', 'angular', 'node', 'express'],\n },\n 'role-tag': {\n knownTypes: ['server', 'app', 'designed-lib', 'lib', 'client', 'api-lib'],\n },\n 'ensure-we-are-secure': {},\n 'nx-wiring': {},\n 'di-graph': {},\n 'missing-design-annotation': {},\n 'validate-ts-in-src': {\n allowedRootFiles: ['jest.setup.ts'],\n excludePaths: [...DEFAULT_EXCLUDE_PATHS],\n },\n 'no-js-files': {},\n 'validate-architecture-unchanged': {},\n 'validate-no-architecture-cycles': {},\n 'validate-packagejson': {},\n 'validate-versions-locked': {},\n 'validate-eslint-sync': {},\n 'no-root-union-api-type': {},\n 'api-rules-for-openapi': {},\n 'api-rules-for-mcp': {},\n // #1023: both REQUIRE `mode` — no entry here may carry one. Like the three above they are new keys\n // the one-release-behind validator does not know yet, so THIS repo's config states them with the\n // pin bump to the release that ships them, tracked in #1024.\n 'no-inline-import-in-api-lib': {},\n 'one-enum-spelling-in-api-lib': {},\n // #1026: REQUIRES `mode` and `paths` — no entry here may carry either. A new key the\n // one-release-behind validator does not know yet, so THIS repo's config states it after publish.\n 'no-utility-types-in-api-lib': {},\n 'branch-creation-guard': {},\n 'pr-lifecycle-guard': {},\n // NOTE: `whole-repo-build-guard` is deliberately ABSENT from this table, and from RULE_SCHEMAS and\n // HOOK_GUARD_NAMES with it. It is EXPERIMENTAL and OFF by default; the ONLY thing that turns it on\n // is `experimental.whole-repo-build-guard: true` in the optional machine-local\n // ~/.webpieces/config.json. Adding it back here would make it a rule every consumer must CONFIGURE\n // — which is fault Y, i.e. every Bash call blocked on upgrade, which is exactly what it did the\n // first time. See RETIRED_CONFIG_KEYS.\n 'branch-state-guard': {},\n};\n\nexport const defaultRulesDir: readonly string[] = [];\n"]}
@@ -6,6 +6,7 @@
6
6
  * delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting
7
7
  * {@link DiffScope} over follow-up PRs, then the delegators are removed.
8
8
  */
9
+ import { FileScope } from './file-scope';
9
10
  /** A git diff range: the base ref to compare against and an optional head (else the working tree). */
10
11
  export declare class DiffRange {
11
12
  base?: string;
@@ -26,18 +27,46 @@ export declare class ChangedFilesOptions {
26
27
  includeDeletions?: boolean;
27
28
  }
28
29
  export declare class DiffScope {
29
- /** Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. */
30
+ /**
31
+ * The {@link FileScope} the current async call chain runs inside. AsyncLocalStorage rather than a
32
+ * field, because the free-function delegators below and every injected instance must see the SAME
33
+ * scope, and because the scope must never leak past the one rule run that set it.
34
+ */
35
+ private static readonly active;
36
+ /**
37
+ * Run `work` with every getChangedFiles / getFileDiff call inside it answering for `scope` — the
38
+ * one switch the whole-scope modes (#1027) and the debug run's `--projects` are built on.
39
+ */
40
+ within<T>(scope: FileScope, work: () => Promise<T>): Promise<T>;
41
+ /** The scope the caller is running inside; plain DIFF outside any {@link within}. */
42
+ currentScope(): FileScope;
43
+ /**
44
+ * Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. Under
45
+ * RUN_EVERY_TIME the base is irrelevant to the file set, so an undetectable one falls back to HEAD
46
+ * rather than making the rule skip.
47
+ */
30
48
  detectBase(workspaceRoot: string): string | null;
49
+ private detectMergeBase;
31
50
  /** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */
32
51
  resolveBase(workspaceRoot: string): DiffRange;
33
52
  /**
34
- * Changed files between base and head (or base→working-tree when head is omitted). Untracked files
35
- * are unioned in for the working-tree case. `tsOnly` (default true) restricts to *.ts/*.tsx and
36
- * drops test files. Deletions are excluded (`--diff-filter=d`).
53
+ * The files a rule judges. Outside any {@link within} (and for the gate's plain diff scope) these are
54
+ * the changed files between base and head (or base→working-tree when head is omitted), untracked
55
+ * files unioned in for the working-tree case. Inside a widened {@link FileScope} they are the files
56
+ * that scope selects — see file-scope.ts. `tsOnly` (default true) restricts to *.ts/*.tsx and drops
57
+ * test files, in every scope. Deletions are excluded (`--diff-filter=d`).
37
58
  */
38
59
  getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[];
39
- /** Diff content for a single file (synthetic all-added diff for an untracked file with no head). */
60
+ private everyChangedFile;
61
+ private diffFiles;
62
+ /**
63
+ * Diff content for a single file (synthetic all-added diff for an untracked file with no head). Inside
64
+ * a whole-scope {@link FileScope} every file is judged WHOLE, so the diff is the synthetic all-added
65
+ * one for every file — a line- or method-scoped rule then sees the entire file as new.
66
+ */
40
67
  getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string;
68
+ private allAddedDiff;
69
+ private realFileDiff;
41
70
  /** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */
42
71
  getChangedLineNumbers(diffContent: string): Set<number>;
43
72
  /** Method names whose signature line is a `+` addition in the diff — the basis of "NEW" methods. */
package/src/diff-scope.js CHANGED
@@ -7,6 +7,7 @@
7
7
  * delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting
8
8
  * {@link DiffScope} over follow-up PRs, then the delegators are removed.
9
9
  */
10
+ var DiffScope_1;
10
11
  Object.defineProperty(exports, "__esModule", { value: true });
11
12
  exports.DiffScope = exports.ChangedFilesOptions = exports.DiffRange = void 0;
12
13
  exports.detectBase = detectBase;
@@ -18,10 +19,12 @@ exports.findNewMethodSignaturesInDiff = findNewMethodSignaturesInDiff;
18
19
  exports.hasChangesInRange = hasChangesInRange;
19
20
  exports.isNewOrModified = isNewOrModified;
20
21
  const tslib_1 = require("tslib");
22
+ const async_hooks_1 = require("async_hooks");
21
23
  const child_process_1 = require("child_process");
22
24
  const fs = tslib_1.__importStar(require("fs"));
23
25
  const path = tslib_1.__importStar(require("path"));
24
26
  const inversify_1 = require("inversify");
27
+ const file_scope_1 = require("./file-scope");
25
28
  const to_error_1 = require("./to-error");
26
29
  /** A git diff range: the base ref to compare against and an optional head (else the working tree). */
27
30
  class DiffRange {
@@ -45,8 +48,36 @@ class ChangedFilesOptions {
45
48
  }
46
49
  exports.ChangedFilesOptions = ChangedFilesOptions;
47
50
  let DiffScope = class DiffScope {
48
- /** Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. */
51
+ static { DiffScope_1 = this; }
52
+ /**
53
+ * The {@link FileScope} the current async call chain runs inside. AsyncLocalStorage rather than a
54
+ * field, because the free-function delegators below and every injected instance must see the SAME
55
+ * scope, and because the scope must never leak past the one rule run that set it.
56
+ */
57
+ static active = new async_hooks_1.AsyncLocalStorage();
58
+ /**
59
+ * Run `work` with every getChangedFiles / getFileDiff call inside it answering for `scope` — the
60
+ * one switch the whole-scope modes (#1027) and the debug run's `--projects` are built on.
61
+ */
62
+ within(scope, work) {
63
+ return DiffScope_1.active.run(scope, work);
64
+ }
65
+ /** The scope the caller is running inside; plain DIFF outside any {@link within}. */
66
+ currentScope() {
67
+ return DiffScope_1.active.getStore() ?? file_scope_1.FileScope.DIFF;
68
+ }
69
+ /**
70
+ * Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. Under
71
+ * RUN_EVERY_TIME the base is irrelevant to the file set, so an undetectable one falls back to HEAD
72
+ * rather than making the rule skip.
73
+ */
49
74
  detectBase(workspaceRoot) {
75
+ const detected = this.detectMergeBase(workspaceRoot);
76
+ if (detected === null && this.currentScope().kind === 'RUN_EVERY_TIME')
77
+ return 'HEAD';
78
+ return detected;
79
+ }
80
+ detectMergeBase(workspaceRoot) {
50
81
  for (const ref of ['origin/main', 'main']) {
51
82
  // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
52
83
  try {
@@ -74,12 +105,29 @@ let DiffScope = class DiffScope {
74
105
  return range;
75
106
  }
76
107
  /**
77
- * Changed files between base and head (or base→working-tree when head is omitted). Untracked files
78
- * are unioned in for the working-tree case. `tsOnly` (default true) restricts to *.ts/*.tsx and
79
- * drops test files. Deletions are excluded (`--diff-filter=d`).
108
+ * The files a rule judges. Outside any {@link within} (and for the gate's plain diff scope) these are
109
+ * the changed files between base and head (or base→working-tree when head is omitted), untracked
110
+ * files unioned in for the working-tree case. Inside a widened {@link FileScope} they are the files
111
+ * that scope selects — see file-scope.ts. `tsOnly` (default true) restricts to *.ts/*.tsx and drops
112
+ * test files, in every scope. Deletions are excluded (`--diff-filter=d`).
80
113
  */
81
- // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths
82
114
  getChangedFiles(workspaceRoot, base, head, opts) {
115
+ const scope = this.currentScope();
116
+ const diffFiles = this.diffFiles(workspaceRoot, base, head, opts);
117
+ if (scope.isPlainDiff())
118
+ return diffFiles;
119
+ const tsOnly = opts?.tsOnly ?? true;
120
+ return new file_scope_1.ScopedFileSelector().select(workspaceRoot, scope, diffFiles, () => this.diffFiles(workspaceRoot, base, head, this.everyChangedFile()), tsOnly ? ['*.ts', '*.tsx'] : [], (f) => !tsOnly || !this.isTestFile(f));
121
+ }
122
+ // "Which projects did the diff touch" counts ANY changed file — a project.json, a README — not only
123
+ // the files the rule itself judges.
124
+ everyChangedFile() {
125
+ const opts = new ChangedFilesOptions();
126
+ opts.tsOnly = false;
127
+ return opts;
128
+ }
129
+ // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths
130
+ diffFiles(workspaceRoot, base, head, opts) {
83
131
  const tsOnly = opts?.tsOnly ?? true;
84
132
  const glob = tsOnly ? " -- '*.ts' '*.tsx'" : '';
85
133
  const keep = (f) => f.length > 0 && (!tsOnly || !this.isTestFile(f));
@@ -119,8 +167,25 @@ let DiffScope = class DiffScope {
119
167
  return [];
120
168
  }
121
169
  }
122
- /** Diff content for a single file (synthetic all-added diff for an untracked file with no head). */
170
+ /**
171
+ * Diff content for a single file (synthetic all-added diff for an untracked file with no head). Inside
172
+ * a whole-scope {@link FileScope} every file is judged WHOLE, so the diff is the synthetic all-added
173
+ * one for every file — a line- or method-scoped rule then sees the entire file as new.
174
+ */
123
175
  getFileDiff(workspaceRoot, file, base, head) {
176
+ if (this.currentScope().isWhole())
177
+ return this.allAddedDiff(workspaceRoot, file);
178
+ return this.realFileDiff(workspaceRoot, file, base, head);
179
+ }
180
+ allAddedDiff(workspaceRoot, file) {
181
+ const fullPath = path.join(workspaceRoot, file);
182
+ if (!fs.existsSync(fullPath))
183
+ return '';
184
+ const lines = fs.readFileSync(fullPath, 'utf-8').split('\n');
185
+ // A real hunk header, so getChangedLineNumbers numbers the lines from 1 like any git diff.
186
+ return [`@@ -0,0 +1,${lines.length} @@`, ...lines.map((l) => `+${l}`)].join('\n');
187
+ }
188
+ realFileDiff(workspaceRoot, file, base, head) {
124
189
  // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
125
190
  try {
126
191
  const diffTarget = head ? `${base} ${head}` : base;
@@ -221,7 +286,7 @@ let DiffScope = class DiffScope {
221
286
  }
222
287
  };
223
288
  exports.DiffScope = DiffScope;
224
- exports.DiffScope = DiffScope = tslib_1.__decorate([
289
+ exports.DiffScope = DiffScope = DiffScope_1 = tslib_1.__decorate([
225
290
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
226
291
  ], DiffScope);
227
292
  // Temporary migration delegators to DiffScope — removed once consumers inject it.
@@ -1 +1 @@
1
- {"version":3,"file":"diff-scope.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/diff-scope.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAqOH,gCAEC;AAGD,kCAEC;AAGD,0CAEC;AAGD,kCAEC;AAGD,sDAEC;AAGD,sEAEC;AAGD,8CAEC;AAGD,0CAQC;;AA9QD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,yCAAqC;AAErC,sGAAsG;AACtG,MAAa,SAAS;IAClB,IAAI,CAAU;IACd,IAAI,CAAU;CACjB;AAHD,8BAGC;AAED,yGAAyG;AACzG,MAAa,mBAAmB;IAC5B,MAAM,CAAW;IACjB;;;;;;;;OAQG;IACH,gBAAgB,CAAW;CAC9B;AAZD,kDAYC;AAGM,IAAM,SAAS,GAAf,MAAM,SAAS;IAClB,kGAAkG;IAClG,UAAU,CAAC,aAAqB;QAC5B,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC;YACxC,8DAA8D;YAC9D,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,uBAAuB,GAAG,EAAE,EAAE;oBAClD,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;iBACzE,CAAC,CAAC,IAAI,EAAE,CAAC;gBACV,IAAI,MAAM;oBAAE,OAAO,MAAM,CAAC;YAC9B,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;gBAC3B,KAAK,KAAK,CAAC,CAAC,6BAA6B;YAC7C,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,4FAA4F;IAC5F,WAAW,C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c,CAAC,CAAC;AAChG,CAAC","sourcesContent":["/**\n * Shared git-diff + diff-scoping service for ALL rule validators (code-rules) and nx executors\n * (nx-webpieces-rules). Centralized here in rules-config because it is the one package both depend on.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it can be injected and appear in the rules-config DI design. Free-function\n * delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting\n * {@link DiffScope} over follow-up PRs, then the delegators are removed.\n */\n\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { toError } from './to-error';\n\n/** A git diff range: the base ref to compare against and an optional head (else the working tree). */\nexport class DiffRange {\n base?: string;\n head?: string;\n}\n\n/** Options for getChangedFiles. `tsOnly` (default true) restricts to *.ts/*.tsx and drops test files. */\nexport class ChangedFilesOptions {\n tsOnly?: boolean;\n /**\n * Include DELETED files in the result. Default false, which is `--diff-filter=d` — the historical\n * behavior, kept as the default so every existing caller is byte-identical.\n *\n * The default is right for lint validators (you cannot lint a file that is gone) and WRONG for checklist\n * matching: a PR that DELETES a migration, an auth check or a terraform rule changed exactly the thing a\n * checklist exists to catch, and dropping it from the changed-file set means the checklist never fires\n * and no reviewer is ever asked. The review flow sets this true.\n */\n includeDeletions?: boolean;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class DiffScope {\n /** Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. */\n detectBase(workspaceRoot: string): string | null {\n for (const ref of ['origin/main', 'main']) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const merged = execSync(`git merge-base HEAD ${ref}`, {\n cwd: workspaceRoot, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n if (merged) return merged;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — try the next ref\n }\n }\n return null;\n }\n\n /** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */\n resolveBase(workspaceRoot: string): DiffRange {\n const range = new DiffRange();\n range.base = process.env['NX_BASE'];\n range.head = process.env['NX_HEAD'];\n if (!range.base) {\n range.base = this.detectBase(workspaceRoot) ?? undefined;\n }\n return range;\n }\n\n /**\n * Changed files between base and head (or base→working-tree when head is omitted). Untracked files\n * are unioned in for the working-tree case. `tsOnly` (default true) restricts to *.ts/*.tsx and\n * drops test files. Deletions are excluded (`--diff-filter=d`).\n */\n // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths\n getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n const tsOnly = opts?.tsOnly ?? true;\n const glob = tsOnly ? \" -- '*.ts' '*.tsx'\" : '';\n const keep = (f: string): boolean => f.length > 0 && (!tsOnly || !this.isTestFile(f));\n // Deletions are excluded by default (see ChangedFilesOptions.includeDeletions) — the review flow\n // opts in, every lint validator keeps the historical filter.\n const filter = opts?.includeDeletions === true ? '' : ' --diff-filter=d';\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const output = execSync(`git diff --name-only${filter} ${diffTarget}${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const changedFiles = output.trim().split('\\n').filter(keep);\n\n // Working-tree comparison (no head): also include untracked files, as nx affected does.\n if (!head) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const untrackedOutput = execSync(`git ls-files --others --exclude-standard${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const untrackedFiles = untrackedOutput.trim().split('\\n').filter(keep);\n return Array.from(new Set([...changedFiles, ...untrackedFiles]));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — ls-files failure falls back to the tracked list\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns an empty list\n return [];\n }\n }\n\n /** Diff content for a single file (synthetic all-added diff for an untracked file with no head). */\n getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const diff = execSync(`git diff ${diffTarget} -- \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n\n if (!diff && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\n const isUntracked = execSync(`git ls-files --others --exclude-standard \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n }).trim();\n\n if (isUntracked) {\n const content = fs.readFileSync(fullPath, 'utf-8');\n return content.split('\\n').map((l: string) => `+${l}`).join('\\n');\n }\n }\n }\n\n return diff;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns no diff\n return '';\n }\n }\n\n /** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */\n getChangedLineNumbers(diffContent: string): Set<number> {\n const changedLines = new Set<number>();\n const lines = diffContent.split('\\n');\n let currentLine = 0;\n\n for (const line of lines) {\n const hunkMatch = line.match(/^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/);\n if (hunkMatch) {\n currentLine = parseInt(hunkMatch[1], 10);\n continue;\n }\n\n if (line.startsWith('+') && !line.startsWith('+++')) {\n changedLines.add(currentLine);\n currentLine++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n // Deletions don't advance the new-file line counter.\n } else {\n currentLine++;\n }\n }\n\n return changedLines;\n }\n\n /** Method names whose signature line is a `+` addition in the diff — the basis of \"NEW\" methods. */\n findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n const newMethods = new Set<string>();\n const lines = diffContent.split('\\n');\n\n const patterns = [\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\n /^\\+\\s*(?:(?:public|private|protected)\\s+)?(?:static\\s+)?(?:async\\s+)?(\\w+)\\s*\\(/,\n ];\n\n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n for (const pattern of patterns) {\n const match = line.match(pattern);\n if (match) {\n const methodName = match[1];\n if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {\n newMethods.add(methodName);\n }\n break;\n }\n }\n }\n }\n\n return newMethods;\n }\n\n /** True if any line in [startLine, endLine] is in the changedLines set. */\n hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n for (let line = startLine; line <= endLine; line++) {\n if (changedLines.has(line)) {\n return true;\n }\n }\n return false;\n }\n\n /** True if a node (method/function) is newly added or has any changed line in its range. */\n isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n ): boolean {\n if (newMethodNames.has(name)) return true;\n return this.hasChangesInRange(startLine, endLine, changedLines);\n }\n\n // A file is \"a test file\" (excluded from diff-scoped rules) when it is a .spec/.test file or lives\n // under a __tests__/ directory.\n private isTestFile(file: string): boolean {\n return file.includes('.spec.ts') || file.includes('.test.ts') || file.includes('__tests__/');\n }\n}\n\n// Temporary migration delegators to DiffScope — removed once consumers inject it.\nconst diffScopeSvc = new DiffScope();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function detectBase(workspaceRoot: string): string | null {\n return diffScopeSvc.detectBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function resolveBase(workspaceRoot: string): DiffRange {\n return diffScopeSvc.resolveBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n return diffScopeSvc.getChangedFiles(workspaceRoot, base, head, opts);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n return diffScopeSvc.getFileDiff(workspaceRoot, file, base, head);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedLineNumbers(diffContent: string): Set<number> {\n return diffScopeSvc.getChangedLineNumbers(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n return diffScopeSvc.findNewMethodSignaturesInDiff(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n return diffScopeSvc.hasChangesInRange(startLine, endLine, changedLines);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n): boolean {\n return diffScopeSvc.isNewOrModified(name, startLine, endLine, changedLines, newMethodNames);\n}\n"]}
1
+ {"version":3,"file":"diff-scope.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/diff-scope.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;AA+SH,gCAEC;AAGD,kCAEC;AAGD,0CAEC;AAGD,kCAEC;AAGD,sDAEC;AAGD,sEAEC;AAGD,8CAEC;AAGD,0CAQC;;AAxVD,6CAAgD;AAChD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,6CAA6D;AAC7D,yCAAqC;AAErC,sGAAsG;AACtG,MAAa,SAAS;IAClB,IAAI,CAAU;IACd,IAAI,CAAU;CACjB;AAHD,8BAGC;AA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AC;AACrE,CAAC;AAED,gIAAgI;AAChI,SAAgB,qBAAqB,CAAC,WAAmB;IACrD,OAAO,YAAY,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;AAC3D,CAAC;AAED,gIAAgI;AAChI,SAAgB,6BAA6B,CAAC,WAAmB;IAC7D,OAAO,YAAY,CAAC,6BAA6B,CAAC,WAAW,CAAC,CAAC;AACnE,CAAC;AAED,gIAAgI;AAChI,SAAgB,iBAAiB,CAAC,SAAiB,EAAE,OAAe,EAAE,YAAyB;IAC3F,OAAO,YAAY,CAAC,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAC5E,CAAC;AAED,gIAAgI;AAChI,SAAgB,eAAe,CAC3B,IAAY,EACZ,SAAiB,EACjB,OAAe,EACf,YAAyB,EACzB,cAA2B;IAE3B,OAAO,YAAY,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;AAChG,CAAC","sourcesContent":["/**\n * Shared git-diff + diff-scoping service for ALL rule validators (code-rules) and nx executors\n * (nx-webpieces-rules). Centralized here in rules-config because it is the one package both depend on.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it can be injected and appear in the rules-config DI design. Free-function\n * delegators are kept temporarily so the many existing consumers stay green; they migrate to injecting\n * {@link DiffScope} over follow-up PRs, then the delegators are removed.\n */\n\nimport { AsyncLocalStorage } from 'async_hooks';\nimport { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { FileScope, ScopedFileSelector } from './file-scope';\nimport { toError } from './to-error';\n\n/** A git diff range: the base ref to compare against and an optional head (else the working tree). */\nexport class DiffRange {\n base?: string;\n head?: string;\n}\n\n/** Options for getChangedFiles. `tsOnly` (default true) restricts to *.ts/*.tsx and drops test files. */\nexport class ChangedFilesOptions {\n tsOnly?: boolean;\n /**\n * Include DELETED files in the result. Default false, which is `--diff-filter=d` — the historical\n * behavior, kept as the default so every existing caller is byte-identical.\n *\n * The default is right for lint validators (you cannot lint a file that is gone) and WRONG for checklist\n * matching: a PR that DELETES a migration, an auth check or a terraform rule changed exactly the thing a\n * checklist exists to catch, and dropping it from the changed-file set means the checklist never fires\n * and no reviewer is ever asked. The review flow sets this true.\n */\n includeDeletions?: boolean;\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class DiffScope {\n /**\n * The {@link FileScope} the current async call chain runs inside. AsyncLocalStorage rather than a\n * field, because the free-function delegators below and every injected instance must see the SAME\n * scope, and because the scope must never leak past the one rule run that set it.\n */\n private static readonly active = new AsyncLocalStorage<FileScope>();\n\n /**\n * Run `work` with every getChangedFiles / getFileDiff call inside it answering for `scope` — the\n * one switch the whole-scope modes (#1027) and the debug run's `--projects` are built on.\n */\n within<T>(scope: FileScope, work: () => Promise<T>): Promise<T> {\n return DiffScope.active.run(scope, work);\n }\n\n /** The scope the caller is running inside; plain DIFF outside any {@link within}. */\n currentScope(): FileScope {\n return DiffScope.active.getStore() ?? FileScope.DIFF;\n }\n\n /**\n * Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. Under\n * RUN_EVERY_TIME the base is irrelevant to the file set, so an undetectable one falls back to HEAD\n * rather than making the rule skip.\n */\n detectBase(workspaceRoot: string): string | null {\n const detected = this.detectMergeBase(workspaceRoot);\n if (detected === null && this.currentScope().kind === 'RUN_EVERY_TIME') return 'HEAD';\n return detected;\n }\n\n private detectMergeBase(workspaceRoot: string): string | null {\n for (const ref of ['origin/main', 'main']) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const merged = execSync(`git merge-base HEAD ${ref}`, {\n cwd: workspaceRoot, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n if (merged) return merged;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — try the next ref\n }\n }\n return null;\n }\n\n /** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */\n resolveBase(workspaceRoot: string): DiffRange {\n const range = new DiffRange();\n range.base = process.env['NX_BASE'];\n range.head = process.env['NX_HEAD'];\n if (!range.base) {\n range.base = this.detectBase(workspaceRoot) ?? undefined;\n }\n return range;\n }\n\n /**\n * The files a rule judges. Outside any {@link within} (and for the gate's plain diff scope) these are\n * the changed files between base and head (or base→working-tree when head is omitted), untracked\n * files unioned in for the working-tree case. Inside a widened {@link FileScope} they are the files\n * that scope selects — see file-scope.ts. `tsOnly` (default true) restricts to *.ts/*.tsx and drops\n * test files, in every scope. Deletions are excluded (`--diff-filter=d`).\n */\n getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n const scope = this.currentScope();\n const diffFiles = this.diffFiles(workspaceRoot, base, head, opts);\n if (scope.isPlainDiff()) return diffFiles;\n const tsOnly = opts?.tsOnly ?? true;\n return new ScopedFileSelector().select(\n workspaceRoot,\n scope,\n diffFiles,\n () => this.diffFiles(workspaceRoot, base, head, this.everyChangedFile()),\n tsOnly ? ['*.ts', '*.tsx'] : [],\n (f: string) => !tsOnly || !this.isTestFile(f),\n );\n }\n\n // \"Which projects did the diff touch\" counts ANY changed file — a project.json, a README — not only\n // the files the rule itself judges.\n private everyChangedFile(): ChangedFilesOptions {\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n return opts;\n }\n\n // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths\n private diffFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n const tsOnly = opts?.tsOnly ?? true;\n const glob = tsOnly ? \" -- '*.ts' '*.tsx'\" : '';\n const keep = (f: string): boolean => f.length > 0 && (!tsOnly || !this.isTestFile(f));\n // Deletions are excluded by default (see ChangedFilesOptions.includeDeletions) — the review flow\n // opts in, every lint validator keeps the historical filter.\n const filter = opts?.includeDeletions === true ? '' : ' --diff-filter=d';\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const output = execSync(`git diff --name-only${filter} ${diffTarget}${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const changedFiles = output.trim().split('\\n').filter(keep);\n\n // Working-tree comparison (no head): also include untracked files, as nx affected does.\n if (!head) {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const untrackedOutput = execSync(`git ls-files --others --exclude-standard${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n const untrackedFiles = untrackedOutput.trim().split('\\n').filter(keep);\n return Array.from(new Set([...changedFiles, ...untrackedFiles]));\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — ls-files failure falls back to the tracked list\n return changedFiles;\n }\n }\n\n return changedFiles;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns an empty list\n return [];\n }\n }\n\n /**\n * Diff content for a single file (synthetic all-added diff for an untracked file with no head). Inside\n * a whole-scope {@link FileScope} every file is judged WHOLE, so the diff is the synthetic all-added\n * one for every file — a line- or method-scoped rule then sees the entire file as new.\n */\n getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n if (this.currentScope().isWhole()) return this.allAddedDiff(workspaceRoot, file);\n return this.realFileDiff(workspaceRoot, file, base, head);\n }\n\n private allAddedDiff(workspaceRoot: string, file: string): string {\n const fullPath = path.join(workspaceRoot, file);\n if (!fs.existsSync(fullPath)) return '';\n const lines = fs.readFileSync(fullPath, 'utf-8').split('\\n');\n // A real hunk header, so getChangedLineNumbers numbers the lines from 1 like any git diff.\n return [`@@ -0,0 +1,${lines.length} @@`, ...lines.map((l: string) => `+${l}`)].join('\\n');\n }\n\n private realFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n const diffTarget = head ? `${base} ${head}` : base;\n const diff = execSync(`git diff ${diffTarget} -- \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n });\n\n if (!diff && !head) {\n const fullPath = path.join(workspaceRoot, file);\n if (fs.existsSync(fullPath)) {\n const isUntracked = execSync(`git ls-files --others --exclude-standard \"${file}\"`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n }).trim();\n\n if (isUntracked) {\n const content = fs.readFileSync(fullPath, 'utf-8');\n return content.split('\\n').map((l: string) => `+${l}`).join('\\n');\n }\n }\n }\n\n return diff;\n } catch (err: unknown) {\n const error = toError(err);\n void error; // swallow — git diff failure returns no diff\n return '';\n }\n }\n\n /** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */\n getChangedLineNumbers(diffContent: string): Set<number> {\n const changedLines = new Set<number>();\n const lines = diffContent.split('\\n');\n let currentLine = 0;\n\n for (const line of lines) {\n const hunkMatch = line.match(/^@@ -\\d+(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@/);\n if (hunkMatch) {\n currentLine = parseInt(hunkMatch[1], 10);\n continue;\n }\n\n if (line.startsWith('+') && !line.startsWith('+++')) {\n changedLines.add(currentLine);\n currentLine++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n // Deletions don't advance the new-file line counter.\n } else {\n currentLine++;\n }\n }\n\n return changedLines;\n }\n\n /** Method names whose signature line is a `+` addition in the diff — the basis of \"NEW\" methods. */\n findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n const newMethods = new Set<string>();\n const lines = diffContent.split('\\n');\n\n const patterns = [\n /^\\+\\s*(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?\\(/,\n /^\\+\\s*(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s+)?function/,\n /^\\+\\s*(?:(?:public|private|protected)\\s+)?(?:static\\s+)?(?:async\\s+)?(\\w+)\\s*\\(/,\n ];\n\n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n for (const pattern of patterns) {\n const match = line.match(pattern);\n if (match) {\n const methodName = match[1];\n if (methodName && !['if', 'for', 'while', 'switch', 'catch', 'constructor'].includes(methodName)) {\n newMethods.add(methodName);\n }\n break;\n }\n }\n }\n }\n\n return newMethods;\n }\n\n /** True if any line in [startLine, endLine] is in the changedLines set. */\n hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n for (let line = startLine; line <= endLine; line++) {\n if (changedLines.has(line)) {\n return true;\n }\n }\n return false;\n }\n\n /** True if a node (method/function) is newly added or has any changed line in its range. */\n isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n ): boolean {\n if (newMethodNames.has(name)) return true;\n return this.hasChangesInRange(startLine, endLine, changedLines);\n }\n\n // A file is \"a test file\" (excluded from diff-scoped rules) when it is a .spec/.test file or lives\n // under a __tests__/ directory.\n private isTestFile(file: string): boolean {\n return file.includes('.spec.ts') || file.includes('.test.ts') || file.includes('__tests__/');\n }\n}\n\n// Temporary migration delegators to DiffScope — removed once consumers inject it.\nconst diffScopeSvc = new DiffScope();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function detectBase(workspaceRoot: string): string | null {\n return diffScopeSvc.detectBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function resolveBase(workspaceRoot: string): DiffRange {\n return diffScopeSvc.resolveBase(workspaceRoot);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n return diffScopeSvc.getChangedFiles(workspaceRoot, base, head, opts);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string {\n return diffScopeSvc.getFileDiff(workspaceRoot, file, base, head);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function getChangedLineNumbers(diffContent: string): Set<number> {\n return diffScopeSvc.getChangedLineNumbers(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function findNewMethodSignaturesInDiff(diffContent: string): Set<string> {\n return diffScopeSvc.findNewMethodSignaturesInDiff(diffContent);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function hasChangesInRange(startLine: number, endLine: number, changedLines: Set<number>): boolean {\n return diffScopeSvc.hasChangesInRange(startLine, endLine, changedLines);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to DiffScope; removed once consumers inject it\nexport function isNewOrModified(\n name: string,\n startLine: number,\n endLine: number,\n changedLines: Set<number>,\n newMethodNames: Set<string>,\n): boolean {\n return diffScopeSvc.isNewOrModified(name, startLine, endLine, changedLines, newMethodNames);\n}\n"]}