@webpieces/hook-runtime 0.4.943 → 0.4.944

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/hook-runtime",
3
- "version": "0.4.943",
3
+ "version": "0.4.944",
4
4
  "description": "Agent hook protocol, normalized events, and fail-closed application boundary.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -22,16 +22,16 @@
22
22
  "dependencies": {
23
23
  "inversify": "7.10.4",
24
24
  "reflect-metadata": "0.2.2",
25
- "@webpieces/rules-config": "0.4.943",
26
- "@webpieces/tooling-common": "0.4.943",
25
+ "@webpieces/rules-config": "0.4.944",
26
+ "@webpieces/tooling-common": "0.4.944",
27
27
  "tslib": "2.8.1",
28
- "@webpieces/rules-sdk": "0.4.943"
28
+ "@webpieces/rules-sdk": "0.4.944"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
33
  "devDependencies": {
34
- "@webpieces/tooling-testkit": "0.4.943"
34
+ "@webpieces/tooling-testkit": "0.4.944"
35
35
  },
36
36
  "types": "./src/index.d.ts"
37
37
  }
@@ -1,3 +1,4 @@
1
+ import { InformAiError } from '@webpieces/tooling-common';
1
2
  import { NormalizedToolInput, ToolKind } from '../protocol';
2
3
  /** Character range in the final proposed file. Empty ranges record deletion sites. */
