@anarchitects/governance-cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -0
- package/dist/agov.d.ts +71 -0
- package/dist/agov.d.ts.map +1 -0
- package/dist/bin/agov.d.ts +3 -0
- package/dist/bin/agov.d.ts.map +1 -0
- package/dist/bin/agov.js +792 -0
- package/dist/check-_APXAvpi.js +1568 -0
- package/dist/check.d.ts +21 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/internal/health-engine/calculate-health.d.ts +9 -0
- package/dist/internal/health-engine/calculate-health.d.ts.map +1 -0
- package/dist/internal/manual-workspace/capability.d.ts +10 -0
- package/dist/internal/manual-workspace/capability.d.ts.map +1 -0
- package/dist/internal/manual-workspace/load-workspace.d.ts +49 -0
- package/dist/internal/manual-workspace/load-workspace.d.ts.map +1 -0
- package/dist/internal/metric-engine/aggregate-signals.d.ts +18 -0
- package/dist/internal/metric-engine/aggregate-signals.d.ts.map +1 -0
- package/dist/internal/metric-engine/calculate-metrics.d.ts +7 -0
- package/dist/internal/metric-engine/calculate-metrics.d.ts.map +1 -0
- package/dist/internal/policy-engine/evaluate-policies.d.ts +3 -0
- package/dist/internal/policy-engine/evaluate-policies.d.ts.map +1 -0
- package/dist/internal/profile/load-standalone-profile.d.ts +24 -0
- package/dist/internal/profile/load-standalone-profile.d.ts.map +1 -0
- package/dist/internal/reporting/render-cli.d.ts +3 -0
- package/dist/internal/reporting/render-cli.d.ts.map +1 -0
- package/dist/internal/reporting/render-json.d.ts +3 -0
- package/dist/internal/reporting/render-json.d.ts.map +1 -0
- package/dist/internal/signal-engine/builders.d.ts +41 -0
- package/dist/internal/signal-engine/builders.d.ts.map +1 -0
- package/dist/internal/signal-engine/index.d.ts +3 -0
- package/dist/internal/signal-engine/index.d.ts.map +1 -0
- package/dist/internal/signal-engine/types.d.ts +2 -0
- package/dist/internal/signal-engine/types.d.ts.map +1 -0
- package/dist/render-report.d.ts +5 -0
- package/dist/render-report.d.ts.map +1 -0
- package/package.json +60 -0
package/dist/bin/agov.js
ADDED
|
@@ -0,0 +1,792 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { writeFileSync as H, readFileSync as S, existsSync as _, statSync as L } from "node:fs";
|
|
3
|
+
import f from "node:path";
|
|
4
|
+
import { fileURLToPath as O } from "node:url";
|
|
5
|
+
import { r as N, G as E, a as b, S as U, b as J } from "../check-_APXAvpi.js";
|
|
6
|
+
const M = 10;
|
|
7
|
+
function F(e) {
|
|
8
|
+
const o = [];
|
|
9
|
+
o.push(`Nx Governance - ${e.profile}`), o.push(""), o.push(
|
|
10
|
+
`Health Score: ${e.health.score} (${B(
|
|
11
|
+
e.health.status
|
|
12
|
+
)}, ${e.health.grade})`
|
|
13
|
+
), o.push(`Projects: ${e.workspace.projects.length}`), o.push(`Dependencies: ${e.workspace.dependencies.length}`), o.push(`Violations: ${e.violations.length}`), o.push(""), o.push("Signal Sources:");
|
|
14
|
+
for (const t of e.signalBreakdown.bySource)
|
|
15
|
+
o.push(`- ${t.source}: ${t.count}`);
|
|
16
|
+
o.push(""), o.push("Signal Types:");
|
|
17
|
+
for (const t of e.signalBreakdown.byType)
|
|
18
|
+
o.push(`- ${t.type}: ${t.count}`);
|
|
19
|
+
o.push(""), o.push("Signal Severity:");
|
|
20
|
+
for (const t of e.signalBreakdown.bySeverity)
|
|
21
|
+
o.push(`- ${t.severity}: ${t.count}`);
|
|
22
|
+
if (e.warnings.length > 0) {
|
|
23
|
+
o.push(""), o.push("Warnings:");
|
|
24
|
+
for (const t of e.warnings)
|
|
25
|
+
o.push(`- ${t}`);
|
|
26
|
+
}
|
|
27
|
+
if (o.push(""), o.push("Exceptions:"), o.push(`- declared: ${e.exceptions.summary.declaredCount}`), o.push(`- matched: ${e.exceptions.summary.matchedCount}`), o.push(`- unused: ${e.exceptions.summary.unusedExceptionCount}`), o.push(`- active: ${e.exceptions.summary.activeExceptionCount}`), o.push(`- stale: ${e.exceptions.summary.staleExceptionCount}`), o.push(
|
|
28
|
+
`- expired: ${e.exceptions.summary.expiredExceptionCount}`
|
|
29
|
+
), o.push(
|
|
30
|
+
`- suppressed policy findings: ${e.exceptions.summary.suppressedPolicyViolationCount}`
|
|
31
|
+
), o.push(
|
|
32
|
+
`- suppressed conformance findings: ${e.exceptions.summary.suppressedConformanceFindingCount}`
|
|
33
|
+
), o.push(
|
|
34
|
+
`- reactivated policy findings: ${e.exceptions.summary.reactivatedPolicyViolationCount}`
|
|
35
|
+
), o.push(
|
|
36
|
+
`- reactivated conformance findings: ${e.exceptions.summary.reactivatedConformanceFindingCount}`
|
|
37
|
+
), e.exceptions.suppressedFindings.length > 0) {
|
|
38
|
+
o.push("Suppressed Findings:");
|
|
39
|
+
for (const t of e.exceptions.suppressedFindings) {
|
|
40
|
+
const r = t.ruleId ? ` :: ${t.ruleId}` : "", n = [
|
|
41
|
+
t.projectId,
|
|
42
|
+
t.targetProjectId,
|
|
43
|
+
t.relatedProjectIds.length > 0 ? `related=${t.relatedProjectIds.join(",")}` : void 0
|
|
44
|
+
].filter((s) => !!s).join(" -> "), a = n ? ` :: scope=${n}` : "";
|
|
45
|
+
o.push(
|
|
46
|
+
`- ${t.exceptionId} :: ${t.status} :: ${t.source}/${t.kind} :: [${t.severity}]${r}${a} :: ${t.message}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (e.exceptions.reactivatedFindings.length > 0) {
|
|
51
|
+
o.push("Reactivated Findings:");
|
|
52
|
+
for (const t of e.exceptions.reactivatedFindings) {
|
|
53
|
+
const r = t.ruleId ? ` :: ${t.ruleId}` : "", n = [
|
|
54
|
+
t.projectId,
|
|
55
|
+
t.targetProjectId,
|
|
56
|
+
t.relatedProjectIds.length > 0 ? `related=${t.relatedProjectIds.join(",")}` : void 0
|
|
57
|
+
].filter((s) => !!s).join(" -> "), a = n ? ` :: scope=${n}` : "";
|
|
58
|
+
o.push(
|
|
59
|
+
`- ${t.exceptionId} :: ${t.status} :: ${t.source}/${t.kind} :: [${t.severity}]${r}${a} :: ${t.message}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
o.push(""), o.push("Metrics:");
|
|
64
|
+
for (const t of e.measurements)
|
|
65
|
+
o.push(`- ${t.name}: ${t.score}/100`);
|
|
66
|
+
if (e.metricBreakdown.families.length > 0) {
|
|
67
|
+
o.push(""), o.push("Metric Families:");
|
|
68
|
+
for (const t of e.metricBreakdown.families)
|
|
69
|
+
o.push(`- ${t.family}: ${t.score}/100`), o.push(
|
|
70
|
+
` measurements: ${t.measurements.map((r) => `${r.name} (${r.score})`).join(", ")}`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (e.health.metricHotspots.length > 0) {
|
|
74
|
+
o.push(""), o.push("Metric Hotspots:");
|
|
75
|
+
for (const t of e.health.metricHotspots)
|
|
76
|
+
o.push(`- ${t.name}: ${t.score}/100`);
|
|
77
|
+
}
|
|
78
|
+
if (e.health.projectHotspots.length > 0) {
|
|
79
|
+
o.push(""), o.push("Project Hotspots:");
|
|
80
|
+
for (const t of e.health.projectHotspots)
|
|
81
|
+
o.push(
|
|
82
|
+
`- ${t.project}: ${t.count} :: types=${t.dominantIssueTypes.join(",")}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (o.push(""), o.push("Explainability:"), o.push(`- summary: ${e.health.explainability.summary}`), o.push(
|
|
86
|
+
`- status reason: ${e.health.explainability.statusReason}`
|
|
87
|
+
), e.health.explainability.weakestMetrics.length > 0 && o.push(
|
|
88
|
+
`- weakest metrics: ${e.health.explainability.weakestMetrics.map((t) => `${t.name} (${t.score})`).join(", ")}`
|
|
89
|
+
), e.health.explainability.dominantIssues.length > 0 && o.push(
|
|
90
|
+
`- dominant issues: ${e.health.explainability.dominantIssues.map((t) => `${t.type} x${t.count}`).join(", ")}`
|
|
91
|
+
), e.topIssues.length > 0) {
|
|
92
|
+
o.push(""), o.push("Top Issues:");
|
|
93
|
+
for (const t of e.topIssues.slice(0, M)) {
|
|
94
|
+
const r = t.ruleId ? ` :: ${t.ruleId}` : "", n = t.projects.length > 0 ? ` :: projects=${t.projects.join(",")}` : "";
|
|
95
|
+
o.push(
|
|
96
|
+
`- [${t.severity}] ${t.type} (${t.source}) x${t.count}${r}${n} :: ${t.message}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (e.recommendations.length > 0) {
|
|
101
|
+
o.push(""), o.push("Recommendations:");
|
|
102
|
+
for (const t of e.recommendations)
|
|
103
|
+
o.push(
|
|
104
|
+
`- (${t.priority}) ${t.title} - ${t.reason}`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return o.join(`
|
|
108
|
+
`);
|
|
109
|
+
}
|
|
110
|
+
function B(e) {
|
|
111
|
+
return `${e.charAt(0).toUpperCase()}${e.slice(1)}`;
|
|
112
|
+
}
|
|
113
|
+
function K(e) {
|
|
114
|
+
return JSON.stringify(e, null, 2);
|
|
115
|
+
}
|
|
116
|
+
function z(e, o) {
|
|
117
|
+
switch (o) {
|
|
118
|
+
case "json":
|
|
119
|
+
return T(e);
|
|
120
|
+
case "markdown":
|
|
121
|
+
return D(e);
|
|
122
|
+
case "table":
|
|
123
|
+
case "text":
|
|
124
|
+
return Q(e);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function T(e) {
|
|
128
|
+
return JSON.stringify(
|
|
129
|
+
{
|
|
130
|
+
command: e.command,
|
|
131
|
+
success: e.success,
|
|
132
|
+
assessment: JSON.parse(K(e.assessment))
|
|
133
|
+
},
|
|
134
|
+
null,
|
|
135
|
+
2
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
function Q(e) {
|
|
139
|
+
const o = [], { assessment: t } = e, r = F(t).split(`
|
|
140
|
+
`);
|
|
141
|
+
return r[0]?.startsWith("Nx Governance - ") && (r[0] = `Governance Check - ${t.profile}`), o.push("agov check"), o.push(""), o.push(
|
|
142
|
+
...q(
|
|
143
|
+
["Field", "Value"],
|
|
144
|
+
[
|
|
145
|
+
["success", e.success ? "true" : "false"],
|
|
146
|
+
["workspace", t.workspace.name],
|
|
147
|
+
["profile", t.profile]
|
|
148
|
+
]
|
|
149
|
+
)
|
|
150
|
+
), o.push(""), o.push(...r), o.join(`
|
|
151
|
+
`);
|
|
152
|
+
}
|
|
153
|
+
function D(e) {
|
|
154
|
+
const { assessment: o } = e, t = [], r = F(o).split(`
|
|
155
|
+
`);
|
|
156
|
+
r[0]?.startsWith("Nx Governance - ") && (r[0] = `Governance Check - ${o.profile}`), t.push("# agov check"), t.push(""), t.push("| Field | Value |"), t.push("| --- | --- |"), t.push(`| success | ${e.success ? "true" : "false"} |`), t.push(
|
|
157
|
+
`| workspace | ${R(o.workspace.name)} |`
|
|
158
|
+
), t.push(`| profile | ${R(o.profile)} |`), t.push("");
|
|
159
|
+
for (const n of r) {
|
|
160
|
+
if (n.length === 0) {
|
|
161
|
+
t.push("");
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!n.startsWith("- ")) {
|
|
165
|
+
t.push(`## ${n}`);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
t.push(n);
|
|
169
|
+
}
|
|
170
|
+
return t.join(`
|
|
171
|
+
`);
|
|
172
|
+
}
|
|
173
|
+
function q(e, o) {
|
|
174
|
+
const t = Math.max(
|
|
175
|
+
e[0].length,
|
|
176
|
+
...o.map((n) => n[0]?.length ?? 0)
|
|
177
|
+
), r = Math.max(
|
|
178
|
+
e[1].length,
|
|
179
|
+
...o.map((n) => n[1]?.length ?? 0)
|
|
180
|
+
);
|
|
181
|
+
return [
|
|
182
|
+
`${k(e[0], t)} ${k(e[1], r)}`,
|
|
183
|
+
`${"-".repeat(t)} ${"-".repeat(r)}`,
|
|
184
|
+
...o.map(
|
|
185
|
+
(n) => `${k(n[0] ?? "", t)} ${k(
|
|
186
|
+
n[1] ?? "",
|
|
187
|
+
r
|
|
188
|
+
)}`
|
|
189
|
+
)
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
function k(e, o) {
|
|
193
|
+
return e.padEnd(o, " ");
|
|
194
|
+
}
|
|
195
|
+
function R(e) {
|
|
196
|
+
return e.replaceAll("|", "\\|");
|
|
197
|
+
}
|
|
198
|
+
const ee = ["agov.config.json", "governance.config.json"], oe = [
|
|
199
|
+
"tools/governance/profiles/default.json",
|
|
200
|
+
"tools/governance/profile.json",
|
|
201
|
+
"governance.profile.json",
|
|
202
|
+
"agov.profile.json"
|
|
203
|
+
], te = [
|
|
204
|
+
"governance.workspace.json",
|
|
205
|
+
"agov.workspace.json",
|
|
206
|
+
"tools/governance/workspace.json"
|
|
207
|
+
], w = 0, ne = 1, W = 2, y = 3, re = {
|
|
208
|
+
runAgovCheck: N
|
|
209
|
+
};
|
|
210
|
+
class u extends Error {
|
|
211
|
+
constructor(o, t) {
|
|
212
|
+
super(o), this.code = t, this.name = "AgovCliUsageError";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
class V extends Error {
|
|
216
|
+
constructor(o, t, r) {
|
|
217
|
+
super(o), this.code = t, this.filePath = r, this.name = "AgovCliOutputError";
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
class I extends Error {
|
|
221
|
+
constructor(o, t, r) {
|
|
222
|
+
super(o), this.code = t, this.details = r, this.name = "AgovCliRuntimeError";
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async function ae(e, o = Ae(), t = re, r = ye()) {
|
|
226
|
+
try {
|
|
227
|
+
const n = ie(e);
|
|
228
|
+
if (n.kind === "help")
|
|
229
|
+
return o.stdout(ke()), w;
|
|
230
|
+
if (n.kind === "version")
|
|
231
|
+
return o.stdout(r.packageVersion()), w;
|
|
232
|
+
if (n.options.showHelp)
|
|
233
|
+
return o.stdout(we()), w;
|
|
234
|
+
const a = se(n.options, r), s = await pe(
|
|
235
|
+
a,
|
|
236
|
+
r
|
|
237
|
+
), c = await Promise.resolve(t.runAgovCheck(s)), p = z(c, a.format);
|
|
238
|
+
return a.outputPath ? je(a.outputPath, p) : o.stdout(p), c.success ? w : ne;
|
|
239
|
+
} catch (n) {
|
|
240
|
+
return n instanceof u ? (o.stderr(
|
|
241
|
+
v({
|
|
242
|
+
code: n.code,
|
|
243
|
+
message: n.message
|
|
244
|
+
})
|
|
245
|
+
), W) : n instanceof V ? (o.stderr(
|
|
246
|
+
v({
|
|
247
|
+
code: n.code,
|
|
248
|
+
message: n.message,
|
|
249
|
+
details: {
|
|
250
|
+
filePath: n.filePath
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
), W) : n instanceof I ? (o.stderr(
|
|
254
|
+
v({
|
|
255
|
+
code: n.code,
|
|
256
|
+
message: n.message,
|
|
257
|
+
...n.details ? { details: n.details } : {}
|
|
258
|
+
})
|
|
259
|
+
), y) : n instanceof E || n instanceof b || n instanceof U || n instanceof J ? (o.stderr(Ce(n)), y) : (o.stderr(
|
|
260
|
+
v({
|
|
261
|
+
code: "agov.cli.unhandled_error",
|
|
262
|
+
message: n instanceof Error ? n.message : "Unknown agov CLI error."
|
|
263
|
+
})
|
|
264
|
+
), y);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function ie(e) {
|
|
268
|
+
if (e.length === 0)
|
|
269
|
+
return { kind: "help" };
|
|
270
|
+
const [o, ...t] = e;
|
|
271
|
+
if (o === "--help" || o === "-h" || o === "help")
|
|
272
|
+
return { kind: "help" };
|
|
273
|
+
if (o === "--version" || o === "-v" || o === "version")
|
|
274
|
+
return { kind: "version" };
|
|
275
|
+
if (o !== "check")
|
|
276
|
+
throw new u(
|
|
277
|
+
`Unsupported agov command "${o}". Supported commands are "check", "--help", and "--version".`,
|
|
278
|
+
"agov.cli.unknown_command"
|
|
279
|
+
);
|
|
280
|
+
return {
|
|
281
|
+
kind: "check",
|
|
282
|
+
options: ce(t)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function ce(e) {
|
|
286
|
+
let o, t, r, n, a, s, c, p = !1;
|
|
287
|
+
for (let i = 0; i < e.length; i += 1) {
|
|
288
|
+
const d = e[i];
|
|
289
|
+
if (d === "--help" || d === "-h") {
|
|
290
|
+
p = !0;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (d === "--config") {
|
|
294
|
+
o = g(e, i, "--config"), i += 1;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (d === "--profile") {
|
|
298
|
+
t = g(e, i, "--profile"), i += 1;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (d === "--workspace") {
|
|
302
|
+
r = g(e, i, "--workspace"), i += 1;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (d === "--adapter") {
|
|
306
|
+
n = g(e, i, "--adapter"), i += 1;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (d === "--root") {
|
|
310
|
+
a = g(e, i, "--root"), i += 1;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (d === "--format") {
|
|
314
|
+
const l = g(e, i, "--format");
|
|
315
|
+
if (i += 1, l !== "text" && l !== "json" && l !== "markdown" && l !== "table")
|
|
316
|
+
throw new u(
|
|
317
|
+
'Unsupported agov check format. Supported formats are "table", "markdown", "text", and "json".',
|
|
318
|
+
"agov.cli.unsupported_format"
|
|
319
|
+
);
|
|
320
|
+
s = l;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (d === "--output") {
|
|
324
|
+
c = g(e, i, "--output"), i += 1;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
throw new u(
|
|
328
|
+
`Unknown agov option "${d}".`,
|
|
329
|
+
"agov.cli.unknown_option"
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
command: "check",
|
|
334
|
+
configPath: o,
|
|
335
|
+
profilePath: t,
|
|
336
|
+
workspacePath: r,
|
|
337
|
+
adapterPackage: n,
|
|
338
|
+
rootPath: a,
|
|
339
|
+
format: s,
|
|
340
|
+
outputPath: c,
|
|
341
|
+
showHelp: p
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function g(e, o, t) {
|
|
345
|
+
const r = e[o + 1];
|
|
346
|
+
if (!r || r.startsWith("--"))
|
|
347
|
+
throw new u(
|
|
348
|
+
`Missing required value for "${t}".`,
|
|
349
|
+
"agov.cli.missing_option_value"
|
|
350
|
+
);
|
|
351
|
+
return r;
|
|
352
|
+
}
|
|
353
|
+
function se(e, o) {
|
|
354
|
+
const t = f.resolve(o.cwd()), r = e.rootPath ? f.resolve(t, e.rootPath) : void 0, n = he(
|
|
355
|
+
t,
|
|
356
|
+
r,
|
|
357
|
+
e.configPath
|
|
358
|
+
), a = n ? ge(n) : {}, s = n ? f.dirname(n) : t;
|
|
359
|
+
if ((a.adapter || A(a.adapters).length > 0) && a.workspace && !e.adapterPackage && !e.workspacePath)
|
|
360
|
+
throw new u(
|
|
361
|
+
"Config file cannot define both adapter-mode and workspace-mode inputs for agov check. Pass one mode only, or override explicitly with CLI flags.",
|
|
362
|
+
"agov.cli.invalid_config"
|
|
363
|
+
);
|
|
364
|
+
if (e.workspacePath && e.adapterPackage)
|
|
365
|
+
throw new u(
|
|
366
|
+
'agov check does not allow explicit "--workspace" and "--adapter" together. Use canonical workspace mode or adapter mode, not both.',
|
|
367
|
+
"agov.cli.ambiguous_workspace_and_adapter"
|
|
368
|
+
);
|
|
369
|
+
const c = r ?? $(a.root, s) ?? t, p = j(e.workspacePath, t), i = $(
|
|
370
|
+
a.workspace,
|
|
371
|
+
s
|
|
372
|
+
), d = P(
|
|
373
|
+
c,
|
|
374
|
+
te
|
|
375
|
+
), l = p ?? i ?? d, m = j(e.profilePath, t) ?? $(a.profile, s) ?? P(c, oe), x = e.adapterPackage ?? X(a.adapter), G = Ie(c, a), C = ve(e.format, a.format), h = j(e.outputPath, t);
|
|
376
|
+
if (!m)
|
|
377
|
+
throw new u(
|
|
378
|
+
'Could not resolve a governance profile. Pass "--profile <path>", set "profile" in agov.config.json or governance.config.json, or add a conventional profile file such as "governance.profile.json".',
|
|
379
|
+
"agov.cli.missing_profile"
|
|
380
|
+
);
|
|
381
|
+
if (p || i)
|
|
382
|
+
return {
|
|
383
|
+
command: "check",
|
|
384
|
+
rootPath: c,
|
|
385
|
+
profilePath: m,
|
|
386
|
+
workspacePath: l,
|
|
387
|
+
format: C,
|
|
388
|
+
...h ? { outputPath: h } : {},
|
|
389
|
+
...n ? { configPath: n } : {},
|
|
390
|
+
mode: "workspace"
|
|
391
|
+
};
|
|
392
|
+
if (x)
|
|
393
|
+
return {
|
|
394
|
+
command: "check",
|
|
395
|
+
rootPath: c,
|
|
396
|
+
profilePath: m,
|
|
397
|
+
adapterPackage: x,
|
|
398
|
+
format: C,
|
|
399
|
+
...h ? { outputPath: h } : {},
|
|
400
|
+
...n ? { configPath: n } : {},
|
|
401
|
+
mode: "adapter"
|
|
402
|
+
};
|
|
403
|
+
if (G.length > 0)
|
|
404
|
+
return {
|
|
405
|
+
command: "check",
|
|
406
|
+
rootPath: c,
|
|
407
|
+
profilePath: m,
|
|
408
|
+
adapterCandidates: G,
|
|
409
|
+
format: C,
|
|
410
|
+
...h ? { outputPath: h } : {},
|
|
411
|
+
...n ? { configPath: n } : {},
|
|
412
|
+
mode: "adapter-discovery"
|
|
413
|
+
};
|
|
414
|
+
if (l)
|
|
415
|
+
return {
|
|
416
|
+
command: "check",
|
|
417
|
+
rootPath: c,
|
|
418
|
+
profilePath: m,
|
|
419
|
+
workspacePath: l,
|
|
420
|
+
format: C,
|
|
421
|
+
...h ? { outputPath: h } : {},
|
|
422
|
+
...n ? { configPath: n } : {},
|
|
423
|
+
mode: "workspace"
|
|
424
|
+
};
|
|
425
|
+
throw new u(
|
|
426
|
+
'Could not resolve Governance workspace input. Pass "--workspace <path>" for canonical workspace mode, pass "--adapter <package> --root <path>" for explicit adapter mode, or configure generic adapter candidates.',
|
|
427
|
+
"agov.cli.missing_workspace_or_adapter"
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
async function pe(e, o) {
|
|
431
|
+
if (e.mode === "workspace") {
|
|
432
|
+
if (!e.workspacePath)
|
|
433
|
+
throw new I(
|
|
434
|
+
"Resolved workspace mode without a workspace path.",
|
|
435
|
+
"agov.cli.unhandled_error"
|
|
436
|
+
);
|
|
437
|
+
return {
|
|
438
|
+
profilePath: e.profilePath,
|
|
439
|
+
workspacePath: e.workspacePath
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (!e.adapterPackage) {
|
|
443
|
+
if (e.mode !== "adapter-discovery" || !e.adapterCandidates)
|
|
444
|
+
throw new I(
|
|
445
|
+
"Resolved adapter mode without an adapter package.",
|
|
446
|
+
"agov.cli.unhandled_error"
|
|
447
|
+
);
|
|
448
|
+
const r = await de(
|
|
449
|
+
e.adapterCandidates,
|
|
450
|
+
e.rootPath,
|
|
451
|
+
o
|
|
452
|
+
);
|
|
453
|
+
return {
|
|
454
|
+
profilePath: e.profilePath,
|
|
455
|
+
workspaceAdapter: r.adapter,
|
|
456
|
+
workspaceAdapterInput: e.rootPath
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const t = await ue(
|
|
460
|
+
e.adapterPackage,
|
|
461
|
+
e.rootPath,
|
|
462
|
+
o
|
|
463
|
+
);
|
|
464
|
+
return {
|
|
465
|
+
profilePath: e.profilePath,
|
|
466
|
+
workspaceAdapter: t,
|
|
467
|
+
workspaceAdapterInput: e.rootPath
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
async function ue(e, o, t) {
|
|
471
|
+
let r;
|
|
472
|
+
try {
|
|
473
|
+
r = await t.moduleLoader(e);
|
|
474
|
+
} catch {
|
|
475
|
+
throw new I(
|
|
476
|
+
le(e),
|
|
477
|
+
"agov.cli.adapter_not_found",
|
|
478
|
+
{
|
|
479
|
+
adapter: e,
|
|
480
|
+
rootPath: o
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
const n = Y(r);
|
|
485
|
+
if (!n)
|
|
486
|
+
throw new I(
|
|
487
|
+
`Package "${e}" was loaded, but it does not expose a compatible Governance workspace adapter.`,
|
|
488
|
+
"agov.cli.adapter_contract_mismatch",
|
|
489
|
+
{
|
|
490
|
+
adapter: e,
|
|
491
|
+
rootPath: o
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
return n;
|
|
495
|
+
}
|
|
496
|
+
async function de(e, o, t) {
|
|
497
|
+
const r = [];
|
|
498
|
+
let n;
|
|
499
|
+
for (const a of e) {
|
|
500
|
+
let s;
|
|
501
|
+
try {
|
|
502
|
+
s = await t.moduleLoader(a);
|
|
503
|
+
} catch {
|
|
504
|
+
r.push({ packageName: a, status: "load-failed" });
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
const c = Y(s);
|
|
508
|
+
if (!c) {
|
|
509
|
+
r.push({ packageName: a, status: "contract-mismatch" });
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
if (typeof c.probe != "function") {
|
|
513
|
+
r.push({ packageName: a, status: "missing-probe" });
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
const p = c.probe(o);
|
|
517
|
+
if (r.push({
|
|
518
|
+
packageName: a,
|
|
519
|
+
status: p.supported ? "supported" : "unsupported",
|
|
520
|
+
confidence: p.confidence ?? "none",
|
|
521
|
+
reasons: p.reasons ?? []
|
|
522
|
+
}), !p.supported)
|
|
523
|
+
continue;
|
|
524
|
+
const i = fe(p.confidence);
|
|
525
|
+
(!n || i > n.rank) && (n = {
|
|
526
|
+
adapter: c,
|
|
527
|
+
packageName: a,
|
|
528
|
+
probe: p,
|
|
529
|
+
rank: i
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
if (!n)
|
|
533
|
+
throw new I(
|
|
534
|
+
"Could not find a supported Governance adapter from the discovered candidate packages.",
|
|
535
|
+
"agov.cli.no_supported_adapter",
|
|
536
|
+
{
|
|
537
|
+
rootPath: o,
|
|
538
|
+
attemptedPackages: e,
|
|
539
|
+
attempts: r
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
return n;
|
|
543
|
+
}
|
|
544
|
+
function Y(e) {
|
|
545
|
+
const o = typeof e == "object" && e !== null ? e : {};
|
|
546
|
+
for (const r of [
|
|
547
|
+
o.default,
|
|
548
|
+
o.governanceWorkspaceAdapter,
|
|
549
|
+
o.adapter
|
|
550
|
+
])
|
|
551
|
+
if (Z(r))
|
|
552
|
+
return r;
|
|
553
|
+
const t = o.createGovernanceWorkspaceAdapter;
|
|
554
|
+
if (typeof t == "function") {
|
|
555
|
+
const r = t();
|
|
556
|
+
if (Z(r))
|
|
557
|
+
return r;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function Z(e) {
|
|
561
|
+
return typeof e == "object" && e !== null && typeof e.id == "string" && typeof e.loadWorkspace == "function";
|
|
562
|
+
}
|
|
563
|
+
function le(e) {
|
|
564
|
+
const o = [`Could not load Governance adapter package "${e}".`];
|
|
565
|
+
return o.push(
|
|
566
|
+
`Install "${e}" in the consuming workspace to use adapter mode.`
|
|
567
|
+
), o.push(
|
|
568
|
+
`You can also pass "--adapter ${e}" explicitly, or use "--workspace <path>" with a canonical Governance workspace document.`
|
|
569
|
+
), o.join(" ");
|
|
570
|
+
}
|
|
571
|
+
function fe(e) {
|
|
572
|
+
switch (e) {
|
|
573
|
+
case "high":
|
|
574
|
+
return 3;
|
|
575
|
+
case "medium":
|
|
576
|
+
return 2;
|
|
577
|
+
case "low":
|
|
578
|
+
return 1;
|
|
579
|
+
default:
|
|
580
|
+
return 0;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function he(e, o, t) {
|
|
584
|
+
if (t)
|
|
585
|
+
return f.resolve(e, t);
|
|
586
|
+
const r = o ? [o, e] : [e];
|
|
587
|
+
for (const n of r) {
|
|
588
|
+
const a = P(
|
|
589
|
+
n,
|
|
590
|
+
ee
|
|
591
|
+
);
|
|
592
|
+
if (a)
|
|
593
|
+
return a;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function ge(e) {
|
|
597
|
+
let o;
|
|
598
|
+
try {
|
|
599
|
+
o = S(e, "utf8");
|
|
600
|
+
} catch {
|
|
601
|
+
throw new u(
|
|
602
|
+
`Failed to read agov config file "${e}".`,
|
|
603
|
+
"agov.cli.invalid_config"
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
let t;
|
|
607
|
+
try {
|
|
608
|
+
t = JSON.parse(o);
|
|
609
|
+
} catch {
|
|
610
|
+
throw new u(
|
|
611
|
+
`Failed to parse agov config file "${e}" as JSON.`,
|
|
612
|
+
"agov.cli.invalid_json"
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
if (typeof t != "object" || t === null || Array.isArray(t))
|
|
616
|
+
throw new u(
|
|
617
|
+
`agov config file "${e}" must contain a JSON object.`,
|
|
618
|
+
"agov.cli.invalid_config"
|
|
619
|
+
);
|
|
620
|
+
return t;
|
|
621
|
+
}
|
|
622
|
+
function ve(e, o) {
|
|
623
|
+
const t = e ?? X(o) ?? "text";
|
|
624
|
+
if (t !== "text" && t !== "json" && t !== "markdown" && t !== "table")
|
|
625
|
+
throw new u(
|
|
626
|
+
'Unsupported agov check format. Supported formats are "table", "markdown", "text", and "json".',
|
|
627
|
+
"agov.cli.unsupported_format"
|
|
628
|
+
);
|
|
629
|
+
return t;
|
|
630
|
+
}
|
|
631
|
+
function j(e, o) {
|
|
632
|
+
if (e)
|
|
633
|
+
return f.resolve(o, e);
|
|
634
|
+
}
|
|
635
|
+
function $(e, o) {
|
|
636
|
+
if (!(!e || e.trim().length === 0))
|
|
637
|
+
return f.resolve(o, e);
|
|
638
|
+
}
|
|
639
|
+
function X(e) {
|
|
640
|
+
return typeof e == "string" && e.trim().length > 0 ? e.trim() : void 0;
|
|
641
|
+
}
|
|
642
|
+
function A(e) {
|
|
643
|
+
return Array.isArray(e) ? e.filter((o) => typeof o == "string").map((o) => o.trim()).filter((o) => o.length > 0) : [];
|
|
644
|
+
}
|
|
645
|
+
function P(e, o) {
|
|
646
|
+
for (const t of o) {
|
|
647
|
+
const r = f.resolve(e, t);
|
|
648
|
+
if (_(r) && L(r).isFile())
|
|
649
|
+
return r;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function Ie(e, o) {
|
|
653
|
+
return [
|
|
654
|
+
.../* @__PURE__ */ new Set([
|
|
655
|
+
...A(o.adapters),
|
|
656
|
+
...me(e)
|
|
657
|
+
])
|
|
658
|
+
];
|
|
659
|
+
}
|
|
660
|
+
function me(e) {
|
|
661
|
+
const o = f.join(e, "package.json");
|
|
662
|
+
if (!_(o) || !L(o).isFile())
|
|
663
|
+
return [];
|
|
664
|
+
try {
|
|
665
|
+
const t = JSON.parse(S(o, "utf8"));
|
|
666
|
+
if (typeof t != "object" || t === null || Array.isArray(t))
|
|
667
|
+
return [];
|
|
668
|
+
const r = t, n = typeof r.agov == "object" && r.agov !== null && !Array.isArray(r.agov) ? r.agov : void 0, a = typeof r.governance == "object" && r.governance !== null && !Array.isArray(r.governance) ? r.governance : void 0;
|
|
669
|
+
return [
|
|
670
|
+
...A(n?.adapters),
|
|
671
|
+
...A(a?.adapters)
|
|
672
|
+
];
|
|
673
|
+
} catch {
|
|
674
|
+
return [];
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function Ce(e) {
|
|
678
|
+
return e instanceof b || e instanceof J ? v({
|
|
679
|
+
code: e instanceof b ? "agov.cli.invalid_workspace" : "agov.cli.invalid_profile",
|
|
680
|
+
message: e.message,
|
|
681
|
+
details: {
|
|
682
|
+
filePath: e.filePath,
|
|
683
|
+
issues: e.issues
|
|
684
|
+
}
|
|
685
|
+
}) : v({
|
|
686
|
+
code: e instanceof E ? "agov.cli.workspace_load_failed" : "agov.cli.profile_load_failed",
|
|
687
|
+
message: e.message,
|
|
688
|
+
details: {
|
|
689
|
+
filePath: e.filePath,
|
|
690
|
+
loaderCode: e.code
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
function v(e) {
|
|
695
|
+
return JSON.stringify(
|
|
696
|
+
{
|
|
697
|
+
error: {
|
|
698
|
+
code: e.code,
|
|
699
|
+
message: e.message,
|
|
700
|
+
...e.details ? { details: e.details } : {}
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
null,
|
|
704
|
+
2
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
function ke() {
|
|
708
|
+
return [
|
|
709
|
+
"agov",
|
|
710
|
+
"",
|
|
711
|
+
"Usage:",
|
|
712
|
+
" agov --help",
|
|
713
|
+
" agov --version",
|
|
714
|
+
" agov check [options]",
|
|
715
|
+
"",
|
|
716
|
+
"Commands:",
|
|
717
|
+
" check Run a Governance check using canonical workspace mode or adapter mode.",
|
|
718
|
+
"",
|
|
719
|
+
'Run "agov check --help" for command-specific options.'
|
|
720
|
+
].join(`
|
|
721
|
+
`);
|
|
722
|
+
}
|
|
723
|
+
function we() {
|
|
724
|
+
return [
|
|
725
|
+
"agov check",
|
|
726
|
+
"",
|
|
727
|
+
"Usage:",
|
|
728
|
+
" agov check --profile <path> --workspace <path> [--format table|markdown|text|json]",
|
|
729
|
+
" agov check --profile <path> --adapter <package> --root <path> [--format table|markdown|text|json]",
|
|
730
|
+
" agov check [--config <path>]",
|
|
731
|
+
"",
|
|
732
|
+
"Resolution order:",
|
|
733
|
+
" explicit CLI flag -> config file -> conventional files -> generic adapter discovery and probe -> error",
|
|
734
|
+
"",
|
|
735
|
+
"Options:",
|
|
736
|
+
" --help Show check command help.",
|
|
737
|
+
" --config <path> Load agov.config.json or governance.config.json explicitly.",
|
|
738
|
+
" --profile <path> Governance profile document.",
|
|
739
|
+
" --workspace <path> Canonical Governance workspace document.",
|
|
740
|
+
" --adapter <package> Dynamically load a concrete adapter package.",
|
|
741
|
+
" --root <path> Adapter input root. Defaults to the current working directory.",
|
|
742
|
+
" --format <value> Output format: table, markdown, text, or json. Defaults to text.",
|
|
743
|
+
" --output <path> Write command output to a file instead of stdout.",
|
|
744
|
+
"",
|
|
745
|
+
"Conventions:",
|
|
746
|
+
" Config: agov.config.json, governance.config.json",
|
|
747
|
+
" Profile: tools/governance/profiles/default.json, tools/governance/profile.json, governance.profile.json, agov.profile.json",
|
|
748
|
+
" Workspace: governance.workspace.json, agov.workspace.json, tools/governance/workspace.json"
|
|
749
|
+
].join(`
|
|
750
|
+
`);
|
|
751
|
+
}
|
|
752
|
+
function Ae() {
|
|
753
|
+
return {
|
|
754
|
+
stdout(e) {
|
|
755
|
+
process.stdout.write(`${e}
|
|
756
|
+
`);
|
|
757
|
+
},
|
|
758
|
+
stderr(e) {
|
|
759
|
+
process.stderr.write(`${e}
|
|
760
|
+
`);
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
function ye() {
|
|
765
|
+
return {
|
|
766
|
+
cwd() {
|
|
767
|
+
return process.cwd();
|
|
768
|
+
},
|
|
769
|
+
async moduleLoader(e) {
|
|
770
|
+
return import(e);
|
|
771
|
+
},
|
|
772
|
+
packageVersion() {
|
|
773
|
+
const e = O(
|
|
774
|
+
new URL("data:application/json;base64,ewogICJuYW1lIjogIkBhbmFyY2hpdGVjdHMvZ292ZXJuYW5jZS1jbGkiLAogICJ2ZXJzaW9uIjogIjAuMC4xIiwKICAiZGVzY3JpcHRpb24iOiAiUGxhdGZvcm0taW5kZXBlbmRlbnQgc3RhbmRhbG9uZSBHb3Zlcm5hbmNlIENMSSB0aGF0IG9yY2hlc3RyYXRlcyBDb21tdW5pdHktb3duZWQgR292ZXJuYW5jZSBDb3JlIGNvbnRyYWN0cyBvdXRzaWRlIE54LiIsCiAgImxpY2Vuc2UiOiAiTUlUIiwKICAidHlwZSI6ICJtb2R1bGUiLAogICJtYWluIjogIi4vZGlzdC9pbmRleC5qcyIsCiAgIm1vZHVsZSI6ICIuL2Rpc3QvaW5kZXguanMiLAogICJ0eXBlcyI6ICIuL2Rpc3QvaW5kZXguZC50cyIsCiAgInJlcG9zaXRvcnkiOiB7CiAgICAidHlwZSI6ICJnaXQiLAogICAgInVybCI6ICJnaXQraHR0cHM6Ly9naXRodWIuY29tL2FuYXJjaGl0ZWN0cy9hbmFyY2hpdGVjdHVyZS1jb21tdW5pdHkuZ2l0IiwKICAgICJkaXJlY3RvcnkiOiAicGFja2FnZXMvZ292ZXJuYW5jZS9jbGkiCiAgfSwKICAiYnVncyI6IHsKICAgICJ1cmwiOiAiaHR0cHM6Ly9naXRodWIuY29tL2FuYXJjaGl0ZWN0cy9hbmFyY2hpdGVjdHVyZS1jb21tdW5pdHkvaXNzdWVzIgogIH0sCiAgImhvbWVwYWdlIjogImh0dHBzOi8vZ2l0aHViLmNvbS9hbmFyY2hpdGVjdHMvYW5hcmNoaXRlY3R1cmUtY29tbXVuaXR5L3RyZWUvbWFpbi9wYWNrYWdlcy9nb3Zlcm5hbmNlL2NsaSNyZWFkbWUiLAogICJrZXl3b3JkcyI6IFsKICAgICJnb3Zlcm5hbmNlIiwKICAgICJjbGkiCiAgXSwKICAiZXhwb3J0cyI6IHsKICAgICIuL3BhY2thZ2UuanNvbiI6ICIuL3BhY2thZ2UuanNvbiIsCiAgICAiLiI6IHsKICAgICAgIkBhbmFyY2hpdGVjdHVyZS1jb21tdW5pdHkvc291cmNlIjogIi4vc3JjL2luZGV4LnRzIiwKICAgICAgInR5cGVzIjogIi4vZGlzdC9pbmRleC5kLnRzIiwKICAgICAgImltcG9ydCI6ICIuL2Rpc3QvaW5kZXguanMiLAogICAgICAiZGVmYXVsdCI6ICIuL2Rpc3QvaW5kZXguanMiCiAgICB9CiAgfSwKICAiYmluIjogewogICAgImFnb3YiOiAiLi9kaXN0L2Jpbi9hZ292LmpzIgogIH0sCiAgImZpbGVzIjogWwogICAgImRpc3QiLAogICAgIiEqKi8qLnRzYnVpbGRpbmZvIgogIF0sCiAgInB1Ymxpc2hDb25maWciOiB7CiAgICAiYWNjZXNzIjogInB1YmxpYyIKICB9LAogICJueCI6IHsKICAgICJuYW1lIjogImdvdmVybmFuY2UtY2xpIiwKICAgICJ0YXJnZXRzIjogewogICAgICAidGVzdCI6IHsKICAgICAgICAiZXhlY3V0b3IiOiAiQG54L3ZpdGVzdDp0ZXN0IiwKICAgICAgICAib3V0cHV0cyI6IFsKICAgICAgICAgICJ7b3B0aW9ucy5yZXBvcnRzRGlyZWN0b3J5fSIKICAgICAgICBdLAogICAgICAgICJvcHRpb25zIjogewogICAgICAgICAgInJlcG9ydHNEaXJlY3RvcnkiOiAiY292ZXJhZ2UvcGFja2FnZXMvZ292ZXJuYW5jZS9jbGkiCiAgICAgICAgfQogICAgICB9CiAgICB9CiAgfSwKICAiZGVwZW5kZW5jaWVzIjogewogICAgIkBhbmFyY2hpdGVjdHMvZ292ZXJuYW5jZS1jb3JlIjogIl4wLjAuMSIsCiAgICAieWFtbCI6ICJeMi44LjEiCiAgfQp9Cg==", import.meta.url)
|
|
775
|
+
);
|
|
776
|
+
return JSON.parse(S(e, "utf8")).version ?? "0.0.0";
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
function je(e, o) {
|
|
781
|
+
const t = f.resolve(e);
|
|
782
|
+
try {
|
|
783
|
+
H(t, o, "utf8");
|
|
784
|
+
} catch {
|
|
785
|
+
throw new V(
|
|
786
|
+
`Failed to write agov report output to "${t}".`,
|
|
787
|
+
"agov.cli.output_write_failed",
|
|
788
|
+
t
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
process.exitCode = await ae(process.argv.slice(2));
|