@ultimat3/core 31.43.0 → 31.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -412,8 +412,10 @@ The `envSchema` export is the one declaration form: `x env`, `x secrets` and `x
412
412
  and an app's `undeclared-env` guard refuses a `defineEnv` handed anything else.
413
413
 
414
414
  Every missing or malformed key is listed in one `X_ENV_MISSING`. `secret: true` keys are
415
- redacted in logs and masked in `checkEnv()` output; the env summary (`describeEnv()`, internal) emits declarations only,
416
- safe for `x.manifest.json`. Omit `required` for required — `required: false` is the only
415
+ redacted in logs. `maskedEnvValues(schema, values)` — what `x env check --json` prints — masks every
416
+ `secret: true` key **and** every key `isRedactedKey` names (`DATABASE_URL`, `STRIPE_KEY`), and cuts
417
+ the password from any other value's URL userinfo; the env summary (`describeEnv()`, internal) emits
418
+ declarations only, safe for `x.manifest.json`. Omit `required` for required — `required: false` is the only
417
419
  loosening. Never declare an env var for *which deploy this is* — that is `ULTIMATE_ENV`, below.
418
420
 
419
421
  `.env.example` is a **projection** of that schema, never a second list:
@@ -484,6 +486,12 @@ such as `cardPin` or `pinCode`) and a stored hash of any of them (`passwordHash`
484
486
  leaves `idempotencyToken`, a paging token, `maxTokens`, an error `code`, `spinner`, `isPinned`,
485
487
  `sessionStart` and `cookieName` readable — a redacted field is one an operator cannot correlate on.
486
488
 
489
+ A URL's userinfo has one cut too: `replaceUrlUserinfo(text, render)` ends it at the **last** `@`
490
+ before the authority's `/`, `?` or `#` — where a URL parser ends it — so `u:hunter@2secret@host`
491
+ loses the whole password, never just `hunter`. `redactUrlPassword(text)` keeps the user and prints
492
+ `user:[redacted]@host`; `x config`, `x repro`, `maskedEnvValues` and an `X_OUTBOUND_*` cause all
493
+ cut through it.
494
+
487
495
  `LOG_LEVEL` is refused when it is not one of `LOG_LEVELS` (lowercase), exactly as
488
496
  `structuredLogger({ level })` refuses it; unset or empty is `info`.
489
497
 
@@ -594,7 +602,7 @@ match with `sealAll()`; uniqueness cannot be held across keys.
594
602
  barrel's and `./page`'s `systemClock` is a plain `Clock` — browser code reads it and nothing there
595
603
  waits; the sleeping one is `./adapter`'s `systemClock` (`sleep-clock.ts`, server-only).
596
604
  - `uuidV7()` is UUIDv7: time-prefixed, monotonic within a millisecond, never backwards on clock
597
- skew. `typedId<'post'>()` brands it so a post id cannot be passed where a user id is wanted.
605
+ skew. A clock before 1970 (a `frozenClock` may read one) mints at timestamp 0, still monotonic. `typedId<'post'>()` brands it so a post id cannot be passed where a user id is wanted.
598
606
  - `withSpan('action.publishPost', fn)` builds no record until something subscribes to `span.end`.
599
607
  Traces cross process boundaries via `traceparent()` / `parseTraceparent()`, whose ids come from
600
608
  `traceId()` / `spanId()` — **never `uuidV7()`**, whose dashed 36 characters every collector
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "31.43.0",
3
+ "version": "31.45.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -54,6 +54,6 @@
54
54
  "test": "bun test"
55
55
  },
56
56
  "dependencies": {
57
- "@ultimat3/schema": "31.43.0"
57
+ "@ultimat3/schema": "31.45.0"
58
58
  }
59
59
  }
package/src/env.ts CHANGED
@@ -5,8 +5,9 @@
5
5
  import { numeric } from '@ultimat3/schema';
6
6
  import { describeValue, renderFixShellArg } from './error-render';
7
7
  import { EnvMissingError } from './errors';
8
- import { REDACTED, redactKeys } from './logger';
8
+ import { isRedactedKey, REDACTED, redactKeys } from './logger';
9
9
  import { type Role, resolveRole } from './roles';
10
+ import { redactUrlPassword } from './url-userinfo';
10
11
 
11
12
  export type EnvVarType = 'string' | 'url' | 'number' | 'integer' | 'port' | 'boolean' | 'enum';
