@h-rig/standard-plugin 0.0.6-alpha.15 → 0.0.6-alpha.150
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/dist/src/blocker-classifier.d.ts +1 -0
- package/dist/src/blocker-classifier.js +18 -0
- package/dist/src/bundle.d.ts +7 -0
- package/dist/src/bundle.js +1859 -0
- package/dist/src/cli-surface.d.ts +1 -0
- package/dist/src/cli-surface.js +12 -0
- package/dist/src/default-lifecycle.d.ts +2 -0
- package/dist/src/default-lifecycle.js +12 -0
- package/dist/src/dependency-graph.d.ts +1 -0
- package/dist/src/dependency-graph.js +22 -0
- package/dist/src/drift/__fixtures__/temp-repo.d.ts +9 -0
- package/dist/src/drift/__fixtures__/temp-repo.js +41 -0
- package/dist/src/drift/detect.d.ts +11 -0
- package/dist/src/drift/detect.js +299 -0
- package/dist/src/drift/extract-refs.d.ts +7 -0
- package/dist/src/drift/extract-refs.js +60 -0
- package/dist/src/drift/git-adapter.d.ts +7 -0
- package/dist/src/drift/git-adapter.js +63 -0
- package/dist/src/drift/judge.d.ts +19 -0
- package/dist/src/drift/judge.js +16 -0
- package/dist/src/drift/metadata.d.ts +13 -0
- package/dist/src/drift/metadata.js +33 -0
- package/dist/src/drift/plugin.d.ts +53 -0
- package/dist/src/drift/plugin.js +507 -0
- package/dist/src/files-source.d.ts +18 -0
- package/dist/src/files-source.js +4 -3
- package/dist/src/github-issues-source.d.ts +80 -0
- package/dist/src/github-issues-source.js +482 -53
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.js +1369 -68
- package/dist/src/lifecycle-closeout.d.ts +2 -0
- package/dist/src/lifecycle-closeout.js +6 -0
- package/dist/src/planning.d.ts +1 -0
- package/dist/src/planning.js +14 -0
- package/dist/src/plugin.d.ts +24 -0
- package/dist/src/plugin.js +1814 -0
- package/dist/src/product-plugin.d.ts +3 -0
- package/dist/src/product-plugin.js +18 -0
- package/dist/src/run-worker-panels.d.ts +15 -0
- package/dist/src/run-worker-panels.js +53 -0
- package/dist/src/supervisor.d.ts +1 -0
- package/dist/src/supervisor.js +12 -0
- package/dist/src/task-cli.d.ts +1 -0
- package/dist/src/task-cli.js +14 -0
- package/package.json +67 -5
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { DriftFinding, DriftReport, StageResult, StageRun } from "@rig/contracts";
|
|
2
|
+
import type { RegisteredValidator, RuntimeCliCommand, RuntimeCliContext, ValidatorResult } from "@rig/core/config";
|
|
3
|
+
import { type DriftDetectOptions } from "./detect";
|
|
4
|
+
export { DOCS_DRIFT_CAPABILITY_ID, DOCS_DRIFT_CLI_COMMAND, DOCS_DRIFT_CLI_ID, DOCS_DRIFT_STAGE_ID, DOCS_DRIFT_STAGE_MUTATION, DOCS_DRIFT_VALIDATOR, DOCS_DRIFT_VALIDATOR_ID, type DocsDriftPluginOptions, } from "./metadata";
|
|
5
|
+
import { type DocsDriftPluginOptions } from "./metadata";
|
|
6
|
+
export declare function highConfidenceDriftFindings(report: DriftReport): readonly DriftFinding[];
|
|
7
|
+
export declare function driftGateResult(report: DriftReport, mode?: "observe" | "enforce"): StageResult;
|
|
8
|
+
/**
|
|
9
|
+
* Executable for the `docs-drift` pre-merge gate stage (inserted by
|
|
10
|
+
* DOCS_DRIFT_STAGE_MUTATION before `merge-gate`). Reads the project root from the
|
|
11
|
+
* stage context metadata, runs deletion-survival drift detection, and blocks the
|
|
12
|
+
* pipeline on high-confidence drift when enforcing (`failOnDrift`), else observes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createDocsDriftGateStage(options?: DocsDriftPluginOptions): StageRun;
|
|
15
|
+
export declare function runDocsDriftValidation(options: DriftDetectOptions & {
|
|
16
|
+
failOnDrift?: boolean;
|
|
17
|
+
}): Promise<ValidatorResult>;
|
|
18
|
+
export declare function createDocsDriftValidator(options?: DocsDriftPluginOptions): RegisteredValidator;
|
|
19
|
+
export interface RunDriftCliOptions {
|
|
20
|
+
readonly projectRoot?: string;
|
|
21
|
+
readonly write?: (message: string) => void;
|
|
22
|
+
readonly writeError?: (message: string) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare function executeDrift(context: RuntimeCliContext, args: readonly string[], options?: DocsDriftPluginOptions): Promise<{
|
|
25
|
+
ok: boolean;
|
|
26
|
+
group: string;
|
|
27
|
+
command: string;
|
|
28
|
+
details: {
|
|
29
|
+
report: {
|
|
30
|
+
readonly degraded: boolean;
|
|
31
|
+
readonly generatedAt: string;
|
|
32
|
+
readonly findings: readonly {
|
|
33
|
+
readonly kind: "deleted-reference" | "stale-anchor" | "semantic-mismatch" | "issue-mismatch";
|
|
34
|
+
readonly detail: string;
|
|
35
|
+
readonly line: number | null;
|
|
36
|
+
readonly reference: string | null;
|
|
37
|
+
readonly docPath: string;
|
|
38
|
+
readonly confidence: "high" | "medium" | "low";
|
|
39
|
+
}[];
|
|
40
|
+
readonly scanned: number;
|
|
41
|
+
};
|
|
42
|
+
summary: {
|
|
43
|
+
total: number;
|
|
44
|
+
highConfidence: number;
|
|
45
|
+
degraded: boolean;
|
|
46
|
+
};
|
|
47
|
+
failOnDrift: boolean;
|
|
48
|
+
failed: boolean;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
export declare function createDocsDriftRuntimeCliCommand(options?: DocsDriftPluginOptions): RuntimeCliCommand;
|
|
52
|
+
export declare const DOCS_DRIFT_RUNTIME_CLI_COMMAND: RuntimeCliCommand;
|
|
53
|
+
export declare function runDriftCli(args: readonly string[], options?: RunDriftCliOptions): Promise<number>;
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/standard-plugin/src/drift/detect.ts
|
|
3
|
+
import { existsSync } from "fs";
|
|
4
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
5
|
+
import { basename, extname, relative, resolve } from "path";
|
|
6
|
+
|
|
7
|
+
// packages/standard-plugin/src/drift/extract-refs.ts
|
|
8
|
+
var INLINE_CODE = /`([^`\n]+)`/g;
|
|
9
|
+
var MARKDOWN_LINK = /\[[^\]]+\]\(([^)\s]+)\)/g;
|
|
10
|
+
var SYMBOL_REF = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)?$/;
|
|
11
|
+
var PATH_REF = /^(?:\.\.?\/)?(?:[A-Za-z0-9_.-]+\/)+[A-Za-z0-9_.-]+$|^[A-Za-z0-9_.-]+\.(?:ts|tsx|js|jsx|mjs|cjs|json|md|mdx|css|scss|html|yml|yaml|toml|rs|go|py|rb|java|kt|swift|c|cc|cpp|h|hpp)$/;
|
|
12
|
+
function stripFenceLines(markdown) {
|
|
13
|
+
const lines = markdown.split(/\r?\n/);
|
|
14
|
+
let fenced = false;
|
|
15
|
+
return lines.map((line) => {
|
|
16
|
+
if (/^\s*(```|~~~)/.test(line)) {
|
|
17
|
+
fenced = !fenced;
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
return fenced ? "" : line;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function normalizeToken(raw) {
|
|
24
|
+
return raw.trim().replace(/^['"]|['"]$/g, "").replace(/[),.;:]+$/g, "").replace(/#L\d+(?:-L\d+)?$/i, "");
|
|
25
|
+
}
|
|
26
|
+
function classifyReference(raw) {
|
|
27
|
+
if (raw.startsWith("@"))
|
|
28
|
+
return null;
|
|
29
|
+
if (PATH_REF.test(raw))
|
|
30
|
+
return "path";
|
|
31
|
+
if (SYMBOL_REF.test(raw))
|
|
32
|
+
return "symbol";
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function pushReference(refs, seen, raw, line) {
|
|
36
|
+
const value = normalizeToken(raw);
|
|
37
|
+
if (!value)
|
|
38
|
+
return;
|
|
39
|
+
const kind = classifyReference(value);
|
|
40
|
+
if (!kind)
|
|
41
|
+
return;
|
|
42
|
+
const key = `${kind}:${value}:${line}`;
|
|
43
|
+
if (seen.has(key))
|
|
44
|
+
return;
|
|
45
|
+
seen.add(key);
|
|
46
|
+
refs.push({ kind, value, line });
|
|
47
|
+
}
|
|
48
|
+
function extractDriftReferences(markdown) {
|
|
49
|
+
const refs = [];
|
|
50
|
+
const seen = new Set;
|
|
51
|
+
const lines = stripFenceLines(markdown);
|
|
52
|
+
for (const [index, line] of lines.entries()) {
|
|
53
|
+
const lineNumber = index + 1;
|
|
54
|
+
for (const match of line.matchAll(INLINE_CODE)) {
|
|
55
|
+
pushReference(refs, seen, match[1] ?? "", lineNumber);
|
|
56
|
+
}
|
|
57
|
+
for (const match of line.matchAll(MARKDOWN_LINK)) {
|
|
58
|
+
pushReference(refs, seen, match[1] ?? "", lineNumber);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return refs;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// packages/standard-plugin/src/drift/git-adapter.ts
|
|
65
|
+
import { execFile } from "child_process";
|
|
66
|
+
import { promisify } from "util";
|
|
67
|
+
var execFileAsync = promisify(execFile);
|
|
68
|
+
function processError(value) {
|
|
69
|
+
return value && typeof value === "object" ? value : null;
|
|
70
|
+
}
|
|
71
|
+
function lineCount(output) {
|
|
72
|
+
const trimmed = output.trim();
|
|
73
|
+
return trimmed ? trimmed.split(/\r?\n/).length : 0;
|
|
74
|
+
}
|
|
75
|
+
function makeDriftGit(projectRoot) {
|
|
76
|
+
async function git(args) {
|
|
77
|
+
const result = await execFileAsync("git", [...args], {
|
|
78
|
+
cwd: projectRoot,
|
|
79
|
+
encoding: "utf8",
|
|
80
|
+
maxBuffer: 10 * 1024 * 1024
|
|
81
|
+
});
|
|
82
|
+
return String(result.stdout);
|
|
83
|
+
}
|
|
84
|
+
async function grepCountAt(symbolOrPath, commit) {
|
|
85
|
+
try {
|
|
86
|
+
return lineCount(await git(["grep", "-F", "-n", "-e", symbolOrPath, commit, "--"]));
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const detail = processError(error);
|
|
89
|
+
if (detail?.code === 1)
|
|
90
|
+
return 0;
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
async lastCommitTouching(path) {
|
|
96
|
+
const commit = (await git(["log", "-n", "1", "--format=%H", "--", path])).trim();
|
|
97
|
+
return commit || "HEAD";
|
|
98
|
+
},
|
|
99
|
+
async grepCount(symbolOrPath) {
|
|
100
|
+
return grepCountAt(symbolOrPath, "HEAD");
|
|
101
|
+
},
|
|
102
|
+
async grepCountAtCommit(symbolOrPath, commit) {
|
|
103
|
+
return grepCountAt(symbolOrPath, commit);
|
|
104
|
+
},
|
|
105
|
+
async wasRenamed(symbolOrPath, sinceCommit) {
|
|
106
|
+
if (!symbolOrPath.includes("/") && !symbolOrPath.includes("."))
|
|
107
|
+
return false;
|
|
108
|
+
try {
|
|
109
|
+
const output = await git(["log", "--name-status", "--format=", `${sinceCommit}..HEAD`]);
|
|
110
|
+
return output.split(/\r?\n/).some((line) => {
|
|
111
|
+
const match = line.match(/^R\d*\s+(.+?)\s+(.+)$/);
|
|
112
|
+
return Boolean(match && (match[1] === symbolOrPath || match[2] === symbolOrPath));
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const detail = processError(error);
|
|
116
|
+
if (detail?.code === 128)
|
|
117
|
+
return false;
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// packages/standard-plugin/src/drift/detect.ts
|
|
125
|
+
var DEFAULT_IGNORED_DIRS = {
|
|
126
|
+
".git": true,
|
|
127
|
+
node_modules: true,
|
|
128
|
+
dist: true,
|
|
129
|
+
build: true,
|
|
130
|
+
coverage: true,
|
|
131
|
+
".next": true,
|
|
132
|
+
vendor: true
|
|
133
|
+
};
|
|
134
|
+
var SOURCE_EXTENSIONS = {
|
|
135
|
+
".ts": true,
|
|
136
|
+
".tsx": true,
|
|
137
|
+
".js": true,
|
|
138
|
+
".jsx": true,
|
|
139
|
+
".mjs": true,
|
|
140
|
+
".cjs": true,
|
|
141
|
+
".rs": true,
|
|
142
|
+
".go": true,
|
|
143
|
+
".py": true,
|
|
144
|
+
".rb": true,
|
|
145
|
+
".java": true,
|
|
146
|
+
".kt": true,
|
|
147
|
+
".swift": true,
|
|
148
|
+
".c": true,
|
|
149
|
+
".cc": true,
|
|
150
|
+
".cpp": true,
|
|
151
|
+
".h": true,
|
|
152
|
+
".hpp": true,
|
|
153
|
+
".json": true,
|
|
154
|
+
".toml": true,
|
|
155
|
+
".yml": true,
|
|
156
|
+
".yaml": true
|
|
157
|
+
};
|
|
158
|
+
function globLikeMatch(path, pattern) {
|
|
159
|
+
if (pattern === path)
|
|
160
|
+
return true;
|
|
161
|
+
if (pattern.startsWith("**/*"))
|
|
162
|
+
return path.endsWith(pattern.slice(4));
|
|
163
|
+
if (pattern.endsWith("/**"))
|
|
164
|
+
return path.startsWith(pattern.slice(0, -3));
|
|
165
|
+
if (pattern.includes("*")) {
|
|
166
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
167
|
+
return new RegExp(`^${escaped}$`).test(path);
|
|
168
|
+
}
|
|
169
|
+
return path.startsWith(pattern);
|
|
170
|
+
}
|
|
171
|
+
function isDefaultDoc(path) {
|
|
172
|
+
const lower = basename(path).toLowerCase();
|
|
173
|
+
return (path.endsWith(".md") || path.endsWith(".mdx")) && !lower.startsWith("changelog") && !lower.includes("generated");
|
|
174
|
+
}
|
|
175
|
+
function isIgnored(path, patterns) {
|
|
176
|
+
return (patterns ?? []).some((pattern) => globLikeMatch(path, pattern));
|
|
177
|
+
}
|
|
178
|
+
async function collectFiles(root, options) {
|
|
179
|
+
const files = [];
|
|
180
|
+
async function visit(dir) {
|
|
181
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
182
|
+
if (entry.isDirectory() && DEFAULT_IGNORED_DIRS[entry.name])
|
|
183
|
+
continue;
|
|
184
|
+
const absolute = resolve(dir, entry.name);
|
|
185
|
+
const rel = relative(root, absolute).replace(/\\/g, "/");
|
|
186
|
+
if (isIgnored(rel, options.ignore))
|
|
187
|
+
continue;
|
|
188
|
+
if (entry.isDirectory()) {
|
|
189
|
+
await visit(absolute);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (!entry.isFile())
|
|
193
|
+
continue;
|
|
194
|
+
if (options.docs) {
|
|
195
|
+
const matchesConfigured = options.patterns && options.patterns.length > 0 ? options.patterns.some((pattern) => globLikeMatch(rel, pattern)) : isDefaultDoc(rel);
|
|
196
|
+
if (matchesConfigured)
|
|
197
|
+
files.push(rel);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (SOURCE_EXTENSIONS[extname(entry.name)])
|
|
201
|
+
files.push(rel);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
await visit(root);
|
|
205
|
+
return files.sort();
|
|
206
|
+
}
|
|
207
|
+
async function sourceReferenceCount(projectRoot, reference, docPath) {
|
|
208
|
+
if (reference.kind === "path")
|
|
209
|
+
return existsSync(resolve(projectRoot, reference.value)) ? 1 : 0;
|
|
210
|
+
let count = 0;
|
|
211
|
+
const sourceFiles = await collectFiles(projectRoot, { docs: false });
|
|
212
|
+
for (const sourceFile of sourceFiles) {
|
|
213
|
+
if (sourceFile === docPath)
|
|
214
|
+
continue;
|
|
215
|
+
const text = await readFile(resolve(projectRoot, sourceFile), "utf8").catch(() => "");
|
|
216
|
+
if (text.includes(reference.value))
|
|
217
|
+
count += 1;
|
|
218
|
+
}
|
|
219
|
+
return count;
|
|
220
|
+
}
|
|
221
|
+
function deletedReferenceFinding(docPath, reference) {
|
|
222
|
+
return {
|
|
223
|
+
kind: "deleted-reference",
|
|
224
|
+
docPath,
|
|
225
|
+
line: reference.line,
|
|
226
|
+
reference: reference.value,
|
|
227
|
+
detail: `Documented reference "${reference.value}" no longer exists in the source tree.`,
|
|
228
|
+
confidence: "high"
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function staleAnchorFinding(docPath, reference) {
|
|
232
|
+
return {
|
|
233
|
+
kind: "stale-anchor",
|
|
234
|
+
docPath,
|
|
235
|
+
line: reference.line,
|
|
236
|
+
reference: reference.value,
|
|
237
|
+
detail: `Documented path "${reference.value}" changed after this doc was last updated.`,
|
|
238
|
+
confidence: "medium"
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
async function detectDeletedReferences(projectRoot, docPath, git = makeDriftGit(projectRoot)) {
|
|
242
|
+
const markdown = await readFile(resolve(projectRoot, docPath), "utf8");
|
|
243
|
+
const docCommit = await git.lastCommitTouching(docPath);
|
|
244
|
+
const findings = [];
|
|
245
|
+
for (const reference of extractDriftReferences(markdown)) {
|
|
246
|
+
if (await sourceReferenceCount(projectRoot, reference, docPath) > 0)
|
|
247
|
+
continue;
|
|
248
|
+
if (await git.wasRenamed(reference.value, docCommit))
|
|
249
|
+
continue;
|
|
250
|
+
findings.push(deletedReferenceFinding(docPath, reference));
|
|
251
|
+
}
|
|
252
|
+
return findings;
|
|
253
|
+
}
|
|
254
|
+
async function detectStaleAnchors(projectRoot, docPath, git = makeDriftGit(projectRoot)) {
|
|
255
|
+
const markdown = await readFile(resolve(projectRoot, docPath), "utf8");
|
|
256
|
+
const docCommit = await git.lastCommitTouching(docPath);
|
|
257
|
+
const findings = [];
|
|
258
|
+
for (const reference of extractDriftReferences(markdown).filter((ref) => ref.kind === "path")) {
|
|
259
|
+
if (!existsSync(resolve(projectRoot, reference.value)))
|
|
260
|
+
continue;
|
|
261
|
+
const sourceStat = await stat(resolve(projectRoot, reference.value)).catch(() => null);
|
|
262
|
+
if (!sourceStat?.isFile())
|
|
263
|
+
continue;
|
|
264
|
+
const sourceCommit = await git.lastCommitTouching(reference.value);
|
|
265
|
+
if (sourceCommit !== docCommit && !await git.wasRenamed(reference.value, docCommit)) {
|
|
266
|
+
findings.push(staleAnchorFinding(docPath, reference));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return findings;
|
|
270
|
+
}
|
|
271
|
+
async function detectDrift(options) {
|
|
272
|
+
const git = options.git ?? makeDriftGit(options.projectRoot);
|
|
273
|
+
const docs = await collectFiles(options.projectRoot, {
|
|
274
|
+
docs: true,
|
|
275
|
+
...options.docsGlobs !== undefined ? { patterns: options.docsGlobs } : {},
|
|
276
|
+
...options.ignoreGlobs !== undefined ? { ignore: options.ignoreGlobs } : {}
|
|
277
|
+
});
|
|
278
|
+
const findings = [];
|
|
279
|
+
let degraded = false;
|
|
280
|
+
for (const docPath of docs) {
|
|
281
|
+
try {
|
|
282
|
+
findings.push(...await detectDeletedReferences(options.projectRoot, docPath, git));
|
|
283
|
+
findings.push(...await detectStaleAnchors(options.projectRoot, docPath, git));
|
|
284
|
+
} catch {
|
|
285
|
+
degraded = true;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
generatedAt: new Date().toISOString(),
|
|
290
|
+
scanned: docs.length,
|
|
291
|
+
degraded,
|
|
292
|
+
findings
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// packages/standard-plugin/src/drift/metadata.ts
|
|
297
|
+
import { Schema } from "effect";
|
|
298
|
+
import { StageMutation as StageMutationSchema } from "@rig/contracts";
|
|
299
|
+
var DOCS_DRIFT_VALIDATOR_ID = "std:docs-drift";
|
|
300
|
+
var DOCS_DRIFT_CLI_ID = "std:drift";
|
|
301
|
+
var DOCS_DRIFT_STAGE_ID = "docs-drift";
|
|
302
|
+
var DOCS_DRIFT_CAPABILITY_ID = "std:docs-drift-capability";
|
|
303
|
+
var DOCS_DRIFT_VALIDATOR = {
|
|
304
|
+
id: DOCS_DRIFT_VALIDATOR_ID,
|
|
305
|
+
category: "regression",
|
|
306
|
+
description: "Detect documentation references that drifted from the source tree."
|
|
307
|
+
};
|
|
308
|
+
var DOCS_DRIFT_STAGE_MUTATION = Schema.decodeUnknownSync(StageMutationSchema)({
|
|
309
|
+
op: "insert",
|
|
310
|
+
stage: {
|
|
311
|
+
id: DOCS_DRIFT_STAGE_ID,
|
|
312
|
+
kind: "gate",
|
|
313
|
+
before: ["merge-gate"],
|
|
314
|
+
after: ["open-pr"]
|
|
315
|
+
},
|
|
316
|
+
contributedBy: DOCS_DRIFT_STAGE_ID
|
|
317
|
+
});
|
|
318
|
+
var DOCS_DRIFT_CLI_COMMAND = "rig drift [--docs <csv>] [--ignore <csv>] [--fail-on-drift] [--json]";
|
|
319
|
+
// packages/standard-plugin/src/drift/plugin.ts
|
|
320
|
+
function highConfidenceDriftFindings(report) {
|
|
321
|
+
return report.findings.filter((finding) => finding.confidence === "high");
|
|
322
|
+
}
|
|
323
|
+
function driftGateResult(report, mode = "enforce") {
|
|
324
|
+
const high = highConfidenceDriftFindings(report);
|
|
325
|
+
if (mode === "enforce" && high.length > 0) {
|
|
326
|
+
return { kind: "block", reason: `${high.length} high-confidence documentation drift finding(s).` };
|
|
327
|
+
}
|
|
328
|
+
return { kind: "allow" };
|
|
329
|
+
}
|
|
330
|
+
function createDocsDriftGateStage(options = {}) {
|
|
331
|
+
return async (ctx) => {
|
|
332
|
+
const projectRoot = typeof ctx.metadata?.projectRoot === "string" ? ctx.metadata.projectRoot : process.cwd();
|
|
333
|
+
const report = await detectDrift({
|
|
334
|
+
projectRoot,
|
|
335
|
+
...options.docsGlobs !== undefined ? { docsGlobs: options.docsGlobs } : {},
|
|
336
|
+
...options.ignoreGlobs !== undefined ? { ignoreGlobs: options.ignoreGlobs } : {}
|
|
337
|
+
});
|
|
338
|
+
return driftGateResult(report, options.failOnDrift ? "enforce" : "observe");
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
async function runDocsDriftValidation(options) {
|
|
342
|
+
const report = await detectDrift(options);
|
|
343
|
+
const high = highConfidenceDriftFindings(report);
|
|
344
|
+
const passed = options.failOnDrift ? high.length === 0 : true;
|
|
345
|
+
const findingWord = report.findings.length === 1 ? "finding" : "findings";
|
|
346
|
+
return {
|
|
347
|
+
id: DOCS_DRIFT_VALIDATOR_ID,
|
|
348
|
+
passed,
|
|
349
|
+
summary: `docs drift scanned ${report.scanned} doc(s), ${report.findings.length} ${findingWord}`,
|
|
350
|
+
details: JSON.stringify(report)
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function createDocsDriftValidator(options = {}) {
|
|
354
|
+
return {
|
|
355
|
+
...DOCS_DRIFT_VALIDATOR,
|
|
356
|
+
async run(ctx) {
|
|
357
|
+
return runDocsDriftValidation({
|
|
358
|
+
projectRoot: ctx.workspaceRoot,
|
|
359
|
+
...options.docsGlobs !== undefined ? { docsGlobs: options.docsGlobs } : {},
|
|
360
|
+
...options.ignoreGlobs !== undefined ? { ignoreGlobs: options.ignoreGlobs } : {},
|
|
361
|
+
...options.failOnDrift !== undefined ? { failOnDrift: options.failOnDrift } : {}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function takeOptionValue(args, index, flag) {
|
|
367
|
+
const value = args[index + 1];
|
|
368
|
+
if (!value)
|
|
369
|
+
throw new Error(`${flag} requires a value`);
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
372
|
+
function takeFlag(args, flag) {
|
|
373
|
+
const rest = [...args];
|
|
374
|
+
const index = rest.indexOf(flag);
|
|
375
|
+
if (index < 0)
|
|
376
|
+
return { value: false, rest };
|
|
377
|
+
rest.splice(index, 1);
|
|
378
|
+
return { value: true, rest };
|
|
379
|
+
}
|
|
380
|
+
function takeOption(args, flag) {
|
|
381
|
+
const rest = [...args];
|
|
382
|
+
const index = rest.indexOf(flag);
|
|
383
|
+
if (index < 0)
|
|
384
|
+
return { rest };
|
|
385
|
+
const value = rest[index + 1];
|
|
386
|
+
if (!value || value.startsWith("-"))
|
|
387
|
+
throw new Error(`${flag} requires a value.`);
|
|
388
|
+
rest.splice(index, 2);
|
|
389
|
+
return { value, rest };
|
|
390
|
+
}
|
|
391
|
+
function requireNoExtraArgs(args, usage) {
|
|
392
|
+
if (args.length > 0)
|
|
393
|
+
throw new Error(`Unexpected argument: ${args[0]}
|
|
394
|
+
Usage: ${usage}`);
|
|
395
|
+
}
|
|
396
|
+
function parseCsv(value) {
|
|
397
|
+
return value?.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0) ?? [];
|
|
398
|
+
}
|
|
399
|
+
function driftSummary(report) {
|
|
400
|
+
const highConfidence = highConfidenceDriftFindings(report).length;
|
|
401
|
+
return { total: report.findings.length, highConfidence, degraded: report.degraded };
|
|
402
|
+
}
|
|
403
|
+
async function executeDrift(context, args, options = {}) {
|
|
404
|
+
const json = takeFlag(args, "--json");
|
|
405
|
+
const docs = takeOption(json.rest, "--docs");
|
|
406
|
+
const ignore = takeOption(docs.rest, "--ignore");
|
|
407
|
+
const failOnDrift = takeFlag(ignore.rest, "--fail-on-drift");
|
|
408
|
+
requireNoExtraArgs(failOnDrift.rest, "rig drift [--docs <csv>] [--ignore <csv>] [--fail-on-drift] [--json]");
|
|
409
|
+
const docsGlobs = parseCsv(docs.value);
|
|
410
|
+
const ignoreGlobs = parseCsv(ignore.value);
|
|
411
|
+
const effectiveDocsGlobs = docsGlobs.length > 0 ? docsGlobs : options.docsGlobs;
|
|
412
|
+
const effectiveIgnoreGlobs = ignoreGlobs.length > 0 ? ignoreGlobs : options.ignoreGlobs;
|
|
413
|
+
const effectiveFailOnDrift = failOnDrift.value || options.failOnDrift === true;
|
|
414
|
+
const report = await detectDrift({
|
|
415
|
+
projectRoot: context.projectRoot,
|
|
416
|
+
...effectiveDocsGlobs !== undefined ? { docsGlobs: effectiveDocsGlobs } : {},
|
|
417
|
+
...effectiveIgnoreGlobs !== undefined ? { ignoreGlobs: effectiveIgnoreGlobs } : {}
|
|
418
|
+
});
|
|
419
|
+
const failed = effectiveFailOnDrift && highConfidenceDriftFindings(report).length > 0;
|
|
420
|
+
const details = { report, summary: driftSummary(report), failOnDrift: effectiveFailOnDrift, failed };
|
|
421
|
+
if (context.outputMode === "text") {
|
|
422
|
+
if (json.value)
|
|
423
|
+
console.log(JSON.stringify(details, null, 2));
|
|
424
|
+
else
|
|
425
|
+
console.log(report.findings.length === 0 ? `No drift findings across ${report.scanned} documents.` : report.findings.map((finding) => `${finding.docPath}:${finding.line ?? "?"} ${finding.kind} ${finding.confidence} ${finding.detail}`).join(`
|
|
426
|
+
`));
|
|
427
|
+
}
|
|
428
|
+
return { ok: !failed, group: "drift", command: "scan", details };
|
|
429
|
+
}
|
|
430
|
+
function createDocsDriftRuntimeCliCommand(options = {}) {
|
|
431
|
+
return {
|
|
432
|
+
id: DOCS_DRIFT_CLI_ID,
|
|
433
|
+
family: "drift",
|
|
434
|
+
command: DOCS_DRIFT_CLI_COMMAND,
|
|
435
|
+
description: "Scan documentation for stale code references.",
|
|
436
|
+
usage: DOCS_DRIFT_CLI_COMMAND,
|
|
437
|
+
projectRequired: true,
|
|
438
|
+
run: (context, args) => executeDrift(context, args, options)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
var DOCS_DRIFT_RUNTIME_CLI_COMMAND = createDocsDriftRuntimeCliCommand();
|
|
442
|
+
async function runDriftCli(args, options = {}) {
|
|
443
|
+
const docsGlobs = [];
|
|
444
|
+
const ignoreGlobs = [];
|
|
445
|
+
let json = false;
|
|
446
|
+
let failOnDrift = false;
|
|
447
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
448
|
+
const arg = args[index];
|
|
449
|
+
if (arg === "--json") {
|
|
450
|
+
json = true;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (arg === "--fail-on-drift") {
|
|
454
|
+
failOnDrift = true;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (arg === "--docs") {
|
|
458
|
+
docsGlobs.push(takeOptionValue(args, index, arg));
|
|
459
|
+
index += 1;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (arg === "--ignore") {
|
|
463
|
+
ignoreGlobs.push(takeOptionValue(args, index, arg));
|
|
464
|
+
index += 1;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
throw new Error(`Unknown rig drift argument: ${arg}`);
|
|
468
|
+
}
|
|
469
|
+
const report = await detectDrift({
|
|
470
|
+
projectRoot: options.projectRoot ?? process.cwd(),
|
|
471
|
+
...docsGlobs.length > 0 ? { docsGlobs } : {},
|
|
472
|
+
...ignoreGlobs.length > 0 ? { ignoreGlobs } : {}
|
|
473
|
+
});
|
|
474
|
+
const write = options.write ?? ((message) => console.log(message));
|
|
475
|
+
if (json) {
|
|
476
|
+
write(JSON.stringify(report));
|
|
477
|
+
} else {
|
|
478
|
+
write(`Scanned ${report.scanned} doc(s); ${report.findings.length} drift finding(s).`);
|
|
479
|
+
for (const finding of report.findings) {
|
|
480
|
+
write(`${finding.confidence.toUpperCase()} ${finding.kind} ${finding.docPath}${finding.line ? `:${finding.line}` : ""} ${finding.reference ?? ""} \u2014 ${finding.detail}`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const high = highConfidenceDriftFindings(report);
|
|
484
|
+
if (failOnDrift && high.length > 0) {
|
|
485
|
+
options.writeError?.(`${high.length} high-confidence drift finding(s).`);
|
|
486
|
+
return 2;
|
|
487
|
+
}
|
|
488
|
+
return 0;
|
|
489
|
+
}
|
|
490
|
+
export {
|
|
491
|
+
runDriftCli,
|
|
492
|
+
runDocsDriftValidation,
|
|
493
|
+
highConfidenceDriftFindings,
|
|
494
|
+
executeDrift,
|
|
495
|
+
driftGateResult,
|
|
496
|
+
createDocsDriftValidator,
|
|
497
|
+
createDocsDriftRuntimeCliCommand,
|
|
498
|
+
createDocsDriftGateStage,
|
|
499
|
+
DOCS_DRIFT_VALIDATOR_ID,
|
|
500
|
+
DOCS_DRIFT_VALIDATOR,
|
|
501
|
+
DOCS_DRIFT_STAGE_MUTATION,
|
|
502
|
+
DOCS_DRIFT_STAGE_ID,
|
|
503
|
+
DOCS_DRIFT_RUNTIME_CLI_COMMAND,
|
|
504
|
+
DOCS_DRIFT_CLI_ID,
|
|
505
|
+
DOCS_DRIFT_CLI_COMMAND,
|
|
506
|
+
DOCS_DRIFT_CAPABILITY_ID
|
|
507
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RegisteredTaskSource } from "@rig/contracts";
|
|
2
|
+
export interface FilesTaskSourceOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Directory containing one JSON file per task. Use either `path` (matches
|
|
5
|
+
* the `taskSource.path` field in rig.config.ts) or `dir` (back-compat).
|
|
6
|
+
*/
|
|
7
|
+
path?: string;
|
|
8
|
+
dir?: string;
|
|
9
|
+
pattern?: RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* Root a relative `path`/`dir` resolves against. The serving process's cwd
|
|
12
|
+
* is NOT the project (workspace-spawned servers run from the engine
|
|
13
|
+
* checkout), so without this a relative path silently reads the WRONG
|
|
14
|
+
* repo's tasks. Defaults to cwd for direct programmatic use.
|
|
15
|
+
*/
|
|
16
|
+
projectRoot?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function createFilesTaskSource(opts: FilesTaskSourceOptions): RegisteredTaskSource;
|
package/dist/src/files-source.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/standard-plugin/src/files-source.ts
|
|
3
3
|
import { readFileSync, readdirSync, existsSync, statSync, writeFileSync } from "fs";
|
|
4
|
-
import { join, basename } from "path";
|
|
4
|
+
import { join, basename, isAbsolute, resolve } from "path";
|
|
5
5
|
var DEFAULT_PATTERN = /\.(task\.)?json$/;
|
|
6
6
|
function readTaskFile(file, pattern) {
|
|
7
7
|
const raw = JSON.parse(readFileSync(file, "utf-8"));
|
|
@@ -22,10 +22,11 @@ function readTaskFile(file, pattern) {
|
|
|
22
22
|
}
|
|
23
23
|
function createFilesTaskSource(opts) {
|
|
24
24
|
const pattern = opts.pattern ?? DEFAULT_PATTERN;
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
25
|
+
const configured = opts.path ?? opts.dir;
|
|
26
|
+
if (!configured) {
|
|
27
27
|
throw new Error("createFilesTaskSource: either `path` or `dir` must be provided");
|
|
28
28
|
}
|
|
29
|
+
const directory = isAbsolute(configured) ? configured : resolve(opts.projectRoot ?? process.cwd(), configured);
|
|
29
30
|
const findTaskFile = (id) => {
|
|
30
31
|
if (!existsSync(directory))
|
|
31
32
|
return;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import type { RegisteredTaskSource, TaskRecord } from "@rig/contracts";
|
|
3
|
+
export type GitHubCredentialPurpose = "selected-repo" | "admin-fallback";
|
|
4
|
+
export type GitHubIssueUpdatesMode = "lifecycle" | "minimal" | "off";
|
|
5
|
+
export interface GitHubCredentialProvider {
|
|
6
|
+
resolveGitHubToken(input: {
|
|
7
|
+
owner: string;
|
|
8
|
+
repo: string;
|
|
9
|
+
workspaceId: string;
|
|
10
|
+
userId?: string;
|
|
11
|
+
purpose: GitHubCredentialPurpose;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
token: string;
|
|
14
|
+
source: "signed-in-user" | "host-admin-fallback";
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
export type GitHubProjectLifecycleStatus = "todo" | "running" | "prOpen" | "ciFixing" | "merging" | "done" | "needsAttention";
|
|
18
|
+
export interface GitHubProjectsOptions {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
projectId?: string;
|
|
21
|
+
statusFieldId?: string;
|
|
22
|
+
statuses?: Partial<Record<GitHubProjectLifecycleStatus, string>>;
|
|
23
|
+
}
|
|
24
|
+
export interface GitHubIssuesOptions {
|
|
25
|
+
owner: string;
|
|
26
|
+
repo: string;
|
|
27
|
+
labels?: readonly string[];
|
|
28
|
+
state?: "open" | "closed" | "all";
|
|
29
|
+
assignee?: string;
|
|
30
|
+
ghBinary?: string;
|
|
31
|
+
workspaceId?: string;
|
|
32
|
+
userId?: string;
|
|
33
|
+
credentialProvider?: GitHubCredentialProvider;
|
|
34
|
+
issueUpdates?: GitHubIssueUpdatesMode;
|
|
35
|
+
/** Timeout for every gh CLI call. Defaults to 15 seconds. */
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
/** Maximum issue-list rows before Rig fails loudly instead of silently truncating. Defaults to 1,000. */
|
|
38
|
+
listLimit?: number;
|
|
39
|
+
/** @internal — for testing. Override the spawnSync used by the adapter. */
|
|
40
|
+
spawn?: typeof spawnSync;
|
|
41
|
+
/** Notify the host that issue-backed task state changed and snapshots should refresh. */
|
|
42
|
+
onTaskChanged?: (event: {
|
|
43
|
+
repo: string;
|
|
44
|
+
id: string;
|
|
45
|
+
status?: string;
|
|
46
|
+
reason: "github-issue-updated";
|
|
47
|
+
}) => void;
|
|
48
|
+
/** Optional GitHub Projects (v2) status-field sync mapped from Rig task status. */
|
|
49
|
+
projects?: GitHubProjectsOptions;
|
|
50
|
+
/** Opt into GitHub-native issue dependency reads; body parsing remains the fallback. */
|
|
51
|
+
useNativeDependencies?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface GitHubIssueCreateInput {
|
|
54
|
+
title: string;
|
|
55
|
+
body?: string;
|
|
56
|
+
labels?: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
export interface GitHubIssuesTaskSource extends RegisteredTaskSource {
|
|
59
|
+
addLabels(id: string, labels: readonly string[]): Promise<void>;
|
|
60
|
+
removeLabels(id: string, labels: readonly string[]): Promise<void>;
|
|
61
|
+
createIssue(input: GitHubIssueCreateInput): Promise<TaskRecord>;
|
|
62
|
+
getIssueBody(id: string): Promise<string | undefined>;
|
|
63
|
+
}
|
|
64
|
+
export declare function createEnvGitHubCredentialProvider(): GitHubCredentialProvider;
|
|
65
|
+
export declare function createStateGitHubCredentialProvider(options?: {
|
|
66
|
+
stateFile?: string;
|
|
67
|
+
stateDir?: string;
|
|
68
|
+
}): GitHubCredentialProvider;
|
|
69
|
+
export declare const RIG_STATUS_COMMENT_MARKER = "<!-- rig:status-comment -->";
|
|
70
|
+
export declare const RIG_METADATA_START = "<!-- rig:metadata:start -->";
|
|
71
|
+
export declare const RIG_METADATA_END = "<!-- rig:metadata:end -->";
|
|
72
|
+
export declare function updateRigOwnedMetadataBlock(body: string, metadata: Record<string, unknown>): string;
|
|
73
|
+
export declare function buildRigStickyStatusComment(input: {
|
|
74
|
+
status: "running" | "prOpen" | "ciFixing" | "done" | "needsAttention" | string;
|
|
75
|
+
summary: string;
|
|
76
|
+
runId?: string;
|
|
77
|
+
prUrl?: string;
|
|
78
|
+
details?: readonly string[];
|
|
79
|
+
}): string;
|
|
80
|
+
export declare function createGitHubIssuesTaskSource(opts: GitHubIssuesOptions): GitHubIssuesTaskSource;
|