@intellectual-frontiers/ergonex 0.3.1 → 0.3.3

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.
Files changed (54) hide show
  1. package/dist/desired.d.ts +1 -1
  2. package/dist/mod.js +853 -955
  3. package/dist/modules/external.d.ts +1 -1
  4. package/dist/modules/registry.d.ts +1 -1
  5. package/dist/modules/types.d.ts +2 -2
  6. package/dist/plan.d.ts +1 -1
  7. package/dist/render.d.ts +2 -2
  8. package/dist/state-record.d.ts +2 -2
  9. package/dist/tools/catalog.d.ts +1 -1
  10. package/dist/vendor/ts/runtime/http-client.d.ts +1 -1
  11. package/ergonex.mjs +3641 -3638
  12. package/package.json +5 -4
  13. package/dist/vendor/ts/kernel/archive.d.ts +0 -147
  14. package/dist/vendor/ts/kernel/assess.d.ts +0 -247
  15. package/dist/vendor/ts/kernel/attest.d.ts +0 -164
  16. package/dist/vendor/ts/kernel/base64.d.ts +0 -24
  17. package/dist/vendor/ts/kernel/cbor.d.ts +0 -39
  18. package/dist/vendor/ts/kernel/cms.d.ts +0 -106
  19. package/dist/vendor/ts/kernel/cose.d.ts +0 -34
  20. package/dist/vendor/ts/kernel/crypt.d.ts +0 -30
  21. package/dist/vendor/ts/kernel/csv.d.ts +0 -38
  22. package/dist/vendor/ts/kernel/der.d.ts +0 -67
  23. package/dist/vendor/ts/kernel/documentation.d.ts +0 -118
  24. package/dist/vendor/ts/kernel/dsse.d.ts +0 -137
  25. package/dist/vendor/ts/kernel/evidence.d.ts +0 -212
  26. package/dist/vendor/ts/kernel/glob.d.ts +0 -64
  27. package/dist/vendor/ts/kernel/grc.d.ts +0 -356
  28. package/dist/vendor/ts/kernel/http.d.ts +0 -46
  29. package/dist/vendor/ts/kernel/json5.d.ts +0 -46
  30. package/dist/vendor/ts/kernel/layers.d.ts +0 -35
  31. package/dist/vendor/ts/kernel/md5.d.ts +0 -19
  32. package/dist/vendor/ts/kernel/media-types.d.ts +0 -28
  33. package/dist/vendor/ts/kernel/mod.d.ts +0 -89
  34. package/dist/vendor/ts/kernel/ocsf-types.auto.d.ts +0 -4374
  35. package/dist/vendor/ts/kernel/ocsf.d.ts +0 -160
  36. package/dist/vendor/ts/kernel/oscal.d.ts +0 -356
  37. package/dist/vendor/ts/kernel/otel.d.ts +0 -365
  38. package/dist/vendor/ts/kernel/otlp.d.ts +0 -83
  39. package/dist/vendor/ts/kernel/png.d.ts +0 -124
  40. package/dist/vendor/ts/kernel/render.d.ts +0 -111
  41. package/dist/vendor/ts/kernel/schedule.d.ts +0 -207
  42. package/dist/vendor/ts/kernel/semver.d.ts +0 -94
  43. package/dist/vendor/ts/kernel/sha256.d.ts +0 -29
  44. package/dist/vendor/ts/kernel/signals.d.ts +0 -371
  45. package/dist/vendor/ts/kernel/sigv4.d.ts +0 -67
  46. package/dist/vendor/ts/kernel/test-record.d.ts +0 -222
  47. package/dist/vendor/ts/kernel/test-report.d.ts +0 -294
  48. package/dist/vendor/ts/kernel/toml.d.ts +0 -51
  49. package/dist/vendor/ts/kernel/trace.d.ts +0 -169
  50. package/dist/vendor/ts/kernel/ts-literal.d.ts +0 -62
  51. package/dist/vendor/ts/kernel/uuid.d.ts +0 -53
  52. package/dist/vendor/ts/kernel/webauthn.d.ts +0 -212
  53. package/dist/vendor/ts/kernel/xml.d.ts +0 -73
  54. package/dist/vendor/ts/kernel/yaml.d.ts +0 -44
package/dist/mod.js CHANGED
@@ -189,20 +189,6 @@ function oneOf(...alternatives) {
189
189
  return fail(path, `one of ${alternatives.length} alternatives`, input);
190
190
  };
191
191
  }
