micro-contracts 0.16.3 → 0.17.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/cli-contract.yaml +0 -32
- package/dist/micro-contracts.bundle.mjs +4682 -0
- package/dist/micro-contracts.bundle.mjs.map +7 -0
- package/docs/cli-reference.md +0 -28
- package/package.json +20 -23
- package/dist/agents/context-builder.d.ts +0 -5
- package/dist/agents/context-builder.d.ts.map +0 -1
- package/dist/agents/context-builder.js +0 -239
- package/dist/agents/context-builder.js.map +0 -1
- package/dist/agents/formatter.d.ts +0 -9
- package/dist/agents/formatter.d.ts.map +0 -1
- package/dist/agents/formatter.js +0 -124
- package/dist/agents/formatter.js.map +0 -1
- package/dist/agents/index.d.ts +0 -5
- package/dist/agents/index.d.ts.map +0 -1
- package/dist/agents/index.js +0 -3
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/orchestrator.d.ts +0 -5
- package/dist/agents/orchestrator.d.ts.map +0 -1
- package/dist/agents/orchestrator.js +0 -105
- package/dist/agents/orchestrator.js.map +0 -1
- package/dist/agents/types.d.ts +0 -21
- package/dist/agents/types.d.ts.map +0 -1
- package/dist/agents/types.js +0 -2
- package/dist/agents/types.js.map +0 -1
- package/dist/cli/templates.d.ts +0 -22
- package/dist/cli/templates.d.ts.map +0 -1
- package/dist/cli/templates.js +0 -445
- package/dist/cli/templates.js.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -1142
- package/dist/cli.js.map +0 -1
- package/dist/commands/audit-guardrails.d.ts +0 -13
- package/dist/commands/audit-guardrails.d.ts.map +0 -1
- package/dist/commands/audit-guardrails.js +0 -32
- package/dist/commands/audit-guardrails.js.map +0 -1
- package/dist/commands/audit-openapi.d.ts +0 -13
- package/dist/commands/audit-openapi.d.ts.map +0 -1
- package/dist/commands/audit-openapi.js +0 -32
- package/dist/commands/audit-openapi.js.map +0 -1
- package/dist/commands/propose-overlays.d.ts +0 -13
- package/dist/commands/propose-overlays.d.ts.map +0 -1
- package/dist/commands/propose-overlays.js +0 -32
- package/dist/commands/propose-overlays.js.map +0 -1
- package/dist/commands/review-published.d.ts +0 -13
- package/dist/commands/review-published.d.ts.map +0 -1
- package/dist/commands/review-published.js +0 -32
- package/dist/commands/review-published.js.map +0 -1
- package/dist/generated/commands.d.ts +0 -2
- package/dist/generated/commands.d.ts.map +0 -1
- package/dist/generated/commands.js +0 -2
- package/dist/generated/commands.js.map +0 -1
- package/dist/generated/dsl/agents.d.ts +0 -34
- package/dist/generated/dsl/agents.d.ts.map +0 -1
- package/dist/generated/dsl/agents.js +0 -98
- package/dist/generated/dsl/agents.js.map +0 -1
- package/dist/generated/dsl/handoffs.d.ts +0 -457
- package/dist/generated/dsl/handoffs.d.ts.map +0 -1
- package/dist/generated/dsl/handoffs.js +0 -205
- package/dist/generated/dsl/handoffs.js.map +0 -1
- package/dist/generated/dsl/index.d.ts +0 -13
- package/dist/generated/dsl/index.d.ts.map +0 -1
- package/dist/generated/dsl/index.js +0 -10
- package/dist/generated/dsl/index.js.map +0 -1
- package/dist/generated/dsl/tasks.d.ts +0 -26
- package/dist/generated/dsl/tasks.d.ts.map +0 -1
- package/dist/generated/dsl/tasks.js +0 -133
- package/dist/generated/dsl/tasks.js.map +0 -1
- package/dist/generated/dsl/workflows.d.ts +0 -34
- package/dist/generated/dsl/workflows.d.ts.map +0 -1
- package/dist/generated/dsl/workflows.js +0 -84
- package/dist/generated/dsl/workflows.js.map +0 -1
- package/dist/generated/index.d.ts +0 -7
- package/dist/generated/index.d.ts.map +0 -1
- package/dist/generated/index.js +0 -7
- package/dist/generated/index.js.map +0 -1
- package/dist/generated/policy-runtime.d.ts +0 -114
- package/dist/generated/policy-runtime.d.ts.map +0 -1
- package/dist/generated/policy-runtime.js +0 -195
- package/dist/generated/policy-runtime.js.map +0 -1
- package/dist/generated/policy.d.ts +0 -619
- package/dist/generated/policy.d.ts.map +0 -1
- package/dist/generated/policy.js +0 -802
- package/dist/generated/policy.js.map +0 -1
- package/dist/generated/program.d.ts +0 -112
- package/dist/generated/program.d.ts.map +0 -1
- package/dist/generated/program.js +0 -266
- package/dist/generated/program.js.map +0 -1
- package/dist/generated/schemas.d.ts +0 -778
- package/dist/generated/schemas.d.ts.map +0 -1
- package/dist/generated/schemas.js +0 -1005
- package/dist/generated/schemas.js.map +0 -1
- package/dist/generated/types.d.ts +0 -395
- package/dist/generated/types.d.ts.map +0 -1
- package/dist/generated/types.js +0 -3
- package/dist/generated/types.js.map +0 -1
- package/dist/generator/dependencyGenerator.d.ts +0 -43
- package/dist/generator/dependencyGenerator.d.ts.map +0 -1
- package/dist/generator/dependencyGenerator.js +0 -159
- package/dist/generator/dependencyGenerator.js.map +0 -1
- package/dist/generator/index.d.ts +0 -39
- package/dist/generator/index.d.ts.map +0 -1
- package/dist/generator/index.js +0 -720
- package/dist/generator/index.js.map +0 -1
- package/dist/generator/inputHash.d.ts +0 -23
- package/dist/generator/inputHash.d.ts.map +0 -1
- package/dist/generator/inputHash.js +0 -145
- package/dist/generator/inputHash.js.map +0 -1
- package/dist/generator/linter.d.ts +0 -26
- package/dist/generator/linter.d.ts.map +0 -1
- package/dist/generator/linter.js +0 -352
- package/dist/generator/linter.js.map +0 -1
- package/dist/generator/overlayProcessor.d.ts +0 -90
- package/dist/generator/overlayProcessor.d.ts.map +0 -1
- package/dist/generator/overlayProcessor.js +0 -541
- package/dist/generator/overlayProcessor.js.map +0 -1
- package/dist/generator/schemaGenerator.d.ts +0 -10
- package/dist/generator/schemaGenerator.d.ts.map +0 -1
- package/dist/generator/schemaGenerator.js +0 -299
- package/dist/generator/schemaGenerator.js.map +0 -1
- package/dist/generator/serviceGenerator.d.ts +0 -41
- package/dist/generator/serviceGenerator.d.ts.map +0 -1
- package/dist/generator/serviceGenerator.js +0 -296
- package/dist/generator/serviceGenerator.js.map +0 -1
- package/dist/generator/templateProcessor.d.ts +0 -245
- package/dist/generator/templateProcessor.d.ts.map +0 -1
- package/dist/generator/templateProcessor.js +0 -821
- package/dist/generator/templateProcessor.js.map +0 -1
- package/dist/generator/typeGenerator.d.ts +0 -9
- package/dist/generator/typeGenerator.d.ts.map +0 -1
- package/dist/generator/typeGenerator.js +0 -424
- package/dist/generator/typeGenerator.js.map +0 -1
- package/dist/generator/typeGenerator.test.d.ts +0 -2
- package/dist/generator/typeGenerator.test.d.ts.map +0 -1
- package/dist/generator/typeGenerator.test.js +0 -122
- package/dist/generator/typeGenerator.test.js.map +0 -1
- package/dist/guardrails/allowlist.d.ts +0 -45
- package/dist/guardrails/allowlist.d.ts.map +0 -1
- package/dist/guardrails/allowlist.js +0 -261
- package/dist/guardrails/allowlist.js.map +0 -1
- package/dist/guardrails/config.d.ts +0 -40
- package/dist/guardrails/config.d.ts.map +0 -1
- package/dist/guardrails/config.js +0 -174
- package/dist/guardrails/config.js.map +0 -1
- package/dist/guardrails/docs.d.ts +0 -24
- package/dist/guardrails/docs.d.ts.map +0 -1
- package/dist/guardrails/docs.js +0 -138
- package/dist/guardrails/docs.js.map +0 -1
- package/dist/guardrails/drift.d.ts +0 -23
- package/dist/guardrails/drift.d.ts.map +0 -1
- package/dist/guardrails/drift.js +0 -127
- package/dist/guardrails/drift.js.map +0 -1
- package/dist/guardrails/index.d.ts +0 -19
- package/dist/guardrails/index.d.ts.map +0 -1
- package/dist/guardrails/index.js +0 -23
- package/dist/guardrails/index.js.map +0 -1
- package/dist/guardrails/lint.d.ts +0 -20
- package/dist/guardrails/lint.d.ts.map +0 -1
- package/dist/guardrails/lint.js +0 -274
- package/dist/guardrails/lint.js.map +0 -1
- package/dist/guardrails/manifest.d.ts +0 -63
- package/dist/guardrails/manifest.d.ts.map +0 -1
- package/dist/guardrails/manifest.js +0 -299
- package/dist/guardrails/manifest.js.map +0 -1
- package/dist/guardrails/runner.d.ts +0 -43
- package/dist/guardrails/runner.d.ts.map +0 -1
- package/dist/guardrails/runner.js +0 -365
- package/dist/guardrails/runner.js.map +0 -1
- package/dist/guardrails/typecheck.d.ts +0 -15
- package/dist/guardrails/typecheck.d.ts.map +0 -1
- package/dist/guardrails/typecheck.js +0 -104
- package/dist/guardrails/typecheck.js.map +0 -1
- package/dist/guardrails/types.d.ts +0 -202
- package/dist/guardrails/types.d.ts.map +0 -1
- package/dist/guardrails/types.js +0 -8
- package/dist/guardrails/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -583
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -305
- package/dist/types.js.map +0 -1
package/dist/guardrails/docs.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Documentation consistency check for guardrails
|
|
3
|
-
*
|
|
4
|
-
* Verifies that documentation references (links, file paths, images) are valid.
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { glob } from 'glob';
|
|
9
|
-
/**
|
|
10
|
-
* Check if a path exists relative to a document file
|
|
11
|
-
*/
|
|
12
|
-
function existsRelativeToDoc(docFile, refPath) {
|
|
13
|
-
// Skip empty, anchor-only, or URL
|
|
14
|
-
if (!refPath || refPath.startsWith('#') || refPath.includes('://')) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
// Root-relative (starts with /) → resolve from cwd (repo root)
|
|
18
|
-
// Relative (including ./) → resolve from doc's directory
|
|
19
|
-
const resolved = refPath.startsWith('/')
|
|
20
|
-
? path.resolve(process.cwd(), refPath.slice(1))
|
|
21
|
-
: path.resolve(path.dirname(docFile), refPath);
|
|
22
|
-
return fs.existsSync(resolved);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Check a single markdown file for broken references
|
|
26
|
-
*/
|
|
27
|
-
export function checkMarkdownFile(docFile) {
|
|
28
|
-
const issues = [];
|
|
29
|
-
if (!fs.existsSync(docFile)) {
|
|
30
|
-
return issues;
|
|
31
|
-
}
|
|
32
|
-
const lines = fs.readFileSync(docFile, 'utf-8').split('\n');
|
|
33
|
-
lines.forEach((line, idx) => {
|
|
34
|
-
const lineNum = idx + 1;
|
|
35
|
-
// 1. Check file path references like [examples/...] or `examples/...`
|
|
36
|
-
const pathRefs = line.matchAll(/(?:\[|`)([a-zA-Z0-9_\-./]+\/[a-zA-Z0-9_\-./]+\.[a-zA-Z]+)(?:\]|`)/g);
|
|
37
|
-
for (const match of pathRefs) {
|
|
38
|
-
const refPath = match[1];
|
|
39
|
-
if (!existsRelativeToDoc(docFile, refPath)) {
|
|
40
|
-
issues.push({
|
|
41
|
-
file: docFile,
|
|
42
|
-
line: lineNum,
|
|
43
|
-
issue: `Referenced file does not exist: ${refPath}`,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// 2. Check markdown link targets like ](path#anchor)
|
|
48
|
-
const linkRefs = line.matchAll(/\]\((?!http)([^)]+)\)/g);
|
|
49
|
-
for (const match of linkRefs) {
|
|
50
|
-
const raw = match[1];
|
|
51
|
-
const linkPath = raw.split('#')[0]; // Remove anchor
|
|
52
|
-
if (linkPath && !existsRelativeToDoc(docFile, linkPath)) {
|
|
53
|
-
issues.push({
|
|
54
|
-
file: docFile,
|
|
55
|
-
line: lineNum,
|
|
56
|
-
issue: `Broken link: ${linkPath}`,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// 3. Check image references like 
|
|
61
|
-
const imgRefs = line.matchAll(/!\[[^\]]*\]\((?!http)([^)]+)\)/g);
|
|
62
|
-
for (const match of imgRefs) {
|
|
63
|
-
const imgPath = match[1].split('#')[0];
|
|
64
|
-
if (imgPath && !existsRelativeToDoc(docFile, imgPath)) {
|
|
65
|
-
issues.push({
|
|
66
|
-
file: docFile,
|
|
67
|
-
line: lineNum,
|
|
68
|
-
issue: `Image not found: ${imgPath}`,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return issues;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Find all markdown files to check
|
|
77
|
-
*/
|
|
78
|
-
export async function findMarkdownFiles() {
|
|
79
|
-
const files = [];
|
|
80
|
-
// Check README.md at root
|
|
81
|
-
if (fs.existsSync('README.md')) {
|
|
82
|
-
files.push('README.md');
|
|
83
|
-
}
|
|
84
|
-
// Check docs directory
|
|
85
|
-
const docsFiles = await glob('docs/**/*.md', {
|
|
86
|
-
ignore: ['**/node_modules/**'],
|
|
87
|
-
});
|
|
88
|
-
files.push(...docsFiles);
|
|
89
|
-
return files;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Run docs consistency check
|
|
93
|
-
*/
|
|
94
|
-
export async function runDocsCheck(options) {
|
|
95
|
-
const start = Date.now();
|
|
96
|
-
try {
|
|
97
|
-
// Find all markdown files
|
|
98
|
-
const docFiles = await findMarkdownFiles();
|
|
99
|
-
if (docFiles.length === 0) {
|
|
100
|
-
return {
|
|
101
|
-
name: 'docs',
|
|
102
|
-
status: 'skip',
|
|
103
|
-
duration: Date.now() - start,
|
|
104
|
-
message: 'No documentation files found',
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
const allIssues = [];
|
|
108
|
-
for (const docFile of docFiles) {
|
|
109
|
-
const issues = checkMarkdownFile(docFile);
|
|
110
|
-
allIssues.push(...issues);
|
|
111
|
-
}
|
|
112
|
-
if (allIssues.length > 0) {
|
|
113
|
-
const details = allIssues.map(i => ` ${i.file}:${i.line}: ${i.issue}`);
|
|
114
|
-
return {
|
|
115
|
-
name: 'docs',
|
|
116
|
-
status: 'fail',
|
|
117
|
-
duration: Date.now() - start,
|
|
118
|
-
message: `${allIssues.length} broken reference(s) in ${docFiles.length} file(s)`,
|
|
119
|
-
details,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
name: 'docs',
|
|
124
|
-
status: 'pass',
|
|
125
|
-
duration: Date.now() - start,
|
|
126
|
-
message: `${docFiles.length} documentation file(s) verified`,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
return {
|
|
131
|
-
name: 'docs',
|
|
132
|
-
status: 'fail',
|
|
133
|
-
duration: Date.now() - start,
|
|
134
|
-
message: error instanceof Error ? error.message : String(error),
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=docs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../src/guardrails/docs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAS5B;;GAEG;AACH,SAAS,mBAAmB,CAAC,OAAe,EAAE,OAAe;IAC3D,kCAAkC;IAClC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+DAA+D;IAC/D,yDAAyD;IACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QACtC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;IAEjD,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,MAAM,GAAe,EAAE,CAAC;IAE9B,IAAI,CAAC,EAAE,CAAC,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AAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAChE,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drift detection for generated artifacts
|
|
3
|
-
*
|
|
4
|
-
* Verifies that generated files match the committed state after running generate.
|
|
5
|
-
*/
|
|
6
|
-
import type { DriftResult, CheckResult, CheckOptions } from './types.js';
|
|
7
|
-
/**
|
|
8
|
-
* Check for drift in generated files
|
|
9
|
-
*/
|
|
10
|
-
export declare function checkDrift(generatedDir?: string): DriftResult;
|
|
11
|
-
/**
|
|
12
|
-
* Check for uncommitted changes (including untracked files)
|
|
13
|
-
*/
|
|
14
|
-
export declare function checkUncommittedChanges(generatedDir?: string): DriftResult;
|
|
15
|
-
/**
|
|
16
|
-
* Run drift check
|
|
17
|
-
*/
|
|
18
|
-
export declare function runDriftCheck(options: CheckOptions): Promise<CheckResult>;
|
|
19
|
-
/**
|
|
20
|
-
* Format drift result for CLI output
|
|
21
|
-
*/
|
|
22
|
-
export declare function formatDriftResult(result: DriftResult): string;
|
|
23
|
-
//# sourceMappingURL=drift.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drift.d.ts","sourceRoot":"","sources":["../../src/guardrails/drift.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEzE;;GAEG;AACH,wBAAgB,UAAU,CAAC,YAAY,GAAE,MAAoB,GAAG,WAAW,CAsB1E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,GAAE,MAAoB,GAAG,WAAW,CA6BvF;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CA2C/E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAsB7D"}
|
package/dist/guardrails/drift.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drift detection for generated artifacts
|
|
3
|
-
*
|
|
4
|
-
* Verifies that generated files match the committed state after running generate.
|
|
5
|
-
*/
|
|
6
|
-
import { execSync } from 'child_process';
|
|
7
|
-
/**
|
|
8
|
-
* Check for drift in generated files
|
|
9
|
-
*/
|
|
10
|
-
export function checkDrift(generatedDir = 'packages/') {
|
|
11
|
-
try {
|
|
12
|
-
// Run git diff on the generated directory
|
|
13
|
-
const output = execSync(`git diff --name-only "${generatedDir}"`, {
|
|
14
|
-
encoding: 'utf8',
|
|
15
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
16
|
-
});
|
|
17
|
-
const changedFiles = output.trim().split('\n').filter(Boolean);
|
|
18
|
-
return {
|
|
19
|
-
valid: changedFiles.length === 0,
|
|
20
|
-
changedFiles,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
// Git command failed
|
|
25
|
-
return {
|
|
26
|
-
valid: false,
|
|
27
|
-
changedFiles: [],
|
|
28
|
-
error: error instanceof Error ? error.message : String(error),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Check for uncommitted changes (including untracked files)
|
|
34
|
-
*/
|
|
35
|
-
export function checkUncommittedChanges(generatedDir = 'packages/') {
|
|
36
|
-
try {
|
|
37
|
-
// Check for modified files
|
|
38
|
-
const modifiedOutput = execSync(`git diff --name-only "${generatedDir}"`, {
|
|
39
|
-
encoding: 'utf8',
|
|
40
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
41
|
-
});
|
|
42
|
-
// Check for untracked files
|
|
43
|
-
const untrackedOutput = execSync(`git ls-files --others --exclude-standard "${generatedDir}"`, {
|
|
44
|
-
encoding: 'utf8',
|
|
45
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
46
|
-
});
|
|
47
|
-
const modifiedFiles = modifiedOutput.trim().split('\n').filter(Boolean);
|
|
48
|
-
const untrackedFiles = untrackedOutput.trim().split('\n').filter(Boolean);
|
|
49
|
-
const allChangedFiles = [...modifiedFiles, ...untrackedFiles];
|
|
50
|
-
return {
|
|
51
|
-
valid: allChangedFiles.length === 0,
|
|
52
|
-
changedFiles: allChangedFiles,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
return {
|
|
57
|
-
valid: false,
|
|
58
|
-
changedFiles: [],
|
|
59
|
-
error: error instanceof Error ? error.message : String(error),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Run drift check
|
|
65
|
-
*/
|
|
66
|
-
export async function runDriftCheck(options) {
|
|
67
|
-
const start = Date.now();
|
|
68
|
-
const generatedDir = options.generatedDir || 'packages/';
|
|
69
|
-
try {
|
|
70
|
-
const result = checkUncommittedChanges(generatedDir);
|
|
71
|
-
if (result.error) {
|
|
72
|
-
return {
|
|
73
|
-
name: 'drift',
|
|
74
|
-
status: 'fail',
|
|
75
|
-
duration: Date.now() - start,
|
|
76
|
-
message: `Git error: ${result.error}`,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
if (result.valid) {
|
|
80
|
-
return {
|
|
81
|
-
name: 'drift',
|
|
82
|
-
status: 'pass',
|
|
83
|
-
duration: Date.now() - start,
|
|
84
|
-
message: `No uncommitted changes in ${generatedDir}`,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
const details = result.changedFiles.map(f => ` - ${f}`);
|
|
88
|
-
return {
|
|
89
|
-
name: 'drift',
|
|
90
|
-
status: 'fail',
|
|
91
|
-
duration: Date.now() - start,
|
|
92
|
-
message: `${result.changedFiles.length} file(s) have uncommitted changes`,
|
|
93
|
-
details,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
return {
|
|
98
|
-
name: 'drift',
|
|
99
|
-
status: 'fail',
|
|
100
|
-
duration: Date.now() - start,
|
|
101
|
-
message: error instanceof Error ? error.message : String(error),
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Format drift result for CLI output
|
|
107
|
-
*/
|
|
108
|
-
export function formatDriftResult(result) {
|
|
109
|
-
const lines = [];
|
|
110
|
-
if (result.error) {
|
|
111
|
-
lines.push(`❌ Drift check failed: ${result.error}`);
|
|
112
|
-
return lines.join('\n');
|
|
113
|
-
}
|
|
114
|
-
if (result.valid) {
|
|
115
|
-
lines.push('✅ No drift detected - generated files match committed state');
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
lines.push('❌ Generated code differs from committed code:\n');
|
|
119
|
-
for (const file of result.changedFiles) {
|
|
120
|
-
lines.push(` - ${file}`);
|
|
121
|
-
}
|
|
122
|
-
lines.push('\n💡 Run `micro-contracts generate` to regenerate artifacts.');
|
|
123
|
-
lines.push('💡 Then commit the changes or verify they are expected.');
|
|
124
|
-
}
|
|
125
|
-
return lines.join('\n');
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=drift.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"drift.js","sourceRoot":"","sources":["../../src/guardrails/drift.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,eAAuB,WAAW;IAC3D,IAAI,CAAC;QACH,0CAA0C;QAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC,yBAAyB,YAAY,GAAG,EAAE;YAChE,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;SAChC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK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
-
* and enforcing change policies.
|
|
6
|
-
*/
|
|
7
|
-
export type { GuardrailsConfig, ChecksConfig, CheckCommandConfig, AllowlistResult, AllowlistViolation, DriftResult, GeneratedManifest, GeneratedFileInfo, ManifestResult, ManifestMismatch, CheckOptions, CheckResult, CheckSummary, CheckDefinition, GateNumber, } from './types.js';
|
|
8
|
-
export { DEFAULT_GUARDRAILS, findGuardrailsConfig, loadGuardrailsConfig, loadGuardrailsConfigWithPath, generateGuardrailsTemplate, createGuardrailsConfig, } from './config.js';
|
|
9
|
-
export type { LoadedGuardrailsConfig } from './config.js';
|
|
10
|
-
export { matchWithNegation, matchGlob, getChangedFiles, verifyAllowlist, runAllowlistCheck, formatAllowlistResult, } from './allowlist.js';
|
|
11
|
-
export { checkDrift, checkUncommittedChanges, runDriftCheck, formatDriftResult, } from './drift.js';
|
|
12
|
-
export { hashFile, getGeneratedFiles, generateManifest, writeManifest, loadManifest, verifyManifest, canSkipGeneration, runManifestCheck, formatManifestResult, } from './manifest.js';
|
|
13
|
-
export type { GenerateManifestResult } from './manifest.js';
|
|
14
|
-
export { findOpenAPISpecs, runLintCheck, } from './lint.js';
|
|
15
|
-
export { findTsConfigs, runTypecheckCheck, } from './typecheck.js';
|
|
16
|
-
export { checkMarkdownFile, findMarkdownFiles, runDocsCheck, } from './docs.js';
|
|
17
|
-
export { runAllChecks, formatCheckResults, formatSingleCheckResult, formatCheckStart, formatCheckSummary, getAvailableChecks, GATE_DESCRIPTIONS, } from './runner.js';
|
|
18
|
-
export type { CheckSummaryWithGates } from './runner.js';
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guardrails/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG5D,OAAO,EACL,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,aAAa,EACb,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,GACb,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/guardrails/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Guardrails module
|
|
3
|
-
*
|
|
4
|
-
* Provides AI-driven development guardrails for protecting generated artifacts
|
|
5
|
-
* and enforcing change policies.
|
|
6
|
-
*/
|
|
7
|
-
// Config
|
|
8
|
-
export { DEFAULT_GUARDRAILS, findGuardrailsConfig, loadGuardrailsConfig, loadGuardrailsConfigWithPath, generateGuardrailsTemplate, createGuardrailsConfig, } from './config.js';
|
|
9
|
-
// Allowlist
|
|
10
|
-
export { matchWithNegation, matchGlob, getChangedFiles, verifyAllowlist, runAllowlistCheck, formatAllowlistResult, } from './allowlist.js';
|
|
11
|
-
// Drift
|
|
12
|
-
export { checkDrift, checkUncommittedChanges, runDriftCheck, formatDriftResult, } from './drift.js';
|
|
13
|
-
// Manifest
|
|
14
|
-
export { hashFile, getGeneratedFiles, generateManifest, writeManifest, loadManifest, verifyManifest, canSkipGeneration, runManifestCheck, formatManifestResult, } from './manifest.js';
|
|
15
|
-
// Lint
|
|
16
|
-
export { findOpenAPISpecs, runLintCheck, } from './lint.js';
|
|
17
|
-
// Typecheck
|
|
18
|
-
export { findTsConfigs, runTypecheckCheck, } from './typecheck.js';
|
|
19
|
-
// Docs
|
|
20
|
-
export { checkMarkdownFile, findMarkdownFiles, runDocsCheck, } from './docs.js';
|
|
21
|
-
// Check runner
|
|
22
|
-
export { runAllChecks, formatCheckResults, formatSingleCheckResult, formatCheckStart, formatCheckSummary, getAvailableChecks, GATE_DESCRIPTIONS, } from './runner.js';
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guardrails/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,SAAS;AACT,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAIrB,YAAY;AACZ,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,QAAQ;AACR,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,aAAa,EACb,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,WAAW;AACX,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAIvB,OAAO;AACP,OAAO,EACL,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,YAAY;AACZ,OAAO,EACL,aAAa,EACb,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAExB,OAAO;AACP,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,eAAe;AACf,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAPI lint check for guardrails
|
|
3
|
-
*
|
|
4
|
-
* Supports both built-in linter and external command execution.
|
|
5
|
-
*/
|
|
6
|
-
import type { CheckResult, CheckOptions } from './types.js';
|
|
7
|
-
/**
|
|
8
|
-
* Find OpenAPI spec files based on guardrails config or defaults
|
|
9
|
-
*/
|
|
10
|
-
export declare function findOpenAPISpecs(options: CheckOptions): Promise<string[]>;
|
|
11
|
-
/**
|
|
12
|
-
* Run lint check on all OpenAPI specs
|
|
13
|
-
*/
|
|
14
|
-
export declare function runLintCheck(options: CheckOptions): Promise<CheckResult>;
|
|
15
|
-
/**
|
|
16
|
-
* Run a custom command check (generic check execution)
|
|
17
|
-
* This is used for checks defined in guardrails.yaml
|
|
18
|
-
*/
|
|
19
|
-
export declare function runCustomCommandCheck(name: string, commandTemplate: string, options: CheckOptions): Promise<CheckResult>;
|
|
20
|
-
//# sourceMappingURL=lint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/guardrails/lint.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO5D;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAuC/E;AAuDD;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAwB9E;AA8DD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,CAAC,CAwDtB"}
|
package/dist/guardrails/lint.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAPI lint check for guardrails
|
|
3
|
-
*
|
|
4
|
-
* Supports both built-in linter and external command execution.
|
|
5
|
-
*/
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
import yaml from 'js-yaml';
|
|
8
|
-
import { spawn } from 'child_process';
|
|
9
|
-
import { lintSpec } from '../generator/linter.js';
|
|
10
|
-
import { loadGuardrailsConfig, loadGuardrailsConfigWithPath } from './config.js';
|
|
11
|
-
import { glob } from 'glob';
|
|
12
|
-
/**
|
|
13
|
-
* Find OpenAPI spec files based on guardrails config or defaults
|
|
14
|
-
*/
|
|
15
|
-
export async function findOpenAPISpecs(options) {
|
|
16
|
-
// Try to load guardrails config to find spec patterns
|
|
17
|
-
const config = loadGuardrailsConfig(options.guardrailsPath);
|
|
18
|
-
// Look for YAML files in spec directories - prioritize openapi/ subdirs
|
|
19
|
-
const defaultPatterns = [
|
|
20
|
-
'spec/**/openapi/*.yaml',
|
|
21
|
-
'spec/**/openapi/*.yml',
|
|
22
|
-
];
|
|
23
|
-
const specFiles = [];
|
|
24
|
-
for (const pattern of defaultPatterns) {
|
|
25
|
-
const matches = await glob(pattern, {
|
|
26
|
-
ignore: [
|
|
27
|
-
'**/node_modules/**',
|
|
28
|
-
'**/*.overlay.yaml',
|
|
29
|
-
'**/spectral.yaml',
|
|
30
|
-
'**/.generated-manifest.json',
|
|
31
|
-
'**/_shared/**', // Exclude shared schemas
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
// Filter to only OpenAPI specs (have openapi and paths fields)
|
|
35
|
-
for (const match of matches) {
|
|
36
|
-
try {
|
|
37
|
-
const content = fs.readFileSync(match, 'utf-8');
|
|
38
|
-
const doc = yaml.load(content);
|
|
39
|
-
// Must have both 'openapi' version and 'paths' to be a full spec
|
|
40
|
-
if (doc && typeof doc === 'object' && 'openapi' in doc && 'paths' in doc) {
|
|
41
|
-
specFiles.push(match);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// Not a valid YAML or not an OpenAPI spec
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return [...new Set(specFiles)]; // Deduplicate
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Execute an external command and capture output
|
|
53
|
-
*/
|
|
54
|
-
async function executeCommand(command) {
|
|
55
|
-
return new Promise((resolve) => {
|
|
56
|
-
// Use shell to execute the full command string
|
|
57
|
-
// This allows complex commands like "cmd1 && cmd2" or commands with pipes
|
|
58
|
-
const child = spawn(command, [], {
|
|
59
|
-
shell: true,
|
|
60
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
61
|
-
});
|
|
62
|
-
let stdout = '';
|
|
63
|
-
let stderr = '';
|
|
64
|
-
child.stdout?.on('data', (data) => {
|
|
65
|
-
stdout += data.toString();
|
|
66
|
-
});
|
|
67
|
-
child.stderr?.on('data', (data) => {
|
|
68
|
-
stderr += data.toString();
|
|
69
|
-
});
|
|
70
|
-
child.on('close', (code) => {
|
|
71
|
-
resolve({ exitCode: code ?? 1, stdout, stderr });
|
|
72
|
-
});
|
|
73
|
-
child.on('error', (err) => {
|
|
74
|
-
resolve({ exitCode: 1, stdout: '', stderr: err.message });
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Expand placeholders in command template
|
|
80
|
-
*/
|
|
81
|
-
function expandPlaceholders(command, context) {
|
|
82
|
-
let result = command;
|
|
83
|
-
if (context.files) {
|
|
84
|
-
result = result.replace(/\{files\}/g, context.files.join(' '));
|
|
85
|
-
}
|
|
86
|
-
if (context.cwd) {
|
|
87
|
-
result = result.replace(/\{cwd\}/g, context.cwd);
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Run lint check on all OpenAPI specs
|
|
93
|
-
*/
|
|
94
|
-
export async function runLintCheck(options) {
|
|
95
|
-
const start = Date.now();
|
|
96
|
-
try {
|
|
97
|
-
// Load guardrails config to check for custom command
|
|
98
|
-
const { config } = loadGuardrailsConfigWithPath(options.guardrailsPath);
|
|
99
|
-
const lintConfig = config?.checks?.lint;
|
|
100
|
-
// If custom command is configured and enabled, use it
|
|
101
|
-
if (lintConfig?.command && lintConfig.enabled !== false) {
|
|
102
|
-
return await runExternalLintCheck(lintConfig.command, options, start);
|
|
103
|
-
}
|
|
104
|
-
// Otherwise, use built-in linter
|
|
105
|
-
return await runBuiltinLintCheck(options, start);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
return {
|
|
109
|
-
name: 'lint',
|
|
110
|
-
status: 'fail',
|
|
111
|
-
duration: Date.now() - start,
|
|
112
|
-
message: error instanceof Error ? error.message : String(error),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Run external lint command
|
|
118
|
-
*/
|
|
119
|
-
async function runExternalLintCheck(commandTemplate, options, start) {
|
|
120
|
-
// Find OpenAPI specs
|
|
121
|
-
const specFiles = await findOpenAPISpecs(options);
|
|
122
|
-
if (specFiles.length === 0) {
|
|
123
|
-
return {
|
|
124
|
-
name: 'lint',
|
|
125
|
-
status: 'skip',
|
|
126
|
-
duration: Date.now() - start,
|
|
127
|
-
message: 'No OpenAPI specs found',
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
// Expand placeholders
|
|
131
|
-
const command = expandPlaceholders(commandTemplate, {
|
|
132
|
-
files: specFiles,
|
|
133
|
-
cwd: process.cwd(),
|
|
134
|
-
});
|
|
135
|
-
if (options.verbose) {
|
|
136
|
-
console.log(`Running: ${command}`);
|
|
137
|
-
}
|
|
138
|
-
// Execute command
|
|
139
|
-
const { exitCode, stdout, stderr } = await executeCommand(command);
|
|
140
|
-
// Parse output for details
|
|
141
|
-
const output = (stdout + stderr).trim();
|
|
142
|
-
const lines = output.split('\n').filter(line => line.trim());
|
|
143
|
-
if (exitCode === 0) {
|
|
144
|
-
return {
|
|
145
|
-
name: 'lint',
|
|
146
|
-
status: 'pass',
|
|
147
|
-
duration: Date.now() - start,
|
|
148
|
-
message: `${specFiles.length} spec(s) passed lint`,
|
|
149
|
-
details: options.verbose && lines.length > 0 ? lines : undefined,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
// Count errors and warnings from output
|
|
153
|
-
const errorCount = (output.match(/error/gi) || []).length;
|
|
154
|
-
const warningCount = (output.match(/warning/gi) || []).length;
|
|
155
|
-
return {
|
|
156
|
-
name: 'lint',
|
|
157
|
-
status: 'fail',
|
|
158
|
-
duration: Date.now() - start,
|
|
159
|
-
message: `Lint failed with ${errorCount} error(s), ${warningCount} warning(s)`,
|
|
160
|
-
details: lines.slice(0, 50), // Limit output
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Run a custom command check (generic check execution)
|
|
165
|
-
* This is used for checks defined in guardrails.yaml
|
|
166
|
-
*/
|
|
167
|
-
export async function runCustomCommandCheck(name, commandTemplate, options) {
|
|
168
|
-
const start = Date.now();
|
|
169
|
-
try {
|
|
170
|
-
// Find OpenAPI specs for {files} placeholder
|
|
171
|
-
const specFiles = await findOpenAPISpecs(options);
|
|
172
|
-
// Expand placeholders
|
|
173
|
-
const command = expandPlaceholders(commandTemplate, {
|
|
174
|
-
files: specFiles.length > 0 ? specFiles : undefined,
|
|
175
|
-
cwd: process.cwd(),
|
|
176
|
-
});
|
|
177
|
-
if (options.verbose) {
|
|
178
|
-
console.log(`Running: ${command}`);
|
|
179
|
-
}
|
|
180
|
-
// Execute command
|
|
181
|
-
const { exitCode, stdout, stderr } = await executeCommand(command);
|
|
182
|
-
// Parse output for details
|
|
183
|
-
const output = (stdout + stderr).trim();
|
|
184
|
-
const lines = output.split('\n').filter(line => line.trim());
|
|
185
|
-
if (exitCode === 0) {
|
|
186
|
-
return {
|
|
187
|
-
name,
|
|
188
|
-
status: 'pass',
|
|
189
|
-
duration: Date.now() - start,
|
|
190
|
-
message: `${name} passed`,
|
|
191
|
-
details: options.verbose && lines.length > 0 ? lines : undefined,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
// Count errors and warnings from output
|
|
195
|
-
const errorCount = (output.match(/error/gi) || []).length;
|
|
196
|
-
const warningCount = (output.match(/warning/gi) || []).length;
|
|
197
|
-
return {
|
|
198
|
-
name,
|
|
199
|
-
status: 'fail',
|
|
200
|
-
duration: Date.now() - start,
|
|
201
|
-
message: errorCount > 0 || warningCount > 0
|
|
202
|
-
? `${name} failed with ${errorCount} error(s), ${warningCount} warning(s)`
|
|
203
|
-
: `${name} failed (exit code: ${exitCode})`,
|
|
204
|
-
details: lines.slice(0, 50), // Limit output
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
return {
|
|
209
|
-
name,
|
|
210
|
-
status: 'fail',
|
|
211
|
-
duration: Date.now() - start,
|
|
212
|
-
message: error instanceof Error ? error.message : String(error),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Run built-in lint check
|
|
218
|
-
*/
|
|
219
|
-
async function runBuiltinLintCheck(options, start) {
|
|
220
|
-
// Find all OpenAPI specs
|
|
221
|
-
const specFiles = await findOpenAPISpecs(options);
|
|
222
|
-
if (specFiles.length === 0) {
|
|
223
|
-
return {
|
|
224
|
-
name: 'lint',
|
|
225
|
-
status: 'skip',
|
|
226
|
-
duration: Date.now() - start,
|
|
227
|
-
message: 'No OpenAPI specs found',
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
const allErrors = [];
|
|
231
|
-
const allWarnings = [];
|
|
232
|
-
let hasErrors = false;
|
|
233
|
-
for (const specFile of specFiles) {
|
|
234
|
-
try {
|
|
235
|
-
const content = fs.readFileSync(specFile, 'utf-8');
|
|
236
|
-
const spec = yaml.load(content);
|
|
237
|
-
const result = lintSpec(spec, { strict: false });
|
|
238
|
-
if (result.errors.length > 0) {
|
|
239
|
-
hasErrors = true;
|
|
240
|
-
for (const error of result.errors) {
|
|
241
|
-
allErrors.push(`${specFile}: [${error.code}] ${error.message}`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (result.warnings.length > 0) {
|
|
245
|
-
for (const warning of result.warnings) {
|
|
246
|
-
allWarnings.push(`${specFile}: [${warning.code}] ${warning.message}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
catch (error) {
|
|
251
|
-
allErrors.push(`${specFile}: Failed to parse - ${error instanceof Error ? error.message : String(error)}`);
|
|
252
|
-
hasErrors = true;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (hasErrors) {
|
|
256
|
-
return {
|
|
257
|
-
name: 'lint',
|
|
258
|
-
status: 'fail',
|
|
259
|
-
duration: Date.now() - start,
|
|
260
|
-
message: `${allErrors.length} error(s) in ${specFiles.length} spec(s)`,
|
|
261
|
-
details: options.verbose ? [...allErrors, ...allWarnings.map(w => `⚠️ ${w}`)] : allErrors,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return {
|
|
265
|
-
name: 'lint',
|
|
266
|
-
status: 'pass',
|
|
267
|
-
duration: Date.now() - start,
|
|
268
|
-
message: `${specFiles.length} spec(s) passed lint`,
|
|
269
|
-
details: options.verbose && allWarnings.length > 0
|
|
270
|
-
? allWarnings.map(w => `⚠️ ${w}`)
|
|
271
|
-
: undefined,
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
//# sourceMappingURL=lint.js.map
|