mirror of
https://github.com/morluto/rea.git
synced 2026-10-29 19:05:45 +00:00
Share parser modes and collision-free composite keys, enforce architecture guards, and consolidate redundant unit assertions into filesystem, CLI, MCP, and producer-backed workflows. Preserve concurrent upstream boundary fixes and exclude legacy Objective-C class-name bookkeeping labels. Validation: source/composition suites (3358 passing), focused canonical digest and MCP checks, typecheck/lint, Knip, formatting, architecture guards, and real Foundation archive and Apple legacy simulator CLI/MCP verification. No real Hopper, Ghidra, or IDA verification claim.
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { z } from "zod";
|
|
|
|
/**
|
|
* Canonical digest and identifier shapes.
|
|
*
|
|
* These were previously a hand-copied regex in ~30 modules: 32 local
|
|
* `digestSchema` definitions plus a distinct literal for each of roughly
|
|
* thirty `prefix_hash` identifier families. Nothing kept them in step, so a
|
|
* change to what counts as a digest had to be found and repeated by hand.
|
|
*
|
|
* One owner means the shape is stated once, and a new identifier family
|
|
* cannot accidentally invent its own spelling of "lowercase sha256".
|
|
*/
|
|
|
|
/** Lowercase hex SHA-256, as every digest in the system is emitted. */
|
|
export const SHA256_PATTERN = /^[a-f0-9]{64}$/u;
|
|
|
|
/** A bare artifact/content digest. */
|
|
export const digestSchema = z.string().regex(SHA256_PATTERN);
|
|
|
|
/**
|
|
* A namespaced identifier: `<prefix>_<64 lowercase hex>`. Prefixes keep
|
|
* identifiers from different families apart at a glance and make a
|
|
* mis-pasted identifier from another family fail validation rather than
|
|
* resolve to the wrong object.
|
|
*/
|
|
export const prefixedDigestSchema = (prefix: string): z.ZodString =>
|
|
z
|
|
.string()
|
|
.regex(
|
|
new RegExp(`^${prefix}_[a-f0-9]{64}$`, "u"),
|
|
`Expected a ${prefix}_ prefixed lowercase sha256 digest`,
|
|
);
|
|
|
|
/** True when `value` is a bare digest. */
|
|
export const isDigest = (value: unknown): value is string =>
|
|
typeof value === "string" && SHA256_PATTERN.test(value);
|