Local-first 🧠memory for Hermes Agent that lives in your Obsidian vault and remembers project context. Nightly 😴 dream passes turn repeat corrections into confirmed preferences with measurable confidence. Adapters ship for Claude Code, Codex, and OpenClaw, with an MCP server for anything else.
TypeScript
/**
* Census over the closed verdict vocabularies.
*
* The silence-is-not-an-answer wave turns "could not check" into a
* first-class value in several unrelated subsystems. Each one owns its own
* vocabulary, because a suppression status, a coverage verdict and an
* archive-inclusion decision are not the same type - but they all follow
* one convention this project already uses: a frozen object of values, a
* companion list of members, and a type guard that decides whether a
* string read back off disk is one of them.
*
* That trio can drift. A value added to the object and forgotten in the
* list makes the guard reject a value the code itself produces; a guard
* written against a stale list silently rejects a member. Grounding found
* exactly this class already shipped elsewhere - a status list copied as a
* literal into a tool schema with nothing asserting the two agree.
*
* This file is the assertion that they agree. Every vocabulary the wave
* introduces registers below, and so does any closed vocabulary whose
* values the wave copies OUT of TypeScript - a code interpolated into an
* emitted shell script is the same drift risk by another route.
*
* It deliberately does NOT require values to be unique across
* vocabularies. An absent config file and an absent store file are both
* honestly named `absent`, and forcing them apart would buy nothing.
*
* ## The population is READ, not remembered
*
* The registry below used to be the whole file: a hand-written list of
* imports, auditing the vocabularies somebody remembered to add and
* nothing at all about the ones they did not. A new module carrying a
* duplicate value, a phantom member and a guard that accepts every
* string ran clean, because an unregistered vocabulary was invisible.
* {@link scanVocabularies} closes that: it walks `src/`, finds every
* vocabulary that carries the FOUR-PIECE shape, and
* {@link CENSUS} must account for each one.
*
* The four pieces, all four required and all four in one module:
*
* 1. `const NAME = Object.freeze({ … })` whose every entry is
* `key: "string literal"`;
* 2. a union derived from it - `(typeof NAME)[keyof typeof NAME]`;
* 3. a membership list built from it - a const initialised from
* `Object.values(NAME)` or from an array of `NAME.member`;
* 4. a guard: a function or arrow taking a parameter typed `unknown`
* that reads the membership list or the object.
*
* All four, because all four is exactly what {@link auditVocabulary}
* audits: two of its seven checks ask what the guard accepts, and an
* object with no guard is one whose values never have to survive the
* round trip through a string that the guard exists to police.
* Widening the rule to three pieces would also enrol lists that are
* curated ORDERINGS rather than membership - `DREAM_STEP_RUNNABLE` (the
* steps that can be run on their own) and `DREAM_GATE_NAMES` (the gates
* an operator may override). Both name every member of their object
* today; the day one of them does not - a step that cannot run alone, a
* gate that is not overridable - that is a correct divergence, and a
* census that reported it as drift would be teaching contributors to
* ignore it. That is also why there is no exemption list here: a
* construct with all four pieces has nothing to be excused from, and an
* empty escape hatch is an invitation rather than a policy.
*
* ## What the scan cannot see, stated rather than implied
*
* It reads text, not a parse tree - this repository has one runtime
* dependency and no TypeScript AST library - so it masks comments and
* string CONTENTS before matching (a `"{"` inside a value cannot
* mis-terminate a body) and then reads brackets. What that still leaves:
*
* - A vocabulary SPLIT ACROSS MODULES: object here, membership list or
* guard there. Detection is per-file, so a split trio is out of
* population entirely. No vocabulary in this tree is split.
* - A vocabulary with no membership list or no guard. Two pieces are
* not the idiom, and there is nothing for the audit to compare -
* but it is the cheapest way to leave the population, so it is named
* here rather than left for a reader to discover.
* - Values that are not literals in the object: a spread of another
* object, a computed key's value, a value built by a call. Any of
* these drops the object out of the population.
* - A guard whose parameter is typed `string`. It is a guard that can
* only be called once the caller proved what it was asked to prove,
* and the idiom's own rule is `unknown`.
* - Trees other than `src/`. `hooks/`, `scripts/` and `plugins/`
* declare no derived-union vocabulary today; if one appears there it
* is invisible until this root list grows.
* - Code inside a `${…}` interpolation: a template literal is blanked
* whole, so a vocabulary piece written inside one is not read. A
* template can also legally span lines, which is why the masker's
* "a quote with no partner on this line is not a string" rule - the
* rule that keeps a regex literal such as `/["]/` from blanking the
* rest of a module - applies to `"` and `'` only.
*
* The progress census next door reads its population the same way, off a
* lexed view with offsets preserved, and states its own blind spots in
* the same place. Two censuses, one technique; the shared lexer they both
* deserve is a consolidation neither owns alone.
*
* Each of those is a shape a future contributor could write. The
* "the scan sees the shapes it claims to" block below pins the ones it
* DOES see, one synthetic module per shape - and, in the same block, the
* frozen objects that must stay OUT - so a scan that quietly stops
* matching fails by name instead of reporting a smaller population.
*/
import { describe, expect, test } from "bun:test";
import { readdirSync, readFileSync } from "node:fs";
import { join, relative } from "node:path";
import {
isSchemaPackIntegrityStatus,
isSchemaPackUnverifiedReason,
SCHEMA_PACK_INTEGRITY,
SCHEMA_PACK_INTEGRITY_STATUSES,
SCHEMA_PACK_UNVERIFIED_REASON,
SCHEMA_PACK_UNVERIFIED_REASONS,
} from "../../../src/core/brain/schema-integrity.ts";
import {
isSkillBenchCheck,
isSkillBenchTaskKind,
isSkillBenchValueClass,
SKILL_BENCH_CHECK,
SKILL_BENCH_CHECKS,
SKILL_BENCH_TASK_KIND,
SKILL_BENCH_TASK_KINDS,
SKILL_BENCH_VALUE_CLASS,
SKILL_BENCH_VALUE_CLASSES,
} from "../../../src/core/brain/skill-rewrite-tasks.ts";
import {
isSkillRewriteMode,
isSkillRewriteRoundArm,
isSkillRewriteVerdict,
SKILL_REWRITE_MODE,
SKILL_REWRITE_MODES,
SKILL_REWRITE_ROUND_ARM,
SKILL_REWRITE_ROUND_ARMS,
SKILL_REWRITE_VERDICT,
SKILL_REWRITE_VERDICTS,
} from "../../../src/core/brain/skill-rewrite.ts";
import {
isLessonsBlockState,
LESSONS_BLOCK_STATE,
LESSONS_BLOCK_STATES,
} from "../../../src/core/brain/doctor/lessons-block-check.ts";
import {
isNegativeRecallState,
isNegativeRecallUnknownReason,
isRetractionEvidenceKind,
NEGATIVE_RECALL_STATE,
NEGATIVE_RECALL_STATES,
NEGATIVE_RECALL_UNKNOWN_REASON,
NEGATIVE_RECALL_UNKNOWN_REASONS,
RETRACTION_EVIDENCE_KIND,
RETRACTION_EVIDENCE_KINDS,
} from "../../../src/core/brain/negative-recall.ts";
import {
isStaleDependencyConsumerKind,
isStaleDependencyStateKind,
STALE_DEPENDENCY_CONSUMER,
STALE_DEPENDENCY_CONSUMERS,
STALE_DEPENDENCY_STATE,
STALE_DEPENDENCY_STATES,
} from "../../../src/core/brain/doctor/stale-dependency-check.ts";
import {
isSnapshotStoreExclusionReason,
SNAPSHOT_STORE_EXCLUSION,
SNAPSHOT_STORE_EXCLUSION_REASONS,
} from "../../../src/core/brain/manifest.ts";
import {
isSnapshotEntrySkipReason,
isSnapshotPruneRefusal,
SNAPSHOT_ENTRY_SKIP_REASON,
SNAPSHOT_ENTRY_SKIP_REASONS,
SNAPSHOT_PRUNE_REFUSAL,
SNAPSHOT_PRUNE_REFUSALS,
} from "../../../src/core/brain/snapshot.ts";
import { GATE_MODE, GATE_MODES, isGateMode } from "../../../src/core/integrity/stamp.ts";
import { REVIEW_LANE, REVIEW_LANES, isReviewLane } from "../../../src/core/brain/write-gate.ts";
import { isToolScope, TOOL_SCOPE, TOOL_SCOPES } from "../../../src/mcp/tool-contract.ts";
import {
isRuntimeTarget,
KNOWN_RUNTIME_TARGETS,
RUNTIME_TARGET,
} from "../../../src/core/identity-reminder.ts";
import {
isTriggerStatus,
TRIGGER_STATUS,
TRIGGER_STATUSES,
} from "../../../src/core/brain/triggers/types.ts";
import {
isOpenDecisionStatus,
OPEN_DECISION_STATUS,
OPEN_DECISION_STATUSES,
} from "../../../src/core/brain/decisions/open-store.ts";
import {
isLessonPromotionBlocked,
LESSON_PROMOTION_BLOCKED,
LESSON_PROMOTION_BLOCKED_MEMBERS,
} from "../../../src/core/brain/lessons-promotion.ts";
import {
BRAIN_SNAPSHOT_REASON,
BRAIN_SNAPSHOT_REASONS,
isBrainSnapshotReason,
} from "../../../src/core/brain/types.ts";
import {
GRAPH_HEALTH_CODE_LIST,
GRAPH_HEALTH_CODES,
isGraphHealthCode,
} from "../../../src/core/partner/codegraph-health.ts";
import {
isRecallInjectFault,
RECALL_INJECT_FAULT,
RECALL_INJECT_FAULTS,
} from "../../../src/core/brain/recall-inject.ts";
import {
isRecallChannel,
isRecallTelemetryMode,
isRecallTelemetryStatus,
RECALL_CHANNEL,
RECALL_CHANNELS,
RECALL_TELEMETRY_MODE,
RECALL_TELEMETRY_MODES,
RECALL_TELEMETRY_STATUS,
RECALL_TELEMETRY_STATUSES,
} from "../../../src/core/brain/recall-telemetry.ts";
import {
isMaterializeFreshness,
isMaterializeStaleReason,
isMaterializeUnknownReason,
MATERIALIZE_FRESHNESS,
MATERIALIZE_FRESHNESS_STATES,
MATERIALIZE_STALE_REASON,
MATERIALIZE_STALE_REASONS,
MATERIALIZE_UNKNOWN_REASON,
MATERIALIZE_UNKNOWN_REASONS,
} from "../../../src/core/brain/staleness.ts";
import {
isReadinessStatus,
READINESS_STATUS,
READINESS_STATUSES,
} from "../../../src/core/doctor-readiness.ts";
import {
EMBEDDING_GATE_REASON,
EMBEDDING_GATE_REASONS,
isEmbeddingGateReason,
} from "../../../src/core/search/embedding-spend.ts";
import {
EMBEDDING_PRICE_SOURCE,
EMBEDDING_PRICE_SOURCES,
isEmbeddingPriceSource,
} from "../../../src/core/search/embeddings/pricing.ts";
import {
isRetrievalDegradationCode,
RETRIEVAL_DEGRADATION,
RETRIEVAL_DEGRADATION_CODES,
} from "../../../src/core/search/retrieval-trail.ts";
import {
isRerankFailureCategory,
RERANK_FAILURE_CATEGORIES,
RERANK_FAILURE_CATEGORY,
} from "../../../src/core/search/rerank/failure.ts";
import {
GENERIC_TOOL_ERROR_CODES,
isGenericToolErrorCode,
TOOL_ERROR_CODE,
} from "../../../src/mcp/tool-error-codes.ts";
import {
isPageLintSkipReason,
PAGE_LINT_SKIP_REASON,
PAGE_LINT_SKIP_REASONS,
} from "../../../src/core/brain/page-lint.ts";
import {
isSkippedPageReason,
SKIPPED_PAGE_REASON,
SKIPPED_PAGE_REASONS,
} from "../../../src/core/brain/ingest/extractable-gate.ts";
import {
isSourceExtractSkipReason,
isSourceFormat,
SOURCE_EXTRACT_SKIP_REASON,
SOURCE_EXTRACT_SKIP_REASONS,
SOURCE_FORMAT,
SOURCE_FORMATS,
} from "../../../src/core/brain/ingest/source-formats.ts";
import {
isTableNoteSkipReason,
isTableTruncation,
TABLE_NOTE_SKIP_REASON,
TABLE_NOTE_SKIP_REASONS,
TABLE_TRUNCATION,
TABLE_TRUNCATIONS,
} from "../../../src/core/brain/ingest/table-note.ts";
import {
EGRESS_REDACTION,
EGRESS_REDACTION_STATUSES,
isEgressRedactionStatus,
} from "../../../src/core/egress/registry.ts";
import {
EGRESS_OUTCOME,
EGRESS_OUTCOMES,
isEgressOutcome,
} from "../../../src/core/egress/guard.ts";
import {
isProviderProbeState,
PROVIDER_PROBE,
PROVIDER_PROBE_STATES,
} from "../../../src/core/search/provider-probe.ts";
import {
isPreferenceRestoreFailure,
PREFERENCE_RESTORE_FAILURE,
PREFERENCE_RESTORE_FAILURES,
} from "../../../src/core/brain/portability/preference-restore.ts";
import {
isSchemaCompletenessRule,
isSchemaNodeKind,
SCHEMA_COMPLETENESS_RULE,
SCHEMA_COMPLETENESS_RULES,
SCHEMA_NODE_KIND,
SCHEMA_NODE_KINDS,
} from "../../../src/mcp/registry-guard.ts";
import {
isRecoverabilityBlocker,
isRecoverabilityState,
isRecoveryCoverage,
RECOVERABILITY_BLOCKER,
RECOVERABILITY_BLOCKERS,
RECOVERABILITY_STATE,
RECOVERABILITY_STATES,
RECOVERY_COVERAGE,
RECOVERY_COVERAGES,
} from "../../../src/core/brain/gates/recoverability.ts";
import {
BASENAME_REWRITE,
BASENAME_REWRITES,
INDEX_EVIDENCE,
INDEX_EVIDENCE_STATES,
INDEX_REFRESH,
INDEX_REFRESHES,
isBasenameRewrite,
isIndexEvidenceState,
isIndexRefresh,
isNoteLifecycleAction,
NOTE_LIFECYCLE_ACTION,
NOTE_LIFECYCLE_ACTIONS,
} from "../../../src/core/brain/notes/lifecycle.ts";
import {
DANGLING_SCAN,
DANGLING_SCANS,
isDanglingScan,
} from "../../../src/core/brain/notes/scaffold-stub.ts";
import {
isStubScaffoldAction,
STUB_SCAFFOLD_ACTION,
STUB_SCAFFOLD_ACTIONS,
} from "../../../src/mcp/brain/lifecycle-file-tools.ts";
import {
isSessionAdapterId,
SESSION_ADAPTER_ID,
SESSION_ADAPTER_IDS,
} from "../../../src/core/brain/sessions/types.ts";
import {
isTranscriptScan,
TRANSCRIPT_SCAN,
TRANSCRIPT_SCANS,
} from "../../../src/core/discipline/transcripts/types.ts";
import {
IMPORT_WRITE_MODE,
IMPORT_WRITE_MODES,
isImportWriteMode,
} from "../../../src/core/brain/sessions/import.ts";
import {
EMBEDDING_SUNSET,
EMBEDDING_SUNSET_SOURCE,
EMBEDDING_SUNSET_SOURCES,
EMBEDDING_SUNSET_STATES,
EMBEDDING_SUNSET_UNDETERMINED_REASON,
EMBEDDING_SUNSET_UNDETERMINED_REASONS,
isEmbeddingSunsetSource,
isEmbeddingSunsetState,
isEmbeddingSunsetUndeterminedReason,
} from "../../../src/core/search/embeddings/sunset.ts";
import {
isVaultBackingRemoteness,
isVaultBackingState,
isVaultBackingUndeterminedReason,
VAULT_BACKING,
VAULT_BACKING_REMOTENESS,
VAULT_BACKING_REMOTENESS_STATES,
VAULT_BACKING_STATES,
VAULT_BACKING_UNDETERMINED_REASON,
VAULT_BACKING_UNDETERMINED_REASONS,
} from "../../../src/core/vault-backing.ts";
import {
isSelfHealReindexOutcome,
isSelfHealSpawnDecision,
SELF_HEAL_REINDEX_OUTCOME,
SELF_HEAL_REINDEX_OUTCOMES,
SELF_HEAL_SPAWN,
SELF_HEAL_SPAWN_DECISIONS,
} from "../../../src/core/maintenance/self-heal-reindex.ts";
import {
isProgressKind,
isProgressReason,
PROGRESS_KIND,
PROGRESS_KINDS,
PROGRESS_REASON,
PROGRESS_REASONS,
} from "../../../src/core/brain/progress.ts";
import { isOperation, OPERATION, OPERATIONS } from "../../../src/core/brain/safeguard.ts";
import {
isTokenCountMethod,
TOKEN_COUNT_METHOD,
TOKEN_COUNT_METHODS,
} from "../../../src/core/brain/token-impact.ts";
import {
isRecallFailure,
RECALL_FAILURE,
RECALL_FAILURES,
} from "../../../src/core/bench/failure-modes.ts";
import {
isMaintenanceVerdict,
MAINTENANCE_VERDICT,
MAINTENANCE_VERDICTS,
} from "../../../src/core/brain/maintenance/journal.ts";
import {
isProgressOutcome,
PROGRESS_OUTCOME,
PROGRESS_OUTCOMES,
} from "../../../src/cli/progress-rail.ts";
import {
HOST_PRESSURE,
HOST_PRESSURE_STATES,
HOST_PRESSURE_UNMEASURABLE_REASON,
HOST_PRESSURE_UNMEASURABLE_REASONS,
isHostPressureState,
isHostPressureUnmeasurableReason,
} from "../../../src/core/brain/maintenance/host-pressure.ts";
import {
isOwnerScopeRefusal,
OWNER_SCOPE_REFUSAL,
OWNER_SCOPE_REFUSALS,
} from "../../../src/mcp/owner-scope-refusal.ts";
import {
isWriteRefusalCode,
WRITE_REFUSAL_CODES,
WRITE_REFUSAL_CODE_LIST,
} from "../../../src/core/brain/pending/pending-lanes.ts";
import {
isOriginReach,
isOriginReachReason,
ORIGIN_REACH,
ORIGIN_REACH_REASON,
ORIGIN_REACH_REASONS,
ORIGIN_REACHES,
} from "../../../src/core/brain/portability/origin-reach.ts";
import {
isMirrorOutcome,
MIRROR_OUTCOME,
MIRROR_OUTCOMES,
} from "../../../src/core/brain/shared-namespace.ts";
import {
INSTALL_TARGET_ID,
INSTALL_TARGET_IDS,
isInstallTargetId,
isSessionRuntimeId,
isToolCeilingKind,
SESSION_RUNTIME_ID,
SESSION_RUNTIME_IDS,
TOOL_CEILING_KIND,
TOOL_CEILING_KINDS,
} from "../../../src/core/runtime/host-facts.ts";
import { CONFIG_ORIGIN, CONFIG_ORIGINS, isConfigOrigin } from "../../../src/core/validate.ts";
import {
HARNESS_ID,
HARNESS_IDS,
isHarnessId,
isScopedRuleAxis,
SCOPED_RULE_AXES,
SCOPED_RULE_AXIS,
} from "../../../src/core/brain/scoped-rules.ts";
import { EXPORT_FORMAT, EXPORT_FORMATS, isExportFormat } from "../../../src/core/brain/export.ts";
import {
isStateReachability,
isStateSurfaceId,
isStateTier,
STATE_REACHABILITIES,
STATE_REACHABILITY,
STATE_SURFACE_ID,
STATE_SURFACE_IDS,
STATE_TIER,
STATE_TIERS,
} from "../../../src/core/state/surfaces.ts";
import {
isReconciliationOutcome,
RECONCILIATION_OUTCOME,
RECONCILIATION_OUTCOMES,
} from "../../../src/core/reconciliation-report.ts";
import {
isOriginChannel,
ORIGIN_CHANNEL,
ORIGIN_CHANNELS,
} from "../../../src/core/origin-channel.ts";
import {
isNoteWriteOp,
NOTE_WRITE_OP,
NOTE_WRITE_OPS,
} from "../../../src/core/brain/notes/write-record.ts";
import {
DISCLOSURE_MODE,
DISCLOSURE_MODES,
isDisclosureMode,
} from "../../../src/core/search/disclosure-mode.ts";
import {
FTS_MATCH_MODE,
FTS_MATCH_MODES,
isFtsMatchMode,
} from "../../../src/core/search/fts-match-mode.ts";
import { lexCode } from "../../helpers/source-lexer.ts";
import {
TRANSPORT_REACH,
TRANSPORT_REACHES,
isTransportReach,
} from "../../../src/core/graph/transport-reach.ts";
import {
CAPTURE_SCOPE,
CAPTURE_SCOPES,
isCaptureScope,
} from "../../../src/core/brain/provenance/capture-scope.ts";
import {
isQuoteCheckOutcome,
QUOTE_CHECK_OUTCOME,
QUOTE_CHECK_OUTCOMES,
} from "../../../src/core/brain/distill/quote-verdict.ts";
import {
isManifestStatus,
MANIFEST_STATUS,
MANIFEST_STATUSES,
} from "../../../src/core/brain/architect/manifests.ts";
import {
ANSWER_QUOTE_VERDICT,
ANSWER_QUOTE_VERDICTS,
isAnswerQuoteVerdict,
} from "../../../src/core/brain/answer-quotes/check.ts";
import {
DELIVERY_TREATMENT,
DELIVERY_TREATMENTS,
isDeliveryTreatment,
} from "../../../src/core/brain/delivery-shaping.ts";
import {
isReceiptVerifyUnavailableReason,
isReceiptVerifyVerdict,
RECEIPT_VERIFY_UNAVAILABLE_REASON,
RECEIPT_VERIFY_UNAVAILABLE_REASONS,
RECEIPT_VERIFY_VERDICT,
RECEIPT_VERIFY_VERDICTS,
} from "../../../src/core/brain/context-receipts-verify.ts";
import {
ARCHIVE_VERIFICATION,
ARCHIVE_VERIFICATIONS,
isArchiveVerification,
} from "../../../src/core/brain/provenance/source-archive.ts";
import {
REPLAY_EXPECTATION,
REPLAY_EXPECTATIONS,
isReplayExpectation,
} from "../../../src/core/bench/replay-fixture.ts";
import {
SURFACING_TIER,
SURFACING_TIERS,
isSurfacingTier,
} from "../../../src/core/search/surfacing-key.ts";
import {
isStorageForecastTier,
STORAGE_FORECAST_TIER,
STORAGE_FORECAST_TIERS,
} from "../../../src/core/brain/storage/forecast.ts";
import {
isReceiptLedgerFamily,
isReceiptMode,
RECEIPT_LEDGER_FAMILY,
RECEIPT_LEDGER_FAMILIES,
RECEIPT_MODE,
RECEIPT_MODES,
} from "../../../src/core/brain/receipts/types.ts";
import {
BENCH_REFUSAL,
BENCH_REFUSAL_KINDS,
isBenchRefusalKind,
} from "../../../src/core/bench/guards.ts";
import {
CONTENT_CLASSES,
CONTENT_CLASS,
isContentClass,
} from "../../../src/core/brain/provenance/content-class.ts";
interface VocabularyUnderCensus {
/** Identifies the vocabulary in a failure message. */
readonly name: string;
/** The frozen object every producer reads its value from. */
readonly values: Readonly<Record<string, string>>;
/** The companion membership list every reader validates against. */
readonly members: ReadonlyArray<string>;
/** The guard that decides whether a persisted string is a member. */
readonly guard: (value: unknown) => boolean;
}
/**
* Strings that must never be accepted by any guard here. They are shaped
* like plausible drift - a case change, a stray space, an empty value, a
* near-miss spelling - rather than obvious garbage.
*/
const NON_MEMBERS: ReadonlyArray<unknown> = Object.freeze([
"",
" ",
"unknown-vocabulary-member",
null,
undefined,
42,
{},
]);
/** Returns one line per defect. An empty array is a clean vocabulary. */
function auditVocabulary(vocabulary: VocabularyUnderCensus): ReadonlyArray<string> {
const problems: string[] = [];
const { name, values, members, guard } = vocabulary;
if (!Object.isFrozen(values)) problems.push(`${name}: values object is not frozen`);
const declared = Object.values(values);
const declaredSet = new Set(declared);
if (declaredSet.size !== declared.length) {
problems.push(`${name}: values object carries a duplicate value`);
}
const memberSet = new Set(members);
if (memberSet.size !== members.length) {
problems.push(`${name}: membership list carries a duplicate value`);
}
for (const value of declaredSet) {
if (!memberSet.has(value)) problems.push(`${name}: "${value}" is declared but not a member`);
if (!guard(value)) problems.push(`${name}: guard rejects declared value "${value}"`);
}
for (const member of memberSet) {
if (!declaredSet.has(member)) problems.push(`${name}: "${member}" is a member of nothing`);
}
for (const outsider of NON_MEMBERS) {
if (declaredSet.has(outsider as string)) continue;
if (guard(outsider))
problems.push(`${name}: guard accepts non-member ${JSON.stringify(outsider)}`);
}
return problems;
}
/**
* Every closed vocabulary that follows the trio convention. Units of this
* wave append here as they land; the seed entry is the one vocabulary that
* already shipped the complete trio.
*/
const CENSUS: ReadonlyArray<VocabularyUnderCensus> = Object.freeze([
{
// B5. `unknown` is the member the trio was missing: the install-state
// probe reads a manifest that can exist and refuse to parse, and among
// pass, fail and skipped there was no answer for "could not measure"
// that was not a lie in one direction or the other.
name: "READINESS_STATUS",
values: READINESS_STATUS,
members: READINESS_STATUSES,
guard: isReadinessStatus,
},
{ name: "GATE_MODE", values: GATE_MODE, members: GATE_MODES, guard: isGateMode },
{
// Who stated an embedding price: the value leaves TypeScript in spend
// receipts, the maintenance_spend metric and the JSON surfaces, so a
// reader can tell a builtin or operator price from an unknown one.
name: "EMBEDDING_PRICE_SOURCE",
values: EMBEDDING_PRICE_SOURCE,
members: EMBEDDING_PRICE_SOURCES,
guard: isEmbeddingPriceSource,
},
{
// Why the embedding cost gate refused: over the cap on a known price,
// or unpriced under an explicit positive gate. Rendered in previews and
// JSON so a refusal says which of the two it is.
name: "EMBEDDING_GATE_REASON",
values: EMBEDDING_GATE_REASON,
members: EMBEDDING_GATE_REASONS,
guard: isEmbeddingGateReason,
},
{
name: "SCHEMA_PACK_INTEGRITY",
values: SCHEMA_PACK_INTEGRITY,
members: SCHEMA_PACK_INTEGRITY_STATUSES,
guard: isSchemaPackIntegrityStatus,
},
{
name: "SCHEMA_PACK_UNVERIFIED_REASON",
values: SCHEMA_PACK_UNVERIFIED_REASON,
members: SCHEMA_PACK_UNVERIFIED_REASONS,
guard: isSchemaPackUnverifiedReason,
},
{
// U5. The trio was incomplete when the wave started: the list and
// the guard shipped, the frozen object did not, and the MCP tool
// schema carried a fourth hand-written copy of the list.
name: "TRIGGER_STATUS",
values: TRIGGER_STATUS,
members: TRIGGER_STATUSES,
guard: isTriggerStatus,
},
{
// write-side-trust wave (Task 10). The lifecycle of a parked
// question: open while the options are being weighed, then resolved
// (into a real decision page) or discarded. History is a status
// filter, so the trio must survive the round trip off disk.
name: "OPEN_DECISION_STATUS",
values: OPEN_DECISION_STATUS,
members: OPEN_DECISION_STATUSES,
guard: isOpenDecisionStatus,
},
{
// Operator-approved lesson promotion (t_1e952e43). Why a lesson is not
// promotable: the reason rides the CLI candidates listing and the JSON
// surfaces, so a reader can tell a scope that was never enabled from an
// approval that went stale on content drift.
name: "LESSON_PROMOTION_BLOCKED",
values: LESSON_PROMOTION_BLOCKED,
members: LESSON_PROMOTION_BLOCKED_MEMBERS,
guard: isLessonPromotionBlocked,
},
{
// U2. Three vocabularies, because a corpus verdict, the reason it
// could not be reached, and the stored edge that grounds a
// non-occurrence are three types - the wave's rule that a union of
// disjoint sets is a namespace rather than an abstraction.
name: "NEGATIVE_RECALL_STATE",
values: NEGATIVE_RECALL_STATE,
members: NEGATIVE_RECALL_STATES,
guard: isNegativeRecallState,
},
{
name: "NEGATIVE_RECALL_UNKNOWN_REASON",
values: NEGATIVE_RECALL_UNKNOWN_REASON,
members: NEGATIVE_RECALL_UNKNOWN_REASONS,
guard: isNegativeRecallUnknownReason,
},
{
name: "RETRACTION_EVIDENCE_KIND",
values: RETRACTION_EVIDENCE_KIND,
members: RETRACTION_EVIDENCE_KINDS,
guard: isRetractionEvidenceKind,
},
{
// U3. Two vocabularies for the two sides of one row: what stopped
// being current, and what kind of thing is still resting on it. They
// are read from different stores and lead to different remedies, so
// collapsing them into one axis would name neither.
name: "STALE_DEPENDENCY_CONSUMER",
values: STALE_DEPENDENCY_CONSUMER,
members: STALE_DEPENDENCY_CONSUMERS,
guard: isStaleDependencyConsumerKind,
},
{
name: "STALE_DEPENDENCY_STATE",
values: STALE_DEPENDENCY_STATE,
members: STALE_DEPENDENCY_STATES,
guard: isStaleDependencyStateKind,
},
{
// U6. Persisted into a replicated sidecar, so the guard is what
// stands between a peer's hand-edited manifest and a restore acting
// on a reason this build does not understand.
name: "SNAPSHOT_STORE_EXCLUSION",
values: SNAPSHOT_STORE_EXCLUSION,
members: SNAPSHOT_STORE_EXCLUSION_REASONS,
guard: isSnapshotStoreExclusionReason,
},
{
// U7. Four of its nine members have no producer in this release
// (snapshots at a session, plan or decision boundary are deferred, and
// nothing takes one on demand), and the census does not care: what it
// asserts is that the guard accepts every member, which is precisely
// what lets this build read a sidecar a later release wrote and
// replicated back.
name: "BRAIN_SNAPSHOT_REASON",
values: BRAIN_SNAPSHOT_REASON,
members: BRAIN_SNAPSHOT_REASONS,
guard: isBrainSnapshotReason,
},
{
// U4. Registered because the values leave TypeScript: the resync cron
// recipe interpolates one of them into the shell gate it emits, which
// is the copy-drift class this census exists for - a code renamed here
// and left as a literal there would silently stop matching, and the
// emitted gate would pass every report.
name: "GRAPH_HEALTH_CODES",
values: GRAPH_HEALTH_CODES,
members: GRAPH_HEALTH_CODE_LIST,
guard: isGraphHealthCode,
},
{
// B4. Three vocabularies for one gate, because the verdict, the
// reason an artifact is out of date, and the reason no verdict could
// be reached are three disjoint sets. The verdict replaced a boolean
// `fresh`, which is exactly the shape that forced a failed
// measurement to be reported as one of the two real answers.
name: "MATERIALIZE_FRESHNESS",
values: MATERIALIZE_FRESHNESS,
members: MATERIALIZE_FRESHNESS_STATES,
guard: isMaterializeFreshness,
},
{
// B4. Registered separately from the verdict: a stale reason is only
// ever paired with `stale`, and a guard that accepted both sets
// would let a persisted `unknown` reason be read back as a claim
// that the outputs are merely out of date.
name: "MATERIALIZE_STALE_REASON",
values: MATERIALIZE_STALE_REASON,
members: MATERIALIZE_STALE_REASONS,
guard: isMaterializeStaleReason,
},
{
// B4. These values leave TypeScript: the `--if-stale` fast-path
// writes the reason into the `communities` metric payload and into
// its `--json` output, so a rename here with the reader left alone
// is the copy-drift this census exists for.
name: "MATERIALIZE_UNKNOWN_REASON",
values: MATERIALIZE_UNKNOWN_REASON,
members: MATERIALIZE_UNKNOWN_REASONS,
guard: isMaterializeUnknownReason,
},
{
// C1. The transport a recall record arrived on. Registered because
// the doctor check that crosses it against an install state switches
// over it with no default arm, and because the value is persisted
// into the continuity log and copied into a tool-schema enum - both
// routes out of TypeScript this census exists to pin.
name: "RECALL_CHANNEL",
values: RECALL_CHANNEL,
members: RECALL_CHANNELS,
guard: isRecallChannel,
},
{
// C1. Not new - the guard was a hand-rolled equality chain, so
// `query` was added to the union and three copies of the list went
// stale, one of them a tool-schema enum that then rejected a mode
// the server itself records.
name: "RECALL_TELEMETRY_MODE",
values: RECALL_TELEMETRY_MODE,
members: RECALL_TELEMETRY_MODES,
guard: isRecallTelemetryMode,
},
{
// C1. The same conversion, and the vocabulary the injecting hook's
// three decisions map onto.
name: "RECALL_TELEMETRY_STATUS",
values: RECALL_TELEMETRY_STATUS,
members: RECALL_TELEMETRY_STATUSES,
guard: isRecallTelemetryStatus,
},
{
// Why the prompt-time recall hook failed. Minted because the error
// decision used to carry the retriever's RAW message and the hook
// copied it onto a synced continuity record that
// `brain_recall_telemetry` returns verbatim to a model - a SQLite or
// config failure names the index file or the config path, and the
// redactor strips secret-shaped tokens, not paths. Registered here
// because the value leaves TypeScript: it is persisted into that
// payload, and a member added to the object and forgotten in the list
// would be a fault no reader could narrow back.
name: "RECALL_INJECT_FAULT",
values: RECALL_INJECT_FAULT,
members: RECALL_INJECT_FAULTS,
guard: isRecallInjectFault,
},
{
// C2. Why a retrieval narrowed or came back empty. Registered because
// the values leave TypeScript twice over: they are declared as an
// `enum` in the `brain_search` output schema, where an undeclared code
// fails the response contract, and they are emitted as recall-telemetry
// gap strings - two hand-written copies away from the one definition if
// nothing asserts the trio agrees.
name: "RETRIEVAL_DEGRADATION",
values: RETRIEVAL_DEGRADATION,
members: RETRIEVAL_DEGRADATION_CODES,
guard: isRetrievalDegradationCode,
},
{
// Why a cross-encoder rerank request failed. Registered because the
// value leaves TypeScript: it rides `detail.category` of the
// `rerank-provider-unavailable` trail entry in `--json` and MCP
// `brain_search`, and it is computed from typed errors, so a member
// added to the object and forgotten in the list would be a category
// the producer emits and no reader can narrow back.
name: "RERANK_FAILURE_CATEGORY",
values: RERANK_FAILURE_CATEGORY,
members: RERANK_FAILURE_CATEGORIES,
guard: isRerankFailureCategory,
},
{
// The generic tokens the MCP boundary adds for failures that reach it
// with no code of their own. Registered because every value is a wire
// contract: it rides `error.data.code` or
// `_meta["open-second-brain/error"].code`, and clients branch on it.
// Only the generic object is four-piece; the imported core
// vocabularies keep their own registration where they live.
name: "TOOL_ERROR_CODE",
values: TOOL_ERROR_CODE,
members: GENERIC_TOOL_ERROR_CODES,
guard: isGenericToolErrorCode,
},
{
// C3. The two vocabularies the schema-completeness audit is built on:
// what kind of schema node the walk is standing on, and what a node
// failed to declare. Test-time only, so no value crosses a wire - but
// the rule vocabulary is the audit's whole contract with its readers,
// and a member added to the object and forgotten in the list would be
// a rule that never appears in a failure message.
name: "SCHEMA_NODE_KIND",
values: SCHEMA_NODE_KIND,
members: SCHEMA_NODE_KINDS,
guard: isSchemaNodeKind,
},
{
name: "SCHEMA_COMPLETENESS_RULE",
values: SCHEMA_COMPLETENESS_RULE,
members: SCHEMA_COMPLETENESS_RULES,
guard: isSchemaCompletenessRule,
},
{
// A4. Why a written page was not linted. The values ride out of
// TypeScript in the `lint.skipped[]` array of all four note-write
// tools, where a caller reads the reason to decide whether the silence
// about that page means clean or means unread - so a value added here
// and forgotten in the list is a reason no reader can narrow.
name: "PAGE_LINT_SKIP_REASON",
values: PAGE_LINT_SKIP_REASON,
members: PAGE_LINT_SKIP_REASONS,
guard: isPageLintSkipReason,
},
{
// What the extractable gate names a skipped page. Registered for the
// same reason the page-lint vocabulary is: the token crosses the MCP
// wire and the CLI JSON verbatim, so a value added here and forgotten
// in the membership list is a reason no reader can narrow.
name: "SKIPPED_PAGE_REASON",
values: SKIPPED_PAGE_REASON,
members: SKIPPED_PAGE_REASONS,
guard: isSkippedPageReason,
},
{
// The format a source file is, by extension. The token crosses the MCP
// wire (a planned file's `format`, a format skip's `detail`) and the CLI
// JSON verbatim, so a format added to the registry and forgotten in the
// list is one no reader can narrow.
name: "SOURCE_FORMAT",
values: SOURCE_FORMAT,
members: SOURCE_FORMATS,
guard: isSourceFormat,
},
{
// Why a source's content was not extracted. "Could not extract" is data
// on the ingest result and the extract verb's JSON, so the reason must
// survive the round trip through a string.
name: "SOURCE_EXTRACT_SKIP_REASON",
values: SOURCE_EXTRACT_SKIP_REASON,
members: SOURCE_EXTRACT_SKIP_REASONS,
guard: isSourceExtractSkipReason,
},
{
// Why a CSV or TSV source has no rendered table. The token crosses the
// MCP wire on the ingest result's `table` and the extract verb's JSON,
// so a reason added here and forgotten in the list is one no reader can
// narrow.
name: "TABLE_NOTE_SKIP_REASON",
values: TABLE_NOTE_SKIP_REASON,
members: TABLE_NOTE_SKIP_REASONS,
guard: isTableNoteSkipReason,
},
{
// Which cap cut a rendered table. Persisted as `table_truncated` on the
// summary page and read back across the wire, so every cap must survive
// the round trip through a string.
name: "TABLE_TRUNCATION",
values: TABLE_TRUNCATION,
members: TABLE_TRUNCATIONS,
guard: isTableTruncation,
},
{
// C1. What a given export path does about secrets on the way out.
// Registered because the value is the load-bearing field of a
// declaration that a source-reading census checks against the code:
// a status renamed here and left spelled the old way in the census
// would silently stop matching, and every entry would read as
// accounted for.
name: "EGRESS_REDACTION",
values: EGRESS_REDACTION,
members: EGRESS_REDACTION_STATUSES,
guard: isEgressRedactionStatus,
},
{
// C1. Released or refused at the export boundary. Registered
// separately from the status above because they answer different
// questions - what a PATH does in general, and what happened to ONE
// payload - and a guard that accepted both would let a refusal be
// read back as a policy.
name: "EGRESS_OUTCOME",
values: EGRESS_OUTCOME,
members: EGRESS_OUTCOMES,
guard: isEgressOutcome,
},
{
// E1. What the live embedding-provider probe of `o2b search check`
// concluded. It replaced a `boolean | null` that had to answer four
// questions with two truth values, so a provider that answered with a
// refusal and one that never answered were the same `false`. The
// values leave TypeScript through the verb's `--json` payload, where
// a caller reads `provider_probe` to decide whether the silence about
// an endpoint means healthy, broken, or unmeasured - which is exactly
// the copy this census exists to keep honest.
name: "PROVIDER_PROBE",
values: PROVIDER_PROBE,
members: PROVIDER_PROBE_STATES,
guard: isProviderProbeState,
},
{
// E2. Why one preference in a bank bundle did not restore. The values
// ride out of TypeScript in the `preferences.failed[]` array of the
// bank-import result and its `--json` rendering, where an operator
// reads the reason to decide whether to re-export, resolve a
// divergence by hand, or upgrade an old bundle. A value the guard
// rejects would read back off that JSON as an unknown refusal.
name: "PREFERENCE_RESTORE_FAILURE",
values: PREFERENCE_RESTORE_FAILURE,
members: PREFERENCE_RESTORE_FAILURES,
guard: isPreferenceRestoreFailure,
},
{
// R1a. Three vocabularies for one gate, by the same rule U2 states at
// :228-232: what a recovery point is worth, which regions of the vault
// an archive actually holds, and what stops a region being provable
// are three disjoint sets, so they are a namespace rather than an
// abstraction. The state replaced a `throw`-or-`DestructiveSnapshot`
// pair that had no way to say "a recovery point exists and it does not
// cover all of this" - which is what `--include-originals` needed to
// say while it reported a snapshot path instead.
name: "RECOVERABILITY_STATE",
values: RECOVERABILITY_STATE,
members: RECOVERABILITY_STATES,
guard: isRecoverabilityState,
},
{
// R1a. Registered separately because the regions are read back off a
// gate result and switched over by the destructive-site registry: a
// guard that also accepted a state would let `partial` be read as a
// region of the vault an archive holds.
name: "RECOVERY_COVERAGE",
values: RECOVERY_COVERAGE,
members: RECOVERY_COVERAGES,
guard: isRecoveryCoverage,
},
{
// R1a. These values leave TypeScript: they ride out in the
// `recoverability.blockers[]` array of the delete-by-source response,
// where a caller reads them to decide whether the deletion it just
// authorised is reversible.
name: "RECOVERABILITY_BLOCKER",
values: RECOVERABILITY_BLOCKER,
members: RECOVERABILITY_BLOCKERS,
guard: isRecoverabilityBlocker,
},
{
// B1. One member, and the census does not care how many: what it
// asserts is that the guard accepts it and rejects everything else.
// The value rides out of TypeScript in the prune report the
// destructive gate returns and the CLI prints, and it exists because
// a configured retention of zero used to make the most destructive
// operation in the snapshot module remove every archive in the vault
// without a word.
name: "SNAPSHOT_PRUNE_REFUSAL",
values: SNAPSHOT_PRUNE_REFUSAL,
members: SNAPSHOT_PRUNE_REFUSALS,
guard: isSnapshotPruneRefusal,
},
{
// B2. The dispatch key of the note-file lifecycle tool, so the value
// arrives as an untyped MCP argument or a raw CLI positional and the
// guard is the boundary between the two.
name: "NOTE_LIFECYCLE_ACTION",
values: NOTE_LIFECYCLE_ACTION,
members: NOTE_LIFECYCLE_ACTIONS,
guard: isNoteLifecycleAction,
},
{
// B2. What a rename did about `[[Basename]]` - the one inbound
// spelling that is not unique by construction. Three answers, and
// the reason it is a vocabulary rather than a boolean is that
// "withheld because two notes carry the name" and "there was nothing
// to rewrite" are opposite facts a boolean would collapse.
name: "BASENAME_REWRITE",
values: BASENAME_REWRITE,
members: BASENAME_REWRITES,
guard: isBasenameRewrite,
},
{
// B2. The freshness of the derived index a relocation could not
// update. No `current` member: nothing in this codebase writes the
// `links` table on a note write, so an index that exists is stale
// with respect to a rename that just happened, and declaring a
// member nothing produces would invite the opposite reading.
name: "INDEX_EVIDENCE",
values: INDEX_EVIDENCE,
members: INDEX_EVIDENCE_STATES,
guard: isIndexEvidenceState,
},
{
// B2. Whether the write started the detached index refresh, riding
// the report beside the index evidence above. Registered when the
// guard was added so the vocabulary carries the same four pieces as
// its siblings - the token a caller reads back out of a report or a
// persisted payload has to survive the round trip through a string
// like every other one here. Two members, and the difference between
// them is the honesty claim: `claimed` says a run is IN FLIGHT, and
// `not_claimed` says the evidence's next command still reconciles.
name: "INDEX_REFRESH",
values: INDEX_REFRESH,
members: INDEX_REFRESHES,
guard: isIndexRefresh,
},
{
// B3. Three of its four members are refusals, and that is the unit:
// the index reports dangling links as a COUNT, and a count taken
// after an incremental pass is not reproducible. An empty list from
// a partially-resolved index would read as a clean vault, so the
// scan says which of the four states produced the answer.
name: "DANGLING_SCAN",
values: DANGLING_SCAN,
members: DANGLING_SCANS,
guard: isDanglingScan,
},
{
// B3. The dispatch key of the stub-scaffolding tool. Separate from
// NOTE_LIFECYCLE_ACTION because the subjects are different kinds:
// every lifecycle action names an existing note by path, and a
// dangling target has no path yet - that is what makes it dangling.
name: "STUB_SCAFFOLD_ACTION",
values: STUB_SCAFFOLD_ACTION,
members: STUB_SCAFFOLD_ACTIONS,
guard: isStubScaffoldAction,
},
{
// U10. How a token-impact sample's counts were PRODUCED. Promoted to
// the idiom when its members were renamed off `exact` / `fallback`:
// the ledger counts nothing, so labelling a caller's integer exact
// asserted a property nothing had checked. The guard is the boundary
// for a value arriving as an untyped MCP argument or read back out of
// a continuity payload written by an older build.
name: "TOKEN_COUNT_METHOD",
values: TOKEN_COUNT_METHOD,
members: TOKEN_COUNT_METHODS,
guard: isTokenCountMethod,
},
{
// U10. How one proactive-recall decision failed. `faulted` is the
// member that earns the vocabulary: a retriever that threw is not a
// memory that stayed quiet, and a boolean would collapse them - which
// would let a broken harness report itself as a cautious one. The
// guard is the boundary for a value read back out of a persisted
// retrieve-phase result file.
name: "RECALL_FAILURE",
values: RECALL_FAILURE,
members: RECALL_FAILURES,
guard: isRecallFailure,
},
{
// U1. What one progress tick says happened. `refused` and `stopped`
// are the members that earn the vocabulary: an operation whose events
// no transport could carry, and one the operator cancelled, are
// different facts, and both were previously reported as an absence of
// progress - which is what a hung run looks like too.
name: "PROGRESS_KIND",
values: PROGRESS_KIND,
members: PROGRESS_KINDS,
guard: isProgressKind,
},
{
// U1. Why a run stopped short or why its ticks could not be carried.
// Closed for the same reason the kind is: a reader must branch on it,
// and a free string would let prose onto a structured surface.
name: "PROGRESS_REASON",
values: PROGRESS_REASON,
members: PROGRESS_REASONS,
guard: isProgressReason,
},
{
// U1. The operations this repository calls long. It was a bare union
// owned by the safeguard; the progress spine needed to name the same
// population, and a second list would have drifted. Registering it
// here is what stops the two readers - the timeout ladder and the
// progress event - from disagreeing about what is long.
name: "OPERATION",
values: OPERATION,
members: OPERATIONS,
guard: isOperation,
},
{
// U5. What the parent did about a reindex it found necessary. The
// values leave TypeScript into `Brain/metrics/self_heal_reindex.jsonl`,
// a file that is synced to peer devices and read back by a build that
// may not be the one that wrote it - so the guard is the boundary
// between this release and a row it does not understand.
name: "SELF_HEAL_SPAWN",
values: SELF_HEAL_SPAWN,
members: SELF_HEAL_SPAWN_DECISIONS,
guard: isSelfHealSpawnDecision,
},
{
// U5. Registered separately from the decision above because the two
// are answered by different processes to different questions - whether
// a child was started, and what a started child ended as - and one
// guard over both would let a refusal to start be read back off the
// same file as a rebuild that finished.
name: "SELF_HEAL_REINDEX_OUTCOME",
values: SELF_HEAL_REINDEX_OUTCOME,
members: SELF_HEAL_REINDEX_OUTCOMES,
guard: isSelfHealReindexOutcome,
},
{
// A2. What filesystem backs the vault path. `undetermined` is the
// member that earns the vocabulary: the alternative design classified
// the HOST as local / cloud sandbox / ephemeral, and every signal that
// classifier reads is one-way, so a negative container marker would
// have bought a positive durability verdict on every modern container
// that does not ship one.
name: "VAULT_BACKING",
values: VAULT_BACKING,
members: VAULT_BACKING_STATES,
guard: isVaultBackingState,
},
{
// A2. Why the backing probe reached no verdict. Separate from the
// state for the reason MATERIALIZE_UNKNOWN_REASON is separate from its
// freshness: one guard over both would let `path_unreadable` be read
// back off a payload everywhere a survival verdict is expected.
name: "VAULT_BACKING_UNDETERMINED_REASON",
values: VAULT_BACKING_UNDETERMINED_REASON,
members: VAULT_BACKING_UNDETERMINED_REASONS,
guard: isVaultBackingUndeterminedReason,
},
{
// A2, second axis. Whether the backing is a NAMED network filesystem,
// beside - not inside - the survival verdict: nfs and cifs are both
// durable AND remote, and `non_remote` deliberately is not named
// `local`, because an unknown or unprobeable backing answers
// non-remote too and "no network finding" is not evidence of local.
name: "VAULT_BACKING_REMOTENESS",
values: VAULT_BACKING_REMOTENESS,
members: VAULT_BACKING_REMOTENESS_STATES,
guard: isVaultBackingRemoteness,
},
{
// U7. The runtimes whose session adapters ship in this tree. It was a
// hand-written string union with a guard taking `string`, which is a
// guard that can only be called once the caller has already proved
// what it was asked to prove - and `--format` hands it a raw argv
// value. The registry it names is keyed by `string` and open to a
// caller's own adapter; this vocabulary is the closed half, and
// `tests/core/brain/sessions/adapter-registry.test.ts` locks it to
// the built-in registry's keys.
name: "SESSION_ADAPTER_ID",
values: SESSION_ADAPTER_ID,
members: SESSION_ADAPTER_IDS,
guard: isSessionAdapterId,
},
{
// U7. Which emptiness a transcript scan found. `root_absent`,
// `unreadable` and `idle` were one value - a zero file count - feeding
// an alert that exists to notice a day with no recorded work, so an
// unreadable home was read as a confirmed quiet day. The three cannot
// be one member for the same reason `partial` is not `full`: the
// middle one is the report failing, not the agent resting.
name: "TRANSCRIPT_SCAN",
values: TRANSCRIPT_SCAN,
members: TRANSCRIPT_SCANS,
guard: isTranscriptScan,
},
{
// U7. Whether an import result's counters describe writes that happened
// or writes it would have made. Two members, and the vocabulary earns
// its place on the pair it separates: `signals_created: 0` was the
// honest answer for a dry run AND for a real run over a session with
// nothing in it, so the counters alone could not say which run the
// operator had just performed.
name: "IMPORT_WRITE_MODE",
values: IMPORT_WRITE_MODE,
members: IMPORT_WRITE_MODES,
guard: isImportWriteMode,
},
{
// B1. What this build can say about one embedding model's
// decommission. `unsurveyed` and `none_announced` are separate
// members and that separation IS the unit: `embedding_model` is a
// free string with no validation and off-catalog is the normal case,
// so reporting "no sunset announced" for a model nobody looked up is
// the misleading silence the check exists to remove.
name: "EMBEDDING_SUNSET",
values: EMBEDDING_SUNSET,
members: EMBEDDING_SUNSET_STATES,
guard: isEmbeddingSunsetState,
},
{
// B1. Why no sunset verdict was reached. Separate from the state so
// `survey_stale` - a fact about this build's own table rather than
// about the model - can never be read back where a verdict belongs.
name: "EMBEDDING_SUNSET_UNDETERMINED_REASON",
values: EMBEDDING_SUNSET_UNDETERMINED_REASON,
members: EMBEDDING_SUNSET_UNDETERMINED_REASONS,
guard: isEmbeddingSunsetUndeterminedReason,
},
{
// B1. Which layer answered a sunset question - the operator's
// declaration in `_brain.yaml`, this build's table, or NEITHER. A
// boolean was the obvious shape and it is wrong: it would have made
// "the survey answered" and "nothing answered" the same value, which
// is the collapse this whole check exists to undo.
name: "EMBEDDING_SUNSET_SOURCE",
values: EMBEDDING_SUNSET_SOURCE,
members: EMBEDDING_SUNSET_SOURCES,
guard: isEmbeddingSunsetSource,
},
{
// U6. What one maintenance-lane journal row records. It was a bare
// union, and the fourth gate is what made the trio worth having: the
// rows are persisted as JSONL and read back by whichever build runs
// next, which after an upgrade is not the build that wrote them.
// `pressure:unmeasurable` is the member that earns the vocabulary -
// it is a NOTICE that a gate did not evaluate, emitted beside the
// decision rather than instead of it, so an operator can tell a host
// that was quiet from one that could not say.
name: "MAINTENANCE_VERDICT",
values: MAINTENANCE_VERDICT,
members: MAINTENANCE_VERDICTS,
guard: isMaintenanceVerdict,
},
{
// U6. Whether host pressure is a number or a named absence. Two
// members, and the pair is the whole unit: `os.loadavg()` returns
// zero both on an idle host and on the platform that does not
// implement it, so without this state the gate's "quiet" would have
// been indistinguishable from its "I cannot see".
name: "HOST_PRESSURE",
values: HOST_PRESSURE,
members: HOST_PRESSURE_STATES,
guard: isHostPressureState,
},
{
// U6. Which question failed. Separate from the state for the reason
// every undetermined-reason vocabulary here is separate from its
// verdict: the value is persisted into a journal row's
// `pressure_reason`, and one guard over both would let
// `cpu_quota_in_force` be read back where a load percentage belongs.
name: "HOST_PRESSURE_UNMEASURABLE_REASON",
values: HOST_PRESSURE_UNMEASURABLE_REASON,
members: HOST_PRESSURE_UNMEASURABLE_REASONS,
guard: isHostPressureUnmeasurableReason,
},
{
// U1. Whether a progress line reached stderr or was refused because
// the command's streams are buffered for the whole run. It was NOT
// registered here when it shipped, and the source scan below is how
// it was found - the first vocabulary this census enrolled because
// the tree said so rather than because an author remembered.
name: "PROGRESS_OUTCOME",
values: PROGRESS_OUTCOME,
members: PROGRESS_OUTCOMES,
guard: isProgressOutcome,
},
{
// U6. Why one `.snapshots/` entry could not become a listing row.
// The second vocabulary the scan enrolled rather than an author: it
// shipped complete, beside SNAPSHOT_PRUNE_REFUSAL in the same module,
// and was registered here by nobody.
name: "SNAPSHOT_ENTRY_SKIP_REASON",
values: SNAPSHOT_ENTRY_SKIP_REASON,
members: SNAPSHOT_ENTRY_SKIP_REASONS,
guard: isSnapshotEntrySkipReason,
},
{
// U6. Which tool surface a server process advertises. It shipped as a
// bare union with its three members hand-copied into four places - the
// union, the `second_brain_capabilities` output schema, the `--scope`
// validity check and the `--scope` error message - and nothing
// asserting the four agreed, which is the drift class this census
// exists for, one level up from the vocabularies it already held.
name: "TOOL_SCOPE",
values: TOOL_SCOPE,
members: TOOL_SCOPES,
guard: isToolScope,
},
{
// U6. Which host runtime the per-turn identity reminder is rendered
// for. It was the nearest thing to a selector in the tree and followed
// three of the four pieces: an array, a derived type and a guard typed
// `string | undefined`, which kept it out of this population entirely.
// The guard now takes `unknown`, so a target name read off an
// environment variable is narrowed by the same rule as every other
// persisted member here.
name: "RUNTIME_TARGET",
values: RUNTIME_TARGET,
members: KNOWN_RUNTIME_TARGETS,
guard: isRuntimeTarget,
},
{
// U2. A caller-supplied owner scope naming someone other than the
// server-resolved identity. Refused rather than narrowed: a silent
// narrowing leaves the caller believing it read what it asked for.
name: "OWNER_SCOPE_REFUSAL",
values: OWNER_SCOPE_REFUSAL,
members: OWNER_SCOPE_REFUSALS,
guard: isOwnerScopeRefusal,
},
{
// Write-side trust, Task 12. The named tokens a refused write-side
// trust call carries: a permissions document rule denied the write
// outright, or refused the force_confirmed bypass for a caller whose
// write verdict is not allow. Registered so the tokens a client
// branches on cannot drift from the guard that narrows them.
name: "WRITE_REFUSAL_CODES",
values: WRITE_REFUSAL_CODES,
members: WRITE_REFUSAL_CODE_LIST,
guard: isWriteRefusalCode,
},
{
// private-is-not-a-suggestion, U2. How far the caller of this process
// had to reach to get here. Minted by the transport and never parsed
// out of a request, so the guard is for a value read back off a
// stored envelope rather than for one arriving from a caller.
name: "TRANSPORT_REACH",
values: TRANSPORT_REACH,
members: TRANSPORT_REACHES,
guard: isTransportReach,
},
{
// U5. Whether a registered search origin could be read at all.
// `unreachable` and `unknown` are distinct members because "it is not
// there" and "I could not look" have different repairs, and neither
// may read as a zero contribution the way a dropped origin did.
name: "ORIGIN_REACH",
values: ORIGIN_REACH,
members: ORIGIN_REACHES,
guard: isOriginReach,
},
{
// U5. Why an origin was not reachable - the axis that makes the
// verdict actionable rather than merely honest.
name: "ORIGIN_REACH_REASON",
values: ORIGIN_REACH_REASON,
members: ORIGIN_REACH_REASONS,
guard: isOriginReachReason,
},
{
// U5. The shared-namespace mirror's verdict. It was a two-piece type
// alias outside this population, and it conflated operator
// misconfiguration with an I/O failure under one token, so the caller
// could not tell a vault that never opted in from a write that broke.
name: "MIRROR_OUTCOME",
values: MIRROR_OUTCOME,
members: MIRROR_OUTCOMES,
guard: isMirrorOutcome,
},
{
// U9. The runtimes `o2b install --target` can name. They were bare
// strings validated only by a registry-lookup miss, which is a check
// that runs after the value has already been carried through the
// adapter contract, the manifest and the ownership statement - so a
// typo was a value the type system had no opinion about anywhere.
name: "INSTALL_TARGET_ID",
values: INSTALL_TARGET_ID,
members: INSTALL_TARGET_IDS,
guard: isInstallTargetId,
},
{
// U9. The runtimes whose session logs this build can LOCATE. Neither
// the install-target set nor the session-adapter set: Claude Code is
// not installable and writes the largest transcript store on a
// typical machine, Cursor is locatable and unparsable, and Hermes is
// parsable at no path this build knows. The value round-trips through
// the import ledger on disk, which is what the guard is for.
name: "SESSION_RUNTIME_ID",
values: SESSION_RUNTIME_ID,
members: SESSION_RUNTIME_IDS,
guard: isSessionRuntimeId,
},
{
// U9. What this build can say about one host's per-workspace MCP tool
// limit. `unknown` and `unbounded` are separate members and that
// separation IS the unit: collapsing them would let a host nobody
// checked be read as one that publishes no limit, one layer above the
// fail-open profile selection that made the card true.
name: "TOOL_CEILING_KIND",
values: TOOL_CEILING_KIND,
members: TOOL_CEILING_KINDS,
guard: isToolCeilingKind,
},
{
// U9. Which layer produced a resolved configuration value. Four
// members rather than three because a vault carries a COMMITTED
// configuration that travels with it, next to the machine-local one
// that does not - and for generated install content the committed
// tier OUTRANKS the machine, so collapsing the two would make the
// only interesting provenance question unanswerable.
name: "CONFIG_ORIGIN",
values: CONFIG_ORIGIN,
members: CONFIG_ORIGINS,
guard: isConfigOrigin,
},
{
// U9. The durable locations this build keeps inside a vault. Closed
// because the inventory hands the id back to a caller that may ask
// for one surface by name; a bare `string` there would make a typo a
// silently empty answer rather than a compile error.
name: "STATE_SURFACE_ID",
values: STATE_SURFACE_ID,
members: STATE_SURFACE_IDS,
guard: isStateSurfaceId,
},
{
// U9. What losing one surface costs. Two members because derived
// machine state and vault content have genuinely different recovery
// stories, and an inventory that folded them into one bucket could
// not tell an operator which deletions are reversible.
name: "STATE_TIER",
values: STATE_TIER,
members: STATE_TIERS,
guard: isStateTier,
},
{
// U9. What this run established about one surface. `absent` and
// `unchecked` are separate members for the reason ORIGIN_REACH keeps
// its two apart: "it is not there" and "I could not look" are
// different repairs, and a permission error read as an absent file
// sends an operator to recreate what is already on disk.
name: "STATE_REACHABILITY",
values: STATE_REACHABILITY,
members: STATE_REACHABILITIES,
guard: isStateReachability,
},
{
// U11. What `o2b brain export --format` accepts. It shipped as a bare
// type alias that NOTHING imported, while the verb compared the raw
// argv string against two inline literals - a contract declared with
// nothing behind it, which is the defect class this release closes.
// The guard is now the boundary the argv value crosses, and the frozen
// object is the dispatch table's key set, so a format with no handler
// is a compile error rather than a silent fall-through.
name: "EXPORT_FORMAT",
values: EXPORT_FORMAT,
members: EXPORT_FORMATS,
guard: isExportFormat,
},
{
// nothing-writes-silently, shared substrate. The wave's one
// reconciliation report shape (attempted/found/missing) is consumed
// by three unrelated lanes - import read-back, envelope write
// accounting, embedder record-vs-data audit - and `contradicted` is
// the third state none of the pair-of-booleans vocabularies it
// replaces could name: a recorded claim that disagrees with what the
// report itself measured, not merely a shortfall against it.
name: "RECONCILIATION_OUTCOME",
values: RECONCILIATION_OUTCOME,
members: RECONCILIATION_OUTCOMES,
guard: isReconciliationOutcome,
},
{
// nothing-writes-silently, unit C. The wave's newest on-disk
// vocabulary, and the one that nearly escaped: the trio was complete
// from the start, but the object shipped as a bare `as const` rather
// than frozen, so the scan below - which enumerates frozen bindings -
// could not see it. Its members are load-bearing on-disk strings, and
// a rename that missed the guard would have failed the census for
// every other vocabulary in the tree and passed for this one.
name: "ORIGIN_CHANNEL",
values: ORIGIN_CHANNEL,
members: ORIGIN_CHANNELS,
guard: isOriginChannel,
},
{
// who-wrote-what, Task A. What a recorded note write DID to its
// target. `revert` is a member from the start rather than added when
// the revert task lands, because a restore is a write like any other
// and a reader that could not name it would have to fall back to a
// string comparison the moment the first one was recorded.
name: "NOTE_WRITE_OP",
values: NOTE_WRITE_OP,
members: NOTE_WRITE_OPS,
guard: isNoteWriteOp,
},
{
// t_c5326ece. The keyword-lane match breadth a caller selects. The
// same list is copied OUT of TypeScript into the brain_search MCP
// enum and every refusal message, so a mode added to the object and
// missed in the list would be refused by the guard the CLI and the
// MCP argument check both call.
name: "FTS_MATCH_MODE",
values: FTS_MATCH_MODE,
members: FTS_MATCH_MODES,
guard: isFtsMatchMode,
},
{
// The brain_search result depth. Like the match mode it is copied
// out of TypeScript into the MCP enum and both refusal messages.
name: "DISCLOSURE_MODE",
values: DISCLOSURE_MODE,
members: DISCLOSURE_MODES,
guard: isDisclosureMode,
},
{
// How much of its source a page holds. Stamped into page frontmatter
// and read back by the capture-scope hygiene detector, so a value the
// guard rejected would turn a stamped page into an unstamped one.
name: "CAPTURE_SCOPE",
values: CAPTURE_SCOPE,
members: CAPTURE_SCOPES,
guard: isCaptureScope,
},
{
// The verdict on one quoted span of a distilled claim. It reaches the
// MCP payload and the strict refusal message; its `url-only` member is
// the CAPTURE_SCOPE token, spelled once for "no local bytes".
name: "QUOTE_CHECK_OUTCOME",
values: QUOTE_CHECK_OUTCOME,
members: QUOTE_CHECK_OUTCOMES,
guard: isQuoteCheckOutcome,
},
{
// How one project manifest was read by the architecture scanner. It
// reaches the `o2b brain architect --json` envelope and the overview
// note, so a broken manifest is reported instead of read as absent.
name: "MANIFEST_STATUS",
values: MANIFEST_STATUS,
members: MANIFEST_STATUSES,
guard: isManifestStatus,
},
{
// The axis a scoped operator rule file is keyed on
// (`Brain/standing-rules/<axis>/<key>.md`). It reaches the
// `brain_context` output and orders the drop priority under the cap.
name: "SCOPED_RULE_AXIS",
values: SCOPED_RULE_AXIS,
members: SCOPED_RULE_AXES,
guard: isScopedRuleAxis,
},
{
// The runtimes `o2b mcp --harness` can name: every install target
// plus the three runtimes with no install adapter. Kept apart from
// INSTALL_TARGET_ID, which must equal the adapter registry.
name: "HARNESS_ID",
values: HARNESS_ID,
members: HARNESS_IDS,
guard: isHarnessId,
},
{
// The review lanes a write can be staged through (write-side trust):
// the lane name selects the `write_approval.*` key and names the
// `Brain/pending/` subdirectory a staged document lands in.
name: "REVIEW_LANE",
values: REVIEW_LANE,
members: REVIEW_LANES,
guard: isReviewLane,
},
{
// The verdict on one quoted span of a host answer (answer-trust wave,
// Lane A). It rides the Stop hook's annotation and the enforce trail's
// Brain-log event, and its degradation members are the point: a
// truncated note can under-deliver evidence but never acquits a span
// (`source-truncated`), and "we could not check" is a finding, not an
// all-clear (`note-unavailable`).
name: "ANSWER_QUOTE_VERDICT",
values: ANSWER_QUOTE_VERDICT,
members: ANSWER_QUOTE_VERDICTS,
guard: isAnswerQuoteVerdict,
},
{
// What a delivery does with one stored record's text on its way out
// (delivery-trust wave, Lane A). The pair is closed because there are
// exactly two things a read face can do: hand the stored bytes over
// (`plain`, earned only by a page stamped origin_channel: cli with no
// other marker) or fence them (`fenced`, the fail-closed answer every
// absence resolves to). A third member would be a new delivery
// contract and has to register here.
name: "DELIVERY_TREATMENT",
values: DELIVERY_TREATMENT,
members: DELIVERY_TREATMENTS,
guard: isDeliveryTreatment,
},
{
// What re-hashing one context-receipt item concluded (delivery-trust
// wave, Lane B). The verdict rides the MCP and CLI verify faces and
// the drift doctor's counts, so every member must survive the round
// trip through a string; a fourth member would be a new verify
// contract and has to register here.
name: "RECEIPT_VERIFY_VERDICT",
values: RECEIPT_VERIFY_VERDICT,
members: RECEIPT_VERIFY_VERDICTS,
guard: isReceiptVerifyVerdict,
},
{
// Why a receipt item could not be re-verified at all (delivery-trust
// wave, Lane B). It rides the same faces as the verdict beside it, so
// a reason added to the object and forgotten in the list is one no
// caller can narrow.
name: "RECEIPT_VERIFY_UNAVAILABLE_REASON",
values: RECEIPT_VERIFY_UNAVAILABLE_REASON,
members: RECEIPT_VERIFY_UNAVAILABLE_REASONS,
guard: isReceiptVerifyUnavailableReason,
},
{
// What comparing a stamped archive digest against the entry it names
// concluded (answer-trust wave, Lane C). It rides the capture-scope
// detector's finding evidence and the archive read op, and the pair it
// separates is the unit: `missing` (the evidence is gone) and
// `mismatched` (the evidence disagrees with the page) are different
// repairs, and a boolean would collapse them.
name: "ARCHIVE_VERIFICATION",
values: ARCHIVE_VERIFICATION,
members: ARCHIVE_VERIFICATIONS,
guard: isArchiveVerification,
},
{
// What a recorded surfacing-replay prompt expected memory to do
// (recall-quality wave, Lane C): `inject` (speak up) vs `abstain`
// (stay quiet) is the pair the replay corpus scores the gate on, and
// a boolean would collapse outcomes the fixture round-trips by name.
name: "REPLAY_EXPECTATION",
values: REPLAY_EXPECTATION,
members: REPLAY_EXPECTATIONS,
guard: isReplayExpectation,
},
{
// The graded-surfacing admission verdict (recall-quality wave,
// Lane C): explicit, suppressed, admitted, below_floor and
// unmeasurable_quality are distinct outcomes the gate telemetry and
// the replay corpus both render, not a boolean admitted/not.
name: "SURFACING_TIER",
values: SURFACING_TIER,
members: SURFACING_TIERS,
guard: isSurfacingTier,
},
{
// The storage-lifecycle wave. How full a capped vault will be, and
// what the gate does about it. The three measured tiers order by
// severity, and the three refusals are separate members because they
// answer different questions a reader branches on: `unbounded` is a
// fact about the vault's configuration, `unmeasurable` a fact about
// the census that missed a surface, and `no_forecast` the named
// two-truths state of too few stored samples - collapsing any pair
// would turn "the vault has no cap" into "the sampler is broken".
// The values ride the storage gate's verdict and the doctor's
// capacity check, both rendered surfaces an operator reads.
name: "STORAGE_FORECAST_TIER",
values: STORAGE_FORECAST_TIER,
members: STORAGE_FORECAST_TIERS,
guard: isStorageForecastTier,
},
{
// The storage-lifecycle wave. Which receipt ledger one compaction
// surface addresses. Two members because there are exactly two
// families and the fold rewrites one shard at a time under its own
// lock; a free string would let a caller name a ledger this build
// does not scan and read the run back as a clean no-op.
name: "RECEIPT_LEDGER_FAMILY",
values: RECEIPT_LEDGER_FAMILY,
members: RECEIPT_LEDGER_FAMILIES,
guard: isReceiptLedgerFamily,
},
{
// The storage-lifecycle wave. What one receipt-compaction invocation
// was asked to do. `scan` inventories and writes nothing, `compact`
// rewrites under a snapshot; the pair is the whole input schema the
// CLI verb and the MCP tool share, and one guard over both the flag
// and the wire argument is what keeps the two surfaces unable to
// disagree about what the second one does.
name: "RECEIPT_MODE",
values: RECEIPT_MODE,
members: RECEIPT_MODES,
guard: isReceiptMode,
},
{
// Cycle 20261020, Lane E. The bench guards' refusal vocabulary: one
// closed kind per catchable pre-run (P1-P7) and pre-report (T1-T7)
// damaged state, rendered verbatim in `refused (<kind>): <detail>` -
// a name an operator's script can branch on is the whole contract,
// so it is audited like every other verdict a surface prints.
name: "BENCH_REFUSAL",
values: BENCH_REFUSAL,
members: BENCH_REFUSAL_KINDS,
guard: isBenchRefusalKind,
},
{
// The write-honesty wave (F5, task E1, commit dca029dd). What kind of
// process produced a page's text, stamped into `content_class`
// frontmatter and read back by the egress filter at every shared
// export - the value is an on-disk spelling an operator can query on
// and hand-edit, so the guard is the boundary between this build's
// one member and a spelling a later release or a text editor writes.
// One member, because the stamp exists for exactly one decision
// (shared exports leave such pages out by default); the vocabulary
// grows the day a second decision ships.
name: "CONTENT_CLASS",
values: CONTENT_CLASS,
members: CONTENT_CLASSES,
guard: isContentClass,
},
{
// agent-presence, Lane A (t_635e3e72): the three-arm rewrite verdict,
// copied from the decision-model eval vocabulary the gate generalizes.
// Leaves TypeScript in grade records and the CLI/MCP status surfaces.
name: "SKILL_REWRITE_VERDICT",
values: SKILL_REWRITE_VERDICT,
members: SKILL_REWRITE_VERDICTS,
guard: isSkillRewriteVerdict,
},
{
// The closed task-kind vocabulary of a benchmark task set. Leaves
// TypeScript in the tasks.json fixtures and their named parse errors.
name: "SKILL_BENCH_TASK_KIND",
values: SKILL_BENCH_TASK_KIND,
members: SKILL_BENCH_TASK_KINDS,
guard: isSkillBenchTaskKind,
},
{
// The closed structural-predicate vocabulary a task's expectations are
// written against; the check ids leave TypeScript in grade-record rows
// and the score output.
name: "SKILL_BENCH_CHECK",
values: SKILL_BENCH_CHECK,
members: SKILL_BENCH_CHECKS,
guard: isSkillBenchCheck,
},
{
// agent-presence, Lane C (t_1e952e43): the four states a managed
// lessons block grades to in the doctor readiness check - the shared
// writer's drift vocabulary plus the named stale-lessons extension.
// Leaves TypeScript in doctor findings and the per-file readiness
// rows, both of which the refresh verb's own surfaces read back.
name: "LESSONS_BLOCK_STATE",
values: LESSONS_BLOCK_STATE,
members: LESSONS_BLOCK_STATES,
guard: isLessonsBlockState,
},
{
// The closed value-class vocabulary an output_field expectation
// asserts over; leaves TypeScript in the fixtures and their named
// parse errors.
name: "SKILL_BENCH_VALUE_CLASS",
values: SKILL_BENCH_VALUE_CLASS,
members: SKILL_BENCH_VALUE_CLASSES,
guard: isSkillBenchValueClass,
},
{
// Which round an envelope belongs to: the baseline and candidate dev
// rounds and the single held-out check. Leaves TypeScript in the
// transcript drop-site paths and the round reports.
name: "SKILL_REWRITE_ROUND_ARM",
values: SKILL_REWRITE_ROUND_ARM,
members: SKILL_REWRITE_ROUND_ARMS,
guard: isSkillRewriteRoundArm,
},
{
// The rewrite gate mode: gated (one candidate per round) or iterative
// (a bounded dev-only edit loop, still gated before any write).
// Resolved from `skill_rewrite.mode`, refused by name on other values.
name: "SKILL_REWRITE_MODE",
values: SKILL_REWRITE_MODE,
members: SKILL_REWRITE_MODES,
guard: isSkillRewriteMode,
},
]);
// ---------------------------------------------------------------------------
// The population, read from `src/`
// ---------------------------------------------------------------------------
const REPO_ROOT = join(import.meta.dir, "..", "..", "..");
/** Roots the scan walks. See the docblock for what living outside costs. */
const SCANNED_ROOTS: ReadonlyArray<string> = Object.freeze(["src"]);
interface SourceFile {
readonly path: string;
readonly text: string;
}
function readSourceTree(): SourceFile[] {
const files: SourceFile[] = [];
const walk = (dir: string): void => {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const abs = join(dir, entry.name);
if (entry.isDirectory()) walk(abs);
else if (entry.name.endsWith(".ts")) {
files.push({
path: relative(REPO_ROOT, abs).split("\\").join("/"),
text: readFileSync(abs, "utf8"),
});
}
}
};
for (const root of SCANNED_ROOTS) walk(join(REPO_ROOT, root));
files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
return files;
}
const CLOSER: Readonly<Record<string, string>> = Object.freeze({
"{": "}",
"[": "]",
"(": ")",
});
/** Index of the bracket closing the one at `open`, or -1. */
function matchBracket(masked: string, open: number): number {
const opener = masked[open]!;
const closer = CLOSER[opener]!;
let depth = 0;
for (let i = open; i < masked.length; i += 1) {
const char = masked[i];
if (char === opener) depth += 1;
else if (char === closer) {
depth -= 1;
if (depth === 0) return i;
}
}
return -1;
}
/** A `const NAME = …` whose initialiser is a bracketed expression. */
interface Binding {
readonly name: string;
/** Index of the opening bracket of the initialiser's outermost group. */
readonly open: number;
/** Index of its closer. */
readonly close: number;
/** `{` for an object literal, `[` for an array, `(` for `Object.freeze(…)`. */
readonly bracket: string;
}
/**
* `Object.freeze(` and bare-array bindings. The optional type annotation
* is matched as "anything up to the `=`" excluding `;` and `=`, which is
* every annotation in this tree; a function-typed annotation (`() => T`)
* would hide the binding, and hiding a MEMBERSHIP LIST is the only way
* that matters - it drops its vocabulary out of the population.
*/
const FROZEN_BINDING_RE =
/\bconst\s+([A-Za-z_$][\w$]*)\s*(?::[^;=]*)?=\s*Object\s*\.\s*freeze\s*\(/g;
const ARRAY_BINDING_RE = /\bconst\s+([A-Za-z_$][\w$]*)\s*(?::[^;=]*)?=\s*\[/g;
function bindings(masked: string): Binding[] {
const found: Binding[] = [];
for (const match of masked.matchAll(FROZEN_BINDING_RE)) {
const paren = match.index! + match[0].length - 1;
const close = matchBracket(masked, paren);
if (close === -1) continue;
// `Object.freeze({ … })` and `Object.freeze([ … ])` are reported as
// the literal they wrap; `Object.freeze(Object.values(X))` stays a
// call, which is a membership list and never an object literal.
const inner = masked.slice(paren + 1, close);
const offset = inner.search(/\S/);
const first = offset === -1 ? "" : inner[offset];
if (first === "{" || first === "[") {
const open = paren + 1 + offset;
const innerClose = matchBracket(masked, open);
if (innerClose !== -1) {
found.push({ name: match[1]!, open, close: innerClose, bracket: first });
continue;
}
}
found.push({ name: match[1]!, open: paren, close, bracket: "(" });
}
for (const match of masked.matchAll(ARRAY_BINDING_RE)) {
const open = match.index! + match[0].length - 1;
const close = matchBracket(masked, open);
if (close !== -1) found.push({ name: match[1]!, open, close, bracket: "[" });
}
return found;
}
/** Top-level `,`-separated segments of a bracketed body, as index pairs. */
function segments(masked: string, open: number, close: number): Array<readonly [number, number]> {
const parts: Array<readonly [number, number]> = [];
let depth = 0;
let start = open + 1;
for (let i = open + 1; i < close; i += 1) {
const char = masked[i];
if (char === "(" || char === "[" || char === "{") depth += 1;
else if (char === ")" || char === "]" || char === "}") depth -= 1;
else if (char === "," && depth === 0) {
parts.push([start, i]);
start = i + 1;
}
}
parts.push([start, close]);
return parts;
}
const ENTRY_RE = /^\s*(?:[A-Za-z_$][\w$]*|"[^"]*"|'[^']*')\s*:\s*(["'])/;
/**
* The declared values of a frozen object literal, in source order, or
* `null` when ANY entry is something other than `key: "literal"` - a
* spread, a nested object, a call. Not-a-literal is not a partial read:
* it means this object is not a string vocabulary.
*/
function declaredValues(masked: string, text: string, binding: Binding): string[] | null {
if (binding.bracket !== "{") return null;
const values: string[] = [];
for (const [from, to] of segments(masked, binding.open, binding.close)) {
const segment = masked.slice(from, to);
if (segment.trim() === "") continue;
const match = ENTRY_RE.exec(segment);
if (match === null) return null;
const quote = match[1]!;
const valueStart = from + match[0].length;
const valueEnd = masked.indexOf(quote, valueStart);
if (valueEnd === -1 || valueEnd >= to) return null;
values.push(text.slice(valueStart, valueEnd));
}
return values.length > 0 ? values : null;
}
/** A declaration that takes a parameter typed `unknown`. */
interface GuardCandidate {
readonly name: string;
/** Source range of the whole declaration, signature and body. */
readonly from: number;
readonly to: number;
}
const FUNCTION_RE = /\bfunction\s+([A-Za-z_$][\w$]*)\s*\(/g;
const ARROW_RE = /\bconst\s+([A-Za-z_$][\w$]*)\s*(?::[^;=]*)?=\s*(?:async\s*)?\(/g;
/** Index of the end of the statement starting at `from`, at depth zero. */
function statementEnd(masked: string, from: number): number {
let depth = 0;
for (let i = from; i < masked.length; i += 1) {
const char = masked[i];
if (char === "(" || char === "[" || char === "{") depth += 1;
else if (char === ")" || char === "]" || char === "}") {
depth -= 1;
if (depth < 0) return i;
} else if (char === ";" && depth === 0) return i;
}
return masked.length;
}
function guardCandidates(masked: string): GuardCandidate[] {
const found: GuardCandidate[] = [];
for (const match of masked.matchAll(FUNCTION_RE)) {
const paramsOpen = match.index! + match[0].length - 1;
const paramsClose = matchBracket(masked, paramsOpen);
if (paramsClose === -1) continue;
if (!/:\s*unknown\b/.test(masked.slice(paramsOpen, paramsClose))) continue;
const bodyOpen = masked.indexOf("{", paramsClose);
const bodyClose = bodyOpen === -1 ? -1 : matchBracket(masked, bodyOpen);
found.push({
name: match[1]!,
from: match.index!,
to: bodyClose === -1 ? masked.length : bodyClose,
});
}
for (const match of masked.matchAll(ARROW_RE)) {
const paramsOpen = match.index! + match[0].length - 1;
const paramsClose = matchBracket(masked, paramsOpen);
if (paramsClose === -1) continue;
if (!/:\s*unknown\b/.test(masked.slice(paramsOpen, paramsClose))) continue;
if (!/^[^;{]*=>/.test(masked.slice(paramsClose + 1))) continue;
found.push({ name: match[1]!, from: match.index!, to: statementEnd(masked, paramsClose + 1) });
}
return found;
}
/** One vocabulary the tree declares, as the scan reads it. */
interface ScannedVocabulary {
readonly file: string;
/** The frozen object's identifier. `CENSUS.name` must equal it. */
readonly name: string;
/** Its declared values, in source order. */
readonly values: ReadonlyArray<string>;
/** The membership-list constant built from it. */
readonly members: string;
/** The guard that takes `unknown`. */
readonly guard: string;
}
function scanVocabularies(files: ReadonlyArray<SourceFile>): ScannedVocabulary[] {
const found: ScannedVocabulary[] = [];
for (const file of files) {
const masked = lexCode(file.text);
const declared = bindings(masked);
const guards = guardCandidates(masked);
for (const binding of declared) {
const values = declaredValues(masked, file.text, binding);
if (values === null) continue;
const name = binding.name;
const derived = new RegExp(
String.raw`\(\s*typeof\s+${name}\s*\)\s*\[\s*keyof\s+typeof\s+${name}\s*\]`,
);
if (!derived.test(masked)) continue;
const referencesObject = new RegExp(
String.raw`\b${name}\s*\.|Object\s*\.\s*values\s*\(\s*${name}\s*\)`,
);
const list = declared.find(
(candidate) =>
candidate !== binding &&
candidate.bracket !== "{" &&
referencesObject.test(masked.slice(candidate.open, candidate.close)),
);
if (list === undefined) continue;
const reads = new RegExp(String.raw`\b(?:${list.name}|${name})\b`);
const guard = guards.find((candidate) =>
reads.test(masked.slice(candidate.from, candidate.to)),
);
if (guard === undefined) continue;
found.push({
file: file.path,
name,
values,
members: list.name,
guard: guard.name,
});
}
}
return found;
}
const SOURCE_TREE = readSourceTree();
const SCANNED = scanVocabularies(SOURCE_TREE);
/**
* How many four-piece vocabularies `src/` currently holds. Measured, and
* kept as an equality rather than a floor - see the population test.
*/
// 99: Lane C's REPLAY_EXPECTATION (replay corpus) and SURFACING_TIER
// (graded surfacing) join the scanned population, the same append Lane
// C's ARCHIVE_VERIFICATION made.
// 102: the storage-lifecycle wave's three - STORAGE_FORECAST_TIER (the
// capacity gate's tiers), RECEIPT_LEDGER_FAMILY and RECEIPT_MODE (the
// receipt-compaction surfaces' shared input vocabulary).
// 103: INDEX_REFRESH (note lifecycle) gains its isIndexRefresh guard,
// completing the four-piece shape its sibling vocabularies already
// carry and so entering the scanned population.
// 104: BENCH_REFUSAL (cycle 20261020, Lane E) - the bench guards'
// closed refusal vocabulary, rendered by name in every bench refusal.
// 105: CONTENT_CLASS (write-honesty wave, task E1, commit dca029dd) -
// the content-class stamp's one-member vocabulary, complete with its
// membership list and `unknown` guard from the start, enrolled here when
// the egress census that reads it landed (task E4).
// 107/108: RECEIPT_VERIFY_VERDICT and RECEIPT_VERIFY_UNAVAILABLE_REASON
// (delivery-trust fix wave 1) - lane B's closed verify vocabularies ship
// their membership lists and guards so the scanner can see them.
// 109: LESSON_PROMOTION_BLOCKED (operator-approved lesson promotion,
// t_1e952e43) - the named reason a lesson fails the promotion gate,
// rendered by the candidates listing and the JSON surfaces.
// 110-115: the agent-presence rewrite lane's six closed vocabularies
// (t_635e3e72) - SKILL_REWRITE_VERDICT, SKILL_BENCH_TASK_KIND,
// SKILL_BENCH_CHECK, SKILL_BENCH_VALUE_CLASS, SKILL_REWRITE_ROUND_ARM and
// SKILL_REWRITE_MODE - join, each with its membership list and guard.
const VOCABULARY_POPULATION = 115;
const REGISTERED = new Map(CENSUS.map((entry) => [entry.name, entry] as const));
describe("verdict vocabulary census", () => {
test("the registry is not empty", () => {
// A census with nothing in it passes for the wrong reason. This is the
// guard against the registry being emptied rather than fixed.
expect(CENSUS.length).toBeGreaterThan(0);
});
for (const vocabulary of CENSUS) {
test(`${vocabulary.name} object, membership list and guard agree`, () => {
expect(auditVocabulary(vocabulary)).toEqual([]);
});
}
});
describe("the census itself catches drift", () => {
// Without these, a broken audit would report every vocabulary clean and
// the file above would be decoration.
const values = Object.freeze({ ok: "ok", unverified: "unverified" });
const members = ["ok", "unverified"];
const guard = (value: unknown): boolean => members.includes(value as string);
test("accepts a well-formed vocabulary", () => {
expect(auditVocabulary({ name: "synthetic", values, members, guard })).toEqual([]);
});
test("catches a value that is missing from the membership list", () => {
const problems = auditVocabulary({ name: "synthetic", values, members: ["ok"], guard });
expect(problems).toContain('synthetic: "unverified" is declared but not a member');
});
test("catches a member that no value declares", () => {
const problems = auditVocabulary({
name: "synthetic",
values,
members: [...members, "modified"],
guard,
});
expect(problems).toContain('synthetic: "modified" is a member of nothing');
});
test("catches a guard that rejects one of its own values", () => {
const problems = auditVocabulary({
name: "synthetic",
values,
members,
guard: (value) => value === "ok",
});
expect(problems).toContain('synthetic: guard rejects declared value "unverified"');
});
test("catches a guard that accepts anything", () => {
const problems = auditVocabulary({ name: "synthetic", values, members, guard: () => true });
expect(problems).toContain('synthetic: guard accepts non-member ""');
});
test("catches an unfrozen values object", () => {
const problems = auditVocabulary({
name: "synthetic",
values: { ok: "ok", unverified: "unverified" },
members,
guard,
});
expect(problems).toContain("synthetic: values object is not frozen");
});
test("catches a duplicate value", () => {
const problems = auditVocabulary({
name: "synthetic",
values: Object.freeze({ ok: "ok", alsoOk: "ok" }),
members: ["ok"],
guard: (value) => value === "ok",
});
expect(problems).toContain("synthetic: values object carries a duplicate value");
});
});
describe("the census reads the tree", () => {
test("every four-piece vocabulary in src/ is registered", () => {
// The finding this block exists for: an unregistered vocabulary used
// to be invisible, so a module carrying a duplicate value, a phantom
// member and a guard that accepts every string ran clean.
const unregistered = SCANNED.filter((row) => !REGISTERED.has(row.name)).map(
(row) => `${row.name} (${row.file})`,
);
// Named, not counted: the failure has to say which vocabulary.
expect(unregistered).toEqual([]);
});
test("no registration outlives the vocabulary it audits", () => {
// The other direction, and the reason the scan can be trusted at all:
// if it stopped seeing a shape, the vocabularies written in that shape
// would go missing here rather than silently leave the population.
const scanned = new Set(SCANNED.map((row) => row.name));
const orphaned = CENSUS.filter((entry) => !scanned.has(entry.name)).map((entry) => entry.name);
expect(orphaned).toEqual([]);
});
test("each registration names the object the source declares", () => {
// `name` is the source identifier, which is what lets the two halves
// be joined at all. A registration pointing at a different object -
// the copy-paste failure this file is one long list of opportunities
// for - lands here as a value mismatch.
const mismatched: string[] = [];
for (const row of SCANNED) {
const entry = REGISTERED.get(row.name);
if (entry === undefined) continue;
const registered = Object.values(entry.values).toSorted();
const read = [...row.values].toSorted();
if (registered.join(" ") !== read.join(" ")) {
mismatched.push(
`${row.name}: registered [${registered.join(",")}] source [${read.join(",")}]`,
);
}
}
expect(mismatched).toEqual([]);
});
test("the scan still finds the population it measures", () => {
// An EQUALITY, not a floor. A scanner that matched nothing would
// report a clean sweep over an empty set, and a floor of 50 against a
// real 63 would let a fifth of the population stop being seen without
// anything going red - which is the same shape of defect this census
// exists to catch, one level up.
//
// Adding a vocabulary therefore means bumping this number, which is
// the point: the count is the measurement, and a measurement nobody
// has to keep true is not one.
// 115 -> 116: the lessons-block state vocabulary (LESSONS_BLOCK_STATE) joins the
// population with the lessons lane's final commit (t_1e952e43).
expect(SCANNED.length).toBe(VOCABULARY_POPULATION + 1);
expect(SOURCE_TREE.length).toBeGreaterThan(500);
});
test("a vocabulary whose list is a multi-line Object.values stays visible", () => {
// The concrete shape a line-oriented scan loses: the membership list
// is `Object.freeze(` then `Object.values(HOST_PRESSURE),` on the next
// line, so no single line carries both. Pinned by name because a
// regression to line matching drops 20-odd rows at once and every
// other test in this file still passes.
const row = SCANNED.find((candidate) => candidate.name === "HOST_PRESSURE");
expect(`${row?.members} ${row?.guard} ${row?.values.join(",")}`).toBe(
"HOST_PRESSURE_STATES isHostPressureState measured,unmeasurable",
);
});
});
describe("the scan sees the shapes it claims to", () => {
/**
* The real scan and the real registry, over one synthetic module.
*
* One file rather than the whole tree plus one, because
* {@link scanVocabularies} decides per file - the four pieces must be
* in one module - so the two runs cannot differ, and re-walking `src/`
* once per shape costs a second each for an identical answer.
*/
function unregisteredWith(intruder: SourceFile): string[] {
return scanVocabularies([intruder])
.filter((row) => !REGISTERED.has(row.name))
.map((row) => row.name);
}
const OBJECT = 'export const ZZ = Object.freeze({\n a: "a",\n b: "b",\n} as const);\n';
const DERIVED = "export type Zz = (typeof ZZ)[keyof typeof ZZ];\n";
const FROZEN_LIST = "export const ZZS: ReadonlyArray<Zz> = Object.freeze([ZZ.a, ZZ.b]);\n";
const GUARD =
"export function isZz(value: unknown): value is Zz {\n" +
" return typeof value === 'string' && (ZZS as ReadonlyArray<string>).includes(value);\n}\n";
/**
* Every source shape the four pieces can arrive in. Each must be
* enrolled on its own: these are the forms a contributor reaches for
* without thinking, and a scan that stops matching one fails here by
* name rather than reporting a quietly smaller population.
*/
const INTRUDER_SHAPES: ReadonlyArray<readonly [string, string]> = Object.freeze([
["an array-literal membership list", OBJECT + DERIVED + FROZEN_LIST + GUARD],
[
"a multi-line Object.values membership list",
OBJECT +
DERIVED +
"export const ZZS: ReadonlyArray<Zz> = Object.freeze(\n Object.values(ZZ),\n);\n" +
GUARD,
],
[
"an unfrozen membership list",
OBJECT + DERIVED + "export const ZZS: ReadonlyArray<Zz> = [ZZ.a, ZZ.b];\n" + GUARD,
],
[
"an arrow-function guard",
OBJECT +
DERIVED +
FROZEN_LIST +
"export const isZz = (value: unknown): value is Zz =>\n" +
" typeof value === 'string' && (ZZS as ReadonlyArray<string>).includes(value);\n",
],
[
"single-quoted values",
"export const ZZ = Object.freeze({\n a: 'a',\n b: 'b',\n} as const);\n" +
DERIVED +
FROZEN_LIST +
GUARD,
],
[
"a brace inside a value and a brace inside a comment",
'export const ZZ = Object.freeze({\n // closes nothing: }\n a: "a }",\n b: "b",\n} as const);\n' +
DERIVED +
FROZEN_LIST +
GUARD,
],
["a guard declared before the object it reads", GUARD + OBJECT + DERIVED + FROZEN_LIST],
[
"a vocabulary behind a regex literal holding an unpaired quote",
'const QUOTED = /["]/;\nexport const ok = QUOTED.source;\n' +
OBJECT +
DERIVED +
FROZEN_LIST +
GUARD,
],
[
// The positive control for the backtick hole. The regex line is
// `src/core/vault.ts:88` verbatim, and before the shared lexer
// landed it opened a phantom template that blanked 9,706 of that
// module's 31,608 bytes - hiding `DOUBLE_QUOTED_ESCAPES`, the one
// frozen binding in the tree this census could not see. A masker
// that reads a backtick inside a regex as a template opener
// reports this file as carrying no vocabulary at all.
"a vocabulary behind a regex literal holding a backtick",
"const CODE_BLOCK_RE = /```[\\s\\S]*?```|`[^`]+`/g;\n" +
"export const source = CODE_BLOCK_RE.source;\n" +
OBJECT +
DERIVED +
FROZEN_LIST +
GUARD,
],
]);
for (const [shape, source] of INTRUDER_SHAPES) {
test(`a new vocabulary written as ${shape} is reported unregistered`, () => {
expect(unregisteredWith({ path: "src/core/zz-intruder.ts", text: source })).toEqual(["ZZ"]);
});
}
test("the module the reviewer smuggled past this file is now reported", () => {
// Reproduced from the review: a duplicate value, a member no value
// declares, and a guard that accepts every string - three of the
// defects `auditVocabulary` exists to catch. It scored 63 pass /
// 0 fail here before the scan existed.
const text =
'export const ZZ_NEW_VOCAB = Object.freeze({\n first: "same",\n second: "same",\n} as const);\n' +
"export type ZzNewVocab = (typeof ZZ_NEW_VOCAB)[keyof typeof ZZ_NEW_VOCAB];\n" +
"export const ZZ_NEW_VOCABS: ReadonlyArray<string> = Object.freeze([\n" +
' ZZ_NEW_VOCAB.first,\n "phantom",\n]);\n' +
"export function isZzNewVocab(value: unknown): value is ZzNewVocab {\n" +
" return typeof value === 'string' && ZZ_NEW_VOCABS.length > 0;\n}\n";
expect(unregisteredWith({ path: "src/core/zz-new-vocab.ts", text })).toEqual(["ZZ_NEW_VOCAB"]);
});
/**
* Shapes that must stay OUT. A census that reports frozen objects which
* are not vocabularies gets deleted, and each of these is a live idiom
* in this tree - the second one by name.
*/
const NON_VOCABULARY_SHAPES: ReadonlyArray<readonly [string, string]> = Object.freeze([
[
"a frozen object with no derived union type",
'export const ZZ = Object.freeze({ a: "a" });\n' +
"export const ZZS = Object.freeze(Object.values(ZZ));\n" +
"export function isZz(value: unknown): boolean {\n" +
" return ZZS.includes(value as string);\n}\n",
],
[
"a curated ordering with no guard, as DREAM_STEP_RUNNABLE is",
OBJECT + DERIVED + "export const ZZ_RUNNABLE: ReadonlyArray<Zz> = Object.freeze([ZZ.a]);\n",
],
[
"a frozen lookup whose values are not literals",
"export const ZZ = Object.freeze({ a: readSourceTree, b: maskSource });\n" +
DERIVED +
"export const ZZS = Object.freeze(Object.values(ZZ));\n" +
"export function isZz(value: unknown): boolean {\n" +
" return ZZS.includes(value as never);\n}\n",
],
[
"a guard that takes an already-narrowed string",
OBJECT +
DERIVED +
FROZEN_LIST +
"export function isZz(value: string): value is Zz {\n" +
" return (ZZS as ReadonlyArray<string>).includes(value);\n}\n",
],
]);
for (const [shape, source] of NON_VOCABULARY_SHAPES) {
test(`${shape} is not dragged into the population`, () => {
expect(unregisteredWith({ path: "src/core/zz-intruder.ts", text: source })).toEqual([]);
});
}
});