192
- function mapDecoder(base, f) {
193
- return (input, path = "$") => {
194
- const r = base(input, path);
195
- return r.kind === "ok" ? ok(f(r.value)) : r;
196
- };
197
- }
198
- function refine(base, name, valid) {
199
- return (input, path = "$") => {
200
- const r = base(input, path);
201
- if (r.kind === "err")
202
- return r;
203
- return valid(r.value) ? ok(r.value) : fail(path, `a ${name}`, input);
204
- };
205
- }
206
192
  function json(text, decoder) {
207
193
  let value;
208
194
  try {
@@ -214,7 +200,19 @@ function json(text, decoder) {
214
200
  }
215
201
  // ../core/src/text.ts
216
202
  var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;?]*[A-Za-z]`, "g");
217
- // ../ts/kernel/archive.ts
203
+ // ../formats/src/base64.ts
204
+ function fromBase64(text) {
205
+ const t = text.replace(/[\t\n\r ]/g, "");
206
+ if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))
207
+ return err("the text is not padded standard base64");
208
+ const s = atob(t);
209
+ const out = new Uint8Array(s.length);
210
+ for (let i = 0;i < s.length; i++)
211
+ out[i] = s.charCodeAt(i);
212
+ return ok(out);
213
+ }
214
+
215
+ // ../formats/src/archive.ts
218
216
  var CRC_TABLE = Array.from({ length: 256 }, (_, i) => {
219
217
  let c = i;
220
218
  for (let k = 0;k < 8; k++)
@@ -227,126 +225,29 @@ function dosDate(year, month, day) {
227
225
  var ZIP_EPOCH = dosDate(1980, 1, 1);
228
226
  var NO_PENDING = { pax: new Map, longName: undefined, longLink: undefined };
229
227
  var MAX_META = 1 << 20;
230
- // ../ts/kernel/base64.ts
231
- function fromBase64(text) {
232
- const t = text.replace(/[\t\n\r ]/g, "");
233
- if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))
234
- return err("the text is not padded standard base64");
235
- const s = atob(t);
236
- const out = new Uint8Array(s.length);
237
- for (let i = 0;i < s.length; i++)
238
- out[i] = s.charCodeAt(i);
239
- return ok(out);
240
- }
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);
267
- }
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;
276
- }
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;
280
- }
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) });
288
- }
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);
300
- }
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
228
 
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;
336
- }
229
+ // ../formats/src/hex.ts
337
230
  function toHex(bytes) {
338
231
  let out = "";
339
232
  for (const b of bytes)
340
233
  out += b.toString(16).padStart(2, "0");
341
234
  return out;
342
235
  }
236
+ // ../formats/src/cbor.ts
237
+ var UTF8 = new TextDecoder("utf-8", { fatal: true });
238
+ // ../crypto/src/sha256.ts
239
+ var SHA256 = /^[0-9a-f]{64}$/;
240
+ function sha256Of(text) {
241
+ const t = text.trim().toLowerCase();
242
+ return SHA256.test(t) ? t : undefined;
243
+ }
343
244
  async function sha256(data) {
344
245
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
345
246
  const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
346
247
  return toHex(new Uint8Array(digest));
347
248
  }
348
249
 
349
- // ../ts/kernel/dsse.ts
250
+ // ../crypto/src/dsse.ts
350
251
  var utf8 = new TextEncoder;
351
252
  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
253
  var resourceDescriptorDecoder = object({ name: string, digest: record(lowerHex) }, { uri: string, mediaType: string, annotations: record(unknownValue) });
@@ -356,27 +257,12 @@ var envelopeDecoder = object({
356
257
  payloadType: string,
357
258
  signatures: array(object({ sig: base64Text }, { keyid: string }))
358
259
  });
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
260
+ // ../crypto/src/md5.ts
261
+ var T = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0);
262
+ // ../crypto/src/sigv4.ts
263
+ var UNSIGNED_HEADERS = new Set(["authorization", "connection", "expect", "user-agent", "x-amzn-trace-id", "traceparent", "tracestate"]);
264
+ var encoder = new TextEncoder;
265
+ // ../crypto/src/uuid.ts
380
266
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
381
267
  function uuidOf(text) {
382
268
  const t = text.trim().toLowerCase();
@@ -395,769 +281,260 @@ var NAMESPACE_URL = constant("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
395
281
  var NAMESPACE_OID = constant("6ba7b812-9dad-11d1-80b4-00c04fd430c8");
396
282
  var NAMESPACE_X500 = constant("6ba7b814-9dad-11d1-80b4-00c04fd430c8");
397
283
  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 }
442
- });
284
+ // ../crypto/src/webauthn.ts
285
+ var clientData = object({ type: string, challenge: string, origin: string }, { crossOrigin: boolean, topOrigin: string });
286
+ var kind = literal("public-key");
287
+ var extensionResults = record(unknownValue);
288
+ // src/portable.ts
289
+ function describePortableError(e) {
290
+ switch (e.kind) {
291
+ case "empty":
292
+ return "a path segment is empty";
293
+ case "dot":
294
+ return `the path segment ${JSON.stringify(e.segment)} would leave its folder`;
295
+ case "forbidden-character":
296
+ return `the path segment ${JSON.stringify(e.segment)} holds ${JSON.stringify(e.character)}, which Windows does not allow in a name`;
297
+ case "control-character":
298
+ return `the path segment ${JSON.stringify(e.segment)} holds a control character`;
299
+ case "trailing-dot-or-space":
300
+ return `the path segment ${JSON.stringify(e.segment)} ends in a dot or a space, which Windows drops`;
301
+ case "device-name":
302
+ return `the path segment ${JSON.stringify(e.segment)} is the Windows device name ${e.device}, with or without an extension, in any case`;
303
+ case "too-long":
304
+ return `the path segment is ${e.bytes} bytes in UTF-8, and a name may have 255`;
305
+ case "not-nfc":
306
+ return `the path segment ${JSON.stringify(e.segment)} is not in Unicode normalization form NFC, so it would be another name on macOS`;
307
+ default:
308
+ return absurd(e);
309
+ }
443
310
  }
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);
311
+ var FORBIDDEN = new Set(["<", ">", ":", '"', "/", "\\", "|", "?", "*"]);
312
+ var DEVICE = /^(?:CON|PRN|AUX|NUL|CONIN\$|CONOUT\$|COM[0-9\u00b9\u00b2\u00b3]|LPT[0-9\u00b9\u00b2\u00b3])$/i;
313
+ function isDeviceName(name) {
314
+ return DEVICE.test((name.split(".")[0] ?? "").replace(/ +$/, ""));
467
315
  }
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");
316
+ var MAX_SEGMENT_BYTES = 255;
317
+ function segment(text) {
318
+ if (text === "")
319
+ return err({ kind: "empty" });
320
+ if (text === "." || text === "..")
321
+ return err({ kind: "dot", segment: text });
322
+ for (const ch of text) {
323
+ const code = ch.codePointAt(0) ?? 0;
324
+ if (code < 32 || code === 127)
325
+ return err({ kind: "control-character", segment: text });
326
+ if (FORBIDDEN.has(ch))
327
+ return err({ kind: "forbidden-character", segment: text, character: ch });
328
+ }
329
+ if (text.endsWith(".") || text.endsWith(" "))
330
+ return err({ kind: "trailing-dot-or-space", segment: text });
331
+ const stem = (text.split(".")[0] ?? "").replace(/ +$/, "");
332
+ if (isDeviceName(text))
333
+ return err({
334
+ kind: "device-name",
335
+ segment: text,
336
+ device: stem.toUpperCase()
337
+ });
338
+ const bytes = new TextEncoder().encode(text).length;
339
+ if (bytes > MAX_SEGMENT_BYTES)
340
+ return err({ kind: "too-long", segment: text.slice(0, 40), bytes });
341
+ if (text !== text.normalize("NFC"))
342
+ return err({ kind: "not-nfc", segment: text });
473
343
  return ok(text);
474
344
  }
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)
493
- break;
494
- const member = raw.replace(/^[ \t]+|[ \t]+$/g, "");
495
- if (member === "")
496
- continue;
497
- const eq = member.indexOf("=");
498
- if (eq < 0)
499
- continue;
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 });
345
+ function repoPath(segments) {
346
+ if (segments.length === 0)
347
+ return err({ kind: "empty" });
348
+ const made = [];
349
+ for (const s of segments) {
350
+ const r = segment(s);
351
+ if (r.kind === "err")
352
+ return r;
353
+ made.push(r.value);
506
354
  }
507
- return out;
355
+ return ok(made.join("/"));
508
356
  }
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;
357
+ function segmentsOf(path) {
358
+ return path.split("/");
512
359
  }
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;
522
- }
360
+ function child(path, name) {
361
+ return `${path}/${name}`;
523
362
  }
524
- function failure(path, expected, input) {
525
- return { kind: "decode", path, expected, found: describe(input) };
363
+ function nativePath(root, path, separator) {
364
+ const base = root.replace(/[\\/]+$/, "");
365
+ return [base, ...segmentsOf(path)].join(separator);
526
366
  }
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;
550
- }
551
- };
367
+ function foldKey(path) {
368
+ return path.normalize("NFC").toUpperCase().toLowerCase().normalize("NFC");
552
369
  }
553
- function list(element) {
554
- return (input, path = "$") => {
555
- if (!Array.isArray(input))
556
- return err(failure(path, "an array", input));
557
- const out = [];
558
- for (const [i, value] of input.entries()) {
559
- const r = element(value, `${path}[${i}]`);
560
- if (r.kind === "err")
561
- return r;
562
- out.push(r.value);
563
- }
564
- return ok(out);
565
- };
370
+ function collisions(items) {
371
+ const groups = new Map;
372
+ for (const item of items) {
373
+ const key = foldKey(item.path);
374
+ const group = groups.get(key);
375
+ if (group === undefined)
376
+ groups.set(key, [{ ...item }]);
377
+ else
378
+ group.push({ ...item });
379
+ }
380
+ return [...groups.entries()].filter(([, members]) => members.length > 1).map(([key, members]) => ({ key, members }));
566
381
  }
567
- var str = (input, path = "$") => typeof input === "string" ? ok(input) : err(failure(path, "a string", input));
568
- var bool = (input, path = "$") => typeof input === "boolean" ? ok(input) : err(failure(path, "a boolean", input));
569
- var int64 = (input, path = "$") => {
570
- if (typeof input === "number" && Number.isInteger(input))
571
- return ok(BigInt(input));
572
- if (typeof input === "string" && /^-?[0-9]+$/.test(input))
573
- return ok(BigInt(input));
574
- return err(failure(path, "a 64-bit integer (a number or a decimal string)", input));
575
- };
576
- var count = (input, path = "$") => {
577
- const r = int64(input, path);
578
- if (r.kind === "err")
579
- return r;
580
- return r.value >= 0n && r.value <= BigInt(Number.MAX_SAFE_INTEGER) ? ok(Number(r.value)) : err(failure(path, "a count", input));
581
- };
582
- var double = (input, path = "$") => {
583
- if (typeof input === "number")
584
- return ok(input);
585
- if (input === "NaN")
586
- return ok(NaN);
587
- if (input === "Infinity")
588
- return ok(Infinity);
589
- if (input === "-Infinity")
590
- return ok(-Infinity);
591
- return err(failure(path, "a double", input));
592
- };
593
- var bytes = (input, path = "$") => {
594
- if (typeof input !== "string")
595
- return err(failure(path, "base64", input));
596
- const r = fromBase64(input);
597
- return r.kind === "ok" ? r : err(failure(path, "base64", input));
598
- };
599
- var traceId = (input, path = "$") => {
600
- const r = typeof input === "string" ? parseTraceId(input.toLowerCase()) : err("");
601
- return r.kind === "ok" ? r : err(failure(path, "a trace id (32 hexadecimal digits, not all zeros)", input));
602
- };
603
- var spanId = (input, path = "$") => {
604
- const r = typeof input === "string" ? parseSpanId(input.toLowerCase()) : err("");
605
- return r.kind === "ok" ? r : err(failure(path, "a span id (16 hexadecimal digits, not all zeros)", input));
606
- };
607
- function enumeration(names) {
608
- return (input, path = "$") => {
609
- if (typeof input === "number" && Number.isInteger(input) && input >= 0 && input < names.length)
610
- return ok(input);
611
- if (typeof input === "string") {
612
- const i = names.indexOf(input);
613
- if (i >= 0)
614
- return ok(i);
615
- }
616
- return err(failure(path, `one of ${names.join(", ")} or its number`, input));
617
- };
382
+ var WINDOWS_PATH_LIMIT = 259;
383
+ function checkPathLength(windowsPath, longPathsEnabled) {
384
+ if (longPathsEnabled || windowsPath.length <= WINDOWS_PATH_LIMIT)
385
+ return ok(windowsPath);
386
+ return err({
387
+ kind: "path-too-long",
388
+ path: windowsPath,
389
+ length: windowsPath.length,
390
+ limit: WINDOWS_PATH_LIMIT
391
+ });
618
392
  }
619
- var spanKindEnum = enumeration([
620
- "SPAN_KIND_UNSPECIFIED",
621
- "SPAN_KIND_INTERNAL",
622
- "SPAN_KIND_SERVER",
623
- "SPAN_KIND_CLIENT",
624
- "SPAN_KIND_PRODUCER",
625
- "SPAN_KIND_CONSUMER"
626
- ]);
627
- var statusCodeEnum = enumeration(["STATUS_CODE_UNSET", "STATUS_CODE_OK", "STATUS_CODE_ERROR"]);
628
- var temporalityEnum = enumeration([
629
- "AGGREGATION_TEMPORALITY_UNSPECIFIED",
630
- "AGGREGATION_TEMPORALITY_DELTA",
631
- "AGGREGATION_TEMPORALITY_CUMULATIVE"
632
- ]);
633
- var SEVERITY_NAMES = ["SEVERITY_NUMBER_UNSPECIFIED"].concat(["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"].flatMap((r) => ["", "2", "3", "4"].map((n) => `SEVERITY_NUMBER_${r}${n}`)));
634
- var severityEnum = (input, path = "$") => {
635
- const r = enumeration(SEVERITY_NAMES)(input, path);
636
- if (r.kind === "err")
637
- return r;
638
- return isSeverityNumber(r.value) ? ok(r.value) : err(failure(path, "a severity number from 1 to 24", input));
639
- };
640
- var decodeAnyValue = (input, path = "$") => {
641
- if (typeof input !== "object" || input === null || Array.isArray(input))
642
- return err(failure(path, "an AnyValue object", input));
643
- const has = (key) => {
644
- const v = Reflect.get(input, key);
645
- return v !== undefined && v !== null;
646
- };
647
- const at = (key) => Reflect.get(input, key);
648
- if (has("stringValue"))
649
- return str(at("stringValue"), `${path}.stringValue`);
650
- if (has("boolValue"))
651
- return bool(at("boolValue"), `${path}.boolValue`);
652
- if (has("intValue"))
653
- return int64(at("intValue"), `${path}.intValue`);
654
- if (has("doubleValue"))
655
- return double(at("doubleValue"), `${path}.doubleValue`);
656
- if (has("bytesValue"))
657
- return bytes(at("bytesValue"), `${path}.bytesValue`);
658
- if (has("arrayValue"))
659
- return message((f) => f.opt("values", list(decodeAnyValue), []))(at("arrayValue"), `${path}.arrayValue`);
660
- if (has("kvlistValue")) {
661
- return message((f) => {
662
- const out = {};
663
- for (const kv of f.opt("values", list(keyValue(decodeAnyValue)), [])) {
664
- Object.defineProperty(out, kv.key, { value: kv.value, enumerable: true, writable: true, configurable: true });
665
- }
666
- return out;
667
- })(at("kvlistValue"), `${path}.kvlistValue`);
393
+ var REPO_PATH_ROOM = 150;
394
+ function repoPathLength(root, path, separator) {
395
+ const length = nativePath(root, path, separator).length;
396
+ if (length > WINDOWS_PATH_LIMIT)
397
+ return { kind: "too-long", length };
398
+ if (length > REPO_PATH_ROOM)
399
+ return { kind: "no-room", length };
400
+ return { kind: "fits", length };
401
+ }
402
+
403
+ // src/render.ts
404
+ function describeGenerateError(e) {
405
+ switch (e.kind) {
406
+ case "bad-path":
407
+ return `${JSON.stringify(e.path)} cannot be the path of a generated file: ${e.reason}`;
408
+ case "not-auto":
409
+ return `${e.path} is a generated file whose name does not carry .auto. (only a Git hook in .ergonex/hooks/ may lack it)`;
410
+ case "collision":
411
+ return `${e.path} is the same path as ${e.other} after Unicode normalization and case folding; both are refused`;
412
+ case "inside-repository":
413
+ return `${e.path} is inside the working tree of ${e.repository}; a generated file is never written into a repository`;
414
+ case "bad-data":
415
+ return `${e.what}: ${e.reason}`;
416
+ default:
417
+ return absurd(e);
668
418
  }
669
- return err(failure(path, "an AnyValue holding a value", input));
670
- };
671
- function keyValue(value) {
672
- return message((f) => ({ key: f.req("key", str), value: f.req("value", value) }));
673
419
  }
674
- var decodeAttributeValue = (input, path = "$") => {
675
- const r = decodeAnyValue(input, path);
676
- if (r.kind === "err")
677
- return r;
678
- const v = r.value;
679
- if (typeof v !== "object" || v instanceof Uint8Array)
680
- return ok(v);
681
- if (Array.isArray(v)) {
682
- const values = v;
683
- if (values.every((e) => typeof e === "string"))
684
- return ok(values.filter((e) => typeof e === "string"));
685
- if (values.every((e) => typeof e === "boolean"))
686
- return ok(values.filter((e) => typeof e === "boolean"));
687
- if (values.every((e) => typeof e === "bigint"))
688
- return ok(values.filter((e) => typeof e === "bigint"));
689
- if (values.every((e) => typeof e === "number"))
690
- return ok(values.filter((e) => typeof e === "number"));
420
+ var HOOKS_FOLDER = ".ergonex/hooks";
421
+ function headerText(generator) {
422
+ return `Generated by ${generator}. Do not edit by hand: change workspace.ts and run \`ergonex render\`.`;
423
+ }
424
+ function normalizeText(text) {
425
+ const lf = text.replace(/^/, "").replaceAll(`\r
426
+ `, `
427
+ `).replaceAll("\r", `
428
+ `);
429
+ return `${lf.replace(/\n+$/, "")}
430
+ `;
431
+ }
432
+ function isAutoName(name) {
433
+ return name.includes(".auto.") || name.endsWith(".auto");
434
+ }
435
+ function generatedPath(path) {
436
+ const made = repoPath(path.split("/"));
437
+ if (made.kind === "err")
438
+ return err({
439
+ kind: "bad-path",
440
+ path,
441
+ reason: describePortableError(made.error)
442
+ });
443
+ return made;
444
+ }
445
+ var noBom = (text) => text.replace(/^\uFEFF/, "");
446
+ function contentOf(body, generator) {
447
+ const header = headerText(generator);
448
+ switch (body.format) {
449
+ case "json":
450
+ return normalizeText(JSON.stringify({ _generated: header, ...body.value }, null, 2));
451
+ case "markdown":
452
+ return normalizeText(`<!-- ${header} -->
453
+
454
+ ${noBom(body.text)}`);
455
+ case "yaml":
456
+ case "gitconfig":
457
+ case "envrc":
458
+ return normalizeText(`# ${header}
459
+
460
+ ${noBom(body.text)}`);
461
+ case "sh": {
462
+ const text = noBom(body.text);
463
+ const m = /^(#![^\n]*)\n/.exec(text);
464
+ return m === null ? normalizeText(`# ${header}
465
+ ${text}`) : normalizeText(`${m[1]}
466
+ # ${header}
467
+ ${text.slice(m[0].length)}`);
468
+ }
469
+ default:
470
+ return absurd(body);
691
471
  }
692
- return err(failure(path, "an attribute value (a primitive or a homogeneous array of primitives)", input));
693
- };
694
- var decodeAttributes = (input, path = "$") => {
695
- const r = list(keyValue(decodeAttributeValue))(input, path);
696
- if (r.kind === "err")
697
- return r;
698
- const out = {};
699
- for (const kv of r.value)
700
- Object.defineProperty(out, kv.key, { value: kv.value, enumerable: true, writable: true, configurable: true });
701
- return ok(out);
702
- };
703
- var resource = message((f) => ({ attributes: f.opt("attributes", decodeAttributes, {}) }));
704
- var scope = message((f) => {
705
- const version = f.opt("version", str, undefined);
706
- const attributes = f.opt("attributes", decodeAttributes, undefined);
707
- return {
708
- name: f.opt("name", str, ""),
709
- ...version === undefined ? {} : { version },
710
- ...attributes === undefined ? {} : { attributes }
711
- };
712
- });
713
- var event = message((f) => ({
714
- name: f.opt("name", str, ""),
715
- time: f.opt("timeUnixNano", int64, 0n),
716
- attributes: f.opt("attributes", decodeAttributes, {}),
717
- droppedAttributesCount: f.opt("droppedAttributesCount", count, 0)
718
- }));
719
- var link = message((f) => ({
720
- traceId: f.req("traceId", traceId),
721
- spanId: f.req("spanId", spanId),
722
- traceState: parseTracestate(f.opt("traceState", str, "")),
723
- traceFlags: f.opt("flags", count, 0) & 255,
724
- attributes: f.opt("attributes", decodeAttributes, {}),
725
- droppedAttributesCount: f.opt("droppedAttributesCount", count, 0)
726
- }));
727
- var status = message((f) => {
728
- const code = f.opt("code", statusCodeEnum, 0);
729
- if (code === 1)
730
- return { kind: "ok" };
731
- if (code === 2)
732
- return { kind: "error", message: f.opt("message", str, "") };
733
- return { kind: "unset" };
734
- });
735
- var optionalSpanId = (input, path = "$") => input === "" ? ok(undefined) : spanId(input, path);
736
- var decodeSpan = message((f) => {
737
- const parentSpanId = f.opt("parentSpanId", optionalSpanId, undefined);
738
- const kind = f.opt("kind", spanKindEnum, 1);
739
- return {
740
- name: f.opt("name", str, ""),
741
- context: {
742
- traceId: f.req("traceId", traceId),
743
- spanId: f.req("spanId", spanId),
744
- traceFlags: f.opt("flags", count, 0) & 255,
745
- traceState: parseTracestate(f.opt("traceState", str, "")),
746
- isRemote: false
747
- },
748
- ...parentSpanId === undefined ? {} : { parentSpanId },
749
- kind: SPAN_KINDS[kind - 1] ?? "internal",
750
- startTime: f.opt("startTimeUnixNano", int64, 0n),
751
- endTime: f.opt("endTimeUnixNano", int64, 0n),
752
- attributes: f.opt("attributes", decodeAttributes, {}),
753
- events: f.opt("events", list(event), []),
754
- links: f.opt("links", list(link), []),
755
- status: f.opt("status", status, { kind: "unset" }),
756
- droppedAttributesCount: f.opt("droppedAttributesCount", count, 0),
757
- droppedEventsCount: f.opt("droppedEventsCount", count, 0),
758
- droppedLinksCount: f.opt("droppedLinksCount", count, 0)
759
- };
760
- });
761
- var optionalTraceId = (input, path = "$") => input === "" ? ok(undefined) : traceId(input, path);
762
- var decodeLogRecord = message((f) => {
763
- const body = f.opt("body", decodeAnyValue, undefined);
764
- const traceFlags = f.opt("flags", count, undefined);
765
- const tid = f.opt("traceId", optionalTraceId, undefined);
766
- const sid = f.opt("spanId", optionalSpanId, undefined);
767
- const eventName = f.opt("eventName", str, undefined);
768
- return {
769
- time: f.opt("timeUnixNano", int64, 0n),
770
- observedTime: f.opt("observedTimeUnixNano", int64, 0n),
771
- severityNumber: f.req("severityNumber", severityEnum),
772
- severityText: f.opt("severityText", str, ""),
773
- ...body === undefined ? {} : { body },
774
- attributes: f.opt("attributes", decodeAttributes, {}),
775
- droppedAttributesCount: f.opt("droppedAttributesCount", count, 0),
776
- ...eventName === undefined ? {} : { eventName },
777
- ...tid === undefined ? {} : { traceId: tid },
778
- ...sid === undefined ? {} : { spanId: sid },
779
- ...traceFlags === undefined ? {} : { traceFlags: traceFlags & 255 }
780
- };
781
- });
782
- var numberPoint = message((f, path) => {
783
- const asInt = f.opt("asInt", int64, undefined);
784
- const asDouble = f.opt("asDouble", double, undefined);
785
- const value = asInt ?? asDouble;
786
- if (value === undefined)
787
- throw new Failure(failure(`${path}.asDouble`, "asInt or asDouble", undefined));
788
- return {
789
- attributes: f.opt("attributes", decodeAttributes, {}),
790
- startTime: f.opt("startTimeUnixNano", int64, 0n),
791
- time: f.opt("timeUnixNano", int64, 0n),
792
- value
793
- };
794
- });
795
- var histogramPoint = message((f, path) => {
796
- const sum = f.opt("sum", double, undefined);
797
- const min = f.opt("min", double, undefined);
798
- const max = f.opt("max", double, undefined);
799
- const bounds = f.opt("explicitBounds", list(double), []);
800
- const bucketCounts = f.opt("bucketCounts", list(count), []);
801
- if (bucketCounts.length !== 0 && bucketCounts.length !== bounds.length + 1) {
802
- throw new Failure(failure(`${path}.bucketCounts`, `${bounds.length + 1} bucket counts`, bucketCounts.length));
472
+ }
473
+ function generated(path, body, options) {
474
+ const made = generatedPath(path);
475
+ if (made.kind === "err")
476
+ return made;
477
+ const name = made.value.split("/").at(-1) ?? "";
478
+ const isHook = made.value.startsWith(`${HOOKS_FOLDER}/`) && made.value.split("/").length === 3;
479
+ if (!isAutoName(name) && !isHook)
480
+ return err({ kind: "not-auto", path });
481
+ return ok({
482
+ path: made.value,
483
+ content: contentOf(body, options.generator),
484
+ mode: options.mode ?? "0644",
485
+ generator: options.generator
486
+ });
487
+ }
488
+ function fileDigest(file) {
489
+ return sha256(file.content);
490
+ }
491
+ function checkFiles(files, repositories) {
492
+ const errors = [];
493
+ for (const c of collisions(files.map((f) => ({ id: f.path, path: f.path })))) {
494
+ for (const m of c.members) {
495
+ const other = c.members.find((o) => o !== m);
496
+ errors.push({
497
+ kind: "collision",
498
+ path: m.path,
499
+ other: other?.path ?? m.path
500
+ });
501
+ }
803
502
  }
804
- return {
805
- attributes: f.opt("attributes", decodeAttributes, {}),
806
- startTime: f.opt("startTimeUnixNano", int64, 0n),
807
- time: f.opt("timeUnixNano", int64, 0n),
808
- count: f.opt("count", count, 0),
809
- ...sum === undefined ? {} : { sum },
810
- ...min === undefined ? {} : { min },
811
- ...max === undefined ? {} : { max },
812
- bounds,
813
- bucketCounts
814
- };
815
- });
816
- function temporalityOf(n) {
817
- return n === 1 ? "delta" : "cumulative";
503
+ for (const f of files) {
504
+ const key = foldKey(f.path);
505
+ const inside = repositories.find((r) => key.startsWith(`${foldKey(r)}/`));
506
+ if (inside !== undefined)
507
+ errors.push({
508
+ kind: "inside-repository",
509
+ path: f.path,
510
+ repository: inside
511
+ });
512
+ }
513
+ if (errors.length > 0)
514
+ return err(errors);
515
+ return ok([...files].sort((a, b) => foldKey(a.path) < foldKey(b.path) ? -1 : foldKey(a.path) > foldKey(b.path) ? 1 : 0));
818
516
  }
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
517
 
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
- }
518
+ // src/desired.ts
519
+ function settingsOf(manifest, facts) {
520
+ const settings = {
521
+ "core.hooksPath": `${facts.homePosix.replace(/\/+$/, "")}/.ergonex/hooks`
522
+ };
523
+ if (manifest.policy.requiresSignedCommits) {
524
+ settings["commit.gpgsign"] = "true";
525
+ if (manifest.signing !== undefined) {
526
+ settings["gpg.format"] = manifest.signing.format;
527
+ if (manifest.signing.key !== undefined)
528
+ settings["user.signingkey"] = manifest.signing.key;
882
529
  }
883
530
  }
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 });
951
- }
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 });
966
- return ok(text);
967
- }
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) {
1028
- switch (e.kind) {
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}`;
1039
- default:
1040
- return absurd(e);
1041
- }
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;
1157
- }
1158
- if (facts.windows)
1159
- settings["core.longpaths"] = "true";
1160
- return settings;
531
+ if (manifest.identity !== undefined) {
532
+ settings["user.name"] = manifest.identity.name;
533
+ settings["user.email"] = manifest.identity.email;
534
+ }
535
+ if (facts.windows)
536
+ settings["core.longpaths"] = "true";
537
+ return settings;
1161
538
  }
1162
539
  async function desiredOf(manifest, files, facts) {
1163
540
  const settings = settingsOf(manifest, facts);
@@ -1180,22 +557,87 @@ async function digestsOf(files) {
1180
557
  out.set(f.path, await fileDigest(f));
1181
558
  return out;
1182
559
  }
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
- }
1197
- }
1198
- function findingsOf(checks, today) {
560
+ // ../formats/src/glob.ts
561
+ var ESCAPE_OUTSIDE = new Set(["!", "$", "(", ")", "*", "+", ".", "=", "?", "[", "\\", "^", "{", "|"]);
562
+ var ESCAPE_INSIDE = new Set(["-", "\\", "]"]);
563
+ var CLASSES = new Map([
564
+ ["alnum", "\\dA-Za-z"],
565
+ ["alpha", "A-Za-z"],
566
+ ["ascii", "\\x00-\\x7F"],
567
+ ["blank", "\\t "],
568
+ ["cntrl", "\\x00-\\x1F\\x7F"],
569
+ ["digit", "\\d"],
570
+ ["graph", "\\x21-\\x7E"],
571
+ ["lower", "a-z"],
572
+ ["print", "\\x20-\\x7E"],
573
+ ["punct", "!-\\/:-@\\[-`{-~"],
574
+ ["space", "\\s\\v"],
575
+ ["upper", "A-Z"],
576
+ ["word", "\\w"],
577
+ ["xdigit", "\\dA-Fa-f"]
578
+ ]);
579
+ // ../formats/src/http.ts
580
+ var SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS", "TRACE"]);
581
+ // ../formats/src/semver.ts
582
+ 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-]+)*))?$/;
583
+ function parseSemVer(text) {
584
+ const m = PATTERN.exec(text.trim());
585
+ if (m === null)
586
+ return err(`${JSON.stringify(text)} is not a semantic version (major.minor.patch[-pre][+build])`);
587
+ const [, major = "", minor = "", patch = "", pre, build] = m;
588
+ const parts = [Number(major), Number(minor), Number(patch)];
589
+ if (!parts.every(Number.isSafeInteger))
590
+ return err(`${JSON.stringify(text)} has a number too large`);
591
+ return ok({
592
+ major: parts[0],
593
+ minor: parts[1],
594
+ patch: parts[2],
595
+ ...pre === undefined ? {} : { pre },
596
+ ...build === undefined ? {} : { build }
597
+ });
598
+ }
599
+ var IDENT = "(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)";
600
+ var PART = "(0|[1-9][0-9]*|[xX*])";
601
+ var PARTIAL = new RegExp(`^v?${PART}(?:\\.${PART}(?:\\.${PART}(?:-(${IDENT}(?:\\.${IDENT})*))?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?)?)?$`);
602
+ var ver = (major, minor, patch, pre) => ({
603
+ major,
604
+ minor,
605
+ patch,
606
+ ...pre === undefined ? {} : { pre }
607
+ });
608
+ var at = (op, version) => ({ op, version });
609
+ var NOTHING = [at("<", ver(0, 0, 0, "0"))];
610
+ // ../formats/src/png.ts
611
+ var MAX_PIXELS = 2 ** 24;
612
+ var COLOUR_TYPES = new Map([
613
+ [0, { samples: 1, depths: [1, 2, 4, 8, 16], name: "greyscale" }],
614
+ [2, { samples: 3, depths: [8, 16], name: "RGB" }],
615
+ [3, { samples: 1, depths: [1, 2, 4, 8], name: "palette" }],
616
+ [4, { samples: 2, depths: [8, 16], name: "greyscale with alpha" }],
617
+ [6, { samples: 4, depths: [8, 16], name: "RGBA" }]
618
+ ]);
619
+ var PRECISION_BITS = 32 - 8 - 2;
620
+ var ONE = 2 ** PRECISION_BITS;
621
+ // ../formats/src/toml.ts
622
+ var CONTROL = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(8, 10)}-${String.fromCharCode(31, 127)}]`);
623
+ // ../formats/src/xml.ts
624
+ var FORBIDDEN2 = new RegExp(`[${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11, 12)}${String.fromCharCode(14)}-${String.fromCharCode(31)}\\ufffe\\uffff]`, "g");
625
+ // src/doctor.ts
626
+ function severityOf(level) {
627
+ switch (level) {
628
+ case "ok":
629
+ return;
630
+ case "suggest":
631
+ return "Informational";
632
+ case "warn":
633
+ return "Warning";
634
+ case "error":
635
+ return "Error";
636
+ default:
637
+ return absurd(level);
638
+ }
639
+ }
640
+ function findingsOf(checks, today) {
1199
641
  return checks.flatMap((c) => {
1200
642
  const severity = severityOf(c.level);
1201
643
  return severity === undefined ? [] : [
@@ -1388,7 +830,7 @@ function hookChecks(facts, wantedHooksPath) {
1388
830
  });
1389
831
  }
1390
832
  // src/findings.ts
1391
- var SEVERITIES2 = ["Informational", "Warning", "Error"];
833
+ var SEVERITIES = ["Informational", "Warning", "Error"];
1392
834
  function sarifLevel(severity) {
1393
835
  switch (severity) {
1394
836
  case "Informational":
@@ -1404,7 +846,7 @@ function sarifLevel(severity) {
1404
846
  function worst(findings) {
1405
847
  let top;
1406
848
  for (const f of findings)
1407
- if (top === undefined || SEVERITIES2.indexOf(f.severity) > SEVERITIES2.indexOf(top))
849
+ if (top === undefined || SEVERITIES.indexOf(f.severity) > SEVERITIES.indexOf(top))
1408
850
  top = f.severity;
1409
851
  return top;
1410
852
  }
@@ -1469,7 +911,7 @@ function toSarif(findings, tool = "ergonex") {
1469
911
  }
1470
912
 
1471
913
  // src/state-record.ts
1472
- var ERGONEX_VERSION = "0.3.1";
914
+ var ERGONEX_VERSION = "0.3.3";
1473
915
  var STATE_RECORD_PATH = ".ergonex/state.auto.json";
1474
916
  var EMPTY_RECORD = {
1475
917
  ergonex: ERGONEX_VERSION,
@@ -1877,14 +1319,14 @@ var commandDecoder = object({
1877
1319
  name: string,
1878
1320
  summary: string
1879
1321
  });
1880
- var manifestDecoder2 = object({
1322
+ var manifestDecoder = object({
1881
1323
  contract: integer,
1882
1324
  name: string,
1883
1325
  summary: string,
1884
1326
  commands: array(commandDecoder)
1885
1327
  });
1886
1328
  function decodeExternalManifest(text) {
1887
- const r = json(text, manifestDecoder2);
1329
+ const r = json(text, manifestDecoder);
1888
1330
  if (r.kind === "err")
1889
1331
  return err(formatDecodeError(r.error));
1890
1332
  const m = r.value;
@@ -2636,57 +2078,445 @@ function rcFileFor(shell, f) {
2636
2078
  return absurd(shell);
2637
2079
  }
2638
2080
  }
2639
- // ../ts/runtime/otel.ts
2640
- var RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
2641
- var DAY_MS = 24 * 60 * 60 * 1000;
2642
- var RUNTIME_SIGNALS = defineSignals({
2643
- process: {
2644
- signal: "span",
2645
- spanKind: "client",
2646
- role: "detail",
2647
- description: "A program run by proc: its name and option names alone (FR-006), and its exit status.",
2648
- attributes: { "process.executable.name": "string", "process.command_args": "string[]", "process.exit.code?": "int" }
2649
- },
2650
- "http.client": {
2651
- signal: "span",
2652
- spanKind: "client",
2653
- role: "detail",
2654
- description: "A request made by the HTTP client; the URL redacted (FR-006).",
2655
- attributes: {
2656
- "http.request.method": "string",
2657
- "url.full": "string",
2658
- "server.address": "string",
2659
- "server.port?": "int",
2660
- "http.response.status_code?": "int",
2661
- "error.type?": "string"
2081
+ // ../ts/kernel/otel.ts
2082
+ var TRACE_ID = /^[0-9a-f]{32}$/;
2083
+ var SPAN_ID = /^[0-9a-f]{16}$/;
2084
+ var ZEROS = /^0+$/;
2085
+ function parseTraceId(text) {
2086
+ if (!TRACE_ID.test(text))
2087
+ return err("a trace id is 32 lower-case hexadecimal digits");
2088
+ if (ZEROS.test(text))
2089
+ return err("a trace id of all zeros is not valid");
2090
+ return ok(text);
2091
+ }
2092
+ function parseSpanId(text) {
2093
+ if (!SPAN_ID.test(text))
2094
+ return err("a span id is 16 lower-case hexadecimal digits");
2095
+ if (ZEROS.test(text))
2096
+ return err("a span id of all zeros is not valid");
2097
+ return ok(text);
2098
+ }
2099
+ var SAMPLED = 1;
2100
+ var RANDOM = 2;
2101
+ var KNOWN_FLAGS = SAMPLED | RANDOM;
2102
+ var TRACESTATE_MAX_MEMBERS = 32;
2103
+ var KEY_CHAR = "[a-z0-9_\\-*/]";
2104
+ var TRACESTATE_KEY = new RegExp(`^(?:[a-z]${KEY_CHAR}{0,255}|[a-z0-9]${KEY_CHAR}{0,240}@[a-z]${KEY_CHAR}{0,13})$`);
2105
+ var TRACESTATE_VALUE = /^[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]$/;
2106
+ function isTraceStateKey(key) {
2107
+ return TRACESTATE_KEY.test(key);
2108
+ }
2109
+ function isTraceStateValue(value) {
2110
+ return TRACESTATE_VALUE.test(value);
2111
+ }
2112
+ function parseTracestate(header) {
2113
+ const out = [];
2114
+ const seen = new Set;
2115
+ for (const raw of header.split(",")) {
2116
+ if (out.length >= TRACESTATE_MAX_MEMBERS)
2117
+ break;
2118
+ const member = raw.replace(/^[ \t]+|[ \t]+$/g, "");
2119
+ if (member === "")
2120
+ continue;
2121
+ const eq = member.indexOf("=");
2122
+ if (eq < 0)
2123
+ continue;
2124
+ const key = member.slice(0, eq);
2125
+ const value = member.slice(eq + 1);
2126
+ if (!isTraceStateKey(key) || !isTraceStateValue(value) || seen.has(key))
2127
+ continue;
2128
+ seen.add(key);
2129
+ out.push({ key, value });
2130
+ }
2131
+ return out;
2132
+ }
2133
+ var SEVERITY = { TRACE: 1, DEBUG: 5, INFO: 9, WARN: 13, ERROR: 17, FATAL: 21 };
2134
+ function isSeverityNumber(n) {
2135
+ return Number.isInteger(n) && n >= 1 && n <= 24;
2136
+ }
2137
+ var TWO_56 = 2 ** 56;
2138
+ var CREDENTIAL_WORDS = new Set(["key", "code", "sig", "pwd", "pass", "session", "sid", "otp", "awsaccesskeyid", "sas", "se", "sp", "sv"]);
2139
+ function commandShape(argv) {
2140
+ const [program, ...rest] = argv;
2141
+ if (program === undefined)
2142
+ return [];
2143
+ const out = [program.split(/[/\\]/).pop() ?? program];
2144
+ for (const arg of rest) {
2145
+ if (arg === "--")
2146
+ break;
2147
+ if (arg.startsWith("--"))
2148
+ out.push(arg.split("=")[0] ?? arg);
2149
+ else if (arg.startsWith("-") && arg.length > 1 && !/^-[0-9.]/.test(arg))
2150
+ out.push(arg.slice(0, 2));
2151
+ }
2152
+ return out;
2153
+ }
2154
+
2155
+ // ../ts/kernel/otlp.ts
2156
+ var SPAN_KINDS = ["internal", "server", "client", "producer", "consumer"];
2157
+ class Failure extends Error {
2158
+ error;
2159
+ constructor(error) {
2160
+ super(error.path);
2161
+ this.error = error;
2162
+ }
2163
+ }
2164
+ function failure(path, expected, input) {
2165
+ return { kind: "decode", path, expected, found: describe(input) };
2166
+ }
2167
+ function message(build) {
2168
+ return (input, path = "$") => {
2169
+ if (typeof input !== "object" || input === null || Array.isArray(input))
2170
+ return err(failure(path, "an object", input));
2171
+ const read = (key, decoder) => {
2172
+ const r = decoder(Reflect.get(input, key), `${path}.${key}`);
2173
+ if (r.kind === "err")
2174
+ throw new Failure(r.error);
2175
+ return r.value;
2176
+ };
2177
+ const f = {
2178
+ req: read,
2179
+ opt: (key, decoder, fallback) => {
2180
+ const v = Reflect.get(input, key);
2181
+ return v === undefined || v === null ? fallback : read(key, decoder);
2182
+ }
2183
+ };
2184
+ try {
2185
+ return ok(build(f, path));
2186
+ } catch (e) {
2187
+ if (e instanceof Failure)
2188
+ return err(e.error);
2189
+ throw e;
2190
+ }
2191
+ };
2192
+ }
2193
+ function list(element) {
2194
+ return (input, path = "$") => {
2195
+ if (!Array.isArray(input))
2196
+ return err(failure(path, "an array", input));
2197
+ const out = [];
2198
+ for (const [i, value] of input.entries()) {
2199
+ const r = element(value, `${path}[${i}]`);
2200
+ if (r.kind === "err")
2201
+ return r;
2202
+ out.push(r.value);
2203
+ }
2204
+ return ok(out);
2205
+ };
2206
+ }
2207
+ var str = (input, path = "$") => typeof input === "string" ? ok(input) : err(failure(path, "a string", input));
2208
+ var bool = (input, path = "$") => typeof input === "boolean" ? ok(input) : err(failure(path, "a boolean", input));
2209
+ var int64 = (input, path = "$") => {
2210
+ if (typeof input === "number" && Number.isInteger(input))
2211
+ return ok(BigInt(input));
2212
+ if (typeof input === "string" && /^-?[0-9]+$/.test(input))
2213
+ return ok(BigInt(input));
2214
+ return err(failure(path, "a 64-bit integer (a number or a decimal string)", input));
2215
+ };
2216
+ var count = (input, path = "$") => {
2217
+ const r = int64(input, path);
2218
+ if (r.kind === "err")
2219
+ return r;
2220
+ return r.value >= 0n && r.value <= BigInt(Number.MAX_SAFE_INTEGER) ? ok(Number(r.value)) : err(failure(path, "a count", input));
2221
+ };
2222
+ var double = (input, path = "$") => {
2223
+ if (typeof input === "number")
2224
+ return ok(input);
2225
+ if (input === "NaN")
2226
+ return ok(NaN);
2227
+ if (input === "Infinity")
2228
+ return ok(Infinity);
2229
+ if (input === "-Infinity")
2230
+ return ok(-Infinity);
2231
+ return err(failure(path, "a double", input));
2232
+ };
2233
+ var bytes = (input, path = "$") => {
2234
+ if (typeof input !== "string")
2235
+ return err(failure(path, "base64", input));
2236
+ const r = fromBase64(input);
2237
+ return r.kind === "ok" ? r : err(failure(path, "base64", input));
2238
+ };
2239
+ var traceId = (input, path = "$") => {
2240
+ const r = typeof input === "string" ? parseTraceId(input.toLowerCase()) : err("");
2241
+ return r.kind === "ok" ? r : err(failure(path, "a trace id (32 hexadecimal digits, not all zeros)", input));
2242
+ };
2243
+ var spanId = (input, path = "$") => {
2244
+ const r = typeof input === "string" ? parseSpanId(input.toLowerCase()) : err("");
2245
+ return r.kind === "ok" ? r : err(failure(path, "a span id (16 hexadecimal digits, not all zeros)", input));
2246
+ };
2247
+ function enumeration(names) {
2248
+ return (input, path = "$") => {
2249
+ if (typeof input === "number" && Number.isInteger(input) && input >= 0 && input < names.length)
2250
+ return ok(input);
2251
+ if (typeof input === "string") {
2252
+ const i = names.indexOf(input);
2253
+ if (i >= 0)
2254
+ return ok(i);
2255
+ }
2256
+ return err(failure(path, `one of ${names.join(", ")} or its number`, input));
2257
+ };
2258
+ }
2259
+ var spanKindEnum = enumeration([
2260
+ "SPAN_KIND_UNSPECIFIED",
2261
+ "SPAN_KIND_INTERNAL",
2262
+ "SPAN_KIND_SERVER",
2263
+ "SPAN_KIND_CLIENT",
2264
+ "SPAN_KIND_PRODUCER",
2265
+ "SPAN_KIND_CONSUMER"
2266
+ ]);
2267
+ var statusCodeEnum = enumeration(["STATUS_CODE_UNSET", "STATUS_CODE_OK", "STATUS_CODE_ERROR"]);
2268
+ var temporalityEnum = enumeration([
2269
+ "AGGREGATION_TEMPORALITY_UNSPECIFIED",
2270
+ "AGGREGATION_TEMPORALITY_DELTA",
2271
+ "AGGREGATION_TEMPORALITY_CUMULATIVE"
2272
+ ]);
2273
+ var SEVERITY_NAMES = ["SEVERITY_NUMBER_UNSPECIFIED"].concat(["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"].flatMap((r) => ["", "2", "3", "4"].map((n) => `SEVERITY_NUMBER_${r}${n}`)));
2274
+ var severityEnum = (input, path = "$") => {
2275
+ const r = enumeration(SEVERITY_NAMES)(input, path);
2276
+ if (r.kind === "err")
2277
+ return r;
2278
+ return isSeverityNumber(r.value) ? ok(r.value) : err(failure(path, "a severity number from 1 to 24", input));
2279
+ };
2280
+ var decodeAnyValue = (input, path = "$") => {
2281
+ if (typeof input !== "object" || input === null || Array.isArray(input))
2282
+ return err(failure(path, "an AnyValue object", input));
2283
+ const has = (key) => {
2284
+ const v = Reflect.get(input, key);
2285
+ return v !== undefined && v !== null;
2286
+ };
2287
+ const at = (key) => Reflect.get(input, key);
2288
+ if (has("stringValue"))
2289
+ return str(at("stringValue"), `${path}.stringValue`);
2290
+ if (has("boolValue"))
2291
+ return bool(at("boolValue"), `${path}.boolValue`);
2292
+ if (has("intValue"))
2293
+ return int64(at("intValue"), `${path}.intValue`);
2294
+ if (has("doubleValue"))
2295
+ return double(at("doubleValue"), `${path}.doubleValue`);
2296
+ if (has("bytesValue"))
2297
+ return bytes(at("bytesValue"), `${path}.bytesValue`);
2298
+ if (has("arrayValue"))
2299
+ return message((f) => f.opt("values", list(decodeAnyValue), []))(at("arrayValue"), `${path}.arrayValue`);
2300
+ if (has("kvlistValue")) {
2301
+ return message((f) => {
2302
+ const out = {};
2303
+ for (const kv of f.opt("values", list(keyValue(decodeAnyValue)), [])) {
2304
+ Object.defineProperty(out, kv.key, { value: kv.value, enumerable: true, writable: true, configurable: true });
2305
+ }
2306
+ return out;
2307
+ })(at("kvlistValue"), `${path}.kvlistValue`);
2308
+ }
2309
+ return err(failure(path, "an AnyValue holding a value", input));
2310
+ };
2311
+ function keyValue(value) {
2312
+ return message((f) => ({ key: f.req("key", str), value: f.req("value", value) }));
2313
+ }
2314
+ var decodeAttributeValue = (input, path = "$") => {
2315
+ const r = decodeAnyValue(input, path);
2316
+ if (r.kind === "err")
2317
+ return r;
2318
+ const v = r.value;
2319
+ if (typeof v !== "object" || v instanceof Uint8Array)
2320
+ return ok(v);
2321
+ if (Array.isArray(v)) {
2322
+ const values = v;
2323
+ if (values.every((e) => typeof e === "string"))
2324
+ return ok(values.filter((e) => typeof e === "string"));
2325
+ if (values.every((e) => typeof e === "boolean"))
2326
+ return ok(values.filter((e) => typeof e === "boolean"));
2327
+ if (values.every((e) => typeof e === "bigint"))
2328
+ return ok(values.filter((e) => typeof e === "bigint"));
2329
+ if (values.every((e) => typeof e === "number"))
2330
+ return ok(values.filter((e) => typeof e === "number"));
2331
+ }
2332
+ return err(failure(path, "an attribute value (a primitive or a homogeneous array of primitives)", input));
2333
+ };
2334
+ var decodeAttributes = (input, path = "$") => {
2335
+ const r = list(keyValue(decodeAttributeValue))(input, path);
2336
+ if (r.kind === "err")
2337
+ return r;
2338
+ const out = {};
2339
+ for (const kv of r.value)
2340
+ Object.defineProperty(out, kv.key, { value: kv.value, enumerable: true, writable: true, configurable: true });
2341
+ return ok(out);
2342
+ };
2343
+ var resource = message((f) => ({ attributes: f.opt("attributes", decodeAttributes, {}) }));
2344
+ var scope = message((f) => {
2345
+ const version = f.opt("version", str, undefined);
2346
+ const attributes = f.opt("attributes", decodeAttributes, undefined);
2347
+ return {
2348
+ name: f.opt("name", str, ""),
2349
+ ...version === undefined ? {} : { version },
2350
+ ...attributes === undefined ? {} : { attributes }
2351
+ };
2352
+ });
2353
+ var event = message((f) => ({
2354
+ name: f.opt("name", str, ""),
2355
+ time: f.opt("timeUnixNano", int64, 0n),
2356
+ attributes: f.opt("attributes", decodeAttributes, {}),
2357
+ droppedAttributesCount: f.opt("droppedAttributesCount", count, 0)
2358
+ }));
2359
+ var link = message((f) => ({
2360
+ traceId: f.req("traceId", traceId),
2361
+ spanId: f.req("spanId", spanId),
2362
+ traceState: parseTracestate(f.opt("traceState", str, "")),
2363
+ traceFlags: f.opt("flags", count, 0) & 255,
2364
+ attributes: f.opt("attributes", decodeAttributes, {}),
2365
+ droppedAttributesCount: f.opt("droppedAttributesCount", count, 0)
2366
+ }));
2367
+ var status = message((f) => {
2368
+ const code = f.opt("code", statusCodeEnum, 0);
2369
+ if (code === 1)
2370
+ return { kind: "ok" };
2371
+ if (code === 2)
2372
+ return { kind: "error", message: f.opt("message", str, "") };
2373
+ return { kind: "unset" };
2374
+ });
2375
+ var optionalSpanId = (input, path = "$") => input === "" ? ok(undefined) : spanId(input, path);
2376
+ var decodeSpan = message((f) => {
2377
+ const parentSpanId = f.opt("parentSpanId", optionalSpanId, undefined);
2378
+ const kind = f.opt("kind", spanKindEnum, 1);
2379
+ return {
2380
+ name: f.opt("name", str, ""),
2381
+ context: {
2382
+ traceId: f.req("traceId", traceId),
2383
+ spanId: f.req("spanId", spanId),
2384
+ traceFlags: f.opt("flags", count, 0) & 255,
2385
+ traceState: parseTracestate(f.opt("traceState", str, "")),
2386
+ isRemote: false
2387
+ },
2388
+ ...parentSpanId === undefined ? {} : { parentSpanId },
2389
+ kind: SPAN_KINDS[kind - 1] ?? "internal",
2390
+ startTime: f.opt("startTimeUnixNano", int64, 0n),
2391
+ endTime: f.opt("endTimeUnixNano", int64, 0n),
2392
+ attributes: f.opt("attributes", decodeAttributes, {}),
2393
+ events: f.opt("events", list(event), []),
2394
+ links: f.opt("links", list(link), []),
2395
+ status: f.opt("status", status, { kind: "unset" }),
2396
+ droppedAttributesCount: f.opt("droppedAttributesCount", count, 0),
2397
+ droppedEventsCount: f.opt("droppedEventsCount", count, 0),
2398
+ droppedLinksCount: f.opt("droppedLinksCount", count, 0)
2399
+ };
2400
+ });
2401
+ var optionalTraceId = (input, path = "$") => input === "" ? ok(undefined) : traceId(input, path);
2402
+ var decodeLogRecord = message((f) => {
2403
+ const body = f.opt("body", decodeAnyValue, undefined);
2404
+ const traceFlags = f.opt("flags", count, undefined);
2405
+ const tid = f.opt("traceId", optionalTraceId, undefined);
2406
+ const sid = f.opt("spanId", optionalSpanId, undefined);
2407
+ const eventName = f.opt("eventName", str, undefined);
2408
+ return {
2409
+ time: f.opt("timeUnixNano", int64, 0n),
2410
+ observedTime: f.opt("observedTimeUnixNano", int64, 0n),
2411
+ severityNumber: f.req("severityNumber", severityEnum),
2412
+ severityText: f.opt("severityText", str, ""),
2413
+ ...body === undefined ? {} : { body },
2414
+ attributes: f.opt("attributes", decodeAttributes, {}),
2415
+ droppedAttributesCount: f.opt("droppedAttributesCount", count, 0),
2416
+ ...eventName === undefined ? {} : { eventName },
2417
+ ...tid === undefined ? {} : { traceId: tid },
2418
+ ...sid === undefined ? {} : { spanId: sid },
2419
+ ...traceFlags === undefined ? {} : { traceFlags: traceFlags & 255 }
2420
+ };
2421
+ });
2422
+ var numberPoint = message((f, path) => {
2423
+ const asInt = f.opt("asInt", int64, undefined);
2424
+ const asDouble = f.opt("asDouble", double, undefined);
2425
+ const value = asInt ?? asDouble;
2426
+ if (value === undefined)
2427
+ throw new Failure(failure(`${path}.asDouble`, "asInt or asDouble", undefined));
2428
+ return {
2429
+ attributes: f.opt("attributes", decodeAttributes, {}),
2430
+ startTime: f.opt("startTimeUnixNano", int64, 0n),
2431
+ time: f.opt("timeUnixNano", int64, 0n),
2432
+ value
2433
+ };
2434
+ });
2435
+ var histogramPoint = message((f, path) => {
2436
+ const sum = f.opt("sum", double, undefined);
2437
+ const min = f.opt("min", double, undefined);
2438
+ const max = f.opt("max", double, undefined);
2439
+ const bounds = f.opt("explicitBounds", list(double), []);
2440
+ const bucketCounts = f.opt("bucketCounts", list(count), []);
2441
+ if (bucketCounts.length !== 0 && bucketCounts.length !== bounds.length + 1) {
2442
+ throw new Failure(failure(`${path}.bucketCounts`, `${bounds.length + 1} bucket counts`, bucketCounts.length));
2443
+ }
2444
+ return {
2445
+ attributes: f.opt("attributes", decodeAttributes, {}),
2446
+ startTime: f.opt("startTimeUnixNano", int64, 0n),
2447
+ time: f.opt("timeUnixNano", int64, 0n),
2448
+ count: f.opt("count", count, 0),
2449
+ ...sum === undefined ? {} : { sum },
2450
+ ...min === undefined ? {} : { min },
2451
+ ...max === undefined ? {} : { max },
2452
+ bounds,
2453
+ bucketCounts
2454
+ };
2455
+ });
2456
+ function temporalityOf(n) {
2457
+ return n === 1 ? "delta" : "cumulative";
2458
+ }
2459
+ var decodeMetric = message((f, path) => {
2460
+ const head = { name: f.opt("name", str, ""), description: f.opt("description", str, ""), unit: f.opt("unit", str, "") };
2461
+ const sum = f.opt("sum", message((g) => ({
2462
+ kind: "sum",
2463
+ points: g.opt("dataPoints", list(numberPoint), []),
2464
+ temporality: temporalityOf(g.opt("aggregationTemporality", temporalityEnum, 2)),
2465
+ monotonic: g.opt("isMonotonic", bool, false)
2466
+ })), undefined);
2467
+ if (sum !== undefined)
2468
+ return { ...head, data: sum };
2469
+ const gauge = f.opt("gauge", message((g) => ({ kind: "gauge", points: g.opt("dataPoints", list(numberPoint), []) })), undefined);
2470
+ if (gauge !== undefined)
2471
+ return { ...head, data: gauge };
2472
+ const histogram = f.opt("histogram", message((g) => ({
2473
+ kind: "histogram",
2474
+ points: g.opt("dataPoints", list(histogramPoint), []),
2475
+ temporality: temporalityOf(g.opt("aggregationTemporality", temporalityEnum, 2))
2476
+ })), undefined);
2477
+ if (histogram !== undefined)
2478
+ return { ...head, data: histogram };
2479
+ throw new Failure(failure(`${path}.sum`, "a sum, a gauge or a histogram", undefined));
2480
+ });
2481
+
2482
+ // ../ts/kernel/signals.ts
2483
+ var ATTRIBUTE_TYPES = new Set([
2484
+ "string",
2485
+ "boolean",
2486
+ "int",
2487
+ "double",
2488
+ "bytes",
2489
+ "string[]",
2490
+ "boolean[]",
2491
+ "int[]",
2492
+ "double[]"
2493
+ ]);
2494
+ function defineSignals(kinds) {
2495
+ for (const [name, d] of Object.entries(kinds)) {
2496
+ const declared = new Set(Object.keys(d.attributes).map((k) => k.replace(/\?$/, "")));
2497
+ for (const [k, t] of Object.entries(d.attributes)) {
2498
+ if (!ATTRIBUTE_TYPES.has(t))
2499
+ throw new Error(`${name}: the attribute ${k} has the type ${t}, which does not exist`);
2662
2500
  }
2663
- },
2664
- "http.server": {
2665
- signal: "span",
2666
- spanKind: "server",
2667
- role: "detail",
2668
- description: "A request answered by serve; its parent is the request's traceparent.",
2669
- attributes: {
2670
- "http.request.method": "string",
2671
- "url.path": "string",
2672
- "url.scheme": "string",
2673
- "server.address?": "string",
2674
- "server.port?": "int",
2675
- "http.response.status_code?": "int"
2501
+ for (const s of d.secret ?? [])
2502
+ if (!declared.has(s))
2503
+ throw new Error(`${name}: the secret attribute ${s} is not declared`);
2504
+ if (d.signal === "histogram" && d.bounds !== undefined) {
2505
+ const b = d.bounds;
2506
+ if (b.some((x, i) => !Number.isFinite(x) || i > 0 && x <= (b[i - 1] ?? -Infinity))) {
2507
+ throw new Error(`${name}: the histogram bounds do not increase`);
2508
+ }
2676
2509
  }
2677
- },
2678
- "otel.warning": {
2679
- signal: "log",
2680
- severity: SEVERITY.WARN,
2681
- role: "none",
2682
- description: "Signals were not sent: an export failed, no collector answered, or the wait at exit ran out.",
2683
- attributes: {}
2684
2510
  }
2685
- });
2686
- var UNTRACED = new WeakSet;
2511
+ return { kinds };
2512
+ }
2687
2513
 
2688
- // ../ts/runtime/proc.ts
2514
+ // ../system/src/proc.ts
2689
2515
  import process from "node:process";
2516
+ var tracer;
2517
+ function setProcessTracer(t) {
2518
+ tracer = t;
2519
+ }
2690
2520
  var args = Object.freeze(process.argv.slice(2));
2691
2521
  var pid = process.pid;
2692
2522
  function osOf(platform) {
@@ -2749,6 +2579,74 @@ var build = Object.freeze({
2749
2579
  target: tripleOf(osOf(process.platform), archOf(process.arch))
2750
2580
  });
2751
2581
 
2582
+ // ../ts/runtime/otel.ts
2583
+ var RETRYABLE_STATUSES = new Set([429, 502, 503, 504]);
2584
+ var DAY_MS = 24 * 60 * 60 * 1000;
2585
+ var RUNTIME_SIGNALS = defineSignals({
2586
+ process: {
2587
+ signal: "span",
2588
+ spanKind: "client",
2589
+ role: "detail",
2590
+ description: "A program run by proc: its name and option names alone (FR-006), and its exit status.",
2591
+ attributes: { "process.executable.name": "string", "process.command_args": "string[]", "process.exit.code?": "int" }
2592
+ },
2593
+ "http.client": {
2594
+ signal: "span",
2595
+ spanKind: "client",
2596
+ role: "detail",
2597
+ description: "A request made by the HTTP client; the URL redacted (FR-006).",
2598
+ attributes: {
2599
+ "http.request.method": "string",
2600
+ "url.full": "string",
2601
+ "server.address": "string",
2602
+ "server.port?": "int",
2603
+ "http.response.status_code?": "int",
2604
+ "error.type?": "string"
2605
+ }
2606
+ },
2607
+ "http.server": {
2608
+ signal: "span",
2609
+ spanKind: "server",
2610
+ role: "detail",
2611
+ description: "A request answered by serve; its parent is the request's traceparent.",
2612
+ attributes: {
2613
+ "http.request.method": "string",
2614
+ "url.path": "string",
2615
+ "url.scheme": "string",
2616
+ "server.address?": "string",
2617
+ "server.port?": "int",
2618
+ "http.response.status_code?": "int"
2619
+ }
2620
+ },
2621
+ "otel.warning": {
2622
+ signal: "log",
2623
+ severity: SEVERITY.WARN,
2624
+ role: "none",
2625
+ description: "Signals were not sent: an export failed, no collector answered, or the wait at exit ran out.",
2626
+ attributes: {}
2627
+ }
2628
+ });
2629
+ var current;
2630
+ function carried(r) {
2631
+ return r.kind === "ok" ? r.value : r.error.value;
2632
+ }
2633
+ function traceProcess(argv, run) {
2634
+ const c = current;
2635
+ if (c === undefined)
2636
+ return run({});
2637
+ const shape = commandShape(argv);
2638
+ return c.runtime.span("process", { "process.executable.name": shape[0] ?? "", "process.command_args": shape }, async (span) => {
2639
+ const env = { TRACEPARENT: span.traceparent };
2640
+ if (span.tracestate !== "")
2641
+ env["TRACESTATE"] = span.tracestate;
2642
+ const r = await run(env);
2643
+ span.set({ "process.exit.code": r.code });
2644
+ return r.code === 0 ? ok(r) : err({ value: r, message: `${shape[0] ?? "the program"} exited with ${r.code}` });
2645
+ }).then(carried);
2646
+ }
2647
+ setProcessTracer(traceProcess);
2648
+ var UNTRACED = new WeakSet;
2649
+
2752
2650
  // ../ts/runtime/http-client.ts
2753
2651
  var exchangeDecoder = object({
2754
2652
  method: literal("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"),
@@ -3820,7 +3718,7 @@ export {
3820
3718
  MODULE_SOURCES,
3821
3719
  REPO_PATH_ROOM,
3822
3720
  REPO_STATE_KINDS,
3823
- SEVERITIES2 as SEVERITIES,
3721
+ SEVERITIES,
3824
3722
  SHELLS,
3825
3723
  STATE_RECORD_PATH,
3826
3724
  TEMPLATES,
@@ -3830,7 +3728,7 @@ export {
3830
3728
  branchName,
3831
3729
  checkFiles,
3832
3730
  checkPathLength,
3833
- child2 as child,
3731
+ child,
3834
3732
  classify,
3835
3733
  classifyFs,
3836
3734
  collisions,