@webpieces/rules-config 0.4.926 → 0.4.928
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 +5 -5
- package/src/abstract-rule.d.ts +13 -1
- package/src/abstract-rule.js +17 -1
- package/src/abstract-rule.js.map +1 -1
- package/src/diff-scope.d.ts +8 -0
- package/src/diff-scope.js +15 -1
- package/src/diff-scope.js.map +1 -1
- package/src/exclude-hook-paths.js +4 -3
- package/src/exclude-hook-paths.js.map +1 -1
- package/src/generated-code-paths.js +2 -2
- package/src/generated-code-paths.js.map +1 -1
- package/src/glob-matches.d.ts +8 -0
- package/src/glob-matches.js +49 -0
- package/src/glob-matches.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +14 -7
- package/src/index.js.map +1 -1
- package/src/rule-file-scope.d.ts +33 -0
- package/src/rule-file-scope.js +67 -0
- package/src/rule-file-scope.js.map +1 -0
- package/src/rule-pack-registry.d.ts +25 -0
- package/src/rule-pack-registry.js +62 -5
- package/src/rule-pack-registry.js.map +1 -1
- package/src/rule-pack-sync.js +6 -4
- package/src/rule-pack-sync.js.map +1 -1
- package/src/rule-runtime-modules.d.ts +1 -1
- package/src/rule-runtime-modules.js +4 -2
- package/src/rule-runtime-modules.js.map +1 -1
- package/src/validate-config.d.ts +3 -2
- package/src/validate-config.js +3 -2
- package/src/validate-config.js.map +1 -1
- package/templates/webpieces.filesize.md +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/rules-config",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.928",
|
|
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",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"inversify": "7.10.4",
|
|
20
20
|
"reflect-metadata": "0.2.2",
|
|
21
21
|
"minimatch": "10.0.1",
|
|
22
|
-
"@webpieces/tooling-common": "0.4.
|
|
23
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
24
|
-
"@webpieces/rules-sdk": "0.4.
|
|
22
|
+
"@webpieces/tooling-common": "0.4.928",
|
|
23
|
+
"@webpieces/repo-workflow-core": "0.4.928",
|
|
24
|
+
"@webpieces/rules-sdk": "0.4.928"
|
|
25
25
|
},
|
|
26
26
|
"author": "Dean Hiller",
|
|
27
27
|
"license": "Apache-2.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
37
|
+
"@webpieces/tooling-testkit": "0.4.928"
|
|
38
38
|
},
|
|
39
39
|
"types": "./src/index.d.ts",
|
|
40
40
|
"bin": {
|
package/src/abstract-rule.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseRuleConfig } from '@webpieces/rules-sdk';
|
|
2
|
+
import { RuleFileExclusions } from './rule-file-scope';
|
|
2
3
|
/**
|
|
3
4
|
* Shared base for every rule in BOTH packages (ai-hook-rules and code-rules). A rule is
|
|
4
5
|
* constructed with its typed config (`new NoAnyUnknownRule(config['no-any-unknown'])`), so the
|
|
@@ -32,6 +33,17 @@ export declare abstract class AbstractRule<C extends BaseRuleConfig> {
|
|
|
32
33
|
readonly name: string;
|
|
33
34
|
readonly configKey: string;
|
|
34
35
|
constructor(config: C, name: string, configKey: string);
|
|
35
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* True unless the rule is `mode: "OFF"` or skipped by a branch/epoch escape hatch. Every dispatcher
|
|
38
|
+
* (the code-rules runtime, the build runner, the hook engine) asks this before a rule runs, so no
|
|
39
|
+
* rule checks its own hatches.
|
|
40
|
+
*/
|
|
36
41
|
shouldRun(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* True when this rule's own `excludePaths` matches `relativePath` (workspace-relative). The hook
|
|
44
|
+
* engine asks it before dispatching the rule on a file — the path-filter twin of shouldRun().
|
|
45
|
+
*/
|
|
46
|
+
excludesPath(relativePath: string): boolean;
|
|
47
|
+
/** This rule's exclusions combined with the repo's top-level `excludePaths`, for one rule run. */
|
|
48
|
+
fileExclusions(globalPaths: readonly string[]): RuleFileExclusions;
|
|
37
49
|
}
|
package/src/abstract-rule.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractRule = void 0;
|
|
4
4
|
const skip_rule_1 = require("./skip-rule");
|
|
5
|
+
const rule_file_scope_1 = require("./rule-file-scope");
|
|
5
6
|
/**
|
|
6
7
|
* Shared base for every rule in BOTH packages (ai-hook-rules and code-rules). A rule is
|
|
7
8
|
* constructed with its typed config (`new NoAnyUnknownRule(config['no-any-unknown'])`), so the
|
|
@@ -39,13 +40,28 @@ class AbstractRule {
|
|
|
39
40
|
this.name = name;
|
|
40
41
|
this.configKey = configKey;
|
|
41
42
|
}
|
|
42
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* True unless the rule is `mode: "OFF"` or skipped by a branch/epoch escape hatch. Every dispatcher
|
|
45
|
+
* (the code-rules runtime, the build runner, the hook engine) asks this before a rule runs, so no
|
|
46
|
+
* rule checks its own hatches.
|
|
47
|
+
*/
|
|
43
48
|
shouldRun() {
|
|
44
49
|
if (this.config.mode === 'OFF')
|
|
45
50
|
return false;
|
|
46
51
|
const skip = (0, skip_rule_1.shouldSkipRule)(this.config.turnOffRuleUntilEpoch, this.config.turnOffRuleWhileOnBranch);
|
|
47
52
|
return !skip.skip;
|
|
48
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* True when this rule's own `excludePaths` matches `relativePath` (workspace-relative). The hook
|
|
56
|
+
* engine asks it before dispatching the rule on a file — the path-filter twin of shouldRun().
|
|
57
|
+
*/
|
|
58
|
+
excludesPath(relativePath) {
|
|
59
|
+
return this.fileExclusions([]).excludes(relativePath);
|
|
60
|
+
}
|
|
61
|
+
/** This rule's exclusions combined with the repo's top-level `excludePaths`, for one rule run. */
|
|
62
|
+
fileExclusions(globalPaths) {
|
|
63
|
+
return new rule_file_scope_1.RuleFileExclusions(this.name, globalPaths, this.config.excludePaths ?? []);
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
66
|
exports.AbstractRule = AbstractRule;
|
|
51
67
|
//# sourceMappingURL=abstract-rule.js.map
|
package/src/abstract-rule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/abstract-rule.ts"],"names":[],"mappings":";;;AAEA,2CAA6C;
|
|
1
|
+
{"version":3,"file":"abstract-rule.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/abstract-rule.ts"],"names":[],"mappings":";;;AAEA,2CAA6C;AAC7C,uDAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAsB,YAAY;IACC;IAAoB;IAAuB;IAA1E,YAA+B,MAAS,EAAW,IAAY,EAAW,SAAiB;QAA5D,WAAM,GAAN,MAAM,CAAG;QAAW,SAAI,GAAJ,IAAI,CAAQ;QAAW,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IAE/F;;;;OAIG;IACH,SAAS;QACL,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK;YAAE,OAAO,KAAK,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAA,0BAAc,EAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,EAAE,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACrG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,YAAoB;QAC7B,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED,kGAAkG;IAClG,cAAc,CAAC,WAA8B;QACzC,OAAO,IAAI,oCAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC1F,CAAC;CACJ;AA1BD,oCA0BC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\n\nimport { shouldSkipRule } from './skip-rule';\nimport { RuleFileExclusions } from './rule-file-scope';\n\n/**\n * Shared base for every rule in BOTH packages (ai-hook-rules and code-rules). A rule is\n * constructed with its typed config (`new NoAnyUnknownRule(config['no-any-unknown'])`), so the\n * config class is genuinely consumed — find-usages/rename work across packages.\n *\n * It is execution-agnostic: it owns only `name` + `configKey` + the on/off + escape-hatch decision\n * (`shouldRun`). Each package's base adds its own execution surface (ai-hook `check(ctx)`,\n * code-rules `run(workspaceRoot)`), so rules-config stays free of package-specific types.\n *\n * ## `name` and `configKey` are two different identities, and they are BOTH required\n *\n * `name` is the OPERATOR identity: it is what a decision-log line carries as `rule=`, what a deny\n * report titles itself with, and what prose in `guards/**` names when it describes behaviour. It is\n * per-CLASS and it never changes when the config collapses.\n *\n * `configKey` is the webpieces.config.json KEY whose entry configures this rule. Several classes may\n * share one key when they implement one POLICY — the four branch-state guards all read\n * `branch-state-guard`, the four PR-lifecycle guards all read `pr-lifecycle-guard` — because a\n * consumer switches a POLICY on and off, not an implementation class. Half a policy (`read-stale-guard`\n * OFF while `merged-branch-bash-guard` stays ON: read the file, yes; `cat` the same file, no) was\n * representable while the two were the same string, and this split is what makes it unrepresentable.\n *\n * BOTH are constructor params with NO default. A `configKey = name` default would make the common\n * case silent and the shared case a thing you have to remember — which is the same \"widening that is\n * an ABSENCE rather than a token\" `.claude/rules/no-backwards-compat.md` rejects. Every rule says which\n * key configures it, out loud,\n * so `grep \"'branch-state-guard'\"` lists every class that key governs.\n */\nexport abstract class AbstractRule<C extends BaseRuleConfig> {\n constructor(protected readonly config: C, readonly name: string, readonly configKey: string) {}\n\n /**\n * True unless the rule is `mode: \"OFF\"` or skipped by a branch/epoch escape hatch. Every dispatcher\n * (the code-rules runtime, the build runner, the hook engine) asks this before a rule runs, so no\n * rule checks its own hatches.\n */\n shouldRun(): boolean {\n if (this.config.mode === 'OFF') return false;\n const skip = shouldSkipRule(this.config.turnOffRuleUntilEpoch, this.config.turnOffRuleWhileOnBranch);\n return !skip.skip;\n }\n\n /**\n * True when this rule's own `excludePaths` matches `relativePath` (workspace-relative). The hook\n * engine asks it before dispatching the rule on a file — the path-filter twin of shouldRun().\n */\n excludesPath(relativePath: string): boolean {\n return this.fileExclusions([]).excludes(relativePath);\n }\n\n /** This rule's exclusions combined with the repo's top-level `excludePaths`, for one rule run. */\n fileExclusions(globalPaths: readonly string[]): RuleFileExclusions {\n return new RuleFileExclusions(this.name, globalPaths, this.config.excludePaths ?? []);\n }\n}\n"]}
|
package/src/diff-scope.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export declare class ChangedFilesOptions {
|
|
|
26
26
|
includeDeletions?: boolean;
|
|
27
27
|
}
|
|
28
28
|
export declare class DiffScope {
|
|
29
|
+
private readonly ruleFileScope;
|
|
29
30
|
/** Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. */
|
|
30
31
|
detectBase(workspaceRoot: string): string | null;
|
|
31
32
|
/** Resolve the diff range a rule should compare against (honors nx's NX_BASE / NX_HEAD). */
|
|
@@ -34,8 +35,12 @@ export declare class DiffScope {
|
|
|
34
35
|
* Changed files between base and head (or base→working-tree when head is omitted). Untracked files
|
|
35
36
|
* are unioned in for the working-tree case. `tsOnly` (default true) restricts to *.ts/*.tsx and
|
|
36
37
|
* drops test files. Deletions are excluded (`--diff-filter=d`).
|
|
38
|
+
*
|
|
39
|
+
* Inside a rule run, the files that run's path exclusions match are dropped (#1253): this listing is
|
|
40
|
+
* where the framework applies the top-level and per-rule `excludePaths`, so no rule does it itself.
|
|
37
41
|
*/
|
|
38
42
|
getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[];
|
|
43
|
+
private listChangedFiles;
|
|
39
44
|
/**
|
|
40
45
|
* EVERY file in the working tree — tracked plus untracked-not-ignored, minus files deleted on disk —
|
|
41
46
|
* filtered exactly like {@link getChangedFiles} (`tsOnly` default true: *.ts/*.tsx, no test files).
|
|
@@ -46,8 +51,11 @@ export declare class DiffScope {
|
|
|
46
51
|
* Unlike getChangedFiles it does NOT swallow a git failure into an empty list: an empty whole-scope
|
|
47
52
|
* listing reads as "0 sites left", a false answer to exactly the question these modes exist to
|
|
48
53
|
* answer, so a failed `git ls-files` throws and fails the run.
|
|
54
|
+
*
|
|
55
|
+
* Inside a rule run, the run's path exclusions are applied exactly as in {@link getChangedFiles}.
|
|
49
56
|
*/
|
|
50
57
|
getAllFiles(workspaceRoot: string, opts?: ChangedFilesOptions): string[];
|
|
58
|
+
private listAllFiles;
|
|
51
59
|
/** Diff content for a single file (synthetic all-added diff for an untracked file with no head). */
|
|
52
60
|
getFileDiff(workspaceRoot: string, file: string, base: string, head?: string): string;
|
|
53
61
|
/** Added/changed line numbers (the `+` lines per hunk) — basis of NEW_AND_MODIFIED_CODE scoping. */
|
package/src/diff-scope.js
CHANGED
|
@@ -23,6 +23,7 @@ const fs = tslib_1.__importStar(require("fs"));
|
|
|
23
23
|
const path = tslib_1.__importStar(require("path"));
|
|
24
24
|
const inversify_1 = require("inversify");
|
|
25
25
|
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
26
|
+
const rule_file_scope_1 = require("./rule-file-scope");
|
|
26
27
|
/** A git diff range: the base ref to compare against and an optional head (else the working tree). */
|
|
27
28
|
class DiffRange {
|
|
28
29
|
base;
|
|
@@ -45,6 +46,8 @@ class ChangedFilesOptions {
|
|
|
45
46
|
}
|
|
46
47
|
exports.ChangedFilesOptions = ChangedFilesOptions;
|
|
47
48
|
let DiffScope = class DiffScope {
|
|
49
|
+
// Stateless reader of the rule run in progress (an AsyncLocalStorage store), not a dependency.
|
|
50
|
+
ruleFileScope = new rule_file_scope_1.RuleFileScope();
|
|
48
51
|
/** Auto-detect the diff base: merge-base of HEAD with origin/main, falling back to local main. */
|
|
49
52
|
detectBase(workspaceRoot) {
|
|
50
53
|
for (const ref of ['origin/main', 'main']) {
|
|
@@ -77,9 +80,15 @@ let DiffScope = class DiffScope {
|
|
|
77
80
|
* Changed files between base and head (or base→working-tree when head is omitted). Untracked files
|
|
78
81
|
* are unioned in for the working-tree case. `tsOnly` (default true) restricts to *.ts/*.tsx and
|
|
79
82
|
* drops test files. Deletions are excluded (`--diff-filter=d`).
|
|
83
|
+
*
|
|
84
|
+
* Inside a rule run, the files that run's path exclusions match are dropped (#1253): this listing is
|
|
85
|
+
* where the framework applies the top-level and per-rule `excludePaths`, so no rule does it itself.
|
|
80
86
|
*/
|
|
81
|
-
// webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths
|
|
82
87
|
getChangedFiles(workspaceRoot, base, head, opts) {
|
|
88
|
+
return this.ruleFileScope.filter(this.listChangedFiles(workspaceRoot, base, head, opts));
|
|
89
|
+
}
|
|
90
|
+
// webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths
|
|
91
|
+
listChangedFiles(workspaceRoot, base, head, opts) {
|
|
83
92
|
const tsOnly = opts?.tsOnly ?? true;
|
|
84
93
|
const glob = tsOnly ? " -- '*.ts' '*.tsx'" : '';
|
|
85
94
|
const keep = (f) => f.length > 0 && (!tsOnly || !this.isTestFile(f));
|
|
@@ -129,8 +138,13 @@ let DiffScope = class DiffScope {
|
|
|
129
138
|
* Unlike getChangedFiles it does NOT swallow a git failure into an empty list: an empty whole-scope
|
|
130
139
|
* listing reads as "0 sites left", a false answer to exactly the question these modes exist to
|
|
131
140
|
* answer, so a failed `git ls-files` throws and fails the run.
|
|
141
|
+
*
|
|
142
|
+
* Inside a rule run, the run's path exclusions are applied exactly as in {@link getChangedFiles}.
|
|
132
143
|
*/
|
|
133
144
|
getAllFiles(workspaceRoot, opts) {
|
|
145
|
+
return this.ruleFileScope.filter(this.listAllFiles(workspaceRoot, opts));
|
|
146
|
+
}
|
|
147
|
+
listAllFiles(workspaceRoot, opts) {
|
|
134
148
|
const tsOnly = opts?.tsOnly ?? true;
|
|
135
149
|
const glob = tsOnly ? " -- '*.ts' '*.tsx'" : '';
|
|
136
150
|
const output = (0, child_process_1.execSync)(`git ls-files --cached --others --exclude-standard${glob}`, {
|
package/src/diff-scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff-scope.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/diff-scope.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AA6PH,gCAEC;AAGD,kCAEC;AAGD,0CAEC;AAGD,kCAEC;AAGD,sDAEC;AAGD,sEAEC;AAGD,8CAEC;AAGD,0CAQC;;AAtSD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,iEAA6D;AAE7D,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,CAA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O,YAAY,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAClD,CAAC;AAED,gIAAgI;AAChI,SAAgB,WAAW,CAAC,aAAqB;IAC7C,OAAO,YAAY,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;AACnD,CAAC;AAED,gIAAgI;AAChI,SAAgB,eAAe,CAAC,aAAqB,EAAE,IAAY,EAAE,IAAa,EAAE,IAA0B;IAC1G,OAAO,YAAY,CAAC,eAAe,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACzE,CAAC;AAED,gIAAgI;AAChI,SAAgB,WAAW,CAAC,aAAqB,EAAE,IAAY,EAAE,IAAY,EAAE,IAAa;IACxF,OAAO,YAAY,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;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 { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { toError } from '@webpieces/tooling-common/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 /**\n * EVERY file in the working tree — tracked plus untracked-not-ignored, minus files deleted on disk —\n * filtered exactly like {@link getChangedFiles} (`tsOnly` default true: *.ts/*.tsx, no test files).\n * The file set of the whole-scope modes (#1027): RUN_EVERY_TIME judges all of it, MODIFIED_PROJECTS the\n * part owned by a touched project. Git, not a directory walk, so `.gitignore` (node_modules, dist)\n * is honoured for free.\n *\n * Unlike getChangedFiles it does NOT swallow a git failure into an empty list: an empty whole-scope\n * listing reads as \"0 sites left\", a false answer to exactly the question these modes exist to\n * answer, so a failed `git ls-files` throws and fails the run.\n */\n getAllFiles(workspaceRoot: string, opts?: ChangedFilesOptions): string[] {\n const tsOnly = opts?.tsOnly ?? true;\n const glob = tsOnly ? \" -- '*.ts' '*.tsx'\" : '';\n const output = execSync(`git ls-files --cached --others --exclude-standard${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n maxBuffer: 256 * 1024 * 1024,\n });\n const keep = (f: string): boolean =>\n f.length > 0 && (!tsOnly || !this.isTestFile(f)) && fs.existsSync(path.join(workspaceRoot, f));\n return Array.from(new Set(output.trim().split('\\n').filter(keep)));\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+QH,gCAEC;AAGD,kCAEC;AAGD,0CAEC;AAGD,kCAEC;AAGD,sDAEC;AAGD,sEAEC;AAGD,8CAEC;AAGD,0CAQC;;AAxTD,iDAAyC;AACzC,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAE3D,iEAA6D;AAE7D,uDAAkD;AAElD,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,+FAA+F;IAC9E,aAAa,GAAG,IAAI,+BAAa,EAAE,CAAC;IAErD,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;Y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AAgI;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 { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { toError } from '@webpieces/tooling-common/to-error';\n\nimport { RuleFileScope } from './rule-file-scope';\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 // Stateless reader of the rule run in progress (an AsyncLocalStorage store), not a dependency.\n private readonly ruleFileScope = new RuleFileScope();\n\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 * Inside a rule run, the files that run's path exclusions match are dropped (#1253): this listing is\n * where the framework applies the top-level and per-rule `excludePaths`, so no rule does it itself.\n */\n getChangedFiles(workspaceRoot: string, base: string, head?: string, opts?: ChangedFilesOptions): string[] {\n return this.ruleFileScope.filter(this.listChangedFiles(workspaceRoot, base, head, opts));\n }\n\n // webpieces-disable max-lines-new-methods -- git command handling with untracked files needs several code paths\n private listChangedFiles(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 * EVERY file in the working tree — tracked plus untracked-not-ignored, minus files deleted on disk —\n * filtered exactly like {@link getChangedFiles} (`tsOnly` default true: *.ts/*.tsx, no test files).\n * The file set of the whole-scope modes (#1027): RUN_EVERY_TIME judges all of it, MODIFIED_PROJECTS the\n * part owned by a touched project. Git, not a directory walk, so `.gitignore` (node_modules, dist)\n * is honoured for free.\n *\n * Unlike getChangedFiles it does NOT swallow a git failure into an empty list: an empty whole-scope\n * listing reads as \"0 sites left\", a false answer to exactly the question these modes exist to\n * answer, so a failed `git ls-files` throws and fails the run.\n *\n * Inside a rule run, the run's path exclusions are applied exactly as in {@link getChangedFiles}.\n */\n getAllFiles(workspaceRoot: string, opts?: ChangedFilesOptions): string[] {\n return this.ruleFileScope.filter(this.listAllFiles(workspaceRoot, opts));\n }\n\n private listAllFiles(workspaceRoot: string, opts?: ChangedFilesOptions): string[] {\n const tsOnly = opts?.tsOnly ?? true;\n const glob = tsOnly ? \" -- '*.ts' '*.tsx'\" : '';\n const output = execSync(`git ls-files --cached --others --exclude-standard${glob}`, {\n cwd: workspaceRoot,\n encoding: 'utf-8',\n maxBuffer: 256 * 1024 * 1024,\n });\n const keep = (f: string): boolean =>\n f.length > 0 && (!tsOnly || !this.isTestFile(f)) && fs.existsSync(path.join(workspaceRoot, f));\n return Array.from(new Set(output.trim().split('\\n').filter(keep)));\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"]}
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExcludePaths = void 0;
|
|
4
4
|
exports.isWebpiecesStateDir = isWebpiecesStateDir;
|
|
5
5
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
-
// Top-level `excludePaths` block from webpieces.config.json: ONE glob list
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// Top-level `excludePaths` block from webpieces.config.json: ONE glob list of paths no rule judges
|
|
7
|
+
// (matched against the workspace-relative path by globMatches). A path listed here is hands-off for
|
|
8
|
+
// everything — hook rules, file-scoped guards, AND the build's code rules, which the code-rules runtime
|
|
9
|
+
// filters through RuleFileScope (#1253). One meaning, both engines.
|
|
9
10
|
//
|
|
10
11
|
// It used to be TWO independently-varying lists, `rules` and `guards`. The split never earned its
|
|
11
12
|
// keep: every consumer set both to the same value, and the one case that would need them to differ
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exclude-hook-paths.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/exclude-hook-paths.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"exclude-hook-paths.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/exclude-hook-paths.ts"],"names":[],"mappings":";;;AA8CA,kDAEC;AAhDD,8DAA8D;AAE9D,mGAAmG;AACnG,oGAAoG;AACpG,wGAAwG;AACxG,oEAAoE;AACpE,EAAE;AACF,kGAAkG;AAClG,mGAAmG;AACnG,qGAAqG;AACrG,gGAAgG;AAChG,mEAAmE;AACnE,EAAE;AACF,wGAAwG;AACxG,wGAAwG;AACxG,wGAAwG;AACxG,+FAA+F;AAC/F,MAAa,YAAY;IACA;IAArB,YAAqB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;CAC3C;AAFD,oCAEC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,oKAAoK;AACpK,SAAgB,mBAAmB,CAAC,YAAoB;IACpD,OAAO,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,kCAAiB,CAAC;AAChF,CAAC","sourcesContent":["import { WEBPIECES_TMP_DIR } from '@webpieces/tooling-common';\n\n// Top-level `excludePaths` block from webpieces.config.json: ONE glob list of paths no rule judges\n// (matched against the workspace-relative path by globMatches). A path listed here is hands-off for\n// everything — hook rules, file-scoped guards, AND the build's code rules, which the code-rules runtime\n// filters through RuleFileScope (#1253). One meaning, both engines.\n//\n// It used to be TWO independently-varying lists, `rules` and `guards`. The split never earned its\n// keep: every consumer set both to the same value, and the one case that would need them to differ\n// (exclude a generated tree from style rules but keep the git guards on it) is already served better\n// one level down, by a rule's OWN `excludePaths` inside its config block. A path is governed by\n// webpieces or it is not, so the top-level block is a single list.\n//\n// The object form `{ \"rules\": [...], \"guards\": [...] }` is RETIRED, not accepted — validateExcludePaths\n// rejects it with the union instruction. It was tolerated once, which is precisely why consumer configs\n// (this repo's included) stayed on it: an accepted shape is never migrated. See retired-config-keys.ts.\n// Data-only (per CLAUDE.md, classes for data). Built once by loadAndValidate after validation.\nexport class ExcludePaths {\n constructor(readonly paths: string[]) {}\n}\n\n/**\n * webpieces' OWN state directory is NEVER governed, whatever `excludePaths` says.\n *\n * `.webpieces/` is gitignored in every consumer, so nothing under it can reach a branch, be reviewed,\n * be reverted, or be lost to a checkout — every justification the branch-state guard prints about\n * protecting `main` is vacuous there. Leaving that to config made the exemption OPTIONAL, and the\n * tooling writes into the directory itself: `wp-review-upsert-pr` asks a reviewer subagent to write its\n * verdict to `<primary>/.webpieces/worktrees/agent-<id>/pr-review/<branch>/`, feature-branch-guard\n * resolved that write to the PRIMARY clone and judged the primary's live branch — a tree the subagent\n * is not standing in — so the reviewer was blocked with \"You should not be working on main\" whenever an\n * unrelated session happened to leave the primary there. Hard-coding the skip makes that whole class\n * unreachable, and fixes existing consumer repos the moment they upgrade the pin.\n *\n * THIS IS THE ONLY SPELLING. There is deliberately no companion `.webpieces/**` glob seeded into\n * `excludePaths` — a config entry that changed nothing would be a second spelling of a decision that\n * already has one, and a strictly WEAKER one at that: the repo's glob matcher compiles `.webpieces/**`\n * to an anchored regex whose `/` is literal, so it misses the bare directory `.webpieces` that this\n * predicate matches. A consumer reading such a glob would also conclude the exemption is config-driven\n * and therefore removable, which is exactly the belief this predicate exists to destroy.\n *\n * FIRST SEGMENT ONLY, deliberately: this is the tooling's own directory at the workspace root, not any\n * path that merely contains the name. A `relativePath` that escapes the workspace ('../x'), or that is\n * '' (the Bash path with no `cd`), has a first segment of '..'/'' and does not match.\n */\n// webpieces-disable no-function-outside-class -- leaf predicate over one path string, beside the constant it tests; a class here would be a namespace with no state\nexport function isWebpiecesStateDir(relativePath: string): boolean {\n return relativePath.replace(/\\\\/g, '/').split('/')[0] === WEBPIECES_TMP_DIR;\n}\n"]}
|
|
@@ -10,8 +10,8 @@ exports.GENERATED_CODE_PATHS = void 0;
|
|
|
10
10
|
// `turnOffRuleUntilEpoch`, a GLOBAL off-switch that also stopped the rule on hand-written files —
|
|
11
11
|
// i.e. the protection was removed exactly when a real 1,500-line service class could slip in.
|
|
12
12
|
//
|
|
13
|
-
// So these globs are exempt UNCONDITIONALLY, and a rule's own `
|
|
14
|
-
// than replacing them. A consumer who configures `
|
|
13
|
+
// So these globs are exempt UNCONDITIONALLY, and a rule's own `excludePaths` ADDS to them rather
|
|
14
|
+
// than replacing them. A consumer who configures `excludePaths` for one of their own trees cannot
|
|
15
15
|
// silently lose the generated-code exemption and re-acquire the incident.
|
|
16
16
|
//
|
|
17
17
|
// Matched with the shared `isPathExcluded` glob/prefix/segment semantics, so a bare `dist` matches a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated-code-paths.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/generated-code-paths.ts"],"names":[],"mappings":";;;AAAA,8EAA8E;AAC9E,EAAE;AACF,8CAA8C;AAC9C,gGAAgG;AAChG,kGAAkG;AAClG,qGAAqG;AACrG,kGAAkG;AAClG,8FAA8F;AAC9F,EAAE;AACF,iGAAiG;AACjG,kGAAkG;AAClG,0EAA0E;AAC1E,EAAE;AACF,qGAAqG;AACrG,uFAAuF;AAC1E,QAAA,oBAAoB,GAAsB;IACnD,qBAAqB;IACrB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,MAAM;CACT,CAAC","sourcesContent":["// The machine-generated file trees that a LINE-COUNT rule must never fire on.\n//\n// WHY THIS IS A FLOOR AND NOT A DEFAULT VALUE\n// A `graphql-codegen` client-preset output is 42,000 lines because it embeds the whole upstream\n// schema — the size is a property of a schema nobody in the consuming repo owns, so \"refactor it\"\n// is not advice, it is an impossibility. Before this existed the only escape from max-file-lines was\n// `turnOffRuleUntilEpoch`, a GLOBAL off-switch that also stopped the rule on hand-written files —\n// i.e. the protection was removed exactly when a real 1,500-line service class could slip in.\n//\n// So these globs are exempt UNCONDITIONALLY, and a rule's own `
|
|
1
|
+
{"version":3,"file":"generated-code-paths.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/generated-code-paths.ts"],"names":[],"mappings":";;;AAAA,8EAA8E;AAC9E,EAAE;AACF,8CAA8C;AAC9C,gGAAgG;AAChG,kGAAkG;AAClG,qGAAqG;AACrG,kGAAkG;AAClG,8FAA8F;AAC9F,EAAE;AACF,iGAAiG;AACjG,kGAAkG;AAClG,0EAA0E;AAC1E,EAAE;AACF,qGAAqG;AACrG,uFAAuF;AAC1E,QAAA,oBAAoB,GAAsB;IACnD,qBAAqB;IACrB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,MAAM;CACT,CAAC","sourcesContent":["// The machine-generated file trees that a LINE-COUNT rule must never fire on.\n//\n// WHY THIS IS A FLOOR AND NOT A DEFAULT VALUE\n// A `graphql-codegen` client-preset output is 42,000 lines because it embeds the whole upstream\n// schema — the size is a property of a schema nobody in the consuming repo owns, so \"refactor it\"\n// is not advice, it is an impossibility. Before this existed the only escape from max-file-lines was\n// `turnOffRuleUntilEpoch`, a GLOBAL off-switch that also stopped the rule on hand-written files —\n// i.e. the protection was removed exactly when a real 1,500-line service class could slip in.\n//\n// So these globs are exempt UNCONDITIONALLY, and a rule's own `excludePaths` ADDS to them rather\n// than replacing them. A consumer who configures `excludePaths` for one of their own trees cannot\n// silently lose the generated-code exemption and re-acquire the incident.\n//\n// Matched with the shared `isPathExcluded` glob/prefix/segment semantics, so a bare `dist` matches a\n// `dist` segment at any depth — build output, by construction not authored by anybody.\nexport const GENERATED_CODE_PATHS: readonly string[] = [\n '**/__generated__/**',\n '**/generated/**',\n '**/*.generated.ts',\n '**/*.generated.tsx',\n 'dist',\n];\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE glob matcher of every path exclusion webpieces applies (#1253): the top-level `excludePaths` and
|
|
3
|
+
* each rule's own `excludePaths`, in the hooks AND in the build — one matcher, so one list means one
|
|
4
|
+
* thing everywhere. `**` crosses directories (a following `/` is optional), `*` and `?` stay inside one
|
|
5
|
+
* segment, and the whole workspace-relative path must match (anchored). It moved here from hook-runtime
|
|
6
|
+
* so the code-rules build path can apply the same lists with the same answer.
|
|
7
|
+
*/
|
|
8
|
+
export declare function globMatches(pattern: string, filePath: string): boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globMatches = globMatches;
|
|
4
|
+
/**
|
|
5
|
+
* THE glob matcher of every path exclusion webpieces applies (#1253): the top-level `excludePaths` and
|
|
6
|
+
* each rule's own `excludePaths`, in the hooks AND in the build — one matcher, so one list means one
|
|
7
|
+
* thing everywhere. `**` crosses directories (a following `/` is optional), `*` and `?` stay inside one
|
|
8
|
+
* segment, and the whole workspace-relative path must match (anchored). It moved here from hook-runtime
|
|
9
|
+
* so the code-rules build path can apply the same lists with the same answer.
|
|
10
|
+
*/
|
|
11
|
+
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
12
|
+
function globMatches(pattern, filePath) {
|
|
13
|
+
const regex = globToRegex(pattern);
|
|
14
|
+
return regex.test(filePath);
|
|
15
|
+
}
|
|
16
|
+
// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API
|
|
17
|
+
function globToRegex(pattern) {
|
|
18
|
+
let re = '';
|
|
19
|
+
let i = 0;
|
|
20
|
+
while (i < pattern.length) {
|
|
21
|
+
const ch = pattern[i];
|
|
22
|
+
if (ch === '*') {
|
|
23
|
+
if (pattern[i + 1] === '*') {
|
|
24
|
+
re += '.*';
|
|
25
|
+
i += 2;
|
|
26
|
+
if (pattern[i] === '/')
|
|
27
|
+
i += 1;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
re += '[^/]*';
|
|
31
|
+
i += 1;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (ch === '?') {
|
|
35
|
+
re += '[^/]';
|
|
36
|
+
i += 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if ('.+^$(){}|[]\\'.includes(ch)) {
|
|
40
|
+
re += '\\' + ch;
|
|
41
|
+
i += 1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
re += ch;
|
|
45
|
+
i += 1;
|
|
46
|
+
}
|
|
47
|
+
return new RegExp('^' + re + '$');
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=glob-matches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob-matches.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/glob-matches.ts"],"names":[],"mappings":";;AAQA,kCAGC;AAXD;;;;;;GAMG;AACH,mKAAmK;AACnK,SAAgB,WAAW,CAAC,OAAe,EAAE,QAAgB;IACzD,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,mKAAmK;AACnK,SAAS,WAAW,CAAC,OAAe;IAChC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzB,EAAE,IAAI,IAAI,CAAC;gBACX,CAAC,IAAI,CAAC,CAAC;gBACP,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;oBAAE,CAAC,IAAI,CAAC,CAAC;gBAC/B,SAAS;YACb,CAAC;YACD,EAAE,IAAI,OAAO,CAAC;YACd,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,EAAE,IAAI,MAAM,CAAC;YACb,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC/B,EAAE,IAAI,IAAI,GAAG,EAAE,CAAC;YAChB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,EAAE,IAAI,EAAE,CAAC;QACT,CAAC,IAAI,CAAC,CAAC;IACX,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/**\n * THE glob matcher of every path exclusion webpieces applies (#1253): the top-level `excludePaths` and\n * each rule's own `excludePaths`, in the hooks AND in the build — one matcher, so one list means one\n * thing everywhere. `**` crosses directories (a following `/` is optional), `*` and `?` stay inside one\n * segment, and the whole workspace-relative path must match (anchored). It moved here from hook-runtime\n * so the code-rules build path can apply the same lists with the same answer.\n */\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nexport function globMatches(pattern: string, filePath: string): boolean {\n const regex = globToRegex(pattern);\n return regex.test(filePath);\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless module helper moved intact with its callers; ownership extraction preserves its functional API\nfunction globToRegex(pattern: string): RegExp {\n let re = '';\n let i = 0;\n while (i < pattern.length) {\n const ch = pattern[i];\n if (ch === '*') {\n if (pattern[i + 1] === '*') {\n re += '.*';\n i += 2;\n if (pattern[i] === '/') i += 1;\n continue;\n }\n re += '[^/]*';\n i += 1;\n continue;\n }\n if (ch === '?') {\n re += '[^/]';\n i += 1;\n continue;\n }\n if ('.+^$(){}|[]\\\\'.includes(ch)) {\n re += '\\\\' + ch;\n i += 1;\n continue;\n }\n re += ch;\n i += 1;\n }\n return new RegExp('^' + re + '$');\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export { RulesConfigDesign } from './rules-config-design';
|
|
|
16
16
|
export { DocumentDesign, isDocumentDesign, DESIGN_METADATA_KEYS } from './di';
|
|
17
17
|
export { ExcludePaths, isWebpiecesStateDir } from './exclude-hook-paths';
|
|
18
18
|
export { isPathExcluded, matchesAnyGlob } from './exclude-paths';
|
|
19
|
+
export { globMatches } from './glob-matches';
|
|
20
|
+
export { RuleFileScope, RuleFileExclusions } from './rule-file-scope';
|
|
19
21
|
export { GENERATED_CODE_PATHS } from './generated-code-paths';
|
|
20
22
|
export { NoCustomCssScope, PathScopeConfig } from './no-custom-css-scope';
|
|
21
23
|
export { loadTemplate, writeTemplateIfMissing, writeTemplate, TemplateWriter, } from './load-template';
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.PathMatchCandidate = exports.FirstPathMatchResult = exports.FirstPathMatch = exports.RuntimeContributionGroup = exports.NodeRuleRuntimeModuleLoader = exports.RuleRuntimeModuleLoader = exports.RuleRuntimeModules = exports.RepositoryLayoutRepair = exports.RunCommandCure = exports.EditFileCure = exports.ConfigRepairError = exports.ConfigRepairCure = exports.ConfigRepairBootstrap = exports.ConfigRepairAccess = exports.RulePackSync = exports.PackPolicyFiles = exports.PackPolicyFilesResult = exports.SelectedPolicyPack = exports.PackPolicyDeclaration = exports.LegacyUpgradeResult = exports.LegacyConfigDocument = exports.prepareLegacyUpgrade = exports.RulePackModuleLoader = exports.RulePackDiscovery = exports.NodeRulePackModuleLoader = exports.RulePackRegistry = exports.TMP_SCRATCH_PREFIX = exports.TMP_SCRATCH_RETENTION_DAYS = exports.TmpScratchSweeper = exports.SCRATCH_DIR_NAME = exports.RepoScratchDirs = exports.staleBinSweeper = exports.StaleBinSweeper = exports.StaleBinRemoval = exports.DEFAULT_MERGE_COMPLETE_COMMAND = exports.DEFAULT_UPSERT_PR_COMMAND = exports.buildCommandsConfig = exports.CommandsConfig = exports.summaryJsonSchemaHint = void 0;
|
|
3
|
+
exports.RuleFileExclusions = exports.RuleFileScope = exports.globMatches = exports.matchesAnyGlob = exports.isPathExcluded = exports.isWebpiecesStateDir = exports.ExcludePaths = exports.DESIGN_METADATA_KEYS = exports.isDocumentDesign = exports.DocumentDesign = exports.RulesConfigDesign = exports.atRoot = exports.CLAUDE_PROJECT_DIR_UNSET = exports.CLAUDE_PROJECT_DIR_ENV = exports.claudeEnv = exports.ClaudeEnv = exports.RETENTION_DAYS = exports.SweepCount = exports.AgedTreeSweeper = exports.INSTRUCT_AI_LEAF = exports.INSTRUCT_AI_DIR = exports.RepoRootFinder = exports.RawConfigFile = exports.CONFIG_PARSE_RETRY_MILLIS = exports.CONFIG_PARSE_ATTEMPTS = exports.ConfigParseAttempt = exports.ConfigFile = exports.CONFIG_FILENAME = exports.findConfigFile = exports.RETIRED_TOP_LEVEL_MARKER = exports.RETIRED_KEY_MARKER = exports.CONFIG_POLICY_DOC = exports.formatConfigErrorsBanner = exports.ConfigLoader = exports.LoadedConfig = exports.loadAndValidate = exports.runMain = exports.CliArgs = exports.CliArgsCheck = exports.CliArgSet = exports.CliFlag = exports.CliUsage = exports.CliExitError = exports.formatFixOptions = exports.Option = exports.renderRuleFailForHuman = exports.renderRuleFailForAi = exports.RuleFailError = exports.ResolvedRuleConfig = exports.ResolvedConfig = void 0;
|
|
4
|
+
exports.HOME_EXPERIMENTAL_SECTION = exports.HOME_CONFIG_FILE = exports.HOME_CONFIG_DIR = exports.RETIRED_HOME_CONFIG_KEYS = exports.RetiredHomeConfigKey = exports.HomeConfigService = exports.HomeConfig = exports.validateChecklistDocs = exports.PrunedKey = exports.PruneResult = exports.ConfigPruner = exports.retiredRuleFor = exports.retiredKeyErrorsIn = exports.retiredKeyError = exports.retiredEntry = exports.isRetiredKey = exports.RETIRED_SCOPE_RULE = exports.RETIRED_SCOPE_KEY = exports.RETIRED_CONFIG_KEYS = exports.COMMENT_KEY_SUFFIX = exports.validateTopLevelKeys = exports.isCommentKey = exports.unknownKeyErrors = exports.validateCommandsSection = exports.seedEntryForRule = exports.recommendedSeedModeFor = exports.recommendedSeedMode = exports.allRuleNames = exports.validateMatchRulesSection = exports.validateExcludePaths = exports.validateChecklistsSection = exports.validatePrGateSection = exports.validateWebpiecesConfig = exports.BUILD_LOG_DOC = exports.ReferenceMergeRun = exports.MergeRun = exports.MergeProcessText = exports.MERGE_PROCESS_DOC = exports.MergeProcessDoc = exports.InstructAiDocSet = exports.InstructAiDoc = exports.GitWorkflowDoc = exports.GIT_WORKFLOW_DOC = exports.TemplateWriter = exports.writeTemplate = exports.writeTemplateIfMissing = exports.loadTemplate = exports.PathScopeConfig = exports.NoCustomCssScope = exports.GENERATED_CODE_PATHS = void 0;
|
|
5
|
+
exports.getFileDiff = exports.getChangedFiles = exports.resolveBase = exports.detectBase = exports.SkipRuleResult = exports.HOTFIX_AUDIT_BANNER = exports.HOTFIX_BUILD_COMMAND = exports.shouldSkipRule = exports.sectionForRule = exports.isHookGuard = exports.schemaFieldNames = exports.DEFAULT_MATCH_RULES = exports.renderMatchRuleMessage = exports.compileMatchRulePatterns = exports.isMatchRuleAllowedPath = exports.findMatchRuleViolations = exports.MatchRuleViolation = exports.MatchRuleConfig = exports.OrphanSweepReport = exports.OrphanDirSweeper = exports.TRASH_RETENTION_DAYS = exports.TRASH_MANIFEST_FILE = exports.TRASH_STATE_DIR = exports.OrphanSweepManifest = exports.OrphanSweepResult = exports.FailedOrphan = exports.ArchivedOrphan = exports.OrphanDirArchiver = exports.OrphanCandidate = exports.OrphanDirScanner = exports.MAX_ROW_BYTES = exports.BUILDS_LOG_GENERATIONS = exports.MAX_BUILDS_LOG_BYTES = exports.BUILD_DONE_FAIL = exports.BUILD_DONE_SUCCESS = exports.BUILD_START = exports.BUILDS_LOCK_FILE = exports.BUILDS_LOG_FILE = exports.RunningBuild = exports.BuildTermination = exports.BuildTicket = exports.BuildsLog = exports.DOCUMENTATION_KEYS = exports.HOME_KEY_AI_DOC = exports.HOME_KEY_DOC = exports.DEFAULT_MAX_CONCURRENT_BUILDS = exports.HOME_KEY_TURN_OFF_ALL_REVIEWERS = exports.HOME_KEY_MAX_CONCURRENT_BUILDS = exports.HOME_KEY_WHOLE_REPO_BUILD_GUARD = exports.HOME_KEY_ORPHAN_DIR_SWEEP = void 0;
|
|
6
|
+
exports.ChecklistValidator = exports.formatFileList = exports.normalizeChecklistDoc = exports.toChecklist = exports.DEFAULT_REVIEWER_AGENT_NAME = exports.REVIEWER_AGENTS_PLACEHOLDER = exports.ReviewerAgentPolicy = exports.ChecklistDefinition = exports.MERGE_MODES = exports.MERGE_MODE_NONE = exports.MERGE_MODE_AUTO = exports.buildDevDeployConfig = exports.buildLandPrConfig = exports.buildPrGateConfig = exports.defaultDevDeployConfig = exports.defaultLandPrConfig = exports.defaultPrGateConfig = exports.defaultGates = exports.ReviewContextEntry = exports.DEFAULT_DEV_BRANCH = exports.DEFAULT_DEV_BRANCH_NAMESPACE = exports.DevDeployConfig = exports.LandPrConfig = exports.DEFAULT_BUILD_COMMAND = exports.PrGateConfig = exports.GateDefinition = exports.WP_FINISH_PUSH_DEV = exports.WP_PUSH_DEV = exports.WP_FINISH_UPSERT_PR = exports.WP_START_UPSERT_PR = exports.WP_FINISH_UPDATE = exports.WP_START_UPDATE = exports.SyncFlowGuidance = exports.WebpiecesRulesConfig = exports.UPGRADE_SHIM_COMMAND = exports.PRUNE_UNKNOWN_COMMAND = exports.PUSH_DEV_STATE_FILE = exports.MERGE_EXPLANATION_FILE = exports.MERGE_IN_PROGRESS_FILE = exports.MERGE_INFO_DIR = exports.hasDisable = exports.WEBPIECES_DISABLE = exports.AbstractRule = exports.ChangedFilesOptions = exports.DiffRange = exports.DiffScope = exports.isNewOrModified = exports.hasChangesInRange = exports.findNewMethodSignaturesInDiff = exports.getChangedLineNumbers = void 0;
|
|
7
|
+
exports.ChecklistReviewContext = exports.RequiredChecklist = exports.VERDICT_STATUSES = exports.VERDICT_RED = exports.VERDICT_ORANGE = exports.VERDICT_YELLOW = exports.VERDICT_GREEN = exports.CK_BAD_FORMAT = exports.CK_MISSING = exports.CK_FAIL = exports.CK_ORANGE = exports.CK_ORANGE_FIXED = exports.CK_OVERRIDDEN = exports.CK_WARN = exports.CK_PASS = exports.checklistOverrideService = exports.ChecklistOverrideService = exports.ChecklistOverride = exports.ChecklistVerdict = exports.ChecklistResult = exports.PrContext = exports.PrSummary = exports.DEFAULT_RETENTION_DAYS = exports.ProvenanceWriteRequest = exports.OfferedContext = exports.ReviewerPaths = exports.ReviewerTranscript = exports.ReviewProvenance = exports.ReviewProvenanceService = exports.PROVENANCE_SKIPPED = exports.PROVENANCE_MISSING = exports.PROVENANCE_OK = exports.ProvenanceResult = exports.TranscriptScan = exports.ExpectedReviewer = exports.ReviewerContext = exports.ReviewerEvidence = exports.SubagentProvenanceService = exports.verifyGateToken = exports.extractGateToken = exports.gateTokenMarker = exports.computeGateToken = exports.GateTokenService = exports.ALL_DIFF_ONE_READ_LINES = exports.READ_TRUNCATION_LINES = exports.ContextEntry = exports.BriefedFile = exports.ReviewerBriefing = exports.ReviewerInstructionsService = exports.ChecklistInstructionsService = void 0;
|
|
8
|
+
exports.PathMatchCandidate = exports.FirstPathMatchResult = exports.FirstPathMatch = exports.RuntimeContributionGroup = exports.NodeRuleRuntimeModuleLoader = exports.RuleRuntimeModuleLoader = exports.RuleRuntimeModules = exports.RepositoryLayoutRepair = exports.RunCommandCure = exports.EditFileCure = exports.ConfigRepairError = exports.ConfigRepairCure = exports.ConfigRepairBootstrap = exports.ConfigRepairAccess = exports.RulePackSync = exports.PackPolicyFiles = exports.PackPolicyFilesResult = exports.SelectedPolicyPack = exports.PackPolicyDeclaration = exports.LegacyUpgradeResult = exports.LegacyConfigDocument = exports.prepareLegacyUpgrade = exports.RulePackModuleLoader = exports.RulePackDiscovery = exports.NodeRulePackModuleLoader = exports.RulePackRegistry = exports.TMP_SCRATCH_PREFIX = exports.TMP_SCRATCH_RETENTION_DAYS = exports.TmpScratchSweeper = exports.SCRATCH_DIR_NAME = exports.RepoScratchDirs = exports.staleBinSweeper = exports.StaleBinSweeper = exports.StaleBinRemoval = exports.DEFAULT_MERGE_COMPLETE_COMMAND = exports.DEFAULT_UPSERT_PR_COMMAND = exports.buildCommandsConfig = exports.CommandsConfig = exports.summaryJsonSchemaHint = exports.summaryJsonPath = exports.prDirFor = exports.ReviewJsonService = void 0;
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
var types_1 = require("./types");
|
|
11
11
|
Object.defineProperty(exports, "ResolvedConfig", { enumerable: true, get: function () { return types_1.ResolvedConfig; } });
|
|
@@ -87,8 +87,15 @@ Object.defineProperty(exports, "isWebpiecesStateDir", { enumerable: true, get: f
|
|
|
87
87
|
var exclude_paths_1 = require("./exclude-paths");
|
|
88
88
|
Object.defineProperty(exports, "isPathExcluded", { enumerable: true, get: function () { return exclude_paths_1.isPathExcluded; } });
|
|
89
89
|
Object.defineProperty(exports, "matchesAnyGlob", { enumerable: true, get: function () { return exclude_paths_1.matchesAnyGlob; } });
|
|
90
|
+
var glob_matches_1 = require("./glob-matches");
|
|
91
|
+
Object.defineProperty(exports, "globMatches", { enumerable: true, get: function () { return glob_matches_1.globMatches; } });
|
|
92
|
+
// Framework-applied path exclusions for a rule run (#1253): the dispatcher enters the scope, DiffScope's
|
|
93
|
+
// file listings honour it, so no rule filters its own files.
|
|
94
|
+
var rule_file_scope_1 = require("./rule-file-scope");
|
|
95
|
+
Object.defineProperty(exports, "RuleFileScope", { enumerable: true, get: function () { return rule_file_scope_1.RuleFileScope; } });
|
|
96
|
+
Object.defineProperty(exports, "RuleFileExclusions", { enumerable: true, get: function () { return rule_file_scope_1.RuleFileExclusions; } });
|
|
90
97
|
// The machine-generated trees a line-count rule never fires on. A FLOOR, not a default value:
|
|
91
|
-
// `max-file-lines.
|
|
98
|
+
// `max-file-lines.excludePaths` adds to it, so configuring your own tree cannot lose it.
|
|
92
99
|
var generated_code_paths_1 = require("./generated-code-paths");
|
|
93
100
|
Object.defineProperty(exports, "GENERATED_CODE_PATHS", { enumerable: true, get: function () { return generated_code_paths_1.GENERATED_CODE_PATHS; } });
|
|
94
101
|
// THE one `no-custom-css` path exemption. Both engines that enforce the rule (the edit-time hook and the
|