@intellectual-frontiers/ergonex 0.3.0 → 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/mod.js +1236 -1528
- package/dist/modules/types.d.ts +4 -4
- package/dist/platform/k-args.d.ts +3 -24
- package/dist/state-record.d.ts +1 -1
- package/dist/vendor/ts/kernel/mod.d.ts +0 -6
- package/dist/vendor/ts/kernel/render.d.ts +1 -1
- package/dist/vendor/ts/kernel/trace.d.ts +1 -1
- package/ergonex.mjs +3421 -3705
- package/package.json +4 -2
- package/dist/vendor/ts/kernel/args.d.ts +0 -240
- package/dist/vendor/ts/kernel/commands.d.ts +0 -103
- package/dist/vendor/ts/kernel/palette.d.ts +0 -44
- package/dist/vendor/ts/kernel/rdf-schema.d.ts +0 -190
- package/dist/vendor/ts/kernel/rdf-term.d.ts +0 -162
- package/dist/vendor/ts/kernel/rdf-vocabularies.d.ts +0 -148
- package/dist/vendor/ts/kernel/rdf-write.d.ts +0 -25
- package/dist/vendor/ts/kernel/rdf.d.ts +0 -35
- package/dist/vendor/ts/kernel/vt.d.ts +0 -78
- package/dist/vendor/ts/kernel/width.d.ts +0 -63
package/dist/mod.js
CHANGED
|
@@ -238,582 +238,317 @@ function fromBase64(text) {
|
|
|
238
238
|
out[i] = s.charCodeAt(i);
|
|
239
239
|
return ok(out);
|
|
240
240
|
}
|
|
241
|
-
// ../ts/kernel/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
241
|
+
// ../ts/kernel/grc.ts
|
|
242
|
+
var INSTANT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:[.,](\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/i;
|
|
243
|
+
var CANONICAL_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
244
|
+
function instantOf(text) {
|
|
245
|
+
const m = INSTANT.exec(text.trim());
|
|
246
|
+
if (m === null)
|
|
247
|
+
return;
|
|
248
|
+
const [y, mo, d, h, mi, s] = [m[1], m[2], m[3], m[4], m[5], m[6]].map((x) => Number(x ?? ""));
|
|
249
|
+
if (y === undefined || mo === undefined || d === undefined || h === undefined || mi === undefined || s === undefined)
|
|
250
|
+
return;
|
|
251
|
+
const ms = Number((m[7] ?? "").padEnd(3, "0").slice(0, 3));
|
|
252
|
+
if (mo < 1 || mo > 12 || d < 1 || d > daysInMonth(y, mo) || h > 23 || mi > 59 || s > 59)
|
|
253
|
+
return;
|
|
254
|
+
const zone = (m[8] ?? "Z").toUpperCase();
|
|
255
|
+
let offset = 0;
|
|
256
|
+
if (zone !== "Z") {
|
|
257
|
+
const oh = Number(zone.slice(1, 3));
|
|
258
|
+
const om = Number(zone.slice(4, 6));
|
|
259
|
+
if (oh > 23 || om > 59)
|
|
260
|
+
return;
|
|
261
|
+
offset = (zone.startsWith("-") ? -1 : 1) * (oh * 60 + om) * 60000;
|
|
262
|
+
}
|
|
263
|
+
const date = new Date(0);
|
|
264
|
+
date.setUTCFullYear(y, mo - 1, d);
|
|
265
|
+
date.setUTCHours(h, mi, s, ms);
|
|
266
|
+
return instantFromEpochMs(date.getTime() - offset);
|
|
251
267
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
};
|
|
268
|
+
function instantFromEpochMs(ms) {
|
|
269
|
+
if (!Number.isFinite(ms))
|
|
270
|
+
return;
|
|
271
|
+
const date = new Date(Math.trunc(ms));
|
|
272
|
+
if (Number.isNaN(date.getTime()))
|
|
273
|
+
return;
|
|
274
|
+
const text = date.toISOString();
|
|
275
|
+
return CANONICAL_INSTANT.test(text) ? text : undefined;
|
|
261
276
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
return
|
|
277
|
+
function daysInMonth(year, month) {
|
|
278
|
+
const leap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
279
|
+
return month === 2 ? leap ? 29 : 28 : [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
265
280
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
prev = row;
|
|
274
|
-
}
|
|
275
|
-
return prev[b.length] ?? 0;
|
|
281
|
+
var DURATION = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:[.,]\d+)?)S)?)?$/;
|
|
282
|
+
function parseDuration(text) {
|
|
283
|
+
const m = DURATION.exec(text);
|
|
284
|
+
if (m === null || text === "P" || text.endsWith("T"))
|
|
285
|
+
return err({ kind: "duration", text });
|
|
286
|
+
const n = (i) => Number((m[i] ?? "0").replace(",", "."));
|
|
287
|
+
return ok({ text, years: n(1), months: n(2), weeks: n(3), days: n(4), hours: n(5), minutes: n(6), seconds: n(7) });
|
|
276
288
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
289
|
+
var ROLE = /^[a-z][a-z0-9]*(?:[-_./][a-z0-9]+)*$/;
|
|
290
|
+
function roleOf(text) {
|
|
291
|
+
return ROLE.test(text) ? text : undefined;
|
|
292
|
+
}
|
|
293
|
+
var SEVERITIES = ["info", "low", "medium", "high", "critical"];
|
|
294
|
+
var refined = (name, f) => {
|
|
295
|
+
return (input, path = "$") => {
|
|
296
|
+
if (typeof input === "string") {
|
|
297
|
+
const v = f(input);
|
|
298
|
+
if (v !== undefined)
|
|
299
|
+
return ok(v);
|
|
285
300
|
}
|
|
286
|
-
|
|
287
|
-
|
|
301
|
+
return err({
|
|
302
|
+
kind: "decode",
|
|
303
|
+
path,
|
|
304
|
+
expected: name,
|
|
305
|
+
found: typeof input === "string" ? `the string ${JSON.stringify(input).slice(0, 60)}` : typeof input
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
var instantDecoder = refined("an ISO 8601 date-time with a zone", instantOf);
|
|
310
|
+
var roleDecoder = refined("a role (lower-case words joined by - _ . or /)", roleOf);
|
|
311
|
+
var durationDecoder = refined("an ISO 8601 duration", (t) => {
|
|
312
|
+
const r = parseDuration(t);
|
|
313
|
+
return r.kind === "ok" ? r.value : undefined;
|
|
314
|
+
});
|
|
315
|
+
var severityDecoder = literal(...SEVERITIES);
|
|
316
|
+
var waiverInput = mapDecoder(object({ id: string, control: string, subjects: array(string), reason: string, approvedBy: roleDecoder, grantedAt: instantDecoder }, { expiresAt: instantDecoder }), (w) => w);
|
|
317
|
+
|
|
318
|
+
// ../ts/kernel/assess.ts
|
|
319
|
+
var impactDeclarationDecoder = object({ paths: array(string), controls: array(string) });
|
|
320
|
+
var RISK_LEVELS = ["very-low", "low", "moderate", "high", "very-high"];
|
|
321
|
+
var levelDecoder = literal(...RISK_LEVELS);
|
|
322
|
+
var riskDecoder = object({
|
|
323
|
+
id: string,
|
|
324
|
+
title: string,
|
|
325
|
+
likelihood: levelDecoder,
|
|
326
|
+
impact: levelDecoder,
|
|
327
|
+
treatment: literal("accept", "mitigate", "transfer", "avoid"),
|
|
328
|
+
owner: roleDecoder,
|
|
329
|
+
reviewBy: instantDecoder
|
|
330
|
+
}, { description: string, controls: array(string) });
|
|
331
|
+
// ../ts/kernel/sha256.ts
|
|
332
|
+
var SHA256 = /^[0-9a-f]{64}$/;
|
|
333
|
+
function sha256Of(text) {
|
|
334
|
+
const t = text.trim().toLowerCase();
|
|
335
|
+
return SHA256.test(t) ? t : undefined;
|
|
288
336
|
}
|
|
289
|
-
function
|
|
290
|
-
|
|
337
|
+
function toHex(bytes) {
|
|
338
|
+
let out = "";
|
|
339
|
+
for (const b of bytes)
|
|
340
|
+
out += b.toString(16).padStart(2, "0");
|
|
341
|
+
return out;
|
|
291
342
|
}
|
|
292
|
-
function
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
case "optional":
|
|
297
|
-
return `[${o.name}]`;
|
|
298
|
-
case "many":
|
|
299
|
-
return `[${o.name}...]`;
|
|
300
|
-
default:
|
|
301
|
-
return absurd(o.arity);
|
|
302
|
-
}
|
|
343
|
+
async function sha256(data) {
|
|
344
|
+
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
345
|
+
const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
|
|
346
|
+
return toHex(new Uint8Array(digest));
|
|
303
347
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
348
|
+
|
|
349
|
+
// ../ts/kernel/dsse.ts
|
|
350
|
+
var utf8 = new TextEncoder;
|
|
351
|
+
var lowerHex = (input, path = "$") => typeof input === "string" && /^(?:[0-9a-f]{2})+$/.test(input) ? ok(input) : err({ kind: "decode", path, expected: "lower-case hexadecimal", found: describe(input) });
|
|
352
|
+
var resourceDescriptorDecoder = object({ name: string, digest: record(lowerHex) }, { uri: string, mediaType: string, annotations: record(unknownValue) });
|
|
353
|
+
var base64Text = (input, path = "$") => typeof input === "string" && fromBase64(input).kind === "ok" ? ok(input) : err({ kind: "decode", path, expected: "standard base64", found: describe(input) });
|
|
354
|
+
var envelopeDecoder = object({
|
|
355
|
+
payload: base64Text,
|
|
356
|
+
payloadType: string,
|
|
357
|
+
signatures: array(object({ sig: base64Text }, { keyid: string }))
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// ../ts/kernel/evidence.ts
|
|
361
|
+
var GENESIS = "0".repeat(64);
|
|
362
|
+
var sha256Decoder = (input, path = "$") => {
|
|
363
|
+
const s = typeof input === "string" && /^[0-9a-f]{64}$/.test(input) ? sha256Of(input) : undefined;
|
|
364
|
+
return s === undefined ? err({ kind: "decode", path, expected: "a SHA-256 (64 lower-case hexadecimal digits)", found: typeof input }) : ok(s);
|
|
365
|
+
};
|
|
366
|
+
var ledgerEntryDecoder = object({
|
|
367
|
+
seq: refine(integer, "positive", (n) => n >= 1),
|
|
368
|
+
prev: sha256Decoder,
|
|
369
|
+
at: instantDecoder,
|
|
370
|
+
kind: string,
|
|
371
|
+
subject: object({ kind: string, id: string }),
|
|
372
|
+
evidence: sha256Decoder,
|
|
373
|
+
digest: sha256Decoder
|
|
374
|
+
});
|
|
375
|
+
var manifestDecoder = object({
|
|
376
|
+
files: array(object({ path: string, size: refine(integer, "size", (n) => n >= 0), sha256: sha256Decoder }))
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// ../ts/kernel/uuid.ts
|
|
380
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
381
|
+
function uuidOf(text) {
|
|
382
|
+
const t = text.trim().toLowerCase();
|
|
383
|
+
const bare = t.startsWith("urn:uuid:") ? t.slice("urn:uuid:".length) : t;
|
|
384
|
+
return UUID.test(bare) ? bare : undefined;
|
|
385
|
+
}
|
|
386
|
+
function constant(text) {
|
|
387
|
+
const u = uuidOf(text);
|
|
388
|
+
if (u === undefined)
|
|
389
|
+
throw new Error(`not a UUID: ${text}`);
|
|
390
|
+
return u;
|
|
391
|
+
}
|
|
392
|
+
var NIL_UUID = constant("00000000-0000-0000-0000-000000000000");
|
|
393
|
+
var NAMESPACE_DNS = constant("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
|
|
394
|
+
var NAMESPACE_URL = constant("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
|
|
395
|
+
var NAMESPACE_OID = constant("6ba7b812-9dad-11d1-80b4-00c04fd430c8");
|
|
396
|
+
var NAMESPACE_X500 = constant("6ba7b814-9dad-11d1-80b4-00c04fd430c8");
|
|
397
|
+
var utf82 = new TextEncoder;
|
|
398
|
+
|
|
399
|
+
// ../ts/kernel/attest.ts
|
|
400
|
+
var PASSING = new Set(["pass"]);
|
|
401
|
+
// ../ts/kernel/cbor.ts
|
|
402
|
+
var UTF8 = new TextDecoder("utf-8", { fatal: true });
|
|
403
|
+
// ../ts/kernel/glob.ts
|
|
404
|
+
var ESCAPE_OUTSIDE = new Set(["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]);
|
|
405
|
+
var ESCAPE_INSIDE = new Set(["-", "\\", "]"]);
|
|
406
|
+
var CLASSES = new Map([
|
|
407
|
+
["alnum", "\\dA-Za-z"],
|
|
408
|
+
["alpha", "A-Za-z"],
|
|
409
|
+
["ascii", "\\x00-\\x7F"],
|
|
410
|
+
["blank", "\\t "],
|
|
411
|
+
["cntrl", "\\x00-\\x1F\\x7F"],
|
|
412
|
+
["digit", "\\d"],
|
|
413
|
+
["graph", "\\x21-\\x7E"],
|
|
414
|
+
["lower", "a-z"],
|
|
415
|
+
["print", "\\x20-\\x7E"],
|
|
416
|
+
["punct", "!-\\/:-@\\[-`{-~"],
|
|
417
|
+
["space", "\\s\\v"],
|
|
418
|
+
["upper", "A-Z"],
|
|
419
|
+
["word", "\\w"],
|
|
420
|
+
["xdigit", "\\dA-Fa-f"]
|
|
421
|
+
]);
|
|
422
|
+
// ../ts/kernel/http.ts
|
|
423
|
+
var SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS", "TRACE"]);
|
|
424
|
+
// ../ts/kernel/md5.ts
|
|
425
|
+
var T = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0);
|
|
426
|
+
// ../ts/kernel/semver.ts
|
|
427
|
+
var PATTERN = /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
428
|
+
function parseSemVer(text) {
|
|
429
|
+
const m = PATTERN.exec(text.trim());
|
|
430
|
+
if (m === null)
|
|
431
|
+
return err(`${JSON.stringify(text)} is not a semantic version (major.minor.patch[-pre][+build])`);
|
|
432
|
+
const [, major = "", minor = "", patch = "", pre, build] = m;
|
|
433
|
+
const parts = [Number(major), Number(minor), Number(patch)];
|
|
434
|
+
if (!parts.every(Number.isSafeInteger))
|
|
435
|
+
return err(`${JSON.stringify(text)} has a number too large`);
|
|
436
|
+
return ok({
|
|
437
|
+
major: parts[0],
|
|
438
|
+
minor: parts[1],
|
|
439
|
+
patch: parts[2],
|
|
440
|
+
...pre === undefined ? {} : { pre },
|
|
441
|
+
...build === undefined ? {} : { build }
|
|
311
442
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
443
|
+
}
|
|
444
|
+
var IDENT = "(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)";
|
|
445
|
+
var PART = "(0|[1-9][0-9]*|[xX*])";
|
|
446
|
+
var PARTIAL = new RegExp(`^v?${PART}(?:\\.${PART}(?:\\.${PART}(?:-(${IDENT}(?:\\.${IDENT})*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?$`);
|
|
447
|
+
var ver = (major, minor, patch, pre) => ({
|
|
448
|
+
major,
|
|
449
|
+
minor,
|
|
450
|
+
patch,
|
|
451
|
+
...pre === undefined ? {} : { pre }
|
|
452
|
+
});
|
|
453
|
+
var at = (op, version) => ({ op, version });
|
|
454
|
+
var NOTHING = [at("<", ver(0, 0, 0, "0"))];
|
|
455
|
+
// ../ts/kernel/oscal.ts
|
|
456
|
+
var OPEN_OUTCOMES = new Set(["fail", "warn", "gap", "error", "accepted"]);
|
|
457
|
+
// ../ts/kernel/otel.ts
|
|
458
|
+
var TRACE_ID = /^[0-9a-f]{32}$/;
|
|
459
|
+
var SPAN_ID = /^[0-9a-f]{16}$/;
|
|
460
|
+
var ZEROS = /^0+$/;
|
|
461
|
+
function parseTraceId(text) {
|
|
462
|
+
if (!TRACE_ID.test(text))
|
|
463
|
+
return err("a trace id is 32 lower-case hexadecimal digits");
|
|
464
|
+
if (ZEROS.test(text))
|
|
465
|
+
return err("a trace id of all zeros is not valid");
|
|
466
|
+
return ok(text);
|
|
467
|
+
}
|
|
468
|
+
function parseSpanId(text) {
|
|
469
|
+
if (!SPAN_ID.test(text))
|
|
470
|
+
return err("a span id is 16 lower-case hexadecimal digits");
|
|
471
|
+
if (ZEROS.test(text))
|
|
472
|
+
return err("a span id of all zeros is not valid");
|
|
473
|
+
return ok(text);
|
|
474
|
+
}
|
|
475
|
+
var SAMPLED = 1;
|
|
476
|
+
var RANDOM = 2;
|
|
477
|
+
var KNOWN_FLAGS = SAMPLED | RANDOM;
|
|
478
|
+
var TRACESTATE_MAX_MEMBERS = 32;
|
|
479
|
+
var KEY_CHAR = "[a-z0-9_\\-*/]";
|
|
480
|
+
var TRACESTATE_KEY = new RegExp(`^(?:[a-z]${KEY_CHAR}{0,255}|[a-z0-9]${KEY_CHAR}{0,240}@[a-z]${KEY_CHAR}{0,13})$`);
|
|
481
|
+
var TRACESTATE_VALUE = /^[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]$/;
|
|
482
|
+
function isTraceStateKey(key) {
|
|
483
|
+
return TRACESTATE_KEY.test(key);
|
|
484
|
+
}
|
|
485
|
+
function isTraceStateValue(value) {
|
|
486
|
+
return TRACESTATE_VALUE.test(value);
|
|
487
|
+
}
|
|
488
|
+
function parseTracestate(header) {
|
|
489
|
+
const out = [];
|
|
490
|
+
const seen = new Set;
|
|
491
|
+
for (const raw of header.split(",")) {
|
|
492
|
+
if (out.length >= TRACESTATE_MAX_MEMBERS)
|
|
349
493
|
break;
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
const eq = word.indexOf("=");
|
|
353
|
-
const name = eq < 0 ? word : word.slice(0, eq);
|
|
354
|
-
const inline = eq < 0 ? undefined : word.slice(eq + 1);
|
|
355
|
-
if (name === "--help")
|
|
356
|
-
return err({ kind: "unexpected-value", option: name, value: inline ?? "" });
|
|
357
|
-
const direct = entries.find((e) => e.long === name);
|
|
358
|
-
const positive = name.startsWith("--no-") ? entries.find((e) => e.long === `--${name.slice(5)}`) : undefined;
|
|
359
|
-
const negated = direct === undefined && positive !== undefined && positive.option.kind === "flag" && positive.option.negatable;
|
|
360
|
-
const e = direct ?? (negated ? positive : undefined);
|
|
361
|
-
if (e === undefined)
|
|
362
|
-
return err({ kind: "unknown-option", option: name, suggestion: suggest(name, longs) });
|
|
363
|
-
const problem = take(e, name, inline, negated);
|
|
364
|
-
if (problem !== undefined)
|
|
365
|
-
return err(problem);
|
|
494
|
+
const member = raw.replace(/^[ \t]+|[ \t]+$/g, "");
|
|
495
|
+
if (member === "")
|
|
366
496
|
continue;
|
|
367
|
-
|
|
368
|
-
if (
|
|
369
|
-
positionals.push(word);
|
|
497
|
+
const eq = member.indexOf("=");
|
|
498
|
+
if (eq < 0)
|
|
370
499
|
continue;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return err({ kind: "unknown-option", option: written, suggestion: suggest(`-${word}`, longs) });
|
|
378
|
-
const after = word.slice(j + 1);
|
|
379
|
-
if (e.option.kind === "flag") {
|
|
380
|
-
if (after.startsWith("="))
|
|
381
|
-
return err({ kind: "unexpected-value", option: written, value: after.slice(1) });
|
|
382
|
-
} else if (after !== "") {
|
|
383
|
-
return err({ kind: "attached-value", option: written, word });
|
|
384
|
-
}
|
|
385
|
-
const problem = take(e, written, undefined, false);
|
|
386
|
-
if (problem !== undefined)
|
|
387
|
-
return err(problem);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
const values = [];
|
|
391
|
-
for (const e of entries) {
|
|
392
|
-
const o = e.option;
|
|
393
|
-
switch (o.kind) {
|
|
394
|
-
case "many":
|
|
395
|
-
values.push([e.key, listed.get(e.key) ?? []]);
|
|
396
|
-
break;
|
|
397
|
-
case "flag":
|
|
398
|
-
case "value": {
|
|
399
|
-
if (given.has(e.key)) {
|
|
400
|
-
values.push([e.key, given.get(e.key)]);
|
|
401
|
-
break;
|
|
402
|
-
}
|
|
403
|
-
const f = o.fallback;
|
|
404
|
-
switch (f.kind) {
|
|
405
|
-
case "none":
|
|
406
|
-
values.push([e.key, undefined]);
|
|
407
|
-
break;
|
|
408
|
-
case "default":
|
|
409
|
-
values.push([e.key, f.value]);
|
|
410
|
-
break;
|
|
411
|
-
case "required":
|
|
412
|
-
return err({ kind: "missing-option", option: e.long });
|
|
413
|
-
default:
|
|
414
|
-
return absurd(f);
|
|
415
|
-
}
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
default:
|
|
419
|
-
return absurd(o);
|
|
420
|
-
}
|
|
500
|
+
const key = member.slice(0, eq);
|
|
501
|
+
const value = member.slice(eq + 1);
|
|
502
|
+
if (!isTraceStateKey(key) || !isTraceStateValue(value) || seen.has(key))
|
|
503
|
+
continue;
|
|
504
|
+
seen.add(key);
|
|
505
|
+
out.push({ key, value });
|
|
421
506
|
}
|
|
422
|
-
|
|
423
|
-
const most = operands.some((o) => o.arity === "many") ? Number.POSITIVE_INFINITY : operands.filter((o) => o.arity !== "many").length;
|
|
424
|
-
const missing = least[positionals.length];
|
|
425
|
-
if (missing !== undefined)
|
|
426
|
-
return err({ kind: "missing-argument", argument: missing.name });
|
|
427
|
-
const extra = positionals[most];
|
|
428
|
-
if (extra !== undefined)
|
|
429
|
-
return err({ kind: "unexpected-argument", argument: extra, takes: operands.map(operandWord) });
|
|
430
|
-
const options = Object.fromEntries(values);
|
|
431
|
-
return ok({ kind: "args", options, positionals, rest });
|
|
507
|
+
return out;
|
|
432
508
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
return `${e.option} is given more than once`;
|
|
447
|
-
case "missing-option":
|
|
448
|
-
return `${e.option} is required`;
|
|
449
|
-
case "missing-argument":
|
|
450
|
-
return `${command} needs ${e.argument}`;
|
|
451
|
-
case "unexpected-argument":
|
|
452
|
-
return `${command} does not take ${e.argument}: ${e.takes.length === 0 ? "it takes no arguments" : `it takes ${e.takes.join(" ")}`}`;
|
|
453
|
-
default:
|
|
454
|
-
return absurd(e);
|
|
509
|
+
var SEVERITY = { TRACE: 1, DEBUG: 5, INFO: 9, WARN: 13, ERROR: 17, FATAL: 21 };
|
|
510
|
+
function isSeverityNumber(n) {
|
|
511
|
+
return Number.isInteger(n) && n >= 1 && n <= 24;
|
|
512
|
+
}
|
|
513
|
+
var TWO_56 = 2 ** 56;
|
|
514
|
+
var CREDENTIAL_WORDS = new Set(["key", "code", "sig", "pwd", "pass", "session", "sid", "otp", "awsaccesskeyid", "sas", "se", "sp", "sv"]);
|
|
515
|
+
// ../ts/kernel/otlp.ts
|
|
516
|
+
var SPAN_KINDS = ["internal", "server", "client", "producer", "consumer"];
|
|
517
|
+
class Failure extends Error {
|
|
518
|
+
error;
|
|
519
|
+
constructor(error) {
|
|
520
|
+
super(error.path);
|
|
521
|
+
this.error = error;
|
|
455
522
|
}
|
|
456
523
|
}
|
|
457
|
-
function
|
|
458
|
-
return
|
|
524
|
+
function failure(path, expected, input) {
|
|
525
|
+
return { kind: "decode", path, expected, found: describe(input) };
|
|
459
526
|
}
|
|
460
|
-
function
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
527
|
+
function message(build) {
|
|
528
|
+
return (input, path = "$") => {
|
|
529
|
+
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
530
|
+
return err(failure(path, "an object", input));
|
|
531
|
+
const read = (key, decoder) => {
|
|
532
|
+
const r = decoder(Reflect.get(input, key), `${path}.${key}`);
|
|
533
|
+
if (r.kind === "err")
|
|
534
|
+
throw new Failure(r.error);
|
|
535
|
+
return r.value;
|
|
536
|
+
};
|
|
537
|
+
const f = {
|
|
538
|
+
req: read,
|
|
539
|
+
opt: (key, decoder, fallback) => {
|
|
540
|
+
const v = Reflect.get(input, key);
|
|
541
|
+
return v === undefined || v === null ? fallback : read(key, decoder);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
try {
|
|
545
|
+
return ok(build(f, path));
|
|
546
|
+
} catch (e) {
|
|
547
|
+
if (e instanceof Failure)
|
|
548
|
+
return err(e.error);
|
|
549
|
+
throw e;
|
|
473
550
|
}
|
|
474
|
-
|
|
475
|
-
return { left: `${short}${e.long} ${o.valueName}`, note: " (repeatable)" };
|
|
476
|
-
default:
|
|
477
|
-
return absurd(o);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
function columns(rows) {
|
|
481
|
-
const width = Math.max(0, ...rows.map(([l]) => l.length));
|
|
482
|
-
return rows.map(([l, r]) => ` ${l.padEnd(width)} ${r}`.trimEnd());
|
|
483
|
-
}
|
|
484
|
-
function helpOf(program, summary, spec, operands = []) {
|
|
485
|
-
const entries = Object.keys(spec).flatMap((key) => {
|
|
486
|
-
const option = spec[key];
|
|
487
|
-
return option === undefined ? [] : [{ key, long: longName(key), option }];
|
|
488
|
-
});
|
|
489
|
-
const required = entries.flatMap((e) => e.option.kind === "value" && e.option.fallback.kind === "required" ? [`${e.long} ${e.option.valueName}`] : []);
|
|
490
|
-
const usage = [program, "[OPTIONS]", ...required, ...operands.map(operandWord)].join(" ");
|
|
491
|
-
const rows = entries.map((e) => {
|
|
492
|
-
const line = optionLine(e);
|
|
493
|
-
return [line.left, `${e.option.help}${line.note}`];
|
|
494
|
-
});
|
|
495
|
-
return [
|
|
496
|
-
`${program}: ${summary}`,
|
|
497
|
-
"",
|
|
498
|
-
`Usage: ${usage}`,
|
|
499
|
-
"",
|
|
500
|
-
"Options:",
|
|
501
|
-
...columns([...rows, ["-h, --help", "Show this help and do nothing else."]]),
|
|
502
|
-
...operands.length === 0 ? [] : ["", "Arguments:", ...columns(operands.map((o) => [operandWord(o), o.help]))]
|
|
503
|
-
].join(`
|
|
504
|
-
`);
|
|
505
|
-
}
|
|
506
|
-
// ../ts/kernel/grc.ts
|
|
507
|
-
var INSTANT = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:[.,](\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/i;
|
|
508
|
-
var CANONICAL_INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
509
|
-
function instantOf(text) {
|
|
510
|
-
const m = INSTANT.exec(text.trim());
|
|
511
|
-
if (m === null)
|
|
512
|
-
return;
|
|
513
|
-
const [y, mo, d, h, mi, s] = [m[1], m[2], m[3], m[4], m[5], m[6]].map((x) => Number(x ?? ""));
|
|
514
|
-
if (y === undefined || mo === undefined || d === undefined || h === undefined || mi === undefined || s === undefined)
|
|
515
|
-
return;
|
|
516
|
-
const ms = Number((m[7] ?? "").padEnd(3, "0").slice(0, 3));
|
|
517
|
-
if (mo < 1 || mo > 12 || d < 1 || d > daysInMonth(y, mo) || h > 23 || mi > 59 || s > 59)
|
|
518
|
-
return;
|
|
519
|
-
const zone = (m[8] ?? "Z").toUpperCase();
|
|
520
|
-
let offset = 0;
|
|
521
|
-
if (zone !== "Z") {
|
|
522
|
-
const oh = Number(zone.slice(1, 3));
|
|
523
|
-
const om = Number(zone.slice(4, 6));
|
|
524
|
-
if (oh > 23 || om > 59)
|
|
525
|
-
return;
|
|
526
|
-
offset = (zone.startsWith("-") ? -1 : 1) * (oh * 60 + om) * 60000;
|
|
527
|
-
}
|
|
528
|
-
const date = new Date(0);
|
|
529
|
-
date.setUTCFullYear(y, mo - 1, d);
|
|
530
|
-
date.setUTCHours(h, mi, s, ms);
|
|
531
|
-
return instantFromEpochMs(date.getTime() - offset);
|
|
532
|
-
}
|
|
533
|
-
function instantFromEpochMs(ms) {
|
|
534
|
-
if (!Number.isFinite(ms))
|
|
535
|
-
return;
|
|
536
|
-
const date = new Date(Math.trunc(ms));
|
|
537
|
-
if (Number.isNaN(date.getTime()))
|
|
538
|
-
return;
|
|
539
|
-
const text = date.toISOString();
|
|
540
|
-
return CANONICAL_INSTANT.test(text) ? text : undefined;
|
|
541
|
-
}
|
|
542
|
-
function daysInMonth(year, month) {
|
|
543
|
-
const leap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
544
|
-
return month === 2 ? leap ? 29 : 28 : [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
545
|
-
}
|
|
546
|
-
var DURATION = /^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:[.,]\d+)?)S)?)?$/;
|
|
547
|
-
function parseDuration(text) {
|
|
548
|
-
const m = DURATION.exec(text);
|
|
549
|
-
if (m === null || text === "P" || text.endsWith("T"))
|
|
550
|
-
return err({ kind: "duration", text });
|
|
551
|
-
const n = (i) => Number((m[i] ?? "0").replace(",", "."));
|
|
552
|
-
return ok({ text, years: n(1), months: n(2), weeks: n(3), days: n(4), hours: n(5), minutes: n(6), seconds: n(7) });
|
|
553
|
-
}
|
|
554
|
-
var ROLE = /^[a-z][a-z0-9]*(?:[-_./][a-z0-9]+)*$/;
|
|
555
|
-
function roleOf(text) {
|
|
556
|
-
return ROLE.test(text) ? text : undefined;
|
|
557
|
-
}
|
|
558
|
-
var SEVERITIES = ["info", "low", "medium", "high", "critical"];
|
|
559
|
-
var refined = (name, f) => {
|
|
560
|
-
return (input, path = "$") => {
|
|
561
|
-
if (typeof input === "string") {
|
|
562
|
-
const v = f(input);
|
|
563
|
-
if (v !== undefined)
|
|
564
|
-
return ok(v);
|
|
565
|
-
}
|
|
566
|
-
return err({
|
|
567
|
-
kind: "decode",
|
|
568
|
-
path,
|
|
569
|
-
expected: name,
|
|
570
|
-
found: typeof input === "string" ? `the string ${JSON.stringify(input).slice(0, 60)}` : typeof input
|
|
571
|
-
});
|
|
572
|
-
};
|
|
573
|
-
};
|
|
574
|
-
var instantDecoder = refined("an ISO 8601 date-time with a zone", instantOf);
|
|
575
|
-
var roleDecoder = refined("a role (lower-case words joined by - _ . or /)", roleOf);
|
|
576
|
-
var durationDecoder = refined("an ISO 8601 duration", (t) => {
|
|
577
|
-
const r = parseDuration(t);
|
|
578
|
-
return r.kind === "ok" ? r.value : undefined;
|
|
579
|
-
});
|
|
580
|
-
var severityDecoder = literal(...SEVERITIES);
|
|
581
|
-
var waiverInput = mapDecoder(object({ id: string, control: string, subjects: array(string), reason: string, approvedBy: roleDecoder, grantedAt: instantDecoder }, { expiresAt: instantDecoder }), (w) => w);
|
|
582
|
-
|
|
583
|
-
// ../ts/kernel/assess.ts
|
|
584
|
-
var impactDeclarationDecoder = object({ paths: array(string), controls: array(string) });
|
|
585
|
-
var RISK_LEVELS = ["very-low", "low", "moderate", "high", "very-high"];
|
|
586
|
-
var levelDecoder = literal(...RISK_LEVELS);
|
|
587
|
-
var riskDecoder = object({
|
|
588
|
-
id: string,
|
|
589
|
-
title: string,
|
|
590
|
-
likelihood: levelDecoder,
|
|
591
|
-
impact: levelDecoder,
|
|
592
|
-
treatment: literal("accept", "mitigate", "transfer", "avoid"),
|
|
593
|
-
owner: roleDecoder,
|
|
594
|
-
reviewBy: instantDecoder
|
|
595
|
-
}, { description: string, controls: array(string) });
|
|
596
|
-
// ../ts/kernel/sha256.ts
|
|
597
|
-
var SHA256 = /^[0-9a-f]{64}$/;
|
|
598
|
-
function sha256Of(text) {
|
|
599
|
-
const t = text.trim().toLowerCase();
|
|
600
|
-
return SHA256.test(t) ? t : undefined;
|
|
601
|
-
}
|
|
602
|
-
function toHex(bytes) {
|
|
603
|
-
let out = "";
|
|
604
|
-
for (const b of bytes)
|
|
605
|
-
out += b.toString(16).padStart(2, "0");
|
|
606
|
-
return out;
|
|
607
|
-
}
|
|
608
|
-
async function sha256(data) {
|
|
609
|
-
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
610
|
-
const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
|
|
611
|
-
return toHex(new Uint8Array(digest));
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// ../ts/kernel/dsse.ts
|
|
615
|
-
var utf8 = new TextEncoder;
|
|
616
|
-
var lowerHex = (input, path = "$") => typeof input === "string" && /^(?:[0-9a-f]{2})+$/.test(input) ? ok(input) : err({ kind: "decode", path, expected: "lower-case hexadecimal", found: describe(input) });
|
|
617
|
-
var resourceDescriptorDecoder = object({ name: string, digest: record(lowerHex) }, { uri: string, mediaType: string, annotations: record(unknownValue) });
|
|
618
|
-
var base64Text = (input, path = "$") => typeof input === "string" && fromBase64(input).kind === "ok" ? ok(input) : err({ kind: "decode", path, expected: "standard base64", found: describe(input) });
|
|
619
|
-
var envelopeDecoder = object({
|
|
620
|
-
payload: base64Text,
|
|
621
|
-
payloadType: string,
|
|
622
|
-
signatures: array(object({ sig: base64Text }, { keyid: string }))
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// ../ts/kernel/evidence.ts
|
|
626
|
-
var GENESIS = "0".repeat(64);
|
|
627
|
-
var sha256Decoder = (input, path = "$") => {
|
|
628
|
-
const s = typeof input === "string" && /^[0-9a-f]{64}$/.test(input) ? sha256Of(input) : undefined;
|
|
629
|
-
return s === undefined ? err({ kind: "decode", path, expected: "a SHA-256 (64 lower-case hexadecimal digits)", found: typeof input }) : ok(s);
|
|
630
|
-
};
|
|
631
|
-
var ledgerEntryDecoder = object({
|
|
632
|
-
seq: refine(integer, "positive", (n) => n >= 1),
|
|
633
|
-
prev: sha256Decoder,
|
|
634
|
-
at: instantDecoder,
|
|
635
|
-
kind: string,
|
|
636
|
-
subject: object({ kind: string, id: string }),
|
|
637
|
-
evidence: sha256Decoder,
|
|
638
|
-
digest: sha256Decoder
|
|
639
|
-
});
|
|
640
|
-
var manifestDecoder = object({
|
|
641
|
-
files: array(object({ path: string, size: refine(integer, "size", (n) => n >= 0), sha256: sha256Decoder }))
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
// ../ts/kernel/uuid.ts
|
|
645
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
646
|
-
function uuidOf(text) {
|
|
647
|
-
const t = text.trim().toLowerCase();
|
|
648
|
-
const bare = t.startsWith("urn:uuid:") ? t.slice("urn:uuid:".length) : t;
|
|
649
|
-
return UUID.test(bare) ? bare : undefined;
|
|
650
|
-
}
|
|
651
|
-
function constant(text) {
|
|
652
|
-
const u = uuidOf(text);
|
|
653
|
-
if (u === undefined)
|
|
654
|
-
throw new Error(`not a UUID: ${text}`);
|
|
655
|
-
return u;
|
|
656
|
-
}
|
|
657
|
-
var NIL_UUID = constant("00000000-0000-0000-0000-000000000000");
|
|
658
|
-
var NAMESPACE_DNS = constant("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
|
|
659
|
-
var NAMESPACE_URL = constant("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
|
|
660
|
-
var NAMESPACE_OID = constant("6ba7b812-9dad-11d1-80b4-00c04fd430c8");
|
|
661
|
-
var NAMESPACE_X500 = constant("6ba7b814-9dad-11d1-80b4-00c04fd430c8");
|
|
662
|
-
var utf82 = new TextEncoder;
|
|
663
|
-
|
|
664
|
-
// ../ts/kernel/attest.ts
|
|
665
|
-
var PASSING = new Set(["pass"]);
|
|
666
|
-
// ../ts/kernel/cbor.ts
|
|
667
|
-
var UTF8 = new TextDecoder("utf-8", { fatal: true });
|
|
668
|
-
// ../ts/kernel/glob.ts
|
|
669
|
-
var ESCAPE_OUTSIDE = new Set(["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]);
|
|
670
|
-
var ESCAPE_INSIDE = new Set(["-", "\\", "]"]);
|
|
671
|
-
var CLASSES = new Map([
|
|
672
|
-
["alnum", "\\dA-Za-z"],
|
|
673
|
-
["alpha", "A-Za-z"],
|
|
674
|
-
["ascii", "\\x00-\\x7F"],
|
|
675
|
-
["blank", "\\t "],
|
|
676
|
-
["cntrl", "\\x00-\\x1F\\x7F"],
|
|
677
|
-
["digit", "\\d"],
|
|
678
|
-
["graph", "\\x21-\\x7E"],
|
|
679
|
-
["lower", "a-z"],
|
|
680
|
-
["print", "\\x20-\\x7E"],
|
|
681
|
-
["punct", "!-\\/:-@\\[-`{-~"],
|
|
682
|
-
["space", "\\s\\v"],
|
|
683
|
-
["upper", "A-Z"],
|
|
684
|
-
["word", "\\w"],
|
|
685
|
-
["xdigit", "\\dA-Fa-f"]
|
|
686
|
-
]);
|
|
687
|
-
// ../ts/kernel/http.ts
|
|
688
|
-
var SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS", "TRACE"]);
|
|
689
|
-
// ../ts/kernel/md5.ts
|
|
690
|
-
var T = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0);
|
|
691
|
-
// ../ts/kernel/semver.ts
|
|
692
|
-
var PATTERN = /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
693
|
-
function parseSemVer(text) {
|
|
694
|
-
const m = PATTERN.exec(text.trim());
|
|
695
|
-
if (m === null)
|
|
696
|
-
return err(`${JSON.stringify(text)} is not a semantic version (major.minor.patch[-pre][+build])`);
|
|
697
|
-
const [, major = "", minor = "", patch = "", pre, build] = m;
|
|
698
|
-
const parts = [Number(major), Number(minor), Number(patch)];
|
|
699
|
-
if (!parts.every(Number.isSafeInteger))
|
|
700
|
-
return err(`${JSON.stringify(text)} has a number too large`);
|
|
701
|
-
return ok({
|
|
702
|
-
major: parts[0],
|
|
703
|
-
minor: parts[1],
|
|
704
|
-
patch: parts[2],
|
|
705
|
-
...pre === undefined ? {} : { pre },
|
|
706
|
-
...build === undefined ? {} : { build }
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
var IDENT = "(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)";
|
|
710
|
-
var PART = "(0|[1-9][0-9]*|[xX*])";
|
|
711
|
-
var PARTIAL = new RegExp(`^v?${PART}(?:\\.${PART}(?:\\.${PART}(?:-(${IDENT}(?:\\.${IDENT})*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?$`);
|
|
712
|
-
var ver = (major, minor, patch, pre) => ({
|
|
713
|
-
major,
|
|
714
|
-
minor,
|
|
715
|
-
patch,
|
|
716
|
-
...pre === undefined ? {} : { pre }
|
|
717
|
-
});
|
|
718
|
-
var at = (op, version) => ({ op, version });
|
|
719
|
-
var NOTHING = [at("<", ver(0, 0, 0, "0"))];
|
|
720
|
-
// ../ts/kernel/oscal.ts
|
|
721
|
-
var OPEN_OUTCOMES = new Set(["fail", "warn", "gap", "error", "accepted"]);
|
|
722
|
-
// ../ts/kernel/otel.ts
|
|
723
|
-
var TRACE_ID = /^[0-9a-f]{32}$/;
|
|
724
|
-
var SPAN_ID = /^[0-9a-f]{16}$/;
|
|
725
|
-
var ZEROS = /^0+$/;
|
|
726
|
-
function parseTraceId(text) {
|
|
727
|
-
if (!TRACE_ID.test(text))
|
|
728
|
-
return err("a trace id is 32 lower-case hexadecimal digits");
|
|
729
|
-
if (ZEROS.test(text))
|
|
730
|
-
return err("a trace id of all zeros is not valid");
|
|
731
|
-
return ok(text);
|
|
732
|
-
}
|
|
733
|
-
function parseSpanId(text) {
|
|
734
|
-
if (!SPAN_ID.test(text))
|
|
735
|
-
return err("a span id is 16 lower-case hexadecimal digits");
|
|
736
|
-
if (ZEROS.test(text))
|
|
737
|
-
return err("a span id of all zeros is not valid");
|
|
738
|
-
return ok(text);
|
|
739
|
-
}
|
|
740
|
-
var SAMPLED = 1;
|
|
741
|
-
var RANDOM = 2;
|
|
742
|
-
var KNOWN_FLAGS = SAMPLED | RANDOM;
|
|
743
|
-
var TRACESTATE_MAX_MEMBERS = 32;
|
|
744
|
-
var KEY_CHAR = "[a-z0-9_\\-*/]";
|
|
745
|
-
var TRACESTATE_KEY = new RegExp(`^(?:[a-z]${KEY_CHAR}{0,255}|[a-z0-9]${KEY_CHAR}{0,240}@[a-z]${KEY_CHAR}{0,13})$`);
|
|
746
|
-
var TRACESTATE_VALUE = /^[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]$/;
|
|
747
|
-
function isTraceStateKey(key) {
|
|
748
|
-
return TRACESTATE_KEY.test(key);
|
|
749
|
-
}
|
|
750
|
-
function isTraceStateValue(value) {
|
|
751
|
-
return TRACESTATE_VALUE.test(value);
|
|
752
|
-
}
|
|
753
|
-
function parseTracestate(header) {
|
|
754
|
-
const out = [];
|
|
755
|
-
const seen = new Set;
|
|
756
|
-
for (const raw of header.split(",")) {
|
|
757
|
-
if (out.length >= TRACESTATE_MAX_MEMBERS)
|
|
758
|
-
break;
|
|
759
|
-
const member = raw.replace(/^[ \t]+|[ \t]+$/g, "");
|
|
760
|
-
if (member === "")
|
|
761
|
-
continue;
|
|
762
|
-
const eq = member.indexOf("=");
|
|
763
|
-
if (eq < 0)
|
|
764
|
-
continue;
|
|
765
|
-
const key = member.slice(0, eq);
|
|
766
|
-
const value = member.slice(eq + 1);
|
|
767
|
-
if (!isTraceStateKey(key) || !isTraceStateValue(value) || seen.has(key))
|
|
768
|
-
continue;
|
|
769
|
-
seen.add(key);
|
|
770
|
-
out.push({ key, value });
|
|
771
|
-
}
|
|
772
|
-
return out;
|
|
773
|
-
}
|
|
774
|
-
var SEVERITY = { TRACE: 1, DEBUG: 5, INFO: 9, WARN: 13, ERROR: 17, FATAL: 21 };
|
|
775
|
-
function isSeverityNumber(n) {
|
|
776
|
-
return Number.isInteger(n) && n >= 1 && n <= 24;
|
|
777
|
-
}
|
|
778
|
-
var TWO_56 = 2 ** 56;
|
|
779
|
-
var CREDENTIAL_WORDS = new Set(["key", "code", "sig", "pwd", "pass", "session", "sid", "otp", "awsaccesskeyid", "sas", "se", "sp", "sv"]);
|
|
780
|
-
// ../ts/kernel/otlp.ts
|
|
781
|
-
var SPAN_KINDS = ["internal", "server", "client", "producer", "consumer"];
|
|
782
|
-
class Failure extends Error {
|
|
783
|
-
error;
|
|
784
|
-
constructor(error) {
|
|
785
|
-
super(error.path);
|
|
786
|
-
this.error = error;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
function failure(path, expected, input) {
|
|
790
|
-
return { kind: "decode", path, expected, found: describe(input) };
|
|
791
|
-
}
|
|
792
|
-
function message(build) {
|
|
793
|
-
return (input, path = "$") => {
|
|
794
|
-
if (typeof input !== "object" || input === null || Array.isArray(input))
|
|
795
|
-
return err(failure(path, "an object", input));
|
|
796
|
-
const read = (key, decoder) => {
|
|
797
|
-
const r = decoder(Reflect.get(input, key), `${path}.${key}`);
|
|
798
|
-
if (r.kind === "err")
|
|
799
|
-
throw new Failure(r.error);
|
|
800
|
-
return r.value;
|
|
801
|
-
};
|
|
802
|
-
const f = {
|
|
803
|
-
req: read,
|
|
804
|
-
opt: (key, decoder, fallback) => {
|
|
805
|
-
const v = Reflect.get(input, key);
|
|
806
|
-
return v === undefined || v === null ? fallback : read(key, decoder);
|
|
807
|
-
}
|
|
808
|
-
};
|
|
809
|
-
try {
|
|
810
|
-
return ok(build(f, path));
|
|
811
|
-
} catch (e) {
|
|
812
|
-
if (e instanceof Failure)
|
|
813
|
-
return err(e.error);
|
|
814
|
-
throw e;
|
|
815
|
-
}
|
|
816
|
-
};
|
|
551
|
+
};
|
|
817
552
|
}
|
|
818
553
|
function list(element) {
|
|
819
554
|
return (input, path = "$") => {
|
|
@@ -1081,1034 +816,1007 @@ var histogramPoint = message((f, path) => {
|
|
|
1081
816
|
function temporalityOf(n) {
|
|
1082
817
|
return n === 1 ? "delta" : "cumulative";
|
|
1083
818
|
}
|
|
1084
|
-
var decodeMetric = message((f, path) => {
|
|
1085
|
-
const head = { name: f.opt("name", str, ""), description: f.opt("description", str, ""), unit: f.opt("unit", str, "") };
|
|
1086
|
-
const sum = f.opt("sum", message((g) => ({
|
|
1087
|
-
kind: "sum",
|
|
1088
|
-
points: g.opt("dataPoints", list(numberPoint), []),
|
|
1089
|
-
temporality: temporalityOf(g.opt("aggregationTemporality", temporalityEnum, 2)),
|
|
1090
|
-
monotonic: g.opt("isMonotonic", bool, false)
|
|
1091
|
-
})), undefined);
|
|
1092
|
-
if (sum !== undefined)
|
|
1093
|
-
return { ...head, data: sum };
|
|
1094
|
-
const gauge = f.opt("gauge", message((g) => ({ kind: "gauge", points: g.opt("dataPoints", list(numberPoint), []) })), undefined);
|
|
1095
|
-
if (gauge !== undefined)
|
|
1096
|
-
return { ...head, data: gauge };
|
|
1097
|
-
const histogram = f.opt("histogram", message((g) => ({
|
|
1098
|
-
kind: "histogram",
|
|
1099
|
-
points: g.opt("dataPoints", list(histogramPoint), []),
|
|
1100
|
-
temporality: temporalityOf(g.opt("aggregationTemporality", temporalityEnum, 2))
|
|
1101
|
-
})), undefined);
|
|
1102
|
-
if (histogram !== undefined)
|
|
1103
|
-
return { ...head, data: histogram };
|
|
1104
|
-
throw new Failure(failure(`${path}.sum`, "a sum, a gauge or a histogram", undefined));
|
|
1105
|
-
});
|
|
1106
|
-
// ../ts/kernel/
|
|
1107
|
-
var
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
[
|
|
1112
|
-
[
|
|
1113
|
-
[
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
var
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
var
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
819
|
+
var decodeMetric = message((f, path) => {
|
|
820
|
+
const head = { name: f.opt("name", str, ""), description: f.opt("description", str, ""), unit: f.opt("unit", str, "") };
|
|
821
|
+
const sum = f.opt("sum", message((g) => ({
|
|
822
|
+
kind: "sum",
|
|
823
|
+
points: g.opt("dataPoints", list(numberPoint), []),
|
|
824
|
+
temporality: temporalityOf(g.opt("aggregationTemporality", temporalityEnum, 2)),
|
|
825
|
+
monotonic: g.opt("isMonotonic", bool, false)
|
|
826
|
+
})), undefined);
|
|
827
|
+
if (sum !== undefined)
|
|
828
|
+
return { ...head, data: sum };
|
|
829
|
+
const gauge = f.opt("gauge", message((g) => ({ kind: "gauge", points: g.opt("dataPoints", list(numberPoint), []) })), undefined);
|
|
830
|
+
if (gauge !== undefined)
|
|
831
|
+
return { ...head, data: gauge };
|
|
832
|
+
const histogram = f.opt("histogram", message((g) => ({
|
|
833
|
+
kind: "histogram",
|
|
834
|
+
points: g.opt("dataPoints", list(histogramPoint), []),
|
|
835
|
+
temporality: temporalityOf(g.opt("aggregationTemporality", temporalityEnum, 2))
|
|
836
|
+
})), undefined);
|
|
837
|
+
if (histogram !== undefined)
|
|
838
|
+
return { ...head, data: histogram };
|
|
839
|
+
throw new Failure(failure(`${path}.sum`, "a sum, a gauge or a histogram", undefined));
|
|
840
|
+
});
|
|
841
|
+
// ../ts/kernel/png.ts
|
|
842
|
+
var MAX_PIXELS = 2 ** 24;
|
|
843
|
+
var COLOUR_TYPES = new Map([
|
|
844
|
+
[0, { samples: 1, depths: [1, 2, 4, 8, 16], name: "greyscale" }],
|
|
845
|
+
[2, { samples: 3, depths: [8, 16], name: "RGB" }],
|
|
846
|
+
[3, { samples: 1, depths: [1, 2, 4, 8], name: "palette" }],
|
|
847
|
+
[4, { samples: 2, depths: [8, 16], name: "greyscale with alpha" }],
|
|
848
|
+
[6, { samples: 4, depths: [8, 16], name: "RGBA" }]
|
|
849
|
+
]);
|
|
850
|
+
var PRECISION_BITS = 32 - 8 - 2;
|
|
851
|
+
var ONE = 2 ** PRECISION_BITS;
|
|
852
|
+
// ../terminal/src/palette.ts
|
|
853
|
+
var ESC = String.fromCharCode(27);
|
|
854
|
+
|
|
855
|
+
// ../ts/kernel/signals.ts
|
|
856
|
+
var ATTRIBUTE_TYPES = new Set([
|
|
857
|
+
"string",
|
|
858
|
+
"boolean",
|
|
859
|
+
"int",
|
|
860
|
+
"double",
|
|
861
|
+
"bytes",
|
|
862
|
+
"string[]",
|
|
863
|
+
"boolean[]",
|
|
864
|
+
"int[]",
|
|
865
|
+
"double[]"
|
|
866
|
+
]);
|
|
867
|
+
function defineSignals(kinds) {
|
|
868
|
+
for (const [name, d] of Object.entries(kinds)) {
|
|
869
|
+
const declared = new Set(Object.keys(d.attributes).map((k) => k.replace(/\?$/, "")));
|
|
870
|
+
for (const [k, t] of Object.entries(d.attributes)) {
|
|
871
|
+
if (!ATTRIBUTE_TYPES.has(t))
|
|
872
|
+
throw new Error(`${name}: the attribute ${k} has the type ${t}, which does not exist`);
|
|
873
|
+
}
|
|
874
|
+
for (const s of d.secret ?? [])
|
|
875
|
+
if (!declared.has(s))
|
|
876
|
+
throw new Error(`${name}: the secret attribute ${s} is not declared`);
|
|
877
|
+
if (d.signal === "histogram" && d.bounds !== undefined) {
|
|
878
|
+
const b = d.bounds;
|
|
879
|
+
if (b.some((x, i) => !Number.isFinite(x) || i > 0 && x <= (b[i - 1] ?? -Infinity))) {
|
|
880
|
+
throw new Error(`${name}: the histogram bounds do not increase`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
return { kinds };
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// ../terminal/src/width.ts
|
|
888
|
+
var ESC2 = String.fromCharCode(27);
|
|
889
|
+
var BEL = String.fromCharCode(7);
|
|
890
|
+
var ESCAPE = new RegExp(`${ESC2}(?:\\[[0-?]*[ -/]*[@-~]?|[\\]PX^_][^${BEL}${ESC2}]*(?:${BEL}|${ESC2}\\\\)?|[ -/]*[0-~]|)`, "g");
|
|
891
|
+
var segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
892
|
+
var SGR = new RegExp(`^${ESC2}\\[([0-9;:]*)m$`);
|
|
893
|
+
var RESET = `${ESC2}[0m`;
|
|
894
|
+
|
|
895
|
+
// ../ts/kernel/render.ts
|
|
896
|
+
var ESC3 = String.fromCharCode(27);
|
|
897
|
+
var CONTROL = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(31)}${String.fromCharCode(127)}-${String.fromCharCode(159)}]`, "g");
|
|
898
|
+
// ../ts/kernel/xml.ts
|
|
899
|
+
var FORBIDDEN = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11, 12)}${String.fromCharCode(14)}-${String.fromCharCode(31)}\\ufffe\\uffff]`, "g");
|
|
900
|
+
// ../ts/kernel/sigv4.ts
|
|
901
|
+
var UNSIGNED_HEADERS = new Set(["authorization", "connection", "expect", "user-agent", "x-amzn-trace-id", "traceparent", "tracestate"]);
|
|
902
|
+
var encoder = new TextEncoder;
|
|
903
|
+
// ../ts/kernel/test-report.ts
|
|
904
|
+
var STYLE = "body{font:15px/1.5 system-ui,sans-serif;margin:2rem auto;max-width:72rem;padding:0 1rem;color:#1b1b1b;background:#fff}" + "table{border-collapse:collapse;margin:.5rem 0;width:100%}th,td{border:1px solid #c8c8c8;padding:.25rem .5rem;text-align:left;vertical-align:top;overflow-wrap:anywhere}" + "th{background:#f0f0f0}h1{font-size:1.6rem}h2{font-size:1.2rem;margin-top:2rem}" + "@media (prefers-color-scheme:dark){body{color:#e8e8e8;background:#161616}th{background:#2a2a2a}th,td{border-color:#444}}";
|
|
905
|
+
// ../ts/kernel/toml.ts
|
|
906
|
+
var CONTROL2 = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(8, 10)}-${String.fromCharCode(31, 127)}]`);
|
|
907
|
+
// ../ts/kernel/webauthn.ts
|
|
908
|
+
var clientData = object({ type: string, challenge: string, origin: string }, { crossOrigin: boolean, topOrigin: string });
|
|
909
|
+
var kind = literal("public-key");
|
|
910
|
+
var extensionResults = record(unknownValue);
|
|
911
|
+
// src/portable.ts
|
|
912
|
+
function describePortableError(e) {
|
|
913
|
+
switch (e.kind) {
|
|
914
|
+
case "empty":
|
|
915
|
+
return "a path segment is empty";
|
|
916
|
+
case "dot":
|
|
917
|
+
return `the path segment ${JSON.stringify(e.segment)} would leave its folder`;
|
|
918
|
+
case "forbidden-character":
|
|
919
|
+
return `the path segment ${JSON.stringify(e.segment)} holds ${JSON.stringify(e.character)}, which Windows does not allow in a name`;
|
|
920
|
+
case "control-character":
|
|
921
|
+
return `the path segment ${JSON.stringify(e.segment)} holds a control character`;
|
|
922
|
+
case "trailing-dot-or-space":
|
|
923
|
+
return `the path segment ${JSON.stringify(e.segment)} ends in a dot or a space, which Windows drops`;
|
|
924
|
+
case "device-name":
|
|
925
|
+
return `the path segment ${JSON.stringify(e.segment)} is the Windows device name ${e.device}, with or without an extension, in any case`;
|
|
926
|
+
case "too-long":
|
|
927
|
+
return `the path segment is ${e.bytes} bytes in UTF-8, and a name may have 255`;
|
|
928
|
+
case "not-nfc":
|
|
929
|
+
return `the path segment ${JSON.stringify(e.segment)} is not in Unicode normalization form NFC, so it would be another name on macOS`;
|
|
930
|
+
default:
|
|
931
|
+
return absurd(e);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
var FORBIDDEN2 = new Set(["<", ">", ":", '"', "/", "\\", "|", "?", "*"]);
|
|
935
|
+
var DEVICE = /^(?:CON|PRN|AUX|NUL|CONIN\$|CONOUT\$|COM[0-9\u00b9\u00b2\u00b3]|LPT[0-9\u00b9\u00b2\u00b3])$/i;
|
|
936
|
+
function isDeviceName(name) {
|
|
937
|
+
return DEVICE.test((name.split(".")[0] ?? "").replace(/ +$/, ""));
|
|
938
|
+
}
|
|
939
|
+
var MAX_SEGMENT_BYTES = 255;
|
|
940
|
+
function segment(text) {
|
|
941
|
+
if (text === "")
|
|
942
|
+
return err({ kind: "empty" });
|
|
943
|
+
if (text === "." || text === "..")
|
|
944
|
+
return err({ kind: "dot", segment: text });
|
|
945
|
+
for (const ch of text) {
|
|
946
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
947
|
+
if (code < 32 || code === 127)
|
|
948
|
+
return err({ kind: "control-character", segment: text });
|
|
949
|
+
if (FORBIDDEN2.has(ch))
|
|
950
|
+
return err({ kind: "forbidden-character", segment: text, character: ch });
|
|
1126
951
|
}
|
|
1127
|
-
if (
|
|
1128
|
-
return err({ kind: "
|
|
952
|
+
if (text.endsWith(".") || text.endsWith(" "))
|
|
953
|
+
return err({ kind: "trailing-dot-or-space", segment: text });
|
|
954
|
+
const stem = (text.split(".")[0] ?? "").replace(/ +$/, "");
|
|
955
|
+
if (isDeviceName(text))
|
|
956
|
+
return err({
|
|
957
|
+
kind: "device-name",
|
|
958
|
+
segment: text,
|
|
959
|
+
device: stem.toUpperCase()
|
|
960
|
+
});
|
|
961
|
+
const bytes = new TextEncoder().encode(text).length;
|
|
962
|
+
if (bytes > MAX_SEGMENT_BYTES)
|
|
963
|
+
return err({ kind: "too-long", segment: text.slice(0, 40), bytes });
|
|
964
|
+
if (text !== text.normalize("NFC"))
|
|
965
|
+
return err({ kind: "not-nfc", segment: text });
|
|
1129
966
|
return ok(text);
|
|
1130
967
|
}
|
|
1131
|
-
function
|
|
968
|
+
function repoPath(segments) {
|
|
969
|
+
if (segments.length === 0)
|
|
970
|
+
return err({ kind: "empty" });
|
|
971
|
+
const made = [];
|
|
972
|
+
for (const s of segments) {
|
|
973
|
+
const r = segment(s);
|
|
974
|
+
if (r.kind === "err")
|
|
975
|
+
return r;
|
|
976
|
+
made.push(r.value);
|
|
977
|
+
}
|
|
978
|
+
return ok(made.join("/"));
|
|
979
|
+
}
|
|
980
|
+
function segmentsOf(path) {
|
|
981
|
+
return path.split("/");
|
|
982
|
+
}
|
|
983
|
+
function child2(path, name) {
|
|
984
|
+
return `${path}/${name}`;
|
|
985
|
+
}
|
|
986
|
+
function nativePath(root, path, separator) {
|
|
987
|
+
const base = root.replace(/[\\/]+$/, "");
|
|
988
|
+
return [base, ...segmentsOf(path)].join(separator);
|
|
989
|
+
}
|
|
990
|
+
function foldKey(path) {
|
|
991
|
+
return path.normalize("NFC").toUpperCase().toLowerCase().normalize("NFC");
|
|
992
|
+
}
|
|
993
|
+
function collisions(items) {
|
|
994
|
+
const groups = new Map;
|
|
995
|
+
for (const item of items) {
|
|
996
|
+
const key = foldKey(item.path);
|
|
997
|
+
const group = groups.get(key);
|
|
998
|
+
if (group === undefined)
|
|
999
|
+
groups.set(key, [{ ...item }]);
|
|
1000
|
+
else
|
|
1001
|
+
group.push({ ...item });
|
|
1002
|
+
}
|
|
1003
|
+
return [...groups.entries()].filter(([, members]) => members.length > 1).map(([key, members]) => ({ key, members }));
|
|
1004
|
+
}
|
|
1005
|
+
var WINDOWS_PATH_LIMIT = 259;
|
|
1006
|
+
function checkPathLength(windowsPath, longPathsEnabled) {
|
|
1007
|
+
if (longPathsEnabled || windowsPath.length <= WINDOWS_PATH_LIMIT)
|
|
1008
|
+
return ok(windowsPath);
|
|
1009
|
+
return err({
|
|
1010
|
+
kind: "path-too-long",
|
|
1011
|
+
path: windowsPath,
|
|
1012
|
+
length: windowsPath.length,
|
|
1013
|
+
limit: WINDOWS_PATH_LIMIT
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
var REPO_PATH_ROOM = 150;
|
|
1017
|
+
function repoPathLength(root, path, separator) {
|
|
1018
|
+
const length = nativePath(root, path, separator).length;
|
|
1019
|
+
if (length > WINDOWS_PATH_LIMIT)
|
|
1020
|
+
return { kind: "too-long", length };
|
|
1021
|
+
if (length > REPO_PATH_ROOM)
|
|
1022
|
+
return { kind: "no-room", length };
|
|
1023
|
+
return { kind: "fits", length };
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// src/render.ts
|
|
1027
|
+
function describeGenerateError(e) {
|
|
1132
1028
|
switch (e.kind) {
|
|
1133
|
-
case "
|
|
1134
|
-
return `${JSON.stringify(e.
|
|
1135
|
-
case "
|
|
1136
|
-
return `${
|
|
1029
|
+
case "bad-path":
|
|
1030
|
+
return `${JSON.stringify(e.path)} cannot be the path of a generated file: ${e.reason}`;
|
|
1031
|
+
case "not-auto":
|
|
1032
|
+
return `${e.path} is a generated file whose name does not carry .auto. (only a Git hook in .ergonex/hooks/ may lack it)`;
|
|
1033
|
+
case "collision":
|
|
1034
|
+
return `${e.path} is the same path as ${e.other} after Unicode normalization and case folding; both are refused`;
|
|
1035
|
+
case "inside-repository":
|
|
1036
|
+
return `${e.path} is inside the working tree of ${e.repository}; a generated file is never written into a repository`;
|
|
1037
|
+
case "bad-data":
|
|
1038
|
+
return `${e.what}: ${e.reason}`;
|
|
1137
1039
|
default:
|
|
1138
1040
|
return absurd(e);
|
|
1139
1041
|
}
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1042
|
+
}
|
|
1043
|
+
var HOOKS_FOLDER = ".ergonex/hooks";
|
|
1044
|
+
function headerText(generator) {
|
|
1045
|
+
return `Generated by ${generator}. Do not edit by hand: change workspace.ts and run \`ergonex render\`.`;
|
|
1046
|
+
}
|
|
1047
|
+
function normalizeText(text) {
|
|
1048
|
+
const lf = text.replace(/^/, "").replaceAll(`\r
|
|
1049
|
+
`, `
|
|
1050
|
+
`).replaceAll("\r", `
|
|
1051
|
+
`);
|
|
1052
|
+
return `${lf.replace(/\n+$/, "")}
|
|
1053
|
+
`;
|
|
1054
|
+
}
|
|
1055
|
+
function isAutoName(name) {
|
|
1056
|
+
return name.includes(".auto.") || name.endsWith(".auto");
|
|
1057
|
+
}
|
|
1058
|
+
function generatedPath(path) {
|
|
1059
|
+
const made = repoPath(path.split("/"));
|
|
1060
|
+
if (made.kind === "err")
|
|
1061
|
+
return err({
|
|
1062
|
+
kind: "bad-path",
|
|
1063
|
+
path,
|
|
1064
|
+
reason: describePortableError(made.error)
|
|
1065
|
+
});
|
|
1066
|
+
return made;
|
|
1067
|
+
}
|
|
1068
|
+
var noBom = (text) => text.replace(/^\uFEFF/, "");
|
|
1069
|
+
function contentOf(body, generator) {
|
|
1070
|
+
const header = headerText(generator);
|
|
1071
|
+
switch (body.format) {
|
|
1072
|
+
case "json":
|
|
1073
|
+
return normalizeText(JSON.stringify({ _generated: header, ...body.value }, null, 2));
|
|
1074
|
+
case "markdown":
|
|
1075
|
+
return normalizeText(`<!-- ${header} -->
|
|
1076
|
+
|
|
1077
|
+
${noBom(body.text)}`);
|
|
1078
|
+
case "yaml":
|
|
1079
|
+
case "gitconfig":
|
|
1080
|
+
case "envrc":
|
|
1081
|
+
return normalizeText(`# ${header}
|
|
1082
|
+
|
|
1083
|
+
${noBom(body.text)}`);
|
|
1084
|
+
case "sh": {
|
|
1085
|
+
const text = noBom(body.text);
|
|
1086
|
+
const m = /^(#![^\n]*)\n/.exec(text);
|
|
1087
|
+
return m === null ? normalizeText(`# ${header}
|
|
1088
|
+
${text}`) : normalizeText(`${m[1]}
|
|
1089
|
+
# ${header}
|
|
1090
|
+
${text.slice(m[0].length)}`);
|
|
1091
|
+
}
|
|
1092
|
+
default:
|
|
1093
|
+
return absurd(body);
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
function generated(path, body, options) {
|
|
1097
|
+
const made = generatedPath(path);
|
|
1098
|
+
if (made.kind === "err")
|
|
1099
|
+
return made;
|
|
1100
|
+
const name = made.value.split("/").at(-1) ?? "";
|
|
1101
|
+
const isHook = made.value.startsWith(`${HOOKS_FOLDER}/`) && made.value.split("/").length === 3;
|
|
1102
|
+
if (!isAutoName(name) && !isHook)
|
|
1103
|
+
return err({ kind: "not-auto", path });
|
|
1104
|
+
return ok({
|
|
1105
|
+
path: made.value,
|
|
1106
|
+
content: contentOf(body, options.generator),
|
|
1107
|
+
mode: options.mode ?? "0644",
|
|
1108
|
+
generator: options.generator
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
function fileDigest(file) {
|
|
1112
|
+
return sha256(file.content);
|
|
1113
|
+
}
|
|
1114
|
+
function checkFiles(files, repositories) {
|
|
1115
|
+
const errors = [];
|
|
1116
|
+
for (const c of collisions(files.map((f) => ({ id: f.path, path: f.path })))) {
|
|
1117
|
+
for (const m of c.members) {
|
|
1118
|
+
const other = c.members.find((o) => o !== m);
|
|
1119
|
+
errors.push({
|
|
1120
|
+
kind: "collision",
|
|
1121
|
+
path: m.path,
|
|
1122
|
+
other: other?.path ?? m.path
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
for (const f of files) {
|
|
1127
|
+
const key = foldKey(f.path);
|
|
1128
|
+
const inside = repositories.find((r) => key.startsWith(`${foldKey(r)}/`));
|
|
1129
|
+
if (inside !== undefined)
|
|
1130
|
+
errors.push({
|
|
1131
|
+
kind: "inside-repository",
|
|
1132
|
+
path: f.path,
|
|
1133
|
+
repository: inside
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
if (errors.length > 0)
|
|
1137
|
+
return err(errors);
|
|
1138
|
+
return ok([...files].sort((a, b) => foldKey(a.path) < foldKey(b.path) ? -1 : foldKey(a.path) > foldKey(b.path) ? 1 : 0));
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// src/desired.ts
|
|
1142
|
+
function settingsOf(manifest, facts) {
|
|
1143
|
+
const settings = {
|
|
1144
|
+
"core.hooksPath": `${facts.homePosix.replace(/\/+$/, "")}/.ergonex/hooks`
|
|
1145
|
+
};
|
|
1146
|
+
if (manifest.policy.requiresSignedCommits) {
|
|
1147
|
+
settings["commit.gpgsign"] = "true";
|
|
1148
|
+
if (manifest.signing !== undefined) {
|
|
1149
|
+
settings["gpg.format"] = manifest.signing.format;
|
|
1150
|
+
if (manifest.signing.key !== undefined)
|
|
1151
|
+
settings["user.signingkey"] = manifest.signing.key;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
if (manifest.identity !== undefined) {
|
|
1155
|
+
settings["user.name"] = manifest.identity.name;
|
|
1156
|
+
settings["user.email"] = manifest.identity.email;
|
|
1146
1157
|
}
|
|
1158
|
+
if (facts.windows)
|
|
1159
|
+
settings["core.longpaths"] = "true";
|
|
1160
|
+
return settings;
|
|
1147
1161
|
}
|
|
1148
|
-
function
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
return {
|
|
1162
|
-
}
|
|
1163
|
-
function iriIn(ns, local) {
|
|
1164
|
-
return checked(`${ns.iri}${local}`);
|
|
1162
|
+
async function desiredOf(manifest, files, facts) {
|
|
1163
|
+
const settings = settingsOf(manifest, facts);
|
|
1164
|
+
const repos = manifest.repositories.map((r) => ({
|
|
1165
|
+
path: r.path,
|
|
1166
|
+
ref: r.ref,
|
|
1167
|
+
cloneUrl: r.cloneUrl,
|
|
1168
|
+
branch: r.branch,
|
|
1169
|
+
settings
|
|
1170
|
+
}));
|
|
1171
|
+
const worktrees = manifest.repositories.flatMap((r) => r.worktrees.map((w) => ({ path: w.path, repo: r.path, branch: w.branch })));
|
|
1172
|
+
const desiredFiles = [];
|
|
1173
|
+
for (const f of files)
|
|
1174
|
+
desiredFiles.push({ path: f.path, sha256: await fileDigest(f) });
|
|
1175
|
+
return { repos, worktrees, files: desiredFiles, hostChanges: [] };
|
|
1165
1176
|
}
|
|
1166
|
-
function
|
|
1167
|
-
const out =
|
|
1168
|
-
for (const
|
|
1169
|
-
out
|
|
1177
|
+
async function digestsOf(files) {
|
|
1178
|
+
const out = new Map;
|
|
1179
|
+
for (const f of files)
|
|
1180
|
+
out.set(f.path, await fileDigest(f));
|
|
1170
1181
|
return out;
|
|
1171
1182
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
]);
|
|
1187
|
-
// ../ts/kernel/rdf-vocabularies.ts
|
|
1188
|
-
var RDF = namespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
|
|
1189
|
-
var rdf = vocabulary(RDF, {
|
|
1190
|
-
type: "rdf:Property",
|
|
1191
|
-
first: "rdf:Property",
|
|
1192
|
-
rest: "rdf:Property",
|
|
1193
|
-
value: "rdf:Property",
|
|
1194
|
-
Property: "rdfs:Class",
|
|
1195
|
-
List: "rdfs:Class",
|
|
1196
|
-
nil: "rdf:List",
|
|
1197
|
-
langString: "rdfs:Datatype"
|
|
1198
|
-
});
|
|
1199
|
-
var RDFS = namespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
|
|
1200
|
-
var rdfs = vocabulary(RDFS, {
|
|
1201
|
-
Resource: "rdfs:Class",
|
|
1202
|
-
Class: "rdfs:Class",
|
|
1203
|
-
Datatype: "rdfs:Class",
|
|
1204
|
-
Literal: "rdfs:Class",
|
|
1205
|
-
label: "rdf:Property",
|
|
1206
|
-
comment: "rdf:Property",
|
|
1207
|
-
domain: "rdf:Property",
|
|
1208
|
-
range: "rdf:Property",
|
|
1209
|
-
subClassOf: "rdf:Property",
|
|
1210
|
-
subPropertyOf: "rdf:Property",
|
|
1211
|
-
seeAlso: "rdf:Property",
|
|
1212
|
-
isDefinedBy: "rdf:Property"
|
|
1213
|
-
});
|
|
1214
|
-
var OWL = namespace("owl", "http://www.w3.org/2002/07/owl#");
|
|
1215
|
-
var owl = vocabulary(OWL, {
|
|
1216
|
-
Ontology: "rdfs:Class",
|
|
1217
|
-
Class: "rdfs:Class",
|
|
1218
|
-
ObjectProperty: "rdfs:Class",
|
|
1219
|
-
DatatypeProperty: "rdfs:Class",
|
|
1220
|
-
AnnotationProperty: "rdfs:Class",
|
|
1221
|
-
NamedIndividual: "rdfs:Class",
|
|
1222
|
-
Thing: "rdfs:Class",
|
|
1223
|
-
versionInfo: "rdf:Property",
|
|
1224
|
-
versionIRI: "rdf:Property",
|
|
1225
|
-
imports: "rdf:Property",
|
|
1226
|
-
sameAs: "rdf:Property",
|
|
1227
|
-
equivalentClass: "rdf:Property"
|
|
1228
|
-
});
|
|
1229
|
-
var XSD2 = namespace("xsd", "http://www.w3.org/2001/XMLSchema#");
|
|
1230
|
-
var xsd = vocabulary(XSD2, {
|
|
1231
|
-
string: "rdfs:Datatype",
|
|
1232
|
-
boolean: "rdfs:Datatype",
|
|
1233
|
-
integer: "rdfs:Datatype",
|
|
1234
|
-
nonNegativeInteger: "rdfs:Datatype",
|
|
1235
|
-
positiveInteger: "rdfs:Datatype",
|
|
1236
|
-
decimal: "rdfs:Datatype",
|
|
1237
|
-
double: "rdfs:Datatype",
|
|
1238
|
-
date: "rdfs:Datatype",
|
|
1239
|
-
dateTime: "rdfs:Datatype",
|
|
1240
|
-
duration: "rdfs:Datatype",
|
|
1241
|
-
anyURI: "rdfs:Datatype",
|
|
1242
|
-
language: "rdfs:Datatype"
|
|
1243
|
-
});
|
|
1244
|
-
var SKOS = namespace("skos", "http://www.w3.org/2004/02/skos/core#");
|
|
1245
|
-
var skos = vocabulary(SKOS, {
|
|
1246
|
-
Concept: "rdfs:Class",
|
|
1247
|
-
ConceptScheme: "rdfs:Class",
|
|
1248
|
-
Collection: "rdfs:Class",
|
|
1249
|
-
inScheme: "rdf:Property",
|
|
1250
|
-
hasTopConcept: "rdf:Property",
|
|
1251
|
-
topConceptOf: "rdf:Property",
|
|
1252
|
-
prefLabel: "rdf:Property",
|
|
1253
|
-
altLabel: "rdf:Property",
|
|
1254
|
-
definition: "rdf:Property",
|
|
1255
|
-
notation: "rdf:Property",
|
|
1256
|
-
broader: "rdf:Property",
|
|
1257
|
-
narrower: "rdf:Property",
|
|
1258
|
-
related: "rdf:Property",
|
|
1259
|
-
note: "rdf:Property",
|
|
1260
|
-
scopeNote: "rdf:Property",
|
|
1261
|
-
example: "rdf:Property"
|
|
1262
|
-
});
|
|
1263
|
-
var DCTERMS = namespace("dcterms", "http://purl.org/dc/terms/");
|
|
1264
|
-
var dcterms = vocabulary(DCTERMS, {
|
|
1265
|
-
identifier: "rdf:Property",
|
|
1266
|
-
title: "rdf:Property",
|
|
1267
|
-
description: "rdf:Property",
|
|
1268
|
-
source: "rdf:Property",
|
|
1269
|
-
license: "rdf:Property",
|
|
1270
|
-
created: "rdf:Property",
|
|
1271
|
-
modified: "rdf:Property",
|
|
1272
|
-
date: "rdf:Property",
|
|
1273
|
-
creator: "rdf:Property",
|
|
1274
|
-
publisher: "rdf:Property",
|
|
1275
|
-
isPartOf: "rdf:Property",
|
|
1276
|
-
hasPart: "rdf:Property",
|
|
1277
|
-
references: "rdf:Property",
|
|
1278
|
-
conformsTo: "rdf:Property",
|
|
1279
|
-
Standard: "rdfs:Class"
|
|
1280
|
-
});
|
|
1281
|
-
var PROV = namespace("prov", "http://www.w3.org/ns/prov#");
|
|
1282
|
-
var prov = vocabulary(PROV, {
|
|
1283
|
-
Entity: "rdfs:Class",
|
|
1284
|
-
Activity: "rdfs:Class",
|
|
1285
|
-
Agent: "rdfs:Class",
|
|
1286
|
-
Person: "rdfs:Class",
|
|
1287
|
-
Organization: "rdfs:Class",
|
|
1288
|
-
SoftwareAgent: "rdfs:Class",
|
|
1289
|
-
wasGeneratedBy: "rdf:Property",
|
|
1290
|
-
wasDerivedFrom: "rdf:Property",
|
|
1291
|
-
wasAttributedTo: "rdf:Property",
|
|
1292
|
-
wasAssociatedWith: "rdf:Property",
|
|
1293
|
-
wasInformedBy: "rdf:Property",
|
|
1294
|
-
actedOnBehalfOf: "rdf:Property",
|
|
1295
|
-
used: "rdf:Property",
|
|
1296
|
-
startedAtTime: "rdf:Property",
|
|
1297
|
-
endedAtTime: "rdf:Property",
|
|
1298
|
-
generatedAtTime: "rdf:Property",
|
|
1299
|
-
atLocation: "rdf:Property",
|
|
1300
|
-
value: "rdf:Property"
|
|
1301
|
-
});
|
|
1302
|
-
var SH = namespace("sh", "http://www.w3.org/ns/shacl#");
|
|
1303
|
-
var sh = vocabulary(SH, {
|
|
1304
|
-
NodeShape: "rdfs:Class",
|
|
1305
|
-
PropertyShape: "rdfs:Class",
|
|
1306
|
-
targetClass: "rdf:Property",
|
|
1307
|
-
property: "rdf:Property",
|
|
1308
|
-
path: "rdf:Property",
|
|
1309
|
-
datatype: "rdf:Property",
|
|
1310
|
-
class: "rdf:Property",
|
|
1311
|
-
node: "rdf:Property",
|
|
1312
|
-
minCount: "rdf:Property",
|
|
1313
|
-
maxCount: "rdf:Property",
|
|
1314
|
-
pattern: "rdf:Property",
|
|
1315
|
-
in: "rdf:Property",
|
|
1316
|
-
order: "rdf:Property",
|
|
1317
|
-
name: "rdf:Property",
|
|
1318
|
-
description: "rdf:Property"
|
|
1319
|
-
});
|
|
1320
|
-
// ../ts/kernel/rdf-schema.ts
|
|
1321
|
-
function rangeOf(kind, words) {
|
|
1322
|
-
return words === undefined ? { kind } : { kind, words };
|
|
1323
|
-
}
|
|
1324
|
-
var range = {
|
|
1325
|
-
string: rangeOf("string"),
|
|
1326
|
-
langString: rangeOf("lang"),
|
|
1327
|
-
text: rangeOf("text"),
|
|
1328
|
-
boolean: rangeOf("boolean"),
|
|
1329
|
-
integer: rangeOf("integer"),
|
|
1330
|
-
ref: () => rangeOf("ref"),
|
|
1331
|
-
oneOf: (words) => rangeOf("string", words)
|
|
1332
|
-
};
|
|
1333
|
-
function one(property, r) {
|
|
1334
|
-
return { property, range: r, cardinality: "one" };
|
|
1183
|
+
// src/doctor.ts
|
|
1184
|
+
function severityOf(level) {
|
|
1185
|
+
switch (level) {
|
|
1186
|
+
case "ok":
|
|
1187
|
+
return;
|
|
1188
|
+
case "suggest":
|
|
1189
|
+
return "Informational";
|
|
1190
|
+
case "warn":
|
|
1191
|
+
return "Warning";
|
|
1192
|
+
case "error":
|
|
1193
|
+
return "Error";
|
|
1194
|
+
default:
|
|
1195
|
+
return absurd(level);
|
|
1196
|
+
}
|
|
1335
1197
|
}
|
|
1336
|
-
function
|
|
1337
|
-
return
|
|
1198
|
+
function findingsOf(checks, today) {
|
|
1199
|
+
return checks.flatMap((c) => {
|
|
1200
|
+
const severity = severityOf(c.level);
|
|
1201
|
+
return severity === undefined ? [] : [
|
|
1202
|
+
{
|
|
1203
|
+
ruleId: c.id,
|
|
1204
|
+
severity,
|
|
1205
|
+
message: c.message,
|
|
1206
|
+
subject: c.subject,
|
|
1207
|
+
firstSeen: today
|
|
1208
|
+
}
|
|
1209
|
+
];
|
|
1210
|
+
});
|
|
1338
1211
|
}
|
|
1339
|
-
function
|
|
1340
|
-
|
|
1212
|
+
function classifyFs(type, wsl) {
|
|
1213
|
+
const t = type.toLowerCase();
|
|
1214
|
+
if (["msdos", "vfat", "fat", "fat32", "fat16"].includes(t))
|
|
1215
|
+
return "fat";
|
|
1216
|
+
if (t === "exfat")
|
|
1217
|
+
return "exfat";
|
|
1218
|
+
if (["9p", "drvfs", "v9fs"].includes(t) && wsl)
|
|
1219
|
+
return "wsl-windows-drive";
|
|
1220
|
+
if ([
|
|
1221
|
+
"nfs",
|
|
1222
|
+
"nfs3",
|
|
1223
|
+
"nfs4",
|
|
1224
|
+
"cifs",
|
|
1225
|
+
"smb",
|
|
1226
|
+
"smb2",
|
|
1227
|
+
"smb3",
|
|
1228
|
+
"smbfs",
|
|
1229
|
+
"afpfs",
|
|
1230
|
+
"9p",
|
|
1231
|
+
"v9fs",
|
|
1232
|
+
"sshfs",
|
|
1233
|
+
"fuse.sshfs",
|
|
1234
|
+
"webdav",
|
|
1235
|
+
"ncpfs",
|
|
1236
|
+
"fuse.rclone"
|
|
1237
|
+
].includes(t))
|
|
1238
|
+
return "network";
|
|
1239
|
+
return "ok";
|
|
1341
1240
|
}
|
|
1342
|
-
function
|
|
1343
|
-
|
|
1241
|
+
function fsCheck(probe, home) {
|
|
1242
|
+
if (probe.kind === "not-run")
|
|
1243
|
+
return {
|
|
1244
|
+
id: "ergonex/filesystem",
|
|
1245
|
+
level: "suggest",
|
|
1246
|
+
subject: home,
|
|
1247
|
+
message: `the file system of the root was not probed: ${probe.reason}`
|
|
1248
|
+
};
|
|
1249
|
+
const kind = classifyFs(probe.type, probe.wsl);
|
|
1250
|
+
const at = (level, message) => ({
|
|
1251
|
+
id: "ergonex/filesystem",
|
|
1252
|
+
level,
|
|
1253
|
+
subject: home,
|
|
1254
|
+
message
|
|
1255
|
+
});
|
|
1256
|
+
switch (kind) {
|
|
1257
|
+
case "ok":
|
|
1258
|
+
return at("ok", `the root is on a file system of type ${probe.type}`);
|
|
1259
|
+
case "fat":
|
|
1260
|
+
return at("warn", `the root is on a FAT file system (${probe.type}): it has no execute bit and a two-second time resolution, so hooks may not run; move the root to NTFS, APFS or ext4`);
|
|
1261
|
+
case "exfat":
|
|
1262
|
+
return at("warn", "the root is on an exFAT file system: it has no execute bit and a two-second time resolution, so hooks may not run; move the root to NTFS, APFS or ext4");
|
|
1263
|
+
case "network":
|
|
1264
|
+
return at("warn", `the root is on a network share (${probe.type}): its locks are not reliable, so two runs may write at once; move the root to a local disk`);
|
|
1265
|
+
case "wsl-windows-drive":
|
|
1266
|
+
return at("warn", "the root is on a Windows drive seen from WSL (/mnt/c): it is slow and case-insensitive; keep the root in the Linux file system, or run ergonex from Windows");
|
|
1267
|
+
default:
|
|
1268
|
+
return absurd(kind);
|
|
1269
|
+
}
|
|
1344
1270
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1271
|
+
var MIN_NODE_MAJOR = 26;
|
|
1272
|
+
function runtimeChecks(runtime, tools) {
|
|
1273
|
+
const out = [];
|
|
1274
|
+
const major = parseSemVer(runtime.version.replace(/^v/, ""));
|
|
1275
|
+
if (runtime.name === "node" && major.kind === "ok" && major.value.major < MIN_NODE_MAJOR)
|
|
1276
|
+
out.push({
|
|
1277
|
+
id: "ergonex/runtime",
|
|
1278
|
+
level: "error",
|
|
1279
|
+
subject: "node",
|
|
1280
|
+
message: `ergonex runs on Node ${MIN_NODE_MAJOR} or later, and this is Node ${runtime.version}; install Node ${MIN_NODE_MAJOR} or run ergonex with Bun`
|
|
1281
|
+
});
|
|
1282
|
+
else
|
|
1283
|
+
out.push({
|
|
1284
|
+
id: "ergonex/runtime",
|
|
1285
|
+
level: "ok",
|
|
1286
|
+
subject: runtime.name,
|
|
1287
|
+
message: `running on ${runtime.name} ${runtime.version}`
|
|
1288
|
+
});
|
|
1289
|
+
for (const t of tools) {
|
|
1290
|
+
if (t.version === undefined) {
|
|
1291
|
+
const needed = t.name === "git";
|
|
1292
|
+
const isRuntime = t.name === runtime.name;
|
|
1293
|
+
out.push({
|
|
1294
|
+
id: "ergonex/tool",
|
|
1295
|
+
level: needed ? "error" : isRuntime ? "ok" : "suggest",
|
|
1296
|
+
subject: t.name,
|
|
1297
|
+
message: needed ? `git is not installed or not on the PATH; ergonex needs it, and does not install it: install git from your system's package manager` : `${t.name} was not found on the PATH; ${t.name === "bun" ? "Bun is the default runtime" : `Node ${MIN_NODE_MAJOR} is the backup runtime`}, and ergonex does not install it: install it to have both`
|
|
1298
|
+
});
|
|
1299
|
+
} else
|
|
1300
|
+
out.push({
|
|
1301
|
+
id: "ergonex/tool",
|
|
1302
|
+
level: "ok",
|
|
1303
|
+
subject: t.name,
|
|
1304
|
+
message: `${t.name} ${t.version}`
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
return out;
|
|
1351
1308
|
}
|
|
1352
|
-
function
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
const statements = [{ predicate: named(RDF_TYPE), objects: [klass] }];
|
|
1361
|
-
for (const [name, f] of Object.entries(fields)) {
|
|
1362
|
-
const objects = valuesIn(own[name]);
|
|
1363
|
-
if (objects.length === 0)
|
|
1364
|
-
continue;
|
|
1365
|
-
statements.push(f.range.words === undefined ? { predicate: f.property, objects } : { predicate: f.property, objects, words: f.range.words });
|
|
1309
|
+
function pathChecks(f) {
|
|
1310
|
+
if (!f.windows)
|
|
1311
|
+
return [
|
|
1312
|
+
{
|
|
1313
|
+
id: "ergonex/path-length",
|
|
1314
|
+
level: "ok",
|
|
1315
|
+
subject: f.home,
|
|
1316
|
+
message: "the 259-character limit of Windows does not apply on this system"
|
|
1366
1317
|
}
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1318
|
+
];
|
|
1319
|
+
const long = f.longPaths === "enabled";
|
|
1320
|
+
const tooLong = f.paths.flatMap((p) => {
|
|
1321
|
+
const native = nativePath(f.home, p, "\\");
|
|
1322
|
+
const r = checkPathLength(native, long);
|
|
1323
|
+
return r.kind === "err" ? [r.error] : [];
|
|
1324
|
+
});
|
|
1325
|
+
const out = tooLong.map((e) => ({
|
|
1326
|
+
id: "ergonex/path-too-long",
|
|
1327
|
+
level: "error",
|
|
1328
|
+
subject: e.path,
|
|
1329
|
+
message: `${e.path} is ${e.length} characters, over the ${WINDOWS_PATH_LIMIT} Windows allows while long paths are off; run \`ergonex setup\` to turn long paths on, or move the root to a shorter path`
|
|
1330
|
+
}));
|
|
1331
|
+
if (!long && tooLong.length === 0)
|
|
1332
|
+
out.push({
|
|
1333
|
+
id: "ergonex/windows-long-paths",
|
|
1334
|
+
level: "suggest",
|
|
1335
|
+
subject: f.home,
|
|
1336
|
+
message: f.longPaths === "unknown" ? "Windows long paths are not known to be enabled (the setting could not be read); no path of the workspace exceeds 259 characters yet; run `ergonex setup` to turn them on" : "Windows long paths not enabled; no path of the workspace exceeds 259 characters yet; run `ergonex setup` to turn them on"
|
|
1337
|
+
});
|
|
1338
|
+
if (long)
|
|
1339
|
+
out.push({
|
|
1340
|
+
id: "ergonex/windows-long-paths",
|
|
1341
|
+
level: "ok",
|
|
1342
|
+
subject: f.home,
|
|
1343
|
+
message: "Windows long paths are enabled"
|
|
1344
|
+
});
|
|
1345
|
+
return out;
|
|
1371
1346
|
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
var ConceptSchema = classSchema(skos.Concept, {
|
|
1399
|
-
inScheme: one(skos.inScheme, range.ref()),
|
|
1400
|
-
notation: one(skos.notation, range.string),
|
|
1401
|
-
prefLabel: one(skos.prefLabel, range.langString),
|
|
1402
|
-
definition: optional(skos.definition, range.langString)
|
|
1403
|
-
});
|
|
1404
|
-
// ../ts/kernel/signals.ts
|
|
1405
|
-
var ATTRIBUTE_TYPES = new Set([
|
|
1406
|
-
"string",
|
|
1407
|
-
"boolean",
|
|
1408
|
-
"int",
|
|
1409
|
-
"double",
|
|
1410
|
-
"bytes",
|
|
1411
|
-
"string[]",
|
|
1412
|
-
"boolean[]",
|
|
1413
|
-
"int[]",
|
|
1414
|
-
"double[]"
|
|
1415
|
-
]);
|
|
1416
|
-
function defineSignals(kinds) {
|
|
1417
|
-
for (const [name, d] of Object.entries(kinds)) {
|
|
1418
|
-
const declared = new Set(Object.keys(d.attributes).map((k) => k.replace(/\?$/, "")));
|
|
1419
|
-
for (const [k, t] of Object.entries(d.attributes)) {
|
|
1420
|
-
if (!ATTRIBUTE_TYPES.has(t))
|
|
1421
|
-
throw new Error(`${name}: the attribute ${k} has the type ${t}, which does not exist`);
|
|
1422
|
-
}
|
|
1423
|
-
for (const s of d.secret ?? [])
|
|
1424
|
-
if (!declared.has(s))
|
|
1425
|
-
throw new Error(`${name}: the secret attribute ${s} is not declared`);
|
|
1426
|
-
if (d.signal === "histogram" && d.bounds !== undefined) {
|
|
1427
|
-
const b = d.bounds;
|
|
1428
|
-
if (b.some((x, i) => !Number.isFinite(x) || i > 0 && x <= (b[i - 1] ?? -Infinity))) {
|
|
1429
|
-
throw new Error(`${name}: the histogram bounds do not increase`);
|
|
1430
|
-
}
|
|
1347
|
+
function repoPathChecks(f) {
|
|
1348
|
+
const out = [];
|
|
1349
|
+
for (const repo of f.repositories) {
|
|
1350
|
+
const native = nativePath(f.home, repo, f.windows ? "\\" : "/");
|
|
1351
|
+
const r = repoPathLength(f.home, repo, f.windows ? "\\" : "/");
|
|
1352
|
+
switch (r.kind) {
|
|
1353
|
+
case "fits":
|
|
1354
|
+
break;
|
|
1355
|
+
case "no-room":
|
|
1356
|
+
out.push({
|
|
1357
|
+
id: "ergonex/repo-path-room",
|
|
1358
|
+
level: "suggest",
|
|
1359
|
+
subject: native,
|
|
1360
|
+
message: `${native} is ${r.length} characters, over ${REPO_PATH_ROOM}: that leaves little room for the files inside the repository; move the root to a shorter path`
|
|
1361
|
+
});
|
|
1362
|
+
break;
|
|
1363
|
+
case "too-long":
|
|
1364
|
+
out.push({
|
|
1365
|
+
id: "ergonex/repo-path-too-long",
|
|
1366
|
+
level: "error",
|
|
1367
|
+
subject: native,
|
|
1368
|
+
message: `${native} is ${r.length} characters, over ${WINDOWS_PATH_LIMIT}, which is too long for a repository whether or not long paths are enabled; move the root to a shorter path or shorten the repository's path in the manifest`
|
|
1369
|
+
});
|
|
1370
|
+
break;
|
|
1371
|
+
default:
|
|
1372
|
+
return absurd(r);
|
|
1431
1373
|
}
|
|
1432
1374
|
}
|
|
1433
|
-
return
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
// ../ts/kernel/width.ts
|
|
1437
|
-
var ESC2 = String.fromCharCode(27);
|
|
1438
|
-
var BEL = String.fromCharCode(7);
|
|
1439
|
-
var ESCAPE = new RegExp(`${ESC2}(?:\\[[0-?]*[ -/]*[@-~]?|[\\]PX^_][^${BEL}${ESC2}]*(?:${BEL}|${ESC2}\\\\)?|[ -/]*[0-~]|)`, "g");
|
|
1440
|
-
var segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
1441
|
-
var SGR = new RegExp(`^${ESC2}\\[([0-9;:]*)m$`);
|
|
1442
|
-
var RESET = `${ESC2}[0m`;
|
|
1443
|
-
|
|
1444
|
-
// ../ts/kernel/render.ts
|
|
1445
|
-
var ESC3 = String.fromCharCode(27);
|
|
1446
|
-
var CONTROL = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(31)}${String.fromCharCode(127)}-${String.fromCharCode(159)}]`, "g");
|
|
1447
|
-
// ../ts/kernel/xml.ts
|
|
1448
|
-
var FORBIDDEN2 = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11, 12)}${String.fromCharCode(14)}-${String.fromCharCode(31)}\\ufffe\\uffff]`, "g");
|
|
1449
|
-
// ../ts/kernel/sigv4.ts
|
|
1450
|
-
var UNSIGNED_HEADERS = new Set(["authorization", "connection", "expect", "user-agent", "x-amzn-trace-id", "traceparent", "tracestate"]);
|
|
1451
|
-
var encoder = new TextEncoder;
|
|
1452
|
-
// ../ts/kernel/test-report.ts
|
|
1453
|
-
var STYLE = "body{font:15px/1.5 system-ui,sans-serif;margin:2rem auto;max-width:72rem;padding:0 1rem;color:#1b1b1b;background:#fff}" + "table{border-collapse:collapse;margin:.5rem 0;width:100%}th,td{border:1px solid #c8c8c8;padding:.25rem .5rem;text-align:left;vertical-align:top;overflow-wrap:anywhere}" + "th{background:#f0f0f0}h1{font-size:1.6rem}h2{font-size:1.2rem;margin-top:2rem}" + "@media (prefers-color-scheme:dark){body{color:#e8e8e8;background:#161616}th{background:#2a2a2a}th,td{border-color:#444}}";
|
|
1454
|
-
// ../ts/kernel/toml.ts
|
|
1455
|
-
var CONTROL2 = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(8, 10)}-${String.fromCharCode(31, 127)}]`);
|
|
1456
|
-
// ../ts/kernel/webauthn.ts
|
|
1457
|
-
var clientData = object({ type: string, challenge: string, origin: string }, { crossOrigin: boolean, topOrigin: string });
|
|
1458
|
-
var kind = literal("public-key");
|
|
1459
|
-
var extensionResults = record(unknownValue);
|
|
1460
|
-
// src/portable.ts
|
|
1461
|
-
function describePortableError(e) {
|
|
1462
|
-
switch (e.kind) {
|
|
1463
|
-
case "empty":
|
|
1464
|
-
return "a path segment is empty";
|
|
1465
|
-
case "dot":
|
|
1466
|
-
return `the path segment ${JSON.stringify(e.segment)} would leave its folder`;
|
|
1467
|
-
case "forbidden-character":
|
|
1468
|
-
return `the path segment ${JSON.stringify(e.segment)} holds ${JSON.stringify(e.character)}, which Windows does not allow in a name`;
|
|
1469
|
-
case "control-character":
|
|
1470
|
-
return `the path segment ${JSON.stringify(e.segment)} holds a control character`;
|
|
1471
|
-
case "trailing-dot-or-space":
|
|
1472
|
-
return `the path segment ${JSON.stringify(e.segment)} ends in a dot or a space, which Windows drops`;
|
|
1473
|
-
case "device-name":
|
|
1474
|
-
return `the path segment ${JSON.stringify(e.segment)} is the Windows device name ${e.device}, with or without an extension, in any case`;
|
|
1475
|
-
case "too-long":
|
|
1476
|
-
return `the path segment is ${e.bytes} bytes in UTF-8, and a name may have 255`;
|
|
1477
|
-
case "not-nfc":
|
|
1478
|
-
return `the path segment ${JSON.stringify(e.segment)} is not in Unicode normalization form NFC, so it would be another name on macOS`;
|
|
1479
|
-
default:
|
|
1480
|
-
return absurd(e);
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
var FORBIDDEN3 = new Set(["<", ">", ":", '"', "/", "\\", "|", "?", "*"]);
|
|
1484
|
-
var DEVICE = /^(?:CON|PRN|AUX|NUL|CONIN\$|CONOUT\$|COM[0-9\u00b9\u00b2\u00b3]|LPT[0-9\u00b9\u00b2\u00b3])$/i;
|
|
1485
|
-
function isDeviceName(name) {
|
|
1486
|
-
return DEVICE.test((name.split(".")[0] ?? "").replace(/ +$/, ""));
|
|
1375
|
+
return out;
|
|
1487
1376
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
}
|
|
1501
|
-
if (text.endsWith(".") || text.endsWith(" "))
|
|
1502
|
-
return err({ kind: "trailing-dot-or-space", segment: text });
|
|
1503
|
-
const stem = (text.split(".")[0] ?? "").replace(/ +$/, "");
|
|
1504
|
-
if (isDeviceName(text))
|
|
1505
|
-
return err({
|
|
1506
|
-
kind: "device-name",
|
|
1507
|
-
segment: text,
|
|
1508
|
-
device: stem.toUpperCase()
|
|
1509
|
-
});
|
|
1510
|
-
const bytes = new TextEncoder().encode(text).length;
|
|
1511
|
-
if (bytes > MAX_SEGMENT_BYTES)
|
|
1512
|
-
return err({ kind: "too-long", segment: text.slice(0, 40), bytes });
|
|
1513
|
-
if (text !== text.normalize("NFC"))
|
|
1514
|
-
return err({ kind: "not-nfc", segment: text });
|
|
1515
|
-
return ok(text);
|
|
1377
|
+
function hookChecks(facts, wantedHooksPath) {
|
|
1378
|
+
return facts.filter((f) => f.present).map((f) => f.hooksPath === wantedHooksPath ? {
|
|
1379
|
+
id: "ergonex/hooks",
|
|
1380
|
+
level: "ok",
|
|
1381
|
+
subject: f.repo,
|
|
1382
|
+
message: "the workspace's hooks are set"
|
|
1383
|
+
} : {
|
|
1384
|
+
id: "ergonex/hooks",
|
|
1385
|
+
level: "warn",
|
|
1386
|
+
subject: f.repo,
|
|
1387
|
+
message: f.hooksPath === undefined ? `${f.repo} does not use the workspace's hooks (core.hooksPath is not set in its local configuration); run \`ergonex apply\`` : `${f.repo} uses other hooks than the workspace's (its core.hooksPath is elsewhere); run \`ergonex apply\` to replace it`
|
|
1388
|
+
});
|
|
1516
1389
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
return
|
|
1525
|
-
|
|
1390
|
+
// src/findings.ts
|
|
1391
|
+
var SEVERITIES2 = ["Informational", "Warning", "Error"];
|
|
1392
|
+
function sarifLevel(severity) {
|
|
1393
|
+
switch (severity) {
|
|
1394
|
+
case "Informational":
|
|
1395
|
+
return "note";
|
|
1396
|
+
case "Warning":
|
|
1397
|
+
return "warning";
|
|
1398
|
+
case "Error":
|
|
1399
|
+
return "error";
|
|
1400
|
+
default:
|
|
1401
|
+
return absurd(severity);
|
|
1526
1402
|
}
|
|
1527
|
-
return ok(made.join("/"));
|
|
1528
1403
|
}
|
|
1529
|
-
function
|
|
1530
|
-
|
|
1404
|
+
function worst(findings) {
|
|
1405
|
+
let top;
|
|
1406
|
+
for (const f of findings)
|
|
1407
|
+
if (top === undefined || SEVERITIES2.indexOf(f.severity) > SEVERITIES2.indexOf(top))
|
|
1408
|
+
top = f.severity;
|
|
1409
|
+
return top;
|
|
1531
1410
|
}
|
|
1532
|
-
function
|
|
1533
|
-
|
|
1411
|
+
function exitStatusOf(findings) {
|
|
1412
|
+
const top = worst(findings);
|
|
1413
|
+
return top === "Warning" || top === "Error" ? "Findings" : "Ok";
|
|
1534
1414
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1415
|
+
var DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1416
|
+
function dayNumber(day) {
|
|
1417
|
+
const m = DAY.exec(day);
|
|
1418
|
+
if (m === null)
|
|
1419
|
+
return;
|
|
1420
|
+
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
1421
|
+
const ms = Date.UTC(y, mo - 1, d);
|
|
1422
|
+
const back = new Date(ms);
|
|
1423
|
+
if (back.getUTCFullYear() !== y || back.getUTCMonth() !== mo - 1 || back.getUTCDate() !== d)
|
|
1424
|
+
return;
|
|
1425
|
+
return Math.round(ms / 86400000);
|
|
1538
1426
|
}
|
|
1539
|
-
function
|
|
1540
|
-
|
|
1427
|
+
function daysBetween(from, to) {
|
|
1428
|
+
const a = dayNumber(from);
|
|
1429
|
+
const b = dayNumber(to);
|
|
1430
|
+
if (a === undefined)
|
|
1431
|
+
return err(`${JSON.stringify(from)} is not a day (YYYY-MM-DD)`);
|
|
1432
|
+
if (b === undefined)
|
|
1433
|
+
return err(`${JSON.stringify(to)} is not a day (YYYY-MM-DD)`);
|
|
1434
|
+
return ok(b - a);
|
|
1541
1435
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
const group = groups.get(key);
|
|
1547
|
-
if (group === undefined)
|
|
1548
|
-
groups.set(key, [{ ...item }]);
|
|
1549
|
-
else
|
|
1550
|
-
group.push({ ...item });
|
|
1551
|
-
}
|
|
1552
|
-
return [...groups.entries()].filter(([, members]) => members.length > 1).map(([key, members]) => ({ key, members }));
|
|
1436
|
+
var UNAPPROVED_GRACE_DAYS = 90;
|
|
1437
|
+
function unapprovedSeverity(firstSeen, today, graceDays = UNAPPROVED_GRACE_DAYS) {
|
|
1438
|
+
const age = daysBetween(firstSeen, today);
|
|
1439
|
+
return age.kind === "ok" && age.value > graceDays ? "Warning" : "Informational";
|
|
1553
1440
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
return ok(windowsPath);
|
|
1558
|
-
return err({
|
|
1559
|
-
kind: "path-too-long",
|
|
1560
|
-
path: windowsPath,
|
|
1561
|
-
length: windowsPath.length,
|
|
1562
|
-
limit: WINDOWS_PATH_LIMIT
|
|
1563
|
-
});
|
|
1441
|
+
function firstSeenOf(previous, key, today) {
|
|
1442
|
+
const before = Object.hasOwn(previous, key) ? previous[key] : undefined;
|
|
1443
|
+
return before !== undefined && dayNumber(before) !== undefined ? before : today;
|
|
1564
1444
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1445
|
+
function toSarif(findings, tool = "ergonex") {
|
|
1446
|
+
const rules = [...new Set(findings.map((f) => f.ruleId))].sort().map((id) => ({ id }));
|
|
1447
|
+
return {
|
|
1448
|
+
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
1449
|
+
version: "2.1.0",
|
|
1450
|
+
runs: [
|
|
1451
|
+
{
|
|
1452
|
+
tool: {
|
|
1453
|
+
driver: {
|
|
1454
|
+
name: tool,
|
|
1455
|
+
informationUri: "https://intellectual-frontiers.github.io/.github/",
|
|
1456
|
+
rules
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
results: findings.map((f) => ({
|
|
1460
|
+
ruleId: f.ruleId,
|
|
1461
|
+
level: sarifLevel(f.severity),
|
|
1462
|
+
message: { text: f.message },
|
|
1463
|
+
locations: [{ logicalLocations: [{ name: f.subject }] }],
|
|
1464
|
+
properties: { firstSeen: f.firstSeen }
|
|
1465
|
+
}))
|
|
1466
|
+
}
|
|
1467
|
+
]
|
|
1468
|
+
};
|
|
1573
1469
|
}
|
|
1574
1470
|
|
|
1575
|
-
// src/
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
var
|
|
1593
|
-
|
|
1594
|
-
|
|
1471
|
+
// src/state-record.ts
|
|
1472
|
+
var ERGONEX_VERSION = "0.3.1";
|
|
1473
|
+
var STATE_RECORD_PATH = ".ergonex/state.auto.json";
|
|
1474
|
+
var EMPTY_RECORD = {
|
|
1475
|
+
ergonex: ERGONEX_VERSION,
|
|
1476
|
+
files: {},
|
|
1477
|
+
firstSeen: {}
|
|
1478
|
+
};
|
|
1479
|
+
var hash = (input, path = "$") => {
|
|
1480
|
+
const s = typeof input === "string" ? sha256Of(input) : undefined;
|
|
1481
|
+
return s === undefined ? err({
|
|
1482
|
+
kind: "decode",
|
|
1483
|
+
path,
|
|
1484
|
+
expected: "a SHA-256 (64 hexadecimal digits)",
|
|
1485
|
+
found: typeof input
|
|
1486
|
+
}) : ok(s);
|
|
1487
|
+
};
|
|
1488
|
+
var day = (input, path = "$") => typeof input === "string" && dayNumber(input) !== undefined ? ok(input) : err({
|
|
1489
|
+
kind: "decode",
|
|
1490
|
+
path,
|
|
1491
|
+
expected: "a day (YYYY-MM-DD)",
|
|
1492
|
+
found: typeof input
|
|
1493
|
+
});
|
|
1494
|
+
var shape = object({
|
|
1495
|
+
ergonex: string,
|
|
1496
|
+
files: record(object({ sha256: hash, generator: string })),
|
|
1497
|
+
firstSeen: record(day)
|
|
1498
|
+
}, { plan: hash });
|
|
1499
|
+
function decodeStateRecord(text) {
|
|
1500
|
+
const r = json(text, shape);
|
|
1501
|
+
return r.kind === "ok" ? ok(r.value) : err(formatDecodeError(r.error));
|
|
1595
1502
|
}
|
|
1596
|
-
function
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1503
|
+
function encodeStateRecord(r) {
|
|
1504
|
+
const sorted = (o) => Object.fromEntries(Object.entries(o).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
1505
|
+
const value = {
|
|
1506
|
+
_generated: headerText("ergonex state"),
|
|
1507
|
+
ergonex: r.ergonex,
|
|
1508
|
+
...r.plan === undefined ? {} : { plan: r.plan },
|
|
1509
|
+
files: sorted(r.files),
|
|
1510
|
+
firstSeen: sorted(r.firstSeen)
|
|
1511
|
+
};
|
|
1512
|
+
return `${JSON.stringify(value, null, 2)}
|
|
1602
1513
|
`;
|
|
1603
1514
|
}
|
|
1604
|
-
function
|
|
1605
|
-
return
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
return err({
|
|
1611
|
-
kind: "bad-path",
|
|
1612
|
-
path,
|
|
1613
|
-
reason: describePortableError(made.error)
|
|
1614
|
-
});
|
|
1615
|
-
return made;
|
|
1616
|
-
}
|
|
1617
|
-
var noBom = (text) => text.replace(/^\uFEFF/, "");
|
|
1618
|
-
function contentOf(body, generator) {
|
|
1619
|
-
const header = headerText(generator);
|
|
1620
|
-
switch (body.format) {
|
|
1621
|
-
case "json":
|
|
1622
|
-
return normalizeText(JSON.stringify({ _generated: header, ...body.value }, null, 2));
|
|
1623
|
-
case "markdown":
|
|
1624
|
-
return normalizeText(`<!-- ${header} -->
|
|
1625
|
-
|
|
1626
|
-
${noBom(body.text)}`);
|
|
1627
|
-
case "yaml":
|
|
1628
|
-
case "gitconfig":
|
|
1629
|
-
case "envrc":
|
|
1630
|
-
return normalizeText(`# ${header}
|
|
1631
|
-
|
|
1632
|
-
${noBom(body.text)}`);
|
|
1633
|
-
case "sh": {
|
|
1634
|
-
const text = noBom(body.text);
|
|
1635
|
-
const m = /^(#![^\n]*)\n/.exec(text);
|
|
1636
|
-
return m === null ? normalizeText(`# ${header}
|
|
1637
|
-
${text}`) : normalizeText(`${m[1]}
|
|
1638
|
-
# ${header}
|
|
1639
|
-
${text.slice(m[0].length)}`);
|
|
1515
|
+
function withFile(r, file, digest) {
|
|
1516
|
+
return {
|
|
1517
|
+
...r,
|
|
1518
|
+
files: {
|
|
1519
|
+
...r.files,
|
|
1520
|
+
[file.path]: { sha256: digest, generator: file.generator }
|
|
1640
1521
|
}
|
|
1641
|
-
|
|
1642
|
-
return absurd(body);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
function generated(path, body, options) {
|
|
1646
|
-
const made = generatedPath(path);
|
|
1647
|
-
if (made.kind === "err")
|
|
1648
|
-
return made;
|
|
1649
|
-
const name = made.value.split("/").at(-1) ?? "";
|
|
1650
|
-
const isHook = made.value.startsWith(`${HOOKS_FOLDER}/`) && made.value.split("/").length === 3;
|
|
1651
|
-
if (!isAutoName(name) && !isHook)
|
|
1652
|
-
return err({ kind: "not-auto", path });
|
|
1653
|
-
return ok({
|
|
1654
|
-
path: made.value,
|
|
1655
|
-
content: contentOf(body, options.generator),
|
|
1656
|
-
mode: options.mode ?? "0644",
|
|
1657
|
-
generator: options.generator
|
|
1658
|
-
});
|
|
1522
|
+
};
|
|
1659
1523
|
}
|
|
1660
|
-
function
|
|
1661
|
-
return
|
|
1524
|
+
function withoutFile(r, path) {
|
|
1525
|
+
return {
|
|
1526
|
+
...r,
|
|
1527
|
+
files: Object.fromEntries(Object.entries(r.files).filter(([p]) => p !== path))
|
|
1528
|
+
};
|
|
1662
1529
|
}
|
|
1663
|
-
function
|
|
1664
|
-
const
|
|
1665
|
-
for (const
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1530
|
+
function verifyFindings(facts, today) {
|
|
1531
|
+
const out = [];
|
|
1532
|
+
for (const f of facts) {
|
|
1533
|
+
const at = (ruleId, severity, message) => void out.push({
|
|
1534
|
+
ruleId,
|
|
1535
|
+
severity,
|
|
1536
|
+
message,
|
|
1537
|
+
subject: f.path,
|
|
1538
|
+
firstSeen: today
|
|
1539
|
+
});
|
|
1540
|
+
if (f.recorded !== undefined && f.onDisk === undefined) {
|
|
1541
|
+
at("ergonex/generated-missing", "Warning", `${f.path} is recorded as written and is not there; run \`ergonex render\` to write it again`);
|
|
1542
|
+
} else if (f.recorded !== undefined && f.onDisk !== undefined && f.onDisk !== f.recorded) {
|
|
1543
|
+
at("ergonex/generated-edited", "Error", `${f.path} was edited by hand (its bytes are not the ones recorded); \`ergonex render --force\` replaces it`);
|
|
1544
|
+
} else if (f.recorded === undefined && f.onDisk !== undefined) {
|
|
1545
|
+
at("ergonex/generated-unrecorded", "Warning", `${f.path} is a generated file the state record does not hold; run \`ergonex render\` to record it, or remove it`);
|
|
1673
1546
|
}
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
if (inside !== undefined)
|
|
1679
|
-
errors.push({
|
|
1680
|
-
kind: "inside-repository",
|
|
1681
|
-
path: f.path,
|
|
1682
|
-
repository: inside
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
if (errors.length > 0)
|
|
1686
|
-
return err(errors);
|
|
1687
|
-
return ok([...files].sort((a, b) => foldKey(a.path) < foldKey(b.path) ? -1 : foldKey(a.path) > foldKey(b.path) ? 1 : 0));
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
// src/desired.ts
|
|
1691
|
-
function settingsOf(manifest, facts) {
|
|
1692
|
-
const settings = {
|
|
1693
|
-
"core.hooksPath": `${facts.homePosix.replace(/\/+$/, "")}/.ergonex/hooks`
|
|
1694
|
-
};
|
|
1695
|
-
if (manifest.policy.requiresSignedCommits) {
|
|
1696
|
-
settings["commit.gpgsign"] = "true";
|
|
1697
|
-
if (manifest.signing !== undefined) {
|
|
1698
|
-
settings["gpg.format"] = manifest.signing.format;
|
|
1699
|
-
if (manifest.signing.key !== undefined)
|
|
1700
|
-
settings["user.signingkey"] = manifest.signing.key;
|
|
1547
|
+
const edited = f.recorded !== undefined && f.onDisk !== undefined && f.onDisk !== f.recorded;
|
|
1548
|
+
const missing = f.recorded !== undefined && f.onDisk === undefined;
|
|
1549
|
+
if (f.wanted !== undefined && f.onDisk !== f.wanted && !edited && !missing) {
|
|
1550
|
+
at("ergonex/generated-drift", "Warning", f.onDisk === undefined ? `${f.path} is not written yet; run \`ergonex render\`` : `${f.path} would be written differently by the templates now; run \`ergonex render\``);
|
|
1701
1551
|
}
|
|
1702
1552
|
}
|
|
1703
|
-
if (manifest.identity !== undefined) {
|
|
1704
|
-
settings["user.name"] = manifest.identity.name;
|
|
1705
|
-
settings["user.email"] = manifest.identity.email;
|
|
1706
|
-
}
|
|
1707
|
-
if (facts.windows)
|
|
1708
|
-
settings["core.longpaths"] = "true";
|
|
1709
|
-
return settings;
|
|
1710
|
-
}
|
|
1711
|
-
async function desiredOf(manifest, files, facts) {
|
|
1712
|
-
const settings = settingsOf(manifest, facts);
|
|
1713
|
-
const repos = manifest.repositories.map((r) => ({
|
|
1714
|
-
path: r.path,
|
|
1715
|
-
ref: r.ref,
|
|
1716
|
-
cloneUrl: r.cloneUrl,
|
|
1717
|
-
branch: r.branch,
|
|
1718
|
-
settings
|
|
1719
|
-
}));
|
|
1720
|
-
const worktrees = manifest.repositories.flatMap((r) => r.worktrees.map((w) => ({ path: w.path, repo: r.path, branch: w.branch })));
|
|
1721
|
-
const desiredFiles = [];
|
|
1722
|
-
for (const f of files)
|
|
1723
|
-
desiredFiles.push({ path: f.path, sha256: await fileDigest(f) });
|
|
1724
|
-
return { repos, worktrees, files: desiredFiles, hostChanges: [] };
|
|
1725
|
-
}
|
|
1726
|
-
async function digestsOf(files) {
|
|
1727
|
-
const out = new Map;
|
|
1728
|
-
for (const f of files)
|
|
1729
|
-
out.set(f.path, await fileDigest(f));
|
|
1730
1553
|
return out;
|
|
1731
1554
|
}
|
|
1732
|
-
// src/
|
|
1733
|
-
function
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
return "Error";
|
|
1743
|
-
default:
|
|
1744
|
-
return absurd(level);
|
|
1745
|
-
}
|
|
1555
|
+
// ../terminal/src/args.ts
|
|
1556
|
+
function flag(o) {
|
|
1557
|
+
const negatable = o.negatable === true;
|
|
1558
|
+
return {
|
|
1559
|
+
kind: "flag",
|
|
1560
|
+
short: o.short,
|
|
1561
|
+
help: o.help,
|
|
1562
|
+
negatable,
|
|
1563
|
+
fallback: negatable && o.default === undefined ? { kind: "none" } : { kind: "default", value: o.default ?? false }
|
|
1564
|
+
};
|
|
1746
1565
|
}
|
|
1747
|
-
function
|
|
1748
|
-
return
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
firstSeen: today
|
|
1757
|
-
}
|
|
1758
|
-
];
|
|
1759
|
-
});
|
|
1566
|
+
function value(o) {
|
|
1567
|
+
return {
|
|
1568
|
+
kind: "value",
|
|
1569
|
+
short: o.short,
|
|
1570
|
+
help: o.help,
|
|
1571
|
+
valueName: o.valueName ?? "VALUE",
|
|
1572
|
+
parse: o.parse ?? text,
|
|
1573
|
+
fallback: o.required === true ? { kind: "required" } : ("default" in o) ? { kind: "default", value: o.default } : { kind: "none" }
|
|
1574
|
+
};
|
|
1760
1575
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
"smb2",
|
|
1776
|
-
"smb3",
|
|
1777
|
-
"smbfs",
|
|
1778
|
-
"afpfs",
|
|
1779
|
-
"9p",
|
|
1780
|
-
"v9fs",
|
|
1781
|
-
"sshfs",
|
|
1782
|
-
"fuse.sshfs",
|
|
1783
|
-
"webdav",
|
|
1784
|
-
"ncpfs",
|
|
1785
|
-
"fuse.rclone"
|
|
1786
|
-
].includes(t))
|
|
1787
|
-
return "network";
|
|
1788
|
-
return "ok";
|
|
1576
|
+
var text = (t) => ok(t);
|
|
1577
|
+
function longName(key) {
|
|
1578
|
+
return `--${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`;
|
|
1579
|
+
}
|
|
1580
|
+
function editDistance(a, b) {
|
|
1581
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
1582
|
+
for (let i = 1;i <= a.length; i++) {
|
|
1583
|
+
const row = [i];
|
|
1584
|
+
for (let j = 1;j <= b.length; j++) {
|
|
1585
|
+
row.push(Math.min((prev[j] ?? 0) + 1, (row[j - 1] ?? 0) + 1, (prev[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1)));
|
|
1586
|
+
}
|
|
1587
|
+
prev = row;
|
|
1588
|
+
}
|
|
1589
|
+
return prev[b.length] ?? 0;
|
|
1789
1590
|
}
|
|
1790
|
-
function
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
const at = (level, message) => ({
|
|
1800
|
-
id: "ergonex/filesystem",
|
|
1801
|
-
level,
|
|
1802
|
-
subject: home,
|
|
1803
|
-
message
|
|
1804
|
-
});
|
|
1805
|
-
switch (kind) {
|
|
1806
|
-
case "ok":
|
|
1807
|
-
return at("ok", `the root is on a file system of type ${probe.type}`);
|
|
1808
|
-
case "fat":
|
|
1809
|
-
return at("warn", `the root is on a FAT file system (${probe.type}): it has no execute bit and a two-second time resolution, so hooks may not run; move the root to NTFS, APFS or ext4`);
|
|
1810
|
-
case "exfat":
|
|
1811
|
-
return at("warn", "the root is on an exFAT file system: it has no execute bit and a two-second time resolution, so hooks may not run; move the root to NTFS, APFS or ext4");
|
|
1812
|
-
case "network":
|
|
1813
|
-
return at("warn", `the root is on a network share (${probe.type}): its locks are not reliable, so two runs may write at once; move the root to a local disk`);
|
|
1814
|
-
case "wsl-windows-drive":
|
|
1815
|
-
return at("warn", "the root is on a Windows drive seen from WSL (/mnt/c): it is slow and case-insensitive; keep the root in the Linux file system, or run ergonex from Windows");
|
|
1816
|
-
default:
|
|
1817
|
-
return absurd(kind);
|
|
1591
|
+
function suggest(word, candidates) {
|
|
1592
|
+
let best;
|
|
1593
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
1594
|
+
for (const c of candidates) {
|
|
1595
|
+
const d = editDistance(word, c);
|
|
1596
|
+
if (d < bestDistance) {
|
|
1597
|
+
best = c;
|
|
1598
|
+
bestDistance = d;
|
|
1599
|
+
}
|
|
1818
1600
|
}
|
|
1601
|
+
return bestDistance <= Math.max(2, Math.floor(word.length / 2)) ? best : undefined;
|
|
1819
1602
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
id: "ergonex/runtime",
|
|
1834
|
-
level: "ok",
|
|
1835
|
-
subject: runtime.name,
|
|
1836
|
-
message: `running on ${runtime.name} ${runtime.version}`
|
|
1837
|
-
});
|
|
1838
|
-
for (const t of tools) {
|
|
1839
|
-
if (t.version === undefined) {
|
|
1840
|
-
const needed = t.name === "git";
|
|
1841
|
-
const isRuntime = t.name === runtime.name;
|
|
1842
|
-
out.push({
|
|
1843
|
-
id: "ergonex/tool",
|
|
1844
|
-
level: needed ? "error" : isRuntime ? "ok" : "suggest",
|
|
1845
|
-
subject: t.name,
|
|
1846
|
-
message: needed ? `git is not installed or not on the PATH; ergonex needs it, and does not install it: install git from your system's package manager` : `${t.name} was not found on the PATH; ${t.name === "bun" ? "Bun is the default runtime" : `Node ${MIN_NODE_MAJOR} is the backup runtime`}, and ergonex does not install it: install it to have both`
|
|
1847
|
-
});
|
|
1848
|
-
} else
|
|
1849
|
-
out.push({
|
|
1850
|
-
id: "ergonex/tool",
|
|
1851
|
-
level: "ok",
|
|
1852
|
-
subject: t.name,
|
|
1853
|
-
message: `${t.name} ${t.version}`
|
|
1854
|
-
});
|
|
1603
|
+
function asksHelp(word) {
|
|
1604
|
+
return word === "--help" || /^-[A-Za-z]*h[A-Za-z]*$/.test(word);
|
|
1605
|
+
}
|
|
1606
|
+
function operandWord(o) {
|
|
1607
|
+
switch (o.arity) {
|
|
1608
|
+
case "one":
|
|
1609
|
+
return o.name;
|
|
1610
|
+
case "optional":
|
|
1611
|
+
return `[${o.name}]`;
|
|
1612
|
+
case "many":
|
|
1613
|
+
return `[${o.name}...]`;
|
|
1614
|
+
default:
|
|
1615
|
+
return absurd(o.arity);
|
|
1855
1616
|
}
|
|
1856
|
-
return out;
|
|
1857
1617
|
}
|
|
1858
|
-
function
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
message: "the 259-character limit of Windows does not apply on this system"
|
|
1866
|
-
}
|
|
1867
|
-
];
|
|
1868
|
-
const long = f.longPaths === "enabled";
|
|
1869
|
-
const tooLong = f.paths.flatMap((p) => {
|
|
1870
|
-
const native = nativePath(f.home, p, "\\");
|
|
1871
|
-
const r = checkPathLength(native, long);
|
|
1872
|
-
return r.kind === "err" ? [r.error] : [];
|
|
1618
|
+
function parseArgs(argv, spec, operands = []) {
|
|
1619
|
+
const end = argv.indexOf("--");
|
|
1620
|
+
if ((end < 0 ? argv : argv.slice(0, end)).some(asksHelp))
|
|
1621
|
+
return ok({ kind: "help" });
|
|
1622
|
+
const entries = Object.keys(spec).flatMap((key) => {
|
|
1623
|
+
const option = spec[key];
|
|
1624
|
+
return option === undefined ? [] : [{ key, long: longName(key), option }];
|
|
1873
1625
|
});
|
|
1874
|
-
const
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1626
|
+
const longs = [
|
|
1627
|
+
...entries.flatMap((e) => e.option.kind === "flag" && e.option.negatable ? [e.long, `--no-${e.long.slice(2)}`] : [e.long]),
|
|
1628
|
+
"--help"
|
|
1629
|
+
];
|
|
1630
|
+
const given = new Map;
|
|
1631
|
+
const listed = new Map;
|
|
1632
|
+
const positionals = [];
|
|
1633
|
+
let rest = [];
|
|
1634
|
+
let i = 0;
|
|
1635
|
+
const take = (e, written, inline, negated) => {
|
|
1636
|
+
const o = e.option;
|
|
1637
|
+
if (o.kind !== "many" && given.has(e.key))
|
|
1638
|
+
return { kind: "repeated-option", option: e.long };
|
|
1639
|
+
if (o.kind === "flag") {
|
|
1640
|
+
if (inline !== undefined)
|
|
1641
|
+
return { kind: "unexpected-value", option: written, value: inline };
|
|
1642
|
+
given.set(e.key, !negated);
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
const t = inline ?? argv[++i];
|
|
1646
|
+
if (t === undefined)
|
|
1647
|
+
return { kind: "missing-value", option: written };
|
|
1648
|
+
const parsed = o.parse(t);
|
|
1649
|
+
if (parsed.kind === "err") {
|
|
1650
|
+
const reason = typeof parsed.error === "string" ? parsed.error : `expected ${parsed.error.expected}, found ${parsed.error.found}`;
|
|
1651
|
+
return { kind: "invalid-value", option: written, value: t, reason };
|
|
1652
|
+
}
|
|
1653
|
+
if (o.kind === "value")
|
|
1654
|
+
given.set(e.key, parsed.value);
|
|
1655
|
+
else
|
|
1656
|
+
listed.set(e.key, [...listed.get(e.key) ?? [], parsed.value]);
|
|
1657
|
+
return;
|
|
1658
|
+
};
|
|
1659
|
+
for (;i < argv.length; i++) {
|
|
1660
|
+
const word = argv[i] ?? "";
|
|
1661
|
+
if (word === "--") {
|
|
1662
|
+
rest = argv.slice(i + 1);
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
if (word.startsWith("--")) {
|
|
1666
|
+
const eq = word.indexOf("=");
|
|
1667
|
+
const name = eq < 0 ? word : word.slice(0, eq);
|
|
1668
|
+
const inline = eq < 0 ? undefined : word.slice(eq + 1);
|
|
1669
|
+
if (name === "--help")
|
|
1670
|
+
return err({ kind: "unexpected-value", option: name, value: inline ?? "" });
|
|
1671
|
+
const direct = entries.find((e) => e.long === name);
|
|
1672
|
+
const positive = name.startsWith("--no-") ? entries.find((e) => e.long === `--${name.slice(5)}`) : undefined;
|
|
1673
|
+
const negated = direct === undefined && positive !== undefined && positive.option.kind === "flag" && positive.option.negatable;
|
|
1674
|
+
const e = direct ?? (negated ? positive : undefined);
|
|
1675
|
+
if (e === undefined)
|
|
1676
|
+
return err({ kind: "unknown-option", option: name, suggestion: suggest(name, longs) });
|
|
1677
|
+
const problem = take(e, name, inline, negated);
|
|
1678
|
+
if (problem !== undefined)
|
|
1679
|
+
return err(problem);
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
if (word.length < 2 || !word.startsWith("-") || /^-[0-9]/.test(word)) {
|
|
1683
|
+
positionals.push(word);
|
|
1684
|
+
continue;
|
|
1685
|
+
}
|
|
1686
|
+
for (let j = 1;j < word.length; j++) {
|
|
1687
|
+
const letter = word.charAt(j);
|
|
1688
|
+
const written = `-${letter}`;
|
|
1689
|
+
const e = entries.find((x) => x.option.short === letter);
|
|
1690
|
+
if (e === undefined)
|
|
1691
|
+
return err({ kind: "unknown-option", option: written, suggestion: suggest(`-${word}`, longs) });
|
|
1692
|
+
const after = word.slice(j + 1);
|
|
1693
|
+
if (e.option.kind === "flag") {
|
|
1694
|
+
if (after.startsWith("="))
|
|
1695
|
+
return err({ kind: "unexpected-value", option: written, value: after.slice(1) });
|
|
1696
|
+
} else if (after !== "") {
|
|
1697
|
+
return err({ kind: "attached-value", option: written, word });
|
|
1698
|
+
}
|
|
1699
|
+
const problem = take(e, written, undefined, false);
|
|
1700
|
+
if (problem !== undefined)
|
|
1701
|
+
return err(problem);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
const values = [];
|
|
1705
|
+
for (const e of entries) {
|
|
1706
|
+
const o = e.option;
|
|
1707
|
+
switch (o.kind) {
|
|
1708
|
+
case "many":
|
|
1709
|
+
values.push([e.key, listed.get(e.key) ?? []]);
|
|
1911
1710
|
break;
|
|
1912
|
-
case "
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1711
|
+
case "flag":
|
|
1712
|
+
case "value": {
|
|
1713
|
+
if (given.has(e.key)) {
|
|
1714
|
+
values.push([e.key, given.get(e.key)]);
|
|
1715
|
+
break;
|
|
1716
|
+
}
|
|
1717
|
+
const f = o.fallback;
|
|
1718
|
+
switch (f.kind) {
|
|
1719
|
+
case "none":
|
|
1720
|
+
values.push([e.key, undefined]);
|
|
1721
|
+
break;
|
|
1722
|
+
case "default":
|
|
1723
|
+
values.push([e.key, f.value]);
|
|
1724
|
+
break;
|
|
1725
|
+
case "required":
|
|
1726
|
+
return err({ kind: "missing-option", option: e.long });
|
|
1727
|
+
default:
|
|
1728
|
+
return absurd(f);
|
|
1729
|
+
}
|
|
1919
1730
|
break;
|
|
1731
|
+
}
|
|
1920
1732
|
default:
|
|
1921
|
-
return absurd(
|
|
1733
|
+
return absurd(o);
|
|
1922
1734
|
}
|
|
1923
1735
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
level: "warn",
|
|
1935
|
-
subject: f.repo,
|
|
1936
|
-
message: f.hooksPath === undefined ? `${f.repo} does not use the workspace's hooks (core.hooksPath is not set in its local configuration); run \`ergonex apply\`` : `${f.repo} uses other hooks than the workspace's (its core.hooksPath is elsewhere); run \`ergonex apply\` to replace it`
|
|
1937
|
-
});
|
|
1736
|
+
const least = operands.filter((o) => o.arity === "one");
|
|
1737
|
+
const most = operands.some((o) => o.arity === "many") ? Number.POSITIVE_INFINITY : operands.filter((o) => o.arity !== "many").length;
|
|
1738
|
+
const missing = least[positionals.length];
|
|
1739
|
+
if (missing !== undefined)
|
|
1740
|
+
return err({ kind: "missing-argument", argument: missing.name });
|
|
1741
|
+
const extra = positionals[most];
|
|
1742
|
+
if (extra !== undefined)
|
|
1743
|
+
return err({ kind: "unexpected-argument", argument: extra, takes: operands.map(operandWord) });
|
|
1744
|
+
const options = Object.fromEntries(values);
|
|
1745
|
+
return ok({ kind: "args", options, positionals, rest });
|
|
1938
1746
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
case "
|
|
1944
|
-
return
|
|
1945
|
-
case "
|
|
1946
|
-
return
|
|
1947
|
-
case "
|
|
1948
|
-
return
|
|
1747
|
+
function formatUsageError(e, command = "this command") {
|
|
1748
|
+
switch (e.kind) {
|
|
1749
|
+
case "unknown-option":
|
|
1750
|
+
return `${e.option} is not an option of ${command}${e.suggestion === undefined ? "" : `; did you mean ${e.suggestion}?`}`;
|
|
1751
|
+
case "missing-value":
|
|
1752
|
+
return `${e.option} needs a value`;
|
|
1753
|
+
case "unexpected-value":
|
|
1754
|
+
return `${e.option} takes no value, but was given ${JSON.stringify(e.value)}`;
|
|
1755
|
+
case "attached-value":
|
|
1756
|
+
return `${e.option} takes its value as the next word, not attached as in ${e.word}`;
|
|
1757
|
+
case "invalid-value":
|
|
1758
|
+
return `${JSON.stringify(e.value)} is not a valid value of ${e.option}: ${e.reason}`;
|
|
1759
|
+
case "repeated-option":
|
|
1760
|
+
return `${e.option} is given more than once`;
|
|
1761
|
+
case "missing-option":
|
|
1762
|
+
return `${e.option} is required`;
|
|
1763
|
+
case "missing-argument":
|
|
1764
|
+
return `${command} needs ${e.argument}`;
|
|
1765
|
+
case "unexpected-argument":
|
|
1766
|
+
return `${command} does not take ${e.argument}: ${e.takes.length === 0 ? "it takes no arguments" : `it takes ${e.takes.join(" ")}`}`;
|
|
1949
1767
|
default:
|
|
1950
|
-
return absurd(
|
|
1768
|
+
return absurd(e);
|
|
1951
1769
|
}
|
|
1952
1770
|
}
|
|
1953
|
-
function
|
|
1954
|
-
|
|
1955
|
-
for (const f of findings)
|
|
1956
|
-
if (top === undefined || SEVERITIES2.indexOf(f.severity) > SEVERITIES2.indexOf(top))
|
|
1957
|
-
top = f.severity;
|
|
1958
|
-
return top;
|
|
1959
|
-
}
|
|
1960
|
-
function exitStatusOf(findings) {
|
|
1961
|
-
const top = worst(findings);
|
|
1962
|
-
return top === "Warning" || top === "Error" ? "Findings" : "Ok";
|
|
1963
|
-
}
|
|
1964
|
-
var DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1965
|
-
function dayNumber(day) {
|
|
1966
|
-
const m = DAY.exec(day);
|
|
1967
|
-
if (m === null)
|
|
1968
|
-
return;
|
|
1969
|
-
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
1970
|
-
const ms = Date.UTC(y, mo - 1, d);
|
|
1971
|
-
const back = new Date(ms);
|
|
1972
|
-
if (back.getUTCFullYear() !== y || back.getUTCMonth() !== mo - 1 || back.getUTCDate() !== d)
|
|
1973
|
-
return;
|
|
1974
|
-
return Math.round(ms / 86400000);
|
|
1975
|
-
}
|
|
1976
|
-
function daysBetween(from, to) {
|
|
1977
|
-
const a = dayNumber(from);
|
|
1978
|
-
const b = dayNumber(to);
|
|
1979
|
-
if (a === undefined)
|
|
1980
|
-
return err(`${JSON.stringify(from)} is not a day (YYYY-MM-DD)`);
|
|
1981
|
-
if (b === undefined)
|
|
1982
|
-
return err(`${JSON.stringify(to)} is not a day (YYYY-MM-DD)`);
|
|
1983
|
-
return ok(b - a);
|
|
1984
|
-
}
|
|
1985
|
-
var UNAPPROVED_GRACE_DAYS = 90;
|
|
1986
|
-
function unapprovedSeverity(firstSeen, today, graceDays = UNAPPROVED_GRACE_DAYS) {
|
|
1987
|
-
const age = daysBetween(firstSeen, today);
|
|
1988
|
-
return age.kind === "ok" && age.value > graceDays ? "Warning" : "Informational";
|
|
1989
|
-
}
|
|
1990
|
-
function firstSeenOf(previous, key, today) {
|
|
1991
|
-
const before = Object.hasOwn(previous, key) ? previous[key] : undefined;
|
|
1992
|
-
return before !== undefined && dayNumber(before) !== undefined ? before : today;
|
|
1993
|
-
}
|
|
1994
|
-
function toSarif(findings, tool = "ergonex") {
|
|
1995
|
-
const rules = [...new Set(findings.map((f) => f.ruleId))].sort().map((id) => ({ id }));
|
|
1996
|
-
return {
|
|
1997
|
-
$schema: "https://json.schemastore.org/sarif-2.1.0.json",
|
|
1998
|
-
version: "2.1.0",
|
|
1999
|
-
runs: [
|
|
2000
|
-
{
|
|
2001
|
-
tool: {
|
|
2002
|
-
driver: {
|
|
2003
|
-
name: tool,
|
|
2004
|
-
informationUri: "https://intellectual-frontiers.github.io/.github/",
|
|
2005
|
-
rules
|
|
2006
|
-
}
|
|
2007
|
-
},
|
|
2008
|
-
results: findings.map((f) => ({
|
|
2009
|
-
ruleId: f.ruleId,
|
|
2010
|
-
level: sarifLevel(f.severity),
|
|
2011
|
-
message: { text: f.message },
|
|
2012
|
-
locations: [{ logicalLocations: [{ name: f.subject }] }],
|
|
2013
|
-
properties: { firstSeen: f.firstSeen }
|
|
2014
|
-
}))
|
|
2015
|
-
}
|
|
2016
|
-
]
|
|
2017
|
-
};
|
|
2018
|
-
}
|
|
2019
|
-
|
|
2020
|
-
// src/state-record.ts
|
|
2021
|
-
var ERGONEX_VERSION = "0.3.0";
|
|
2022
|
-
var STATE_RECORD_PATH = ".ergonex/state.auto.json";
|
|
2023
|
-
var EMPTY_RECORD = {
|
|
2024
|
-
ergonex: ERGONEX_VERSION,
|
|
2025
|
-
files: {},
|
|
2026
|
-
firstSeen: {}
|
|
2027
|
-
};
|
|
2028
|
-
var hash = (input, path = "$") => {
|
|
2029
|
-
const s = typeof input === "string" ? sha256Of(input) : undefined;
|
|
2030
|
-
return s === undefined ? err({
|
|
2031
|
-
kind: "decode",
|
|
2032
|
-
path,
|
|
2033
|
-
expected: "a SHA-256 (64 hexadecimal digits)",
|
|
2034
|
-
found: typeof input
|
|
2035
|
-
}) : ok(s);
|
|
2036
|
-
};
|
|
2037
|
-
var day = (input, path = "$") => typeof input === "string" && dayNumber(input) !== undefined ? ok(input) : err({
|
|
2038
|
-
kind: "decode",
|
|
2039
|
-
path,
|
|
2040
|
-
expected: "a day (YYYY-MM-DD)",
|
|
2041
|
-
found: typeof input
|
|
2042
|
-
});
|
|
2043
|
-
var shape = object({
|
|
2044
|
-
ergonex: string,
|
|
2045
|
-
files: record(object({ sha256: hash, generator: string })),
|
|
2046
|
-
firstSeen: record(day)
|
|
2047
|
-
}, { plan: hash });
|
|
2048
|
-
function decodeStateRecord(text) {
|
|
2049
|
-
const r = json(text, shape);
|
|
2050
|
-
return r.kind === "ok" ? ok(r.value) : err(formatDecodeError(r.error));
|
|
2051
|
-
}
|
|
2052
|
-
function encodeStateRecord(r) {
|
|
2053
|
-
const sorted = (o) => Object.fromEntries(Object.entries(o).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
2054
|
-
const value = {
|
|
2055
|
-
_generated: headerText("ergonex state"),
|
|
2056
|
-
ergonex: r.ergonex,
|
|
2057
|
-
...r.plan === undefined ? {} : { plan: r.plan },
|
|
2058
|
-
files: sorted(r.files),
|
|
2059
|
-
firstSeen: sorted(r.firstSeen)
|
|
2060
|
-
};
|
|
2061
|
-
return `${JSON.stringify(value, null, 2)}
|
|
2062
|
-
`;
|
|
1771
|
+
function shown(v) {
|
|
1772
|
+
return typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "bigint" ? String(v) : JSON.stringify(v);
|
|
2063
1773
|
}
|
|
2064
|
-
function
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
1774
|
+
function optionLine(e) {
|
|
1775
|
+
const o = e.option;
|
|
1776
|
+
const short = o.short === undefined ? " " : `-${o.short}, `;
|
|
1777
|
+
switch (o.kind) {
|
|
1778
|
+
case "flag":
|
|
1779
|
+
return {
|
|
1780
|
+
left: `${short}${o.negatable ? `--[no-]${e.long.slice(2)}` : e.long}`,
|
|
1781
|
+
note: o.negatable && o.fallback.kind === "default" ? ` (default: ${o.fallback.value ? e.long : `--no-${e.long.slice(2)}`})` : ""
|
|
1782
|
+
};
|
|
1783
|
+
case "value": {
|
|
1784
|
+
const f = o.fallback;
|
|
1785
|
+
const note = f.kind === "default" ? ` (default: ${shown(f.value)})` : f.kind === "required" ? " (required)" : "";
|
|
1786
|
+
return { left: `${short}${e.long} ${o.valueName}`, note };
|
|
2070
1787
|
}
|
|
2071
|
-
|
|
1788
|
+
case "many":
|
|
1789
|
+
return { left: `${short}${e.long} ${o.valueName}`, note: " (repeatable)" };
|
|
1790
|
+
default:
|
|
1791
|
+
return absurd(o);
|
|
1792
|
+
}
|
|
2072
1793
|
}
|
|
2073
|
-
function
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
files: Object.fromEntries(Object.entries(r.files).filter(([p]) => p !== path))
|
|
2077
|
-
};
|
|
1794
|
+
function columns(rows) {
|
|
1795
|
+
const width = Math.max(0, ...rows.map(([l]) => l.length));
|
|
1796
|
+
return rows.map(([l, r]) => ` ${l.padEnd(width)} ${r}`.trimEnd());
|
|
2078
1797
|
}
|
|
2079
|
-
function
|
|
2080
|
-
const
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
}
|
|
2101
|
-
}
|
|
2102
|
-
return out;
|
|
1798
|
+
function helpOf(program, summary, spec, operands = []) {
|
|
1799
|
+
const entries = Object.keys(spec).flatMap((key) => {
|
|
1800
|
+
const option = spec[key];
|
|
1801
|
+
return option === undefined ? [] : [{ key, long: longName(key), option }];
|
|
1802
|
+
});
|
|
1803
|
+
const required = entries.flatMap((e) => e.option.kind === "value" && e.option.fallback.kind === "required" ? [`${e.long} ${e.option.valueName}`] : []);
|
|
1804
|
+
const usage = [program, "[OPTIONS]", ...required, ...operands.map(operandWord)].join(" ");
|
|
1805
|
+
const rows = entries.map((e) => {
|
|
1806
|
+
const line = optionLine(e);
|
|
1807
|
+
return [line.left, `${e.option.help}${line.note}`];
|
|
1808
|
+
});
|
|
1809
|
+
return [
|
|
1810
|
+
`${program}: ${summary}`,
|
|
1811
|
+
"",
|
|
1812
|
+
`Usage: ${usage}`,
|
|
1813
|
+
"",
|
|
1814
|
+
"Options:",
|
|
1815
|
+
...columns([...rows, ["-h, --help", "Show this help and do nothing else."]]),
|
|
1816
|
+
...operands.length === 0 ? [] : ["", "Arguments:", ...columns(operands.map((o) => [operandWord(o), o.help]))]
|
|
1817
|
+
].join(`
|
|
1818
|
+
`);
|
|
2103
1819
|
}
|
|
2104
|
-
// src/platform/k-args.ts
|
|
2105
|
-
var editDistance2 = editDistance;
|
|
2106
|
-
var flag2 = flag;
|
|
2107
|
-
var formatUsageError2 = formatUsageError;
|
|
2108
|
-
var helpOf2 = helpOf;
|
|
2109
|
-
var parseArgs2 = parseArgs;
|
|
2110
|
-
var value2 = value;
|
|
2111
|
-
|
|
2112
1820
|
// src/modules/name.ts
|
|
2113
1821
|
var MAX_MODULE_NAME = 32;
|
|
2114
1822
|
function describeNameError(e) {
|
|
@@ -2138,7 +1846,7 @@ function moduleName(text) {
|
|
|
2138
1846
|
return ok(text);
|
|
2139
1847
|
}
|
|
2140
1848
|
function nearestNames(word, names) {
|
|
2141
|
-
return names.map((n) => ({ n, d:
|
|
1849
|
+
return names.map((n) => ({ n, d: editDistance(word, n) })).filter((x) => x.d <= 2).sort((a, b) => a.d - b.d || (a.n < b.n ? -1 : a.n > b.n ? 1 : 0)).slice(0, 3).map((x) => x.n);
|
|
2142
1850
|
}
|
|
2143
1851
|
|
|
2144
1852
|
// src/modules/external.ts
|
|
@@ -2248,13 +1956,13 @@ function precedenceOf(source) {
|
|
|
2248
1956
|
}
|
|
2249
1957
|
}
|
|
2250
1958
|
var GLOBAL_OPTIONS = {
|
|
2251
|
-
home:
|
|
1959
|
+
home: value({
|
|
2252
1960
|
help: "The root of the workspace for this run (else $ERGONEX_HOME, else $HOME/workspaces).",
|
|
2253
1961
|
valueName: "DIR"
|
|
2254
1962
|
}),
|
|
2255
|
-
json:
|
|
2256
|
-
sarif:
|
|
2257
|
-
noColor:
|
|
1963
|
+
json: flag({ help: "Write the report as JSON." }),
|
|
1964
|
+
sarif: flag({ help: "Write the findings as a SARIF 2.1.0 log." }),
|
|
1965
|
+
noColor: flag({ help: "Write no colour." })
|
|
2258
1966
|
};
|
|
2259
1967
|
function globalsOf(options) {
|
|
2260
1968
|
const home = options["home"];
|
|
@@ -2267,20 +1975,20 @@ function globalsOf(options) {
|
|
|
2267
1975
|
}
|
|
2268
1976
|
function defineCommand(d) {
|
|
2269
1977
|
const operands = d.operands ?? [];
|
|
2270
|
-
const help = (program) =>
|
|
1978
|
+
const help = (program) => helpOf(program, d.summary, d.options, operands);
|
|
2271
1979
|
return {
|
|
2272
1980
|
name: d.name,
|
|
2273
1981
|
summary: d.summary,
|
|
2274
1982
|
help,
|
|
2275
1983
|
execute: async (words, base) => {
|
|
2276
1984
|
const program = `ergonex ${d.name}`;
|
|
2277
|
-
const parsed =
|
|
1985
|
+
const parsed = parseArgs(words, d.options, operands);
|
|
2278
1986
|
if (parsed.kind === "err") {
|
|
2279
1987
|
return {
|
|
2280
1988
|
command: d.name,
|
|
2281
1989
|
outcome: err({
|
|
2282
1990
|
kind: "usage",
|
|
2283
|
-
message: `${
|
|
1991
|
+
message: `${formatUsageError(parsed.error, program)}
|
|
2284
1992
|
|
|
2285
1993
|
${help(program)}`
|
|
2286
1994
|
})
|