@webpieces/ai-hooks 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/bin/setup-ai-hooks.sh +137 -0
- package/openclaw.plugin.json +15 -0
- package/package.json +35 -0
- package/src/adapters/claude-code-hook.d.ts +1 -0
- package/src/adapters/claude-code-hook.js +97 -0
- package/src/adapters/claude-code-hook.js.map +1 -0
- package/src/adapters/openclaw-plugin.d.ts +14 -0
- package/src/adapters/openclaw-plugin.js +73 -0
- package/src/adapters/openclaw-plugin.js.map +1 -0
- package/src/core/build-context.d.ts +7 -0
- package/src/core/build-context.js +58 -0
- package/src/core/build-context.js.map +1 -0
- package/src/core/configs/default.d.ts +2 -0
- package/src/core/configs/default.js +22 -0
- package/src/core/configs/default.js.map +1 -0
- package/src/core/disable-directives.d.ts +9 -0
- package/src/core/disable-directives.js +92 -0
- package/src/core/disable-directives.js.map +1 -0
- package/src/core/load-config.d.ts +3 -0
- package/src/core/load-config.js +81 -0
- package/src/core/load-config.js.map +1 -0
- package/src/core/load-rules.d.ts +3 -0
- package/src/core/load-rules.js +131 -0
- package/src/core/load-rules.js.map +1 -0
- package/src/core/rejection-log.d.ts +2 -0
- package/src/core/rejection-log.js +146 -0
- package/src/core/rejection-log.js.map +1 -0
- package/src/core/report.d.ts +2 -0
- package/src/core/report.js +34 -0
- package/src/core/report.js.map +1 -0
- package/src/core/rules/catch-error-pattern.d.ts +3 -0
- package/src/core/rules/catch-error-pattern.js +91 -0
- package/src/core/rules/catch-error-pattern.js.map +1 -0
- package/src/core/rules/file-location.d.ts +3 -0
- package/src/core/rules/file-location.js +73 -0
- package/src/core/rules/file-location.js.map +1 -0
- package/src/core/rules/index.d.ts +1 -0
- package/src/core/rules/index.js +13 -0
- package/src/core/rules/index.js.map +1 -0
- package/src/core/rules/max-file-lines.d.ts +3 -0
- package/src/core/rules/max-file-lines.js +131 -0
- package/src/core/rules/max-file-lines.js.map +1 -0
- package/src/core/rules/no-any-unknown.d.ts +3 -0
- package/src/core/rules/no-any-unknown.js +30 -0
- package/src/core/rules/no-any-unknown.js.map +1 -0
- package/src/core/rules/no-destructure.d.ts +3 -0
- package/src/core/rules/no-destructure.js +30 -0
- package/src/core/rules/no-destructure.js.map +1 -0
- package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -0
- package/src/core/rules/no-unmanaged-exceptions.js +41 -0
- package/src/core/rules/no-unmanaged-exceptions.js.map +1 -0
- package/src/core/rules/require-return-type.d.ts +3 -0
- package/src/core/rules/require-return-type.js +52 -0
- package/src/core/rules/require-return-type.js.map +1 -0
- package/src/core/runner.d.ts +2 -0
- package/src/core/runner.js +127 -0
- package/src/core/runner.js.map +1 -0
- package/src/core/strip-ts-noise.d.ts +1 -0
- package/src/core/strip-ts-noise.js +178 -0
- package/src/core/strip-ts-noise.js.map +1 -0
- package/src/core/to-error.d.ts +5 -0
- package/src/core/to-error.js +38 -0
- package/src/core/to-error.js.map +1 -0
- package/src/core/types.d.ts +89 -0
- package/src/core/types.js +90 -0
- package/src/core/types.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +24 -0
- package/src/index.js.map +1 -0
- package/templates/claude-settings-hook.json +15 -0
- package/templates/webpieces.ai-hooks.seed.json +16 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = run;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const build_context_1 = require("./build-context");
|
|
7
|
+
const load_config_1 = require("./load-config");
|
|
8
|
+
const load_rules_1 = require("./load-rules");
|
|
9
|
+
const to_error_1 = require("./to-error");
|
|
10
|
+
const report_1 = require("./report");
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
function run(toolKind, input, cwd) {
|
|
13
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
14
|
+
try {
|
|
15
|
+
return runInternal(toolKind, input, cwd);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
const error = (0, to_error_1.toError)(err);
|
|
19
|
+
console.error(`[ai-hooks] runner crashed (failing open): ${error.message}`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function runInternal(toolKind, input, cwd) {
|
|
24
|
+
const config = (0, load_config_1.loadConfig)(cwd);
|
|
25
|
+
if (!config.configPath)
|
|
26
|
+
return null;
|
|
27
|
+
const workspaceRoot = path.dirname(config.configPath);
|
|
28
|
+
const rules = (0, load_rules_1.loadRules)(config, workspaceRoot);
|
|
29
|
+
if (rules.length === 0)
|
|
30
|
+
return null;
|
|
31
|
+
const contexts = (0, build_context_1.buildContexts)(toolKind, input, workspaceRoot);
|
|
32
|
+
const relativePath = path.relative(workspaceRoot, input.filePath);
|
|
33
|
+
const editGroups = runEditRules(rules, contexts.editContexts, config);
|
|
34
|
+
const fileGroups = runFileRules(rules, contexts.fileContext, config);
|
|
35
|
+
const allGroups = [...editGroups, ...fileGroups];
|
|
36
|
+
if (allGroups.length === 0)
|
|
37
|
+
return null;
|
|
38
|
+
const report = (0, report_1.formatReport)(relativePath, allGroups);
|
|
39
|
+
return new types_1.BlockedResult(report);
|
|
40
|
+
}
|
|
41
|
+
function ruleMatchesFile(rule, relativePath) {
|
|
42
|
+
for (const pattern of rule.files) {
|
|
43
|
+
if ((0, load_rules_1.globMatches)(pattern, relativePath))
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
function mergeOptions(defaultOptions, ruleConfig) {
|
|
49
|
+
// webpieces-disable no-any-unknown -- building an options bag from opaque RuleOptions
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const key of Object.keys(defaultOptions))
|
|
52
|
+
out[key] = defaultOptions[key];
|
|
53
|
+
for (const key of Object.keys(ruleConfig.options)) {
|
|
54
|
+
if (key === 'enabled')
|
|
55
|
+
continue;
|
|
56
|
+
out[key] = ruleConfig.options[key];
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function safeCheckEdit(rule, ctx) {
|
|
61
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
62
|
+
try {
|
|
63
|
+
return rule.check(ctx);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
const error = (0, to_error_1.toError)(err);
|
|
67
|
+
process.stderr.write(`[ai-hooks] rule ${rule.name} crashed: ${error.message}\n`);
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function safeCheckFile(rule, ctx) {
|
|
72
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
73
|
+
try {
|
|
74
|
+
return rule.check(ctx);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
const error = (0, to_error_1.toError)(err);
|
|
78
|
+
process.stderr.write(`[ai-hooks] rule ${rule.name} crashed: ${error.message}\n`);
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function runEditRules(rules, editContexts, config) {
|
|
83
|
+
const groups = [];
|
|
84
|
+
for (const rule of rules) {
|
|
85
|
+
if (rule.scope !== 'edit')
|
|
86
|
+
continue;
|
|
87
|
+
const ruleConfig = config.rules.get(rule.name);
|
|
88
|
+
if (!ruleConfig || ruleConfig.enabled === false)
|
|
89
|
+
continue;
|
|
90
|
+
const allViolations = [];
|
|
91
|
+
for (const ctx of editContexts) {
|
|
92
|
+
if (!ruleMatchesFile(rule, ctx.relativePath))
|
|
93
|
+
continue;
|
|
94
|
+
ctx.options = mergeOptions(rule.defaultOptions, ruleConfig);
|
|
95
|
+
const vs = safeCheckEdit(rule, ctx);
|
|
96
|
+
for (const v of vs) {
|
|
97
|
+
const copy = new types_1.Violation(v.line, v.snippet, v.message);
|
|
98
|
+
copy.editIndex = ctx.editIndex;
|
|
99
|
+
copy.editCount = ctx.editCount;
|
|
100
|
+
allViolations.push(copy);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (allViolations.length > 0) {
|
|
104
|
+
groups.push(new types_1.RuleGroup(rule.name, rule.description, [...rule.fixHint], allViolations));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return groups;
|
|
108
|
+
}
|
|
109
|
+
function runFileRules(rules, fileContext, config) {
|
|
110
|
+
const groups = [];
|
|
111
|
+
for (const rule of rules) {
|
|
112
|
+
if (rule.scope !== 'file')
|
|
113
|
+
continue;
|
|
114
|
+
const ruleConfig = config.rules.get(rule.name);
|
|
115
|
+
if (!ruleConfig || ruleConfig.enabled === false)
|
|
116
|
+
continue;
|
|
117
|
+
if (!ruleMatchesFile(rule, fileContext.relativePath))
|
|
118
|
+
continue;
|
|
119
|
+
fileContext.options = mergeOptions(rule.defaultOptions, ruleConfig);
|
|
120
|
+
const vs = safeCheckFile(rule, fileContext);
|
|
121
|
+
if (vs.length > 0) {
|
|
122
|
+
groups.push(new types_1.RuleGroup(rule.name, rule.description, [...rule.fixHint], [...vs]));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return groups;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hooks/src/core/runner.ts"],"names":[],"mappings":";;AAaA,kBAaC;;AA1BD,mDAA6B;AAE7B,mDAAgD;AAChD,+CAA2C;AAC3C,6CAAsD;AACtD,yCAAqC;AACrC,qCAAwC;AACxC,mCAIiB;AAEjB,SAAgB,GAAG,CACf,QAAkB,EAClB,KAA0B,EAC1B,GAAW;IAEX,8DAA8D;IAC9D,IAAI,CAAC;QACD,OAAO,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAY,EAAE,C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","sourcesContent":["import * as path from 'path';\n\nimport { buildContexts } from './build-context';\nimport { loadConfig } from './load-config';\nimport { loadRules, globMatches } from './load-rules';\nimport { toError } from './to-error';\nimport { formatReport } from './report';\nimport {\n ToolKind, NormalizedToolInput, BlockedResult,\n Rule, EditRule, FileRule, Violation, RuleGroup,\n EditContext, FileContext, ResolvedConfig, ResolvedRuleConfig, RuleOptions,\n} from './types';\n\nexport function run(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n cwd: string,\n): BlockedResult | null {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return runInternal(toolKind, input, cwd);\n } catch (err: unknown) {\n const error = toError(err);\n console.error(`[ai-hooks] runner crashed (failing open): ${error.message}`);\n return null;\n }\n}\n\nfunction runInternal(\n toolKind: ToolKind,\n input: NormalizedToolInput,\n cwd: string,\n): BlockedResult | null {\n const config = loadConfig(cwd);\n if (!config.configPath) return null;\n\n const workspaceRoot = path.dirname(config.configPath);\n const rules = loadRules(config, workspaceRoot);\n if (rules.length === 0) return null;\n\n const contexts = buildContexts(toolKind, input, workspaceRoot);\n const relativePath = path.relative(workspaceRoot, input.filePath);\n\n const editGroups = runEditRules(rules, contexts.editContexts, config);\n const fileGroups = runFileRules(rules, contexts.fileContext, config);\n const allGroups = [...editGroups, ...fileGroups];\n\n if (allGroups.length === 0) return null;\n\n const report = formatReport(relativePath, allGroups);\n return new BlockedResult(report);\n}\n\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\nfunction mergeOptions(defaultOptions: RuleOptions, ruleConfig: ResolvedRuleConfig): RuleOptions {\n // webpieces-disable no-any-unknown -- building an options bag from opaque RuleOptions\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(defaultOptions)) out[key] = defaultOptions[key];\n for (const key of Object.keys(ruleConfig.options)) {\n if (key === 'enabled') continue;\n out[key] = ruleConfig.options[key];\n }\n return out;\n}\n\nfunction safeCheckEdit(rule: EditRule, ctx: EditContext): readonly Violation[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return rule.check(ctx);\n } catch (err: unknown) {\n const error = toError(err);\n process.stderr.write(`[ai-hooks] rule ${rule.name} crashed: ${error.message}\\n`);\n return [];\n }\n}\n\nfunction safeCheckFile(rule: FileRule, ctx: FileContext): readonly Violation[] {\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return rule.check(ctx);\n } catch (err: unknown) {\n const error = toError(err);\n process.stderr.write(`[ai-hooks] rule ${rule.name} crashed: ${error.message}\\n`);\n return [];\n }\n}\n\nfunction runEditRules(\n rules: readonly Rule[],\n editContexts: readonly EditContext[],\n config: ResolvedConfig,\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'edit') continue;\n const ruleConfig = config.rules.get(rule.name);\n if (!ruleConfig || ruleConfig.enabled === false) continue;\n const allViolations: Violation[] = [];\n for (const ctx of editContexts) {\n if (!ruleMatchesFile(rule, ctx.relativePath)) continue;\n ctx.options = mergeOptions(rule.defaultOptions, ruleConfig);\n const vs = safeCheckEdit(rule as EditRule, 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(\n rule.name, rule.description, [...rule.fixHint], allViolations,\n ));\n }\n }\n return groups;\n}\n\nfunction runFileRules(\n rules: readonly Rule[],\n fileContext: FileContext,\n config: ResolvedConfig,\n): readonly RuleGroup[] {\n const groups: RuleGroup[] = [];\n for (const rule of rules) {\n if (rule.scope !== 'file') continue;\n const ruleConfig = config.rules.get(rule.name);\n if (!ruleConfig || ruleConfig.enabled === false) continue;\n if (!ruleMatchesFile(rule, fileContext.relativePath)) continue;\n fileContext.options = mergeOptions(rule.defaultOptions, ruleConfig);\n const vs = safeCheckFile(rule as FileRule, fileContext);\n if (vs.length > 0) {\n groups.push(new RuleGroup(\n rule.name, rule.description, [...rule.fixHint], [...vs],\n ));\n }\n }\n return groups;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stripTsNoise(source: string): string;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stripTsNoise = stripTsNoise;
|
|
4
|
+
class StripState {
|
|
5
|
+
constructor(source) {
|
|
6
|
+
this.source = source;
|
|
7
|
+
this.len = source.length;
|
|
8
|
+
this.out = new Array(source.length);
|
|
9
|
+
this.stack = [];
|
|
10
|
+
this.state = 'code';
|
|
11
|
+
this.braceDepth = 0;
|
|
12
|
+
this.i = 0;
|
|
13
|
+
}
|
|
14
|
+
ch() { return this.source[this.i]; }
|
|
15
|
+
next() { return this.i + 1 < this.len ? this.source[this.i + 1] : ''; }
|
|
16
|
+
emit(idx, ch) { this.out[idx] = ch; }
|
|
17
|
+
blank(idx, ch) { this.out[idx] = ch === '\n' ? '\n' : ' '; }
|
|
18
|
+
pushState(newState) {
|
|
19
|
+
this.stack.push({ state: this.state, braceDepth: this.braceDepth });
|
|
20
|
+
this.state = newState;
|
|
21
|
+
}
|
|
22
|
+
popState() {
|
|
23
|
+
const frame = this.stack.pop();
|
|
24
|
+
this.state = frame.state;
|
|
25
|
+
this.braceDepth = frame.braceDepth;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function handleCodeOrInterp(s) {
|
|
29
|
+
const ch = s.ch();
|
|
30
|
+
const next = s.next();
|
|
31
|
+
if (s.state === 'templateInterp') {
|
|
32
|
+
if (ch === '{') {
|
|
33
|
+
s.braceDepth += 1;
|
|
34
|
+
s.emit(s.i, ch);
|
|
35
|
+
s.i += 1;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (ch === '}') {
|
|
39
|
+
if (s.braceDepth === 0) {
|
|
40
|
+
s.emit(s.i, ch);
|
|
41
|
+
s.i += 1;
|
|
42
|
+
s.popState();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
s.braceDepth -= 1;
|
|
46
|
+
s.emit(s.i, ch);
|
|
47
|
+
s.i += 1;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (ch === '/' && next === '/') {
|
|
52
|
+
s.emit(s.i, '/');
|
|
53
|
+
s.emit(s.i + 1, '/');
|
|
54
|
+
s.i += 2;
|
|
55
|
+
s.pushState('lineComment');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (ch === '/' && next === '*') {
|
|
59
|
+
s.emit(s.i, '/');
|
|
60
|
+
s.emit(s.i + 1, '*');
|
|
61
|
+
s.i += 2;
|
|
62
|
+
s.pushState('blockComment');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (ch === '"') {
|
|
66
|
+
s.emit(s.i, '"');
|
|
67
|
+
s.i += 1;
|
|
68
|
+
s.pushState('dquote');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (ch === "'") {
|
|
72
|
+
s.emit(s.i, "'");
|
|
73
|
+
s.i += 1;
|
|
74
|
+
s.pushState('squote');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (ch === '`') {
|
|
78
|
+
s.emit(s.i, '`');
|
|
79
|
+
s.i += 1;
|
|
80
|
+
s.pushState('template');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
s.emit(s.i, ch);
|
|
84
|
+
s.i += 1;
|
|
85
|
+
}
|
|
86
|
+
function handleLineComment(s) {
|
|
87
|
+
if (s.ch() === '\n') {
|
|
88
|
+
s.emit(s.i, '\n');
|
|
89
|
+
s.i += 1;
|
|
90
|
+
s.popState();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
s.blank(s.i, s.ch());
|
|
94
|
+
s.i += 1;
|
|
95
|
+
}
|
|
96
|
+
function handleBlockComment(s) {
|
|
97
|
+
if (s.ch() === '*' && s.next() === '/') {
|
|
98
|
+
s.emit(s.i, '*');
|
|
99
|
+
s.emit(s.i + 1, '/');
|
|
100
|
+
s.i += 2;
|
|
101
|
+
s.popState();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
s.blank(s.i, s.ch());
|
|
105
|
+
s.i += 1;
|
|
106
|
+
}
|
|
107
|
+
function handleStringLiteral(s, quoteChar) {
|
|
108
|
+
const ch = s.ch();
|
|
109
|
+
if (ch === '\\' && s.i + 1 < s.len) {
|
|
110
|
+
s.blank(s.i, ch);
|
|
111
|
+
s.blank(s.i + 1, s.source[s.i + 1]);
|
|
112
|
+
s.i += 2;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (ch === quoteChar) {
|
|
116
|
+
s.emit(s.i, quoteChar);
|
|
117
|
+
s.i += 1;
|
|
118
|
+
s.popState();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
s.blank(s.i, ch);
|
|
122
|
+
s.i += 1;
|
|
123
|
+
}
|
|
124
|
+
function handleTemplate(s) {
|
|
125
|
+
const ch = s.ch();
|
|
126
|
+
if (ch === '\\' && s.i + 1 < s.len) {
|
|
127
|
+
s.blank(s.i, ch);
|
|
128
|
+
s.blank(s.i + 1, s.source[s.i + 1]);
|
|
129
|
+
s.i += 2;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (ch === '`') {
|
|
133
|
+
s.emit(s.i, '`');
|
|
134
|
+
s.i += 1;
|
|
135
|
+
s.popState();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (ch === '$' && s.next() === '{') {
|
|
139
|
+
s.emit(s.i, '$');
|
|
140
|
+
s.emit(s.i + 1, '{');
|
|
141
|
+
s.i += 2;
|
|
142
|
+
s.stack.push({ state: 'template', braceDepth: 0 });
|
|
143
|
+
s.state = 'templateInterp';
|
|
144
|
+
s.braceDepth = 0;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
s.blank(s.i, ch);
|
|
148
|
+
s.i += 1;
|
|
149
|
+
}
|
|
150
|
+
function stripTsNoise(source) {
|
|
151
|
+
const s = new StripState(source);
|
|
152
|
+
while (s.i < s.len) {
|
|
153
|
+
if (s.state === 'code' || s.state === 'templateInterp') {
|
|
154
|
+
handleCodeOrInterp(s);
|
|
155
|
+
}
|
|
156
|
+
else if (s.state === 'lineComment') {
|
|
157
|
+
handleLineComment(s);
|
|
158
|
+
}
|
|
159
|
+
else if (s.state === 'blockComment') {
|
|
160
|
+
handleBlockComment(s);
|
|
161
|
+
}
|
|
162
|
+
else if (s.state === 'dquote') {
|
|
163
|
+
handleStringLiteral(s, '"');
|
|
164
|
+
}
|
|
165
|
+
else if (s.state === 'squote') {
|
|
166
|
+
handleStringLiteral(s, "'");
|
|
167
|
+
}
|
|
168
|
+
else if (s.state === 'template') {
|
|
169
|
+
handleTemplate(s);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
s.emit(s.i, s.ch());
|
|
173
|
+
s.i += 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return s.out.join('');
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=strip-ts-noise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip-ts-noise.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hooks/src/core/strip-ts-noise.ts"],"names":[],"mappings":";;AA0FA,oCAYC;AAjGD,MAAM,UAAU;IASZ,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,IAAI,KAAK,CAAS,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACpB,IAAI,CAA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YAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAAC,CAAC;IAC3C,CAAC;IACD,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["interface StackFrame {\n readonly state: string;\n readonly braceDepth: number;\n}\n\nclass StripState {\n readonly source: string;\n readonly len: number;\n readonly out: string[];\n readonly stack: StackFrame[];\n state: string;\n braceDepth: number;\n i: number;\n\n constructor(source: string) {\n this.source = source;\n this.len = source.length;\n this.out = new Array<string>(source.length);\n this.stack = [];\n this.state = 'code';\n this.braceDepth = 0;\n this.i = 0;\n }\n\n ch(): string { return this.source[this.i]; }\n next(): string { return this.i + 1 < this.len ? this.source[this.i + 1] : ''; }\n emit(idx: number, ch: string): void { this.out[idx] = ch; }\n blank(idx: number, ch: string): void { this.out[idx] = ch === '\\n' ? '\\n' : ' '; }\n\n pushState(newState: string): void {\n this.stack.push({ state: this.state, braceDepth: this.braceDepth });\n this.state = newState;\n }\n\n popState(): void {\n const frame = this.stack.pop()!;\n this.state = frame.state;\n this.braceDepth = frame.braceDepth;\n }\n}\n\nfunction handleCodeOrInterp(s: StripState): void {\n const ch = s.ch();\n const next = s.next();\n\n if (s.state === 'templateInterp') {\n if (ch === '{') { s.braceDepth += 1; s.emit(s.i, ch); s.i += 1; return; }\n if (ch === '}') {\n if (s.braceDepth === 0) { s.emit(s.i, ch); s.i += 1; s.popState(); return; }\n s.braceDepth -= 1; s.emit(s.i, ch); s.i += 1; return;\n }\n }\n if (ch === '/' && next === '/') { s.emit(s.i, '/'); s.emit(s.i + 1, '/'); s.i += 2; s.pushState('lineComment'); return; }\n if (ch === '/' && next === '*') { s.emit(s.i, '/'); s.emit(s.i + 1, '*'); s.i += 2; s.pushState('blockComment'); return; }\n if (ch === '\"') { s.emit(s.i, '\"'); s.i += 1; s.pushState('dquote'); return; }\n if (ch === \"'\") { s.emit(s.i, \"'\"); s.i += 1; s.pushState('squote'); return; }\n if (ch === '`') { s.emit(s.i, '`'); s.i += 1; s.pushState('template'); return; }\n s.emit(s.i, ch); s.i += 1;\n}\n\nfunction handleLineComment(s: StripState): void {\n if (s.ch() === '\\n') { s.emit(s.i, '\\n'); s.i += 1; s.popState(); return; }\n s.blank(s.i, s.ch()); s.i += 1;\n}\n\nfunction handleBlockComment(s: StripState): void {\n if (s.ch() === '*' && s.next() === '/') { s.emit(s.i, '*'); s.emit(s.i + 1, '/'); s.i += 2; s.popState(); return; }\n s.blank(s.i, s.ch()); s.i += 1;\n}\n\nfunction handleStringLiteral(s: StripState, quoteChar: string): void {\n const ch = s.ch();\n if (ch === '\\\\' && s.i + 1 < s.len) { s.blank(s.i, ch); s.blank(s.i + 1, s.source[s.i + 1]); s.i += 2; return; }\n if (ch === quoteChar) { s.emit(s.i, quoteChar); s.i += 1; s.popState(); return; }\n s.blank(s.i, ch); s.i += 1;\n}\n\nfunction handleTemplate(s: StripState): void {\n const ch = s.ch();\n if (ch === '\\\\' && s.i + 1 < s.len) { s.blank(s.i, ch); s.blank(s.i + 1, s.source[s.i + 1]); s.i += 2; return; }\n if (ch === '`') { s.emit(s.i, '`'); s.i += 1; s.popState(); return; }\n if (ch === '$' && s.next() === '{') {\n s.emit(s.i, '$'); s.emit(s.i + 1, '{'); s.i += 2;\n s.stack.push({ state: 'template', braceDepth: 0 });\n s.state = 'templateInterp'; s.braceDepth = 0;\n return;\n }\n s.blank(s.i, ch); s.i += 1;\n}\n\nexport function stripTsNoise(source: string): string {\n const s = new StripState(source);\n while (s.i < s.len) {\n if (s.state === 'code' || s.state === 'templateInterp') { handleCodeOrInterp(s); }\n else if (s.state === 'lineComment') { handleLineComment(s); }\n else if (s.state === 'blockComment') { handleBlockComment(s); }\n else if (s.state === 'dquote') { handleStringLiteral(s, '\"'); }\n else if (s.state === 'squote') { handleStringLiteral(s, \"'\"); }\n else if (s.state === 'template') { handleTemplate(s); }\n else { s.emit(s.i, s.ch()); s.i += 1; }\n }\n return s.out.join('');\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toError = toError;
|
|
4
|
+
// ai-hook-disable-file require-return-type -- toError is a utility copied from dev-config; function return type is on line 6
|
|
5
|
+
/**
|
|
6
|
+
* Lightweight duplicate of @webpieces/core-util toError.
|
|
7
|
+
* ai-hooks is a standalone package and cannot depend on core-util or dev-config.
|
|
8
|
+
*/
|
|
9
|
+
// webpieces-disable no-any-unknown -- toError intentionally accepts unknown to safely convert any thrown value to Error
|
|
10
|
+
function toError(err) {
|
|
11
|
+
if (err instanceof Error) {
|
|
12
|
+
return err;
|
|
13
|
+
}
|
|
14
|
+
if (err && typeof err === 'object') {
|
|
15
|
+
if ('message' in err) {
|
|
16
|
+
const error = new Error(String(err.message));
|
|
17
|
+
if ('stack' in err && typeof err.stack === 'string') {
|
|
18
|
+
error.stack = err.stack;
|
|
19
|
+
}
|
|
20
|
+
if ('name' in err && typeof err.name === 'string') {
|
|
21
|
+
error.name = err.name;
|
|
22
|
+
}
|
|
23
|
+
return error;
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
26
|
+
try {
|
|
27
|
+
return new Error(`Non-Error object thrown: ${JSON.stringify(err)}`);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
//const error = toError(err);
|
|
31
|
+
void err;
|
|
32
|
+
return new Error('Non-Error object thrown (unable to stringify)');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const message = err == null ? 'Null or undefined thrown' : String(err);
|
|
36
|
+
return new Error(message);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=to-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-error.js","sourceRo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ai-hook-disable-file require-return-type -- toError is a utility copied from dev-config; function return type is on line 6\n/**\n * Lightweight duplicate of @webpieces/core-util toError.\n * ai-hooks is a standalone package and cannot depend on core-util or dev-config.\n */\n// webpieces-disable no-any-unknown -- toError intentionally accepts unknown to safely convert any thrown value to Error\nexport function toError(err: unknown): Error {\n if (err instanceof Error) {\n return err;\n }\n\n if (err && typeof err === 'object') {\n if ('message' in err) {\n const error = new Error(String(err.message));\n if ('stack' in err && typeof err.stack === 'string') {\n error.stack = err.stack;\n }\n if ('name' in err && typeof err.name === 'string') {\n error.name = err.name;\n }\n return error;\n }\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return new Error(`Non-Error object thrown: ${JSON.stringify(err)}`);\n } catch (err: unknown) {\n //const error = toError(err);\n void err;\n return new Error('Non-Error object thrown (unable to stringify)');\n }\n }\n\n const message = err == null ? 'Null or undefined thrown' : String(err);\n return new Error(message);\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type ToolKind = 'Write' | 'Edit' | 'MultiEdit';
|
|
2
|
+
export type RuleScope = 'edit' | 'file';
|
|
3
|
+
export type RuleOptions = Record<string, unknown>;
|
|
4
|
+
export type IsLineDisabled = (lineNum: number, ruleName: string) => boolean;
|
|
5
|
+
export declare class Violation {
|
|
6
|
+
readonly line: number;
|
|
7
|
+
readonly snippet: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
editIndex: number | undefined;
|
|
10
|
+
editCount: number | undefined;
|
|
11
|
+
constructor(line: number, snippet: string, message: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class NormalizedEdit {
|
|
14
|
+
readonly oldString: string;
|
|
15
|
+
readonly newString: string;
|
|
16
|
+
constructor(oldString: string, newString: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class NormalizedToolInput {
|
|
19
|
+
readonly filePath: string;
|
|
20
|
+
readonly edits: readonly NormalizedEdit[];
|
|
21
|
+
constructor(filePath: string, edits: readonly NormalizedEdit[]);
|
|
22
|
+
}
|
|
23
|
+
export declare class EditContext {
|
|
24
|
+
readonly tool: ToolKind;
|
|
25
|
+
readonly editIndex: number;
|
|
26
|
+
readonly editCount: number;
|
|
27
|
+
readonly filePath: string;
|
|
28
|
+
readonly relativePath: string;
|
|
29
|
+
readonly workspaceRoot: string;
|
|
30
|
+
readonly addedContent: string;
|
|
31
|
+
readonly strippedContent: string;
|
|
32
|
+
readonly lines: readonly string[];
|
|
33
|
+
readonly strippedLines: readonly string[];
|
|
34
|
+
readonly removedContent: string;
|
|
35
|
+
readonly isLineDisabled: IsLineDisabled;
|
|
36
|
+
options: RuleOptions;
|
|
37
|
+
constructor(tool: ToolKind, editIndex: number, editCount: number, filePath: string, relativePath: string, workspaceRoot: string, addedContent: string, strippedContent: string, lines: readonly string[], strippedLines: readonly string[], removedContent: string, isLineDisabled: IsLineDisabled);
|
|
38
|
+
}
|
|
39
|
+
export declare class FileContext {
|
|
40
|
+
readonly tool: ToolKind;
|
|
41
|
+
readonly filePath: string;
|
|
42
|
+
readonly relativePath: string;
|
|
43
|
+
readonly workspaceRoot: string;
|
|
44
|
+
readonly currentFileLines: number;
|
|
45
|
+
readonly linesAdded: number;
|
|
46
|
+
readonly linesRemoved: number;
|
|
47
|
+
readonly projectedFileLines: number;
|
|
48
|
+
options: RuleOptions;
|
|
49
|
+
constructor(tool: ToolKind, filePath: string, relativePath: string, workspaceRoot: string, currentFileLines: number, linesAdded: number, linesRemoved: number, projectedFileLines: number);
|
|
50
|
+
}
|
|
51
|
+
interface RuleBase {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly description: string;
|
|
54
|
+
readonly files: readonly string[];
|
|
55
|
+
readonly defaultOptions: RuleOptions;
|
|
56
|
+
readonly fixHint: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
export interface EditRule extends RuleBase {
|
|
59
|
+
readonly scope: 'edit';
|
|
60
|
+
check(ctx: EditContext): readonly Violation[];
|
|
61
|
+
}
|
|
62
|
+
export interface FileRule extends RuleBase {
|
|
63
|
+
readonly scope: 'file';
|
|
64
|
+
check(ctx: FileContext): readonly Violation[];
|
|
65
|
+
}
|
|
66
|
+
export type Rule = EditRule | FileRule;
|
|
67
|
+
export declare class RuleGroup {
|
|
68
|
+
readonly ruleName: string;
|
|
69
|
+
readonly ruleDescription: string;
|
|
70
|
+
readonly fixHint: readonly string[];
|
|
71
|
+
readonly violations: readonly Violation[];
|
|
72
|
+
constructor(ruleName: string, ruleDescription: string, fixHint: readonly string[], violations: readonly Violation[]);
|
|
73
|
+
}
|
|
74
|
+
export declare class BlockedResult {
|
|
75
|
+
readonly report: string;
|
|
76
|
+
constructor(report: string);
|
|
77
|
+
}
|
|
78
|
+
export declare class ResolvedConfig {
|
|
79
|
+
readonly rules: Map<string, ResolvedRuleConfig>;
|
|
80
|
+
readonly rulesDir: readonly string[];
|
|
81
|
+
readonly configPath: string | null;
|
|
82
|
+
constructor(rules: Map<string, ResolvedRuleConfig>, rulesDir: readonly string[], configPath: string | null);
|
|
83
|
+
}
|
|
84
|
+
export declare class ResolvedRuleConfig {
|
|
85
|
+
readonly enabled: boolean;
|
|
86
|
+
readonly options: RuleOptions;
|
|
87
|
+
constructor(enabled: boolean, options: RuleOptions);
|
|
88
|
+
}
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResolvedRuleConfig = exports.ResolvedConfig = exports.BlockedResult = exports.RuleGroup = exports.FileContext = exports.EditContext = exports.NormalizedToolInput = exports.NormalizedEdit = exports.Violation = void 0;
|
|
4
|
+
class Violation {
|
|
5
|
+
constructor(line, snippet, message) {
|
|
6
|
+
this.line = line;
|
|
7
|
+
this.snippet = snippet;
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.editIndex = undefined;
|
|
10
|
+
this.editCount = undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Violation = Violation;
|
|
14
|
+
class NormalizedEdit {
|
|
15
|
+
constructor(oldString, newString) {
|
|
16
|
+
this.oldString = oldString;
|
|
17
|
+
this.newString = newString;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.NormalizedEdit = NormalizedEdit;
|
|
21
|
+
class NormalizedToolInput {
|
|
22
|
+
constructor(filePath, edits) {
|
|
23
|
+
this.filePath = filePath;
|
|
24
|
+
this.edits = edits;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.NormalizedToolInput = NormalizedToolInput;
|
|
28
|
+
class EditContext {
|
|
29
|
+
constructor(tool, editIndex, editCount, filePath, relativePath, workspaceRoot, addedContent, strippedContent, lines, strippedLines, removedContent, isLineDisabled) {
|
|
30
|
+
this.tool = tool;
|
|
31
|
+
this.editIndex = editIndex;
|
|
32
|
+
this.editCount = editCount;
|
|
33
|
+
this.filePath = filePath;
|
|
34
|
+
this.relativePath = relativePath;
|
|
35
|
+
this.workspaceRoot = workspaceRoot;
|
|
36
|
+
this.addedContent = addedContent;
|
|
37
|
+
this.strippedContent = strippedContent;
|
|
38
|
+
this.lines = lines;
|
|
39
|
+
this.strippedLines = strippedLines;
|
|
40
|
+
this.removedContent = removedContent;
|
|
41
|
+
this.isLineDisabled = isLineDisabled;
|
|
42
|
+
this.options = {};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.EditContext = EditContext;
|
|
46
|
+
class FileContext {
|
|
47
|
+
constructor(tool, filePath, relativePath, workspaceRoot, currentFileLines, linesAdded, linesRemoved, projectedFileLines) {
|
|
48
|
+
this.tool = tool;
|
|
49
|
+
this.filePath = filePath;
|
|
50
|
+
this.relativePath = relativePath;
|
|
51
|
+
this.workspaceRoot = workspaceRoot;
|
|
52
|
+
this.currentFileLines = currentFileLines;
|
|
53
|
+
this.linesAdded = linesAdded;
|
|
54
|
+
this.linesRemoved = linesRemoved;
|
|
55
|
+
this.projectedFileLines = projectedFileLines;
|
|
56
|
+
this.options = {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.FileContext = FileContext;
|
|
60
|
+
class RuleGroup {
|
|
61
|
+
constructor(ruleName, ruleDescription, fixHint, violations) {
|
|
62
|
+
this.ruleName = ruleName;
|
|
63
|
+
this.ruleDescription = ruleDescription;
|
|
64
|
+
this.fixHint = fixHint;
|
|
65
|
+
this.violations = violations;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.RuleGroup = RuleGroup;
|
|
69
|
+
class BlockedResult {
|
|
70
|
+
constructor(report) {
|
|
71
|
+
this.report = report;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.BlockedResult = BlockedResult;
|
|
75
|
+
class ResolvedConfig {
|
|
76
|
+
constructor(rules, rulesDir, configPath) {
|
|
77
|
+
this.rules = rules;
|
|
78
|
+
this.rulesDir = rulesDir;
|
|
79
|
+
this.configPath = configPath;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ResolvedConfig = ResolvedConfig;
|
|
83
|
+
class ResolvedRuleConfig {
|
|
84
|
+
constructor(enabled, options) {
|
|
85
|
+
this.enabled = enabled;
|
|
86
|
+
this.options = options;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.ResolvedRuleConfig = ResolvedRuleConfig;
|
|
90
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hooks/src/core/types.ts"],"names":[],"mappings":";;;AAMA,MAAa,SAAS;IAOlB,YAAY,IAAY,EAAE,OAAe,EAAE,OAAe;QACtD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC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DAQC","sourcesContent":["export type ToolKind = 'Write' | 'Edit' | 'MultiEdit';\nexport type RuleScope = 'edit' | 'file';\n// webpieces-disable no-any-unknown -- rule options are opaque at framework level; each rule casts internally\nexport type RuleOptions = Record<string, unknown>;\nexport type IsLineDisabled = (lineNum: number, ruleName: string) => boolean;\n\nexport class Violation {\n readonly line: number;\n readonly snippet: string;\n readonly message: string;\n editIndex: number | undefined;\n editCount: number | undefined;\n\n constructor(line: number, snippet: string, message: string) {\n this.line = line;\n this.snippet = snippet;\n this.message = message;\n this.editIndex = undefined;\n this.editCount = undefined;\n }\n}\n\nexport class NormalizedEdit {\n readonly oldString: string;\n readonly newString: string;\n\n constructor(oldString: string, newString: string) {\n this.oldString = oldString;\n this.newString = newString;\n }\n}\n\nexport class NormalizedToolInput {\n readonly filePath: string;\n readonly edits: readonly NormalizedEdit[];\n\n constructor(filePath: string, edits: readonly NormalizedEdit[]) {\n this.filePath = filePath;\n this.edits = edits;\n }\n}\n\nexport class EditContext {\n readonly tool: ToolKind;\n readonly editIndex: number;\n readonly editCount: number;\n readonly filePath: string;\n readonly relativePath: string;\n readonly workspaceRoot: string;\n readonly addedContent: string;\n readonly strippedContent: string;\n readonly lines: readonly string[];\n readonly strippedLines: readonly string[];\n readonly removedContent: string;\n readonly isLineDisabled: IsLineDisabled;\n options: RuleOptions;\n\n constructor(\n tool: ToolKind,\n editIndex: number,\n editCount: number,\n filePath: string,\n relativePath: string,\n workspaceRoot: string,\n addedContent: string,\n strippedContent: string,\n lines: readonly string[],\n strippedLines: readonly string[],\n removedContent: string,\n isLineDisabled: IsLineDisabled,\n ) {\n this.tool = tool;\n this.editIndex = editIndex;\n this.editCount = editCount;\n this.filePath = filePath;\n this.relativePath = relativePath;\n this.workspaceRoot = workspaceRoot;\n this.addedContent = addedContent;\n this.strippedContent = strippedContent;\n this.lines = lines;\n this.strippedLines = strippedLines;\n this.removedContent = removedContent;\n this.isLineDisabled = isLineDisabled;\n this.options = {};\n }\n}\n\nexport class FileContext {\n readonly tool: ToolKind;\n readonly filePath: string;\n readonly relativePath: string;\n readonly workspaceRoot: string;\n readonly currentFileLines: number;\n readonly linesAdded: number;\n readonly linesRemoved: number;\n readonly projectedFileLines: number;\n options: RuleOptions;\n\n constructor(\n tool: ToolKind,\n filePath: string,\n relativePath: string,\n workspaceRoot: string,\n currentFileLines: number,\n linesAdded: number,\n linesRemoved: number,\n projectedFileLines: number,\n ) {\n this.tool = tool;\n this.filePath = filePath;\n this.relativePath = relativePath;\n this.workspaceRoot = workspaceRoot;\n this.currentFileLines = currentFileLines;\n this.linesAdded = linesAdded;\n this.linesRemoved = linesRemoved;\n this.projectedFileLines = projectedFileLines;\n this.options = {};\n }\n}\n\ninterface RuleBase {\n readonly name: string;\n readonly description: string;\n readonly files: readonly string[];\n readonly defaultOptions: RuleOptions;\n readonly fixHint: readonly string[];\n}\n\nexport interface EditRule extends RuleBase {\n readonly scope: 'edit';\n check(ctx: EditContext): readonly Violation[];\n}\n\nexport interface FileRule extends RuleBase {\n readonly scope: 'file';\n check(ctx: FileContext): readonly Violation[];\n}\n\nexport type Rule = EditRule | FileRule;\n\nexport class RuleGroup {\n readonly ruleName: string;\n readonly ruleDescription: string;\n readonly fixHint: readonly string[];\n readonly violations: readonly Violation[];\n\n constructor(\n ruleName: string,\n ruleDescription: string,\n fixHint: readonly string[],\n violations: readonly Violation[],\n ) {\n this.ruleName = ruleName;\n this.ruleDescription = ruleDescription;\n this.fixHint = fixHint;\n this.violations = violations;\n }\n}\n\nexport class BlockedResult {\n readonly report: string;\n\n constructor(report: string) {\n this.report = report;\n }\n}\n\nexport class ResolvedConfig {\n readonly rules: Map<string, ResolvedRuleConfig>;\n readonly rulesDir: readonly string[];\n readonly configPath: string | null;\n\n constructor(\n rules: Map<string, ResolvedRuleConfig>,\n rulesDir: readonly string[],\n configPath: string | null,\n ) {\n this.rules = rules;\n this.rulesDir = rulesDir;\n this.configPath = configPath;\n }\n}\n\nexport class ResolvedRuleConfig {\n readonly enabled: boolean;\n readonly options: RuleOptions;\n\n constructor(enabled: boolean, options: RuleOptions) {\n this.enabled = enabled;\n this.options = options;\n }\n}\n"]}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ToolKind, RuleScope, RuleOptions, IsLineDisabled, Violation, NormalizedEdit, NormalizedToolInput, EditContext, FileContext, Rule, EditRule, FileRule, RuleGroup, BlockedResult, ResolvedConfig, ResolvedRuleConfig, } from './core/types';
|
|
2
|
+
export { run } from './core/runner';
|
|
3
|
+
export { stripTsNoise } from './core/strip-ts-noise';
|
|
4
|
+
export { parseDirectives, DirectiveIndex, createIsLineDisabled } from './core/disable-directives';
|
|
5
|
+
export { formatReport } from './core/report';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatReport = exports.createIsLineDisabled = exports.DirectiveIndex = exports.parseDirectives = exports.stripTsNoise = exports.run = exports.ResolvedRuleConfig = exports.ResolvedConfig = exports.BlockedResult = exports.RuleGroup = exports.FileContext = exports.EditContext = exports.NormalizedToolInput = exports.NormalizedEdit = exports.Violation = void 0;
|
|
4
|
+
var types_1 = require("./core/types");
|
|
5
|
+
Object.defineProperty(exports, "Violation", { enumerable: true, get: function () { return types_1.Violation; } });
|
|
6
|
+
Object.defineProperty(exports, "NormalizedEdit", { enumerable: true, get: function () { return types_1.NormalizedEdit; } });
|
|
7
|
+
Object.defineProperty(exports, "NormalizedToolInput", { enumerable: true, get: function () { return types_1.NormalizedToolInput; } });
|
|
8
|
+
Object.defineProperty(exports, "EditContext", { enumerable: true, get: function () { return types_1.EditContext; } });
|
|
9
|
+
Object.defineProperty(exports, "FileContext", { enumerable: true, get: function () { return types_1.FileContext; } });
|
|
10
|
+
Object.defineProperty(exports, "RuleGroup", { enumerable: true, get: function () { return types_1.RuleGroup; } });
|
|
11
|
+
Object.defineProperty(exports, "BlockedResult", { enumerable: true, get: function () { return types_1.BlockedResult; } });
|
|
12
|
+
Object.defineProperty(exports, "ResolvedConfig", { enumerable: true, get: function () { return types_1.ResolvedConfig; } });
|
|
13
|
+
Object.defineProperty(exports, "ResolvedRuleConfig", { enumerable: true, get: function () { return types_1.ResolvedRuleConfig; } });
|
|
14
|
+
var runner_1 = require("./core/runner");
|
|
15
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return runner_1.run; } });
|
|
16
|
+
var strip_ts_noise_1 = require("./core/strip-ts-noise");
|
|
17
|
+
Object.defineProperty(exports, "stripTsNoise", { enumerable: true, get: function () { return strip_ts_noise_1.stripTsNoise; } });
|
|
18
|
+
var disable_directives_1 = require("./core/disable-directives");
|
|
19
|
+
Object.defineProperty(exports, "parseDirectives", { enumerable: true, get: function () { return disable_directives_1.parseDirectives; } });
|
|
20
|
+
Object.defineProperty(exports, "DirectiveIndex", { enumerable: true, get: function () { return disable_directives_1.DirectiveIndex; } });
|
|
21
|
+
Object.defineProperty(exports, "createIsLineDisabled", { enumerable: true, get: function () { return disable_directives_1.createIsLineDisabled; } });
|
|
22
|
+
var report_1 = require("./core/report");
|
|
23
|
+
Object.defineProperty(exports, "formatReport", { enumerable: true, get: function () { return report_1.formatReport; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/ai-hooks/src/index.ts"],"names":[],"mappings":";;;AAAA,sCAOsB;AALlB,kGAAA,SAAS,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAC9C,oGAAA,WAAW,OAAA;AAAE,oGAAA,WAAW,OAAA;AAExB,kGAAA,SAAS,OAAA;AAAE,sGAAA,aAAa,OAAA;AACxB,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAGtC,wCAAoC;AAA3B,6FAAA,GAAG,OAAA;AACZ,wDAAqD;AAA5C,8GAAA,YAAY,OAAA;AACrB,gEAAkG;AAAzF,qHAAA,eAAe,OAAA;AAAE,oHAAA,cAAc,OAAA;AAAE,0HAAA,oBAAoB,OAAA;AAC9D,wCAA6C;AAApC,sGAAA,YAAY,OAAA","sourcesContent":["export {\n ToolKind, RuleScope, RuleOptions, IsLineDisabled,\n Violation, NormalizedEdit, NormalizedToolInput,\n EditContext, FileContext,\n Rule, EditRule, FileRule,\n RuleGroup, BlockedResult,\n ResolvedConfig, ResolvedRuleConfig,\n} from './core/types';\n\nexport { run } from './core/runner';\nexport { stripTsNoise } from './core/strip-ts-noise';\nexport { parseDirectives, DirectiveIndex, createIsLineDisabled } from './core/disable-directives';\nexport { formatReport } from './core/report';\n"]}
|