@objectstack/lint 16.1.0 → 17.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/validate-widget-bindings.ts","../src/validate-expressions.ts","../src/validate-list-view-mode.ts","../src/validate-flow-trigger-readiness.ts","../src/validate-view-containers.ts","../src/validate-responsive-styles.ts","../src/validate-jsx-pages.ts","../src/validate-react-pages.ts","../src/validate-react-page-props.ts","../src/validate-page-source-styling.ts","../src/validate-record-title.ts","../src/validate-semantic-roles.ts","../src/validate-form-layout.ts","../src/validate-visibility-predicates.ts","../src/validate-capability-references.ts","../src/validate-approval-approvers.ts","../src/validate-security-posture.ts","../src/validate-dashboard-action-refs.ts","../src/build-access-matrix.ts"],"sourcesContent":["// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// @objectstack/lint — public API.\n//\n// Static, build-time validation over an ObjectStack metadata graph. Every rule\n// is a pure `(stack) => Finding[]` function: no I/O, no runtime, no filesystem\n// — it operates on an in-memory, schema-parsed stack object. Shared by the\n// CLI's `os validate`/`compile` AND any other consumer (e.g. AI authoring) so\n// hand-authored and generated apps are held to the same bar (ADR-0019).\n//\n// Dependency direction is one-way: lint → @objectstack/spec (the contract).\n// It never depends on a runtime, and it is never bundled into a frontend.\n\nexport {\n validateWidgetBindings,\n WIDGET_DATASET_UNKNOWN,\n WIDGET_DIMENSION_UNKNOWN,\n WIDGET_MEASURE_UNKNOWN,\n CHART_FIELD_UNKNOWN,\n CHART_CONFIG_MISSING,\n TABLE_COUNT_ONLY,\n MEASURE_AGGREGATE_INCOHERENT,\n DASHBOARD_FILTER_FIELD_UNKNOWN,\n} from './validate-widget-bindings.js';\nexport type { WidgetBindingFinding, WidgetBindingSeverity } from './validate-widget-bindings.js';\n\nexport { validateStackExpressions } from './validate-expressions.js';\nexport type { ExprIssue } from './validate-expressions.js';\n\nexport { validateListViewMode, LIST_VIEW_FILTERS_IN_VIEWS_MODE } from './validate-list-view-mode.js';\nexport type { ListViewModeFinding, ListViewModeSeverity } from './validate-list-view-mode.js';\nexport {\n validateFlowTriggerReadiness,\n FLOW_TRIGGER_UNKNOWN_OBJECT,\n FLOW_DRAFT_STATUS_AMBIGUOUS,\n} from './validate-flow-trigger-readiness.js';\nexport type {\n FlowTriggerReadinessFinding,\n FlowTriggerReadinessSeverity,\n} from './validate-flow-trigger-readiness.js';\n\nexport { validateViewContainers, VIEW_CONTAINER_SHAPE } from './validate-view-containers.js';\nexport type { ViewContainerFinding, ViewContainerSeverity } from './validate-view-containers.js';\n\nexport {\n validateResponsiveStyles,\n STYLE_NODE_MISSING_ID,\n STYLE_CLASSNAME_TAILWIND,\n STYLE_RESPONSIVE_NO_BASE,\n STYLE_UNKNOWN_CSS_PROPERTY,\n STYLE_UNKNOWN_TOKEN,\n} from './validate-responsive-styles.js';\nexport type { StyleFinding, StyleSeverity } from './validate-responsive-styles.js';\nexport { validateJsxPages } from './validate-jsx-pages.js';\nexport type { JsxPageFinding, JsxPageSeverity } from './validate-jsx-pages.js';\nexport { validateReactPages } from './validate-react-pages.js';\nexport type { ReactPageFinding, ReactPageSeverity } from './validate-react-pages.js';\nexport { validateReactPageProps } from './validate-react-page-props.js';\nexport type { ReactPropFinding, ReactPropSeverity } from './validate-react-page-props.js';\nexport { validatePageSourceStyling, PAGE_SOURCE_CLASSNAME } from './validate-page-source-styling.js';\nexport type { SourceStyleFinding, SourceStyleSeverity } from './validate-page-source-styling.js';\n\nexport {\n validateRecordTitle,\n TITLE_FORMAT_RETIRED,\n TITLE_UNRESOLVABLE,\n} from './validate-record-title.js';\nexport type { RecordTitleFinding, RecordTitleSeverity } from './validate-record-title.js';\n\nexport {\n validateSemanticRoles,\n FIELD_GROUP_UNDECLARED,\n FIELD_GROUP_EMPTY,\n SEMANTIC_ROLE_FIELD_UNKNOWN,\n} from './validate-semantic-roles.js';\nexport type { SemanticRoleFinding, SemanticRoleSeverity } from './validate-semantic-roles.js';\n\nexport {\n validateFormLayout,\n FORM_FIELD_UNKNOWN,\n FORM_COLSPAN_ABSOLUTE,\n} from './validate-form-layout.js';\nexport type { FormLayoutFinding, FormLayoutSeverity } from './validate-form-layout.js';\n\nexport {\n validateVisibilityPredicates,\n VISIBILITY_ALIAS_DEPRECATED,\n VISIBILITY_ROOT_MISLAYERED,\n} from './validate-visibility-predicates.js';\nexport type {\n VisibilityFinding,\n VisibilitySeverity,\n VisibilityLayer,\n VisibilityOptions,\n} from './validate-visibility-predicates.js';\n\nexport {\n validateCapabilityReferences,\n CAPABILITY_REFERENCE_UNKNOWN,\n} from './validate-capability-references.js';\nexport type { CapabilityRefFinding, CapabilityRefSeverity } from './validate-capability-references.js';\n\nexport {\n validateApprovalApprovers,\n APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER,\n APPROVAL_APPROVER_TYPE_DEPRECATED,\n APPROVAL_APPROVER_TYPE_UNKNOWN,\n APPROVAL_ESCALATION_REASSIGN_NO_TARGET,\n} from './validate-approval-approvers.js';\nexport type { ApprovalApproverFinding, ApprovalApproverSeverity } from './validate-approval-approvers.js';\n\nexport {\n validateSecurityPosture,\n SECURITY_OWD_UNSET,\n SECURITY_OWD_ALIAS,\n SECURITY_EXTERNAL_WIDER,\n SECURITY_WILDCARD_VAMA,\n SECURITY_ANCHOR_HIGH_PRIVILEGE,\n SECURITY_ROLE_WORD,\n SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,\n SECURITY_PRIVATE_NO_READSCOPE,\n SECURITY_MASTER_DETAIL_UNGRANTED,\n SECURITY_GRANT_EXPIRED_AT_AUTHORING,\n SECURITY_DELEGATION_MISSING_REASON,\n} from './validate-security-posture.js';\nexport type { SecurityFinding, SecuritySeverity } from './validate-security-posture.js';\n\nexport {\n validateDashboardActionRefs,\n DASHBOARD_ACTION_TARGET_UNDEFINED,\n DASHBOARD_ACTION_ROUTE_UNRESOLVED,\n} from './validate-dashboard-action-refs.js';\nexport type {\n DashboardActionRefFinding,\n DashboardActionRefSeverity,\n} from './validate-dashboard-action-refs.js';\n\nexport { buildAccessMatrix, diffAccessMatrix } from './build-access-matrix.js';\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { isIncoherentAggregate } from '@objectstack/spec/data';\n\n/**\n * Build-time dashboard widget binding diagnostics (issues #1719, #1721).\n *\n * Runs at `objectstack validate`/`compile`/`build` AFTER the stack has been\n * schema-parsed, so every widget's `dataset` reference can be linked to its\n * `defineDataset` and each entry in `dimensions`/`values` resolved to a\n * declared dimension/measure. This is the semantic/cross-reference phase —\n * the rules here cannot run during plain Zod parsing of the raw widget\n * literal (the dataset may even live in another package of the stack).\n *\n * Reference-integrity rules (#1721) — severity `error`, the page is broken:\n *\n * - `widget-dataset-unknown` — `dataset` does not resolve to a declared\n * `Dataset`.\n * - `widget-dimension-unknown` — a `dimensions[]` entry is not a dimension\n * name on the bound dataset.\n * - `widget-measure-unknown` — a `values[]` entry is not a measure name on\n * the bound dataset.\n * - `chart-field-unknown` — a `chartConfig` binding names a field the query\n * result will not contain: `xAxis.field` must be one of the widget's\n * dimensions (or a dataset dimension), and each `yAxis[].field` /\n * `series[].name` must be one of the widget's selected measures\n * (`values`). Post-cutover (ADR-0021) the result rows are keyed by\n * measure NAME (e.g. `sum_amount`), not the base column (`amount`) — a\n * stale base-column reference renders the axis but an empty series.\n * - `widget-legacy-analytics-unrenderable` (#1878/#1894) — a widget uses the\n * removed pre-ADR-0021 inline-analytics shape (`categoryField`/`rowField`/…)\n * as its ONLY data wiring: no `dataset`, no `object`, no inline `data`. The\n * renderer reads only the dataset path, so the widget has no data at all and\n * renders nothing. Errored (not warned) so this class of authoring mistake —\n * very often an AI emitting a removed shape — fails the build instead of\n * shipping a blank widget past human review.\n * - `dashboard-filter-field-unknown` (#3365) — a dashboard-level filter\n * (`dateRange` or a `globalFilters[]` entry) is wired into EVERY widget's\n * analytics query (#2501), but its EFFECTIVE field (after any `filterBindings`\n * re-target) does not exist on a bound widget's dataset object. The widget's\n * query then references a non-existent column and crashes at render time\n * (`no such column …`) — a build-decidable invariant that previously escaped\n * the static gate and failed only when a user opened the dashboard. A widget\n * opts out with `filterBindings: { <name>: false }` or re-targets to a real\n * field. This is the same field-existence invariant ADR-0032 enforces for\n * CEL formula / sharing-rule references, applied to dashboard filter fields.\n *\n * Advisory rules — severity `warning`, build stays green:\n *\n * - `chart-config-missing` — a chart-type widget (bar/line/pie/…) has no\n * `chartConfig`, so the renderer cannot tell which measure to plot.\n * - `table-count-only` (#1719) — a `table`/`pivot` widget whose selected\n * measures are ALL `aggregate: 'count'` and which declares no\n * `dimensions` asks the analytics service for a single summary row. That\n * is the shape a `metric` widget wants — for a table it almost always\n * means the author wanted a per-record listing, which is not an\n * analytics dataset at all (model it as an object-bound ListView,\n * ADR-0017). Evaluated on the WIDGET's binding, not the dataset.\n * - `measure-aggregate-incoherent` — a dataset measure aggregates its field\n * in a way that produces a meaningless number: today, SUM (or\n * `count_distinct`) of a `percent`/rate field, whose total routinely\n * exceeds 100%. Rates must AVG. Checked once per dataset (independent of\n * any widget) when the bound object's field types are known.\n * - `widget-legacy-analytics-shape` (#1878/#1894) — a widget sets a\n * pre-ADR-0021 inline key (`categoryField`/`valueField`/`xAxisField`/\n * `yAxisFields`/`aggregate`/`aggregation`/`rowField`/`columnField`) that the\n * single-form cutover removed. The dashboard renderer routes dataset-bound\n * widgets through `DatasetWidget` and never reads these, so they are a\n * silent no-op. Steers the author onto `dataset`+`dimensions`+`values`.\n *\n * Warnings can be deliberately suppressed per widget via\n * `suppressWarnings: ['<rule-id>']`; errors cannot — they describe a\n * binding the analytics service cannot satisfy.\n */\n\nexport const WIDGET_DATASET_UNKNOWN = 'widget-dataset-unknown';\nexport const WIDGET_DIMENSION_UNKNOWN = 'widget-dimension-unknown';\nexport const WIDGET_MEASURE_UNKNOWN = 'widget-measure-unknown';\nexport const CHART_FIELD_UNKNOWN = 'chart-field-unknown';\nexport const CHART_CONFIG_MISSING = 'chart-config-missing';\nexport const TABLE_COUNT_ONLY = 'table-count-only';\nexport const MEASURE_AGGREGATE_INCOHERENT = 'measure-aggregate-incoherent';\nexport const WIDGET_LEGACY_ANALYTICS_SHAPE = 'widget-legacy-analytics-shape';\nexport const WIDGET_LEGACY_ANALYTICS_UNRENDERABLE = 'widget-legacy-analytics-unrenderable';\nexport const DASHBOARD_FILTER_FIELD_UNKNOWN = 'dashboard-filter-field-unknown';\n\n/**\n * Pre-ADR-0021 inline-analytics keys. The single-form cutover replaced them\n * with the semantic-layer shape (`dataset` + `dimensions` + `values`); the\n * dashboard renderer routes dataset-bound widgets through `DatasetWidget` and\n * never reads these, so authoring one today is a silent no-op. Warned (not\n * errored) because they still parse and a legacy object-bound widget keeps\n * rendering — the author is just being steered to the governed shape.\n * (liveness audit #1878 / #1894).\n *\n * Interplay with `DashboardWidgetSchema.strict()` (framework#3251, protocol 16):\n * on the schema-parsed CLI paths (`compile`, `validate`) strict rejects these\n * keys as a hard parse error *before* binding validation runs, so these rules\n * are effectively preempted there. They remain the friendly, suppressible\n * bridge on the raw-config paths (`lint`, `doctor`) that hand\n * `validateWidgetBindings` un-parsed config — keeping the actionable\n * \"steer to the dataset shape\" message rather than a bare unknown-key error.\n */\nconst LEGACY_ANALYTICS_KEYS = [\n 'categoryField', 'valueField', 'xAxisField', 'yAxisFields',\n 'aggregate', 'aggregation', 'rowField', 'columnField',\n] as const;\n\nexport type WidgetBindingSeverity = 'error' | 'warning';\n\nexport interface WidgetBindingFinding {\n /** `error` = unresolvable binding (broken page); `warning` = advisory. */\n severity: WidgetBindingSeverity;\n /** Diagnostic rule id (registry entry), e.g. `widget-measure-unknown`. */\n rule: string;\n /** Human-readable location, e.g. `dashboard \"x\" › widget \"y\"`. */\n where: string;\n /** Config path, e.g. `dashboards[0].widgets[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix (or deliberately suppress) it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction asStrings(v: unknown): string[] {\n return Array.isArray(v) ? v.filter((s): s is string => typeof s === 'string') : [];\n}\n\n/**\n * Chart families whose renderer needs a `chartConfig` measure mapping.\n * Single-value types (metric/kpi/gauge/…) plot their lone value and tabular\n * types (table/pivot) render every column, so they are exempt.\n */\nconst CHART_TYPES = new Set([\n 'bar', 'horizontal-bar', 'column',\n 'line', 'area',\n 'pie', 'donut', 'funnel',\n 'scatter', 'treemap', 'sankey', 'radar',\n]);\n\nfunction levenshtein(a: string, b: string): number {\n const m = a.length, n = b.length;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const cur = [i];\n for (let j = 1; j <= n; j++) {\n cur[j] = Math.min(\n prev[j] + 1,\n cur[j - 1] + 1,\n prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),\n );\n }\n prev = cur;\n }\n return prev[n];\n}\n\n/**\n * Nearest declared name for a typo'd/stale reference, or undefined when\n * nothing is close. Containment is checked first because the cutover's\n * canonical drift is base column → prefixed measure name (`amount` →\n * `sum_amount`), which is far in edit distance but obvious to a human.\n */\nfunction didYouMean(input: string, candidates: Iterable<string>): string | undefined {\n let best: string | undefined;\n let bestScore = Infinity;\n for (const c of candidates) {\n let score: number;\n if (input.length >= 3 && (c.includes(input) || input.includes(c))) {\n score = Math.abs(c.length - input.length);\n } else {\n const d = levenshtein(input, c);\n if (d > Math.max(2, Math.floor(input.length / 3))) continue;\n score = 100 + d;\n }\n if (score < bestScore) { bestScore = score; best = c; }\n }\n return best;\n}\n\nfunction suggest(input: string, candidates: Iterable<string>): string {\n const s = didYouMean(input, candidates);\n return s ? ` Did you mean \"${s}\"?` : '';\n}\n\nfunction list(names: Iterable<string>): string {\n const arr = [...names];\n return arr.length > 0 ? arr.join(', ') : '(none)';\n}\n\n// ── dashboard-filter field-existence (#3365) ─────────────────────────────────\n\n/** Reserved filter name for the dashboard's built-in date range (#2501). */\nconst DATE_RANGE_FILTER_NAME = 'dateRange';\n/**\n * Default field of the built-in date range when `dateRange.field` is omitted.\n * MUST track objectui `dashboard-filters.ts` `DATE_RANGE_DEFAULT_FIELD` — the\n * runtime this check shadows. `created_at` is a registry-injected system field\n * (below), so a bare `dateRange` never false-positives.\n */\nconst DATE_RANGE_DEFAULT_FIELD = 'created_at';\n\n/**\n * Registry-injected fields present on (almost) every object but NOT declared in\n * `object.fields`, so a dashboard filter targeting one must not be flagged as a\n * missing column. Superset of the objectql registry's `applySystemFields`\n * (audit columns, ownership, tenant, soft-delete) and spec's `SystemFieldName`.\n * Deliberately generous: the cost of over-inclusion is at worst a missed error\n * on a `systemFields: false` object (rare); the cost of under-inclusion is a\n * false build failure on the ubiquitous `dateRange` → `created_at` default. The\n * near-zero-false-positive bias mirrors ADR-0032's field-ref validator.\n */\nconst SYSTEM_FIELDS = new Set<string>([\n 'id',\n 'created_at', 'created_by', 'updated_at', 'updated_by',\n 'owner_id', 'organization_id', 'tenant_id', 'user_id',\n 'deleted_at',\n]);\n\ninterface DashFilterDef {\n /** Stable filter name — the key widgets bind against in `filterBindings`. */\n name: string;\n /** Default target field when a widget declares no explicit binding. */\n field: string;\n /** Legacy widget-id allow-list; gates the DEFAULT binding only. */\n targetWidgets?: string[];\n}\n\n/**\n * Normalize a dashboard's declared filters into `{ name, field, targetWidgets }`\n * defs — the built-in `dateRange` (reserved name) first, then every\n * `globalFilters[]` entry named by its `name` (defaulting to `field`). Later\n * duplicates win. Mirrors objectui `resolveDashboardFilterDefs`.\n */\nfunction dashboardFilterDefs(dash: AnyRec): DashFilterDef[] {\n const byName = new Map<string, DashFilterDef>();\n\n const dateRange = dash.dateRange;\n if (dateRange && typeof dateRange === 'object') {\n const declared = (dateRange as AnyRec).field;\n const field = typeof declared === 'string' && declared ? declared : DATE_RANGE_DEFAULT_FIELD;\n byName.set(DATE_RANGE_FILTER_NAME, { name: DATE_RANGE_FILTER_NAME, field });\n }\n\n for (const f of asArray(dash.globalFilters)) {\n if (typeof f.field !== 'string' || !f.field) continue;\n const name = typeof f.name === 'string' && f.name ? f.name : f.field;\n const targetWidgets = Array.isArray(f.targetWidgets)\n ? f.targetWidgets.filter((w): w is string => typeof w === 'string')\n : undefined;\n byName.set(name, { name, field: f.field, targetWidgets });\n }\n\n return [...byName.values()];\n}\n\n/**\n * Resolve which field of `widget` a filter binds to, or `undefined` when the\n * widget is not bound (opted out / not targeted). Precedence mirrors objectui\n * `resolveBoundField`: explicit `filterBindings` entry (string re-targets,\n * `false` opts out — both win) → legacy `targetWidgets` allow-list → the\n * filter's own default `field`. `explicit` distinguishes an author-chosen field\n * (a typo they must fix) from the inherited default (which they may opt out of).\n */\nfunction effectiveFilterField(\n widget: AnyRec,\n def: DashFilterDef,\n): { field: string; explicit: boolean } | undefined {\n const bindings = widget.filterBindings;\n const binding = bindings && typeof bindings === 'object'\n ? (bindings as AnyRec)[def.name]\n : undefined;\n if (binding === false) return undefined;\n if (typeof binding === 'string' && binding) return { field: binding, explicit: true };\n if (def.targetWidgets && def.targetWidgets.length > 0) {\n const id = typeof widget.id === 'string' ? widget.id : undefined;\n if (!id || !def.targetWidgets.includes(id)) return undefined;\n }\n return { field: def.field, explicit: false };\n}\n\n/**\n * Validate every dashboard widget's dataset binding. Returns the list of\n * findings (empty = clean). Caller decides how to surface them: `error`\n * findings describe bindings the analytics service cannot satisfy and\n * should fail validate/build; `warning` findings are advisory and must\n * never fail the build on their own.\n */\nexport function validateWidgetBindings(stack: AnyRec): WidgetBindingFinding[] {\n const findings: WidgetBindingFinding[] = [];\n\n const datasets = new Map<string, AnyRec>();\n for (const ds of asArray(stack.datasets)) {\n if (typeof ds.name === 'string') datasets.set(ds.name, ds);\n }\n\n // ── (0) dataset measures aggregate their field coherently ──\n // A measure that SUMs a percentage/rate field produces a meaningless total\n // (it can exceed 100%); rates must AVG. This is a dataset-level defect (it\n // does not depend on any widget), so it is checked once over every dataset\n // whose object's field types are known. Advisory — the page still renders.\n const objectFieldTypes = new Map<string, Map<string, string>>();\n for (const o of asArray(stack.objects)) {\n if (typeof o.name !== 'string') continue;\n const fm = new Map<string, string>();\n for (const f of asArray(o.fields)) {\n if (typeof f.name === 'string' && typeof f.type === 'string') fm.set(f.name, f.type);\n }\n objectFieldTypes.set(o.name, fm);\n }\n const datasetList = asArray(stack.datasets);\n for (let i = 0; i < datasetList.length; i++) {\n const ds = datasetList[i];\n const fieldTypes = typeof ds.object === 'string' ? objectFieldTypes.get(ds.object) : undefined;\n if (!fieldTypes) continue; // cannot judge without the object's field types\n const dsMeasures = asArray(ds.measures);\n for (let k = 0; k < dsMeasures.length; k++) {\n const m = dsMeasures[k];\n const field = typeof m.field === 'string' ? m.field : undefined;\n const aggregate = typeof m.aggregate === 'string' ? m.aggregate : undefined;\n if (!field || !aggregate) continue; // count(*) and underivable measures are fine\n const ftype = fieldTypes.get(field);\n if (ftype && isIncoherentAggregate(aggregate, ftype)) {\n findings.push({\n severity: 'warning',\n rule: MEASURE_AGGREGATE_INCOHERENT,\n where: `dataset \"${typeof ds.name === 'string' ? ds.name : `(dataset ${i})`}\" › measure \"${typeof m.name === 'string' ? m.name : `(measure ${k})`}\"`,\n path: `datasets[${i}].measures[${k}]`,\n message:\n `measure \"${m.name}\" applies ${aggregate} to ${ftype} field \"${field}\" — ` +\n `summed percentages are meaningless (they can exceed 100%).`,\n hint:\n `Use aggregate \"avg\" for percentage/rate fields (or \"count\" of records). ` +\n `If a running total is genuinely intended, suppress with: ` +\n `suppressWarnings: ['${MEASURE_AGGREGATE_INCOHERENT}'] on the measure.`,\n });\n }\n }\n }\n\n const dashboards = asArray(stack.dashboards);\n for (let i = 0; i < dashboards.length; i++) {\n const dash = dashboards[i];\n const dashName = typeof dash.name === 'string' ? dash.name : `(dashboard ${i})`;\n const widgets = Array.isArray(dash.widgets) ? (dash.widgets as AnyRec[]) : [];\n // Dashboard-level filters (`dateRange` + `globalFilters`) are broadcast into\n // every widget's query (#2501) — resolved once here, checked per widget below.\n const dashFilterDefs = dashboardFilterDefs(dash);\n\n for (let j = 0; j < widgets.length; j++) {\n const w = widgets[j];\n const widgetId = typeof w.id === 'string' ? w.id : `(widget ${j})`;\n const where = `dashboard \"${dashName}\" › widget \"${widgetId}\"`;\n const path = `dashboards[${i}].widgets[${j}]`;\n const suppressed = (rule: string): boolean =>\n Array.isArray(w.suppressWarnings) && w.suppressWarnings.includes(rule);\n const push = (f: Omit<WidgetBindingFinding, 'where' | 'path'>): void => {\n if (f.severity === 'warning' && suppressed(f.rule)) return;\n findings.push({ ...f, where, path });\n };\n\n // ── (a0) legacy pre-ADR-0021 analytics shape ──\n // Steer authors (very often an AI) off the removed inline shape and onto\n // the semantic-layer `dataset`+`dimensions`+`values`. The renderer reads\n // ONLY the dataset path, so these keys are dead. Two severities:\n // • ERROR — the legacy keys are the widget's only (dead) data wiring\n // (no dataset / object / inline data): it renders nothing.\n // • warning — a data source is present, so the widget still renders and\n // the legacy keys are merely ignored noise (suppressible).\n const legacyUsed = LEGACY_ANALYTICS_KEYS.filter((k) => w[k] !== undefined);\n if (legacyUsed.length > 0) {\n const optionsData =\n typeof w.options === 'object' && w.options !== null &&\n (w.options as AnyRec).data !== undefined;\n const hasDataSource =\n w.dataset !== undefined || w.object !== undefined ||\n w.data !== undefined || optionsData;\n const keyList = legacyUsed.map((k) => `\\`${k}\\``).join(', ');\n const plural = legacyUsed.length > 1;\n const datasetHint =\n `Bind a semantic dataset and select fields BY NAME: ` +\n `\\`dataset: '<name>', dimensions: [...], values: [...]\\`. ` +\n `Dataset-bound widgets render through DatasetWidget (pivot rows/cols come from ` +\n `\\`dimensions\\`, cell values from \\`values\\`).`;\n if (!hasDataSource) {\n push({\n severity: 'error',\n rule: WIDGET_LEGACY_ANALYTICS_UNRENDERABLE,\n message:\n `sets legacy analytics key${plural ? 's' : ''} ${keyList} ` +\n `(removed by the ADR-0021 single-form cutover) and binds no data source ` +\n `(no \\`dataset\\`, \\`object\\`, or inline \\`data\\`) — it renders nothing.`,\n hint:\n `${datasetHint} The renderer ignores the legacy keys, so without a data ` +\n `source this widget has no data at all.`,\n });\n } else {\n push({\n severity: 'warning',\n rule: WIDGET_LEGACY_ANALYTICS_SHAPE,\n message:\n `sets legacy analytics key${plural ? 's' : ''} ${keyList} that the ADR-0021 ` +\n `single-form cutover removed — the dashboard renderer ignores ${plural ? 'them' : 'it'}.`,\n hint:\n `${datasetHint} These inline keys are a no-op. ` +\n `Suppress with suppressWarnings: ['${WIDGET_LEGACY_ANALYTICS_SHAPE}'] if intentional.`,\n });\n }\n }\n\n // ── (a) dataset reference resolves ──\n const dsName = typeof w.dataset === 'string' ? w.dataset : undefined;\n const dataset = dsName ? datasets.get(dsName) : undefined;\n if (dsName && !dataset) {\n push({\n severity: 'error',\n rule: WIDGET_DATASET_UNKNOWN,\n message: `dataset \"${dsName}\" does not resolve to a declared dataset.`,\n hint:\n `Declared datasets: ${list(datasets.keys())}.${suggest(dsName, datasets.keys())} ` +\n `Define the dataset with defineDataset() or fix the reference (ADR-0021).`,\n });\n }\n // Without a resolved dataset there is nothing to check names against.\n if (!dataset) continue;\n\n // ── (a1) dashboard filter fields exist on the widget's object (#3365) ──\n // Each dashboard-level filter is ANDed into this widget's analytics query\n // (#2501); a filter whose EFFECTIVE field (after `filterBindings`) is not a\n // column on the bound dataset object emits SQL like `WHERE close_date …`\n // against a table without that column and the widget crashes at query time.\n // Errored (not warned): a broken query, not advice. The opt-out is the\n // author's own `filterBindings: { <name>: false }`, so no suppression needed.\n if (dashFilterDefs.length > 0) {\n const datasetObject = typeof dataset.object === 'string' ? dataset.object : undefined;\n // Only judge when the bound object's fields are known in THIS stack; an\n // object from another installed package is unknowable here — skip rather\n // than false-positive (mirrors the measure-aggregate check above).\n const objectFields = datasetObject ? objectFieldTypes.get(datasetObject) : undefined;\n if (objectFields) {\n for (const def of dashFilterDefs) {\n const eff = effectiveFilterField(w, def);\n if (!eff) continue; // opted out / not targeted → filter never applies\n const field = eff.field;\n // A relationship path (`account.region`) is resolved by the query\n // engine, not a base column, so it can't be checked here — skip it.\n if (field.includes('.')) continue;\n if (objectFields.has(field) || SYSTEM_FIELDS.has(field)) continue;\n push({\n severity: 'error',\n rule: DASHBOARD_FILTER_FIELD_UNKNOWN,\n message: eff.explicit\n ? `binds dashboard filter \\`${def.name}\\` to field \\`${field}\\` ` +\n `(via filterBindings), but object \\`${datasetObject}\\` (dataset \"${dsName}\") ` +\n `has no field \\`${field}\\`.`\n : `inherits dashboard filter \\`${def.name}(${field})\\`, but object ` +\n `\\`${datasetObject}\\` (dataset \"${dsName}\") has no field \\`${field}\\`.`,\n hint: eff.explicit\n ? `Point filterBindings: { ${def.name}: '<field>' } at a field that exists on ` +\n `\\`${datasetObject}\\`, or opt out with filterBindings: { ${def.name}: false }.` +\n `${suggest(field, objectFields.keys())} Object fields: ${list(objectFields.keys())}.`\n : `Set filterBindings: { ${def.name}: false } on this widget to opt out, or ` +\n `re-target to an existing field with filterBindings: { ${def.name}: '<field>' }.` +\n `${suggest(field, objectFields.keys())} Object fields: ${list(objectFields.keys())}.`,\n });\n }\n }\n }\n\n const dimensionNames = new Set<string>();\n for (const d of asArray(dataset.dimensions)) {\n if (typeof d.name === 'string') dimensionNames.add(d.name);\n }\n const measures = new Map<string, AnyRec>();\n for (const m of asArray(dataset.measures)) {\n if (typeof m.name === 'string') measures.set(m.name, m);\n }\n\n // ── (b) every dimensions[] entry is a dataset dimension ──\n const dims = asStrings(w.dimensions);\n for (let k = 0; k < dims.length; k++) {\n if (dimensionNames.has(dims[k])) continue;\n push({\n severity: 'error',\n rule: WIDGET_DIMENSION_UNKNOWN,\n message:\n `dimensions[${k}] \"${dims[k]}\" is not a dimension of dataset ` +\n `\"${dsName}\" (declared dimensions: ${list(dimensionNames)}).`,\n hint:\n `Widgets select dataset dimensions BY NAME.${suggest(dims[k], dimensionNames)} ` +\n `Add the dimension to the dataset or fix the reference.`,\n });\n }\n\n // ── (c) every values[] entry is a dataset measure ──\n const values = asStrings(w.values);\n for (let k = 0; k < values.length; k++) {\n if (measures.has(values[k])) continue;\n push({\n severity: 'error',\n rule: WIDGET_MEASURE_UNKNOWN,\n message:\n `values[${k}] \"${values[k]}\" is not a measure of dataset ` +\n `\"${dsName}\" (declared measures: ${list(measures.keys())}).`,\n hint:\n `Widgets select dataset measures BY NAME, not by base column.` +\n `${suggest(values[k], measures.keys())} ` +\n `Add the measure to the dataset or fix the reference.`,\n });\n }\n\n // ── (d) chartConfig bindings resolve against the widget's selection ──\n const chartConfig = (w.chartConfig && typeof w.chartConfig === 'object')\n ? (w.chartConfig as AnyRec)\n : undefined;\n const isChartType = typeof w.type === 'string' && CHART_TYPES.has(w.type);\n\n if (chartConfig) {\n // The query result carries the widget's selected dimensions and\n // measures; resolve every chartConfig field against that shape.\n const selectedValues = new Set(values.filter((v) => measures.has(v)));\n\n const xAxis = (chartConfig.xAxis && typeof chartConfig.xAxis === 'object')\n ? (chartConfig.xAxis as AnyRec)\n : undefined;\n // A field naming an entry of the widget's own (already-validated)\n // selection is not re-reported here — rules (b)/(c) own that error.\n if (xAxis && typeof xAxis.field === 'string'\n && !dimensionNames.has(xAxis.field) && !dims.includes(xAxis.field)) {\n push({\n severity: 'error',\n rule: CHART_FIELD_UNKNOWN,\n message:\n `chartConfig.xAxis.field \"${xAxis.field}\" does not resolve to a ` +\n `dimension of dataset \"${dsName}\" (declared dimensions: ${list(dimensionNames)}).`,\n hint: `Point xAxis.field at a dataset dimension name.${suggest(xAxis.field, dimensionNames)}`,\n });\n }\n\n const measureField = (label: string, field: string): void => {\n if (values.includes(field)) return; // resolvable, or already errored via rule (c)\n const declaredButUnselected = measures.has(field);\n push({\n severity: 'error',\n rule: CHART_FIELD_UNKNOWN,\n message: declaredButUnselected\n ? `chartConfig.${label} \"${field}\" is a measure of dataset \"${dsName}\" ` +\n `but is not selected in the widget's values (${list(values)}), so the ` +\n `query result will not contain it.`\n : `chartConfig.${label} \"${field}\" does not resolve to a measure of ` +\n `dataset \"${dsName}\" (declared measures: ${list(measures.keys())}).`,\n hint: declaredButUnselected\n ? `Add \"${field}\" to the widget's values, or bind the chart to a selected measure.`\n : `Post-cutover data is keyed by the dataset's measure NAME, not the ` +\n `base column.${suggest(field, selectedValues.size > 0 ? selectedValues : measures.keys())}`,\n });\n };\n\n const yAxes = Array.isArray(chartConfig.yAxis) ? (chartConfig.yAxis as AnyRec[]) : [];\n for (let k = 0; k < yAxes.length; k++) {\n const field = yAxes[k]?.field;\n if (typeof field === 'string') measureField(`yAxis[${k}].field`, field);\n }\n const series = Array.isArray(chartConfig.series) ? (chartConfig.series as AnyRec[]) : [];\n for (let k = 0; k < series.length; k++) {\n const name = series[k]?.name;\n if (typeof name === 'string') measureField(`series[${k}].name`, name);\n }\n } else if (isChartType) {\n push({\n severity: 'warning',\n rule: CHART_CONFIG_MISSING,\n message:\n `chart-type widget ('${w.type}') has no chartConfig — the renderer ` +\n `cannot determine which measure to plot, so the series renders empty.`,\n hint:\n `Add chartConfig with xAxis.field set to a dimension (${list(dims)}) and ` +\n `yAxis[].field set to a measure name (${list(values)}). If the default ` +\n `rendering is intentional, suppress with: suppressWarnings: ['${CHART_CONFIG_MISSING}']`,\n });\n }\n\n // ── (e) table/pivot bound to a count-only, dimensionless selection ──\n if (w.type !== 'table' && w.type !== 'pivot') continue;\n // Grouped by at least one dimension → genuinely aggregated rows.\n if (dims.length > 0) continue;\n if (values.length === 0) continue;\n const resolved = values.map((v) => measures.get(v));\n // An unresolvable measure name already errored above — don't guess here.\n if (resolved.some((m) => !m)) continue;\n\n // Derived measures combine other measures; treat them as non-count even\n // when their (ignored) `aggregate` says otherwise.\n const countOnly = resolved.every((m) => m!.aggregate === 'count' && !m!.derived);\n if (!countOnly) continue;\n\n push({\n severity: 'warning',\n rule: TABLE_COUNT_ONLY,\n message:\n `a '${w.type}' widget bound to dataset \"${dsName}\" selects only count ` +\n `measure(s) (${values.join(', ')}) and no dimensions, so it renders a ` +\n `single summary row — not a per-record list.`,\n hint:\n `A flat record listing is not an analytics dataset. Model it as an ` +\n `object-bound ListView (ADR-0017) surfaced through app navigation, and ` +\n `use a 'metric' widget here if you only need the count. If a single-row ` +\n `table is intentional, add an explicit dimension or suppress with: ` +\n `suppressWarnings: ['${TABLE_COUNT_ONLY}']`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time expression validation (ADR-0032 §Decision 1a + 1b).\n *\n * Runs at `objectstack compile`, where the whole normalized stack is in hand —\n * so flow conditions can be checked against the *resolved* object schema\n * (field existence) in addition to CEL syntax. Uses the one shared validator\n * from `@objectstack/formula`, so the verdict matches `registerFlow` and the\n * agent `validate_expression` tool exactly.\n *\n * Scope (v1): flow predicates (start/decision `config.condition` + edge\n * `condition`), object validation-rule / formula predicates, and UI action\n * `visible` / `disabled` predicates. Each error is located (flow/object/action\n * + node/edge/field) with a corrective message.\n */\n\nimport { validateExpression } from '@objectstack/formula';\n\nexport interface ExprIssue {\n where: string;\n message: string;\n source: string;\n /**\n * `error` fails the build (e.g. a bare ref in a record-scoped formula). `warning`\n * is advisory and never fails it (e.g. a possible field typo in a flattened flow\n * condition, which might be a flow variable). Absent ⇒ treat as `error`.\n */\n severity?: 'error' | 'warning';\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an `objects` collection (array or name-keyed map) to an array. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** object name → set of its field names, for schema-aware field checks. */\nfunction buildFieldIndex(objects: AnyRec[]): Map<string, string[]> {\n const idx = new Map<string, string[]>();\n for (const obj of objects) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fields = obj.fields;\n let names: string[] = [];\n if (Array.isArray(fields)) names = fields.map(f => (f as AnyRec).name).filter((n): n is string => typeof n === 'string');\n else if (fields && typeof fields === 'object') names = Object.keys(fields as AnyRec);\n idx.set(name, names);\n }\n return idx;\n}\n\n/**\n * object name → (field name → field type), for the #1928 tier-4 type-soundness\n * check. Handles both `fields` shapes (array of `{name, type}` and name-keyed\n * map). Fields with a non-string `type` are simply omitted (treated as `dyn`).\n */\nfunction buildFieldTypeIndex(objects: AnyRec[]): Map<string, Record<string, string>> {\n const idx = new Map<string, Record<string, string>>();\n for (const obj of objects) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fields = obj.fields;\n const types: Record<string, string> = {};\n if (Array.isArray(fields)) {\n for (const f of fields as AnyRec[]) {\n const fn = (f as AnyRec)?.name;\n const ft = (f as AnyRec)?.type;\n if (typeof fn === 'string' && typeof ft === 'string') types[fn] = ft;\n }\n } else if (fields && typeof fields === 'object') {\n for (const [fn, def] of Object.entries(fields as AnyRec)) {\n const ft = (def as AnyRec)?.type;\n if (typeof ft === 'string') types[fn] = ft;\n }\n }\n idx.set(name, types);\n }\n return idx;\n}\n\n/**\n * Validate every predicate in the stack. Returns the list of issues (empty =\n * clean). Caller decides how to surface / whether to fail the build.\n */\nexport function validateStackExpressions(stack: AnyRec): ExprIssue[] {\n const issues: ExprIssue[] = [];\n const objects = asArray(stack.objects);\n const fieldIndex = buildFieldIndex(objects);\n const fieldTypeIndex = buildFieldTypeIndex(objects);\n\n const check = (\n where: string,\n raw: unknown,\n objectName?: string,\n scope: 'record' | 'flattened' = 'flattened',\n ): void => {\n if (raw == null) return;\n const fields = objectName ? fieldIndex.get(objectName) : undefined;\n // Field types feed the #1928 tier-4 soundness warning; only consulted for\n // `record`-scoped sites, so it is harmless to pass for flattened ones too.\n const fieldTypes = objectName ? fieldTypeIndex.get(objectName) : undefined;\n const res = validateExpression('predicate', raw as string | { dialect?: string; source?: string },\n objectName ? { objectName, fields, fieldTypes, scope } : { scope });\n for (const e of res.errors) issues.push({ where, message: e.message, source: e.source, severity: 'error' });\n for (const w of res.warnings) issues.push({ where, message: w.message, source: w.source, severity: 'warning' });\n };\n\n // ── Flows ──────────────────────────────────────────────────────────\n for (const flow of asArray(stack.flows)) {\n const flowName = typeof flow.name === 'string' ? flow.name : '(unnamed flow)';\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n const edges = Array.isArray(flow.edges) ? (flow.edges as AnyRec[]) : [];\n // The record-change target object — `record.*` refs resolve against it.\n const startNode = nodes.find(n => n.type === 'start');\n const startCfg = (startNode?.config ?? {}) as AnyRec;\n const objectName = typeof startCfg.objectName === 'string' ? startCfg.objectName : undefined;\n\n for (const node of nodes) {\n const cfg = (node.config ?? {}) as AnyRec;\n check(`flow '${flowName}' · node '${node.id}' (${node.type}) condition`, cfg.condition, objectName);\n // #1870 — a `script` node must declare a callable target (`actionType` or\n // `function`). A node with neither is a silent no-op that otherwise passes\n // build. (Function *existence* isn't checkable here — functions are code,\n // not serialized into the artifact — so this is a structural check; the\n // runtime verifies the named function is actually registered.)\n if (node.type === 'script') {\n // `function` is canonical; `functionName` is an accepted alias.\n const fn =\n (typeof cfg.function === 'string' ? cfg.function.trim() : '') ||\n (typeof cfg.functionName === 'string' ? cfg.functionName.trim() : '');\n const action = typeof cfg.actionType === 'string' ? cfg.actionType.trim() : '';\n // Inline `config.script` (a JS body) is also a declared form — the\n // built-in runtime doesn't execute it (warned at run time), but the node\n // is not the empty no-op this check targets, so don't flag it.\n const inline = typeof cfg.script === 'string' ? cfg.script.trim() : '';\n if (!fn && !action && !inline) {\n issues.push({\n where: `flow '${flowName}' · node '${node.id}' (script) callable`,\n message:\n `script node declares neither \\`actionType\\` nor \\`function\\` — it would do nothing at runtime. ` +\n `Name a built-in action (e.g. \\`actionType: 'email'\\`) or a registered function ` +\n `(\\`function: 'my_fn'\\`, registered via \\`defineStack({ functions })\\`).`,\n source: JSON.stringify({ id: node.id, type: node.type, config: cfg }),\n });\n } else if (action === 'invoke_function' && !fn) {\n // `actionType: 'invoke_function'` is a marker that names no callable on\n // its own — the function name must be in `function`/`functionName`.\n issues.push({\n where: `flow '${flowName}' · node '${node.id}' (script) callable`,\n message:\n `script node uses \\`actionType: 'invoke_function'\\` but no \\`function\\` (or \\`functionName\\`) — ` +\n `it names no callable. Set \\`function: 'my_fn'\\` and register it via \\`defineStack({ functions })\\`.`,\n source: JSON.stringify({ id: node.id, type: node.type, config: cfg }),\n });\n }\n }\n }\n for (const edge of edges) {\n check(`flow '${flowName}' · edge '${edge.id}' (${edge.source}→${edge.target}) condition`, edge.condition, objectName);\n }\n }\n\n // ── Object validation-rule + formula predicates ────────────────────\n for (const obj of objects) {\n const objectName = typeof obj.name === 'string' ? obj.name : undefined;\n const validations = obj.validations ?? obj.validationRules;\n for (const rule of asArray(validations)) {\n const where = `object '${objectName}' · validation '${(rule.name as string) ?? '?'}'`;\n // Common predicate keys across rule shapes. Validation predicates are\n // `record`-scoped — no field flattening — so bare refs are flagged (#1928).\n check(where, rule.expression ?? rule.predicate ?? rule.condition ?? rule.formula, objectName, 'record');\n // `conditional` rules carry a nested `when` predicate (record-scoped).\n check(`${where} when`, (rule as AnyRec).when, objectName, 'record');\n }\n // Field-level formulas (computed fields) reference the same object.\n const fields = obj.fields;\n const fieldList = Array.isArray(fields)\n ? (fields as AnyRec[])\n : (fields && typeof fields === 'object' ? Object.values(fields as AnyRec) as AnyRec[] : []);\n\n // (ADR-0062 D7's `field.columnName`-on-external-objects rejection was removed\n // with `field.columnName` itself in #2377: the field no longer exists, so there\n // is no dual-source ambiguity to guard — external column mapping is `external.columnMap`.)\n\n for (const f of fieldList) {\n // Field-level conditional rules are server-enforced (rule-validator) and\n // record-scoped — a bare ref silently fails the rule (required/readonly\n // not enforced = data-integrity hole). #1928 class, same as actions.\n if (f && typeof f === 'object') {\n const fname = (f.name as string) ?? '?';\n for (const key of ['requiredWhen', 'readonlyWhen', 'conditionalRequired', 'visibleWhen'] as const) {\n check(`object '${objectName}' · field '${fname}' ${key}`, (f as AnyRec)[key], objectName, 'record');\n }\n }\n if (f && typeof f === 'object' && f.formula) {\n // formulas are `value` role (any return type), still CEL. They are\n // `record`-scoped — `record.<field>`, never bare — so flag bare refs (#1928).\n const res = validateExpression('value', f.formula as string | { dialect?: string; source?: string },\n objectName ? { objectName, fields: fieldIndex.get(objectName), fieldTypes: fieldTypeIndex.get(objectName), scope: 'record' } : { scope: 'record' });\n const fieldWhere = `object '${objectName}' · field '${(f.name as string) ?? '?'}' formula`;\n for (const e of res.errors) issues.push({ where: fieldWhere, message: e.message, source: e.source, severity: 'error' });\n for (const w of res.warnings) issues.push({ where: fieldWhere, message: w.message, source: w.source, severity: 'warning' });\n }\n }\n }\n\n // ── Action `visible` / `disabled` predicates ───────────────────────\n // Record-scoped, same as validation rules: a record-header / row action's\n // `visible` is evaluated by ActionEngine against `{ record, recordId,\n // objectName, user, … }` with fail-closed semantics, so a BARE field ref\n // (`done` instead of `record.done`) throws and the action is silently hidden\n // on every record (the trap behind the #2183 \"Mark Done never hides\" hunt).\n // Flagging it here turns that into a build error with a corrective message.\n // `disabled` may be a boolean (skip) or a predicate (check).\n const seenActions = new Set<string>();\n const checkAction = (where: string, action: AnyRec, objectName?: string): void => {\n const obj = objectName\n ?? (typeof action.objectName === 'string' ? action.objectName : undefined)\n ?? (typeof action.object === 'string' ? action.object : undefined);\n const name = typeof action.name === 'string' ? action.name : '?';\n const key = `${obj ?? ''}:${name}`;\n if (seenActions.has(key)) return; // de-dup (actions are merged onto objects AND kept top-level)\n seenActions.add(key);\n check(`${where} · action '${name}' visible`, action.visible, obj, 'record');\n if (typeof action.disabled !== 'boolean') {\n check(`${where} · action '${name}' disabled`, action.disabled, obj, 'record');\n }\n };\n for (const action of asArray(stack.actions)) {\n checkAction('stack', action);\n }\n for (const obj of objects) {\n const objectName = typeof obj.name === 'string' ? obj.name : undefined;\n for (const action of asArray(obj.actions)) {\n checkAction(`object '${objectName}'`, action, objectName);\n }\n }\n\n // ── Sharing-rule predicates (security-critical, record-scoped) ─────\n // A criteria sharing rule's `condition` decides which rows a principal sees.\n // It is evaluated against the record, so a bare ref silently changes access.\n for (const rule of asArray(stack.sharingRules)) {\n const ruleObj = typeof rule.object === 'string' ? rule.object : undefined;\n const where = `sharingRule '${(rule.name as string) ?? '?'}'${ruleObj ? ` (${ruleObj})` : ''} condition`;\n check(where, rule.condition ?? rule.criteria ?? rule.predicate, ruleObj, 'record');\n }\n\n // ── Hook `condition` predicates (record-scoped gate) ───────────────\n // A lifecycle hook's `condition` skips the handler when false; it is\n // evaluated against the record, so a bare ref silently makes the hook\n // run on every record (or never) instead of the intended subset.\n for (const hook of asArray(stack.hooks)) {\n const hookObj = typeof hook.object === 'string' ? hook.object : undefined; // array targets → no single field set\n check(`hook '${(hook.name as string) ?? '?'}'${hookObj ? ` (${hookObj})` : ''} condition`, hook.condition, hookObj, 'record');\n }\n\n return issues;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for ADR-0047 list-view navigation modes.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` and\n// reusable by AI authoring. It catches the \"wrong context\" authoring mistake\n// the type system alone cannot surface at author time on an object list view\n// (\"views\" mode — where the ViewTabBar owns the tab-bar role):\n// - `quickFilters` — never valid on an object list view;\n// - `userFilters` with `element: 'tabs'` (or carrying `tabs`) — the tab-bar\n// preset style is page-only; it would collide with the ViewTabBar.\n// A `dropdown` (value-chip) `userFilters` IS allowed on object views since the\n// ADR-0047 amendment (framework #2679 / objectui #2338) and is NOT flagged.\n//\n// Runs PRE-parse (on the normalizeStackInput output, before the\n// ObjectStackDefinition parse): the object-list schema (ObjectListViewSchema)\n// narrows `userFilters` to ObjectUserFiltersSchema (dropdown/toggle only), so a\n// post-parse stack has already had a `tabs` user-filter stripped and this rule\n// would never see it. The layering is deliberate — tsc rejects it at author\n// time, the schema strips it at runtime (no throw, back-compat), and this rule\n// reports it at `os validate` with a fix hint. See objectui #2338 and ADR-0047.\n\nexport type ListViewModeSeverity = 'error' | 'warning';\n\nexport interface ListViewModeFinding {\n severity: ListViewModeSeverity;\n rule: string;\n /** Human-readable location, e.g. `object \"task\" › listViews.my_pending`. */\n where: string;\n /** Config path, e.g. `objects[0].listViews.my_pending.userFilters`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const LIST_VIEW_FILTERS_IN_VIEWS_MODE = 'list-view-filters-in-views-mode';\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({\n name,\n ...(def as AnyRec),\n }));\n }\n return [];\n}\n\n/** Emit a finding for each wrong-context filter control on a single list-view def. */\nfunction scanView(\n view: unknown,\n where: string,\n path: string,\n out: ListViewModeFinding[],\n): void {\n if (!view || typeof view !== 'object') return;\n const rec = view as AnyRec;\n\n // `quickFilters` is never valid on an object list view.\n if (rec.quickFilters != null) {\n out.push({\n severity: 'error',\n rule: LIST_VIEW_FILTERS_IN_VIEWS_MODE,\n where,\n path: `${path}.quickFilters`,\n message:\n '`quickFilters` is a page filters-mode control and is ignored on an object ' +\n 'list view (\"views\" mode) — the ViewTabBar owns nav here.',\n hint:\n 'Move `quickFilters` to a page list (InterfaceListPage, \"filters\" mode), or ' +\n 'remove it. See ADR-0047.',\n });\n }\n\n // `userFilters` is allowed on object views ONLY as `dropdown` (value chips).\n // The `tabs` preset style — or any `userFilters` carrying `tabs` — collides\n // with the ViewTabBar and stays page-only.\n const uf = rec.userFilters;\n if (uf && typeof uf === 'object') {\n const ufRec = uf as AnyRec;\n if (ufRec.element === 'tabs' || ufRec.tabs != null) {\n out.push({\n severity: 'error',\n rule: LIST_VIEW_FILTERS_IN_VIEWS_MODE,\n where,\n path: `${path}.userFilters`,\n message:\n '`userFilters` with `element: \"tabs\"` is page-only and is ignored on an ' +\n 'object list view (\"views\" mode) — it would collide with the ViewTabBar.',\n hint:\n 'Use `listViews` for named presets on an object (each becomes a segmented ' +\n 'tab), switch to `element: \"dropdown\"` for value chips, or move the `tabs` ' +\n 'filter to a page list (InterfaceListPage, \"filters\" mode). See ADR-0047.',\n });\n }\n }\n}\n\n/** Scan a `listViews` record (name → list-view def). */\nfunction scanListViews(\n listViews: unknown,\n wherePrefix: string,\n pathPrefix: string,\n out: ListViewModeFinding[],\n): void {\n if (!listViews || typeof listViews !== 'object') return;\n for (const [name, view] of Object.entries(listViews as AnyRec)) {\n scanView(\n view,\n `${wherePrefix} › listViews.${name}`,\n `${pathPrefix}.listViews.${name}`,\n out,\n );\n }\n}\n\n/**\n * Flag ADR-0047 \"views\" mode violations on an object's built-in named views or a\n * `defineView` default `list` / named `listViews`: `quickFilters`, or a `tabs`\n * `userFilters`. A `dropdown` `userFilters` is allowed and not flagged. Returns\n * the list of findings (empty = clean). Caller decides how to surface / whether\n * to fail the build.\n *\n * Feed the PRE-parse stack (normalizeStackInput output) — see file header.\n */\nexport function validateListViewMode(stack: AnyRec): ListViewModeFinding[] {\n const out: ListViewModeFinding[] = [];\n\n // Object built-in named views (object.zod.ts `listViews`).\n asArray(stack.objects).forEach((obj, i) => {\n const label = typeof obj.name === 'string' ? `object \"${obj.name}\"` : `objects[${i}]`;\n scanListViews(obj.listViews, label, `objects[${i}]`, out);\n });\n\n // `defineView` aggregates (stack `views`: default `list` + named `listViews`).\n asArray(stack.views).forEach((view, i) => {\n const named =\n typeof view.objectName === 'string'\n ? view.objectName\n : typeof view.name === 'string'\n ? view.name\n : undefined;\n const label = named ? `view \"${named}\"` : `views[${i}]`;\n scanView(view.list, `${label} › list`, `views[${i}].list`, out);\n scanListViews(view.listViews, label, `views[${i}]`, out);\n });\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for auto-launched flow trigger wiring (2026-07-17\n// third-party eval: a record-change flow that silently never fires).\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` and\n// reusable by AI authoring. It catches the two authoring mistakes that produce\n// a flow which LOOKS armed but never launches — with zero runtime output:\n//\n// 1. `objectName` mismatch — the start node targets an object name that is\n// not defined in this stack. The runtime binds an ObjectQL hook filtered\n// to that exact name; if nobody writes it, the flow never fires. Names\n// match exactly (`eval_app_candidate`, not `candidate`). Objects owned by\n// other packages (`sys_*`, dependency packages) are legitimate targets,\n// so this is a warning with the cross-package caveat, not an error.\n//\n// 2. `status: 'draft'` on an auto-triggered flow — the schema default when\n// no status is authored (defineFlow parses at definition time, so by the\n// time this rule runs an unauthored status is indistinguishable from an\n// explicit 'draft'). Either way the intent is ambiguous: the engine still\n// binds and fires draft flows (only `obsolete`/`invalid` disable), which\n// surprises authors in both directions. Declare `'active'` to arm\n// deliberately or `'obsolete'` to disable. Only auto-triggered flows are\n// flagged (manual/screen flows have no arming semantics to be unclear\n// about).\n\nexport type FlowTriggerReadinessSeverity = 'error' | 'warning';\n\nexport interface FlowTriggerReadinessFinding {\n severity: FlowTriggerReadinessSeverity;\n rule: string;\n /** Human-readable location, e.g. `flow \"notify_on_done\" › start node`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[0].config.objectName`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries).\nexport const FLOW_TRIGGER_UNKNOWN_OBJECT = 'flow-trigger-unknown-object';\nexport const FLOW_DRAFT_STATUS_AMBIGUOUS = 'flow-draft-status-ambiguous';\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({\n name,\n ...(def as AnyRec),\n }));\n }\n return [];\n}\n\n/** The start node of a flow definition, if any. */\nfunction startNodeOf(flow: AnyRec): { node: AnyRec; index: number } | undefined {\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n const index = nodes.findIndex((n) => n?.type === 'start');\n return index >= 0 ? { node: nodes[index], index } : undefined;\n}\n\n/**\n * Validate auto-launched flow trigger wiring against the stack definition.\n * Pure and dependency-free; safe on pre- or post-parse stacks.\n */\nexport function validateFlowTriggerReadiness(stack: AnyRec): FlowTriggerReadinessFinding[] {\n const findings: FlowTriggerReadinessFinding[] = [];\n const flows = asArray(stack.flows);\n if (flows.length === 0) return findings;\n\n const objectNames = new Set(\n asArray(stack.objects)\n .map((o) => (typeof o.name === 'string' ? o.name : undefined))\n .filter((n): n is string => !!n),\n );\n\n flows.forEach((flow, flowIndex) => {\n const flowName = typeof flow.name === 'string' ? flow.name : `#${flowIndex}`;\n const start = startNodeOf(flow);\n const config = (start?.node.config ?? {}) as AnyRec;\n const triggerType = typeof config.triggerType === 'string' ? config.triggerType : undefined;\n const isRecordTriggered = !!triggerType && triggerType.startsWith('record-');\n const isTimeRelative = config.timeRelative != null && typeof config.timeRelative === 'object';\n const isAutoTriggered =\n isRecordTriggered || triggerType === 'api' || config.schedule != null ||\n isTimeRelative || flow.type === 'schedule' || flow.type === 'api';\n\n // 1. Record-triggered flow targeting an object this stack does not define.\n if (isRecordTriggered && start) {\n const objectName = typeof config.objectName === 'string' ? config.objectName : undefined;\n if (objectName && !objectNames.has(objectName) && !objectName.startsWith('sys_')) {\n findings.push({\n severity: 'warning',\n rule: FLOW_TRIGGER_UNKNOWN_OBJECT,\n where: `flow \"${flowName}\" › start node`,\n path: `flows[${flowIndex}].nodes[${start.index}].config.objectName`,\n message:\n `targets object '${objectName}', which this stack does not define — if the name is wrong, ` +\n `the flow will never fire (and the runtime stays silent about it).`,\n hint:\n `Object names match exactly. Check config.objectName against the object's registered name ` +\n `(e.g. 'app_candidate', not 'candidate'). If the object comes from another installed package, ` +\n `this warning can be ignored.`,\n });\n }\n }\n\n // 1b. Time-relative flow sweeping an object this stack does not define. Like\n // the record-change case, a wrong object name makes the sweep match\n // nothing forever with no runtime output.\n if (isTimeRelative && start) {\n const tr = config.timeRelative as AnyRec;\n const objectName = typeof tr.object === 'string' ? tr.object : undefined;\n if (objectName && !objectNames.has(objectName) && !objectName.startsWith('sys_')) {\n findings.push({\n severity: 'warning',\n rule: FLOW_TRIGGER_UNKNOWN_OBJECT,\n where: `flow \"${flowName}\" › start node`,\n path: `flows[${flowIndex}].nodes[${start.index}].config.timeRelative.object`,\n message:\n `sweeps object '${objectName}', which this stack does not define — if the name is wrong, ` +\n `the sweep will match nothing (and the runtime stays quiet about it).`,\n hint:\n `Object names match exactly. Check config.timeRelative.object against the object's registered name. ` +\n `If the object comes from another installed package, this warning can be ignored.`,\n });\n }\n }\n\n // 2. Auto-triggered flow whose status is 'draft' — authored or defaulted\n // (defineFlow parses at definition time, so the two are the same here).\n if (isAutoTriggered && (flow.status == null || flow.status === 'draft')) {\n findings.push({\n severity: 'warning',\n rule: FLOW_DRAFT_STATUS_AMBIGUOUS,\n where: `flow \"${flowName}\"`,\n path: `flows[${flowIndex}].status`,\n message:\n `has status 'draft' (the default when none is authored). Draft flows DO still fire their ` +\n `triggers (only 'obsolete'/'invalid' disable), so the intent is ambiguous.`,\n hint: `Declare status: 'active' to arm it deliberately, or status: 'obsolete' to disable it.`,\n });\n }\n });\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for the `defineView` container shape.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate`. It\n// catches the \"flat view object\" authoring mistake the schema alone cannot\n// surface: `ViewSchema` is a container (`{ list, form, listViews, formViews }`)\n// whose slots are all optional, and Zod strips unknown keys — so a flat list\n// view (`{ name: 'all_tasks', label, type: 'grid', columns: [...] }`) parses\n// to an EMPTY container. The stack validates, the loader finds nothing to\n// expand, and the Console silently renders no view (no switcher entry). The\n// third-party 15.1 evaluation hit exactly this via the old docs.\n//\n// Runs PRE-parse (on the normalizeStackInput output, before the\n// ObjectStackDefinition parse): post-parse the flat keys are already stripped\n// and the mistake is indistinguishable from an intentionally empty container.\n//\n// Independent ViewItems (`viewKind` + `config`) are legal `views: []` entries\n// (the loader registers them as-is) and are not flagged.\n\nexport type ViewContainerSeverity = 'error' | 'warning';\n\nexport interface ViewContainerFinding {\n severity: ViewContainerSeverity;\n rule: string;\n /** Human-readable location, e.g. `views[0] (\"all_tasks\")`. */\n where: string;\n /** Config path, e.g. `views[0]`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const VIEW_CONTAINER_SHAPE = 'view-container-shape';\n\ntype AnyRec = Record<string, unknown>;\n\nconst CONTAINER_SLOT_KEYS = ['list', 'form', 'listViews', 'formViews'] as const;\n\n/** Coerce an array-or-name-keyed-map collection to indexed entries. */\nfunction asEntries(v: unknown): Array<{ key: string; value: unknown }> {\n if (Array.isArray(v)) return v.map((value, i) => ({ key: `[${i}]`, value }));\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, value]) => ({ key: `.${name}`, value }));\n }\n return [];\n}\n\n/** Number of views a parsed-or-raw container actually carries. */\nfunction containerViewCount(rec: AnyRec): number {\n const named = (slot: unknown): number =>\n slot && typeof slot === 'object' && !Array.isArray(slot) ? Object.keys(slot as AnyRec).length : 0;\n return (rec.list ? 1 : 0) + (rec.form ? 1 : 0) + named(rec.listViews) + named(rec.formViews);\n}\n\n/**\n * Validate that every stack-level `views` entry is a real view container (or\n * an independent ViewItem). Flat list-view objects and view-less containers\n * are reported as errors with a wrap-it fix hint.\n */\nexport function validateViewContainers(stack: Record<string, unknown>): ViewContainerFinding[] {\n const out: ViewContainerFinding[] = [];\n if (!stack || typeof stack !== 'object') return out;\n\n for (const { key, value } of asEntries((stack as AnyRec).views)) {\n // Non-object entries are the schema step's problem, not this rule's.\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const rec = value as AnyRec;\n\n // Independent ViewItem (`viewKind` discriminator) — registered as-is.\n if (rec.viewKind != null) continue;\n\n if (containerViewCount(rec) > 0) continue;\n\n const label = typeof rec.name === 'string' ? ` (\"${rec.name}\")` : '';\n const hasContainerSlot = CONTAINER_SLOT_KEYS.some((k) => k in rec);\n // Flat list-view fingerprint: view-ish keys at the top level where the\n // container slots should be.\n const looksFlat = !hasContainerSlot\n && ['type', 'columns', 'data', 'filter', 'sort'].some((k) => k in rec);\n\n out.push({\n severity: 'error',\n rule: VIEW_CONTAINER_SHAPE,\n where: `views${key}${label}`,\n path: `views${key}`,\n message: looksFlat\n ? 'Flat list-view object is not a view container: `ViewSchema` strips its keys, '\n + 'so it parses to an EMPTY container — zero views register and the Console '\n + 'renders no view for it.'\n : 'View container defines no views — all of `list` / `form` / `listViews` / '\n + '`formViews` are absent or empty, so nothing registers.',\n hint: 'Wrap every view in a defineView container: defineView({ list: { type, data, '\n + 'columns, ... }, listViews: { ... }, formViews: { ... } }). See '\n + 'examples/app-showcase/src/ui/views/task.view.ts.',\n });\n }\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time diagnostics for the SDUI scoped-styling model (ADR-0065).\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019): the same bar holds for\n// hand-authored and AI-generated pages, run from `os validate`/`compile` and\n// reusable by AI authoring. It catches the deterministic ways a `responsiveStyles`\n// block silently fails or drifts — the class of mistake an AI author is most\n// likely to make — *before* render, with actionable hints it can self-correct on.\n//\n// What it does NOT catch: whether the result looks good. Visual/semantic quality\n// (contrast, balance, \"is it ugly\") is only catchable by rendering + a VLM gate,\n// which is a separate, render-time concern (ADR-0065 §Decision-5).\n\nexport type StyleSeverity = 'error' | 'warning';\n\nexport interface StyleFinding {\n severity: StyleSeverity;\n rule: string;\n /** Human-readable location, e.g. `page \"pricing\" › node \"plan_solo\"`. */\n where: string;\n /** Config path, e.g. `pages[0].regions[0].components[1]`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries).\nexport const STYLE_NODE_MISSING_ID = 'style-node-missing-id';\nexport const STYLE_CLASSNAME_TAILWIND = 'style-classname-tailwind';\nexport const STYLE_RESPONSIVE_NO_BASE = 'style-responsive-no-base';\nexport const STYLE_UNKNOWN_CSS_PROPERTY = 'style-unknown-css-property';\nexport const STYLE_UNKNOWN_TOKEN = 'style-unknown-token';\n\ntype AnyRec = Record<string, unknown>;\n\nconst BREAKPOINTS = ['large', 'medium', 'small', 'xsmall'] as const;\n\n/** SDUI design-token palette (ADR-0065) + base theme tokens, referenced as\n * `var(--name)`. Authors should resolve values against these. Kept in sync with\n * `apps/console/src/index.css` / `@object-ui/components` `:root`. */\nconst KNOWN_TOKENS = new Set<string>([\n // SDUI tokens\n 'space-1', 'space-2', 'space-3', 'space-4', 'space-5', 'space-6', 'space-8', 'space-10', 'space-12',\n 'radius', 'radius-sm', 'radius-md', 'radius-lg', 'radius-xl',\n 'shadow-sm', 'shadow-md', 'shadow-lg',\n 'surface', 'surface-sunken', 'text-strong', 'text-muted', 'brand', 'brand-foreground', 'hairline',\n // Base theme tokens (shadcn) — usually wrapped as hsl(var(--x)).\n 'background', 'foreground', 'card', 'card-foreground', 'popover', 'popover-foreground',\n 'primary', 'primary-foreground', 'secondary', 'secondary-foreground',\n 'muted', 'muted-foreground', 'accent', 'accent-foreground',\n 'destructive', 'destructive-foreground', 'border', 'input', 'ring',\n 'success', 'success-foreground', 'warning', 'warning-foreground',\n 'chart-1', 'chart-2', 'chart-3', 'chart-4', 'chart-5',\n]);\n\n/** Common CSS properties (camelCase) an SDUI block realistically sets. Generous\n * on purpose: an unknown property is only a *warning* (typo catcher), never a\n * blocker. Custom properties (`--x`) are always allowed. */\nconst KNOWN_CSS_PROPERTIES = new Set<string>([\n 'display', 'position', 'top', 'right', 'bottom', 'left', 'inset', 'zIndex', 'overflow', 'overflowX', 'overflowY', 'visibility', 'boxSizing', 'float', 'clear',\n 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'aspectRatio',\n 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginInline', 'marginBlock',\n 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingInline', 'paddingBlock',\n 'flex', 'flexDirection', 'flexWrap', 'flexGrow', 'flexShrink', 'flexBasis', 'alignItems', 'alignContent', 'alignSelf', 'justifyContent', 'justifyItems', 'justifySelf', 'gap', 'rowGap', 'columnGap', 'order', 'placeItems', 'placeContent',\n 'grid', 'gridTemplate', 'gridTemplateColumns', 'gridTemplateRows', 'gridTemplateAreas', 'gridColumn', 'gridRow', 'gridArea', 'gridAutoFlow', 'gridAutoColumns', 'gridAutoRows',\n 'color', 'backgroundColor', 'background', 'backgroundImage', 'backgroundSize', 'backgroundPosition', 'backgroundRepeat', 'backgroundClip', 'opacity', 'mixBlendMode',\n 'fontSize', 'fontWeight', 'fontFamily', 'fontStyle', 'lineHeight', 'letterSpacing', 'textAlign', 'textTransform', 'textDecoration', 'textOverflow', 'whiteSpace', 'wordBreak', 'overflowWrap', 'fontVariantNumeric', 'verticalAlign', 'textShadow',\n 'border', 'borderTop', 'borderRight', 'borderBottom', 'borderLeft', 'borderColor', 'borderWidth', 'borderStyle', 'borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'outline', 'outlineOffset',\n 'boxShadow', 'transform', 'transformOrigin', 'transition', 'transitionProperty', 'transitionDuration', 'transitionTimingFunction', 'transitionDelay', 'animation', 'filter', 'backdropFilter', 'willChange',\n 'cursor', 'pointerEvents', 'userSelect', 'objectFit', 'objectPosition', 'content',\n]);\n\nconst VAR_RE = /var\\(\\s*--([a-zA-Z0-9-]+)\\s*[,)]/g;\n\n// High-precision Tailwind-utility detection. A `className` in page metadata is\n// \"Tailwind-looking\" if any token is a responsive/state variant, an arbitrary\n// `[…]` value, a known utility stem followed by a Tailwind *value* (number /\n// fraction / size keyword), or a bare layout utility. Tuned to NOT trip on\n// ordinary custom class names (e.g. `my-custom-scope`, `os-s-plan_solo`).\nconst TW_VARIANT = /^(sm|md|lg|xl|2xl|hover|focus|active|disabled|dark|group-hover|peer-[a-z]+|first|last|odd|even):/;\nconst TW_STEM_VALUE = /^-?(p|m|px|py|pt|pb|pl|pr|mx|my|mt|mb|ml|mr|gap|gap-x|gap-y|space-x|space-y|w|h|min-w|max-w|min-h|max-h|size|text|leading|tracking|bg|border|rounded|shadow|ring|opacity|inset|top|bottom|left|right|z|order|col|row|grid-cols|grid-rows|basis)-(\\d+(\\.\\d+)?|\\d+\\/\\d+|px|full|auto|none|screen|min|max|fit|xs|sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl)$/;\nconst TW_BARE = /^(flex|grid|block|inline|inline-block|inline-flex|hidden|contents|table|flow-root|grow|shrink|truncate|italic|underline|uppercase|lowercase|capitalize|antialiased|absolute|relative|fixed|sticky|static|isolate|flex-col|flex-row|flex-wrap|flex-nowrap|items-center|items-start|items-end|items-stretch|justify-center|justify-between|justify-around|justify-start|justify-end|text-center|text-left|text-right|font-bold|font-semibold|font-medium|font-normal|tabular-nums)$/;\n\nfunction looksLikeTailwind(className: string): boolean {\n return className.split(/\\s+/).some((tok) => {\n if (!tok) return false;\n if (TW_VARIANT.test(tok)) return true;\n if (/\\[[^\\]]+\\]/.test(tok)) return true; // arbitrary value, e.g. p-[13px]\n if (TW_STEM_VALUE.test(tok)) return true;\n if (TW_BARE.test(tok)) return true;\n return false;\n });\n}\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** Child nodes can hang off `children`, `properties.children`, `body`, or\n * `properties.body` depending on block type — collect them all. */\nfunction childrenOf(node: AnyRec): AnyRec[] {\n const props = (node.properties as AnyRec) ?? {};\n const out: AnyRec[] = [];\n for (const c of [node.children, props.children, node.body, props.body]) {\n if (Array.isArray(c)) out.push(...(c.filter((x) => x && typeof x === 'object') as AnyRec[]));\n }\n return out;\n}\n\nfunction checkNode(node: AnyRec, pageName: string, path: string, findings: StyleFinding[]): void {\n const id = typeof node.id === 'string' ? node.id : undefined;\n const type = typeof node.type === 'string' ? node.type : 'node';\n const where = `page \"${pageName}\" › ${id ? `node \"${id}\"` : `<${type}>`}`;\n const rs = node.responsiveStyles as AnyRec | undefined;\n const hasRs = !!rs && typeof rs === 'object' && BREAKPOINTS.some((b) => rs[b]);\n\n // (1) responsiveStyles needs an id to scope to — else the CSS is dropped.\n if (hasRs && !id) {\n findings.push({\n severity: 'error', rule: STYLE_NODE_MISSING_ID, where, path,\n message: `Node has responsiveStyles but no \\`id\\`; scoped CSS cannot be generated and the styles are silently dropped.`,\n hint: `Add a stable \\`id\\` to this node.`,\n });\n }\n\n // (2) responsive breakpoint without a `large` base → unstyled at desktop.\n if (hasRs && !rs!.large && BREAKPOINTS.slice(1).some((b) => rs![b])) {\n findings.push({\n severity: 'warning', rule: STYLE_RESPONSIVE_NO_BASE, where, path,\n message: `responsiveStyles sets a smaller breakpoint but no \\`large\\` base; the node is unstyled at desktop width.`,\n hint: `Put the unconditional/base styles under \\`responsiveStyles.large\\` (desktop-first).`,\n });\n }\n\n // (3) className that looks like Tailwind → won't render from metadata.\n if (typeof node.className === 'string' && node.className.trim() && looksLikeTailwind(node.className)) {\n findings.push({\n severity: 'warning', rule: STYLE_CLASSNAME_TAILWIND, where, path,\n message: `\\`className\\` contains Tailwind-looking utilities (\"${node.className.trim().slice(0, 60)}\"); these are not compiled from metadata and will silently do nothing.`,\n hint: `Style this node with \\`responsiveStyles\\` + design tokens instead of \\`className\\` (ADR-0065).`,\n });\n }\n\n // (4)+(5) unknown CSS property / unknown token inside each breakpoint map.\n if (rs && typeof rs === 'object') {\n for (const bp of BREAKPOINTS) {\n const map = rs[bp] as AnyRec | undefined;\n if (!map || typeof map !== 'object') continue;\n for (const [prop, value] of Object.entries(map)) {\n if (!prop.startsWith('--') && !KNOWN_CSS_PROPERTIES.has(prop)) {\n findings.push({\n severity: 'warning', rule: STYLE_UNKNOWN_CSS_PROPERTY, where, path: `${path}.responsiveStyles.${bp}`,\n message: `Unknown CSS property \"${prop}\" (typo?); if unintended it will not apply.`,\n hint: `Use a camelCase CSS property name (e.g. \\`flexDirection\\`, \\`backgroundColor\\`).`,\n });\n }\n if (typeof value === 'string') {\n let m: RegExpExecArray | null;\n VAR_RE.lastIndex = 0;\n while ((m = VAR_RE.exec(value))) {\n const token = m[1];\n if (!KNOWN_TOKENS.has(token) && !token.startsWith('tw-')) {\n findings.push({\n severity: 'warning', rule: STYLE_UNKNOWN_TOKEN, where, path: `${path}.responsiveStyles.${bp}.${prop}`,\n message: `References unknown design token \\`var(--${token})\\` (typo?); it will not resolve.`,\n hint: `Use a token from the ADR-0065 palette (e.g. \\`var(--space-6)\\`, \\`var(--surface)\\`, \\`hsl(var(--primary))\\`).`,\n });\n }\n }\n }\n }\n }\n }\n\n // Recurse.\n const kids = childrenOf(node);\n for (let i = 0; i < kids.length; i++) {\n checkNode(kids[i], pageName, `${path}.children[${i}]`, findings);\n }\n}\n\n/**\n * Validate every page's component tree for SDUI styling correctness (ADR-0065).\n * Returns findings (empty = clean). `error` findings describe styles that are\n * silently dropped and should fail validate/build; `warning` findings are\n * advisory (typos, drift, footguns).\n */\nexport function validateResponsiveStyles(stack: AnyRec): StyleFinding[] {\n const findings: StyleFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n const pageName = typeof page.name === 'string' ? page.name : `pages[${p}]`;\n const regions = asArray(page.regions);\n for (let r = 0; r < regions.length; r++) {\n const components = asArray(regions[r].components);\n for (let c = 0; c < components.length; c++) {\n checkNode(components[c], pageName, `pages[${p}].regions[${r}].components[${c}]`, findings);\n }\n }\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time diagnostics for AI-authored HTML-source pages (ADR-0080).\n//\n// Applies to `kind:'html'` (and its deprecated alias `kind:'jsx'`) — the tier\n// whose `source` is constrained JSX/HTML parsed (never executed) to the tree.\n// `kind:'react'` (ADR-0081) is intentionally NOT linted here: its source is\n// real JavaScript, not constrained JSX, so the constrained parser would\n// false-error on hooks / expressions.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` / `os\n// build`. An html page's `source` is a constrained JSX/Tailwind string\n// compiled (parsed, never executed) to the SDUI tree at save time. This gate\n// parses it at author time so malformed source fails loudly (ADR-0078) instead\n// of being stored and breaking only at render.\n//\n// Scope: parse-level — syntax, tag matching, and forbidden constructs (event\n// handlers, dangerouslySetInnerHTML). Full component/prop whitelist validation\n// needs the registry manifest (a cross-repo artifact); when that is wired,\n// thread it through `compile()` here. Until then this catches the structural\n// class of error an AI author is most likely to emit.\n\nimport { parseJsx, compile, type Manifest } from '@objectstack/sdui-parser';\n\nexport type JsxPageSeverity = 'error' | 'warning';\n\nexport interface JsxPageFinding {\n severity: JsxPageSeverity;\n rule: string;\n /** Human-readable location, e.g. `page \"command_center\" › <flex>`. */\n where: string;\n /** Config path, e.g. `pages[3].source`. */\n path: string;\n message: string;\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\nexport function validateJsxPages(stack: AnyRec, opts: { manifest?: Manifest } = {}): JsxPageFinding[] {\n const findings: JsxPageFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n // html tier (+ deprecated 'jsx' alias). react pages are not constrained JSX.\n if (!page || (page.kind !== 'html' && page.kind !== 'jsx')) continue;\n const name = String(page.name ?? `#${p}`);\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') {\n // (PageSchema's superRefine also covers this; keep it for the build path.)\n findings.push({\n severity: 'error',\n rule: 'jsx-page-empty-source',\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: `kind:'${page.kind}' page has no \\`source\\`.`,\n hint: 'Author the page as a constrained JSX/Tailwind string in `source`.',\n });\n continue;\n }\n // With a component manifest, do full validation (unknown component, missing/\n // wrong prop, bad enum, bindings); without it, parse-level (syntax/structure).\n const { diagnostics } = opts.manifest ? compile(source, opts.manifest) : parseJsx(source);\n for (const d of diagnostics) {\n findings.push({\n severity: d.severity,\n rule: `jsx-${d.code}`,\n where: d.tag ? `page \"${name}\" › <${d.tag}>` : `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: d.message,\n hint: 'The source is parsed (never executed) and compiled to the SDUI tree at save time — fix the JSX.',\n });\n }\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time syntax gate for `kind:'react'` pages (ADR-0081).\n//\n// A react page's `source` is REAL JavaScript/JSX executed at render by the\n// runtime — so the constrained JSX parser (validate-jsx-pages) cannot check it.\n// We instead transpile it with Sucrase (the same transpiler the runtime uses),\n// transpile-ONLY — never executed — to surface syntax errors at `os build`\n// instead of at render (ADR-0078: fail loudly at author time). It does NOT\n// validate runtime behaviour (a transpiling page can still throw at render);\n// the render-time error boundary owns that.\n\nimport { createRequire } from 'node:module';\nimport type { transform as sucraseTransform } from 'sucrase';\n\n// Sucrase must NOT be imported at module top level: it is ~1.5 MB of CJS\n// (~16 ms cold require), and @objectstack/lint sits on the kernel boot path —\n// while this gate only runs when a `kind:'react'` page is actually validated\n// (rare, trusted tier). Same boot-path contract as the TypeScript compiler in\n// validate-react-page-props.ts: loaded lazily, on first use, staying a regular\n// dependency in package.json. Guarded by lazy-deps.test.ts.\n//\n// `node:module` is a Node builtin, untouched by esbuild/tsup, so the static\n// `createRequire` import survives bundling; the `createRequire(...)` call is\n// deferred because `import.meta.url` is rewritten to an empty stub in the CJS\n// build (same pattern as driver-sqlite-wasm's knex-wasm-dialect).\nlet cachedTransform: typeof sucraseTransform | null = null;\nfunction loadSucraseTransform(): typeof sucraseTransform {\n if (cachedTransform) return cachedTransform;\n const anchor =\n typeof import.meta !== 'undefined' && import.meta.url\n ? import.meta.url\n : typeof __filename !== 'undefined'\n ? __filename\n : process.cwd() + '/';\n try {\n cachedTransform = (createRequire(anchor)('sucrase') as { transform: typeof sucraseTransform }).transform;\n } catch (err) {\n throw new Error(\n `@objectstack/lint: validating a kind:'react' page requires the \"sucrase\" package, which could not be loaded ` +\n `(${err instanceof Error ? err.message : String(err)}). It is a declared dependency of @objectstack/lint — ` +\n `if this deployment prunes packages, keep \"sucrase\" in the image; it is only loaded when a react-source page is validated.`,\n );\n }\n return cachedTransform;\n}\n\nexport type ReactPageSeverity = 'error' | 'warning';\n\nexport interface ReactPageFinding {\n severity: ReactPageSeverity;\n rule: string;\n where: string;\n path: string;\n message: string;\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\nexport function validateReactPages(stack: AnyRec): ReactPageFinding[] {\n const findings: ReactPageFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n if (!page || page.kind !== 'react') continue;\n const name = String(page.name ?? `#${p}`);\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') {\n findings.push({\n severity: 'error',\n rule: 'react-page-empty-source',\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: \"kind:'react' page has no `source`.\",\n hint: 'Author the page as a real React component string in `source`.',\n });\n continue;\n }\n // Outside the try below on purpose: a missing transpiler must surface as\n // an error, not be swallowed as a syntax finding.\n const transform = loadSucraseTransform();\n try {\n // transpile-only (no eval) — catches syntax errors, unterminated JSX, etc.\n transform(source, { transforms: ['jsx', 'typescript'], production: true });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n findings.push({\n severity: 'error',\n rule: 'react-page-syntax',\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: `kind:'react' source has a syntax error: ${message.split('\\n')[0]}`,\n hint: 'The source is transpiled (never executed) at build to catch syntax errors early — fix the JS/JSX.',\n });\n }\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time prop check for `kind:'react'` pages (ADR-0081 Phase 2). The syntax\n// gate (validate-react-pages) confirms the source parses; this confirms the\n// AUTHOR USED THE COMPONENT CONTRACT correctly — it parses the real JSX with the\n// TypeScript compiler, finds usages of the injected blocks (<ObjectForm>,\n// <ListView>, …), and checks each against the react-tier contract\n// (REACT_BLOCKS in @objectstack/spec):\n//\n// - missing a required binding prop (e.g. <ObjectForm> with no objectName)\n// → error. (Only the React-enforceable overlay props are required-checked;\n// a spread `{...props}` escapes the check since props may come from it.)\n// - a prop that is a near-miss (edit distance ≤ 2) of a known prop\n// (e.g. `onSucces` → `onSuccess`) → warning. We do NOT flag arbitrary\n// unknown props (the contract's data props are a curated subset) — only the\n// likely typos, to keep false positives near zero.\n\nimport { createRequire } from 'node:module';\nimport type ts from 'typescript';\nimport { REACT_BLOCKS } from '@objectstack/spec/ui';\n\n// The TypeScript compiler must NOT be imported at module top level: it is\n// ~9 MB of CJS (~70 ms+ to parse, worse on container cold starts), and\n// @objectstack/lint sits on the kernel boot path — while this gate only runs\n// when a `kind:'react'` page is actually validated (rare, trusted tier). An\n// eager import also hard-crashes boot in deployments that prune the package\n// from the image (cloud's Docker pruner did exactly that). So the compiler is\n// loaded lazily, on first use, and stays a regular dependency in package.json.\n// Guarded by lazy-deps.test.ts.\n//\n// `node:module` is a Node builtin, untouched by esbuild/tsup, so the static\n// `createRequire` import survives bundling; the `createRequire(...)` call is\n// deferred because `import.meta.url` is rewritten to an empty stub in the CJS\n// build (same pattern as driver-sqlite-wasm's knex-wasm-dialect).\nlet cachedTs: typeof ts | null = null;\nfunction loadTypeScript(): typeof ts {\n if (cachedTs) return cachedTs;\n const anchor =\n typeof import.meta !== 'undefined' && import.meta.url\n ? import.meta.url\n : typeof __filename !== 'undefined'\n ? __filename\n : process.cwd() + '/';\n try {\n cachedTs = createRequire(anchor)('typescript') as typeof ts;\n } catch (err) {\n throw new Error(\n `@objectstack/lint: validating a kind:'react' page requires the \"typescript\" package, which could not be loaded ` +\n `(${err instanceof Error ? err.message : String(err)}). It is a declared dependency of @objectstack/lint — ` +\n `if this deployment prunes packages, keep \"typescript\" in the image; it is only loaded when a react-source page is validated.`,\n );\n }\n return cachedTs;\n}\n\nexport type ReactPropSeverity = 'error' | 'warning';\n\nexport interface ReactPropFinding {\n severity: ReactPropSeverity;\n rule: string;\n where: string;\n path: string;\n message: string;\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\ninterface BlockSpec {\n requiredBindings: string[];\n knownProps: Set<string>;\n}\nconst BLOCKS: Map<string, BlockSpec> = new Map(\n (REACT_BLOCKS as Array<{ tag: string; interactions: Array<{ name: string; required?: boolean }> }>).map((b) => [\n b.tag,\n {\n requiredBindings: b.interactions.filter((i) => i.required).map((i) => i.name),\n knownProps: new Set(b.interactions.map((i) => i.name)),\n },\n ]),\n);\n\nfunction editDistance(a: string, b: string, cap = 2): number {\n if (Math.abs(a.length - b.length) > cap) return cap + 1;\n const dp = Array.from({ length: a.length + 1 }, (_, i) => i);\n for (let j = 1; j <= b.length; j++) {\n let prev = dp[0];\n dp[0] = j;\n for (let i = 1; i <= a.length; i++) {\n const tmp = dp[i];\n dp[i] = Math.min(dp[i] + 1, dp[i - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));\n prev = tmp;\n }\n }\n return dp[a.length];\n}\n\nfunction nearestKnown(prop: string, known: Set<string>): string | null {\n if (known.has(prop)) return null;\n let best: string | null = null;\n let bestD = 3;\n for (const k of known) {\n const d = editDistance(prop, k);\n if (d < bestD) { bestD = d; best = k; }\n }\n return bestD <= 2 ? best : null;\n}\n\nexport function validateReactPageProps(stack: AnyRec): ReactPropFinding[] {\n const findings: ReactPropFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n if (!page || page.kind !== 'react') continue;\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') continue;\n const name = String(page.name ?? `#${p}`);\n\n // Outside the try below on purpose: a missing compiler must surface as an\n // error, not be swallowed as \"unparseable source\".\n const tsc = loadTypeScript();\n\n let sf: ts.SourceFile;\n try {\n sf = tsc.createSourceFile('page.tsx', source, tsc.ScriptTarget.Latest, true, tsc.ScriptKind.TSX);\n } catch {\n continue; // the syntax gate reports unparseable sources\n }\n\n const visit = (node: ts.Node): void => {\n if (tsc.isJsxOpeningElement(node) || tsc.isJsxSelfClosingElement(node)) {\n const tag = node.tagName.getText(sf);\n const block = BLOCKS.get(tag);\n if (block) {\n let hasSpread = false;\n const used = new Set<string>();\n for (const a of node.attributes.properties) {\n if (tsc.isJsxSpreadAttribute(a)) { hasSpread = true; continue; }\n if (tsc.isJsxAttribute(a)) used.add(a.name.getText(sf));\n }\n const where = `page \"${name}\" › <${tag}>`;\n const path = `pages[${p}].source`;\n if (!hasSpread) {\n for (const req of block.requiredBindings) {\n if (!used.has(req)) {\n findings.push({\n severity: 'error',\n rule: 'react-prop-missing-required',\n where, path,\n message: `<${tag}> is missing the required prop \"${req}\".`,\n hint: `Pass ${req}={…}. See the react-tier component contract.`,\n });\n }\n }\n }\n for (const u of used) {\n const near = nearestKnown(u, block.knownProps);\n if (near) {\n findings.push({\n severity: 'warning',\n rule: 'react-prop-typo',\n where, path,\n message: `<${tag}> has prop \"${u}\" — did you mean \"${near}\"?`,\n hint: 'Likely a typo of a contract prop. Fix it or remove it.',\n });\n }\n }\n }\n }\n tsc.forEachChild(node, visit);\n };\n visit(sf);\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for SDUI source-tier page styling (ADR-0065 / ADR-0080 /\n// ADR-0081). A `kind:'html'` or `kind:'react'` page's `source` is RUNTIME\n// metadata — the console's build-time Tailwind only scans the renderer's own\n// source, never an authored page string. So a Tailwind `className` in page\n// source silently produces NO CSS (the exact ADR-0065 failure: styling that\n// \"works only by coincidence\" when the class happens to be one objectui already\n// ships). This rule flags authored `className` attributes in source-tier pages\n// before render, with the actionable fix.\n//\n// It is the styling counterpart to the react-prop gate: a pure\n// `(stack) => Finding[]` rule (ADR-0019), run from `os validate`/`compile` and\n// reusable by AI authoring so the agent self-corrects.\n\nexport type SourceStyleSeverity = 'error' | 'warning';\n\nexport interface SourceStyleFinding {\n severity: SourceStyleSeverity;\n rule: string;\n where: string;\n path: string;\n message: string;\n hint: string;\n}\n\nexport const PAGE_SOURCE_CLASSNAME = 'page-source-className-tailwind';\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\n// `className=` as a JSX attribute: name, optional ws, `=`, then `\"`/`'`/`{`.\nconst CLASSNAME_ATTR = /\\bclassName\\s*=\\s*[\"'{]/g;\n\nexport function validatePageSourceStyling(stack: AnyRec): SourceStyleFinding[] {\n const findings: SourceStyleFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n if (!page) continue;\n const kind = page.kind;\n if (kind !== 'html' && kind !== 'react' && kind !== 'jsx') continue;\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') continue;\n const name = String(page.name ?? `#${p}`);\n\n CLASSNAME_ATTR.lastIndex = 0;\n let count = 0;\n while (CLASSNAME_ATTR.exec(source) !== null) count++;\n if (count === 0) continue;\n\n findings.push({\n severity: 'warning',\n rule: PAGE_SOURCE_CLASSNAME,\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: `${count} \\`className\\` attribute${count > 1 ? 's' : ''} in ${String(kind)}-source page — Tailwind utilities in page source silently produce no CSS (the build never scans authored metadata; ADR-0065).`,\n hint:\n kind === 'react'\n ? \"Style with inline style={{}} using hsl(var(--token)) theme colors (e.g. color:'hsl(var(--foreground))', background:'hsl(var(--card))'); render drawer/modal via <ObjectForm formType=\\\"drawer\\\"|\\\"modal\\\"> instead of hand-rolled overlays.\"\n : \"Lay out with the components' structured props (<flex direction gap>, <grid columns>) and add CSS via a JSON style object style={{\\\"color\\\":\\\"hsl(var(--foreground))\\\"}}; do not use Tailwind className.\",\n });\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { objectTitleCompleteness } from '@objectstack/spec/data';\nimport type { DisplayNameObjectMeta } from '@objectstack/spec/data';\n\n/**\n * Build-time record-title diagnostics (ADR-0079).\n *\n * A record's human title is a structural invariant: every object resolves a\n * primary title from a real STORED field via `nameField` (the canonical\n * pointer; `displayNameField` is the deprecated alias) or a deterministic\n * derivation. Two authoring smells are flagged here so `os build`/`os lint`,\n * the MCP authoring surface, and hand-authoring all get the coverage cloud\n * graph-lint already has (the ADR-0078 \"not cloud-only\" principle):\n *\n * - `title-format-retired` — the object declares a `titleFormat`. That field\n * is a RENDER-ONLY template the server can neither return nor query; ADR-0079\n * retires it in favour of `nameField`. The schema still parses it (existing\n * metadata keeps loading), so this is advisory, not an error.\n * - `title-unresolvable` — `objectTitleCompleteness` reports `status: 'none'`:\n * no `nameField`/`displayNameField` pointer and no title-eligible field to\n * derive one from. Records will have no meaningful title (the runtime falls\n * back to the auto-provisioned primary / `Record #<id>` floor), so this is a\n * warning, not an error — nothing is fully broken.\n *\n * Both are warnings: the auto-provision transform and the id floor mean a\n * green build never ships a fully title-less object. Reuses the shared spec\n * predicate (`@objectstack/spec/data` → display-name) so cloud and framework\n * classify titles identically.\n */\n\nexport const TITLE_FORMAT_RETIRED = 'title-format-retired';\nexport const TITLE_UNRESOLVABLE = 'title-unresolvable';\n\nexport type RecordTitleSeverity = 'error' | 'warning';\n\nexport interface RecordTitleFinding {\n /** Always `warning` today — both rules are advisory (see module note). */\n severity: RecordTitleSeverity;\n /** Diagnostic rule id (registry entry), e.g. `title-format-retired`. */\n rule: string;\n /** Human-readable location, e.g. `object \"invoice\"`. */\n where: string;\n /** Config path, e.g. `objects[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/**\n * Validate every object's record-title declaration. Returns the list of\n * findings (empty = clean). Both rules are advisory (`warning`): the caller\n * must never fail the build on them alone — auto-provision + the `Record #<id>`\n * floor guarantee a resolvable title at runtime.\n */\nexport function validateRecordTitle(stack: AnyRec): RecordTitleFinding[] {\n const findings: RecordTitleFinding[] = [];\n\n const objects = asArray(stack.objects);\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const where = `object \"${objName}\"`;\n const path = `objects[${i}]`;\n\n // ── (a) titleFormat is retired (ADR-0079) ──\n // Render-only template the server cannot return or query. Still parsed by\n // the schema for back-compat, so advisory.\n if (obj.titleFormat !== undefined && obj.titleFormat !== null && obj.titleFormat !== '') {\n findings.push({\n severity: 'warning',\n rule: TITLE_FORMAT_RETIRED,\n where,\n path,\n message:\n `${objName}: titleFormat is retired (ADR-0079) — migrate to nameField ` +\n `(single field) or a formula field designated nameField`,\n hint:\n `titleFormat is a render-only template the server cannot return or ` +\n `query, and an explicit nameField now takes precedence. For a ` +\n `single-field title set nameField: '<field>'. For a composite title, ` +\n `add a formula field (returnType: 'text') and designate it via ` +\n `nameField.`,\n });\n }\n\n // ── (b) no resolvable title (status: 'none') ──\n // Reuse the shared spec predicate so cloud graph-lint and framework lint\n // classify titles identically. `none` = no pointer AND nothing derivable.\n const completeness = objectTitleCompleteness(obj as DisplayNameObjectMeta);\n if (completeness.status === 'none') {\n findings.push({\n severity: 'warning',\n rule: TITLE_UNRESOLVABLE,\n where,\n path,\n message:\n `${objName}: no resolvable record title — records will have no ` +\n `meaningful name (no nameField and no title-eligible field to derive one)`,\n hint:\n `Set nameField to a text/email field (or a formula field with ` +\n `returnType: 'text'), or add a text field named \"name\"/\"title\". The ` +\n `runtime auto-provisions a primary and falls back to \"Record #<id>\", ` +\n `but an explicit title is far more useful.`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time semantic-role diagnostics (ADR-0085).\n *\n * The object-level semantic roles (`stageField`, `highlightFields` /\n * deprecated `compactLayout`, `fieldGroups` + `Field.group`) are pointers\n * into the object's own field map. A dangling pointer is Zod-valid but\n * silently inert at render time — the exact \"parsed, unmarked, silently\n * inert\" shape ADR-0078 prohibits — so the completeness lint flags it here,\n * uniformly for `os build`/`os validate`, MCP authoring and hand authors.\n *\n * All three rules are warnings, not errors: every consumer degrades\n * gracefully (an unknown `Field.group` renders in the ungrouped bucket, an\n * unknown highlight name is skipped, an unknown `stageField` falls back to\n * heuristics), so nothing is fully broken — but the author almost certainly\n * typo'd a name and should be told at author time, not discover it by\n * staring at an unchanged page.\n */\n\nexport const FIELD_GROUP_UNDECLARED = 'field-group-undeclared';\nexport const FIELD_GROUP_EMPTY = 'field-group-empty';\nexport const FIELD_GROUP_SHADOWED = 'field-group-shadowed';\nexport const SEMANTIC_ROLE_FIELD_UNKNOWN = 'semantic-role-field-unknown';\n\nexport type SemanticRoleSeverity = 'error' | 'warning';\n\nexport interface SemanticRoleFinding {\n /** Always `warning` today — all three rules are advisory (see module note). */\n severity: SemanticRoleSeverity;\n /** Diagnostic rule id, e.g. `field-group-undeclared`. */\n rule: string;\n /** Human-readable location, e.g. `object \"invoice\"`. */\n where: string;\n /** Config path, e.g. `objects[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/**\n * Validate every object's semantic-role pointers. Returns the list of\n * findings (empty = clean). Advisory only — the caller must never fail the\n * build on these alone.\n */\nexport function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] {\n const findings: SemanticRoleFinding[] = [];\n\n const objects = asArray(stack.objects);\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object') continue; // tolerate junk entries\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const where = `object \"${objName}\"`;\n const path = `objects[${i}]`;\n\n const fields = (obj.fields && typeof obj.fields === 'object' && !Array.isArray(obj.fields))\n ? (obj.fields as Record<string, AnyRec | undefined>)\n : {};\n const fieldNames = new Set(Object.keys(fields));\n\n // ── (a) Field.group → declared fieldGroups[].key ──\n const declaredGroups = new Set(\n (Array.isArray(obj.fieldGroups) ? obj.fieldGroups : [])\n .filter((g): g is AnyRec => !!g && typeof g === 'object')\n .map((g) => g.key)\n .filter((k): k is string => typeof k === 'string' && k.length > 0),\n );\n const referencedGroups = new Set<string>();\n for (const [fname, f] of Object.entries(fields)) {\n const g = f?.group;\n if (typeof g !== 'string' || g.length === 0) continue;\n referencedGroups.add(g);\n if (!declaredGroups.has(g)) {\n findings.push({\n severity: 'warning',\n rule: FIELD_GROUP_UNDECLARED,\n where,\n path: `${path}.fields.${fname}.group`,\n message:\n `${objName}.${fname}: group \"${g}\" is not declared in fieldGroups — ` +\n `the field renders in the ungrouped bucket, not under \"${g}\"`,\n hint:\n `Declare { key: '${g}', label: '…' } in ${objName}.fieldGroups, or fix ` +\n `the field's group reference. Group keys are snake_case and must match exactly.`,\n });\n }\n }\n\n // ── (b) declared group no field references ──\n for (const key of declaredGroups) {\n if (!referencedGroups.has(key)) {\n findings.push({\n severity: 'warning',\n rule: FIELD_GROUP_EMPTY,\n where,\n path: `${path}.fieldGroups`,\n message:\n `${objName}: fieldGroups declares \"${key}\" but no field references it — ` +\n `the group never renders`,\n hint:\n `Assign at least one field via group: '${key}', or remove the unused ` +\n `group declaration.`,\n });\n }\n }\n\n // ── (c) semantic-role pointers name real fields ──\n const stage = obj.stageField;\n if (typeof stage === 'string' && stage.length > 0 && !fieldNames.has(stage)) {\n findings.push({\n severity: 'warning',\n rule: SEMANTIC_ROLE_FIELD_UNKNOWN,\n where,\n path: `${path}.stageField`,\n message:\n `${objName}: stageField \"${stage}\" is not a field on this object — ` +\n `consumers fall back to heuristic stage detection`,\n hint:\n `Point stageField at an existing select/status field, or set ` +\n `stageField: false to declare the object has no linear lifecycle.`,\n });\n }\n\n const highlights = Array.isArray(obj.highlightFields)\n ? obj.highlightFields\n : Array.isArray(obj.compactLayout) // deprecated alias (pre-normalization input)\n ? obj.compactLayout\n : [];\n for (const entry of highlights) {\n if (typeof entry !== 'string' || entry.length === 0 || fieldNames.has(entry)) continue;\n findings.push({\n severity: 'warning',\n rule: SEMANTIC_ROLE_FIELD_UNKNOWN,\n where,\n path: `${path}.highlightFields`,\n message:\n `${objName}: highlightFields entry \"${entry}\" is not a field on this ` +\n `object — it is silently skipped by every consumer`,\n hint:\n `Fix the field name (highlightFields drives default columns, cards, ` +\n `previews and the detail highlight strip, in order).`,\n });\n }\n\n // ── (d) declared group fully shadowed by the detail highlight strip ──\n // Detail pages render the first 4 highlightFields as the top strip and\n // HIDE those fields from the details body; the record's title field is\n // the page H1 and never renders in the body either. A group whose every\n // visible member is covered by strip ∪ title therefore renders on FORMS\n // but silently never on detail pages — legal, but almost never what the\n // author pictured when they declared the group.\n const declaredStrings = highlights.filter(\n (h): h is string => typeof h === 'string' && h.length > 0,\n );\n if (declaredStrings.length > 0 && declaredGroups.size > 0) {\n // Mirror the renderer's title resolution: declared role first\n // (nameField / primaryField / deprecated displayNameField), else the\n // first conventional display-field name present on the object.\n const declaredTitle = [obj.nameField, obj.primaryField, obj.displayNameField]\n .find((v): v is string => typeof v === 'string' && v.length > 0 && fieldNames.has(v));\n const titleField = declaredTitle\n ?? ['name', 'full_name', 'title', 'subject', 'display_name'].find((c) => fieldNames.has(c));\n const stripSet = new Set(\n declaredStrings.filter((h) => h !== titleField).slice(0, 4),\n );\n const hiddenFromBody = new Set(stripSet);\n if (titleField) hiddenFromBody.add(titleField);\n\n for (const key of declaredGroups) {\n const members = Object.entries(fields)\n .filter(([, f]) => f?.group === key && f?.hidden !== true)\n .map(([fname]) => fname);\n if (members.length === 0) continue; // rule (b) already covers empty groups\n if (!members.every((m) => hiddenFromBody.has(m))) continue;\n findings.push({\n severity: 'warning',\n rule: FIELD_GROUP_SHADOWED,\n where,\n path: `${path}.fieldGroups`,\n message:\n `${objName}: every field in group \"${key}\" (${members.join(', ')}) is ` +\n `hoisted into the detail highlight strip (or is the record title) — ` +\n `the group renders on forms but never on detail pages`,\n hint:\n `Keep at least one non-highlighted field in \"${key}\", or remove the ` +\n `group if the strip already covers it. (Detail pages show the first ` +\n `4 highlightFields as the top strip and hide them from the body.)`,\n });\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time form-layout diagnostics (#2578).\n *\n * Authored form views carry field references and column-layout hints that are\n * Zod-valid but can be silently wrong at render time — the \"parsed, unmarked,\n * silently inert\" shape ADR-0078 prohibits. This lint catches the two that\n * matter for multi-column, AI-authored forms, uniformly for `os build` /\n * `os validate`, MCP authoring and hand authors (ADR-0019).\n *\n * Both rules are warnings, not errors — nothing is fully broken (an unknown\n * field name is skipped; an over-wide colSpan is clamped) — but each is almost\n * certainly an authoring mistake worth surfacing at author time:\n *\n * - `form-field-unknown` — a section references a field that is not on the\n * form's bound object, so the field silently does not render.\n * - `absolute-colspan-discouraged` — a field uses the absolute `colSpan`. Under\n * a per-surface DERIVED column count (mobile 1 / modal 2 / page 3-4) a fixed\n * span only lines up at the one width the author imagined; the renderer\n * clamps it. The robust primitive is the relative `span: 'full'`.\n *\n * Scope: top-level form `views` (a `sections` array). Forms embedded inside\n * page component trees are a follow-up — the walker deliberately stays shallow\n * so it never guesses at an arbitrary component's object binding.\n */\n\nexport const FORM_FIELD_UNKNOWN = 'form-field-unknown';\nexport const FORM_COLSPAN_ABSOLUTE = 'absolute-colspan-discouraged';\n\nexport type FormLayoutSeverity = 'error' | 'warning';\n\nexport interface FormLayoutFinding {\n /** Always `warning` today — both rules are advisory (see module note). */\n severity: FormLayoutSeverity;\n /** Diagnostic rule id, e.g. `form-field-unknown`. */\n rule: string;\n /** Human-readable location, e.g. `view \"contract_form\"`. */\n where: string;\n /** Config path, e.g. `views[2].sections[0].fields[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** A section field entry is either a bare field name or `{ field, colSpan, … }`. */\nfunction fieldNameOf(entry: unknown): string | null {\n if (typeof entry === 'string') return entry.length > 0 ? entry : null;\n if (entry && typeof entry === 'object' && !Array.isArray(entry)) {\n const f = (entry as AnyRec).field;\n return typeof f === 'string' && f.length > 0 ? f : null;\n }\n return null;\n}\n\n/** The object a form view binds to: `data.object` (canonical) or `objectName`. */\nfunction boundObject(view: AnyRec): string | undefined {\n const data = view.data;\n if (data && typeof data === 'object' && typeof (data as AnyRec).object === 'string') {\n return (data as AnyRec).object as string;\n }\n return typeof view.objectName === 'string' ? (view.objectName as string) : undefined;\n}\n\n/**\n * Validate authored form-view layout. Returns findings (empty = clean).\n * Advisory only — the caller must never fail the build on these alone.\n */\nexport function validateFormLayout(stack: AnyRec): FormLayoutFinding[] {\n const findings: FormLayoutFinding[] = [];\n\n // object name → its field-name set, for reference checking.\n const objectFields = new Map<string, Set<string>>();\n for (const obj of asArray(stack.objects)) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fields = (obj.fields && typeof obj.fields === 'object' && !Array.isArray(obj.fields))\n ? Object.keys(obj.fields as AnyRec)\n : [];\n objectFields.set(name, new Set(fields));\n }\n\n const views = asArray(stack.views);\n for (let i = 0; i < views.length; i++) {\n const view = views[i];\n if (!view || typeof view !== 'object') continue;\n const sections = Array.isArray(view.sections) ? view.sections : null;\n if (!sections) continue; // only form views carry a sections array\n\n const viewName = typeof view.name === 'string' ? view.name : `(view ${i})`;\n const objName = boundObject(view);\n // Only reference-check when the bound object resolves; otherwise we can't.\n const known = objName ? objectFields.get(objName) : undefined;\n const where = `view \"${viewName}\"`;\n const base = `views[${i}]`;\n\n for (let s = 0; s < sections.length; s++) {\n const sec = sections[s];\n const secFields = sec && typeof sec === 'object' && Array.isArray((sec as AnyRec).fields)\n ? ((sec as AnyRec).fields as unknown[])\n : [];\n for (let f = 0; f < secFields.length; f++) {\n const entry = secFields[f];\n const fname = fieldNameOf(entry);\n const fpath = `${base}.sections[${s}].fields[${f}]`;\n\n // ── (a) section field references a real field on the bound object ──\n if (fname && known && !known.has(fname)) {\n findings.push({\n severity: 'warning',\n rule: FORM_FIELD_UNKNOWN,\n where,\n path: fpath,\n message:\n `${viewName}: field \"${fname}\" is not a field on object \"${objName}\" — ` +\n `it is silently skipped and never renders on the form`,\n hint:\n `Fix the field name, or add \"${fname}\" to ${objName}. Section field ` +\n `references must match the object's field names exactly.`,\n });\n }\n\n // ── (b) absolute colSpan → steer to the surface-independent span ──\n const colSpan = entry && typeof entry === 'object' && !Array.isArray(entry)\n ? (entry as AnyRec).colSpan\n : undefined;\n if (colSpan != null) {\n findings.push({\n severity: 'warning',\n rule: FORM_COLSPAN_ABSOLUTE,\n where,\n path: `${fpath}.colSpan`,\n message:\n `${viewName}: field \"${fname ?? '?'}\" sets absolute colSpan ${String(colSpan)} — ` +\n `the form's column count is derived per surface (mobile 1 / modal 2 / page 3-4), ` +\n `so a fixed span only aligns at one width`,\n hint:\n `Prefer span: 'full' (whole row at any column count), or omit for auto ` +\n `width. The renderer clamps colSpan to the current column count.`,\n });\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time conditional-visibility diagnostics (ADR-0089 D3b).\n *\n * ADR-0089 unifies the conditional-visibility predicate under the single\n * canonical key **`visibleWhen`** across data fields, view form sections/fields,\n * and page components. The deprecated spellings — `visibleOn` (view form) and\n * `visibility` (page component) — stay accepted and are folded into `visibleWhen`\n * at the schema boundary (a zod `.transform()`). Because that fold happens during\n * `parse()`, the aliases are gone from the *parsed* stack — so this rule runs on\n * the **pre-parse** (normalized) stack, exactly like `validate-list-view-mode`,\n * to see what the author actually wrote.\n *\n * Two advisory rules (both `warning` — nothing is broken, the alias still works\n * and a mis-rooted predicate just never matches):\n *\n * - `visibility-alias-deprecated` — a `visibleOn` / `visibility` key in authored\n * source. Autofix intent: rename the key to `visibleWhen` (same value).\n * - `visibility-root-mislayered` — a visibility predicate whose binding root does\n * not match its layer (ADR-0089 D3, §Context). The check is **bidirectional**:\n * - **runtime** view/page surfaces (`*.view.ts` / `*.page.ts`) bind\n * `record` + `current_user` (pages also expose `page.<var>`), so a `data.`-rooted\n * predicate here is a wrong-layer paste that silently never matches; and\n * - **metadata-editing** forms (`*.form.ts` — the row under edit) bind `data`, so\n * a `record.`-rooted predicate there is the same bug in the other direction.\n * The layer is supplied by the caller (`opts.layer`, default `'runtime'`): the\n * app-lint path (`os validate` / `compile`) always lints runtime surfaces, while a\n * file-aware caller linting a `*.form.ts` passes `layer: 'metadata'`.\n *\n * Scope: `views` (form `sections` / legacy `groups`, and their `fields`) and\n * `pages` (`regions[].components[]`). Data-field `visibleWhen` is already covered\n * by `validate-expressions` and is not re-checked here.\n */\n\nexport const VISIBILITY_ALIAS_DEPRECATED = 'visibility-alias-deprecated';\nexport const VISIBILITY_ROOT_MISLAYERED = 'visibility-root-mislayered';\n\nexport type VisibilitySeverity = 'error' | 'warning';\n\n/**\n * Which binding environment the linted surface belongs to (ADR-0089 §Context):\n * - `runtime` — `*.view.ts` / `*.page.ts`; binds `record` + `current_user` (+ `page`).\n * - `metadata` — `*.form.ts` metadata-editing forms; binds `data` (the row under edit).\n */\nexport type VisibilityLayer = 'runtime' | 'metadata';\n\n/** Options for {@link validateVisibilityPredicates}. */\nexport interface VisibilityOptions {\n /** Binding layer of the surface being linted. Defaults to `'runtime'`. */\n layer?: VisibilityLayer;\n}\n\nexport interface VisibilityFinding {\n /** Always `warning` today — both rules are advisory (see module note). */\n severity: VisibilitySeverity;\n /** Diagnostic rule id, e.g. `visibility-alias-deprecated`. */\n rule: string;\n /** Human-readable location, e.g. `view \"contact_form\"`. */\n where: string;\n /** Config path, e.g. `views[2].sections[0].fields[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** The canonical key and its two deprecated aliases (ADR-0089). */\nconst CANONICAL = 'visibleWhen';\nconst ALIASES = ['visibleOn', 'visibility'] as const;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** Extract the CEL source from a predicate value (string, or `{ source }` envelope). */\nfunction predicateSource(v: unknown): string | undefined {\n if (typeof v === 'string') return v;\n if (v && typeof v === 'object' && typeof (v as AnyRec).source === 'string') {\n return (v as AnyRec).source as string;\n }\n return undefined;\n}\n\n/** Does the predicate reference `<root>.<x>` as a leading binding root? */\nfunction usesRoot(source: string, root: string): boolean {\n // `<root>` as a leading identifier followed by a property access. The leading\n // `(^|[^.\\w$])` guard excludes a nested access like `foo.data` (a field named\n // `data`) or `my_record.x` (an identifier that merely ends in `record`).\n return new RegExp(`(^|[^.\\\\w$])${root}\\\\.\\\\w`).test(source);\n}\n\n/**\n * Per-layer mis-rooted-predicate description. The `runtime` layer forbids the\n * metadata-editing-form root (`data.`); the `metadata` layer forbids the runtime\n * record-surface root (`record.`) — ADR-0089 D3 spells out both directions.\n */\nconst MISLAYER_BY_LAYER: Record<\n VisibilityLayer,\n { forbiddenRoot: string; message: string; hint: string }\n> = {\n runtime: {\n forbiddenRoot: 'data',\n message:\n 'visibility predicate is rooted at `data.` — that is the ' +\n 'metadata-editing-form root (a `*.form.ts` row under edit), not a runtime ' +\n 'surface. A runtime view/page predicate that binds `data.` never matches ' +\n 'and the element renders unconditionally (ADR-0089).',\n hint:\n 'Runtime record surfaces bind `record` + `current_user` (pages also ' +\n \"expose `page.<var>`). Use e.g. `record.status == 'open'` instead of \" +\n \"`data.status == 'open'`.\",\n },\n metadata: {\n forbiddenRoot: 'record',\n message:\n 'visibility predicate is rooted at `record.` — that is the runtime ' +\n 'record-surface root (a `*.view.ts` / `*.page.ts` live record), not a ' +\n 'metadata-editing form. A `*.form.ts` predicate that binds `record.` never ' +\n 'matches and the element renders unconditionally (ADR-0089).',\n hint:\n 'Metadata-editing forms bind `data` (the row under edit). Use e.g. ' +\n \"`data.type == 'grid'` instead of `record.type == 'grid'`.\",\n },\n};\n\n/**\n * Inspect one element carrying a visibility predicate. Emits the alias-deprecated\n * finding (when an alias key is present) and the mis-layered-root finding (when\n * the effective predicate's binding root does not match `layer`).\n */\nfunction checkElement(\n el: AnyRec,\n where: string,\n path: string,\n layer: VisibilityLayer,\n findings: VisibilityFinding[],\n): void {\n // (1) deprecated alias key present → steer to `visibleWhen`.\n for (const alias of ALIASES) {\n if (el[alias] !== undefined) {\n findings.push({\n severity: 'warning',\n rule: VISIBILITY_ALIAS_DEPRECATED,\n where,\n path: `${path}.${alias}`,\n message:\n `\\`${alias}\\` is the deprecated spelling of the conditional-visibility ` +\n `predicate (ADR-0089). It still works — it is normalized to \\`visibleWhen\\` ` +\n `at parse — but the canonical key is \\`visibleWhen\\`.`,\n hint: `Rename the key \\`${alias}\\` → \\`visibleWhen\\` (same CEL value).`,\n });\n }\n }\n\n // (2) mis-layered binding root — check the effective predicate (canonical wins)\n // against the root expected for this layer.\n const raw = el[CANONICAL] ?? el.visibleOn ?? el.visibility;\n const source = predicateSource(raw);\n const rule = MISLAYER_BY_LAYER[layer];\n if (source && usesRoot(source, rule.forbiddenRoot)) {\n findings.push({\n severity: 'warning',\n rule: VISIBILITY_ROOT_MISLAYERED,\n where,\n path,\n message: rule.message,\n hint: rule.hint,\n });\n }\n}\n\n/** A section field entry is either a bare field name or `{ field, visibleWhen, … }`. */\nfunction isFieldObject(entry: unknown): entry is AnyRec {\n return !!entry && typeof entry === 'object' && !Array.isArray(entry);\n}\n\n/**\n * Validate conditional-visibility keys across authored views and pages.\n *\n * Runs on the **pre-parse** (normalized) stack so it can see the deprecated\n * `visibleOn` / `visibility` aliases before the schema folds them into\n * `visibleWhen`. Returns findings (empty = clean); all advisory (`warning`) —\n * the caller must never fail the build on these alone.\n *\n * The binding-root check is layer-directional (ADR-0089 D3): pass\n * `opts.layer = 'metadata'` when linting a `*.form.ts` metadata-editing form (so a\n * `record.`-rooted predicate is flagged), or leave it at the `'runtime'` default for\n * `*.view.ts` / `*.page.ts` surfaces (so a `data.`-rooted predicate is flagged). The\n * alias-deprecated check is layer-agnostic.\n */\nexport function validateVisibilityPredicates(\n stack: AnyRec,\n opts: VisibilityOptions = {},\n): VisibilityFinding[] {\n const layer: VisibilityLayer = opts.layer ?? 'runtime';\n const findings: VisibilityFinding[] = [];\n\n // ── Views: form sections / legacy groups, and their fields ──────────\n const views = asArray(stack.views);\n for (let i = 0; i < views.length; i++) {\n const view = views[i];\n if (!view || typeof view !== 'object') continue;\n const viewName = typeof view.name === 'string' ? view.name : `(view ${i})`;\n const where = `view \"${viewName}\"`;\n\n // `sections` (canonical) and `groups` (legacy alias → sections) both hold\n // FormSection objects with an optional visibility predicate + `fields`.\n for (const bucket of ['sections', 'groups'] as const) {\n const sections = Array.isArray(view[bucket]) ? (view[bucket] as unknown[]) : [];\n for (let s = 0; s < sections.length; s++) {\n const sec = sections[s];\n if (!sec || typeof sec !== 'object') continue;\n const secPath = `views[${i}].${bucket}[${s}]`;\n checkElement(sec as AnyRec, where, secPath, layer, findings);\n\n const secFields = Array.isArray((sec as AnyRec).fields) ? ((sec as AnyRec).fields as unknown[]) : [];\n for (let f = 0; f < secFields.length; f++) {\n const entry = secFields[f];\n if (isFieldObject(entry)) {\n checkElement(entry, where, `${secPath}.fields[${f}]`, layer, findings);\n }\n }\n }\n }\n }\n\n // ── Pages: regions[].components[] ───────────────────────────────────\n const pages = asArray(stack.pages);\n for (let i = 0; i < pages.length; i++) {\n const page = pages[i];\n if (!page || typeof page !== 'object') continue;\n const pageName = typeof page.name === 'string' ? page.name : `(page ${i})`;\n const where = `page \"${pageName}\"`;\n const regions = Array.isArray(page.regions) ? (page.regions as unknown[]) : [];\n for (let r = 0; r < regions.length; r++) {\n const region = regions[r];\n const components = region && typeof region === 'object' && Array.isArray((region as AnyRec).components)\n ? ((region as AnyRec).components as unknown[])\n : [];\n for (let c = 0; c < components.length; c++) {\n const comp = components[c];\n if (comp && typeof comp === 'object') {\n checkElement(comp as AnyRec, where, `pages[${i}].regions[${r}].components[${c}]`, layer, findings);\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0066 ⑨] Authoring-time validation for capability references.\n *\n * `requiredPermissions` (on objects, fields, apps, and actions) and\n * `systemPermissions` (on permission sets) are free capability strings. A typo\n * — `mange_users` for `manage_users` — is Zod-valid and fails CLOSED at runtime\n * (the caller is denied), which is the safe direction but UNDISCOVERABLE: nothing\n * tells the author the referenced capability exists nowhere. This rule closes\n * that gap by resolving every `requiredPermissions` reference against the set of\n * capabilities known at author time and warning on the unresolved ones —\n * \"reject at the producer\" (Prime Directive / ADR-0049 honesty).\n *\n * The author-time \"known\" set is:\n * 1. the built-in platform capabilities (`PLATFORM_CAPABILITY_NAMES`),\n * 2. every capability the stack DECLARES via `defineCapability`\n * (`stack.capabilities`) — the explicit, package-provenanced declaration\n * (ADR-0066 D1), materialized at boot by `bootstrapDeclaredCapabilities`,\n * 3. every capability a permission set in this stack GRANTS via\n * `systemPermissions` (granting a capability also declares it — mirrors\n * the runtime `bootstrapSystemCapabilities` derived-defaults rule), and\n * 4. any `sys_capability` row shipped as seed data.\n *\n * WARNING, not error: a single package's lint cannot see capabilities declared\n * by OTHER installed packages, and the reference fails closed at runtime anyway,\n * so a dangling reference is \"almost certainly a typo\" — surface it, don't break\n * the build. Assignment (`systemPermissions`) is NOT flagged: it is the\n * declaration side, and a package legitimately introduces new capabilities there.\n */\n\nimport { PLATFORM_CAPABILITY_NAMES } from '@objectstack/spec/security';\n\nexport const CAPABILITY_REFERENCE_UNKNOWN = 'capability-reference-unknown';\n\nexport type CapabilityRefSeverity = 'error' | 'warning';\n\nexport interface CapabilityRefFinding {\n /** Always `warning` — the reference fails closed at runtime (see module note). */\n severity: CapabilityRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `object \"sys_license\"`. */\n where: string;\n /** Config path, e.g. `objects[3].requiredPermissions`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** The capability strings in a `string[]` value. */\nfunction asCapArray(v: unknown): string[] {\n return Array.isArray(v) ? v.filter((s): s is string => typeof s === 'string' && s.length > 0) : [];\n}\n\n/**\n * Flatten an object-level `requiredPermissions` — either a `string[]` (all\n * operations) or a per-operation `{ read, create, update, delete }` map (ADR-0066\n * ⑤) — into `[{ cap, key }]`, where `key` is the map key (or `undefined` for the\n * array form) so a finding can point at the exact operation slice.\n */\nfunction flattenObjectRequired(v: unknown): Array<{ cap: string; key?: string }> {\n if (Array.isArray(v)) return asCapArray(v).map((cap) => ({ cap }));\n if (v && typeof v === 'object') {\n const out: Array<{ cap: string; key?: string }> = [];\n for (const [key, val] of Object.entries(v as AnyRec)) {\n for (const cap of asCapArray(val)) out.push({ cap, key });\n }\n return out;\n }\n return [];\n}\n\n/**\n * Validate every capability reference in a stack. Returns findings (empty =\n * clean). Advisory only — callers must not fail the build on these alone.\n */\nexport function validateCapabilityReferences(stack: AnyRec): CapabilityRefFinding[] {\n const findings: CapabilityRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n // ── Build the author-time \"known capability\" set ──\n const known = new Set<string>(PLATFORM_CAPABILITY_NAMES);\n // [ADR-0066 D1] Capabilities the stack explicitly DECLARES via defineCapability.\n for (const cap of asArray(stack.capabilities)) {\n if (typeof cap.name === 'string' && cap.name.length > 0) known.add(cap.name);\n }\n for (const ps of asArray(stack.permissions)) {\n for (const cap of asCapArray(ps.systemPermissions)) known.add(cap);\n }\n for (const seed of asArray(stack.data)) {\n if (seed.object !== 'sys_capability') continue;\n for (const rec of Array.isArray(seed.records) ? seed.records : []) {\n const name = (rec as AnyRec | null)?.name;\n if (typeof name === 'string' && name.length > 0) known.add(name);\n }\n }\n\n const hint =\n 'Fix the capability name, define it with defineCapability (stack.capabilities), ' +\n 'declare it on a permission set’s systemPermissions, ship a sys_capability seed row, ' +\n 'or ignore this if the capability is provided by another installed package ' +\n '(references fail closed at runtime).';\n\n const flag = (cap: string, where: string, path: string) => {\n if (known.has(cap)) return;\n findings.push({\n severity: 'warning',\n rule: CAPABILITY_REFERENCE_UNKNOWN,\n where,\n path,\n message:\n `requiredPermissions references capability \"${cap}\" which is registered ` +\n `nowhere — no built-in capability, no permission set in this package grants ` +\n `it via systemPermissions, and no sys_capability seed declares it`,\n hint,\n });\n };\n\n // ── Objects (D3) + their fields (D3) + embedded actions (D4) ──\n const objects = asArray(stack.objects);\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object') continue;\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const objPath = `objects[${i}]`;\n\n for (const { cap, key } of flattenObjectRequired(obj.requiredPermissions)) {\n flag(cap, `object \"${objName}\"`, `${objPath}.requiredPermissions${key ? `.${key}` : ''}`);\n }\n\n const fields = asArray(obj.fields);\n for (const f of fields) {\n const fname = typeof f.name === 'string' ? f.name : '(field)';\n for (const cap of asCapArray(f.requiredPermissions)) {\n flag(cap, `field \"${objName}.${fname}\"`, `${objPath}.fields.${fname}.requiredPermissions`);\n }\n }\n\n for (const [ai, action] of asArray(obj.actions).entries()) {\n const aName = typeof action.name === 'string' ? action.name : `(action ${ai})`;\n for (const cap of asCapArray(action.requiredPermissions)) {\n flag(cap, `action \"${objName}.${aName}\"`, `${objPath}.actions[${ai}].requiredPermissions`);\n }\n }\n }\n\n // ── Top-level actions (D4) ──\n for (const [i, action] of asArray(stack.actions).entries()) {\n const aName = typeof action.name === 'string' ? action.name : `(action ${i})`;\n for (const cap of asCapArray(action.requiredPermissions)) {\n flag(cap, `action \"${aName}\"`, `actions[${i}].requiredPermissions`);\n }\n }\n\n // ── Apps: requiredPermissions can appear at the app, area/tab, and nav-item\n // (recursively through groups) levels. Walk each app subtree. ──\n const apps = asArray(stack.apps);\n for (let i = 0; i < apps.length; i++) {\n const app = apps[i];\n if (!app || typeof app !== 'object') continue;\n const appName = typeof app.name === 'string' ? app.name : `(app ${i})`;\n const walk = (node: unknown, path: string) => {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((child, ci) => walk(child, `${path}[${ci}]`));\n return;\n }\n const rec = node as AnyRec;\n for (const cap of asCapArray(rec.requiredPermissions)) {\n flag(cap, `app \"${appName}\"`, `${path}.requiredPermissions`);\n }\n // Recurse only into the sub-structures that carry requiredPermissions.\n if (rec.navigation) walk(rec.navigation, `${path}.navigation`);\n if (rec.areas) walk(rec.areas, `${path}.areas`);\n if (rec.tabs) walk(rec.tabs, `${path}.tabs`);\n if (rec.children) walk(rec.children, `${path}.children`);\n if (rec.items) walk(rec.items, `${path}.items`);\n };\n walk(app, `apps[${i}]`);\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Approval-node approver authoring lint (ADR-0090 D3 fallout).\n *\n * `org_membership_level` (and `role`, its deprecated spelling) resolves against\n * better-auth's org-membership tier (`sys_member.role`: owner / admin / member)\n * — it is NOT a position. After ADR-0090 D3 renamed `sys_role` → `sys_position`,\n * downstream apps that authored `{ type: 'role', value: 'sales_manager' }`\n * silently route the approval to nobody: the expansion finds no member row,\n * falls back to the `role:sales_manager` literal, and the request waits on an\n * approver that can never act. These rules move that failure from a stuck\n * request at runtime to a located fix-it at author time.\n *\n * Rules:\n *\n * | Rule | Severity | Origin |\n * |--------------------------------------------|----------|----------------------------|\n * | approval-approver-not-membership-tier | warning | ADR-0090 D3 (hotcrm class) |\n * | approval-approver-type-deprecated | warning | ADR-0090 D3 (#3133) |\n * | approval-approver-type-unknown | warning | contract-first (PD #12) |\n * | approval-escalation-reassign-no-target | warning | silent notify degradation |\n *\n * The first two are mutually exclusive by construction — a bad *value* wins,\n * because its fix (`position`) differs from the deprecation's fix\n * (`org_membership_level`), and prescribing the latter for a position name\n * would be wrong advice.\n *\n * Warnings (not errors): a custom better-auth membership tier is legal, and\n * the runtime keeps its literal fallback — but both shapes are near-certainly\n * authoring mistakes, so say it out loud.\n *\n * Pure `(stack) => Finding[]`; accepts the NORMALIZED stack input.\n */\n\nimport {\n ApproverType,\n APPROVAL_NODE_TYPE,\n DEPRECATED_APPROVER_TYPES,\n canonicalApproverType,\n} from '@objectstack/spec/automation';\n\nexport const APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER = 'approval-approver-not-membership-tier';\nexport const APPROVAL_APPROVER_TYPE_DEPRECATED = 'approval-approver-type-deprecated';\nexport const APPROVAL_APPROVER_TYPE_UNKNOWN = 'approval-approver-type-unknown';\nexport const APPROVAL_ESCALATION_REASSIGN_NO_TARGET = 'approval-escalation-reassign-no-target';\n\nexport type ApprovalApproverSeverity = 'error' | 'warning' | 'info';\n\nexport interface ApprovalApproverFinding {\n severity: ApprovalApproverSeverity;\n /** Diagnostic rule id (`approval-*`). */\n rule: string;\n /** Human-readable location, e.g. `flow \"expense_approval\" · node \"step1\"`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[2].config.approvers[0]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/**\n * The better-auth org-membership tiers `sys_member.role` actually stores\n * (see `identity/organization.zod.ts` + `mapMembershipRole`). Anything else\n * authored as `{ type: 'org_membership_level' }` (or its deprecated `role`\n * spelling) is almost certainly a position name.\n */\nconst MEMBERSHIP_TIERS = new Set(['owner', 'admin', 'member', 'guest']);\n\n/** Off-spec dialect spellings we can name a canonical fix for. */\nconst TYPE_FIX: Record<string, string> = {\n business_unit: 'department',\n bu: 'department',\n};\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/**\n * Validate the approvers of every Approval node in the stack's flows.\n * Returns findings (empty = clean).\n */\nexport function validateApprovalApprovers(stack: AnyRec): ApprovalApproverFinding[] {\n const findings: ApprovalApproverFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const flows = asArray(stack.flows);\n const validTypes = new Set<string>(ApproverType.options);\n\n for (let fi = 0; fi < flows.length; fi++) {\n const flow = flows[fi];\n if (!flow || typeof flow !== 'object') continue;\n const flowName = typeof flow.name === 'string' ? flow.name : `(flow ${fi})`;\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n\n for (let ni = 0; ni < nodes.length; ni++) {\n const node = nodes[ni];\n if (!node || node.type !== APPROVAL_NODE_TYPE) continue;\n const nodeId = typeof node.id === 'string' ? node.id : `(node ${ni})`;\n const cfg = (node.config ?? {}) as AnyRec;\n const approvers = Array.isArray(cfg.approvers) ? (cfg.approvers as AnyRec[]) : [];\n const where = `flow \"${flowName}\" · node \"${nodeId}\"`;\n\n for (let ai = 0; ai < approvers.length; ai++) {\n const a = approvers[ai];\n if (!a || typeof a !== 'object') continue;\n const type = typeof a.type === 'string' ? a.type : '';\n const value = typeof a.value === 'string' ? a.value : '';\n const path = `flows[${fi}].nodes[${ni}].config.approvers[${ai}]`;\n\n if (type && !validTypes.has(type)) {\n const fix = TYPE_FIX[type];\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_TYPE_UNKNOWN,\n where,\n path: `${path}.type`,\n message:\n `approver type '${type}' is not an ApproverType (${ApproverType.options.join(' | ')}).`,\n hint: fix\n ? `Use the spec value: { type: '${fix}', value: '${value}' }.`\n : `Pick one of the spec values; unmapped types degrade to an inert '${type}:${value}' literal at runtime.`,\n });\n continue;\n }\n\n const canonical = canonicalApproverType(type);\n\n // Exactly one of the two below fires. Order matters: a bad VALUE is\n // the more serious (and differently-fixed) defect, so it wins. Telling\n // an author to rewrite { type: 'role', value: 'sales_manager' } as\n // `org_membership_level` would be actively wrong advice — the fix is\n // `position`, and the deprecation is beside the point.\n if (canonical === 'org_membership_level' && value && !MEMBERSHIP_TIERS.has(value.toLowerCase())) {\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER,\n where,\n path: `${path}.value`,\n message:\n `approver { type: '${type}', value: '${value}' } resolves against the better-auth ` +\n `org-membership tier (sys_member.role: owner/admin/member) — '${value}' is not a ` +\n `membership tier, so this approver matches nobody and the request stalls.`,\n hint:\n `If '${value}' is an org position, author { type: 'position', value: '${value}' } ` +\n `(resolved via sys_user_position, ADR-0090 D3). Keep type 'org_membership_level' ` +\n `only for membership tiers (owner/admin/member).`,\n });\n } else if (type in DEPRECATED_APPROVER_TYPES) {\n const fix = canonicalApproverType(type);\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_TYPE_DEPRECATED,\n where,\n path: `${path}.type`,\n message:\n `approver type '${type}' is the deprecated spelling of '${fix}' (ADR-0090 D3) and ` +\n `is removed in the next major.`,\n hint: `Author { type: '${fix}', value: '${value}' }. It resolves identically today.`,\n });\n }\n }\n\n // escalation.action 'reassign' with no escalateTo silently degrades to a\n // plain SLA-breach notification at runtime — the hand-off the author\n // asked for never happens.\n const escalation = (cfg.escalation ?? null) as AnyRec | null;\n if (escalation && typeof escalation === 'object' && escalation.action === 'reassign') {\n const target = typeof escalation.escalateTo === 'string' ? escalation.escalateTo.trim() : '';\n if (!target) {\n findings.push({\n severity: 'warning',\n rule: APPROVAL_ESCALATION_REASSIGN_NO_TARGET,\n where,\n path: `flows[${fi}].nodes[${ni}].config.escalation.escalateTo`,\n message:\n `escalation.action is 'reassign' but escalateTo is empty — at runtime the ` +\n `escalation degrades to a notify and the request stays with the original approvers.`,\n hint:\n `Set escalateTo to a position machine name (expanded via sys_user_position, ` +\n `ADR-0090 D3) or a specific user id, or change action to 'notify'.`,\n });\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0090 D7] Security-domain publish linter.\n *\n * Every rule here is traceable to an observed failure class (the taxonomy\n * grows by incident, per the ADR):\n *\n * | Rule | Origin |\n * |-----------------------------------------|---------------------------------|\n * | security-owd-unset (error) | objectui#2348 leave_request 事故 |\n * | security-owd-alias (error) | ADR-0090 D4 canonical enum |\n * | security-external-wider (error) | ADR-0090 D11 external ≤ internal|\n * | security-wildcard-vama (error) | ADR-0066 superuser wildcard |\n * | security-anchor-high-privilege(error) | ADR-0090 D5/D9 anchors |\n * | security-role-word (error) | ADR-0090 D3 vocabulary freeze |\n * | security-book-audience-unknown-set(warn)| ADR-0046 §6.7 { permissionSet } |\n * | security-private-no-readscope (info) | admin-intent mismatch class |\n * | security-master-detail-ungranted(warn) | framework#2700 os-tianshun-mtc#43|\n * | security-grant-expired-at-authoring(err)| ADR-0091 D2 resolution filtering|\n * | security-delegation-missing-reason(err) | ADR-0091 D3 dual audit |\n *\n * Per ADR-0049 discipline these are NOT advisory security: every `error` rule\n * mirrors a runtime enforcement point (D1 fail-closed OWD default, D4 zod\n * enum + fail-closed evaluator, D5/D9 anchor binding gate, D3 rename wave) —\n * the lint moves the failure from runtime-deny to author-time fix-it. The lone\n * `warning` (master-detail-ungranted) likewise mirrors a runtime gate — the\n * object-level CRUD check (ADR-0055) — but stays advisory: it flags a *likely*\n * misconfiguration whose per-permission-set nuance it cannot fully adjudicate.\n *\n * Pure `(stack) => Finding[]`; accepts the NORMALIZED stack input (works both\n * pre- and post-zod-parse, so `os lint` catches what the zod gate would\n * reject in `os compile` — with a better message).\n */\n\nimport { describeAnchorForbiddenBits } from '@objectstack/spec/security';\n\nexport const SECURITY_OWD_UNSET = 'security-owd-unset';\nexport const SECURITY_OWD_ALIAS = 'security-owd-alias';\nexport const SECURITY_EXTERNAL_WIDER = 'security-external-wider-than-internal';\nexport const SECURITY_WILDCARD_VAMA = 'security-wildcard-vama';\nexport const SECURITY_ANCHOR_HIGH_PRIVILEGE = 'security-anchor-high-privilege';\nexport const SECURITY_ROLE_WORD = 'security-role-word';\nexport const SECURITY_BOOK_AUDIENCE_UNKNOWN_SET = 'security-book-audience-unknown-set';\nexport const SECURITY_PRIVATE_NO_READSCOPE = 'security-private-no-readscope';\nexport const SECURITY_MASTER_DETAIL_UNGRANTED = 'security-master-detail-ungranted';\nexport const SECURITY_FLS_UNQUALIFIED_KEY = 'security-fls-unqualified-key';\nexport const SECURITY_GRANT_EXPIRED_AT_AUTHORING = 'security-grant-expired-at-authoring';\nexport const SECURITY_DELEGATION_MISSING_REASON = 'security-delegation-missing-reason';\n\nexport type SecuritySeverity = 'error' | 'warning' | 'info';\n\nexport interface SecurityFinding {\n severity: SecuritySeverity;\n /** Diagnostic rule id (`security-*`). */\n rule: string;\n /** Human-readable location, e.g. `object \"leave_request\"`. */\n where: string;\n /** Config path, e.g. `objects[3].sharingModel`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nconst CANONICAL_OWD = ['private', 'public_read', 'public_read_write', 'controlled_by_parent'] as const;\n/** [ADR-0090 D4] Legacy alias → canonical fix-it mapping. */\nconst OWD_ALIAS_FIX: Record<string, string> = {\n read: 'public_read',\n read_write: 'public_read_write',\n full: 'public_read_write',\n public: 'public_read_write',\n};\n/** D11 ordering for external ≤ internal (controlled_by_parent excluded). */\nconst OWD_WIDTH: Record<string, number> = {\n private: 0,\n public_read: 1,\n public_read_write: 2,\n};\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction owdOf(obj: AnyRec): unknown {\n return obj.sharingModel ?? (obj.security as AnyRec | undefined)?.sharingModel;\n}\n\nfunction isSystemObject(obj: AnyRec): boolean {\n return obj.isSystem === true || String(obj.name ?? '').startsWith('sys_');\n}\n\n/** snake_case identifier contains the reserved token `role`/`roles`. */\nfunction identifierHasRoleToken(name: unknown): boolean {\n if (typeof name !== 'string') return false;\n return name\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .some((tok) => tok === 'role' || tok === 'roles');\n}\n\n/** Free-text label contains the whole word `role(s)` (case-insensitive). */\nfunction labelHasRoleWord(label: unknown): boolean {\n if (typeof label !== 'string') return false;\n return /\\brole(s)?\\b/i.test(label);\n}\n\n/** The `reference`/`reference_to` target a relationship field points at. */\nfunction refOf(def: AnyRec): string | undefined {\n const r = (def.reference ?? def.reference_to) as unknown;\n return typeof r === 'string' && r ? r : undefined;\n}\n\n/**\n * The first `master_detail` field on an object, if any — its presence is what\n * makes the object a DETAIL (the child side of a master-detail; ADR-0055).\n * Works for both the array and name-keyed-map field forms (`asArray` folds the\n * map key into `name`).\n */\nfunction firstMasterDetailField(obj: AnyRec): { name: string; parent?: string } | undefined {\n for (const f of asArray(obj.fields)) {\n if (f.type === 'master_detail') {\n return { name: String(f.name ?? '?'), parent: refOf(f) };\n }\n }\n return undefined;\n}\n\n/**\n * Does a per-object permission entry open the object-level CRUD gate at all?\n * Any of the four CRUD bits, or a super-user bypass (View/Modify All Data),\n * counts — this mirrors the runtime `checkObjectPermission` gate (ADR-0066 D2):\n * that gate returns true if ANY set contributes one of these for the object.\n */\nfunction grantsObjectAccess(p: AnyRec): boolean {\n return (\n p.allowRead === true ||\n p.allowCreate === true ||\n p.allowEdit === true ||\n p.allowDelete === true ||\n p.viewAllRecords === true ||\n p.modifyAllRecords === true\n );\n}\n\n/**\n * Validate the security posture of a stack. Returns findings (empty = clean).\n * `error` findings gate the build in `os compile`; `info` is advisory.\n *\n * `opts.nowMs` injects the clock for the ADR-0091 authoring-time expiry rule\n * (tests); production callers omit it.\n */\nexport function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number }): SecurityFinding[] {\n const findings: SecurityFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const objects = asArray(stack.objects);\n const permissionSets = asArray(stack.permissions);\n\n // ── D1/D4/D11: per-object OWD posture ────────────────────────────────\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object') continue;\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const objPath = `objects[${i}]`;\n const owd = owdOf(obj);\n const external = obj.externalSharingModel;\n\n if (!isSystemObject(obj)) {\n if (owd == null) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_UNSET,\n where: `object \"${objName}\"`,\n path: `${objPath}.sharingModel`,\n message:\n `custom object \"${objName}\" declares no sharingModel (OWD). The runtime fails ` +\n `CLOSED to 'private' (ADR-0090 D1), but the baseline must be an authored decision, ` +\n `not an accident — this is the exact shape of the leave_request incident (objectui#2348).`,\n hint:\n `Declare sharingModel explicitly: 'private' (owner + shares; recommended default), ` +\n `'public_read', 'public_read_write', or 'controlled_by_parent' (master-detail children).`,\n });\n } else if (typeof owd === 'string' && OWD_ALIAS_FIX[owd]) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_ALIAS,\n where: `object \"${objName}\"`,\n path: `${objPath}.sharingModel`,\n message:\n `sharingModel '${owd}' is a retired alias (ADR-0090 D4). The runtime fails CLOSED ` +\n `to 'private' on unknown values, so this object is NOT ${owd === 'read' ? 'readable' : 'writable'} org-wide.`,\n hint: `Replace with the canonical value: sharingModel: '${OWD_ALIAS_FIX[owd]}'.`,\n });\n } else if (typeof owd === 'string' && !(CANONICAL_OWD as readonly string[]).includes(owd)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_ALIAS,\n where: `object \"${objName}\"`,\n path: `${objPath}.sharingModel`,\n message:\n `sharingModel '${owd}' is not a canonical OWD value; the runtime fails CLOSED to 'private'.`,\n hint: `Use one of: ${CANONICAL_OWD.join(', ')}.`,\n });\n }\n }\n\n // D11: external dial present on any object (system included) must obey\n // external ≤ internal. controlled_by_parent inherits the master's pair.\n if (typeof external === 'string') {\n if (OWD_ALIAS_FIX[external]) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_ALIAS,\n where: `object \"${objName}\"`,\n path: `${objPath}.externalSharingModel`,\n message: `externalSharingModel '${external}' is a retired alias (ADR-0090 D4).`,\n hint: `Replace with the canonical value: externalSharingModel: '${OWD_ALIAS_FIX[external]}'.`,\n });\n } else if (\n typeof owd === 'string' &&\n external in OWD_WIDTH &&\n owd in OWD_WIDTH &&\n OWD_WIDTH[external] > OWD_WIDTH[owd]\n ) {\n findings.push({\n severity: 'error',\n rule: SECURITY_EXTERNAL_WIDER,\n where: `object \"${objName}\"`,\n path: `${objPath}.externalSharingModel`,\n message:\n `externalSharingModel '${external}' is WIDER than the internal sharingModel '${owd}' — ` +\n `the external baseline must never exceed the internal one (ADR-0090 D11).`,\n hint: `Narrow externalSharingModel to '${owd}' or below (ordering: private < public_read < public_read_write).`,\n });\n }\n }\n }\n\n // ── ADR-0066 / D5/D9: permission-set posture ─────────────────────────\n for (let i = 0; i < permissionSets.length; i++) {\n const ps = permissionSets[i];\n if (!ps || typeof ps !== 'object') continue;\n const psName = typeof ps.name === 'string' ? ps.name : `(permission set ${i})`;\n const psPath = `permissions[${i}]`;\n const objectsMap = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n\n // [#19 / permission zoo audit] FLS keys MUST be `<object>.<field>`\n // qualified. The runtime evaluator matches keys by object prefix\n // (`getFieldPermissions`: `key.startsWith(objectName + '.')`), so a bare\n // `budget` key matches NOTHING — the declared masking silently never\n // enforces (the worst declared-≠-enforced class, ADR-0049). The showcase\n // itself shipped this bug for months.\n const flsMap = (ps.fields && typeof ps.fields === 'object' ? ps.fields : {}) as AnyRec;\n for (const flsKey of Object.keys(flsMap)) {\n if (flsKey.includes('.')) continue;\n findings.push({\n severity: 'error',\n rule: SECURITY_FLS_UNQUALIFIED_KEY,\n where: `permission set \"${psName}\"`,\n path: `${psPath}.fields[\"${flsKey}\"]`,\n message:\n `field-permission key '${flsKey}' is not object-qualified — the runtime matches FLS keys ` +\n `by '<object>.<field>' prefix, so a bare key is silently IGNORED and the declared masking never enforces.`,\n hint: `Qualify the key with its object, e.g. 'crm_opportunity.${flsKey}': { readable: true, editable: false }.`,\n });\n }\n\n const wildcard = objectsMap['*'] as AnyRec | undefined;\n if (wildcard && (wildcard.viewAllRecords === true || wildcard.modifyAllRecords === true)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_WILDCARD_VAMA,\n where: `permission set \"${psName}\"`,\n path: `${psPath}.objects.*`,\n message:\n `'*' wildcard carrying View All / Modify All Data — a package-authored superuser. ` +\n `Only the platform's own admin set may combine the wildcard with VAMA (ADR-0066).`,\n hint:\n `Enumerate the objects this set really needs, or drop viewAllRecords/modifyAllRecords ` +\n `from the wildcard entry. App-level admins belong in an ordinary set the customer binds ` +\n `to a position of their choosing (ADR-0090 D9).`,\n });\n }\n\n // D5: an isDefault set is a SUGGESTED binding to the `everyone` anchor —\n // hold it to the anchor tier at author time (the runtime gate enforces the\n // same predicate at bind time; this moves the failure to the author).\n if (ps.isDefault === true) {\n const offending = describeAnchorForbiddenBits(ps, 'everyone');\n if (offending) {\n findings.push({\n severity: 'error',\n rule: SECURITY_ANCHOR_HIGH_PRIVILEGE,\n where: `permission set \"${psName}\"`,\n path: `${psPath}.isDefault`,\n message:\n `isDefault:true suggests binding this set to the 'everyone' audience anchor, but it ` +\n `carries ${offending} — the runtime will refuse the binding (ADR-0090 D5/D9).`,\n hint:\n `Split the powerful bits into a separate set granted through ordinary positions, and ` +\n `keep the everyone-suggested set low-privilege.`,\n });\n }\n }\n }\n\n // ── D3: the word \"role\" is reserved-forbidden ────────────────────────\n // Scope: security-relevant identifiers/labels (objects, fields, actions,\n // permission sets, positions, apps). Pages/views/components are NOT\n // scanned — `role` there is HTML/ARIA semantics, not permission vocabulary.\n // The sole platform exception (better-auth `sys_member.role`) is a system\n // object, which app stacks never author.\n const flagRole = (kind: string, name: unknown, label: unknown, where: string, path: string) => {\n if (identifierHasRoleToken(name)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_ROLE_WORD,\n where,\n path,\n message:\n `${kind} name \"${String(name)}\" uses the reserved word \"role\" — the platform vocabulary ` +\n `is permission_set (capability), position (distribution), business_unit (hierarchy) (ADR-0090 D3).`,\n hint: `Rename using 'position' for distribution groups or a domain word (e.g. 'function', 'duty').`,\n });\n } else if (labelHasRoleWord(label)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_ROLE_WORD,\n where,\n path: `${path.replace(/\\.name$/, '')}.label`,\n message: `${kind} label \"${String(label)}\" uses the reserved word \"role\" (ADR-0090 D3).`,\n hint: `Relabel with 'Position' (distribution) or a domain word — admins must meet ONE vocabulary.`,\n });\n }\n };\n\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object' || isSystemObject(obj)) continue;\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n flagRole('object', obj.name, obj.label, `object \"${objName}\"`, `objects[${i}].name`);\n for (const f of asArray(obj.fields)) {\n flagRole('field', f.name, f.label, `field \"${objName}.${String(f.name ?? '?')}\"`, `objects[${i}].fields.${String(f.name ?? '?')}.name`);\n }\n for (const [ai, action] of asArray(obj.actions).entries()) {\n flagRole('action', action.name, action.label, `action \"${objName}.${String(action.name ?? '?')}\"`, `objects[${i}].actions[${ai}].name`);\n }\n }\n for (let i = 0; i < permissionSets.length; i++) {\n const ps = permissionSets[i];\n if (!ps || typeof ps !== 'object') continue;\n flagRole('permission set', ps.name, ps.label, `permission set \"${String(ps.name ?? i)}\"`, `permissions[${i}].name`);\n }\n for (const [i, pos] of asArray(stack.positions).entries()) {\n flagRole('position', pos.name, pos.label, `position \"${String(pos.name ?? i)}\"`, `positions[${i}].name`);\n }\n for (const [i, app] of asArray(stack.apps).entries()) {\n flagRole('app', app.name, app.label, `app \"${String(app.name ?? i)}\"`, `apps[${i}].name`);\n }\n for (const [i, book] of asArray(stack.books).entries()) {\n // Books entered the security-relevant set when `book.audience` became a\n // permission-model reference (ADR-0046 §6.7 / ADR-0090): their names and\n // labels are access-adjacent UI copy.\n flagRole('book', book.name, book.label, `book \"${String(book.name ?? i)}\"`, `books[${i}].name`);\n }\n\n // ── Book audience → permission-set reference must resolve ────────────\n // A `{ permissionSet }` book audience names a set the reader must hold\n // (ADR-0046 §6.7). The runtime fails CLOSED on an unknown name (nobody\n // holds it → nobody reads the book), so a typo is not a leak — but it IS\n // the \"why can nobody see the Admin Guide\" support class, and packages\n // should gate their books on their own sets (ADR-0090 D9 / ADR-0086\n // provenance). Advisory: an environment-authored book may legitimately\n // reference an installed package's set that is not in THIS stack.\n const stackSetNames = new Set(\n permissionSets\n .map((ps) => (typeof ps.name === 'string' ? ps.name : undefined))\n .filter((n): n is string => !!n),\n );\n for (const [i, book] of asArray(stack.books).entries()) {\n const audience = (book as AnyRec).audience;\n if (!audience || typeof audience !== 'object') continue;\n const setName = (audience as AnyRec).permissionSet;\n if (typeof setName !== 'string' || setName.length === 0) continue;\n if (!stackSetNames.has(setName)) {\n findings.push({\n severity: 'warning',\n rule: SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,\n where: `book \"${String(book.name ?? i)}\"`,\n path: `books[${i}].audience.permissionSet`,\n message:\n `book audience references permission set \"${setName}\", which this stack does not declare. ` +\n `The runtime fails closed — no holder means NO reader can open the book.`,\n hint:\n `Gate the book on one of this package's own permission sets (ADR-0090 D9, e.g. its admin set), ` +\n `or fix the typo. Ignore if the set is intentionally provided by another installed package.`,\n });\n }\n }\n\n // ── Admin-intent mismatch: private object, plain read, no depth ──────\n // An object whose baseline is private (explicit or D1-defaulted) where a set\n // grants allowRead with neither readScope nor viewAllRecords: every reader\n // sees ONLY their own records. Legitimate (personal to-dos) often enough\n // that this stays `info` — but it is the #1 \"why can't 李四 see the data\"\n // support class, so say it out loud at author time.\n const privateObjects = new Set(\n objects\n .filter((o) => o && typeof o === 'object' && !isSystemObject(o))\n .filter((o) => {\n const owd = owdOf(o);\n return owd == null || owd === 'private';\n })\n .map((o) => String(o.name ?? '')),\n );\n if (privateObjects.size > 0) {\n for (let i = 0; i < permissionSets.length; i++) {\n const ps = permissionSets[i];\n if (!ps || typeof ps !== 'object') continue;\n const psName = typeof ps.name === 'string' ? ps.name : `(permission set ${i})`;\n const objectsMap = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n for (const [objName, rawPerm] of Object.entries(objectsMap)) {\n if (!privateObjects.has(objName)) continue;\n const p = (rawPerm ?? {}) as AnyRec;\n if (p.allowRead === true && p.readScope == null && p.viewAllRecords !== true) {\n findings.push({\n severity: 'info',\n rule: SECURITY_PRIVATE_NO_READSCOPE,\n where: `permission set \"${psName}\"`,\n path: `permissions[${i}].objects.${objName}.readScope`,\n message:\n `\"${objName}\" is private (OWD) and this set grants allowRead without a readScope — ` +\n `holders see ONLY records they own (plus explicit shares).`,\n hint:\n `If that is intended (personal data), ignore this. Otherwise add readScope: ` +\n `'own_and_reports' | 'unit' | 'unit_and_below' | 'org', or widen the object's sharingModel.`,\n });\n }\n }\n }\n }\n\n // ── ADR-0055: master-detail DETAIL object with no object-level CRUD ───\n // A master-detail CHILD derives its RECORD-level scope from the master\n // (`controlled_by_parent`) — but that is gate ②. Object-level CRUD is a\n // SEPARATE gate ① (`checkObjectPermission`) that is NEVER derived: a set that\n // lists the parent but forgets the child denies role-bound non-admin users a\n // 403 *before* the parent-derived access is ever consulted, surfacing as the\n // silent \"can't fill in / can't submit the subtable\" trap (framework#2700,\n // downstream os-tianshun-mtc#43). Statically detectable: a detail (has a\n // master_detail field) that NO authored permission set grants.\n //\n // Advisory `warning` — it does not gate the build. Two deliberate silences\n // keep the false-positive rate near zero: (a) if the package authors no\n // permission sets there is nothing to compare against, and (b) a package-\n // declared `'*'` wildcard grant is treated as covering every object (a broad\n // grant is an explicit choice — suppress rather than cry wolf). The residual\n // per-set gap (one role grants it, another forgets it) is intentionally out\n // of scope (issue #2700); the platform's own default admin set lives outside\n // the linted stack, so it never masks a package that forgot the child here.\n if (permissionSets.length > 0) {\n const wildcardGrantsAll = permissionSets.some((ps) =>\n grantsObjectAccess(((ps.objects as AnyRec | undefined)?.['*'] ?? {}) as AnyRec),\n );\n if (!wildcardGrantsAll) {\n const grantedObjects = new Set<string>();\n for (const ps of permissionSets) {\n const objectsMap = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n for (const [objName, rawPerm] of Object.entries(objectsMap)) {\n if (objName === '*') continue;\n if (grantsObjectAccess((rawPerm ?? {}) as AnyRec)) grantedObjects.add(objName);\n }\n }\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object' || isSystemObject(obj)) continue;\n const objName = typeof obj.name === 'string' ? obj.name : '';\n if (!objName || grantedObjects.has(objName)) continue;\n const md = firstMasterDetailField(obj);\n if (!md) continue;\n const parentText = md.parent ? ` → \"${md.parent}\"` : '';\n findings.push({\n severity: 'warning',\n rule: SECURITY_MASTER_DETAIL_UNGRANTED,\n where: `object \"${objName}\"`,\n path: `objects[${i}].fields.${md.name}`,\n message:\n `detail object \"${objName}\" (master_detail \"${md.name}\"${parentText}) has no object-level ` +\n `CRUD grant in any permission set. A master-detail child derives its RECORD-level access ` +\n `from the master (ADR-0055 controlled_by_parent), but object-level CRUD is a SEPARATE gate ` +\n `that is never derived — role-bound non-admin users are denied (403) before the ` +\n `parent-derived access is ever consulted (the silent \"can't submit the subtable\" trap).`,\n hint:\n `Grant \"${objName}\" in at least one permission set that already grants its master` +\n `${md.parent ? ` \"${md.parent}\"` : ''} — e.g. permissions[i].objects.${objName} = ` +\n `{ allowRead: true, allowCreate: true, allowEdit: true }. If no role should ever touch ` +\n `it (a pure system/internal table), name it sys_* or set isSystem: true.`,\n });\n }\n }\n }\n\n // ── ADR-0091: authored grant rows (seed data) — lifecycle sanity ──────\n // Grant assignments authored as seed data on the two user-grant tables.\n // Both rules mirror runtime enforcement (D2 resolution-time filtering; the\n // D3 delegation gate), per the ADR-0049 \"no advisory security\" discipline:\n // the lint moves the failure from silent-dead-grant to author-time fix-it.\n const GRANT_SEED_OBJECTS = new Set(['sys_user_position', 'sys_user_permission_set']);\n const nowMs = opts?.nowMs ?? Date.now();\n for (const [i, seed] of asArray(stack.data).entries()) {\n const seedObject = typeof seed.object === 'string' ? seed.object : '';\n if (!GRANT_SEED_OBJECTS.has(seedObject)) continue;\n const records = Array.isArray(seed.records) ? (seed.records as AnyRec[]) : [];\n for (let j = 0; j < records.length; j++) {\n const rec = (records[j] ?? {}) as AnyRec;\n const where = `seed \"${seedObject}\" record #${j}`;\n\n // D2: a valid_until already in the past (or unparseable) at authoring\n // time is a grant that will NEVER resolve — dead on arrival, fail-closed.\n const until = rec.valid_until;\n if (until != null && until !== '') {\n const ms =\n typeof until === 'number'\n ? (until < 1e12 ? until * 1000 : until)\n : until instanceof Date\n ? until.getTime()\n : typeof until === 'string'\n ? Date.parse(until)\n : Number.NaN;\n if (Number.isNaN(ms) || ms <= nowMs) {\n findings.push({\n severity: 'error',\n rule: SECURITY_GRANT_EXPIRED_AT_AUTHORING,\n where,\n path: `data[${i}].records[${j}].valid_until`,\n message: Number.isNaN(ms)\n ? `valid_until ${JSON.stringify(until)} is not a parseable timestamp — the resolver fails ` +\n `closed (ADR-0091 D2), so this grant will NEVER be active.`\n : `valid_until ${JSON.stringify(until)} is already in the past — this grant is expired at ` +\n `authoring time and will never resolve (ADR-0091 D2 filters it fail-closed).`,\n hint:\n `Set valid_until to a future instant (ISO-8601 UTC), or drop the column for an unbounded ` +\n `grant. If the row is a historical record, it belongs in audit history, not seed data.`,\n });\n }\n }\n\n // D3: delegation rows (delegated_from set) MUST carry a reason — the\n // dual-audit half the runtime gate also rejects.\n const delegatedFrom = rec.delegated_from;\n if (delegatedFrom != null && delegatedFrom !== '') {\n const reason = rec.reason;\n if (typeof reason !== 'string' || reason.trim().length === 0) {\n findings.push({\n severity: 'error',\n rule: SECURITY_DELEGATION_MISSING_REASON,\n where,\n path: `data[${i}].records[${j}].reason`,\n message:\n `delegation row (delegated_from = ${JSON.stringify(delegatedFrom)}) has no reason. ` +\n `ADR-0091 D3 requires a mandatory reason on every delegation for the dual audit trail ` +\n `(granted_by = writer, delegated_from = authority source, reason = why).`,\n hint: `Add reason: 'vacation stand-in for 张三, 2026-08-01..15' (free text, required).`,\n });\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0049 — references] Reference-integrity for dashboard header & widget\n * action targets (issue #3367).\n *\n * ADR-0049 established the \"enforce-or-remove\" gate for spec *properties*: a\n * declared property the runtime does not honour is a false promise and must be\n * enforced, marked experimental, or removed. This rule applies the SAME honesty\n * principle to *references*. A dashboard header action (or a widget's header\n * action button) names a target — a `script`/`modal` action, or a `url` route —\n * that must actually resolve. A dangling target ships a button that renders and,\n * on click, silently does nothing: a false affordance, exactly the failure\n * ADR-0049 exists to prevent, just for a reference rather than a property.\n *\n * Nothing in the protocol schema can express this: `actionUrl` is a free string,\n * so `{ actionType: 'script', actionUrl: 'export_dashboard_pdf' }` parses and\n * ships even when no such action is defined anywhere in the stack.\n *\n * Surfaces checked:\n * - dashboard `header.actions[]` — each `{ actionType, actionUrl }`\n * - dashboard `widgets[].actionUrl` (+ `actionType`) — the per-widget button\n *\n * Resolution mirrors the objectui runtime dispatch (`DashboardRenderer` +\n * `DashboardView`) so the lint flags exactly what would fail to resolve at\n * runtime:\n *\n * actionType 'script' → `actionUrl` must name a DEFINED action (`stack.actions`\n * or any `object.actions`, by `name`). A script target that names no\n * defined action fails open at runtime (\"action not found\"). → ERROR.\n *\n * actionType 'modal' → `actionUrl` resolves if it names a defined action, OR\n * matches the runtime `<verb>_<object>` convention the modalHandler\n * implements (create_/new_/add_/edit_/update_ + a defined object), OR is a\n * bare defined object name (the handler falls back to that object's create\n * form). Otherwise → ERROR.\n *\n * actionType 'url' → a relative in-app path. WARN when a recognizable\n * `<collection>/<name>` segment (objects/reports/dashboards/pages/views)\n * names an entity that does not exist in this stack. External URLs\n * (`http(s)://`, `//`), interpolated targets (`${…}`), and opaque routes\n * (no recognized collection segment) are skipped — they cannot be resolved\n * statically and may be host/app/plugin routes. → WARNING.\n *\n * actionType 'flow' | 'api' — not checked: flow targets resolve against the\n * automation engine / other packages, and api targets are opaque endpoints.\n * Out of scope for #3367.\n *\n * Severity split follows the issue's acceptance criteria: an undefined\n * `script`/`modal` target FAILS validation (a genuine dead reference that fails\n * open at runtime as a dead button); an unresolved `url` route is advisory\n * (route resolution is app-context-dependent, and a path may be served by\n * another installed package or a host/console route). External, interpolated,\n * convention, and opaque targets are exempted to keep false positives near zero\n * — the same conservative posture as the sibling `lint-view-refs` and\n * `validate-capability-references` rules.\n */\n\nexport const DASHBOARD_ACTION_TARGET_UNDEFINED = 'dashboard-action-target-undefined';\nexport const DASHBOARD_ACTION_ROUTE_UNRESOLVED = 'dashboard-action-route-unresolved';\n\nexport type DashboardActionRefSeverity = 'error' | 'warning';\n\nexport interface DashboardActionRefFinding {\n /** `error` for a dangling script/modal action; `warning` for an unresolved url route. */\n severity: DashboardActionRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `dashboard \"sales_overview\" · header action \"Export PDF\"`. */\n where: string;\n /** Config path, e.g. `dashboards[2].header.actions[0].actionUrl`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records, injecting\n * `name` from the map key — mirrors the helper in the sibling authoring lints so\n * the rule works on both the parsed (array) and normalized (map) stack shapes. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/** The runtime modal `<verb>_<object>` convention (objectui `DashboardView`\n * modalHandler): `create_/new_/add_/edit_/update_` + an object name opens that\n * object's create/edit form. */\nconst MODAL_VERB_RE = /^(?:create|new|add|edit|update)_(.+)$/;\n\n/** URL path segments that name a metadata collection, mapped to the stack key\n * whose members can appear after them in an in-app route\n * (`/…/objects/crm_lead`, `/reports/forecast`, `/dashboards/exec`, …). Both the\n * singular and plural spellings are accepted. */\nconst URL_COLLECTION_TO_STACK_KEY: Record<string, 'objects' | 'reports' | 'dashboards' | 'pages' | 'views'> = {\n object: 'objects',\n objects: 'objects',\n report: 'reports',\n reports: 'reports',\n dashboard: 'dashboards',\n dashboards: 'dashboards',\n page: 'pages',\n pages: 'pages',\n view: 'views',\n views: 'views',\n};\n\n/** Derive the name a top-level `views` container registers under (mirrors the\n * runtime loader's `resolveMetadataItemName('views', …)` fallbacks). */\nfunction viewContainerName(item: AnyRec): string | undefined {\n return (\n strName(item.name) ??\n strName(item.id) ??\n strName(item.object) ??\n strName((item.list as AnyRec | undefined)?.data && ((item.list as AnyRec).data as AnyRec).object) ??\n strName((item.form as AnyRec | undefined)?.data && ((item.form as AnyRec).data as AnyRec).object)\n );\n}\n\ninterface KnownTargets {\n /** Every action name defined in the stack (global + object-embedded). */\n actions: Set<string>;\n /** Object names (also valid as bare modal targets and `objects/<name>` routes). */\n objects: Set<string>;\n reports: Set<string>;\n dashboards: Set<string>;\n pages: Set<string>;\n /** View names routable as `views/<name>` — container names plus object names. */\n views: Set<string>;\n}\n\n/** Build the author-time \"known target\" sets from a stack. */\nfunction collectKnownTargets(stack: AnyRec): KnownTargets {\n const actions = new Set<string>();\n const objects = new Set<string>();\n const reports = new Set<string>();\n const dashboards = new Set<string>();\n const pages = new Set<string>();\n const views = new Set<string>();\n\n const collectNames = (v: unknown, into: Set<string>, name: (rec: AnyRec) => string | undefined) => {\n for (const item of asArray(v)) {\n if (!item || typeof item !== 'object') continue;\n const n = name(item);\n if (n) into.add(n);\n }\n };\n\n collectNames(stack.actions, actions, (a) => strName(a.name));\n for (const obj of asArray(stack.objects)) {\n if (!obj || typeof obj !== 'object') continue;\n const n = strName(obj.name);\n if (n) objects.add(n);\n collectNames(obj.actions, actions, (a) => strName(a.name));\n }\n collectNames(stack.reports, reports, (r) => strName(r.name));\n collectNames(stack.dashboards, dashboards, (d) => strName(d.name));\n collectNames(stack.pages, pages, (p) => strName(p.name));\n collectNames(stack.views, views, viewContainerName);\n // An object's default view is routable by the object's own name too.\n for (const o of objects) views.add(o);\n\n return { actions, objects, reports, dashboards, pages, views };\n}\n\n/** Does a `script`/`modal` `actionUrl` resolve? */\nfunction resolveActionTarget(\n actionType: 'script' | 'modal',\n target: string,\n known: KnownTargets,\n): boolean {\n if (known.actions.has(target)) return true;\n if (actionType === 'modal') {\n // Runtime modalHandler convention: `<verb>_<object>` or a bare object name\n // opens that object's create/edit form.\n if (known.objects.has(target)) return true;\n const m = MODAL_VERB_RE.exec(target);\n if (m && known.objects.has(m[1])) return true;\n }\n return false;\n}\n\n/**\n * Resolve a relative `url` in-app route. Returns:\n * - `null` when the target is not statically resolvable (external, interpolated,\n * or carries no recognized `<collection>/<name>` segment) — SKIP, no finding.\n * - `{ collection, name }` for a recognized `<collection>/<name>` pair that does\n * NOT exist in the stack — WARN.\n * - `undefined` when a recognized pair DID resolve — OK, no finding.\n */\nfunction resolveUrlRoute(\n target: string,\n known: KnownTargets,\n): { collection: string; name: string } | null | undefined {\n // External / protocol-relative — leaves the app; not an in-app route.\n if (/^[a-z][a-z0-9+.-]*:\\/\\//i.test(target) || target.startsWith('//')) return null;\n // Interpolated — resolved by the renderer at click time, not statically known.\n if (target.includes('${')) return null;\n // Only relative in-app paths are considered.\n if (!target.startsWith('/')) return null;\n\n // Strip query + hash, then split into non-empty segments.\n const pathPart = target.split(/[?#]/, 1)[0];\n const segments = pathPart.split('/').filter(Boolean);\n\n for (let i = 0; i < segments.length - 1; i++) {\n const stackKey = URL_COLLECTION_TO_STACK_KEY[segments[i]];\n if (!stackKey) continue;\n const name = segments[i + 1];\n if (known[stackKey].has(name)) return undefined; // resolved\n return { collection: segments[i], name }; // recognized shape, unknown name\n }\n return null; // no recognized collection segment — opaque route, skip\n}\n\ninterface HeaderAction {\n actionType?: string;\n actionUrl?: string;\n label?: string;\n}\n\n/**\n * Validate every dashboard header / widget action reference in a stack. Returns\n * findings (empty = clean). `script`/`modal` dead targets are errors; `url`\n * unresolved routes are warnings.\n */\nexport function validateDashboardActionRefs(stack: AnyRec): DashboardActionRefFinding[] {\n const findings: DashboardActionRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const dashboards = asArray(stack.dashboards);\n if (dashboards.length === 0) return findings;\n\n const known = collectKnownTargets(stack);\n\n const checkOne = (\n action: HeaderAction,\n where: string,\n path: string,\n ) => {\n const target = strName(action.actionUrl);\n if (!target) return; // nothing referenced (widget with no action button)\n if (target.includes('${')) return; // dynamic target — not statically resolvable\n\n // Renderer default: a missing actionType is treated as a 'url' navigation\n // (DashboardRenderer builds header ActionDefs with `type: actionType || 'url'`).\n const actionType = strName(action.actionType) ?? 'url';\n\n if (actionType === 'script' || actionType === 'modal') {\n if (resolveActionTarget(actionType, target, known)) return;\n const kindWord = actionType === 'script' ? 'script' : 'modal';\n findings.push({\n severity: 'error',\n rule: DASHBOARD_ACTION_TARGET_UNDEFINED,\n where,\n path,\n message:\n `${kindWord} action target \"${target}\" resolves to no defined action` +\n (actionType === 'modal' ? ' or object' : '') +\n `. The button renders but does nothing when clicked — a dangling reference ` +\n `the runtime cannot dispatch (ADR-0049: a declared reference must resolve).`,\n hint:\n actionType === 'modal'\n ? `Define an action named \"${target}\" (stack.actions or the object's actions), ` +\n `use the \"<verb>_<object>\" convention against a real object ` +\n `(e.g. \"create_<object>\"), point actionUrl at an existing object, or remove the button.`\n : `Define a script action named \"${target}\" (stack.actions or the object's actions) ` +\n `with an inline body or a registered handler, or remove the button.`,\n });\n return;\n }\n\n if (actionType === 'url') {\n const route = resolveUrlRoute(target, known);\n if (!route) return; // skip (external/interpolated/opaque) or resolved\n findings.push({\n severity: 'warning',\n rule: DASHBOARD_ACTION_ROUTE_UNRESOLVED,\n where,\n path,\n message:\n `url action target \"${target}\" points at ${route.collection}/${route.name}, ` +\n `but no ${route.collection.replace(/s$/, '')} named \"${route.name}\" is registered ` +\n `in this stack — the button likely navigates to a dead route.`,\n hint:\n `Check the path for a typo, define the referenced ${route.collection.replace(/s$/, '')}, ` +\n `or ignore this if the route is served by another installed package or a host/console route.`,\n });\n return;\n }\n // 'flow' | 'api' | custom types are out of scope (see module header).\n };\n\n for (let di = 0; di < dashboards.length; di++) {\n const dash = dashboards[di];\n if (!dash || typeof dash !== 'object') continue;\n const dashName = strName(dash.name) ?? `(dashboard ${di})`;\n const dashPath = `dashboards[${di}]`;\n\n // Header actions.\n const headerActions = asArray((dash.header as AnyRec | undefined)?.actions);\n for (let ai = 0; ai < headerActions.length; ai++) {\n const action = headerActions[ai] as HeaderAction | null;\n if (!action || typeof action !== 'object') continue;\n const label = strName(action.label) ?? strName(action.actionUrl) ?? `#${ai}`;\n checkOne(\n action,\n `dashboard \"${dashName}\" · header action \"${label}\"`,\n `${dashPath}.header.actions[${ai}].actionUrl`,\n );\n }\n\n // Per-widget action buttons.\n const widgets = asArray(dash.widgets);\n for (let wi = 0; wi < widgets.length; wi++) {\n const widget = widgets[wi];\n if (!widget || typeof widget !== 'object') continue;\n if (!strName(widget.actionUrl)) continue;\n const widgetId = strName(widget.id) ?? `#${wi}`;\n checkOne(\n { actionType: widget.actionType as string | undefined, actionUrl: widget.actionUrl as string | undefined },\n `dashboard \"${dashName}\" · widget \"${widgetId}\" action`,\n `${dashPath}.widgets[${wi}].actionUrl`,\n );\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0090 D6] Access-matrix snapshot — authoring-time companion to the\n * runtime explain engine.\n *\n * `buildAccessMatrix(stack)` derives, PURELY from metadata, one row per\n * (permission set × object) the stack declares: the CRUD/VAMA bits, the\n * depth axes, and the object's OWD for context. The matrix is snapshotted to\n * `access-matrix.json` and diffed on every compile: an unchanged matrix\n * auto-passes; a changed one fails the build until the snapshot is updated —\n * so every capability change becomes a REVIEWABLE, semantic diff\n * (\"`crm_admin` gains delete on `crm_lead`\") instead of a buried JSON hunk.\n * This is the publish-gate substrate the AI-authoring safety story needs:\n * AI may draft grants freely; it cannot silently change who can do what.\n */\n\nimport type { AccessMatrix, AccessMatrixEntry } from '@objectstack/spec/security';\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** Build the sorted access matrix for a normalized stack. */\nexport function buildAccessMatrix(stack: AnyRec): AccessMatrix {\n const entries: AccessMatrixEntry[] = [];\n if (!stack || typeof stack !== 'object') return { version: 1, entries };\n\n const owdByObject = new Map<string, string>();\n for (const obj of asArray(stack.objects)) {\n const name = typeof obj.name === 'string' ? obj.name : '';\n if (!name) continue;\n const owd = (obj.sharingModel ?? (obj.security as AnyRec | undefined)?.sharingModel) as string | undefined;\n if (typeof owd === 'string') owdByObject.set(name, owd);\n }\n\n for (const ps of asArray(stack.permissions)) {\n const psName = typeof ps.name === 'string' ? ps.name : '';\n if (!psName) continue;\n const objects = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n for (const [objName, rawPerm] of Object.entries(objects)) {\n const p = (rawPerm ?? {}) as AnyRec;\n const entry: AccessMatrixEntry = {\n permissionSet: psName,\n object: objName,\n create: p.allowCreate === true,\n read: p.allowRead === true || p.viewAllRecords === true || p.modifyAllRecords === true,\n edit: p.allowEdit === true || p.modifyAllRecords === true,\n delete: p.allowDelete === true || p.modifyAllRecords === true,\n viewAllRecords: p.viewAllRecords === true,\n modifyAllRecords: p.modifyAllRecords === true,\n };\n if (typeof p.readScope === 'string') entry.readScope = p.readScope;\n if (typeof p.writeScope === 'string') entry.writeScope = p.writeScope;\n const owd = owdByObject.get(objName);\n if (owd) entry.sharingModel = owd;\n entries.push(entry);\n }\n }\n\n entries.sort((a, b) =>\n a.permissionSet === b.permissionSet\n ? a.object.localeCompare(b.object)\n : a.permissionSet.localeCompare(b.permissionSet),\n );\n return { version: 1, entries };\n}\n\nconst BIT_LABELS: Array<[keyof AccessMatrixEntry, string]> = [\n ['create', 'create'],\n ['read', 'read'],\n ['edit', 'edit'],\n ['delete', 'delete'],\n ['viewAllRecords', 'View All Data'],\n ['modifyAllRecords', 'Modify All Data'],\n];\n\n/**\n * Semantic diff between two matrices — human-review lines, empty = identical.\n * Ordered: removals, additions, then per-entry bit/scope changes.\n */\nexport function diffAccessMatrix(before: AccessMatrix, after: AccessMatrix): string[] {\n const lines: string[] = [];\n const key = (e: AccessMatrixEntry) => `${e.permissionSet}\\u0000${e.object}`;\n const beforeMap = new Map((before?.entries ?? []).map((e) => [key(e), e]));\n const afterMap = new Map((after?.entries ?? []).map((e) => [key(e), e]));\n\n for (const [k, b] of beforeMap) {\n if (!afterMap.has(k)) {\n lines.push(`'${b.permissionSet}' loses ALL access to '${b.object}' (entry removed)`);\n }\n }\n for (const [k, a] of afterMap) {\n const b = beforeMap.get(k);\n if (!b) {\n const grants = BIT_LABELS.filter(([bit]) => a[bit] === true).map(([, label]) => label);\n lines.push(`'${a.permissionSet}' gains access to '${a.object}' (${grants.join(', ') || 'no bits set'})`);\n continue;\n }\n for (const [bit, label] of BIT_LABELS) {\n if (b[bit] !== a[bit]) {\n lines.push(`'${a.permissionSet}' ${a[bit] ? 'gains' : 'loses'} ${label} on '${a.object}'`);\n }\n }\n if ((b.readScope ?? 'own') !== (a.readScope ?? 'own')) {\n lines.push(`'${a.permissionSet}' read depth on '${a.object}': ${b.readScope ?? 'own'} → ${a.readScope ?? 'own'}`);\n }\n if ((b.writeScope ?? 'own') !== (a.writeScope ?? 'own')) {\n lines.push(`'${a.permissionSet}' write depth on '${a.object}': ${b.writeScope ?? 'own'} → ${a.writeScope ?? 'own'}`);\n }\n if ((b.sharingModel ?? '') !== (a.sharingModel ?? '')) {\n lines.push(`'${a.object}' record baseline (OWD): ${b.sharingModel ?? '(unset)'} → ${a.sharingModel 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IAAI,EAAE,MAAM,4BAA4B,EAAE,gBAAgB,SAAS,WAAM,EAAE,gBAAgB,SAAS,4BAA4B;AAAA,IAC7I;AAAA,EACF;AACA,SAAO;AACT;","names":["asArray","asArray","asArray","asArray","asArray","asArray","import_node_module","import_meta","asArray","asArray","import_data","asArray","asArray","asArray","asArray","asArray","asArray","import_security","asArray","asArray","asArray"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/validate-widget-bindings.ts","../src/system-fields.ts","../src/validate-expressions.ts","../src/validate-list-view-mode.ts","../src/validate-flow-trigger-readiness.ts","../src/flow-walk.ts","../src/validate-flow-template-paths.ts","../src/validate-readonly-flow-writes.ts","../src/validate-view-containers.ts","../src/validate-responsive-styles.ts","../src/validate-jsx-pages.ts","../src/validate-react-pages.ts","../src/validate-react-page-props.ts","../src/validate-searchable-fields.ts","../src/page-walk.ts","../src/validate-page-field-bindings.ts","../src/validate-page-source-styling.ts","../src/validate-record-title.ts","../src/validate-semantic-roles.ts","../src/validate-form-layout.ts","../src/validate-visibility-predicates.ts","../src/validate-capability-references.ts","../src/validate-approval-approvers.ts","../src/validate-seed-replay-safety.ts","../src/validate-seed-state-machine.ts","../src/validate-security-posture.ts","../src/validate-org-axis-red-lines.ts","../src/validate-dashboard-action-refs.ts","../src/validate-filter-tokens.ts","../src/validate-object-references.ts","../src/validate-action-name-refs.ts","../src/validate-chart-bindings.ts","../src/validate-nav-access.ts","../src/build-access-matrix.ts","../src/validate-translation-references.ts","../src/validate-ai-surface-affinity.ts","../src/validate-ai-tool-references.ts","../src/validate-ai-agent-authoring.ts","../src/validate-hook-body-writes.ts","../src/validate-action-body-writes.ts","../src/validate-flow-node-writes.ts","../src/reference-integrity-suite.ts"],"sourcesContent":["// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// @objectstack/lint — public API.\n//\n// Static, build-time validation over an ObjectStack metadata graph. Every rule\n// is a pure `(stack) => Finding[]` function: no I/O, no runtime, no filesystem\n// — it operates on an in-memory, schema-parsed stack object. Shared by the\n// CLI's `os validate`/`compile` AND any other consumer (e.g. AI authoring) so\n// hand-authored and generated apps are held to the same bar (ADR-0019).\n//\n// Dependency direction is one-way: lint → @objectstack/spec (the contract).\n// It never depends on a runtime, and it is never bundled into a frontend.\n\nexport {\n validateWidgetBindings,\n WIDGET_DATASET_UNKNOWN,\n WIDGET_DIMENSION_UNKNOWN,\n WIDGET_MEASURE_UNKNOWN,\n CHART_FIELD_UNKNOWN,\n CHART_CONFIG_MISSING,\n TABLE_COUNT_ONLY,\n MEASURE_AGGREGATE_INCOHERENT,\n DASHBOARD_FILTER_FIELD_UNKNOWN,\n} from './validate-widget-bindings.js';\nexport type { WidgetBindingFinding, WidgetBindingSeverity } from './validate-widget-bindings.js';\n\nexport { validateStackExpressions } from './validate-expressions.js';\nexport type { ExprIssue } from './validate-expressions.js';\n\nexport { validateListViewMode, LIST_VIEW_FILTERS_IN_VIEWS_MODE } from './validate-list-view-mode.js';\nexport type { ListViewModeFinding, ListViewModeSeverity } from './validate-list-view-mode.js';\nexport {\n validateFlowTriggerReadiness,\n FLOW_TRIGGER_UNKNOWN_OBJECT,\n FLOW_DRAFT_STATUS_AMBIGUOUS,\n} from './validate-flow-trigger-readiness.js';\nexport type {\n FlowTriggerReadinessFinding,\n FlowTriggerReadinessSeverity,\n} from './validate-flow-trigger-readiness.js';\n\nexport {\n validateFlowTemplatePaths,\n FLOW_TEMPLATE_UNKNOWN_FIELD,\n FLOW_TEMPLATE_LOOKUP_TRAVERSAL,\n} from './validate-flow-template-paths.js';\nexport type {\n FlowTemplatePathFinding,\n FlowTemplatePathSeverity,\n} from './validate-flow-template-paths.js';\n\nexport {\n validateReadonlyFlowWrites,\n FLOW_UPDATE_READONLY_FIELD,\n FLOW_UPDATE_READONLY_WHEN_FIELD,\n} from './validate-readonly-flow-writes.js';\nexport type {\n ReadonlyFlowWriteFinding,\n ReadonlyFlowWriteSeverity,\n} from './validate-readonly-flow-writes.js';\n\nexport { validateViewContainers, VIEW_CONTAINER_SHAPE } from './validate-view-containers.js';\nexport type { ViewContainerFinding, ViewContainerSeverity } from './validate-view-containers.js';\n\nexport {\n validateResponsiveStyles,\n STYLE_NODE_MISSING_ID,\n STYLE_CLASSNAME_TAILWIND,\n STYLE_RESPONSIVE_NO_BASE,\n STYLE_UNKNOWN_CSS_PROPERTY,\n STYLE_UNKNOWN_TOKEN,\n} from './validate-responsive-styles.js';\nexport type { StyleFinding, StyleSeverity } from './validate-responsive-styles.js';\nexport { validateJsxPages } from './validate-jsx-pages.js';\nexport type { JsxPageFinding, JsxPageSeverity } from './validate-jsx-pages.js';\nexport { validateReactPages } from './validate-react-pages.js';\nexport type { ReactPageFinding, ReactPageSeverity } from './validate-react-pages.js';\nexport {\n validateReactPageProps,\n REACT_CHART_FIELD_UNKNOWN,\n REACT_CHART_AGGREGATE_INVALID,\n REACT_CHART_AXIS_UNKNOWN,\n} from './validate-react-page-props.js';\nexport type { ReactPropFinding, ReactPropSeverity } from './validate-react-page-props.js';\nexport { validatePageSourceStyling, PAGE_SOURCE_CLASSNAME } from './validate-page-source-styling.js';\nexport type { SourceStyleFinding, SourceStyleSeverity } from './validate-page-source-styling.js';\n\nexport {\n validateRecordTitle,\n TITLE_FORMAT_RETIRED,\n TITLE_UNRESOLVABLE,\n} from './validate-record-title.js';\nexport type { RecordTitleFinding, RecordTitleSeverity } from './validate-record-title.js';\n\nexport {\n validateSemanticRoles,\n FIELD_GROUP_UNDECLARED,\n FIELD_GROUP_EMPTY,\n SEMANTIC_ROLE_FIELD_UNKNOWN,\n} from './validate-semantic-roles.js';\nexport type { SemanticRoleFinding, SemanticRoleSeverity } from './validate-semantic-roles.js';\n\nexport {\n validateFormLayout,\n FORM_FIELD_UNKNOWN,\n FORM_COLSPAN_ABSOLUTE,\n} from './validate-form-layout.js';\nexport type { FormLayoutFinding, FormLayoutSeverity } from './validate-form-layout.js';\n\nexport {\n validateVisibilityPredicates,\n VISIBILITY_ALIAS_DEPRECATED,\n VISIBILITY_ROOT_MISLAYERED,\n} from './validate-visibility-predicates.js';\nexport type {\n VisibilityFinding,\n VisibilitySeverity,\n VisibilityLayer,\n VisibilityOptions,\n} from './validate-visibility-predicates.js';\n\nexport {\n validateCapabilityReferences,\n CAPABILITY_REFERENCE_UNKNOWN,\n} from './validate-capability-references.js';\nexport type { CapabilityRefFinding, CapabilityRefSeverity } from './validate-capability-references.js';\n\nexport {\n validateApprovalApprovers,\n APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER,\n APPROVAL_APPROVER_TYPE_DEPRECATED,\n APPROVAL_APPROVER_TYPE_UNKNOWN,\n APPROVAL_ESCALATION_REASSIGN_NO_TARGET,\n APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY,\n APPROVAL_EXPRESSION_INVALID,\n APPROVAL_EXPRESSION_NO_EMPTY_POLICY,\n APPROVAL_DECISION_OUTPUTS_RESERVED,\n APPROVAL_APPROVER_CROSS_ORG_UNSUPPORTED,\n} from './validate-approval-approvers.js';\nexport type { ApprovalApproverFinding, ApprovalApproverSeverity } from './validate-approval-approvers.js';\n\nexport {\n validateSeedReplaySafety,\n SEED_INSERT_MODE_DUPLICATES_ON_REPLAY,\n} from './validate-seed-replay-safety.js';\nexport type { SeedReplaySafetyFinding, SeedReplaySafetySeverity } from './validate-seed-replay-safety.js';\n\nexport {\n validateSeedStateMachine,\n SEED_VALUE_OUTSIDE_STATE_MACHINE,\n} from './validate-seed-state-machine.js';\nexport type { SeedStateMachineFinding, SeedStateMachineSeverity } from './validate-seed-state-machine.js';\n\nexport {\n validateSecurityPosture,\n SECURITY_OWD_UNSET,\n SECURITY_OWD_ALIAS,\n SECURITY_EXTERNAL_WIDER,\n SECURITY_WILDCARD_VAMA,\n SECURITY_ANCHOR_HIGH_PRIVILEGE,\n SECURITY_ROLE_WORD,\n SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,\n SECURITY_PRIVATE_NO_READSCOPE,\n SECURITY_MASTER_DETAIL_UNGRANTED,\n SECURITY_GRANT_EXPIRED_AT_AUTHORING,\n SECURITY_DELEGATION_MISSING_REASON,\n} from './validate-security-posture.js';\nexport type { SecurityFinding, SecuritySeverity } from './validate-security-posture.js';\n\nexport {\n validateOrgAxisRedLines,\n ORG_AXIS_PERMISSION_INHERITANCE,\n ORG_AXIS_CROSS_ORG_BU_GRANT,\n} from './validate-org-axis-red-lines.js';\nexport type { OrgAxisFinding, OrgAxisSeverity } from './validate-org-axis-red-lines.js';\n\nexport {\n validateDashboardActionRefs,\n DASHBOARD_ACTION_TARGET_UNDEFINED,\n DASHBOARD_ACTION_ROUTE_UNRESOLVED,\n} from './validate-dashboard-action-refs.js';\nexport type {\n DashboardActionRefFinding,\n DashboardActionRefSeverity,\n} from './validate-dashboard-action-refs.js';\n\nexport { validateFilterTokens, FILTER_TOKEN_UNKNOWN } from './validate-filter-tokens.js';\nexport type { FilterTokenFinding, FilterTokenSeverity } from './validate-filter-tokens.js';\n\nexport {\n validateObjectReferences,\n OBJECT_REFERENCE_UNKNOWN,\n OBJECT_REFERENCE_UNREGISTERED_PLATFORM,\n} from './validate-object-references.js';\nexport type { ObjectRefFinding, ObjectRefSeverity } from './validate-object-references.js';\n\nexport {\n validateSearchableFields,\n SEARCHABLE_FIELD_UNKNOWN,\n} from './validate-searchable-fields.js';\nexport type {\n SearchableFieldFinding,\n SearchableFieldSeverity,\n} from './validate-searchable-fields.js';\n\nexport { validateActionNameRefs, ACTION_NAME_UNDEFINED } from './validate-action-name-refs.js';\nexport type { ActionNameRefFinding, ActionNameRefSeverity } from './validate-action-name-refs.js';\n\nexport { validatePageFieldBindings, PAGE_FIELD_UNKNOWN } from './validate-page-field-bindings.js';\nexport type { PageFieldFinding, PageFieldSeverity } from './validate-page-field-bindings.js';\n\nexport {\n validateChartBindings,\n CHART_DIMENSION_UNKNOWN,\n CHART_MEASURE_UNKNOWN,\n CHART_DATASET_UNKNOWN,\n CHART_AXIS_NOT_SELECTED,\n} from './validate-chart-bindings.js';\nexport type { ChartBindingFinding, ChartBindingSeverity } from './validate-chart-bindings.js';\n\nexport { validateNavAccess, NAV_OBJECT_UNGRANTED } from './validate-nav-access.js';\nexport type { NavAccessFinding, NavAccessSeverity } from './validate-nav-access.js';\n\nexport {\n validateTranslationReferences,\n TRANSLATION_TARGET_UNKNOWN,\n TRANSLATION_OPTION_KEY_UNKNOWN,\n} from './validate-translation-references.js';\nexport type {\n TranslationRefFinding,\n TranslationRefSeverity,\n} from './validate-translation-references.js';\n\nexport {\n validateAiSurfaceAffinity,\n AI_SKILL_SURFACE_MISMATCH,\n} from './validate-ai-surface-affinity.js';\nexport type {\n AiSurfaceAffinityFinding,\n AiSurfaceAffinitySeverity,\n} from './validate-ai-surface-affinity.js';\n\nexport {\n validateAiToolReferences,\n AI_SKILL_TOOL_UNRESOLVED,\n} from './validate-ai-tool-references.js';\nexport type {\n AiToolRefFinding,\n AiToolRefSeverity,\n} from './validate-ai-tool-references.js';\n\nexport {\n validateAiAgentAuthoring,\n AGENT_AUTHORING_WITHDRAWN,\n} from './validate-ai-agent-authoring.js';\nexport type {\n AiAgentAuthoringFinding,\n AiAgentAuthoringSeverity,\n} from './validate-ai-agent-authoring.js';\n\nexport {\n validateHookBodyWrites,\n extractHookBodyWrites,\n extractHookBodyWriteSet,\n HOOK_BODY_WRITE_PATTERNS,\n HOOK_BODY_WRITE_PATTERN_IDS,\n HOOK_BODY_WRITE_EXCLUSIONS,\n HOOK_BODY_WRITE_UNKNOWN_FIELD,\n} from './validate-hook-body-writes.js';\nexport type {\n HookBodyWriteFinding,\n HookBodyWriteSeverity,\n HookBodyWritePattern,\n BodyWritePatternExclusion,\n ExtractedHookBodyWrite,\n ExtractedHookBodyWriteSet,\n} from './validate-hook-body-writes.js';\n\n// The same write-set check on action bodies — same schema, same sandbox, same\n// silent no-op. Its ledger is a declared partition of HOOK_BODY_WRITE_PATTERNS\n// (only the `ctx.api` family survives the context change), so the two rules\n// share one extractor rather than growing two.\nexport {\n validateActionBodyWrites,\n ACTION_BODY_WRITE_PATTERNS,\n ACTION_BODY_WRITE_PATTERN_IDS,\n ACTION_RECORD_WRITE_PATTERNS,\n ACTION_RECORD_WRITE_PATTERN_IDS,\n ACTION_BODY_WRITE_EXCLUSIONS,\n ACTION_BODY_WRITE_UNKNOWN_FIELD,\n ACTION_RECORD_WRITE_DISCARDED,\n} from './validate-action-body-writes.js';\nexport type {\n ActionBodyWriteFinding,\n ActionBodyWriteSeverity,\n ActionBodyWriteExclusion,\n} from './validate-action-body-writes.js';\n\n// The same write-set question on the third surface — a flow `update_record`\n// node's structural `config.fields`. Shares the hook rule's field index and\n// implicit-field set so all three agree on what is writable without being\n// authored; gates (`error`) rather than advising, because a literal key against\n// a literal object name is a certainty the parsed-JS rules cannot claim.\nexport {\n validateFlowNodeWrites,\n FLOW_NODE_WRITE_UNKNOWN_FIELD,\n FLOW_WRITE_NODE_TYPES,\n FLOW_WRITE_NODE_TYPES_DEFERRED,\n} from './validate-flow-node-writes.js';\nexport type {\n FlowNodeWriteFinding,\n FlowNodeWriteSeverity,\n FlowWriteNodeDeferral,\n} from './validate-flow-node-writes.js';\n\n// One entry point for the reference-resolution rules above (#3583 §5 D5).\n// Adding a rule to `REFERENCE_INTEGRITY_RULES` runs it on `validate`, `lint`\n// and `compile` at once — the CLI call sites do not change.\nexport {\n validateReferenceIntegrity,\n REFERENCE_INTEGRITY_RULES,\n} from './reference-integrity-suite.js';\nexport type {\n ReferenceIntegrityFinding,\n ReferenceIntegrityRule,\n ReferenceIntegritySeverity,\n} from './reference-integrity-suite.js';\n\nexport { buildAccessMatrix, diffAccessMatrix } from './build-access-matrix.js';\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { isIncoherentAggregate } from '@objectstack/spec/data';\nimport { ChartTypeSchema } from '@objectstack/spec/ui';\n\nimport { SYSTEM_FIELDS } from './system-fields.js';\n\n/**\n * Build-time dashboard widget binding diagnostics (issues #1719, #1721).\n *\n * Runs at `objectstack validate`/`compile`/`build` AFTER the stack has been\n * schema-parsed, so every widget's `dataset` reference can be linked to its\n * `defineDataset` and each entry in `dimensions`/`values` resolved to a\n * declared dimension/measure. This is the semantic/cross-reference phase —\n * the rules here cannot run during plain Zod parsing of the raw widget\n * literal (the dataset may even live in another package of the stack).\n *\n * Reference-integrity rules (#1721) — severity `error`, the page is broken:\n *\n * - `widget-dataset-unknown` — `dataset` does not resolve to a declared\n * `Dataset`.\n * - `widget-dimension-unknown` — a `dimensions[]` entry is not a dimension\n * name on the bound dataset.\n * - `widget-measure-unknown` — a `values[]` entry is not a measure name on\n * the bound dataset.\n * - `chart-field-unknown` — a `chartConfig` binding names a field the query\n * result will not contain: `xAxis.field` must be one of the widget's\n * dimensions (or a dataset dimension), and each `yAxis[].field` /\n * `series[].name` must be one of the widget's selected measures\n * (`values`). Post-cutover (ADR-0021) the result rows are keyed by\n * measure NAME (e.g. `sum_amount`), not the base column (`amount`) — a\n * stale base-column reference renders the axis but an empty series.\n * - `widget-legacy-analytics-unrenderable` (#1878/#1894) — a widget uses the\n * removed pre-ADR-0021 inline-analytics shape (`categoryField`/`rowField`/…)\n * as its ONLY data wiring: no `dataset`, no `object`, no inline `data`. The\n * renderer reads only the dataset path, so the widget has no data at all and\n * renders nothing. Errored (not warned) so this class of authoring mistake —\n * very often an AI emitting a removed shape — fails the build instead of\n * shipping a blank widget past human review.\n * - `dashboard-filter-field-unknown` (#3365) — a dashboard-level filter\n * (`dateRange` or a `globalFilters[]` entry) is wired into EVERY widget's\n * analytics query (#2501), but its EFFECTIVE field (after any `filterBindings`\n * re-target) does not exist on a bound widget's dataset object. The widget's\n * query then references a non-existent column and crashes at render time\n * (`no such column …`) — a build-decidable invariant that previously escaped\n * the static gate and failed only when a user opened the dashboard. A widget\n * opts out with `filterBindings: { <name>: false }` or re-targets to a real\n * field. This is the same field-existence invariant ADR-0032 enforces for\n * CEL formula / sharing-rule references, applied to dashboard filter fields.\n *\n * Advisory rules — severity `warning`, build stays green:\n *\n * - `chart-config-missing` — a chart-type widget (bar/line/pie/…) has no\n * `chartConfig`, so the renderer cannot tell which measure to plot.\n * - `table-count-only` (#1719) — a `table`/`pivot` widget whose selected\n * measures are ALL `aggregate: 'count'` and which declares no\n * `dimensions` asks the analytics service for a single summary row. That\n * is the shape a `metric` widget wants — for a table it almost always\n * means the author wanted a per-record listing, which is not an\n * analytics dataset at all (model it as an object-bound ListView,\n * ADR-0017). Evaluated on the WIDGET's binding, not the dataset.\n * - `measure-aggregate-incoherent` — a dataset measure aggregates its field\n * in a way that produces a meaningless number: today, SUM (or\n * `count_distinct`) of a `percent`/rate field, whose total routinely\n * exceeds 100%. Rates must AVG. Checked once per dataset (independent of\n * any widget) when the bound object's field types are known.\n * - `widget-legacy-analytics-shape` (#1878/#1894) — a widget sets a\n * pre-ADR-0021 inline key (`categoryField`/`valueField`/`xAxisField`/\n * `yAxisFields`/`aggregate`/`aggregation`/`rowField`/`columnField`) that the\n * single-form cutover removed. The dashboard renderer routes dataset-bound\n * widgets through `DatasetWidget` and never reads these, so they are a\n * silent no-op. Steers the author onto `dataset`+`dimensions`+`values`.\n *\n * Warnings can be deliberately suppressed per widget via\n * `suppressWarnings: ['<rule-id>']`; errors cannot — they describe a\n * binding the analytics service cannot satisfy.\n */\n\nexport const WIDGET_DATASET_UNKNOWN = 'widget-dataset-unknown';\nexport const WIDGET_DIMENSION_UNKNOWN = 'widget-dimension-unknown';\nexport const WIDGET_MEASURE_UNKNOWN = 'widget-measure-unknown';\nexport const CHART_FIELD_UNKNOWN = 'chart-field-unknown';\nexport const CHART_CONFIG_MISSING = 'chart-config-missing';\nexport const TABLE_COUNT_ONLY = 'table-count-only';\nexport const MEASURE_AGGREGATE_INCOHERENT = 'measure-aggregate-incoherent';\nexport const WIDGET_LEGACY_ANALYTICS_SHAPE = 'widget-legacy-analytics-shape';\nexport const WIDGET_LEGACY_ANALYTICS_UNRENDERABLE = 'widget-legacy-analytics-unrenderable';\nexport const DASHBOARD_FILTER_FIELD_UNKNOWN = 'dashboard-filter-field-unknown';\n\n/**\n * Pre-ADR-0021 inline-analytics keys. The single-form cutover replaced them\n * with the semantic-layer shape (`dataset` + `dimensions` + `values`); the\n * dashboard renderer routes dataset-bound widgets through `DatasetWidget` and\n * never reads these, so authoring one today is a silent no-op. Warned (not\n * errored) because they still parse and a legacy object-bound widget keeps\n * rendering — the author is just being steered to the governed shape.\n * (liveness audit #1878 / #1894).\n *\n * Interplay with `DashboardWidgetSchema.strict()` (framework#3251, protocol 16):\n * on the schema-parsed CLI paths (`compile`, `validate`) strict rejects these\n * keys as a hard parse error *before* binding validation runs, so these rules\n * are effectively preempted there. They remain the friendly, suppressible\n * bridge on the raw-config paths (`lint`, `doctor`) that hand\n * `validateWidgetBindings` un-parsed config — keeping the actionable\n * \"steer to the dataset shape\" message rather than a bare unknown-key error.\n */\nconst LEGACY_ANALYTICS_KEYS = [\n 'categoryField', 'valueField', 'xAxisField', 'yAxisFields',\n 'aggregate', 'aggregation', 'rowField', 'columnField',\n] as const;\n\nexport type WidgetBindingSeverity = 'error' | 'warning';\n\nexport interface WidgetBindingFinding {\n /** `error` = unresolvable binding (broken page); `warning` = advisory. */\n severity: WidgetBindingSeverity;\n /** Diagnostic rule id (registry entry), e.g. `widget-measure-unknown`. */\n rule: string;\n /** Human-readable location, e.g. `dashboard \"x\" › widget \"y\"`. */\n where: string;\n /** Config path, e.g. `dashboards[0].widgets[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix (or deliberately suppress) it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction asStrings(v: unknown): string[] {\n return Array.isArray(v) ? v.filter((s): s is string => typeof s === 'string') : [];\n}\n\n/**\n * Chart families that plot a single value or every column, and so need no\n * `chartConfig` measure mapping: single-value types plot their lone value,\n * tabular types render each column as-is.\n */\nconst MEASURE_EXEMPT_CHART_TYPES = new Set([\n 'gauge', 'solid-gauge', 'metric', 'kpi', 'bullet',\n 'table', 'pivot',\n]);\n\n/**\n * Chart families whose renderer needs a `chartConfig` measure mapping — the\n * taxonomy minus the exemptions above.\n *\n * Derived from `ChartTypeSchema` rather than restated. As a hand-written list it\n * had no way to know when the taxonomy grew, and the omission is silent in\n * exactly the wrong direction: an unlisted family is treated as \"not a chart\",\n * so a widget missing its measure mapping passes validation instead of being\n * reported. objectui#2945.\n */\nconst CHART_TYPES = new Set<string>(\n ChartTypeSchema.options.filter(t => !MEASURE_EXEMPT_CHART_TYPES.has(t)),\n);\n\nfunction levenshtein(a: string, b: string): number {\n const m = a.length, n = b.length;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const cur = [i];\n for (let j = 1; j <= n; j++) {\n cur[j] = Math.min(\n prev[j] + 1,\n cur[j - 1] + 1,\n prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),\n );\n }\n prev = cur;\n }\n return prev[n];\n}\n\n/**\n * Nearest declared name for a typo'd/stale reference, or undefined when\n * nothing is close. Containment is checked first because the cutover's\n * canonical drift is base column → prefixed measure name (`amount` →\n * `sum_amount`), which is far in edit distance but obvious to a human.\n */\nfunction didYouMean(input: string, candidates: Iterable<string>): string | undefined {\n let best: string | undefined;\n let bestScore = Infinity;\n for (const c of candidates) {\n let score: number;\n if (input.length >= 3 && (c.includes(input) || input.includes(c))) {\n score = Math.abs(c.length - input.length);\n } else {\n const d = levenshtein(input, c);\n if (d > Math.max(2, Math.floor(input.length / 3))) continue;\n score = 100 + d;\n }\n if (score < bestScore) { bestScore = score; best = c; }\n }\n return best;\n}\n\nfunction suggest(input: string, candidates: Iterable<string>): string {\n const s = didYouMean(input, candidates);\n return s ? ` Did you mean \"${s}\"?` : '';\n}\n\nfunction list(names: Iterable<string>): string {\n const arr = [...names];\n return arr.length > 0 ? arr.join(', ') : '(none)';\n}\n\n// ── dashboard-filter field-existence (#3365) ─────────────────────────────────\n\n/** Reserved filter name for the dashboard's built-in date range (#2501). */\nconst DATE_RANGE_FILTER_NAME = 'dateRange';\n/**\n * Default field of the built-in date range when `dateRange.field` is omitted.\n * MUST track objectui `dashboard-filters.ts` `DATE_RANGE_DEFAULT_FIELD` — the\n * runtime this check shadows. `created_at` is a registry-injected system field\n * (the package-shared `SYSTEM_FIELDS`, `system-fields.ts`), so a bare\n * `dateRange` never false-positives.\n */\nconst DATE_RANGE_DEFAULT_FIELD = 'created_at';\n\ninterface DashFilterDef {\n /** Stable filter name — the key widgets bind against in `filterBindings`. */\n name: string;\n /** Default target field when a widget declares no explicit binding. */\n field: string;\n /** Legacy widget-id allow-list; gates the DEFAULT binding only. */\n targetWidgets?: string[];\n}\n\n/**\n * Normalize a dashboard's declared filters into `{ name, field, targetWidgets }`\n * defs — the built-in `dateRange` (reserved name) first, then every\n * `globalFilters[]` entry named by its `name` (defaulting to `field`). Later\n * duplicates win. Mirrors objectui `resolveDashboardFilterDefs`.\n */\nfunction dashboardFilterDefs(dash: AnyRec): DashFilterDef[] {\n const byName = new Map<string, DashFilterDef>();\n\n const dateRange = dash.dateRange;\n if (dateRange && typeof dateRange === 'object') {\n const declared = (dateRange as AnyRec).field;\n const field = typeof declared === 'string' && declared ? declared : DATE_RANGE_DEFAULT_FIELD;\n byName.set(DATE_RANGE_FILTER_NAME, { name: DATE_RANGE_FILTER_NAME, field });\n }\n\n for (const f of asArray(dash.globalFilters)) {\n if (typeof f.field !== 'string' || !f.field) continue;\n const name = typeof f.name === 'string' && f.name ? f.name : f.field;\n const targetWidgets = Array.isArray(f.targetWidgets)\n ? f.targetWidgets.filter((w): w is string => typeof w === 'string')\n : undefined;\n byName.set(name, { name, field: f.field, targetWidgets });\n }\n\n return [...byName.values()];\n}\n\n/**\n * Resolve which field of `widget` a filter binds to, or `undefined` when the\n * widget is not bound (opted out / not targeted). Precedence mirrors objectui\n * `resolveBoundField`: explicit `filterBindings` entry (string re-targets,\n * `false` opts out — both win) → legacy `targetWidgets` allow-list → the\n * filter's own default `field`. `explicit` distinguishes an author-chosen field\n * (a typo they must fix) from the inherited default (which they may opt out of).\n */\nfunction effectiveFilterField(\n widget: AnyRec,\n def: DashFilterDef,\n): { field: string; explicit: boolean } | undefined {\n const bindings = widget.filterBindings;\n const binding = bindings && typeof bindings === 'object'\n ? (bindings as AnyRec)[def.name]\n : undefined;\n if (binding === false) return undefined;\n if (typeof binding === 'string' && binding) return { field: binding, explicit: true };\n if (def.targetWidgets && def.targetWidgets.length > 0) {\n const id = typeof widget.id === 'string' ? widget.id : undefined;\n if (!id || !def.targetWidgets.includes(id)) return undefined;\n }\n return { field: def.field, explicit: false };\n}\n\n/**\n * Validate every dashboard widget's dataset binding. Returns the list of\n * findings (empty = clean). Caller decides how to surface them: `error`\n * findings describe bindings the analytics service cannot satisfy and\n * should fail validate/build; `warning` findings are advisory and must\n * never fail the build on their own.\n */\nexport function validateWidgetBindings(stack: AnyRec): WidgetBindingFinding[] {\n const findings: WidgetBindingFinding[] = [];\n\n const datasets = new Map<string, AnyRec>();\n for (const ds of asArray(stack.datasets)) {\n if (typeof ds.name === 'string') datasets.set(ds.name, ds);\n }\n\n // ── (0) dataset measures aggregate their field coherently ──\n // A measure that SUMs a percentage/rate field produces a meaningless total\n // (it can exceed 100%); rates must AVG. This is a dataset-level defect (it\n // does not depend on any widget), so it is checked once over every dataset\n // whose object's field types are known. Advisory — the page still renders.\n const objectFieldTypes = new Map<string, Map<string, string>>();\n for (const o of asArray(stack.objects)) {\n if (typeof o.name !== 'string') continue;\n const fm = new Map<string, string>();\n for (const f of asArray(o.fields)) {\n if (typeof f.name === 'string' && typeof f.type === 'string') fm.set(f.name, f.type);\n }\n objectFieldTypes.set(o.name, fm);\n }\n const datasetList = asArray(stack.datasets);\n for (let i = 0; i < datasetList.length; i++) {\n const ds = datasetList[i];\n const fieldTypes = typeof ds.object === 'string' ? objectFieldTypes.get(ds.object) : undefined;\n if (!fieldTypes) continue; // cannot judge without the object's field types\n const dsMeasures = asArray(ds.measures);\n for (let k = 0; k < dsMeasures.length; k++) {\n const m = dsMeasures[k];\n const field = typeof m.field === 'string' ? m.field : undefined;\n const aggregate = typeof m.aggregate === 'string' ? m.aggregate : undefined;\n if (!field || !aggregate) continue; // count(*) and underivable measures are fine\n const ftype = fieldTypes.get(field);\n if (ftype && isIncoherentAggregate(aggregate, ftype)) {\n findings.push({\n severity: 'warning',\n rule: MEASURE_AGGREGATE_INCOHERENT,\n where: `dataset \"${typeof ds.name === 'string' ? ds.name : `(dataset ${i})`}\" › measure \"${typeof m.name === 'string' ? m.name : `(measure ${k})`}\"`,\n path: `datasets[${i}].measures[${k}]`,\n message:\n `measure \"${m.name}\" applies ${aggregate} to ${ftype} field \"${field}\" — ` +\n `summed percentages are meaningless (they can exceed 100%).`,\n hint:\n `Use aggregate \"avg\" for percentage/rate fields (or \"count\" of records). ` +\n `If a running total is genuinely intended, suppress with: ` +\n `suppressWarnings: ['${MEASURE_AGGREGATE_INCOHERENT}'] on the measure.`,\n });\n }\n }\n }\n\n const dashboards = asArray(stack.dashboards);\n for (let i = 0; i < dashboards.length; i++) {\n const dash = dashboards[i];\n const dashName = typeof dash.name === 'string' ? dash.name : `(dashboard ${i})`;\n const widgets = Array.isArray(dash.widgets) ? (dash.widgets as AnyRec[]) : [];\n // Dashboard-level filters (`dateRange` + `globalFilters`) are broadcast into\n // every widget's query (#2501) — resolved once here, checked per widget below.\n const dashFilterDefs = dashboardFilterDefs(dash);\n\n for (let j = 0; j < widgets.length; j++) {\n const w = widgets[j];\n const widgetId = typeof w.id === 'string' ? w.id : `(widget ${j})`;\n const where = `dashboard \"${dashName}\" › widget \"${widgetId}\"`;\n const path = `dashboards[${i}].widgets[${j}]`;\n const suppressed = (rule: string): boolean =>\n Array.isArray(w.suppressWarnings) && w.suppressWarnings.includes(rule);\n const push = (f: Omit<WidgetBindingFinding, 'where' | 'path'>): void => {\n if (f.severity === 'warning' && suppressed(f.rule)) return;\n findings.push({ ...f, where, path });\n };\n\n // ── (a0) legacy pre-ADR-0021 analytics shape ──\n // Steer authors (very often an AI) off the removed inline shape and onto\n // the semantic-layer `dataset`+`dimensions`+`values`. The renderer reads\n // ONLY the dataset path, so these keys are dead. Two severities:\n // • ERROR — the legacy keys are the widget's only (dead) data wiring\n // (no dataset / object / inline data): it renders nothing.\n // • warning — a data source is present, so the widget still renders and\n // the legacy keys are merely ignored noise (suppressible).\n const legacyUsed = LEGACY_ANALYTICS_KEYS.filter((k) => w[k] !== undefined);\n if (legacyUsed.length > 0) {\n const optionsData =\n typeof w.options === 'object' && w.options !== null &&\n (w.options as AnyRec).data !== undefined;\n const hasDataSource =\n w.dataset !== undefined || w.object !== undefined ||\n w.data !== undefined || optionsData;\n const keyList = legacyUsed.map((k) => `\\`${k}\\``).join(', ');\n const plural = legacyUsed.length > 1;\n const datasetHint =\n `Bind a semantic dataset and select fields BY NAME: ` +\n `\\`dataset: '<name>', dimensions: [...], values: [...]\\`. ` +\n `Dataset-bound widgets render through DatasetWidget (pivot rows/cols come from ` +\n `\\`dimensions\\`, cell values from \\`values\\`).`;\n if (!hasDataSource) {\n push({\n severity: 'error',\n rule: WIDGET_LEGACY_ANALYTICS_UNRENDERABLE,\n message:\n `sets legacy analytics key${plural ? 's' : ''} ${keyList} ` +\n `(removed by the ADR-0021 single-form cutover) and binds no data source ` +\n `(no \\`dataset\\`, \\`object\\`, or inline \\`data\\`) — it renders nothing.`,\n hint:\n `${datasetHint} The renderer ignores the legacy keys, so without a data ` +\n `source this widget has no data at all.`,\n });\n } else {\n push({\n severity: 'warning',\n rule: WIDGET_LEGACY_ANALYTICS_SHAPE,\n message:\n `sets legacy analytics key${plural ? 's' : ''} ${keyList} that the ADR-0021 ` +\n `single-form cutover removed — the dashboard renderer ignores ${plural ? 'them' : 'it'}.`,\n hint:\n `${datasetHint} These inline keys are a no-op. ` +\n `Suppress with suppressWarnings: ['${WIDGET_LEGACY_ANALYTICS_SHAPE}'] if intentional.`,\n });\n }\n }\n\n // ── (a) dataset reference resolves ──\n const dsName = typeof w.dataset === 'string' ? w.dataset : undefined;\n const dataset = dsName ? datasets.get(dsName) : undefined;\n if (dsName && !dataset) {\n push({\n severity: 'error',\n rule: WIDGET_DATASET_UNKNOWN,\n message: `dataset \"${dsName}\" does not resolve to a declared dataset.`,\n hint:\n `Declared datasets: ${list(datasets.keys())}.${suggest(dsName, datasets.keys())} ` +\n `Define the dataset with defineDataset() or fix the reference (ADR-0021).`,\n });\n }\n // A widget with NO `dataset` key at all. `DashboardWidgetSchema.dataset`\n // is REQUIRED, so the schema-parsed paths (`compile`, `validate`) reject\n // this before we run — but `lint`/`doctor` hand us raw, un-parsed config,\n // where it previously fell into the `continue` below and silently\n // bypassed EVERY binding and chart check (issue #3583). Report it rather\n // than skip: an unbound widget resolves no data and renders empty.\n if (!dsName) {\n push({\n severity: 'error',\n rule: WIDGET_DATASET_UNKNOWN,\n message:\n `binds no \\`dataset\\` — the ADR-0021 widget shape requires one, so this ` +\n `widget resolves no data and renders empty.`,\n hint:\n `Set \\`dataset: '<name>'\\` (plus \\`values\\`, and \\`dimensions\\` where the chart ` +\n `family needs them). Declared datasets: ${list(datasets.keys())}.`,\n });\n continue;\n }\n // A named-but-unresolvable dataset was already reported above; either way\n // there is nothing left to check names against.\n if (!dataset) continue;\n\n // ── (a1) dashboard filter fields exist on the widget's object (#3365) ──\n // Each dashboard-level filter is ANDed into this widget's analytics query\n // (#2501); a filter whose EFFECTIVE field (after `filterBindings`) is not a\n // column on the bound dataset object emits SQL like `WHERE close_date …`\n // against a table without that column and the widget crashes at query time.\n // Errored (not warned): a broken query, not advice. The opt-out is the\n // author's own `filterBindings: { <name>: false }`, so no suppression needed.\n if (dashFilterDefs.length > 0) {\n const datasetObject = typeof dataset.object === 'string' ? dataset.object : undefined;\n // Only judge when the bound object's fields are known in THIS stack; an\n // object from another installed package is unknowable here — skip rather\n // than false-positive (mirrors the measure-aggregate check above).\n const objectFields = datasetObject ? objectFieldTypes.get(datasetObject) : undefined;\n if (objectFields) {\n for (const def of dashFilterDefs) {\n const eff = effectiveFilterField(w, def);\n if (!eff) continue; // opted out / not targeted → filter never applies\n const field = eff.field;\n // A relationship path (`account.region`) is resolved by the query\n // engine, not a base column, so it can't be checked here — skip it.\n if (field.includes('.')) continue;\n if (objectFields.has(field) || SYSTEM_FIELDS.has(field)) continue;\n push({\n severity: 'error',\n rule: DASHBOARD_FILTER_FIELD_UNKNOWN,\n message: eff.explicit\n ? `binds dashboard filter \\`${def.name}\\` to field \\`${field}\\` ` +\n `(via filterBindings), but object \\`${datasetObject}\\` (dataset \"${dsName}\") ` +\n `has no field \\`${field}\\`.`\n : `inherits dashboard filter \\`${def.name}(${field})\\`, but object ` +\n `\\`${datasetObject}\\` (dataset \"${dsName}\") has no field \\`${field}\\`.`,\n hint: eff.explicit\n ? `Point filterBindings: { ${def.name}: '<field>' } at a field that exists on ` +\n `\\`${datasetObject}\\`, or opt out with filterBindings: { ${def.name}: false }.` +\n `${suggest(field, objectFields.keys())} Object fields: ${list(objectFields.keys())}.`\n : `Set filterBindings: { ${def.name}: false } on this widget to opt out, or ` +\n `re-target to an existing field with filterBindings: { ${def.name}: '<field>' }.` +\n `${suggest(field, objectFields.keys())} Object fields: ${list(objectFields.keys())}.`,\n });\n }\n }\n }\n\n const dimensionNames = new Set<string>();\n for (const d of asArray(dataset.dimensions)) {\n if (typeof d.name === 'string') dimensionNames.add(d.name);\n }\n const measures = new Map<string, AnyRec>();\n for (const m of asArray(dataset.measures)) {\n if (typeof m.name === 'string') measures.set(m.name, m);\n }\n\n // ── (b) every dimensions[] entry is a dataset dimension ──\n const dims = asStrings(w.dimensions);\n for (let k = 0; k < dims.length; k++) {\n if (dimensionNames.has(dims[k])) continue;\n push({\n severity: 'error',\n rule: WIDGET_DIMENSION_UNKNOWN,\n message:\n `dimensions[${k}] \"${dims[k]}\" is not a dimension of dataset ` +\n `\"${dsName}\" (declared dimensions: ${list(dimensionNames)}).`,\n hint:\n `Widgets select dataset dimensions BY NAME.${suggest(dims[k], dimensionNames)} ` +\n `Add the dimension to the dataset or fix the reference.`,\n });\n }\n\n // ── (c) every values[] entry is a dataset measure ──\n const values = asStrings(w.values);\n for (let k = 0; k < values.length; k++) {\n if (measures.has(values[k])) continue;\n push({\n severity: 'error',\n rule: WIDGET_MEASURE_UNKNOWN,\n message:\n `values[${k}] \"${values[k]}\" is not a measure of dataset ` +\n `\"${dsName}\" (declared measures: ${list(measures.keys())}).`,\n hint:\n `Widgets select dataset measures BY NAME, not by base column.` +\n `${suggest(values[k], measures.keys())} ` +\n `Add the measure to the dataset or fix the reference.`,\n });\n }\n\n // ── (d) chartConfig bindings resolve against the widget's selection ──\n const chartConfig = (w.chartConfig && typeof w.chartConfig === 'object')\n ? (w.chartConfig as AnyRec)\n : undefined;\n const isChartType = typeof w.type === 'string' && CHART_TYPES.has(w.type);\n\n if (chartConfig) {\n // The query result carries the widget's selected dimensions and\n // measures; resolve every chartConfig field against that shape.\n const selectedValues = new Set(values.filter((v) => measures.has(v)));\n\n const xAxis = (chartConfig.xAxis && typeof chartConfig.xAxis === 'object')\n ? (chartConfig.xAxis as AnyRec)\n : undefined;\n // A field naming an entry of the widget's own (already-validated)\n // selection is not re-reported here — rules (b)/(c) own that error.\n if (xAxis && typeof xAxis.field === 'string'\n && !dimensionNames.has(xAxis.field) && !dims.includes(xAxis.field)) {\n push({\n severity: 'error',\n rule: CHART_FIELD_UNKNOWN,\n message:\n `chartConfig.xAxis.field \"${xAxis.field}\" does not resolve to a ` +\n `dimension of dataset \"${dsName}\" (declared dimensions: ${list(dimensionNames)}).`,\n hint: `Point xAxis.field at a dataset dimension name.${suggest(xAxis.field, dimensionNames)}`,\n });\n }\n\n const measureField = (label: string, field: string): void => {\n if (values.includes(field)) return; // resolvable, or already errored via rule (c)\n const declaredButUnselected = measures.has(field);\n push({\n severity: 'error',\n rule: CHART_FIELD_UNKNOWN,\n message: declaredButUnselected\n ? `chartConfig.${label} \"${field}\" is a measure of dataset \"${dsName}\" ` +\n `but is not selected in the widget's values (${list(values)}), so the ` +\n `query result will not contain it.`\n : `chartConfig.${label} \"${field}\" does not resolve to a measure of ` +\n `dataset \"${dsName}\" (declared measures: ${list(measures.keys())}).`,\n hint: declaredButUnselected\n ? `Add \"${field}\" to the widget's values, or bind the chart to a selected measure.`\n : `Post-cutover data is keyed by the dataset's measure NAME, not the ` +\n `base column.${suggest(field, selectedValues.size > 0 ? selectedValues : measures.keys())}`,\n });\n };\n\n const yAxes = Array.isArray(chartConfig.yAxis) ? (chartConfig.yAxis as AnyRec[]) : [];\n for (let k = 0; k < yAxes.length; k++) {\n const field = yAxes[k]?.field;\n if (typeof field === 'string') measureField(`yAxis[${k}].field`, field);\n }\n const series = Array.isArray(chartConfig.series) ? (chartConfig.series as AnyRec[]) : [];\n for (let k = 0; k < series.length; k++) {\n const name = series[k]?.name;\n if (typeof name === 'string') measureField(`series[${k}].name`, name);\n }\n } else if (isChartType) {\n push({\n severity: 'warning',\n rule: CHART_CONFIG_MISSING,\n message:\n `chart-type widget ('${w.type}') has no chartConfig — the renderer ` +\n `cannot determine which measure to plot, so the series renders empty.`,\n hint:\n `Add chartConfig with xAxis.field set to a dimension (${list(dims)}) and ` +\n `yAxis[].field set to a measure name (${list(values)}). If the default ` +\n `rendering is intentional, suppress with: suppressWarnings: ['${CHART_CONFIG_MISSING}']`,\n });\n }\n\n // ── (e) table/pivot bound to a count-only, dimensionless selection ──\n if (w.type !== 'table' && w.type !== 'pivot') continue;\n // Grouped by at least one dimension → genuinely aggregated rows.\n if (dims.length > 0) continue;\n if (values.length === 0) continue;\n const resolved = values.map((v) => measures.get(v));\n // An unresolvable measure name already errored above — don't guess here.\n if (resolved.some((m) => !m)) continue;\n\n // Derived measures combine other measures; treat them as non-count even\n // when their (ignored) `aggregate` says otherwise.\n const countOnly = resolved.every((m) => m!.aggregate === 'count' && !m!.derived);\n if (!countOnly) continue;\n\n push({\n severity: 'warning',\n rule: TABLE_COUNT_ONLY,\n message:\n `a '${w.type}' widget bound to dataset \"${dsName}\" selects only count ` +\n `measure(s) (${values.join(', ')}) and no dimensions, so it renders a ` +\n `single summary row — not a per-record list.`,\n hint:\n `A flat record listing is not an analytics dataset. Model it as an ` +\n `object-bound ListView (ADR-0017) surfaced through app navigation, and ` +\n `use a 'metric' widget here if you only need the count. If a single-row ` +\n `table is intentional, add an explicit dimension or suppress with: ` +\n `suppressWarnings: ['${TABLE_COUNT_ONLY}']`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * The ONE answer to \"which columns does the registry inject on (almost) every\n * object without them appearing in authored `fields`?\" (#4330).\n *\n * Every field-resolving rule in this package needs that answer: a reference to\n * `created_at` or `owner_id` is authored against a real, addressable column\n * even though no object declares it, so flagging it would be the false finding\n * that makes authors stop trusting the linter (ADR-0072 D1). Before this\n * module, five rules each carried their own hand-copied list and had already\n * drifted from one another — the exact shape #3786 removed from the\n * audit-provenance family, rebuilt one package over.\n *\n * DERIVED from the spec's two declarations, so it cannot drift from them:\n *\n * - {@link FIELD_GROUP_SYSTEM_FIELDS} (`@objectstack/spec/data`) — audit\n * provenance plus `organization_id` / `tenant_id` / `is_deleted` /\n * `deleted_at`;\n * - {@link SystemFieldName} (`@objectstack/spec/system`) — the protocol-level\n * ids: `id`, `owner_id`, `user_id` and the timestamp/tenant columns.\n *\n * The union is deliberately generous, because the cost asymmetry is the same\n * in every consumer: over-inclusion costs at worst a missed finding on a\n * `systemFields: false` object (rare); under-inclusion costs a false one.\n *\n * What does NOT belong here: names that are ordinary AUTHORED fields on most\n * objects (`name`, `owner`, `record_type`) or legacy physical spellings\n * (`_id`, `space`). A rule that deliberately exempts those keeps them in a\n * rule-local extension next to its reason — adding them here would silently\n * stop every other rule from catching a reference to a field the object\n * genuinely does not have.\n */\n\nimport { FIELD_GROUP_SYSTEM_FIELDS } from '@objectstack/spec/data';\nimport { SystemFieldName } from '@objectstack/spec/system';\n\n/**\n * Registry-injected columns addressable at runtime without being authored in\n * `fields` — the union of the spec's two system-field declarations.\n */\nexport const SYSTEM_FIELDS: ReadonlySet<string> = new Set<string>([\n ...FIELD_GROUP_SYSTEM_FIELDS,\n ...Object.values(SystemFieldName),\n]);\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time expression validation (ADR-0032 §Decision 1a + 1b).\n *\n * Runs at `objectstack compile`, where the whole normalized stack is in hand —\n * so flow conditions can be checked against the *resolved* object schema\n * (field existence) in addition to CEL syntax. Uses the one shared validator\n * from `@objectstack/formula`, so the verdict matches `registerFlow` and the\n * agent `validate_expression` tool exactly.\n *\n * Scope: flow predicates (start/decision `config.condition` + edge `condition`),\n * every **descriptor-declared** expression slot named by\n * `FLOW_NODE_EXPRESSION_PATHS` (#4027 — e.g. a screen field's `visibleWhen`),\n * object validation-rule / formula predicates, and UI action `visible` /\n * `disabled` predicates. Each error is located (flow/object/action +\n * node/edge/field) with a corrective message.\n */\n\nimport { validateExpression } from '@objectstack/formula';\nimport { collectFlowGraphs, resolveFlowNodeExpressions } from '@objectstack/spec/automation';\nimport type { FlowNodeParsed } from '@objectstack/spec/automation';\n\nexport interface ExprIssue {\n where: string;\n message: string;\n source: string;\n /**\n * `error` fails the build (e.g. a bare ref in a record-scoped formula). `warning`\n * is advisory and never fails it (e.g. a possible field typo in a flattened flow\n * condition, which might be a flow variable). Absent ⇒ treat as `error`.\n */\n severity?: 'error' | 'warning';\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an `objects` collection (array or name-keyed map) to an array. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** object name → set of its field names, for schema-aware field checks. */\nfunction buildFieldIndex(objects: AnyRec[]): Map<string, string[]> {\n const idx = new Map<string, string[]>();\n for (const obj of objects) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fields = obj.fields;\n let names: string[] = [];\n if (Array.isArray(fields)) names = fields.map(f => (f as AnyRec).name).filter((n): n is string => typeof n === 'string');\n else if (fields && typeof fields === 'object') names = Object.keys(fields as AnyRec);\n idx.set(name, names);\n }\n return idx;\n}\n\n/**\n * object name → (field name → field type), for the #1928 tier-4 type-soundness\n * check. Handles both `fields` shapes (array of `{name, type}` and name-keyed\n * map). Fields with a non-string `type` are simply omitted (treated as `dyn`).\n */\nfunction buildFieldTypeIndex(objects: AnyRec[]): Map<string, Record<string, string>> {\n const idx = new Map<string, Record<string, string>>();\n for (const obj of objects) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fields = obj.fields;\n const types: Record<string, string> = {};\n if (Array.isArray(fields)) {\n for (const f of fields as AnyRec[]) {\n const fn = (f as AnyRec)?.name;\n const ft = (f as AnyRec)?.type;\n if (typeof fn === 'string' && typeof ft === 'string') types[fn] = ft;\n }\n } else if (fields && typeof fields === 'object') {\n for (const [fn, def] of Object.entries(fields as AnyRec)) {\n const ft = (def as AnyRec)?.type;\n if (typeof ft === 'string') types[fn] = ft;\n }\n }\n idx.set(name, types);\n }\n return idx;\n}\n\n/**\n * Validate every predicate in the stack. Returns the list of issues (empty =\n * clean). Caller decides how to surface / whether to fail the build.\n */\nexport function validateStackExpressions(stack: AnyRec): ExprIssue[] {\n const issues: ExprIssue[] = [];\n const objects = asArray(stack.objects);\n const fieldIndex = buildFieldIndex(objects);\n const fieldTypeIndex = buildFieldTypeIndex(objects);\n\n const check = (\n where: string,\n raw: unknown,\n objectName?: string,\n scope: 'record' | 'flattened' = 'flattened',\n ): void => {\n if (raw == null) return;\n const fields = objectName ? fieldIndex.get(objectName) : undefined;\n // Field types feed the #1928 tier-4 soundness warning; only consulted for\n // `record`-scoped sites, so it is harmless to pass for flattened ones too.\n const fieldTypes = objectName ? fieldTypeIndex.get(objectName) : undefined;\n const res = validateExpression('predicate', raw as string | { dialect?: string; source?: string },\n objectName ? { objectName, fields, fieldTypes, scope } : { scope });\n for (const e of res.errors) issues.push({ where, message: e.message, source: e.source, severity: 'error' });\n for (const w of res.warnings) issues.push({ where, message: w.message, source: w.source, severity: 'warning' });\n };\n\n /**\n * A declared bare-CEL slot (#4027). No object schema is passed: these slots\n * bind the *screen's own* collected values, not the trigger record's fields, so\n * a field-existence pass would report every field name as unknown.\n */\n const checkDeclaredPredicate = (where: string, raw: unknown): void => {\n if (raw == null) return;\n const res = validateExpression('predicate', raw as string | { dialect?: string; source?: string });\n for (const e of res.errors) issues.push({ where, message: e.message, source: e.source, severity: 'error' });\n for (const w of res.warnings) issues.push({ where, message: w.message, source: w.source, severity: 'warning' });\n };\n\n // ── Flows ──────────────────────────────────────────────────────────\n for (const flow of asArray(stack.flows)) {\n const flowName = typeof flow.name === 'string' ? flow.name : '(unnamed flow)';\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n // The record-change target object — `record.*` refs resolve against it.\n const startNode = nodes.find(n => n.type === 'start');\n const startCfg = (startNode?.config ?? {}) as AnyRec;\n const objectName = typeof startCfg.objectName === 'string' ? startCfg.objectName : undefined;\n\n // #4347 — every graph in the flow, not just `flow.nodes`/`flow.edges`. An\n // ADR-0031 container keeps a whole sub-graph in its `config`, so the\n // top-level walk validated PART of the flow while reporting on all of it: a\n // predicate written in the wrong dialect inside a `loop` body passed\n // `objectstack validate` and shipped. This is the author-time half of the\n // same traversal the engine's registration pass now does; `scope` names the\n // region so the located message still points at one edge.\n for (const graph of collectFlowGraphs(flow as { nodes?: FlowNodeParsed[] })) {\n const at = graph.scope ? `flow '${flowName}' · ${graph.scope}` : `flow '${flowName}'`;\n for (const node of graph.nodes as unknown as AnyRec[]) {\n const cfg = (node.config ?? {}) as AnyRec;\n check(`${at} · node '${node.id}' (${node.type}) condition`, cfg.condition, objectName);\n\n // Descriptor-declared expression slots (#4027). Before this, the traversal\n // hardcoded `condition` and assumed every other node string was a `{var}`\n // template — so `screen.fields[].visibleWhen`, declared bare CEL since\n // #3304, was validated by nobody and #3528 shipped a template-dialect\n // predicate through compile, validate and run time in silence.\n // Only `predicate` slots are checkable: `flow-template` slots take the\n // single-brace `{var}` dialect `interpolate()` implements, which no\n // validator covers (the `template` role enforces ADR-0032 §3's\n // double-brace text template and would reject every correct\n // `loop.collection`). The ledger records them regardless, so the\n // reconciliation ratchet still sees the marker.\n const nodeType = typeof node.type === 'string' ? node.type : '';\n for (const found of resolveFlowNodeExpressions(nodeType, cfg)) {\n if (found.entry.role !== 'predicate') continue;\n checkDeclaredPredicate(\n `${at} · node '${node.id}' (${nodeType}) ${found.entry.label} at config.${found.path}`,\n found.value,\n );\n }\n // #1870 — a `script` node must declare a callable target (`actionType` or\n // `function`). A node with neither is a silent no-op that otherwise passes\n // build. (Function *existence* isn't checkable here — functions are code,\n // not serialized into the artifact — so this is a structural check; the\n // runtime verifies the named function is actually registered.)\n if (node.type === 'script') {\n // `function` is canonical; a pre-parse source may still carry the\n // `functionName` alias during the protocol-17 window, until the\n // 'flow-node-script-config-aliases' conversion (#3796) canonicalizes it.\n const fn =\n (typeof cfg.function === 'string' ? cfg.function.trim() : '') ||\n (typeof cfg.functionName === 'string' ? cfg.functionName.trim() : '');\n const action = typeof cfg.actionType === 'string' ? cfg.actionType.trim() : '';\n // Inline `config.script` (a JS body) is also a declared form — the\n // built-in runtime doesn't execute it (warned at run time), but the node\n // is not the empty no-op this check targets, so don't flag it.\n const inline = typeof cfg.script === 'string' ? cfg.script.trim() : '';\n if (!fn && !action && !inline) {\n issues.push({\n where: `${at} · node '${node.id}' (script) callable`,\n message:\n `script node declares neither \\`actionType\\` nor \\`function\\` — it would do nothing at runtime. ` +\n `Name a built-in action (e.g. \\`actionType: 'email'\\`) or a registered function ` +\n `(\\`function: 'my_fn'\\`, registered via \\`defineStack({ functions })\\`).`,\n source: JSON.stringify({ id: node.id, type: node.type, config: cfg }),\n });\n } else if (action === 'invoke_function' && !fn) {\n // `actionType: 'invoke_function'` is a marker that names no callable on\n // its own — the function name must be in `function`/`functionName`.\n issues.push({\n where: `${at} · node '${node.id}' (script) callable`,\n message:\n `script node uses \\`actionType: 'invoke_function'\\` but no \\`function\\` (or \\`functionName\\`) — ` +\n `it names no callable. Set \\`function: 'my_fn'\\` and register it via \\`defineStack({ functions })\\`.`,\n source: JSON.stringify({ id: node.id, type: node.type, config: cfg }),\n });\n }\n }\n }\n for (const edge of graph.edges as unknown as AnyRec[]) {\n check(`${at} · edge '${edge.id}' (${edge.source}→${edge.target}) condition`, edge.condition, objectName);\n }\n }\n }\n\n // ── Object validation-rule + formula predicates ────────────────────\n for (const obj of objects) {\n const objectName = typeof obj.name === 'string' ? obj.name : undefined;\n const validations = obj.validations ?? obj.validationRules;\n for (const rule of asArray(validations)) {\n const where = `object '${objectName}' · validation '${(rule.name as string) ?? '?'}'`;\n // Common predicate keys across rule shapes. Validation predicates are\n // `record`-scoped — no field flattening — so bare refs are flagged (#1928).\n check(where, rule.expression ?? rule.predicate ?? rule.condition ?? rule.formula, objectName, 'record');\n // `conditional` rules carry a nested `when` predicate (record-scoped).\n check(`${where} when`, (rule as AnyRec).when, objectName, 'record');\n }\n // Field-level formulas (computed fields) reference the same object.\n const fields = obj.fields;\n const fieldList = Array.isArray(fields)\n ? (fields as AnyRec[])\n : (fields && typeof fields === 'object' ? Object.values(fields as AnyRec) as AnyRec[] : []);\n\n // (ADR-0062 D7's `field.columnName`-on-external-objects rejection was removed\n // with `field.columnName` itself in #2377: the field no longer exists, so there\n // is no dual-source ambiguity to guard — external column mapping is `external.columnMap`.)\n\n for (const f of fieldList) {\n // Field-level conditional rules are server-enforced (rule-validator) and\n // record-scoped — a bare ref silently fails the rule (required/readonly\n // not enforced = data-integrity hole). #1928 class, same as actions.\n if (f && typeof f === 'object') {\n const fname = (f.name as string) ?? '?';\n for (const key of ['requiredWhen', 'readonlyWhen', 'conditionalRequired', 'visibleWhen'] as const) {\n check(`object '${objectName}' · field '${fname}' ${key}`, (f as AnyRec)[key], objectName, 'record');\n }\n }\n if (f && typeof f === 'object' && f.formula) {\n // formulas are `value` role (any return type), still CEL. They are\n // `record`-scoped — `record.<field>`, never bare — so flag bare refs (#1928).\n const res = validateExpression('value', f.formula as string | { dialect?: string; source?: string },\n objectName ? { objectName, fields: fieldIndex.get(objectName), fieldTypes: fieldTypeIndex.get(objectName), scope: 'record' } : { scope: 'record' });\n const fieldWhere = `object '${objectName}' · field '${(f.name as string) ?? '?'}' formula`;\n for (const e of res.errors) issues.push({ where: fieldWhere, message: e.message, source: e.source, severity: 'error' });\n for (const w of res.warnings) issues.push({ where: fieldWhere, message: w.message, source: w.source, severity: 'warning' });\n }\n }\n }\n\n // ── Action `visible` / `disabled` predicates ───────────────────────\n // Record-scoped, same as validation rules: a record-header / row action's\n // `visible` is evaluated by ActionEngine against `{ record, recordId,\n // objectName, user, … }` with fail-closed semantics, so a BARE field ref\n // (`done` instead of `record.done`) throws and the action is silently hidden\n // on every record (the trap behind the #2183 \"Mark Done never hides\" hunt).\n // Flagging it here turns that into a build error with a corrective message.\n // `disabled` may be a boolean (skip) or a predicate (check).\n const seenActions = new Set<string>();\n const checkAction = (where: string, action: AnyRec, objectName?: string): void => {\n const obj = objectName\n ?? (typeof action.objectName === 'string' ? action.objectName : undefined)\n ?? (typeof action.object === 'string' ? action.object : undefined);\n const name = typeof action.name === 'string' ? action.name : '?';\n const key = `${obj ?? ''}:${name}`;\n if (seenActions.has(key)) return; // de-dup (actions are merged onto objects AND kept top-level)\n seenActions.add(key);\n check(`${where} · action '${name}' visible`, action.visible, obj, 'record');\n if (typeof action.disabled !== 'boolean') {\n check(`${where} · action '${name}' disabled`, action.disabled, obj, 'record');\n }\n };\n for (const action of asArray(stack.actions)) {\n checkAction('stack', action);\n }\n for (const obj of objects) {\n const objectName = typeof obj.name === 'string' ? obj.name : undefined;\n for (const action of asArray(obj.actions)) {\n checkAction(`object '${objectName}'`, action, objectName);\n }\n }\n\n // ── Sharing-rule predicates (security-critical, record-scoped) ─────\n // A criteria sharing rule's `condition` decides which rows a principal sees.\n // It is evaluated against the record, so a bare ref silently changes access.\n for (const rule of asArray(stack.sharingRules)) {\n const ruleObj = typeof rule.object === 'string' ? rule.object : undefined;\n const where = `sharingRule '${(rule.name as string) ?? '?'}'${ruleObj ? ` (${ruleObj})` : ''} condition`;\n check(where, rule.condition ?? rule.criteria ?? rule.predicate, ruleObj, 'record');\n }\n\n // ── Hook `condition` predicates (record-scoped gate) ───────────────\n // A lifecycle hook's `condition` skips the handler when false; it is\n // evaluated against the record, so a bare ref silently makes the hook\n // run on every record (or never) instead of the intended subset.\n for (const hook of asArray(stack.hooks)) {\n const hookName = (hook.name as string) ?? '?';\n if (typeof hook.object === 'string') {\n check(`hook '${hookName}' (${hook.object}) condition`, hook.condition, hook.object, 'record');\n continue;\n }\n\n // A hook may target MANY objects (`object: ['a','b']`). Previously any\n // non-string target dropped to `undefined`, so the condition got NO\n // field-awareness at all — a hook filtering on a field that exists on none\n // of its targets passed clean (issue #3583). The hook body runs against\n // each target in turn, so a ref missing from ANY of them silently\n // misbehaves there; validate per target and de-duplicate the\n // object-independent diagnostics (syntax/shape) that every pass repeats.\n const targets = Array.isArray(hook.object)\n ? (hook.object as unknown[]).filter((o): o is string => typeof o === 'string' && o !== '*')\n : [];\n if (targets.length === 0) {\n // `'*'` (or an unusable shape) — no single field set to judge against;\n // syntax/shape is still validated.\n check(`hook '${hookName}' condition`, hook.condition, undefined, 'record');\n continue;\n }\n\n const before = issues.length;\n const seen = new Set<string>();\n const kept: ExprIssue[] = [];\n for (const target of targets) {\n const mark = issues.length;\n check(`hook '${hookName}' (${target}) condition`, hook.condition, target, 'record');\n for (let i = mark; i < issues.length; i++) {\n const issue = issues[i];\n const key = `${issue.message}\\u0000${issue.source ?? ''}`;\n // Keep the first occurrence of each distinct diagnostic. A field-unknown\n // finding differs per target (it names the object), so each survives;\n // a syntax error is identical across targets and collapses to one.\n if (!seen.has(key)) {\n seen.add(key);\n kept.push(issue);\n }\n }\n }\n issues.length = before;\n issues.push(...kept);\n }\n\n return issues;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for ADR-0047 list-view navigation modes.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` and\n// reusable by AI authoring. It catches the \"wrong context\" authoring mistake\n// the type system alone cannot surface at author time on an object list view\n// (\"views\" mode — where the ViewTabBar owns the tab-bar role):\n// - `quickFilters` — never valid on an object list view;\n// - `userFilters` with `element: 'tabs'` (or carrying `tabs`) — the tab-bar\n// preset style is page-only; it would collide with the ViewTabBar.\n// A `dropdown` (value-chip) `userFilters` IS allowed on object views since the\n// ADR-0047 amendment (framework #2679 / objectui #2338) and is NOT flagged.\n//\n// Runs PRE-parse (on the normalizeStackInput output, before the\n// ObjectStackDefinition parse): the object-list schema (ObjectListViewSchema)\n// narrows `userFilters` to ObjectUserFiltersSchema (dropdown/toggle only), so a\n// post-parse stack has already had a `tabs` user-filter stripped and this rule\n// would never see it. The layering is deliberate — tsc rejects it at author\n// time, the schema strips it at runtime (no throw, back-compat), and this rule\n// reports it at `os validate` with a fix hint. See objectui #2338 and ADR-0047.\n\nexport type ListViewModeSeverity = 'error' | 'warning';\n\nexport interface ListViewModeFinding {\n severity: ListViewModeSeverity;\n rule: string;\n /** Human-readable location, e.g. `object \"task\" › listViews.my_pending`. */\n where: string;\n /** Config path, e.g. `objects[0].listViews.my_pending.userFilters`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const LIST_VIEW_FILTERS_IN_VIEWS_MODE = 'list-view-filters-in-views-mode';\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({\n name,\n ...(def as AnyRec),\n }));\n }\n return [];\n}\n\n/** Emit a finding for each wrong-context filter control on a single list-view def. */\nfunction scanView(\n view: unknown,\n where: string,\n path: string,\n out: ListViewModeFinding[],\n): void {\n if (!view || typeof view !== 'object') return;\n const rec = view as AnyRec;\n\n // `quickFilters` is never valid on an object list view.\n if (rec.quickFilters != null) {\n out.push({\n severity: 'error',\n rule: LIST_VIEW_FILTERS_IN_VIEWS_MODE,\n where,\n path: `${path}.quickFilters`,\n message:\n '`quickFilters` is a page filters-mode control and is ignored on an object ' +\n 'list view (\"views\" mode) — the ViewTabBar owns nav here.',\n hint:\n 'Move `quickFilters` to a page list (InterfaceListPage, \"filters\" mode), or ' +\n 'remove it. See ADR-0047.',\n });\n }\n\n // `userFilters` is allowed on object views ONLY as `dropdown` (value chips).\n // The `tabs` preset style — or any `userFilters` carrying `tabs` — collides\n // with the ViewTabBar and stays page-only.\n const uf = rec.userFilters;\n if (uf && typeof uf === 'object') {\n const ufRec = uf as AnyRec;\n if (ufRec.element === 'tabs' || ufRec.tabs != null) {\n out.push({\n severity: 'error',\n rule: LIST_VIEW_FILTERS_IN_VIEWS_MODE,\n where,\n path: `${path}.userFilters`,\n message:\n '`userFilters` with `element: \"tabs\"` is page-only and is ignored on an ' +\n 'object list view (\"views\" mode) — it would collide with the ViewTabBar.',\n hint:\n 'Use `listViews` for named presets on an object (each becomes a segmented ' +\n 'tab), switch to `element: \"dropdown\"` for value chips, or move the `tabs` ' +\n 'filter to a page list (InterfaceListPage, \"filters\" mode). See ADR-0047.',\n });\n }\n }\n}\n\n/** Scan a `listViews` record (name → list-view def). */\nfunction scanListViews(\n listViews: unknown,\n wherePrefix: string,\n pathPrefix: string,\n out: ListViewModeFinding[],\n): void {\n if (!listViews || typeof listViews !== 'object') return;\n for (const [name, view] of Object.entries(listViews as AnyRec)) {\n scanView(\n view,\n `${wherePrefix} › listViews.${name}`,\n `${pathPrefix}.listViews.${name}`,\n out,\n );\n }\n}\n\n/**\n * Flag ADR-0047 \"views\" mode violations on an object's built-in named views or a\n * `defineView` default `list` / named `listViews`: `quickFilters`, or a `tabs`\n * `userFilters`. A `dropdown` `userFilters` is allowed and not flagged. Returns\n * the list of findings (empty = clean). Caller decides how to surface / whether\n * to fail the build.\n *\n * Feed the PRE-parse stack (normalizeStackInput output) — see file header.\n */\nexport function validateListViewMode(stack: AnyRec): ListViewModeFinding[] {\n const out: ListViewModeFinding[] = [];\n\n // Object built-in named views (object.zod.ts `listViews`).\n asArray(stack.objects).forEach((obj, i) => {\n const label = typeof obj.name === 'string' ? `object \"${obj.name}\"` : `objects[${i}]`;\n scanListViews(obj.listViews, label, `objects[${i}]`, out);\n });\n\n // `defineView` aggregates (stack `views`: default `list` + named `listViews`).\n asArray(stack.views).forEach((view, i) => {\n const named =\n typeof view.objectName === 'string'\n ? view.objectName\n : typeof view.name === 'string'\n ? view.name\n : undefined;\n const label = named ? `view \"${named}\"` : `views[${i}]`;\n scanView(view.list, `${label} › list`, `views[${i}].list`, out);\n scanListViews(view.listViews, label, `views[${i}]`, out);\n });\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for auto-launched flow trigger wiring (2026-07-17\n// third-party eval: a record-change flow that silently never fires).\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` and\n// reusable by AI authoring. It catches the two authoring mistakes that produce\n// a flow which LOOKS armed but never launches — with zero runtime output:\n//\n// 1. `objectName` mismatch — the start node targets an object name that is\n// not defined in this stack. The runtime binds an ObjectQL hook filtered\n// to that exact name; if nobody writes it, the flow never fires. Names\n// match exactly (`eval_app_candidate`, not `candidate`). Objects owned by\n// other packages (`sys_*`, dependency packages) are legitimate targets,\n// so this is a warning with the cross-package caveat, not an error.\n//\n// 2. `status: 'draft'` on an auto-triggered flow — the schema default when\n// no status is authored (defineFlow parses at definition time, so by the\n// time this rule runs an unauthored status is indistinguishable from an\n// explicit 'draft'). Either way the intent is ambiguous: the engine still\n// binds and fires draft flows (only `obsolete`/`invalid` disable), which\n// surprises authors in both directions. Declare `'active'` to arm\n// deliberately or `'obsolete'` to disable. Only auto-triggered flows are\n// flagged (manual/screen flows have no arming semantics to be unclear\n// about).\n\nexport type FlowTriggerReadinessSeverity = 'error' | 'warning';\n\nexport interface FlowTriggerReadinessFinding {\n severity: FlowTriggerReadinessSeverity;\n rule: string;\n /** Human-readable location, e.g. `flow \"notify_on_done\" › start node`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[0].config.objectName`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries).\nexport const FLOW_TRIGGER_UNKNOWN_OBJECT = 'flow-trigger-unknown-object';\nexport const FLOW_DRAFT_STATUS_AMBIGUOUS = 'flow-draft-status-ambiguous';\nexport const FLOW_TRIGGER_UNKNOWN_EVENT = 'flow-trigger-unknown-event';\n\ntype AnyRec = Record<string, unknown>;\n\n/**\n * The record-change trigger fires only for a `triggerType` matching this exact\n * grammar — the same set its `triggerTypeToHookEvents` maps to ObjectQL hooks.\n * `insert` is a synonym for `create`; `write` is the create-OR-update union\n * (#3427). Any OTHER `record-`-prefixed token — a typo (`record-after-updated`),\n * a phase-less bare noun (`record-change`), or a bad phase (`record-during-update`)\n * — binds to the trigger but maps to NO hook and never fires. Kept in sync with\n * that trigger (one small, stable contract).\n */\nconst VALID_RECORD_TRIGGER = /^record-(?:before|after)-(?:create|insert|update|delete|write)$/;\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({\n name,\n ...(def as AnyRec),\n }));\n }\n return [];\n}\n\n/** The start node of a flow definition, if any. */\nfunction startNodeOf(flow: AnyRec): { node: AnyRec; index: number } | undefined {\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n const index = nodes.findIndex((n) => n?.type === 'start');\n return index >= 0 ? { node: nodes[index], index } : undefined;\n}\n\n/**\n * Validate auto-launched flow trigger wiring against the stack definition.\n * Pure and dependency-free; safe on pre- or post-parse stacks.\n */\nexport function validateFlowTriggerReadiness(stack: AnyRec): FlowTriggerReadinessFinding[] {\n const findings: FlowTriggerReadinessFinding[] = [];\n const flows = asArray(stack.flows);\n if (flows.length === 0) return findings;\n\n const objectNames = new Set(\n asArray(stack.objects)\n .map((o) => (typeof o.name === 'string' ? o.name : undefined))\n .filter((n): n is string => !!n),\n );\n\n flows.forEach((flow, flowIndex) => {\n const flowName = typeof flow.name === 'string' ? flow.name : `#${flowIndex}`;\n const start = startNodeOf(flow);\n const config = (start?.node.config ?? {}) as AnyRec;\n const triggerType = typeof config.triggerType === 'string' ? config.triggerType : undefined;\n const isRecordTriggered = !!triggerType && triggerType.startsWith('record-');\n // Array-form triggerType (e.g. ['record-after-create', 'record-after-delete'])\n // is NOT supported — multi-event unions are deferred (#3457). It needs its own\n // detection because a non-string triggerType folds to `undefined` above, so the\n // runtime misclassifies the flow as manual and it never fires with zero output\n // (#3481). Any record-* element is enough to recognize the (unsupported) intent.\n const isArrayRecordTriggered =\n Array.isArray(config.triggerType) &&\n (config.triggerType as unknown[]).some((t) => typeof t === 'string' && t.startsWith('record-'));\n const isTimeRelative = config.timeRelative != null && typeof config.timeRelative === 'object';\n const isAutoTriggered =\n isRecordTriggered || triggerType === 'api' || config.schedule != null ||\n isTimeRelative || flow.type === 'schedule' || flow.type === 'api';\n\n // 1. Record-triggered flow targeting an object this stack does not define.\n if (isRecordTriggered && start) {\n const objectName = typeof config.objectName === 'string' ? config.objectName : undefined;\n if (objectName && !objectNames.has(objectName) && !objectName.startsWith('sys_')) {\n findings.push({\n severity: 'warning',\n rule: FLOW_TRIGGER_UNKNOWN_OBJECT,\n where: `flow \"${flowName}\" › start node`,\n path: `flows[${flowIndex}].nodes[${start.index}].config.objectName`,\n message:\n `targets object '${objectName}', which this stack does not define — if the name is wrong, ` +\n `the flow will never fire (and the runtime stays silent about it).`,\n hint:\n `Object names match exactly. Check config.objectName against the object's registered name ` +\n `(e.g. 'app_candidate', not 'candidate'). If the object comes from another installed package, ` +\n `this warning can be ignored.`,\n });\n }\n }\n\n // 1b. Time-relative flow sweeping an object this stack does not define. Like\n // the record-change case, a wrong object name makes the sweep match\n // nothing forever with no runtime output.\n if (isTimeRelative && start) {\n const tr = config.timeRelative as AnyRec;\n const objectName = typeof tr.object === 'string' ? tr.object : undefined;\n if (objectName && !objectNames.has(objectName) && !objectName.startsWith('sys_')) {\n findings.push({\n severity: 'warning',\n rule: FLOW_TRIGGER_UNKNOWN_OBJECT,\n where: `flow \"${flowName}\" › start node`,\n path: `flows[${flowIndex}].nodes[${start.index}].config.timeRelative.object`,\n message:\n `sweeps object '${objectName}', which this stack does not define — if the name is wrong, ` +\n `the sweep will match nothing (and the runtime stays quiet about it).`,\n hint:\n `Object names match exactly. Check config.timeRelative.object against the object's registered name. ` +\n `If the object comes from another installed package, this warning can be ignored.`,\n });\n }\n }\n\n // 1c. A `record-`-prefixed triggerType the trigger cannot map to any hook —\n // a typo (`record-after-updated`), a phase-less bare noun (`record-change`,\n // which the Studio picker once offered as \"Record changed (any)\"), or a bad\n // phase (`record-during-update`). The engine routes any `record-` token to\n // the record-change trigger, which then binds to NO hook and never fires\n // (only a runtime warn). Surface the never-fire defect at authoring time.\n if (start && isRecordTriggered && !VALID_RECORD_TRIGGER.test((triggerType ?? '').trim())) {\n findings.push({\n severity: 'warning',\n rule: FLOW_TRIGGER_UNKNOWN_EVENT,\n where: `flow \"${flowName}\" › start node`,\n path: `flows[${flowIndex}].nodes[${start.index}].config.triggerType`,\n message:\n `triggerType '${triggerType}' is not a recognized record trigger — the flow binds to the ` +\n `record-change trigger but never fires (the runtime stays silent about it).`,\n hint:\n `Use record-{before,after}-{create,update,delete,write}. 'write' fires on create OR update in one ` +\n `flow (#3427); create/insert are synonyms. There is no \"any change\" token — pick the specific event(s).`,\n });\n }\n\n // 1d. Array-form triggerType — an unsupported multi-event shape (#3457). The\n // runtime folds a non-string triggerType to \"no trigger\" and treats the\n // flow as manual, so it binds to nothing and never fires, with zero output\n // at any layer (#3481). Surface it at authoring time like the unmappable\n // single tokens above (same rule id — both are \"this token never fires\").\n if (start && isArrayRecordTriggered) {\n findings.push({\n severity: 'warning',\n rule: FLOW_TRIGGER_UNKNOWN_EVENT,\n where: `flow \"${flowName}\" › start node`,\n path: `flows[${flowIndex}].nodes[${start.index}].config.triggerType`,\n message:\n `triggerType is an array (${JSON.stringify(config.triggerType)}), which is not supported — a start ` +\n `node takes a single trigger event, so the flow binds to nothing and never fires (the runtime stays silent about it).`,\n hint:\n `Use one triggerType string. For \"created or updated\" use record-after-write (one flow, both events, #3427). ` +\n `For any other combination, author one flow per event — multi-event arrays are deferred (#3457).`,\n });\n }\n\n // 2. Auto-triggered flow whose status is 'draft' — authored or defaulted\n // (defineFlow parses at definition time, so the two are the same here).\n if (isAutoTriggered && (flow.status == null || flow.status === 'draft')) {\n findings.push({\n severity: 'warning',\n rule: FLOW_DRAFT_STATUS_AMBIGUOUS,\n where: `flow \"${flowName}\"`,\n path: `flows[${flowIndex}].status`,\n message:\n `has status 'draft' (the default when none is authored). Draft flows DO still fire their ` +\n `triggers (only 'obsolete'/'invalid' disable), so the intent is ambiguous.`,\n hint: `Declare status: 'active' to arm it deliberately, or status: 'obsolete' to disable it.`,\n });\n }\n });\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Shared flow-node traversal for the rules that inspect `FlowNode.config`\n * (issue #4380) — the flow-side counterpart of `page-walk.ts`, and here for the\n * same reason: every rule had hand-written the same one-liner,\n *\n * ```ts\n * const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n * ```\n *\n * …and every one of them was therefore blind to the same thing.\n *\n * ## What the one-liner misses\n *\n * `FlowRegionSchema` (`@objectstack/spec/automation`) holds a FULL\n * `nodes: z.array(FlowNodeSchema)`, and four config slots carry one:\n *\n * | node type | slot(s) |\n * |-------------|----------------------------------|\n * | `try_catch` | `config.try`, `config.catch` |\n * | `loop` | `config.body` |\n * | `parallel` | `config.branches[].nodes` |\n *\n * Regions nest arbitrarily (a region node may itself be a `try_catch`). Before\n * this walk, a node moved into any of them left the checking behind:\n * `flow-node-write-unknown-field` and `flow-update-readonly-field` — both\n * GATING errors — reported nothing, and `approval-approver-*` went quiet too.\n *\n * `validate-flow-template-paths` failed a third way, worth naming because it is\n * the one a reader would not predict: it scans a node's whole `config` for\n * string leaves, so it still SAW tokens inside a region — but its `filter`\n * position split only looks at the top level of the node it was handed, so a\n * nested filter token lost its position and the #3810 finding silently\n * downgraded from `error` to `warning`, reported against the wrapping\n * `try_catch` instead of the `get_record` that cannot run. Being visible is not\n * the same as being judged correctly, which is why {@link WalkedFlowNode}\n * carries a real per-node `path` rather than only the node object.\n *\n * ## The double-count trap\n *\n * A container node is yielded too — it has its own config worth checking (a\n * `loop`'s `collection`, a `try_catch`'s `retry`). But its `config` physically\n * CONTAINS every descendant, so any rule that walks config recursively would\n * report each nested finding twice: once at the inner node, once at the\n * container. {@link WalkedFlowNode.localConfig} is the container's config with\n * the region slots removed — the view a recursive scan must use. Rules that\n * read named keys (`config.fields`, `config.objectName`) can use either.\n */\n\nimport { FLOW_REGION_SLOTS_BY_TYPE, FLOW_REGION_CONFIG_KEYS } from '@objectstack/spec/automation';\n\nexport type AnyRec = Record<string, unknown>;\n\nfunction isRec(v: unknown): v is AnyRec {\n return !!v && typeof v === 'object' && !Array.isArray(v);\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/**\n * Config keys that hold a nested region, by owning node type.\n *\n * Projected from `@objectstack/spec/automation` rather than declared here\n * (#4401). This used to be a local copy with its own reconciliation test — as\n * did the ADR-0087 conversion walk's copy and the spec-side control-flow walk's.\n * Three tables, three tests each pinning its own copy, and nothing that would\n * fail if they drifted from ONE ANOTHER: every copy was individually protected\n * and the set was not. A fourth construct is now a single entry in\n * `spec/src/automation/region-slots.ts`.\n *\n * The **walk** below stays here. It takes raw authored records (not\n * `FlowNodeParsed`), and it yields per-node diagnostic paths and label trails —\n * formatting that is lint's business, not the protocol's (Prime Directive #2).\n * Only the table is shared; the three traversals stay separate because they walk\n * different units for different consumers.\n */\nexport const REGION_SLOTS: ReadonlyMap<string, readonly string[]> = new Map(\n [...FLOW_REGION_SLOTS_BY_TYPE].map(([type, slots]) => [type, slots.map(s => s.key)]),\n);\n\n/** Every config key that may hold region nodes, across all node types. */\nexport const REGION_CONFIG_KEYS: ReadonlySet<string> = FLOW_REGION_CONFIG_KEYS;\n\n/**\n * Depth cap. Regions are a tree in parsed metadata, so this is not a cycle\n * guard — it is a cheap promise that a hand-authored (pre-parse) stack cannot\n * make a lint hang. Well past anything reviewable: five levels of nested\n * try/loop/parallel is already an unreadable flow.\n */\nexport const MAX_REGION_DEPTH = 16;\n\n/** A visited flow node plus everything needed to locate and describe it. */\nexport interface WalkedFlowNode {\n /** The node record itself. */\n node: AnyRec;\n /** Config path, e.g. `flows[0].nodes[1].config.catch.nodes[0]`. */\n path: string;\n /**\n * The node's config with region slots stripped — what a rule that scans\n * config RECURSIVELY must read, or it reports every descendant's finding a\n * second time against this node. `undefined` when the node has no config.\n */\n localConfig?: AnyRec;\n /**\n * Region breadcrumb from the flow root, e.g. `try_catch \"Guard\" › catch`.\n * Empty string for a top-level node, so a caller can append it unconditionally.\n */\n regionTrail: string;\n /** 0 for a top-level node; 1 inside one region; and so on. */\n depth: number;\n}\n\n/** A node's label for diagnostics: `label` → `id` → `#index`. */\nexport function flowNodeLabel(node: AnyRec, index: number): string {\n return strName(node.label) ?? strName(node.id) ?? `#${index}`;\n}\n\n/** `config` minus the region slots, or `undefined` when there is no config. */\nfunction stripRegions(config: unknown): AnyRec | undefined {\n if (!isRec(config)) return undefined;\n let out: AnyRec | undefined;\n for (const key of Object.keys(config)) {\n if (!REGION_CONFIG_KEYS.has(key)) continue;\n out ??= { ...config };\n delete out[key];\n }\n return out ?? config;\n}\n\n/**\n * Walk every node of a flow, depth-first, including those nested in\n * `try_catch` / `loop` / `parallel` regions. Yields each with its own config\n * path, so a finding lands on the node that is actually wrong.\n *\n * `flowPath` is the caller's path prefix for the flow (e.g. `flows[3]`).\n */\nexport function walkFlowNodes(flow: AnyRec, flowPath: string): WalkedFlowNode[] {\n const out: WalkedFlowNode[] = [];\n if (!isRec(flow)) return out;\n\n const visitList = (nodes: unknown, basePath: string, trail: string, depth: number): void => {\n if (!Array.isArray(nodes) || depth > MAX_REGION_DEPTH) return;\n nodes.forEach((raw, index) => {\n if (!isRec(raw)) return;\n const path = `${basePath}[${index}]`;\n out.push({\n node: raw,\n path,\n localConfig: stripRegions(raw.config),\n regionTrail: trail,\n depth,\n });\n\n const type = strName(raw.type);\n const slots = type ? REGION_SLOTS.get(type) : undefined;\n if (!slots || !isRec(raw.config)) return;\n const config = raw.config;\n const here = `${type} \"${flowNodeLabel(raw, index)}\"`;\n\n for (const slot of slots) {\n const value = config[slot];\n if (slot === 'branches') {\n // parallel: an array of regions, each with its own nodes.\n if (!Array.isArray(value)) continue;\n value.forEach((branch, b) => {\n if (!isRec(branch)) return;\n const branchName = strName(branch.name) ?? `#${b}`;\n visitList(\n branch.nodes,\n `${path}.config.branches[${b}].nodes`,\n joinTrail(trail, `${here} › branch ${branchName}`),\n depth + 1,\n );\n });\n continue;\n }\n if (!isRec(value)) continue;\n visitList(\n value.nodes,\n `${path}.config.${slot}.nodes`,\n joinTrail(trail, `${here} › ${slot}`),\n depth + 1,\n );\n }\n });\n };\n\n visitList(flow.nodes, `${flowPath}.nodes`, '', 0);\n return out;\n}\n\nfunction joinTrail(trail: string, segment: string): string {\n return trail ? `${trail} › ${segment}` : segment;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for `{record.<path>}` template references in a\n// record-change flow's node config (#3426).\n//\n// A `notify` / `update_record` / `http` / ... node interpolates\n// `{record.<field>}` tokens against the triggering record. Two authoring\n// mistakes render a SILENT empty string at runtime, with no design-time\n// signal — exactly the failure #3426 reported:\n//\n// 1. `{record.<unknown>}` — the path head is neither a declared field nor a\n// system column. Almost always a typo (`{record.full_naem}`). The template\n// engine resolves it to `undefined` -> '' with no warning.\n//\n// 2. `{record.<lookup>.<subfield>}` — a cross-object hop through a lookup /\n// master_detail / user / tree relation. The seeded flow record carries the\n// relation as a SCALAR foreign-key id, not an expanded object (a default\n// data-API read does not expand relations either — see #3426's hydration\n// note and #1872). So `record.account.name` walks `.name` on a string id\n// and yields '' silently. Not resolved today; tracked on #3426.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` and\n// reusable by AI authoring.\n//\n// SEVERITY FOLLOWS THE RUNTIME CONSEQUENCE, which differs by POSITION:\n//\n// - Everywhere else (a message body, an http url, a write payload) an\n// unresolved token renders a blank. The output is wrong but the run\n// completes, and the head object may legitimately come from another\n// installed package (skipped — see below). Advisory: WARNING.\n//\n// - Inside a filter-guarded CRUD node's `filter`, an unresolved token used to\n// DELETE the condition from the query, and a removed condition matches MORE\n// rows — `delete_record` with its only condition gone matched every row.\n// Since framework#3810 those nodes REFUSE TO EXECUTE. So a finding here is\n// not \"the output will be blank\", it is \"this node cannot run\": the build\n// is shipping a flow whose runtime is already decided. Gating: ERROR.\n//\n// The split is the same shift-left `validateReadonlyFlowWrites` makes — a\n// certain runtime failure gates the build, a state-dependent one advises — and\n// it keeps this rule honest about what it found. Catching the typo at build\n// time beats a failed run at 3am; catching it and calling it advisory, when the\n// runtime has already committed to refusing, understates it.\n//\n// Deliberately conservative to keep false positives near zero:\n// - Only `record.`-prefixed tokens are checked. Other `{var}` tokens address\n// flow variables / node outputs the rule cannot resolve statically.\n// - Only flows bound to an object THIS stack defines are checked; when the\n// object is unknown here (another package, `sys_*`) the rule has no schema\n// to compare against and skips the whole flow.\n// - `formula` / `summary` fields are VALID heads (formula is hydrated onto the\n// record since #3445; summary is stored on write) — never flagged.\n// - A trailing NUMERIC segment (`{record.target_channels.0}`) is an array\n// index into a `multiple` lookup (#1872), not a cross-object hop — allowed.\n// - Structured scalar heads (`json` / `composite` / `repeater` / `record`) may\n// carry legitimate sub-paths — their `.<sub>` access is left alone.\n\nimport { SYSTEM_FIELDS } from './system-fields.js';\nimport { walkFlowNodes } from './flow-walk.js';\n\nexport type FlowTemplatePathSeverity = 'error' | 'warning';\n\nexport interface FlowTemplatePathFinding {\n severity: FlowTemplatePathSeverity;\n rule: string;\n /** Human-readable location, e.g. `flow \"notify_lead\" node \"notify\"`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[2]`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries).\nexport const FLOW_TEMPLATE_UNKNOWN_FIELD = 'flow-template-unknown-field';\nexport const FLOW_TEMPLATE_LOOKUP_TRAVERSAL = 'flow-template-lookup-traversal';\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({\n name,\n ...(def as AnyRec),\n }));\n }\n return [];\n}\n\n// Path heads addressable in a `{record.<col>}` template without being authored\n// fields: the package-shared registry-injected columns (`system-fields.ts`,\n// #4330) plus three heads this rule has always exempted. `name`, `owner` and\n// `record_type` are NOT registry-injected system columns (`name` in particular\n// is an ordinary authored field on most objects), so they stay rule-local —\n// see the shared module's note — instead of widening every field-existence\n// rule in the package.\nconst IMPLICIT_HEADS: ReadonlySet<string> = new Set([\n ...SYSTEM_FIELDS,\n 'name', 'owner', 'record_type',\n]);\n\n// Field types that address ANOTHER object — a `.<subfield>` hop through one is\n// a cross-object traversal the seeded flow record does not expand.\nconst RELATION_TYPES: ReadonlySet<string> = new Set([\n 'lookup',\n 'master_detail',\n 'user',\n 'tree',\n]);\n\n// The CRUD nodes whose `filter` the runtime guards (framework#3810): each calls\n// `resolveNodeFilter`, which refuses the node when interpolation erased any\n// authored condition. `create_record` is deliberately absent — it writes a\n// payload and has no filter, so an unresolved token there is a blank value on\n// the new row, not a widened query.\nconst FILTER_GUARDED_NODE_TYPES: ReadonlySet<string> = new Set([\n 'get_record',\n 'update_record',\n 'delete_record',\n]);\n\n/** Build a `fieldName -> type` map for an object (declared fields only). */\nfunction fieldTypesOf(obj: AnyRec): Map<string, string> {\n const types = new Map<string, string>();\n for (const f of asArray(obj.fields)) {\n if (typeof f.name === 'string') {\n types.set(f.name, typeof f.type === 'string' ? f.type : '');\n }\n }\n return types;\n}\n\n/**\n * Extract the `record.<path>` references from a template string. Mirrors the\n * runtime interpolator's token grammar (service-automation builtin/template.ts):\n * a `{...}` token whose body is a dotted path whose HEAD is `record`. Arithmetic\n * / function tokens (`{NOW()}`, `{a + b}`) and non-`record` heads are ignored.\n *\n * Returns each reference's segment list AFTER the `record` head, e.g.\n * `{record.account.name}` -> `[['account', 'name']]`.\n */\nfunction recordRefsIn(text: string): string[][] {\n const refs: string[][] = [];\n const tokenRe = /\\{([^{}]+)\\}/g;\n let m: RegExpExecArray | null;\n while ((m = tokenRe.exec(text)) !== null) {\n const body = m[1].trim();\n // Pure dotted path only (same shape the interpolator's fast path accepts):\n // identifier head, then identifier-or-numeric segments. Anything with\n // operators / spaces / quotes is an arithmetic token — not a bare field ref.\n if (!/^[A-Za-z_$][\\w$]*(?:\\.(?:[A-Za-z_$][\\w$]*|\\d+))*$/.test(body)) continue;\n const segments = body.split('.');\n if (segments[0] !== 'record') continue;\n const rest = segments.slice(1);\n if (rest.length > 0) refs.push(rest);\n }\n return refs;\n}\n\n/** Recursively collect templated string leaves from a config-bearing block. */\nfunction stringLeaves(value: unknown, out: string[]): void {\n if (typeof value === 'string') {\n if (value.includes('{')) out.push(value);\n return;\n }\n if (Array.isArray(value)) {\n for (const v of value) stringLeaves(v, out);\n return;\n }\n if (value && typeof value === 'object') {\n for (const v of Object.values(value as AnyRec)) stringLeaves(v, out);\n }\n}\n\n// The typed config blocks + freeform `config` a node interpolates at runtime.\n// We scan every string leaf under these (the runtime `interpolate()` walks the\n// whole config recursively), NOT `id` / `type` / `label` / `position`, which are\n// never templated.\nconst NODE_CONFIG_KEYS = [\n 'config',\n 'notify',\n 'update_record',\n 'create_record',\n 'http',\n 'script',\n 'screen',\n 'wait',\n 'approval',\n 'connector_action',\n 'subflow',\n 'decision',\n 'start',\n];\n\n/** A templated string leaf plus the one thing severity depends on: where it sits. */\ninterface TemplateLeaf {\n text: string;\n /** Inside a filter-guarded CRUD node's `filter` — an unresolved token there is refused at runtime. */\n inFilter: boolean;\n}\n\n/**\n * Collect a node's templated string leaves, tagging those that sit under a\n * `filter` key when the node type is one the runtime guards.\n *\n * `guarded` leaves are returned FIRST so the per-node dedupe below resolves a\n * reference that appears in both positions at its higher severity: one typo\n * used in a filter and echoed in a message is an error, not a warning.\n */\nfunction collectNodeLeaves(node: AnyRec, guarded: boolean): TemplateLeaf[] {\n const filterLeaves: TemplateLeaf[] = [];\n const otherLeaves: TemplateLeaf[] = [];\n\n for (const key of NODE_CONFIG_KEYS) {\n if (!(key in node)) continue;\n const block = node[key];\n const splitFilter = guarded && !!block && typeof block === 'object' && !Array.isArray(block);\n\n if (splitFilter) {\n const { filter, ...rest } = block as AnyRec;\n const inFilter: string[] = [];\n stringLeaves(filter, inFilter);\n for (const text of inFilter) filterLeaves.push({ text, inFilter: true });\n const outside: string[] = [];\n stringLeaves(rest, outside);\n for (const text of outside) otherLeaves.push({ text, inFilter: false });\n continue;\n }\n\n const plain: string[] = [];\n stringLeaves(block, plain);\n for (const text of plain) otherLeaves.push({ text, inFilter: false });\n }\n\n return [...filterLeaves, ...otherLeaves];\n}\n\n/** True when the flow is armed by a record lifecycle event. */\nfunction isRecordTriggered(flow: AnyRec, startConfig: AnyRec): boolean {\n if (flow.type === 'record_change') return true;\n const triggerType = typeof startConfig.triggerType === 'string' ? startConfig.triggerType : undefined;\n return !!triggerType && triggerType.startsWith('record-');\n}\n\n/** Resolve the object a record-change flow binds to, from its start node. */\nfunction boundObjectOf(flow: AnyRec): string | undefined {\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n const start = nodes.find((n) => n?.type === 'start');\n if (!start) return undefined;\n const config = (start.config ?? {}) as AnyRec;\n const typed = (start.start ?? {}) as AnyRec;\n const fromConfig = typeof config.objectName === 'string' ? config.objectName : undefined;\n const fromTyped = typeof typed.objectName === 'string' ? typed.objectName : undefined;\n return fromConfig ?? fromTyped;\n}\n\n/**\n * The lookup relations a record-change flow opted IN to expand, from the start\n * node's `config.expand` (#3475). A `{record.<rel>.<field>}` hop through one of\n * these IS resolved at run time — the engine re-reads it as the run's identity —\n * so the traversal warning is suppressed for those relations. Accepts a `string`\n * or `string[]`; anything else yields the empty set.\n */\nfunction declaredExpandOf(flow: AnyRec): Set<string> {\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n const start = nodes.find((n) => n?.type === 'start');\n const raw = ((start?.config ?? {}) as AnyRec).expand;\n if (typeof raw === 'string') return new Set(raw ? [raw] : []);\n if (Array.isArray(raw)) return new Set(raw.filter((r): r is string => typeof r === 'string' && r.length > 0));\n return new Set();\n}\n\n/**\n * Validate `{record.<path>}` template references across every record-change\n * flow. Pure and dependency-free; safe on pre- or post-parse stacks.\n */\nexport function validateFlowTemplatePaths(stack: AnyRec): FlowTemplatePathFinding[] {\n const findings: FlowTemplatePathFinding[] = [];\n const flows = asArray(stack.flows);\n if (flows.length === 0) return findings;\n\n const objectsByName = new Map<string, AnyRec>();\n for (const obj of asArray(stack.objects)) {\n if (typeof obj.name === 'string') objectsByName.set(obj.name, obj);\n }\n\n flows.forEach((flow, flowIndex) => {\n const flowName = typeof flow.name === 'string' ? flow.name : `#${flowIndex}`;\n const nodes = Array.isArray(flow.nodes) ? (flow.nodes as AnyRec[]) : [];\n const start = (nodes.find((n) => n?.type === 'start')?.config ?? {}) as AnyRec;\n if (!isRecordTriggered(flow, start)) return;\n\n const objectName = boundObjectOf(flow);\n if (!objectName) return;\n const obj = objectsByName.get(objectName);\n // Unknown object here -> no schema to compare against (another package /\n // `sys_*`). The trigger-readiness rule already flags a wrong name; we can't\n // meaningfully classify field paths, so skip the whole flow.\n if (!obj) return;\n\n const fieldTypes = fieldTypesOf(obj);\n const expandSet = declaredExpandOf(flow);\n\n // Every node, INCLUDING those nested in try_catch / loop / parallel regions\n // (#4380). This rule was not merely blind to them — it was WORSE than\n // blind: the recursive string-leaf scan already saw a nested node's tokens\n // through its container's `config`, but `collectNodeLeaves` splits `filter`\n // only at the top level of the node it is handed, so a nested filter token\n // lost its position and the gating #3810 finding silently degraded to a\n // warning reported against the wrapping `try_catch`. Walking to the real\n // node restores both the severity and the location.\n walkFlowNodes(flow, `flows[${flowIndex}]`).forEach(({ node, path: nodePath, regionTrail, localConfig }, walkIndex) => {\n const nodeLabel =\n typeof node.type === 'string' ? node.type : typeof node.id === 'string' ? node.id : `#${walkIndex}`;\n const where = regionTrail\n ? `flow \"${flowName}\" ${regionTrail} node \"${nodeLabel}\"`\n : `flow \"${flowName}\" node \"${nodeLabel}\"`;\n\n // Collect templated string leaves from the config-bearing blocks only,\n // tagging filter positions when this node type guards its filter (#3810).\n const nodeType = typeof node.type === 'string' ? node.type : '';\n const guarded = FILTER_GUARDED_NODE_TYPES.has(nodeType);\n // Scan the container's config WITHOUT its region slots: their nodes are\n // walked in their own right, and leaving them in would report every\n // nested finding a second time against the container.\n const scanNode =\n localConfig !== undefined && localConfig !== node.config\n ? ({ ...node, config: localConfig } as AnyRec)\n : (node as AnyRec);\n const leaves = collectNodeLeaves(scanNode, guarded);\n if (leaves.length === 0) return;\n\n // Dedupe references so one repeated typo yields one finding per node.\n const seenUnknown = new Set<string>();\n const seenTraversal = new Set<string>();\n\n for (const leaf of leaves) {\n const inFilter = leaf.inFilter;\n for (const rest of recordRefsIn(leaf.text)) {\n const head = rest[0];\n const hasSubPath = rest.length > 1;\n // A trailing numeric segment is an array index (#1872), not a hop.\n const nextIsIdentifier = hasSubPath && !/^\\d+$/.test(rest[1]);\n\n const isKnown = fieldTypes.has(head) || IMPLICIT_HEADS.has(head);\n\n if (!isKnown) {\n if (seenUnknown.has(head)) continue;\n seenUnknown.add(head);\n findings.push({\n severity: inFilter ? 'error' : 'warning',\n rule: FLOW_TEMPLATE_UNKNOWN_FIELD,\n where,\n path: nodePath,\n message: inFilter\n ? `${nodeType} filter references '{record.${rest.join('.')}}', but '${head}' is not a field on ` +\n `object '${objectName}' — the token resolves to nothing, which DROPS the condition from the ` +\n `query instead of narrowing it. The node refuses to run at execution time (#3810).`\n : `template references '{record.${rest.join('.')}}', but '${head}' is not a field on ` +\n `object '${objectName}' — it resolves to an empty string at runtime (silently).`,\n hint: inFilter\n ? `Check the field name against the object's field definitions (e.g. '{record.full_name}', ` +\n `not '{record.full_naem}'); system columns like id/created_at/owner are also addressable. ` +\n `This gates the build rather than warning: an absent condition WIDENS the query, so the ` +\n `runtime has already decided to refuse this node.`\n : `Check the field name against the object's field definitions (e.g. '{record.full_name}', ` +\n `not '{record.full_naem}'). System columns like id/created_at/owner are also addressable.`,\n });\n continue;\n }\n\n if (nextIsIdentifier) {\n const headType = fieldTypes.get(head) ?? '';\n if (RELATION_TYPES.has(headType) && !expandSet.has(head)) {\n const key = rest.join('.');\n if (seenTraversal.has(key)) continue;\n seenTraversal.add(key);\n findings.push({\n severity: inFilter ? 'error' : 'warning',\n rule: FLOW_TEMPLATE_LOOKUP_TRAVERSAL,\n where,\n path: nodePath,\n message: inFilter\n ? `${nodeType} filter references '{record.${key}}', a cross-object hop through the ` +\n `${headType} field '${head}' — the flow record carries '${head}' as a scalar id, not an ` +\n `expanded object, so the token resolves to nothing and the condition is DROPPED from the ` +\n `query instead of narrowing it. The node refuses to run at execution time (#3810).`\n : `template references '{record.${key}}', a cross-object hop through the ${headType} field ` +\n `'${head}' — the flow record carries '${head}' as a scalar id, not an expanded object, so ` +\n `this resolves to an empty string at runtime (silently).`,\n hint: inFilter\n ? `Opt in to resolve it: add '${head}' to the start node's config.expand (#3475) and the ` +\n `engine re-reads it as the run's identity. Otherwise filter on the foreign-key id directly ` +\n `('{record.${head}}'), or project the value via a formula field on '${objectName}'. This ` +\n `gates the build rather than warning: an absent condition WIDENS the query.`\n : `Opt in to resolve it: add '${head}' to the start node's config.expand (#3475) and the ` +\n `engine re-reads it as the run's identity. Otherwise reference the foreign-key id directly ` +\n `('{record.${head}}'), or project the value via a formula field on '${objectName}'.`,\n });\n }\n // STRUCTURED_TYPES + any other scalar `.sub` access is left alone:\n // json/composite/record sub-paths are legitimate in-row reads, and\n // a plain scalar `.sub` is rare enough that flagging it would risk\n // more false positives than it prevents.\n }\n }\n }\n });\n });\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail: a flow `update_record` node that writes a field the\n// target object declares `readonly: true`, under a non-system run identity, is\n// a SILENT NO-OP. The objectql engine strips static-`readonly` fields from a\n// non-system UPDATE payload (#2948), so the intended write never lands — yet\n// the step still reports `success`. #3407/#3413 made that strip observable at\n// RUN time (a step warning + `droppedFields`); this rule shifts the discovery\n// LEFT to `os validate` / `os build`, so an author finds the mismatch at design\n// time instead of by reading server WARN logs days later (#3425).\n//\n// Scope — deliberately narrow to keep it false-positive-free:\n//\n// • Only `update_record`. INSERT is engine-exempt from the readonly strip (a\n// `create_record` may legitimately seed readonly columns; the ingress strip\n// added in #3043 lives in metadata-protocol, which the flow engine bypasses\n// by calling the data engine directly), so a create writing a readonly\n// field is NOT a no-op and is never flagged.\n//\n// • Only `runAs !== 'system'`. A `runAs:'system'` run is elevated and the\n// engine skips the strip entirely, so a system flow legitimately MAINTAINS\n// readonly fields (\"users can't edit this, but automation does\"). That is\n// the intended channel, so it is never flagged.\n//\n// • Static `readonly:true` + a LITERAL field name is a 100%-certain no-op →\n// ERROR (gates the build). `readonlyWhen` is per-record-state — it strips\n// only on records whose predicate is TRUE at run time, so it MAY silently\n// not land → WARNING (advisory). A templated object name or a non-literal\n// `fields` map is not statically knowable → skipped, no guess.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019): no I/O, no runtime. Shared by\n// the CLI and any other consumer (AI authoring), so hand-authored and generated\n// flows are held to the same bar.\n\nimport { walkFlowNodes, flowNodeLabel } from './flow-walk.js';\n\nexport type ReadonlyFlowWriteSeverity = 'error' | 'warning';\n\nexport interface ReadonlyFlowWriteFinding {\n severity: ReadonlyFlowWriteSeverity;\n rule: string;\n /** Human-readable location, e.g. `flow \"approve_deal\" › node \"Mark approved\"`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[3].config.fields.approval_status`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries).\nexport const FLOW_UPDATE_READONLY_FIELD = 'flow-update-readonly-field';\nexport const FLOW_UPDATE_READONLY_WHEN_FIELD = 'flow-update-readonly-when-field';\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({\n name,\n ...(def as AnyRec),\n }));\n }\n return [];\n}\n\ninterface FieldReadonlyMeta {\n /** Static `readonly: true`. */\n readonly: boolean;\n /** A non-empty `readonlyWhen` predicate is declared. */\n readonlyWhen: boolean;\n}\n\n/**\n * object name → (field name → readonly metadata). Handles both `fields` shapes\n * (array of `{name, readonly, readonlyWhen}` and name-keyed map). A field with\n * neither flag is recorded as `{false, false}` so callers can distinguish a\n * \"known-writable field\" from an \"unknown field\" (absent from the map).\n */\nfunction buildReadonlyIndex(objects: AnyRec[]): Map<string, Map<string, FieldReadonlyMeta>> {\n const idx = new Map<string, Map<string, FieldReadonlyMeta>>();\n for (const obj of objects) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fieldMap = new Map<string, FieldReadonlyMeta>();\n const collect = (fieldName: string, def: AnyRec): void => {\n const rw = def?.readonlyWhen;\n const readonlyWhen = rw != null && !(typeof rw === 'string' && rw.trim() === '');\n fieldMap.set(fieldName, { readonly: def?.readonly === true, readonlyWhen });\n };\n const fields = obj.fields;\n if (Array.isArray(fields)) {\n for (const f of fields as AnyRec[]) {\n const fn = (f as AnyRec)?.name;\n if (typeof fn === 'string') collect(fn, f as AnyRec);\n }\n } else if (fields && typeof fields === 'object') {\n for (const [fn, def] of Object.entries(fields as AnyRec)) collect(fn, def as AnyRec);\n }\n idx.set(name, fieldMap);\n }\n return idx;\n}\n\n/**\n * The target object of an `update_record` node, when statically knowable. Reads\n * the canonical `objectName` and its historical `object` alias — a pre-parse\n * source may still carry the alias during the protocol-17 window, until the\n * 'flow-node-crud-object-alias' conversion (#3796) canonicalizes it at load. A\n * templated value (contains `{`) is dynamic — return undefined so the node is\n * skipped rather than guessed.\n */\nfunction readLiteralObjectName(config: AnyRec): string | undefined {\n const raw = config.objectName ?? config.object;\n if (typeof raw !== 'string' || raw.includes('{')) return undefined;\n return raw || undefined;\n}\n\n/**\n * Validate flow `update_record` writes against target-object readonly\n * declarations. Pure and dependency-free; safe on pre- or post-parse stacks.\n */\nexport function validateReadonlyFlowWrites(stack: AnyRec): ReadonlyFlowWriteFinding[] {\n const findings: ReadonlyFlowWriteFinding[] = [];\n const flows = asArray(stack.flows);\n if (flows.length === 0) return findings;\n\n const roIndex = buildReadonlyIndex(asArray(stack.objects));\n\n flows.forEach((flow, flowIndex) => {\n // `runAs` defaults to 'user' (schema default). Only an explicit 'system'\n // run bypasses the strip, so treat anything else — including an unauthored\n // (undefined) runAs — as strip-subject.\n if (flow.runAs === 'system') return;\n const runAs = flow.runAs === 'user' || flow.runAs === 'system' ? flow.runAs : 'user';\n\n const flowName = typeof flow.name === 'string' ? flow.name : `#${flowIndex}`;\n // Every node, INCLUDING those nested in try_catch / loop / parallel regions.\n // A readonly write inside a `catch` branch is the same certain no-op as one\n // at the top level, and this rule gates on it (#4380).\n const walked = walkFlowNodes(flow, `flows[${flowIndex}]`);\n\n walked.forEach(({ node, path: nodePath, regionTrail }, walkIndex) => {\n if (node?.type !== 'update_record') return;\n const config = (node.config ?? {}) as AnyRec;\n\n const objectName = readLiteralObjectName(config);\n if (!objectName) return; // templated / dynamic object — not statically knowable\n const fieldMap = roIndex.get(objectName);\n if (!fieldMap) return; // object defined by another package — cannot judge its fields\n\n const fields = config.fields;\n // A non-literal write map (templated string, spread, array) is not\n // statically knowable — skip rather than guess.\n if (!fields || typeof fields !== 'object' || Array.isArray(fields)) return;\n\n const nodeName = flowNodeLabel(node, walkIndex);\n const where = regionTrail\n ? `flow \"${flowName}\" › ${regionTrail} › node \"${nodeName}\"`\n : `flow \"${flowName}\" › node \"${nodeName}\"`;\n\n for (const fieldName of Object.keys(fields as AnyRec)) {\n const meta = fieldMap.get(fieldName);\n // Unknown field — `validate-flow-node-writes.ts` owns that question\n // (`flow-node-write-unknown-field`, also gating). This rule is about a\n // field the object DOES declare and the engine then strips; a name that\n // resolves to no column is a different failure with a different fix, so\n // the two never double-report the same key.\n if (!meta) continue;\n\n if (meta.readonly) {\n findings.push({\n severity: 'error',\n rule: FLOW_UPDATE_READONLY_FIELD,\n where,\n path: `${nodePath}.config.fields.${fieldName}`,\n message:\n `writes field '${fieldName}', which object '${objectName}' declares readonly:true. Under ` +\n `runAs:'${runAs}' the engine silently strips readonly fields from the UPDATE payload (#2948), ` +\n `so this write never lands — while the step still reports success.`,\n hint:\n `If automation is meant to maintain this field, declare the flow runAs:'system' (the intended ` +\n `channel — readonly governs the end-user/API surface, not trusted system writers). Otherwise ` +\n `remove '${fieldName}' from this update_record node.`,\n });\n } else if (meta.readonlyWhen) {\n findings.push({\n severity: 'warning',\n rule: FLOW_UPDATE_READONLY_WHEN_FIELD,\n where,\n path: `${nodePath}.config.fields.${fieldName}`,\n message:\n `writes field '${fieldName}', which object '${objectName}' declares readonlyWhen. On records ` +\n `where that predicate is TRUE, a runAs:'${runAs}' UPDATE strips the field (#3042), so this ` +\n `write may silently not land depending on the record's state.`,\n hint:\n `If automation must maintain this field regardless of record state, run the flow runAs:'system'. ` +\n `Otherwise confirm this node only targets records whose readonlyWhen predicate is FALSE.`,\n });\n }\n }\n });\n });\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for the `defineView` container shape.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate`. It\n// catches the \"flat view object\" authoring mistake the schema alone cannot\n// surface: `ViewSchema` is a container (`{ list, form, listViews, formViews }`)\n// whose slots are all optional, and Zod strips unknown keys — so a flat list\n// view (`{ name: 'all_tasks', label, type: 'grid', columns: [...] }`) parses\n// to an EMPTY container. The stack validates, the loader finds nothing to\n// expand, and the Console silently renders no view (no switcher entry). The\n// third-party 15.1 evaluation hit exactly this via the old docs.\n//\n// Runs PRE-parse (on the normalizeStackInput output, before the\n// ObjectStackDefinition parse): post-parse the flat keys are already stripped\n// and the mistake is indistinguishable from an intentionally empty container.\n//\n// Independent ViewItems (`viewKind` + `config`) are legal `views: []` entries\n// (the loader registers them as-is) and are not flagged.\n\nexport type ViewContainerSeverity = 'error' | 'warning';\n\nexport interface ViewContainerFinding {\n severity: ViewContainerSeverity;\n rule: string;\n /** Human-readable location, e.g. `views[0] (\"all_tasks\")`. */\n where: string;\n /** Config path, e.g. `views[0]`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const VIEW_CONTAINER_SHAPE = 'view-container-shape';\n\ntype AnyRec = Record<string, unknown>;\n\nconst CONTAINER_SLOT_KEYS = ['list', 'form', 'listViews', 'formViews'] as const;\n\n/** Coerce an array-or-name-keyed-map collection to indexed entries. */\nfunction asEntries(v: unknown): Array<{ key: string; value: unknown }> {\n if (Array.isArray(v)) return v.map((value, i) => ({ key: `[${i}]`, value }));\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, value]) => ({ key: `.${name}`, value }));\n }\n return [];\n}\n\n/** Number of views a parsed-or-raw container actually carries. */\nfunction containerViewCount(rec: AnyRec): number {\n const named = (slot: unknown): number =>\n slot && typeof slot === 'object' && !Array.isArray(slot) ? Object.keys(slot as AnyRec).length : 0;\n return (rec.list ? 1 : 0) + (rec.form ? 1 : 0) + named(rec.listViews) + named(rec.formViews);\n}\n\n/**\n * Validate that every stack-level `views` entry is a real view container (or\n * an independent ViewItem). Flat list-view objects and view-less containers\n * are reported as errors with a wrap-it fix hint.\n */\nexport function validateViewContainers(stack: Record<string, unknown>): ViewContainerFinding[] {\n const out: ViewContainerFinding[] = [];\n if (!stack || typeof stack !== 'object') return out;\n\n for (const { key, value } of asEntries((stack as AnyRec).views)) {\n // Non-object entries are the schema step's problem, not this rule's.\n if (!value || typeof value !== 'object' || Array.isArray(value)) continue;\n const rec = value as AnyRec;\n\n // Independent ViewItem (`viewKind` discriminator) — registered as-is.\n if (rec.viewKind != null) continue;\n\n if (containerViewCount(rec) > 0) continue;\n\n const label = typeof rec.name === 'string' ? ` (\"${rec.name}\")` : '';\n const hasContainerSlot = CONTAINER_SLOT_KEYS.some((k) => k in rec);\n // Flat list-view fingerprint: view-ish keys at the top level where the\n // container slots should be.\n const looksFlat = !hasContainerSlot\n && ['type', 'columns', 'data', 'filter', 'sort'].some((k) => k in rec);\n\n out.push({\n severity: 'error',\n rule: VIEW_CONTAINER_SHAPE,\n where: `views${key}${label}`,\n path: `views${key}`,\n message: looksFlat\n ? 'Flat list-view object is not a view container: `ViewSchema` strips its keys, '\n + 'so it parses to an EMPTY container — zero views register and the Console '\n + 'renders no view for it.'\n : 'View container defines no views — all of `list` / `form` / `listViews` / '\n + '`formViews` are absent or empty, so nothing registers.',\n hint: 'Wrap every view in a defineView container: defineView({ list: { type, data, '\n + 'columns, ... }, listViews: { ... }, formViews: { ... } }). See '\n + 'examples/app-showcase/src/ui/views/task.view.ts.',\n });\n }\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time diagnostics for the SDUI scoped-styling model (ADR-0065).\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019): the same bar holds for\n// hand-authored and AI-generated pages, run from `os validate`/`compile` and\n// reusable by AI authoring. It catches the deterministic ways a `responsiveStyles`\n// block silently fails or drifts — the class of mistake an AI author is most\n// likely to make — *before* render, with actionable hints it can self-correct on.\n//\n// What it does NOT catch: whether the result looks good. Visual/semantic quality\n// (contrast, balance, \"is it ugly\") is only catchable by rendering + a VLM gate,\n// which is a separate, render-time concern (ADR-0065 §Decision-5).\n\nexport type StyleSeverity = 'error' | 'warning';\n\nexport interface StyleFinding {\n severity: StyleSeverity;\n rule: string;\n /** Human-readable location, e.g. `page \"pricing\" › node \"plan_solo\"`. */\n where: string;\n /** Config path, e.g. `pages[0].regions[0].components[1]`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries).\nexport const STYLE_NODE_MISSING_ID = 'style-node-missing-id';\nexport const STYLE_CLASSNAME_TAILWIND = 'style-classname-tailwind';\nexport const STYLE_RESPONSIVE_NO_BASE = 'style-responsive-no-base';\nexport const STYLE_UNKNOWN_CSS_PROPERTY = 'style-unknown-css-property';\nexport const STYLE_UNKNOWN_TOKEN = 'style-unknown-token';\n\ntype AnyRec = Record<string, unknown>;\n\nconst BREAKPOINTS = ['large', 'medium', 'small', 'xsmall'] as const;\n\n/** SDUI design-token palette (ADR-0065) + base theme tokens, referenced as\n * `var(--name)`. Authors should resolve values against these. Kept in sync with\n * `apps/console/src/index.css` / `@object-ui/components` `:root`. */\nconst KNOWN_TOKENS = new Set<string>([\n // SDUI tokens\n 'space-1', 'space-2', 'space-3', 'space-4', 'space-5', 'space-6', 'space-8', 'space-10', 'space-12',\n 'radius', 'radius-sm', 'radius-md', 'radius-lg', 'radius-xl',\n 'shadow-sm', 'shadow-md', 'shadow-lg',\n 'surface', 'surface-sunken', 'text-strong', 'text-muted', 'brand', 'brand-foreground', 'hairline',\n // Base theme tokens (shadcn) — usually wrapped as hsl(var(--x)).\n 'background', 'foreground', 'card', 'card-foreground', 'popover', 'popover-foreground',\n 'primary', 'primary-foreground', 'secondary', 'secondary-foreground',\n 'muted', 'muted-foreground', 'accent', 'accent-foreground',\n 'destructive', 'destructive-foreground', 'border', 'input', 'ring',\n 'success', 'success-foreground', 'warning', 'warning-foreground',\n 'chart-1', 'chart-2', 'chart-3', 'chart-4', 'chart-5',\n]);\n\n/** Common CSS properties (camelCase) an SDUI block realistically sets. Generous\n * on purpose: an unknown property is only a *warning* (typo catcher), never a\n * blocker. Custom properties (`--x`) are always allowed. */\nconst KNOWN_CSS_PROPERTIES = new Set<string>([\n 'display', 'position', 'top', 'right', 'bottom', 'left', 'inset', 'zIndex', 'overflow', 'overflowX', 'overflowY', 'visibility', 'boxSizing', 'float', 'clear',\n 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'aspectRatio',\n 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginInline', 'marginBlock',\n 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingInline', 'paddingBlock',\n 'flex', 'flexDirection', 'flexWrap', 'flexGrow', 'flexShrink', 'flexBasis', 'alignItems', 'alignContent', 'alignSelf', 'justifyContent', 'justifyItems', 'justifySelf', 'gap', 'rowGap', 'columnGap', 'order', 'placeItems', 'placeContent',\n 'grid', 'gridTemplate', 'gridTemplateColumns', 'gridTemplateRows', 'gridTemplateAreas', 'gridColumn', 'gridRow', 'gridArea', 'gridAutoFlow', 'gridAutoColumns', 'gridAutoRows',\n 'color', 'backgroundColor', 'background', 'backgroundImage', 'backgroundSize', 'backgroundPosition', 'backgroundRepeat', 'backgroundClip', 'opacity', 'mixBlendMode',\n 'fontSize', 'fontWeight', 'fontFamily', 'fontStyle', 'lineHeight', 'letterSpacing', 'textAlign', 'textTransform', 'textDecoration', 'textOverflow', 'whiteSpace', 'wordBreak', 'overflowWrap', 'fontVariantNumeric', 'verticalAlign', 'textShadow',\n 'border', 'borderTop', 'borderRight', 'borderBottom', 'borderLeft', 'borderColor', 'borderWidth', 'borderStyle', 'borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'outline', 'outlineOffset',\n 'boxShadow', 'transform', 'transformOrigin', 'transition', 'transitionProperty', 'transitionDuration', 'transitionTimingFunction', 'transitionDelay', 'animation', 'filter', 'backdropFilter', 'willChange',\n 'cursor', 'pointerEvents', 'userSelect', 'objectFit', 'objectPosition', 'content',\n]);\n\nconst VAR_RE = /var\\(\\s*--([a-zA-Z0-9-]+)\\s*[,)]/g;\n\n// High-precision Tailwind-utility detection. A `className` in page metadata is\n// \"Tailwind-looking\" if any token is a responsive/state variant, an arbitrary\n// `[…]` value, a known utility stem followed by a Tailwind *value* (number /\n// fraction / size keyword), or a bare layout utility. Tuned to NOT trip on\n// ordinary custom class names (e.g. `my-custom-scope`, `os-s-plan_solo`).\nconst TW_VARIANT = /^(sm|md|lg|xl|2xl|hover|focus|active|disabled|dark|group-hover|peer-[a-z]+|first|last|odd|even):/;\nconst TW_STEM_VALUE = /^-?(p|m|px|py|pt|pb|pl|pr|mx|my|mt|mb|ml|mr|gap|gap-x|gap-y|space-x|space-y|w|h|min-w|max-w|min-h|max-h|size|text|leading|tracking|bg|border|rounded|shadow|ring|opacity|inset|top|bottom|left|right|z|order|col|row|grid-cols|grid-rows|basis)-(\\d+(\\.\\d+)?|\\d+\\/\\d+|px|full|auto|none|screen|min|max|fit|xs|sm|md|lg|xl|2xl|3xl|4xl|5xl|6xl)$/;\nconst TW_BARE = /^(flex|grid|block|inline|inline-block|inline-flex|hidden|contents|table|flow-root|grow|shrink|truncate|italic|underline|uppercase|lowercase|capitalize|antialiased|absolute|relative|fixed|sticky|static|isolate|flex-col|flex-row|flex-wrap|flex-nowrap|items-center|items-start|items-end|items-stretch|justify-center|justify-between|justify-around|justify-start|justify-end|text-center|text-left|text-right|font-bold|font-semibold|font-medium|font-normal|tabular-nums)$/;\n\nfunction looksLikeTailwind(className: string): boolean {\n return className.split(/\\s+/).some((tok) => {\n if (!tok) return false;\n if (TW_VARIANT.test(tok)) return true;\n if (/\\[[^\\]]+\\]/.test(tok)) return true; // arbitrary value, e.g. p-[13px]\n if (TW_STEM_VALUE.test(tok)) return true;\n if (TW_BARE.test(tok)) return true;\n return false;\n });\n}\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** Child nodes can hang off `children`, `properties.children`, `body`, or\n * `properties.body` depending on block type — collect them all. */\nfunction childrenOf(node: AnyRec): AnyRec[] {\n const props = (node.properties as AnyRec) ?? {};\n const out: AnyRec[] = [];\n for (const c of [node.children, props.children, node.body, props.body]) {\n if (Array.isArray(c)) out.push(...(c.filter((x) => x && typeof x === 'object') as AnyRec[]));\n }\n return out;\n}\n\nfunction checkNode(node: AnyRec, pageName: string, path: string, findings: StyleFinding[]): void {\n const id = typeof node.id === 'string' ? node.id : undefined;\n const type = typeof node.type === 'string' ? node.type : 'node';\n const where = `page \"${pageName}\" › ${id ? `node \"${id}\"` : `<${type}>`}`;\n const rs = node.responsiveStyles as AnyRec | undefined;\n const hasRs = !!rs && typeof rs === 'object' && BREAKPOINTS.some((b) => rs[b]);\n\n // (1) responsiveStyles needs an id to scope to — else the CSS is dropped.\n if (hasRs && !id) {\n findings.push({\n severity: 'error', rule: STYLE_NODE_MISSING_ID, where, path,\n message: `Node has responsiveStyles but no \\`id\\`; scoped CSS cannot be generated and the styles are silently dropped.`,\n hint: `Add a stable \\`id\\` to this node.`,\n });\n }\n\n // (2) responsive breakpoint without a `large` base → unstyled at desktop.\n if (hasRs && !rs!.large && BREAKPOINTS.slice(1).some((b) => rs![b])) {\n findings.push({\n severity: 'warning', rule: STYLE_RESPONSIVE_NO_BASE, where, path,\n message: `responsiveStyles sets a smaller breakpoint but no \\`large\\` base; the node is unstyled at desktop width.`,\n hint: `Put the unconditional/base styles under \\`responsiveStyles.large\\` (desktop-first).`,\n });\n }\n\n // (3) className that looks like Tailwind → won't render from metadata.\n if (typeof node.className === 'string' && node.className.trim() && looksLikeTailwind(node.className)) {\n findings.push({\n severity: 'warning', rule: STYLE_CLASSNAME_TAILWIND, where, path,\n message: `\\`className\\` contains Tailwind-looking utilities (\"${node.className.trim().slice(0, 60)}\"); these are not compiled from metadata and will silently do nothing.`,\n hint: `Style this node with \\`responsiveStyles\\` + design tokens instead of \\`className\\` (ADR-0065).`,\n });\n }\n\n // (4)+(5) unknown CSS property / unknown token inside each breakpoint map.\n if (rs && typeof rs === 'object') {\n for (const bp of BREAKPOINTS) {\n const map = rs[bp] as AnyRec | undefined;\n if (!map || typeof map !== 'object') continue;\n for (const [prop, value] of Object.entries(map)) {\n if (!prop.startsWith('--') && !KNOWN_CSS_PROPERTIES.has(prop)) {\n findings.push({\n severity: 'warning', rule: STYLE_UNKNOWN_CSS_PROPERTY, where, path: `${path}.responsiveStyles.${bp}`,\n message: `Unknown CSS property \"${prop}\" (typo?); if unintended it will not apply.`,\n hint: `Use a camelCase CSS property name (e.g. \\`flexDirection\\`, \\`backgroundColor\\`).`,\n });\n }\n if (typeof value === 'string') {\n let m: RegExpExecArray | null;\n VAR_RE.lastIndex = 0;\n while ((m = VAR_RE.exec(value))) {\n const token = m[1];\n if (!KNOWN_TOKENS.has(token) && !token.startsWith('tw-')) {\n findings.push({\n severity: 'warning', rule: STYLE_UNKNOWN_TOKEN, where, path: `${path}.responsiveStyles.${bp}.${prop}`,\n message: `References unknown design token \\`var(--${token})\\` (typo?); it will not resolve.`,\n hint: `Use a token from the ADR-0065 palette (e.g. \\`var(--space-6)\\`, \\`var(--surface)\\`, \\`hsl(var(--primary))\\`).`,\n });\n }\n }\n }\n }\n }\n }\n\n // Recurse.\n const kids = childrenOf(node);\n for (let i = 0; i < kids.length; i++) {\n checkNode(kids[i], pageName, `${path}.children[${i}]`, findings);\n }\n}\n\n/**\n * Validate every page's component tree for SDUI styling correctness (ADR-0065).\n * Returns findings (empty = clean). `error` findings describe styles that are\n * silently dropped and should fail validate/build; `warning` findings are\n * advisory (typos, drift, footguns).\n */\nexport function validateResponsiveStyles(stack: AnyRec): StyleFinding[] {\n const findings: StyleFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n const pageName = typeof page.name === 'string' ? page.name : `pages[${p}]`;\n const regions = asArray(page.regions);\n for (let r = 0; r < regions.length; r++) {\n const components = asArray(regions[r].components);\n for (let c = 0; c < components.length; c++) {\n checkNode(components[c], pageName, `pages[${p}].regions[${r}].components[${c}]`, findings);\n }\n }\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time diagnostics for AI-authored HTML-source pages (ADR-0080).\n//\n// Applies to `kind:'html'` (and its deprecated alias `kind:'jsx'`) — the tier\n// whose `source` is constrained JSX/HTML parsed (never executed) to the tree.\n// `kind:'react'` (ADR-0081) is intentionally NOT linted here: its source is\n// real JavaScript, not constrained JSX, so the constrained parser would\n// false-error on hooks / expressions.\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` / `os\n// build`. An html page's `source` is a constrained JSX/Tailwind string\n// compiled (parsed, never executed) to the SDUI tree at save time. This gate\n// parses it at author time so malformed source fails loudly (ADR-0078) instead\n// of being stored and breaking only at render.\n//\n// Scope: parse-level — syntax, tag matching, and forbidden constructs (event\n// handlers, dangerouslySetInnerHTML). Full component/prop whitelist validation\n// needs the registry manifest (a cross-repo artifact); when that is wired,\n// thread it through `compile()` here. Until then this catches the structural\n// class of error an AI author is most likely to emit.\n\nimport { parseJsx, compile, type Manifest } from '@objectstack/sdui-parser';\n\nexport type JsxPageSeverity = 'error' | 'warning';\n\nexport interface JsxPageFinding {\n severity: JsxPageSeverity;\n rule: string;\n /** Human-readable location, e.g. `page \"command_center\" › <flex>`. */\n where: string;\n /** Config path, e.g. `pages[3].source`. */\n path: string;\n message: string;\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\nexport function validateJsxPages(stack: AnyRec, opts: { manifest?: Manifest } = {}): JsxPageFinding[] {\n const findings: JsxPageFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n // html tier (+ deprecated 'jsx' alias). react pages are not constrained JSX.\n if (!page || (page.kind !== 'html' && page.kind !== 'jsx')) continue;\n const name = String(page.name ?? `#${p}`);\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') {\n // (PageSchema's superRefine also covers this; keep it for the build path.)\n findings.push({\n severity: 'error',\n rule: 'jsx-page-empty-source',\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: `kind:'${page.kind}' page has no \\`source\\`.`,\n hint: 'Author the page as a constrained JSX/Tailwind string in `source`.',\n });\n continue;\n }\n // With a component manifest, do full validation (unknown component, missing/\n // wrong prop, bad enum, bindings); without it, parse-level (syntax/structure).\n const { diagnostics } = opts.manifest ? compile(source, opts.manifest) : parseJsx(source);\n for (const d of diagnostics) {\n findings.push({\n severity: d.severity,\n rule: `jsx-${d.code}`,\n where: d.tag ? `page \"${name}\" › <${d.tag}>` : `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: d.message,\n hint: 'The source is parsed (never executed) and compiled to the SDUI tree at save time — fix the JSX.',\n });\n }\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time syntax gate for `kind:'react'` pages (ADR-0081).\n//\n// A react page's `source` is REAL JavaScript/JSX executed at render by the\n// runtime — so the constrained JSX parser (validate-jsx-pages) cannot check it.\n// We instead transpile it with Sucrase (the same transpiler the runtime uses),\n// transpile-ONLY — never executed — to surface syntax errors at `os build`\n// instead of at render (ADR-0078: fail loudly at author time). It does NOT\n// validate runtime behaviour (a transpiling page can still throw at render);\n// the render-time error boundary owns that.\n\nimport { createRequire } from 'node:module';\nimport type { transform as sucraseTransform } from 'sucrase';\n\n// Sucrase must NOT be imported at module top level: it is ~1.5 MB of CJS\n// (~16 ms cold require), and @objectstack/lint sits on the kernel boot path —\n// while this gate only runs when a `kind:'react'` page is actually validated\n// (rare, trusted tier). Same boot-path contract as the TypeScript compiler in\n// validate-react-page-props.ts: loaded lazily, on first use, staying a regular\n// dependency in package.json. Guarded by lazy-deps.test.ts.\n//\n// `node:module` is a Node builtin, untouched by esbuild/tsup, so the static\n// `createRequire` import survives bundling; the `createRequire(...)` call is\n// deferred because `import.meta.url` is rewritten to an empty stub in the CJS\n// build (same pattern as driver-sqlite-wasm's knex-wasm-dialect).\nlet cachedTransform: typeof sucraseTransform | null = null;\nfunction loadSucraseTransform(): typeof sucraseTransform {\n if (cachedTransform) return cachedTransform;\n const anchor =\n typeof import.meta !== 'undefined' && import.meta.url\n ? import.meta.url\n : typeof __filename !== 'undefined'\n ? __filename\n : process.cwd() + '/';\n try {\n cachedTransform = (createRequire(anchor)('sucrase') as { transform: typeof sucraseTransform }).transform;\n } catch (err) {\n throw new Error(\n `@objectstack/lint: validating a kind:'react' page requires the \"sucrase\" package, which could not be loaded ` +\n `(${err instanceof Error ? err.message : String(err)}). It is a declared dependency of @objectstack/lint — ` +\n `if this deployment prunes packages, keep \"sucrase\" in the image; it is only loaded when a react-source page is validated.`,\n );\n }\n return cachedTransform;\n}\n\nexport type ReactPageSeverity = 'error' | 'warning';\n\nexport interface ReactPageFinding {\n severity: ReactPageSeverity;\n rule: string;\n where: string;\n path: string;\n message: string;\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\nexport function validateReactPages(stack: AnyRec): ReactPageFinding[] {\n const findings: ReactPageFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n if (!page || page.kind !== 'react') continue;\n const name = String(page.name ?? `#${p}`);\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') {\n findings.push({\n severity: 'error',\n rule: 'react-page-empty-source',\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: \"kind:'react' page has no `source`.\",\n hint: 'Author the page as a real React component string in `source`.',\n });\n continue;\n }\n // Outside the try below on purpose: a missing transpiler must surface as\n // an error, not be swallowed as a syntax finding.\n const transform = loadSucraseTransform();\n try {\n // transpile-only (no eval) — catches syntax errors, unterminated JSX, etc.\n transform(source, { transforms: ['jsx', 'typescript'], production: true });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n findings.push({\n severity: 'error',\n rule: 'react-page-syntax',\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: `kind:'react' source has a syntax error: ${message.split('\\n')[0]}`,\n hint: 'The source is transpiled (never executed) at build to catch syntax errors early — fix the JS/JSX.',\n });\n }\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time prop check for `kind:'react'` pages (ADR-0081 Phase 2). The syntax\n// gate (validate-react-pages) confirms the source parses; this confirms the\n// AUTHOR USED THE COMPONENT CONTRACT correctly — it parses the real JSX with the\n// TypeScript compiler, finds usages of the injected blocks (<ObjectForm>,\n// <ListView>, …), and checks each against the react-tier contract\n// (REACT_BLOCKS in @objectstack/spec):\n//\n// - missing a required binding prop (e.g. <ObjectForm> with no objectName)\n// → error. (Only the React-enforceable overlay props are required-checked;\n// a spread `{...props}` escapes the check since props may come from it.)\n// - a prop that is a near-miss (edit distance ≤ 2) of a known prop\n// (e.g. `onSucces` → `onSuccess`) → warning. We do NOT flag arbitrary\n// unknown props (the contract's data props are a curated subset) — only the\n// likely typos, to keep false positives near zero.\n// - <ObjectChart>'s data BINDINGS, by reading the attribute VALUES (#3701,\n// retargeted to the spec shape in #3729). See the block comment above\n// `checkObjectChart`.\n// - <ListView>'s `searchableFields` entries, resolved against the bound\n// object's declared fields (#4329) — the react-surface twin of the\n// metadata rule `searchable-field-unknown`, sharing its core.\n// - EVERY OTHER field-bearing prop a react block can author (#4340) — see\n// `REACT_FIELD_SPECS` below and the ledger beside it.\n//\n// Reading values is opt-in per block and per prop: everything below evaluates\n// only STATIC literals (`objectName=\"invoice\"`, an `aggregate={{…}}` object\n// literal). A value that comes from a variable, a call, or a spread is not\n// knowable at build time and is skipped silently — an unresolvable binding is\n// not a wrong one (ADR-0072 D1).\n\nimport { createRequire } from 'node:module';\nimport type ts from 'typescript';\nimport { REACT_BLOCKS, chartAggregateResultKeys } from '@objectstack/spec/ui';\nimport { VALID_AST_OPERATORS } from '@objectstack/spec/data';\nimport {\n checkSearchableFieldList,\n indexObjectSearchTargets,\n} from './validate-searchable-fields.js';\nimport {\n COMPONENT_FIELD_SPECS,\n RELATED_LIST_TYPE,\n checkFieldRefs,\n componentFieldRefs,\n fieldRefsFrom,\n indexObjectFields,\n relatedListFieldRefs,\n sortFieldRefs,\n type FieldRef,\n type PageFieldFinding,\n} from './validate-page-field-bindings.js';\n\nimport { SYSTEM_FIELDS } from './system-fields.js';\n\n// The TypeScript compiler must NOT be imported at module top level: it is\n// ~9 MB of CJS (~70 ms+ to parse, worse on container cold starts), and\n// @objectstack/lint sits on the kernel boot path — while this gate only runs\n// when a `kind:'react'` page is actually validated (rare, trusted tier). An\n// eager import also hard-crashes boot in deployments that prune the package\n// from the image (cloud's Docker pruner did exactly that). So the compiler is\n// loaded lazily, on first use, and stays a regular dependency in package.json.\n// Guarded by lazy-deps.test.ts.\n//\n// `node:module` is a Node builtin, untouched by esbuild/tsup, so the static\n// `createRequire` import survives bundling; the `createRequire(...)` call is\n// deferred because `import.meta.url` is rewritten to an empty stub in the CJS\n// build (same pattern as driver-sqlite-wasm's knex-wasm-dialect).\nlet cachedTs: typeof ts | null = null;\nfunction loadTypeScript(): typeof ts {\n if (cachedTs) return cachedTs;\n const anchor =\n typeof import.meta !== 'undefined' && import.meta.url\n ? import.meta.url\n : typeof __filename !== 'undefined'\n ? __filename\n : process.cwd() + '/';\n try {\n cachedTs = createRequire(anchor)('typescript') as typeof ts;\n } catch (err) {\n throw new Error(\n `@objectstack/lint: validating a kind:'react' page requires the \"typescript\" package, which could not be loaded ` +\n `(${err instanceof Error ? err.message : String(err)}). It is a declared dependency of @objectstack/lint — ` +\n `if this deployment prunes packages, keep \"typescript\" in the image; it is only loaded when a react-source page is validated.`,\n );\n }\n return cachedTs;\n}\n\nexport type ReactPropSeverity = 'error' | 'warning';\n\nexport interface ReactPropFinding {\n severity: ReactPropSeverity;\n rule: string;\n where: string;\n path: string;\n message: string;\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\ninterface BlockSpec {\n requiredBindings: string[];\n knownProps: Set<string>;\n}\nconst BLOCKS: Map<string, BlockSpec> = new Map(\n (REACT_BLOCKS as Array<{ tag: string; interactions: Array<{ name: string; required?: boolean }> }>).map((b) => [\n b.tag,\n {\n requiredBindings: b.interactions.filter((i) => i.required).map((i) => i.name),\n knownProps: new Set(b.interactions.map((i) => i.name)),\n },\n ]),\n);\n\nfunction editDistance(a: string, b: string, cap = 2): number {\n if (Math.abs(a.length - b.length) > cap) return cap + 1;\n const dp = Array.from({ length: a.length + 1 }, (_, i) => i);\n for (let j = 1; j <= b.length; j++) {\n let prev = dp[0];\n dp[0] = j;\n for (let i = 1; i <= a.length; i++) {\n const tmp = dp[i];\n dp[i] = Math.min(dp[i] + 1, dp[i - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));\n prev = tmp;\n }\n }\n return dp[a.length];\n}\n\nfunction nearestKnown(prop: string, known: Set<string>): string | null {\n if (known.has(prop)) return null;\n let best: string | null = null;\n let bestD = 3;\n for (const k of known) {\n const d = editDistance(prop, k);\n if (d < bestD) { bestD = d; best = k; }\n }\n return bestD <= 2 ? best : null;\n}\n\n// ─── Static attribute values ──────────────────────────────────────────────\n//\n// The gate above only needed prop NAMES. Checking a binding needs its VALUE,\n// and a JSX attribute's value is an arbitrary expression. `NOT_STATIC` is the\n// sentinel for \"this expression is not knowable at build time\" — distinct from\n// a literal `undefined`, which IS knowable.\n\nconst NOT_STATIC = Symbol('not-static');\n\n/** Evaluate a JSX expression to a plain JS value, or `NOT_STATIC`. */\nfunction staticValue(tsc: typeof ts, sf: ts.SourceFile, node: ts.Node | undefined): unknown {\n if (!node) return NOT_STATIC;\n if (tsc.isParenthesizedExpression(node)) return staticValue(tsc, sf, node.expression);\n if (tsc.isStringLiteral(node) || tsc.isNoSubstitutionTemplateLiteral(node)) return node.text;\n if (tsc.isNumericLiteral(node)) return Number(node.text);\n if (node.kind === tsc.SyntaxKind.TrueKeyword) return true;\n if (node.kind === tsc.SyntaxKind.FalseKeyword) return false;\n if (node.kind === tsc.SyntaxKind.NullKeyword) return null;\n if (tsc.isArrayLiteralExpression(node)) {\n const out: unknown[] = [];\n for (const el of node.elements) {\n const v = staticValue(tsc, sf, el);\n if (v === NOT_STATIC) return NOT_STATIC;\n out.push(v);\n }\n return out;\n }\n if (tsc.isObjectLiteralExpression(node)) {\n const out: Record<string, unknown> = {};\n for (const p of node.properties) {\n // A shorthand (`{ field }`) or spread (`{ ...cfg }`) hides its value.\n if (!tsc.isPropertyAssignment(p)) return NOT_STATIC;\n const key = tsc.isIdentifier(p.name) || tsc.isStringLiteral(p.name) ? p.name.text : null;\n if (key === null) return NOT_STATIC;\n const v = staticValue(tsc, sf, p.initializer);\n if (v === NOT_STATIC) return NOT_STATIC;\n out[key] = v;\n }\n return out;\n }\n return NOT_STATIC;\n}\n\n/** The static value of one JSX attribute (`x=\"s\"` or `x={…}`), or `NOT_STATIC`. */\nfunction attrValue(tsc: typeof ts, sf: ts.SourceFile, attr: ts.JsxAttribute): unknown {\n const init = attr.initializer;\n if (!init) return true; // bare `showLegend` — JSX shorthand for `={true}`\n if (tsc.isStringLiteral(init)) return init.text;\n if (tsc.isJsxExpression(init)) return staticValue(tsc, sf, init.expression);\n return NOT_STATIC;\n}\n\n/**\n * The value of a FILTER attribute, resolved position by position: an array\n * literal survives even when some of its elements do not, each unknowable\n * element left as `NOT_STATIC` in place.\n *\n * `staticValue` collapses such an array to `NOT_STATIC` whole, which is correct\n * where the value only means something entire (an `aggregate={{…}}`) and wrong\n * for a filter, whose positions are independent: `['status', '=', stage]` has a\n * knowable FIELD beside an unknowable VALUE, and that is the shape a react page\n * writes when it drives a list from React state. See `filterFieldRefs`.\n */\nfunction filterAttrValue(tsc: typeof ts, sf: ts.SourceFile, attr: ts.JsxAttribute): unknown {\n const init = attr.initializer;\n if (!init || !tsc.isJsxExpression(init)) return NOT_STATIC;\n const perPosition = (node: ts.Node | undefined): unknown => {\n if (!node) return NOT_STATIC;\n if (tsc.isParenthesizedExpression(node)) return perPosition(node.expression);\n if (tsc.isArrayLiteralExpression(node)) return node.elements.map((el) => perPosition(el));\n return staticValue(tsc, sf, node);\n };\n return perPosition(init.expression);\n}\n\n// ─── <ObjectChart> binding integrity (#3701) ──────────────────────────────\n//\n// `validate-chart-bindings` covers every DATASET-bound chart surface: a\n// dataset declares its dimensions/measures by NAME, result rows are keyed by\n// those names, and an axis is checked against them. The react `<ObjectChart>`\n// block was excluded because it is OBJECT-bound — `objectName` + an inline\n// `aggregate` — and nothing said what the aggregated result columns were\n// called, so `xAxisKey`/`series[].dataKey` had nothing to resolve against.\n//\n// #3701 closed that: `chartAggregateResultKeys` in @objectstack/spec/ui now\n// records the convention every renderer already implements (rows keyed by the\n// RAW FIELD NAMES — `groupBy` for the category, `field` for the value, the\n// literal `'count'` for a fieldless count). With the columns pinned, both\n// halves of the binding are checkable:\n//\n// * `aggregate.field` / `aggregate.groupBy` are RAW FIELD names → check them\n// against the object's declared fields.\n// * the axes are RESULT COLUMN names → check them against what this\n// aggregate produces.\n//\n// The axes are read in the SPEC spelling — `xAxis.field`, `yAxis[].field`,\n// `series[].name` (#3729). #3701 had to read `xAxisKey`/`series[].dataKey`\n// because those were the only spellings the renderer honored; objectui#2880\n// made it honor ChartConfig, so the gate follows the protocol again. The\n// internal spellings are still accepted, silently: dashboards and the console's\n// own chart-view wiring emit them, and they remain a valid (if unpublished)\n// way to write the same binding.\n\nexport const REACT_CHART_FIELD_UNKNOWN = 'react-chart-field-unknown';\nexport const REACT_CHART_AGGREGATE_INVALID = 'react-chart-aggregate-invalid';\nexport const REACT_CHART_AXIS_UNKNOWN = 'react-chart-axis-unknown';\n\nconst CHART_FUNCTIONS = ['count', 'sum', 'avg', 'min', 'max'] as const;\n\nconst isRec = (v: unknown): v is Record<string, unknown> =>\n !!v && typeof v === 'object' && !Array.isArray(v);\n\nconst strOf = (v: unknown): string | undefined =>\n typeof v === 'string' && v.length > 0 ? v : undefined;\n\ninterface ChartAttrs {\n /** Statically resolved attribute values, keyed by prop name. */\n values: Map<string, unknown>;\n where: string;\n path: string;\n}\n\nfunction checkObjectChart(\n attrs: ChartAttrs,\n objectFields: Map<string, Set<string>>,\n findings: ReactPropFinding[],\n): void {\n const { values, where, path } = attrs;\n const push = (severity: ReactPropSeverity, rule: string, message: string, hint: string) =>\n findings.push({ severity, rule, where, path, message, hint });\n\n // Inline `data` wins over the aggregate query: the columns then come from\n // the author's own rows, which this rule cannot see. Nothing further to say.\n if (values.has('data')) return;\n\n const aggregate = values.get('aggregate');\n if (aggregate === undefined || aggregate === NOT_STATIC) return;\n if (!isRec(aggregate)) return;\n\n const fn = strOf(aggregate.function);\n const field = strOf(aggregate.field);\n const groupBy = aggregate.groupBy;\n const groupByField = strOf(groupBy) ?? (isRec(groupBy) ? strOf(groupBy.field) : undefined);\n\n // 1. The aggregate declaration itself.\n if (fn && !(CHART_FUNCTIONS as readonly string[]).includes(fn)) {\n push(\n 'error',\n REACT_CHART_AGGREGATE_INVALID,\n `aggregate.function \"${fn}\" is not an aggregation this chart can run.`,\n `Use one of: ${CHART_FUNCTIONS.join(', ')}.`,\n );\n } else if (fn && fn !== 'count' && !field) {\n push(\n 'error',\n REACT_CHART_AGGREGATE_INVALID,\n `aggregate.function \"${fn}\" has no \"field\" to aggregate.`,\n 'Add aggregate.field, or use function \"count\" (the only one that may omit it).',\n );\n }\n\n // 2. `field` / `groupBy` are RAW field names on the bound object.\n const objectName = strOf(values.get('objectName'));\n const known = objectName ? objectFields.get(objectName) : undefined;\n // No object name, or an object declared in another package: unknowable here\n // — the same skip the widget/flow/page rules take.\n if (objectName && known) {\n const fieldRef = (name: string | undefined, prop: string) => {\n if (!name) return;\n // A relationship path (`account.name`) is resolved by the query engine.\n if (name.includes('.')) return;\n if (known.has(name) || SYSTEM_FIELDS.has(name)) return;\n push(\n 'error',\n REACT_CHART_FIELD_UNKNOWN,\n `aggregate.${prop} \"${name}\" is not a field on object \"${objectName}\" — ` +\n `the aggregate query has nothing to ${prop === 'groupBy' ? 'group by' : 'aggregate'}, so the chart comes back empty.`,\n `Fix the field name, or add \"${name}\" to ${objectName}.` +\n (known.size > 0 ? ` Object fields: ${[...known].sort().join(', ')}.` : ''),\n );\n };\n fieldRef(field, 'field');\n fieldRef(groupByField, 'groupBy');\n }\n\n // 3. The axes name RESULT COLUMNS, not fields — the #3701 convention.\n const keys = chartAggregateResultKeys({ field, function: fn, groupBy });\n const columns = [keys.category, keys.value].filter((k): k is string => !!k);\n if (columns.length === 0) return; // an aggregate too incomplete to judge against\n\n const axisRef = (name: string | undefined, prop: string) => {\n if (!name) return;\n if (columns.includes(name)) return;\n // The comparison overlay's column only exists when `compareTo` is on, but\n // binding it is legitimate — never flag it as unknown.\n if (keys.comparison && name === keys.comparison) return;\n push(\n 'error',\n REACT_CHART_AXIS_UNKNOWN,\n `\"${name}\" is not a column this aggregate returns, so the axis plots nothing. ` +\n `Object-bound aggregate rows are keyed by the RAW FIELD NAMES ` +\n `(unlike a dataset, whose rows are keyed by measure name).`,\n `Result columns: ${columns.join(', ')}` +\n (keys.comparison ? ` (plus \"${keys.comparison}\" with a comparison overlay)` : '') +\n `. Bind ${prop} to one of them.`,\n );\n };\n\n // The category axis: spec `xAxis: { field }`, the report surface's bare\n // string, or the internal `xAxisKey`. All three name the same column.\n const xAxisRaw = values.get('xAxis');\n const categoryAxis =\n strOf(values.get('xAxisKey')) ??\n strOf(xAxisRaw) ??\n (isRec(xAxisRaw) ? strOf(xAxisRaw.field) : undefined);\n const categoryProp = values.has('xAxisKey') ? 'xAxisKey' : 'xAxis.field';\n axisRef(categoryAxis, categoryProp);\n\n // The value axes: spec `yAxis: [{ field }]` (or a single object / bare\n // string) and spec `series: [{ name }]` / internal `series: [{ dataKey }]`.\n const yAxisRaw = values.get('yAxis');\n const yAxisList = Array.isArray(yAxisRaw) ? yAxisRaw : yAxisRaw !== undefined ? [yAxisRaw] : [];\n for (const a of yAxisList) {\n axisRef(strOf(a) ?? (isRec(a) ? strOf(a.field) : undefined), 'yAxis[].field');\n }\n\n const series = values.get('series');\n if (Array.isArray(series)) {\n for (const s of series) {\n if (!isRec(s)) continue;\n const dataKey = strOf(s.dataKey);\n axisRef(dataKey ?? strOf(s.name), dataKey ? 'series[].dataKey' : 'series[].name');\n }\n }\n\n // A category axis bound to anything but the groupBy is always wrong, and the\n // check above lets it through when it happens to equal the VALUE column.\n if (categoryAxis && keys.category && categoryAxis !== keys.category && categoryAxis === keys.value) {\n push(\n 'error',\n REACT_CHART_AXIS_UNKNOWN,\n `${categoryProp} \"${categoryAxis}\" is the aggregate's VALUE column, not its category column.`,\n `The category axis is keyed by groupBy — bind it to \"${keys.category}\".`,\n );\n }\n}\n\n// ─── Field-bearing block props (#4340) ────────────────────────────────────\n//\n// #4329 closed ONE prop — `<ListView searchableFields>` — by running the\n// metadata rule's core from here. `searchableFields` was an instance, not the\n// class: every other prop a react block binds BY FIELD NAME shipped exactly as\n// typed, the same silent drift `validate-page-field-bindings` closes for the\n// page-component `properties` bag one surface over. This section closes the\n// class.\n//\n// ## Where the answers come from\n//\n// The `record:*` blocks ARE the components that rule already walks — one\n// registry component, two authoring surfaces — so they are not re-described\n// here at all: `componentFieldRefs` / `relatedListFieldRefs` read the SAME\n// `COMPONENT_FIELD_SPECS` table, keyed by the block's own `schemaType`. A prop\n// added there is checked on both surfaces at once, which is the point.\n//\n// `REACT_FIELD_SPECS` below covers only what the shared table cannot: the two\n// blocks whose metadata twin lives under different prop names —\n// `<ListView>` (twin: a list page's `interfaceConfig`) and `<ObjectForm>`\n// (twin: `element:form` + the form-layout rule).\n//\n// ## What is deliberately NOT checked, and why\n//\n// - Anything non-static (a variable, a call, a value behind a spread) —\n// ADR-0072 D1: unresolvable is not wrong. `filters` is the one place this\n// is resolved PER POSITION rather than all-or-nothing; see below.\n// - `<RecordRelatedList relationshipValueField>`: it names a field on the\n// PARENT object, and the react surface binds the parent by `recordId`\n// only — there is no parent OBJECT to resolve against. The metadata twin\n// has the page's object and checks it there. This is the ONE field-bearing\n// prop in the index that stays unresolved, and the reason is a missing\n// binding rather than a missing rule.\n// - `<ObjectChart>`'s axes: they name the aggregate's RESULT COLUMNS, not\n// fields, and `checkObjectChart` above already owns them.\n//\n// `<ObjectForm subforms>` does not ride the table either, but IS checked:\n// each entry names its own `childObject`, so its refs are split per entry\n// rather than pooled against the block's object (`subformFieldRefs`).\n\n/**\n * Which props of a block carry field names, and in what shape. Each bucket is\n * a different SHAPE, not a different meaning — every entry resolves against the\n * block's own `objectName`.\n */\ninterface ReactFieldSpec {\n /** Bare names, `{field}`/`{name}` records, or arrays of either. */\n fields?: readonly string[];\n /** A `sort`: structured `{field,order}[]` or the legacy `\"field desc\"` string. */\n sorts?: readonly string[];\n /** A `{ fields: […] }` wrapper — one level of nesting. */\n nestedFields?: readonly string[];\n /** `{…}[]` sections whose `fields[]` name fields. */\n sections?: readonly string[];\n /** An object literal whose KEYS name fields. */\n keyedByField?: readonly string[];\n /** An ObjectQL FilterArray — its field POSITIONS gate (see `filterFieldRefs`). */\n filterArrays?: readonly string[];\n}\n\nconst REACT_FIELD_SPECS: Readonly<Record<string, ReactFieldSpec>> = {\n ListView: {\n // `fields` is the React overlay's \"limit/order the columns\"; `columns` the\n // spec ListView prop. Both name columns on the bound object, and a page may\n // write either. `hiddenFields`/`fieldOrder`/`filterableFields` are schema\n // props outside the curated contract — unadvertised but honored by the\n // renderer, so a stale name there is drift just the same.\n fields: ['fields', 'columns', 'hiddenFields', 'fieldOrder', 'filterableFields'],\n sorts: ['sort'],\n nestedFields: ['userFilters', 'grouping'],\n filterArrays: ['filters'],\n },\n ObjectForm: {\n fields: ['fields'],\n keyedByField: ['initialValues'],\n // `groups` is FormViewSchema's legacy alias for `sections`.\n sections: ['sections', 'groups'],\n },\n ObjectChart: {\n // The axes are result columns (checkObjectChart owns them); `filter` is an\n // ordinary ObjectQL predicate over the bound object, like ListView's.\n filterArrays: ['filter'],\n },\n};\n\n/**\n * How a prop name joins onto a react page's `path`. The props live inside one\n * opaque `source` string, so there is no config path to extend — #4329\n * established `pages[0].source › searchableFields[1]` and every prop below\n * follows it.\n */\nconst PATH_SEP = ' › ';\n\n/** tag → `schemaType`, read from the contract rather than restated. */\nconst SCHEMA_TYPE_BY_TAG: ReadonlyMap<string, string> = new Map(\n (REACT_BLOCKS as Array<{ tag: string; schemaType: string }>).map((b) => [b.tag, b.schemaType]),\n);\n\n/**\n * Attribute names read POSITION BY POSITION rather than all-or-nothing (see\n * `filterAttrValue`). Derived from the specs so a new `filterArrays` entry\n * cannot forget to opt in — the failure mode would be silent, since the\n * all-or-nothing reader simply finds nothing.\n *\n * `<RecordRelatedList filter>` rides along under the same name while holding a\n * different shape (`{field, operator, value}[]`, not a FilterArray). That is\n * harmless: a fully-static array reads identically either way, and the only\n * difference — surviving with `NOT_STATIC` holes — is dropped by\n * `fieldRefsFrom`, which ignores a non-string, non-record entry.\n */\nconst FILTER_PROPS: ReadonlySet<string> = new Set(\n Object.values(REACT_FIELD_SPECS).flatMap((s) => s.filterArrays ?? []),\n);\n\n/** Strip the `NOT_STATIC` sentinel so a shared extractor sees plain data. */\nfunction readableProps(values: ReadonlyMap<string, unknown>): AnyRec {\n const out: AnyRec = {};\n for (const [k, v] of values) if (v !== NOT_STATIC) out[k] = v;\n return out;\n}\n\n/**\n * `<ObjectForm subforms>` — inline master-detail child collections. Each entry\n * names the object its own refs resolve against (`childObject`), so unlike\n * every bucket in {@link ReactFieldSpec} these cannot be pooled into one batch\n * checked against the block's `objectName`. `totalField` is the exception\n * inside the exception: it names the PARENT field the child sum rolls up into.\n */\nfunction subformFieldRefs(\n value: unknown,\n basePath: string,\n): { child: Array<{ objectName: string | undefined; refs: FieldRef[] }>; parent: FieldRef[] } {\n const child: Array<{ objectName: string | undefined; refs: FieldRef[] }> = [];\n const parent: FieldRef[] = [];\n if (!Array.isArray(value)) return { child, parent };\n for (let i = 0; i < value.length; i++) {\n const sub = value[i];\n if (!isRec(sub)) continue;\n const at = (key: string) => `${basePath}[${i}].${key}`;\n child.push({\n objectName: strOf(sub.childObject),\n refs: [\n ...fieldRefsFrom(sub.columns, at('columns')),\n ...fieldRefsFrom(sub.relationshipField, at('relationshipField')),\n ...fieldRefsFrom(sub.amountField, at('amountField')),\n ],\n });\n parent.push(...fieldRefsFrom(sub.totalField, at('totalField')));\n }\n return { child, parent };\n}\n\n/**\n * Field references in an ObjectQL FilterArray, resolved PER POSITION.\n *\n * `staticValue` is all-or-nothing by design: an array containing one unknowable\n * element is not a knowable array. That is right for an `aggregate={{…}}`, and\n * wrong here, because the common react filter is exactly the mixed case —\n * `filters={['status', '=', stage]}` pairs a STATIC field position with a\n * React-state value. Bailing on the whole array would skip the only position\n * this rule can judge, on the shape authors actually write.\n *\n * So the reader keeps each position separate (`filterAttrValue`) and this walk\n * only ever reads position 0, and only when position 1 is a recognised operator\n * — the same test `isFilterAST` makes, using the spec's own operator vocabulary\n * so the two cannot drift. A non-static field position, a non-static operator,\n * or a shape that is not a filter node yields nothing.\n */\nfunction filterFieldRefs(node: unknown, basePath: string, out: FieldRef[]): void {\n if (!Array.isArray(node) || node.length === 0) return;\n const head = node[0];\n if (typeof head === 'string' && (head.toLowerCase() === 'and' || head.toLowerCase() === 'or')) {\n for (let i = 1; i < node.length; i++) filterFieldRefs(node[i], `${basePath}[${i}]`, out);\n return;\n }\n // Legacy flat array of conditions: `[[a,'=',1], [b,'>',2]]`.\n if (Array.isArray(head)) {\n for (let i = 0; i < node.length; i++) filterFieldRefs(node[i], `${basePath}[${i}]`, out);\n return;\n }\n if (\n typeof head === 'string' && head.length > 0 &&\n node.length >= 2 && typeof node[1] === 'string' &&\n VALID_AST_OPERATORS.has(node[1].toLowerCase())\n ) {\n out.push({ name: head, path: `${basePath}[0]` });\n }\n}\n\n/** The field refs one block's statically-read attributes hold, by bucket. */\nfunction reactFieldRefs(\n spec: ReactFieldSpec,\n values: ReadonlyMap<string, unknown>,\n basePath: string,\n): { own: FieldRef[]; queried: FieldRef[] } {\n const own: FieldRef[] = [];\n const queried: FieldRef[] = [];\n const readable = (key: string): unknown => {\n const v = values.get(key);\n return v === NOT_STATIC ? undefined : v;\n };\n const at = (key: string) => `${basePath}${PATH_SEP}${key}`;\n\n for (const key of spec.fields ?? []) {\n own.push(...fieldRefsFrom(readable(key), at(key)));\n }\n for (const key of spec.sorts ?? []) {\n own.push(...sortFieldRefs(readable(key), at(key)));\n }\n for (const key of spec.nestedFields ?? []) {\n const v = readable(key);\n if (isRec(v)) own.push(...fieldRefsFrom(v.fields, at(`${key}.fields`)));\n }\n for (const key of spec.sections ?? []) {\n const v = readable(key);\n if (!Array.isArray(v)) continue;\n for (let i = 0; i < v.length; i++) {\n const section = v[i];\n if (!isRec(section)) continue;\n own.push(...fieldRefsFrom(section.fields, at(`${key}[${i}].fields`)));\n }\n }\n for (const key of spec.keyedByField ?? []) {\n const v = readable(key);\n if (!isRec(v)) continue;\n for (const k of Object.keys(v)) own.push({ name: k, path: at(`${key}.${k}`) });\n }\n for (const key of spec.filterArrays ?? []) {\n // Read the raw attribute here, NOT `readable`: a filter whose VALUE is\n // non-static still has a knowable field position, and `filterAttrValue`\n // preserved exactly that.\n filterFieldRefs(values.get(key), at(key), queried);\n }\n return { own, queried };\n}\n\n/**\n * Resolve every field-bearing prop of one block usage against its bound object.\n *\n * Three sources feed it, in the order a block can claim them:\n *\n * 1. `REACT_FIELD_SPECS` — the react-only descriptors (`ListView`,\n * `ObjectForm`, `ObjectChart`'s `filter`).\n * 2. the `record:related_list` split, when the block IS that component.\n * 3. `COMPONENT_FIELD_SPECS`, keyed by the block's `schemaType` — the shared\n * table the metadata surface already uses. `<Block type=\"…\">` reaches it\n * by the type the author wrote, which is what makes the escape hatch\n * checked rather than a hole.\n *\n * Findings come back in this rule's own shape but under the metadata rule's id\n * (`page-field-unknown`): the same question, asked of the same component, with\n * the same fix.\n */\nfunction checkBlockFieldProps(\n tag: string,\n values: ReadonlyMap<string, unknown>,\n objectFields: ReadonlyMap<string, Set<string>>,\n where: string,\n path: string,\n): ReactPropFinding[] {\n const objectName = strOf(values.get('objectName'));\n const out: PageFieldFinding[] = [];\n\n const spec = REACT_FIELD_SPECS[tag];\n if (spec) {\n const { own, queried } = reactFieldRefs(spec, values, path);\n out.push(...checkFieldRefs(own, objectName, objectFields, where));\n out.push(...checkFieldRefs(queried, objectName, objectFields, where, 'queried'));\n }\n\n if (tag === 'ObjectForm') {\n const raw = values.get('subforms');\n const subs = subformFieldRefs(raw === NOT_STATIC ? undefined : raw, `${path}${PATH_SEP}subforms`);\n for (const sub of subs.child) {\n out.push(...checkFieldRefs(sub.refs, sub.objectName, objectFields, where));\n }\n // `totalField` names the FORM object's field the child sum rolls up into.\n out.push(...checkFieldRefs(subs.parent, objectName, objectFields, where));\n }\n\n // `<Block type=\"record:highlights\">` renders the registered component the\n // author names; every other block's type is fixed by its tag.\n const schemaType = tag === 'Block' ? strOf(values.get('type')) : SCHEMA_TYPE_BY_TAG.get(tag);\n if (schemaType) {\n const props = readableProps(values);\n if (schemaType === RELATED_LIST_TYPE) {\n const split = relatedListFieldRefs(props, path, PATH_SEP);\n out.push(...checkFieldRefs(split.related, split.relatedObject, objectFields, where));\n out.push(...checkFieldRefs(split.picker, split.pickerObject, objectFields, where));\n // `split.parent` (`relationshipValueField`) is deliberately dropped: the\n // react surface binds the parent RECORD (`recordId`) but never its\n // object, so there is nothing to resolve it against. See the section note.\n } else if (COMPONENT_FIELD_SPECS[schemaType]) {\n out.push(\n ...checkFieldRefs(\n componentFieldRefs(schemaType, props, path, PATH_SEP) ?? [],\n objectName,\n objectFields,\n where,\n ),\n );\n }\n }\n\n // The two finding shapes are structurally identical; `where`/`path` are\n // already this surface's, so only the declared type differs.\n return out as ReactPropFinding[];\n}\n\nexport function validateReactPageProps(stack: AnyRec): ReactPropFinding[] {\n const findings: ReactPropFinding[] = [];\n const objectFields = indexObjectFields(stack);\n // A separate index for the searchableFields check, built by the metadata\n // rule's own indexer: it keeps `null` for an object with no authored field\n // map (external / datasource-introspected), a distinction `indexObjectFields`\n // flattens — and one this check must honor so both surfaces skip alike.\n const searchTargets = indexObjectSearchTargets(stack);\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n if (!page || page.kind !== 'react') continue;\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') continue;\n const name = String(page.name ?? `#${p}`);\n\n // Outside the try below on purpose: a missing compiler must surface as an\n // error, not be swallowed as \"unparseable source\".\n const tsc = loadTypeScript();\n\n let sf: ts.SourceFile;\n try {\n sf = tsc.createSourceFile('page.tsx', source, tsc.ScriptTarget.Latest, true, tsc.ScriptKind.TSX);\n } catch {\n continue; // the syntax gate reports unparseable sources\n }\n\n const visit = (node: ts.Node): void => {\n if (tsc.isJsxOpeningElement(node) || tsc.isJsxSelfClosingElement(node)) {\n const tag = node.tagName.getText(sf);\n const block = BLOCKS.get(tag);\n if (block) {\n let hasSpread = false;\n const used = new Set<string>();\n const values = new Map<string, unknown>();\n for (const a of node.attributes.properties) {\n if (tsc.isJsxSpreadAttribute(a)) { hasSpread = true; continue; }\n if (tsc.isJsxAttribute(a)) {\n const propName = a.name.getText(sf);\n used.add(propName);\n values.set(\n propName,\n FILTER_PROPS.has(propName)\n ? filterAttrValue(tsc, sf, a)\n : attrValue(tsc, sf, a),\n );\n }\n }\n const where = `page \"${name}\" › <${tag}>`;\n const path = `pages[${p}].source`;\n if (!hasSpread) {\n for (const req of block.requiredBindings) {\n if (!used.has(req)) {\n findings.push({\n severity: 'error',\n rule: 'react-prop-missing-required',\n where, path,\n message: `<${tag}> is missing the required prop \"${req}\".`,\n hint: `Pass ${req}={…}. See the react-tier component contract.`,\n });\n }\n }\n }\n for (const u of used) {\n const near = nearestKnown(u, block.knownProps);\n if (near) {\n findings.push({\n severity: 'warning',\n rule: 'react-prop-typo',\n where, path,\n message: `<${tag}> has prop \"${u}\" — did you mean \"${near}\"?`,\n hint: 'Likely a typo of a contract prop. Fix it or remove it.',\n });\n }\n }\n // A spread can supply any of the bindings below, so the values we\n // can see are an incomplete picture — skip rather than guess.\n if (tag === 'ObjectChart' && !hasSpread) {\n checkObjectChart({ values, where, path }, objectFields, findings);\n }\n // <ListView searchableFields> names fields on the bound object — the\n // react-surface twin of `searchable-field-unknown` (#4329). It runs\n // the metadata rule's own core, so the skips (cross-package object,\n // no authored field map, system columns) and the dotted-path\n // strictness match by construction. A non-static value — either\n // attribute — bails inside the checker: unresolvable is not wrong.\n if (tag === 'ListView' && !hasSpread) {\n findings.push(\n ...checkSearchableFieldList(\n values.get('searchableFields'),\n strOf(values.get('objectName')),\n searchTargets,\n where,\n `${path} › searchableFields`,\n 'searchableFields',\n ),\n );\n }\n // Every other field-bearing prop (#4340). Same skips as the chart\n // and searchableFields checks: a spread hides the picture, and a\n // non-static value is unresolvable rather than wrong.\n if (!hasSpread) {\n findings.push(\n ...checkBlockFieldProps(tag, values, objectFields, where, path),\n );\n }\n }\n }\n tsc.forEachChild(node, visit);\n };\n visit(sf);\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0061 — searchable set] `searchableFields` entries must name a field the\n * object actually has.\n *\n * `searchableFields` is `z.array(z.string())` in both `object.zod.ts` and the\n * list-view schema, so nothing checks that an entry resolves to anything. Rename\n * a field and the old name stays behind: Zod-valid, shipped, and pointing at a\n * column that no longer exists.\n *\n * ── Why a stale entry is not merely inert ────────────────────────────────\n *\n * The engine tolerates it. `resolveSearchFields` (`@objectstack/objectql`)\n * filters the declaration down to fields that exist —\n * `searchableFields?.filter((f) => all[f])` — so a stale name is dropped\n * without a word. That tolerance is what makes the drift invisible, and it\n * fails in the direction nobody expects:\n *\n * - Some entries stale → `$search` quietly scans a NARROWER set than the\n * object declares. Records that should match do not, and the response is\n * indistinguishable from \"no such record\".\n * - EVERY entry stale → the filtered set is empty, so resolution falls\n * through to the AUTO-DEFAULT (name/title + short-text fields). A\n * declaration whose entire purpose is to CHOOSE the searchable set ends up\n * selecting a set the author never wrote — the same \"asked narrower,\n * answered wider\" inversion #4226 closed on the projection axis.\n *\n * And it does not stay quiet downstream. objectui's list search echoes\n * `schema.searchableFields` verbatim as the `$searchFields` override, so once\n * the REST read path validates that override against the object (#4254), a\n * stale declaration the engine had been silently skipping becomes a `400\n * INVALID_FIELD` on every list search for that object — a request-time break\n * whose cause is an authoring typo made long before.\n *\n * Hence `error`, not the advisory level the other field-existence rules use\n * (`page-field-unknown`, `form-field-unknown`, `semantic-role-field-unknown`\n * are all warnings). Those describe a consumer that SKIPS an unknown name and\n * renders the rest; this one describes a declaration that either selects the\n * wrong set or refuses the request outright. It is the same call\n * `validate-flow-template-paths` makes for a filter-position token: gating when\n * the miss widens the query rather than shrinking the page.\n *\n * ── What is checked, and what is deliberately not ────────────────────────\n *\n * Existence only. A field that exists but is an odd search target (a `json`\n * column, say) is NOT flagged: an explicit `searchableFields` is authoritative\n * — the engine scans exactly what it names — so declaring one is a choice, not\n * a mistake. Only a name resolving to no field at all is drift.\n *\n * Three skips keep false positives near zero (ADR-0072 D1 — one dead finding\n * and authors stop trusting the linter):\n *\n * 1. An object this stack does not define. It may come from another package,\n * and a field map we cannot see cannot be judged (the same skip the\n * page/flow/widget rules take).\n * 2. An object that declares no field map at all — external objects and\n * datasource-introspected schemas whose columns are resolved at runtime.\n * 3. Registry-injected system columns, which are searchable at runtime but\n * never appear in authored `fields` — the package-shared `SYSTEM_FIELDS`\n * (`system-fields.ts`), derived from the spec's own declarations rather\n * than hand-copied (#4330).\n *\n * Dotted paths are NOT skipped here, unlike every sibling rule. Elsewhere\n * `owner_id.name` is left alone because the query engine resolves the traversal;\n * search does not — `resolveSearchFields` matches the field map by exact string,\n * so a dotted entry is dropped exactly like a typo. Skipping it would exempt the\n * one wrong spelling most likely to be borrowed from `select`/`sort`.\n */\n\nimport { SYSTEM_FIELDS } from './system-fields.js';\n\nexport const SEARCHABLE_FIELD_UNKNOWN = 'searchable-field-unknown';\n\nexport type SearchableFieldSeverity = 'error' | 'warning';\n\nexport interface SearchableFieldFinding {\n /** Always `error` — a stale entry narrows, widens or refuses the search (see module note). */\n severity: SearchableFieldSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `object \"crm_lead\"`. */\n where: string;\n /** Config path, e.g. `objects[0].searchableFields[2]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction isRec(v: unknown): v is AnyRec {\n return !!v && typeof v === 'object' && !Array.isArray(v);\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/**\n * The declared field NAMES of an object, or `null` when the object declares no\n * readable field map (external / introspected — nothing to judge against).\n * Reads both shapes: the name-keyed map and the legacy array of `{ name }`.\n */\nfunction declaredFieldNames(obj: AnyRec): Set<string> | null {\n const fields = obj.fields;\n if (!fields || typeof fields !== 'object') return null;\n const names = new Set<string>();\n for (const f of asArray(fields)) {\n const n = strName(f.name);\n if (n) names.add(n);\n }\n return names.size > 0 ? names : null;\n}\n\n/** Levenshtein-bounded \"did you mean?\" over the object's own field names. */\nfunction suggest(target: string, known: Iterable<string>): string {\n let best: string | undefined;\n let bestScore = Infinity;\n for (const candidate of known) {\n const d = distance(target, candidate);\n if (d < bestScore) {\n bestScore = d;\n best = candidate;\n }\n }\n const limit = Math.max(2, Math.floor(target.length / 3));\n return best && bestScore <= limit ? ` Did you mean \"${best}\"?` : '';\n}\n\nfunction distance(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const curr = [i, ...new Array<number>(n).fill(0)];\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);\n }\n prev = curr;\n }\n return prev[n];\n}\n\n/**\n * object name → declared field names. `null` marks an object with no readable\n * field map, so \"declared nothing\" stays distinguishable from \"not in stack\".\n * Exported alongside `checkSearchableFieldList` so every surface that authors\n * a searchable set resolves against the identical index (#4329).\n */\nexport function indexObjectSearchTargets(\n stack: Record<string, unknown>,\n): Map<string, Set<string> | null> {\n const fieldsByObject = new Map<string, Set<string> | null>();\n if (!isRec(stack)) return fieldsByObject;\n for (const obj of asArray(stack.objects)) {\n const name = strName(obj.name);\n if (name) fieldsByObject.set(name, declaredFieldNames(obj));\n }\n return fieldsByObject;\n}\n\n/**\n * Check one `searchableFields` array against the field map `fieldsByObject`\n * holds for `objectName` — the shared core behind every surface that authors a\n * searchable set: the object/list-view metadata walked by\n * `validateSearchableFields` below, and the react page surface\n * (`<ListView searchableFields={…}>`, `validate-react-page-props`), which\n * reuses it so the two surfaces agree on what counts as a field — same three\n * skips, same dotted-path strictness (#4329).\n *\n * `subject` names the declaration for the message, since an object's own set\n * and a view's narrowing of it are fixed differently; the entry index is\n * appended to `path` so the author can go straight to the stale name.\n */\nexport function checkSearchableFieldList(\n declared: unknown,\n objectName: string | undefined,\n fieldsByObject: ReadonlyMap<string, Set<string> | null>,\n where: string,\n path: string,\n subject: string,\n): SearchableFieldFinding[] {\n const findings: SearchableFieldFinding[] = [];\n if (!Array.isArray(declared) || declared.length === 0) return findings;\n if (!objectName) return findings; // nothing to resolve against\n if (!fieldsByObject.has(objectName)) return findings; // ① object from another package\n const known = fieldsByObject.get(objectName);\n if (!known) return findings; // ② external / introspected — no authored field map\n\n for (let i = 0; i < declared.length; i++) {\n const entry = declared[i];\n // Pre-parse input may carry junk here; a non-string is a SHAPE error the\n // schema owns, not a dangling reference.\n const name = strName(entry);\n if (!name) continue;\n if (known.has(name) || SYSTEM_FIELDS.has(name)) continue; // ③ system column\n\n const dotted = name.includes('.');\n findings.push({\n severity: 'error',\n rule: SEARCHABLE_FIELD_UNKNOWN,\n where,\n path: `${path}[${i}]`,\n message:\n `${subject} entry \"${name}\" is not a field on object \"${objectName}\". ` +\n `The declaration is stale: searching it can never match, and the engine ` +\n `silently drops it — leaving a narrower search than declared, or the ` +\n `auto-default set once every entry is dropped.` +\n (dotted ? '' : suggest(name, known)),\n hint:\n (dotted\n ? `'search' scans this object's own columns, so a related record's ` +\n `column cannot be a search target — expand the relation and search ` +\n `the related object, or copy the value onto a formula field here. `\n : `Fix the name, or add \"${name}\" to ${objectName}.fields. `) +\n `Clients echo this declaration verbatim as the '$searchFields' ` +\n `override, so a stale entry becomes a 400 INVALID_FIELD on list ` +\n `search (#4254), not just a quietly narrowed one.` +\n (known.size > 0 ? ` Object fields: ${[...known].sort().join(', ')}.` : ''),\n });\n }\n return findings;\n}\n\n/**\n * Validate every `searchableFields` declaration in the stack — the object's own\n * (the canonical set, ADR-0061) and the list views that narrow it. Returns\n * findings (empty = clean).\n *\n * The react page surface (`<ListView searchableFields={…}>`) is deliberately\n * NOT walked here: its declaration lives inside JSX source, and\n * `validate-react-page-props` — the gate that already parses that source —\n * runs the same `checkSearchableFieldList` core on it (#4329).\n */\nexport function validateSearchableFields(stack: AnyRec): SearchableFieldFinding[] {\n const findings: SearchableFieldFinding[] = [];\n if (!isRec(stack)) return findings;\n\n const objects = asArray(stack.objects);\n const fieldsByObject = indexObjectSearchTargets(stack);\n\n const check = (\n declared: unknown,\n objectName: string | undefined,\n where: string,\n path: string,\n subject: string,\n ) => {\n findings.push(\n ...checkSearchableFieldList(declared, objectName, fieldsByObject, where, path, subject),\n );\n };\n\n // ── The object's own canonical set, and its built-in named list views ──\n for (let oi = 0; oi < objects.length; oi++) {\n const obj = objects[oi];\n if (!isRec(obj)) continue;\n const objName = strName(obj.name);\n const label = objName ? `object \"${objName}\"` : `objects[${oi}]`;\n\n check(\n obj.searchableFields,\n objName,\n label,\n `objects[${oi}].searchableFields`,\n 'searchableFields',\n );\n\n if (isRec(obj.listViews)) {\n for (const [key, lv] of Object.entries(obj.listViews)) {\n if (!isRec(lv)) continue;\n check(\n lv.searchableFields,\n // A built-in list view belongs to its object; an inline `data.object`\n // may still retarget it (ADR-0047 allows the explicit binding).\n listViewObject(lv) ?? objName,\n `${label} › listViews.${key}`,\n `objects[${oi}].listViews.${key}.searchableFields`,\n 'list-view searchableFields',\n );\n }\n }\n }\n\n // ── `defineView` aggregates: the default `list` + named `listViews` ──\n const views = asArray(stack.views);\n for (let vi = 0; vi < views.length; vi++) {\n const view = views[vi];\n if (!isRec(view)) continue;\n const viewLabel = strName(view.name) ?? strName(view.objectName) ?? `#${vi}`;\n // The aggregate's own binding is the fallback for a list view that declares\n // none — the same resolution order `validate-list-view-mode` reads.\n const viewObject = strName(view.objectName) ?? strName(view.object);\n\n if (isRec(view.list)) {\n check(\n view.list.searchableFields,\n listViewObject(view.list) ?? viewObject,\n `view \"${viewLabel}\" › list`,\n `views[${vi}].list.searchableFields`,\n 'list-view searchableFields',\n );\n }\n\n if (isRec(view.listViews)) {\n for (const [key, lv] of Object.entries(view.listViews)) {\n if (!isRec(lv)) continue;\n check(\n lv.searchableFields,\n listViewObject(lv) ?? viewObject,\n `view \"${viewLabel}\" › listViews.${key}`,\n `views[${vi}].listViews.${key}.searchableFields`,\n 'list-view searchableFields',\n );\n }\n }\n }\n\n return findings;\n}\n\n/** A list view's own object binding: `data: { provider: 'object', object }`. */\nfunction listViewObject(listView: AnyRec): string | undefined {\n const data = listView.data;\n return isRec(data) ? strName(data.object) : undefined;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Shared page-component traversal for the lint rules that inspect\n * `PageComponent.properties` (issue #3583).\n *\n * Getting this walk right is subtle enough that duplicating it has already\n * produced one dead rule, so it lives here once:\n *\n * - Components hang off `page.regions[].components[]` and `page.slots.<slot>`\n * — there is NO top-level `page.components`. A walker that reads\n * `page.components` silently visits nothing on a schema-parsed stack.\n * - `slots.<slot>` is `PageComponent | PageComponent[]` — a single component\n * is legal and must be normalized.\n * - `PageComponentSchema` is `.strict()`, so a component carries no `children`\n * key of its own. Sub-trees live INSIDE the untyped `properties` bag:\n * `page:tabs` → `properties.items[].children`, `page:accordion` →\n * `properties.items[].children`, `page:card` → `properties.body` /\n * `properties.footer`. All are `z.array(z.unknown())`, so the recursion is\n * untyped and has to be done by hand.\n * - `kind: 'html' | 'react' | 'jsx'` pages are authored as `source`, which is\n * authoritative; their `regions` hold at most a DERIVED cache that the\n * source wins over. Linting that cache reports findings about metadata the\n * author never wrote, so those pages are skipped here and covered by\n * `validate-jsx-pages` / `validate-react-page-props` instead.\n */\n\nexport type AnyRec = Record<string, unknown>;\n\n/** A visited component plus everything needed to locate and bind it. */\nexport interface WalkedComponent {\n /** The component record itself. */\n component: AnyRec;\n /** Config path, e.g. `pages[0].regions[1].components[2]`. */\n path: string;\n /**\n * The object this component binds against, by precedence:\n * `dataSource.object` → `properties.object` → the page's `object`.\n * `undefined` when nothing in the chain names one.\n */\n objectName?: string;\n}\n\nfunction isRec(v: unknown): v is AnyRec {\n return !!v && typeof v === 'object' && !Array.isArray(v);\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/** Page kinds whose component tree is a derived cache, not authored metadata. */\nconst SOURCE_AUTHORED_KINDS = new Set(['html', 'react', 'jsx']);\n\n/** Is this page authored as `source` (so its `regions` must not be linted)? */\nexport function isSourceAuthoredPage(page: AnyRec): boolean {\n const kind = strName(page.kind);\n return kind !== undefined && SOURCE_AUTHORED_KINDS.has(kind);\n}\n\n/**\n * Walk every component on a page, depth-first, yielding each with its config\n * path and resolved object binding. Source-authored pages yield nothing.\n *\n * `pagePath` is the caller's path prefix for the page (e.g. `pages[3]`).\n */\nexport function walkPageComponents(page: AnyRec, pagePath: string): WalkedComponent[] {\n const out: WalkedComponent[] = [];\n if (!isRec(page) || isSourceAuthoredPage(page)) return out;\n\n const pageObject = strName(page.object);\n\n const visit = (node: unknown, path: string, inheritedObject?: string) => {\n if (!isRec(node)) return;\n\n // Per-element `dataSource` overrides the page object so one page can bind\n // several objects; an inline `properties.object` does the same for the\n // element-family components that declare one.\n const props = isRec(node.properties) ? node.properties : undefined;\n const dataSource = isRec(node.dataSource) ? node.dataSource : undefined;\n const objectName =\n strName(dataSource?.object) ?? strName(props?.object) ?? inheritedObject;\n\n out.push({ component: node, path, objectName });\n\n if (!props) return;\n\n // `page:tabs` / `page:accordion` — items[].children[]\n if (Array.isArray(props.items)) {\n for (let i = 0; i < props.items.length; i++) {\n const item = props.items[i];\n if (!isRec(item) || !Array.isArray(item.children)) continue;\n for (let c = 0; c < item.children.length; c++) {\n visit(item.children[c], `${path}.properties.items[${i}].children[${c}]`, objectName);\n }\n }\n }\n // Generic layout nesting — `properties.children[]`. Not in any props\n // schema, but it is how real pages compose layout containers (`type:\n // 'flex'` grids in the showcase command-center wrap every chart this way).\n // Omitting it hides whole sub-trees from every rule built on this walk.\n if (Array.isArray(props.children)) {\n for (let i = 0; i < props.children.length; i++) {\n visit(props.children[i], `${path}.properties.children[${i}]`, objectName);\n }\n }\n // `page:card` — body[] / footer[]\n for (const key of ['body', 'footer'] as const) {\n const slotList = props[key];\n if (!Array.isArray(slotList)) continue;\n for (let i = 0; i < slotList.length; i++) {\n visit(slotList[i], `${path}.properties.${key}[${i}]`, objectName);\n }\n }\n };\n\n const regions = Array.isArray(page.regions) ? page.regions : [];\n for (let r = 0; r < regions.length; r++) {\n const region = regions[r];\n if (!isRec(region) || !Array.isArray(region.components)) continue;\n for (let c = 0; c < region.components.length; c++) {\n visit(region.components[c], `${pagePath}.regions[${r}].components[${c}]`, pageObject);\n }\n }\n\n const slots = isRec(page.slots) ? page.slots : undefined;\n if (slots) {\n for (const [slot, value] of Object.entries(slots)) {\n // A slot holds a single component or an array of them.\n const list = Array.isArray(value) ? value : [value];\n const indexed = Array.isArray(value);\n for (let i = 0; i < list.length; i++) {\n visit(list[i], `${pagePath}.slots.${slot}${indexed ? `[${i}]` : ''}`, pageObject);\n }\n }\n }\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0078 — completeness] Field-reference integrity for page components\n * (issue #3583, assessment R3).\n *\n * `PageComponent.properties` is `z.record(z.string(), z.unknown())` — an\n * untyped bag. The typed prop schemas exist (`ComponentPropsMap` in\n * `@objectstack/spec/ui`) but nothing validates `properties` against them, so\n * every field name a component references ships exactly as typed. The HotCRM\n * audit found KPI cards and page headers bound to fields the object does not\n * have; each renders blank or falls back, and nothing reports the miss.\n *\n * Field-existence lint already exists for forms (`FORM_FIELD_UNKNOWN`),\n * semantic roles, and flow templates. This is the same check for pages, at the\n * same advisory severity: every consumer degrades gracefully (a missing field\n * is skipped, not crashed on), so a warning is the honest level.\n *\n * ── Which object a component binds ──────────────────────────────────────\n *\n * `dataSource.object` → `properties.object` → the page's `object`. A per-element\n * `dataSource` exists precisely so one page can bind several objects, and the\n * `element:*` family declares its own `object`; both must win over the page's.\n *\n * ── Why a hand-written descriptor table ─────────────────────────────────\n *\n * `ComponentPropsMap` cannot drive this rule: a Zod schema does not say which\n * of its `z.string()` props is a FIELD NAME (`RecordPathProps.statusField` and\n * `AIChatWindowProps.agentId` are both plain strings), and the type universe is\n * open anyway — `PageComponent.type` is `z.union([PageComponentType,\n * z.string()])`, so unregistered types like `record:line_items` parse and are\n * authored in the wild. The table below names the field-bearing props\n * explicitly; an unknown component type is SKIPPED silently, never flagged.\n *\n * The table also covers shapes the props schemas do not yet describe but real\n * pages authored anyway (they pass only because `properties` is unvalidated):\n * `record:details` `sections[].fields[]` and `hideFields[]`, and the record\n * picker's `labelField`. Linting the schema's shape alone would find nothing on\n * the actual corpus.\n *\n * ── Shared with the react page surface ──────────────────────────────────\n *\n * A `kind:'react'` page authors the SAME components, one surface over, as JSX\n * props instead of a `properties` bag (`<RecordHighlights fields={…}>`). The\n * extraction and the check are therefore exported — `COMPONENT_FIELD_SPECS`,\n * {@link componentFieldRefs}, {@link relatedListFieldRefs},\n * {@link indexObjectFields}, {@link checkFieldRefs} — and\n * `validate-react-page-props` runs them on the parsed JSX (#4340). Same table,\n * same skips, same rule id: the two surfaces agree on what counts as a field by\n * construction rather than by two lists that happen to match, which is the\n * drift #4330 had just finished removing from the system-field lists.\n */\n\nexport const PAGE_FIELD_UNKNOWN = 'page-field-unknown';\n\nexport type PageFieldSeverity = 'error' | 'warning';\n\nexport interface PageFieldFinding {\n /**\n * `warning` on every surface this rule itself walks — page renderers skip an\n * unknown field rather than fail. The shared {@link checkFieldRefs} core also\n * serves the react page surface, where one batch of refs reaches a QUERY\n * rather than a renderer and gates instead; see {@link FieldRefConsequence}.\n */\n severity: PageFieldSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `page \"task_detail\" · record:highlights`. */\n where: string;\n /** Config path, e.g. `pages[0].regions[1].components[0].properties.fields[2]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\nimport { walkPageComponents, type AnyRec } from './page-walk.js';\n// Real pages DO reference registry-injected columns — e.g. `sys_user.page.ts`\n// lists `created_at` in a related-list's columns — so the shared set is load-\n// bearing here, not merely defensive.\nimport { SYSTEM_FIELDS } from './system-fields.js';\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\nfunction isRec(v: unknown): v is AnyRec {\n return !!v && typeof v === 'object' && !Array.isArray(v);\n}\n\n/** A field reference found in a props bag, with the path that located it. */\nexport interface FieldRef {\n name: string;\n path: string;\n}\n\n/**\n * Pull field names out of a value that may be a bare string, a `{field}` or\n * `{name}` record, or an array of either — the three shapes the component props\n * use interchangeably (`record:highlights` keys its object form `name`, while\n * columns/sort/filter key theirs `field`).\n */\nexport function fieldRefsFrom(value: unknown, basePath: string): FieldRef[] {\n const out: FieldRef[] = [];\n const one = (v: unknown, path: string) => {\n const bare = strName(v);\n if (bare) {\n out.push({ name: bare, path });\n return;\n }\n if (!isRec(v)) return;\n const named = strName(v.field) ?? strName(v.name);\n if (named) out.push({ name: named, path: `${path}.${strName(v.field) ? 'field' : 'name'}` });\n };\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) one(value[i], `${basePath}[${i}]`);\n } else {\n one(value, basePath);\n }\n return out;\n}\n\n/**\n * Field references in a `sort` value.\n *\n * The structured form (`[{ field, order }]`) is ordinary {@link fieldRefsFrom}\n * work. The LEGACY bare-string form is not: `ListViewSchema.sort` still accepts\n * `\"created_at desc\"`, where the string names ONE field followed by a direction\n * word — so reading the whole string as a field name reports `\"created_at desc\"`\n * as unknown, a finding whose \"field\" the author never wrote. Read its head\n * instead, which is exactly what the renderer does with it.\n */\nexport function sortFieldRefs(value: unknown, basePath: string): FieldRef[] {\n if (typeof value === 'string') {\n const head = value.trim().split(/\\s+/)[0];\n return head ? [{ name: head, path: basePath }] : [];\n }\n return fieldRefsFrom(value, basePath);\n}\n\n/**\n * Per-component-type descriptor: which `properties` paths hold field names, and\n * whether they resolve against this component's own object or another one.\n *\n * `props` entries are read from `component.properties`. Entries under\n * `nestedSections` walk `properties.<key>[].fields[]` — the section shape real\n * pages author for `record:details`.\n */\nexport interface ComponentFieldSpec {\n /** Props holding field names bound to the component's resolved object. */\n props?: readonly string[];\n /** Props holding `{...}[]` section objects whose `fields[]` are field names. */\n nestedSections?: readonly string[];\n}\n\nexport const COMPONENT_FIELD_SPECS: Readonly<Record<string, ComponentFieldSpec>> = {\n 'record:highlights': { props: ['fields'] },\n // `sections`/`hideFields` are not in RecordDetailsProps, but every real page\n // authors them (they survive because `properties` is unvalidated).\n 'record:details': { props: ['fields', 'hideFields'], nestedSections: ['sections'] },\n 'record:path': { props: ['statusField'] },\n 'element:number': { props: ['field'] },\n 'element:filter': { props: ['fields'] },\n 'element:form': { props: ['fields'] },\n // The schema says `displayField`; real pages author `labelField`. Accept both.\n 'element:record_picker': { props: ['displayField', 'labelField', 'searchFields'] },\n};\n\n/**\n * `record:related_list` is special: its `columns`/`sort`/`filter` resolve\n * against the RELATED object (`properties.objectName`), not the page's object,\n * so it cannot ride the generic table.\n */\nexport const RELATED_LIST_TYPE = 'record:related_list';\n\n/**\n * The field references a component's props bag holds, per\n * {@link COMPONENT_FIELD_SPECS}. `null` for a type with no descriptor —\n * unregistered / non-field components are skipped silently, never flagged.\n *\n * `basePath` is the path of the props bag itself, and `sep` joins a prop name\n * onto it: `.` for a metadata page (`…components[0].properties.fields[2]`),\n * ` › ` for react source, whose props live inside one opaque `source` string\n * and so are addressed the way #4329 established (`pages[0].source › fields[2]`).\n */\nexport function componentFieldRefs(\n type: string,\n props: AnyRec,\n basePath: string,\n sep = '.',\n): FieldRef[] | null {\n const spec = COMPONENT_FIELD_SPECS[type];\n if (!spec) return null;\n const refs: FieldRef[] = [];\n for (const key of spec.props ?? []) {\n refs.push(...fieldRefsFrom(props[key], `${basePath}${sep}${key}`));\n }\n for (const key of spec.nestedSections ?? []) {\n const sections = Array.isArray(props[key]) ? (props[key] as unknown[]) : [];\n for (let si = 0; si < sections.length; si++) {\n const section = sections[si];\n // A `sections` that is a plain `string[]` (the shape `RecordDetailsProps`\n // actually declares — section IDs) yields nothing here, which is right:\n // those are not field names.\n if (!isRec(section)) continue;\n refs.push(...fieldRefsFrom(section.fields, `${basePath}${sep}${key}[${si}].fields`));\n }\n }\n return refs;\n}\n\n/** A `record:related_list` props bag, split by which object each batch resolves against. */\nexport interface RelatedListFieldRefs {\n /** The related (child) object this list renders — `properties.objectName`. */\n relatedObject: string | undefined;\n /** Refs resolved against {@link relatedObject}. */\n related: FieldRef[];\n /** Refs resolved against the PARENT object (the record the list hangs off). */\n parent: FieldRef[];\n /** The Add picker's own object, and the refs resolved against it. */\n pickerObject: string | undefined;\n picker: FieldRef[];\n}\n\n/**\n * Split a `record:related_list` props bag into its three object scopes. Shared\n * so the react `<RecordRelatedList>` block and the metadata component cannot\n * disagree about which object each prop addresses — the exact confusion #4340\n * found published under one prop name.\n */\nexport function relatedListFieldRefs(\n props: AnyRec,\n basePath: string,\n sep = '.',\n): RelatedListFieldRefs {\n const add = isRec(props.add) ? props.add : undefined;\n const picker = add && isRec(add.picker) ? add.picker : undefined;\n const at = (key: string) => `${basePath}${sep}${key}`;\n return {\n relatedObject: strName(props.objectName),\n related: [\n ...fieldRefsFrom(props.columns, at('columns')),\n ...sortFieldRefs(props.sort, at('sort')),\n ...fieldRefsFrom(props.filter, at('filter')),\n ...fieldRefsFrom(props.relationshipField, at('relationshipField')),\n ...(add ? fieldRefsFrom(add.linkField, at('add.linkField')) : []),\n ],\n parent: fieldRefsFrom(props.relationshipValueField, at('relationshipValueField')),\n pickerObject: picker ? strName(picker.object) : undefined,\n picker: picker\n ? [\n ...fieldRefsFrom(picker.valueField, at('add.picker.valueField')),\n ...fieldRefsFrom(picker.labelField, at('add.picker.labelField')),\n ]\n : [],\n };\n}\n\n/** object name → its declared field names. Both `fields` shapes resolve. */\nexport function indexObjectFields(stack: AnyRec): Map<string, Set<string>> {\n const objectFields = new Map<string, Set<string>>();\n if (!isRec(stack)) return objectFields;\n for (const obj of asArray(stack.objects)) {\n const name = strName(obj.name);\n if (!name) continue;\n const names = new Set<string>();\n for (const f of asArray(obj.fields)) {\n const fn = strName(f.name);\n if (fn) names.add(fn);\n }\n objectFields.set(name, names);\n }\n return objectFields;\n}\n\n/**\n * How a miss on this batch of refs fails at runtime — the two calls this\n * package makes, named so the message and the severity cannot drift apart.\n *\n * - `skipped` (default): the consumer drops the unknown name and renders the\n * rest. Advisory, like every other field-existence rule.\n * - `queried`: the name reached a QUERY. An unknown column in a predicate\n * matches no row (`SqlDriver` swallows the driver's \"no such column\" and\n * returns `[]`), so the surface renders an empty list that is\n * indistinguishable from \"there is no data\" — the silent-zero failure\n * `filter-token-unknown` and `validate-flow-template-paths`' filter-position\n * call both gate on. Gating.\n */\nexport type FieldRefConsequence = 'skipped' | 'queried';\n\n/**\n * Check one batch of refs against `objectName`'s declared fields.\n *\n * Bails out entirely when the object is not defined in this stack — it may come\n * from another installed package, and we cannot judge fields on a schema we\n * cannot see (the same skip the flow/widget rules use).\n */\nexport function checkFieldRefs(\n refs: readonly FieldRef[],\n objectName: string | undefined,\n objectFields: ReadonlyMap<string, Set<string>>,\n where: string,\n consequence: FieldRefConsequence = 'skipped',\n): PageFieldFinding[] {\n const findings: PageFieldFinding[] = [];\n if (!objectName) return findings; // nothing to resolve against\n const known = objectFields.get(objectName);\n if (!known) return findings; // cross-package object — unknowable here\n for (const ref of refs) {\n // A relationship path (`account.name`) is resolved by the query engine,\n // not a base column, so it cannot be judged here.\n if (ref.name.includes('.')) continue;\n if (known.has(ref.name) || SYSTEM_FIELDS.has(ref.name)) continue;\n findings.push({\n severity: consequence === 'queried' ? 'error' : 'warning',\n rule: PAGE_FIELD_UNKNOWN,\n where,\n path: ref.path,\n message:\n `field \"${ref.name}\" is not a field on object \"${objectName}\" — ` +\n (consequence === 'queried'\n ? 'it is used in a QUERY, so the predicate can never match: the surface ' +\n 'renders an empty result that looks exactly like \"there is no data\".'\n : 'the component silently skips it, so it never renders.'),\n hint:\n `Fix the field name, or add \"${ref.name}\" to ${objectName}. ` +\n `References must match the object's field names exactly.` +\n (known.size > 0 ? ` Object fields: ${[...known].sort().join(', ')}.` : ''),\n });\n }\n return findings;\n}\n\nexport function validatePageFieldBindings(stack: AnyRec): PageFieldFinding[] {\n const findings: PageFieldFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n // object name → its declared field names. Built with `asArray` so BOTH\n // `fields` shapes (array of `{name}` and name-keyed map) resolve.\n const objectFields = indexObjectFields(stack);\n\n const pages = asArray(stack.pages);\n for (let pi = 0; pi < pages.length; pi++) {\n const page = pages[pi];\n if (!page || typeof page !== 'object') continue;\n const pageName = strName(page.name) ?? `#${pi}`;\n\n const checkRefs = (refs: readonly FieldRef[], objectName: string | undefined, where: string) => {\n findings.push(...checkFieldRefs(refs, objectName, objectFields, where));\n };\n\n for (const { component, path, objectName } of walkPageComponents(page, `pages[${pi}]`)) {\n const type = strName(component.type);\n const props = isRec(component.properties) ? component.properties : undefined;\n if (!type || !props) continue;\n const where = `page \"${pageName}\" · ${type}`;\n const base = `${path}.properties`;\n\n if (type === RELATED_LIST_TYPE) {\n const split = relatedListFieldRefs(props, base);\n checkRefs(split.related, split.relatedObject, where);\n // `relationshipValueField` names a field on the PARENT (page) object.\n checkRefs(split.parent, objectName, where);\n // The add-picker resolves against its own object.\n checkRefs(split.picker, split.pickerObject, where);\n continue;\n }\n\n const refs = componentFieldRefs(type, props, base);\n if (!refs) continue; // unregistered / non-field component — skip silently\n checkRefs(refs, objectName, where);\n }\n\n // ── interfaceConfig (list pages) ──\n // Bound by `interfaceConfig.source`, falling back to the page's object.\n const cfg = isRec(page.interfaceConfig) ? page.interfaceConfig : undefined;\n if (cfg) {\n const cfgObject = strName(cfg.source) ?? strName(page.object);\n const base = `pages[${pi}].interfaceConfig`;\n const refs: FieldRef[] = [\n ...fieldRefsFrom(cfg.columns, `${base}.columns`),\n ...sortFieldRefs(cfg.sort, `${base}.sort`),\n ...fieldRefsFrom(cfg.filterBy, `${base}.filterBy`),\n ];\n const userFilters = isRec(cfg.userFilters) ? cfg.userFilters : undefined;\n if (userFilters) {\n refs.push(...fieldRefsFrom(userFilters.fields, `${base}.userFilters.fields`));\n }\n checkRefs(refs, cfgObject, `page \"${pageName}\" · interfaceConfig`);\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for SDUI source-tier page styling (ADR-0065 / ADR-0080 /\n// ADR-0081). A `kind:'html'` or `kind:'react'` page's `source` is RUNTIME\n// metadata — the console's build-time Tailwind only scans the renderer's own\n// source, never an authored page string. So a Tailwind `className` in page\n// source silently produces NO CSS (the exact ADR-0065 failure: styling that\n// \"works only by coincidence\" when the class happens to be one objectui already\n// ships). This rule flags authored `className` attributes in source-tier pages\n// before render, with the actionable fix.\n//\n// It is the styling counterpart to the react-prop gate: a pure\n// `(stack) => Finding[]` rule (ADR-0019), run from `os validate`/`compile` and\n// reusable by AI authoring so the agent self-corrects.\n\nexport type SourceStyleSeverity = 'error' | 'warning';\n\nexport interface SourceStyleFinding {\n severity: SourceStyleSeverity;\n rule: string;\n where: string;\n path: string;\n message: string;\n hint: string;\n}\n\nexport const PAGE_SOURCE_CLASSNAME = 'page-source-className-tailwind';\n\ntype AnyRec = Record<string, unknown>;\nconst asArray = (v: unknown): AnyRec[] => (Array.isArray(v) ? (v as AnyRec[]) : []);\n\n// `className=` as a JSX attribute: name, optional ws, `=`, then `\"`/`'`/`{`.\nconst CLASSNAME_ATTR = /\\bclassName\\s*=\\s*[\"'{]/g;\n\nexport function validatePageSourceStyling(stack: AnyRec): SourceStyleFinding[] {\n const findings: SourceStyleFinding[] = [];\n const pages = asArray(stack.pages);\n for (let p = 0; p < pages.length; p++) {\n const page = pages[p];\n if (!page) continue;\n const kind = page.kind;\n if (kind !== 'html' && kind !== 'react' && kind !== 'jsx') continue;\n const source = page.source;\n if (typeof source !== 'string' || source.trim() === '') continue;\n const name = String(page.name ?? `#${p}`);\n\n CLASSNAME_ATTR.lastIndex = 0;\n let count = 0;\n while (CLASSNAME_ATTR.exec(source) !== null) count++;\n if (count === 0) continue;\n\n findings.push({\n severity: 'warning',\n rule: PAGE_SOURCE_CLASSNAME,\n where: `page \"${name}\"`,\n path: `pages[${p}].source`,\n message: `${count} \\`className\\` attribute${count > 1 ? 's' : ''} in ${String(kind)}-source page — Tailwind utilities in page source silently produce no CSS (the build never scans authored metadata; ADR-0065).`,\n hint:\n kind === 'react'\n ? \"Style with inline style={{}} using hsl(var(--token)) theme colors (e.g. color:'hsl(var(--foreground))', background:'hsl(var(--card))'); render drawer/modal via <ObjectForm formType=\\\"drawer\\\"|\\\"modal\\\"> instead of hand-rolled overlays.\"\n : \"Lay out with the components' structured props (<flex direction gap>, <grid columns>) and add CSS via a JSON style object style={{\\\"color\\\":\\\"hsl(var(--foreground))\\\"}}; do not use Tailwind className.\",\n });\n }\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { objectTitleCompleteness } from '@objectstack/spec/data';\nimport type { DisplayNameObjectMeta } from '@objectstack/spec/data';\n\n/**\n * Build-time record-title diagnostics (ADR-0079).\n *\n * A record's human title is a structural invariant: every object resolves a\n * primary title from a real STORED field via `nameField` (the canonical\n * pointer; `displayNameField` is the deprecated alias) or a deterministic\n * derivation. Two authoring smells are flagged here so `os build`/`os lint`,\n * the MCP authoring surface, and hand-authoring all get the coverage cloud\n * graph-lint already has (the ADR-0078 \"not cloud-only\" principle):\n *\n * - `title-format-retired` — the object declares a `titleFormat`. That field\n * is a RENDER-ONLY template the server can neither return nor query; ADR-0079\n * retires it in favour of `nameField`. The schema still parses it (existing\n * metadata keeps loading), so this is advisory, not an error.\n * - `title-unresolvable` — `objectTitleCompleteness` reports `status: 'none'`:\n * no `nameField`/`displayNameField` pointer and no title-eligible field to\n * derive one from. Records will have no meaningful title (the runtime falls\n * back to the auto-provisioned primary / `Record #<id>` floor), so this is a\n * warning, not an error — nothing is fully broken.\n *\n * Both are warnings: the auto-provision transform and the id floor mean a\n * green build never ships a fully title-less object. Reuses the shared spec\n * predicate (`@objectstack/spec/data` → display-name) so cloud and framework\n * classify titles identically.\n */\n\nexport const TITLE_FORMAT_RETIRED = 'title-format-retired';\nexport const TITLE_UNRESOLVABLE = 'title-unresolvable';\n\nexport type RecordTitleSeverity = 'error' | 'warning';\n\nexport interface RecordTitleFinding {\n /** Always `warning` today — both rules are advisory (see module note). */\n severity: RecordTitleSeverity;\n /** Diagnostic rule id (registry entry), e.g. `title-format-retired`. */\n rule: string;\n /** Human-readable location, e.g. `object \"invoice\"`. */\n where: string;\n /** Config path, e.g. `objects[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/**\n * Validate every object's record-title declaration. Returns the list of\n * findings (empty = clean). Both rules are advisory (`warning`): the caller\n * must never fail the build on them alone — auto-provision + the `Record #<id>`\n * floor guarantee a resolvable title at runtime.\n */\nexport function validateRecordTitle(stack: AnyRec): RecordTitleFinding[] {\n const findings: RecordTitleFinding[] = [];\n\n const objects = asArray(stack.objects);\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const where = `object \"${objName}\"`;\n const path = `objects[${i}]`;\n\n // ── (a) titleFormat is retired (ADR-0079) ──\n // Render-only template the server cannot return or query. Still parsed by\n // the schema for back-compat, so advisory.\n if (obj.titleFormat !== undefined && obj.titleFormat !== null && obj.titleFormat !== '') {\n findings.push({\n severity: 'warning',\n rule: TITLE_FORMAT_RETIRED,\n where,\n path,\n message:\n `${objName}: titleFormat is retired (ADR-0079) — migrate to nameField ` +\n `(single field) or a formula field designated nameField`,\n hint:\n `titleFormat is a render-only template the server cannot return or ` +\n `query, and an explicit nameField now takes precedence. For a ` +\n `single-field title set nameField: '<field>'. For a composite title, ` +\n `add a formula field (returnType: 'text') and designate it via ` +\n `nameField.`,\n });\n }\n\n // ── (b) no resolvable title (status: 'none') ──\n // Reuse the shared spec predicate so cloud graph-lint and framework lint\n // classify titles identically. `none` = no pointer AND nothing derivable.\n const completeness = objectTitleCompleteness(obj as DisplayNameObjectMeta);\n if (completeness.status === 'none') {\n findings.push({\n severity: 'warning',\n rule: TITLE_UNRESOLVABLE,\n where,\n path,\n message:\n `${objName}: no resolvable record title — records will have no ` +\n `meaningful name (no nameField and no title-eligible field to derive one)`,\n hint:\n `Set nameField to a text/email field (or a formula field with ` +\n `returnType: 'text'), or add a text field named \"name\"/\"title\". The ` +\n `runtime auto-provisions a primary and falls back to \"Record #<id>\", ` +\n `but an explicit title is far more useful.`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time semantic-role diagnostics (ADR-0085).\n *\n * The object-level semantic roles (`stageField`, `highlightFields` /\n * deprecated `compactLayout`, `fieldGroups` + `Field.group`) are pointers\n * into the object's own field map. A dangling pointer is Zod-valid but\n * silently inert at render time — the exact \"parsed, unmarked, silently\n * inert\" shape ADR-0078 prohibits — so the completeness lint flags it here,\n * uniformly for `os build`/`os validate`, MCP authoring and hand authors.\n *\n * All three rules are warnings, not errors: every consumer degrades\n * gracefully (an unknown `Field.group` renders in the ungrouped bucket, an\n * unknown highlight name is skipped, an unknown `stageField` falls back to\n * heuristics), so nothing is fully broken — but the author almost certainly\n * typo'd a name and should be told at author time, not discover it by\n * staring at an unchanged page.\n */\n\nexport const FIELD_GROUP_UNDECLARED = 'field-group-undeclared';\nexport const FIELD_GROUP_EMPTY = 'field-group-empty';\nexport const FIELD_GROUP_SHADOWED = 'field-group-shadowed';\nexport const SEMANTIC_ROLE_FIELD_UNKNOWN = 'semantic-role-field-unknown';\n\nexport type SemanticRoleSeverity = 'error' | 'warning';\n\nexport interface SemanticRoleFinding {\n /** Always `warning` today — all three rules are advisory (see module note). */\n severity: SemanticRoleSeverity;\n /** Diagnostic rule id, e.g. `field-group-undeclared`. */\n rule: string;\n /** Human-readable location, e.g. `object \"invoice\"`. */\n where: string;\n /** Config path, e.g. `objects[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/**\n * Validate every object's semantic-role pointers. Returns the list of\n * findings (empty = clean). Advisory only — the caller must never fail the\n * build on these alone.\n */\nexport function validateSemanticRoles(stack: AnyRec): SemanticRoleFinding[] {\n const findings: SemanticRoleFinding[] = [];\n\n const objects = asArray(stack.objects);\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object') continue; // tolerate junk entries\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const where = `object \"${objName}\"`;\n const path = `objects[${i}]`;\n\n const fields = (obj.fields && typeof obj.fields === 'object' && !Array.isArray(obj.fields))\n ? (obj.fields as Record<string, AnyRec | undefined>)\n : {};\n const fieldNames = new Set(Object.keys(fields));\n\n // ── (a) Field.group → declared fieldGroups[].key ──\n const declaredGroups = new Set(\n (Array.isArray(obj.fieldGroups) ? obj.fieldGroups : [])\n .filter((g): g is AnyRec => !!g && typeof g === 'object')\n .map((g) => g.key)\n .filter((k): k is string => typeof k === 'string' && k.length > 0),\n );\n const referencedGroups = new Set<string>();\n for (const [fname, f] of Object.entries(fields)) {\n const g = f?.group;\n if (typeof g !== 'string' || g.length === 0) continue;\n referencedGroups.add(g);\n if (!declaredGroups.has(g)) {\n findings.push({\n severity: 'warning',\n rule: FIELD_GROUP_UNDECLARED,\n where,\n path: `${path}.fields.${fname}.group`,\n message:\n `${objName}.${fname}: group \"${g}\" is not declared in fieldGroups — ` +\n `the field renders in the ungrouped bucket, not under \"${g}\"`,\n hint:\n `Declare { key: '${g}', label: '…' } in ${objName}.fieldGroups, or fix ` +\n `the field's group reference. Group keys are snake_case and must match exactly.`,\n });\n }\n }\n\n // ── (b) declared group no field references ──\n for (const key of declaredGroups) {\n if (!referencedGroups.has(key)) {\n findings.push({\n severity: 'warning',\n rule: FIELD_GROUP_EMPTY,\n where,\n path: `${path}.fieldGroups`,\n message:\n `${objName}: fieldGroups declares \"${key}\" but no field references it — ` +\n `the group never renders`,\n hint:\n `Assign at least one field via group: '${key}', or remove the unused ` +\n `group declaration.`,\n });\n }\n }\n\n // ── (c) semantic-role pointers name real fields ──\n const stage = obj.stageField;\n if (typeof stage === 'string' && stage.length > 0 && !fieldNames.has(stage)) {\n findings.push({\n severity: 'warning',\n rule: SEMANTIC_ROLE_FIELD_UNKNOWN,\n where,\n path: `${path}.stageField`,\n message:\n `${objName}: stageField \"${stage}\" is not a field on this object — ` +\n `consumers fall back to heuristic stage detection`,\n hint:\n `Point stageField at an existing select/status field, or set ` +\n `stageField: false to declare the object has no linear lifecycle.`,\n });\n }\n\n const highlights = Array.isArray(obj.highlightFields)\n ? obj.highlightFields\n : Array.isArray(obj.compactLayout) // deprecated alias (pre-normalization input)\n ? obj.compactLayout\n : [];\n for (const entry of highlights) {\n if (typeof entry !== 'string' || entry.length === 0 || fieldNames.has(entry)) continue;\n findings.push({\n severity: 'warning',\n rule: SEMANTIC_ROLE_FIELD_UNKNOWN,\n where,\n path: `${path}.highlightFields`,\n message:\n `${objName}: highlightFields entry \"${entry}\" is not a field on this ` +\n `object — it is silently skipped by every consumer`,\n hint:\n `Fix the field name (highlightFields drives default columns, cards, ` +\n `previews and the detail highlight strip, in order).`,\n });\n }\n\n // ── (d) declared group fully shadowed by the detail highlight strip ──\n // Detail pages render the first 4 highlightFields as the top strip and\n // HIDE those fields from the details body; the record's title field is\n // the page H1 and never renders in the body either. A group whose every\n // visible member is covered by strip ∪ title therefore renders on FORMS\n // but silently never on detail pages — legal, but almost never what the\n // author pictured when they declared the group.\n const declaredStrings = highlights.filter(\n (h): h is string => typeof h === 'string' && h.length > 0,\n );\n if (declaredStrings.length > 0 && declaredGroups.size > 0) {\n // Mirror the renderer's title resolution: declared role first\n // (nameField / primaryField / deprecated displayNameField), else the\n // first conventional display-field name present on the object.\n const declaredTitle = [obj.nameField, obj.primaryField, obj.displayNameField]\n .find((v): v is string => typeof v === 'string' && v.length > 0 && fieldNames.has(v));\n const titleField = declaredTitle\n ?? ['name', 'full_name', 'title', 'subject', 'display_name'].find((c) => fieldNames.has(c));\n const stripSet = new Set(\n declaredStrings.filter((h) => h !== titleField).slice(0, 4),\n );\n const hiddenFromBody = new Set(stripSet);\n if (titleField) hiddenFromBody.add(titleField);\n\n for (const key of declaredGroups) {\n const members = Object.entries(fields)\n .filter(([, f]) => f?.group === key && f?.hidden !== true)\n .map(([fname]) => fname);\n if (members.length === 0) continue; // rule (b) already covers empty groups\n if (!members.every((m) => hiddenFromBody.has(m))) continue;\n findings.push({\n severity: 'warning',\n rule: FIELD_GROUP_SHADOWED,\n where,\n path: `${path}.fieldGroups`,\n message:\n `${objName}: every field in group \"${key}\" (${members.join(', ')}) is ` +\n `hoisted into the detail highlight strip (or is the record title) — ` +\n `the group renders on forms but never on detail pages`,\n hint:\n `Keep at least one non-highlighted field in \"${key}\", or remove the ` +\n `group if the strip already covers it. (Detail pages show the first ` +\n `4 highlightFields as the top strip and hide them from the body.)`,\n });\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time form-layout diagnostics (#2578).\n *\n * Authored form views carry field references and column-layout hints that are\n * Zod-valid but can be silently wrong at render time — the \"parsed, unmarked,\n * silently inert\" shape ADR-0078 prohibits. This lint catches the two that\n * matter for multi-column, AI-authored forms, uniformly for `os build` /\n * `os validate`, MCP authoring and hand authors (ADR-0019).\n *\n * Both rules are warnings, not errors — nothing is fully broken (an unknown\n * field name is skipped; an over-wide colSpan is clamped) — but each is almost\n * certainly an authoring mistake worth surfacing at author time:\n *\n * - `form-field-unknown` — a section references a field that is not on the\n * form's bound object, so the field silently does not render.\n * - `absolute-colspan-discouraged` — a field uses the absolute `colSpan`. Under\n * a per-surface DERIVED column count (mobile 1 / modal 2 / page 3-4) a fixed\n * span only lines up at the one width the author imagined; the renderer\n * clamps it. The robust primitive is the relative `span: 'full'`.\n *\n * Scope: top-level form `views` (a `sections` array). Forms embedded inside\n * page component trees are a follow-up — the walker deliberately stays shallow\n * so it never guesses at an arbitrary component's object binding.\n */\n\nexport const FORM_FIELD_UNKNOWN = 'form-field-unknown';\nexport const FORM_COLSPAN_ABSOLUTE = 'absolute-colspan-discouraged';\n\nexport type FormLayoutSeverity = 'error' | 'warning';\n\nexport interface FormLayoutFinding {\n /** Always `warning` today — both rules are advisory (see module note). */\n severity: FormLayoutSeverity;\n /** Diagnostic rule id, e.g. `form-field-unknown`. */\n rule: string;\n /** Human-readable location, e.g. `view \"contract_form\"`. */\n where: string;\n /** Config path, e.g. `views[2].sections[0].fields[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** A section field entry is either a bare field name or `{ field, colSpan, … }`. */\nfunction fieldNameOf(entry: unknown): string | null {\n if (typeof entry === 'string') return entry.length > 0 ? entry : null;\n if (entry && typeof entry === 'object' && !Array.isArray(entry)) {\n const f = (entry as AnyRec).field;\n return typeof f === 'string' && f.length > 0 ? f : null;\n }\n return null;\n}\n\n/** The object a form view binds to: `data.object` (canonical) or `objectName`. */\nfunction boundObject(view: AnyRec): string | undefined {\n const data = view.data;\n if (data && typeof data === 'object' && typeof (data as AnyRec).object === 'string') {\n return (data as AnyRec).object as string;\n }\n return typeof view.objectName === 'string' ? (view.objectName as string) : undefined;\n}\n\n/**\n * Validate authored form-view layout. Returns findings (empty = clean).\n * Advisory only — the caller must never fail the build on these alone.\n */\nexport function validateFormLayout(stack: AnyRec): FormLayoutFinding[] {\n const findings: FormLayoutFinding[] = [];\n\n // object name → its field-name set, for reference checking.\n const objectFields = new Map<string, Set<string>>();\n for (const obj of asArray(stack.objects)) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const fields = (obj.fields && typeof obj.fields === 'object' && !Array.isArray(obj.fields))\n ? Object.keys(obj.fields as AnyRec)\n : [];\n objectFields.set(name, new Set(fields));\n }\n\n const views = asArray(stack.views);\n for (let i = 0; i < views.length; i++) {\n const view = views[i];\n if (!view || typeof view !== 'object') continue;\n const sections = Array.isArray(view.sections) ? view.sections : null;\n if (!sections) continue; // only form views carry a sections array\n\n const viewName = typeof view.name === 'string' ? view.name : `(view ${i})`;\n const objName = boundObject(view);\n // Only reference-check when the bound object resolves; otherwise we can't.\n const known = objName ? objectFields.get(objName) : undefined;\n const where = `view \"${viewName}\"`;\n const base = `views[${i}]`;\n\n for (let s = 0; s < sections.length; s++) {\n const sec = sections[s];\n const secFields = sec && typeof sec === 'object' && Array.isArray((sec as AnyRec).fields)\n ? ((sec as AnyRec).fields as unknown[])\n : [];\n for (let f = 0; f < secFields.length; f++) {\n const entry = secFields[f];\n const fname = fieldNameOf(entry);\n const fpath = `${base}.sections[${s}].fields[${f}]`;\n\n // ── (a) section field references a real field on the bound object ──\n if (fname && known && !known.has(fname)) {\n findings.push({\n severity: 'warning',\n rule: FORM_FIELD_UNKNOWN,\n where,\n path: fpath,\n message:\n `${viewName}: field \"${fname}\" is not a field on object \"${objName}\" — ` +\n `it is silently skipped and never renders on the form`,\n hint:\n `Fix the field name, or add \"${fname}\" to ${objName}. Section field ` +\n `references must match the object's field names exactly.`,\n });\n }\n\n // ── (b) absolute colSpan → steer to the surface-independent span ──\n const colSpan = entry && typeof entry === 'object' && !Array.isArray(entry)\n ? (entry as AnyRec).colSpan\n : undefined;\n if (colSpan != null) {\n findings.push({\n severity: 'warning',\n rule: FORM_COLSPAN_ABSOLUTE,\n where,\n path: `${fpath}.colSpan`,\n message:\n `${viewName}: field \"${fname ?? '?'}\" sets absolute colSpan ${String(colSpan)} — ` +\n `the form's column count is derived per surface (mobile 1 / modal 2 / page 3-4), ` +\n `so a fixed span only aligns at one width`,\n hint:\n `Prefer span: 'full' (whole row at any column count), or omit for auto ` +\n `width. The renderer clamps colSpan to the current column count.`,\n });\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Build-time conditional-visibility diagnostics (ADR-0089 D3b).\n *\n * ADR-0089 unifies the conditional-visibility predicate under the single\n * canonical key **`visibleWhen`** across data fields, view form sections/fields,\n * and page components. The deprecated spellings — `visibleOn` (view form) and\n * `visibility` (page component) — stay accepted and are folded into `visibleWhen`\n * at the schema boundary (a zod `.transform()`). Because that fold happens during\n * `parse()`, the aliases are gone from the *parsed* stack — so this rule runs on\n * the **pre-parse** (normalized) stack, exactly like `validate-list-view-mode`,\n * to see what the author actually wrote.\n *\n * Two advisory rules (both `warning` — nothing is broken, the alias still works\n * and a mis-rooted predicate just never matches):\n *\n * - `visibility-alias-deprecated` — a `visibleOn` / `visibility` key in authored\n * source. Autofix intent: rename the key to `visibleWhen` (same value).\n * - `visibility-root-mislayered` — a visibility predicate whose binding root does\n * not match its layer (ADR-0089 D3, §Context). The check is **bidirectional**:\n * - **runtime** view/page surfaces (`*.view.ts` / `*.page.ts`) bind\n * `record` + `current_user` (pages also expose `page.<var>`), so a `data.`-rooted\n * predicate here is a wrong-layer paste that silently never matches; and\n * - **metadata-editing** forms (`*.form.ts` — the row under edit) bind `data`, so\n * a `record.`-rooted predicate there is the same bug in the other direction.\n * The layer is supplied by the caller (`opts.layer`, default `'runtime'`): the\n * app-lint path (`os validate` / `compile`) always lints runtime surfaces, while a\n * file-aware caller linting a `*.form.ts` passes `layer: 'metadata'`.\n *\n * Scope: `views` (form `sections` / legacy `groups`, and their `fields`) and\n * `pages` (`regions[].components[]`). Data-field `visibleWhen` is already covered\n * by `validate-expressions` and is not re-checked here.\n */\n\nexport const VISIBILITY_ALIAS_DEPRECATED = 'visibility-alias-deprecated';\nexport const VISIBILITY_ROOT_MISLAYERED = 'visibility-root-mislayered';\n\nexport type VisibilitySeverity = 'error' | 'warning';\n\n/**\n * Which binding environment the linted surface belongs to (ADR-0089 §Context):\n * - `runtime` — `*.view.ts` / `*.page.ts`; binds `record` + `current_user` (+ `page`).\n * - `metadata` — `*.form.ts` metadata-editing forms; binds `data` (the row under edit).\n */\nexport type VisibilityLayer = 'runtime' | 'metadata';\n\n/** Options for {@link validateVisibilityPredicates}. */\nexport interface VisibilityOptions {\n /** Binding layer of the surface being linted. Defaults to `'runtime'`. */\n layer?: VisibilityLayer;\n}\n\nexport interface VisibilityFinding {\n /** Always `warning` today — both rules are advisory (see module note). */\n severity: VisibilitySeverity;\n /** Diagnostic rule id, e.g. `visibility-alias-deprecated`. */\n rule: string;\n /** Human-readable location, e.g. `view \"contact_form\"`. */\n where: string;\n /** Config path, e.g. `views[2].sections[0].fields[3]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** The canonical key and its two deprecated aliases (ADR-0089). */\nconst CANONICAL = 'visibleWhen';\nconst ALIASES = ['visibleOn', 'visibility'] as const;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** Extract the CEL source from a predicate value (string, or `{ source }` envelope). */\nfunction predicateSource(v: unknown): string | undefined {\n if (typeof v === 'string') return v;\n if (v && typeof v === 'object' && typeof (v as AnyRec).source === 'string') {\n return (v as AnyRec).source as string;\n }\n return undefined;\n}\n\n/** Does the predicate reference `<root>.<x>` as a leading binding root? */\nfunction usesRoot(source: string, root: string): boolean {\n // `<root>` as a leading identifier followed by a property access. The leading\n // `(^|[^.\\w$])` guard excludes a nested access like `foo.data` (a field named\n // `data`) or `my_record.x` (an identifier that merely ends in `record`).\n return new RegExp(`(^|[^.\\\\w$])${root}\\\\.\\\\w`).test(source);\n}\n\n/**\n * Per-layer mis-rooted-predicate description. The `runtime` layer forbids the\n * metadata-editing-form root (`data.`); the `metadata` layer forbids the runtime\n * record-surface root (`record.`) — ADR-0089 D3 spells out both directions.\n */\nconst MISLAYER_BY_LAYER: Record<\n VisibilityLayer,\n { forbiddenRoot: string; message: string; hint: string }\n> = {\n runtime: {\n forbiddenRoot: 'data',\n message:\n 'visibility predicate is rooted at `data.` — that is the ' +\n 'metadata-editing-form root (a `*.form.ts` row under edit), not a runtime ' +\n 'surface. A runtime view/page predicate that binds `data.` never matches ' +\n 'and the element renders unconditionally (ADR-0089).',\n hint:\n 'Runtime record surfaces bind `record` + `current_user` (pages also ' +\n \"expose `page.<var>`). Use e.g. `record.status == 'open'` instead of \" +\n \"`data.status == 'open'`.\",\n },\n metadata: {\n forbiddenRoot: 'record',\n message:\n 'visibility predicate is rooted at `record.` — that is the runtime ' +\n 'record-surface root (a `*.view.ts` / `*.page.ts` live record), not a ' +\n 'metadata-editing form. A `*.form.ts` predicate that binds `record.` never ' +\n 'matches and the element renders unconditionally (ADR-0089).',\n hint:\n 'Metadata-editing forms bind `data` (the row under edit). Use e.g. ' +\n \"`data.type == 'grid'` instead of `record.type == 'grid'`.\",\n },\n};\n\n/**\n * Inspect one element carrying a visibility predicate. Emits the alias-deprecated\n * finding (when an alias key is present) and the mis-layered-root finding (when\n * the effective predicate's binding root does not match `layer`).\n */\nfunction checkElement(\n el: AnyRec,\n where: string,\n path: string,\n layer: VisibilityLayer,\n findings: VisibilityFinding[],\n): void {\n // (1) deprecated alias key present → steer to `visibleWhen`.\n for (const alias of ALIASES) {\n if (el[alias] !== undefined) {\n findings.push({\n severity: 'warning',\n rule: VISIBILITY_ALIAS_DEPRECATED,\n where,\n path: `${path}.${alias}`,\n message:\n `\\`${alias}\\` is the deprecated spelling of the conditional-visibility ` +\n `predicate (ADR-0089). It still works — it is normalized to \\`visibleWhen\\` ` +\n `at parse — but the canonical key is \\`visibleWhen\\`.`,\n hint: `Rename the key \\`${alias}\\` → \\`visibleWhen\\` (same CEL value).`,\n });\n }\n }\n\n // (2) mis-layered binding root — check the effective predicate (canonical wins)\n // against the root expected for this layer.\n const raw = el[CANONICAL] ?? el.visibleOn ?? el.visibility;\n const source = predicateSource(raw);\n const rule = MISLAYER_BY_LAYER[layer];\n if (source && usesRoot(source, rule.forbiddenRoot)) {\n findings.push({\n severity: 'warning',\n rule: VISIBILITY_ROOT_MISLAYERED,\n where,\n path,\n message: rule.message,\n hint: rule.hint,\n });\n }\n}\n\n/** A section field entry is either a bare field name or `{ field, visibleWhen, … }`. */\nfunction isFieldObject(entry: unknown): entry is AnyRec {\n return !!entry && typeof entry === 'object' && !Array.isArray(entry);\n}\n\n/**\n * Validate conditional-visibility keys across authored views and pages.\n *\n * Runs on the **pre-parse** (normalized) stack so it can see the deprecated\n * `visibleOn` / `visibility` aliases before the schema folds them into\n * `visibleWhen`. Returns findings (empty = clean); all advisory (`warning`) —\n * the caller must never fail the build on these alone.\n *\n * The binding-root check is layer-directional (ADR-0089 D3): pass\n * `opts.layer = 'metadata'` when linting a `*.form.ts` metadata-editing form (so a\n * `record.`-rooted predicate is flagged), or leave it at the `'runtime'` default for\n * `*.view.ts` / `*.page.ts` surfaces (so a `data.`-rooted predicate is flagged). The\n * alias-deprecated check is layer-agnostic.\n */\nexport function validateVisibilityPredicates(\n stack: AnyRec,\n opts: VisibilityOptions = {},\n): VisibilityFinding[] {\n const layer: VisibilityLayer = opts.layer ?? 'runtime';\n const findings: VisibilityFinding[] = [];\n\n // ── Views: form sections / legacy groups, and their fields ──────────\n const views = asArray(stack.views);\n for (let i = 0; i < views.length; i++) {\n const view = views[i];\n if (!view || typeof view !== 'object') continue;\n const viewName = typeof view.name === 'string' ? view.name : `(view ${i})`;\n const where = `view \"${viewName}\"`;\n\n // `sections` (canonical) and `groups` (legacy alias → sections) both hold\n // FormSection objects with an optional visibility predicate + `fields`.\n for (const bucket of ['sections', 'groups'] as const) {\n const sections = Array.isArray(view[bucket]) ? (view[bucket] as unknown[]) : [];\n for (let s = 0; s < sections.length; s++) {\n const sec = sections[s];\n if (!sec || typeof sec !== 'object') continue;\n const secPath = `views[${i}].${bucket}[${s}]`;\n checkElement(sec as AnyRec, where, secPath, layer, findings);\n\n const secFields = Array.isArray((sec as AnyRec).fields) ? ((sec as AnyRec).fields as unknown[]) : [];\n for (let f = 0; f < secFields.length; f++) {\n const entry = secFields[f];\n if (isFieldObject(entry)) {\n checkElement(entry, where, `${secPath}.fields[${f}]`, layer, findings);\n }\n }\n }\n }\n }\n\n // ── Pages: regions[].components[] ───────────────────────────────────\n const pages = asArray(stack.pages);\n for (let i = 0; i < pages.length; i++) {\n const page = pages[i];\n if (!page || typeof page !== 'object') continue;\n const pageName = typeof page.name === 'string' ? page.name : `(page ${i})`;\n const where = `page \"${pageName}\"`;\n const regions = Array.isArray(page.regions) ? (page.regions as unknown[]) : [];\n for (let r = 0; r < regions.length; r++) {\n const region = regions[r];\n const components = region && typeof region === 'object' && Array.isArray((region as AnyRec).components)\n ? ((region as AnyRec).components as unknown[])\n : [];\n for (let c = 0; c < components.length; c++) {\n const comp = components[c];\n if (comp && typeof comp === 'object') {\n checkElement(comp as AnyRec, where, `pages[${i}].regions[${r}].components[${c}]`, layer, findings);\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0066 ⑨] Authoring-time validation for capability references.\n *\n * `requiredPermissions` (on objects, fields, apps, and actions) and\n * `systemPermissions` (on permission sets) are free capability strings. A typo\n * — `mange_users` for `manage_users` — is Zod-valid and fails CLOSED at runtime\n * (the caller is denied), which is the safe direction but UNDISCOVERABLE: nothing\n * tells the author the referenced capability exists nowhere. This rule closes\n * that gap by resolving every `requiredPermissions` reference against the set of\n * capabilities known at author time and warning on the unresolved ones —\n * \"reject at the producer\" (Prime Directive / ADR-0049 honesty).\n *\n * The author-time \"known\" set is:\n * 1. the built-in platform capabilities (`PLATFORM_CAPABILITY_NAMES`),\n * 2. every capability the stack DECLARES via `defineCapability`\n * (`stack.capabilities`) — the explicit, package-provenanced declaration\n * (ADR-0066 D1), materialized at boot by `bootstrapDeclaredCapabilities`,\n * 3. every capability a permission set in this stack GRANTS via\n * `systemPermissions` (granting a capability also declares it — mirrors\n * the runtime `bootstrapSystemCapabilities` derived-defaults rule), and\n * 4. any `sys_capability` row shipped as seed data.\n *\n * WARNING, not error: a single package's lint cannot see capabilities declared\n * by OTHER installed packages, and the reference fails closed at runtime anyway,\n * so a dangling reference is \"almost certainly a typo\" — surface it, don't break\n * the build. Assignment (`systemPermissions`) is NOT flagged: it is the\n * declaration side, and a package legitimately introduces new capabilities there.\n */\n\nimport { PLATFORM_CAPABILITY_NAMES } from '@objectstack/spec/security';\n\nexport const CAPABILITY_REFERENCE_UNKNOWN = 'capability-reference-unknown';\n\nexport type CapabilityRefSeverity = 'error' | 'warning';\n\nexport interface CapabilityRefFinding {\n /** Always `warning` — the reference fails closed at runtime (see module note). */\n severity: CapabilityRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `object \"sys_license\"`. */\n where: string;\n /** Config path, e.g. `objects[3].requiredPermissions`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** The capability strings in a `string[]` value. */\nfunction asCapArray(v: unknown): string[] {\n return Array.isArray(v) ? v.filter((s): s is string => typeof s === 'string' && s.length > 0) : [];\n}\n\n/**\n * Flatten an object-level `requiredPermissions` — either a `string[]` (all\n * operations) or a per-operation `{ read, create, update, delete }` map (ADR-0066\n * ⑤) — into `[{ cap, key }]`, where `key` is the map key (or `undefined` for the\n * array form) so a finding can point at the exact operation slice.\n */\nfunction flattenObjectRequired(v: unknown): Array<{ cap: string; key?: string }> {\n if (Array.isArray(v)) return asCapArray(v).map((cap) => ({ cap }));\n if (v && typeof v === 'object') {\n const out: Array<{ cap: string; key?: string }> = [];\n for (const [key, val] of Object.entries(v as AnyRec)) {\n for (const cap of asCapArray(val)) out.push({ cap, key });\n }\n return out;\n }\n return [];\n}\n\n/**\n * Validate every capability reference in a stack. Returns findings (empty =\n * clean). Advisory only — callers must not fail the build on these alone.\n */\nexport function validateCapabilityReferences(stack: AnyRec): CapabilityRefFinding[] {\n const findings: CapabilityRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n // ── Build the author-time \"known capability\" set ──\n const known = new Set<string>(PLATFORM_CAPABILITY_NAMES);\n // [ADR-0066 D1] Capabilities the stack explicitly DECLARES via defineCapability.\n for (const cap of asArray(stack.capabilities)) {\n if (typeof cap.name === 'string' && cap.name.length > 0) known.add(cap.name);\n }\n for (const ps of asArray(stack.permissions)) {\n for (const cap of asCapArray(ps.systemPermissions)) known.add(cap);\n }\n for (const seed of asArray(stack.data)) {\n if (seed.object !== 'sys_capability') continue;\n for (const rec of Array.isArray(seed.records) ? seed.records : []) {\n const name = (rec as AnyRec | null)?.name;\n if (typeof name === 'string' && name.length > 0) known.add(name);\n }\n }\n\n const hint =\n 'Fix the capability name, define it with defineCapability (stack.capabilities), ' +\n 'declare it on a permission set’s systemPermissions, ship a sys_capability seed row, ' +\n 'or ignore this if the capability is provided by another installed package ' +\n '(references fail closed at runtime).';\n\n const flag = (cap: string, where: string, path: string) => {\n if (known.has(cap)) return;\n findings.push({\n severity: 'warning',\n rule: CAPABILITY_REFERENCE_UNKNOWN,\n where,\n path,\n message:\n `requiredPermissions references capability \"${cap}\" which is registered ` +\n `nowhere — no built-in capability, no permission set in this package grants ` +\n `it via systemPermissions, and no sys_capability seed declares it`,\n hint,\n });\n };\n\n // ── Objects (D3) + their fields (D3) + embedded actions (D4) ──\n const objects = asArray(stack.objects);\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object') continue;\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const objPath = `objects[${i}]`;\n\n for (const { cap, key } of flattenObjectRequired(obj.requiredPermissions)) {\n flag(cap, `object \"${objName}\"`, `${objPath}.requiredPermissions${key ? `.${key}` : ''}`);\n }\n\n const fields = asArray(obj.fields);\n for (const f of fields) {\n const fname = typeof f.name === 'string' ? f.name : '(field)';\n for (const cap of asCapArray(f.requiredPermissions)) {\n flag(cap, `field \"${objName}.${fname}\"`, `${objPath}.fields.${fname}.requiredPermissions`);\n }\n }\n\n for (const [ai, action] of asArray(obj.actions).entries()) {\n const aName = typeof action.name === 'string' ? action.name : `(action ${ai})`;\n for (const cap of asCapArray(action.requiredPermissions)) {\n flag(cap, `action \"${objName}.${aName}\"`, `${objPath}.actions[${ai}].requiredPermissions`);\n }\n }\n }\n\n // ── Top-level actions (D4) ──\n for (const [i, action] of asArray(stack.actions).entries()) {\n const aName = typeof action.name === 'string' ? action.name : `(action ${i})`;\n for (const cap of asCapArray(action.requiredPermissions)) {\n flag(cap, `action \"${aName}\"`, `actions[${i}].requiredPermissions`);\n }\n }\n\n // ── Apps: requiredPermissions can appear at the app, area/tab, and nav-item\n // (recursively through groups) levels. Walk each app subtree. ──\n const apps = asArray(stack.apps);\n for (let i = 0; i < apps.length; i++) {\n const app = apps[i];\n if (!app || typeof app !== 'object') continue;\n const appName = typeof app.name === 'string' ? app.name : `(app ${i})`;\n const walk = (node: unknown, path: string) => {\n if (!node || typeof node !== 'object') return;\n if (Array.isArray(node)) {\n node.forEach((child, ci) => walk(child, `${path}[${ci}]`));\n return;\n }\n const rec = node as AnyRec;\n for (const cap of asCapArray(rec.requiredPermissions)) {\n flag(cap, `app \"${appName}\"`, `${path}.requiredPermissions`);\n }\n // Recurse only into the sub-structures that carry requiredPermissions.\n if (rec.navigation) walk(rec.navigation, `${path}.navigation`);\n if (rec.areas) walk(rec.areas, `${path}.areas`);\n if (rec.tabs) walk(rec.tabs, `${path}.tabs`);\n if (rec.children) walk(rec.children, `${path}.children`);\n if (rec.items) walk(rec.items, `${path}.items`);\n };\n walk(app, `apps[${i}]`);\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Approval-node approver authoring lint (ADR-0090 D3 fallout).\n *\n * `org_membership_level` (and `role`, its deprecated spelling) resolves against\n * better-auth's org-membership tier (`sys_member.role`: owner / admin / member)\n * — it is NOT a position. After ADR-0090 D3 renamed `sys_role` → `sys_position`,\n * downstream apps that authored `{ type: 'role', value: 'sales_manager' }`\n * silently route the approval to nobody: the expansion finds no member row,\n * falls back to the `role:sales_manager` literal, and the request waits on an\n * approver that can never act. These rules move that failure from a stuck\n * request at runtime to a located fix-it at author time.\n *\n * Rules:\n *\n * | Rule | Severity | Origin |\n * |--------------------------------------------|----------|----------------------------|\n * | approval-approver-not-membership-tier | warning | ADR-0090 D3 (hotcrm class) |\n * | approval-approver-type-deprecated | warning | ADR-0090 D3 (#3133) |\n * | approval-approver-type-unknown | warning | contract-first (PD #12) |\n * | approval-escalation-reassign-no-target | warning | silent notify degradation |\n * | approval-approvers-may-resolve-empty | info | empty-position dead-end (#3424) |\n * | approval-expression-invalid | error/info | #3447 P2 closed-root expressions |\n * | approval-expression-no-empty-policy | info | #3447 P2 empty-slate policy |\n * | approval-decision-outputs-reserved | error | #3447 P2 resume envelope |\n * | approval-approver-cross-org-unsupported | error | ADR-0105 D9 targeting |\n *\n * The first two are mutually exclusive by construction — a bad *value* wins,\n * because its fix (`position`) differs from the deprecation's fix\n * (`org_membership_level`), and prescribing the latter for a position name\n * would be wrong advice.\n *\n * Warnings (not errors): a custom better-auth membership tier is legal, and\n * the runtime keeps its literal fallback — but both shapes are near-certainly\n * authoring mistakes, so say it out loud.\n *\n * Pure `(stack) => Finding[]`; accepts the NORMALIZED stack input.\n */\n\nimport {\n ApproverType,\n APPROVAL_NODE_TYPE,\n DEPRECATED_APPROVER_TYPES,\n APPROVER_VALUE_BINDINGS,\n approverTypeIsOrgScoped,\n canonicalApproverType,\n normalizeDecisionOutputs,\n} from '@objectstack/spec/automation';\nimport { BUILTIN_MEMBERSHIP_ROLES } from '@objectstack/spec';\nimport { collectCelRootIdentifiers } from '@objectstack/formula';\nimport { walkFlowNodes } from './flow-walk.js';\n\nexport const APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER = 'approval-approver-not-membership-tier';\nexport const APPROVAL_APPROVER_TYPE_DEPRECATED = 'approval-approver-type-deprecated';\nexport const APPROVAL_APPROVER_TYPE_UNKNOWN = 'approval-approver-type-unknown';\nexport const APPROVAL_APPROVER_TYPE_UNSUPPORTED = 'approval-approver-type-unsupported';\nexport const APPROVAL_ESCALATION_REASSIGN_NO_TARGET = 'approval-escalation-reassign-no-target';\nexport const APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY = 'approval-approvers-may-resolve-empty';\nexport const APPROVAL_EXPRESSION_INVALID = 'approval-expression-invalid';\nexport const APPROVAL_EXPRESSION_NO_EMPTY_POLICY = 'approval-expression-no-empty-policy';\nexport const APPROVAL_DECISION_OUTPUTS_RESERVED = 'approval-decision-outputs-reserved';\nexport const APPROVAL_APPROVER_CROSS_ORG_UNSUPPORTED = 'approval-approver-cross-org-unsupported';\n\n/**\n * The CLOSED root set an `expression` approver may reference (#3447 P2) —\n * `current` (live record at node entry), `trigger` (submit-time snapshot),\n * `vars` (flow variables). Mirrors APPROVER_EXPRESSION_ROOTS in\n * plugin-approvals; both sides extract roots via the same\n * {@link collectCelRootIdentifiers}, so what lints clean is what runs.\n */\nconst EXPRESSION_ROOTS = new Set(['current', 'trigger', 'vars']);\n\n/** Resume-envelope keys a decision output may never use (#3447 P2). */\nconst RESERVED_OUTPUT_KEYS = new Set(['decision', 'requestId']);\n\n/**\n * Approver types that route to a GROUP whose membership is runtime data and can\n * be empty (an unstaffed position, an empty team/department). When EVERY\n * approver on a node is one of these, the node can resolve to an empty slate at\n * runtime — the framework#3424 dead-end. Individually-routed types\n * (`user`/`field`/`manager`), the guaranteed-staffed `org_membership_level`\n * tiers, and the opaque `queue` are deliberately excluded: any of them present\n * signals the author has a non-group route, so the node isn't purely\n * group-gated.\n */\nconst GROUP_ROUTED_TYPES = new Set(['position', 'team', 'department']);\n\nexport type ApprovalApproverSeverity = 'error' | 'warning' | 'info';\n\nexport interface ApprovalApproverFinding {\n severity: ApprovalApproverSeverity;\n /** Diagnostic rule id (`approval-*`). */\n rule: string;\n /** Human-readable location, e.g. `flow \"expense_approval\" · node \"step1\"`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[2].config.approvers[0]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/**\n * The org-membership tiers `sys_member.role` actually stores — DERIVED, not\n * transcribed (ADR-0108 / #3723).\n *\n * The vocabulary is closed and framework-owned, so the one source in\n * `@objectstack/spec` is also the only correct list here. A hand-kept copy is\n * how this list came to carry `guest`, which the `sys_member.role` select has\n * never offered: an approver naming it resolved to nobody, and the lint that\n * exists to catch exactly that stayed silent.\n *\n * Anything outside this set authored as `{ type: 'org_membership_level' }` (or\n * its deprecated `role` spelling) is almost certainly a position name.\n */\nconst MEMBERSHIP_TIERS: ReadonlySet<string> = new Set<string>(BUILTIN_MEMBERSHIP_ROLES);\n\n/** The same list, rendered for diagnostics — so no message can contradict it. */\nconst MEMBERSHIP_TIER_LIST = BUILTIN_MEMBERSHIP_ROLES.join('/');\n\n/** Off-spec dialect spellings we can name a canonical fix for. */\nconst TYPE_FIX: Record<string, string> = {\n business_unit: 'department',\n bu: 'department',\n};\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/**\n * Validate the approvers of every Approval node in the stack's flows.\n * Returns findings (empty = clean).\n */\nexport function validateApprovalApprovers(stack: AnyRec): ApprovalApproverFinding[] {\n const findings: ApprovalApproverFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const flows = asArray(stack.flows);\n const validTypes = new Set<string>(ApproverType.options);\n\n for (let fi = 0; fi < flows.length; fi++) {\n const flow = flows[fi];\n if (!flow || typeof flow !== 'object') continue;\n const flowName = typeof flow.name === 'string' ? flow.name : `(flow ${fi})`;\n // Every node, INCLUDING those nested in try_catch / loop / parallel regions\n // — an approval inside a loop body is still an approval (#4380).\n const walked = walkFlowNodes(flow, `flows[${fi}]`);\n\n for (let ni = 0; ni < walked.length; ni++) {\n const { node, path: nodePath } = walked[ni];\n if (!node || node.type !== APPROVAL_NODE_TYPE) continue;\n const nodeId = typeof node.id === 'string' ? node.id : `(node ${ni})`;\n const cfg = (node.config ?? {}) as AnyRec;\n const approvers = Array.isArray(cfg.approvers) ? (cfg.approvers as AnyRec[]) : [];\n const where = `flow \"${flowName}\" · node \"${nodeId}\"`;\n\n for (let ai = 0; ai < approvers.length; ai++) {\n const a = approvers[ai];\n if (!a || typeof a !== 'object') continue;\n const type = typeof a.type === 'string' ? a.type : '';\n const value = typeof a.value === 'string' ? a.value : '';\n const path = `${nodePath}.config.approvers[${ai}]`;\n\n if (type && !validTypes.has(type)) {\n const fix = TYPE_FIX[type];\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_TYPE_UNKNOWN,\n where,\n path: `${path}.type`,\n message:\n `approver type '${type}' is not an ApproverType (${ApproverType.options.join(' | ')}).`,\n hint: fix\n ? `Use the spec value: { type: '${fix}', value: '${value}' }.`\n : `Pick one of the spec values; unmapped types degrade to an inert '${type}:${value}' literal at runtime.`,\n });\n continue;\n }\n\n const canonical = canonicalApproverType(type);\n\n // Expression approvers (#3447 P2): the runtime REJECTS an expression\n // that doesn't parse or references a root outside `current`/`trigger`/\n // `vars` (the CEL env would resolve an unknown root as dyn → null → a\n // silently-empty slate, so the pre-check fails the node loudly). Catch\n // both at author time — `error`, because the node cannot run.\n if (canonical === 'expression') {\n const source = value.trim();\n if (!source) {\n findings.push({\n severity: 'error',\n rule: APPROVAL_EXPRESSION_INVALID,\n where,\n path: `${path}.value`,\n message: `expression approver has an empty expression — the node fails at entry.`,\n hint:\n `Write a CEL expression over current.* (the record's live state at node entry), ` +\n `trigger.* (the submit-time snapshot) or vars.* (flow variables), ` +\n `e.g. current.approvers_dynamic or vars.approval_lead.picked_departments.`,\n });\n } else {\n const parsed = collectCelRootIdentifiers(source);\n if (!parsed.ok) {\n findings.push({\n severity: 'error',\n rule: APPROVAL_EXPRESSION_INVALID,\n where,\n path: `${path}.value`,\n message: `expression approver does not parse as CEL: ${parsed.error}.`,\n hint:\n `Approver expressions are bare CEL (no {…} template braces), e.g. ` +\n `current.approvers_dynamic or vars.get_reviewers.record.owner_id.`,\n });\n } else {\n const illegal = parsed.roots.filter((r) => !EXPRESSION_ROOTS.has(r));\n if (illegal.length) {\n const wantsRecord = illegal.includes('record') || illegal.includes('previous');\n findings.push({\n severity: 'error',\n rule: APPROVAL_EXPRESSION_INVALID,\n where,\n path: `${path}.value`,\n message:\n `expression approver references \\`${illegal.join('`, `')}\\` — only current.*, ` +\n `trigger.* and vars.* are available, and the node fails at entry on any other root.`,\n hint: wantsRecord\n ? `\\`record\\`/\\`previous\\` are not bound here (on this platform \\`record\\` always means ` +\n `\"the record at event time\", which is ambiguous at an approval node). Write ` +\n `current.<field> for the live value at node entry, trigger.<field> for the ` +\n `submit-time snapshot (vars.previous carries the pre-update row).`\n : `Did you mean current.<field> (live record), trigger.<field> (submit snapshot), ` +\n `or vars.<name> (flow variable)?`,\n });\n }\n }\n }\n } else if (a.resolveAs != null) {\n // resolveAs only means something on an expression approver; on any\n // other type it silently does nothing — surface the dead config.\n findings.push({\n severity: 'info',\n rule: APPROVAL_EXPRESSION_INVALID,\n where,\n path: `${path}.resolveAs`,\n message: `resolveAs has no effect on a '${type}' approver — it only applies to type 'expression'.`,\n hint: `Remove it, or switch this approver to { type: 'expression', value: '<CEL>', resolveAs: '${String(a.resolveAs)}' }.`,\n });\n }\n\n // Exactly one of the two below fires. Order matters: a bad VALUE is\n // the more serious (and differently-fixed) defect, so it wins. Telling\n // an author to rewrite { type: 'role', value: 'sales_manager' } as\n // `org_membership_level` would be actively wrong advice — the fix is\n // `position`, and the deprecation is beside the point.\n if (canonical === 'org_membership_level' && value && !MEMBERSHIP_TIERS.has(value.toLowerCase())) {\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_NOT_MEMBERSHIP_TIER,\n where,\n path: `${path}.value`,\n message:\n `approver { type: '${type}', value: '${value}' } resolves against the better-auth ` +\n `org-membership tier (sys_member.role: ${MEMBERSHIP_TIER_LIST}) — '${value}' is not ` +\n `a membership tier, so this approver matches nobody and the request stalls.`,\n hint:\n `If '${value}' is an org position, author { type: 'position', value: '${value}' } ` +\n `(resolved via sys_user_position, ADR-0090 D3). Keep type 'org_membership_level' ` +\n `only for membership tiers (${MEMBERSHIP_TIER_LIST}) — the vocabulary is closed ` +\n `(ADR-0108), so a business role is always a position.`,\n });\n } else if (type in DEPRECATED_APPROVER_TYPES) {\n const fix = canonicalApproverType(type);\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_TYPE_DEPRECATED,\n where,\n path: `${path}.type`,\n message:\n `approver type '${type}' is the deprecated spelling of '${fix}' (ADR-0090 D3) and ` +\n `is removed in the next major.`,\n hint: `Author { type: '${fix}', value: '${value}' }. It resolves identically today.`,\n });\n } else if (\n (APPROVER_VALUE_BINDINGS as Record<string, { source: string }>)[canonical]?.source === 'unsupported'\n ) {\n // Declared-but-unenforced (#3508): the runtime has no resolution for\n // this type — the slot degrades to an inert `type:value` literal and\n // the request routes to nobody. Say it at authoring time instead of\n // letting the request stall silently (Prime Directive #10).\n findings.push({\n severity: 'warning',\n rule: APPROVAL_APPROVER_TYPE_UNSUPPORTED,\n where,\n path: `${path}.type`,\n message:\n `approver type '${type}' is declared but not implemented by the runtime (#3508) — ` +\n `the slot resolves to nobody and the request stalls.`,\n hint:\n `Route to people the engine can expand: { type: 'team' | 'department' | 'position', ... }. ` +\n `Queue approvers need a real ownership-queue implementation before they take effect.`,\n });\n }\n\n // [ADR-0105 D9] Cross-organization targeting on a type that has no\n // organization-scoped directory. `user` / `field` / `manager` name a\n // person outright and `team` membership carries no organization, so the\n // declaration cannot narrow anything — it is a misunderstanding of what\n // the field does, and the runtime refuses it. Error, not warning: this\n // is a certain authoring mistake with a certain fix, and letting it\n // reach the runtime turns author time into an incident.\n const declaredOrg = (a as AnyRec).organization;\n if (typeof declaredOrg === 'string' && declaredOrg.trim() !== ''\n && ApproverType.options.includes(canonical as never)\n && !approverTypeIsOrgScoped(canonical)) {\n findings.push({\n severity: 'error',\n rule: APPROVAL_APPROVER_CROSS_ORG_UNSUPPORTED,\n where,\n path: `${path}.organization`,\n message:\n `approver type '${type}' does not resolve through an organization directory, so ` +\n `'organization: ${declaredOrg}' has no effect (ADR-0105 D9) — the runtime refuses it.`,\n hint:\n `Drop 'organization' here. Cross-organization targeting applies to ` +\n `'position', 'org_membership_level', 'department' and 'expression' approvers.`,\n });\n }\n }\n\n // Empty-slate dead-end (#3424): when EVERY approver on the node routes to\n // a group whose membership can be empty (an unstaffed position, an empty\n // team/department), the request can resolve to an empty `pending_approvers`\n // at runtime — no concrete user can act, and with `lockRecord` the record\n // stays locked with no recovery except a platform/tenant admin override.\n // Advisory (`info`): staffing is runtime data a linter can't see, so this\n // flags the risky SHAPE and prescribes a guaranteed-staffed fallback.\n const routable = approvers.filter(\n (a) => a && typeof a === 'object' && typeof (a as AnyRec).type === 'string',\n );\n if (\n routable.length > 0 &&\n routable.every((a) => GROUP_ROUTED_TYPES.has(canonicalApproverType(String((a as AnyRec).type))))\n ) {\n const locks = (cfg as AnyRec).lockRecord !== false; // default true\n findings.push({\n severity: 'info',\n rule: APPROVAL_APPROVERS_MAY_RESOLVE_EMPTY,\n where,\n path: `${nodePath}.config.approvers`,\n message:\n `every approver on this node routes to a group (position/team/department) whose ` +\n `members are runtime data — if none is staffed, the request resolves to an empty ` +\n `slate and waits forever` +\n (locks ? `, and (lockRecord) the record stays locked with no in-product recovery.` : `.`),\n hint:\n `Make sure at least one target is always staffed, or add a guaranteed-staffed ` +\n `fallback approver, e.g. { type: 'org_membership_level', value: 'owner' }. A request ` +\n `that still lands empty is recoverable only by a platform/tenant admin override (#3424).`,\n });\n }\n\n // #3447 P2: a node with an `expression` approver resolves people from\n // runtime data — an empty result is far likelier than for static types\n // (a mid-flow field nobody wrote yet, an upstream output that came back\n // empty). Nudge the author to SAY what an empty slate should do rather\n // than inherit the default silently.\n const hasExpression = approvers.some(\n (a) => a && typeof a === 'object' && canonicalApproverType(String((a as AnyRec).type ?? '')) === 'expression',\n );\n if (hasExpression && (cfg as AnyRec).onEmptyApprovers == null) {\n findings.push({\n severity: 'info',\n rule: APPROVAL_EXPRESSION_NO_EMPTY_POLICY,\n where,\n path: `${nodePath}.config`,\n message:\n `this node resolves approvers from an expression but declares no onEmptyApprovers — ` +\n `an empty result falls back to the default ('admin_rescue': request opens, only a ` +\n `privileged admin can act).`,\n hint:\n `Declare the empty-slate policy explicitly: onEmptyApprovers: 'admin_rescue' (hold for ` +\n `admin takeover), 'fail' (fail the node — config bug), or 'auto_approve' (wave through, ` +\n `output.autoApproved = true).`,\n });\n }\n\n // #3447 P2: `decision`/`requestId` ride the resume envelope; a declared\n // decision output with either name is rejected at runtime on every\n // decide — the node can never accept the output it declares.\n // Bare keys and typed { key, … } declarations whitelist identically —\n // the spec normalizer is the one reader of the union shape.\n const declaredOutputs = normalizeDecisionOutputs((cfg as AnyRec).decisionOutputs).map((d) => d.key);\n const reserved = declaredOutputs.filter((k) => RESERVED_OUTPUT_KEYS.has(k));\n if (reserved.length) {\n findings.push({\n severity: 'error',\n rule: APPROVAL_DECISION_OUTPUTS_RESERVED,\n where,\n path: `${nodePath}.config.decisionOutputs`,\n message:\n `decisionOutputs declares reserved key(s) \\`${reserved.join('`, `')}\\` — the resume ` +\n `envelope owns them, so every decide carrying them is rejected.`,\n hint: `Rename the output key(s); any name other than 'decision'/'requestId' works.`,\n });\n }\n\n // escalation.action 'reassign' with no escalateTo silently degrades to a\n // plain SLA-breach notification at runtime — the hand-off the author\n // asked for never happens.\n const escalation = (cfg.escalation ?? null) as AnyRec | null;\n if (escalation && typeof escalation === 'object' && escalation.action === 'reassign') {\n const target = typeof escalation.escalateTo === 'string' ? escalation.escalateTo.trim() : '';\n if (!target) {\n findings.push({\n severity: 'warning',\n rule: APPROVAL_ESCALATION_REASSIGN_NO_TARGET,\n where,\n path: `${nodePath}.config.escalation.escalateTo`,\n message:\n `escalation.action is 'reassign' but escalateTo is empty — at runtime the ` +\n `escalation degrades to a notify and the request stays with the original approvers.`,\n hint:\n `Set escalateTo to a position machine name (expanded via sys_user_position, ` +\n `ADR-0090 D3) or a specific user id, or change action to 'notify'.`,\n });\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for replay-unsafe seed datasets (framework#3434).\n//\n// A pure `(stack) => Finding[]` rule (ADR-0019), run from `os validate` and\n// reusable by AI authoring. Seeds are REPLAYED — they re-load on every\n// dev-server boot and every package re-publish, not applied once — so a\n// dataset's mode has to be idempotent. `mode: 'insert'` is the one mode that\n// is not: the loader's `insert` path writes every record unconditionally, with\n// no existing-row check, so the table grows by the dataset's size on every\n// restart (the showcase `showcase_project_membership` fixture went 3 → 6 → 9).\n//\n// This is the authoring-time nudge that would have caught #3434 before boot:\n// flag `insert`, and point at the idempotent modes (`ignore` / `upsert`) plus\n// the `externalId` — single field, or a COMPOSITE list of fields for a join /\n// junction table that has no single natural key (`['team', 'project']`), the\n// support for which #3434 added.\n//\n// Advisory (warning): an `insert` seed is not a schema error — it loads and\n// \"works\" on a fresh DB; the defect only shows on the second boot. So it earns\n// a located fix-it, not a hard `os compile` gate.\n\nexport type SeedReplaySafetySeverity = 'error' | 'warning';\n\nexport interface SeedReplaySafetyFinding {\n severity: SeedReplaySafetySeverity;\n rule: string;\n /** Human-readable location, e.g. `seed \"showcase_project_membership\"`. */\n where: string;\n /** Config path, e.g. `data[12].mode`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const SEED_INSERT_MODE_DUPLICATES_ON_REPLAY = 'seed-insert-mode-duplicates-on-replay';\n\ntype AnyRec = Record<string, unknown>;\n\n/**\n * Flag every seed dataset declared with `mode: 'insert'` — the one non-idempotent\n * mode, which duplicates its rows on every replay boot (framework#3434). Returns\n * the findings (empty = clean). The caller decides how to surface them / whether\n * to fail the build; the CLI folds them in as advisory warnings.\n *\n * Reads `stack.data` (the `SeedSchema[]` fixtures). Safe on any shape — a stack\n * with no `data` array yields no findings.\n */\nexport function validateSeedReplaySafety(stack: AnyRec): SeedReplaySafetyFinding[] {\n const out: SeedReplaySafetyFinding[] = [];\n const seeds = Array.isArray(stack.data) ? (stack.data as AnyRec[]) : [];\n\n seeds.forEach((seed, i) => {\n if (!seed || typeof seed !== 'object') return;\n if (seed.mode !== 'insert') return;\n\n const object = typeof seed.object === 'string' ? seed.object : undefined;\n const where = object ? `seed \"${object}\"` : `data[${i}]`;\n\n out.push({\n severity: 'warning',\n rule: SEED_INSERT_MODE_DUPLICATES_ON_REPLAY,\n where,\n path: `data[${i}].mode`,\n message:\n \"`mode: 'insert'` re-inserts every record on each replay boot (dev-server restart, \" +\n 'package re-publish) with no existing-row check, so the dataset duplicates the table ' +\n 'on every restart — seeds are replayed, not applied once.',\n hint:\n \"Use `mode: 'ignore'` (skip rows that already exist) or `'upsert'` (create-or-update), \" +\n \"and declare an `externalId` to match on: a single natural-key field (e.g. `externalId: 'code'`), \" +\n 'or a COMPOSITE list of fields for a join / junction table with no single natural key ' +\n \"(e.g. `externalId: ['team', 'project']`).\",\n });\n });\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Build-time guardrail for seed values that fall outside an object's declared\n// state machine (framework#3433 follow-up).\n//\n// #3433 made seed writes EXEMPT from the `state_machine` validation rule — a\n// curated seed is an established fact, so it may be born mid-lifecycle\n// (a `completed` project, a `closed_won` opportunity) without the FSM entry\n// guard rejecting it. That exemption is deliberate, but it is also a SILENT\n// back door: the state machine's \"is this value even a state I know about?\"\n// check no longer runs for seed rows. A field-level `select` still rejects a\n// value outside its `options` at write time, so a plain typo is caught there —\n// but a `state_machine` on a free-text field, or a value that is a valid option\n// yet not a declared FSM state, now sails straight through.\n//\n// This author-time rule re-adds that safety net WITHOUT re-imposing the FSM: a\n// seeded value need not be an initial state (that is the whole point of the\n// exemption), but it must be a state the machine DECLARES — the union of\n// `initialStates`, the transition-map keys, and the transition targets.\n// Anything else is almost certainly a typo or an FSM that forgot to declare the\n// state; either way the author should see it before boot.\n//\n// Advisory (warning): a curated value the FSM does not know about is suspicious\n// but not necessarily wrong. Located fix-it, not a hard `os compile` gate —\n// symmetric with the replay-safety rule (framework#3434).\n\nexport type SeedStateMachineSeverity = 'warning';\n\nexport interface SeedStateMachineFinding {\n severity: SeedStateMachineSeverity;\n rule: string;\n /** Human-readable location, e.g. `seed \"showcase_project\" (\"Legacy Sunset\")`. */\n where: string;\n /** Config path, e.g. `data[4].records[3].status`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const SEED_VALUE_OUTSIDE_STATE_MACHINE = 'seed-value-outside-state-machine';\n\ntype AnyRec = Record<string, unknown>;\n\ninterface FsmRule {\n field: string;\n /** Every state the machine declares: initialStates ∪ transition keys ∪ targets. */\n states: Set<string>;\n}\n\n/**\n * Collect the `state_machine` rules (field + full declared-state set) for every\n * object, keyed by object name. An object with no such rule contributes nothing.\n * The declared-state set is derived from the rule alone so the check does not\n * depend on the field's `options` shape (and so it covers free-text state\n * fields the enum validator never sees).\n */\nfunction fsmRulesByObject(objects: AnyRec[]): Map<string, FsmRule[]> {\n const map = new Map<string, FsmRule[]>();\n for (const obj of objects) {\n if (!obj || typeof obj !== 'object') continue;\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const validations = Array.isArray(obj.validations) ? (obj.validations as AnyRec[]) : [];\n const rules: FsmRule[] = [];\n for (const v of validations) {\n if (!v || typeof v !== 'object' || v.type !== 'state_machine') continue;\n const field = typeof v.field === 'string' ? v.field : undefined;\n if (!field) continue;\n const transitions =\n v.transitions && typeof v.transitions === 'object' ? (v.transitions as Record<string, unknown>) : {};\n const states = new Set<string>();\n for (const s of Array.isArray(v.initialStates) ? v.initialStates : []) states.add(String(s));\n for (const from of Object.keys(transitions)) {\n states.add(String(from));\n const targets = transitions[from];\n for (const to of Array.isArray(targets) ? targets : []) states.add(String(to));\n }\n // A state_machine with neither transitions nor initialStates declares no\n // states — nothing to check against, so skip it (never flag every value).\n if (states.size > 0) rules.push({ field, states });\n }\n if (rules.length > 0) map.set(name, rules);\n }\n return map;\n}\n\n/** Best-effort label for a seed record — its externalId value(s), else its index. */\nfunction recordLabel(record: AnyRec, externalId: unknown, index: number): string {\n const keys = Array.isArray(externalId)\n ? (externalId as unknown[]).map(String)\n : typeof externalId === 'string'\n ? [externalId]\n : ['name'];\n const parts = keys.map((k) => record[k]).filter((v) => v != null && v !== '');\n return parts.length > 0 ? parts.map(String).join(' · ') : `#${index}`;\n}\n\n/**\n * Flag every seed record whose `state_machine`-governed field carries a value\n * the machine does not declare (framework#3433 follow-up). Returns the findings\n * (empty = clean). The caller decides how to surface them; the CLI folds them in\n * as advisory warnings.\n *\n * Reads `stack.objects` (for the state-machine rules) and `stack.data` (the\n * `SeedSchema[]` fixtures). Safe on any shape — a stack with no objects or no\n * `data` array yields no findings. A value that is not a plain string (an\n * unresolved `cel` Expression envelope, a number) is skipped: it cannot be\n * statically compared to the declared-state set.\n */\nexport function validateSeedStateMachine(stack: AnyRec): SeedStateMachineFinding[] {\n const out: SeedStateMachineFinding[] = [];\n const objects = Array.isArray(stack.objects) ? (stack.objects as AnyRec[]) : [];\n const seeds = Array.isArray(stack.data) ? (stack.data as AnyRec[]) : [];\n if (objects.length === 0 || seeds.length === 0) return out;\n\n const rulesByObject = fsmRulesByObject(objects);\n if (rulesByObject.size === 0) return out;\n\n seeds.forEach((seed, i) => {\n if (!seed || typeof seed !== 'object') return;\n const objectName = typeof seed.object === 'string' ? seed.object : undefined;\n if (!objectName) return;\n const rules = rulesByObject.get(objectName);\n if (!rules) return;\n const records = Array.isArray(seed.records) ? (seed.records as AnyRec[]) : [];\n\n records.forEach((record, j) => {\n if (!record || typeof record !== 'object') return;\n for (const rule of rules) {\n const value = record[rule.field];\n // Absent / cleared → nothing to check. A non-string (Expression\n // envelope, number) can't be compared statically → skip.\n if (value == null || value === '') continue;\n if (typeof value !== 'string') continue;\n if (rule.states.has(value)) continue;\n\n out.push({\n severity: 'warning',\n rule: SEED_VALUE_OUTSIDE_STATE_MACHINE,\n where: `seed \"${objectName}\" (${recordLabel(record, seed.externalId, j)})`,\n path: `data[${i}].records[${j}].${rule.field}`,\n message:\n `seeds '${rule.field}=${value}', which the '${objectName}' state machine does not declare ` +\n `(known states: ${[...rule.states].sort().join(', ')}). Seed writes are exempt from the ` +\n 'state_machine rule (#3433), so this is NOT rejected at write time — a typo lands silently.',\n hint:\n `If '${value}' is a real state, add it to the state machine (as an initial state or a ` +\n `transition endpoint). If it is a typo, correct it to a declared state. The exemption lets ` +\n 'a seed be born mid-lifecycle; it is not a licence to write an unknown state.',\n });\n }\n });\n });\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0090 D7] Security-domain publish linter.\n *\n * Every rule here is traceable to an observed failure class (the taxonomy\n * grows by incident, per the ADR):\n *\n * | Rule | Origin |\n * |-----------------------------------------|---------------------------------|\n * | security-owd-unset (error) | objectui#2348 leave_request 事故 |\n * | security-owd-alias (error) | ADR-0090 D4 canonical enum |\n * | security-external-wider (error) | ADR-0090 D11 external ≤ internal|\n * | security-wildcard-vama (error) | ADR-0066 superuser wildcard |\n * | security-anchor-high-privilege(error) | ADR-0090 D5/D9 anchors |\n * | security-role-word (error) | ADR-0090 D3 vocabulary freeze |\n * | security-book-audience-unknown-set(warn)| ADR-0046 §6.7 { permissionSet } |\n * | security-private-no-readscope (info) | admin-intent mismatch class |\n * | security-master-detail-ungranted(warn) | framework#2700 os-tianshun-mtc#43|\n * | security-grant-expired-at-authoring(err)| ADR-0091 D2 resolution filtering|\n * | security-delegation-missing-reason(err) | ADR-0091 D3 dual audit |\n *\n * Per ADR-0049 discipline these are NOT advisory security: every `error` rule\n * mirrors a runtime enforcement point (D1 fail-closed OWD default, D4 zod\n * enum + fail-closed evaluator, D5/D9 anchor binding gate, D3 rename wave) —\n * the lint moves the failure from runtime-deny to author-time fix-it. The lone\n * `warning` (master-detail-ungranted) likewise mirrors a runtime gate — the\n * object-level CRUD check (ADR-0055) — but stays advisory: it flags a *likely*\n * misconfiguration whose per-permission-set nuance it cannot fully adjudicate.\n *\n * Pure `(stack) => Finding[]`; accepts the NORMALIZED stack input (works both\n * pre- and post-zod-parse, so `os lint` catches what the zod gate would\n * reject in `os compile` — with a better message).\n */\n\nimport { describeAnchorForbiddenBits } from '@objectstack/spec/security';\n\nexport const SECURITY_OWD_UNSET = 'security-owd-unset';\nexport const SECURITY_OWD_ALIAS = 'security-owd-alias';\nexport const SECURITY_EXTERNAL_WIDER = 'security-external-wider-than-internal';\nexport const SECURITY_WILDCARD_VAMA = 'security-wildcard-vama';\nexport const SECURITY_ANCHOR_HIGH_PRIVILEGE = 'security-anchor-high-privilege';\nexport const SECURITY_ROLE_WORD = 'security-role-word';\nexport const SECURITY_BOOK_AUDIENCE_UNKNOWN_SET = 'security-book-audience-unknown-set';\nexport const SECURITY_PRIVATE_NO_READSCOPE = 'security-private-no-readscope';\nexport const SECURITY_MASTER_DETAIL_UNGRANTED = 'security-master-detail-ungranted';\nexport const SECURITY_FLS_UNQUALIFIED_KEY = 'security-fls-unqualified-key';\nexport const SECURITY_GRANT_EXPIRED_AT_AUTHORING = 'security-grant-expired-at-authoring';\nexport const SECURITY_DELEGATION_MISSING_REASON = 'security-delegation-missing-reason';\n\nexport type SecuritySeverity = 'error' | 'warning' | 'info';\n\nexport interface SecurityFinding {\n severity: SecuritySeverity;\n /** Diagnostic rule id (`security-*`). */\n rule: string;\n /** Human-readable location, e.g. `object \"leave_request\"`. */\n where: string;\n /** Config path, e.g. `objects[3].sharingModel`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nconst CANONICAL_OWD = ['private', 'public_read', 'public_read_write', 'controlled_by_parent'] as const;\n/** [ADR-0090 D4] Legacy alias → canonical fix-it mapping. */\nconst OWD_ALIAS_FIX: Record<string, string> = {\n read: 'public_read',\n read_write: 'public_read_write',\n full: 'public_read_write',\n public: 'public_read_write',\n};\n/** D11 ordering for external ≤ internal (controlled_by_parent excluded). */\nconst OWD_WIDTH: Record<string, number> = {\n private: 0,\n public_read: 1,\n public_read_write: 2,\n};\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction owdOf(obj: AnyRec): unknown {\n return obj.sharingModel ?? (obj.security as AnyRec | undefined)?.sharingModel;\n}\n\nfunction isSystemObject(obj: AnyRec): boolean {\n return obj.isSystem === true || String(obj.name ?? '').startsWith('sys_');\n}\n\n/** snake_case identifier contains the reserved token `role`/`roles`. */\nfunction identifierHasRoleToken(name: unknown): boolean {\n if (typeof name !== 'string') return false;\n return name\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .some((tok) => tok === 'role' || tok === 'roles');\n}\n\n/** Free-text label contains the whole word `role(s)` (case-insensitive). */\nfunction labelHasRoleWord(label: unknown): boolean {\n if (typeof label !== 'string') return false;\n return /\\brole(s)?\\b/i.test(label);\n}\n\n/** The `reference`/`reference_to` target a relationship field points at. */\nfunction refOf(def: AnyRec): string | undefined {\n const r = (def.reference ?? def.reference_to) as unknown;\n return typeof r === 'string' && r ? r : undefined;\n}\n\n/**\n * The first `master_detail` field on an object, if any — its presence is what\n * makes the object a DETAIL (the child side of a master-detail; ADR-0055).\n * Works for both the array and name-keyed-map field forms (`asArray` folds the\n * map key into `name`).\n */\nfunction firstMasterDetailField(obj: AnyRec): { name: string; parent?: string } | undefined {\n for (const f of asArray(obj.fields)) {\n if (f.type === 'master_detail') {\n return { name: String(f.name ?? '?'), parent: refOf(f) };\n }\n }\n return undefined;\n}\n\n/**\n * Does a per-object permission entry open the object-level CRUD gate at all?\n * Any of the four CRUD bits, or a super-user bypass (View/Modify All Data),\n * counts — this mirrors the runtime `checkObjectPermission` gate (ADR-0066 D2):\n * that gate returns true if ANY set contributes one of these for the object.\n */\nfunction grantsObjectAccess(p: AnyRec): boolean {\n return (\n p.allowRead === true ||\n p.allowCreate === true ||\n p.allowEdit === true ||\n p.allowDelete === true ||\n p.viewAllRecords === true ||\n p.modifyAllRecords === true\n );\n}\n\n/**\n * Validate the security posture of a stack. Returns findings (empty = clean).\n * `error` findings gate the build in `os compile`; `info` is advisory.\n *\n * `opts.nowMs` injects the clock for the ADR-0091 authoring-time expiry rule\n * (tests); production callers omit it.\n */\nexport function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number }): SecurityFinding[] {\n const findings: SecurityFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const objects = asArray(stack.objects);\n const permissionSets = asArray(stack.permissions);\n\n // ── D1/D4/D11: per-object OWD posture ────────────────────────────────\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object') continue;\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n const objPath = `objects[${i}]`;\n const owd = owdOf(obj);\n const external = obj.externalSharingModel;\n\n if (!isSystemObject(obj)) {\n if (owd == null) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_UNSET,\n where: `object \"${objName}\"`,\n path: `${objPath}.sharingModel`,\n message:\n `custom object \"${objName}\" declares no sharingModel (OWD). The runtime fails ` +\n `CLOSED to 'private' (ADR-0090 D1), but the baseline must be an authored decision, ` +\n `not an accident — this is the exact shape of the leave_request incident (objectui#2348).`,\n hint:\n `Declare sharingModel explicitly: 'private' (owner + shares; recommended default), ` +\n `'public_read', 'public_read_write', or 'controlled_by_parent' (master-detail children).`,\n });\n } else if (typeof owd === 'string' && OWD_ALIAS_FIX[owd]) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_ALIAS,\n where: `object \"${objName}\"`,\n path: `${objPath}.sharingModel`,\n message:\n `sharingModel '${owd}' is a retired alias (ADR-0090 D4). The runtime fails CLOSED ` +\n `to 'private' on unknown values, so this object is NOT ${owd === 'read' ? 'readable' : 'writable'} org-wide.`,\n hint: `Replace with the canonical value: sharingModel: '${OWD_ALIAS_FIX[owd]}'.`,\n });\n } else if (typeof owd === 'string' && !(CANONICAL_OWD as readonly string[]).includes(owd)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_ALIAS,\n where: `object \"${objName}\"`,\n path: `${objPath}.sharingModel`,\n message:\n `sharingModel '${owd}' is not a canonical OWD value; the runtime fails CLOSED to 'private'.`,\n hint: `Use one of: ${CANONICAL_OWD.join(', ')}.`,\n });\n }\n }\n\n // D11: external dial present on any object (system included) must obey\n // external ≤ internal. controlled_by_parent inherits the master's pair.\n if (typeof external === 'string') {\n if (OWD_ALIAS_FIX[external]) {\n findings.push({\n severity: 'error',\n rule: SECURITY_OWD_ALIAS,\n where: `object \"${objName}\"`,\n path: `${objPath}.externalSharingModel`,\n message: `externalSharingModel '${external}' is a retired alias (ADR-0090 D4).`,\n hint: `Replace with the canonical value: externalSharingModel: '${OWD_ALIAS_FIX[external]}'.`,\n });\n } else if (\n typeof owd === 'string' &&\n external in OWD_WIDTH &&\n owd in OWD_WIDTH &&\n OWD_WIDTH[external] > OWD_WIDTH[owd]\n ) {\n findings.push({\n severity: 'error',\n rule: SECURITY_EXTERNAL_WIDER,\n where: `object \"${objName}\"`,\n path: `${objPath}.externalSharingModel`,\n message:\n `externalSharingModel '${external}' is WIDER than the internal sharingModel '${owd}' — ` +\n `the external baseline must never exceed the internal one (ADR-0090 D11).`,\n hint: `Narrow externalSharingModel to '${owd}' or below (ordering: private < public_read < public_read_write).`,\n });\n }\n }\n }\n\n // ── ADR-0066 / D5/D9: permission-set posture ─────────────────────────\n for (let i = 0; i < permissionSets.length; i++) {\n const ps = permissionSets[i];\n if (!ps || typeof ps !== 'object') continue;\n const psName = typeof ps.name === 'string' ? ps.name : `(permission set ${i})`;\n const psPath = `permissions[${i}]`;\n const objectsMap = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n\n // [#19 / permission zoo audit] FLS keys MUST be `<object>.<field>`\n // qualified. The runtime evaluator matches keys by object prefix\n // (`getFieldPermissions`: `key.startsWith(objectName + '.')`), so a bare\n // `budget` key matches NOTHING — the declared masking silently never\n // enforces (the worst declared-≠-enforced class, ADR-0049). The showcase\n // itself shipped this bug for months.\n const flsMap = (ps.fields && typeof ps.fields === 'object' ? ps.fields : {}) as AnyRec;\n for (const flsKey of Object.keys(flsMap)) {\n if (flsKey.includes('.')) continue;\n findings.push({\n severity: 'error',\n rule: SECURITY_FLS_UNQUALIFIED_KEY,\n where: `permission set \"${psName}\"`,\n path: `${psPath}.fields[\"${flsKey}\"]`,\n message:\n `field-permission key '${flsKey}' is not object-qualified — the runtime matches FLS keys ` +\n `by '<object>.<field>' prefix, so a bare key is silently IGNORED and the declared masking never enforces.`,\n hint: `Qualify the key with its object, e.g. 'crm_opportunity.${flsKey}': { readable: true, editable: false }.`,\n });\n }\n\n const wildcard = objectsMap['*'] as AnyRec | undefined;\n if (wildcard && (wildcard.viewAllRecords === true || wildcard.modifyAllRecords === true)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_WILDCARD_VAMA,\n where: `permission set \"${psName}\"`,\n path: `${psPath}.objects.*`,\n message:\n `'*' wildcard carrying View All / Modify All Data — a package-authored superuser. ` +\n `Only the platform's own admin set may combine the wildcard with VAMA (ADR-0066).`,\n hint:\n `Enumerate the objects this set really needs, or drop viewAllRecords/modifyAllRecords ` +\n `from the wildcard entry. App-level admins belong in an ordinary set the customer binds ` +\n `to a position of their choosing (ADR-0090 D9).`,\n });\n }\n\n // D5: an isDefault set is a SUGGESTED binding to the `everyone` anchor —\n // hold it to the anchor tier at author time (the runtime gate enforces the\n // same predicate at bind time; this moves the failure to the author).\n if (ps.isDefault === true) {\n const offending = describeAnchorForbiddenBits(ps, 'everyone');\n if (offending) {\n findings.push({\n severity: 'error',\n rule: SECURITY_ANCHOR_HIGH_PRIVILEGE,\n where: `permission set \"${psName}\"`,\n path: `${psPath}.isDefault`,\n message:\n `isDefault:true suggests binding this set to the 'everyone' audience anchor, but it ` +\n `carries ${offending} — the runtime will refuse the binding (ADR-0090 D5/D9).`,\n hint:\n `Split the powerful bits into a separate set granted through ordinary positions, and ` +\n `keep the everyone-suggested set low-privilege.`,\n });\n }\n }\n }\n\n // ── D3: the word \"role\" is reserved-forbidden ────────────────────────\n // Scope: security-relevant identifiers/labels (objects, fields, actions,\n // permission sets, positions, apps). Pages/views/components are NOT\n // scanned — `role` there is HTML/ARIA semantics, not permission vocabulary.\n // The sole platform exception (better-auth `sys_member.role`) is a system\n // object, which app stacks never author.\n const flagRole = (kind: string, name: unknown, label: unknown, where: string, path: string) => {\n if (identifierHasRoleToken(name)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_ROLE_WORD,\n where,\n path,\n message:\n `${kind} name \"${String(name)}\" uses the reserved word \"role\" — the platform vocabulary ` +\n `is permission_set (capability), position (distribution), business_unit (hierarchy) (ADR-0090 D3).`,\n hint: `Rename using 'position' for distribution groups or a domain word (e.g. 'function', 'duty').`,\n });\n } else if (labelHasRoleWord(label)) {\n findings.push({\n severity: 'error',\n rule: SECURITY_ROLE_WORD,\n where,\n path: `${path.replace(/\\.name$/, '')}.label`,\n message: `${kind} label \"${String(label)}\" uses the reserved word \"role\" (ADR-0090 D3).`,\n hint: `Relabel with 'Position' (distribution) or a domain word — admins must meet ONE vocabulary.`,\n });\n }\n };\n\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object' || isSystemObject(obj)) continue;\n const objName = typeof obj.name === 'string' ? obj.name : `(object ${i})`;\n flagRole('object', obj.name, obj.label, `object \"${objName}\"`, `objects[${i}].name`);\n for (const f of asArray(obj.fields)) {\n flagRole('field', f.name, f.label, `field \"${objName}.${String(f.name ?? '?')}\"`, `objects[${i}].fields.${String(f.name ?? '?')}.name`);\n }\n for (const [ai, action] of asArray(obj.actions).entries()) {\n flagRole('action', action.name, action.label, `action \"${objName}.${String(action.name ?? '?')}\"`, `objects[${i}].actions[${ai}].name`);\n }\n }\n for (let i = 0; i < permissionSets.length; i++) {\n const ps = permissionSets[i];\n if (!ps || typeof ps !== 'object') continue;\n flagRole('permission set', ps.name, ps.label, `permission set \"${String(ps.name ?? i)}\"`, `permissions[${i}].name`);\n }\n for (const [i, pos] of asArray(stack.positions).entries()) {\n flagRole('position', pos.name, pos.label, `position \"${String(pos.name ?? i)}\"`, `positions[${i}].name`);\n }\n for (const [i, app] of asArray(stack.apps).entries()) {\n flagRole('app', app.name, app.label, `app \"${String(app.name ?? i)}\"`, `apps[${i}].name`);\n }\n for (const [i, book] of asArray(stack.books).entries()) {\n // Books entered the security-relevant set when `book.audience` became a\n // permission-model reference (ADR-0046 §6.7 / ADR-0090): their names and\n // labels are access-adjacent UI copy.\n flagRole('book', book.name, book.label, `book \"${String(book.name ?? i)}\"`, `books[${i}].name`);\n }\n\n // ── Book audience → permission-set reference must resolve ────────────\n // A `{ permissionSet }` book audience names a set the reader must hold\n // (ADR-0046 §6.7). The runtime fails CLOSED on an unknown name (nobody\n // holds it → nobody reads the book), so a typo is not a leak — but it IS\n // the \"why can nobody see the Admin Guide\" support class, and packages\n // should gate their books on their own sets (ADR-0090 D9 / ADR-0086\n // provenance). Advisory: an environment-authored book may legitimately\n // reference an installed package's set that is not in THIS stack.\n const stackSetNames = new Set(\n permissionSets\n .map((ps) => (typeof ps.name === 'string' ? ps.name : undefined))\n .filter((n): n is string => !!n),\n );\n for (const [i, book] of asArray(stack.books).entries()) {\n const audience = (book as AnyRec).audience;\n if (!audience || typeof audience !== 'object') continue;\n const setName = (audience as AnyRec).permissionSet;\n if (typeof setName !== 'string' || setName.length === 0) continue;\n if (!stackSetNames.has(setName)) {\n findings.push({\n severity: 'warning',\n rule: SECURITY_BOOK_AUDIENCE_UNKNOWN_SET,\n where: `book \"${String(book.name ?? i)}\"`,\n path: `books[${i}].audience.permissionSet`,\n message:\n `book audience references permission set \"${setName}\", which this stack does not declare. ` +\n `The runtime fails closed — no holder means NO reader can open the book.`,\n hint:\n `Gate the book on one of this package's own permission sets (ADR-0090 D9, e.g. its admin set), ` +\n `or fix the typo. Ignore if the set is intentionally provided by another installed package.`,\n });\n }\n }\n\n // ── Admin-intent mismatch: private object, plain read, no depth ──────\n // An object whose baseline is private (explicit or D1-defaulted) where a set\n // grants allowRead with neither readScope nor viewAllRecords: every reader\n // sees ONLY their own records. Legitimate (personal to-dos) often enough\n // that this stays `info` — but it is the #1 \"why can't 李四 see the data\"\n // support class, so say it out loud at author time.\n const privateObjects = new Set(\n objects\n .filter((o) => o && typeof o === 'object' && !isSystemObject(o))\n .filter((o) => {\n const owd = owdOf(o);\n return owd == null || owd === 'private';\n })\n .map((o) => String(o.name ?? '')),\n );\n if (privateObjects.size > 0) {\n for (let i = 0; i < permissionSets.length; i++) {\n const ps = permissionSets[i];\n if (!ps || typeof ps !== 'object') continue;\n const psName = typeof ps.name === 'string' ? ps.name : `(permission set ${i})`;\n const objectsMap = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n for (const [objName, rawPerm] of Object.entries(objectsMap)) {\n if (!privateObjects.has(objName)) continue;\n const p = (rawPerm ?? {}) as AnyRec;\n if (p.allowRead === true && p.readScope == null && p.viewAllRecords !== true) {\n findings.push({\n severity: 'info',\n rule: SECURITY_PRIVATE_NO_READSCOPE,\n where: `permission set \"${psName}\"`,\n path: `permissions[${i}].objects.${objName}.readScope`,\n message:\n `\"${objName}\" is private (OWD) and this set grants allowRead without a readScope — ` +\n `holders see ONLY records they own (plus explicit shares).`,\n hint:\n `If that is intended (personal data), ignore this. Otherwise add readScope: ` +\n `'own_and_reports' | 'unit' | 'unit_and_below' | 'org', or widen the object's sharingModel.`,\n });\n }\n }\n }\n }\n\n // ── ADR-0055: master-detail DETAIL object with no object-level CRUD ───\n // A master-detail CHILD derives its RECORD-level scope from the master\n // (`controlled_by_parent`) — but that is gate ②. Object-level CRUD is a\n // SEPARATE gate ① (`checkObjectPermission`) that is NEVER derived: a set that\n // lists the parent but forgets the child denies role-bound non-admin users a\n // 403 *before* the parent-derived access is ever consulted, surfacing as the\n // silent \"can't fill in / can't submit the subtable\" trap (framework#2700,\n // downstream os-tianshun-mtc#43). Statically detectable: a detail (has a\n // master_detail field) that NO authored permission set grants.\n //\n // Advisory `warning` — it does not gate the build. Two deliberate silences\n // keep the false-positive rate near zero: (a) if the package authors no\n // permission sets there is nothing to compare against, and (b) a package-\n // declared `'*'` wildcard grant is treated as covering every object (a broad\n // grant is an explicit choice — suppress rather than cry wolf). The residual\n // per-set gap (one role grants it, another forgets it) is intentionally out\n // of scope (issue #2700); the platform's own default admin set lives outside\n // the linted stack, so it never masks a package that forgot the child here.\n if (permissionSets.length > 0) {\n const wildcardGrantsAll = permissionSets.some((ps) =>\n grantsObjectAccess(((ps.objects as AnyRec | undefined)?.['*'] ?? {}) as AnyRec),\n );\n if (!wildcardGrantsAll) {\n const grantedObjects = new Set<string>();\n for (const ps of permissionSets) {\n const objectsMap = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n for (const [objName, rawPerm] of Object.entries(objectsMap)) {\n if (objName === '*') continue;\n if (grantsObjectAccess((rawPerm ?? {}) as AnyRec)) grantedObjects.add(objName);\n }\n }\n for (let i = 0; i < objects.length; i++) {\n const obj = objects[i];\n if (!obj || typeof obj !== 'object' || isSystemObject(obj)) continue;\n const objName = typeof obj.name === 'string' ? obj.name : '';\n if (!objName || grantedObjects.has(objName)) continue;\n const md = firstMasterDetailField(obj);\n if (!md) continue;\n const parentText = md.parent ? ` → \"${md.parent}\"` : '';\n findings.push({\n severity: 'warning',\n rule: SECURITY_MASTER_DETAIL_UNGRANTED,\n where: `object \"${objName}\"`,\n path: `objects[${i}].fields.${md.name}`,\n message:\n `detail object \"${objName}\" (master_detail \"${md.name}\"${parentText}) has no object-level ` +\n `CRUD grant in any permission set. A master-detail child derives its RECORD-level access ` +\n `from the master (ADR-0055 controlled_by_parent), but object-level CRUD is a SEPARATE gate ` +\n `that is never derived — role-bound non-admin users are denied (403) before the ` +\n `parent-derived access is ever consulted (the silent \"can't submit the subtable\" trap).`,\n hint:\n `Grant \"${objName}\" in at least one permission set that already grants its master` +\n `${md.parent ? ` \"${md.parent}\"` : ''} — e.g. permissions[i].objects.${objName} = ` +\n `{ allowRead: true, allowCreate: true, allowEdit: true }. If no role should ever touch ` +\n `it (a pure system/internal table), name it sys_* or set isSystem: true.`,\n });\n }\n }\n }\n\n // ── ADR-0091: authored grant rows (seed data) — lifecycle sanity ──────\n // Grant assignments authored as seed data on the two user-grant tables.\n // Both rules mirror runtime enforcement (D2 resolution-time filtering; the\n // D3 delegation gate), per the ADR-0049 \"no advisory security\" discipline:\n // the lint moves the failure from silent-dead-grant to author-time fix-it.\n const GRANT_SEED_OBJECTS = new Set(['sys_user_position', 'sys_user_permission_set']);\n const nowMs = opts?.nowMs ?? Date.now();\n for (const [i, seed] of asArray(stack.data).entries()) {\n const seedObject = typeof seed.object === 'string' ? seed.object : '';\n if (!GRANT_SEED_OBJECTS.has(seedObject)) continue;\n const records = Array.isArray(seed.records) ? (seed.records as AnyRec[]) : [];\n for (let j = 0; j < records.length; j++) {\n const rec = (records[j] ?? {}) as AnyRec;\n const where = `seed \"${seedObject}\" record #${j}`;\n\n // D2: a valid_until already in the past (or unparseable) at authoring\n // time is a grant that will NEVER resolve — dead on arrival, fail-closed.\n const until = rec.valid_until;\n if (until != null && until !== '') {\n const ms =\n typeof until === 'number'\n ? (until < 1e12 ? until * 1000 : until)\n : until instanceof Date\n ? until.getTime()\n : typeof until === 'string'\n ? Date.parse(until)\n : Number.NaN;\n if (Number.isNaN(ms) || ms <= nowMs) {\n findings.push({\n severity: 'error',\n rule: SECURITY_GRANT_EXPIRED_AT_AUTHORING,\n where,\n path: `data[${i}].records[${j}].valid_until`,\n message: Number.isNaN(ms)\n ? `valid_until ${JSON.stringify(until)} is not a parseable timestamp — the resolver fails ` +\n `closed (ADR-0091 D2), so this grant will NEVER be active.`\n : `valid_until ${JSON.stringify(until)} is already in the past — this grant is expired at ` +\n `authoring time and will never resolve (ADR-0091 D2 filters it fail-closed).`,\n hint:\n `Set valid_until to a future instant (ISO-8601 UTC), or drop the column for an unbounded ` +\n `grant. If the row is a historical record, it belongs in audit history, not seed data.`,\n });\n }\n }\n\n // D3: delegation rows (delegated_from set) MUST carry a reason — the\n // dual-audit half the runtime gate also rejects.\n const delegatedFrom = rec.delegated_from;\n if (delegatedFrom != null && delegatedFrom !== '') {\n const reason = rec.reason;\n if (typeof reason !== 'string' || reason.trim().length === 0) {\n findings.push({\n severity: 'error',\n rule: SECURITY_DELEGATION_MISSING_REASON,\n where,\n path: `data[${i}].records[${j}].reason`,\n message:\n `delegation row (delegated_from = ${JSON.stringify(delegatedFrom)}) has no reason. ` +\n `ADR-0091 D3 requires a mandatory reason on every delegation for the dual audit trail ` +\n `(granted_by = writer, delegated_from = authority source, reason = why).`,\n hint: `Add reason: 'vacation stand-in for 张三, 2026-08-01..15' (free text, required).`,\n });\n }\n }\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0105 D6] The two organization-axis red lines, enforced at authoring time.\n *\n * ADR-0105 gives organizations a reporting/grouping dimension\n * (`sys_organization.parent_organization_id`, sibling ordering). That dimension\n * is load-bearing for consolidated reporting — and dangerous, because it LOOKS\n * like a permission hierarchy. Two lines keep it from becoming one:\n *\n * | Rule | Red line |\n * |-----------------------------------------|-----------------------------------|\n * | org-axis-permission-inheritance (error) | D6 ①: no inheritance along the org tree |\n * | org-axis-cross-org-bu-grant (error) | D6 ②: business-unit trees stay org-internal |\n *\n * **① No permission inheritance along the org axis.** Cross-organization\n * visibility comes from membership union (`accessible_org_ids`, ADR-0105 D2) —\n * the engine's own Layer 0 wall — never from walking a parent reference. An RLS\n * policy or sharing rule that reads `parent_organization_id` builds a SECOND\n * permission hierarchy beside the business-unit tree: exactly the dual-hierarchy\n * mistake ADR-0057 D5 retired and ADR-0090 D3 finalized for positions. It also\n * silently outranks the wall it sits behind, since a Layer-1 policy cannot widen\n * Layer 0 (W1) — so the author gets a rule that appears to grant access and\n * does not. Fail at authoring, not in a support ticket.\n *\n * **② Business-unit trees remain org-internal.** `sys_business_unit` is\n * org-scoped and every BU mechanism (`unit_and_subordinates` sharing,\n * `adminScope` delegation, depth scopes) resolves within ONE organization. A\n * business-unit sharing rule on a PLATFORM-GLOBAL object (`tenancy.enabled:\n * false`) has no organization column to scope against, so the grant spans every\n * organization in the database — a cross-org BU grant by construction, and the\n * \"cross-org BU mega-tree\" the ADR rejected, arrived at by accident.\n *\n * Both are `error`, per ADR-0049 discipline: each mirrors a real enforcement\n * property (the Layer 0 wall's independence; the org-predicated BU resolver),\n * so the lint moves the failure from silent-wrong-answer to author-time fix-it.\n *\n * Pure `(stack) => Finding[]`; accepts the NORMALIZED stack input.\n */\n\nexport const ORG_AXIS_PERMISSION_INHERITANCE = 'org-axis-permission-inheritance';\nexport const ORG_AXIS_CROSS_ORG_BU_GRANT = 'org-axis-cross-org-bu-grant';\n\nexport type OrgAxisSeverity = 'error' | 'warning';\n\nexport interface OrgAxisFinding {\n severity: OrgAxisSeverity;\n /** Diagnostic rule id (`org-axis-*`). */\n rule: string;\n /** Human-readable location, e.g. `permission set \"plant_reader\"`. */\n where: string;\n /** Config path, e.g. `permissions[2].rowLevelSecurity[0].using`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** The org-axis grouping reference. Reporting only — never an authorization input. */\nconst ORG_PARENT_FIELD = 'parent_organization_id';\n\n/** Coerce a collection (array or name-keyed map) to an array of records. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction str(v: unknown): string {\n return typeof v === 'string' ? v : '';\n}\n\n/** True iff the object opted out of tenancy — platform-global, no org column. */\nfunction isTenancyDisabled(object: AnyRec): boolean {\n const tenancy = object.tenancy as AnyRec | undefined;\n if (tenancy && typeof tenancy === 'object' && tenancy.enabled === false) return true;\n const systemFields = object.systemFields as AnyRec | undefined;\n if (systemFields && typeof systemFields === 'object' && systemFields.tenant === false) return true;\n return false;\n}\n\nconst INHERITANCE_HINT =\n `Remove the ${ORG_PARENT_FIELD} reference. Cross-organization visibility comes from MEMBERSHIP: ` +\n `under the \\`group\\` tenancy posture the engine's Layer 0 wall is ` +\n `\\`organization_id IN accessible_org_ids\\`, so a user who should see several organizations is made ` +\n `a member of them (ADR-0105 D2). A Layer-1 policy cannot widen Layer 0 anyway, so this rule would ` +\n `not grant the access it appears to. For a hierarchy INSIDE one organization, use the business-unit ` +\n `tree (\\`unit_and_subordinates\\` sharing, or a depth scope anchored on \\`sys_user_position\\`).`;\n\n/**\n * Lint an ObjectStack config for the ADR-0105 D6 organization-axis red lines.\n */\nexport function validateOrgAxisRedLines(stack: unknown): OrgAxisFinding[] {\n const findings: OrgAxisFinding[] = [];\n const cfg = (stack ?? {}) as AnyRec;\n\n // ── ① No permission inheritance along the org axis ────────────────────────\n //\n // RLS policies may live on a permission set (`rowLevelSecurity`) or be\n // authored per object; both reach the same compiler, so both are checked.\n const permissionSets = asArray(cfg.permissions ?? cfg.permissionSets);\n permissionSets.forEach((ps, psIndex) => {\n asArray(ps.rowLevelSecurity).forEach((policy, pIndex) => {\n for (const clause of ['using', 'check'] as const) {\n if (!str(policy[clause]).includes(ORG_PARENT_FIELD)) continue;\n findings.push({\n severity: 'error',\n rule: ORG_AXIS_PERMISSION_INHERITANCE,\n where: `permission set \"${str(ps.name) || psIndex}\" policy \"${str(policy.name) || pIndex}\"`,\n path: `permissions[${psIndex}].rowLevelSecurity[${pIndex}].${clause}`,\n message:\n `RLS ${clause} reads \\`${ORG_PARENT_FIELD}\\`, which builds a permission hierarchy along the ` +\n `organization axis. ADR-0105 D6 forbids it: the org tree is a REPORTING dimension only.`,\n hint: INHERITANCE_HINT,\n });\n }\n });\n });\n\n const objects = asArray(cfg.objects);\n objects.forEach((object, oIndex) => {\n const objectName = str(object.name) || String(oIndex);\n\n asArray(object.rowLevelSecurity ?? object.rls).forEach((policy, pIndex) => {\n for (const clause of ['using', 'check'] as const) {\n if (!str(policy[clause]).includes(ORG_PARENT_FIELD)) continue;\n findings.push({\n severity: 'error',\n rule: ORG_AXIS_PERMISSION_INHERITANCE,\n where: `object \"${objectName}\" policy \"${str(policy.name) || pIndex}\"`,\n path: `objects[${oIndex}].rowLevelSecurity[${pIndex}].${clause}`,\n message:\n `RLS ${clause} reads \\`${ORG_PARENT_FIELD}\\`, which builds a permission hierarchy along the ` +\n `organization axis. ADR-0105 D6 forbids it: the org tree is a REPORTING dimension only.`,\n hint: INHERITANCE_HINT,\n });\n }\n });\n });\n\n // Sharing rules — criteria and recipient may both reach for the org parent.\n asArray(cfg.sharingRules ?? cfg.sharing).forEach((rule, rIndex) => {\n const criteria = JSON.stringify(rule.criteria ?? rule.filter ?? '');\n const sharedTo = JSON.stringify(rule.sharedTo ?? rule.recipient ?? '');\n if (criteria.includes(ORG_PARENT_FIELD) || sharedTo.includes(ORG_PARENT_FIELD)) {\n findings.push({\n severity: 'error',\n rule: ORG_AXIS_PERMISSION_INHERITANCE,\n where: `sharing rule \"${str(rule.name) || rIndex}\"`,\n path: `sharingRules[${rIndex}]`,\n message:\n `Sharing rule reads \\`${ORG_PARENT_FIELD}\\`, granting access by walking the organization ` +\n `tree. ADR-0105 D6 forbids permission inheritance along the org axis.`,\n hint: INHERITANCE_HINT,\n });\n }\n });\n\n // ── ② Business-unit trees remain org-internal ─────────────────────────────\n //\n // A `business_unit` recipient on a platform-global object has no organization\n // column to scope against, so the grant reaches every organization's rows.\n const tenancyDisabledObjects = new Set(\n objects.filter((o) => isTenancyDisabled(o)).map((o) => str(o.name)).filter(Boolean),\n );\n asArray(cfg.sharingRules ?? cfg.sharing).forEach((rule, rIndex) => {\n const target = str(rule.object ?? rule.objectName);\n if (!target || !tenancyDisabledObjects.has(target)) return;\n const sharedTo = (rule.sharedTo ?? rule.recipient) as AnyRec | undefined;\n const recipientType = str(sharedTo?.type);\n if (recipientType !== 'business_unit') return;\n findings.push({\n severity: 'error',\n rule: ORG_AXIS_CROSS_ORG_BU_GRANT,\n where: `sharing rule \"${str(rule.name) || rIndex}\" on object \"${target}\"`,\n path: `sharingRules[${rIndex}].sharedTo`,\n message:\n `A business-unit sharing rule targets \"${target}\", which opted out of tenancy ` +\n `(\\`tenancy.enabled: false\\`). Platform-global objects carry no organization column, so this ` +\n `grant spans EVERY organization — a cross-organization business-unit grant, which ADR-0105 D6 ` +\n `forbids (BU trees are org-internal).`,\n hint:\n `Either scope the object to organizations (drop \\`tenancy.enabled: false\\` so Layer 0 walls it), ` +\n `or share it to a position / permission-set audience instead of a business unit. A ` +\n `platform-global catalog that everyone should read wants an OWD of \\`public_read\\`, not a BU grant.`,\n });\n });\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0049 — references] Reference-integrity for dashboard header & widget\n * action targets (issue #3367).\n *\n * ADR-0049 established the \"enforce-or-remove\" gate for spec *properties*: a\n * declared property the runtime does not honour is a false promise and must be\n * enforced, marked experimental, or removed. This rule applies the SAME honesty\n * principle to *references*. A dashboard header action (or a widget's header\n * action button) names a target — a `script`/`modal` action, or a `url` route —\n * that must actually resolve. A dangling target ships a button that renders and,\n * on click, silently does nothing: a false affordance, exactly the failure\n * ADR-0049 exists to prevent, just for a reference rather than a property.\n *\n * Nothing in the protocol schema can express this: `actionUrl` is a free string,\n * so `{ actionType: 'script', actionUrl: 'export_dashboard_pdf' }` parses and\n * ships even when no such action is defined anywhere in the stack.\n *\n * Surfaces checked:\n * - dashboard `header.actions[]` — each `{ actionType, actionUrl }`\n * - dashboard `widgets[].actionUrl` (+ `actionType`) — the per-widget button\n *\n * Resolution mirrors the objectui runtime dispatch (`DashboardRenderer` +\n * `DashboardView`) so the lint flags exactly what would fail to resolve at\n * runtime:\n *\n * actionType 'script' → `actionUrl` must name a DEFINED action (`stack.actions`\n * or any `object.actions`, by `name`). A script target that names no\n * defined action fails open at runtime (\"action not found\"). → ERROR.\n *\n * actionType 'modal' → `actionUrl` resolves if it names a defined action, OR\n * matches the runtime `<verb>_<object>` convention the modalHandler\n * implements (create_/new_/add_/edit_/update_ + a defined object), OR is a\n * bare defined object name (the handler falls back to that object's create\n * form). Otherwise → ERROR.\n *\n * actionType 'url' → a relative in-app path. WARN when a recognizable\n * `<collection>/<name>` segment (objects/reports/dashboards/pages/views)\n * names an entity that does not exist in this stack. External URLs\n * (`http(s)://`, `//`), interpolated targets (`${…}`), and opaque routes\n * (no recognized collection segment) are skipped — they cannot be resolved\n * statically and may be host/app/plugin routes. → WARNING.\n *\n * actionType 'flow' | 'api' — not checked: flow targets resolve against the\n * automation engine / other packages, and api targets are opaque endpoints.\n * Out of scope for #3367.\n *\n * Severity split follows the issue's acceptance criteria: an undefined\n * `script`/`modal` target FAILS validation (a genuine dead reference that fails\n * open at runtime as a dead button); an unresolved `url` route is advisory\n * (route resolution is app-context-dependent, and a path may be served by\n * another installed package or a host/console route). External, interpolated,\n * convention, and opaque targets are exempted to keep false positives near zero\n * — the same conservative posture as the sibling `lint-view-refs` and\n * `validate-capability-references` rules.\n */\n\nexport const DASHBOARD_ACTION_TARGET_UNDEFINED = 'dashboard-action-target-undefined';\nexport const DASHBOARD_ACTION_ROUTE_UNRESOLVED = 'dashboard-action-route-unresolved';\n\nexport type DashboardActionRefSeverity = 'error' | 'warning';\n\nexport interface DashboardActionRefFinding {\n /** `error` for a dangling script/modal action; `warning` for an unresolved url route. */\n severity: DashboardActionRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `dashboard \"sales_overview\" · header action \"Export PDF\"`. */\n where: string;\n /** Config path, e.g. `dashboards[2].header.actions[0].actionUrl`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records, injecting\n * `name` from the map key — mirrors the helper in the sibling authoring lints so\n * the rule works on both the parsed (array) and normalized (map) stack shapes. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/** The runtime modal `<verb>_<object>` convention (objectui `DashboardView`\n * modalHandler): `create_/new_/add_/edit_/update_` + an object name opens that\n * object's create/edit form. */\nconst MODAL_VERB_RE = /^(?:create|new|add|edit|update)_(.+)$/;\n\n/** URL path segments that name a metadata collection, mapped to the stack key\n * whose members can appear after them in an in-app route\n * (`/…/objects/crm_lead`, `/reports/forecast`, `/dashboards/exec`, …). Both the\n * singular and plural spellings are accepted. */\nconst URL_COLLECTION_TO_STACK_KEY: Record<string, 'objects' | 'reports' | 'dashboards' | 'pages' | 'views'> = {\n object: 'objects',\n objects: 'objects',\n report: 'reports',\n reports: 'reports',\n dashboard: 'dashboards',\n dashboards: 'dashboards',\n page: 'pages',\n pages: 'pages',\n view: 'views',\n views: 'views',\n};\n\n/** Derive the name a top-level `views` container registers under (mirrors the\n * runtime loader's `resolveMetadataItemName('views', …)` fallbacks). */\nfunction viewContainerName(item: AnyRec): string | undefined {\n return (\n strName(item.name) ??\n strName(item.id) ??\n strName(item.object) ??\n strName((item.list as AnyRec | undefined)?.data && ((item.list as AnyRec).data as AnyRec).object) ??\n strName((item.form as AnyRec | undefined)?.data && ((item.form as AnyRec).data as AnyRec).object)\n );\n}\n\ninterface KnownTargets {\n /** Every action name defined in the stack (global + object-embedded). */\n actions: Set<string>;\n /** Object names (also valid as bare modal targets and `objects/<name>` routes). */\n objects: Set<string>;\n reports: Set<string>;\n dashboards: Set<string>;\n pages: Set<string>;\n /** View names routable as `views/<name>` — container names plus object names. */\n views: Set<string>;\n}\n\n/** Build the author-time \"known target\" sets from a stack. */\nfunction collectKnownTargets(stack: AnyRec): KnownTargets {\n const actions = new Set<string>();\n const objects = new Set<string>();\n const reports = new Set<string>();\n const dashboards = new Set<string>();\n const pages = new Set<string>();\n const views = new Set<string>();\n\n const collectNames = (v: unknown, into: Set<string>, name: (rec: AnyRec) => string | undefined) => {\n for (const item of asArray(v)) {\n if (!item || typeof item !== 'object') continue;\n const n = name(item);\n if (n) into.add(n);\n }\n };\n\n collectNames(stack.actions, actions, (a) => strName(a.name));\n for (const obj of asArray(stack.objects)) {\n if (!obj || typeof obj !== 'object') continue;\n const n = strName(obj.name);\n if (n) objects.add(n);\n collectNames(obj.actions, actions, (a) => strName(a.name));\n }\n collectNames(stack.reports, reports, (r) => strName(r.name));\n collectNames(stack.dashboards, dashboards, (d) => strName(d.name));\n collectNames(stack.pages, pages, (p) => strName(p.name));\n collectNames(stack.views, views, viewContainerName);\n // An object's default view is routable by the object's own name too.\n for (const o of objects) views.add(o);\n\n return { actions, objects, reports, dashboards, pages, views };\n}\n\n/** Does a `script`/`modal` `actionUrl` resolve? */\nfunction resolveActionTarget(\n actionType: 'script' | 'modal',\n target: string,\n known: KnownTargets,\n): boolean {\n if (known.actions.has(target)) return true;\n if (actionType === 'modal') {\n // Runtime modalHandler convention: `<verb>_<object>` or a bare object name\n // opens that object's create/edit form.\n if (known.objects.has(target)) return true;\n const m = MODAL_VERB_RE.exec(target);\n if (m && known.objects.has(m[1])) return true;\n }\n return false;\n}\n\n/**\n * Resolve a relative `url` in-app route. Returns:\n * - `null` when the target is not statically resolvable (external, interpolated,\n * or carries no recognized `<collection>/<name>` segment) — SKIP, no finding.\n * - `{ collection, name }` for a recognized `<collection>/<name>` pair that does\n * NOT exist in the stack — WARN.\n * - `undefined` when a recognized pair DID resolve — OK, no finding.\n */\nfunction resolveUrlRoute(\n target: string,\n known: KnownTargets,\n): { collection: string; name: string } | null | undefined {\n // External / protocol-relative — leaves the app; not an in-app route.\n if (/^[a-z][a-z0-9+.-]*:\\/\\//i.test(target) || target.startsWith('//')) return null;\n // Interpolated — resolved by the renderer at click time, not statically known.\n if (target.includes('${')) return null;\n // Only relative in-app paths are considered.\n if (!target.startsWith('/')) return null;\n\n // Strip query + hash, then split into non-empty segments.\n const pathPart = target.split(/[?#]/, 1)[0];\n const segments = pathPart.split('/').filter(Boolean);\n\n for (let i = 0; i < segments.length - 1; i++) {\n const stackKey = URL_COLLECTION_TO_STACK_KEY[segments[i]];\n if (!stackKey) continue;\n const name = segments[i + 1];\n if (known[stackKey].has(name)) return undefined; // resolved\n return { collection: segments[i], name }; // recognized shape, unknown name\n }\n return null; // no recognized collection segment — opaque route, skip\n}\n\ninterface HeaderAction {\n actionType?: string;\n actionUrl?: string;\n label?: string;\n}\n\n/**\n * Validate every dashboard header / widget action reference in a stack. Returns\n * findings (empty = clean). `script`/`modal` dead targets are errors; `url`\n * unresolved routes are warnings.\n */\nexport function validateDashboardActionRefs(stack: AnyRec): DashboardActionRefFinding[] {\n const findings: DashboardActionRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const dashboards = asArray(stack.dashboards);\n if (dashboards.length === 0) return findings;\n\n const known = collectKnownTargets(stack);\n\n const checkOne = (\n action: HeaderAction,\n where: string,\n path: string,\n ) => {\n const target = strName(action.actionUrl);\n if (!target) return; // nothing referenced (widget with no action button)\n if (target.includes('${')) return; // dynamic target — not statically resolvable\n\n // Renderer default: a missing actionType is treated as a 'url' navigation\n // (DashboardRenderer builds header ActionDefs with `type: actionType || 'url'`).\n const actionType = strName(action.actionType) ?? 'url';\n\n if (actionType === 'script' || actionType === 'modal') {\n if (resolveActionTarget(actionType, target, known)) return;\n const kindWord = actionType === 'script' ? 'script' : 'modal';\n findings.push({\n severity: 'error',\n rule: DASHBOARD_ACTION_TARGET_UNDEFINED,\n where,\n path,\n message:\n `${kindWord} action target \"${target}\" resolves to no defined action` +\n (actionType === 'modal' ? ' or object' : '') +\n `. The button renders but does nothing when clicked — a dangling reference ` +\n `the runtime cannot dispatch (ADR-0049: a declared reference must resolve).`,\n hint:\n actionType === 'modal'\n ? `Define an action named \"${target}\" (stack.actions or the object's actions), ` +\n `use the \"<verb>_<object>\" convention against a real object ` +\n `(e.g. \"create_<object>\"), point actionUrl at an existing object, or remove the button.`\n : `Define a script action named \"${target}\" (stack.actions or the object's actions) ` +\n `with an inline body or a registered handler, or remove the button.`,\n });\n return;\n }\n\n if (actionType === 'url') {\n const route = resolveUrlRoute(target, known);\n if (!route) return; // skip (external/interpolated/opaque) or resolved\n findings.push({\n severity: 'warning',\n rule: DASHBOARD_ACTION_ROUTE_UNRESOLVED,\n where,\n path,\n message:\n `url action target \"${target}\" points at ${route.collection}/${route.name}, ` +\n `but no ${route.collection.replace(/s$/, '')} named \"${route.name}\" is registered ` +\n `in this stack — the button likely navigates to a dead route.`,\n hint:\n `Check the path for a typo, define the referenced ${route.collection.replace(/s$/, '')}, ` +\n `or ignore this if the route is served by another installed package or a host/console route.`,\n });\n return;\n }\n // 'flow' | 'api' | custom types are out of scope (see module header).\n };\n\n for (let di = 0; di < dashboards.length; di++) {\n const dash = dashboards[di];\n if (!dash || typeof dash !== 'object') continue;\n const dashName = strName(dash.name) ?? `(dashboard ${di})`;\n const dashPath = `dashboards[${di}]`;\n\n // Header actions.\n const headerActions = asArray((dash.header as AnyRec | undefined)?.actions);\n for (let ai = 0; ai < headerActions.length; ai++) {\n const action = headerActions[ai] as HeaderAction | null;\n if (!action || typeof action !== 'object') continue;\n const label = strName(action.label) ?? strName(action.actionUrl) ?? `#${ai}`;\n checkOne(\n action,\n `dashboard \"${dashName}\" · header action \"${label}\"`,\n `${dashPath}.header.actions[${ai}].actionUrl`,\n );\n }\n\n // Per-widget action buttons.\n const widgets = asArray(dash.widgets);\n for (let wi = 0; wi < widgets.length; wi++) {\n const widget = widgets[wi];\n if (!widget || typeof widget !== 'object') continue;\n if (!strName(widget.actionUrl)) continue;\n const widgetId = strName(widget.id) ?? `#${wi}`;\n checkOne(\n { actionType: widget.actionType as string | undefined, actionUrl: widget.actionUrl as string | undefined },\n `dashboard \"${dashName}\" · widget \"${widgetId}\" action`,\n `${dashPath}.widgets[${wi}].actionUrl`,\n );\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\nimport { classifyFilterToken, CONTEXT_TOKENS } from '@objectstack/spec/data';\n\n/**\n * Build-time filter-placeholder diagnostics (issue #3574).\n *\n * Filter values travel as JSON, so a user-scoped or time-scoped slice cannot\n * call code inline — it writes a placeholder that the client resolves just\n * before querying:\n *\n * { owner_id: '{current_user_id}', created_at: { $gte: '{week_start}' } }\n *\n * Exactly two vocabularies resolve inside a filter value: context tokens\n * (`{current_user_id}`, `{current_org_id}` — see `context-tokens.zod.ts`) and\n * date macros (`{today}`, `{30_days_ago}` — see `date-macros.zod.ts`).\n * Anything else is passed to the data engine **verbatim**, matches no row, and\n * the surface renders an empty result.\n *\n * ## Why this is an error, not a warning\n *\n * The runtime failure mode is silent and indistinguishable from success. A\n * metric widget filtered on an unresolved `{current_user}` renders `0`, which\n * looks exactly like a metric that is legitimately zero — no console error, no\n * server log, nothing for a human reviewer to notice. Issue #3574 found a\n * dashboard that had been broken this way since the day it was written.\n *\n * That failure mode is worse for AI authors than for humans. An AI reads a\n * successful query returning `0` as a correct answer and builds on it — it has\n * no instinct that the number looks wrong. Its correction loop is\n * \"author → validate → fix\", so a diagnostic only reaches it if the diagnostic\n * can fail the build. A runtime warning in a server log is invisible to it.\n * Hence: authoring-time error.\n *\n * The near-miss spellings this catches are not hypothetical. Each is a correct\n * spelling *somewhere else* in the platform, which is precisely why authors\n * reach for them:\n *\n * - `{current_user}` — `current_user.id` is the RLS expression root\n * - `{user_id}` — `{user_id}` is valid `titleFormat` field interpolation\n * - `{current_organization_id}` — `organization_id` is the real column name\n *\n * `CONTEXT_TOKEN_SUGGESTIONS` maps each to what the author meant, so the\n * diagnostic names the fix instead of only reporting the symptom.\n *\n * ## Scope — filter subtrees only\n *\n * The walk descends into `filter` / `filters` / `runtimeFilter` subtrees and\n * classifies string values inside them. It deliberately does NOT check\n * navigation `recordId` / `params`, which resolve an additional vocabulary —\n * `AppContextSelector` ids such as `{active_package}` — that is meaningless in\n * a filter because filters are not evaluated with the sidebar's selector\n * state. Restricting the walk keeps that legitimate usage out of the rule and\n * holds false positives at zero.\n *\n * Only whole-string placeholders are considered (`'{token}'` / `'${token}'`,\n * anchored). A value that merely contains braces is left alone.\n */\n\nexport const FILTER_TOKEN_UNKNOWN = 'filter-token-unknown';\n\nexport type FilterTokenSeverity = 'error' | 'warning';\n\nexport interface FilterTokenFinding {\n /** Always `error` today — an unresolved placeholder silently matches nothing. */\n severity: FilterTokenSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `dashboard \"sales\" · widget \"my_deals\"`. */\n where: string;\n /** Config path, e.g. `dashboards[0].widgets[2].filter.owner_id`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Keys whose subtree is a filter — the only place placeholders resolve. */\nconst FILTER_KEYS = new Set(['filter', 'filters', 'runtimeFilter']);\n\n/**\n * Coerce a collection (array or name-keyed map) to an array of records,\n * injecting `name` from the map key — mirrors the helper in the sibling\n * authoring lints so the rule works on both the parsed (array) and normalized\n * (map) stack shapes.\n */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction label(v: unknown, fallback: string): string {\n return typeof v === 'string' && v.length > 0 ? v : fallback;\n}\n\nconst KNOWN_LIST = CONTEXT_TOKENS.join('}, {');\n\n/**\n * Classify every string inside an already-identified filter subtree.\n *\n * Walks arrays and plain objects uniformly, which is what makes this work\n * across the platform's two filter shapes: the MongoDB-style object a\n * dashboard widget carries (`{ owner_id: '{current_user_id}' }`) and the\n * condition/triple arrays a list view carries\n * (`[{ field, operator, value }]` / `[['owner','=','…']]`). The bug this rule\n * exists for was caused by a resolver that handled only one of those shapes.\n */\nfunction walkFilterValues(\n node: unknown,\n path: string,\n where: string,\n out: FilterTokenFinding[],\n seen: Set<unknown>,\n): void {\n if (node === null || node === undefined) return;\n\n if (typeof node === 'string') {\n const cls = classifyFilterToken(node);\n if (cls?.kind === 'unknown') {\n const suggestion = cls.suggestion;\n out.push({\n severity: 'error',\n rule: FILTER_TOKEN_UNKNOWN,\n where,\n path,\n message:\n `Filter value \"${node}\" is not a resolvable placeholder. It is sent to the ` +\n `data engine as a literal string, matches no record, and the surface renders empty.`,\n hint: suggestion\n ? `Did you mean \"{${suggestion}}\"? Context tokens are {${KNOWN_LIST}}; ` +\n `time-based values use date macros such as {today} or {30_days_ago}.`\n : `Resolvable placeholders are the context tokens {${KNOWN_LIST}} and the ` +\n `date macros (e.g. {today}, {week_start}, {30_days_ago}). To filter on a ` +\n `literal value that happens to look like a placeholder, this is not supported — ` +\n `rename the value.`,\n });\n }\n return;\n }\n\n if (typeof node !== 'object') return;\n // Metadata graphs can be cyclic once normalized; guard the walk.\n if (seen.has(node)) return;\n seen.add(node);\n\n if (Array.isArray(node)) {\n node.forEach((v, i) => walkFilterValues(v, `${path}[${i}]`, where, out, seen));\n return;\n }\n\n for (const [k, v] of Object.entries(node as AnyRec)) {\n walkFilterValues(v, `${path}.${k}`, where, out, seen);\n }\n}\n\n/**\n * Find `filter` / `filters` / `runtimeFilter` subtrees anywhere beneath\n * `node`, then classify the values inside them.\n *\n * Scanning for filter KEYS rather than enumerating known surfaces is\n * deliberate: widget filters, list-view filters, dataset and measure filters,\n * report runtime filters, and SDUI component filters all spell the key the\n * same way, and a new surface that follows the convention is covered the day\n * it ships. Enumerating surfaces is how #3574 happened — the dashboard was\n * simply never added to the list.\n */\nfunction scanForFilters(\n node: unknown,\n path: string,\n where: string,\n out: FilterTokenFinding[],\n seen: Set<unknown>,\n): void {\n if (!node || typeof node !== 'object') return;\n if (seen.has(node)) return;\n seen.add(node);\n\n if (Array.isArray(node)) {\n node.forEach((v, i) => scanForFilters(v, `${path}[${i}]`, where, out, seen));\n return;\n }\n\n for (const [k, v] of Object.entries(node as AnyRec)) {\n const childPath = `${path}.${k}`;\n if (FILTER_KEYS.has(k)) {\n walkFilterValues(v, childPath, where, out, new Set());\n continue;\n }\n scanForFilters(v, childPath, where, out, seen);\n }\n}\n\n/**\n * Validate filter placeholders across a schema-parsed stack.\n *\n * Pure `(stack) => Finding[]`; no I/O. Covers dashboards (widget + global\n * filters), objects (list views), top-level view containers, reports,\n * datasets, and pages.\n */\nexport function validateFilterTokens(stack: Record<string, unknown> | undefined | null): FilterTokenFinding[] {\n if (!stack || typeof stack !== 'object') return [];\n const out: FilterTokenFinding[] = [];\n\n const surfaces: Array<[key: string, kind: string]> = [\n ['dashboards', 'dashboard'],\n ['objects', 'object'],\n ['views', 'view'],\n ['reports', 'report'],\n ['datasets', 'dataset'],\n ['pages', 'page'],\n ['apps', 'app'],\n ];\n\n for (const [key, kind] of surfaces) {\n const items = asArray((stack as AnyRec)[key]);\n items.forEach((item, i) => {\n const name = label(item.name ?? item.id, `#${i}`);\n // Dashboards are the surface #3574 was filed against; name the widget in\n // `where` so the author can jump straight to it.\n if (kind === 'dashboard') {\n const widgets = Array.isArray(item.widgets) ? (item.widgets as AnyRec[]) : [];\n widgets.forEach((w, wi) => {\n const wName = label(w.id ?? w.title, `#${wi}`);\n scanForFilters(\n w,\n `${key}[${i}].widgets[${wi}]`,\n `dashboard \"${name}\" · widget \"${wName}\"`,\n out,\n new Set(),\n );\n });\n // …and everything else on the dashboard (globalFilters, header, etc.)\n // minus the widgets already covered above.\n const { widgets: _skip, ...rest } = item;\n scanForFilters(rest, `${key}[${i}]`, `dashboard \"${name}\"`, out, new Set());\n return;\n }\n scanForFilters(item, `${key}[${i}]`, `${kind} \"${name}\"`, out, new Set());\n });\n }\n\n return out;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0072 — reference resolvability] Object-name reference integrity for the\n * surfaces no other rule owns (issue #3583).\n *\n * A HotCRM audit (~18k lines of shipped metadata) found ~20 instances of ONE\n * bug class: metadata naming an object that does not exist. Every instance\n * passed `objectstack validate` and `objectstack lint` cleanly and failed\n * SILENTLY at runtime — `object: 'user'` where the platform object is\n * `sys_user`, navigation targeting `sys_approval_process` (which\n * `@objectstack/plugin-approvals` never registers; ADR-0019 removed it).\n *\n * `defineStack`'s `validateCrossReferences` already hard-fails on the object\n * references it knows about (hooks, view data, seeds, mappings, permission\n * grants, nav `objectName`, action targets). This rule covers the REST — the\n * reference sites that are plain `z.string()` in the schema and therefore ship\n * whatever the author typed:\n *\n * - action params — `reference` (inline lookup/master_detail target) and\n * `objectOverride` (the object owning a field-backed param). Both are the\n * record picker's search target; a dead one degrades the dialog to a raw\n * id text input.\n * - dashboard `globalFilters[].optionsFrom.object` — the object a filter\n * dropdown fetches its options from. Dead → an always-empty dropdown.\n * - navigation `requiresObject` / `requiresService` capability gates. This is\n * the escape hatch `stack.zod.ts` honours to SKIP nav validation, so a typo\n * here is doubly silent: the entry is hidden forever (the runtime never\n * finds the object in its SchemaRegistry) AND the skip suppresses the\n * cross-reference error that would have caught the nav target.\n * - the nav `objectName` of an item that carries `requiresObject` — exempted\n * from the `defineStack` throw for good reason (it may come from another\n * package), but still worth an advisory when NO known package provides it.\n *\n * ── Severity ladder (the point of the rule) ──────────────────────────────\n *\n * Prior rules answered \"might this object come from another package?\" with a\n * PREFIX GUESS (`name.startsWith('sys_')` → skip). That guess cannot tell\n * `sys_user` (real) from `sys_approval_process` (fictional), so every fictional\n * platform-prefixed reference shipped. This rule resolves against the curated\n * `PLATFORM_PROVIDED_OBJECT_NAMES` registry instead:\n *\n * 1. resolves in the stack's own objects → OK\n * 2. unresolved, NOT platform-prefixed → ERROR\n * (`user`, `total_revenue` — no cross-package story exists for an\n * unprefixed name, since a stack's objects are namespace-prefixed;\n * this is the pure typo class and the bulk of the HotCRM findings)\n * 3. unresolved, prefixed, IN the registry → OK\n * 4. unresolved, prefixed, NOT in the registry → WARNING\n * (`sys_approval_process` — no package we know of registers it, but a\n * third-party package still might, so advisory is the honest ceiling)\n *\n * Interpolated targets (`${…}`, `{…}`) are skipped — they resolve at render\n * time, the same conservative exemption `validate-dashboard-action-refs` uses\n * to keep false positives near zero (ADR-0072 D1: one dead finding and authors\n * stop trusting the linter).\n */\n\nimport {\n hasPlatformObjectPrefix,\n isPlatformProvidedObjectName,\n PLATFORM_PROVIDED_OBJECT_NAMES,\n} from '@objectstack/spec/system';\n\n/** Materialized once for the repeated edit-distance scans in `suggest`. */\nconst PLATFORM_NAMES: readonly string[] = [...PLATFORM_PROVIDED_OBJECT_NAMES];\n\nexport const OBJECT_REFERENCE_UNKNOWN = 'object-reference-unknown';\nexport const OBJECT_REFERENCE_UNREGISTERED_PLATFORM = 'object-reference-unregistered-platform';\n\nexport type ObjectRefSeverity = 'error' | 'warning';\n\nexport interface ObjectRefFinding {\n /** `error` for an unresolvable own-stack name; `warning` for an unknown platform name. */\n severity: ObjectRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `action \"mass_update\" · param \"owner\"`. */\n where: string;\n /** Config path, e.g. `actions[2].params[0].reference`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\n/** Coerce a collection (array or name-keyed map) to an array of records,\n * injecting `name` from the map key — mirrors the sibling authoring lints so\n * the rule works on both the parsed (array) and normalized (map) stack shapes. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/**\n * A target the author cannot have meant literally — `${…}` or `{…}` resolved at\n * render time.\n *\n * Scanned rather than matched with `/\\{[^}]+\\}/`: that pattern backtracks\n * quadratically on a long run of `{` with no closing brace (CodeQL\n * polynomial-ReDoS), and the question here is simply \"is there a `{` with a\n * later `}` and something in between\", which one pass answers.\n */\nfunction isInterpolated(target: string): boolean {\n if (target.includes('${')) return true;\n const open = target.indexOf('{');\n // `+ 2` keeps the original \"at least one character between the braces\"\n // semantics, so a literal `{}` is not treated as a placeholder.\n return open !== -1 && target.indexOf('}', open + 2) !== -1;\n}\n\n/** Levenshtein-bounded \"did you mean?\" over the known names. */\nfunction suggest(target: string, known: Iterable<string>): string {\n let best: string | undefined;\n let bestScore = Infinity;\n for (const candidate of known) {\n const d = distance(target, candidate);\n if (d < bestScore) {\n bestScore = d;\n best = candidate;\n }\n }\n // Only offer a suggestion that is plausibly the same identifier mistyped.\n const limit = Math.max(2, Math.floor(target.length / 3));\n return best && bestScore <= limit ? ` Did you mean \"${best}\"?` : '';\n}\n\nfunction distance(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const curr = [i, ...new Array<number>(n).fill(0)];\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);\n }\n prev = curr;\n }\n return prev[n];\n}\n\n/**\n * Validate every object-name reference on the surfaces listed in the module\n * header. Returns findings (empty = clean).\n */\nexport function validateObjectReferences(stack: AnyRec): ObjectRefFinding[] {\n const findings: ObjectRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const objects = asArray(stack.objects);\n const ownObjects = new Set<string>();\n for (const obj of objects) {\n const n = strName(obj.name);\n if (n) ownObjects.add(n);\n }\n\n /**\n * Resolve one reference through the ladder and record a finding if it fails.\n * `subject` describes the reference for the message (\"record-picker target\").\n */\n const check = (\n target: string | undefined,\n where: string,\n path: string,\n subject: string,\n fix: string,\n ) => {\n const name = strName(target);\n if (!name) return;\n if (isInterpolated(name)) return; // resolved at render time\n if (ownObjects.has(name)) return; // ① own object\n if (isPlatformProvidedObjectName(name)) return; // ③ known platform object\n\n if (hasPlatformObjectPrefix(name)) {\n // ④ Platform-shaped, but no package we know of registers it.\n findings.push({\n severity: 'warning',\n rule: OBJECT_REFERENCE_UNREGISTERED_PLATFORM,\n where,\n path,\n message:\n `${subject} \"${name}\" carries a platform namespace prefix, but no platform ` +\n `package, official plugin, or cloud runtime object registers that name — ` +\n `and this stack does not define it either. If nothing provides it at runtime ` +\n `the reference resolves to nothing and fails silently.` +\n suggest(name, PLATFORM_NAMES),\n hint:\n `Check the spelling against the object the providing package actually registers ` +\n `(e.g. \"sys_approval_request\", not \"sys_approval_process\" — the process object ` +\n `was removed when approval became a flow node, ADR-0019). If a third-party ` +\n `package genuinely provides it, this warning is expected. ${fix}`,\n });\n return;\n }\n\n // ② Unprefixed and unresolved — a stack's own objects are namespace-\n // prefixed and present here, so there is no legitimate elsewhere.\n findings.push({\n severity: 'error',\n rule: OBJECT_REFERENCE_UNKNOWN,\n where,\n path,\n message:\n `${subject} \"${name}\" resolves to no object defined in this stack. ` +\n `The reference is inert at runtime — nothing reports the miss.` +\n suggest(name, ownObjects),\n hint:\n `Point it at one of this stack's objects, or at a platform object by its full ` +\n `name (the platform user object is \"sys_user\", not \"user\"). ${fix}` +\n (ownObjects.size > 0 ? ` Defined objects: ${[...ownObjects].sort().join(', ')}.` : ''),\n });\n };\n\n // ── Actions (global + object-embedded) → param object targets ──\n const checkActionParams = (action: AnyRec, actionPath: string, actionLabel: string) => {\n const params = asArray(action.params);\n for (let pi = 0; pi < params.length; pi++) {\n const param = params[pi];\n if (!param || typeof param !== 'object') continue;\n const paramLabel = strName(param.name) ?? strName(param.field) ?? `#${pi}`;\n const where = `${actionLabel} · param \"${paramLabel}\"`;\n check(\n strName(param.reference),\n where,\n `${actionPath}.params[${pi}].reference`,\n 'record-picker target',\n 'Without a resolvable target the picker degrades to a raw record-id text input.',\n );\n check(\n strName(param.objectOverride),\n where,\n `${actionPath}.params[${pi}].objectOverride`,\n 'field-backed param object',\n 'The param inherits type/options from a field on this object, so an unknown object leaves it untyped.',\n );\n }\n };\n\n const globalActions = asArray(stack.actions);\n for (let ai = 0; ai < globalActions.length; ai++) {\n const action = globalActions[ai];\n if (!action || typeof action !== 'object') continue;\n checkActionParams(action, `actions[${ai}]`, `action \"${strName(action.name) ?? `#${ai}`}\"`);\n }\n\n for (let oi = 0; oi < objects.length; oi++) {\n const obj = objects[oi];\n if (!obj || typeof obj !== 'object') continue;\n const objName = strName(obj.name) ?? `#${oi}`;\n const objActions = asArray(obj.actions);\n for (let ai = 0; ai < objActions.length; ai++) {\n const action = objActions[ai];\n if (!action || typeof action !== 'object') continue;\n checkActionParams(\n action,\n `objects[${oi}].actions[${ai}]`,\n `object \"${objName}\" · action \"${strName(action.name) ?? `#${ai}`}\"`,\n );\n }\n }\n\n // ── Dashboard global filters → optionsFrom.object ──\n const dashboards = asArray(stack.dashboards);\n for (let di = 0; di < dashboards.length; di++) {\n const dash = dashboards[di];\n if (!dash || typeof dash !== 'object') continue;\n const dashName = strName(dash.name) ?? `#${di}`;\n const filters = asArray(dash.globalFilters);\n for (let fi = 0; fi < filters.length; fi++) {\n const filter = filters[fi];\n if (!filter || typeof filter !== 'object') continue;\n const optionsFrom = filter.optionsFrom as AnyRec | undefined;\n if (!optionsFrom || typeof optionsFrom !== 'object') continue;\n check(\n strName(optionsFrom.object),\n `dashboard \"${dashName}\" · filter \"${strName(filter.name) ?? `#${fi}`}\"`,\n `dashboards[${di}].globalFilters[${fi}].optionsFrom.object`,\n 'filter options source',\n 'The dropdown fetches its options from this object; an unknown one renders an always-empty filter.',\n );\n }\n }\n\n // ── App navigation → requiresObject gates (and gated objectName) ──\n const apps = asArray(stack.apps);\n for (let ai = 0; ai < apps.length; ai++) {\n const app = apps[ai];\n if (!app || typeof app !== 'object') continue;\n const appName = strName(app.name) ?? `#${ai}`;\n\n const walkNav = (items: unknown, basePath: string) => {\n const navItems = asArray(items);\n for (let ni = 0; ni < navItems.length; ni++) {\n const nav = navItems[ni];\n if (!nav || typeof nav !== 'object') continue;\n const navId = strName(nav.id) ?? `#${ni}`;\n const where = `app \"${appName}\" · nav \"${navId}\"`;\n const navPath = `${basePath}[${ni}]`;\n\n check(\n strName(nav.requiresObject),\n where,\n `${navPath}.requiresObject`,\n 'capability gate object',\n 'The entry is hidden unless this object is registered, so a typo hides it permanently — ' +\n 'and it suppresses the nav cross-reference check that would have caught the target.',\n );\n\n // A nav target exempted from the `defineStack` throw by `requiresObject`\n // still deserves an advisory when nothing known provides it.\n if (nav.requiresObject && strName(nav.objectName)) {\n check(\n strName(nav.objectName),\n where,\n `${navPath}.objectName`,\n 'navigation target',\n 'Declaring `requiresObject` exempts this target from the build-time check, so it is only verified here.',\n );\n }\n\n if (Array.isArray(nav.children)) walkNav(nav.children, `${navPath}.children`);\n }\n };\n\n walkNav(app.navigation, `apps[${ai}].navigation`);\n const areas = asArray(app.areas);\n for (let ri = 0; ri < areas.length; ri++) {\n walkNav(areas[ri]?.navigation, `apps[${ai}].areas[${ri}].navigation`);\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0049 — references] Action-NAME reference integrity for the surfaces that\n * bind an action by name (issue #3583).\n *\n * `locations` is an action's primary binding, but several surfaces reference\n * actions **by name** instead (see `content/docs/ui/actions.mdx` — \"Surfaces can\n * also reference actions by name\"). Every one of those fields is a plain\n * `z.array(z.string())` / `z.string()`, so a name that matches no defined action\n * parses and ships:\n *\n * - list views — `rowActions[]` / `bulkActions[]` (both the default `list`\n * container and each `listViews.<key>` entry)\n * - page components — `record:quick_actions` → `properties.actionNames[]`\n * - app navigation — `{ type: 'action', actionDef: { actionName } }`\n *\n * The HotCRM audit shipped `bulkActions: ['mass_update', 'mass_delete',\n * 'assign_owner']` with none of the three defined anywhere: the toolbar renders\n * the buttons, selecting rows enables them, and clicking does nothing.\n *\n * This is the same failure `validate-dashboard-action-refs` catches for\n * dashboard header/widget buttons (`DASHBOARD_ACTION_TARGET_UNDEFINED`), so it\n * carries the same severity: **error**. It is a genuine dead reference, and —\n * unlike an object name — there is no cross-package escape hatch to soften it\n * with. The runtime ships NO built-in action names (there is no\n * `BUILTIN_ACTIONS` registry; `list_toolbar`/`list_item` are *locations*, not\n * actions), so a name resolving nowhere is dead, full stop.\n *\n * Scope note: this rule asks only \"is this action defined ANYWHERE in the\n * stack?\". It deliberately does NOT check that a view's action belongs to the\n * view's own object, nor that the action declares the matching `location` —\n * both are real but distinct classes, and folding them in here would trade the\n * zero-false-positive posture (ADR-0072 D1) for coverage this issue did not ask\n * for. An action defined by another installed package is the one legitimate\n * miss; it is called out in the hint rather than guessed at.\n */\n\nimport { walkPageComponents } from './page-walk.js';\n\nexport const ACTION_NAME_UNDEFINED = 'action-name-undefined';\n\nexport type ActionNameRefSeverity = 'error' | 'warning';\n\nexport interface ActionNameRefFinding {\n /** Always `error` — a name-bound action that resolves nowhere is a dead button. */\n severity: ActionNameRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `view \"crm_lead\" · list \"all\" · bulkActions`. */\n where: string;\n /** Config path, e.g. `views[0].list.bulkActions[1]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\nfunction strList(v: unknown): string[] {\n return Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string' && x.length > 0) : [];\n}\n\nfunction distance(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const curr = [i, ...new Array<number>(n).fill(0)];\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);\n }\n prev = curr;\n }\n return prev[n];\n}\n\nfunction suggest(target: string, known: Iterable<string>): string {\n let best: string | undefined;\n let bestScore = Infinity;\n for (const candidate of known) {\n const d = distance(target, candidate);\n if (d < bestScore) {\n bestScore = d;\n best = candidate;\n }\n }\n const limit = Math.max(2, Math.floor(target.length / 3));\n return best && bestScore <= limit ? ` Did you mean \"${best}\"?` : '';\n}\n\n/** Every action name defined in the stack (global + object-embedded). */\nfunction collectActionNames(stack: AnyRec): Set<string> {\n const names = new Set<string>();\n for (const action of asArray(stack.actions)) {\n const n = strName(action?.name);\n if (n) names.add(n);\n }\n for (const obj of asArray(stack.objects)) {\n if (!obj || typeof obj !== 'object') continue;\n for (const action of asArray(obj.actions)) {\n const n = strName(action?.name);\n if (n) names.add(n);\n }\n }\n return names;\n}\n\n/**\n * Validate every name-bound action reference in a stack. Returns findings\n * (empty = clean).\n */\nexport function validateActionNameRefs(stack: AnyRec): ActionNameRefFinding[] {\n const findings: ActionNameRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const known = collectActionNames(stack);\n\n const check = (name: string, where: string, path: string, surface: string) => {\n if (known.has(name)) return;\n findings.push({\n severity: 'error',\n rule: ACTION_NAME_UNDEFINED,\n where,\n path,\n message:\n `${surface} names action \"${name}\", which is defined by no action in this stack ` +\n `(neither \\`stack.actions\\` nor any object's \\`actions\\`). The button renders and ` +\n `does nothing when clicked — a dead affordance the runtime cannot dispatch.` +\n suggest(name, known),\n hint:\n `Define an action named \"${name}\" (in \\`stack.actions\\` or the object's \\`actions\\`) ` +\n `with the location this surface needs, remove the reference, or ignore this if the ` +\n `action is contributed by another installed package.` +\n (known.size > 0 ? ` Defined actions: ${[...known].sort().join(', ')}.` : ''),\n });\n };\n\n // ── List views: rowActions / bulkActions on `list` + each `listViews.<key>` ──\n const views = asArray(stack.views);\n for (let vi = 0; vi < views.length; vi++) {\n const view = views[vi];\n if (!view || typeof view !== 'object') continue;\n const viewName = strName(view.name) ?? strName(view.object) ?? `#${vi}`;\n\n const checkListContainer = (container: unknown, label: string, path: string) => {\n if (!container || typeof container !== 'object') return;\n const list = container as AnyRec;\n for (const key of ['rowActions', 'bulkActions'] as const) {\n const names = strList(list[key]);\n for (let ai = 0; ai < names.length; ai++) {\n check(\n names[ai],\n `view \"${viewName}\" · ${label} · ${key}`,\n `${path}.${key}[${ai}]`,\n key === 'bulkActions' ? 'Bulk-action menu' : 'Row-action menu',\n );\n }\n }\n };\n\n checkListContainer(view.list, 'list', `views[${vi}].list`);\n const listViews = view.listViews;\n if (listViews && typeof listViews === 'object' && !Array.isArray(listViews)) {\n for (const [key, lv] of Object.entries(listViews as AnyRec)) {\n checkListContainer(lv, `listViews.${key}`, `views[${vi}].listViews.${key}`);\n }\n }\n }\n\n // ── Page components: record:quick_actions → properties.actionNames ──\n const pages = asArray(stack.pages);\n for (let pi = 0; pi < pages.length; pi++) {\n const page = pages[pi];\n if (!page || typeof page !== 'object') continue;\n const pageName = strName(page.name) ?? `#${pi}`;\n\n // Traversal is shared (`page-walk.ts`): the component tree is NOT where a\n // first reading suggests. Components hang off `regions[].components[]` and\n // `slots`, never a top-level `page.components`, and sub-trees nest inside\n // the untyped `properties` bag rather than under a `children` key.\n for (const { component, path } of walkPageComponents(page, `pages[${pi}]`)) {\n const props = component.properties as AnyRec | undefined;\n if (!props || typeof props !== 'object') continue;\n const names = strList(props.actionNames);\n for (let ai = 0; ai < names.length; ai++) {\n check(\n names[ai],\n `page \"${pageName}\" · component \"${strName(component.type) ?? '?'}\"`,\n `${path}.properties.actionNames[${ai}]`,\n 'Quick-actions bar',\n );\n }\n }\n }\n\n // ── App navigation: { type: 'action', actionDef: { actionName } } ──\n const apps = asArray(stack.apps);\n for (let ai = 0; ai < apps.length; ai++) {\n const app = apps[ai];\n if (!app || typeof app !== 'object') continue;\n const appName = strName(app.name) ?? `#${ai}`;\n\n const walkNav = (items: unknown, basePath: string) => {\n const navItems = asArray(items);\n for (let ni = 0; ni < navItems.length; ni++) {\n const nav = navItems[ni];\n if (!nav || typeof nav !== 'object') continue;\n const navPath = `${basePath}[${ni}]`;\n const actionDef = nav.actionDef as AnyRec | undefined;\n const actionName = strName(actionDef?.actionName);\n if (nav.type === 'action' && actionName) {\n check(\n actionName,\n `app \"${appName}\" · nav \"${strName(nav.id) ?? `#${ni}`}\"`,\n `${navPath}.actionDef.actionName`,\n 'Navigation action item',\n );\n }\n if (Array.isArray(nav.children)) walkNav(nav.children, `${navPath}.children`);\n }\n };\n\n walkNav(app.navigation, `apps[${ai}].navigation`);\n const areas = asArray(app.areas);\n for (let ri = 0; ri < areas.length; ri++) {\n walkNav(areas[ri]?.navigation, `apps[${ai}].areas[${ri}].navigation`);\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0021 — semantic layer] Chart-binding integrity for the surfaces the\n * dashboard rule does not reach (issue #3583, assessment R4).\n *\n * `validate-widget-bindings` already resolves a dashboard widget's\n * `chartConfig` axes against its dataset's declared dimensions and measures\n * (`chart-field-unknown`). It is scoped to `stack.dashboards`, so three other\n * chart surfaces ship unchecked — and the HotCRM audit found exactly the bug\n * that scoping allows: an axis naming a RAW FIELD instead of a dataset measure.\n * Post-ADR-0021 the result rows are keyed by measure NAME (`sum_amount`), not\n * the base column (`amount`), so the axis renders and the series is empty.\n *\n * Surfaces covered here:\n *\n * 1. **Report charts** — `report.chart` and `report.blocks[].chart`.\n * `ReportChartSchema` narrows `xAxis`/`yAxis` from ChartConfig's\n * object/array shapes to bare STRINGS, which is why simply pointing the\n * dashboard rule at reports would find nothing: its `Array.isArray(yAxis)`\n * guard skips a string silently. `series[].name` keeps the array shape.\n * 2. **List-view charts** — `ListChartConfigSchema` (`dataset` +\n * `dimensions` + `values`), reachable through `views[].list`,\n * `views[].listViews.<key>`, and `objects[].listViews.<key>`.\n * 3. **Dataset-bound page chart components** — a `PageComponent` whose\n * `properties` carry a `dataset` (the `object-chart` component). Same\n * binding shape as a list chart, but it arrives through the untyped\n * `properties` bag.\n *\n * Not covered HERE, and deliberately so: the react `<ObjectChart>` block. It is\n * OBJECT-bound (`objectName` + an inline `aggregate`), so its result rows are\n * keyed by the RAW FIELD NAMES rather than by a measure name — the opposite\n * convention, which would make `chart-measure-unknown`'s message a lie. It also\n * arrives as JSX rather than config, so it needs the TypeScript compiler this\n * rule has no business loading. It is checked by `validate-react-page-props`\n * instead, against the naming convention `chartAggregateResultKeys`\n * (`@objectstack/spec/ui`) now pins down (#3701).\n */\n\nexport const CHART_DIMENSION_UNKNOWN = 'chart-dimension-unknown';\nexport const CHART_MEASURE_UNKNOWN = 'chart-measure-unknown';\nexport const CHART_DATASET_UNKNOWN = 'chart-dataset-unknown';\nexport const CHART_AXIS_NOT_SELECTED = 'chart-axis-not-selected';\n\nexport type ChartBindingSeverity = 'error' | 'warning';\n\nexport interface ChartBindingFinding {\n severity: ChartBindingSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `report \"hours_by_status\" · chart`. */\n where: string;\n /** Config path, e.g. `reports[2].chart.yAxis`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\nimport { walkPageComponents, type AnyRec } from './page-walk.js';\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\nfunction strList(v: unknown): string[] {\n return Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string' && x.length > 0) : [];\n}\n\nfunction isRec(v: unknown): v is AnyRec {\n return !!v && typeof v === 'object' && !Array.isArray(v);\n}\n\nfunction distance(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const curr = [i, ...new Array<number>(n).fill(0)];\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);\n }\n prev = curr;\n }\n return prev[n];\n}\n\nfunction suggest(target: string, known: Iterable<string>): string {\n let best: string | undefined;\n let bestScore = Infinity;\n for (const c of known) {\n const d = distance(target, c);\n if (d < bestScore) {\n bestScore = d;\n best = c;\n }\n }\n const limit = Math.max(2, Math.floor(target.length / 3));\n return best && bestScore <= limit ? ` Did you mean \"${best}\"?` : '';\n}\n\nfunction list(names: Iterable<string>): string {\n const all = [...names].sort();\n return all.length ? all.join(', ') : '(none)';\n}\n\n/** A dataset's declared dimension and measure names. */\ninterface DatasetNames {\n dimensions: Set<string>;\n measures: Set<string>;\n}\n\nfunction indexDatasets(stack: AnyRec): Map<string, DatasetNames> {\n const out = new Map<string, DatasetNames>();\n for (const ds of asArray(stack.datasets)) {\n const name = strName(ds.name);\n if (!name) continue;\n const dimensions = new Set<string>();\n for (const d of asArray(ds.dimensions)) {\n const n = strName(d.name);\n if (n) dimensions.add(n);\n }\n const measures = new Set<string>();\n for (const m of asArray(ds.measures)) {\n const n = strName(m.name);\n if (n) measures.add(n);\n }\n out.set(name, { dimensions, measures });\n }\n return out;\n}\n\n/**\n * One dataset-bound chart to check: the binding, the selection, and where it\n * came from. `xAxis`/`yAxis`/`series` are the ChartConfig-style axis refs;\n * `dimensions`/`values` are the list-chart-style selection.\n */\ninterface ChartBinding {\n dataset?: string;\n /** Selected dimension names (list-chart shape). */\n dimensions?: { names: string[]; path: string };\n /** Selected measure names (list-chart / report shape). */\n values?: { names: string[]; path: string };\n /** Single dimension ref (report `xAxis`). */\n xAxis?: { name: string; path: string };\n /** Single measure ref (report `yAxis`). */\n yAxis?: { name: string; path: string };\n /** Series names — measure refs (ChartConfig shape). */\n series?: Array<{ name: string; path: string }>;\n where: string;\n /** Path of the chart container, for the dataset-level finding. */\n path: string;\n}\n\nexport function validateChartBindings(stack: AnyRec): ChartBindingFinding[] {\n const findings: ChartBindingFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const datasets = indexDatasets(stack);\n if (datasets.size === 0 && !stack.reports && !stack.views && !stack.pages) return findings;\n\n const check = (binding: ChartBinding) => {\n const dsName = binding.dataset;\n if (!dsName) return; // nothing bound — the shape rules own that case\n const ds = datasets.get(dsName);\n if (!ds) {\n findings.push({\n severity: 'error',\n rule: CHART_DATASET_UNKNOWN,\n where: binding.where,\n path: `${binding.path}.dataset`,\n message:\n `binds dataset \"${dsName}\", which resolves to no declared dataset — ` +\n `the chart has no data to render.`,\n hint:\n `Declared datasets: ${list(datasets.keys())}.${suggest(dsName, datasets.keys())} ` +\n `Define it with defineDataset() or fix the reference (ADR-0021).`,\n });\n return;\n }\n\n const dimensionRef = (name: string, path: string) => {\n if (ds.dimensions.has(name)) return;\n findings.push({\n severity: 'error',\n rule: CHART_DIMENSION_UNKNOWN,\n where: binding.where,\n path,\n message:\n `\"${name}\" is not a dimension declared by dataset \"${dsName}\". ` +\n `Post-ADR-0021 result rows are keyed by DIMENSION NAME, not the base ` +\n `field, so this axis renders with no categories.`,\n hint:\n `Dataset dimensions: ${list(ds.dimensions)}.${suggest(name, ds.dimensions)} ` +\n `Declare the dimension on the dataset, or bind an existing one.`,\n });\n };\n\n const measureRef = (name: string, path: string, selected?: Set<string>) => {\n if (!ds.measures.has(name)) {\n findings.push({\n severity: 'error',\n rule: CHART_MEASURE_UNKNOWN,\n where: binding.where,\n path,\n message:\n `\"${name}\" is not a measure declared by dataset \"${dsName}\". ` +\n `Post-ADR-0021 result rows are keyed by MEASURE NAME (e.g. \"sum_amount\"), ` +\n `not the base field (e.g. \"amount\"), so this series comes back empty.`,\n hint:\n `Dataset measures: ${list(ds.measures)}.${suggest(name, ds.measures)} ` +\n `Declare the measure on the dataset, or bind an existing one.`,\n });\n return;\n }\n // Declared but not part of this chart's selection: the query never asks\n // for it, so the axis still plots nothing. Advisory — the selection may\n // legitimately be widened at runtime.\n if (selected && selected.size > 0 && !selected.has(name)) {\n findings.push({\n severity: 'warning',\n rule: CHART_AXIS_NOT_SELECTED,\n where: binding.where,\n path,\n message:\n `\"${name}\" is a declared measure of \"${dsName}\" but is not in this chart's ` +\n `selected values (${list(selected)}) — the query does not return it, ` +\n `so the series plots nothing.`,\n hint: `Add \"${name}\" to \\`values\\`, or point the axis at a selected measure.`,\n });\n }\n };\n\n const dimSel = binding.dimensions;\n if (dimSel) {\n for (let i = 0; i < dimSel.names.length; i++) {\n dimensionRef(dimSel.names[i], `${dimSel.path}[${i}]`);\n }\n }\n const valSel = binding.values;\n const selected = new Set(valSel?.names ?? []);\n if (valSel) {\n for (let i = 0; i < valSel.names.length; i++) {\n measureRef(valSel.names[i], `${valSel.path}[${i}]`);\n }\n }\n if (binding.xAxis) dimensionRef(binding.xAxis.name, binding.xAxis.path);\n if (binding.yAxis) measureRef(binding.yAxis.name, binding.yAxis.path, selected);\n for (const s of binding.series ?? []) measureRef(s.name, s.path, selected);\n };\n\n // ── 1. Report charts (report.chart + report.blocks[].chart) ──\n const reports = asArray(stack.reports);\n for (let ri = 0; ri < reports.length; ri++) {\n const report = reports[ri];\n if (!isRec(report)) continue;\n const reportName = strName(report.name) ?? `#${ri}`;\n\n const checkReportChart = (\n chart: unknown,\n dataset: string | undefined,\n values: string[],\n where: string,\n path: string,\n ) => {\n if (!isRec(chart)) return;\n check({\n dataset,\n // `values` is the report's measure SELECTION, not a chart ref; feeding\n // it in lets the yAxis \"declared but not selected\" check work without\n // reporting the selection itself twice.\n values: { names: values, path: `${path}.values` },\n xAxis: strName(chart.xAxis) ? { name: strName(chart.xAxis)!, path: `${path}.chart.xAxis` } : undefined,\n yAxis: strName(chart.yAxis) ? { name: strName(chart.yAxis)!, path: `${path}.chart.yAxis` } : undefined,\n series: asArray(chart.series)\n .map((s, si) => ({ name: strName(s.name), path: `${path}.chart.series[${si}].name` }))\n .filter((s): s is { name: string; path: string } => !!s.name),\n where,\n path: `${path}.chart`,\n });\n };\n\n checkReportChart(\n report.chart,\n strName(report.dataset),\n strList(report.values),\n `report \"${reportName}\" · chart`,\n `reports[${ri}]`,\n );\n\n const blocks = Array.isArray(report.blocks) ? report.blocks : [];\n for (let bi = 0; bi < blocks.length; bi++) {\n const block = blocks[bi];\n if (!isRec(block)) continue;\n checkReportChart(\n block.chart,\n strName(block.dataset),\n strList(block.values),\n `report \"${reportName}\" · block \"${strName(block.name) ?? `#${bi}`}\" chart`,\n `reports[${ri}].blocks[${bi}]`,\n );\n }\n }\n\n // ── 2. List-view charts ──\n const checkListChart = (container: unknown, where: string, path: string) => {\n if (!isRec(container)) return;\n const chart = container.chart;\n if (!isRec(chart)) return;\n check({\n dataset: strName(chart.dataset),\n dimensions: { names: strList(chart.dimensions), path: `${path}.chart.dimensions` },\n values: { names: strList(chart.values), path: `${path}.chart.values` },\n where,\n path: `${path}.chart`,\n });\n };\n\n const views = asArray(stack.views);\n for (let vi = 0; vi < views.length; vi++) {\n const view = views[vi];\n if (!isRec(view)) continue;\n const viewName = strName(view.name) ?? strName(view.objectName) ?? `#${vi}`;\n checkListChart(view.list, `view \"${viewName}\" · list chart`, `views[${vi}].list`);\n if (isRec(view.listViews)) {\n for (const [key, lv] of Object.entries(view.listViews)) {\n checkListChart(lv, `view \"${viewName}\" · listViews.${key} chart`, `views[${vi}].listViews.${key}`);\n }\n }\n }\n\n const objects = asArray(stack.objects);\n for (let oi = 0; oi < objects.length; oi++) {\n const obj = objects[oi];\n if (!isRec(obj) || !isRec(obj.listViews)) continue;\n const objName = strName(obj.name) ?? `#${oi}`;\n for (const [key, lv] of Object.entries(obj.listViews)) {\n checkListChart(\n lv,\n `object \"${objName}\" · listViews.${key} chart`,\n `objects[${oi}].listViews.${key}`,\n );\n }\n }\n\n // ── 3. Dataset-bound page chart components ──\n // A chart component arrives through the untyped `properties` bag. The\n // presence of a `dataset` key is what marks it dataset-bound (and so\n // checkable); an object-bound chart has none and is left alone.\n const pages = asArray(stack.pages);\n for (let pi = 0; pi < pages.length; pi++) {\n const page = pages[pi];\n if (!isRec(page)) continue;\n const pageName = strName(page.name) ?? `#${pi}`;\n for (const { component, path } of walkPageComponents(page, `pages[${pi}]`)) {\n const props = isRec(component.properties) ? component.properties : undefined;\n if (!props || !strName(props.dataset)) continue;\n // A page chart mixes the list-chart selection (`dataset`/`dimensions`/\n // `values`) with ChartConfig-style axes (`yAxis: [{ field }]`), so both\n // shapes are read here.\n const axisRefs = asArray(props.yAxis)\n .map((a, ai) => ({ name: strName(a.field), path: `${path}.properties.yAxis[${ai}].field` }))\n .filter((a): a is { name: string; path: string } => !!a.name);\n const seriesRefs = asArray(props.series)\n .map((s, si) => ({ name: strName(s.name), path: `${path}.properties.series[${si}].name` }))\n .filter((s): s is { name: string; path: string } => !!s.name);\n check({\n dataset: strName(props.dataset),\n dimensions: { names: strList(props.dimensions), path: `${path}.properties.dimensions` },\n values: { names: strList(props.values), path: `${path}.properties.values` },\n series: [...axisRefs, ...seriesRefs],\n where: `page \"${pageName}\" · ${strName(component.type) ?? 'chart'}`,\n path: `${path}.properties`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0090 D6] Navigation reachability vs. granted access (issue #3583,\n * assessment R5).\n *\n * An app can put an object in its navigation without any permission set\n * granting read on it. Nothing rejects that: navigation and permissions are\n * separate metadata, each valid on its own. At runtime the entry renders, the\n * user clicks it, and the list view comes back permission-denied — for EVERY\n * user, including the admin, because a permission nobody was granted is a\n * permission nobody has. The HotCRM audit shipped two such objects\n * (`crm_forecast`, `crm_knowledge_article`).\n *\n * This is the first lint consumer of `buildAccessMatrix` (ADR-0090 D6), which\n * already derives one row per (permission set × object) with `read` folded\n * across `allowRead` / `viewAllRecords` / `modifyAllRecords`. The rule is that\n * matrix joined against what navigation exposes.\n *\n * ── Advisory, deliberately ──────────────────────────────────────────────\n *\n * A grant can legitimately live outside this stack: a permission set shipped by\n * another installed package, a platform default, or an org-level assignment\n * made after install. A stack is therefore not *wrong* to ship an ungranted nav\n * entry — it is only *suspicious*, and the ceiling for a static check is a\n * warning (the same posture `validate-capability-references` takes).\n *\n * Two exemptions keep it quiet:\n * - **Platform-provided objects** (`sys_user`, `sys_approval_request`, …) are\n * skipped: the packages that register them ship their own permission sets,\n * which this stack never sees.\n * - **A stack that declares no permission sets at all** is skipped entirely.\n * Flagging every nav entry there says nothing useful — it means permissions\n * are managed elsewhere, not that each entry is broken (the same\n * \"empty collection ⇒ don't judge\" gate `defineStack` applies to nav\n * dashboard/page/report references).\n */\n\nimport { isPlatformProvidedObjectName } from '@objectstack/spec/system';\nimport { buildAccessMatrix } from './build-access-matrix.js';\n\nexport const NAV_OBJECT_UNGRANTED = 'nav-object-ungranted';\n\nexport type NavAccessSeverity = 'error' | 'warning';\n\nexport interface NavAccessFinding {\n /** Always `warning` — a grant may come from a package this stack cannot see. */\n severity: NavAccessSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `app \"crm\" · nav \"nav_forecast\"`. */\n where: string;\n /** Config path, e.g. `apps[0].navigation[3].objectName`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/** One navigation entry that exposes an object. */\ninterface NavExposure {\n objectName: string;\n where: string;\n path: string;\n}\n\n/** Collect every object a stack's navigation exposes, across areas and children. */\nfunction collectNavExposures(stack: AnyRec): NavExposure[] {\n const out: NavExposure[] = [];\n const apps = asArray(stack.apps);\n\n for (let ai = 0; ai < apps.length; ai++) {\n const app = apps[ai];\n if (!app || typeof app !== 'object') continue;\n const appName = strName(app.name) ?? `#${ai}`;\n\n const walk = (items: unknown, basePath: string) => {\n const navItems = asArray(items);\n for (let ni = 0; ni < navItems.length; ni++) {\n const nav = navItems[ni];\n if (!nav || typeof nav !== 'object') continue;\n const navPath = `${basePath}[${ni}]`;\n const objectName = strName(nav.objectName);\n if (nav.type === 'object' && objectName) {\n out.push({\n objectName,\n where: `app \"${appName}\" · nav \"${strName(nav.id) ?? `#${ni}`}\"`,\n path: `${navPath}.objectName`,\n });\n }\n if (Array.isArray(nav.children)) walk(nav.children, `${navPath}.children`);\n }\n };\n\n walk(app.navigation, `apps[${ai}].navigation`);\n const areas = asArray(app.areas);\n for (let ri = 0; ri < areas.length; ri++) {\n walk(areas[ri]?.navigation, `apps[${ai}].areas[${ri}].navigation`);\n }\n }\n\n return out;\n}\n\n/**\n * Validate that every object a stack's navigation exposes is readable by at\n * least one permission set the stack declares. Returns findings (empty = clean).\n */\nexport function validateNavAccess(stack: AnyRec): NavAccessFinding[] {\n const findings: NavAccessFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n // No permission sets in this stack ⇒ permissions are managed elsewhere.\n const permissionSets = asArray(stack.permissions);\n if (permissionSets.length === 0) return findings;\n\n const exposures = collectNavExposures(stack);\n if (exposures.length === 0) return findings;\n\n // Objects this stack actually defines — the only ones whose grants must be\n // present here. A nav target that resolves nowhere is a different bug, owned\n // by `validate-object-references` / `defineStack`.\n const ownObjects = new Set<string>();\n for (const obj of asArray(stack.objects)) {\n const n = strName(obj.name);\n if (n) ownObjects.add(n);\n }\n\n // `read` is already folded across allowRead / viewAllRecords / modifyAllRecords.\n const readable = new Set<string>();\n for (const entry of buildAccessMatrix(stack).entries) {\n if (entry.read) readable.add(entry.object);\n }\n // A wildcard grant (`objects: { '*': { allowRead: true } }`) covers every\n // object — the shape the platform's own `admin_full_access` uses. Without\n // this the matrix records the literal key `*` and every object looks\n // ungranted, which would make the rule fire on exactly the stacks that\n // granted the most.\n if (readable.has('*')) return findings;\n\n // De-duplicate: one finding per object, not per nav entry that exposes it.\n const reported = new Set<string>();\n\n for (const exposure of exposures) {\n const { objectName } = exposure;\n if (reported.has(objectName)) continue;\n if (isPlatformProvidedObjectName(objectName)) continue; // granted by its own package\n if (!ownObjects.has(objectName)) continue; // not ours to grant\n if (readable.has(objectName)) continue;\n\n reported.add(objectName);\n findings.push({\n severity: 'warning',\n rule: NAV_OBJECT_UNGRANTED,\n where: exposure.where,\n path: exposure.path,\n message:\n `navigation exposes object \"${objectName}\", but no permission set this stack ` +\n `declares grants read on it — the entry renders, and opening it fails ` +\n `permission-denied for every principal except one holding the platform's ` +\n `built-in wildcard admin set. It works when you browse as an administrator ` +\n `and breaks for the users the app ships permission sets for.`,\n hint:\n `Add \"${objectName}\" to a permission set's \\`objects\\` with \\`allowRead: true\\` ` +\n `(or \\`viewAllRecords\\`), gate the entry with \\`requiredPermissions\\`/\\`visible\\` ` +\n `if it is meant for admins only, or drop it. Ignore this if a permission set ` +\n `from another installed package grants it.`,\n });\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0090 D6] Access-matrix snapshot — authoring-time companion to the\n * runtime explain engine.\n *\n * `buildAccessMatrix(stack)` derives, PURELY from metadata, one row per\n * (permission set × object) the stack declares: the CRUD/VAMA bits, the\n * depth axes, and the object's OWD for context. The matrix is snapshotted to\n * `access-matrix.json` and diffed on every compile: an unchanged matrix\n * auto-passes; a changed one fails the build until the snapshot is updated —\n * so every capability change becomes a REVIEWABLE, semantic diff\n * (\"`crm_admin` gains delete on `crm_lead`\") instead of a buried JSON hunk.\n * This is the publish-gate substrate the AI-authoring safety story needs:\n * AI may draft grants freely; it cannot silently change who can do what.\n */\n\nimport type { AccessMatrix, AccessMatrixEntry } from '@objectstack/spec/security';\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\n/** Build the sorted access matrix for a normalized stack. */\nexport function buildAccessMatrix(stack: AnyRec): AccessMatrix {\n const entries: AccessMatrixEntry[] = [];\n if (!stack || typeof stack !== 'object') return { version: 1, entries };\n\n const owdByObject = new Map<string, string>();\n for (const obj of asArray(stack.objects)) {\n const name = typeof obj.name === 'string' ? obj.name : '';\n if (!name) continue;\n const owd = (obj.sharingModel ?? (obj.security as AnyRec | undefined)?.sharingModel) as string | undefined;\n if (typeof owd === 'string') owdByObject.set(name, owd);\n }\n\n for (const ps of asArray(stack.permissions)) {\n const psName = typeof ps.name === 'string' ? ps.name : '';\n if (!psName) continue;\n const objects = (ps.objects && typeof ps.objects === 'object' ? ps.objects : {}) as AnyRec;\n for (const [objName, rawPerm] of Object.entries(objects)) {\n const p = (rawPerm ?? {}) as AnyRec;\n const entry: AccessMatrixEntry = {\n permissionSet: psName,\n object: objName,\n create: p.allowCreate === true,\n read: p.allowRead === true || p.viewAllRecords === true || p.modifyAllRecords === true,\n edit: p.allowEdit === true || p.modifyAllRecords === true,\n delete: p.allowDelete === true || p.modifyAllRecords === true,\n viewAllRecords: p.viewAllRecords === true,\n modifyAllRecords: p.modifyAllRecords === true,\n };\n if (typeof p.readScope === 'string') entry.readScope = p.readScope;\n if (typeof p.writeScope === 'string') entry.writeScope = p.writeScope;\n const owd = owdByObject.get(objName);\n if (owd) entry.sharingModel = owd;\n entries.push(entry);\n }\n }\n\n entries.sort((a, b) =>\n a.permissionSet === b.permissionSet\n ? a.object.localeCompare(b.object)\n : a.permissionSet.localeCompare(b.permissionSet),\n );\n return { version: 1, entries };\n}\n\nconst BIT_LABELS: Array<[keyof AccessMatrixEntry, string]> = [\n ['create', 'create'],\n ['read', 'read'],\n ['edit', 'edit'],\n ['delete', 'delete'],\n ['viewAllRecords', 'View All Data'],\n ['modifyAllRecords', 'Modify All Data'],\n];\n\n/**\n * Semantic diff between two matrices — human-review lines, empty = identical.\n * Ordered: removals, additions, then per-entry bit/scope changes.\n */\nexport function diffAccessMatrix(before: AccessMatrix, after: AccessMatrix): string[] {\n const lines: string[] = [];\n const key = (e: AccessMatrixEntry) => `${e.permissionSet}\\u0000${e.object}`;\n const beforeMap = new Map((before?.entries ?? []).map((e) => [key(e), e]));\n const afterMap = new Map((after?.entries ?? []).map((e) => [key(e), e]));\n\n for (const [k, b] of beforeMap) {\n if (!afterMap.has(k)) {\n lines.push(`'${b.permissionSet}' loses ALL access to '${b.object}' (entry removed)`);\n }\n }\n for (const [k, a] of afterMap) {\n const b = beforeMap.get(k);\n if (!b) {\n const grants = BIT_LABELS.filter(([bit]) => a[bit] === true).map(([, label]) => label);\n lines.push(`'${a.permissionSet}' gains access to '${a.object}' (${grants.join(', ') || 'no bits set'})`);\n continue;\n }\n for (const [bit, label] of BIT_LABELS) {\n if (b[bit] !== a[bit]) {\n lines.push(`'${a.permissionSet}' ${a[bit] ? 'gains' : 'loses'} ${label} on '${a.object}'`);\n }\n }\n if ((b.readScope ?? 'own') !== (a.readScope ?? 'own')) {\n lines.push(`'${a.permissionSet}' read depth on '${a.object}': ${b.readScope ?? 'own'} → ${a.readScope ?? 'own'}`);\n }\n if ((b.writeScope ?? 'own') !== (a.writeScope ?? 'own')) {\n lines.push(`'${a.permissionSet}' write depth on '${a.object}': ${b.writeScope ?? 'own'} → ${a.writeScope ?? 'own'}`);\n }\n if ((b.sharingModel ?? '') !== (a.sharingModel ?? '')) {\n lines.push(`'${a.object}' record baseline (OWD): ${b.sharingModel ?? '(unset)'} → ${a.sharingModel ?? '(unset)'} (affects every principal)`);\n }\n }\n return lines;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0072 — reference resolvability] Translation-bundle reference integrity\n * and option-key validation (issue #3583, assessment R6).\n *\n * The i18n gate has always run in ONE direction: `computeI18nCoverage` asks\n * \"which keys does the metadata expect that no bundle carries?\" Nothing asks the\n * reverse — \"which keys does a bundle carry that no metadata claims?\" — even\n * though the spec already names the answer: `TranslationDiffStatus 'redundant'`\n * and `TranslationCoverageResult.redundantKeys` are declared and have no\n * producer.\n *\n * The HotCRM audit found that direction shipping broken metadata:\n *\n * - bundles keyed to fields the object never declares (`assigned_to`,\n * `budget`, `image_url`) — usually a rename that moved the field and left\n * the translation behind;\n * - select-option translations keyed by the option's DISPLAY LABEL instead of\n * its stored value, or by a near-miss of the value (`direct-mail` for\n * `direct_mail`, `planned` for `planning`).\n *\n * Both fail the same way: the resolver looks up the key it derives from the\n * metadata, finds nothing, and renders the untranslated source string. The app\n * looks *translated* — every other label on the screen resolves — so the hole is\n * invisible until a reader in that locale hits the one field or one picklist\n * value that stayed English.\n *\n * ── Severity ─────────────────────────────────────────────────────────────\n *\n * All findings are **warnings**. An orphan key is inert, not broken: it costs a\n * few bytes and one untranslated string, and nothing crashes. That is a weaker\n * failure than the dead references `validate-object-references` /\n * `validate-action-name-refs` report as errors, and the severity should say so\n * (ADR-0072 D1 — a linter that over-states is a linter authors stop reading).\n *\n * ── What this rule deliberately does NOT check ───────────────────────────\n *\n * - `messages`, `validationMessages`, `settings`, `settingsCommon` — keyed by\n * free-form message ids / namespaces owned by code and plugins, not by\n * stack metadata. There is no enumerable universe to resolve against, so a\n * rule here would be guessing.\n * - `metadataForms` — keyed by the platform's own metadata-type registry, not\n * by this stack. Owned by the platform packages; a stack translating them is\n * correct, not orphaned.\n * - leaf attribute names (`labl:` instead of `label:`) — Zod strips unknown\n * keys at parse, so they never reach a consumer with a value; that is a\n * schema-shape concern, not a reference.\n * - the object-first `AppTranslationBundle` (`o.<object>` …) — that shape is\n * the `translation` METADATA TYPE (records persisted through the metadata\n * store), not `stack.translations`, which is `TranslationBundle[]`\n * (locale → `TranslationData`). Its keys are simply not visited here: an\n * unrecognised top-level namespace is skipped, never reported.\n *\n * ── Cross-package objects ────────────────────────────────────────────────\n *\n * A stack legitimately translates objects it does not define — `sys_user`'s\n * labels are exactly the kind of thing an app localizes. Resolution follows the\n * §4 ladder of the assessment, with the field-level S3 rule intact:\n *\n * 1. own object → check its fields/views/actions/sections\n * 2. platform object in the registry → skip WHOLLY (we cannot see its\n * fields, so we cannot judge them)\n * 3. platform-prefixed, not in registry → warn on the object key only\n * 4. unresolved, unprefixed → warn on the object key only\n */\n\nimport { hasPlatformObjectPrefix, isPlatformProvidedObjectName } from '@objectstack/spec/system';\nimport { walkPageComponents } from './page-walk.js';\nimport { SYSTEM_FIELDS } from './system-fields.js';\n\nexport const TRANSLATION_TARGET_UNKNOWN = 'translation-target-unknown';\nexport const TRANSLATION_OPTION_KEY_UNKNOWN = 'translation-option-key-unknown';\n\nexport type TranslationRefSeverity = 'warning';\n\nexport interface TranslationRefFinding {\n /** Always `warning` — an orphan translation key is inert, not broken. */\n severity: TranslationRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `locale \"zh-CN\" · object \"crm_lead\"`. */\n where: string;\n /** Config path, e.g. `translations[0][\"zh-CN\"].objects.crm_lead.fields.campaign`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nfunction isRec(v: unknown): v is AnyRec {\n return !!v && typeof v === 'object' && !Array.isArray(v);\n}\n\n/** Coerce a collection (array or name-keyed map) to an array of records,\n * injecting `name` from the map key — mirrors the sibling authoring lints so\n * the rule works on both the parsed (array) and normalized (map) stack shapes. */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v as AnyRec[];\n if (isRec(v)) return Object.entries(v).map(([name, def]) => ({ name, ...(isRec(def) ? def : {}) }));\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\nfunction distance(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const curr = [i, ...new Array<number>(n).fill(0)];\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);\n }\n prev = curr;\n }\n return prev[n];\n}\n\n/**\n * \"Did you mean?\" over the known names — Levenshtein-bounded, plus a namespace\n * pass the distance metric cannot see.\n *\n * A stack prefixes its object names (`todo_task`, `crm_lead`), and the orphan\n * key is routinely the bare noun the author had in mind (`task`). That is 5\n * edits from `todo_task` — far outside the typo bound, and exactly the case\n * where the suggestion is most useful — so a candidate that differs only by a\n * snake_case namespace segment is offered before falling back to edit distance.\n */\nfunction suggest(target: string, known: Iterable<string>): string {\n const names = [...known];\n const segmentMatch = names.find(\n (candidate) => candidate.endsWith(`_${target}`) || candidate.startsWith(`${target}_`),\n );\n if (segmentMatch) return ` Did you mean \"${segmentMatch}\"?`;\n\n let best: string | undefined;\n let bestScore = Infinity;\n for (const candidate of names) {\n const d = distance(target, candidate);\n if (d < bestScore) {\n bestScore = d;\n best = candidate;\n }\n }\n const limit = Math.max(2, Math.floor(target.length / 3));\n return best && bestScore <= limit ? ` Did you mean \"${best}\"?` : '';\n}\n\n/** At most `max` names, sorted, for the \"known values are …\" tail of a hint. */\nfunction listNames(names: Iterable<string>, max = 12): string {\n const all = [...names].sort();\n if (all.length === 0) return '';\n const shown = all.slice(0, max).join(', ');\n return all.length > max ? `${shown}, … (${all.length} total)` : shown;\n}\n\n/**\n * Fields a bundle may translate without reading as orphans: the package-shared\n * registry-injected columns (`system-fields.ts`, #4330) plus three exemptions\n * this rule has carried since it landed — `_id` and `space` are legacy\n * physical spellings older bundles still key, and `name` is an ordinary\n * authored field on most objects. None of the three is a system column in the\n * spec's sense, so they stay rule-local (see the shared module's note) instead\n * of widening every field-existence rule in the package.\n */\nconst IMPLICIT_FIELDS: ReadonlySet<string> = new Set([\n ...SYSTEM_FIELDS,\n '_id', 'name', 'space',\n]);\n\n/** Everything a bundle may legally name under one object. */\ninterface ObjectFacts {\n fields: Map<string, AnyRec>;\n views: Set<string>;\n actions: Map<string, AnyRec>;\n sections: Set<string>;\n}\n\ninterface Universe {\n objects: Map<string, ObjectFacts>;\n /** App name → every navigation item id declared by that app. */\n apps: Map<string, Set<string>>;\n dashboards: Map<string, { widgets: Set<string>; actions: Set<string> }>;\n /** Object-less actions — the ones `globalActions.*` may name. */\n globalActions: Map<string, AnyRec>;\n /** Action name → owning object, so a misfiled `globalActions` key can say where it belongs. */\n actionOwners: Map<string, string>;\n}\n\nfunction emptyFacts(): ObjectFacts {\n return { fields: new Map(), views: new Set(), actions: new Map(), sections: new Set() };\n}\n\n/**\n * Register everything ONE view record contributes: the `_views` names it makes\n * legal, and the `_sections` names its form views declare — each under the\n * object that container actually binds.\n *\n * Two things about the real shape make this more than \"read `view.name`\", and\n * both were learned from the HotCRM corpus (~18k lines of shipped metadata),\n * where a first pass reported ~40 correct keys as orphans:\n *\n * 1. A view record is a CONTAINER, not a view. The default list sits at\n * `list`; the named tabs at `listViews.<key>` and `formViews.<key>`, each\n * of which may also carry its own `name`. Both the map key and the inner\n * `name` are accepted — authors write either, and the key is what the\n * console renders the tab from.\n * 2. The object binding lives INSIDE the container (`list.data.object`), not\n * at the record root. A record-level lookup alone resolves to nothing on\n * the canonical shape, which silently drops the whole record — a rule that\n * then reports every view key the app ships.\n */\nfunction collectViewRecord(view: AnyRec, factsFor: (objectName: string) => ObjectFacts): void {\n const recordObject = viewObjectName(view);\n const bindingOf = (container: AnyRec): string | undefined =>\n viewObjectName(container) ?? recordObject;\n\n const addView = (objectName: string | undefined, name: string | undefined) => {\n if (objectName && name) factsFor(objectName).views.add(name);\n };\n\n const listBinding = isRec(view.list) ? bindingOf(view.list) : undefined;\n if (isRec(view.list)) addView(listBinding, strName(view.list.name));\n addView(recordObject ?? listBinding, strName(view.name));\n\n for (const key of ['listViews', 'formViews'] as const) {\n const container = view[key];\n if (!isRec(container)) continue;\n for (const [subKey, sub] of Object.entries(container)) {\n if (!isRec(sub)) continue;\n const binding = bindingOf(sub) ?? listBinding;\n addView(binding, subKey);\n addView(binding, strName(sub.name));\n\n // Form sections carry an OPTIONAL `name` that exists purely for the\n // `_sections` lookup (`ui/view.zod.ts`: \"Stable section identifier for\n // i18n lookup\"). A section without one cannot be translated at all, so\n // it contributes nothing here.\n if (binding) {\n for (const section of asArray(sub.sections)) {\n const sectionName = strName(section.name);\n if (sectionName) factsFor(binding).sections.add(sectionName);\n }\n }\n }\n }\n\n const sectionBinding = recordObject ?? listBinding;\n if (sectionBinding) {\n for (const section of asArray(view.sections)) {\n const sectionName = strName(section.name);\n if (sectionName) factsFor(sectionBinding).sections.add(sectionName);\n }\n }\n}\n\n/** The object a view (or one of its containers) binds to, across the shapes it is authored in. */\nfunction viewObjectName(view: AnyRec): string | undefined {\n return (\n strName(view.objectName) ??\n strName(view.object) ??\n (isRec(view.data) ? strName(view.data.object) : undefined)\n );\n}\n\n/**\n * Declared select options for a field, or `undefined` when the field declares\n * none at all. Handles the canonical `{value,label}[]` shape plus the two\n * legacy shapes the extractor also tolerates (bare `string[]`, and a\n * `value → label` record).\n */\nfunction readOptions(field: AnyRec): { values: Set<string>; byLabel: Map<string, string> } | undefined {\n const raw = field.options;\n const values = new Set<string>();\n const byLabel = new Map<string, string>();\n if (Array.isArray(raw)) {\n for (const opt of raw) {\n if (typeof opt === 'string') {\n values.add(opt);\n continue;\n }\n if (!isRec(opt)) continue;\n const value = strName(opt.value);\n if (!value) continue;\n values.add(value);\n const label = strName(opt.label);\n if (label) byLabel.set(label.toLowerCase(), value);\n }\n } else if (isRec(raw)) {\n for (const [value, label] of Object.entries(raw)) {\n values.add(value);\n if (typeof label === 'string' && label.length > 0) byLabel.set(label.toLowerCase(), value);\n }\n } else {\n return undefined;\n }\n return values.size > 0 ? { values, byLabel } : undefined;\n}\n\n/**\n * Collect every name a translation bundle may resolve against. Built once per\n * run: the same universe answers all bundles and all locales.\n */\nfunction buildUniverse(stack: AnyRec): Universe {\n const objects = new Map<string, ObjectFacts>();\n const factsFor = (name: string): ObjectFacts => {\n let facts = objects.get(name);\n if (!facts) {\n facts = emptyFacts();\n objects.set(name, facts);\n }\n return facts;\n };\n\n // ── Objects: fields, embedded actions/views, fieldGroups (the `_sections` anchor) ──\n for (const obj of asArray(stack.objects)) {\n const objectName = strName(obj.name);\n if (!objectName) continue;\n const facts = factsFor(objectName);\n\n for (const field of asArray(obj.fields)) {\n const fieldName = strName(field.name);\n if (fieldName) facts.fields.set(fieldName, field);\n }\n for (const action of asArray(obj.actions)) {\n const actionName = strName(action.name);\n if (actionName) facts.actions.set(actionName, action);\n }\n // An object can carry views directly, including the `objects[].listViews`\n // container the chart rule also walks. `{ ...view, object: objectName }`\n // pins the binding: an embedded view inherits its owner, and nothing here\n // depends on the container repeating it.\n for (const view of asArray(obj.views)) {\n collectViewRecord({ ...view, object: strName(view.object) ?? objectName }, factsFor);\n }\n collectViewRecord({ object: objectName, listViews: obj.listViews }, factsFor);\n // ADR-0085: `fieldGroups[].key` is the i18n anchor for `_sections`.\n for (const group of asArray(obj.fieldGroups)) {\n const key = strName(group.key) ?? strName(group.name);\n if (key) facts.sections.add(key);\n }\n }\n\n // ── Stack-level views: `_views` names + form-section names ──\n for (const view of asArray(stack.views)) {\n collectViewRecord(view, factsFor);\n }\n\n // ── Pages: `record:details` sections are the other `_sections` anchor ──\n const pages = asArray(stack.pages);\n for (let pi = 0; pi < pages.length; pi++) {\n for (const walked of walkPageComponents(pages[pi], `pages[${pi}]`)) {\n if (!walked.objectName) continue;\n const props = isRec(walked.component.properties) ? walked.component.properties : undefined;\n if (!props) continue;\n for (const section of asArray(props.sections)) {\n const sectionName = strName(section.name);\n if (sectionName) factsFor(walked.objectName).sections.add(sectionName);\n }\n }\n }\n\n // ── Actions: object-bound ones join their object; the rest are global ──\n const globalActions = new Map<string, AnyRec>();\n const actionOwners = new Map<string, string>();\n for (const action of asArray(stack.actions)) {\n const actionName = strName(action.name);\n if (!actionName) continue;\n const owner = strName(action.objectName) ?? strName(action.object);\n if (owner) {\n factsFor(owner).actions.set(actionName, action);\n actionOwners.set(actionName, owner);\n } else {\n globalActions.set(actionName, action);\n }\n }\n for (const [objectName, facts] of objects) {\n for (const actionName of facts.actions.keys()) {\n if (!actionOwners.has(actionName)) actionOwners.set(actionName, objectName);\n }\n }\n\n // ── Apps: navigation item ids (`apps.<app>.navigation.<id>.label`) ──\n const apps = new Map<string, Set<string>>();\n for (const app of asArray(stack.apps)) {\n const appName = strName(app.name);\n if (!appName) continue;\n const navIds = apps.get(appName) ?? new Set<string>();\n const walkNav = (items: unknown) => {\n for (const item of asArray(items)) {\n const id = strName(item.id);\n if (id) navIds.add(id);\n if (item.children) walkNav(item.children);\n }\n };\n walkNav(app.navigation);\n for (const area of asArray(app.areas)) {\n const areaId = strName(area.id);\n if (areaId) navIds.add(areaId);\n walkNav(area.navigation);\n }\n apps.set(appName, navIds);\n }\n\n // ── Dashboards: widget ids + header action urls ──\n const dashboards = new Map<string, { widgets: Set<string>; actions: Set<string> }>();\n for (const dash of asArray(stack.dashboards)) {\n const dashName = strName(dash.name);\n if (!dashName) continue;\n const widgets = new Set<string>();\n for (const widget of asArray(dash.widgets)) {\n const id = strName(widget.id) ?? strName(widget.name);\n if (id) widgets.add(id);\n }\n const actions = new Set<string>();\n const headerActions = [\n ...asArray(isRec(dash.header) ? dash.header.actions : undefined),\n ...asArray(dash.actions),\n ];\n for (const action of headerActions) {\n const key = strName(action.actionUrl) ?? strName(action.url) ?? strName(action.name);\n if (key) actions.add(key);\n }\n dashboards.set(dashName, { widgets, actions });\n }\n\n return { objects, apps, dashboards, globalActions, actionOwners };\n}\n\n/** Quote a locale for the config path — BCP-47 tags carry `-`. */\nfunction localePath(bundleIndex: number, locale: string): string {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(locale)\n ? `translations[${bundleIndex}].${locale}`\n : `translations[${bundleIndex}][\"${locale}\"]`;\n}\n\n/**\n * Validate every reference a translation bundle makes against the metadata it\n * claims to translate. Returns findings (empty = clean).\n */\nexport function validateTranslationReferences(stack: AnyRec): TranslationRefFinding[] {\n const findings: TranslationRefFinding[] = [];\n if (!isRec(stack)) return findings;\n\n const bundles = Array.isArray(stack.translations) ? stack.translations : [];\n if (bundles.length === 0) return findings;\n\n const universe = buildUniverse(stack);\n\n const orphan = (where: string, path: string, message: string, hint: string) => {\n findings.push({ severity: 'warning', rule: TRANSLATION_TARGET_UNKNOWN, where, path, message, hint });\n };\n\n for (let bi = 0; bi < bundles.length; bi++) {\n const bundle = bundles[bi];\n if (!isRec(bundle)) continue;\n\n for (const [locale, rawData] of Object.entries(bundle)) {\n if (!isRec(rawData)) continue;\n const base = localePath(bi, locale);\n const inLocale = `locale \"${locale}\"`;\n\n // ── objects.<name>.… ──────────────────────────────────────────────\n for (const [objectName, rawNode] of Object.entries(asRecord(rawData.objects))) {\n if (!isRec(rawNode)) continue;\n const objPath = `${base}.objects.${objectName}`;\n const facts = universe.objects.get(objectName);\n\n if (!facts) {\n // Not this stack's object. Platform objects are translated by their\n // owning package but a stack may override them, so a registered\n // platform name is legitimate — and unreadable from here, which is\n // why the whole subtree is skipped rather than half-checked.\n if (isPlatformProvidedObjectName(objectName)) continue;\n orphan(\n `${inLocale} · object \"${objectName}\"`,\n objPath,\n hasPlatformObjectPrefix(objectName)\n ? `Translations are keyed to \"${objectName}\", which carries a platform namespace ` +\n `prefix but is registered by no platform package, official plugin, or cloud ` +\n `runtime object — and this stack does not define it either. Nothing resolves ` +\n `these keys.` + suggest(objectName, universe.objects.keys())\n : `Translations are keyed to \"${objectName}\", which no object in this stack ` +\n `defines. The resolver looks up keys derived from the metadata, so this whole ` +\n `subtree is dead weight — every label it carries renders untranslated.` +\n suggest(objectName, universe.objects.keys()),\n `Rename the key to the object it was written for, drop it, or ignore this if the ` +\n `object is contributed by another installed package.` +\n (universe.objects.size > 0 ? ` Defined objects: ${listNames(universe.objects.keys())}.` : ''),\n );\n continue;\n }\n\n // fields.<name>[.options.<value>]\n for (const [fieldName, rawField] of Object.entries(asRecord(rawNode.fields))) {\n const fieldPath = `${objPath}.fields.${fieldName}`;\n const field = facts.fields.get(fieldName);\n if (!field) {\n if (IMPLICIT_FIELDS.has(fieldName)) continue;\n orphan(\n `${inLocale} · object \"${objectName}\" · field \"${fieldName}\"`,\n fieldPath,\n `Translations are keyed to field \"${fieldName}\", which object \"${objectName}\" ` +\n `does not declare. The label renders untranslated in this locale — and because ` +\n `every neighbouring field DOES resolve, the hole reads as a styling quirk ` +\n `rather than a missing translation.` + suggest(fieldName, facts.fields.keys()),\n `Point the key at a declared field, or drop it if the field was removed or renamed.` +\n (facts.fields.size > 0 ? ` Declared fields: ${listNames(facts.fields.keys())}.` : ''),\n );\n continue;\n }\n if (!isRec(rawField)) continue;\n checkOptionKeys(findings, {\n optionMap: rawField.options,\n field,\n fieldName,\n objectName,\n path: `${fieldPath}.options`,\n where: `${inLocale} · object \"${objectName}\" · field \"${fieldName}\"`,\n });\n }\n\n // _views.<name>\n for (const viewName of Object.keys(asRecord(rawNode._views))) {\n if (facts.views.has(viewName)) continue;\n orphan(\n `${inLocale} · object \"${objectName}\" · view \"${viewName}\"`,\n `${objPath}._views.${viewName}`,\n `Translations are keyed to view \"${viewName}\", which no view of object ` +\n `\"${objectName}\" declares. The view tab keeps its source-locale label.` +\n suggest(viewName, facts.views),\n `Match the key to the view's \\`name\\` (not its label), or drop it.` +\n (facts.views.size > 0 ? ` Declared views: ${listNames(facts.views)}.` : ''),\n );\n }\n\n // _sections.<key>\n for (const sectionName of Object.keys(asRecord(rawNode._sections))) {\n if (facts.sections.has(sectionName)) continue;\n orphan(\n `${inLocale} · object \"${objectName}\" · section \"${sectionName}\"`,\n `${objPath}._sections.${sectionName}`,\n `Translations are keyed to section \"${sectionName}\", which nothing on object ` +\n `\"${objectName}\" declares — no \\`fieldGroups[].key\\`, no named form-view section, ` +\n `no named \\`record:details\\` section. The section heading stays in the source locale.` +\n suggest(sectionName, facts.sections),\n `Sections are translatable only through a STABLE NAME: give the group/section a ` +\n `\\`key\\`/\\`name\\` and use it here, or drop the translation.` +\n (facts.sections.size > 0\n ? ` Declared sections: ${listNames(facts.sections)}.`\n : ` Object \"${objectName}\" declares no named section at all.`),\n );\n }\n\n // _actions.<name>[.params.<name>]\n for (const [actionName, rawAction] of Object.entries(asRecord(rawNode._actions))) {\n const actionPath = `${objPath}._actions.${actionName}`;\n const action = facts.actions.get(actionName);\n if (!action) {\n orphan(\n `${inLocale} · object \"${objectName}\" · action \"${actionName}\"`,\n actionPath,\n `Translations are keyed to action \"${actionName}\", which is defined by neither ` +\n `object \"${objectName}\"'s \\`actions\\` nor a \\`stack.actions\\` entry bound to it. ` +\n `The button keeps its source-locale label.` + suggest(actionName, facts.actions.keys()),\n `Match the key to a defined action name, move it under the object that owns the ` +\n `action, or drop it.` +\n (facts.actions.size > 0 ? ` Actions on this object: ${listNames(facts.actions.keys())}.` : ''),\n );\n continue;\n }\n checkActionParams(findings, {\n rawAction,\n action,\n path: actionPath,\n where: `${inLocale} · object \"${objectName}\" · action \"${actionName}\"`,\n subject: `action \"${actionName}\"`,\n });\n }\n }\n\n // ── globalActions.<name> ──────────────────────────────────────────\n for (const [actionName, rawAction] of Object.entries(asRecord(rawData.globalActions))) {\n const actionPath = `${base}.globalActions.${actionName}`;\n const action = universe.globalActions.get(actionName);\n if (!action) {\n const owner = universe.actionOwners.get(actionName);\n orphan(\n `${inLocale} · global action \"${actionName}\"`,\n actionPath,\n owner\n ? `Action \"${actionName}\" is bound to object \"${owner}\", so the resolver looks it ` +\n `up under \\`objects.${owner}._actions.${actionName}\\` — never under ` +\n `\\`globalActions\\`, which is only consulted for object-less actions. This key ` +\n `is never read.`\n : `Translations are keyed to global action \"${actionName}\", which no object-less ` +\n `action in this stack defines. The button keeps its source-locale label.` +\n suggest(actionName, universe.globalActions.keys()),\n owner\n ? `Move these keys under \\`objects.${owner}._actions.${actionName}\\`.`\n : `Match the key to an object-less action's name, or drop it.` +\n (universe.globalActions.size > 0\n ? ` Object-less actions: ${listNames(universe.globalActions.keys())}.`\n : ''),\n );\n continue;\n }\n checkActionParams(findings, {\n rawAction,\n action,\n path: actionPath,\n where: `${inLocale} · global action \"${actionName}\"`,\n subject: `action \"${actionName}\"`,\n });\n }\n\n // ── apps.<name>[.navigation.<id>] ─────────────────────────────────\n for (const [appName, rawApp] of Object.entries(asRecord(rawData.apps))) {\n const appPath = `${base}.apps.${appName}`;\n const navIds = universe.apps.get(appName);\n if (!navIds) {\n orphan(\n `${inLocale} · app \"${appName}\"`,\n appPath,\n `Translations are keyed to app \"${appName}\", which this stack does not define. ` +\n `The app launcher shows the source-locale label.` + suggest(appName, universe.apps.keys()),\n `Match the key to an app's \\`name\\`, or drop it.` +\n (universe.apps.size > 0 ? ` Defined apps: ${listNames(universe.apps.keys())}.` : ''),\n );\n continue;\n }\n if (!isRec(rawApp)) continue;\n for (const navId of Object.keys(asRecord(rawApp.navigation))) {\n if (navIds.has(navId)) continue;\n orphan(\n `${inLocale} · app \"${appName}\" · navigation \"${navId}\"`,\n `${appPath}.navigation.${navId}`,\n `Translations are keyed to navigation item \"${navId}\", which app \"${appName}\" ` +\n `does not declare. The menu entry keeps its source-locale label.` +\n suggest(navId, navIds),\n `Match the key to the navigation item's \\`id\\`, or drop it.` +\n (navIds.size > 0 ? ` Declared navigation ids: ${listNames(navIds)}.` : ''),\n );\n }\n }\n\n // ── dashboards.<name>[.widgets.<id> | .actions.<url>] ─────────────\n for (const [dashName, rawDash] of Object.entries(asRecord(rawData.dashboards))) {\n const dashPath = `${base}.dashboards.${dashName}`;\n const dash = universe.dashboards.get(dashName);\n if (!dash) {\n orphan(\n `${inLocale} · dashboard \"${dashName}\"`,\n dashPath,\n `Translations are keyed to dashboard \"${dashName}\", which this stack does not ` +\n `define. The dashboard title stays in the source locale.` +\n suggest(dashName, universe.dashboards.keys()),\n `Match the key to a dashboard's \\`name\\`, or drop it.` +\n (universe.dashboards.size > 0 ? ` Defined dashboards: ${listNames(universe.dashboards.keys())}.` : ''),\n );\n continue;\n }\n if (!isRec(rawDash)) continue;\n for (const widgetId of Object.keys(asRecord(rawDash.widgets))) {\n if (dash.widgets.has(widgetId)) continue;\n orphan(\n `${inLocale} · dashboard \"${dashName}\" · widget \"${widgetId}\"`,\n `${dashPath}.widgets.${widgetId}`,\n `Translations are keyed to widget \"${widgetId}\", which dashboard \"${dashName}\" ` +\n `does not declare. The widget title stays in the source locale.` +\n suggest(widgetId, dash.widgets),\n `Match the key to the widget's \\`id\\`, or drop it.` +\n (dash.widgets.size > 0 ? ` Declared widget ids: ${listNames(dash.widgets)}.` : ''),\n );\n }\n for (const actionKey of Object.keys(asRecord(rawDash.actions))) {\n if (dash.actions.has(actionKey)) continue;\n orphan(\n `${inLocale} · dashboard \"${dashName}\" · action \"${actionKey}\"`,\n `${dashPath}.actions.${actionKey}`,\n `Translations are keyed to header action \"${actionKey}\", which dashboard ` +\n `\"${dashName}\" does not declare. The button keeps its source-locale label.` +\n suggest(actionKey, dash.actions),\n `Header-action translations are keyed by the action's \\`actionUrl\\`, not its label.` +\n (dash.actions.size > 0 ? ` Declared header actions: ${listNames(dash.actions)}.` : ''),\n );\n }\n }\n }\n }\n\n return findings;\n}\n\n/** `v` as a record of sub-nodes, or an empty record when absent/malformed. */\nfunction asRecord(v: unknown): Record<string, unknown> {\n return isRec(v) ? v : {};\n}\n\n/**\n * Option translations are keyed by the option's STORED VALUE. Keying them by\n * the display label — or by a near-miss of the value — is the second half of\n * issue #3583's option-key class: the map parses, ships, and never resolves.\n */\nfunction checkOptionKeys(\n findings: TranslationRefFinding[],\n ctx: {\n optionMap: unknown;\n field: AnyRec;\n fieldName: string;\n objectName: string;\n path: string;\n where: string;\n },\n): void {\n const optionKeys = Object.keys(asRecord(ctx.optionMap));\n if (optionKeys.length === 0) return;\n\n const declared = readOptions(ctx.field);\n if (!declared) {\n findings.push({\n severity: 'warning',\n rule: TRANSLATION_OPTION_KEY_UNKNOWN,\n where: ctx.where,\n path: ctx.path,\n message:\n `Option translations are keyed under field \"${ctx.fieldName}\" of object ` +\n `\"${ctx.objectName}\", which declares no \\`options\\` at all (field type ` +\n `\"${strName(ctx.field.type) ?? 'unknown'}\"). Nothing reads this map.`,\n hint:\n `Declare the options on the field, move the translations to the field that owns ` +\n `them, or drop them.`,\n });\n return;\n }\n\n for (const key of optionKeys) {\n if (declared.values.has(key)) continue;\n const byLabel = declared.byLabel.get(key.toLowerCase());\n findings.push({\n severity: 'warning',\n rule: TRANSLATION_OPTION_KEY_UNKNOWN,\n where: ctx.where,\n path: `${ctx.path}.${key}`,\n message: byLabel\n ? `Option translation is keyed by the DISPLAY LABEL \"${key}\" instead of the stored ` +\n `value \"${byLabel}\". The resolver looks the option up by value, so this entry is ` +\n `never found and the option renders with its source-locale label.`\n : `Option translation is keyed by \"${key}\", which is not one of the values declared ` +\n `by field \"${ctx.objectName}.${ctx.fieldName}\". The option renders untranslated.` +\n suggest(key, declared.values),\n hint: byLabel\n ? `Rename the key to \"${byLabel}\".`\n : `Option keys are the stored \\`value\\`, not the label and not a variant spelling ` +\n `(\\`direct_mail\\`, not \\`direct-mail\\`). Declared values: ${listNames(declared.values)}.`,\n });\n }\n}\n\n/** Action-parameter translations are keyed by the param's `name`. */\nfunction checkActionParams(\n findings: TranslationRefFinding[],\n ctx: { rawAction: unknown; action: AnyRec; path: string; where: string; subject: string },\n): void {\n const rawParams = Object.keys(asRecord(isRec(ctx.rawAction) ? ctx.rawAction.params : undefined));\n if (rawParams.length === 0) return;\n\n const declared = new Set<string>();\n for (const param of asArray(ctx.action.params)) {\n const name = strName(param.name) ?? strName(param.field);\n if (name) declared.add(name);\n }\n\n for (const paramName of rawParams) {\n if (declared.has(paramName)) continue;\n findings.push({\n severity: 'warning',\n rule: TRANSLATION_TARGET_UNKNOWN,\n where: `${ctx.where} · param \"${paramName}\"`,\n path: `${ctx.path}.params.${paramName}`,\n message:\n `Translations are keyed to parameter \"${paramName}\", which ${ctx.subject} does not ` +\n `declare. The parameter's label and help text render untranslated in the action dialog.` +\n suggest(paramName, declared),\n hint:\n `Match the key to a declared param \\`name\\`, or drop it.` +\n (declared.size > 0 ? ` Declared params: ${listNames(declared)}.` : ''),\n });\n }\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0064 §3] Skill ↔ agent surface affinity (issue #3820).\n *\n * An agent binds a product surface (`'ask'` | `'build'`, ADR-0063 §1) and a\n * skill declares which surface it belongs to (`'ask'` | `'build'` | `'both'`,\n * ADR-0063 §3). A skill may only attach to an agent whose surface it matches —\n * `'both'` attaches to either. The runtime treats a violation as a FAST LOAD\n * ERROR: `resolveActiveSkills()` throws on the first incompatible binding, so\n * an agent shipping one mismatched skill reference fails at **chat time** with\n * a 500 — after parse, after validate, after deploy.\n *\n * Both sides of the check are declared in the same stack, so the contradiction\n * is statically provable and this rule carries severity **error** with zero\n * false positives by construction. Both sides default to `'ask'` when the\n * `surface` field is absent (mirroring the runtime's defaults), so the rule is\n * safe on the raw/normalized config the `lint` path carries as well as the\n * schema-parsed stack.\n *\n * Scope note: this rule deliberately does NOT check that `agent.skills[]`\n * names resolve at all. Kernel skills (`schema_reader`, the `ask`/`build`\n * bundles) are runtime-registered and statically invisible, and whether\n * app-stack tool/skill namespaces get a platform-name registry is an open\n * decision (#3820 D0/D2) — resolving names against `stack.skills` alone would\n * flag every kernel-skill reference. An unresolved name is therefore skipped\n * here; only a reference that resolves in-stack AND contradicts the affinity\n * contract is reported.\n */\n\nexport const AI_SKILL_SURFACE_MISMATCH = 'ai-skill-surface-mismatch';\n\nexport type AiSurfaceAffinitySeverity = 'error' | 'warning';\n\nexport interface AiSurfaceAffinityFinding {\n /** Always `error` — the runtime throws on this binding at chat time. */\n severity: AiSurfaceAffinitySeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `agent \"sales_copilot\" · skills`. */\n where: string;\n /** Config path, e.g. `agents[0].skills[2]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v.filter((x): x is AnyRec => !!x && typeof x === 'object');\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/** The runtime defaults an absent `surface` to `'ask'` on both sides. */\nfunction surfaceOf(v: unknown): string {\n return typeof v === 'string' && v.length > 0 ? v : 'ask';\n}\n\n/**\n * Validate every in-stack agent→skill binding against the ADR-0064 §3 surface\n * affinity contract. Returns findings (empty = clean).\n */\nexport function validateAiSurfaceAffinity(stack: AnyRec): AiSurfaceAffinityFinding[] {\n const findings: AiSurfaceAffinityFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const skillsByName = new Map<string, AnyRec>();\n for (const skill of asArray(stack.skills)) {\n const n = strName(skill.name);\n if (n) skillsByName.set(n, skill);\n }\n\n const agents = asArray(stack.agents);\n for (let ai = 0; ai < agents.length; ai++) {\n const agent = agents[ai];\n const agentName = strName(agent.name) ?? `#${ai}`;\n const agentSurface = surfaceOf(agent.surface);\n const skillRefs = Array.isArray(agent.skills) ? agent.skills : [];\n\n for (let si = 0; si < skillRefs.length; si++) {\n const ref = strName(skillRefs[si]);\n if (!ref) continue;\n const skill = skillsByName.get(ref);\n // Unresolved in-stack → runtime-registered kernel skill or another\n // package's — out of this rule's scope (see header; #3820 D0/D2).\n if (!skill) continue;\n\n const skillSurface = surfaceOf(skill.surface);\n if (skillSurface === 'both' || skillSurface === agentSurface) continue;\n\n findings.push({\n severity: 'error',\n rule: AI_SKILL_SURFACE_MISMATCH,\n where: `agent \"${agentName}\" · skills`,\n path: `agents[${ai}].skills[${si}]`,\n message:\n `Agent \"${agentName}\" (surface: '${agentSurface}') references skill \"${ref}\" ` +\n `(surface: '${skillSurface}') — incompatible affinity (ADR-0064 §3). The runtime ` +\n `refuses this binding with a load error, so chatting with this agent fails at ` +\n `request time even though the stack parses and validates cleanly.`,\n hint:\n `A skill may only attach to an agent whose surface it matches. Move \"${ref}\" to a ` +\n `'${skillSurface}'-surface agent, change its \\`surface\\` to '${agentSurface}', or — ` +\n `only if it is a genuinely shared, read-only capability — declare \\`surface: 'both'\\`.`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0109 / issue #3820 R7] `skill.tools[]` reference integrity — the tool\n * branch of the AI reference rules.\n *\n * Under ADR-0109's authoring model the DEFAULT third-party path declares no\n * tool records at all: a skill names either a platform-registered tool or an\n * auto-materialised action tool. A `skill.tools[]` entry therefore resolves\n * against, in order:\n *\n * 1. the stack's own `stack.tools[]` names (the optional refinement layer);\n * 2. `PLATFORM_PROVIDED_TOOL_NAMES` — the curated registry of tools the\n * cloud AI runtime registers at boot (spec owns the list; the owning\n * cloud packages carry the conformance tests);\n * 3. the materialised `action_<name>` family — one tool per declarative\n * action (`stack.actions` ∪ every object's `actions`), the mechanism the\n * built-in `actions_executor` subscribes to with `action_*`.\n *\n * Trailing-wildcard entries (`action_*`, `foo_*`) resolve when ANY member of\n * that universe matches the prefix.\n *\n * Severity is **warning** (ADR-0078 advisory-first ratchet), not error,\n * because the universe has a known blind spot: a runtime plugin outside the\n * registry can legitimately register tools no static analysis can see, and\n * the runtime deliberately tolerates unresolved names (skills may be authored\n * before their tools exist — `skill-registry.ts`). What the warning buys: the\n * HotCRM failure — 10 fictional tools across 6 skills, every one shipping\n * through `validate`/`lint` clean and surfacing as a copilot that claims\n * abilities it does not have — now surfaces at authoring time. On that same\n * corpus the resolution ladder above yields exactly 10 findings and 0 false\n * positives (6 references resolve via the registry).\n */\n\nimport { PLATFORM_PROVIDED_TOOL_NAMES, PLATFORM_TOOL_FAMILY_PREFIXES } from '@objectstack/spec/system';\n\nexport const AI_SKILL_TOOL_UNRESOLVED = 'ai-skill-tool-unresolved';\n\nexport type AiToolRefSeverity = 'error' | 'warning';\n\nexport interface AiToolRefFinding {\n /** Always `warning` — see the header for why this rule starts advisory. */\n severity: AiToolRefSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `skill \"revenue_forecasting\" · tools`. */\n where: string;\n /** Config path, e.g. `skills[3].tools[1]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v.filter((x): x is AnyRec => !!x && typeof x === 'object');\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\nfunction distance(a: string, b: string): number {\n const m = a.length;\n const n = b.length;\n if (m === 0) return n;\n if (n === 0) return m;\n let prev = Array.from({ length: n + 1 }, (_, j) => j);\n for (let i = 1; i <= m; i++) {\n const curr = [i, ...new Array<number>(n).fill(0)];\n for (let j = 1; j <= n; j++) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1;\n curr[j] = Math.min(curr[j - 1] + 1, prev[j] + 1, prev[j - 1] + cost);\n }\n prev = curr;\n }\n return prev[n];\n}\n\nfunction suggest(target: string, known: Set<string>): string {\n // The high-frequency near-miss first: naming the raw ACTION where the\n // materialised TOOL (`action_<name>`) is meant. Edit distance cannot catch\n // it (the prefix alone is 7 edits), and it is exactly the mistake the\n // ADR-0109 default path invites from authors who know their action names.\n for (const prefix of PLATFORM_TOOL_FAMILY_PREFIXES) {\n if (known.has(`${prefix}${target}`)) return ` Did you mean \"${prefix}${target}\"?`;\n }\n\n let best: string | undefined;\n let bestScore = Infinity;\n for (const candidate of known) {\n const d = distance(target, candidate);\n if (d < bestScore) {\n bestScore = d;\n best = candidate;\n }\n }\n const limit = Math.max(2, Math.floor(target.length / 3));\n return best && bestScore <= limit ? ` Did you mean \"${best}\"?` : '';\n}\n\n/**\n * Action types with a headless invocation path. `url`/`modal`/`form` are\n * Studio-only UI types — the runtime never materialises a tool for them\n * because there is nothing to call without the UI collecting input first.\n */\nconst HEADLESS_ACTION_TYPES = new Set(['script', 'api', 'flow']);\n\n/**\n * Would the runtime materialise an `action_<name>` tool for this action?\n *\n * Mirrors the STATIC half of the runtime's `actionSkipReason` (ADR-0011\n * opt-in + the headless-path checks). The runtime additionally checks\n * service wiring (is the automation service up?), which is not knowable at\n * authoring time and is deliberately not modelled here — this predicate is\n * about \"did the author wire it\", not \"is the server configured\".\n *\n * Getting this wrong in the permissive direction is worse than having no\n * rule: an author who names `action_foo` for a `type:'modal'` action would\n * be told the reference resolves, and would ship a skill whose instructions\n * promise a capability the agent can never call — the exact failure this\n * rule exists to catch.\n */\nfunction materialisesAsTool(action: AnyRec): boolean {\n const ai = action.ai;\n if (!ai || typeof ai !== 'object') return false;\n const aiRec = ai as AnyRec;\n // ADR-0011 — opt-in, and `description` is the LLM-facing contract the\n // spec requires whenever `exposed` is true.\n if (aiRec.exposed !== true) return false;\n if (!strName(aiRec.description)) return false;\n\n const type = strName(action.type);\n if (!type || !HEADLESS_ACTION_TYPES.has(type)) return false;\n // `script` can carry either a named handler or an inline body; `api` and\n // `flow` are dispatched by target.\n if (type === 'script') return Boolean(action.target || action.body);\n return Boolean(action.target);\n}\n\n/**\n * The full set of tool names resolvable from this stack: declared tool\n * records ∪ the platform registry ∪ the materialised action family.\n */\nfunction collectToolUniverse(stack: AnyRec): Set<string> {\n const universe = new Set<string>(PLATFORM_PROVIDED_TOOL_NAMES);\n\n for (const tool of asArray(stack.tools)) {\n const n = strName(tool.name);\n if (n) universe.add(n);\n }\n\n const addActionFamily = (actions: unknown) => {\n for (const action of asArray(actions)) {\n const n = strName(action.name);\n if (n && materialisesAsTool(action)) universe.add(`action_${n}`);\n }\n };\n addActionFamily(stack.actions);\n for (const obj of asArray(stack.objects)) {\n addActionFamily(obj.actions);\n }\n\n return universe;\n}\n\n/**\n * Actions that exist but are NOT AI-exposed, for the near-miss hint: naming\n * `action_foo` when `foo` exists but never materialises is a different\n * mistake from naming something fictional, and deserves a different fix.\n */\nfunction collectUnexposedActionNames(stack: AnyRec): Set<string> {\n const names = new Set<string>();\n const scan = (actions: unknown) => {\n for (const action of asArray(actions)) {\n const n = strName(action.name);\n if (n && !materialisesAsTool(action)) names.add(n);\n }\n };\n scan(stack.actions);\n for (const obj of asArray(stack.objects)) scan(obj.actions);\n return names;\n}\n\n/**\n * Validate every `skill.tools[]` reference in a stack. Returns findings\n * (empty = clean).\n */\nexport function validateAiToolReferences(stack: AnyRec): AiToolRefFinding[] {\n const findings: AiToolRefFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const universe = collectToolUniverse(stack);\n const unexposedActions = collectUnexposedActionNames(stack);\n\n const resolves = (ref: string): boolean => {\n if (ref.endsWith('*')) {\n const prefix = ref.slice(0, -1);\n for (const name of universe) {\n if (name.startsWith(prefix)) return true;\n }\n return false;\n }\n return universe.has(ref);\n };\n\n const skills = asArray(stack.skills);\n for (let si = 0; si < skills.length; si++) {\n const skill = skills[si];\n const skillName = strName(skill.name) ?? `#${si}`;\n const refs = Array.isArray(skill.tools) ? skill.tools : [];\n\n for (let ti = 0; ti < refs.length; ti++) {\n const ref = strName(refs[ti]);\n if (!ref || resolves(ref)) continue;\n\n const isPattern = ref.endsWith('*');\n // The distinct, high-frequency case: the action EXISTS but never\n // materialises. \"Fictional name\" and \"real action that isn't exposed\"\n // need different fixes, so they get different messages.\n const unexposed =\n !isPattern && ref.startsWith('action_') && unexposedActions.has(ref.slice('action_'.length))\n ? ref.slice('action_'.length)\n : undefined;\n\n findings.push({\n severity: 'warning',\n rule: AI_SKILL_TOOL_UNRESOLVED,\n where: `skill \"${skillName}\" · tools`,\n path: `skills[${si}].tools[${ti}]`,\n message: isPattern\n ? `Skill \"${skillName}\" subscribes to tool family \"${ref}\", which matches nothing this ` +\n `stack can resolve (no declared tool, no platform tool, and no AI-exposed declarative ` +\n `action materialises into it). The subscription contributes zero tools at runtime.`\n : unexposed\n ? `Skill \"${skillName}\" references tool \"${ref}\", but the action \"${unexposed}\" does ` +\n `not become an AI tool: the runtime materialises \\`action_<name>\\` only for an ` +\n `action that opts in with \\`ai.exposed: true\\` + \\`ai.description\\` (ADR-0011) AND ` +\n `has a headless path (type \\`script\\`/\\`api\\`/\\`flow\\` with a target or body — ` +\n `\\`url\\`/\\`modal\\`/\\`form\\` are UI-only). The reference is dropped at runtime, so ` +\n `the skill promises a capability the agent cannot call.`\n : `Skill \"${skillName}\" references tool \"${ref}\", which resolves to nothing this stack ` +\n `can see: not a \\`stack.tools\\` record, not a platform-registered tool, and not a ` +\n `materialised action tool (\\`action_<name>\\`). The runtime silently drops the ` +\n `reference, so the skill's instructions claim a capability the agent does not have — ` +\n `the assistant will improvise or fail when asked to use it.` +\n suggest(ref, universe),\n hint: unexposed\n ? `Either opt \"${unexposed}\" in — set \\`ai: { exposed: true, description: '…' }\\` (≥40 ` +\n `chars, LLM-facing) and give it a headless type — or drop the reference and have the ` +\n `skill's instructions recommend the UI action instead. A \\`modal\\`/\\`form\\`/\\`url\\` ` +\n `action stays human-driven by design; that is a legitimate answer, not a gap.`\n : `Back \"${ref}\" with a real executable: declare a declarative action (or flow), opt it ` +\n `in with \\`ai.exposed: true\\` + \\`ai.description\\`, and reference its materialised ` +\n `tool (\\`action_<name>\\` — the ADR-0109 default path, no tool record needed); or ` +\n `reference a platform tool by its registered name; or remove the reference and the ` +\n `instructions that mention it. Ignore this only if a runtime plugin outside the ` +\n `platform registry provides \"${ref}\". Family prefixes materialised by the runtime: ` +\n `${PLATFORM_TOOL_FAMILY_PREFIXES.join(', ')}.`,\n });\n }\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * [ADR-0063 §2] `stack.agents` is a platform-internal slot (issue #3820).\n *\n * ADR-0063 §2 withdrew tenant/app-package custom agents: the kernel ships\n * exactly two agents (`ask`, `build`), the surface the user is in binds one,\n * and third parties extend the platform by authoring **skills**, never\n * `*.agent.ts`. The `agent` metadata type carries the decision\n * (`allowRuntimeCreate: false, allowOrgOverride: false`), and the runtime\n * enforces it on both paths — `listAgents()` filters non-platform records out\n * of the catalog, and `loadAgent()` refuses them outright (cloud#904), so a\n * stack-authored agent 404s on chat and cannot be pinned via\n * `app.defaultAgent`.\n *\n * What was missing is the AUTHORING-time signal. `defineStack` still accepts\n * an `agents` array, so an app package could declare agents that parse,\n * validate, and build into the artifact — and then do nothing at runtime.\n * HotCRM shipped two of them for months. That is the ADR-0078 shape this rule\n * closes: loud at the producer, tolerant at the consumer (Prime Directive\n * #12).\n *\n * Severity is **warning**, not error, for one reason: the platform's own\n * packages legitimately author agent records, and this rule cannot tell a\n * platform package from an app package by reading the stack alone. A warning\n * that names the runtime consequence is honest for both readers; the runtime\n * is what actually gates. Deliberately NOT a Zod refine — an existing stack\n * must keep parsing (ADR-0078 non-goal #1).\n */\n\nexport const AGENT_AUTHORING_WITHDRAWN = 'agent-authoring-withdrawn';\n\nexport type AiAgentAuthoringSeverity = 'error' | 'warning';\n\nexport interface AiAgentAuthoringFinding {\n /** Always `warning` — the runtime is the gate; this is the authoring-time signal. */\n severity: AiAgentAuthoringSeverity;\n /** Diagnostic rule id. */\n rule: string;\n /** Human-readable location, e.g. `agent \"sales_copilot\"`. */\n where: string;\n /** Config path, e.g. `agents[0]`. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\ntype AnyRec = Record<string, unknown>;\n\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v.filter((x): x is AnyRec => !!x && typeof x === 'object');\n if (v && typeof v === 'object') {\n return Object.entries(v as AnyRec).map(([name, def]) => ({ name, ...(def as AnyRec) }));\n }\n return [];\n}\n\nfunction strName(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined;\n}\n\n/**\n * The two platform agent ids. A stack that re-declares one of these is doing\n * something different from inventing a custom persona (it is shadowing a\n * platform record), so it gets its own wording.\n */\nconst PLATFORM_AGENT_NAMES = new Set(['ask', 'build', 'data_chat', 'metadata_assistant']);\n\n/**\n * Flag every agent declared in a stack. Returns findings (empty = clean,\n * which is what every app package should be).\n */\nexport function validateAiAgentAuthoring(stack: AnyRec): AiAgentAuthoringFinding[] {\n const findings: AiAgentAuthoringFinding[] = [];\n if (!stack || typeof stack !== 'object') return findings;\n\n const agents = asArray(stack.agents);\n for (let ai = 0; ai < agents.length; ai++) {\n const agent = agents[ai];\n const name = strName(agent.name) ?? `#${ai}`;\n const isPlatformName = PLATFORM_AGENT_NAMES.has(name);\n const skillCount = Array.isArray(agent.skills) ? agent.skills.length : 0;\n\n findings.push({\n severity: 'warning',\n rule: AGENT_AUTHORING_WITHDRAWN,\n where: `agent \"${name}\"`,\n path: `agents[${ai}]`,\n message: isPlatformName\n ? `This stack declares an agent named \"${name}\", which is a PLATFORM agent id. The ` +\n `runtime serves its own record for that name and ignores this one — the declaration ` +\n `has no effect and will drift from the platform's definition.`\n : `This stack declares the agent \"${name}\", but tenant/app-package agents were withdrawn ` +\n `(ADR-0063 §2): the kernel ships exactly two agents (\\`ask\\`, \\`build\\`) and the surface ` +\n `the user is in binds one. The runtime filters this record out of the agent catalog and ` +\n `refuses to load it, so it never runs — it parses, validates, and ships as inert ` +\n `metadata.`,\n hint: isPlatformName\n ? `Remove the declaration; the platform owns \"${name}\". Extend it with skills instead.`\n : `Delete the agent and express its capability as skills. Everything an agent carried ` +\n `that a skill does not is persona text: move the useful parts of \\`instructions\\` into ` +\n `the skills' own instructions.` +\n (skillCount > 0\n ? ` The ${skillCount} skill${skillCount === 1 ? '' : 's'} this agent references ` +\n `already carry the capability — they attach to the platform agent by \\`surface\\` ` +\n `affinity, so nothing is lost by dropping the persona.`\n : ``),\n });\n }\n\n return findings;\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Author-time write-set check for L2 (`language:'js'`) hook bodies (#4271).\n//\n// An L2 body that writes a field the target object never declares —\n// `ctx.input.amout = 0`, `ctx.api.object('deal').update({ stag: 'won' })` —\n// runs clean in the QuickJS sandbox and reaches the driver UNFILTERED:\n// `applyMutationsToInput` (runtime/src/sandbox/body-runner.ts) is a plain\n// `Object.assign`, and `validateRecord` walks declared fields on insert and\n// `continue`s past a key with no field def on update. What happens after that\n// is DRIVER-DEPENDENT, and neither half is acceptable:\n//\n// • SQL — the stray column enters the knex statement and the WHOLE write\n// fails with a driver-level error (`table deal has no column named\n// stagee`). The write is lost, and the error surfaces far from the\n// authoring mistake that caused it.\n// • Schemaless (memory, MongoDB) — the driver spreads the payload, so the\n// stray key IS persisted: an undeclared column nothing downstream reads.\n//\n// Either way the mistake is invisible where it is MADE — the #4001 family, if\n// not literally its silent-no-op shape. Both runtime outcomes are pinned by\n// `runtime/src/sandbox/undeclared-field-write-driver-split.integration.test.ts`\n// so this rule's wording cannot drift from what the runtime does; the same\n// split is documented in `content/docs/automation/hook-bodies.mdx`.\n//\n// The read side (`hook.condition`, ADR-0032) and the capability surface are\n// statically checked; until this rule, the write side was the one blind face\n// (the gap `hook-body.zod.ts` used to carry as \"accepted\").\n//\n// Scope — the literal write patterns in {@link HOOK_BODY_WRITE_PATTERNS}, and\n// nothing else. The body is PARSED (TypeScript parser, never executed, never\n// type-checked); each declared pattern is reconciliation-tested against the\n// extractor, so a pattern cannot be declared-but-unverified (#3528's death).\n// Everything statically unknowable is skipped SILENTLY, asymmetrically\n// favouring missed findings over false ones — a false positive kills an\n// advisory lint, a miss just leaves the gap open a little longer:\n//\n// • computed keys (`ctx.input[k] = …`), spreads, non-literal payloads;\n// • dynamic object names (`ctx.api.object(name)`);\n// • `object:'*'` wildcard hooks' `ctx.input` writes (no single target);\n// • multi-target hooks where the field exists on SOME target — the body may\n// legitimately branch per object (`if (ctx.object === '…')`), so only a\n// field missing on EVERY named target is flagged;\n// • targets declared by another package (not in this stack);\n// • one-level aliasing (`const doc = ctx.input; doc.x = 1`) — known miss,\n// deliberately: v1 does no data-flow analysis.\n//\n// Severity: always `warning` (advisory, never gates). Same posture as\n// `lintUnknownAuthoringKeys` (#3786) — ratchet only with field data.\n//\n// Wired via REFERENCE_INTEGRITY_RULES (it resolves field NAMES written in\n// metadata against what the stack declares — the suite's exact membership\n// test), so it runs on `os validate`, `os lint` and `os compile` at once.\n// Deliberately NOT in the `defineStack` runtime path: the TypeScript parser\n// has no place on kernel boot (see the lazy-load contract below).\n//\n// ACTION bodies run through the same `HookBodySchema` and the same sandbox, so\n// they get the same treatment from a sibling rule — `validate-action-body-\n// writes.ts`, which reuses this module's extractor, ledger, field index and\n// implicit-field set. It carries only the pattern subset that survives the\n// context change (an action's `ctx.input` is its params bag, not a record);\n// the reasoning is declared as data there, not restated here.\n\nimport { createRequire } from 'node:module';\nimport type ts from 'typescript';\nimport { findClosestMatches, formatSuggestion } from '@objectstack/spec/shared';\n\nimport { SYSTEM_FIELDS } from './system-fields.js';\n\n// The TypeScript compiler must NOT be imported at module top level: it is\n// ~9 MB of CJS, and @objectstack/lint sits on the kernel boot path — while\n// this gate only parses when a hook actually carries an L2 JS body. Same\n// lazy-load contract as validate-react-page-props.ts (which see for the\n// history, including production images pruning the package). Guarded by\n// lazy-deps.test.ts.\n//\n// `node:module` is a Node builtin, untouched by esbuild/tsup, so the static\n// `createRequire` import survives bundling; the `createRequire(...)` call is\n// deferred because `import.meta.url` is rewritten to an empty stub in the CJS\n// build (same pattern as driver-sqlite-wasm's knex-wasm-dialect).\nlet cachedTs: typeof ts | null = null;\nfunction loadTypeScript(): typeof ts {\n if (cachedTs) return cachedTs;\n const anchor =\n typeof import.meta !== 'undefined' && import.meta.url\n ? import.meta.url\n : typeof __filename !== 'undefined'\n ? __filename\n : process.cwd() + '/';\n try {\n cachedTs = createRequire(anchor)('typescript') as typeof ts;\n } catch (err) {\n throw new Error(\n `@objectstack/lint: checking an L2 (language:'js') hook body requires the \"typescript\" package, which could not ` +\n `be loaded (${err instanceof Error ? err.message : String(err)}). It is a declared dependency of ` +\n `@objectstack/lint — if this deployment prunes packages, keep \"typescript\" in the image; it is only loaded ` +\n `when a hook with a JS body is validated.`,\n );\n }\n return cachedTs;\n}\n\nexport type HookBodyWriteSeverity = 'warning';\n\nexport interface HookBodyWriteFinding {\n /** v1 is advisory-only by contract — the type says so. */\n severity: HookBodyWriteSeverity;\n rule: string;\n /** Human-readable location, e.g. `hook \"normalize_lead\" › body`. */\n where: string;\n /** Config path, e.g. `hooks[0].body.source`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const HOOK_BODY_WRITE_UNKNOWN_FIELD = 'hook-body-write-unknown-field';\n\n// ─── The write-pattern ledger ───────────────────────────────────────────────\n//\n// Every syntactic write shape the extractor recognizes, declared as data. The\n// reconciliation test (validate-hook-body-writes.test.ts) runs the extractor\n// over each entry's example and asserts it yields EXACTLY the declared writes,\n// each tagged with this entry's id — so \"the docs say this pattern is covered\n// but nothing extracts it\" cannot happen (#3528), and the answer to \"which\n// writes does the lint see?\" is this list, not the extractor's code.\n\n/** One syntactic write shape the extractor recognizes. */\nexport interface HookBodyWritePattern {\n /** Stable pattern id, carried on every extracted write. */\n readonly id: string;\n /** Author-facing syntax summary (for docs/diagnostics, not matching). */\n readonly syntax: string;\n /** Reconciliation fixture: extracting `source` must yield exactly `writes`. */\n readonly example: {\n readonly source: string;\n readonly writes: ReadonlyArray<{ field: string; object?: string }>;\n };\n}\n\nexport const HOOK_BODY_WRITE_PATTERNS: readonly HookBodyWritePattern[] = [\n {\n id: 'input-property-assign',\n syntax: \"ctx.input.<field> = … | ctx.input['<field>'] ⟨op⟩= …\",\n example: {\n // Compound (`+=`) and logical (`??=`) assignment operators write their\n // LHS exactly like `=` does — the example pins the whole operator range.\n source: \"ctx.input.total = 0; ctx.input['status'] ??= 'open'; ctx.input.retries += 1;\",\n writes: [{ field: 'total' }, { field: 'status' }, { field: 'retries' }],\n },\n },\n {\n id: 'input-object-assign',\n syntax: 'Object.assign(ctx.input, { <field>: … })',\n example: {\n source: \"Object.assign(ctx.input, { total: 5, 'status': 'open', discount });\",\n writes: [{ field: 'total' }, { field: 'status' }, { field: 'discount' }],\n },\n },\n {\n // ACTION-only shape (the hook sandbox context has no `ctx.record` at all).\n // Declared here because this ledger is the extractor's shape inventory, not\n // any one rule's; every consumer declares which shapes it consumes.\n id: 'record-property-assign',\n syntax: \"ctx.record.<field> = … | ctx.record['<field>'] ⟨op⟩= …\",\n example: {\n source: \"ctx.record.stage = 'won'; ctx.record['amount'] += 1;\",\n writes: [{ field: 'stage' }, { field: 'amount' }],\n },\n },\n {\n id: 'api-crud-literal',\n syntax:\n \"ctx.api.object('<object>').insert({…}) | .create({…}) | .update({…}) | .updateById(id, {…})\",\n example: {\n // Real ObjectRepository signatures: the record payload is argument 0 for\n // insert/create/update and argument 1 for updateById. (`update(data)` —\n // NOT `update(id, data)`; the id travels inside the payload/options.)\n source:\n \"await ctx.api.object('audit_log').insert({ event: 'won' }); \" +\n \"await ctx.api.object('crm_deal').updateById(id, { stage: 'won' });\",\n writes: [\n { field: 'event', object: 'audit_log' },\n { field: 'stage', object: 'crm_deal' },\n ],\n },\n },\n];\n\n/** A ledger pattern a given rule does NOT consume, and why. */\nexport interface BodyWritePatternExclusion {\n /** The {@link HOOK_BODY_WRITE_PATTERNS} entry id being excluded. */\n readonly id: string;\n /** Why the shape does not mean the same thing on this rule's surface. */\n readonly reason: string;\n}\n\n/**\n * The ledger shapes THIS rule consumes.\n *\n * Declared rather than implied: before the ledger carried a shape the hook\n * surface does not have, every write with no `object` was necessarily a\n * `ctx.input` write, and the rule could branch on that alone. It no longer can\n * — a `record-property-assign` write also carries no object, and would have\n * been reported as \"the hook writes 'stage' to its input\", which is false.\n * Each consumer declaring its own subset is what stops the next added shape\n * from silently landing in a branch that was never written for it.\n */\nexport const HOOK_BODY_WRITE_PATTERN_IDS: readonly string[] = [\n 'input-property-assign',\n 'input-object-assign',\n 'api-crud-literal',\n];\n\n/** Ledger shapes this rule leaves alone, each with its reason. */\nexport const HOOK_BODY_WRITE_EXCLUSIONS: readonly BodyWritePatternExclusion[] = [\n {\n id: 'record-property-assign',\n reason:\n 'a hook sandbox context has no `ctx.record` at all — `buildSandboxContext` never sets it (a hook’s ' +\n 'record IS `ctx.input`), so the expression throws at run time rather than silently no-op’ing. A loud ' +\n 'failure the author sees on the first run is not this advisory rule’s business',\n },\n];\n\nconst HOOK_APPLICABLE_IDS: ReadonlySet<string> = new Set(HOOK_BODY_WRITE_PATTERN_IDS);\n\n/**\n * `ctx.api.object(name)` write methods → index of the record-payload argument.\n * Mirrors `ObjectRepository` in packages/objectql (the surface hooks actually\n * receive): `upsert` exists only on the last-resort engine facade actions may\n * fall back to, never on the hook path, so it is deliberately absent.\n */\nconst API_WRITE_METHODS: ReadonlyMap<string, number> = new Map([\n ['insert', 0],\n ['create', 0],\n ['update', 0],\n ['updateById', 1],\n]);\n\n/**\n * Wrapper keys of the flat-input proxy (`installFlatInput` in\n * packages/objectql/src/hook-wrappers.ts). `ctx.input.data = …` replaces the\n * whole record payload and `id`/`options`/`ast` address the operation\n * envelope — none is a record-FIELD write, so none is ever flagged.\n */\nconst INPUT_ENVELOPE_KEYS: ReadonlySet<string> = new Set(['id', 'options', 'ast', 'data']);\n\n/**\n * Columns always legitimately writable by automation without appearing in\n * `object.fields`: the package-shared registry-injected columns\n * (`system-fields.ts`, #4330) plus the UNION of its sibling rules' local\n * exemptions (`_id`/`name`/`space` from validate-translation-references,\n * `name`/`owner`/`record_type` from validate-flow-template-paths) — because\n * the cost asymmetry is the same everywhere: over-inclusion is at worst a\n * missed finding, under-inclusion is a false one.\n *\n * Exported for `validate-action-body-writes.ts` only (not re-exported from the\n * package barrel). The action rule is this same check on the other surface that\n * carries a `HookBodySchema` body, so the two must agree on what is implicitly\n * writable — a second copy of this extension would drift exactly the way the\n * five hand-copied lists #4330 collapsed did.\n */\nexport const IMPLICIT_FIELDS: ReadonlySet<string> = new Set([\n ...SYSTEM_FIELDS,\n '_id', 'name', 'space', 'owner', 'record_type',\n]);\n\ntype AnyRec = Record<string, unknown>;\n\nconst isRec = (v: unknown): v is AnyRec => !!v && typeof v === 'object' && !Array.isArray(v);\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v.filter((x): x is AnyRec => isRec(x));\n if (isRec(v)) {\n return Object.entries(v).map(([name, def]) => ({\n name,\n ...(isRec(def) ? def : {}),\n }));\n }\n return [];\n}\n\n/**\n * object name → its declared field names (both `fields` authoring shapes).\n *\n * Exported for `validate-action-body-writes.ts` only (see\n * {@link IMPLICIT_FIELDS} for why the two rules share rather than copy).\n */\nexport function indexObjectFields(stack: AnyRec): Map<string, Set<string>> {\n const out = new Map<string, Set<string>>();\n for (const obj of asArray(stack.objects)) {\n const name = typeof obj.name === 'string' ? obj.name : undefined;\n if (!name) continue;\n const names = new Set<string>();\n for (const f of asArray(obj.fields)) {\n if (typeof f.name === 'string' && f.name) names.add(f.name);\n }\n out.set(name, names);\n }\n return out;\n}\n\n/**\n * The declared field names of `objectName` — but ONLY when they are a sound\n * basis for judging \"this name resolves to nothing\". Otherwise `undefined`.\n *\n * Two different unknowns collapse to one answer on purpose, because every\n * caller in this family owes them the same silence:\n *\n * • the object is not in this stack — another package declares it, and a\n * field map we cannot see cannot be judged;\n * • the object is here but declares NO fields at all — an external object or\n * a datasource-introspected schema whose columns are resolved at runtime.\n * Its field map is not empty, it is *unknown*, and an empty Set answers\n * `has(anything) === false`, which reads as \"no such field\" for EVERY write\n * to it. That is a false-positive generator, and a false positive kills an\n * advisory lint (#4383).\n *\n * The distinction is unused today — no rule in the family wants to act on one\n * and not the other — so collapsing it here is what stops the guard from being\n * hand-copied per call site and forgotten at one of them, which is exactly how\n * it went missing from the hook and action rules while\n * `validate-searchable-fields` (skip #2) and `validate-flow-node-writes` both\n * had it. A future caller that genuinely needs to tell them apart should read\n * the index directly and say why.\n */\nexport function judgeableFieldsOf(\n index: ReadonlyMap<string, Set<string>>,\n objectName: string,\n): Set<string> | undefined {\n const declared = index.get(objectName);\n if (!declared || declared.size === 0) return undefined;\n return declared;\n}\n\n/** One statically-extracted field write found in an L2 body. */\nexport interface ExtractedHookBodyWrite {\n /** Which {@link HOOK_BODY_WRITE_PATTERNS} entry matched. */\n patternId: string;\n /** Target object name; `undefined` = the hook's own target object(s). */\n object?: string;\n /** The `ctx.api` method for diagnostics (`insert`/`create`/`update`/`updateById`). */\n method?: string;\n field: string;\n}\n\n/** Everything one parse of an L2 body yields. */\nexport interface ExtractedHookBodyWriteSet {\n /** Every literal write the {@link HOOK_BODY_WRITE_PATTERNS} ledger declares. */\n writes: ExtractedHookBodyWrite[];\n /**\n * `ctx.record` is handed to something as a VALUE somewhere in the body — an\n * argument, an assignment RHS, a spread, a return — rather than only having\n * its properties read and written, or being truthiness/type tested.\n *\n * The action rule needs this to tell a dead snapshot write from a live one:\n * `ctx.record.stage = 'won'; await ctx.api.object('d').update(ctx.record)`\n * builds a payload and persists it, so the assignment is not a no-op. When\n * this is true, no record write in the body can be judged, and none is\n * reported. (One-level aliasing — `const r = ctx.record` — reads as an\n * escape too, which is the safe direction: it suppresses findings.)\n */\n ctxRecordEscapes: boolean;\n}\n\n/**\n * Extract every literal field write the pattern ledger declares from an L2\n * body's source. Parse-only (the source is never executed), error-tolerant\n * (a body with syntax errors simply yields fewer matches), and lazy: the\n * TypeScript compiler is not loaded when no pattern can possibly match.\n *\n * Thin projection of {@link extractHookBodyWriteSet} — use that one when the\n * `ctx.record` liveness signal matters, so the body is parsed once, not twice.\n */\nexport function extractHookBodyWrites(source: string): ExtractedHookBodyWrite[] {\n return extractHookBodyWriteSet(source).writes;\n}\n\n/** {@link extractHookBodyWrites} plus the `ctx.record` liveness signal, one parse. */\nexport function extractHookBodyWriteSet(source: string): ExtractedHookBodyWriteSet {\n // Every recognizable pattern begins at a `ctx` or `Object` identifier — a\n // body containing neither cannot match, and must not pay the compiler load.\n if (!/\\bctx\\b/.test(source) && !/\\bObject\\b/.test(source)) {\n return { writes: [], ctxRecordEscapes: false };\n }\n\n const tsc = loadTypeScript();\n // The runtime wraps a hook body as `new AsyncFunction('ctx', source)` — a\n // FUNCTION BODY, not a module. Parse it in the same context so bare\n // `return` / `await` mean what they mean at run time.\n const sf = tsc.createSourceFile(\n 'hook-body.ts',\n `async function __body(ctx) {\\n${source}\\n}`,\n tsc.ScriptTarget.Latest,\n /* setParentNodes */ false,\n tsc.ScriptKind.TS,\n );\n\n const writes: ExtractedHookBodyWrite[] = [];\n /** Every `ctx.record` reference, and the subset that is only an access base. */\n const recordRefs: ts.Node[] = [];\n const consumedRecordRefs = new Set<ts.Node>();\n\n /** `node` is exactly `ctx.<prop>`. */\n const isCtxDot = (node: ts.Node, prop: string): boolean =>\n tsc.isPropertyAccessExpression(node) &&\n tsc.isIdentifier(node.expression) &&\n node.expression.text === 'ctx' &&\n node.name.text === prop;\n\n /** The literal field name of an LHS rooted at `ctx.<prop>`, if any. */\n const fieldOfCtxLhs = (lhs: ts.Expression, prop: string): string | undefined => {\n if (tsc.isPropertyAccessExpression(lhs) && tsc.isIdentifier(lhs.name) && isCtxDot(lhs.expression, prop)) {\n return lhs.name.text;\n }\n if (tsc.isElementAccessExpression(lhs) && isCtxDot(lhs.expression, prop)) {\n const arg = lhs.argumentExpression;\n if (tsc.isStringLiteral(arg) || tsc.isNoSubstitutionTemplateLiteral(arg)) return arg.text;\n }\n return undefined; // computed key / nested path — statically opaque\n };\n\n /** Literal keys of an object-literal expression (spreads/computed skipped). */\n const literalObjectKeys = (node: ts.Expression): string[] => {\n if (!tsc.isObjectLiteralExpression(node)) return [];\n const keys: string[] = [];\n for (const p of node.properties) {\n if (tsc.isPropertyAssignment(p)) {\n if (tsc.isIdentifier(p.name) || tsc.isStringLiteral(p.name)) keys.push(p.name.text);\n } else if (tsc.isShorthandPropertyAssignment(p)) {\n keys.push(p.name.text);\n }\n // spread / computed / method members are statically opaque — skipped\n }\n return keys;\n };\n\n const visit = (node: ts.Node): void => {\n // Pattern: input-property-assign. FirstAssignment..LastAssignment spans\n // `=` and every compound/logical assignment operator (`+=`, `??=`, …) —\n // each writes its LHS.\n if (\n tsc.isBinaryExpression(node) &&\n node.operatorToken.kind >= tsc.SyntaxKind.FirstAssignment &&\n node.operatorToken.kind <= tsc.SyntaxKind.LastAssignment\n ) {\n const inputField = fieldOfCtxLhs(node.left, 'input');\n if (inputField !== undefined && !INPUT_ENVELOPE_KEYS.has(inputField)) {\n writes.push({ patternId: 'input-property-assign', field: inputField });\n }\n // Pattern: record-property-assign. No envelope-key filter — `ctx.record`\n // is a plain snapshot of the record, not the flat-input proxy, so it\n // carries no operation envelope to exclude.\n const recordField = fieldOfCtxLhs(node.left, 'record');\n if (recordField !== undefined) {\n writes.push({ patternId: 'record-property-assign', field: recordField });\n }\n }\n\n // `ctx.record` liveness, for the rule that judges whether a record write\n // can possibly matter. A reference is CONSUMED when the position it sits in\n // cannot hand the object to anything that might persist it; every other\n // position — an argument, an assignment RHS, a spread, a return — can.\n //\n // 1. the base of a property/element access: `ctx.record.id`,\n // `ctx.record.x = 1`, `ctx.record['k']`;\n // 2. a truthiness or type test. `ctx.record && ctx.record.id` is the\n // defensive idiom real action bodies are written with (the showcase's\n // own `mark_done` opens with it), and reading a test as an escape\n // would suppress the finding on most bodies that have one. A test\n // reads the reference and yields a boolean — or, for `&&`/`||`/`??`,\n // yields the LEFT operand only when it is falsy, which is null or\n // undefined and persists nothing either way. Only the left operand is\n // a test: `x || ctx.record` really does evaluate to the object.\n if (tsc.isPropertyAccessExpression(node) || tsc.isElementAccessExpression(node)) {\n if (isCtxDot(node.expression, 'record')) consumedRecordRefs.add(node.expression);\n }\n if (tsc.isBinaryExpression(node)) {\n const op = node.operatorToken.kind;\n if (\n (op === tsc.SyntaxKind.AmpersandAmpersandToken ||\n op === tsc.SyntaxKind.BarBarToken ||\n op === tsc.SyntaxKind.QuestionQuestionToken) &&\n isCtxDot(node.left, 'record')\n ) {\n consumedRecordRefs.add(node.left);\n }\n }\n if (tsc.isPrefixUnaryExpression(node) && node.operator === tsc.SyntaxKind.ExclamationToken) {\n if (isCtxDot(node.operand, 'record')) consumedRecordRefs.add(node.operand);\n }\n if (tsc.isTypeOfExpression(node) && isCtxDot(node.expression, 'record')) {\n consumedRecordRefs.add(node.expression);\n }\n if (\n (tsc.isIfStatement(node) || tsc.isWhileStatement(node) || tsc.isDoStatement(node)) &&\n isCtxDot(node.expression, 'record')\n ) {\n consumedRecordRefs.add(node.expression);\n }\n if (tsc.isConditionalExpression(node) && isCtxDot(node.condition, 'record')) {\n consumedRecordRefs.add(node.condition);\n }\n if (isCtxDot(node, 'record')) recordRefs.push(node);\n\n if (tsc.isCallExpression(node)) {\n const callee = node.expression;\n\n // Pattern: input-object-assign.\n if (\n tsc.isPropertyAccessExpression(callee) &&\n tsc.isIdentifier(callee.expression) &&\n callee.expression.text === 'Object' &&\n callee.name.text === 'assign' &&\n node.arguments.length >= 2 &&\n isCtxDot(node.arguments[0], 'input')\n ) {\n // Later Object.assign sources overwrite earlier ones but never remove\n // a key, so every literal key is genuinely written regardless of the\n // non-literal arguments around it.\n for (const arg of node.arguments.slice(1)) {\n for (const field of literalObjectKeys(arg)) {\n if (!INPUT_ENVELOPE_KEYS.has(field)) {\n writes.push({ patternId: 'input-object-assign', field });\n }\n }\n }\n }\n\n // Pattern: api-crud-literal — ctx.api.object('<lit>').<method>(payload…).\n if (tsc.isPropertyAccessExpression(callee) && tsc.isIdentifier(callee.name)) {\n const payloadIndex = API_WRITE_METHODS.get(callee.name.text);\n const recv = callee.expression;\n if (\n payloadIndex !== undefined &&\n tsc.isCallExpression(recv) &&\n tsc.isPropertyAccessExpression(recv.expression) &&\n recv.expression.name.text === 'object' &&\n isCtxDot(recv.expression.expression, 'api') &&\n recv.arguments.length === 1\n ) {\n const objArg = recv.arguments[0];\n const objectName =\n tsc.isStringLiteral(objArg) || tsc.isNoSubstitutionTemplateLiteral(objArg)\n ? objArg.text\n : undefined; // dynamic object name — statically opaque\n const payload = node.arguments[payloadIndex];\n if (objectName && payload !== undefined) {\n for (const field of literalObjectKeys(payload)) {\n writes.push({\n patternId: 'api-crud-literal',\n object: objectName,\n method: callee.name.text,\n field,\n });\n }\n }\n }\n }\n }\n\n tsc.forEachChild(node, visit);\n };\n visit(sf);\n return {\n writes,\n ctxRecordEscapes: recordRefs.some((ref) => !consumedRecordRefs.has(ref)),\n };\n}\n\n/**\n * Validate L2 hook-body writes against target-object field declarations.\n * Pure `(stack) => Finding[]` (ADR-0019); safe on pre- or post-parse stacks.\n */\nexport function validateHookBodyWrites(stack: AnyRec): HookBodyWriteFinding[] {\n const findings: HookBodyWriteFinding[] = [];\n const hooks = asArray(stack.hooks);\n if (hooks.length === 0) return findings;\n\n // Built lazily: a stack whose hooks are all L1/handler-based never pays it.\n let objectFields: Map<string, Set<string>> | null = null;\n\n hooks.forEach((hook, hookIndex) => {\n const body = hook.body;\n if (!isRec(body) || body.language !== 'js') return;\n const source = body.source;\n if (typeof source !== 'string' || source.trim() === '') return;\n\n const writes = extractHookBodyWrites(source).filter((w) => HOOK_APPLICABLE_IDS.has(w.patternId));\n if (writes.length === 0) return;\n\n objectFields ??= indexObjectFields(stack);\n const hookName = typeof hook.name === 'string' && hook.name ? hook.name : `#${hookIndex}`;\n\n // The hook's own target set, for `ctx.input` writes. A wildcard target has\n // no single object to check against; a target whose fields cannot be judged\n // ({@link judgeableFieldsOf} — cross-package, or declaring no fields at all)\n // gives nothing to resolve against — either way `ctx.input` writes are\n // skipped, not guessed.\n const targets = (Array.isArray(hook.object) ? hook.object : [hook.object]).filter(\n (o): o is string => typeof o === 'string' && o.trim() !== '',\n );\n const targetSets = targets.map((t) => judgeableFieldsOf(objectFields!, t));\n // ALL targets must be judgeable, not just one: the finding below fires only\n // when a field is missing from EVERY target, and an unjudgeable target is\n // one the field might well exist on. One opaque target therefore makes the\n // whole \"missing everywhere\" claim unsound, not merely narrower (#4383).\n const inputJudgeable =\n targets.length > 0 && !targets.includes('*') && targetSets.every((s) => s !== undefined);\n\n const where = `hook \"${hookName}\" › body`;\n const path = `hooks[${hookIndex}].body.source`;\n const reported = new Set<string>();\n\n for (const w of writes) {\n const dedupeKey = `${w.object ?? ''}\\u0000${w.field}`;\n if (reported.has(dedupeKey)) continue;\n\n if (w.object === undefined) {\n // ctx.input write → the hook's own object(s). Flag only a field\n // missing on EVERY named target (a multi-target body may branch per\n // object, so a partial miss is not statically wrong).\n if (!inputJudgeable) continue;\n if (IMPLICIT_FIELDS.has(w.field)) continue;\n if (targetSets.some((s) => s!.has(w.field))) continue;\n\n reported.add(dedupeKey);\n const objDesc =\n targets.length === 1\n ? `object '${targets[0]}'`\n : `none of its target objects (${targets.join(', ')})`;\n const declares = targets.length === 1 ? 'declares no such field' : 'declare that field';\n findings.push({\n severity: 'warning',\n rule: HOOK_BODY_WRITE_UNKNOWN_FIELD,\n where,\n path,\n message:\n `body writes '${w.field}' to its input, but ${objDesc} ${declares}. The sandboxed script runs ` +\n `clean and the value is copied back onto the record payload unfiltered — on a SQL driver the ` +\n `stray column then fails the WHOLE write with a driver-level error far from here; on a ` +\n `schemaless driver (memory, MongoDB) it is persisted as an undeclared key (#4271).`,\n hint: fixHint(w.field, unionCandidates(targetSets)),\n });\n } else {\n // ctx.api write → the named object.\n const known = judgeableFieldsOf(objectFields!, w.object);\n if (!known) continue; // cross-package, or no declared fields — cannot judge\n if (IMPLICIT_FIELDS.has(w.field) || known.has(w.field)) continue;\n\n reported.add(dedupeKey);\n findings.push({\n severity: 'warning',\n rule: HOOK_BODY_WRITE_UNKNOWN_FIELD,\n where,\n path,\n message:\n `body calls ctx.api.object('${w.object}').${w.method ?? 'update'}(…) writing '${w.field}', but ` +\n `object '${w.object}' declares no such field. The write-path validator skips the unknown key — ` +\n `on a SQL driver the whole call then fails with a driver-level error far from here; on a ` +\n `schemaless driver (memory, MongoDB) the stray key is persisted (#4271).`,\n hint: fixHint(w.field, [...known]),\n });\n }\n }\n });\n\n return findings;\n}\n\n/** Every field name declared across the (all-known) target sets, deduplicated. */\nfunction unionCandidates(targetSets: ReadonlyArray<Set<string> | undefined>): string[] {\n const out = new Set<string>();\n for (const s of targetSets) for (const f of s ?? []) out.add(f);\n return [...out];\n}\n\n/** Did-you-mean (declared + system columns as candidates) plus the fix. */\nfunction fixHint(field: string, declared: string[]): string {\n const suggestion = formatSuggestion(findClosestMatches(field, [...declared, ...IMPLICIT_FIELDS]));\n return (\n (suggestion ? `${suggestion} ` : '') +\n `Fix the field name, or declare '${field}' on the object. Only the literal write patterns in ` +\n `HOOK_BODY_WRITE_PATTERNS are checked — computed keys, spreads and aliased input are not — and this ` +\n `warning never blocks a build.`\n );\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Author-time write-set check for L2 (`language:'js'`) ACTION bodies — the\n// sibling of `validate-hook-body-writes.ts` (#4271 follow-up).\n//\n// An action body is the same artefact as a hook body: the same\n// `HookBodySchema` union, parsed by the same `HookBodySchema.safeParse` in\n// `actionBodyRunnerFactory` (packages/runtime/src/sandbox/body-runner.ts), run\n// in the same QuickJS sandbox. So it fails the same way — an action body that\n// writes a field the target object never declares reaches the driver\n// unfiltered, and the outcome is DRIVER-DEPENDENT: on SQL the stray column\n// fails the whole call with a driver-level error far from the authoring\n// mistake, on a schemaless driver the stray key is persisted. Same #4271\n// split as the hook side (see that file's header for the measured chain, and\n// `undeclared-field-write-driver-split.integration.test.ts` for the pin); the\n// hook rule alone left half the surface uncovered.\n//\n// ─── What does NOT carry over ───────────────────────────────────────────────\n//\n// The context the body receives is NOT the hook context, so the hook ledger\n// cannot be adopted wholesale. `buildActionSandboxContext` binds\n// `input: unwrapProxyToPlain(actionCtx?.params ?? {})` — an action's\n// `ctx.input` is its PARAMS BAG, validated upstream against the action's own\n// `params` declaration (ADR-0104 D2), not a record. Resolving those names\n// against object fields would flag every correctly-named parameter: a pure\n// false-positive machine, and a false positive kills an advisory lint. Hence\n// {@link ACTION_BODY_WRITE_EXCLUSIONS} — declared as data, with reasons, and\n// partition-tested against the shared ledger so a pattern added to the hook\n// side later cannot be silently assumed to apply here.\n//\n// So the unknown-field check keeps exactly one shape: `api-crud-literal`\n// (`ctx.api.object('<literal>').insert|.create|.update|.updateById({…})`). That\n// is the one path through which an action body actually persists anything, it\n// addresses its target object explicitly (so the action's own `objectName`\n// binding is irrelevant to the check), and the hook rule's extractor already\n// recognizes it verbatim.\n//\n// ─── The second finding: a record write that reaches nothing (#4345) ────────\n//\n// `ctx.record` is not a write surface either, but it fails DIFFERENTLY, so it\n// gets its own rule id rather than being folded in or dropped. The runner hands\n// the body a plain snapshot (`record: unwrapProxyToPlain(actionCtx?.record)`)\n// and `boundActionHandler` returns `result.value` without writing anything back\n// — no `applyMutationsToInput`, which is the hook path's alone. So\n// `ctx.record.x = …` is discarded for DECLARED and undeclared fields alike.\n// Reporting that through the unknown-field rule would be actively wrong:\n// flagging only the undeclared half implies the declared half persists —\n// precisely the false completion this rule family exists to stop manufacturing.\n//\n// It is NOT enough to flag every `ctx.record.<field> = …`, because mutating the\n// snapshot to build a payload is a legitimate idiom:\n//\n// ctx.record.stage = 'won';\n// await ctx.api.object('crm_deal').update(ctx.record); // the write is LIVE\n//\n// So the finding requires the write to be PROVABLY dead: reported only when\n// `ctx.record` never escapes as a value anywhere in the body (see\n// `ctxRecordEscapes`). Property reads (`ctx.record.id`) do not rescue a write\n// and do not suppress the finding; handing the object to anything — an\n// argument, an assignment RHS, a spread, a return — does. Aliasing\n// (`const r = ctx.record`) reads as an escape, which is the safe direction.\n//\n// ─── Shared posture ─────────────────────────────────────────────────────────\n//\n// Both findings keep the hook rule's posture: advisory `warning`, silent bail\n// on anything statically unknowable (dynamic object names, non-literal\n// payloads, cross-package targets), did-you-mean on a miss.\n//\n// ONE suite entry, TWO rule ids. Both findings fall out of one parse of one\n// source on one surface, so splitting them into two `REFERENCE_INTEGRITY_RULES`\n// members would parse every action body twice to say two things about the same\n// walk; hand-wiring the second into the CLI instead is the drift that suite\n// exists to end — `validateReadonlyFlowWrites` is the standing proof, wired\n// into `validate` and `compile` but never into `lint`.\n//\n// Lazy like its sibling: a body mentioning neither `api` nor `record` cannot\n// match either shape and never pays the TypeScript load.\n\nimport { findClosestMatches, formatSuggestion } from '@objectstack/spec/shared';\nimport {\n extractHookBodyWriteSet,\n indexObjectFields,\n judgeableFieldsOf,\n IMPLICIT_FIELDS,\n HOOK_BODY_WRITE_PATTERNS,\n type BodyWritePatternExclusion,\n type HookBodyWritePattern,\n} from './validate-hook-body-writes.js';\n\nexport type ActionBodyWriteSeverity = 'warning';\n\nexport interface ActionBodyWriteFinding {\n /** Advisory-only by contract, exactly like the hook rule — the type says so. */\n severity: ActionBodyWriteSeverity;\n rule: string;\n /** Human-readable location, e.g. `action \"close_deal\" › body`. */\n where: string;\n /** Config path, e.g. `actions[0].body.source`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule ids (registry entries). Two, from one walk — see the header.\nexport const ACTION_BODY_WRITE_UNKNOWN_FIELD = 'action-body-write-unknown-field';\nexport const ACTION_RECORD_WRITE_DISCARDED = 'action-record-write-discarded';\n\n// ─── The applicable-pattern ledger ──────────────────────────────────────────\n//\n// Not a second pattern list: a declared PARTITION of the shared\n// `HOOK_BODY_WRITE_PATTERNS` into the shapes each of this module's two checks\n// consumes, plus the shapes neither does. Every part is data, and\n// validate-action-body-writes.test.ts asserts they cover the shared ledger\n// exactly — so a pattern added on the hook side FAILS this rule's test until\n// someone decides which part it belongs in. Silence is not a decision.\n// (`record-property-assign` landing here is that ratchet's first live catch.)\n\n/** @deprecated alias — the exclusion shape is shared with the hook rule. */\nexport type ActionBodyWriteExclusion = BodyWritePatternExclusion;\n\n/**\n * Ledger shapes the UNKNOWN-FIELD check consumes — resolved against the named\n * object's declared fields.\n *\n * Include-list, not exclude-list, on purpose: an unclassified new pattern is\n * then inert here (a missed finding) rather than live against a context it was\n * never reasoned about (a false one) — the same asymmetry the extractor's\n * silent bails follow.\n */\nexport const ACTION_BODY_WRITE_PATTERN_IDS: readonly string[] = ['api-crud-literal'];\n\n/**\n * Ledger shapes the DISCARDED-RECORD-WRITE check consumes — never resolved\n * against anything, because no field name can make a discarded write land.\n */\nexport const ACTION_RECORD_WRITE_PATTERN_IDS: readonly string[] = ['record-property-assign'];\n\n/** Shared-ledger patterns neither check consumes, each with its reason. */\nexport const ACTION_BODY_WRITE_EXCLUSIONS: readonly BodyWritePatternExclusion[] = [\n {\n id: 'input-property-assign',\n reason:\n \"an action's ctx.input is its params bag (`input: unwrapProxyToPlain(actionCtx?.params)`), not a \" +\n 'record — `ctx.input.<name>` writes a declared PARAMETER, which object fields cannot judge',\n },\n {\n id: 'input-object-assign',\n reason: 'same surface as input-property-assign — Object.assign(ctx.input, …) targets the params bag',\n },\n];\n\n/**\n * The subset of the shared ledger the unknown-field check sees — the published\n * answer to \"which writes does the action lint resolve against fields?\".\n */\nexport const ACTION_BODY_WRITE_PATTERNS: readonly HookBodyWritePattern[] =\n HOOK_BODY_WRITE_PATTERNS.filter((p) => ACTION_BODY_WRITE_PATTERN_IDS.includes(p.id));\n\n/** The subset the discarded-record-write check sees. */\nexport const ACTION_RECORD_WRITE_PATTERNS: readonly HookBodyWritePattern[] =\n HOOK_BODY_WRITE_PATTERNS.filter((p) => ACTION_RECORD_WRITE_PATTERN_IDS.includes(p.id));\n\nconst APPLICABLE_IDS: ReadonlySet<string> = new Set(ACTION_BODY_WRITE_PATTERN_IDS);\nconst RECORD_WRITE_IDS: ReadonlySet<string> = new Set(ACTION_RECORD_WRITE_PATTERN_IDS);\n\ntype AnyRec = Record<string, unknown>;\n\nconst isRec = (v: unknown): v is AnyRec => !!v && typeof v === 'object' && !Array.isArray(v);\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v.filter((x): x is AnyRec => isRec(x));\n if (isRec(v)) {\n return Object.entries(v).map(([name, def]) => ({\n name,\n ...(isRec(def) ? def : {}),\n }));\n }\n return [];\n}\n\n/** One L2 action body found in the stack, with the location to report it at. */\ninterface ActionBodySite {\n name: string;\n source: string;\n path: string;\n}\n\n/** The object an action binds to, by the same rule `collectBundleActions` uses. */\nfunction actionObjectBinding(action: AnyRec, parentObject?: string): string | undefined {\n if (typeof action.object === 'string' && action.object) return action.object;\n if (typeof action.objectName === 'string' && action.objectName) return action.objectName;\n return parentObject;\n}\n\n/**\n * Every L2 action body in the stack, from both places the runtime reads them.\n *\n * `collectBundleActions` (packages/runtime/src/app-plugin.ts) registers\n * `bundle.actions` AND `objects[].actions` — and `defineStack`'s\n * `mergeObjectActions` appends an action carrying `objectName` to its object's\n * array while PRESERVING the top-level entry, so a merged action is genuinely\n * reachable twice. Walk both and collapse the duplicate, or every merged\n * action's findings are reported twice.\n *\n * Deduplicated by VALUE — bound object, name and body source — not by object\n * identity the way the runtime can afford to. The suite runs on the\n * schema-PARSED stack (`validateReferenceIntegrity(result.data)` in `os\n * validate` / `os compile`), and parsing rebuilds every node, so the two copies\n * of a merged action arrive as distinct objects that are merely equal. An\n * identity check silently degrades to no check at all there — which is how the\n * showcase app reported its one action-body warning twice.\n *\n * Two same-named actions on DIFFERENT objects stay separate (the binding is in\n * the key). Two on the SAME binding with byte-identical bodies collapse to one\n * — they would emit the same sentence twice, so the second is noise.\n *\n * The top-level entry is walked first, so a merged action reports at\n * `actions[i]` — the authored location, not the derived copy.\n *\n * `type` is deliberately not consulted: the runtime binds a handler from\n * `action.body` alone (`actionBodyRunnerFactory` never reads `type`), so a body\n * on a non-`script` action still runs and still fails silently. Checking what\n * executes beats checking what the schema says should.\n */\nfunction collectActionBodies(stack: AnyRec): ActionBodySite[] {\n const sites: ActionBodySite[] = [];\n const seen = new Set<string>();\n\n const collect = (actions: unknown, pathPrefix: string, parentObject?: string): void => {\n asArray(actions).forEach((action, index) => {\n const body = action.body;\n if (!isRec(body) || body.language !== 'js') return;\n const source = body.source;\n if (typeof source !== 'string' || source.trim() === '') return;\n const name = typeof action.name === 'string' && action.name ? action.name : `#${index}`;\n const key = `${actionObjectBinding(action, parentObject) ?? ''}\\u0000${name}\\u0000${source}`;\n if (seen.has(key)) return;\n seen.add(key);\n sites.push({ name, source, path: `${pathPrefix}[${index}].body.source` });\n });\n };\n\n collect(stack.actions, 'actions');\n asArray(stack.objects).forEach((obj, objIndex) => {\n const parentObject = typeof obj.name === 'string' && obj.name ? obj.name : undefined;\n collect(obj.actions, `objects[${objIndex}].actions`, parentObject);\n });\n\n return sites;\n}\n\n/**\n * Validate L2 action-body writes against target-object field declarations.\n * Pure `(stack) => Finding[]` (ADR-0019); safe on pre- or post-parse stacks.\n */\nexport function validateActionBodyWrites(stack: AnyRec): ActionBodyWriteFinding[] {\n const findings: ActionBodyWriteFinding[] = [];\n if (!isRec(stack)) return findings;\n\n const sites = collectActionBodies(stack);\n if (sites.length === 0) return findings;\n\n // Built lazily: only the unknown-field check needs it, so a stack whose\n // action bodies never reach `ctx.api` never pays it.\n let objectFields: Map<string, Set<string>> | null = null;\n\n for (const site of sites) {\n // Cheap prefilter, narrower than the extractor's own: every consumed\n // pattern is rooted at `ctx.api` or `ctx.record`, so a body carrying\n // neither identifier cannot match and must not pay the ~9 MB TypeScript\n // load. Pinned by the ledger test — a consumed pattern whose example fails\n // this filter fails there, rather than going quietly unchecked here.\n if (!/\\bapi\\b/.test(site.source) && !/\\brecord\\b/.test(site.source)) continue;\n\n // ONE parse per body, both checks read from it.\n const { writes: allWrites, ctxRecordEscapes } = extractHookBodyWriteSet(site.source);\n const writes = allWrites.filter((w) => APPLICABLE_IDS.has(w.patternId));\n const recordWrites = allWrites.filter((w) => RECORD_WRITE_IDS.has(w.patternId));\n if (writes.length === 0 && recordWrites.length === 0) continue;\n\n const where = `action \"${site.name}\" › body`;\n\n // ── Discarded record writes (#4345) ──────────────────────────────────\n // Reported only when the write is PROVABLY dead: `ctx.record` never\n // leaves the body as a value, so nothing can persist the mutation. When\n // it does escape, the snapshot may be a payload under construction, and\n // every one of its writes is skipped — a missed finding, never a false one.\n if (recordWrites.length > 0 && !ctxRecordEscapes) {\n const reportedFields = new Set<string>();\n for (const w of recordWrites) {\n if (reportedFields.has(w.field)) continue;\n reportedFields.add(w.field);\n findings.push({\n severity: 'warning',\n rule: ACTION_RECORD_WRITE_DISCARDED,\n where,\n path: site.path,\n message:\n `body assigns ctx.record.${w.field}, but an action's ctx.record is a plain snapshot the runtime ` +\n `never writes back — the action returns success and the assignment is discarded, whether or not ` +\n `'${w.field}' is a declared field (#4345).`,\n hint:\n `To persist it, write through the API: ctx.api.object('<object>').updateById(ctx.recordId, ` +\n `{ ${w.field}: … }). Reported only because ctx.record is never passed anywhere in this body — ` +\n `mutating the snapshot and then handing it to an API write is a live payload and is not flagged. ` +\n `This warning never blocks a build.`,\n });\n }\n }\n\n if (writes.length === 0) continue;\n objectFields ??= indexObjectFields(stack);\n const reported = new Set<string>();\n\n for (const w of writes) {\n // Defensive: today every applicable pattern addresses its object\n // explicitly. A future applicable pattern that does not (a `ctx.input`-\n // shaped one) has no target to resolve against in an action, so it stays\n // silent rather than being guessed at the action's `objectName`.\n if (w.object === undefined) continue;\n\n const dedupeKey = `${w.object}\\u0000${w.field}`;\n if (reported.has(dedupeKey)) continue;\n\n const known = judgeableFieldsOf(objectFields, w.object);\n if (!known) continue; // cross-package, or no declared fields — cannot judge\n if (IMPLICIT_FIELDS.has(w.field) || known.has(w.field)) continue;\n\n reported.add(dedupeKey);\n findings.push({\n severity: 'warning',\n rule: ACTION_BODY_WRITE_UNKNOWN_FIELD,\n where,\n path: site.path,\n message:\n `body calls ctx.api.object('${w.object}').${w.method ?? 'update'}(…) writing '${w.field}', but ` +\n `object '${w.object}' declares no such field. The write-path validator skips the unknown key — ` +\n `on a SQL driver the whole action then fails with a driver-level error far from here; on a ` +\n `schemaless driver (memory, MongoDB) the stray key is persisted (#4271).`,\n hint: fixHint(w.field, [...known]),\n });\n }\n }\n\n return findings;\n}\n\n/** Did-you-mean (declared + system columns as candidates) plus the fix. */\nfunction fixHint(field: string, declared: string[]): string {\n const suggestion = formatSuggestion(findClosestMatches(field, [...declared, ...IMPLICIT_FIELDS]));\n return (\n (suggestion ? `${suggestion} ` : '') +\n `Fix the field name, or declare '${field}' on the object. Only the literal write patterns in ` +\n `ACTION_BODY_WRITE_PATTERNS are checked — an action's ctx.input is its params bag, so it is not a ` +\n `record-write surface and is never resolved against fields — and this warning never blocks a build.`\n );\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n//\n// Author-time write-set check for a flow CRUD node's `fields` write map — the\n// THIRD surface in the family #4271 opened, and the one the docs spent the\n// longest recommending as the safe alternative to the other two.\n//\n// A flow node that writes a field the target object never declares\n// (`config.fields.stagee` against an object whose column is `stage`) was caught\n// by nothing. `validate-readonly-flow-writes.ts` walks this exact map and\n// explicitly stepped over the unknown key (\"a form/field-layout lint concern,\n// not this rule's\" — a referral to a rule that does not check writes);\n// `validate-flow-template-paths.ts` checks the `{record.<path>}` READ tokens\n// interpolated into node config, never the write-side key. So the surface the\n// hook-body docs pointed authors at — \"prefer a flow update_record node, whose\n// structural `fields` config is checked\" — was the least checked of the three.\n//\n// ─── Why this one GATES where its two siblings advise ───────────────────────\n//\n// `hook-body-write-unknown-field` (#4305) and `action-body-write-unknown-field`\n// (#4344) are `warning` because they PARSE JavaScript: the finding is only as\n// good as the extractor, and a false positive kills an advisory lint. Nothing\n// here is parsed. `config.fields` is a literal, structural map next to a\n// literal `objectName` — when this rule speaks, the key provably resolves to no\n// column, at the same certainty `flow-update-readonly-field` already gates on\n// one config key over.\n//\n// And the runtime consequence is not the benign \"consumer skips the unknown\n// name and does the rest\" that keeps `page-field-unknown` / `form-field-unknown`\n// advisory. Nothing between the node and storage removes the key: the flow\n// executor calls the data engine directly (bypassing the metadata-protocol\n// ingress, which strips `readonly` — not unknown — keys anyway), the engine's\n// write paths strip only readonly/readonlyWhen, and the SQL driver's\n// `formatInput` / `applyWriteColumnMap` pass an unrecognized key straight\n// through (`m[k] ?? k`). Every branch below was measured, not inferred:\n//\n// • Through the engine, an undeclared key reaches `driver.update` /\n// `driver.create` verbatim, alongside the audit stamps.\n// • On SQLite/knex an UPDATE becomes `update \"deal\" set \"name\" = 'n2',\n// \"stagee\" = 'won' … → no such column: stagee`. The statement is rejected\n// WHOLE: `name` — spelled correctly, in the same payload — does not land\n// either, and the step fails with a driver error naming a column, far from\n// the authoring mistake.\n// • An INSERT fails the same way (`table deal has no column named stagee`),\n// and one notch harder: the row is never created at all, so every later\n// node that expected `{<node>.id}` is working from a record that does not\n// exist.\n// • On a schemaless datasource (memory, MongoDB) nothing rejects it, so the\n// stray key is persisted into a column the object never declares — where no\n// schema-driven read surface will return it.\n//\n// No outcome is \"the rest still works\". That is the same call\n// `validate-searchable-fields` makes for a stale entry and\n// `validate-flow-template-paths` makes for a filter-position token: gate when\n// the miss breaks or corrupts the operation, advise when it merely narrows the\n// output. Every skip below exists so that gate only ever fires on a certainty.\n//\n// ─── Scope ──────────────────────────────────────────────────────────────────\n//\n// {@link FLOW_WRITE_NODE_TYPES} — every CRUD node type that carries a `fields`\n// WRITE map: `update_record` (#4369) and `create_record` (#4371). The deferred\n// half, {@link FLOW_WRITE_NODE_TYPES_DEFERRED}, is now empty, and the partition\n// test still derives the full set behaviourally from the spec's\n// executor-written config schemas — so a node type that grows a write map later\n// lands on neither side and fails that test until someone classifies it.\n//\n// `get_record.fields` is NOT a member and never will be: it is a projection\n// (`z.array(z.string())`), a READ, and an unknown entry there narrows the\n// selection rather than breaking the statement. `screen.defaults` is not one\n// either — an object-form screen forwards it into the `ScreenSpec` the client\n// renders, so an unknown key is a form prefill the renderer ignores: inert, the\n// \"skips it and renders the rest\" case this rule's severity is defined against.\n// Both are excluded on the shape of their failure, not by omission.\n//\n// `runAs` is deliberately NOT consulted, unlike its readonly sibling. A\n// `runAs:'system'` flow is elevated past the readonly strip, which is why that\n// rule skips it — but no run identity conjures a column, so an unknown field is\n// unknown at every privilege level.\n//\n// Wired via REFERENCE_INTEGRITY_RULES (it resolves a field NAME written in\n// metadata against what the stack declares — the suite's exact membership\n// test), so `os validate`, `os lint` and `os compile` report it at once. The\n// readonly rule next door is still hand-wired into two of those three; this one\n// does not repeat that.\n\nimport { findClosestMatches, formatSuggestion } from '@objectstack/spec/shared';\n\nimport { indexObjectFields, judgeableFieldsOf, IMPLICIT_FIELDS } from './validate-hook-body-writes.js';\nimport { walkFlowNodes, flowNodeLabel } from './flow-walk.js';\n\nexport type FlowNodeWriteSeverity = 'error';\n\nexport interface FlowNodeWriteFinding {\n /** Always `error` — a literal key against a literal object is a certainty (see module note). */\n severity: FlowNodeWriteSeverity;\n rule: string;\n /** Human-readable location, e.g. `flow \"close_deal\" › node \"Mark won\"`. */\n where: string;\n /** Config path, e.g. `flows[0].nodes[3].config.fields.stagee`. */\n path: string;\n message: string;\n hint: string;\n}\n\n// Rule id (registry entry).\nexport const FLOW_NODE_WRITE_UNKNOWN_FIELD = 'flow-node-write-unknown-field';\n\n// ─── The covered-node ledger ────────────────────────────────────────────────\n//\n// Which flow node types have their `config.fields` write map resolved against\n// the target object, declared as data — and, next to it, which `fields`-bearing\n// node type deliberately does not yet, with its reason. Both halves are\n// partition-tested against the CRUD schemas in\n// `@objectstack/spec/automation/builtin-node-config`, so a node type that grows\n// a write map later cannot land on the uncovered side by nobody noticing.\n\n/** Flow node types whose `config.fields` keys this rule resolves. */\nexport const FLOW_WRITE_NODE_TYPES: readonly string[] = ['update_record', 'create_record'];\n\n/** A `fields`-bearing node type this rule does NOT cover yet, and why. */\nexport interface FlowWriteNodeDeferral {\n /** The `FlowNode.type` left uncovered. */\n readonly type: string;\n /** Why it is not covered, in terms a reviewer can act on. */\n readonly reason: string;\n}\n\n/**\n * `fields`-bearing CRUD node types deliberately left uncovered.\n *\n * **Empty, and that is the point.** #4369 shipped `update_record` alone and\n * parked `create_record` here with its reason — a gating rule earning its\n * severity one measured surface at a time — rather than leaving the other half\n * as silence. #4371 measured the INSERT path (`table deal has no column named\n * stagee`, and the row never created at all), found it strictly worse than the\n * UPDATE one, and moved it across.\n *\n * The slot stays because the partition test derives the full `fields`-write-map\n * set from the spec's own config schemas: a node type that grows one later\n * belongs to neither list and fails that test until someone puts it in one.\n * Deleting this array would turn that forced decision back into a default.\n */\nexport const FLOW_WRITE_NODE_TYPES_DEFERRED: readonly FlowWriteNodeDeferral[] = [];\n\ntype AnyRec = Record<string, unknown>;\n\nconst isRec = (v: unknown): v is AnyRec => !!v && typeof v === 'object' && !Array.isArray(v);\n\n/** Coerce an array-or-name-keyed-map collection to an array (name injected). */\nfunction asArray(v: unknown): AnyRec[] {\n if (Array.isArray(v)) return v.filter((x): x is AnyRec => isRec(x));\n if (isRec(v)) {\n return Object.entries(v).map(([name, def]) => ({\n name,\n ...(isRec(def) ? def : {}),\n }));\n }\n return [];\n}\n\n/**\n * The target object of a CRUD node, when statically knowable. Reads the\n * canonical `objectName` and its historical `object` alias — a pre-parse source\n * may still carry the alias until the 'flow-node-crud-object-alias' conversion\n * (#3796) canonicalizes it at load. A templated value (contains `{`) is\n * resolved from flow variables at run time, so it is skipped rather than\n * guessed. Same read as `validate-readonly-flow-writes.ts`, which walks the\n * same nodes for the other question.\n */\nfunction readLiteralObjectName(config: AnyRec): string | undefined {\n const raw = config.objectName ?? config.object;\n if (typeof raw !== 'string' || raw.includes('{')) return undefined;\n return raw || undefined;\n}\n\nconst COVERED_TYPES: ReadonlySet<string> = new Set(FLOW_WRITE_NODE_TYPES);\n\n/**\n * Validate flow write-node `fields` keys against the target object's declared\n * fields. Pure `(stack) => Finding[]` (ADR-0019); safe on pre- or post-parse\n * stacks.\n */\nexport function validateFlowNodeWrites(stack: AnyRec): FlowNodeWriteFinding[] {\n const findings: FlowNodeWriteFinding[] = [];\n if (!isRec(stack)) return findings;\n\n const flows = asArray(stack.flows);\n if (flows.length === 0) return findings;\n\n // Built lazily: a stack whose flows carry no write node never pays it.\n let objectFields: Map<string, Set<string>> | null = null;\n\n flows.forEach((flow, flowIndex) => {\n const flowName = typeof flow.name === 'string' && flow.name ? flow.name : `#${flowIndex}`;\n // Every node, INCLUDING those nested in try_catch / loop / parallel regions\n // — a gating rule that stops at the top level simply stops gating the\n // moment an author wraps the write in error handling (#4380).\n const walked = walkFlowNodes(flow, `flows[${flowIndex}]`);\n\n walked.forEach(({ node, path: nodePath, regionTrail }, walkIndex) => {\n if (typeof node.type !== 'string' || !COVERED_TYPES.has(node.type)) return;\n\n const config = isRec(node.config) ? node.config : undefined;\n if (!config) return;\n\n // A non-literal write map (templated string, spread result, array) is not\n // statically knowable — skip rather than guess.\n const fields = config.fields;\n if (!isRec(fields)) return;\n const written = Object.keys(fields);\n if (written.length === 0) return;\n\n const objectName = readLiteralObjectName(config);\n if (!objectName) return; // templated / dynamic object — resolved at run time\n\n objectFields ??= indexObjectFields(stack);\n // Cross-package objects and objects declaring no fields at all (external /\n // datasource-introspected schemas) are both unjudgeable, and this rule\n // gates — see {@link judgeableFieldsOf}, which is where that guard now\n // lives for the whole family rather than once per rule (#4383).\n const known = judgeableFieldsOf(objectFields, objectName);\n if (!known) return;\n\n const nodeName = flowNodeLabel(node, walkIndex);\n // A nested node names the region that holds it, or \"node X\" is ambiguous\n // in a flow where the same label appears in a try and a catch branch.\n const nodeWhere = regionTrail ? `${regionTrail} › node \"${nodeName}\"` : `node \"${nodeName}\"`;\n\n for (const fieldName of written) {\n if (known.has(fieldName) || IMPLICIT_FIELDS.has(fieldName)) continue;\n // A dotted key addresses a nested path, not a top-level column — the\n // document drivers forward it verbatim. Not statically a missing field.\n if (fieldName.includes('.')) continue;\n\n findings.push({\n severity: 'error',\n rule: FLOW_NODE_WRITE_UNKNOWN_FIELD,\n where: `flow \"${flowName}\" › ${nodeWhere}`,\n path: `${nodePath}.config.fields.${fieldName}`,\n message:\n `${node.type} writes '${fieldName}', but object '${objectName}' declares no such field. Nothing ` +\n `between the node and storage removes the key: on a SQL datasource the driver rejects the whole ` +\n `statement ('no such column'), so the correctly named fields in this same payload never land ` +\n `either${\n node.type === 'create_record' ? ' and the record is never created at all' : ''\n }; on a schemaless one the stray key is persisted into a column no read surface returns.`,\n hint: fixHint(fieldName, [...known]),\n });\n }\n });\n });\n\n return findings;\n}\n\n/** Did-you-mean (declared + system columns as candidates) plus the fix. */\nfunction fixHint(field: string, declared: string[]): string {\n const suggestion = formatSuggestion(findClosestMatches(field, [...declared, ...IMPLICIT_FIELDS]));\n return (\n (suggestion ? `${suggestion} ` : '') +\n `Fix the field name, or declare '${field}' on the object. This gates the build rather than warning: ` +\n `the key is literal and so is the object, so unlike the hook/action body rules there is nothing here ` +\n `that could have been mis-extracted.`\n );\n}\n","// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * The reference-integrity suite — one entry point for the rules that answer\n * \"does this name resolve to anything?\" (issue #3583, assessment §5 D5).\n *\n * ## Why this exists\n *\n * These rules were wired **by hand** into each CLI entry point that runs them.\n * `os validate`, `os lint` and `os compile` each grew their own import list and\n * their own call site, so landing a rule meant remembering three places — and\n * the assessment's §2.2 already named the resulting drift as the enemy: the\n * same stack, checked by a different rule subset depending on which command\n * the author happened to run.\n *\n * The suite makes the next rule's wiring a ONE-LINE edit here, and makes the\n * question \"which rules run on this path?\" answerable by reading one list.\n *\n * ## What belongs in it\n *\n * A rule belongs here when it resolves a NAME written in metadata against the\n * things a stack actually declares — objects, actions, fields, measures,\n * permissions, translation keys. That is the family the HotCRM audit found\n * shipping broken: every instance parsed, validated, and failed silently at\n * runtime because nothing checked that the name pointed at anything.\n *\n * `validateFlowTemplatePaths` is a member for exactly that reason: a\n * `{record.<field>}` token is a field name written in metadata, resolved\n * against the bound object's declared fields. It was wired by hand into\n * `os validate` alone — the drift this suite exists to end — so `os lint` and\n * `os compile` accepted a flow the runtime refuses. Its findings carry BOTH\n * severities (see that module: a filter-position miss gates, every other\n * position advises), which is why the suite's contract is severity-agnostic.\n *\n * `validateSearchableFields` is a member on the same reading, one layer in: an\n * ADR-0061 `searchableFields` entry is a field name written in metadata,\n * resolved against the object's own declared fields. It gates (`error`) because\n * the engine's tolerance for a stale entry — silently filtering it out — either\n * narrows the searched set below what the object declares or, once every entry\n * is stale, falls through to the auto-default and searches a set the author\n * never wrote. See that module for why the other field-existence rules stay\n * advisory and this one does not.\n *\n * Rules that check SHAPE rather than reference (view containers, responsive\n * styles, seed replay safety, seed state machines, seed/security posture) stay\n * out — they answer a different question and have their own call sites.\n *\n * ## Known remaining asymmetry\n *\n * `os doctor` runs only `validateWidgetBindings` and is NOT converted here: it\n * is an environment health check (node version, config presence, circular\n * lookups), not an authoring gate, so adopting the suite there is a product\n * decision about what `doctor` is for — not a wiring cleanup. It is named here\n * so the gap stays visible instead of being rediscovered.\n */\n\nimport { validateObjectReferences } from './validate-object-references.js';\nimport { validateSearchableFields } from './validate-searchable-fields.js';\nimport { validateActionNameRefs } from './validate-action-name-refs.js';\nimport { validatePageFieldBindings } from './validate-page-field-bindings.js';\nimport { validateChartBindings } from './validate-chart-bindings.js';\nimport { validateNavAccess } from './validate-nav-access.js';\nimport { validateTranslationReferences } from './validate-translation-references.js';\nimport { validateFlowTemplatePaths } from './validate-flow-template-paths.js';\nimport { validateAiSurfaceAffinity } from './validate-ai-surface-affinity.js';\nimport { validateAiToolReferences } from './validate-ai-tool-references.js';\nimport { validateAiAgentAuthoring } from './validate-ai-agent-authoring.js';\nimport { validateHookBodyWrites } from './validate-hook-body-writes.js';\nimport { validateActionBodyWrites } from './validate-action-body-writes.js';\nimport { validateFlowNodeWrites } from './validate-flow-node-writes.js';\nimport { validateReadonlyFlowWrites } from './validate-readonly-flow-writes.js';\nimport { validateReactPageProps } from './validate-react-page-props.js';\n\nexport type ReferenceIntegritySeverity = 'error' | 'warning';\n\n/**\n * The shape every rule in the suite already returns. Declared here so callers\n * can hold one type instead of a six-way union.\n */\nexport interface ReferenceIntegrityFinding {\n /** `error` = the reference is dead; `warning` = it may resolve elsewhere, or the miss is inert. */\n severity: ReferenceIntegritySeverity;\n /** Diagnostic rule id (stable; used by allowlists and docs). */\n rule: string;\n /** Human-readable location. */\n where: string;\n /** Config path. */\n path: string;\n /** What is wrong. */\n message: string;\n /** How to fix it. */\n hint: string;\n}\n\n/** One member of the suite. `name` is the exported function's name — the id a wiring test can assert on. */\nexport interface ReferenceIntegrityRule {\n name: string;\n run: (stack: Record<string, unknown>) => ReferenceIntegrityFinding[];\n}\n\n/**\n * Every reference-integrity rule, in the order their findings are reported.\n *\n * ADDING A RULE: append it here and it runs on `validate`, `lint` and\n * `compile` at once. Do not re-wire the commands.\n */\nexport const REFERENCE_INTEGRITY_RULES: readonly ReferenceIntegrityRule[] = [\n { name: 'validateObjectReferences', run: validateObjectReferences },\n { name: 'validateSearchableFields', run: validateSearchableFields },\n { name: 'validateActionNameRefs', run: validateActionNameRefs },\n { name: 'validatePageFieldBindings', run: validatePageFieldBindings },\n { name: 'validateChartBindings', run: validateChartBindings },\n { name: 'validateNavAccess', run: validateNavAccess },\n { name: 'validateTranslationReferences', run: validateTranslationReferences },\n { name: 'validateFlowTemplatePaths', run: validateFlowTemplatePaths },\n { name: 'validateAiSurfaceAffinity', run: validateAiSurfaceAffinity },\n { name: 'validateAiToolReferences', run: validateAiToolReferences },\n { name: 'validateAiAgentAuthoring', run: validateAiAgentAuthoring },\n // Field names WRITTEN by an L2 hook body (`ctx.input.x = …`,\n // `ctx.api.object('y').update({ x })`), resolved against the target object's\n // declared fields — the write-side counterpart of validateFlowTemplatePaths'\n // read-side membership (#4271). Lazy: only a hook that actually carries a\n // `language:'js'` body loads the TypeScript parser.\n { name: 'validateHookBodyWrites', run: validateHookBodyWrites },\n // The same check on the other surface that carries a `HookBodySchema` body:\n // action bodies, run by the same sandbox. Only the `ctx.api` write family\n // carries over — an action's `ctx.input` is its params bag, not a record\n // (see that module's ledger). Lazy on the same terms.\n //\n // The first member here to emit more than one rule id (`validateReactPageProps`\n // below is the other, and carries the most). Besides resolving `ctx.api`\n // writes against declared fields (`action-body-write-unknown-field`), it\n // reports a `ctx.record` write that can reach nothing\n // (`action-record-write-discarded`, #4345) — not a resolution question, so\n // by the charter above it does not belong in the suite. It rides along\n // anyway because it falls out of the SAME parse of the SAME source: a\n // separate member would parse every action body twice to say two things\n // about one walk, and hand-wiring it into the CLI instead is exactly the\n // drift this suite exists to end — which `validateReadonlyFlowWrites` was\n // the standing proof of, until it joined the suite below.\n { name: 'validateActionBodyWrites', run: validateActionBodyWrites },\n // The third surface that writes a record field set: a flow `update_record`\n // node's `config.fields`. Same question as the two rules above, but the map\n // is structural metadata rather than parsed JS, so a finding is a certainty\n // and gates (`error`) — see that module for why, and why the docs' long-\n // standing \"prefer a flow node, it's checked\" advice was the least true of\n // the three until it landed.\n { name: 'validateFlowNodeWrites', run: validateFlowNodeWrites },\n // The OTHER question about that same `config.fields` map: not \"does this\n // field exist?\" but \"is it writable?\" — a `runAs:'user'` update_record\n // writing a static-`readonly` field is stripped by the engine and the step\n // still reports success (#2948/#3425). It walks the identical map the rule\n // above walks, so the two splitting call sites was never defensible: hand-\n // wired into `validate` and `compile` only, it left `os lint` PASSING a flow\n // `os validate` refuses — and this one gates, so the divergence shipped a\n // build the other command would have stopped. Joining the suite is the whole\n // fix; the two hand-wired call sites are deleted with it (#4345 follow-up).\n { name: 'validateReadonlyFlowWrites', run: validateReadonlyFlowWrites },\n // The `kind:'react'` page surface. Every prop a react block binds BY FIELD\n // NAME is resolved against the object it names (#4340) — `<ListView columns>`,\n // `<ObjectForm fields>`, the `record:*` family through the SAME\n // `COMPONENT_FIELD_SPECS` table `validatePageFieldBindings` walks one surface\n // over, plus `<ObjectChart>`'s aggregate/axes (#3701/#3729) and\n // `searchableFields` (#4329). Squarely the charter's question, on the surface\n // where it had no answer at all.\n //\n // It was hand-wired into `os validate` ALONE, so `os lint` and `os compile`\n // accepted a react page whose every field binding was stale — including the\n // gating ones (a missing required binding, a filter position naming no field:\n // the predicate can never match and the list comes back empty). That is\n // `validateReadonlyFlowWrites`' divergence again, one surface over, and it is\n // the reason this entry exists rather than a fourth hand-wiring.\n //\n // Like `validateActionBodyWrites` above, it emits ids that are not resolution\n // questions — `react-prop-missing-required` and `react-prop-typo` are shape,\n // and by the charter belong outside. They ride along for the same reason: they\n // fall out of the SAME TypeScript parse of the SAME page source, and splitting\n // them into a second member would parse every react page twice to say two\n // things about one walk. Lazy on the same terms as the hook/action body rules\n // — only a page that is actually `kind:'react'` loads the compiler.\n { name: 'validateReactPageProps', run: validateReactPageProps },\n];\n\n/**\n * Run every reference-integrity rule over a stack. Returns the concatenated\n * findings (empty = clean). Pure: no I/O, safe on both the schema-parsed stack\n * and the raw/normalized config the `lint` path carries.\n */\nexport function validateReferenceIntegrity(stack: Record<string, unknown>): ReferenceIntegrityFinding[] {\n const findings: ReferenceIntegrityFinding[] = [];\n for (const rule of REFERENCE_INTEGRITY_RULES) {\n findings.push(...rule.run(stack));\n }\n return findings;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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AAC;AAAA,EAClC;AACA,SAAO;AACT;","names":["import_data","label","asArray","asArray","label","asArray","isRecordTriggered","import_automation","asArray","asArray","label","asArray","asArray","asArray","import_node_module","import_ui","import_data","asArray","isRec","strName","suggest","label","isRec","strName","list","asArray","strName","isRec","import_meta","asArray","isRec","asArray","import_data","asArray","asArray","asArray","asArray","asArray","import_automation","import_formula","asArray","import_security","asArray","label","asArray","asArray","strName","label","import_data","asArray","import_system","asArray","strName","suggest","distance","checkActionParams","asArray","strName","distance","suggest","label","list","asArray","strName","strList","isRec","distance","suggest","list","selected","import_system","asArray","label","asArray","strName","import_system","isRec","asArray","strName","distance","suggest","label","asArray","strName","import_system","asArray","strName","distance","suggest","asArray","strName","import_node_module","import_meta","cachedTs","loadTypeScript","IMPLICIT_FIELDS","isRec","asArray","indexObjectFields","import_shared","isRec","asArray","indexObjectFields","IMPLICIT_FIELDS","fixHint","import_shared","isRec","asArray","readLiteralObjectName","indexObjectFields","IMPLICIT_FIELDS","fixHint"]}