@cejel/cejel 0.2.1 → 0.3.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/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire as __cejelCreateRequire } from 'node:module';
3
+ const require = __cejelCreateRequire(import.meta.url);
2
4
  import {
3
5
  WitanReportSchema,
4
6
  createWitanAttestation,
@@ -9,15 +11,20 @@ import {
9
11
  runCejelScan,
10
12
  serializeWitanReport,
11
13
  verifyWitanAttestationBinding
12
- } from "./chunk-BR2DO4QJ.js";
14
+ } from "./chunk-XB65L6WE.js";
15
+ import {
16
+ init_esm_shims
17
+ } from "./chunk-LZVKQV3R.js";
13
18
 
14
19
  // src/index.ts
20
+ init_esm_shims();
15
21
  import { createHash } from "crypto";
16
22
  import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "fs";
17
23
  import { join, resolve } from "path";
18
24
  import { pathToFileURL } from "url";
19
25
 
20
26
  // src/terminal.ts
27
+ init_esm_shims();
21
28
  function renderMinScoreAbstentionFailure(summary, minScore) {
22
29
  if (summary.verdict !== "Insufficient source" && summary.verdict !== "Insufficient evidence") {
23
30
  throw new Error("A minimum-score abstention message requires an abstained Cejel summary.");
@@ -25,6 +32,13 @@ function renderMinScoreAbstentionFailure(summary, minScore) {
25
32
  return `Cejel: cannot evaluate the required minimum ${minScore.toFixed(1)}/4.0 because this repository has ${summary.verdict.toLowerCase()}.
26
33
  `;
27
34
  }
35
+ function renderMinScoreLimitationFailure(summary, minScore) {
36
+ if (summary.scanLimitations.length === 0) {
37
+ throw new Error("A minimum-score limitation message requires a limited Cejel summary.");
38
+ }
39
+ return `Cejel: cannot evaluate the required minimum ${minScore.toFixed(1)}/4.0 because the scan has limited evidence (${summary.scanLimitations.length} limitation${summary.scanLimitations.length === 1 ? "" : "s"}). Resolve the reported limitations and re-scan.
40
+ `;
41
+ }
28
42
  function renderTerminalCertificate(summary) {
29
43
  const abstained = summary.verdict === "Insufficient source" || summary.verdict === "Insufficient evidence";
30
44
  if (!abstained && (summary.overallScore === null || summary.codeTrustScore === null || summary.processTrustScore === null)) {
@@ -44,6 +58,26 @@ function renderTerminalCertificate(summary) {
44
58
  ` Process trust: ${formatScore(summary.processTrustScore)}/4.0`,
45
59
  ""
46
60
  ];
61
+ if (summary.scanLimitations.length > 0) {
62
+ lines.push(
63
+ "LIMITED EVIDENCE \u2014 the score and verdict are qualified by scan limitations:",
64
+ ...summary.scanLimitations.map((limitation) => ` - ${limitation}`),
65
+ ""
66
+ );
67
+ }
68
+ if (summary.contentReadSummary && summary.contentReadSummary.skipped > 0) {
69
+ const reads = summary.contentReadSummary;
70
+ const errnoCounts = Object.entries(reads.unreadableByErrno).map(([errno, count]) => `${errno}: ${count}`).join(", ");
71
+ lines.push(
72
+ `Skipped content entries: ${reads.skipped} (unreadable: ${reads.byReason.unreadable}${errnoCounts ? ` [${errnoCounts}]` : ""}; too large: ${reads.byReason.tooLarge}; excluded by extension: ${reads.byReason.excludedByExtension}; denied path: ${reads.byReason.deniedPath}; non-regular file: ${reads.byReason.nonRegularFile}).`
73
+ );
74
+ if (reads.affectedCriteria.length > 0) {
75
+ lines.push(
76
+ `Criteria abstaining as insufficient_data: ${reads.affectedCriteria.join(", ")}.`
77
+ );
78
+ }
79
+ lines.push("");
80
+ }
47
81
  if (summary.contributingSources.length > 0) {
48
82
  lines.push(`Incorporates findings from: ${summary.contributingSources.join(", ")}`);
49
83
  for (const source of summary.externalSources) {
@@ -210,13 +244,13 @@ async function runWitanFreeCli(args) {
210
244
  process.stdout.write(USAGE);
211
245
  return 0;
212
246
  }
213
- const { report, summary } = runCejelScan({
247
+ const { report, summary, generatedAt } = runCejelScan({
214
248
  repoPath: options.repoPath,
215
249
  ...options.productDisplayName ? { productDisplayName: options.productDisplayName } : {},
216
250
  ingestPatterns: options.ingestPatterns,
217
251
  warnOnEmptyIngestMatch: !options.quiet
218
252
  });
219
- const attestation = createWitanAttestation(report, { toolVersion: cliVersion() });
253
+ const attestation = createWitanAttestation(report, { toolVersion: cliVersion(), generatedAt });
220
254
  mkdirSync(options.outDir, { recursive: true });
221
255
  writeFileSync(join(options.outDir, "report.json"), serializeWitanReport(report), "utf8");
222
256
  writeFileSync(
@@ -224,7 +258,11 @@ async function runWitanFreeCli(args) {
224
258
  JSON.stringify(attestation, null, 2),
225
259
  "utf8"
226
260
  );
227
- writeFileSync(join(options.outDir, "certificate.html"), renderWitanHtmlReport(report), "utf8");
261
+ writeFileSync(
262
+ join(options.outDir, "certificate.html"),
263
+ renderWitanHtmlReport(report, { cliVersion: cliVersion(), generatedAt }),
264
+ "utf8"
265
+ );
228
266
  writeFileSync(
229
267
  join(options.outDir, "badge.json"),
230
268
  JSON.stringify(renderWitanBadgeEndpoint(report), null, 2),
@@ -246,6 +284,10 @@ Wrote:
246
284
  );
247
285
  }
248
286
  if (options.minScore != null) {
287
+ if (summary.scanLimitations.length > 0) {
288
+ process.stderr.write(renderMinScoreLimitationFailure(summary, options.minScore));
289
+ return 1;
290
+ }
249
291
  if (report.verdict === "insufficient_source") {
250
292
  process.stderr.write(renderMinScoreAbstentionFailure(summary, options.minScore));
251
293
  return 1;