12
13
 
@@ -252,10 +253,11 @@ export function defineEnv<const S extends EnvSchema>(schema: S, options?: EnvOpt
252
253
  }
253
254
 
254
255
  /**
255
- * The resolved values with every `secret: true` key replaced. `checkEnv().values` carries the REAL
256
- * values because `defineEnv()` has to return them — so anything that PRINTS a report (`x env check
257
- * --json`, a doctor line, a log field) renders this instead, and the masking lives in one place
258
- * rather than at each printer.
256
+ * The resolved values with every `secret: true` key AND every credential-named key (`isRedactedKey`,
257
+ * the logger's and `x config`'s rule) replaced, and any other string's URL password cut from its
258
+ * userinfo. `checkEnv().values` carries the REAL values because `defineEnv()` has to return them —
259
+ * so anything that PRINTS a report (`x env check --json`, a doctor line, a log field) renders this
260
+ * instead, and the masking lives in one place rather than at each printer.
259
261
  */
260
262
  export function maskedEnvValues(
261
263
  schema: EnvSchema,
@@ -263,7 +265,9 @@ export function maskedEnvValues(
263
265
  ): Readonly<Record<string, unknown>> {
264
266
  const out: Record<string, unknown> = {};
265
267
  for (const [key, value] of Object.entries(values)) {
266
- out[key] = schema[key]?.secret === true && value !== undefined ? REDACTED : value;
268
+ if (value === undefined) out[key] = value;
269
+ else if (schema[key]?.secret === true || isRedactedKey(key)) out[key] = REDACTED;
270
+ else out[key] = typeof value === 'string' ? redactUrlPassword(value) : value;
267
271
  }
268
272
  return Object.freeze(out);
269
273
  }
package/src/ids.ts CHANGED
@@ -105,17 +105,24 @@ function hexOf(byteLength: number): string {
105
105
  * UUIDv7 per RFC 9562: 48-bit unix ms, version 7, 12-bit monotonic counter, 62 random bits.
106
106
  * Strictly increasing lexicographically even within the same millisecond, and never goes
107
107
  * backwards when the wall clock does.
108
+ *
109
+ * A pre-1970 clock mints at timestamp 0 (the field's floor), still monotonic: `frozenClock`
110
+ * accepts such an instant on purpose — a test pinned to 1969 — and an id that cannot encode it
111
+ * sorts first rather than refusing every context built on that clock. An Invalid Date and an
112
+ * instant past 2^48-1 ms are still refused (`X_INVARIANT`).
108
113
  */
109
114
  export function uuidV7(clock: Clock = systemClock): string {
110
- let epochMs = clock.now().getTime();
115
+ const read = clock.now().getTime();
116
+ // `Math.max` keeps `NaN` as `NaN`, so an Invalid Date still reaches the refusal below.
117
+ let epochMs = Math.max(read, 0);
111
118
  // Before the clamp and before `lastEpochMs` is written: an Invalid Date minted `…-0NaN-7…` and
112
119
  // stored `NaN` as the high-water mark, so the next id skipped the clamp and could sort first.
113
120
  // `assert` only on the failing branch: its messages would otherwise be built on every id.
114
121
  if (!(epochMs >= 0 && epochMs <= MAX_EPOCH_MS)) {
115
122
  assert(
116
123
  false,
117
- `uuidV7's clock read ${String(epochMs)} ms: a UUIDv7 holds 0 to 2^48-1 unix ms, so an Invalid Date or a pre-1970 instant has no encoding`,
118
- "uuidV7(frozenClock('2026-01-01T00:00:00Z')) // a clock at a valid instant on or after 1970",
124
+ `uuidV7's clock read ${String(read)} ms: a UUIDv7 holds up to 2^48-1 unix ms, so an Invalid Date or an instant past the year 10889 has no encoding`,
125
+ "uuidV7(frozenClock('2026-01-01T00:00:00Z')) // a clock at a valid instant",
119
126
  );
120
127
  }
121
128
  if (epochMs < lastEpochMs) epochMs = lastEpochMs;
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export type {
29
29
  ActorOrigin,
30
30
  } from './actor';
31
31
  export {
32
+ ACTOR_KINDS,
32
33
  actorFact,
33
34
  actorLabel,
34
35
  actorOf,
@@ -1001,6 +1002,7 @@ export type { ToolDescriptionSource } from './tool-description';
1001
1002
  // A projected tool's description: `@ultimat3/mcp`'s and `@ultimat3/ai`'s, one tier apart from neither.
1002
1003
  export { toolDescription } from './tool-description';
1003
1004
  export { trimTrailingSlashes } from './trailing-slashes';
1005
+ export { redactUrlPassword, replaceUrlUserinfo } from './url-userinfo';
1004
1006
  export {
1005
1007
  frameworkVersion,
1006
1008
  readPackageVersion,
@@ -5,6 +5,7 @@
5
5
  import { renderFixShellArg, renderThrowable } from './error-render';
6
6
  import { registerErrorRetry } from './error-retry';
7
7
  import { UltimateError } from './errors';
8
+ import { replaceUrlUserinfo } from './url-userinfo';
8
9
 
9
10
  /**
10
11
  * The eleven codes' retry classes, registered HERE and not in `error-retry.ts`'s core table: that
@@ -67,14 +68,13 @@ export function outboundTimeout(
67
68
  }
68
69
 
69
70
  /**
70
- * A transport failure in its own words with every query string cut (`?…`) and every URL's
71
- * userinfo cut (`//…@`): a runtime's message may quote the URL it was dialling, a signed URL keeps
72
- * its credential in the query, and a proxy URL keeps it before the `@`.
71
+ * A transport failure in its own words with every URL's userinfo cut (`//…@`) and every query
72
+ * string cut (`?…`): a runtime's message may quote the URL it was dialling, a proxy URL keeps its
73
+ * credential before the LAST `@` (`replaceUrlUserinfo`), and a signed URL keeps it in the query.
74
+ * Userinfo first: a `?` the query cut stops at would otherwise end an authority early.
73
75
  */
74
76
  export const transportText = (error: unknown): string =>
75
- renderThrowable(error)
76
- .replaceAll(/\?[^\s"'`)]*/g, '?…')
77
- .replaceAll(/\/\/[^\s"'`/?#@]*@/g, '//…@');
77
+ replaceUrlUserinfo(renderThrowable(error), () => '…').replaceAll(/\?[^\s"'`)]*/g, '?…');
78
78
 
79
79
  /** The refusals that say the CALLER's bound ran out, not the vendor: a breaker hears nothing. */
80
80
  const CALLER_BOUND = new WeakSet<UltimateError>();
@@ -0,0 +1,34 @@
1
+ // Single responsibility: find every URL's userinfo in a string and hand it to a renderer — the one
2
+ // rule the redactors share. A URL parser ends the userinfo at the LAST `@` before the authority's
3
+ // end, so a password holding a raw `@` (`u:hunter@2secret@host`) is cut whole, never at its first.
4
+
5
+ import { REDACTED } from './secret';
6
+
7
+ /**
8
+ * An authority: after `//`, up to the first `/`, `?` or `#` (WHATWG's end), or anything prose ends
9
+ * a URL with — whitespace, a quote, a bracket. Greedy, so the last `@` inside it is the parser's.
10
+ */
11
+ const AUTHORITY = /\/\/([^\s"'`<>()/?#]*)/g;
12
+
13
+ /**
14
+ * Every `//userinfo@host` in `text` rewritten as `//render(userinfo)@host`; a URL with no `@` in
15
+ * its authority, and an `@` past the path, query or fragment, are left as written. The renderer
16
+ * decides how much survives: the user alone, a marker, nothing.
17
+ */
18
+ export function replaceUrlUserinfo(text: string, render: (userinfo: string) => string): string {
19
+ return text.replace(AUTHORITY, (whole: string, authority: string) => {
20
+ const at = authority.lastIndexOf('@');
21
+ return at < 0 ? whole : `//${render(authority.slice(0, at))}${authority.slice(at)}`;
22
+ });
23
+ }
24
+
25
+ /**
26
+ * `scheme://user:password@host` → `scheme://user:[redacted]@host`, for every URL in `text`. The
27
+ * user stays — it is no secret — and the password runs to the userinfo's LAST `@`, raw `@` and `:`
28
+ * included. What `x config` and `maskedEnvValues` print.
29
+ */
30
+ export const redactUrlPassword = (text: string): string =>
31
+ replaceUrlUserinfo(text, (userinfo) => {
32
+ const colon = userinfo.indexOf(':');
33
+ return colon < 0 ? userinfo : `${userinfo.slice(0, colon)}:${REDACTED}`;
34
+ });