@yearofthedan/warp 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +97 -2
- package/dist/analysis/complexity.d.ts +4 -0
- package/dist/analysis/complexity.js +84 -0
- package/dist/analysis/folders.d.ts +2 -0
- package/dist/analysis/folders.js +15 -0
- package/dist/analysis/imports.d.ts +13 -0
- package/dist/analysis/imports.js +135 -0
- package/dist/analysis/members.d.ts +4 -0
- package/dist/analysis/members.js +190 -0
- package/dist/analysis/source.d.ts +13 -0
- package/dist/analysis/source.js +29 -0
- package/dist/analysis/specifiers.d.ts +2 -0
- package/dist/analysis/specifiers.js +6 -0
- package/dist/analysis/typescript.d.ts +2 -0
- package/dist/analysis/typescript.js +105 -0
- package/dist/app/check.d.ts +23 -0
- package/dist/app/check.js +15 -0
- package/dist/app/checkModel.d.ts +5 -0
- package/dist/app/checkModel.js +30 -0
- package/dist/app/diff.d.ts +25 -0
- package/dist/app/diff.js +53 -0
- package/dist/app/facts.d.ts +7 -0
- package/dist/app/facts.js +55 -0
- package/dist/app/load.d.ts +13 -0
- package/dist/app/load.js +76 -0
- package/dist/app/ports.d.ts +41 -0
- package/dist/app/ports.js +1 -0
- package/dist/app/unclassified.d.ts +5 -0
- package/dist/app/unclassified.js +13 -0
- package/dist/builtins/cognitive-complexity/cognitiveComplexity.d.ts +6 -0
- package/dist/builtins/cognitive-complexity/cognitiveComplexity.js +26 -0
- package/dist/builtins/components.d.ts +2 -0
- package/dist/builtins/components.js +20 -0
- package/dist/builtins/dependency-direction/dependencyDirection.d.ts +2 -0
- package/dist/builtins/dependency-direction/dependencyDirection.js +65 -0
- package/dist/builtins/file-cohesion/fileCohesion.d.ts +6 -0
- package/dist/builtins/file-cohesion/fileCohesion.js +30 -0
- package/dist/builtins/function-cohesion/functionCohesion.d.ts +6 -0
- package/dist/builtins/function-cohesion/functionCohesion.js +30 -0
- package/dist/builtins/index.d.ts +4 -0
- package/dist/builtins/index.js +30 -0
- package/dist/builtins/loops.d.ts +25 -0
- package/dist/builtins/loops.js +64 -0
- package/dist/builtins/module-cycle/moduleCycle.d.ts +3 -0
- package/dist/builtins/module-cycle/moduleCycle.js +61 -0
- package/dist/builtins/module-externals/moduleExternals.d.ts +2 -0
- package/dist/builtins/module-externals/moduleExternals.js +41 -0
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.d.ts +2 -0
- package/dist/builtins/no-cross-module-reexport/noCrossModuleReexport.js +47 -0
- package/dist/builtins/no-cycle/noCycle.d.ts +3 -0
- package/dist/builtins/no-cycle/noCycle.js +39 -0
- package/dist/builtins/no-double-export/noDoubleExport.d.ts +2 -0
- package/dist/builtins/no-double-export/noDoubleExport.js +38 -0
- package/dist/builtins/packages.d.ts +2 -0
- package/dist/builtins/packages.js +5 -0
- package/dist/builtins/place.d.ts +2 -0
- package/dist/builtins/place.js +6 -0
- package/dist/builtins/shared.d.ts +10 -0
- package/dist/builtins/shared.js +13 -0
- package/dist/builtins/unused-declaration/declarations.d.ts +32 -0
- package/dist/builtins/unused-declaration/declarations.js +26 -0
- package/dist/builtins/unused-declaration/empty.d.ts +3 -0
- package/dist/builtins/unused-declaration/empty.js +22 -0
- package/dist/builtins/unused-declaration/grants.d.ts +3 -0
- package/dist/builtins/unused-declaration/grants.js +48 -0
- package/dist/builtins/unused-declaration/surfaces.d.ts +3 -0
- package/dist/builtins/unused-declaration/surfaces.js +57 -0
- package/dist/builtins/unused-declaration/unusedDeclaration.d.ts +2 -0
- package/dist/builtins/unused-declaration/unusedDeclaration.js +14 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +168 -0
- package/dist/config/loadConfig.d.ts +7 -0
- package/dist/config/loadConfig.js +53 -0
- package/dist/config/toolDigest.d.ts +1 -0
- package/dist/config/toolDigest.js +16 -0
- package/dist/git/cache.d.ts +3 -0
- package/dist/git/cache.js +41 -0
- package/dist/git/repository.d.ts +3 -0
- package/dist/git/repository.js +81 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/model/archetype/builder.d.ts +183 -0
- package/dist/model/archetype/builder.js +85 -0
- package/dist/model/archetype/data.d.ts +92 -0
- package/dist/model/archetype/data.js +1 -0
- package/dist/model/archetype/draft.d.ts +37 -0
- package/dist/model/archetype/draft.js +275 -0
- package/dist/model/archetype/reach.d.ts +35 -0
- package/dist/model/archetype/reach.js +209 -0
- package/dist/model/archetype/references.d.ts +13 -0
- package/dist/model/archetype/references.js +166 -0
- package/dist/model/archetype/requirements.d.ts +5 -0
- package/dist/model/archetype/requirements.js +69 -0
- package/dist/model/archetype/resolve.d.ts +30 -0
- package/dist/model/archetype/resolve.js +311 -0
- package/dist/model/archetype/rulesets.d.ts +4 -0
- package/dist/model/archetype/rulesets.js +115 -0
- package/dist/model/archetype/settings.d.ts +21 -0
- package/dist/model/archetype/settings.js +64 -0
- package/dist/model/archetype/shared.d.ts +5 -0
- package/dist/model/archetype/shared.js +4 -0
- package/dist/model/configError.d.ts +3 -0
- package/dist/model/configError.js +3 -0
- package/dist/model/facts.d.ts +57 -0
- package/dist/model/facts.js +1 -0
- package/dist/reporters/claudeHook.d.ts +2 -0
- package/dist/reporters/claudeHook.js +10 -0
- package/dist/reporters/index.d.ts +2 -0
- package/dist/reporters/index.js +9 -0
- package/dist/reporters/json.d.ts +2 -0
- package/dist/reporters/json.js +4 -0
- package/dist/reporters/model.d.ts +4 -0
- package/dist/reporters/model.js +60 -0
- package/dist/reporters/omp.d.ts +2 -0
- package/dist/reporters/omp.js +8 -0
- package/dist/reporters/reporter.d.ts +26 -0
- package/dist/reporters/reporter.js +14 -0
- package/dist/reporters/sarif.d.ts +2 -0
- package/dist/reporters/sarif.js +44 -0
- package/dist/reporters/text.d.ts +6 -0
- package/dist/reporters/text.js +35 -0
- package/dist/rules/diff.d.ts +10 -0
- package/dist/rules/diff.js +31 -0
- package/dist/rules/registry.d.ts +5 -0
- package/dist/rules/registry.js +33 -0
- package/dist/rules/rule.d.ts +59 -0
- package/dist/rules/rule.js +18 -0
- package/integrations/omp/warp.ts +40 -0
- package/package.json +44 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const modelText = (model, rules) => {
|
|
2
|
+
const lines = [];
|
|
3
|
+
const visit = (module, depth) => {
|
|
4
|
+
const indent = ' '.repeat(depth);
|
|
5
|
+
lines.push(`${indent}${module.id} ${heading(module)}`);
|
|
6
|
+
if (rules) {
|
|
7
|
+
const changed = changedRules(module, rules);
|
|
8
|
+
if (changed)
|
|
9
|
+
lines.push(`${indent} rules: ${changed}`);
|
|
10
|
+
}
|
|
11
|
+
for (const file of module.looseFiles)
|
|
12
|
+
lines.push(`${indent} loose: ${file}`);
|
|
13
|
+
for (const child of module.children)
|
|
14
|
+
visit(child, depth + 1);
|
|
15
|
+
};
|
|
16
|
+
visit(model.root, 0);
|
|
17
|
+
const files = model.modules.reduce((sum, module) => sum + module.files.length, 0);
|
|
18
|
+
const loose = model.modules.reduce((sum, module) => sum + module.looseFiles.length, 0);
|
|
19
|
+
const tests = model.modules.reduce((sum, module) => sum + module.tests.length, 0);
|
|
20
|
+
const tested = tests > 0 ? `, ${count(tests, 'test')}` : '';
|
|
21
|
+
lines.push('', `${model.modules.length} modules, ${files} files${tested}, ${loose} loose.`);
|
|
22
|
+
return lines.join('\n');
|
|
23
|
+
};
|
|
24
|
+
const changedRules = (module, rules) => {
|
|
25
|
+
const resolved = rules.module(module);
|
|
26
|
+
const from = module.parent ? rules.module(module.parent) : rules.defaults;
|
|
27
|
+
return Object.entries(resolved)
|
|
28
|
+
.filter(([id, setting]) => JSON.stringify(setting) !== JSON.stringify(from[id]))
|
|
29
|
+
.map(([id, setting]) => (setting === false ? `${id} off` : `${id} ${JSON.stringify(setting)}`))
|
|
30
|
+
.join(', ');
|
|
31
|
+
};
|
|
32
|
+
const count = (n, noun = 'file') => `${n} ${noun}${n === 1 ? '' : 's'}`;
|
|
33
|
+
const heading = (module) => {
|
|
34
|
+
const owned = module.files.length - module.looseFiles.length;
|
|
35
|
+
if (module.kind === 'files')
|
|
36
|
+
return count(owned);
|
|
37
|
+
const captures = Object.entries(module.captures)
|
|
38
|
+
.map(([key, value]) => ` {${key}=${value}}`)
|
|
39
|
+
.join('');
|
|
40
|
+
const contents = [
|
|
41
|
+
...(owned > 0 ? [count(owned)] : []),
|
|
42
|
+
...(module.tests.length > 0 ? [count(module.tests.length, 'test')] : []),
|
|
43
|
+
];
|
|
44
|
+
return `${module.name ?? 'root'}: ${module.archetype}${captures}${contents.map((part) => `, ${part}`).join('')}`;
|
|
45
|
+
};
|
|
46
|
+
export const modelJson = (model, rules) => JSON.stringify({
|
|
47
|
+
modules: model.modules.map((module) => ({
|
|
48
|
+
id: module.id,
|
|
49
|
+
name: module.name,
|
|
50
|
+
kind: module.kind,
|
|
51
|
+
archetype: module.archetype,
|
|
52
|
+
captures: module.captures,
|
|
53
|
+
parent: module.parent?.id,
|
|
54
|
+
children: module.children.map((child) => child.id),
|
|
55
|
+
files: module.files,
|
|
56
|
+
looseFiles: module.looseFiles,
|
|
57
|
+
tests: module.tests,
|
|
58
|
+
...(rules ? { rules: rules.module(module) } : {}),
|
|
59
|
+
})),
|
|
60
|
+
}, null, 2);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { actionable, agentContext } from './reporter.js';
|
|
2
|
+
import { diffText, line } from './text.js';
|
|
3
|
+
export const ompReporter = {
|
|
4
|
+
id: 'omp',
|
|
5
|
+
render: (report) => actionable(report).length === 0
|
|
6
|
+
? ''
|
|
7
|
+
: JSON.stringify({ additionalContext: agentContext(report, { delta: diffText, finding: line }) }),
|
|
8
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Delta } from '../rules/diff.ts';
|
|
2
|
+
import type { Finding } from '../rules/rule.ts';
|
|
3
|
+
export type Report = {
|
|
4
|
+
mode: 'check';
|
|
5
|
+
findings: Finding[];
|
|
6
|
+
} | {
|
|
7
|
+
mode: 'diff';
|
|
8
|
+
delta: Delta;
|
|
9
|
+
};
|
|
10
|
+
export interface ReportContext {
|
|
11
|
+
toolVersion: string;
|
|
12
|
+
projectPath: string;
|
|
13
|
+
}
|
|
14
|
+
export interface Reporter {
|
|
15
|
+
id: string;
|
|
16
|
+
render: (report: Report, context: ReportContext) => string;
|
|
17
|
+
renderFailure?: (problem: string) => string;
|
|
18
|
+
failureExitCode?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const unavailable: (problem: string) => string;
|
|
21
|
+
export declare const actionable: (report: Report) => Finding[];
|
|
22
|
+
export declare const agentContext: (report: Report, render: {
|
|
23
|
+
delta: (delta: Delta) => string;
|
|
24
|
+
finding: (finding: Finding) => string;
|
|
25
|
+
}) => string;
|
|
26
|
+
export declare const ruleDocs: (findings: Finding[]) => [string, string][];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const unavailable = (problem) => `Warp architecture feedback is unavailable, so edits are not checked: ${problem}`;
|
|
2
|
+
export const actionable = (report) => report.mode === 'check' ? report.findings : [...report.delta.added, ...report.delta.worsened];
|
|
3
|
+
export const agentContext = (report, render) => {
|
|
4
|
+
const body = report.mode === 'diff'
|
|
5
|
+
? `New or worse architecture fitness findings. Address them if this edit caused them:\n${render.delta(report.delta)}`
|
|
6
|
+
: `Architecture fitness findings:\n${report.findings.map(render.finding).join('\n')}`;
|
|
7
|
+
const docs = ruleDocs(actionable(report));
|
|
8
|
+
return docs.length === 0
|
|
9
|
+
? body
|
|
10
|
+
: `${body}\n\nRule docs:\n${docs.map(([rule, url]) => `- ${rule}: ${url}`).join('\n')}`;
|
|
11
|
+
};
|
|
12
|
+
export const ruleDocs = (findings) => [
|
|
13
|
+
...new Map(findings.flatMap((finding) => (finding.docs ? [[finding.rule, finding.docs]] : []))),
|
|
14
|
+
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { actionable, ruleDocs } from './reporter.js';
|
|
2
|
+
export const sarifReporter = {
|
|
3
|
+
id: 'sarif',
|
|
4
|
+
render: (report, context) => {
|
|
5
|
+
const findings = actionable(report);
|
|
6
|
+
const docs = new Map(ruleDocs(findings));
|
|
7
|
+
const rules = [...new Set(findings.map((finding) => finding.rule))].sort();
|
|
8
|
+
return JSON.stringify({
|
|
9
|
+
$schema: 'https://json.schemastore.org/sarif-2.1.0.json',
|
|
10
|
+
version: '2.1.0',
|
|
11
|
+
runs: [
|
|
12
|
+
{
|
|
13
|
+
tool: {
|
|
14
|
+
driver: {
|
|
15
|
+
name: 'warp',
|
|
16
|
+
version: context.toolVersion,
|
|
17
|
+
informationUri: 'https://github.com/yearofthedan/warp',
|
|
18
|
+
rules: rules.map((id) => ({
|
|
19
|
+
id,
|
|
20
|
+
shortDescription: { text: id },
|
|
21
|
+
...(docs.has(id) ? { helpUri: docs.get(id) } : {}),
|
|
22
|
+
})),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
results: findings.map((finding) => result(finding, context)),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
}, null, 2);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const result = (finding, context) => ({
|
|
32
|
+
ruleId: finding.rule,
|
|
33
|
+
level: 'warning',
|
|
34
|
+
message: { text: finding.message },
|
|
35
|
+
locations: [
|
|
36
|
+
{
|
|
37
|
+
physicalLocation: {
|
|
38
|
+
artifactLocation: { uri: context.projectPath ? `${context.projectPath}/${finding.file}` : finding.file },
|
|
39
|
+
region: { startLine: finding.line },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
partialFingerprints: { 'warpKey/v1': finding.key },
|
|
44
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Delta } from '../rules/diff.ts';
|
|
2
|
+
import type { Finding } from '../rules/rule.ts';
|
|
3
|
+
import type { Reporter } from './reporter.ts';
|
|
4
|
+
export declare const textReporter: Reporter;
|
|
5
|
+
export declare const diffText: (delta: Delta) => string;
|
|
6
|
+
export declare const line: (finding: Finding) => string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const textReporter = {
|
|
2
|
+
id: 'text',
|
|
3
|
+
render: (report) => (report.mode === 'check' ? checkText(report.findings) : diffText(report.delta)),
|
|
4
|
+
};
|
|
5
|
+
const checkText = (findings) => findings.length === 0
|
|
6
|
+
? 'No findings.'
|
|
7
|
+
: [
|
|
8
|
+
...findings.map(line),
|
|
9
|
+
'',
|
|
10
|
+
'By rule and module:',
|
|
11
|
+
...summary(findings),
|
|
12
|
+
'',
|
|
13
|
+
count(findings.length, 'finding'),
|
|
14
|
+
].join('\n');
|
|
15
|
+
const summary = (findings) => {
|
|
16
|
+
const groups = Map.groupBy(findings, (finding) => `${finding.rule}\t${finding.module ?? finding.file}`);
|
|
17
|
+
const rows = [...groups]
|
|
18
|
+
.map(([group, members]) => [...group.split('\t'), String(members.length)])
|
|
19
|
+
.toSorted(([rule, module, n], [otherRule, otherModule, other]) => {
|
|
20
|
+
const byCount = Number(other) - Number(n);
|
|
21
|
+
return byCount || rule.localeCompare(otherRule) || module.localeCompare(otherModule);
|
|
22
|
+
});
|
|
23
|
+
const width = (column) => Math.max(...rows.map((row) => row[column].length));
|
|
24
|
+
return rows.map(([rule, module, n]) => ` ${rule.padEnd(width(0))} ${module.padEnd(width(1))} ${n.padStart(width(2))}`);
|
|
25
|
+
};
|
|
26
|
+
export const diffText = (delta) => {
|
|
27
|
+
const lines = [
|
|
28
|
+
...delta.added.map((finding) => `new: ${line(finding)}`),
|
|
29
|
+
...delta.worsened.map((finding) => `worse (was ${finding.was}): ${line(finding)}`),
|
|
30
|
+
];
|
|
31
|
+
const summary = `${count(delta.added.length, 'new finding')}, ${delta.worsened.length} worsened, ${delta.resolved.length} resolved.`;
|
|
32
|
+
return [...lines, ...(lines.length > 0 ? [''] : []), summary].join('\n');
|
|
33
|
+
};
|
|
34
|
+
export const line = (finding) => `${finding.file}:${finding.line} [${finding.rule}] ${finding.message}`;
|
|
35
|
+
const count = (n, noun) => `${n} ${noun}${n === 1 ? '' : 's'}`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Finding, Site } from './rule.ts';
|
|
2
|
+
export interface Delta {
|
|
3
|
+
added: Finding[];
|
|
4
|
+
worsened: (Finding & {
|
|
5
|
+
was: number;
|
|
6
|
+
})[];
|
|
7
|
+
resolved: Finding[];
|
|
8
|
+
}
|
|
9
|
+
export declare const diff: (base: Finding[], head: Finding[]) => Delta;
|
|
10
|
+
export declare const anchorAtChange: (delta: Delta, changed: () => (site: Site) => boolean) => Delta;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const partKey = (rule, part) => `${rule}\0${part}`;
|
|
2
|
+
export const diff = (base, head) => {
|
|
3
|
+
const byKey = new Map(base.map((finding) => [finding.key, finding]));
|
|
4
|
+
const byPart = new Map(base.flatMap((finding) => finding.parts?.map((part) => [partKey(finding.rule, part), finding]) ?? []));
|
|
5
|
+
const matched = new Set();
|
|
6
|
+
const added = [];
|
|
7
|
+
const worsened = [];
|
|
8
|
+
for (const finding of head) {
|
|
9
|
+
const was = byKey.get(finding.key) ??
|
|
10
|
+
finding.parts?.map((part) => byPart.get(partKey(finding.rule, part))).find((match) => match !== undefined);
|
|
11
|
+
if (!was)
|
|
12
|
+
added.push(finding);
|
|
13
|
+
else {
|
|
14
|
+
matched.add(was);
|
|
15
|
+
if (finding.value > was.value)
|
|
16
|
+
worsened.push({ ...finding, was: was.value });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { added, worsened, resolved: base.filter((finding) => !matched.has(finding)) };
|
|
20
|
+
};
|
|
21
|
+
export const anchorAtChange = (delta, changed) => {
|
|
22
|
+
const actionable = [...delta.added, ...delta.worsened];
|
|
23
|
+
if (!actionable.some((finding) => finding.sites))
|
|
24
|
+
return delta;
|
|
25
|
+
const isChanged = changed();
|
|
26
|
+
const anchor = (finding) => {
|
|
27
|
+
const site = finding.sites?.find(isChanged);
|
|
28
|
+
return site ? { ...finding, file: site.file, line: site.line } : finding;
|
|
29
|
+
};
|
|
30
|
+
return { added: delta.added.map(anchor), worsened: delta.worsened.map(anchor), resolved: delta.resolved };
|
|
31
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ConfigError } from '../model/configError.js';
|
|
2
|
+
export const registry = (rules) => {
|
|
3
|
+
const byId = new Map();
|
|
4
|
+
for (const rule of rules) {
|
|
5
|
+
if (byId.has(rule.id))
|
|
6
|
+
throw new ConfigError(`rules: two rules have the id ${rule.id}`);
|
|
7
|
+
byId.set(rule.id, rule);
|
|
8
|
+
}
|
|
9
|
+
return byId;
|
|
10
|
+
};
|
|
11
|
+
const name = /^[a-z][a-z0-9-]*$/;
|
|
12
|
+
export const pluginRules = (plugins) => Object.entries(plugins).flatMap(([namespace, plugin]) => namespaced(namespace, plugin, `config.plugins.${namespace}`));
|
|
13
|
+
const namespaced = (namespace, plugin, at) => {
|
|
14
|
+
if (!name.test(namespace))
|
|
15
|
+
throw new ConfigError(`${at}: a namespace is lowercase letters, digits and dashes`);
|
|
16
|
+
const rules = typeof plugin === 'object' && plugin !== null ? plugin.rules : undefined;
|
|
17
|
+
if (!Array.isArray(rules))
|
|
18
|
+
throw new ConfigError(`${at}: expected a plugin, { rules: Rule[] }, imported in a warp.config.ts`);
|
|
19
|
+
return rules.map((rule, index) => {
|
|
20
|
+
const where = `${at}.rules[${index}]`;
|
|
21
|
+
if (typeof rule?.id !== 'string' || !name.test(rule.id))
|
|
22
|
+
throw new ConfigError(`${where}: a rule id is lowercase letters, digits and dashes`);
|
|
23
|
+
if (typeof rule.check !== 'function')
|
|
24
|
+
throw new ConfigError(`${where}: ${rule.id} has no check function`);
|
|
25
|
+
if (rule.scope !== undefined && rule.scope !== 'file' && rule.scope !== 'project')
|
|
26
|
+
throw new ConfigError(`${where}: ${rule.id} has scope ${String(rule.scope)}; a scope is file or project`);
|
|
27
|
+
const id = `${namespace}/${rule.id}`;
|
|
28
|
+
const owned = (findings) => findings.map((finding) => ({ ...finding, rule: id, key: `${namespace}/${finding.key}` }));
|
|
29
|
+
if (rule.scope === 'project')
|
|
30
|
+
return { ...rule, id, check: (context) => owned(rule.check(context)) };
|
|
31
|
+
return { ...rule, id, check: (context) => owned(rule.check(context)) };
|
|
32
|
+
});
|
|
33
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ConfigData } from '../model/archetype/data.ts';
|
|
2
|
+
import type { Verdicts } from '../model/archetype/reach.ts';
|
|
3
|
+
import type { Model, ModuleView } from '../model/archetype/resolve.ts';
|
|
4
|
+
import type { FileFacts, Project } from '../model/facts.ts';
|
|
5
|
+
export interface Site {
|
|
6
|
+
file: string;
|
|
7
|
+
line: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Finding {
|
|
10
|
+
rule: string;
|
|
11
|
+
key: string;
|
|
12
|
+
file: string;
|
|
13
|
+
line: number;
|
|
14
|
+
module?: string;
|
|
15
|
+
value: number;
|
|
16
|
+
limit?: number;
|
|
17
|
+
message: string;
|
|
18
|
+
docs?: string;
|
|
19
|
+
sites?: Site[];
|
|
20
|
+
parts?: string[];
|
|
21
|
+
details?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface FileContext<Options> {
|
|
24
|
+
file: FileFacts;
|
|
25
|
+
options: Options;
|
|
26
|
+
}
|
|
27
|
+
export interface Setting<Options> {
|
|
28
|
+
on: boolean;
|
|
29
|
+
options: Options;
|
|
30
|
+
}
|
|
31
|
+
export interface ProjectContext<Options> {
|
|
32
|
+
project: Project;
|
|
33
|
+
config: ConfigData;
|
|
34
|
+
model: Model;
|
|
35
|
+
verdicts: Verdicts;
|
|
36
|
+
atFile: (file: string) => Setting<Options>;
|
|
37
|
+
atModule: (module: ModuleView) => Setting<Options>;
|
|
38
|
+
}
|
|
39
|
+
interface RuleBase<Options extends object> {
|
|
40
|
+
id: string;
|
|
41
|
+
docs?: string;
|
|
42
|
+
defaults?: Options;
|
|
43
|
+
parseOptions?: (raw: Record<string, unknown>, at: string) => Partial<Options>;
|
|
44
|
+
}
|
|
45
|
+
export interface FileRule<Options extends object = object> extends RuleBase<Options> {
|
|
46
|
+
scope?: 'file';
|
|
47
|
+
check: (context: FileContext<Options>) => Finding[];
|
|
48
|
+
}
|
|
49
|
+
export interface ProjectRule<Options extends object = object> extends RuleBase<Options> {
|
|
50
|
+
scope: 'project';
|
|
51
|
+
check: (context: ProjectContext<Options>) => Finding[];
|
|
52
|
+
}
|
|
53
|
+
export type Rule = FileRule<any> | ProjectRule<any>;
|
|
54
|
+
export interface Plugin {
|
|
55
|
+
rules: readonly Rule[];
|
|
56
|
+
}
|
|
57
|
+
export declare const noOptions: (raw: Record<string, unknown>, at: string) => Partial<object>;
|
|
58
|
+
export declare const wholeNumberOptions: <Options extends Record<string, number>>(defaults: Options) => (raw: Record<string, unknown>, at: string) => Partial<Options>;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConfigError } from '../model/configError.js';
|
|
2
|
+
export const noOptions = (raw, at) => {
|
|
3
|
+
const keys = Object.keys(raw);
|
|
4
|
+
if (keys.length > 0)
|
|
5
|
+
throw new ConfigError(`${at}: unknown key ${keys.join(', ')}`);
|
|
6
|
+
return {};
|
|
7
|
+
};
|
|
8
|
+
export const wholeNumberOptions = (defaults) => (raw, at) => {
|
|
9
|
+
const unknown = Object.keys(raw).filter((key) => !(key in defaults));
|
|
10
|
+
if (unknown.length > 0)
|
|
11
|
+
throw new ConfigError(`${at}: unknown key ${unknown.join(', ')}`);
|
|
12
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
13
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {
|
|
14
|
+
throw new ConfigError(`${at}.${key}: expected a whole number of at least 1`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return raw;
|
|
18
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type ToolResultEvent = { toolName: string; isError: boolean };
|
|
2
|
+
type ToolResultEventResult = { additionalContext?: string };
|
|
3
|
+
type ExecResult = { stdout: string; stderr: string; code: number };
|
|
4
|
+
type Context = { cwd: string };
|
|
5
|
+
|
|
6
|
+
export type Extension = {
|
|
7
|
+
on(
|
|
8
|
+
event: 'tool_result',
|
|
9
|
+
handler: (event: ToolResultEvent, context: Context) => Promise<ToolResultEventResult | undefined>,
|
|
10
|
+
): void;
|
|
11
|
+
exec(command: string, args: string[], options?: { cwd?: string; timeout?: number }): Promise<ExecResult>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const editTools = new Set(['edit', 'write', 'ast_edit', 'apply_patch']);
|
|
15
|
+
|
|
16
|
+
export default function warp(pi: Extension, env: Record<string, string | undefined> = process.env): void {
|
|
17
|
+
const [command, ...prefix] = (env.WARP_COMMAND ?? 'warp').trim().split(/\s+/);
|
|
18
|
+
const base = env.WARP_BASE ?? 'HEAD';
|
|
19
|
+
const ruleset = env.WARP_RULESET ? ['--ruleset', env.WARP_RULESET] : [];
|
|
20
|
+
let reported: string | undefined;
|
|
21
|
+
const health = (problem: string | undefined): ToolResultEventResult | undefined => {
|
|
22
|
+
const changed = problem !== reported;
|
|
23
|
+
reported = problem;
|
|
24
|
+
return problem && changed
|
|
25
|
+
? { additionalContext: `Warp architecture feedback is unavailable, so edits are not checked: ${problem}` }
|
|
26
|
+
: undefined;
|
|
27
|
+
};
|
|
28
|
+
pi.on('tool_result', async (event, context) => {
|
|
29
|
+
if (event.isError || !editTools.has(event.toolName)) return undefined;
|
|
30
|
+
const run = await pi
|
|
31
|
+
.exec(command, [...prefix, 'diff', base, '--since-last-run', ...ruleset, '--reporter', 'omp'], {
|
|
32
|
+
cwd: context.cwd,
|
|
33
|
+
timeout: 60_000,
|
|
34
|
+
})
|
|
35
|
+
.catch((error: unknown): ExecResult => ({ stdout: '', stderr: String(error), code: -1 }));
|
|
36
|
+
if (run.code !== 0) return health(run.stderr.trim() || `${command} exited with code ${run.code}`);
|
|
37
|
+
health(undefined);
|
|
38
|
+
return run.stdout.trim() === '' ? undefined : (JSON.parse(run.stdout) as ToolResultEventResult);
|
|
39
|
+
});
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yearofthedan/warp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Architectural fitness checks for TypeScript codebases",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/yearofthedan/warp.git"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"warp": "./dist/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"integrations/omp/warp.ts"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"provenance": true
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"prepare": "vp config --no-agent",
|
|
30
|
+
"build": "tsc -p tsconfig.build.json"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"typescript": "7.1.0-beta"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@stryker-mutator/core": "10.1.1",
|
|
37
|
+
"@stryker-mutator/vitest-runner": "10.1.1",
|
|
38
|
+
"@types/node": "26.6.6",
|
|
39
|
+
"secretlint": "14.0.1",
|
|
40
|
+
"vite-plus": "catalog:"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=26"
|
|
44
|
+
},
|
|
45
|
+
"packageManager": "pnpm@12.20.0"
|
|
46
|
+
}
|