3
4
  export declare class ChangedRange {
@@ -12,6 +13,16 @@ export declare class ProposedContent {
12
13
  constructor(original: string, text: string, changes: readonly ChangedRange[]);
13
14
  changedLines(): ReadonlySet<number>;
14
15
  }
16
+ /**
17
+ * The proposed file cannot be projected from this edit: its context is stale, ambiguous or empty, so no
18
+ * rule may judge guessed content. A structured refusal, not a rule bug — `runRuleCheck` renders it as the
19
+ * deny it is (never "Rule … crashed"). Worded for every harness: Claude Code, Codex and openclaw each name
20
+ * the edit's fields differently, so the cure names the INTENT, never a tool's parameter.
21
+ */
22
+ export declare class ProjectionRefusal extends InformAiError {
23
+ readonly filePath: string;
24
+ constructor(filePath: string, reason: string);
25
+ }
15
26
  /** Lazily projects an operation in memory; existing non-syntax rules need not read the file. */
16
27
  export declare class ProposedFile {
17
28
  private readonly tool;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProposedFile = exports.ProposedContent = exports.ChangedRange = void 0;
3
+ exports.ProposedFile = exports.ProjectionRefusal = exports.ProposedContent = exports.ChangedRange = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
6
  const tooling_common_1 = require("@webpieces/tooling-common");
@@ -35,6 +35,21 @@ class ProposedContent {
35
35
  }
36
36
  }
37
37
  exports.ProposedContent = ProposedContent;
38
+ /**
39
+ * The proposed file cannot be projected from this edit: its context is stale, ambiguous or empty, so no
40
+ * rule may judge guessed content. A structured refusal, not a rule bug — `runRuleCheck` renders it as the
41
+ * deny it is (never "Rule … crashed"). Worded for every harness: Claude Code, Codex and openclaw each name
42
+ * the edit's fields differently, so the cure names the INTENT, never a tool's parameter.
43
+ */
44
+ class ProjectionRefusal extends tooling_common_1.InformAiError {
45
+ filePath;
46
+ constructor(filePath, reason) {
47
+ super(`Cannot judge the edit of ${filePath}: ${reason}`);
48
+ this.name = 'ProjectionRefusal';
49
+ this.filePath = filePath;
50
+ }
51
+ }
52
+ exports.ProjectionRefusal = ProjectionRefusal;
38
53
  /** Lazily projects an operation in memory; existing non-syntax rules need not read the file. */
39
54
  class ProposedFile {
40
55
  tool;
@@ -57,7 +72,7 @@ class ProposedFile {
57
72
  let changes = [];
58
73
  for (const edit of this.input.edits) {
59
74
  if (!edit.oldString)
60
- throw new tooling_common_1.InformAiError(`Cannot project edit of ${this.input.filePath}: old_string is empty. Use Write for a complete file.`);
75
+ throw new ProjectionRefusal(this.input.filePath, 'the edit names no existing text to replace, so there is nothing to locate. Write the complete file in one whole-file write instead, or base the edit on text the file already contains.');
61
76
  let offset = 0;
62
77
  let count = 0;
63
78
  while (true) {
@@ -65,7 +80,7 @@ class ProposedFile {
65
80
  if (start < 0)
66
81
  break;
67
82
  if (!edit.replaceAll && text.indexOf(edit.oldString, start + edit.oldString.length) >= 0)
68
- throw new tooling_common_1.InformAiError(`Cannot project edit of ${this.input.filePath}: old_string matches multiple locations. Supply unique context or replace_all.`);
83
+ throw new ProjectionRefusal(this.input.filePath, 'the text to replace matches multiple locations, so the edit is ambiguous. Include enough surrounding lines that it matches exactly once, or make it an edit that replaces every occurrence.');
69
84
  const end = start + edit.oldString.length;
70
85
  if (edit.oldString === edit.newString) {
71
86
  count++;
@@ -93,7 +108,7 @@ class ProposedFile {
93
108
  break;
94
109
  }
95
110
  if (count === 0)
96
- throw new tooling_common_1.InformAiError(`Cannot project edit of ${this.input.filePath}: old_string does not match the current file. Read the file and retry with current context.`);
111
+ throw new ProjectionRefusal(this.input.filePath, 'the text to replace does not match the current file. Read the file again and base the edit on its current content.');
97
112
  }
98
113
  this.content = new ProposedContent(original, text, text === original ? [] : changes);
99
114
  return this.content;
@@ -1 +1 @@
1
- {"version":3,"file":"proposed-file.js","sourceRoot":"","sources":["../../../../../../packages/tooling/hook-runtime/src/core/proposed-file.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,8DAA0D;AAG1D,sFAAsF;AACtF,MAAa,YAAY;IACA;IAAwB;IAA7C,YAAqB,KAAa,EAAW,GAAW;QAAnC,UAAK,GAAL,KAAK,CAAQ;QAAW,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;CAC/D;AAFD,oCAEC;AAED,MAAa,eAAe;IACH;IAA2B;IAAuB;IAAvE,YAAqB,QAAgB,EAAW,IAAY,EAAW,OAAgC;QAAlF,aAAQ,GAAR,QAAQ,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAE3G,YAAY;QACR,MAAM,KAAK,GAAG,IAAI,GAAG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BAAE,MAAM,EAAE,CAAC;gBAC3H,OAAO,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;gBACvF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC/D,KAAK,EAAE,CAAC;gBACR,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBACvC,IAAI,CAAC,IAAI,CAAC,UAAU;oBAAE,MAAM;YAChC,CAAC;YACD,IAAI,KAAK,KAAK,CAAC;gBAAE,MAAM,IAAI,8BAAa,CAAC,0BAA0B,IAAI,CAAC,KAAK,CAAC,QAAQ,6FAA6F,CAAC,CAAC;QACzL,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACrF,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAnDD,oCAmDC","sourcesContent":["import * as fs from 'fs';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { NormalizedToolInput, ToolKind } from '../protocol';\n\n/** Character range in the final proposed file. Empty ranges record deletion sites. */\nexport class ChangedRange {\n constructor(readonly start: number, readonly end: number) {}\n}\n\nexport class ProposedContent {\n constructor(readonly original: string, readonly text: string, readonly changes: readonly ChangedRange[]) {}\n\n changedLines(): ReadonlySet<number> {\n const lines = new Set<number>();\n for (const range of this.changes) {\n const startLine = this.text.slice(0, range.start).split('\\n').length;\n const endLine = this.text.slice(0, Math.max(range.start, range.end - 1)).split('\\n').length;\n for (let line = startLine; line <= endLine; line++) lines.add(line);\n }\n return lines;\n }\n}\n\n/** Lazily projects an operation in memory; existing non-syntax rules need not read the file. */\nexport class ProposedFile {\n private content: ProposedContent | null = null;\n\n constructor(private readonly tool: ToolKind, private readonly input: NormalizedToolInput) {}\n\n read(): ProposedContent {\n if (this.content) return this.content;\n const original = fs.existsSync(this.input.sourcePath) ? fs.readFileSync(this.input.sourcePath, 'utf8') : '';\n if (this.tool === 'Write') {\n const text = this.input.edits[0]?.newString ?? '';\n this.content = new ProposedContent(original, text, [new ChangedRange(0, text.length)]);\n return this.content;\n }\n let text = original;\n let changes: ChangedRange[] = [];\n for (const edit of this.input.edits) {\n if (!edit.oldString) throw new InformAiError(`Cannot project edit of ${this.input.filePath}: old_string is empty. Use Write for a complete file.`);\n let offset = 0;\n let count = 0;\n while (true) {\n const start = text.indexOf(edit.oldString, offset);\n if (start < 0) break;\n if (!edit.replaceAll && text.indexOf(edit.oldString, start + edit.oldString.length) >= 0)\n throw new InformAiError(`Cannot project edit of ${this.input.filePath}: old_string matches multiple locations. Supply unique context or replace_all.`);\n const end = start + edit.oldString.length;\n if (edit.oldString === edit.newString) {\n count++;\n offset = end;\n if (!edit.replaceAll) break;\n continue;\n }\n const delta = edit.newString.length - edit.oldString.length;\n changes = changes.map((range: ChangedRange): ChangedRange => range.end < start ? range\n : range.start > end ? new ChangedRange(range.start + delta, range.end + delta)\n : new ChangedRange(Math.min(range.start, start), Math.max(start + edit.newString.length, range.end + delta)));\n let prefix = 0;\n while (prefix < edit.oldString.length && prefix < edit.newString.length && edit.oldString[prefix] === edit.newString[prefix]) prefix++;\n let suffix = 0;\n while (suffix < edit.oldString.length - prefix && suffix < edit.newString.length - prefix\n && edit.oldString[edit.oldString.length - suffix - 1] === edit.newString[edit.newString.length - suffix - 1]) suffix++;\n changes.push(new ChangedRange(start + prefix, start + edit.newString.length - suffix));\n text = text.slice(0, start) + edit.newString + text.slice(end);\n count++;\n offset = start + edit.newString.length;\n if (!edit.replaceAll) break;\n }\n if (count === 0) throw new InformAiError(`Cannot project edit of ${this.input.filePath}: old_string does not match the current file. Read the file and retry with current context.`);\n }\n this.content = new ProposedContent(original, text, text === original ? [] : changes);\n return this.content;\n }\n}\n"]}
1
+ {"version":3,"file":"proposed-file.js","sourceRoot":"","sources":["../../../../../../packages/tooling/hook-runtime/src/core/proposed-file.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,8DAA0D;AAG1D,sFAAsF;AACtF,MAAa,YAAY;IACA;IAAwB;IAA7C,YAAqB,KAAa,EAAW,GAAW;QAAnC,UAAK,GAAL,KAAK,CAAQ;QAAW,QAAG,GAAH,GAAG,CAAQ;IAAG,CAAC;CAC/D;AAFD,oCAEC;AAED,MAAa,eAAe;IACH;IAA2B;IAAuB;IAAvE,YAAqB,QAAgB,EAAW,IAAY,EAAW,OAAgC;QAAlF,aAAQ,GAAR,QAAQ,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAyB;IAAG,CAAC;IAE3G,YAAY;QACR,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;QAChC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;YACrE,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;YAC5F,KAAK,IAAI,IAAI,GAAG,SAAS,EAAE,IAAI,IAAI,OAAO,EAAE,IAAI,EAAE;gBAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxE,CAAC;QACD,O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AG,CAAC,CAAC;gBAC/D,KAAK,EAAE,CAAC;gBACR,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;gBACvC,IAAI,CAAC,IAAI,CAAC,UAAU;oBAAE,MAAM;YAChC,CAAC;YACD,IAAI,KAAK,KAAK,CAAC;gBAAE,MAAM,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,oHAAoH,CAAC,CAAC;QAC5L,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACrF,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAnDD,oCAmDC","sourcesContent":["import * as fs from 'fs';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { NormalizedToolInput, ToolKind } from '../protocol';\n\n/** Character range in the final proposed file. Empty ranges record deletion sites. */\nexport class ChangedRange {\n constructor(readonly start: number, readonly end: number) {}\n}\n\nexport class ProposedContent {\n constructor(readonly original: string, readonly text: string, readonly changes: readonly ChangedRange[]) {}\n\n changedLines(): ReadonlySet<number> {\n const lines = new Set<number>();\n for (const range of this.changes) {\n const startLine = this.text.slice(0, range.start).split('\\n').length;\n const endLine = this.text.slice(0, Math.max(range.start, range.end - 1)).split('\\n').length;\n for (let line = startLine; line <= endLine; line++) lines.add(line);\n }\n return lines;\n }\n}\n\n/**\n * The proposed file cannot be projected from this edit: its context is stale, ambiguous or empty, so no\n * rule may judge guessed content. A structured refusal, not a rule bug — `runRuleCheck` renders it as the\n * deny it is (never \"Rule … crashed\"). Worded for every harness: Claude Code, Codex and openclaw each name\n * the edit's fields differently, so the cure names the INTENT, never a tool's parameter.\n */\nexport class ProjectionRefusal extends InformAiError {\n readonly filePath: string;\n\n constructor(filePath: string, reason: string) {\n super(`Cannot judge the edit of ${filePath}: ${reason}`);\n this.name = 'ProjectionRefusal';\n this.filePath = filePath;\n }\n}\n\n/** Lazily projects an operation in memory; existing non-syntax rules need not read the file. */\nexport class ProposedFile {\n private content: ProposedContent | null = null;\n\n constructor(private readonly tool: ToolKind, private readonly input: NormalizedToolInput) {}\n\n read(): ProposedContent {\n if (this.content) return this.content;\n const original = fs.existsSync(this.input.sourcePath) ? fs.readFileSync(this.input.sourcePath, 'utf8') : '';\n if (this.tool === 'Write') {\n const text = this.input.edits[0]?.newString ?? '';\n this.content = new ProposedContent(original, text, [new ChangedRange(0, text.length)]);\n return this.content;\n }\n let text = original;\n let changes: ChangedRange[] = [];\n for (const edit of this.input.edits) {\n if (!edit.oldString) throw new ProjectionRefusal(this.input.filePath, 'the edit names no existing text to replace, so there is nothing to locate. Write the complete file in one whole-file write instead, or base the edit on text the file already contains.');\n let offset = 0;\n let count = 0;\n while (true) {\n const start = text.indexOf(edit.oldString, offset);\n if (start < 0) break;\n if (!edit.replaceAll && text.indexOf(edit.oldString, start + edit.oldString.length) >= 0)\n throw new ProjectionRefusal(this.input.filePath, 'the text to replace matches multiple locations, so the edit is ambiguous. Include enough surrounding lines that it matches exactly once, or make it an edit that replaces every occurrence.');\n const end = start + edit.oldString.length;\n if (edit.oldString === edit.newString) {\n count++;\n offset = end;\n if (!edit.replaceAll) break;\n continue;\n }\n const delta = edit.newString.length - edit.oldString.length;\n changes = changes.map((range: ChangedRange): ChangedRange => range.end < start ? range\n : range.start > end ? new ChangedRange(range.start + delta, range.end + delta)\n : new ChangedRange(Math.min(range.start, start), Math.max(start + edit.newString.length, range.end + delta)));\n let prefix = 0;\n while (prefix < edit.oldString.length && prefix < edit.newString.length && edit.oldString[prefix] === edit.newString[prefix]) prefix++;\n let suffix = 0;\n while (suffix < edit.oldString.length - prefix && suffix < edit.newString.length - prefix\n && edit.oldString[edit.oldString.length - suffix - 1] === edit.newString[edit.newString.length - suffix - 1]) suffix++;\n changes.push(new ChangedRange(start + prefix, start + edit.newString.length - suffix));\n text = text.slice(0, start) + edit.newString + text.slice(end);\n count++;\n offset = start + edit.newString.length;\n if (!edit.replaceAll) break;\n }\n if (count === 0) throw new ProjectionRefusal(this.input.filePath, 'the text to replace does not match the current file. Read the file again and base the edit on its current content.');\n }\n this.content = new ProposedContent(original, text, text === original ? [] : changes);\n return this.content;\n }\n}\n"]}
@@ -6,6 +6,7 @@ exports.runEditRules = runEditRules;
6
6
  exports.runFileRules = runFileRules;
7
7
  const rules_config_1 = require("@webpieces/rules-config");
8
8
  const to_error_1 = require("@webpieces/tooling-common/to-error");
9
+ const tooling_common_1 = require("@webpieces/tooling-common");
9
10
  const types_1 = require("./types");
10
11
  const rules_config_2 = require("@webpieces/rules-config");
11
12
  // Every entry was read from its declared owner file and validated before execution.
@@ -21,6 +22,11 @@ function runRuleCheck(rule, ctx) {
21
22
  if (error instanceof rules_config_1.RuleFailError) {
22
23
  return [violationFromRuleFail(error)];
23
24
  }
25
+ // A structured refusal written for the AI — e.g. ProposedFile refusing stale or ambiguous edit
26
+ // context — is the deny itself, not a bug in the rule, so it is never rendered as "crashed".
27
+ if (error instanceof tooling_common_1.InformAiError) {
28
+ return [new types_1.Violation(0, '', error.message)];
29
+ }
24
30
  return [new types_1.Violation(0, '', `Rule '${rule.name}' crashed: ${error.message}`)];
25
31
  }
26
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rule-evaluation.js","sourceRoot":"","sources":["../../../../../../packages/tooling/hook-runtime/src/core/rule-evaluation.ts"],"names":[],"mappings":";;AAgBA,oCAeC;AAqBD,oCAcC;AAGD,oCAwBC;AAGD,oCAeC;AA/GD,0DAA6E;AAC7E,iEAA6D;AAC7D,mCAQiB;AAEjB,0DAAsD;AAEtD,oFAAoF;AACpF,+HAA+H;AAC/H,SAAgB,YAAY,CACxB,IAAU,EACV,GAA4C;IAE5C,8DAA8D;IAC9D,IAAI,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,6GAA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C,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;QACzF,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,+HAA+H;AAC/H,SAAgB,YAAY,CACxB,KAAsB,EACtB,WAAwB;IAExB,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM;YAAE,SAAS;QACpC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YAAE,SAAS;QAChC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,YAAY,CAAC;YAAE,SAAS;QAC/D,MAAM,EAAE,GAAG,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,IAAI,iBAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACnF,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { RuleFailError, renderRuleFailForAi } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport {\n Rule,\n EditContext,\n FileContext,\n BashContext,\n Violation,\n RuleGroup,\n BlockedResult,\n} from './types';\n\nimport { globMatches } from '@webpieces/rules-config';\n\n// Every entry was read from its declared owner file and validated before execution.\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runRuleCheck(\n rule: Rule,\n ctx: EditContext | FileContext | BashContext,\n): readonly Violation[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return rule.check(ctx);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) {\n return [violationFromRuleFail(error)];\n }\n return [new Violation(0, '', `Rule '${rule.name}' crashed: ${error.message}`)];\n }\n}\n\n// A thrown RuleFailError carries its own AI-facing message + optional location and cures. Fold the\n// cures into the message because Violation has no fixHint field (RuleGroup's fixHint comes from the\n// rule definition, not a per-throw value). The \"Fix Option N:\"/\"(preferred)\" labels come from the ONE\n// framework-owned renderer, exactly as report.ts renders a rule's static FixHint — a rule never\n// hand-numbers its own cures.\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nfunction violationFromRuleFail(error: RuleFailError): Violation {\n return new Violation(error.line ?? 0, error.snippet ?? '', renderRuleFailForAi(error));\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nfunction ruleMatchesFile(rule: Rule, relativePath: string): boolean {\n for (const pattern of rule.files) {\n if (globMatches(pattern, relativePath)) return true;\n }\n return false;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runBashRules(\n rules: readonly Rule[],\n bashContext: BashContext,\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'bash') continue;\n if (!rule.shouldRun()) continue;\n const vs = runRuleCheck(rule, bashContext);\n if (vs.length > 0) {\n groups.push(new RuleGroup(rule.name, rule.description, rule.fixHint, [...vs]));\n }\n }\n return groups;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runEditRules(\n rules: readonly Rule[],\n editContexts: readonly EditContext[],\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'edit') continue;\n if (!rule.shouldRun()) continue;\n const allViolations: Violation[] = [];\n for (const ctx of editContexts) {\n if (!ruleMatchesFile(rule, ctx.relativePath)) continue;\n const vs = runRuleCheck(rule, ctx);\n for (const v of vs) {\n const copy = new Violation(v.line, v.snippet, v.message);\n copy.editIndex = ctx.editIndex;\n copy.editCount = ctx.editCount;\n allViolations.push(copy);\n }\n }\n if (allViolations.length > 0) {\n groups.push(new RuleGroup(rule.name, rule.description, rule.fixHint, allViolations));\n }\n }\n return groups;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runFileRules(\n rules: readonly Rule[],\n fileContext: FileContext,\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'file') continue;\n if (!rule.shouldRun()) continue;\n if (!ruleMatchesFile(rule, fileContext.relativePath)) continue;\n const vs = runRuleCheck(rule, fileContext);\n if (vs.length > 0) {\n groups.push(new RuleGroup(rule.name, rule.description, rule.fixHint, [...vs]));\n }\n }\n return groups;\n}\n"]}
1
+ {"version":3,"file":"rule-evaluation.js","sourceRoot":"","sources":["../../../../../../packages/tooling/hook-runtime/src/core/rule-evaluation.ts"],"names":[],"mappings":";;AAiBA,oCAoBC;AAqBD,oCAcC;AAGD,oCAwBC;AAGD,oCAeC;AArHD,0DAA6E;AAC7E,iEAA6D;AAC7D,8DAA0D;AAC1D,mCAQiB;AAEjB,0DAAsD;AAEtD,oFAAoF;AACpF,+HAA+H;AAC/H,SAAgB,YAAY,CACxB,IAAU,EACV,GAA4C;IAE5C,8DAA8D;IAC9D,IAAI,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,6GAA6G;IAC7G,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,YAAY,4BAAa,EAAE,CAAC;YACjC,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,CAAC;QACD,+FAA+F;QAC/F,6FAA6F;QAC7F,IAAI,KAAK,YA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F,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,+HAA+H;AAC/H,SAAgB,YAAY,CACxB,KAAsB,EACtB,WAAwB;IAExB,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM;YAAE,SAAS;QACpC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YAAE,SAAS;QAChC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,YAAY,CAAC;YAAE,SAAS;QAC/D,MAAM,EAAE,GAAG,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC3C,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChB,MAAM,CAAC,IAAI,CAAC,IAAI,iBAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACnF,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { RuleFailError, renderRuleFailForAi } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport {\n Rule,\n EditContext,\n FileContext,\n BashContext,\n Violation,\n RuleGroup,\n BlockedResult,\n} from './types';\n\nimport { globMatches } from '@webpieces/rules-config';\n\n// Every entry was read from its declared owner file and validated before execution.\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runRuleCheck(\n rule: Rule,\n ctx: EditContext | FileContext | BashContext,\n): readonly Violation[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return rule.check(ctx);\n // webpieces-disable no-any-unknown -- external JSON or runtime exports are validated before policy execution\n } catch (err: unknown) {\n const error = toError(err);\n if (error instanceof RuleFailError) {\n return [violationFromRuleFail(error)];\n }\n // A structured refusal written for the AI — e.g. ProposedFile refusing stale or ambiguous edit\n // context — is the deny itself, not a bug in the rule, so it is never rendered as \"crashed\".\n if (error instanceof InformAiError) {\n return [new Violation(0, '', error.message)];\n }\n return [new Violation(0, '', `Rule '${rule.name}' crashed: ${error.message}`)];\n }\n}\n\n// A thrown RuleFailError carries its own AI-facing message + optional location and cures. Fold the\n// cures into the message because Violation has no fixHint field (RuleGroup's fixHint comes from the\n// rule definition, not a per-throw value). The \"Fix Option N:\"/\"(preferred)\" labels come from the ONE\n// framework-owned renderer, exactly as report.ts renders a rule's static FixHint — a rule never\n// hand-numbers its own cures.\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nfunction violationFromRuleFail(error: RuleFailError): Violation {\n return new Violation(error.line ?? 0, error.snippet ?? '', renderRuleFailForAi(error));\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nfunction ruleMatchesFile(rule: Rule, relativePath: string): boolean {\n for (const pattern of rule.files) {\n if (globMatches(pattern, relativePath)) return true;\n }\n return false;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runBashRules(\n rules: readonly Rule[],\n bashContext: BashContext,\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'bash') continue;\n if (!rule.shouldRun()) continue;\n const vs = runRuleCheck(rule, bashContext);\n if (vs.length > 0) {\n groups.push(new RuleGroup(rule.name, rule.description, rule.fixHint, [...vs]));\n }\n }\n return groups;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runEditRules(\n rules: readonly Rule[],\n editContexts: readonly EditContext[],\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'edit') continue;\n if (!rule.shouldRun()) continue;\n const allViolations: Violation[] = [];\n for (const ctx of editContexts) {\n if (!ruleMatchesFile(rule, ctx.relativePath)) continue;\n const vs = runRuleCheck(rule, ctx);\n for (const v of vs) {\n const copy = new Violation(v.line, v.snippet, v.message);\n copy.editIndex = ctx.editIndex;\n copy.editCount = ctx.editCount;\n allViolations.push(copy);\n }\n }\n if (allViolations.length > 0) {\n groups.push(new RuleGroup(rule.name, rule.description, rule.fixHint, allViolations));\n }\n }\n return groups;\n}\n\n// webpieces-disable no-function-outside-class -- existing stateless evaluator helpers extracted intact for both hook providers\nexport function runFileRules(\n rules: readonly Rule[],\n fileContext: FileContext,\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'file') continue;\n if (!rule.shouldRun()) continue;\n if (!ruleMatchesFile(rule, fileContext.relativePath)) continue;\n const vs = runRuleCheck(rule, fileContext);\n if (vs.length > 0) {\n groups.push(new RuleGroup(rule.name, rule.description, rule.fixHint, [...vs]));\n }\n }\n return groups;\n}\n"]}